gstreamer/tests/check/pipelines/oggmux.c

431 lines
12 KiB
C
Raw Normal View History

/* GStreamer
*
* unit tests for oggmux
*
* Copyright (C) 2006 James Livingston <doclivingston at gmail.com>
*
* 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <string.h>
#include <gst/check/gstcheck.h>
#include <ogg/ogg.h>
typedef enum
{
CODEC_UNKNOWN,
CODEC_VORBIS,
CODEC_THEORA,
CODEC_SPEEX,
} ChainCodec;
typedef struct
{
gboolean eos;
gulong serialno;
gint64 last_granule;
ChainCodec codec;
} ChainState;
#if (defined (HAVE_THEORA) || defined (HAVE_VORBIS))
Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static... Original commit message from CVS: * ext/alsa/gstalsamixertrack.c: (gst_alsa_mixer_track_get_type): * ext/alsa/gstalsasink.c: (set_hwparams): * ext/alsa/gstalsasrc.c: (set_hwparams): * ext/gio/gstgio.c: (gst_gio_uri_handler_get_uri): * ext/ogg/gstoggmux.h: * ext/ogg/gstogmparse.c: * gst-libs/gst/audio/audio.c: * gst-libs/gst/fft/kiss_fft_f64.c: (kiss_fft_f64_alloc): * gst-libs/gst/pbutils/missing-plugins.c: (gst_missing_uri_sink_message_new), (gst_missing_element_message_new), (gst_missing_decoder_message_new), (gst_missing_encoder_message_new): * gst-libs/gst/rtp/gstbasertppayload.c: * gst-libs/gst/rtp/gstrtcpbuffer.c: (gst_rtcp_packet_bye_get_reason): * gst/audioconvert/gstaudioconvert.c: * gst/audioresample/gstaudioresample.c: * gst/ffmpegcolorspace/imgconvert.c: * gst/playback/test.c: (gen_video_element), (gen_audio_element): * gst/typefind/gsttypefindfunctions.c: * gst/videoscale/vs_4tap.c: * gst/videoscale/vs_4tap.h: * sys/v4l/gstv4lelement.c: * sys/v4l/gstv4lsrc.c: (gst_v4lsrc_get_any_caps): * sys/v4l/v4l_calls.c: * sys/v4l/v4lsrc_calls.c: (gst_v4lsrc_capture_init), (gst_v4lsrc_try_capture): * sys/ximage/ximagesink.c: (gst_ximagesink_check_xshm_calls), (gst_ximagesink_ximage_new): * sys/xvimage/xvimagesink.c: (gst_xvimagesink_check_xshm_calls), (gst_xvimagesink_xvimage_new): * tests/check/elements/audioconvert.c: * tests/check/elements/audioresample.c: (fail_unless_perfect_stream): * tests/check/elements/audiotestsrc.c: (setup_audiotestsrc): * tests/check/elements/decodebin.c: * tests/check/elements/gdpdepay.c: (setup_gdpdepay), (setup_gdpdepay_streamheader): * tests/check/elements/gdppay.c: (setup_gdppay), (GST_START_TEST), (setup_gdppay_streamheader): * tests/check/elements/gnomevfssink.c: (setup_gnomevfssink): * tests/check/elements/multifdsink.c: (setup_multifdsink): * tests/check/elements/textoverlay.c: * tests/check/elements/videorate.c: (setup_videorate): * tests/check/elements/videotestsrc.c: (setup_videotestsrc): * tests/check/elements/volume.c: (setup_volume): * tests/check/elements/vorbisdec.c: (setup_vorbisdec): * tests/check/elements/vorbistag.c: * tests/check/generic/clock-selection.c: * tests/check/generic/states.c: (setup), (teardown): * tests/check/libs/cddabasesrc.c: * tests/check/libs/video.c: * tests/check/pipelines/gio.c: * tests/check/pipelines/oggmux.c: * tests/check/pipelines/simple-launch-lines.c: (simple_launch_lines_suite): * tests/check/pipelines/streamheader.c: * tests/check/pipelines/theoraenc.c: * tests/check/pipelines/vorbisdec.c: * tests/check/pipelines/vorbisenc.c: * tests/examples/seek/scrubby.c: * tests/examples/seek/seek.c: (query_positions_elems), (query_positions_pads): * tests/icles/stress-xoverlay.c: (myclock): Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static, using NULL instead of 0 for pointers and using "foo (void)" instead of "foo ()" for declarations. * win32/common/libgstrtp.def: Add gst_rtp_buffer_set_extension_data to the symbol definition file.
2008-03-03 06:04:31 +00:00
static ogg_sync_state oggsync;
static GHashTable *eos_chain_states;
static gulong probe_id;
static ChainCodec
get_page_codec (ogg_page * page)
{
ChainCodec codec = CODEC_UNKNOWN;
ogg_stream_state state;
ogg_packet packet;
ogg_stream_init (&state, ogg_page_serialno (page));
if (ogg_stream_pagein (&state, page) == 0) {
if (ogg_stream_packetpeek (&state, &packet) > 0) {
if (strncmp ((char *) &packet.packet[1], "vorbis",
strlen ("vorbis")) == 0)
codec = CODEC_VORBIS;
else if (strncmp ((char *) &packet.packet[1], "theora",
strlen ("theora")) == 0)
codec = CODEC_THEORA;
else if (strncmp ((char *) &packet.packet[0], "Speex ",
strlen ("Speex ")) == 0)
codec = CODEC_SPEEX;
}
}
ogg_stream_clear (&state);
return codec;
}
static void
fail_if_audio (gpointer key, ChainState * state, gpointer data)
{
fail_if (state->codec == CODEC_VORBIS,
"vorbis BOS occurred before theora BOS");
fail_if (state->codec == CODEC_SPEEX, "speex BOS occurred before theora BOS");
}
static ChainState *
validate_ogg_page (ogg_page * page)
{
gulong serialno;
gint64 granule;
ChainState *state;
serialno = ogg_page_serialno (page);
granule = ogg_page_granulepos (page);
state = g_hash_table_lookup (eos_chain_states, GINT_TO_POINTER (serialno));
fail_if (ogg_page_packets (page) == 0 && granule != -1,
"Must have granulepos -1 when page has no packets, has %" G_GINT64_FORMAT,
granule);
if (ogg_page_bos (page)) {
fail_unless (state == NULL, "Extraneous BOS flag on chain %u", serialno);
state = g_new0 (ChainState, 1);
g_hash_table_insert (eos_chain_states, GINT_TO_POINTER (serialno), state);
state->serialno = serialno;
state->last_granule = granule;
state->codec = get_page_codec (page);
/* check for things like BOS ordering, etc */
switch (state->codec) {
case CODEC_THEORA:
/* check we have no vorbis/speex chains yet */
g_hash_table_foreach (eos_chain_states, (GHFunc) fail_if_audio, NULL);
break;
case CODEC_VORBIS:
case CODEC_SPEEX:
/* no checks (yet) */
break;
case CODEC_UNKNOWN:
default:
break;
}
} else if (ogg_page_eos (page)) {
fail_unless (state != NULL, "Missing BOS flag on chain %u", serialno);
state->eos = TRUE;
} else {
fail_unless (state != NULL, "Missing BOS flag on chain %u", serialno);
fail_unless (!state->eos, "Data after EOS flag on chain %u", serialno);
}
if (granule != -1) {
fail_unless (granule >= state->last_granule,
"Granulepos out-of-order for chain %u: old=%" G_GINT64_FORMAT ", new="
G_GINT64_FORMAT, serialno, state->last_granule, granule);
state->last_granule = granule;
}
return state;
}
static void
is_video (gpointer key, ChainState * state, gpointer data)
{
if (state->codec == CODEC_THEORA)
*((gboolean *) data) = TRUE;
}
static gboolean
check_chain_final_state (gpointer key, ChainState * state, gpointer data)
{
fail_unless (state->eos, "missing EOS flag on chain %u", state->serialno);
/* return TRUE to empty the chain table */
return TRUE;
}
static gboolean
eos_buffer_probe (GstPad * pad, GstBuffer * buffer, gpointer unused)
{
gint ret;
gint size;
guint8 *data;
gchar *oggbuffer;
ChainState *state = NULL;
gboolean has_video = FALSE;
size = GST_BUFFER_SIZE (buffer);
data = GST_BUFFER_DATA (buffer);
oggbuffer = ogg_sync_buffer (&oggsync, size);
memcpy (oggbuffer, data, size);
ogg_sync_wrote (&oggsync, size);
do {
ogg_page page;
ret = ogg_sync_pageout (&oggsync, &page);
if (ret > 0)
state = validate_ogg_page (&page);
}
while (ret != 0);
if (state) {
/* Now, we can do buffer-level checks...
* If we have video somewhere, then we should have DELTA_UNIT set on all
* non-header (not IN_CAPS), non-video buffers
*/
g_hash_table_foreach (eos_chain_states, (GHFunc) is_video, &has_video);
if (has_video && state->codec != CODEC_THEORA) {
if (!GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_IN_CAPS))
fail_unless (GST_BUFFER_FLAG_IS_SET (buffer,
GST_BUFFER_FLAG_DELTA_UNIT),
"Non-video buffer doesn't have DELTA_UNIT in stream with video");
}
}
return TRUE;
}
static void
start_pipeline (GstElement * bin, GstPad * pad)
{
GstStateChangeReturn ret;
ogg_sync_init (&oggsync);
eos_chain_states =
g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free);
probe_id =
gst_pad_add_buffer_probe (pad, G_CALLBACK (eos_buffer_probe), NULL);
ret = gst_element_set_state (bin, GST_STATE_PLAYING);
fail_if (ret == GST_STATE_CHANGE_FAILURE, "Could not start test pipeline");
if (ret == GST_STATE_CHANGE_ASYNC) {
ret = gst_element_get_state (bin, NULL, NULL, GST_CLOCK_TIME_NONE);
fail_if (ret != GST_STATE_CHANGE_SUCCESS, "Could not start test pipeline");
}
}
static void
stop_pipeline (GstElement * bin, GstPad * pad)
{
GstStateChangeReturn ret;
ret = gst_element_set_state (bin, GST_STATE_NULL);
fail_if (ret == GST_STATE_CHANGE_FAILURE, "Could not stop test pipeline");
if (ret == GST_STATE_CHANGE_ASYNC) {
ret = gst_element_get_state (bin, NULL, NULL, GST_CLOCK_TIME_NONE);
fail_if (ret != GST_STATE_CHANGE_SUCCESS, "Could not stop test pipeline");
}
gst_pad_remove_buffer_probe (pad, (guint) probe_id);
ogg_sync_clear (&oggsync);
/* check end conditions, such as EOS flags */
g_hash_table_foreach_remove (eos_chain_states,
(GHRFunc) check_chain_final_state, NULL);
}
static gboolean
eos_watch (GstBus * bus, GstMessage * message, GMainLoop * loop)
{
if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_EOS) {
g_main_loop_quit (loop);
}
return TRUE;
}
static void
test_pipeline (const char *pipeline)
{
GstElement *bin, *sink;
GstPad *pad, *sinkpad;
GstBus *bus;
GError *error = NULL;
GMainLoop *loop;
GstPadLinkReturn linkret;
bin = gst_parse_launch (pipeline, &error);
fail_unless (bin != NULL, "Error parsing pipeline: %s",
error ? error->message : "(invalid error)");
pad = gst_bin_find_unlinked_pad (GST_BIN (bin), GST_PAD_SRC);
fail_unless (pad != NULL, "Could not locate free src pad");
/* connect the fake sink */
sink = gst_element_factory_make ("fakesink", "fake_sink");
fail_unless (sink != NULL, "Could create fakesink");
fail_unless (gst_bin_add (GST_BIN (bin), sink), "Could not insert fakesink");
Don't use bad gst_element_get_pad(). Original commit message from CVS: * ext/ogg/gstoggdemux.c: (gst_ogg_pad_typefind): * gst/playback/decodetest.c: (new_decoded_pad_cb): * gst/playback/gstdecodebin.c: (gst_decode_bin_init), (try_to_link_1), (elem_is_dynamic), (close_link), (type_found), (cleanup_decodebin): * gst/playback/gstdecodebin2.c: (gst_decode_bin_init), (connect_element), (gst_decode_group_control_demuxer_pad): * gst/playback/gstplaybasebin.c: (queue_remove_probe), (queue_out_of_data), (gen_preroll_element), (preroll_unlinked), (mute_group_type): * gst/playback/gstplaybin.c: (gst_play_bin_vis_blocked), (gst_play_bin_set_property), (handoff), (gen_video_element), (gen_text_element), (gen_audio_element), (gen_vis_element), (remove_sinks), (add_sink), (setup_sinks): * gst/playback/gstplaybin2.c: (pad_added_cb), (no_more_pads_cb): * gst/playback/gstplaysink.c: (gst_play_sink_get_video_sink), (gst_play_sink_get_audio_sink), (gst_play_sink_vis_unblocked), (gst_play_sink_vis_blocked), (gst_play_sink_set_vis_plugin), (gst_play_sink_get_vis_plugin), (gst_play_sink_set_mute), (gen_video_chain), (gen_text_chain), (gen_audio_chain), (gen_vis_chain), (gst_play_sink_reconfigure), (gst_play_sink_set_font_desc), (gst_play_sink_get_font_desc), (gst_play_sink_request_pad): * gst/playback/gsturidecodebin.c: (type_found), (setup_source): * gst/playback/test.c: (gen_video_element), (gen_audio_element), (cb_newpad): * gst/playback/test6.c: (new_decoded_pad_cb): * tests/check/elements/audioconvert.c: (GST_START_TEST): * tests/check/elements/audiorate.c: (test_injector_chain), (do_perfect_stream_test): * tests/check/elements/ffmpegcolorspace.c: (GST_START_TEST): * tests/check/elements/gdpdepay.c: (GST_START_TEST): * tests/check/elements/gnomevfssink.c: * tests/check/elements/textoverlay.c: (notgst_check_setup_src_pad2), (notgst_check_teardown_src_pad2): * tests/check/elements/videotestsrc.c: (GST_START_TEST): * tests/check/libs/cddabasesrc.c: (GST_START_TEST): * tests/check/pipelines/oggmux.c: (test_pipeline): * tests/check/pipelines/streamheader.c: (GST_START_TEST): * tests/check/pipelines/theoraenc.c: (GST_START_TEST): * tests/check/pipelines/vorbisenc.c: (GST_START_TEST): * tests/examples/seek/scrubby.c: (make_wav_pipeline): * tests/examples/seek/seek.c: (make_mod_pipeline), (make_dv_pipeline), (make_wav_pipeline), (make_flac_pipeline), (make_sid_pipeline), (make_parse_pipeline), (make_vorbis_pipeline), (make_theora_pipeline), (make_vorbis_theora_pipeline), (make_avi_msmpeg4v3_mp3_pipeline), (make_mp3_pipeline), (make_avi_pipeline), (make_mpeg_pipeline), (make_mpegnt_pipeline), (update_fill), (msg_buffering): Don't use bad gst_element_get_pad().
2008-05-21 16:36:50 +00:00
sinkpad = gst_element_get_static_pad (sink, "sink");
fail_unless (sinkpad != NULL, "Could not get fakesink src pad");
linkret = gst_pad_link (pad, sinkpad);
fail_unless (GST_PAD_LINK_SUCCESSFUL (linkret),
"Could not link to fake sink");
gst_object_unref (sinkpad);
/* run until we receive EOS */
loop = g_main_loop_new (NULL, FALSE);
bus = gst_element_get_bus (bin);
gst_bus_add_watch (bus, (GstBusFunc) eos_watch, loop);
gst_object_unref (bus);
start_pipeline (bin, pad);
g_main_loop_run (loop);
/* we're EOS now; make sure oggmux out caps have stream headers on them */
{
GstStructure *s;
GstCaps *muxcaps;
muxcaps = gst_pad_get_negotiated_caps (sinkpad);
fail_unless (muxcaps != NULL);
s = gst_caps_get_structure (muxcaps, 0);
fail_unless (gst_structure_has_name (s, "application/ogg"));
fail_unless (gst_structure_has_field (s, "streamheader"));
fail_unless (gst_structure_has_field_typed (s, "streamheader",
GST_TYPE_ARRAY));
gst_caps_unref (muxcaps);
}
stop_pipeline (bin, pad);
/* clean up */
g_main_loop_unref (loop);
gst_object_unref (pad);
gst_object_unref (bin);
}
#endif
#ifdef HAVE_VORBIS
GST_START_TEST (test_vorbis)
{
test_pipeline
("audiotestsrc num-buffers=5 ! audioconvert ! vorbisenc ! oggmux");
}
GST_END_TEST;
GST_START_TEST (test_vorbis_oggmux_unlinked)
{
GstElement *pipe;
GstMessage *msg;
pipe = gst_parse_launch ("audiotestsrc ! vorbisenc ! oggmux", NULL);
if (pipe == NULL) {
g_printerr ("Skipping test 'test_vorbis_oggmux_unlinked'");
return;
}
/* no sink, no async state change */
fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_PAUSED),
GST_STATE_CHANGE_SUCCESS);
/* we expect an error (without any criticals/warnings) */
msg = gst_bus_timed_pop_filtered (GST_ELEMENT_BUS (pipe), -1,
GST_MESSAGE_ERROR);
gst_message_unref (msg);
fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_NULL),
GST_STATE_CHANGE_SUCCESS);
gst_object_unref (pipe);
}
GST_END_TEST;
#endif
#ifdef HAVE_THEORA
GST_START_TEST (test_theora)
{
test_pipeline
("videotestsrc num-buffers=5 ! ffmpegcolorspace ! theoraenc ! oggmux");
}
GST_END_TEST;
#endif
#if (defined (HAVE_THEORA) && defined (HAVE_VORBIS))
GST_START_TEST (test_theora_vorbis)
{
test_pipeline
("videotestsrc num-buffers=10 ! ffmpegcolorspace ! theoraenc ! queue ! oggmux name=mux "
"audiotestsrc num-buffers=2 ! audioconvert ! vorbisenc ! queue ! mux.");
}
GST_END_TEST;
GST_START_TEST (test_vorbis_theora)
{
test_pipeline
("videotestsrc num-buffers=2 ! ffmpegcolorspace ! theoraenc ! queue ! oggmux name=mux "
"audiotestsrc num-buffers=10 ! audioconvert ! vorbisenc ! queue ! mux.");
}
GST_END_TEST;
#endif
GST_START_TEST (test_simple_cleanup)
{
GstElement *oggmux;
oggmux = gst_element_factory_make ("oggmux", NULL);
gst_object_unref (oggmux);
}
GST_END_TEST;
GST_START_TEST (test_request_pad_cleanup)
{
GstElement *oggmux;
GstPad *pad;
oggmux = gst_element_factory_make ("oggmux", NULL);
pad = gst_element_get_request_pad (oggmux, "sink_%d");
fail_unless (pad != NULL);
gst_object_unref (pad);
pad = gst_element_get_request_pad (oggmux, "sink_%d");
fail_unless (pad != NULL);
gst_object_unref (pad);
gst_object_unref (oggmux);
}
GST_END_TEST;
static Suite *
oggmux_suite (void)
{
Suite *s = suite_create ("oggmux");
TCase *tc_chain = tcase_create ("general");
suite_add_tcase (s, tc_chain);
#ifdef HAVE_VORBIS
tcase_add_test (tc_chain, test_vorbis);
tcase_add_test (tc_chain, test_vorbis_oggmux_unlinked);
#endif
#ifdef HAVE_THEORA
tcase_add_test (tc_chain, test_theora);
#endif
#if (defined (HAVE_THEORA) && defined (HAVE_VORBIS))
tcase_add_test (tc_chain, test_vorbis_theora);
tcase_add_test (tc_chain, test_theora_vorbis);
#endif
tcase_add_test (tc_chain, test_simple_cleanup);
tcase_add_test (tc_chain, test_request_pad_cleanup);
return s;
}
GST_CHECK_MAIN (oggmux);