[FFmpeg-devel] [PATCH] start FLAC decoding mid-stream

Michael Niedermayer michaelni
Tue Dec 9 00:25:52 CET 2008


On Mon, Dec 08, 2008 at 05:48:29PM -0500, Justin Ruggles wrote:
> Michael Niedermayer wrote:
> > On Sun, Dec 07, 2008 at 05:32:02PM -0500, Justin Ruggles wrote:
> >> Justin Ruggles wrote:
> >>> Hi,
> >>>
> >>> As mentioned in another thread, our FLAC decoder cannot start decoding
> >>> mid-stream without having the STREAMINFO.  The FLAC format allows for
> >>> doing this as long as each frame header supplies all the necessary info.
> >>>
> >>> Here is a patch to allow decoding starting anywhere in a FLAC stream.
> >>>
> >>> Thanks,
> >>> Justin
> >> Here is a slightly better version which only allocates buffers once if
> >> starting mid-stream.
> >>
> >> -Justin
> >>
> > 
[...]
> > 
> >> @@ -495,12 +500,25 @@ static int decode_frame(FLACContext *s, int alloc_
> >>  {
> >>      int blocksize_code, sample_rate_code, sample_size_code, assignment, i, crc8;
> >>      int decorrelation, bps, blocksize, samplerate;
> >> +    int allocate_buffers = 0;
> >>  
> >>      blocksize_code = get_bits(&s->gb, 4);
> >>  
> >>      sample_rate_code = get_bits(&s->gb, 4);
> >>  
> >>      assignment = get_bits(&s->gb, 4); /* channel assignment */
> >> +    if (s->channels < 0)
> >> +    {
> >> +        if (assignment < 8)
> >> +        {
> >> +            s->channels = assignment + 1;
> >> +        }
> >> +        else
> >> +        {
> >> +            s->channels = 2;
> >> +        }
> >> +        allocate_buffers = 1;
> >> +    }
> > 
> > why is this under channels < 0 ?
> 
> The idea was that the number of channels shouldn't change mid-stream.
> That is not currently supported, but I could fabricate a test stream and
> try to support it.  Then again, I don't know if ffmpeg/ffplay would
> support it either.  It is handled in AC3 by silently changing the mixing
> within the decoder, but I don't think that would be desirable for a
> lossless codec.
> 
> > 
> > [...]
> >> @@ -570,6 +605,12 @@ static int decode_frame(FLACContext *s, int alloc_
> >>          av_log(s->avctx, AV_LOG_ERROR, "illegal sample rate code %d\n", sample_rate_code);
> >>          return -1;
> >>      }
> >> +    if (s->samplerate < 0) {
> >> +        s->avctx->sample_rate = samplerate;
> > 
> >> +    } else if (samplerate != s->avctx->sample_rate) {
> >> +        av_log(s->avctx, AV_LOG_ERROR, "cannot change sample rate mid-stream\n");
> >> +        return -1;
> >> +    }
> >>  
> >>      skip_bits(&s->gb, 8);
> >>      crc8 = av_crc(av_crc_get_table(AV_CRC_8_ATM), 0,
> > 
> > what is the problem with it changing?
> 
> Same deal as channels (and bps for that matter).  I can try to add
> support for it.  It would be interesting to see how libFLAC handles it,
> so I'll give it a shot.

thanks
my reasoning was that not supporting changing samplerate/channels is ok
but explicitly checking for it and then failing seemed odd.

ffmpeg is likely not going to like changing such things but at least it
should not crash, if it does report it and ill look into it.


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

While the State exists there can be no freedom; when there is freedom there
will be no State. -- Vladimir Lenin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20081209/7628e0e4/attachment.pgp>



More information about the ffmpeg-devel mailing list