feat: basic-tutorial-6 finish
parent
905ac7fb1e
commit
9768fa1cb4
|
@ -8,7 +8,8 @@ include_directories(/usr/lib/aarch64-linux-gnu/glib-2.0/include)
|
|||
|
||||
# add_executable(${PROJECT_NAME} basic-tutorial-1.c)
|
||||
# add_executable(${PROJECT_NAME} basic-tutorial-2.c)
|
||||
add_executable(${PROJECT_NAME} basic-tutorial-3.c)
|
||||
# add_executable(${PROJECT_NAME} basic-tutorial-3.c)
|
||||
add_executable(${PROJECT_NAME} basic-tutorial-6.c)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
gstreamer-1.0
|
||||
|
|
|
@ -0,0 +1,217 @@
|
|||
#include <gst/gst.h>
|
||||
|
||||
static gboolean print_field (GQuark field,const GValue *value, gpointer pfx)
|
||||
{
|
||||
gchar *str = gst_value_serialize (value);
|
||||
g_print("%s %15s: %s\n",(gchar *)pfx, g_quark_to_string(field),str);
|
||||
g_free(str);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void print_caps (const GstCaps *caps, const gchar *pfx)
|
||||
{
|
||||
guint i;
|
||||
g_return_if_fail (caps != NULL);
|
||||
|
||||
if(gst_caps_is_any(caps))
|
||||
{
|
||||
g_print("%sANY\n",pfx);
|
||||
return;
|
||||
}
|
||||
if(gst_caps_is_empty(caps))
|
||||
{
|
||||
g_print("%sEMPTY\n",pfx);
|
||||
return;
|
||||
}
|
||||
|
||||
for( i = 0; i < gst_caps_get_size(caps);i++)
|
||||
{
|
||||
GstStructure *structure = gst_caps_get_structure(caps,i);
|
||||
|
||||
g_print("%s%s\n",pfx,gst_structure_get_name(structure));
|
||||
gst_structure_foreach(structure,print_field,(gpointer)pfx);
|
||||
}
|
||||
}
|
||||
|
||||
static void print_pad_templates_information (GstElementFactory *factory)
|
||||
{
|
||||
const GList *pads;
|
||||
GstStaticPadTemplate *padtemplate;
|
||||
|
||||
g_print("Pad Templates for %s:\n",gst_element_factory_get_longname(factory));
|
||||
if(!gst_element_factory_get_num_pad_templates(factory))
|
||||
{
|
||||
g_print(" none\n");
|
||||
return;
|
||||
}
|
||||
|
||||
pads = gst_element_factory_get_static_pad_templates(factory);
|
||||
while(pads)
|
||||
{
|
||||
padtemplate = pads->data;
|
||||
pads = g_list_next(pads);
|
||||
if(padtemplate->direction == GST_PAD_SRC)
|
||||
{
|
||||
g_print("SRC template: '%s'\n",padtemplate->name_template);
|
||||
}
|
||||
else if(padtemplate->direction == GST_PAD_SINK)
|
||||
{
|
||||
g_print("SINK template: '%s'\n",padtemplate->name_template);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_print("UNKNOWN!! template: '%s'\n",padtemplate->name_template);
|
||||
}
|
||||
|
||||
if(padtemplate->presence == GST_PAD_ALWAYS)
|
||||
{
|
||||
g_print(" Availability: Always\n");
|
||||
}
|
||||
else if(padtemplate->presence == GST_PAD_SOMETIMES)
|
||||
{
|
||||
g_print(" Availability: Sometimes\n");
|
||||
}
|
||||
else if(padtemplate->presence == GST_PAD_REQUEST)
|
||||
{
|
||||
g_print(" Availability: On request\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
g_print(" Availability: UNKNOWN!!!\n");
|
||||
}
|
||||
|
||||
if(padtemplate->static_caps.string)
|
||||
{
|
||||
GstCaps *caps;
|
||||
g_print(" Capabilities: \n");
|
||||
caps = gst_static_caps_get(&padtemplate->static_caps);
|
||||
print_caps(caps, " ");
|
||||
gst_caps_unref(caps);
|
||||
}
|
||||
g_print("\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void print_pad_capabilities(GstElement *element, gchar *pad_name)
|
||||
{
|
||||
GstPad *pad = NULL;
|
||||
GstCaps *caps = NULL;
|
||||
|
||||
pad = gst_element_get_static_pad(element, pad_name);
|
||||
if(!pad)
|
||||
{
|
||||
g_printerr("Could not retrieve pad '%s'\n",pad_name);
|
||||
return;
|
||||
}
|
||||
|
||||
caps = gst_pad_get_current_caps(pad);
|
||||
if(!caps)
|
||||
{
|
||||
caps = gst_pad_query_caps(pad,NULL);
|
||||
|
||||
g_print("Caps for the %s pad:\n",pad_name);
|
||||
print_caps(caps," ");
|
||||
gst_caps_unref(caps);
|
||||
gst_object_unref(pad);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
GstElement *pipeline, *source, *sink;
|
||||
GstElementFactory *source_factory,*sink_factory;
|
||||
GstBus *bus;
|
||||
GstMessage *msg;
|
||||
GstStateChangeReturn ret;
|
||||
gboolean terminate = FALSE;
|
||||
|
||||
gst_init(&argc,&argv);
|
||||
|
||||
source_factory = gst_element_factory_find("audiotestsrc");
|
||||
sink_factory = gst_element_factory_find("autoaudiosink");
|
||||
if(!source_factory || !sink_factory)
|
||||
{
|
||||
g_printerr("Not all element fatories could be created.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
print_pad_templates_information(source_factory);
|
||||
print_pad_templates_information(sink_factory);
|
||||
|
||||
source = gst_element_factory_create(source_factory,"source");
|
||||
sink = gst_element_factory_create(sink_factory,"sink");
|
||||
|
||||
pipeline = gst_pipeline_new("test-pipeline");
|
||||
|
||||
if(!pipeline || !source || !sink)
|
||||
{
|
||||
g_printerr("Not all element could be created!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
gst_bin_add_many(GST_BIN(pipeline),source,sink,NULL);
|
||||
if(gst_element_link(source,sink)!=TRUE)
|
||||
{
|
||||
g_printerr("Elements could not be linked!\n");
|
||||
g_object_unref(pipeline);
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_print("In NULL state:\n");
|
||||
print_pad_capabilities(sink,"sink");
|
||||
|
||||
ret = gst_element_set_state(pipeline,GST_STATE_PLAYING);
|
||||
if(ret == GST_STATE_CHANGE_FAILURE)
|
||||
{
|
||||
g_printerr("Unable to set the pipeline to the playing state (check the bus for error message).\n");
|
||||
}
|
||||
|
||||
bus = gst_element_get_bus(pipeline);
|
||||
do
|
||||
{
|
||||
msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS |GST_MESSAGE_STATE_CHANGED);
|
||||
|
||||
if(msg != NULL)
|
||||
{
|
||||
GError *err;
|
||||
gchar *debug_info;
|
||||
|
||||
switch (GST_MESSAGE_TYPE (msg))
|
||||
{
|
||||
case GST_MESSAGE_ERROR:
|
||||
gst_message_parse_error(msg, &err, &debug_info);
|
||||
g_printerr("Error received from element %s: %s\n",GST_OBJECT_NAME(msg->src),err->message);
|
||||
g_printerr("Debugging information: %s\n",debug_info ? debug_info : "none");
|
||||
g_clear_error(&err);
|
||||
g_free(debug_info);
|
||||
terminate = TRUE;
|
||||
break;
|
||||
case GST_MESSAGE_EOS:
|
||||
g_print("End-Of-Stream reached.\n");
|
||||
terminate = TRUE;
|
||||
break;
|
||||
case GST_MESSAGE_STATE_CHANGED:
|
||||
if(GST_MESSAGE_SRC(msg) == GST_OBJECT(pipeline))
|
||||
{
|
||||
GstState old_state,new_state,pending_state;
|
||||
gst_message_parse_state_changed(msg,&old_state,&new_state,&pending_state);
|
||||
g_print("\nPipeline state changed from %s to %s:\n",
|
||||
gst_element_state_get_name(old_state),gst_element_state_get_name(new_state));
|
||||
print_pad_capabilities(sink,"sink");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
g_printerr("Unexpected message received.\n");
|
||||
break;
|
||||
}
|
||||
gst_message_unref(msg);
|
||||
}
|
||||
}while(!terminate);
|
||||
|
||||
gst_object_unref(bus);
|
||||
gst_element_set_state(pipeline,GST_STATE_NULL);
|
||||
gst_object_unref(pipeline);
|
||||
gst_object_unref(source_factory);
|
||||
gst_object_unref(sink_factory);
|
||||
return;
|
||||
}
|
|
@ -123,32 +123,32 @@ BasicTutorial/fast:
|
|||
$(MAKE) -f CMakeFiles/BasicTutorial.dir/build.make CMakeFiles/BasicTutorial.dir/build
|
||||
.PHONY : BasicTutorial/fast
|
||||
|
||||
basic-tutorial-3.o: basic-tutorial-3.c.o
|
||||
basic-tutorial-6.o: basic-tutorial-6.c.o
|
||||
|
||||
.PHONY : basic-tutorial-3.o
|
||||
.PHONY : basic-tutorial-6.o
|
||||
|
||||
# target to build an object file
|
||||
basic-tutorial-3.c.o:
|
||||
$(MAKE) -f CMakeFiles/BasicTutorial.dir/build.make CMakeFiles/BasicTutorial.dir/basic-tutorial-3.c.o
|
||||
.PHONY : basic-tutorial-3.c.o
|
||||
basic-tutorial-6.c.o:
|
||||
$(MAKE) -f CMakeFiles/BasicTutorial.dir/build.make CMakeFiles/BasicTutorial.dir/basic-tutorial-6.c.o
|
||||
.PHONY : basic-tutorial-6.c.o
|
||||
|
||||
basic-tutorial-3.i: basic-tutorial-3.c.i
|
||||
basic-tutorial-6.i: basic-tutorial-6.c.i
|
||||
|
||||
.PHONY : basic-tutorial-3.i
|
||||
.PHONY : basic-tutorial-6.i
|
||||
|
||||
# target to preprocess a source file
|
||||
basic-tutorial-3.c.i:
|
||||
$(MAKE) -f CMakeFiles/BasicTutorial.dir/build.make CMakeFiles/BasicTutorial.dir/basic-tutorial-3.c.i
|
||||
.PHONY : basic-tutorial-3.c.i
|
||||
basic-tutorial-6.c.i:
|
||||
$(MAKE) -f CMakeFiles/BasicTutorial.dir/build.make CMakeFiles/BasicTutorial.dir/basic-tutorial-6.c.i
|
||||
.PHONY : basic-tutorial-6.c.i
|
||||
|
||||
basic-tutorial-3.s: basic-tutorial-3.c.s
|
||||
basic-tutorial-6.s: basic-tutorial-6.c.s
|
||||
|
||||
.PHONY : basic-tutorial-3.s
|
||||
.PHONY : basic-tutorial-6.s
|
||||
|
||||
# target to generate assembly for a file
|
||||
basic-tutorial-3.c.s:
|
||||
$(MAKE) -f CMakeFiles/BasicTutorial.dir/build.make CMakeFiles/BasicTutorial.dir/basic-tutorial-3.c.s
|
||||
.PHONY : basic-tutorial-3.c.s
|
||||
basic-tutorial-6.c.s:
|
||||
$(MAKE) -f CMakeFiles/BasicTutorial.dir/build.make CMakeFiles/BasicTutorial.dir/basic-tutorial-6.c.s
|
||||
.PHONY : basic-tutorial-6.c.s
|
||||
|
||||
# Help Target
|
||||
help:
|
||||
|
@ -159,9 +159,9 @@ help:
|
|||
@echo "... rebuild_cache"
|
||||
@echo "... edit_cache"
|
||||
@echo "... BasicTutorial"
|
||||
@echo "... basic-tutorial-3.o"
|
||||
@echo "... basic-tutorial-3.i"
|
||||
@echo "... basic-tutorial-3.s"
|
||||
@echo "... basic-tutorial-6.o"
|
||||
@echo "... basic-tutorial-6.i"
|
||||
@echo "... basic-tutorial-6.s"
|
||||
.PHONY : help
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue