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

api: add sxplayer_release_frame_mediacodec() #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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