chromium/media/formats/webm/webm_parser.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

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

#include "media/formats/webm/webm_parser.h"

// This file contains code to parse WebM file elements. It was created
// from information in the Matroska spec.
// http://www.matroska.org/technical/specs/index.html
//
// WebM Container Guidelines is at https://www.webmproject.org/docs/container/
// WebM Encryption spec is at: https://www.webmproject.org/docs/webm-encryption/

#include <stddef.h>

#include <algorithm>
#include <cstring>
#include <iomanip>
#include <limits>

#include "base/check_op.h"
#include "base/logging.h"
#include "base/memory/raw_ptr_exclusion.h"
#include "base/notreached.h"
#include "base/numerics/safe_conversions.h"
#include "media/formats/webm/webm_constants.h"

namespace media {

enum ElementType {};

struct ElementIdInfo {};

struct ListElementInfo {};

// The following are tables indicating what IDs are valid sub-elements of
// particular elements. If an element is encountered that doesn't appear in the
// list, a parsing error is signalled. Elements supported by Matroska but not
// supported by WebM are marked with SKIP_* types so that they will be skipped
// but will not fail the parser.

static const ElementIdInfo kEBMLHeaderIds[] =;

static const ElementIdInfo kSegmentIds[] =;

static const ElementIdInfo kSeekHeadIds[] =;

static const ElementIdInfo kSeekIds[] =;

static const ElementIdInfo kInfoIds[] =;

static const ElementIdInfo kChapterTranslateIds[] =;

static const ElementIdInfo kClusterIds[] =;

static const ElementIdInfo kSilentTracksIds[] =;

static const ElementIdInfo kBlockGroupIds[] =;

static const ElementIdInfo kBlockAdditionsIds[] =;

static const ElementIdInfo kBlockMoreIds[] =;

static const ElementIdInfo kSlicesIds[] =;

static const ElementIdInfo kTimeSliceIds[] =;

static const ElementIdInfo kTracksIds[] =;

static const ElementIdInfo kTrackEntryIds[] =;

static const ElementIdInfo kTrackTranslateIds[] =;

static const ElementIdInfo kVideoIds[] =;

static const ElementIdInfo kColourIds[] =;

static const ElementIdInfo kColorVolumeMetadataIds[] =;

static const ElementIdInfo kProjectionIds[]{};

static const ElementIdInfo kAudioIds[] =;

static const ElementIdInfo kTrackOperationIds[] =;

static const ElementIdInfo kTrackCombinePlanesIds[] =;

static const ElementIdInfo kTrackPlaneIds[] =;

static const ElementIdInfo kJoinBlocksIds[] =;

static const ElementIdInfo kContentEncodingsIds[] =;

static const ElementIdInfo kContentEncodingIds[] =;

static const ElementIdInfo kContentCompressionIds[] =;

static const ElementIdInfo kContentEncryptionIds[] =;

static const ElementIdInfo kContentEncAESSettingsIds[] =;

static const ElementIdInfo kCuesIds[] =;

static const ElementIdInfo kCuePointIds[] =;

static const ElementIdInfo kCueTrackPositionsIds[] =;

static const ElementIdInfo kCueReferenceIds[] =;

static const ElementIdInfo kAttachmentsIds[] =;

static const ElementIdInfo kAttachedFileIds[] =;

static const ElementIdInfo kChaptersIds[] =;

static const ElementIdInfo kEditionEntryIds[] =;

static const ElementIdInfo kChapterAtomIds[] =;

static const ElementIdInfo kChapterTrackIds[] =;

static const ElementIdInfo kChapterDisplayIds[] =;

static const ElementIdInfo kChapProcessIds[] =;

static const ElementIdInfo kChapProcessCommandIds[] =;

static const ElementIdInfo kTagsIds[] =;

static const ElementIdInfo kTagIds[] =;

static const ElementIdInfo kTargetsIds[] =;

static const ElementIdInfo kSimpleTagIds[] =;

#define LIST_ELEMENT_INFO(id, level, id_info)

static const ListElementInfo kListElementInfo[] =;

// Parses an element header id or size field. These fields are variable length
// encoded. The first byte indicates how many bytes the field occupies.
// |buf|  - The buffer to parse.
// |size| - The number of bytes in |buf|
// |max_bytes| - The maximum number of bytes the field can be. ID fields
//               set this to 4 & element size fields set this to 8. If the
//               first byte indicates a larger field size than this it is a
//               parser error.
// |mask_first_byte| - For element size fields the field length encoding bits
//                     need to be masked off. This parameter is true for
//                     element size fields and is false for ID field values.
//
// Returns: The number of bytes parsed on success. -1 on error.
static int ParseWebMElementHeaderField(const uint8_t* buf,
                                       int size,
                                       int max_bytes,
                                       bool mask_first_byte,
                                       int64_t* num) {}

int WebMParseElementHeader(const uint8_t* buf,
                           int size,
                           int* id,
                           int64_t* element_size) {}

// Finds ElementType for a specific ID.
static ElementType FindIdType(int id,
                              const ElementIdInfo* id_info,
                              int id_info_count) {}

// Finds ListElementInfo for a specific ID.
static const ListElementInfo* FindListInfo(int id) {}

static int FindListLevel(int id) {}

static int ParseUInt(const uint8_t* buf,
                     int size,
                     int id,
                     WebMParserClient* client) {}

static int ParseFloat(const uint8_t* buf,
                      int size,
                      int id,
                      WebMParserClient* client) {}

static int ParseBinary(const uint8_t* buf,
                       int size,
                       int id,
                       WebMParserClient* client) {}

static int ParseString(const uint8_t* buf,
                       int size,
                       int id,
                       WebMParserClient* client) {}

static int ParseNonListElement(ElementType type,
                               int id,
                               int64_t element_size,
                               const uint8_t* buf,
                               int size,
                               WebMParserClient* client) {}

WebMParserClient::WebMParserClient() = default;
WebMParserClient::~WebMParserClient() = default;

WebMParserClient* WebMParserClient::OnListStart(int id) {}

bool WebMParserClient::OnListEnd(int id) {}

bool WebMParserClient::OnUInt(int id, int64_t val) {}

bool WebMParserClient::OnFloat(int id, double val) {}

bool WebMParserClient::OnBinary(int id, const uint8_t* data, int size) {}

bool WebMParserClient::OnString(int id, const std::string& str) {}

WebMListParser::WebMListParser(int id, WebMParserClient* client)
    :{}

WebMListParser::~WebMListParser() = default;

void WebMListParser::Reset() {}

int WebMListParser::Parse(const uint8_t* buf, int size) {}

bool WebMListParser::IsParsingComplete() const {}

void WebMListParser::ChangeState(State new_state) {}

int WebMListParser::ParseListElement(int header_size,
                                     int id,
                                     int64_t element_size,
                                     const uint8_t* data,
                                     int size) {}

bool WebMListParser::OnListStart(int id, int64_t size) {}

bool WebMListParser::OnListEnd() {}

bool WebMListParser::IsSiblingOrAncestor(int id_a, int id_b) const {}

}  // namespace media