libVLC + xcb - simple video player

This forum is about all development around libVLC.
LukeCodeBaker
New Cone
New Cone
Posts: 1
Joined: 07 May 2015 13:33

libVLC + xcb - simple video player

Postby LukeCodeBaker » 07 May 2015 13:44

Hi, I'd like to present a simple video player using xcb. Documentation site: https://wiki.videolan.org/LibVLC/ contains multiple implementations using different libraries.
Here is another one for someone who want to use xcb.

BTW
I found that libvlc embedded media player uses xcb ( modules/video_output/xcb/window.c ) but libvlc_media_player.h exposes only few functions for window manipulation. Using native xcb you can do almost everything.

The quality of the code is not brilliant but it's a good entry point for further coding.

Code: Select all

#include <string> #include <vlc/vlc.h> #include <xcb/xcb.h> // link -lvlc, -lX11, -lxcb int main( int argc, char** argv) { // XCB xcb_connection_t *connection = xcb_connect (NULL, NULL); const xcb_setup_t *setup = xcb_get_setup (connection); xcb_screen_iterator_t iter = xcb_setup_roots_iterator (setup); xcb_screen_t *screen = iter.data; // Create Window xcb_window_t xcb_window = xcb_generate_id (connection); xcb_create_window (connection, /* Connection */ XCB_COPY_FROM_PARENT, /* depth (same as root)*/ xcb_window, /* window Id */ screen->root, /* parent window */ 0, 0, /* x, y */ 1, 1, /* width, height */ 1, /* border_width */ XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */ screen->root_visual, /* visual */ 0, NULL ); /* masks, not used yet */ // Set window name const std::string wtitle("WindowName"); xcb_change_property (connection, XCB_PROP_MODE_REPLACE, xcb_window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, wtitle.size(), wtitle.c_str() ); // Resize window const static uint32_t values[] = { 1280, 720 }; xcb_configure_window (connection, xcb_window, XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, values); xcb_map_window (connection, xcb_window); xcb_flush (connection); // LibVLC libvlc_instance_t * inst; libvlc_media_player_t *mp; libvlc_media_t *m; inst = libvlc_new (argc, argv); m = libvlc_media_new_path (inst, "YouMovie.mp4"); mp = libvlc_media_player_new_from_media (m); libvlc_media_release (m); // attatch xcb_window to libvlc player libvlc_media_player_set_xwindow (mp, xcb_window); libvlc_media_player_play (mp); // xcb simple event loop xcb_generic_event_t* event; while((event = xcb_wait_for_event(connection))) { switch((*event).response_type & ~0x80) { case XCB_EXPOSE: break; case XCB_CLIENT_MESSAGE: { // window has been closed break; } } } // stop libvlc_media_player_stop (mp); libvlc_media_player_release (mp); libvlc_release (inst); xcb_disconnect (connection); return 0; }

Rémi Denis-Courmont
Developer
Developer
Posts: 15268
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: libVLC + xcb - simple video player

Postby Rémi Denis-Courmont » 07 May 2015 16:17

You don't need to change the window configuration. Just pass the correct size when your create the window.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 28 guests