diff mbox series

[FFmpeg-devel] avformat/3dostr: Return directly after having read packet

Message ID 20200727032348.17362-1-andreas.rheinhardt@gmail.com
State Accepted
Commit edcd7c735c098a3b72cada2c791d04b4428b145d
Headers show
Series [FFmpeg-devel] avformat/3dostr: Return directly after having read packet
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt July 27, 2020, 3:23 a.m. UTC
Avoids an avio_skip(s->pb, 0).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/3dostr.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

Comments

Paul B Mahol July 27, 2020, 6:58 a.m. UTC | #1
Make sure this does not break demuxing/decoding.

On 7/27/20, Andreas Rheinhardt <andreas.rheinhardt@gmail.com> wrote:
> Avoids an avio_skip(s->pb, 0).
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/3dostr.c | 13 ++++---------
>  1 file changed, 4 insertions(+), 9 deletions(-)
>
> diff --git a/libavformat/3dostr.c b/libavformat/3dostr.c
> index 6c49f7589c..3ec3c4393e 100644
> --- a/libavformat/3dostr.c
> +++ b/libavformat/3dostr.c
> @@ -110,15 +110,12 @@ static int threedostr_read_header(AVFormatContext *s)
>
>  static int threedostr_read_packet(AVFormatContext *s, AVPacket *pkt)
>  {
> -    unsigned chunk, size, found_ssmp = 0;
> +    unsigned chunk, size;
>      AVStream *st = s->streams[0];
>      int64_t pos;
>      int ret = 0;
>
> -    while (!found_ssmp) {
> -        if (avio_feof(s->pb))
> -            return AVERROR_EOF;
> -
> +    while (!avio_feof(s->pb)) {
>          pos   = avio_tell(s->pb);
>          chunk = avio_rl32(s->pb);
>          size  = avio_rb32(s->pb);
> @@ -143,9 +140,7 @@ static int threedostr_read_packet(AVFormatContext *s,
> AVPacket *pkt)
>              pkt->pos = pos;
>              pkt->stream_index = 0;
>              pkt->duration = size / st->codecpar->channels;
> -            size = 0;
> -            found_ssmp = 1;
> -            break;
> +            return ret;
>          default:
>              av_log(s, AV_LOG_DEBUG, "skipping unknown chunk: %X\n", chunk);
>              break;
> @@ -154,7 +149,7 @@ static int threedostr_read_packet(AVFormatContext *s,
> AVPacket *pkt)
>          avio_skip(s->pb, size);
>      }
>
> -    return ret;
> +    return AVERROR_EOF;
>  }
>
>  AVInputFormat ff_threedostr_demuxer = {
> --
> 2.20.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".
Andreas Rheinhardt July 27, 2020, 7:06 a.m. UTC | #2
Paul B Mahol:
> Make sure this does not break demuxing/decoding.
> 

This patch is designed to not change the packets output by the demuxer
or the demuxer's return value at all. I have tested this with a small
sample created in a hex editor, but only demuxing (as the content of the
packet was garbage). I'd like to test this with a real sample, but
couldn't find one. Do you have one (after all, you wrote that demuxer)?

- Andreas
Paul B Mahol July 27, 2020, 7:37 a.m. UTC | #3
On 7/27/20, Andreas Rheinhardt <andreas.rheinhardt@gmail.com> wrote:
> Paul B Mahol:
>> Make sure this does not break demuxing/decoding.
>>
>
> This patch is designed to not change the packets output by the demuxer
> or the demuxer's return value at all. I have tested this with a small
> sample created in a hex editor, but only demuxing (as the content of the
> packet was garbage). I'd like to test this with a real sample, but
> couldn't find one. Do you have one (after all, you wrote that demuxer)?
>

Find it on web. It is used in old dos games, like DOOM.

> - Andreas
> _______________________________________________
> 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".
Andreas Rheinhardt Aug. 1, 2020, 4:44 p.m. UTC | #4
Paul B Mahol:
> On 7/27/20, Andreas Rheinhardt <andreas.rheinhardt@gmail.com> wrote:
>> Paul B Mahol:
>>> Make sure this does not break demuxing/decoding.
>>>
>>
>> This patch is designed to not change the packets output by the demuxer
>> or the demuxer's return value at all. I have tested this with a small
>> sample created in a hex editor, but only demuxing (as the content of the
>> packet was garbage). I'd like to test this with a real sample, but
>> couldn't find one. Do you have one (after all, you wrote that demuxer)?
>>
> 
> Find it on web. It is used in old dos games, like DOOM.
> 

I have now tested this and the output is of course unchanged (as
expected). Will apply tomorrow unless there are objections.

- Andreas
diff mbox series

Patch

diff --git a/libavformat/3dostr.c b/libavformat/3dostr.c
index 6c49f7589c..3ec3c4393e 100644
--- a/libavformat/3dostr.c
+++ b/libavformat/3dostr.c
@@ -110,15 +110,12 @@  static int threedostr_read_header(AVFormatContext *s)
 
 static int threedostr_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
-    unsigned chunk, size, found_ssmp = 0;
+    unsigned chunk, size;
     AVStream *st = s->streams[0];
     int64_t pos;
     int ret = 0;
 
-    while (!found_ssmp) {
-        if (avio_feof(s->pb))
-            return AVERROR_EOF;
-
+    while (!avio_feof(s->pb)) {
         pos   = avio_tell(s->pb);
         chunk = avio_rl32(s->pb);
         size  = avio_rb32(s->pb);
@@ -143,9 +140,7 @@  static int threedostr_read_packet(AVFormatContext *s, AVPacket *pkt)
             pkt->pos = pos;
             pkt->stream_index = 0;
             pkt->duration = size / st->codecpar->channels;
-            size = 0;
-            found_ssmp = 1;
-            break;
+            return ret;
         default:
             av_log(s, AV_LOG_DEBUG, "skipping unknown chunk: %X\n", chunk);
             break;
@@ -154,7 +149,7 @@  static int threedostr_read_packet(AVFormatContext *s, AVPacket *pkt)
         avio_skip(s->pb, size);
     }
 
-    return ret;
+    return AVERROR_EOF;
 }
 
 AVInputFormat ff_threedostr_demuxer = {