[vlc-commits] [Git][videolan/vlc][master] avcodec: remove use of av_init_packet as it is deprecated in new ffmpeg major version
Steve Lhomme (@robUx4)
gitlab at videolan.org
Wed Jul 7 12:38:05 UTC 2021
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
16fd46fa by Ilkka Ollakka at 2021-07-07T12:37:58+00:00
avcodec: remove use of av_init_packet as it is deprecated in new ffmpeg major version
av_init_packet is deprecated in new major version of ffmpeg.
Also use av_packet_free instead of unref.
Use av_packet_clone and AVPacket * in vlc_av_packet_t.
- - - - -
5 changed files:
- modules/codec/avcodec/audio.c
- modules/codec/avcodec/encoder.c
- modules/codec/avcodec/subtitle.c
- modules/codec/avcodec/video.c
- modules/demux/avformat/mux.c
Changes:
=====================================
modules/codec/avcodec/audio.c
=====================================
@@ -372,11 +372,13 @@ static int DecodeBlock( decoder_t *p_dec, block_t **pp_block )
/* Feed in the loop as buffer could have been full on first iterations */
if( p_block )
{
- AVPacket pkt;
- av_init_packet( &pkt );
- pkt.data = p_block->p_buffer;
- pkt.size = p_block->i_buffer;
- ret = avcodec_send_packet( ctx, &pkt );
+ AVPacket *pkt = av_packet_alloc();
+ if( !pkt )
+ goto end;
+ pkt->data = p_block->p_buffer;
+ pkt->size = p_block->i_buffer;
+ ret = avcodec_send_packet( ctx, pkt );
+ av_packet_free(&pkt);
if( ret == 0 ) /* Block has been consumed */
{
/* Only set new pts from input block if it has been used,
=====================================
modules/codec/avcodec/encoder.c
=====================================
@@ -1067,14 +1067,14 @@ error:
typedef struct
{
block_t self;
- AVPacket packet;
+ AVPacket *packet;
} vlc_av_packet_t;
static void vlc_av_packet_Release(block_t *block)
{
vlc_av_packet_t *b = (void *) block;
- av_packet_unref(&b->packet);
+ av_packet_free( &b->packet );
free(b);
}
@@ -1100,7 +1100,7 @@ static block_t *vlc_av_packet_Wrap(AVPacket *packet, AVCodecContext *context )
block_Init( p_block, &vlc_av_packet_cbs, packet->data, packet->size );
p_block->i_nb_samples = 0;
p_block->cbs = &vlc_av_packet_cbs;
- b->packet = *packet;
+ b->packet = packet;
p_block->i_length = FROM_AVSCALE(packet->duration, context->time_base);
if( unlikely( packet->flags & AV_PKT_FLAG_CORRUPT ) )
@@ -1170,11 +1170,13 @@ static void check_hurry_up( encoder_sys_t *p_sys, AVFrame *frame, encoder_t *p_e
static block_t *encode_avframe( encoder_t *p_enc, encoder_sys_t *p_sys, AVFrame *frame )
{
- AVPacket av_pkt;
- av_pkt.data = NULL;
- av_pkt.size = 0;
+ AVPacket *av_pkt = av_packet_alloc();
- av_init_packet( &av_pkt );
+ if( !av_pkt )
+ {
+ av_frame_unref( frame );
+ return NULL;
+ }
int ret = avcodec_send_frame( p_sys->p_context, frame );
if( frame && ret != 0 && ret != AVERROR(EAGAIN) )
@@ -1182,17 +1184,18 @@ static block_t *encode_avframe( encoder_t *p_enc, encoder_sys_t *p_sys, AVFrame
msg_Warn( p_enc, "cannot send one frame to encoder %d", ret );
return NULL;
}
- ret = avcodec_receive_packet( p_sys->p_context, &av_pkt );
+ ret = avcodec_receive_packet( p_sys->p_context, av_pkt );
if( ret != 0 && ret != AVERROR(EAGAIN) )
{
msg_Warn( p_enc, "cannot encode one frame" );
+ av_packet_free( &av_pkt );
return NULL;
}
- block_t *p_block = vlc_av_packet_Wrap( &av_pkt, p_sys->p_context );
+ block_t *p_block = vlc_av_packet_Wrap( av_pkt, p_sys->p_context );
if( unlikely(p_block == NULL) )
{
- av_packet_unref( &av_pkt );
+ av_packet_free( &av_pkt );
return NULL;
}
return p_block;
=====================================
modules/codec/avcodec/subtitle.c
=====================================
@@ -113,11 +113,7 @@ int InitSubtitleDec(vlc_object_t *obj)
}
}
-#if LIBAVFORMAT_VERSION_MAJOR >= 59
context->pkt_timebase=AV_TIME_BASE_Q;
-#elif LIBAVFORMAT_VERSION_MICRO >= 100
- av_codec_set_pkt_timebase(context, AV_TIME_BASE_Q);
-#endif
/* */
int ret;
@@ -217,16 +213,21 @@ static subpicture_t *DecodeBlock(decoder_t *dec, block_t **block_ptr)
AVSubtitle subtitle;
memset(&subtitle, 0, sizeof(subtitle));
- AVPacket pkt;
- av_init_packet(&pkt);
- pkt.data = block->p_buffer;
- pkt.size = block->i_buffer;
- pkt.pts = TO_AV_TS(block->i_pts);
+ AVPacket *pkt = av_packet_alloc();
+ if(!pkt)
+ {
+ block_Release(block);
+ return NULL;
+ }
+ pkt->data = block->p_buffer;
+ pkt->size = block->i_buffer;
+ pkt->pts = TO_AV_TS(block->i_pts);
int has_subtitle = 0;
int used = avcodec_decode_subtitle2(sys->p_context,
- &subtitle, &has_subtitle, &pkt);
+ &subtitle, &has_subtitle, pkt);
+ av_packet_free(&pkt);
if (used < 0) {
msg_Warn(dec, "cannot decode one subtitle (%zu bytes)",
block->i_buffer);
=====================================
modules/codec/avcodec/video.c
=====================================
@@ -973,29 +973,33 @@ static int DecodeBlock( decoder_t *p_dec, block_t **pp_block )
if( (p_block && p_block->i_buffer > 0) || b_drain )
{
- AVPacket pkt;
- av_init_packet( &pkt );
+ AVPacket *pkt = av_packet_alloc();
+ if(!pkt)
+ {
+ b_error = true;
+ break;
+ }
if( p_block && p_block->i_buffer > 0 )
{
- pkt.data = p_block->p_buffer;
- pkt.size = p_block->i_buffer;
- pkt.pts = p_block->i_pts != VLC_TICK_INVALID ? TO_AV_TS(p_block->i_pts) : AV_NOPTS_VALUE;
- pkt.dts = p_block->i_dts != VLC_TICK_INVALID ? TO_AV_TS(p_block->i_dts) : AV_NOPTS_VALUE;
+ pkt->data = p_block->p_buffer;
+ pkt->size = p_block->i_buffer;
+ pkt->pts = p_block->i_pts != VLC_TICK_INVALID ? TO_AV_TS(p_block->i_pts) : AV_NOPTS_VALUE;
+ pkt->dts = p_block->i_dts != VLC_TICK_INVALID ? TO_AV_TS(p_block->i_dts) : AV_NOPTS_VALUE;
if (p_block->i_flags & BLOCK_FLAG_TYPE_I)
- pkt.flags |= AV_PKT_FLAG_KEY;
+ pkt->flags |= AV_PKT_FLAG_KEY;
}
else
{
/* Drain */
- pkt.data = NULL;
- pkt.size = 0;
+ pkt->data = NULL;
+ pkt->size = 0;
b_drain = false;
b_drained = true;
}
if( !p_sys->palette_sent )
{
- uint8_t *pal = av_packet_new_side_data(&pkt, AV_PKT_DATA_PALETTE, AVPALETTE_SIZE);
+ uint8_t *pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, AVPALETTE_SIZE);
if (pal) {
memcpy(pal, p_dec->fmt_in.video.p_palette->palette, AVPALETTE_SIZE);
p_sys->palette_sent = true;
@@ -1009,7 +1013,7 @@ static int DecodeBlock( decoder_t *p_dec, block_t **pp_block )
p_block->i_dts = VLC_TICK_INVALID;
}
- int ret = avcodec_send_packet(p_context, &pkt);
+ int ret = avcodec_send_packet(p_context, pkt);
if( ret != 0 && ret != AVERROR(EAGAIN) )
{
if (ret == AVERROR(ENOMEM) || ret == AVERROR(EINVAL))
@@ -1017,7 +1021,7 @@ static int DecodeBlock( decoder_t *p_dec, block_t **pp_block )
msg_Err(p_dec, "avcodec_send_packet critical error");
b_error = true;
}
- av_packet_unref( &pkt );
+ av_packet_free( &pkt );
break;
}
@@ -1026,8 +1030,8 @@ static int DecodeBlock( decoder_t *p_dec, block_t **pp_block )
p_frame_info->b_display = b_need_output_picture;
p_context->reordered_opaque++;
- i_used = ret != AVERROR(EAGAIN) ? pkt.size : 0;
- av_packet_unref( &pkt );
+ i_used = ret != AVERROR(EAGAIN) ? pkt->size : 0;
+ av_packet_free( &pkt );
if( p_frame_info->b_eos && !b_drained )
{
=====================================
modules/demux/avformat/mux.c
=====================================
@@ -377,14 +377,16 @@ static int MuxBlock( sout_mux_t *p_mux, sout_input_t *p_input )
block_t *p_data = block_FifoGet( p_input->p_fifo );
int i_stream = *((int *)p_input->p_sys);
AVStream *p_stream = p_sys->oc->streams[i_stream];
- AVPacket pkt;
-
- memset( &pkt, 0, sizeof(AVPacket) );
+ AVPacket *pkt = av_packet_alloc();
+ if( !pkt )
+ {
+ block_Release( p_data );
+ return VLC_EGENERIC;
+ }
- av_init_packet(&pkt);
- pkt.data = p_data->p_buffer;
- pkt.size = p_data->i_buffer;
- pkt.stream_index = i_stream;
+ pkt->data = p_data->p_buffer;
+ pkt->size = p_data->i_buffer;
+ pkt->stream_index = i_stream;
if( p_data->i_flags & BLOCK_FLAG_TYPE_I )
{
@@ -395,26 +397,28 @@ static int MuxBlock( sout_mux_t *p_mux, sout_input_t *p_input )
#endif
p_sys->b_write_keyframe = true;
- pkt.flags |= AV_PKT_FLAG_KEY;
+ pkt->flags |= AV_PKT_FLAG_KEY;
}
if( p_data->i_pts >= VLC_TICK_0 )
- pkt.pts = av_rescale_q( p_data->i_pts - VLC_TICK_0,
+ pkt->pts = av_rescale_q( p_data->i_pts - VLC_TICK_0,
VLC_TIME_BASE_Q, p_stream->time_base );
if( p_data->i_dts >= VLC_TICK_0 )
- pkt.dts = av_rescale_q( p_data->i_dts - VLC_TICK_0,
+ pkt->dts = av_rescale_q( p_data->i_dts - VLC_TICK_0,
VLC_TIME_BASE_Q, p_stream->time_base );
- if( av_write_frame( p_sys->oc, &pkt ) < 0 )
+ if( av_write_frame( p_sys->oc, pkt ) < 0 )
{
msg_Err( p_mux, "could not write frame (pts: %"PRId64", dts: %"PRId64") "
"(pkt pts: %"PRId64", dts: %"PRId64")",
- p_data->i_pts, p_data->i_dts, pkt.pts, pkt.dts );
+ p_data->i_pts, p_data->i_dts, pkt->pts, pkt->dts );
block_Release( p_data );
+ av_packet_unref( pkt );
return VLC_EGENERIC;
}
+ av_packet_unref( pkt );
block_Release( p_data );
return VLC_SUCCESS;
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/16fd46fa506424134beb53ec88be3eea1b42a221
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/16fd46fa506424134beb53ec88be3eea1b42a221
You're receiving this email because of your account on code.videolan.org.
More information about the vlc-commits
mailing list