Blame tests/check/elements/encodebin.c

Packit 971217
/* GStreamer unit test for gstprofile
Packit 971217
 *
Packit 971217
 * Copyright (C) <2009> Edward Hervey <edward.hervey@collabora.co.uk>
Packit 971217
 *
Packit 971217
 * This library is free software; you can redistribute it and/or
Packit 971217
 * modify it under the terms of the GNU Library General Public
Packit 971217
 * License as published by the Free Software Foundation; either
Packit 971217
 * version 2 of the License, or (at your option) any later version.
Packit 971217
 *
Packit 971217
 * This library is distributed in the hope that it will be useful,
Packit 971217
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 971217
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 971217
 * Library General Public License for more details.
Packit 971217
 *
Packit 971217
 * You should have received a copy of the GNU Library General Public
Packit 971217
 * License along with this library; if not, write to the
Packit 971217
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit 971217
 * Boston, MA 02110-1301, USA.
Packit 971217
 */
Packit 971217
Packit 971217
#ifdef HAVE_CONFIG_H
Packit 971217
#include "config.h"
Packit 971217
#endif
Packit 971217
Packit 971217
#include <gst/pbutils/encoding-profile.h>
Packit 971217
#include <gst/pbutils/missing-plugins.h>
Packit 971217
#include <gst/check/gstcheck.h>
Packit 971217
Packit 971217
/* Helper functions to create profiles */
Packit 971217
Packit 971217
static GstEncodingProfile *
Packit 971217
create_ogg_profile ()
Packit 971217
{
Packit 971217
  GstEncodingContainerProfile *prof;
Packit 971217
  GstCaps *ogg;
Packit 971217
Packit 971217
  ogg = gst_caps_new_empty_simple ("application/ogg");
Packit 971217
  prof = gst_encoding_container_profile_new ((gchar *) "myprofile", NULL, ogg,
Packit 971217
      NULL);
Packit 971217
  gst_caps_unref (ogg);
Packit 971217
  return (GstEncodingProfile *) prof;
Packit 971217
}
Packit 971217
Packit 971217
static GstEncodingProfile *
Packit 971217
create_ogg_vorbis_profile (guint presence, gchar * preset)
Packit 971217
{
Packit 971217
  GstEncodingContainerProfile *cprof;
Packit 971217
  GstCaps *ogg, *vorbis;
Packit 971217
Packit 971217
  ogg = gst_caps_new_empty_simple ("application/ogg");
Packit 971217
  cprof =
Packit 971217
      gst_encoding_container_profile_new ((gchar *) "myprofile", NULL, ogg,
Packit 971217
      NULL);
Packit 971217
  gst_caps_unref (ogg);
Packit 971217
Packit 971217
  vorbis = gst_caps_new_empty_simple ("audio/x-vorbis");
Packit 971217
  fail_unless (gst_encoding_container_profile_add_profile (cprof,
Packit 971217
          (GstEncodingProfile *) gst_encoding_audio_profile_new (vorbis, preset,
Packit 971217
              NULL, presence)));
Packit 971217
  gst_caps_unref (vorbis);
Packit 971217
Packit 971217
  return (GstEncodingProfile *) cprof;
Packit 971217
}
Packit 971217
Packit 971217
static GstEncodingProfile *
Packit 971217
create_ogg_theora_vorbis_profile (guint theorapresence, guint vorbispresence)
Packit 971217
{
Packit 971217
  GstEncodingContainerProfile *prof;
Packit 971217
  GstCaps *ogg, *vorbis, *theora;
Packit 971217
Packit 971217
  ogg = gst_caps_new_empty_simple ("application/ogg");
Packit 971217
  prof =
Packit 971217
      gst_encoding_container_profile_new ((gchar *) "myprofile", NULL, ogg,
Packit 971217
      NULL);
Packit 971217
  gst_caps_unref (ogg);
Packit 971217
Packit 971217
  vorbis = gst_caps_new_empty_simple ("audio/x-vorbis");
Packit 971217
  fail_unless (gst_encoding_container_profile_add_profile (prof,
Packit 971217
          (GstEncodingProfile *) gst_encoding_audio_profile_new (vorbis, NULL,
Packit 971217
              NULL, vorbispresence)));
Packit 971217
  gst_caps_unref (vorbis);
Packit 971217
Packit 971217
  theora = gst_caps_new_empty_simple ("video/x-theora");
Packit 971217
  fail_unless (gst_encoding_container_profile_add_profile (prof,
Packit 971217
          (GstEncodingProfile *) gst_encoding_video_profile_new (theora, NULL,
Packit 971217
              NULL, theorapresence)));
Packit 971217
  gst_caps_unref (theora);
Packit 971217
Packit 971217
  return (GstEncodingProfile *) prof;
Packit 971217
}
Packit 971217
Packit 971217
static GstEncodingProfile *
Packit 971217
create_vorbis_only_profile (void)
Packit 971217
{
Packit 971217
  GstEncodingProfile *prof;
Packit 971217
  GstCaps *vorbis;
Packit 971217
Packit 971217
  vorbis = gst_caps_new_empty_simple ("audio/x-vorbis");
Packit 971217
  prof =
Packit 971217
      (GstEncodingProfile *) gst_encoding_audio_profile_new (vorbis, NULL, NULL,
Packit 971217
      0);
Packit 971217
  gst_caps_unref (vorbis);
Packit 971217
Packit 971217
  return prof;
Packit 971217
}
Packit 971217
Packit 971217
static GstCaps *
Packit 971217
create_unsupported_caps (void)
Packit 971217
{
Packit 971217
  return gst_caps_new_empty_simple ("audio/x-bogus");
Packit 971217
}
Packit 971217
Packit 971217
static GstEncodingProfile *
Packit 971217
create_unsupported_profile (void)
Packit 971217
{
Packit 971217
  GstEncodingProfile *prof;
Packit 971217
  GstCaps *caps;
Packit 971217
Packit 971217
  caps = create_unsupported_caps ();
Packit 971217
  prof =
Packit 971217
      (GstEncodingProfile *) gst_encoding_audio_profile_new (caps, NULL, NULL,
Packit 971217
      0);
Packit 971217
  gst_caps_unref (caps);
Packit 971217
Packit 971217
  return prof;
Packit 971217
}
Packit 971217
Packit 971217
static void
Packit 971217
_caps_match (GstPad * sinkpad, const gchar * capsname)
Packit 971217
{
Packit 971217
  GstCaps *caps, *sinkcaps;
Packit 971217
  gchar *name;
Packit 971217
Packit 971217
  caps = gst_caps_from_string (capsname);
Packit 971217
  sinkcaps = gst_pad_query_caps (sinkpad, NULL);
Packit 971217
  fail_unless (sinkcaps != NULL);
Packit 971217
  name = gst_caps_to_string (sinkcaps);
Packit 971217
  fail_unless (gst_caps_is_subset (sinkcaps, caps),
Packit 971217
      "caps ('%s') are not a subset of ('%s')", name, capsname);
Packit 971217
  g_free (name);
Packit 971217
  gst_caps_unref (sinkcaps);
Packit 971217
  gst_caps_unref (caps);
Packit 971217
}
Packit 971217
Packit 971217
static void
Packit 971217
set_profile (GstElement * ebin, GstEncodingProfile * prof)
Packit 971217
{
Packit 971217
  g_object_set (ebin, "profile", prof, NULL);
Packit 971217
  gst_encoding_profile_unref (prof);
Packit 971217
}
Packit 971217
Packit 971217
/* Tests */
Packit 971217
Packit 971217
GST_START_TEST (test_encodebin_set_profile)
Packit 971217
{
Packit 971217
  GstElement *ebin;
Packit 971217
  GstEncodingProfile *prof, *prof2;
Packit 971217
Packit 971217
  /* Create an encodebin and check that it correctly changes states
Packit 971217
   * according to whether a profile is set or not */
Packit 971217
Packit 971217
  ebin = gst_element_factory_make ("encodebin", NULL);
Packit 971217
Packit 971217
  /* Set a profile on encodebin... */
Packit 971217
  prof = create_ogg_profile ();
Packit 971217
  g_object_set (ebin, "profile", prof, NULL);
Packit 971217
Packit 971217
  /* ... and check the profile has been properly set */
Packit 971217
  g_object_get (ebin, "profile", &prof2, NULL);
Packit 971217
Packit 971217
  fail_unless (gst_encoding_profile_is_equal (prof, prof2));
Packit 971217
Packit 971217
  gst_encoding_profile_unref (prof);
Packit 971217
  gst_encoding_profile_unref (prof2);
Packit 971217
Packit 971217
  gst_object_unref (ebin);
Packit 971217
};
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
Packit 971217
GST_START_TEST (test_encodebin_can_go_to_ready_without_profile)
Packit 971217
{
Packit 971217
  GstElement *ebin;
Packit 971217
  GstPad *srcpad;
Packit 971217
  GstPad *target;
Packit 971217
Packit 971217
  /* Create an encodebin and check that it correctly changes states
Packit 971217
   * according to whether a profile is set or not */
Packit 971217
Packit 971217
  ebin = gst_element_factory_make ("encodebin", NULL);
Packit 971217
Packit 971217
  /* Check if the source pad was properly created */
Packit 971217
  srcpad = gst_element_get_static_pad (ebin, "src");
Packit 971217
  fail_unless (srcpad != NULL);
Packit 971217
Packit 971217
  /* At this point, the ghostpad has *NO* target */
Packit 971217
  target = gst_ghost_pad_get_target (GST_GHOST_PAD (srcpad));
Packit 971217
  fail_unless (target == NULL);
Packit 971217
  gst_object_unref (srcpad);
Packit 971217
Packit 971217
  /* No profile,
Packit 971217
   * switching to READY should succeed,
Packit 971217
   * but switching to PAUSED should fail
Packit 971217
   */
Packit 971217
  fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_READY),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
  fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_PAUSED),
