A network broadcast system using the LIVE555 class library

Source: Internet
Author: User

LIVE555 There are four main classes of libraries:

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

After importing these four class libraries and related header files into the vc++2010, you can easily implement a live webcast system.

Here directly paste the full code, pasted into the VC inside can run.

Note: Once the program is running, use the Player software (VLC Media player,ffplay, etc.) to open the url:rtp://239.255.42.42:1234 and watch the live video.

Webcast System. CPP: Defines the entry point of the console application. Rai//Communication University/Digital TV 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 established usage 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 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 = 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, I, 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] = ' + '; #ifdef implement_rtsp_server rtcpinstance* rtcp = #endif rtcpinstance::createnew (*env, &rtcpgroupsock, ES
			 Timatedsessionbandwidth, CNAME,   VideoSink, NULL/* we ' re a server */, ISSSM);
  
  Start auto-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 warning} void Afterplaying (void*/*clientdata*/) {*env << "...

  Read from file \ n ";
  Medium::close (VideoSource); The input file read from the source will be closed play ();
void Play () {unsigned const INPUTDATACHUNKSIZE = transport_packets_per_network_packet*transport_packet_size; Open 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); }

Full 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.