diff mbox series

[FFmpeg-devel,31/50] avformat/wc3movie: use av_packet_alloc() to allocate packets

Message ID 20210204191005.48190-32-jamrial@gmail.com
State New
Headers show
Series deprecate av_init_packet() and sizeof(AVPacket) as part of the ABI | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

James Almer Feb. 4, 2021, 7:09 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/wc3movie.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

Comments

Andreas Rheinhardt Feb. 7, 2021, 7:52 a.m. UTC | #1
James Almer:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavformat/wc3movie.c | 21 ++++++++++-----------
>  1 file changed, 10 insertions(+), 11 deletions(-)
> 
> diff --git a/libavformat/wc3movie.c b/libavformat/wc3movie.c
> index 76e945d261..1fe582945a 100644
> --- a/libavformat/wc3movie.c
> +++ b/libavformat/wc3movie.c
> @@ -69,7 +69,7 @@ typedef struct Wc3DemuxContext {
>      int video_stream_index;
>      int audio_stream_index;
>  
> -    AVPacket vpkt;
> +    AVPacket *vpkt;
>  
>  } Wc3DemuxContext;
>  
> @@ -77,8 +77,7 @@ static int wc3_read_close(AVFormatContext *s)
>  {
>      Wc3DemuxContext *wc3 = s->priv_data;
>  
> -    if (wc3->vpkt.size > 0)
> -        av_packet_unref(&wc3->vpkt);
> +    av_packet_free(&wc3->vpkt);
>  
>      return 0;
>  }
> @@ -110,8 +109,9 @@ static int wc3_read_header(AVFormatContext *s)
>      wc3->height = WC3_DEFAULT_HEIGHT;
>      wc3->pts = 0;
>      wc3->video_stream_index = wc3->audio_stream_index = 0;
> -    av_init_packet(&wc3->vpkt);
> -    wc3->vpkt.data = NULL; wc3->vpkt.size = 0;
> +    wc3->vpkt = av_packet_alloc();
> +    if (!wc3->vpkt)
> +        goto fail;

goto fail returns 0. You should instead just return AVERROR(ENOMEM)
directly. Nothing has been (successfully) allocated at this point.

>  
>      /* skip the first 3 32-bit numbers */
>      avio_skip(pb, 12);
> @@ -162,7 +162,7 @@ static int wc3_read_header(AVFormatContext *s)
>          case PALT_TAG:
>              /* one of several palettes */
>              avio_seek(pb, -8, SEEK_CUR);
> -            av_append_packet(pb, &wc3->vpkt, 8 + PALETTE_SIZE);
> +            av_append_packet(pb, wc3->vpkt, 8 + PALETTE_SIZE);
>              break;
>  
>          default:
> @@ -248,18 +248,17 @@ static int wc3_read_packet(AVFormatContext *s,
>          case SHOT_TAG:
>              /* load up new palette */
>              avio_seek(pb, -8, SEEK_CUR);
> -            av_append_packet(pb, &wc3->vpkt, 8 + 4);
> +            av_append_packet(pb, wc3->vpkt, 8 + 4);
>              break;
>  
>          case VGA__TAG:
>              /* send out video chunk */
>              avio_seek(pb, -8, SEEK_CUR);
> -            ret= av_append_packet(pb, &wc3->vpkt, 8 + size);
> +            ret= av_append_packet(pb, wc3->vpkt, 8 + size);
>              // ignore error if we have some data
> -            if (wc3->vpkt.size > 0)
> +            if (wc3->vpkt->size > 0)
>                  ret = 0;
> -            *pkt = wc3->vpkt;
> -            wc3->vpkt.data = NULL; wc3->vpkt.size = 0;
> +            av_packet_move_ref(pkt, wc3->vpkt);
>              pkt->stream_index = wc3->video_stream_index;
>              pkt->pts = wc3->pts;
>              packet_read = 1;
>
James Almer Feb. 7, 2021, 1:09 p.m. UTC | #2
On 2/7/2021 4:52 AM, Andreas Rheinhardt wrote:
> James Almer:
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>   libavformat/wc3movie.c | 21 ++++++++++-----------
>>   1 file changed, 10 insertions(+), 11 deletions(-)
>>
>> diff --git a/libavformat/wc3movie.c b/libavformat/wc3movie.c
>> index 76e945d261..1fe582945a 100644
>> --- a/libavformat/wc3movie.c
>> +++ b/libavformat/wc3movie.c
>> @@ -69,7 +69,7 @@ typedef struct Wc3DemuxContext {
>>       int video_stream_index;
>>       int audio_stream_index;
>>   
>> -    AVPacket vpkt;
>> +    AVPacket *vpkt;
>>   
>>   } Wc3DemuxContext;
>>   
>> @@ -77,8 +77,7 @@ static int wc3_read_close(AVFormatContext *s)
>>   {
>>       Wc3DemuxContext *wc3 = s->priv_data;
>>   
>> -    if (wc3->vpkt.size > 0)
>> -        av_packet_unref(&wc3->vpkt);
>> +    av_packet_free(&wc3->vpkt);
>>   
>>       return 0;
>>   }
>> @@ -110,8 +109,9 @@ static int wc3_read_header(AVFormatContext *s)
>>       wc3->height = WC3_DEFAULT_HEIGHT;
>>       wc3->pts = 0;
>>       wc3->video_stream_index = wc3->audio_stream_index = 0;
>> -    av_init_packet(&wc3->vpkt);
>> -    wc3->vpkt.data = NULL; wc3->vpkt.size = 0;
>> +    wc3->vpkt = av_packet_alloc();
>> +    if (!wc3->vpkt)
>> +        goto fail;
> 
> goto fail returns 0. You should instead just return AVERROR(ENOMEM)
> directly. Nothing has been (successfully) allocated at this point.

Changed locally. Thanks.

> 
>>   
>>       /* skip the first 3 32-bit numbers */
>>       avio_skip(pb, 12);
>> @@ -162,7 +162,7 @@ static int wc3_read_header(AVFormatContext *s)
>>           case PALT_TAG:
>>               /* one of several palettes */
>>               avio_seek(pb, -8, SEEK_CUR);
>> -            av_append_packet(pb, &wc3->vpkt, 8 + PALETTE_SIZE);
>> +            av_append_packet(pb, wc3->vpkt, 8 + PALETTE_SIZE);
>>               break;
>>   
>>           default:
>> @@ -248,18 +248,17 @@ static int wc3_read_packet(AVFormatContext *s,
>>           case SHOT_TAG:
>>               /* load up new palette */
>>               avio_seek(pb, -8, SEEK_CUR);
>> -            av_append_packet(pb, &wc3->vpkt, 8 + 4);
>> +            av_append_packet(pb, wc3->vpkt, 8 + 4);
>>               break;
>>   
>>           case VGA__TAG:
>>               /* send out video chunk */
>>               avio_seek(pb, -8, SEEK_CUR);
>> -            ret= av_append_packet(pb, &wc3->vpkt, 8 + size);
>> +            ret= av_append_packet(pb, wc3->vpkt, 8 + size);
>>               // ignore error if we have some data
>> -            if (wc3->vpkt.size > 0)
>> +            if (wc3->vpkt->size > 0)
>>                   ret = 0;
>> -            *pkt = wc3->vpkt;
>> -            wc3->vpkt.data = NULL; wc3->vpkt.size = 0;
>> +            av_packet_move_ref(pkt, wc3->vpkt);
>>               pkt->stream_index = wc3->video_stream_index;
>>               pkt->pts = wc3->pts;
>>               packet_read = 1;
>>
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
diff mbox series

Patch

diff --git a/libavformat/wc3movie.c b/libavformat/wc3movie.c
index 76e945d261..1fe582945a 100644
--- a/libavformat/wc3movie.c
+++ b/libavformat/wc3movie.c
@@ -69,7 +69,7 @@  typedef struct Wc3DemuxContext {
     int video_stream_index;
     int audio_stream_index;
 
-    AVPacket vpkt;
+    AVPacket *vpkt;
 
 } Wc3DemuxContext;
 
@@ -77,8 +77,7 @@  static int wc3_read_close(AVFormatContext *s)
 {
     Wc3DemuxContext *wc3 = s->priv_data;
 
-    if (wc3->vpkt.size > 0)
-        av_packet_unref(&wc3->vpkt);
+    av_packet_free(&wc3->vpkt);
 
     return 0;
 }
@@ -110,8 +109,9 @@  static int wc3_read_header(AVFormatContext *s)
     wc3->height = WC3_DEFAULT_HEIGHT;
     wc3->pts = 0;
     wc3->video_stream_index = wc3->audio_stream_index = 0;
-    av_init_packet(&wc3->vpkt);
-    wc3->vpkt.data = NULL; wc3->vpkt.size = 0;
+    wc3->vpkt = av_packet_alloc();
+    if (!wc3->vpkt)
+        goto fail;
 
     /* skip the first 3 32-bit numbers */
     avio_skip(pb, 12);
@@ -162,7 +162,7 @@  static int wc3_read_header(AVFormatContext *s)
         case PALT_TAG:
             /* one of several palettes */
             avio_seek(pb, -8, SEEK_CUR);
-            av_append_packet(pb, &wc3->vpkt, 8 + PALETTE_SIZE);
+            av_append_packet(pb, wc3->vpkt, 8 + PALETTE_SIZE);
             break;
 
         default:
@@ -248,18 +248,17 @@  static int wc3_read_packet(AVFormatContext *s,
         case SHOT_TAG:
             /* load up new palette */
             avio_seek(pb, -8, SEEK_CUR);
-            av_append_packet(pb, &wc3->vpkt, 8 + 4);
+            av_append_packet(pb, wc3->vpkt, 8 + 4);
             break;
 
         case VGA__TAG:
             /* send out video chunk */
             avio_seek(pb, -8, SEEK_CUR);
-            ret= av_append_packet(pb, &wc3->vpkt, 8 + size);
+            ret= av_append_packet(pb, wc3->vpkt, 8 + size);
             // ignore error if we have some data
-            if (wc3->vpkt.size > 0)
+            if (wc3->vpkt->size > 0)
                 ret = 0;
-            *pkt = wc3->vpkt;
-            wc3->vpkt.data = NULL; wc3->vpkt.size = 0;
+            av_packet_move_ref(pkt, wc3->vpkt);
             pkt->stream_index = wc3->video_stream_index;
             pkt->pts = wc3->pts;
             packet_read = 1;