mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 04:01:08 +00:00
examples: camerabin2: add format selection for camerabin2 example
Adds a combobox for selecting the video profile for recordings. Useful for testing multiple formats a/v sync when recording.
This commit is contained in:
parent
d465188879
commit
0ef2d627be
4 changed files with 187 additions and 14 deletions
|
@ -15,6 +15,7 @@ gst_camera2_LDADD = \
|
|||
$(top_builddir)/gst-libs/gst/interfaces/libgstphotography-@GST_MAJORMINOR@.la \
|
||||
$(GST_PLUGINS_BASE_LIBS) \
|
||||
-lgstinterfaces-@GST_MAJORMINOR@ \
|
||||
-lgstpbutils-@GST_MAJORMINOR@ \
|
||||
$(GST_LIBS) \
|
||||
$(GTK_LIBS) \
|
||||
$(GMODULE_EXPORT_LIBS)
|
||||
|
|
|
@ -31,6 +31,9 @@
|
|||
|
||||
#include "gst-camera2.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <gst/pbutils/encoding-profile.h>
|
||||
#include <gst/gst.h>
|
||||
#include <gst/interfaces/xoverlay.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
@ -42,6 +45,77 @@
|
|||
static GstElement *camera;
|
||||
static GtkBuilder *builder;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const gchar *name;
|
||||
GstEncodingProfile *(*create_profile) ();
|
||||
} GstCameraVideoFormat;
|
||||
|
||||
static GstEncodingProfile *
|
||||
create_ogg_profile (void)
|
||||
{
|
||||
GstEncodingContainerProfile *container;
|
||||
|
||||
container = gst_encoding_container_profile_new ("ogg", NULL,
|
||||
gst_caps_new_simple ("application/ogg", NULL), NULL);
|
||||
|
||||
gst_encoding_container_profile_add_profile (container, (GstEncodingProfile *)
|
||||
gst_encoding_video_profile_new (gst_caps_new_simple ("video/theora",
|
||||
NULL), NULL, NULL, 1));
|
||||
gst_encoding_container_profile_add_profile (container, (GstEncodingProfile *)
|
||||
gst_encoding_audio_profile_new (gst_caps_new_simple ("audio/vorbis",
|
||||
NULL), NULL, NULL, 1));
|
||||
|
||||
return (GstEncodingProfile *) container;
|
||||
}
|
||||
|
||||
static GstEncodingProfile *
|
||||
create_webm_profile (void)
|
||||
{
|
||||
GstEncodingContainerProfile *container;
|
||||
|
||||
container = gst_encoding_container_profile_new ("webm", NULL,
|
||||
gst_caps_new_simple ("video/webm", NULL), NULL);
|
||||
|
||||
gst_encoding_container_profile_add_profile (container, (GstEncodingProfile *)
|
||||
gst_encoding_video_profile_new (gst_caps_new_simple ("video/x-vp8", NULL),
|
||||
NULL, NULL, 1));
|
||||
gst_encoding_container_profile_add_profile (container, (GstEncodingProfile *)
|
||||
gst_encoding_audio_profile_new (gst_caps_new_simple ("audio/vorbis",
|
||||
NULL), NULL, NULL, 1));
|
||||
|
||||
return (GstEncodingProfile *) container;
|
||||
}
|
||||
|
||||
static GstEncodingProfile *
|
||||
create_mp4_profile (void)
|
||||
{
|
||||
GstEncodingContainerProfile *container;
|
||||
|
||||
container = gst_encoding_container_profile_new ("mp4", NULL,
|
||||
gst_caps_new_simple ("video/quicktime", "variant", G_TYPE_STRING, "iso",
|
||||
NULL), NULL);
|
||||
|
||||
gst_encoding_container_profile_add_profile (container, (GstEncodingProfile *)
|
||||
gst_encoding_video_profile_new (gst_caps_new_simple ("video/x-h264",
|
||||
NULL), NULL, NULL, 1));
|
||||
gst_encoding_container_profile_add_profile (container, (GstEncodingProfile *)
|
||||
gst_encoding_audio_profile_new (gst_caps_new_simple ("audio/mpeg",
|
||||
"version", G_TYPE_INT, 4, NULL), NULL, NULL, 1));
|
||||
|
||||
return (GstEncodingProfile *) container;
|
||||
}
|
||||
|
||||
GstCameraVideoFormat formats[] = {
|
||||
{"ogg (theora/vorbis)", create_ogg_profile}
|
||||
,
|
||||
{"webm (vp8/vorbis)", create_webm_profile}
|
||||
,
|
||||
{"mp4 (h264+aac)", create_mp4_profile}
|
||||
,
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
void
|
||||
on_mainWindow_delete_event (GtkWidget * widget, GdkEvent * event, gpointer data)
|
||||
{
|
||||
|
@ -84,6 +158,23 @@ on_viewfinderArea_realize (GtkWidget * widget, gpointer data)
|
|||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
on_formatComboBox_changed (GtkWidget * widget, gpointer data)
|
||||
{
|
||||
GstEncodingProfile *profile = NULL;
|
||||
gint index = gtk_combo_box_get_active (GTK_COMBO_BOX (widget));
|
||||
|
||||
if (formats[index].create_profile) {
|
||||
profile = formats[index].create_profile ();
|
||||
}
|
||||
|
||||
g_return_if_fail (profile != NULL);
|
||||
gst_element_set_state (camera, GST_STATE_NULL);
|
||||
g_object_set (camera, "video-profile", profile, NULL);
|
||||
gst_element_set_state (camera, GST_STATE_PLAYING);
|
||||
gst_encoding_profile_unref (profile);
|
||||
}
|
||||
|
||||
static GstBusSyncReply
|
||||
bus_sync_callback (GstBus * bus, GstMessage * message, gpointer data)
|
||||
{
|
||||
|
@ -152,6 +243,24 @@ bus_callback (GstBus * bus, GstMessage * message, gpointer data)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
init_gtkwidgets_data (void)
|
||||
{
|
||||
gint i;
|
||||
GtkComboBoxText *combobox =
|
||||
GTK_COMBO_BOX_TEXT (gtk_builder_get_object (builder, "formatComboBox"));
|
||||
|
||||
/* init formats combobox */
|
||||
i = 0;
|
||||
while (formats[i].name) {
|
||||
gtk_combo_box_text_append_text (combobox, formats[i].name);
|
||||
i++;
|
||||
}
|
||||
|
||||
/* default to the first one -> ogg */
|
||||
gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
|
@ -176,6 +285,8 @@ main (int argc, char *argv[])
|
|||
gst_bus_set_sync_handler (bus, bus_sync_callback, NULL);
|
||||
gst_object_unref (bus);
|
||||
|
||||
init_gtkwidgets_data ();
|
||||
|
||||
ui_main_window = GTK_WIDGET (gtk_builder_get_object (builder, "mainWindow"));
|
||||
gtk_builder_connect_signals (builder, NULL);
|
||||
gtk_widget_show_all (ui_main_window);
|
||||
|
|
|
@ -45,4 +45,7 @@ on_videoRButton_toggled (GtkToggleButton * button, gpointer user_data);
|
|||
void
|
||||
on_viewfinderArea_realize (GtkWidget * widget, gpointer data);
|
||||
|
||||
void
|
||||
on_formatComboBox_changed (GtkWidget * widget, gpointer data);
|
||||
|
||||
#endif /* __GST_CAMERA_BIN_H__ */
|
||||
|
|
|
@ -1,43 +1,53 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<requires lib="gtk+" version="2.16"/>
|
||||
<!-- interface-naming-policy project-wide -->
|
||||
<object class="GtkWindow" id="mainWindow">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="default_width">800</property>
|
||||
<property name="default_height">600</property>
|
||||
<signal name="delete_event" handler="on_mainWindow_delete_event"/>
|
||||
<signal name="delete-event" handler="on_mainWindow_delete_event" swapped="no"/>
|
||||
<child>
|
||||
<object class="GtkVBox" id="vbox1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkHBox" id="hbox1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkRadioButton" id="imageRButton">
|
||||
<property name="label" translatable="yes">Image</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="active">True</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
<signal name="toggled" handler="on_imageRButton_toggled"/>
|
||||
<signal name="toggled" handler="on_imageRButton_toggled" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioButton" id="videoRButton">
|
||||
<property name="label" translatable="yes">Video</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="active">True</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
<property name="group">imageRButton</property>
|
||||
<signal name="toggled" handler="on_videoRButton_toggled"/>
|
||||
<signal name="toggled" handler="on_videoRButton_toggled" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
@ -51,39 +61,44 @@
|
|||
<child>
|
||||
<object class="GtkHBox" id="hbox2">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkDrawingArea" id="viewfinderArea">
|
||||
<property name="visible">True</property>
|
||||
<signal name="realize" handler="on_viewfinderArea_realize"/>
|
||||
<property name="can_focus">False</property>
|
||||
<signal name="realize" handler="on_viewfinderArea_realize" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkVBox" id="vbox2">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="captureButton">
|
||||
<property name="label" translatable="yes">Capture</property>
|
||||
<object class="GtkLabel" id="label4">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<signal name="clicked" handler="on_captureButton_clicked"/>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Actions</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="stopCaptureButton">
|
||||
<property name="label" translatable="yes">Stop Capture</property>
|
||||
<object class="GtkButton" id="captureButton">
|
||||
<property name="label" translatable="yes">Capture</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<signal name="clicked" handler="on_stopCaptureButton_clicked"/>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<signal name="clicked" handler="on_captureButton_clicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -91,6 +106,47 @@
|
|||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="stopCaptureButton">
|
||||
<property name="label" translatable="yes">Stop Capture</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<signal name="clicked" handler="on_stopCaptureButton_clicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label5">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Video format</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="padding">5</property>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkComboBoxText" id="formatComboBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<signal name="changed" handler="on_formatComboBox_changed" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -100,6 +156,8 @@
|
|||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
|
Loading…
Reference in a new issue