[Ffmpeg-devel] [PATCH] H.264 crash
Johan Lindström
johan
Wed Nov 9 04:53:43 CET 2005
>> Hello,
>>
>> The H.264 decoder crashes when you return -1 from the custom
>> get_buffer function. This patch fixes that.
>
> Could you provide a sample to reproduce the crash? Just upload the
> file somewhere and post a link to it here...
Hello,
It is not a specific H.264 encoded file that causes the crash, but (I
suppose) all H.264 encoded files. The crash occurs when you return -1
from your custom get_buffer function, to indicate that you don't want
to return a video frame/buffer to libavcodec. In my code this happens
when I want to close/free the movie and do not have any available
video frames to return to libavcodec. The get_buffer function blocks
on a dequeue call on a queue that holds preallocated video frames
that get reused over and over again. They are put back in the queue
when the program has processed/displayed/whatevered them, but if all
frames are busy there is no frame to return at the time of the
freeing the movie, and I can't wait for them to ever become available
either, because the display function will need to draw in the main
thread, which is blocked on waiting for the movie to be freed, hence
I return -1. Does this make sense? I'm not sure if this is the
correct thing to do, but it seems to work just fine with all other
codecs.
Here's a snippet of my code:
static int FF_get_buffer(struct AVCodecContext * context, AVFrame *
av_frame)
{
FFLAVideoTrack * track = (FFLAVideoTrack *) context->opaque;
FFLAVideoFrame * frame = [[track newFrame] retain];
// The frame can be nil when aborting the threads.
if (frame == nil)
return -1;
av_frame->opaque = (void *) frame;
av_frame->type = FF_BUFFER_TYPE_USER;
av_frame->age = av_frame->coded_picture_number - [frame age];
for (unsigned i = 0; i < 3; i++)
{
av_frame->data [i] = [frame baseAddr][i];
av_frame->linesize[i] = [frame rowBytes][i];
}
[frame setAge:av_frame->coded_picture_number];
[frame incUsageCount:@"FFmpeg"];
return 0;
}
Regards,
Johan Lindstr?m
More information about the ffmpeg-devel
mailing list