aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordvdli <dvdli@google.com>2021-01-28 11:53:30 +0800
committerdvdli <dvdli@google.com>2021-01-28 14:25:40 +0800
commitc0f924738de2b8f5478e8b454b4ad5521802f3f6 (patch)
treecc0248f32f5e6c7afee5b098d416c846cf435c04
parentb618ec79a1fde67594d7361c5fdc07d74a464951 (diff)
prepare in pcm_generic_transfer
-rw-r--r--examples/pcm-readi.c1
-rw-r--r--examples/pcm-writei.c1
-rw-r--r--src/pcm.c4
-rw-r--r--tests/src/pcm_in_test.cc2
-rw-r--r--tests/src/pcm_loopback_test.cc2
-rw-r--r--tests/src/pcm_out_test.cc2
-rw-r--r--utils/tinycap.c1
-rw-r--r--utils/tinyplay.c1
8 files changed, 5 insertions, 9 deletions
diff --git a/examples/pcm-readi.c b/examples/pcm-readi.c
index dc18b63..8722b41 100644
--- a/examples/pcm-readi.c
+++ b/examples/pcm-readi.c
@@ -29,7 +29,6 @@ static size_t read_frames(void **frames)
fprintf(stderr, "failed to open PCM\n");
return 0;
}
- pcm_prepare(pcm);
unsigned int frame_size = pcm_frames_to_bytes(pcm, 1);
unsigned int frames_per_sec = pcm_get_rate(pcm);
diff --git a/examples/pcm-writei.c b/examples/pcm-writei.c
index 46b1a3d..19eafac 100644
--- a/examples/pcm-writei.c
+++ b/examples/pcm-writei.c
@@ -70,7 +70,6 @@ static int write_frames(const void * frames, size_t byte_count){
fprintf(stderr, "failed to open PCM\n");
return -1;
}
- pcm_prepare(pcm);
unsigned int frame_count = pcm_bytes_to_frames(pcm, byte_count);
diff --git a/src/pcm.c b/src/pcm.c
index 8678919..3d7da0c 100644
--- a/src/pcm.c
+++ b/src/pcm.c
@@ -1637,6 +1637,10 @@ static int pcm_generic_transfer(struct pcm *pcm, void *data,
if (frames > INT_MAX)
return -EINVAL;
+ if (pcm_state(pcm) == PCM_STATE_SETUP && pcm_prepare(pcm) != 0) {
+ return -1;
+ }
+
again:
if (pcm->flags & PCM_MMAP)
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 {
diff --git a/utils/tinycap.c b/utils/tinycap.c
index e3aa9df..7d4b8a4 100644
--- a/utils/tinycap.c
+++ b/utils/tinycap.c
@@ -231,7 +231,6 @@ unsigned int capture_sample(FILE *file, unsigned int card, unsigned int device,
pcm_get_error(pcm));
return 0;
}
- pcm_prepare(pcm);
size = pcm_frames_to_bytes(pcm, pcm_get_buffer_size(pcm));
buffer = malloc(size);
diff --git a/utils/tinyplay.c b/utils/tinyplay.c
index 482ad24..2689158 100644
--- a/utils/tinyplay.c
+++ b/utils/tinyplay.c
@@ -192,7 +192,6 @@ int ctx_init(struct ctx* ctx, const struct cmd *cmd)
pcm_close(ctx->pcm);
return -1;
}
- pcm_prepare(ctx->pcm);
return 0;
}