Commit c240692f authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont
Browse files

Common structure for VLC common object members, document

parent 70a05fb5
......@@ -411,47 +411,86 @@ typedef int ( * vlc_list_callback_t ) ( vlc_object_t *, /* variable's objec
#include "vlc_mtime.h"
#include "vlc_threads.h"
/*****************************************************************************
/**
* Common structure members
*****************************************************************************/
/* VLC_COMMON_MEMBERS : members common to all basic vlc objects */
#define VLC_COMMON_MEMBERS \
/** \name VLC_COMMON_MEMBERS \
* these members are common for all vlc objects \
*/ \
/**@{*/ \
const char *psz_object_type; \
\
/* Messages header */ \
char *psz_header; \
int i_flags; \
\
/* Object properties */ \
bool b_force; /**< set by the outside (eg. module_need()) */ \
\
/* Stuff related to the libvlc structure */ \
libvlc_int_t *p_libvlc; /**< (root of all evil) - 1 */ \
\
vlc_object_t * p_parent; /**< our parent */ \
\
/**@}*/ \
/* VLC_OBJECT: attempt at doing a clever cast */
#if VLC_GCC_VERSION(4,0)
/**
* VLC object common members
*
* Common public properties for all VLC objects.
* Object also have private properties maintained by the core, see
* \ref vlc_object_internals_t
*/
struct vlc_common_members
{
/** Object type name
*
* A constant string identifying the type of the object (for logging)
*/
const char *object_type;
/** Log messages header
*
* Human-readable header for log messages. This is not thread-safe and
* only used by VLM and Lua interfaces.
*/
char *header;
int flags;
/** Module probe flag
*
* A boolean during module probing when the probe is "forced".
* See \ref module_need().
*/
bool force;
/** LibVLC instance
*
* Root VLC object of the objects tree that this object belongs in.
*/
libvlc_int_t *libvlc;
/** Parent object
*
* The parent VLC object in the objects tree. For the root (the LibVLC
* instance) object, this is NULL.
*/
vlc_object_t *parent;
};
/**
* Backward compatibility macro
*/
#define VLC_COMMON_MEMBERS struct vlc_common_members obj;
/**
* Type-safe vlc_object_t cast
*
* This macro attempts to cast a pointer to a compound type to a
* \ref vlc_object_t pointer in a type-safe manner.
* It checks if the compound type actually starts with an embedded
* \ref vlc_object_t structure.
*/
#if !defined(__cplusplus) && (__STDC_VERSION__ >= 201112L)
# define VLC_OBJECT(x) \
_Generic((x)->obj, \
struct vlc_common_members: (vlc_object_t *)(&(x)->obj) \
)
#elif VLC_GCC_VERSION(4,0)
# ifndef __cplusplus
# define VLC_OBJECT( x ) \
__builtin_choose_expr( \
__builtin_offsetof(__typeof__(*(x)), psz_object_type), \
(void)0 /* screw you */, \
(vlc_object_t *)(x))
__builtin_types_compatible_p(__typeof__((x)->obj), struct vlc_common_members), \
(vlc_object_t *)(x), (void)0)
# else
# define VLC_OBJECT( x ) \
((vlc_object_t *)(x) \
+ 0 * __builtin_offsetof(__typeof__(*(x)), psz_object_type))
((vlc_object_t *)(&((x)->obj)) \
+ 0 * __builtin_offsetof(__typeof__(*(x)), obj.object_type))
# endif
#else
# define VLC_OBJECT( x ) ((vlc_object_t *)(x))
# define VLC_OBJECT( x ) ((vlc_object_t *)&(x)->obj)
#endif
/*****************************************************************************
......
......@@ -92,7 +92,7 @@ VLC_API void libvlc_Quit( libvlc_int_t * );
static inline playlist_t *pl_Get( struct intf_thread_t *intf )
{
return (playlist_t *)(intf->p_parent);
return (playlist_t *)(intf->obj.parent);
}
/**
......
......@@ -739,7 +739,7 @@ libvlc_media_player_new( libvlc_instance_t *instance )
* FIXME: It's unclear why we want to put this in public API, and why we
* want to expose it in such a limiting and ugly way.
*/
var_AddCallback(mp->p_libvlc, "snapshot-file", snapshot_was_taken, mp);
var_AddCallback(mp->obj.libvlc, "snapshot-file", snapshot_was_taken, mp);
libvlc_retain(instance);
return mp;
......@@ -773,7 +773,7 @@ static void libvlc_media_player_destroy( libvlc_media_player_t *p_mi )
assert( p_mi );
/* Detach Callback from the main libvlc object */
var_DelCallback( p_mi->p_libvlc,
var_DelCallback( p_mi->obj.libvlc,
"snapshot-file", snapshot_was_taken, p_mi );
/* Detach callback from the media player / input manager object */
......
......@@ -118,10 +118,10 @@ static int FindVolumes(access_t *p_access, struct archive *p_archive, const char
break;
/* Probe URI */
int i_savedflags = p_access->i_flags;
p_access->i_flags |= OBJECT_FLAGS_NOINTERACT;
int i_savedflags = p_access->obj.flags;
p_access->obj.flags |= OBJECT_FLAGS_NOINTERACT;
stream_t *p_stream = stream_UrlNew(p_access, psz_newuri);
p_access->i_flags = i_savedflags;
p_access->obj.flags = i_savedflags;
if (p_stream)
{
ppsz_files[*pi_files] = psz_newuri;
......
......@@ -127,7 +127,7 @@ vlc_tls_t *vlc_https_connect(vlc_tls_creds_t *creds, const char *name,
if (port == 0)
port = 443;
int fd = vlc_tcp_connect(creds->p_parent, name, port);
int fd = vlc_tcp_connect(creds->obj.parent, name, port);
if (fd == -1)
return NULL;
......
......@@ -151,7 +151,7 @@ vlc_tls_t *vlc_https_connect_proxy(vlc_tls_creds_t *creds,
sock = vlc_https_connect(creds, url.psz_host, url.i_port, &ptwo);
else
if (!strcasecmp(url.psz_protocol, "http"))
sock = vlc_http_connect(creds ? creds->p_parent : NULL,
sock = vlc_http_connect(creds ? creds->obj.parent : NULL,
url.psz_host, url.i_port);
else
sock = NULL;
......
......@@ -162,7 +162,7 @@ nop:
msg_Info( p_demux, "command `quit'" );
p_demux->pf_demux = DemuxNoOp;
p_demux->pf_control = DemuxControl;
libvlc_Quit( p_demux->p_libvlc );
libvlc_Quit( p_demux->obj.libvlc );
return VLC_SUCCESS;
}
......
......@@ -394,10 +394,10 @@ int RarParse(stream_t *s, int *count, rar_file_t ***file, unsigned int *pi_nbvol
if (!volume_mrl)
return VLC_SUCCESS;
const int s_flags = s->i_flags;
s->i_flags |= OBJECT_FLAGS_NOINTERACT;
const int s_flags = s->obj.flags;
s->obj.flags |= OBJECT_FLAGS_NOINTERACT;
vol = stream_UrlNew(s, volume_mrl);
s->i_flags = s_flags;
s->obj.flags = s_flags;
if (!vol) {
free(volume_mrl);
......
......@@ -139,8 +139,8 @@ static int Open( vlc_object_t *p_this )
p_filter->fmt_out.audio = p_filter->fmt_in.audio;
p_filter->pf_audio_filter = DoWork;
var_Create(p_filter->p_libvlc, "audiobargraph_v-alarm", VLC_VAR_BOOL);
var_Create(p_filter->p_libvlc, "audiobargraph_v-i_values", VLC_VAR_STRING);
var_Create(p_filter->obj.libvlc, "audiobargraph_v-alarm", VLC_VAR_BOOL);
var_Create(p_filter->obj.libvlc, "audiobargraph_v-i_values", VLC_VAR_STRING);
return VLC_SUCCESS;
}
......@@ -157,7 +157,7 @@ static void SendValues(filter_t *p_filter, float *value, int nbChannels)
}
//msg_Dbg(p_filter, "values: %s", message);
var_SetString(p_filter->p_libvlc, "audiobargraph_v-i_values", msg);
var_SetString(p_filter->obj.libvlc, "audiobargraph_v-i_values", msg);
}
/*****************************************************************************
......@@ -223,7 +223,7 @@ static block_t *DoWork( filter_t *p_filter, block_t *p_in_buf )
sum = sqrtf(sum);
/* 5 - compare it to the threshold */
var_SetBool(p_filter->p_libvlc, "audiobargraph_v-alarm",
var_SetBool(p_filter->obj.libvlc, "audiobargraph_v-alarm",
sum < p_sys->alarm_threshold);
p_sys->lastAlarm = p_in_buf->i_pts;
......@@ -246,8 +246,8 @@ static void Close( vlc_object_t *p_this )
filter_t * p_filter = (filter_t *)p_this;
filter_sys_t *p_sys = p_filter->p_sys;
var_Destroy(p_filter->p_libvlc, "audiobargraph_v-i_values");
var_Destroy(p_filter->p_libvlc, "audiobargraph_v-alarm");
var_Destroy(p_filter->obj.libvlc, "audiobargraph_v-i_values");
var_Destroy(p_filter->obj.libvlc, "audiobargraph_v-alarm");
while (p_sys->first != NULL) {
ValueDate_t *current = p_sys->first;
......
......@@ -205,7 +205,7 @@ vlc_module_end ()
static int Open( vlc_object_t *p_this )
{
filter_t *p_filter = (filter_t*)p_this;
vlc_object_t *p_aout = p_filter->p_parent;
vlc_object_t *p_aout = p_filter->obj.parent;
float f_sample_rate = p_filter->fmt_in.audio.i_rate;
float f_num;
......@@ -270,7 +270,7 @@ static int Open( vlc_object_t *p_this )
static void Close( vlc_object_t *p_this )
{
filter_t *p_filter = (filter_t*)p_this;
vlc_object_t *p_aout = p_filter->p_parent;
vlc_object_t *p_aout = p_filter->obj.parent;
filter_sys_t *p_sys = p_filter->p_sys;
/* Remove our callbacks */
......
......@@ -282,7 +282,7 @@ static int EqzInit( filter_t *p_filter, int i_rate )
eqz_config_t cfg;
int i, ch;
vlc_value_t val1, val2, val3;
vlc_object_t *p_aout = p_filter->p_parent;
vlc_object_t *p_aout = p_filter->obj.parent;
int i_ret = VLC_ENOMEM;
bool b_vlcFreqs = var_InheritBool( p_aout, "equalizer-vlcfreqs" );
......@@ -451,7 +451,7 @@ static void EqzFilter( filter_t *p_filter, float *out, float *in,
static void EqzClean( filter_t *p_filter )
{
filter_sys_t *p_sys = p_filter->p_sys;
vlc_object_t *p_aout = p_filter->p_parent;
vlc_object_t *p_aout = p_filter->obj.parent;
var_DelCallback( p_aout, "equalizer-bands", BandsCallback, p_sys );
var_DelCallback( p_aout, "equalizer-preset", PresetCallback, p_sys );
......
......@@ -93,7 +93,7 @@ static int Open( vlc_object_t *p_this )
return VLC_EGENERIC;
}
p_sys->f_gain = var_InheritFloat( p_filter->p_parent, "gain-value" );
p_sys->f_gain = var_InheritFloat( p_filter->obj.parent, "gain-value" );
msg_Dbg( p_filter, "gain multiplier sets to %.2fx", p_sys->f_gain );
p_filter->fmt_out.audio = p_filter->fmt_in.audio;
......
......@@ -102,8 +102,10 @@ static int Open( vlc_object_t *p_this )
p_sys = p_filter->p_sys = malloc( sizeof( *p_sys ) );
if( !p_sys )
return VLC_ENOMEM;
p_sys->i_nb = var_CreateGetInteger( p_filter->p_parent, "norm-buff-size" );
p_sys->f_max = var_CreateGetFloat( p_filter->p_parent, "norm-max-level" );
p_sys->i_nb = var_CreateGetInteger( p_filter->obj.parent,
"norm-buff-size" );
p_sys->f_max = var_CreateGetFloat( p_filter->obj.parent,
"norm-max-level" );
if( p_sys->f_max <= 0 ) p_sys->f_max = 0.01;
......@@ -184,7 +186,8 @@ static block_t *DoWork( filter_t *p_filter, block_t *p_in_buf )
f_average = f_average / p_sys->i_nb;
/* Seuil arbitraire */
p_sys->f_max = var_GetFloat( p_filter->p_parent, "norm-max-level" );
p_sys->f_max = var_GetFloat( p_filter->obj.parent,
"norm-max-level" );
//fprintf(stderr,"Average %f, max %f\n", f_average, p_sys->f_max );
if( f_average > p_sys->f_max )
......
......@@ -132,7 +132,7 @@ static int Open( vlc_object_t *p_this )
{
filter_t *p_filter = (filter_t *)p_this;
filter_sys_t *p_sys;
vlc_object_t *p_aout = p_filter->p_parent;
vlc_object_t *p_aout = p_filter->obj.parent;
/* Allocate structure */
p_sys = p_filter->p_sys = (filter_sys_t*)malloc( sizeof( *p_sys ) );
......@@ -172,7 +172,7 @@ static void Close( vlc_object_t *p_this )
{
filter_t *p_filter = (filter_t *)p_this;
filter_sys_t *p_sys = p_filter->p_sys;
vlc_object_t *p_aout = p_filter->p_parent;
vlc_object_t *p_aout = p_filter->obj.parent;
/* Delete the callbacks */
for(unsigned i=0;i<num_callbacks;++i)
......
......@@ -581,7 +581,7 @@ static int OpenEncoder( vlc_object_t *p_this )
int status;
if( p_enc->fmt_out.i_codec != VLC_CODEC_DAALA &&
!p_enc->b_force )
!p_enc->obj.force )
{
return VLC_EGENERIC;
}
......
......@@ -1719,7 +1719,7 @@ static int OpenEncoder( vlc_object_t *p_this )
encoder_sys_t *p_sys;
if( ( p_enc->fmt_out.i_codec != VLC_CODEC_DVBS ) &&
!p_enc->b_force )
!p_enc->obj.force )
{
return VLC_EGENERIC;
}
......
......@@ -669,7 +669,7 @@ static int OpenEncoder( vlc_object_t *p_this )
encoder_sys_t *p_sys;
if( p_enc->fmt_out.i_codec != VLC_CODEC_FLAC &&
!p_enc->b_force )
!p_enc->obj.force )
{
return VLC_EGENERIC;
}
......
......@@ -53,7 +53,7 @@ vlc_module_end ()
static int OpenEncoder( vlc_object_t *p_this )
{
encoder_t *p_enc = (encoder_t *)p_this;
if( p_enc->fmt_out.i_codec != VLC_CODEC_R420 && !p_enc->b_force )
if( p_enc->fmt_out.i_codec != VLC_CODEC_R420 && !p_enc->obj.force )
return VLC_EGENERIC;
p_enc->pf_encode_video = Encode;
......
......@@ -1078,7 +1078,7 @@ static int OpenEncoder( vlc_object_t *p_this )
char *psz_tmp;
if( p_enc->fmt_out.i_codec != VLC_CODEC_DIRAC &&
!p_enc->b_force )
!p_enc->obj.force )
{
return VLC_EGENERIC;
}
......
......@@ -957,7 +957,7 @@ static int OpenEncoder( vlc_object_t *p_this )
uint8_t *p_extra;
if( p_enc->fmt_out.i_codec != VLC_CODEC_SPEEX &&
!p_enc->b_force )
!p_enc->obj.force )
{
return VLC_EGENERIC;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment