chromium/third_party/libgav1/src/src/obu_parser.cc

// Copyright 2019 The libgav1 Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "src/obu_parser.h"

#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <memory>

#include "src/buffer_pool.h"
#include "src/decoder_impl.h"
#include "src/motion_vector.h"
#include "src/utils/common.h"
#include "src/utils/logging.h"

namespace libgav1 {
namespace {

// 5.9.16.
// Find the smallest value of k such that block_size << k is greater than or
// equal to target.
//
// NOTE: TileLog2(block_size, target) is equal to
//   CeilLog2(ceil((double)target / block_size))
// where the division is a floating-point number division. (This equality holds
// even when |target| is equal to 0.) In the special case of block_size == 1,
// TileLog2(1, target) is equal to CeilLog2(target).
int TileLog2(int block_size, int target) {}

void ParseBitStreamLevel(BitStreamLevel* const level, uint8_t level_bits) {}

// This function assumes loop_filter is zero-initialized, so only it needs to
// set the nonzero default values.
void SetDefaultRefDeltas(LoopFilter* const loop_filter) {}

bool InTemporalLayer(int operating_point_idc, int temporal_id) {}

bool InSpatialLayer(int operating_point_idc, int spatial_id) {}

// Returns the index of the last nonzero byte in the |data| buffer of |size|
// bytes. If there is no nonzero byte in the |data| buffer, returns -1.
int GetLastNonzeroByteIndex(const uint8_t* data, size_t size) {}

// A cleanup helper class that releases the frame buffer reference held in
// |frame| in the destructor.
class RefCountedBufferPtrCleanup {};

}  // namespace

bool ObuSequenceHeader::ParametersChanged(const ObuSequenceHeader& old) const {}

// Macros to avoid repeated error checks in the parser code.
#define OBU_LOG_AND_RETURN_FALSE
#define OBU_PARSER_FAIL
#define OBU_READ_BIT_OR_FAIL
#define OBU_READ_LITERAL_OR_FAIL
#define OBU_READ_UVLC_OR_FAIL

bool ObuParser::ParseColorConfig(ObuSequenceHeader* sequence_header) {}

bool ObuParser::ParseTimingInfo(ObuSequenceHeader* sequence_header) {}

bool ObuParser::ParseDecoderModelInfo(ObuSequenceHeader* sequence_header) {}

bool ObuParser::ParseOperatingParameters(ObuSequenceHeader* sequence_header,
                                         int index) {}

bool ObuParser::ParseSequenceHeader(bool seen_frame_header) {}

// Marks reference frames as invalid for referencing when they are too far in
// the past to be referenced by the frame id mechanism.
void ObuParser::MarkInvalidReferenceFrames() {}

bool ObuParser::ParseFrameSizeAndRenderSize() {}

bool ObuParser::ParseSuperResParametersAndComputeImageSize() {}

bool ObuParser::ValidateInterFrameSize() const {}

bool ObuParser::ParseReferenceOrderHint() {}

// static
int ObuParser::FindLatestBackwardReference(
    const int current_frame_hint,
    const std::array<int, kNumReferenceFrameTypes>& shifted_order_hints,
    const std::array<bool, kNumReferenceFrameTypes>& used_frame) {}

// static
int ObuParser::FindEarliestBackwardReference(
    const int current_frame_hint,
    const std::array<int, kNumReferenceFrameTypes>& shifted_order_hints,
    const std::array<bool, kNumReferenceFrameTypes>& used_frame) {}

// static
int ObuParser::FindLatestForwardReference(
    const int current_frame_hint,
    const std::array<int, kNumReferenceFrameTypes>& shifted_order_hints,
    const std::array<bool, kNumReferenceFrameTypes>& used_frame) {}

// static
int ObuParser::FindReferenceWithSmallestOutputOrder(
    const std::array<int, kNumReferenceFrameTypes>& shifted_order_hints) {}

// Computes the elements in the frame_header_.reference_frame_index array
// based on:
// * the syntax elements last_frame_idx and gold_frame_idx, and
// * the values stored within the decoder_state_.reference_order_hint array
//   (these values represent the least significant bits of the expected output
//   order of the frames).
//
// Frame type: {
//       libgav1_name              spec_name              int
//   kReferenceFrameLast,          LAST_FRAME              1
//   kReferenceFrameLast2,         LAST2_FRAME             2
//   kReferenceFrameLast3,         LAST3_FRAME             3
//   kReferenceFrameGolden,        GOLDEN_FRAME            4
//   kReferenceFrameBackward,      BWDREF_FRAME            5
//   kReferenceFrameAlternate2,    ALTREF2_FRAME           6
//   kReferenceFrameAlternate,     ALTREF_FRAME            7
// }
//
// A typical case of a group of pictures (frames) in display order:
// (However, more complex cases are possibly allowed in terms of
// bitstream conformance.)
//
// |         |         |         |         |         |         |         |
// |         |         |         |         |         |         |         |
// |         |         |         |         |         |         |         |
// |         |         |         |         |         |         |         |
//
// 4         3         2         1   current_frame   5         6         7
//
bool ObuParser::SetFrameReferences(const int8_t last_frame_idx,
                                   const int8_t gold_frame_idx) {}

bool ObuParser::ParseLoopFilterParameters() {}

bool ObuParser::ParseDeltaQuantizer(int8_t* const delta) {}

bool ObuParser::ParseQuantizerParameters() {}

// This method implements the following functions in the spec:
// - segmentation_params()
// - part of setup_past_independence(): Set the FeatureData and FeatureEnabled
//   arrays to all 0.
// - part of load_previous(): Call load_segmentation_params().
//
// A careful analysis of the spec shows the part of setup_past_independence()
// can be optimized away and the part of load_previous() only needs to be
// invoked under a specific condition. Although the logic looks different from
// the spec, it is equivalent and more efficient.
bool ObuParser::ParseSegmentationParameters() {}

bool ObuParser::ParseQuantizerIndexDeltaParameters() {}

bool ObuParser::ParseLoopFilterDeltaParameters() {}

void ObuParser::ComputeSegmentLosslessAndQIndex() {}

bool ObuParser::ParseCdefParameters() {}

bool ObuParser::ParseLoopRestorationParameters() {}

bool ObuParser::ParseTxModeSyntax() {}

bool ObuParser::ParseFrameReferenceModeSyntax() {}

bool ObuParser::IsSkipModeAllowed() {}

bool ObuParser::ParseSkipModeParameters() {}

// Sets frame_header_.global_motion[ref].params[index].
bool ObuParser::ParseGlobalParamSyntax(
    int ref, int index,
    const std::array<GlobalMotion, kNumReferenceFrameTypes>&
        prev_global_motions) {}

bool ObuParser::ParseGlobalMotionParameters() {}

bool ObuParser::ParseFilmGrainParameters() {}

bool ObuParser::ParseTileInfoSyntax() {}

bool ObuParser::ReadAllowWarpedMotion() {}

bool ObuParser::ParseFrameParameters() {}

bool ObuParser::ParseFrameHeader() {}

bool ObuParser::ParsePadding(const uint8_t* data, size_t size) {}

bool ObuParser::ParseMetadataScalability() {}

bool ObuParser::ParseMetadataTimecode() {}

bool ObuParser::ParseMetadata(const uint8_t* data, size_t size) {}

bool ObuParser::AddTileBuffers(int start, int end, size_t total_size,
                               size_t tg_header_size,
                               size_t bytes_consumed_so_far) {}

bool ObuParser::ParseTileGroup(size_t size, size_t bytes_consumed_so_far) {}

bool ObuParser::ParseHeader() {}

#undef OBU_READ_UVLC_OR_FAIL
#undef OBU_READ_LITERAL_OR_FAIL
#undef OBU_READ_BIT_OR_FAIL
#undef OBU_PARSER_FAIL
#undef OBU_LOG_AND_RETURN_FALSE

bool ObuParser::InitBitReader(const uint8_t* const data, size_t size) {}

bool ObuParser::EnsureCurrentFrameIsNotNull() {}

bool ObuParser::HasData() const {}

StatusCode ObuParser::ParseOneFrame(RefCountedBufferPtr* const current_frame) {}

// AV1CodecConfigurationBox specification:
// https://aomediacodec.github.io/av1-isobmff/#av1codecconfigurationbox.
// static
std::unique_ptr<uint8_t[]> ObuParser::GetAV1CodecConfigurationBox(
    const uint8_t* data, size_t size, size_t* const av1c_size) {}

// static
StatusCode ObuParser::ParseBasicStreamInfo(const uint8_t* data, size_t size,
                                           ObuSequenceHeader* sequence_header,
                                           size_t* sequence_header_offset,
                                           size_t* sequence_header_size) {}

}  // namespace libgav1