Added trick_play_rate to VideoStreamInfo.

Added ability to query the Demuxer for the container name (type).

Change-Id: I328215f7c5badfe117c5419dd42f5262c568112a
This commit is contained in:
Thomas Inskip 2015-06-02 14:41:49 -07:00 committed by Gerrit Code Review
parent 581cb1fc4d
commit a14ea461fb
8 changed files with 24 additions and 6 deletions

View File

@ -9,7 +9,6 @@
#include "packager/base/bind.h" #include "packager/base/bind.h"
#include "packager/base/logging.h" #include "packager/base/logging.h"
#include "packager/base/stl_util.h" #include "packager/base/stl_util.h"
#include "packager/media/base/container_names.h"
#include "packager/media/base/decryptor_source.h" #include "packager/media/base/decryptor_source.h"
#include "packager/media/base/key_source.h" #include "packager/media/base/key_source.h"
#include "packager/media/base/media_sample.h" #include "packager/media/base/media_sample.h"
@ -33,6 +32,7 @@ Demuxer::Demuxer(const std::string& file_name)
: file_name_(file_name), : file_name_(file_name),
media_file_(NULL), media_file_(NULL),
init_event_received_(false), init_event_received_(false),
container_name_(CONTAINER_UNKNOWN),
buffer_(new uint8_t[kBufSize]), buffer_(new uint8_t[kBufSize]),
cancelled_(false) { cancelled_(false) {
} }
@ -70,10 +70,10 @@ Status Demuxer::Initialize() {
break; break;
bytes_read += read_result; bytes_read += read_result;
} }
MediaContainerName container = DetermineContainer(buffer_.get(), bytes_read); container_name_ = DetermineContainer(buffer_.get(), bytes_read);
// Initialize media parser. // Initialize media parser.
switch (container) { switch (container_name_) {
case CONTAINER_MOV: case CONTAINER_MOV:
parser_.reset(new mp4::MP4MediaParser()); parser_.reset(new mp4::MP4MediaParser());
break; break;
@ -93,7 +93,7 @@ Status Demuxer::Initialize() {
key_source_.get()); key_source_.get());
// Handle trailing 'moov'. // Handle trailing 'moov'.
if (container == CONTAINER_MOV) if (container_name_ == CONTAINER_MOV)
static_cast<mp4::MP4MediaParser*>(parser_.get())->LoadMoov(file_name_); static_cast<mp4::MP4MediaParser*>(parser_.get())->LoadMoov(file_name_);
if (!parser_->Parse(buffer_.get(), bytes_read)) { if (!parser_->Parse(buffer_.get(), bytes_read)) {

View File

@ -65,6 +65,10 @@ class Demuxer {
/// through MediaStream APIs. /// through MediaStream APIs.
const std::vector<MediaStream*>& streams() { return streams_; } const std::vector<MediaStream*>& streams() { return streams_; }
/// @return Container name (type). Value is CONTAINER_UNKNOWN if the demuxer
/// is not initialized.
MediaContainerName container_name() { return container_name_; }
private: private:
// Parser event handlers. // Parser event handlers.
void ParserInitEvent(const std::vector<scoped_refptr<StreamInfo> >& streams); void ParserInitEvent(const std::vector<scoped_refptr<StreamInfo> >& streams);
@ -77,6 +81,7 @@ class Demuxer {
Status init_parsing_status_; Status init_parsing_status_;
scoped_ptr<MediaParser> parser_; scoped_ptr<MediaParser> parser_;
std::vector<MediaStream*> streams_; std::vector<MediaStream*> streams_;
MediaContainerName container_name_;
scoped_ptr<uint8_t[]> buffer_; scoped_ptr<uint8_t[]> buffer_;
scoped_ptr<KeySource> key_source_; scoped_ptr<KeySource> key_source_;
bool cancelled_; bool cancelled_;

View File

@ -46,6 +46,7 @@ VideoStreamInfo::VideoStreamInfo(int track_id,
const std::string& language, const std::string& language,
uint16_t width, uint16_t width,
uint16_t height, uint16_t height,
int16_t trick_play_rate,
uint8_t nalu_length_size, uint8_t nalu_length_size,
const uint8_t* extra_data, const uint8_t* extra_data,
size_t extra_data_size, size_t extra_data_size,
@ -62,6 +63,7 @@ VideoStreamInfo::VideoStreamInfo(int track_id,
codec_(codec), codec_(codec),
width_(width), width_(width),
height_(height), height_(height),
trick_play_rate_(trick_play_rate),
nalu_length_size_(nalu_length_size) { nalu_length_size_(nalu_length_size) {
} }
@ -76,11 +78,13 @@ bool VideoStreamInfo::IsValidConfig() const {
std::string VideoStreamInfo::ToString() const { std::string VideoStreamInfo::ToString() const {
return base::StringPrintf( return base::StringPrintf(
"%s codec: %s\n width: %d\n height: %d\n nalu_length_size: %d\n", "%s codec: %s\n width: %d\n height: %d\n trick_play_rate: %d\n"
" nalu_length_size: %d\n",
StreamInfo::ToString().c_str(), StreamInfo::ToString().c_str(),
VideoCodecToString(codec_).c_str(), VideoCodecToString(codec_).c_str(),
width_, width_,
height_, height_,
trick_play_rate_,
nalu_length_size_); nalu_length_size_);
} }

View File

@ -36,6 +36,7 @@ class VideoStreamInfo : public StreamInfo {
const std::string& language, const std::string& language,
uint16_t width, uint16_t width,
uint16_t height, uint16_t height,
int16_t trick_play_rate,
uint8_t nalu_length_size, uint8_t nalu_length_size,
const uint8_t* extra_data, const uint8_t* extra_data,
size_t extra_data_size, size_t extra_data_size,
@ -65,6 +66,7 @@ class VideoStreamInfo : public StreamInfo {
VideoCodec codec_; VideoCodec codec_;
uint16_t width_; uint16_t width_;
uint16_t height_; uint16_t height_;
int16_t trick_play_rate_; // Non-zero for trick-play streams.
// Specifies the normalized size of the NAL unit length field. Can be 1, 2 or // Specifies the normalized size of the NAL unit length field. Can be 1, 2 or
// 4 bytes, or 0 if the size if unknown or the stream is not a AVC stream // 4 bytes, or 0 if the size if unknown or the stream is not a AVC stream

View File

@ -63,6 +63,7 @@ scoped_refptr<StreamInfo> CreateVideoStreamInfo(
param.language, param.language,
param.width, param.width,
param.height, param.height,
0, // trick_play_rate
param.nalu_length_size, param.nalu_length_size,
vector_as_array(&param.extra_data), vector_as_array(&param.extra_data),
param.extra_data.size(), param.extra_data.size(),

View File

@ -363,6 +363,7 @@ bool EsParserH264::UpdateVideoDecoderConfig(const H264SPS* sps) {
std::string(), std::string(),
width, width,
height, height,
0,
H264ByteToUnitStreamConverter::kUnitStreamNaluLengthSize, H264ByteToUnitStreamConverter::kUnitStreamNaluLengthSize,
decoder_config_record.data(), decoder_config_record.data(),
decoder_config_record.size(), decoder_config_record.size(),

View File

@ -378,6 +378,7 @@ bool MP4MediaParser::ParseMoov(BoxReader* reader) {
track->media.header.language, track->media.header.language,
entry.width, entry.width,
entry.height, entry.height,
0, // trick_play_rate
entry.avcc.length_size, entry.avcc.length_size,
&entry.avcc.data[0], &entry.avcc.data[0],
entry.avcc.data.size(), entry.avcc.data.size(),

View File

@ -564,6 +564,7 @@ bool WvmMediaParser::ParseIndexEntry() {
} }
uint64_t track_duration = 0; uint64_t track_duration = 0;
int16_t trick_play_rate = 0;
uint32_t sampling_frequency = kDefaultSamplingFrequency; uint32_t sampling_frequency = kDefaultSamplingFrequency;
uint32_t time_scale = kMpeg2ClockRate; uint32_t time_scale = kMpeg2ClockRate;
uint16_t video_width = 0; uint16_t video_width = 0;
@ -668,6 +669,9 @@ bool WvmMediaParser::ParseIndexEntry() {
case TrackDuration: case TrackDuration:
track_duration = value; track_duration = value;
break; break;
case TrackTrickPlayRate:
trick_play_rate = value;
break;
case VideoStreamId: case VideoStreamId:
video_pes_stream_id = value; video_pes_stream_id = value;
break; break;
@ -706,7 +710,7 @@ bool WvmMediaParser::ParseIndexEntry() {
stream_infos_.push_back(new VideoStreamInfo( stream_infos_.push_back(new VideoStreamInfo(
stream_id_count_, time_scale, track_duration, video_codec, stream_id_count_, time_scale, track_duration, video_codec,
video_codec_string, std::string(), video_width, video_height, video_codec_string, std::string(), video_width, video_height,
nalu_length_size, NULL, 0, true)); trick_play_rate, nalu_length_size, NULL, 0, true));
program_demux_stream_map_[base::UintToString(index_program_id_) + ":" + program_demux_stream_map_[base::UintToString(index_program_id_) + ":" +
base::UintToString(video_pes_stream_id)] = base::UintToString(video_pes_stream_id)] =
stream_id_count_++; stream_id_count_++;