Handle AspectRatioType video element.
[libmkv.git] / src / chapters.c
blob70f4d5641962eb9323ba310c8f4ac63279730df0
1 /*****************************************************************************
2 * chapters.c:
3 *****************************************************************************
4 * Copyright (C) 2007 libmkv
5 * $Id: $
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 *****************************************************************************/
23 #include "config.h"
24 #include "libmkv.h"
25 #include "matroska.h"
27 int mk_createChapterSimple(mk_Writer *w, uint64_t start, uint64_t end, char *name)
29 mk_Context *ca, *cd;
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
45 return -1;
46 if ((w->edition_entry = mk_createContext(w, w->chapters, MATROSKA_ID_EDITIONENTRY)) == NULL) // EditionEntry
47 return -1;
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
53 return -1;
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
58 if (name != NULL) {
59 if ((cd = mk_createContext(w, ca, MATROSKA_ID_CHAPTERDISPLAY)) == NULL) // ChapterDisplay
60 return -1;
61 CHECK(mk_writeStr(cd, MATROSKA_ID_CHAPTERSTRING, name)); // ChapterString
62 CHECK(mk_closeContext(cd, 0));
64 CHECK(mk_closeContext(ca, 0));
66 return 0;
69 int mk_writeChapters(mk_Writer *w) {
70 if ((w->chapters == NULL) || (w->edition_entry == NULL))
71 return -1;
72 CHECK(mk_closeContext(w->edition_entry, 0));
73 CHECK(mk_closeContext(w->chapters, 0));
75 return 0;