Click here to Skip to main content
13,051,413 members (63,443 online)
Rate this:
Please Sign up or sign in to vote.
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"
////////// 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);
						printf("value of t1 is %.6lf\t Framek %d \n",t1,Framek);
							if(Framek == 1)
									gettimeofday(&timeNow, NULL);
									printf("value of t2 is %.6lf Framek = %d\n",t2,Framek);
								Framek =0;
								printf("\nFramek = %d\t t1= %.6lf\t t2= %.6lf\t T = %.6lf\t\n",Framek,t1,t2,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";
  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;
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->fFrameSize, source->fNumTruncatedBytes,
void FramedSource::handleClosure(void* clientData) {
  FramedSource* source = (FramedSource*)clientData;
  source->fIsCurrentlyAwaitingData = False; // because we got a close instead
  if (source->fOnCloseFunc != NULL) {
void FramedSource::stopGettingFrames() {
  fIsCurrentlyAwaitingData = False; // indicates that we can be read again
  // Perform any specialized action now:
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 3:44am
Updated 18-Jul-12 4:03am
Wes Aday 18-Jul-12 10:05am
A solution to what? You were already told the solution by the "live media people" were you not?
Tarun22 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
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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 24 Jul 2012
Copyright © CodeProject, 1999-2017
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