From 8736d254cc33bc293646bb93a9cdf5e6e89da1cd Mon Sep 17 00:00:00 2001 From: Randell Jesup Date: Mon, 4 May 2015 14:51:24 -0400 Subject: [PATCH] Bug 1161079: Fix VideoCodecStats to allow for collecting encoder and decoder stats r=jib --- .../src/media-conduit/CodecStatistics.cpp | 27 ++++++++++++------- .../src/media-conduit/CodecStatistics.h | 6 +++-- .../src/media-conduit/VideoConduit.cpp | 6 +++-- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/media/webrtc/signaling/src/media-conduit/CodecStatistics.cpp b/media/webrtc/signaling/src/media-conduit/CodecStatistics.cpp index f13dc7efad31..876e333db244 100644 --- a/media/webrtc/signaling/src/media-conduit/CodecStatistics.cpp +++ b/media/webrtc/signaling/src/media-conduit/CodecStatistics.cpp @@ -16,14 +16,14 @@ using namespace webrtc; static const char* logTag ="WebrtcVideoSessionConduit"; VideoCodecStatistics::VideoCodecStatistics(int channel, - ViECodec* codec, - bool encoder) : + ViECodec* codec) : mChannel(channel), mSentRawFrames(0), mPtrViECodec(codec), mEncoderDroppedFrames(0), mDecoderDiscardedPackets(0), - mEncoderMode(encoder), + mRegisteredEncode(false), + mRegisteredDecode(false), mReceiveState(kReceiveStateInitial) #ifdef MOZILLA_INTERNAL_API , mRecoveredBeforeLoss(0) @@ -31,22 +31,29 @@ VideoCodecStatistics::VideoCodecStatistics(int channel, #endif { MOZ_ASSERT(mPtrViECodec); - if (mEncoderMode) { - mPtrViECodec->RegisterEncoderObserver(mChannel, *this); - } else { - mPtrViECodec->RegisterDecoderObserver(mChannel, *this); - } } VideoCodecStatistics::~VideoCodecStatistics() { - if (mEncoderMode) { + if (mRegisteredEncode) { mPtrViECodec->DeregisterEncoderObserver(mChannel); - } else { + } + if (mRegisteredDecode) { mPtrViECodec->DeregisterDecoderObserver(mChannel); } } +void VideoCodecStatistics::Register(bool encoder) +{ + if (encoder && !mRegisteredEncode) { + mPtrViECodec->RegisterEncoderObserver(mChannel, *this); + mRegisteredEncode = true; + } else if (!encoder && !mRegisteredDecode) { + mPtrViECodec->RegisterDecoderObserver(mChannel, *this); + mRegisteredDecode = true; + } +} + void VideoCodecStatistics::OutgoingRate(const int video_channel, const uint32_t framerate, const uint32_t bitrate) diff --git a/media/webrtc/signaling/src/media-conduit/CodecStatistics.h b/media/webrtc/signaling/src/media-conduit/CodecStatistics.h index 6f61c31709de..ab81a6f33424 100644 --- a/media/webrtc/signaling/src/media-conduit/CodecStatistics.h +++ b/media/webrtc/signaling/src/media-conduit/CodecStatistics.h @@ -21,8 +21,9 @@ class VideoCodecStatistics : public webrtc::ViEEncoderObserver , public webrtc::ViEDecoderObserver { public: - VideoCodecStatistics(int channel, webrtc::ViECodec* vieCodec, bool encoder); + VideoCodecStatistics(int channel, webrtc::ViECodec* vieCodec); ~VideoCodecStatistics(); + void Register(bool encoder); void SentFrame(); virtual void OutgoingRate(const int video_channel, @@ -92,7 +93,8 @@ private: RunningStat mDecoderBitRate; RunningStat mDecoderFps; uint32_t mDecoderDiscardedPackets; - const bool mEncoderMode; + bool mRegisteredEncode; + bool mRegisteredDecode; webrtc::VideoReceiveState mReceiveState; #ifdef MOZILLA_INTERNAL_API diff --git a/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp b/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp index 5dca63382a15..c534f14c850e 100755 --- a/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp +++ b/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp @@ -644,8 +644,9 @@ WebrtcVideoConduit::ConfigureSendMediaCodec(const VideoCodecConfig* codecConfig) } if (!mVideoCodecStat) { - mVideoCodecStat = new VideoCodecStatistics(mChannel, mPtrViECodec, true); + mVideoCodecStat = new VideoCodecStatistics(mChannel, mPtrViECodec); } + mVideoCodecStat->Register(true); mSendingWidth = 0; mSendingHeight = 0; @@ -800,8 +801,9 @@ WebrtcVideoConduit::ConfigureRecvMediaCodecs( } if (!mVideoCodecStat) { - mVideoCodecStat = new VideoCodecStatistics(mChannel, mPtrViECodec, false); + mVideoCodecStat = new VideoCodecStatistics(mChannel, mPtrViECodec); } + mVideoCodecStat->Register(false); // XXX Currently, we gather up all of the feedback types that the remote // party indicated it supports for all video codecs and configure the entire