[Live-devel] TRYED TO FIND BIT RATE BUT NOT GETTING

Ketan Gholap ketangholap1990 at gmail.com
Fri Jul 13 07:00:55 PDT 2012


Hello Sir
As told by you i try'ed to find the bit/byte rte but every time i am
getting zero could please tell me where i am wrong.I would be very thank
full to you



// A test program that reads a MPEG-2 Transport Stream file,
// and streams it using RTP
// main program

#include "liveMedia.hh"
#include "BasicUsageEnvironment.hh"
#include "GroupsockHelper.hh"

// To stream using "source-specific multicast" (SSM), uncomment the
following:
//#define USE_SSM 1
#ifdef USE_SSM
Boolean const isSSM = True;
#else
Boolean const isSSM = False;
#endif

// To set up an internal RTSP server, uncomment the following:
#define IMPLEMENT_RTSP_SERVER 1
// (Note that this RTSP server works for multicast only)

#define TRANSPORT_PACKET_SIZE 188
#define TRANSPORT_PACKETS_PER_NETWORK_PACKET 7
// The product of these two numbers must be enough to fit within a network
packet

UsageEnvironment* env;
char const* inputFileName = "test.ts";
FramedSource* videoSource;
RTPSink* videoSink;
 int64_t uSecsToDelay=1000000;
void play(); // forward
void a(RTPSink* sink);
void periodicQOSMeasurement1(void* clientData);
int CreateINI();
char *sstreamip;
int SSport;

int main(int argc, char** argv) {
  // Begin by setting up our usage environment:
  TaskScheduler* scheduler = BasicTaskScheduler::createNew();
  env = BasicUsageEnvironment::createNew(*scheduler);
 //CreateINI();

  // 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 wish to stream using
  // unicast instead, then replace this string with the unicast address
  // of the (single) destination.  (You may also need to make a similar
  // change to the receiver program.)
#endif
  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);
#ifdef USE_SSM
  rtpGroupsock.multicastSendOnly();
  rtcpGroupsock.multicastSendOnly();
#endif

  // Create an appropriate 'RTP sink' from the RTP 'groupsock':
  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
#ifdef IMPLEMENT_RTSP_SERVER
  RTCPInstance* rtcp =
#endif
    RTCPInstance::createNew(*env, &rtcpGroupsock,
    estimatedSessionBandwidth, CNAME,
    videoSink, NULL /* we're a server */, isSSM);
  // Note: This starts RTCP running automatically

#ifdef IMPLEMENT_RTSP_SERVER
  RTSPServer* rtspServer = RTSPServer::createNew(*env);
  // Note that this (attempts to) start a server on the default RTSP server
  // port: 554.  To use a different port number, add it as an extra
  // (optional) parameter to the "RTSPServer::createNew()" call above.
  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

  // Finally, start the streaming:
  *env << "Beginning streaming...\n";
  play();
  a(videoSink);

  env->taskScheduler().doEventLoop(); // does not return


  return 0; // only to prevent compiler warning
}

void afterPlaying(void* /*clientData*/) {
  *env << "...done reading from file\n";

  videoSink->stopPlaying();
  Medium::close(videoSource);
  // Note that this also closes the input file that this source read from.

  play();
}

void play() {
  unsigned const inputDataChunkSize
    = TRANSPORT_PACKETS_PER_NETWORK_PACKET*TRANSPORT_PACKET_SIZE;

  // Open the input file as a 'byte-stream file source':
  ByteStreamFileSource* fileSource
    = ByteStreamFileSource::createNew(*env, inputFileName,
inputDataChunkSize);
  if (fileSource == NULL) {
    *env << "Unable to open file \"" << inputFileName
 << "\" as a byte-stream file source\n";
    exit(1);
  }

  // Create a 'framer' for the input source (to give us proper inter-packet
gaps):
  videoSource = MPEG2TransportStreamFramer::createNew(*env, fileSource);

  // Finally, start playing:
  *env << "Beginning to read from file...\n";
  videoSink->startPlaying(*videoSource, afterPlaying, videoSink);


}



*void periodicQOSMeasurement1(void* clientData) *
*{*
* struct timeval timeNow;*
* gettimeofday(&timeNow, NULL);
RTPSink* sink = (RTPSink*)clientData;
*
* int s1=timeNow.tv_sec;*
* printf("value of s1 %d\n",s1);*
* int o1= videoSink->octetCount();*
* printf("value of o1 %d\n",o1);*
* int s2=timeNow.tv_sec;*
* printf("value of s2 %d\n",s2);*
*
*
* int o2= videoSink->octetCount();*
* printf("value of o2 %d\n",o2);*
* double mbits_sent = (o2 - o1) / 1024.0 / 1024.0 / (s2 - s1);*
* printf("mbits_sent is %ld\n",mbits_sent);*
* env->taskScheduler().**scheduleDelayedTask(**uSecsToDelay, (TaskFunc*)**
periodicQOSMeasurement1,**clientData);*
*
*
*
*
*
*
*
*
*
*
*}*
*void a(RTPSink* sink)*
*{*
* //periodicQOSMeasurement1((**void*)NULL);*
* periodicQOSMeasurement1(sink);*
*}*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20120713/d58f475c/attachment-0001.html>


More information about the live-devel mailing list