Adding AddLastFrame to Segment
Adding AddLastFrame function to the Segment muxer so that the duration of the Segment can be accurately calculated given the last Block's duration. We now provide an AddLastFrame function which will take duration of that block as a parameter. When this function is used to add the last frame, the duration of it is taken into account when computing the Segment's duration. Change-Id: I3e1456299fefa1a4dd6d845c47292951d1ce3ad0
This commit is contained in:
58
mkvmuxer.cpp
58
mkvmuxer.cpp
@@ -115,15 +115,20 @@ bool ChunkedCopy(mkvparser::IMkvReader* source,
|
||||
// Frame Class
|
||||
|
||||
Frame::Frame()
|
||||
: frame_(NULL),
|
||||
: add_id_(0),
|
||||
additional_(NULL),
|
||||
additional_length_(0),
|
||||
duration_(0),
|
||||
frame_(NULL),
|
||||
is_key_(false),
|
||||
length_(0),
|
||||
track_number_(0),
|
||||
timestamp_(0),
|
||||
is_key_(false) {
|
||||
timestamp_(0) {
|
||||
}
|
||||
|
||||
Frame::~Frame() {
|
||||
delete [] frame_;
|
||||
delete [] additional_;
|
||||
}
|
||||
|
||||
bool Frame::Init(const uint8* frame, uint64 length) {
|
||||
@@ -140,6 +145,22 @@ bool Frame::Init(const uint8* frame, uint64 length) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Frame::AddAdditionalData(const uint8* additional, uint64 length,
|
||||
uint64 add_id) {
|
||||
uint8* const data =
|
||||
new (std::nothrow) uint8[static_cast<size_t>(length)]; // NOLINT
|
||||
if (!data)
|
||||
return false;
|
||||
|
||||
delete [] additional_;
|
||||
additional_ = data;
|
||||
additional_length_ = length;
|
||||
add_id_ = add_id;
|
||||
|
||||
memcpy(additional_, additional, static_cast<size_t>(additional_length_));
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
//
|
||||
// CuePoint Class
|
||||
@@ -2140,7 +2161,8 @@ bool Segment::Finalize() {
|
||||
}
|
||||
|
||||
const double duration =
|
||||
static_cast<double>(last_timestamp_) / segment_info_.timecode_scale();
|
||||
(static_cast<double>(last_timestamp_) + last_block_duration_) /
|
||||
segment_info_.timecode_scale();
|
||||
segment_info_.set_duration(duration);
|
||||
if (!segment_info_.Finalize(writer_header_))
|
||||
return false;
|
||||
@@ -2456,6 +2478,34 @@ bool Segment::AddMetadata(const uint8* frame,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Segment::AddGenericFrame(const Frame* frame) {
|
||||
last_block_duration_ = frame->duration();
|
||||
if (!tracks_.TrackIsAudio(frame->track_number()) &&
|
||||
!tracks_.TrackIsVideo(frame->track_number()) &&
|
||||
frame->duration() > 0) {
|
||||
return AddMetadata(frame->frame(),
|
||||
frame->length(),
|
||||
frame->track_number(),
|
||||
frame->timestamp(),
|
||||
frame->duration());
|
||||
} else if (frame->additional() && frame->additional_length() > 0) {
|
||||
return AddFrameWithAdditional(frame->frame(),
|
||||
frame->length(),
|
||||
frame->additional(),
|
||||
frame->additional_length(),
|
||||
frame->add_id(),
|
||||
frame->track_number(),
|
||||
frame->timestamp(),
|
||||
frame->is_key());
|
||||
} else {
|
||||
return AddFrame(frame->frame(),
|
||||
frame->length(),
|
||||
frame->track_number(),
|
||||
frame->timestamp(),
|
||||
frame->is_key());
|
||||
}
|
||||
}
|
||||
|
||||
void Segment::OutputCues(bool output_cues) {
|
||||
output_cues_ = output_cues;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user