OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2017 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/api/video/video_content_type.h" |
| 12 |
| 13 // VideoContentType stored as a single byte, which is sent over the network. |
| 14 // Structure: |
| 15 // |
| 16 // 0 1 2 3 4 5 6 7 |
| 17 // +---------------+ |
| 18 // |r r e e e s s c| |
| 19 // |
| 20 // where: |
| 21 // r - reserved bits. |
| 22 // e - 3-bit number of an experiment group counted from 1. 0 means there's no |
| 23 // experiment ongoing. |
| 24 // s - 2-bit simulcast stream id or spatial layer, counted from 1. 0 means that |
| 25 // no simulcast information is set. |
| 26 // c - content type. 0 means real-time video, 1 means screenshare. |
| 27 // |
| 28 |
| 29 namespace webrtc { |
| 30 |
| 31 namespace { |
| 32 static constexpr uint8_t kScreenshareBitsSize = 1; |
| 33 static constexpr uint8_t kScreenshareBitsMask = |
| 34 (1u << kScreenshareBitsSize) - 1; |
| 35 |
| 36 static constexpr uint8_t kSimulcastShift = 1; |
| 37 static constexpr uint8_t kSimulcastBitsSize = 2; |
| 38 static constexpr uint8_t kSimulcastBitsMask = ((1u << kSimulcastBitsSize) - 1) |
| 39 << kSimulcastShift; // 0b00000110 |
| 40 |
| 41 static constexpr uint8_t kExperimentShift = 3; |
| 42 static constexpr uint8_t kExperimentBitsSize = 3; |
| 43 static constexpr uint8_t kExperimentBitsMask = |
| 44 ((1u << kExperimentBitsSize) - 1) << kExperimentShift; // 0b00111000 |
| 45 |
| 46 static constexpr uint8_t kTotalBitsSize = |
| 47 kScreenshareBitsSize + kSimulcastBitsSize + kExperimentBitsSize; |
| 48 } // namespace |
| 49 |
| 50 bool VideoContentTypeHelpers::SetExperimentId(VideoContentType* content_type, |
| 51 uint8_t experiment_id) { |
| 52 // Store in bits 2-4. |
| 53 if (experiment_id >= (1 << kExperimentBitsSize)) |
| 54 return false; |
| 55 *content_type = static_cast<VideoContentType>( |
| 56 (static_cast<uint8_t>(*content_type) & ~kExperimentBitsMask) | |
| 57 ((experiment_id << kExperimentShift) & kExperimentBitsMask)); |
| 58 return true; |
| 59 } |
| 60 |
| 61 bool VideoContentTypeHelpers::SetSimulcastId(VideoContentType* content_type, |
| 62 uint8_t simulcast_id) { |
| 63 // Store in bits 5-6. |
| 64 if (simulcast_id >= (1 << kSimulcastBitsSize)) |
| 65 return false; |
| 66 *content_type = static_cast<VideoContentType>( |
| 67 (static_cast<uint8_t>(*content_type) & ~kSimulcastBitsMask) | |
| 68 ((simulcast_id << kSimulcastShift) & kSimulcastBitsMask)); |
| 69 return true; |
| 70 } |
| 71 |
| 72 uint8_t VideoContentTypeHelpers::GetExperimentId( |
| 73 const VideoContentType& content_type) { |
| 74 return (static_cast<uint8_t>(content_type) & kExperimentBitsMask) >> |
| 75 kExperimentShift; |
| 76 } |
| 77 uint8_t VideoContentTypeHelpers::GetSimulcastId( |
| 78 const VideoContentType& content_type) { |
| 79 return (static_cast<uint8_t>(content_type) & kSimulcastBitsMask) >> |
| 80 kSimulcastShift; |
| 81 } |
| 82 |
| 83 bool VideoContentTypeHelpers::IsScreenshare( |
| 84 const VideoContentType& content_type) { |
| 85 return (static_cast<uint8_t>(content_type) & kScreenshareBitsMask) > 0; |
| 86 } |
| 87 |
| 88 bool VideoContentTypeHelpers::IsValidContentType(uint8_t value) { |
| 89 // Any 6-bit value is allowed. |
| 90 return value < (1 << kTotalBitsSize); |
| 91 } |
| 92 } // namespace webrtc |
OLD | NEW |