线程堆栈过小导致MFXVideoDECODE_DecodeHeader出现signal 11

最近在freeswitch上做intel qsv的相关功能开发,主要是做一个编解码的功能。结果却在MFXVideoDECODE_DecodeHeader的时候出现的signal 11的崩溃。一直以为是因为freeswitch开发才导致的,因为之前做的另一个程序,并不基于freeswitch的开发并未有任何的异常。

最后发现是因为解码的时候,我实现上是会去起一个线程来做解码的,而之前的程序是基于系统默认的pthread调用,并没有设置多余的参数。而freeswitch这边是有设置堆栈空间大小的。所以就做了以下这个小代码程序 http://elkpi.com/code-snippets/dec_hdr.zip 代码的参数也很简单,默认是1024*16的堆栈空间设置,当然取决于对h264文件的解码上的处理。结果是会崩溃的,当堆栈空间达到1024000则不会有异常。我也在intel的论坛上发了帖子

使用默认1024*16的堆栈空间大小,出现崩溃:

[root@localhost ~]# ./demo 
use stack size is 16384
open /dev/dri/card0 success!!!!
libva info: VA-API version 0.99.0
libva info: va_getDriverName() returns 0
libva info: User requested driver 'iHD'
libva info: Trying to open /opt/intel/mediasdk/lib64/iHD_drv_video.so
libva info: Found init function __vaDriverInit_0_32
libva info: va_openDriver() returns 0
Initialized VA v0.99
impl desc is [hardware accelerated] version is 1.17
段错误(吐核)

[root@localhost ~]# gdb ./demo core.14748 
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-80.el7
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /root/demo...done.
[New LWP 14757]
[New LWP 14752]
[New LWP 14750]
[New LWP 14751]
[New LWP 14748]
[New LWP 14749]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Core was generated by `./demo'.
Program terminated with signal 11, Segmentation fault.
#0  0x00007f5dac246504 in ?? () from /opt/intel/mediasdk/lib64/libmfxhw64-p.so.1.17
Missing separate debuginfos, use: debuginfo-install glibc-2.17-106.el7_2.6.x86_64 intel-linux-media-16.4.4-47109.el7.x86_64 libX11-devel-1.6.3-2.el7.x86_64 libXau-1.0.8-2.1.el7.x86_64 libdrm-2.4.56-47109.el7.x86_64 libdrm-2.4.60-3.el7.x86_64 libgcc-4.8.5-4.el7.x86_64 libpciaccess-0.13.4-2.el7.x86_64 libstdc++-4.8.5-4.el7.x86_64 libva-1.67.0.pre1-47109.el7.x86_64 libxcb-1.11-4.el7.x86_64
(gdb) bt
#0  0x00007f5dac246504 in ?? () from /opt/intel/mediasdk/lib64/libmfxhw64-p.so.1.17
#1  0x00007f5dac239478 in ?? () from /opt/intel/mediasdk/lib64/libmfxhw64-p.so.1.17
#2  0x00007f5dac236029 in ?? () from /opt/intel/mediasdk/lib64/libmfxhw64-p.so.1.17
#3  0x00007f5dac23880f in ?? () from /opt/intel/mediasdk/lib64/libmfxhw64-p.so.1.17
#4  0x00007f5dac23a000 in ?? () from /opt/intel/mediasdk/lib64/libmfxhw64-p.so.1.17
#5  0x00007f5dac23a59b in ?? () from /opt/intel/mediasdk/lib64/libmfxhw64-p.so.1.17
#6  0x00007f5dac1331ee in ?? () from /opt/intel/mediasdk/lib64/libmfxhw64-p.so.1.17
#7  0x00007f5dac0ca720 in MFXVideoDECODE_DecodeHeader () from /opt/intel/mediasdk/lib64/libmfxhw64-p.so.1.17
#8  0x0000000000403597 in __dec_hdr (p=0x0) at main.c:39
#9  0x00007f5daffb1dc5 in start_thread () from /lib64/libpthread.so.0
#10 0x00007f5dafac8ced in clone () from /lib64/libc.so.6
(gdb)

而修改为1024000后,正常运行:

[root@localhost ~]# ./demo 1024000
use stack size is 1024000
open /dev/dri/card0 success!!!!
libva info: VA-API version 0.99.0
libva info: va_getDriverName() returns 0
libva info: User requested driver 'iHD'
libva info: Trying to open /opt/intel/mediasdk/lib64/iHD_drv_video.so
libva info: Found init function __vaDriverInit_0_32
libva info: va_openDriver() returns 0
Initialized VA v0.99
impl desc is [hardware accelerated] version is 1.17

mfx decode header success!!!

最后,我处理是不调用pthread_attr_setstacksize去固定堆栈的空间大小,而由系统自己去处理。虽然这样解决了问题,而由于intel的libmfxhw64.so是不开源的,并不清楚其内部是如何一个实现的方式。当然,毕竟是做h264的编解码操作,对于内存的需求比较大,也是在情理之中吧。在这里记录一下这件事情,因为之前并不是很在意这个堆栈的设置。

转载请注明: 转载自elkPi.com

本文链接地址: 线程堆栈过小导致MFXVideoDECODE_DecodeHeader出现signal 11

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Scroll to top