-
Notifications
You must be signed in to change notification settings - Fork 292
Symphonia custom registry support #806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
1304806
ca23dd7
036d8a6
01436ef
2647e82
7c6f984
f019c33
64bbb92
0df400f
ed6482f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| use std::{error::Error, sync::Arc}; | ||
|
|
||
| use rodio::decoder::DecoderBuilder; | ||
| use symphonia::{core::codecs::CodecRegistry, default::register_enabled_codecs}; | ||
| use symphonia_adapter_libopus::OpusDecoder; | ||
|
|
||
| fn main() -> Result<(), Box<dyn Error>> { | ||
| let stream_handle = rodio::DeviceSinkBuilder::open_default_sink()?; | ||
| let sink = rodio::Player::connect_new(stream_handle.mixer()); | ||
|
|
||
| let mut codec_registry = CodecRegistry::new(); | ||
| codec_registry.register_all::<OpusDecoder>(); | ||
| register_enabled_codecs(&mut codec_registry); | ||
|
|
||
| let codec_registry_arc = Arc::new(codec_registry); | ||
|
|
||
| let file = std::fs::File::open("../assets/music.opus")?; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this work? Shouldn't it just be "assets/music.opus"? |
||
| let decoder = DecoderBuilder::new() | ||
| .with_codec_registry(codec_registry_arc) | ||
| .with_data(file) | ||
| .build()?; | ||
| sink.append(decoder); | ||
|
|
||
| sink.sleep_until_end(); | ||
|
|
||
| Ok(()) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| use core::time::Duration; | ||
| use std::sync::Arc; | ||
| use std::{fmt::Debug, sync::Arc}; | ||
| use symphonia::{ | ||
| core::{ | ||
| audio::{AudioBufferRef, SampleBuffer, SignalSpec}, | ||
| codecs::{Decoder, DecoderOptions, CODEC_TYPE_NULL}, | ||
| codecs::{CodecRegistry, Decoder, DecoderOptions, CODEC_TYPE_NULL}, | ||
| errors::Error, | ||
| formats::{FormatOptions, FormatReader, SeekMode, SeekTo, SeekedTo}, | ||
| io::MediaSourceStream, | ||
|
|
@@ -20,6 +20,25 @@ use crate::{ | |
| source, Source, | ||
| }; | ||
|
|
||
| #[derive(Clone)] | ||
| /// Enum for choosing which codec registry to used with Symphonia decoders. | ||
| pub enum SymphoniaRegistry { | ||
| /// Use the symphonia default registry symphonia::default::get_codecs() | ||
| Default, | ||
|
|
||
| ///Use a custom CodecRegistry | ||
| Custom(Arc<CodecRegistry>), | ||
| } | ||
|
|
||
| impl Debug for SymphoniaRegistry { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| match self { | ||
| Self::Default => write!(f, "Default"), | ||
| Self::Custom(_) => write!(f, "Custom"), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could it put out more? It seems that |
||
| } | ||
| } | ||
| } | ||
|
|
||
| pub(crate) struct SymphoniaDecoder { | ||
| decoder: Box<dyn Decoder>, | ||
| current_span_offset: usize, | ||
|
|
@@ -102,8 +121,12 @@ impl SymphoniaDecoder { | |
| None => return Ok(None), | ||
| }; | ||
|
|
||
| let mut decoder = symphonia::default::get_codecs() | ||
| .make(&track.codec_params, &DecoderOptions::default())?; | ||
| let mut decoder = match &settings.codec_registry { | ||
| SymphoniaRegistry::Default => symphonia::default::get_codecs(), | ||
| SymphoniaRegistry::Custom(cr) => cr.as_ref(), | ||
| } | ||
| .make(&track.codec_params, &DecoderOptions::default())?; | ||
|
|
||
| let total_duration = stream | ||
| .codec_params | ||
| .time_base | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: please add a newline after.
Should we call this
symphonic-opusinstead?