Hello Sir<br>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<br><div class="gmail_quote"><br><br><div><br></div>
<div>// A test program that reads a MPEG-2 Transport Stream file,</div><div>// and streams it using RTP</div><div>// main program</div><div><br></div><div>#include "liveMedia.hh"</div><div>#include "BasicUsageEnvironment.hh"</div>
<div>#include "GroupsockHelper.hh"</div><div><br></div><div>// To stream using "source-specific multicast" (SSM), uncomment the following:</div><div>//#define USE_SSM 1</div><div>#ifdef USE_SSM</div><div>
Boolean const isSSM = True;</div><div>#else</div><div>Boolean const isSSM = False;</div><div>#endif</div><div><br></div><div>// To set up an internal RTSP server, uncomment the following:</div><div>#define IMPLEMENT_RTSP_SERVER 1</div>
<div>// (Note that this RTSP server works for multicast only)</div><div><br></div><div>#define TRANSPORT_PACKET_SIZE 188</div><div>#define TRANSPORT_PACKETS_PER_NETWORK_PACKET 7</div><div>// The product of these two numbers must be enough to fit within a network packet</div>
<div><br></div><div>UsageEnvironment* env;</div><div>char const* inputFileName = "test.ts";</div><div>FramedSource* videoSource;</div><div>RTPSink* videoSink;</div><div> int64_t uSecsToDelay=1000000;</div><div>
void play(); // forward</div>
<div>void a(RTPSink* sink);</div><div>void periodicQOSMeasurement1(void* clientData);</div><div>int CreateINI();</div><div>char *sstreamip;</div><div>int SSport;</div><div><br></div><div>int main(int argc, char** argv) {</div>
<div> // Begin by setting up our usage environment:</div><div> TaskScheduler* scheduler = BasicTaskScheduler::createNew();</div><div> env = BasicUsageEnvironment::createNew(*scheduler);</div><div> //CreateINI();</div>
<div>
<br></div><div> // Create 'groupsocks' for RTP and RTCP:</div><div> char const* destinationAddressStr</div><div>#ifdef USE_SSM</div><div> = "232.255.42.42";</div><div>#else</div><div> = "239.255.42.42";</div>
<div> // Note: This is a multicast address. If you wish to stream using</div><div> // unicast instead, then replace this string with the unicast address</div><div> // of the (single) destination. (You may also need to make a similar</div>
<div> // change to the receiver program.)</div><div>#endif</div><div> const unsigned short rtpPortNum = 1234;</div><div> const unsigned short rtcpPortNum</div><div><span style="white-space:pre-wrap"> </span> = rtpPortNum+1;</div>
<div> const unsigned char ttl = 7; // low, in case routers don't admin scope</div><div><br></div><div> struct in_addr destinationAddress;</div><div> destinationAddress.s_addr = our_inet_addr(destinationAddressStr);</div>
<div> const Port rtpPort(rtpPortNum);</div><div> const Port rtcpPort(rtcpPortNum);</div><div><br></div><div> Groupsock rtpGroupsock(*env, destinationAddress, rtpPort, ttl);</div><div> Groupsock rtcpGroupsock(*env, destinationAddress, rtcpPort, ttl);</div>
<div>#ifdef USE_SSM</div><div> rtpGroupsock.multicastSendOnly();</div><div> rtcpGroupsock.multicastSendOnly();</div><div>#endif</div><div><br></div><div> // Create an appropriate 'RTP sink' from the RTP 'groupsock':</div>
<div> videoSink =</div><div> SimpleRTPSink::createNew(*env, &rtpGroupsock, 33, 90000, "video", "MP2T",</div><div><span style="white-space:pre-wrap"> </span> 1, True, False /*no 'M' bit*/);</div>
<div><br></div><div> // Create (and start) a 'RTCP instance' for this RTP sink:</div><div> const unsigned estimatedSessionBandwidth = 5000; // in kbps; for RTCP b/w share</div><div> const unsigned maxCNAMElen = 100;</div>
<div> unsigned char CNAME[maxCNAMElen+1];</div><div> gethostname((char*)CNAME, maxCNAMElen);</div><div> CNAME[maxCNAMElen] = '\0'; // just in case</div><div>#ifdef IMPLEMENT_RTSP_SERVER</div><div> RTCPInstance* rtcp =</div>
<div>#endif</div><div> RTCPInstance::createNew(*env, &rtcpGroupsock,</div><div><span style="white-space:pre-wrap"> </span> estimatedSessionBandwidth, CNAME,</div><div><span style="white-space:pre-wrap"> </span> videoSink, NULL /* we're a server */, isSSM);</div>
<div> // Note: This starts RTCP running automatically</div><div><br></div><div>#ifdef IMPLEMENT_RTSP_SERVER</div><div> RTSPServer* rtspServer = RTSPServer::createNew(*env);</div><div> // Note that this (attempts to) start a server on the default RTSP server</div>
<div> // port: 554. To use a different port number, add it as an extra</div><div> // (optional) parameter to the "RTSPServer::createNew()" call above.</div><div> if (rtspServer == NULL) {</div><div> *env << "Failed to create RTSP server: " << env->getResultMsg() << "\n";</div>
<div> exit(1);</div><div> }</div><div> ServerMediaSession* sms</div><div> = ServerMediaSession::createNew(*env, "testStream", inputFileName,</div><div><span style="white-space:pre-wrap"> </span> "Session streamed by \"testMPEG2TransportStreamer\"",</div>
<div><span style="white-space:pre-wrap"> </span> isSSM);</div><div> sms->addSubsession(PassiveServerMediaSubsession::createNew(*videoSink, rtcp));</div><div> rtspServer->addServerMediaSession(sms);</div>
<div><br></div><div> char* url = rtspServer->rtspURL(sms);</div><div> *env << "Play this stream using the URL \"" << url << "\"\n";</div><div> delete[] url;</div><div>
#endif</div><div><br></div><div> // Finally, start the streaming:</div><div> *env << "Beginning streaming...\n";</div><div> play();</div><div> a(videoSink);</div><div><br></div>
<div> env->taskScheduler().doEventLoop(); // does not return</div><div><br></div><div><br></div><div> return 0; // only to prevent compiler warning</div>
<div>}</div><div><br></div><div>void afterPlaying(void* /*clientData*/) {</div><div> *env << "...done reading from file\n";</div><div><br></div><div> videoSink->stopPlaying();</div><div> Medium::close(videoSource);</div>
<div> // Note that this also closes the input file that this source read from.</div><div><br></div><div> play();</div><div>}</div><div><br></div><div>void play() {</div><div> unsigned const inputDataChunkSize</div><div>
= TRANSPORT_PACKETS_PER_NETWORK_PACKET*TRANSPORT_PACKET_SIZE;</div><div><br></div><div> // Open the input file as a 'byte-stream file source':</div><div> ByteStreamFileSource* fileSource</div><div> = ByteStreamFileSource::createNew(*env, inputFileName, inputDataChunkSize);</div>
<div> if (fileSource == NULL) {</div><div> *env << "Unable to open file \"" << inputFileName</div><div><span style="white-space:pre-wrap"> </span> << "\" as a byte-stream file source\n";</div>
<div> exit(1);</div><div> }</div><div><br></div><div> // Create a 'framer' for the input source (to give us proper inter-packet gaps):</div><div> videoSource = MPEG2TransportStreamFramer::createNew(*env, fileSource);</div>
<div><br></div><div> // Finally, start playing:</div><div> *env << "Beginning to read from file...\n";</div><div> videoSink->startPlaying(*videoSource, afterPlaying, videoSink);</div><div><br></div>
<div><br></div><div>}</div><div><br></div>
<div><br></div><div><br></div><div><b>void periodicQOSMeasurement1(void* clientData) </b></div><div><b>{</b></div><div><b><span style="white-space:pre-wrap"> </span>struct timeval timeNow;</b></div><div><b><span style="white-space:pre-wrap"> </span>gettimeofday(&timeNow, NULL);<br>
RTPSink* sink = (RTPSink*)clientData;<br></b></div>
<div><b><span style="white-space:pre-wrap"> </span>int s1=timeNow.tv_sec;</b></div><div><b><span style="white-space:pre-wrap"> </span>printf("value of s1 %d\n",s1);</b></div><div><b><span style="white-space:pre-wrap"> </span>int o1=<span style="white-space:pre-wrap"> </span>videoSink->octetCount();</b></div>
<div><b><span style="white-space:pre-wrap"> </span>printf("value of o1 %d\n",o1);</b></div><div><b><span style="white-space:pre-wrap"> </span>int s2=timeNow.tv_sec;</b></div><div><b><span style="white-space:pre-wrap"> </span>printf("value of s2 %d\n",s2);</b></div>
<div><b><span style="white-space:pre-wrap"> </span><br></b></div><div><b><span style="white-space:pre-wrap"> </span>int o2=<span style="white-space:pre-wrap"> </span>videoSink->octetCount();</b></div>
<div><b><span style="white-space:pre-wrap"> </span>printf("value of o2 %d\n",o2);</b></div><div><b><span style="white-space:pre-wrap"> </span>double mbits_sent = (o2 - o1) / 1024.0 / 1024.0 / (s2 - s1);</b></div>
<div><b><span style="white-space:pre-wrap"> </span>printf("mbits_sent is %ld\n",mbits_sent);</b></div><div><b><span style="white-space:pre-wrap"> </span>env->taskScheduler().</b><b>scheduleDelayedTask(</b><b>uSecsToDelay, (TaskFunc*)</b><b>periodicQOSMeasurement1,</b><b>clientData);</b></div>
<div><b><span style="white-space:pre-wrap"> </span><br></b></div><div><b><br></b></div><div><b><br></b></div><div><b><br></b></div><div><b><br></b></div><div><b>}</b></div><div><b>void a(RTPSink* sink)</b></div>
<div><b>{</b></div><div><b><span style="white-space:pre-wrap"> </span>//periodicQOSMeasurement1((</b><b>void*)NULL);</b></div><div><b><span style="white-space:pre-wrap"> </span>periodicQOSMeasurement1(sink);</b></div>
<div><b>}</b></div><div><br></div>
</div><br>