我正在尝试使用libvlc库在我的gtk + app中运行一个流。 我测试了单独运行流并完美运行:
// gcc -o gtk_player gtk_player.c `pkg-config --libs gtk+-2.0 libvlc` `pkg~-config --cflags gtk+-2.0 libvlc`
/* License WTFPL http://sam.zoy.org/wtfpl/ */
/* Written by Vincent Schüßler */
#include <stdlib.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <vlc/vlc.h>
#include <X11/Xlib.h>
#define BORDER_WIDTH 6
void destroy(GtkWidget *widget, gpointer data);
void player_widget_on_realize(GtkWidget *widget, gpointer data);
libvlc_media_player_t *media_player;
libvlc_instance_t *vlc_inst;
GtkWidget *playpause_button;
void destroy(GtkWidget *widget, gpointer data) {
gtk_main_quit();
}
void player_widget_on_realize(GtkWidget *widget, gpointer data) {
libvlc_media_player_set_xwindow(media_player,
GDK_WINDOW_XID(gtk_widget_get_window(widget)));
}
int main( int argc, char *argv[] ) {
GtkWidget *window,
*vbox,
*menubar,
*filemenu,
*fileitem,
*filemenu_openitem,
*player_widget,
*hbuttonbox,
*stop_button;
libvlc_media_player_t *mp;
libvlc_media_t *m;
gtk_init (&argc, &argv);
// setup window
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(window), 400, 300);
g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL);
gtk_container_set_border_width (GTK_CONTAINER (window), 0);
gtk_window_set_title(GTK_WINDOW(window), "GTK+ libVLC Demo");
//setup vbox
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
//setup menu
//setup player widget
player_widget = gtk_drawing_area_new();
gtk_box_pack_start(GTK_BOX(vbox), player_widget, TRUE, TRUE, 0);
//setup controls
//playpause_button = gtk_button_new_from_stock(GTK_STOCK_MEDIA_PLAY);
//setup vlc
vlc_inst = libvlc_new(0,"NULL");
m = libvlc_media_new_location (vlc_inst, "rtsp://192.168.1.64:554/Streaming/Channels/101/?transportmode=unicast");
media_player = libvlc_media_player_new_from_media(m);
XInitThreads();
/* play the media_player */
libvlc_media_player_play (media_player);
g_signal_connect(G_OBJECT(player_widget), "realize", G_CALLBACK(player_widget_on_realize), NULL);
gtk_widget_show_all(window);
gtk_main ();
libvlc_media_player_release(media_player);
libvlc_release(vlc_inst);
return 0;
}
现在我在我的应用程序中插入此代码,但只显示一个图像,如果相机和流停止..
更新: 在我的应用程序中,我在实现绘图区域时进行回调并编写此功能:
void on_video_window_realize(GtkWidget *widget, gpointer data) {
libvlc_media_t *m;
libvlc_instance_t *vlc_inst;
vlc_inst = libvlc_new(0,NULL);
m = libvlc_media_new_location (vlc_inst, "rtsp://192.168.1.64:554/Streaming/Channels/101/?transportmode=unicast");
media_player = libvlc_media_player_new_from_media(m);
libvlc_media_player_play (media_player);
libvlc_media_player_set_xwindow(media_player, GDK_WINDOW_XID(gtk_widget_get_window(widget)));
gtk_widget_show_all(gtk_widget_get_window(widget));
}