/***************************************************************************** * Decrement an object refcount * And destroy the object if its refcount reach zero. *****************************************************************************/ void vlc_object_release( vlc_object_t *p_this ) { vlc_object_internals_t *internals = vlc_internals( p_this ); vlc_object_t *parent = NULL; bool b_should_destroy; vlc_spin_lock( &internals->ref_spin ); assert( internals->i_refcount > 0 ); if( internals->i_refcount > 1 ) { /* Fast path */ /* There are still other references to the object */ internals->i_refcount--; vlc_spin_unlock( &internals->ref_spin ); return; } vlc_spin_unlock( &internals->ref_spin ); /* Slow path */ /* Remember that we cannot hold the spin while waiting on the mutex */ libvlc_lock (p_this->p_libvlc); /* Take the spin again. Note that another thread may have held the * object in the (very short) mean time. */ vlc_spin_lock( &internals->ref_spin ); b_should_destroy = --internals->i_refcount == 0; vlc_spin_unlock( &internals->ref_spin ); if( b_should_destroy ) { /* Detach from parent to protect against FIND_CHILDREN */ parent = p_this->p_parent; if (likely(parent)) { /* Unlink */ if (internals->prev != NULL) internals->prev->next = internals->next; else vlc_internals(parent)->first = internals->next; if (internals->next != NULL) internals->next->prev = internals->prev; } /* We have no children */ assert (internals->first == NULL); } libvlc_unlock (p_this->p_libvlc); if( b_should_destroy ) { int canc; canc = vlc_savecancel (); vlc_object_destroy( p_this ); vlc_restorecancel (canc); if (parent) vlc_object_release (parent); } }
/***************************************************************************** * RenderBlur: renders a blurred picture *****************************************************************************/ static void RenderBlur( filter_sys_t *p_sys, picture_t *p_newpic, picture_t *p_outpic ) { int i_plane; vlc_spin_lock( &p_sys->lock ); const int i_oldfactor = p_sys->i_factor; vlc_spin_unlock( &p_sys->lock ); int i_newfactor = 128 - i_oldfactor; for( i_plane = 0; i_plane < p_outpic->i_planes; i_plane++ ) { uint8_t *p_old, *p_new, *p_out, *p_out_end, *p_out_line_end; const int i_visible_pitch = p_outpic->p[i_plane].i_visible_pitch; const int i_visible_lines = p_outpic->p[i_plane].i_visible_lines; p_out = p_outpic->p[i_plane].p_pixels; p_new = p_newpic->p[i_plane].p_pixels; p_old = p_sys->p_tmp->p[i_plane].p_pixels; p_out_end = p_out + p_outpic->p[i_plane].i_pitch * i_visible_lines; while ( p_out < p_out_end ) { p_out_line_end = p_out + i_visible_pitch; while ( p_out < p_out_line_end ) { *p_out++ = (((*p_old++) * i_oldfactor) + ((*p_new++) * i_newfactor)) >> 7; } p_old += p_sys->p_tmp->p[i_plane].i_pitch - i_visible_pitch; p_new += p_newpic->p[i_plane].i_pitch - i_visible_pitch; p_out += p_outpic->p[i_plane].i_pitch - i_visible_pitch; } } }
libvlc_log_message_t *libvlc_log_iterator_next( libvlc_log_iterator_t *p_iter, libvlc_log_message_t *buffer, libvlc_exception_t *p_e ) { unsigned i_pos; if( !p_iter ) RAISENULL("Invalid log iterator!"); if( !buffer ) RAISENULL("Invalid message buffer!"); i_pos = p_iter->i_pos; if( i_pos != p_iter->i_end ) { msg_item_t *msg; vlc_spin_lock (&p_iter->p_data->lock); msg = p_iter->p_data->items[i_pos]; buffer->i_severity = msg->i_type; buffer->psz_type = msg->psz_object_type; buffer->psz_name = msg->psz_module; buffer->psz_header = msg->psz_header; buffer->psz_message = msg->psz_msg; vlc_spin_unlock (&p_iter->p_data->lock); p_iter->i_pos++; return buffer; } RAISENULL("No more messages"); }
libvlc_log_message_t *libvlc_log_iterator_next( libvlc_log_iterator_t *p_iter, libvlc_log_message_t *buffer ) { unsigned i_pos; if( !p_iter ) return NULL; assert (buffer != NULL); i_pos = p_iter->i_pos; if( i_pos != p_iter->i_end ) { msg_item_t *msg; vlc_spin_lock (&p_iter->p_data->lock); msg = p_iter->p_data->items[i_pos]; buffer->i_severity = msg->i_type; buffer->psz_type = msg->psz_object_type; buffer->psz_name = msg->psz_module; buffer->psz_header = msg->psz_header; buffer->psz_message = msg->psz_msg; vlc_spin_unlock (&p_iter->p_data->lock); p_iter->i_pos++; return buffer; } return NULL; }
/** **************************************************************************** * Set the destructor of a vlc object * * This function sets the destructor of the vlc object. It will be called * when the object is destroyed when the its refcount reaches 0. * (It is called by the internal function vlc_object_destroy()) *****************************************************************************/ void vlc_object_set_destructor( vlc_object_t *p_this, vlc_destructor_t pf_destructor ) { vlc_object_internals_t *p_priv = vlc_internals(p_this ); vlc_spin_lock( &p_priv->ref_spin ); p_priv->pf_destructor = pf_destructor; vlc_spin_unlock( &p_priv->ref_spin ); }
/** * Increment an object reference counter. */ void * vlc_object_hold( vlc_object_t *p_this ) { vlc_object_internals_t *internals = vlc_internals( p_this ); vlc_spin_lock( &internals->ref_spin ); /* Avoid obvious freed object uses */ assert( internals->i_refcount > 0 ); /* Increment the counter */ internals->i_refcount++; vlc_spin_unlock( &internals->ref_spin ); return p_this; }
static void handler( msg_cb_data_t *d, const msg_item_t *p_item ) { if (p_item->i_type > d->verbosity) return; msg_item_t *msg = msg_Copy (p_item); vlc_spin_lock (&d->lock); if (d->count < VLC_MSG_QSIZE) d->items[d->count++] = msg; vlc_spin_unlock (&d->lock); }
static void handler( msg_cb_data_t *d, msg_item_t *p_item, unsigned i_drop ) { if (p_item->i_type > d->verbosity) return; vlc_spin_lock (&d->lock); if (d->count < VLC_MSG_QSIZE) { d->items[d->count++] = p_item; msg_Hold (p_item); } vlc_spin_unlock (&d->lock); (void)i_drop; }
void libvlc_log_clear( libvlc_log_t *p_log ) { if( !p_log ) return; vlc_spin_lock (&p_log->data.lock); msg_item_t *tab[p_log->data.count]; memcpy (tab, p_log->data.items, sizeof (tab)); p_log->data.count = 0; vlc_spin_unlock (&p_log->data.lock); for (unsigned i = 0; i < sizeof (tab) / sizeof (tab[0]); i++) msg_Free (tab[i]); }
static int MotionBlurCallback( vlc_object_t *p_this, char const *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { VLC_UNUSED(p_this); VLC_UNUSED(oldval); filter_sys_t *p_sys = (filter_sys_t *)p_data; if( !strcmp( psz_var, FILTER_PREFIX "factor" ) ) { vlc_spin_lock( &p_sys->lock ); p_sys->i_factor = __MIN( 127, __MAX( 1, newval.i_int ) ); vlc_spin_unlock( &p_sys->lock ); } return VLC_SUCCESS; }
unsigned libvlc_log_count( const libvlc_log_t *p_log ) { if( !p_log ) return 0; msg_cb_data_t *data = &((libvlc_log_t *)p_log)->data; unsigned ret; /* We cannot lock due to constant pointer constraints. Break them. * Even then, this si not really thread safe anyway. */ vlc_spin_lock (&data->lock); ret = data->count; vlc_spin_unlock (&data->lock); return ret; }
void libvlc_log_clear( libvlc_log_t *p_log, libvlc_exception_t *p_e ) { if( p_log ) { vlc_spin_lock (&p_log->data.lock); msg_item_t *tab[p_log->data.count]; memcpy (tab, p_log->data.items, sizeof (tab)); p_log->data.count = 0; vlc_spin_unlock (&p_log->data.lock); for (unsigned i = 0; i < sizeof (tab) / sizeof (tab[0]); i++) msg_Release (tab[i]); } else RAISEVOID("Invalid log object!"); }
unsigned libvlc_log_count( const libvlc_log_t *p_log, libvlc_exception_t *p_e ) { if( p_log ) { msg_cb_data_t *data = &((libvlc_log_t *)p_log)->data; unsigned ret; /* We cannot lock due to constant pointer constraints. Break them. * Even then, this si not really thread safe anyway. */ vlc_spin_lock (&data->lock); ret = data->count; vlc_spin_unlock (&data->lock); return ret; } RAISEZERO("Invalid log object!"); }
libvlc_log_iterator_t *libvlc_log_get_iterator( const libvlc_log_t *p_log, libvlc_exception_t *p_e ) { if( p_log ) { struct libvlc_log_iterator_t *p_iter = (struct libvlc_log_iterator_t *)malloc(sizeof(struct libvlc_log_iterator_t)); /* FIXME: break constant pointer constraints */ msg_cb_data_t *data = &((libvlc_log_t *)p_log)->data; if( !p_iter ) RAISENULL( "Out of memory" ); vlc_spin_lock (&data->lock); p_iter->p_data = data; p_iter->i_pos = 0; p_iter->i_end = data->count; vlc_spin_unlock (&data->lock); return p_iter; } RAISENULL("Invalid log object!"); }
libvlc_log_iterator_t *libvlc_log_get_iterator( const libvlc_log_t *p_log ) { if (p_log == NULL) return NULL; struct libvlc_log_iterator_t *p_iter = malloc (sizeof (*p_iter)); if (unlikely(p_iter == NULL)) { libvlc_printerr ("Not enough memory"); return NULL; } /* FIXME: break constant pointer constraints */ msg_cb_data_t *data = &((libvlc_log_t *)p_log)->data; vlc_spin_lock (&data->lock); p_iter->p_data = data; p_iter->i_pos = 0; p_iter->i_end = data->count; vlc_spin_unlock (&data->lock); return p_iter; }
static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) { picture_t *p_outpic; filter_sys_t *p_sys = p_filter->p_sys; if( !p_pic ) return NULL; p_outpic = filter_NewPicture( p_filter ); if( !p_outpic ) { picture_Release( p_pic ); return NULL; } vlc_spin_lock( &p_sys->lock ); const int i_sin = p_sys->i_sin; const int i_cos = p_sys->i_cos; vlc_spin_unlock( &p_sys->lock ); for( int i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ ) { const int i_visible_lines = p_pic->p[i_plane].i_visible_lines; const int i_visible_pitch = p_pic->p[i_plane].i_visible_pitch; const int i_pitch = p_pic->p[i_plane].i_pitch; const int i_hidden_pitch = i_pitch - i_visible_pitch; const int i_aspect = __MAX( 1, ( i_visible_lines * p_pic->p[Y_PLANE].i_visible_pitch ) / ( p_pic->p[Y_PLANE].i_visible_lines * i_visible_pitch )); /* = 2 for U and V planes in YUV 4:2:2, = 1 otherwise */ const int i_line_center = i_visible_lines>>1; const int i_col_center = i_visible_pitch>>1; const uint8_t *p_in = p_pic->p[i_plane].p_pixels; uint8_t *p_out = p_outpic->p[i_plane].p_pixels; uint8_t *p_outendline = p_out + i_visible_pitch; const uint8_t *p_outend = p_out + i_visible_lines * i_pitch; const uint8_t black_pixel = ( i_plane == Y_PLANE ) ? 0x00 : 0x80; const int i_line_next = i_cos / i_aspect -i_sin*i_visible_pitch; const int i_col_next = -i_sin / i_aspect -i_cos*i_visible_pitch; int i_line_orig0 = ( - i_cos * i_line_center / i_aspect - i_sin * i_col_center + (1<<11) ); int i_col_orig0 = i_sin * i_line_center / i_aspect - i_cos * i_col_center + (1<<11); for( ; p_outendline < p_outend; p_out += i_hidden_pitch, p_outendline += i_pitch, i_line_orig0 += i_line_next, i_col_orig0 += i_col_next ) { for( ; p_out < p_outendline; p_out++, i_line_orig0 += i_sin, i_col_orig0 += i_cos ) { const int i_line_orig = (i_line_orig0>>12)*i_aspect + i_line_center; const int i_col_orig = (i_col_orig0>>12) + i_col_center; const uint8_t* p_orig_offset = p_in + i_line_orig * i_pitch + i_col_orig; const uint8_t i_line_percent = (i_line_orig0>>4) & 255; const uint8_t i_col_percent = (i_col_orig0 >>4) & 255; if( -1 <= i_line_orig && i_line_orig < i_visible_lines && -1 <= i_col_orig && i_col_orig < i_visible_pitch ) { #define test 1 #undef test #ifdef test if( ( i_col_orig > i_visible_pitch/2 ) ) #endif { uint8_t i_curpix = black_pixel; uint8_t i_colpix = black_pixel; uint8_t i_linpix = black_pixel; uint8_t i_nexpix = black_pixel; if( ( 0 <= i_line_orig ) && ( 0 <= i_col_orig ) ) i_curpix = *p_orig_offset; p_orig_offset++; if( ( i_col_orig < i_visible_pitch - 1) && ( i_line_orig >= 0 ) ) i_colpix = *p_orig_offset; p_orig_offset+=i_pitch; if( ( i_line_orig < i_visible_lines - 1) && ( i_col_orig < i_visible_pitch - 1) ) i_nexpix = *p_orig_offset; p_orig_offset--; if( ( i_line_orig < i_visible_lines - 1) && ( i_col_orig >= 0 ) ) i_linpix = *p_orig_offset; unsigned int temp = 0; temp+= i_curpix * (256 - i_line_percent) * ( 256 - i_col_percent ); temp+= i_linpix * i_line_percent * (256 - i_col_percent ); temp+= i_nexpix * ( i_col_percent) * ( i_line_percent); temp+= i_colpix * i_col_percent * (256 - i_line_percent ); *p_out = temp >> 16; } #ifdef test else if (i_col_orig == i_visible_pitch/2 ) { *p_out = black_pixel; } else *p_out = *p_orig_offset; #endif #undef test } else { *p_out = black_pixel; } }