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 stores a single byte, which is sent other 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 static const uint8_t kScreenshareBitsMask = 0x01; | |
29 | |
30 static const uint8_t kSimulcastShift = 1; | |
31 static const uint8_t kSimulcastBitsMask = 0x06; // 0b00000110 | |
32 static const uint8_t kSimulcastBitsSize = 2; | |
33 | |
34 static const uint8_t kExperimentShift = 3; | |
35 static const uint8_t kExperimentBitsMask = 0x38; // 0b00111000 | |
36 static const uint8_t kExperimentBitsSize = 3; | |
37 | |
38 namespace webrtc { | |
39 const VideoContentType VideoContentType::UNSPECIFIED = VideoContentType({0}); | |
tommi
2017/08/29 09:25:45
if for some reason we can't use enum, can we use c
ilnik
2017/08/29 10:26:14
Done. However, it's not constexpr in the .h file,
| |
40 const VideoContentType VideoContentType::SCREENSHARE = VideoContentType({1}); | |
41 | |
42 VideoContentType::operator uint8_t() const { | |
43 return content_type; | |
44 } | |
45 | |
46 uint8_t VideoContentType::operator=(uint8_t value) { | |
47 content_type = value; | |
48 return value; | |
49 } | |
50 | |
51 bool VideoContentType::operator==(const VideoContentType& other) { | |
52 return content_type == other.content_type; | |
53 } | |
54 | |
55 bool VideoContentType::operator==(uint8_t value) { | |
56 return content_type == value; | |
57 } | |
58 | |
59 bool VideoContentType::SetExperimentId(uint8_t experiment_id) { | |
60 // Store in bits 3-5. | |
61 if (experiment_id >= (1 << kExperimentBitsSize)) | |
62 return false; | |
63 content_type = (content_type & ~kExperimentBitsMask) | | |
64 ((experiment_id << kExperimentShift) & kExperimentBitsMask); | |
65 return true; | |
66 } | |
67 | |
68 bool VideoContentType::SetSimulcastId(uint8_t simulcast_id) { | |
69 // Store in bits 1-2. | |
70 if (simulcast_id >= (1 << kSimulcastBitsSize)) | |
71 return false; | |
72 content_type = (content_type & ~kSimulcastBitsMask) | | |
73 ((simulcast_id << kSimulcastShift) & kSimulcastBitsMask); | |
74 return true; | |
75 } | |
76 | |
77 uint8_t VideoContentType::GetExperimentId() const { | |
78 return (content_type & kExperimentBitsMask) >> kExperimentShift; | |
79 } | |
80 | |
81 uint8_t VideoContentType::GetSimulcastId() const { | |
82 return (content_type & kSimulcastBitsMask) >> kSimulcastShift; | |
83 } | |
84 | |
85 bool VideoContentType::IsValidContentType(uint8_t value) { | |
86 // Any 6-bit value is allowed. | |
87 return value < (1 << 6); | |
88 } | |
89 | |
90 bool VideoContentType::IsScreenshare() const { | |
91 return (content_type & kScreenshareBitsMask) > 0; | |
92 } | |
93 } // namespace webrtc | |
OLD | NEW |