18 * You should have received a copy of the GNU Library General Public |
18 * You should have received a copy of the GNU Library General Public |
19 * License along with this library; if not, write to the |
19 * License along with this library; if not, write to the |
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
21 * Boston, MA 02111-1307, USA. |
21 * Boston, MA 02111-1307, USA. |
22 */ |
22 */ |
|
23 |
|
24 |
23 #include <gst/gst_global.h> |
25 #include <gst/gst_global.h> |
24 #include <unistd.h> |
26 #include <unistd.h> |
25 |
|
26 #include <gst/check/gstcheck.h> |
27 #include <gst/check/gstcheck.h> |
27 |
28 |
28 #include <gst/audio/audio.h> |
29 |
|
30 |
29 |
31 |
30 #define LOG_FILE "c:\\logs\\audioresample_logs.txt" |
32 #define LOG_FILE "c:\\logs\\audioresample_logs.txt" |
31 #include "std_log_result.h" |
33 #include "std_log_result.h" |
32 #define LOG_FILENAME_LINE __FILE__, __LINE__ |
34 #define LOG_FILENAME_LINE __FILE__, __LINE__ |
33 |
35 |
34 //char* xmlfile = "gstsystemclock"; |
|
35 |
|
36 void create_xml(int result) |
36 void create_xml(int result) |
37 { |
37 { |
38 |
|
39 if(result) |
38 if(result) |
40 { |
|
41 assert_failed = 1; |
39 assert_failed = 1; |
42 } |
40 |
43 |
|
44 testResultXml(xmlfile); |
41 testResultXml(xmlfile); |
45 close_log_file(); |
42 close_log_file(); |
46 |
43 } |
47 if(result) |
|
48 { |
|
49 exit (-1); |
|
50 } |
|
51 |
|
52 } |
|
53 |
|
54 #include "libgstreamer_wsd_solution.h" |
44 #include "libgstreamer_wsd_solution.h" |
55 |
45 |
56 |
46 |
57 #if EMULATOR |
47 #if EMULATOR |
58 static GET_GLOBAL_VAR_FROM_TLS(threads_running,gstcheck,gboolean) |
48 static GET_GLOBAL_VAR_FROM_TLS(threads_running,gstcheck,gboolean) |
59 #define _gst_check_threads_running (*GET_GSTREAMER_WSD_VAR_NAME(threads_running,gstcheck,g)()) |
49 #define _gst_check_threads_running (*GET_GSTREAMER_WSD_VAR_NAME(threads_running,gstcheck,g)()) |
60 #else |
50 #else |
61 IMPORT_C extern gboolean _gst_check_threads_running; |
51 extern gboolean _gst_check_threads_running; |
62 #endif |
52 #endif |
63 #if EMULATOR |
53 #if EMULATOR |
64 static GET_GLOBAL_VAR_FROM_TLS(raised_critical,gstcheck,gboolean) |
54 static GET_GLOBAL_VAR_FROM_TLS(raised_critical,gstcheck,gboolean) |
65 #define _gst_check_raised_critical (*GET_GSTREAMER_WSD_VAR_NAME(raised_critical,gstcheck,g)()) |
55 #define _gst_check_raised_critical (*GET_GSTREAMER_WSD_VAR_NAME(raised_critical,gstcheck,g)()) |
66 #else |
56 #else |
67 IMPORT_C extern gboolean _gst_check_raised_critical; |
57 extern gboolean _gst_check_raised_critical; |
68 #endif |
58 #endif |
69 //gboolean _gst_check_raised_warning = FALSE; |
59 //gboolean _gst_check_raised_warning = FALSE; |
70 #if EMULATOR |
60 #if EMULATOR |
71 static GET_GLOBAL_VAR_FROM_TLS(raised_warning,gstcheck,gboolean) |
61 static GET_GLOBAL_VAR_FROM_TLS(raised_warning,gstcheck,gboolean) |
72 #define _gst_check_raised_warning (*GET_GSTREAMER_WSD_VAR_NAME(raised_warning,gstcheck,g)()) |
62 #define _gst_check_raised_warning (*GET_GSTREAMER_WSD_VAR_NAME(raised_warning,gstcheck,g)()) |
73 #else |
63 #else |
74 IMPORT_C extern gboolean _gst_check_raised_warning; |
64 extern gboolean _gst_check_raised_warning; |
75 #endif |
65 #endif |
76 //gboolean _gst_check_expecting_log = FALSE; |
66 //gboolean _gst_check_expecting_log = FALSE; |
77 #if EMULATOR |
67 #if EMULATOR |
78 static GET_GLOBAL_VAR_FROM_TLS(expecting_log,gstcheck,gboolean) |
68 static GET_GLOBAL_VAR_FROM_TLS(expecting_log,gstcheck,gboolean) |
79 #define _gst_check_expecting_log (*GET_GSTREAMER_WSD_VAR_NAME(expecting_log,gstcheck,g)()) |
69 #define _gst_check_expecting_log (*GET_GSTREAMER_WSD_VAR_NAME(expecting_log,gstcheck,g)()) |
80 #else |
70 #else |
81 IMPORT_C extern gboolean _gst_check_expecting_log; |
71 extern gboolean _gst_check_expecting_log; |
82 #endif |
72 #endif |
83 |
73 |
84 #if EMULATOR |
74 #if EMULATOR |
85 GET_GLOBAL_VAR_FROM_TLS(buffers,gstcheck,GList*) |
75 GET_GLOBAL_VAR_FROM_TLS(buffers,gstcheck,GList*) |
86 #define buffers (*GET_GSTREAMER_WSD_VAR_NAME(buffers,gstcheck,g)()) |
76 #define buffers (*GET_GSTREAMER_WSD_VAR_NAME(buffers,gstcheck,g)()) |
87 #else |
77 #else |
88 IMPORT_C extern GList *buffers; |
78 extern GList *buffers; |
89 #endif |
79 #endif |
|
80 |
|
81 |
|
82 |
90 |
83 |
91 |
84 |
92 /* For ease of programming we use globals to keep refs for our floating |
85 /* For ease of programming we use globals to keep refs for our floating |
93 * src and sink pads we create; otherwise we always have to do get_pad, |
86 * src and sink pads we create; otherwise we always have to do get_pad, |
94 * get_peer, and then remove references in every test function */ |
87 * get_peer, and then remove references in every test function */ |
95 static GstPad *mysrcpad, *mysinkpad; |
88 static GstPad *mysrcpad, *mysinkpad; |
96 |
89 |
97 #define RESAMPLE_CAPS_FLOAT \ |
90 |
98 "audio/x-raw-float, " \ |
91 #define RESAMPLE_CAPS_TEMPLATE_STRING \ |
99 "channels = (int) [ 1, MAX ], " \ |
|
100 "rate = (int) [ 1, MAX ], " \ |
|
101 "endianness = (int) BYTE_ORDER, " \ |
|
102 "width = (int) { 32, 64 }" |
|
103 |
|
104 #define RESAMPLE_CAPS_INT \ |
|
105 "audio/x-raw-int, " \ |
92 "audio/x-raw-int, " \ |
106 "channels = (int) [ 1, MAX ], " \ |
93 "channels = (int) [ 1, MAX ], " \ |
107 "rate = (int) [ 1, MAX ], " \ |
94 "rate = (int) [ 1, MAX ], " \ |
108 "endianness = (int) BYTE_ORDER, " \ |
95 "endianness = (int) BYTE_ORDER, " \ |
109 "width = (int) 16, " \ |
96 "width = (int) 16, " \ |
110 "depth = (int) 16, " \ |
97 "depth = (int) 16, " \ |
111 "signed = (bool) TRUE" |
98 "signed = (bool) TRUE" |
112 |
|
113 #define RESAMPLE_CAPS_TEMPLATE_STRING \ |
|
114 RESAMPLE_CAPS_FLOAT " ; " \ |
|
115 RESAMPLE_CAPS_INT |
|
116 |
99 |
117 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", |
100 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", |
118 GST_PAD_SINK, |
101 GST_PAD_SINK, |
119 GST_PAD_ALWAYS, |
102 GST_PAD_ALWAYS, |
120 GST_STATIC_CAPS (RESAMPLE_CAPS_TEMPLATE_STRING) |
103 GST_STATIC_CAPS (RESAMPLE_CAPS_TEMPLATE_STRING) |
124 GST_PAD_ALWAYS, |
107 GST_PAD_ALWAYS, |
125 GST_STATIC_CAPS (RESAMPLE_CAPS_TEMPLATE_STRING) |
108 GST_STATIC_CAPS (RESAMPLE_CAPS_TEMPLATE_STRING) |
126 ); |
109 ); |
127 |
110 |
128 static GstElement * |
111 static GstElement * |
129 setup_audioresample (int channels, int inrate, int outrate, int width, |
112 setup_audioresample (int channels, int inrate, int outrate) |
130 gboolean fp) |
|
131 { |
113 { |
132 GstElement *audioresample; |
114 GstElement *audioresample; |
133 GstCaps *caps; |
115 GstCaps *caps; |
134 GstStructure *structure; |
116 GstStructure *structure; |
|
117 GstPad *pad; |
135 |
118 |
136 GST_DEBUG ("setup_audioresample"); |
119 GST_DEBUG ("setup_audioresample"); |
137 audioresample = gst_check_setup_element ("audioresample"); |
120 audioresample = gst_check_setup_element ("audioresample"); |
138 |
121 |
139 if (fp) |
122 caps = gst_caps_from_string (RESAMPLE_CAPS_TEMPLATE_STRING); |
140 caps = gst_caps_from_string (RESAMPLE_CAPS_FLOAT); |
|
141 else |
|
142 caps = gst_caps_from_string (RESAMPLE_CAPS_INT); |
|
143 structure = gst_caps_get_structure (caps, 0); |
123 structure = gst_caps_get_structure (caps, 0); |
144 gst_structure_set (structure, "channels", G_TYPE_INT, channels, |
124 gst_structure_set (structure, "channels", G_TYPE_INT, channels, |
145 "rate", G_TYPE_INT, inrate, "width", G_TYPE_INT, width, NULL); |
125 "rate", G_TYPE_INT, inrate, NULL); |
146 if (!fp) |
|
147 gst_structure_set (structure, "depth", G_TYPE_INT, width, NULL); |
|
148 fail_unless (gst_caps_is_fixed (caps)); |
126 fail_unless (gst_caps_is_fixed (caps)); |
149 |
127 |
150 fail_unless (gst_element_set_state (audioresample, |
128 fail_unless (gst_element_set_state (audioresample, |
151 GST_STATE_PAUSED) == GST_STATE_CHANGE_SUCCESS, |
129 GST_STATE_PAUSED) == GST_STATE_CHANGE_SUCCESS, |
152 "could not set to paused"); |
130 "could not set to paused"); |
153 |
131 |
154 mysrcpad = gst_check_setup_src_pad (audioresample, &srctemplate, caps); |
132 mysrcpad = gst_check_setup_src_pad (audioresample, &srctemplate, caps); |
155 gst_pad_set_caps (mysrcpad, caps); |
133 pad = gst_pad_get_peer (mysrcpad); |
156 gst_caps_unref (caps); |
134 gst_pad_set_caps (pad, caps); |
157 |
135 gst_object_unref (GST_OBJECT (pad)); |
158 if (fp) |
136 gst_caps_unref (caps); |
159 caps = gst_caps_from_string (RESAMPLE_CAPS_FLOAT); |
137 gst_pad_set_active (mysrcpad, TRUE); |
160 else |
138 |
161 caps = gst_caps_from_string (RESAMPLE_CAPS_INT); |
139 caps = gst_caps_from_string (RESAMPLE_CAPS_TEMPLATE_STRING); |
162 structure = gst_caps_get_structure (caps, 0); |
140 structure = gst_caps_get_structure (caps, 0); |
163 gst_structure_set (structure, "channels", G_TYPE_INT, channels, |
141 gst_structure_set (structure, "channels", G_TYPE_INT, channels, |
164 "rate", G_TYPE_INT, outrate, "width", G_TYPE_INT, width, NULL); |
142 "rate", G_TYPE_INT, outrate, NULL); |
165 if (!fp) |
|
166 gst_structure_set (structure, "depth", G_TYPE_INT, width, NULL); |
|
167 fail_unless (gst_caps_is_fixed (caps)); |
143 fail_unless (gst_caps_is_fixed (caps)); |
168 |
144 |
169 mysinkpad = gst_check_setup_sink_pad (audioresample, &sinktemplate, caps); |
145 mysinkpad = gst_check_setup_sink_pad (audioresample, &sinktemplate, caps); |
170 /* this installs a getcaps func that will always return the caps we set |
146 /* this installs a getcaps func that will always return the caps we set |
171 * later */ |
147 * later */ |
172 gst_pad_set_caps (mysinkpad, caps); |
|
173 gst_pad_use_fixed_caps (mysinkpad); |
148 gst_pad_use_fixed_caps (mysinkpad); |
174 |
149 pad = gst_pad_get_peer (mysinkpad); |
|
150 gst_pad_set_caps (pad, caps); |
|
151 gst_object_unref (GST_OBJECT (pad)); |
|
152 gst_caps_unref (caps); |
175 gst_pad_set_active (mysinkpad, TRUE); |
153 gst_pad_set_active (mysinkpad, TRUE); |
176 gst_pad_set_active (mysrcpad, TRUE); |
|
177 |
|
178 gst_caps_unref (caps); |
|
179 |
154 |
180 return audioresample; |
155 return audioresample; |
181 } |
156 } |
182 |
157 |
183 static void |
158 static void |
359 ++p; |
327 ++p; |
360 *p = -32767 + i * (65535 / samples); |
328 *p = -32767 + i * (65535 / samples); |
361 ++p; |
329 ++p; |
362 } |
330 } |
363 |
331 |
364 GST_DEBUG ("Sending Buffer time:%" G_GUINT64_FORMAT " duration:%" |
|
365 G_GINT64_FORMAT " discont:%d offset:%" G_GUINT64_FORMAT " offset_end:%" |
|
366 G_GUINT64_FORMAT, GST_BUFFER_TIMESTAMP (inbuffer), |
|
367 GST_BUFFER_DURATION (inbuffer), GST_BUFFER_IS_DISCONT (inbuffer), |
|
368 GST_BUFFER_OFFSET (inbuffer), GST_BUFFER_OFFSET_END (inbuffer)); |
|
369 /* pushing gives away my reference ... */ |
332 /* pushing gives away my reference ... */ |
370 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); |
333 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); |
371 |
334 |
372 /* check if the timestamp of the pushed buffer matches the incoming one */ |
335 /* check if the timestamp of the pushed buffer matches the incoming one */ |
373 outbuffer = g_list_nth_data (buffers, g_list_length (buffers) - 1); |
336 outbuffer = g_list_nth_data (buffers, g_list_length (buffers) - 1); |
374 fail_if (outbuffer == NULL); |
337 fail_if (outbuffer == NULL); |
375 fail_unless_equals_uint64 (ints, GST_BUFFER_TIMESTAMP (outbuffer)); |
338 fail_unless_equals_uint64 (ints, GST_BUFFER_TIMESTAMP (outbuffer)); |
376 GST_DEBUG ("Got Buffer time:%" G_GUINT64_FORMAT " duration:%" |
|
377 G_GINT64_FORMAT " discont:%d offset:%" G_GUINT64_FORMAT " offset_end:%" |
|
378 G_GUINT64_FORMAT, GST_BUFFER_TIMESTAMP (outbuffer), |
|
379 GST_BUFFER_DURATION (outbuffer), GST_BUFFER_IS_DISCONT (outbuffer), |
|
380 GST_BUFFER_OFFSET (outbuffer), GST_BUFFER_OFFSET_END (outbuffer)); |
|
381 if (j > 1) { |
339 if (j > 1) { |
382 fail_unless (GST_BUFFER_IS_DISCONT (outbuffer), |
340 fail_unless (GST_BUFFER_IS_DISCONT (outbuffer), |
383 "expected discont for buffer #%d", j); |
341 "expected discont buffer"); |
384 } |
342 } |
385 } |
343 } |
386 |
344 |
387 /* cleanup */ |
345 /* cleanup */ |
388 gst_caps_unref (caps); |
346 gst_caps_unref (caps); |
389 cleanup_audioresample (audioresample); |
347 cleanup_audioresample (audioresample); |
390 } |
348 } |
391 |
349 |
392 void test_discont_stream() |
350 void test_discont_stream() |
393 { |
351 { |
|
352 xmlfile = "test_discont_stream"; |
|
353 std_log(LOG_FILENAME_LINE, "Test Started test_discont_stream"); |
|
354 |
394 /* integral scalings */ |
355 /* integral scalings */ |
395 xmlfile = "test_discont_stream"; |
|
396 std_log(LOG_FILENAME_LINE, "Test Started test_discont_stream"); |
|
397 test_discont_stream_instance (48000, 24000, 500, 20); |
356 test_discont_stream_instance (48000, 24000, 500, 20); |
398 test_discont_stream_instance (48000, 12000, 500, 20); |
357 test_discont_stream_instance (48000, 12000, 500, 20); |
399 test_discont_stream_instance (12000, 24000, 500, 20); |
358 test_discont_stream_instance (12000, 24000, 500, 20); |
400 test_discont_stream_instance (12000, 48000, 500, 20); |
359 test_discont_stream_instance (12000, 48000, 500, 20); |
401 |
360 |
524 g_usleep (100); |
484 g_usleep (100); |
525 gst_element_set_state (pipeline, GST_STATE_NULL); |
485 gst_element_set_state (pipeline, GST_STATE_NULL); |
526 } |
486 } |
527 |
487 |
528 gst_object_unref (pipeline); |
488 gst_object_unref (pipeline); |
529 |
|
530 std_log(LOG_FILENAME_LINE, "Test Successful"); |
489 std_log(LOG_FILENAME_LINE, "Test Successful"); |
531 create_xml(0); |
490 create_xml(0); |
532 } |
491 } |
533 |
492 |
534 |
493 /* |
535 |
494 audioresample_suite (void) |
536 static GstFlowReturn |
495 { |
537 live_switch_alloc_only_48000 (GstPad * pad, guint64 offset, |
496 test_perfect_stream(); |
538 guint size, GstCaps * caps, GstBuffer ** buf) |
497 test_discont_stream(); |
539 { |
498 test_reuse(); |
540 GstStructure *structure; |
499 test_shutdown(); |
541 gint rate; |
500 }*/ |
542 gint channels; |
|
543 GstCaps *desired; |
|
544 |
|
545 structure = gst_caps_get_structure (caps, 0); |
|
546 fail_unless (gst_structure_get_int (structure, "rate", &rate)); |
|
547 fail_unless (gst_structure_get_int (structure, "channels", &channels)); |
|
548 |
|
549 if (rate < 48000) |
|
550 return GST_FLOW_NOT_NEGOTIATED; |
|
551 |
|
552 desired = gst_caps_copy (caps); |
|
553 gst_caps_set_simple (desired, "rate", G_TYPE_INT, 48000, NULL); |
|
554 |
|
555 *buf = gst_buffer_new_and_alloc (channels * 48000); |
|
556 gst_buffer_set_caps (*buf, desired); |
|
557 gst_caps_unref (desired); |
|
558 |
|
559 return GST_FLOW_OK; |
|
560 } |
|
561 |
|
562 static GstCaps * |
|
563 live_switch_get_sink_caps (GstPad * pad) |
|
564 { |
|
565 GstCaps *result; |
|
566 |
|
567 result = gst_caps_copy (GST_PAD_CAPS (pad)); |
|
568 |
|
569 gst_caps_set_simple (result, |
|
570 "rate", GST_TYPE_INT_RANGE, 48000, G_MAXINT, NULL); |
|
571 |
|
572 return result; |
|
573 } |
|
574 |
|
575 static void |
|
576 live_switch_push (int rate, GstCaps * caps) |
|
577 { |
|
578 GstBuffer *inbuffer; |
|
579 GstCaps *desired; |
|
580 GList *l; |
|
581 |
|
582 desired = gst_caps_copy (caps); |
|
583 gst_caps_set_simple (desired, "rate", G_TYPE_INT, rate, NULL); |
|
584 gst_pad_set_caps (mysrcpad, desired); |
|
585 |
|
586 fail_unless (gst_pad_alloc_buffer_and_set_caps (mysrcpad, |
|
587 GST_BUFFER_OFFSET_NONE, rate * 4, desired, &inbuffer) == GST_FLOW_OK); |
|
588 |
|
589 /* When the basetransform hits the non-configured case it always |
|
590 * returns a buffer with exactly the same caps as we requested so the actual |
|
591 * renegotiation (if needed) will be done in the _chain*/ |
|
592 fail_unless (inbuffer != NULL); |
|
593 GST_DEBUG ("desired: %" GST_PTR_FORMAT ".... got: %" GST_PTR_FORMAT, |
|
594 desired, GST_BUFFER_CAPS (inbuffer)); |
|
595 fail_unless (gst_caps_is_equal (desired, GST_BUFFER_CAPS (inbuffer))); |
|
596 |
|
597 memset (GST_BUFFER_DATA (inbuffer), 0, GST_BUFFER_SIZE (inbuffer)); |
|
598 GST_BUFFER_DURATION (inbuffer) = GST_SECOND; |
|
599 GST_BUFFER_TIMESTAMP (inbuffer) = 0; |
|
600 GST_BUFFER_OFFSET (inbuffer) = 0; |
|
601 |
|
602 /* pushing gives away my reference ... */ |
|
603 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); |
|
604 |
|
605 /* ... but it ends up being collected on the global buffer list */ |
|
606 fail_unless_equals_int (g_list_length (buffers), 1); |
|
607 |
|
608 for (l = buffers; l; l = l->next) { |
|
609 GstBuffer *buffer = GST_BUFFER (l->data); |
|
610 |
|
611 gst_buffer_unref (buffer); |
|
612 } |
|
613 |
|
614 g_list_free (buffers); |
|
615 buffers = NULL; |
|
616 |
|
617 gst_caps_unref (desired); |
|
618 } |
|
619 |
|
620 void test_live_switch() |
|
621 { |
|
622 GstElement *audioresample; |
|
623 GstEvent *newseg; |
|
624 GstCaps *caps; |
|
625 xmlfile = "test_live_switch"; |
|
626 std_log(LOG_FILENAME_LINE, "Test Started test_live_switch"); |
|
627 audioresample = setup_audioresample (4, 48000, 48000, 16, FALSE); |
|
628 |
|
629 /* Let the sinkpad act like something that can only handle things of |
|
630 * rate 48000- and can only allocate buffers for that rate, but if someone |
|
631 * tries to get a buffer with a rate higher then 48000 tries to renegotiate |
|
632 * */ |
|
633 gst_pad_set_bufferalloc_function (mysinkpad, live_switch_alloc_only_48000); |
|
634 gst_pad_set_getcaps_function (mysinkpad, live_switch_get_sink_caps); |
|
635 |
|
636 gst_pad_use_fixed_caps (mysrcpad); |
|
637 |
|
638 caps = gst_pad_get_negotiated_caps (mysrcpad); |
|
639 fail_unless (gst_caps_is_fixed (caps)); |
|
640 |
|
641 fail_unless (gst_element_set_state (audioresample, |
|
642 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, |
|
643 "could not set to playing"); |
|
644 |
|
645 newseg = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME, 0, -1, 0); |
|
646 fail_unless (gst_pad_push_event (mysrcpad, newseg) != FALSE); |
|
647 |
|
648 /* downstream can provide the requested rate, a buffer alloc will be passed |
|
649 * on */ |
|
650 live_switch_push (48000, caps); |
|
651 |
|
652 /* Downstream can never accept this rate, buffer alloc isn't passed on */ |
|
653 live_switch_push (40000, caps); |
|
654 |
|
655 /* Downstream can provide the requested rate but will re-negotiate */ |
|
656 live_switch_push (50000, caps); |
|
657 |
|
658 cleanup_audioresample (audioresample); |
|
659 gst_caps_unref (caps); |
|
660 |
|
661 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
662 create_xml(0); |
|
663 } |
|
664 |
|
665 |
|
666 |
|
667 #ifndef GST_DISABLE_PARSE |
|
668 |
|
669 static GMainLoop *loop; |
|
670 static gint messages = 0; |
|
671 |
|
672 static void |
|
673 element_message_cb (GstBus * bus, GstMessage * message, gpointer user_data) |
|
674 { |
|
675 gchar *s; |
|
676 |
|
677 s = gst_structure_to_string (gst_message_get_structure (message)); |
|
678 GST_DEBUG ("Received message: %s", s); |
|
679 g_free (s); |
|
680 |
|
681 messages++; |
|
682 } |
|
683 |
|
684 static void |
|
685 eos_message_cb (GstBus * bus, GstMessage * message, gpointer user_data) |
|
686 { |
|
687 GST_DEBUG ("Received eos"); |
|
688 g_main_loop_quit (loop); |
|
689 } |
|
690 |
|
691 static void |
|
692 test_pipeline (gint width, gboolean fp, gint inrate, gint outrate, gint quality) |
|
693 { |
|
694 GstElement *pipeline; |
|
695 GstBus *bus; |
|
696 GError *error = NULL; |
|
697 gchar *pipe_str; |
|
698 |
|
699 pipe_str = |
|
700 g_strdup_printf |
|
701 ("audiotestsrc num-buffers=10 ! audioconvert ! audio/x-raw-%s,rate=%d,width=%d,channels=2 ! audioresample quality=%d ! audio/x-raw-%s,rate=%d,width=%d ! identity check-imperfect-timestamp=TRUE ! fakesink", |
|
702 (fp) ? "float" : "int", inrate, width, quality, (fp) ? "float" : "int", |
|
703 outrate, width); |
|
704 |
|
705 pipeline = gst_parse_launch (pipe_str, &error); |
|
706 fail_unless (pipeline != NULL, "Error parsing pipeline: %s", |
|
707 error ? error->message : "(invalid error)"); |
|
708 g_free (pipe_str); |
|
709 |
|
710 bus = gst_element_get_bus (pipeline); |
|
711 fail_if (bus == NULL); |
|
712 gst_bus_add_signal_watch (bus); |
|
713 g_signal_connect (bus, "message::element", (GCallback) element_message_cb, |
|
714 NULL); |
|
715 g_signal_connect (bus, "message::eos", (GCallback) eos_message_cb, NULL); |
|
716 |
|
717 gst_element_set_state (pipeline, GST_STATE_PLAYING); |
|
718 |
|
719 /* run until we receive EOS */ |
|
720 loop = g_main_loop_new (NULL, FALSE); |
|
721 |
|
722 g_main_loop_run (loop); |
|
723 |
|
724 g_main_loop_unref (loop); |
|
725 loop = NULL; |
|
726 |
|
727 gst_element_set_state (pipeline, GST_STATE_NULL); |
|
728 |
|
729 fail_if (messages > 0, "Received imperfect timestamp messages"); |
|
730 gst_object_unref (pipeline); |
|
731 } |
|
732 |
|
733 void test_pipelines() |
|
734 { |
|
735 gint quality; |
|
736 xmlfile = "test_pipelines"; |
|
737 std_log(LOG_FILENAME_LINE, "Test Started test_pipelines"); |
|
738 /* Test qualities 0, 5 and 10 */ |
|
739 for (quality = 0; quality < 11; quality += 5) { |
|
740 test_pipeline (8, FALSE, 44100, 48000, quality); |
|
741 test_pipeline (8, FALSE, 48000, 44100, quality); |
|
742 |
|
743 test_pipeline (16, FALSE, 44100, 48000, quality); |
|
744 test_pipeline (16, FALSE, 48000, 44100, quality); |
|
745 |
|
746 test_pipeline (24, FALSE, 44100, 48000, quality); |
|
747 test_pipeline (24, FALSE, 48000, 44100, quality); |
|
748 |
|
749 test_pipeline (32, FALSE, 44100, 48000, quality); |
|
750 test_pipeline (32, FALSE, 48000, 44100, quality); |
|
751 |
|
752 test_pipeline (32, TRUE, 44100, 48000, quality); |
|
753 test_pipeline (32, TRUE, 48000, 44100, quality); |
|
754 |
|
755 test_pipeline (64, TRUE, 44100, 48000, quality); |
|
756 test_pipeline (64, TRUE, 48000, 44100, quality); |
|
757 } |
|
758 |
|
759 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
760 create_xml(0); |
|
761 } |
|
762 |
|
763 |
|
764 |
|
765 void test_preference_passthrough() |
|
766 { |
|
767 GstStateChangeReturn ret; |
|
768 GstElement *pipeline, *src; |
|
769 GstStructure *s; |
|
770 GstMessage *msg; |
|
771 GstCaps *caps; |
|
772 GstPad *pad; |
|
773 GstBus *bus; |
|
774 GError *error = NULL; |
|
775 gint rate = 0; |
|
776 |
|
777 xmlfile = "test_preference_passthrough"; |
|
778 std_log(LOG_FILENAME_LINE, "Test Started test_preference_passthrough"); |
|
779 pipeline = gst_parse_launch ("audiotestsrc num-buffers=1 name=src ! " |
|
780 "audioresample ! " |
|
781 "audio/x-raw-int,rate=8000,channels=1,width=16,depth=16,signed=(boolean)true,endianness=(int)BYTE_ORDER ! " |
|
782 "fakesink can-activate-pull=0 ", &error); |
|
783 fail_unless (pipeline != NULL, "Error parsing pipeline: %s", |
|
784 error ? error->message : "(invalid error)"); |
|
785 |
|
786 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING); |
|
787 fail_unless_equals_int (ret, GST_STATE_CHANGE_ASYNC); |
|
788 |
|
789 /* run until we receive EOS */ |
|
790 bus = gst_element_get_bus (pipeline); |
|
791 fail_if (bus == NULL); |
|
792 msg = gst_bus_timed_pop_filtered (bus, -1, GST_MESSAGE_EOS); |
|
793 gst_message_unref (msg); |
|
794 gst_object_unref (bus); |
|
795 |
|
796 src = gst_bin_get_by_name (GST_BIN (pipeline), "src"); |
|
797 fail_unless (src != NULL); |
|
798 pad = gst_element_get_static_pad (src, "src"); |
|
799 fail_unless (pad != NULL); |
|
800 caps = gst_pad_get_negotiated_caps (pad); |
|
801 GST_LOG ("negotiated audiotestsrc caps: %" GST_PTR_FORMAT, caps); |
|
802 fail_unless (caps != NULL); |
|
803 s = gst_caps_get_structure (caps, 0); |
|
804 fail_unless (gst_structure_get_int (s, "rate", &rate)); |
|
805 /* there's no need to resample, audiotestsrc supports any rate, so make |
|
806 * sure audioresample provided upstream with the right caps to negotiate |
|
807 * this correctly */ |
|
808 fail_unless_equals_int (rate, 8000); |
|
809 gst_caps_unref (caps); |
|
810 gst_object_unref (pad); |
|
811 gst_object_unref (src); |
|
812 |
|
813 gst_element_set_state (pipeline, GST_STATE_NULL); |
|
814 gst_object_unref (pipeline); |
|
815 |
|
816 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
817 create_xml(0); |
|
818 } |
|
819 |
|
820 |
|
821 |
|
822 #endif |
|
823 |
|
824 //static Suite * |
|
825 //audioresample_suite (void) |
|
826 //{ |
|
827 // Suite *s = suite_create ("audioresample"); |
|
828 // TCase *tc_chain = tcase_create ("general"); |
|
829 // |
|
830 // suite_add_tcase (s, tc_chain); |
|
831 // tcase_add_test (tc_chain, test_perfect_stream); |
|
832 // tcase_add_test (tc_chain, test_discont_stream); |
|
833 // tcase_add_test (tc_chain, test_reuse); |
|
834 // tcase_add_test (tc_chain, test_shutdown); |
|
835 // tcase_add_test (tc_chain, test_live_switch); |
|
836 // |
|
837 //#ifndef GST_DISABLE_PARSE |
|
838 // tcase_set_timeout (tc_chain, 360); |
|
839 // tcase_add_test (tc_chain, test_pipelines); |
|
840 // tcase_add_test (tc_chain, test_preference_passthrough); |
|
841 //#endif |
|
842 // |
|
843 // return s; |
|
844 //} |
|
845 |
501 |
846 void (*fn[]) (void) = { |
502 void (*fn[]) (void) = { |
847 test_perfect_stream, |
503 test_perfect_stream, |
848 test_discont_stream, |
504 test_discont_stream, |
849 test_reuse, |
505 test_reuse, |
850 test_shutdown, |
506 test_shutdown |
851 test_live_switch, |
|
852 test_pipelines, |
|
853 test_preference_passthrough |
|
854 }; |
507 }; |
855 |
508 |
856 char *args[] = { |
509 char *args[] = { |
857 "test_perfect_stream", |
510 "test_perfect_stream", |
858 "test_discont_stream", |
511 "test_discont_stream", |
859 "test_reuse", |
512 "test_reuse", |
860 "test_shutdown", |
513 "test_shutdown" |
861 "test_live_switch", |
|
862 "test_pipelines", |
|
863 "test_preference_passthrough" |
|
864 }; |
514 }; |
865 |
515 |
866 GST_CHECK_MAIN (audioresample); |
516 GST_CHECK_MAIN (audioresample); |
867 |
517 |
868 |
518 |