diff mbox series

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

Message ID 20210204191005.48190-20-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/flacdec.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

Comments

Andreas Rheinhardt Feb. 8, 2021, 6:43 p.m. UTC | #1
James Almer:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavformat/flacdec.c | 20 ++++++++++++--------
>  1 file changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
> index 6aca4755a1..7852a79d39 100644
> --- a/libavformat/flacdec.c
> +++ b/libavformat/flacdec.c
> @@ -259,7 +259,7 @@ static int flac_probe(const AVProbeData *p)
>  static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_index,
>                                               int64_t *ppos, int64_t pos_limit)
>  {
> -    AVPacket pkt;
> +    AVPacket *pkt;
>      AVStream *st = s->streams[stream_index];
>      AVCodecParserContext *parser;
>      int ret;
> @@ -268,9 +268,12 @@ static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde
>      if (avio_seek(s->pb, *ppos, SEEK_SET) < 0)
>          return AV_NOPTS_VALUE;
>  
> -    av_init_packet(&pkt);
> +    pkt = av_packet_alloc();
> +    if (!pkt)
> +        return AV_NOPTS_VALUE;
>      parser = av_parser_init(st->codecpar->codec_id);
>      if (!parser){
> +        av_packet_free(&pkt);
>          return AV_NOPTS_VALUE;
>      }
>      parser->flags |= PARSER_FLAG_USE_CODEC_TS;
> @@ -279,20 +282,20 @@ static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde
>          uint8_t *data;
>          int size;
>  
> -        ret = ff_raw_read_partial_packet(s, &pkt);
> +        ret = ff_raw_read_partial_packet(s, pkt);
>          if (ret < 0){
>              if (ret == AVERROR(EAGAIN))
>                  continue;
>              else {
> -                av_packet_unref(&pkt);
> -                av_assert1(!pkt.size);
> +                av_packet_unref(pkt);
> +                av_assert1(!pkt->size);
>              }
>          }
>          av_parser_parse2(parser, st->internal->avctx,
> -                         &data, &size, pkt.data, pkt.size,
> -                         pkt.pts, pkt.dts, *ppos);
> +                         &data, &size, pkt->data, pkt->size,
> +                         pkt->pts, pkt->dts, *ppos);
>  
> -        av_packet_unref(&pkt);
> +        av_packet_unref(pkt);
>          if (size) {
>              if (parser->pts != AV_NOPTS_VALUE){
>                  // seeking may not have started from beginning of a frame
> @@ -304,6 +307,7 @@ static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde
>          } else if (ret < 0)
>              break;
>      }
> +    av_packet_free(&pkt);
>      av_parser_close(parser);
>      return pts;
>  }
> 
The parse_packet is unused during this function, so it can be reused.

