+/****************************************************************************
+ * Ffmpeg threading system
+ ****************************************************************************/
+#if LIBAVCODEC_BUILD >= 4702
+static int FfmpegThread( struct thread_context_t *p_context )
+{
+ while ( !p_context->b_die && !p_context->b_error )
+ {
+ vlc_mutex_lock( &p_context->lock );
+ while ( !p_context->b_work && !p_context->b_die && !p_context->b_error )
+ {
+ vlc_cond_wait( &p_context->cond, &p_context->lock );
+ }
+ p_context->b_work = 0;
+ vlc_mutex_unlock( &p_context->lock );
+ if ( p_context->b_die || p_context->b_error )
+ break;
+
+ if ( p_context->pf_func )
+ {
+ p_context->i_ret = p_context->pf_func( p_context->p_context,
+ p_context->arg );
+ }
+
+ vlc_mutex_lock( &p_context->lock );
+ p_context->b_done = 1;
+ vlc_cond_signal( &p_context->cond );
+ vlc_mutex_unlock( &p_context->lock );
+ }
+
+ return 0;
+}
+
+static int FfmpegExecute( AVCodecContext *s,
+ int (*pf_func)(AVCodecContext *c2, void *arg2),
+ void **arg, int *ret, int count )
+{
+ struct thread_context_t ** pp_contexts =
+ (struct thread_context_t **)s->thread_opaque;
+ int i;
+
+ /* Note, we can be certain that this is not called with the same
+ * AVCodecContext by different threads at the same time */
+ for ( i = 0; i < count; i++ )
+ {
+ vlc_mutex_lock( &pp_contexts[i]->lock );
+ pp_contexts[i]->arg = arg[i];
+ pp_contexts[i]->pf_func = pf_func;
+ pp_contexts[i]->i_ret = 12345;
+ pp_contexts[i]->b_work = 1;
+ vlc_cond_signal( &pp_contexts[i]->cond );
+ vlc_mutex_unlock( &pp_contexts[i]->lock );
+ }
+ for ( i = 0; i < count; i++ )
+ {
+ vlc_mutex_lock( &pp_contexts[i]->lock );
+ while ( !pp_contexts[i]->b_done )
+ {
+ vlc_cond_wait( &pp_contexts[i]->cond, &pp_contexts[i]->lock );
+ }
+ pp_contexts[i]->b_done = 0;
+ pp_contexts[i]->pf_func = NULL;
+ vlc_mutex_unlock( &pp_contexts[i]->lock );
+
+ if ( ret )
+ {
+ ret[i] = pp_contexts[i]->i_ret;
+ }
+ }
+
+ return 0;
+}
+#endif
+