Esempio n. 1
0
/* Main method for the native code. This is executed on its own thread. */
void *
app_function(void *userdata)
{
	CustomData *data = (CustomData *) userdata;

	GPlayerDEBUG("Creating pipeline in CustomData at %p", data);

	/* Create our own GLib Main Context and make it the default one */
	data->context = g_main_context_new();
	g_main_context_push_thread_default(data->context);

	data->pipeline = gst_pipeline_new("test-pipeline");

	build_pipeline(data);

	/* Create a GLib Main Loop and set it to run */
	GPlayerDEBUG("Entering main loop... (CustomData:%p)", data);
	data->main_loop = g_main_loop_new(data->context, FALSE);
	check_initialization_complete(data);
	g_main_loop_run(data->main_loop);
	GPlayerDEBUG("Exited main loop");

	/* Free resources */
	g_main_context_pop_thread_default(data->context);
	g_main_context_unref(data->context);
	data->target_state = GST_STATE_NULL;
	gst_element_set_state(data->pipeline, GST_STATE_NULL);
	kill_object(data->pipeline);

	return NULL;
}
Esempio n. 2
0
void cb_typefound(GstElement *typefind, guint probability, GstCaps *caps, CustomData *data)
{
	GstAudioInfo info;
	gst_audio_info_from_caps(&info, caps);
	data->audio_info = info;
	GPlayerDEBUG("  Rate is '%i'.\n", info.rate);
	GPlayerDEBUG("  Channels is '%i'.\n", info.channels);
	GPlayerDEBUG("  Width is '%i'.\n", info.finfo->width);
	gint req_buffer_size = info.rate * info.channels * info.finfo->width / 8 * BUFFER_TIME;
	GPlayerDEBUG("Request buffer size: %i for %i [s] of playback.\n", req_buffer_size, BUFFER_TIME);
	buffer_size(data, req_buffer_size);
	kill_object(&info);
}
Esempio n. 3
0
/* This function will be called by the pad-added signal */
void pad_added_handler(GstElement *src, GstPad *new_pad, CustomData *data)
{
	GstPad *sink_pad = gst_element_get_static_pad(data->buffer, "sink");
	GstPadLinkReturn ret;
	GstCaps *new_pad_caps = NULL;
	GstStructure *new_pad_struct = NULL;
	const gchar *new_pad_type = NULL;

	GPlayerDEBUG("Received new pad '%s' from '%s':\n", GST_PAD_NAME(new_pad), GST_ELEMENT_NAME(src));

	/* If our converter is already linked, we have nothing to do here */
	if (gst_pad_is_linked(sink_pad))
	{
		GPlayerDEBUG("  We are already linked. Ignoring.\n");
		goto exit;
	}

	/* Check the new pad's type */
	new_pad_caps = gst_pad_query_caps(new_pad, NULL);
	new_pad_struct = gst_caps_get_structure(new_pad_caps, 0);
	new_pad_type = gst_structure_get_name(new_pad_struct);
	if (!g_str_has_prefix(new_pad_type, "audio/x-raw"))
	{
		GPlayerDEBUG("  It has type '%s' which is not raw audio. Ignoring.\n", new_pad_type);
		goto exit;
	}

	/* Attempt the link */
	ret = gst_pad_link(new_pad, sink_pad);
	if (GST_PAD_LINK_FAILED(ret))
	{
		GPlayerDEBUG("  Type is '%s' but link failed.\n", new_pad_type);
		gplayer_error(-1, data);
		data->target_state = GST_STATE_NULL;
		data->is_live = (gst_element_set_state(data->pipeline, data->target_state) == GST_STATE_CHANGE_NO_PREROLL);
	}
	else
	{
		GPlayerDEBUG("  Link succeeded (type '%s').\n", new_pad_type);
	}

	exit:
	/* Unreference the new pad's caps, if we got them */
	if (new_pad_caps != NULL)
		gst_caps_unref(new_pad_caps);

	/* Unreference the sink pad */
	kill_object(sink_pad);
}
Esempio n. 4
0
// ---------------------------------------------------------------------------
// 
// -----------
bool bMacMapType::clone_object(bGenericGeoElement	*fin,	bGenericGeoElement	**fout){
_bTrace_("bMacMapType::clone_object",false);
	(*fout)=NULL;
	if(is_lock()){
		return(false);
	}
int					status;
bMacMapGeoElement*	obj=new bMacMapGeoElement((bMacMapGeoElement*)fin,&status);
	if(status<0){
_te_("status = "+status);
		_nbalive++;// DŽcrŽmentŽ dans kill object
		kill_object(obj);
		delete obj;
		(*fout)=NULL;
		return(false);
	}
	_nbalive++;
	(*fout)=obj;
	return(true);
}
Esempio n. 5
0
void build_pipeline(CustomData *data)
{
	GstBus *bus;
	GError *error = NULL;
	guint flags;

	data->count_buffer_fill = 0;
	data->no_buffer_fill = 0;
	data->buffer_is_slow = 0;
	data->counter = 0;

	pthread_mutex_lock(&data->mutex);
	gst_element_set_state(data->pipeline, GST_STATE_NULL);
	kill_object(data->pipeline);

	gplayer_error(BUFFER_SLOW, data);
	data->delta_index = 0;
	data->last_buffer_load = 0;
	data->buffering_time = 0;
	data->flow_error = FALSE;
	data->pipeline = gst_pipeline_new("test-pipeline");
	data->allow_seek = FALSE;

	/* Build pipeline */
	data->source = gst_element_factory_make("uridecodebin", "source");
	data->resample = gst_element_factory_make("audioresample", "resample");
	data->typefinder = gst_element_factory_make("typefind", "typefind");
	data->buffer = gst_element_factory_make("queue2", "buffer");
	data->convert = gst_element_factory_make("audioconvert", "convert");
	data->volume = gst_element_factory_make("volume", "volume");
	data->sink = gst_element_factory_make("autoaudiosink", "sink");

	if (!data->pipeline || !data->resample || !data->source || !data->convert || !data->buffer || !data->typefinder || !data->volume || !data->sink)
	{
		gplayer_error(-1, data);
		GPlayerDEBUG("Not all elements could be created.\n");
		pthread_mutex_unlock(&data->mutex);
		return;
	}

	gst_bin_add_many(GST_BIN(data->pipeline), data->source, data->buffer, data->typefinder, data->convert, data->resample, data->volume, data->sink,
	NULL);
	if (!gst_element_link(data->buffer, data->typefinder) || !gst_element_link(data->typefinder, data->convert)
			|| !gst_element_link(data->convert, data->resample) || !gst_element_link(data->resample, data->volume)
			|| !gst_element_link(data->volume, data->sink))
	{
		GPlayerDEBUG("Elements could not be linked.\n");
		kill_object(data->pipeline);
		pthread_mutex_unlock(&data->mutex);
		return;
	}

	g_signal_connect(data->source, "pad-added", (GCallback ) pad_added_handler, data);
	g_signal_connect(data->typefinder, "have-type", (GCallback ) cb_typefound, data);

	data->target_state = GST_STATE_READY;
	gst_element_set_state(data->pipeline, GST_STATE_READY);

	bus = gst_element_get_bus(data->pipeline);

	g_signal_connect(G_OBJECT(bus), "message::error", (GCallback ) error_cb, data);
	g_signal_connect(G_OBJECT(bus), "message::eos", (GCallback ) eos_cb, data);
	g_signal_connect(G_OBJECT(bus), "message::tag", (GCallback ) tag_cb, data);
	g_signal_connect(G_OBJECT(bus), "message::state-changed", (GCallback ) state_changed_cb, data);
	g_signal_connect(G_OBJECT(bus), "message::clock-lost", (GCallback ) clock_lost_cb, data);
	kill_object(bus);

	pthread_mutex_unlock(&data->mutex);
}