Use size_t as the type of stream_index

Change-Id: Ica8ffeccc45c1adf5def6fe9b2edde5708d6b432
This commit is contained in:
Kongqun Yang 2017-03-02 16:10:30 -08:00 committed by KongQun Yang
parent 160700b452
commit 8806f78655
18 changed files with 86 additions and 83 deletions

View File

@ -30,22 +30,22 @@ const size_t kBufSize = 0x200000; // 2MB
// samples before seeing init_event, something is not right. The number // samples before seeing init_event, something is not right. The number
// set here is arbitrary though. // set here is arbitrary though.
const size_t kQueuedSamplesLimit = 10000; const size_t kQueuedSamplesLimit = 10000;
const int kInvalidStreamIndex = -1; const size_t kInvalidStreamIndex = static_cast<size_t>(-1);
const int kBaseVideoOutputStreamIndex = 0x100; const size_t kBaseVideoOutputStreamIndex = 0x100;
const int kBaseAudioOutputStreamIndex = 0x200; const size_t kBaseAudioOutputStreamIndex = 0x200;
std::string GetStreamLabel(int stream_index) { std::string GetStreamLabel(size_t stream_index) {
switch (stream_index) { switch (stream_index) {
case kBaseVideoOutputStreamIndex: case kBaseVideoOutputStreamIndex:
return "video"; return "video";
case kBaseAudioOutputStreamIndex: case kBaseAudioOutputStreamIndex:
return "audio"; return "audio";
default: default:
return base::IntToString(stream_index); return base::SizeTToString(stream_index);
} }
} }
bool GetStreamIndex(const std::string& stream_label, int* stream_index) { bool GetStreamIndex(const std::string& stream_label, size_t* stream_index) {
DCHECK(stream_index); DCHECK(stream_index);
if (stream_label == "video") { if (stream_label == "video") {
*stream_index = kBaseVideoOutputStreamIndex; *stream_index = kBaseVideoOutputStreamIndex;
@ -53,7 +53,7 @@ bool GetStreamIndex(const std::string& stream_label, int* stream_index) {
*stream_index = kBaseAudioOutputStreamIndex; *stream_index = kBaseAudioOutputStreamIndex;
} else { } else {
// Expect stream_label to be a zero based stream id. // Expect stream_label to be a zero based stream id.
if (!base::StringToInt(stream_label, stream_index)) { if (!base::StringToSizeT(stream_label, stream_index)) {
LOG(ERROR) << "Invalid argument --stream=" << stream_label << "; " LOG(ERROR) << "Invalid argument --stream=" << stream_label << "; "
<< "should be 'audio', 'video', or a number"; << "should be 'audio', 'video', or a number";
return false; return false;
@ -106,7 +106,7 @@ Status Demuxer::Run() {
return Status(error::CANCELLED, "Demuxer run cancelled"); return Status(error::CANCELLED, "Demuxer run cancelled");
if (status.error_code() == error::END_OF_STREAM) { if (status.error_code() == error::END_OF_STREAM) {
for (int stream_index : stream_indexes_) { for (size_t stream_index : stream_indexes_) {
status = FlushDownstream(stream_index); status = FlushDownstream(stream_index);
if (!status.ok()) if (!status.ok())
return status; return status;
@ -122,7 +122,7 @@ void Demuxer::Cancel() {
Status Demuxer::SetHandler(const std::string& stream_label, Status Demuxer::SetHandler(const std::string& stream_label,
std::shared_ptr<MediaHandler> handler) { std::shared_ptr<MediaHandler> handler) {
int stream_index = kInvalidStreamIndex; size_t stream_index = kInvalidStreamIndex;
if (!GetStreamIndex(stream_label, &stream_index)) { if (!GetStreamIndex(stream_label, &stream_index)) {
return Status(error::INVALID_ARGUMENT, return Status(error::INVALID_ARGUMENT,
"Invalid stream: " + stream_label); "Invalid stream: " + stream_label);
@ -132,7 +132,7 @@ Status Demuxer::SetHandler(const std::string& stream_label,
void Demuxer::SetLanguageOverride(const std::string& stream_label, void Demuxer::SetLanguageOverride(const std::string& stream_label,
const std::string& language_override) { const std::string& language_override) {
int stream_index = kInvalidStreamIndex; size_t stream_index = kInvalidStreamIndex;
if (!GetStreamIndex(stream_label, &stream_index)) if (!GetStreamIndex(stream_label, &stream_index))
LOG(WARNING) << "Invalid stream for language override " << stream_label; LOG(WARNING) << "Invalid stream for language override " << stream_label;
language_overrides_[stream_index] = language_override; language_overrides_[stream_index] = language_override;
@ -222,7 +222,7 @@ void Demuxer::ParserInitEvent(
output_handlers().find(kBaseAudioOutputStreamIndex) != output_handlers().find(kBaseAudioOutputStreamIndex) !=
output_handlers().end(); output_handlers().end();
for (const std::shared_ptr<StreamInfo>& stream_info : stream_infos) { for (const std::shared_ptr<StreamInfo>& stream_info : stream_infos) {
int stream_index = base_stream_index; size_t stream_index = base_stream_index;
if (video_handler_set && stream_info->stream_type() == kStreamVideo) { if (video_handler_set && stream_info->stream_type() == kStreamVideo) {
stream_index = kBaseVideoOutputStreamIndex; stream_index = kBaseVideoOutputStreamIndex;
// Only for the first video stream. // Only for the first video stream.

View File

@ -82,7 +82,7 @@ class Demuxer : public MediaHandler {
return Status(error::INTERNAL_ERROR, return Status(error::INTERNAL_ERROR,
"Demuxer should not be the downstream handler."); "Demuxer should not be the downstream handler.");
} }
bool ValidateOutputStreamIndex(int stream_index) const override { bool ValidateOutputStreamIndex(size_t stream_index) const override {
// We don't know if the stream is valid or not when setting up the graph. // We don't know if the stream is valid or not when setting up the graph.
// Will validate the stream index later when stream info is available. // Will validate the stream index later when stream info is available.
return true; return true;
@ -128,12 +128,12 @@ class Demuxer : public MediaHandler {
std::deque<QueuedSample> queued_samples_; std::deque<QueuedSample> queued_samples_;
std::unique_ptr<MediaParser> parser_; std::unique_ptr<MediaParser> parser_;
// TrackId -> StreamIndex map. // TrackId -> StreamIndex map.
std::map<uint32_t, int> track_id_to_stream_index_map_; std::map<uint32_t, size_t> track_id_to_stream_index_map_;
// The list of stream indexes in the above map (in the same order as the input // The list of stream indexes in the above map (in the same order as the input
// stream info vector). // stream info vector).
std::vector<int> stream_indexes_; std::vector<size_t> stream_indexes_;
// StreamIndex -> language_override map. // StreamIndex -> language_override map.
std::map<int, std::string> language_overrides_; std::map<size_t, std::string> language_overrides_;
MediaContainerName container_name_ = CONTAINER_UNKNOWN; MediaContainerName container_name_ = CONTAINER_UNKNOWN;
std::unique_ptr<uint8_t[]> buffer_; std::unique_ptr<uint8_t[]> buffer_;
std::unique_ptr<KeySource> key_source_; std::unique_ptr<KeySource> key_source_;

View File

@ -9,10 +9,8 @@
namespace shaka { namespace shaka {
namespace media { namespace media {
Status MediaHandler::SetHandler(int output_stream_index, Status MediaHandler::SetHandler(size_t output_stream_index,
std::shared_ptr<MediaHandler> handler) { std::shared_ptr<MediaHandler> handler) {
if (output_stream_index < 0)
return Status(error::INVALID_ARGUMENT, "Invalid output stream index");
if (output_handlers_.find(output_stream_index) != output_handlers_.end()) { if (output_handlers_.find(output_stream_index) != output_handlers_.end()) {
return Status(error::ALREADY_EXISTS, return Status(error::ALREADY_EXISTS,
"The handler at the specified index already exists."); "The handler at the specified index already exists.");
@ -40,19 +38,19 @@ Status MediaHandler::Initialize() {
return Status::OK; return Status::OK;
} }
Status MediaHandler::OnFlushRequest(int input_stream_index) { Status MediaHandler::OnFlushRequest(size_t input_stream_index) {
// The default implementation treats the output stream index to be identical // The default implementation treats the output stream index to be identical
// to the input stream index, which is true for most handlers. // to the input stream index, which is true for most handlers.
const int output_stream_index = input_stream_index; const size_t output_stream_index = input_stream_index;
return FlushDownstream(output_stream_index); return FlushDownstream(output_stream_index);
} }
bool MediaHandler::ValidateOutputStreamIndex(int stream_index) const { bool MediaHandler::ValidateOutputStreamIndex(size_t stream_index) const {
return stream_index >= 0 && stream_index < num_input_streams_; return stream_index < num_input_streams_;
} }
Status MediaHandler::Dispatch(std::unique_ptr<StreamData> stream_data) { Status MediaHandler::Dispatch(std::unique_ptr<StreamData> stream_data) {
int output_stream_index = stream_data->stream_index; size_t output_stream_index = stream_data->stream_index;
auto handler_it = output_handlers_.find(output_stream_index); auto handler_it = output_handlers_.find(output_stream_index);
if (handler_it == output_handlers_.end()) { if (handler_it == output_handlers_.end()) {
return Status(error::NOT_FOUND, return Status(error::NOT_FOUND,
@ -62,7 +60,7 @@ Status MediaHandler::Dispatch(std::unique_ptr<StreamData> stream_data) {
return handler_it->second.first->Process(std::move(stream_data)); return handler_it->second.first->Process(std::move(stream_data));
} }
Status MediaHandler::FlushDownstream(int output_stream_index) { Status MediaHandler::FlushDownstream(size_t output_stream_index) {
auto handler_it = output_handlers_.find(output_stream_index); auto handler_it = output_handlers_.find(output_stream_index);
if (handler_it == output_handlers_.end()) { if (handler_it == output_handlers_.end()) {
return Status(error::NOT_FOUND, return Status(error::NOT_FOUND,

View File

@ -41,7 +41,7 @@ struct SegmentInfo {
// TODO(kqyang): Should we use protobuf? // TODO(kqyang): Should we use protobuf?
struct StreamData { struct StreamData {
int stream_index = -1; size_t stream_index = -1;
StreamDataType stream_data_type = StreamDataType::kUnknown; StreamDataType stream_data_type = StreamDataType::kUnknown;
std::shared_ptr<PeriodInfo> period_info; std::shared_ptr<PeriodInfo> period_info;
@ -73,7 +73,7 @@ class MediaHandler {
virtual ~MediaHandler() = default; virtual ~MediaHandler() = default;
/// Connect downstream handler at the specified output stream index. /// Connect downstream handler at the specified output stream index.
Status SetHandler(int output_stream_index, Status SetHandler(size_t output_stream_index,
std::shared_ptr<MediaHandler> handler); std::shared_ptr<MediaHandler> handler);
/// Connect downstream handler to the next availble output stream index. /// Connect downstream handler to the next availble output stream index.
@ -97,20 +97,20 @@ class MediaHandler {
virtual Status Process(std::unique_ptr<StreamData> stream_data) = 0; virtual Status Process(std::unique_ptr<StreamData> stream_data) = 0;
/// Event handler for flush request at the specific input stream index. /// Event handler for flush request at the specific input stream index.
virtual Status OnFlushRequest(int input_stream_index); virtual Status OnFlushRequest(size_t input_stream_index);
/// Validate if the stream at the specified index actually exists. /// Validate if the stream at the specified index actually exists.
virtual bool ValidateOutputStreamIndex(int stream_index) const; virtual bool ValidateOutputStreamIndex(size_t stream_index) const;
bool initialized() { return initialized_; } bool initialized() { return initialized_; }
int num_input_streams() { return num_input_streams_; } size_t num_input_streams() { return num_input_streams_; }
/// Dispatch the stream data to downstream handlers. Note that /// Dispatch the stream data to downstream handlers. Note that
/// stream_data.stream_index should be the output stream index. /// stream_data.stream_index should be the output stream index.
Status Dispatch(std::unique_ptr<StreamData> stream_data); Status Dispatch(std::unique_ptr<StreamData> stream_data);
/// Dispatch the period info to downstream handlers. /// Dispatch the period info to downstream handlers.
Status DispatchPeriodInfo(int stream_index, Status DispatchPeriodInfo(size_t stream_index,
std::shared_ptr<PeriodInfo> period_info) { std::shared_ptr<PeriodInfo> period_info) {
std::unique_ptr<StreamData> stream_data(new StreamData); std::unique_ptr<StreamData> stream_data(new StreamData);
stream_data->stream_index = stream_index; stream_data->stream_index = stream_index;
@ -120,7 +120,7 @@ class MediaHandler {
} }
/// Dispatch the stream info to downstream handlers. /// Dispatch the stream info to downstream handlers.
Status DispatchStreamInfo(int stream_index, Status DispatchStreamInfo(size_t stream_index,
std::shared_ptr<StreamInfo> stream_info) { std::shared_ptr<StreamInfo> stream_info) {
std::unique_ptr<StreamData> stream_data(new StreamData); std::unique_ptr<StreamData> stream_data(new StreamData);
stream_data->stream_index = stream_index; stream_data->stream_index = stream_index;
@ -131,7 +131,7 @@ class MediaHandler {
/// Dispatch the encryption config to downstream handlers. /// Dispatch the encryption config to downstream handlers.
Status DispatchEncryptionConfig( Status DispatchEncryptionConfig(
int stream_index, size_t stream_index,
std::unique_ptr<EncryptionConfig> encryption_config) { std::unique_ptr<EncryptionConfig> encryption_config) {
std::unique_ptr<StreamData> stream_data(new StreamData); std::unique_ptr<StreamData> stream_data(new StreamData);
stream_data->stream_index = stream_index; stream_data->stream_index = stream_index;
@ -141,7 +141,7 @@ class MediaHandler {
} }
/// Dispatch the media sample to downstream handlers. /// Dispatch the media sample to downstream handlers.
Status DispatchMediaSample(int stream_index, Status DispatchMediaSample(size_t stream_index,
std::shared_ptr<MediaSample> media_sample) { std::shared_ptr<MediaSample> media_sample) {
std::unique_ptr<StreamData> stream_data(new StreamData); std::unique_ptr<StreamData> stream_data(new StreamData);
stream_data->stream_index = stream_index; stream_data->stream_index = stream_index;
@ -151,7 +151,7 @@ class MediaHandler {
} }
/// Dispatch the media event to downstream handlers. /// Dispatch the media event to downstream handlers.
Status DispatchMediaEvent(int stream_index, Status DispatchMediaEvent(size_t stream_index,
std::shared_ptr<MediaEvent> media_event) { std::shared_ptr<MediaEvent> media_event) {
std::unique_ptr<StreamData> stream_data(new StreamData); std::unique_ptr<StreamData> stream_data(new StreamData);
stream_data->stream_index = stream_index; stream_data->stream_index = stream_index;
@ -161,7 +161,7 @@ class MediaHandler {
} }
/// Dispatch the segment info to downstream handlers. /// Dispatch the segment info to downstream handlers.
Status DispatchSegmentInfo(int stream_index, Status DispatchSegmentInfo(size_t stream_index,
std::shared_ptr<SegmentInfo> segment_info) { std::shared_ptr<SegmentInfo> segment_info) {
std::unique_ptr<StreamData> stream_data(new StreamData); std::unique_ptr<StreamData> stream_data(new StreamData);
stream_data->stream_index = stream_index; stream_data->stream_index = stream_index;
@ -171,11 +171,11 @@ class MediaHandler {
} }
/// Flush the downstream connected at the specified output stream index. /// Flush the downstream connected at the specified output stream index.
Status FlushDownstream(int output_stream_index); Status FlushDownstream(size_t output_stream_index);
int num_input_streams() const { return num_input_streams_; } size_t num_input_streams() const { return num_input_streams_; }
int next_output_stream_index() const { return next_output_stream_index_; } size_t next_output_stream_index() const { return next_output_stream_index_; }
const std::map<int, std::pair<std::shared_ptr<MediaHandler>, int>>& const std::map<size_t, std::pair<std::shared_ptr<MediaHandler>, size_t>>&
output_handlers() { output_handlers() {
return output_handlers_; return output_handlers_;
} }
@ -186,12 +186,13 @@ class MediaHandler {
bool initialized_ = false; bool initialized_ = false;
// Number of input streams. // Number of input streams.
int num_input_streams_ = 0; size_t num_input_streams_ = 0;
// The next available output stream index, used by AddHandler. // The next available output stream index, used by AddHandler.
int next_output_stream_index_ = 0; size_t next_output_stream_index_ = 0;
// output stream index -> {output handler, output handler input stream index} // output stream index -> {output handler, output handler input stream index}
// map. // map.
std::map<int, std::pair<std::shared_ptr<MediaHandler>, int>> output_handlers_; std::map<size_t, std::pair<std::shared_ptr<MediaHandler>, size_t>>
output_handlers_;
}; };
} // namespace media } // namespace media

View File

@ -73,8 +73,8 @@ class FakeMediaHandler : public MediaHandler {
stream_data_vector_.push_back(std::move(stream_data)); stream_data_vector_.push_back(std::move(stream_data));
return Status::OK; return Status::OK;
} }
Status OnFlushRequest(int input_stream_index) override { return Status::OK; } Status OnFlushRequest(size_t input_stream_index) override { return Status::OK; }
bool ValidateOutputStreamIndex(int stream_index) const override { bool ValidateOutputStreamIndex(size_t stream_index) const override {
return true; return true;
} }

View File

@ -97,7 +97,7 @@ class Muxer : public MediaHandler {
/// @{ /// @{
Status InitializeInternal() override { return Status::OK; } Status InitializeInternal() override { return Status::OK; }
Status Process(std::unique_ptr<StreamData> stream_data) override; Status Process(std::unique_ptr<StreamData> stream_data) override;
Status OnFlushRequest(int input_stream_index) override { return Finalize(); } Status OnFlushRequest(size_t input_stream_index) override { return Finalize(); }
/// @} /// @}
const MuxerOptions& options() const { return options_; } const MuxerOptions& options() const { return options_; }
@ -124,11 +124,11 @@ class Muxer : public MediaHandler {
virtual Status Finalize() = 0; virtual Status Finalize() = 0;
// Add a new sample. // Add a new sample.
virtual Status AddSample(int stream_id, virtual Status AddSample(size_t stream_id,
std::shared_ptr<MediaSample> sample) = 0; std::shared_ptr<MediaSample> sample) = 0;
// Finalize the segment or subsegment. // Finalize the segment or subsegment.
virtual Status FinalizeSegment(int stream_id, virtual Status FinalizeSegment(size_t stream_id,
std::shared_ptr<SegmentInfo> segment_info) = 0; std::shared_ptr<SegmentInfo> segment_info) = 0;
MuxerOptions options_; MuxerOptions options_;

View File

@ -50,7 +50,7 @@ Status ChunkingHandler::Process(std::unique_ptr<StreamData> stream_data) {
// The video stream is treated as the main stream. If there is only one // The video stream is treated as the main stream. If there is only one
// stream, it is the main stream. // stream, it is the main stream.
const bool is_main_stream = const bool is_main_stream =
main_stream_index_ == -1 && main_stream_index_ == kInvalidStreamIndex &&
(stream_data->stream_info->stream_type() == kStreamVideo || (stream_data->stream_info->stream_type() == kStreamVideo ||
num_input_streams() == 1); num_input_streams() == 1);
if (is_main_stream) { if (is_main_stream) {
@ -70,7 +70,7 @@ Status ChunkingHandler::Process(std::unique_ptr<StreamData> stream_data) {
VLOG(3) << "Drop existing segment info."; VLOG(3) << "Drop existing segment info.";
return Status::OK; return Status::OK;
case StreamDataType::kMediaSample: { case StreamDataType::kMediaSample: {
const int stream_index = stream_data->stream_index; const size_t stream_index = stream_data->stream_index;
DCHECK_NE(time_scales_[stream_index], 0u) DCHECK_NE(time_scales_[stream_index], 0u)
<< "kStreamInfo should arrive before kMediaSample"; << "kStreamInfo should arrive before kMediaSample";
if (stream_index != main_stream_index_) { if (stream_index != main_stream_index_) {
@ -111,7 +111,7 @@ Status ChunkingHandler::Process(std::unique_ptr<StreamData> stream_data) {
return Dispatch(std::move(stream_data)); return Dispatch(std::move(stream_data));
} }
Status ChunkingHandler::OnFlushRequest(int input_stream_index) { Status ChunkingHandler::OnFlushRequest(size_t input_stream_index) {
if (segment_info_[input_stream_index]) { if (segment_info_[input_stream_index]) {
Status status; Status status;
if (input_stream_index != main_stream_index_) { if (input_stream_index != main_stream_index_) {
@ -185,7 +185,7 @@ Status ChunkingHandler::DispatchNonMainSamples(int64_t timestamp_threshold) {
while (status.ok() && !non_main_samples_.empty()) { while (status.ok() && !non_main_samples_.empty()) {
DCHECK_EQ(non_main_samples_.front()->stream_data_type, DCHECK_EQ(non_main_samples_.front()->stream_data_type,
StreamDataType::kMediaSample); StreamDataType::kMediaSample);
const int stream_index = non_main_samples_.front()->stream_index; const size_t stream_index = non_main_samples_.front()->stream_index;
const MediaSample* sample = non_main_samples_.front()->media_sample.get(); const MediaSample* sample = non_main_samples_.front()->media_sample.get();
// If the portion of the sample before |timestamp_threshold| is bigger than // If the portion of the sample before |timestamp_threshold| is bigger than
// the other portion, we consider it part of the current segment. // the other portion, we consider it part of the current segment.
@ -225,8 +225,7 @@ Status ChunkingHandler::DispatchNonMainSamples(int64_t timestamp_threshold) {
Status ChunkingHandler::DispatchSegmentInfoForAllStreams() { Status ChunkingHandler::DispatchSegmentInfoForAllStreams() {
Status status; Status status;
for (int i = 0; i < static_cast<int>(segment_info_.size()) && status.ok(); for (size_t i = 0; i < segment_info_.size() && status.ok(); ++i) {
++i) {
if (segment_info_[i] && segment_info_[i]->start_timestamp != -1) { if (segment_info_[i] && segment_info_[i]->start_timestamp != -1) {
segment_info_[i]->duration = segment_info_[i]->duration =
last_sample_end_timestamps_[i] - segment_info_[i]->start_timestamp; last_sample_end_timestamps_[i] - segment_info_[i]->start_timestamp;
@ -240,8 +239,7 @@ Status ChunkingHandler::DispatchSegmentInfoForAllStreams() {
Status ChunkingHandler::DispatchSubsegmentInfoForAllStreams() { Status ChunkingHandler::DispatchSubsegmentInfoForAllStreams() {
Status status; Status status;
for (int i = 0; i < static_cast<int>(subsegment_info_.size()) && status.ok(); for (size_t i = 0; i < subsegment_info_.size() && status.ok(); ++i) {
++i) {
if (subsegment_info_[i] && subsegment_info_[i]->start_timestamp != -1) { if (subsegment_info_[i] && subsegment_info_[i]->start_timestamp != -1) {
subsegment_info_[i]->duration = subsegment_info_[i]->duration =
last_sample_end_timestamps_[i] - subsegment_info_[i]->start_timestamp; last_sample_end_timestamps_[i] - subsegment_info_[i]->start_timestamp;

View File

@ -68,7 +68,7 @@ class ChunkingHandler : public MediaHandler {
/// @{ /// @{
Status InitializeInternal() override; Status InitializeInternal() override;
Status Process(std::unique_ptr<StreamData> stream_data) override; Status Process(std::unique_ptr<StreamData> stream_data) override;
Status OnFlushRequest(int input_stream_index) override; Status OnFlushRequest(size_t input_stream_index) override;
/// @} /// @}
private: private:
@ -94,7 +94,8 @@ class ChunkingHandler : public MediaHandler {
// The video stream is the main stream; if there is only one stream, it is the // The video stream is the main stream; if there is only one stream, it is the
// main stream. The chunking is based on the main stream. // main stream. The chunking is based on the main stream.
int main_stream_index_ = -1; const size_t kInvalidStreamIndex = static_cast<size_t>(-1);
size_t main_stream_index_ = kInvalidStreamIndex;
// Segment and subsegment duration in main stream's time scale. // Segment and subsegment duration in main stream's time scale.
int64_t segment_duration_ = 0; int64_t segment_duration_ = 0;
int64_t subsegment_duration_ = 0; int64_t subsegment_duration_ = 0;

View File

@ -18,8 +18,8 @@ using ::testing::IsEmpty;
namespace shaka { namespace shaka {
namespace media { namespace media {
namespace { namespace {
const int kStreamIndex0 = 0; const size_t kStreamIndex0 = 0;
const int kStreamIndex1 = 1; const size_t kStreamIndex1 = 1;
const uint32_t kTimeScale0 = 800; const uint32_t kTimeScale0 = 800;
const uint32_t kTimeScale1 = 1000; const uint32_t kTimeScale1 = 1000;
const int64_t kDuration0 = 200; const int64_t kDuration0 = 200;

View File

@ -104,7 +104,7 @@ TEST_F(EncryptionHandlerTest, OnlyOneInput) {
namespace { namespace {
const int kStreamIndex = 0; const size_t kStreamIndex = 0;
const bool kEncrypted = true; const bool kEncrypted = true;
const uint32_t kTimeScale = 1000; const uint32_t kTimeScale = 1000;
const uint32_t kMaxSdPixels = 100u; const uint32_t kMaxSdPixels = 100u;
@ -335,7 +335,7 @@ TEST_P(EncryptionHandlerEncryptionTest, Encrypt) {
DoAll(SetArgPointee<1>(GetMockEncryptionKey()), Return(Status::OK))); DoAll(SetArgPointee<1>(GetMockEncryptionKey()), Return(Status::OK)));
ASSERT_OK(Process(std::move(stream_data))); ASSERT_OK(Process(std::move(stream_data)));
ASSERT_EQ(2u, GetOutputStreamDataVector().size()); ASSERT_EQ(2u, GetOutputStreamDataVector().size());
ASSERT_EQ(0, GetOutputStreamDataVector().back()->stream_index); ASSERT_EQ(0u, GetOutputStreamDataVector().back()->stream_index);
ASSERT_EQ(StreamDataType::kMediaSample, ASSERT_EQ(StreamDataType::kMediaSample,
GetOutputStreamDataVector().back()->stream_data_type); GetOutputStreamDataVector().back()->stream_data_type);

View File

@ -34,14 +34,15 @@ Status TsMuxer::Finalize() {
return segmenter_->Finalize(); return segmenter_->Finalize();
} }
Status TsMuxer::AddSample(int stream_id, std::shared_ptr<MediaSample> sample) { Status TsMuxer::AddSample(size_t stream_id,
DCHECK_EQ(stream_id, 0); std::shared_ptr<MediaSample> sample) {
DCHECK_EQ(stream_id, 0u);
return segmenter_->AddSample(sample); return segmenter_->AddSample(sample);
} }
Status TsMuxer::FinalizeSegment(int stream_id, Status TsMuxer::FinalizeSegment(size_t stream_id,
std::shared_ptr<SegmentInfo> segment_info) { std::shared_ptr<SegmentInfo> segment_info) {
DCHECK_EQ(stream_id, 0); DCHECK_EQ(stream_id, 0u);
return segment_info->is_subsegment return segment_info->is_subsegment
? Status::OK ? Status::OK
: segmenter_->FinalizeSegment(segment_info->start_timestamp, : segmenter_->FinalizeSegment(segment_info->start_timestamp,

View File

@ -26,8 +26,9 @@ class TsMuxer : public Muxer {
// Muxer implementation. // Muxer implementation.
Status InitializeMuxer() override; Status InitializeMuxer() override;
Status Finalize() override; Status Finalize() override;
Status AddSample(int stream_id, std::shared_ptr<MediaSample> sample) override; Status AddSample(size_t stream_id,
Status FinalizeSegment(int stream_id, std::shared_ptr<MediaSample> sample) override;
Status FinalizeSegment(size_t stream_id,
std::shared_ptr<SegmentInfo> sample) override; std::shared_ptr<SegmentInfo> sample) override;
void FireOnMediaStartEvent(); void FireOnMediaStartEvent();

View File

@ -161,12 +161,13 @@ Status MP4Muxer::Finalize() {
return Status::OK; return Status::OK;
} }
Status MP4Muxer::AddSample(int stream_id, std::shared_ptr<MediaSample> sample) { Status MP4Muxer::AddSample(size_t stream_id,
std::shared_ptr<MediaSample> sample) {
DCHECK(segmenter_); DCHECK(segmenter_);
return segmenter_->AddSample(stream_id, sample); return segmenter_->AddSample(stream_id, sample);
} }
Status MP4Muxer::FinalizeSegment(int stream_id, Status MP4Muxer::FinalizeSegment(size_t stream_id,
std::shared_ptr<SegmentInfo> segment_info) { std::shared_ptr<SegmentInfo> segment_info) {
DCHECK(segmenter_); DCHECK(segmenter_);
VLOG(3) << "Finalize " << (segment_info->is_subsegment ? "sub" : "") VLOG(3) << "Finalize " << (segment_info->is_subsegment ? "sub" : "")

View File

@ -37,8 +37,9 @@ class MP4Muxer : public Muxer {
// Muxer implementation overrides. // Muxer implementation overrides.
Status InitializeMuxer() override; Status InitializeMuxer() override;
Status Finalize() override; Status Finalize() override;
Status AddSample(int stream_id, std::shared_ptr<MediaSample> sample) override; Status AddSample(size_t stream_id,
Status FinalizeSegment(int stream_id, std::shared_ptr<MediaSample> sample) override;
Status FinalizeSegment(size_t stream_id,
std::shared_ptr<SegmentInfo> segment_info) override; std::shared_ptr<SegmentInfo> segment_info) override;
// Generate Audio/Video Track box. // Generate Audio/Video Track box.

View File

@ -308,7 +308,7 @@ Status Segmenter::Finalize() {
return DoFinalize(); return DoFinalize();
} }
Status Segmenter::AddSample(int stream_id, Status Segmenter::AddSample(size_t stream_id,
std::shared_ptr<MediaSample> sample) { std::shared_ptr<MediaSample> sample) {
// Set default sample duration if it has not been set yet. // Set default sample duration if it has not been set yet.
if (moov_->extends.tracks[stream_id].default_sample_duration == 0) { if (moov_->extends.tracks[stream_id].default_sample_duration == 0) {
@ -316,7 +316,7 @@ Status Segmenter::AddSample(int stream_id,
sample->duration(); sample->duration();
} }
DCHECK_LT(stream_id, static_cast<int>(fragmenters_.size())); DCHECK_LT(stream_id, fragmenters_.size());
Fragmenter* fragmenter = fragmenters_[stream_id].get(); Fragmenter* fragmenter = fragmenters_[stream_id].get();
if (fragmenter->fragment_finalized()) { if (fragmenter->fragment_finalized()) {
return Status(error::FRAGMENT_FINALIZED, return Status(error::FRAGMENT_FINALIZED,
@ -333,8 +333,8 @@ Status Segmenter::AddSample(int stream_id,
return Status::OK; return Status::OK;
} }
Status Segmenter::FinalizeSegment(int stream_id, bool is_subsegment) { Status Segmenter::FinalizeSegment(size_t stream_id, bool is_subsegment) {
DCHECK_LT(stream_id, static_cast<int>(fragmenters_.size())); DCHECK_LT(stream_id, fragmenters_.size());
Fragmenter* fragmenter = fragmenters_[stream_id].get(); Fragmenter* fragmenter = fragmenters_[stream_id].get();
DCHECK(fragmenter); DCHECK(fragmenter);
fragmenter->FinalizeFragment(); fragmenter->FinalizeFragment();

View File

@ -88,13 +88,13 @@ class Segmenter {
/// @param stream_id is the zero-based stream index. /// @param stream_id is the zero-based stream index.
/// @param sample points to the sample to be added. /// @param sample points to the sample to be added.
/// @return OK on success, an error status otherwise. /// @return OK on success, an error status otherwise.
Status AddSample(int stream_id, std::shared_ptr<MediaSample> sample); Status AddSample(size_t stream_id, std::shared_ptr<MediaSample> sample);
/// Finalize the segment / subsegment. /// Finalize the segment / subsegment.
/// @param stream_id is the zero-based stream index. /// @param stream_id is the zero-based stream index.
/// @param is_subsegment indicates if it is a subsegment (fragment). /// @param is_subsegment indicates if it is a subsegment (fragment).
/// @return OK on success, an error status otherwise. /// @return OK on success, an error status otherwise.
Status FinalizeSegment(int stream_id, bool is_subsegment); Status FinalizeSegment(size_t stream_id, bool is_subsegment);
/// @return true if there is an initialization range, while setting @a offset /// @return true if there is an initialization range, while setting @a offset
/// and @a size; or false if initialization range does not apply. /// and @a size; or false if initialization range does not apply.

View File

@ -72,17 +72,17 @@ Status WebMMuxer::Finalize() {
return Status::OK; return Status::OK;
} }
Status WebMMuxer::AddSample(int stream_id, Status WebMMuxer::AddSample(size_t stream_id,
std::shared_ptr<MediaSample> sample) { std::shared_ptr<MediaSample> sample) {
DCHECK(segmenter_); DCHECK(segmenter_);
DCHECK_EQ(stream_id, 0); DCHECK_EQ(stream_id, 0u);
return segmenter_->AddSample(sample); return segmenter_->AddSample(sample);
} }
Status WebMMuxer::FinalizeSegment(int stream_id, Status WebMMuxer::FinalizeSegment(size_t stream_id,
std::shared_ptr<SegmentInfo> segment_info) { std::shared_ptr<SegmentInfo> segment_info) {
DCHECK(segmenter_); DCHECK(segmenter_);
DCHECK_EQ(stream_id, 0); DCHECK_EQ(stream_id, 0u);
return segmenter_->FinalizeSegment(segment_info->start_timestamp, return segmenter_->FinalizeSegment(segment_info->start_timestamp,
segment_info->duration, segment_info->duration,
segment_info->is_subsegment); segment_info->is_subsegment);

View File

@ -26,8 +26,9 @@ class WebMMuxer : public Muxer {
// Muxer implementation overrides. // Muxer implementation overrides.
Status InitializeMuxer() override; Status InitializeMuxer() override;
Status Finalize() override; Status Finalize() override;
Status AddSample(int stream_id, std::shared_ptr<MediaSample> sample) override; Status AddSample(size_t stream_id,
Status FinalizeSegment(int stream_id, std::shared_ptr<MediaSample> sample) override;
Status FinalizeSegment(size_t stream_id,
std::shared_ptr<SegmentInfo> segment_info) override; std::shared_ptr<SegmentInfo> segment_info) override;
void FireOnMediaStartEvent(); void FireOnMediaStartEvent();