[Live-devel] DeviceSource.cpp problem (code)

Xiao Li geniusbill at gmail.com
Fri Feb 13 07:53:12 PST 2009


*Below is the code to assist you to understand my previous question, many
thanks!

envpW = envp; (Note: envpW  is the global variable that I used to get the
encoded frame from the writer thread)*

void EncoderSource::doGetNextFrame() {
   deliverFrame();

  if (0 /* the source stops being readable */) {
    handleClosure(this);
    return;
  }
}

void EncoderSource::deliverFrame() {
  // Deliver the data here:

    //Below from original write.cpp
    //FILE  *outputFp = NULL;
    //WriterEnv          *envp          = (WriterEnv *) arg;
    //void               *status        = THREAD_SUCCESS;
    extern WriterEnv  *envpW;
    WriterBufferElement we2;

    //while (TRUE) {

        /* Get an encoded buffer from the video thread */
        if (FifoUtil_get(&envpW->inFifo, &we2) == FIFOUTIL_FAILURE)
    {
        }

    //Set Device Source Params...
    if (we2.frameSize > fMaxSize){
    we2.frameSize = fMaxSize;
    }

     //Copy to DeviceSource...
    //fTo = (unsigned char*)malloc(we2.frameSize);
    memcpy(fTo, we2.encodedBuffer, we2.frameSize);

    printf("Frame %d bytes %d\n", we2.frameSize,fMaxSize);

        /* Send back the buffer to the video thread */
        if (FifoUtil_put(&envpW->outFifo, &we2) == FIFOUTIL_FAILURE) {
            ERR("Failed to put buffer in output fifo\n");
        }
     // Final cleanup.

  // After delivering the data, inform the reader that it is now available:
 nextTask() = envir().taskScheduler().scheduleDelayedTask(0,
                (TaskFunc*)FramedSource::afterGetting, this);
}

void *writerThread(void *arg)
{
extern WriterEnv  *envpW;

    WriterBufferElement wFlush        = { WRITER_FLUSH };
    WriterEnv          *envp          = (WriterEnv *) arg;
    void               *status        = THREAD_SUCCESS;
    WriterBufferElement we;

    *envpW = envp;*
    /* Signal that initialization is done and wait for other threads */
    Rendezvous_meet(envp->hRendezvousInit);

    ERR("Entering writer main loop.\n");

    startMPEG4Streamer();

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);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20090213/71b487af/attachment.html>


More information about the live-devel mailing list