⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 writer.c

📁 TI DM6446板卡上调用encode engine进行编码的例子程序
💻 C
字号:
/* * writer.c * * ============================================================================ * Copyright (c) Texas Instruments Inc 2005 * * Use of this software is controlled by the terms and conditions found in the * license agreement under which this software has been supplied or provided. * ============================================================================ *//* Standard Linux headers */#include <stdio.h>/* Demo headers */#include <rendezvous.h>#include <fifoutil.h>#include "encode.h"#include "writer.h"/* The levels of initialization */#define VIDEOFILEINITIALIZED      0x1/****************************************************************************** * writerThrFxn ******************************************************************************/void *writerThrFxn(void *arg){    OutBufferElement   outFlush      = { WRITER_FLUSH };    unsigned int       initMask      = 0;    WriterEnv         *envp          = (WriterEnv *) arg;    void              *status        = THREAD_SUCCESS;    FILE              *outputFp;    OutBufferElement   oe;    /* Open the output video file */    outputFp = fopen(envp->videoFile, "w");    if (outputFp == NULL) {        ERR("Failed to open %s for writing\n", envp->videoFile);        cleanup(THREAD_FAILURE);    }    DBG("Video file successfully opened\n");    initMask |= VIDEOFILEINITIALIZED;    /* Signal that initialization is done and wait for other threads */    Rendezvous_meet(envp->hRendezvous);    DBG("Entering writer main loop.\n");    while (TRUE) {        /* Get an encoded buffer from the video thread */        if (FifoUtil_get(&envp->outFifo, &oe) == FIFOUTIL_FAILURE) {                    breakLoop(THREAD_FAILURE);        }        /* Is the video thread flushing the pipe? */        if (oe.id == WRITER_FLUSH) {            breakLoop(THREAD_SUCCESS);        }        /* Store the encoded frame to disk */        if (oe.id != WRITER_PRIME && oe.frameSize) {            if (fwrite(oe.encodedBuffer, oe.frameSize, 1, outputFp) != 1) {                ERR("Error writing the encoded data to video file\n");                breakLoop(THREAD_FAILURE);            }        }        /* Send back the buffer to the video thread */        oe.id = 0;        if (FifoUtil_put(&envp->inFifo, &oe) == FIFOUTIL_FAILURE) {            ERR("Failed to put buffer in output fifo\n");            breakLoop(THREAD_FAILURE);        }    }cleanup:    /* Make sure the other threads aren't waiting for init to complete */    Rendezvous_force(envp->hRendezvous);    /* Make sure the video thread isn't stuck in FifoUtil_get() */    FifoUtil_put(&envp->inFifo, &outFlush);    if (initMask & VIDEOFILEINITIALIZED) {        fclose(outputFp);    }    return status;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -