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 850e58c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- This Changelog
- New MediaCodec helper function: `sxplayer_release_frame_mediacodec()`

### Changed
- Switch build system from GNU/Make to [Meson](https://mesonbuild.com/)
Expand Down
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
struct sxplayer_frame *frame = *framep;
if (!frame)
return 0;
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
14 changes: 14 additions & 0 deletions sxplayer.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,20 @@ 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
* buffer 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 850e58c

Please sign in to comment.