Hello everyone,
I am now modify the encode example provided withe DVSDK, and I want to do event recording.
Originally, the example writes the encoded frame into one video.
Now, in my own application, I add one function to do determine the input frame is good or bad.
The algorithm is checked and with no problem.
And I want to write the good frames into one video, and bad frames to another.
So, as I can think of, I decided to modify the write thread of the example.
I have marked the modified part red.
/******************************************************************************
* writerThrFxn
******************************************************************************/
void *writerThrFxn(void *arg)
{
WriterBufferElement wFlush = { WRITER_FLUSH };
WriterEnv *envp = (WriterEnv *) arg;
void *status = THREAD_SUCCESS;
FILE *outputFp = NULL;
WriterBufferElement we;
/* Open the output video file */
outputFp = fopen("goodframe.mpeg4", "w");
outputFp2=fopen("badframe.mpeg4.mpeg4","w");
if (outputFp == NULL) {
ERR("Failed to open %s for writing\n", goodframe.mpeg4);
cleanup(THREAD_FAILURE);
}
if (outputFp2 == NULL) {
ERR("Failed to open %s for writing\n", video.mpeg4);
cleanup(THREAD_FAILURE);
}
DBG("Video file successfully opened\n");
/* Signal that initialization is done and wait for other threads */
Rendezvous_meet(envp->hRendezvousInit);
DBG("Entering writer main loop.\n");
while (TRUE) {
/* Get an encoded buffer from the video thread */
if (FifoUtil_get(&envp->inFifo, &we) == FIFOUTIL_FAILURE) {
breakLoop(THREAD_FAILURE);
}
/* Is the video thread flushing the pipe? */
if (we.id == WRITER_FLUSH) {
breakLoop(THREAD_SUCCESS);
}
/* Store the encoded frame to disk */
if (we.id != WRITER_PRIME && we.frameSize) {
if(good())
{
if (fwrite(we.encodedBuffer, we.frameSize, 1, outputFp) != 1) {
ERR("Error writing the encoded data to video file\n");
breakLoop(THREAD_FAILURE); }
}
else
{
if (fwrite(we.encodedBuffer, we.frameSize, 1, outputFp2) != 1) {
ERR("Error writing the encoded data to video file\n");
breakLoop(THREAD_FAILURE); }
}
}
else {
we.id = WRITER_NORMAL;
}
/* Send back the buffer to the video thread */
if (FifoUtil_put(&envp->outFifo, &we) == 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->hRendezvousInit);
/* Make sure the other threads aren't stuck pausing */
Pause_off(envp->hPause);
/* Make sure the video thread isn't stuck in FifoUtil_get() */
FifoUtil_put(&envp->outFifo, &wFlush);
/* Meet up with other threads before cleaning up */
Rendezvous_meet(envp->hRendezvousCleanup);
if (outputFp) {
fclose(outputFp);
}
if (outputFp2) {
fclose(outputFp2);
}
return status;
}