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 =
|
||||
segmenter_->Initialize(streams(),
|
||||
muxer_listener(),
|
||||
encryption_key_source(),
|
||||
max_sd_pixels(),
|
||||
clear_lead_in_seconds(),
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "media/base/buffer_writer.h"
|
||||
#include "media/base/media_stream.h"
|
||||
#include "media/base/muxer_options.h"
|
||||
#include "media/event/muxer_listener.h"
|
||||
#include "media/file/file.h"
|
||||
#include "media/formats/mp4/box_definitions.h"
|
||||
|
||||
|
@ -159,12 +160,26 @@ Status MultiSegmentSegmenter::WriteSegment() {
|
|||
if (options().num_subsegments_per_sidx >= 0)
|
||||
sidx()->Write(buffer.get());
|
||||
|
||||
const size_t segment_size = buffer->Size() + fragment_buffer()->Size();
|
||||
DCHECK_NE(segment_size, 0u);
|
||||
|
||||
Status status = buffer->WriteToFile(file);
|
||||
if (status.ok())
|
||||
status = fragment_buffer()->WriteToFile(file);
|
||||
|
||||
if (!file->Close())
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -119,16 +119,19 @@ Segmenter::Segmenter(const MuxerOptions& options,
|
|||
fragment_buffer_(new BufferWriter()),
|
||||
sidx_(new SegmentIndex()),
|
||||
segment_initialized_(false),
|
||||
end_of_segment_(false) {}
|
||||
end_of_segment_(false),
|
||||
muxer_listener_(NULL) {}
|
||||
|
||||
Segmenter::~Segmenter() { STLDeleteElements(&fragmenters_); }
|
||||
|
||||
Status Segmenter::Initialize(const std::vector<MediaStream*>& streams,
|
||||
event::MuxerListener* muxer_listener,
|
||||
EncryptionKeySource* encryption_key_source,
|
||||
uint32 max_sd_pixels,
|
||||
double clear_lead_in_seconds,
|
||||
double crypto_period_duration_in_seconds) {
|
||||
DCHECK_LT(0u, streams.size());
|
||||
muxer_listener_ = muxer_listener;
|
||||
moof_->header.sequence_number = 0;
|
||||
|
||||
moof_->tracks.resize(streams.size());
|
||||
|
|
|
@ -23,6 +23,10 @@ class EncryptionKeySource;
|
|||
class MediaSample;
|
||||
class MediaStream;
|
||||
|
||||
namespace event {
|
||||
class MuxerListener;
|
||||
} // namespace event
|
||||
|
||||
namespace mp4 {
|
||||
|
||||
class Fragmenter;
|
||||
|
@ -59,6 +63,7 @@ class Segmenter {
|
|||
/// @param crypto_period_duration specifies crypto period duration in seconds.
|
||||
/// @return OK on success, an error status otherwise.
|
||||
Status Initialize(const std::vector<MediaStream*>& streams,
|
||||
event::MuxerListener* muxer_listener,
|
||||
EncryptionKeySource* encryption_key_source,
|
||||
uint32 max_sd_pixels,
|
||||
double clear_lead_in_seconds,
|
||||
|
@ -95,6 +100,7 @@ class Segmenter {
|
|||
Movie* moov() { return moov_.get(); }
|
||||
BufferWriter* fragment_buffer() { return fragment_buffer_.get(); }
|
||||
SegmentIndex* sidx() { return sidx_.get(); }
|
||||
event::MuxerListener* muxer_listener() { return muxer_listener_; }
|
||||
|
||||
private:
|
||||
virtual Status DoInitialize() = 0;
|
||||
|
@ -119,6 +125,7 @@ class Segmenter {
|
|||
std::map<const MediaStream*, uint32> stream_map_;
|
||||
bool segment_initialized_;
|
||||
bool end_of_segment_;
|
||||
event::MuxerListener* muxer_listener_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Segmenter);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue