MPEG2TransportStreamFramer

MPEG2TransportStreamFramer

本文介绍了实时媒体流的帧率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好先生
我问现场媒体人以下问题:-
testMPEG2TransportStreamer.cpp中有什么方法可以知道帧
>正在流式传输的文件的速率???

尝试对MPEG2TransportStreamFramer进行子类化,并跟踪其
调用getNextFrame()方法.在那和gettimeofday()之间,您
应该能够计算出这个


我将其实现如下:-

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 **@***.***

推荐答案


这篇关于实时媒体流的帧率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 19:43