[x264-devel] Single frame encoding

Jason Garrett-Glaser darkshikari at gmail.com
Fri Nov 20 21:05:15 CET 2009


On Fri, Nov 20, 2009 at 2:36 AM, Takashi Mochizuki
<mochi at da2.so-net.ne.jp> wrote:
> Hi,
> I have tried latest git-1342 library with my x264Encoder (QuickTime
> Component for MacOS X).
> Mostly works well, but I have found an intermittent hang on threaded
> lookahead.
> It could happen only when "encoding single frame" repeatedly (e.g. updating
> preview images).
> //
> My component uses libx264 via patched libavcodec, and it could stop
> - when tried to take out delayed output frame from libx264 (passing NULL
> buffer) -
> Code snippet like:
>         glob->frame_size = avcodec_encode_video(glob->codecCont,
>             glob->encode_buffer, glob->encode_buffer_size, NULL);
> Tried to dump stacks, and found that, there is x264_lookahead_thread()
> remaining inside stack trace.
>   Thread id:      5872ba0
>   User stack:
>     586 _thread_start + 34 (in libSystem.B.dylib) [0x94b9a012]
>       586 _x264_lookahead_thread + 169 (in x264Encoder) [0x15bb7e89]
>         586 _semaphore_wait_signal_trap + 10 (in libSystem.B.dylib)
> [0x94b692ce]
> Disassemble in debugger, and found it is waiting at pthread_cond_wait.
> encoder/lookahead.c
>  88: static void x264_lookahead_thread( x264_t *h )
> :
> 104:            while( !h->lookahead->ifbuf.i_size &&
> !h->lookahead->b_exit_thread )
> 105:                x264_pthread_cond_wait( &h->lookahead->ifbuf.cv_fill,
> &h->lookahead->ifbuf.mutex );
> Do you have any idea about what is happening?
> //
> Takashi Mochizuki
>
> _______________________________________________
> x264-devel mailing list
> x264-devel at videolan.org
> http://mailman.videolan.org/listinfo/x264-devel
>
>

I've applied a fix for the problem locally.

Here's the diff, from Steven Walters:

diff --git a/encoder/encoder.c b/encoder/encoder.c
index 0b4117e..1e59c3c 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
 -1958,8 +1958,10 @@ int     x264_encoder_encode( x264_t *h,
     else
     {
         /* signal kills for lookahead thread */
+        x264_pthread_mutex_lock( &h->lookahead->ifbuf.mutex );
         h->lookahead->b_exit_thread = 1;
         x264_pthread_cond_broadcast( &h->lookahead->ifbuf.cv_fill );
+        x264_pthread_mutex_unlock( &h->lookahead->ifbuf.mutex );
     }

     h->i_frame++;

Dark Shikari


More information about the x264-devel mailing list