#include "common_video/h264/sps_vui_rewriter.h"
#include <string.h>
#include <algorithm>
#include <cstdint>
#include <vector>
#include "api/video/color_space.h"
#include "common_video/h264/h264_common.h"
#include "common_video/h264/sps_parser.h"
#include "rtc_base/bit_buffer.h"
#include "rtc_base/bitstream_reader.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "system_wrappers/include/metrics.h"
namespace webrtc {
namespace {
const size_t kMaxVuiSpsIncrease = …;
const char* kSpsValidHistogramName = …;
enum SpsValidEvent { … };
#define RETURN_FALSE_ON_FAIL(x) …
uint8_t CopyUInt8(BitstreamReader& source, rtc::BitBufferWriter& destination) { … }
uint32_t CopyExpGolomb(BitstreamReader& source,
rtc::BitBufferWriter& destination) { … }
uint32_t CopyBits(int bits,
BitstreamReader& source,
rtc::BitBufferWriter& destination) { … }
bool CopyAndRewriteVui(const SpsParser::SpsState& sps,
BitstreamReader& source,
rtc::BitBufferWriter& destination,
const webrtc::ColorSpace* color_space,
SpsVuiRewriter::ParseResult& out_vui_rewritten);
void CopyHrdParameters(BitstreamReader& source,
rtc::BitBufferWriter& destination);
bool AddBitstreamRestriction(rtc::BitBufferWriter* destination,
uint32_t max_num_ref_frames);
bool IsDefaultColorSpace(const ColorSpace& color_space);
bool AddVideoSignalTypeInfo(rtc::BitBufferWriter& destination,
const ColorSpace& color_space);
bool CopyOrRewriteVideoSignalTypeInfo(
BitstreamReader& source,
rtc::BitBufferWriter& destination,
const ColorSpace* color_space,
SpsVuiRewriter::ParseResult& out_vui_rewritten);
bool CopyRemainingBits(BitstreamReader& source,
rtc::BitBufferWriter& destination);
}
void SpsVuiRewriter::UpdateStats(ParseResult result, Direction direction) { … }
SpsVuiRewriter::ParseResult SpsVuiRewriter::ParseAndRewriteSps(
rtc::ArrayView<const uint8_t> buffer,
absl::optional<SpsParser::SpsState>* sps,
const webrtc::ColorSpace* color_space,
rtc::Buffer* destination) { … }
SpsVuiRewriter::ParseResult SpsVuiRewriter::ParseAndRewriteSps(
rtc::ArrayView<const uint8_t> buffer,
absl::optional<SpsParser::SpsState>* sps,
const webrtc::ColorSpace* color_space,
rtc::Buffer* destination,
Direction direction) { … }
rtc::Buffer SpsVuiRewriter::ParseOutgoingBitstreamAndRewrite(
rtc::ArrayView<const uint8_t> buffer,
const webrtc::ColorSpace* color_space) { … }
namespace {
bool CopyAndRewriteVui(const SpsParser::SpsState& sps,
BitstreamReader& source,
rtc::BitBufferWriter& destination,
const webrtc::ColorSpace* color_space,
SpsVuiRewriter::ParseResult& out_vui_rewritten) { … }
void CopyHrdParameters(BitstreamReader& source,
rtc::BitBufferWriter& destination) { … }
bool AddBitstreamRestriction(rtc::BitBufferWriter* destination,
uint32_t max_num_ref_frames) { … }
bool IsDefaultColorSpace(const ColorSpace& color_space) { … }
bool AddVideoSignalTypeInfo(rtc::BitBufferWriter& destination,
const ColorSpace& color_space) { … }
bool CopyOrRewriteVideoSignalTypeInfo(
BitstreamReader& source,
rtc::BitBufferWriter& destination,
const ColorSpace* color_space,
SpsVuiRewriter::ParseResult& out_vui_rewritten) { … }
bool CopyRemainingBits(BitstreamReader& source,
rtc::BitBufferWriter& destination) { … }
}
}