[FFmpeg-devel] alsa: Can't add support for different codecs

Alexey Balekhov a at balek.ru
Thu Feb 13 06:36:38 CET 2014


Hello. I have a soundcard, which outputs G.723 stream (actually it's
Bluecherry's video/audio capture card). I want to decode audio with ffmpeg,
but I can't add support to the alsa libavdevice.

I've modified codec_id_to_pcm_format from libavdevice/alsa-audio-common.c:
case AV_CODEC_ID_ADPCM_G726: return SND_PCM_FORMAT_U8;

But when I run ffmpeg, it crashes with segfault. The same thing for tests
with other decoders: AV_CODEC_ID_ADPCM_G722, AV_CODEC_ID_MP3. But
AV_CODEC_ID_PCM_S16LE_PLANAR works fine. I ran ffmpeg through gdb and found
that all crashes happen in different places for different codecs:

Starting program: /home/build/ffmpeg-dmo-2.1.3/ffmpeg_g -loglevel debug -f
alsa -acodec g726 -ar 8000 -ac 1 -i hw:0,0,5 -f s16le test.pcm
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
ffmpeg version 2.1.3 Copyright (c) 2000-2013 the FFmpeg developers
  built on Feb 13 2014 09:02:39 with gcc 4.7 (Debian 4.7.2-5)
  configuration: --prefix=/usr --extra-cflags='-g -O2 -fstack-protector
--param=ssp-buffer-size=4 -Wformat -Werror=format-security '
--extra-ldflags='-Wl,-z,relro' --cc='ccache cc' --enable-shared
--enable-libmp3lame --enable-gpl --enable-nonfree --enable-libvorbis
--enable-pthreads --enable-libfaac --enable-libxvid --enable-postproc
--enable-x11grab --enable-libgsm --enable-libtheora
--enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264
--enable-libspeex --enable-nonfree --disable-stripping --enable-libvpx
--enable-libschroedinger --disable-encoder=libschroedinger
--enable-version3 --enable-libopenjpeg --enable-librtmp --enable-avfilter
--enable-libfreetype --enable-libvo-aacenc --disable-decoder=amrnb
--enable-libvo-amrwbenc --enable-libaacplus
--libdir=/usr/lib/x86_64-linux-gnu --disable-vda --enable-libbluray
--enable-libcdio --enable-gnutls --enable-frei0r --enable-openssl
--enable-libass --enable-libopus --enable-fontconfig --enable-libpulse
--disable-mips32r2 --disable-mipsdspr1 --disable-mipsdspr2
--enable-libvidstab --enable-libzvbi --enable-avresample --enable-shared
--disable-optimizations --disable-mmx --disable-stripping
--enable-libiec61883 --enable-libfdk-aac --enable-vaapi --enable-libdc1394
--disable-altivec --disable-armv5te --disable-armv6 --disable-vis
--shlibdir=/usr/lib/x86_64-linux-gnu
  libavutil      52. 48.101 / 52. 48.101
  libavcodec     55. 39.101 / 55. 39.101
  libavformat    55. 19.104 / 55. 19.104
  libavdevice    55.  5.100 / 55.  5.100
  libavfilter     3. 90.100 /  3. 90.100
  libavresample   1.  1.  0 /  1.  1.  0
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Splitting the commandline.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging
level) with argument 'debug'.
Reading option '-f' ... matched as option 'f' (force format) with argument
'alsa'.
Reading option '-acodec' ... matched as option 'acodec' (force audio codec
('copy' to copy stream)) with argument 'g726'.
Reading option '-ar' ... matched as option 'ar' (set audio sampling rate
(in Hz)) with argument '8000'.
Reading option '-ac' ... matched as option 'ac' (set number of audio
channels) with argument '1'.
Reading option '-i' ... matched as input file with argument 'hw:0,0,5'.
Reading option '-f' ... matched as option 'f' (force format) with argument
's16le'.
Reading option 'test.pcm' ... matched as output file.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option loglevel (set logging level) with argument debug.
Successfully parsed a group of options.
Parsing a group of options: input file hw:0,0,5.
Applying option f (force format) with argument alsa.
Applying option acodec (force audio codec ('copy' to copy stream)) with
argument g726.
Applying option ar (set audio sampling rate (in Hz)) with argument 8000.
Applying option ac (set number of audio channels) with argument 1.
Successfully parsed a group of options.
Opening an input file: hw:0,0,5.

