Esempio n. 1
0
void FBVLCVideoAPI::getVideoSize( unsigned* width, unsigned* height )
{
    FBVLCPtr plg = getPlugin();
    vlc_player& p = plg->get_player();

    vlc::media media = p.current_media();
    libvlc_media_t* libvlc_media = media.libvlc_media_t();
    if( media && !media.is_parsed() )
        media.parse();

    *width = *height = 0;
    libvlc_video_get_size( p.get_mp(), 0, width, height );

    if( media && ( !*width || !*height ) ) {
        /*FIXME: It's not absolutely correct way to detect media dimensions,
        since now will be returned dimensions of first track with not zero demensions,
        and there are no any guarantee it will be be current playing track.
        But we nothing can do with it, since there are no way to match current
        playing track and track info received from libvlc_media_get_tracks_info for now.*/
        libvlc_media_track_info_t* info;
        int infoCount = libvlc_media_get_tracks_info( libvlc_media, &info );
        for( int i = 0; i < infoCount; ++i ) {
            if( libvlc_track_video == info[i].i_type &&
                info[i].u.video.i_width &&
                info[i].u.video.i_height )
            {
                *width = info[i].u.video.i_width;
                *height = info[i].u.video.i_height;
                break;
            }
        }
        libvlc_free( info );
    }
}
Esempio n. 2
0
void QmlVlcVideo::getVideoSize( unsigned* width, unsigned* height )
{
    libvlc_media_t* media = libvlc_media_player_get_media( m_player.get_mp() );
    if( media && !libvlc_media_is_parsed( media ) )
        libvlc_media_parse( media );

    *width = *height = 0;
    libvlc_video_get_size( m_player.get_mp(), 0, width, height );

    if( media && ( !*width || !*height ) ) {
        /*FIXME: It's not absolutely correct way to detect media dimensions,
        since now will be returned dimensions of first track with not zero demensions,
        and there are no any guarantee it will be be current playing track.
        But we nothing can do with it, since there are no way to match current
        playing track and track info received from libvlc_media_get_tracks_info for now.*/
        libvlc_media_track_info_t* info;
        int infoCount = libvlc_media_get_tracks_info( media, &info );
        for( int i = 0; i < infoCount; ++i ) {
            if( libvlc_track_video == info[i].i_type &&
                info[i].u.video.i_width &&
                info[i].u.video.i_height )
            {
                *width = info[i].u.video.i_width;
                *height = info[i].u.video.i_height;
                break;
            }
        }
        libvlc_free( info );
    }
}
Esempio n. 3
0
UInt32 VLCVideoWrapper::getHeight(void) const
{
    unsigned width, height;
    libvlc_video_get_size(_MediaPlayer, 0, &width, &height);
    bool error = checkVLCError("getting height");

    return height;
}
Esempio n. 4
0
void VLCWrapperImpl::Snapshot()
{
	unsigned width = 0, height = 0;
	libvlc_video_get_size(pMediaPlayer_, 0, &width, &height);

	SYSTEMTIME curTime = { 0 };
	GetLocalTime(&curTime);

	std::ostringstream filename;
	filename << "snapshot_" 
		<< std::setfill('0')
		<< std::setw(4) << curTime.wYear
		<< std::setw(2) << curTime.wMonth
		<< std::setw(2) << curTime.wDay << '_'
		<< std::setw(2) << curTime.wHour
		<< std::setw(2) << curTime.wMinute
		<< std::setw(2) << curTime.wSecond << '_'
		<< std::setw(3) << curTime.wMilliseconds
		<< ".png";

	libvlc_video_take_snapshot(pMediaPlayer_, 0,
		filename.str().data(), 
		width, height);


	//static bool bFullScreen = false;
	//HWND hWnd = (HWND)libvlc_media_player_get_hwnd(pMediaPlayer_);
	//if (hWnd)
	//{
	//	bFullScreen = !bFullScreen;
	//	//::SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
	//	ShowWindow(hWnd, bFullScreen?SW_SHOWMAXIMIZED:SW_SHOWNORMAL);
	//}

	//libvlc_video_set_scale(pMediaPlayer_, 2.5);

	//libvlc_media_player_t *mp = pMediaPlayer_;
	//bool fs = libvlc_get_fullscreen(mp);
	//libvlc_set_fullscreen(mp, true);
	//assert(libvlc_get_fullscreen(mp));
	//libvlc_set_fullscreen(mp, false);
	//assert(!libvlc_get_fullscreen(mp));
	//libvlc_toggle_fullscreen(mp);
	//assert(libvlc_get_fullscreen(mp));
	//libvlc_toggle_fullscreen(mp);
	//assert(!libvlc_get_fullscreen(mp));
	//libvlc_set_fullscreen(mp, fs);
	//assert(libvlc_get_fullscreen(mp) == fs);

	//assert(libvlc_video_get_scale(mp) == 0.); /* default */
	//libvlc_video_set_scale(mp, 0.); /* no-op */
	//libvlc_video_set_scale(mp, 2.5);
	//assert(libvlc_video_get_scale(mp) == 2.5);
	//libvlc_video_set_scale(mp, 0.);
	//libvlc_video_set_scale(mp, 0.); /* no-op */
	//assert(libvlc_video_get_scale(mp) == 0.);
}
Esempio n. 5
0
QSize VlcVideo::size() const
{
    unsigned x = 640;
    unsigned y = 480;

    if (_vlcMediaPlayer && libvlc_media_player_has_vout(_vlcMediaPlayer)) {
        libvlc_video_get_size(_vlcMediaPlayer, 0, &x, &y);
        VlcError::errmsg();
    }

    return QSize(x, y);
}
void VlcVideoWidget::DetermineVideoSize()
{
    if (!status.sourceSize.isNull())
        return;

    uint w, h;
    if (libvlc_video_get_size(vlcPlayer_, 0, &w, &h) == 0)
    {
        status.sourceSize = QSize(w,h);        
        status.playing = false;
        status.paused = false;
        status.stopped = false;
        status.doRestart = true;
        status.doStop = true;
        status.change = PlayerStatus::MediaSize;
    }
}
Esempio n. 7
0
static void
_position_changed(struct _App *app)
{
   if (!app->opening)
     return;

   /* sending size info only once */
   int r;
   unsigned int w, h;
   r = libvlc_video_get_size(app->mp, 0, &w, &h);
   if (r < 0)
     return;
   _send_resize(app, w, h);

   /* sending audio track info */
   _send_all_track_info(app);

   /* sending meta info */
   _send_all_meta_info(app);

   libvlc_media_player_stop(app->mp);
}
Esempio n. 8
0
int Ibex::VLCVideoPlayer::playVLCVideo(const char *fileName, Display *dpy, GLXDrawable root) {
	if(mp != 0) {
		try {
			pixels = 0;
			done = true;

			// Stop stream and clean up libVLC.
			libvlc_media_player_stop(mp);
			libvlc_media_player_release(mp);
			mp = 0;
		} catch(...) {
			mp = 0;
		}
	}

    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 action = 0, pause = 0;
    context = new struct context();
    context->isStereo = isStereo;
    context->videoTexture = videoTexture;
    context->player = this;
    context->dpy = dpy;
    context->root = root;
    context->data = data;

    // create texture/mutex
    //setenv("VLC_PLUGIN_PATH", "/Applications/VLC.app/Contents/MacOS/plugins", 1);
    // 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.
	if(libvlc == 0) {
		libvlc = libvlc_new(vlc_argc, vlc_argv);
		if(NULL == libvlc) {
			printf("LibVLC initialization failure.\n");
			return EXIT_FAILURE;
		}
	}

    libvlc_media_t *m = libvlc_media_new_path(libvlc, fileName);
    mp = libvlc_media_player_new_from_media(m);
    libvlc_media_release(m);
	m = 0;

    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);
    libvlc_video_set_format_callbacks(mp,
                                           my_libvlc_video_format_cb,
                                           my_libvlc_video_cleanup_cb );

    
    if(libvlc_video_get_size(mp, 0, &width, & height) == 0) {
        VIDEOWIDTH = width;
        VIDEOHEIGHT = height;
    }
    context->mp = mp;
    
	done = false;
    libvlc_media_player_play(mp);

    // Main loop.
    while(!done) {
        action = 0;
        switch(action) {
			case 's':
				libvlc_media_player_stop(mp);
				break;
            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));
    }

    return 0;
}
Esempio n. 9
0
// VLC wants to display a video frame.
static void vlcdisplay(void *data, void *id) {
	try {
  struct context *c = (struct context*)data;
  
  unsigned int *videoTexture = c->videoTexture;
  bool isStereo = c->isStereo;
  //std::cerr << "**** display: " << videoTexture[0] << std::endl;

//setup GL context by OS
#if __APPLE__
    // TODO: probably delete this, confirm no static init and only run-once init needed before getting rid of
    //static bool init2 = false;
    //if(!init2) {
    //    init2 = true;
//        setupVideoGLContext(c->data);
    //}
#else
#ifdef WIN32
  makeCurrentGL = (void(*)())c->data;
  makeCurrentGL();
#else
 // TODO: GET RID OF THIS STATIC STUFF!  MOVE INTO INIT FUNCTION OR SOMETHING
 // Create the pixmap, where one designs the scene
  static Pixmap pix = XCreatePixmap(c->dpy, c->root, VIDEOWIDTH, VIDEOHEIGHT, vi->depth);
  static GLXPixmap px = glXCreateGLXPixmap(c->dpy, vi, pix);

  static GLXContext ctx = glXCreateContext(c->dpy, vi, context, GL_TRUE);
  static bool r = glXMakeCurrent(c->dpy, px, ctx);
  if(!r) {
    std::cerr << "* failed to create GL for video" << std::endl;
  }
#endif
#endif
    
  if(!c->init) {
        c->init = true;
      
#if __APPLE__
      setupVideoGLContext(c->data);
#endif
      
        c->player->createVideoTextures(c->isStereo, VIDEOWIDTH, VIDEOHEIGHT);
        c->player->width = VIDEOWIDTH;
        c->player->height = VIDEOHEIGHT;
          
        unsigned int width,height;
        if(libvlc_video_get_size(c->mp, 0, &width, & height) == 0) {
//            first = true;
          c->player->width = width;
          c->player->height = height;
            std::cerr << "***************** " << VIDEOWIDTH << "x" << VIDEOHEIGHT << " ==> " << width << "x" << height << std::endl;
//            if(VIDEOWIDTH != width && VIDEOHEIGHT != height) {
//                VIDEOWIDTH = width;
//                VIDEOHEIGHT = height;
//                libvlc_video_set_format(c->mp, "RV32", VIDEOWIDTH, VIDEOHEIGHT, VIDEOWIDTH*sizeof(uint32_t));
//                return;
//            }
        }
  }

  const GLuint width = VIDEOWIDTH;
  const GLuint height = VIDEOHEIGHT;
//  const GLuint width = c->player->width;
//  const GLuint height = c->player->height;
  if(isStereo) {
    glBindTexture(GL_TEXTURE_2D, videoTexture[1]);
//      std::cerr << width << " " << stride << std::endl;
    glPixelStorei(GL_UNPACK_ROW_LENGTH,width*2);
    glPixelStorei(GL_UNPACK_ALIGNMENT,1);
    if(first) {
      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height/2, 0,
		   GL_BGRA, IBEX_VIDEO_GL_PIX_FORMAT, pixels);
      glBindTexture(GL_TEXTURE_2D, videoTexture[0]);
      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height/2, 0,
		   GL_BGRA, IBEX_VIDEO_GL_PIX_FORMAT, &pixels[width]);
    } else {
      glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height/2,
		      GL_BGRA, IBEX_VIDEO_GL_PIX_FORMAT, pixels);
      glBindTexture(GL_TEXTURE_2D, videoTexture[0]);
      glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height/2,
		      GL_BGRA, IBEX_VIDEO_GL_PIX_FORMAT , &pixels[width]);
    }
  } else {
    glBindTexture(GL_TEXTURE_2D, videoTexture[0]);
	glPixelStorei(GL_UNPACK_ROW_LENGTH,width);
    glPixelStorei(GL_UNPACK_ALIGNMENT,1);
    if(first) {
      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
      	   GL_BGRA, IBEX_VIDEO_GL_PIX_FORMAT, pixels);
    } else {
      glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height,
		      GL_BGRA, IBEX_VIDEO_GL_PIX_FORMAT, pixels);
    }
  }
  first = false;
  glFlush();

  //struct context *c = (context *)data;
    // WIDTH/HEIGHT VIDEOWIDTH/VIDEOHEIGHT
	}catch(...) {
	}
}
Esempio n. 10
0
bool VLCVideoWrapper::open(const std::string& ThePath, Window* const TheWindow)
{
    bool errorOpening(false);

    //BoostPath PluginsDirPath("/Applications/VLC.app/Contents/MacOS/modules");
    BoostPath PluginsDirPath("/Applications/VLC-1.1.7.app/Contents/MacOS/modules");

    std::vector<std::string> VLCArguments;

    VLCArguments.push_back("-I");
    VLCArguments.push_back("dummy"); /* no interface */

    VLCArguments.push_back(std::string("--plugin-path=") + PluginsDirPath.string());

    //VLCArguments.push_back("--no-audio"); [> we don't want audio <]
    VLCArguments.push_back("--verbose=0"); /* show only errors */
    VLCArguments.push_back("--no-media-library");/* don't want that */
    VLCArguments.push_back("--services-discovery=");/* don't want that */
    VLCArguments.push_back("--no-video-title-show");/* don't want that */
    VLCArguments.push_back("--no-stats");/* don't want that */
    VLCArguments.push_back("--ignore-config"); /* don't use/overwrite the config */
    VLCArguments.push_back("--no-sub-autodetect");/* don't want subtitles */
    VLCArguments.push_back("--control=");/* don't want interface (again) */
    VLCArguments.push_back("--no-disable-screensaver");/* don't want that */

    // libvlc settings 
    const char** args = new const char*[VLCArguments.size()];
    for(UInt32 i(0) ; i<VLCArguments.size() ; ++i)
    {
        args[i] = VLCArguments[i].c_str();
    }

    /*
     *  Initialise libVLC
     */
    UInt32 nargs = VLCArguments.size();
    _VLCInstance = libvlc_new( nargs, args );
    if(_VLCInstance == NULL)
    {
        checkVLCError("creating new vlc instance");
        return false;
    }

    delete [] args;


    // creates vlc struct holding data to the video file
    libvlc_media_t *TheMedia = libvlc_media_new_path( _VLCInstance, ThePath.c_str() );
    checkVLCError("initializing media file");

    // initialize a temporary media player so we can get height and width before
    // adding the vmem options to TheMedia
    libvlc_media_player_t * tempMediaPlayer = libvlc_media_player_new_from_media( TheMedia );

    unsigned Width(200), Height(200);
    libvlc_video_set_callbacks(tempMediaPlayer,
                               lock,
                               unlock,
                               display,
                               &_VideoMemContext);

    _VideoMemContext._pixels = ( UInt8* )malloc( ( sizeof( *( _VideoMemContext._pixels ) )
                                                   * Width
                                                   * Height ) * 4 );

    libvlc_video_set_format(tempMediaPlayer,
                            "RV24",
                            Width,
                            Height,
                            Width * 3);

    //Release the media file
    libvlc_media_release( TheMedia );

    libvlc_media_player_play( tempMediaPlayer );
    checkVLCError("playing the media");

    libvlc_state_t currentState;
    do
    {
        currentState = libvlc_media_player_get_state(tempMediaPlayer);
        checkVLCError("getting state");
    } while(currentState != libvlc_Playing);

    int VLCResult;
    do
    {
        VLCResult = libvlc_video_get_size(tempMediaPlayer, 0, &Width, &Height);
    } while(VLCResult != 0);
    checkVLCError("getting size");
    libvlc_media_player_stop( tempMediaPlayer );
    libvlc_media_player_release(tempMediaPlayer);// releases media currently in use


    //Now that we have the size initialize the media again
    TheMedia = libvlc_media_new_path( _VLCInstance, ThePath.c_str() );
    checkVLCError("initializing media file");

    // initialize the media player
    _MediaPlayer = libvlc_media_player_new_from_media( TheMedia );
    checkVLCError("initializing media player");

    //Release the media file
    libvlc_media_release( TheMedia );

#ifdef __APPLE__
    //set agl handle (if TheWindow is pointing to a carbon window)
    if (TheWindow->getType().isDerivedFrom(CarbonWindow::getClassType()))
    {
        HIWindowRef windowRef = aglGetWindowRef(dynamic_cast<CarbonWindow* const>(TheWindow)->getContext());

        HIViewRef contentView = 0;
        GetRootControl(windowRef, &contentView);


        //uint32_t aglHandler = CarbonWindowPtr::dcast(TheWindow)->winId();
        libvlc_media_player_set_agl (_MediaPlayer, reinterpret_cast<uint32_t>(contentView) );
        checkVLCError("attaching media player to carbon window");
    }
#endif
#ifdef WIN32
    if (TheWindow->getType().isDerivedFrom(WIN32Window::getClassType()))
    {
        libvlc_media_player_set_hwnd (_MediaPlayer, dynamic_cast<WIN32Window* const>(TheWindow)->getHwnd() );
        checkVLCError("attaching media player to WIN32 window");
    }
#endif
#ifdef __linux
    if (TheWindow->getType().isDerivedFrom(XWindow::getClassType()))
    {
        libvlc_media_player_set_xwindow (_MediaPlayer, dynamic_cast<XWindow* const>(TheWindow)->getDisplay() );
        checkVLCError("attaching media player to Xwindow");
    }
#endif

    libvlc_video_set_callbacks(_MediaPlayer,
                               lock,
                               unlock,
                               display,
                               &_VideoMemContext);

    _VideoMemContext._pixels = ( UInt8* )malloc( ( sizeof( *( _VideoMemContext._pixels ) )
                                                   * Width
                                                   * Height ) * 4 );

    libvlc_video_set_format(_MediaPlayer,
                            "RV24",
                            Width,
                            Height,
                            Width * 3);

    //Start playing the video
    libvlc_media_player_play( _MediaPlayer );
    checkVLCError("playing the media");

    do
    {
        currentState = libvlc_media_player_get_state(_MediaPlayer);
        checkVLCError("getting state");
    } while(currentState != libvlc_Playing);

    clock_t endwait;
    endwait = clock () + 2 * CLOCKS_PER_SEC ;
    while (clock() < endwait) {}



    _Initialized = true;

    // check if the player can be paused
    if(libvlc_media_player_can_pause(_MediaPlayer))
    {	// can pause it?  do it
        libvlc_media_player_pause(_MediaPlayer);
        // error checking of course
        checkVLCError("pausing media player");

        libvlc_media_player_set_position( _MediaPlayer, 0.0f );
        checkVLCError("setting position during player initialization");
    }

    return errorOpening;
}
Esempio n. 11
0
// VLC wants to display a video frame.
static void vlcdisplay(void *data, void *id) {
  struct context *c = (struct context*)data;
  unsigned int *videoTexture = c->videoTexture;
  bool isStereo = c->isStereo;
  //std::cerr << "**** display: " << videoTexture[0] << std::endl;

//setup GL context by OS
#if __APPLE__
    static bool init2 = false;
    if(!init2) {
        init2 = true;
        setupVideoGLContext(c->data);
    }
#else
#ifdef WIN32
  makeCurrentGL = (void(*)())c->data;
  makeCurrentGL();
#else
 // Create the pixmap, where one designs the scene
  static Pixmap pix = XCreatePixmap(c->dpy, c->root, VIDEOWIDTH, VIDEOHEIGHT, vi->depth);
  static GLXPixmap px = glXCreateGLXPixmap(c->dpy, vi, pix);

  static GLXContext ctx = glXCreateContext(c->dpy, vi, context, GL_TRUE);
  static bool r = glXMakeCurrent(c->dpy, px, ctx);
  if(!r) {
    std::cerr << "* failed to create GL for video" << std::endl;
  }
#endif
#endif
    
  static bool init = false;
  if(!init) {
        init = true;
      
        c->player->createVideoTextures(c->isStereo, VIDEOWIDTH, VIDEOHEIGHT);
        c->player->width = VIDEOWIDTH;
        c->player->height = VIDEOHEIGHT;
          
        unsigned int width,height;
        if(libvlc_video_get_size(c->mp, 0, &width, & height) == 0) {
          c->player->width = width;
          c->player->height = height;
            std::cerr << "***************** " << VIDEOWIDTH << "x" << VIDEOHEIGHT << " ==> " << width << "x" << height << std::endl;
        }
    
        isStereo = false;
  }

  const GLuint width = VIDEOWIDTH;
  const GLuint height = VIDEOHEIGHT;
  bool first = true;
  if(isStereo) {
    glBindTexture(GL_TEXTURE_2D, videoTexture[1]);
    int stride = width*2;
    glPixelStorei(GL_UNPACK_ROW_LENGTH,stride);
    if(first) {
      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height/2, 0,
		   GL_BGRA, GL_UNSIGNED_BYTE, pixels);
      glBindTexture(GL_TEXTURE_2D, videoTexture[0]);
      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height/2, 0,
		   GL_BGRA, GL_UNSIGNED_BYTE, pixels+(width*3));
    } else {
      glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height/2,
		      GL_RGB, GL_UNSIGNED_BYTE, pixels);
      glBindTexture(GL_TEXTURE_2D, videoTexture[0]);
      glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height/2,
		      GL_RGB, GL_UNSIGNED_BYTE, pixels+(width*3));
    }
  } else {
    glBindTexture(GL_TEXTURE_2D, videoTexture[0]);
    if(first) {
      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0,
      	   GL_BGRA, GL_UNSIGNED_BYTE, pixels);
    } else {
      glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height,
		      GL_BGRA, GL_UNSIGNED_BYTE, pixels);
    }
  }
  glFlush();

  //struct context *c = (context *)data;
    // WIDTH/HEIGHT VIDEOWIDTH/VIDEOHEIGHT
}