[Live-devel] How to dispatch media data to multiple sinks?

alphax alphax at vip.163.com
Fri Oct 14 01:42:12 PDT 2011


At 2011-10-14 12:34:56,"Ross Finlayson" <finlayson at live555.com> wrote:

No, unfortunately there's no general 'frame duplicator' mechanism in our library.




Now, I known I can use a FileSink for save the media data to file.

RTPSource -> FileSink

But, how to send to the live player simultaneously? Should I make a Filter class, so the chain becomes:

RTPSource -> Filter -> RTPSink(to player)



Yes, the simplest thing to do here would be to write your own filter class (a subclass of "FramedFilter") that copies input frames to the output, but also writes them to a file.  The "writing to a file" would be done directly (i.e., using "fwrite()"), rather than using a "FileSink").




If I should do so, how about send to 2 and more live player


The simplest way to do this is just to use multicast.  I.e., send the frames out just once (using a single "RTPSink" object, but do so using an IP multicast address).  (E.g., our "testRelay" demo application does something like this.)


Ross Finlayson
Live Networks, Inc.
http://www.live555.com/

Thank you for your reply!

I just wrote a simple Filter class:
===========================================================
H264VideoFilter::H264VideoFilter(UsageEnvironment& env,
        H264VideoRTPSource* source, char* saveToFileName) :
    FramedSource(env) {
    this->source = source;
    this->saveToFileName = saveToFileName;

    fileToSave = fopen(saveToFileName, "rw");
}

H264VideoFilter::~H264VideoFilter() {
    if (fileToSave != NULL) {
        fclose(fileToSave);
    }
}

void H264VideoFilter::onCloseCallback(void *clientData) {
    H264VideoFilter* filter = (H264VideoFilter*) clientData;

    if (filter->fileToSave != NULL) {
        fclose(filter->fileToSave);
        filter->fileToSave = NULL;
    }
}

void H264VideoFilter::afterGettingCallback(void *clientData,
        unsigned frameSize, unsigned numTruncatedBytes,
        struct timeval presentationTime, unsigned durationInMicroseconds) {

    H264VideoFilter* source = (H264VideoFilter*) clientData;
   /* save the frame to file */
    fwrite((void*)source->fTo, (size_t)frameSize, 1, source->fileToSave);

    FramedSource::afterGetting(source);
}

void H264VideoFilter::doGetNextFrame() {
    source->getNextFrame(fTo, fMaxSize, &afterGettingCallback, this,
            &onCloseCallback, this);
}
===========================================================
Now, I can use this filter as the source of my custom subsession object, then pass True as reuseFirstSource argument of the subsession constructor, so I can just use one filter to serve multiple remote player, right?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20111014/ccdae190/attachment.html>


More information about the live-devel mailing list