forked from videolan/vlc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobjects.c
210 lines (177 loc) · 5.94 KB
/
objects.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*****************************************************************************
* objects.c: vlc_object_t handling
*****************************************************************************
* Copyright (C) 2004-2008 VLC authors and VideoLAN
* Copyright (C) 2006-2010 Rémi Denis-Courmont
*
* Authors: Samuel Hocevar <[email protected]>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/**
* \file
* This file contains the functions to handle the vlc_object_t type
*
* Unless otherwise stated, functions in this file are not cancellation point.
* All functions in this file are safe w.r.t. deferred cancellation.
*/
/*****************************************************************************
* Preamble
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <vlc_common.h>
#include "../libvlc.h"
#include <vlc_aout.h>
#include "audio_output/aout_internal.h"
#include "vlc_interface.h"
#include "vlc_codec.h"
#include "variables.h"
#ifdef HAVE_SEARCH_H
# include <search.h>
#endif
#include <limits.h>
#include <assert.h>
#define vlc_children_foreach(pos, priv) \
while (((void)(pos), (void)(priv), 0))
int vlc_object_init(vlc_object_t *restrict obj, vlc_object_t *parent,
const char *typename)
{
vlc_object_internals_t *priv = malloc(sizeof (*priv));
if (unlikely(priv == NULL))
return -1;
priv->parent = parent;
priv->typename = typename;
priv->var_root = NULL;
vlc_mutex_init (&priv->var_lock);
priv->resources = NULL;
obj->priv = priv;
obj->force = false;
if (likely(parent != NULL))
{
obj->logger = parent->logger;
obj->no_interact = parent->no_interact;
}
else
{
obj->logger = NULL;
obj->no_interact = false;
}
return 0;
}
void *(vlc_custom_create)(vlc_object_t *parent, size_t length,
const char *typename)
{
assert(length >= sizeof (vlc_object_t));
vlc_object_t *obj = calloc(length, 1);
if (unlikely(obj == NULL || vlc_object_init(obj, parent, typename))) {
free(obj);
obj = NULL;
}
return obj;
}
void *(vlc_object_create)(vlc_object_t *p_this, size_t i_size)
{
return vlc_custom_create( p_this, i_size, "generic" );
}
const char *vlc_object_typename(const vlc_object_t *obj)
{
return vlc_internals(obj)->typename;
}
vlc_object_t *(vlc_object_parent)(vlc_object_t *obj)
{
return vlc_internals(obj)->parent;
}
struct vlc_tracer *vlc_object_get_tracer(vlc_object_t *obj)
{
libvlc_int_t *vlc = vlc_object_instance(obj);
libvlc_priv_t *vlc_priv = libvlc_priv(vlc);
return vlc_priv->tracer;
}
void vlc_object_deinit(vlc_object_t *obj)
{
vlc_object_internals_t *priv = vlc_internals(obj);
assert(priv->resources == NULL);
/* Destroy the associated variables. */
int canc = vlc_savecancel();
var_DestroyAll(obj);
vlc_restorecancel(canc);
free(priv);
}
void (vlc_object_delete)(vlc_object_t *obj)
{
vlc_object_deinit(obj);
free(obj);
}
void vlc_object_vaLog(vlc_object_t *obj, int prio, const char *module,
const char *file, unsigned line, const char *func,
const char *format, va_list ap)
{
if (obj == NULL)
return;
const char *typename = vlc_object_typename(obj);
/* FIXME: libvlc allows NULL type but modules don't */
if (typename == NULL)
typename = "generic";
vlc_vaLog(&obj->logger, prio, typename, module, file, line, func,
format, ap);
}
void vlc_object_Log(vlc_object_t *obj, int prio, const char *module,
const char *file, unsigned line, const char *func,
const char *format, ...)
{
va_list ap;
va_start(ap, format);
vlc_object_vaLog(obj, prio, module, file, line, func, format, ap);
va_end(ap);
}
/**
* Lists the children of an object.
*
* Fills a table of pointers to children object of an object, incrementing the
* reference count for each of them.
*
* @param obj object whose children are to be listed
* @param tab base address to hold the list of children [OUT]
* @param max size of the table
*
* @return the actual number of children (may be larger than requested).
*
* @warning The list of object can change asynchronously even before the
* function returns. The list meant exclusively for debugging and tracing,
* not for functional introspection of any kind.
*
* @warning Objects appear in the object tree early, and disappear late.
* Most object properties are not accessible or not defined when the object is
* accessed through this function.
* For instance, the object cannot be used as a message log target
* (because object flags are not accessible asynchronously).
* Also type-specific object variables may not have been created yet, or may
* already have been deleted.
*/
size_t vlc_list_children(vlc_object_t *obj, vlc_object_t **restrict tab,
size_t max)
{
vlc_object_internals_t *priv;
size_t count = 0;
vlc_children_foreach(priv, vlc_internals(obj))
{
if (count < max)
tab[count] = vlc_object_hold(vlc_externals(priv));
count++;
}
return count;
}