LCOV - code coverage report
Current view: top level - media/webrtc/trunk/webrtc - common_types.cc (source / functions) Hit Total Coverage
Test: output.info Lines: 0 97 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 19 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
       3             :  *
       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
       6             :  *  tree. An additional intellectual property rights grant can be found
       7             :  *  in the file PATENTS.  All contributing project authors may
       8             :  *  be found in the AUTHORS file in the root of the source tree.
       9             :  */
      10             : 
      11             : #include "webrtc/common_types.h"
      12             : 
      13             : #include <limits>
      14             : #include <string.h>
      15             : 
      16             : #include "webrtc/base/checks.h"
      17             : #include "webrtc/base/stringutils.h"
      18             : 
      19             : namespace webrtc {
      20             : 
      21           0 : StreamDataCounters::StreamDataCounters() : first_packet_time_ms(-1) {}
      22             : 
      23           0 : RTPHeaderExtension::RTPHeaderExtension()
      24             :     : hasTransmissionTimeOffset(false),
      25             :       transmissionTimeOffset(0),
      26             :       hasAbsoluteSendTime(false),
      27             :       absoluteSendTime(0),
      28             :       hasTransportSequenceNumber(false),
      29             :       transportSequenceNumber(0),
      30             :       hasAudioLevel(false),
      31             :       voiceActivity(false),
      32             :       audioLevel(0),
      33             :       hasVideoRotation(false),
      34             :       videoRotation(kVideoRotation_0),
      35             :       hasRID(false),
      36           0 :       rid(nullptr) {
      37           0 : }
      38             : 
      39           0 : RTPHeaderExtension::RTPHeaderExtension(const RTPHeaderExtension& rhs) {
      40           0 :   *this = rhs;
      41           0 : }
      42             : 
      43             : RTPHeaderExtension&
      44           0 : RTPHeaderExtension::operator=(const RTPHeaderExtension& rhs) {
      45           0 :   hasTransmissionTimeOffset = rhs.hasTransmissionTimeOffset;
      46           0 :   transmissionTimeOffset = rhs.transmissionTimeOffset;
      47           0 :   hasAbsoluteSendTime = rhs.hasAbsoluteSendTime;
      48           0 :   absoluteSendTime = rhs.absoluteSendTime;
      49           0 :   hasTransportSequenceNumber = rhs.hasTransportSequenceNumber;
      50           0 :   transportSequenceNumber = rhs.transportSequenceNumber;
      51             : 
      52           0 :   hasAudioLevel = rhs.hasAudioLevel;
      53           0 :   voiceActivity = rhs.voiceActivity;
      54           0 :   audioLevel = rhs.audioLevel;
      55             : 
      56           0 :   hasVideoRotation = rhs.hasVideoRotation;
      57           0 :   videoRotation = rhs.videoRotation;
      58             : 
      59           0 :   hasRID = rhs.hasRID;
      60           0 :  if (rhs.rid) {
      61           0 :     rid.reset(new char[strlen(rhs.rid.get())+1]);
      62           0 :     strcpy(rid.get(), rhs.rid.get());
      63             :   }
      64           0 :   return *this;
      65             : }
      66             : 
      67           0 : RTPHeader::RTPHeader()
      68             :     : markerBit(false),
      69             :       payloadType(0),
      70             :       sequenceNumber(0),
      71             :       timestamp(0),
      72             :       ssrc(0),
      73             :       numCSRCs(0),
      74             :       arrOfCSRCs(),
      75             :       paddingLength(0),
      76             :       headerLength(0),
      77             :       payload_type_frequency(0),
      78           0 :       extension() {}
      79             : 
      80           0 : VideoCodec::VideoCodec()
      81             :     : codecType(kVideoCodecUnknown),
      82             :       plName(),
      83             :       plType(0),
      84             :       width(0),
      85             :       height(0),
      86             :       startBitrate(0),
      87             :       maxBitrate(0),
      88             :       minBitrate(0),
      89             :       targetBitrate(0),
      90             :       maxFramerate(0),
      91             :       qpMax(0),
      92             :       numberOfSimulcastStreams(0),
      93             :       simulcastStream(),
      94             :       spatialLayers(),
      95             :       mode(kRealtimeVideo),
      96             :       expect_encode_from_texture(false),
      97           0 :       codec_specific_() {}
      98             : 
      99           0 : VideoCodecVP8* VideoCodec::VP8() {
     100           0 :   RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
     101           0 :   return &codec_specific_.VP8;
     102             : }
     103             : 
     104           0 : const VideoCodecVP8& VideoCodec::VP8() const {
     105           0 :   RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
     106           0 :   return codec_specific_.VP8;
     107             : }
     108             : 
     109           0 : VideoCodecVP9* VideoCodec::VP9() {
     110           0 :   RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
     111           0 :   return &codec_specific_.VP9;
     112             : }
     113             : 
     114           0 : const VideoCodecVP9& VideoCodec::VP9() const {
     115           0 :   RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
     116           0 :   return codec_specific_.VP9;
     117             : }
     118             : 
     119           0 : VideoCodecH264* VideoCodec::H264() {
     120           0 :   RTC_DCHECK_EQ(codecType, kVideoCodecH264);
     121           0 :   return &codec_specific_.H264;
     122             : }
     123             : 
     124           0 : const VideoCodecH264& VideoCodec::H264() const {
     125           0 :   RTC_DCHECK_EQ(codecType, kVideoCodecH264);
     126           0 :   return codec_specific_.H264;
     127             : }
     128             : 
     129             : static const char* kPayloadNameVp8 = "VP8";
     130             : static const char* kPayloadNameVp9 = "VP9";
     131             : static const char* kPayloadNameH264 = "H264";
     132             : static const char* kPayloadNameI420 = "I420";
     133             : static const char* kPayloadNameRED = "RED";
     134             : static const char* kPayloadNameULPFEC = "ULPFEC";
     135             : static const char* kPayloadNameGeneric = "Generic";
     136             : 
     137           0 : static bool CodecNamesEq(const char* name1, const char* name2) {
     138           0 :   return _stricmp(name1, name2) == 0;
     139             : }
     140             : 
     141           0 : rtc::Optional<const char*> CodecTypeToPayloadName(VideoCodecType type) {
     142           0 :   switch (type) {
     143             :     case kVideoCodecVP8:
     144           0 :       return rtc::Optional<const char*>(kPayloadNameVp8);
     145             :     case kVideoCodecVP9:
     146           0 :       return rtc::Optional<const char*>(kPayloadNameVp9);
     147             :     case kVideoCodecH264:
     148           0 :       return rtc::Optional<const char*>(kPayloadNameH264);
     149             :     case kVideoCodecI420:
     150           0 :       return rtc::Optional<const char*>(kPayloadNameI420);
     151             :     case kVideoCodecRED:
     152           0 :       return rtc::Optional<const char*>(kPayloadNameRED);
     153             :     case kVideoCodecULPFEC:
     154           0 :       return rtc::Optional<const char*>(kPayloadNameULPFEC);
     155             :     case kVideoCodecGeneric:
     156           0 :       return rtc::Optional<const char*>(kPayloadNameGeneric);
     157             :     default:
     158           0 :       return rtc::Optional<const char*>();
     159             :   }
     160             : }
     161             : 
     162           0 : rtc::Optional<VideoCodecType> PayloadNameToCodecType(const std::string& name) {
     163           0 :   if (CodecNamesEq(name.c_str(), kPayloadNameVp8))
     164           0 :     return rtc::Optional<VideoCodecType>(kVideoCodecVP8);
     165           0 :   if (CodecNamesEq(name.c_str(), kPayloadNameVp9))
     166           0 :     return rtc::Optional<VideoCodecType>(kVideoCodecVP9);
     167           0 :   if (CodecNamesEq(name.c_str(), kPayloadNameH264))
     168           0 :     return rtc::Optional<VideoCodecType>(kVideoCodecH264);
     169           0 :   if (CodecNamesEq(name.c_str(), kPayloadNameI420))
     170           0 :     return rtc::Optional<VideoCodecType>(kVideoCodecI420);
     171           0 :   if (CodecNamesEq(name.c_str(), kPayloadNameRED))
     172           0 :     return rtc::Optional<VideoCodecType>(kVideoCodecRED);
     173           0 :   if (CodecNamesEq(name.c_str(), kPayloadNameULPFEC))
     174           0 :     return rtc::Optional<VideoCodecType>(kVideoCodecULPFEC);
     175           0 :   if (CodecNamesEq(name.c_str(), kPayloadNameGeneric))
     176           0 :     return rtc::Optional<VideoCodecType>(kVideoCodecGeneric);
     177           0 :   return rtc::Optional<VideoCodecType>();
     178             : }
     179             : 
     180             : const uint32_t BitrateAllocation::kMaxBitrateBps =
     181             :     std::numeric_limits<uint32_t>::max();
     182             : 
     183           0 : BitrateAllocation::BitrateAllocation() : sum_(0), bitrates_{} {}
     184             : 
     185           0 : bool BitrateAllocation::SetBitrate(size_t spatial_index,
     186             :                                    size_t temporal_index,
     187             :                                    uint32_t bitrate_bps) {
     188           0 :   RTC_CHECK_LT(spatial_index, kMaxSpatialLayers);
     189           0 :   RTC_CHECK_LT(temporal_index, kMaxTemporalStreams);
     190           0 :   RTC_CHECK_LE(bitrates_[spatial_index][temporal_index], sum_);
     191           0 :   uint64_t new_bitrate_sum_bps = sum_;
     192           0 :   new_bitrate_sum_bps -= bitrates_[spatial_index][temporal_index];
     193           0 :   new_bitrate_sum_bps += bitrate_bps;
     194           0 :   if (new_bitrate_sum_bps > kMaxBitrateBps)
     195           0 :     return false;
     196             : 
     197           0 :   bitrates_[spatial_index][temporal_index] = bitrate_bps;
     198           0 :   sum_ = static_cast<uint32_t>(new_bitrate_sum_bps);
     199           0 :   return true;
     200             : }
     201             : 
     202           0 : uint32_t BitrateAllocation::GetBitrate(size_t spatial_index,
     203             :                                        size_t temporal_index) const {
     204           0 :   RTC_CHECK_LT(spatial_index, kMaxSpatialLayers);
     205           0 :   RTC_CHECK_LT(temporal_index, kMaxTemporalStreams);
     206           0 :   return bitrates_[spatial_index][temporal_index];
     207             : }
     208             : 
     209             : // Get the sum of all the temporal layer for a specific spatial layer.
     210           0 : uint32_t BitrateAllocation::GetSpatialLayerSum(size_t spatial_index) const {
     211           0 :   RTC_CHECK_LT(spatial_index, kMaxSpatialLayers);
     212           0 :   uint32_t sum = 0;
     213           0 :   for (int i = 0; i < kMaxTemporalStreams; ++i)
     214           0 :     sum += bitrates_[spatial_index][i];
     215           0 :   return sum;
     216             : }
     217             : 
     218             : }  // namespace webrtc

Generated by: LCOV version 1.13