From edd2351a77223cf6c6730c7ba782f355ef027b8b Mon Sep 17 00:00:00 2001 From: Nathan Caldwell Date: Wed, 23 Jan 2008 23:07:29 -0700 Subject: [PATCH] Use random() to create Track, Chapter, and Edition UIDs. Remove the no longer needed chapter_uid from mk_Writer struct. --- src/chapters.c | 14 +++++++++++++- src/matroska.h | 1 - src/tracks.c | 19 ++++++++++++------- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/chapters.c b/src/chapters.c index 272c30f..2ba07ca 100644 --- a/src/chapters.c +++ b/src/chapters.c @@ -27,19 +27,31 @@ int mk_createChapterSimple(mk_Writer *w, uint64_t start, uint64_t end, char *name) { mk_Context *ca, *cd; + unsigned long chapter_uid; + /* + * Generate a random UID for this Chapter. + * NOTE: This probably should be a CRC32 of some unique chapter information. + * In place of being completely random. + */ + chapter_uid = random(); + if (w->chapters == NULL) { + unsigned long edition_uid; + edition_uid = random(); + if ((w->chapters = mk_createContext(w, w->root, 0x1043a770)) == NULL) // Chapters return -1; if ((w->edition_entry = mk_createContext(w, w->chapters, 0x45b9)) == NULL) // EditionEntry return -1; + CHECK(mk_writeUInt(w->edition_entry, 0x45bc, edition_uid)); /* EditionUID - See note above about Chapter UID. */ CHECK(mk_writeUInt(w->edition_entry, 0x45db, 1)); // EditionFlagDefault - Force this to be the default. CHECK(mk_writeUInt(w->edition_entry, 0x45dd, 0)); // EditionFlagOrdered - Force simple chapters. } if ((ca = mk_createContext(w, w->edition_entry, 0xb6)) == NULL) // ChapterAtom return -1; - CHECK(mk_writeUInt(ca, 0x73c4, ++w->chapter_uid)); + CHECK(mk_writeUInt(ca, 0x73c4, chapter_uid)); /* ChapterUID */ CHECK(mk_writeUInt(ca, 0x91, start)); // ChapterTimeStart if (end != start) // Just create a StartTime if chapter length would be 0. CHECK(mk_writeUInt(ca, 0x92, end)); // ChapterTimeEnd diff --git a/src/matroska.h b/src/matroska.h index 6d225f2..33924a2 100644 --- a/src/matroska.h +++ b/src/matroska.h @@ -85,7 +85,6 @@ struct mk_Writer_s { int64_t tc_scaled; } cluster; - int chapter_uid; uint8_t vlc_compat; }; diff --git a/src/tracks.c b/src/tracks.c index 2152261..27e012d 100644 --- a/src/tracks.c +++ b/src/tracks.c @@ -50,14 +50,19 @@ mk_Track *mk_createTrack(mk_Writer *w, mk_TrackConfig *tc) return NULL; if (mk_writeUInt(ti, 0xd7, track->track_id) < 0) // TrackNumber return NULL; - if (tc->trackUID) - { - if (mk_writeUInt(ti, 0x73c5, tc->trackUID) < 0) // TrackUID + if (tc->trackUID) { + if (mk_writeUInt(ti, 0x73c5, tc->trackUID) < 0) /* TrackUID */ return NULL; - } - else - { - if (mk_writeUInt(ti, 0x73c5, track->track_id) < 0) + } else { + /* + * If we aren't given a UID, randomly generate one. + * NOTE: It would probably be better to CRC32 some unique track information + * in place of something completely random. + */ + unsigned long track_uid; + track_uid = random(); + + if (mk_writeUInt(ti, 0x73c5, track_uid) < 0) /* TrackUID */ return NULL; } if (mk_writeUInt(ti, 0x83, tc->trackType) < 0) // TrackType -- 2.11.4.GIT