feat: add the video sink to the tutorial-3
parent
de7f25c417
commit
905ac7fb1e
|
@ -4,15 +4,17 @@
|
|||
{
|
||||
"label": "CMake",
|
||||
"detail": "Produce MakeFile",
|
||||
"command":[
|
||||
"command": [
|
||||
"cmake"
|
||||
],
|
||||
"type": "shell",
|
||||
"args": [".."],
|
||||
"args": [
|
||||
".."
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}/build",
|
||||
"cwd": "${workspaceFolder}/build"
|
||||
},
|
||||
"group": "build",
|
||||
"group": "build"
|
||||
},
|
||||
{
|
||||
"label": "Build",
|
||||
|
@ -27,7 +29,7 @@
|
|||
"reveal": "always"
|
||||
},
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}/build",
|
||||
"cwd": "${workspaceFolder}/build"
|
||||
},
|
||||
"group": "build"
|
||||
},
|
||||
|
@ -38,15 +40,15 @@
|
|||
"type": "shell",
|
||||
"group": "build",
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}/build",
|
||||
"cwd": "${workspaceFolder}/build"
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "Build & Run",
|
||||
"detail": "Build program and run it",
|
||||
"dependsOn":[
|
||||
"dependsOn": [
|
||||
"Build",
|
||||
"Run",
|
||||
"Run"
|
||||
],
|
||||
"dependsOrder": "sequence",
|
||||
"group": "build"
|
||||
|
|
|
@ -7,7 +7,8 @@ typedef struct _CustomData
|
|||
GstElement *source;
|
||||
GstElement *convert;
|
||||
GstElement *resample;
|
||||
GstElement *sink;
|
||||
GstElement *audio_sink;
|
||||
GstElement *video_sink;
|
||||
} CustomData;
|
||||
|
||||
static void pad_added_handler(GstElement *src, GstPad *new_pad,CustomData *data);
|
||||
|
@ -25,25 +26,27 @@ int main(int argc, char *argv[])
|
|||
data.source = gst_element_factory_make("uridecodebin","source");
|
||||
data.convert = gst_element_factory_make("audioconvert","convert");
|
||||
data.resample = gst_element_factory_make("audioresample","resample");
|
||||
data.sink = gst_element_factory_make("autoaudiosink","sink");
|
||||
data.audio_sink = gst_element_factory_make("autoaudiosink","audio_sink");
|
||||
data.video_sink = gst_element_factory_make("autovideosink","video_sink");
|
||||
|
||||
data.pipeline = gst_pipeline_new("test-pipeline");
|
||||
|
||||
if(!data.pipeline|| !data.source || !data.convert || !data.resample || ! data.sink)
|
||||
if(!data.pipeline|| !data.source || !data.convert || !data.resample || ! data.audio_sink || !data.video_sink)
|
||||
{
|
||||
g_printerr("Not all elements could be created.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
gst_bin_add_many(GST_BIN(data.pipeline),data.source,data.convert,data.resample,data.sink,NULL);
|
||||
if(!gst_element_link_many(data.convert,data.resample,data.sink,NULL))
|
||||
gst_bin_add_many(GST_BIN(data.pipeline),data.source,data.convert,data.resample,data.audio_sink,data.video_sink,NULL);
|
||||
if(!gst_element_link_many(data.convert,data.resample,data.audio_sink,NULL))
|
||||
{
|
||||
g_printerr("Elements could not be linked.\n");
|
||||
gst_object_unref(data.pipeline);
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_object_set(data.source,"uri","https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm",NULL);
|
||||
// g_object_set(data.source,"uri","https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm",NULL);
|
||||
g_object_set(data.source,"uri","https://media.w3.org/2010/05/sintel/trailer.mp4",NULL);
|
||||
|
||||
g_signal_connect(data.source,"pad-added",G_CALLBACK(pad_added_handler),&data);
|
||||
|
||||
|
@ -103,7 +106,8 @@ int main(int argc, char *argv[])
|
|||
|
||||
static void pad_added_handler(GstElement *src, GstPad *new_pad,CustomData *data)
|
||||
{
|
||||
GstPad *sink_pad = gst_element_get_static_pad(data->convert,"sink");
|
||||
GstPad *audio_sink_pad = gst_element_get_static_pad(data->convert,"sink");
|
||||
GstPad *video_sink_pad = gst_element_get_static_pad(data->video_sink,"sink");
|
||||
GstPadLinkReturn ret;
|
||||
GstCaps *new_pad_caps = NULL;
|
||||
GstStructure *new_pad_struct = NULL;
|
||||
|
@ -111,7 +115,7 @@ static void pad_added_handler(GstElement *src, GstPad *new_pad,CustomData *data)
|
|||
|
||||
g_print("Received new pad '%s' from '%s':\n",GST_PAD_NAME(new_pad),GST_ELEMENT_NAME(src));
|
||||
|
||||
if(gst_pad_is_linked(sink_pad))
|
||||
if(gst_pad_is_linked(audio_sink_pad))// && gst_pad_is_linked(video_sink_pad))
|
||||
{
|
||||
g_print("We are already linked. Ignoring.\n");
|
||||
goto exit;
|
||||
|
@ -120,20 +124,35 @@ static void pad_added_handler(GstElement *src, GstPad *new_pad,CustomData *data)
|
|||
new_pad_caps = gst_pad_get_current_caps(new_pad);
|
||||
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"))
|
||||
if(g_str_has_prefix(new_pad_type,"audio/x-raw"))
|
||||
{
|
||||
g_print("It has type '%s' which is not raw audio. Ignoring.\n",new_pad_type);
|
||||
goto exit;
|
||||
ret = gst_pad_link(new_pad,audio_sink_pad);
|
||||
if(GST_PAD_LINK_FAILED(ret))
|
||||
{
|
||||
g_print("Type is %s but link failed.\n",new_pad_type);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_print("Link succeeded (type %s).\n",new_pad_type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ret = gst_pad_link(new_pad,sink_pad);
|
||||
if(GST_PAD_LINK_FAILED(ret))
|
||||
else if(g_str_has_prefix(new_pad_type,"video/x-raw"))
|
||||
{
|
||||
g_print("Type is %s but link failed.\n",new_pad_type);
|
||||
ret = gst_pad_link(new_pad,video_sink_pad);
|
||||
if(GST_PAD_LINK_FAILED(ret))
|
||||
{
|
||||
g_print("Type is %s but link failed.\n",new_pad_type);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_print("Link succeeded (type %s).\n",new_pad_type);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g_print("Link succeeded (type %s).\n",new_pad_type);
|
||||
g_print("It has type '%s' which is not raw audio. Ignoring.\n",new_pad_type);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -141,6 +160,6 @@ static void pad_added_handler(GstElement *src, GstPad *new_pad,CustomData *data)
|
|||
{
|
||||
gst_caps_unref(new_pad_caps);
|
||||
}
|
||||
gst_object_unref(sink_pad);
|
||||
gst_object_unref(audio_sink_pad);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue