Skip to content
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

Require FormatReader and Decoder to be Send #31

Merged
merged 2 commits into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion symphonia-core/src/codecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ impl Default for DecoderOptions {

/// A `Decoder` implements a codec's decode algorithm. It consumes `Packet`s and produces
/// `AudioBuffer`s.
pub trait Decoder {
pub trait Decoder: Send {

/// Attempts to instantiates a `Decoder` using the provided `CodecParameters`.
fn try_new(params: &CodecParameters, options: &DecoderOptions) -> Result<Self>
Expand Down
2 changes: 1 addition & 1 deletion symphonia-core/src/formats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl Stream {
/// `FormatReader` provides an Iterator-like interface over packets for easy consumption and
/// filtering. Seeking will invalidate the assumed state of any decoder processing packets from
/// `FormatReader` and should be reset after a successful seek operation.
pub trait FormatReader {
pub trait FormatReader: Send {
/// Attempt to instantiate a `FormatReader` using the provided `FormatOptions` and
/// `MediaSourceStream`. The reader will probe the container to verify format support, determine
/// the number of contained streams, and read any initial metadata.
Expand Down
8 changes: 4 additions & 4 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 All @@ -81,7 +81,7 @@ pub struct ReadOnlySource<R: io::Read> {
inner: R,
}

impl<R: io::Read> ReadOnlySource<R> {
impl<R: io::Read + Send> ReadOnlySource<R> {
/// Instantiates a new `ReadOnlySource<R>` by taking ownership and wrapping the provided
/// `Read`er.
pub fn new(inner: R) -> Self {
Expand All @@ -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
2 changes: 1 addition & 1 deletion symphonia-core/src/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ impl MetadataQueue {
}
}

pub trait MetadataReader {
pub trait MetadataReader: Send {
/// Instantiates the `MetadataReader` with the provided `MetadataOptions`.
fn new(options: &MetadataOptions) -> Self
where
Expand Down
8 changes: 4 additions & 4 deletions symphonia-format-isomp4/src/demuxer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use symphonia_core::meta::MetadataQueue;
use symphonia_core::probe::{Descriptor, Instantiate, QueryDescriptor};
use symphonia_core::units::Time;

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

use crate::atoms::{AtomIterator, AtomType};
use crate::atoms::{FtypAtom, MoovAtom, MoofAtom, SidxAtom, TrakAtom, MetaAtom, MvexAtom};
Expand Down Expand Up @@ -109,7 +109,7 @@ pub struct IsoMp4Reader {
/// 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 @@ -404,8 +404,8 @@ impl FormatReader for IsoMp4Reader {
.collect();

// 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));
// present, wrap it in an Arc so it can be shared amongst all segments.
let mvex = moov.mvex.take().map(|m| Arc::new(m));

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

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

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

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

pub struct SampleDataDesc {
pub base_pos: u64,
pub size: u32,
}

pub trait StreamSegment {
pub trait StreamSegment: Send {
/// Gets the sequence number of this segment.
fn sequence_num(&self) -> u32;

Expand Down Expand Up @@ -45,13 +45,13 @@ 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>) -> MoofSegment {
let mut seq = Vec::new();

// Calculate the sequence information for each track of this segment.
Expand Down
2 changes: 1 addition & 1 deletion symphonia-format-ogg/src/mappings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub enum MapResult {
}

/// A `Mapper` implements packet-handling for a specific `Codec`.
pub trait Mapper {
pub trait Mapper: Send {
fn codec(&self) -> &CodecParameters;
fn map_packet(&mut self, buf: &[u8]) -> Result<MapResult>;
}
Expand Down