mkvmuxer: refactored code that creates a new cluster
Change-Id: I5db03b0e1ea23f45820dd47b7be9e4b0422f3e6a
This commit is contained in:
parent
c9e284b9e7
commit
db20aaa2b1
62
mkvmuxer.cpp
62
mkvmuxer.cpp
@ -1638,33 +1638,8 @@ bool Segment::AddFrame(const uint8* frame,
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check to see if the muxer needs to start a new cluster.
|
||||
if (is_key && tracks_.TrackIsVideo(track_number)) {
|
||||
new_cluster_ = true;
|
||||
} else if (cluster_list_size_ > 0) {
|
||||
const Cluster* const cluster = cluster_list_[cluster_list_size_-1];
|
||||
|
||||
if (!cluster)
|
||||
return false;
|
||||
|
||||
const uint64 cluster_ts =
|
||||
cluster->timecode() * segment_info_.timecode_scale();
|
||||
|
||||
if (max_cluster_duration_ > 0 &&
|
||||
(timestamp - cluster_ts) >= max_cluster_duration_) {
|
||||
new_cluster_ = true;
|
||||
} else if (max_cluster_size_ > 0 && cluster_list_size_ > 0) {
|
||||
if (cluster->payload_size() >= max_cluster_size_) {
|
||||
new_cluster_ = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (new_cluster_) {
|
||||
if (!MakeNewCluster(timestamp))
|
||||
return false;
|
||||
new_cluster_ = false;
|
||||
}
|
||||
if (!DoNewClusterProcessing(track_number, timestamp, is_key))
|
||||
return false;
|
||||
|
||||
// Write any audio frames left.
|
||||
if (WriteFramesAll() < 0)
|
||||
@ -1922,6 +1897,39 @@ bool Segment::MakeNewCluster(uint64 frame_timestamp_ns) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Segment::DoNewClusterProcessing(uint64 track_number,
|
||||
uint64 frame_timestamp_ns,
|
||||
bool is_key) {
|
||||
// Check to see if the muxer needs to start a new cluster.
|
||||
if (is_key && tracks_.TrackIsVideo(track_number)) {
|
||||
new_cluster_ = true;
|
||||
} else if (cluster_list_size_ > 0) {
|
||||
const Cluster* const cluster = cluster_list_[cluster_list_size_ - 1];
|
||||
if (!cluster)
|
||||
return false;
|
||||
|
||||
const uint64 timecode_scale = segment_info_.timecode_scale();
|
||||
const uint64 cluster_timestamp_ns = cluster->timecode() * timecode_scale;
|
||||
|
||||
if (max_cluster_duration_ > 0 &&
|
||||
(frame_timestamp_ns - cluster_timestamp_ns) >= max_cluster_duration_) {
|
||||
new_cluster_ = true;
|
||||
} else if (max_cluster_size_ > 0 && cluster_list_size_ > 0) {
|
||||
if (cluster->payload_size() >= max_cluster_size_) {
|
||||
new_cluster_ = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (new_cluster_) {
|
||||
if (!MakeNewCluster(frame_timestamp_ns))
|
||||
return false;
|
||||
new_cluster_ = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Segment::CheckHeaderInfo() {
|
||||
if (!header_written_) {
|
||||
if (!WriteSegmentHeader())
|
||||
|
@ -790,6 +790,11 @@ class Segment {
|
||||
// frame, or the indicated time. Returns true on success.
|
||||
bool MakeNewCluster(uint64 timestamp_ns);
|
||||
|
||||
// Checks whether a new cluster needs to be created, and if so
|
||||
// creates a new cluster. Returns false if creation of a new cluster
|
||||
// was necessary but creation was not successful.
|
||||
bool DoNewClusterProcessing(uint64 track_num, uint64 timestamp_ns, bool key);
|
||||
|
||||
// WebM elements
|
||||
Cues cues_;
|
||||
SeekHead seek_head_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user