Packit 971217
      GST_STATE_CHANGE_FAILURE);
Packit 971217
Packit 971217
  /* Set back to NULL */
Packit 971217
  fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_NULL),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
Packit 971217
  gst_object_unref (ebin);
Packit 971217
};
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_encodebin_can_go_to_paused_with_profile)
Packit 971217
{
Packit 971217
  GstElement *ebin;
Packit 971217
  GstPad *srcpad;
Packit 971217
  GstPad *target;
Packit 971217
Packit 971217
  /* Create an encodebin and check that it correctly changes states
Packit 971217
   * according to whether a profile is set or not */
Packit 971217
Packit 971217
  ebin = gst_element_factory_make ("encodebin", NULL);
Packit 971217
Packit 971217
  /* Set a profile on encodebin... */
Packit 971217
  set_profile (ebin, create_ogg_profile ());
Packit 971217
Packit 971217
  /* Make sure we can go to PAUSED */
Packit 971217
  fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_PAUSED),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
Packit 971217
  /* At this point, the source pad *HAS* a target */
Packit 971217
  srcpad = gst_element_get_static_pad (ebin, "src");
Packit 971217
  fail_unless (srcpad != NULL);
Packit 971217
  target = gst_ghost_pad_get_target (GST_GHOST_PAD (srcpad));
Packit 971217
  fail_unless (target != NULL);
Packit 971217
  gst_object_unref (target);
Packit 971217
  gst_object_unref (srcpad);
Packit 971217
Packit 971217
Packit 971217
  /* Set back to NULL */
Packit 971217
  fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_NULL),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
Packit 971217
  gst_object_unref (ebin);
Packit 971217
};
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
Packit 971217
GST_START_TEST (test_encodebin_sink_pads_static)
Packit 971217
{
Packit 971217
  GstElement *ebin;
Packit 971217
  GstPad *srcpad, *sinkpad;
Packit 971217
Packit 971217
  /* Create an encodebin and check that it properly creates the sink pads
Packit 971217
   * for a single-stream profile with fixed presence */
Packit 971217
Packit 971217
  ebin = gst_element_factory_make ("encodebin", NULL);
Packit 971217
Packit 971217
  /* streamprofile that has a forced presence of 1 */
Packit 971217
  set_profile (ebin, create_ogg_vorbis_profile (1, NULL));
Packit 971217
Packit 971217
  fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_PAUSED),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
Packit 971217
  /* Check if the source pad was properly created */
Packit 971217
  srcpad = gst_element_get_static_pad (ebin, "src");
Packit 971217
  fail_unless (srcpad != NULL);
Packit 971217
  gst_object_unref (srcpad);
Packit 971217
Packit 971217
  /* Check if the audio sink pad was properly created */
Packit 971217
  sinkpad = gst_element_get_static_pad (ebin, "audio_0");
Packit 971217
  fail_unless (sinkpad != NULL);
Packit 971217
  /* Check caps match */
Packit 971217
  _caps_match (sinkpad, "audio/x-raw;audio/x-vorbis");
Packit 971217
  gst_object_unref (sinkpad);
Packit 971217
Packit 971217
  /* Set back to NULL */
Packit 971217
  fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_NULL),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
Packit 971217
  gst_object_unref (ebin);
