7 #ifndef MEDIA_BASE_MEDIA_SAMPLE_H_
8 #define MEDIA_BASE_MEDIA_SAMPLE_H_
14 #include "packager/base/logging.h"
15 #include "packager/base/memory/ref_counted.h"
16 #include "packager/media/base/decrypt_config.h"
22 class MediaSample :
public base::RefCountedThreadSafe<MediaSample> {
29 static scoped_refptr<MediaSample>
CopyFrom(
const uint8_t* data,
42 static scoped_refptr<MediaSample>
CopyFrom(
const uint8_t* data,
44 const uint8_t* side_data,
45 size_t side_data_size,
54 static scoped_refptr<MediaSample>
FromMetadata(
const uint8_t* metadata,
55 size_t metadata_size);
66 DCHECK(!end_of_stream());
70 void set_dts(int64_t dts) { dts_ = dts; }
73 DCHECK(!end_of_stream());
77 void set_pts(int64_t pts) { pts_ = pts; }
79 int64_t duration()
const {
80 DCHECK(!end_of_stream());
84 void set_duration(int64_t duration) {
85 DCHECK(!end_of_stream());
89 bool is_key_frame()
const {
90 DCHECK(!end_of_stream());
94 bool is_encrypted()
const {
95 DCHECK(!end_of_stream());
98 const uint8_t* data()
const {
99 DCHECK(!end_of_stream());
103 uint8_t* writable_data() {
104 DCHECK(!end_of_stream());
108 size_t data_size()
const {
109 DCHECK(!end_of_stream());
113 const uint8_t* side_data()
const {
114 return &side_data_[0];
117 size_t side_data_size()
const {
118 return side_data_.size();
122 return decrypt_config_.get();
125 void set_data(
const uint8_t* data,
const size_t data_size) {
126 data_.assign(data, data + data_size);
129 void resize_data(
const size_t data_size) {
130 data_.resize(data_size);
133 void set_is_key_frame(
bool value) {
134 is_key_frame_ = value;
137 void set_is_encrypted(
bool value) {
138 is_encrypted_ = value;
141 void set_decrypt_config(std::unique_ptr<DecryptConfig> decrypt_config) {
142 decrypt_config_ = std::move(decrypt_config);
146 bool end_of_stream()
const {
return data_.size() == 0; }
148 const std::string& config_id()
const {
return config_id_; }
149 void set_config_id(
const std::string& config_id) {
150 config_id_ = config_id;
157 friend class base::RefCountedThreadSafe<MediaSample>;
162 MediaSample(
const uint8_t* data,
164 const uint8_t* side_data,
165 size_t side_data_size,
168 virtual ~MediaSample();
180 std::vector<uint8_t> data_;
184 std::vector<uint8_t> side_data_;
188 std::string config_id_;
191 std::unique_ptr<DecryptConfig> decrypt_config_;
193 DISALLOW_COPY_AND_ASSIGN(MediaSample);
196 typedef std::deque<scoped_refptr<MediaSample> > BufferQueue;
201 #endif // MEDIA_BASE_MEDIA_SAMPLE_H_