Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Visual-Studio VC VC++
Hello Sir
i asked live media people the following ques:-
Is there any way in testMPEG2TransportStreamer.cpp to know the frame
> rate of the file it is streaming????
 
Try subclassing MPEG2TransportStreamFramer, and keeping track when its
getNextFrame() method is called. Between that and gettimeofday(), you
should be able to calculate this
 

i implemented this as follows:-
// "liveMedia"
// Copyright (c) 1996-2012 Live Networks, Inc.  All rights reserved.
// Framed Sources
// Implementation

#include "FramedSource.hh"
#include <stdlib.h>
#include "GroupsockHelper.hh"
#include<math.h>

////////// FramedSource //////////
static int Framek=0;
double t1,t2,T;
float F;
struct timeval timeNow;
 
FramedSource::FramedSource(UsageEnvironment& env)
  : MediaSource(env),
    fAfterGettingFunc(NULL), fAfterGettingClientData(NULL),
    fOnCloseFunc(NULL), fOnCloseClientData(NULL),
    fIsCurrentlyAwaitingData(False) {
  fPresentationTime.tv_sec = fPresentationTime.tv_usec = 0; // initially
}
 
FramedSource::~FramedSource() {
}
 
Boolean FramedSource::isFramedSource() const {
  return True;
}
 
Boolean FramedSource::lookupByName(UsageEnvironment& env, char const* sourceName,
				   FramedSource*& resultSource) {
  resultSource = NULL; // unless we succeed

  MediaSource* source;
  if (!MediaSource::lookupByName(env, sourceName, source)) return False;
 
  if (!source->isFramedSource()) {
    env.setResultMsg(sourceName, " is not a framed source");
    return False;
  }
 
  resultSource = (FramedSource*)source;
  return True;
}
 
void FramedSource::getNextFrame(unsigned char* to, unsigned maxSize,
				afterGettingFunc* afterGettingFunc,
				void* afterGettingClientData,
				onCloseFunc* onCloseFunc,
				void* onCloseClientData) {
 
					if(Framek == 0)
					{
						gettimeofday(&timeNow, NULL);
						t1=timeNow.tv_sec+(timeNow.tv_usec/1000000.0);
						printf("value of t1 is %.6lf\t Framek %d \n",t1,Framek);
						Framek++;
					}
					else
					{
							if(Framek == 1)
							{
									gettimeofday(&timeNow, NULL);
									t2=timeNow.tv_sec+(timeNow.tv_usec/1000000.0);
									printf("value of t2 is %.6lf Framek = %d\n",t2,Framek);
									Framek++;
							}
							else
							{
								Framek =0;
								T=t2-t1;
								printf("\nFramek = %d\t t1= %.6lf\t t2= %.6lf\t T = %.6lf\t\n",Framek,t1,t2,T);
								F=(float)(1/T);
								printf("Framerate is %f\n",F);
							}
					}
  // Make sure we're not already being read:
  if (fIsCurrentlyAwaitingData) {
    envir() << "FramedSource[" << this << "]::getNextFrame(): attempting to read more than once at the same time!\n";
    envir().internalError();
  }
 
  fTo = to;
  fMaxSize = maxSize;
  fNumTruncatedBytes = 0; // by default; could be changed by doGetNextFrame()
  fDurationInMicroseconds = 0; // by default; could be changed by doGetNextFrame()
  fAfterGettingFunc = afterGettingFunc;
  fAfterGettingClientData = afterGettingClientData;
  fOnCloseFunc = onCloseFunc;
  fOnCloseClientData = onCloseClientData;
  fIsCurrentlyAwaitingData = True;
 
  doGetNextFrame();
}
 
void FramedSource::afterGetting(FramedSource* source) {
  source->fIsCurrentlyAwaitingData = False;
      // indicates that we can be read again
      // Note that this needs to be done here, in case the "fAfterFunc"
      // called below tries to read another frame (which it usually will)

  if (source->fAfterGettingFunc != NULL) {
    (*(source->fAfterGettingFunc))(source->fAfterGettingClientData,
				   source->fFrameSize, source->fNumTruncatedBytes,
				   source->fPresentationTime,
				   source->fDurationInMicroseconds);
  }
}
 
void FramedSource::handleClosure(void* clientData) {
  FramedSource* source = (FramedSource*)clientData;
  source->fIsCurrentlyAwaitingData = False; // because we got a close instead
  if (source->fOnCloseFunc != NULL) {
    (*(source->fOnCloseFunc))(source->fOnCloseClientData);
  }
}
 
void FramedSource::stopGettingFrames() {
  fIsCurrentlyAwaitingData = False; // indicates that we can be read again

  // Perform any specialized action now:
  doStopGettingFrames();
}
 
void FramedSource::doStopGettingFrames() {
  // Default implementation: Do nothing
  // Subclasses may wish to specialize this so as to ensure that a
  // subsequent reader can pick up where this one left off.
}
 
unsigned FramedSource::maxFrameSize() const {
  // By default, this source has no maximum frame size.
  return 0;
}
 

 
If anyone knows the problem solution do mail me on **@***.***
Posted 18-Jul-12 4:44am
Tarun22560
Edited 18-Jul-12 5:03am
v2
Comments
Wes Aday at 18-Jul-12 10:05am
   
A solution to what? You were already told the solution by the "live media people" were you not?
Tarun22 at 18-Jul-12 11:03am
   
i am not getting the frame correctly,i am getting a frame rate nearly 2217.252,how can it be possible

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Perhaps you have a calculation issue... It could be 22.17252 Frames Per Second Average.
 
You have to read the documentation... many of the calculations divide by things such as 10000000 or 100000000 to get the actual frame rate, etc.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,192
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 24 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100