[vlc-devel] libvcl: screen:// does not work
    Jens Kallup 
    kallup.jens at web.de
       
    Tue Sep 10 14:53:50 CEST 2019
    
    
  
Hello List Member's,
I have did some little changes.
the screen:// capture error seems to be not fired.
but the screen is not displayed in the little box.
Also, I don't get gtk drawable error.
Is there something missing?
Jens
// video.h
#pragma once
#include <glib.h>
#include <glib/gprintf.h>
#include <SDL/SDL.h>
#include <SDL/SDL_mutex.h>
#include <vlc/vlc.h>
#include <vlc/libvlc.h>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
extern libvlc_instance_t     * inst;
extern libvlc_media_t        * m   ;
extern libvlc_media_player_t * mp  ;
extern GtkWidget    * video, *vpane;
extern GMainContext * context;
extern SDL_Surface  *screen, * empty;
extern SDL_Rect      rect;
struct ctx {
     SDL_Surface *surf;
     SDL_mutex *mutex;
};
extern struct ctx ctx;
// EOF - video.h
#include <stdio.h>
#include <assert.h>
#include <math.h>
#undef HAVE_STRINGS_H
#include "fe-gtk.h"
#include "video.h"
struct ctx ctx;
#define VIDEOWIDTH  160
#define VIDEOHEIGHT 100
bool videoinit = false;
libvlc_instance_t     * inst  = NULL;
libvlc_media_t        * m     = NULL;
libvlc_media_player_t * mp    = NULL;
libvlc_media_list_t        * ml  = NULL;
libvlc_media_list_player_t * mlp = NULL;
GdkPixmap    * pixmap = NULL;
GtkWidget    * video, *vpane;
GMainContext * context;
GThread      * thread ;
SDL_Surface  * screen,* empty;
SDL_Rect       rect;
typedef void (*OnExit_ptr)(void*);
void OnExit(void*d)
{
     libvlc_media_player_stop(mp);
     libvlc_media_player_release(mp);
     libvlc_release(inst);
     SDL_DestroyMutex(ctx.mutex);
     SDL_FreeSurface(ctx.surf);
     SDL_FreeSurface(empty);
     SDL_Quit();
}
OnExit_ptr on_exit_ptr = OnExit;
static gboolean
update_process(gpointer user_data)
{
     SDL_LockMutex(ctx.mutex);
     SDL_BlitSurface(ctx.surf, NULL, screen, &rect);
     SDL_UnlockMutex(ctx.mutex);
     SDL_Flip(screen);
     SDL_Delay(10);
     SDL_BlitSurface(empty, NULL, screen, &rect);
     return G_SOURCE_REMOVE;
}
static gpointer
thread_func(gpointer user_data)
{
     GSource * source;
     rect.w = 0;
     rect.h = 0;
     source = g_idle_source_new();
     g_source_set_callback(source, update_process, NULL, NULL);
     g_source_attach(source, context);
     g_source_unref(source);
     return NULL;
}
static void *lock(void *data, void **p_pixels)
{
     struct ctx *ctx = data;
     SDL_LockMutex(ctx->mutex);
     SDL_LockSurface(ctx->surf);
     *p_pixels = ctx->surf->pixels;
     return NULL; /* picture identifier, not needed here */
}
static void unlock(void *data, void *id, void *const *p_pixels)
{
     struct ctx *ctx = data;
     /* VLC just rendered the video, but we can also render stuff */
     uint16_t *pixels = *p_pixels;
     int x, y;
     for(y = 10; y < 40; y++)
         for(x = 10; x < 40; x++)
             if(x < 13 || y < 13 || x > 36 || y > 36)
                 pixels[y * VIDEOWIDTH + x] = 0xffff;
             else
                 pixels[y * VIDEOWIDTH + x] = 0x0;
     SDL_UnlockSurface(ctx->surf);
     SDL_UnlockMutex(ctx->mutex);
     assert(id == NULL); /* picture identifier, not needed here */
}
static void display(void *data, void *id)
{
     /* VLC wants to display the video */
     (void) data;
     assert(id == NULL);
}
void init_video(GtkWidget * box)
{
     libvlc_media_t *md1;
     char const *vlc_argv[] = {
         "-vv"
     };
     int vlc_argc = sizeof(vlc_argv) / sizeof(*vlc_argv);
     int n  = 0;
     if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTTHREAD) == -1) {
         g_printf("cannot initialize SDL\n");
         return EXIT_FAILURE;
     }
     empty       = SDL_CreateRGBSurface(SDL_SWSURFACE, VIDEOWIDTH,
VIDEOHEIGHT, 32, 0, 0, 0, 0);
     ctx.surf    = SDL_CreateRGBSurface(SDL_SWSURFACE, VIDEOWIDTH,
VIDEOHEIGHT, 16, 0x001f, 0x07e0, 0xf800, 0);
     ctx.mutex   = SDL_CreateMutex();
     int options = SDL_ANYFORMAT | SDL_HWSURFACE | SDL_DOUBLEBUF;
     screen      = SDL_SetVideoMode(VIDEOWIDTH, VIDEOHEIGHT, 0, options);
     if (!screen) {
         printf("cannot set video mode\n");
         return EXIT_FAILURE;
     }
     video =
     gtk_frame_new(NULL);
