1. 程式人生 > >Davinci encode分析(DM355)

Davinci encode分析(DM355)

對視訊和音訊進行編碼

音訊演算法是G.711

視訊演算法是mpeg4和H.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;

}