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" | |
21 #include "webrtc/system_wrappers/include/metrics.h" | 20 #include "webrtc/system_wrappers/include/metrics.h" |
22 | 21 |
23 namespace webrtc { | 22 namespace webrtc { |
24 namespace { | 23 namespace { |
25 const float kEncodeTimeWeigthFactor = 0.5f; | 24 const float kEncodeTimeWeigthFactor = 0.5f; |
26 | 25 |
27 // Used by histograms. Values of entries should not be changed. | 26 // Used by histograms. Values of entries should not be changed. |
28 enum HistogramCodecType { | 27 enum HistogramCodecType { |
29 kVideoUnknown = 0, | 28 kVideoUnknown = 0, |
30 kVideoVp8 = 1, | 29 kVideoVp8 = 1, |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 stats->width = 0; | 419 stats->width = 0; |
421 } | 420 } |
422 | 421 |
423 void SendStatisticsProxy::OnSetRates(uint32_t bitrate_bps, int framerate) { | 422 void SendStatisticsProxy::OnSetRates(uint32_t bitrate_bps, int framerate) { |
424 rtc::CritScope lock(&crit_); | 423 rtc::CritScope lock(&crit_); |
425 stats_.target_media_bitrate_bps = bitrate_bps; | 424 stats_.target_media_bitrate_bps = bitrate_bps; |
426 } | 425 } |
427 | 426 |
428 void SendStatisticsProxy::OnSendEncodedImage( | 427 void SendStatisticsProxy::OnSendEncodedImage( |
429 const EncodedImage& encoded_image, | 428 const EncodedImage& encoded_image, |
430 const CodecSpecificInfo* codec_info) { | 429 const RTPVideoHeader* rtp_video_header) { |
431 size_t simulcast_idx = 0; | 430 size_t simulcast_idx = rtp_video_header ? rtp_video_header->simulcastIdx : 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 | |
441 if (simulcast_idx >= config_.rtp.ssrcs.size()) { | 431 if (simulcast_idx >= config_.rtp.ssrcs.size()) { |
442 LOG(LS_ERROR) << "Encoded image outside simulcast range (" << simulcast_idx | 432 LOG(LS_ERROR) << "Encoded image outside simulcast range (" << simulcast_idx |
443 << " >= " << config_.rtp.ssrcs.size() << ")."; | 433 << " >= " << config_.rtp.ssrcs.size() << ")."; |
444 return; | 434 return; |
445 } | 435 } |
446 uint32_t ssrc = config_.rtp.ssrcs[simulcast_idx]; | 436 uint32_t ssrc = config_.rtp.ssrcs[simulcast_idx]; |
447 | 437 |
448 rtc::CritScope lock(&crit_); | 438 rtc::CritScope lock(&crit_); |
449 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 439 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
450 if (!stats) | 440 if (!stats) |
(...skipping 21 matching lines...) Expand all Loading... |
472 } | 462 } |
473 if (encoded_image.adapt_reason_.bw_resolutions_disabled != -1) { | 463 if (encoded_image.adapt_reason_.bw_resolutions_disabled != -1) { |
474 bool bw_limited = encoded_image.adapt_reason_.bw_resolutions_disabled > 0; | 464 bool bw_limited = encoded_image.adapt_reason_.bw_resolutions_disabled > 0; |
475 uma_container_->bw_limited_frame_counter_.Add(bw_limited); | 465 uma_container_->bw_limited_frame_counter_.Add(bw_limited); |
476 if (bw_limited) { | 466 if (bw_limited) { |
477 uma_container_->bw_resolutions_disabled_counter_.Add( | 467 uma_container_->bw_resolutions_disabled_counter_.Add( |
478 encoded_image.adapt_reason_.bw_resolutions_disabled); | 468 encoded_image.adapt_reason_.bw_resolutions_disabled); |
479 } | 469 } |
480 } | 470 } |
481 | 471 |
482 if (encoded_image.qp_ != -1 && codec_info) { | 472 if (encoded_image.qp_ != -1 && rtp_video_header) { |
483 if (codec_info->codecType == kVideoCodecVP8) { | 473 if (rtp_video_header->codec == kRtpVideoVp8) { |
484 int spatial_idx = (config_.rtp.ssrcs.size() == 1) | 474 int spatial_idx = (config_.rtp.ssrcs.size() == 1) |
485 ? -1 | 475 ? -1 |
486 : static_cast<int>(simulcast_idx); | 476 : static_cast<int>(simulcast_idx); |
487 uma_container_->qp_counters_[spatial_idx].vp8.Add(encoded_image.qp_); | 477 uma_container_->qp_counters_[spatial_idx].vp8.Add(encoded_image.qp_); |
488 } else if (codec_info->codecType == kVideoCodecVP9) { | 478 } else if (rtp_video_header->codec == kRtpVideoVp9) { |
489 int spatial_idx = (codec_info->codecSpecific.VP9.num_spatial_layers == 1) | 479 int spatial_idx = |
490 ? -1 | 480 (rtp_video_header->codecHeader.VP9.num_spatial_layers == 1) |
491 : codec_info->codecSpecific.VP9.spatial_idx; | 481 ? -1 |
| 482 : rtp_video_header->codecHeader.VP9.spatial_idx; |
492 uma_container_->qp_counters_[spatial_idx].vp9.Add(encoded_image.qp_); | 483 uma_container_->qp_counters_[spatial_idx].vp9.Add(encoded_image.qp_); |
493 } | 484 } |
494 } | 485 } |
495 | 486 |
496 // TODO(asapersson): This is incorrect if simulcast layers are encoded on | 487 // TODO(asapersson): This is incorrect if simulcast layers are encoded on |
497 // different threads and there is no guarantee that one frame of all layers | 488 // different threads and there is no guarantee that one frame of all layers |
498 // are encoded before the next start. | 489 // are encoded before the next start. |
499 if (last_sent_frame_timestamp_ > 0 && | 490 if (last_sent_frame_timestamp_ > 0 && |
500 encoded_image._timeStamp != last_sent_frame_timestamp_) { | 491 encoded_image._timeStamp != last_sent_frame_timestamp_) { |
501 uma_container_->sent_frame_rate_tracker_.AddSamples(1); | 492 uma_container_->sent_frame_rate_tracker_.AddSamples(1); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 return Fraction(min_required_samples, 1000.0f); | 615 return Fraction(min_required_samples, 1000.0f); |
625 } | 616 } |
626 | 617 |
627 int SendStatisticsProxy::BoolSampleCounter::Fraction( | 618 int SendStatisticsProxy::BoolSampleCounter::Fraction( |
628 int min_required_samples, float multiplier) const { | 619 int min_required_samples, float multiplier) const { |
629 if (num_samples < min_required_samples || num_samples == 0) | 620 if (num_samples < min_required_samples || num_samples == 0) |
630 return -1; | 621 return -1; |
631 return static_cast<int>((sum * multiplier / num_samples) + 0.5f); | 622 return static_cast<int>((sum * multiplier / num_samples) + 0.5f); |
632 } | 623 } |
633 } // namespace webrtc | 624 } // namespace webrtc |
OLD | NEW |