public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Simon Ser <simon.ser@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: martin.peres@intel.com
Subject: [igt-dev] [PATCH i-g-t v3 03/10] tests/kms_chamelium: introduce audio_state_receive
Date: Mon, 27 May 2019 17:34:11 +0300	[thread overview]
Message-ID: <20190527143418.7925-4-simon.ser@intel.com> (raw)
In-Reply-To: <20190527143418.7925-1-simon.ser@intel.com>

This extracts the logic receiving audio pages in do_test_display_audio into a
new audio_state_receive function. The function takes care of updating the
current msec counter and dumping the received data in a file.

Signed-off-by: Simon Ser <simon.ser@intel.com>
Reviewed-by: Martin Peres <martin.peres@linux.intel.com>
---
 tests/kms_chamelium.c | 55 ++++++++++++++++++++++++++++---------------
 1 file changed, 36 insertions(+), 19 deletions(-)

diff --git a/tests/kms_chamelium.c b/tests/kms_chamelium.c
index 27693681728e..71489e5df9d7 100644
--- a/tests/kms_chamelium.c
+++ b/tests/kms_chamelium.c
@@ -827,6 +827,9 @@ struct audio_state {
 	struct audio_signal *signal;
 	int channel_mapping[CHAMELIUM_MAX_AUDIO_CHANNELS];
 
+	size_t recv_pages;
+	int msec;
+
 	int dump_fd;
 	char *dump_path;
 
@@ -876,6 +879,9 @@ static void audio_state_start(struct audio_state *state)
 	enum chamelium_stream_realtime_mode stream_mode;
 	char dump_suffix[64];
 
+	state->recv_pages = 0;
+	state->msec = 0;
+
 	igt_debug("Starting test with playback format %s, sampling rate %d Hz "
 		  "and %d channels\n",
 		  snd_pcm_format_name(state->playback.format),
@@ -936,6 +942,29 @@ static void audio_state_start(struct audio_state *state)
 	}
 }
 
