Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(int argc, char** argv) {
- // Begin by setting up our usage environment:
- TaskScheduler* scheduler = BasicTaskScheduler::createNew();
- env = BasicUsageEnvironment::createNew(*scheduler);
- char const* destinationAddressStr = "239.255.42.42";
- const unsigned short rtpPortNum = 1234;
- const unsigned short rtcpPortNum = rtpPortNum+1;
- const unsigned char ttl = 7; // low, in case routers don't admin scope
- struct in_addr destinationAddress;
- destinationAddress.s_addr = our_inet_addr(destinationAddressStr);
- const Port rtpPort(rtpPortNum);
- const Port rtcpPort(rtcpPortNum);
- Groupsock rtpGroupsock(*env, destinationAddress, rtpPort, ttl);
- Groupsock rtcpGroupsock(*env, destinationAddress, rtcpPort, ttl);
- videoSink =
- SimpleRTPSink::createNew(*env, &rtpGroupsock, 33, 90000, "video", "MP2T",
- 1, True, False /*no 'M' bit*/);
- // Create (and start) a 'RTCP instance' for this RTP sink:
- const unsigned estimatedSessionBandwidth = 5000; // in kbps; for RTCP b/w share
- const unsigned maxCNAMElen = 100;
- unsigned char CNAME[maxCNAMElen+1];
- gethostname((char*)CNAME, maxCNAMElen);
- CNAME[maxCNAMElen] = '\0'; // just in case
- RTCPInstance::createNew(*env, &rtcpGroupsock,
- estimatedSessionBandwidth, CNAME,
- videoSink, NULL /* we're a server */, False);
- // Open the input file as a 'byte-stream file source':
- FramedSource* inputSource = ByteStreamFileSource::createNew(*env, inputFileName);
- if (inputSource == NULL) {
- *env << "Unable to open file \"" << inputFileName
- << "\" as a byte-stream file source\n";
- exit(1);
- }
- // Create a 'framer' filter for this file source, to generate presentation times for each NAL unit:
- H264VideoStreamFramer* framer = H264VideoStreamFramer::createNew(*env, inputSource, True);
- // Then create a filter that packs the H.264 video data into a Transport Stream:
- tsFrames = MPEG2TransportStreamFromESSource::createNew(*env);
- tsFrames->addNewVideoSource(framer, 5/*mpegVersion: H.264*/);
- play();
- env->taskScheduler().doEventLoop(); // does not return
- return 0; // only to prevent compiler warning
- }
- void play()
- {
- *env << "Beginning to read...\n";
- videoSink->startPlaying(*tsFrames, afterPlaying, videoSink);
- }
- void afterPlaying(void* /*clientData*/)
- {
- *env << "...done reading from file\n";
- videoSink->stopPlaying();
- play();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement