Sergio Garcia Murillo | 43800f9 | 2018-06-21 16:16:38 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 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 "modules/video_coding/utility/simulcast_utility.h" |
| 12 | |
| 13 | namespace webrtc { |
| 14 | |
| 15 | uint32_t SimulcastUtility::SumStreamMaxBitrate(int streams, |
| 16 | const VideoCodec& codec) { |
| 17 | uint32_t bitrate_sum = 0; |
| 18 | for (int i = 0; i < streams; ++i) { |
| 19 | bitrate_sum += codec.simulcastStream[i].maxBitrate; |
| 20 | } |
| 21 | return bitrate_sum; |
| 22 | } |
| 23 | |
| 24 | int SimulcastUtility::NumberOfSimulcastStreams(const VideoCodec& codec) { |
| 25 | int streams = |
| 26 | codec.numberOfSimulcastStreams < 1 ? 1 : codec.numberOfSimulcastStreams; |
| 27 | uint32_t simulcast_max_bitrate = SumStreamMaxBitrate(streams, codec); |
| 28 | if (simulcast_max_bitrate == 0) { |
| 29 | streams = 1; |
| 30 | } |
| 31 | return streams; |
| 32 | } |
| 33 | |
| 34 | bool SimulcastUtility::ValidSimulcastResolutions(const VideoCodec& codec, |
| 35 | int num_streams) { |
| 36 | if (codec.width != codec.simulcastStream[num_streams - 1].width || |
| 37 | codec.height != codec.simulcastStream[num_streams - 1].height) { |
| 38 | return false; |
| 39 | } |
| 40 | for (int i = 0; i < num_streams; ++i) { |
| 41 | if (codec.width * codec.simulcastStream[i].height != |
| 42 | codec.height * codec.simulcastStream[i].width) { |
| 43 | return false; |
| 44 | } |
| 45 | } |
| 46 | for (int i = 1; i < num_streams; ++i) { |
| 47 | if (codec.simulcastStream[i].width != |
| 48 | codec.simulcastStream[i - 1].width * 2) { |
| 49 | return false; |
| 50 | } |
| 51 | } |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | bool SimulcastUtility::ValidSimulcastTemporalLayers(const VideoCodec& codec, |
| 56 | int num_streams) { |
| 57 | for (int i = 0; i < num_streams - 1; ++i) { |
| 58 | if (codec.simulcastStream[i].numberOfTemporalLayers != |
| 59 | codec.simulcastStream[i + 1].numberOfTemporalLayers) |
| 60 | return false; |
| 61 | } |
| 62 | return true; |
| 63 | } |
| 64 | |
| 65 | } // namespace webrtc |