All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Ser <simon.ser@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t 2/2] tests/kms_chamelium: introduce audio_state_receive
Date: Thu, 23 May 2019 14:59:24 +0300	[thread overview]
Message-ID: <20190523115924.30524-2-simon.ser@intel.com> (raw)
In-Reply-To: <20190523115924.30524-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>
---
 tests/kms_chamelium.c | 51 +++++++++++++++++++++++++++----------------
 1 file changed, 32 insertions(+), 19 deletions(-)

diff --git a/tests/kms_chamelium.c b/tests/kms_chamelium.c
index faa4c539dbe3..350c46ec76a1 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[8];
 
+	size_t recv_pages;
+	int msec;
+
 	int dump_fd;
 	char *dump_path;
 
@@ -937,6 +940,28 @@ 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->recv_pages++;
+	state->msec = state->recv_pages * *recv_len /
+		      (double) state->capture.rate * 1000;
+
+	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;
@@ -996,12 +1021,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,
@@ -1057,13 +1082,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;
@@ -1072,13 +1092,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];
@@ -1100,7 +1114,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

  reply	other threads:[~2019-05-23 11:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-23 11:59 [igt-dev] [PATCH i-g-t 1/2] tests/kms_chamelium: refactor audio test Simon Ser
2019-05-23 11:59 ` Simon Ser [this message]
2019-05-23 14:06 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/2] " Patchwork
2019-05-24 18:31 ` [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=20190523115924.30524-2-simon.ser@intel.com \
    --to=simon.ser@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.