/***************************************************************************** * Close: close the target *****************************************************************************/ static void Close( vlc_object_t * p_this ) { sout_access_out_t *p_access = (sout_access_out_t *) p_this; sout_access_out_sys_t *p_sys = p_access->p_sys; int i; vlc_cancel( p_sys->p_thread->thread ); vlc_join( p_sys->p_thread->thread, NULL ); vlc_cond_destroy( &p_sys->p_thread->wait ); vlc_mutex_destroy( &p_sys->p_thread->lock ); block_FifoRelease( p_sys->p_thread->p_fifo_input ); block_FifoRelease( p_sys->p_thread->p_empty_blocks ); for( i = 0; i < 64; i++ ) /* RTMP_HEADER_STREAM_INDEX_MASK */ { if( p_sys->p_thread->rtmp_headers_recv[i].body != NULL ) { free( p_sys->p_thread->rtmp_headers_recv[i].body->body ); free( p_sys->p_thread->rtmp_headers_recv[i].body ); } } net_Close( p_sys->p_thread->fd ); vlc_object_release( p_sys->p_thread ); vlc_UrlClean( &p_sys->p_thread->url ); free( p_sys->p_thread->psz_application ); free( p_sys->p_thread->psz_media ); free( p_sys ); }
/***************************************************************************** * Close: close the target *****************************************************************************/ static void Close( vlc_object_t * p_this ) { sout_access_out_t *p_access = (sout_access_out_t*)p_this; sout_access_out_sys_t *p_sys = p_access->p_sys; vlc_cancel( p_sys->thread ); vlc_join( p_sys->thread, NULL ); block_FifoRelease( p_sys->p_fifo ); block_FifoRelease( p_sys->p_empty_blocks ); if( p_sys->p_buffer ) block_Release( p_sys->p_buffer ); net_Close( p_sys->i_handle ); free( p_sys ); }
/***************************************************************************** * sout_MuxDeleteStream: *****************************************************************************/ void sout_MuxDeleteStream( sout_mux_t *p_mux, sout_input_t *p_input ) { int i_index; if( p_mux->b_waiting_stream && block_FifoCount( p_input->p_fifo ) > 0 ) { /* We stop waiting, and call the muxer for taking care of the data * before we remove this es */ p_mux->b_waiting_stream = false; p_mux->pf_mux( p_mux ); } TAB_FIND( p_mux->i_nb_inputs, p_mux->pp_inputs, p_input, i_index ); if( i_index >= 0 ) { p_mux->pf_delstream( p_mux, p_input ); /* remove the entry */ TAB_REMOVE( p_mux->i_nb_inputs, p_mux->pp_inputs, p_input ); if( p_mux->i_nb_inputs == 0 ) { msg_Warn( p_mux, "no more input streams for this mux" ); } block_FifoRelease( p_input->p_fifo ); es_format_Clean( &p_input->fmt ); free( p_input ); } }
/***************************************************************************** * sout_MuxAddStream: *****************************************************************************/ sout_input_t *sout_MuxAddStream( sout_mux_t *p_mux, es_format_t *p_fmt ) { sout_input_t *p_input; if( !p_mux->b_add_stream_any_time && !p_mux->b_waiting_stream ) { msg_Err( p_mux, "cannot add a new stream (unsupported while muxing " "to this format). You can try increasing sout-mux-caching value" ); return NULL; } msg_Dbg( p_mux, "adding a new input" ); /* create a new sout input */ p_input = malloc( sizeof( sout_input_t ) ); if( !p_input ) return NULL; p_input->p_fmt = p_fmt; p_input->p_fifo = block_FifoNew(); p_input->p_sys = NULL; TAB_APPEND( p_mux->i_nb_inputs, p_mux->pp_inputs, p_input ); if( p_mux->pf_addstream( p_mux, p_input ) < 0 ) { msg_Err( p_mux, "cannot add this stream" ); TAB_REMOVE( p_mux->i_nb_inputs, p_mux->pp_inputs, p_input ); block_FifoRelease( p_input->p_fifo ); free( p_input ); return NULL; } return p_input; }
/***************************************************************************** * Open: Starts the RTSP server module *****************************************************************************/ int OpenVoD( vlc_object_t *p_this ) { vod_t *p_vod = (vod_t *)p_this; vod_sys_t *p_sys = NULL; char *psz_url; p_vod->p_sys = p_sys = malloc( sizeof( vod_sys_t ) ); if( !p_sys ) goto error; psz_url = var_InheritString( p_vod, "rtsp-host" ); if( psz_url == NULL ) p_sys->psz_rtsp_path = strdup( "/" ); else { vlc_url_t url; vlc_UrlParse( &url, psz_url, 0 ); free( psz_url ); if( url.psz_path == NULL ) p_sys->psz_rtsp_path = strdup( "/" ); else if( !( strlen( url.psz_path ) > 0 && url.psz_path[strlen( url.psz_path ) - 1] == '/' ) ) { if( asprintf( &p_sys->psz_rtsp_path, "%s/", url.psz_path ) == -1 ) { p_sys->psz_rtsp_path = NULL; vlc_UrlClean( &url ); goto error; } } else p_sys->psz_rtsp_path = strdup( url.psz_path ); vlc_UrlClean( &url ); } p_vod->pf_media_new = MediaNew; p_vod->pf_media_del = MediaAskDel; p_sys->p_fifo_cmd = block_FifoNew(); if( vlc_clone( &p_sys->thread, CommandThread, p_vod, VLC_THREAD_PRIORITY_LOW ) ) { msg_Err( p_vod, "cannot spawn rtsp vod thread" ); block_FifoRelease( p_sys->p_fifo_cmd ); goto error; } return VLC_SUCCESS; error: if( p_sys ) { free( p_sys->psz_rtsp_path ); free( p_sys ); } return VLC_EGENERIC; }
stream_t *stream_DemuxNew( demux_t *p_demux, const char *psz_demux, es_out_t *out ) { vlc_object_t *p_obj = VLC_OBJECT(p_demux); /* We create a stream reader, and launch a thread */ stream_t *s; stream_sys_t *p_sys; s = stream_CommonNew( p_obj ); if( s == NULL ) return NULL; s->p_input = p_demux->p_input; s->pf_read = DStreamRead; s->pf_control= DStreamControl; s->pf_destroy= DStreamDelete; s->p_sys = p_sys = malloc( sizeof( *p_sys) ); if( !s->p_sys ) { stream_Delete( s ); return NULL; } p_sys->i_pos = 0; p_sys->out = out; p_sys->p_block = NULL; p_sys->psz_name = strdup( psz_demux ); p_sys->stats.position = 0.; p_sys->stats.length = 0; p_sys->stats.time = 0; /* decoder fifo */ if( ( p_sys->p_fifo = block_FifoNew() ) == NULL ) { stream_Delete( s ); free( p_sys->psz_name ); free( p_sys ); return NULL; } atomic_init( &p_sys->active, true ); vlc_mutex_init( &p_sys->lock ); if( vlc_clone( &p_sys->thread, DStreamThread, s, VLC_THREAD_PRIORITY_INPUT ) ) { vlc_mutex_destroy( &p_sys->lock ); block_FifoRelease( p_sys->p_fifo ); stream_Delete( s ); free( p_sys->psz_name ); free( p_sys ); return NULL; } return s; }
static void CloseEncoder( vlc_object_t *p_this ) { encoder_sys_t *p_sys = ((encoder_t*)p_this)->p_sys; vlc_mutex_lock( &entrant.lock ); entrant.busy = false; vlc_mutex_unlock( &entrant.lock ); /* TODO: we should send the last PCM block padded with 0 * But we don't know if other blocks will come before it's too late */ if( p_sys->i_buffer ) free( p_sys->p_buffer ); block_FifoRelease( p_sys->p_fifo ); free( p_sys ); }
/***************************************************************************** * CloseEncoder: dirac encoder destruction *****************************************************************************/ static void CloseEncoder( vlc_object_t *p_this ) { encoder_t *p_enc = (encoder_t *)p_this; encoder_sys_t *p_sys = p_enc->p_sys; /* Free the encoder resources */ if( p_sys->p_dirac ) dirac_encoder_close( p_sys->p_dirac ); free( p_sys->p_buffer_in ); free( p_sys->p_buffer_out ); if( p_sys->p_dts_fifo ) block_FifoRelease( p_sys->p_dts_fifo ); block_ChainRelease( p_sys->p_chain ); free( p_sys ); }
static void DStreamDelete( stream_t *s ) { stream_sys_t *p_sys = s->p_sys; block_t *p_empty; atomic_store( &p_sys->active, false ); p_empty = block_Alloc( 0 ); block_FifoPut( p_sys->p_fifo, p_empty ); vlc_join( p_sys->thread, NULL ); vlc_mutex_destroy( &p_sys->lock ); if( p_sys->p_block ) block_Release( p_sys->p_block ); block_FifoRelease( p_sys->p_fifo ); free( p_sys->psz_name ); free( p_sys ); }
/** * Close the module. * @param p_this: the filter object */ 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; /* Terminate the thread. */ vlc_cancel(p_sys->thread); vlc_join(p_sys->thread, NULL); /* Free the ressources */ vout_DeleteDisplay(p_sys->p_vd, NULL); vlc_object_release(p_sys->p_vout); block_FifoRelease(p_sys->fifo); free(p_sys->p_prev_s16_buff); vlc_sem_destroy(&p_sys->ready); free(p_sys); }
/***************************************************************************** * Close: *****************************************************************************/ void CloseVoD( vlc_object_t * p_this ) { vod_t *p_vod = (vod_t *)p_this; vod_sys_t *p_sys = p_vod->p_sys; /* Stop command thread */ vlc_cancel( p_sys->thread ); vlc_join( p_sys->thread, NULL ); while( block_FifoCount( p_sys->p_fifo_cmd ) > 0 ) { rtsp_cmd_t cmd; block_t *p_block_cmd = block_FifoGet( p_sys->p_fifo_cmd ); memcpy( &cmd, p_block_cmd->p_buffer, sizeof(cmd) ); block_Release( p_block_cmd ); if ( cmd.i_type == RTSP_CMD_TYPE_DEL ) MediaDel(p_vod, cmd.p_media); free( cmd.psz_arg ); } block_FifoRelease( p_sys->p_fifo_cmd ); free( p_sys->psz_rtsp_path ); free( p_sys ); }
/***************************************************************************** * Open: open the file *****************************************************************************/ static int Open( vlc_object_t *p_this ) { sout_access_out_t *p_access = (sout_access_out_t*)p_this; sout_access_out_sys_t *p_sys; char *psz_dst_addr = NULL; int i_dst_port; int i_handle; config_ChainParse( p_access, SOUT_CFG_PREFIX, ppsz_sout_options, p_access->p_cfg ); config_ChainParse( p_access, "", ppsz_core_options, p_access->p_cfg ); if (var_Create (p_access, "dst-port", VLC_VAR_INTEGER) || var_Create (p_access, "src-port", VLC_VAR_INTEGER) || var_Create (p_access, "dst-addr", VLC_VAR_STRING) || var_Create (p_access, "src-addr", VLC_VAR_STRING)) { return VLC_ENOMEM; } if( !( p_sys = malloc ( sizeof( *p_sys ) ) ) ) return VLC_ENOMEM; p_access->p_sys = p_sys; i_dst_port = DEFAULT_PORT; char *psz_parser = psz_dst_addr = strdup( p_access->psz_path ); if( !psz_dst_addr ) { free( p_sys ); return VLC_ENOMEM; } if (psz_parser[0] == '[') psz_parser = strchr (psz_parser, ']'); psz_parser = strchr (psz_parser ? psz_parser : psz_dst_addr, ':'); if (psz_parser != NULL) { *psz_parser++ = '\0'; i_dst_port = atoi (psz_parser); } i_handle = net_ConnectDgram( p_this, psz_dst_addr, i_dst_port, -1, IPPROTO_UDP ); free (psz_dst_addr); if( i_handle == -1 ) { msg_Err( p_access, "failed to create raw UDP socket" ); free (p_sys); return VLC_EGENERIC; } else { char addr[NI_MAXNUMERICHOST]; int port; if (net_GetSockAddress (i_handle, addr, &port) == 0) { msg_Dbg (p_access, "source: %s port %d", addr, port); var_SetString (p_access, "src-addr", addr); var_SetInteger (p_access, "src-port", port); } if (net_GetPeerAddress (i_handle, addr, &port) == 0) { msg_Dbg (p_access, "destination: %s port %d", addr, port); var_SetString (p_access, "dst-addr", addr); var_SetInteger (p_access, "dst-port", port); } } shutdown( i_handle, SHUT_RD ); p_sys->i_caching = UINT64_C(1000) * var_GetInteger( p_access, SOUT_CFG_PREFIX "caching"); p_sys->i_handle = i_handle; p_sys->i_mtu = var_CreateGetInteger( p_this, "mtu" ); p_sys->b_mtu_warning = false; p_sys->p_fifo = block_FifoNew(); p_sys->p_empty_blocks = block_FifoNew(); p_sys->p_buffer = NULL; if( vlc_clone( &p_sys->thread, ThreadWrite, p_access, VLC_THREAD_PRIORITY_HIGHEST ) ) { msg_Err( p_access, "cannot spawn sout access thread" ); block_FifoRelease( p_sys->p_fifo ); block_FifoRelease( p_sys->p_empty_blocks ); net_Close (i_handle); free (p_sys); return VLC_EGENERIC; } p_access->pf_write = Write; p_access->pf_seek = Seek; p_access->pf_control = Control; return VLC_SUCCESS; }