Refactor some receive-side stats.

Removes polling of CName as well as receive codec statistics in favor of
internal callbacks keeping a statistics struct up to date.

R=mflodman@webrtc.org, stefan@webrtc.org
BUG=1667

Review URL: https://webrtc-codereview.appspot.com/28259005

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7950 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
pbos@webrtc.org
2014-12-18 13:50:16 +00:00
parent 98c04b38a8
commit ce4e9a3562
38 changed files with 235 additions and 178 deletions

View File

@ -124,6 +124,7 @@ VCMJitterBuffer::VCMJitterBuffer(Clock* clock, EventFactory* event_factory)
incomplete_frames_(),
last_decoded_state_(),
first_packet_since_reset_(true),
frame_count_observer_(NULL),
incoming_frame_rate_(0),
incoming_frame_count_(0),
time_last_incoming_frame_count_(0),
@ -184,14 +185,15 @@ void VCMJitterBuffer::UpdateHistograms() {
RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.DuplicatedPacketsInPercent",
num_duplicated_packets_ * 100 / num_packets_);
uint32_t total_frames = receive_statistics_[kVideoFrameKey] +
receive_statistics_[kVideoFrameDelta];
int total_frames =
receive_statistics_.key_frames + receive_statistics_.delta_frames;
if (total_frames > 0) {
RTC_HISTOGRAM_COUNTS_100("WebRTC.Video.CompleteFramesReceivedPerSecond",
static_cast<int>((total_frames / elapsed_sec) + 0.5f));
RTC_HISTOGRAM_COUNTS_1000("WebRTC.Video.KeyFramesReceivedInPermille",
static_cast<int>((receive_statistics_[kVideoFrameKey] * 1000.0f /
total_frames) + 0.5f));
RTC_HISTOGRAM_COUNTS_1000(
"WebRTC.Video.KeyFramesReceivedInPermille",
static_cast<int>(
(receive_statistics_.key_frames * 1000.0f / total_frames) + 0.5f));
}
}
@ -203,7 +205,7 @@ void VCMJitterBuffer::Start() {
incoming_bit_count_ = 0;
incoming_bit_rate_ = 0;
time_last_incoming_frame_count_ = clock_->TimeInMilliseconds();
receive_statistics_.clear();
receive_statistics_ = FrameCounts();
num_consecutive_old_packets_ = 0;
num_packets_ = 0;
@ -269,7 +271,7 @@ void VCMJitterBuffer::Flush() {
}
// Get received key and delta frames
std::map<FrameType, uint32_t> VCMJitterBuffer::FrameStatistics() const {
FrameCounts VCMJitterBuffer::FrameStatistics() const {
CriticalSectionScoped cs(crit_sect_);
return receive_statistics_;
}
@ -1038,6 +1040,12 @@ void VCMJitterBuffer::RenderBufferSize(uint32_t* timestamp_start,
*timestamp_end = decodable_frames_.Back()->TimeStamp();
}
void VCMJitterBuffer::RegisterFrameCountObserver(
FrameCountObserver* frame_count_observer) {
CriticalSectionScoped cs(crit_sect_);
frame_count_observer_ = frame_count_observer;
}
VCMFrameBuffer* VCMJitterBuffer::GetEmptyFrame() {
if (free_frames_.empty()) {
if (!TryToIncreaseJitterBufferSize()) {
@ -1105,7 +1113,13 @@ void VCMJitterBuffer::CountFrame(const VCMFrameBuffer& frame) {
// Update receive statistics. We count all layers, thus when you use layers
// adding all key and delta frames might differ from frame count.
if (frame.IsSessionComplete()) {
++receive_statistics_[frame.FrameType()];
if (frame.FrameType() == kVideoFrameKey) {
++receive_statistics_.key_frames;
} else {
++receive_statistics_.delta_frames;
}
if (frame_count_observer_ != NULL)
frame_count_observer_->FrameCountUpdated(receive_statistics_, 0);
}
}

View File

@ -94,7 +94,7 @@ class VCMJitterBuffer {
// Get the number of received frames, by type, since the jitter buffer
// was started.
std::map<FrameType, uint32_t> FrameStatistics() const;
FrameCounts FrameStatistics() const;
// The number of packets discarded by the jitter buffer because the decoder
// won't be able to decode them.
@ -184,6 +184,8 @@ class VCMJitterBuffer {
// corresponding to the start and end of the continuous complete buffer.
void RenderBufferSize(uint32_t* timestamp_start, uint32_t* timestamp_end);
void RegisterFrameCountObserver(FrameCountObserver* observer);
private:
class SequenceNumberLessThan {
public:
@ -254,7 +256,8 @@ class VCMJitterBuffer {
// Updates the frame statistics.
// Counts only complete frames, so decodable incomplete frames will not be
// counted.
void CountFrame(const VCMFrameBuffer& frame);
void CountFrame(const VCMFrameBuffer& frame)
EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
// Update rolling average of packets per frame.
void UpdateAveragePacketsPerFrame(int current_number_packets_);
@ -301,7 +304,8 @@ class VCMJitterBuffer {
// Statistics.
// Frame counts for each type (key, delta, ...)
std::map<FrameType, uint32_t> receive_statistics_;
FrameCountObserver* frame_count_observer_ GUARDED_BY(crit_sect_);
FrameCounts receive_statistics_;
// Latest calculated frame rates of incoming stream.
unsigned int incoming_frame_rate_;
unsigned int incoming_frame_count_;

View File

@ -1693,9 +1693,9 @@ TEST_F(TestRunningJitterBuffer, EmptyPackets) {
}
TEST_F(TestRunningJitterBuffer, StatisticsTest) {
std::map<FrameType, uint32_t> frame_stats(jitter_buffer_->FrameStatistics());
EXPECT_EQ(0u, frame_stats[kVideoFrameDelta]);
EXPECT_EQ(0u, frame_stats[kVideoFrameKey]);
FrameCounts frame_stats(jitter_buffer_->FrameStatistics());
EXPECT_EQ(0, frame_stats.delta_frames);
EXPECT_EQ(0, frame_stats.key_frames);
uint32_t framerate = 0;
uint32_t bitrate = 0;
@ -1714,8 +1714,8 @@ TEST_F(TestRunningJitterBuffer, StatisticsTest) {
EXPECT_TRUE(DecodeCompleteFrame());
EXPECT_TRUE(DecodeCompleteFrame());
frame_stats = jitter_buffer_->FrameStatistics();
EXPECT_EQ(3u, frame_stats[kVideoFrameDelta]);
EXPECT_EQ(2u, frame_stats[kVideoFrameKey]);
EXPECT_EQ(3, frame_stats.delta_frames);
EXPECT_EQ(2, frame_stats.key_frames);
// Insert 20 more frames to get estimates of bitrate and framerate over
// 1 second.

View File

@ -186,13 +186,6 @@ void VCMReceiver::ReceiveStatistics(uint32_t* bitrate,
jitter_buffer_.IncomingRateStatistics(framerate, bitrate);
}
void VCMReceiver::ReceivedFrameCount(VCMFrameCount* frame_count) const {
assert(frame_count);
std::map<FrameType, uint32_t> counts(jitter_buffer_.FrameStatistics());
frame_count->numDeltaFrames = counts[kVideoFrameDelta];
frame_count->numKeyFrames = counts[kVideoFrameKey];
}
uint32_t VCMReceiver::DiscardedPackets() const {
return jitter_buffer_.num_discarded_packets();
}
@ -276,4 +269,10 @@ int VCMReceiver::RenderBufferSizeMs() {
uint32_t render_end = timing_->RenderTimeMs(timestamp_end, now_ms);
return render_end - render_start;
}
void VCMReceiver::RegisterFrameCountObserver(
FrameCountObserver* frame_count_observer) {
jitter_buffer_.RegisterFrameCountObserver(frame_count_observer);
}
} // namespace webrtc

View File

@ -53,7 +53,6 @@ class VCMReceiver {
bool render_timing = true);
void ReleaseFrame(VCMEncodedFrame* frame);
void ReceiveStatistics(uint32_t* bitrate, uint32_t* framerate);
void ReceivedFrameCount(VCMFrameCount* frame_count) const;
uint32_t DiscardedPackets() const;
// NACK.
@ -80,6 +79,8 @@ class VCMReceiver {
// the time this function is called.
int RenderBufferSizeMs();
void RegisterFrameCountObserver(FrameCountObserver* frame_count_observer);
private:
static int32_t GenerateReceiverId();

View File

@ -278,6 +278,11 @@ class VideoCodingModuleImpl : public VideoCodingModule {
return receiver_->RegisterRenderBufferSizeCallback(callback);
}
virtual void RegisterReceiveFrameCountObserver(
FrameCountObserver* frame_count_observer) OVERRIDE {
receiver_->RegisterFrameCountObserver(frame_count_observer);
}
virtual int32_t Decode(uint16_t maxWaitTimeMs) OVERRIDE {
return receiver_->Decode(maxWaitTimeMs);
}
@ -308,10 +313,6 @@ class VideoCodingModuleImpl : public VideoCodingModule {
virtual int32_t Delay() const OVERRIDE { return receiver_->Delay(); }
virtual int32_t ReceivedFrameCount(VCMFrameCount& frameCount) const OVERRIDE {
return receiver_->ReceivedFrameCount(&frameCount);
}
virtual uint32_t DiscardedPackets() const OVERRIDE {
return receiver_->DiscardedPackets();
}

View File

@ -164,7 +164,6 @@ class VideoReceiver {
int32_t SetMinimumPlayoutDelay(uint32_t minPlayoutDelayMs);
int32_t SetRenderDelay(uint32_t timeMS);
int32_t Delay() const;
int32_t ReceivedFrameCount(VCMFrameCount* frameCount) const;
uint32_t DiscardedPackets() const;
int SetReceiverRobustnessMode(ReceiverRobustness robustnessMode,
@ -183,6 +182,7 @@ class VideoReceiver {
int32_t Process();
void RegisterPreDecodeImageCallback(EncodedImageCallback* observer);
void RegisterFrameCountObserver(FrameCountObserver* frame_count_observer);
protected:
int32_t Decode(const webrtc::VCMEncodedFrame& frame)

View File

@ -592,11 +592,6 @@ int32_t VideoReceiver::NackList(uint16_t* nackList, uint16_t* size) {
return VCM_OK;
}
int32_t VideoReceiver::ReceivedFrameCount(VCMFrameCount* frameCount) const {
_receiver.ReceivedFrameCount(frameCount);
return VCM_OK;
}
uint32_t VideoReceiver::DiscardedPackets() const {
return _receiver.DiscardedPackets();
}
@ -671,6 +666,10 @@ void VideoReceiver::RegisterPreDecodeImageCallback(
CriticalSectionScoped cs(_receiveCritSect);
pre_decode_image_callback_ = observer;
}
void VideoReceiver::RegisterFrameCountObserver(
FrameCountObserver* frame_count_observer) {
_receiver.RegisterFrameCountObserver(frame_count_observer);
}
} // namespace vcm
} // namespace webrtc