2014-02-14 23:21:05 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
2013-09-24 04:17:12 +00:00
|
|
|
|
|
|
|
#ifndef MEDIA_BASE_MEDIA_SAMPLE_H_
|
|
|
|
#define MEDIA_BASE_MEDIA_SAMPLE_H_
|
|
|
|
|
|
|
|
#include <deque>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "base/logging.h"
|
|
|
|
#include "base/memory/ref_counted.h"
|
|
|
|
#include "base/memory/scoped_ptr.h"
|
|
|
|
#include "media/base/decrypt_config.h"
|
|
|
|
|
|
|
|
namespace media {
|
|
|
|
|
|
|
|
class DecryptConfig;
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Class to hold a media sample.
|
2013-11-12 20:32:44 +00:00
|
|
|
class MediaSample : public base::RefCountedThreadSafe<MediaSample> {
|
2013-09-24 04:17:12 +00:00
|
|
|
public:
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Create a MediaSample object from input.
|
|
|
|
/// @param data points to the buffer containing the sample data.
|
|
|
|
/// Must not be NULL.
|
|
|
|
/// @param size indicates sample size in bytes. Must not be negative.
|
|
|
|
/// @param is_key_frame indicates whether the sample is a key frame.
|
2013-09-24 04:17:12 +00:00
|
|
|
static scoped_refptr<MediaSample> CopyFrom(const uint8* data,
|
|
|
|
int size,
|
|
|
|
bool is_key_frame);
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Create a MediaSample object from input.
|
|
|
|
/// @param data points to the buffer containing the sample data.
|
|
|
|
/// Must not be NULL.
|
|
|
|
/// @param side_data points to the buffer containing the additional data.
|
|
|
|
/// Some containers allow additional data to be specified.
|
|
|
|
/// Must not be NULL.
|
|
|
|
/// @param size indicates sample size in bytes. Must not be negative.
|
|
|
|
/// @param side_data_size indicates additional sample data size in bytes.
|
|
|
|
/// Must not be negative.
|
|
|
|
/// @param is_key_frame indicates whether the sample is a key frame.
|
2013-09-24 04:17:12 +00:00
|
|
|
static scoped_refptr<MediaSample> CopyFrom(const uint8* data,
|
|
|
|
int size,
|
|
|
|
const uint8* side_data,
|
|
|
|
int side_data_size,
|
|
|
|
bool is_key_frame);
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Create a MediaSample indicating we've reached end of stream.
|
|
|
|
/// Calling any method other than end_of_stream() on the resulting buffer
|
|
|
|
/// is disallowed.
|
2013-09-24 04:17:12 +00:00
|
|
|
static scoped_refptr<MediaSample> CreateEOSBuffer();
|
|
|
|
|
|
|
|
int64 dts() const {
|
|
|
|
DCHECK(!end_of_stream());
|
|
|
|
return dts_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_dts(int64 dts) {
|
|
|
|
DCHECK(!end_of_stream());
|
|
|
|
dts_ = dts;
|
|
|
|
}
|
|
|
|
|
|
|
|
int64 pts() const {
|
|
|
|
DCHECK(!end_of_stream());
|
|
|
|
return pts_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_pts(int64 pts) {
|
|
|
|
DCHECK(!end_of_stream());
|
|
|
|
pts_ = pts;
|
|
|
|
}
|
|
|
|
|
|
|
|
int64 duration() const {
|
|
|
|
DCHECK(!end_of_stream());
|
|
|
|
return duration_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_duration(int64 duration) {
|
|
|
|
DCHECK(!end_of_stream());
|
|
|
|
duration_ = duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_key_frame() const {
|
|
|
|
DCHECK(!end_of_stream());
|
|
|
|
return is_key_frame_;
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint8* data() const {
|
|
|
|
DCHECK(!end_of_stream());
|
2013-11-12 20:32:44 +00:00
|
|
|
return &data_[0];
|
2013-09-24 04:17:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8* writable_data() {
|
|
|
|
DCHECK(!end_of_stream());
|
2013-11-12 20:32:44 +00:00
|
|
|
return &data_[0];
|
2013-09-24 04:17:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int data_size() const {
|
|
|
|
DCHECK(!end_of_stream());
|
|
|
|
return data_.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint8* side_data() const {
|
|
|
|
DCHECK(!end_of_stream());
|
2013-11-12 20:32:44 +00:00
|
|
|
return &side_data_[0];
|
2013-09-24 04:17:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int side_data_size() const {
|
|
|
|
DCHECK(!end_of_stream());
|
|
|
|
return side_data_.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
const DecryptConfig* decrypt_config() const {
|
|
|
|
DCHECK(!end_of_stream());
|
|
|
|
return decrypt_config_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_decrypt_config(scoped_ptr<DecryptConfig> decrypt_config) {
|
|
|
|
DCHECK(!end_of_stream());
|
|
|
|
decrypt_config_ = decrypt_config.Pass();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there's no data in this buffer, it represents end of stream.
|
2013-11-12 20:32:44 +00:00
|
|
|
bool end_of_stream() const { return data_.size() == 0; }
|
2013-09-24 04:17:12 +00:00
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// @return a human-readable string describing |*this|.
|
2013-10-11 21:44:55 +00:00
|
|
|
std::string ToString() const;
|
2013-09-24 04:17:12 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
friend class base::RefCountedThreadSafe<MediaSample>;
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Create a MediaSample. Buffer will be padded and aligned as necessary.
|
|
|
|
/// @param data,side_data can be NULL, which indicates an empty sample.
|
|
|
|
/// @param size,side_data_size should not be negative.
|
2013-09-24 04:17:12 +00:00
|
|
|
MediaSample(const uint8* data,
|
|
|
|
int size,
|
|
|
|
const uint8* side_data,
|
|
|
|
int side_data_size,
|
|
|
|
bool is_key_frame);
|
|
|
|
virtual ~MediaSample();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Decoding time stamp.
|
|
|
|
int64 dts_;
|
|
|
|
// Presentation time stamp.
|
|
|
|
int64 pts_;
|
|
|
|
int64 duration_;
|
|
|
|
bool is_key_frame_;
|
|
|
|
|
|
|
|
// Main buffer data.
|
|
|
|
std::vector<uint8> data_;
|
|
|
|
// Contain additional buffers to complete the main one. Needed by WebM
|
|
|
|
// http://www.matroska.org/technical/specs/index.html BlockAdditional[A5].
|
|
|
|
// Not used by mp4 and other containers.
|
|
|
|
std::vector<uint8> side_data_;
|
|
|
|
scoped_ptr<DecryptConfig> decrypt_config_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(MediaSample);
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::deque<scoped_refptr<MediaSample> > BufferQueue;
|
|
|
|
|
|
|
|
} // namespace media
|
|
|
|
|
|
|
|
#endif // MEDIA_BASE_MEDIA_SAMPLE_H_
|