Exemplo n.º 1
1
//	Initialization
bool MediaPlayer::initialize( const std::string &url ) {
	LDEBUG( "vlc", "Initialize: url=%s", url.c_str() );
	
	//	Create media from url
	libvlc_media_t *m=libvlc_media_new_path( instance(), url.c_str() );
	if (!m) {
		LERROR( "vlc", "Cannot initialize new media from url: url=%s", url.c_str() );
		return false;
	}

	//	Add common parameters
	libvlc_media_add_option( m, "verbose=1000" );
	libvlc_media_add_option( m, "no-osd" );
	libvlc_media_add_option( m, "ffmpeg-hw" );

	//	Create a media player playing environement
	_mp = libvlc_media_player_new_from_media(m);
	if (!_mp) {
		libvlc_media_release (m);
		LERROR( "vlc", "Cannot create media player from url: url=%s", url.c_str() );
		return false;
	}

	//	No need to keep the media now
	libvlc_media_release (m);

	{	//	Set WindowID
		VideoDescription desc;
		if (getVideoDescription( desc )) {
#ifndef _WIN32
			libvlc_media_player_set_xwindow( _mp, desc.winID );
#else
			libvlc_media_player_set_hwnd( _mp, desc );
#endif
		}
	}

	{	//	Attach to stop asyn events
		libvlc_event_manager_t *mgr=libvlc_media_player_event_manager( _mp );
		libvlc_event_attach( mgr, libvlc_MediaPlayerEndReached, vlcCallback, this ); 
	}

	return true;
}
Exemplo n.º 2
0
	VLCWrapper::VLCWrapper (QObject *parent)
	: QObject (parent)
	, CurrentItem_ (-1)
	, IsPlayedFromQueue_ (false)
	{
		Instance_ = libvlc_instance_ptr (libvlc_new (sizeof (vlc_args)
				/ sizeof (vlc_args[0]), vlc_args), libvlc_release);
		LPlayer_ = libvlc_media_list_player_ptr (libvlc_media_list_player_new (Instance_.get ()),
				libvlc_media_list_player_release);
		Player_ = libvlc_media_player_ptr (libvlc_media_player_new (Instance_.get ()),
				libvlc_media_player_release);
		List_ = libvlc_media_list_ptr (libvlc_media_list_new (Instance_.get ()),
				libvlc_media_list_release);

		libvlc_media_list_player_set_media_player (LPlayer_.get (), Player_.get ());
		libvlc_media_list_player_set_media_list (LPlayer_.get (), List_.get ());

		auto listEventManager = libvlc_media_list_player_event_manager (LPlayer_.get ());
		libvlc_event_attach (listEventManager, libvlc_MediaListPlayerNextItemSet,
				ListEventCallback, this);

		auto playerEventManager = libvlc_media_player_event_manager (Player_.get ());
		libvlc_event_attach (playerEventManager, libvlc_MediaPlayerPlaying,
				ListEventCallback, this);

		libvlc_event_attach (playerEventManager, libvlc_MediaPlayerStopped,
				ListEventCallback, this);
		libvlc_event_attach (playerEventManager, libvlc_MediaPlayerPaused,
				ListEventCallback, this);
		libvlc_event_attach (playerEventManager, libvlc_MediaPlayerEndReached,
				ListEventCallback, this);
	}
