Ejemplo n.º 1
0
/* Get a valid sink inside the pipeline. */
GstElement *get_sink()
{
	if (GST_PAD_IS_LINKED(vqueuesink)) return xvsink;
	if (audio_disabled) return NULL;
	if (GST_PAD_IS_LINKED(aqueuesink)) return asink;
	return NULL;
}
Ejemplo n.º 2
0
/* This callback will be called when GStreamer finds some stream (audio or
 * video) in the open file. This function links the appropriate elements. */
static void cb_new_pad(GstElement* object, GstPad *pad, 
		gboolean arg1, gpointer user_data)
{
	GstCaps *caps;
	GstStructure *str;

	caps = gst_pad_get_caps (pad);
	str = gst_caps_get_structure (caps, 0);

#ifdef DEBUG
	g_print("New found stream: %s\n", gst_structure_get_name (str));
#endif

	if (g_strrstr (gst_structure_get_name (str), "video"))
	{
		if (GST_PAD_IS_LINKED (vqueuesink)) return;

		g_signal_connect(GST_PAD_REALIZE(pad),
				"notify::caps", G_CALLBACK(cb_notify_caps), NULL);
		
		if (!gst_pad_link(pad, vqueuesink))
		{
			g_error("Cannot link video\n");
			return;
		}

		gst_bin_add(GST_BIN(pipeline), vthread);
		gst_bin_sync_children_state (GST_BIN (pipeline));

		return;
	}

	if (audio_disabled) return;

	if (g_strrstr (gst_structure_get_name (str), "audio"))
	{
		if (GST_PAD_IS_LINKED (aqueuesink)) return;

		if (!gst_pad_link(pad, aqueuesink))
		{
			g_error("Cannot link audio\n");
			return;
		}

		apeer = pad;
		gst_bin_add(GST_BIN(pipeline), athread);
		gst_bin_sync_children_state (GST_BIN (pipeline));
	}
}
Ejemplo n.º 3
0
static void
cb_newpad (GstElement *decodebin,
	   GstPad     *pad,
	   gpointer    data)
{
  GstCaps *caps;
  GstStructure *str;
  GstPad *audiopad;

  /* only link once */
  audiopad = gst_element_get_static_pad (audio, "sink");
  if (GST_PAD_IS_LINKED (audiopad)) {
    g_object_unref (audiopad);
    return;
  }

  /* check media type */
  caps = gst_pad_query_caps (pad, NULL);
  str = gst_caps_get_structure (caps, 0);
  if (!g_strrstr (gst_structure_get_name (str), "audio")) {
    gst_caps_unref (caps);
    gst_object_unref (audiopad);
    return;
  }
  gst_caps_unref (caps);

  /* link'n'play */
  gst_pad_link (pad, audiopad);

  g_object_unref (audiopad);
}
static void
bbd_new_decoded_pad(GstElement *decodebin, GstPad *pad, 
    gboolean last, gpointer data)
{
    GstCaps *caps;
    GstStructure *str;
    GstPad *audiopad;
    BansheeBpmDetector *detector = (BansheeBpmDetector *)data;

    g_return_if_fail(detector != NULL);

    audiopad = gst_element_get_static_pad(detector->audioconvert, "sink");
    
    if(GST_PAD_IS_LINKED(audiopad)) {
        g_object_unref(audiopad);
        return;
    }

    caps = gst_pad_query_caps(pad, NULL);
    str = gst_caps_get_structure(caps, 0);
    
    if(!g_strrstr(gst_structure_get_name(str), "audio")) {
        gst_caps_unref(caps);
        gst_object_unref(audiopad);
        return;
    }
   
    gst_caps_unref(caps);
    gst_pad_link(pad, audiopad);
}
Ejemplo n.º 5
0
//
// connect decodebin's dynamically created source pads to colourconverter
//
static void icvNewPad(GstElement *decodebin, GstPad *pad, gboolean last, gpointer data)
{
	GstElement *sink = GST_ELEMENT(data);
	GstStructure *str;
	GstPad *sinkpad;
	GstCaps *caps;

	/* link only once */
	sinkpad = gst_element_get_pad(sink, "sink");

	if(GST_PAD_IS_LINKED(sinkpad)) {
		g_print("sink is already linked\n");
		g_object_unref(sinkpad);
		return;
	}

	/* check media type */
	caps = gst_pad_get_caps(pad);
	str = gst_caps_get_structure(caps, 0);
	const char *structname = gst_structure_get_name(str);
//	g_print("new pad %s\n", structname);
	if(!g_strrstr(structname, "video")) {
		gst_caps_unref(caps);
		gst_object_unref(sinkpad);
		return;
	}
	printf("linking pad %s\n", structname);

	/* link'n'play */
	gst_pad_link (pad, sinkpad);

	gst_caps_unref(caps);
	gst_object_unref(sinkpad);
}
Ejemplo n.º 6
0
static void cb_newpad_video (GstElement *decodebin, GstPad *pad, gboolean last, gpointer data)
{
  EntradaFitxer *grup = (EntradaFitxer*)data;
  GstCaps *caps;
  GstStructure *str;
  GstPad *videopad;

  //Linkem només una vegada
  videopad = gst_element_get_static_pad (grup->v.bin, "sink");
  if (GST_PAD_IS_LINKED (videopad)) {
    g_object_unref (videopad);
    return;
  }

  //Mirem els tipus de dades multimedia
  caps = gst_pad_get_caps (pad);
  str = gst_caps_get_structure (caps, 0);
  if (!g_strrstr (gst_structure_get_name (str), "video")) {
    gst_caps_unref (caps);
    gst_object_unref (videopad);
    return;
  }
  gst_caps_unref (caps);

  //Link'n'play
  gst_pad_link (pad, videopad);

  g_object_unref (videopad);
}
Ejemplo n.º 7
0
static void
gst_transcoder_new_decoded_pad(GstElement *decodebin, GstPad *pad, 
    gboolean last, gpointer data)
{
    GstCaps *caps;
    GstStructure *str;
    GstPad *audiopad;
    GstTranscoder *transcoder = (GstTranscoder *)data;

    g_return_if_fail(transcoder != NULL);

    audiopad = gst_element_get_pad(transcoder->sink_bin, "sink");
    
    if(GST_PAD_IS_LINKED(audiopad)) {
        g_object_unref(audiopad);
        return;
    }

    caps = gst_pad_get_caps(pad);
    str = gst_caps_get_structure(caps, 0);
    
    if(!g_strrstr(gst_structure_get_name(str), "audio")) {
        gst_caps_unref(caps);
        gst_object_unref(audiopad);
        return;
    }
   
    gst_caps_unref(caps);
    gst_pad_link(pad, audiopad);
}
Ejemplo n.º 8
0
static void
cb_newpad (GstElement *decodebin,
           GstPad     *pad,
           gboolean    last,
           gpointer    data)
{
    GstCaps *caps;
    GstStructure *str;
    GstPad *audiopad;

    audiopad = gst_element_get_static_pad (audio, "sink");
    if (GST_PAD_IS_LINKED (audiopad)) {
        g_object_unref (audiopad);
        decodebin = NULL;
        last = false;
        data = NULL;
        return;
    }

    caps = gst_pad_get_caps (pad);
    str = gst_caps_get_structure (caps, 0);
    if (!g_strrstr (gst_structure_get_name (str), "audio")) {
        gst_caps_unref (caps);
        gst_object_unref (audiopad);
        return;
    }
    gst_caps_unref (caps);

    gst_pad_link (pad, audiopad);
}
Ejemplo n.º 9
0
void Pipeline::cb_new_pad (GstElement* decodebin, GstPad* pad, gboolean last, GstElement* glimagesink)
{
    GstPad* glpad = gst_element_get_pad (glimagesink, "sink");
    
    //only link once 
    if (GST_PAD_IS_LINKED (glpad)) 
    {
        gst_object_unref (glpad);
        return;
    }

    GstCaps* caps = gst_pad_get_caps (pad);
    GstStructure* str = gst_caps_get_structure (caps, 0);
    if (!g_strrstr (gst_structure_get_name (str), "video")) 
    {
        gst_caps_unref (caps);
        gst_object_unref (glpad);
        return;
    }
    gst_caps_unref (caps);

    GstPadLinkReturn ret = gst_pad_link (pad, glpad);
    if (ret != GST_PAD_LINK_OK) 
        g_warning ("Failed to link with decodebin!\n");
}
static void
mirageaudio_link_audio_pad(GstPad *pad, GstCaps *caps, MirageAudio *ma)
{
    GstStructure *str;
    GstPad *audiopad;

    // only link once
    audiopad = gst_element_get_static_pad(ma->audio, "sink");
    if (GST_PAD_IS_LINKED(audiopad)) {
        g_object_unref(audiopad);
        return;
    }

    // check media type
    str = gst_caps_get_structure(caps, 0);
    if (!g_strrstr(gst_structure_get_name(str), "audio/")) {
        gst_object_unref(audiopad);
        return;
    }

    if (!gst_structure_get_int(str, "rate", &ma->filerate))
        ma->filerate = -1;

    // link
    gst_pad_link(pad, audiopad);
    gst_object_unref(audiopad);
}
Ejemplo n.º 11
0
void PlayerGst::newpad (GstElement *decodebin,
		   GstPad     *pad,
		   gboolean    last,
		   gpointer    data)
{
	GstCaps *caps;
	GstStructure *str;
	GstPad *audiopad;
	
	/* only link once */
	GstElement *audio = gst_bin_get_by_name(GST_BIN(pipeline), "audiobin");
	audiopad = gst_element_get_static_pad (audio, "sink");
	gst_object_unref(audio);
	if (GST_PAD_IS_LINKED (audiopad)) {
		g_object_unref (audiopad);
		return;
	}
	
	/* check media type */
	caps = gst_pad_get_caps (pad);
	str = gst_caps_get_structure (caps, 0);
	if (!g_strrstr (gst_structure_get_name (str), "audio")) {
		gst_caps_unref (caps);
		gst_object_unref (audiopad);
		return;
	}
	gst_caps_unref (caps);
	
	/* link'n'play */
	gst_pad_link (pad, audiopad);
}
Ejemplo n.º 12
0
static void
gst_navseek_segseek (GstNavSeek * navseek)
{
  GstEvent *event;
  GstPad *peer_pad;

  if ((navseek->segment_start == GST_CLOCK_TIME_NONE) ||
      (navseek->segment_end == GST_CLOCK_TIME_NONE) ||
      (!GST_PAD_IS_LINKED (GST_BASE_TRANSFORM (navseek)->sinkpad))) {
    return;
  }

  if (navseek->loop) {
    event =
        gst_event_new_seek (1.0, GST_FORMAT_TIME,
        GST_SEEK_FLAG_ACCURATE | GST_SEEK_FLAG_SEGMENT,
        GST_SEEK_TYPE_SET, navseek->segment_start, GST_SEEK_TYPE_SET,
        navseek->segment_end);
  } else {
    event =
        gst_event_new_seek (1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_ACCURATE,
        GST_SEEK_TYPE_SET, navseek->segment_start, GST_SEEK_TYPE_SET,
        navseek->segment_end);
  }

  peer_pad = gst_pad_get_peer (GST_BASE_TRANSFORM (navseek)->sinkpad);
  gst_pad_send_event (peer_pad, event);
  gst_object_unref (peer_pad);
}
Ejemplo n.º 13
0
static void cb_new_pad (GstElement* decodebin, GstPad* pad, GstElement* identity)
{
    GstPad* identity_pad = gst_element_get_static_pad (identity, "sink");

    //only link once
    if (GST_PAD_IS_LINKED (identity_pad))
    {
        gst_object_unref (identity_pad);
        return;
    }

    GstCaps* caps = gst_pad_get_current_caps (pad);
    GstStructure* str = gst_caps_get_structure (caps, 0);
    if (!g_strrstr (gst_structure_get_name (str), "video"))
    {
        gst_caps_unref (caps);
        gst_object_unref (identity_pad);
        return;
    }
    gst_caps_unref (caps);

    GstPadLinkReturn ret = gst_pad_link (pad, identity_pad);
    if (ret != GST_PAD_LINK_OK)
        g_warning ("Failed to link with decodebin!\n");
}
static void
Lastfmfp_cb_newpad(GstElement *decodebin, GstPad *pad, gboolean last, LastfmfpAudio *ma)
{
    GstCaps *caps;
    GstStructure *str;
    GstPad *audiopad;

    // only link once
    audiopad = gst_element_get_pad(ma->audio, "sink");
    if (GST_PAD_IS_LINKED(audiopad)) {
        g_object_unref(audiopad);
        return;
    }

    // check media type
    caps = gst_pad_get_caps(pad);
    str = gst_caps_get_structure(caps, 0);

    if (!g_strrstr(gst_structure_get_name(str), "audio")) {
        gst_caps_unref(caps);
        gst_object_unref(audiopad);
        return;
    }
    gst_caps_unref(caps);

    // link
    gst_pad_link(pad, audiopad);
    gst_object_unref(audiopad);
}
Ejemplo n.º 15
0
static void
new_decoded_pad_cb (GstElement * object, GstPad * pad, gpointer user_data)
{
  GstCaps *caps = NULL;
  GstStructure *str = NULL;
  GstPad *videopad = NULL;
  GstPad *audiopad = NULL;
  GstVideoEditor *gve = NULL;

  g_return_if_fail (GST_IS_VIDEO_EDITOR (user_data));
  gve = GST_VIDEO_EDITOR (user_data);

  /* check media type */
  caps = GST_PAD_CAPS (pad);
  str = gst_caps_get_structure (caps, 0);

  if (g_strrstr (gst_structure_get_name (str), "video")) {
    videopad = gst_element_get_static_pad (gve->priv->vencode_bin, "sink");
    /* only link once */
    if (GST_PAD_IS_LINKED (videopad)) {
      gst_object_unref (videopad);
      return;
    }
    /* link 'n play */
    GST_INFO ("Found video stream...%" GST_PTR_FORMAT, caps);
    gst_pad_link (pad, videopad);
    gst_object_unref (videopad);
  }

  else if (g_strrstr (gst_structure_get_name (str), "audio")
      && gve->priv->audio_enabled) {
    audiopad = gst_element_get_static_pad (gve->priv->aencode_bin, "sink");
    /* only link once */
    if (GST_PAD_IS_LINKED (audiopad)) {
      gst_object_unref (audiopad);
      return;
    }
    /* link 'n play */
    GST_INFO ("Found audio stream...%" GST_PTR_FORMAT, caps);
    gst_pad_link (pad, audiopad);
    gst_object_unref (audiopad);
  }
}
Ejemplo n.º 16
0
/* Enable audio on-the-fly: */
void enable_audio()
{
	if (audio_disabled) return;
	if (gst_bin_get_by_name(GST_BIN(pipeline), "athread")) return;
	if (GST_PAD_IS_LINKED(aqueuesink)) return;
	if (!apeer) return;

	gst_pad_link(apeer, aqueuesink);
	gst_bin_add(GST_BIN(pipeline), athread);
	gst_bin_sync_children_state (GST_BIN (pipeline));
}
Ejemplo n.º 17
0
/* Disable audio on-the-fly: */
void disable_audio()
{
	if (audio_disabled) return;
	if (!gst_bin_get_by_name(GST_BIN(pipeline), "athread")) return;
	if (!GST_PAD_IS_LINKED(aqueuesink)) return;
	if (!apeer) return;

	gst_pad_unlink(apeer, aqueuesink);
	gst_bin_remove(GST_BIN(pipeline), athread);
	gst_element_set_state(athread, GST_STATE_READY);
	gst_bin_sync_children_state (GST_BIN (pipeline));
}
Ejemplo n.º 18
0
void Chromaprinter::NewPadCallback(GstElement*, GstPad* pad, gboolean, gpointer data) {
  Chromaprinter* instance = reinterpret_cast<Chromaprinter*>(data);
  GstPad* const audiopad = gst_element_get_static_pad(
      instance->convert_element_, "sink");

  if (GST_PAD_IS_LINKED(audiopad)) {
    qLog(Warning) << "audiopad is already linked, unlinking old pad";
    gst_pad_unlink(audiopad, GST_PAD_PEER(audiopad));
  }

  gst_pad_link(pad, audiopad);
  gst_object_unref(audiopad);
}
void GstEnginePipeline::NewPadCallback(GstElement*, GstPad* pad, gpointer self) {
    GstEnginePipeline* instance = reinterpret_cast<GstEnginePipeline*>(self);
    GstPad* const audiopad = gst_element_get_pad(instance->audiobin_, "sink");

    if (GST_PAD_IS_LINKED(audiopad)) {
        qLog(Warning) << instance->id() << "audiopad is already linked, unlinking old pad";
        gst_pad_unlink(audiopad, GST_PAD_PEER(audiopad));
    }

    gst_pad_link(pad, audiopad);

    gst_object_unref(audiopad);

    instance->pipeline_is_connected_ = true;
    if (instance->pending_seek_nanosec_ != -1 && instance->pipeline_is_initialised_) {
        QMetaObject::invokeMethod(instance, "Seek", Qt::QueuedConnection,
                                  Q_ARG(qint64, instance->pending_seek_nanosec_));
    }
}
Ejemplo n.º 20
0
/* Callback for when decodebin exposes a source pad */
static void
connect_decodebin_cb (GstElement *decodebin,
		      GstPad     *pad,
		      gboolean    last,
		      gpointer    data)
{
        GstPad *audiopad;

        /* Only link once */
        audiopad = gst_element_get_pad (data, "sink");
        if (GST_PAD_IS_LINKED (audiopad)) {
                g_object_unref (audiopad);
                return;
        }

        if (gst_pad_link (pad, audiopad) != GST_PAD_LINK_OK) {
                g_print ("Failed to link elements decodebin-encode\n");
        }
}
Ejemplo n.º 21
0
/// Called due to incoming dv stream, either video or audio, links appropriately
void Pipeline::cb_new_dvdemux_src_pad(GstElement * /*srcElement*/, GstPad * srcPad, gpointer data)
{
    GstElement *sinkElement = static_cast<GstElement*>(data);
    bool verbose = false; // TODO
    if (std::string("video") == gst_pad_get_name(srcPad))
    {
        if (verbose)
            g_print("Got video stream from DV\n");
    }
    else 
    {
        if (verbose)
            g_print("Ignoring %s stream from DV\n", gst_pad_get_name(srcPad));
        return;
    }

    GstPad *sinkPad;
    sinkPad = gst_element_get_static_pad(sinkElement, "sink");
    if (GST_PAD_IS_LINKED(sinkPad))
    {
        g_object_unref(sinkPad); // don't link more than once
        return;
    }
    //gchar *src_pad_name = gst_pad_get_name(srcPad);
    gchar *src_pad_name = gst_pad_get_name(srcPad);
    gchar *sink_pad_name = gst_pad_get_name(sinkPad);
    gchar *sink_element_name = gst_element_get_name(sinkElement);
    if (verbose)
        g_print("Pipeline::%s: Dv1394: linking %s src pad to %s's %s sinkpad.", __FUNCTION__, "video", sink_element_name, sink_pad_name);
    GstPadLinkReturn is_linked = gst_pad_link(srcPad, sinkPad);
    if (is_linked != GST_PAD_LINK_OK) 
    {
        g_print("Could not link %s to %s.\n", src_pad_name, sink_element_name); 
        exit(1);
    }
    g_free(src_pad_name);
    g_free(sink_pad_name);
    g_free(sink_element_name);
    if (verbose)
        g_print("Success!\n");
    gst_object_unref(sinkPad);
}
Ejemplo n.º 22
0
void Player::newpad (GstElement *decodebin,
                   GstPad     *pad,
                   gpointer    data)
{
    Q_UNUSED(decodebin);
    Q_UNUSED(data);

        GstCaps *caps;
        GstStructure *str;
        GstPad *audiopad;

        /* only link once */
        GstElement *audio = gst_bin_get_by_name(GST_BIN(pipeline), "audiobin");
        audiopad = gst_element_get_static_pad (audio, "sink");
        gst_object_unref(audio);

        if (GST_PAD_IS_LINKED (audiopad)) {
                g_object_unref (audiopad);
                return;
        }

        /* check media type */
#ifdef GST_API_VERSION_1
        caps = gst_pad_query_caps (pad,NULL);
#else
        caps = gst_pad_get_caps (pad);
#endif
        str = gst_caps_get_structure (caps, 0);
        if (!g_strrstr (gst_structure_get_name (str), "audio")) {
                gst_caps_unref (caps);
                gst_object_unref (audiopad);
                return;
        }
        gst_caps_unref (caps);

        /* link'n'play */
        gst_pad_link (pad, audiopad);

        GstElement *valve = gst_bin_get_by_name(GST_BIN(pipeline), "valve");
        g_object_set (valve, "drop", FALSE, NULL);
}
Ejemplo n.º 23
0
// Used to seal up unconnected source nodes by connecting unconnected src pads to fake sinks
bool MediaNode::connectToFakeSink(GstElement *tee, GstElement *sink, GstElement *bin)
{
    bool success = true;
    GstPad *sinkPad = gst_element_get_pad (sink, "sink");

    if (GST_PAD_IS_LINKED (sinkPad)) {
        //This fakesink is already connected
        gst_object_unref (sinkPad);
        return true;
    }

    GstPad *srcPad = gst_element_get_request_pad (tee, "src%d");
    gst_bin_add(GST_BIN(bin), sink);
    if (success)
        success = (gst_pad_link (srcPad, sinkPad) == GST_PAD_LINK_OK);
    if (success)
        success = (gst_element_set_state(sink, GST_STATE(bin)) != GST_STATE_CHANGE_FAILURE);
    gst_object_unref (srcPad);
    gst_object_unref (sinkPad);
    return success;
}
Ejemplo n.º 24
0
static void
brasero_normalize_new_decoded_pad_cb (GstElement *decode,
				      GstPad *pad,
				      BraseroNormalize *normalize)
{
	GstPad *sink;
	GstCaps *caps;
	GstStructure *structure;
	BraseroNormalizePrivate *priv;

	priv = BRASERO_NORMALIZE_PRIVATE (normalize);

	sink = gst_element_get_static_pad (priv->resample, "sink");
	if (GST_PAD_IS_LINKED (sink)) {
		BRASERO_JOB_LOG (normalize, "New decoded pad already linked");
		return;
	}

	/* make sure we only have audio */
	/* FIXME: get_current_caps() doesn't always seem to work yet here */
	caps = gst_pad_query_caps (pad, NULL);
	if (!caps)
		return;

	structure = gst_caps_get_structure (caps, 0);
	if (structure && g_strrstr (gst_structure_get_name (structure), "audio")) {
		if (gst_pad_link (pad, sink) != GST_PAD_LINK_OK) {
			BRASERO_JOB_LOG (normalize, "New decoded pad can't be linked");
			brasero_job_error (BRASERO_JOB (normalize), NULL);
		}
		else
			BRASERO_JOB_LOG (normalize, "New decoded pad linked");
	}
	else
		BRASERO_JOB_LOG (normalize, "New decoded pad with unsupported stream time");

	gst_object_unref (sink);
	gst_caps_unref (caps);
}
Ejemplo n.º 25
0
void GstEnginePipeline::NewPadCallback(GstElement*, GstPad* pad,
                                       gpointer self) {
    GstEnginePipeline* instance = reinterpret_cast<GstEnginePipeline*>(self);
    GstPad* const audiopad =
        gst_element_get_static_pad(instance->audiobin_, "sink");

    // Link decodebin's sink pad to audiobin's src pad.
    if (GST_PAD_IS_LINKED(audiopad)) {
        qLog(Warning) << instance->id()
                      << "audiopad is already linked, unlinking old pad";
        gst_pad_unlink(audiopad, GST_PAD_PEER(audiopad));
    }

    gst_pad_link(pad, audiopad);
    gst_object_unref(audiopad);

    // Offset the timestamps on all the buffers coming out of the decodebin so
    // they line up exactly with the end of the last buffer from the old
    // decodebin.
    // "Running time" is the time since the last flushing seek.
    GstClockTime running_time = gst_segment_to_running_time(
                                    &instance->last_decodebin_segment_, GST_FORMAT_TIME,
                                    instance->last_decodebin_segment_.position);
    gst_pad_set_offset(pad, running_time);

    // Add a probe to the pad so we can update last_decodebin_segment_.
    gst_pad_add_probe(
        pad, static_cast<GstPadProbeType>(GST_PAD_PROBE_TYPE_BUFFER |
                                          GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
                                          GST_PAD_PROBE_TYPE_EVENT_FLUSH),
        DecodebinProbe, instance, nullptr);

    instance->pipeline_is_connected_ = true;
    if (instance->pending_seek_nanosec_ != -1 &&
            instance->pipeline_is_initialised_) {
        QMetaObject::invokeMethod(instance, "Seek", Qt::QueuedConnection,
                                  Q_ARG(qint64, instance->pending_seek_nanosec_));
    }
}
int configureAVElement (GstPad* pad, GstElement *element)
{
    int linked = 0;
    GstPad* sinkpad = gst_element_get_static_pad (element, "sink");
    if(!GST_PAD_IS_LINKED(sinkpad))
    {
        linked = GST_PAD_LINK_SUCCESSFUL(gst_pad_link (pad, sinkpad));

        if (!linked)
        {
            g_print ("Gstreamer: Failed to link demux and AV decoders\n");
        }
        else
        {
            g_print("Configured Audio/Video \n");
        }
    }
    else
        g_print("Already linked\n");

    gst_object_unref (sinkpad);

   return linked;
}
Ejemplo n.º 27
0
static void
try_to_plug (GstPad        *pad,
	     const GstCaps *caps)
{
  GstObject *parent = GST_OBJECT (GST_OBJECT_PARENT (pad));
  const gchar *mime;
  const GList *item;
  GstCaps *res, *audiocaps;

  /* don't plug if we're already plugged - FIXME: memleak for pad */
  if (GST_PAD_IS_LINKED (gst_element_get_pad (audiosink, "sink"))) {
    g_print ("Omitting link for pad %s:%s because we're already linked\n",
	     GST_OBJECT_NAME (parent), GST_OBJECT_NAME (pad));
    return;
  }

  /* as said above, we only try to plug audio... Omit video */
  mime = gst_structure_get_name (gst_caps_get_structure (caps, 0));
  if (g_strrstr (mime, "video")) {
    g_print ("Omitting link for pad %s:%s because mimetype %s is non-audio\n",
	     GST_OBJECT_NAME (parent), GST_OBJECT_NAME (pad), mime);
    return;
  }

  /* can it link to the audiopad? */
  audiocaps = gst_pad_get_caps (gst_element_get_pad (audiosink, "sink"));
  res = gst_caps_intersect (caps, audiocaps);
  if (res && !gst_caps_is_empty (res)) {
    g_print ("Found pad to link to audiosink - plugging is now done\n");
    close_link (pad, audiosink, "sink", NULL);
    gst_caps_unref (audiocaps);
    gst_caps_unref (res);
    return;
  }
  gst_caps_unref (audiocaps);
  gst_caps_unref (res);

  /* try to plug from our list */
  for (item = factories; item != NULL; item = item->next) {
    GstElementFactory *factory = GST_ELEMENT_FACTORY (item->data);
    const GList *pads;

    for (pads = gst_element_factory_get_static_pad_templates (factory);
         pads != NULL; pads = pads->next) {
      GstStaticPadTemplate *templ = pads->data;

      /* find the sink template - need an always pad*/
      if (templ->direction != GST_PAD_SINK ||
          templ->presence != GST_PAD_ALWAYS) {
        continue;
      }

      /* can it link? */
      res = gst_caps_intersect (caps,
          gst_static_caps_get (&templ->static_caps));
      if (res && !gst_caps_is_empty (res)) {
        GstElement *element;
        gchar *name_template = g_strdup (templ->name_template);

        /* close link and return */
        gst_caps_unref (res);
        element = gst_element_factory_create (factory, NULL);
        close_link (pad, element, name_template,
		    gst_element_factory_get_static_pad_templates (factory));
        g_free (name_template);
        return;
      }
      gst_caps_unref (res);

      /* we only check one sink template per factory, so move on to the
       * next factory now */
      break;
    }
  }

  /* if we get here, no item was found */
  g_print ("No compatible pad found to decode %s on %s:%s\n",
	   mime, GST_OBJECT_NAME (parent), GST_OBJECT_NAME (pad));
}
Ejemplo n.º 28
0
int
main (int argc, gchar * argv[])
{
  GstElement *element;
  GstElement *element2;
  GstPad *pad;
  long usage1;
  gint i, iters;

  gst_init (&argc, &argv);

  if (argc == 2)
    iters = atoi (argv[1]);
  else
    iters = ITERS;

  g_print ("starting element with pad test with %d iterations\n", iters);
  usage1 = vmsize ();

  element = gst_element_factory_make ("fakesink", NULL);;
  g_assert (GST_IS_ELEMENT (element));
  pad = gst_element_get_pad (element, "sink");
  g_assert (GST_IS_PAD (pad));
  g_assert (GST_OBJECT_IS_FLOATING (element));
  g_assert (!GST_OBJECT_IS_FLOATING (pad));
  g_assert (gst_pad_get_parent (pad) == element);
  gst_object_unref (element);
  g_print ("create/addpad/unref 1 new element: %ld\n", vmsize () - usage1);

  for (i = 0; i < iters; i++) {
    element = gst_element_factory_make ("fakesink", NULL);;
    g_assert (GST_IS_ELEMENT (element));
    gst_object_unref (element);
  }
  g_print ("create/unref %d elements: %ld\n", iters, vmsize () - usage1);

  for (i = 0; i < iters / 2; i++) {
    element = gst_element_factory_make ("fakesink", NULL);
    g_assert (GST_IS_ELEMENT (element));
    element2 = gst_element_factory_make ("fakesrc", NULL);
    g_assert (GST_IS_ELEMENT (element2));
    gst_element_link_pads (element2, "src", element, "sink");
    g_assert (GST_PAD_IS_LINKED (gst_element_get_pad (element2, "src")));
    g_assert (GST_PAD_IS_LINKED (gst_element_get_pad (element, "sink")));
    gst_object_unref (element);
    g_assert (!GST_PAD_IS_LINKED (gst_element_get_pad (element2, "src")));
    gst_object_unref (element2);
  }
  g_print ("create/link/unref %d element duos: %ld\n", iters / 2,
      vmsize () - usage1);

  element = gst_element_factory_make ("fakesink", NULL);;
  g_assert (GST_IS_ELEMENT (element));
  pad = gst_element_get_pad (element, "sink");
  g_assert (GST_IS_PAD (pad));
  gst_element_remove_pad (element, pad);
  g_assert (gst_element_get_pad (element, "sink") == NULL);
  gst_object_unref (element);

  g_print ("pad removal on one element: %ld\n", vmsize () - usage1);

  for (i = 0; i < iters / 2; i++) {
    element = gst_element_factory_make ("fakesink", NULL);;
    g_assert (GST_IS_ELEMENT (element));
    pad = gst_element_get_pad (element, "sink");
    g_assert (GST_IS_PAD (pad));
    gst_element_remove_pad (element, pad);
    g_assert (gst_element_get_pad (element, "sink") == NULL);
    gst_object_unref (element);
  }
  g_print ("pad removal loop on %d elements: %ld\n", iters / 2,
      vmsize () - usage1);

  for (i = 0; i < iters / 2; i++) {
    element = gst_element_factory_make ("fakesink", NULL);;
    g_assert (GST_IS_ELEMENT (element));
    pad = gst_element_get_pad (element, "sink");
    g_assert (GST_IS_PAD (pad));
    gst_object_ref (pad);
    gst_element_remove_pad (element, pad);
    g_assert (gst_pad_get_parent (pad) == NULL);
    gst_object_unref (pad);
    gst_object_unref (element);
  }
  g_print ("pad ref/removal/test loop on %d elements: %ld\n", iters / 2,
      vmsize () - usage1);

  element = gst_element_factory_make ("fakesink", NULL);;
  g_assert (GST_IS_ELEMENT (element));
  pad = gst_element_get_pad (element, "sink");
  g_assert (GST_IS_PAD (pad));
  gst_object_unref (element);

  g_print ("pad unref on one element: %ld\n", vmsize () - usage1);

  for (i = 0; i < iters / 2; i++) {
    element = gst_element_factory_make ("fakesink", NULL);
    g_assert (GST_IS_ELEMENT (element));
    pad = gst_element_get_pad (element, "sink");
    g_assert (GST_IS_PAD (pad));
    gst_object_unref (element);
  }
  g_print ("pad unref loop on %d elements: %ld\n", iters / 2,
      vmsize () - usage1);

  g_print ("leaked: %ld\n", vmsize () - usage1);

  return 0;
}
Ejemplo n.º 29
0
static gboolean
gst_navseek_handle_src_event (GstPad * pad, GstEvent * event)
{
  GstNavSeek *navseek;
  gboolean ret = TRUE;

  navseek = GST_NAVSEEK (GST_PAD_PARENT (pad));

  switch (GST_EVENT_TYPE (event)) {
    case GST_EVENT_NAVIGATION:
      /* Check for a keyup and convert left/right to a seek event */
    {
      const GstStructure *structure;
      const gchar *event_type;

      structure = gst_event_get_structure (event);
      g_return_val_if_fail (structure != NULL, FALSE);

      event_type = gst_structure_get_string (structure, "event");
      g_return_val_if_fail (event_type != NULL, FALSE);

      if (strcmp (event_type, "key-press") == 0) {
        const gchar *key;

        key = gst_structure_get_string (structure, "key");
        g_return_val_if_fail (key != NULL, FALSE);

        if (strcmp (key, "Left") == 0) {
          /* Seek backward by 5 secs */
          gst_navseek_seek (navseek, -1.0 * navseek->seek_offset * GST_SECOND);
        } else if (strcmp (key, "Right") == 0) {
          /* Seek forward */
          gst_navseek_seek (navseek, navseek->seek_offset * GST_SECOND);
        } else if (strcmp (key, "s") == 0) {
          /* Grab the next frame as the start frame of a segment */
          navseek->grab_seg_start = TRUE;
        } else if (strcmp (key, "e") == 0) {
          /* Grab the next frame as the end frame of a segment */
          navseek->grab_seg_end = TRUE;
        } else if (strcmp (key, "l") == 0) {
          /* Toggle the loop flag. If we have both start and end segment times send a seek */
          navseek->loop = !navseek->loop;
          gst_navseek_segseek (navseek);
        }
      } else {
        break;
      }
      gst_event_unref (event);
      event = NULL;
    }
      break;
    default:
      break;
  }

  if (event && GST_PAD_IS_LINKED (GST_BASE_TRANSFORM (navseek)->sinkpad)) {
    GstPad *peer_pad = gst_pad_get_peer (GST_BASE_TRANSFORM (navseek)->sinkpad);

    ret = gst_pad_send_event (peer_pad, event);
    gst_object_unref (peer_pad);
  }

  return ret;
}
Ejemplo n.º 30
0
static void
brasero_transcode_new_decoded_pad_cb (GstElement *decode,
				      GstPad *pad,
				      BraseroTranscode *transcode)
{
	GstCaps *caps;
	GstStructure *structure;
	BraseroTranscodePrivate *priv;

	priv = BRASERO_TRANSCODE_PRIVATE (transcode);

	BRASERO_JOB_LOG (transcode, "New pad");

	/* make sure we only have audio */
	/* FIXME: get_current_caps() doesn't always seem to work yet here */
	caps = gst_pad_query_caps (pad, NULL);
	if (!caps)
		return;

	structure = gst_caps_get_structure (caps, 0);
	if (structure) {
		if (g_strrstr (gst_structure_get_name (structure), "audio")) {
			GstPad *sink;
			GstElement *queue;
			GstPadLinkReturn res;

			/* before linking pads (before any data reach grvolume), send tags */
			brasero_transcode_send_volume_event (transcode);

			/* This is necessary in case there is a video stream
			 * (see brasero-metadata.c). we need to queue to avoid
			 * a deadlock. */
			queue = gst_element_factory_make ("queue", NULL);
			gst_bin_add (GST_BIN (priv->pipeline), queue);
			if (!gst_element_link (queue, priv->link)) {
				brasero_transcode_error_on_pad_linking (transcode, "Sent by brasero_transcode_new_decoded_pad_cb");
				goto end;
			}

			sink = gst_element_get_static_pad (queue, "sink");
			if (GST_PAD_IS_LINKED (sink)) {
				brasero_transcode_error_on_pad_linking (transcode, "Sent by brasero_transcode_new_decoded_pad_cb");
				goto end;
			}

			res = gst_pad_link (pad, sink);
			if (res == GST_PAD_LINK_OK)
				gst_element_set_state (queue, GST_STATE_PLAYING);
			else
				brasero_transcode_error_on_pad_linking (transcode, "Sent by brasero_transcode_new_decoded_pad_cb");

			gst_object_unref (sink);
		}
		/* For video streams add a fakesink (see brasero-metadata.c) */
		else if (g_strrstr (gst_structure_get_name (structure), "video")) {
			GstPad *sink;
			GstElement *fakesink;
			GstPadLinkReturn res;

			BRASERO_JOB_LOG (transcode, "Adding a fakesink for video stream");

			fakesink = gst_element_factory_make ("fakesink", NULL);
			if (!fakesink) {
				brasero_transcode_error_on_pad_linking (transcode, "Sent by brasero_transcode_new_decoded_pad_cb");
				goto end;
			}

			sink = gst_element_get_static_pad (fakesink, "sink");
			if (!sink) {
				brasero_transcode_error_on_pad_linking (transcode, "Sent by brasero_transcode_new_decoded_pad_cb");
				gst_object_unref (fakesink);
				goto end;
			}

			gst_bin_add (GST_BIN (priv->pipeline), fakesink);
			res = gst_pad_link (pad, sink);

			if (res == GST_PAD_LINK_OK)
				gst_element_set_state (fakesink, GST_STATE_PLAYING);
			else
				brasero_transcode_error_on_pad_linking (transcode, "Sent by brasero_transcode_new_decoded_pad_cb");

			gst_object_unref (sink);
		}
	}

end:
	gst_caps_unref (caps);
}