Add API to get the number of packets discarded by the video jitter buffer due to being too late.

BUG=
TEST=

Review URL: http://webrtc-codereview.appspot.com/200001

git-svn-id: http://webrtc.googlecode.com/svn/trunk@723 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
stefan@webrtc.org 2011-10-11 07:53:43 +00:00
parent 06887aebae
commit 791eec7424
13 changed files with 506 additions and 205 deletions

View File

@ -490,6 +490,12 @@ public:
// Return value : VCM_OK, on success.
// <0, on error.
virtual WebRtc_Word32 ReceivedFrameCount(VCMFrameCount& frameCount) const = 0;
// Returns the number of packets discarded by the jitter buffer due to being
// too late. This can include duplicated packets which arrived after the
// frame was sent to the decoder. Therefore packets which were prematurely
// NACKed will be counted.
virtual WebRtc_UWord32 DiscardedPackets() const = 0;
};
} // namespace webrtc

View File

@ -81,6 +81,7 @@ VCMJitterBuffer::VCMJitterBuffer(WebRtc_Word32 vcmId, WebRtc_Word32 receiverId,
_dropCount(0),
_numConsecutiveOldFrames(0),
_numConsecutiveOldPackets(0),
_discardedPackets(0),
_jitterEstimate(vcmId, receiverId),
_rttMs(0),
_nackMode(kNoNack),
@ -134,6 +135,7 @@ VCMJitterBuffer::operator=(const VCMJitterBuffer& rhs)
_dropCount = rhs._dropCount;
_numConsecutiveOldFrames = rhs._numConsecutiveOldFrames;
_numConsecutiveOldPackets = rhs._numConsecutiveOldPackets;
_discardedPackets = rhs._discardedPackets;
_jitterEstimate = rhs._jitterEstimate;
_delayEstimate = rhs._delayEstimate;
_waitingForCompletion = rhs._waitingForCompletion;
@ -210,6 +212,7 @@ VCMJitterBuffer::Start()
_numConsecutiveOldFrames = 0;
_numConsecutiveOldPackets = 0;
_discardedPackets = 0;
_frameEvent.Reset(); // start in a non-signaled state
_packetEvent.Reset(); // start in a non-signaled state
@ -438,6 +441,11 @@ VCMJitterBuffer::GetFrameStatistics(WebRtc_UWord32& receivedDeltaFrames,
return 0;
}
WebRtc_UWord32 VCMJitterBuffer::DiscardedPackets() const {
CriticalSectionScoped cs(_critSect);
return _discardedPackets;
}
// Gets frame to use for this timestamp. If no match, get empty frame.
WebRtc_Word32
VCMJitterBuffer::GetFrame(const VCMPacket& packet, VCMEncodedFrame*& frame)
@ -448,11 +456,12 @@ VCMJitterBuffer::GetFrame(const VCMPacket& packet, VCMEncodedFrame*& frame)
}
_critSect.Enter();
// Make sure that old empty packets are inserted.
if (LatestTimestamp(static_cast<WebRtc_UWord32>(_lastDecodedTimeStamp),
packet.timestamp) == _lastDecodedTimeStamp
&& packet.sizeBytes > 0)
// Make sure that old Empty packets are inserted.
{
_discardedPackets++; // Only counts discarded media packets
// Trying to get an old frame.
_numConsecutiveOldPackets++;
if (_numConsecutiveOldPackets > kMaxConsecutiveOldPackets)

View File

@ -68,6 +68,9 @@ public:
WebRtc_Word32 GetFrameStatistics(WebRtc_UWord32& receivedDeltaFrames,
WebRtc_UWord32& receivedKeyFrames) const;
// Get number of packets discarded by the jitter buffer
WebRtc_UWord32 DiscardedPackets() const;
// Statistics, Calculate frame and bit rates
WebRtc_Word32 GetUpdate(WebRtc_UWord32& frameRate, WebRtc_UWord32& bitRate);
@ -223,6 +226,9 @@ private:
WebRtc_UWord32 _numConsecutiveOldFrames;
// Number of packets in a row that have been too old
WebRtc_UWord32 _numConsecutiveOldPackets;
// Number of packets discarded by the jitter buffer
WebRtc_UWord32 _discardedPackets;
// Filters for estimating jitter
VCMJitterEstimator _jitterEstimate;
// Calculates network delays used for jitter calculations

View File

@ -344,6 +344,10 @@ VCMReceiver::ReceivedFrameCount(VCMFrameCount& frameCount) const
frameCount.numKeyFrames);
}
WebRtc_UWord32 VCMReceiver::DiscardedPackets() const {
return _jitterBuffer.DiscardedPackets();
}
void
VCMReceiver::SetNackMode(VCMNackMode nackMode)
{

View File

@ -57,6 +57,7 @@ public:
void ReleaseFrame(VCMEncodedFrame* frame);
WebRtc_Word32 ReceiveStatistics(WebRtc_UWord32& bitRate, WebRtc_UWord32& frameRate);
WebRtc_Word32 ReceivedFrameCount(VCMFrameCount& frameCount) const;
WebRtc_UWord32 DiscardedPackets() const;
// NACK
void SetNackMode(VCMNackMode nackMode);

File diff suppressed because it is too large Load Diff

View File

@ -43,9 +43,11 @@ private:
enum VCMKeyRequestMode
{
kKeyOnError, // Normal mode, request key frames on decoder error
kKeyOnKeyLoss, // Request key frames on decoder error and on packet loss in key frames
kKeyOnLoss, // Request key frames on decoder error and on packet loss in any frame
kKeyOnError, // Normal mode, request key frames on decoder error
kKeyOnKeyLoss, // Request key frames on decoder error and on packet loss
// in key frames.
kKeyOnLoss, // Request key frames on decoder error and on packet loss
// in any frame
};
class VideoCodingModuleImpl : public VideoCodingModule
@ -65,7 +67,8 @@ public:
// Change the unique identifier of this object
virtual WebRtc_Word32 ChangeUniqueId(const WebRtc_Word32 id);
// Returns the number of milliseconds until the module want a worker thread to call Process
// Returns the number of milliseconds until the module want a worker thread
// to call Process
virtual WebRtc_Word32 TimeUntilNextProcess();
virtual WebRtc_Word32 Process();
@ -97,7 +100,8 @@ public:
bool internalSource = false);
// Get codec config parameters
virtual WebRtc_Word32 CodecConfigParameters(WebRtc_UWord8* buffer, WebRtc_Word32 size);
virtual WebRtc_Word32 CodecConfigParameters(WebRtc_UWord8* buffer,
WebRtc_Word32 size);
// Get encode bitrate
virtual WebRtc_UWord32 Bitrate() const;
@ -106,30 +110,38 @@ public:
virtual WebRtc_UWord32 FrameRate() const;
// Set channel parameters
virtual WebRtc_Word32 SetChannelParameters(WebRtc_UWord32 availableBandWidth,
WebRtc_UWord8 lossRate,
WebRtc_UWord32 RTT);
virtual WebRtc_Word32 SetChannelParameters(
WebRtc_UWord32 availableBandWidth,
WebRtc_UWord8 lossRate,
WebRtc_UWord32 RTT);
// Set recieve channel parameters
virtual WebRtc_Word32 SetReceiveChannelParameters(WebRtc_UWord32 RTT);
// Register a transport callback which will be called to deliver the encoded buffers
virtual WebRtc_Word32 RegisterTransportCallback(VCMPacketizationCallback* transport);
// Register a transport callback which will be called to deliver the
// encoded buffers
virtual WebRtc_Word32 RegisterTransportCallback(
VCMPacketizationCallback* transport);
// Register a send statistics callback which will be called to deliver information
// about the video stream produced by the encoder,
// Register a send statistics callback which will be called to deliver
// information about the video stream produced by the encoder,
// for instance the average frame rate and bit rate.
virtual WebRtc_Word32 RegisterSendStatisticsCallback(VCMSendStatisticsCallback* sendStats);
virtual WebRtc_Word32 RegisterSendStatisticsCallback(
VCMSendStatisticsCallback* sendStats);
// Register a video quality settings callback which will be called when
// frame rate/dimensions need to be updated for video quality optimization
virtual WebRtc_Word32 RegisterVideoQMCallback(VCMQMSettingsCallback* videoQMSettings);
virtual WebRtc_Word32 RegisterVideoQMCallback(
VCMQMSettingsCallback* videoQMSettings);
// Register a video protection callback which will be called to deliver
// the requested FEC rate and NACK status (on/off).
virtual WebRtc_Word32 RegisterProtectionCallback(VCMProtectionCallback* protection);
virtual WebRtc_Word32 RegisterProtectionCallback(
VCMProtectionCallback* protection);
// Enable or disable a video protection method.
virtual WebRtc_Word32 SetVideoProtection(VCMVideoProtection videoProtection, bool enable);
virtual WebRtc_Word32 SetVideoProtection(VCMVideoProtection videoProtection,
bool enable);
// Add one raw video frame to the encoder, blocking.
virtual WebRtc_Word32 AddVideoFrame(
@ -164,31 +176,35 @@ public:
WebRtc_UWord8 payloadType,
bool internalRenderTiming);
// Register a receive callback. Will be called whenever there are a new frame ready
// for rendering.
virtual WebRtc_Word32 RegisterReceiveCallback(VCMReceiveCallback* receiveCallback);
// Register a receive callback. Will be called whenever there are a new
// frame ready for rendering.
virtual WebRtc_Word32 RegisterReceiveCallback(
VCMReceiveCallback* receiveCallback);
// Register a receive statistics callback which will be called to deliver information
// about the video stream received by the receiving side of the VCM, for instance
// the average frame rate and bit rate.
// Register a receive statistics callback which will be called to deliver
// information about the video stream received by the receiving side of the
// VCM, for instance the average frame rate and bit rate.
virtual WebRtc_Word32 RegisterReceiveStatisticsCallback(
VCMReceiveStatisticsCallback* receiveStats);
VCMReceiveStatisticsCallback* receiveStats);
// Register a frame type request callback.
virtual WebRtc_Word32 RegisterFrameTypeCallback(VCMFrameTypeCallback* frameTypeCallback);
virtual WebRtc_Word32 RegisterFrameTypeCallback(
VCMFrameTypeCallback* frameTypeCallback);
// Register a frame storage callback.
virtual WebRtc_Word32 RegisterFrameStorageCallback(
VCMFrameStorageCallback* frameStorageCallback);
VCMFrameStorageCallback* frameStorageCallback);
// Nack callback
virtual WebRtc_Word32 RegisterPacketRequestCallback(VCMPacketRequestCallback* callback);
virtual WebRtc_Word32 RegisterPacketRequestCallback(
VCMPacketRequestCallback* callback);
// Decode next frame, blocks for a maximum of maxWaitTimeMs milliseconds.
// Should be called as often as possible to get the most out of the decoder.
virtual WebRtc_Word32 Decode(WebRtc_UWord16 maxWaitTimeMs = 200);
// Decode next dual frame, blocks for a maximum of maxWaitTimeMs milliseconds.
// Decode next dual frame, blocks for a maximum of maxWaitTimeMs
// milliseconds.
virtual WebRtc_Word32 DecodeDualFrame(WebRtc_UWord16 maxWaitTimeMs = 200);
// Reset the decoder state
@ -207,17 +223,19 @@ public:
// A part of an encoded frame to be decoded.
// Used in conjunction with VCMFrameStorageCallback.
virtual WebRtc_Word32 DecodeFromStorage(const EncodedVideoData& frameFromStorage);
virtual WebRtc_Word32 DecodeFromStorage(
const EncodedVideoData& frameFromStorage);
// Set codec config parameters
virtual WebRtc_Word32 SetCodecConfigParameters(WebRtc_UWord8 payloadType,
const WebRtc_UWord8* buffer,
WebRtc_Word32 length);
// Minimum playout delay (Used for lip-sync). This is the minimum delay required
// to sync with audio. Not included in VideoCodingModule::Delay()
// Minimum playout delay (Used for lip-sync). This is the minimum delay
// required to sync with audio. Not included in VideoCodingModule::Delay()
// Defaults to 0 ms.
virtual WebRtc_Word32 SetMinimumPlayoutDelay(WebRtc_UWord32 minPlayoutDelayMs);
virtual WebRtc_Word32 SetMinimumPlayoutDelay(
WebRtc_UWord32 minPlayoutDelayMs);
// The estimated delay caused by rendering
virtual WebRtc_Word32 SetRenderDelay(WebRtc_UWord32 timeMS);
@ -228,15 +246,19 @@ public:
// Received frame counters
virtual WebRtc_Word32 ReceivedFrameCount(VCMFrameCount& frameCount) const;
// Returns the number of packets discarded by the jitter buffer.
virtual WebRtc_UWord32 DiscardedPackets() const;
protected:
WebRtc_Word32 Decode(const webrtc::VCMEncodedFrame& frame);
WebRtc_Word32 RequestKeyFrame();
WebRtc_Word32 RequestSliceLossIndication(const WebRtc_UWord64 pictureID) const;
WebRtc_Word32 RequestSliceLossIndication(
const WebRtc_UWord64 pictureID) const;
WebRtc_Word32 NackList(WebRtc_UWord16* nackList, WebRtc_UWord16& size);
private:
WebRtc_Word32 _id;
CriticalSectionWrapper& _receiveCritSect; // Critical section for receive side
CriticalSectionWrapper& _receiveCritSect;
bool _receiverInited;
VCMTiming _timing;
VCMTiming _dualTiming;
@ -255,7 +277,7 @@ private:
VCMKeyRequestMode _keyRequestMode;
bool _scheduleKeyRequest;
CriticalSectionWrapper& _sendCritSect; // Critical section for send side
CriticalSectionWrapper& _sendCritSect;
VCMGenericEncoder* _encoder;
VCMEncodedFrameCallback _encodedFrameCallback;
FrameType _nextFrameType;

