7 #ifndef MEDIA_BASE_MEDIA_SAMPLE_H_
8 #define MEDIA_BASE_MEDIA_SAMPLE_H_
15 #include "packager/base/logging.h"
16 #include "packager/media/base/decrypt_config.h"
29 static std::shared_ptr<MediaSample>
CopyFrom(
const uint8_t* data,
42 static std::shared_ptr<MediaSample>
CopyFrom(
const uint8_t* data,
44 const uint8_t* side_data,
45 size_t side_data_size,
58 static std::shared_ptr<MediaSample>
FromMetadata(
const uint8_t* metadata,
59 size_t metadata_size);
74 const uint8_t* side_data,
75 size_t side_data_size,
81 DCHECK(!end_of_stream());
85 void set_dts(int64_t dts) { dts_ = dts; }
88 DCHECK(!end_of_stream());
92 void set_pts(int64_t pts) { pts_ = pts; }
94 int64_t duration()
const {
95 DCHECK(!end_of_stream());
99 void set_duration(int64_t duration) {
100 DCHECK(!end_of_stream());
101 duration_ = duration;
104 bool is_key_frame()
const {
105 DCHECK(!end_of_stream());
106 return is_key_frame_;
109 bool is_encrypted()
const {
110 DCHECK(!end_of_stream());
111 return is_encrypted_;
113 const uint8_t* data()
const {
114 DCHECK(!end_of_stream());
118 uint8_t* writable_data() {
119 DCHECK(!end_of_stream());
123 size_t data_size()
const {
124 DCHECK(!end_of_stream());
128 const uint8_t* side_data()
const {
129 return side_data_.data();
132 size_t side_data_size()
const {
133 return side_data_.size();
137 return decrypt_config_.get();
140 void set_data(
const uint8_t* data,
const size_t data_size) {
141 data_.assign(data, data + data_size);
144 void resize_data(
const size_t data_size) {
145 data_.resize(data_size);
148 void set_is_key_frame(
bool value) {
149 is_key_frame_ = value;
152 void set_is_encrypted(
bool value) {
153 is_encrypted_ = value;
156 void set_decrypt_config(std::unique_ptr<DecryptConfig> decrypt_config) {
157 decrypt_config_ = std::move(decrypt_config);
161 bool end_of_stream()
const {
return data_.size() == 0; }
163 const std::string& config_id()
const {
return config_id_; }
164 void set_config_id(
const std::string& config_id) {
165 config_id_ = config_id;
182 std::vector<uint8_t> data_;
186 std::vector<uint8_t> side_data_;
190 std::string config_id_;
193 std::unique_ptr<DecryptConfig> decrypt_config_;
198 typedef std::deque<std::shared_ptr<MediaSample>> BufferQueue;
203 #endif // MEDIA_BASE_MEDIA_SAMPLE_H_