Packit 971217
};
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_encodebin_preset)
Packit 971217
{
Packit 971217
  GstElement *ebin;
Packit 971217
  GstEncodingProfile *prof;
Packit 971217
  guint64 max_delay = 0;
Packit 971217
  GstPreset *oggmuxpreset;
Packit 971217
Packit 971217
  /* Create an encodebin with a bogus preset and check it fails switching states */
Packit 971217
Packit 971217
  ebin = gst_element_factory_make ("encodebin", NULL);
Packit 971217
  oggmuxpreset = GST_PRESET (gst_element_factory_make ("oggmux", NULL));
Packit 971217
Packit 971217
  /* We also set the name as the load_preset call will reset the element name to
Packit 971217
   * what is described in the preset... which might not be very smart tbh */
Packit 971217
  g_object_set (oggmuxpreset, "max-delay", (guint64) 12, "name",
Packit 971217
      "testingoggmux", NULL);
Packit 971217
Packit 971217
  /* Give a name someone should never use outside of that test */
Packit 971217
  gst_preset_save_preset (oggmuxpreset, "test_encodebin_preset");
Packit 971217
Packit 971217
  /* streamprofile that has a forced presence of 1 */
Packit 971217
  prof = create_ogg_vorbis_profile (1, NULL);
Packit 971217
Packit 971217
  gst_encoding_profile_set_preset (prof, "test_encodebin_preset");
Packit 971217
  gst_encoding_profile_set_preset_name (prof, "oggmux");
Packit 971217
Packit 971217
  set_profile (ebin, prof);
Packit 971217
Packit 971217
  /* It will go to READY... */
Packit 971217
  fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_READY),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
  /* ... and to PAUSED */
Packit 971217
  fail_unless (gst_element_set_state (ebin, GST_STATE_PAUSED) !=
Packit 971217
      GST_STATE_CHANGE_FAILURE);
Packit 971217
Packit 971217
  gst_child_proxy_get (GST_CHILD_PROXY (ebin), "testingoggmux::max-delay",
Packit 971217
      &max_delay, NULL);
Packit 971217
  fail_unless_equals_uint64 (max_delay, 12);
Packit 971217
Packit 971217
  gst_element_set_state (ebin, GST_STATE_NULL);
Packit 971217
  gst_preset_delete_preset (oggmuxpreset, "test_encodebin_preset");
Packit 971217
Packit 971217
  gst_object_unref (oggmuxpreset);
Packit 971217
  gst_object_unref (ebin);
Packit 971217
};
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_encodebin_sink_pads_nopreset_static)
Packit 971217
{
Packit 971217
  GstElement *ebin;
Packit 971217
Packit 971217
  /* Create an encodebin with a bogus preset and check it fails switching states */
Packit 971217
Packit 971217
  ebin = gst_element_factory_make ("encodebin", NULL);
Packit 971217
Packit 971217
  /* streamprofile that has a forced presence of 1 */
Packit 971217
  set_profile (ebin,
Packit 971217
      create_ogg_vorbis_profile (1, (gchar *) "nowaythispresetexists"));
Packit 971217
Packit 971217
  /* It will go to READY... */
Packit 971217
  fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_READY),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
  /* ... but to not PAUSED */
Packit 971217
  fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_PAUSED),
Packit 971217
      GST_STATE_CHANGE_FAILURE);
Packit 971217
Packit 971217
  gst_element_set_state (ebin, GST_STATE_NULL);
Packit 971217
Packit 971217
  gst_object_unref (ebin);
Packit 971217
};
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_encodebin_sink_pads_dynamic)
Packit 971217
{
Packit 971217
  GstElement *ebin;
Packit 971217
  GstPad *srcpad, *sinkpad;
Packit 971217
  GstCaps *sinkcaps;
Packit 971217
Packit 971217
  /* Create an encodebin and check that it properly creates the sink pads
Packit 971217
   * for a single-stream profile with a unfixed presence */
Packit 971217
Packit 971217
  ebin = gst_element_factory_make ("encodebin", NULL);
Packit 971217
Packit 971217
  /* streamprofile that has non-forced presence */
Packit 971217
  set_profile (ebin, create_ogg_vorbis_profile (0, NULL));
Packit 971217
Packit 971217
  /* Check if the source pad was properly created */
Packit 971217
  srcpad = gst_element_get_static_pad (ebin, "src");
Packit 971217
  fail_unless (srcpad != NULL);
Packit 971217
  gst_object_unref (srcpad);
Packit 971217
Packit 971217
  /* Check if the audio sink pad can be requested */
Packit 971217
  sinkpad = gst_element_get_request_pad (ebin, "audio_0");
Packit 971217
  fail_unless (sinkpad != NULL);
Packit 971217
  _caps_match (sinkpad, "audio/x-raw;audio/x-vorbis");
Packit 971217
  gst_element_release_request_pad (ebin, sinkpad);
Packit 971217
  gst_object_unref (sinkpad);
Packit 971217
  sinkpad = NULL;
Packit 971217
Packit 971217
  /* Check again with the 'request-pad' signal */
Packit 971217
  sinkcaps = gst_caps_new_empty_simple ("audio/x-raw");
Packit 971217
  g_signal_emit_by_name (ebin, "request-pad", sinkcaps, &sinkpad);
Packit 971217
  gst_caps_unref (sinkcaps);
Packit 971217
  fail_unless (sinkpad != NULL);
Packit 971217
  _caps_match (sinkpad, "audio/x-raw;audio/x-vorbis");
Packit 971217
  gst_element_release_request_pad (ebin, sinkpad);
Packit 971217
  gst_object_unref (sinkpad);
Packit 971217
  sinkpad = NULL;
Packit 971217
Packit 971217
  fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_PAUSED),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
Packit 971217
  /* Set back to NULL */
Packit 971217
  fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_NULL),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
Packit 971217
  gst_object_unref (ebin);
Packit 971217
};
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_encodebin_sink_pads_multiple_static)
Packit 971217
{
Packit 971217
  GstElement *ebin;
Packit 971217
  GstPad *srcpad, *sinkpadvorbis, *sinkpadtheora;
Packit 971217
Packit 971217
  /* Create an encodebin and check that it properly creates the sink pads */
Packit 971217
Packit 971217
  ebin = gst_element_factory_make ("encodebin", NULL);
Packit 971217
Packit 971217
  /* First try is with a streamprofile that has a forced presence of 1 */
Packit 971217
  set_profile (ebin, create_ogg_theora_vorbis_profile (1, 1));
Packit 971217
Packit 971217
  fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_PAUSED),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
Packit 971217
  /* Check if the source pad was properly created */
Packit 971217
  srcpad = gst_element_get_static_pad (ebin, "src");
Packit 971217
  fail_unless (srcpad != NULL);
Packit 971217
  gst_object_unref (srcpad);
Packit 971217
Packit 971217
  /* Check if the audio sink pad was properly created */
Packit 971217
  sinkpadvorbis = gst_element_get_static_pad (ebin, "audio_0");
Packit 971217
  fail_unless (sinkpadvorbis != NULL);
Packit 971217
  _caps_match (sinkpadvorbis, "audio/x-raw;audio/x-vorbis");
Packit 971217
  gst_object_unref (sinkpadvorbis);
Packit 971217
Packit 971217
  /* Check if the video sink pad was properly created */
Packit 971217
  sinkpadtheora = gst_element_get_static_pad (ebin, "video_1");
Packit 971217
  fail_unless (sinkpadtheora != NULL);
Packit 971217
  _caps_match (sinkpadtheora, "video/x-raw;video/x-theora");
Packit 971217
  gst_object_unref (sinkpadtheora);
Packit 971217
Packit 971217
  /* Set back to NULL */
Packit 971217
  fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_NULL),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
Packit 971217
  gst_object_unref (ebin);
