muxer: Add support to force Cluster placement.

Change-Id: I7d4653561ca760885ba6926825ba6b80cdbea8ab
This commit is contained in:
Frank Galligan
2012-10-25 09:53:34 -07:00
parent 25ee621061
commit 50afbea946
3 changed files with 23 additions and 5 deletions

View File

@@ -1461,6 +1461,7 @@ Segment::Segment()
cluster_list_capacity_(0), cluster_list_capacity_(0),
cluster_list_size_(0), cluster_list_size_(0),
cues_track_(0), cues_track_(0),
force_new_cluster_(false),
frames_(NULL), frames_(NULL),
frames_capacity_(0), frames_capacity_(0),
frames_size_(0), frames_size_(0),
@@ -1695,7 +1696,7 @@ bool Segment::AddFrame(const uint8* frame,
// If the segment has a video track hold onto audio frames to make sure the // If the segment has a video track hold onto audio frames to make sure the
// audio that is associated with the start time of a video key-frame is // audio that is associated with the start time of a video key-frame is
// muxed into the same cluster. // muxed into the same cluster.
if (has_video_ && tracks_.TrackIsAudio(track_number)) { if (has_video_ && tracks_.TrackIsAudio(track_number) && !force_new_cluster_) {
Frame* const new_frame = new Frame(); Frame* const new_frame = new Frame();
if (!new_frame->Init(frame, length)) if (!new_frame->Init(frame, length))
return false; return false;
@@ -1875,6 +1876,10 @@ bool Segment::CuesTrack(uint64 track_number) {
return true; return true;
} }
void Segment::ForceNewClusterOnNextFrame() {
force_new_cluster_ = true;
}
Track* Segment::GetTrackByNumber(uint64 track_number) const { Track* Segment::GetTrackByNumber(uint64 track_number) const {
return tracks_.GetTrackByNumber(track_number); return tracks_.GetTrackByNumber(track_number);
} }
@@ -1938,6 +1943,9 @@ bool Segment::WriteSegmentHeader() {
int Segment::TestFrame(uint64 track_number, int Segment::TestFrame(uint64 track_number,
uint64 frame_timestamp_ns, uint64 frame_timestamp_ns,
bool is_key) const { bool is_key) const {
if (force_new_cluster_)
return 1;
// If no clusters have been created yet, then create a new cluster // If no clusters have been created yet, then create a new cluster
// and write this frame immediately, in the new cluster. This path // and write this frame immediately, in the new cluster. This path
// should only be followed once, the first time we attempt to write // should only be followed once, the first time we attempt to write
@@ -2090,6 +2098,9 @@ bool Segment::DoNewClusterProcessing(uint64 track_number,
if (result < 0) // error if (result < 0) // error
return false; return false;
// Always set force_new_cluster_ to false after TestFrame.
force_new_cluster_ = false;
// A non-zero result means create a new cluster. // A non-zero result means create a new cluster.
if (result > 0 && !MakeNewCluster(frame_timestamp_ns)) if (result > 0 && !MakeNewCluster(frame_timestamp_ns))
return false; return false;

View File

@@ -751,6 +751,10 @@ class Segment {
// returned by the Add track functions. // returned by the Add track functions.
bool CuesTrack(uint64 track_number); bool CuesTrack(uint64 track_number);
// This will force the muxer to create a new Cluster when the next frame is
// added.
void ForceNewClusterOnNextFrame();
// Writes out any frames that have not been written out. Finalizes the last // Writes out any frames that have not been written out. Finalizes the last
// cluster. May update the size and duration of the segment. May output the // cluster. May update the size and duration of the segment. May output the
// Cues element. May finalize the SeekHead element. Returns true on success. // Cues element. May finalize the SeekHead element. Returns true on success.
@@ -889,6 +893,9 @@ class Segment {
// Track number that is associated with the cues element for this segment. // Track number that is associated with the cues element for this segment.
uint64 cues_track_; uint64 cues_track_;
// Tells the muxer to force a new cluster on the next Block.
bool force_new_cluster_;
// List of stored audio frames. These variables are used to store frames so // List of stored audio frames. These variables are used to store frames so
// the muxer can follow the guideline "Audio blocks that contain the video // the muxer can follow the guideline "Audio blocks that contain the video
// key frame's timecode should be in the same cluster as the video key frame // key frame's timecode should be in the same cluster as the video key frame

View File

@@ -497,7 +497,7 @@ uint64 WriteVoidElement(IMkvWriter* writer, uint64 size) {
void GetVersion(int32* major, int32* minor, int32* build, int32* revision) { void GetVersion(int32* major, int32* minor, int32* build, int32* revision) {
*major = 0; *major = 0;
*minor = 2; *minor = 2;
*build = 0; *build = 1;
*revision = 0; *revision = 0;
} }