static void* Raw1394EventThread( vlc_object_t *p_this ) { event_thread_t *p_ev = (event_thread_t *) p_this; access_t *p_access = (access_t *) p_ev->p_access; access_sys_t *p_sys = (access_sys_t *) p_access->p_sys; int result = 0; int canc = vlc_savecancel (); AVCPlay( p_access, p_sys->i_node ); while( vlc_object_alive (p_sys->p_ev) ) { while( ( result = poll( &(p_sys->raw1394_poll), 1, 200 ) ) < 0 ) { if( !( errno == EAGAIN || errno == EINTR ) ) { perror( "error: raw1394 poll" ); msg_Err( p_access, "retrying device raw1394" ); } } if( !vlc_object_alive (p_sys->p_ev) ) break; if( result > 0 && ( ( p_sys->raw1394_poll.revents & POLLIN ) || ( p_sys->raw1394_poll.revents & POLLPRI ) ) ) result = raw1394_loop_iterate( p_sys->p_raw1394 ); } AVCStop( p_access, p_sys->i_node ); vlc_restorecancel (canc); return NULL; }
/** * Run the main control thread itself */ static void* RunControlThread ( vlc_object_t *p_this ) { playlist_t *p_playlist = (playlist_t*)p_this; /* Tell above that we're ready */ vlc_thread_ready( p_playlist ); vlc_object_lock( p_playlist ); while( vlc_object_alive( p_playlist ) ) { playlist_MainLoop( p_playlist ); /* The playlist lock has been unlocked, so we can't tell if * someone has killed us in the meantime. Check now. */ if( !vlc_object_alive( p_playlist ) ) break; if( p_playlist->b_cant_sleep ) { /* 100 ms is an acceptable delay for playlist operations */ vlc_object_unlock( p_playlist ); msleep( INTF_IDLE_SLEEP*2 ); vlc_object_lock( p_playlist ); } else { vlc_object_wait( p_playlist ); } } vlc_object_unlock( p_playlist ); playlist_LastLoop( p_playlist ); return NULL; }
/***************************************************************************** * ALSAThread: asynchronous thread used to DMA the data to the device *****************************************************************************/ static void* ALSAThread( vlc_object_t* p_this ) { aout_instance_t * p_aout = (aout_instance_t*)p_this; struct aout_sys_t * p_sys = p_aout->output.p_sys; int canc = vlc_savecancel (); p_sys->p_status = (snd_pcm_status_t *)malloc(snd_pcm_status_sizeof()); /* Wait for the exact time to start playing (avoids resampling) */ vlc_mutex_lock( &p_sys->lock ); while( !p_sys->start_date && vlc_object_alive (p_aout) ) vlc_cond_wait( &p_sys->wait, &p_sys->lock ); vlc_mutex_unlock( &p_sys->lock ); if( !vlc_object_alive (p_aout) ) goto cleanup; mwait( p_sys->start_date - AOUT_PTS_TOLERANCE / 4 ); while ( vlc_object_alive (p_aout) ) { ALSAFill( p_aout ); } cleanup: snd_pcm_drop( p_sys->p_snd_pcm ); free( p_aout->output.p_sys->p_status ); vlc_restorecancel (canc); return NULL; }
/***************************************************************************** * RunIntf: main loop *****************************************************************************/ static void RunIntf( intf_thread_t *p_intf ) { int canc = vlc_savecancel( ); /* Main loop */ while( vlc_object_alive( p_intf ) ) { vlc_mutex_lock( &p_intf->p_sys->lock ); /* Notify the interfaces */ if( p_intf->p_sys->b_triggered ) { var_SetBool( p_intf->p_libvlc, "intf-show", true ); p_intf->p_sys->b_triggered = false; } vlc_mutex_unlock( &p_intf->p_sys->lock ); /* Take care of the video output */ if( p_intf->p_sys->p_vout && !vlc_object_alive (p_intf->p_sys->p_vout) ) { var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved", MouseEvent, p_intf ); var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down", MouseEvent, p_intf ); vlc_object_release( p_intf->p_sys->p_vout ); p_intf->p_sys->p_vout = NULL; } if( p_intf->p_sys->p_vout == NULL ) { p_intf->p_sys->p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE ); if( p_intf->p_sys->p_vout ) { var_AddCallback( p_intf->p_sys->p_vout, "mouse-moved", MouseEvent, p_intf ); var_AddCallback( p_intf->p_sys->p_vout, "mouse-button-down", MouseEvent, p_intf ); } } /* Wait a bit */ msleep( INTF_IDLE_SLEEP ); } if( p_intf->p_sys->p_vout ) { var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved", MouseEvent, p_intf ); var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down", MouseEvent, p_intf ); vlc_object_release( p_intf->p_sys->p_vout ); } vlc_restorecancel( canc ); }
static void LoopRequest( playlist_t *p_playlist ) { playlist_private_t *p_sys = pl_priv(p_playlist); assert( !p_sys->p_input ); /* No input. Several cases * - No request, running status -> start new item * - No request, stopped status -> collect garbage * - Request, running requested -> start new item * - Request, stopped requested -> collect garbage */ const int i_status = p_sys->request.b_request ? p_sys->request.i_status : p_sys->status.i_status; if( i_status == PLAYLIST_STOPPED || !vlc_object_alive( p_playlist ) ) { p_sys->status.i_status = PLAYLIST_STOPPED; if( p_sys->p_input_resource && input_resource_HasVout( p_sys->p_input_resource ) ) { /* XXX We can unlock if we don't issue the wait as we will be * call again without anything else done between the calls */ PL_UNLOCK; /* input_resource_t must be manipulated without playlist lock */ input_resource_TerminateVout( p_sys->p_input_resource ); PL_LOCK; } else { if( vlc_object_alive( p_playlist ) ) vlc_cond_wait( &p_sys->signal, &p_sys->lock ); } return; } playlist_item_t *p_item = NextItem( p_playlist ); if( p_item ) { msg_Dbg( p_playlist, "starting playback of the new playlist item" ); PlayItem( p_playlist, p_item ); return; } msg_Dbg( p_playlist, "nothing to play" ); p_sys->status.i_status = PLAYLIST_STOPPED; if( var_GetBool( p_playlist, "play-and-exit" ) ) { msg_Info( p_playlist, "end of playlist, exiting" ); libvlc_Quit( p_playlist->p_libvlc ); } }
static void* EncoderThread( vlc_object_t* p_this ) { sout_stream_sys_t *p_sys = (sout_stream_sys_t*)p_this; sout_stream_id_t *id = p_sys->id_video; picture_t *p_pic; int canc = vlc_savecancel (); while( vlc_object_alive (p_sys) && !p_sys->b_error ) { block_t *p_block; vlc_mutex_lock( &p_sys->lock_out ); while( p_sys->i_last_pic == p_sys->i_first_pic ) { vlc_cond_wait( &p_sys->cond, &p_sys->lock_out ); if( !vlc_object_alive (p_sys) || p_sys->b_error ) break; } if( !vlc_object_alive (p_sys) || p_sys->b_error ) { vlc_mutex_unlock( &p_sys->lock_out ); break; } p_pic = p_sys->pp_pics[p_sys->i_first_pic++]; p_sys->i_first_pic %= PICTURE_RING_SIZE; vlc_mutex_unlock( &p_sys->lock_out ); video_timer_start( id->p_encoder ); p_block = id->p_encoder->pf_encode_video( id->p_encoder, p_pic ); video_timer_stop( id->p_encoder ); vlc_mutex_lock( &p_sys->lock_out ); block_ChainAppend( &p_sys->p_buffers, p_block ); vlc_mutex_unlock( &p_sys->lock_out ); picture_Release( p_pic ); } while( p_sys->i_last_pic != p_sys->i_first_pic ) { p_pic = p_sys->pp_pics[p_sys->i_first_pic++]; p_sys->i_first_pic %= PICTURE_RING_SIZE; picture_Release( p_pic ); } block_ChainRelease( p_sys->p_buffers ); vlc_restorecancel (canc); return NULL; }
/** * Run the main control thread itself */ static void *Thread ( void *data ) { playlist_t *p_playlist = data; playlist_private_t *p_sys = pl_priv(p_playlist); playlist_Lock( p_playlist ); while( vlc_object_alive( p_playlist ) || p_sys->p_input ) { /* FIXME: what's that ! */ if( p_sys->b_reset_currently_playing && mdate() - p_sys->last_rebuild_date > 30000 ) // 30 ms { ResetCurrentlyPlaying( p_playlist, get_current_status_item( p_playlist ) ); p_sys->last_rebuild_date = mdate(); } /* If there is an input, check that it doesn't need to die. */ while( !LoopInput( p_playlist ) ) vlc_cond_wait( &p_sys->signal, &p_sys->lock ); LoopRequest( p_playlist ); } playlist_Unlock( p_playlist ); return NULL; }
/* Define the Input used. Add the callbacks on input p_input is held once here */ void InputManager::setInput( input_thread_t *_p_input ) { delInput(); p_input = _p_input; if( p_input && !( p_input->b_dead || !vlc_object_alive (p_input) ) ) { msg_Dbg( p_intf, "IM: Setting an input" ); vlc_object_hold( p_input ); addCallbacks(); UpdateStatus(); UpdateName(); UpdateArt(); UpdateTeletext(); UpdateNavigation(); UpdateVout(); p_item = input_GetItem( p_input ); emit rateChanged( var_GetFloat( p_input, "rate" ) ); } else { p_input = NULL; p_item = NULL; assert( !p_input_vbi ); emit rateChanged( var_InheritFloat( p_intf, "rate" ) ); } }
/** * @brief Directory Monitoring thread loop */ void *RunMonitoringThread( void *p_this ) { monitoring_thread_t *p_mon = (monitoring_thread_t*) p_this; vlc_cond_init( &p_mon->wait ); vlc_mutex_init( &p_mon->lock ); var_Create( p_mon, "ml-recursive-scan", VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); while( vlc_object_alive( p_mon ) ) { vlc_mutex_lock( &p_mon->lock ); /* Update */ UpdateLibrary( p_mon ); /* We wait MONITORING_DELAY seconds or wait that the media library signals us to do something */ vlc_cond_timedwait( &p_mon->wait, &p_mon->lock, mdate() + 1000000*MONITORING_DELAY ); vlc_mutex_unlock( &p_mon->lock ); } vlc_cond_destroy( &p_mon->wait ); vlc_mutex_destroy( &p_mon->lock ); return NULL; }
/***************************************************************************** * MonitorLibVLCDeath: Used when b_should_run_on_first_thread is set. *****************************************************************************/ static void * MonitorLibVLCDeath( vlc_object_t * p_this ) { intf_thread_t *p_intf = (intf_thread_t *)p_this; libvlc_int_t * p_libvlc = p_intf->p_libvlc; vlc_object_lock( p_libvlc ); while(vlc_object_alive( p_libvlc ) ) { if(p_intf->b_die) { vlc_object_unlock( p_libvlc ); return NULL; } vlc_object_wait( p_libvlc ); } vlc_object_unlock( p_libvlc ); /* Someone killed libvlc */ /* Make sure we kill all interface objects, especially * those that are blocking libvlc (running on main thread) */ vlc_list_t * p_list = vlc_list_find( p_libvlc, VLC_OBJECT_INTF, FIND_CHILD ); for( int i = 0; i < p_list->i_count; i++ ) { vlc_object_t * p_intf = p_list->p_values[i].p_object; vlc_object_kill( p_intf ); } vlc_list_release( p_list ); return NULL; }
/***************************************************************************** * Open: *****************************************************************************/ static int Open( vlc_object_t *p_this ) { access_t *p_access = (access_t*)p_this; /* use specified method */ if( *p_access->psz_access ) { if( !strncmp( p_access->psz_access, "mmsu", 4 ) ) { return MMSTUOpen ( p_access ); } else if( !strncmp( p_access->psz_access, "mmst", 4 ) ) { return MMSTUOpen ( p_access ); } else if( !strncmp( p_access->psz_access, "mmsh", 4 ) || !strncmp( p_access->psz_access, "http", 4 ) ) { return MMSHOpen ( p_access ); } } if( MMSTUOpen ( p_access ) ) { if( !vlc_object_alive(p_access) ) return VLC_EGENERIC; /* try mmsh if mmstu failed */ return MMSHOpen ( p_access ); } return VLC_SUCCESS; }
static void Process( intf_thread_t *p_intf ) { for( ;; ) { char *code, *c; if( lirc_nextcode( &code ) ) return; if( code == NULL ) return; while( vlc_object_alive( p_intf ) && (lirc_code2char( p_intf->p_sys->config, code, &c ) == 0) && (c != NULL) ) { if( !strncmp( "key-", c, 4 ) ) { vlc_action_t i_key = vlc_GetActionId( c ); if( i_key ) var_SetInteger( p_intf->p_libvlc, "key-action", i_key ); else msg_Err( p_intf, "Unknown hotkey '%s'", c ); } else { msg_Err( p_intf, "this doesn't appear to be a valid keycombo " "lirc sent us. Please look at the " "doc/lirc/example.lirc file in VLC" ); break; } } free( code ); } }
/** * Add an input item to a given node * * \param p_playlist the playlist to add into * \param p_input the input item to add * \param p_parent the parent item to add into * \param i_mode the mode used when addin * \param i_pos the position in the playlist where to add. If this is * PLAYLIST_END the item will be added at the end of the playlist * regardless of its size * \param b_locked TRUE if the playlist is locked * \return the new playlist item */ playlist_item_t * playlist_NodeAddInput( playlist_t *p_playlist, input_item_t *p_input, playlist_item_t *p_parent, int i_mode, int i_pos, bool b_locked ) { playlist_item_t *p_item; assert( p_input ); assert( p_parent && p_parent->i_children != -1 ); /* FIXME: use b_killed instead: */ if( !vlc_object_alive(p_playlist) ) return NULL; PL_LOCK_IF( !b_locked ); p_item = playlist_ItemNewFromInput( p_playlist, p_input ); if( p_item == NULL ) return NULL; AddItem( p_playlist, p_item, p_parent, i_mode, i_pos ); GoAndPreparse( p_playlist, i_mode, p_item ); PL_UNLOCK_IF( !b_locked ); return p_item; }
/***************************************************************************** * Render: display previously rendered output ***************************************************************************** * This function sends the currently rendered image to Crop image, waits * until it is displayed and switches the two rendering buffers, preparing next * frame. *****************************************************************************/ static void Render( vout_thread_t *p_vout, picture_t *p_pic ) { picture_t *p_outpic = NULL; int i_plane; if( p_vout->p_sys->b_changed ) { return; } while( ( p_outpic = vout_CreatePicture( p_vout->p_sys->p_vout, 0, 0, 0 ) ) == NULL ) { if( !vlc_object_alive (p_vout) || p_vout->b_error ) { vout_DestroyPicture( p_vout->p_sys->p_vout, p_outpic ); return; } msleep( VOUT_OUTMEM_SLEEP ); } p_outpic->date = p_pic->date; vout_LinkPicture( p_vout->p_sys->p_vout, p_outpic ); for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ ) { uint8_t *p_in, *p_out, *p_out_end; int i_in_pitch = p_pic->p[i_plane].i_pitch; const int i_out_pitch = p_outpic->p[i_plane].i_pitch; const int i_copy_pitch = p_outpic->p[i_plane].i_visible_pitch; p_in = p_pic->p[i_plane].p_pixels /* Skip the right amount of lines */ + i_in_pitch * ( p_pic->p[i_plane].i_visible_lines * p_vout->p_sys->i_y / p_vout->output.i_height ) /* Skip the right amount of columns */ + i_in_pitch * p_vout->p_sys->i_x / p_vout->output.i_width; p_out = p_outpic->p[i_plane].p_pixels; p_out_end = p_out + i_out_pitch * p_outpic->p[i_plane].i_visible_lines; while( p_out < p_out_end ) { vlc_memcpy( p_out, p_in, i_copy_pitch ); p_in += i_in_pitch; p_out += i_out_pitch; } } vout_UnlinkPicture( p_vout->p_sys->p_vout, p_outpic ); vout_DisplayPicture( p_vout->p_sys->p_vout, p_outpic ); /* The source image may still be in the cache ... parse it! */ vlc_mutex_lock( &p_vout->p_sys->lock ); if( p_vout->p_sys->b_autocrop ) UpdateStats( p_vout, p_pic ); vlc_mutex_unlock( &p_vout->p_sys->lock ); }
bool hasInput() { return p_input /* We have an input */ && !p_input->b_dead /* not dead yet, */ && !p_input->b_eof /* not EOF either, */ && vlc_object_alive (p_input); /* and the VLC object is alive */ }
/***************************************************************************** * Render: displays previously rendered output ***************************************************************************** * This function send the currently rendered image to the internal opencv * filter for processing. *****************************************************************************/ static void Render( vout_thread_t *p_vout, picture_t *p_pic ) { picture_t *p_outpic = NULL; clock_t start, finish; double duration; while( ( p_outpic = vout_CreatePicture( p_vout->p_sys->p_vout, 0, 0, 0 ) ) == NULL ) { if( !vlc_object_alive (p_vout) || p_vout->b_error ) { return; } msleep( VOUT_OUTMEM_SLEEP ); } vout_LinkPicture( p_vout->p_sys->p_vout, p_outpic ); start = clock(); if (p_vout->p_sys->i_wrapper_output == VINPUT) //output = input video { //This copy is a bit unfortunate but image_Convert can't write into an existing image so it is better to copy the //(say) 16bit YUV image here than a 32bit RGB image somehwere else. //It is also not that expensive in time. picture_Copy( p_outpic, p_pic ); VlcPictureToIplImage( p_vout, p_pic); //pass the image to the internal opencv filter for processing if ((p_vout->p_sys->p_opencv) && (p_vout->p_sys->p_opencv->p_module)) p_vout->p_sys->p_opencv->pf_video_filter( p_vout->p_sys->p_opencv, &(p_vout->p_sys->hacked_pic)); } else //output = processed video (NONE option not working yet) { VlcPictureToIplImage( p_vout, p_pic); //pass the image to the internal opencv filter for processing if ((p_vout->p_sys->p_opencv) && (p_vout->p_sys->p_opencv->p_module)) p_vout->p_sys->p_opencv->pf_video_filter( p_vout->p_sys->p_opencv, &(p_vout->p_sys->hacked_pic)); //copy the processed image into the output image if ((p_vout->p_sys->p_proc_image) && (p_vout->p_sys->p_proc_image->i_planes > 0)) picture_Copy( p_outpic, p_vout->p_sys->p_proc_image ); } //calculate duration finish = clock(); duration = (double)(finish - start) / CLOCKS_PER_SEC; if (p_vout->p_sys->i_verbosity > VERB_WARN) msg_Dbg( p_vout, "Render took %2.4f seconds", duration ); ReleaseImages(p_vout); p_outpic->date = p_pic->date; vout_UnlinkPicture( p_vout->p_sys->p_vout, p_outpic ); vout_DisplayPicture( p_vout->p_sys->p_vout, p_outpic ); }
static int WindowOpen( vout_window_t *pWnd, const vout_window_cfg_t *cfg ) { vout_window_sys_t* sys; vlc_mutex_lock( &skin_load.mutex ); intf_thread_t *pIntf = skin_load.intf; if( pIntf ) vlc_object_hold( pIntf ); vlc_mutex_unlock( &skin_load.mutex ); if( pIntf == NULL ) return VLC_EGENERIC; if( !vlc_object_alive( pIntf ) || !var_InheritBool( pIntf, "skinned-video") || cfg->is_standalone ) { vlc_object_release( pIntf ); return VLC_EGENERIC; } sys = (vout_window_sys_t*)calloc( 1, sizeof( *sys ) ); if( !sys ) { vlc_object_release( pIntf ); return VLC_ENOMEM; } pWnd->sys = sys; pWnd->sys->cfg = *cfg; pWnd->sys->pIntf = pIntf; pWnd->control = WindowControl; // force execution in the skins2 thread context CmdExecuteBlock* cmd = new CmdExecuteBlock( pIntf, VLC_OBJECT( pWnd ), WindowOpenLocal ); CmdExecuteBlock::executeWait( CmdGenericPtr( cmd ) ); #ifdef X11_SKINS if( !pWnd->handle.xid ) #else if( !pWnd->handle.hwnd ) #endif { free( sys ); vlc_object_release( pIntf ); return VLC_EGENERIC; } return VLC_SUCCESS; }
static int LoopInput( playlist_t *p_playlist ) { playlist_private_t *p_sys = pl_priv(p_playlist); input_thread_t *p_input = p_sys->p_input; if( !p_input ) return VLC_EGENERIC; if( ( p_sys->request.b_request || !vlc_object_alive( p_playlist ) ) && !p_input->b_die ) { PL_DEBUG( "incoming request - stopping current input" ); input_Stop( p_input, true ); } /* This input is dead. Remove it ! */ if( p_input->b_dead ) { PL_DEBUG( "dead input" ); PL_UNLOCK; /* We can unlock as we return VLC_EGENERIC (no event will be lost) */ /* input_resource_t must be manipulated without playlist lock */ if( !var_CreateGetBool( p_input, "sout-keep" ) ) input_resource_TerminateSout( p_sys->p_input_resource ); /* The DelCallback must be issued without playlist lock */ var_DelCallback( p_input, "intf-event", InputEvent, p_playlist ); PL_LOCK; p_sys->p_input = NULL; input_Close( p_input ); UpdateActivity( p_playlist, -DEFAULT_INPUT_ACTIVITY ); return VLC_EGENERIC; } /* This input is dying, let it do */ else if( p_input->b_die ) { PL_DEBUG( "dying input" ); } /* This input has finished, ask it to die ! */ else if( p_input->b_error || p_input->b_eof ) { PL_DEBUG( "finished input" ); input_Stop( p_input, false ); } return VLC_SUCCESS; }
void VlcProc::manage() { // Did the user request to quit vlc ? if( !vlc_object_alive( getIntf() ) ) { // Get the instance of OSFactory OSFactory *pOsFactory = OSFactory::instance( getIntf() ); // Exit the main OS loop pOsFactory->getOSLoop()->exit(); return; } }
static void* update_request_thread( vlc_object_t *p_thread_obj ) { filter_t* p_filter = (filter_t*)(p_thread_obj->p_parent); filter_sys_t *p_sys = p_filter->p_sys; int canc = vlc_savecancel (); msg_Dbg( p_filter, "VNC update request thread started" ); rfbFramebufferUpdateRequestMsg udr; udr.type = rfbFramebufferUpdateRequest; udr.incremental = 0; udr.x = 0; udr.y = 0; udr.w = htons(p_sys->i_vnc_width); udr.h = htons(p_sys->i_vnc_height); if( !write_exact(p_filter, p_sys->i_socket, (char*)&udr, sz_rfbFramebufferUpdateRequestMsg) ) { msg_Err( p_filter, "Could not write rfbFramebufferUpdateRequestMsg." ); p_sys->b_continue = false; return NULL; } udr.incremental = 1; mtime_t i_poll_interval_microsec = p_sys->i_vnc_poll_interval * 1000; if( p_sys->b_vnc_poll) { while( vlc_object_alive( p_thread_obj ) ) { msleep( i_poll_interval_microsec ); if( !write_exact(p_filter, p_sys->i_socket, (char*)&udr, sz_rfbFramebufferUpdateRequestMsg)) { msg_Err( p_filter, "Could not write rfbFramebufferUpdateRequestMsg." ); break; } } p_sys->b_continue = false; } else { msg_Dbg( p_filter, "VNC polling disabled." ); } msg_Dbg( p_filter, "VNC update request thread ended" ); vlc_restorecancel (canc); return NULL; }
/***************************************************************************** * Thread: thread used to DMA the data to the device *****************************************************************************/ static void* Thread( vlc_object_t *p_this ) { aout_instance_t * p_aout = (aout_instance_t*)p_this; aout_buffer_t * p_buffer; struct aout_sys_t * p_sys = p_aout->output.p_sys; PCMAudioPlayer * pPlayer = p_sys->pPlayer; int canc = vlc_savecancel (); while( vlc_object_alive (p_aout) ) { pPlayer->WaitForBuffer(); vlc_mutex_lock( &p_aout->output_fifo_lock ); p_buffer = aout_FifoPop( p_aout, &p_aout->output.fifo ); vlc_mutex_unlock( &p_aout->output_fifo_lock ); #define i p_sys->nNextBufferIndex if( p_buffer == NULL ) { vlc_memset( p_aout, p_sys->ppBuffers[ i ], 0, p_sys->nBufferSize ); } else { InterleaveS16( (int16_t *)p_buffer->p_buffer, (int16_t *)p_sys->ppBuffers[ i ] ); aout_BufferFree( p_buffer ); } if( !pPlayer->QueueBuffer( (s16 *)p_sys->ppBuffers[ i ], p_sys->nBufferSize / 2 ) ) { msg_Err( p_aout, "QueueBuffer failed" ); } i = (i + 1) % p_sys->nBuffers; #undef i } vlc_restorecancel (canc); return NULL; }
/***************************************************************************** * Render: displays previously rendered output ***************************************************************************** * This function send the currently rendered image to Transform image, waits * until it is displayed and switch the two rendering buffers, preparing next * frame. *****************************************************************************/ static void Render( vout_thread_t *p_vout, picture_t *p_pic ) { picture_t *p_outpic; /* This is a new frame. Get a structure from the video_output. */ while( ( p_outpic = vout_CreatePicture( p_vout->p_sys->p_vout, 0, 0, 0 ) ) == NULL ) { if( !vlc_object_alive (p_vout) || p_vout->b_error ) { return; } msleep( VOUT_OUTMEM_SLEEP ); } p_outpic->date = p_pic->date; p_vout->p_sys->pf_filter( p_vout, p_pic, p_outpic ); vout_DisplayPicture( p_vout->p_sys->p_vout, p_outpic ); }
// Callbacks for vout requests static int WindowOpen( vlc_object_t *p_this ) { vout_window_t *pWnd = (vout_window_t *)p_this; vlc_mutex_lock( &skin_load.mutex ); intf_thread_t *pIntf = skin_load.intf; if( pIntf ) vlc_object_hold( pIntf ); vlc_mutex_unlock( &skin_load.mutex ); if( pIntf == NULL ) return VLC_EGENERIC; if( !vlc_object_alive( pIntf ) || !var_InheritBool( pIntf, "skinned-video") || pWnd->cfg->is_standalone ) { vlc_object_release( pIntf ); return VLC_EGENERIC; } vlc_mutex_lock( &serializer ); pWnd->handle.hwnd = VoutManager::getWindow( pIntf, pWnd ); if( pWnd->handle.hwnd ) { pWnd->control = &VoutManager::controlWindow; pWnd->sys = (vout_window_sys_t*)pIntf; vlc_mutex_unlock( &serializer ); return VLC_SUCCESS; } else { vlc_object_release( pIntf ); vlc_mutex_unlock( &serializer ); return VLC_EGENERIC; } }
/***************************************************************************** * DoWork: convert a buffer ***************************************************************************** * Audio part pasted from trivial.c ****************************************************************************/ static block_t *DoWork( filter_t *p_filter, block_t *p_in_buf ) { filter_sys_t *p_sys = p_filter->p_sys; picture_t *p_outpic; int i; /* First, get a new picture */ while( ( p_outpic = vout_CreatePicture( p_sys->p_vout, 0, 0, 3 ) ) == NULL) { /* XXX: This looks like a bad idea. Don't run to me for sympathy if it * dead locks... */ if( !vlc_object_alive (p_sys->p_vout) ) return NULL; msleep( VOUT_OUTMEM_SLEEP ); } /* Blank the picture */ for( i = 0 ; i < p_outpic->i_planes ; i++ ) { memset( p_outpic->p[i].p_pixels, i > 0 ? 0x80 : 0x00, p_outpic->p[i].i_visible_lines * p_outpic->p[i].i_pitch ); } /* We can now call our visualization effects */ for( i = 0; i < p_sys->i_effect; i++ ) { #define p_effect p_sys->effect[i] if( p_effect->pf_run ) { p_effect->pf_run( p_effect, VLC_OBJECT(p_filter), p_in_buf, p_outpic ); } #undef p_effect } p_outpic->date = p_in_buf->i_pts + (p_in_buf->i_length / 2); vout_DisplayPicture( p_sys->p_vout, p_outpic ); return p_in_buf; }
/** * Gets a datagram from the network. * @param fd datagram file descriptor * @return a block or NULL on fatal error (socket dead) */ static block_t *rtp_dgram_recv (vlc_object_t *obj, int fd) { block_t *block = block_Alloc (0xffff); ssize_t len; block_cleanup_push (block); do { len = net_Read (obj, fd, NULL, block->p_buffer, block->i_buffer, false); if (((len <= 0) && fd_dead (fd)) || !vlc_object_alive (obj)) { /* POLLHUP -> permanent (DCCP) socket error */ block_Release (block); block = NULL; break; } } while (len == -1); vlc_cleanup_pop (); return block ? block_Realloc (block, 0, len) : NULL; }
static ssize_t AccessReadStream( access_t *access, uint8_t *buf, size_t len ) { demux_sys_t *sys = (demux_sys_t *)access->p_sys; struct pollfd ufd; int i_ret; ufd.fd = sys->i_fd; ufd.events = POLLIN; if( access->info.b_eof ) return 0; /* FIXME: kill timeout and vlc_object_alive() */ do { if( !vlc_object_alive(access) ) return 0; ufd.revents = 0; } while( ( i_ret = poll( &ufd, 1, 500 ) ) == 0 ); if( i_ret < 0 ) { if( errno != EINTR ) msg_Err( access, "poll error: %m" ); return -1; } i_ret = v4l2_read( sys->i_fd, buf, len ); if( i_ret == 0 ) access->info.b_eof = true; else if( i_ret > 0 ) access->info.i_pos += i_ret; return i_ret; }
/** * Add an input item to the playlist node * * \param p_playlist the playlist to add into * \param p_input the input item to add * \param i_mode the mode used when adding * \param i_pos the position in the playlist where to add. If this is * PLAYLIST_END the item will be added at the end of the playlist * regardless of its size * \param b_playlist TRUE for playlist, FALSE for media library * \param b_locked TRUE if the playlist is locked * \return VLC_SUCCESS or VLC_ENOMEM or VLC_EGENERIC */ int playlist_AddInput( playlist_t* p_playlist, input_item_t *p_input, int i_mode, int i_pos, bool b_playlist, bool b_locked ) { playlist_item_t *p_item; /* FIXME: use b_killed instead: */ if( !vlc_object_alive(p_playlist) ) return VLC_EGENERIC; if( !pl_priv(p_playlist)->b_doing_ml ) PL_DEBUG( "adding item `%s' ( %s )", p_input->psz_name, p_input->psz_uri ); PL_LOCK_IF( !b_locked ); p_item = playlist_ItemNewFromInput( p_playlist, p_input ); if( p_item == NULL ) return VLC_ENOMEM; AddItem( p_playlist, p_item, b_playlist ? p_playlist->p_playing : p_playlist->p_media_library , i_mode, i_pos ); GoAndPreparse( p_playlist, i_mode, p_item ); PL_UNLOCK_IF( !b_locked ); return VLC_SUCCESS; }
/***************************************************************************** * main loop of qtapplication *****************************************************************************/ static void* RunQtThread( vlc_object_t *p_this ) { event_thread_t *p_event = (event_thread_t *)p_this; int canc = vlc_savecancel (); msg_Dbg( p_event->p_vout, "RunQtThread starting" ); #ifdef NEED_QTE_MAIN if (qApp) { p_event->p_vout->p_sys->p_QApplication = qApp; p_event->p_vout->p_sys->bOwnsQApp = FALSE; p_event->p_vout->p_sys->p_VideoWidget = qApp->mainWidget(); msg_Dbg( p_event->p_vout, "RunQtThread applicaton attached" ); } #else if (qApp==NULL) { int argc = 0; QApplication* pApp = new QApplication(argc, NULL); if(pApp) { p_event->p_vout->p_sys->p_QApplication = pApp; p_event->p_vout->p_sys->bOwnsQApp = TRUE; } QWidget* pWidget = new QWidget(); if (pWidget) { p_event->p_vout->p_sys->p_VideoWidget = pWidget; } } #endif /* signal the creation of the window */ vlc_thread_ready( p_event ); msg_Dbg( p_event->p_vout, "RunQtThread ready" ); if (p_event->p_vout->p_sys->p_QApplication) { /* Set default window width and heigh to exactly preferred size. */ QWidget *desktop = p_event->p_vout->p_sys->p_QApplication->desktop(); p_event->p_vout->p_sys->p_VideoWidget->setMinimumWidth( 10 ); p_event->p_vout->p_sys->p_VideoWidget->setMinimumHeight( 10 ); p_event->p_vout->p_sys->p_VideoWidget->setBaseSize( p_event->p_vout->p_sys->i_width, p_event->p_vout->p_sys->i_height ); p_event->p_vout->p_sys->p_VideoWidget->setMaximumWidth( desktop->width() ); p_event->p_vout->p_sys->p_VideoWidget->setMaximumHeight( desktop->height() ); /* Check on fullscreen */ if (p_event->p_vout->b_fullscreen) p_event->p_vout->p_sys->p_VideoWidget->showFullScreen(); else p_event->p_vout->p_sys->p_VideoWidget->showNormal(); p_event->p_vout->p_sys->p_VideoWidget->show(); p_event->p_vout->p_sys->bRunning = TRUE; #ifdef NEED_QTE_MAIN while(vlc_object_alive (p_event) && p_event->p_vout->p_sys->bRunning) { /* Check if we are asked to exit */ if( !vlc_object_alive (p_event) ) break; msleep(100); } #else // run the main loop of qtapplication until someone says: 'quit' p_event->p_vout->p_sys->pcQApplication->exec(); #endif } #ifndef NEED_QTE_MAIN if(p_event->p_vout->p_sys->p_QApplication) { delete p_event->p_vout->p_sys->p_VideoWidget; p_event->p_vout->p_sys->p_VideoWidget = NULL; delete p_event->p_vout->p_sys->p_QApplication; p_event->p_vout->p_sys->p_QApplication = NULL; } #else p_event->p_vout->p_sys->p_VideoWidget = NULL; #endif msg_Dbg( p_event->p_vout, "RunQtThread terminating" ); vlc_restorecancel (canc); return NULL; }
static void Run(intf_thread_t *p_intf) { intf_sys_t *p_sys = p_intf->p_sys; input_thread_t *p_input = NULL; playlist_t *p_playlist = pl_Get(p_intf); int *pi_fd, i_listen = 0, i_err; p_intf->p_sys->p_playlist = p_playlist; for (pi_fd = p_sys->pi_socket; *pi_fd != -1; pi_fd++) i_listen++; for (; vlc_object_alive(p_intf);) { vlc_value_t val; struct pollfd fd[i_listen + 2]; vlc_testcancel(); if (p_input == NULL) { p_input = playlist_CurrentInput(p_playlist); if (p_input) { var_AddCallback(p_input, "intf-event", InputEvent, p_intf); } } else { if (p_input->b_dead || !vlc_object_alive(p_input)) { var_DelCallback(p_input, "intf-event", InputEvent, p_intf); vlc_object_release(p_input); p_input = NULL; } } memset(&fd, 0, sizeof(fd[0]) * (i_listen + 1)); if (p_sys->i_socket == -1) { for (int i = 0; i < i_listen; i++) { fd[i].fd = p_sys->pi_socket[i]; fd[i].events = POLLIN; fd[i].revents = 0; } } else { fd[0].fd = p_sys->i_wakeup[0]; fd[0].events = POLLIN; fd[0].revents = 0; fd[1].fd = p_sys->i_socket; fd[1].events = POLLIN | (p_sys->i_write_length > 0 ? POLLOUT : 0); fd[1].revents = 0; } i_err = poll(fd, (p_sys->i_socket != -1) ? 2 : i_listen, -1); if (i_err < 0) { msg_Dbg(p_intf, "poll() failed"); vlc_object_kill(p_intf); break; } if (i_err == 0) continue; if (p_sys->i_socket == -1) { for (int i = 0; i < i_listen; i++) { if (fd[i].revents & POLLIN) { int client = net_AcceptSingle(VLC_OBJECT(p_intf), fd[i].fd); if (client == -1) continue; p_sys->i_socket = client; break; } } } else { if (fd[0].revents & POLLIN) { char ch; read(fd[0].fd, &ch, 1); } if (fd[1].revents & (POLLERR|POLLHUP|POLLNVAL)) { net_Close(fd[0].fd); p_sys->i_socket = -1; msg_Dbg(VLC_OBJECT(p_intf), "connection error"); continue; } ssize_t i_len, i_test; if (fd[1].revents & POLLIN) { //msg_Dbg(VLC_OBJECT(p_intf), "poll in"); bool b_line = false; while ((i_len = recv(fd[1].fd, p_sys->p_read_buffer + p_sys->i_read_offset, 1, 0)) > 0) { char ch; ch = p_sys->p_read_buffer[p_sys->i_read_offset]; switch (ch) { case '\r': case '\n': p_sys->p_read_buffer[p_sys->i_read_offset] = '\0'; b_line = true; break; case '\0': b_line = true; break; default: break; } p_sys->i_read_offset++; if (p_sys->i_read_offset == sizeof(p_sys->p_read_buffer) && !b_line) { net_Close(p_sys->i_socket); p_sys->i_socket = -1; msg_Dbg(VLC_OBJECT(p_intf), "input is too long, close connection"); break; } } if (b_line && strlen(p_sys->p_read_buffer)) { p_sys->i_read_offset = 0; //msg_Dbg(VLC_OBJECT(p_intf), "%s\n", p_sys->p_read_buffer); ProcessCommand(p_intf, p_sys->p_read_buffer); } if(i_len == 0) { net_Close(p_sys->i_socket); p_sys->i_socket = -1; msg_Dbg(VLC_OBJECT(p_intf), "connection is closed by client"); } } if (fd[1].revents & POLLOUT) { vlc_mutex_lock(&p_sys->o_write_lock); if (p_sys->i_write_length) { int i_first, i_second; i_first = sizeof(p_sys->p_write_buffer) - p_sys->i_write_offset; i_second = (p_sys->i_write_offset + p_sys->i_write_length) % sizeof(p_sys->p_write_buffer); i_test = 0; if (i_first >= p_sys->i_write_length) i_len = send(fd[1].fd, p_sys->p_write_buffer + p_sys->i_write_offset, p_sys->i_write_length, 0); else { i_len = send(fd[1].fd, p_sys->p_write_buffer + p_sys->i_write_offset, i_first, 0); if (i_len == i_first) i_test = send(fd[1].fd, p_sys->p_write_buffer, i_second, 0); if (i_test > 0) i_len += i_test; } if (i_len > 0) { p_sys->i_write_offset += i_len; p_sys->i_write_offset %= sizeof(p_sys->p_write_buffer); p_sys->i_write_length -= i_len; if (p_sys->i_write_length == 0) p_sys->i_write_offset = 0; } } vlc_mutex_unlock(&p_sys->o_write_lock); } } } }
/***************************************************************************** * RunInterface: setups necessary data and give control to the interface *****************************************************************************/ static void* RunInterface( vlc_object_t *p_this ) { intf_thread_t *p_intf = (intf_thread_t *)p_this; vlc_value_t val, text; char *psz_intf; /* Variable used for interface spawning */ var_Create( p_intf, "intf-add", VLC_VAR_STRING | VLC_VAR_HASCHOICE | VLC_VAR_ISCOMMAND ); text.psz_string = _("Add Interface"); var_Change( p_intf, "intf-add", VLC_VAR_SETTEXT, &text, NULL ); val.psz_string = (char *)"rc"; text.psz_string = (char *)_("Console"); var_Change( p_intf, "intf-add", VLC_VAR_ADDCHOICE, &val, &text ); val.psz_string = (char *)"telnet"; text.psz_string = (char *)_("Telnet Interface"); var_Change( p_intf, "intf-add", VLC_VAR_ADDCHOICE, &val, &text ); val.psz_string = (char *)"http"; text.psz_string = (char *)_("Web Interface"); var_Change( p_intf, "intf-add", VLC_VAR_ADDCHOICE, &val, &text ); val.psz_string = (char *)"logger"; text.psz_string = (char *)_("Debug logging"); var_Change( p_intf, "intf-add", VLC_VAR_ADDCHOICE, &val, &text ); val.psz_string = (char *)"gestures"; text.psz_string = (char *)_("Mouse Gestures"); var_Change( p_intf, "intf-add", VLC_VAR_ADDCHOICE, &val, &text ); var_AddCallback( p_intf, "intf-add", AddIntfCallback, NULL ); do { /* Give control to the interface */ if( p_intf->pf_run ) p_intf->pf_run( p_intf ); else { vlc_object_lock( p_intf ); while( vlc_object_alive( p_intf ) ) vlc_object_wait( p_intf ); vlc_object_unlock( p_intf ); } if( !p_intf->psz_switch_intf ) { break; } /* Make sure the old interface is completely uninitialized */ module_Unneed( p_intf, p_intf->p_module ); /* Provide ability to switch the main interface on the fly */ psz_intf = p_intf->psz_switch_intf; p_intf->psz_switch_intf = NULL; vlc_object_lock( p_intf ); p_intf->b_die = false; /* FIXME */ p_intf->b_dead = false; vlc_object_unlock( p_intf ); p_intf->psz_intf = psz_intf; p_intf->p_module = module_Need( p_intf, "interface", psz_intf, 0 ); } while( p_intf->p_module ); return NULL; }