From 6e876c7217bc33f592738faaddc75f1d4e725db4 Mon Sep 17 00:00:00 2001 From: Nathan Caldwell Date: Thu, 19 Jul 2007 15:28:39 -0600 Subject: [PATCH] Latest Cues changes. We now write Cues every ~3MB only for video track keyframes. --- src/matroska.c | 32 +++++++++----------------------- src/matroska.h | 8 ++------ 2 files changed, 11 insertions(+), 29 deletions(-) diff --git a/src/matroska.c b/src/matroska.c index d20d0ff..607b0a4 100644 --- a/src/matroska.c +++ b/src/matroska.c @@ -177,7 +177,7 @@ static int mk_closeCluster(mk_Writer *w) { } int mk_flushFrame(mk_Writer *w, mk_Track *track) { - mk_Context *c; + mk_Context *c, *tp; int64_t delta, ref = 0; unsigned fsize, bgsize; uint8_t flags, c_delta_flags[2]; @@ -268,29 +268,18 @@ int mk_flushFrame(mk_Writer *w, mk_Track *track) { if (!track->frame.keyframe) CHECK(mk_writeSInt(w->cluster.context, 0xfb, ref)); // ReferenceBlock - if ((track->cue_flag || (track->track_type & MK_TRACK_VIDEO)) && track->frame.keyframe) { - for(i = 0; i < w->num_tracks; i++) - w->tracks_arr[i]->cue_flag = 1; - if (w->cue_point.timecode != track->frame.timecode) { - if (w->cue_point.context != NULL) { - CHECK(mk_closeContext(w->cue_point.context, 0)); - w->cue_point.context = NULL; - } - } - if (w->cue_point.context == NULL) { - if ((w->cue_point.context = mk_createContext(w, w->cues, 0xbb)) == NULL) // CuePoint - return -1; - CHECK(mk_writeUInt(w->cue_point.context, 0xb3, track->frame.timecode)); // CueTime - w->cue_point.timecode = track->frame.timecode; - } + if (track->frame.keyframe && (track->track_type & MK_TRACK_VIDEO) && (w->prev_cue_pos + 3*CLSIZE) >= w->f_pos) { + if ((c = mk_createContext(w, w->cues, 0xbb)) == NULL) // CuePoint + return -1; + CHECK(mk_writeUInt(c, 0xb3, track->frame.timecode)); // CueTime - if ((c = mk_createContext(w, w->cue_point.context, 0xb7)) == NULL) // CueTrackPositions + if ((tp = mk_createContext(w, c, 0xb7)) == NULL) // CueTrackPositions return -1; - CHECK(mk_writeUInt(c, 0xf7, track->track_id)); // CueTrack - CHECK(mk_writeUInt(c, 0xf1, w->cluster.pointer)); // CueClusterPosition + CHECK(mk_writeUInt(tp, 0xf7, track->track_id)); // CueTrack + CHECK(mk_writeUInt(tp, 0xf1, w->cluster.pointer)); // CueClusterPosition // CHECK(mk_writeUInt(c, 0x5378, w->cluster.block_count)); // CueBlockNumber + CHECK(mk_closeContext(tp, 0)); CHECK(mk_closeContext(c, 0)); - track->cue_flag = 0; } track->in_frame = 0; @@ -457,9 +446,6 @@ int mk_close(mk_Writer *w) { } w->seek_data.cues = w->f_pos - w->segment_ptr; - if (w->cue_point.context != NULL) - if (mk_closeContext(w->cue_point.context, 0) < 0) - ret = -1; // if (w->vlc_compat) { // if (mk_seekFile(w, w->segment_ptr + 259 + 2051) < 0) // ret = -1; diff --git a/src/matroska.h b/src/matroska.h index ba46322..57d8a8b 100644 --- a/src/matroska.h +++ b/src/matroska.h @@ -78,11 +78,8 @@ struct mk_Writer_s { int64_t attachments; int64_t tags; } seek_data; - - struct { - mk_Context *context; - uint64_t timecode; - } cue_point; + + int64_t prev_cue_pos; struct { mk_Context *context; @@ -103,7 +100,6 @@ struct mk_Track_s { int64_t max_frame_tc; uint8_t in_frame; uint64_t default_duration; - uint8_t cue_flag; uint8_t track_type; struct { -- 2.11.4.GIT