Davinci encode分析(dm365)

来源:互联网 发布:单词翻译软件 编辑:程序博客网 时间:2024/04/27 14:06
原文地址:Davinci encode分析(dm355)作者:姜汁呗

对视频和音频进行编码

音频算法是G.711

视频算法是mpeg4H.264

这些算法符合xDM界面。

6个线程:控制线程、视频线程、显示线程、写线程、语音线程、采集线程。

 

主线程—--->视频线程video thread、语音线程Speech Thread、采集线程、写线程

                 视频线程-->显示线程Display Thread、写线程Write Thread

主线程-à控制线程

注:视频文件存在则创建视频线程、采集线程、写线程、显示线程

       语音文件存在则创建语音线程

完成以上线程的创建后控制线程变为控制线程。

至少存在一个文件,因此系统中最少有2个线程,最多有6个线程。

 

用法

Usage: encode [options]

      Options:

      -s | --speechfile  Speech file to record to        声音文件

      -v | --videofile   Video file to record to           视频文件名

      -r | --resolution  Video resolution ('width'x'height') [720x480] 视频分辨率

      -b | --bitrate     Bit rate to encode video at [variable]

      -d | --deinterlace Disable removal of interlacing artifacts from the

                    captured video frames before encoding [off]

      -x | --svideo      Use s-video instead of composite video input [off]

      -l | --linein      Use line in for encoding sound instead of mic [off]

      -k | --keyboard    Enable keyboard interface [off]

      -t | --time        Number of seconds to run the demo [infinite]

      -i | --interface   Launch the demo interface when exiting [off]

      -h | --help        Print this message

      You must supply at least a video or a speech file or both

      with appropriate extensions for the file formats.

   

writer线程分析

1. Open the output video file: outputFp = fopen(envp->videoFile, "w");

2. 等待汇集:      如果有视频文件或语音文件则汇集线程数为5

                            如果视频文件和语音文件都有则汇集线程数为6

                            视频文件和语音文件至少有一个。  

   Rendezvous_meet(envp->hRendezvousInit);

      这些线程是:控制线程、视频线程、采集线程、写线程、显示线程

                                   语音线程

3. 进入循环

4. Get an encoded buffer from the video thread.

5. Is the video thread flushing the pipe?  Yes, Exit. No, cont.

6. Store the encoded frame to disk.

7. Send back the buffer to the video thread. (the encoded buffer)

8. goto  3.

video线程分析

视频线程所用管道

        videoEnv.hCaptureOutFifo    = &captureEnv.outFifo;

        videoEnv.hCaptureInFifo     = &captureEnv.inFifo;

        videoEnv.hWriterOutFifo     = &writerEnv.outFifo;

        videoEnv.hWriterInFifo      = &writerEnv.inFifo;

 

1. Open Codec Engine Reset, load, and start DSP Engine.

