Advertisement
Guest User

Untitled

a guest
Nov 7th, 2012
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. int main(int argc, char** argv) {
  2. // Begin by setting up our usage environment:
  3. TaskScheduler* scheduler = BasicTaskScheduler::createNew();
  4. env = BasicUsageEnvironment::createNew(*scheduler);
  5.  
  6. char const* destinationAddressStr = "239.255.42.42";
  7. const unsigned short rtpPortNum = 1234;
  8. const unsigned short rtcpPortNum = rtpPortNum+1;
  9. const unsigned char ttl = 7; // low, in case routers don't admin scope
  10.  
  11. struct in_addr destinationAddress;
  12. destinationAddress.s_addr = our_inet_addr(destinationAddressStr);
  13. const Port rtpPort(rtpPortNum);
  14. const Port rtcpPort(rtcpPortNum);
  15.  
  16. Groupsock rtpGroupsock(*env, destinationAddress, rtpPort, ttl);
  17. Groupsock rtcpGroupsock(*env, destinationAddress, rtcpPort, ttl);
  18.  
  19. videoSink =
  20. SimpleRTPSink::createNew(*env, &rtpGroupsock, 33, 90000, "video", "MP2T",
  21. 1, True, False /*no 'M' bit*/);
  22.  
  23. // Create (and start) a 'RTCP instance' for this RTP sink:
  24. const unsigned estimatedSessionBandwidth = 5000; // in kbps; for RTCP b/w share
  25. const unsigned maxCNAMElen = 100;
  26. unsigned char CNAME[maxCNAMElen+1];
  27. gethostname((char*)CNAME, maxCNAMElen);
  28. CNAME[maxCNAMElen] = '\0'; // just in case
  29. RTCPInstance::createNew(*env, &rtcpGroupsock,
  30. estimatedSessionBandwidth, CNAME,
  31. videoSink, NULL /* we're a server */, False);
  32.  
  33. // Open the input file as a 'byte-stream file source':
  34. FramedSource* inputSource = ByteStreamFileSource::createNew(*env, inputFileName);
  35. if (inputSource == NULL) {
  36. *env << "Unable to open file \"" << inputFileName
  37. << "\" as a byte-stream file source\n";
  38. exit(1);
  39. }
  40.  
  41. // Create a 'framer' filter for this file source, to generate presentation times for each NAL unit:
  42. H264VideoStreamFramer* framer = H264VideoStreamFramer::createNew(*env, inputSource, True);
  43.  
  44. // Then create a filter that packs the H.264 video data into a Transport Stream:
  45. tsFrames = MPEG2TransportStreamFromESSource::createNew(*env);
  46. tsFrames->addNewVideoSource(framer, 5/*mpegVersion: H.264*/);
  47.  
  48. play();
  49.  
  50. env->taskScheduler().doEventLoop(); // does not return
  51.  
  52. return 0; // only to prevent compiler warning
  53. }
  54. void play()
  55. {
  56. *env << "Beginning to read...\n";
  57. videoSink->startPlaying(*tsFrames, afterPlaying, videoSink);
  58. }
  59.  
  60. void afterPlaying(void* /*clientData*/)
  61. {
  62. *env << "...done reading from file\n";
  63.  
  64. videoSink->stopPlaying();
  65.  
  66. play();
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement