Bump version to 0.6.4.1
[libmkv.git] / src / tags.c
blob689a1cbe19477b7f1d44116e38aba9ee6c71b4f3
1 /*****************************************************************************
2 * tags.c:
3 *****************************************************************************
4 * Copyright (C) 2007 libmkv
6 * Authors: John A. Stebbins
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 *****************************************************************************/
22 #include "config.h"
23 #include "libmkv.h"
24 #include "matroska.h"
26 int mk_initTags(mk_Writer *w)
28 mk_Context *targets;
30 if (w->tags == NULL) {
31 /* Tags */
32 if ((w->tags = mk_createContext(w, w->root, MATROSKA_ID_TAGS)) == NULL)
33 return -1;
34 /* Tag */
35 if ((w->tag = mk_createContext(w, w->tags, MATROSKA_ID_TAG)) == NULL)
36 return -1;
37 /* Targets */
38 if ((targets = mk_createContext(w, w->tag, MATROSKA_ID_TARGETS)) == NULL)
39 return -1;
40 /* TargetTypeValue */
41 CHECK(mk_writeUInt(targets, MATROSKA_ID_TARGETTYPEVALUE, MK_TARGETTYPE_MOVIE)); /* Album/Movie/Episode */
42 CHECK(mk_closeContext(targets, 0));
45 return 0;
48 int mk_createTagSimple(mk_Writer * w, char *tag_id, char *value)
50 mk_Context *simple;
52 CHECK(mk_initTags(w));
54 /* SimpleTag */
55 if ((simple = mk_createContext(w, w->tag, MATROSKA_ID_SIMPLETAG)) == NULL)
56 return -1;
58 CHECK(mk_writeStr(simple, MATROSKA_ID_TAGNAME, tag_id)); /* TagName */
59 CHECK(mk_writeStr(simple, MATROSKA_ID_TAGSTRING, value)); /* TagString */
60 CHECK(mk_closeContext(simple, 0));
62 return 0;
65 int mk_createTagSimpleBin(mk_Writer * w, char *tag_id, const void *data, unsigned size)
67 mk_Context *simple;
69 CHECK(mk_initTags(w));
71 /* SimpleTag */
72 if ((simple = mk_createContext(w, w->tag, MATROSKA_ID_SIMPLETAG)) == NULL)
73 return -1;
75 /* TagName */
76 CHECK(mk_writeStr(simple, MATROSKA_ID_TAGNAME, tag_id));
77 /* TagBinary */
78 CHECK(mk_writeBin(simple, MATROSKA_ID_TAGBINARY, data, size));
79 CHECK(mk_closeContext(simple, 0));
81 return 0;
84 int mk_writeTags(mk_Writer * w)
86 if ((w->tags == NULL) || (w->tag == NULL))
87 return -1;
88 CHECK(mk_closeContext(w->tag, 0));
89 CHECK(mk_closeContext(w->tags, 0));
91 return 0;