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

When using ALSA backend Voice doesn't call drop after termination #73

Closed
nchashch opened this issue Aug 4, 2016 · 4 comments
Closed

Comments

@nchashch
Copy link

nchashch commented Aug 4, 2016

I have added a println in Voice::drop like this:

impl Drop for Voice {
    #[inline]
    fn drop(&mut self) {
        println!("Voice droped.");
        unsafe {
            alsa::snd_pcm_close(*self.channel.lock().expect("drop for voice"));
        }
    }
}

And used modified cpal version in rodio like this:

[dependencies.cpal]
path = "../cpal/"
version = "0.2.8"

When running any rodio example line "Voice droped." isn't printed, and the next time I run the example it panics with:

RUST_BACKTRACE=1 cargo run --example basic
     Running `target/debug/examples/basic`
ALSA lib pcm_dmix.c:1079:(snd_pcm_dmix_open) unable to open slave
thread '<main>' panicked at 'device not available: "File descriptor in bad state"', ../src/libcore/result.rs:785
stack backtrace:
   1:     0x55d38f4528ef - std::sys::backtrace::tracing::imp::write::h3800f45f421043b8
   2:     0x55d38f45607b - std::panicking::default_hook::_$u7b$$u7b$closure$u7d$$u7d$::h0ef6c8db532f55dc
   3:     0x55d38f455d03 - std::panicking::default_hook::hf3839060ccbb8764
   4:     0x55d38f44c44d - std::panicking::rust_panic_with_hook::h5dd7da6bb3d06020
   5:     0x55d38f4562c1 - std::panicking::begin_panic::h9bf160aee246b9f6
   6:     0x55d38f44d31a - std::panicking::begin_panic_fmt::haf08a9a70a097ee1
   7:     0x55d38f45625e - rust_begin_unwind
   8:     0x55d38f48b4cf - core::panicking::panic_fmt::h93df64e7370b5253
   9:     0x55d38f444039 - core::result::unwrap_failed::hfa264942aa0c849a
                        at ../src/libcore/macros.rs:29
  10:     0x55d38f443e4d - _<std..result..Result<T, E>>::expect::h4d9839a56813da38
                        at ../src/libcore/result.rs:747
  11:     0x55d38f44023f - cpal::cpal_impl::Endpoint::get_supported_formats_list::h75c5d241492cc62d
                        at /home/user/C/cpal/src/alsa/mod.rs:37
  12:     0x55d38f421efa - cpal::Endpoint::get_supported_formats_list::hb577f5a458b49c0a
                        at /home/user/C/cpal/src/lib.rs:107
  13:     0x55d38f41ad5e - rodio::engine::Engine::start::_$u7b$$u7b$closure$u7d$$u7d$::h88818cfd009576fc
                        at /home/user/C/rodio/src/engine.rs:76
  14:     0x55d38f418e88 - _<std..collections..hash_map..Entry<'a, K, V>>::or_insert_with::h21890678fa9fa9ae
                        at ../src/libstd/collections/hash/map.rs:1534
  15:     0x55d38f41226d - rodio::engine::Engine::start::h87deb3d983372762
                        at /home/user/C/rodio/src/engine.rs:73
  16:     0x55d38f3ea741 - rodio::Sink::new::h808662d15dce8280
                        at /home/user/C/rodio/examples/lib.rs:94
  17:     0x55d38f3daa87 - rodio::play_once::h13ef39eaad2afdcf
                        at /home/user/C/rodio/examples/lib.rs:153
  18:     0x55d38f3cb5bb - basic::main::h8b9602a214009541
                        at /home/user/C/rodio/examples/basic.rs:9
  19:     0x55d38f455918 - std::panicking::try::call::hbbf4746cba890ca7
  20:     0x55d38f45f6db - __rust_try
  21:     0x55d38f45f67e - __rust_maybe_catch_panic
  22:     0x55d38f4553be - std::rt::lang_start::hbcefdc316c2fbd45
  23:     0x55d38f406f29 - main
  24:     0x7fe316299740 - __libc_start_main
  25:     0x55d38f3cb3b8 - _start
  26:                0x0 - <unknown>
error: Process didn't exit successfully: `target/debug/examples/basic` (exit code: 101)

If Voice is properly dropped it doesn't panic and also it doesn't panic when some other process is playing sound.

I have encountered the same problem with cpal/examples/beep.rs example.

@nchashch
Copy link
Author

After #72 examples don't panic anymore when run on my system, but the sound doesn't play properly, it plays for a few moments and then cuts off. I suspect it is caused by the same problem which caused the panics.

@tomaka
Copy link
Collaborator

tomaka commented Sep 13, 2016

#72 considerably changed the code, so I'm not sure that the two problems are related.

@tomaka
Copy link
Collaborator

tomaka commented Sep 13, 2016

I think the new problem is caused by the fact that we immediately drop the cpal voice and stream at creation. This looks like a stupid mistake, but it makes me wonder why it's working for me then.

Anyway, may be fixed by storing the Voice created here in the EndPointVoices created the line below (by adding a new member to the struct).

@nchashch
Copy link
Author

nchashch commented Jan 2, 2017

Closing this, since panic seems to be fixed and the problem I am experiencing with sound not playing properly with ALSA backend is most likely caused by RustAudio/cpal#142.

@nchashch nchashch closed this as completed Jan 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants