Switch to calloc in mk_createWriter, so we don't have to do a memset.
[libmkv.git] / src / chapters.c
blobc1f566b824a3325341bace16e6f30f4b8dc13878
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 "libmkv.h"
24 #include "matroska.h"
25 #include "config.h"
27 int mk_createChapterSimple(mk_Writer *w, uint64_t start, uint64_t end, char *name)
29 mk_Context *ca, *cd;
31 if (w->chapters == NULL)
33 if ((w->chapters = mk_createContext(w, w->root, 0x1043a770)) == NULL) // Chapters
34 return -1;
35 if ((w->edition_entry = mk_createContext(w, w->chapters, 0x45b9)) == NULL) // EditionEntry
36 return -1;
37 CHECK(mk_writeUInt(w->edition_entry, 0x45db, 1)); // EditionFlagDefault - Force this to be the default.
38 CHECK(mk_writeUInt(w->edition_entry, 0x45dd, 0)); // EditionFlagOrdered - Force simple chapters.
40 if ((ca = mk_createContext(w, w->edition_entry, 0xb6)) == NULL) // ChapterAtom
41 return -1;
42 CHECK(mk_writeUInt(ca, 0x73c4, ++w->chapter_uid));
43 CHECK(mk_writeUInt(ca, 0x91, start)); // ChapterTimeStart
44 if (end != start) // Just create a StartTime if chapter length would be 0.
45 CHECK(mk_writeUInt(ca, 0x92, end)); // ChapterTimeEnd
46 if (name != NULL) {
47 if ((cd = mk_createContext(w, ca, 0x80)) == NULL) // ChapterDisplay
48 return -1;
49 CHECK(mk_writeStr(cd, 0x85, name)); // ChapterDisplay
50 CHECK(mk_closeContext(cd, 0));
52 CHECK(mk_closeContext(ca, 0));
54 return 0;
57 int mk_writeChapters(mk_Writer *w) {
58 if ((w->chapters == NULL) || (w->edition_entry == NULL))
59 return -1;
60 CHECK(mk_closeContext(w->edition_entry, 0));
61 CHECK(mk_closeContext(w->chapters, 0));
63 return 0;