From b1d353e2de91545128bcd0900799e98aeec1e370 Mon Sep 17 00:00:00 2001 From: Stefan Kost Date: Fri, 17 Jul 2009 15:38:06 +0300 Subject: camerabin: implemnet two more tests Add tests for videorecording startup and capture startup delay. --- tests/examples/camerabin/gst-camera-perf.c | 325 +++++++++++++++++++++++------ 1 file changed, 259 insertions(+), 66 deletions(-) (limited to 'tests') diff --git a/tests/examples/camerabin/gst-camera-perf.c b/tests/examples/camerabin/gst-camera-perf.c index 858e60cd..cadffa2b 100644 --- a/tests/examples/camerabin/gst-camera-perf.c +++ b/tests/examples/camerabin/gst-camera-perf.c @@ -54,6 +54,13 @@ #include #include +/* + * debug logging + */ +GST_DEBUG_CATEGORY_STATIC (camera_perf); +#define GST_CAT_DEFAULT camera_perf + + /* * enums, typedefs and defines */ @@ -61,7 +68,7 @@ #define GET_TIME(t) \ do { \ t = gst_util_get_timestamp (); \ - GST_INFO("%2d ----------------------------------------", test_ix); \ + GST_DEBUG("%2d ----------------------------------------", test_ix); \ } while(0) #define DIFF_TIME(e,s,d) d=GST_CLOCK_DIFF(s,e) @@ -102,10 +109,16 @@ static guint32 num_pics = 0; static guint32 num_pics_cont = 0; //static guint32 num_vids = 0; static guint test_ix = 0; -static gboolean signal_sink = FALSE; +static gboolean signal_vf_sink = FALSE; +static gboolean signal_vid_sink = FALSE; +static gboolean signal_img_enc = FALSE; static gboolean signal_shot = FALSE; static gboolean signal_cont = FALSE; +static gboolean need_pad_probe = FALSE; +static gboolean need_ienc_pad_probe = FALSE; +static gboolean need_vmux_pad_probe = FALSE; + static gboolean have_img_captured = FALSE; static gboolean have_img_done = FALSE; @@ -113,6 +126,7 @@ static gboolean have_img_done = FALSE; static GstClockTime t_initial = G_GUINT64_CONSTANT (0); static GstClockTime t_final[CONT_SHOTS] = { G_GUINT64_CONSTANT (0), }; +static GstClockTime test_06_taget, test_09_taget; static GstClockTimeDiff diff; static ResultType result; @@ -135,10 +149,10 @@ static const gchar *test_names[TEST_CASES] = { "Shot to snapshot", "Shot to shot", "Serial shooting", - "(Shutter lag)", + "Shutter lag", "Image saved", "Mode change", - "(Video recording)" /* time to get videobin to PLAYING? or first buffer reaching filesink? */ + "Video recording" }; /* @@ -147,28 +161,88 @@ static const gchar *test_names[TEST_CASES] = { static void print_result (void); static gboolean run_test (gpointer user_data); +static gboolean setup_add_pad_probe (GstElement * elem, const gchar * pad_name, + GCallback handler, gpointer data); + /* * Callbacks */ static gboolean -img_sink_has_buffer (GstPad * pad, GstBuffer * buf, gpointer user_data) +pad_has_buffer (GstPad * pad, GstBuffer * buf, gpointer user_data) { - if (signal_sink) { - signal_sink = FALSE; + gboolean *signal_sink = (gboolean *) user_data; + gboolean print_and_restart = FALSE; + + if (*signal_sink) { + *signal_sink = FALSE; GET_TIME (t_final[0]); + GST_DEBUG_OBJECT (pad, "%2d pad has buffer", test_ix); + switch (test_ix) { + case 5: + DIFF_TIME (t_final[num_pics_cont], t_initial, diff); + result.avg = result.min = result.max = diff; + print_and_restart = TRUE; + break; + case 8: + DIFF_TIME (t_final[num_pics_cont], t_initial, diff); + result.avg = result.min = result.max = diff; + g_signal_emit_by_name (camera_bin, "user-stop", 0); + print_and_restart = TRUE; + break; + default: + GST_WARNING_OBJECT (pad, "%2d pad has buffer, not handled", test_ix); + break; + } + } + if (print_and_restart) { + print_result (); + g_idle_add ((GSourceFunc) run_test, NULL); + return FALSE; } return TRUE; } +static void +element_added (GstBin * bin, GstElement * element, gpointer user_data) +{ + GstElement *elem; + + if (GST_IS_BIN (element)) { + g_signal_connect (element, "element-added", (GCallback) element_added, + NULL); + } + + if (need_vmux_pad_probe) { + g_object_get (camera_bin, "videomux", &elem, NULL); + if (elem) { + setup_add_pad_probe (elem, "src", (GCallback) pad_has_buffer, + &signal_vid_sink); + need_vmux_pad_probe = FALSE; + target[8] = test_09_taget; + GST_INFO_OBJECT (elem, "got default video muxer"); + } + } + if (need_ienc_pad_probe) { + g_object_get (camera_bin, "imageenc", &elem, NULL); + if (elem) { + setup_add_pad_probe (elem, "src", (GCallback) pad_has_buffer, + &signal_img_enc); + need_ienc_pad_probe = FALSE; + target[5] = test_06_taget; + GST_INFO_OBJECT (elem, "got default image encoder"); + } + } +} + static gboolean img_capture_done (GstElement * camera, GString * fname, gpointer user_data) { gboolean ret = FALSE; gboolean print_and_restart = FALSE; - GST_INFO ("shot %d, cont %d, num %d", signal_shot, signal_cont, + GST_DEBUG ("shot %d, cont %d, num %d", signal_shot, signal_cont, num_pics_cont); if (signal_shot) { @@ -181,7 +255,7 @@ img_capture_done (GstElement * camera, GString * fname, gpointer user_data) print_and_restart = TRUE; break; } - GST_INFO ("%2d shot done", test_ix); + GST_DEBUG ("%2d shot done", test_ix); } if (signal_cont) { @@ -198,7 +272,7 @@ img_capture_done (GstElement * camera, GString * fname, gpointer user_data) } snprintf (tmp, 6, "_%04d", num_pics_cont); memcpy (filename->str + i, tmp, 5); - GST_INFO ("%2d cont new filename '%s'", test_ix, filename->str); + GST_DEBUG ("%2d cont new filename '%s'", test_ix, filename->str); g_object_set (camera_bin, "filename", filename->str, NULL); // FIXME: is burst capture broken? new filename and return TRUE should be enough // as a workaround we will kick next image from here @@ -244,7 +318,7 @@ img_capture_done (GstElement * camera, GString * fname, gpointer user_data) result.min = min; result.max = max; print_and_restart = TRUE; - GST_INFO ("%2d cont done", test_ix); + GST_DEBUG ("%2d cont done", test_ix); } } @@ -286,33 +360,36 @@ bus_callback (GstBus * bus, GstMessage * message, gpointer data) break; } case GST_MESSAGE_STATE_CHANGED: - if (GST_MESSAGE_SRC (message) == GST_OBJECT (camera_bin)) { + if (GST_IS_BIN (GST_MESSAGE_SRC (message))) { GstState oldstate, newstate; gst_message_parse_state_changed (message, &oldstate, &newstate, NULL); - GST_INFO ("state-changed: %s -> %s", + GST_DEBUG_OBJECT (GST_MESSAGE_SRC (message), "state-changed: %s -> %s", gst_element_state_get_name (oldstate), gst_element_state_get_name (newstate)); - if (GST_STATE_TRANSITION (oldstate, - newstate) == GST_STATE_CHANGE_PAUSED_TO_PLAYING) { - GET_TIME (t_final[0]); - DIFF_TIME (t_final[0], t_initial, diff); - - result.avg = result.min = result.max = diff; - print_result (); - g_idle_add ((GSourceFunc) run_test, NULL); + if (GST_MESSAGE_SRC (message) == GST_OBJECT (camera_bin)) { + if (GST_STATE_TRANSITION (oldstate, + newstate) == GST_STATE_CHANGE_PAUSED_TO_PLAYING) { + GET_TIME (t_final[0]); + DIFF_TIME (t_final[0], t_initial, diff); + + result.avg = result.min = result.max = diff; + print_result (); + g_idle_add ((GSourceFunc) run_test, NULL); + } } } break; case GST_MESSAGE_EOS: /* end-of-stream */ + GST_INFO ("got eos() - should not happen"); g_main_loop_quit (loop); break; default: st = gst_message_get_structure (message); if (st) { if (gst_structure_has_name (st, "image-captured")) { - GST_INFO ("%2d image-captured", test_ix); + GST_DEBUG ("%2d image-captured", test_ix); switch (test_ix) { case 3: GET_TIME (t_final[num_pics_cont]); @@ -330,12 +407,14 @@ bus_callback (GstBus * bus, GstMessage * message, gpointer data) break; } } else if (gst_structure_has_name (st, "preview-image")) { - GST_INFO ("%2d preview-image", test_ix); + GST_DEBUG ("%2d preview-image", test_ix); switch (test_ix) { case 2: GET_TIME (t_final[num_pics_cont]); DIFF_TIME (t_final[num_pics_cont], t_initial, diff); result.avg = result.min = result.max = diff; + /* turn off preview image generation again */ + g_object_set (camera_bin, "preview-caps", NULL, NULL); break; } } @@ -363,52 +442,43 @@ cleanup_pipeline (void) } static gboolean -setup_pipeline_video_sink (void) +setup_add_pad_probe (GstElement * elem, const gchar * pad_name, + GCallback handler, gpointer data) { - GstElement *sink = NULL; GstPad *pad = NULL; - sink = gst_element_factory_make ("fakesink", NULL); - if (NULL == sink) { - g_warning ("failed to create sink\n"); - goto error; - } - - pad = gst_element_get_static_pad (sink, "sink"); - if (NULL == pad) { - g_warning ("sink has no pad named 'sink'\n"); - goto error; + if (!(pad = gst_element_get_static_pad (elem, pad_name))) { + GST_WARNING ("sink has no pad named '%s'", pad_name); + return FALSE; } - g_object_set (sink, "sync", TRUE, NULL); - gst_pad_add_buffer_probe (pad, (GCallback) img_sink_has_buffer, NULL); + gst_pad_add_buffer_probe (pad, (GCallback) handler, data); gst_object_unref (pad); - g_object_set (camera_bin, "vfsink", sink, NULL); - return TRUE; -error: - if (sink) - gst_object_unref (sink); - return FALSE; } static gboolean -setup_pipeline_element (const gchar * property_name, const gchar * element_name) +setup_pipeline_element (const gchar * property_name, const gchar * element_name, + GstElement ** res_elem) { gboolean res = TRUE; + GstElement *elem = NULL; - GstElement *elem; if (element_name) { elem = gst_element_factory_make (element_name, NULL); if (elem) { g_object_set (camera_bin, property_name, elem, NULL); } else { - g_warning ("can't create element '%s' for property '%s'", element_name, + GST_WARNING ("can't create element '%s' for property '%s'", element_name, property_name); res = FALSE; } + } else { + GST_DEBUG ("no element for property '%s' given", property_name); } + if (res_elem) + *res_elem = elem; return res; } @@ -417,6 +487,7 @@ setup_pipeline (void) { GstBus *bus; gboolean res = TRUE; + GstElement *vmux, *ienc, *sink; g_string_printf (filename, "test_%04u.jpg", num_pics); @@ -432,11 +503,24 @@ setup_pipeline (void) gst_bus_add_watch (bus, bus_callback, NULL); gst_object_unref (bus); - if (!setup_pipeline_video_sink ()) { + GST_INFO_OBJECT (camera_bin, "camerabin created"); + + /* configure used elements */ + res &= setup_pipeline_element ("vfsink", "fakesink", &sink); + res &= setup_pipeline_element ("audiosrc", audiosrc_name, NULL); + res &= setup_pipeline_element ("videosrc", videosrc_name, NULL); + res &= setup_pipeline_element ("audioenc", audioenc_name, NULL); + res &= setup_pipeline_element ("videoenc", videoenc_name, NULL); + res &= setup_pipeline_element ("imageenc", imageenc_name, &ienc); + res &= setup_pipeline_element ("videomux", videomux_name, &vmux); + if (!res) { goto error; } + GST_INFO_OBJECT (camera_bin, "elements created"); + /* set properties */ + g_object_set (camera_bin, "filename", filename->str, NULL); if (src_csp && strlen (src_csp) == 4) { GstCaps *filter_caps; @@ -446,8 +530,7 @@ setup_pipeline (void) "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC (src_csp[0], src_csp[1], src_csp[2], src_csp[3]), NULL); if (filter_caps) { - g_object_set (camera_bin, "filename", filename->str, - "filter-caps", filter_caps, NULL); + g_object_set (camera_bin, "filter-caps", filter_caps, NULL); gst_caps_unref (filter_caps); } else { g_warning ("can't make filter-caps with format=%s\n", src_csp); @@ -455,16 +538,49 @@ setup_pipeline (void) } } - /* configure used elements */ - res &= setup_pipeline_element ("audiosrc", audiosrc_name); - res &= setup_pipeline_element ("videosrc", videosrc_name); - res &= setup_pipeline_element ("audioenc", audioenc_name); - res &= setup_pipeline_element ("videoenc", videoenc_name); - res &= setup_pipeline_element ("imageenc", imageenc_name); - res &= setup_pipeline_element ("videomux", videomux_name); - if (!res) { + g_object_set (sink, "sync", TRUE, NULL); + + GST_INFO_OBJECT (camera_bin, "elements configured"); + + /* connect signal handlers */ + g_assert (sink); + if (!setup_add_pad_probe (sink, "sink", (GCallback) pad_has_buffer, + &signal_vf_sink)) { goto error; } + if (!vmux) { + g_object_get (camera_bin, "videomux", &vmux, NULL); + if (!vmux) { + need_pad_probe = need_vmux_pad_probe = TRUE; + test_09_taget = target[8]; + target[8] = G_GUINT64_CONSTANT (0); + } + } + if (vmux) { + if (!setup_add_pad_probe (vmux, "src", (GCallback) pad_has_buffer, + &signal_vid_sink)) { + goto error; + } + } + if (!ienc) { + g_object_get (camera_bin, "imageenc", &ienc, NULL); + if (!ienc) { + need_pad_probe = need_ienc_pad_probe = TRUE; + test_06_taget = target[5]; + target[5] = G_GUINT64_CONSTANT (0); + } + } + if (ienc) { + if (!setup_add_pad_probe (ienc, "src", (GCallback) pad_has_buffer, + &signal_img_enc)) { + goto error; + } + } + if (need_pad_probe) { + g_signal_connect (camera_bin, "element-added", (GCallback) element_added, + NULL); + } + GST_INFO_OBJECT (camera_bin, "probe signals connected"); /* configure a resolution and framerate */ if (image_width && image_height && view_framerate_num && view_framerate_den) { @@ -477,13 +593,14 @@ setup_pipeline (void) g_warning ("can't set camerabin to ready\n"); goto error; } + GST_INFO_OBJECT (camera_bin, "camera ready"); if (GST_STATE_CHANGE_FAILURE == gst_element_set_state (camera_bin, GST_STATE_PLAYING)) { g_warning ("can't set camerabin to playing\n"); goto error; } - GST_INFO_OBJECT (camera_bin, "created and started"); + GST_INFO_OBJECT (camera_bin, "camera started"); return TRUE; error: cleanup_pipeline (); @@ -541,6 +658,9 @@ test_03 (void) g_object_set (camera_bin, "preview-caps", snap_caps, NULL); gst_caps_unref (snap_caps); + /* switch to image mode */ + g_object_set (camera_bin, "mode", 0, NULL); + g_object_set (camera_bin, "filename", filename->str, NULL); GET_TIME (t_initial); g_signal_emit_by_name (camera_bin, "user-start", 0); @@ -556,6 +676,8 @@ test_03 (void) static gboolean test_04 (void) { + /* switch to image mode */ + g_object_set (camera_bin, "mode", 0, NULL); GET_TIME (t_initial); g_signal_emit_by_name (camera_bin, "user-start", 0); @@ -564,6 +686,7 @@ test_04 (void) return FALSE; } + /* 05) Serial shooting * * It tests the time between shots in continuous mode. @@ -573,6 +696,8 @@ test_05 (void) { signal_cont = TRUE; have_img_captured = have_img_done = FALSE; + /* switch to image mode */ + g_object_set (camera_bin, "mode", 0, NULL); GET_TIME (t_initial); g_signal_emit_by_name (camera_bin, "user-start", 0); @@ -582,6 +707,27 @@ test_05 (void) } +/* 06) Shutter lag + * + * It tests the time from user-start signal to buffer reaching img-enc + */ +static gboolean +test_06 (void) +{ + signal_img_enc = TRUE; + + /* switch to image mode */ + g_object_set (camera_bin, "mode", 0, NULL); + g_object_set (camera_bin, "filename", filename->str, NULL); + GET_TIME (t_initial); + g_signal_emit_by_name (camera_bin, "user-start", 0); + + /* the actual results are fetched in pad_has_buffer */ + result.times = 1; + return FALSE; +} + + /* 07) Image saved * * It tests the time between pressing the Shot and the final image is saved to @@ -592,10 +738,11 @@ test_07 (void) { signal_shot = TRUE; + /* switch to image mode */ + g_object_set (camera_bin, "mode", 0, NULL); + g_object_set (camera_bin, "filename", filename->str, NULL); GET_TIME (t_initial); g_signal_emit_by_name (camera_bin, "user-start", 0); - /* call "user-stop" just to go back to initial state (view-finder) again */ - g_signal_emit_by_name (camera_bin, "user-stop", 0); /* the actual results are fetched in img_capture_done */ result.times = 1; return FALSE; @@ -616,6 +763,10 @@ test_08 (void) const gint count = 6; gint i; + /* switch to image mode */ + g_object_set (camera_bin, "mode", 0, NULL); + g_object_set (camera_bin, "filename", filename->str, NULL); + for (i = 0; i < count; ++i) { GET_TIME (t_final[i]); g_object_set (camera_bin, "mode", (i + 1) & 1, NULL); @@ -641,6 +792,29 @@ test_08 (void) return TRUE; } + +/* 09) Video recording + * + * It tests the time it takes to start video recording. + * FIXME: shouldn't we wait for the buffer arriving on the venc instead of sink? + */ +static gboolean +test_09 (void) +{ + signal_vid_sink = TRUE; + + /* switch to video mode */ + g_object_set (camera_bin, "mode", 1, NULL); + g_object_set (camera_bin, "filename", filename->str, NULL); + GET_TIME (t_initial); + g_signal_emit_by_name (camera_bin, "user-start", 0); + + /* the actual results are fetched in pad_has_buffer */ + result.times = 1; + return FALSE; +} + + typedef gboolean (*test_case) (void); static test_case test_cases[TEST_CASES] = { test_01, @@ -648,10 +822,10 @@ static test_case test_cases[TEST_CASES] = { test_03, test_04, test_05, - NULL, + test_06, test_07, test_08, - NULL + test_09 }; static void @@ -671,6 +845,13 @@ static gboolean run_test (gpointer user_data) { gboolean ret = TRUE; + guint old_test_ix = test_ix; + + if (test_ix == TEST_CASES) { + GST_INFO ("done"); + g_main_loop_quit (loop); + return FALSE; + } printf ("| %02d ", test_ix + 1); if (test_cases[test_ix]) { @@ -693,14 +874,23 @@ run_test (gpointer user_data) test_ix++; } - if (!camera_bin || test_ix == TEST_CASES) { + if (old_test_ix == 0 && ret == TRUE && !camera_bin) { + GST_INFO ("done (camerabin creation failed)"); + g_main_loop_quit (loop); + return FALSE; + } + if (old_test_ix > 0 && !camera_bin) { + GST_INFO ("done (camerabin was destroyed)"); + g_main_loop_quit (loop); + return FALSE; + } + if (test_ix == TEST_CASES) { GST_INFO ("done"); g_main_loop_quit (loop); return FALSE; - } else { - GST_INFO ("%2d result: %d", test_ix, ret); - return ret; } + GST_INFO ("%2d result: %d", test_ix, ret); + return ret; } int @@ -750,6 +940,9 @@ main (int argc, char *argv[]) } g_option_context_free (ctx); + GST_DEBUG_CATEGORY_INIT (camera_perf, "camera-perf", 0, + "camera performcance test"); + /* init */ filename = g_string_new_len ("", 16); loop = g_main_loop_new (NULL, FALSE); -- cgit v1.2.1 From e88984ccbd4b2b7b5527cbc3ff488c5c85bb1e97 Mon Sep 17 00:00:00 2001 From: Vincent Penquerc'h Date: Sun, 15 Feb 2009 18:35:04 +0000 Subject: add new Kate plugin, for Kate overlay streams katedec: Kate decoder (text only) kateenc: Kate encoder (text and DVD SPU only) katetag: Kate tagger kateparse: Kate parser tiger: Kate renderer using the Tiger rendering library Fixes #525743. --- tests/check/Makefile.am | 11 + tests/check/elements/kate.c | 839 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 850 insertions(+) create mode 100644 tests/check/elements/kate.c (limited to 'tests') diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index bf4f07ce..1aa99d1a 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -63,6 +63,13 @@ else check_timidity= endif +if USE_KATE +check_kate=elements/kate +else +check_kate= +endif + + VALGRIND_TO_FIX = \ elements/mpeg2enc \ elements/mplex @@ -78,6 +85,7 @@ check_PROGRAMS = \ $(check_neon) \ $(check_ofa) \ $(check_timidity) \ + $(check_kate) \ elements/aacparse \ elements/amrparse \ elements/camerabin \ @@ -119,4 +127,7 @@ elements_rtpbin_buffer_list_SOURCES = elements/rtpbin_buffer_list.c elements_timidity_CFLAGS = $(GST_BASE_CFLAGS) $(AM_CFLAGS) elements_timidity_LDADD = $(GST_BASE_LIBS) $(LDADD) +elements_kate_CFLAGS = $(GST_BASE_CFLAGS) $(AM_CFLAGS) +elements_kate_LDADD = $(GST_BASE_LIBS) $(LDADD) + EXTRA_DIST = gst-plugins-bad.supp diff --git a/tests/check/elements/kate.c b/tests/check/elements/kate.c new file mode 100644 index 00000000..f7ac3ed4 --- /dev/null +++ b/tests/check/elements/kate.c @@ -0,0 +1,839 @@ +/* GStreamer + * + * unit test for kate + * + * Copyright (C) <2007> Stefan Kost + * Copyright (C) <2008> ogg.k.ogg.k + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include + +#include +#include + + +static const guint8 kate_header_0x80[64] = { + 0x80, 0x6b, 0x61, 0x74, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x09, 0x00, 0x00, 0x00, 0x20, /* .kate...... ... */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe8, 0x03, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, /* ................ */ + 0x65, 0x6e, 0x5f, 0x47, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* en_GB........... */ + 0x6e, 0x6f, 0x6e, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* none............ */ +}; + +static const guint8 kate_header_0x81[53] = { + 0x81, 0x6b, 0x61, 0x74, 0x65, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x6c, 0x69, 0x62, /* .kate........lib */ + 0x6b, 0x61, 0x74, 0x65, 0x20, 0x30, 0x2e, 0x31, 0x2e, 0x30, 0x20, 0x28, 0x54, 0x69, 0x67, 0x65, /* kate 0.1.0 (Tige */ + 0x72, 0x29, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x54, 0x49, 0x54, 0x4c, 0x45, 0x3d, /* r)........TITLE= */ + 0x54, 0x69, 0x67, 0x65, 0x72, /* Tiger */ +}; +static const guint8 kate_header_0x8x[10] = { + 0x80, 0x6b, 0x61, 0x74, 0x65, 0x00, 0x00, 0x00, 0x00 +}; +static const guint8 kate_header_0x88[11] = { + 0x88, 0x6b, 0x61, 0x74, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +static const guint8 kate_header_0x00[45] = { + 0x00, 0xe8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, /* ................ */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x70, 0x6c, 0x61, /* .............pla */ + 0x69, 0x6e, 0x20, 0x6f, 0x6c, 0x64, 0x20, 0x74, 0x65, 0x78, 0x74, 0x08, 0x00 /* in old text.. */ +}; +static const guint8 kate_header_0x01[1] = { + 0x01 +}; +static const guint8 kate_header_0x7f[1] = { + 0x7f +}; + +static const unsigned char kate_spu[] = { + 0x00, 0x1b, /* size */ + 0x00, 0x06, /* commands at offset 6 */ + 0x45, /* first line data - 2 pixels of colors 0 and 1 */ + 0x76, /* first line data - 2 pixels of colors 3 and 2 */ + 0x00, 0x00, /* timestamp */ + 0x00, 0x06, /* link to next command sequence - points back to the current one to mark no more */ + 0x06, 0x00, 0x04, 0x00, 0x05, /* pointers to data */ + 0x05, 0x00, 0x30, 0x04, 0x00, 0x10, 0x02, /* area: 3x1 -> 4x2 */ + 0x04, 0x0f, 0xff, /* alpha: color 0 transparent, all others opaque */ + 0x01, /* show */ + 0xff /* end */ +}; + +/* A lot of these taken from the vorbisdec test */ + +/* For ease of programming we use globals to keep refs for our floating + * src and sink pads we create; otherwise we always have to do get_pad, + * get_peer, and then remove references in every test function */ +static GstPad *mydecsrcpad, *mydecsinkpad; +static GstPad *myencsrcpad, *myencsinkpad; +static GstPad *myparsesrcpad, *myparsesinkpad; +static GstPad *mytagsrcpad, *mytagsinkpad; + +static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS_ANY); +static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS_ANY); + +static GstElement * +setup_katedec (void) +{ + GstElement *katedec; + + GST_DEBUG ("setup_katedec"); + katedec = gst_check_setup_element ("katedec"); + mydecsrcpad = gst_check_setup_src_pad (katedec, &srctemplate, NULL); + mydecsinkpad = gst_check_setup_sink_pad (katedec, &sinktemplate, NULL); + gst_pad_set_active (mydecsrcpad, TRUE); + gst_pad_set_active (mydecsinkpad, TRUE); + + return katedec; +} + +static void +cleanup_katedec (GstElement * katedec) +{ + GST_DEBUG ("cleanup_katedec"); + gst_element_set_state (katedec, GST_STATE_NULL); + + gst_pad_set_active (mydecsrcpad, FALSE); + gst_pad_set_active (mydecsinkpad, FALSE); + gst_check_teardown_src_pad (katedec); + gst_check_teardown_sink_pad (katedec); + gst_check_teardown_element (katedec); +} + +static GstElement * +setup_kateenc (void) +{ + GstElement *kateenc; + + GST_DEBUG ("setup_kateenc"); + kateenc = gst_check_setup_element ("kateenc"); + myencsrcpad = gst_check_setup_src_pad (kateenc, &srctemplate, NULL); + myencsinkpad = gst_check_setup_sink_pad (kateenc, &sinktemplate, NULL); + gst_pad_set_active (myencsrcpad, TRUE); + gst_pad_set_active (myencsinkpad, TRUE); + + return kateenc; +} + +static void +cleanup_kateenc (GstElement * kateenc) +{ + GST_DEBUG ("cleanup_kateenc"); + gst_element_set_state (kateenc, GST_STATE_NULL); + + gst_pad_set_active (myencsrcpad, FALSE); + gst_pad_set_active (myencsinkpad, FALSE); + gst_check_teardown_src_pad (kateenc); + gst_check_teardown_sink_pad (kateenc); + gst_check_teardown_element (kateenc); +} + +static GstElement * +setup_kateparse (void) +{ + GstElement *kateparse; + + GST_DEBUG ("setup_kateparse"); + kateparse = gst_check_setup_element ("kateparse"); + myparsesrcpad = gst_check_setup_src_pad (kateparse, &srctemplate, NULL); + myparsesinkpad = gst_check_setup_sink_pad (kateparse, &sinktemplate, NULL); + gst_pad_set_active (myparsesrcpad, TRUE); + gst_pad_set_active (myparsesinkpad, TRUE); + + return kateparse; +} + +static void +cleanup_kateparse (GstElement * kateparse) +{ + GST_DEBUG ("cleanup_kateparse"); + gst_element_set_state (kateparse, GST_STATE_NULL); + + gst_pad_set_active (myparsesrcpad, FALSE); + gst_pad_set_active (myparsesinkpad, FALSE); + gst_check_teardown_src_pad (kateparse); + gst_check_teardown_sink_pad (kateparse); + gst_check_teardown_element (kateparse); +} + +static GstElement * +setup_katetag (void) +{ + GstElement *katetag; + + GST_DEBUG ("setup_katetag"); + katetag = gst_check_setup_element ("katetag"); + mytagsrcpad = gst_check_setup_src_pad (katetag, &srctemplate, NULL); + mytagsinkpad = gst_check_setup_sink_pad (katetag, &sinktemplate, NULL); + gst_pad_set_active (mytagsrcpad, TRUE); + gst_pad_set_active (mytagsinkpad, TRUE); + + return katetag; +} + +static void +cleanup_katetag (GstElement * katetag) +{ + GST_DEBUG ("cleanup_katetag"); + gst_element_set_state (katetag, GST_STATE_NULL); + + gst_pad_set_active (mytagsrcpad, FALSE); + gst_pad_set_active (mytagsinkpad, FALSE); + gst_check_teardown_src_pad (katetag); + gst_check_teardown_sink_pad (katetag); + gst_check_teardown_element (katetag); +} + +static void +check_buffers (guint expected, gboolean headers_in_caps) +{ + GstBuffer *outbuffer; + guint i, num_buffers; + const int num_headers = 9; + unsigned char packet_type; + + /* check buffers are the type we expect */ + num_buffers = g_list_length (buffers); + fail_unless (num_buffers >= num_headers + expected); /* at least 9 headers, plus a variable number of data packets */ + for (i = 0; i < num_buffers; ++i) { + outbuffer = GST_BUFFER (buffers->data); + fail_if (outbuffer == NULL); + fail_if (GST_BUFFER_SIZE (outbuffer) == 0); + + if (i < num_headers) { + /* different headers packets */ + packet_type = (0x80 | i); + fail_unless (GST_BUFFER_DATA (outbuffer)[0] == packet_type); + /* headers could be in caps, so would have an extra ref */ + } else if (i == num_buffers - 1) { + /* eos data packet */ + packet_type = 0x7f; + fail_unless (GST_BUFFER_DATA (outbuffer)[0] == packet_type); + } else { + /* data packet */ + packet_type = 0; + fail_unless (GST_BUFFER_DATA (outbuffer)[0] >= 0 + && GST_BUFFER_DATA (outbuffer)[0] < 0x7f); + } + + buffers = g_list_remove (buffers, outbuffer); + + ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1); + gst_buffer_unref (outbuffer); + outbuffer = NULL; + } +} + +GST_START_TEST (test_kate_typefind) +{ + GstTypeFindProbability prob; + const gchar *type; + GstBuffer *buf; + GstCaps *caps = NULL; + + buf = gst_buffer_new (); + GST_BUFFER_DATA (buf) = (guint8 *) kate_header_0x80; + GST_BUFFER_SIZE (buf) = sizeof (kate_header_0x80); + GST_BUFFER_OFFSET (buf) = 0; + + caps = gst_type_find_helper_for_buffer (NULL, buf, &prob); + fail_unless (caps != NULL); + GST_LOG ("Found type: %" GST_PTR_FORMAT, caps); + + type = gst_structure_get_name (gst_caps_get_structure (caps, 0)); + fail_unless_equals_string (type, "application/x-kate"); + fail_unless (prob > GST_TYPE_FIND_MINIMUM && prob <= GST_TYPE_FIND_MAXIMUM); + + gst_buffer_unref (buf); + gst_caps_unref (caps); +} + +GST_END_TEST; + +GST_START_TEST (test_kate_empty_identification_header) +{ + GstElement *katedec; + GstBuffer *inbuffer; + GstBus *bus; + + katedec = setup_katedec (); + bus = gst_bus_new (); + + fail_unless (gst_element_set_state (katedec, + GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, + "could not set to playing"); + + inbuffer = gst_buffer_new_and_alloc (0); + ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); + + /* set a bus here so we avoid getting state change messages */ + gst_element_set_bus (katedec, bus); + + fail_unless_equals_int (gst_pad_push (mydecsrcpad, inbuffer), GST_FLOW_ERROR); + /* ... but it ends up being collected on the global buffer list */ + fail_unless_equals_int (g_list_length (buffers), 0); + + gst_element_set_bus (katedec, NULL); + + /* cleanup */ + gst_object_unref (GST_OBJECT (bus)); + cleanup_katedec (katedec); +} + +GST_END_TEST; + +/* FIXME: also tests comment header */ +GST_START_TEST (test_kate_identification_header) +{ + GstElement *katedec; + GstBuffer *inbuffer; + GstBus *bus; + GstMessage *message; + GstTagList *tag_list; + gchar *language; + gchar *title; + + katedec = setup_katedec (); + fail_unless (gst_element_set_state (katedec, + GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, + "could not set to playing"); + bus = gst_bus_new (); + + inbuffer = gst_buffer_new_and_alloc (sizeof (kate_header_0x80)); + memcpy (GST_BUFFER_DATA (inbuffer), kate_header_0x80, + sizeof (kate_header_0x80)); + ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); + gst_buffer_ref (inbuffer); + + gst_element_set_bus (katedec, bus); + /* pushing gives away my reference ... */ + fail_unless (gst_pad_push (mydecsrcpad, inbuffer) == GST_FLOW_OK); + /* ... and nothing ends up on the global buffer list */ + ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); + gst_buffer_unref (inbuffer); + fail_unless (g_list_length (buffers) == 0); + + inbuffer = gst_buffer_new_and_alloc (sizeof (kate_header_0x81)); + memcpy (GST_BUFFER_DATA (inbuffer), kate_header_0x81, + sizeof (kate_header_0x81)); + ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); + gst_buffer_ref (inbuffer); + + /* pushing gives away my reference ... */ + fail_unless (gst_pad_push (mydecsrcpad, inbuffer) == GST_FLOW_OK); + /* ... and nothing ends up on the global buffer list */ + ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); + gst_buffer_unref (inbuffer); + fail_unless (g_list_length (buffers) == 0); + /* there's a tag message waiting */ + fail_if ((message = gst_bus_pop (bus)) == NULL); + gst_message_parse_tag (message, &tag_list); + fail_unless_equals_int (gst_tag_list_get_tag_size (tag_list, + GST_TAG_LANGUAGE_CODE), 1); + fail_unless (gst_tag_list_get_string (tag_list, GST_TAG_LANGUAGE_CODE, + &language)); + fail_unless_equals_string (language, "en_GB"); + g_free (language); + fail_unless_equals_int (gst_tag_list_get_tag_size (tag_list, "title"), 1); + fail_unless (gst_tag_list_get_string (tag_list, GST_TAG_TITLE, &title)); + fail_unless_equals_string (title, "Tiger"); + g_free (title); + gst_tag_list_free (tag_list); + gst_message_unref (message); + + /* cleanup */ + gst_bus_set_flushing (bus, TRUE); + gst_element_set_bus (katedec, NULL); + gst_object_unref (GST_OBJECT (bus)); + cleanup_katedec (katedec); +} + +GST_END_TEST; + +GST_START_TEST (test_kate_encode_nothing) +{ + GstElement *kateenc; + + kateenc = setup_kateenc (); + fail_unless (gst_element_set_state (kateenc, + GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, + "could not set to playing"); + + fail_unless (gst_pad_push_event (myencsrcpad, gst_event_new_eos ()) == TRUE); + + fail_unless (gst_element_set_state (kateenc, + GST_STATE_READY) == GST_STATE_CHANGE_SUCCESS, + "could not set to ready"); + + /* cleanup */ + cleanup_kateenc (kateenc); +} + +GST_END_TEST; + +GST_START_TEST (test_kate_encode_empty) +{ + GstElement *kateenc; + GstBuffer *inbuffer; + GstBus *bus; + GstCaps *caps; + + kateenc = setup_kateenc (); + fail_unless (gst_element_set_state (kateenc, + GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, + "could not set to playing"); + bus = gst_bus_new (); + + inbuffer = gst_buffer_new_and_alloc (0); + GST_BUFFER_TIMESTAMP (inbuffer) = GST_BUFFER_OFFSET (inbuffer) = + 1 * GST_SECOND; + GST_BUFFER_DURATION (inbuffer) = 5 * GST_SECOND; + ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); + gst_buffer_ref (inbuffer); + + caps = gst_caps_from_string ("text/plain"); + fail_unless (caps != NULL); + gst_buffer_set_caps (inbuffer, caps); + gst_caps_unref (caps); + + gst_element_set_bus (kateenc, bus); + /* pushing gives away my reference ... */ + fail_unless (gst_pad_push (myencsrcpad, inbuffer) == GST_FLOW_ERROR); + + fail_unless (gst_pad_push_event (myencsrcpad, gst_event_new_eos ()) == TRUE); + + fail_unless (gst_element_set_state (kateenc, + GST_STATE_READY) == GST_STATE_CHANGE_SUCCESS, + "could not set to ready"); + + gst_element_set_bus (kateenc, NULL); + + /* cleanup */ + gst_object_unref (GST_OBJECT (bus)); + cleanup_kateenc (kateenc); +} + +GST_END_TEST; + +GST_START_TEST (test_kate_encode_simple) +{ + GstElement *kateenc; + GstBuffer *inbuffer; + GstBus *bus; + const gchar *test_string = ""; + GstCaps *caps; + + kateenc = setup_kateenc (); + fail_unless (gst_element_set_state (kateenc, + GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, + "could not set to playing"); + bus = gst_bus_new (); + + inbuffer = gst_buffer_new_and_alloc (strlen (test_string) + 1); + memcpy (GST_BUFFER_DATA (inbuffer), test_string, strlen (test_string) + 1); + GST_BUFFER_TIMESTAMP (inbuffer) = GST_BUFFER_OFFSET (inbuffer) = + 1 * GST_SECOND; + GST_BUFFER_DURATION (inbuffer) = 5 * GST_SECOND; + ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); + gst_buffer_ref (inbuffer); + + caps = gst_caps_from_string ("text/plain"); + fail_unless (caps != NULL); + gst_buffer_set_caps (inbuffer, caps); + gst_caps_unref (caps); + + gst_element_set_bus (kateenc, bus); + /* pushing gives away my reference ... */ + fail_unless (gst_pad_push (myencsrcpad, inbuffer) == GST_FLOW_OK); + /* ... and nothing ends up on the global buffer list */ + ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); + gst_buffer_unref (inbuffer); + fail_unless (gst_pad_push_event (myencsrcpad, gst_event_new_eos ()) == TRUE); + + fail_unless (gst_element_set_state (kateenc, + GST_STATE_READY) == GST_STATE_CHANGE_SUCCESS, + "could not set to ready"); + + /* at least one data packet and one EOS packet should have been emitted */ + check_buffers (1 + 1, FALSE); + + /* cleanup */ + gst_bus_set_flushing (bus, TRUE); + gst_element_set_bus (kateenc, NULL); + gst_object_unref (GST_OBJECT (bus)); + cleanup_kateenc (kateenc); + g_list_free (buffers); +} + +GST_END_TEST; + +GST_START_TEST (test_kate_encode_spu) +{ + GstElement *kateenc; + GstBuffer *inbuffer; + GstBus *bus; + GstCaps *caps; + + kateenc = setup_kateenc (); + fail_unless (gst_element_set_state (kateenc, + GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, + "could not set to playing"); + bus = gst_bus_new (); + + inbuffer = gst_buffer_new_and_alloc (sizeof (kate_spu)); + memcpy (GST_BUFFER_DATA (inbuffer), kate_spu, sizeof (kate_spu)); + GST_BUFFER_TIMESTAMP (inbuffer) = GST_BUFFER_OFFSET (inbuffer) = + 1 * GST_SECOND; + GST_BUFFER_DURATION (inbuffer) = 5 * GST_SECOND; + ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); + gst_buffer_ref (inbuffer); + + caps = gst_caps_from_string ("video/x-dvd-subpicture"); + fail_unless (caps != NULL); + gst_buffer_set_caps (inbuffer, caps); + gst_caps_unref (caps); + + gst_element_set_bus (kateenc, bus); + /* pushing gives away my reference ... */ + fail_unless_equals_int (gst_pad_push (myencsrcpad, inbuffer), GST_FLOW_OK); + /* ... and nothing ends up on the global buffer list */ + ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); + gst_buffer_unref (inbuffer); + fail_unless (gst_pad_push_event (myencsrcpad, gst_event_new_eos ()) == TRUE); + + fail_unless (gst_element_set_state (kateenc, + GST_STATE_READY) == GST_STATE_CHANGE_SUCCESS, + "could not set to ready"); + + /* at least one data packet and one EOS packet should have been emitted */ + check_buffers (2, FALSE); + + /* cleanup */ + gst_bus_set_flushing (bus, TRUE); + gst_element_set_bus (kateenc, NULL); + gst_object_unref (GST_OBJECT (bus)); + cleanup_kateenc (kateenc); + g_list_free (buffers); +} + +GST_END_TEST; + +GST_START_TEST (test_kate_encode_keepalives) +{ + GstElement *kateenc; + GstBus *bus; + guint i, round; + enum + { n_keepalives = 1000 }; + static const struct + { + gdouble keepalive_min_time; + gint packets; + } cfg[3] = { + { + 0.5, n_keepalives}, { + 2.0, n_keepalives / 2}, { + 5.0, n_keepalives / 5},}; + + for (round = 0; round < 3; ++round) { + kateenc = setup_kateenc (); + fail_unless (gst_element_set_state (kateenc, + GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, + "could not set to playing"); + bus = gst_bus_new (); + + gst_element_set_bus (kateenc, bus); + + g_object_set (kateenc, "keepalive-min-time", cfg[round].keepalive_min_time, + NULL); + + /* the second one here should not emit a keepalive since the time since last packet + is less than the keepalive delay */ + for (i = 1; i <= n_keepalives; ++i) { + gint64 t = i * GST_SECOND; + fail_unless (gst_pad_push_event (myencsrcpad, + gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, t, -1, + 0)) == TRUE); + } + + fail_unless (gst_pad_push_event (myencsrcpad, + gst_event_new_eos ()) == TRUE); + + fail_unless (gst_element_set_state (kateenc, + GST_STATE_READY) == GST_STATE_CHANGE_SUCCESS, + "could not set to ready"); + + /* at least a number data packet and an EOS packet should have been emitted */ + check_buffers (cfg[round].packets + 1, FALSE); + + /* cleanup */ + gst_bus_set_flushing (bus, TRUE); + gst_element_set_bus (kateenc, NULL); + gst_object_unref (GST_OBJECT (bus)); + cleanup_kateenc (kateenc); + g_list_free (buffers); + } +} + +GST_END_TEST; + +static void +test_kate_send_headers (GstPad * pad) +{ + GstBuffer *inbuffer; + int i; + + /* push headers */ + inbuffer = gst_buffer_new (); + GST_BUFFER_DATA (inbuffer) = (guint8 *) kate_header_0x80; + GST_BUFFER_SIZE (inbuffer) = sizeof (kate_header_0x80); + GST_BUFFER_OFFSET (inbuffer) = GST_BUFFER_OFFSET_END (inbuffer) = 0; + fail_unless_equals_int (gst_pad_push (pad, inbuffer), GST_FLOW_OK); + + inbuffer = gst_buffer_new (); + GST_BUFFER_DATA (inbuffer) = (guint8 *) kate_header_0x81; + GST_BUFFER_SIZE (inbuffer) = sizeof (kate_header_0x81); + GST_BUFFER_OFFSET (inbuffer) = GST_BUFFER_OFFSET_END (inbuffer) = 0; + fail_unless_equals_int (gst_pad_push (pad, inbuffer), GST_FLOW_OK); + + for (i = 2; i < 8; ++i) { + inbuffer = gst_buffer_new_and_alloc (sizeof (kate_header_0x8x)); + memcpy (GST_BUFFER_DATA (inbuffer), (guint8 *) kate_header_0x8x, + sizeof (kate_header_0x8x)); + GST_BUFFER_DATA (inbuffer)[0] = 0x80 | i; + GST_BUFFER_OFFSET (inbuffer) = GST_BUFFER_OFFSET_END (inbuffer) = 0; + fail_unless_equals_int (gst_pad_push (pad, inbuffer), GST_FLOW_OK); + } + + inbuffer = gst_buffer_new (); + GST_BUFFER_DATA (inbuffer) = (guint8 *) kate_header_0x88; + GST_BUFFER_SIZE (inbuffer) = sizeof (kate_header_0x88); + GST_BUFFER_OFFSET (inbuffer) = GST_BUFFER_OFFSET_END (inbuffer) = 0; + fail_unless_equals_int (gst_pad_push (pad, inbuffer), GST_FLOW_OK); +} + +GST_START_TEST (test_kate_parse) +{ + GstElement *kateparse; + GstBuffer *inbuffer; + GstBus *bus; + + kateparse = setup_kateparse (); + fail_unless (gst_element_set_state (kateparse, + GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, + "could not set to playing"); + bus = gst_bus_new (); + + gst_element_set_bus (kateparse, bus); + + test_kate_send_headers (myparsesrcpad); + + /* push a text packet */ + inbuffer = gst_buffer_new (); + GST_BUFFER_DATA (inbuffer) = (guint8 *) kate_header_0x00; + GST_BUFFER_SIZE (inbuffer) = sizeof (kate_header_0x00); + GST_BUFFER_TIMESTAMP (inbuffer) = GST_BUFFER_OFFSET (inbuffer) = + 1 * GST_SECOND; + GST_BUFFER_DURATION (inbuffer) = 5 * GST_SECOND; + GST_BUFFER_OFFSET_END (inbuffer) = (GST_BUFFER_TIMESTAMP (inbuffer) << 32); /* granpos */ + fail_unless_equals_int (gst_pad_push (myparsesrcpad, inbuffer), GST_FLOW_OK); + + /* push a eos packet */ + inbuffer = gst_buffer_new (); + GST_BUFFER_DATA (inbuffer) = (guint8 *) kate_header_0x7f; + GST_BUFFER_SIZE (inbuffer) = sizeof (kate_header_0x7f); + GST_BUFFER_TIMESTAMP (inbuffer) = GST_BUFFER_OFFSET (inbuffer) = + 6 * GST_SECOND; + GST_BUFFER_DURATION (inbuffer) = 0; + GST_BUFFER_OFFSET_END (inbuffer) = (GST_BUFFER_TIMESTAMP (inbuffer) << 32); /* granpos */ + fail_unless_equals_int (gst_pad_push (myparsesrcpad, inbuffer), GST_FLOW_OK); + + /* signal eos */ + fail_unless (gst_pad_push_event (myparsesrcpad, + gst_event_new_eos ()) == TRUE); + + fail_unless (gst_element_set_state (kateparse, + GST_STATE_READY) == GST_STATE_CHANGE_SUCCESS, + "could not set to ready"); + + /* at least one data packet and one EOS packet should have been emitted */ + check_buffers (2, TRUE); + + /* cleanup */ + gst_bus_set_flushing (bus, TRUE); + gst_element_set_bus (kateparse, NULL); + gst_object_unref (GST_OBJECT (bus)); + cleanup_kateparse (kateparse); + g_list_free (buffers); +} + +GST_END_TEST; + +GST_START_TEST (test_kate_tag_passthrough) +{ + GstElement *katetag; + GstBus *bus; + GstBuffer *outbuffer; + GList *list; + + katetag = setup_katetag (); + fail_unless (gst_element_set_state (katetag, + GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, + "could not set to playing"); + bus = gst_bus_new (); + + gst_element_set_bus (katetag, bus); + + test_kate_send_headers (mytagsrcpad); + + /* signal eos */ + fail_unless (gst_pad_push_event (mytagsrcpad, gst_event_new_eos ()) == TRUE); + + fail_unless (gst_element_set_state (katetag, + GST_STATE_READY) == GST_STATE_CHANGE_SUCCESS, + "could not set to ready"); + + /* get the first buffer and check language/category */ + fail_unless (g_list_length (buffers) >= 2); /* ID header, Vorbis comments header */ + outbuffer = GST_BUFFER (buffers->data); + fail_if (outbuffer == NULL); + + /* check identification header is unchanged */ + list = g_list_nth (buffers, 0); + fail_unless (list != NULL); + outbuffer = list->data; + fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), + sizeof (kate_header_0x80)); + fail_unless_equals_int (memcmp (GST_BUFFER_DATA (outbuffer), kate_header_0x80, + sizeof (kate_header_0x80)), 0); + + /* check comment header is unchanged */ + list = g_list_nth (buffers, 1); + fail_unless (list != NULL); + outbuffer = list->data; + fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), + sizeof (kate_header_0x81)); + fail_unless_equals_int (memcmp (GST_BUFFER_DATA (outbuffer), kate_header_0x81, + sizeof (kate_header_0x81)), 0); + + /* all headers should have been emitted, but no particular packets */ + check_buffers (0, TRUE); + + /* cleanup */ + gst_bus_set_flushing (bus, TRUE); + gst_element_set_bus (katetag, NULL); + gst_object_unref (GST_OBJECT (bus)); + cleanup_katetag (katetag); + g_list_free (buffers); +} + +GST_END_TEST; + +GST_START_TEST (test_kate_tag) +{ + GstElement *katetag; + GstBus *bus; + GstBuffer *outbuffer; + + katetag = setup_katetag (); + fail_unless (gst_element_set_state (katetag, + GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, + "could not set to playing"); + bus = gst_bus_new (); + + gst_element_set_bus (katetag, bus); + + g_object_set (katetag, "language", "cy", NULL); + g_object_set (katetag, "category", "subtitles", NULL); + + test_kate_send_headers (mytagsrcpad); + + /* signal eos */ + fail_unless (gst_pad_push_event (mytagsrcpad, gst_event_new_eos ()) == TRUE); + + fail_unless (gst_element_set_state (katetag, + GST_STATE_READY) == GST_STATE_CHANGE_SUCCESS, + "could not set to ready"); + + /* get the first buffer and check language/category */ + fail_unless (g_list_length (buffers) >= 1); + outbuffer = GST_BUFFER (buffers->data); + fail_if (outbuffer == NULL); + fail_if (GST_BUFFER_SIZE (outbuffer) != 64); + fail_if (strcmp ((const char *) GST_BUFFER_DATA (outbuffer) + 32, "cy")); + fail_if (strcmp ((const char *) GST_BUFFER_DATA (outbuffer) + 48, + "subtitles")); + + /* all headers should have been emitted, but no particular packets */ + check_buffers (0, TRUE); + + /* cleanup */ + gst_bus_set_flushing (bus, TRUE); + gst_element_set_bus (katetag, NULL); + gst_object_unref (GST_OBJECT (bus)); + cleanup_katetag (katetag); + g_list_free (buffers); +} + +GST_END_TEST; + +Suite * +kate_suite (void) +{ + Suite *s = suite_create ("kate"); + TCase *tc_chain = tcase_create ("general"); + + suite_add_tcase (s, tc_chain); + +#define X if (0) + tcase_add_test (tc_chain, test_kate_typefind); + tcase_add_test (tc_chain, test_kate_empty_identification_header); + tcase_add_test (tc_chain, test_kate_identification_header); + tcase_add_test (tc_chain, test_kate_encode_nothing); + tcase_add_test (tc_chain, test_kate_encode_empty); + tcase_add_test (tc_chain, test_kate_encode_simple); + tcase_add_test (tc_chain, test_kate_encode_spu); + tcase_add_test (tc_chain, test_kate_encode_keepalives); + tcase_add_test (tc_chain, test_kate_parse); + tcase_add_test (tc_chain, test_kate_tag_passthrough); + tcase_add_test (tc_chain, test_kate_tag); +#undef X + + return s; +} + +int +main (int argc, char **argv) +{ + int nf; + + Suite *s = kate_suite (); + SRunner *sr = srunner_create (s); + + gst_check_init (&argc, &argv); + + srunner_run_all (sr, CK_NORMAL); + nf = srunner_ntests_failed (sr); + srunner_free (sr); + + return nf; +} -- cgit v1.2.1 From 71efbb1e73a557d50093ccaf2ecc47009b7edd95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Sun, 19 Jul 2009 22:29:19 +0100 Subject: kate: fix up for additional subtitle/x-kate media type --- tests/check/elements/kate.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests') diff --git a/tests/check/elements/kate.c b/tests/check/elements/kate.c index f7ac3ed4..80ea6882 100644 --- a/tests/check/elements/kate.c +++ b/tests/check/elements/kate.c @@ -40,20 +40,25 @@ static const guint8 kate_header_0x81[53] = { 0x72, 0x29, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x54, 0x49, 0x54, 0x4c, 0x45, 0x3d, /* r)........TITLE= */ 0x54, 0x69, 0x67, 0x65, 0x72, /* Tiger */ }; + static const guint8 kate_header_0x8x[10] = { 0x80, 0x6b, 0x61, 0x74, 0x65, 0x00, 0x00, 0x00, 0x00 }; + static const guint8 kate_header_0x88[11] = { 0x88, 0x6b, 0x61, 0x74, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00 }; + static const guint8 kate_header_0x00[45] = { 0x00, 0xe8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, /* ................ */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x70, 0x6c, 0x61, /* .............pla */ 0x69, 0x6e, 0x20, 0x6f, 0x6c, 0x64, 0x20, 0x74, 0x65, 0x78, 0x74, 0x08, 0x00 /* in old text.. */ }; + static const guint8 kate_header_0x01[1] = { 0x01 }; + static const guint8 kate_header_0x7f[1] = { 0x7f }; @@ -600,16 +605,21 @@ static void test_kate_send_headers (GstPad * pad) { GstBuffer *inbuffer; + GstCaps *caps; int i; + caps = gst_caps_new_simple ("subtitle/x-kate", NULL); + /* push headers */ inbuffer = gst_buffer_new (); + gst_buffer_set_caps (inbuffer, caps); GST_BUFFER_DATA (inbuffer) = (guint8 *) kate_header_0x80; GST_BUFFER_SIZE (inbuffer) = sizeof (kate_header_0x80); GST_BUFFER_OFFSET (inbuffer) = GST_BUFFER_OFFSET_END (inbuffer) = 0; fail_unless_equals_int (gst_pad_push (pad, inbuffer), GST_FLOW_OK); inbuffer = gst_buffer_new (); + gst_buffer_set_caps (inbuffer, caps); GST_BUFFER_DATA (inbuffer) = (guint8 *) kate_header_0x81; GST_BUFFER_SIZE (inbuffer) = sizeof (kate_header_0x81); GST_BUFFER_OFFSET (inbuffer) = GST_BUFFER_OFFSET_END (inbuffer) = 0; @@ -617,6 +627,7 @@ test_kate_send_headers (GstPad * pad) for (i = 2; i < 8; ++i) { inbuffer = gst_buffer_new_and_alloc (sizeof (kate_header_0x8x)); + gst_buffer_set_caps (inbuffer, caps); memcpy (GST_BUFFER_DATA (inbuffer), (guint8 *) kate_header_0x8x, sizeof (kate_header_0x8x)); GST_BUFFER_DATA (inbuffer)[0] = 0x80 | i; @@ -625,10 +636,13 @@ test_kate_send_headers (GstPad * pad) } inbuffer = gst_buffer_new (); + gst_buffer_set_caps (inbuffer, caps); GST_BUFFER_DATA (inbuffer) = (guint8 *) kate_header_0x88; GST_BUFFER_SIZE (inbuffer) = sizeof (kate_header_0x88); GST_BUFFER_OFFSET (inbuffer) = GST_BUFFER_OFFSET_END (inbuffer) = 0; fail_unless_equals_int (gst_pad_push (pad, inbuffer), GST_FLOW_OK); + + gst_caps_unref (caps); } GST_START_TEST (test_kate_parse) -- cgit v1.2.1 From 0d16612717860fff76a9c1889d47f7f5fe0fbf7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Sun, 19 Jul 2009 23:29:19 +0100 Subject: checks: add kate unit tests to valgrind blacklist for now And add check binary to ignore list. --- tests/check/Makefile.am | 1 + tests/check/elements/.gitignore | 2 ++ 2 files changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index 1aa99d1a..41581363 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -71,6 +71,7 @@ endif VALGRIND_TO_FIX = \ + elements/kate \ elements/mpeg2enc \ elements/mplex diff --git a/tests/check/elements/.gitignore b/tests/check/elements/.gitignore index 5f268d3b..df2bb15d 100644 --- a/tests/check/elements/.gitignore +++ b/tests/check/elements/.gitignore @@ -6,6 +6,7 @@ deinterleave gdpdepay gdppay interleave +kate legacyresample mpeg2enc mplex @@ -19,6 +20,7 @@ rganalysis rglimiter rgvolume rtpbin +rtpbin_buffer_list selector shapewipe spectrum -- cgit v1.2.1 From cae6b621aaa64bbfdda102e8295b9035e0c42fa8 Mon Sep 17 00:00:00 2001 From: Stefan Kost Date: Mon, 20 Jul 2009 10:17:07 +0300 Subject: camerabin: improve perf test robustness and add comments --- tests/examples/camerabin/gst-camera-perf.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/examples/camerabin/gst-camera-perf.c b/tests/examples/camerabin/gst-camera-perf.c index cadffa2b..56d8b401 100644 --- a/tests/examples/camerabin/gst-camera-perf.c +++ b/tests/examples/camerabin/gst-camera-perf.c @@ -39,7 +39,8 @@ * ./gst-camera-perf --src-colorspace=UYVY --image-width=640 --image-height=480 --view-framerate-num=2999 --view-framerate-den=100 --video-src=v4l2camsrc --audio-enc=nokiaaacenc --video-enc=omx_mpeg4enc --video-mux=hantromp4mux * ./gst-camera-perf --src-colorspace=UYVY --image-width=2592 --image-height=1968 --view-framerate-num=399 --view-framerate-den=100 --video-src=v4l2camsrc --audio-enc=nokiaaacenc --video-enc=omx_mpeg4enc --video-mux=hantromp4mux * ./gst-camera-perf --src-colorspace=UYVY --image-width=2592 --image-height=1968 --view-framerate-num=325 --view-framerate-den=25 --video-src=v4l2camsrc --audio-enc=nokiaaacenc --video-enc=omx_mpeg4enc --video-mux=hantromp4mux --image-enc=dspjpegenc - * ./gst-camera-perf --src-colorspace=UYVY --image-width=640 --image-height=480 --view-framerate-num=1491 --view-framerate-den=100 --video-src=v4l2camsrc --audio-enc=nokiaaacenc --video-enc=omx_mpeg4enc --video-mux=hantromp4mux --target-times=1000,0,1500,0,0,0,0,1000,0 + * ./gst-camera-perf --src-colorspace=UYVY --image-width=640 --image-height=480 --view-framerate-num=1491 --view-framerate-den=100 --video-src=v4l2camsrc --audio-enc=nokiaaacenc --video-enc=dspmpeg4enc --video-mux=hantromp4mux --image-enc=dspjpegenc --target-times=1000,1500,1500,2000,500,2000,3500,1000,1000 + * ./gst-camera-perf --src-colorspace=UYVY --image-width=2576 --image-height=1936 --view-framerate-num=1491 --view-framerate-den=100 --video-src=v4l2camsrc --audio-enc=nokiaaacenc --video-enc=omx_mpeg4enc --video-mux=hantromp4mux */ /* @@ -217,21 +218,25 @@ element_added (GstBin * bin, GstElement * element, gpointer user_data) if (need_vmux_pad_probe) { g_object_get (camera_bin, "videomux", &elem, NULL); if (elem) { - setup_add_pad_probe (elem, "src", (GCallback) pad_has_buffer, - &signal_vid_sink); need_vmux_pad_probe = FALSE; - target[8] = test_09_taget; GST_INFO_OBJECT (elem, "got default video muxer"); + if (setup_add_pad_probe (elem, "src", (GCallback) pad_has_buffer, + &signal_vid_sink)) { + /* enable test */ + target[8] = test_09_taget; + } } } if (need_ienc_pad_probe) { g_object_get (camera_bin, "imageenc", &elem, NULL); if (elem) { - setup_add_pad_probe (elem, "src", (GCallback) pad_has_buffer, - &signal_img_enc); need_ienc_pad_probe = FALSE; - target[5] = test_06_taget; GST_INFO_OBJECT (elem, "got default image encoder"); + if (setup_add_pad_probe (elem, "src", (GCallback) pad_has_buffer, + &signal_img_enc)) { + /* enable test */ + target[5] = test_06_taget; + } } } } @@ -552,6 +557,7 @@ setup_pipeline (void) g_object_get (camera_bin, "videomux", &vmux, NULL); if (!vmux) { need_pad_probe = need_vmux_pad_probe = TRUE; + /* only run the test if we later get the element */ test_09_taget = target[8]; target[8] = G_GUINT64_CONSTANT (0); } @@ -566,6 +572,7 @@ setup_pipeline (void) g_object_get (camera_bin, "imageenc", &ienc, NULL); if (!ienc) { need_pad_probe = need_ienc_pad_probe = TRUE; + /* only run the test if we later get the element */ test_06_taget = target[5]; target[5] = G_GUINT64_CONSTANT (0); } @@ -847,7 +854,7 @@ run_test (gpointer user_data) gboolean ret = TRUE; guint old_test_ix = test_ix; - if (test_ix == TEST_CASES) { + if (test_ix >= TEST_CASES) { GST_INFO ("done"); g_main_loop_quit (loop); return FALSE; @@ -884,7 +891,7 @@ run_test (gpointer user_data) g_main_loop_quit (loop); return FALSE; } - if (test_ix == TEST_CASES) { + if (test_ix >= TEST_CASES) { GST_INFO ("done"); g_main_loop_quit (loop); return FALSE; -- cgit v1.2.1 From 8ac16a90e4d0cc05a5c1c84c0c04bded901795bb Mon Sep 17 00:00:00 2001 From: Stefan Kost Date: Mon, 20 Jul 2009 16:39:42 +0300 Subject: camerabin: add code in test to store snapshots for manual verification Use gdk_pixbuf to save the image in perf-test. Also remove some obsolute commented out code. --- tests/examples/camerabin/gst-camera-perf.c | 38 +++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/examples/camerabin/gst-camera-perf.c b/tests/examples/camerabin/gst-camera-perf.c index 56d8b401..2337321d 100644 --- a/tests/examples/camerabin/gst-camera-perf.c +++ b/tests/examples/camerabin/gst-camera-perf.c @@ -32,7 +32,7 @@ * gcc `pkg-config --cflags --libs gstreamer-0.10` gst-camera-perf.c -ogst-camera-perf * * plain linux: - * ./gst-camera-perf --src-colorspace=YUY2 --image-width=320 --image-height=240 --view-framerate-num=15 --view-framerate-den=1 + * ./gst-camera-perf --src-colorspace=YUY2 --image-width=640 --image-height=480 --view-framerate-num=15 --view-framerate-den=1 * * maemo: * ./gst-camera-perf --src-colorspace=UYVY --image-width=640 --image-height=480 --view-framerate-num=1491 --view-framerate-den=100 --video-src=v4l2camsrc --audio-enc=nokiaaacenc --video-enc=omx_mpeg4enc --video-mux=hantromp4mux @@ -50,11 +50,18 @@ # include "config.h" #endif +/* save the snapshot images + * gcc `pkg-config --cflags --libs gstreamer-0.10 gdk-pixbuf-2.0` gst-camera-perf.c -ogst-camera-perf + * +#define SAVE_SNAPSHOT 1 + **/ #include +#ifdef SAVE_SNAPSHOT +#include +#endif #include #include #include - /* * debug logging */ @@ -422,6 +429,29 @@ bus_callback (GstBus * bus, GstMessage * message, gpointer data) g_object_set (camera_bin, "preview-caps", NULL, NULL); break; } +#ifdef SAVE_SNAPSHOT + { + const GValue *value = gst_structure_get_value (st, "buffer"); + GstBuffer *buf = gst_value_get_buffer (value); + GstCaps *caps = GST_BUFFER_CAPS (buf); + GstStructure *buf_st = gst_caps_get_structure (caps, 0); + guchar *data = GST_BUFFER_DATA (buf); + gint width, height, rowstride; + GdkPixbuf *pixbuf; + + GST_INFO ("preview : buf=%p, size=%d, format=%" GST_PTR_FORMAT, + buf, GST_BUFFER_SIZE (buf), caps); + gst_structure_get_int (buf_st, "width", &width); + gst_structure_get_int (buf_st, "height", &height); + rowstride = GST_ROUND_UP_4 (width * 3); + //GST_INFO ("rowstride : %d, %d", rowstride, width*3); + pixbuf = gdk_pixbuf_new_from_data (data, GDK_COLORSPACE_RGB, FALSE, + 8, width, height, rowstride, NULL, NULL); + gdk_pixbuf_save (pixbuf, "/tmp/gst-camerabin-preview.png", "png", + NULL, NULL); + gdk_pixbuf_unref (pixbuf); + } +#endif } } /* unhandled message */ @@ -632,10 +662,6 @@ test_01 (void) GET_TIME (t_initial); if (setup_pipeline ()) { - /* MAKE SURE THE PIPELINE IS IN PLAYING STATE BEFORE START TAKING PICTURES - AND SO ON (otherwise it will deadlock) */ - - //gst_element_get_state (camera_bin, NULL, NULL, GST_CLOCK_TIME_NONE); /* the actual results are fetched in bus_callback::state-changed */ res = FALSE; } else { -- cgit v1.2.1 From 265b75ca38913c7a9c0281d472f93e7936b6fa91 Mon Sep 17 00:00:00 2001 From: "ogg.k.ogg.k" Date: Mon, 20 Jul 2009 16:24:23 +0100 Subject: kate: fix some minor memory leaks Makes 'make check-valgrind' work for the kate unit test (#525743) --- tests/check/Makefile.am | 1 - tests/check/elements/kate.c | 1 - 2 files changed, 2 deletions(-) (limited to 'tests') diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index 41581363..1aa99d1a 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -71,7 +71,6 @@ endif VALGRIND_TO_FIX = \ - elements/kate \ elements/mpeg2enc \ elements/mplex diff --git a/tests/check/elements/kate.c b/tests/check/elements/kate.c index 80ea6882..551d72a1 100644 --- a/tests/check/elements/kate.c +++ b/tests/check/elements/kate.c @@ -413,7 +413,6 @@ GST_START_TEST (test_kate_encode_empty) 1 * GST_SECOND; GST_BUFFER_DURATION (inbuffer) = 5 * GST_SECOND; ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - gst_buffer_ref (inbuffer); caps = gst_caps_from_string ("text/plain"); fail_unless (caps != NULL); -- cgit v1.2.1 From ced14a1ff7a0a7190be214848d3de5af2ab7b0ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Tue, 21 Jul 2009 00:54:47 +0100 Subject: katedec: only put primary language tag in GST_TAG_LANGUAGE Only put primary language into GST_TAG_LANGUAGE, and convert to lower case, ie. only use "en" of "en_GB". This is per our tag documentation and hence what apps expect. Also add example to kateenc property description so people know a language code is wanted here. --- tests/check/elements/kate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/check/elements/kate.c b/tests/check/elements/kate.c index 551d72a1..c848cc5c 100644 --- a/tests/check/elements/kate.c +++ b/tests/check/elements/kate.c @@ -356,7 +356,7 @@ GST_START_TEST (test_kate_identification_header) GST_TAG_LANGUAGE_CODE), 1); fail_unless (gst_tag_list_get_string (tag_list, GST_TAG_LANGUAGE_CODE, &language)); - fail_unless_equals_string (language, "en_GB"); + fail_unless_equals_string (language, "en"); g_free (language); fail_unless_equals_int (gst_tag_list_get_tag_size (tag_list, "title"), 1); fail_unless (gst_tag_list_get_string (tag_list, GST_TAG_TITLE, &title)); -- cgit v1.2.1 From b3753116d22f90a992f6ec8b4a876faca3a3ebfc Mon Sep 17 00:00:00 2001 From: Stefan Kost Date: Tue, 21 Jul 2009 16:48:26 +0300 Subject: camerabin: we need to copy the data in the example gdk_pixbuf_new_from_data does not copy the data. --- tests/examples/camerabin/gst-camera-perf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/examples/camerabin/gst-camera-perf.c b/tests/examples/camerabin/gst-camera-perf.c index 2337321d..ba8ff6a6 100644 --- a/tests/examples/camerabin/gst-camera-perf.c +++ b/tests/examples/camerabin/gst-camera-perf.c @@ -435,16 +435,18 @@ bus_callback (GstBus * bus, GstMessage * message, gpointer data) GstBuffer *buf = gst_value_get_buffer (value); GstCaps *caps = GST_BUFFER_CAPS (buf); GstStructure *buf_st = gst_caps_get_structure (caps, 0); - guchar *data = GST_BUFFER_DATA (buf); gint width, height, rowstride; GdkPixbuf *pixbuf; + guchar *data; GST_INFO ("preview : buf=%p, size=%d, format=%" GST_PTR_FORMAT, buf, GST_BUFFER_SIZE (buf), caps); + + data = g_memdup (GST_BUFFER_DATA (buff), GST_BUFFER_SIZE (buff)); gst_structure_get_int (buf_st, "width", &width); gst_structure_get_int (buf_st, "height", &height); rowstride = GST_ROUND_UP_4 (width * 3); - //GST_INFO ("rowstride : %d, %d", rowstride, width*3); + pixbuf = gdk_pixbuf_new_from_data (data, GDK_COLORSPACE_RGB, FALSE, 8, width, height, rowstride, NULL, NULL); gdk_pixbuf_save (pixbuf, "/tmp/gst-camerabin-preview.png", "png", -- cgit v1.2.1 From 7e7c63737ecb9b54f16a6d651ece7c3c716b9f16 Mon Sep 17 00:00:00 2001 From: Stefan Kost Date: Wed, 22 Jul 2009 17:05:29 +0300 Subject: camerabin: more perf-test cleanups Remove some obsolete exmaples. Add video-width/height. Use proper api for setting still image resolution. Fix stopping random tests on bin-state-changes. Remove the memdup in snapshot again, as its not needed (pixbuf goes out of scope with the buffer). --- tests/examples/camerabin/gst-camera-perf.c | 63 +++++++++++++++++++----------- 1 file changed, 40 insertions(+), 23 deletions(-) (limited to 'tests') diff --git a/tests/examples/camerabin/gst-camera-perf.c b/tests/examples/camerabin/gst-camera-perf.c index ba8ff6a6..8aa62e9c 100644 --- a/tests/examples/camerabin/gst-camera-perf.c +++ b/tests/examples/camerabin/gst-camera-perf.c @@ -32,15 +32,12 @@ * gcc `pkg-config --cflags --libs gstreamer-0.10` gst-camera-perf.c -ogst-camera-perf * * plain linux: - * ./gst-camera-perf --src-colorspace=YUY2 --image-width=640 --image-height=480 --view-framerate-num=15 --view-framerate-den=1 + * ./gst-camera-perf --src-colorspace=YUY2 --image-width=640 --image-height=480 --video-width=640 --video-height=480 --view-framerate-num=15 --view-framerate-den=1 * * maemo: - * ./gst-camera-perf --src-colorspace=UYVY --image-width=640 --image-height=480 --view-framerate-num=1491 --view-framerate-den=100 --video-src=v4l2camsrc --audio-enc=nokiaaacenc --video-enc=omx_mpeg4enc --video-mux=hantromp4mux - * ./gst-camera-perf --src-colorspace=UYVY --image-width=640 --image-height=480 --view-framerate-num=2999 --view-framerate-den=100 --video-src=v4l2camsrc --audio-enc=nokiaaacenc --video-enc=omx_mpeg4enc --video-mux=hantromp4mux - * ./gst-camera-perf --src-colorspace=UYVY --image-width=2592 --image-height=1968 --view-framerate-num=399 --view-framerate-den=100 --video-src=v4l2camsrc --audio-enc=nokiaaacenc --video-enc=omx_mpeg4enc --video-mux=hantromp4mux - * ./gst-camera-perf --src-colorspace=UYVY --image-width=2592 --image-height=1968 --view-framerate-num=325 --view-framerate-den=25 --video-src=v4l2camsrc --audio-enc=nokiaaacenc --video-enc=omx_mpeg4enc --video-mux=hantromp4mux --image-enc=dspjpegenc - * ./gst-camera-perf --src-colorspace=UYVY --image-width=640 --image-height=480 --view-framerate-num=1491 --view-framerate-den=100 --video-src=v4l2camsrc --audio-enc=nokiaaacenc --video-enc=dspmpeg4enc --video-mux=hantromp4mux --image-enc=dspjpegenc --target-times=1000,1500,1500,2000,500,2000,3500,1000,1000 - * ./gst-camera-perf --src-colorspace=UYVY --image-width=2576 --image-height=1936 --view-framerate-num=1491 --view-framerate-den=100 --video-src=v4l2camsrc --audio-enc=nokiaaacenc --video-enc=omx_mpeg4enc --video-mux=hantromp4mux + * ./gst-camera-perf --src-colorspace=UYVY --image-width=640 --image-height=480 --video-width=640 --video-height=480 --view-framerate-num=1491 --view-framerate-den=100 --video-src=v4l2camsrc --audio-enc=nokiaaacenc --video-enc=dspmpeg4enc --video-mux=hantromp4mux --image-enc=dspjpegenc --target-times=1000,1500,1500,2000,500,2000,3500,1000,1000 + * ./gst-camera-perf --src-colorspace=UYVY --image-width=2576 --image-height=1936 --video-width=640 --video-height=480 --view-framerate-num=2999 --view-framerate-den=100 --video-src=v4l2camsrc --audio-enc=nokiaaacenc --video-enc=dspmpeg4enc --video-mux=hantromp4mux + * ./gst-camera-perf --src-colorspace=UYVY --image-width=2576 --image-height=1936 --video-width=640 --video-height=480 --view-framerate-num=126 --view-framerate-den=5 --video-src=v4l2camsrc --audio-enc=nokiaaacenc --video-enc=dspmpeg4enc --video-mux=hantromp4mux --image-enc=dspjpegenc */ /* @@ -108,6 +105,8 @@ static gchar *videomux_name = NULL; static gchar *src_csp = NULL; static gint image_width = 0; static gint image_height = 0; +static gint video_width = 0; +static gint video_height = 0; static gint view_framerate_num = 0; static gint view_framerate_den = 0; @@ -188,15 +187,15 @@ pad_has_buffer (GstPad * pad, GstBuffer * buf, gpointer user_data) GET_TIME (t_final[0]); GST_DEBUG_OBJECT (pad, "%2d pad has buffer", test_ix); switch (test_ix) { - case 5: + case 5: // shutter lag DIFF_TIME (t_final[num_pics_cont], t_initial, diff); result.avg = result.min = result.max = diff; print_and_restart = TRUE; break; - case 8: + case 8: // video recording start DIFF_TIME (t_final[num_pics_cont], t_initial, diff); result.avg = result.min = result.max = diff; - g_signal_emit_by_name (camera_bin, "user-stop", 0); + //g_signal_emit_by_name (camera_bin, "user-stop", 0); print_and_restart = TRUE; break; default: @@ -207,7 +206,6 @@ pad_has_buffer (GstPad * pad, GstBuffer * buf, gpointer user_data) if (print_and_restart) { print_result (); g_idle_add ((GSourceFunc) run_test, NULL); - return FALSE; } return TRUE; } @@ -382,12 +380,16 @@ bus_callback (GstBus * bus, GstMessage * message, gpointer data) if (GST_MESSAGE_SRC (message) == GST_OBJECT (camera_bin)) { if (GST_STATE_TRANSITION (oldstate, newstate) == GST_STATE_CHANGE_PAUSED_TO_PLAYING) { - GET_TIME (t_final[0]); - DIFF_TIME (t_final[0], t_initial, diff); - - result.avg = result.min = result.max = diff; - print_result (); - g_idle_add ((GSourceFunc) run_test, NULL); + switch (test_ix) { + case 0: // camera on + GET_TIME (t_final[0]); + DIFF_TIME (t_final[0], t_initial, diff); + + result.avg = result.min = result.max = diff; + print_result (); + g_idle_add ((GSourceFunc) run_test, NULL); + break; + } } } } @@ -442,7 +444,7 @@ bus_callback (GstBus * bus, GstMessage * message, gpointer data) GST_INFO ("preview : buf=%p, size=%d, format=%" GST_PTR_FORMAT, buf, GST_BUFFER_SIZE (buf), caps); - data = g_memdup (GST_BUFFER_DATA (buff), GST_BUFFER_SIZE (buff)); + data = GST_BUFFER_DATA (buff); gst_structure_get_int (buf_st, "width", &width); gst_structure_get_int (buf_st, "height", &height); rowstride = GST_ROUND_UP_4 (width * 3); @@ -621,10 +623,15 @@ setup_pipeline (void) } GST_INFO_OBJECT (camera_bin, "probe signals connected"); - /* configure a resolution and framerate */ - if (image_width && image_height && view_framerate_num && view_framerate_den) { - g_signal_emit_by_name (camera_bin, "user-res-fps", image_width, - image_height, view_framerate_num, view_framerate_den, NULL); + /* configure a resolution and framerate for video and viewfinder */ + if (image_width && image_height) { + g_signal_emit_by_name (camera_bin, "user-image-res", image_width, + image_height, NULL); + } + /* configure a resolution and framerate for video and viewfinder */ + if (video_width && video_height && view_framerate_num && view_framerate_den) { + g_signal_emit_by_name (camera_bin, "user-res-fps", video_width, + video_height, view_framerate_num, view_framerate_den, NULL); } if (GST_STATE_CHANGE_FAILURE == @@ -866,7 +873,11 @@ static test_case test_cases[TEST_CASES] = { static void print_result (void) { - printf ("| %6.02f%% ", 100.0f * (float) result.max / (float) target[test_ix]); + if (test_ix >= TEST_CASES) { + GST_WARNING ("text case index overrun"); + return; + } + printf ("| %6.02f%% ", 100.0f * (float) result.avg / (float) target[test_ix]); printf ("|%5u ms ", (guint) GST_TIME_AS_MSECONDS (target[test_ix])); printf ("|%5u ms ", (guint) GST_TIME_AS_MSECONDS (result.avg)); printf ("|%5u ms ", (guint) GST_TIME_AS_MSECONDS (result.min)); @@ -889,6 +900,7 @@ run_test (gpointer user_data) } printf ("| %02d ", test_ix + 1); + fflush (stdout); if (test_cases[test_ix]) { if (target[test_ix]) { memset (&result, 0, sizeof (ResultType)); @@ -908,6 +920,7 @@ run_test (gpointer user_data) printf ("| %-19s |\n", test_names[test_ix]); test_ix++; } + fflush (stdout); if (old_test_ix == 0 && ret == TRUE && !camera_bin) { GST_INFO ("done (camerabin creation failed)"); @@ -949,6 +962,10 @@ main (int argc, char *argv[]) "width for image capture", NULL}, {"image-height", '\0', 0, G_OPTION_ARG_INT, &image_height, "height for image capture", NULL}, + {"video-width", '\0', 0, G_OPTION_ARG_INT, &video_width, + "width for image capture", NULL}, + {"video-height", '\0', 0, G_OPTION_ARG_INT, &video_height, + "height for image capture", NULL}, {"view-framerate-num", '\0', 0, G_OPTION_ARG_INT, &view_framerate_num, "framerate numerator for viewfinder", NULL}, {"view-framerate-den", '\0', 0, G_OPTION_ARG_INT, &view_framerate_den, -- cgit v1.2.1