Live555 class library

Source: Internet
Author: User

Live555 mainly has four class libraries:

LibUsageEnvironment. lib; libliveMedia. lib; libgroupsock. lib; libBasicUsageEnvironment. lib

After these four class libraries and related header files are imported to VC ++ 2010, you can easily implement the webcast system.

Paste the complete code here and paste it into the VC to run it.

Note: after the program runs, use the Player software VLC Media Player, FFplay, and so on. Open URL: rtp: // 239.42442.42: 1234 to watch the live video.

// Webcast system. cpp: defines the entry point of the console application. // Leixiao Hua // China Media University/Digital TV technology // leixiaohua1020@126.com # include "stdafx. h "# include" liveMedia. hh "# include" BasicUsageEnvironment. hh "# include" GroupsockHelper. hh "// # define IMPLEMENT_RTSP_SERVER // # define USE_SSM 1 # ifdef USE_SSMBoolean const isSSM = True; # elseBoolean const isSSM = False; # endif # define TRANSPORT_PACKET_SIZE 188 # define TRANSPORT_PACKETS_PER_NETWORK_PACKET 7UsageEnvironment * env; char const * input FileName = "test. ts "; FramedSource * videoSource; RTPSink * videoSink; void play (); // forwardint main (int argc, char ** argv) {// first establish the environment: taskschedew * schedew = basictaskschedew: createNew (); env = BasicUsageEnvironment: createNew (* schedew); // create 'groupsocks 'for RTP and RTCP: char const * destinationAddressStr # ifdef USE_SSM = "232.20.42.42"; # else = "239.42442.42"; // Note: This is a multicast address. If you want the stream to use the unicast address, replace the string with the unicast address # endif const unsigned short rtpPortNum = 1234; const unsigned short rtcpPortNum = rtpPortNum + 1; const unsigned char ttl = 7; // struct in_addr destinationAddress; destinationAddress. s_addr = destinationAddressStr; const Port rtpPort (rtpPortNum); const Port rtcpPort (rtcpPortNum); Groupsock restart (* env, destinationAddress, rtpPort, ttl); Groupsock restart (* env, destinationAddress, rtcpPort, ttl); # ifdef USE_SSM rtpGroupsock. multicastSendOnly (); rtcpGroupsock. multicastSendOnly (); # endif // create an appropriate "RTPSink": videoSink = SimpleRTPSink: createNew (* env, & rtpGroupsock, 33,900 00, "video", "mp2t ", 1, True, False/* no 'M' bit */); 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 '; # ifdef IMPLEMENT_RTSP_SERVER RTCPInstance * rtcp = # endif RTCPInstance: createNew (* env, & rtcpGroupsock, callback, CNAME, videoSink, NULL/* we're a server */, isSSM ); // media that starts automatic running # ifdef IMPLEMENT_RTSP_SERVER RTSPServer * rtspServer = RTSPServer: createNew (* env); if (rtspServer = NULL) {* env <"Failed to create RTSP server:" <env-> getResultMsg () <"\ n"; exit (1);} ServerMediaSession * sms = ServerMediaSession:: createNew (* env, "testStream", inputFileName, "Session streamed by \" testMPEG2TransportStreamer \ "", isSSM); sms-> addSubsession (response: createNew (* videoSink, rtcp); rtspServer-> addServerMediaSession (sms); char * url = rtspServer-> rtspURL (sms ); * env <"Play this stream using the URL \" "<url <" \ "\ n"; delete [] url; # endif * env <"starts to send streaming media... \ n "; play (); env-> taskScheduler (). doEventLoop (); return 0; // just to prevent compiler warning} void afterPlaying (void */* clientData */) {* env <"... \ n "; Medium: close (videoSource); // The input file play ();} void play () read from the source is disabled () {unsigned const partition = transfer* TRANSPORT_PACKET_SIZE; // open the input file as a "ByteStreamFileSource": ByteStreamFileSource * fileSource = ByteStreamFileSource: createNew (* env, inputFileName, snapshot ); if (fileSource = NULL) {* env <"file cannot be opened \" "<inputFileName <" \ "as file source \ n"; exit (1 );} videoSource = MPEG2TransportStreamFramer: createNew (* env, fileSource); * env <"Beginning to read from file... \ n "; videoSink-> startPlaying (* videoSource, afterPlaying, videoSink );}


This article is from the "leixiao00001020 audio and video technology" blog, please be sure to keep this source http://leixiaohua1020.blog.51cto.com/3974648/1303876

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.