Bug 951496 - Statistics data for checking the status of codec. r=jesup

This commit is contained in:
Steven Lee 2014-06-04 23:56:30 -04:00
Родитель 4a0ae13401
Коммит d63ac551ec
7 изменённых файлов: 230 добавлений и 0 удалений

Просмотреть файл

@ -62,6 +62,7 @@ if CONFIG['MOZ_WEBRTC_SIGNALING']:
'signaling/src/callcontrol/CallControlManagerImpl.cpp',
'signaling/src/common/browser_logging/CSFLog.cpp',
'signaling/src/media-conduit/AudioConduit.cpp',
'signaling/src/media-conduit/CodecStatistics.cpp',
'signaling/src/media-conduit/VideoConduit.cpp',
'signaling/src/media/CSFAudioControlWrapper.cpp',
'signaling/src/media/CSFVideoControlWrapper.cpp',

Просмотреть файл

@ -84,6 +84,9 @@
'./src/media-conduit/AudioConduit.cpp',
'./src/media-conduit/VideoConduit.h',
'./src/media-conduit/VideoConduit.cpp',
'./src/media-conduit/CodecStatistics.h',
'./src/media-conduit/CodecStatistics.cpp',
'./src/media-conduit/RunningStat.h',
# Common
'./src/common/CommonTypes.h',
'./src/common/csf_common.h',

Просмотреть файл

@ -0,0 +1,87 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "CodecStatistics.h"
#include "CSFLog.h"
using namespace mozilla;
using namespace webrtc;
// use the same tag as VideoConduit
static const char* logTag ="WebrtcVideoSessionConduit";
VideoCodecStatistics::VideoCodecStatistics(int channel, ViECodec* codec) :
mChannel(channel),
mSentRawFrames(0),
mPtrViECodec(codec),
mEncoderDroppedFrames(0),
mDecoderDiscardedPackets(0)
{
MOZ_ASSERT(mPtrViECodec);
mPtrViECodec->RegisterEncoderObserver(mChannel, *this);
mPtrViECodec->RegisterDecoderObserver(mChannel, *this);
}
VideoCodecStatistics::~VideoCodecStatistics()
{
mPtrViECodec->DeregisterEncoderObserver(mChannel);
mPtrViECodec->DeregisterDecoderObserver(mChannel);
}
void VideoCodecStatistics::OutgoingRate(const int video_channel,
const uint32_t framerate,
const uint32_t bitrate)
{
unsigned int keyFrames, deltaFrames;
mPtrViECodec->GetSendCodecStatistics(video_channel, keyFrames, deltaFrames);
uint32_t dropped = mSentRawFrames - (keyFrames + deltaFrames);
CSFLogDebug(logTag,
"encoder statistics - framerate: %u, bitrate: %u, dropped frames: %u",
framerate, bitrate, dropped);
mEncoderBitRate.Push(bitrate);
mEncoderFps.Push(framerate);
mEncoderDroppedFrames += dropped;
}
void VideoCodecStatistics::IncomingCodecChanged(const int video_channel,
const VideoCodec& video_codec)
{
CSFLogDebug(logTag,
"channel %d change codec to \"%s\" ",
video_channel, video_codec.plName);
}
void VideoCodecStatistics::IncomingRate(const int video_channel,
const unsigned int framerate,
const unsigned int bitrate)
{
unsigned int discarded = mPtrViECodec->GetDiscardedPackets(video_channel);
CSFLogDebug(logTag,
"decoder statistics - framerate: %u, bitrate: %u, discarded packets %u",
framerate, bitrate, discarded);
mDecoderBitRate.Push(bitrate);
mDecoderFps.Push(framerate);
mDecoderDiscardedPackets += discarded;
}
void VideoCodecStatistics::SentFrame()
{
mSentRawFrames++;
}
void VideoCodecStatistics::Dump()
{
Dump(mEncoderBitRate, "encoder bitrate");
Dump(mEncoderFps, "encoder fps");
Dump(mDecoderBitRate, "decoder bitrate");
Dump(mDecoderFps, "decoder fps");
}
void VideoCodecStatistics::Dump(RunningStat& s, const char *name)
{
CSFLogDebug(logTag,
"%s, mean: %f, variance: %f, standard deviation: %f",
name, s.Mean(), s.Variance(), s.StandardDeviation());
}

Просмотреть файл

