<b style="color: rgb(255, 0, 0);">Below is the code to assist you to understand my previous question, many thanks!<br><br>envpW = envp; (Note: envpW is the global variable that I used to get the encoded frame from the writer thread)</b><br>
<br>void EncoderSource::doGetNextFrame() {<br> deliverFrame();<br> <br> if (0 /* the source stops being readable */) {<br> handleClosure(this);<br> return;<br> }<br>}<br><br>void EncoderSource::deliverFrame() {<br>
// Deliver the data here:<br><br> //Below from original write.cpp<br> //FILE *outputFp = NULL;<br> //WriterEnv *envp = (WriterEnv *) arg;<br> //void *status = THREAD_SUCCESS;<br>
extern WriterEnv *envpW;<br> WriterBufferElement we2;<br><br> //while (TRUE) {<br> <br> /* Get an encoded buffer from the video thread */<br> if (FifoUtil_get(&envpW->inFifo, &we2) == FIFOUTIL_FAILURE) <br>
{<br> }<br><br> //Set Device Source Params...<br> if (we2.frameSize > fMaxSize){<br> we2.frameSize = fMaxSize;<br> }<br> <br> //Copy to DeviceSource...<br> //fTo = (unsigned char*)malloc(we2.frameSize);<br>
memcpy(fTo, we2.encodedBuffer, we2.frameSize);<br> <br> printf("Frame %d bytes %d\n", we2.frameSize,fMaxSize);<br><br> /* Send back the buffer to the video thread */<br> if (FifoUtil_put(&envpW->outFifo, &we2) == FIFOUTIL_FAILURE) {<br>
ERR("Failed to put buffer in output fifo\n");<br> }<br> // Final cleanup.<br><br> // After delivering the data, inform the reader that it is now available:<br> nextTask() = envir().taskScheduler().scheduleDelayedTask(0,<br>
(TaskFunc*)FramedSource::afterGetting, this);<br>}<br><br>void *writerThread(void *arg)<br>{<br>extern WriterEnv *envpW;<br><br> WriterBufferElement wFlush = { WRITER_FLUSH };<br> WriterEnv *envp = (WriterEnv *) arg;<br>
void *status = THREAD_SUCCESS;<br> WriterBufferElement we;<br><br> <b style="color: rgb(255, 0, 0);">envpW = envp;</b><br> /* Signal that initialization is done and wait for other threads */<br>
Rendezvous_meet(envp->hRendezvousInit);<br><br> ERR("Entering writer main loop.\n");<br><br> startMPEG4Streamer();<br><br>cleanup:<br> /* Make sure the other threads aren't waiting for init to complete */<br>
Rendezvous_force(envp->hRendezvousInit);<br><br> /* Make sure the other threads aren't stuck pausing */<br> Pause_off(envp->hPause);<br><br> /* Make sure the video thread isn't stuck in FifoUtil_get() */<br>
FifoUtil_put(&envp->outFifo, &wFlush);<br><br> /* Meet up with other threads before cleaning up */<br> Rendezvous_meet(envp->hRendezvousCleanup);<br>}<br>