blob: aa9ddaea902a86b7fa22a5d33ba18d39a17b51d0 [file] [log] [blame]
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <vector>
#include "base/memory/scoped_ptr.h"
#include "cobalt/media/base/media_export.h"
#include "cobalt/media/base/video_codecs.h"
#include "cobalt/media/formats/mp4/bitstream_converter.h"
#include "cobalt/media/formats/mp4/box_definitions.h"
#include "starboard/types.h"
namespace cobalt {
namespace media {
struct SubsampleEntry;
namespace mp4 {
struct MEDIA_EXPORT HEVCDecoderConfigurationRecord : Box {
// Parses HEVCDecoderConfigurationRecord data encoded in |data|.
// Note: This method is intended to parse data outside the MP4StreamParser
// context and therefore the box header is not expected to be present
// in |data|.
// Returns true if |data| was successfully parsed.
bool Parse(const uint8_t* data, int data_size);
uint8_t configurationVersion;
uint8_t general_profile_space;
uint8_t general_tier_flag;
uint8_t general_profile_idc;
uint32_t general_profile_compatibility_flags;
uint64_t general_constraint_indicator_flags;
uint8_t general_level_idc;
uint16_t min_spatial_segmentation_idc;
uint8_t parallelismType;
uint8_t chromaFormat;
uint8_t bitDepthLumaMinus8;
uint8_t bitDepthChromaMinus8;
uint16_t avgFrameRate;
uint8_t constantFrameRate;
uint8_t numTemporalLayers;
uint8_t temporalIdNested;
uint8_t lengthSizeMinusOne;
uint8_t numOfArrays;
typedef std::vector<uint8_t> HVCCNALUnit;
struct HVCCNALArray {
HVCCNALArray(const HVCCNALArray& other);
uint8_t first_byte;
std::vector<HVCCNALUnit> units;
std::vector<HVCCNALArray> arrays;
VideoCodecProfile GetVideoProfile() const;
bool ParseInternal(BufferReader* reader,
const scoped_refptr<MediaLog>& media_log);
static bool ConvertConfigToAnnexB(
const HEVCDecoderConfigurationRecord& hevc_config,
std::vector<uint8_t>* buffer);
static bool InsertParamSetsAnnexB(
const HEVCDecoderConfigurationRecord& hevc_config,
std::vector<uint8_t>* buffer, std::vector<SubsampleEntry>* subsamples);
// Verifies that the contents of |buffer| conform to
// Section of ISO/IEC 23008-2.
// |subsamples| contains the information about what parts of the buffer are
// encrypted and which parts are clear.
// Returns true if |buffer| contains conformant Annex B data
// TODO(servolk): Remove the std::vector version when we can use,
// C++11's std::vector<T>::data() method.
static bool IsValidAnnexB(const std::vector<uint8_t>& buffer,
const std::vector<SubsampleEntry>& subsamples);
static bool IsValidAnnexB(const uint8_t* buffer, size_t size,
const std::vector<SubsampleEntry>& subsamples);
class HEVCBitstreamConverter : public BitstreamConverter {
explicit HEVCBitstreamConverter(
scoped_ptr<HEVCDecoderConfigurationRecord> hevc_config);
// BitstreamConverter interface
bool ConvertFrame(std::vector<uint8_t>* frame_buf, bool is_keyframe,
std::vector<SubsampleEntry>* subsamples) const OVERRIDE;
~HEVCBitstreamConverter() OVERRIDE;
scoped_ptr<HEVCDecoderConfigurationRecord> hevc_config_;
} // namespace mp4
} // namespace media
} // namespace cobalt