static int MarshalStatus( intf_thread_t* p_intf, DBusMessageIter* args ) { /* This is NOT the right way to do that, it would be better to sore the status information in p_sys and update it on change, thus avoiding a long lock */ DBusMessageIter status; dbus_int32_t i_state, i_random, i_repeat, i_loop; playlist_t* p_playlist = p_intf->p_sys->p_playlist; vlc_mutex_lock( &p_intf->p_sys->lock ); i_state = p_intf->p_sys->i_playing_state; vlc_mutex_unlock( &p_intf->p_sys->lock ); i_random = var_CreateGetBool( p_playlist, "random" ); i_repeat = var_CreateGetBool( p_playlist, "repeat" ); i_loop = var_CreateGetBool( p_playlist, "loop" ); dbus_message_iter_open_container( args, DBUS_TYPE_STRUCT, NULL, &status ); dbus_message_iter_append_basic( &status, DBUS_TYPE_INT32, &i_state ); dbus_message_iter_append_basic( &status, DBUS_TYPE_INT32, &i_random ); dbus_message_iter_append_basic( &status, DBUS_TYPE_INT32, &i_repeat ); dbus_message_iter_append_basic( &status, DBUS_TYPE_INT32, &i_loop ); dbus_message_iter_close_container( args, &status ); return VLC_SUCCESS; }
/***************************************************************************** * OpenDecoder: probe the decoder and return score ***************************************************************************** * Tries to launch a decoder and return score so that the interface is able * to chose. *****************************************************************************/ static int OpenDecoder( vlc_object_t *p_this ) { decoder_t *p_dec = (decoder_t*)p_this; decoder_sys_t *p_sys; if( p_dec->fmt_in.i_codec != VLC_CODEC_USF ) return VLC_EGENERIC; /* Allocate the memory needed to store the decoder's structure */ if( ( p_dec->p_sys = p_sys = calloc(1, sizeof(decoder_sys_t)) ) == NULL ) return VLC_ENOMEM; p_dec->pf_decode_sub = DecodeBlock; p_dec->fmt_out.i_cat = SPU_ES; p_dec->fmt_out.i_codec = 0; /* init of p_sys */ TAB_INIT( p_sys->i_ssa_styles, p_sys->pp_ssa_styles ); TAB_INIT( p_sys->i_images, p_sys->pp_images ); /* USF subtitles are mandated to be UTF-8, so don't need vlc_iconv */ p_sys->i_align = var_CreateGetInteger( p_dec, "subsdec-align" ); ParseImageAttachments( p_dec ); if( var_CreateGetBool( p_dec, "subsdec-formatted" ) ) { if( p_dec->fmt_in.i_extra > 0 ) ParseUSFHeader( p_dec ); } return VLC_SUCCESS; }
/** * @brief Remove a directory to monitor * @param p_ml A media library object * @param psz_dir the directory to remove * @return VLC_SUCCESS or VLC_EGENERIC */ int RemoveDirToMonitor( media_library_t *p_ml, const char *psz_dir ) { assert( p_ml ); char **pp_results = NULL; int i_cols = 0, i_rows = 0, i_ret = VLC_SUCCESS; int i; bool b_recursive = var_CreateGetBool( p_ml, "ml-recursive-scan" ); if( b_recursive ) { i_ret = Query( p_ml, &pp_results, &i_rows, &i_cols, "SELECT media.id FROM media JOIN directories ON " "(media.directory_id = directories.id) WHERE " "directories.uri LIKE '%q%%'", psz_dir ); if( i_ret != VLC_SUCCESS ) { msg_Err( p_ml, "Error occured while making a query to the database" ); return i_ret; } QuerySimple( p_ml, "DELETE FROM directories WHERE uri LIKE '%q%%'", psz_dir ); } else { i_ret = Query( p_ml, &pp_results, &i_rows, &i_cols, "SELECT media.id FROM media JOIN directories ON " "(media.directory_id = directories.id) WHERE " "directories.uri = %Q", psz_dir ); if( i_ret != VLC_SUCCESS ) { msg_Err( p_ml, "Error occured while making a query to the database" ); return i_ret; } QuerySimple( p_ml, "DELETE FROM directories WHERE uri = %Q", psz_dir ); } vlc_array_t *p_where = vlc_array_new(); for( i = 1; i <= i_rows; i++ ) { int id = atoi( pp_results[i*i_cols] ); ml_element_t* p_find = ( ml_element_t * ) calloc( 1, sizeof( ml_element_t ) ); p_find->criteria = ML_ID; p_find->value.i = id; vlc_array_append( p_where, p_find ); } Delete( p_ml, p_where ); FreeSQLResult( p_ml, pp_results ); for( i = 0; i < vlc_array_count( p_where ); i++ ) { free( vlc_array_item_at_index( p_where, i ) ); } vlc_array_destroy( p_where ); return VLC_SUCCESS; }
static int MarshalStatus( intf_thread_t* p_intf, DBusMessageIter* args ) { /* This is NOT the right way to do that, it would be better to sore the status information in p_sys and update it on change, thus avoiding a long lock */ DBusMessageIter status; dbus_int32_t i_state, i_random, i_repeat, i_loop; vlc_value_t val; playlist_t* p_playlist = NULL; input_thread_t* p_input = NULL; p_playlist = pl_Hold( p_intf ); i_state = 2; p_input = playlist_CurrentInput( p_playlist ); if( p_input ) { var_Get( p_input, "state", &val ); if( val.i_int >= END_S ) i_state = 2; else if( val.i_int == PAUSE_S ) i_state = 1; else if( val.i_int <= PLAYING_S ) i_state = 0; vlc_object_release( p_input ); } i_random = var_CreateGetBool( p_playlist, "random" ); i_repeat = var_CreateGetBool( p_playlist, "repeat" ); i_loop = var_CreateGetBool( p_playlist, "loop" ); pl_Release( p_intf ); dbus_message_iter_open_container( args, DBUS_TYPE_STRUCT, NULL, &status ); dbus_message_iter_append_basic( &status, DBUS_TYPE_INT32, &i_state ); dbus_message_iter_append_basic( &status, DBUS_TYPE_INT32, &i_random ); dbus_message_iter_append_basic( &status, DBUS_TYPE_INT32, &i_repeat ); dbus_message_iter_append_basic( &status, DBUS_TYPE_INT32, &i_loop ); dbus_message_iter_close_container( args, &status ); 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; }
/***************************************************************************** * Create: initialize and set pf_video_filter() *****************************************************************************/ static int Create( vlc_object_t *p_this ) { filter_t *p_filter = (filter_t *)p_this; filter_sys_t *p_sys; const vlc_chroma_description_t *p_chroma = vlc_fourcc_GetChromaDescription( p_filter->fmt_in.video.i_chroma ); if( p_chroma == NULL || p_chroma->plane_count == 0 ) return VLC_EGENERIC; config_ChainParse( p_filter, CFG_PREFIX, ppsz_vfilter_options, p_filter->p_cfg ); p_filter->p_sys = p_sys = calloc( 1, sizeof( filter_sys_t ) ); if( p_filter->p_sys == NULL ) return VLC_ENOMEM; p_sys->p_image = image_HandlerCreate( p_this ); if( !p_sys->p_image ) { msg_Err( p_this, "Couldn't get handle to image conversion routines." ); free( p_sys ); return VLC_EGENERIC; } p_sys->psz_format = var_CreateGetString( p_this, CFG_PREFIX "format" ); p_sys->i_format = image_Type2Fourcc( p_sys->psz_format ); if( !p_sys->i_format ) { msg_Err( p_filter, "Could not find FOURCC for image type '%s'", p_sys->psz_format ); image_HandlerDelete( p_sys->p_image ); free( p_sys->psz_format ); free( p_sys ); return VLC_EGENERIC; } p_sys->i_width = var_CreateGetInteger( p_this, CFG_PREFIX "width" ); p_sys->i_height = var_CreateGetInteger( p_this, CFG_PREFIX "height" ); p_sys->i_ratio = var_CreateGetInteger( p_this, CFG_PREFIX "ratio" ); if( p_sys->i_ratio <= 0) p_sys->i_ratio = 1; p_sys->b_replace = var_CreateGetBool( p_this, CFG_PREFIX "replace" ); p_sys->psz_prefix = var_CreateGetString( p_this, CFG_PREFIX "prefix" ); p_sys->psz_path = var_GetNonEmptyString( p_this, CFG_PREFIX "path" ); if( p_sys->psz_path == NULL ) p_sys->psz_path = config_GetUserDir( VLC_PICTURES_DIR ); p_filter->pf_video_filter = Filter; return VLC_SUCCESS; }
/***************************************************************************** * OpenDecoder: Open the decoder *****************************************************************************/ static int OpenDecoderCommon( vlc_object_t *p_this, bool b_force_dump ) { decoder_t *p_dec = (decoder_t*)p_this; decoder_sys_t *p_sys; char psz_file[ PATH_MAX ]; /* Allocate the memory needed to store the decoder's structure */ if( ( p_dec->p_sys = p_sys = (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL ) { return VLC_ENOMEM; } snprintf( psz_file, sizeof( psz_file), "stream.%p", p_dec ); #ifndef UNDER_CE if( !b_force_dump ) { b_force_dump = var_CreateGetBool( p_dec, "dummy-save-es" ); } if( b_force_dump ) { p_sys->i_fd = vlc_open( psz_file, O_WRONLY | O_CREAT | O_TRUNC, 00644 ); if( p_sys->i_fd == -1 ) { msg_Err( p_dec, "cannot create `%s'", psz_file ); free( p_sys ); return VLC_EGENERIC; } msg_Dbg( p_dec, "dumping stream to file `%s'", psz_file ); } else #endif { p_sys->i_fd = -1; } /* Set callbacks */ p_dec->pf_decode_video = (picture_t *(*)(decoder_t *, block_t **)) DecodeBlock; p_dec->pf_decode_audio = (aout_buffer_t *(*)(decoder_t *, block_t **)) DecodeBlock; p_dec->pf_decode_sub = (subpicture_t *(*)(decoder_t *, block_t **)) DecodeBlock; es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in ); return VLC_SUCCESS; }
static bool FindLength( demux_t *p_demux ) { demux_sys_t *p_sys = p_demux->p_sys; int64_t i_current_pos = -1, i_size = 0, i_end = 0; if( !var_CreateGetBool( p_demux, "ps-trust-timestamps" ) ) return true; if( p_sys->i_length == VLC_TICK_INVALID ) /* First time */ { p_sys->i_length = VLC_TICK_0; /* Check beginning */ int i = 0; i_current_pos = vlc_stream_Tell( p_demux->s ); while( i < 40 && Probe( p_demux, false ) > 0 ) i++; /* Check end */ i_size = stream_Size( p_demux->s ); i_end = VLC_CLIP( i_size, 0, 200000 ); if( vlc_stream_Seek( p_demux->s, i_size - i_end ) == VLC_SUCCESS ) { i = 0; while( i < 400 && Probe( p_demux, true ) > 0 ) i++; if( i_current_pos >= 0 && vlc_stream_Seek( p_demux->s, i_current_pos ) != VLC_SUCCESS ) return false; } else return false; } /* Find the longest track */ for( int i = 0; i < PS_TK_COUNT; i++ ) { ps_track_t *tk = &p_sys->tk[i]; if( tk->i_first_pts != VLC_TICK_INVALID && tk->i_last_pts > tk->i_first_pts ) { vlc_tick_t i_length = tk->i_last_pts - tk->i_first_pts; if( i_length > p_sys->i_length ) { p_sys->i_length = i_length; p_sys->i_time_track_index = i; msg_Dbg( p_demux, "we found a length of: %"PRId64 "s", SEC_FROM_VLC_TICK(p_sys->i_length) ); } } } return true; }
/** * Open() */ static int Open (vlc_object_t *obj) { access_t *access = (access_t*)obj; access_t *src = access->p_source; if (!var_CreateGetBool (access, "dump-force")) { bool b; if ((access_Control (src, ACCESS_CAN_FASTSEEK, &b) == 0) && b) { msg_Dbg (obj, "dump filter useless"); return VLC_EGENERIC; } } if (src->pf_read != NULL) access->pf_read = Read; else access->pf_block = Block; if (src->pf_seek != NULL) access->pf_seek = Seek; access->pf_control = Control; access->info = src->info; access_sys_t *p_sys = access->p_sys = calloc( 1, sizeof (*p_sys) ); if( !p_sys ) return VLC_ENOMEM; # ifndef UNDER_CE if ((p_sys->stream = tmpfile ()) == NULL) # else char buf[75]; if(GetTempFileName("\\Temp\\","vlc",0,buf) || ((p_sys->stream = fopen(buf,"wb+")) ==NULL)) #endif { msg_Err (access, "cannot create temporary file: %m"); free (p_sys); return VLC_EGENERIC; } p_sys->tmp_max = ((int64_t)var_CreateGetInteger (access, "dump-margin")) << 20; var_AddCallback (access->p_libvlc, "key-action", KeyHandler, access); return VLC_SUCCESS; }
/***************************************************************************** * Open: *****************************************************************************/ static int Open( vlc_object_t *p_this ) { char* psz_tmp; sout_stream_t *p_stream = (sout_stream_t*)p_this; sout_stream_sys_t *p_sys; p_sys = calloc( 1, sizeof( sout_stream_sys_t ) ); if( !p_sys ) return VLC_ENOMEM; p_stream->p_sys = p_sys; p_sys->time_sync = var_CreateGetBool( p_stream, SOUT_CFG_PREFIX "time-sync" ); psz_tmp = var_CreateGetString( p_stream, SOUT_PREFIX_VIDEO "prerender-callback" ); p_sys->pf_video_prerender_callback = (void (*) (void *, uint8_t**, int))(intptr_t)atoll( psz_tmp ); free( psz_tmp ); psz_tmp = var_CreateGetString( p_stream, SOUT_PREFIX_AUDIO "prerender-callback" ); p_sys->pf_audio_prerender_callback = (void (*) (void* , uint8_t**, unsigned int))(intptr_t)atoll( psz_tmp ); free( psz_tmp ); psz_tmp = var_CreateGetString( p_stream, SOUT_PREFIX_VIDEO "postrender-callback" ); p_sys->pf_video_postrender_callback = (void (*) (void*, uint8_t*, int, int, int, int, int))(intptr_t)atoll( psz_tmp ); free( psz_tmp ); psz_tmp = var_CreateGetString( p_stream, SOUT_PREFIX_AUDIO "postrender-callback" ); p_sys->pf_audio_postrender_callback = (void (*) (void*, uint8_t*, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, int))(intptr_t)atoll( psz_tmp ); free( psz_tmp ); /* Create the remaining variables for a later use */ var_Create( p_stream, SOUT_PREFIX_VIDEO "data", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); var_Create( p_stream, SOUT_PREFIX_AUDIO "data", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); /* Setting stream out module callbacks */ p_stream->pf_add = Add; p_stream->pf_del = Del; p_stream->pf_send = Send; /* Does the module need out_pace_control? */ if ( p_sys->time_sync ) p_stream->p_sout->i_out_pace_nocontrol++; return VLC_SUCCESS; }
/***************************************************************************** * Create: allocates video thread ***************************************************************************** * This function allocates and initializes a vout method. *****************************************************************************/ static int Create( vlc_object_t *p_this ) { vout_thread_t *p_vout = ( vout_thread_t * )p_this; /* Allocate instance and initialize some members */ p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); if( ! p_vout->p_sys ) return VLC_ENOMEM; p_vout->p_sys->psz_prefix = var_CreateGetString( p_this, "image-out-prefix" ); p_vout->p_sys->psz_format = var_CreateGetString( p_this, "image-out-format" ); p_vout->p_sys->i_width = var_CreateGetInteger( p_this, "image-width" ); p_vout->p_sys->i_height = var_CreateGetInteger( p_this, "image-height" ); p_vout->p_sys->i_ratio = var_CreateGetInteger( p_this, "image-out-ratio" ); p_vout->p_sys->b_replace = var_CreateGetBool( p_this, "image-out-replace" ); p_vout->p_sys->i_current = 0; p_vout->p_sys->p_image = image_HandlerCreate( p_vout ); if( !p_vout->p_sys->p_image ) { msg_Err( p_this, "unable to create image handler") ; FREE( p_vout->p_sys->psz_prefix ); FREE( p_vout->p_sys ); return VLC_EGENERIC; } p_vout->pf_init = Init; p_vout->pf_end = End; p_vout->pf_manage = NULL; p_vout->pf_render = Display; p_vout->pf_display = NULL; return VLC_SUCCESS; }
/***************************************************************************** * InitVideo: initialize the video decoder ***************************************************************************** * the ffmpeg codec will be opened, some memory allocated. The vout is not yet * opened (done after the first decoded frame). *****************************************************************************/ int InitVideoDec( decoder_t *p_dec, AVCodecContext *p_context, AVCodec *p_codec, int i_codec_id, const char *psz_namecodec ) { decoder_sys_t *p_sys; int i_val; /* Allocate the memory needed to store the decoder's structure */ if( ( p_dec->p_sys = p_sys = calloc( 1, sizeof(decoder_sys_t) ) ) == NULL ) return VLC_ENOMEM; p_codec->type = AVMEDIA_TYPE_VIDEO; p_context->codec_type = AVMEDIA_TYPE_VIDEO; p_context->codec_id = i_codec_id; p_sys->p_context = p_context; p_sys->p_codec = p_codec; p_sys->i_codec_id = i_codec_id; p_sys->psz_namecodec = psz_namecodec; p_sys->p_ff_pic = avcodec_alloc_frame(); p_sys->b_delayed_open = true; p_sys->p_va = NULL; vlc_sem_init( &p_sys->sem_mt, 0 ); /* ***** Fill p_context with init values ***** */ p_sys->p_context->codec_tag = ffmpeg_CodecTag( p_dec->fmt_in.i_original_fourcc ? p_dec->fmt_in.i_original_fourcc : p_dec->fmt_in.i_codec ); // sunqueen modify /* ***** Get configuration of ffmpeg plugin ***** */ p_sys->p_context->workaround_bugs = var_InheritInteger( p_dec, "avcodec-workaround-bugs" ); p_sys->p_context->err_recognition = var_InheritInteger( p_dec, "avcodec-error-resilience" ); if( var_CreateGetBool( p_dec, "grayscale" ) ) p_sys->p_context->flags |= CODEC_FLAG_GRAY; /* ***** Output always the frames ***** */ #if LIBAVCODEC_VERSION_CHECK(55, 23, 1, 40, 101) p_sys->p_context->flags |= CODEC_FLAG_OUTPUT_CORRUPT; #endif i_val = var_CreateGetInteger( p_dec, "avcodec-vismv" ); if( i_val ) p_sys->p_context->debug_mv = i_val; i_val = var_CreateGetInteger( p_dec, "avcodec-skiploopfilter" ); if( i_val >= 4 ) p_sys->p_context->skip_loop_filter = AVDISCARD_ALL; else if( i_val == 3 ) p_sys->p_context->skip_loop_filter = AVDISCARD_NONKEY; else if( i_val == 2 ) p_sys->p_context->skip_loop_filter = AVDISCARD_BIDIR; else if( i_val == 1 ) p_sys->p_context->skip_loop_filter = AVDISCARD_NONREF; if( var_CreateGetBool( p_dec, "avcodec-fast" ) ) p_sys->p_context->flags2 |= CODEC_FLAG2_FAST; /* ***** libavcodec frame skipping ***** */ p_sys->b_hurry_up = var_CreateGetBool( p_dec, "avcodec-hurry-up" ); i_val = var_CreateGetInteger( p_dec, "avcodec-skip-frame" ); if( i_val >= 4 ) p_sys->p_context->skip_frame = AVDISCARD_ALL; else if( i_val == 3 ) p_sys->p_context->skip_frame = AVDISCARD_NONKEY; else if( i_val == 2 ) p_sys->p_context->skip_frame = AVDISCARD_BIDIR; else if( i_val == 1 ) p_sys->p_context->skip_frame = AVDISCARD_NONREF; else if( i_val == -1 ) p_sys->p_context->skip_frame = AVDISCARD_NONE; else p_sys->p_context->skip_frame = AVDISCARD_DEFAULT; p_sys->i_skip_frame = p_sys->p_context->skip_frame; i_val = var_CreateGetInteger( p_dec, "avcodec-skip-idct" ); if( i_val >= 4 ) p_sys->p_context->skip_idct = AVDISCARD_ALL; else if( i_val == 3 ) p_sys->p_context->skip_idct = AVDISCARD_NONKEY; else if( i_val == 2 ) p_sys->p_context->skip_idct = AVDISCARD_BIDIR; else if( i_val == 1 ) p_sys->p_context->skip_idct = AVDISCARD_NONREF; else if( i_val == -1 ) p_sys->p_context->skip_idct = AVDISCARD_NONE; else p_sys->p_context->skip_idct = AVDISCARD_DEFAULT; p_sys->i_skip_idct = p_sys->p_context->skip_idct; /* ***** libavcodec direct rendering ***** */ p_sys->b_direct_rendering = false; p_sys->i_direct_rendering_used = -1; if( var_CreateGetBool( p_dec, "avcodec-dr" ) && (p_sys->p_codec->capabilities & CODEC_CAP_DR1) && /* No idea why ... but this fixes flickering on some TSCC streams */ p_sys->i_codec_id != AV_CODEC_ID_TSCC && p_sys->i_codec_id != AV_CODEC_ID_CSCD && p_sys->i_codec_id != AV_CODEC_ID_CINEPAK && !p_sys->p_context->debug_mv ) { /* Some codecs set pix_fmt only after the 1st frame has been decoded, * so we need to do another check in ffmpeg_GetFrameBuf() */ p_sys->b_direct_rendering = true; } /* libavcodec doesn't properly release old pictures when frames are skipped */ //if( p_sys->b_hurry_up ) p_sys->b_direct_rendering = false; if( p_sys->b_direct_rendering ) { msg_Dbg( p_dec, "trying to use direct rendering" ); p_sys->p_context->flags |= CODEC_FLAG_EMU_EDGE; } else { msg_Dbg( p_dec, "direct rendering is disabled" ); } p_sys->p_context->get_format = ffmpeg_GetFormat; /* Always use our get_buffer wrapper so we can calculate the * PTS correctly */ #if LIBAVCODEC_VERSION_MAJOR >= 55 p_sys->p_context->get_buffer2 = lavc_GetFrame; #else p_sys->p_context->get_buffer = ffmpeg_GetFrameBuf; p_sys->p_context->reget_buffer = avcodec_default_reget_buffer; p_sys->p_context->release_buffer = ffmpeg_ReleaseFrameBuf; #endif p_sys->p_context->opaque = p_dec; #ifdef HAVE_AVCODEC_MT int i_thread_count = var_InheritInteger( p_dec, "avcodec-threads" ); if( i_thread_count <= 0 ) { i_thread_count = vlc_GetCPUCount(); if( i_thread_count > 1 ) i_thread_count++; //FIXME: take in count the decoding time i_thread_count = __MIN( i_thread_count, 4 ); } i_thread_count = __MIN( i_thread_count, 16 ); msg_Dbg( p_dec, "allowing %d thread(s) for decoding", i_thread_count ); p_sys->p_context->thread_count = i_thread_count; p_sys->p_context->thread_safe_callbacks = true; switch( i_codec_id ) { case AV_CODEC_ID_MPEG4: case AV_CODEC_ID_H263: p_sys->p_context->thread_type = 0; break; case AV_CODEC_ID_MPEG1VIDEO: case AV_CODEC_ID_MPEG2VIDEO: p_sys->p_context->thread_type &= ~FF_THREAD_SLICE; /* fall through */ # if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55, 1, 0)) case AV_CODEC_ID_H264: case AV_CODEC_ID_VC1: case AV_CODEC_ID_WMV3: p_sys->p_context->thread_type &= ~FF_THREAD_FRAME; # endif } /* Workaround: frame multithreading is not compatible with * DXVA2. When a frame is being copied to host memory, the frame * is locked and cannot be used as a reference frame * simultaneously and thus decoding fails for some frames. This * causes major image corruption. */ # if defined(_WIN32) char *avcodec_hw = var_InheritString( p_dec, "avcodec-hw" ); if( avcodec_hw == NULL || strcasecmp( avcodec_hw, "none" ) ) { msg_Warn( p_dec, "threaded frame decoding is not compatible with DXVA2, disabled" ); p_sys->p_context->thread_type &= ~FF_THREAD_FRAME; } free( avcodec_hw ); # endif if( p_sys->p_context->thread_type & FF_THREAD_FRAME ) p_dec->i_extra_picture_buffers = 2 * p_sys->p_context->thread_count; #endif /* ***** misc init ***** */ p_sys->i_pts = VLC_TS_INVALID; p_sys->b_has_b_frames = false; p_sys->b_first_frame = true; p_sys->b_flush = false; p_sys->i_late_frames = 0; /* Set output properties */ p_dec->fmt_out.i_cat = VIDEO_ES; if( GetVlcChroma( &p_dec->fmt_out.video, p_context->pix_fmt ) != VLC_SUCCESS ) { /* we are doomed. but not really, because most codecs set their pix_fmt later on */ p_dec->fmt_out.i_codec = VLC_CODEC_I420; } p_dec->fmt_out.i_codec = p_dec->fmt_out.video.i_chroma; p_dec->fmt_out.video.orientation = p_dec->fmt_in.video.orientation; #if LIBAVCODEC_VERSION_MAJOR < 54 /* Setup palette */ memset( &p_sys->palette, 0, sizeof(p_sys->palette) ); if( p_dec->fmt_in.video.p_palette ) { p_sys->palette.palette_changed = 1; for( int i = 0; i < __MIN( AVPALETTE_COUNT, p_dec->fmt_in.video.p_palette->i_entries ); i++ ) { union { uint32_t u; uint8_t a[4]; } c; c.a[0] = p_dec->fmt_in.video.p_palette->palette[i][0]; c.a[1] = p_dec->fmt_in.video.p_palette->palette[i][1]; c.a[2] = p_dec->fmt_in.video.p_palette->palette[i][2]; c.a[3] = p_dec->fmt_in.video.p_palette->palette[i][3]; p_sys->palette.palette[i] = c.u; } p_sys->p_context->palctrl = &p_sys->palette; p_dec->fmt_out.video.p_palette = malloc( sizeof(video_palette_t) ); if( p_dec->fmt_out.video.p_palette ) *p_dec->fmt_out.video.p_palette = *p_dec->fmt_in.video.p_palette; } else if( p_sys->i_codec_id != CODEC_ID_MSVIDEO1 && p_sys->i_codec_id != CODEC_ID_CINEPAK ) { p_sys->p_context->palctrl = &p_sys->palette; } #else if( p_dec->fmt_in.video.p_palette ) { p_sys->palette_sent = false; p_dec->fmt_out.video.p_palette = malloc( sizeof(video_palette_t) ); if( p_dec->fmt_out.video.p_palette ) *p_dec->fmt_out.video.p_palette = *p_dec->fmt_in.video.p_palette; } else p_sys->palette_sent = true; #endif /* ***** init this codec with special data ***** */ ffmpeg_InitCodec( p_dec ); /* ***** Open the codec ***** */ if( ffmpeg_OpenCodec( p_dec ) < 0 ) { msg_Err( p_dec, "cannot open codec (%s)", p_sys->psz_namecodec ); avcodec_free_frame( &p_sys->p_ff_pic ); vlc_sem_destroy( &p_sys->sem_mt ); free( p_sys ); return VLC_EGENERIC; } if ( p_dec->fmt_in.i_codec == VLC_CODEC_VP9 ) p_dec->b_need_packetized = true; return VLC_SUCCESS; }
static int Activate( vlc_object_t *p_this ) { filter_t *p_filter = (filter_t *)p_this; unsigned i_canvas_width; /* width of output canvas */ unsigned i_canvas_height; /* height of output canvas */ unsigned i_canvas_aspect; /* canvas PictureAspectRatio */ es_format_t fmt; /* target format after up/down conversion */ char psz_croppadd[100]; int i_padd,i_offset; char *psz_aspect, *psz_parser; bool b_padd; unsigned i_fmt_in_aspect; if( !p_filter->b_allow_fmt_out_change ) { msg_Err( p_filter, "Picture format change isn't allowed" ); return VLC_EGENERIC; } if( p_filter->fmt_in.video.i_chroma != p_filter->fmt_out.video.i_chroma ) { msg_Err( p_filter, "Input and output chromas don't match" ); return VLC_EGENERIC; } config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options, p_filter->p_cfg ); i_canvas_width = var_CreateGetInteger( p_filter, CFG_PREFIX "width" ); i_canvas_height = var_CreateGetInteger( p_filter, CFG_PREFIX "height" ); if( i_canvas_width == 0 || i_canvas_height == 0 ) { msg_Err( p_filter, "Width and height options must be set" ); return VLC_EGENERIC; } if( i_canvas_width & 1 || i_canvas_height & 1 ) { /* If this restriction were ever relaxed, it is very important to * get the field polatiry correct */ msg_Err( p_filter, "Width and height options must be even integers" ); return VLC_EGENERIC; } i_fmt_in_aspect = (int64_t)p_filter->fmt_in.video.i_sar_num * p_filter->fmt_in.video.i_width * VOUT_ASPECT_FACTOR / p_filter->fmt_in.video.i_sar_den / p_filter->fmt_in.video.i_height; psz_aspect = var_CreateGetNonEmptyString( p_filter, CFG_PREFIX "aspect" ); if( psz_aspect ) { psz_parser = strchr( psz_aspect, ':' ); int numerator = atoi( psz_aspect ); int denominator = psz_parser ? atoi( psz_parser+1 ) : 0; denominator = denominator == 0 ? 1 : denominator; i_canvas_aspect = numerator * VOUT_ASPECT_FACTOR / denominator; free( psz_aspect ); if( numerator <= 0 || denominator < 0 ) { msg_Err( p_filter, "Aspect ratio must be strictly positive" ); return VLC_EGENERIC; } } else { /* if there is no user supplied aspect ratio, assume the canvas * has the same sample aspect ratio as the subpicture */ /* aspect = subpic_sar * canvas_width / canvas_height * where subpic_sar = subpic_ph * subpic_par / subpic_pw */ i_canvas_aspect = (uint64_t) p_filter->fmt_in.video.i_height * i_fmt_in_aspect * i_canvas_width / (i_canvas_height * p_filter->fmt_in.video.i_width); } b_padd = var_CreateGetBool( p_filter, CFG_PREFIX "padd" ); filter_sys_t *p_sys = (filter_sys_t *)malloc( sizeof( filter_sys_t ) ); if( !p_sys ) return VLC_ENOMEM; p_filter->p_sys = p_sys; p_sys->p_chain = filter_chain_New( p_filter, "video filter2", true, alloc_init, NULL, p_filter ); if( !p_sys->p_chain ) { msg_Err( p_filter, "Could not allocate filter chain" ); free( p_sys ); return VLC_EGENERIC; } es_format_Copy( &fmt, &p_filter->fmt_in ); /* one dimension will end up with one of the following: */ fmt.video.i_width = i_canvas_width; fmt.video.i_height = i_canvas_height; if( b_padd ) { /* Padd */ if( i_canvas_aspect > i_fmt_in_aspect ) { /* The canvas has a wider aspect than the subpicture: * ie, pillarbox the [scaled] subpicture */ /* The following is derived form: * width = upconverted_subpic_height * subpic_par / canvas_sar * where canvas_sar = canvas_width / (canvas_height * canvas_par) * then simplify */ fmt.video.i_width = i_canvas_width * i_fmt_in_aspect / i_canvas_aspect; if( fmt.video.i_width & 1 ) fmt.video.i_width -= 1; i_padd = (i_canvas_width - fmt.video.i_width) / 2; i_offset = (i_padd & 1); _snprintf( psz_croppadd, 100, "croppadd{paddleft=%d,paddright=%d}", i_padd - i_offset, i_padd + i_offset ); // sunqueen modify } else { /* The canvas has a taller aspect than the subpicture: * ie, letterbox the [scaled] subpicture */ fmt.video.i_height = i_canvas_height * i_canvas_aspect / i_fmt_in_aspect; if( fmt.video.i_height & 1 ) fmt.video.i_height -= 1; i_padd = (i_canvas_height - fmt.video.i_height ) / 2; i_offset = (i_padd & 1); _snprintf( psz_croppadd, 100, "croppadd{paddtop=%d,paddbottom=%d}", i_padd - i_offset, i_padd + i_offset ); // sunqueen modify } } else { /* Crop */ if( i_canvas_aspect < i_fmt_in_aspect ) { /* The canvas has a narrower aspect than the subpicture: * ie, crop the [scaled] subpicture horizontally */ fmt.video.i_width = i_canvas_width * i_fmt_in_aspect / i_canvas_aspect; if( fmt.video.i_width & 1 ) fmt.video.i_width -= 1; i_padd = (fmt.video.i_width - i_canvas_width) / 2; i_offset = (i_padd & 1); _snprintf( psz_croppadd, 100, "croppadd{cropleft=%d,cropright=%d}", i_padd - i_offset, i_padd + i_offset ); // sunqueen modify } else { /* The canvas has a shorter aspect than the subpicture: * ie, crop the [scaled] subpicture vertically */ fmt.video.i_height = i_canvas_height * i_canvas_aspect / i_fmt_in_aspect; if( fmt.video.i_height & 1 ) fmt.video.i_height -= 1; i_padd = (fmt.video.i_height - i_canvas_height) / 2; i_offset = (i_padd & 1); _snprintf( psz_croppadd, 100, "croppadd{croptop=%d,cropbottom=%d}", i_padd - i_offset, i_padd + i_offset ); // sunqueen modify } } /* xxx, should the clean area include the letter-boxing? * probably not, as some codecs can make use of that information * and it should be a scaled version of the input clean area * -- davidf */ fmt.video.i_visible_width = fmt.video.i_width; fmt.video.i_visible_height = fmt.video.i_height; filter_chain_Reset( p_sys->p_chain, &p_filter->fmt_in, &fmt ); /* Append scaling module */ filter_chain_AppendFilter( p_sys->p_chain, NULL, NULL, NULL, NULL ); /* Append padding module */ filter_chain_AppendFromString( p_sys->p_chain, psz_croppadd ); fmt = *filter_chain_GetFmtOut( p_sys->p_chain ); es_format_Copy( &p_filter->fmt_out, &fmt ); p_filter->fmt_out.video.i_sar_num = i_canvas_aspect * p_filter->fmt_out.video.i_height; p_filter->fmt_out.video.i_sar_den = VOUT_ASPECT_FACTOR * p_filter->fmt_out.video.i_width; if( p_filter->fmt_out.video.i_width != i_canvas_width || p_filter->fmt_out.video.i_height != i_canvas_height ) { msg_Warn( p_filter, "Looks like something went wrong. " "Output size is %dx%d while we asked for %dx%d", p_filter->fmt_out.video.i_width, p_filter->fmt_out.video.i_height, i_canvas_width, i_canvas_height ); } p_filter->pf_video_filter = Filter; return VLC_SUCCESS; }
/** This function allocates and initialize the DirectX vout display. */ static int Open(vlc_object_t *object) { vout_display_t *vd = (vout_display_t *)object; vout_display_sys_t *sys; /* Allocate structure */ vd->sys = sys = calloc(1, sizeof(*sys)); if (!sys) return VLC_ENOMEM; /* Load direct draw DLL */ sys->hddraw_dll = LoadLibrary(_T("DDRAW.DLL")); if (!sys->hddraw_dll) { msg_Warn(vd, "DirectXInitDDraw failed loading ddraw.dll"); free(sys); return VLC_EGENERIC; } /* */ sys->use_wallpaper = var_CreateGetBool(vd, "video-wallpaper"); /* FIXME */ sys->use_overlay = false;//var_CreateGetBool(vd, "overlay"); /* FIXME */ sys->restore_overlay = false; var_Create(vd, "directx-device", VLC_VAR_STRING | VLC_VAR_DOINHERIT); /* Initialisation */ if (CommonInit(vd)) goto error; /* */ video_format_t fmt = vd->fmt; if (DirectXOpen(vd, &fmt)) goto error; /* */ vout_display_info_t info = vd->info; info.is_slow = true; info.has_double_click = true; info.has_hide_mouse = false; info.has_pictures_invalid = true; info.has_event_thread = true; /* Interaction TODO support starting with wallpaper mode */ vlc_mutex_init(&sys->lock); sys->ch_wallpaper = sys->use_wallpaper; sys->wallpaper_requested = sys->use_wallpaper; sys->use_wallpaper = false; vlc_value_t val; val.psz_string = _("Wallpaper"); var_Change(vd, "video-wallpaper", VLC_VAR_SETTEXT, &val, NULL); var_AddCallback(vd, "video-wallpaper", WallpaperCallback, NULL); /* Setup vout_display now that everything is fine */ vd->fmt = fmt; vd->info = info; vd->pool = Pool; vd->prepare = NULL; vd->display = Display; vd->control = Control; vd->manage = Manage; return VLC_SUCCESS; error: DirectXClose(vd); CommonClean(vd); if (sys->hddraw_dll) FreeLibrary(sys->hddraw_dll); free(sys); return VLC_EGENERIC; }
static int Start_LuaIntf( vlc_object_t *p_this, const char *name ) { intf_thread_t *p_intf = (intf_thread_t*)p_this; intf_sys_t *p_sys; lua_State *L; config_ChainParse( p_intf, "lua-", ppsz_intf_options, p_intf->p_cfg ); char *psz_config; bool b_config_set = false; if( name == NULL ) { char *n = var_InheritString( p_this, "lua-intf" ); if( unlikely(n == NULL) ) return VLC_EGENERIC; name = p_intf->psz_header = n; } else /* Cleaned up by vlc_object_release() */ p_intf->psz_header = strdup( name ); p_intf->p_sys = (intf_sys_t*)malloc( sizeof(intf_sys_t) ); if( !p_intf->p_sys ) { free( p_intf->psz_header ); p_intf->psz_header = NULL; return VLC_ENOMEM; } p_sys = p_intf->p_sys; p_sys->psz_filename = vlclua_find_file( p_this, "intf", name ); if( !p_sys->psz_filename ) { msg_Err( p_intf, "Couldn't find lua interface script \"%s\".", name ); goto error; } msg_Dbg( p_intf, "Found lua interface script: %s", p_sys->psz_filename ); L = luaL_newstate(); if( !L ) { msg_Err( p_intf, "Could not create new Lua State" ); goto error; } vlclua_set_this( L, p_intf ); vlclua_set_intf( L, p_sys ); luaL_openlibs( L ); /* register our functions */ luaL_register( L, "vlc", p_reg ); /* register submodules */ luaopen_acl( L ); luaopen_config( L ); luaopen_volume( L ); luaopen_httpd( L ); luaopen_input( L ); luaopen_msg( L ); luaopen_misc( L ); luaopen_net( L ); luaopen_object( L ); luaopen_osd( L ); luaopen_playlist( L ); luaopen_sd( L ); luaopen_stream( L ); luaopen_strings( L ); luaopen_variables( L ); luaopen_video( L ); luaopen_vlm( L ); luaopen_volume( L ); luaopen_gettext( L ); luaopen_xml( L ); luaopen_equalizer( L ); /* clean up */ lua_pop( L, 1 ); /* Setup the module search path */ if( vlclua_add_modules_path( p_intf, L, p_sys->psz_filename ) ) { msg_Warn( p_intf, "Error while setting the module search path for %s", p_sys->psz_filename ); lua_close( L ); goto error; } /* * Get the lua-config string. * If the string is empty, try with the old http-* or telnet-* options * and build the right configuration line */ psz_config = var_CreateGetNonEmptyString( p_intf, "lua-config" ); if( !psz_config ) { if( !strcmp( name, "http" ) ) { char *psz_http_src = var_CreateGetNonEmptyString( p_intf, "http-src" ); bool b_http_index = var_CreateGetBool( p_intf, "http-index" ); if( psz_http_src ) { char *psz_esc = config_StringEscape( psz_http_src ); if( psz_config ) { char *psz_tmp; asprintf( &psz_tmp, "%s,dir='%s'", psz_config, psz_esc ); free( psz_config ); psz_config = psz_tmp; } else asprintf( &psz_config, "http={dir='%s'", psz_esc ); free( psz_esc ); free( psz_http_src ); } if( psz_config ) { char *psz_tmp; asprintf( &psz_tmp, "%s,no_index=%s}", psz_config, b_http_index ? "true" : "false" ); free( psz_config ); psz_config = psz_tmp; } else asprintf( &psz_config, "http={no_index=%s}", b_http_index ? "true" : "false" ); } else if( !strcmp( name, "telnet" ) ) { char *psz_telnet_host = var_CreateGetString( p_intf, "telnet-host" ); if( !strcmp( psz_telnet_host, "*console" ) ) ; else { vlc_url_t url; vlc_UrlParse( &url, psz_telnet_host, 0 ); int i_telnet_port = var_CreateGetInteger( p_intf, "telnet-port" ); if ( url.i_port != 0 ) { if ( i_telnet_port == TELNETPORT_DEFAULT ) i_telnet_port = url.i_port; else if ( url.i_port != i_telnet_port ) msg_Warn( p_intf, "ignoring port %d (using %d)", url.i_port, i_telnet_port ); } char *psz_esc_host = config_StringEscape( url.psz_host ); free( psz_telnet_host ); vlc_UrlClean( &url ); asprintf( &psz_telnet_host, "telnet://%s:%d", psz_esc_host ? psz_esc_host : "", i_telnet_port ); free( psz_esc_host ); } char *psz_telnet_passwd = var_CreateGetString( p_intf, "telnet-password" ); char *psz_esc_passwd = config_StringEscape( psz_telnet_passwd ); asprintf( &psz_config, "telnet={host='%s',password='******'}", psz_telnet_host, psz_esc_passwd ); free( psz_esc_passwd ); free( psz_telnet_passwd ); free( psz_telnet_host ); } else if( !strcmp( name, "cli" ) ) { char *psz_rc_host = var_CreateGetNonEmptyString( p_intf, "rc-host" ); if( !psz_rc_host ) psz_rc_host = var_CreateGetNonEmptyString( p_intf, "cli-host" ); if( psz_rc_host ) { char *psz_esc_host = config_StringEscape( psz_rc_host ); asprintf( &psz_config, "cli={host='%s'}", psz_esc_host ); free( psz_esc_host ); free( psz_rc_host ); } } } if( psz_config ) { char *psz_buffer; if( asprintf( &psz_buffer, "config={%s}", psz_config ) != -1 ) { char *psz_log = StripPasswords( psz_buffer ); if( psz_log != NULL ) { msg_Dbg( p_intf, "Setting config variable: %s", psz_log ); free( psz_log ); } if( luaL_dostring( L, psz_buffer ) == 1 ) msg_Err( p_intf, "Error while parsing \"lua-config\"." ); free( psz_buffer ); lua_getglobal( L, "config" ); if( lua_istable( L, -1 ) ) { if( !strcmp( name, "cli" ) ) { lua_getfield( L, -1, "rc" ); if( lua_istable( L, -1 ) ) { /* msg_Warn( p_intf, "The `rc' lua interface script " "was renamed `cli', please update " "your configuration!" ); */ lua_setfield( L, -2, "cli" ); } else lua_pop( L, 1 ); } lua_getfield( L, -1, name ); if( lua_istable( L, -1 ) ) { lua_setglobal( L, "config" ); b_config_set = true; } } } free( psz_config ); } if( !b_config_set ) { lua_newtable( L ); lua_setglobal( L, "config" ); } /* Wrapper for legacy telnet config */ if ( !strcmp( name, "telnet" ) ) { /* msg_Warn( p_intf, "The `telnet' lua interface script was replaced " "by `cli', please update your configuration!" ); */ char *wrapped_file = vlclua_find_file( p_this, "intf", "cli" ); if( !wrapped_file ) { msg_Err( p_intf, "Couldn't find lua interface script \"cli\", " "needed by telnet wrapper" ); lua_close( p_sys->L ); goto error; } lua_pushstring( L, wrapped_file ); lua_setglobal( L, "wrapped_file" ); free( wrapped_file ); } p_sys->L = L; vlc_mutex_init( &p_sys->lock ); vlc_cond_init( &p_sys->wait ); p_sys->exiting = false; if( vlc_clone( &p_sys->thread, Run, p_intf, VLC_THREAD_PRIORITY_LOW ) ) { vlc_cond_destroy( &p_sys->wait ); vlc_mutex_destroy( &p_sys->lock ); lua_close( p_sys->L ); goto error; } return VLC_SUCCESS; error: free( p_sys->psz_filename ); free( p_sys ); free( p_intf->psz_header ); p_intf->psz_header = NULL; return VLC_EGENERIC; }
/***************************************************************************** * OpenDecoder: probe the decoder and return score ***************************************************************************** * Tries to launch a decoder and return score so that the interface is able * to chose. *****************************************************************************/ static int OpenDecoder( vlc_object_t *p_this ) { decoder_t *p_dec = (decoder_t*)p_this; decoder_sys_t *p_sys; if( p_dec->fmt_in.i_codec != VLC_CODEC_KATE ) { return VLC_EGENERIC; } msg_Dbg( p_dec, "kate: OpenDecoder"); /* Set callbacks */ p_dec->pf_decode_sub = (subpicture_t *(*)(decoder_t *, block_t **)) DecodeBlock; p_dec->pf_packetize = (block_t *(*)(decoder_t *, block_t **)) DecodeBlock; /* Allocate the memory needed to store the decoder's structure */ if( ( p_dec->p_sys = p_sys = (decoder_sys_t *)malloc(sizeof(*p_sys)) ) == NULL ) // sunqueen modify return VLC_ENOMEM; vlc_mutex_init( &p_sys->lock ); p_sys->i_refcount = 0; DecSysHold( p_sys ); /* init of p_sys */ #ifdef ENABLE_PACKETIZER p_sys->b_packetizer = false; #endif p_sys->b_ready = false; p_sys->i_pts = p_sys->i_max_stop = VLC_TS_INVALID; kate_comment_init( &p_sys->kc ); kate_info_init( &p_sys->ki ); p_sys->b_has_headers = false; /* retrieve options */ p_sys->b_formatted = var_CreateGetBool( p_dec, "kate-formatted" ); vlc_mutex_lock( &kate_decoder_list_mutex ); #ifdef HAVE_TIGER p_sys->b_use_tiger = var_CreateGetBool( p_dec, "kate-use-tiger" ); p_sys->p_tr = NULL; /* get initial value of configuration */ p_sys->i_tiger_default_font_color = GetTigerColor( p_dec, "kate-tiger-default-font" ); p_sys->i_tiger_default_background_color = GetTigerColor( p_dec, "kate-tiger-default-background" ); p_sys->e_tiger_default_font_effect = GetTigerInteger( p_dec, "kate-tiger-default-font-effect" ); p_sys->f_tiger_default_font_effect_strength = GetTigerFloat( p_dec, "kate-tiger-default-font-effect-strength" ); p_sys->psz_tiger_default_font_desc = GetTigerString( p_dec, "kate-tiger-default-font-desc" ); p_sys->f_tiger_quality = GetTigerFloat( p_dec, "kate-tiger-quality" ); if( p_sys->b_use_tiger ) { int i_ret = tiger_renderer_create( &p_sys->p_tr ); if( i_ret < 0 ) { msg_Warn ( p_dec, "Failed to create Tiger renderer, falling back to basic rendering" ); p_sys->p_tr = NULL; p_sys->b_use_tiger = false; } else { CHECK_TIGER_RET( tiger_renderer_set_surface_clear_color( p_sys->p_tr, 1, 0, 0, 0, 0 ) ); UpdateTigerFontEffect( p_dec ); UpdateTigerFontColor( p_dec ); UpdateTigerBackgroundColor( p_dec ); UpdateTigerQuality( p_dec ); UpdateTigerFontDesc( p_dec ); } } #else p_sys->b_use_tiger = false; #endif es_format_Init( &p_dec->fmt_out, SPU_ES, 0 ); /* add the decoder to the global list */ decoder_t **list = (decoder_t **)realloc( kate_decoder_list, (kate_decoder_list_size+1) * sizeof( *list )); // sunqueen modify if( list ) { list[ kate_decoder_list_size++ ] = p_dec; kate_decoder_list = list; } vlc_mutex_unlock( &kate_decoder_list_mutex ); return VLC_SUCCESS; }
void vout_IntfInit( vout_thread_t *p_vout ) { vlc_value_t val, text, old_val; bool b_force_par = false; char *psz_buf; int i; /* Create a few object variables we'll need later on */ var_Create( p_vout, "snapshot-path", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); var_Create( p_vout, "snapshot-prefix", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); var_Create( p_vout, "snapshot-format", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); var_Create( p_vout, "snapshot-preview", VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); var_Create( p_vout, "snapshot-sequential", VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); var_Create( p_vout, "snapshot-num", VLC_VAR_INTEGER ); var_SetInteger( p_vout, "snapshot-num", 1 ); var_Create( p_vout, "snapshot-width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); var_Create( p_vout, "snapshot-height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); var_Create( p_vout, "width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); var_Create( p_vout, "height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); p_vout->i_alignment = var_CreateGetInteger( p_vout, "align" ); var_Create( p_vout, "video-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); var_Create( p_vout, "video-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); var_Create( p_vout, "mouse-hide-timeout", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); p_vout->b_title_show = var_CreateGetBool( p_vout, "video-title-show" ); p_vout->i_title_timeout = (mtime_t)var_CreateGetInteger( p_vout, "video-title-timeout" ); p_vout->i_title_position = var_CreateGetInteger( p_vout, "video-title-position" ); var_AddCallback( p_vout, "video-title-show", TitleShowCallback, NULL ); var_AddCallback( p_vout, "video-title-timeout", TitleTimeoutCallback, NULL ); var_AddCallback( p_vout, "video-title-position", TitlePositionCallback, NULL ); /* Zoom object var */ var_Create( p_vout, "zoom", VLC_VAR_FLOAT | VLC_VAR_ISCOMMAND | VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT ); text.psz_string = _("Zoom"); var_Change( p_vout, "zoom", VLC_VAR_SETTEXT, &text, NULL ); var_Get( p_vout, "zoom", &old_val ); for( i = 0; p_zoom_values[i].f_value; i++ ) { if( old_val.f_float == p_zoom_values[i].f_value ) var_Change( p_vout, "zoom", VLC_VAR_DELCHOICE, &old_val, NULL ); val.f_float = p_zoom_values[i].f_value; text.psz_string = _( p_zoom_values[i].psz_label ); var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text ); } var_Set( p_vout, "zoom", old_val ); /* Is this really needed? */ var_AddCallback( p_vout, "zoom", ZoomCallback, NULL ); /* Crop offset vars */ var_Create( p_vout, "crop-left", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND ); var_Create( p_vout, "crop-top", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND ); var_Create( p_vout, "crop-right", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND ); var_Create( p_vout, "crop-bottom", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND ); var_AddCallback( p_vout, "crop-left", CropCallback, NULL ); var_AddCallback( p_vout, "crop-top", CropCallback, NULL ); var_AddCallback( p_vout, "crop-right", CropCallback, NULL ); var_AddCallback( p_vout, "crop-bottom", CropCallback, NULL ); /* Crop object var */ var_Create( p_vout, "crop", VLC_VAR_STRING | VLC_VAR_ISCOMMAND | VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT ); text.psz_string = _("Crop"); var_Change( p_vout, "crop", VLC_VAR_SETTEXT, &text, NULL ); val.psz_string = (char*)""; var_Change( p_vout, "crop", VLC_VAR_DELCHOICE, &val, 0 ); for( i = 0; p_crop_values[i].psz_value; i++ ) { val.psz_string = (char*)p_crop_values[i].psz_value; text.psz_string = _( p_crop_values[i].psz_label ); var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text ); } /* update triggered every time the vout's crop parameters are changed */ var_Create( p_vout, "crop-update", VLC_VAR_VOID ); /* Add custom crop ratios */ psz_buf = config_GetPsz( p_vout, "custom-crop-ratios" ); AddCustomRatios( p_vout, "crop", psz_buf ); free( psz_buf ); var_AddCallback( p_vout, "crop", CropCallback, NULL ); var_Get( p_vout, "crop", &old_val ); if( old_val.psz_string && *old_val.psz_string ) var_Change( p_vout, "crop", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 ); free( old_val.psz_string ); /* Monitor pixel aspect-ratio */ var_Create( p_vout, "monitor-par", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); var_Get( p_vout, "monitor-par", &val ); if( val.psz_string && *val.psz_string ) { char *psz_parser = strchr( val.psz_string, ':' ); unsigned int i_aspect_num = 0, i_aspect_den = 0; float i_aspect = 0; if( psz_parser ) { i_aspect_num = strtol( val.psz_string, 0, 10 ); i_aspect_den = strtol( ++psz_parser, 0, 10 ); } else { i_aspect = atof( val.psz_string ); vlc_ureduce( &i_aspect_num, &i_aspect_den, i_aspect *VOUT_ASPECT_FACTOR, VOUT_ASPECT_FACTOR, 0 ); } if( !i_aspect_num || !i_aspect_den ) i_aspect_num = i_aspect_den = 1; p_vout->i_par_num = i_aspect_num; p_vout->i_par_den = i_aspect_den; vlc_ureduce( &p_vout->i_par_num, &p_vout->i_par_den, p_vout->i_par_num, p_vout->i_par_den, 0 ); msg_Dbg( p_vout, "overriding monitor pixel aspect-ratio: %i:%i", p_vout->i_par_num, p_vout->i_par_den ); b_force_par = true; } free( val.psz_string ); /* Aspect-ratio object var */ var_Create( p_vout, "aspect-ratio", VLC_VAR_STRING | VLC_VAR_ISCOMMAND | VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT ); text.psz_string = _("Aspect-ratio"); var_Change( p_vout, "aspect-ratio", VLC_VAR_SETTEXT, &text, NULL ); val.psz_string = (char*)""; var_Change( p_vout, "aspect-ratio", VLC_VAR_DELCHOICE, &val, 0 ); for( i = 0; p_aspect_ratio_values[i].psz_value; i++ ) { val.psz_string = (char*)p_aspect_ratio_values[i].psz_value; text.psz_string = _( p_aspect_ratio_values[i].psz_label ); var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text ); } /* Add custom aspect ratios */ psz_buf = config_GetPsz( p_vout, "custom-aspect-ratios" ); AddCustomRatios( p_vout, "aspect-ratio", psz_buf ); free( psz_buf ); var_AddCallback( p_vout, "aspect-ratio", AspectCallback, NULL ); var_Get( p_vout, "aspect-ratio", &old_val ); if( (old_val.psz_string && *old_val.psz_string) || b_force_par ) var_Change( p_vout, "aspect-ratio", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 ); free( old_val.psz_string ); /* Initialize the dimensions of the video window */ InitWindowSize( p_vout, &p_vout->i_window_width, &p_vout->i_window_height ); /* Add a variable to indicate if the window should be on top of others */ var_Create( p_vout, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT | VLC_VAR_ISCOMMAND ); text.psz_string = _("Always on top"); var_Change( p_vout, "video-on-top", VLC_VAR_SETTEXT, &text, NULL ); var_AddCallback( p_vout, "video-on-top", OnTopCallback, NULL ); /* Add a variable to indicate whether we want window decoration or not */ var_Create( p_vout, "video-deco", VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); /* Add a fullscreen variable */ if( var_CreateGetBoolCommand( p_vout, "fullscreen" ) ) { /* user requested fullscreen */ p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE; } text.psz_string = _("Fullscreen"); var_Change( p_vout, "fullscreen", VLC_VAR_SETTEXT, &text, NULL ); var_AddCallback( p_vout, "fullscreen", FullscreenCallback, NULL ); /* Add a snapshot variable */ var_Create( p_vout, "video-snapshot", VLC_VAR_VOID | VLC_VAR_ISCOMMAND ); text.psz_string = _("Snapshot"); var_Change( p_vout, "video-snapshot", VLC_VAR_SETTEXT, &text, NULL ); var_AddCallback( p_vout, "video-snapshot", SnapshotCallback, NULL ); /* Mouse coordinates */ var_Create( p_vout, "mouse-x", VLC_VAR_INTEGER ); var_Create( p_vout, "mouse-y", VLC_VAR_INTEGER ); var_Create( p_vout, "mouse-button-down", VLC_VAR_INTEGER ); var_Create( p_vout, "mouse-moved", VLC_VAR_BOOL ); var_Create( p_vout, "mouse-clicked", VLC_VAR_INTEGER ); var_Create( p_vout, "intf-change", VLC_VAR_BOOL ); var_SetBool( p_vout, "intf-change", true ); }
static void PMThread( void *arg ) { vout_display_t *vd = ( vout_display_t * )arg; vout_display_sys_t * sys = vd->sys; ULONG i_frame_flags; QMSG qm; char *psz_mode; ULONG i_kva_mode; /* */ video_format_t fmt = vd->fmt; /* */ vout_display_info_t info = vd->info; info.is_slow = false; info.has_double_click = true; info.has_hide_mouse = false; info.has_pictures_invalid = false; MorphToPM(); sys->hab = WinInitialize( 0 ); sys->hmq = WinCreateMsgQueue( sys->hab, 0); WinRegisterClass( sys->hab, WC_VLC_KVA, WndProc, CS_SIZEREDRAW | CS_MOVENOTIFY, sizeof( PVOID )); sys->b_fixt23 = var_CreateGetBool( vd, "kva-fixt23"); if( !sys->b_fixt23 ) { vout_window_cfg_t wnd_cfg; wnd_cfg.is_standalone = false; wnd_cfg.type = VOUT_WINDOW_TYPE_HWND; wnd_cfg.x = var_InheritInteger(vd, "video-x"); wnd_cfg.y = var_InheritInteger(vd, "video-y"); wnd_cfg.width = vd->cfg->display.width; wnd_cfg.height = vd->cfg->display.height; /* If an external window was specified, we'll draw in it. */ sys->parent_window = vout_display_NewWindow( vd, &wnd_cfg ); } if( sys->parent_window ) { sys->parent = ( HWND )sys->parent_window->handle.hwnd; /* Workaround : * When an embedded window opened first, it is not positioned * correctly. So reposition it here, again. */ WinSetWindowPos( WinQueryWindow( sys->parent, QW_PARENT ), HWND_TOP, 0, 0, 0, 0, SWP_MOVE ); ULONG i_style = WinQueryWindowULong( sys->parent, QWL_STYLE ); WinSetWindowULong( sys->parent, QWL_STYLE, i_style | WS_CLIPCHILDREN ); i_frame_flags = FCF_TITLEBAR; } else { sys->parent = HWND_DESKTOP; i_frame_flags = FCF_SYSMENU | FCF_TITLEBAR | FCF_MINMAX | FCF_SIZEBORDER | FCF_TASKLIST; } sys->frame = WinCreateStdWindow( sys->parent, /* parent window handle */ WS_VISIBLE, /* frame window style */ &i_frame_flags, /* window style */ WC_VLC_KVA, /* class name */ "", /* window title */ 0L, /* default client style */ NULLHANDLE, /* resource in exe file */ 1, /* frame window id */ &sys->client ); /* client window handle */ if( sys->frame == NULLHANDLE ) { msg_Err( vd, "cannot create a frame window"); goto exit_frame; } WinSetWindowPtr( sys->client, 0, vd ); if( sys->b_fixt23 ) { WinSetWindowPtr( sys->frame, 0, vd ); sys->p_old_frame = WinSubclassWindow( sys->frame, MyFrameWndProc ); } psz_mode = var_CreateGetString( vd, "kva-video-mode" ); i_kva_mode = KVAM_AUTO; if( strcmp( psz_mode, "snap" ) == 0 ) i_kva_mode = KVAM_SNAP; else if( strcmp( psz_mode, "wo" ) == 0 ) i_kva_mode = KVAM_WO; else if( strcmp( psz_mode, "vman" ) == 0 ) i_kva_mode = KVAM_VMAN; else if( strcmp( psz_mode, "dive" ) == 0 ) i_kva_mode = KVAM_DIVE; free( psz_mode ); if( kvaInit( i_kva_mode, sys->client, COLOR_KEY )) { msg_Err( vd, "cannot initialize KVA"); goto exit_kva_init; } kvaCaps( &sys->kvac ); msg_Dbg( vd, "selected video mode = %s", psz_video_mode[ sys->kvac.ulMode - 1 ]); if( OpenDisplay( vd, &fmt ) ) { msg_Err( vd, "cannot open display"); goto exit_open_display; } if( vd->cfg->is_fullscreen ) { if( sys->parent_window ) vout_window_SetFullScreen(sys->parent_window, true); else WinPostMsg( sys->client, WM_VLC_FULLSCREEN_CHANGE, MPFROMLONG( true ), 0 ); } kvaDisableScreenSaver(); /* Setup vout_display now that everything is fine */ vd->fmt = fmt; vd->info = info; vd->pool = Pool; vd->prepare = NULL; vd->display = Display; vd->control = Control; vd->manage = Manage; /* Prevent SIG_FPE */ _control87(MCW_EM, MCW_EM); sys->i_result = VLC_SUCCESS; DosPostEventSem( sys->ack_event ); while( WinGetMsg( sys->hab, &qm, NULLHANDLE, 0, 0 )) WinDispatchMsg( sys->hab, &qm ); kvaEnableScreenSaver(); CloseDisplay( vd ); /* fall through */ exit_open_display : kvaDone(); exit_kva_init : if( sys->b_fixt23 ) WinSubclassWindow( sys->frame, sys->p_old_frame ); WinDestroyWindow( sys->frame ); exit_frame : vout_display_DeleteWindow( vd, sys->parent_window ); if( sys->is_mouse_hidden ) WinShowPointer( HWND_DESKTOP, TRUE ); WinDestroyMsgQueue( sys->hmq ); WinTerminate( sys->hab ); sys->i_result = VLC_EGENERIC; DosPostEventSem( sys->ack_event ); }
/***************************************************************************** * Open: open a dummy audio device *****************************************************************************/ static int Open( vlc_object_t * p_this ) { aout_instance_t * p_aout = (aout_instance_t *)p_this; char * psz_name, * psz_format; const char * const * ppsz_compare = format_list; int i_channels, i = 0; psz_name = var_CreateGetString( p_this, "audiofile-file" ); if( !psz_name || !*psz_name ) { msg_Err( p_aout, "you need to specify an output file name" ); free( psz_name ); return VLC_EGENERIC; } /* Allocate structure */ p_aout->output.p_sys = malloc( sizeof( aout_sys_t ) ); if( p_aout->output.p_sys == NULL ) return VLC_ENOMEM; if( !strcmp( psz_name, "-" ) ) p_aout->output.p_sys->p_file = stdout; else p_aout->output.p_sys->p_file = utf8_fopen( psz_name, "wb" ); free( psz_name ); if ( p_aout->output.p_sys->p_file == NULL ) { free( p_aout->output.p_sys ); return VLC_EGENERIC; } p_aout->output.pf_play = Play; /* Audio format */ psz_format = var_CreateGetString( p_this, "audiofile-format" ); while ( *ppsz_compare != NULL ) { if ( !strncmp( *ppsz_compare, psz_format, strlen(*ppsz_compare) ) ) { break; } ppsz_compare++; i++; } if ( *ppsz_compare == NULL ) { msg_Err( p_aout, "cannot understand the format string (%s)", psz_format ); if( p_aout->output.p_sys->p_file != stdout ) fclose( p_aout->output.p_sys->p_file ); free( p_aout->output.p_sys ); free( psz_format ); return VLC_EGENERIC; } free( psz_format ); p_aout->output.output.i_format = format_int[i]; if ( AOUT_FMT_NON_LINEAR( &p_aout->output.output ) ) { p_aout->output.i_nb_samples = A52_FRAME_NB; p_aout->output.output.i_bytes_per_frame = AOUT_SPDIF_SIZE; p_aout->output.output.i_frame_length = A52_FRAME_NB; aout_VolumeNoneInit( p_aout ); } else { p_aout->output.i_nb_samples = FRAME_SIZE; aout_VolumeSoftInit( p_aout ); } /* Channels number */ i_channels = var_CreateGetInteger( p_this, "audiofile-channels" ); if( i_channels > 0 && i_channels <= CHANNELS_MAX ) { p_aout->output.output.i_physical_channels = pi_channels_maps[i_channels]; } /* WAV header */ p_aout->output.p_sys->b_add_wav_header = var_CreateGetBool( p_this, "audiofile-wav" ); if( p_aout->output.p_sys->b_add_wav_header ) { /* Write wave header */ WAVEHEADER *wh = &p_aout->output.p_sys->waveh; memset( wh, 0, sizeof(wh) ); switch( p_aout->output.output.i_format ) { case VLC_CODEC_FL32: wh->Format = WAVE_FORMAT_IEEE_FLOAT; wh->BitsPerSample = sizeof(float) * 8; break; case VLC_CODEC_U8: wh->Format = WAVE_FORMAT_PCM; wh->BitsPerSample = 8; break; case VLC_CODEC_S16L: default: wh->Format = WAVE_FORMAT_PCM; wh->BitsPerSample = 16; break; } wh->MainChunkID = VLC_FOURCC('R', 'I', 'F', 'F'); wh->Length = 0; /* temp, to be filled in as we go */ wh->ChunkTypeID = VLC_FOURCC('W', 'A', 'V', 'E'); wh->SubChunkID = VLC_FOURCC('f', 'm', 't', ' '); wh->SubChunkLength = 16; wh->Modus = aout_FormatNbChannels( &p_aout->output.output ); wh->SampleFreq = p_aout->output.output.i_rate; wh->BytesPerSample = wh->Modus * ( wh->BitsPerSample / 8 ); wh->BytesPerSec = wh->BytesPerSample * wh->SampleFreq; wh->DataChunkID = VLC_FOURCC('d', 'a', 't', 'a'); wh->DataLength = 0; /* temp, to be filled in as we go */ /* Header -> little endian format */ SetWLE( &wh->Format, wh->Format ); SetWLE( &wh->BitsPerSample, wh->BitsPerSample ); SetDWLE( &wh->SubChunkLength, wh->SubChunkLength ); SetWLE( &wh->Modus, wh->Modus ); SetDWLE( &wh->SampleFreq, wh->SampleFreq ); SetWLE( &wh->BytesPerSample, wh->BytesPerSample ); SetDWLE( &wh->BytesPerSec, wh->BytesPerSec ); if( fwrite( wh, sizeof(WAVEHEADER), 1, p_aout->output.p_sys->p_file ) != 1 ) { msg_Err( p_aout, "write error (%m)" ); } } return 0; }
static int Open( vlc_object_t *p_this ) { /* initialisation of the connection */ intf_thread_t *p_intf = (intf_thread_t*)p_this; intf_sys_t *p_sys = malloc( sizeof( intf_sys_t ) ); playlist_t *p_playlist; DBusConnection *p_conn; DBusError error; char *psz_service_name = NULL; if( !p_sys || !dbus_threads_init_default()) return VLC_ENOMEM; p_sys->b_meta_read = false; p_sys->i_caps = CAPS_NONE; p_sys->b_dead = false; p_sys->p_input = NULL; p_sys->i_playing_state = -1; if( vlc_pipe( p_sys->p_pipe_fds ) ) { free( p_sys ); msg_Err( p_intf, "Could not create pipe" ); return VLC_EGENERIC; } p_sys->b_unique = var_CreateGetBool( p_intf, "dbus-unique-service-id" ); if( p_sys->b_unique ) { if( asprintf( &psz_service_name, "%s-%d", DBUS_MPRIS_BUS_NAME, getpid() ) < 0 ) { free( p_sys ); return VLC_ENOMEM; } } else { psz_service_name = strdup(DBUS_MPRIS_BUS_NAME); } dbus_error_init( &error ); /* connect privately to the session bus * the connection will not be shared with other vlc modules which use dbus, * thus avoiding a whole class of concurrency issues */ p_conn = dbus_bus_get_private( DBUS_BUS_SESSION, &error ); if( !p_conn ) { msg_Err( p_this, "Failed to connect to the D-Bus session daemon: %s", error.message ); dbus_error_free( &error ); free( psz_service_name ); free( p_sys ); return VLC_EGENERIC; } dbus_connection_set_exit_on_disconnect( p_conn, FALSE ); /* register a well-known name on the bus */ dbus_bus_request_name( p_conn, psz_service_name, 0, &error ); if( dbus_error_is_set( &error ) ) { msg_Err( p_this, "Error requesting service %s: %s", psz_service_name, error.message ); dbus_error_free( &error ); free( psz_service_name ); free( p_sys ); return VLC_EGENERIC; } msg_Info( p_intf, "listening on dbus as: %s", psz_service_name ); free( psz_service_name ); /* we register the objects */ dbus_connection_register_object_path( p_conn, DBUS_MPRIS_ROOT_PATH, &dbus_mpris_root_vtable, p_this ); dbus_connection_register_object_path( p_conn, DBUS_MPRIS_PLAYER_PATH, &dbus_mpris_player_vtable, p_this ); dbus_connection_register_object_path( p_conn, DBUS_MPRIS_TRACKLIST_PATH, &dbus_mpris_tracklist_vtable, p_this ); dbus_connection_flush( p_conn ); p_intf->pf_run = Run; p_intf->p_sys = p_sys; p_sys->p_conn = p_conn; p_sys->p_events = vlc_array_new(); p_sys->p_timeouts = vlc_array_new(); p_sys->p_watches = vlc_array_new(); vlc_mutex_init( &p_sys->lock ); p_playlist = pl_Get( p_intf ); p_sys->p_playlist = p_playlist; var_AddCallback( p_playlist, "item-current", AllCallback, p_intf ); var_AddCallback( p_playlist, "intf-change", AllCallback, p_intf ); var_AddCallback( p_playlist, "playlist-item-append", AllCallback, p_intf ); var_AddCallback( p_playlist, "playlist-item-deleted", AllCallback, p_intf ); var_AddCallback( p_playlist, "random", AllCallback, p_intf ); var_AddCallback( p_playlist, "repeat", AllCallback, p_intf ); var_AddCallback( p_playlist, "loop", AllCallback, p_intf ); dbus_connection_set_dispatch_status_function( p_conn, dispatch_status_cb, p_intf, NULL ); if( !dbus_connection_set_timeout_functions( p_conn, add_timeout, remove_timeout, timeout_toggled, p_intf, NULL ) ) { dbus_connection_unref( p_conn ); free( psz_service_name ); free( p_sys ); return VLC_ENOMEM; } if( !dbus_connection_set_watch_functions( p_conn, add_watch, remove_watch, watch_toggled, p_intf, NULL ) ) { dbus_connection_unref( p_conn ); free( psz_service_name ); free( p_sys ); return VLC_ENOMEM; } /* dbus_connection_set_wakeup_main_function( p_conn, wakeup_main_loop, p_intf, NULL); */ UpdateCaps( p_intf ); return VLC_SUCCESS; }
static int EqzInit( aout_filter_t *p_filter, int i_rate ) { aout_filter_sys_t *p_sys = p_filter->p_sys; const eqz_config_t *p_cfg; int i, ch; vlc_value_t val1, val2, val3; aout_instance_t *p_aout = (aout_instance_t *)p_filter->p_parent; /* Select the config */ if( i_rate == 48000 ) { p_cfg = &eqz_config_48000_10b; } else if( i_rate == 44100 ) { p_cfg = &eqz_config_44100_10b; } else { /* TODO compute the coeffs on the fly */ msg_Err( p_filter, "unsupported rate" ); return VLC_EGENERIC; } /* Create the static filter config */ p_sys->i_band = p_cfg->i_band; p_sys->f_alpha = malloc( p_sys->i_band * sizeof(float) ); p_sys->f_beta = malloc( p_sys->i_band * sizeof(float) ); p_sys->f_gamma = malloc( p_sys->i_band * sizeof(float) ); for( i = 0; i < p_sys->i_band; i++ ) { p_sys->f_alpha[i] = p_cfg->band[i].f_alpha; p_sys->f_beta[i] = p_cfg->band[i].f_beta; p_sys->f_gamma[i] = p_cfg->band[i].f_gamma; } /* Filter dyn config */ p_sys->b_2eqz = VLC_FALSE; p_sys->f_gamp = 1.0; p_sys->f_amp = malloc( p_sys->i_band * sizeof(float) ); for( i = 0; i < p_sys->i_band; i++ ) { p_sys->f_amp[i] = 0.0; } /* Filter state */ for( ch = 0; ch < 32; ch++ ) { p_sys->x[ch][0] = p_sys->x[ch][1] = p_sys->x2[ch][0] = p_sys->x2[ch][1] = 0.0; for( i = 0; i < p_sys->i_band; i++ ) { p_sys->y[ch][i][0] = p_sys->y[ch][i][1] = p_sys->y2[ch][i][0] = p_sys->y2[ch][i][1] = 0.0; } } var_CreateGetString( p_aout,"equalizer-bands" ); var_CreateGetString( p_aout, "equalizer-preset" ); p_sys->b_2eqz = var_CreateGetBool( p_aout, "equalizer-2pass" ); var_CreateGetFloat( p_aout, "equalizer-preamp" ); /* Get initial values */ var_Get( p_aout, "equalizer-preset", &val1 ); var_Get( p_aout, "equalizer-bands", &val2 ); var_Get( p_aout, "equalizer-preamp", &val3 ); p_sys->b_first = VLC_TRUE; PresetCallback( VLC_OBJECT( p_aout ), NULL, val1, val1, p_sys ); BandsCallback( VLC_OBJECT( p_aout ), NULL, val2, val2, p_sys ); PreampCallback( VLC_OBJECT( p_aout ), NULL, val3, val3, p_sys ); p_sys->b_first = VLC_FALSE; /* Register preset bands (for intf) if : */ /* We have no bands info --> the preset info must be given to the intf */ /* or The bands info matches the preset */ if (p_sys->psz_newbands == NULL) { msg_Err(p_filter, "No preset selected"); return (VLC_EGENERIC); } if( ( *(val2.psz_string) && strstr( p_sys->psz_newbands, val2.psz_string ) ) || !*val2.psz_string ) { var_SetString( p_aout, "equalizer-bands", p_sys->psz_newbands ); var_SetFloat( p_aout, "equalizer-preamp", p_sys->f_newpreamp ); } /* Add our own callbacks */ var_AddCallback( p_aout, "equalizer-preset", PresetCallback, p_sys ); var_AddCallback( p_aout, "equalizer-bands", BandsCallback, p_sys ); var_AddCallback( p_aout, "equalizer-preamp", PreampCallback, p_sys ); msg_Dbg( p_filter, "equalizer loaded for %d Hz with %d bands %d pass", i_rate, p_sys->i_band, p_sys->b_2eqz ? 2 : 1 ); for( i = 0; i < p_sys->i_band; i++ ) { msg_Dbg( p_filter, " %d Hz -> factor:%f alpha:%f beta:%f gamma:%f", (int)p_cfg->band[i].f_frequency, p_sys->f_amp[i], p_sys->f_alpha[i], p_sys->f_beta[i], p_sys->f_gamma[i]); } return VLC_SUCCESS; }
/***************************************************************************** * Open: *****************************************************************************/ static int Open( vlc_object_t *p_this ) { decoder_t *p_dec = (decoder_t*)p_this; decoder_sys_t *p_sys; if( p_dec->fmt_in.i_codec != VLC_CODEC_MPGV ) return VLC_EGENERIC; es_format_Init( &p_dec->fmt_out, VIDEO_ES, VLC_CODEC_MPGV ); p_dec->fmt_out.i_original_fourcc = p_dec->fmt_in.i_original_fourcc; p_dec->pf_packetize = Packetize; p_dec->pf_get_cc = GetCc; p_dec->p_sys = p_sys = malloc( sizeof( decoder_sys_t ) ); if( !p_dec->p_sys ) return VLC_ENOMEM; memset( p_dec->p_sys, 0, sizeof( decoder_sys_t ) ); /* Misc init */ packetizer_Init( &p_sys->packetizer, p_mp2v_startcode, sizeof(p_mp2v_startcode), NULL, 0, 4, PacketizeReset, PacketizeParse, PacketizeValidate, p_dec ); p_sys->p_seq = NULL; p_sys->p_ext = NULL; p_sys->p_frame = NULL; p_sys->pp_last = &p_sys->p_frame; p_sys->b_frame_slice = false; p_sys->i_dts = p_sys->i_pts = VLC_TS_INVALID; p_sys->i_frame_rate = 1; p_sys->i_frame_rate_base = 1; p_sys->b_seq_progressive = true; p_sys->b_low_delay = true; p_sys->i_seq_old = 0; p_sys->i_temporal_ref = 0; p_sys->i_picture_type = 0; p_sys->i_picture_structure = 0x03; /* frame */ p_sys->i_top_field_first = 0; p_sys->i_repeat_first_field = 0; p_sys->i_progressive_frame = 0; p_sys->b_inited = 0; p_sys->i_interpolated_dts = VLC_TS_INVALID; p_sys->i_last_ref_pts = VLC_TS_INVALID; p_sys->b_second_field = 0; p_sys->b_discontinuity = false; p_sys->b_sync_on_intra_frame = var_CreateGetBool( p_dec, "packetizer-mpegvideo-sync-iframe" ); if( p_sys->b_sync_on_intra_frame ) msg_Dbg( p_dec, "syncing on intra frame now" ); p_sys->b_cc_reset = false; p_sys->i_cc_pts = 0; p_sys->i_cc_dts = 0; p_sys->i_cc_flags = 0; cc_Init( &p_sys->cc ); return VLC_SUCCESS; }
/***************************************************************************** * CreateFilter: allocates RSS video filter *****************************************************************************/ static int CreateFilter( vlc_object_t *p_this ) { filter_t *p_filter = (filter_t *)p_this; filter_sys_t *p_sys; char *psz_urls; int i_ttl; /* Allocate structure */ p_sys = p_filter->p_sys = (filter_sys_t *)malloc( sizeof( filter_sys_t ) ); // sunqueen modify if( p_sys == NULL ) return VLC_ENOMEM; config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options, p_filter->p_cfg ); /* Get the urls to parse: must be non empty */ psz_urls = var_CreateGetNonEmptyString( p_filter, CFG_PREFIX "urls" ); if( !psz_urls ) { msg_Err( p_filter, "The list of urls must not be empty" ); free( p_sys ); return VLC_EGENERIC; } /* Fill the p_sys structure with the configuration */ p_sys->i_title = var_CreateGetInteger( p_filter, CFG_PREFIX "title" ); p_sys->i_cur_feed = 0; p_sys->i_cur_item = p_sys->i_title == scroll_title ? -1 : 0; p_sys->i_cur_char = 0; p_sys->i_feeds = 0; p_sys->p_feeds = NULL; p_sys->i_speed = var_CreateGetInteger( p_filter, CFG_PREFIX "speed" ); p_sys->i_length = var_CreateGetInteger( p_filter, CFG_PREFIX "length" ); p_sys->b_images = var_CreateGetBool( p_filter, CFG_PREFIX "images" ); i_ttl = __MAX( 0, var_CreateGetInteger( p_filter, CFG_PREFIX "ttl" ) ); p_sys->psz_marquee = (char *)malloc( p_sys->i_length + 1 ); // sunqueen modify if( p_sys->psz_marquee == NULL ) { free( psz_urls ); free( p_sys ); return VLC_ENOMEM; } p_sys->psz_marquee[p_sys->i_length] = '\0'; p_sys->p_style = text_style_New(); if( p_sys->p_style == NULL ) goto error; p_sys->i_xoff = var_CreateGetInteger( p_filter, CFG_PREFIX "x" ); p_sys->i_yoff = var_CreateGetInteger( p_filter, CFG_PREFIX "y" ); p_sys->i_pos = var_CreateGetInteger( p_filter, CFG_PREFIX "position" ); p_sys->p_style->i_font_alpha = 255 - var_CreateGetInteger( p_filter, CFG_PREFIX "opacity" ); p_sys->p_style->i_font_color = var_CreateGetInteger( p_filter, CFG_PREFIX "color" ); p_sys->p_style->i_font_size = var_CreateGetInteger( p_filter, CFG_PREFIX "size" ); if( p_sys->b_images && p_sys->p_style->i_font_size == -1 ) { msg_Warn( p_filter, "rss-size wasn't specified. Feed images will thus be displayed without being resized" ); } /* Parse the urls */ if( ParseUrls( p_filter, psz_urls ) ) goto error; /* Misc init */ vlc_mutex_init( &p_sys->lock ); p_filter->pf_sub_source = Filter; p_sys->last_date = (mtime_t)0; p_sys->b_fetched = false; /* Create and arm the timer */ if( vlc_timer_create( &p_sys->timer, Fetch, p_filter ) ) { vlc_mutex_destroy( &p_sys->lock ); goto error; } vlc_timer_schedule( p_sys->timer, false, 1, (mtime_t)(i_ttl)*1000000 ); free( psz_urls ); return VLC_SUCCESS; error: if( p_sys->p_style ) text_style_Delete( p_sys->p_style ); free( p_sys->psz_marquee ); free( psz_urls ); free( p_sys ); return VLC_ENOMEM; }
/***************************************************************************** * Open: open the rtmp connection *****************************************************************************/ 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, *p; int length_path, length_media_name; int i; if( !( p_sys = calloc ( 1, sizeof( sout_access_out_sys_t ) ) ) ) return VLC_ENOMEM; p_access->p_sys = p_sys; p_sys->p_thread = vlc_object_create( p_access, sizeof( rtmp_control_thread_t ) ); if( !p_sys->p_thread ) { free( p_sys ); return VLC_ENOMEM; } vlc_object_attach( p_sys->p_thread, p_access ); /* Parse URI - remove spaces */ p = psz = strdup( p_access->psz_path ); while( ( p = strchr( p, ' ' ) ) != NULL ) *p = '+'; vlc_UrlParse( &p_sys->p_thread->url, psz, 0 ); free( psz ); if( p_sys->p_thread->url.psz_host == NULL || *p_sys->p_thread->url.psz_host == '\0' ) { msg_Warn( p_access, "invalid host" ); goto error; } if( p_sys->p_thread->url.i_port <= 0 ) p_sys->p_thread->url.i_port = 1935; if ( p_sys->p_thread->url.psz_path == NULL ) { msg_Warn( p_access, "invalid path" ); goto error; } length_path = strlen( p_sys->p_thread->url.psz_path ); char* psz_tmp = strrchr( p_sys->p_thread->url.psz_path, '/' ); if( !psz_tmp ) goto error; length_media_name = strlen( psz_tmp ) - 1; p_sys->p_thread->psz_application = strndup( p_sys->p_thread->url.psz_path + 1, length_path - length_media_name - 2 ); p_sys->p_thread->psz_media = strdup( p_sys->p_thread->url.psz_path + ( length_path - length_media_name ) ); msg_Dbg( p_access, "rtmp: host='%s' port=%d path='%s'", p_sys->p_thread->url.psz_host, p_sys->p_thread->url.i_port, p_sys->p_thread->url.psz_path ); if( p_sys->p_thread->url.psz_username && *p_sys->p_thread->url.psz_username ) { msg_Dbg( p_access, " user='******'", p_sys->p_thread->url.psz_username ); } /* Initialize thread variables */ p_sys->p_thread->b_error= 0; p_sys->p_thread->p_fifo_input = block_FifoNew(); p_sys->p_thread->p_empty_blocks = block_FifoNew(); p_sys->p_thread->has_audio = 0; p_sys->p_thread->has_video = 0; p_sys->p_thread->metadata_received = 0; p_sys->p_thread->first_media_packet = 1; p_sys->p_thread->flv_tag_previous_tag_size = 0x00000000; /* FLV_TAG_FIRST_PREVIOUS_TAG_SIZE */ p_sys->p_thread->flv_body = rtmp_body_new( -1 ); p_sys->p_thread->flv_length_body = 0; p_sys->p_thread->chunk_size_recv = 128; /* RTMP_DEFAULT_CHUNK_SIZE */ p_sys->p_thread->chunk_size_send = 128; /* RTMP_DEFAULT_CHUNK_SIZE */ for(i = 0; i < 64; i++) { memset( &p_sys->p_thread->rtmp_headers_recv[i], 0, sizeof( rtmp_packet_t ) ); p_sys->p_thread->rtmp_headers_send[i].length_header = -1; p_sys->p_thread->rtmp_headers_send[i].stream_index = -1; p_sys->p_thread->rtmp_headers_send[i].timestamp = -1; p_sys->p_thread->rtmp_headers_send[i].timestamp_relative = -1; p_sys->p_thread->rtmp_headers_send[i].length_encoded = -1; p_sys->p_thread->rtmp_headers_send[i].length_body = -1; p_sys->p_thread->rtmp_headers_send[i].content_type = -1; p_sys->p_thread->rtmp_headers_send[i].src_dst = -1; p_sys->p_thread->rtmp_headers_send[i].body = NULL; } vlc_cond_init( &p_sys->p_thread->wait ); vlc_mutex_init( &p_sys->p_thread->lock ); p_sys->p_thread->result_connect = 1; /* p_sys->p_thread->result_publish = only used on access */ p_sys->p_thread->result_play = 1; p_sys->p_thread->result_stop = 0; p_sys->p_thread->fd = -1; /* Open connection */ if( var_CreateGetBool( p_access, "rtmp-connect" ) > 0 ) { #if 0 p_sys->p_thread->fd = net_ConnectTCP( p_access, p_sys->p_thread->url.psz_host, p_sys->p_thread->url.i_port ); #endif msg_Err( p_access, "to be implemented" ); goto error2; } else { int *p_fd_listen; p_sys->active = 0; p_fd_listen = net_ListenTCP( p_access, p_sys->p_thread->url.psz_host, p_sys->p_thread->url.i_port ); if( p_fd_listen == NULL ) { msg_Warn( p_access, "cannot listen to %s port %i", p_sys->p_thread->url.psz_host, p_sys->p_thread->url.i_port ); goto error2; } do p_sys->p_thread->fd = net_Accept( p_access, p_fd_listen ); while( p_sys->p_thread->fd == -1 ); net_ListenClose( p_fd_listen ); if( rtmp_handshake_passive( p_this, p_sys->p_thread->fd ) < 0 ) { msg_Err( p_access, "handshake passive failed"); goto error2; } } if( vlc_clone( &p_sys->p_thread->thread, ThreadControl, p_sys->p_thread, VLC_THREAD_PRIORITY_INPUT ) ) { msg_Err( p_access, "cannot spawn rtmp control thread" ); goto error2; } if( !p_sys->active ) { if( rtmp_connect_passive( p_sys->p_thread ) < 0 ) { msg_Err( p_access, "connect passive failed"); vlc_cancel( p_sys->p_thread->thread ); vlc_join( p_sys->p_thread->thread, NULL ); goto error2; } } p_access->pf_write = Write; p_access->pf_seek = Seek; return VLC_SUCCESS; error2: vlc_cond_destroy( &p_sys->p_thread->wait ); vlc_mutex_destroy( &p_sys->p_thread->lock ); free( p_sys->p_thread->psz_application ); free( p_sys->p_thread->psz_media ); if( p_sys->p_thread->fd != -1 ) net_Close( p_sys->p_thread->fd ); error: vlc_UrlClean( &p_sys->p_thread->url ); vlc_object_release( p_sys->p_thread ); free( p_sys ); return VLC_EGENERIC; }
static int EqzInit( filter_t *p_filter, int i_rate ) { filter_sys_t *p_sys = p_filter->p_sys; eqz_config_t cfg; int i, ch; vlc_value_t val1, val2, val3; vlc_object_t *p_aout = p_filter->p_parent; int i_ret = VLC_ENOMEM; bool b_vlcFreqs = var_InheritBool( p_aout, "equalizer-vlcfreqs" ); EqzCoeffs( i_rate, 1.0f, b_vlcFreqs, &cfg ); /* Create the static filter config */ p_sys->i_band = cfg.i_band; p_sys->f_alpha = malloc( p_sys->i_band * sizeof(float) ); p_sys->f_beta = malloc( p_sys->i_band * sizeof(float) ); p_sys->f_gamma = malloc( p_sys->i_band * sizeof(float) ); if( !p_sys->f_alpha || !p_sys->f_beta || !p_sys->f_gamma ) goto error; for( i = 0; i < p_sys->i_band; i++ ) { p_sys->f_alpha[i] = cfg.band[i].f_alpha; p_sys->f_beta[i] = cfg.band[i].f_beta; p_sys->f_gamma[i] = cfg.band[i].f_gamma; } /* Filter dyn config */ p_sys->b_2eqz = false; p_sys->f_gamp = 1.0f; p_sys->f_amp = malloc( p_sys->i_band * sizeof(float) ); if( !p_sys->f_amp ) goto error; for( i = 0; i < p_sys->i_band; i++ ) { p_sys->f_amp[i] = 0.0f; } /* Filter state */ for( ch = 0; ch < 32; ch++ ) { p_sys->x[ch][0] = p_sys->x[ch][1] = p_sys->x2[ch][0] = p_sys->x2[ch][1] = 0.0f; for( i = 0; i < p_sys->i_band; i++ ) { p_sys->y[ch][i][0] = p_sys->y[ch][i][1] = p_sys->y2[ch][i][0] = p_sys->y2[ch][i][1] = 0.0f; } } p_sys->psz_newbands = NULL; var_Create( p_aout, "equalizer-bands", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); var_Create( p_aout, "equalizer-preset", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); p_sys->b_2eqz = var_CreateGetBool( p_aout, "equalizer-2pass" ); var_Create( p_aout, "equalizer-preamp", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT ); /* Get initial values */ var_Get( p_aout, "equalizer-preset", &val1 ); var_Get( p_aout, "equalizer-bands", &val2 ); var_Get( p_aout, "equalizer-preamp", &val3 ); p_sys->b_first = true; PresetCallback( VLC_OBJECT( p_aout ), NULL, val1, val1, p_sys ); BandsCallback( VLC_OBJECT( p_aout ), NULL, val2, val2, p_sys ); PreampCallback( VLC_OBJECT( p_aout ), NULL, val3, val3, p_sys ); p_sys->b_first = false; free( val1.psz_string ); /* Exit if we have no preset and no bands value */ if (p_sys->psz_newbands == NULL && (!val2.psz_string || !*val2.psz_string)) { msg_Err(p_filter, "No preset selected"); free( val2.psz_string ); free( p_sys->f_amp ); i_ret = VLC_EGENERIC; goto error; } /* Register preset bands (for intf) if : */ /* We have no bands info --> the preset info must be given to the intf */ /* or The bands info matches the preset */ if( ( p_sys->psz_newbands && *(val2.psz_string) && strstr( p_sys->psz_newbands, val2.psz_string ) ) || !*val2.psz_string ) { var_SetString( p_aout, "equalizer-bands", p_sys->psz_newbands ); if( p_sys->f_newpreamp == p_sys->f_gamp ) var_SetFloat( p_aout, "equalizer-preamp", p_sys->f_newpreamp ); } free( val2.psz_string ); /* Add our own callbacks */ var_AddCallback( p_aout, "equalizer-preset", PresetCallback, p_sys ); var_AddCallback( p_aout, "equalizer-bands", BandsCallback, p_sys ); var_AddCallback( p_aout, "equalizer-preamp", PreampCallback, p_sys ); var_AddCallback( p_aout, "equalizer-2pass", TwoPassCallback, p_sys ); msg_Dbg( p_filter, "equalizer loaded for %d Hz with %d bands %d pass", i_rate, p_sys->i_band, p_sys->b_2eqz ? 2 : 1 ); for( i = 0; i < p_sys->i_band; i++ ) { msg_Dbg( p_filter, " %.2f Hz -> factor:%f alpha:%f beta:%f gamma:%f", cfg.band[i].f_frequency, p_sys->f_amp[i], p_sys->f_alpha[i], p_sys->f_beta[i], p_sys->f_gamma[i]); } return VLC_SUCCESS; error: free( p_sys->f_alpha ); free( p_sys->f_beta ); free( p_sys->f_gamma ); return i_ret; }
/** * It creates a Direct3D vout display. */ static int Open(vlc_object_t *object) { vout_display_t *vd = (vout_display_t *)object; vout_display_sys_t *sys; /* Allocate structure */ vd->sys = sys = calloc(1, sizeof(vout_display_sys_t)); if (!sys) return VLC_ENOMEM; if (Direct3DCreate(vd)) { msg_Err(vd, "Direct3D could not be initialized"); Direct3DDestroy(vd); free(sys); return VLC_EGENERIC; } sys->use_desktop = var_CreateGetBool(vd, "direct3d-desktop"); sys->reset_device = false; sys->reset_device = false; sys->allow_hw_yuv = var_CreateGetBool(vd, "directx-hw-yuv"); sys->desktop_save.is_fullscreen = vd->cfg->is_fullscreen; sys->desktop_save.is_on_top = false; sys->desktop_save.win.left = var_InheritInteger(vd, "video-x"); sys->desktop_save.win.right = vd->cfg->display.width; sys->desktop_save.win.top = var_InheritInteger(vd, "video-y"); sys->desktop_save.win.bottom = vd->cfg->display.height; if (CommonInit(vd)) goto error; /* */ video_format_t fmt; if (Direct3DOpen(vd, &fmt)) { msg_Err(vd, "Direct3D could not be opened"); goto error; } /* */ vout_display_info_t info = vd->info; info.is_slow = true; info.has_double_click = true; info.has_hide_mouse = false; info.has_pictures_invalid = true; info.has_event_thread = true; /* Interaction */ vlc_mutex_init(&sys->lock); sys->ch_desktop = false; sys->desktop_requested = sys->use_desktop; vlc_value_t val; val.psz_string = _("Desktop"); var_Change(vd, "direct3d-desktop", VLC_VAR_SETTEXT, &val, NULL); var_AddCallback(vd, "direct3d-desktop", DesktopCallback, NULL); /* Setup vout_display now that everything is fine */ vd->fmt = fmt; vd->info = info; vd->pool = Pool; vd->prepare = Prepare; vd->display = Display; vd->control = Control; vd->manage = Manage; /* Fix state in case of desktop mode */ if (sys->use_desktop && vd->cfg->is_fullscreen) vout_display_SendEventFullscreen(vd, false); return VLC_SUCCESS; error: Direct3DClose(vd); CommonClean(vd); Direct3DDestroy(vd); free(vd->sys); return VLC_EGENERIC; }
/***************************************************************************** * Open: probe the decoder and return score ***************************************************************************** * Tries to launch a decoder and return score so that the interface is able * to chose. *****************************************************************************/ static int Open( vlc_object_t *p_this ) { decoder_t *p_dec = (decoder_t *) p_this; decoder_sys_t *p_sys = NULL; if( p_dec->fmt_in.i_codec != VLC_CODEC_TELETEXT ) return VLC_EGENERIC; p_dec->pf_decode_sub = Decode; p_sys = p_dec->p_sys = calloc( 1, sizeof(decoder_sys_t) ); if( p_sys == NULL ) return VLC_ENOMEM; p_sys->i_key[0] = p_sys->i_key[1] = p_sys->i_key[2] = '*' - '0'; p_sys->b_update = false; p_sys->p_vbi_dec = vbi_decoder_new(); p_sys->p_dvb_demux = vbi_dvb_pes_demux_new( NULL, NULL ); vlc_mutex_init( &p_sys->lock ); if( (p_sys->p_vbi_dec == NULL) || (p_sys->p_dvb_demux == NULL) ) { msg_Err( p_dec, "VBI decoder/demux could not be created." ); Close( p_this ); return VLC_ENOMEM; } /* Some broadcasters in countries with level 1 and level 1.5 still not send a G0 to do * matches against table 32 of ETSI 300 706. We try to do some best effort guessing * This is not perfect, but might handle some cases where we know the vbi language * is known. It would be better if people started sending G0 */ for( int i = 0; ppsz_default_triplet[i] != NULL; i++ ) { if( p_dec->fmt_in.psz_language && !strcasecmp( p_dec->fmt_in.psz_language, ppsz_default_triplet[i] ) ) { vbi_teletext_set_default_region( p_sys->p_vbi_dec, pi_default_triplet[i]); msg_Dbg( p_dec, "overwriting default zvbi region: %d", pi_default_triplet[i] ); } } vbi_event_handler_register( p_sys->p_vbi_dec, VBI_EVENT_TTX_PAGE | VBI_EVENT_NETWORK | #ifdef ZVBI_DEBUG VBI_EVENT_CAPTION | VBI_EVENT_TRIGGER | VBI_EVENT_ASPECT | VBI_EVENT_PROG_INFO | VBI_EVENT_NETWORK_ID | #endif 0 , EventHandler, p_dec ); /* Create the var on vlc_global. */ p_sys->i_wanted_page = var_CreateGetInteger( p_dec, "vbi-page" ); var_AddCallback( p_dec, "vbi-page", RequestPage, p_sys ); /* Check if the Teletext track has a known "initial page". */ if( p_sys->i_wanted_page == 100 && p_dec->fmt_in.subs.teletext.i_magazine != -1 ) { p_sys->i_wanted_page = 100 * p_dec->fmt_in.subs.teletext.i_magazine + vbi_bcd2dec( p_dec->fmt_in.subs.teletext.i_page ); var_SetInteger( p_dec, "vbi-page", p_sys->i_wanted_page ); } p_sys->i_wanted_subpage = VBI_ANY_SUBNO; p_sys->b_opaque = var_CreateGetBool( p_dec, "vbi-opaque" ); var_AddCallback( p_dec, "vbi-opaque", Opaque, p_sys ); p_sys->i_align = var_CreateGetInteger( p_dec, "vbi-position" ); var_AddCallback( p_dec, "vbi-position", Position, p_sys ); p_sys->b_text = var_CreateGetBool( p_dec, "vbi-text" ); // var_AddCallback( p_dec, "vbi-text", Text, p_sys ); /* Listen for keys */ var_AddCallback( p_dec->p_libvlc, "key-pressed", EventKey, p_dec ); es_format_Init( &p_dec->fmt_out, SPU_ES, VLC_CODEC_SPU ); if( p_sys->b_text ) p_dec->fmt_out.video.i_chroma = VLC_CODEC_TEXT; else p_dec->fmt_out.video.i_chroma = VLC_CODEC_RGBA; return VLC_SUCCESS; }
/** * This function initializes SDL vout method. */ static int Open(vlc_object_t *object) { vout_display_t *vd = (vout_display_t *)object; vout_display_sys_t *sys; /* XXX: check for conflicts with the SDL audio output */ vlc_mutex_lock(&sdl_lock); /* Check if SDL video module has been initialized */ if (SDL_WasInit(SDL_INIT_VIDEO) != 0) { vlc_mutex_unlock(&sdl_lock); return VLC_EGENERIC; } vd->sys = sys = calloc(1, sizeof(*sys)); if (!sys) { vlc_mutex_unlock(&sdl_lock); return VLC_ENOMEM; } #ifdef HAVE_SETENV char *psz_driver = var_CreateGetNonEmptyString(vd, "sdl-video-driver"); if (psz_driver) { setenv("SDL_VIDEODRIVER", psz_driver, 1); free(psz_driver); } #endif /* */ int sdl_flags = SDL_INIT_VIDEO; #ifndef WIN32 /* Win32 SDL implementation doesn't support SDL_INIT_EVENTTHREAD yet*/ sdl_flags |= SDL_INIT_EVENTTHREAD; #endif #ifndef NDEBUG /* In debug mode you may want vlc to dump a core instead of staying stuck */ sdl_flags |= SDL_INIT_NOPARACHUTE; #endif /* Initialize library */ if (SDL_Init(sdl_flags) < 0) { vlc_mutex_unlock(&sdl_lock); msg_Err(vd, "cannot initialize SDL (%s)", SDL_GetError()); free(sys); return VLC_EGENERIC; } vlc_mutex_unlock(&sdl_lock); /* Translate keys into unicode */ SDL_EnableUNICODE(1); /* Get the desktop resolution */ /* FIXME: SDL has a problem with virtual desktop */ sys->desktop_width = SDL_GetVideoInfo()->current_w; sys->desktop_height = SDL_GetVideoInfo()->current_h; /* */ video_format_t fmt = vd->fmt; /* */ vout_display_info_t info = vd->info; /* Set main window's size */ int display_width; int display_height; if (vd->cfg->is_fullscreen) { display_width = sys->desktop_width; display_height = sys->desktop_height; } else { display_width = vd->cfg->display.width; display_height = vd->cfg->display.height; } /* Initialize flags and cursor */ sys->display_flags = SDL_ANYFORMAT | SDL_HWPALETTE | SDL_HWSURFACE | SDL_DOUBLEBUF; sys->display_flags |= vd->cfg->is_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE; sys->display_bpp = SDL_VideoModeOK(display_width, display_height, 16, sys->display_flags); if (sys->display_bpp == 0) { msg_Err(vd, "no video mode available"); goto error; } sys->display = SDL_SetVideoMode(display_width, display_height, sys->display_bpp, sys->display_flags); if (!sys->display) { msg_Err(vd, "cannot set video mode"); goto error; } /* We keep the surface locked forever */ SDL_LockSurface(sys->display); /* */ vlc_fourcc_t forced_chroma = 0; char *psz_chroma = var_CreateGetNonEmptyString(vd, "sdl-chroma"); if (psz_chroma) { forced_chroma = vlc_fourcc_GetCodecFromString(VIDEO_ES, psz_chroma); if (forced_chroma) msg_Dbg(vd, "Forcing chroma to 0x%.8x (%4.4s)", forced_chroma, (const char*)&forced_chroma); free(psz_chroma); } /* Try to open an overlay if requested */ sys->overlay = NULL; const bool is_overlay = var_CreateGetBool(vd, "overlay"); if (is_overlay) { static const struct { vlc_fourcc_t vlc; uint32_t sdl; } vlc_to_sdl[] = { { VLC_CODEC_YV12, SDL_YV12_OVERLAY }, { VLC_CODEC_I420, SDL_IYUV_OVERLAY }, { VLC_CODEC_YUYV, SDL_YUY2_OVERLAY }, { VLC_CODEC_UYVY, SDL_UYVY_OVERLAY }, { VLC_CODEC_YVYU, SDL_YVYU_OVERLAY }, { 0, 0 } }; const vlc_fourcc_t forced_chromas[] = { forced_chroma, 0 }; const vlc_fourcc_t *fallback_chromas = vlc_fourcc_GetYUVFallback(fmt.i_chroma); const vlc_fourcc_t *chromas = forced_chroma ? forced_chromas : fallback_chromas; for (int pass = forced_chroma ? 1 : 0; pass < 2 && !sys->overlay; pass++) { for (int i = 0; chromas[i] != 0; i++) { const vlc_fourcc_t vlc = chromas[i]; uint32_t sdl = 0; for (int j = 0; vlc_to_sdl[j].vlc != 0 && !sdl; j++) { if (vlc_to_sdl[j].vlc == vlc) sdl = vlc_to_sdl[j].sdl; } if (!sdl) continue; sys->overlay = SDL_CreateYUVOverlay(fmt.i_width, fmt.i_height, sdl, sys->display); if (sys->overlay && !sys->overlay->hw_overlay && pass == 0) { /* Ignore non hardware overlay surface in first pass */ SDL_FreeYUVOverlay(sys->overlay); sys->overlay = NULL; } if (sys->overlay) { /* We keep the surface locked forever */ SDL_LockYUVOverlay(sys->overlay); fmt.i_chroma = vlc; sys->is_uv_swapped = vlc_fourcc_AreUVPlanesSwapped(fmt.i_chroma, vd->fmt.i_chroma); if (sys->is_uv_swapped) fmt.i_chroma = vd->fmt.i_chroma; break; } } } } else { msg_Warn(vd, "SDL overlay disabled by the user"); } /* */ vout_display_cfg_t place_cfg = *vd->cfg; place_cfg.display.width = display_width; place_cfg.display.height = display_height; vout_display_PlacePicture(&sys->place, &vd->source, &place_cfg, !sys->overlay); /* If no overlay, fallback to software output */ if (!sys->overlay) { /* */ switch (sys->display->format->BitsPerPixel) { case 8: fmt.i_chroma = VLC_CODEC_RGB8; break; case 15: fmt.i_chroma = VLC_CODEC_RGB15; break; case 16: fmt.i_chroma = VLC_CODEC_RGB16; break; case 24: fmt.i_chroma = VLC_CODEC_RGB24; break; case 32: fmt.i_chroma = VLC_CODEC_RGB32; break; default: msg_Err(vd, "unknown screen depth %i", sys->display->format->BitsPerPixel); goto error; } /* All we have is an RGB image with square pixels */ fmt.i_width = display_width; fmt.i_height = display_height; fmt.i_rmask = sys->display->format->Rmask; fmt.i_gmask = sys->display->format->Gmask; fmt.i_bmask = sys->display->format->Bmask; info.has_pictures_invalid = true; } if (vd->cfg->display.title) SDL_WM_SetCaption(vd->cfg->display.title, vd->cfg->display.title); else if (!sys->overlay) SDL_WM_SetCaption(VOUT_TITLE " (software RGB SDL output)", VOUT_TITLE " (software RGB SDL output)"); else if (sys->overlay->hw_overlay) SDL_WM_SetCaption(VOUT_TITLE " (hardware YUV SDL output)", VOUT_TITLE " (hardware YUV SDL output)"); else SDL_WM_SetCaption(VOUT_TITLE " (software YUV SDL output)", VOUT_TITLE " (software YUV SDL output)"); /* Setup events */ SDL_EventState(SDL_KEYUP, SDL_IGNORE); /* ignore keys up */ /* Setup vout_display now that everything is fine */ vd->fmt = fmt; vd->info = info; vd->get = Get; vd->prepare = NULL; vd->display = Display; vd->control = Control; vd->manage = Manage; /* */ vout_display_SendEventDisplaySize(vd, display_width, display_height, vd->cfg->is_fullscreen); return VLC_SUCCESS; error: msg_Err(vd, "cannot set up SDL (%s)", SDL_GetError()); if (sys->display) { SDL_UnlockSurface(sys->display); SDL_FreeSurface(sys->display); } vlc_mutex_lock(&sdl_lock); SDL_QuitSubSystem(SDL_INIT_VIDEO); vlc_mutex_unlock(&sdl_lock); free(sys); return VLC_EGENERIC; }
/***************************************************************************** * InitVideo: initialize the video decoder ***************************************************************************** * the ffmpeg codec will be opened, some memory allocated. The vout is not yet * opened (done after the first decoded frame). *****************************************************************************/ int InitVideoDec( decoder_t *p_dec, AVCodecContext *p_context, AVCodec *p_codec, int i_codec_id, const char *psz_namecodec ) { decoder_sys_t *p_sys; int i_val; /* Allocate the memory needed to store the decoder's structure */ if( ( p_dec->p_sys = p_sys = calloc( 1, sizeof(decoder_sys_t) ) ) == NULL ) return VLC_ENOMEM; p_codec->type = CODEC_TYPE_VIDEO; p_context->codec_type = CODEC_TYPE_VIDEO; p_context->codec_id = i_codec_id; p_sys->p_context = p_context; p_sys->p_codec = p_codec; p_sys->i_codec_id = i_codec_id; p_sys->psz_namecodec = psz_namecodec; p_sys->p_ff_pic = avcodec_alloc_frame(); p_sys->b_delayed_open = true; p_sys->p_va = NULL; vlc_sem_init( &p_sys->sem_mt, 0 ); /* ***** Fill p_context with init values ***** */ p_sys->p_context->codec_tag = ffmpeg_CodecTag( p_dec->fmt_in.i_original_fourcc ?: p_dec->fmt_in.i_codec ); /* ***** Get configuration of ffmpeg plugin ***** */ p_sys->p_context->workaround_bugs = var_InheritInteger( p_dec, "ffmpeg-workaround-bugs" ); p_sys->p_context->error_recognition = var_InheritInteger( p_dec, "ffmpeg-error-resilience" ); if( var_CreateGetBool( p_dec, "grayscale" ) ) p_sys->p_context->flags |= CODEC_FLAG_GRAY; i_val = var_CreateGetInteger( p_dec, "ffmpeg-vismv" ); if( i_val ) p_sys->p_context->debug_mv = i_val; i_val = var_CreateGetInteger( p_dec, "ffmpeg-lowres" ); if( i_val > 0 && i_val <= 2 ) p_sys->p_context->lowres = i_val; i_val = var_CreateGetInteger( p_dec, "ffmpeg-skiploopfilter" ); if( i_val >= 4 ) p_sys->p_context->skip_loop_filter = AVDISCARD_ALL; else if( i_val == 3 ) p_sys->p_context->skip_loop_filter = AVDISCARD_NONKEY; else if( i_val == 2 ) p_sys->p_context->skip_loop_filter = AVDISCARD_BIDIR; else if( i_val == 1 ) p_sys->p_context->skip_loop_filter = AVDISCARD_NONREF; if( var_CreateGetBool( p_dec, "ffmpeg-fast" ) ) p_sys->p_context->flags2 |= CODEC_FLAG2_FAST; /* ***** ffmpeg frame skipping ***** */ p_sys->b_hurry_up = var_CreateGetBool( p_dec, "ffmpeg-hurry-up" ); switch( var_CreateGetInteger( p_dec, "ffmpeg-skip-frame" ) ) { case -1: p_sys->p_context->skip_frame = AVDISCARD_NONE; break; case 0: p_sys->p_context->skip_frame = AVDISCARD_DEFAULT; break; case 1: p_sys->p_context->skip_frame = AVDISCARD_BIDIR; break; case 2: p_sys->p_context->skip_frame = AVDISCARD_NONKEY; break; case 3: p_sys->p_context->skip_frame = AVDISCARD_ALL; break; default: p_sys->p_context->skip_frame = AVDISCARD_NONE; break; } p_sys->i_skip_frame = p_sys->p_context->skip_frame; switch( var_CreateGetInteger( p_dec, "ffmpeg-skip-idct" ) ) { case -1: p_sys->p_context->skip_idct = AVDISCARD_NONE; break; case 0: p_sys->p_context->skip_idct = AVDISCARD_DEFAULT; break; case 1: p_sys->p_context->skip_idct = AVDISCARD_BIDIR; break; case 2: p_sys->p_context->skip_idct = AVDISCARD_NONKEY; break; case 3: p_sys->p_context->skip_idct = AVDISCARD_ALL; break; default: p_sys->p_context->skip_idct = AVDISCARD_NONE; break; } p_sys->i_skip_idct = p_sys->p_context->skip_idct; /* ***** ffmpeg direct rendering ***** */ p_sys->b_direct_rendering = false; p_sys->i_direct_rendering_used = -1; if( var_CreateGetBool( p_dec, "ffmpeg-dr" ) && (p_sys->p_codec->capabilities & CODEC_CAP_DR1) && /* No idea why ... but this fixes flickering on some TSCC streams */ p_sys->i_codec_id != CODEC_ID_TSCC && !p_sys->p_context->debug_mv ) { /* Some codecs set pix_fmt only after the 1st frame has been decoded, * so we need to do another check in ffmpeg_GetFrameBuf() */ p_sys->b_direct_rendering = true; } /* ffmpeg doesn't properly release old pictures when frames are skipped */ //if( p_sys->b_hurry_up ) p_sys->b_direct_rendering = false; if( p_sys->b_direct_rendering ) { msg_Dbg( p_dec, "trying to use direct rendering" ); p_sys->p_context->flags |= CODEC_FLAG_EMU_EDGE; } else { msg_Dbg( p_dec, "direct rendering is disabled" ); } /* Always use our get_buffer wrapper so we can calculate the * PTS correctly */ p_sys->p_context->get_buffer = ffmpeg_GetFrameBuf; p_sys->p_context->reget_buffer = ffmpeg_ReGetFrameBuf; p_sys->p_context->release_buffer = ffmpeg_ReleaseFrameBuf; p_sys->p_context->opaque = p_dec; #ifdef HAVE_AVCODEC_MT int i_thread_count = var_InheritInteger( p_dec, "ffmpeg-threads" ); if( i_thread_count <= 0 ) i_thread_count = vlc_GetCPUCount(); msg_Dbg( p_dec, "allowing %d thread(s) for decoding", i_thread_count ); p_sys->p_context->thread_count = i_thread_count; #endif #ifdef HAVE_AVCODEC_VA const bool b_use_hw = var_CreateGetBool( p_dec, "ffmpeg-hw" ); if( b_use_hw ) { #ifdef HAVE_AVCODEC_MT msg_Err( p_dec, "ffmpeg-hw is not compatible with ffmpeg-mt" ); #else p_sys->p_context->get_format = ffmpeg_GetFormat; #endif } #endif /* ***** misc init ***** */ p_sys->i_pts = VLC_TS_INVALID; p_sys->b_has_b_frames = false; p_sys->b_first_frame = true; p_sys->b_flush = false; p_sys->i_late_frames = 0; /* Set output properties */ p_dec->fmt_out.i_cat = VIDEO_ES; if( GetVlcChroma( &p_dec->fmt_out.video, p_context->pix_fmt ) != VLC_SUCCESS ) { /* we are doomed. but not really, because most codecs set their pix_fmt later on */ p_dec->fmt_out.i_codec = VLC_CODEC_I420; } p_dec->fmt_out.i_codec = p_dec->fmt_out.video.i_chroma; /* Setup palette */ memset( &p_sys->palette, 0, sizeof(p_sys->palette) ); if( p_dec->fmt_in.video.p_palette ) { p_sys->palette.palette_changed = 1; for( int i = 0; i < __MIN( AVPALETTE_COUNT, p_dec->fmt_in.video.p_palette->i_entries ); i++ ) { union { uint32_t u; uint8_t a[4]; } c; c.a[0] = p_dec->fmt_in.video.p_palette->palette[i][0]; c.a[1] = p_dec->fmt_in.video.p_palette->palette[i][1]; c.a[2] = p_dec->fmt_in.video.p_palette->palette[i][2]; c.a[3] = p_dec->fmt_in.video.p_palette->palette[i][3]; p_sys->palette.palette[i] = c.u; } p_sys->p_context->palctrl = &p_sys->palette; p_dec->fmt_out.video.p_palette = malloc( sizeof(video_palette_t) ); if( p_dec->fmt_out.video.p_palette ) *p_dec->fmt_out.video.p_palette = *p_dec->fmt_in.video.p_palette; } else if( p_sys->i_codec_id != CODEC_ID_MSVIDEO1 && p_sys->i_codec_id != CODEC_ID_CINEPAK ) { p_sys->p_context->palctrl = &p_sys->palette; } /* ***** init this codec with special data ***** */ ffmpeg_InitCodec( p_dec ); /* ***** Open the codec ***** */ if( ffmpeg_OpenCodec( p_dec ) < 0 ) { msg_Err( p_dec, "cannot open codec (%s)", p_sys->psz_namecodec ); av_free( p_sys->p_ff_pic ); vlc_sem_destroy( &p_sys->sem_mt ); free( p_sys ); return VLC_EGENERIC; } return VLC_SUCCESS; }
/***************************************************************************** * OpenFilter *****************************************************************************/ static int OpenFilter( vlc_object_t *p_this ) { filter_t * p_filter = (filter_t *)p_this; filter_sys_t *p_sys = NULL; if( aout_FormatNbChannels( &(p_filter->fmt_in.audio) ) == 1 ) { /*msg_Dbg( p_filter, "filter discarded (incompatible format)" );*/ return VLC_EGENERIC; } if( (p_filter->fmt_in.i_codec != VLC_CODEC_S16N) || (p_filter->fmt_out.i_codec != VLC_CODEC_S16N) ) { /*msg_Err( p_this, "filter discarded (invalid format)" );*/ return VLC_EGENERIC; } if( (p_filter->fmt_in.audio.i_format != p_filter->fmt_out.audio.i_format) || (p_filter->fmt_in.audio.i_rate != p_filter->fmt_out.audio.i_rate) || (p_filter->fmt_in.audio.i_format != VLC_CODEC_S16N) || (p_filter->fmt_out.audio.i_format != VLC_CODEC_S16N) || (p_filter->fmt_in.audio.i_bitspersample != p_filter->fmt_out.audio.i_bitspersample)) { /*msg_Err( p_this, "couldn't load mono filter" );*/ return VLC_EGENERIC; } /* Allocate the memory needed to store the module's structure */ p_sys = p_filter->p_sys = malloc( sizeof(filter_sys_t) ); if( p_sys == NULL ) return VLC_EGENERIC; p_sys->b_downmix = var_CreateGetBool( p_this, MONO_CFG "downmix" ); p_sys->i_channel_selected = (unsigned int) var_CreateGetInteger( p_this, MONO_CFG "channel" ); if( p_sys->b_downmix ) { msg_Dbg( p_this, "using stereo to mono downmix" ); p_filter->fmt_out.audio.i_physical_channels = AOUT_CHAN_CENTER; p_filter->fmt_out.audio.i_channels = 1; } else { msg_Dbg( p_this, "using pseudo mono" ); p_filter->fmt_out.audio.i_physical_channels = (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT); p_filter->fmt_out.audio.i_channels = 2; } p_filter->fmt_out.audio.i_rate = p_filter->fmt_in.audio.i_rate; p_filter->fmt_out.audio.i_format = p_filter->fmt_out.i_codec; p_sys->i_nb_channels = aout_FormatNbChannels( &(p_filter->fmt_in.audio) ); p_sys->i_bitspersample = p_filter->fmt_out.audio.i_bitspersample; p_sys->i_overflow_buffer_size = 0; p_sys->p_overflow_buffer = NULL; p_sys->i_nb_atomic_operations = 0; p_sys->p_atomic_operations = NULL; if( Init( VLC_OBJECT(p_filter), p_filter->p_sys, aout_FormatNbChannels( &p_filter->fmt_in.audio ), p_filter->fmt_in.audio.i_physical_channels, p_filter->fmt_in.audio.i_rate ) < 0 ) { var_Destroy( p_this, MONO_CFG "channel" ); var_Destroy( p_this, MONO_CFG "downmix" ); free( p_sys ); return VLC_EGENERIC; } p_filter->pf_audio_filter = Convert; msg_Dbg( p_this, "%4.4s->%4.4s, channels %d->%d, bits per sample: %i->%i", (char *)&p_filter->fmt_in.i_codec, (char *)&p_filter->fmt_out.i_codec, p_filter->fmt_in.audio.i_physical_channels, p_filter->fmt_out.audio.i_physical_channels, p_filter->fmt_in.audio.i_bitspersample, p_filter->fmt_out.audio.i_bitspersample ); return VLC_SUCCESS; }