Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upPlay silence by default #15
Conversation
|
r? @Manishearth |
| 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(); |
This comment has been minimized.
This comment has been minimized.
| @@ -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(); | |||
This comment has been minimized.
This comment has been minimized.
sdroege
May 22, 2018
Contributor
... 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
| 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(); |
This comment has been minimized.
This comment has been minimized.
sdroege
May 22, 2018
Contributor
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. |
| rate, | ||
| ); | ||
| sample_offset += n_samples; | ||
| AudioFormatInfo::from_format(gst_audio::AUDIO_FORMAT_F32).fill_silence(data); |
This comment has been minimized.
This comment has been minimized.
sdroege
May 22, 2018
Contributor
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 |
I'm doing this as part of #21 |
ferjm commentedMay 22, 2018
Quoting the spec: