ratectl.h
Go to the documentation of this file.
/*
* ratectl.h
*
* Video rate controller
*
* Open Phone Abstraction Library (OPAL)
*
* Copyright (C) 2007 Matthias Schneider
* Copyright (C) 2008 Post Increment
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Open Phone Abstraction Library.
*
* The Initial Developer of the Original Code is Matthias Schneider
*
* Contributor(s): Post Increment
*
* $Revision: 22839 $
* $Author: rjongbloed $
* $Date: 2009-06-10 20:37:03 -0500 (Wed, 10 Jun 2009) $
*/
#ifndef OPAL_RATE_CONTROL_H
#define OPAL_RATE_CONTROL_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
#include <opal/buildopts.h>
#if OPAL_VIDEO
#include <rtp/rtp.h>
extern double OpalCalcSNR(const BYTE * src1, const BYTE * src2, PINDEX dataLen);
class OpalBitRateCalculator
{
public:
OpalBitRateCalculator();
void Reset();
void SetQuanta(
unsigned quanta_
);
unsigned GetQuanta() const
{ return m_quanta; }
void AddPacket(PINDEX size, bool marker);
unsigned GetBitRate();
unsigned GetAverageBitRate();
unsigned GetAveragePacketSize();
unsigned GetTrialBitRate(PINDEX size);
PInt64 GetTotalSize() const;
PInt64 GetTotalTime() const;
size_t GetHistoryCount() const
{ return m_history.size(); }
unsigned GetHistorySize() const
{ return m_historySize; }
PInt64 GetEarliestHistoryTime() const
{ if (m_history.size() == 0) return 0; return m_history.begin()->m_timeStamp; }
unsigned GetHistoryFrames() const;
// flush old data from history
void Flush();
// used to get "now"
static PInt64 GetNow();
protected:
void Flush(PInt64 now);
struct History {
History(PINDEX size_, PInt64 timeStamp_, bool marker_)
: m_size(size_), m_timeStamp(timeStamp_), m_marker(marker_)
{ }
PINDEX m_size;
PInt64 m_timeStamp;
bool m_marker;
};
std::deque<History> m_history;
PINDEX m_historySize;
PInt64 m_totalSize;
PINDEX m_historyFrames;
unsigned m_quanta;
unsigned m_bitRate;
bool m_first;
PInt64 m_baseTimeStamp;
};
//
// Declare a generic video rate controller class.
// A rate controller seeks to maintain a constant bit rate by manipulating
// the parameters of the video stream
//
// Before encoding a potential output frame, use the SkipFrame function to determine if the
// frame should be skipped.
//
// If the frame is not skipped, encode the frame and call PushFrame to add the frame to the rate controller queue
// PopFrame can then be called to retreive frames to transmit
//
// PushFrame must always be called with packets from a single video frame, but PopFrame may return packets
// from multiple video frames
//
class OpalMediaFormat;
class OpalVideoRateController
{
public:
OpalVideoRateController();
virtual ~OpalVideoRateController();
virtual void Open(
const OpalMediaFormat & mediaFormat
);
virtual bool SkipFrame(
bool & forceIFrame
) = 0;
virtual void Push(
RTP_DataFrameList & inputFrames,
bool iFrame
);
virtual bool Pop(
RTP_DataFrameList & outputPackets,
bool & iFrame,
bool force
);
OpalBitRateCalculator m_bitRateCalc;
protected:
unsigned m_targetBitRate;
unsigned m_outputFrameTime;
PInt64 m_inputFrameCount;
PInt64 m_outputFrameCount;
struct PacketEntry {
PacketEntry(RTP_DataFrame * rtp_, bool iFrame_)
: m_rtp(rtp_), m_iFrame(iFrame_)
{ }
RTP_DataFrame * m_rtp;
bool m_iFrame;
};
std::deque<PacketEntry> m_packets;
};
namespace PWLibStupidLinkerHacks {
extern int rateControlKickerVal;
// static class RateControlKicker { public: RateControlKicker() { rateControlKickerVal = 1; } } rateControlKicker;
};
#endif // OPAL_VIDEO
#endif // OPAL_RATE_CONTROL_H
OpalBitRateCalculator::m_history
std::deque< History > m_history
Definition: ratectl.h:140
PWLibStupidLinkerHacks::rateControlKickerVal
int rateControlKickerVal
OpalBitRateCalculator::GetTrialBitRate
unsigned GetTrialBitRate(PINDEX size)
OpalBitRateCalculator::GetTotalSize
PInt64 GetTotalSize() const
buildopts.h
OpalBitRateCalculator::History::m_size
PINDEX m_size
Definition: ratectl.h:135
OpalVideoRateController::m_packets
std::deque< PacketEntry > m_packets
Definition: ratectl.h:223
OpalVideoRateController::m_outputFrameTime
unsigned m_outputFrameTime
Definition: ratectl.h:211
OpalCalcSNR
double OpalCalcSNR(const BYTE *src1, const BYTE *src2, PINDEX dataLen)
PWLibStupidLinkerHacks
Definition: ratectl.h:226
OpalVideoRateController::OpalVideoRateController
OpalVideoRateController()
OpalVideoRateController::Open
virtual void Open(const OpalMediaFormat &mediaFormat)
OpalBitRateCalculator
Definition: ratectl.h:51
OpalBitRateCalculator::AddPacket
void AddPacket(PINDEX size, bool marker)
OpalBitRateCalculator::m_totalSize
PInt64 m_totalSize
Definition: ratectl.h:143
OpalVideoRateController::PacketEntry::m_rtp
RTP_DataFrame * m_rtp
Definition: ratectl.h:220
OpalVideoRateController::m_bitRateCalc
OpalBitRateCalculator m_bitRateCalc
Definition: ratectl.h:207
OpalBitRateCalculator::History::History
History(PINDEX size_, PInt64 timeStamp_, bool marker_)
Definition: ratectl.h:131
RTP_DataFrame
Definition: rtp.h:71
OpalBitRateCalculator::m_historySize
PINDEX m_historySize
Definition: ratectl.h:142
OpalMediaFormat
Definition: mediafmt.h:724
OpalBitRateCalculator::m_first
bool m_first
Definition: ratectl.h:148
OpalBitRateCalculator::GetNow
static PInt64 GetNow()
OpalVideoRateController::Push
virtual void Push(RTP_DataFrameList &inputFrames, bool iFrame)
OpalBitRateCalculator::SetQuanta
void SetQuanta(unsigned quanta_)
OpalVideoRateController::m_outputFrameCount
PInt64 m_outputFrameCount
Definition: ratectl.h:213
OpalBitRateCalculator::History
Definition: ratectl.h:130
OpalBitRateCalculator::History::m_timeStamp
PInt64 m_timeStamp
Definition: ratectl.h:136
OpalBitRateCalculator::GetAveragePacketSize
unsigned GetAveragePacketSize()
OpalVideoRateController::m_targetBitRate
unsigned m_targetBitRate
Definition: ratectl.h:210
OpalBitRateCalculator::GetAverageBitRate
unsigned GetAverageBitRate()
OpalBitRateCalculator::GetQuanta
unsigned GetQuanta() const
Definition: ratectl.h:70
OpalBitRateCalculator::Flush
void Flush()
OpalVideoRateController::~OpalVideoRateController
virtual ~OpalVideoRateController()
OpalBitRateCalculator::m_historyFrames
PINDEX m_historyFrames
Definition: ratectl.h:144
OpalBitRateCalculator::GetBitRate
unsigned GetBitRate()
OpalBitRateCalculator::GetHistoryFrames
unsigned GetHistoryFrames() const
OpalVideoRateController::Pop
virtual bool Pop(RTP_DataFrameList &outputPackets, bool &iFrame, bool force)
OpalBitRateCalculator::Reset
void Reset()
OpalBitRateCalculator::GetHistoryCount
size_t GetHistoryCount() const
Definition: ratectl.h:103
OpalVideoRateController::PacketEntry::PacketEntry
PacketEntry(RTP_DataFrame *rtp_, bool iFrame_)
Definition: ratectl.h:216
OpalBitRateCalculator::GetEarliestHistoryTime
PInt64 GetEarliestHistoryTime() const
Definition: ratectl.h:113
OpalBitRateCalculator::OpalBitRateCalculator
OpalBitRateCalculator()
OpalBitRateCalculator::GetTotalTime
PInt64 GetTotalTime() const
rtp.h
OpalVideoRateController::m_inputFrameCount
PInt64 m_inputFrameCount
Definition: ratectl.h:212
OpalBitRateCalculator::m_quanta
unsigned m_quanta
Definition: ratectl.h:146
OpalBitRateCalculator::m_baseTimeStamp
PInt64 m_baseTimeStamp
Definition: ratectl.h:149
OpalVideoRateController::PacketEntry::m_iFrame
bool m_iFrame
Definition: ratectl.h:221
OpalVideoRateController::SkipFrame
virtual bool SkipFrame(bool &forceIFrame)=0
OpalBitRateCalculator::m_bitRate
unsigned m_bitRate
Definition: ratectl.h:147
OpalBitRateCalculator::GetHistorySize
unsigned GetHistorySize() const
Definition: ratectl.h:108
OpalVideoRateController::PacketEntry
Definition: ratectl.h:215
OpalVideoRateController
Definition: ratectl.h:169
OpalBitRateCalculator::History::m_marker
bool m_marker
Definition: ratectl.h:137