This reverts commit c2406e4eaf7703c6c64d21318186adda791e09fd. Reason for revert: Reland by removing the conflict with the broken CL. Original change's description: > Revert "Move allocation and rtp conversion logic out of payload router." > > This reverts commit 1da4d79ba3275b3fa48cad3b2c0949e0d3b7afe7. > > Reason for revert: Need to revert https://webrtc-review.googlesource.com/c/src/+/88220 > > This causes a merge conflict. So need to revert this first. > > Original change's description: > > Move allocation and rtp conversion logic out of payload router. > > > > Makes it easier to write tests, and allows for moving rtp module > > ownership into the payload router in the future. > > > > The RtpPayloadParams class is split into declaration and definition and > > moved into separate files. > > > > Bug: webrtc:9517 > > Change-Id: I8700628edff19abcacfe8d3a20e4ba7476f712ad > > Reviewed-on: https://webrtc-review.googlesource.com/88564 > > Commit-Queue: Stefan Holmer <stefan@webrtc.org> > > Reviewed-by: Sebastian Jansson <srte@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#23983} > > TBR=sprang@webrtc.org,stefan@webrtc.org,srte@webrtc.org > > Change-Id: I342c4bf483d975c87c706fe7f76f44e2dc60fe4c > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:9517 > Reviewed-on: https://webrtc-review.googlesource.com/88821 > Reviewed-by: JT Teh <jtteh@webrtc.org> > Commit-Queue: JT Teh <jtteh@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#23991} TBR=sprang@webrtc.org,stefan@webrtc.org,srte@webrtc.org,lliuu@webrtc.org,jtteh@webrtc.org,tkchin@webrtc.org Change-Id: I154145cdbc668feee86dbe78860147a6954fee6c No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: webrtc:9517 Reviewed-on: https://webrtc-review.googlesource.com/89020 Commit-Queue: Stefan Holmer <stefan@webrtc.org> Reviewed-by: Stefan Holmer <stefan@webrtc.org> Cr-Commit-Position: refs/heads/master@{#23996}
92 lines
3.3 KiB
C++
92 lines
3.3 KiB
C++
/*
|
|
* Copyright (c) 2018 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.
|
|
*/
|
|
|
|
#ifndef API_VIDEO_VIDEO_BITRATE_ALLOCATION_H_
|
|
#define API_VIDEO_VIDEO_BITRATE_ALLOCATION_H_
|
|
|
|
#include <limits>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "absl/types/optional.h"
|
|
#include "typedefs.h" // NOLINT(build/include)
|
|
|
|
namespace webrtc {
|
|
|
|
// TODO(sprang): Move back to common_types when include of this is removed.
|
|
enum : int { kMaxSimulcastStreams = 4 };
|
|
enum : int { kMaxSpatialLayers = 5 };
|
|
enum : int { kMaxTemporalStreams = 4 };
|
|
|
|
// Class that describes how video bitrate, in bps, is allocated across temporal
|
|
// and spatial layers. Not that bitrates are NOT cumulative. Depending on if
|
|
// layers are dependent or not, it is up to the user to aggregate.
|
|
// For each index, the bitrate can also both set and unset. This is used with a
|
|
// set bps = 0 to signal an explicit "turn off" signal.
|
|
class VideoBitrateAllocation {
|
|
public:
|
|
static constexpr uint32_t kMaxBitrateBps =
|
|
std::numeric_limits<uint32_t>::max();
|
|
VideoBitrateAllocation();
|
|
|
|
bool SetBitrate(size_t spatial_index,
|
|
size_t temporal_index,
|
|
uint32_t bitrate_bps);
|
|
|
|
bool HasBitrate(size_t spatial_index, size_t temporal_index) const;
|
|
|
|
uint32_t GetBitrate(size_t spatial_index, size_t temporal_index) const;
|
|
|
|
// Whether the specific spatial layers has the bitrate set in any of its
|
|
// temporal layers.
|
|
bool IsSpatialLayerUsed(size_t spatial_index) const;
|
|
|
|
// Get the sum of all the temporal layer for a specific spatial layer.
|
|
uint32_t GetSpatialLayerSum(size_t spatial_index) const;
|
|
|
|
// Sum of bitrates of temporal layers, from layer 0 to |temporal_index|
|
|
// inclusive, of specified spatial layer |spatial_index|. Bitrates of lower
|
|
// spatial layers are not included.
|
|
uint32_t GetTemporalLayerSum(size_t spatial_index,
|
|
size_t temporal_index) const;
|
|
|
|
// Returns a vector of the temporal layer bitrates for the specific spatial
|
|
// layer. Length of the returned vector is cropped to the highest temporal
|
|
// layer with a defined bitrate.
|
|
std::vector<uint32_t> GetTemporalLayerAllocation(size_t spatial_index) const;
|
|
|
|
// Returns one VideoBitrateAllocation for each spatial layer. This is used to
|
|
// configure simulcast streams. Note that the length of the returned vector is
|
|
// always kMaxSpatialLayers, the optional is unset for unused layers.
|
|
std::vector<absl::optional<VideoBitrateAllocation>> GetSimulcastAllocations()
|
|
const;
|
|
|
|
uint32_t get_sum_bps() const { return sum_; } // Sum of all bitrates.
|
|
uint32_t get_sum_kbps() const {
|
|
// Round down to not exceed the allocated bitrate.
|
|
return sum_ / 1000;
|
|
}
|
|
|
|
bool operator==(const VideoBitrateAllocation& other) const;
|
|
inline bool operator!=(const VideoBitrateAllocation& other) const {
|
|
return !(*this == other);
|
|
}
|
|
|
|
std::string ToString() const;
|
|
|
|
private:
|
|
uint32_t sum_;
|
|
absl::optional<uint32_t> bitrates_[kMaxSpatialLayers][kMaxTemporalStreams];
|
|
};
|
|
|
|
} // namespace webrtc
|
|
|
|
#endif // API_VIDEO_VIDEO_BITRATE_ALLOCATION_H_
|