chromium/media/parsers/vp9_parser.cc

// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// This file contains an implementation of a VP9 bitstream parser.
//
// VERBOSE level:
//  1 something wrong in bitstream
//  2 parsing steps
//  3 parsed values (selected)

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "media/parsers/vp9_parser.h"

#include <algorithm>

#include "base/containers/circular_deque.h"
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/numerics/byte_conversions.h"
#include "base/numerics/safe_conversions.h"
#include "media/parsers/vp9_compressed_header_parser.h"
#include "media/parsers/vp9_uncompressed_header_parser.h"

namespace media {

namespace {

// Coefficients extracted verbatim from "VP9 Bitstream & Decoding Process
// Specification" Version 0.6, Sec 8.6.1 Dequantization functions, see:
// https://www.webmproject.org/vp9/#draft-vp9-bitstream-and-decoding-process-specification
constexpr size_t kQIndexRange =;
// clang-format off
// libva is the only user of high bit depth VP9 formats and only supports
// 10 bits per component, see https://github.com/01org/libva/issues/137.
// TODO(mcasas): Add the 12 bit versions of these tables.
const int16_t kDcQLookup[][kQIndexRange] =;

const int16_t kAcQLookup[][kQIndexRange] =;
// clang-format on

static_assert;

size_t ClampQ(int64_t q) {}

int ClampLf(int lf) {}

std::string IncrementIV(std::string_view iv, uint32_t by) {}

// |frame_size|: The size of the current frame; this controls how long we
//               loop through the subsamples.
// |current_subsample_index|: An index into the |subsamples| vector, we need
//                            to have this saved between function calls.
// |extra_clear_bytes|: The previous call may have set this variable to show
//                      that a subsample mey have already started being parsed
//                      and that only X bytes of free data are left in it.
// |base_decrypt_config|: Not an output parameter, it is just a raw ptr from a
//                        unique_ptr.
// |subsamples|: A vector of subsamples.
// |iv|: The initialization vector (128bit number stored as std::string). This
//       gets incremented by (cipher_bytes % 16) for each frame, and must be
//       preserved across function calls.
std::unique_ptr<DecryptConfig> SplitSubsamples(
    uint32_t frame_size,
    size_t* current_subsample_index,
    size_t* extra_clear_subsample_bytes,
    const DecryptConfig* base_decrypt_config,
    const std::vector<SubsampleEntry>& subsamples,
    std::string* iv) {}

bool IsByteNEncrypted(off_t byte,
                      const std::vector<SubsampleEntry>& subsamples) {}

}  // namespace

bool Vp9FrameHeader::IsKeyframe() const {}

bool Vp9FrameHeader::IsIntra() const {}

VideoColorSpace Vp9FrameHeader::GetColorSpace() const {}

Vp9Parser::FrameInfo::FrameInfo() = default;

Vp9Parser::FrameInfo::~FrameInfo() = default;

Vp9Parser::FrameInfo::FrameInfo(const uint8_t* ptr, off_t size)
    :{}

Vp9Parser::FrameInfo::FrameInfo(const FrameInfo& copy_from)
    :{}

Vp9Parser::FrameInfo& Vp9Parser::FrameInfo::operator=(
    const FrameInfo& copy_from) {}

bool Vp9FrameContext::IsValid() const {}

void Vp9Parser::Context::Reset() {}

const Vp9Parser::ReferenceSlot& Vp9Parser::Context::GetRefSlot(
    size_t ref_type) const {}

void Vp9Parser::Context::UpdateRefSlot(
    size_t ref_type,
    const Vp9Parser::ReferenceSlot& ref_slot) {}

Vp9Parser::Vp9Parser(bool parsing_compressed_header)
    :{}

Vp9Parser::~Vp9Parser() = default;

void Vp9Parser::SetStream(const uint8_t* stream,
                          off_t stream_size,
                          const std::vector<uint32_t>& spatial_layer_frame_size,
                          std::unique_ptr<DecryptConfig> stream_config) {}

void Vp9Parser::SetStream(const uint8_t* stream,
                          off_t stream_size,
                          std::unique_ptr<DecryptConfig> stream_config) {}

void Vp9Parser::Reset() {}

bool Vp9Parser::ParseUncompressedHeader(const FrameInfo& frame_info,
                                        Vp9FrameHeader* fhdr,
                                        Result* result,
                                        Vp9Parser::Context* context) {}

bool Vp9Parser::ParseCompressedHeader(const FrameInfo& frame_info,
                                      Result* result) {}

Vp9Parser::Result Vp9Parser::ParseNextFrame(
    Vp9FrameHeader* fhdr,
    gfx::Size* allocate_size,
    std::unique_ptr<DecryptConfig>* frame_decrypt_config) {}

std::unique_ptr<DecryptConfig> Vp9Parser::NextFrameDecryptContextForTesting() {}

std::string Vp9Parser::IncrementIVForTesting(std::string_view iv, uint32_t by) {}

// static
bool Vp9Parser::IsSuperframe(const uint8_t* stream,
                             off_t stream_size,
                             const DecryptConfig* decrypt_config) {}

// static
base::circular_deque<Vp9Parser::FrameInfo> Vp9Parser::ExtractFrames(
    const uint8_t* stream,
    off_t stream_size,
    const DecryptConfig* decrypt_config) {}

// Annex B Superframes
base::circular_deque<Vp9Parser::FrameInfo> Vp9Parser::ParseSuperframe() {}

base::circular_deque<Vp9Parser::FrameInfo> Vp9Parser::ParseSVCFrame() {}

// 8.6.1 Dequantization functions
int64_t Vp9Parser::GetQIndex(const Vp9QuantizationParams& quant,
                             size_t segid) const {}

// 8.6.1 Dequantization functions
bool Vp9Parser::SetupSegmentationDequant() {}

// 8.8.1 Loop filter frame init process
void Vp9Parser::SetupLoopFilter() {}

void Vp9Parser::UpdateSlots(Vp9Parser::Context* context) {}

}  // namespace media