The network live Broadcast system implemented using LIVE555 class library

Source: Internet
Author: User

LIVE555 has four main class libraries:

Libusageenvironment.lib;liblivemedia.lib;libgroupsock.lib;libbasicusageenvironment.lib

After the four class libraries and related header files are imported into vc++2010, the webcast system can be easily implemented.

Here directly affixed to the complete code, paste into the VC inside can be run.

Note: After the program is run, use the Player software (VLC Media player,ffplay, etc.), open url:rtp://239.255.42.42:1234, you can watch live video.

Webcast System. CPP: Defines the entry point for a console application. Rai//Communication University/digital television Technology//leixiaohua1020@126.com #include "stdafx.h" #include "livemedia.hh" #include "Basicusageenviro Nment.hh "#include" groupsockhelper.hh "//#define IMPLEMENT_RTSP_SERVER//#define USE_SSM 1 #ifdef USE_SSM Boolean const
ISSSM = True;
#else Boolean Const ISSSM = False;
#endif #define TRANSPORT_PACKET_SIZE 188 #define Transport_packets_per_network_packet 7 usageenvironment* env;
char const* inputfilename = "Test.ts";
Framedsource* VideoSource;

Rtpsink* Videosink; void Play (); 
  Forward int main (int argc, char** argv) {//First set up the use environment: taskscheduler* scheduler = Basictaskscheduler::createnew ();

  env = Basicusageenvironment::createnew (*scheduler);
Create ' groupsocks ' for RTP and Rtcp:char const* destinationaddressstr #ifdef USE_SSM = "232.255.42.42";
  #else = "239.255.42.42"; Note: This is a multicast address.
  If you want the stream to use a unicast address, then replace this string with a 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 = Our_inet_addr (DESTINATIONADDRESSSTR);
  Const Port Rtpport (rtpportnum);

  Const Port Rtcpport (rtcpportnum);
  Groupsock Rtpgroupsock (*env, Destinationaddress, Rtpport, TTL);
Groupsock Rtcpgroupsock (*env, Destinationaddress, Rtcpport, TTL);
  #ifdef USE_SSM rtpgroupsock.multicastsendonly ();
Rtcpgroupsock.multicastsendonly (); #endif//Create an appropriate "Rtpsink": Videosink = Simplertpsink::createnew (*env, &rtpgroupsock, 90000, "video", "M


  P2T ", 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] = ' the '; #ifdef implement_rtsp_server rtcpinstance* rtcp = #endif rtcpinstance::createnew (*env, &rtcpgroupsock, ES
			 Timatedsessionbandwidth, CNAME,   Videosink, NULL/* we ' re a server */, ISSSM);
  
  Start automatically run media #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 (Passiveservermediasubsession::createnew (*videosink, RTCP));

  Rtspserver->addservermediasession (SMS);
  char* URL = rtspserver->rtspurl (SMS);
  *env << "Play this stream using the URL \" "<< URL <<" \ \ n ";
delete[] URL;
  #endif *env << "Start sending streaming media ... \ n";

  Play (); 

  Env->taskscheduler (). Doeventloop (); return 0; Just to prevent compiler warnings} void Afterplaying (void*/*clientdata*/) {*env << ...

  Read from file \ n ";
  Medium::close (VideoSource); The input file read from the source will be turned off play ();
} void Play () {unsigned const INPUTDATACHUNKSIZE = transport_packets_per_network_packet*transport_packet_size; Open the input file as a "Bytestreamfilesource": bytestreamfilesource* Filesource = bytestreamfilesource::createnew (*env, INP
  Utfilename, inputdatachunksize);
    if (Filesource = = NULL) {*env << "cannot open file \" "<< inputfilename <<" \ "as File source\n";
  Exit (1);

  
  } VideoSource = Mpeg2transportstreamframer::createnew (*env, Filesource);
  *env << "beginning to read from file...\n";
Videosink->startplaying (*videosource, afterplaying, Videosink); }

Complete Project Download Address: http://download.csdn.net/detail/leixiaohua1020/6272839

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.