- Andreas
James Almer Feb. 8, 2021, 6:55 p.m. UTC | #2
On 2/8/2021 3:43 PM, Andreas Rheinhardt wrote:
> James Almer:
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>   libavformat/flacdec.c | 20 ++++++++++++--------
>>   1 file changed, 12 insertions(+), 8 deletions(-)
>>
>> diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
>> index 6aca4755a1..7852a79d39 100644
>> --- a/libavformat/flacdec.c
>> +++ b/libavformat/flacdec.c
>> @@ -259,7 +259,7 @@ static int flac_probe(const AVProbeData *p)
>>   static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_index,
>>                                                int64_t *ppos, int64_t pos_limit)
>>   {
>> -    AVPacket pkt;
>> +    AVPacket *pkt;
>>       AVStream *st = s->streams[stream_index];
>>       AVCodecParserContext *parser;
>>       int ret;
>> @@ -268,9 +268,12 @@ static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde
>>       if (avio_seek(s->pb, *ppos, SEEK_SET) < 0)
>>           return AV_NOPTS_VALUE;
>>   
>> -    av_init_packet(&pkt);
>> +    pkt = av_packet_alloc();
>> +    if (!pkt)
>> +        return AV_NOPTS_VALUE;
>>       parser = av_parser_init(st->codecpar->codec_id);
>>       if (!parser){
>> +        av_packet_free(&pkt);
>>           return AV_NOPTS_VALUE;
>>       }
>>       parser->flags |= PARSER_FLAG_USE_CODEC_TS;
>> @@ -279,20 +282,20 @@ static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde
>>           uint8_t *data;
>>           int size;
>>   
>> -        ret = ff_raw_read_partial_packet(s, &pkt);
>> +        ret = ff_raw_read_partial_packet(s, pkt);
>>           if (ret < 0){
>>               if (ret == AVERROR(EAGAIN))
>>                   continue;
>>               else {
>> -                av_packet_unref(&pkt);
>> -                av_assert1(!pkt.size);
>> +                av_packet_unref(pkt);
>> +                av_assert1(!pkt->size);
>>               }
>>           }
>>           av_parser_parse2(parser, st->internal->avctx,
>> -                         &data, &size, pkt.data, pkt.size,
>> -                         pkt.pts, pkt.dts, *ppos);
>> +                         &data, &size, pkt->data, pkt->size,
>> +                         pkt->pts, pkt->dts, *ppos);
>>   
>> -        av_packet_unref(&pkt);
>> +        av_packet_unref(pkt);
>>           if (size) {
>>               if (parser->pts != AV_NOPTS_VALUE){
>>                   // seeking may not have started from beginning of a frame
>> @@ -304,6 +307,7 @@ static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde
>>           } else if (ret < 0)
>>               break;
>>       }
>> +    av_packet_free(&pkt);
>>       av_parser_close(parser);
>>       return pts;
>>   }
>>
> The parse_packet is unused during this function, so it can be reused.

The AVFormatInternal one? Good idea.
diff mbox series

Patch

diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index 6aca4755a1..7852a79d39 100644
--- a/libavformat/flacdec.c
+++ b/libavformat/flacdec.c
@@ -259,7 +259,7 @@  static int flac_probe(const AVProbeData *p)
 static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_index,
                                              int64_t *ppos, int64_t pos_limit)
 {
-    AVPacket pkt;
+    AVPacket *pkt;
     AVStream *st = s->streams[stream_index];
     AVCodecParserContext *parser;
     int ret;
@@ -268,9 +268,12 @@  static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde
     if (avio_seek(s->pb, *ppos, SEEK_SET) < 0)
         return AV_NOPTS_VALUE;
 
-    av_init_packet(&pkt);
+    pkt = av_packet_alloc();
+    if (!pkt)
+        return AV_NOPTS_VALUE;
     parser = av_parser_init(st->codecpar->codec_id);
     if (!parser){
+        av_packet_free(&pkt);
         return AV_NOPTS_VALUE;
     }
     parser->flags |= PARSER_FLAG_USE_CODEC_TS;
@@ -279,20 +282,20 @@  static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde
         uint8_t *data;
         int size;
 
-        ret = ff_raw_read_partial_packet(s, &pkt);
+        ret = ff_raw_read_partial_packet(s, pkt);
         if (ret < 0){
             if (ret == AVERROR(EAGAIN))
                 continue;
             else {
-                av_packet_unref(&pkt);
-                av_assert1(!pkt.size);
+                av_packet_unref(pkt);
+                av_assert1(!pkt->size);
             }
         }
         av_parser_parse2(parser, st->internal->avctx,
-                         &data, &size, pkt.data, pkt.size,
-                         pkt.pts, pkt.dts, *ppos);
+                         &data, &size, pkt->data, pkt->size,
+                         pkt->pts, pkt->dts, *ppos);
 
-        av_packet_unref(&pkt);
+        av_packet_unref(pkt);
         if (size) {
             if (parser->pts != AV_NOPTS_VALUE){
                 // seeking may not have started from beginning of a frame
@@ -304,6 +307,7 @@  static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde
         } else if (ret < 0)
             break;
     }
+    av_packet_free(&pkt);
     av_parser_close(parser);
     return pts;
 }