avcodec/mediacodecenc: add AV_CODEC_CAP_ENCODER_FLUSH support

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
This commit is contained in:
Zhao Zhili 2024-04-17 12:37:41 +08:00
parent 9e49915195
commit 66161166dc
1 changed files with 13 additions and 2 deletions

View File

@ -705,6 +705,15 @@ static av_cold int mediacodec_close(AVCodecContext *avctx)
return 0; return 0;
} }
static av_cold void mediacodec_flush(AVCodecContext *avctx)
{
MediaCodecEncContext *s = avctx->priv_data;
if (s->bsf)
av_bsf_flush(s->bsf);
av_frame_unref(s->frame);
ff_AMediaCodec_flush(s->codec);
}
static const AVCodecHWConfigInternal *const mediacodec_hw_configs[] = { static const AVCodecHWConfigInternal *const mediacodec_hw_configs[] = {
&(const AVCodecHWConfigInternal) { &(const AVCodecHWConfigInternal) {
.public = { .public = {
@ -755,13 +764,15 @@ const FFCodec ff_ ## short_name ## _mediacodec_encoder = { \
CODEC_LONG_NAME(long_name " Android MediaCodec encoder"), \ CODEC_LONG_NAME(long_name " Android MediaCodec encoder"), \
.p.type = AVMEDIA_TYPE_VIDEO, \ .p.type = AVMEDIA_TYPE_VIDEO, \
.p.id = codec_id, \ .p.id = codec_id, \
.p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY \ .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | \
| AV_CODEC_CAP_HARDWARE, \ AV_CODEC_CAP_HARDWARE | \
AV_CODEC_CAP_ENCODER_FLUSH, \
.priv_data_size = sizeof(MediaCodecEncContext), \ .priv_data_size = sizeof(MediaCodecEncContext), \
.p.pix_fmts = avc_pix_fmts, \ .p.pix_fmts = avc_pix_fmts, \
.init = mediacodec_init, \ .init = mediacodec_init, \
FF_CODEC_RECEIVE_PACKET_CB(mediacodec_encode), \ FF_CODEC_RECEIVE_PACKET_CB(mediacodec_encode), \
.close = mediacodec_close, \ .close = mediacodec_close, \
.flush = mediacodec_flush, \
.p.priv_class = &short_name ## _mediacodec_class, \ .p.priv_class = &short_name ## _mediacodec_class, \
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP, \ .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, \
.p.wrapper_name = "mediacodec", \ .p.wrapper_name = "mediacodec", \