Commit 87e3828
refactor: formalize C ABI codec registry via as_c_name/from_c_name (#265)
* refactor: formalize C ABI codec registry via as_c_name/from_c_name
Centralizes codec name ↔ enum conversion in AudioCodec and VideoCodec,
eliminating hardcoded string matching duplicated across 6 locations in the
plugin SDK (conversions.rs, processor macro, source macro × input/output).
Key changes:
- Add AudioCodec::as_c_name()/from_c_name() and VideoCodec equivalents
as the single source of truth for C ABI codec name strings.
- Fix EncodedVideo to carry codec info via custom_type_id (same pattern
as EncodedAudio). Previously mapped to PacketType::Binary with a TODO.
Null custom_type_id falls back to Binary for backward compat.
- Replace 4 duplicated match blocks in native_plugin_entry! and
native_source_plugin_entry! macros with as_c_name() calls.
- Add EncodedVideo custom_type_id handling to both macros.
- Document the codec extensibility pattern in CPacketTypeInfo.
- Add roundtrip tests for all codec name conversions and C ABI encoding.
Adding a new codec now requires only two changes:
1. Add the variant to AudioCodec/VideoCodec
2. Add its name in as_c_name() and from_c_name()
No API version bump needed — CPacketTypeInfo struct layout unchanged.
BREAKING CHANGE: EncodedVideo pin declarations now carry codec info
via custom_type_id instead of mapping to Binary.
Signed-off-by: StreamKit Devin <devin@streamkit.dev>
Co-Authored-By: Claudio Costa <cstcld91@gmail.com>
* refactor: use CPacketTypeOwned::CodecName to eliminate duplicated codec strings
Add CodecName(CString) variant to CPacketTypeOwned and a
codec_name_to_cstring() helper so packet_type_to_c derives its
null-terminated codec names from as_c_name() instead of maintaining
parallel hardcoded byte literals.
This makes the doc comment claim true: as_c_name()/from_c_name() are
now genuinely the only places codec-name strings live.
Signed-off-by: StreamKit Devin <devin@streamkit.dev>
Co-Authored-By: Claudio Costa <cstcld91@gmail.com>
* fix: address review feedback on C ABI codec registry
- codec_name_to_cstring: use expect() instead of unwrap_or_default()
to fail fast on programmer errors (matches lib.rs macro pattern)
- Add tracing::warn! when EncodedVideo null custom_type_id falls back
to Binary (aids debugging of new plugins vs backward compat)
- Simplify map_err to forward original from_c_name() error messages
- Add doc comments clarifying intentional field loss (bitstream_format,
codec_private, profile, level) through C ABI pin-type declarations
Signed-off-by: StreamKit Devin <devin@streamkit.dev>
Co-Authored-By: Claudio Costa <cstcld91@gmail.com>
* fix: address review feedback on C ABI codec registry
- codec_name_to_cstring: use expect() instead of unwrap_or_default()
to fail fast on programmer errors (matches lib.rs macro pattern)
- Add tracing::warn! when EncodedVideo null custom_type_id falls back
to Binary (aids debugging of new plugins vs backward compat)
- Simplify map_err to forward original from_c_name() error messages
- Add doc comments clarifying intentional field loss (bitstream_format,
codec_private, profile, level) through C ABI pin-type declarations
Signed-off-by: StreamKit Devin <devin@streamkit.dev>
Co-Authored-By: Claudio Costa <cstcld91@gmail.com>
* fix: address second round of review feedback on C ABI codec registry
- Make from_c_name strict (canonical lowercase only): remove 'avc'/'avc1'
aliases from VideoCodec::from_c_name — serde aliases are for config
deserialization, C ABI is a controlled interface with canonical names
- Add tracing::warn! for EncodedAudio null custom_type_id fallback to
Opus (matching the EncodedVideo pattern)
- Make codec_name_to_cstring pub and replace 8 inline CString::new()
.expect() sites in lib.rs macros — fully centralizes CString
construction for codec names
- Fix EncodedAudio doc comment: audio_codec -> custom_type_id
- Replace alias roundtrip test with strict-mode rejection test
Signed-off-by: StreamKit Devin <devin@streamkit.dev>
Co-Authored-By: Claudio Costa <cstcld91@gmail.com>
* style: apply rustfmt to macro codec_name_to_cstring calls
Signed-off-by: StreamKit Devin <devin@streamkit.dev>
Co-Authored-By: Claudio Costa <cstcld91@gmail.com>
* docs: add Panics section to codec_name_to_cstring doc comment
Signed-off-by: StreamKit Devin <devin@streamkit.dev>
Co-Authored-By: Claudio Costa <cstcld91@gmail.com>
---------
Signed-off-by: StreamKit Devin <devin@streamkit.dev>
Co-authored-by: StreamKit Devin <devin@streamkit.dev>
Co-authored-by: Claudio Costa <cstcld91@gmail.com>1 parent f28ab86 commit 87e3828
File tree
4 files changed
+292
-73
lines changed- crates/core/src
- sdks/plugin-sdk/native/src
4 files changed
+292
-73
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
84 | 107 | | |
85 | 108 | | |
86 | 109 | | |
| |||
99 | 122 | | |
100 | 123 | | |
101 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
102 | 152 | | |
103 | 153 | | |
104 | 154 | | |
| |||
897 | 947 | | |
898 | 948 | | |
899 | 949 | | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
900 | 990 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | | - | |
| 21 | + | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
71 | 90 | | |
72 | 91 | | |
73 | 92 | | |
74 | 93 | | |
75 | 94 | | |
76 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
77 | 100 | | |
78 | 101 | | |
79 | 102 | | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
| 103 | + | |
85 | 104 | | |
| 105 | + | |
| 106 | + | |
86 | 107 | | |
87 | 108 | | |
88 | 109 | | |
| |||
169 | 190 | | |
170 | 191 | | |
171 | 192 | | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
172 | 208 | | |
173 | 209 | | |
174 | 210 | | |
| |||
179 | 215 | | |
180 | 216 | | |
181 | 217 | | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
182 | 222 | | |
183 | 223 | | |
184 | 224 | | |
| |||
224 | 264 | | |
225 | 265 | | |
226 | 266 | | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
234 | 271 | | |
235 | 272 | | |
236 | 273 | | |
237 | 274 | | |
238 | | - | |
| 275 | + | |
239 | 276 | | |
240 | 277 | | |
241 | | - | |
| 278 | + | |
242 | 279 | | |
243 | 280 | | |
244 | 281 | | |
| |||
282 | 319 | | |
283 | 320 | | |
284 | 321 | | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
294 | 337 | | |
295 | 338 | | |
296 | 339 | | |
| |||
990 | 1033 | | |
991 | 1034 | | |
992 | 1035 | | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
993 | 1116 | | |
0 commit comments