Line data Source code
1 : /*
2 : * GPAC - Multimedia Framework C SDK
3 : *
4 : * Authors: Deniz Ugur, Romain Bouqueau, Sohaib Larbi
5 : * Copyright (c) Motion Spell
6 : * All rights reserved
7 : *
8 : * This file is part of the GPAC/GStreamer wrapper
9 : *
10 : * This GPAC/GStreamer wrapper is free software; you can redistribute it
11 : * and/or modify it under the terms of the GNU Affero General Public License
12 : * as published by the Free Software Foundation; either version 3, or (at
13 : * your option) any later version.
14 : *
15 : * This GPAC/GStreamer wrapper is distributed in the hope that it will be
16 : * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
17 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 : * GNU Affero General Public License for more details.
19 : *
20 : * You should have received a copy of the GNU Affero General Public
21 : * License along with this library; see the file LICENSE. If not, write to
22 : * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23 : *
24 : */
25 :
26 : #include "lib/caps.h"
27 :
28 : GstGpacFormatProp gst_gpac_sink_formats = {
29 : .video_caps = GST_STATIC_CAPS(AV1_CAPS "; " H264_CAPS "; " H265_CAPS),
30 : .audio_caps = GST_STATIC_CAPS(AAC_CAPS "; " EAC3_CAPS),
31 : .subtitle_caps = GST_STATIC_CAPS(TEXT_UTF8),
32 : };
33 :
34 : GstPadTemplate* sink_templates[4] = { NULL };
35 :
36 : GstPadTemplate*
37 13071 : gst_gpac_get_sink_template(GstGpacSinkTemplateType type)
38 : {
39 13071 : return sink_templates[type];
40 : }
41 :
42 : void
43 4 : gpac_install_sink_pad_templates(GstElementClass* klass)
44 : {
45 : // Video pad template
46 4 : if (sink_templates[GPAC_TEMPLATE_VIDEO] == NULL) {
47 2 : sink_templates[GPAC_TEMPLATE_VIDEO] = gst_pad_template_new(
48 : "video_%u",
49 : GST_PAD_SINK,
50 : GST_PAD_REQUEST,
51 : gst_static_caps_get(&gst_gpac_sink_formats.video_caps));
52 : }
53 4 : gst_element_class_add_pad_template(klass,
54 : sink_templates[GPAC_TEMPLATE_VIDEO]);
55 :
56 : // Audio pad template
57 4 : if (sink_templates[GPAC_TEMPLATE_AUDIO] == NULL) {
58 2 : sink_templates[GPAC_TEMPLATE_AUDIO] = gst_pad_template_new(
59 : "audio_%u",
60 : GST_PAD_SINK,
61 : GST_PAD_REQUEST,
62 : gst_static_caps_get(&gst_gpac_sink_formats.audio_caps));
63 : }
64 4 : gst_element_class_add_pad_template(klass,
65 : sink_templates[GPAC_TEMPLATE_AUDIO]);
66 :
67 : // Subtitle pad template
68 4 : if (sink_templates[GPAC_TEMPLATE_SUBTITLE] == NULL) {
69 2 : sink_templates[GPAC_TEMPLATE_SUBTITLE] = gst_pad_template_new(
70 : "subtitle_%u",
71 : GST_PAD_SINK,
72 : GST_PAD_REQUEST,
73 : gst_static_caps_get(&gst_gpac_sink_formats.subtitle_caps));
74 : }
75 4 : gst_element_class_add_pad_template(klass,
76 : sink_templates[GPAC_TEMPLATE_SUBTITLE]);
77 4 : }
78 :
79 : GstStaticPadTemplate gst_gpac_src_template =
80 : GST_STATIC_PAD_TEMPLATE("src",
81 : GST_PAD_SRC,
82 : GST_PAD_ALWAYS,
83 : GST_STATIC_CAPS(QT_CAPS "; " MPEG_TS_CAPS));
84 :
85 : void
86 4 : gpac_install_src_pad_templates(GstElementClass* klass)
87 : {
88 4 : gst_element_class_add_static_pad_template(klass, &gst_gpac_src_template);
89 4 : }
90 :
91 : GF_FilterCapability*
92 9 : gpac_gstcaps_to_gfcaps(GstCaps* caps, guint* nb_caps)
93 : {
94 9 : if (!caps)
95 0 : return NULL;
96 :
97 : // Get the structure from the caps
98 9 : if (gst_caps_get_size(caps) == 0) {
99 0 : GST_ERROR("No structure in caps");
100 0 : return NULL;
101 : }
102 9 : if (gst_caps_get_size(caps) > 1)
103 0 : GST_WARNING("Multiple structures in caps, will only use the first one");
104 9 : GstStructure* structure = gst_caps_get_structure(caps, 0);
105 :
106 : /**
107 : * Currently, we only support file output stream. Therefore, we only need to
108 : * set MIME type and stream type.
109 : */
110 :
111 : // Allocate the capabilities
112 9 : *nb_caps = 2;
113 9 : GF_FilterCapability* gf_caps = g_new0(GF_FilterCapability, *nb_caps);
114 9 : if (!gf_caps)
115 0 : return NULL;
116 :
117 : // Set the stream type
118 9 : gf_caps[0].code = GF_PROP_PID_STREAM_TYPE;
119 9 : gf_caps[0].val.type = GF_PROP_UINT;
120 9 : gf_caps[0].val.value.uint = GF_STREAM_FILE;
121 9 : gf_caps[0].flags = GF_CAPS_INPUT;
122 :
123 : // Set the mime type
124 9 : gf_caps[1].code = GF_PROP_PID_MIME;
125 9 : gf_caps[1].val.type = GF_PROP_STRING;
126 9 : gf_caps[1].val.value.string = g_strdup(gst_structure_get_name(structure));
127 9 : gf_caps[1].flags = GF_CAPS_INPUT;
128 :
129 9 : return gf_caps;
130 : }
|