Program received signal SIGSEGV, Segmentation fault.
malloc_consolidate (av=0x7ffff5747e60) at malloc.c:5184
5184    malloc.c: No such file or directory.
(gdb) bt
#0  malloc_consolidate (av=0x7ffff5747e60) at malloc.c:5184
#1  0x00007ffff54396a8 in _int_free (av=0x7ffff5747e60, p=0x670b50) at
malloc.c:5063
#2  0x00007ffff543cb1c in *__GI___libc_free (mem=<optimized out>) at
malloc.c:3738
#3  0x00007ffff5c053cc in av_freep () from
/usr/lib/x86_64-linux-gnu/libavutil.so.52
#4  0x00007ffff68a95f9 in avcodec_free_frame (frame=<optimized out>) at
libavcodec/utils.c:1089
#5  0x00007ffff76399a9 in try_decode_frame (s=s at entry=0x6600c0,
st=st at entry=0x660680,
avpkt=avpkt at entry=0x6610c0, options=<optimized out>) at
libavformat/utils.c:2542
#6  0x00007ffff763fc11 in avformat_find_stream_info (ic=0x6600c0,
options=0x6707a0) at libavformat/utils.c:2978
#7  0x000000000040d980 in open_input_file (o=o at entry=0x7fffffffe560,
filename=<optimized out>) at ffmpeg_opt.c:818
#8  0x000000000040b6b1 in open_files (inout=inout at entry=0x42274a "input",
open_file=open_file at entry=0x40d5b0 <open_input_file>, l=<error reading
variable: Unhandled dwarf expression opcode 0xfa>,
    l=<error reading variable: Unhandled dwarf expression opcode 0xfa>) at
ffmpeg_opt.c:2506
#9  0x0000000000410dda in ffmpeg_parse_options (argc=argc at entry=16,
argv=argv at entry=0x7fffffffeb98) at ffmpeg_opt.c:2543
#10 0x0000000000407d51 in main (argc=16, argv=0x7fffffffeb98) at
ffmpeg.c:3433



Starting program: /home/build/ffmpeg-dmo-2.1.3/ffmpeg_g -f alsa -acodec
g722 -ar 8000 -ac 1 -i hw:0,0,5 -f s16le test.pcm
...
Program received signal SIGSEGV, Segmentation fault.
malloc_consolidate (av=0x7ffff5747e60) at malloc.c:5184
5184    malloc.c: No such file or directory.
(gdb) bt
#0  malloc_consolidate (av=0x7ffff5747e60) at malloc.c:5184
#1  0x00007ffff543a4d4 in _int_malloc (av=0x7ffff5747e60, bytes=1456) at
malloc.c:4402
#2  0x00007ffff543b89e in _int_memalign (av=0x7ffff5747e60, alignment=32,
bytes=<optimized out>) at malloc.c:5521
#3  0x00007ffff543d196 in *__GI___libc_memalign (alignment=32, bytes=1384)
at malloc.c:3895
#4  0x00007ffff543d449 in __posix_memalign (memptr=0x7fffffffe388,
alignment=140737311440480, size=1456) at malloc.c:6344
#5  0x00007ffff5c0522a in av_malloc () from
/usr/lib/x86_64-linux-gnu/libavutil.so.52
#6  0x00007ffff7602dcb in avformat_alloc_context () at
libavformat/options.c:109
#7  0x00007ffff75e912e in avformat_alloc_output_context2
(avctx=avctx at entry=0x7fffffffe478,
oformat=oformat at entry=0x0, format=0x657f00 "s16le",
filename=filename at entry=0x7fffffffee6e
"test.pcm") at libavformat/mux.c:127
#8  0x000000000040ea9c in open_output_file (o=o at entry=0x7fffffffe580,
filename=0x7fffffffee6e "test.pcm") at ffmpeg_opt.c:1617
#9  0x000000000040b6b1 in open_files (inout=inout at entry=0x42276c "output",
open_file=open_file at entry=0x40e8c0 <open_output_file>, l=<error reading
variable: Unhandled dwarf expression opcode 0xfa>,
    l=<error reading variable: Unhandled dwarf expression opcode 0xfa>) at
ffmpeg_opt.c:2506
#10 0x0000000000410e04 in ffmpeg_parse_options (argc=argc at entry=14,
argv=argv at entry=0x7fffffffebb8) at ffmpeg_opt.c:2550
#11 0x0000000000407d51 in main (argc=14, argv=0x7fffffffebb8) at
ffmpeg.c:3433



Starting program: /home/build/ffmpeg-dmo-2.1.3/ffmpeg_g -f alsa -acodec mp3
-ar 8000 -ac 1 -i hw:0,0,5 -f s16le test.pcm

