examples : Port to 0.11

This commit is contained in:
Edward Hervey 2011-11-04 16:23:03 +01:00
parent eaad7e58b0
commit 4642c67d30
5 changed files with 62 additions and 64 deletions

View file

@ -219,8 +219,7 @@ handle_element_message (GstMessage * msg)
const GValue *image; const GValue *image;
GstBuffer *buf = NULL; GstBuffer *buf = NULL;
guint8 *data = NULL; guint8 *data = NULL;
gchar *caps_string; gsize size = 0;
guint size = 0;
gchar *filename = NULL; gchar *filename = NULL;
FILE *f = NULL; FILE *f = NULL;
size_t written; size_t written;
@ -232,8 +231,6 @@ handle_element_message (GstMessage * msg)
image = gst_structure_get_value (st, "buffer"); image = gst_structure_get_value (st, "buffer");
if (image) { if (image) {
buf = gst_value_get_buffer (image); buf = gst_value_get_buffer (image);
data = GST_BUFFER_DATA (buf);
size = GST_BUFFER_SIZE (buf);
if (g_str_equal (gst_structure_get_name (st), "raw-image")) { if (g_str_equal (gst_structure_get_name (st), "raw-image")) {
filename = g_strdup_printf ("test_%04u.raw", num_pics); filename = g_strdup_printf ("test_%04u.raw", num_pics);
} else if (g_str_equal (gst_structure_get_name (st), "preview-image")) { } else if (g_str_equal (gst_structure_get_name (st), "preview-image")) {
@ -243,13 +240,12 @@ handle_element_message (GstMessage * msg)
g_print ("unknown buffer received\n"); g_print ("unknown buffer received\n");
return; return;
} }
caps_string = gst_caps_to_string (GST_BUFFER_CAPS (buf)); g_print ("writing buffer to %s\n", filename);
g_print ("writing buffer to %s, buffer caps: %s\n",
filename, caps_string);
g_free (caps_string);
f = g_fopen (filename, "w"); f = g_fopen (filename, "w");
if (f) { if (f) {
data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
written = fwrite (data, size, 1, f); written = fwrite (data, size, 1, f);
gst_buffer_unmap (buf, data, size);
if (!written) { if (!written) {
g_print ("errro writing file\n"); g_print ("errro writing file\n");
} }
@ -270,11 +266,11 @@ my_bus_sync_callback (GstBus * bus, GstMessage * message, gpointer data)
if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT) if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT)
return GST_BUS_PASS; return GST_BUS_PASS;
if (!gst_structure_has_name (message->structure, "prepare-xwindow-id")) if (!gst_message_has_name (message, "prepare-xwindow-id"))
return GST_BUS_PASS; return GST_BUS_PASS;
/* FIXME: make sure to get XID in main thread */ /* FIXME: make sure to get XID in main thread */
gst_x_overlay_set_window_handle (GST_X_OVERLAY (message->src), gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (message->src),
#if GTK_CHECK_VERSION (2, 91, 6) #if GTK_CHECK_VERSION (2, 91, 6)
GDK_WINDOW_XID (gtk_widget_get_window (ui_drawing))); GDK_WINDOW_XID (gtk_widget_get_window (ui_drawing)));
#else #else
@ -465,7 +461,7 @@ me_gst_setup_pipeline_create_post_bin (const gchar * post, gboolean video)
} }
caps = gst_caps_new_simple ("video/x-raw-yuv", caps = gst_caps_new_simple ("video/x-raw-yuv",
"format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('I', '4', '2', '0'), NULL); "format", G_TYPE_STRING, "I420", NULL);
g_object_set (G_OBJECT (filter), "caps", caps, NULL); g_object_set (G_OBJECT (filter), "caps", caps, NULL);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -1110,7 +1106,7 @@ create_menu_items_from_structure (GstStructure * structure)
GString *item_str = NULL; GString *item_str = NULL;
guint j, num_items_created = 0, num_framerates = 1; guint j, num_items_created = 0, num_framerates = 1;
gint w = 0, h = 0, n = 0, d = 1; gint w = 0, h = 0, n = 0, d = 1;
guint32 fourcc = 0; const gchar *format = NULL;
g_return_val_if_fail (structure != NULL, 0); g_return_val_if_fail (structure != NULL, 0);
@ -1120,8 +1116,8 @@ create_menu_items_from_structure (GstStructure * structure)
if (0 == strcmp (structure_name, "video/x-raw-yuv")) { if (0 == strcmp (structure_name, "video/x-raw-yuv")) {
item_str = g_string_new_len ("", 128); item_str = g_string_new_len ("", 128);
if (gst_structure_has_field_typed (structure, "format", GST_TYPE_FOURCC)) { if (gst_structure_has_field_typed (structure, "format", G_TYPE_STRING)) {
gst_structure_get_fourcc (structure, "format", &fourcc); format = gst_structure_get_string (structure, "format");
} }
if (gst_structure_has_field_typed (structure, "width", GST_TYPE_INT_RANGE)) { if (gst_structure_has_field_typed (structure, "width", GST_TYPE_INT_RANGE)) {
@ -1170,15 +1166,14 @@ create_menu_items_from_structure (GstStructure * structure)
d = gst_value_get_fraction_denominator (item); d = gst_value_get_fraction_denominator (item);
} }
g_string_assign (item_str, structure_name); g_string_assign (item_str, structure_name);
g_string_append_printf (item_str, " (%" GST_FOURCC_FORMAT ")", g_string_append_printf (item_str, " (%s)", format);
GST_FOURCC_ARGS (fourcc));
g_string_append_printf (item_str, ", %dx%d at %d/%d", w, h, n, d); g_string_append_printf (item_str, ", %dx%d at %d/%d", w, h, n, d);
gtk_list_store_append (store, &iter); gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, item_str->str, -1); gtk_list_store_set (store, &iter, 0, item_str->str, -1);
video_caps = video_caps =
gst_caps_new_simple (structure_name, "format", GST_TYPE_FOURCC, gst_caps_new_simple (structure_name, "format", G_TYPE_STRING,
fourcc, format,
"width", G_TYPE_INT, w, "height", G_TYPE_INT, h, "width", G_TYPE_INT, w, "height", G_TYPE_INT, h,
"framerate", GST_TYPE_FRACTION, n, d, NULL); "framerate", GST_TYPE_FRACTION, n, d, NULL);
video_caps_list = g_list_append (video_caps_list, video_caps); video_caps_list = g_list_append (video_caps_list, video_caps);

View file

@ -32,7 +32,7 @@
#include "gst-camera2.h" #include "gst-camera2.h"
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/interfaces/xoverlay.h> #include <gst/interfaces/videooverlay.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <gdk/gdkx.h> #include <gdk/gdkx.h>
#include <gdk/gdkkeysyms.h> #include <gdk/gdkkeysyms.h>
@ -92,12 +92,12 @@ bus_sync_callback (GstBus * bus, GstMessage * message, gpointer data)
if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT) if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT)
return GST_BUS_PASS; return GST_BUS_PASS;
if (!gst_structure_has_name (message->structure, "prepare-xwindow-id")) if (!gst_message_has_name (message, "prepare-xwindow-id"))
return GST_BUS_PASS; return GST_BUS_PASS;
/* FIXME: make sure to get XID in main thread */ /* FIXME: make sure to get XID in main thread */
ui_drawing = GTK_WIDGET (gtk_builder_get_object (builder, "viewfinderArea")); ui_drawing = GTK_WIDGET (gtk_builder_get_object (builder, "viewfinderArea"));
gst_x_overlay_set_window_handle (GST_X_OVERLAY (message->src), gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (message->src),
#if GTK_CHECK_VERSION (2, 91, 6) #if GTK_CHECK_VERSION (2, 91, 6)
GDK_WINDOW_XID (gtk_widget_get_window (ui_drawing))); GDK_WINDOW_XID (gtk_widget_get_window (ui_drawing)));
#else #else

View file

@ -105,7 +105,7 @@
#define GST_USE_UNSTABLE_API 1 #define GST_USE_UNSTABLE_API 1
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/interfaces/xoverlay.h> #include <gst/interfaces/videooverlay.h>
#include <gst/interfaces/photography.h> #include <gst/interfaces/photography.h>
#include <string.h> #include <string.h>
#include <sys/time.h> #include <sys/time.h>
@ -311,18 +311,16 @@ create_host_window (void)
} }
} }
static gboolean static GstPadProbeReturn
camera_src_get_timestamp_probe (GstPad * pad, GstMiniObject * obj, camera_src_get_timestamp_probe (GstPad * pad, GstPadProbeType type,
gpointer udata) GstMiniObject * obj, gpointer udata)
{ {
CaptureTiming *timing; CaptureTiming *timing;
timing = (CaptureTiming *) g_list_first (capture_times)->data; timing = (CaptureTiming *) g_list_first (capture_times)->data;
timing->camera_capture = gst_util_get_timestamp (); timing->camera_capture = gst_util_get_timestamp ();
gst_pad_remove_data_probe (pad, camera_probe_id); return GST_PAD_PROBE_REMOVE;
return TRUE;
} }
static gboolean static gboolean
@ -334,7 +332,7 @@ viewfinder_get_timestamp_probe (GstPad * pad, GstMiniObject * obj,
timing = (CaptureTiming *) g_list_first (capture_times)->data; timing = (CaptureTiming *) g_list_first (capture_times)->data;
timing->precapture = gst_util_get_timestamp (); timing->precapture = gst_util_get_timestamp ();
gst_pad_remove_data_probe (pad, viewfinder_probe_id); gst_pad_remove_probe (pad, viewfinder_probe_id);
return TRUE; return TRUE;
} }
@ -346,8 +344,7 @@ sync_bus_callback (GstBus * bus, GstMessage * message, gpointer data)
const GValue *image; const GValue *image;
GstBuffer *buf = NULL; GstBuffer *buf = NULL;
guint8 *data_buf = NULL; guint8 *data_buf = NULL;
gchar *caps_string; gsize size = 0;
guint size = 0;
gchar *preview_filename = NULL; gchar *preview_filename = NULL;
FILE *f = NULL; FILE *f = NULL;
size_t written; size_t written;
@ -356,10 +353,10 @@ sync_bus_callback (GstBus * bus, GstMessage * message, gpointer data)
case GST_MESSAGE_ELEMENT:{ case GST_MESSAGE_ELEMENT:{
st = gst_message_get_structure (message); st = gst_message_get_structure (message);
if (st) { if (st) {
if (gst_structure_has_name (message->structure, "prepare-xwindow-id")) { if (gst_message_has_name (message, "prepare-xwindow-id")) {
if (!no_xwindow && window) { if (!no_xwindow && window) {
gst_x_overlay_set_window_handle (GST_X_OVERLAY (GST_MESSAGE_SRC gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY
(message)), window); (GST_MESSAGE_SRC (message)), window);
gst_message_unref (message); gst_message_unref (message);
message = NULL; message = NULL;
return GST_BUS_DROP; return GST_BUS_DROP;
@ -376,8 +373,10 @@ sync_bus_callback (GstBus * bus, GstMessage * message, gpointer data)
/* set up probe to check when the viewfinder gets data */ /* set up probe to check when the viewfinder gets data */
GstPad *pad = gst_element_get_static_pad (viewfinder_sink, "sink"); GstPad *pad = gst_element_get_static_pad (viewfinder_sink, "sink");
viewfinder_probe_id = gst_pad_add_buffer_probe (pad, viewfinder_probe_id =
(GCallback) viewfinder_get_timestamp_probe, NULL); gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_BUFFER,
(GstPadProbeCallback) viewfinder_get_timestamp_probe, NULL,
NULL);
gst_object_unref (pad); gst_object_unref (pad);
} }
@ -386,14 +385,12 @@ sync_bus_callback (GstBus * bus, GstMessage * message, gpointer data)
image = gst_structure_get_value (st, "buffer"); image = gst_structure_get_value (st, "buffer");
if (image) { if (image) {
buf = gst_value_get_buffer (image); buf = gst_value_get_buffer (image);
data_buf = GST_BUFFER_DATA (buf);
size = GST_BUFFER_SIZE (buf);
preview_filename = g_strdup_printf ("test_vga.rgb"); preview_filename = g_strdup_printf ("test_vga.rgb");
caps_string = gst_caps_to_string (GST_BUFFER_CAPS (buf));
g_free (caps_string);
f = g_fopen (preview_filename, "w"); f = g_fopen (preview_filename, "w");
if (f) { if (f) {
data_buf = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
written = fwrite (data_buf, size, 1, f); written = fwrite (data_buf, size, 1, f);
gst_buffer_unmap (buf, data_buf, size);
if (!written) { if (!written) {
g_print ("error writing file\n"); g_print ("error writing file\n");
} }
@ -915,8 +912,7 @@ run_pipeline (gpointer user_data)
g_object_get (camerabin, "camera-source", &video_source, NULL); g_object_get (camerabin, "camera-source", &video_source, NULL);
if (video_source) { if (video_source) {
if (GST_IS_ELEMENT (video_source) && if (GST_IS_ELEMENT (video_source) && GST_IS_PHOTOGRAPHY (video_source)) {
gst_element_implements_interface (video_source, GST_TYPE_PHOTOGRAPHY)) {
/* Set GstPhotography interface options. If option not given as /* Set GstPhotography interface options. If option not given as
command-line parameter use default of the source element. */ command-line parameter use default of the source element. */
if (scene_mode != SCENE_MODE_NONE) if (scene_mode != SCENE_MODE_NONE)
@ -953,8 +949,8 @@ run_pipeline (gpointer user_data)
GstPad *pad; GstPad *pad;
pad = gst_element_get_static_pad (video_source, "imgsrc"); pad = gst_element_get_static_pad (video_source, "imgsrc");
camera_probe_id = gst_pad_add_buffer_probe (pad, camera_probe_id = gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_BUFFER,
(GCallback) camera_src_get_timestamp_probe, NULL); (GstPadProbeCallback) camera_src_get_timestamp_probe, NULL, NULL);
gst_object_unref (pad); gst_object_unref (pad);
} }

View file

@ -30,8 +30,14 @@ static gchar *
g_value_to_string (const GValue * val) g_value_to_string (const GValue * val)
{ {
if (G_VALUE_TYPE (val) == GST_TYPE_BUFFER) { if (G_VALUE_TYPE (val) == GST_TYPE_BUFFER) {
const GstBuffer *buf = gst_value_get_buffer (val); GstBuffer *buf = gst_value_get_buffer (val);
gchar *ret = g_base64_encode (GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf)); gpointer data;
gsize size;
gchar *ret;
data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
ret = g_base64_encode (data, size);
gst_buffer_unmap (buf, data, size);
return ret; return ret;
} else { } else {

View file

@ -68,19 +68,19 @@ no_pipeline (DemoPlayer * player)
return FALSE; return FALSE;
} }
static gboolean static GstPadProbeReturn
demo_player_event_listener (GstElement * host, GstEvent * event, gpointer data) demo_player_event_listener (GstPad * pad, GstPadProbeType type,
GstEvent * event, gpointer data)
{ {
DemoPlayer *player = DEMO_PLAYER (data); DemoPlayer *player = DEMO_PLAYER (data);
DemoPlayerPrivate *priv = DEMO_PLAYER_GET_PRIVATE (player); DemoPlayerPrivate *priv = DEMO_PLAYER_GET_PRIVATE (player);
if (GST_EVENT_TYPE (event) == GST_EVENT_NEWSEGMENT) { if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
gdouble rate, applied_rate; const GstSegment *segment;
gdouble new_rate; gdouble new_rate;
gst_event_parse_new_segment_full (event, NULL, &rate, &applied_rate, NULL, gst_event_parse_segment (event, &segment);
NULL, NULL, NULL); new_rate = segment->rate * segment->applied_rate;
new_rate = rate * applied_rate;
if (priv->rate != new_rate) { if (priv->rate != new_rate) {
priv->rate = new_rate; priv->rate = new_rate;
g_signal_emit (player, demo_player_signals[SIGNAL_RATE_CHANGE], 0, g_signal_emit (player, demo_player_signals[SIGNAL_RATE_CHANGE], 0,
@ -88,7 +88,7 @@ demo_player_event_listener (GstElement * host, GstEvent * event, gpointer data)
} }
} }
return TRUE; return GST_PAD_PROBE_OK;
} }
static void static void
@ -174,8 +174,9 @@ demo_player_build_pipeline (DemoPlayer * player)
LINK_ELEMENTS (format, resample); LINK_ELEMENTS (format, resample);
LINK_ELEMENTS (resample, asink); LINK_ELEMENTS (resample, asink);
gst_pad_add_event_probe (gst_element_get_static_pad (asink, "sink"), gst_pad_add_probe (gst_element_get_static_pad (asink, "sink"),
G_CALLBACK (demo_player_event_listener), player); GST_PAD_PROBE_TYPE_EVENT,
(GstPadProbeCallback) demo_player_event_listener, player, NULL);
ghostpad = gst_element_get_static_pad (filter, "sink"); ghostpad = gst_element_get_static_pad (filter, "sink");
gst_element_add_pad (audioline, gst_ghost_pad_new ("sink", ghostpad)); gst_element_add_pad (audioline, gst_ghost_pad_new ("sink", ghostpad));
@ -196,8 +197,9 @@ demo_player_build_pipeline (DemoPlayer * player)
priv->scaletempo_line = audioline; priv->scaletempo_line = audioline;
MAKE_ELEMENT (NULL, priv->scalerate_line, audiosink_name, MAKE_ELEMENT (NULL, priv->scalerate_line, audiosink_name,
"scaling_audio_sink"); "scaling_audio_sink");
gst_pad_add_event_probe (gst_element_get_static_pad (priv->scalerate_line, gst_pad_add_probe (gst_element_get_static_pad (priv->scalerate_line,
"sink"), G_CALLBACK (demo_player_event_listener), player); "sink"), GST_PAD_PROBE_TYPE_EVENT,
(GstPadProbeCallback) demo_player_event_listener, player, NULL);
g_object_ref (priv->scaletempo_line); g_object_ref (priv->scaletempo_line);
g_object_ref (priv->scalerate_line); g_object_ref (priv->scalerate_line);
} }
@ -221,9 +223,8 @@ _set_rate (DemoPlayer * player, gdouble new_rate, gint second)
priv = DEMO_PLAYER_GET_PRIVATE (player); priv = DEMO_PLAYER_GET_PRIVATE (player);
if (second < 0) { if (second < 0) {
GstFormat fmt = GST_FORMAT_TIME;
seek_type = GST_SEEK_TYPE_SET; seek_type = GST_SEEK_TYPE_SET;
if (!gst_element_query_position (priv->pipeline, &fmt, &pos)) { if (!gst_element_query_position (priv->pipeline, GST_FORMAT_TIME, &pos)) {
// This should be the default but too many upstream elements seek anyway // This should be the default but too many upstream elements seek anyway
pos = GST_CLOCK_TIME_NONE; pos = GST_CLOCK_TIME_NONE;
seek_type = GST_SEEK_TYPE_NONE; seek_type = GST_SEEK_TYPE_NONE;
@ -461,12 +462,12 @@ demo_player_get_position_func (DemoPlayer * player)
{ {
DemoPlayerPrivate *priv = DEMO_PLAYER_GET_PRIVATE (player); DemoPlayerPrivate *priv = DEMO_PLAYER_GET_PRIVATE (player);
gint64 pos; gint64 pos;
GstFormat fmt = GST_FORMAT_TIME;
if (!priv->pipeline) if (!priv->pipeline)
return -1; return -1;
if (!gst_element_query_position (priv->pipeline, &fmt, &pos) || pos < 0) { if (!gst_element_query_position (priv->pipeline, GST_FORMAT_TIME, &pos)
|| pos < 0) {
return -1; return -1;
} }
@ -478,12 +479,12 @@ demo_player_get_duration_func (DemoPlayer * player)
{ {
DemoPlayerPrivate *priv = DEMO_PLAYER_GET_PRIVATE (player); DemoPlayerPrivate *priv = DEMO_PLAYER_GET_PRIVATE (player);
gint64 dur; gint64 dur;
GstFormat fmt = GST_FORMAT_TIME;
if (!priv->pipeline) if (!priv->pipeline)
return -1; return -1;
if (!gst_element_query_duration (priv->pipeline, &fmt, &dur) || dur < 0) { if (!gst_element_query_duration (priv->pipeline, GST_FORMAT_TIME, &dur)
|| dur < 0) {
return -1; return -1;
} }