Example #1
0
static void
mpegts_base_loop (MpegTSBase * base)
{
  GstFlowReturn ret = GST_FLOW_ERROR;

  switch (base->mode) {
    case BASE_MODE_SCANNING:
      /* Find first sync point */
      ret = mpegts_base_scan (base);
      if (G_UNLIKELY (ret != GST_FLOW_OK))
        goto error;
      base->mode = BASE_MODE_STREAMING;
      GST_DEBUG ("Changing to Streaming");
      break;
    case BASE_MODE_SEEKING:
      /* FIXME : unclear if we still need mode_seeking... */
      base->mode = BASE_MODE_STREAMING;
      break;
    case BASE_MODE_STREAMING:
    {
      GstBuffer *buf = NULL;

      GST_DEBUG ("Pulling data from %" G_GUINT64_FORMAT, base->seek_offset);

      ret = gst_pad_pull_range (base->sinkpad, base->seek_offset,
          100 * base->packetsize, &buf);
      if (G_UNLIKELY (ret != GST_FLOW_OK))
        goto error;
      base->seek_offset += gst_buffer_get_size (buf);
      ret = mpegts_base_chain (base->sinkpad, GST_OBJECT_CAST (base), buf);
      if (G_UNLIKELY (ret != GST_FLOW_OK))
        goto error;
    }
      break;
    case BASE_MODE_PUSHING:
      GST_WARNING ("wrong BASE_MODE_PUSHING mode in pull loop");
      break;
  }

  return;

error:
  {
    const gchar *reason = gst_flow_get_name (ret);
    GST_DEBUG_OBJECT (base, "Pausing task, reason %s", reason);
    if (ret == GST_FLOW_EOS) {
      if (!GST_MPEGTS_BASE_GET_CLASS (base)->push_event (base,
              gst_event_new_eos ()))
        GST_ELEMENT_ERROR (base, STREAM, FAILED,
            (_("Internal data stream error.")),
            ("No program activated before EOS"));
    } else if (ret == GST_FLOW_NOT_LINKED || ret < GST_FLOW_EOS) {
      GST_ELEMENT_ERROR (base, STREAM, FAILED,
          (_("Internal data stream error.")),
          ("stream stopped, reason %s", reason));
      GST_MPEGTS_BASE_GET_CLASS (base)->push_event (base, gst_event_new_eos ());
    }
    gst_pad_pause_task (base->sinkpad);
  }
}
Example #2
0
static void
gst_gme_play (GstPad * pad)
{
  GstGmeDec *gme = GST_GME_DEC (gst_pad_get_parent (pad));
  GstFlowReturn flow_return;
  GstBuffer *out;
  gboolean seeking = gme->seeking;
  gme_err_t gme_err = NULL;
  const int NUM_SAMPLES = 1600; /* 4 bytes (stereo 16-bit) per sample */

  if (!seeking) {
    GstMapInfo map;

    out = gst_buffer_new_and_alloc (NUM_SAMPLES * 4);
    GST_BUFFER_TIMESTAMP (out) = gme_tell (gme->player) * GST_MSECOND;

    gst_buffer_map (out, &map, GST_MAP_WRITE);
    gme_err = gme_play (gme->player, NUM_SAMPLES * 2, (short *) map.data);
    gst_buffer_unmap (out, &map);

    if (gme_err) {
      GST_ELEMENT_ERROR (gme, STREAM, DEMUX, (NULL), ("%s", gme_err));
      gst_pad_pause_task (pad);
      gst_pad_push_event (pad, gst_event_new_eos ());
      gst_object_unref (gme);
      return;
    }
  } else {
    gme_seek (gme->player, gme->seekpoint);
    gme->seeking = FALSE;

    out = gst_buffer_new ();
  }

  if ((flow_return = gst_pad_push (gme->srcpad, out)) != GST_FLOW_OK) {
    GST_DEBUG_OBJECT (gme, "pausing task, reason %s",
        gst_flow_get_name (flow_return));

    gst_pad_pause_task (pad);

    if (flow_return == GST_FLOW_EOS) {
      gst_pad_push_event (pad, gst_event_new_eos ());
    } else if (flow_return < GST_FLOW_EOS || flow_return == GST_FLOW_NOT_LINKED) {
      GST_ELEMENT_ERROR (gme, STREAM, FAILED, ("Internal data stream error."),
          ("stream stopped, reason %s", gst_flow_get_name (flow_return)));

      gst_pad_push_event (pad, gst_event_new_eos ());
    }
  }

  if (gme_tell (gme->player) * GST_MSECOND > gme->total_duration) {
    gst_pad_pause_task (pad);
    gst_pad_push_event (pad, gst_event_new_eos ());
  }

  gst_object_unref (gme);

  return;
}
Example #3
0
static void
gst_nle_source_push_eos (GstNleSource * nlesrc)
{
  GST_INFO_OBJECT (nlesrc, "All items rendered, pushing eos");

  /* push on both sink pads of our A/V prep bins */
  gst_pad_send_event (nlesrc->video_sinkpad, gst_event_new_eos ());
  gst_pad_send_event (nlesrc->audio_sinkpad, gst_event_new_eos ());
}
KUIRecord::~KUIRecord()
{
  gst_element_send_event (screenEnc, gst_event_new_eos ());
  gst_element_send_event (camEnc, gst_event_new_eos ());
  gst_element_send_event (audioEnc, gst_event_new_eos());
  gst_element_send_event(pipeline, gst_event_new_flush_stop());
  gst_element_set_state(pipeline, GST_STATE_NULL);
  gst_object_unref(pipeline);  
}
Example #5
0
static void
user_read_data (png_structp png_ptr, png_bytep data, png_size_t length)
{
  GstPngDec *pngdec;
  GstBuffer *buffer;
  GstFlowReturn ret = GST_FLOW_OK;
  guint size;

  pngdec = GST_PNGDEC (png_get_io_ptr (png_ptr));

  GST_LOG ("reading %" G_GSIZE_FORMAT " bytes of data at offset %d", length,
      pngdec->offset);

  ret = gst_pad_pull_range (pngdec->sinkpad, pngdec->offset, length, &buffer);
  if (ret != GST_FLOW_OK)
    goto pause;

  size = GST_BUFFER_SIZE (buffer);

  if (size != length)
    goto short_buffer;

  memcpy (data, GST_BUFFER_DATA (buffer), size);

  gst_buffer_unref (buffer);

  pngdec->offset += length;

  return;

  /* ERRORS */
pause:
  {
    GST_INFO_OBJECT (pngdec, "pausing task, reason %s",
        gst_flow_get_name (ret));
    gst_pad_pause_task (pngdec->sinkpad);
    if (ret == GST_FLOW_UNEXPECTED) {
      gst_pad_push_event (pngdec->srcpad, gst_event_new_eos ());
    } else if (ret < GST_FLOW_UNEXPECTED || ret == GST_FLOW_NOT_LINKED) {
      GST_ELEMENT_ERROR (pngdec, STREAM, FAILED,
          (_("Internal data stream error.")),
          ("stream stopped, reason %s", gst_flow_get_name (ret)));
      gst_pad_push_event (pngdec->srcpad, gst_event_new_eos ());
    }
    png_error (png_ptr, "Internal data stream error.");
    return;
  }
short_buffer:
  {
    gst_buffer_unref (buffer);
    GST_ELEMENT_ERROR (pngdec, STREAM, FAILED,
        (_("Internal data stream error.")),
        ("Read %u, needed %" G_GSIZE_FORMAT "bytes", size, length));
    ret = GST_FLOW_ERROR;
    goto pause;
  }
}
Example #6
0
static void
gst_nuv_demux_send_eos (GstNuvDemux * nuv)
{
  gst_element_post_message (GST_ELEMENT (nuv),
      gst_message_new_segment_done (GST_OBJECT (nuv), GST_FORMAT_TIME, -1));

  if (nuv->src_video_pad)
    gst_pad_push_event (nuv->src_video_pad, gst_event_new_eos ());
  if (nuv->src_audio_pad)
    gst_pad_push_event (nuv->src_audio_pad, gst_event_new_eos ());
}
Example #7
0
static void
gst_funnel_release_pad (GstElement * element, GstPad * pad)
{
  GstFunnel *funnel = GST_FUNNEL (element);
  GstFunnelPad *fpad = GST_FUNNEL_PAD_CAST (pad);
  gboolean got_eos;
  gboolean send_eos = FALSE;

  GST_DEBUG_OBJECT (funnel, "releasing pad %s:%s", GST_DEBUG_PAD_NAME (pad));

  gst_pad_set_active (pad, FALSE);

  got_eos = fpad->got_eos;

  gst_element_remove_pad (GST_ELEMENT_CAST (funnel), pad);

  GST_OBJECT_LOCK (funnel);
  if (!got_eos && gst_funnel_all_sinkpads_eos_unlocked (funnel, NULL)) {
    GST_DEBUG_OBJECT (funnel, "Pad removed. All others are EOS. Sending EOS");
    send_eos = TRUE;
  }
  GST_OBJECT_UNLOCK (funnel);

  if (send_eos)
    if (!gst_pad_push_event (funnel->srcpad, gst_event_new_eos ()))
      GST_WARNING_OBJECT (funnel, "Failure pushing EOS");
}
Example #8
0
void ofGstUtils::close(){
	if(bPlaying){
		if(!bIsMovieDone && !bPaused && !isStream){
			std::unique_lock<std::mutex> lck(eosMutex);
			closing = true;
			gst_element_send_event(gstPipeline,gst_event_new_eos());
			if(eosCondition.wait_for(lck,std::chrono::milliseconds(5000))==std::cv_status::timeout){
				ofLogWarning("ofGstUtils") << "didn't received EOS in 5s, closing pipeline anyway";
			}
			closing = false;
		}
	}
	stop();

	if(bLoaded){
		gst_element_set_state(GST_ELEMENT(gstPipeline), GST_STATE_NULL);
		gst_element_get_state(gstPipeline,NULL,NULL,2*GST_SECOND);

		if(busWatchID!=0) g_source_remove(busWatchID);

		gst_object_unref(gstPipeline);
		gstPipeline = NULL;
		gstSink = NULL;
	}

	bLoaded = false;
}
Example #9
0
static void
switch_pads (GstHLSDemux * demux, GstCaps * newcaps)
{
  GstPad *oldpad = demux->srcpad;

  GST_DEBUG ("Switching pads (oldpad:%p)", oldpad);

  /* First create and activate new pad */
  demux->srcpad = gst_pad_new_from_static_template (&srctemplate, NULL);
  gst_pad_set_event_function (demux->srcpad,
      GST_DEBUG_FUNCPTR (gst_hls_demux_src_event));
  gst_pad_set_query_function (demux->srcpad,
      GST_DEBUG_FUNCPTR (gst_hls_demux_src_query));
  gst_pad_set_element_private (demux->srcpad, demux);
  gst_pad_set_active (demux->srcpad, TRUE);
  gst_pad_set_caps (demux->srcpad, newcaps);
  gst_element_add_pad (GST_ELEMENT (demux), demux->srcpad);

  gst_element_no_more_pads (GST_ELEMENT (demux));

  if (oldpad) {
    /* Push out EOS */
    gst_pad_push_event (oldpad, gst_event_new_eos ());
    gst_pad_set_active (oldpad, FALSE);
    gst_element_remove_pad (GST_ELEMENT (demux), oldpad);
  }
}
Example #10
0
static void
test_srt_do_test (SubParseInputChunk * input, guint start_idx, guint num)
{
  guint n;
  GstCaps *outcaps;

  GST_LOG ("srt test: start_idx = %u, num = %u", start_idx, num);

  setup_subparse ();

  for (n = start_idx; n < start_idx + num; ++n) {
    GstBuffer *buf;

    buf = buffer_from_static_string (input[n].in);
    fail_unless_equals_int (gst_pad_push (mysrcpad, buf), GST_FLOW_OK);
  }

  gst_pad_push_event (mysrcpad, gst_event_new_eos ());

  fail_unless_equals_int (g_list_length (buffers), num);

  outcaps = gst_pad_get_current_caps (mysinkpad);

  for (n = start_idx; n < start_idx + num; ++n) {
    const GstStructure *buffer_caps_struct;
    GstBuffer *buf;
    GstMapInfo map;

    buf = g_list_nth_data (buffers, n - start_idx);
    fail_unless (buf != NULL);
    fail_unless (GST_BUFFER_TIMESTAMP_IS_VALID (buf), NULL);
    fail_unless (GST_BUFFER_DURATION_IS_VALID (buf), NULL);
    fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (buf), input[n].from_ts);
    fail_unless_equals_uint64 (GST_BUFFER_DURATION (buf),
        input[n].to_ts - input[n].from_ts);

    gst_buffer_map (buf, &map, GST_MAP_READ);
    /* can be NULL */
    if (map.data != NULL) {
      /* shouldn't have trailing newline characters */
      fail_if (map.size > 0 && map.data[map.size - 1] == '\n');
      /* shouldn't include NUL-terminator in data size */
      fail_if (map.size > 0 && map.data[map.size - 1] == '\0');
      /* but should still have a  NUL-terminator behind the declared data */
      fail_unless_equals_int (map.data[map.size], '\0');
      /* make sure out string matches expected string */
      fail_unless_equals_string ((gchar *) map.data, input[n].out);
    }
    gst_buffer_unmap (buf, &map);
    /* check caps */
    fail_unless (outcaps != NULL);
    buffer_caps_struct = gst_caps_get_structure (outcaps, 0);
    fail_unless (gst_structure_has_name (buffer_caps_struct, "text/x-raw"));
    fail_unless_equals_string (gst_structure_get_string (buffer_caps_struct,
            "format"), "pango-markup");
  }
  gst_caps_unref (outcaps);

  teardown_subparse ();
}
Example #11
0
static void
pad_removed_cb (GstElement * element, GstPad * pad, gpointer data)
{
    GstElement *wavenc;
    GstPad *sinkpad;

    if (gst_pad_get_direction (pad) != GST_PAD_SRC)
        return;

    GST_DEBUG ("Removed pad %" GST_PTR_FORMAT, pad);
    wavenc = g_hash_table_lookup (hash, GST_OBJECT_NAME (pad));

    if (wavenc == NULL)
        return;

    GST_DEBUG ("Send EOS to %s", GST_OBJECT_NAME (wavenc));

    sinkpad = gst_element_get_static_pad (wavenc, "sink");
    gst_pad_send_event (sinkpad, gst_event_new_eos ());
    gst_object_unref (sinkpad);

#ifdef MANUAL_CHECK
    {
        /* Let test last for a few seconds to have a decent output file to debug */
        g_timeout_add_seconds (2, quit_main_loop, NULL);
    }
#else
    {
        g_idle_add (quit_main_loop, NULL);
    }
#endif
}
Example #12
0
static HRESULT WINAPI Gstreamer_transform_EndOfStream(TransformFilter *iface) {
    GstTfImpl *This = (GstTfImpl*)iface;
    TRACE("%p\n", This);

    gst_pad_push_event(This->my_src, gst_event_new_eos());
    return S_OK;
}
static void
input_selector_push_eos (gint stream, gboolean active)
{
  GstPad *pad = stream == 1 ? stream1_pad : stream2_pad;

  if (active) {
    fail_unless (gst_pad_push_event (pad, gst_event_new_eos ()));
  } else {
    /* The non-active pads will block when receving eos, so we need to do it
     * from a separate thread. This makes this test racy, but it should only
     * cause false positives, not false negatives */
    GThread *t = g_thread_new ("selector-test-push-eos",
        (GThreadFunc) input_selector_do_push_eos, pad);

    /* Sleep half a second to allow the other thread to execute, this is not
     * a definitive solution but there is no way to know when the
     * EOS has reached input-selector and blocked there, so this is just
     * to reduce the possibility of this test being racy (false positives)
     */
    g_usleep (0.5 * G_USEC_PER_SEC);
    g_thread_unref (t);
  }

  input_selector_check_eos (active);
}
Example #14
0
static GstFlowReturn
gst_compare_collect_pads (GstCollectPads2 * cpads, GstCompare * comp)
{
  GstBuffer *buf1, *buf2;

  buf1 = gst_collect_pads2_pop (comp->cpads,
      gst_pad_get_element_private (comp->sinkpad));

  buf2 = gst_collect_pads2_pop (comp->cpads,
      gst_pad_get_element_private (comp->checkpad));

  if (!buf1 && !buf2) {
    gst_pad_push_event (comp->srcpad, gst_event_new_eos ());
    return GST_FLOW_UNEXPECTED;
  } else if (buf1 && buf2) {
    gst_compare_buffers (comp, buf1, buf2);
  } else {
    GST_WARNING_OBJECT (comp, "buffer %p != NULL", buf1 ? buf1 : buf2);

    comp->count++;
    gst_element_post_message (GST_ELEMENT (comp),
        gst_message_new_element (GST_OBJECT (comp),
            gst_structure_new ("delta", "count", G_TYPE_INT, comp->count,
                NULL)));
  }

  if (buf1)
    gst_pad_push (comp->srcpad, buf1);

  if (buf2)
    gst_buffer_unref (buf2);

  return GST_FLOW_OK;
}
static GstEvent *
create_event (GstEventType type)
{
  GstEvent *event = NULL;

  switch (type) {
   case GST_EVENT_CUSTOM_DOWNSTREAM:
    event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM,
        gst_structure_new ("x-app/test", "test-field", G_TYPE_STRING,
            "test-value", NULL));
    break;
   case GST_EVENT_CUSTOM_DOWNSTREAM_OOB:
    event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM_OOB,
        gst_structure_new ("x-app/test", "test-field", G_TYPE_STRING,
            "test-value", NULL));
    break;
   case GST_EVENT_EOS:
    event = gst_event_new_eos ();
    break;
   default:
    g_assert_not_reached ();
    break;
  }

  return event;
}
Example #16
0
static int
gst_ffmpegdata_close (URLContext * h)
{
    GstProtocolInfo *info;

    info = (GstProtocolInfo *) h->priv_data;
    if (info == NULL)
        return 0;

    GST_LOG ("Closing file");

    switch (h->flags) {
    case URL_WRONLY:
    {
        /* send EOS - that closes down the stream */
        gst_pad_push_event (info->pad, gst_event_new_eos ());
        break;
    }
    default:
        break;
    }

    /* clean up data */
    g_free (info);
    h->priv_data = NULL;

    return 0;
}
Example #17
0
static void
user_read_data (png_structp png_ptr, png_bytep data, png_size_t length)
{
  GstPngDec *pngdec;
  GstBuffer *buffer;
  GstFlowReturn ret = GST_FLOW_OK;

  pngdec = GST_PNGDEC (png_ptr->io_ptr);

  GST_LOG ("reading %" G_GSIZE_FORMAT " bytes of data at offset %d", length,
      pngdec->offset);

  ret = gst_pad_pull_range (pngdec->sinkpad, pngdec->offset, length, &buffer);
  if ((ret != GST_FLOW_OK) || (GST_BUFFER_SIZE (buffer) != length))
    goto pause;

  memcpy (data, GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer));

  gst_buffer_unref (buffer);

  pngdec->offset += length;

  return;

