2015-10-08 21:48:07 +00:00
|
|
|
// Copyright 2014 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.
|
|
|
|
|
2017-12-20 00:56:36 +00:00
|
|
|
#ifndef PACKAGER_MEDIA_FORMATS_WEBM_CLUSTER_BUILDER_H_
|
|
|
|
#define PACKAGER_MEDIA_FORMATS_WEBM_CLUSTER_BUILDER_H_
|
2015-10-08 21:48:07 +00:00
|
|
|
|
2015-10-14 22:46:23 +00:00
|
|
|
#include <stdint.h>
|
2022-12-17 05:40:00 +00:00
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2022-12-17 05:40:00 +00:00
|
|
|
#include "packager/macros.h"
|
2015-10-08 21:48:07 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2015-10-08 21:48:07 +00:00
|
|
|
namespace media {
|
|
|
|
|
|
|
|
class Cluster {
|
|
|
|
public:
|
2016-08-17 17:41:40 +00:00
|
|
|
Cluster(std::unique_ptr<uint8_t[]> data, int size);
|
2015-10-08 21:48:07 +00:00
|
|
|
~Cluster();
|
|
|
|
|
2015-10-14 22:46:23 +00:00
|
|
|
const uint8_t* data() const { return data_.get(); }
|
2015-10-08 21:48:07 +00:00
|
|
|
int size() const { return size_; }
|
|
|
|
|
|
|
|
private:
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<uint8_t[]> data_;
|
2015-10-08 21:48:07 +00:00
|
|
|
int size_;
|
|
|
|
|
|
|
|
DISALLOW_IMPLICIT_CONSTRUCTORS(Cluster);
|
|
|
|
};
|
|
|
|
|
|
|
|
class ClusterBuilder {
|
|
|
|
public:
|
|
|
|
ClusterBuilder();
|
|
|
|
~ClusterBuilder();
|
|
|
|
|
2015-10-14 22:46:23 +00:00
|
|
|
void SetClusterTimecode(int64_t cluster_timecode);
|
|
|
|
void AddSimpleBlock(int track_num,
|
|
|
|
int64_t timecode,
|
|
|
|
int flags,
|
|
|
|
const uint8_t* data,
|
|
|
|
int size);
|
|
|
|
void AddBlockGroup(int track_num,
|
|
|
|
int64_t timecode,
|
|
|
|
int duration,
|
|
|
|
int flags,
|
2016-07-29 23:06:20 +00:00
|
|
|
bool is_key_frame,
|
2015-10-14 22:46:23 +00:00
|
|
|
const uint8_t* data,
|
|
|
|
int size);
|
|
|
|
void AddBlockGroupWithoutBlockDuration(int track_num,
|
|
|
|
int64_t timecode,
|
|
|
|
int flags,
|
2016-07-29 23:06:20 +00:00
|
|
|
bool is_key_frame,
|
2015-10-14 22:46:23 +00:00
|
|
|
const uint8_t* data,
|
|
|
|
int size);
|
2015-10-08 21:48:07 +00:00
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<Cluster> Finish();
|
|
|
|
std::unique_ptr<Cluster> FinishWithUnknownSize();
|
2015-10-08 21:48:07 +00:00
|
|
|
|
|
|
|
private:
|
2015-10-14 22:46:23 +00:00
|
|
|
void AddBlockGroupInternal(int track_num,
|
|
|
|
int64_t timecode,
|
|
|
|
bool include_block_duration,
|
|
|
|
int duration,
|
|
|
|
int flags,
|
2016-07-29 23:06:20 +00:00
|
|
|
bool is_key_frame,
|
2015-10-14 22:46:23 +00:00
|
|
|
const uint8_t* data,
|
|
|
|
int size);
|
2015-10-08 21:48:07 +00:00
|
|
|
void Reset();
|
|
|
|
void ExtendBuffer(int bytes_needed);
|
2015-10-14 22:46:23 +00:00
|
|
|
void UpdateUInt64(int offset, int64_t value);
|
|
|
|
void WriteBlock(uint8_t* buf,
|
|
|
|
int track_num,
|
|
|
|
int64_t timecode,
|
|
|
|
int flags,
|
|
|
|
const uint8_t* data,
|
|
|
|
int size);
|
2015-10-08 21:48:07 +00:00
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<uint8_t[]> buffer_;
|
2015-10-08 21:48:07 +00:00
|
|
|
int buffer_size_;
|
|
|
|
int bytes_used_;
|
2015-10-14 22:46:23 +00:00
|
|
|
int64_t cluster_timecode_;
|
2015-10-08 21:48:07 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ClusterBuilder);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2015-10-08 21:48:07 +00:00
|
|
|
|
2017-12-20 00:56:36 +00:00
|
|
|
#endif // PACKAGER_MEDIA_FORMATS_WEBM_CLUSTER_BUILDER_H_
|