static void x264_lookahead_encoder_shift( x264_t *h ) { int bframes = 0; int i_frames = 0; while( h->lookahead->ofbuf.list[i_frames] ) { if( IS_X264_TYPE_B( h->lookahead->ofbuf.list[bframes]->i_type ) ) bframes++; else break; i_frames++; } if( h->lookahead->ofbuf.list[i_frames] ) { x264_frame_push( h->frames.current, x264_frame_shift( &h->lookahead->ofbuf.list[bframes] ) ); h->lookahead->ofbuf.i_size--; if( h->param.b_bframe_pyramid && bframes > 1 ) { x264_frame_t *mid = x264_frame_shift( &h->lookahead->ofbuf.list[bframes/2] ); h->lookahead->ofbuf.i_size--; mid->i_type = X264_TYPE_BREF; x264_frame_push( h->frames.current, mid ); bframes--; } while( bframes-- ) { x264_frame_push( h->frames.current, x264_frame_shift( h->lookahead->ofbuf.list ) ); h->lookahead->ofbuf.i_size--; } x264_pthread_cond_broadcast( &h->lookahead->ofbuf.cv_empty ); } }
static void x264_lookahead_shift( x264_synch_frame_list_t *dst, x264_synch_frame_list_t *src, int count ) { int i = count; while( i-- ) { assert( dst->i_size < dst->i_max_size ); assert( src->i_size ); dst->list[ dst->i_size++ ] = x264_frame_shift( src->list ); src->i_size--; } if( count ) { x264_pthread_cond_broadcast( &dst->cv_fill ); x264_pthread_cond_broadcast( &src->cv_empty ); } }
static void *x264_lookahead_thread( x264_t *h ) { while( !h->lookahead->b_exit_thread ) { x264_pthread_mutex_lock( &h->lookahead->ifbuf.mutex ); x264_pthread_mutex_lock( &h->lookahead->next.mutex ); int shift = X264_MIN( h->lookahead->next.i_max_size - h->lookahead->next.i_size, h->lookahead->ifbuf.i_size ); x264_lookahead_shift( &h->lookahead->next, &h->lookahead->ifbuf, shift ); x264_pthread_mutex_unlock( &h->lookahead->next.mutex ); if( h->lookahead->next.i_size <= h->lookahead->i_slicetype_length + h->param.b_vfr_input ) { while( !h->lookahead->ifbuf.i_size && !h->lookahead->b_exit_thread ) x264_pthread_cond_wait( &h->lookahead->ifbuf.cv_fill, &h->lookahead->ifbuf.mutex ); x264_pthread_mutex_unlock( &h->lookahead->ifbuf.mutex ); } else { x264_pthread_mutex_unlock( &h->lookahead->ifbuf.mutex ); x264_lookahead_slicetype_decide( h ); } } /* end of input frames */ x264_pthread_mutex_lock( &h->lookahead->ifbuf.mutex ); x264_pthread_mutex_lock( &h->lookahead->next.mutex ); x264_lookahead_shift( &h->lookahead->next, &h->lookahead->ifbuf, h->lookahead->ifbuf.i_size ); x264_pthread_mutex_unlock( &h->lookahead->next.mutex ); x264_pthread_mutex_unlock( &h->lookahead->ifbuf.mutex ); while( h->lookahead->next.i_size ) x264_lookahead_slicetype_decide( h ); x264_pthread_mutex_lock( &h->lookahead->ofbuf.mutex ); h->lookahead->b_thread_active = 0; x264_pthread_cond_broadcast( &h->lookahead->ofbuf.cv_fill ); x264_pthread_mutex_unlock( &h->lookahead->ofbuf.mutex ); return NULL; }
static void x264_lookahead_encoder_shift( x264_t *h ) { if( !h->lookahead->ofbuf.i_size ) return; int i_frames = h->lookahead->ofbuf.list[0]->i_bframes + 1; while( i_frames-- ) { x264_frame_push( h->frames.current, x264_frame_shift( h->lookahead->ofbuf.list ) ); h->lookahead->ofbuf.i_size--; } x264_pthread_cond_broadcast( &h->lookahead->ofbuf.cv_empty ); }
void x264_threadpool_delete( x264_threadpool_t *pool ) { x264_pthread_mutex_lock( &pool->run.mutex ); pool->exit = 1; x264_pthread_cond_broadcast( &pool->run.cv_fill ); x264_pthread_mutex_unlock( &pool->run.mutex ); for( int i = 0; i < pool->threads; i++ ) x264_pthread_join( pool->thread_handle[i], NULL ); x264_threadpool_list_delete( &pool->uninit ); x264_threadpool_list_delete( &pool->run ); x264_threadpool_list_delete( &pool->done ); x264_free( pool->thread_handle ); x264_free( pool ); }
static void x264_lookahead_thread( x264_t *h ) { int shift; #ifdef HAVE_MMX if( h->param.cpu&X264_CPU_SSE_MISALIGN ) x264_cpu_mask_misalign_sse(); #endif while( !h->lookahead->b_exit_thread ) { x264_pthread_mutex_lock( &h->lookahead->ifbuf.mutex ); x264_pthread_mutex_lock( &h->lookahead->next.mutex ); shift = X264_MIN( h->lookahead->next.i_max_size - h->lookahead->next.i_size, h->lookahead->ifbuf.i_size ); x264_lookahead_shift( &h->lookahead->next, &h->lookahead->ifbuf, shift ); x264_pthread_mutex_unlock( &h->lookahead->next.mutex ); if( h->lookahead->next.i_size <= h->lookahead->i_slicetype_length ) { while( !h->lookahead->ifbuf.i_size && !h->lookahead->b_exit_thread ) x264_pthread_cond_wait( &h->lookahead->ifbuf.cv_fill, &h->lookahead->ifbuf.mutex ); x264_pthread_mutex_unlock( &h->lookahead->ifbuf.mutex ); } else { x264_pthread_mutex_unlock( &h->lookahead->ifbuf.mutex ); x264_lookahead_slicetype_decide( h ); } } /* end of input frames */ #ifdef ERR1 x264_pthread_mutex_lock( &h->lookahead->next.mutex ); x264_pthread_mutex_lock( &h->lookahead->ifbuf.mutex ); #else x264_pthread_mutex_lock( &h->lookahead->ifbuf.mutex ); x264_pthread_mutex_lock( &h->lookahead->next.mutex ); #endif x264_lookahead_shift( &h->lookahead->next, &h->lookahead->ifbuf, h->lookahead->ifbuf.i_size ); #ifdef ERR1 x264_pthread_mutex_unlock( &h->lookahead->ifbuf.mutex ); x264_pthread_mutex_unlock( &h->lookahead->next.mutex ); #else x264_pthread_mutex_unlock( &h->lookahead->next.mutex ); x264_pthread_mutex_unlock( &h->lookahead->ifbuf.mutex ); #endif while( h->lookahead->next.i_size ) x264_lookahead_slicetype_decide( h ); x264_pthread_mutex_lock( &h->lookahead->ofbuf.mutex ); h->lookahead->b_thread_active = 0; x264_pthread_cond_broadcast( &h->lookahead->ofbuf.cv_fill ); x264_pthread_mutex_unlock( &h->lookahead->ofbuf.mutex ); }
void x264_lookahead_delete( x264_t *h ) { if( h->param.i_sync_lookahead ) { h->lookahead->b_exit_thread = 1; x264_pthread_cond_broadcast( &h->lookahead->ifbuf.cv_fill ); x264_pthread_join( h->thread[h->param.i_threads]->thread_handle, NULL ); x264_macroblock_cache_end( h->thread[h->param.i_threads] ); x264_free( h->thread[h->param.i_threads] ); } x264_synch_frame_list_delete( &h->lookahead->ifbuf ); x264_synch_frame_list_delete( &h->lookahead->next ); if( h->lookahead->last_nonb ) x264_frame_push_unused( h, h->lookahead->last_nonb ); x264_synch_frame_list_delete( &h->lookahead->ofbuf ); x264_free( h->lookahead ); }