Packit 971217
};
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_encodebin_sink_pads_multiple_dynamic)
Packit 971217
{
Packit 971217
  GstElement *ebin;
Packit 971217
  GstPad *srcpad, *sinkpadvorbis, *sinkpadtheora;
Packit 971217
Packit 971217
  /* Create an encodebin and check that it properly creates the sink pads
Packit 971217
   * for a multiple-stream with unfixed presence */
Packit 971217
Packit 971217
  ebin = gst_element_factory_make ("encodebin", NULL);
Packit 971217
Packit 971217
  /* multi-stream profile that has non-forced presence */
Packit 971217
  set_profile (ebin, create_ogg_theora_vorbis_profile (0, 0));
Packit 971217
Packit 971217
  /* Check if the source pad was properly created */
Packit 971217
  srcpad = gst_element_get_static_pad (ebin, "src");
Packit 971217
  fail_unless (srcpad != NULL);
Packit 971217
  gst_object_unref (srcpad);
Packit 971217
Packit 971217
  /* Check if the audio sink pad was properly created */
Packit 971217
  sinkpadvorbis = gst_element_get_request_pad (ebin, "audio_0");
Packit 971217
  _caps_match (sinkpadvorbis, "audio/x-raw;audio/x-vorbis");
Packit 971217
  fail_unless (sinkpadvorbis != NULL);
Packit 971217
Packit 971217
  /* Check if the video sink pad was properly created */
Packit 971217
  sinkpadtheora = gst_element_get_request_pad (ebin, "video_1");
Packit 971217
  _caps_match (sinkpadtheora, "video/x-raw;video/x-theora");
Packit 971217
  fail_unless (sinkpadtheora != NULL);
Packit 971217
Packit 971217
  fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_PAUSED),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
Packit 971217
  /* Set back to NULL */
Packit 971217
  fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_NULL),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
Packit 971217
  gst_element_release_request_pad (GST_ELEMENT (ebin), sinkpadvorbis);
Packit 971217
  gst_object_unref (sinkpadvorbis);
Packit 971217
  gst_element_release_request_pad (GST_ELEMENT (ebin), sinkpadtheora);
Packit 971217
  gst_object_unref (sinkpadtheora);
Packit 971217
Packit 971217
  gst_object_unref (ebin);
Packit 971217
};
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_encodebin_sink_pads_dynamic_encoder)
Packit 971217
{
Packit 971217
  GstElement *ebin;
Packit 971217
  GstPad *srcpad, *sinkpad = NULL;
Packit 971217
  GstCaps *vorbiscaps;
Packit 971217
Packit 971217
  /* Create an encodebin and check that it properly creates the sink pads
Packit 971217
   * for a single-stream profile with a unfixed presence */
Packit 971217
Packit 971217
  ebin = gst_element_factory_make ("encodebin", NULL);
Packit 971217
Packit 971217
  /* streamprofile that has non-forced presence */
Packit 971217
  set_profile (ebin, create_ogg_vorbis_profile (0, NULL));
Packit 971217
Packit 971217
  /* Check if the source pad was properly created */
Packit 971217
  srcpad = gst_element_get_static_pad (ebin, "src");
Packit 971217
  fail_unless (srcpad != NULL);
Packit 971217
  gst_object_unref (srcpad);
Packit 971217
Packit 971217
  /* Check if the audio sink pad was properly created */
Packit 971217
  vorbiscaps = gst_caps_from_string ("audio/x-vorbis,channels=2,rate=44100");
Packit 971217
  g_signal_emit_by_name (ebin, "request-pad", vorbiscaps, &sinkpad);
Packit 971217
  gst_caps_unref (vorbiscaps);
Packit 971217
  fail_unless (sinkpad != NULL);
Packit 971217
  _caps_match (sinkpad, "audio/x-raw;audio/x-vorbis");
Packit 971217
  gst_element_release_request_pad (ebin, sinkpad);
Packit 971217
  gst_object_unref (sinkpad);
Packit 971217
Packit 971217
  fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_PAUSED),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
Packit 971217
  /* Set back to NULL */
Packit 971217
  fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_NULL),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
Packit 971217
  gst_object_unref (ebin);
Packit 971217
};
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_encodebin_render_audio_static)
Packit 971217
{
Packit 971217
  GstElement *ebin, *pipeline, *audiotestsrc, *fakesink;
Packit 971217
  GstBus *bus;
Packit 971217
  gboolean done = FALSE;
Packit 971217
Packit 971217
  /* Create an encodebin and render 5s of vorbis/ogg */
Packit 971217
Packit 971217
  pipeline = gst_pipeline_new ("encodebin-pipeline");
Packit 971217
  bus = gst_pipeline_get_bus ((GstPipeline *) pipeline);
Packit 971217
  audiotestsrc = gst_element_factory_make ("audiotestsrc", NULL);
Packit 971217
  g_object_set (audiotestsrc, "num-buffers", 10, NULL);
Packit 971217
  fakesink = gst_element_factory_make ("fakesink", NULL);
Packit 971217
Packit 971217
  ebin = gst_element_factory_make ("encodebin", NULL);
Packit 971217
  set_profile (ebin, create_ogg_vorbis_profile (1, NULL));
Packit 971217
Packit 971217
  gst_bin_add_many ((GstBin *) pipeline, audiotestsrc, ebin, fakesink, NULL);
Packit 971217
Packit 971217
  fail_unless (gst_element_link_many (audiotestsrc, ebin, fakesink, NULL));
Packit 971217
Packit 971217
  fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_PLAYING),
Packit 971217
      GST_STATE_CHANGE_ASYNC);
Packit 971217
Packit 971217
  while (!done) {
Packit 971217
    GstMessage *msg;
Packit 971217
Packit 971217
    /* poll the bus until we get EOS without any errors */
Packit 971217
    msg = gst_bus_timed_pop (bus, GST_SECOND / 10);
Packit 971217
    if (msg) {
Packit 971217
      switch (GST_MESSAGE_TYPE (msg)) {
Packit 971217
        case GST_MESSAGE_ERROR:
Packit 971217
          fail ("GST_MESSAGE_ERROR");
Packit 971217
          break;
Packit 971217
        case GST_MESSAGE_EOS:
Packit 971217
          done = TRUE;
Packit 971217
          break;
Packit 971217
        default:
Packit 971217
          break;
Packit 971217
      }
Packit 971217
      gst_message_unref (msg);
Packit 971217
    }
Packit 971217
  }
Packit 971217
Packit 971217
  /* Set back to NULL */
Packit 971217
  fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_NULL),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
Packit 971217
  gst_object_unref (bus);