View File

@ -800,11 +800,6 @@ int JitterBufferTest(CmdArgs& args)
packet.insertStartCode = false;
//printf("DONE H.264 insert start code test 2 packets\n");
// Temporarily do this to make the rest of the test work:
timeStamp += 33*90;
seqNum += 4;
//
// TEST statistics
//
@ -823,8 +818,35 @@ int JitterBufferTest(CmdArgs& args)
TEST(frameRate > 30);
TEST(bitRate > 10000000);
// Insert 3 old packets and verify that we have 3 discarded packets
packet.timestamp = timeStamp - 1000;
frameIn = jb.GetFrame(packet);
TEST(frameIn == NULL);
packet.timestamp = timeStamp - 500;
frameIn = jb.GetFrame(packet);
TEST(frameIn == NULL);
packet.timestamp = timeStamp - 100;
frameIn = jb.GetFrame(packet);
TEST(frameIn == NULL);
TEST(jb.DiscardedPackets() == 3);
jb.Flush();
// This statistic shouldn't be reset by a flush.
TEST(jb.DiscardedPackets() == 3);
//printf("DONE Statistics\n");
// Temporarily do this to make the rest of the test work:
timeStamp += 33*90;
seqNum += 4;
//
// TEST delta frame 100 packets with seqNum wrap
//
@ -833,7 +855,6 @@ int JitterBufferTest(CmdArgs& args)
// ---------------------------------------
//
// test flush
jb.Flush();
// insert first packet

