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

Unified 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, 4 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698