[libav-api] Segfault using avcodec_decode_audio3 in multithreaded app

Ronald S. Bultje rsbultje at gmail.com
Mon Feb 13 22:31:39 CET 2012


Hi,

On Mon, Feb 13, 2012 at 12:19 PM, Ibrahim Sha'ath
<ibrahimshaath at gmail.com> wrote:
>> >>>>>> > [wmav2 @ 0x106829e20] prev_block_len_bits N out of range
>> >>>>>> > (where N is in the range 4..6).
>> >>>>>>
>> >>>>>> Do these errors occur when you're decoding only a single file, without
>> >>>>>> threading?
>> >>>>>
>> >>>>> Yes they do, and on both platforms, though I've never seen them cause
>> >>>>> a segfault when not parallelised. Also interspersed with those errors
>> >>>>> are
>> >>>>> [wmav2 @ 0x1030a9800] overflow in spectral RLE, ignoring
>> >>>>> [wmav2 @ 0x1030a9800] frame_len overflow
>> >>>>>
>> >>>>> And very occasionally
>> >>>>> [wmav2 @ 0x1030a9800] len -211 invalid
>> >>>>>
>> >>>>> Do these errors suggest anything in particular to you?
>> >>>>
>> >>>> Yes, is it possible you're not setting AVCodecContext->bit_rate,
>> >>>> ->block_align, ->extradata or ->extradata_size?
>> >>>
>> >>> I had thought (based on what I'd read in the ffmpeg doxygen) that all
>> >>> of those fields (certainly bit_rate, extra_data and extradata_size)
>> >>> were set internally by libav for decoding, and only needed to be set
>> >>> by the user for encoding?
>> >>>
>> >>> If I'm wrong, could you suggest what I should set them to, for a
>> >>> general decoding solution? I'm seeing no examples online that set
>> >>> them.
>> >>
>> >> They are set, but (in the case of WMA) by the demuxer instead of the
>> >> decoder. My impression is you're not using the
>> >> AVFormatContext->streams[%d]->codec for decoding, but rather create
>> >> one independently. Then you need to copy the demuxer values to the
>> >> decoder values. If you're using your own demuxer instead of
>> >> libavformat's, see libavformat for how to read them.
>> >>
>> >
>> > I'm doing something in the neighbourhood of this:
>> >
>> > AVCodecContext* cCtx = fCtx->streams[audioStream]->codec;
>> > codec = avcodec_find_decoder(cCtx->codec_id);
>> > if(codec == NULL){
>> >  throw Exception();
>> > }
>> > if(avcodec_open2(cCtx, codec, &opts) < 0){
>> >  throw Exception();
>> > }
>> >
>> > And then passing that codec context into the decode job. So I think
>> > that should be fine, no?
>>
>> Probably. Can a tool like avconv or avplay playback the file
>> succesfully without throwing errors?
>
> Yes. Plays back with no errors at all.

Can we see your full code? It's possible you're initializing the code
at the wrong moment when these things aren't known yet...

Ronald


More information about the libav-api mailing list