pause:
  GST_INFO_OBJECT (pngdec, "pausing task, reason %s", gst_flow_get_name (ret));
  gst_pad_pause_task (pngdec->sinkpad);
  if (GST_FLOW_IS_FATAL (ret) || ret == GST_FLOW_NOT_LINKED) {
    gst_pad_push_event (pngdec->srcpad, gst_event_new_eos ());
    GST_ELEMENT_ERROR (pngdec, STREAM, FAILED,
        (_("Internal data stream error.")),
        ("stream stopped, reason %s", gst_flow_get_name (ret)));
  }
}
Example #18
0
void ofGstUtils::close(){
	if(bPlaying){
		if(!bIsMovieDone && !bPaused && !isStream){
			eosMutex.lock();
			closing = true;
			gst_element_send_event(gstPipeline,gst_event_new_eos());
			try{
				eosCondition.wait(eosMutex,5000);
			}catch(const Poco::TimeoutException & e){
				ofLogWarning("ofGstUtils") << "didn't received EOS in 5s, closing pipeline anyway";
			}
			eosMutex.unlock();
			closing = false;
		}
	}
	stop();

	if(bLoaded){
		gst_element_set_state(GST_ELEMENT(gstPipeline), GST_STATE_NULL);
		gst_element_get_state(gstPipeline,NULL,NULL,2*GST_SECOND);

		if(busWatchID!=0) g_source_remove(busWatchID);

		gst_object_unref(gstPipeline);
		gstPipeline = NULL;
		gstSink = NULL;
	}

	bLoaded = false;
}
Example #19
0
static gboolean pad_event_handler(GstPad *pad, GstEvent *event) {
	// Establish thread-local.
	MpfComponent *component = MPF_COMPONENT(GST_OBJECT_PARENT(pad));
	mpf_component_set_curcomponent(component);
	GstElement *element = gst_pad_get_parent_element(pad);

	gchar *elementname = gst_element_get_name(element);
	gchar *padname = gst_pad_get_name(pad);
	const gchar *eventname = gst_event_type_get_name(event->type);

	MPF_PRIVATE_ALWAYS("element=%s pad=%s event=%s\n", elementname, padname,
			eventname);
	// If EOS, poke a message out of the events pad.
	if (event->type == GST_EVENT_EOS) {
		GstPad *events = gst_element_get_pad(element, "events");

		printf("GstPad *events=%p\n", events);

		GString *string = g_string_new("");
		g_string_printf(string, "%s: EOS buffer_count=%d\n", elementname,
				mpf_private.buffer_count);
		mpf_voidstar_push("events", mpf_voidstar_stralloc(string->str));
		mpf_voidstar_send_outbuffers();
		gst_pad_push_event(events, gst_event_new_eos());
	}

	g_free(elementname);
	g_free(padname);
	return gst_pad_event_default(pad, event);
}
Example #20
0
void ofxGstRTPServer::close(){
	if(appSrcDepth){
		gst_element_send_event(appSrcDepth,gst_event_new_eos());
	}
	if(appSrcVideoRGB){
		gst_element_send_event(appSrcVideoRGB,gst_event_new_eos());
	}
	if(appSrcOsc){
		gst_element_send_event(appSrcOsc,gst_event_new_eos());
	}
	if(gst.getGstElementByName("audiocapture")){
		gst_element_send_event(gst.getGstElementByName("audiocapture"),gst_event_new_eos());
	}
	gst.close();
	vRTPsink = NULL;
	vRTPCsink = NULL;
	vRTPCsrc = NULL;
	vEncoder = NULL;
	dEncoder = NULL;
	aEncoder = NULL;
	appSrcVideoRGB = NULL;
	appSrcDepth = NULL;
	appSrcOsc = NULL;
	bufferPool = NULL;
	bufferPoolDepth = NULL;
	fps = 0;
	prevTimestamp = 0;
	numFrame = 0;
	prevTimestampDepth = 0;
	numFrameDepth = 0;
	prevTimestampOsc = 0;
	numFrameOsc = 0;
	width = 0;
	height = 0;
	lastSessionNumber = 0;
#if ENABLE_NAT_TRANSVERSAL
	videoStream.reset();
	depthStream.reset();
	oscStream.reset();
	audioStream.reset();
#endif
	firstVideoFrame = true;
	firstOscFrame = true;
	firstDepthFrame = true;

	ofRemoveListener(ofEvents().update,this,&ofxGstRTPServer::update);
}
static GstFlowReturn
gst_smart_encoder_reencode_gop (GstSmartEncoder * smart_encoder)
{
  GstFlowReturn res = GST_FLOW_OK;
  GList *tmp;

  if (smart_encoder->encoder == NULL) {
    if (!setup_recoder_pipeline (smart_encoder))
      return GST_FLOW_ERROR;
  }

  /* Activate elements */
  /* Set elements to PAUSED */
  gst_element_set_state (smart_encoder->encoder, GST_STATE_PAUSED);
  gst_element_set_state (smart_encoder->decoder, GST_STATE_PAUSED);

  GST_INFO ("Pushing Flush start/stop to clean decoder/encoder");
  gst_pad_push_event (smart_encoder->internal_srcpad,
      gst_event_new_flush_start ());
  gst_pad_push_event (smart_encoder->internal_srcpad,
      gst_event_new_flush_stop (TRUE));

  /* push newsegment */
  GST_INFO ("Pushing newsegment %" GST_PTR_FORMAT, smart_encoder->newsegment);
  gst_pad_push_event (smart_encoder->internal_srcpad,
      gst_event_ref (smart_encoder->newsegment));

  /* Push buffers through our pads */
  GST_DEBUG ("Pushing pending buffers");

  for (tmp = smart_encoder->pending_gop; tmp; tmp = tmp->next) {
    GstBuffer *buf = (GstBuffer *) tmp->data;

    res = gst_pad_push (smart_encoder->internal_srcpad, buf);
    if (G_UNLIKELY (res != GST_FLOW_OK))
      break;
  }

  if (G_UNLIKELY (res != GST_FLOW_OK)) {
    GST_WARNING ("Error pushing pending buffers : %s", gst_flow_get_name (res));
    /* Remove pending bfufers */
    for (tmp = smart_encoder->pending_gop; tmp; tmp = tmp->next) {
      gst_buffer_unref ((GstBuffer *) tmp->data);
    }
  } else {
    GST_INFO ("Pushing out EOS to flush out decoder/encoder");
    gst_pad_push_event (smart_encoder->internal_srcpad, gst_event_new_eos ());
  }

  /* Activate elements */
  /* Set elements to PAUSED */
  gst_element_set_state (smart_encoder->encoder, GST_STATE_NULL);
  gst_element_set_state (smart_encoder->decoder, GST_STATE_NULL);

  g_list_free (smart_encoder->pending_gop);
  smart_encoder->pending_gop = NULL;

  return res;
}
/**
 * hls_progress_buffer_loop()
 *
 * Primary function for push-mode.  Pulls data from progressbuffer's cache queue.
 */
