fix: basic-tutorial-7.c works!

master
邱棚 2023-02-13 15:37:13 +00:00
parent 9768fa1cb4
commit 8c0acdf21a
4 changed files with 112 additions and 19 deletions

7
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,7 @@
{
// 使 IntelliSense
//
// 访: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": []
}

View File

@ -9,7 +9,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-1.c)
# add_executable(${PROJECT_NAME} basic-tutorial-2.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) # add_executable(${PROJECT_NAME} basic-tutorial-6.c)
add_executable(${PROJECT_NAME} basic-tutorial-7.c)
target_link_libraries(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME}
gstreamer-1.0 gstreamer-1.0

85
basic-tutorial-7.c Normal file
View File

@ -0,0 +1,85 @@
#include <gst/gst.h>
int main(int argc,char *argv[])
{
GstElement *pipeline,*audio_source,*tee,*audio_queue,*audio_convert,*audio_resample,*audio_sink;
GstElement *video_queue,*visual,*video_convert,*video_sink;
GstBus *bus;
GstMessage *msg;
GstPad *tee_audio_pad, *tee_video_pad;
GstPad *queue_audio_pad,*queue_video_pad;
GstPadTemplate *tee_audio_pad_template,*tee_video_pad_template;
gst_init(&argc,&argv);
audio_source = gst_element_factory_make("audiotestsrc","audio_source");
tee = gst_element_factory_make("tee","tee");
audio_queue = gst_element_factory_make("queue","audio_queue");
audio_convert = gst_element_factory_make("audioconvert","audio_convert");
audio_resample = gst_element_factory_make("audioresample","Audio_resample");
audio_sink = gst_element_factory_make("autoaudiosink","audio_sink");
video_queue = gst_element_factory_make("queue","vide_queue");
visual = gst_element_factory_make("wavescope","visual");
video_convert = gst_element_factory_make("videoconvert","csp");
video_sink = gst_element_factory_make("autovideosink","video_sink");
pipeline = gst_pipeline_new("test-pipeline");
if( !pipeline ||!audio_source || !tee|| !audio_queue || !audio_convert || !audio_resample || !audio_sink ||
!video_queue || !visual || !video_convert || !video_sink)
{
g_printerr("Not all elements could be created.\n");
return -1;
}
g_object_set(audio_source,"freq",215.0f,NULL);
g_object_set(visual,"shader",0,"style",1,NULL);
gst_bin_add_many(GST_BIN(pipeline),audio_source,tee,audio_queue,audio_convert,audio_resample,
audio_sink,video_queue,visual,video_convert,video_sink,NULL);
if(gst_element_link_many(audio_source,tee,NULL)!= TRUE ||
gst_element_link_many(audio_queue,audio_convert,audio_resample,audio_sink,NULL) != TRUE ||
gst_element_link_many(video_queue,visual,video_convert,video_sink,NULL) != TRUE )
{
g_printerr("Elements could not be linked.\n");
g_object_unref(pipeline);
return -1;
}
// tee_audio_pad_template = gst_element_class_get_pad_template(GST_ELEMENT_GET_CLASS(tee),"src%d");
tee_audio_pad = gst_element_get_request_pad(tee,"src_%u");
g_print("Obtained request pad %s for audio branch.\n",gst_pad_get_name(tee_audio_pad));
// tee_video_pad_template = gst_element_class_get_pad_template(GST_ELEMENT_CLASS(tee),"src%d");
queue_audio_pad = gst_element_get_static_pad(audio_queue,"sink");
tee_video_pad = gst_element_get_request_pad(tee,"src_%u");
g_print("Obtained request pad %s for video branch",gst_pad_get_name(tee_video_pad));
queue_video_pad = gst_element_get_static_pad(video_queue,"sink");
if(gst_pad_link(tee_audio_pad,queue_audio_pad) != GST_PAD_LINK_OK ||
gst_pad_link(tee_video_pad,queue_video_pad) != GST_PAD_LINK_OK)
{
g_printerr("Tee could not be linked!\n");
return -1;
}
gst_object_unref(queue_audio_pad);
gst_object_unref(queue_video_pad);
gst_element_set_state(pipeline,GST_STATE_PLAYING);
bus = gst_element_get_bus(pipeline);
msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE,GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
gst_element_release_request_pad(tee,tee_audio_pad);
gst_element_release_request_pad(tee,tee_video_pad);
gst_object_unref(tee_audio_pad);
gst_object_unref(tee_video_pad);
if(msg != NULL)
gst_message_unref(msg);
gst_object_unref(bus);
gst_element_set_state(pipeline,GST_STATE_NULL);
gst_object_unref(pipeline);
return 0;
}

