Skip to content

Commit 16f4b71

Browse files
committed
core: Gate experimental subtitle and video codec support.
Gate subtitle and video codec decoder traits behind experimental feature flags as these will not be fully or correctly defined for v0.6.0.
1 parent 2846716 commit 16f4b71

8 files changed

Lines changed: 70 additions & 1 deletion

File tree

symphonia-core/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ opt-simd = [
2727
"opt-simd-neon",
2828
]
2929

30+
# Experimental features.
31+
exp-subtitle-codecs = []
32+
exp-video-codecs = []
33+
3034
[dependencies]
3135
bitflags = "2.4.2"
3236
bytemuck = "1.7"

symphonia-core/src/codecs/registry.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ use std::default::Default;
1212
use std::hash::Hash;
1313

1414
use crate::codecs::audio::{AudioCodecId, AudioCodecParameters, AudioDecoder, AudioDecoderOptions};
15+
#[cfg(feature = "exp-subtitle-codecs")]
1516
use crate::codecs::subtitle::{
1617
SubtitleCodecId, SubtitleCodecParameters, SubtitleDecoder, SubtitleDecoderOptions,
1718
};
19+
#[cfg(feature = "exp-video-codecs")]
1820
use crate::codecs::video::{VideoCodecId, VideoCodecParameters, VideoDecoder, VideoDecoderOptions};
1921
use crate::codecs::CodecInfo;
2022
use crate::common::Tier;
@@ -42,6 +44,7 @@ pub trait RegisterableAudioDecoder: AudioDecoder {
4244
}
4345