View File

@ -140,6 +140,10 @@ public:
unsigned int& keyFrames,
unsigned int& deltaFrames) const = 0;
// Gets the number of packets discarded by the jitter buffer because they
// arrived too late.
virtual unsigned int GetDiscardedPackets(const int videoChannel) const = 0;
// Enables key frame request callback in ViEDecoderObserver.
virtual int SetKeyFrameRequestCallbackStatus(const int videoChannel,
const bool enable) = 0;

View File

@ -515,6 +515,14 @@ WebRtc_Word32 ViEChannel::ReceiveCodecStatistics(WebRtc_UWord32& numKeyFrames,
return 0;
}
WebRtc_UWord32 ViEChannel::DiscardedPackets() const {
WEBRTC_TRACE(webrtc::kTraceInfo,
webrtc::kTraceVideo,
ViEId(_engineId, _channelId),
"%s", __FUNCTION__);
return _vcm.DiscardedPackets();
}
// ----------------------------------------------------------------------------
// WaitForKeyFrame
//

View File

@ -95,6 +95,8 @@ public:
WebRtc_Word32 ReceiveCodecStatistics(WebRtc_UWord32& numKeyFrames,
WebRtc_UWord32& numDeltaFrames);
WebRtc_UWord32 DiscardedPackets() const;
WebRtc_Word32 WaitForKeyFrame(bool wait);
WebRtc_Word32 SetSignalPacketLossStatus(bool enable, bool onlyKeyFrames);

View File

@ -566,6 +566,25 @@ int ViECodecImpl::GetReceiveCodecStastistics(const int videoChannel,
}
unsigned int ViECodecImpl::GetDiscardedPackets(const int videoChannel) const {
WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo,
ViEId(_instanceId, videoChannel),
"%s(videoChannel: %d, codecType: %d)", __FUNCTION__,
videoChannel);
ViEChannelManagerScoped cs(_channelManager);
ViEChannel* vieChannel = cs.Channel(videoChannel);
if (vieChannel == NULL)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
ViEId(_instanceId, videoChannel), "%s: No channel %d",
__FUNCTION__, videoChannel);
SetLastError(kViECodecInvalidChannelId);
return -1;
}
return vieChannel->DiscardedPackets();
}
// Callbacks
// ----------------------------------------------------------------------------
// SetKeyFrameRequestCallbackStatus

View File

@ -72,6 +72,8 @@ public:
unsigned int& keyFrames,
unsigned int& deltaFrames) const;
virtual unsigned int GetDiscardedPackets(const int videoChannel) const;
// Callbacks
virtual int SetKeyFrameRequestCallbackStatus(const int videoChannel,
const bool enable);