Exemplo n.º 3
0
bool VlcMediaWidget::init()
{
	const char *arguments[] = { "--no-video-title-show" };
	vlcInstance = libvlc_new(sizeof(arguments) / sizeof(arguments[0]), arguments);

	if (vlcInstance == NULL) {
		Log("VlcMediaWidget::init: cannot create vlc instance") << QLatin1String(libvlc_errmsg());
		return false;
	}

	vlcMediaPlayer = libvlc_media_player_new(vlcInstance);

	if (vlcMediaPlayer == NULL) {
		Log("VlcMediaWidget::init: cannot create vlc media player") << QLatin1String(libvlc_errmsg());
		return false;
	}

	libvlc_event_manager_t *eventManager = libvlc_media_player_event_manager(vlcMediaPlayer);
	libvlc_event_e eventTypes[] = { libvlc_MediaPlayerEncounteredError,
		libvlc_MediaPlayerEndReached, libvlc_MediaPlayerLengthChanged,
		libvlc_MediaPlayerSeekableChanged, libvlc_MediaPlayerStopped,
		libvlc_MediaPlayerTimeChanged };

	for (uint i = 0; i < (sizeof(eventTypes) / sizeof(eventTypes[0])); ++i) {
		if (libvlc_event_attach(eventManager, eventTypes[i], vlcEventHandler, this) != 0) {
			Log("VlcMediaWidget::init: cannot attach event handler") << eventTypes[i];
			return false;
		}
	}

	libvlc_media_player_set_xwindow(vlcMediaPlayer, quint32(winId()));
	setAttribute(Qt::WA_NativeWindow);
	setAttribute(Qt::WA_PaintOnScreen);
	return true;
}
Exemplo n.º 4
0
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);
}
Exemplo n.º 5
0
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);
}
Exemplo n.º 6
0
void NPlaybackEngineVlc::init()
{
    int argc;
    const char **argv;
    NCore::cArgs(&argc, &argv);

    QVector<const char *> argVector;
    for (int i = 0; i < argc; ++i)
        argVector << argv[i];

    argVector << "-I" << "dummy"
              << "--ignore-config"
              << "--no-xlib";

    m_vlcInstance = libvlc_new(argVector.size(), &argVector[0]);
    m_mediaPlayer = libvlc_media_player_new(m_vlcInstance);
    m_eventManager = libvlc_media_player_event_manager(m_mediaPlayer);
    libvlc_event_attach(m_eventManager, libvlc_MediaPlayerEndReached, _eventHandler, this);

    m_oldVolume = -1;
    m_oldPosition = -1;
    m_oldState = N::PlaybackStopped;

    m_timer = new QTimer(this);
    connect(m_timer, SIGNAL(timeout()), this, SLOT(checkStatus()));
    m_timer->start(100);

    m_init = true;
}
Exemplo n.º 7
0
VlcMediaPlayer::VlcMediaPlayer(VlcInstance *instance)
    : QObject(instance)
{
    _vlcMediaPlayer = libvlc_media_player_new(instance->core());
    _vlcEvents = libvlc_media_player_event_manager(_vlcMediaPlayer);

    /* Disable mouse and keyboard events */
    libvlc_video_set_key_input(_vlcMediaPlayer, false);
    libvlc_video_set_mouse_input(_vlcMediaPlayer, false);

    VlcError::showErrmsg();

    _vlcAudio = new VlcAudio(this);
    _vlcVideo = new VlcVideo(this);
#if LIBVLC_VERSION >= 0x020200
    _vlcEqualizer = new VlcEqualizer(this);
#endif

    _videoWidget = 0;
    _media = 0;

    createCoreConnections();

    VlcError::showErrmsg();
}
static void
MediaPlayer_newCommon(JNIEnv *env, jobject thiz, vlcjni_object *p_obj,
                      jobject jwindow)
{
    p_obj->p_sys = calloc(1, sizeof(vlcjni_object_sys));

    if (!p_obj->u.p_mp || !p_obj->p_sys)
    {
        VLCJniObject_release(env, thiz, p_obj);
        throw_IllegalStateException(env, "can't create MediaPlayer instance");
        return;
    }
    p_obj->p_sys->jwindow = (*env)->NewGlobalRef(env, jwindow);
    if (!p_obj->p_sys->jwindow)
    {
        VLCJniObject_release(env, thiz, p_obj);
        throw_IllegalStateException(env, "can't create MediaPlayer instance");
        return;
    }
    libvlc_media_player_set_android_context(p_obj->u.p_mp, libvlc_get_jvm(),
                                            p_obj->p_sys->jwindow);

    VLCJniObject_attachEvents(p_obj, MediaPlayer_event_cb,
                              libvlc_media_player_event_manager(p_obj->u.p_mp),
                              mp_events);
}
Exemplo n.º 9
0
VlcVideoPlayer::VlcVideoPlayer(wxWindow* win, const VideoID& id, wxPoint pt, wxSize size)
    : wxPanel(win, wxID_ANY, pt, size), videoID_(id), firstPlay_(1)
{
	SetBackgroundColour(axColor(0, 0, 0));

	_DEBUG_ nb_time_callback = 0;

    // Create new VLC instance.
    char const* vlcOptions[] = {"--no-video-title-show"}; //Hide filename.

	vlcInstance = NULL;
	vlcPlayer = NULL;

    // Create VLC instance
	vlcInstance = libvlc_new(1, vlcOptions);

    if( vlcInstance )
	{
		vlcPlayer = libvlc_media_player_new(vlcInstance);

		// Create VLC player
		if( vlcPlayer )
		{
			// Create VLC EventManager
			vlcEventManager = libvlc_media_player_event_manager(vlcPlayer);

			if( !vlcEventManager )
			{
				_DEBUG_ DSTREAM << "Can't create VLC Event Manager" << endl;
				wxMessageDialog (this, "Can't create VLC Event Manager");
			}
		}
		else // vlcPlayer
		{
			_DEBUG_ DSTREAM << "Can't create player from vlcMedia" << endl;
			wxMessageDialog (this, "Can't create player from vlcMedia");
		}
	}

    else // vlcInstance.
	{
		_DEBUG_ DSTREAM << "Can't Open VLC instance" << endl;
		wxMessageDialog (this, "Can't Open VLC instance");
	}

    // libVLC events and callback
	if( vlcInstance && vlcPlayer && vlcEventManager )
	{
		libvlc_event_attach(vlcEventManager, 
							libvlc_MediaPlayerPositionChanged, 
							VlcVideoPlayer::vlcPositionChanged, 
							this);
		
		libvlc_event_attach(vlcEventManager, 
							libvlc_MediaPlayerTimeChanged, 
							VlcVideoPlayer::vlcTimeChanged, 
							this);
	}
}
VLCEventBridge::VLCEventBridge( VLCMediaPlayer* mediaplayer ) {
    Q_ASSERT( mediaplayer != 0 );
    Q_ASSERT( mediaplayer->_mediaPlayer != 0 );
    _mediaPlayer = mediaplayer;
    _eventManager = libvlc_media_player_event_manager( _mediaPlayer->_mediaPlayer );

    if ( !_eventManager )
        throw libvlc_errmsg();
}
Exemplo n.º 11
0
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;
    }
}
Exemplo n.º 12
0
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);
}
Exemplo n.º 13
0
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);
}
Exemplo n.º 14
0
bool CAVPlayer::Play(const std::string &strPath)
{
    if (! m_pVLC_Inst)
    {// 如果播放引擎没有创建,则创建它
        Init();
    }

    if(strPath.empty() || ! m_pVLC_Inst)
    {// 如果链接地址为空,或播放引擎没创建,则直接返回
        return false;
    }

    // 验证地址是网络地址,还是本地地址
    bool bURL = false;
	bURL = IsURL(strPath);

    Stop();

    bool bRet = false;
    libvlc_media_t *m = NULL;

    if (bURL)
    {// 网络路径
        m = libvlc_media_new_location(m_pVLC_Inst, strPath.c_str());
    } 
    else
    {// 本地路径
        m = libvlc_media_new_path(m_pVLC_Inst, strPath.c_str());
    }

    if (m)
    {
        if (m_pVLC_Player = libvlc_media_player_new_from_media(m))
        {
            libvlc_media_player_set_hwnd(m_pVLC_Player, m_hWnd);
            libvlc_media_player_play(m_pVLC_Player);
			m_bStatus = em_play;//播放状态
            // 事件管理
            libvlc_event_manager_t *vlc_evt_man = libvlc_media_player_event_manager(m_pVLC_Player);
            libvlc_event_attach(vlc_evt_man, libvlc_MediaPlayerPlaying,CAVPlayer::OnVLC_Event, this);
            libvlc_event_attach(vlc_evt_man, libvlc_MediaPlayerPositionChanged, CAVPlayer::OnVLC_Event, this);
            libvlc_event_attach(vlc_evt_man, libvlc_MediaPlayerEndReached, CAVPlayer::OnVLC_Event, this);
            bRet = true;
        }

        libvlc_media_release(m);
    }

    return bRet;
}
Exemplo n.º 15
0
bool Transcode::m_doTranscode( const QString &transStr )
{
    QString sout( ":sout=" );
    sout += transStr;

    char const *vlc_argv[] = 
    {
        "-I", "dummy", 
        "--no-skip-frame",
    };

    int vlc_argc = sizeof( vlc_argv ) / sizeof( *vlc_argv );

    libvlc_exception_init( &m_vlcEx );
    
    m_libvlc = libvlc_new( vlc_argc, vlc_argv, &m_vlcEx );
    if ( catchVLCException( &m_vlcEx ) )
        return false;
    
    m_vlcMedia = libvlc_media_new( m_libvlc, m_origVidPath.toLocal8Bit(), &m_vlcEx );
    if ( catchVLCException( &m_vlcEx ) ) 
        return false;

    libvlc_media_add_option(m_vlcMedia, sout.toStdString().c_str(), &m_vlcEx);
    if ( catchVLCException( &m_vlcEx ) ) 
        return false;

    m_vlcMp = libvlc_media_player_new_from_media( m_vlcMedia, &m_vlcEx );
    if ( catchVLCException( &m_vlcEx ) )
        return false;

    m_vlcEM = libvlc_media_player_event_manager( m_vlcMp, &m_vlcEx );
    if ( catchVLCException( &m_vlcEx ) ) 
        return false;

    libvlc_event_attach( m_vlcEM, libvlc_MediaPlayerPlaying, m_callback, this, &m_vlcEx );
    if ( catchVLCException( &m_vlcEx ) ) 
        return false;
    libvlc_event_attach( m_vlcEM, libvlc_MediaPlayerEndReached, m_callback, this,  &m_vlcEx );
    if ( catchVLCException( &m_vlcEx ) ) 
        return false;

    libvlc_media_player_play( m_vlcMp, &m_vlcEx );
    if ( catchVLCException( &m_vlcEx ) ) 
        return false;
    m_running = true;
    m_initProgressDialog();

    return true;
}
Exemplo n.º 16
0
bool	VLCAudioPlayer::init(QStringList opt)
{
	handleOption(opt);
	const char * const vlc_args[] = {
              "-I", "dummy", "-A", optionValue["ao"].toString().toStdString().c_str(), /* Don't use any interface */
             "--ignore-config", "--no-video"}; /* Don't use VLC's config */

	libvlc_event_manager_t	*em;
	libvlc_exception_init(&vlc_ex);
	inst = libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args, &vlc_ex);
	mediaPlayer = libvlc_media_player_new(inst, &vlc_ex);
	em = libvlc_media_player_event_manager(mediaPlayer, &vlc_ex);
	return true;
}
Exemplo n.º 17
0
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();
}
Exemplo n.º 18
0
VLCWrapperImpl::VLCWrapperImpl(void)
:	m_pVLCInstance(0),
	m_pMediaPlayer(0),
	m_pMedia(0),
    m_pEvtManager(0),
    m_EH(0),
    m_EvtH(0)
{
	const char * const vlc_args[] = {
		"-I", "dummy",     // No special interface
		"--ignore-config", // Don't use VLC's config
		"--plugins-cache",
		"--no-reset-plugins-cache",
		"--plugin-path=./plugins",
#if defined(WIN32)
		"--one-instance", 
#endif
		"--ts-es-id-pid",
		"--video-on-top",
		"--vout-event=3",
		"--no-video-title-show",
		"--embedded-video",
		"--video-x=0",
		"--video-y=0",
		"--width=1", 
		"--height=1",
		"--scale=1.0",
		"--no-video-deco",
		"--video-title=VLC/VIDEO",
		"--loop",
		};

    // init the exception object.
	libvlc_exception_init (&m_VLCex);

	// init vlc modules, should be done only once
	m_pVLCInstance = libvlc_new (sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args, &m_VLCex);
    ProcessVLCException(&m_VLCex, m_EH);

    // Create a media player playing environement
    m_pMediaPlayer = libvlc_media_player_new(m_pVLCInstance, &m_VLCex);
    ProcessVLCException(&m_VLCex, m_EH);

    // Create an event manager for the player for handling e.g. time change events
    m_pEvtManager=libvlc_media_player_event_manager(m_pMediaPlayer, &m_VLCex);
    ProcessVLCException(&m_VLCex, m_EH);
}
Exemplo n.º 19
0
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);
}
Exemplo n.º 20
0
 VLCImageStream( const char* const* vlc_argv=0 )
 :   osg::ImageStream(), _vlcMedia(0)
 {
     if ( !vlc_argv )
     {
         const char* vlc_args[] = {
             "--ignore-config",      // don't use VLC's config
             "--data-path="VLC_PLUGIN_PATH
         };
         _vlc = libvlc_new( sizeof(vlc_args)/sizeof(vlc_args[0]), vlc_args );
     }
     else
         _vlc = libvlc_new( sizeof(vlc_argv)/sizeof(vlc_argv[0]), vlc_argv );
     _vlcPlayer = libvlc_media_player_new( _vlc );
     
     libvlc_event_attach( libvlc_media_player_event_manager(_vlcPlayer), libvlc_MediaPlayerStopped,
                          &VLCImageStream::videoEndFunc, this );
     _status = INVALID;
 }
