| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/video/send_statistics_proxy.h" | 11 #include "webrtc/video/send_statistics_proxy.h" |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 #include <cmath> | 14 #include <cmath> |
| 15 #include <map> | 15 #include <map> |
| 16 #include <vector> | 16 #include <vector> |
| 17 | 17 |
| 18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
| 19 #include "webrtc/base/logging.h" | 19 #include "webrtc/base/logging.h" |
| 20 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
| 20 #include "webrtc/system_wrappers/include/metrics.h" | 21 #include "webrtc/system_wrappers/include/metrics.h" |
| 21 | 22 |
| 22 namespace webrtc { | 23 namespace webrtc { |
| 23 namespace { | 24 namespace { |
| 24 const float kEncodeTimeWeigthFactor = 0.5f; | 25 const float kEncodeTimeWeigthFactor = 0.5f; |
| 25 | 26 |
| 26 // Used by histograms. Values of entries should not be changed. | 27 // Used by histograms. Values of entries should not be changed. |
| 27 enum HistogramCodecType { | 28 enum HistogramCodecType { |
| 28 kVideoUnknown = 0, | 29 kVideoUnknown = 0, |
| 29 kVideoVp8 = 1, | 30 kVideoVp8 = 1, |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 stats->width = 0; | 420 stats->width = 0; |
| 420 } | 421 } |
| 421 | 422 |
| 422 void SendStatisticsProxy::OnSetRates(uint32_t bitrate_bps, int framerate) { | 423 void SendStatisticsProxy::OnSetRates(uint32_t bitrate_bps, int framerate) { |
| 423 rtc::CritScope lock(&crit_); | 424 rtc::CritScope lock(&crit_); |
| 424 stats_.target_media_bitrate_bps = bitrate_bps; | 425 stats_.target_media_bitrate_bps = bitrate_bps; |
| 425 } | 426 } |
| 426 | 427 |
| 427 void SendStatisticsProxy::OnSendEncodedImage( | 428 void SendStatisticsProxy::OnSendEncodedImage( |
| 428 const EncodedImage& encoded_image, | 429 const EncodedImage& encoded_image, |
| 429 const RTPVideoHeader* rtp_video_header) { | 430 const CodecSpecificInfo* codec_info) { |
| 430 size_t simulcast_idx = rtp_video_header ? rtp_video_header->simulcastIdx : 0; | 431 size_t simulcast_idx = 0; |
| 432 |
| 433 if (codec_info) { |
| 434 if (codec_info->codecType == kVideoCodecVP8) { |
| 435 simulcast_idx = codec_info->codecSpecific.VP8.simulcastIdx; |
| 436 } else if (codec_info->codecType == kVideoCodecGeneric) { |
| 437 simulcast_idx = codec_info->codecSpecific.generic.simulcast_idx; |
| 438 } |
| 439 } |
| 440 |
| 431 if (simulcast_idx >= config_.rtp.ssrcs.size()) { | 441 if (simulcast_idx >= config_.rtp.ssrcs.size()) { |
| 432 LOG(LS_ERROR) << "Encoded image outside simulcast range (" << simulcast_idx | 442 LOG(LS_ERROR) << "Encoded image outside simulcast range (" << simulcast_idx |
| 433 << " >= " << config_.rtp.ssrcs.size() << ")."; | 443 << " >= " << config_.rtp.ssrcs.size() << ")."; |
| 434 return; | 444 return; |
| 435 } | 445 } |
| 436 uint32_t ssrc = config_.rtp.ssrcs[simulcast_idx]; | 446 uint32_t ssrc = config_.rtp.ssrcs[simulcast_idx]; |
| 437 | 447 |
| 438 rtc::CritScope lock(&crit_); | 448 rtc::CritScope lock(&crit_); |
| 439 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 449 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
| 440 if (!stats) | 450 if (!stats) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 462 } | 472 } |
| 463 if (encoded_image.adapt_reason_.bw_resolutions_disabled != -1) { | 473 if (encoded_image.adapt_reason_.bw_resolutions_disabled != -1) { |
| 464 bool bw_limited = encoded_image.adapt_reason_.bw_resolutions_disabled > 0; | 474 bool bw_limited = encoded_image.adapt_reason_.bw_resolutions_disabled > 0; |
| 465 uma_container_->bw_limited_frame_counter_.Add(bw_limited); | 475 uma_container_->bw_limited_frame_counter_.Add(bw_limited); |
| 466 if (bw_limited) { | 476 if (bw_limited) { |
| 467 uma_container_->bw_resolutions_disabled_counter_.Add( | 477 uma_container_->bw_resolutions_disabled_counter_.Add( |
| 468 encoded_image.adapt_reason_.bw_resolutions_disabled); | 478 encoded_image.adapt_reason_.bw_resolutions_disabled); |
| 469 } | 479 } |
| 470 } | 480 } |
| 471 | 481 |
| 472 if (encoded_image.qp_ != -1 && rtp_video_header) { | 482 if (encoded_image.qp_ != -1 && codec_info) { |
| 473 if (rtp_video_header->codec == kRtpVideoVp8) { | 483 if (codec_info->codecType == kVideoCodecVP8) { |
| 474 int spatial_idx = (config_.rtp.ssrcs.size() == 1) | 484 int spatial_idx = (config_.rtp.ssrcs.size() == 1) |
| 475 ? -1 | 485 ? -1 |
| 476 : static_cast<int>(simulcast_idx); | 486 : static_cast<int>(simulcast_idx); |
| 477 uma_container_->qp_counters_[spatial_idx].vp8.Add(encoded_image.qp_); | 487 uma_container_->qp_counters_[spatial_idx].vp8.Add(encoded_image.qp_); |
| 478 } else if (rtp_video_header->codec == kRtpVideoVp9) { | 488 } else if (codec_info->codecType == kVideoCodecVP9) { |
| 479 int spatial_idx = | 489 int spatial_idx = (codec_info->codecSpecific.VP9.num_spatial_layers == 1) |
| 480 (rtp_video_header->codecHeader.VP9.num_spatial_layers == 1) | 490 ? -1 |
| 481 ? -1 | 491 : codec_info->codecSpecific.VP9.spatial_idx; |
| 482 : rtp_video_header->codecHeader.VP9.spatial_idx; | |
| 483 uma_container_->qp_counters_[spatial_idx].vp9.Add(encoded_image.qp_); | 492 uma_container_->qp_counters_[spatial_idx].vp9.Add(encoded_image.qp_); |
| 484 } | 493 } |
| 485 } | 494 } |
| 486 | 495 |
| 487 // TODO(asapersson): This is incorrect if simulcast layers are encoded on | 496 // TODO(asapersson): This is incorrect if simulcast layers are encoded on |
| 488 // different threads and there is no guarantee that one frame of all layers | 497 // different threads and there is no guarantee that one frame of all layers |
| 489 // are encoded before the next start. | 498 // are encoded before the next start. |
| 490 if (last_sent_frame_timestamp_ > 0 && | 499 if (last_sent_frame_timestamp_ > 0 && |
| 491 encoded_image._timeStamp != last_sent_frame_timestamp_) { | 500 encoded_image._timeStamp != last_sent_frame_timestamp_) { |
| 492 uma_container_->sent_frame_rate_tracker_.AddSamples(1); | 501 uma_container_->sent_frame_rate_tracker_.AddSamples(1); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 return Fraction(min_required_samples, 1000.0f); | 624 return Fraction(min_required_samples, 1000.0f); |
| 616 } | 625 } |
| 617 | 626 |
| 618 int SendStatisticsProxy::BoolSampleCounter::Fraction( | 627 int SendStatisticsProxy::BoolSampleCounter::Fraction( |
| 619 int min_required_samples, float multiplier) const { | 628 int min_required_samples, float multiplier) const { |
| 620 if (num_samples < min_required_samples || num_samples == 0) | 629 if (num_samples < min_required_samples || num_samples == 0) |
| 621 return -1; | 630 return -1; |
| 622 return static_cast<int>((sum * multiplier / num_samples) + 0.5f); | 631 return static_cast<int>((sum * multiplier / num_samples) + 0.5f); |
| 623 } | 632 } |
| 624 } // namespace webrtc | 633 } // namespace webrtc |
| OLD | NEW |