@ -0,0 +1,63 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef CODEC_STATISTICS_H_
#define CODEC_STATISTICS_H_
#include <math.h>
#include "nsTArray.h"
#include "nsISupportsImpl.h"
#include "webrtc/video_engine/include/vie_codec.h"
#include "MediaEngineWrapper.h"
#include "RunningStat.h"
namespace mozilla {
// Statistics-gathering observer for Video Encoder and Decoder
class VideoCodecStatistics : public webrtc::ViEEncoderObserver
, public webrtc::ViEDecoderObserver
{
public:
VideoCodecStatistics(int channel, webrtc::ViECodec* vieCodec);
~VideoCodecStatistics();
void SentFrame();
virtual void OutgoingRate(const int video_channel,
const unsigned int framerate, const unsigned int bitrate) MOZ_OVERRIDE;
virtual void IncomingCodecChanged(const int video_channel,
const webrtc::VideoCodec& video_codec) MOZ_OVERRIDE;
virtual void IncomingRate(const int video_channel,
const unsigned int framerate,
const unsigned int bitrate) MOZ_OVERRIDE;
virtual void RequestNewKeyFrame(const int video_channel) MOZ_OVERRIDE {};
virtual void SuspendChange(int video_channel, bool is_suspended) MOZ_OVERRIDE {};
virtual void DecoderTiming(int decode_ms,
int max_decode_ms,
int current_delay_ms,
int target_delay_ms,
int jitter_buffer_ms,
int min_playout_delay_ms,
int render_delay_ms) MOZ_OVERRIDE {}
void Dump();
private:
void Dump(RunningStat& s, const char *name);
int mChannel;
uint32_t mSentRawFrames;
ScopedCustomReleasePtr<webrtc::ViECodec> mPtrViECodec; // back-pointer
RunningStat mEncoderBitRate;
RunningStat mEncoderFps;
uint32_t mEncoderDroppedFrames;
RunningStat mDecoderBitRate;
RunningStat mDecoderFps;
uint32_t mDecoderDiscardedPackets;
};
}
#endif //CODEC_STATISTICS_H_

Просмотреть файл

@ -0,0 +1,66 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/* Adapted from "Accurately computing running variance - John D. Cook"
http://www.johndcook.com/standard_deviation.html */
#ifndef RUNNING_STAT_H_
#define RUNNING_STAT_H_
#include <math.h>
namespace mozilla {
class RunningStat
{
public:
RunningStat() : mN(0) {}
void Clear()
{
mN = 0;
}
void Push(double x)
{
mN++;
// See Knuth TAOCP vol 2, 3rd edition, page 232
if (mN == 1)
{
mOldM = mNewM = x;
mOldS = 0.0;
} else {
mNewM = mOldM + (x - mOldM) / mN;
mNewS = mOldS + (x - mOldM) * (x - mNewM);
// set up for next iteration
mOldM = mNewM;
mOldS = mNewS;
}
}
int NumDataValues() const
{
return mN;
}
double Mean() const
{
return (mN > 0) ? mNewM : 0.0;
}
double Variance() const
{
return (mN > 1) ? mNewS / (mN - 1) : 0.0;
}
double StandardDeviation() const
{
return sqrt(Variance());
}
private:
int mN;
double mOldM, mNewM, mOldS, mNewS;
};
}
#endif //RUNNING_STAT_H_

Просмотреть файл

@ -117,6 +117,8 @@ WebrtcVideoConduit::~WebrtcVideoConduit()
mOtherDirection->mShutDown = true;
mVideoEngine = nullptr;
} else {
// mVideoCodecStat has a back-ptr to mPtrViECodec that must be released first
mVideoCodecStat = nullptr;
// We can't delete the VideoEngine until all these are released!
// And we can't use a Scoped ptr, since the order is arbitrary
mPtrViEBase = nullptr;
@ -568,6 +570,9 @@ WebrtcVideoConduit::ConfigureSendMediaCodec(const VideoCodecConfig* codecConfig)
mPtrViEBase->LastError());
return kMediaConduitUnknownError;
}
mVideoCodecStat = new VideoCodecStatistics(mChannel, mPtrViECodec);
mSendingWidth = 0;
mSendingHeight = 0;
@ -1010,6 +1015,7 @@ WebrtcVideoConduit::SendVideoFrame(unsigned char* video_frame,
return kMediaConduitCaptureError;
}
mVideoCodecStat->SentFrame();
CSFLogDebug(logTag, "%s Inserted a frame", __FUNCTION__);
return kMediaConduitNoError;
}

Просмотреть файл

@ -10,6 +10,7 @@
#include "MediaConduitInterface.h"
#include "MediaEngineWrapper.h"
#include "CodecStatistics.h"
// conflicts with #include of scoped_ptr.h
#undef FF
@ -344,6 +345,9 @@ private:
nsAutoPtr<VideoCodecConfig> mExternalSendCodec;
nsAutoPtr<VideoCodecConfig> mExternalRecvCodec;
// statistics object for video codec;
nsAutoPtr<VideoCodecStatistics> mVideoCodecStat;
};
} // end namespace