Packit 971217
Packit 971217
  gst_object_unref (pipeline);
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_encodebin_render_audio_only_static)
Packit 971217
{
Packit 971217
  GstElement *ebin, *pipeline, *audiotestsrc, *fakesink;
Packit 971217
  GstBus *bus;
Packit 971217
  gboolean done = FALSE;
Packit 971217
  GstPad *sinkpad;
Packit 971217
  GstCaps *sinkcaps;
Packit 971217
Packit 971217
  /* Create an encodebin and render 5s of vorbis only */
Packit 971217
  pipeline = gst_pipeline_new ("encodebin-pipeline");
Packit 971217
  bus = gst_pipeline_get_bus ((GstPipeline *) pipeline);
Packit 971217
  audiotestsrc = gst_element_factory_make ("audiotestsrc", NULL);
Packit 971217
  g_object_set (audiotestsrc, "num-buffers", 10, NULL);
Packit 971217
  fakesink = gst_element_factory_make ("fakesink", NULL);
Packit 971217
Packit 971217
  ebin = gst_element_factory_make ("encodebin", NULL);
Packit 971217
  set_profile (ebin, create_vorbis_only_profile ());
Packit 971217
Packit 971217
  gst_bin_add_many (GST_BIN (pipeline), audiotestsrc, ebin, fakesink, NULL);
Packit 971217
Packit 971217
  GST_DEBUG ("linking encodebin");
Packit 971217
  fail_unless (gst_element_link_many (audiotestsrc, ebin, fakesink, NULL));
Packit 971217
Packit 971217
  /* Requesting a new pad should fail */
Packit 971217
  ASSERT_CRITICAL (gst_element_get_request_pad (ebin, "audio_0"));
Packit 971217
Packit 971217
  sinkcaps = gst_caps_new_empty_simple ("audio/x-raw");
Packit 971217
  g_signal_emit_by_name (ebin, "request-pad", sinkcaps, &sinkpad);
Packit 971217
  gst_caps_unref (sinkcaps);
Packit 971217
  fail_if (sinkpad != NULL);
Packit 971217
Packit 971217
  fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_PLAYING),
Packit 971217
      GST_STATE_CHANGE_ASYNC);
Packit 971217
Packit 971217
  while (!done) {
Packit 971217
    GstMessage *msg;
Packit 971217
Packit 971217
    /* poll the bus until we get EOS without any errors */
Packit 971217
    msg = gst_bus_timed_pop (bus, GST_SECOND / 10);
Packit 971217
    if (msg) {
Packit 971217
      switch (GST_MESSAGE_TYPE (msg)) {
Packit 971217
        case GST_MESSAGE_ERROR:
Packit 971217
          fail ("GST_MESSAGE_ERROR");
Packit 971217
          break;
Packit 971217
        case GST_MESSAGE_EOS:
Packit 971217
          done = TRUE;
Packit 971217
          break;
Packit 971217
        default:
Packit 971217
          break;
Packit 971217
      }
Packit 971217
      gst_message_unref (msg);
Packit 971217
    }
Packit 971217
  }
Packit 971217
Packit 971217
  /* Set back to NULL */
Packit 971217
  fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_NULL),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
Packit 971217
  gst_object_unref (bus);
Packit 971217
Packit 971217
  gst_object_unref (pipeline);
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_encodebin_render_audio_dynamic)
Packit 971217
{
Packit 971217
  GstElement *ebin, *pipeline, *audiotestsrc, *fakesink;
Packit 971217
  GstBus *bus;
Packit 971217
  GstPad *sinkpad, *srcpad;
Packit 971217
  gboolean done = FALSE;
Packit 971217
Packit 971217
  /* Create an encodebin and render 5s of vorbis/ogg */
Packit 971217
Packit 971217
  pipeline = gst_pipeline_new ("encodebin-pipeline");
Packit 971217
  bus = gst_pipeline_get_bus ((GstPipeline *) pipeline);
Packit 971217
  audiotestsrc = gst_element_factory_make ("audiotestsrc", NULL);
Packit 971217
  g_object_set (audiotestsrc, "num-buffers", 10, NULL);
Packit 971217
  fakesink = gst_element_factory_make ("fakesink", NULL);
Packit 971217
Packit 971217
  ebin = gst_element_factory_make ("encodebin", NULL);
Packit 971217
  set_profile (ebin, create_ogg_vorbis_profile (0, NULL));
Packit 971217
Packit 971217
  gst_bin_add_many ((GstBin *) pipeline, audiotestsrc, ebin, fakesink, NULL);
Packit 971217
Packit 971217
  srcpad = gst_element_get_static_pad (audiotestsrc, "src");
Packit 971217
  fail_unless (srcpad != NULL);
Packit 971217
Packit 971217
  sinkpad = gst_element_get_request_pad (ebin, "audio_0");
Packit 971217
  fail_unless (sinkpad != NULL);
Packit 971217
  _caps_match (sinkpad, "audio/x-raw;audio/x-vorbis");
Packit 971217
Packit 971217
  fail_unless_equals_int (gst_pad_link (srcpad, sinkpad), GST_PAD_LINK_OK);
Packit 971217
Packit 971217
  gst_object_unref (srcpad);
Packit 971217
Packit 971217
  fail_unless (gst_element_link (ebin, fakesink));
Packit 971217
Packit 971217
  fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_PLAYING),
Packit 971217
      GST_STATE_CHANGE_ASYNC);
Packit 971217
Packit 971217
  while (!done) {
Packit 971217
    GstMessage *msg;
Packit 971217
Packit 971217
    /* poll the bus until we get EOS without any errors */
Packit 971217
    msg = gst_bus_timed_pop (bus, GST_SECOND / 10);
Packit 971217
    if (msg) {
Packit 971217
      switch (GST_MESSAGE_TYPE (msg)) {
Packit 971217
        case GST_MESSAGE_ERROR:
Packit 971217
          fail ("GST_MESSAGE_ERROR");
Packit 971217
          break;
Packit 971217
        case GST_MESSAGE_EOS:
Packit 971217
          done = TRUE;
Packit 971217
          break;
Packit 971217
        default:
Packit 971217
          break;
Packit 971217
      }
Packit 971217
      gst_message_unref (msg);
Packit 971217
    }
Packit 971217
  }
Packit 971217
Packit 971217
  /* Set back to NULL */
Packit 971217
  fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_NULL),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
Packit 971217
  gst_element_release_request_pad (GST_ELEMENT (ebin), sinkpad);
Packit 971217
  gst_object_unref (sinkpad);
Packit 971217
Packit 971217
  gst_object_unref (bus);
