[FFmpeg-trac] #361(avcodec:new): avcodec_decode_audio3 SEGFAULT while decoding certain codec types

FFmpeg trac at avcodec.org
Thu Jul 28 16:03:44 CEST 2011


#361: avcodec_decode_audio3 SEGFAULT while decoding certain codec types
-------------------------------------------------+-------------------------
Reporter:  danijel                               |       Owner:
    Type:  defect                                |      Status:  new
Priority:  important                             |   Component:  avcodec
 Version:  git                                   |  Resolution:
Keywords:  avcodec decode segfault float int     |  Blocked By:
  conversion                                     |  Reproduced:  0
Blocking:                                        |
Analyzed:  0                                     |
-------------------------------------------------+-------------------------

Comment (by danijel):

 Ok, I found and fixed the problem. It was also fixed on an external forum:
 http://forum.visionopen.com/viewtopic.php?f=31&t=3057

 The reason was a note in the documentation (note the bold):
 > You might have to align the input buffer avpkt->data '''and output
 buffer''' samples. The alignment requirements depend on the CPU: On some
 CPUs it isn't necessary at all, on others it won't work at all if not
 aligned and on others it will work but it will have an impact on
 performance.

 Since I used packets decoded by the library I thought all is fine, but
 somehow missed that the output buffer also has to be aligned.

 The error is kind of strange, since all the values are correct (all the
 arrays can be debugged and analyzed by GDB), but the system still throws
 out a SEGFAULT. It turns out that an SSE2 assembler command "MOVDQA"
 throws out a general protection fault if the source and destination is not
 aligned properly.

 To fix he problem, it's enough to declare the output buffer correctly:

 {{{
 DECLARE_ALIGNED(16,uint8_t,outbuf)[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) /
 2];
 }}}

 Or alternatively use {{{av_malloc}}} as described here:
 http://ffmpeg.org/doxygen/trunk/mem_8c.html

 And then, you can use the "decode_audio" method without any issues, like
 this:
 {{{
 outbuf_size=sizeof(outbuf);
 ret=dynamic_ffmpeg::avcodec_decode_audio3(pCodecCtx,(short*)outbuf,&outbuf_size,&currpkt);
 }}}

 I would also like to add that the "audio_decode_example" in libavcodec
 /api-example.c is incorrect in this fashion and should be updated. Just to
 make things clear, this code will work on some machines and compilers
 without any errors. Namely, if compiled using MinGW, it works fine, but
 under GCC it will bug out, since GCC doesn't automatically align its
 memory and MinGW does (source:
 http://ffmpeg.arrozcru.org/forum/viewtopic.php?f=1&t=549)

-- 
Ticket URL: <https://ffmpeg.org/trac/ffmpeg/ticket/361#comment:1>
FFmpeg <http://ffmpeg.org>
FFmpeg issue tracker


More information about the FFmpeg-trac mailing list