gtk_frame_set_shadow_type(GTK_FRAME(video),GTK_SHADOW_ETCHED_OUT);
     gtk_container_add(GTK_CONTAINER(box),video);
     on_exit_ptr = OnExit;
            libvlc_clearerr();
     inst = libvlc_new(vlc_argc,vlc_argv);
            libvlc_set_exit_handler(inst,on_exit_ptr,NULL);
     ml   = libvlc_media_list_new        (inst);
     md1  = libvlc_media_new_location    (inst,"screen://");
            libvlc_media_list_add_media  (ml,md1);
            libvlc_media_release(md1);
     mlp  = libvlc_media_list_player_new (inst);
     mp   = libvlc_media_player_new      (inst);
     libvlc_media_list_player_set_media_list  (mlp, ml);
     libvlc_media_list_player_set_media_player(mlp, mp);
     libvlc_video_set_callbacks(mp, lock, unlock, display, &ctx);
     libvlc_video_set_format   (mp, "RV16", VIDEOWIDTH, VIDEOHEIGHT,
VIDEOWIDTH*2);
     gtk_widget_realize(video);
     gtk_widget_show(video);
     pixmap = gdk_pixmap_new(video->window,VIDEOWIDTH, VIDEOHEIGHT,16);
     libvlc_media_player_set_xwindow (mp,GDK_WINDOW_XID(pixmap));
     context = g_main_context_default();
     thread  = g_thread_new(NULL, thread_func, GINT_TO_POINTER(n));
     libvlc_media_player_play(mp);
}
[0000564a8d847c00] main libvlc debug: VLC media player - 4.0.0-dev Otto
Chriek
[0000564a8d847c00] main libvlc debug: Copyright © 1996-2018 the VideoLAN
team
[0000564a8d847c00] main libvlc debug: revision 4.0.0-dev-4567-g92c146a
[0000564a8d847c00] main libvlc debug: configured with ./configure
'--disable-lua' '--disable-xcb'
[0000564a8d847c00] main libvlc debug: searching plug-in modules
[0000564a8d847c00] main libvlc debug: loading plugins cache file
/usr/local/lib/vlc/plugins/plugins.dat
[0000564a8d847c00] main libvlc debug: recursively browsing
`/usr/local/lib/vlc/plugins'
[0000564a8d847c00] main libvlc debug: plug-ins loaded: 394 modules
[0000564a8d847f10] main logger debug: looking for logger module matching
"any": 3 candidates
[0000564a8d847f10] main logger debug: using logger module "console"
[0000564a8d847c00] main libvlc debug: translation test: code is "de"
[0000564a8dcbcf10] main keystore debug: looking for keystore module
matching "memory": 3 candidates
[0000564a8dcbcf10] main keystore debug: using keystore module "memory"
[0000564a8d847c00] main libvlc debug: CPU has capabilities MMX MMXEXT
SSE SSE2 SSE3 SSSE3 FPU
[0000564a8dc9d390] main generic debug: creating audio output
[0000564a8dcbc0a0] main audio output debug: looking for audio output
module matching "any": 5 candidates
[0000564a8dcbc0a0] vlcpulse audio output debug: using library version 4.0.0
[0000564a8dcbc0a0] vlcpulse audio output debug:  (compiled with version
4.0.0, protocol 28)
[0000564a8dcbc0a0] vlcpulse audio output debug: connected locally to
unix:/run/user/1006/pulse/native as client #78
[0000564a8dcbc0a0] vlcpulse audio output debug: using protocol 28,
server protocol 28
[0000564a8dcbc0a0] pulse audio output debug: adding sink 0:
alsa_output.pci-0000_20_00.1.hdmi-stereo (RV620 HDMI Audio [Radeon HD
3400 Series] Digital Stereo (HDMI))
[0000564a8dcbc0a0] main audio output debug: using audio output module
"pulse"
[0000564a8dc9d390] main generic debug: keeping audio output
[0000564a8dca4620] main generic debug: creating audio output
[0000564a8dc1f1a0] main audio output debug: looking for audio output
module matching "any": 5 candidates
[0000564a8dc1f1a0] vlcpulse audio output debug: using library version 4.0.0
[0000564a8dc1f1a0] vlcpulse audio output debug:  (compiled with version
4.0.0, protocol 28)
[0000564a8dc1f1a0] vlcpulse audio output debug: connected locally to
unix:/run/user/1006/pulse/native as client #79
[0000564a8dc1f1a0] vlcpulse audio output debug: using protocol 28,
server protocol 28
[0000564a8dc1f1a0] pulse audio output debug: adding sink 0:
alsa_output.pci-0000_20_00.1.hdmi-stereo (RV620 HDMI Audio [Radeon HD
3400 Series] Digital Stereo (HDMI))
[0000564a8dc1f1a0] main audio output debug: using audio output module
"pulse"
[0000564a8dca4620] main generic debug: keeping audio output
[0000564a8dcbc0a0] main audio output debug: removing module "pulse"
Jens
    
    
More information about the vlc-devel
mailing list