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 namespace videocontenttypehelpers { |
| 31 |
| 32 namespace { |
| 33 static constexpr uint8_t kScreenshareBitsSize = 1; |
| 34 static constexpr uint8_t kScreenshareBitsMask = |
| 35 (1u << kScreenshareBitsSize) - 1; |
| 36 |
| 37 static constexpr uint8_t kSimulcastShift = 1; |
| 38 static constexpr uint8_t kSimulcastBitsSize = 2; |
| 39 static constexpr uint8_t kSimulcastBitsMask = ((1u << kSimulcastBitsSize) - 1) |
| 40 << kSimulcastShift; // 0b00000110 |
| 41 |
| 42 static constexpr uint8_t kExperimentShift = 3; |
| 43 static constexpr uint8_t kExperimentBitsSize = 3; |
| 44 static constexpr uint8_t kExperimentBitsMask = |
| 45 ((1u << kExperimentBitsSize) - 1) << kExperimentShift; // 0b00111000 |
| 46 |
| 47 static constexpr uint8_t kTotalBitsSize = |
| 48 kScreenshareBitsSize + kSimulcastBitsSize + kExperimentBitsSize; |
| 49 } // namespace |
| 50 |
| 51 bool SetExperimentId(VideoContentType* content_type, |
| 52 uint8_t experiment_id) { |
| 53 // Store in bits 2-4. |
| 54 if (experiment_id >= (1 << kExperimentBitsSize)) |
| 55 return false; |
| 56 *content_type = static_cast<VideoContentType>( |
| 57 (static_cast<uint8_t>(*content_type) & ~kExperimentBitsMask) | |
| 58 ((experiment_id << kExperimentShift) & kExperimentBitsMask)); |
| 59 return true; |
| 60 } |
| 61 |
| 62 bool SetSimulcastId(VideoContentType* content_type, |
| 63 uint8_t simulcast_id) { |
| 64 // Store in bits 5-6. |
| 65 if (simulcast_id >= (1 << kSimulcastBitsSize)) |
| 66 return false; |
| 67 *content_type = static_cast<VideoContentType>( |
| 68 (static_cast<uint8_t>(*content_type) & ~kSimulcastBitsMask) | |
| 69 ((simulcast_id << kSimulcastShift) & kSimulcastBitsMask)); |
| 70 return true; |
| 71 } |
| 72 |
| 73 uint8_t GetExperimentId( |
| 74 const VideoContentType& content_type) { |
| 75 return (static_cast<uint8_t>(content_type) & kExperimentBitsMask) >> |
| 76 kExperimentShift; |
| 77 } |
| 78 uint8_t GetSimulcastId( |
| 79 const VideoContentType& content_type) { |
| 80 return (static_cast<uint8_t>(content_type) & kSimulcastBitsMask) >> |
| 81 kSimulcastShift; |
| 82 } |
| 83 |
| 84 bool IsScreenshare( |
| 85 const VideoContentType& content_type) { |
| 86 return (static_cast<uint8_t>(content_type) & kScreenshareBitsMask) > 0; |
| 87 } |
| 88 |
| 89 bool IsValidContentType(uint8_t value) { |
| 90 // Any 6-bit value is allowed. |
| 91 return value < (1 << kTotalBitsSize); |
| 92 } |
| 93 } // namespace videocontenttypehelpers |
| 94 } // namespace webrtc |
OLD | NEW |