-
Notifications
You must be signed in to change notification settings - Fork 53
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
Play silence by default #15
Conversation
r? @Manishearth |
src/backends/gstreamer/audio_sink.rs
Outdated
let need_data = move |app: &AppSrc, _bytes: u32| { | ||
let mut buffer = gst::Buffer::with_size(buf_size).unwrap(); | ||
let need_data = move |app: &AppSrc, bytes: u32| { | ||
let mut buffer = gst::Buffer::from_slice(&SILENCE[0..bytes as usize]).unwrap(); |
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.
Here you create a buffer with read-only memory ...
src/backends/gstreamer/audio_sink.rs
Outdated
@@ -81,19 +55,16 @@ impl AudioSink for GStreamerAudioSink { | |||
.mul_div_floor(gst::SECOND_VAL, rate as u64) | |||
.unwrap() | |||
.into(); | |||
let next_pts: gst::ClockTime = (sample_offset + n_samples) | |||
let next_pts: gst::ClockTime = (sample_offset + WEBAUDIO_RENDER_QUANTUM) | |||
.mul_div_floor(gst::SECOND_VAL, rate as u64) | |||
.unwrap() | |||
.into(); | |||
buffer.set_pts(pts); | |||
buffer.set_duration(next_pts - pts); | |||
let mut map = buffer.map_writable().unwrap(); |
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.
... and here the read-only memory would be copied into writeable memory so you can modify it.
It would be more efficient to create a buffer with writeable memory to begin with. with_size
as before would do that, you only have to fill it with silence then e.g. with this
src/backends/gstreamer/audio_sink.rs
Outdated
let need_data = move |app: &AppSrc, _bytes: u32| { | ||
let mut buffer = gst::Buffer::with_size(buf_size).unwrap(); | ||
let need_data = move |app: &AppSrc, bytes: u32| { | ||
let mut buffer = gst::Buffer::from_slice(&SILENCE[0..bytes as usize]).unwrap(); |
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.
Also you use the bytes as passed in by appsrc. In theory that might be more than 4096, in theory it might not be a multiple of the unit size (sample size * channels), and worst: the alignment of the silence Vec
might not be correct (it needs to be aligned to the sample size). You probably want to allocate always the same buffer size here like before and not worry about anything :)
Thank you for the feedback @sdroege! I just updated the patch. |
src/backends/gstreamer/audio_sink.rs
Outdated
rate, | ||
); | ||
sample_offset += n_samples; | ||
AudioFormatInfo::from_format(gst_audio::AUDIO_FORMAT_F32).fill_silence(data); |
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.
This works, but you probably want to simply keep around a AudioInfo
for the format you produce later (which then also contains an AudioFormatInfo
).
The render quantum is now called This just needs |
Okay, so there are two separate issues here. One is "what should happen if we don't connect a source node to the output". That should be fixed by fill_silence. I've made this commit do so. The other is "source nodes should output silence when stopped". That should be fixed by having them directly output silence 😄 . We can do that once we have messaging. |
I'm doing this as part of #21 |
Quoting the spec: