diff --git a/gst-libs/gst/video/gstbasevideocodec.c b/gst-libs/gst/video/gstbasevideocodec.c index 816e62e35b..c545b07867 100644 --- a/gst-libs/gst/video/gstbasevideocodec.c +++ b/gst-libs/gst/video/gstbasevideocodec.c @@ -152,6 +152,8 @@ gst_base_video_codec_reset (GstBaseVideoCodec * base_video_codec) gst_buffer_replace (&base_video_codec->state.codec_data, NULL); gst_caps_replace (&base_video_codec->state.caps, NULL); + memset (&base_video_codec->state, 0, sizeof (GstVideoState)); + base_video_codec->state.format = GST_VIDEO_FORMAT_UNKNOWN; GST_BASE_VIDEO_CODEC_STREAM_UNLOCK (base_video_codec); } diff --git a/gst/camerabin2/gstcamerabin2.c b/gst/camerabin2/gstcamerabin2.c index 12c52b0a24..ad22826f3b 100644 --- a/gst/camerabin2/gstcamerabin2.c +++ b/gst/camerabin2/gstcamerabin2.c @@ -1688,7 +1688,7 @@ gst_camera_bin_create_elements (GstCameraBin2 * camera) NULL); if (camera->video_profile_switch) { - GST_DEBUG_OBJECT (camera, "Switching encodebin's profile"); + GST_DEBUG_OBJECT (camera, "Switching video-encodebin's profile"); g_object_set (camera->video_encodebin, "profile", camera->video_profile, NULL); if (GST_PAD_LINK_FAILED (gst_camera_bin_link_encodebin (camera, @@ -1703,7 +1703,7 @@ gst_camera_bin_create_elements (GstCameraBin2 * camera) } if (camera->image_profile_switch) { - GST_DEBUG_OBJECT (camera, "Switching encodebin's profile"); + GST_DEBUG_OBJECT (camera, "Switching image-encodebin's profile"); g_object_set (camera->image_encodebin, "profile", camera->image_profile, NULL); if (GST_PAD_LINK_FAILED (gst_camera_bin_link_encodebin (camera, diff --git a/tests/examples/camerabin2/Makefile.am b/tests/examples/camerabin2/Makefile.am index 807a22924c..c92f95c6ec 100644 --- a/tests/examples/camerabin2/Makefile.am +++ b/tests/examples/camerabin2/Makefile.am @@ -15,7 +15,7 @@ gst_camera2_LDADD = \ $(top_builddir)/gst-libs/gst/interfaces/libgstphotography-@GST_MAJORMINOR@.la \ $(GST_PLUGINS_BASE_LIBS) \ -lgstinterfaces-@GST_MAJORMINOR@ \ - -lgstvideo-@GST_MAJORMINOR@ \ + -lgstpbutils-@GST_MAJORMINOR@ \ $(GST_LIBS) \ $(GTK_LIBS) \ $(GMODULE_EXPORT_LIBS) diff --git a/tests/examples/camerabin2/gst-camera2.c b/tests/examples/camerabin2/gst-camera2.c index c8cc8dc84a..a6610c856b 100644 --- a/tests/examples/camerabin2/gst-camera2.c +++ b/tests/examples/camerabin2/gst-camera2.c @@ -31,6 +31,9 @@ #include "gst-camera2.h" +#include + +#include #include #include #include @@ -41,6 +44,78 @@ static GstElement *camera; static GtkBuilder *builder; +static GtkWidget *ui_main_window; + +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_empty_simple ("application/ogg"), NULL); + + gst_encoding_container_profile_add_profile (container, (GstEncodingProfile *) + gst_encoding_video_profile_new (gst_caps_new_empty_simple + ("video/x-theora"), NULL, NULL, 1)); + gst_encoding_container_profile_add_profile (container, (GstEncodingProfile *) + gst_encoding_audio_profile_new (gst_caps_new_empty_simple + ("audio/x-vorbis"), 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_empty_simple ("video/webm"), NULL); + + gst_encoding_container_profile_add_profile (container, (GstEncodingProfile *) + gst_encoding_video_profile_new (gst_caps_new_empty_simple ("video/x-vp8"), + NULL, NULL, 1)); + gst_encoding_container_profile_add_profile (container, (GstEncodingProfile *) + gst_encoding_audio_profile_new (gst_caps_new_empty_simple + ("audio/x-vorbis"), 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_empty_simple + ("video/x-h264"), 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 +159,36 @@ 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_encoding_profile_unref (profile); + + if (GST_STATE_CHANGE_FAILURE == gst_element_set_state (camera, + GST_STATE_PLAYING)) { + GtkWidget *dialog = + gtk_message_dialog_new (GTK_WINDOW (ui_main_window), GTK_DIALOG_MODAL, + GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, + "Could not initialize camerabin2 with the " + "selected format. Your system might not have the required plugins installed.\n" + "Please select another format."); + + gtk_dialog_run (GTK_DIALOG (dialog)); + + gtk_widget_destroy (dialog); + } +} + static GstBusSyncReply bus_sync_callback (GstBus * bus, GstMessage * message, gpointer data) { @@ -152,11 +257,28 @@ 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[]) { int ret = 0; - GtkWidget *ui_main_window; GError *error = NULL; GstBus *bus; @@ -176,6 +298,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); diff --git a/tests/examples/camerabin2/gst-camera2.h b/tests/examples/camerabin2/gst-camera2.h index d96e2de63a..10bea027aa 100644 --- a/tests/examples/camerabin2/gst-camera2.h +++ b/tests/examples/camerabin2/gst-camera2.h @@ -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__ */ diff --git a/tests/examples/camerabin2/gst-camera2.ui b/tests/examples/camerabin2/gst-camera2.ui index 48fe1410ab..9dc1fee3d5 100644 --- a/tests/examples/camerabin2/gst-camera2.ui +++ b/tests/examples/camerabin2/gst-camera2.ui @@ -1,43 +1,53 @@ - + False 800 600 - + True + False True + False Image + False True True False + False True True - + + True + True 0 Video + False True True False + False True True imageRButton - + + True + True 1 @@ -51,39 +61,44 @@ True + False True - + False + + True + True 0 True + False - - Capture + True - True - True - + False + Actions False - False + True 0 - - Stop Capture + + Capture + False True True True - + False + False @@ -91,6 +106,47 @@ 1 + + + Stop Capture + False + True + True + True + False + + + + False + False + 2 + + + + + True + False + Video format + + + False + True + 5 + 3 + + + + + True + False + + + + False + True + 4 + + False @@ -100,6 +156,8 @@ + True + True 1