| 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..349a69f59196d1cefa4a6496fdb58362ea544f48
|
| --- /dev/null
|
| +++ b/webrtc/api/video/video_content_type.cc
|
| @@ -0,0 +1,100 @@
|
| +/*
|
| + * 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 stores a single byte, which is sent other the network.
|
| +// 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;
|
| +
|
| +namespace webrtc {
|
| +
|
| +// static
|
| +VideoContentType VideoContentType::Unspecified() {
|
| + return VideoContentType({0});
|
| +}
|
| +// static
|
| +VideoContentType VideoContentType::Screenshare() {
|
| + return VideoContentType({1});
|
| +}
|
| +
|
| +VideoContentType::operator uint8_t() const {
|
| + return content_type;
|
| +}
|
| +
|
| +uint8_t VideoContentType::operator=(uint8_t value) {
|
| + content_type = value;
|
| + return value;
|
| +}
|
| +
|
| +bool VideoContentType::operator==(const VideoContentType& other) {
|
| + return content_type == other.content_type;
|
| +}
|
| +
|
| +bool VideoContentType::operator==(uint8_t value) {
|
| + return content_type == value;
|
| +}
|
| +
|
| +bool VideoContentType::SetExperimentId(uint8_t experiment_id) {
|
| + // Store in bits 3-5.
|
| + if (experiment_id >= (1 << kExperimentBitsSize))
|
| + return false;
|
| + content_type = (content_type & ~kExperimentBitsMask) |
|
| + ((experiment_id << kExperimentShift) & kExperimentBitsMask);
|
| + return true;
|
| +}
|
| +
|
| +bool VideoContentType::SetSimulcastId(uint8_t simulcast_id) {
|
| + // Store in bits 1-2.
|
| + if (simulcast_id >= (1 << kSimulcastBitsSize))
|
| + return false;
|
| + content_type = (content_type & ~kSimulcastBitsMask) |
|
| + ((simulcast_id << kSimulcastShift) & kSimulcastBitsMask);
|
| + return true;
|
| +}
|
| +
|
| +uint8_t VideoContentType::GetExperimentId() const {
|
| + return (content_type & kExperimentBitsMask) >> kExperimentShift;
|
| +}
|
| +
|
| +uint8_t VideoContentType::GetSimulcastId() const {
|
| + return (content_type & kSimulcastBitsMask) >> kSimulcastShift;
|
| +}
|
| +
|
| +bool VideoContentType::IsValidContentType(uint8_t value) {
|
| + // Any 6-bit value is allowed.
|
| + return value < (1 << 6);
|
| +}
|
| +
|
| +bool VideoContentType::IsScreenshare() const {
|
| + return (content_type & kScreenshareBitsMask) > 0;
|
| +}
|
| +} // namespace webrtc
|
|
|