basic-tutorial-3: Use gst_pad_get_current_caps() instead of gst_pad_query_caps()

We're interested in the currently negotiated caps, not all the caps the
pad can potentially output. Also update the text accordingly.
This commit is contained in:
Sebastian Dröge 2017-09-14 13:38:22 +03:00
parent dbf7d255dc
commit 020bf14d03
2 changed files with 11 additions and 7 deletions

View file

@ -123,7 +123,7 @@ static void pad_added_handler (GstElement *src, GstPad *new_pad, CustomData *dat
}
/* Check the new pad's type */
new_pad_caps = gst_pad_query_caps (new_pad, NULL);
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")) {

View file

@ -211,7 +211,7 @@ static void pad_added_handler (GstElement *src, GstPad *new_pad, CustomData *dat
}
/* Check the new pad's type */
new_pad_caps = gst_pad_query_caps (new_pad, NULL);
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")) {
@ -390,7 +390,7 @@ trying to link to a new pad once we are already linked.
``` c
/* Check the new pad's type */
new_pad_caps = gst_pad_query_caps (new_pad, NULL);
new_pad_caps = gst_pad_get_current_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")) {
@ -405,10 +405,14 @@ previously created a piece of pipeline which deals with audio (an
`audioconvert` linked with an `autoaudiosink`), and we will not be able
to link it to a pad producing video, for example.
`gst_pad_query_caps()` retrieves the *capabilities* of the pad (this is,
the kind of data it supports), wrapped in a `GstCaps` structure. A pad
can offer many capabilities, and hence `GstCaps` can contain many
`GstStructure`, each representing a different capability.
`gst_pad_get_current_caps()` retrieves the current *capabilities* of the pad
(that is, the kind of data it currently outputs), wrapped in a `GstCaps`
structure. All possible caps a pad can support can be queried with
`gst_pad_query_caps()`. A pad can offer many capabilities, and hence `GstCaps`
can contain many `GstStructure`, each representing a different capability. The
current caps on a pad will always have a single `GstStructure` and represent a
single media format, or if there are no current caps yet `NULL` will be
returned.
Since, in this case, we know that the pad we want only had one
capability (audio), we retrieve the first `GstStructure` with