Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(499)

Side by Side Diff: webrtc/api/video/video_content_type.cc

Issue 2986893002: Piggybacking simulcast id and ALR experiment id into video content type extension. (Closed)
Patch Set: Cleanup Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 other the network.
kwiberg-webrtc 2017/08/29 20:58:53 over
ilnik 2017/08/30 07:36:06 Done.
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;
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.
37
38 namespace webrtc {
39 namespace VideoContentTypeHelpers {
40
41 bool SetExperimentId(VideoContentType* content_type, uint8_t experiment_id) {
42 // Store in bits 3-5.
kwiberg-webrtc 2017/08/29 20:58:53 2-4
ilnik 2017/08/30 07:36:06 Done.
43 if (experiment_id >= (1 << kExperimentBitsSize))
44 return false;
45 *content_type = static_cast<VideoContentType>(
46 (static_cast<uint8_t>(*content_type) & ~kExperimentBitsMask) |
47 ((experiment_id << kExperimentShift) & kExperimentBitsMask));
48 return true;
49 }
50
51 bool SetSimulcastId(VideoContentType* content_type, uint8_t simulcast_id) {
52 // Store in bits 1-2.
kwiberg-webrtc 2017/08/29 20:58:53 5-6
ilnik 2017/08/30 07:36:06 Done.
53 if (simulcast_id >= (1 << kSimulcastBitsSize))
54 return false;
55 *content_type = static_cast<VideoContentType>(
56 (static_cast<uint8_t>(*content_type) & ~kSimulcastBitsMask) |
57 ((simulcast_id << kSimulcastShift) & kSimulcastBitsMask));
58 return true;
59 }
60
61 uint8_t GetExperimentId(const VideoContentType& content_type) {
62 return (static_cast<uint8_t>(content_type) & kExperimentBitsMask) >>
63 kExperimentShift;
64 }
65 uint8_t GetSimulcastId(const VideoContentType& content_type) {
66 return (static_cast<uint8_t>(content_type) & kSimulcastBitsMask) >>
67 kSimulcastShift;
68 }
69
70 bool IsScreenshare(const VideoContentType& content_type) {
71 return (static_cast<uint8_t>(content_type) & kScreenshareBitsMask) > 0;
72 }
73
74 bool IsValidContentType(uint8_t value) {
75 // Any 6-bit value is allowed.
76 return value < (1 << 6);
77 }
78
79 } // namespace VideoContentTypeHelpers
80 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698