diff mbox

[FFmpeg-devel,4/4] avformat/flacdec: Remove useless packet

Message ID 20191008054116.60992-4-andreas.rheinhardt@gmail.com
State Accepted
Commit 5d8d9e032cafa88e99046478090dd5a629e3d51c
Headers show

Commit Message

Andreas Rheinhardt Oct. 8, 2019, 5:41 a.m. UTC
flac_read_timestamp() applied av_init_packet() to a packet (which
initializes all fields of the packet except for data and size) and then
went on to use only the data and size fields. In other words: Said
packet can be removed and replaced by an uint8_t * and an int.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/flacdec.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

Comments

Paul B Mahol Oct. 8, 2019, 7:24 a.m. UTC | #1
lgtm

On 10/8/19, Andreas Rheinhardt <andreas.rheinhardt@gmail.com> wrote:
> flac_read_timestamp() applied av_init_packet() to a packet (which
> initializes all fields of the packet except for data and size) and then
> went on to use only the data and size fields. In other words: Said
> packet can be removed and replaced by an uint8_t * and an int.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/flacdec.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
> index 8394e47483..cb516fb1f3 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, out_pkt;
> +    AVPacket pkt;
>      AVStream *st = s->streams[stream_index];
>      AVCodecParserContext *parser;
>      int ret;
> @@ -276,6 +276,9 @@ static av_unused int64_t
> flac_read_timestamp(AVFormatContext *s, int stream_inde
>      parser->flags |= PARSER_FLAG_USE_CODEC_TS;
>
>      for (;;){
> +        uint8_t *data;
> +        int size;
> +
>          ret = ff_raw_read_partial_packet(s, &pkt);
>          if (ret < 0){
>              if (ret == AVERROR(EAGAIN))
> @@ -285,14 +288,12 @@ static av_unused int64_t
> flac_read_timestamp(AVFormatContext *s, int stream_inde
>                  av_assert1(!pkt.size);
>              }
>          }
> -        av_init_packet(&out_pkt);
>          av_parser_parse2(parser, st->internal->avctx,
> -                         &out_pkt.data, &out_pkt.size, pkt.data, pkt.size,
> +                         &data, &size, pkt.data, pkt.size,
>                           pkt.pts, pkt.dts, *ppos);
>
>          av_packet_unref(&pkt);
> -        if (out_pkt.size){
> -            int size = out_pkt.size;
> +        if (size) {
>              if (parser->pts != AV_NOPTS_VALUE){
>                  // seeking may not have started from beginning of a frame
>                  // calculate frame start position from next frame backwards
> --
> 2.21.0
>
> _______________________________________________
> 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".
Michael Niedermayer Nov. 17, 2019, 10:37 p.m. UTC | #2
On Tue, Oct 08, 2019 at 09:24:29AM +0200, Paul B Mahol wrote:
> lgtm

will apply

[...]
diff mbox

Patch

diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index 8394e47483..cb516fb1f3 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, out_pkt;
+    AVPacket pkt;
     AVStream *st = s->streams[stream_index];
     AVCodecParserContext *parser;
     int ret;
@@ -276,6 +276,9 @@  static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde
     parser->flags |= PARSER_FLAG_USE_CODEC_TS;
 
     for (;;){
+        uint8_t *data;
+        int size;
+
         ret = ff_raw_read_partial_packet(s, &pkt);
         if (ret < 0){
             if (ret == AVERROR(EAGAIN))
@@ -285,14 +288,12 @@  static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde
                 av_assert1(!pkt.size);
             }
         }
-        av_init_packet(&out_pkt);
         av_parser_parse2(parser, st->internal->avctx,
-                         &out_pkt.data, &out_pkt.size, pkt.data, pkt.size,
+                         &data, &size, pkt.data, pkt.size,
                          pkt.pts, pkt.dts, *ppos);
 
         av_packet_unref(&pkt);
-        if (out_pkt.size){
-            int size = out_pkt.size;
+        if (size) {
             if (parser->pts != AV_NOPTS_VALUE){
                 // seeking may not have started from beginning of a frame
                 // calculate frame start position from next frame backwards