static void hls_progress_buffer_loop(void *data)
{
    HLSProgressBuffer* element = HLS_PROGRESS_BUFFER(data);
    GstFlowReturn      result = GST_FLOW_OK;

    g_mutex_lock(element->lock);

    while (element->srcresult == GST_FLOW_OK && !cache_has_enough_data(element->cache[element->cache_read_index]))
    {
        if (element->is_eos)
        {
            gst_pad_push_event(element->srcpad, gst_event_new_eos());
            element->srcresult = GST_FLOW_WRONG_STATE;
            break;
        }

        if (!element->is_eos)
        {
            g_cond_wait(element->add_cond, element->lock);
        }
    }

    result = element->srcresult;

    if (result == GST_FLOW_OK)
    {
        GstBuffer *buffer = NULL;
        guint64 read_position = cache_read_buffer(element->cache[element->cache_read_index], &buffer);

        if (read_position == element->cache_size[element->cache_read_index])
        {
            element->cache_write_ready[element->cache_read_index] = TRUE;
            element->cache_read_index = (element->cache_read_index + 1) % NUM_OF_CACHED_SEGMENTS;
            send_hls_not_full_message(element);
            g_cond_signal(element->del_cond);
        }

        g_mutex_unlock(element->lock);

        gst_buffer_set_caps(buffer, GST_PAD_CAPS(element->sinkpad));

        // Send the data to the hls progressbuffer source pad
        result = gst_pad_push(element->srcpad, buffer);

        g_mutex_lock(element->lock);
        if (GST_FLOW_OK == element->srcresult || GST_FLOW_OK != result)
            element->srcresult = result;
        else
            result = element->srcresult;
        g_mutex_unlock(element->lock);
    }
    else
    {
        g_mutex_unlock(element->lock);
    }

    if (result != GST_FLOW_OK && !element->is_flushing)
        gst_pad_pause_task(element->srcpad);
}
static void
gst_tee_push_eos (const GValue * vpad, GstTee * tee)
{
  GstPad *pad = g_value_get_object (vpad);

  if (pad != tee->pull_pad)
    gst_pad_push_event (pad, gst_event_new_eos ());
}
Example #24
0
static void
do_test (SubParseInputChunk * input, guint num, const gchar * media_type)
{
    guint n;

    setup_subparse ();

    for (n = 0; n < num; ++n) {
        GstBuffer *buf;

        buf = buffer_from_static_string (input[n].in);
        fail_unless_equals_int (gst_pad_push (mysrcpad, buf), GST_FLOW_OK);
    }

    gst_pad_push_event (mysrcpad, gst_event_new_eos ());

    fail_unless_equals_int (g_list_length (buffers), num);

    for (n = 0; n < num; ++n) {
        const GstStructure *buffer_caps_struct;
        GstBuffer *buf;
        gchar *out;
        guint out_size;

        buf = g_list_nth_data (buffers, n);
        fail_unless (buf != NULL);

        /* check timestamp */
        fail_unless (GST_BUFFER_TIMESTAMP_IS_VALID (buf), NULL);
        fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (buf), input[n].from_ts);

        /* might not be able to put a duration on the last buffer */
        if (input[n].to_ts != GST_CLOCK_TIME_NONE) {
            /* check duration */
            fail_unless (GST_BUFFER_DURATION_IS_VALID (buf), NULL);
            fail_unless_equals_uint64 (GST_BUFFER_DURATION (buf),
                                       input[n].to_ts - input[n].from_ts);
        }

        out = (gchar *) GST_BUFFER_DATA (buf);
        out_size = GST_BUFFER_SIZE (buf);
        /* shouldn't have trailing newline characters */
        fail_if (out_size > 0 && out[out_size - 1] == '\n');
        /* shouldn't include NUL-terminator in data size */
        fail_if (out_size > 0 && out[out_size - 1] == '\0');
        /* but should still have a  NUL-terminator behind the declared data */
        fail_unless_equals_int (out[out_size], '\0');
        /* make sure out string matches expected string */
        fail_unless_equals_string (out, input[n].out);
        /* check caps */
        fail_unless (GST_BUFFER_CAPS (buf) != NULL);
        buffer_caps_struct = gst_caps_get_structure (GST_BUFFER_CAPS (buf), 0);
        fail_unless_equals_string (gst_structure_get_name (buffer_caps_struct),
                                   media_type);
    }

    teardown_subparse ();
}
Example #25
0
static void
do_end_of_track (GstSpotSrc *spot)
{
  GstPad *src_pad = gst_element_get_static_pad (GST_ELEMENT (spot), "src");
  GstPad *peer_pad = gst_pad_get_peer (src_pad);
  gst_pad_send_event (peer_pad, gst_event_new_eos ());
  spot->end_of_track = FALSE;
  gst_object_unref (peer_pad);
}
static void
do_two_buffers_test_apply (gboolean end_contiguous)
{
  GstBuffer *buffer_in, *buffer_out;
  GList *node;

  g_object_set (element, "ntp-offset", NTP_OFFSET, "cseq", 0x12345678,
      "set-e-bit", TRUE, NULL);

  ASSERT_SET_STATE (element, GST_STATE_PLAYING, GST_STATE_CHANGE_SUCCESS);

  buffer_in = create_rtp_buffer (TIMESTAMP, FALSE);
  buffer_out = create_extension_buffer (buffer_in, FALSE, end_contiguous,
      FALSE, NTP_OFFSET, CSEQ);

  /* push initial events */
  gst_check_setup_events (mysrcpad, element, NULL, GST_FORMAT_TIME);

  /* Push buffer */
  fail_unless_equals_int (gst_pad_push (mysrcpad, buffer_in), GST_FLOW_OK);

  /* The buffer hasn't been pushed it as the element is waiting for the next
   * buffer. */
  fail_unless_equals_int (g_list_length (buffers), 0);

  /* push an ntp-offset event to trigger a discontinuty */
  fail_unless (gst_pad_push_event (mysrcpad,
          create_ntp_offset_event (NTP_OFFSET, end_contiguous)));

  /* A second buffer is pushed */
  buffer_in = create_rtp_buffer (TIMESTAMP + 1, FALSE);

  fail_unless_equals_int (gst_pad_push (mysrcpad, buffer_in), GST_FLOW_OK);

  /* The first buffer has now been pushed out */
  fail_unless_equals_int (g_list_length (buffers), 1);

  node = g_list_last (buffers);
  check_buffer_equal ((GstBuffer *) node->data, buffer_out);
  gst_buffer_unref (buffer_out);

  /* Push EOS */
  fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ()));

  /* The second buffer has been pushed out */
  fail_unless_equals_int (g_list_length (buffers), 2);

  /* Last buffer always has the 'E' flag */
  buffer_out = create_extension_buffer (buffer_in, FALSE, TRUE, end_contiguous,
      NTP_OFFSET, CSEQ);
  node = g_list_last (buffers);
  check_buffer_equal ((GstBuffer *) node->data, buffer_out);
  gst_buffer_unref (buffer_out);

  ASSERT_SET_STATE (element, GST_STATE_NULL, GST_STATE_CHANGE_SUCCESS);
}
Example #27
0
//-----------------------------------------------------------------------------
void tIMX51Video::StopInternal()
{
    if( m_pGstPipeline )
    {
        //qDebug() << "tHalVideoSr2::StopInternal: gst_element_get_state";
        gst_element_get_state( m_pGstPipeline, NULL, NULL, 3000000000ULL );
    }

    if( m_RunningInternal )
    {
        killTimer(m_TimerId);
        m_RunningInternal = false;

        // Send an event down the gstreamer pipeline to stop the data being processed.
        // When the app has received this message, then we know all plugins have got the message.
        // (Needed because ipu_csc is using hw buffers mmap'd inside v4lsrc plugin. Since src
        // plugin stopped before csc, then this can cause problems)
        if( !EosReceived() )
        {
            qDebug() << "tHalVideoSr2::StopInternal: send EOS";
            int timeout = 5000;
            gst_element_send_event( m_pGstPipeline, gst_event_new_eos() );
            while(!EosReceived())
            {
                usleep(1000);
                timeout--;
                if(timeout == 0)
                {
                    qDebug() << "tHalVideoSr2::StopInternal: timeout waiting for EOS";
                    break;
                }
            }
            m_EosReceived = false;
        }
        else
            qDebug() << "tHalVideoSr2::StopInternal: EOS already received?";

        /*qDebug() << "tHalVideoSr2::StopInternal: ->PAUSED";
        gst_element_set_state( m_pGstPipeline, GST_STATE_PAUSED );
        gst_element_get_state( m_pGstPipeline, NULL, NULL, 3000000000ULL );
        while (g_main_context_iteration (NULL, FALSE)); // not sure the purpose of this - copied from 

        qDebug() << "tHalVideoSr2::StopInternal: ->READY";
        gst_element_set_state( m_pGstPipeline, GST_STATE_READY );
        gst_element_get_state( m_pGstPipeline, NULL, NULL, 3000000000ULL );*/

        qDebug() << "tHalVideoSr2::StopInternal: setting GST_STATE_NULL state";
        gst_element_set_state( m_pGstPipeline, GST_STATE_NULL );
        gst_element_get_state( m_pGstPipeline, NULL, NULL, 3000000000ULL );

        //qDebug() << "tHalVideoSr2::StopInternal: gst_object_unref";  
        gst_object_unref( GST_OBJECT( m_pGstPipeline ) );    
        m_pGstPipeline = 0;
    }
    qDebug() << "tHalVideoSr2::StopInternal: done";  
}
Example #28
0
static VALUE
eos_initialize(VALUE self)
{
    GstEvent *event;

    event = gst_event_new_eos();

    G_INITIALIZE(self, event);
    return Qnil;
}
Example #29
0
void
gst_droidcamsrc_dev_stop_video_recording (GstDroidCamSrcDev * dev)
{
  GST_DEBUG ("dev stop video recording");

  gst_buffer_pool_set_flushing (dev->pool, TRUE);

  /* We need to make sure that some buffers have been pushed */
  g_mutex_lock (&dev->vid->lock);
  while (dev->vid->video_frames <= 4) {
    g_cond_wait (&dev->vid->cond, &dev->vid->lock);
  }
  g_mutex_unlock (&dev->vid->lock);

  /* Now stop pushing to the pad */
  g_rec_mutex_lock (dev->lock);
  dev->vid->running = FALSE;
  g_rec_mutex_unlock (dev->lock);

  /* now make sure nothing is being pushed to the queue */
  g_mutex_lock (&dev->vid->lock);
  g_mutex_unlock (&dev->vid->lock);

  /* our pad task is either sleeping or still pushing buffers. We empty the queue. */
  g_mutex_lock (&dev->vidsrc->lock);
  g_queue_foreach (dev->vidsrc->queue, (GFunc) gst_buffer_unref, NULL);
  g_queue_clear (dev->vidsrc->queue);
  g_mutex_unlock (&dev->vidsrc->lock);

  /* now we are done. We just push eos */
  GST_DEBUG ("Pushing EOS");
  if (!gst_pad_push_event (dev->vidsrc->pad, gst_event_new_eos ())) {
    GST_ERROR ("failed to push EOS event");
  }

  g_rec_mutex_lock (dev->lock);

  GST_INFO ("waiting for queued frames %i", dev->vid->queued_frames);

  while (dev->vid->queued_frames > 0) {
    GST_INFO ("waiting for queued frames to reach 0 from %i",
        dev->vid->queued_frames);
    g_rec_mutex_unlock (dev->lock);
    usleep (VIDEO_RECORDING_STOP_TIMEOUT);
    g_rec_mutex_lock (dev->lock);
  }

  g_rec_mutex_unlock (dev->lock);

  droid_media_camera_stop_recording (dev->cam);

  gst_buffer_pool_set_flushing (dev->pool, FALSE);

  GST_INFO ("dev stopped video recording");
}
Example #30
0
static void
_push_eos (GstAggregator * self)
{
  GstEvent *event;
  _push_mandatory_events (self);

  self->priv->send_eos = FALSE;
  event = gst_event_new_eos ();
  gst_event_set_seqnum (event, self->priv->seqnum);
  gst_pad_push_event (self->srcpad, event);
}