4446
/// Description of a supported video codec.
47+
#[cfg(feature = "exp-video-codecs")]
4548
#[derive(Copy, Clone)]
4649
pub struct SupportedVideoCodec {
4750
pub codec: VideoCodecId,
@@ -50,6 +53,7 @@ pub struct SupportedVideoCodec {
5053

5154
/// To support registration in a codec registry, a `VideoDecoder` must implement the
5255
/// `RegisterableVideoDecoder` trait.
56+
#[cfg(feature = "exp-video-codecs")]
5357
pub trait RegisterableVideoDecoder: VideoDecoder {
5458
fn try_registry_new(
5559
params: &VideoCodecParameters,
@@ -63,6 +67,7 @@ pub trait RegisterableVideoDecoder: VideoDecoder {
6367
}
6468

6569
/// Description of a supported subtitle codec.
70+
#[cfg(feature = "exp-subtitle-codecs")]
6671
#[derive(Copy, Clone)]
6772
pub struct SupportedSubtitleCodec {
6873
pub codec: SubtitleCodecId,
@@ -71,6 +76,7 @@ pub struct SupportedSubtitleCodec {
7176

7277
/// To support registration in a codec registry, a `SubtitleDecoder` must implement the
7378
/// `RegisterableSubtitleDecoder` trait.
79+
#[cfg(feature = "exp-subtitle-codecs")]
7480
pub trait RegisterableSubtitleDecoded: SubtitleDecoder {
7581
fn try_registry_new(
7682
params: &SubtitleCodecParameters,
@@ -88,10 +94,12 @@ pub type AudioDecoderFactoryFn =
8894
fn(&AudioCodecParameters, &AudioDecoderOptions) -> Result<Box<dyn AudioDecoder>>;
8995

9096
/// `VideoDecoder` factory function. Creates a boxed `VideoDecoder`.
97+
#[cfg(feature = "exp-video-codecs")]
9198
pub type VideoDecoderFactoryFn =
9299
fn(&VideoCodecParameters, &VideoDecoderOptions) -> Result<Box<dyn VideoDecoder>>;
93100

94101
/// `SubtitleDecoder` factory function. Creates a boxed `SubtitleDecoder`.
102+
#[cfg(feature = "exp-subtitle-codecs")]
95103
pub type SubtitleDecoderFactoryFn =
96104
fn(&SubtitleCodecParameters, &SubtitleDecoderOptions) -> Result<Box<dyn SubtitleDecoder>>;
97105

@@ -104,6 +112,7 @@ pub struct RegisteredAudioDecoder {
104112
}
105113

106114
/// Registration details of a video decoder for a particular video codec.
115+
#[cfg(feature = "exp-video-codecs")]
107116
pub struct RegisteredVideoDecoder {
108117
/// Video codec details.
109118
pub codec: SupportedVideoCodec,
@@ -112,6 +121,7 @@ pub struct RegisteredVideoDecoder {
112121
}
113122

114123
/// Registration details of a subtitle decoder for a particular subtitle codec.
124+
#[cfg(feature = "exp-subtitle-codecs")]
115125
pub struct RegisteredSubtitleDecoder {
116126
/// Subtitle codec details.
117127
pub codec: SupportedSubtitleCodec,
@@ -165,7 +175,9 @@ where
165175
#[derive(Default)]
166176
pub struct CodecRegistry {
167177
audio: InnerCodecRegistry<AudioCodecId, RegisteredAudioDecoder>,
178+
#[cfg(feature = "exp-video-codecs")]
168179
video: InnerCodecRegistry<VideoCodecId, RegisteredVideoDecoder>,
180+
#[cfg(feature = "exp-subtitle-codecs")]
169181
subtitle: InnerCodecRegistry<SubtitleCodecId, RegisteredSubtitleDecoder>,
170182
}
171183

@@ -174,7 +186,9 @@ impl CodecRegistry {
174186
pub fn new() -> Self {
175187
CodecRegistry {
176188
audio: Default::default(),
189+
#[cfg(feature = "exp-video-codecs")]
177190
video: Default::default(),
191+
#[cfg(feature = "exp-subtitle-codecs")]
178192
subtitle: Default::default(),
179193
}
180194
}
@@ -197,12 +211,14 @@ impl CodecRegistry {
197211

198212
/// Get the registration information of the most preferred video decoder for the specified
199213
/// video codec.
214+
#[cfg(feature = "exp-video-codecs")]
200215
pub fn get_video_decoder(&self, id: VideoCodecId) -> Option<&RegisteredVideoDecoder> {
201216
self.video.get(&id)
202217
}
203218

204219
/// Get the registration information of the video decoder at the specified tier for the
205220
/// specified video codec.
221+
#[cfg(feature = "exp-video-codecs")]
206222
pub fn get_video_decoder_at_tier(
207223
&self,
208224
tier: Tier,
@@ -213,12 +229,14 @@ impl CodecRegistry {
213229

214230
/// Get the registration information of the most preferred subtitle decoder for the specified
215231
/// subtitle codec.
232+
#[cfg(feature = "exp-subtitle-codecs")]
216233
pub fn get_subtitle_decoder(&self, id: SubtitleCodecId) -> Option<&RegisteredSubtitleDecoder> {
217234
self.subtitle.get(&id)
218235
}
219236

220237
/// Get the registration information of the subtitle decoder at the specified tier for the
221238
/// specified subtitle codec.
239+
#[cfg(feature = "exp-subtitle-codecs")]
222240
pub fn get_subtitle_decoder_at_tier(
223241
&self,
224242
tier: Tier,
@@ -254,6 +272,7 @@ impl CodecRegistry {
254272
///
255273
/// If a supported video codec was previously registered by another video decoder at the same
256274
/// tier, it will be replaced within the registry.
275+
#[cfg(feature = "exp-video-codecs")]
257276
pub fn register_video_decoder<C: RegisterableVideoDecoder>(&mut self) {
258277
self.register_video_decoder_at_tier::<C>(Tier::Standard);
259278
}
@@ -262,6 +281,7 @@ impl CodecRegistry {
262281
///
263282
/// If a supported codec was previously registered by another video decoder at the same tier, it
264283
/// will be replaced within the registry.
284+
#[cfg(feature = "exp-video-codecs")]
265285
pub fn register_video_decoder_at_tier<C: RegisterableVideoDecoder>(&mut self, tier: Tier) {
266286
for codec in C::supported_codecs() {
267287
let reg = RegisteredVideoDecoder {
@@ -277,6 +297,7 @@ impl CodecRegistry {
277297
///
278298
/// If a supported subtitle codec was previously registered by another subtitle decoder at the
279299
/// same tier, it will be replaced within the registry.
300+
#[cfg(feature = "exp-subtitle-codecs")]
280301
pub fn register_subtitle_decoder<C: RegisterableSubtitleDecoded>(&mut self) {
281302
self.register_subtitle_decoder_at_tier::<C>(Tier::Standard);
282303
}
@@ -285,6 +306,7 @@ impl CodecRegistry {
285306
///
286307
/// If a supported codec was previously registered by another subtitle decoder at the same tier,
287308
/// it will be replaced within the registry.
309+
#[cfg(feature = "exp-subtitle-codecs")]
288310
pub fn register_subtitle_decoder_at_tier<C: RegisterableSubtitleDecoded>(
289311
&mut self,
290312
tier: Tier,
@@ -324,6 +346,7 @@ impl CodecRegistry {
324346
/// found, it will be instantiated with the provided video codec parameters and video decoder
325347
/// options. If a suitable decoder could not be found, or the decoder could not be instantiated,
326348
/// an error will be returned.
349+
#[cfg(feature = "exp-video-codecs")]
327350
pub fn make_video_decoder(
328351
&self,
329352
params: &VideoCodecParameters,
@@ -343,6 +366,7 @@ impl CodecRegistry {
343366
/// is found, it will be instantiated with the provided subtitle codec parameters and subtitle
344367
/// decoder options. If a suitable decoder could not be found, or the decoder could not be
345368
/// instantiated, an error will be returned.
369+
#[cfg(feature = "exp-subtitle-codecs")]
346370
pub fn make_subtitle_decoder(
347371
&self,
348372
params: &SubtitleCodecParameters,

symphonia-core/src/codecs/subtitle.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
1010
use std::fmt;
1111

12+
#[cfg(feature = "exp-subtitle-codecs")]
1213
use crate::codecs::CodecInfo;
1314
use crate::common::FourCc;
15+
#[cfg(feature = "exp-subtitle-codecs")]
1416
use crate::errors::Result;
17+
#[cfg(feature = "exp-subtitle-codecs")]
1518
use crate::formats::Packet;
19+
#[cfg(feature = "exp-subtitle-codecs")]
1620
use crate::subtitle::GenericSubtitleBufferRef;
1721

1822
/// An `SubtitleCodecId` is a unique identifier used to identify a specific video codec.
@@ -84,13 +88,15 @@ impl SubtitleCodecParameters {
8488
}
8589

8690
/// `SubtitleDecoderOptions` is a common set of options that all subtitle decoders use.
91+
#[cfg(feature = "exp-subtitle-codecs")]
8792
#[derive(Copy, Clone, Debug, Default)]
8893
pub struct SubtitleDecoderOptions {
8994
// None yet.
9095
}
9196

9297
/// A `SubtitleDecoder` implements a subtitle codec's decode algorithm. It consumes `Packet`s and
9398
/// produces plain text or rendered subtitles.
99+
#[cfg(feature = "exp-subtitle-codecs")]
94100
pub trait SubtitleDecoder: Send + Sync {
95101
/// Reset the decoder.
96102
///

symphonia-core/src/codecs/video.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
1010
use std::fmt;
1111

12-
use crate::codecs::{CodecInfo, CodecProfile};
12+
#[cfg(feature = "exp-video-codecs")]
13+
use crate::codecs::CodecInfo;
14+
use crate::codecs::CodecProfile;
1315
use crate::common::FourCc;
1416

1517
/// An `VideoCodecId` is a unique identifier used to identify a specific video codec.
@@ -132,13 +134,15 @@ impl VideoCodecParameters {
132134
}
133135

134136
/// `VideoDecoderOptions` is a common set of options that all subtitle decoders use.
137+
#[cfg(feature = "exp-video-codecs")]
135138
#[derive(Copy, Clone, Debug, Default)]
136139
pub struct VideoDecoderOptions {
137140
// None yet.
138141
}
139142

140143
/// A `VideoDecoder` implements a video codec's decode algorithm. It consumes `Packet`s and
141144
/// produces video frames.
145+
#[cfg(feature = "exp-video-codecs")]
142146
pub trait VideoDecoder: Send + Sync {
143147
/// Reset the decoder.
144148
///

symphonia-play/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ rust-version = "1.77"
1111
publish = false
1212
default-run = "symphonia-play"
1313

14+
[features]
15+
exp-video-codecs = ["symphonia/exp-video-codecs"]
16+
exp-subtitle-codecs = ["symphonia/exp-subtitle-codecs"]
17+
18+
# Enable experimental features since symphonia-play is a development tool.
19+
default = ["exp-subtitle-codecs", "exp-video-codecs"]
20+
1421
[dependencies]
1522
clap = "3.1.0"
1623
lazy_static = "1.4.0"

symphonia-play/src/ui.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ pub fn print_tracks(tracks: &[Track]) {
105105
print_pair("Channel Map:", &channels, Bullet::None, 1);
106106
}
107107
}
108+
#[cfg(feature = "exp-video-codecs")]
108109
Some(CodecParameters::Video(params)) => {
109110
let codec_info = reg.get_video_decoder(params.codec).map(|d| &d.codec.info);
110111

@@ -130,6 +131,7 @@ pub fn print_tracks(tracks: &[Track]) {
130131
print_pair("Height:", &height, Bullet::None, 1);
131132
}
132133
}
134+
#[cfg(feature = "exp-subtitle-codecs")]
133135
Some(CodecParameters::Subtitle(params)) => {
134136
let codec_name = fmt_codec_name(
135137
reg.get_subtitle_decoder(params.codec).map(|d| &d.codec.info),

symphonia/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ opt-simd = [
8888
"opt-simd-neon",
8989
]
9090

91+
# Experimental features.
92+
exp-subtitle-codecs = ["symphonia-core/exp-subtitle-codecs"]
93+
exp-video-codecs = ["symphonia-core/exp-video-codecs"]
94+
9195
[dependencies]
9296
lazy_static = "1.4.0"
9397

symphonia/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,24 @@
8888
//!
8989
//! **Tip:** All SIMD optimizations can be enabled with the `opt-simd` feature flag.
9090
//!
91+
//! # Experimental Features
92+
//!
93+
//! Previews of experimental new features may be enabled by using feature flags. Experimental
94+
//! features should be used for development purposes only. Before using an experimental feature,
95+
//! please observe the warnings below. Never use experimental features in a production application.
96+
//!
97+
//! | Experimental Feature | Feature Flag |
98+
//! |------------------------|-----------------------|
99+
//! | Subtitle codec support | `exp-subtitle-codecs` |
100+
//! | Video codec support | `exp-video-codecs` |
101+
//!
102+
//! ## Warnings
103+
//!
104+
//! * SemVer compatibilty is **not** guaranteed. Be prepared for build failures.
105+
//! * Experimental features and their associated feature flags **may be removed at any time.**
106+
//! * Functionality **may change or break at any time.**
107+
//! * Again, **never** use in any production application.
108+
//!
91109
//! # Usage
92110
//!
93111
//! The following steps describe a basic usage of Symphonia:

0 commit comments

Comments
 (0)