static void uninstall_md_listener( libvlc_media_list_view_t * p_mlv, libvlc_media_t * p_md) { libvlc_media_list_t * p_mlist; libvlc_exception_t ignored_exception; libvlc_exception_init( &ignored_exception ); libvlc_event_detach( p_md->p_event_manager, libvlc_MediaSubItemAdded, media_list_subitem_added, p_mlv, &ignored_exception ); if( libvlc_exception_raised( &ignored_exception ) ) libvlc_exception_clear( &ignored_exception ); /* We don't care if we encounter an exception */ if((p_mlist = libvlc_media_subitems( p_md ))) { libvlc_media_list_lock( p_mlist ); libvlc_event_detach( p_mlist->p_event_manager, libvlc_MediaListItemAdded, media_list_item_added, p_mlv, NULL ); libvlc_event_detach( p_mlist->p_event_manager, libvlc_MediaListItemDeleted, media_list_item_removed, p_mlv, NULL ); int i, count = libvlc_media_list_count( p_mlist, NULL ); for( i = 0; i < count; i++) { libvlc_media_t * p_submd; p_submd = libvlc_media_list_item_at_index( p_mlist,i, NULL ); uninstall_md_listener( p_mlv, p_submd ); libvlc_media_release( p_submd ); } libvlc_media_list_unlock( p_mlist ); libvlc_media_list_release( p_mlist ); } }
void Java_org_videolan_libvlc_MediaPlayer_nativeRelease(JNIEnv *env, jobject thiz) { vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz); if (!p_obj) return; /* TODO: REMOVE */ libvlc_event_manager_t *ev = libvlc_media_player_event_manager(p_obj->u.p_mp); static const libvlc_event_type_t mp_events[] = { libvlc_MediaPlayerPlaying, libvlc_MediaPlayerPaused, libvlc_MediaPlayerEndReached, libvlc_MediaPlayerStopped, libvlc_MediaPlayerVout, libvlc_MediaPlayerPositionChanged, libvlc_MediaPlayerTimeChanged, libvlc_MediaPlayerEncounteredError, libvlc_MediaPlayerESAdded, libvlc_MediaPlayerESDeleted, }; for(int i = 0; i < (sizeof(mp_events) / sizeof(*mp_events)); i++) libvlc_event_detach(ev, mp_events[i], vlc_event_callback, NULL); libvlc_media_player_release(p_obj->u.p_mp); VLCJniObject_release(env, thiz, p_obj); }
/************************************************************************** * uninstall_playlist_observer (private) **************************************************************************/ static void uninstall_playlist_observer(libvlc_media_list_player_t * p_mlp) { assert_locked(p_mlp); if (!p_mlp->p_mlist) return; libvlc_event_detach(mlist_em(p_mlp), libvlc_MediaListItemDeleted, mlist_item_deleted, p_mlp, NULL); }
static void media_list_subitem_added( const libvlc_event_t * p_event, void * p_user_data ) { libvlc_media_list_t * p_mlist; libvlc_event_t added_event; libvlc_media_list_view_t * p_mlv = p_user_data; libvlc_media_t * p_submd = p_event->u.media_subitem_added.new_child; libvlc_media_t * p_md = p_event->p_obj; if((p_mlist = libvlc_media_subitems( p_md ))) { /* We have a mlist to which we're going to listen to events * thus, no need to wait for SubItemAdded events */ libvlc_event_detach( p_md->p_event_manager, libvlc_MediaSubItemAdded, media_list_subitem_added, p_mlv, NULL ); libvlc_media_list_lock( p_mlist ); libvlc_event_attach( p_mlist->p_event_manager, libvlc_MediaListItemAdded, media_list_item_added, p_mlv, NULL ); libvlc_event_attach( p_mlist->p_event_manager, libvlc_MediaListItemDeleted, media_list_item_removed, p_mlv, NULL ); libvlc_media_list_unlock( p_mlist ); libvlc_media_list_release( p_mlist ); } install_md_listener( p_mlv, p_submd ); added_event.u.media_list_item_added.item = p_submd; added_event.u.media_list_item_added.index = 0; if( p_mlv->pf_ml_item_added ) p_mlv->pf_ml_item_added( &added_event, p_mlv ); }
void Java_org_videolan_libvlc_MediaPlayer_stop(JNIEnv *env, jobject thiz) { vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz); if (!p_obj) return; /* TODO: REMOVE */ libvlc_media_t* p_md = libvlc_media_player_get_media(p_obj->u.p_mp); if (p_md) { libvlc_event_manager_t *ev_media = libvlc_media_event_manager(p_md); static const libvlc_event_type_t mp_media_events[] = { libvlc_MediaParsedChanged, libvlc_MediaMetaChanged, }; for(int i = 0; i < (sizeof(mp_media_events) / sizeof(*mp_media_events)); i++) libvlc_event_detach(ev_media, mp_media_events[i], vlc_event_callback, NULL); libvlc_media_release(p_md); libvlc_media_player_set_media(p_obj->u.p_mp, NULL); } libvlc_media_player_stop(p_obj->u.p_mp); }
static void xmr_player_dispose(GObject *object) { XmrPlayer *player = XMR_PLAYER(object); XmrPlayerPrivate *priv = player->priv; libvlc_event_manager_t *event_mgr; gint i; event_mgr = libvlc_media_player_event_manager(priv->player); for (i = 0; i < g_vlc_event_count; ++i) libvlc_event_detach(event_mgr, g_vlc_events[i], vlc_event_callback, player); if (priv->event_idle_id != 0) { g_source_remove (priv->event_idle_id); priv->event_idle_id = 0; } if (priv->event_queue) { g_async_queue_unref(priv->event_queue); priv->event_queue = NULL; } libvlc_media_player_release(priv->player); libvlc_release(priv->instance); G_OBJECT_CLASS(xmr_player_parent_class)->dispose(object); }
/************************************************************************** * flat_media_list_view_release (private) * (called by media_list_view_release) **************************************************************************/ static void hierarch_media_list_view_release( libvlc_media_list_view_t * p_mlv ) { libvlc_event_detach( p_mlv->p_mlist->p_event_manager, libvlc_MediaListItemAdded, media_list_item_added, p_mlv, NULL ); libvlc_event_detach( p_mlv->p_mlist->p_event_manager, libvlc_MediaListWillAddItem, media_list_will_add_item, p_mlv, NULL ); libvlc_event_detach( p_mlv->p_mlist->p_event_manager, libvlc_MediaListItemDeleted, media_list_item_deleted, p_mlv, NULL ); libvlc_event_detach( p_mlv->p_mlist->p_event_manager, libvlc_MediaListWillDeleteItem, media_list_will_delete_item, p_mlv, NULL ); }
JNIEXPORT void JNICALL NAME(nativeRelease)(JNIEnv *env, jobject thiz) { vlc_mutex_t *parse_lock = (vlc_mutex_t *) getIntValue(env, thiz, "mNativeMediaParseLock"); vlc_cond_t *parse_cond = (vlc_cond_t *) getIntValue(env, thiz, "mNativeMediaParseCond"); /* wake up threads that waiting on prepare */ vlc_mutex_lock(parse_lock); setIntValue(env, thiz, "mNativeMediaParsed", 4); vlc_cond_broadcast(parse_cond); vlc_mutex_unlock(parse_lock); jint mLibVlcMediaPlayer = getIntValue(env, thiz, "mLibVlcMediaPlayer"); if (mLibVlcMediaPlayer != 0) { libvlc_event_manager_t *em; libvlc_media_player_t *mp = (libvlc_media_player_t*) mLibVlcMediaPlayer; libvlc_media_t *md = libvlc_media_player_get_media(mp); if (md) { em = libvlc_media_event_manager(md); for (int i = 0; i < sizeof(md_listening) / sizeof(*md_listening); i++) { libvlc_event_detach(em, md_listening[i], vlc_event_callback, thiz); } } em = libvlc_media_player_event_manager(mp); for (int i = 0; i < sizeof(mp_listening) / sizeof(*mp_listening); i++) { libvlc_event_detach(em, mp_listening[i], vlc_event_callback, thiz); } libvlc_media_player_stop(mp); libvlc_media_player_release(mp); setIntValue(env, thiz, "mLibVlcMediaPlayer", 0); } jint mLibVlcInstance = getIntValue(env, thiz, "mLibVlcInstance"); if (mLibVlcInstance != 0) { libvlc_instance_t *instance = (libvlc_instance_t*) mLibVlcInstance; libvlc_release(instance); setIntValue(env, thiz, "mLibVlcInstance", 0); } setIntValue(env, thiz, "mNativeMediaBufferingCount", 0); vlc_mutex_destroy(parse_lock); free(parse_lock); setIntValue(env, thiz, "mNativeMediaParseLock", 0); vlc_cond_destroy(parse_cond); free(parse_cond); setIntValue(env, thiz, "mNativeMediaParseCond", 0); freeClasses(env, thiz); }
void VLCHolderWnd::DetachFromLibVlcEventSystem() { libvlc_event_manager_t* em = libvlc_media_player_event_manager(_p_md); if(_LibVlcESAttached && em){ libvlc_event_detach(em, libvlc_MediaPlayerPositionChanged, OnLibVlcEvent, this); _LibVlcESAttached=false; } }
/************************************************************************** * libvlc_media_list_view_release (Public) **************************************************************************/ void libvlc_media_list_view_release( libvlc_media_list_view_t * p_mlv ) { vlc_mutex_lock( &p_mlv->object_lock ); p_mlv->i_refcount--; if( p_mlv->i_refcount > 0 ) { vlc_mutex_unlock( &p_mlv->object_lock ); return; } vlc_mutex_unlock( &p_mlv->object_lock ); /* Refcount null, time to free */ libvlc_media_list_lock( p_mlv->p_mlist ); if( p_mlv->pf_ml_item_added ) { libvlc_event_detach( p_mlv->p_mlist->p_event_manager, libvlc_MediaListItemAdded, media_list_item_added, p_mlv, NULL ); } if( p_mlv->pf_ml_item_removed ) { libvlc_event_detach( p_mlv->p_mlist->p_event_manager, libvlc_MediaListItemDeleted, media_list_item_removed, p_mlv, NULL ); } int i, count = libvlc_media_list_count( p_mlv->p_mlist, NULL ); for( i = 0; i < count; i++) { libvlc_media_t * p_md; p_md = libvlc_media_list_item_at_index( p_mlv->p_mlist, i, NULL ); uninstall_md_listener( p_mlv, p_md ); libvlc_media_release( p_md ); } libvlc_media_list_unlock( p_mlv->p_mlist ); libvlc_event_manager_release( p_mlv->p_event_manager ); if( p_mlv->pf_release ) p_mlv->pf_release( p_mlv ); libvlc_media_list_release( p_mlv->p_mlist ); vlc_mutex_destroy( &p_mlv->object_lock ); }
static void snapshot(libvlc_media_player_t *mp, int width, char *out_with_ext) { libvlc_event_manager_t *em = libvlc_media_player_event_manager(mp); assert(em); libvlc_event_attach(em, libvlc_MediaPlayerSnapshotTaken, callback, NULL); done = false; libvlc_video_take_snapshot(mp, 0, out_with_ext, width, 0); event_wait("Snapshot has not been written"); libvlc_event_detach(em, libvlc_MediaPlayerSnapshotTaken, callback, NULL); }
static void set_position(libvlc_media_player_t *mp) { libvlc_event_manager_t *em = libvlc_media_player_event_manager(mp); assert(em); libvlc_event_attach(em, libvlc_MediaPlayerPositionChanged, callback, NULL); done = false; libvlc_media_player_set_position(mp, VLC_THUMBNAIL_POSITION); event_wait("Couldn't set position"); libvlc_event_detach(em, libvlc_MediaPlayerPositionChanged, callback, NULL); }
static void media_list_item_deleted( const libvlc_event_t * p_event, void * user_data ) { libvlc_media_t * p_md; libvlc_media_list_view_t * p_mlv = user_data; int index; p_md = p_event->u.media_list_item_deleted.item; index = index_of_item( p_mlv, p_md ); trace("%d\n", index); if( index >= 0) libvlc_media_list_view_item_deleted( p_mlv, p_md, index ); libvlc_event_detach( p_md->p_event_manager, libvlc_MediaSubItemAdded, items_subitems_added, p_mlv, NULL ); }
static void mediaplayer_play_sync(libvlc_media_player_t *p_mp) { vlc_sem_t sem; vlc_sem_init(&sem, 0); libvlc_event_manager_t *p_em = libvlc_media_player_event_manager(p_mp); libvlc_event_attach(p_em, libvlc_MediaPlayerPlaying, finished_event, &sem); libvlc_event_attach(p_em, libvlc_MediaPlayerEndReached, finished_event, &sem); libvlc_event_attach(p_em, libvlc_MediaPlayerEncounteredError, finished_event, &sem); int i_ret = libvlc_media_player_play(p_mp); assert(i_ret == 0); vlc_sem_wait (&sem); libvlc_event_detach(p_em, libvlc_MediaPlayerPlaying, finished_event, &sem); libvlc_event_detach(p_em, libvlc_MediaPlayerEndReached, finished_event, &sem); libvlc_event_detach(p_em, libvlc_MediaPlayerEncounteredError, finished_event, &sem); libvlc_media_player_stop(p_mp); vlc_sem_destroy (&sem); }
void MediaPlayer::finalize() { LDEBUG( "vlc", "Finalize" ); assert(_mp); { // Dettach to stop asyn events libvlc_event_manager_t *mgr=libvlc_media_player_event_manager( _mp ); libvlc_event_detach( mgr, libvlc_MediaPlayerEndReached, vlcCallback, this ); } // Release player libvlc_media_player_release( _mp ); _mp = NULL; MediaPlayerImpl::finalize(); }
/************************************************************************** * uninstall_media_player_observer (private) **************************************************************************/ static void uninstall_media_player_observer(libvlc_media_list_player_t * p_mlp) { assert_locked(p_mlp); // Allow callbacks to run, because detach() will wait until all callbacks are processed. // This is safe because only callbacks are allowed, and there execution will be cancelled. vlc_mutex_unlock(&p_mlp->mp_callback_lock); libvlc_event_detach(mplayer_em(p_mlp), libvlc_MediaPlayerEndReached, media_player_reached_end, p_mlp); // Now, lock back the callback lock. No more callback will be present from this point. vlc_mutex_lock(&p_mlp->mp_callback_lock); // What is here is safe, because we guarantee that we won't be able to anything concurrently, // - except (cancelled) callbacks - thanks to the object_lock. }
void Java_org_videolan_libvlc_VLCObject_nativeDetachEvents(JNIEnv *env, jobject thiz) { vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz); if (!p_obj || !p_obj->p_owner->p_event_manager || !p_obj->p_owner->p_events) return; for(int i = 0; p_obj->p_owner->p_events[i] != -1; ++i) libvlc_event_detach(p_obj->p_owner->p_event_manager, p_obj->p_owner->p_events[i], VLCJniObject_eventCallback, p_obj); p_obj->p_owner->p_event_manager = NULL; p_obj->p_owner->p_events = NULL; }
static void media_parse_sync(libvlc_media_t *p_m) { vlc_sem_t sem; vlc_sem_init(&sem, 0); libvlc_event_manager_t *p_em = libvlc_media_event_manager(p_m); libvlc_event_attach(p_em, libvlc_MediaParsedChanged, finished_event, &sem); int i_ret = libvlc_media_parse_with_options(p_m, libvlc_media_parse_local); assert(i_ret == 0); vlc_sem_wait (&sem); libvlc_event_detach(p_em, libvlc_MediaParsedChanged, finished_event, &sem); vlc_sem_destroy (&sem); }
VLC::~VLC() { if (_mediaPlayer) { libvlc_event_manager_t *eventManager = libvlc_media_player_event_manager(_mediaPlayer); libvlc_event_detach(eventManager, libvlc_MediaPlayerEndReached, VLC::handle_vlc_event, this); libvlc_media_player_stop(_mediaPlayer); libvlc_media_player_release(_mediaPlayer); _mediaPlayer = NULL; } if (_libvlc) { libvlc_release(_libvlc); _libvlc = NULL; } if (_curBuffer) { delete _curBuffer; } AC_DEBUG << "deleting VLC instance"; setTimeCode(as_string(0)); }
void VLCWindowsManager::VlcEvents( bool Attach ) { if( !VP() ) return; vlc_player& vp = *VP(); libvlc_event_manager_t* em = libvlc_media_player_event_manager( vp.get_mp() ); if( !em ) return; for( int e = libvlc_MediaPlayerMediaChanged; e <= libvlc_MediaPlayerVout; ++e ) { switch( e ) { //case libvlc_MediaPlayerMediaChanged: //case libvlc_MediaPlayerNothingSpecial: //case libvlc_MediaPlayerOpening: //case libvlc_MediaPlayerBuffering: case libvlc_MediaPlayerPlaying: //case libvlc_MediaPlayerPaused: //case libvlc_MediaPlayerStopped: //case libvlc_MediaPlayerForward: //case libvlc_MediaPlayerBackward: //case libvlc_MediaPlayerEndReached: //case libvlc_MediaPlayerEncounteredError: //case libvlc_MediaPlayerTimeChanged: case libvlc_MediaPlayerPositionChanged: //case libvlc_MediaPlayerSeekableChanged: //case libvlc_MediaPlayerPausableChanged: //case libvlc_MediaPlayerTitleChanged: //case libvlc_MediaPlayerSnapshotTaken: //case libvlc_MediaPlayerLengthChanged: //case libvlc_MediaPlayerVout: if( Attach ) libvlc_event_attach( em, e, OnLibVlcEvent_proxy, this ); else libvlc_event_detach( em, e, OnLibVlcEvent_proxy, this ); break; } } }
MediaListPlayer::~MediaListPlayer() { foreach (const libvlc_event_e & event, _events) { libvlc_event_detach(libvlc_media_list_player_event_manager(_mediaListPlayer),event,processEvent,this); }
jboolean Java_org_videolan_libvlc_LibVLC_hasVideoTrack(JNIEnv *env, jobject thiz, jlong i_instance, jstring fileLocation) { /* Create a new item and assign it to the media player. */ libvlc_media_t *p_m = new_media(i_instance, env, thiz, fileLocation, false, false); if (p_m == NULL) { LOGE("Could not create the media!"); return JNI_FALSE; } /* Get the tracks information of the media. */ libvlc_media_parse(p_m); libvlc_media_player_t* p_mp = libvlc_media_player_new_from_media(p_m); libvlc_media_player_set_video_title_display(p_mp, libvlc_position_disable, 0); struct length_change_monitor* monitor; monitor = malloc(sizeof(struct length_change_monitor)); if (!monitor) return 0; /* Initialize pthread variables. */ pthread_mutex_init(&monitor->doneMutex, NULL); pthread_cond_init(&monitor->doneCondVar, NULL); monitor->length_changed = false; libvlc_event_manager_t *ev = libvlc_media_player_event_manager(p_mp); libvlc_event_attach(ev, libvlc_MediaPlayerLengthChanged, length_changed_callback, monitor); libvlc_media_player_play( p_mp ); pthread_mutex_lock(&monitor->doneMutex); struct timespec deadline; clock_gettime(CLOCK_REALTIME, &deadline); deadline.tv_sec += 2; /* If "VLC can't open the file", return */ int mp_alive = 1; while( !monitor->length_changed && mp_alive ) { pthread_cond_timedwait(&monitor->doneCondVar, &monitor->doneMutex, &deadline); mp_alive = libvlc_media_player_will_play(p_mp); } pthread_mutex_unlock(&monitor->doneMutex); int i_nbTracks; if( mp_alive ) i_nbTracks = libvlc_video_get_track_count(p_mp); else i_nbTracks = -1; LOGI("Number of video tracks: %d",i_nbTracks); libvlc_event_detach(ev, libvlc_MediaPlayerLengthChanged, length_changed_callback, monitor); libvlc_media_player_stop(p_mp); libvlc_media_player_release(p_mp); libvlc_media_release(p_m); pthread_mutex_destroy(&monitor->doneMutex); pthread_cond_destroy(&monitor->doneCondVar); free(monitor); if(i_nbTracks > 0) return JNI_TRUE; else if(i_nbTracks < 0) (*env)->ThrowNew(env, (*env)->FindClass(env, "java/io/IOException"), "VLC can't open the file"); else return JNI_FALSE; }
void VLCEventBridge::detachEvent( libvlc_event_type_t event_type ) { libvlc_event_detach( _eventManager, event_type, onVLCEvent, _mediaPlayer ); }
void MediaPlayer::setMedia(QString file) { //qDebug() << "MediaPlayer::setMedia" << file; if (vlcMediaPlayer) { //libvlc_event_attach (libvlc_event_manager_t *p_event_manager, libvlc_event_type_t i_event_type, libvlc_callback_t f_callback, void *user_data) libvlc_event_manager_t *manager = libvlc_media_player_event_manager(vlcMediaPlayer); libvlc_event_manager_t *mediamanager = libvlc_media_event_manager(vlcMedia); //libvlc_event_detach(mediamanager,libvlc_MediaStateChanged,&callback,this); /* libvlc_MediaPlayerNothingSpecial libvlc_MediaPlayerOpening libvlc_MediaPlayerBuffering libvlc_MediaPlayerPlaying libvlc_MediaPlayerPaused libvlc_MediaPlayerStopped libvlc_MediaPlayerForward libvlc_MediaPlayerBackward libvlc_MediaPlayerEndReached libvlc_MediaPlayerEncounteredError libvlc_MediaPlayerTimeChanged libvlc_MediaPlayerPositionChanged libvlc_MediaPlayerSeekableChanged libvlc_MediaPlayerPausableChanged libvlc_MediaPlayerTitleChanged libvlc_MediaPlayerSnapshotTaken libvlc_MediaPlayerLengthChanged */ libvlc_event_detach(manager,libvlc_MediaPlayerOpening,&callback,this); libvlc_event_detach(manager,libvlc_MediaPlayerBuffering,&callback,this); libvlc_event_detach(manager,libvlc_MediaPlayerPlaying,&callback,this); libvlc_event_detach(manager,libvlc_MediaPlayerStopped,&callback,this); libvlc_event_detach(manager,libvlc_MediaPlayerPaused,&callback,this); libvlc_event_detach(manager,libvlc_MediaPlayerForward,&callback,this); libvlc_event_detach(manager,libvlc_MediaPlayerBackward,&callback,this); libvlc_event_detach(manager,libvlc_MediaPlayerEndReached,&callback,this); libvlc_event_detach(manager,libvlc_MediaPlayerEncounteredError,&callback,this); libvlc_event_detach(manager,libvlc_MediaPlayerTimeChanged,&callback,this); //libvlc_event_detach(manager,libvlc_MediaPlayerPositionChanged,&callback,this); libvlc_event_detach(manager,libvlc_MediaPlayerSeekableChanged,&callback,this); libvlc_event_detach(manager,libvlc_MediaPlayerPausableChanged,&callback,this); libvlc_event_detach(manager,libvlc_MediaPlayerTitleChanged,&callback,this); libvlc_event_detach(manager,libvlc_MediaPlayerSnapshotTaken,&callback,this); libvlc_event_detach(manager,libvlc_MediaPlayerLengthChanged,&callback,this); libvlc_media_release(vlcMedia); libvlc_media_player_stop(vlcMediaPlayer); libvlc_media_player_release(vlcMediaPlayer); vlcMediaPlayer = 0; vlcMedia = 0; } //This little bs code is brought to you by the dolts from vlc and Qt. Qt's QDir dosen't return //native path seperators nicely, and VLC won't accept anything but native. #ifdef Q_OS_WIN32 vlcMedia = libvlc_media_new_path(vlcInstance,file.replace("/","\\").toAscii()); #else #ifdef Q_OS_LINUX vlcMedia = libvlc_media_new_path(vlcInstance,file.toAscii()); #endif #endif vlcMediaPlayer = libvlc_media_player_new_from_media(vlcMedia); libvlc_media_parse(vlcMedia); libvlc_event_manager_t *manager = libvlc_media_player_event_manager(vlcMediaPlayer); libvlc_event_attach(manager,libvlc_MediaPlayerOpening,&callback,this); libvlc_event_attach(manager,libvlc_MediaPlayerBuffering,&callback,this); libvlc_event_attach(manager,libvlc_MediaPlayerPlaying,&callback,this); libvlc_event_attach(manager,libvlc_MediaPlayerStopped,&callback,this); libvlc_event_attach(manager,libvlc_MediaPlayerPaused,&callback,this); libvlc_event_attach(manager,libvlc_MediaPlayerForward,&callback,this); libvlc_event_attach(manager,libvlc_MediaPlayerBackward,&callback,this); libvlc_event_attach(manager,libvlc_MediaPlayerEndReached,&callback,this); libvlc_event_attach(manager,libvlc_MediaPlayerEncounteredError,&callback,this); libvlc_event_attach(manager,libvlc_MediaPlayerTimeChanged,&callback,this); //libvlc_event_attach(manager,libvlc_MediaPlayerPositionChanged,&callback,this); libvlc_event_attach(manager,libvlc_MediaPlayerSeekableChanged,&callback,this); libvlc_event_attach(manager,libvlc_MediaPlayerPausableChanged,&callback,this); libvlc_event_attach(manager,libvlc_MediaPlayerTitleChanged,&callback,this); libvlc_event_attach(manager,libvlc_MediaPlayerSnapshotTaken,&callback,this); libvlc_event_attach(manager,libvlc_MediaPlayerLengthChanged,&callback,this); //libvlc_event_manager_t *mediamanager = libvlc_media_event_manager(vlcMedia); //libvlc_event_attach(mediamanager,libvlc_MediaStateChanged,&callback,this); emit mediaChanged(); }
int transcode_stream::transcode_process(platform::process &process) { std::vector<std::string> vlc_options; vlc_options.push_back("--no-sub-autodetect-file"); if (compare_version(instance::version(), "2.1") >= 0) vlc_options.push_back("--avcodec-fast"); int font_size = -1; process >> font_size; if (font_size > 0) { vlc_options.push_back("--freetype-fontsize"); vlc_options.push_back(std::to_string(font_size)); } vlc::instance instance(vlc_options); std::string mrl, transcode, mux; process >> mrl >> transcode >> mux; std::ostringstream sout; sout << ":sout=" << from_percent(transcode) << ":std{access=fd,mux=" << mux << ",dst=" << process.output_fd() << "}"; auto media = media::from_mrl(instance, mrl); libvlc_media_add_option(media, sout.str().c_str()); std::string subtitle_file; process >> subtitle_file; if (subtitle_file != "(none)") { std::string file = from_percent(subtitle_file); #ifdef WIN32 file = from_utf16(platform::to_windows_path(file)); #endif libvlc_media_add_option(media, (":sub-file=" + file).c_str()); } size_t num_options = 0; process >> num_options; for (size_t i = 0; i < num_options; i++) { std::string option; process >> option; libvlc_media_add_option(media, from_percent(option).c_str()); } struct T { static void callback(const libvlc_event_t *e, void *opaque) { T * const t = reinterpret_cast<T *>(opaque); std::lock_guard<std::mutex> _(t->mutex); if (e->type == libvlc_MediaPlayerTimeChanged) { if (t->info) t->info->time = e->u.media_player_time_changed.new_time; } else if (e->type == libvlc_MediaPlayerPlaying) { t->started = true; if (t->track_ids.video >= -1) { libvlc_video_set_track(t->player, -1); if (t->track_ids.video > 0) libvlc_video_set_track(t->player, t->track_ids.video); } if (t->track_ids.audio >= -1) { libvlc_audio_set_track(t->player, -1); if (t->track_ids.audio >= 0) libvlc_audio_set_track(t->player, t->track_ids.audio); } if (t->track_ids.text >= -1) { libvlc_video_set_spu(t->player, -1); if (t->track_ids.text >= 0) libvlc_video_set_spu(t->player, t->track_ids.text); } } else if (e->type == libvlc_MediaPlayerEndReached) { t->end_reached = true; if (t->info) t->info->end_reached = true; } else if (e->type == libvlc_MediaPlayerEncounteredError) t->encountered_error = true; t->condition.notify_one(); } volatile shared_info *info; struct track_ids track_ids; std::mutex mutex; std::condition_variable condition; bool started; bool end_reached; bool encountered_error; libvlc_media_player_t *player; } t; unsigned info_offset(-1); process >> info_offset; process >> t.track_ids.audio >> t.track_ids.video >> t.track_ids.text; int chapter = -1; int64_t position = -1; float rate = 0.0f; process >> chapter >> position >> rate; t.info = &process.get_shared<shared_info>(info_offset); t.started = false; t.end_reached = false; t.encountered_error = false; t.player = libvlc_media_player_new_from_media(media); if (t.player) { auto event_manager = libvlc_media_player_event_manager(t.player); libvlc_event_attach(event_manager, libvlc_MediaPlayerTimeChanged, &T::callback, &t); libvlc_event_attach(event_manager, libvlc_MediaPlayerPlaying, &T::callback, &t); libvlc_event_attach(event_manager, libvlc_MediaPlayerEndReached, &T::callback, &t); libvlc_event_attach(event_manager, libvlc_MediaPlayerEncounteredError, &T::callback, &t); if (libvlc_media_player_play(t.player) == 0) { std::unique_lock<std::mutex> l(t.mutex); while (!t.end_reached && !t.encountered_error && process) { if (t.started) { l.unlock(); if (chapter >= 0) libvlc_media_player_set_chapter(t.player, chapter); if (position > 0) libvlc_media_player_set_time(t.player, position); if (std::abs(rate - 1.0f) > 0.01f) libvlc_media_player_set_rate(t.player, rate); l.lock(); t.started = false; } t.condition.wait(l); } l.unlock(); libvlc_media_player_stop(t.player); } libvlc_event_detach(event_manager, libvlc_MediaPlayerEncounteredError, &T::callback, &t); libvlc_event_detach(event_manager, libvlc_MediaPlayerEndReached, &T::callback, &t); libvlc_event_detach(event_manager, libvlc_MediaPlayerPlaying, &T::callback, &t); libvlc_event_detach(event_manager, libvlc_MediaPlayerTimeChanged, &T::callback, &t); libvlc_media_player_release(t.player); } return 0; }
/** * Thumbnailer main function. * return null if the thumbail generation failed. **/ jbyteArray Java_org_videolan_libvlc_util_VLCUtil_nativeGetThumbnail(JNIEnv *env, jobject thiz, jobject jmedia, const jint frameWidth, const jint frameHeight) { vlcjni_object *p_obj = VLCJniObject_getInstance(env, jmedia); jbyteArray byteArray = NULL; /* Create the thumbnailer data structure */ thumbnailer_sys_t *sys = calloc(1, sizeof(thumbnailer_sys_t)); if (sys == NULL) { LOGE("Could not create the thumbnailer data structure!"); return NULL; } /* Initialize the barrier. */ pthread_mutex_init(&sys->doneMutex, NULL); pthread_cond_init(&sys->doneCondVar, NULL); /* Create a media player playing environment */ libvlc_media_player_t *mp = libvlc_media_player_new_from_media(p_obj->u.p_m); if (!mp) goto end; libvlc_media_player_set_video_title_display(mp, libvlc_position_disable, 0); sys->frameWidth = frameWidth; sys->frameHeight = frameHeight; /* Set the video format and the callbacks. */ libvlc_video_set_callbacks(mp, thumbnailer_lock, thumbnailer_unlock, thumbnailer_display, (void*)sys); libvlc_video_set_format_callbacks(mp, thumbnailer_setup, NULL); libvlc_event_attach(libvlc_media_player_event_manager(mp), libvlc_MediaPlayerPositionChanged, thumbnailer_event, sys); /* Play the media. */ libvlc_media_player_play(mp); libvlc_media_player_set_position(mp, THUMBNAIL_POSITION); /* Wait for the thumbnail to be generated. */ pthread_mutex_lock(&sys->doneMutex); struct timespec deadline; clock_gettime(CLOCK_REALTIME, &deadline); deadline.tv_sec += 3; /* Wait for a VOUT for 3 seconds, some input format like *.TS make some time * to initialize a VOUT */ int ret = 0; while (!(sys->state & THUMB_VOUT) && ret != ETIMEDOUT) ret = pthread_cond_timedwait(&sys->doneCondVar, &sys->doneMutex, &deadline); if (sys->state & THUMB_VOUT) { ret = 0; /* Wait an additional 7 seconds for a frame */ deadline.tv_sec += 7; while (!(sys->state & THUMB_DONE) && ret != ETIMEDOUT) ret = pthread_cond_timedwait(&sys->doneCondVar, &sys->doneMutex, &deadline); } else LOGE("media has not VOUT"); pthread_mutex_unlock(&sys->doneMutex); /* Stop and release the media player. */ libvlc_media_player_stop(mp); libvlc_event_detach(libvlc_media_player_event_manager(mp), libvlc_MediaPlayerPositionChanged, thumbnailer_event, sys); libvlc_media_player_release(mp); if ((sys->state & THUMB_DONE) && sys->frameData) { /* Create the Java byte array to return the create thumbnail. */ byteArray = (*env)->NewByteArray(env, sys->frameSize); if (byteArray == NULL) { LOGE("Could not allocate the Java byte array to store the frame!"); goto end; } (*env)->SetByteArrayRegion(env, byteArray, 0, sys->frameSize, (jbyte *)sys->frameData); } end: pthread_mutex_destroy(&sys->doneMutex); pthread_cond_destroy(&sys->doneCondVar); free(sys->frameData); free(sys->thumbData); free(sys); return byteArray; }