Media code change to support live mpd
Change-Id: I24ca877ec62e69df5dbf3c9ede54da4df189dbc4
This commit is contained in:
parent
6837ac45b7
commit
1d920a1a4e
|
@ -100,6 +100,7 @@ Status MP4Muxer::Initialize() {
|
||||||
|
|
||||||
Status segmenter_initialized =
|
Status segmenter_initialized =
|
||||||
segmenter_->Initialize(streams(),
|
segmenter_->Initialize(streams(),
|
||||||
|
muxer_listener(),
|
||||||
encryption_key_source(),
|
encryption_key_source(),
|
||||||
max_sd_pixels(),
|
max_sd_pixels(),
|
||||||
clear_lead_in_seconds(),
|
clear_lead_in_seconds(),
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "media/base/buffer_writer.h"
|
#include "media/base/buffer_writer.h"
|
||||||
#include "media/base/media_stream.h"
|
#include "media/base/media_stream.h"
|
||||||
#include "media/base/muxer_options.h"
|
#include "media/base/muxer_options.h"
|
||||||
|
#include "media/event/muxer_listener.h"
|
||||||
#include "media/file/file.h"
|
#include "media/file/file.h"
|
||||||
#include "media/formats/mp4/box_definitions.h"
|
#include "media/formats/mp4/box_definitions.h"
|
||||||
|
|
||||||
|
@ -159,12 +160,26 @@ Status MultiSegmentSegmenter::WriteSegment() {
|
||||||
if (options().num_subsegments_per_sidx >= 0)
|
if (options().num_subsegments_per_sidx >= 0)
|
||||||
sidx()->Write(buffer.get());
|
sidx()->Write(buffer.get());
|
||||||
|
|
||||||
|
const size_t segment_size = buffer->Size() + fragment_buffer()->Size();
|
||||||
|
DCHECK_NE(segment_size, 0u);
|
||||||
|
|
||||||
Status status = buffer->WriteToFile(file);
|
Status status = buffer->WriteToFile(file);
|
||||||
if (status.ok())
|
if (status.ok())
|
||||||
status = fragment_buffer()->WriteToFile(file);
|
status = fragment_buffer()->WriteToFile(file);
|
||||||
|
|
||||||
if (!file->Close())
|
if (!file->Close())
|
||||||
LOG(WARNING) << "Failed to close the file properly: " << file_name;
|
LOG(WARNING) << "Failed to close the file properly: " << file_name;
|
||||||
|
|
||||||
|
if (status.ok() && muxer_listener()) {
|
||||||
|
uint64 segment_duration = 0;
|
||||||
|
// ISO/IEC 23009-1:2012: the value shall be identical to sum of the the
|
||||||
|
// values of all Subsegment_duration fields in the first ‘sidx’ box.
|
||||||
|
for (size_t i = 0; i < sidx()->references.size(); ++i)
|
||||||
|
segment_duration += sidx()->references[i].subsegment_duration;
|
||||||
|
muxer_listener()->OnNewSegment(
|
||||||
|
sidx()->earliest_presentation_time, segment_duration, segment_size);
|
||||||
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,16 +119,19 @@ Segmenter::Segmenter(const MuxerOptions& options,
|
||||||
fragment_buffer_(new BufferWriter()),
|
fragment_buffer_(new BufferWriter()),
|
||||||
sidx_(new SegmentIndex()),
|
sidx_(new SegmentIndex()),
|
||||||
segment_initialized_(false),
|
segment_initialized_(false),
|
||||||
end_of_segment_(false) {}
|
end_of_segment_(false),
|
||||||
|
muxer_listener_(NULL) {}
|
||||||
|
|
||||||
Segmenter::~Segmenter() { STLDeleteElements(&fragmenters_); }
|
Segmenter::~Segmenter() { STLDeleteElements(&fragmenters_); }
|
||||||
|
|
||||||
Status Segmenter::Initialize(const std::vector<MediaStream*>& streams,
|
Status Segmenter::Initialize(const std::vector<MediaStream*>& streams,
|
||||||
|
event::MuxerListener* muxer_listener,
|
||||||
EncryptionKeySource* encryption_key_source,
|
EncryptionKeySource* encryption_key_source,
|
||||||
uint32 max_sd_pixels,
|
uint32 max_sd_pixels,
|
||||||
double clear_lead_in_seconds,
|
double clear_lead_in_seconds,
|
||||||
double crypto_period_duration_in_seconds) {
|
double crypto_period_duration_in_seconds) {
|
||||||
DCHECK_LT(0u, streams.size());
|
DCHECK_LT(0u, streams.size());
|
||||||
|
muxer_listener_ = muxer_listener;
|
||||||
moof_->header.sequence_number = 0;
|
moof_->header.sequence_number = 0;
|
||||||
|
|
||||||
moof_->tracks.resize(streams.size());
|
moof_->tracks.resize(streams.size());
|
||||||
|
|
|
@ -23,6 +23,10 @@ class EncryptionKeySource;
|
||||||
class MediaSample;
|
class MediaSample;
|
||||||
class MediaStream;
|
class MediaStream;
|
||||||
|
|
||||||
|
namespace event {
|
||||||
|
class MuxerListener;
|
||||||
|
} // namespace event
|
||||||
|
|
||||||
namespace mp4 {
|
namespace mp4 {
|
||||||
|
|
||||||
class Fragmenter;
|
class Fragmenter;
|
||||||
|
@ -59,6 +63,7 @@ class Segmenter {
|
||||||
/// @param crypto_period_duration specifies crypto period duration in seconds.
|
/// @param crypto_period_duration specifies crypto period duration in seconds.
|
||||||
/// @return OK on success, an error status otherwise.
|
/// @return OK on success, an error status otherwise.
|
||||||
Status Initialize(const std::vector<MediaStream*>& streams,
|
Status Initialize(const std::vector<MediaStream*>& streams,
|
||||||
|
event::MuxerListener* muxer_listener,
|
||||||
EncryptionKeySource* encryption_key_source,
|
EncryptionKeySource* encryption_key_source,
|
||||||
uint32 max_sd_pixels,
|
uint32 max_sd_pixels,
|
||||||
double clear_lead_in_seconds,
|
double clear_lead_in_seconds,
|
||||||
|
@ -95,6 +100,7 @@ class Segmenter {
|
||||||
Movie* moov() { return moov_.get(); }
|
Movie* moov() { return moov_.get(); }
|
||||||
BufferWriter* fragment_buffer() { return fragment_buffer_.get(); }
|
BufferWriter* fragment_buffer() { return fragment_buffer_.get(); }
|
||||||
SegmentIndex* sidx() { return sidx_.get(); }
|
SegmentIndex* sidx() { return sidx_.get(); }
|
||||||
|
event::MuxerListener* muxer_listener() { return muxer_listener_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual Status DoInitialize() = 0;
|
virtual Status DoInitialize() = 0;
|
||||||
|
@ -119,6 +125,7 @@ class Segmenter {
|
||||||
std::map<const MediaStream*, uint32> stream_map_;
|
std::map<const MediaStream*, uint32> stream_map_;
|
||||||
bool segment_initialized_;
|
bool segment_initialized_;
|
||||||
bool end_of_segment_;
|
bool end_of_segment_;
|
||||||
|
event::MuxerListener* muxer_listener_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(Segmenter);
|
DISALLOW_COPY_AND_ASSIGN(Segmenter);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue