Ipcamera SD card video dual-thread dual Buffer Management

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.