+static void audio_state_receive(struct audio_state *state,
+				int32_t **recv, size_t *recv_len)
+{
+	bool ok;
+	size_t page_count;
+	size_t recv_size;
+
+	ok = chamelium_stream_receive_realtime_audio(state->stream,
+						     &page_count,
+						     recv, recv_len);
+	igt_assert(ok);
+
+	state->msec = state->recv_pages * *recv_len
+		      / (double) state->capture.channels
+		      / (double) state->capture.rate * 1000;
+	state->recv_pages++;
+
+	if (state->dump_fd >= 0) {
+		recv_size = *recv_len * sizeof(int32_t);
+		igt_assert(write(state->dump_fd, *recv, recv_size) == recv_size);
+	}
+}
+
 static void audio_state_stop(struct audio_state *state, bool success)
 {
 	bool ok;
@@ -1003,12 +1032,12 @@ audio_output_callback(void *data, void *buffer, int samples)
 
 static bool do_test_display_audio(struct audio_state *state)
 {
-	int msec, freq, step;
+	int freq, step;
 	int32_t *recv, *buf;
 	double *channel;
-	size_t i, j, streak, page_count;
-	size_t recv_len, buf_len, buf_cap, buf_size, channel_len;
-	bool ok, success;
+	size_t i, j, streak;
+	size_t recv_len, buf_len, buf_cap, channel_len;
+	bool success;
 	int capture_chan;
 
 	state->signal = audio_signal_init(state->playback.channels,
@@ -1064,13 +1093,8 @@ static bool do_test_display_audio(struct audio_state *state)
 
 	success = false;
 	streak = 0;
-	msec = 0;
-	i = 0;
-	while (!success && msec < AUDIO_TIMEOUT) {
-		ok = chamelium_stream_receive_realtime_audio(state->stream,
-							     &page_count,
-							     &recv, &recv_len);
-		igt_assert(ok);
+	while (!success && state->msec < AUDIO_TIMEOUT) {
+		audio_state_receive(state, &recv, &recv_len);
 
 		memcpy(&buf[buf_len], recv, recv_len * sizeof(int32_t));
 		buf_len += recv_len;
@@ -1079,13 +1103,7 @@ static bool do_test_display_audio(struct audio_state *state)
 			continue;
 		igt_assert(buf_len == buf_cap);
 
-		if (state->dump_fd >= 0) {
-			buf_size = buf_len * sizeof(int32_t);
-			igt_assert(write(state->dump_fd, buf, buf_size) == buf_size);
-		}
-
-		msec = i * channel_len / (double) state->capture.rate * 1000;
-		igt_debug("Detecting audio signal, t=%d msec\n", msec);
+		igt_debug("Detecting audio signal, t=%d msec\n", state->msec);
 
 		for (j = 0; j < state->playback.channels; j++) {
 			capture_chan = state->channel_mapping[j];
@@ -1107,7 +1125,6 @@ static bool do_test_display_audio(struct audio_state *state)
 		}
 
 		buf_len = 0;
-		i++;
 
 		success = streak == MIN_STREAK * state->playback.channels;
 	}
-- 
2.21.0

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  parent reply	other threads:[~2019-05-27 14:34 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-27 14:34 [igt-dev] [PATCH i-g-t v3 00/10] tests/kms_chamelium: add pulse test Simon Ser
2019-05-27 14:34 ` [igt-dev] [PATCH i-g-t v3 01/10] lib/igt_chamelium: introduce CHAMELIUM_MAX_AUDIO_CHANNELS Simon Ser
2019-05-27 14:41   ` Peres, Martin
2019-05-27 14:34 ` [igt-dev] [PATCH i-g-t v3 02/10] tests/kms_chamelium: refactor audio test Simon Ser
2019-05-27 14:34 ` Simon Ser [this message]
2019-05-27 14:34 ` [igt-dev] [PATCH i-g-t v3 04/10] tests/kms_chamelium: rename do_test_display_audio and test_audio_configuration Simon Ser
2019-05-27 14:34 ` [igt-dev] [PATCH i-g-t v3 05/10] tests/kms_chamelium: explain why 8-channel tests aren't performed Simon Ser
2019-05-27 14:34 ` [igt-dev] [PATCH i-g-t v3 06/10] lib/igt_audio: introduce audio_convert_to Simon Ser
2019-05-27 14:34 ` [igt-dev] [PATCH i-g-t v3 07/10] tests/kms_chamelium: add name parameter to audio_state_start Simon Ser
2019-05-27 14:34 ` [igt-dev] [PATCH i-g-t v3 08/10] lib/igt_audio: make audio_extract_channel_s32_le support a NULL dst Simon Ser
2019-05-27 14:34 ` [igt-dev] [PATCH i-g-t v3 09/10] tests/kms_chamelium: add a flatline audio test Simon Ser
2019-06-04  8:38   ` Tvrtko Ursulin
2019-06-04 11:22     ` Ser, Simon
2019-06-04 12:26       ` Peres, Martin
2019-06-04 12:59         ` Tvrtko Ursulin
2019-06-04 14:06           ` Ser, Simon
2019-06-05 10:51             ` Tvrtko Ursulin
2019-06-05 13:04               ` Ser, Simon
2019-06-05 13:30                 ` Tvrtko Ursulin
2019-06-04 14:11         ` Ser, Simon
2019-05-27 14:34 ` [igt-dev] [PATCH i-g-t v3 10/10] tests/kms_chamelium: add audio channel alignment test Simon Ser
2019-05-27 16:03 ` [igt-dev] ✓ Fi.CI.BAT: success for tests/kms_chamelium: add pulse test (rev3) Patchwork
2019-05-28  4:48 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190527143418.7925-4-simon.ser@intel.com \
    --to=simon.ser@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=martin.peres@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox