Exemplo n.º 1
0
int wmain(int argc, wchar_t **argv) {
   // having these declarations at the start of the function is only needed for C compatibility
   int i;
   int soutBufferSize;
   int nr;
   char **vlc_argv; 
   wchar_t *soutOption; 
   wchar_t *config; 
   wchar_t *path; 
   libvlc_instance_t *vlc;
   libvlc_media_t *media;
   libvlc_media_player_t *player;
   libvlc_event_manager_t *eventManager;

   // init arguments
   if(argc < 3) {
      fwprintf(stdout, ENDLN(L"Usage: vlcwrapper <input> <soutstring> [optional vlc arguments]"));
      return 1;
   }

	// print some information
	path = argv[1];
   config = argv[2];
   fwprintf(stdout, ENDLN(L"I VLCWrapper version %s, using VLC %hs"), VERSION, libvlc_get_version());
   fwprintf(stdout, ENDLN(L"A path %s"), path);
   fwprintf(stdout, ENDLN(L"A config %s"), config);
   
   // init state machine  
   global_state = STATE_NULL;

   // arguments (you shouldn't need these in normal usage; but we don't support all arguments by ourself yet)
   nr = argc - 3;
   vlc_argv = (char**)malloc(nr * sizeof(char*));
   for(i = 3; i < argc; i++) {
      fwprintf(stdout, ENDLN(L"A cmd %d %s"), i - 3, argv[i]);
	  vlc_argv[i - 3] = to_utf8(argv[i]);
   }

   // init vlc
   vlc = libvlc_new(nr, vlc_argv);
   libvlc_set_user_agent(vlc, to_utf8(USER_AGENT), to_utf8(HTTP_USER_AGENT));
   
   // create media and set sout string
   media = libvlc_media_new_path(vlc, to_utf8(path));
   soutBufferSize = wcslen(config) + 6;
   soutOption = (wchar_t*)malloc(soutBufferSize * sizeof(wchar_t));
   snwprintf(soutOption, soutBufferSize, soutBufferSize, L"sout=%s", config);
   libvlc_media_add_option(media, to_utf8(soutOption));
   
   // create player and listen for events
   player = libvlc_media_player_new_from_media(media);
   eventManager = libvlc_media_player_event_manager(player);
   register_event(eventManager, libvlc_MediaPlayerPlaying, STATE_PLAYING);
   register_event(eventManager, libvlc_MediaPlayerEncounteredError, STATE_ERROR);
   register_event(eventManager, libvlc_MediaPlayerEndReached, STATE_FINISHED);
   
   // start playing it
   libvlc_media_player_play(player);
   
   // wait till it's started or stopped because of an error
   while(global_state != STATE_ERROR && global_state != STATE_PLAYING)
      millisleep(100);

   // let it play till it has finished, while printing status information
   while(global_state == STATE_PLAYING) {
      fwprintf(stdout, ENDLN(L"P %d"), libvlc_media_player_get_time(player));
      fflush(stdout);
      millisleep(LOG_INTERVAL);
   }
   
   // stop playing
   libvlc_media_player_stop(player);
   
   // release objects in memory
   libvlc_media_release(media);
   libvlc_media_player_release(player);
   libvlc_release(vlc);
   return 0;
}
Exemplo n.º 2
0
void VideoSource::UpdateSettings()
{
    
    EnterCriticalSection(&textureLock);
    isRendering = false;
    LeaveCriticalSection(&textureLock);

    if (mediaPlayer) {
        libvlc_video_set_callbacks(mediaPlayer, nullptr, nullptr, nullptr, nullptr);
        libvlc_media_player_stop(mediaPlayer);
    }
    
    config->Reload();

    hasSetVolume = false;

    videoSize.x = float(config->width);
    videoSize.y = float(config->height);

    if (mediaPlayer == nullptr) {
        mediaPlayer = libvlc_media_player_new(vlc);
        libvlc_event_manager_t *em = libvlc_media_player_event_manager(mediaPlayer);
        libvlc_event_attach(em, libvlc_MediaPlayerEndReached, vlcEvent, this);
        libvlc_event_attach(em, libvlc_MediaPlayerPlaying, vlcEvent, this);
    }

    if (mediaListPlayer == nullptr) {
        mediaListPlayer = libvlc_media_list_player_new(vlc);
        libvlc_media_list_player_set_media_player(mediaListPlayer, mediaPlayer);
    } else {
        libvlc_media_list_player_stop(mediaListPlayer);
    }

    if (mediaList) {
        libvlc_media_list_lock(mediaList);
        while(libvlc_media_list_count(mediaList)) {
            libvlc_media_list_remove_index(mediaList, 0);
        }
        libvlc_media_list_unlock(mediaList);
    } else {
        mediaList = libvlc_media_list_new(vlc);
        libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList);
    }

    

    char *utf8PathOrUrl;
    for(unsigned int i = 0; i < config->playlist.Num(); i++) {
        String &mediaEntry = config->playlist[i];
        String token = mediaEntry.GetToken(1, L':');
     
        // .. Yup.
        bool isStream = token.Length() >= 2 && token[0] == L'/' && token[1] == L'/';
        utf8PathOrUrl = config->playlist[i].CreateUTF8String();
        if (utf8PathOrUrl) {
            libvlc_media_t *media;
            if (!isStream) {
                media = libvlc_media_new_path(vlc, utf8PathOrUrl);
            } else {
                media = libvlc_media_new_location(vlc, utf8PathOrUrl);
            }
            
            libvlc_media_list_lock(mediaList);
            libvlc_media_list_add_media(mediaList, media);
            libvlc_media_list_unlock(mediaList);

            libvlc_media_release(media);
            Free(utf8PathOrUrl);
        }
    }

    if (!config->isPlaylistLooping) {
        remainingVideos = config->playlist.Num();
    }

    libvlc_video_set_callbacks(mediaPlayer, lock, unlock, display, this);
    libvlc_video_set_format_callbacks(mediaPlayer, videoFormatProxy, videoCleanupProxy);

    libvlc_media_list_player_set_playback_mode(mediaListPlayer, config->isPlaylistLooping ? libvlc_playback_mode_loop : libvlc_playback_mode_default);
    

    if (!audioOutputStreamHandler) {
        audioOutputStreamHandler = new AudioOutputStreamHandler(vlc, mediaPlayer);
    }

    audioOutputStreamHandler->SetOutputParameters(
        config->audioOutputType, 
        config->audioOutputTypeDevice,
        config->audioOutputDevice, 
        config->isAudioOutputToStream);
    
    audioOutputStreamHandler->SetVolume(config->volume);
    
    // set (possibly in vane) the volume.  If it doesn't work it will try later until it works
    // vlc... que pasa amigo
    hasSetVolume = libvlc_audio_set_volume(mediaPlayer, config->volume) == 0;
    
    EnterCriticalSection(&textureLock);
    isRendering = true;
    LeaveCriticalSection(&textureLock);

    libvlc_media_list_player_play(mediaListPlayer);
    
}
Exemplo n.º 3
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 );
}
bool VLCVideoTextureObjChunk::createVLCInstance(libvlc_time_t start_time, 
                                                bool          play      )
{
    libvlc_media_t *m;
    
    char const *vlc_argv[] =
    {       
        "-I", "dumy",      // No special interface
        "--ignore-config", // Don't use VLC's config        
        "--quiet",         // deactivates VLCs console outputs
        "--no-xlib",       // tell VLC to not use Xlib                   
        "--no-video-title-show", // no titles
    };
        
    int vlc_argc        = sizeof(vlc_argv       ) / sizeof(*vlc_argv       );
         
    // Initialize libVLC   
    if (libvlc==NULL) 
    {        
        libvlc = libvlc_new(vlc_argc, vlc_argv);        
    } 
    else 
    {
        if (vlcmediaplayer!=NULL) 
        {
            ctx.idstr = NULL;
            libvlc_media_player_stop(vlcmediaplayer);    
            libvlc_media_player_release(vlcmediaplayer);
            vlcmediaplayer = NULL;
            if (ctx.videothread!=NULL) {
                ctx.videothread->runFunction(NULL,NULL); // reset thread structure: isInititialized=false
            }
            ctx.videothread = NULL;            
        }
    }
    m = libvlc_media_new_path(libvlc, getUrl().c_str());
   
    vlcmediaplayer = libvlc_media_player_new_from_media(m);
   
    libvlc_media_release(m);

    ctx.idstr = strdup((std::string("video")+getVideoID()).c_str());
    ctx.videothread = NULL;            
    ctx.img = Image::create();
    ctx.img->set(OSG::Image::OSG_BGR_PF,getWidth(), getHeight());
    ctx.lock = Lock::create();
    
    this->setImage(ctx.img);
    this->setTarget(GL_TEXTURE_2D);
    ctx.self = this;


    vlceventmgr = libvlc_media_player_event_manager( vlcmediaplayer );
    // attach event to defined event handler callback
    libvlc_event_attach( vlceventmgr, libvlc_MediaPlayerEndReached, vlc_event, &ctx);

    libvlc_video_set_callbacks(vlcmediaplayer, vlc_lock, vlc_unlock, vlc_display, &ctx);
    libvlc_video_set_format(vlcmediaplayer, "RV24", getWidth(), getHeight(), getWidth()*3);
    if (getIsMaster()==false) libvlc_audio_set_mute(vlcmediaplayer, 1);
    
#if 0
    {
        SLOG << "available filters:" << std::endl;
        libvlc_module_description_t *list = libvlc_video_filter_list_get(libvlc);
        libvlc_module_description_t *iter = list;
        while(iter!=NULL) {
            SLOG << iter->psz_name << std::endl;
            iter = iter->p_next;
        }                
        libvlc_module_description_list_release(list);
    }
#endif
        

    libvlc_media_player_play(vlcmediaplayer);
    libvlc_media_player_set_time(vlcmediaplayer, start_time);
    if (!play) libvlc_media_player_pause(vlcmediaplayer); //not working?
    
    // add to static list
    //allVideoTextures.push_back(&ctx);

    lastSync=OSG::getTimeStamp();

    return true;
}
Exemplo n.º 5
0
int main(int argc, char* argv[]){
	FILE *f;
	FILE *p;
	FILE *r;
	f = fopen("/home/michal/pass2.txt", "rw+");
	p = fopen("krypt.txt", "rw+");
	r = fopen("conf.txt", "rw+");	
	char done[100];	
	char check[100];
	char pass[100];
	char decode[100] = "./test 0";
	char code[100] = "./test 1";
	int t;
	if(argc < 3){
	perror("Zła liczba argumentów");
	return 0;
	}
	while(!feof(f)){
		fscanf(f, "%s", check);
	}
	fscanf(p, "%s", done);
	if(strcmp("1", done) != 0){
	printf("Konfirgurowanie\n");
	fprintf(r, "/home/michal/key.txt\n");
	fprintf(r, "/home/michal/key2.txt\n");
	fprintf(r, "/home/michal/iv.txt\n");
	fprintf(r, "/home/michal/pass.txt\n");
	fprintf(r, "/home/michal/pass2.txt\n");
	fclose(r);
	printf("Zabezpiecz sciezki\n");
	system("./test 1 conf.txt /home/michal/key2.txt /home/michal/iv.txt");
	fprintf(p, "1");
	printf("Uruchom ponownie program, aby dokończyc proces...\n");
	fclose(p);
	return 0;
	}
	strcat(decode, " ");
	strcat(decode, argv[1]);
	strcat(decode, " /home/michal/key.txt");
	strcat(decode, " /home/michal/iv.txt");
	strcat(code, " ");
	strcat(code, argv[1]);
	strcat(code, " /home/michal/key.txt");
	strcat(code, " /home/michal/iv.txt");
	printf("To execute program type password: "******"%s", pass);
	tcsetattr(STDIN_FILENO, TCSANOW, &term_orig);
	//Rozkodowywanie i odtworzenie pliku
	if(strcmp(pass, check) == 0){
	printf("OK\n");	
	printf("Type password to decode mp3\n");
	system(decode);
	libvlc_instance_t *inst;
	libvlc_media_player_t *mp;
	libvlc_media_t *m;

	inst = libvlc_new(0, NULL);
	m = libvlc_media_new_path(inst, argv[1]);
	printf("%d", t);
	mp = libvlc_media_player_new_from_media(m);
	libvlc_media_player_play(mp);
	sleep(atoi(argv[2]));
	
	libvlc_media_player_stop(mp);
	libvlc_media_release(m);
	libvlc_media_player_release(mp);
	libvlc_release(inst);
	//Ponownie szyfrujemy plik.
	printf("Type password to encode mp3\n");
	system(code);
	}
	else{
		printf("bledne haslo\n"); return 0;
	}
	fclose(f);
	return 0;
}
Exemplo n.º 6
0
/**
 * Thumbnailer main function.
 * return null if the thumbail generation failed.
 **/
jbyteArray Java_org_videolan_libvlc_LibVLC_getThumbnail(JNIEnv *env, jobject thiz,
                                                        jlong instance, jstring filePath,
                                                        const jint frameWidth, const jint frameHeight)
{
    libvlc_instance_t *libvlc = (libvlc_instance_t *)(intptr_t)instance;
    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(libvlc);

    libvlc_media_t *m = new_media(instance, env, thiz, filePath, true, false);
    if (m == NULL)
    {
        LOGE("Could not create the media to play!");
        goto end;
    }

    /* Fast and no options */
    libvlc_media_add_option( m, ":no-audio" );
    libvlc_media_add_option( m, ":no-spu" );
    libvlc_media_add_option( m, ":no-osd" );

    libvlc_media_player_set_media(mp, m);

    /* Get the size of the video with the tracks information of the media. */
    libvlc_media_track_t **tracks;
    libvlc_media_parse(m);
    int nbTracks = libvlc_media_tracks_get(m, &tracks);
    libvlc_media_release(m);

    /* Parse the results */
    unsigned videoWidth = 0, videoHeight = 0;
    bool hasVideoTrack = false;
    for (unsigned i = 0; i < nbTracks; ++i)
        if (tracks[i]->i_type == libvlc_track_video)
        {
            videoWidth = tracks[i]->video->i_width;
            videoHeight = tracks[i]->video->i_height;
            hasVideoTrack = true;
            break;
        }

    libvlc_media_tracks_release(tracks, nbTracks);

    /* Abort if we have not found a video track. */
    if (!hasVideoTrack)
    {
        LOGE("Could not find any video track in this file.\n");
        goto end;
    }

    LOGD("Video dimensions: %ix%i.\n", videoWidth, videoHeight );

    /* VLC could not tell us the size */
    if( videoWidth == 0 || videoHeight == 0 )
    {
        LOGE("Could not find the video dimensions.\n");
        goto end;
    }

    if( videoWidth < 32 || videoHeight < 32 || videoWidth > 2048 || videoWidth > 2048 )
    {
        LOGE("Wrong video dimensions.\n");
        goto end;
    }

    /* Compute the size parameters of the frame to generate. */
    unsigned thumbWidth  = frameWidth;
    unsigned thumbHeight = frameHeight;
    const float inputAR = (float)videoWidth / videoHeight;
    const float screenAR = (float)frameWidth / frameHeight;

    /* Most of the cases, video is wider than tall */
    if (screenAR < inputAR)
    {
        thumbHeight = (float)frameWidth / inputAR + 1;
        sys->blackBorders = ( (frameHeight - thumbHeight) / 2 ) * frameWidth;
    }
    else
    {
        LOGD("Weird aspect Ratio.\n");
        thumbWidth = (float)frameHeight * inputAR;
        sys->blackBorders = (frameWidth - thumbWidth) / 2;
    }

    sys->thumbPitch  = thumbWidth * PIXEL_SIZE;
    sys->thumbHeight = thumbHeight;
    sys->frameWidth  = frameWidth;

    /* Allocate the memory to store the frames. */
    size_t thumbSize = sys->thumbPitch * (sys->thumbHeight+1);
    sys->thumbData = malloc(thumbSize);
    if (sys->thumbData == NULL)
    {
        LOGE("Could not allocate the memory to store the frame!");
        goto end;
    }

    /* Allocate the memory to store the thumbnail. */
    unsigned frameSize = frameWidth * frameHeight * PIXEL_SIZE;
    sys->frameData = calloc(frameSize, 1);
    if (sys->frameData == NULL)
    {
        LOGE("Could not allocate the memory to store the thumbnail!");
        goto end;
    }

    /* Set the video format and the callbacks. */
    libvlc_video_set_format(mp, "RGBA", thumbWidth, thumbHeight, sys->thumbPitch);
    libvlc_video_set_callbacks(mp, thumbnailer_lock, thumbnailer_unlock,
                               NULL, (void*)sys);
    sys->state = THUMB_SEEKING;

    /* Play the media. */
    libvlc_media_player_play(mp);
    libvlc_media_player_set_position(mp, THUMBNAIL_POSITION);

    int loops = 100;
    for (;;) {
        float pos = libvlc_media_player_get_position(mp);
        if (pos > THUMBNAIL_POSITION || !loops--)
            break;
        usleep(50000);
    }

    /* Wait for the thumbnail to be generated. */
    pthread_mutex_lock(&sys->doneMutex);
    sys->state = THUMB_SEEKED;
    struct timespec deadline;
    clock_gettime(CLOCK_REALTIME, &deadline);
    deadline.tv_sec += 10; /* amount of seconds before we abort thumbnailer */
    do {
        int ret = pthread_cond_timedwait(&sys->doneCondVar, &sys->doneMutex, &deadline);
        if (ret == ETIMEDOUT)
            break;
    } while (sys->state != THUMB_DONE);
    pthread_mutex_unlock(&sys->doneMutex);

    /* Stop and release the media player. */
    libvlc_media_player_stop(mp);
    libvlc_media_player_release(mp);

    if (sys->state == THUMB_DONE) {
        /* Create the Java byte array to return the create thumbnail. */
        byteArray = (*env)->NewByteArray(env, frameSize);
        if (byteArray == NULL)
        {
            LOGE("Could not allocate the Java byte array to store the frame!");
            goto end;
        }

        (*env)->SetByteArrayRegion(env, byteArray, 0, 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;
}
Exemplo n.º 7
0
void MainWindow::gameIsLoaded()
{
    if(vlcPlayer!=NULL)
        libvlc_media_player_stop(vlcPlayer);
}
Exemplo n.º 8
0
JNIEXPORT void JNICALL NAME(nativeStop)(JNIEnv *env, jobject thiz) {
    libvlc_media_player_t *mp = (libvlc_media_player_t *) getIntValue(env, thiz, "mLibVlcMediaPlayer");
    libvlc_media_player_stop(mp);
}
Exemplo n.º 9
0
/**
 * Thumbnailer main function.
 * return null if the thumbail generation failed.
 **/
jbyteArray Java_org_videolan_vlc_android_LibVLC_getThumbnail(JNIEnv *env, jobject thiz,
                                                             jint instance, jstring filePath,
                                                             jint width, jint height)
{
    libvlc_instance_t *libvlc = (libvlc_instance_t *)instance;
    jbyteArray byteArray = NULL;

    /* Create the thumbnailer data structure */
    thumbnailer_sys_t *sys = calloc(1, sizeof(thumbnailer_sys_t));
    if (sys == NULL)
    {
        LOGE("Couldn't 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 */
    sys->mp = libvlc_media_player_new(libvlc);

    libvlc_media_t *m = new_media(instance, env, thiz, filePath);
    if (m == NULL)
    {
        LOGE("Couldn't create the media to play!");
        goto end;
    }
    libvlc_media_add_option( m, ":no-audio" );

    libvlc_media_player_set_media(sys->mp, m);
    libvlc_media_release(m);

    /* Get the size of the video with the tracks information of the media. */
    libvlc_media_track_info_t *tracks;
    libvlc_media_parse(m);
    int nbTracks = libvlc_media_get_tracks_info(m, &tracks);

    unsigned i, videoWidth, videoHeight;
    bool hasVideoTrack = false;
    for (i = 0; i < nbTracks; ++i)
        if (tracks[i].i_type == libvlc_track_video)
        {
            videoWidth = tracks[i].u.video.i_width;
            videoHeight = tracks[i].u.video.i_height;
            hasVideoTrack = true;
            break;
        }

    free(tracks);

    /* Abord if we have not found a video track. */
    if (!hasVideoTrack)
    {
        LOGE("Could not find a video track in this file.\n");
        goto end;
    }

    /* Compute the size parameters of the frame to generate. */
    unsigned picWidth  = width;
    unsigned picHeight = height;
    float videoAR = (float)videoWidth / videoHeight;
    if (videoAR < ((float)width / height))
    {
        picHeight /= videoAR;
        sys->thumbnailOffset = (picHeight - height) / 2 * sys->picPitch;
    }
    else
    {
        picWidth *= videoAR;
        sys->thumbnailOffset = (picWidth - width) / 2 * PIXEL_SIZE;
    }

    sys->picPitch = picWidth * PIXEL_SIZE;
    sys->lineSize = width * PIXEL_SIZE;
    sys->nbLines = height;

    /* Allocate the memory to store the frames. */
    unsigned picSize = sys->picPitch * picHeight;
    sys->frameData = malloc(picSize);
    if (sys->frameData == NULL)
    {
        LOGE("Couldn't allocate the memory to store the frame!");
        goto end;
    }

    /* Allocate the memory to store the thumbnail. */
    unsigned thumbnailSize = width * height * PIXEL_SIZE;
    sys->thumbnail = malloc(thumbnailSize);
    if (sys->thumbnail == NULL)
    {
        LOGE("Couldn't allocate the memory to store the thumbnail!");
        goto end;
    }

    /* Set the video format and the callbacks. */
    libvlc_video_set_format(sys->mp, "RGBA", picWidth, picHeight, sys->picPitch);
    libvlc_video_set_callbacks(sys->mp, thumbnailer_lock, thumbnailer_unlock,
                               NULL, (void*)sys);

    /* Play the media. */
    libvlc_media_player_play(sys->mp);
    libvlc_media_player_set_position(sys->mp, THUMBNAIL_POSITION);

    /* Wait for the thumbnail to be generated. */
    pthread_mutex_lock(&sys->doneMutex);
    while (!sys->hasThumb)
        pthread_cond_wait(&sys->doneCondVar, &sys->doneMutex);
    pthread_mutex_unlock(&sys->doneMutex);

    /* Stop and realease the media player. */
    libvlc_media_player_stop(sys->mp);
    libvlc_media_player_release(sys->mp);

    /* Create the Java byte array to return the create thumbnail. */
    byteArray = (*env)->NewByteArray(env, thumbnailSize);
    if (byteArray == NULL)
    {
        LOGE("Couldn't allocate the Java byte array to store the frame!");
        goto end;
    }

    (*env)->SetByteArrayRegion(env, byteArray, 0, thumbnailSize,
                                 (jbyte *)sys->thumbnail);

    (*env)->DeleteLocalRef(env, byteArray);

end:
    pthread_mutex_destroy(&sys->doneMutex);
    pthread_cond_destroy(&sys->doneCondVar);
    free(sys->thumbnail);
    free(sys->frameData);
    free(sys);

    return byteArray;
}
Exemplo n.º 10
0
void SMActionVideoVLC::stop()
{
    libvlc_media_player_stop(_mp);
    SMAction::stop();
}
Exemplo n.º 11
0
/**
 * Entry point (main func)
 */
int main(int argc, char **argv) {

    // Init SDL + OpenGL
    if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTTHREAD) == -1) {
        return -1;
    }
    SDL_SetVideoMode(W, H, 16, SDL_OPENGL);
    glewInit();
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_DEPTH_TEST);

    // Init Textures
    glGenTextures(1, &textureId);
    glBindTexture(GL_TEXTURE_2D, textureId);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glGenTextures(1, &textureId2);
    glBindTexture(GL_TEXTURE_2D, textureId2);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glGenTextures(1, &textureId3);
    glBindTexture(GL_TEXTURE_2D, textureId3);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    // Init SDL_surfaces
    sdlStruct.sdlSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, W, H, 16, 0xf800, 0x07e0, 0x001f, 0);
    sdlStruct.sdlMutex = SDL_CreateMutex();
    sdlStruct2.sdlSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, W, H, 16, 0xf800, 0x07e0, 0x001f, 0);
    sdlStruct2.sdlMutex = SDL_CreateMutex();
    sdlStruct3.sdlSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, W, H, 16, 0xf800, 0x07e0, 0x001f, 0);
    sdlStruct3.sdlMutex = SDL_CreateMutex();

    // Init LibVLC + media player
    const char *vlc_argv[] = {};
    int vlc_argc = sizeof(vlc_argv) / sizeof(*vlc_argv);
    libvlc_instance_t * libVlcInstance = libvlc_new(vlc_argc, vlc_argv);
    libvlc_media_t * media = libvlc_media_new_path(libVlcInstance, VIDEOFILE);
    libvlc_media_player_t * mediaPlayer = libvlc_media_player_new_from_media(media);
    libvlc_media_release(media);
    libvlc_release(libVlcInstance);

    libvlc_video_set_callbacks(mediaPlayer, lockfct, unlockfct, NULL, &sdlStruct);
    libvlc_video_set_format(mediaPlayer, "RV16", W, H, W*2);

    // Init LibVLC Round2
    libvlc_instance_t * libVlcInstance2 = libvlc_new(vlc_argc, vlc_argv);
    libvlc_media_t * media2 = libvlc_media_new_path(libVlcInstance2, VIDEOFILE2);
    libvlc_media_player_t * mediaPlayer2 = libvlc_media_player_new_from_media(media2);
    libvlc_media_release(media2);
    libvlc_release(libVlcInstance2);

    libvlc_video_set_callbacks(mediaPlayer2, lockfct2, unlockfct2, NULL, &sdlStruct2);
    libvlc_video_set_format(mediaPlayer2, "RV16", W, H, W*2);

    //Round 3
    libvlc_instance_t * libVlcInstance3 = libvlc_new(vlc_argc, vlc_argv);
    libvlc_media_t * media3 = libvlc_media_new_path(libVlcInstance3, VIDEOFILE3);
    libvlc_media_player_t * mediaPlayer3 = libvlc_media_player_new_from_media(media3);
    libvlc_media_release(media3);
    libvlc_release(libVlcInstance3);

    libvlc_video_set_callbacks(mediaPlayer3, lockfct3, unlockfct3, NULL, &sdlStruct3);
    libvlc_video_set_format(mediaPlayer3, "RV16", W, H, W*2);

    // Start reading the video
    libvlc_media_player_play(mediaPlayer);
    libvlc_media_player_play(mediaPlayer2);
    libvlc_media_player_play(mediaPlayer3);
    libvlc_state_t state = libvlc_media_player_get_state(mediaPlayer);

    while ((state != libvlc_Ended) && (state != libvlc_Error)) {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


        loadTexture(); // Loading the texture

        // Square
        glBegin(GL_QUADS);
        glTexCoord2d(0, 0);
        glVertex2f(-0.95, 0.00);
        glTexCoord2d(0, 1);
        glVertex2f(-0.95, 0.95);
        glTexCoord2d(1, 1);
        glVertex2f(0.00, 0.95);
        glTexCoord2d(1, 0);
        glVertex2f(0.00, 0.00);
        glEnd();

        loadTexture2();

        glBegin(GL_QUADS);
        glTexCoord2d(0, 0);
        glVertex2f(0.05, 0.00);
        glTexCoord2d(0, 1);
        glVertex2f(0.05, 0.95);
        glTexCoord2d(1, 1);
        glVertex2f(0.95, 0.95);
        glTexCoord2d(1, 0);
        glVertex2f(0.95, 0.00);
        glEnd();

        loadTexture3();

        glBegin(GL_QUADS);
        glTexCoord2d(0, 0);
        glVertex2f(-0.95, -0.95);
        glTexCoord2d(0, 1);
        glVertex2f(-0.95, -0.05);
        glTexCoord2d(1, 1);
        glVertex2f(0.00, -0.05);
        glTexCoord2d(1, 0);
        glVertex2f(0.0, -0.95);
        glEnd();

        glFlush();
        SDL_GL_SwapBuffers();
        SDL_Delay(10);
        state = libvlc_media_player_get_state(mediaPlayer);
    }

    // Frees
    libvlc_media_player_stop(mediaPlayer);
    libvlc_media_player_stop(mediaPlayer2);
    libvlc_media_player_stop(mediaPlayer3);
    libvlc_media_player_release(mediaPlayer);
    libvlc_media_player_release(mediaPlayer2);
    libvlc_media_player_release(mediaPlayer3);
    SDL_DestroyMutex(sdlStruct.sdlMutex);
    SDL_FreeSurface(sdlStruct.sdlSurface);
    SDL_DestroyMutex(sdlStruct2.sdlMutex);
    SDL_FreeSurface(sdlStruct2.sdlSurface);
    SDL_DestroyMutex(sdlStruct3.sdlMutex);
    SDL_FreeSurface(sdlStruct3.sdlSurface);

    SDL_Quit();
    return 0;
}
Exemplo n.º 12
0
int Ibex::VLCVideoPlayer::playVLCVideo(const char *fileName, Display *dpy, GLXDrawable root) {
    libvlc_instance_t *libvlc;
    libvlc_media_t *m;
    libvlc_media_player_t *mp;
    char const *vlc_argv[] = {
        //"-H"
        "--text-renderer","none"
        //"--reset-plugins-cache",
        //"--reset-config"
      //"--no-audio", // Don't play audio.
       //"--no-xlib" // Don't use Xlib.

        // Apply a video filter.
        //"--video-filter", "sepia",
        //"--sepia-intensity=200"
    };
    int vlc_argc = sizeof(vlc_argv) / sizeof(*vlc_argv);

    int done = 0, action = 0, pause = 0;
    struct context context;
    context.isStereo = 0;
    context.videoTexture = videoTexture;
    context.player = this;
    context.dpy = dpy;
    context.root = root;
    context.data = data;

    // create texture/mutex

    // If you don't have this variable set you must have plugins directory
    // with the executable or libvlc_new() will not work!
    printf("VLC_PLUGIN_PATH=%s\n", getenv("VLC_PLUGIN_PATH"));

    // Initialise libVLC.
    libvlc = libvlc_new(vlc_argc, vlc_argv);
    if(NULL == libvlc) {
        printf("LibVLC initialization failure.\n");
        return EXIT_FAILURE;
    }

    m = libvlc_media_new_path(libvlc, fileName);
    mp = libvlc_media_player_new_from_media(m);
    libvlc_media_release(m);
    pixels = new uint32_t[VIDEOWIDTH*VIDEOHEIGHT*4];
    memset(pixels, 0, sizeof(uint32_t)*VIDEOWIDTH*VIDEOHEIGHT*4);
    libvlc_video_set_callbacks(mp, vlclock, vlcunlock, vlcdisplay, &context);
    libvlc_video_set_format(mp, "RV32", VIDEOWIDTH, VIDEOHEIGHT, VIDEOWIDTH*sizeof(uint32_t));
    //libvlc_video_set_format(mp, "YUYV", VIDEOWIDTH, VIDEOHEIGHT, VIDEOWIDTH*2);
    
    if(libvlc_video_get_size(mp, 0, &width, & height) == 0) {
        VIDEOWIDTH = width;
        VIDEOHEIGHT = height;
    }
        context.mp = mp;
    
    libvlc_media_player_play(mp);
    
    // Main loop.
    while(!done) {
        action = 0;
        switch(action) {
            case 'q':
                done = 1;
                break;
            case ' ':
                printf("Pause toggle.\n");
                pause = !pause;
                break;
        }

        if(!pause) { context.n++; }

        std::this_thread::sleep_for(std::chrono::milliseconds(100));
    }

    // Stop stream and clean up libVLC.
    libvlc_media_player_stop(mp);
    libvlc_media_player_release(mp);
    libvlc_release(libvlc);

    // delete mutex/texture info

    quit(0);

    return 0;
}
Exemplo n.º 13
0
void qtVlc::stop()
{
    /* stop the media_player */
    libvlc_media_player_stop (mp);
}
Exemplo n.º 14
0
jboolean Java_org_videolan_libvlc_LibVLC_hasVideoTrack(JNIEnv *env, jobject thiz,
                                                       jstring fileLocation)
{
    /* Create a new item and assign it to the media player. */
    libvlc_media_t *p_m = new_media(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;
}
Exemplo n.º 15
0
void media_stop()
{
	if(mediaplay != NULL)
		libvlc_media_player_stop(mediaplay);
	else;
}