From 855354a87d2983e190088bc5330c129094b900ca Mon Sep 17 00:00:00 2001 From: dvdli Date: Tue, 12 Jan 2021 14:53:42 +0800 Subject: remove pcm_prepare in pcm_open For the dynamic pcm device, it is valid to specify the backend after opening it. However, it is invalid to call prepare on a dynamic pcm device without connecting any backend device. We should not do pcm_prepare in pcm_open. See also: Issue #197 --- tests/src/pcm_in_test.cc | 1 + tests/src/pcm_loopback_test.cc | 2 ++ tests/src/pcm_out_test.cc | 2 ++ 3 files changed, 5 insertions(+) (limited to 'tests') diff --git a/tests/src/pcm_in_test.cc b/tests/src/pcm_in_test.cc index e912abb..5491b00 100644 --- a/tests/src/pcm_in_test.cc +++ b/tests/src/pcm_in_test.cc @@ -47,6 +47,7 @@ class PcmInTest : public ::testing::Test { pcm_object = pcm_open(kLoopbackCard, kLoopbackCaptureDevice, PCM_IN, &kDefaultConfig); ASSERT_NE(pcm_object, nullptr); ASSERT_TRUE(pcm_is_ready(pcm_object)); + pcm_prepare(pcm_object); } virtual void TearDown() override { diff --git a/tests/src/pcm_loopback_test.cc b/tests/src/pcm_loopback_test.cc index 6a3ffb8..9685364 100644 --- a/tests/src/pcm_loopback_test.cc +++ b/tests/src/pcm_loopback_test.cc @@ -160,6 +160,7 @@ TEST(PcmLoopbackTest, LoopbackS16le) { }; pcm *pcm_in = pcm_open(kLoopbackCard, kLoopbackCaptureDevice, PCM_IN, &kInConfig); ASSERT_TRUE(pcm_is_ready(pcm_in)); + pcm_prepare(pcm_in); static constexpr pcm_config kOutConfig = { .channels = kDefaultChannels, @@ -174,6 +175,7 @@ TEST(PcmLoopbackTest, LoopbackS16le) { }; pcm *pcm_out = pcm_open(kLoopbackCard, kLoopbackPlaybackDevice, PCM_OUT, &kOutConfig); ASSERT_TRUE(pcm_is_ready(pcm_out)); + pcm_prepare(pcm_out); ASSERT_EQ(pcm_link(pcm_in, pcm_out), 0); diff --git a/tests/src/pcm_out_test.cc b/tests/src/pcm_out_test.cc index cbc6983..ca984a6 100644 --- a/tests/src/pcm_out_test.cc +++ b/tests/src/pcm_out_test.cc @@ -47,6 +47,7 @@ class PcmOutTest : public ::testing::Test { pcm_object = pcm_open(kLoopbackCard, kLoopbackPlaybackDevice, PCM_OUT, &kDefaultConfig); ASSERT_NE(pcm_object, nullptr); ASSERT_TRUE(pcm_is_ready(pcm_object)); + pcm_prepare(pcm_object); } virtual void TearDown() override { @@ -176,6 +177,7 @@ class PcmOutMmapTest : public PcmOutTest { &kDefaultConfig); ASSERT_NE(pcm_object, nullptr); ASSERT_TRUE(pcm_is_ready(pcm_object)); + pcm_prepare(pcm_object); } virtual void TearDown() override { -- cgit v1.2.3 From c0f924738de2b8f5478e8b454b4ad5521802f3f6 Mon Sep 17 00:00:00 2001 From: dvdli Date: Thu, 28 Jan 2021 11:53:30 +0800 Subject: prepare in pcm_generic_transfer --- tests/src/pcm_in_test.cc | 2 +- tests/src/pcm_loopback_test.cc | 2 -- tests/src/pcm_out_test.cc | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/src/pcm_in_test.cc b/tests/src/pcm_in_test.cc index 5491b00..4d8a697 100644 --- a/tests/src/pcm_in_test.cc +++ b/tests/src/pcm_in_test.cc @@ -47,7 +47,6 @@ class PcmInTest : public ::testing::Test { pcm_object = pcm_open(kLoopbackCard, kLoopbackCaptureDevice, PCM_IN, &kDefaultConfig); ASSERT_NE(pcm_object, nullptr); ASSERT_TRUE(pcm_is_ready(pcm_object)); - pcm_prepare(pcm_object); } virtual void TearDown() override { @@ -74,6 +73,7 @@ class PcmInTest : public ::testing::Test { }; TEST_F(PcmInTest, GetDelay) { + pcm_prepare(pcm_object); long delay = pcm_get_delay(pcm_object); std::cout << delay << std::endl; ASSERT_GE(delay, 0); diff --git a/tests/src/pcm_loopback_test.cc b/tests/src/pcm_loopback_test.cc index 9685364..6a3ffb8 100644 --- a/tests/src/pcm_loopback_test.cc +++ b/tests/src/pcm_loopback_test.cc @@ -160,7 +160,6 @@ TEST(PcmLoopbackTest, LoopbackS16le) { }; pcm *pcm_in = pcm_open(kLoopbackCard, kLoopbackCaptureDevice, PCM_IN, &kInConfig); ASSERT_TRUE(pcm_is_ready(pcm_in)); - pcm_prepare(pcm_in); static constexpr pcm_config kOutConfig = { .channels = kDefaultChannels, @@ -175,7 +174,6 @@ TEST(PcmLoopbackTest, LoopbackS16le) { }; pcm *pcm_out = pcm_open(kLoopbackCard, kLoopbackPlaybackDevice, PCM_OUT, &kOutConfig); ASSERT_TRUE(pcm_is_ready(pcm_out)); - pcm_prepare(pcm_out); ASSERT_EQ(pcm_link(pcm_in, pcm_out), 0); diff --git a/tests/src/pcm_out_test.cc b/tests/src/pcm_out_test.cc index ca984a6..cbc6983 100644 --- a/tests/src/pcm_out_test.cc +++ b/tests/src/pcm_out_test.cc @@ -47,7 +47,6 @@ class PcmOutTest : public ::testing::Test { pcm_object = pcm_open(kLoopbackCard, kLoopbackPlaybackDevice, PCM_OUT, &kDefaultConfig); ASSERT_NE(pcm_object, nullptr); ASSERT_TRUE(pcm_is_ready(pcm_object)); - pcm_prepare(pcm_object); } virtual void TearDown() override { @@ -177,7 +176,6 @@ class PcmOutMmapTest : public PcmOutTest { &kDefaultConfig); ASSERT_NE(pcm_object, nullptr); ASSERT_TRUE(pcm_is_ready(pcm_object)); - pcm_prepare(pcm_object); } virtual void TearDown() override { -- cgit v1.2.3 From 3694925022aa16b10978c92b9a2a69661dbbcdcf Mon Sep 17 00:00:00 2001 From: dvdli Date: Thu, 28 Jan 2021 15:03:17 +0800 Subject: Let pcm_mmap_read/write call pcm_readi/writei The pcm_readi and pcm_writei also can deal with the mmap read/write. Also mark the pcm_mmap_read/write functions as deprecated functions and update the test case. Add mmap playback support to tinyplay --- tests/src/pcm_out_test.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/src/pcm_out_test.cc b/tests/src/pcm_out_test.cc index cbc6983..f8d4345 100644 --- a/tests/src/pcm_out_test.cc +++ b/tests/src/pcm_out_test.cc @@ -192,13 +192,13 @@ TEST_F(PcmOutMmapTest, Write) { buffer[i] = static_cast(i); } - int written_frames = 0; + int res = 0; unsigned int frames = pcm_bytes_to_frames(pcm_object, buffer_size); pcm_start(pcm_object); auto start = std::chrono::steady_clock::now(); for (uint32_t i = 0; i < write_count; ++i) { - written_frames = pcm_mmap_write(pcm_object, buffer.get(), buffer_size); - ASSERT_EQ(written_frames, frames); + res = pcm_mmap_write(pcm_object, buffer.get(), buffer_size); + ASSERT_EQ(res, 0); } pcm_stop(pcm_object); -- cgit v1.2.3 From 1fd610f036a894bc5bcef84d1c1ccd40c45950d8 Mon Sep 17 00:00:00 2001 From: dvdli Date: Thu, 28 Jan 2021 17:46:05 +0800 Subject: fix test case to match the API --- tests/src/mixer_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/src/mixer_test.cc b/tests/src/mixer_test.cc index 717269c..903fb8f 100644 --- a/tests/src/mixer_test.cc +++ b/tests/src/mixer_test.cc @@ -288,7 +288,7 @@ TEST_P(MixerControlsTest, Event) { EXPECT_EQ(mixer_wait_event(mixer_object, 1000), 1); - EXPECT_EQ(mixer_consume_event(mixer_object), 0); + EXPECT_EQ(mixer_consume_event(mixer_object), 1); thread.join(); ASSERT_EQ(mixer_subscribe_events(mixer_object, 0), 0); -- cgit v1.2.3