fixup! lavc/rkmppenc: add RKMPP H264 and HEVC encoder

fix artifacts caused by delayed release of MppPacket data.

Signed-off-by: nyanmisaka <nst799610810@gmail.com>
This commit is contained in:
nyanmisaka 2024-11-11 00:27:52 +08:00
parent c5e745e3c1
commit 57b7952f6a
2 changed files with 11 additions and 14 deletions

View file

@ -758,12 +758,6 @@ exit:
return ret; return ret;
} }
static void rkmpp_free_packet_buf(void *opaque, uint8_t *data)
{
MppPacket mpp_pkt = opaque;
mpp_packet_deinit(&mpp_pkt);
}
static int rkmpp_get_packet(AVCodecContext *avctx, AVPacket *packet, int timeout) static int rkmpp_get_packet(AVCodecContext *avctx, AVPacket *packet, int timeout)
{ {
RKMPPEncContext *r = avctx->priv_data; RKMPPEncContext *r = avctx->priv_data;
@ -794,13 +788,15 @@ static int rkmpp_get_packet(AVCodecContext *avctx, AVPacket *packet, int timeout
} }
av_log(avctx, AV_LOG_DEBUG, "Received a packet\n"); av_log(avctx, AV_LOG_DEBUG, "Received a packet\n");
packet->data = mpp_packet_get_data(mpp_pkt); /* freeing MppPacket data in buffer callbacks is not supported in async mode */
packet->size = mpp_packet_get_length(mpp_pkt); {
packet->buf = av_buffer_create(packet->data, packet->size, rkmpp_free_packet_buf, size_t mpp_pkt_length = mpp_packet_get_length(mpp_pkt);
mpp_pkt, AV_BUFFER_FLAG_READONLY);
if (!packet->buf) { if ((ret = ff_alloc_packet(avctx, packet, mpp_pkt_length)) < 0) {
ret = AVERROR(ENOMEM); av_log(avctx, AV_LOG_ERROR, "ff_alloc_packet failed: %d\n", ret);
goto exit; goto exit;
}
memcpy(packet->data, mpp_packet_get_data(mpp_pkt), mpp_pkt_length);
} }
packet->time_base.num = avctx->time_base.num; packet->time_base.num = avctx->time_base.num;
@ -814,6 +810,7 @@ static int rkmpp_get_packet(AVCodecContext *avctx, AVPacket *packet, int timeout
ret = AVERROR_EXTERNAL; ret = AVERROR_EXTERNAL;
goto exit; goto exit;
} }
mpp_packet_deinit(&mpp_pkt);
mpp_meta_get_s32(mpp_meta, KEY_OUTPUT_INTRA, &key_frame); mpp_meta_get_s32(mpp_meta, KEY_OUTPUT_INTRA, &key_frame);
if (key_frame) if (key_frame)

View file

@ -244,7 +244,7 @@ static const AVCodecHWConfigInternal *const rkmpp_enc_hw_configs[] = {
static const FFCodecDefault rkmpp_enc_defaults[] = { static const FFCodecDefault rkmpp_enc_defaults[] = {
{ "b", "2M" }, { "b", "2M" },
{ "g", "250" }, { "g", "250" },
{ NULL } { NULL },
}; };
#define DEFINE_RKMPP_ENCODER(x, X, xx) \ #define DEFINE_RKMPP_ENCODER(x, X, xx) \