[FFmpeg-devel] [PATCH] avformat/aacdec: add a custom read_packet function

Michael Niedermayer michael at niedermayer.cc
Sun Jun 4 14:44:01 EEST 2017


On Sat, Jun 03, 2017 at 06:14:12PM -0300, James Almer wrote:
> On 6/3/2017 5:16 PM, Michael Niedermayer wrote:
> > On Sat, Jun 03, 2017 at 12:33:33AM -0300, James Almer wrote:
> >> Atempt to read and propagate only full ADTS frames and not other data,
> >> like id3v1 or APETags at the end of the file.
> >>
> >> Fixes ticket #6439.
> >>
> >> Signed-off-by: James Almer <jamrial at gmail.com>
> >> ---
> >>  libavformat/aacdec.c | 42 ++++++++++++++++++++++++++++++++++++++++--
> >>  1 file changed, 40 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/libavformat/aacdec.c b/libavformat/aacdec.c
> >> index 5ab5197e33..aee1efe03c 100644
> >> --- a/libavformat/aacdec.c
> >> +++ b/libavformat/aacdec.c
> >> @@ -23,10 +23,11 @@
> >>  #include "libavutil/intreadwrite.h"
> >>  #include "avformat.h"
> >>  #include "internal.h"
> >> -#include "rawdec.h"
> >>  #include "id3v1.h"
> >>  #include "apetag.h"
> >>  
> >> +#define ADTS_HEADER_SIZE 7
> >> +
> >>  static int adts_aac_probe(AVProbeData *p)
> >>  {
> >>      int max_frames = 0, first_frames = 0;
> >> @@ -79,6 +80,7 @@ static int adts_aac_probe(AVProbeData *p)
> >>  static int adts_aac_read_header(AVFormatContext *s)
> >>  {
> >>      AVStream *st;
> >> +    uint16_t state;
> >>  
> >>      st = avformat_new_stream(s, NULL);
> >>      if (!st)
> >> @@ -96,18 +98,54 @@ static int adts_aac_read_header(AVFormatContext *s)
> >>          avio_seek(s->pb, cur, SEEK_SET);
> >>      }
> >>  
> >> +    // skip data until the first ADTS frame is found
> >> +    state = avio_r8(s->pb);
> >> +    while (!avio_feof(s->pb)) {
> >> +        state = (state << 8) | avio_r8(s->pb);
> >> +        if ((state >> 4) != 0xFFF)
> >> +            continue;
> >> +        avio_seek(s->pb, -2, SEEK_CUR);
> >> +        break;
> >> +    }
> > 
> > this would loop forever with /dev/zero as input
> 
> How can i prevent this? Maybe checking a max of
> AVFormatContext.probesize or AVFormatContext.format_probesize bytes
> before bailing out? Which one if so?

id tend toward probesize, but anything will do.

thx

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I know you won't believe me, but the highest form of Human Excellence is
to question oneself and others. -- Socrates
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20170604/66ade2dc/attachment.sig>


More information about the ffmpeg-devel mailing list