Packit 971217
Packit 971217
  gst_object_unref (pipeline);
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_encodebin_render_audio_video_static)
Packit 971217
{
Packit 971217
  GstElement *ebin, *pipeline, *audiotestsrc, *videotestsrc, *fakesink;
Packit 971217
  GstBus *bus;
Packit 971217
  gboolean done = FALSE;
Packit 971217
Packit 971217
  /* Create an encodebin and render 5s of vorbis/ogg */
Packit 971217
Packit 971217
  pipeline = gst_pipeline_new ("encodebin-pipeline");
Packit 971217
  bus = gst_pipeline_get_bus ((GstPipeline *) pipeline);
Packit 971217
  audiotestsrc = gst_element_factory_make ("audiotestsrc", NULL);
Packit 971217
  g_object_set (audiotestsrc, "num-buffers", 10, NULL);
Packit 971217
  videotestsrc = gst_element_factory_make ("videotestsrc", NULL);
Packit 971217
  g_object_set (videotestsrc, "num-buffers", 5, NULL);
Packit 971217
  fakesink = gst_element_factory_make ("fakesink", NULL);
Packit 971217
Packit 971217
  ebin = gst_element_factory_make ("encodebin", NULL);
Packit 971217
  set_profile (ebin, create_ogg_theora_vorbis_profile (1, 1));
Packit 971217
Packit 971217
  gst_bin_add_many ((GstBin *) pipeline, audiotestsrc, videotestsrc, ebin,
Packit 971217
      fakesink, NULL);
Packit 971217
Packit 971217
  fail_unless (gst_element_link (videotestsrc, ebin));
Packit 971217
  fail_unless (gst_element_link_many (audiotestsrc, ebin, fakesink, NULL));
Packit 971217
Packit 971217
  fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_PLAYING),
Packit 971217
      GST_STATE_CHANGE_ASYNC);
Packit 971217
Packit 971217
  while (!done) {
Packit 971217
    GstMessage *msg;
Packit 971217
Packit 971217
    /* poll the bus until we get EOS without any errors */
Packit 971217
    msg = gst_bus_timed_pop (bus, GST_SECOND / 10);
Packit 971217
    if (msg) {
Packit 971217
      switch (GST_MESSAGE_TYPE (msg)) {
Packit 971217
        case GST_MESSAGE_ERROR:
Packit 971217
          fail ("GST_MESSAGE_ERROR");
Packit 971217
          break;
Packit 971217
        case GST_MESSAGE_EOS:
Packit 971217
          done = TRUE;
Packit 971217
          break;
Packit 971217
        default:
Packit 971217
          break;
Packit 971217
      }
Packit 971217
      gst_message_unref (msg);
Packit 971217
    }
Packit 971217
  }
Packit 971217
Packit 971217
  /* Set back to NULL */
Packit 971217
  fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_NULL),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
Packit 971217
  gst_object_unref (bus);
Packit 971217
Packit 971217
  gst_object_unref (pipeline);
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_encodebin_render_audio_video_dynamic)
Packit 971217
{
Packit 971217
  GstElement *ebin, *pipeline, *audiotestsrc, *videotestsrc, *fakesink;
Packit 971217
  GstBus *bus;
Packit 971217
  gboolean done = FALSE;
Packit 971217
  GstPad *sinkpad1, *sinkpad2, *srcpad;
Packit 971217
Packit 971217
  /* Create an encodebin and render 5s of vorbis/ogg */
Packit 971217
Packit 971217
  pipeline = gst_pipeline_new ("encodebin-pipeline");
Packit 971217
  bus = gst_pipeline_get_bus ((GstPipeline *) pipeline);
Packit 971217
  audiotestsrc = gst_element_factory_make ("audiotestsrc", NULL);
Packit 971217
  g_object_set (audiotestsrc, "num-buffers", 10, NULL);
Packit 971217
  videotestsrc = gst_element_factory_make ("videotestsrc", NULL);
Packit 971217
  g_object_set (videotestsrc, "num-buffers", 5, NULL);
Packit 971217
  fakesink = gst_element_factory_make ("fakesink", NULL);
Packit 971217
Packit 971217
  ebin = gst_element_factory_make ("encodebin", NULL);
Packit 971217
  set_profile (ebin, create_ogg_theora_vorbis_profile (0, 0));
Packit 971217
Packit 971217
  gst_bin_add_many ((GstBin *) pipeline, audiotestsrc, videotestsrc, ebin,
Packit 971217
      fakesink, NULL);
Packit 971217
Packit 971217
  fail_unless (gst_element_link (ebin, fakesink));
Packit 971217
Packit 971217
  srcpad = gst_element_get_static_pad (audiotestsrc, "src");
Packit 971217
  sinkpad1 = gst_element_get_request_pad (ebin, "audio_0");
Packit 971217
  fail_unless (srcpad != NULL);
Packit 971217
  fail_unless (sinkpad1 != NULL);
Packit 971217
  _caps_match (sinkpad1, "audio/x-raw;audio/x-vorbis");
Packit 971217
  fail_unless_equals_int (gst_pad_link (srcpad, sinkpad1), GST_PAD_LINK_OK);
Packit 971217
  gst_object_unref (srcpad);
Packit 971217
Packit 971217
  srcpad = gst_element_get_static_pad (videotestsrc, "src");
Packit 971217
  sinkpad2 = gst_element_get_request_pad (ebin, "video_1");
Packit 971217
  _caps_match (sinkpad2, "video/x-raw;video/x-theora");
Packit 971217
  fail_unless_equals_int (gst_pad_link (srcpad, sinkpad2), GST_PAD_LINK_OK);
Packit 971217
  gst_object_unref (srcpad);
Packit 971217
Packit 971217
  fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_PLAYING),
Packit 971217
      GST_STATE_CHANGE_ASYNC);
Packit 971217
Packit 971217
  while (!done) {
Packit 971217
    GstMessage *msg;
Packit 971217
Packit 971217
    /* poll the bus until we get EOS without any errors */
Packit 971217
    msg = gst_bus_timed_pop (bus, GST_SECOND / 10);
Packit 971217
    if (msg) {
Packit 971217
      switch (GST_MESSAGE_TYPE (msg)) {
Packit 971217
        case GST_MESSAGE_ERROR:
Packit 971217
          fail ("GST_MESSAGE_ERROR");
Packit 971217
          break;
Packit 971217
        case GST_MESSAGE_EOS:
Packit 971217
          done = TRUE;
Packit 971217
          break;
Packit 971217
        default:
Packit 971217
          break;
Packit 971217
      }
Packit 971217
      gst_message_unref (msg);
Packit 971217
    }
Packit 971217
  }
Packit 971217
Packit 971217
  /* Set back to NULL */
Packit 971217
  fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_NULL),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
Packit 971217
  gst_element_release_request_pad (GST_ELEMENT (ebin), sinkpad1);
Packit 971217
  gst_object_unref (sinkpad1);
Packit 971217
  gst_element_release_request_pad (GST_ELEMENT (ebin), sinkpad2);
Packit 971217
  gst_object_unref (sinkpad2);
Packit 971217
Packit 971217
  gst_object_unref (bus);
