I just compiled and installed CVS HEAD of pymedia
within a CVS version of Python on Linux 2.6.11. Header
parsing, etc. works fine, but Python seg faults when
instantiating the Decoder object. For example:
pymedia.video.vcodec.Decoder({'index': 0,
'block_align': 0, 'type': 0, 'frame_rate_base': 66666,
'height': 240, 'channels': 0, 'width': 320, 'length':
0, 'sample_rate': 0, 'frame_rate': 1000000, 'bitrate':
0, 'id': 10})
causes a segmentation fault. That dictionary is what
pymedia reported from actual use on an AVI file.
However, it does not seem to matter what dictionary I
specify (e.g., empty dictionary behaves the same).
Here is a debugger trace from gdb:
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 535905984 (LWP 17173)]
avcodec_close (avctx=0x0) at video/libavcodec/utils.c:443
443 if (avctx->codec->close)
(gdb) list
438 return ret;
439 }
440
441 int avcodec_close(AVCodecContext *avctx)
442 {
443 if (avctx->codec->close)
444 avctx->codec->close(avctx);
445 av_freep(&avctx->priv_data);
446 avctx->codec = NULL;
447 return 0;
(gdb) bt
#0 avcodec_close (avctx=0x0) at
video/libavcodec/utils.c:443
#1 0x00927652 in CodecClose (obj=0x1feddd40) at
video/vcodec/vcodec.c:1197
#2 0x009277bc in Codec_New (cObj=0x1fed0bdc,
type=Variable "type" is not available.
)
at video/vcodec/vcodec.c:1252
#3 0x0092781c in DecoderNew (type=0xa2e140,
args=0x1fe4fc2c, kwds=0x0)
at video/vcodec/vcodec.c:1273
#4 0x080896c0 in type_call (type=0xa2e140,
args=0x1fe4fc2c, kwds=0x0)
at Objects/typeobject.c:421
#5 0x0805bfa4 in PyObject_Call (func=0xa2e140,
arg=0x1fe4fc2c, kw=0x0)
at Objects/abstract.c:1752
#6 0x080b2d25 in PyEval_EvalFrameEx (f=0x857fcf4, throw=0)
at Python/ceval.c:3783
#7 0x080b6c62 in PyEval_EvalFrameEx (f=0x8520e2c, throw=0)
at Python/ceval.c:3657
#8 0x080b6c62 in PyEval_EvalFrameEx (f=0x8527d94, throw=0)
at Python/ceval.c:3657
#9 0x080b6c62 in PyEval_EvalFrameEx (f=0x8545cdc, throw=0)
at Python/ceval.c:3657
#10 0x080b6c62 in PyEval_EvalFrameEx (f=0x850b1ac, throw=0)
at Python/ceval.c:3657
#11 0x080b7530 in PyEval_EvalCodeEx (co=0x1fe78be0,
globals=0x1feeb8ac,
locals=0x1feeb8ac, args=0x0, argcount=0, kws=0x0,
kwcount=0, defs=0x0,
defcount=0, closure=0x0) at Python/ceval.c:2754
#12 0x080b7696 in PyEval_EvalCode (co=0x1fe78be0,
globals=0x1feeb8ac,
locals=0x1feeb8ac) at Python/ceval.c:490
#13 0x080dbf2c in PyRun_FileExFlags (fp=0x8509008,
filename=0xbffa07c0 "photos", start=257,
globals=0x1feeb8ac,
locals=0x1feeb8ac, closeit=1, flags=0xbff40f44) at
Python/pythonrun.c:1268
#14 0x080dc80e in PyRun_SimpleFileExFlags (fp=0x8509008,
filename=0xbffa07c0 "photos", closeit=1,
flags=0xbff40f44)
at Python/pythonrun.c:863
#15 0x0805582f in Py_Main (argc=2, argv=0xbff41014) at
Modules/main.c:484
#16 0x08055057 in main (argc=3, argv=0xbff41014) at
Modules/python.c:23
Logged In: YES
user_id=127598
This happens because Codec_New might run CodecClose before
setting the cCodec. Here is a patch which lets Codec_New
fail with an exception instead of a crash:
Index: video/vcodec/vcodec.c
RCS file: /cvsroot/pymedia/pymedia/video/vcodec/vcodec.c,v
retrieving revision 1.11
diff -r1.11 vcodec.c
1204,1205c1204,1207
< avcodec_close(obj->cCodec);
< av_free( obj->cCodec );
---
> if (obj->cCodec) {
> avcodec_close(obj->cCodec);
> av_free( obj->cCodec );
> }
1221a1224
> codec->cCodec = NULL;