Chromium Code Reviews| Index: webrtc/api/video/video_content_type.cc |
| diff --git a/webrtc/api/video/video_content_type.cc b/webrtc/api/video/video_content_type.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..17577e6f86328c14322a1860e42cbdbc382272ee |
| --- /dev/null |
| +++ b/webrtc/api/video/video_content_type.cc |
| @@ -0,0 +1,80 @@ |
| +/* |
| + * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#include "webrtc/api/video/video_content_type.h" |
| + |
| +// VideoContentType stored as a single byte, which is sent other the network. |
|
kwiberg-webrtc
2017/08/29 20:58:53
over
ilnik
2017/08/30 07:36:06
Done.
|
| +// Structure: |
| +// |
| +// 0 1 2 3 4 5 6 7 |
| +// +---------------+ |
| +// |r r e e e s s c| |
| +// |
| +// where: |
| +// r - reserved bits. |
| +// e - 3-bit number of an experiment group counted from 1. 0 means there's no |
| +// experiment ongoing. |
| +// s - 2-bit simulcast stream id or spatial layer, counted from 1. 0 means that |
| +// no simulcast information is set. |
| +// c - content type. 0 means real-time video, 1 means screenshare. |
| +// |
| +static const uint8_t kScreenshareBitsMask = 0x01; |
| + |
| +static const uint8_t kSimulcastShift = 1; |
| +static const uint8_t kSimulcastBitsMask = 0x06; // 0b00000110 |
| +static const uint8_t kSimulcastBitsSize = 2; |
| + |
| +static const uint8_t kExperimentShift = 3; |
| +static const uint8_t kExperimentBitsMask = 0x38; // 0b00111000 |
| +static const uint8_t kExperimentBitsSize = 3; |
|
kwiberg-webrtc
2017/08/29 20:58:53
constexpr?
Also, put these in a namespace. An unn
ilnik
2017/08/30 07:36:06
Done.
|
| + |
| +namespace webrtc { |
| +namespace VideoContentTypeHelpers { |
| + |
| +bool SetExperimentId(VideoContentType* content_type, uint8_t experiment_id) { |
| + // Store in bits 3-5. |
|
kwiberg-webrtc
2017/08/29 20:58:53
2-4
ilnik
2017/08/30 07:36:06
Done.
|
| + if (experiment_id >= (1 << kExperimentBitsSize)) |
| + return false; |
| + *content_type = static_cast<VideoContentType>( |
| + (static_cast<uint8_t>(*content_type) & ~kExperimentBitsMask) | |
| + ((experiment_id << kExperimentShift) & kExperimentBitsMask)); |
| + return true; |
| +} |
| + |
| +bool SetSimulcastId(VideoContentType* content_type, uint8_t simulcast_id) { |
| + // Store in bits 1-2. |
|
kwiberg-webrtc
2017/08/29 20:58:53
5-6
ilnik
2017/08/30 07:36:06
Done.
|
| + if (simulcast_id >= (1 << kSimulcastBitsSize)) |
| + return false; |
| + *content_type = static_cast<VideoContentType>( |
| + (static_cast<uint8_t>(*content_type) & ~kSimulcastBitsMask) | |
| + ((simulcast_id << kSimulcastShift) & kSimulcastBitsMask)); |
| + return true; |
| +} |
| + |
| +uint8_t GetExperimentId(const VideoContentType& content_type) { |
| + return (static_cast<uint8_t>(content_type) & kExperimentBitsMask) >> |
| + kExperimentShift; |
| +} |
| +uint8_t GetSimulcastId(const VideoContentType& content_type) { |
| + return (static_cast<uint8_t>(content_type) & kSimulcastBitsMask) >> |
| + kSimulcastShift; |
| +} |
| + |
| +bool IsScreenshare(const VideoContentType& content_type) { |
| + return (static_cast<uint8_t>(content_type) & kScreenshareBitsMask) > 0; |
| +} |
| + |
| +bool IsValidContentType(uint8_t value) { |
| + // Any 6-bit value is allowed. |
| + return value < (1 << 6); |
| +} |
| + |
| +} // namespace VideoContentTypeHelpers |
| +} // namespace webrtc |