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 : #pragma once
27 :
28 : #include "lib/pid.h"
29 :
30 : //
31 : // Macros for declaring PID property handlers
32 : //
33 :
34 : #define GPAC_PROP_IMPL_DECL_CAPS(prop_nickname) \
35 : gboolean prop_nickname##_caps_handler(GPAC_PID_PROP_IMPL_ARGS);
36 :
37 : #define GPAC_PROP_IMPL_DECL_TAGS(prop_nickname) \
38 : gboolean prop_nickname##_tags_handler(GPAC_PID_PROP_IMPL_ARGS);
39 :
40 : #define GPAC_PROP_IMPL_DECL_SEGMENT(prop_nickname) \
41 : gboolean prop_nickname##_segment_handler(GPAC_PID_PROP_IMPL_ARGS);
42 :
43 : #define GPAC_PROP_IMPL_DECL_QUERY(prop_nickname) \
44 : gboolean prop_nickname##_query_handler(GPAC_PID_PROP_IMPL_ARGS);
45 :
46 : #define GPAC_PROP_IMPL_DECL_DEFAULT(prop_nickname) \
47 : gboolean prop_nickname##_default_handler(GPAC_PID_PROP_IMPL_ARGS_NO_ELEMENT);
48 :
49 : #define GPAC_PROP_IMPL_DECL_BUNDLE_ALL(prop_nickname) \
50 : GPAC_PROP_IMPL_DECL_CAPS(prop_nickname) \
51 : GPAC_PROP_IMPL_DECL_TAGS(prop_nickname) \
52 : GPAC_PROP_IMPL_DECL_SEGMENT(prop_nickname) \
53 : GPAC_PROP_IMPL_DECL_QUERY(prop_nickname) \
54 : GPAC_PROP_IMPL_DECL_DEFAULT(prop_nickname)
55 :
56 : #define GPAC_PROP_IMPL_DECL_BUNDLE_CAPS(prop_nickname) \
57 : GPAC_PROP_IMPL_DECL_CAPS(prop_nickname) \
58 : GPAC_PROP_IMPL_DECL_DEFAULT(prop_nickname)
59 :
60 : #define GPAC_PROP_IMPL_DECL_BUNDLE_TAGS(prop_nickname) \
61 : GPAC_PROP_IMPL_DECL_TAGS(prop_nickname) \
62 : GPAC_PROP_IMPL_DECL_DEFAULT(prop_nickname)
63 :
64 : #define GPAC_PROP_IMPL_DECL_BUNDLE_SEGMENT(prop_nickname) \
65 : GPAC_PROP_IMPL_DECL_SEGMENT(prop_nickname) \
66 : GPAC_PROP_IMPL_DECL_DEFAULT(prop_nickname)
67 :
68 : //
69 : // Macros for declaring PID property handlers
70 : //
71 :
72 : #define GPAC_PROP_DEFINE_ALL(prop_4cc, prop_nickname) \
73 : { prop_4cc, \
74 : prop_nickname##_caps_handler, \
75 : prop_nickname##_tags_handler, \
76 : prop_nickname##_segment_handler, \
77 : prop_nickname##_query_handler, \
78 : prop_nickname##_default_handler }
79 :
80 : #define GPAC_PROP_DEFINE_CAPS(prop_4cc, prop_nickname) \
81 : { prop_4cc, prop_nickname##_caps_handler, NULL, NULL, \
82 : NULL, prop_nickname##_default_handler }
83 :
84 : #define GPAC_PROP_DEFINE_TAGS(prop_4cc, prop_nickname) \
85 : { prop_4cc, NULL, prop_nickname##_tags_handler, \
86 : NULL, NULL, prop_nickname##_default_handler }
87 :
88 : #define GPAC_PROP_DEFINE_SEGMENT(prop_4cc, prop_nickname) \
89 : { prop_4cc, NULL, \
90 : NULL, prop_nickname##_segment_handler, \
91 : NULL, prop_nickname##_default_handler }
92 :
93 : #define GPAC_PROP_DEFINE_DEFAULT(prop_4cc, prop_nickname) \
94 : { prop_4cc, NULL, NULL, NULL, NULL, prop_nickname##_default_handler }
95 :
96 : /*!
97 : \brief PID Property Management and Reconfiguration
98 :
99 : The value of a PID property can be set through four sources:
100 : - Caps
101 : - Tags
102 : - Segment
103 : - Query
104 :
105 : If none of these sources set the property, the default handler is invoked. At
106 : least one of the sources must return `TRUE` for the property to be set.
107 :
108 : Properties can also be set using custom caps fields by prefixing the property
109 : name with `"gpac-"`. This approach is particularly useful for setting properties
110 : via tools like `gst-launch-1.0`. For a more structured approach, a nested
111 : structure with `"gpac"` as the field name can be used. These custom fields will
112 : override properties that would otherwise be set by GStreamer.
113 :
114 : Property handlers have access to private data for each pad, which can be used to
115 : store state information. Since the element's lock is acquired, the private data
116 : can be safely modified, and the global context can also be utilized if required
117 : by any property handler.
118 :
119 : For example, the `id` property must remain consistent across subsequent calls
120 : and must increment monotonically across all pads. This behavior is achieved by
121 : storing the last `id` in a global context.
122 : */
123 :
124 : //
125 : // PID property handler declarations
126 : //
127 : GPAC_PROP_IMPL_DECL_BUNDLE_CAPS(stream_type)
128 : GPAC_PROP_IMPL_DECL_BUNDLE_TAGS(id)
129 : GPAC_PROP_IMPL_DECL_BUNDLE_CAPS(codec_id)
130 : GPAC_PROP_IMPL_DECL_BUNDLE_CAPS(unframed)
131 :
132 : GPAC_PROP_IMPL_DECL_BUNDLE_CAPS(width)
133 : GPAC_PROP_IMPL_DECL_BUNDLE_CAPS(height)
134 :
135 : GPAC_PROP_IMPL_DECL_BUNDLE_TAGS(dbsize)
136 : GPAC_PROP_IMPL_DECL_BUNDLE_TAGS(bitrate)
137 : GPAC_PROP_IMPL_DECL_BUNDLE_TAGS(max_bitrate)
138 :
139 : GPAC_PROP_IMPL_DECL_BUNDLE_ALL(duration)
140 : GPAC_PROP_IMPL_DECL_BUNDLE_CAPS(timescale)
141 : GPAC_PROP_IMPL_DECL_BUNDLE_CAPS(sample_rate)
142 : GPAC_PROP_IMPL_DECL_BUNDLE_CAPS(fps)
143 :
144 : GPAC_PROP_IMPL_DECL_BUNDLE_CAPS(num_channels)
145 : GPAC_PROP_IMPL_DECL_BUNDLE_TAGS(language)
146 :
147 : GPAC_PROP_IMPL_DECL_BUNDLE_CAPS(decoder_config)
148 :
149 : typedef struct
150 : {
151 : u32 prop_4cc;
152 :
153 : // Handlers
154 : gboolean (*caps_handler)(GPAC_PID_PROP_IMPL_ARGS);
155 : gboolean (*tags_handler)(GPAC_PID_PROP_IMPL_ARGS);
156 : gboolean (*segment_handler)(GPAC_PID_PROP_IMPL_ARGS);
157 : gboolean (*query_handler)(GPAC_PID_PROP_IMPL_ARGS);
158 :
159 : // Default fallback handler
160 : gboolean (*default_handler)(GPAC_PID_PROP_IMPL_ARGS_NO_ELEMENT);
161 : } prop_registry_entry;
162 :
163 : static prop_registry_entry prop_registry[] = {
164 : GPAC_PROP_DEFINE_CAPS(GF_PROP_PID_STREAM_TYPE, stream_type),
165 : GPAC_PROP_DEFINE_TAGS(GF_PROP_PID_ID, id),
166 : GPAC_PROP_DEFINE_CAPS(GF_PROP_PID_CODECID, codec_id),
167 : GPAC_PROP_DEFINE_CAPS(GF_PROP_PID_UNFRAMED, unframed),
168 :
169 : GPAC_PROP_DEFINE_CAPS(GF_PROP_PID_WIDTH, width),
170 : GPAC_PROP_DEFINE_CAPS(GF_PROP_PID_HEIGHT, height),
171 :
172 : GPAC_PROP_DEFINE_TAGS(GF_PROP_PID_DBSIZE, dbsize),
173 : GPAC_PROP_DEFINE_TAGS(GF_PROP_PID_BITRATE, bitrate),
174 : GPAC_PROP_DEFINE_TAGS(GF_PROP_PID_MAXRATE, max_bitrate),
175 :
176 : // DO NOT change the order of the next 4 properties
177 : GPAC_PROP_DEFINE_CAPS(GF_PROP_PID_SAMPLE_RATE, sample_rate),
178 : GPAC_PROP_DEFINE_CAPS(GF_PROP_PID_FPS, fps),
179 : GPAC_PROP_DEFINE_CAPS(GF_PROP_PID_TIMESCALE, timescale),
180 : GPAC_PROP_DEFINE_ALL(GF_PROP_PID_DURATION, duration),
181 :
182 : GPAC_PROP_DEFINE_CAPS(GF_PROP_PID_NUM_CHANNELS, num_channels),
183 : GPAC_PROP_DEFINE_TAGS(GF_PROP_PID_LANGUAGE, language),
184 :
185 : GPAC_PROP_DEFINE_CAPS(GF_PROP_PID_DECODER_CONFIG, decoder_config),
186 : };
187 :
188 : u32
189 357 : gpac_pid_get_num_supported_props()
190 : {
191 357 : return G_N_ELEMENTS(prop_registry);
192 : }
|