2. Create video encoder /* Allocate and initialize video encoder on the engine

3. Allocate buffers for encoded data and prime the writer thread.

              为已编码的数据分配缓冲区,并装填给写线程。

Memory_contigAlloc() 分配连续的缓冲区

              FifoUtil_put(envp->hWriterInFifo, &we)  //写管道操作

                            // 将申请的缓冲区内容写到管道hWriterInFifo中。

              我的理解,申请若干个缓冲区,每个缓冲区要连续,并将缓冲区中的内容

写到管道envp->hWriterInFifo中(注:该管道在创建线程之前,已打开)。

有用吗?buffer中的数据是什么?

4. Allocate buffers for interacting with the capture thread

              Memory_contigAlloc() 分配连续的缓冲区

              FifoUtil_put(envp->hCaptureInFifo, &ce)  // FIFo且当管道

                            // 将申请的缓冲区放在hCaptureInFifo队列中。

              我的理解,申请若干个缓冲区,每个缓冲区要连续,并将它们放在

采集线程的缓冲队列中。

5. 等待汇集;

6. 当不需要退出时,执行下列步骤:

7. 测试等待状态,按要求决定是否继续。

8.  Get a buffer from the capture thread.  hCaptureOutFifo

       视频线程读采集线程采集的数据-->ce

9. 视频线程从写线程读回数据。àwe

10. ce编码并送到we中。

11. 视频线程将已编码的数据写到管道,由写线程写文件

12. 视频线程将原数据送给采集线程。ce

13. goto 6.

 

 

pause

Pause_open

       初始化互斥变量条件变量;

       且设置pause未暂停,hPause->pause = FALSE;

Pause_test 如果在暂停中则等待,否则继续。

       1. 进入临界区(有互斥变量控制);

       2. 如果在暂停中,则等待在条件变量中;

       3. 退出临界区。

Pause_on

       1. 进入临界区(有互斥变量控制);

       2. 设置暂停标志;

       3. 退出临界区。

Pause_off

       1. 进入临界区(有互斥变量控制);

       2. 如果在暂停中,则清暂停标志,并向其他线程广播该消息;

       3. 退出临界区。

Pause_close

       释放互斥变量和条件变量。

Pause的应用

       显示线程:    开始循环时:Pause_test(envp->hPause);

退出时:Pause_off(envp->hPause);

语音线程:    开始循环时:Pause_test(envp->hPause);

退出时:Pause_off(envp->hPause);

采集线程:    开始循环时:Pause_test(envp->hPause);

退出时:Pause_off(envp->hPause);

写线程:       退出时:Pause_off(envp->hPause);

控制线程:    当按下录制键时:Pause_off(envp->hPause);

                            当按下暂停键时:Pause_on(hPause);

退出时:Pause_off(envp->hPause);

 

fifoutil

  This interface enables easy passing of fixed size messages between POSIX threads in Linux using first in first out ordering. Only one reader and writer per fifo is supported unless the application serializes the calls.

FifoUtil_open

static inline int FifoUtil_open(FifoUtil_Handle hFifo, size_t size)

brief Opens the fifo. Must be called before other API:s on a fifo.

摘要:打开fifo管道。

@param hFifo Pointer to the fifo object to open.

@param size Size in bytes of the messages to be passed through this fifo.

@return FIFOUTIL_SUCCESS for success or FIFOUTIL_FAILURE for failure.

使用管道。

FifoUtil_close

static inline int FifoUtil_close(FifoUtil_Handle hFifo)

brief Closes the fifo. No API calls can be made on this fifo after this.

param hFifo Pointer to the fifo object to close.

return FIFOUTIL_SUCCESS for success or FIFOUTIL_FAILURE for failure.

FifoUtil_get 读管道

FifoUtil_get(FifoUtil_Handle hFifo, void *buffer)

brief Blocking call to get a message from a fifo.

param hFifo Pointer to a previously opened fifo object.

param buffer A pointer to the buffer which will be copied to the fifo.

return FIFOUTIL_SUCCESS for success or FIFOUTIL_FAILURE for failure.

读管道。

static inline int FifoUtil_get(FifoUtil_Handle hFifo, void *buffer)

{

    if (read(hFifo->pipes[0], buffer, hFifo->size) != hFifo->size) {

        return FIFOUTIL_FAILURE;

    }

 

    return FIFOUTIL_SUCCESS;

}

FifoUtil_put 写管道

FifoUtil_put(FifoUtil_Handle hFifo, void *buffer)

@brief Put a message on the fifo.

@param hFifo Pointer to a previously opened fifo object.

@param buffer A pointer to the buffer which will be copied from the fifo.

@return FIFOUTIL_SUCCESS for success or FIFOUTIL_FAILURE for failure.

static inline int FifoUtil_put(FifoUtil_Handle hFifo, void *buffer)

{

    if (write(hFifo->pipes[1], buffer, hFifo->size) != hFifo->size) {

        return FIFOUTIL_FAILURE;

    }

 

    return FIFOUTIL_SUCCESS;

}

0 0
原创粉丝点击