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"
21 class MediaSample :
public base::RefCountedThreadSafe<MediaSample> {
28 static scoped_refptr<MediaSample>
CopyFrom(
const uint8_t* data,
41 static scoped_refptr<MediaSample>
CopyFrom(
const uint8_t* data,
43 const uint8_t* side_data,
44 size_t side_data_size,
53 static scoped_refptr<MediaSample>
FromMetadata(
const uint8_t* metadata,
54 size_t metadata_size);
65 DCHECK(!end_of_stream());
69 void set_dts(int64_t dts) { dts_ = dts; }
72 DCHECK(!end_of_stream());
76 void set_pts(int64_t pts) { pts_ = pts; }
78 int64_t duration()
const {
79 DCHECK(!end_of_stream());
83 void set_duration(int64_t duration) {
84 DCHECK(!end_of_stream());
88 bool is_key_frame()
const {
89 DCHECK(!end_of_stream());
93 bool is_encrypted()
const {
94 DCHECK(!end_of_stream());
97 const uint8_t* data()
const {
98 DCHECK(!end_of_stream());
102 uint8_t* writable_data() {
103 DCHECK(!end_of_stream());
107 size_t data_size()
const {
108 DCHECK(!end_of_stream());
112 const uint8_t* side_data()
const {
113 return &side_data_[0];
116 size_t side_data_size()
const {
117 return side_data_.size();
120 void set_data(
const uint8_t* data,
const size_t data_size) {
121 data_.assign(data, data + data_size);
124 void resize_data(
const size_t data_size) {
125 data_.resize(data_size);
128 void set_is_key_frame(
bool value) {
129 is_key_frame_ = value;
132 void set_is_encrypted(
bool value) {
133 is_encrypted_ = value;
137 bool end_of_stream()
const {
return data_.size() == 0; }
139 const std::string& config_id()
const {
return config_id_; }
140 void set_config_id(
const std::string& config_id) {
141 config_id_ = config_id;
148 friend class base::RefCountedThreadSafe<MediaSample>;
153 MediaSample(
const uint8_t* data,
155 const uint8_t* side_data,
156 size_t side_data_size,
159 virtual ~MediaSample();
171 std::vector<uint8_t> data_;
175 std::vector<uint8_t> side_data_;
179 std::string config_id_;
181 DISALLOW_COPY_AND_ASSIGN(MediaSample);
184 typedef std::deque<scoped_refptr<MediaSample> > BufferQueue;
189 #endif // MEDIA_BASE_MEDIA_SAMPLE_H_