1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2007 libmkv
7 * Authors: Nathan Caldwell
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
27 int mk_createChapterSimple(mk_Writer
*w
, uint64_t start
, uint64_t end
, char *name
)
30 unsigned long chapter_uid
;
33 * Generate a random UID for this Chapter.
34 * NOTE: This probably should be a CRC32 of some unique chapter information.
35 * In place of being completely random.
37 chapter_uid
= random();
39 if (w
->chapters
== NULL
)
41 unsigned long edition_uid
;
42 edition_uid
= random();
44 if ((w
->chapters
= mk_createContext(w
, w
->root
, MATROSKA_ID_CHAPTERS
)) == NULL
) // Chapters
46 if ((w
->edition_entry
= mk_createContext(w
, w
->chapters
, MATROSKA_ID_EDITIONENTRY
)) == NULL
) // EditionEntry
48 CHECK(mk_writeUInt(w
->edition_entry
, MATROSKA_ID_EDITIONUID
, edition_uid
)); /* EditionUID - See note above about Chapter UID. */
49 CHECK(mk_writeUInt(w
->edition_entry
, MATROSKA_ID_EDITIONFLAGDEFAULT
, 1)); // EditionFlagDefault - Force this to be the default.
50 CHECK(mk_writeUInt(w
->edition_entry
, MATROSKA_ID_EDITIONFLAGORDERED
, 0)); // EditionFlagOrdered - Force simple chapters.
52 if ((ca
= mk_createContext(w
, w
->edition_entry
, MATROSKA_ID_CHAPTERATOM
)) == NULL
) // ChapterAtom
54 CHECK(mk_writeUInt(ca
, MATROSKA_ID_CHAPTERUID
, chapter_uid
)); /* ChapterUID */
55 CHECK(mk_writeUInt(ca
, MATROSKA_ID_CHAPTERTIMESTART
, start
)); // ChapterTimeStart
56 if (end
!= start
) // Just create a StartTime if chapter length would be 0.
57 CHECK(mk_writeUInt(ca
, MATROSKA_ID_CHAPTERTIMEEND
, end
)); // ChapterTimeEnd
59 if ((cd
= mk_createContext(w
, ca
, MATROSKA_ID_CHAPTERDISPLAY
)) == NULL
) // ChapterDisplay
61 CHECK(mk_writeStr(cd
, MATROSKA_ID_CHAPTERSTRING
, name
)); // ChapterString
62 CHECK(mk_closeContext(cd
, 0));
64 CHECK(mk_closeContext(ca
, 0));
69 int mk_writeChapters(mk_Writer
*w
) {
70 if ((w
->chapters
== NULL
) || (w
->edition_entry
== NULL
))
72 CHECK(mk_closeContext(w
->edition_entry
, 0));
73 CHECK(mk_closeContext(w
->chapters
, 0));