feat: configure demuxer buffer size
This commit is contained in:
14
src/demux.rs
14
src/demux.rs
@ -37,6 +37,7 @@ pub enum DemuxerInput {
|
|||||||
pub struct Demuxer {
|
pub struct Demuxer {
|
||||||
ctx: *mut AVFormatContext,
|
ctx: *mut AVFormatContext,
|
||||||
input: DemuxerInput,
|
input: DemuxerInput,
|
||||||
|
buffer_size: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Demuxer {
|
impl Demuxer {
|
||||||
@ -50,10 +51,17 @@ impl Demuxer {
|
|||||||
Ok(Self {
|
Ok(Self {
|
||||||
ctx,
|
ctx,
|
||||||
input: DemuxerInput::Url(input.to_string()),
|
input: DemuxerInput::Url(input.to_string()),
|
||||||
|
buffer_size: 1024 * 16,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Configure the buffer size for custom_io
|
||||||
|
pub fn with_buffer_size(mut self, buffer_size: usize) -> Self {
|
||||||
|
self.buffer_size = buffer_size;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Create a new [Demuxer] from an object that implements [Read]
|
/// Create a new [Demuxer] from an object that implements [Read]
|
||||||
pub fn new_custom_io<R: Read + 'static>(reader: R, url: Option<String>) -> Result<Self> {
|
pub fn new_custom_io<R: Read + 'static>(reader: R, url: Option<String>) -> Result<Self> {
|
||||||
unsafe {
|
unsafe {
|
||||||
@ -66,6 +74,7 @@ impl Demuxer {
|
|||||||
Ok(Self {
|
Ok(Self {
|
||||||
ctx,
|
ctx,
|
||||||
input: DemuxerInput::Reader(Some(slimbox_unsize!(reader)), url),
|
input: DemuxerInput::Reader(Some(slimbox_unsize!(reader)), url),
|
||||||
|
buffer_size: 1024 * 16,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,10 +98,9 @@ impl Demuxer {
|
|||||||
}
|
}
|
||||||
DemuxerInput::Reader(input, url) => {
|
DemuxerInput::Reader(input, url) => {
|
||||||
let input = input.take().expect("input stream already taken");
|
let input = input.take().expect("input stream already taken");
|
||||||
const BUFFER_SIZE: usize = 4096;
|
|
||||||
let pb = avio_alloc_context(
|
let pb = avio_alloc_context(
|
||||||
av_mallocz(BUFFER_SIZE) as *mut libc::c_uchar,
|
av_mallocz(self.buffer_size) as *mut _,
|
||||||
BUFFER_SIZE as libc::c_int,
|
self.buffer_size as _,
|
||||||
0,
|
0,
|
||||||
input.into_raw(),
|
input.into_raw(),
|
||||||
Some(read_data),
|
Some(read_data),
|
||||||
|
Reference in New Issue
Block a user