xkfz007
22nd July 2014, 08:55
Recently, I am learning the multithreads of X264.
In my opinion, two command line arguments are important: --threads and --lookahead-threads.
--thrreads decides the number of threads doing the encoding work.
--lookahead-threads decides the number of threads analyzing the frame to calculate the SATD cost.
For example, --threads 4 --lookahead-threads 2
Then 7 threads in total will be created:
1 MainThread : control the entire flow
1 IOThread: read frames from yuv files
4 EncodeThread: encode one frame(x264_slicewrite)
1 MainLookaheadThread: control the Lookahead analysis flow
2 LookaheadThread: analyse a part of a frame(like slice based parallelism)
So the MainLookaheadThread controls the analysis flow of the lookahead process. For lookahead, there are three lists:
x264_sync_frame_list_t ifbuf;
x264_sync_frame_list_t next;
x264_sync_frame_list_t ofbuf;
ifbuf will be used by IOThread and MainLookaheadThread and ofbuf will be used by MainThread and MainLookaheadThread. So ifbuf and ofbuf should be locked before visiting and unlocked after visiting. However, the "next" list is used only by the MainLookaheadThread and why should it also use the mutex_lock and mutex_unlock?
In my opinion, two command line arguments are important: --threads and --lookahead-threads.
--thrreads decides the number of threads doing the encoding work.
--lookahead-threads decides the number of threads analyzing the frame to calculate the SATD cost.
For example, --threads 4 --lookahead-threads 2
Then 7 threads in total will be created:
1 MainThread : control the entire flow
1 IOThread: read frames from yuv files
4 EncodeThread: encode one frame(x264_slicewrite)
1 MainLookaheadThread: control the Lookahead analysis flow
2 LookaheadThread: analyse a part of a frame(like slice based parallelism)
So the MainLookaheadThread controls the analysis flow of the lookahead process. For lookahead, there are three lists:
x264_sync_frame_list_t ifbuf;
x264_sync_frame_list_t next;
x264_sync_frame_list_t ofbuf;
ifbuf will be used by IOThread and MainLookaheadThread and ofbuf will be used by MainThread and MainLookaheadThread. So ifbuf and ofbuf should be locked before visiting and unlocked after visiting. However, the "next" list is used only by the MainLookaheadThread and why should it also use the mutex_lock and mutex_unlock?