add operation to add generic track

Change-Id: I34e4ab14c0a5b022b77b98d9403125550024e730
This commit is contained in:
Matthew Heaney 2012-09-14 18:30:55 -07:00
parent 21a2bd14c7
commit 38173f9d49
2 changed files with 35 additions and 4 deletions

View File

@ -880,13 +880,23 @@ bool Tracks::AddTrack(Track* track, int32 number) {
if (number < 0)
return false;
// This muxer only supports track numbers in the range [1, 126], in
// order to be able (to use Matroska integer representation) to
// serialize the block header (of which the track number is a part)
// for a frame using exactly 4 bytes.
if (number > 0x7E)
return false;
uint32 track_num = number;
if (track_num > 0) {
// Check to make sure a track does not already have |track_num|.
for (uint32 i = 0; i < track_entries_size_; ++i) {
if (track_entries_[i]->number() == track_num)
return false;
}
}
const uint32 count = track_entries_size_ + 1;
@ -1584,6 +1594,20 @@ bool Segment::Finalize() {
return true;
}
Track* Segment::AddTrack(int32 number) {
Track* const track = new (std::nothrow) Track; // NOLINT
if (!track)
return NULL;
if (!tracks_.AddTrack(track, number)) {
delete track;
return NULL;
}
return track;
}
uint64 Segment::AddVideoTrack(int32 width, int32 height, int32 number) {
VideoTrack* const vid_track = new (std::nothrow) VideoTrack(); // NOLINT
if (!vid_track)

View File

@ -668,6 +668,13 @@ class Segment {
// |ptr_writer| is NULL.
bool Init(IMkvWriter* ptr_writer);
// Adds a generic track to the segment. Returns the newly-allocated
// track object (which is owned by the segment) on success, NULL on
// error. |number| is the number to use for the track. |number|
// must be >= 0. If |number| == 0 then the muxer will decide on the
// track number.
Track* AddTrack(int32 number);
// Adds an audio track to the segment. Returns the number of the track on
// success, 0 on error. |number| is the number to use for the audio track.
// |number| must be >= 0. If |number| == 0 then the muxer will decide on