Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
api: add sxplayer_release_frame_mediacodec()
Browse files Browse the repository at this point in the history
  • Loading branch information
mbouron committed Nov 3, 2020
1 parent abc13b0 commit e1f64aa
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
23 changes: 23 additions & 0 deletions sxplayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
#include "log.h"
#include "internal.h"

#if HAVE_MEDIACODEC_HWACCEL
#include <libavcodec/mediacodec.h>
#endif

struct sxplayer_ctx {
const AVClass *class; // necessary for the AVOption mechanism
struct log_ctx *log_ctx;
Expand Down Expand Up @@ -547,6 +551,25 @@ void sxplayer_release_frame(struct sxplayer_frame *frame)
}
}

int sxplayer_release_frame_mediacodec(struct sxplayer_frame **framep)
{
#if HAVE_MEDIACODEC_HWACCEL
if (!*framep)
return 0;
struct sxplayer_frame *frame = *framep;
av_assert0(frame->pix_fmt == SXPLAYER_PIXFMT_MEDIACODEC);
AVMediaCodecBuffer *buffer = (AVMediaCodecBuffer *)frame->data;
int ret = av_mediacodec_release_buffer(buffer, 1);
sxplayer_release_frame(frame);
*framep = NULL;
if (ret < 0)
return -1;
return 0;
#else
av_assert0(0);
#endif
}

int sxplayer_set_drop_ref(struct sxplayer_ctx *s, int drop)
{
return -1; // TODO
Expand Down
15 changes: 15 additions & 0 deletions sxplayer.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,21 @@ int sxplayer_set_drop_ref(struct sxplayer_ctx *s, int drop);
/* Release a frame obtained with sxplayer_get_frame() */
void sxplayer_release_frame(struct sxplayer_frame *frame);

/**
* Render to surface and release a MediaCodec frame obtained with
* sxplayer_get_frame().
*
* @param framep the address of a sxplayer_frame pointer to be rendered
* and released
*
* Note: the sxplayer_frame is released even if the underlying MediaCodec
* failed to be rendered.
*
* Return 0 on success, a negative value on error
*
*/
int sxplayer_release_frame_mediacodec(struct sxplayer_frame **framep);

/* Close and free everything */
void sxplayer_free(struct sxplayer_ctx **ss);

Expand Down

0 comments on commit e1f64aa

Please sign in to comment.