Packit 971217
Packit 971217
  gst_object_unref (pipeline);
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_encodebin_impossible_element_combination)
Packit 971217
{
Packit 971217
  GstElement *ebin;
Packit 971217
  GstEncodingProfile *prof;
Packit 971217
  GstCaps *ogg, *x264;
Packit 971217
Packit 971217
  ebin = gst_element_factory_make ("x264enc", NULL);
Packit 971217
  if (ebin == NULL) {
Packit 971217
    GST_DEBUG ("No available h264 encoder, skipping test");
Packit 971217
    return;
Packit 971217
  }
Packit 971217
  gst_object_unref (ebin);
Packit 971217
Packit 971217
  /* Make sure that impossible combinations of encoders and muxer
Packit 971217
   * properly fail. In this case we try putting h264 in ogg.
Packit 971217
   *
Packit 971217
   * To properly test we abort early, we use a presence of zero for the
Packit 971217
   * h264 stream profile. */
Packit 971217
Packit 971217
  ebin = gst_element_factory_make ("encodebin", NULL);
Packit 971217
Packit 971217
  ogg = gst_caps_new_empty_simple ("application/ogg");
Packit 971217
  prof = (GstEncodingProfile *) gst_encoding_container_profile_new ((gchar *)
Packit 971217
      "myprofile", NULL, ogg, NULL);
Packit 971217
  gst_caps_unref (ogg);
Packit 971217
Packit 971217
  x264 = gst_caps_new_empty_simple ("video/x-h264");
Packit 971217
  fail_unless (gst_encoding_container_profile_add_profile
Packit 971217
      (GST_ENCODING_CONTAINER_PROFILE (prof),
Packit 971217
          (GstEncodingProfile *) gst_encoding_video_profile_new (x264, NULL,
Packit 971217
              NULL, 0)));
Packit 971217
  gst_caps_unref (x264);
Packit 971217
Packit 971217
  g_object_set (ebin, "profile", prof, NULL);
Packit 971217
  gst_encoding_profile_unref (prof);
Packit 971217
Packit 971217
  /* It will go to READY... */
Packit 971217
  fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_READY),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
  /* ... but to not PAUSED */
Packit 971217
  fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_PAUSED),
Packit 971217
      GST_STATE_CHANGE_FAILURE);
Packit 971217
Packit 971217
  gst_element_set_state (ebin, GST_STATE_NULL);
Packit 971217
Packit 971217
  gst_object_unref (ebin);
Packit 971217
};
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
static void
Packit 971217
_test_encodebin_reuse (GstEncodingProfile * prof1, GstEncodingProfile * prof2)
Packit 971217
{
Packit 971217
  GstElement *ebin;
Packit 971217
Packit 971217
  ebin = gst_element_factory_make ("encodebin", NULL);
Packit 971217
Packit 971217
  /* Set a profile on encodebin... */
Packit 971217
  if (prof1)
Packit 971217
    g_object_set (ebin, "profile", prof1, NULL);
Packit 971217
Packit 971217
  /* Make sure we can go to PAUSED */
Packit 971217
  fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_PAUSED),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
Packit 971217
  /* Set back to NULL */
Packit 971217
  fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_NULL),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
Packit 971217
  if (prof2)
Packit 971217
    g_object_set (ebin, "profile", prof2, NULL);
Packit 971217
Packit 971217
  /* Make sure we can go to PLAYING */
Packit 971217
  fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_PAUSED),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
Packit 971217
  /* Set back to NULL */
Packit 971217
  fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_NULL),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
Packit 971217
  gst_object_unref (ebin);
Packit 971217
}
Packit 971217
Packit 971217
GST_START_TEST (test_encodebin_reuse)
Packit 971217
{
Packit 971217
  GstEncodingProfile *prof1;
Packit 971217
  GstEncodingProfile *prof2;
Packit 971217
  GstEncodingProfile *prof3;
Packit 971217
Packit 971217
  prof1 = create_ogg_profile ();
Packit 971217
  prof2 = create_ogg_theora_vorbis_profile (1, 1);
Packit 971217
  prof3 = create_vorbis_only_profile ();
Packit 971217
Packit 971217
  _test_encodebin_reuse (prof1, NULL);
Packit 971217
  _test_encodebin_reuse (prof1, prof1);
Packit 971217
  _test_encodebin_reuse (prof1, prof2);
Packit 971217
  _test_encodebin_reuse (prof2, prof3);
Packit 971217
Packit 971217
  gst_encoding_profile_unref (prof1);
Packit 971217
  gst_encoding_profile_unref (prof2);
Packit 971217
  gst_encoding_profile_unref (prof3);
Packit 971217
};
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_encodebin_named_requests)
Packit 971217
{
Packit 971217
  GstElement *ebin;
Packit 971217
  GstEncodingContainerProfile *cprof;
Packit 971217
  GstCaps *ogg, *vorbis, *theora;
Packit 971217
  GstEncodingProfile *vorbisprof, *theoraprof;
Packit 971217
  GstPad *srcpad, *sinkpadvorbis, *sinkpadtheora;
Packit 971217
Packit 971217
  /* Create a profile with vorbis/theora named profile */
Packit 971217
  ogg = gst_caps_new_empty_simple ("application/ogg");
Packit 971217
  cprof =
Packit 971217
      gst_encoding_container_profile_new ((gchar *) "myprofile", NULL, ogg,
Packit 971217
      NULL);
Packit 971217
  gst_caps_unref (ogg);
Packit 971217
Packit 971217
  vorbis = gst_caps_new_empty_simple ("audio/x-vorbis");
Packit 971217
  vorbisprof =
Packit 971217
      (GstEncodingProfile *) gst_encoding_audio_profile_new (vorbis, NULL, NULL,
Packit 971217
      0);
Packit 971217
  gst_encoding_profile_set_name (vorbisprof, "vorbisprofile");
Packit 971217
  fail_unless (gst_encoding_container_profile_add_profile (cprof, vorbisprof));
Packit 971217
  gst_caps_unref (vorbis);
Packit 971217
Packit 971217
  theora = gst_caps_new_empty_simple ("video/x-theora");
Packit 971217
  theoraprof =
Packit 971217
      (GstEncodingProfile *) gst_encoding_video_profile_new (theora, NULL, NULL,
Packit 971217
      0);
Packit 971217
  gst_encoding_profile_set_name (theoraprof, "theoraprofile");
Packit 971217
  fail_unless (gst_encoding_container_profile_add_profile (cprof, theoraprof));
Packit 971217
  gst_caps_unref (theora);
Packit 971217
Packit 971217
  ebin = gst_element_factory_make ("encodebin", NULL);
Packit 971217
Packit 971217
  /* First try is with a streamprofile that has a forced presence of 1 */
Packit 971217
  g_object_set (ebin, "profile", cprof, NULL);
Packit 971217
Packit 971217
  gst_encoding_profile_unref (cprof);
Packit 971217
Packit 971217
  /* Check if the source pad was properly created */
Packit 971217
  srcpad = gst_element_get_static_pad (ebin, "src");
Packit 971217
  fail_unless (srcpad != NULL);
Packit 971217
  gst_object_unref (srcpad);
Packit 971217
Packit 971217
  /* Request a vorbis profile pad */
Packit 971217
  g_signal_emit_by_name (ebin, "request-profile-pad", "vorbisprofile",
Packit 971217
      &sinkpadvorbis);
Packit 971217
  fail_unless (sinkpadvorbis != NULL);
Packit 971217
  _caps_match (sinkpadvorbis, "audio/x-raw;audio/x-vorbis");
Packit 971217
  gst_object_unref (sinkpadvorbis);
Packit 971217
Packit 971217
  /* Request a theora profile pad */
Packit 971217
  g_signal_emit_by_name (ebin, "request-profile-pad", "theoraprofile",
Packit 971217
      &sinkpadtheora);
Packit 971217
  fail_unless (sinkpadtheora != NULL);
Packit 971217
  _caps_match (sinkpadtheora, "video/x-raw;video/x-theora");
Packit 971217
  gst_object_unref (sinkpadtheora);
Packit 971217
Packit 971217
  fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_PAUSED),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