Exemplo n.º 21
0
    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));
    }
Exemplo n.º 22
0
void VLCHolderWnd::LibVlcAttach(libvlc_media_player_t* p_md)
{
    if(!_p_md){
        _p_md = p_md;
        libvlc_media_player_set_hwnd(p_md, getHWND());

        libvlc_event_manager_t* em = libvlc_media_player_event_manager(_p_md);
        if(em){
            //We need set hook to catch doubleclicking (to switch to fullscreen and vice versa).
            //But libvlc media window not exist yet,
            //and we don't know when it will be created, nor ThreadId of it.
            //So we try catch first libvlc_MediaPlayerPositionChanged event,
            //(suppose wnd will be created to that moment)),
            //and then try set mouse hook.
            _LibVlcESAttached =
                0==libvlc_event_attach(em, libvlc_MediaPlayerPositionChanged,
                                       OnLibVlcEvent, this);
        }
    }
}
Exemplo n.º 23
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;
        }
    }
}
Exemplo n.º 24
0
static void
_file_set(struct _App *app)
{
   if (app->opening)
     {
	libvlc_media_release(app->m);
	libvlc_media_player_release(app->mp);
	free(app->filename);
     }

   _em_str_read(app->em_read, &app->filename);

   app->m = libvlc_media_new_path(app->libvlc, app->filename);
   if (!app->m)
     {
	fprintf(stderr, "could not open path: \"%s\"\n", app->filename);
	return;
     }
   app->mp = libvlc_media_player_new_from_media(app->m);

   if (!app->mp)
     {
	fprintf(stderr, "could not create new player from media.\n");
	return;
     }

   app->opening = 1;
   libvlc_video_set_format(app->mp, "RV32", DEFAULTWIDTH, DEFAULTHEIGHT, DEFAULTWIDTH * 4);
   libvlc_video_set_callbacks(app->mp, _tmp_lock, _tmp_unlock, _tmp_display, app);
   app->event_mgr = libvlc_media_player_event_manager(app->mp);
   libvlc_event_attach(app->event_mgr, libvlc_MediaPlayerPositionChanged,
		       _event_cb, app);
   libvlc_event_attach(app->event_mgr, libvlc_MediaPlayerStopped,
		       _event_cb, app);

   app->mevent_mgr = libvlc_media_event_manager(app->m);

   app->tmpbuffer = malloc(sizeof(char) * DEFAULTWIDTH * DEFAULTHEIGHT * 4);
   libvlc_audio_set_mute(app->mp, 1);
   libvlc_media_player_play(app->mp);
}
Exemplo n.º 25
0
VLCWrapperImpl::VLCWrapperImpl(void)
:	pVLCInstance_(0),
	pMediaPlayer_(0),
	pMedia_(0),
    pEventManager_(0),
    eventHandler(0)
{
	const char * const vlc_args[] = {
		"-I", "dumy",      // No special interface
		"--ignore-config", // Don't use VLC's config
		"--plugin-path=./plugins" };

	// init vlc modules, should be done only once
	pVLCInstance_ = libvlc_new (sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);
     
    // Create a media player playing environement
    pMediaPlayer_ = libvlc_media_player_new(pVLCInstance_);

    // Create an event manager for the player for handling e.g. time change events
    pEventManager_ = libvlc_media_player_event_manager(pMediaPlayer_);
}
Exemplo n.º 26
0
bool VLCPlayer::loadFile(const QString & filePath) {
    VLCPlayer::mutex.lock();

    if (VLCPlayer::playbackInProgress == true) {
        qDebug() << "Playback already in progress !";
        VLCPlayer::mutex.unlock();
        return false;
    }

    void *pUserData = 0;


    libvlc_event_manager_t* eventManager = libvlc_media_player_event_manager(VLCPlayer::media_player);
    libvlc_event_attach(eventManager, libvlc_MediaPlayerTimeChanged, handleEvent, pUserData);
    libvlc_event_attach(eventManager, libvlc_MediaPlayerEndReached, handleEvent, pUserData);
    libvlc_event_attach(eventManager, libvlc_MediaPlayerPositionChanged, handleEvent, pUserData);


    QFile mediaFile(filePath);
    if (!mediaFile.open(QIODevice::ReadOnly)) {
        qDebug() << "Unable to open the file : " << filePath;
        VLCPlayer::mutex.unlock();
        return false;
    }

    libvlc_media_t * media = libvlc_media_new_fd(VLCPlayer::inst, mediaFile.handle());
    libvlc_media_player_set_media(VLCPlayer::media_player, media);
    libvlc_media_player_play(VLCPlayer::media_player);


    VLCPlayer::playbackInProgress = true;
    VLCPlayer::mutex.unlock();

    while (VLCPlayer::playbackInProgress) {
        QTest::qSleep(1000);
    }
    mediaFile.close();

    return true;
}
Exemplo n.º 27
0
void VlcVideoWidget::RestartPlayback()
{
    if (!status.doRestart)
        return;
    status.doRestart = false;
    
    vlcPlayer_ = libvlc_media_player_new_from_media(vlcMedia_);
    
    libvlc_event_manager_t *em = libvlc_media_player_event_manager(vlcPlayer_);
    libvlc_event_attach(em, libvlc_MediaPlayerMediaChanged, &VlcEventHandler, this);
    libvlc_event_attach(em, libvlc_MediaPlayerOpening, &VlcEventHandler, this);
    libvlc_event_attach(em, libvlc_MediaPlayerBuffering, &VlcEventHandler, this);
    libvlc_event_attach(em, libvlc_MediaPlayerPlaying, &VlcEventHandler, this);
    libvlc_event_attach(em, libvlc_MediaPlayerPaused, &VlcEventHandler, this);
    libvlc_event_attach(em, libvlc_MediaPlayerStopped, &VlcEventHandler, this);
    libvlc_event_attach(em, libvlc_MediaPlayerEncounteredError, &VlcEventHandler, this);
    libvlc_event_attach(em, libvlc_MediaPlayerTimeChanged, &VlcEventHandler, this);
    libvlc_event_attach(em, libvlc_MediaPlayerPositionChanged, &VlcEventHandler, this);
    libvlc_event_attach(em, libvlc_MediaPlayerSeekableChanged, &VlcEventHandler, this);
    libvlc_event_attach(em, libvlc_MediaPlayerPausableChanged, &VlcEventHandler, this);
    libvlc_event_attach(em, libvlc_MediaPlayerTitleChanged, &VlcEventHandler, this);
    libvlc_event_attach(em, libvlc_MediaPlayerLengthChanged, &VlcEventHandler, this);

    libvlc_video_set_callbacks(
        vlcPlayer_,
        &CallBackLock,
        &CallBackUnlock,
        &CallBackDisplay,
        this);

    renderPixmap_ = QImage(status.sourceSize.width(), status.sourceSize.height(), QImage::Format_RGB32);
    libvlc_video_set_format(vlcPlayer_, "RV32", renderPixmap_.width(), renderPixmap_.height(), renderPixmap_.bytesPerLine());

    if (!status.doNotPlayAfterRestart)
    {
        Play();
        status.doNotPlayAfterRestart = false;
    }
}
Exemplo n.º 28
0
JNIEXPORT void JNICALL NAME(nativeCreate)(JNIEnv *env, jobject thiz)
{
    initClasses(env, thiz);
    vlc_mutex_t *parse_lock = calloc(1, sizeof(vlc_mutex_t));
    vlc_mutex_init(parse_lock);
    setIntValue(env, thiz, "mNativeMediaParseLock", (jint) parse_lock);
    vlc_cond_t *parse_cond = calloc(1, sizeof(vlc_cond_t));
    vlc_cond_init(parse_cond);
    setIntValue(env, thiz, "mNativeMediaParseCond", (jint) parse_cond);
    setIntValue(env, thiz, "mNativeMediaBufferingCount", 0);
    const char *argv[] = {"-I", "dummy", "-vvv", "--no-plugins-cache", "--no-drop-late-frames", "--input-timeshift-path", "/data/local/tmp"};
    libvlc_instance_t *instance = libvlc_new_with_builtins(sizeof(argv) / sizeof(*argv), argv, vlc_builtins_modules);
    setIntValue(env, thiz, "mLibVlcInstance", (jint) instance);
    libvlc_media_player_t *mp = libvlc_media_player_new(instance);
    setIntValue(env, thiz, "mLibVlcMediaPlayer", (jint) mp);
    /* throw? */
    libvlc_event_manager_t *em = libvlc_media_player_event_manager(mp);
    for (int i = 0; i < sizeof(mp_listening) / sizeof(*mp_listening); i++)
    {
        libvlc_event_attach(em, mp_listening[i], vlc_event_callback, thiz);
    }
}
Exemplo n.º 29
0
 VLC::VLC(asl::DLHandle theDLHandle) 
     : CaptureDevice(),
     PlugInBase(theDLHandle),
     _EOF(false),
     _curBuffer(NULL),
     _libvlc(NULL),
     _mediaPlayer(NULL),
     _playTime(0)
 {
     char const *vlc_argv[] =
     {
         "--no-osd",
         //"-vvv",
         "--reset-plugins-cache",
         "--no-xlib" // tell VLC to not use Xlib
     };
     int vlc_argc = sizeof(vlc_argv) / sizeof(*vlc_argv);
     _libvlc = libvlc_new(vlc_argc, vlc_argv);
     _mediaPlayer = libvlc_media_player_new(_libvlc);
     libvlc_event_manager_t *eventManager = libvlc_media_player_event_manager(_mediaPlayer);
     libvlc_event_attach(eventManager, libvlc_MediaPlayerEndReached, VLC::handle_vlc_event, this);
 }
