core: "clock-jitter" is in milliseconds
[vlc.git] / src / input / info.h
blobe32a003b939476cd8e9f587fa518c0d308dc9bef
1 /*****************************************************************************
2 * info.h
3 *****************************************************************************
4 * Copyright (C) 2010 Laurent Aimar
5 * $Id$
7 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #ifndef LIBVLC_INPUT_INFO_H
25 #define LIBVLC_INPUT_INFO_H 1
27 #include "vlc_input_item.h"
29 static inline info_t *info_New(const char *name)
31 info_t *info = malloc(sizeof(*info));
32 if (!info)
33 return NULL;
35 info->psz_name = strdup(name);
36 info->psz_value = NULL;
37 return info;
40 static inline void info_Delete(info_t *i)
42 free(i->psz_name);
43 free(i->psz_value);
44 free(i);
47 static inline info_category_t *info_category_New(const char *name)
49 info_category_t *cat = malloc(sizeof(*cat));
50 if (!cat)
51 return NULL;
52 cat->psz_name = strdup(name);
53 vlc_list_init(&cat->infos);
54 return cat;
57 static inline info_t *info_category_FindInfo(const info_category_t *cat,
58 const char *name)
60 info_t *info;
62 info_foreach(info, &cat->infos)
63 if (!strcmp(info->psz_name, name))
64 return info;
65 return NULL;
68 static inline void info_category_ReplaceInfo(info_category_t *cat,
69 info_t *info)
71 info_t *old = info_category_FindInfo(cat, info->psz_name);
72 if (old) {
73 vlc_list_remove(&old->node);
74 info_Delete(old);
76 vlc_list_append(&info->node, &cat->infos);
79 static inline info_t *info_category_VaAddInfo(info_category_t *cat,
80 const char *name,
81 const char *format, va_list args)
83 info_t *info = info_category_FindInfo(cat, name);
84 if (!info) {
85 info = info_New(name);
86 if (!info)
87 return NULL;
88 vlc_list_append(&info->node, &cat->infos);
89 } else
90 free(info->psz_value);
91 if (vasprintf(&info->psz_value, format, args) == -1)
92 info->psz_value = NULL;
93 return info;
96 static inline info_t *info_category_AddInfo(info_category_t *cat,
97 const char *name,
98 const char *format, ...)
100 va_list args;
102 va_start(args, format);
103 info_t *info = info_category_VaAddInfo(cat, name, format, args);
104 va_end(args);
106 return info;
109 static inline int info_category_DeleteInfo(info_category_t *cat, const char *name)
111 info_t *info = info_category_FindInfo(cat, name);
112 if (info != NULL) {
113 vlc_list_remove(&info->node);
114 info_Delete(info);
115 return VLC_SUCCESS;
117 return VLC_EGENERIC;
120 static inline void info_category_Delete(info_category_t *cat)
122 info_t *info;
124 while ((info = vlc_list_first_entry_or_null(&cat->infos, info_t, node))) {
125 vlc_list_remove(&info->node);
126 info_Delete(info);
128 free(cat->psz_name);
129 free(cat);
132 #endif