Не могу понять как сделать. мне посоветовали попробовать с playbin, и я попробую, а пока посмотрите мой код. здесь я пытаюсь создать приложение, но не появляется сообщение для dbus, которое можно было бы запросить к video overlay.
#include <gtk/gtk.h>
#include <gst/gst.h>
#include <gst/video/video.h>
GtkApplication *app;
const char *file_path = "/home/cf/Videos/The.Shadow.1994.1080p.BDRemux.AVC.DTS-HD.MA5.1.Rus.mkv";
//const char *file_path = "/home/cf/Music/01_stellarissuite_creationandbeyond.mp3";
struct widgets {
GtkWidget *window_main;
GtkWidget *box_main;
GtkWidget *area_video;
} w;
struct gstreamer {
GstElement *pipeline;
GstElement *source;
GstElement *audio_convert;
GstElement *audio_resample;
GstElement *decode_bin;
GstElement *audio_sink;
GstElement *video_sink;
GstElement *video_mixer;
GstElement *video_convert;
GstElement *vsink;
GstElement *videotest;
GstBus *bus;
GstMessage *msg;
} gst;
static void pad_added_handler ( GstElement *src, GstPad *new_pad, gpointer *data ) {
GstPad *sink_pad = gst_element_get_static_pad ( gst.audio_convert, "sink" );
gst_pad_link ( new_pad, sink_pad );
gst_object_unref ( sink_pad );
}
int ii = 0;
static void message_cb ( GstBus *bus, GstMessage *msg, gpointer data ) {
g_print ( "%d\n", ii++ );
switch ( GST_MESSAGE_TYPE ( msg ) ) {
case GST_MESSAGE_ERROR: {
GError *error = NULL;
char *debug = NULL;
gst_message_parse_error ( msg, &error, &debug );
g_print ( "error: from %s %s\n", GST_OBJECT_NAME ( msg->src ), error->message );
g_error_free ( error );
g_free ( debug );
}
break;
case GST_MESSAGE_ELEMENT: {
}
break;
case GST_MESSAGE_BUFFERING: {
g_print ( "buffering\n" );
}
break;
}
}
static GstBusSyncReply create_window ( GstBus *bus, GstMessage *msg, GstPipeline *pipeline ) {
if ( GST_MESSAGE_TYPE ( msg ) != GST_MESSAGE_ELEMENT ) return GST_BUS_PASS;
const GstStructure *s = gst_message_get_structure ( msg );
const char *name = gst_structure_get_name ( s );
g_print ( "->%s\n", name );
if ( !strncmp ( name, "prepare-xwindow-id", strlen ( name ) + 1 ) ) {
gst.vsink = gst_bin_get_by_interface ( GST_BIN ( gst.pipeline ), GST_TYPE_VIDEO_OVERLAY );
void *window = gtk_widget_get_window ( w.area_video );
gst_video_overlay_set_window_handle ( GST_VIDEO_OVERLAY ( gst.vsink ), (guintptr) window );
}else {
return GST_BUS_PASS;
}
gst_message_unref ( msg );
return GST_BUS_DROP;
}
static void init_player ( ) {
gst_init ( NULL, NULL );
gst.pipeline = gst_pipeline_new ( "editor" );
gst.source = gst_element_factory_make ( "filesrc", NULL );
gst.audio_convert = gst_element_factory_make ( "audioconvert", NULL );
gst.audio_resample = gst_element_factory_make ( "audioresample", NULL );
gst.audio_sink = gst_element_factory_make ( "autoaudiosink", NULL );
gst.video_sink = gst_element_factory_make ( "autovideosink", NULL );
gst.video_mixer = gst_element_factory_make ( "videomixer", NULL );
gst.decode_bin = gst_element_factory_make ( "decodebin", NULL );
gst.video_convert = gst_element_factory_make ( "videoconvert", NULL );
gst.videotest = gst_element_factory_make ( "videotestsrc", NULL );
gst_bin_add_many ( GST_BIN ( gst.pipeline ), gst.decode_bin, gst.source, gst.video_convert, NULL );//gst.audio_convert, gst.audio_resample, gst.audio_sink, gst.video_convert, NULL );
//gst_element_link_many ( gst.audio_convert, gst.audio_resample, gst.audio_sink, gst.video_sink, gst.video_convert, gst.videotest, NULL );
gst_element_link_many ( gst.video_sink, gst.video_convert, NULL );
gst_element_link ( gst.source, gst.decode_bin );
// gst_element_link_many ( gst.video_mixer, gst.video_sink, NULL );
g_object_set ( gst.source, "location", file_path, NULL );
gst_element_set_state(gst.pipeline, GST_STATE_READY);
g_signal_connect ( gst.decode_bin, "pad-added", G_CALLBACK ( pad_added_handler ), NULL );
gst.bus = gst_element_get_bus ( gst.pipeline );
gst_bus_set_sync_handler ( gst.bus, (GstBusSyncHandler) create_window, gst.pipeline, NULL );
gst_bus_add_signal_watch ( gst.bus );
g_signal_connect ( gst.bus, "message", G_CALLBACK ( message_cb ), NULL );
gst_element_set_state ( gst.pipeline, GST_STATE_PLAYING );
}
static void app_activate_cb ( GtkApplication *app, gpointer data ) {
w.window_main = gtk_application_window_new ( app );
gtk_window_maximize ( ( GtkWindow * ) w.window_main );
w.box_main = gtk_box_new ( GTK_ORIENTATION_VERTICAL, 0 );
gtk_container_add ( ( GtkContainer * ) w.window_main, w.box_main );
w.area_video = gtk_drawing_area_new ( );
gtk_box_pack_start ( ( GtkBox * ) w.box_main, w.area_video, TRUE, TRUE, 0 );
init_player ( );
gtk_widget_show_all ( w.window_main );
}
int main ( int argc, char **argv ) {
app = gtk_application_new ( "org.xverizex.video_editor", G_APPLICATION_FLAGS_NONE );
g_application_register ( ( GApplication * ) app, NULL, NULL );
g_signal_connect ( app, "activate", G_CALLBACK ( app_activate_cb ), NULL );
return g_application_run ( ( GApplication * ) app, argc, argv );
}