...

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff5437fed in malloc_consolidate (av=0x7ffff5747e60) at
malloc.c:5198
5198    malloc.c: No such file or directory.
(gdb) bt
#0  0x00007ffff5437fed in malloc_consolidate (av=0x7ffff5747e60) at
malloc.c:5198
#1  0x00007ffff54396a8 in _int_free (av=0x7ffff5747e60, p=0x678cf0) at
malloc.c:5063
#2  0x00007ffff543cb1c in *__GI___libc_free (mem=<optimized out>) at
malloc.c:3738
#3  0x00007ffff5c053cc in av_freep () from
/usr/lib/x86_64-linux-gnu/libavutil.so.52
#4  0x00007ffff68a95f9 in avcodec_free_frame (frame=<optimized out>) at
libavcodec/utils.c:1089
#5  0x00007ffff76399a9 in try_decode_frame (s=s at entry=0x6600c0,
st=st at entry=0x660680,
avpkt=avpkt at entry=0x6585a0, options=<optimized out>) at
libavformat/utils.c:2542
#6  0x00007ffff763fc11 in avformat_find_stream_info (ic=0x6600c0,
options=0x670780) at libavformat/utils.c:2978
#7  0x000000000040d980 in open_input_file (o=o at entry=0x7fffffffe590,
filename=<optimized out>) at ffmpeg_opt.c:818
#8  0x000000000040b6b1 in open_files (inout=inout at entry=0x42274a "input",
open_file=open_file at entry=0x40d5b0 <open_input_file>, l=<error reading
variable: Unhandled dwarf expression opcode 0xfa>,
    l=<error reading variable: Unhandled dwarf expression opcode 0xfa>) at
ffmpeg_opt.c:2506
#9  0x0000000000410dda in ffmpeg_parse_options (argc=argc at entry=14,
argv=argv at entry=0x7fffffffebc8) at ffmpeg_opt.c:2543
#10 0x0000000000407d51 in main (argc=14, argv=0x7fffffffebc8) at
ffmpeg.c:3433


I've researched what happens when I'm trying to use g726: local variable
"frame" changes by itself:

(gdb) break libavformat/utils.c:2476
Breakpoint 1 at 0x7ffff763987b: file libavformat/utils.c, line 2476.
(gdb) run -f alsa -acodec g726 -ar 8000 -ac 1 -i hw:0,0,5 -f s16le test.pcm
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/build/ffmpeg-dmo-2.1.3/ffmpeg_g -f alsa -acodec
g726 -ar 8000 -ac 1 -i hw:0,0,5 -f s16le test.pcm
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
ffmpeg version 2.1.3 Copyright (c) 2000-2013 the FFmpeg developers
  built on Feb 13 2014 09:02:39 with gcc 4.7 (Debian 4.7.2-5)
  configuration: --prefix=/usr --extra-cflags='-g -O2 -fstack-protector
--param=ssp-buffer-size=4 -Wformat -Werror=format-security '
--extra-ldflags='-Wl,-z,relro' --cc='ccache cc' --enable-shared
--enable-libmp3lame --enable-gpl --enable-nonfree --enable-libvorbis
--enable-pthreads --enable-libfaac --enable-libxvid --enable-postproc
--enable-x11grab --enable-libgsm --enable-libtheora
--enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264
--enable-libspeex --enable-nonfree --disable-stripping --enable-libvpx
--enable-libschroedinger --disable-encoder=libschroedinger
--enable-version3 --enable-libopenjpeg --enable-librtmp --enable-avfilter
--enable-libfreetype --enable-libvo-aacenc --disable-decoder=amrnb
--enable-libvo-amrwbenc --enable-libaacplus
--libdir=/usr/lib/x86_64-linux-gnu --disable-vda --enable-libbluray
--enable-libcdio --enable-gnutls --enable-frei0r --enable-openssl
--enable-libass --enable-libopus --enable-fontconfig --enable-libpulse
--disable-mips32r2 --disable-mipsdspr1 --disable-mipsdspr2
--enable-libvidstab --enable-libzvbi --enable-avresample --enable-shared
--disable-optimizations --disable-mmx --disable-stripping
--enable-libiec61883 --enable-libfdk-aac --enable-vaapi --enable-libdc1394
--disable-altivec --disable-armv5te --disable-armv6 --disable-vis
--shlibdir=/usr/lib/x86_64-linux-gnu
  libavutil      52. 48.101 / 52. 48.101
  libavcodec     55. 39.101 / 55. 39.101
  libavformat    55. 19.104 / 55. 19.104
  libavdevice    55.  5.100 / 55.  5.100
  libavfilter     3. 90.100 /  3. 90.100
  libavresample   1.  1.  0 /  1.  1.  0
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100

Breakpoint 1, try_decode_frame (s=s at entry=0x6600c0, st=st at entry=0x660680,
avpkt=avpkt at entry=0x670b40, options=0x670780) at libavformat/utils.c:2476
2476        if (!avcodec_is_open(st->codec) && !st->info->found_decoder) {
(gdb) print frame
$1 = (AVFrame *) 0x670c00
(gdb) next
2498        } else if (!st->info->found_decoder)
(gdb) print frame
$2 = (AVFrame *) 0x1

So in all cases there are some problems with memory. I can't understand,
what is the difference between codecs from pcm.c and all other codecs for
alsa libavdevice?

P.S. As I understand, G.726 decoder is compatible with G.723. But it's not
the point at the moment.
P.P.S. There is support for G.723 format in ALSA kernel modules, but it's
not used by my card's driver. It gives stream only as SNDRV_PCM_FORMAT_U8.
P.P.P.S. Sorry for my English.

---
Alexey Balekhov


More information about the ffmpeg-devel mailing list