Exemplo n.º 30
0
void Java_org_videolan_libvlc_MediaList_loadPlaylist(JNIEnv *env, jobject thiz, jobject libvlcJava, jstring mrl, jobject items) {
    const char* p_mrl = (*env)->GetStringUTFChars(env, mrl, NULL);

    libvlc_media_t *p_md = libvlc_media_new_location((libvlc_instance_t*)(intptr_t)getLong(env, libvlcJava, "mLibVlcInstance"), p_mrl);
    libvlc_media_add_option(p_md, ":demux=playlist,none");
    libvlc_media_add_option(p_md, ":run-time=1");

    struct stopped_monitor* monitor = malloc(sizeof(struct stopped_monitor));
    pthread_mutex_init(&monitor->doneMutex, NULL);
    pthread_cond_init(&monitor->doneCondVar, NULL);
    monitor->stopped = false;
    pthread_mutex_lock(&monitor->doneMutex);

    libvlc_media_player_t* p_mp = libvlc_media_player_new((libvlc_instance_t*)(intptr_t)getLong(env, libvlcJava, "mLibVlcInstance"));
    libvlc_media_player_set_video_title_display(p_mp, libvlc_position_disable, 0);
    libvlc_event_manager_t* ev = libvlc_media_player_event_manager(p_mp);
    libvlc_event_attach(ev, libvlc_MediaPlayerEndReached, stopped_callback, monitor);
    libvlc_media_player_set_media(p_mp, p_md);
    libvlc_media_player_play(p_mp);

    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->stopped) && mp_alive) {
        pthread_cond_timedwait(&monitor->doneCondVar, &monitor->doneMutex, &deadline);
        mp_alive = libvlc_media_player_will_play(p_mp);
    }
    pthread_mutex_unlock(&monitor->doneMutex);
    pthread_mutex_destroy(&monitor->doneMutex);
    pthread_cond_destroy(&monitor->doneCondVar);
    free(monitor);

    libvlc_media_player_release(p_mp);

    expand_media_internal(env, (libvlc_instance_t*)(intptr_t)getLong(env, libvlcJava, "mLibVlcInstance"), items, p_md);

    (*env)->ReleaseStringUTFChars(env, mrl, p_mrl);
}