Blame tests/check/elements/encodebin.c

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