View File

@ -123,32 +123,32 @@ BasicTutorial/fast:
$(MAKE) -f CMakeFiles/BasicTutorial.dir/build.make CMakeFiles/BasicTutorial.dir/build $(MAKE) -f CMakeFiles/BasicTutorial.dir/build.make CMakeFiles/BasicTutorial.dir/build
.PHONY : BasicTutorial/fast .PHONY : BasicTutorial/fast
basic-tutorial-6.o: basic-tutorial-6.c.o basic-tutorial-7.o: basic-tutorial-7.c.o
.PHONY : basic-tutorial-6.o .PHONY : basic-tutorial-7.o
# target to build an object file # target to build an object file
basic-tutorial-6.c.o: basic-tutorial-7.c.o:
$(MAKE) -f CMakeFiles/BasicTutorial.dir/build.make CMakeFiles/BasicTutorial.dir/basic-tutorial-6.c.o $(MAKE) -f CMakeFiles/BasicTutorial.dir/build.make CMakeFiles/BasicTutorial.dir/basic-tutorial-7.c.o
.PHONY : basic-tutorial-6.c.o .PHONY : basic-tutorial-7.c.o
basic-tutorial-6.i: basic-tutorial-6.c.i basic-tutorial-7.i: basic-tutorial-7.c.i
.PHONY : basic-tutorial-6.i .PHONY : basic-tutorial-7.i
# target to preprocess a source file # target to preprocess a source file
basic-tutorial-6.c.i: basic-tutorial-7.c.i:
$(MAKE) -f CMakeFiles/BasicTutorial.dir/build.make CMakeFiles/BasicTutorial.dir/basic-tutorial-6.c.i $(MAKE) -f CMakeFiles/BasicTutorial.dir/build.make CMakeFiles/BasicTutorial.dir/basic-tutorial-7.c.i
.PHONY : basic-tutorial-6.c.i .PHONY : basic-tutorial-7.c.i
basic-tutorial-6.s: basic-tutorial-6.c.s basic-tutorial-7.s: basic-tutorial-7.c.s
.PHONY : basic-tutorial-6.s .PHONY : basic-tutorial-7.s
# target to generate assembly for a file # target to generate assembly for a file
basic-tutorial-6.c.s: basic-tutorial-7.c.s:
$(MAKE) -f CMakeFiles/BasicTutorial.dir/build.make CMakeFiles/BasicTutorial.dir/basic-tutorial-6.c.s $(MAKE) -f CMakeFiles/BasicTutorial.dir/build.make CMakeFiles/BasicTutorial.dir/basic-tutorial-7.c.s
.PHONY : basic-tutorial-6.c.s .PHONY : basic-tutorial-7.c.s
# Help Target # Help Target
help: help:
@ -159,9 +159,9 @@ help:
@echo "... rebuild_cache" @echo "... rebuild_cache"
@echo "... edit_cache" @echo "... edit_cache"
@echo "... BasicTutorial" @echo "... BasicTutorial"
@echo "... basic-tutorial-6.o" @echo "... basic-tutorial-7.o"
@echo "... basic-tutorial-6.i" @echo "... basic-tutorial-7.i"
@echo "... basic-tutorial-6.s" @echo "... basic-tutorial-7.s"
.PHONY : help .PHONY : help