Skip to content

Commit

Permalink
make it send
Browse files Browse the repository at this point in the history
  • Loading branch information
aschey committed May 20, 2021
1 parent 47b039c commit 85b4c90
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 23 deletions.
4 changes: 2 additions & 2 deletions symphonia-core/src/codecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ pub struct CodecDescriptor {
/// A longer, more descriptive, string identifying the codec.
pub long_name: &'static str,
// An instantiation function for the codec.
pub inst_func: fn(&CodecParameters, &DecoderOptions) -> Result<Box<dyn Decoder>>,
pub inst_func: fn(&CodecParameters, &DecoderOptions) -> Result<Box<dyn Decoder + Send>>,
}

/// A `CodecRegistry` allows the registration of codecs, and provides a method to instantiate a
Expand Down Expand Up @@ -392,7 +392,7 @@ impl CodecRegistry {
&self,
params: &CodecParameters,
options: &DecoderOptions,
) -> Result<Box<dyn Decoder>> {
) -> Result<Box<dyn Decoder + Send>> {
if let Some(descriptor) = self.codecs.get(&params.codec) {
Ok((descriptor.inst_func)(params, options)?)
} else {
Expand Down
6 changes: 3 additions & 3 deletions symphonia-core/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub use scoped_stream::ScopedStream;

/// A `MediaSource` is a composite trait of `std::io::Read` and `std::io::Seek`. Despite requiring
/// the `Seek` trait, seeking is an optional capability that can be queried at runtime.
pub trait MediaSource: io::Read + io::Seek {
pub trait MediaSource: io::Read + io::Seek + Send {
/// Returns if the source is seekable. This may be an expensive operation.
fn is_seekable(&self) -> bool;

Expand Down Expand Up @@ -60,7 +60,7 @@ impl MediaSource for std::fs::File {
}
}

impl<T: std::convert::AsRef<[u8]>> MediaSource for io::Cursor<T> {
impl<T: std::convert::AsRef<[u8]> + Send> MediaSource for io::Cursor<T> {
/// Always returns true since a `io::Cursor<u8>` is always seekable.
fn is_seekable(&self) -> bool {
true
Expand Down Expand Up @@ -104,7 +104,7 @@ impl<R: io::Read> ReadOnlySource<R> {
}
}

impl<R: io::Read> MediaSource for ReadOnlySource<R> {
impl<R: io::Read + Send> MediaSource for ReadOnlySource<R> {
fn is_seekable(&self) -> bool {
false
}
Expand Down
4 changes: 2 additions & 2 deletions symphonia-core/src/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ mod bloom {
#[derive(Copy, Clone)]
pub enum Instantiate {
/// Instantiation function for a `FormatReader`.
Format(fn(MediaSourceStream, &FormatOptions) -> Result<Box<dyn FormatReader>>),
Format(fn(MediaSourceStream, &FormatOptions) -> Result<Box<dyn FormatReader + Send>>),
/// Instantiation function for a `MetadataReader`.
Metadata(fn(&MetadataOptions) -> Box<dyn MetadataReader>),
}
Expand Down Expand Up @@ -164,7 +164,7 @@ impl Hint {
/// `ProbeResult` contains the result of a format probe operation.
pub struct ProbeResult {
/// An instance of a `FormatReader` for the probed format
pub format: Box<dyn FormatReader>,
pub format: Box<dyn FormatReader + Send>,
/// A queue of `Metadata` revisions read during the probe operation before the instantiation of
/// the `FormatReader`.
pub metadata: MetadataQueue,
Expand Down
14 changes: 8 additions & 6 deletions symphonia-format-isomp4/src/demuxer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ use symphonia_core::meta::MetadataQueue;
use symphonia_core::probe::{Descriptor, Instantiate, QueryDescriptor};
use symphonia_core::units::Time;

use std::io::{Seek, SeekFrom};
use std::rc::Rc;
use std::{
io::{Seek, SeekFrom},
sync::Arc,
};

use crate::atoms::stsd::SampleDescription;
use crate::atoms::{AtomIterator, AtomType};
Expand Down Expand Up @@ -110,11 +112,11 @@ pub struct IsoMp4Reader {
cues: Vec<Cue>,
metadata: MetadataQueue,
/// Segments of the movie. Sorted in ascending order by sequence number.
segs: Vec<Box<dyn StreamSegment>>,
segs: Vec<Box<dyn StreamSegment + Send>>,
/// State tracker for each track.
tracks: Vec<TrackState>,
/// Optional, movie extends atom used for fragmented streams.
mvex: Option<Rc<MvexAtom>>,
mvex: Option<Arc<MvexAtom>>,
}

impl IsoMp4Reader {
Expand Down Expand Up @@ -405,9 +407,9 @@ impl FormatReader for IsoMp4Reader {

// A Movie Extends (mvex) atom is required to support segmented streams. If the mvex atom is
// present, wrap it in an Rc so it can be shared amongst all segments.
let mvex = moov.mvex.take().map(|m| Rc::new(m));
let mvex = moov.mvex.take().map(|m| Arc::new(m));

let segs: Vec<Box<dyn StreamSegment>> = vec![Box::new(MoovSegment::new(moov))];
let segs: Vec<Box<dyn StreamSegment + Send>> = vec![Box::new(MoovSegment::new(moov))];

Ok(IsoMp4Reader {
iter,
Expand Down
10 changes: 7 additions & 3 deletions symphonia-format-isomp4/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use symphonia_core::errors::{decode_error, Error, Result};

use crate::atoms::{stsz::SampleSize, Co64Atom, MoofAtom, MoovAtom, MvexAtom, StcoAtom};

use std::rc::Rc;
use std::sync::Arc;

pub struct SampleDataDesc {
pub base_pos: u64,
Expand Down Expand Up @@ -45,13 +45,17 @@ struct SequenceInfo {

pub struct MoofSegment {
moof: MoofAtom,
mvex: Rc<MvexAtom>,
mvex: Arc<MvexAtom>,
seq: Vec<SequenceInfo>,
}

impl MoofSegment {
/// Instantiate a new segment from a `MoofAtom`.
pub fn new(moof: MoofAtom, mvex: Rc<MvexAtom>, last: &Box<dyn StreamSegment>) -> MoofSegment {
pub fn new(
moof: MoofAtom,
mvex: Arc<MvexAtom>,
last: &Box<dyn StreamSegment + Send>,
) -> MoofSegment {
let mut seq = Vec::new();

// Calculate the sequence information for each track of this segment.
Expand Down
4 changes: 2 additions & 2 deletions symphonia-format-ogg/src/demuxer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct OggReader {
cues: Vec<Cue>,
metadata: MetadataQueue,
physical_stream: PhysicalStream,
mappers: BTreeMap<u32, Box<dyn mappings::Mapper>>,
mappers: BTreeMap<u32, Box<dyn mappings::Mapper + Send>>,
}

impl QueryDescriptor for OggReader {
Expand All @@ -52,7 +52,7 @@ impl FormatReader for OggReader {
let mut physical_stream: PhysicalStream = Default::default();

let mut streams = Vec::new();
let mut mappers = BTreeMap::<u32, Box<dyn mappings::Mapper>>::new();
let mut mappers = BTreeMap::<u32, Box<dyn mappings::Mapper + Send>>::new();

// The first page of each logical stream, marked with the first page flag, must contain the
// identification packet for the encapsulated codec bitstream. The first page for each
Expand Down
2 changes: 1 addition & 1 deletion symphonia-format-ogg/src/mappings/flac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const OGG_FLAC_PACKET_TYPE: u8 = 0x7f;
/// The native FLAC signature.
const FLAC_SIGNATURE: &[u8] = b"fLaC";

pub fn detect(buf: &[u8]) -> Result<Option<Box<dyn Mapper>>> {
pub fn detect(buf: &[u8]) -> Result<Option<Box<dyn Mapper + Send>>> {
// The packet shall be exactly the expected length.
if buf.len() != OGG_FLAC_HEADER_PACKET_SIZE {
return Ok(None);
Expand Down
4 changes: 2 additions & 2 deletions symphonia-format-ogg/src/mappings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod opus;
mod vorbis;

/// Detect `CodecParameters` for a stream that is coded using a supported codec.
pub fn detect(buf: &[u8]) -> Result<Option<Box<dyn Mapper>>> {
pub fn detect(buf: &[u8]) -> Result<Option<Box<dyn Mapper + Send>>> {
let mapper = flac::detect(buf)?
.or(vorbis::detect(buf)?)
.or(opus::detect(buf)?)
Expand All @@ -35,7 +35,7 @@ pub trait Mapper {
fn map_packet(&mut self, buf: &[u8]) -> Result<MapResult>;
}

fn make_null_mapper() -> Option<Box<dyn Mapper>> {
fn make_null_mapper() -> Option<Box<dyn Mapper + Send>> {
Some(Box::new(NullMapper::new()))
}

Expand Down
2 changes: 1 addition & 1 deletion symphonia-format-ogg/src/mappings/opus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const OGG_OPUS_COMMENT_SIGNATURE: &[u8] = b"OpusTags";
/// The maximum support Opus OGG mapping version.
const OGG_OPUS_MAPPING_VERSION_MAX: u8 = 0x0f;

pub fn detect(buf: &[u8]) -> Result<Option<Box<dyn Mapper>>> {
pub fn detect(buf: &[u8]) -> Result<Option<Box<dyn Mapper + Send>>> {
// The identification packet for Opus must be a minimum size.
if buf.len() < OGG_OPUS_MIN_IDENTIFICATION_PACKET_SIZE {
return Ok(None);
Expand Down
2 changes: 1 addition & 1 deletion symphonia-format-ogg/src/mappings/vorbis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const VORBIS_BLOCKSIZE_MIN: u8 = 6;
/// The maximum block size (8192) expressed as a power-of-2 exponent.
const VORBIS_BLOCKSIZE_MAX: u8 = 13;

pub fn detect(buf: &[u8]) -> Result<Option<Box<dyn Mapper>>> {
pub fn detect(buf: &[u8]) -> Result<Option<Box<dyn Mapper + Send>>> {
// The identification header packet must be the correct size.
if buf.len() != VORBIS_IDENTIFICATION_HEADER_SIZE {
return Ok(None);
Expand Down

0 comments on commit 85b4c90

Please sign in to comment.