Method for reading uncompressed YUV file and related equipment
By combining memory mapping and multi-threaded concurrency with a semaphore synchronization mechanism, the problem of low reading efficiency of high-resolution uncompressed video signal files is solved, achieving efficient and reliable data transmission and meeting high bandwidth output requirements.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- BEIJING DIGITAL TV NAT ENG LAB
- Filing Date
- 2025-12-29
- Publication Date
- 2026-05-08
AI Technical Summary
Existing technologies suffer from excessive memory copying overhead in the data transmission path when reading high-resolution uncompressed video signal files, which limits the improvement of reading efficiency and fails to meet the requirements of high bandwidth output.
The system uses memory mapping to directly map hard disk file data to user space memory. Combined with a multi-threaded concurrency strategy, it uses Full and Empty semaphores to synchronize writing and reading, reducing the number of memory copies and improving data throughput.
It achieves efficient and reliable reading of uncompressed video signal files, meets the real-time output requirements of high-resolution video files, reduces the overhead of central processing unit and memory bandwidth, and ensures the security and continuity of data read and write operations.
Smart Images

Figure CN121996565A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data transmission technology, and in particular to a method and related equipment for reading uncompressed YUV files. Background Technology
[0002] In the operating mode of video signal sources, a common approach is to read video signal files from the hard drive, process them, and then output them to the device under test. In specific applications, such as providing test signals for video encoders, the video signal source is required to output the raw, uncompressed video signal to facilitate objective analysis and evaluation of the encoder's encoding capabilities. Furthermore, some national and institutional testing standards explicitly stipulate the use of uncompressed video signals as test signals. However, uncompressed video signal files at high resolutions, such as 8K or 10K, require extremely high sustained read rates from the hard drive to memory. For example, an 8Kp60 YUV420 file requires a read rate of at least 3GBps (24Gbps). If the actual read rate cannot meet the bandwidth requirements of the output signal, stable real-time output of the uncompressed video signal cannot be guaranteed. Therefore, how to achieve fast real-time reading of uncompressed video signals to meet the requirements of high-bandwidth output has become a pressing technical problem.
[0003] To address the need for improved hard drive file read speeds, existing technologies typically optimize at two levels. The first level involves employing a multi-threaded concurrent read strategy. By using multiple threads to read hard drive files, the overall read throughput can be significantly improved. This method avoids the efficiency bottlenecks that may exist with single-threaded sequential reads, allowing multiple threads to read different parts of the file in parallel, thus fully utilizing the potential bandwidth of the hard drive's input / output. The second level concerns the specific input / output operations for file reading. In most existing video signal file reading solutions, standard file read / output operation interfaces are commonly used. This method is suitable for situations with small data volumes or low speed requirements.
[0004] However, the aforementioned existing technologies still have significant drawbacks when dealing with extremely high read rate demands. While multi-threaded read strategies improve concurrency, they do not address the inherent overhead of the underlying data transfer path. Traditional file read / output operations generate substantial input / output overhead at extremely high data read rates. Although these overheads are managed by the operating system at the lower levels, their impact on application performance is significant. The fundamental reason is that standard file read / output operations require first allocating a temporary memory block in the operating system kernel space, reading data from the hard drive into that kernel space memory, and then copying the data from the kernel space memory to user space memory for application use. This process involves at least two memory copy operations. When the data volume is huge and bandwidth requirements are extremely high, these additional memory copy operations consume a significant amount of CPU cycles and memory bandwidth, becoming a key bottleneck restricting further improvements in read efficiency.
[0005] Therefore, a new technical solution is needed that can fundamentally reduce the path overhead of data transfer between storage and memory while retaining the advantages of multi-threaded concurrency, and ensure precise synchronization between read and write operations, thereby enabling reliable real-time reading of high-bandwidth uncompressed video files. Summary of the Invention
[0006] The technical problem to be solved by the present invention is to address the shortcomings of the prior art, specifically by providing a method and related equipment for reading uncompressed YUV files, as detailed below: 1) In a first aspect, the present invention provides a method for reading uncompressed YUV files, the specific technical solution of which is as follows: create Each memory YUV data block is configured with a Full semaphore and an Empty semaphore. The initial value of all Full semaphores is 0, and the initial value of all Empty semaphores is 1. Parallel startup Each worker thread is assigned a unique sequence number. Based on its assigned sequence number, each worker thread cyclically reads the corresponding YUV frame data from the disk file using memory mapping and writes it to the corresponding memory YUV data block. Simultaneously, it synchronizes the write operation by acquiring the Empty semaphore and releasing the Full semaphore for that memory YUV data block. and All are positive integers. for Integer multiples of; YUV frame data is read sequentially from the memory YUV data block and output sequentially. For each read, the Full semaphore of the target memory YUV data block is acquired to read the data, and the Empty semaphore of the memory YUV data block is released after reading, until all YUV frame data is output.
[0007] The beneficial effects of the method for reading uncompressed YUV files provided by this invention are as follows: By employing memory mapping to read YUV frame data from hard disk files, worker threads can directly map file data to user-space memory addresses. This avoids the additional data copying operations from kernel space to user space required in traditional file read / write operations, reducing memory copy counts and lowering CPU and memory bandwidth overhead, fundamentally improving the data reading efficiency of a single worker thread. Building on this, combined with a strategy of launching multiple worker threads in parallel, the system fully utilizes hard disk I / O bandwidth and the parallel computing power of multi-core processors, further enhancing overall data throughput and meeting the extremely high read speed requirements of high-resolution uncompressed YUV video files. A precise read / write synchronization mechanism is established by setting Full and Empty semaphores for each memory YUV data block and performing acquisition and release operations during worker thread writing and data processing module reading, respectively. This mechanism ensures that worker threads do not write data to memory YUV data blocks that have not yet been read, while also guaranteeing that the data processing module can only read valid data that has already been written. This achieves reliability and security of data read / write operations in a multi-threaded concurrent environment, ensuring the continuity and correctness of video signal output. Furthermore, the number of worker threads... Number of memory YUV data blocks Its configurability allows the method to adapt to different hardware environments and performance requirements. The optimal parameter combination can be determined through testing to achieve the best read performance under the current device conditions.
[0008] 2) Secondly, the present invention also provides a system for reading uncompressed YUV files, the specific technical solution of which is as follows: This includes a creation module, a writing module, and an output module; The creation module is used for: creating Each memory YUV data block is configured with a Full semaphore and an Empty semaphore. The initial value of all Full semaphores is 0, and the initial value of all Empty semaphores is 1. The write module is used for: parallel startup Each worker thread is assigned a unique sequence number. Based on its assigned sequence number, each worker thread cyclically reads the corresponding YUV frame data from the disk file using memory mapping and writes it to the corresponding memory YUV data block. Simultaneously, it synchronizes the write operation by acquiring the Empty semaphore and releasing the Full semaphore for that memory YUV data block. and All are positive integers. for Integer multiples of; The output module is used to sequentially read and output YUV frame data from the memory YUV data block. For each read, the data is read by acquiring the Full semaphore of the target memory YUV data block, and the Empty semaphore of the memory YUV data block is released after reading, until all YUV frame data is output.
[0009] 3) In a third aspect, the present invention also provides an electronic device, the electronic device including a processor coupled to a memory, the memory storing at least one computer program, the at least one computer program being loaded and executed by the processor, so that the electronic device implements any of the above-described methods for reading uncompressed YUV files.
[0010] 4) In a fourth aspect, the present invention also provides a computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, it implements any of the above-described methods for reading uncompressed YUV files.
[0011] It should be noted that the beneficial effects of the technical solutions of the second to fourth aspects of the present invention and their corresponding possible implementations can be found in the above description of the technical effects of the first aspect and its corresponding possible implementations, and will not be repeated here. Attached Figure Description
[0012] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments of the present invention will be briefly introduced below: Figure 1 This is a flowchart illustrating a method for reading uncompressed YUV files according to an embodiment of the present invention; Figure 2 This is a schematic diagram of the principle of the present invention; Figure 3 A flowchart illustrating the workflow of writing YUV data blocks into memory for worker threads; Figure 4 A flowchart illustrating the process of reading YUV data blocks from memory; Figure 5 This is a schematic diagram of the structure of a system for reading uncompressed YUV files according to an embodiment of the present invention. Detailed Implementation
[0013] The principles and features of the present invention are described below. The examples given are only for explaining the present invention and are not intended to limit the scope of the present invention.
[0014] The technical solution of the present invention and how the technical solution of the present invention solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of the present invention will now be described with reference to the accompanying drawings.
[0015] like Figure 1 As shown in the figure, a method for reading an uncompressed YUV file according to an embodiment of the present invention includes the following steps: S1, Create Each memory YUV data block is assigned a Full semaphore and an Empty semaphore. All Full semaphores are initialized to 0, and all Empty semaphores are initialized to 1. For multiple different sets of... and The combined configuration was used to test read performance, and the configuration that maximized the read rate was selected based on the test results. and The combined configuration is used as the final working parameters, and the specific implementation process is as follows: S10, according to configuration parameters Dynamically allocate memory in user space Each memory YUV data block has a FrameSize value, calculated based on the video file format. The formula is as follows: Here, Width represents the width of the video frame in pixels; Height represents the height of the video frame in pixels; and ChromaSubsamplingFactor is the chroma sampling factor determined by the specific YUV format (e.g., YUV420, YUV444). Two semaphore objects are created and initialized for each memory YUV data block, serving as its Full and Empty semaphores respectively. During initialization, the semaphore setting function is called, setting the value of the Full semaphore corresponding to each memory YUV data block to 0 and the value of each Empty semaphore to 1. These semaphores will be used for subsequent coordination of read / write synchronization between worker threads and the data processing module.
[0016] S11. Initiate a parameter tuning process to determine the number of worker threads. Number of memory YUV data blocks The optimal combination. This process involves conducting actual read performance tests on multiple different combinations of k and N configurations. Specifically, a test combination list can be predefined, containing multiple sets of k and N values to be tested. For example, k might be 1, 2, 4, 8, and N might be an integer multiple of k, such as 8, 16, 32, 64. For each k and N configuration in the list, the system will perform a complete video file read and output process: allocating N memory YUV data blocks and initializing semaphores, then creating k worker threads to read the file in parallel, while the data processing module reads and outputs data sequentially. During this process, a high-precision timer is used to measure the total time T from the start of reading to the completion of all S-frame data output. S represents the total number of YUV frames in the hard disk video file. The read rate Performance can be calculated by dividing the total data volume by the total time, using the following formula: Where Performance represents the measured read rate in bytes per second; S represents the total number of YUV frames in the video file on the hard drive; FrameSize is the size of each frame; and T is the measured total time in seconds. After iterating through all predefined combinations of configurations, the system compares the Performance values obtained from each test and selects the combination of k and N that maximizes the Performance value as the final operating parameters used by the system. For example, if the test finds that the Performance value is highest when k=4 and N=32, the system will fix k at 4 and N at 32 in subsequent operations.
[0017] S10 to S11 not only completed the initialization and construction of the memory buffer and synchronization mechanism, but also, through a systematic testing process, can adaptively determine the optimal concurrency and buffering parameters under specific hardware and operating system environments, thereby ensuring stable and real-time reading capabilities for high-bandwidth uncompressed YUV video files.
[0018] The memory YUV data block is a contiguous memory area pre-allocated in user space memory, used to temporarily store a complete frame of YUV format video data read from a hard disk file. The size of each memory YUV data block is determined by the resolution and color format of the video frame; for example, the size is fixed for a frame of data in 8K resolution YUV420 format. During system initialization, the system allocates N such memory YUV data blocks in memory according to the number N set by the user, forming a circular buffer for worker threads to write data and for the data processing module to read data.
[0019] The Full semaphore is a synchronization counting semaphore specifically used to indicate whether a valid, readable YUV frame has been stored in the corresponding memory YUV data block. Each memory YUV data block is associated with an independent Full semaphore. The initial value of the Full semaphore is set to 0, indicating that all memory YUV data blocks are initially empty and there is no data available for consumption. When a worker thread successfully copies a frame of YUV data to a memory YUV data block, it releases (increments) the Full semaphore for that block, thereby notifying the data processing module that the data in that block is ready.
[0020] The Empty semaphore is another type of synchronization semaphore specifically used to indicate whether the corresponding memory YUV data block is in an idle state and can be written with new YUV frame data by worker threads. Each memory YUV data block is also associated with an independent Empty semaphore. The initial value of the Empty semaphore is set to 1, indicating that all memory YUV data blocks are initially empty and ready for write operations. When the data processing module finishes reading data from a memory YUV data block, it releases (increments) the Empty semaphore of that block, thereby notifying the worker threads that the block is now idle and ready to write the next frame of data.
[0021] S2, Parallel Startup Each worker thread is assigned a unique sequence number. Based on its assigned sequence number, each worker thread cyclically reads the corresponding YUV frame data from the disk file using memory mapping and writes it to the corresponding memory YUV data block. Simultaneously, it synchronizes the write operation by acquiring the Empty semaphore and releasing the Full semaphore for that memory YUV data block. and All are positive integers. for Integer multiples of; Among them, the serial number is The data processing procedures of the worker thread include: As the starting YUV frame number ,in, for to An integer; based on the current YUV frame number. Calculate the offset of the YUV frame corresponding to the sequence number in the hard disk file; based on the offset, map the file region of the corresponding YUV frame data in the hard disk file to user space memory using memory mapping, and obtain the mapped memory address; based on the current YUV frame sequence number... Calculate the sequence number of the target memory YUV data block. ,in, ; Get the serial number as The Empty semaphore of the memory YUV data block; copies the YUV frame data mapped to the user space memory address to the sequence number. In the memory YUV data block; the release sequence number is Full semaphore for the memory YUV data block; set the current YUV frame sequence number. Updated to The process repeats the steps from calculating the offset to releasing the Full semaphore until all YUV frames have been processed. The specific implementation process is as follows: 1) After completing the creation of the memory YUV data block and semaphore initialization, k worker threads are started in parallel. The system creates k independent execution flows by calling thread creation functions provided by the operating system, such as pthread_create or std::thread. When creating each worker thread, a unique identifier parameter, i.e., the worker thread number, needs to be passed to the thread entry function. The worker thread number i is an integer whose value ranges from 0 to... k is the total number of worker threads. Each worker thread independently and concurrently executes subsequent data read and write tasks according to its assigned sequence number i.
[0022] 2) When each worker thread begins execution, it first determines the starting YUV frame number it needs to process. The worker thread with sequence number i initializes its starting YUV frame number M to the value of its own sequence number i. That is, worker thread 0 starts processing from frame 0, worker thread 1 starts processing from frame 1, and so on. From the Frame processing begins. This initial relationship is determined by the formula... OK. M represents the logical sequence number of the YUV frame currently being processed by the worker thread in the disk file.
[0023] 3) The worker thread calculates the storage location of the currently pending YUV frame number M in the hard disk file. This calculation relies on the premise that each YUV frame has a fixed size. Assuming each YUV frame is FrameSize bytes, a value pre-calculated based on the video resolution and color format, the starting byte offset (Offset) of the YUV frame number M in the hard disk file can be calculated using the following formula: Offset is measured in bytes and represents the distance from the beginning of the file to the start of the Mth frame of data.
[0024] 4) The worker thread maps the corresponding frame of data from the hard disk file to user space memory based on the calculated file offset (Offset). This is implemented by calling operating system-provided file memory mapping functions, such as `mmap` or `MapViewOfFile`. When calling these functions, the file handle to be mapped, the starting address of the mapping (usually NULL and allocated by the system), the mapping length (FrameSize), the offset of the starting file (Offset), and the access permissions (e.g., read-only) must be specified. Upon successful execution, the function returns a pointer to user space memory, denoted as `yuv_addr`. `yuv_addr` represents the starting address of the Mth frame of data from the hard disk file in user space memory after successful mapping. Through memory mapping, subsequent data access will directly operate on this memory region, and the operating system will handle hard disk page scheduling in the background, thus avoiding explicit file read / write operations and an additional data copy from kernel space to user space.
[0025] 5) The worker thread needs to determine which memory YUV data block the read YUV frame data should be written to. A total of N memory YUV data blocks are created, with their sequence numbers ranging from 0 to... The sequence number of the target memory YUV data block. The result is obtained by taking the modulo of the current YUV frame number M with the total number N. The calculation formula is as follows: in, This represents the sequence number of the target memory YUV data block, where M is the current YUV frame sequence number and N is the total number of memory YUV data blocks. The modulo operation ensures that regardless of the size of the YUV frame sequence number M, the write operation always uses these N pre-allocated memory YUV data blocks in a cyclical manner.
[0026] 6) In the direction of the sequence number Before writing data to a memory YUV data block, a worker thread must request write permission by acquiring the Empty semaphore of that memory YUV data block. The Empty semaphore controls the idle state of the memory YUV data block. The worker thread calls a semaphore wait function (such as sem_wait or WaitForSingleObject) to attempt to acquire the semaphore with sequence number 1. The function acquires the Empty semaphore for the YUV data block in memory. If the value of the Empty semaphore is greater than 0, the acquisition is successful, the semaphore value is decremented by 1, and the thread can continue to execute the write operation; if the value is 0, the acquisition fails, and the thread will be blocked at this function call, entering a waiting state. This waiting will continue until the data processing module has finished reading the data in the YUV data block in memory and released the Empty semaphore (incrementing its value). This synchronization mechanism ensures that worker threads will not overwrite data that has not yet been consumed by the data processing module.
[0027] 7) After successfully obtaining the serial number... After the empty semaphore of the memory YUV data block is set, the worker thread performs the data copying operation. The data source is the user-space memory address yuv_addr obtained through memory mapping, and the data target is at sequence number... The memory region corresponding to the YUV data block. The worker thread calls a standard memory copy function (such as memcpy) to copy data of length FrameSize bytes from address yuv_addr to the memory region with sequence number . The data is stored in the memory YUV data block. After the data copy is complete, the worker thread should call the function to unmap the memory (such as munmap or UnmapViewOfFile) to release the previously established mapping relationship to avoid resource leaks.
[0028] 8) Data is copied to sequence number... Once the memory YUV data block is completed, it means that the memory YUV data block now contains valid, newly written YUV frame data, which can be read by the data processing module. To notify the data processing module, the worker thread needs to release the sequence number... The Full semaphore is set for the YUV data block in memory. Worker threads call semaphore release functions (such as sem_post or ReleaseSemaphore) to increment the Full semaphore value. This operation may wake up data processing module threads that are waiting for the Full semaphore, informing them that the data is ready.
[0029] 9) After processing the current YUV frame M, the worker thread needs to determine the sequence number of the next YUV frame to be processed. Since there are k worker threads processing in parallel, each thread is responsible for processing frames with an interval of k in the frame sequence. Therefore, the worker thread updates the current YUV frame sequence number M to M plus the total number of worker threads k, i.e., it performs the following operation: The updated M value is the sequence number of the YUV frame to be processed in the next loop of this worker thread.
[0030] 10) The working thread enters the loop control phase. The thread determines whether the updated YUV frame sequence number M is less than the total number S of YUV frames in the hard disk video file. If M < S holds, it means there are subsequent YUV frames to be processed by this thread, so the working thread jumps back to the above step 3 and starts a new round of the process of "calculating the offset, memory mapping, calculating the target block, obtaining the Empty semaphore, copying data, releasing the Full semaphore" with the new M value. If M >= S holds, it means this working thread has processed all the YUV frames allocated to it (i.e., all frames whose sequence numbers satisfy frame number % k == i). At this time, the working thread exits the loop and ends its execution.
[0031] All k working threads independently and parallelly repeat the above process until each has processed the responsible YUV frame sequence. By improving the single - read efficiency through memory mapping, utilizing the hard disk input - output bandwidth through multi - thread parallelism, and precisely synchronizing with the data processing module through the Empty and Full semaphores, the efficient and real - time reading of large - scale uncompressed YUV video files in the hard disk is jointly achieved.
[0032] S3. Sequentially loop - read YUV frame data from the in - memory YUV data blocks and output it. For each read, obtain the Full semaphore of the target in - memory YUV data block to read the data, and release the Empty semaphore of this in - memory YUV data block after reading until all YUV frame data is output.
[0033] Among them, the process of loop - reading YUV frame data and outputting it includes: initializing the YUV frame sequence number to be read and output as ; according to the current YUV frame sequence number , calculating the corresponding in - memory YUV data block sequence number , where ; obtaining the Full semaphore of the in - memory YUV data block with the sequence number ; reading the stored YUV frame data in the in - memory YUV data block with the sequence number and outputting it; releasing the Empty semaphore of the in - memory YUV data block with the sequence number ; incrementing the YUV frame sequence number and repeating the steps from calculating the corresponding memory block sequence number to releasing the Empty semaphore until all YUV frame data is output. The specific implementation process is as follows: 1) When the data processing module starts up, it needs to perform state initialization. The key operation is to initialize an internal counter, namely the sequence number of the YUV frame to be read and output, to 0. This sequence number is represented by the symbol Q. Therefore, the operation performed is Q=0. The symbol Q represents the logical sequence number of the next YUV frame that the data processing module will request and output in the original video file, which starts from 0 and increments linearly.
[0034] 2) For the YUV frame sequence number Q that needs to be output, the data processing module must determine which memory YUV data block stores the data for that frame. There are N memory YUV data blocks in the system, which are reused cyclically by all worker threads and the data processing module. The sequence number of the target memory YUV data block... The value is obtained by taking the modulo of the current YUV frame sequence number Q with the total number of YUV data blocks N in memory. The calculation formula is as follows: in, is the calculated target memory YUV data block number, ranging from 0 to N-1; Q is the current YUV frame number to be read; and N is the total number of memory YUV data blocks. This formula guarantees a circular mapping between the video frame sequence and the finite memory buffer.
[0035] 3) In attempting to start from the sequence number Before reading data from a memory YUV data block, the data processing module must confirm that the data in the memory YUV data block has been filled by the worker thread and is in a readable state. This confirmation is achieved by acquiring the Full semaphore of the memory YUV data block. The Full semaphore is specifically used to indicate whether valid data exists in the corresponding memory YUV data block. The data processing module calls a semaphore wait function, such as sem_wait or WaitForSingleObject, to attempt to acquire the semaphore with sequence number 1. The Full semaphore is set for the memory YUV data block. If the Full semaphore value is greater than 0, it indicates that the data is ready, the acquisition was successful, the semaphore value is decremented by 1, and the data processing module gains read access and continues execution. If the Full semaphore value is 0, it means that the worker thread has not yet completed writing to the memory YUV data block. The acquisition operation will cause the data processing module thread to block until a worker thread writes data to the memory YUV data block and releases the Full semaphore, at which point it will be awakened and continue. This step is a critical synchronization point to ensure data consistency and read order.
[0036] 4) After successfully obtaining the serial number After the Full semaphore of the memory YUV data block is set, the data processing module can safely read the data within it. At this point, the sequence number is... The complete image data corresponding to the YUV frame sequence number Q is contained in the memory YUV data block. The data processing module directly accesses the memory address corresponding to this memory YUV data block and reads out the YUV frame data stored therein. After the read operation is completed, this data is sent to the subsequent data processing and output process. The subsequent process may include color space conversion, format encapsulation, or directly outputting the video signal to the device under test through a specific interface.
[0037] 5) When the data processing module finishes reading the data in the memory YUV data block with the sequence number , the task of this memory YUV data block has been completed, and the data therein can be overwritten by new frame data. In order to notify the working thread that this memory YUV data block has become idle and available again, the data processing module must release the Empty semaphore of this memory YUV data block. The data processing module calls a semaphore release function, such as sem_post or ReleaseSemaphore, to perform a release operation on the Empty semaphore of the memory YUV data block with the sequence number . This operation will increase the value of the Empty semaphore by 1. At this time, any working thread waiting for this specific Empty semaphore (i.e., the next working thread that needs to write to this sequence number memory YUV data block) will be awakened and can start writing new YUV frame data to it. This step completes the other half of the read-write synchronization and releases the buffer resource.
[0038] 6) After completing the output and synchronization of the current frame, the data processing module needs to prepare to process the next frame. It increments the YUV frame sequence number Q by 1, that is, it performs the operation Q = Q + 1. The updated Q value points to the next frame sequence number in the original video file.
[0039] 7) The data processing module enters the loop control phase. It determines whether the updated YUV frame sequence number Q is less than the total number S of YUV frames in the hard disk video file. If the condition Q < S holds, it means there are still video frames to be output. The data processing module immediately jumps back to the second step above and starts a new round of loop with the new Q value: calculates the sequence number of the new target memory YUV data block , then attempts to acquire its Full semaphore, reads the data, and releases the Empty semaphore. If the condition Q >= S holds, it means that all S-frame video data has been read and output in sequence, and the data processing module ends its working loop and exits after performing cleanup work.
[0040] By repeatedly executing the above process, the data processing module can safely and efficiently retrieve each frame of uncompressed YUV data from the circular buffer, which is asynchronously filled by multiple threads, strictly according to the frame sequence number, and stably output it to the downstream system. The entire process relies entirely on the precise synchronization of read and write operations using Full and Empty semaphores, ensuring data integrity and real-time performance in high-throughput scenarios.
[0041] The technical solution of the present invention will be described through the following embodiments, specifically including the following steps: S101. Based on preset or test parameters, perform basic resource configuration. A key operation is creating a specified number of memory YUV data blocks and configuring synchronization semaphores for each memory YUV data block. Specifically, the system allocates N contiguous memory regions in user space memory, each large enough to store a complete frame of YUV format video data; these regions are defined as memory YUV data blocks. Each memory YUV data block is assigned a unique sequence number from 0 to N-1. Subsequently, two semaphore objects are created for each memory YUV data block: a Full semaphore and an Empty semaphore. The initial value of all Full semaphores is set to 0, and the initial value of all Empty semaphores is set to 1. This step establishes a circular buffer shared by multi-threaded read / write operations and the corresponding synchronization control state.
[0042] S102. Create k worker threads in parallel. When creating each worker thread, the system assigns it a unique worker thread number i, where the value of i ranges from 0 to k-1. All k worker threads are started in parallel and begin executing their independent data reading and writing tasks. Each worker thread determines the YUV frame sequence it is responsible for processing based on its own worker thread number i and enters a cyclic processing flow.
[0043] S103. At the start of each loop, each worker thread needs to determine the logical sequence number of the YUV frame to be read in the current round within the hard disk file. For the thread with program number i, it denotes the sequence number of the YUV frame it is currently processing as M. Upon first entering the loop, M is initialized to the value of i. The symbol M represents the sequence number of the frame currently being processed by the worker thread.
[0044] S104. The worker thread calculates the starting byte position of the current YUV frame number M in the hard disk file. This calculation is based on the assumption that each frame has a fixed size, denoted as FrameSize (bytes). The formula for calculating the offset is: Offset is the byte distance from the beginning of the file to the beginning of the Mth frame of data.
[0045] S105. The worker thread invokes the operating system's memory mapping function to directly map a region in the hard disk file, starting at the Offset address and with a length of FrameSize bytes, into user-space virtual memory. After successful mapping, the system returns a pointer to the starting address of this memory region, denoted as yuv_addr. Subsequently, the worker thread can directly access the raw frame data in the hard disk file through the pointer yuv_addr, without needing to perform traditional read and copy operations.
[0046] S106. The worker thread needs to store the read data into one of N memory YUV data blocks. The target block number... The sequence number is determined by taking the modulo of the current frame number M with the total number N, and the calculation formula is as follows: This identifies the target memory YUV data block for this write operation.
[0047] S107, in the direction of the sequence number Before writing data to a memory YUV data block, the worker thread must ensure that the block is idle. This is done by calling a semaphore wait operation to attempt to acquire the block with sequence number [number missing]. The thread acquires the Empty semaphore of the YUV data block in memory. If the acquisition is successful, the thread continues; if it fails, the thread will block here until the data processing module releases the Empty semaphore.
[0048] S108. After obtaining write permission, the worker thread performs a memory copy operation, copying the FrameSize bytes of data from the mapped memory region yuv_addr to the sequence number... The data is stored in the physical memory corresponding to the YUV data blocks in memory. After copying is complete, the worker thread releases the established memory mapping relationship.
[0049] S109, Data successfully written, sequence number is After a memory YUV data block is loaded, the worker thread releases the Full semaphore for that memory YUV data block. This operation increments the value of the Full semaphore, indicating that valid data is available to read from the memory YUV data block, and may wake up data processing modules that are waiting for this semaphore.
[0050] S110. After the current frame is processed, the worker thread calculates the sequence number of the next frame to be processed. The update rule is to increase the current frame sequence number M by the total number of worker threads k, that is: S111: The worker thread checks if the updated frame sequence number M is less than the total number of YUV frames S in the hard disk file. If M is less than S, the thread jumps back to S104 and begins processing the frame corresponding to the new sequence number M. If M is greater than or equal to S, it means that the worker thread has completed the processing tasks for all the frames assigned to it, and the thread ends the loop and exits.
[0051] S112. Simultaneously or after the system starts the worker thread, the data processing module begins to run. It first initializes the internally maintained YUV frame sequence number Q to 0, indicating that it is ready to output the first frame of the video file.
[0052] S113. For the frame sequence number Q to be output, the data processing module needs to locate the memory YUV data block storing the frame data. Target block sequence number. We obtain the following through modulo operation: It indicates which memory YUV data block should be read from.
[0053] S114, from the sequence number is Before reading data from a memory YUV data block, the data processing module must confirm that the data within that block is ready. This is done by calling a semaphore wait operation to attempt to acquire the sequence number. The module acquires the Full semaphore for the YUV data block in memory. Successful acquisition indicates that data can be safely read; otherwise, the module will block and wait.
[0054] S115. After successfully acquiring the Full semaphore, the data processing module starts from the sequence number... The complete YUV frame data is read from the memory YUV data block. This data is then fed into subsequent video signal processing steps and finally output to the device under test.
[0055] S116. After completing the data reading, the sequence number is... The contents of the memory YUV data block are no longer needed, and the block can be reused to store new data. The data processing module releases the Empty semaphore of the memory YUV data block, notifying the worker threads that the block is now free.
[0056] S117. The data processing module increments the sequence number Q of the YUV frame to be read by 1, preparing to process the next frame: S118. The data processing module determines whether the updated frame sequence number Q is less than the total number of YUV frames S in the hard disk file. If Q is less than S, it jumps back to S113 and continues to output the next frame. If Q is greater than or equal to S, it means that all frames have been output, and the data processing module ends its work.
[0057] S119. To achieve maximum read performance under specific hardware and software conditions, this method includes a parameter optimization phase. The system automatically or manually tests multiple combinations of different worker thread counts k and memory YUV data block counts N. For each test configuration k, N, the system fully executes the above process and accurately measures the total time T from start to finish. The read rate Performance is calculated using the formula: By comparing the Performance values obtained from all test combinations, the parameter combination of k and N that maximizes the Performance value is selected as the optimal operating parameters for this operating environment.
[0058] The principle of this invention is as follows Figure 2 As shown, in the method proposed in this invention, the system adopts a virtual workgroup-based architecture to organize read operations on hard disk files. All virtual workgroups share the same fixed number of worker threads, totaling k worker threads, which have unique serial numbers ranging from 0 to k. A virtual workgroup is not a physical thread, but a logical grouping concept used to clearly describe the mapping relationship between worker threads, data frames, and memory buffers. The number of virtual workgroups depends on the total number N of memory YUV data blocks pre-allocated in user space memory. Each memory YUV data block stores one complete frame of YUV format video data. By design, the number N of memory YUV data blocks needs to be an integer multiple of the number of worker threads k, which is greater than or equal to 1. Assuming the user allocates N memory YUV data blocks, then the system logically divides the system into N / k virtual workgroups. The block diagram shows two workgroups, namely workgroup 0 and workgroup 1; in the actual system, there are N / k such workgroups.
[0059] Each worker thread in all virtual workgroups is responsible for processing YUV frames in a fixed order. Specifically, the worker thread's sequence number determines which frame it processes within each workgroup. For example, worker thread 0 is responsible for the first YUV frame in each virtual workgroup. For the first virtual workgroup, workgroup 0, worker thread 0 reads YUV frame 0 from the hard drive file, which is also the first YUV frame in the entire video file. For the next virtual workgroup, workgroup 1, worker thread 0 reads YUV frame k from the hard drive file, which is also logically the first YUV frame in workgroup 1. Similarly, worker thread 1 is responsible for the second YUV frame in each virtual workgroup. In workgroup 0, worker thread 1 reads YUV frame 1; after completing this operation, in workgroup 1, worker thread 1 immediately reads YUV frame k+1. And so on, with worker thread k-1 responsible for the last, i.e., the kth YUV frame, in each virtual workgroup.
[0060] From the perspective of YUV frames, which worker thread should process a given YUV frame is determined by taking the modulo of the frame's sequence number and the total number of worker threads. Let `frame_number` represent the YUV video frame number to be read. If the video file contains S video frames, then `frame_number` ranges from 0 to S-1. The worker thread number processing this YUV frame is equal to the remainder when `frame_number` is divided by k, i.e., `frame_number%k`. This allocation method automatically implements the fixed responsibilities of worker threads within the virtual workgroup.
[0061] The worker threads are responsible not only for reading disk frames but also for writing data to the corresponding memory YUV data blocks. The total number of memory YUV data blocks is N, and they are used cyclically. When writing a frame of data, each worker thread needs to determine the sequence number of the target memory YUV data block. This sequence number is obtained by taking the modulo of the currently processed YUV frame sequence number `frame_number` with the total number of memory YUV data blocks `N`, i.e., `frame_number%N`. Therefore, the YUV frame data with sequence number `frame_number` is ultimately written to the memory YUV data block with sequence number `(frame_number%N)`. These N memory YUV data blocks, numbered from 0 to N-1, form a circular buffer.
[0062] The data processing module runs independently of the worker thread. It strictly follows the original order of the YUV frames, starting from frame_number 0 and ending at S-1, cyclically reading and outputting YUV frame data from the memory YUV data block. The data processing module sequentially reads data from memory YUV data block 0, then memory YUV data block 1, and so on. After reading memory YUV data block number N-1, it returns to memory YUV data block number 0 to start reading again, because according to the write rules, the updated frame data has already overwritten the oldest data in the circular buffer.
[0063] Because the same memory YUV data block needs to be both written with new YUV frame data by the worker thread and read by the data processing module to output old YUV frame data, a synchronization mechanism must be established between the worker thread and the data processing module to avoid read / write conflicts and data inconsistencies. This synchronization mechanism is implemented by associating each memory YUV data block with a pair of semaphores: a Full semaphore and an Empty semaphore. Before writing to a memory YUV data block, the worker thread must successfully acquire the Empty semaphore for that block to ensure that the block is in an idle and writable state; after writing, it releases the Full semaphore to notify the data processing module that the data is ready. Correspondingly, before reading a memory YUV data block, the data processing module must successfully acquire the Full semaphore for that block to ensure that the data is ready; after reading, it releases the Empty semaphore to notify the worker thread that the block is idle and can be written to again. Through the paired use of this set of semaphores, the read and write operations are guaranteed to be independent and the data flow is smooth.
[0064] exist Figure 2 In this context, workgroup 0 includes the following operational procedures: Worker thread 0 processes disk YUV frame 0, obtaining its memory address through fast mapping and copying the data to the corresponding location in the memory YUV data block. The data at that location is subsequently read sequentially. Worker thread 1 processes disk YUV frame 1, obtaining its memory address through fast mapping and copying the data to the corresponding location in the memory YUV data block. The data at that location is subsequently read sequentially.
[0065] 3) Worker thread 2 processes disk YUV frame 2, obtains the memory address through fast mapping, copies the data to the corresponding position in the memory YUV data block, and the data at that position is subsequently read sequentially. This continues until worker thread k-1 processes disk YUV frame k-1, obtains the memory address through fast mapping, copies the data to the corresponding position in the memory YUV data block, and the data at that position is subsequently read sequentially.
[0066] Working Group 1 includes the following operational procedures: Worker thread 0 processes disk YUV frame k, obtaining its memory address through fast mapping and copying the data to the corresponding position in the memory YUV data block. The data at that position is subsequently read sequentially. Worker thread 1 processes disk YUV frame k+1, obtaining its memory address through fast mapping and copying the data to the corresponding position in the memory YUV data block. The data at that position is subsequently read sequentially. Worker thread 2 processes disk YUV frame k+2, obtaining its memory address through fast mapping and copying the data to the corresponding position in the memory YUV data block. The data at that position is subsequently read sequentially. This process continues until worker thread k-1 processes disk YUV frame 2k-1, obtaining its memory address through fast mapping and copying the data to the corresponding position in the memory YUV data block. The data at that position is subsequently read sequentially.
[0067] The data from all workgroups is ultimately retrieved sequentially from the corresponding memory YUV data blocks by the data processing module and then processed to complete the signal output.
[0068] like Figure 3 As shown, each memory YUV data block is associated with two semaphores for synchronization: a Full semaphore and an Empty semaphore. During system initialization, the initial value of the Full semaphore for all memory YUV data blocks is set to 0, and the initial value of all Empty semaphores is set to 1. This initial state indicates that all buffers are initially empty and writable. The task of the worker threads is to read the YUV frame sequence from the hard disk video file. Assuming the total number of frames in the hard disk video file is S, the YUV frame numbers start from 0 and go up to S-1. Each worker thread processes the frames assigned to it according to a loop process, specifically: 1) The worker thread determines the current YUV frame to be processed. This frame is identified by a variable M, called the YUV frame number to be processed by the current worker thread. The worker thread updates the value of M according to its own sequence number and the global scheduling rules.
[0069] 2) When a worker thread needs to read a YUV frame M, it first determines which worker thread should process the frame. The worker thread number for processing YUV frame M is calculated using the formula Mmodk, where k is the total number of worker threads. This means that frame allocation among worker threads is uniform and cyclical.
[0070] 3) The worker thread calculates the specific location of YUV frame M in the hard disk file. It first obtains the size of a single YUV frame, denoted as frame_size. Then, it calculates the starting byte offset of YUV frame M in the file using the formula: offset = frame_size * M. This offset is a key parameter for performing memory mapping operations.
[0071] 4) The worker thread performs the memory mapping operation. The system directly maps a region in the hard disk file, starting from the calculated offset and with a length of frame_size bytes, into the user space's virtual memory. This operation is called memory-mapped hard disk YUV frame M. After successful mapping, the operating system returns a starting address pointing to this memory region, denoted as yuv_addr. Afterward, the worker thread can directly access the file data through the pointer yuv_addr.
[0072] 5) The worker thread determines which memory buffer the data should be written to. The sequence number of the target memory YUV data block. From the formula: The calculation shows that N is the total number of YUV data blocks in memory. This indicates the memory data block number corresponding to the current YUV frame.
[0073] 6) Before writing data, the worker thread must acquire write permission to the target memory YUV data block. It attempts to acquire the permission with sequence number... The Empty semaphore for the memory YUV data block. This is a critical synchronization point. The operation of acquiring the Empty semaphore may succeed or fail.
[0074] 7) Determine the result of acquiring the Empty semaphore. If the Empty semaphore was not acquired, it means that the data processing module has not yet finished reading the existing data in the memory YUV data block, and the buffer is still occupied. At this time, the worker thread enters a waiting state until the data processing module finishes reading and releases the Empty semaphore before it can continue execution. This process can be described as: if not acquired, wait for the data processing module to release the Empty semaphore.
[0075] 8) When the worker thread successfully obtains the sequence number... After the Empty semaphore is set to the memory address of the YUV data block, it indicates that the buffer is now free and can be written with new data. At this point, the worker thread performs a data copy operation, copying the data of YUV frame M of size frame_size from memory-mapped address yuv_addr to the memory address at sequence number... The physical memory region corresponding to the memory YUV data block. This operation is described as: Successful acquisition, copy from the mapped address to the memory data block. .
[0076] 9) After the data copy is complete, the sequence number is... The memory YUV data block already contains data for a valid YUV frame M. To notify the data processing module that the data is ready, the worker thread releases the Full semaphore for this memory YUV data block. This operation is described as: releasing the Full semaphore.
[0077] 10) After processing the current frame M, the worker thread needs to calculate the next YUV frame number it should process. The update rule is to add the current frame number M to the total number of worker threads k, i.e., perform the calculation M = M + k. This step ensures that the worker thread jumps to the next logically assigned frame.
[0078] 11) The worker thread performs a loop condition check. It checks whether the updated YUV frame number M is less than the total number of frames S in the video file. If M is less than S, the worker thread jumps back to step 2 above (recalculating the processing thread affiliation with the new M value; in fact, for the same worker thread, the frame sequence it processes is already determined by M = M + k), and begins processing the next frame. If M is greater than or equal to S, it means that the worker thread has processed all the frames assigned to it, and the thread ends its work loop.
[0079] Through the cyclic execution of the above steps, all k worker threads work together to efficiently read data through memory mapping and precisely synchronize with the data processing module through Empty and Full semaphores. Finally, the sequence YUV frame data on the hard disk is filled into the cyclically used memory YUV data block in an orderly and error-free manner.
[0080] Figure 4 This diagram illustrates the workflow of the data processing module reading YUV data blocks from memory and outputting YUV frames, defining the specific steps and synchronization rules for consuming data from the circular buffer. The YUV frames output by the data processing module are numbered from 0 to S-1, where S is the total number of YUV frames in the hard disk video file. The specific process is as follows: 1) The data processing module initializes its internal state. It initializes a variable Q, representing the number of the YUV frame to be read and output, to 0. Q represents the number of the YUV frame to be output.
[0081] 2) For a YUV frame Q that needs to be read from the output, the data processing module must determine the memory YUV data block storing the frame data. There are N memory YUV data blocks in the system, numbered from 0 to N-1. The corresponding memory YUV data block numbers are... Through formula The calculation shows that N is the total number of YUV data blocks in memory. (Symbol) This indicates the memory data block number corresponding to the current YUV frame.
[0082] 3) In attempting to start from the sequence number Before reading data from a memory YUV data block, the data processing module must confirm that the data in that block has been prepared by the worker thread. This is done by attempting to obtain the sequence number... This is implemented using Full semaphores for each memory YUV data block. Each memory YUV data block has one Full semaphore and one Empty semaphore for synchronous read and write operations.
[0083] 4) Determine the result of acquiring the Full semaphore. If the data processing module fails to acquire the Full semaphore, it means that the corresponding worker thread has not yet completed reading and copying the data of YUV frame Q to the sequence number. The data is stored in the YUV data block in memory. At this point, the data processing module enters a waiting state, continuing to wait until the worker thread responsible for that frame completes its operation and releases the Full semaphore. This process corresponds to waiting for the worker thread to release the Full semaphore.
[0084] 5) When the data processing module successfully obtains the sequence number... After the Full semaphore is set to the maximum for the memory YUV data block, it indicates that the data copying within that memory YUV data block is complete, the YUV data is intact and valid, and can be safely read. Subsequently, the data processing module performs a read operation, starting from sequence number... YUV frame data is read from the memory data block.
[0085] 6) After successfully reading the data, the contents of this memory YUV data block are no longer used for this output task. To allow worker threads to write new data to this block in the future, the data processing module must release the block with sequence number […]. The Empty semaphore for the memory YUV data block. This operation is described as releasing the Empty semaphore.
[0086] 7) The data processing module sends the read YUV frame data into the subsequent video signal processing and output process, ultimately completing the signal output of YUV frame Q. This step is described as outputting YUV frame Q.
[0087] 8) After completing the output of the current frame Q, the data processing module needs to prepare to output the next frame in the video sequence. It increments the YUV frame number Q to be output by 1, that is, it performs the update operation Q=Q+1.
[0088] 9) The data processing module performs a loop condition check. It checks whether the updated YUV frame number Q is less than the total number of frames S in the video file. If Q is less than S, the data processing module jumps back to step 2 above and starts the next loop with the new Q value to calculate the new memory block number. The system attempts to acquire the Full semaphore to continue reading and outputting. If Q is greater than or equal to S, it indicates that all S frames of video data have been output in sequence, and the data processing module ends its working cycle.
[0089] The above process ensures that the data processing module can safely and stably retrieve and output data from the buffer that is asynchronously filled by multiple threads, strictly following the frame sequence number.
[0090] The entire system startup follows a specific sequence to ensure resource readiness and dependencies. Upon system startup, the following operations are performed: First, k worker threads and N memory YUV data blocks are created according to configuration parameters. Second, a Full and Empty semaphore are set for each memory YUV data block, with all Full semaphores initialized to 0 and all Empty semaphores initialized to 1. Third, the k previously created worker threads are started, and these threads begin executing disk file read and data write tasks in parallel. Fourth, the data processing module is started, beginning the process of cyclically reading YUV frame data from the memory YUV data blocks and outputting it.
[0091] A key advantage of this method lies in the adjustability and optimization potential of its parameters. By adjusting the numerical combinations of the total number of worker threads (k) and the total number of memory YUV data blocks (N), and conducting actual read performance tests on different combinations, the optimal k and N pairings for specific hardware and operating system environments can be determined, thus achieving the optimal read performance configuration. Performance testing is conducted by measuring the total time of the complete output video file and calculating the read rate. In practical product applications, after a series of tests, the parameter combination of a total number of worker threads (k) equal to 4 and a total number of memory YUV data blocks (N) equal to 32 has been verified as the optimal configuration that achieves the highest read performance.
[0092] In the above embodiments, although the steps are numbered S1, S2, etc., they are only specific embodiments given by the present invention. Those skilled in the art can adjust the execution order of S1, S2, etc. according to the actual situation. The scheme after adjusting the order is also within the protection scope of the present invention. It can be understood that in some embodiments, some or all of the above embodiments may be included.
[0093] like Figure 5 As shown, a system 200 for reading uncompressed YUV files according to an embodiment of the present invention includes a creation module 201, a writing module 202, and an output module 203. Module 201 is used for: creating Each memory YUV data block is configured with a Full semaphore and an Empty semaphore. The initial value of all Full semaphores is 0, and the initial value of all Empty semaphores is 1. The writing module 202 is used for: parallel startup Each worker thread is assigned a unique sequence number. Based on its assigned sequence number, each worker thread cyclically reads the corresponding YUV frame data from the hard disk file using memory mapping and writes it to the corresponding memory YUV data block. Simultaneously, it synchronizes the write operation by acquiring the Empty semaphore and releasing the Full semaphore for that memory YUV data block. and All are positive integers. for Integer multiples of; The output module 203 is used to: sequentially read YUV frame data from the memory YUV data block and output it. For each read, the data is read by acquiring the Full semaphore of the target memory YUV data block and releasing the Empty semaphore of the memory YUV data block after reading, until all YUV frame data is output.
[0094] Optionally, in the above technical solutions, the serial number is The data processing procedures of the worker thread include: by As the starting YUV frame number ,in, for to Integers; Based on the current YUV frame number Calculate the offset of the YUV frame corresponding to the sequence number in the hard disk file; Based on the offset, the file region of the corresponding YUV frame data in the hard disk file is mapped to the user space memory through memory mapping, and the mapped memory address is obtained. Based on the current YUV frame number Calculate the sequence number of the target memory YUV data block. ,in, ; Get the serial number as Empty semaphore for memory YUV data blocks; Copy the YUV frame data mapped to the user-space memory address to the sequence number. In the memory YUV data block; Release sequence number is Full semaphore for memory YUV data blocks; Set the current YUV frame number Updated to The process repeats the steps from calculating the offset to releasing the Full semaphore until all YUV frames have been processed.
[0095] Optionally, in the above technical solution, the process of cyclically reading and outputting YUV frame data includes: Initialize the YUV frame sequence number to be read and output to 0. ; Based on the current YUV frame number Calculate the corresponding memory YUV data block number ,in, ; Get the serial number as Full semaphore for memory YUV data blocks; Read sequence number is The YUV frame data already stored in the memory YUV data block is output; Release sequence number is Empty semaphore for memory YUV data blocks; YUV frame sequence number The process is incremented and repeated, from calculating the corresponding memory block number to releasing the Empty semaphore, until all YUV frame data has been output.
[0096] Optionally, the above technical solution also includes a testing module, which is used to: perform read performance tests on multiple different combinations of k and N, and select the combination of k and N that achieves the highest read rate as the final working parameter based on the test results.
[0097] It should be noted that the beneficial effects of the system 200 for reading uncompressed YUV files provided in the above embodiments are the same as those of the method for reading uncompressed YUV files described above, and will not be repeated here. Furthermore, the system provided in the above embodiments is only illustrated by the division of the above functional modules. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the system can be divided into different functional modules according to the actual situation to complete all or part of the functions described above. In addition, the system and method embodiments provided in the above embodiments belong to the same concept, and their specific implementation process is detailed in the method embodiments, and will not be repeated here.
[0098] An electronic device according to an embodiment of the present invention includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements any of the above-described methods for reading uncompressed YUV files.
[0099] Among them, electronic devices can also be terminal devices, which can be any device that can install applications, including at least one of smartphones, tablets, laptops, desktop computers, smart speakers, smartwatches, smart TVs, smart in-vehicle devices, and signal source devices.
[0100] An embodiment of the present invention provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements any of the above-described methods for reading uncompressed YUV files.
[0101] The above description is merely a preferred embodiment of the present invention and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of disclosure in this invention is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-disclosed concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features with similar functions disclosed in this invention.
[0102] Although embodiments of the present invention have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present invention. Those skilled in the art can make changes, modifications, substitutions and variations to the above embodiments within the scope of the present invention.
Claims
1. A method for reading uncompressed YUV files, characterized in that, include: create Each memory YUV data block is configured with a Full semaphore and an Empty semaphore, wherein the initial value of all Full semaphores is 0 and the initial value of all Empty semaphores is 1. Parallel startup Each worker thread is assigned a unique sequence number. Based on its assigned sequence number, each worker thread cyclically reads the corresponding YUV frame data from the hard disk file using memory mapping and writes it to the corresponding memory YUV data block. Simultaneously, it synchronizes the write operation by acquiring the Empty semaphore and releasing the Full semaphore for the memory YUV data block. and All are positive integers. for Integer multiples of; YUV frame data is sequentially read from the memory YUV data block and output. For each read, the Full semaphore of the target memory YUV data block is acquired to read the data, and the Empty semaphore of the memory YUV data block is released after reading, until all YUV frame data is output.
2. The method for reading uncompressed YUV files by a signal source device according to claim 1, characterized in that, The serial number is The data processing procedures of the worker thread include: by As the starting YUV frame number ,in, for to Integers; Based on the current YUV frame number Calculate the offset of the YUV frame corresponding to the sequence number in the hard disk file; Based on the offset, the file region of the corresponding YUV frame data in the hard disk file is mapped to the user space memory through memory mapping, and the mapped memory address is obtained. Based on the current YUV frame number Calculate the sequence number of the target memory YUV data block. ,in, ; Get the serial number as The Empty semaphore of the aforementioned memory YUV data block; Copy the YUV frame data mapped to the user-space memory address to the sequence number. In the aforementioned memory YUV data block; Release sequence number is The Full semaphore of the memory YUV data block; Set the current YUV frame number Updated to The process repeats the steps from calculating the offset to releasing the Full semaphore until all YUV frames have been processed.
3. The method for reading uncompressed YUV files by a signal source device according to claim 2, characterized in that, The process of cyclically reading and outputting YUV frame data includes: Initialize the YUV frame sequence number to be read and output to 0. ; Based on the current YUV frame number Calculate the corresponding memory YUV data block number ,in, ; Get the serial number as The Full semaphore of the memory YUV data block; Read sequence number is The YUV frame data already stored in the memory YUV data block is output; Release sequence number is The Empty semaphore of the aforementioned memory YUV data block; YUV frame sequence number The process is incremented and repeated, from calculating the corresponding memory block number to releasing the Empty semaphore, until all YUV frame data has been output.
4. A method for reading uncompressed YUV files according to any one of claims 1 to 3, characterized in that, Also includes: Read performance tests were conducted on multiple different combinations of k and N, and the combination of k and N that achieved the highest read rate was selected as the final working parameter based on the test results.
5. A system for reading uncompressed YUV files, characterized in that, This includes a creation module, a writing module, and an output module; The creation module is used to: create Each memory YUV data block is configured with a Full semaphore and an Empty semaphore, wherein the initial value of all Full semaphores is 0 and the initial value of all Empty semaphores is 1. The writing module is used for: parallel startup Each worker thread is assigned a unique sequence number. Based on its assigned sequence number, each worker thread cyclically reads the corresponding YUV frame data from the hard disk file using memory mapping and writes it to the corresponding memory YUV data block. Simultaneously, it synchronizes the write operation by acquiring the Empty semaphore and releasing the Full semaphore for the memory YUV data block. and All are positive integers. for Integer multiples of; The output module is used to: sequentially read YUV frame data from the memory YUV data block and output it. For each read, the data is read by acquiring the Full semaphore of the target memory YUV data block, and the Empty semaphore of the memory YUV data block is released after reading, until all YUV frame data is output.
6. A system for reading uncompressed YUV files by a signal source device according to claim 5, characterized in that, The serial number is The data processing procedures of the worker thread include: by As the starting YUV frame number ,in, for to Integers; Based on the current YUV frame number Calculate the offset of the YUV frame corresponding to the sequence number in the hard disk file; Based on the offset, the file region of the corresponding YUV frame data in the hard disk file is mapped to the user space memory through memory mapping, and the mapped memory address is obtained. Based on the current YUV frame number Calculate the sequence number of the target memory YUV data block. ,in, ; Get the serial number as The Empty semaphore of the aforementioned memory YUV data block; Copy the YUV frame data mapped to the user-space memory address to the sequence number. In the aforementioned memory YUV data block; Release sequence number is The Full semaphore of the memory YUV data block; Set the current YUV frame number Updated to The process repeats the steps from calculating the offset to releasing the Full semaphore until all YUV frames have been processed.
7. A system for reading uncompressed YUV files by a signal source device according to claim 6, characterized in that, The process of cyclically reading and outputting YUV frame data includes: Initialize the YUV frame sequence number to be read and output to 0. ; Based on the current YUV frame number Calculate the corresponding memory YUV data block number ,in, ; Get the serial number as The Full semaphore of the memory YUV data block; Read sequence number is The YUV frame data already stored in the memory YUV data block is output; Release sequence number is The Empty semaphore of the aforementioned memory YUV data block; YUV frame sequence number The process is incremented and repeated, from calculating the corresponding memory block number to releasing the Empty semaphore, until all YUV frame data has been output.
8. A system for reading uncompressed YUV files according to any one of claims 5 to 7, characterized in that, It also includes a testing module, which is used to: perform read performance tests on multiple different combinations of k and N, and select the combination of k and N that achieves the highest read rate as the final working parameters based on the test results.
9. An electronic device, characterized in that, The invention includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements a method for reading an uncompressed YUV file as described in any one of claims 1 to 4.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements a method for reading an uncompressed YUV file as described in any one of claims 1 to 4.