Re: [igt-dev] [PATCH i-g-t v2 2/9] tests/kms_chamelium: introduce audio_state_receive

Martin Peres
2019-05-27T12:24:31Z

On 24/05/2019 18:03, Simon Ser wrote:
> 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.

Reviewed-by: Martin Peres <martin.peres@linux.intel.com>

>
> Signed-off-by: Simon Ser <simon.ser@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 1a0a02ca2890..6fdb9d68fcf2 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;
>
> @@ -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;
> }
>