Пример #1
0
/* TODO: NOT IN VLC API */
void
Java_org_videolan_libvlc_MediaPlayer_nativePlayMRL(JNIEnv *env, jobject thiz,
                                                   jstring mrl,
                                                   jobjectArray mediaOptions)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return;

    /* New Media */
    const char* p_mrl = (*env)->GetStringUTFChars(env, mrl, 0);
    libvlc_media_t* p_md = libvlc_media_new_location(p_obj->p_libvlc, p_mrl);

    /* media options */
    if (mediaOptions != NULL)
        add_media_options(p_md, env, mediaOptions);

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

    /* Connect the media event manager. */
    /* TODO use VlcObject events */
    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_attach(ev_media, mp_media_events[i], vlc_event_callback, NULL);

    libvlc_media_player_set_media(p_obj->u.p_mp, p_md);
    libvlc_media_release(p_md);

    libvlc_media_player_play(p_obj->u.p_mp);
}
Пример #2
0
void VlcMedia::initMedia(const QString &location,
                         const bool &localFile,
                         VlcInstance *instance)
{
    _currentLocation = location;
    QString l = location;
#if defined(Q_OS_WIN32)
    if (localFile)
        l.replace("/", "\\");
#endif

    // Create a new libvlc media descriptor from location
    if (localFile)
        _vlcMedia = libvlc_media_new_path(instance->core(), l.toLocal8Bit().data());
    else
        _vlcMedia = libvlc_media_new_location(instance->core(), l.toLocal8Bit().data());

    _vlcEvents = libvlc_media_event_manager(_vlcMedia);

    createCoreConnections();

    VlcError::errmsg();

    qDebug() << "libvlc" << "Media:" << location << "Local:" << localFile;
}
Пример #3
0
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);
}
Пример #4
0
JNIEXPORT void JNICALL NAME(nativeSetDataSource)(JNIEnv *env, jobject thiz, jstring path)
{
    libvlc_instance_t *instance = (libvlc_instance_t *) getIntValue(env, thiz, "mLibVlcInstance");
    libvlc_media_player_t *mp = (libvlc_media_player_t *) getIntValue(env, thiz, "mLibVlcMediaPlayer");
    const char *str = (*env)->GetStringUTFChars(env, path, 0);
    if (!str)
    {
        /* XXX: throw */
        return;
    }
    libvlc_media_t *media = (*str == '/') ? libvlc_media_new_path(instance, str) : libvlc_media_new_location(instance, str);
    if (media)
    {
        libvlc_event_manager_t *em = libvlc_media_event_manager(media);
        for (int i = 0; i < sizeof(md_listening) / sizeof(*md_listening); i++)
        {
            libvlc_event_attach(em, md_listening[i], vlc_event_callback, thiz);
        }
        /* this will cancel current input and start a new one */
        libvlc_media_player_set_media(mp, media);
        setIntValue(env, thiz, "mNativeMediaBufferingCount", 0);
    }
    (*env)->ReleaseStringUTFChars(env, path, str);
    setIntValue(env, thiz, "mLibVlcMedia", (jint) media);
}
Пример #5
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);
}
Пример #6
0
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);
}
Пример #7
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);
}
Пример #8
0
void VlcMedia::initMedia(const QString &location,
                         bool localFile,
                         VlcInstance *instance)
{
    _currentLocation = location;
    QString l = location;
    if (localFile)
        l = QDir::toNativeSeparators(l);

    // Create a new libvlc media descriptor from location
    if (localFile)
        _vlcMedia = libvlc_media_new_path(instance->core(), l.toUtf8().data());
    else
        _vlcMedia = libvlc_media_new_location(instance->core(), l.toUtf8().data());

    _vlcEvents = libvlc_media_event_manager(_vlcMedia);

    createCoreConnections();

    VlcError::errmsg();

    qDebug() << "libvlc" << "Media:" << location << "Local:" << localFile;
}
Пример #9
0
static void test_media_preparsed(const char** argv, int argc)
{
    // We use this image file because "empty.voc" has no track.
    const char * file = SRCDIR"/samples/image.jpg";

    log ("Testing set_media\n");

    libvlc_instance_t *vlc = libvlc_new (argc, argv);
    assert (vlc != NULL);

    libvlc_media_t *media = libvlc_media_new_path (vlc, file);
    assert (media != NULL);

    vlc_sem_t sem;
    vlc_sem_init (&sem, 0);

    // Check to see if we are properly receiving the event.
    libvlc_event_manager_t *em = libvlc_media_event_manager (media);
    libvlc_event_attach (em, libvlc_MediaParsedChanged, preparsed_changed, &sem);

    // Parse the media. This is synchronous.
    libvlc_media_parse_async(media);

    // Wait for preparsed event
    vlc_sem_wait (&sem);
    vlc_sem_destroy (&sem);

    // We are good, now check Elementary Stream info.
    libvlc_media_track_t **tracks;
    unsigned nb_tracks = libvlc_media_tracks_get (media, &tracks);
    assert (nb_tracks == 1);
    assert (tracks[0]->i_type == libvlc_track_video);
    libvlc_media_tracks_release (tracks, nb_tracks);

    libvlc_media_release (media);
    libvlc_release (vlc);
}
Пример #10
0
static void test_media_subitems_media(libvlc_media_t *media, bool play)
{
    libvlc_media_add_option(media, ":ignore-filetypes= ");

    bool subitems_found[TEST_SUBITEMS_COUNT] = { 0 };
    vlc_sem_t sem;
    vlc_sem_init (&sem, 0);

    libvlc_event_manager_t *em = libvlc_media_event_manager (media);
    libvlc_event_attach (em, libvlc_MediaSubItemTreeAdded, subitem_tree_added, &sem);
    libvlc_event_attach (em, libvlc_MediaSubItemAdded, subitem_added, subitems_found);

    if (play)
    {
        /* XXX: libvlc_media_parse_async won't work with fd, since it won't be
         * preparsed because fd:// is an unknown type, so play the file to
         * force parsing. */
        libvlc_media_player_t *mp = libvlc_media_player_new_from_media (media);
        assert (mp);
        assert (libvlc_media_player_play (mp) != -1);
        vlc_sem_wait (&sem);
        libvlc_media_player_release (mp);
    }
    else
    {
        libvlc_media_parse_async (media);
        vlc_sem_wait (&sem);
    }

    vlc_sem_destroy (&sem);

    for (unsigned i = 0; i < TEST_SUBITEMS_COUNT; ++i)
    {
        log ("test if %s was added\n", test_media_subitems_list[i].file);
        assert (subitems_found[i]);
    }
}
Пример #11
0
void VlcMediaWidget::play(const MediaSource &source)
{
	addPendingUpdates(PlaybackStatus | DvdMenu);
	QByteArray url = source.getUrl().toEncoded();
	playingDvd = false;

	switch (source.getType()) {
	case MediaSource::Url:
		if (url.endsWith(".iso")) {
			playingDvd = true;
		}

		break;
	case MediaSource::AudioCd:
		if (url.size() >= 7) {
			url.replace(0, 4, "cdda");
		} else {
			url = "cdda://";
		}

		break;
	case MediaSource::VideoCd:
		if (url.size() >= 7) {
			url.replace(0, 4, "vcd");
		} else {
			url = "vcd://";
		}

		break;
	case MediaSource::Dvd:
		if (url.size() >= 7) {
			url.replace(0, 4, "dvd");
		} else {
			url = "dvd://";
		}

		playingDvd = true;
		break;
	case MediaSource::Dvb:
		break;
	}

	libvlc_media_t *vlcMedia = libvlc_media_new_location(vlcInstance, url.constData());

	if (vlcMedia == NULL) {
		libvlc_media_player_stop(vlcMediaPlayer);
        Log("VlcMediaWidget::play: cannot create media") << source.getUrl().url();
		return;
	}

	libvlc_event_manager_t *eventManager = libvlc_media_event_manager(vlcMedia);
	libvlc_event_e eventTypes[] = { libvlc_MediaMetaChanged };

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

	libvlc_media_player_set_media(vlcMediaPlayer, vlcMedia);
	libvlc_media_release(vlcMedia);

//	FIXME!

// 	if (source.subtitleUrl.isValid()) {
// 		if (libvlc_video_set_subtitle_file(vlcMediaPlayer,
// 		    source.subtitleUrl.toEncoded().constData()) == 0) {
// 			Log("VlcMediaWidget::play: cannot set subtitle file") <<
// 				source.subtitleUrl.prettyUrl();
// 		}
// 	}

	if (libvlc_media_player_play(vlcMediaPlayer) != 0) {
        Log("VlcMediaWidget::play: cannot play media") << source.getUrl().url();
	}
}
Пример #12
0
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();
}
Пример #13
0
void Java_org_videolan_libvlc_LibVLC_playMRL(JNIEnv *env, jobject thiz, jlong instance,
                                             jstring mrl, jobjectArray mediaOptions)
{
    /* Release previous media player, if any */
    releaseMediaPlayer(env, thiz);

    /* Create a media player playing environment */
    libvlc_media_player_t *mp = libvlc_media_player_new((libvlc_instance_t*)(intptr_t)instance);
    libvlc_media_player_set_video_title_display(mp, libvlc_position_disable, 0);
    jobject myJavaLibVLC = (*env)->NewGlobalRef(env, thiz);

    //if AOUT_AUDIOTRACK_JAVA, we use amem
    jclass cls = (*env)->GetObjectClass(env, thiz);
    jmethodID methodId = (*env)->GetMethodID(env, cls, "getAout", "()I");
    if ( (*env)->CallIntMethod(env, thiz, methodId) == AOUT_AUDIOTRACK_JAVA )
    {
        libvlc_audio_set_callbacks(mp, aout_play, aout_pause, NULL, NULL, NULL,
                                   (void*) myJavaLibVLC);
        libvlc_audio_set_format_callbacks(mp, aout_open, aout_close);
    }

    /* Connect the event manager */
    libvlc_event_manager_t *ev = libvlc_media_player_event_manager(mp);
    static const libvlc_event_type_t mp_events[] = {
        libvlc_MediaPlayerPlaying,
        libvlc_MediaPlayerPaused,
        libvlc_MediaPlayerEndReached,
        libvlc_MediaPlayerStopped,
        libvlc_MediaPlayerVout,
        libvlc_MediaPlayerPositionChanged,
        libvlc_MediaPlayerEncounteredError
    };
    for(int i = 0; i < (sizeof(mp_events) / sizeof(*mp_events)); i++)
        libvlc_event_attach(ev, mp_events[i], vlc_event_callback, myVm);

    /* Keep a pointer to this media player */
    setLong(env, thiz, "mInternalMediaPlayerInstance", (jlong)(intptr_t)mp);

    cls = (*env)->GetObjectClass(env, thiz);
    jmethodID methodID = (*env)->GetMethodID(env, cls, "applyEqualizer", "()V");
    (*env)->CallVoidMethod(env, thiz, methodID);

    const char* p_mrl = (*env)->GetStringUTFChars(env, mrl, 0);

    libvlc_media_t* p_md = libvlc_media_new_location((libvlc_instance_t*)(intptr_t)instance, p_mrl);
    /* media options */
    if (mediaOptions != NULL)
    {
        int stringCount = (*env)->GetArrayLength(env, mediaOptions);
        for(int i = 0; i < stringCount; i++)
        {
            jstring option = (jstring)(*env)->GetObjectArrayElement(env, mediaOptions, i);
            const char* p_st = (*env)->GetStringUTFChars(env, option, 0);
            libvlc_media_add_option(p_md, p_st); // option
            (*env)->ReleaseStringUTFChars(env, option, p_st);
        }
    }

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

    /* Connect the media event manager. */
    libvlc_event_manager_t *ev_media = libvlc_media_event_manager(p_md);
    static const libvlc_event_type_t mp_media_events[] = {
        libvlc_MediaParsedChanged
    };
    for(int i = 0; i < (sizeof(mp_media_events) / sizeof(*mp_media_events)); i++)
        libvlc_event_attach(ev_media, mp_media_events[i], vlc_event_callback, myVm);

    libvlc_media_player_set_media(mp, p_md);
    libvlc_media_player_play(mp);
}
Пример #14
0
static switch_status_t vlc_file_open(switch_file_handle_t *handle, const char *path)
{
	vlc_file_context_t *context;
	libvlc_event_manager_t *mp_event_manager, *m_event_manager;
	
	context = switch_core_alloc(handle->memory_pool, sizeof(*context));
	context->pool = handle->memory_pool;

	context->path = switch_core_strdup(context->pool, path);

	switch_buffer_create_dynamic(&(context->audio_buffer), VLC_BUFFER_SIZE, VLC_BUFFER_SIZE * 8, 0);
	switch_mutex_init(&context->audio_mutex, SWITCH_MUTEX_NESTED, context->pool);
	switch_thread_cond_create(&(context->started), context->pool);

	if (switch_test_flag(handle, SWITCH_FILE_FLAG_READ)) {
		
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "VLC open %s for reading\n", path);
		
		/* Determine if this is a url or a path */
		/* TODO: Change this so that it tries local files first, and then if it fails try location. */
		if(! strncmp(context->path, "http", 4)){
			context->m = libvlc_media_new_location(read_inst, context->path);
			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "VLC Path is http %s\n", context->path);
		} else if (! strncmp(context->path, "mms", 3)){
			context->m = libvlc_media_new_path(read_inst, context->path);
			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "VLC Path is mms %s\n", context->path);
		} else if (! strncmp(context->path, "/", 1)){
			context->m = libvlc_media_new_path(read_inst, context->path);
			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "VLC Path is file %s\n", context->path);
		} else {
			context->m = libvlc_media_new_location(read_inst, context->path);
			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "VLC Path is unknown type %s\n", context->path);
		}

		if ( context->m == NULL ) {
			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "VLC error opening %s for reading\n", path);
			return SWITCH_STATUS_GENERR;
		}
		
		context->playing = 0;
		context->err = 0;
		
		context->mp = libvlc_media_player_new_from_media(context->m);
		
		if (!handle->samplerate) {
			handle->samplerate = 16000;
		}

		context->samplerate = handle->samplerate;
		context->channels = handle->channels;

		libvlc_audio_set_format(context->mp, "S16N", context->samplerate, handle->channels);
		
		m_event_manager = libvlc_media_event_manager(context->m);
		libvlc_event_attach(m_event_manager, libvlc_MediaStateChanged, vlc_media_state_callback, (void *) context);

		mp_event_manager = libvlc_media_player_event_manager(context->mp);
		libvlc_event_attach(mp_event_manager, libvlc_MediaPlayerEncounteredError, vlc_mediaplayer_error_callback, (void *) context);
		
		libvlc_audio_set_callbacks(context->mp, vlc_auto_play_callback, NULL,NULL,NULL,NULL, (void *) context);

		libvlc_media_player_play(context->mp);
		
	} else if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
		const char * opts[10] = {
			vlc_args,
			switch_mprintf("--sout=%s", path)
		};
		int opts_count = 10;
		
		if ( !handle->samplerate)
			handle->samplerate = 16000;
		
		context->samplerate = handle->samplerate;

		opts[2] = switch_mprintf("--imem-get=%ld", vlc_imem_get_callback);
		opts[3] = switch_mprintf("--imem-release=%ld", vlc_imem_release_callback);
		opts[4] = switch_mprintf("--imem-cat=%d", 4);
		opts[5] = "--demux=rawaud";
		opts[6] = "--rawaud-fourcc=s16l";
		opts[7] = switch_mprintf("--rawaud-samplerate=%d", context->samplerate);
		opts[8] = switch_mprintf("--imem-data=%ld", context);
		//opts[9] = "--rawaud-channels=1";

		/* Prepare to write to an output stream. */
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "VLC open %s for writing\n", path);

		/* load the vlc engine. */
		context->inst_out = libvlc_new(opts_count, opts);
		
		/* Tell VLC the audio will come from memory, and to use the callbacks to fetch it. */
		context->m = libvlc_media_new_location(context->inst_out, "imem/rawaud://");
		context->mp = libvlc_media_player_new_from_media(context->m);
		context->samples = 0;
		context->pts = 0;
		context->playing = 1;		
		libvlc_media_player_play(context->mp);
	} else {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "VLC tried to open %s for unknown reason\n", path);
		return SWITCH_STATUS_GENERR;
	}

	handle->private_info = context;
	
	return SWITCH_STATUS_SUCCESS;
}
Пример #15
0
void
AudioOutput::setCurrentSource( MediaStream* stream )
{
    tDebug() << Q_FUNC_INFO;

    setState( Loading );

    if ( m_vlcMedia != nullptr )
    {
        // Ensure playback is stopped, then release media
        libvlc_media_player_stop( m_vlcPlayer );
        libvlc_media_release( m_vlcMedia );
        m_vlcMedia = nullptr;
    }
    if ( m_autoDelete && m_currentStream != nullptr )
    {
        delete m_currentStream;
    }

    m_currentStream = stream;
    m_totalTime = 0;
    m_currentTime = 0;
    m_justSeeked = false;
    m_seekable = true;

    QByteArray url;
    switch ( stream->type() )
    {
        case MediaStream::Unknown:
            tDebug() << Q_FUNC_INFO << "MediaStream Type is Invalid:" << stream->type();
            break;

        case MediaStream::Empty:
            tDebug() << Q_FUNC_INFO << "MediaStream is empty.";
            break;

        case MediaStream::Url:
            tDebug() << Q_FUNC_INFO << "MediaStream::Url:" << stream->url();
            if ( stream->url().scheme().isEmpty() )
            {
                url = "file:///";
                if ( stream->url().isRelative() )
                {
                    url.append( QFile::encodeName( QDir::currentPath() ) + '/' );
                }
            }
            url += stream->url().toEncoded();
            break;

        case MediaStream::Stream:
        case MediaStream::IODevice:
            url = QByteArray( "imem://" );
            break;
    }

    tDebug() << Q_FUNC_INFO << "MediaStream::Final Url:" << url;

    m_vlcMedia = libvlc_media_new_location( m_vlcInstance, url.constData() );
    libvlc_event_manager_t* manager = libvlc_media_event_manager( m_vlcMedia );
    libvlc_event_type_t events[] = {
        libvlc_MediaDurationChanged,
    };
    const int eventCount = sizeof(events) / sizeof( *events );
    for ( int i = 0; i < eventCount; i++ )
    {
        libvlc_event_attach( manager, events[ i ], &AudioOutput::vlcEventCallback, this );
    }

    libvlc_media_player_set_media( m_vlcPlayer, m_vlcMedia );

    if ( stream->type() == MediaStream::Url )
    {
        m_totalTime = libvlc_media_get_duration( m_vlcMedia );
    }
    else if ( stream->type() == MediaStream::Stream || stream->type() == MediaStream::IODevice )
    {
        libvlc_media_add_option_flag(m_vlcMedia, "imem-cat=4", libvlc_media_option_trusted);
        const char* imemData = QString( "imem-data=%1" ).arg( (uintptr_t)stream ).toLatin1().constData();
        libvlc_media_add_option_flag(m_vlcMedia, imemData, libvlc_media_option_trusted);
        const char* imemGet = QString( "imem-get=%1" ).arg( (uintptr_t)&readCallback ).toLatin1().constData();
        libvlc_media_add_option_flag(m_vlcMedia, imemGet, libvlc_media_option_trusted);
        const char* imemRelease = QString( "imem-release=%1" ).arg( (uintptr_t)&readDoneCallback ).toLatin1().constData();
        libvlc_media_add_option_flag(m_vlcMedia, imemRelease, libvlc_media_option_trusted);
        const char* imemSeek = QString( "imem-seek=%1" ).arg( (uintptr_t)&MediaStream::seekCallback ).toLatin1().constData();
        libvlc_media_add_option_flag(m_vlcMedia, imemSeek, libvlc_media_option_trusted);
    }
    if ( qApp->arguments().contains( "--chromecast-ip" ) )
    {
        // This is very basic chromecast support through VLC 3+.
        // Totally unstable, unusable and will suck more CPU than you can think of.
        // If you want to improve this, please talk to the guys in #videolan and
        // support them.
        //
        // Knonw problems:
        // 1. It does not work eventhough the IP is correct.
        //    -> Open vlc with the same commandline and accept the Certificate in the VLC UI.
        if ( qApp->arguments().length() > qApp->arguments().indexOf( "--chromecast-ip" ) + 1 )
        {
            QString castIP = qApp->arguments().at( qApp->arguments().indexOf( "--chromecast-ip" ) + 1 );
            QString sout( ":sout=#transcode{vcodec=none,acodec=vorb,ab=320,channels=2,samplerate=44100}:chromecast{ip=%1,mux=webm}" );
            libvlc_media_add_option( m_vlcMedia, sout.arg( castIP ).toLatin1().constData() );
        }
        else
        {
            tLog() << Q_FUNC_INFO << "Chromecast option but no IP supplied.";
        }
    }

//    setState( Stopped );
}
Пример #16
0
bool VlcVideoWidget::OpenSource(const QString &videoUrl) 
{
    if (!Initialized())
        return false;

    // We need to prepend file:// if this is a path on disk.
    QString source = videoUrl;
    AssetAPI::AssetRefType sourceType = AssetAPI::ParseAssetRef(source);
    if ((sourceType == AssetAPI::AssetRefLocalPath || sourceType == AssetAPI::AssetRefLocalUrl))
    {
        if (source.startsWith("file://", Qt::CaseInsensitive))
            source = source.mid(7);
        vlcMedia_ = libvlc_media_new_path(vlcInstance_, source.toUtf8().constData());
    }
    else
        vlcMedia_ = libvlc_media_new_location(vlcInstance_, source.toUtf8().constData());

    if (vlcMedia_ == 0)
    {
        LogError("VlcVideoWidget: Could not load media from '" + videoUrl + "'");
        return false;
    }

    libvlc_event_manager_t *em = libvlc_media_event_manager(vlcMedia_);
    libvlc_event_attach(em, libvlc_MediaMetaChanged, &VlcEventHandler, this);
    libvlc_event_attach(em, libvlc_MediaSubItemAdded, &VlcEventHandler, this);
    libvlc_event_attach(em, libvlc_MediaDurationChanged, &VlcEventHandler, this);
    libvlc_event_attach(em, libvlc_MediaParsedChanged, &VlcEventHandler, this);
    libvlc_event_attach(em, libvlc_MediaFreed, &VlcEventHandler, this);
    libvlc_event_attach(em, libvlc_MediaStateChanged, &VlcEventHandler, this);

    libvlc_state_t state = libvlc_media_get_state(vlcMedia_);

    if (state != libvlc_Error)
    {
        // Reset playback
        Stop();
        hasVideoOut_ = false;

        libvlc_media_player_set_media(vlcPlayer_, vlcMedia_);      

        statusAccess.lock();
        status.Reset();
        status.source = videoUrl;
        status.change = PlayerStatus::MediaSource;
        statusAccess.unlock();

        return true;
    }
    else
    {
        std::string err = "Unknown error";
        if (libvlc_errmsg())
        {
            err = libvlc_errmsg();
            libvlc_clearerr();
        }
        LogError("VlcVideoWidget: " + err);
    }
    return false;
}