void formatSnapshotItem( input_item_t *p_item ) { if( !p_item ) return; if( !p_item->p_meta ) p_item->p_meta = vlc_meta_New(); /* copy the snapshot mrl as a ArtURL */ if( p_item->p_meta ) { char* psz_uri = NULL; psz_uri = input_item_GetURI( p_item ); if( psz_uri ) input_item_SetArtURL( p_item, psz_uri ); free( psz_uri ); } /** * TODO: select the best mrl for displaying snapshots * - vlc://pause:10 => snapshot are displayed as Art * - file:///path/image.ext => snapshot are displayed as videos **/ input_item_SetURI( p_item, "vlc://pause:10" ); // input_item_AddOption( p_item, "fake-duration=10000", // VLC_INPUT_OPTION_TRUSTED ); }
/** * Adds a source. */ static int AddSource (services_discovery_t *sd, const pa_source_info *info) { services_discovery_sys_t *sys = sd->p_sys; msg_Dbg (sd, "adding %s (%s)", info->name, info->description); char *mrl; if (unlikely(asprintf (&mrl, "pulse://%s", info->name) == -1)) return -1; input_item_t *item = input_item_NewCard (mrl, info->description); free (mrl); if (unlikely(item == NULL)) return -1; struct device *d = malloc (sizeof (*d)); if (unlikely(d == NULL)) { input_item_Release (item); return -1; } d->index = info->index; d->item = item; struct device **dp = tsearch (d, &sys->root, cmpsrc); if (dp == NULL) /* Out-of-memory */ { free (d); input_item_Release (item); return -1; } if (*dp != d) /* Update existing source */ { free (d); d = *dp; input_item_SetURI (d->item, item->psz_uri); input_item_SetName (d->item, item->psz_name); input_item_Release (item); return 0; } const char *card = pa_proplist_gets(info->proplist, "device.product.name"); services_discovery_AddItemCat(sd, item, (card != NULL) ? card : N_("Generic")); d->sd = sd; return 0; }
input_item_t *input_item_NewWithType( vlc_object_t *p_obj, const char *psz_uri, const char *psz_name, int i_options, const char *const *ppsz_options, unsigned i_option_flags, mtime_t i_duration, int i_type ) { libvlc_priv_t *priv = libvlc_priv (p_obj->p_libvlc); static vlc_mutex_t input_id_lock = VLC_STATIC_MUTEX; input_item_t* p_input = malloc( sizeof(input_item_t ) ); if( !p_input ) return NULL; input_item_Init( p_obj, p_input ); vlc_gc_init( p_input, input_item_Destroy ); vlc_mutex_lock( &input_id_lock ); p_input->i_id = ++priv->i_last_input_id; vlc_mutex_unlock( &input_id_lock ); p_input->b_fixed_name = false; p_input->i_type = i_type; p_input->b_prefers_tree = false; if( psz_uri ) input_item_SetURI( p_input, psz_uri ); if( i_type != ITEM_TYPE_UNKNOWN ) p_input->i_type = i_type; if( psz_name ) input_item_SetName( p_input, psz_name ); p_input->i_duration = i_duration; for( int i = 0; i < i_options; i++ ) input_item_AddOption( p_input, ppsz_options[i], i_option_flags ); return p_input; }
static void DoFingerprint( fingerprinter_thread_t *p_fingerprinter, acoustid_fingerprint_t *fp, const char *psz_uri ) { input_item_t *p_item = input_item_New( NULL, NULL ); if ( unlikely(p_item == NULL) ) return; char *psz_sout_option; /* Note: need at -max- 2 channels, but we can't guess it before playing */ /* the stereo upmix could make the mono tracks fingerprint to differ :/ */ if ( asprintf( &psz_sout_option, "sout=#transcode{acodec=%s,channels=2}:chromaprint", ( VLC_CODEC_S16L == VLC_CODEC_S16N ) ? "s16l" : "s16b" ) == -1 ) { input_item_Release( p_item ); return; } input_item_AddOption( p_item, psz_sout_option, VLC_INPUT_OPTION_TRUSTED ); free( psz_sout_option ); input_item_AddOption( p_item, "vout=dummy", VLC_INPUT_OPTION_TRUSTED ); input_item_AddOption( p_item, "aout=dummy", VLC_INPUT_OPTION_TRUSTED ); if ( fp->i_duration ) { if ( asprintf( &psz_sout_option, "stop-time=%u", fp->i_duration ) == -1 ) { input_item_Release( p_item ); return; } input_item_AddOption( p_item, psz_sout_option, VLC_INPUT_OPTION_TRUSTED ); free( psz_sout_option ); } input_item_SetURI( p_item, psz_uri ) ; input_thread_t *p_input = input_Create( p_fingerprinter, p_item, "fingerprinter", NULL, NULL ); input_item_Release( p_item ); if( p_input == NULL ) return; chromaprint_fingerprint_t chroma_fingerprint; chroma_fingerprint.psz_fingerprint = NULL; chroma_fingerprint.i_duration = fp->i_duration; var_Create( p_input, "fingerprint-data", VLC_VAR_ADDRESS ); var_SetAddress( p_input, "fingerprint-data", &chroma_fingerprint ); var_AddCallback( p_input, "intf-event", InputEventHandler, p_fingerprinter->p_sys ); if( input_Start( p_input ) != VLC_SUCCESS ) { var_DelCallback( p_input, "intf-event", InputEventHandler, p_fingerprinter->p_sys ); input_Close( p_input ); } else { p_fingerprinter->p_sys->processing.b_working = true; while( p_fingerprinter->p_sys->processing.b_working ) { vlc_cond_wait( &p_fingerprinter->p_sys->processing.cond, &p_fingerprinter->p_sys->processing.lock ); } var_DelCallback( p_input, "intf-event", InputEventHandler, p_fingerprinter->p_sys ); input_Stop( p_input ); input_Close( p_input ); fp->psz_fingerprint = chroma_fingerprint.psz_fingerprint; if( !fp->i_duration ) /* had not given hint */ fp->i_duration = chroma_fingerprint.i_duration; } }
static void DoFingerprint( vlc_object_t *p_this, fingerprinter_sys_t *p_sys, acoustid_fingerprint_t *fp ) { p_sys->p_input = NULL; p_sys->p_item = NULL; p_sys->chroma_fingerprint.psz_fingerprint = NULL; vlc_cleanup_push( cancelDoFingerprint, p_sys ); p_sys->p_item = input_item_New( NULL, NULL ); if ( ! p_sys->p_item ) goto end; char *psz_sout_option; /* Note: need at -max- 2 channels, but we can't guess it before playing */ /* the stereo upmix could make the mono tracks fingerprint to differ :/ */ if ( asprintf( &psz_sout_option, "sout=#transcode{acodec=%s,channels=2}:chromaprint", ( VLC_CODEC_S16L == VLC_CODEC_S16N ) ? "s16l" : "s16b" ) == -1 ) goto end; input_item_AddOption( p_sys->p_item, psz_sout_option, VLC_INPUT_OPTION_TRUSTED ); free( psz_sout_option ); input_item_AddOption( p_sys->p_item, "vout=dummy", VLC_INPUT_OPTION_TRUSTED ); input_item_AddOption( p_sys->p_item, "aout=dummy", VLC_INPUT_OPTION_TRUSTED ); if ( fp->i_duration ) { if ( asprintf( &psz_sout_option, "stop-time=%u", fp->i_duration ) == -1 ) goto end; input_item_AddOption( p_sys->p_item, psz_sout_option, VLC_INPUT_OPTION_TRUSTED ); free( psz_sout_option ); } input_item_SetURI( p_sys->p_item, p_sys->psz_uri ) ; p_sys->p_input = input_Create( p_this, p_sys->p_item, "fingerprinter", NULL ); if ( p_sys->p_input ) { p_sys->chroma_fingerprint.i_duration = fp->i_duration; var_Create( p_sys->p_input, "fingerprint-data", VLC_VAR_ADDRESS ); var_SetAddress( p_sys->p_input, "fingerprint-data", & p_sys->chroma_fingerprint ); input_Start( p_sys->p_input ); /* Wait for input to start && end */ p_sys->condwait.i_input_state = var_GetInteger( p_sys->p_input, "state" ); if ( likely( var_AddCallback( p_sys->p_input, "intf-event", inputStateCallback, p_sys ) == VLC_SUCCESS ) ) { while( p_sys->condwait.i_input_state <= PAUSE_S ) { vlc_mutex_lock( &p_sys->condwait.lock ); mutex_cleanup_push( &p_sys->condwait.lock ); vlc_cond_wait( &p_sys->condwait.wait, &p_sys->condwait.lock ); vlc_cleanup_run(); } var_DelCallback( p_sys->p_input, "intf-event", inputStateCallback, p_sys ); } input_Stop( p_sys->p_input, true ); input_Close( p_sys->p_input ); p_sys->p_input = NULL; if ( p_sys->chroma_fingerprint.psz_fingerprint ) { fp->psz_fingerprint = strdup( p_sys->chroma_fingerprint.psz_fingerprint ); if ( ! fp->i_duration ) /* had not given hint */ fp->i_duration = p_sys->chroma_fingerprint.i_duration; } } end: vlc_cleanup_run( ); }