Video Recording on ipcamera devices can be divided into three modes: mobile detection video, schedule video, and manual video recording. Generally, the video recording of mobile detection is not a long time, which is about several dozen seconds. Such a video file can be stored on ramdisk and is only a temporary file, it can be automatically deleted after being sent to the user by email or other means. Therefore, you do not need an SD card or an external USB disk. However, the scheduled video and manual video files are relatively large, and an external disk must be used. Based on the fact that the chip encoding speed is faster than the disk writing speed, so frames must be discarded during the video recording process. That is to say, we need to develop such a strategy to minimize Frame loss. When frames need to be dropped, we should drop those frames. The dual-Line Process and dual buffer management described here are one of the optional policies.
Here, the double thread refers to: 1. Media Stream packaging thread; 2: Disk Writing thread.
The tasks processed by the packaging thread include extracting video and audio data from the encoding buffer, packaging the data into the same file format as needed, such as asfformat, processing frame loss, put the data into the shared buffer for writing to the disk thread to notify the disk thread of the Data status and next action.
The tasks processed by the write disk thread include accepting messages from the packaging thread, creating, writing, and closing files. Report the write status to the packaging thread to obtain and return the buffer space.
If the audio/video encoding is not synchronized, the packaging thread must handle the synchronization problem. That is, the audio and video timestamps.
Here, dual-buffer refers to the two buffer management methods used for data sharing between the packaging thread and the writing thread. That is, the packaging thread writes buf1 first. After writing, it notifies the writing disk thread that the data is full and can start writing. The packaging thread starts writing buf2. After writing the data, it loops like this.
Assume that the encoding buffer uses a circular linked list structure. This process uses