Packit 971217
  /* Set back to NULL */
Packit 971217
  fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_NULL),
Packit 971217
      GST_STATE_CHANGE_SUCCESS);
Packit 971217
Packit 971217
  gst_object_unref (ebin);
Packit 971217
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_encodebin_missing_plugin_messages)
Packit 971217
{
Packit 971217
  GstElement *pipeline = gst_pipeline_new ("test");
Packit 971217
  GstBus *bus = gst_pipeline_get_bus ((GstPipeline *) pipeline);
Packit 971217
  GstElement *ebin = gst_element_factory_make ("encodebin", NULL);
Packit 971217
  GstMessage *message;
Packit 971217
  GstElement *audiotestsrc;
Packit 971217
  GstPad *sinkpad, *srcpad;
Packit 971217
Packit 971217
  audiotestsrc = gst_element_factory_make ("audiotestsrc", NULL);
Packit 971217
  g_object_set (audiotestsrc, "num-buffers", 1, NULL);
Packit 971217
  gst_bin_add ((GstBin *) pipeline, audiotestsrc);
Packit 971217
Packit 971217
  /* first add to bin, then set profile */
Packit 971217
  gst_bin_add ((GstBin *) pipeline, ebin);
Packit 971217
  set_profile (ebin, create_unsupported_profile ());
Packit 971217
Packit 971217
  srcpad = gst_element_get_static_pad (audiotestsrc, "src");
Packit 971217
  sinkpad = gst_element_get_static_pad (ebin, "audio_0");
Packit 971217
  fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK);
Packit 971217
  gst_object_unref (srcpad);
Packit 971217
  gst_object_unref (sinkpad);
Packit 971217
Packit 971217
  gst_element_set_state (pipeline, GST_STATE_PLAYING);
Packit 971217
Packit 971217
  message =
Packit 971217
      gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
Packit 971217
      GST_MESSAGE_ELEMENT);
Packit 971217
  fail_if (message == NULL);
Packit 971217
  fail_if (!gst_is_missing_plugin_message (message));
Packit 971217
  gst_message_unref (message);
Packit 971217
Packit 971217
  gst_element_set_state (pipeline, GST_STATE_NULL);
Packit 971217
  gst_object_unref (bus);
Packit 971217
  gst_object_unref (pipeline);
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_encodebin_fallback_profiles_on_failure)
Packit 971217
{
Packit 971217
  GstElement *ebin;
Packit 971217
  GstPad *sinkpad = NULL;
Packit 971217
  GstCaps *vorbiscaps;
Packit 971217
  GstEncodingProfile *profile, *vorbis_profile;
Packit 971217
Packit 971217
  ebin = gst_element_factory_make ("encodebin", NULL);
Packit 971217
Packit 971217
  /* Create a ogg profile with a vorbis sub profile
Packit 971217
   * that can't be 'instanciated' because its preset is set
Packit 971217
   * to nowaythispresetexists. */
Packit 971217
  profile = create_ogg_vorbis_profile (0, (gchar *) "nowaythispresetexists");
Packit 971217
  vorbis_profile = create_vorbis_only_profile ();
Packit 971217
  gst_encoding_container_profile_add_profile (GST_ENCODING_CONTAINER_PROFILE
Packit 971217
      (profile), vorbis_profile);
Packit 971217
  set_profile (ebin, profile);
Packit 971217
Packit 971217
  /* Check if the audio sink pad can be created, meaning
Packit 971217
   * that the first profile with a 'nowaythispresetexists'
Packit 971217
   * preset has been skipped. */
Packit 971217
  vorbiscaps = gst_caps_from_string ("audio/x-vorbis");
Packit 971217
  g_signal_emit_by_name (ebin, "request-pad", vorbiscaps, &sinkpad);
Packit 971217
  _caps_match (sinkpad, "audio/x-raw;audio/x-vorbis");
Packit 971217
  gst_element_release_request_pad (ebin, sinkpad);
Packit 971217
  gst_object_unref (sinkpad);
Packit 971217
  gst_caps_unref (vorbiscaps);
Packit 971217
Packit 971217
  gst_object_unref (ebin);
Packit 971217
};
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
static Suite *
Packit 971217
encodebin_suite (void)
Packit 971217
{
Packit 971217
  Suite *s = suite_create ("encodebin element");
Packit 971217
  TCase *tc_chain = tcase_create ("general");
Packit 971217
Packit 971217
  suite_add_tcase (s, tc_chain);
Packit 971217
  tcase_add_test (tc_chain, test_encodebin_set_profile);
Packit 971217
  tcase_add_test (tc_chain, test_encodebin_can_go_to_ready_without_profile);
Packit 971217
  tcase_add_test (tc_chain, test_encodebin_can_go_to_paused_with_profile);
Packit 971217
  tcase_add_test (tc_chain, test_encodebin_sink_pads_static);
Packit 971217
  tcase_add_test (tc_chain, test_encodebin_sink_pads_nopreset_static);
Packit 971217
  tcase_add_test (tc_chain, test_encodebin_preset);
Packit 971217
  tcase_add_test (tc_chain, test_encodebin_sink_pads_dynamic);
Packit 971217
  tcase_add_test (tc_chain, test_encodebin_sink_pads_multiple_static);
Packit 971217
  tcase_add_test (tc_chain, test_encodebin_sink_pads_multiple_dynamic);
Packit 971217
  tcase_add_test (tc_chain, test_encodebin_sink_pads_dynamic_encoder);
Packit 971217
  tcase_add_test (tc_chain, test_encodebin_render_audio_static);
Packit 971217
  tcase_add_test (tc_chain, test_encodebin_render_audio_only_static);
Packit 971217
  tcase_add_test (tc_chain, test_encodebin_render_audio_dynamic);
Packit 971217
  tcase_add_test (tc_chain, test_encodebin_render_audio_video_static);
Packit 971217
  tcase_add_test (tc_chain, test_encodebin_render_audio_video_dynamic);
Packit 971217
  tcase_add_test (tc_chain, test_encodebin_impossible_element_combination);
Packit 971217
  tcase_add_test (tc_chain, test_encodebin_reuse);
Packit 971217
  tcase_add_test (tc_chain, test_encodebin_named_requests);
Packit 971217
  tcase_add_test (tc_chain, test_encodebin_missing_plugin_messages);
Packit 971217
  tcase_add_test (tc_chain, test_encodebin_fallback_profiles_on_failure);
Packit 971217
Packit 971217
  return s;
Packit 971217
}
Packit 971217
Packit 971217
GST_CHECK_MAIN (encodebin);