diff options
author | paulhsia <paulhsia@google.com> | 2019-10-22 22:49:28 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-10-22 22:49:28 -0700 |
commit | 5505d71f92ecdd92c42fd733e6f49f76a2aa1d24 (patch) | |
tree | 0237b1682e1c85194d9fa9e20c6d19137cc5dbc3 | |
parent | 8b9ed1f010af9d82eb3194a10dad52cec551203c (diff) | |
parent | 0323debe2df03406b164fe52470747a92dcc931f (diff) | |
download | adhd-5505d71f92ecdd92c42fd733e6f49f76a2aa1d24.tar.gz |
Merge remote-tracking branch 'cros/master' into uprev
am: 0323debe2d
Change-Id: Iadca70dd62b5598b4c8686b8bc2de9dc0fffa016
269 files changed, 17581 insertions, 14746 deletions
@@ -12,3 +12,6 @@ hychao@google.com paulhsia@google.com tzungbi@google.com yuhsuan@google.com + +# So any team members can +2 +* diff --git a/adhdinfo/Makefile b/adhdinfo/Makefile deleted file mode 100644 index 0819a582..00000000 --- a/adhdinfo/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright (c) 2011 The Chromium OS Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. -include $(ADHD_DIR)/defs/definitions.mk - -CFILES = \ - main.c - -OFILES = $(CFILES:.c=.o) -MY_LIBS = asound - -adhdinfo: $(OFILES) $(GAVD_ARCHIVE) - $(CC) -o $@ $(OFILES) $(LIBS) - --include *.d diff --git a/adhdinfo/main.c b/adhdinfo/main.c deleted file mode 100644 index 0589238d..00000000 --- a/adhdinfo/main.c +++ /dev/null @@ -1,69 +0,0 @@ -/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include <errno.h> -#include <getopt.h> -#include <stdio.h> -#include <stdlib.h> - -#include "adhd_alsa.h" - -static unsigned arg_verbose = 0; - -static void help(void) -{ - /* TODO(thutt): Add help */ -} - -static void process_arguments(int argc, char **argv) -{ - static struct option options[] = { - { - .name = "help", - .has_arg = no_argument, - .flag = NULL, - .val = 256 - }, - { - .name = "verbose", - .has_arg = no_argument, - .flag = NULL, - .val = 257 - }, - }; - - while (1) { - int option_index = 0; - const int choice = getopt_long(argc, argv, "", options, &option_index); - - if (choice == -1) { - break; - } - - switch (choice) { - case 256: - help(); - break; - - case 257: - arg_verbose = 1; - break; - - default: - printf("?? getopt returned character code 0%o ??\n", choice); - } - } -} - - -int main(int argc, char **argv) -{ - adhd_alsa_info_t alsa_info; - process_arguments(argc, argv); - - adhd_alsa_get_all_card_info(&alsa_info); - adhd_alsa_release_card_info(&alsa_info); - return 0; -} diff --git a/alsa-module-config/alsa-auron.conf b/alsa-module-config/alsa-auron.conf deleted file mode 100644 index 6e595b06..00000000 --- a/alsa-module-config/alsa-auron.conf +++ /dev/null @@ -1 +0,0 @@ -options snd_hda_intel model=auron patch=,auron_alsa.fw diff --git a/alsa-module-config/alsa-auron_paine.conf b/alsa-module-config/alsa-auron_paine.conf deleted file mode 100644 index e0925ea9..00000000 --- a/alsa-module-config/alsa-auron_paine.conf +++ /dev/null @@ -1 +0,0 @@ -options snd_hda_intel model=auron_paine patch=,auron_paine_alsa.fw diff --git a/alsa-module-config/alsa-auron_yuna.conf b/alsa-module-config/alsa-auron_yuna.conf deleted file mode 100644 index 937e0488..00000000 --- a/alsa-module-config/alsa-auron_yuna.conf +++ /dev/null @@ -1 +0,0 @@ -options snd_hda_intel model=auron_yuna patch=,auron_yuna_alsa.fw diff --git a/alsa-module-config/alsa-gandof.conf b/alsa-module-config/alsa-gandof.conf deleted file mode 100644 index 5578f5c0..00000000 --- a/alsa-module-config/alsa-gandof.conf +++ /dev/null @@ -1 +0,0 @@ -options snd_hda_intel model=gandof patch=,gandof_alsa.fw diff --git a/alsa-module-config/alsa-lulu.conf b/alsa-module-config/alsa-lulu.conf deleted file mode 100644 index b4f05d88..00000000 --- a/alsa-module-config/alsa-lulu.conf +++ /dev/null @@ -1 +0,0 @@ -options snd_hda_intel model=lulu patch=,lulu_alsa.fw diff --git a/alsa-module-config/auron_alsa.fw b/alsa-module-config/auron_alsa.fw deleted file mode 100644 index 40ac817e..00000000 --- a/alsa-module-config/auron_alsa.fw +++ /dev/null @@ -1,9 +0,0 @@ -[codec] -0x10ec0283 0x10ec0283 0 - -[model] -alc283-dac-wcaps - -[hint] -auto_mute = no -auto_mic = no diff --git a/alsa-module-config/auron_paine_alsa.fw b/alsa-module-config/auron_paine_alsa.fw deleted file mode 100644 index 40ac817e..00000000 --- a/alsa-module-config/auron_paine_alsa.fw +++ /dev/null @@ -1,9 +0,0 @@ -[codec] -0x10ec0283 0x10ec0283 0 - -[model] -alc283-dac-wcaps - -[hint] -auto_mute = no -auto_mic = no diff --git a/alsa-module-config/auron_yuna_alsa.fw b/alsa-module-config/auron_yuna_alsa.fw deleted file mode 100644 index 40ac817e..00000000 --- a/alsa-module-config/auron_yuna_alsa.fw +++ /dev/null @@ -1,9 +0,0 @@ -[codec] -0x10ec0283 0x10ec0283 0 - -[model] -alc283-dac-wcaps - -[hint] -auto_mute = no -auto_mic = no diff --git a/alsa-module-config/gandof_alsa.fw b/alsa-module-config/gandof_alsa.fw deleted file mode 100644 index 40ac817e..00000000 --- a/alsa-module-config/gandof_alsa.fw +++ /dev/null @@ -1,9 +0,0 @@ -[codec] -0x10ec0283 0x10ec0283 0 - -[model] -alc283-dac-wcaps - -[hint] -auto_mute = no -auto_mic = no diff --git a/alsa-module-config/lulu_alsa.fw b/alsa-module-config/lulu_alsa.fw deleted file mode 100644 index 40ac817e..00000000 --- a/alsa-module-config/lulu_alsa.fw +++ /dev/null @@ -1,9 +0,0 @@ -[codec] -0x10ec0283 0x10ec0283 0 - -[model] -alc283-dac-wcaps - -[hint] -auto_mute = no -auto_mic = no diff --git a/audio_streams/src/audio_streams.rs b/audio_streams/src/audio_streams.rs index c3ba9511..672034b7 100644 --- a/audio_streams/src/audio_streams.rs +++ b/audio_streams/src/audio_streams.rs @@ -53,7 +53,7 @@ pub trait StreamSource: Send { num_channels: usize, frame_rate: usize, buffer_size: usize, - ) -> Result<(Box<dyn StreamControl>, Box<dyn PlaybackBufferStream>), Box<error::Error>>; + ) -> Result<(Box<dyn StreamControl>, Box<dyn PlaybackBufferStream>), Box<dyn error::Error>>; /// Returns a stream control and buffer generator object. These are separate as the buffer /// generator might want to be passed to the audio stream. @@ -68,7 +68,7 @@ pub trait StreamSource: Send { Box<dyn StreamControl>, Box<dyn capture::CaptureBufferStream>, ), - Box<error::Error>, + Box<dyn error::Error>, > { Ok(( Box::new(DummyStreamControl::new()), @@ -89,7 +89,7 @@ pub trait StreamSource: Send { /// `PlaybackBufferStream` provides `PlaybackBuffer`s to fill with audio samples for playback. pub trait PlaybackBufferStream: Send { - fn next_playback_buffer<'a>(&'a mut self) -> Result<PlaybackBuffer<'a>, Box<error::Error>>; + fn next_playback_buffer<'a>(&'a mut self) -> Result<PlaybackBuffer<'a>, Box<dyn error::Error>>; } /// `StreamControl` provides a way to set the volume and mute states of a stream. `StreamControl` @@ -130,7 +130,7 @@ struct AudioBuffer<'a> { buffer: &'a mut [u8], offset: usize, // Read or Write offset in frames. frame_size: usize, // Size of a frame in bytes. - drop: &'a mut BufferDrop, + drop: &'a mut dyn BufferDrop, } /// `PlaybackBuffer` is one buffer that holds buffer_size audio frames. It is used to temporarily @@ -242,7 +242,7 @@ impl DummyStream { } impl PlaybackBufferStream for DummyStream { - fn next_playback_buffer<'a>(&'a mut self) -> Result<PlaybackBuffer<'a>, Box<error::Error>> { + fn next_playback_buffer<'a>(&'a mut self) -> Result<PlaybackBuffer<'a>, Box<dyn error::Error>> { if let Some(start_time) = self.start_time { if start_time.elapsed() < self.next_frame { std::thread::sleep(self.next_frame - start_time.elapsed()); @@ -288,7 +288,8 @@ impl StreamSource for DummyStreamSource { num_channels: usize, frame_rate: usize, buffer_size: usize, - ) -> Result<(Box<dyn StreamControl>, Box<dyn PlaybackBufferStream>), Box<error::Error>> { + ) -> Result<(Box<dyn StreamControl>, Box<dyn PlaybackBufferStream>), Box<dyn error::Error>> + { Ok(( Box::new(DummyStreamControl::new()), Box::new(DummyStream::new(num_channels, frame_rate, buffer_size)), diff --git a/audio_streams/src/capture.rs b/audio_streams/src/capture.rs index 1d9dc08e..0e58dc8a 100644 --- a/audio_streams/src/capture.rs +++ b/audio_streams/src/capture.rs @@ -35,7 +35,7 @@ use super::{AudioBuffer, BufferDrop, DummyBufferDrop}; /// `CaptureBufferStream` provides `CaptureBuffer`s to read with audio samples from capture. pub trait CaptureBufferStream: Send { - fn next_capture_buffer<'a>(&'a mut self) -> Result<CaptureBuffer<'a>, Box<error::Error>>; + fn next_capture_buffer<'a>(&'a mut self) -> Result<CaptureBuffer<'a>, Box<dyn error::Error>>; } /// `CaptureBuffer` contains a block of audio samples got from capture stream. It provides @@ -146,7 +146,7 @@ impl DummyCaptureStream { } impl CaptureBufferStream for DummyCaptureStream { - fn next_capture_buffer(&mut self) -> Result<CaptureBuffer, Box<error::Error>> { + fn next_capture_buffer(&mut self) -> Result<CaptureBuffer, Box<dyn error::Error>> { if let Some(start_time) = self.start_time { if start_time.elapsed() < self.next_frame { std::thread::sleep(self.next_frame - start_time.elapsed()); diff --git a/cras-config/auron/HDA Intel PCH b/cras-config/auron/HDA Intel PCH deleted file mode 100644 index e0adc3e9..00000000 --- a/cras-config/auron/HDA Intel PCH +++ /dev/null @@ -1,107 +0,0 @@ -[Speaker] - volume_curve = explicit - db_at_100 = 0 - db_at_99 = -75 - db_at_98 = -75 - db_at_97 = -75 - db_at_96 = -75 - db_at_95 = -75 - db_at_94 = -150 - db_at_93 = -150 - db_at_92 = -150 - db_at_91 = -150 - db_at_90 = -225 - db_at_89 = -225 - db_at_88 = -225 - db_at_87 = -225 - db_at_86 = -300 - db_at_85 = -300 - db_at_84 = -300 - db_at_83 = -300 - db_at_82 = -375 - db_at_81 = -375 - db_at_80 = -450 - db_at_79 = -450 - db_at_78 = -450 - db_at_77 = -450 - db_at_76 = -525 - db_at_75 = -525 - db_at_74 = -600 - db_at_73 = -600 - db_at_72 = -600 - db_at_71 = -600 - db_at_70 = -675 - db_at_69 = -675 - db_at_68 = -675 - db_at_67 = -675 - db_at_66 = -750 - db_at_65 = -750 - db_at_64 = -825 - db_at_63 = -825 - db_at_62 = -825 - db_at_61 = -825 - db_at_60 = -900 - db_at_59 = -900 - db_at_58 = -900 - db_at_57 = -900 - db_at_56 = -975 - db_at_55 = -975 - db_at_54 = -1050 - db_at_53 = -1050 - db_at_52 = -1050 - db_at_51 = -1050 - db_at_50 = -1125 - db_at_49 = -1125 - db_at_48 = -1200 - db_at_47 = -1200 - db_at_46 = -1200 - db_at_45 = -1200 - db_at_44 = -1275 - db_at_43 = -1275 - db_at_42 = -1275 - db_at_41 = -1275 - db_at_40 = -1350 - db_at_39 = -1425 - db_at_38 = -1425 - db_at_37 = -1500 - db_at_36 = -1500 - db_at_35 = -1575 - db_at_34 = -1650 - db_at_33 = -1650 - db_at_32 = -1725 - db_at_31 = -1800 - db_at_30 = -1800 - db_at_29 = -1800 - db_at_28 = -1875 - db_at_27 = -2025 - db_at_26 = -2100 - db_at_25 = -2100 - db_at_24 = -2175 - db_at_23 = -2250 - db_at_22 = -2400 - db_at_21 = -2475 - db_at_20 = -2550 - db_at_19 = -2625 - db_at_18 = -2700 - db_at_17 = -2850 - db_at_16 = -2925 - db_at_15 = -3000 - db_at_14 = -3075 - db_at_13 = -3225 - db_at_12 = -3300 - db_at_11 = -3375 - db_at_10 = -3450 - db_at_9 = -3600 - db_at_8 = -3675 - db_at_7 = -3750 - db_at_6 = -3825 - db_at_5 = -3900 - db_at_4 = -4050 - db_at_3 = -4050 - db_at_2 = -4275 - db_at_1 = -4500 - db_at_0 = -4800 -[Headphone] - volume_curve = simple_step - volume_step = 50 - max_volume = 0 diff --git a/cras-config/auron/dsp.ini b/cras-config/auron/dsp.ini deleted file mode 100644 index e229b199..00000000 --- a/cras-config/auron/dsp.ini +++ /dev/null @@ -1,119 +0,0 @@ -[output_source] -library=builtin -label=source -purpose=playback -disable=(not (equal? dsp_name "speaker_eq")) -output_0={src:0} -output_1={src:1} - -[output_sink] -library=builtin -label=sink -purpose=playback -input_0={dst:0} -input_1={dst:1} - -[drc] -library=builtin -label=drc -input_0={src:0} -input_1={src:1} -output_2={intermediate:0} -output_3={intermediate:1} -input_4=0 ; emphasis_disabled -input_5=0 ; f -input_6=1 ; enable -input_7=-30 ; threshold -input_8=24 ; knee -input_9=6.032 ; ratio -input_10=0.02 ; attack -input_11=0.25 ; release -input_12=2 ; boost -input_13=326 ; f -input_14=1 ; enable -input_15=-27 ; threshold -input_16=23 ; knee -input_17=5.634 ; ratio -input_18=0.003 ; attack -input_19=0.25 ; release -input_20=2 ; boost -input_21=1842 ; f -input_22=1 ; enable -input_23=-40 ; threshold -input_24=37 ; knee -input_25=5.67 ; ratio -input_26=0.003 ; attack -input_27=0.25 ; release -input_28=3 ; boost - -[eq2] -library=builtin -label=eq2 -input_0={intermediate:0} -input_1={intermediate:1} -output_2={dst:0} -output_3={dst:1} -input_4=6 ; peaking -input_5=248 ; freq -input_6=4.8668 ; Q -input_7=-7.8 ; gain -input_8=6 ; peaking -input_9=688 ; freq -input_10=2.6911 ; Q -input_11=-3.9 ; gain -input_12=6 ; peaking -input_13=410 ; freq -input_14=8.5 ; Q -input_15=-7.3 ; gain -input_16=6 ; peaking -input_17=817 ; freq -input_18=4.1703 ; Q -input_19=-15 ; gain -input_20=6 ; peaking -input_21=5112 ; freq -input_22=3.957 ; Q -input_23=-4.4 ; gain -input_24=6 ; peaking -input_25=4827 ; freq -input_26=3.3685 ; Q -input_27=-6.3 ; gain -input_28=6 ; peaking -input_29=819 ; freq -input_30=2.2529 ; Q -input_31=-14.1 ; gain -input_32=6 ; peaking -input_33=4065 ; freq -input_34=2.5388 ; Q -input_35=3 ; gain -input_36=6 ; peaking -input_37=4065 ; freq -input_38=5.9436 ; Q -input_39=3 ; gain -input_40=6 ; peaking -input_41=2292 ; freq -input_42=2.6 ; Q -input_43=1.5 ; gain -input_44=6 ; peaking -input_45=2292 ; freq -input_46=2.6911 ; Q -input_47=1.5 ; gain -input_48=5 ; highshelf -input_49=8960 ; freq -input_50=2.1187 ; Q -input_51=2.6 ; gain -input_52=2 ; highpass -input_53=293 ; freq -input_54=1.0465 ; Q -input_55=0 ; gain -input_56=2 ; highpass -input_57=343 ; freq -input_58=1.4222 ; Q -input_59=0 ; gain -input_60=5 ; highshelf -input_61=8960 ; freq -input_62=1 ; Q -input_63=2.6 ; gain -input_64=0 ; none -input_65=0 ; freq -input_66=0 ; Q -input_67=0 ; gain diff --git a/cras-config/auron_paine/HDA Intel PCH b/cras-config/auron_paine/HDA Intel PCH deleted file mode 100644 index d2ae47c0..00000000 --- a/cras-config/auron_paine/HDA Intel PCH +++ /dev/null @@ -1,107 +0,0 @@ -[Speaker] - volume_curve = explicit - db_at_100 = 0 - db_at_99 = 0 - db_at_98 = 0 - db_at_97 = -75 - db_at_96 = -75 - db_at_95 = -75 - db_at_94 = -75 - db_at_93 = -150 - db_at_92 = -150 - db_at_91 = -150 - db_at_90 = -150 - db_at_89 = -225 - db_at_88 = -225 - db_at_87 = -225 - db_at_86 = -225 - db_at_85 = -300 - db_at_84 = -300 - db_at_83 = -300 - db_at_82 = -300 - db_at_81 = -375 - db_at_80 = -375 - db_at_79 = -375 - db_at_78 = -375 - db_at_77 = -450 - db_at_76 = -450 - db_at_75 = -450 - db_at_74 = -450 - db_at_73 = -525 - db_at_72 = -525 - db_at_71 = -525 - db_at_70 = -525 - db_at_69 = -600 - db_at_68 = -600 - db_at_67 = -600 - db_at_66 = -600 - db_at_65 = -675 - db_at_64 = -675 - db_at_63 = -675 - db_at_62 = -675 - db_at_61 = -750 - db_at_60 = -750 - db_at_59 = -750 - db_at_58 = -750 - db_at_57 = -825 - db_at_56 = -825 - db_at_55 = -825 - db_at_54 = -900 - db_at_53 = -900 - db_at_52 = -975 - db_at_51 = -975 - db_at_50 = -975 - db_at_49 = -1050 - db_at_48 = -1050 - db_at_47 = -1050 - db_at_46 = -1050 - db_at_45 = -1125 - db_at_44 = -1125 - db_at_43 = -1125 - db_at_42 = -1125 - db_at_41 = -1200 - db_at_40 = -1200 - db_at_39 = -1275 - db_at_38 = -1275 - db_at_37 = -1350 - db_at_36 = -1425 - db_at_35 = -1425 - db_at_34 = -1425 - db_at_33 = -1500 - db_at_32 = -1500 - db_at_31 = -1575 - db_at_30 = -1650 - db_at_29 = -1800 - db_at_28 = -1875 - db_at_27 = -1875 - db_at_26 = -1950 - db_at_25 = -1950 - db_at_24 = -2025 - db_at_23 = -2175 - db_at_22 = -2250 - db_at_21 = -2400 - db_at_20 = -2550 - db_at_19 = -2625 - db_at_18 = -2700 - db_at_17 = -2850 - db_at_16 = -2925 - db_at_15 = -2925 - db_at_14 = -2925 - db_at_13 = -3000 - db_at_12 = -3000 - db_at_11 = -3075 - db_at_10 = -3225 - db_at_9 = -3300 - db_at_8 = -3450 - db_at_7 = -3525 - db_at_6 = -3600 - db_at_5 = -3750 - db_at_4 = -3825 - db_at_3 = -3900 - db_at_2 = -3975 - db_at_1 = -4125 - db_at_0 = -4200 -[Headphone] - volume_curve = simple_step - volume_step = 40 - max_volume = 0 diff --git a/cras-config/auron_paine/dsp.ini b/cras-config/auron_paine/dsp.ini deleted file mode 100644 index 2cf5a1ec..00000000 --- a/cras-config/auron_paine/dsp.ini +++ /dev/null @@ -1,143 +0,0 @@ -[output_source] -library=builtin -label=source -purpose=playback -disable=(not (equal? dsp_name "speaker_eq")) -output_0={src:0} -output_1={src:1} - -[output_sink] -library=builtin -label=sink -purpose=playback -input_0={dst:0} -input_1={dst:1} - -[drc] -library=builtin -label=drc -input_0={src:0} -input_1={src:1} -output_2={intermediate:0} -output_3={intermediate:1} -input_4=1 ; emphasis_disabled -input_5=0 ; f -input_6=1 ; enable -input_7=-30 ; threshold -input_8=24 ; knee -input_9=6.032 ; ratio -input_10=0.02 ; attack -input_11=0.25 ; release -input_12=2 ; boost -input_13=326 ; f -input_14=1 ; enable -input_15=-27 ; threshold -input_16=23 ; knee -input_17=5.634 ; ratio -input_18=0.003 ; attack -input_19=0.25 ; release -input_20=2 ; boost -input_21=1842 ; f -input_22=1 ; enable -input_23=-40 ; threshold -input_24=37 ; knee -input_25=5.67 ; ratio -input_26=0.003 ; attack -input_27=0.25 ; release -input_28=3 ; boost - -[eq2] -library=builtin -label=eq2 -input_0={intermediate:0} -input_1={intermediate:1} -output_2={dst:0} -output_3={dst:1} -input_4=6 ; peaking -input_5=248 ; freq -input_6=4.8668 ; Q -input_7=-7.8 ; gain -input_8=6 ; peaking -input_9=688 ; freq -input_10=2.6911 ; Q -input_11=-3.9 ; gain -input_12=6 ; peaking -input_13=410 ; freq -input_14=8.5 ; Q -input_15=-7.3 ; gain -input_16=6 ; peaking -input_17=817 ; freq -input_18=4.1703 ; Q -input_19=-15 ; gain -input_20=6 ; peaking -input_21=5112 ; freq -input_22=3.957 ; Q -input_23=-4.4 ; gain -input_24=6 ; peaking -input_25=4827 ; freq -input_26=3.3685 ; Q -input_27=-6.3 ; gain -input_28=6 ; peaking -input_29=819 ; freq -input_30=2.2529 ; Q -input_31=-14.1 ; gain -input_32=6 ; peaking -input_33=4065 ; freq -input_34=2.5388 ; Q -input_35=3 ; gain -input_36=6 ; peaking -input_37=4065 ; freq -input_38=5.9436 ; Q -input_39=3 ; gain -input_40=6 ; peaking -input_41=2292 ; freq -input_42=2.6 ; Q -input_43=1.5 ; gain -input_44=6 ; peaking -input_45=2292 ; freq -input_46=2.6911 ; Q -input_47=1.5 ; gain -input_48=5 ; highshelf -input_49=8960 ; freq -input_50=2.1187 ; Q -input_51=2.6 ; gain -input_52=2 ; highpass -input_53=293 ; freq -input_54=1.0465 ; Q -input_55=0 ; gain -input_56=2 ; highpass -input_57=343 ; freq -input_58=1.4222 ; Q -input_59=0 ; gain -input_60=5 ; highshelf -input_61=8960 ; freq -input_62=1 ; Q -input_63=2.6 ; gain -input_64=0 ; none -input_65=0 ; freq -input_66=0 ; Q -input_67=0 ; gain - -[input_source] -library=builtin -label=source -purpose=capture -disable=(not (equal? dsp_name "dmic_eq")) -output_0={in_src:0} -output_1={in_src:1} - -[input_sink] -library=builtin -label=sink -purpose=capture -input_0={in_dst:0} -input_1={in_dst:1} - -[in_dcblock] -library=builtin -label=dcblock -input_0={in_src:0} -input_1={in_src:1} -output_2={in_dst:0} -output_3={in_dst:1} -input_4=0.995 ; R - lone filter parameter diff --git a/cras-config/auron_yuna/HDA Intel PCH b/cras-config/auron_yuna/HDA Intel PCH deleted file mode 100644 index d7a71e95..00000000 --- a/cras-config/auron_yuna/HDA Intel PCH +++ /dev/null @@ -1,107 +0,0 @@ -[Speaker] - volume_curve = explicit - db_at_100 = 0 - db_at_99 = 0 - db_at_98 = 0 - db_at_97 = -75 - db_at_96 = -75 - db_at_95 = -75 - db_at_94 = -75 - db_at_93 = -150 - db_at_92 = -150 - db_at_91 = -150 - db_at_90 = -150 - db_at_89 = -225 - db_at_88 = -225 - db_at_87 = -225 - db_at_86 = -225 - db_at_85 = -300 - db_at_84 = -300 - db_at_83 = -300 - db_at_82 = -300 - db_at_81 = -375 - db_at_80 = -375 - db_at_79 = -375 - db_at_78 = -375 - db_at_77 = -450 - db_at_76 = -450 - db_at_75 = -450 - db_at_74 = -450 - db_at_73 = -450 - db_at_72 = -525 - db_at_71 = -525 - db_at_70 = -525 - db_at_69 = -600 - db_at_68 = -600 - db_at_67 = -600 - db_at_66 = -600 - db_at_65 = -675 - db_at_64 = -675 - db_at_63 = -675 - db_at_62 = -675 - db_at_61 = -750 - db_at_60 = -750 - db_at_59 = -750 - db_at_58 = -750 - db_at_57 = -825 - db_at_56 = -825 - db_at_55 = -825 - db_at_54 = -900 - db_at_53 = -900 - db_at_52 = -975 - db_at_51 = -975 - db_at_50 = -975 - db_at_49 = -1050 - db_at_48 = -1050 - db_at_47 = -1050 - db_at_46 = -1050 - db_at_45 = -1125 - db_at_44 = -1125 - db_at_43 = -1125 - db_at_42 = -1125 - db_at_41 = -1200 - db_at_40 = -1200 - db_at_39 = -1275 - db_at_38 = -1275 - db_at_37 = -1350 - db_at_36 = -1425 - db_at_35 = -1425 - db_at_34 = -1425 - db_at_33 = -1500 - db_at_32 = -1500 - db_at_31 = -1575 - db_at_30 = -1650 - db_at_29 = -1800 - db_at_28 = -1875 - db_at_27 = -1875 - db_at_26 = -1950 - db_at_25 = -1950 - db_at_24 = -2025 - db_at_23 = -2175 - db_at_22 = -2250 - db_at_21 = -2400 - db_at_20 = -2550 - db_at_19 = -2625 - db_at_18 = -2700 - db_at_17 = -2850 - db_at_16 = -2925 - db_at_15 = -2925 - db_at_14 = -2925 - db_at_13 = -3000 - db_at_12 = -3000 - db_at_11 = -3075 - db_at_10 = -3225 - db_at_9 = -3300 - db_at_8 = -3450 - db_at_7 = -3600 - db_at_6 = -3750 - db_at_5 = -3900 - db_at_4 = -4050 - db_at_3 = -4200 - db_at_2 = -4350 - db_at_1 = -4500 - db_at_0 = -4650 -[Headphone] - volume_curve = simple_step - volume_step = 40 - max_volume = 0 diff --git a/cras-config/auron_yuna/dsp.ini b/cras-config/auron_yuna/dsp.ini deleted file mode 100644 index 17f53503..00000000 --- a/cras-config/auron_yuna/dsp.ini +++ /dev/null @@ -1,119 +0,0 @@ -[output_source] -library=builtin -label=source -purpose=playback -disable=(not (equal? dsp_name "speaker_eq")) -output_0={src:0} -output_1={src:1} - -[output_sink] -library=builtin -label=sink -purpose=playback -input_0={dst:0} -input_1={dst:1} - -[drc] -library=builtin -label=drc -input_0={src:0} -input_1={src:1} -output_2={intermediate:0} -output_3={intermediate:1} -input_4=1 ; emphasis_disabled -input_5=0 ; f -input_6=1 ; enable -input_7=-24 ; threshold -input_8=20 ; knee -input_9=7.8 ; ratio -input_10=0.003 ; attack -input_11=0.915 ; release -input_12=2 ; boost -input_13=450 ; f -input_14=1 ; enable -input_15=-23 ; threshold -input_16=24 ; knee -input_17=11 ; ratio -input_18=0.003 ; attack -input_19=0.25 ; release -input_20=1.5 ; boost -input_21=2000 ; f -input_22=1 ; enable -input_23=-23 ; threshold -input_24=25 ; knee -input_25=12 ; ratio -input_26=0.003 ; attack -input_27=0.25 ; release -input_28=1.5 ; boost - -[eq2] -library=builtin -label=eq2 -input_0={intermediate:0} -input_1={intermediate:1} -output_2={dst:0} -output_3={dst:1} -input_4=2 ; highpass -input_5=150 ; freq -input_6=0 ; Q -input_7=0 ; gain -input_8=2 ; highpass -input_9=150 ; freq -input_10=0 ; Q -input_11=0 ; gain -input_12=6 ; peaking -input_13=285 ; freq -input_14=2.8 ; Q -input_15=-3.5 ; gain -input_16=6 ; peaking -input_17=300 ; freq -input_18=2.8 ; Q -input_19=-3.5 ; gain -input_20=6 ; peaking -input_21=600 ; freq -input_22=3 ; Q -input_23=-4 ; gain -input_24=6 ; peaking -input_25=600 ; freq -input_26=3 ; Q -input_27=-4 ; gain -input_28=6 ; peaking -input_29=4000 ; freq -input_30=3 ; Q -input_31=-5 ; gain -input_32=6 ; peaking -input_33=4000 ; freq -input_34=3 ; Q -input_35=-5 ; gain -input_36=6 ; peaking -input_37=960 ; freq -input_38=4 ; Q -input_39=3 ; gain -input_40=6 ; peaking -input_41=960 ; freq -input_42=4 ; Q -input_43=3 ; gain -input_44=6 ; peaking -input_45=7800 ; freq -input_46=2 ; Q -input_47=-6 ; gain -input_48=6 ; peaking -input_49=7800 ; freq -input_50=2 ; Q -input_51=-6 ; gain -input_52=6 ; peaking -input_53=1720 ; freq -input_54=4 ; Q -input_55=-5 ; gain -input_56=6 ; peaking -input_57=1720 ; freq -input_58=4 ; Q -input_59=-5 ; gain -input_60=6 ; peaking -input_61=16000 ; freq -input_62=3 ; Q -input_63=2 ; gain -input_64=6 ; peaking -input_65=16000 ; freq -input_66=3 ; Q -input_67=2 ; gain diff --git a/cras-config/cyan/cht-bsw-max98090 b/cras-config/cyan/cht-bsw-max98090 deleted file mode 100644 index fba7d1b9..00000000 --- a/cras-config/cyan/cht-bsw-max98090 +++ /dev/null @@ -1,107 +0,0 @@ -[Speaker] - volume_curve = explicit - db_at_100 = -200 - db_at_99 = -200 - db_at_98 = -250 - db_at_97 = -250 - db_at_96 = -300 - db_at_95 = -300 - db_at_94 = -350 - db_at_93 = -350 - db_at_92 = -400 - db_at_91 = -400 - db_at_90 = -400 - db_at_89 = -450 - db_at_88 = -450 - db_at_87 = -450 - db_at_86 = -450 - db_at_85 = -500 - db_at_84 = -500 - db_at_83 = -500 - db_at_82 = -550 - db_at_81 = -550 - db_at_80 = -600 - db_at_79 = -600 - db_at_78 = -650 - db_at_77 = -650 - db_at_76 = -700 - db_at_75 = -700 - db_at_74 = -750 - db_at_73 = -750 - db_at_72 = -800 - db_at_71 = -800 - db_at_70 = -850 - db_at_69 = -850 - db_at_68 = -900 - db_at_67 = -900 - db_at_66 = -950 - db_at_65 = -950 - db_at_64 = -1000 - db_at_63 = -1000 - db_at_62 = -1050 - db_at_61 = -1050 - db_at_60 = -1100 - db_at_59 = -1100 - db_at_58 = -1150 - db_at_57 = -1150 - db_at_56 = -1200 - db_at_55 = -1200 - db_at_54 = -1250 - db_at_53 = -1250 - db_at_52 = -1300 - db_at_51 = -1300 - db_at_50 = -1350 - db_at_49 = -1350 - db_at_48 = -1400 - db_at_47 = -1400 - db_at_46 = -1450 - db_at_45 = -1450 - db_at_44 = -1500 - db_at_43 = -1550 - db_at_42 = -1600 - db_at_41 = -1650 - db_at_40 = -1700 - db_at_39 = -1750 - db_at_38 = -1850 - db_at_37 = -1900 - db_at_36 = -2000 - db_at_35 = -2100 - db_at_34 = -2200 - db_at_33 = -2300 - db_at_32 = -2400 - db_at_31 = -2450 - db_at_30 = -2500 - db_at_29 = -2550 - db_at_28 = -2600 - db_at_27 = -2650 - db_at_26 = -2700 - db_at_25 = -2750 - db_at_24 = -2800 - db_at_23 = -2850 - db_at_22 = -2950 - db_at_21 = -3000 - db_at_20 = -3100 - db_at_19 = -3150 - db_at_18 = -3250 - db_at_17 = -3300 - db_at_16 = -3400 - db_at_15 = -3450 - db_at_14 = -3550 - db_at_13 = -3600 - db_at_12 = -3700 - db_at_11 = -3750 - db_at_10 = -3850 - db_at_9 = -3900 - db_at_8 = -4000 - db_at_7 = -4050 - db_at_6 = -4150 - db_at_5 = -4200 - db_at_4 = -4300 - db_at_3 = -4350 - db_at_2 = -4450 - db_at_1 = -4500 - db_at_0 = -4600 -[Headphone] - volume_curve = simple_step - volume_step = 70 - max_volume = 0 diff --git a/cras-config/cyan/chtmax98090 b/cras-config/cyan/chtmax98090 deleted file mode 100644 index e121f1dd..00000000 --- a/cras-config/cyan/chtmax98090 +++ /dev/null @@ -1,107 +0,0 @@ -[Speaker]
- volume_curve = explicit
- db_at_100 = -200
- db_at_99 = -200
- db_at_98 = -250
- db_at_97 = -250
- db_at_96 = -300
- db_at_95 = -300
- db_at_94 = -350
- db_at_93 = -350
- db_at_92 = -400
- db_at_91 = -400
- db_at_90 = -400
- db_at_89 = -450
- db_at_88 = -450
- db_at_87 = -450
- db_at_86 = -450
- db_at_85 = -500
- db_at_84 = -500
- db_at_83 = -500
- db_at_82 = -550
- db_at_81 = -550
- db_at_80 = -600
- db_at_79 = -600
- db_at_78 = -650
- db_at_77 = -650
- db_at_76 = -700
- db_at_75 = -700
- db_at_74 = -750
- db_at_73 = -750
- db_at_72 = -800
- db_at_71 = -800
- db_at_70 = -850
- db_at_69 = -850
- db_at_68 = -900
- db_at_67 = -900
- db_at_66 = -950
- db_at_65 = -950
- db_at_64 = -1000
- db_at_63 = -1000
- db_at_62 = -1050
- db_at_61 = -1050
- db_at_60 = -1100
- db_at_59 = -1100
- db_at_58 = -1150
- db_at_57 = -1150
- db_at_56 = -1200
- db_at_55 = -1200
- db_at_54 = -1250
- db_at_53 = -1250
- db_at_52 = -1300
- db_at_51 = -1300
- db_at_50 = -1350
- db_at_49 = -1350
- db_at_48 = -1400
- db_at_47 = -1400
- db_at_46 = -1450
- db_at_45 = -1450
- db_at_44 = -1500
- db_at_43 = -1550
- db_at_42 = -1600
- db_at_41 = -1650
- db_at_40 = -1700
- db_at_39 = -1750
- db_at_38 = -1850
- db_at_37 = -1900
- db_at_36 = -2000
- db_at_35 = -2100
- db_at_34 = -2200
- db_at_33 = -2300
- db_at_32 = -2400
- db_at_31 = -2450
- db_at_30 = -2500
- db_at_29 = -2550
- db_at_28 = -2600
- db_at_27 = -2650
- db_at_26 = -2700
- db_at_25 = -2750
- db_at_24 = -2800
- db_at_23 = -2850
- db_at_22 = -2950
- db_at_21 = -3000
- db_at_20 = -3100
- db_at_19 = -3150
- db_at_18 = -3250
- db_at_17 = -3300
- db_at_16 = -3400
- db_at_15 = -3450
- db_at_14 = -3550
- db_at_13 = -3600
- db_at_12 = -3700
- db_at_11 = -3750
- db_at_10 = -3850
- db_at_9 = -3900
- db_at_8 = -4000
- db_at_7 = -4050
- db_at_6 = -4150
- db_at_5 = -4200
- db_at_4 = -4300
- db_at_3 = -4350
- db_at_2 = -4450
- db_at_1 = -4500
- db_at_0 = -4600
-[Headphone]
- volume_curve = simple_step
- volume_step = 70
- max_volume = 0
diff --git a/cras-config/cyan/dsp.ini b/cras-config/cyan/dsp.ini deleted file mode 100644 index 5f9a3490..00000000 --- a/cras-config/cyan/dsp.ini +++ /dev/null @@ -1,111 +0,0 @@ -[output_source] -library=builtin -label=source -purpose=playback -disable=(not (equal? dsp_name "speaker_eq")) -output_0={src:0} -output_1={src:1} - -[output_sink] -library=builtin -label=sink -purpose=playback -input_0={dst:0} -input_1={dst:1} - -[drc] -library=builtin -label=drc -input_0={src:0} -input_1={src:1} -output_2={intermediate:0} -output_3={intermediate:1} -input_4=1 ; emphasis_disabled -input_5=0 ; f -input_6=1 ; enable -input_7=-27 ; threshold -input_8=31 ; knee -input_9=15.018 ; ratio -input_10=0.003 ; attack -input_11=0.25 ; release -input_12=1.5 ; boost -input_13=250 ; f -input_14=1 ; enable -input_15=-32 ; threshold -input_16=34 ; knee -input_17=12.817 ; ratio -input_18=0.003 ; attack -input_19=0.25 ; release -input_20=2 ; boost -input_21=1800 ; f -input_22=1 ; enable -input_23=-38 ; threshold -input_24=37 ; knee -input_25=9.921 ; ratio -input_26=0.003 ; attack -input_27=0.25 ; release -input_28=2.5 ; boost - -[eq2] -library=builtin -label=eq2 -input_0={intermediate:0} -input_1={intermediate:1} -output_2={dst:0} -output_3={dst:1} -input_4=2 ; highpass -input_5=250 ; freq -input_6=0 ; Q -input_7=-8.8 ; gain -input_8=2 ; highpass -input_9=250 ; freq -input_10=0 ; Q -input_11=-8.3 ; gain -input_12=6 ; peaking -input_13=649 ; freq -input_14=2.5 ; Q -input_15=-8.8 ; gain -input_16=6 ; peaking -input_17=649 ; freq -input_18=2.5 ; Q -input_19=-8.8 ; gain -input_20=6 ; peaking -input_21=1200 ; freq -input_22=3.5 ; Q -input_23=2.4 ; gain -input_24=6 ; peaking -input_25=1200 ; freq -input_26=3.5 ; Q -input_27=2.4 ; gain -input_28=6 ; peaking -input_29=10000 ; freq -input_30=4.5 ; Q -input_31=4.5 ; gain -input_32=6 ; peaking -input_33=10000 ; freq -input_34=4.5 ; Q -input_35=4.5 ; gain -input_36=6 ; peaking -input_37=6070 ; freq -input_38=3.8 ; Q -input_39=3.5 ; gain -input_40=6 ; peaking -input_41=6070 ; freq -input_42=3.8 ; Q -input_43=3 ; gain -input_44=5 ; highshelf -input_45=8083 ; freq -input_46=1 ; Q -input_47=3.5 ; gain -input_48=5 ; highshelf -input_49=8083 ; freq -input_50=1 ; Q -input_51=3.5 ; gain -input_52=6 ; peaking -input_53=3232 ; freq -input_54=3.3685 ; Q -input_55=-7.3 ; gain -input_56=6 ; peaking -input_57=3232 ; freq -input_58=3.3685 ; Q -input_59=-7.3 ; gain diff --git a/cras-config/gandof/HDA Intel PCH b/cras-config/gandof/HDA Intel PCH deleted file mode 100644 index 900fc1eb..00000000 --- a/cras-config/gandof/HDA Intel PCH +++ /dev/null @@ -1,107 +0,0 @@ -[Speaker] - volume_curve = explicit - db_at_100 = -125 - db_at_99 = -125 - db_at_98 = -175 - db_at_97 = -175 - db_at_96 = -200 - db_at_95 = -200 - db_at_94 = -225 - db_at_93 = -225 - db_at_92 = -275 - db_at_91 = -300 - db_at_90 = -325 - db_at_89 = -350 - db_at_88 = -400 - db_at_87 = -425 - db_at_86 = -450 - db_at_85 = -475 - db_at_84 = -525 - db_at_83 = -550 - db_at_82 = -575 - db_at_81 = -600 - db_at_80 = -650 - db_at_79 = -675 - db_at_78 = -700 - db_at_77 = -725 - db_at_76 = -775 - db_at_75 = -800 - db_at_74 = -825 - db_at_73 = -850 - db_at_72 = -900 - db_at_71 = -925 - db_at_70 = -950 - db_at_69 = -975 - db_at_68 = -1025 - db_at_67 = -1075 - db_at_66 = -1125 - db_at_65 = -1175 - db_at_64 = -1200 - db_at_63 = -1250 - db_at_62 = -1300 - db_at_61 = -1350 - db_at_60 = -1400 - db_at_59 = -1450 - db_at_58 = -1500 - db_at_57 = -1550 - db_at_56 = -1600 - db_at_55 = -1650 - db_at_54 = -1700 - db_at_53 = -1750 - db_at_52 = -1800 - db_at_51 = -1850 - db_at_50 = -1900 - db_at_49 = -1950 - db_at_48 = -2000 - db_at_47 = -2050 - db_at_46 = -2100 - db_at_45 = -2150 - db_at_44 = -2200 - db_at_43 = -2250 - db_at_42 = -2300 - db_at_41 = -2350 - db_at_40 = -2400 - db_at_39 = -2450 - db_at_38 = -2500 - db_at_37 = -2550 - db_at_36 = -2600 - db_at_35 = -2650 - db_at_34 = -2700 - db_at_33 = -2800 - db_at_32 = -2850 - db_at_31 = -2900 - db_at_30 = -2950 - db_at_29 = -3000 - db_at_28 = -3100 - db_at_27 = -3150 - db_at_26 = -3250 - db_at_25 = -3300 - db_at_24 = -3400 - db_at_23 = -3450 - db_at_22 = -3550 - db_at_21 = -3600 - db_at_20 = -3700 - db_at_19 = -3750 - db_at_18 = -3850 - db_at_17 = -3900 - db_at_16 = -4000 - db_at_15 = -4050 - db_at_14 = -4150 - db_at_13 = -4200 - db_at_12 = -4300 - db_at_11 = -4350 - db_at_10 = -4450 - db_at_9 = -4500 - db_at_8 = -4600 - db_at_7 = -4700 - db_at_6 = -4800 - db_at_5 = -4900 - db_at_4 = -5000 - db_at_3 = -5100 - db_at_2 = -5200 - db_at_1 = -5300 - db_at_0 = -5400 -[Headphone] - volume_curve = simple_step - volume_step = 70 - max_volume = 0 diff --git a/cras-config/gandof/dsp.ini b/cras-config/gandof/dsp.ini deleted file mode 100644 index 6853c4d4..00000000 --- a/cras-config/gandof/dsp.ini +++ /dev/null @@ -1,71 +0,0 @@ -[output_source] -library=builtin -label=source -purpose=playback -disable=(not (equal? dsp_name "speaker_eq")) -output_0={src:0} -output_1={src:1} - -[output_sink] -library=builtin -label=sink -purpose=playback -input_0={dst:0} -input_1={dst:1} - -[drc] -library=builtin -label=drc -input_0={src:0} -input_1={src:1} -output_2={intermediate:0} -output_3={intermediate:1} -input_4=1 ; emphasis_disabled -input_5=0 ; f -input_6=1 ; enable -input_7=-24 ; threshold -input_8=30 ; knee -input_9=8 ; ratio -input_10=0.003 ; attack -input_11=0.25 ; release -input_12=5 ; boost -input_13=250 ; f -input_14=1 ; enable -input_15=-24 ; threshold -input_16=30 ; knee -input_17=12 ; ratio -input_18=0.003 ; attack -input_19=0.25 ; release -input_20=-2 ; boost -input_21=2000 ; f -input_22=1 ; enable -input_23=-24 ; threshold -input_24=30 ; knee -input_25=12 ; ratio -input_26=0.003 ; attack -input_27=0.25 ; release -input_28=3 ; boost - -[eq2] -library=builtin -label=eq2 -input_0={intermediate:0} -input_1={intermediate:1} -output_2={dst:0} -output_3={dst:1} -input_4=2 ; highpass -input_5=275 ; freq -input_6=2 ; Q -input_7=-10.7 ; gain -input_8=2 ; highpass -input_9=275 ; freq -input_10=2 ; Q -input_11=-40 ; gain -input_12=6 ; peaking -input_13=3500 ; freq -input_14=1 ; Q -input_15=-2 ; gain -input_16=6 ; peaking -input_17=3500 ; freq -input_18=1 ; Q -input_19=-2 ; gain diff --git a/cras-config/lulu/HDA Intel PCH b/cras-config/lulu/HDA Intel PCH deleted file mode 100644 index 52f775f8..00000000 --- a/cras-config/lulu/HDA Intel PCH +++ /dev/null @@ -1,107 +0,0 @@ -[Speaker] - volume_curve = explicit - db_at_100 = 0 - db_at_99 = 0 - db_at_98 = 0 - db_at_97 = -75 - db_at_96 = -75 - db_at_95 = -75 - db_at_94 = -75 - db_at_93 = -150 - db_at_92 = -150 - db_at_91 = -150 - db_at_90 = -150 - db_at_89 = -225 - db_at_88 = -225 - db_at_87 = -225 - db_at_86 = -225 - db_at_85 = -300 - db_at_84 = -300 - db_at_83 = -300 - db_at_82 = -375 - db_at_81 = -375 - db_at_80 = -450 - db_at_79 = -450 - db_at_78 = -525 - db_at_77 = -525 - db_at_76 = -600 - db_at_75 = -600 - db_at_74 = -675 - db_at_73 = -675 - db_at_72 = -750 - db_at_71 = -750 - db_at_70 = -825 - db_at_69 = -825 - db_at_68 = -900 - db_at_67 = -900 - db_at_66 = -975 - db_at_65 = -975 - db_at_64 = -1050 - db_at_63 = -1050 - db_at_62 = -1125 - db_at_61 = -1125 - db_at_60 = -1200 - db_at_59 = -1200 - db_at_58 = -1275 - db_at_57 = -1275 - db_at_56 = -1350 - db_at_55 = -1350 - db_at_54 = -1425 - db_at_53 = -1425 - db_at_52 = -1500 - db_at_51 = -1500 - db_at_50 = -1575 - db_at_49 = -1575 - db_at_48 = -1650 - db_at_47 = -1650 - db_at_46 = -1725 - db_at_45 = -1725 - db_at_44 = -1800 - db_at_43 = -1875 - db_at_42 = -1950 - db_at_41 = -2025 - db_at_40 = -2100 - db_at_39 = -2175 - db_at_38 = -2250 - db_at_37 = -2250 - db_at_36 = -2325 - db_at_35 = -2400 - db_at_34 = -2475 - db_at_33 = -2475 - db_at_32 = -2550 - db_at_31 = -2625 - db_at_30 = -2700 - db_at_29 = -2775 - db_at_28 = -2850 - db_at_27 = -2925 - db_at_26 = -3000 - db_at_25 = -3075 - db_at_24 = -3150 - db_at_23 = -3225 - db_at_22 = -3375 - db_at_21 = -3450 - db_at_20 = -3600 - db_at_19 = -3675 - db_at_18 = -3750 - db_at_17 = -3825 - db_at_16 = -3900 - db_at_15 = -3975 - db_at_14 = -4050 - db_at_13 = -4125 - db_at_12 = -4200 - db_at_11 = -4275 - db_at_10 = -4350 - db_at_9 = -4425 - db_at_8 = -4500 - db_at_7 = -4650 - db_at_6 = -4875 - db_at_5 = -5025 - db_at_4 = -5250 - db_at_3 = -5550 - db_at_2 = -5850 - db_at_1 = -6225 - db_at_0 = -6525 -[Headphone] - volume_curve = simple_step - volume_step = 70 - max_volume = 0 diff --git a/cras-config/lulu/dsp.ini b/cras-config/lulu/dsp.ini deleted file mode 100644 index 2e445c83..00000000 --- a/cras-config/lulu/dsp.ini +++ /dev/null @@ -1,95 +0,0 @@ -[output_source] -library=builtin -label=source -purpose=playback -disable=(not (equal? dsp_name "speaker_eq")) -output_0={src:0} -output_1={src:1} - -[output_sink] -library=builtin -label=sink -purpose=playback -input_0={dst:0} -input_1={dst:1} - -[eq2] -library=builtin -label=eq2 -input_0={src:0} -input_1={src:1} -output_2={intermediate:0} -output_3={intermediate:1} -input_4=2 ; highpass -input_5=160 ; freq -input_6=-4 ; Q -input_7=0 ; gain -input_8=2 ; highpass -input_9=160 ; freq -input_10=-4 ; Q -input_11=0 ; gain -input_12=6 ; peaking -input_13=500 ; freq -input_14=4 ; Q -input_15=-5 ; gain -input_16=6 ; peaking -input_17=500 ; freq -input_18=4 ; Q -input_19=-4 ; gain -input_20=6 ; peaking -input_21=700 ; freq -input_22=3.7526 ; Q -input_23=-6 ; gain -input_24=6 ; peaking -input_25=700 ; freq -input_26=3 ; Q -input_27=-5 ; gain -input_28=6 ; peaking -input_29=4750 ; freq -input_30=1 ; Q -input_31=-5 ; gain -input_32=6 ; peaking -input_33=4750 ; freq -input_34=1 ; Q -input_35=-5 ; gain -input_36=6 ; peaking -input_37=375 ; freq -input_38=6.554 ; Q -input_39=-2.4 ; gain -input_40=6 ; peaking -input_41=375 ; freq -input_42=6.2424 ; Q -input_43=-2.4 ; gain - -[drc] -library=builtin -label=drc -input_0={intermediate:0} -input_1={intermediate:1} -output_2={dst:0} -output_3={dst:1} -input_4=1 ; emphasis_disabled -input_5=0 ; f -input_6=1 ; enable -input_7=-24 ; threshold -input_8=18 ; knee -input_9=4.128 ; ratio -input_10=0.019 ; attack -input_11=0.263 ; release -input_12=2 ; boost -input_13=325 ; f -input_14=1 ; enable -input_15=-12 ; threshold -input_16=12 ; knee -input_17=1 ; ratio -input_18=0.031 ; attack -input_19=0.22 ; release -input_20=-7 ; boost -input_21=850 ; f -input_22=1 ; enable -input_23=-19 ; threshold -input_24=20 ; knee -input_25=2.854 ; ratio -input_26=0.019 ; attack -input_27=0.306 ; release -input_28=1 ; boost diff --git a/cras/client/cras-sys/generator/README.md b/cras/client/cras-sys/generator/README.md index d44fbfaf..0ca99062 100644 --- a/cras/client/cras-sys/generator/README.md +++ b/cras/client/cras-sys/generator/README.md @@ -1,64 +1,3 @@ -1. Create a directory `c_headers` in this directory - (adhd/cras/client/cras-sys/generator). +1. Use `cargo run` to generate rust bindings at `lib_gen.rs` -2. Copy -``` -cras_audio_format.h -cras_iodev_info.h -cras_messages.h -cras_shm.h -cras_types.h -cras_util.h -``` - -From cras/src/common from commit -c2c32a0994b8c68dd7795885ef2910ad7ccc477e - -in to `c_headers/` - -2. If we use both `packed` and `align(4)` for a struct, bindgen will generate - it as an opaque struct. - -`cras_server_state` is created from C with `packed` and `aligned(4)` and shared -through a shared memory area. - -Structs with `packed` and `align(4)` have the same memory layout as those with -`packed` except for some extra alignment bytes at the end. - -Therefore, using only `packed` for `cras_server_state` from Rust side is safe. - -Modify `cras_server_state` from -`__attribute__ ((packed, aligned(4)))` -to -`__attribute__ ((packed))` - -3. And use command -``` -cargo run -``` - -to generate `lib_gen.rs` - -4. Add the following header to the generated file: - -``` -// Copyright 2019 The Chromium OS Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -/* - * automatically generated by rust-bindgen - * from files in cras/src/common in adhd: - * cras_audio_format.h - * cras_iodev_info.h - * cras_messages.h - * cras_shm.h - * cras_types.h - * cras_util.h - * - * at commit c2c32a0994b8c68dd7795885ef2910ad7ccc477e - */ -``` - -5. Copy `lib_gen.rs` to -`cras-sys/src/gen.rs +2. Copy `lib_gen.rs` to `cras-sys/src/gen.rs diff --git a/cras/client/cras-sys/generator/src/main.rs b/cras/client/cras-sys/generator/src/main.rs index d027e56f..7b47f025 100644 --- a/cras/client/cras-sys/generator/src/main.rs +++ b/cras/client/cras-sys/generator/src/main.rs @@ -5,7 +5,100 @@ extern crate bindgen; use bindgen::builder; -fn gen() { +use std::fs::{self, File}; +use std::io::Write; +use std::path::Path; +use std::str; + +fn copy_headers(src_dir: &Path, dst_dir: &Path) -> Result<(), String> { + if dst_dir.is_file() { + fs::remove_file(&dst_dir).or_else(|e| { + Err(format!( + "failed to remove existing file at {:?}: {}", + dst_dir, e + )) + })?; + } + + if !dst_dir.is_dir() { + fs::create_dir(&dst_dir).or_else(|e| { + Err(format!( + "failed to create destination directory: {:?}: {}", + dst_dir, e + )) + })?; + } + + let header_files = vec![ + "cras_audio_format.h", + "cras_iodev_info.h", + "cras_messages.h", + "cras_shm.h", + "cras_types.h", + "cras_util.h", + ]; + + for header in &header_files { + let src = src_dir.join(&header); + let dst = dst_dir.join(&header); + fs::copy(&src, &dst).or_else(|e| { + Err(format!( + "failed to copy header file {:?} to {:?}: {}", + src, dst, e + )) + })?; + } + Ok(()) +} + +/* + * If we use both `packed` and `align(4)` for a struct, bindgen will generate + * it as an opaque struct. + * + * `cras_server_state` is created from C with `packed` and `aligned(4)` and + * shared through a shared memory area. + * + * Structs with `packed` and `align(4)` have the same memory layout as those + * with `packed` except for some extra alignment bytes at the end. + * + * Therefore, using only `packed` for `cras_server_state` from Rust side is safe. + * + * This function modifies `cras_server_state` from + * `__attribute__ ((packed, aligned(4)))` to `__attribute__ ((packed))` + */ +fn modify_server_state_attributes(dir: &Path) -> Result<(), String> { + let cras_types_path = dir.join("cras_types.h"); + let bytes = fs::read(&cras_types_path) + .or_else(|e| Err(format!("failed to read {:?}: {}", cras_types_path, e)))?; + + let old = str::from_utf8(&bytes).or_else(|e| { + Err(format!( + "failed to parse {:?} as utf8: {}", + cras_types_path, e + )) + })?; + + let new = old.replacen( + "struct __attribute__((packed, aligned(4))) cras_server_state {", + "struct __attribute__((packed)) cras_server_state {", + 1, + ); + + if new.len() >= old.len() { + return Err("failed to remove 'aligned(4)' from cras_server_state".to_string()); + } + + fs::write(&cras_types_path, new).or_else(|e| { + Err(format!( + "failed to write updated contents to {:?}: {}", + cras_types_path, e + )) + })?; + + Ok(()) +} + +fn gen() -> String { let name = "cras_gen"; let bindings = builder() .header("c_headers/cras_messages.h") @@ -21,11 +114,39 @@ fn gen() { .rustified_enum("_snd_pcm_.*") .generate() .expect(format!("Unable to generate {} code", name).as_str()); - bindings - .write_to_file("lib_gen.rs") - .expect("Unable to generate lib.rs file"); + + bindings.to_string() +} + +fn write_output(output_path: &Path, output: String) -> std::io::Result<()> { + let header = b"// Copyright 2019 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/* + * generated from files in cras/src/common in adhd: + * cras_audio_format.h + * cras_iodev_info.h + * cras_messages.h + * cras_shm.h + * cras_types.h + * cras_util.h + */ +"; + + let mut output_file = File::create(output_path)?; + output_file.write_all(header)?; + output_file.write_all(output.as_bytes())?; + Ok(()) } fn main() { - gen(); + let src_header_dir = Path::new("../../../src/common"); + let dst_header_dir = Path::new("./c_headers"); + + copy_headers(src_header_dir, dst_header_dir).expect("failed to copy C headers"); + modify_server_state_attributes(dst_header_dir) + .expect("failed to modify cras_server_state's attributes"); + let generated_code = gen(); + write_output(Path::new("lib_gen.rs"), generated_code).expect("failed to write generated code"); } diff --git a/cras/client/cras-sys/src/gen.rs b/cras/client/cras-sys/src/gen.rs index aad9f38a..59d146a6 100644 --- a/cras/client/cras-sys/src/gen.rs +++ b/cras/client/cras-sys/src/gen.rs @@ -3,55 +3,16 @@ // found in the LICENSE file. /* - * automatically generated by rust-bindgen - * from files in cras/src/common in adhd: + * generated from files in cras/src/common in adhd: * cras_audio_format.h * cras_iodev_info.h * cras_messages.h * cras_shm.h * cras_types.h * cras_util.h - * - * at commit c2c32a0994b8c68dd7795885ef2910ad7ccc477e */ +/* automatically generated by rust-bindgen */ -#[repr(C)] -#[derive(Default)] -pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>); -impl<T> __IncompleteArrayField<T> { - #[inline] - pub fn new() -> Self { - __IncompleteArrayField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ptr(&self) -> *const T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut_ptr(&mut self) -> *mut T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) - } - #[inline] - pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) - } -} -impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__IncompleteArrayField") - } -} -impl<T> ::std::clone::Clone for __IncompleteArrayField<T> { - #[inline] - fn clone(&self) -> Self { - Self::new() - } -} -impl<T> ::std::marker::Copy for __IncompleteArrayField<T> {} pub const CRAS_IODEV_NAME_BUFFER_SIZE: u32 = 64; pub const CRAS_NODE_TYPE_BUFFER_SIZE: u32 = 32; pub const CRAS_NODE_MIC_POS_BUFFER_SIZE: u32 = 128; @@ -61,13 +22,12 @@ pub const CRAS_MAX_IODEVS: u32 = 20; pub const CRAS_MAX_IONODES: u32 = 20; pub const CRAS_MAX_ATTACHED_CLIENTS: u32 = 20; pub const CRAS_MAX_AUDIO_THREAD_SNAPSHOTS: u32 = 10; -pub const CRAS_MAX_HOTWORD_MODEL_NAME_SIZE: u32 = 8; +pub const CRAS_MAX_HOTWORD_MODEL_NAME_SIZE: u32 = 12; pub const CRAS_BT_EVENT_LOG_SIZE: u32 = 1024; pub const CRAS_SERVER_STATE_VERSION: u32 = 2; -pub const CRAS_PROTO_VER: u32 = 3; +pub const CRAS_PROTO_VER: u32 = 5; pub const CRAS_SERV_MAX_MSG_SIZE: u32 = 256; pub const CRAS_CLIENT_MAX_MSG_SIZE: u32 = 256; -pub const CRAS_HOTWORD_NAME_MAX_SIZE: u32 = 8; pub const CRAS_MAX_HOTWORD_MODELS: u32 = 244; pub const CRAS_MAX_REMIX_CHANNELS: u32 = 32; pub const CRAS_MAX_TEST_DATA_LEN: u32 = 224; @@ -749,6 +709,17 @@ pub enum CRAS_STREAM_TYPE { } #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum CRAS_CLIENT_TYPE { + CRAS_CLIENT_TYPE_UNKNOWN = 0, + CRAS_CLIENT_TYPE_LEGACY = 1, + CRAS_CLIENT_TYPE_TEST = 2, + CRAS_CLIENT_TYPE_PCM = 3, + CRAS_CLIENT_TYPE_CHROME = 4, + CRAS_CLIENT_TYPE_ARC = 5, + CRAS_CLIENT_TYPE_CROSVM = 6, +} +#[repr(u32)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum CRAS_STREAM_EFFECT { APM_ECHO_CANCELLATION = 1, APM_NOISE_SUPRESSION = 2, @@ -1182,6 +1153,7 @@ pub struct audio_stream_debug_info { pub dev_idx: u32, pub direction: u32, pub stream_type: u32, + pub client_type: u32, pub buffer_frames: u32, pub cb_threshold: u32, pub effects: u64, @@ -1203,7 +1175,7 @@ pub struct audio_stream_debug_info { fn bindgen_test_layout_audio_stream_debug_info() { assert_eq!( ::std::mem::size_of::<audio_stream_debug_info>(), - 99usize, + 103usize, concat!("Size of: ", stringify!(audio_stream_debug_info)) ); assert_eq!( @@ -1259,13 +1231,25 @@ fn bindgen_test_layout_audio_stream_debug_info() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::<audio_stream_debug_info>())).buffer_frames as *const _ as usize + &(*(::std::ptr::null::<audio_stream_debug_info>())).client_type as *const _ as usize }, 20usize, concat!( "Offset of field: ", stringify!(audio_stream_debug_info), "::", + stringify!(client_type) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<audio_stream_debug_info>())).buffer_frames as *const _ as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(audio_stream_debug_info), + "::", stringify!(buffer_frames) ) ); @@ -1273,7 +1257,7 @@ fn bindgen_test_layout_audio_stream_debug_info() { unsafe { &(*(::std::ptr::null::<audio_stream_debug_info>())).cb_threshold as *const _ as usize }, - 24usize, + 28usize, concat!( "Offset of field: ", stringify!(audio_stream_debug_info), @@ -1283,7 +1267,7 @@ fn bindgen_test_layout_audio_stream_debug_info() { ); assert_eq!( unsafe { &(*(::std::ptr::null::<audio_stream_debug_info>())).effects as *const _ as usize }, - 28usize, + 32usize, concat!( "Offset of field: ", stringify!(audio_stream_debug_info), @@ -1293,7 +1277,7 @@ fn bindgen_test_layout_audio_stream_debug_info() { ); assert_eq!( unsafe { &(*(::std::ptr::null::<audio_stream_debug_info>())).flags as *const _ as usize }, - 36usize, + 40usize, concat!( "Offset of field: ", stringify!(audio_stream_debug_info), @@ -1305,7 +1289,7 @@ fn bindgen_test_layout_audio_stream_debug_info() { unsafe { &(*(::std::ptr::null::<audio_stream_debug_info>())).frame_rate as *const _ as usize }, - 40usize, + 44usize, concat!( "Offset of field: ", stringify!(audio_stream_debug_info), @@ -1317,7 +1301,7 @@ fn bindgen_test_layout_audio_stream_debug_info() { unsafe { &(*(::std::ptr::null::<audio_stream_debug_info>())).num_channels as *const _ as usize }, - 44usize, + 48usize, concat!( "Offset of field: ", stringify!(audio_stream_debug_info), @@ -1330,7 +1314,7 @@ fn bindgen_test_layout_audio_stream_debug_info() { &(*(::std::ptr::null::<audio_stream_debug_info>())).longest_fetch_sec as *const _ as usize }, - 48usize, + 52usize, concat!( "Offset of field: ", stringify!(audio_stream_debug_info), @@ -1343,7 +1327,7 @@ fn bindgen_test_layout_audio_stream_debug_info() { &(*(::std::ptr::null::<audio_stream_debug_info>())).longest_fetch_nsec as *const _ as usize }, - 52usize, + 56usize, concat!( "Offset of field: ", stringify!(audio_stream_debug_info), @@ -1355,7 +1339,7 @@ fn bindgen_test_layout_audio_stream_debug_info() { unsafe { &(*(::std::ptr::null::<audio_stream_debug_info>())).num_missed_cb as *const _ as usize }, - 56usize, + 60usize, concat!( "Offset of field: ", stringify!(audio_stream_debug_info), @@ -1367,7 +1351,7 @@ fn bindgen_test_layout_audio_stream_debug_info() { unsafe { &(*(::std::ptr::null::<audio_stream_debug_info>())).num_overruns as *const _ as usize }, - 60usize, + 64usize, concat!( "Offset of field: ", stringify!(audio_stream_debug_info), @@ -1379,7 +1363,7 @@ fn bindgen_test_layout_audio_stream_debug_info() { unsafe { &(*(::std::ptr::null::<audio_stream_debug_info>())).is_pinned as *const _ as usize }, - 64usize, + 68usize, concat!( "Offset of field: ", stringify!(audio_stream_debug_info), @@ -1391,7 +1375,7 @@ fn bindgen_test_layout_audio_stream_debug_info() { unsafe { &(*(::std::ptr::null::<audio_stream_debug_info>())).pinned_dev_idx as *const _ as usize }, - 68usize, + 72usize, concat!( "Offset of field: ", stringify!(audio_stream_debug_info), @@ -1403,7 +1387,7 @@ fn bindgen_test_layout_audio_stream_debug_info() { unsafe { &(*(::std::ptr::null::<audio_stream_debug_info>())).runtime_sec as *const _ as usize }, - 72usize, + 76usize, concat!( "Offset of field: ", stringify!(audio_stream_debug_info), @@ -1415,7 +1399,7 @@ fn bindgen_test_layout_audio_stream_debug_info() { unsafe { &(*(::std::ptr::null::<audio_stream_debug_info>())).runtime_nsec as *const _ as usize }, - 76usize, + 80usize, concat!( "Offset of field: ", stringify!(audio_stream_debug_info), @@ -1427,7 +1411,7 @@ fn bindgen_test_layout_audio_stream_debug_info() { unsafe { &(*(::std::ptr::null::<audio_stream_debug_info>())).stream_volume as *const _ as usize }, - 80usize, + 84usize, concat!( "Offset of field: ", stringify!(audio_stream_debug_info), @@ -1439,7 +1423,7 @@ fn bindgen_test_layout_audio_stream_debug_info() { unsafe { &(*(::std::ptr::null::<audio_stream_debug_info>())).channel_layout as *const _ as usize }, - 88usize, + 92usize, concat!( "Offset of field: ", stringify!(audio_stream_debug_info), @@ -1461,7 +1445,7 @@ pub struct audio_debug_info { fn bindgen_test_layout_audio_debug_info() { assert_eq!( ::std::mem::size_of::<audio_debug_info>(), - 124188usize, + 124220usize, concat!("Size of: ", stringify!(audio_debug_info)) ); assert_eq!( @@ -1511,7 +1495,7 @@ fn bindgen_test_layout_audio_debug_info() { ); assert_eq!( unsafe { &(*(::std::ptr::null::<audio_debug_info>())).log as *const _ as usize }, - 1300usize, + 1332usize, concat!( "Offset of field: ", stringify!(audio_debug_info), @@ -1679,7 +1663,7 @@ pub struct cras_audio_thread_snapshot { fn bindgen_test_layout_cras_audio_thread_snapshot() { assert_eq!( ::std::mem::size_of::<cras_audio_thread_snapshot>(), - 124208usize, + 124240usize, concat!("Size of: ", stringify!(cras_audio_thread_snapshot)) ); assert_eq!( @@ -1735,7 +1719,7 @@ pub struct cras_audio_thread_snapshot_buffer { fn bindgen_test_layout_cras_audio_thread_snapshot_buffer() { assert_eq!( ::std::mem::size_of::<cras_audio_thread_snapshot_buffer>(), - 1242084usize, + 1242404usize, concat!("Size of: ", stringify!(cras_audio_thread_snapshot_buffer)) ); assert_eq!( @@ -1763,7 +1747,7 @@ fn bindgen_test_layout_cras_audio_thread_snapshot_buffer() { unsafe { &(*(::std::ptr::null::<cras_audio_thread_snapshot_buffer>())).pos as *const _ as usize }, - 1242080usize, + 1242400usize, concat!( "Offset of field: ", stringify!(cras_audio_thread_snapshot_buffer), @@ -1816,7 +1800,7 @@ pub struct cras_server_state { fn bindgen_test_layout_cras_server_state() { assert_eq!( ::std::mem::size_of::<cras_server_state>(), - 1398000usize, + 1398352usize, concat!("Size of: ", stringify!(cras_server_state)) ); assert_eq!( @@ -2150,7 +2134,7 @@ fn bindgen_test_layout_cras_server_state() { &(*(::std::ptr::null::<cras_server_state>())).default_output_buffer_size as *const _ as usize }, - 139504usize, + 139536usize, concat!( "Offset of field: ", stringify!(cras_server_state), @@ -2162,7 +2146,7 @@ fn bindgen_test_layout_cras_server_state() { unsafe { &(*(::std::ptr::null::<cras_server_state>())).non_empty_status as *const _ as usize }, - 139508usize, + 139540usize, concat!( "Offset of field: ", stringify!(cras_server_state), @@ -2172,7 +2156,7 @@ fn bindgen_test_layout_cras_server_state() { ); assert_eq!( unsafe { &(*(::std::ptr::null::<cras_server_state>())).aec_supported as *const _ as usize }, - 139512usize, + 139544usize, concat!( "Offset of field: ", stringify!(cras_server_state), @@ -2182,7 +2166,7 @@ fn bindgen_test_layout_cras_server_state() { ); assert_eq!( unsafe { &(*(::std::ptr::null::<cras_server_state>())).aec_group_id as *const _ as usize }, - 139516usize, + 139548usize, concat!( "Offset of field: ", stringify!(cras_server_state), @@ -2194,7 +2178,7 @@ fn bindgen_test_layout_cras_server_state() { unsafe { &(*(::std::ptr::null::<cras_server_state>())).snapshot_buffer as *const _ as usize }, - 139520usize, + 139552usize, concat!( "Offset of field: ", stringify!(cras_server_state), @@ -2204,7 +2188,7 @@ fn bindgen_test_layout_cras_server_state() { ); assert_eq!( unsafe { &(*(::std::ptr::null::<cras_server_state>())).bt_debug_info as *const _ as usize }, - 1381604usize, + 1381956usize, concat!( "Offset of field: ", stringify!(cras_server_state), @@ -2216,7 +2200,7 @@ fn bindgen_test_layout_cras_server_state() { unsafe { &(*(::std::ptr::null::<cras_server_state>())).bt_wbs_enabled as *const _ as usize }, - 1397996usize, + 1398348usize, concat!( "Offset of field: ", stringify!(cras_server_state), @@ -2496,12 +2480,14 @@ pub struct cras_connect_message { pub format: cras_audio_format_packed, pub dev_idx: u32, pub effects: u64, + pub client_type: CRAS_CLIENT_TYPE, + pub client_shm_size: u32, } #[test] fn bindgen_test_layout_cras_connect_message() { assert_eq!( ::std::mem::size_of::<cras_connect_message>(), - 71usize, + 79usize, concat!("Size of: ", stringify!(cras_connect_message)) ); assert_eq!( @@ -2627,6 +2613,184 @@ fn bindgen_test_layout_cras_connect_message() { stringify!(effects) ) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<cras_connect_message>())).client_type as *const _ as usize + }, + 71usize, + concat!( + "Offset of field: ", + stringify!(cras_connect_message), + "::", + stringify!(client_type) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<cras_connect_message>())).client_shm_size as *const _ as usize + }, + 75usize, + concat!( + "Offset of field: ", + stringify!(cras_connect_message), + "::", + stringify!(client_shm_size) + ) + ); +} +#[repr(C, packed)] +#[derive(Debug, Copy, Clone)] +pub struct cras_connect_message_old { + pub header: cras_server_message, + pub proto_version: u32, + pub direction: CRAS_STREAM_DIRECTION, + pub stream_id: cras_stream_id_t, + pub stream_type: CRAS_STREAM_TYPE, + pub buffer_frames: u32, + pub cb_threshold: u32, + pub flags: u32, + pub format: cras_audio_format_packed, + pub dev_idx: u32, + pub effects: u64, +} +#[test] +fn bindgen_test_layout_cras_connect_message_old() { + assert_eq!( + ::std::mem::size_of::<cras_connect_message_old>(), + 71usize, + concat!("Size of: ", stringify!(cras_connect_message_old)) + ); + assert_eq!( + ::std::mem::align_of::<cras_connect_message_old>(), + 1usize, + concat!("Alignment of ", stringify!(cras_connect_message_old)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<cras_connect_message_old>())).header as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(cras_connect_message_old), + "::", + stringify!(header) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<cras_connect_message_old>())).proto_version as *const _ as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(cras_connect_message_old), + "::", + stringify!(proto_version) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<cras_connect_message_old>())).direction as *const _ as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(cras_connect_message_old), + "::", + stringify!(direction) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<cras_connect_message_old>())).stream_id as *const _ as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(cras_connect_message_old), + "::", + stringify!(stream_id) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<cras_connect_message_old>())).stream_type as *const _ as usize + }, + 20usize, + concat!( + "Offset of field: ", + stringify!(cras_connect_message_old), + "::", + stringify!(stream_type) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<cras_connect_message_old>())).buffer_frames as *const _ as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(cras_connect_message_old), + "::", + stringify!(buffer_frames) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<cras_connect_message_old>())).cb_threshold as *const _ as usize + }, + 28usize, + concat!( + "Offset of field: ", + stringify!(cras_connect_message_old), + "::", + stringify!(cb_threshold) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<cras_connect_message_old>())).flags as *const _ as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(cras_connect_message_old), + "::", + stringify!(flags) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<cras_connect_message_old>())).format as *const _ as usize }, + 36usize, + concat!( + "Offset of field: ", + stringify!(cras_connect_message_old), + "::", + stringify!(format) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<cras_connect_message_old>())).dev_idx as *const _ as usize + }, + 59usize, + concat!( + "Offset of field: ", + stringify!(cras_connect_message_old), + "::", + stringify!(dev_idx) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<cras_connect_message_old>())).effects as *const _ as usize + }, + 63usize, + concat!( + "Offset of field: ", + stringify!(cras_connect_message_old), + "::", + stringify!(effects) + ) + ); } #[repr(C, packed)] #[derive(Debug, Copy, Clone)] @@ -3410,13 +3574,13 @@ fn bindgen_test_layout_cras_get_hotword_models() { pub struct cras_set_hotword_model { pub header: cras_server_message, pub node_id: cras_node_id_t, - pub model_name: [::std::os::raw::c_char; 8usize], + pub model_name: [::std::os::raw::c_char; 12usize], } #[test] fn bindgen_test_layout_cras_set_hotword_model() { assert_eq!( ::std::mem::size_of::<cras_set_hotword_model>(), - 24usize, + 28usize, concat!("Size of: ", stringify!(cras_set_hotword_model)) ); assert_eq!( @@ -4280,7 +4444,7 @@ fn bindgen_test_layout_cras_audio_shm_config() { ); } #[repr(C, packed)] -#[derive(Debug)] +#[derive(Debug, Copy, Clone)] pub struct cras_audio_shm_header { pub config: cras_audio_shm_config, pub read_buf_idx: u32, @@ -4293,13 +4457,13 @@ pub struct cras_audio_shm_header { pub callback_pending: i32, pub num_overruns: u32, pub ts: cras_timespec, - pub samples: __IncompleteArrayField<u8>, + pub buffer_offset: [u32; 2usize], } #[test] fn bindgen_test_layout_cras_audio_shm_header() { assert_eq!( ::std::mem::size_of::<cras_audio_shm_header>(), - 72usize, + 80usize, concat!("Size of: ", stringify!(cras_audio_shm_header)) ); assert_eq!( @@ -4307,6 +4471,144 @@ fn bindgen_test_layout_cras_audio_shm_header() { 1usize, concat!("Alignment of ", stringify!(cras_audio_shm_header)) ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<cras_audio_shm_header>())).config as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(cras_audio_shm_header), + "::", + stringify!(config) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<cras_audio_shm_header>())).read_buf_idx as *const _ as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(cras_audio_shm_header), + "::", + stringify!(read_buf_idx) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<cras_audio_shm_header>())).write_buf_idx as *const _ as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(cras_audio_shm_header), + "::", + stringify!(write_buf_idx) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<cras_audio_shm_header>())).read_offset as *const _ as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(cras_audio_shm_header), + "::", + stringify!(read_offset) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<cras_audio_shm_header>())).write_offset as *const _ as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(cras_audio_shm_header), + "::", + stringify!(write_offset) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<cras_audio_shm_header>())).write_in_progress as *const _ as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(cras_audio_shm_header), + "::", + stringify!(write_in_progress) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<cras_audio_shm_header>())).volume_scaler as *const _ as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(cras_audio_shm_header), + "::", + stringify!(volume_scaler) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<cras_audio_shm_header>())).mute as *const _ as usize }, + 44usize, + concat!( + "Offset of field: ", + stringify!(cras_audio_shm_header), + "::", + stringify!(mute) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<cras_audio_shm_header>())).callback_pending as *const _ as usize + }, + 48usize, + concat!( + "Offset of field: ", + stringify!(cras_audio_shm_header), + "::", + stringify!(callback_pending) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<cras_audio_shm_header>())).num_overruns as *const _ as usize + }, + 52usize, + concat!( + "Offset of field: ", + stringify!(cras_audio_shm_header), + "::", + stringify!(num_overruns) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<cras_audio_shm_header>())).ts as *const _ as usize }, + 56usize, + concat!( + "Offset of field: ", + stringify!(cras_audio_shm_header), + "::", + stringify!(ts) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<cras_audio_shm_header>())).buffer_offset as *const _ as usize + }, + 72usize, + concat!( + "Offset of field: ", + stringify!(cras_audio_shm_header), + "::", + stringify!(buffer_offset) + ) + ); } #[repr(C)] #[derive(Copy, Clone)] diff --git a/cras/client/cras_tests/Cargo.toml b/cras/client/cras_tests/Cargo.toml index a4f4d8d2..94453ddf 100644 --- a/cras/client/cras_tests/Cargo.toml +++ b/cras/client/cras_tests/Cargo.toml @@ -8,3 +8,4 @@ edition = "2018" audio_streams = { path = "../../../audio_streams" } # provided by ebuild getopts = "0.2.18" libcras = { path = "../libcras" } # provided by ebuild +sys_util = { path = "../../../../../platform/crosvm/sys_util" } # provided by ebuild diff --git a/cras/client/cras_tests/src/audio_options.rs b/cras/client/cras_tests/src/audio_options.rs new file mode 100644 index 00000000..d71aac5b --- /dev/null +++ b/cras/client/cras_tests/src/audio_options.rs @@ -0,0 +1,194 @@ +// Copyright 2019 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +use std::fmt; +use std::io; +use std::path::PathBuf; + +use getopts::Options; + +type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>; + +#[derive(Debug, PartialEq)] +pub enum Subcommand { + Capture, + Playback, +} + +impl fmt::Display for Subcommand { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + Subcommand::Capture => write!(f, "capture"), + Subcommand::Playback => write!(f, "playback"), + } + } +} + +fn show_usage<T: AsRef<str>>(program_name: T) { + println!( + "Usage: {} [subcommand] <subcommand args>", + program_name.as_ref() + ); + println!("\nSubcommands:\n"); + println!("capture - Capture to a file from CRAS"); + println!("playback - Playback to CRAS from a file"); + println!("\nhelp - Print help message"); +} + +fn show_subcommand_usage<T: AsRef<str>>(program_name: T, subcommand: &Subcommand, opts: &Options) { + let brief = format!( + "Usage: {} {} [options] [filename]", + program_name.as_ref(), + subcommand + ); + print!("{}", opts.usage(&brief)); +} + +pub struct AudioOptions { + pub subcommand: Subcommand, + pub file_name: PathBuf, + pub buffer_size: Option<usize>, + pub num_channels: Option<usize>, + pub frame_rate: Option<usize>, +} + +impl AudioOptions { + pub fn parse_from_args<T: AsRef<str>>(args: &[T]) -> Result<Option<Self>> { + let mut opts = Options::new(); + opts.optopt("b", "buffer_size", "Buffer size in frames", "SIZE") + .optopt("c", "", "Number of channels", "NUM") + .optopt("r", "rate", "Audio frame rate (Hz)", "RATE") + .optflag("h", "help", "Print help message"); + + let mut args = args.into_iter().map(|s| s.as_ref()); + + let program_name = args.next().ok_or_else(|| { + Box::new(io::Error::new( + std::io::ErrorKind::InvalidInput, + "Program name must be specified", + )) + })?; + + let subcommand = match args.next() { + None => { + println!("Must specify a subcommand."); + show_usage(program_name); + return Err(Box::new(std::io::Error::new( + std::io::ErrorKind::InvalidInput, + "No subcommand", + ))); + } + Some("help") => { + show_usage(&program_name); + return Ok(None); + } + Some("capture") => Subcommand::Capture, + Some("playback") => Subcommand::Playback, + Some(s) => { + println!("Subcommand \"{}\" does not exist.", s); + show_usage(&program_name); + return Err(Box::new(std::io::Error::new( + std::io::ErrorKind::InvalidInput, + "Subcommand does not exist", + ))); + } + }; + + let matches = match opts.parse(args) { + Ok(m) => m, + Err(e) => { + show_subcommand_usage(&program_name, &subcommand, &opts); + return Err(Box::new(e)); + } + }; + if matches.opt_present("h") { + show_subcommand_usage(&program_name, &subcommand, &opts); + return Ok(None); + } + let file_name = match matches.free.get(0) { + None => { + println!("Must provide file name."); + show_subcommand_usage(&program_name, &subcommand, &opts); + return Err(Box::new(std::io::Error::new( + std::io::ErrorKind::InvalidInput, + "Must provide file name.", + ))); + } + Some(file_name) => PathBuf::from(file_name), + }; + let buffer_size = matches.opt_get::<usize>("b")?; + let num_channels = matches.opt_get::<usize>("c")?; + let frame_rate = matches.opt_get::<usize>("r")?; + + Ok(Some(AudioOptions { + subcommand, + file_name, + buffer_size, + num_channels, + frame_rate, + })) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use std::ffi::OsString; + + #[test] + fn parse_from_args() { + let opts = AudioOptions::parse_from_args(&["cras_tests", "playback", "output.wav"]) + .unwrap() + .unwrap(); + assert_eq!(opts.subcommand, Subcommand::Playback); + assert_eq!(opts.file_name, OsString::from("output.wav")); + assert_eq!(opts.frame_rate, None); + assert_eq!(opts.num_channels, None); + assert_eq!(opts.buffer_size, None); + + let opts = AudioOptions::parse_from_args(&["cras_tests", "capture", "input.flac"]) + .unwrap() + .unwrap(); + assert_eq!(opts.subcommand, Subcommand::Capture); + assert_eq!(opts.file_name, OsString::from("input.flac")); + assert_eq!(opts.frame_rate, None); + assert_eq!(opts.num_channels, None); + assert_eq!(opts.buffer_size, None); + + let opts = AudioOptions::parse_from_args(&[ + "cras_tests", + "playback", + "-r", + "44100", + "output.wav", + "-c", + "2", + ]) + .unwrap() + .unwrap(); + assert_eq!(opts.subcommand, Subcommand::Playback); + assert_eq!(opts.file_name, OsString::from("output.wav")); + assert_eq!(opts.frame_rate, Some(44100)); + assert_eq!(opts.num_channels, Some(2)); + assert_eq!(opts.buffer_size, None); + + assert!(AudioOptions::parse_from_args(&["cras_tests"]).is_err()); + assert!(AudioOptions::parse_from_args(&["cras_tests", "capture"]).is_err()); + assert!(AudioOptions::parse_from_args(&["cras_tests", "playback"]).is_err()); + assert!(AudioOptions::parse_from_args(&["cras_tests", "loopback"]).is_err()); + assert!(AudioOptions::parse_from_args(&["cras_tests", "loopback", "file.ogg"]).is_err()); + assert!(AudioOptions::parse_from_args(&["cras_tests", "filename.wav"]).is_err()); + assert!(AudioOptions::parse_from_args(&["cras_tests", "filename.wav", "capture"]).is_err()); + assert!(AudioOptions::parse_from_args(&["cras_tests", "help"]).is_ok()); + assert!(AudioOptions::parse_from_args(&[ + "cras_tests", + "-c", + "2", + "playback", + "output.wav", + "-r", + "44100" + ]) + .is_err()); + } +} diff --git a/cras/client/cras_tests/src/main.rs b/cras/client/cras_tests/src/main.rs index b35cbc74..97094042 100644 --- a/cras/client/cras_tests/src/main.rs +++ b/cras/client/cras_tests/src/main.rs @@ -1,68 +1,81 @@ // Copyright 2019 The Chromium OS Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. + +mod audio_options; + use std::fs::File; -use std::io::{Read, Write}; +use std::io::{self, BufRead, BufReader, Write}; use std::thread::spawn; -type Result<T> = std::result::Result<T, Box<std::error::Error>>; - -use getopts::Options; +use sys_util::{set_rt_prio_limit, set_rt_round_robin}; +type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>; use audio_streams::StreamSource; use libcras::CrasClient; -fn show_subcommand_usage(program_name: &str, subcommand: &str, opts: &Options) { - let brief = format!("Usage: {} {} [options]", program_name, subcommand); - print!("{}", opts.usage(&brief)); +use crate::audio_options::{AudioOptions, Subcommand}; + +fn set_priority_to_realtime() { + const AUDIO_THREAD_RTPRIO: u16 = 10; + if set_rt_prio_limit(AUDIO_THREAD_RTPRIO as u64).is_err() + || set_rt_round_robin(AUDIO_THREAD_RTPRIO as i32).is_err() + { + println!("Attempt to use real-time priority failed, running with default scheduler."); + } } -fn playback(args: &[String]) -> Result<()> { - let mut opts = Options::new(); - opts.optopt("b", "buffer_size", "Buffer size in frames", "SIZE") - .optopt("c", "", "Number of channels", "NUM") - .optopt("f", "file", "Path to playback file", "FILE") - .optopt("r", "rate", "Audio frame rate (Hz)", "RATE") - .optflag("h", "help", "Print help message"); - let matches = match opts.parse(&args[1..]) { - Ok(m) => m, - Err(e) => { - show_subcommand_usage(&args[0], &args[1], &opts); - return Err(Box::new(e)); - } - }; - if matches.opt_present("h") { - show_subcommand_usage(&args[0], &args[1], &opts); - return Ok(()); +fn channel_string(num_channels: usize) -> String { + match num_channels { + 1 => "Mono".to_string(), + 2 => "Stereo".to_string(), + _ => format!("{} Channels", num_channels), } - let file_name = match matches.opt_str("f") { - None => { - println!("Must input playback file name."); - show_subcommand_usage(&args[0], &args[1], &opts); - return Ok(()); - } - Some(file_name) => file_name, - }; - let buffer_size = matches.opt_get_default::<usize>("b", 256)?; - let num_channels = matches.opt_get_default::<usize>("c", 2)?; - let frame_rate = matches.opt_get_default::<usize>("r", 48000)?; - let mut cras_client = CrasClient::new()?; - let (_control, mut stream) = - cras_client.new_playback_stream(num_channels, frame_rate, buffer_size)?; +} + +fn playback(opts: AudioOptions) -> Result<()> { + let file = File::open(&opts.file_name).expect("failed to open file"); + let mut buffered_file = BufReader::new(file); - let mut file = File::open(&file_name).unwrap(); + let num_channels = opts.num_channels.unwrap_or(2); + let frame_rate = opts.frame_rate.unwrap_or(48000); + + println!( + "Playing raw data '{}' : Signed 16 bit Little Endian, Rate {} Hz, {}", + opts.file_name.display(), + frame_rate, + channel_string(num_channels) + ); + + let mut cras_client = CrasClient::new()?; + let (_control, mut stream) = cras_client.new_playback_stream( + num_channels, + frame_rate, + opts.buffer_size.unwrap_or(256), + )?; let thread = spawn(move || { - // Play samples from a file - let mut local_buffer = vec![0u8; buffer_size * num_channels * 2]; + set_priority_to_realtime(); loop { - // Reads data to local buffer - let read_count = file.read(&mut local_buffer).unwrap(); - if read_count == 0 { + let local_buffer = buffered_file + .fill_buf() + .expect("failed to read from input file"); + + // Reached EOF + if local_buffer.len() == 0 { break; } - // Gets writable buffer from stream and - let mut buffer = stream.next_playback_buffer().unwrap(); + + // Gets writable buffer from stream + let mut buffer = stream + .next_playback_buffer() + .expect("failed to get next playback buffer"); + // Writes data to stream buffer - let _write_frames = buffer.write(&local_buffer[..read_count]).unwrap(); + let write_frames = buffer + .write(&local_buffer) + .expect("failed to write output data to buffer"); + + // Mark the file data as written + buffered_file.consume(write_frames); } }); thread.join().expect("Failed to join playback thread"); @@ -71,86 +84,48 @@ fn playback(args: &[String]) -> Result<()> { Ok(()) } -fn capture(args: &[String]) -> Result<()> { - let mut opts = Options::new(); - opts.optopt("b", "buffer_size", "Buffer size in frames", "SIZE") - .optopt("c", "", "Number of channels", "NUM") - .optopt("f", "file", "Path to capture file", "FILE") - .optopt("r", "rate", "Audio frame rate (Hz)", "RATE") - .optflag("h", "help", "Print help message"); - let matches = match opts.parse(&args[1..]) { - Ok(m) => m, - Err(e) => { - show_subcommand_usage(&args[0], &args[1], &opts); - return Err(Box::new(e)); - } - }; - if matches.opt_present("h") { - show_subcommand_usage(&args[0], &args[1], &opts); - return Ok(()); - } - let file_name = match matches.opt_str("f") { - None => { - println!("Must input capture file name."); - show_subcommand_usage(&args[0], &args[1], &opts); - return Ok(()); - } - Some(file_name) => file_name, - }; - let buffer_size = matches.opt_get_default::<usize>("b", 256)?; - let num_channels = matches.opt_get_default::<usize>("c", 2)?; - let frame_rate = matches.opt_get_default::<usize>("r", 48000)?; +fn capture(opts: AudioOptions) -> Result<()> { + let num_channels = opts.num_channels.unwrap_or(2); + let frame_rate = opts.frame_rate.unwrap_or(48000); + + println!( + "Recording raw data '{}' : Signed 16 bit Little Endian, Rate {} Hz, {}", + opts.file_name.display(), + frame_rate, + channel_string(num_channels) + ); let mut cras_client = CrasClient::new()?; cras_client.enable_cras_capture(); - let (_control, mut stream) = - cras_client.new_capture_stream(num_channels, frame_rate, buffer_size)?; - let mut file = File::create(&file_name).unwrap(); - let mut local_buffer = vec![0u8; buffer_size * num_channels * 2]; + let (_control, mut stream) = cras_client.new_capture_stream( + num_channels, + frame_rate, + opts.buffer_size.unwrap_or(256), + )?; + let mut file = File::create(&opts.file_name).unwrap(); loop { let _frames = match stream.next_capture_buffer() { Err(e) => { return Err(e.into()); } Ok(mut buf) => { - buf.read(&mut local_buffer)?; - file.write(local_buffer.as_ref())? + let written = io::copy(&mut buf, &mut file)?; + written } }; } } -fn show_usage(program_name: &str) { - println!("Usage: {} [subcommand] <subcommand args>", program_name); - println!("\nSubcommands:\n"); - println!("capture - Test capture function"); - println!("playback - Test playback function"); - println!("\nhelp - Print help message"); -} - fn main() -> Result<()> { let args: Vec<String> = std::env::args().collect(); - if args.len() < 2 { - println!("Must specify a subcommand."); - show_usage(&args[0]); - return Err(Box::new(std::io::Error::new( - std::io::ErrorKind::InvalidInput, - "No subcommand", - ))); - } + let opts = match AudioOptions::parse_from_args(&args)? { + None => return Ok(()), + Some(v) => v, + }; - match args[1].as_ref() { - "capture" => capture(&args)?, - "playback" => playback(&args)?, - "help" => show_usage(&args[0]), - subcommand => { - println!("Subcommand \"{}\" does not exist.", subcommand); - show_usage(&args[0]); - return Err(Box::new(std::io::Error::new( - std::io::ErrorKind::InvalidInput, - "Subcommand does not exist", - ))); - } + match opts.subcommand { + Subcommand::Capture => capture(opts)?, + Subcommand::Playback => playback(opts)?, }; Ok(()) } diff --git a/cras/client/libcras/src/audio_socket.rs b/cras/client/libcras/src/audio_socket.rs index 60a04367..ac56144c 100644 --- a/cras/client/libcras/src/audio_socket.rs +++ b/cras/client/libcras/src/audio_socket.rs @@ -8,6 +8,7 @@ use std::os::unix::{ io::{AsRawFd, RawFd}, net::UnixStream, }; +use std::time::Duration; use cras_sys::gen::{audio_message, CRAS_AUDIO_MESSAGE_ID}; use data_model::DataInit; @@ -94,6 +95,25 @@ impl AudioSocket { /// # Errors /// Returns io::Error if error occurs. pub fn read_audio_message(&mut self) -> io::Result<AudioMessage> { + match self.read_audio_message_with_timeout(None)? { + None => Err(io::Error::new(io::ErrorKind::Other, "Unexpected exit")), + Some(message) => Ok(message), + } + } + + /// Blocks waiting for an `audio message` until `timeout` occurs. If `timeout` + /// is None, blocks indefinitely. + /// + /// # Returns + /// Some(AudioMessage) - AudioMessage enum if we receive a message before timeout. + /// None - If the timeout expires. + /// + /// # Errors + /// Returns io::Error if error occurs. + pub fn read_audio_message_with_timeout( + &mut self, + timeout: Option<Duration>, + ) -> io::Result<Option<AudioMessage>> { #[derive(PollToken)] enum Token { AudioMsg, @@ -109,7 +129,11 @@ impl AudioSocket { } }; let events = { - match poll_ctx.wait() { + let result = match timeout { + None => poll_ctx.wait(), + Some(duration) => poll_ctx.wait_timeout(duration), + }; + match result { Ok(v) => v, Err(e) => { return Err(io::Error::new( @@ -123,10 +147,10 @@ impl AudioSocket { // Check the first readable message let tokens: Vec<Token> = events.iter_readable().map(|e| e.token()).collect(); match tokens.get(0) { - None => Err(io::Error::new(io::ErrorKind::Other, "Unexpected exit")), + None => Ok(None), Some(&Token::AudioMsg) => { let raw_msg: audio_message = self.read_from_socket()?; - Ok(AudioMessage::from(raw_msg)) + Ok(Some(AudioMessage::from(raw_msg))) } } } diff --git a/cras/client/libcras/src/cras_client_message.rs b/cras/client/libcras/src/cras_client_message.rs index 0d9fb4f7..0921c5f2 100644 --- a/cras/client/libcras/src/cras_client_message.rs +++ b/cras/client/libcras/src/cras_client_message.rs @@ -1,7 +1,7 @@ // Copyright 2019 The Chromium OS Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -use std::{error, fmt, io, mem, os::unix::io::RawFd}; +use std::{array::TryFromSliceError, convert::TryInto, error, fmt, io, mem, os::unix::io::RawFd}; use cras_sys::gen::{ cras_client_connected, cras_client_message, cras_client_stream_connected, @@ -20,6 +20,7 @@ enum ErrorType { IoError(io::Error), SysUtilError(sys_util::Error), CrasStreamError(cras_stream::Error), + ArrayTryFromSliceError(TryFromSliceError), InvalidSize, MessageTypeError, MessageNumFdError, @@ -48,6 +49,7 @@ impl fmt::Display for Error { ErrorType::SysUtilError(ref err) => err.fmt(f), ErrorType::MessageTypeError => write!(f, "Message type error"), ErrorType::CrasStreamError(ref err) => err.fmt(f), + ErrorType::ArrayTryFromSliceError(ref err) => err.fmt(f), ErrorType::MessageNumFdError => write!(f, "Message the number of fds is not matched"), ErrorType::MessageTruncated => write!(f, "Read truncated message"), ErrorType::MessageIdError => write!(f, "No such id"), @@ -77,6 +79,12 @@ impl From<cras_stream::Error> for Error { } } +impl From<TryFromSliceError> for Error { + fn from(err: TryFromSliceError) -> Self { + Self::new(ErrorType::ArrayTryFromSliceError(err)) + } +} + /// A handled server result from one message sent from CRAS server. pub enum ServerResult { /// client_id, CrasServerStateShmFd @@ -139,11 +147,6 @@ impl Default for CrasClientMessage { } } -// Converts 4-bytes array to an `u32`. -fn from_le_bytes(bytes: [u8; 4]) -> u32 { - (bytes[0] as u32) | (bytes[1] as u32) << 8 | (bytes[2] as u32) << 16 | (bytes[3] as u32) << 24 -} - impl CrasClientMessage { // Reads a message from server_socket and checks validity of the read result fn try_new(server_socket: &CrasServerSocket) -> Result<CrasClientMessage> { @@ -167,9 +170,9 @@ impl CrasClientMessage { _ => Err(Error::new(ErrorType::MessageNumFdError)), }, CRAS_CLIENT_STREAM_CONNECTED => match fd_nums { - // In current cras_rstream implementation, `fds[0]` and `fds[1]` are pointing to a - // same fd which contains the shared memory area. We should change this while - // refactoring that part. + // CRAS should return two shared memory areas the first which has + // mem::size_of::<cras_audio_shm_header>() bytes, and the second which has + // `samples_shm_size` bytes. 2 => Ok(()), _ => Err(Error::new(ErrorType::MessageNumFdError)), }, @@ -179,13 +182,8 @@ impl CrasClientMessage { // Gets the message id fn get_id(&self) -> Result<CRAS_CLIENT_MESSAGE_ID> { - // Reads 4 bytes start from offset = size_of(cras_client_message.length) - // [TODO] Change this to `from_le_bytes` when rust version >= 1.32.0 - let mut data = [0u8; 4]; let offset = mem::size_of::<u32>(); - data.copy_from_slice(&self.data[offset..offset + 4]); - - match from_le_bytes(data) { + match u32::from_le_bytes(self.data[offset..offset + 4].try_into()?) { id if id == (CRAS_CLIENT_CONNECTED as u32) => Ok(CRAS_CLIENT_CONNECTED), id if id == (CRAS_CLIENT_STREAM_CONNECTED as u32) => Ok(CRAS_CLIENT_STREAM_CONNECTED), _ => Err(Error::new(ErrorType::MessageIdError)), diff --git a/cras/client/libcras/src/cras_shm.rs b/cras/client/libcras/src/cras_shm.rs index 6efc4f9d..55474976 100644 --- a/cras/client/libcras/src/cras_shm.rs +++ b/cras/client/libcras/src/cras_shm.rs @@ -56,6 +56,7 @@ pub struct CrasAudioHeader<'a> { write_buf_idx: VolatileRef<'a, u32>, read_offset: [VolatileRef<'a, u32>; CRAS_NUM_SHM_BUFFERS as usize], write_offset: [VolatileRef<'a, u32>; CRAS_NUM_SHM_BUFFERS as usize], + buffer_offset: [VolatileRef<'a, u32>; CRAS_NUM_SHM_BUFFERS as usize], } // It is safe to send audio buffers between threads as this struct has exclusive ownership of the @@ -122,28 +123,98 @@ impl<'a> CrasAudioHeader<'a> { vref_from_addr!(addr, write_offset[0]), vref_from_addr!(addr, write_offset[1]), ], + buffer_offset: [ + vref_from_addr!(addr, buffer_offset[0]), + vref_from_addr!(addr, buffer_offset[1]), + ], }) } } - /// Gets the write offset of the buffer and the writable length. + /// Calculates the length of a buffer with the given offset. This length will + /// be `used_size`, unless the offset is closer than `used_size` to the end + /// of samples, in which case the length will be as long as possible. + /// + /// If that buffer length is invalid (too small to hold a frame of audio data), + /// then returns an error. + /// The returned buffer length will be rounded down to a multiple of `frame_size`. + fn buffer_len_from_offset(&self, offset: usize) -> io::Result<usize> { + if offset > self.samples_len { + return Err(io::Error::new( + io::ErrorKind::InvalidInput, + format!( + "Buffer offset {} exceeds the length of samples area ({}).", + offset, self.samples_len + ), + )); + } + + let used_size = self.get_used_size(); + let frame_size = self.get_frame_size(); + + // We explicitly allow a buffer shorter than used_size, but only + // at the end of the samples area. + // This is useful if we're playing a file where the number of samples is + // not a multiple of used_size (meaning the length of the samples area + // won't be either). Then, the last buffer played will be smaller than + // used_size. + let mut buffer_length = used_size.min(self.samples_len - offset); + if buffer_length < frame_size { + return Err(io::Error::new( + io::ErrorKind::InvalidInput, + format!( + "Buffer offset {} gives buffer length {} smaller than frame size {}.", + offset, buffer_length, frame_size + ), + )); + } + + // Round buffer_length down to a multiple of frame size + buffer_length = buffer_length / frame_size * frame_size; + Ok(buffer_length) + } + + /// Gets the base of the write buffer and the writable length (rounded to `frame_size`). + /// Does not take into account the write offset. /// /// # Returns /// - /// * (`usize`, `usize`) - write offset in bytes and buffer length in bytes. - pub fn get_offset_and_len(&self) -> (usize, usize) { - let used_size = self.get_used_size(); - let offset = self.get_write_buf_idx() as usize * used_size; - (offset, used_size) + /// * (`usize`, `usize`) - write buffer base as an offset from the start of + /// the samples area and buffer length in bytes. + pub fn get_write_offset_and_len(&self) -> io::Result<(usize, usize)> { + let idx = self.get_write_buf_idx() as usize; + let offset = self.get_buffer_offset(idx)?; + let len = self.buffer_len_from_offset(offset)?; + + Ok((offset, len)) } - /// Gets the read offset of the readable buffer. + /// Gets the buffer offset of the read buffer. /// /// # Returns /// /// * `usize` - read offset in bytes - pub fn get_read_offset(&self) -> usize { - self.get_read_buf_idx() as usize * self.get_used_size() + pub fn get_read_buffer_offset(&self) -> io::Result<usize> { + let idx = self.get_read_buf_idx() as usize; + self.get_buffer_offset(idx) + } + + /// Gets the offset of a buffer from the start of samples. + /// + /// # Arguments + /// `index` - 0 <= `index` < `CRAS_NUM_SHM_BUFFERS`. The index of the buffer + /// for which we want the `buffer_offset`. + /// + /// # Returns + /// * `usize` - buffer offset in bytes + fn get_buffer_offset(&self, idx: usize) -> io::Result<usize> { + let buffer_offset = self + .buffer_offset + .get(idx) + .ok_or_else(index_out_of_range)? + .load() as usize; + self.check_buffer_offset(idx, buffer_offset)?; + Ok(buffer_offset) } /// Gets the number of bytes per frame from the shared memory structure. @@ -188,23 +259,27 @@ impl<'a> CrasAudioHeader<'a> { /// out of range or not. /// /// # Arguments - /// `offset` - 0 <= `offset` <= `used_size` && `offset` + `used_size` <= + /// `idx` - The index of the buffer for which we're checking the offset. + /// `offset` - 0 <= `offset` <= `used_size` && `buffer_offset[idx]` + `offset` <= /// `samples_len`. Writable or readable size equals to 0 when offset equals /// to `used_size`. /// /// # Errors - /// Returns an error if `offset` is out of range. - fn check_offset(&self, offset: u32) -> io::Result<()> { - if offset as usize <= self.get_used_size() - && offset as usize + self.get_used_size() <= self.samples_len - { - Ok(()) - } else { - Err(io::Error::new( + /// Returns an error if `offset` is out of range or if idx is not a valid + /// buffer idx. + fn check_rw_offset(&self, idx: usize, offset: u32) -> io::Result<()> { + let buffer_len = self.buffer_len_from_offset(self.get_buffer_offset(idx)?)?; + if offset as usize > buffer_len { + return Err(io::Error::new( io::ErrorKind::InvalidInput, - "Offset out of range.", - )) + format!( + "Offset {} is larger than buffer size {}.", + offset, buffer_len + ), + )); } + + Ok(()) } /// Sets `write_offset[idx]` to the count of written bytes. @@ -218,7 +293,7 @@ impl<'a> CrasAudioHeader<'a> { /// # Errors /// Returns an error if `offset` is out of range. fn set_write_offset(&mut self, idx: usize, offset: u32) -> io::Result<()> { - self.check_offset(offset)?; + self.check_rw_offset(idx, offset)?; let write_offset = self.write_offset.get(idx).ok_or_else(index_out_of_range)?; write_offset.store(offset); Ok(()) @@ -235,12 +310,64 @@ impl<'a> CrasAudioHeader<'a> { /// # Errors /// Returns error if index out of range. fn set_read_offset(&mut self, idx: usize, offset: u32) -> io::Result<()> { - self.check_offset(offset)?; + self.check_rw_offset(idx, offset)?; let read_offset = self.read_offset.get(idx).ok_or_else(index_out_of_range)?; read_offset.store(offset); Ok(()) } + /// Check that `offset` is a valid buffer offset for the buffer at `idx` + /// An offset is not valid if it is + /// * outside of the samples area + /// * overlaps some other buffer `[other_offset, other_offset + used_size)` + /// * is close enough to the end of the samples area that the buffer would + /// be shorter than `frame_size`. + fn check_buffer_offset(&self, idx: usize, offset: usize) -> io::Result<()> { + let start = offset; + let end = start + self.buffer_len_from_offset(start)?; + + let other_idx = (idx ^ 1) as usize; + let other_start = self + .buffer_offset + .get(other_idx) + .ok_or_else(index_out_of_range)? + .load() as usize; + let other_end = other_start + self.buffer_len_from_offset(other_start)?; + if start < other_end && other_start < end { + return Err(io::Error::new( + io::ErrorKind::InvalidInput, + format!( + "Setting buffer {} to [{}, {}) overlaps buffer {} at [{}, {})", + idx, start, end, other_idx, other_start, other_end, + ), + )); + } + Ok(()) + } + + /// Sets the location of the audio buffer `idx` within the samples area to + /// `offset`, so that CRAS will read/write samples for that buffer from that + /// offset. + /// + /// # Arguments + /// `idx` - 0 <= `idx` < `CRAS_NUM_SHM_BUFFERS` + /// `offset` - 0 <= `offset` && `offset` + `frame_size` <= `samples_len` + /// + /// # Errors + /// If `idx` is out of range + /// If the offset is invalid, which can happen if `offset` is + /// * outside of the samples area + /// * overlaps some other buffer `[other_offset, other_offset + used_size)` + /// * is close enough to the end of the samples area that the buffer would + /// be shorter than `frame_size`. + fn set_buffer_offset(&mut self, idx: usize, offset: usize) -> io::Result<()> { + self.check_buffer_offset(idx, offset)?; + + let buffer_offset = self.buffer_offset.get(idx).ok_or_else(index_out_of_range)?; + buffer_offset.store(offset as u32); + Ok(()) + } + /// Commits written frames by switching the current buffer to the other one /// after samples are ready and indexes of current buffer are all set. /// - Sets `write_offset` of current buffer to `frame_count * frame_size` @@ -551,10 +678,16 @@ impl CrasServerStateShmFd { #[cfg(test)] mod tests { use super::*; - use std::ffi::CString; + use std::fs::File; + use std::os::unix::io::IntoRawFd; + use sys_util::{kernel_has_memfd, SharedMemory}; + #[test] fn cras_audio_header_switch_test() { - let mut header = create_cras_audio_header("/tmp_cras_audio_header1", 0); + if !kernel_has_memfd() { + return; + } + let mut header = create_cras_audio_header(20); assert_eq!(0, header.get_write_buf_idx()); header.switch_write_buf_idx(); assert_eq!(1, header.get_write_buf_idx()); @@ -562,43 +695,63 @@ mod tests { #[test] fn cras_audio_header_write_offset_test() { - let mut header = create_cras_audio_header("/tmp_cras_audio_header2", 20); + if !kernel_has_memfd() { + return; + } + let mut header = create_cras_audio_header(20); header.frame_size.store(2); header.used_size.store(5); + header.set_buffer_offset(0, 12).unwrap(); assert_eq!(0, header.write_offset[0].load()); // Index out of bound assert!(header.set_write_offset(2, 5).is_err()); // Offset out of bound + // Buffer length is 4, since that's the largest multiple of frame_size + // less than used_size. assert!(header.set_write_offset(0, 6).is_err()); assert_eq!(0, header.write_offset[0].load()); - assert!(header.set_write_offset(0, 5).is_ok()); - assert_eq!(5, header.write_offset[0].load()); - mem::forget(header); + assert!(header.set_write_offset(0, 5).is_err()); + assert_eq!(0, header.write_offset[0].load()); + assert!(header.set_write_offset(0, 4).is_ok()); + assert_eq!(4, header.write_offset[0].load()); } #[test] fn cras_audio_header_read_offset_test() { - let mut header = create_cras_audio_header("/tmp_cras_audio_header3", 20); + if !kernel_has_memfd() { + return; + } + let mut header = create_cras_audio_header(20); header.frame_size.store(2); header.used_size.store(5); + header.set_buffer_offset(0, 12).unwrap(); - assert_eq!(0, { header.read_offset[0].load() }); + assert_eq!(0, header.read_offset[0].load()); // Index out of bound assert!(header.set_read_offset(2, 5).is_err()); // Offset out of bound + // Buffer length is 4, since that's the largest multiple of frame_size + // less than used_size. assert!(header.set_read_offset(0, 6).is_err()); assert_eq!(0, header.read_offset[0].load()); - assert!(header.set_read_offset(0, 5).is_ok()); - assert_eq!(5, header.read_offset[0].load()); + assert!(header.set_read_offset(0, 5).is_err()); + assert_eq!(0, header.read_offset[0].load()); + assert!(header.set_read_offset(0, 4).is_ok()); + assert_eq!(4, header.read_offset[0].load()); } #[test] fn cras_audio_header_commit_written_frame_test() { - let mut header = create_cras_audio_header("/tmp_cras_audio_header4", 20); + if !kernel_has_memfd() { + return; + } + let mut header = create_cras_audio_header(20); header.frame_size.store(2); header.used_size.store(10); header.read_offset[0].store(10); + header.set_buffer_offset(0, 10).unwrap(); + assert!(header.commit_written_frames(5).is_ok()); assert_eq!(header.write_offset[0].load(), 10); assert_eq!(header.read_offset[0].load(), 0); @@ -607,7 +760,10 @@ mod tests { #[test] fn cras_audio_header_get_readable_frames_test() { - let header = create_cras_audio_header("/tmp_cras_audio_header5", 20); + if !kernel_has_memfd() { + return; + } + let header = create_cras_audio_header(20); header.frame_size.store(2); header.used_size.store(10); header.read_offset[0].store(2); @@ -620,7 +776,10 @@ mod tests { #[test] fn cras_audio_header_commit_read_frames_test() { - let mut header = create_cras_audio_header("/tmp_cras_audio_header6", 20); + if !kernel_has_memfd() { + return; + } + let mut header = create_cras_audio_header(20); header.frame_size.store(2); header.used_size.store(10); header.read_offset[0].store(2); @@ -641,52 +800,169 @@ mod tests { } #[test] + fn cras_audio_header_get_write_offset_and_len() { + if !kernel_has_memfd() { + return; + } + let header = create_cras_audio_header(30); + header.frame_size.store(2); + header.used_size.store(10); + header.write_buf_idx.store(0); + header.read_offset[0].store(0); + header.write_offset[0].store(0); + header.buffer_offset[0].store(0); + + header.read_buf_idx.store(1); + header.read_offset[1].store(0); + header.write_offset[1].store(0); + header.buffer_offset[1].store(10); + + // standard offsets and lens + let (offset, len) = header.get_write_offset_and_len().unwrap(); + assert_eq!(offset, 0); + assert_eq!(len, 10); + + header.write_buf_idx.store(1); + header.read_buf_idx.store(0); + let (offset, len) = header.get_write_offset_and_len().unwrap(); + assert_eq!(offset, 10); + assert_eq!(len, 10); + + // relocate buffer offsets + header.buffer_offset[1].store(16); + let (offset, len) = header.get_write_offset_and_len().unwrap(); + assert_eq!(offset, 16); + assert_eq!(len, 10); + + header.buffer_offset[0].store(5); + header.write_buf_idx.store(0); + let (offset, len) = header.get_write_offset_and_len().unwrap(); + assert_eq!(offset, 5); + assert_eq!(len, 10); + + header.write_buf_idx.store(0); + header.buffer_offset[0].store(2); + header.read_buf_idx.store(1); + header.buffer_offset[1].store(10); + let result = header.get_write_offset_and_len(); + // Should be an error as write buffer would overrun into other buffer. + assert!(result.is_err()); + + header.buffer_offset[0].store(24); + header.buffer_offset[1].store(10); + let (offset, len) = header.get_write_offset_and_len().unwrap(); + // Should be ok since we're only running up against the end of samples. + assert_eq!(offset, 24); + assert_eq!(len, 6); + + header.buffer_offset[0].store(25); + let (offset, len) = header.get_write_offset_and_len().unwrap(); + // Should be ok, but we'll truncate len to frame_size. + assert_eq!(offset, 25); + assert_eq!(len, 4); + + header.buffer_offset[0].store(29); + let result = header.get_write_offset_and_len(); + // Should be an error as buffer is smaller than frame_size. + assert!(result.is_err()); + } + + #[test] + fn cras_audio_header_set_buffer_offset() { + if !kernel_has_memfd() { + return; + } + let mut header = create_cras_audio_header(30); + header.frame_size.store(2); + header.used_size.store(10); + header.write_buf_idx.store(0); + header.read_offset[0].store(0); + header.write_offset[0].store(0); + header.buffer_offset[0].store(0); + + header.read_buf_idx.store(1); + header.read_offset[1].store(0); + header.write_offset[1].store(0); + header.buffer_offset[1].store(10); + + // Setting buffer_offset to overlap with other buffer is not okay + assert!(header.set_buffer_offset(0, 10).is_err()); + + header.buffer_offset[0].store(0); + header.write_offset[1].store(8); + // With samples, it's still an error. + assert!(header.set_buffer_offset(0, 10).is_err()); + + // Setting the offset past the end of the other buffer is okay + assert!(header.set_buffer_offset(0, 20).is_ok()); + + // Setting buffer offset such that buffer length is less than used_size + // is okay, but only at the end of the samples area. + assert!(header.set_buffer_offset(0, 21).is_ok()); + assert!(header.set_buffer_offset(0, 27).is_ok()); + + // It's not okay if we get a buffer with length less than frame_size. + assert!(header.set_buffer_offset(0, 29).is_err()); + assert!(header.set_buffer_offset(0, 30).is_err()); + + // If we try to overlap another buffer with that other buffer at the end, + // it's not okay. + assert!(header.set_buffer_offset(1, 25).is_err()); + assert!(header.set_buffer_offset(1, 27).is_err()); + assert!(header.set_buffer_offset(1, 28).is_err()); + + // Setting buffer offset past the end of samples is an error. + assert!(header.set_buffer_offset(0, 33).is_err()); + } + + #[test] fn create_header_and_buffers_test() { - let header_fd = cras_audio_header_fd("/tmp_audio_shm_header"); - let samples_fd = cras_audio_samples_fd("/tmp_audio_shm_samples", 20); + if !kernel_has_memfd() { + return; + } + let header_fd = cras_audio_header_fd(); + let samples_fd = cras_audio_samples_fd(20); let res = create_header_and_buffers(header_fd, samples_fd); res.expect("Failed to create header and buffer."); } - fn create_cras_audio_header(name: &str, samples_len: usize) -> CrasAudioHeader { - CrasAudioHeader::new(cras_audio_header_fd(name), samples_len).unwrap() + fn create_shm(size: usize) -> File { + let mut shm = SharedMemory::new(None).expect("failed to create shm"); + shm.set_size(size as u64).expect("failed to set shm size"); + shm.into() } - fn cras_audio_header_fd(name: &str) -> CrasAudioShmHeaderFd { - let size = mem::size_of::<cras_audio_shm_header>(); - let fd = cras_shm_open_rw(name, size); - unsafe { CrasAudioShmHeaderFd::new(fd) } + fn create_cras_audio_header<'a>(samples_len: usize) -> CrasAudioHeader<'a> { + CrasAudioHeader::new(cras_audio_header_fd(), samples_len).unwrap() } - fn cras_audio_samples_fd(name: &str, len: usize) -> CrasShmFd { - let fd = cras_shm_open_rw(name, len); - unsafe { CrasShmFd::new(fd, len) } + fn cras_audio_header_fd() -> CrasAudioShmHeaderFd { + let size = mem::size_of::<cras_audio_shm_header>(); + let shm = create_shm(size); + unsafe { CrasAudioShmHeaderFd::new(shm.into_raw_fd()) } } - fn cras_shm_open_rw(name: &str, size: usize) -> libc::c_int { - unsafe { - let cstr_name = CString::new(name).expect("cras_shm_open_rw: new CString failed"); - let fd = libc::shm_open( - cstr_name.as_ptr() as *const _, - libc::O_CREAT | libc::O_EXCL | libc::O_RDWR, - 0x0600, - ); - assert_ne!(fd, -1, "cras_shm_open_rw: shm_open error"); - libc::ftruncate(fd, size as libc::off_t); - fd - } + fn cras_audio_samples_fd(size: usize) -> CrasShmFd { + let shm = create_shm(size); + unsafe { CrasShmFd::new(shm.into_raw_fd(), size) } } #[test] fn cras_mmap_pass() { - let fd = cras_shm_open_rw("/tmp_cras_shm_test_1", 100); - let rc = unsafe { cras_mmap(10, libc::PROT_READ, fd) }; + if !kernel_has_memfd() { + return; + } + let shm = create_shm(100); + let rc = unsafe { cras_mmap(10, libc::PROT_READ, shm.as_raw_fd()) }; assert!(rc.is_ok()); unsafe { libc::munmap(rc.unwrap(), 10) }; } #[test] fn cras_mmap_failed() { + if !kernel_has_memfd() { + return; + } let rc = unsafe { cras_mmap(10, libc::PROT_READ, -1) }; assert!(rc.is_err()); } diff --git a/cras/client/libcras/src/cras_stream.rs b/cras/client/libcras/src/cras_stream.rs index c069ff31..bd9520a1 100644 --- a/cras/client/libcras/src/cras_stream.rs +++ b/cras/client/libcras/src/cras_stream.rs @@ -251,12 +251,12 @@ impl<'a, T: CrasStreamData<'a> + BufferDrop> Drop for CrasStream<'a, T> { } impl<'a, T: CrasStreamData<'a> + BufferDrop> PlaybackBufferStream for CrasStream<'a, T> { - fn next_playback_buffer(&mut self) -> Result<PlaybackBuffer, Box<error::Error>> { + fn next_playback_buffer(&mut self) -> Result<PlaybackBuffer, Box<dyn error::Error>> { // Wait for request audio message self.wait_request_data()?; let (frame_size, (offset, len)) = match self.controls.header_mut() { None => return Err(Error::new(ErrorType::NoShmError).into()), - Some(header) => (header.get_frame_size(), header.get_offset_and_len()), + Some(header) => (header.get_frame_size(), header.get_write_offset_and_len()?), }; let buf = match self.audio_buffer.as_mut() { None => return Err(Error::new(ErrorType::NoShmError).into()), @@ -267,7 +267,7 @@ impl<'a, T: CrasStreamData<'a> + BufferDrop> PlaybackBufferStream for CrasStream } impl<'a, T: CrasStreamData<'a> + BufferDrop> CaptureBufferStream for CrasStream<'a, T> { - fn next_capture_buffer(&mut self) -> Result<CaptureBuffer, Box<error::Error>> { + fn next_capture_buffer(&mut self) -> Result<CaptureBuffer, Box<dyn error::Error>> { // Wait for data ready message let frames = self.wait_data_ready()?; let (frame_size, shm_frames, offset) = match self.controls.header_mut() { @@ -275,7 +275,7 @@ impl<'a, T: CrasStreamData<'a> + BufferDrop> CaptureBufferStream for CrasStream< Some(header) => ( header.get_frame_size(), header.get_readable_frames()?, - header.get_read_offset(), + header.get_read_buffer_offset()?, ), }; let len = min(shm_frames, frames as usize) * frame_size; diff --git a/cras/client/libcras/src/libcras.rs b/cras/client/libcras/src/libcras.rs index da767b3d..c81e540d 100644 --- a/cras/client/libcras/src/libcras.rs +++ b/cras/client/libcras/src/libcras.rs @@ -25,7 +25,7 @@ //! use std::thread::{spawn, JoinHandle}; //! type Result<T> = std::result::Result<T, Box<std::error::Error>>; //! -//! use libcras::CrasClient; +//! use libcras::{CrasClient, CrasClientType}; //! use audio_streams::StreamSource; //! //! const BUFFER_SIZE: usize = 256; @@ -37,6 +37,7 @@ //! # match args.len() { //! # 2 => { //! let mut cras_client = CrasClient::new()?; +//! cras_client.set_client_type(CrasClientType::CRAS_CLIENT_TYPE_TEST); //! let (_control, mut stream) = cras_client //! .new_playback_stream(NUM_CHANNELS, FRAME_RATE, BUFFER_SIZE)?; //! @@ -76,7 +77,7 @@ //! use std::thread::{spawn, JoinHandle}; //! type Result<T> = std::result::Result<T, Box<std::error::Error>>; //! -//! use libcras::CrasClient; +//! use libcras::{CrasClient, CrasClientType}; //! use audio_streams::StreamSource; //! //! const BUFFER_SIZE: usize = 256; @@ -88,6 +89,7 @@ //! # match args.len() { //! # 2 => { //! let mut cras_client = CrasClient::new()?; +//! cras_client.set_client_type(CrasClientType::CRAS_CLIENT_TYPE_TEST); //! let (_control, mut stream) = cras_client //! .new_capture_stream(NUM_CHANNELS, FRAME_RATE, BUFFER_SIZE)?; //! @@ -124,6 +126,7 @@ use audio_streams::{ capture::{CaptureBufferStream, DummyCaptureStream}, BufferDrop, DummyStreamControl, PlaybackBufferStream, StreamControl, StreamSource, }; +pub use cras_sys::gen::CRAS_CLIENT_TYPE as CrasClientType; use cras_sys::gen::*; use sys_util::{PollContext, PollToken}; @@ -143,7 +146,6 @@ pub enum ErrorType { CrasStreamError(cras_stream::Error), IoError(io::Error), SysUtilError(sys_util::Error), - NoClientId, MessageTypeError, UnexpectedExit, } @@ -168,7 +170,6 @@ impl fmt::Display for Error { ErrorType::CrasStreamError(ref err) => err.fmt(f), ErrorType::IoError(ref err) => err.fmt(f), ErrorType::SysUtilError(ref err) => err.fmt(f), - ErrorType::NoClientId => write!(f, "client_id dose not exists"), ErrorType::MessageTypeError => write!(f, "Message type error"), ErrorType::UnexpectedExit => write!(f, "Unexpected exit"), } @@ -205,9 +206,10 @@ impl From<cras_client_message::Error> for Error { /// to CRAS server. pub struct CrasClient { server_socket: CrasServerSocket, - client_id: Option<u32>, + client_id: u32, next_stream_id: u32, cras_capture: bool, + client_type: CRAS_CLIENT_TYPE, } impl CrasClient { @@ -222,25 +224,26 @@ impl CrasClient { /// Returns error if error occurs while handling server message or message /// type is incorrect pub fn new() -> Result<Self> { - // Initializes a client - let server_socket = CrasServerSocket::new()?; - let mut cras_client = Self { - server_socket, - client_id: None, - next_stream_id: 0, - cras_capture: false, - }; + // Create a connection to the server. + let mut server_socket = CrasServerSocket::new()?; // Gets client ID from server - cras_client.client_id = Some({ - match cras_client.handle_server_message()? { + let client_id = { + match CrasClient::wait_for_message(&mut server_socket)? { ServerResult::Connected(res, _server_state_fd) => res as u32, _ => { return Err(Error::new(ErrorType::MessageTypeError)); } } - }); - Ok(cras_client) + }; + + Ok(Self { + server_socket, + client_id, + next_stream_id: 0, + cras_capture: false, + client_type: CRAS_CLIENT_TYPE::CRAS_CLIENT_TYPE_UNKNOWN, + }) } /// Enables capturing audio through CRAS server. @@ -248,6 +251,11 @@ impl CrasClient { self.cras_capture = true; } + /// Set the type of this client to report to CRAS when connecting streams. + pub fn set_client_type(&mut self, client_type: CRAS_CLIENT_TYPE) { + self.client_type = client_type; + } + // Gets next server_stream_id from client and increment stream_id counter. fn next_server_stream_id(&mut self) -> Result<u32> { let res = self.next_stream_id; @@ -257,7 +265,7 @@ impl CrasClient { // Gets server_stream_id from given stream_id fn server_stream_id(&self, stream_id: &u32) -> Result<u32> { - Ok((self.client_id.ok_or(Error::new(ErrorType::NoClientId))? << 16) | stream_id) + Ok((self.client_id << 16) | stream_id) } // Creates general stream with given parameters @@ -289,6 +297,8 @@ impl CrasClient { format: audio_format, dev_idx: CRAS_SPECIAL_DEVICE::NO_DEVICE as u32, effects: 0, + client_type: self.client_type, + client_shm_size: 0, }; // Creates AudioSocket pair @@ -312,7 +322,7 @@ impl CrasClient { ); loop { - let result = self.handle_server_message()?; + let result = CrasClient::wait_for_message(&mut self.server_socket)?; if let ServerResult::StreamConnected(_stream_id, header_fd, samples_fd) = result { stream.init_shm(header_fd, samples_fd)?; break; @@ -322,14 +332,14 @@ impl CrasClient { Ok(stream) } - // Blocks handling the first server message received from server socket. - fn handle_server_message(&self) -> Result<ServerResult> { + // Blocks handling the first server message received from `socket`. + fn wait_for_message(socket: &mut CrasServerSocket) -> Result<ServerResult> { #[derive(PollToken)] enum Token { ServerMsg, } - let poll_ctx: PollContext<Token> = PollContext::new() - .and_then(|pc| pc.add(&self.server_socket, Token::ServerMsg).and(Ok(pc)))?; + let poll_ctx: PollContext<Token> = + PollContext::new().and_then(|pc| pc.add(socket, Token::ServerMsg).and(Ok(pc)))?; let events = poll_ctx.wait()?; // Check the first readable message @@ -339,7 +349,7 @@ impl CrasClient { .ok_or_else(|| Error::new(ErrorType::UnexpectedExit)) .and_then(|ref token| { match token { - Token::ServerMsg => ServerResult::handle_server_message(&self.server_socket), + Token::ServerMsg => ServerResult::handle_server_message(socket), } .map_err(Into::into) }) @@ -354,7 +364,7 @@ impl StreamSource for CrasClient { buffer_size: usize, ) -> std::result::Result< (Box<dyn StreamControl>, Box<dyn PlaybackBufferStream>), - Box<error::Error>, + Box<dyn error::Error>, > { Ok(( Box::new(DummyStreamControl::new()), @@ -375,7 +385,7 @@ impl StreamSource for CrasClient { buffer_size: usize, ) -> std::result::Result< (Box<dyn StreamControl>, Box<dyn CaptureBufferStream>), - Box<error::Error>, + Box<dyn error::Error>, > { if self.cras_capture { Ok(( diff --git a/cras/src/Makefile.am b/cras/src/Makefile.am index e3cb4e0d..acc62d4a 100644 --- a/cras/src/Makefile.am +++ b/cras/src/Makefile.am @@ -101,6 +101,7 @@ cras_server_SOURCES = \ dsp/dsp_util.c \ dsp/eq.c \ dsp/eq2.c \ + plc/cras_plc.c\ server/audio_thread.c \ server/buffer_share.c \ server/config/cras_board_config.c \ @@ -138,7 +139,10 @@ cras_server_SOURCES = \ server/cras_observer.c \ server/cras_ramp.c \ server/cras_rclient.c \ + server/cras_rclient_util.c \ server/cras_control_rclient.c \ + server/cras_playback_rclient.c \ + server/cras_capture_rclient.c \ server/cras_rstream.c \ server/cras_server_metrics.c \ server/cras_system_state.c \ @@ -160,7 +164,7 @@ libcrasserver_la_SOURCES = \ $(cras_server_SOURCES) libcrasserver_la_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/common \ -I$(top_srcdir)/src/dsp -I$(top_srcdir)/src/server \ - -I$(top_srcdir)/src/server/config \ + -I$(top_srcdir)/src/server/config -I$(top_srcdir)/src/plc \ $(DBUS_CFLAGS) $(SBC_CFLAGS) $(SELINUX_CFLAGS) libcrasserver_la_LIBADD = \ libcrasmix.la \ @@ -179,7 +183,7 @@ cras_SOURCES = \ cras_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/common \ -I$(top_srcdir)/src/dsp -I$(top_srcdir)/src/server \ - -I$(top_srcdir)/src/server/config \ + -I$(top_srcdir)/src/server/config -I$(top_srcdir)/src/plc \ $(DBUS_CFLAGS) $(SBC_CFLAGS) cras_LDADD = \ @@ -209,7 +213,7 @@ libcrasmix_la_SOURCES = \ libcrasmix_la_CFLAGS = \ $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/common \ -I$(top_srcdir)/src/dsp -I$(top_srcdir)/src/server \ - -I$(top_srcdir)/src/server/config \ + -I$(top_srcdir)/src/server/config -I$(top_srcdir)/src/plc \ $(DBUS_CFLAGS) $(SBC_CFLAGS) libcrasmix_sse42_la_SOURCES = \ @@ -218,7 +222,7 @@ libcrasmix_sse42_la_SOURCES = \ libcrasmix_sse42_la_CFLAGS = \ $(COMMON_SIMD_CPPFLAGS) -I$(top_srcdir)/src/common \ -I$(top_srcdir)/src/dsp -I$(top_srcdir)/src/server \ - -I$(top_srcdir)/src/server/config \ + -I$(top_srcdir)/src/server/config -I$(top_srcdir)/src/plc \ $(DBUS_CFLAGS) $(SSE42_CFLAGS) libcrasmix_avx_la_SOURCES = \ @@ -227,7 +231,7 @@ libcrasmix_avx_la_SOURCES = \ libcrasmix_avx_la_CFLAGS = \ $(COMMON_SIMD_CPPFLAGS) -I$(top_srcdir)/src/common \ -I$(top_srcdir)/src/dsp -I$(top_srcdir)/src/server \ - -I$(top_srcdir)/src/server/config \ + -I$(top_srcdir)/src/server/config -I$(top_srcdir)/src/plc \ $(DBUS_CFLAGS) $(AVX_CFLAGS) libcrasmix_avx2_la_SOURCES = \ @@ -236,7 +240,7 @@ libcrasmix_avx2_la_SOURCES = \ libcrasmix_avx2_la_CFLAGS = \ $(COMMON_SIMD_CPPFLAGS) -I$(top_srcdir)/src/common \ -I$(top_srcdir)/src/dsp -I$(top_srcdir)/src/server \ - -I$(top_srcdir)/src/server/config \ + -I$(top_srcdir)/src/server/config -I$(top_srcdir)/src/plc \ $(DBUS_CFLAGS) $(AVX2_CFLAGS) libcrasmix_fma_la_SOURCES = \ @@ -245,7 +249,7 @@ libcrasmix_fma_la_SOURCES = \ libcrasmix_fma_la_CFLAGS = \ $(COMMON_SIMD_CPPFLAGS) -I$(top_srcdir)/src/common \ -I$(top_srcdir)/src/dsp -I$(top_srcdir)/src/server \ - -I$(top_srcdir)/src/server/config \ + -I$(top_srcdir)/src/server/config -I$(top_srcdir)/src/plc \ $(DBUS_CFLAGS) $(FMA_CFLAGS) lib_LTLIBRARIES = libcras.la @@ -376,6 +380,8 @@ TESTS = \ ramp_unittest \ rate_estimator_unittest \ control_rclient_unittest \ + playback_rclient_unittest \ + capture_rclient_unittest \ rstream_unittest \ shm_unittest \ server_metrics_unittest \ @@ -389,27 +395,27 @@ TESTS = \ check_PROGRAMS = $(TESTS) -cras_test_client_SOURCES = tests/cras_test_client.c +cras_test_client_SOURCES = tools/cras_test_client/cras_test_client.c cras_test_client_LDADD = -lm libcras.la cras_test_client_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/libcras \ -I$(top_srcdir)/src/common -I$(top_builddir)/src/common -tests/cras_test_client.c: common/cras_version.h +tools/cras_test_client/cras_test_client.c: common/cras_version.h -cras_monitor_SOURCES = tests/cras_monitor.c +cras_monitor_SOURCES = tools/cras_monitor/cras_monitor.c cras_monitor_LDADD = -lm libcras.la cras_monitor_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/libcras \ -I$(top_srcdir)/src/common -I$(top_builddir)/src/common -tests/cras_monitor.c: common/cras_version.h +tools/cras_monitor/cras_monitor.c: common/cras_version.h -cras_router_SOURCES = tests/cras_router.c +cras_router_SOURCES = tools/cras_router/cras_router.c cras_router_LDADD = -lm libcras.la cras_router_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/libcras \ -I$(top_srcdir)/src/common -I$(top_srcdir)/src/dsp \ -I$(top_srcdir)/src/server -I$(top_builddir)/src/common -tests/cras_router.c: common/cras_version.h +tools/cras_router/cras_router.c: common/cras_version.h CLEANFILES = common/cras_version.h .PHONY: common/cras_version.h @@ -477,6 +483,14 @@ cmpraw_SOURCES = dsp/tests/cmpraw.c dsp/tests/raw.c cmpraw_LDADD = -lm cmpraw_CPPFLAGS = $(COMMON_CPPFLAGS) $(DSP_INCLUDE_PATHS) +cras_plc_test_SOURCES = plc/cras_plc_test.c plc/cras_plc.c \ + common/cras_sbc_codec.c +cras_plc_test_LDADD = -lrt -lm $(SBC_LIBS) +cras_plc_test_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/plc \ + -I$(top_srcdir)/src/common \ + $(SBC_CFLAGS) +check_PROGRAMS += cras_plc_test + # unit tests alert_unittest_SOURCES = tests/alert_unittest.cc \ server/cras_alert.c @@ -513,8 +527,10 @@ audio_format_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/server \ audio_format_unittest_LDADD = -lgtest -lpthread if HAVE_DBUS -a2dp_info_unittest_SOURCES = tests/a2dp_info_unittest.cc \ - server/cras_a2dp_info.c +a2dp_info_unittest_SOURCES = \ + server/cras_a2dp_info.c \ + tests/a2dp_info_unittest.cc \ + tests/sbc_codec_stub.cc a2dp_info_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/server \ -I$(top_srcdir)/src/common a2dp_info_unittest_LDADD = -lgtest -lpthread @@ -578,7 +594,8 @@ array_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/common array_unittest_LDADD = -lgtest -lpthread audio_thread_unittest_SOURCES = tests/audio_thread_unittest.cc \ - server/dev_io.c tests/empty_audio_stub.cc tests/metrics_stub.cc + server/dev_io.c tests/empty_audio_stub.cc tests/metrics_stub.cc \ + common/cras_shm.c audio_thread_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) \ -I$(top_srcdir)/src/common -I$(top_srcdir)/src/server audio_thread_unittest_LDADD = -lgtest -lpthread -lrt @@ -662,10 +679,10 @@ dev_io_unittest_LDADD = \ -lgtest -lrt -lpthread -ldl -lm -lspeexdsp dev_stream_unittest_SOURCES = tests/dev_stream_unittest.cc \ - server/dev_stream.c + server/dev_stream.c common/cras_shm.c dev_stream_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) \ -I$(top_srcdir)/src/common -I$(top_srcdir)/src/server -dev_stream_unittest_LDADD = -lgtest -liniparser -lpthread +dev_stream_unittest_LDADD = -lgtest -liniparser -lpthread -lrt device_blacklist_unittest_SOURCES = tests/device_blacklist_unittest.cc \ server/config/cras_device_blacklist.c @@ -749,9 +766,10 @@ fmt_conv_ops_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/common \ -I$(top_srcdir)/src/server fmt_conv_ops_unittest_LDADD = -lasound -lspeexdsp -lgtest -lpthread -hfp_info_unittest_SOURCES = tests/hfp_info_unittest.cc +hfp_info_unittest_SOURCES = tests/hfp_info_unittest.cc \ + tests/metrics_stub.cc tests/sbc_codec_stub.cc hfp_info_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/common \ - -I$(top_srcdir)/src/server + -I$(top_srcdir)/src/server -I$(top_srcdir)/src/plc hfp_info_unittest_LDADD = -lgtest -lpthread if HAVE_DBUS @@ -768,7 +786,7 @@ hfp_alsa_iodev_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) \ hfp_alsa_iodev_unittest_LDADD = -lgtest -lpthread $(DBUS_LIBS) hfp_ag_profile_unittest_SOURCES = tests/hfp_ag_profile_unittest.cc \ - server/cras_hfp_ag_profile.c common/sfh.c + server/cras_hfp_ag_profile.c common/sfh.c tests/metrics_stub.cc hfp_ag_profile_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) \ -I$(top_srcdir)/src/common -I$(top_srcdir)/src/server $(DBUS_CFLAGS) hfp_ag_profile_unittest_LDADD = -lgtest -lpthread $(DBUS_LIBS) @@ -806,10 +824,10 @@ input_data_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/common \ input_data_unittest_LDADD = -lgtest -lpthread iodev_unittest_SOURCES = tests/iodev_unittest.cc \ - server/cras_iodev.c + server/cras_iodev.c common/cras_shm.c iodev_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/common \ -I$(top_srcdir)/src/server -iodev_unittest_LDADD = -lgtest -lpthread +iodev_unittest_LDADD = -lgtest -lpthread -lrt mix_unittest_SOURCES = tests/mix_unittest.cc server/cras_mix.c mix_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/common \ @@ -855,6 +873,18 @@ control_rclient_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) \ -I$(top_srcdir)/src/server $(CRAS_UT_TMPDIR_CFLAGS) control_rclient_unittest_LDADD = -lgtest -lpthread +playback_rclient_unittest_SOURCES = tests/playback_rclient_unittest.cc +playback_rclient_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) \ + -I$(top_srcdir)/src/common \ + -I$(top_srcdir)/src/server $(CRAS_UT_TMPDIR_CFLAGS) +playback_rclient_unittest_LDADD = -lgtest -lpthread + +capture_rclient_unittest_SOURCES = tests/capture_rclient_unittest.cc +capture_rclient_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) \ + -I$(top_srcdir)/src/common \ + -I$(top_srcdir)/src/server $(CRAS_UT_TMPDIR_CFLAGS) +capture_rclient_unittest_LDADD = -lgtest -lpthread + rstream_unittest_SOURCES = tests/rstream_unittest.cc server/cras_rstream.c \ common/cras_shm.c $(CRAS_SELINUX_UNITTEST_SOURCES) rstream_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/common \ diff --git a/cras/src/alsa_plugin/pcm_cras.c b/cras/src/alsa_plugin/pcm_cras.c index ba51c98b..715db2cc 100644 --- a/cras/src/alsa_plugin/pcm_cras.c +++ b/cras/src/alsa_plugin/pcm_cras.c @@ -241,6 +241,8 @@ static int snd_pcm_cras_start(snd_pcm_ioplug_t *io) goto error_out; } + cras_client_stream_params_set_client_type(params, CRAS_CLIENT_TYPE_PCM); + rc = cras_client_run_thread(pcm_cras->client); if (rc < 0) goto error_out; diff --git a/cras/src/common/a2dp-codecs.h b/cras/src/common/a2dp-codecs.h index 3dc31cbf..006d9fe4 100644 --- a/cras/src/common/a2dp-codecs.h +++ b/cras/src/common/a2dp-codecs.h @@ -22,112 +22,112 @@ * */ -#define A2DP_CODEC_SBC 0x00 -#define A2DP_CODEC_MPEG12 0x01 -#define A2DP_CODEC_MPEG24 0x02 -#define A2DP_CODEC_ATRAC 0x03 -#define A2DP_CODEC_VENDOR 0xFF +#define A2DP_CODEC_SBC 0x00 +#define A2DP_CODEC_MPEG12 0x01 +#define A2DP_CODEC_MPEG24 0x02 +#define A2DP_CODEC_ATRAC 0x03 +#define A2DP_CODEC_VENDOR 0xFF -#define SBC_SAMPLING_FREQ_16000 (1 << 3) -#define SBC_SAMPLING_FREQ_32000 (1 << 2) -#define SBC_SAMPLING_FREQ_44100 (1 << 1) -#define SBC_SAMPLING_FREQ_48000 1 +#define SBC_SAMPLING_FREQ_16000 (1 << 3) +#define SBC_SAMPLING_FREQ_32000 (1 << 2) +#define SBC_SAMPLING_FREQ_44100 (1 << 1) +#define SBC_SAMPLING_FREQ_48000 1 -#define SBC_CHANNEL_MODE_MONO (1 << 3) -#define SBC_CHANNEL_MODE_DUAL_CHANNEL (1 << 2) -#define SBC_CHANNEL_MODE_STEREO (1 << 1) -#define SBC_CHANNEL_MODE_JOINT_STEREO 1 +#define SBC_CHANNEL_MODE_MONO (1 << 3) +#define SBC_CHANNEL_MODE_DUAL_CHANNEL (1 << 2) +#define SBC_CHANNEL_MODE_STEREO (1 << 1) +#define SBC_CHANNEL_MODE_JOINT_STEREO 1 -#define SBC_BLOCK_LENGTH_4 (1 << 3) -#define SBC_BLOCK_LENGTH_8 (1 << 2) -#define SBC_BLOCK_LENGTH_12 (1 << 1) -#define SBC_BLOCK_LENGTH_16 1 +#define SBC_BLOCK_LENGTH_4 (1 << 3) +#define SBC_BLOCK_LENGTH_8 (1 << 2) +#define SBC_BLOCK_LENGTH_12 (1 << 1) +#define SBC_BLOCK_LENGTH_16 1 -#define SBC_SUBBANDS_4 (1 << 1) -#define SBC_SUBBANDS_8 1 +#define SBC_SUBBANDS_4 (1 << 1) +#define SBC_SUBBANDS_8 1 -#define SBC_ALLOCATION_SNR (1 << 1) -#define SBC_ALLOCATION_LOUDNESS 1 +#define SBC_ALLOCATION_SNR (1 << 1) +#define SBC_ALLOCATION_LOUDNESS 1 #define MAX_BITPOOL 64 #define MIN_BITPOOL 2 -#define MPEG_CHANNEL_MODE_MONO (1 << 3) -#define MPEG_CHANNEL_MODE_DUAL_CHANNEL (1 << 2) -#define MPEG_CHANNEL_MODE_STEREO (1 << 1) -#define MPEG_CHANNEL_MODE_JOINT_STEREO 1 - -#define MPEG_LAYER_MP1 (1 << 2) -#define MPEG_LAYER_MP2 (1 << 1) -#define MPEG_LAYER_MP3 1 - -#define MPEG_SAMPLING_FREQ_16000 (1 << 5) -#define MPEG_SAMPLING_FREQ_22050 (1 << 4) -#define MPEG_SAMPLING_FREQ_24000 (1 << 3) -#define MPEG_SAMPLING_FREQ_32000 (1 << 2) -#define MPEG_SAMPLING_FREQ_44100 (1 << 1) -#define MPEG_SAMPLING_FREQ_48000 1 - -#define MPEG_BIT_RATE_VBR 0x8000 -#define MPEG_BIT_RATE_320000 0x4000 -#define MPEG_BIT_RATE_256000 0x2000 -#define MPEG_BIT_RATE_224000 0x1000 -#define MPEG_BIT_RATE_192000 0x0800 -#define MPEG_BIT_RATE_160000 0x0400 -#define MPEG_BIT_RATE_128000 0x0200 -#define MPEG_BIT_RATE_112000 0x0100 -#define MPEG_BIT_RATE_96000 0x0080 -#define MPEG_BIT_RATE_80000 0x0040 -#define MPEG_BIT_RATE_64000 0x0020 -#define MPEG_BIT_RATE_56000 0x0010 -#define MPEG_BIT_RATE_48000 0x0008 -#define MPEG_BIT_RATE_40000 0x0004 -#define MPEG_BIT_RATE_32000 0x0002 -#define MPEG_BIT_RATE_FREE 0x0001 +#define MPEG_CHANNEL_MODE_MONO (1 << 3) +#define MPEG_CHANNEL_MODE_DUAL_CHANNEL (1 << 2) +#define MPEG_CHANNEL_MODE_STEREO (1 << 1) +#define MPEG_CHANNEL_MODE_JOINT_STEREO 1 + +#define MPEG_LAYER_MP1 (1 << 2) +#define MPEG_LAYER_MP2 (1 << 1) +#define MPEG_LAYER_MP3 1 + +#define MPEG_SAMPLING_FREQ_16000 (1 << 5) +#define MPEG_SAMPLING_FREQ_22050 (1 << 4) +#define MPEG_SAMPLING_FREQ_24000 (1 << 3) +#define MPEG_SAMPLING_FREQ_32000 (1 << 2) +#define MPEG_SAMPLING_FREQ_44100 (1 << 1) +#define MPEG_SAMPLING_FREQ_48000 1 + +#define MPEG_BIT_RATE_VBR 0x8000 +#define MPEG_BIT_RATE_320000 0x4000 +#define MPEG_BIT_RATE_256000 0x2000 +#define MPEG_BIT_RATE_224000 0x1000 +#define MPEG_BIT_RATE_192000 0x0800 +#define MPEG_BIT_RATE_160000 0x0400 +#define MPEG_BIT_RATE_128000 0x0200 +#define MPEG_BIT_RATE_112000 0x0100 +#define MPEG_BIT_RATE_96000 0x0080 +#define MPEG_BIT_RATE_80000 0x0040 +#define MPEG_BIT_RATE_64000 0x0020 +#define MPEG_BIT_RATE_56000 0x0010 +#define MPEG_BIT_RATE_48000 0x0008 +#define MPEG_BIT_RATE_40000 0x0004 +#define MPEG_BIT_RATE_32000 0x0002 +#define MPEG_BIT_RATE_FREE 0x0001 #if __BYTE_ORDER == __LITTLE_ENDIAN typedef struct { - uint8_t channel_mode:4; - uint8_t frequency:4; - uint8_t allocation_method:2; - uint8_t subbands:2; - uint8_t block_length:4; + uint8_t channel_mode : 4; + uint8_t frequency : 4; + uint8_t allocation_method : 2; + uint8_t subbands : 2; + uint8_t block_length : 4; uint8_t min_bitpool; uint8_t max_bitpool; -} __attribute__ ((packed)) a2dp_sbc_t; +} __attribute__((packed)) a2dp_sbc_t; typedef struct { - uint8_t channel_mode:4; - uint8_t crc:1; - uint8_t layer:3; - uint8_t frequency:6; - uint8_t mpf:1; - uint8_t rfa:1; + uint8_t channel_mode : 4; + uint8_t crc : 1; + uint8_t layer : 3; + uint8_t frequency : 6; + uint8_t mpf : 1; + uint8_t rfa : 1; uint16_t bitrate; -} __attribute__ ((packed)) a2dp_mpeg_t; +} __attribute__((packed)) a2dp_mpeg_t; #elif __BYTE_ORDER == __BIG_ENDIAN typedef struct { - uint8_t frequency:4; - uint8_t channel_mode:4; - uint8_t block_length:4; - uint8_t subbands:2; - uint8_t allocation_method:2; + uint8_t frequency : 4; + uint8_t channel_mode : 4; + uint8_t block_length : 4; + uint8_t subbands : 2; + uint8_t allocation_method : 2; uint8_t min_bitpool; uint8_t max_bitpool; -} __attribute__ ((packed)) a2dp_sbc_t; +} __attribute__((packed)) a2dp_sbc_t; typedef struct { - uint8_t layer:3; - uint8_t crc:1; - uint8_t channel_mode:4; - uint8_t rfa:1; - uint8_t mpf:1; - uint8_t frequency:6; + uint8_t layer : 3; + uint8_t crc : 1; + uint8_t channel_mode : 4; + uint8_t rfa : 1; + uint8_t mpf : 1; + uint8_t frequency : 6; uint16_t bitrate; -} __attribute__ ((packed)) a2dp_mpeg_t; +} __attribute__((packed)) a2dp_mpeg_t; #else #error "Unknown byte order" @@ -136,4 +136,4 @@ typedef struct { typedef struct { uint8_t vendor_id[4]; uint8_t codec_id[2]; -} __attribute__ ((packed)) a2dp_vendor_codec_t; +} __attribute__((packed)) a2dp_vendor_codec_t; diff --git a/cras/src/common/array.h b/cras/src/common/array.h index 0f295088..b21987e9 100644 --- a/cras/src/common/array.h +++ b/cras/src/common/array.h @@ -37,43 +37,44 @@ void f() */ /* Define a type for the array given the element type */ -#define DECLARE_ARRAY_TYPE(element_type, array_type) \ - typedef struct { \ - int count; \ - int size; \ - element_type *element; \ +#define DECLARE_ARRAY_TYPE(element_type, array_type) \ + typedef struct { \ + int count; \ + int size; \ + element_type *element; \ } array_type; /* The initializer for an empty array is the zero value. */ -#define ARRAY_INIT {} - -#define _ARRAY_EXTEND(a) \ - ({ \ - if ((a)->count >= (a)->size) { \ - if ((a)->size == 0) \ - (a)->size = 4; \ - else \ - (a)->size *= 2; \ - (a)->element = (__typeof((a)->element)) \ - realloc((a)->element, \ - (a)->size * \ - sizeof((a)->element[0])); \ - } \ - &(a)->element[((a)->count)++]; \ +#define ARRAY_INIT \ + { \ + } + +#define _ARRAY_EXTEND(a) \ + ({ \ + if ((a)->count >= (a)->size) { \ + if ((a)->size == 0) \ + (a)->size = 4; \ + else \ + (a)->size *= 2; \ + (a)->element = (__typeof((a)->element))realloc( \ + (a)->element, \ + (a)->size * sizeof((a)->element[0])); \ + } \ + &(a)->element[((a)->count)++]; \ }) /* Append an element with the given value to the array a */ -#define ARRAY_APPEND(a, value) \ - do { \ - *_ARRAY_EXTEND(a) = (value); \ +#define ARRAY_APPEND(a, value) \ + do { \ + *_ARRAY_EXTEND(a) = (value); \ } while (0) /* Append a zero element to the array a and return the pointer to the element */ -#define ARRAY_APPEND_ZERO(a) \ - ({ \ - typeof((a)->element) _tmp_ptr = _ARRAY_EXTEND(a); \ - memset(_tmp_ptr, 0, sizeof(*_tmp_ptr)); \ - _tmp_ptr; \ +#define ARRAY_APPEND_ZERO(a) \ + ({ \ + typeof((a)->element) _tmp_ptr = _ARRAY_EXTEND(a); \ + memset(_tmp_ptr, 0, sizeof(*_tmp_ptr)); \ + _tmp_ptr; \ }) /* Return the number of elements in the array a */ @@ -87,28 +88,26 @@ void f() /* Go through each element in the array a and assign index and pointer to the element to the variable i and ptr */ -#define ARRAY_ELEMENT_FOREACH(a, i, ptr) \ - for ((i) = 0, (ptr) = (a)->element; (i) < (a)->count; \ - (i)++, (ptr)++) +#define ARRAY_ELEMENT_FOREACH(a, i, ptr) \ + for ((i) = 0, (ptr) = (a)->element; (i) < (a)->count; (i)++, (ptr)++) /* Free the memory used by the array a. The array becomes an empty array. */ -#define ARRAY_FREE(a) \ - do { \ - free((a)->element); \ - (a)->element = NULL; \ - (a)->size = 0; \ - (a)->count = 0; \ +#define ARRAY_FREE(a) \ + do { \ + free((a)->element); \ + (a)->element = NULL; \ + (a)->size = 0; \ + (a)->count = 0; \ } while (0) - /* Return the index of the element with the value x. -1 if not found */ -#define ARRAY_FIND(a, x) \ - ({ \ - typeof((a)->element) _bptr = (a)->element; \ - typeof((a)->element) _eptr = (a)->element + (a)->count; \ - for (; _bptr != _eptr && *_bptr != x; _bptr++) \ - ; \ - (_bptr == _eptr) ? -1 : (_bptr - (a)->element); \ +#define ARRAY_FIND(a, x) \ + ({ \ + typeof((a)->element) _bptr = (a)->element; \ + typeof((a)->element) _eptr = (a)->element + (a)->count; \ + for (; _bptr != _eptr && *_bptr != x; _bptr++) \ + ; \ + (_bptr == _eptr) ? -1 : (_bptr - (a)->element); \ }) #ifdef __cplusplus diff --git a/cras/src/common/bluetooth.h b/cras/src/common/bluetooth.h index 824f3d9d..155b5e00 100644 --- a/cras/src/common/bluetooth.h +++ b/cras/src/common/bluetooth.h @@ -11,26 +11,26 @@ #include <unistd.h> -#define HCI_VIRTUAL 0 -#define HCI_USB 1 -#define HCI_PCCARD 2 -#define HCI_UART 3 -#define HCI_RS232 4 -#define HCI_PCI 5 -#define HCI_SDIO 6 -#define HCI_BUS_MAX 7 +#define HCI_VIRTUAL 0 +#define HCI_USB 1 +#define HCI_PCCARD 2 +#define HCI_UART 3 +#define HCI_RS232 4 +#define HCI_PCI 5 +#define HCI_SDIO 6 +#define HCI_BUS_MAX 7 #define BTPROTO_HCI 1 #define BTPROTO_SCO 2 -#define SCO_OPTIONS 0x01 +#define SCO_OPTIONS 0x01 #define SOL_SCO 17 -#define HCIGETDEVINFO _IOR('H', 211, int) +#define HCIGETDEVINFO _IOR('H', 211, int) typedef struct { uint8_t b[6]; -} __attribute__ ((packed)) bdaddr_t; +} __attribute__((packed)) bdaddr_t; struct hci_dev_stats { uint32_t err_rx; @@ -47,11 +47,11 @@ struct hci_dev_stats { struct hci_dev_info { uint16_t dev_id; - char name[8]; + char name[8]; bdaddr_t bdaddr; uint32_t flags; - uint8_t type; - uint8_t features[8]; + uint8_t type; + uint8_t features[8]; uint32_t pkt_type; uint32_t link_policy; uint32_t link_mode; @@ -66,11 +66,11 @@ struct sco_options { uint16_t mtu; }; -#define SOL_BLUETOOTH 274 +#define SOL_BLUETOOTH 274 -#define BT_VOICE 11 +#define BT_VOICE 11 struct bt_voice { uint16_t setting; }; -#define BT_VOICE_TRANSPARENT 0x0003 +#define BT_VOICE_TRANSPARENT 0x0003 diff --git a/cras/src/common/byte_buffer.h b/cras/src/common/byte_buffer.h index 444575e2..dd9cb2d0 100644 --- a/cras/src/common/byte_buffer.h +++ b/cras/src/common/byte_buffer.h @@ -23,8 +23,8 @@ struct byte_buffer { static inline struct byte_buffer *byte_buffer_create(size_t buffer_size_bytes) { struct byte_buffer *buf; - buf = (struct byte_buffer *) - calloc(1, sizeof(struct byte_buffer) + buffer_size_bytes); + buf = (struct byte_buffer *)calloc(1, sizeof(struct byte_buffer) + + buffer_size_bytes); if (!buf) return buf; buf->max_size = buffer_size_bytes; diff --git a/cras/src/common/cras_audio_format.c b/cras/src/common/cras_audio_format.c index e25c20c9..f504dfc3 100644 --- a/cras/src/common/cras_audio_format.c +++ b/cras/src/common/cras_audio_format.c @@ -10,24 +10,22 @@ #include "cras_audio_format.h" - /* Table for allowed alternatives when doing channel re-mapping. * When channel_alt[X][Y] is non-zero, it's allowed to map channel * from X to Y. */ -static const int channel_alt[CRAS_CH_MAX][CRAS_CH_MAX] = -{ - /* FL FR RL RR FC LFE SL SR RC FLC FRC */ - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* FL */ - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* FR */ - { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, /* RL */ - { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 }, /* RR */ - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* FC */ - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* LFE */ - { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 }, /* SL */ - { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 }, /* SR */ - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* RC */ - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* FLC */ - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* FRC */ +static const int channel_alt[CRAS_CH_MAX][CRAS_CH_MAX] = { + /*FL FR RL RR FC LFE SL SR RC FLC FRC */ + { 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, +0 }, /* FL */ + { 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, +0 }, /* FR */ + { 0, 0, 0, 0, 0, 0, +1, 0, 0, 0, +0 }, /* RL */ + { 0, 0, 0, 0, 0, 0, +0, 1, 0, 0, +0 }, /* RR */ + { 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, +0 }, /* FC */ + { 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, +0 }, /* LFE */ + { 0, 0, 1, 0, 0, 0, +0, 0, 0, 0, +0 }, /* SL */ + { 0, 0, 0, 1, 0, 0, +0, 0, 0, 0, +0 }, /* SR */ + { 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, +0 }, /* RC */ + { 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, +0 }, /* FLC */ + { 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, +0 }, /* FRC */ }; /* Create an audio format structure. */ @@ -79,7 +77,7 @@ void cras_audio_format_destroy(struct cras_audio_format *fmt) free(fmt); } -float** cras_channel_conv_matrix_alloc(size_t in_ch, size_t out_ch) +float **cras_channel_conv_matrix_alloc(size_t in_ch, size_t out_ch) { size_t i; float **p; @@ -102,7 +100,7 @@ alloc_err: void cras_channel_conv_matrix_destroy(float **p, size_t out_ch) { size_t i; - for (i = 0; i < out_ch; i ++) + for (i = 0; i < out_ch; i++) free(p[i]); free(p); } @@ -129,11 +127,9 @@ float **cras_channel_conv_matrix_create(const struct cras_audio_format *in, * in use, create a permutation matrix for them. */ for (i = 0; i < CRAS_CH_MAX; i++) { - if (in->channel_layout[i] == -1 && - out->channel_layout[i] == -1) + if (in->channel_layout[i] == -1 && out->channel_layout[i] == -1) continue; - if (in->channel_layout[i] != -1 && - out->channel_layout[i] != -1) + if (in->channel_layout[i] != -1 && out->channel_layout[i] != -1) mtx[out->channel_layout[i]][in->channel_layout[i]] = 1; else if (in->channel_layout[i] != -1) { /* When the same channel does not appear at output @@ -148,7 +144,7 @@ float **cras_channel_conv_matrix_create(const struct cras_audio_format *in, in->channel_layout[alt] == -1 && out->channel_layout[alt] != -1) { mtx[out->channel_layout[alt]] - [in->channel_layout[i]] = 1; + [in->channel_layout[i]] = 1; break; } } diff --git a/cras/src/common/cras_audio_format.h b/cras/src/common/cras_audio_format.h index acef6865..47bb5c59 100644 --- a/cras/src/common/cras_audio_format.h +++ b/cras/src/common/cras_audio_format.h @@ -21,25 +21,25 @@ typedef enum pcm_format snd_pcm_format_t; /* libasound audio formats. */ #define SND_PCM_FORMAT_UNKNOWN -1 -#define SND_PCM_FORMAT_U8 1 -#define SND_PCM_FORMAT_S16_LE 2 -#define SND_PCM_FORMAT_S24_LE 6 -#define SND_PCM_FORMAT_S32_LE 10 +#define SND_PCM_FORMAT_U8 1 +#define SND_PCM_FORMAT_S16_LE 2 +#define SND_PCM_FORMAT_S24_LE 6 +#define SND_PCM_FORMAT_S32_LE 10 static inline int audio_format_to_cras_format(audio_format_t audio_format) { - switch (audio_format) { - case AUDIO_FORMAT_PCM_16_BIT: - return SND_PCM_FORMAT_S16_LE; - case AUDIO_FORMAT_PCM_8_BIT: - return SND_PCM_FORMAT_U8; - case AUDIO_FORMAT_PCM_32_BIT: - return SND_PCM_FORMAT_S32_LE; - case AUDIO_FORMAT_PCM_8_24_BIT: - return SND_PCM_FORMAT_S24_LE; - default: - return SND_PCM_FORMAT_UNKNOWN; - } + switch (audio_format) { + case AUDIO_FORMAT_PCM_16_BIT: + return SND_PCM_FORMAT_S16_LE; + case AUDIO_FORMAT_PCM_8_BIT: + return SND_PCM_FORMAT_U8; + case AUDIO_FORMAT_PCM_32_BIT: + return SND_PCM_FORMAT_S32_LE; + case AUDIO_FORMAT_PCM_8_24_BIT: + return SND_PCM_FORMAT_S24_LE; + default: + return SND_PCM_FORMAT_UNKNOWN; + } } #else #include <alsa/asoundlib.h> @@ -88,31 +88,32 @@ struct cras_audio_format { * the above structure to keep binary compatibility with Chromium. * If cras_audio_format ever changes, merge the 2 structures. */ -struct __attribute__ ((__packed__)) cras_audio_format_packed { +struct __attribute__((__packed__)) cras_audio_format_packed { int32_t format; uint32_t frame_rate; uint32_t num_channels; int8_t channel_layout[CRAS_CH_MAX]; }; -static inline void pack_cras_audio_format(struct cras_audio_format_packed* dest, - const struct cras_audio_format* src) +static inline void pack_cras_audio_format(struct cras_audio_format_packed *dest, + const struct cras_audio_format *src) { dest->format = src->format; dest->frame_rate = src->frame_rate; dest->num_channels = src->num_channels; memcpy(dest->channel_layout, src->channel_layout, - sizeof(src->channel_layout)); + sizeof(src->channel_layout)); } -static inline void unpack_cras_audio_format(struct cras_audio_format* dest, - const struct cras_audio_format_packed* src) +static inline void +unpack_cras_audio_format(struct cras_audio_format *dest, + const struct cras_audio_format_packed *src) { dest->format = (snd_pcm_format_t)src->format; dest->frame_rate = src->frame_rate; dest->num_channels = src->num_channels; memcpy(dest->channel_layout, src->channel_layout, - sizeof(src->channel_layout)); + sizeof(src->channel_layout)); } /* Returns the number of bytes per sample. @@ -126,8 +127,8 @@ static inline size_t cras_get_format_bytes(const struct cras_audio_format *fmt) /* Sets channel layout to a default value where channels [0, num_channels] are * placed to the same position of its channel index, otherwise set to -1. */ -static inline void cras_audio_format_set_default_channel_layout( - struct cras_audio_format *format) +static inline void +cras_audio_format_set_default_channel_layout(struct cras_audio_format *format) { unsigned int i; for (i = 0; i < CRAS_CH_MAX; i++) @@ -151,7 +152,7 @@ int cras_audio_format_set_channel_layout(struct cras_audio_format *format, const int8_t layout[CRAS_CH_MAX]); /* Allocates an empty channel conversion matrix of given size. */ -float** cras_channel_conv_matrix_alloc(size_t in_ch, size_t out_ch); +float **cras_channel_conv_matrix_alloc(size_t in_ch, size_t out_ch); /* Destroys the channel conversion matrix. */ void cras_channel_conv_matrix_destroy(float **mtx, size_t out_ch); diff --git a/cras/src/common/cras_checksum.c b/cras/src/common/cras_checksum.c index 96a2de00..33e9f603 100644 --- a/cras/src/common/cras_checksum.c +++ b/cras/src/common/cras_checksum.c @@ -13,58 +13,49 @@ #include "cras_checksum.h" static const uint32_t crctab[] = { -0x00000000, -0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, -0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, -0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, -0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 0x5f15adac, -0x5bd4b01b, 0x569796c2, 0x52568b75, 0x6a1936c8, 0x6ed82b7f, -0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a, -0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, -0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, -0xbaea46ef, 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, -0xa4ad16ea, 0xa06c0b5d, 0xd4326d90, 0xd0f37027, 0xddb056fe, -0xd9714b49, 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95, -0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 0xe13ef6f4, -0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0, -0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, -0x2ac12072, 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, -0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca, 0x7897ab07, -0x7c56b6b0, 0x71159069, 0x75d48dde, 0x6b93dddb, 0x6f52c06c, -0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, -0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba, -0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, -0xbb60adfc, 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, -0x832f1041, 0x87ee0df6, 0x99a95df3, 0x9d684044, 0x902b669d, -0x94ea7b2a, 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e, -0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, 0xc6bcf05f, -0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34, -0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, -0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, -0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 0x5c007b8a, -0x58c1663d, 0x558240e4, 0x51435d53, 0x251d3b9e, 0x21dc2629, -0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c, -0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, -0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, -0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, -0xeba91bbc, 0xef68060b, 0xd727bbb6, 0xd3e6a601, 0xdea580d8, -0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3, -0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, 0xae3afba2, -0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71, -0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, -0x857130c3, 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, -0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c, 0x7b827d21, -0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a, -0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e, 0x18197087, -0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec, -0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, -0x2056cd3a, 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, -0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, -0xdbee767c, 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18, -0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, 0x89b8fd09, -0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, -0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, -0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 + 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, + 0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, + 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7, + 0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75, + 0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, + 0x709f7b7a, 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, + 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, 0xbaea46ef, + 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d, + 0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb, + 0xceb42022, 0xca753d95, 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, + 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0, + 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072, + 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x018aeb13, 0x054bf6a4, + 0x0808d07d, 0x0cc9cdca, 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde, + 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08, + 0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba, + 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc, + 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6, + 0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, 0xe0b41de7, 0xe4750050, + 0xe9362689, 0xedf73b3e, 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, + 0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34, + 0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637, + 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, 0x4f040d56, 0x4bc510e1, + 0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53, + 0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, + 0x3f9b762c, 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, + 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, 0xf5ee4bb9, + 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b, + 0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, + 0xcda1f604, 0xc960ebb3, 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, + 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71, + 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3, + 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2, + 0x470cdd2b, 0x43cdc09c, 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8, + 0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e, + 0x18197087, 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec, + 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a, + 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0, + 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, 0xe3a1cbc1, 0xe760d676, + 0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, + 0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, + 0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668, + 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 }; uint32_t crc32_checksum(const unsigned char *input, size_t n) diff --git a/cras/src/common/cras_config.c b/cras/src/common/cras_config.c index 29e9fa1c..335b7849 100644 --- a/cras/src/common/cras_config.c +++ b/cras/src/common/cras_config.c @@ -8,6 +8,8 @@ #include <sys/types.h> #include <unistd.h> +#include "cras_config.h" + const char *cras_config_get_system_socket_file_dir() { /* This directory is created by the upstart script, eventually it would @@ -15,3 +17,33 @@ const char *cras_config_get_system_socket_file_dir() * Chrome OS. */ return CRAS_SOCKET_FILE_DIR; } + +int cras_fill_socket_path(enum CRAS_CONNECTION_TYPE conn_type, char *sock_path) +{ + const char *sock_file; + const char *sock_dir; + + sock_dir = cras_config_get_system_socket_file_dir(); + if (sock_dir == NULL) { + return -ENOTDIR; + } + + switch (conn_type) { + case CRAS_CONTROL: + sock_file = CRAS_SOCKET_FILE; + break; + case CRAS_PLAYBACK: + sock_file = CRAS_PLAYBACK_SOCKET_FILE; + break; + case CRAS_CAPTURE: + sock_file = CRAS_CAPTURE_SOCKET_FILE; + break; + default: + return -EINVAL; + } + + snprintf(sock_path, CRAS_MAX_SOCKET_PATH_SIZE, "%s/%s", sock_dir, + sock_file); + + return 0; +} diff --git a/cras/src/common/cras_config.h b/cras/src/common/cras_config.h index c1731c73..8b1e6135 100644 --- a/cras/src/common/cras_config.h +++ b/cras/src/common/cras_config.h @@ -6,12 +6,21 @@ #ifndef CRAS_CONFIG_H_ #define CRAS_CONFIG_H_ +#include "cras_types.h" + #define CRAS_MIN_BUFFER_TIME_IN_US 1000 /* 1 milliseconds */ #define CRAS_SERVER_RT_THREAD_PRIORITY 12 #define CRAS_CLIENT_RT_THREAD_PRIORITY 10 #define CRAS_CLIENT_NICENESS_LEVEL -10 #define CRAS_SOCKET_FILE ".cras_socket" +#define CRAS_PLAYBACK_SOCKET_FILE ".cras_playback" +#define CRAS_CAPTURE_SOCKET_FILE ".cras_capture" + +/* Maximum socket_path size, which is equals to sizeof(sun_path) in sockaddr_un + * structure. + */ +#define CRAS_MAX_SOCKET_PATH_SIZE 108 /* CRAS_CONFIG_FILE_DIR is defined as $sysconfdir/cras by the configure script. */ @@ -19,4 +28,15 @@ /* Gets the path to save UDS socket files. */ const char *cras_config_get_system_socket_file_dir(); +/* Fills sock_path by given connection type. + * + * Args: + * conn_type - server socket connection type. + * sock_path - socket path to be filled. + * + * Returns: + * 0 for success, positive error code on error. + */ +int cras_fill_socket_path(enum CRAS_CONNECTION_TYPE conn_type, char *sock_path); + #endif /* CRAS_CONFIG_H_ */ diff --git a/cras/src/common/cras_file_wait.c b/cras/src/common/cras_file_wait.c index 5304f400..9ad94486 100644 --- a/cras/src/common/cras_file_wait.c +++ b/cras/src/common/cras_file_wait.c @@ -84,7 +84,8 @@ int cras_file_wait_process_event(struct cras_file_wait *file_wait, { cras_file_wait_event_t file_wait_event; - syslog(LOG_DEBUG, "file_wait->watch_id: %d, event->wd: %d" + syslog(LOG_DEBUG, + "file_wait->watch_id: %d, event->wd: %d" ", event->mask: %x, event->name: %s", file_wait->watch_id, event->wd, event->mask, event->len ? event->name : ""); @@ -105,9 +106,9 @@ int cras_file_wait_process_event(struct cras_file_wait *file_wait, return 0; } - if ((event->mask & (IN_CREATE|IN_MOVED_TO)) != 0) + if ((event->mask & (IN_CREATE | IN_MOVED_TO)) != 0) file_wait_event = CRAS_FILE_WAIT_EVENT_CREATED; - else if ((event->mask & (IN_DELETE|IN_MOVED_FROM)) != 0) + else if ((event->mask & (IN_DELETE | IN_MOVED_FROM)) != 0) file_wait_event = CRAS_FILE_WAIT_EVENT_DELETED; else return 0; @@ -146,8 +147,8 @@ int cras_file_wait_dispatch(struct cras_file_wait *file_wait) CRAS_FILE_WAIT_EVENT_SIZE); if (read_rc < 0) { rc = -errno; - if ((rc == -EAGAIN || rc == -EWOULDBLOCK) - && file_wait->watch_id < 0) { + if ((rc == -EAGAIN || rc == -EWOULDBLOCK) && + file_wait->watch_id < 0) { /* Really nothing to read yet: we need to * setup a watch. */ rc = 0; @@ -157,16 +158,19 @@ int cras_file_wait_dispatch(struct cras_file_wait *file_wait) } else if (file_wait->watch_id < 0) { /* Processing messages related to old watches. */ rc = 0; - } else while (rc == 0 && read_offset < read_rc) { - event = (struct inotify_event *) - (file_wait->event_buf + read_offset); - read_offset += sizeof(*event) + event->len; - rc = cras_file_wait_process_event(file_wait, event); - } + } else + while (rc == 0 && read_offset < read_rc) { + event = (struct inotify_event + *)(file_wait->event_buf + + read_offset); + read_offset += sizeof(*event) + event->len; + rc = cras_file_wait_process_event(file_wait, + event); + } } /* Report errors from above here. */ - if (rc != 0) + if (rc < 0) return rc; if (file_wait->watch_id >= 0) { @@ -176,7 +180,7 @@ int cras_file_wait_dispatch(struct cras_file_wait *file_wait) /* Initialize inotify if we haven't already. */ if (file_wait->inotify_fd < 0) { - file_wait->inotify_fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC); + file_wait->inotify_fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC); if (file_wait->inotify_fd < 0) return -errno; } @@ -199,7 +203,7 @@ int cras_file_wait_dispatch(struct cras_file_wait *file_wait) /* Treat consecutive '/' characters as one. */ while (watch_dir_end > file_wait->watch_dir && *(watch_dir_end - 1) == '/') - watch_dir_end--; + watch_dir_end--; watch_dir_len = watch_dir_end - file_wait->watch_dir; if (watch_dir_len == 0) { @@ -225,10 +229,9 @@ int cras_file_wait_dispatch(struct cras_file_wait *file_wait) file_wait->flags &= ~CRAS_FILE_WAIT_FLAG_MOCK_RACE; } - flags = IN_CREATE|IN_MOVED_TO|IN_DELETE|IN_MOVED_FROM; - file_wait->watch_id = - inotify_add_watch(file_wait->inotify_fd, - file_wait->watch_dir, flags); + flags = IN_CREATE | IN_MOVED_TO | IN_DELETE | IN_MOVED_FROM; + file_wait->watch_id = inotify_add_watch( + file_wait->inotify_fd, file_wait->watch_dir, flags); if (file_wait->watch_id < 0) { rc = -errno; continue; @@ -256,7 +259,7 @@ int cras_file_wait_dispatch(struct cras_file_wait *file_wait) /* Start over again. */ rc = cras_file_wait_rm_watch(file_wait); - if (rc != 0) + if (rc < 0) return rc; rc = -ENOENT; strcpy(file_wait->watch_dir, file_wait->file_path); @@ -267,8 +270,7 @@ int cras_file_wait_dispatch(struct cras_file_wait *file_wait) return rc; } -int cras_file_wait_create(const char *file_path, - cras_file_wait_flag_t flags, +int cras_file_wait_create(const char *file_path, cras_file_wait_flag_t flags, cras_file_wait_callback_t callback, void *callback_context, struct cras_file_wait **file_wait_out) @@ -283,8 +285,8 @@ int cras_file_wait_create(const char *file_path, /* Create a struct cras_file_wait to track waiting for this file. */ file_path_len = strlen(file_path); - file_wait = (struct cras_file_wait *) - calloc(1, sizeof(*file_wait) + ((file_path_len + 1) * 5)); + file_wait = (struct cras_file_wait *)calloc( + 1, sizeof(*file_wait) + ((file_path_len + 1) * 5)); if (!file_wait) return -ENOMEM; file_wait->callback = callback; @@ -298,8 +300,8 @@ int cras_file_wait_create(const char *file_path, * watch_dir, and watch_file_name data are appended to the end of * our cras_file_wait structure. */ file_wait->file_path = (const char *)file_wait + sizeof(*file_wait); - file_wait->watch_path = (char *)file_wait->file_path + - file_path_len + 1; + file_wait->watch_path = + (char *)file_wait->file_path + file_path_len + 1; file_wait->watch_dir = file_wait->watch_path + file_path_len + 1; file_wait->watch_file_name = file_wait->watch_dir + file_path_len + 1; memcpy((void *)file_wait->file_path, file_path, file_path_len + 1); @@ -307,9 +309,11 @@ int cras_file_wait_create(const char *file_path, /* Setup the first watch. If that fails unexpectedly, then we destroy * the file wait structure immediately. */ rc = cras_file_wait_dispatch(file_wait); - if (rc != 0) + if (rc < 0) { cras_file_wait_destroy(file_wait); - else - *file_wait_out = file_wait; - return rc; + return rc; + } + + *file_wait_out = file_wait; + return 0; } diff --git a/cras/src/common/cras_file_wait.h b/cras/src/common/cras_file_wait.h index 28035823..e9ec3ad8 100644 --- a/cras/src/common/cras_file_wait.h +++ b/cras/src/common/cras_file_wait.h @@ -17,7 +17,7 @@ struct cras_file_wait; typedef unsigned int cras_file_wait_flag_t; /* No flags. */ -#define CRAS_FILE_WAIT_FLAG_NONE ((cras_file_wait_flag_t)0) +#define CRAS_FILE_WAIT_FLAG_NONE ((cras_file_wait_flag_t)0) /* File wait events. */ typedef enum cras_file_wait_event { @@ -73,11 +73,10 @@ typedef void (*cras_file_wait_callback_t)(void *context, * - 0 for success, or negative on error. * - On error cras_file_wait_destroy() need not be called. */ -int cras_file_wait_create(const char *file_path, - cras_file_wait_flag_t flags, +int cras_file_wait_create(const char *file_path, cras_file_wait_flag_t flags, cras_file_wait_callback_t callback, void *callback_context, - struct cras_file_wait **file_wait_out); + struct cras_file_wait **file_wait_out); /* Returns the file-descriptor to poll for a file wait. * @@ -105,7 +104,7 @@ int cras_file_wait_get_fd(struct cras_file_wait *file_wait); * cras_file_wait_start(). * * Returns: - * - 0 for success, non-zero on error. + * - 0 for success, negative on error. * - -EAGAIN or -EWOULDBLOCK when this function would have blocked. */ int cras_file_wait_dispatch(struct cras_file_wait *file_wait); diff --git a/cras/src/common/cras_iodev_info.h b/cras/src/common/cras_iodev_info.h index bc3c18c4..5317ddee 100644 --- a/cras/src/common/cras_iodev_info.h +++ b/cras/src/common/cras_iodev_info.h @@ -19,14 +19,11 @@ * idx - iodev index. * name - Name displayed to the user. * stable_id - ID that does not change due to device plug/unplug or reboot. - * stable_id_new - New stable_id, it will be deprecated and be put on - * stable_id. */ -struct __attribute__ ((__packed__)) cras_iodev_info { +struct __attribute__((__packed__)) cras_iodev_info { uint32_t idx; char name[CRAS_IODEV_NAME_BUFFER_SIZE]; uint32_t stable_id; - uint32_t stable_id_new; }; /* Identifying information about an ionode on an iodev. @@ -39,25 +36,25 @@ struct __attribute__ ((__packed__)) cras_iodev_info { * capture_gain - per-node capture gain/attenuation (in 100*dBFS) * left_right_swapped - Set true if left and right channels are swapped. * stable_id - ID that does not change due to device plug/unplug or reboot. - * stable_id_new - New stable_id, it will be deprecated and be put on - * stable_id. * mic_positions - Positions of the mic array. * type - Type displayed to the user. * name - Name displayed to the user. * active_hotword_model - name of the currently selected hotword model. */ -struct __attribute__ ((__packed__)) cras_ionode_info { +struct __attribute__((__packed__)) cras_ionode_info { uint32_t iodev_idx; uint32_t ionode_idx; int32_t plugged; int32_t active; - struct { int64_t tv_sec; int64_t tv_usec; } plugged_time; + struct { + int64_t tv_sec; + int64_t tv_usec; + } plugged_time; uint32_t volume; int32_t capture_gain; int32_t left_right_swapped; uint32_t type_enum; uint32_t stable_id; - uint32_t stable_id_new; char mic_positions[CRAS_NODE_MIC_POS_BUFFER_SIZE]; char type[CRAS_NODE_TYPE_BUFFER_SIZE]; char name[CRAS_NODE_NAME_BUFFER_SIZE]; diff --git a/cras/src/common/cras_messages.h b/cras/src/common/cras_messages.h index 4f51369f..195965bb 100644 --- a/cras/src/common/cras_messages.h +++ b/cras/src/common/cras_messages.h @@ -16,11 +16,10 @@ /* Rev when message format changes. If new messages are added, or message ID * values change. */ -#define CRAS_PROTO_VER 3 +#define CRAS_PROTO_VER 5 #define CRAS_SERV_MAX_MSG_SIZE 256 #define CRAS_CLIENT_MAX_MSG_SIZE 256 -#define CRAS_HOTWORD_NAME_MAX_SIZE 8 -#define CRAS_MAX_HOTWORD_MODELS 244 +#define CRAS_MAX_HOTWORD_MODELS 243 #define CRAS_MAX_REMIX_CHANNELS 32 #define CRAS_MAX_TEST_DATA_LEN 224 #define CRAS_AEC_DUMP_FILE_NAME_LEN 128 @@ -58,6 +57,7 @@ enum CRAS_SERVER_MESSAGE_ID { CRAS_SERVER_RELOAD_AEC_CONFIG, CRAS_SERVER_DUMP_BT, CRAS_SERVER_SET_BT_WBS_ENABLED, + CRAS_SERVER_GET_ATLOG_FD, }; enum CRAS_CLIENT_MESSAGE_ID { @@ -77,18 +77,20 @@ enum CRAS_CLIENT_MESSAGE_ID { CRAS_CLIENT_NODE_LEFT_RIGHT_SWAPPED_CHANGED, CRAS_CLIENT_INPUT_NODE_GAIN_CHANGED, CRAS_CLIENT_NUM_ACTIVE_STREAMS_CHANGED, + /* Server -> Client */ + CRAS_CLIENT_ATLOG_FD_READY, }; /* Messages that control the server. These are sent from the client to affect * and action on the server. */ -struct __attribute__ ((__packed__)) cras_server_message { +struct __attribute__((__packed__)) cras_server_message { uint32_t length; enum CRAS_SERVER_MESSAGE_ID id; }; /* Messages that control the client. These are sent from the server to affect * and action on the client. */ -struct __attribute__ ((__packed__)) cras_client_message { +struct __attribute__((__packed__)) cras_client_message { uint32_t length; enum CRAS_CLIENT_MESSAGE_ID id; }; @@ -98,7 +100,30 @@ struct __attribute__ ((__packed__)) cras_client_message { */ /* Sent by a client to connect a stream to the server. */ -struct __attribute__ ((__packed__)) cras_connect_message { +struct __attribute__((__packed__)) cras_connect_message { + struct cras_server_message header; + uint32_t proto_version; + enum CRAS_STREAM_DIRECTION direction; /* input/output/loopback */ + cras_stream_id_t stream_id; /* unique id for this stream */ + enum CRAS_STREAM_TYPE stream_type; /* media, or call, etc. */ + uint32_t buffer_frames; /* Buffer size in frames. */ + uint32_t cb_threshold; /* callback client when this much is left */ + uint32_t flags; + struct cras_audio_format_packed format; /* rate, channel, sample size */ + uint32_t dev_idx; /* device to attach stream, 0 if none */ + uint64_t effects; /* Bit map of requested effects. */ + enum CRAS_CLIENT_TYPE client_type; /* chrome, or arc, etc. */ + uint32_t client_shm_size; /* Size of client-provided samples shm, if any */ +}; + +/* + * Old version of connect message without 'cras_type' and 'client_shm_size' + * defined. + * Used to check against when receiving invalid size of connect message. + * Expected to have proto_version set to 3. + * TODO(yuhsuan): remove when all clients migrate to latest libcras. + */ +struct __attribute__((__packed__)) cras_connect_message_old { struct cras_server_message header; uint32_t proto_version; enum CRAS_STREAM_DIRECTION direction; /* input/output/loopback */ @@ -112,16 +137,13 @@ struct __attribute__ ((__packed__)) cras_connect_message { uint64_t effects; /* Bit map of requested effects. */ }; -static inline void cras_fill_connect_message(struct cras_connect_message *m, - enum CRAS_STREAM_DIRECTION direction, - cras_stream_id_t stream_id, - enum CRAS_STREAM_TYPE stream_type, - size_t buffer_frames, - size_t cb_threshold, - uint32_t flags, - uint64_t effects, - struct cras_audio_format format, - uint32_t dev_idx) +static inline void cras_fill_connect_message( + struct cras_connect_message *m, enum CRAS_STREAM_DIRECTION direction, + cras_stream_id_t stream_id, enum CRAS_STREAM_TYPE stream_type, + enum CRAS_CLIENT_TYPE client_type, size_t buffer_frames, + size_t cb_threshold, uint32_t flags, uint64_t effects, + struct cras_audio_format format, uint32_t dev_idx, + uint32_t client_shm_size) { m->proto_version = CRAS_PROTO_VER; m->direction = direction; @@ -133,18 +155,20 @@ static inline void cras_fill_connect_message(struct cras_connect_message *m, m->effects = effects; pack_cras_audio_format(&m->format, &format); m->dev_idx = dev_idx; + m->client_type = client_type; + m->client_shm_size = client_shm_size; m->header.id = CRAS_SERVER_CONNECT_STREAM; m->header.length = sizeof(struct cras_connect_message); } /* Sent by a client to remove a stream from the server. */ -struct __attribute__ ((__packed__)) cras_disconnect_stream_message { +struct __attribute__((__packed__)) cras_disconnect_stream_message { struct cras_server_message header; cras_stream_id_t stream_id; }; -static inline void cras_fill_disconnect_stream_message( - struct cras_disconnect_stream_message *m, - cras_stream_id_t stream_id) +static inline void +cras_fill_disconnect_stream_message(struct cras_disconnect_stream_message *m, + cras_stream_id_t stream_id) { m->stream_id = stream_id; m->header.id = CRAS_SERVER_DISCONNECT_STREAM; @@ -152,20 +176,19 @@ static inline void cras_fill_disconnect_stream_message( } /* Move streams of "type" to the iodev at "iodev_idx". */ -struct __attribute__ ((__packed__)) cras_switch_stream_type_iodev { +struct __attribute__((__packed__)) cras_switch_stream_type_iodev { struct cras_server_message header; enum CRAS_STREAM_TYPE stream_type; uint32_t iodev_idx; }; /* Set the system volume. */ -struct __attribute__ ((__packed__)) cras_set_system_volume { +struct __attribute__((__packed__)) cras_set_system_volume { struct cras_server_message header; uint32_t volume; }; -static inline void cras_fill_set_system_volume( - struct cras_set_system_volume *m, - size_t volume) +static inline void cras_fill_set_system_volume(struct cras_set_system_volume *m, + size_t volume) { m->volume = volume; m->header.id = CRAS_SERVER_SET_SYSTEM_VOLUME; @@ -173,13 +196,13 @@ static inline void cras_fill_set_system_volume( } /* Sets the capture gain. */ -struct __attribute__ ((__packed__)) cras_set_system_capture_gain { +struct __attribute__((__packed__)) cras_set_system_capture_gain { struct cras_server_message header; int32_t gain; }; -static inline void cras_fill_set_system_capture_gain( - struct cras_set_system_capture_gain *m, - long gain) +static inline void +cras_fill_set_system_capture_gain(struct cras_set_system_capture_gain *m, + long gain) { m->gain = gain; m->header.id = CRAS_SERVER_SET_SYSTEM_CAPTURE_GAIN; @@ -187,45 +210,41 @@ static inline void cras_fill_set_system_capture_gain( } /* Set the system mute state. */ -struct __attribute__ ((__packed__)) cras_set_system_mute { +struct __attribute__((__packed__)) cras_set_system_mute { struct cras_server_message header; int32_t mute; /* 0 = un-mute, 1 = mute. */ }; -static inline void cras_fill_set_system_mute( - struct cras_set_system_mute *m, - int mute) +static inline void cras_fill_set_system_mute(struct cras_set_system_mute *m, + int mute) { m->mute = mute; m->header.id = CRAS_SERVER_SET_SYSTEM_MUTE; m->header.length = sizeof(*m); } -static inline void cras_fill_set_user_mute( - struct cras_set_system_mute *m, - int mute) +static inline void cras_fill_set_user_mute(struct cras_set_system_mute *m, + int mute) { m->mute = mute; m->header.id = CRAS_SERVER_SET_USER_MUTE; m->header.length = sizeof(*m); } -static inline void cras_fill_set_system_mute_locked( - struct cras_set_system_mute *m, - int locked) +static inline void +cras_fill_set_system_mute_locked(struct cras_set_system_mute *m, int locked) { m->mute = locked; m->header.id = CRAS_SERVER_SET_SYSTEM_MUTE_LOCKED; m->header.length = sizeof(*m); } -static inline void cras_fill_set_system_capture_mute( - struct cras_set_system_mute *m, - int mute) +static inline void +cras_fill_set_system_capture_mute(struct cras_set_system_mute *m, int mute) { m->mute = mute; m->header.id = CRAS_SERVER_SET_SYSTEM_CAPTURE_MUTE; m->header.length = sizeof(*m); } -static inline void cras_fill_set_system_capture_mute_locked( - struct cras_set_system_mute *m, - int locked) +static inline void +cras_fill_set_system_capture_mute_locked(struct cras_set_system_mute *m, + int locked) { m->mute = locked; m->header.id = CRAS_SERVER_SET_SYSTEM_CAPTURE_MUTE_LOCKED; @@ -233,17 +252,15 @@ static inline void cras_fill_set_system_capture_mute_locked( } /* Set an attribute of an ionode. */ -struct __attribute__ ((__packed__)) cras_set_node_attr { +struct __attribute__((__packed__)) cras_set_node_attr { struct cras_server_message header; cras_node_id_t node_id; enum ionode_attr attr; int32_t value; }; -static inline void cras_fill_set_node_attr( - struct cras_set_node_attr *m, - cras_node_id_t node_id, - enum ionode_attr attr, - int value) +static inline void cras_fill_set_node_attr(struct cras_set_node_attr *m, + cras_node_id_t node_id, + enum ionode_attr attr, int value) { m->header.id = CRAS_SERVER_SET_NODE_ATTR; m->node_id = node_id; @@ -253,15 +270,14 @@ static inline void cras_fill_set_node_attr( } /* Set an attribute of an ionode. */ -struct __attribute__ ((__packed__)) cras_select_node { +struct __attribute__((__packed__)) cras_select_node { struct cras_server_message header; enum CRAS_STREAM_DIRECTION direction; cras_node_id_t node_id; }; -static inline void cras_fill_select_node( - struct cras_select_node *m, - enum CRAS_STREAM_DIRECTION direction, - cras_node_id_t node_id) +static inline void cras_fill_select_node(struct cras_select_node *m, + enum CRAS_STREAM_DIRECTION direction, + cras_node_id_t node_id) { m->header.id = CRAS_SERVER_SELECT_NODE; m->direction = direction; @@ -270,15 +286,15 @@ static inline void cras_fill_select_node( } /* Add an active ionode. */ -struct __attribute__ ((__packed__)) cras_add_active_node { +struct __attribute__((__packed__)) cras_add_active_node { struct cras_server_message header; enum CRAS_STREAM_DIRECTION direction; cras_node_id_t node_id; }; -static inline void cras_fill_add_active_node( - struct cras_add_active_node *m, - enum CRAS_STREAM_DIRECTION direction, - cras_node_id_t node_id) +static inline void +cras_fill_add_active_node(struct cras_add_active_node *m, + enum CRAS_STREAM_DIRECTION direction, + cras_node_id_t node_id) { m->header.id = CRAS_SERVER_ADD_ACTIVE_NODE; m->direction = direction; @@ -287,15 +303,15 @@ static inline void cras_fill_add_active_node( } /* Remove an active ionode. */ -struct __attribute__ ((__packed__)) cras_rm_active_node { +struct __attribute__((__packed__)) cras_rm_active_node { struct cras_server_message header; enum CRAS_STREAM_DIRECTION direction; cras_node_id_t node_id; }; -static inline void cras_fill_rm_active_node( - struct cras_rm_active_node *m, - enum CRAS_STREAM_DIRECTION direction, - cras_node_id_t node_id) +static inline void +cras_fill_rm_active_node(struct cras_rm_active_node *m, + enum CRAS_STREAM_DIRECTION direction, + cras_node_id_t node_id) { m->header.id = CRAS_SERVER_RM_ACTIVE_NODE; m->direction = direction; @@ -304,42 +320,49 @@ static inline void cras_fill_rm_active_node( } /* Reload the dsp configuration. */ -struct __attribute__ ((__packed__)) cras_reload_dsp { +struct __attribute__((__packed__)) cras_reload_dsp { struct cras_server_message header; }; -static inline void cras_fill_reload_dsp( - struct cras_reload_dsp *m) +static inline void cras_fill_reload_dsp(struct cras_reload_dsp *m) { m->header.id = CRAS_SERVER_RELOAD_DSP; m->header.length = sizeof(*m); } /* Dump current dsp information to syslog. */ -struct __attribute__ ((__packed__)) cras_dump_dsp_info { +struct __attribute__((__packed__)) cras_dump_dsp_info { struct cras_server_message header; }; -static inline void cras_fill_dump_dsp_info( - struct cras_dump_dsp_info *m) +static inline void cras_fill_dump_dsp_info(struct cras_dump_dsp_info *m) { m->header.id = CRAS_SERVER_DUMP_DSP_INFO; m->header.length = sizeof(*m); } /* Dump current audio thread information to syslog. */ -struct __attribute__ ((__packed__)) cras_dump_audio_thread { +struct __attribute__((__packed__)) cras_dump_audio_thread { struct cras_server_message header; }; -static inline void cras_fill_dump_audio_thread( - struct cras_dump_audio_thread *m) +static inline void cras_fill_dump_audio_thread(struct cras_dump_audio_thread *m) { m->header.id = CRAS_SERVER_DUMP_AUDIO_THREAD; m->header.length = sizeof(*m); } +struct __attribute__((__packed__)) cras_get_atlog_fd { + struct cras_server_message header; +}; + +static inline void cras_fill_get_atlog_fd(struct cras_get_atlog_fd *m) +{ + m->header.id = CRAS_SERVER_GET_ATLOG_FD; + m->header.length = sizeof(*m); +} + /* Dump bluetooth events and state changes. */ -struct __attribute__ ((__packed__)) cras_dump_bt { +struct __attribute__((__packed__)) cras_dump_bt { struct cras_server_message header; }; @@ -350,19 +373,18 @@ static inline void cras_fill_dump_bt(struct cras_dump_bt *m) } /* Dump current audio thread snapshots to shard memory with the client. */ -struct __attribute__ ((__packed__)) cras_dump_snapshots { +struct __attribute__((__packed__)) cras_dump_snapshots { struct cras_server_message header; }; -static inline void cras_fill_dump_snapshots( - struct cras_dump_snapshots *m) +static inline void cras_fill_dump_snapshots(struct cras_dump_snapshots *m) { m->header.id = CRAS_SERVER_DUMP_SNAPSHOTS; m->header.length = sizeof(*m); } /* Add a test device. */ -struct __attribute__ ((__packed__)) cras_add_test_dev { +struct __attribute__((__packed__)) cras_add_test_dev { struct cras_server_message header; enum TEST_IODEV_TYPE type; }; @@ -376,7 +398,7 @@ static inline void cras_fill_add_test_dev(struct cras_add_test_dev *m, } /* Command a test device. */ -struct __attribute__ ((__packed__)) cras_test_dev_command { +struct __attribute__((__packed__)) cras_test_dev_command { struct cras_server_message header; unsigned int command; unsigned int iodev_idx; @@ -409,17 +431,16 @@ static inline void cras_fill_suspend_message(struct cras_server_message *m, * Configures the global remix converter. * `num_channels` must be less than `CRAS_MAX_REMIX_CHANNELS`. */ -struct __attribute__ ((__packed__)) cras_config_global_remix { +struct __attribute__((__packed__)) cras_config_global_remix { struct cras_server_message header; unsigned int num_channels; float coefficient[CRAS_MAX_REMIX_CHANNELS]; }; -static inline void cras_fill_config_global_remix_command( - struct cras_config_global_remix *m, - unsigned int num_channels, - float *coeff, - unsigned int count) +static inline void +cras_fill_config_global_remix_command(struct cras_config_global_remix *m, + unsigned int num_channels, float *coeff, + unsigned int count) { m->header.id = CRAS_CONFIG_GLOBAL_REMIX; m->header.length = sizeof(*m) + count * sizeof(*coeff); @@ -428,14 +449,14 @@ static inline void cras_fill_config_global_remix_command( } /* Get supported hotword models. */ -struct __attribute__ ((__packed__)) cras_get_hotword_models { +struct __attribute__((__packed__)) cras_get_hotword_models { struct cras_server_message header; cras_node_id_t node_id; }; -static inline void cras_fill_get_hotword_models_message( - struct cras_get_hotword_models *m, - cras_node_id_t node_id) +static inline void +cras_fill_get_hotword_models_message(struct cras_get_hotword_models *m, + cras_node_id_t node_id) { m->header.id = CRAS_SERVER_GET_HOTWORD_MODELS; m->header.length = sizeof(*m); @@ -443,34 +464,33 @@ static inline void cras_fill_get_hotword_models_message( } /* Set desired hotword model. */ -struct __attribute__ ((__packed__)) cras_set_hotword_model { +struct __attribute__((__packed__)) cras_set_hotword_model { struct cras_server_message header; cras_node_id_t node_id; - char model_name[CRAS_HOTWORD_NAME_MAX_SIZE]; + char model_name[CRAS_MAX_HOTWORD_MODEL_NAME_SIZE]; }; -static inline void cras_fill_set_hotword_model_message( - struct cras_set_hotword_model *m, - cras_node_id_t node_id, - const char *model_name) +static inline void +cras_fill_set_hotword_model_message(struct cras_set_hotword_model *m, + cras_node_id_t node_id, + const char *model_name) { m->header.id = CRAS_SERVER_SET_HOTWORD_MODEL; m->header.length = sizeof(*m); m->node_id = node_id; - memcpy(m->model_name, model_name, CRAS_HOTWORD_NAME_MAX_SIZE); + memcpy(m->model_name, model_name, CRAS_MAX_HOTWORD_MODEL_NAME_SIZE); } /* Set aec dump to start or stop. */ -struct __attribute__ ((__packed__)) cras_set_aec_dump { +struct __attribute__((__packed__)) cras_set_aec_dump { struct cras_server_message header; cras_stream_id_t stream_id; unsigned int start; }; -static inline void cras_fill_set_aec_dump_message( - struct cras_set_aec_dump *m, - cras_stream_id_t stream_id, - unsigned int start) +static inline void cras_fill_set_aec_dump_message(struct cras_set_aec_dump *m, + cras_stream_id_t stream_id, + unsigned int start) { m->header.id = CRAS_SERVER_SET_AEC_DUMP; m->header.length = sizeof(*m); @@ -479,39 +499,38 @@ static inline void cras_fill_set_aec_dump_message( } /* Reload the aec configuration. */ -struct __attribute__ ((__packed__)) cras_reload_aec_config { +struct __attribute__((__packed__)) cras_reload_aec_config { struct cras_server_message header; }; -static inline void cras_fill_reload_aec_config( - struct cras_reload_aec_config *m) +static inline void cras_fill_reload_aec_config(struct cras_reload_aec_config *m) { m->header.id = CRAS_SERVER_RELOAD_AEC_CONFIG; m->header.length = sizeof(*m); } /* Sets the flag to enable or disable bluetooth wideband speech feature. */ -struct __attribute__ ((__packed__)) cras_set_bt_wbs_enabled { +struct __attribute__((__packed__)) cras_set_bt_wbs_enabled { struct cras_server_message header; unsigned int enabled; }; -static inline void cras_fill_set_bt_wbs_enabled( - struct cras_set_bt_wbs_enabled *m, - unsigned int enabled) +static inline void +cras_fill_set_bt_wbs_enabled(struct cras_set_bt_wbs_enabled *m, + unsigned int enabled) { m->header.id = CRAS_SERVER_SET_BT_WBS_ENABLED; m->header.length = sizeof(*m); m->enabled = enabled; } -struct __attribute__ ((__packed__)) cras_register_notification { - struct cras_server_message header; - uint32_t msg_id; - int do_register; +struct __attribute__((__packed__)) cras_register_notification { + struct cras_server_message header; + uint32_t msg_id; + int do_register; }; -static inline void cras_fill_register_notification_message( - struct cras_register_notification *m, - enum CRAS_CLIENT_MESSAGE_ID msg_id, - int do_register) +static inline void +cras_fill_register_notification_message(struct cras_register_notification *m, + enum CRAS_CLIENT_MESSAGE_ID msg_id, + int do_register) { m->header.id = CRAS_SERVER_REGISTER_NOTIFICATION; m->header.length = sizeof(*m); @@ -524,13 +543,12 @@ static inline void cras_fill_register_notification_message( */ /* Reply from the server indicating that the client has connected. */ -struct __attribute__ ((__packed__)) cras_client_connected { +struct __attribute__((__packed__)) cras_client_connected { struct cras_client_message header; uint32_t client_id; }; -static inline void cras_fill_client_connected( - struct cras_client_connected *m, - size_t client_id) +static inline void cras_fill_client_connected(struct cras_client_connected *m, + size_t client_id) { m->client_id = client_id; m->header.id = CRAS_CLIENT_CONNECTED; @@ -544,7 +562,7 @@ static inline void cras_fill_client_connected( * samples_shm_size is shm_max_size for old clients. * TODO(fletcherw) remove comment once all clients are on CRAS_PROTO_VER >= 3. */ -struct __attribute__ ((__packed__)) cras_client_stream_connected { +struct __attribute__((__packed__)) cras_client_stream_connected { struct cras_client_message header; int32_t err; cras_stream_id_t stream_id; @@ -569,62 +587,80 @@ cras_fill_client_stream_connected(struct cras_client_stream_connected *m, } /* Sent from server to client when audio debug information is requested. */ -struct cras_client_audio_debug_info_ready { +struct __attribute__((__packed__)) cras_client_audio_debug_info_ready { struct cras_client_message header; }; static inline void cras_fill_client_audio_debug_info_ready( - struct cras_client_audio_debug_info_ready *m) + struct cras_client_audio_debug_info_ready *m) { m->header.id = CRAS_CLIENT_AUDIO_DEBUG_INFO_READY; m->header.length = sizeof(*m); } +struct __attribute__((__packed__)) cras_client_atlog_fd_ready { + struct cras_client_message header; +}; + +static inline void +cras_fill_client_atlog_fd_ready(struct cras_client_atlog_fd_ready *m) +{ + m->header.id = CRAS_CLIENT_ATLOG_FD_READY; + m->header.length = sizeof(*m); +} + /* Sent from server to client when hotword models info is ready. */ -struct cras_client_get_hotword_models_ready { +struct __attribute__((__packed__)) cras_client_get_hotword_models_ready { struct cras_client_message header; int32_t hotword_models_size; - uint8_t hotword_models[CRAS_MAX_HOTWORD_MODELS]; + uint8_t hotword_models[CRAS_MAX_HOTWORD_MODELS + 1]; }; static inline void cras_fill_client_get_hotword_models_ready( - struct cras_client_get_hotword_models_ready *m, - const char *hotword_models, - size_t hotword_models_size) + struct cras_client_get_hotword_models_ready *m, + const char *hotword_models, size_t hotword_models_size) { m->header.id = CRAS_CLIENT_GET_HOTWORD_MODELS_READY; - m->header.length = sizeof(*m) + hotword_models_size; + m->header.length = sizeof(*m); m->hotword_models_size = hotword_models_size; - memcpy(m->hotword_models, hotword_models, hotword_models_size); + /* Copy string data with terminator. */ + if (hotword_models) { + strncpy((char *)m->hotword_models, hotword_models, + CRAS_MAX_HOTWORD_MODELS); + m->hotword_models[CRAS_MAX_HOTWORD_MODELS] = '\0'; + } } /* System status messages sent from server to client when state changes. */ -struct __attribute__ ((__packed__)) cras_client_volume_changed { +struct __attribute__((__packed__)) cras_client_volume_changed { struct cras_client_message header; int32_t volume; }; -static inline void cras_fill_client_output_volume_changed( - struct cras_client_volume_changed *m, int32_t volume) +static inline void +cras_fill_client_output_volume_changed(struct cras_client_volume_changed *m, + int32_t volume) { m->header.id = CRAS_CLIENT_OUTPUT_VOLUME_CHANGED; m->header.length = sizeof(*m); m->volume = volume; } -static inline void cras_fill_client_capture_gain_changed( - struct cras_client_volume_changed *m, int32_t gain) +static inline void +cras_fill_client_capture_gain_changed(struct cras_client_volume_changed *m, + int32_t gain) { m->header.id = CRAS_CLIENT_CAPTURE_GAIN_CHANGED; m->header.length = sizeof(*m); m->volume = gain; } -struct __attribute__ ((__packed__)) cras_client_mute_changed { +struct __attribute__((__packed__)) cras_client_mute_changed { struct cras_client_message header; int32_t muted; int32_t user_muted; int32_t mute_locked; }; -static inline void cras_fill_client_output_mute_changed( - struct cras_client_mute_changed *m, int32_t muted, - int32_t user_muted, int32_t mute_locked) +static inline void +cras_fill_client_output_mute_changed(struct cras_client_mute_changed *m, + int32_t muted, int32_t user_muted, + int32_t mute_locked) { m->header.id = CRAS_CLIENT_OUTPUT_MUTE_CHANGED; m->header.length = sizeof(*m); @@ -632,9 +668,9 @@ static inline void cras_fill_client_output_mute_changed( m->user_muted = user_muted; m->mute_locked = mute_locked; } -static inline void cras_fill_client_capture_mute_changed( - struct cras_client_mute_changed *m, int32_t muted, - int32_t mute_locked) +static inline void +cras_fill_client_capture_mute_changed(struct cras_client_mute_changed *m, + int32_t muted, int32_t mute_locked) { m->header.id = CRAS_CLIENT_CAPTURE_MUTE_CHANGED; m->header.length = sizeof(*m); @@ -643,25 +679,25 @@ static inline void cras_fill_client_capture_mute_changed( m->mute_locked = mute_locked; } -struct __attribute__ ((__packed__)) cras_client_nodes_changed { +struct __attribute__((__packed__)) cras_client_nodes_changed { struct cras_client_message header; }; -static inline void cras_fill_client_nodes_changed( - struct cras_client_nodes_changed *m) +static inline void +cras_fill_client_nodes_changed(struct cras_client_nodes_changed *m) { m->header.id = CRAS_CLIENT_NODES_CHANGED; m->header.length = sizeof(*m); } -struct __attribute__ ((__packed__)) cras_client_active_node_changed { +struct __attribute__((__packed__)) cras_client_active_node_changed { struct cras_client_message header; uint32_t direction; cras_node_id_t node_id; }; -static inline void cras_fill_client_active_node_changed ( - struct cras_client_active_node_changed *m, - enum CRAS_STREAM_DIRECTION direction, - cras_node_id_t node_id) +static inline void +cras_fill_client_active_node_changed(struct cras_client_active_node_changed *m, + enum CRAS_STREAM_DIRECTION direction, + cras_node_id_t node_id) { m->header.id = CRAS_CLIENT_ACTIVE_NODE_CHANGED; m->header.length = sizeof(*m); @@ -669,35 +705,32 @@ static inline void cras_fill_client_active_node_changed ( m->node_id = node_id; }; -struct __attribute__ ((__packed__)) cras_client_node_value_changed { +struct __attribute__((__packed__)) cras_client_node_value_changed { struct cras_client_message header; cras_node_id_t node_id; int32_t value; }; -static inline void cras_fill_client_output_node_volume_changed ( - struct cras_client_node_value_changed *m, - cras_node_id_t node_id, - int32_t volume) +static inline void cras_fill_client_output_node_volume_changed( + struct cras_client_node_value_changed *m, cras_node_id_t node_id, + int32_t volume) { m->header.id = CRAS_CLIENT_OUTPUT_NODE_VOLUME_CHANGED; m->header.length = sizeof(*m); m->node_id = node_id; m->value = volume; }; -static inline void cras_fill_client_node_left_right_swapped_changed ( - struct cras_client_node_value_changed *m, - cras_node_id_t node_id, - int swapped) +static inline void cras_fill_client_node_left_right_swapped_changed( + struct cras_client_node_value_changed *m, cras_node_id_t node_id, + int swapped) { m->header.id = CRAS_CLIENT_NODE_LEFT_RIGHT_SWAPPED_CHANGED; m->header.length = sizeof(*m); m->node_id = node_id; m->value = swapped; }; -static inline void cras_fill_client_input_node_gain_changed ( - struct cras_client_node_value_changed *m, - cras_node_id_t node_id, - int32_t gain) +static inline void cras_fill_client_input_node_gain_changed( + struct cras_client_node_value_changed *m, cras_node_id_t node_id, + int32_t gain) { m->header.id = CRAS_CLIENT_INPUT_NODE_GAIN_CHANGED; m->header.length = sizeof(*m); @@ -705,15 +738,14 @@ static inline void cras_fill_client_input_node_gain_changed ( m->value = gain; }; -struct __attribute__ ((__packed__)) cras_client_num_active_streams_changed { +struct __attribute__((__packed__)) cras_client_num_active_streams_changed { struct cras_client_message header; uint32_t direction; uint32_t num_active_streams; }; -static inline void cras_fill_client_num_active_streams_changed ( - struct cras_client_num_active_streams_changed *m, - enum CRAS_STREAM_DIRECTION direction, - uint32_t num_active_streams) +static inline void cras_fill_client_num_active_streams_changed( + struct cras_client_num_active_streams_changed *m, + enum CRAS_STREAM_DIRECTION direction, uint32_t num_active_streams) { m->header.id = CRAS_CLIENT_NUM_ACTIVE_STREAMS_CHANGED; m->header.length = sizeof(*m); @@ -731,7 +763,7 @@ enum CRAS_AUDIO_MESSAGE_ID { NUM_AUDIO_MESSAGES }; -struct __attribute__ ((__packed__)) audio_message { +struct __attribute__((__packed__)) audio_message { enum CRAS_AUDIO_MESSAGE_ID id; int32_t error; uint32_t frames; /* number of samples per channel */ diff --git a/cras/src/common/cras_metrics.c b/cras/src/common/cras_metrics.c index ac1fda4d..b318fb44 100644 --- a/cras/src/common/cras_metrics.c +++ b/cras/src/common/cras_metrics.c @@ -20,8 +20,8 @@ void cras_metrics_log_event(const char *event) CMetricsLibraryDelete(handle); } -void cras_metrics_log_histogram(const char *name, int sample, int min, - int max, int nbuckets) +void cras_metrics_log_histogram(const char *name, int sample, int min, int max, + int nbuckets) { CMetricsLibrary handle; @@ -45,8 +45,8 @@ void cras_metrics_log_sparse_histogram(const char *name, int sample) void cras_metrics_log_event(const char *event) { } -void cras_metrics_log_histogram(const char *name, int sample, int min, - int max, int nbuckets) +void cras_metrics_log_histogram(const char *name, int sample, int min, int max, + int nbuckets) { } void cras_metrics_log_enum_histogram(const char *name, int sample, int max) diff --git a/cras/src/common/cras_metrics.h b/cras/src/common/cras_metrics.h index 82c1d218..814b3dde 100644 --- a/cras/src/common/cras_metrics.h +++ b/cras/src/common/cras_metrics.h @@ -10,8 +10,8 @@ void cras_metrics_log_event(const char *event); /* Sends histogram data. */ -void cras_metrics_log_histogram(const char *name, int sample, int min, - int max, int nbuckets); +void cras_metrics_log_histogram(const char *name, int sample, int min, int max, + int nbuckets); /* Sends sparse histogram data. */ void cras_metrics_log_sparse_histogram(const char *name, int sample); diff --git a/cras/src/common/cras_observer_ops.h b/cras/src/common/cras_observer_ops.h index 108f1667..70dd513c 100644 --- a/cras/src/common/cras_observer_ops.h +++ b/cras/src/common/cras_observer_ops.h @@ -17,8 +17,8 @@ struct cras_observer_ops { /* System output volume changed. */ void (*output_volume_changed)(void *context, int32_t volume); /* System output mute changed. */ - void (*output_mute_changed)(void *context, - int muted, int user_muted, int mute_locked); + void (*output_mute_changed)(void *context, int muted, int user_muted, + int mute_locked); /* System input/capture gain changed. */ void (*capture_gain_changed)(void *context, int32_t gain); /* System input/capture mute changed. */ @@ -39,19 +39,17 @@ struct cras_observer_ops { cras_node_id_t node_id, int swapped); /* Input gain changed. */ - void (*input_node_gain_changed)(void *context, - cras_node_id_t node_id, + void (*input_node_gain_changed)(void *context, cras_node_id_t node_id, int32_t gain); /* Suspend state changed. */ - void (*suspend_changed)(void *context, - int suspended); + void (*suspend_changed)(void *context, int suspended); /* Number of active streams changed. */ void (*num_active_streams_changed)(void *context, enum CRAS_STREAM_DIRECTION dir, uint32_t num_active_streams); /* Hotword triggered. */ - void (*hotword_triggered)(void *context, - int64_t tv_sec, int64_t tv_nsec); + void (*hotword_triggered)(void *context, int64_t tv_sec, + int64_t tv_nsec); /* State regarding whether non-empty audio is being played/captured has * changed. */ void (*non_empty_audio_state_changed)(void *context, int non_empty); diff --git a/cras/src/common/cras_sbc_codec.c b/cras/src/common/cras_sbc_codec.c index 231e137d..df02b3eb 100644 --- a/cras/src/common/cras_sbc_codec.c +++ b/cras/src/common/cras_sbc_codec.c @@ -24,7 +24,8 @@ struct cras_sbc_data { int cras_msbc_decode(struct cras_audio_codec *codec, const void *input, size_t input_len, void *output, size_t output_len, - size_t *count) { + size_t *count) +{ struct cras_sbc_data *data = (struct cras_sbc_data *)codec->priv_data; size_t written = 0; ssize_t decoded; @@ -33,11 +34,7 @@ int cras_msbc_decode(struct cras_audio_codec *codec, const void *input, * Proceed decode when there is buffer left in input and room in * output. */ - decoded = sbc_decode(&data->sbc, - input, - input_len, - output, - output_len, + decoded = sbc_decode(&data->sbc, input, input_len, output, output_len, &written); *count = written; @@ -46,7 +43,8 @@ int cras_msbc_decode(struct cras_audio_codec *codec, const void *input, int cras_msbc_encode(struct cras_audio_codec *codec, const void *input, size_t input_len, void *output, size_t output_len, - size_t *count) { + size_t *count) +{ struct cras_sbc_data *data = (struct cras_sbc_data *)codec->priv_data; ssize_t written = 0; ssize_t encoded; @@ -58,12 +56,8 @@ int cras_msbc_encode(struct cras_audio_codec *codec, const void *input, if (input_len < data->codesize) return -EINVAL; - encoded = sbc_encode(&data->sbc, - input, - data->codesize, - output, - output_len, - &written); + encoded = sbc_encode(&data->sbc, input, data->codesize, output, + output_len, &written); *count = written; return encoded; @@ -71,7 +65,8 @@ int cras_msbc_encode(struct cras_audio_codec *codec, const void *input, int cras_sbc_decode(struct cras_audio_codec *codec, const void *input, size_t input_len, void *output, size_t output_len, - size_t *count) { + size_t *count) +{ struct cras_sbc_data *data = (struct cras_sbc_data *)codec->priv_data; size_t written; ssize_t decoded; @@ -82,12 +77,9 @@ int cras_sbc_decode(struct cras_audio_codec *codec, const void *input, * output. */ while (input_len > processed && output_len > result) { - decoded = sbc_decode(&data->sbc, - input + processed, - input_len - processed, - output + result, - output_len - result, - &written); + decoded = sbc_decode(&data->sbc, input + processed, + input_len - processed, output + result, + output_len - result, &written); if (decoded <= 0) break; @@ -100,7 +92,8 @@ int cras_sbc_decode(struct cras_audio_codec *codec, const void *input, int cras_sbc_encode(struct cras_audio_codec *codec, const void *input, size_t input_len, void *output, size_t output_len, - size_t *count) { + size_t *count) +{ struct cras_sbc_data *data = (struct cras_sbc_data *)codec->priv_data; ssize_t written, encoded; int processed = 0, result = 0; @@ -109,13 +102,10 @@ int cras_sbc_encode(struct cras_audio_codec *codec, const void *input, * there is still room in output buffer. */ while (input_len - processed >= data->codesize && - output_len >= result) { - encoded = sbc_encode(&data->sbc, - input + processed, - data->codesize, - output + result, - output_len - result, - &written); + output_len >= result) { + encoded = sbc_encode(&data->sbc, input + processed, + data->codesize, output + result, + output_len - result, &written); if (encoded == -ENOSPC) break; else if (encoded < 0) @@ -149,8 +139,8 @@ struct cras_audio_codec *cras_msbc_codec_create() if (!codec) return NULL; - codec->priv_data = (struct cras_sbc_data *)calloc(1, - sizeof(struct cras_sbc_data)); + codec->priv_data = + (struct cras_sbc_data *)calloc(1, sizeof(struct cras_sbc_data)); if (!codec->priv_data) { free(codec); return NULL; @@ -166,9 +156,10 @@ struct cras_audio_codec *cras_msbc_codec_create() return codec; } -struct cras_audio_codec *cras_sbc_codec_create(uint8_t freq, - uint8_t mode, uint8_t subbands, uint8_t alloc, - uint8_t blocks, uint8_t bitpool) { +struct cras_audio_codec *cras_sbc_codec_create(uint8_t freq, uint8_t mode, + uint8_t subbands, uint8_t alloc, + uint8_t blocks, uint8_t bitpool) +{ struct cras_audio_codec *codec; struct cras_sbc_data *data; @@ -176,8 +167,8 @@ struct cras_audio_codec *cras_sbc_codec_create(uint8_t freq, if (!codec) return NULL; - codec->priv_data = (struct cras_sbc_data *)calloc(1, - sizeof(struct cras_sbc_data)); + codec->priv_data = + (struct cras_sbc_data *)calloc(1, sizeof(struct cras_sbc_data)); if (!codec->priv_data) goto create_error; diff --git a/cras/src/common/cras_sbc_codec.h b/cras/src/common/cras_sbc_codec.h index 1ccbbac6..322c45b6 100644 --- a/cras/src/common/cras_sbc_codec.h +++ b/cras/src/common/cras_sbc_codec.h @@ -19,9 +19,9 @@ * blocks: blocks for sbc encoder settings. * bitpool: bitpool for sbc encoder settings. */ -struct cras_audio_codec *cras_sbc_codec_create(uint8_t freq, - uint8_t mode, uint8_t subbands, uint8_t alloc, - uint8_t blocks, uint8_t bitpool); +struct cras_audio_codec *cras_sbc_codec_create(uint8_t freq, uint8_t mode, + uint8_t subbands, uint8_t alloc, + uint8_t blocks, uint8_t bitpool); /* Creates an mSBC codec, which is a version of SBC codec used for * wideband speech mode of HFP. */ diff --git a/cras/src/common/cras_selinux_helper.c b/cras/src/common/cras_selinux_helper.c index 59717bb9..ddacc6a8 100644 --- a/cras/src/common/cras_selinux_helper.c +++ b/cras/src/common/cras_selinux_helper.c @@ -6,6 +6,7 @@ #include "cras_shm.h" -int cras_selinux_restorecon(const char *pathname) { +int cras_selinux_restorecon(const char *pathname) +{ return selinux_restorecon(pathname, 0); } diff --git a/cras/src/common/cras_shm.c b/cras/src/common/cras_shm.c index 7d1d5261..3e6c2b7e 100644 --- a/cras/src/common/cras_shm.c +++ b/cras/src/common/cras_shm.c @@ -26,7 +26,8 @@ int cras_shm_info_init(const char *stream_name, uint32_t length, if (!info_out) return -EINVAL; - strncpy(info.name, stream_name, sizeof(info.name)); + strncpy(info.name, stream_name, sizeof(info.name) - 1); + info.name[sizeof(info.name) - 1] = '\0'; info.length = length; info.fd = cras_shm_open_rw(info.name, info.length); if (info.fd < 0) @@ -87,7 +88,7 @@ void cras_shm_info_cleanup(struct cras_shm_info *info) } int cras_audio_shm_create(struct cras_shm_info *header_info, - struct cras_shm_info *samples_info, + struct cras_shm_info *samples_info, int samples_prot, struct cras_audio_shm **shm_out) { struct cras_audio_shm *shm; @@ -98,6 +99,13 @@ int cras_audio_shm_create(struct cras_shm_info *header_info, goto cleanup_info; } + if (samples_prot != PROT_READ && samples_prot != PROT_WRITE) { + ret = -EINVAL; + syslog(LOG_ERR, + "cras_shm: samples must be mapped read or write only"); + goto cleanup_info; + } + shm = calloc(1, sizeof(*shm)); if (!shm) { ret = -ENOMEM; @@ -130,7 +138,7 @@ int cras_audio_shm_create(struct cras_shm_info *header_info, goto free_shm; } - shm->samples = mmap(NULL, samples_info->length, PROT_READ | PROT_WRITE, + shm->samples = mmap(NULL, samples_info->length, samples_prot, MAP_SHARED, samples_info->fd, 0); if (shm->samples == (uint8_t *)-1) { ret = errno; @@ -154,68 +162,13 @@ cleanup_info: return ret; } -// TODO(fletcherw) remove once libcras in ARC++ has been upreved -int cras_audio_unsplit_shm_create(struct cras_shm_info *shm_info, - struct cras_audio_shm **shm_out) -{ - struct cras_audio_shm *shm; - int ret; - - if (!shm_info || !shm_out) { - ret = -EINVAL; - goto cleanup_info; - } - - shm = calloc(1, sizeof(*shm)); - if (!shm) { - ret = -ENOMEM; - goto cleanup_info; - } - /* Move the shm info param into the new cras_audio_shm object. - * shm_info is cleared, and the owner of cras_audio_shm is now - * responsible for closing the fd and unlinking any associated shm - * file using cras_audio_shm_destroy. - */ - ret = cras_shm_info_move(shm_info, &shm->header_info); - if (ret) - goto free_shm; - - shm->header = - mmap(NULL, shm->header_info.length, PROT_READ | PROT_WRITE, - MAP_SHARED, shm->header_info.fd, 0); - if (shm->header == (struct cras_audio_shm_header *)-1) { - ret = errno; - syslog(LOG_ERR, "cras_shm: mmap failed to map shm for header."); - goto free_shm; - } - - // Point the samples pointer in shm into the header shm area so that - // the legacy unsplit shm can share code with the new split shm. - shm->samples = shm->header->samples; - - cras_shm_set_volume_scaler(shm, 1.0); - - *shm_out = shm; - return 0; - -free_shm: - free(shm); -cleanup_info: - cras_shm_info_cleanup(shm_info); - return ret; -} - void cras_audio_shm_destroy(struct cras_audio_shm *shm) { if (!shm) return; - // Calls munmap only for split version shm. - // TODO(paulhsia): Remove this check after cleanup unsplit shm. - if (shm->samples_info.length > 0) { - munmap(shm->samples, shm->samples_info.length); - cras_shm_info_cleanup(&shm->samples_info); - } + munmap(shm->samples, shm->samples_info.length); + cras_shm_info_cleanup(&shm->samples_info); munmap(shm->header, shm->header_info.length); cras_shm_info_cleanup(&shm->header_info); free(shm); @@ -227,7 +180,8 @@ static void cras_shm_restorecon(int fd) #ifdef CRAS_SELINUX char fd_proc_path[64]; - if (snprintf(fd_proc_path, sizeof(fd_proc_path), "/proc/self/fd/%d", fd) < 0) { + if (snprintf(fd_proc_path, sizeof(fd_proc_path), "/proc/self/fd/%d", + fd) < 0) { syslog(LOG_WARNING, "Couldn't construct proc symlink path of fd: %d", fd); return; @@ -242,8 +196,8 @@ static void cras_shm_restorecon(int fd) } if (cras_selinux_restorecon(path) < 0) { - syslog(LOG_WARNING, "Restorecon on %s failed: %s", - fd_proc_path, strerror(errno)); + syslog(LOG_WARNING, "Restorecon on %s failed: %s", fd_proc_path, + strerror(errno)); } free(path); @@ -252,7 +206,7 @@ static void cras_shm_restorecon(int fd) #ifdef __BIONIC__ -int cras_shm_open_rw (const char *name, size_t size) +int cras_shm_open_rw(const char *name, size_t size) { int fd; @@ -262,33 +216,32 @@ int cras_shm_open_rw (const char *name, size_t size) fd = ashmem_create_region(name, size); if (fd < 0) { fd = -errno; - syslog(LOG_ERR, "failed to ashmem_create_region %s: %s\n", - name, strerror(-fd)); + syslog(LOG_ERR, "failed to ashmem_create_region %s: %s\n", name, + strerror(-fd)); } return fd; } -int cras_shm_reopen_ro (const char *name, int fd) +int cras_shm_reopen_ro(const char *name, int fd) { /* After mmaping the ashmem read/write, change it's protection bits to disallow further write access. */ if (ashmem_set_prot_region(fd, PROT_READ) != 0) { fd = -errno; - syslog(LOG_ERR, - "failed to ashmem_set_prot_region %s: %s\n", + syslog(LOG_ERR, "failed to ashmem_set_prot_region %s: %s\n", name, strerror(-fd)); } return fd; } -void cras_shm_close_unlink (const char *name, int fd) +void cras_shm_close_unlink(const char *name, int fd) { close(fd); } #else -int cras_shm_open_rw (const char *name, size_t size) +int cras_shm_open_rw(const char *name, size_t size) { int fd; int rc; @@ -296,15 +249,15 @@ int cras_shm_open_rw (const char *name, size_t size) fd = shm_open(name, O_CREAT | O_EXCL | O_RDWR, 0600); if (fd < 0) { fd = -errno; - syslog(LOG_ERR, "failed to shm_open %s: %s\n", - name, strerror(-fd)); + syslog(LOG_ERR, "failed to shm_open %s: %s\n", name, + strerror(-fd)); return fd; } rc = ftruncate(fd, size); if (rc) { rc = -errno; - syslog(LOG_ERR, "failed to set size of shm %s: %s\n", - name, strerror(-rc)); + syslog(LOG_ERR, "failed to set size of shm %s: %s\n", name, + strerror(-rc)); return rc; } @@ -313,7 +266,7 @@ int cras_shm_open_rw (const char *name, size_t size) return fd; } -int cras_shm_reopen_ro (const char *name, int fd) +int cras_shm_reopen_ro(const char *name, int fd) { /* Open a read-only copy to dup and pass to clients. */ fd = shm_open(name, O_RDONLY, 0); @@ -326,7 +279,7 @@ int cras_shm_reopen_ro (const char *name, int fd) return fd; } -void cras_shm_close_unlink (const char *name, int fd) +void cras_shm_close_unlink(const char *name, int fd) { shm_unlink(name); close(fd); @@ -334,9 +287,7 @@ void cras_shm_close_unlink (const char *name, int fd) #endif -void *cras_shm_setup(const char *name, - size_t mmap_size, - int *rw_fd_out, +void *cras_shm_setup(const char *name, size_t mmap_size, int *rw_fd_out, int *ro_fd_out) { int rw_shm_fd = cras_shm_open_rw(name, mmap_size); @@ -344,9 +295,8 @@ void *cras_shm_setup(const char *name, return NULL; /* mmap shm. */ - void *exp_state = mmap(NULL, mmap_size, - PROT_READ | PROT_WRITE, MAP_SHARED, - rw_shm_fd, 0); + void *exp_state = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, + MAP_SHARED, rw_shm_fd, 0); if (exp_state == (void *)-1) return NULL; diff --git a/cras/src/common/cras_shm.h b/cras/src/common/cras_shm.h index 83aae8bc..f9c93920 100644 --- a/cras/src/common/cras_shm.h +++ b/cras/src/common/cras_shm.h @@ -8,6 +8,7 @@ #include <assert.h> #include <stdint.h> +#include <sys/mman.h> #include <sys/param.h> #include "cras_types.h" @@ -21,7 +22,7 @@ * used_size - The size in bytes of the sample area being actively used. * frame_bytes - The size of each frame in bytes. */ -struct __attribute__ ((__packed__)) cras_audio_shm_config { +struct __attribute__((__packed__)) cras_audio_shm_config { uint32_t used_size; uint32_t frame_bytes; }; @@ -43,10 +44,8 @@ struct __attribute__ ((__packed__)) cras_audio_shm_config { * ts - For capture, the time stamp of the next sample at read_index. For * playback, this is the time that the next sample written will be played. * This is only valid in audio callbacks. - * - * TODO(fletcherw) remove once libcras in ARC++ has been upreved - * samples - Audio data - a double buffered area that is used to exchange - * audio samples. + * buffer_offset - Offset of each buffer from start of samples area. + * Valid range: 0 <= buffer_offset <= shm->samples_info.length */ struct __attribute__((__packed__)) cras_audio_shm_header { struct cras_audio_shm_config config; @@ -60,7 +59,7 @@ struct __attribute__((__packed__)) cras_audio_shm_header { int32_t callback_pending; uint32_t num_overruns; struct cras_timespec ts; - uint8_t samples[]; + uint32_t buffer_offset[CRAS_NUM_SHM_BUFFERS]; }; /* Returns the number of bytes needed to hold a cras_audio_shm_header. */ @@ -144,31 +143,31 @@ struct cras_audio_shm { * The samples_info parameter will be returned to an * uninitialized state, and the client need not call * cras_shm_info_destroy. - * This parameter may be NULL. In that case, no shared memory will - * be mapped for the samples. + * samples_prot - the mapping protections to use when mapping samples. Allowed + * values are PROT_READ or PROT_WRITE. * shm_out - pointer where the created cras_audio_shm will be stored. */ int cras_audio_shm_create(struct cras_shm_info *header_info, - struct cras_shm_info *samples_info, + struct cras_shm_info *samples_info, int samples_prot, struct cras_audio_shm **shm_out); -/* Sets up a legacy cras_audio_shm given info about the shared memory to use - * - * shm_info - the underlying shm area to use for the audio shm. The shm - * will be managed by the created cras_audio_shm object. - * The shm_info parameter will be returned to an uninitialized - * state, and the client need not call cras_shm_info_destroy. - * shm_out - pointer where the created cras_audio_shm will be stored. - */ -int cras_audio_unsplit_shm_create(struct cras_shm_info *shm_info, - struct cras_audio_shm **shm_out); - /* Destroys a cras_audio_shm returned from cras_audio_shm_create. * * shm - the cras_audio_shm to destroy. */ void cras_audio_shm_destroy(struct cras_audio_shm *shm); +/* Limit a buffer offset to within the samples area size. */ +static inline unsigned +cras_shm_get_checked_buffer_offset(const struct cras_audio_shm *shm, + uint32_t buf_idx) +{ + unsigned buffer_offset = shm->header->buffer_offset[buf_idx]; + + /* Cap buffer_offset at the length of the samples area */ + return MIN(buffer_offset, shm->samples_info.length); +} + /* Get a pointer to the buffer at idx. */ static inline uint8_t *cras_shm_buff_for_idx(const struct cras_audio_shm *shm, size_t idx) @@ -176,46 +175,58 @@ static inline uint8_t *cras_shm_buff_for_idx(const struct cras_audio_shm *shm, assert_on_compile_is_power_of_2(CRAS_NUM_SHM_BUFFERS); idx = idx & CRAS_SHM_BUFFERS_MASK; - return shm->samples + shm->config.used_size * idx; + return shm->samples + cras_shm_get_checked_buffer_offset(shm, idx); } /* Limit a read offset to within the buffer size. */ -static inline -unsigned cras_shm_check_read_offset(const struct cras_audio_shm *shm, - unsigned offset) +static inline unsigned +cras_shm_get_checked_read_offset(const struct cras_audio_shm *shm, + uint32_t buf_idx) { - /* The offset is allowed to be the total size, indicating that the + unsigned buffer_offset = + cras_shm_get_checked_buffer_offset(shm, buf_idx); + unsigned read_offset = shm->header->read_offset[buf_idx]; + + /* The read_offset is allowed to be the total size, indicating that the * buffer is full. If read pointer is invalid assume it is at the * beginning. */ - if (offset > shm->config.used_size) + if (read_offset > shm->config.used_size) + return 0; + if (buffer_offset + read_offset > shm->samples_info.length) return 0; - return offset; + return read_offset; } /* Limit a write offset to within the buffer size. */ -static inline -unsigned cras_shm_check_write_offset(const struct cras_audio_shm *shm, - unsigned offset) +static inline unsigned +cras_shm_get_checked_write_offset(const struct cras_audio_shm *shm, + uint32_t buf_idx) { - /* The offset is allowed to be the total size, indicating that the - * buffer is full. If write pointer is invalid assume it is at the - * end. */ - if (offset > shm->config.used_size) - return shm->config.used_size; - return offset; + unsigned write_offset = shm->header->write_offset[buf_idx]; + unsigned buffer_offset = + cras_shm_get_checked_buffer_offset(shm, buf_idx); + + /* The write_offset is allowed to be the total size, indicating that the + * buffer is full. If write pointer is past used size, assume it is at + * used size. */ + write_offset = MIN(write_offset, shm->config.used_size); + + /* If the buffer offset plus the write offset overruns the samples area, + * return the longest valid write_offset */ + if (buffer_offset + write_offset > shm->samples_info.length) + return shm->samples_info.length - buffer_offset; + return write_offset; } /* Get the number of frames readable in current read buffer */ -static inline -unsigned cras_shm_get_curr_read_frames(const struct cras_audio_shm *shm) +static inline unsigned +cras_shm_get_curr_read_frames(const struct cras_audio_shm *shm) { - unsigned i = shm->header->read_buf_idx & CRAS_SHM_BUFFERS_MASK; + unsigned buf_idx = shm->header->read_buf_idx & CRAS_SHM_BUFFERS_MASK; unsigned read_offset, write_offset; - read_offset = - cras_shm_check_read_offset(shm, shm->header->read_offset[i]); - write_offset = - cras_shm_check_write_offset(shm, shm->header->write_offset[i]); + read_offset = cras_shm_get_checked_read_offset(shm, buf_idx); + write_offset = cras_shm_get_checked_write_offset(shm, buf_idx); if (read_offset > write_offset) return 0; @@ -224,16 +235,16 @@ unsigned cras_shm_get_curr_read_frames(const struct cras_audio_shm *shm) } /* Get the base of the current read buffer. */ -static inline -uint8_t *cras_shm_get_read_buffer_base(const struct cras_audio_shm *shm) +static inline uint8_t * +cras_shm_get_read_buffer_base(const struct cras_audio_shm *shm) { unsigned i = shm->header->read_buf_idx & CRAS_SHM_BUFFERS_MASK; return cras_shm_buff_for_idx(shm, i); } /* Get the base of the current write buffer. */ -static inline -uint8_t *cras_shm_get_write_buffer_base(const struct cras_audio_shm *shm) +static inline uint8_t * +cras_shm_get_write_buffer_base(const struct cras_audio_shm *shm) { unsigned i = shm->header->write_buf_idx & CRAS_SHM_BUFFERS_MASK; @@ -241,18 +252,16 @@ uint8_t *cras_shm_get_write_buffer_base(const struct cras_audio_shm *shm) } /* Get a pointer to the next buffer to write */ -static inline -uint8_t *cras_shm_get_writeable_frames(const struct cras_audio_shm *shm, - unsigned limit_frames, - unsigned *frames) +static inline uint8_t * +cras_shm_get_writeable_frames(const struct cras_audio_shm *shm, + unsigned limit_frames, unsigned *frames) { - unsigned i = shm->header->write_buf_idx & CRAS_SHM_BUFFERS_MASK; + unsigned buf_idx = shm->header->write_buf_idx & CRAS_SHM_BUFFERS_MASK; unsigned write_offset; const unsigned frame_bytes = shm->config.frame_bytes; unsigned written; - write_offset = - cras_shm_check_write_offset(shm, shm->header->write_offset[i]); + write_offset = cras_shm_get_checked_write_offset(shm, buf_idx); written = write_offset / frame_bytes; if (frames) { if (limit_frames >= written) @@ -261,34 +270,30 @@ uint8_t *cras_shm_get_writeable_frames(const struct cras_audio_shm *shm, *frames = 0; } - return cras_shm_buff_for_idx(shm, i) + write_offset; + return cras_shm_buff_for_idx(shm, buf_idx) + write_offset; } /* Get a pointer to the current read buffer plus an offset. The offset might be * in the next buffer. 'frames' is filled with the number of frames that can be * copied from the returned buffer. */ -static inline -uint8_t *cras_shm_get_readable_frames(const struct cras_audio_shm *shm, - size_t offset, - size_t *frames) +static inline uint8_t * +cras_shm_get_readable_frames(const struct cras_audio_shm *shm, size_t offset, + size_t *frames) { unsigned buf_idx = shm->header->read_buf_idx & CRAS_SHM_BUFFERS_MASK; unsigned read_offset, write_offset, final_offset; assert(frames != NULL); - read_offset = cras_shm_check_read_offset( - shm, shm->header->read_offset[buf_idx]); - write_offset = cras_shm_check_write_offset( - shm, shm->header->write_offset[buf_idx]); + read_offset = cras_shm_get_checked_read_offset(shm, buf_idx); + write_offset = cras_shm_get_checked_write_offset(shm, buf_idx); final_offset = read_offset + offset * shm->config.frame_bytes; if (final_offset >= write_offset) { final_offset -= write_offset; assert_on_compile_is_power_of_2(CRAS_NUM_SHM_BUFFERS); buf_idx = (buf_idx + 1) & CRAS_SHM_BUFFERS_MASK; - write_offset = cras_shm_check_write_offset( - shm, shm->header->write_offset[buf_idx]); + write_offset = cras_shm_get_checked_write_offset(shm, buf_idx); } if (final_offset >= write_offset) { /* Past end of samples. */ @@ -330,8 +335,8 @@ static inline int cras_shm_get_frames(const struct cras_audio_shm *shm) } /* How many frames in the current buffer? */ -static inline -size_t cras_shm_get_frames_in_curr_buffer(const struct cras_audio_shm *shm) +static inline size_t +cras_shm_get_frames_in_curr_buffer(const struct cras_audio_shm *shm) { size_t buf_idx = shm->header->read_buf_idx & CRAS_SHM_BUFFERS_MASK; unsigned read_offset, write_offset; @@ -355,8 +360,8 @@ static inline int cras_shm_is_buffer_available(const struct cras_audio_shm *shm) } /* How many are available to be written? */ -static inline -size_t cras_shm_get_num_writeable(const struct cras_audio_shm *shm) +static inline size_t +cras_shm_get_num_writeable(const struct cras_audio_shm *shm) { /* Not allowed to write to a buffer twice. */ if (!cras_shm_is_buffer_available(shm)) @@ -390,8 +395,8 @@ static inline int cras_shm_check_write_overrun(struct cras_audio_shm *shm) } /* Increment the write pointer for the current buffer. */ -static inline -void cras_shm_buffer_written(struct cras_audio_shm *shm, size_t frames) +static inline void cras_shm_buffer_written(struct cras_audio_shm *shm, + size_t frames) { size_t buf_idx = shm->header->write_buf_idx & CRAS_SHM_BUFFERS_MASK; @@ -403,8 +408,8 @@ void cras_shm_buffer_written(struct cras_audio_shm *shm, size_t frames) } /* Returns the number of frames that have been written to the current buffer. */ -static inline -unsigned int cras_shm_frames_written(const struct cras_audio_shm *shm) +static inline unsigned int +cras_shm_frames_written(const struct cras_audio_shm *shm) { size_t buf_idx = shm->header->write_buf_idx & CRAS_SHM_BUFFERS_MASK; @@ -424,8 +429,8 @@ static inline void cras_shm_buffer_write_complete(struct cras_audio_shm *shm) } /* Set the write pointer for the current buffer and complete the write. */ -static inline -void cras_shm_buffer_written_start(struct cras_audio_shm *shm, size_t frames) +static inline void cras_shm_buffer_written_start(struct cras_audio_shm *shm, + size_t frames) { size_t buf_idx = shm->header->write_buf_idx & CRAS_SHM_BUFFERS_MASK; @@ -436,8 +441,8 @@ void cras_shm_buffer_written_start(struct cras_audio_shm *shm, size_t frames) /* Increment the read pointer. If it goes past the write pointer for this * buffer, move to the next buffer. */ -static inline -void cras_shm_buffer_read(struct cras_audio_shm *shm, size_t frames) +static inline void cras_shm_buffer_read(struct cras_audio_shm *shm, + size_t frames) { size_t buf_idx = shm->header->read_buf_idx & CRAS_SHM_BUFFERS_MASK; size_t remainder; @@ -468,8 +473,8 @@ void cras_shm_buffer_read(struct cras_audio_shm *shm, size_t frames) /* Read from the current buffer. This is similar to cras_shm_buffer_read(), but * it doesn't check for the case we may read from two buffers. */ -static inline -void cras_shm_buffer_read_current(struct cras_audio_shm *shm, size_t frames) +static inline void cras_shm_buffer_read_current(struct cras_audio_shm *shm, + size_t frames) { size_t buf_idx = shm->header->read_buf_idx & CRAS_SHM_BUFFERS_MASK; struct cras_audio_shm_header *header = shm->header; @@ -486,8 +491,8 @@ void cras_shm_buffer_read_current(struct cras_audio_shm *shm, size_t frames) /* Sets the volume for the stream. The volume level is a scaling factor that * will be applied to the stream before mixing. */ -static inline -void cras_shm_set_volume_scaler(struct cras_audio_shm *shm, float volume_scaler) +static inline void cras_shm_set_volume_scaler(struct cras_audio_shm *shm, + float volume_scaler) { volume_scaler = MAX(volume_scaler, 0.0); shm->header->volume_scaler = MIN(volume_scaler, 1.0); @@ -527,8 +532,8 @@ static inline unsigned cras_shm_frame_bytes(const struct cras_audio_shm *shm) } /* Sets if a callback is pending with the client. */ -static inline -void cras_shm_set_callback_pending(struct cras_audio_shm *shm, int pending) +static inline void cras_shm_set_callback_pending(struct cras_audio_shm *shm, + int pending) { shm->header->callback_pending = !!pending; } @@ -539,15 +544,29 @@ static inline int cras_shm_callback_pending(const struct cras_audio_shm *shm) return shm->header->callback_pending; } +/* Sets the starting offset of a buffer */ +static inline void cras_shm_set_buffer_offset(struct cras_audio_shm *shm, + uint32_t buf_idx, uint32_t offset) +{ + shm->header->buffer_offset[buf_idx] = offset; +} + /* Sets the used_size of the shm region. This is the maximum number of bytes * that is exchanged each time a buffer is passed from client to server. + * + * Also sets the buffer_offsets to default values based on the used size. */ -static inline -void cras_shm_set_used_size(struct cras_audio_shm *shm, unsigned used_size) +static inline void cras_shm_set_used_size(struct cras_audio_shm *shm, + unsigned used_size) { + uint32_t i; + shm->config.used_size = used_size; if (shm->header) shm->header->config.used_size = used_size; + + for (i = 0; i < CRAS_NUM_SHM_BUFFERS; i++) + cras_shm_set_buffer_offset(shm, i, i * used_size); } /* Returns the used size of the shm region in bytes. */ @@ -565,12 +584,11 @@ static inline unsigned cras_shm_used_frames(const struct cras_audio_shm *shm) /* Returns the size of the samples shm region. */ static inline unsigned cras_shm_samples_size(const struct cras_audio_shm *shm) { - return cras_shm_used_size(shm) * CRAS_NUM_SHM_BUFFERS; + return shm->samples_info.length; } /* Gets the counter of over-runs. */ -static inline -unsigned cras_shm_num_overruns(const struct cras_audio_shm *shm) +static inline unsigned cras_shm_num_overruns(const struct cras_audio_shm *shm) { return shm->header->num_overruns; } @@ -590,7 +608,7 @@ static inline void cras_shm_copy_shared_config(struct cras_audio_shm *shm) * Returns: * >= 0 file descriptor value, or negative errno value on error. */ -int cras_shm_open_rw (const char *name, size_t size); +int cras_shm_open_rw(const char *name, size_t size); /* Reopen an existing shared memory area read-only. * Args: @@ -599,7 +617,7 @@ int cras_shm_open_rw (const char *name, size_t size); * Returns: * >= 0 new file descriptor value, or negative errno value on error. */ -int cras_shm_reopen_ro (const char *name, int fd); +int cras_shm_reopen_ro(const char *name, int fd); /* Close and delete a shared memory area. * Args: @@ -608,7 +626,7 @@ int cras_shm_reopen_ro (const char *name, int fd); * Returns: * >= 0 new file descriptor value, or negative errno value on error. */ -void cras_shm_close_unlink (const char *name, int fd); +void cras_shm_close_unlink(const char *name, int fd); /* * Configure shared memory for the system state. @@ -619,9 +637,7 @@ void cras_shm_close_unlink (const char *name, int fd); * ro_fd_out - Filled with the RO fd for the shm region. * Returns a pointer to the new shared memory region. Or NULL on error. */ -void *cras_shm_setup(const char *name, - size_t mmap_size, - int *rw_fd_out, +void *cras_shm_setup(const char *name, size_t mmap_size, int *rw_fd_out, int *ro_fd_out); #ifdef CRAS_SELINUX diff --git a/cras/src/common/cras_types.h b/cras/src/common/cras_types.h index e3b72752..3dd9413a 100644 --- a/cras/src/common/cras_types.h +++ b/cras/src/common/cras_types.h @@ -9,6 +9,7 @@ #ifndef CRAS_TYPES_H_ #define CRAS_TYPES_H_ +#include <stdbool.h> #include <stdint.h> #include <stdlib.h> @@ -16,7 +17,7 @@ #include "cras_iodev_info.h" /* Architecture independent timespec */ -struct __attribute__ ((__packed__)) cras_timespec { +struct __attribute__((__packed__)) cras_timespec { int64_t tv_sec; int64_t tv_nsec; }; @@ -37,12 +38,25 @@ enum TEST_IODEV_TYPE { TEST_IODEV_HOTWORD, }; - /* Commands for test iodevs. */ enum CRAS_TEST_IODEV_CMD { TEST_IODEV_CMD_HOTWORD_TRIGGER, }; +/* CRAS client connection types. */ +enum CRAS_CONNECTION_TYPE { + CRAS_CONTROL, // For legacy client. + CRAS_PLAYBACK, // For playback client. + CRAS_CAPTURE, // For capture client. + CRAS_NUM_CONN_TYPE, +}; + +static inline bool +cras_validate_connection_type(enum CRAS_CONNECTION_TYPE conn_type) +{ + return 0 <= conn_type && conn_type < CRAS_NUM_CONN_TYPE; +} + /* Directions of audio streams. * Input, Output, or loopback. * @@ -59,6 +73,24 @@ enum CRAS_STREAM_DIRECTION { CRAS_NUM_DIRECTIONS }; +/* Bitmask for supporting all CRAS_STREAM_DIRECTION. */ +#define CRAS_STREAM_ALL_DIRECTION ((1 << CRAS_NUM_DIRECTIONS) - 1) + +/* Converts CRAS_STREAM_DIRECTION to bitmask. + * Args: + * dir - An enum CRAS_STREAM_DIRECTION. + * + * Returns: + * bitmask for the given direction on success, negative on failure. + */ +static inline int +cras_stream_direction_mask(const enum CRAS_STREAM_DIRECTION dir) +{ + if (0 <= dir && dir < CRAS_NUM_DIRECTIONS) + return (1 << dir); + return -EINVAL; +} + /* * Flags for stream types. * BULK_AUDIO_OK - This stream is OK with receiving up to a full shm of samples @@ -120,12 +152,27 @@ enum CRAS_STREAM_TYPE { CRAS_STREAM_NUM_TYPES, }; -#define ENUM_STR(x) case x: return #x; +/* Types of audio clients. */ +enum CRAS_CLIENT_TYPE { + CRAS_CLIENT_TYPE_UNKNOWN, /* Unknown client */ + CRAS_CLIENT_TYPE_LEGACY, /* A client with old craslib (CRAS_PROTO_VER = 3) */ + CRAS_CLIENT_TYPE_TEST, /* cras_test_client */ + CRAS_CLIENT_TYPE_PCM, /* A client using CRAS via pcm, like aplay */ + CRAS_CLIENT_TYPE_CHROME, /* Chrome, UI */ + CRAS_CLIENT_TYPE_ARC, /* ARC++ */ + CRAS_CLIENT_TYPE_CROSVM, /* CROSVM */ + CRAS_CLIENT_TYPE_SERVER_STREAM, /* Server stream */ +}; + +#define ENUM_STR(x) \ + case x: \ + return #x; -static inline const char *cras_stream_type_str( - enum CRAS_STREAM_TYPE stream_type) +static inline const char * +cras_stream_type_str(enum CRAS_STREAM_TYPE stream_type) { - switch(stream_type) { + // clang-format off + switch (stream_type) { ENUM_STR(CRAS_STREAM_TYPE_DEFAULT) ENUM_STR(CRAS_STREAM_TYPE_MULTIMEDIA) ENUM_STR(CRAS_STREAM_TYPE_VOICE_COMMUNICATION) @@ -135,6 +182,26 @@ static inline const char *cras_stream_type_str( default: return "INVALID_STREAM_TYPE"; } + // clang-format on +} + +static inline const char * +cras_client_type_str(enum CRAS_CLIENT_TYPE client_type) +{ + // clang-format off + switch (client_type) { + ENUM_STR(CRAS_CLIENT_TYPE_UNKNOWN) + ENUM_STR(CRAS_CLIENT_TYPE_LEGACY) + ENUM_STR(CRAS_CLIENT_TYPE_TEST) + ENUM_STR(CRAS_CLIENT_TYPE_PCM) + ENUM_STR(CRAS_CLIENT_TYPE_CHROME) + ENUM_STR(CRAS_CLIENT_TYPE_ARC) + ENUM_STR(CRAS_CLIENT_TYPE_CROSVM) + ENUM_STR(CRAS_CLIENT_TYPE_SERVER_STREAM) + default: + return "INVALID_CLIENT_TYPE"; + } + // clang-format on } /* Effects that can be enabled for a CRAS stream. */ @@ -146,7 +213,7 @@ enum CRAS_STREAM_EFFECT { }; /* Information about a client attached to the server. */ -struct __attribute__ ((__packed__)) cras_attached_client_info { +struct __attribute__((__packed__)) cras_attached_client_info { uint32_t id; int32_t pid; uint32_t uid; @@ -166,22 +233,22 @@ static inline cras_node_id_t cras_make_node_id(uint32_t dev_index, static inline uint32_t dev_index_of(cras_node_id_t id) { - return (uint32_t) (id >> 32); + return (uint32_t)(id >> 32); } static inline uint32_t node_index_of(cras_node_id_t id) { - return (uint32_t) id; + return (uint32_t)id; } #define CRAS_MAX_IODEVS 20 #define CRAS_MAX_IONODES 20 #define CRAS_MAX_ATTACHED_CLIENTS 20 #define CRAS_MAX_AUDIO_THREAD_SNAPSHOTS 10 -#define CRAS_MAX_HOTWORD_MODEL_NAME_SIZE 8 +#define CRAS_MAX_HOTWORD_MODEL_NAME_SIZE 12 #define MAX_DEBUG_DEVS 4 #define MAX_DEBUG_STREAMS 8 -#define AUDIO_THREAD_EVENT_LOG_SIZE (1024*6) +#define AUDIO_THREAD_EVENT_LOG_SIZE (1024 * 6) #define CRAS_BT_EVENT_LOG_SIZE 1024 /* There are 8 bits of space for events. */ @@ -227,6 +294,8 @@ enum AUDIO_THREAD_LOG_EVENTS { AUDIO_THREAD_FILL_ODEV_ZEROS, AUDIO_THREAD_UNDERRUN, AUDIO_THREAD_SEVERE_UNDERRUN, + AUDIO_THREAD_CAPTURE_DROP_TIME, + AUDIO_THREAD_DEV_DROP_FRAMES, }; /* There are 8 bits of space for events. */ @@ -255,7 +324,7 @@ enum CRAS_BT_LOG_EVENTS { BT_TRANSPORT_RELEASE, }; -struct __attribute__ ((__packed__)) audio_thread_event { +struct __attribute__((__packed__)) audio_thread_event { uint32_t tag_sec; uint32_t nsec; uint32_t data1; @@ -264,13 +333,14 @@ struct __attribute__ ((__packed__)) audio_thread_event { }; /* Ring buffer of log events from the audio thread. */ -struct __attribute__ ((__packed__)) audio_thread_event_log { - uint32_t write_pos; +struct __attribute__((__packed__)) audio_thread_event_log { + uint64_t write_pos; + uint64_t sync_write_pos; uint32_t len; struct audio_thread_event log[AUDIO_THREAD_EVENT_LOG_SIZE]; }; -struct __attribute__ ((__packed__)) audio_dev_debug_info { +struct __attribute__((__packed__)) audio_dev_debug_info { char dev_name[CRAS_NODE_NAME_BUFFER_SIZE]; uint32_t buffer_size; uint32_t min_buffer_level; @@ -285,14 +355,17 @@ struct __attribute__ ((__packed__)) audio_dev_debug_info { uint32_t highest_hw_level; uint32_t runtime_sec; uint32_t runtime_nsec; + uint32_t longest_wake_sec; + uint32_t longest_wake_nsec; double software_gain_scaler; }; -struct __attribute__ ((__packed__)) audio_stream_debug_info { +struct __attribute__((__packed__)) audio_stream_debug_info { uint64_t stream_id; uint32_t dev_idx; uint32_t direction; uint32_t stream_type; + uint32_t client_type; uint32_t buffer_frames; uint32_t cb_threshold; uint64_t effects; @@ -312,7 +385,7 @@ struct __attribute__ ((__packed__)) audio_stream_debug_info { }; /* Debug info shared from server to client. */ -struct __attribute__ ((__packed__)) audio_debug_info { +struct __attribute__((__packed__)) audio_debug_info { uint32_t num_streams; uint32_t num_devs; struct audio_dev_debug_info devs[MAX_DEBUG_DEVS]; @@ -320,20 +393,20 @@ struct __attribute__ ((__packed__)) audio_debug_info { struct audio_thread_event_log log; }; -struct __attribute__ ((__packed__)) cras_bt_event { +struct __attribute__((__packed__)) cras_bt_event { uint32_t tag_sec; uint32_t nsec; uint32_t data1; uint32_t data2; }; -struct __attribute__ ((__packed__)) cras_bt_event_log { +struct __attribute__((__packed__)) cras_bt_event_log { uint32_t write_pos; uint32_t len; struct cras_bt_event log[CRAS_BT_EVENT_LOG_SIZE]; }; -struct __attribute__ ((__packed__)) cras_bt_debug_info { +struct __attribute__((__packed__)) cras_bt_debug_info { struct cras_bt_event_log bt_log; }; @@ -346,13 +419,14 @@ enum CRAS_AUDIO_THREAD_EVENT_TYPE { AUDIO_THREAD_EVENT_DEBUG, AUDIO_THREAD_EVENT_SEVERE_UNDERRUN, AUDIO_THREAD_EVENT_UNDERRUN, + AUDIO_THREAD_EVENT_DROP_SAMPLES, AUDIO_THREAD_EVENT_TYPE_COUNT, }; /* * Structure of snapshot for audio thread. */ -struct __attribute__ ((__packed__)) cras_audio_thread_snapshot { +struct __attribute__((__packed__)) cras_audio_thread_snapshot { struct timespec timestamp; enum CRAS_AUDIO_THREAD_EVENT_TYPE event_type; struct audio_debug_info audio_debug_info; @@ -361,9 +435,9 @@ struct __attribute__ ((__packed__)) cras_audio_thread_snapshot { /* * Ring buffer for storing snapshots. */ -struct __attribute__ ((__packed__)) cras_audio_thread_snapshot_buffer{ - struct cras_audio_thread_snapshot snapshots[ - CRAS_MAX_AUDIO_THREAD_SNAPSHOTS]; +struct __attribute__((__packed__)) cras_audio_thread_snapshot_buffer { + struct cras_audio_thread_snapshot + snapshots[CRAS_MAX_AUDIO_THREAD_SNAPSHOTS]; int pos; }; @@ -418,7 +492,7 @@ struct __attribute__ ((__packed__)) cras_audio_thread_snapshot_buffer{ * bt_wbs_enabled - Whether or not bluetooth wideband speech is enabled. */ #define CRAS_SERVER_STATE_VERSION 2 -struct __attribute__ ((packed, aligned(4))) cras_server_state { +struct __attribute__((packed, aligned(4))) cras_server_state { uint32_t state_version; uint32_t volume; int32_t min_volume_dBFS; @@ -451,15 +525,16 @@ struct __attribute__ ((packed, aligned(4))) cras_server_state { int32_t default_output_buffer_size; int32_t non_empty_status; int32_t aec_supported; - int32_t aec_group_id; + int32_t aec_group_id; struct cras_audio_thread_snapshot_buffer snapshot_buffer; struct cras_bt_debug_info bt_debug_info; int32_t bt_wbs_enabled; }; /* Actions for card add/remove/change. */ -enum cras_notify_device_action { /* Must match gavd action definitions. */ - CRAS_DEVICE_ACTION_ADD = 0, +enum cras_notify_device_action { + /* Must match gavd action definitions. */ + CRAS_DEVICE_ACTION_ADD = 0, CRAS_DEVICE_ACTION_REMOVE = 1, CRAS_DEVICE_ACTION_CHANGE = 2, }; @@ -481,7 +556,7 @@ enum CRAS_ALSA_CARD_TYPE { ALSA_CARD_TYPE_USB, }; #define USB_SERIAL_NUMBER_BUFFER_SIZE 64 -struct __attribute__ ((__packed__)) cras_alsa_card_info { +struct __attribute__((__packed__)) cras_alsa_card_info { enum CRAS_ALSA_CARD_TYPE card_type; uint32_t card_index; uint32_t usb_vendor_id; @@ -501,6 +576,12 @@ static inline cras_stream_id_t cras_get_stream_id(uint16_t client_id, return (cras_stream_id_t)(((client_id & 0x0000ffff) << 16) | (stream_id & 0x0000ffff)); } +/* Verify if the stream_id fits the given client_id */ +static inline bool cras_valid_stream_id(cras_stream_id_t stream_id, + uint16_t client_id) +{ + return ((stream_id >> 16) ^ client_id) == 0; +} enum CRAS_NODE_TYPE { /* These value can be used for output nodes. */ @@ -517,6 +598,8 @@ enum CRAS_NODE_TYPE { /* These value can be used for both output and input nodes. */ CRAS_NODE_TYPE_USB, CRAS_NODE_TYPE_BLUETOOTH, + CRAS_NODE_TYPE_FALLBACK_NORMAL, + CRAS_NODE_TYPE_FALLBACK_ABNORMAL, CRAS_NODE_TYPE_UNKNOWN, }; diff --git a/cras/src/common/cras_util.c b/cras/src/common/cras_util.c index bcc513ed..28570bf9 100644 --- a/cras/src/common/cras_util.c +++ b/cras/src/common/cras_util.c @@ -30,7 +30,7 @@ int cras_set_rt_scheduling(int rt_lim) if (setrlimit(RLIMIT_RTPRIO, &rl) < 0) { syslog(LOG_WARNING, "setrlimit %u failed: %d\n", - (unsigned) rt_lim, errno); + (unsigned)rt_lim, errno); return -EACCES; } return 0; @@ -48,7 +48,8 @@ int cras_set_thread_priority(int priority) if (err) syslog(LOG_WARNING, "Failed to set thread sched params to priority %d" - ", rc: %d\n", priority, err); + ", rc: %d\n", + priority, err); return err; } @@ -64,8 +65,8 @@ int cras_set_nice_level(int nice) */ rc = setpriority(PRIO_PROCESS, syscall(__NR_gettid), nice); if (rc) - syslog(LOG_WARNING, "Failed to set nice to %d, rc: %d", - nice, rc); + syslog(LOG_WARNING, "Failed to set nice to %d, rc: %d", nice, + rc); return rc; } @@ -97,7 +98,7 @@ int cras_make_fd_blocking(int fd) int cras_send_with_fds(int sockfd, const void *buf, size_t len, int *fd, unsigned int num_fds) { - struct msghdr msg = {0}; + struct msghdr msg = { 0 }; struct iovec iov; struct cmsghdr *cmsg; char *control; @@ -121,6 +122,8 @@ int cras_send_with_fds(int sockfd, const void *buf, size_t len, int *fd, memcpy(CMSG_DATA(cmsg), fd, sizeof(*fd) * num_fds); rc = sendmsg(sockfd, &msg, 0); + if (rc == -1) + rc = -errno; free(control); return rc; } @@ -128,7 +131,7 @@ int cras_send_with_fds(int sockfd, const void *buf, size_t len, int *fd, int cras_recv_with_fds(int sockfd, void *buf, size_t len, int *fd, unsigned int *num_fds) { - struct msghdr msg = {0}; + struct msghdr msg = { 0 }; struct iovec iov; struct cmsghdr *cmsg; char *control; @@ -156,15 +159,17 @@ int cras_recv_with_fds(int sockfd, void *buf, size_t len, int *fd, for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) { - if (cmsg->cmsg_level == SOL_SOCKET - && cmsg->cmsg_type == SCM_RIGHTS) { + if (cmsg->cmsg_level == SOL_SOCKET && + cmsg->cmsg_type == SCM_RIGHTS) { size_t fd_size = cmsg->cmsg_len - sizeof(*cmsg); *num_fds = MIN(*num_fds, fd_size / sizeof(*fd)); memcpy(fd, CMSG_DATA(cmsg), *num_fds * sizeof(*fd)); - break; + goto exit; } } + // If we reach here, we did not find any file descriptors. + *num_fds = 0; exit: free(control); return rc; @@ -199,8 +204,7 @@ int cras_poll(struct pollfd *fds, nfds_t nfds, struct timespec *timeout, rc = ppoll(fds, nfds, timeout, sigmask); if (rc == 0 && timeout) { rc = -ETIMEDOUT; - } - else if (rc < 0) { + } else if (rc < 0) { rc = -errno; } @@ -229,12 +233,12 @@ int wait_for_dev_input_access() unsigned i = 0; while (i < max_iterations) { - int readable; - struct timeval timeout; - const char * const pathname = "/dev/input/event0"; + int readable; + struct timeval timeout; + const char *const pathname = "/dev/input/event0"; - timeout.tv_sec = 0; - timeout.tv_usec = 500000; /* 1/2 second. */ + timeout.tv_sec = 0; + timeout.tv_usec = 500000; /* 1/2 second. */ readable = access(pathname, R_OK); /* If the file could be opened, then the udev rule has been diff --git a/cras/src/common/cras_util.h b/cras/src/common/cras_util.h index 46435a15..01034242 100644 --- a/cras/src/common/cras_util.h +++ b/cras/src/common/cras_util.h @@ -15,11 +15,11 @@ extern "C" { #include "cras_types.h" -#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) +#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) #define assert_on_compile(e) ((void)sizeof(char[1 - 2 * !(e)])) -#define assert_on_compile_is_power_of_2(n) \ - assert_on_compile((n) != 0 && (((n) & ((n) - 1)) == 0)) +#define assert_on_compile_is_power_of_2(n) \ + assert_on_compile((n) != 0 && (((n) & ((n)-1)) == 0)) /* Enables real time scheduling. */ int cras_set_rt_scheduling(int rt_lim); @@ -36,8 +36,7 @@ static inline size_t cras_frames_at_rate(size_t orig_rate, size_t orig_frames, } /* Converts a number of frames to a time in a timespec. */ -static inline void cras_frames_to_time(unsigned int frames, - unsigned int rate, +static inline void cras_frames_to_time(unsigned int frames, unsigned int rate, struct timespec *t) { t->tv_sec = frames / rate; @@ -46,8 +45,7 @@ static inline void cras_frames_to_time(unsigned int frames, } /* Converts a number of frames to a time in a timespec. */ -static inline void cras_frames_to_time_precise(unsigned int frames, - double rate, +static inline void cras_frames_to_time_precise(unsigned int frames, double rate, struct timespec *t) { double seconds = frames / rate; @@ -103,8 +101,7 @@ static inline void subtract_timespecs(const struct timespec *end, } } -static inline void add_timespecs(struct timespec *a, - const struct timespec *b) +static inline void add_timespecs(struct timespec *a, const struct timespec *b) { a->tv_sec += b->tv_sec; a->tv_nsec += b->tv_nsec; @@ -139,7 +136,7 @@ static inline int timeval_after(const struct timeval *a, const struct timeval *b) { return (a->tv_sec > b->tv_sec) || - (a->tv_sec == b->tv_sec && a->tv_usec > b->tv_usec); + (a->tv_sec == b->tv_sec && a->tv_usec > b->tv_usec); } /* Returns true if timespec a is after timespec b */ @@ -147,7 +144,7 @@ static inline int timespec_after(const struct timespec *a, const struct timespec *b) { return (a->tv_sec > b->tv_sec) || - (a->tv_sec == b->tv_sec && a->tv_nsec > b->tv_nsec); + (a->tv_sec == b->tv_sec && a->tv_nsec > b->tv_nsec); } /* Retruns the equivalent number of milliseconds for a given timespec. @@ -164,10 +161,16 @@ static inline void ms_to_timespec(time_t milliseconds, struct timespec *ts) ts->tv_nsec = (milliseconds % 1000) * 1000000; } +/* Returns true if the given timespec is zero. */ +static inline int timespec_is_zero(const struct timespec *ts) +{ + return ts && ts->tv_sec == 0 && ts->tv_nsec == 0; +} + /* Returns non-zero if the given timespec is non-zero. */ -static inline int timespec_is_nonzero(const struct timespec *ts) { - return ts && (ts->tv_sec != 0 || - (ts->tv_sec == 0 && ts->tv_nsec != 0)); +static inline int timespec_is_nonzero(const struct timespec *ts) +{ + return ts && (ts->tv_sec != 0 || (ts->tv_sec == 0 && ts->tv_nsec != 0)); } /* Calculates frames since time beg. */ @@ -208,7 +211,7 @@ static inline uint64_t cras_frames_since_time(const struct timespec *beg, * Other negative error codes specified in the ppoll() man page. */ int cras_poll(struct pollfd *fds, nfds_t nfds, struct timespec *timeout, - const sigset_t *sigmask); + const sigset_t *sigmask); /* Wait for /dev/input/event* files to become accessible. * diff --git a/cras/src/common/dumper.h b/cras/src/common/dumper.h index 75175643..a6a32276 100644 --- a/cras/src/common/dumper.h +++ b/cras/src/common/dumper.h @@ -15,7 +15,7 @@ extern "C" { /* dumper is an interface to output some human-readable information */ struct dumper { void (*vprintf)(struct dumper *dumper, const char *format, va_list ap); - void *data; /* private to each dumper */ + void *data; /* private to each dumper */ }; /* a convenience function outputs to a dumper */ diff --git a/cras/src/common/edid_utils.c b/cras/src/common/edid_utils.c index 2707b556..d9361f08 100644 --- a/cras/src/common/edid_utils.c +++ b/cras/src/common/edid_utils.c @@ -9,8 +9,8 @@ #include "edid_utils.h" /* Dump out an EDID block in a simple format */ -void show_edid_data(FILE *outfile, unsigned char *edid_data, - int items, int base) +void show_edid_data(FILE *outfile, unsigned char *edid_data, int items, + int base) { int item = 0; @@ -26,180 +26,133 @@ void show_edid_data(FILE *outfile, unsigned char *edid_data, } } - unsigned char test_edid1[256] = { - 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, - 0x06, 0xaf, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x12, 0x01, 0x03, 0x80, 0x1a, 0x0e, 0x78, - 0x0a, 0x99, 0x85, 0x95, 0x55, 0x56, 0x92, 0x28, - 0x22, 0x50, 0x54, 0x00, 0x00, 0x00, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x96, 0x19, - 0x56, 0x28, 0x50, 0x00, 0x08, 0x30, 0x18, 0x10, - 0x24, 0x00, 0x00, 0x90, 0x10, 0x00, 0x00, 0x18, - 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x20, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x41, - 0x55, 0x4f, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfe, - 0x00, 0x42, 0x31, 0x31, 0x36, 0x58, 0x57, 0x30, + 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x06, 0xaf, 0x5c, 0x20, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x12, 0x01, 0x03, 0x80, 0x1a, 0x0e, 0x78, + 0x0a, 0x99, 0x85, 0x95, 0x55, 0x56, 0x92, 0x28, 0x22, 0x50, 0x54, 0x00, + 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x96, 0x19, 0x56, 0x28, 0x50, 0x00, + 0x08, 0x30, 0x18, 0x10, 0x24, 0x00, 0x00, 0x90, 0x10, 0x00, 0x00, 0x18, + 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x41, + 0x55, 0x4f, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x00, 0x00, 0x00, 0xfe, 0x00, 0x42, 0x31, 0x31, 0x36, 0x58, 0x57, 0x30, 0x32, 0x20, 0x56, 0x30, 0x20, 0x0a, 0x00, 0xf8 }; unsigned char test_edid2[256] = { - 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, - 0x30, 0xe4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x14, 0x01, 0x03, 0x80, 0x1a, 0x0e, 0x78, - 0x0a, 0xbf, 0x45, 0x95, 0x58, 0x52, 0x8a, 0x28, - 0x25, 0x50, 0x54, 0x00, 0x00, 0x00, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x84, 0x1c, - 0x56, 0xa8, 0x50, 0x00, 0x19, 0x30, 0x30, 0x20, - 0x35, 0x00, 0x00, 0x90, 0x10, 0x00, 0x00, 0x1b, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x4c, - 0x47, 0x20, 0x44, 0x69, 0x73, 0x70, 0x6c, 0x61, - 0x79, 0x0a, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfc, - 0x00, 0x4c, 0x50, 0x31, 0x31, 0x36, 0x57, 0x48, + 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x30, 0xe4, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x01, 0x03, 0x80, 0x1a, 0x0e, 0x78, + 0x0a, 0xbf, 0x45, 0x95, 0x58, 0x52, 0x8a, 0x28, 0x25, 0x50, 0x54, 0x00, + 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x84, 0x1c, 0x56, 0xa8, 0x50, 0x00, + 0x19, 0x30, 0x30, 0x20, 0x35, 0x00, 0x00, 0x90, 0x10, 0x00, 0x00, 0x1b, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x4c, + 0x47, 0x20, 0x44, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x0a, 0x20, 0x20, + 0x00, 0x00, 0x00, 0xfc, 0x00, 0x4c, 0x50, 0x31, 0x31, 0x36, 0x57, 0x48, 0x31, 0x2d, 0x54, 0x4c, 0x4e, 0x31, 0x00, 0x4e }; unsigned char test_edid3[256] = { - 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, - 0x4d, 0xd9, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x11, 0x01, 0x03, 0x80, 0x00, 0x00, 0x78, - 0x0a, 0x0d, 0xc9, 0xa0, 0x57, 0x47, 0x98, 0x27, - 0x12, 0x48, 0x4c, 0x00, 0x00, 0x00, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1d, - 0x80, 0xd0, 0x72, 0x1c, 0x16, 0x20, 0x10, 0x2c, - 0x25, 0x80, 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x9e, - 0x01, 0x1d, 0x80, 0x18, 0x71, 0x1c, 0x16, 0x20, - 0x58, 0x2c, 0x25, 0x00, 0xc4, 0x8e, 0x21, 0x00, - 0x00, 0x9e, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x48, - 0x44, 0x4d, 0x49, 0x20, 0x4c, 0x4c, 0x43, 0x0a, - 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfd, - 0x00, 0x3b, 0x3d, 0x0f, 0x2d, 0x08, 0x00, 0x0a, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0xc0, - 0x02, 0x03, 0x1e, 0x47, 0x4f, 0x94, 0x13, 0x05, - 0x03, 0x04, 0x02, 0x01, 0x16, 0x15, 0x07, 0x06, - 0x11, 0x10, 0x12, 0x1f, 0x23, 0x09, 0x07, 0x01, - 0x65, 0x03, 0x0c, 0x00, 0x10, 0x00, 0x8c, 0x0a, - 0xd0, 0x90, 0x20, 0x40, 0x31, 0x20, 0x0c, 0x40, - 0x55, 0x00, 0x13, 0x8e, 0x21, 0x00, 0x00, 0x18, - 0x01, 0x1d, 0x00, 0xbc, 0x52, 0xd0, 0x1e, 0x20, - 0xb8, 0x28, 0x55, 0x40, 0xc4, 0x8e, 0x21, 0x00, - 0x00, 0x1e, 0x8c, 0x0a, 0xd0, 0x8a, 0x20, 0xe0, - 0x2d, 0x10, 0x10, 0x3e, 0x96, 0x00, 0xc4, 0x8e, - 0x21, 0x00, 0x00, 0x18, 0x01, 0x1d, 0x00, 0x72, - 0x51, 0xd0, 0x1e, 0x20, 0x6e, 0x28, 0x55, 0x00, - 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x1e, 0x8c, 0x0a, - 0xd0, 0x8a, 0x20, 0xe0, 0x2d, 0x10, 0x10, 0x3e, - 0x96, 0x00, 0x13, 0x8e, 0x21, 0x00, 0x00, 0x18, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb + 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x4d, 0xd9, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x01, 0x03, 0x80, 0x00, 0x00, 0x78, + 0x0a, 0x0d, 0xc9, 0xa0, 0x57, 0x47, 0x98, 0x27, 0x12, 0x48, 0x4c, 0x00, + 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1d, 0x80, 0xd0, 0x72, 0x1c, + 0x16, 0x20, 0x10, 0x2c, 0x25, 0x80, 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x9e, + 0x01, 0x1d, 0x80, 0x18, 0x71, 0x1c, 0x16, 0x20, 0x58, 0x2c, 0x25, 0x00, + 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x9e, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x48, + 0x44, 0x4d, 0x49, 0x20, 0x4c, 0x4c, 0x43, 0x0a, 0x20, 0x20, 0x20, 0x20, + 0x00, 0x00, 0x00, 0xfd, 0x00, 0x3b, 0x3d, 0x0f, 0x2d, 0x08, 0x00, 0x0a, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0xc0, 0x02, 0x03, 0x1e, 0x47, + 0x4f, 0x94, 0x13, 0x05, 0x03, 0x04, 0x02, 0x01, 0x16, 0x15, 0x07, 0x06, + 0x11, 0x10, 0x12, 0x1f, 0x23, 0x09, 0x07, 0x01, 0x65, 0x03, 0x0c, 0x00, + 0x10, 0x00, 0x8c, 0x0a, 0xd0, 0x90, 0x20, 0x40, 0x31, 0x20, 0x0c, 0x40, + 0x55, 0x00, 0x13, 0x8e, 0x21, 0x00, 0x00, 0x18, 0x01, 0x1d, 0x00, 0xbc, + 0x52, 0xd0, 0x1e, 0x20, 0xb8, 0x28, 0x55, 0x40, 0xc4, 0x8e, 0x21, 0x00, + 0x00, 0x1e, 0x8c, 0x0a, 0xd0, 0x8a, 0x20, 0xe0, 0x2d, 0x10, 0x10, 0x3e, + 0x96, 0x00, 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x18, 0x01, 0x1d, 0x00, 0x72, + 0x51, 0xd0, 0x1e, 0x20, 0x6e, 0x28, 0x55, 0x00, 0xc4, 0x8e, 0x21, 0x00, + 0x00, 0x1e, 0x8c, 0x0a, 0xd0, 0x8a, 0x20, 0xe0, 0x2d, 0x10, 0x10, 0x3e, + 0x96, 0x00, 0x13, 0x8e, 0x21, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xfb }; unsigned char test_edid4[256] = { - 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, - 0x4c, 0x2d, 0x10, 0x02, 0x00, 0x00, 0x00, 0x00, - 0x31, 0x0f, 0x01, 0x03, 0x80, 0x10, 0x09, 0x8c, - 0x0a, 0xe2, 0xbd, 0xa1, 0x5b, 0x4a, 0x98, 0x24, - 0x15, 0x47, 0x4a, 0x20, 0x00, 0x00, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1d, - 0x00, 0x72, 0x51, 0xd0, 0x1e, 0x20, 0x6e, 0x28, - 0x55, 0x00, 0xa0, 0x5a, 0x00, 0x00, 0x00, 0x1e, - 0x01, 0x1d, 0x80, 0x18, 0x71, 0x1c, 0x16, 0x20, - 0x58, 0x2c, 0x25, 0x00, 0xa0, 0x5a, 0x00, 0x00, - 0x00, 0x9e, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x3b, - 0x3d, 0x1e, 0x2e, 0x08, 0x00, 0x0a, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfc, - 0x00, 0x53, 0x41, 0x4d, 0x53, 0x55, 0x4e, 0x47, - 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0x8d, - 0x02, 0x03, 0x16, 0x71, 0x43, 0x84, 0x05, 0x03, - 0x23, 0x09, 0x07, 0x07, 0x83, 0x01, 0x00, 0x00, - 0x65, 0x03, 0x0c, 0x00, 0x20, 0x00, 0x8c, 0x0a, - 0xd0, 0x8a, 0x20, 0xe0, 0x2d, 0x10, 0x10, 0x3e, - 0x96, 0x00, 0xa0, 0x5a, 0x00, 0x00, 0x00, 0x18, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30 + 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x4c, 0x2d, 0x10, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x31, 0x0f, 0x01, 0x03, 0x80, 0x10, 0x09, 0x8c, + 0x0a, 0xe2, 0xbd, 0xa1, 0x5b, 0x4a, 0x98, 0x24, 0x15, 0x47, 0x4a, 0x20, + 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1d, 0x00, 0x72, 0x51, 0xd0, + 0x1e, 0x20, 0x6e, 0x28, 0x55, 0x00, 0xa0, 0x5a, 0x00, 0x00, 0x00, 0x1e, + 0x01, 0x1d, 0x80, 0x18, 0x71, 0x1c, 0x16, 0x20, 0x58, 0x2c, 0x25, 0x00, + 0xa0, 0x5a, 0x00, 0x00, 0x00, 0x9e, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x3b, + 0x3d, 0x1e, 0x2e, 0x08, 0x00, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x00, 0x00, 0x00, 0xfc, 0x00, 0x53, 0x41, 0x4d, 0x53, 0x55, 0x4e, 0x47, + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0x8d, 0x02, 0x03, 0x16, 0x71, + 0x43, 0x84, 0x05, 0x03, 0x23, 0x09, 0x07, 0x07, 0x83, 0x01, 0x00, 0x00, + 0x65, 0x03, 0x0c, 0x00, 0x20, 0x00, 0x8c, 0x0a, 0xd0, 0x8a, 0x20, 0xe0, + 0x2d, 0x10, 0x10, 0x3e, 0x96, 0x00, 0xa0, 0x5a, 0x00, 0x00, 0x00, 0x18, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x30 }; unsigned char test_edid5[256] = { - 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, - 0x3d, 0xcb, 0x61, 0x07, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x11, 0x01, 0x03, 0x80, 0x00, 0x00, 0x78, - 0x0a, 0x0d, 0xc9, 0xa0, 0x57, 0x47, 0x98, 0x27, - 0x12, 0x48, 0x4c, 0x00, 0x00, 0x00, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1d, - 0x80, 0x18, 0x71, 0x1c, 0x16, 0x20, 0x58, 0x2c, - 0x25, 0x00, 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x9e, - 0x01, 0x1d, 0x80, 0xd0, 0x72, 0x1c, 0x16, 0x20, - 0x10, 0x2c, 0x25, 0x80, 0xc4, 0x8e, 0x21, 0x00, - 0x00, 0x9e, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x54, - 0x58, 0x2d, 0x53, 0x52, 0x36, 0x30, 0x35, 0x0a, - 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfd, - 0x00, 0x17, 0xf0, 0x0f, 0x7e, 0x11, 0x00, 0x0a, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0x93, - 0x02, 0x03, 0x3b, 0x72, 0x55, 0x85, 0x04, 0x03, - 0x02, 0x0e, 0x0f, 0x07, 0x23, 0x24, 0x10, 0x94, - 0x13, 0x12, 0x11, 0x1d, 0x1e, 0x16, 0x25, 0x26, - 0x01, 0x1f, 0x35, 0x09, 0x7f, 0x07, 0x0f, 0x7f, - 0x07, 0x17, 0x07, 0x50, 0x3f, 0x06, 0xc0, 0x57, - 0x06, 0x00, 0x5f, 0x7e, 0x01, 0x67, 0x5e, 0x00, - 0x83, 0x4f, 0x00, 0x00, 0x66, 0x03, 0x0c, 0x00, - 0x20, 0x00, 0x80, 0x8c, 0x0a, 0xd0, 0x8a, 0x20, - 0xe0, 0x2d, 0x10, 0x10, 0x3e, 0x96, 0x00, 0xc4, - 0x8e, 0x21, 0x00, 0x00, 0x18, 0x8c, 0x0a, 0xd0, - 0x90, 0x20, 0x40, 0x31, 0x20, 0x0c, 0x40, 0x55, - 0x00, 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x18, 0x01, - 0x1d, 0x00, 0x72, 0x51, 0xd0, 0x1e, 0x20, 0x6e, - 0x28, 0x55, 0x00, 0xc4, 0x8e, 0x21, 0x00, 0x00, - 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdd + 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x3d, 0xcb, 0x61, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x01, 0x03, 0x80, 0x00, 0x00, 0x78, + 0x0a, 0x0d, 0xc9, 0xa0, 0x57, 0x47, 0x98, 0x27, 0x12, 0x48, 0x4c, 0x00, + 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1d, 0x80, 0x18, 0x71, 0x1c, + 0x16, 0x20, 0x58, 0x2c, 0x25, 0x00, 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x9e, + 0x01, 0x1d, 0x80, 0xd0, 0x72, 0x1c, 0x16, 0x20, 0x10, 0x2c, 0x25, 0x80, + 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x9e, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x54, + 0x58, 0x2d, 0x53, 0x52, 0x36, 0x30, 0x35, 0x0a, 0x20, 0x20, 0x20, 0x20, + 0x00, 0x00, 0x00, 0xfd, 0x00, 0x17, 0xf0, 0x0f, 0x7e, 0x11, 0x00, 0x0a, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0x93, 0x02, 0x03, 0x3b, 0x72, + 0x55, 0x85, 0x04, 0x03, 0x02, 0x0e, 0x0f, 0x07, 0x23, 0x24, 0x10, 0x94, + 0x13, 0x12, 0x11, 0x1d, 0x1e, 0x16, 0x25, 0x26, 0x01, 0x1f, 0x35, 0x09, + 0x7f, 0x07, 0x0f, 0x7f, 0x07, 0x17, 0x07, 0x50, 0x3f, 0x06, 0xc0, 0x57, + 0x06, 0x00, 0x5f, 0x7e, 0x01, 0x67, 0x5e, 0x00, 0x83, 0x4f, 0x00, 0x00, + 0x66, 0x03, 0x0c, 0x00, 0x20, 0x00, 0x80, 0x8c, 0x0a, 0xd0, 0x8a, 0x20, + 0xe0, 0x2d, 0x10, 0x10, 0x3e, 0x96, 0x00, 0xc4, 0x8e, 0x21, 0x00, 0x00, + 0x18, 0x8c, 0x0a, 0xd0, 0x90, 0x20, 0x40, 0x31, 0x20, 0x0c, 0x40, 0x55, + 0x00, 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x18, 0x01, 0x1d, 0x00, 0x72, 0x51, + 0xd0, 0x1e, 0x20, 0x6e, 0x28, 0x55, 0x00, 0xc4, 0x8e, 0x21, 0x00, 0x00, + 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xdd }; /* Has DTD that is too wide */ unsigned char test_edid6[256] = { - 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, - 0x10, 0xac, 0x63, 0x40, 0x4c, 0x35, 0x31, 0x33, - 0x0c, 0x15, 0x01, 0x03, 0x80, 0x40, 0x28, 0x78, - 0xea, 0x8d, 0x85, 0xad, 0x4f, 0x35, 0xb1, 0x25, - 0x0e, 0x50, 0x54, 0xa5, 0x4b, 0x00, 0x71, 0x4f, - 0x81, 0x00, 0x81, 0x80, 0xa9, 0x40, 0xd1, 0x00, - 0xd1, 0x40, 0x01, 0x01, 0x01, 0x01, 0xe2, 0x68, - 0x00, 0xa0, 0xa0, 0x40, 0x2e, 0x60, 0x30, 0x20, - 0x36, 0x00, 0x81, 0x91, 0x21, 0x00, 0x00, 0x1a, - 0x00, 0x00, 0x00, 0xff, 0x00, 0x50, 0x48, 0x35, - 0x4e, 0x59, 0x31, 0x33, 0x4d, 0x33, 0x31, 0x35, - 0x4c, 0x0a, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x44, - 0x45, 0x4c, 0x4c, 0x20, 0x55, 0x33, 0x30, 0x31, - 0x31, 0x0a, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfd, - 0x00, 0x31, 0x56, 0x1d, 0x71, 0x1c, 0x00, 0x0a, + 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x10, 0xac, 0x63, 0x40, + 0x4c, 0x35, 0x31, 0x33, 0x0c, 0x15, 0x01, 0x03, 0x80, 0x40, 0x28, 0x78, + 0xea, 0x8d, 0x85, 0xad, 0x4f, 0x35, 0xb1, 0x25, 0x0e, 0x50, 0x54, 0xa5, + 0x4b, 0x00, 0x71, 0x4f, 0x81, 0x00, 0x81, 0x80, 0xa9, 0x40, 0xd1, 0x00, + 0xd1, 0x40, 0x01, 0x01, 0x01, 0x01, 0xe2, 0x68, 0x00, 0xa0, 0xa0, 0x40, + 0x2e, 0x60, 0x30, 0x20, 0x36, 0x00, 0x81, 0x91, 0x21, 0x00, 0x00, 0x1a, + 0x00, 0x00, 0x00, 0xff, 0x00, 0x50, 0x48, 0x35, 0x4e, 0x59, 0x31, 0x33, + 0x4d, 0x33, 0x31, 0x35, 0x4c, 0x0a, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x44, + 0x45, 0x4c, 0x4c, 0x20, 0x55, 0x33, 0x30, 0x31, 0x31, 0x0a, 0x20, 0x20, + 0x00, 0x00, 0x00, 0xfd, 0x00, 0x31, 0x56, 0x1d, 0x71, 0x1c, 0x00, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0xb0 }; -static unsigned char *test_edids[N_TEST_EDIDS] = { - test_edid1, test_edid2, test_edid3, test_edid4, test_edid5, - test_edid6 -}; +static unsigned char *test_edids[N_TEST_EDIDS] = { test_edid1, test_edid2, + test_edid3, test_edid4, + test_edid5, test_edid6 }; int get_test_edid(int n, unsigned char *dst) { if ((n < 1) || (n > N_TEST_EDIDS)) return -1; - memcpy(dst, test_edids[n-1], 256); + memcpy(dst, test_edids[n - 1], 256); return 0; } @@ -208,7 +161,7 @@ int show_test_edid(FILE *outfile, int n) if ((n < 1) || (n > N_TEST_EDIDS)) return -1; fprintf(outfile, "Test EDID %d\n", n); - show_edid(outfile, test_edids[n-1], 1); + show_edid(outfile, test_edids[n - 1], 1); return 0; } @@ -227,20 +180,20 @@ static void get_dtd_string(const char *str, char *buf, int buf_size) /* Print an edid descriptor block (standard case is at 54 + 18 * i) */ void show_edid_dtd(FILE *outfile, unsigned char *base) { - int pelclk = base[DTD_PCLK_LO] + (base[DTD_PCLK_HI]<<8); + int pelclk = base[DTD_PCLK_LO] + (base[DTD_PCLK_HI] << 8); char monstr[DTD_SIZE]; if (pelclk != 0) { - int hres = base[DTD_HA_LO] + ((base[DTD_HABL_HI] & 0xf0)<<4); - int hbl = base[DTD_HBL_LO] + ((base[DTD_HABL_HI] & 0x0f)<<8); - int vres = base[DTD_VA_LO] + ((base[DTD_VABL_HI] & 0xf0)<<4); - int vbl = base[DTD_VBL_LO] + ((base[DTD_VABL_HI] & 0x0f)<<8); - int hso = base[DTD_HSO_LO] + ((base[DTD_HVSX_HI] & 0xc0)<<2); - int hsw = base[DTD_HSW_LO] + ((base[DTD_HVSX_HI] & 0x30)<<4); + int hres = base[DTD_HA_LO] + ((base[DTD_HABL_HI] & 0xf0) << 4); + int hbl = base[DTD_HBL_LO] + ((base[DTD_HABL_HI] & 0x0f) << 8); + int vres = base[DTD_VA_LO] + ((base[DTD_VABL_HI] & 0xf0) << 4); + int vbl = base[DTD_VBL_LO] + ((base[DTD_VABL_HI] & 0x0f) << 8); + int hso = base[DTD_HSO_LO] + ((base[DTD_HVSX_HI] & 0xc0) << 2); + int hsw = base[DTD_HSW_LO] + ((base[DTD_HVSX_HI] & 0x30) << 4); int vso = (base[DTD_VSX_LO] >> 4) + - ((base[DTD_HVSX_HI] & 0x0c) << 2); + ((base[DTD_HVSX_HI] & 0x0c) << 2); int vsw = (base[DTD_VSX_LO] & 0xf) + - ((base[DTD_HVSX_HI] & 0x03) << 4); + ((base[DTD_HVSX_HI] & 0x03) << 4); int hsiz = base[DTD_HSIZE_LO] + ((base[DTD_HVSIZE_HI] & 0xf0) << 4); int vsiz = base[DTD_VSIZE_LO] + @@ -249,23 +202,21 @@ void show_edid_dtd(FILE *outfile, unsigned char *base) int vbdr = base[DTD_VBORDER]; int mdflg = base[DTD_FLAGS]; - int refr = (pelclk * 10000)/((hres+hbl)*(vres+vbl)); - int refm = (pelclk * 10000)%((hres+hbl)*(vres+vbl)); - int refd = (refm*100)/((hres+hbl)*(vres+vbl)); + int refr = (pelclk * 10000) / ((hres + hbl) * (vres + vbl)); + int refm = (pelclk * 10000) % ((hres + hbl) * (vres + vbl)); + int refd = (refm * 100) / ((hres + hbl) * (vres + vbl)); fprintf(outfile, "%dx%d%c@%d.%02d, dot clock %d %cHsync %cVsync\n", - hres, vres, (mdflg & 0x80) ? 'i' : 'p', - refr, refd, - pelclk * 10000, - (mdflg & 0x2) ? '+' : '-', + hres, vres, (mdflg & 0x80) ? 'i' : 'p', refr, refd, + pelclk * 10000, (mdflg & 0x2) ? '+' : '-', (mdflg & 0x4) ? '+' : '-'); - fprintf(outfile, "H: start %d, end %d, total %d\n", - hres+hso, hres+hso+hsw, hres+hbl); - fprintf(outfile, "V: start %d, end %d, total %d\n", - vres+vso, vres+vso+vsw, vres+vbl); - fprintf(outfile, "Size %dx%dmm, Border %dx%d pixels\n", - hsiz, vsiz, hbdr, vbdr); + fprintf(outfile, "H: start %d, end %d, total %d\n", hres + hso, + hres + hso + hsw, hres + hbl); + fprintf(outfile, "V: start %d, end %d, total %d\n", vres + vso, + vres + vso + vsw, vres + vbl); + fprintf(outfile, "Size %dx%dmm, Border %dx%d pixels\n", hsiz, + vsiz, hbdr, vbdr); return; } @@ -273,40 +224,48 @@ void show_edid_dtd(FILE *outfile, unsigned char *base) case DTDTYPE_SERIAL: case DTDTYPE_STRING: case DTDTYPE_NAME: - get_dtd_string((const char *)base + DTD_STRING, - monstr, DTD_SIZE); + get_dtd_string((const char *)base + DTD_STRING, monstr, + DTD_SIZE); if (base[3] != DTDTYPE_STRING) fprintf(outfile, "%s: %s\n", - (base[3] == DTDTYPE_NAME) ? - "Name" : "Serial", + (base[3] == DTDTYPE_NAME) ? "Name" : "Serial", monstr); else fprintf(outfile, "%s\n", monstr); break; case DTDTYPE_LIMITS: - fprintf(outfile, - "V %d - %d Hz, H %d - %d kHz, Pel <= %d MHz\n", + fprintf(outfile, "V %d - %d Hz, H %d - %d kHz, Pel <= %d MHz\n", base[DTD_MINV_HZ], base[DTD_MAXV_HZ], base[DTD_MINH_kHZ], base[DTD_MAXH_kHZ], - base[DTD_MAXCLK_100kHZ]*10); + base[DTD_MAXCLK_100kHZ] * 10); break; default: - fprintf(outfile, - "Undecoded descriptor block type 0x%x\n", + fprintf(outfile, "Undecoded descriptor block type 0x%x\n", base[DTD_TYPETAG]); break; } } - char *sad_audio_type[16] = { - "Reserved", "LPCM", "AC-3", "MPEG1 (Layer 1 and 2)", - "MP3", "MPEG2", "AAC", "DTS", - "ATRAC", "SACD", "DD+", "DTS-HD", - "MLP/Dolby TrueHD", "DST Audio", "WMA Pro", "Reserved", + "Reserved", + "LPCM", + "AC-3", + "MPEG1 (Layer 1 and 2)", + "MP3", + "MPEG2", + "AAC", + "DTS", + "ATRAC", + "SACD", + "DD+", + "DTS-HD", + "MLP/Dolby TrueHD", + "DST Audio", + "WMA Pro", + "Reserved", }; char *uscanstr[4] = { @@ -316,16 +275,14 @@ char *uscanstr[4] = { "supports both over- and underscan", }; -static inline void show_audio_dbc(FILE *outfile, - const unsigned char *edid_ext, +static inline void show_audio_dbc(FILE *outfile, const unsigned char *edid_ext, int dbc) { int dbp = dbc + 1; - int db_len = edid_ext[dbc+DBC_TAG_LENGTH] & DBC_LEN_MASK; + int db_len = edid_ext[dbc + DBC_TAG_LENGTH] & DBC_LEN_MASK; while (dbp < (dbc + db_len + 1)) { - int atype = - (edid_ext[dbp + DBCA_FORMAT]>>3) & 0xf; + int atype = (edid_ext[dbp + DBCA_FORMAT] >> 3) & 0xf; unsigned char dbca_rate = edid_ext[dbp + DBCA_RATE]; fprintf(outfile, "Audio: %d channels %s: ", @@ -365,8 +322,7 @@ static inline void show_audio_dbc(FILE *outfile, } } -static inline void show_vendor_dbc(FILE *outfile, - const unsigned char *edid_ext, +static inline void show_vendor_dbc(FILE *outfile, const unsigned char *edid_ext, int dbp) { if ((edid_ext[dbp + DBCVND_IEEE_LO] != 0x03) || @@ -383,7 +339,7 @@ static inline void show_vendor_dbc(FILE *outfile, "HDMI Vendor block (CEC @0x%04x):\n" "Support: %s%s%s%s%s%s\n", edid_ext[dbp + DBCVHDMI_CEC_LO] + - (edid_ext[dbp + DBCVHDMI_CEC_HI] << 8), + (edid_ext[dbp + DBCVHDMI_CEC_HI] << 8), (edid_ext[dbp + DBCVHDMI_SUPPORT] & 0x80) ? "AI " : "", (edid_ext[dbp + DBCVHDMI_SUPPORT] & 0x40) ? "DC_48bit " : "", (edid_ext[dbp + DBCVHDMI_SUPPORT] & 0x20) ? "DC_36bit " : "", @@ -393,7 +349,7 @@ static inline void show_vendor_dbc(FILE *outfile, if (edid_ext[dbp + DBCVHDMI_MAXTMDS_5MHz] > 0) fprintf(outfile, "Max TMDS Frequency %dMHz\n", - edid_ext[dbp + DBCVHDMI_MAXTMDS_5MHz]*5); + edid_ext[dbp + DBCVHDMI_MAXTMDS_5MHz] * 5); if (edid_ext[dbp + DBCVHDMI_LATFLAGS] & 0x80) fprintf(outfile, "Video latency %dms, audio latency %dms\n", @@ -407,31 +363,27 @@ static inline void show_vendor_dbc(FILE *outfile, 2 * (edid_ext[dbp + DBCVHDMI_IALAT] - 1)); } -static void show_extended_dbc(FILE *outfile, - const unsigned char *edid_ext, +static void show_extended_dbc(FILE *outfile, const unsigned char *edid_ext, int dbc) { int dbp = dbc + 1; int db_len = edid_ext[dbc + DBC_TAG_LENGTH] & DBC_LEN_MASK; switch (edid_ext[dbp + DBC_ETAG]) { - case DBC_ETAG_VCDB: - { + case DBC_ETAG_VCDB: { unsigned char vcdb_flags; fprintf(outfile, "Video Capabilities:\n"); - fprintf(outfile, - " Quantization range selectable: %s\n", - (edid_ext[dbp + VCDB_FLAGS] & 0x40) ? - "unknown" : "via AVI Q"); + fprintf(outfile, " Quantization range selectable: %s\n", + (edid_ext[dbp + VCDB_FLAGS] & 0x40) ? "unknown" : + "via AVI Q"); /* PT field zero implies no data, just use IT * and CE fields */ vcdb_flags = edid_ext[dbp + VCDB_FLAGS]; if (VCDB_S_PT(vcdb_flags)) - fprintf(outfile, - " Preferred mode %s\n", + fprintf(outfile, " Preferred mode %s\n", uscanstr[VCDB_S_PT(vcdb_flags)]); fprintf(outfile, " IT modes %s\n", uscanstr[VCDB_S_IT(vcdb_flags)]); @@ -441,8 +393,7 @@ static void show_extended_dbc(FILE *outfile, } case DBC_ETAG_COL: - fprintf(outfile, - "Colorimetry supports %s%s metadata 0x%x\n", + fprintf(outfile, "Colorimetry supports %s%s metadata 0x%x\n", (edid_ext[dbp + COL_FLAGS] & 0x02) ? "HD(YCC709) " : "", (edid_ext[dbp + COL_FLAGS] & 0x01) ? "SD(YCC601) " : "", (edid_ext[dbp + COL_META] & 0x07)); @@ -467,7 +418,7 @@ void show_cea_timing(FILE *outfile, unsigned char *edid_ext) return; } /* Ends with 0 and a checksum, have at least one pad byte */ - n_dtd = (CEA_LAST_PAD - off_dtd)/DTD_SIZE; + n_dtd = (CEA_LAST_PAD - off_dtd) / DTD_SIZE; fprintf(outfile, "Block has DTDs starting at offset %d (%d bytes of DBCs)\n", off_dtd, off_dtd - CEA_DBC_START); @@ -490,7 +441,7 @@ void show_cea_timing(FILE *outfile, unsigned char *edid_ext) int db_len = edid_ext[dbc + DBC_TAG_LENGTH] & DBC_LEN_MASK; int dbp = dbc + 1; - switch (edid_ext[dbc+DBC_TAG_LENGTH] >> DBC_TAG_SHIFT) { + switch (edid_ext[dbc + DBC_TAG_LENGTH] >> DBC_TAG_SHIFT) { case DBC_TAG_AUDIO: /* Audio Data Block */ show_audio_dbc(outfile, edid_ext, dbc); @@ -502,7 +453,8 @@ void show_cea_timing(FILE *outfile, unsigned char *edid_ext) int vtype = edid_ext[dbp + DBCV_CODE] & 0x7f; fprintf(outfile, "Video: Code %d %s\n", vtype, (edid_ext[dbp + DBCV_CODE] & 0x80) ? - "(native)" : ""); + "(native)" : + ""); dbp += DBCV_SIZE; } break; @@ -512,8 +464,7 @@ void show_cea_timing(FILE *outfile, unsigned char *edid_ext) show_vendor_dbc(outfile, edid_ext, dbc + 1); break; - case DBC_TAG_SPEAKER: - { + case DBC_TAG_SPEAKER: { /* Speaker allocation Block */ unsigned char dbcsp_alloc = edid_ext[dbp + DBCSP_ALLOC]; @@ -535,7 +486,7 @@ void show_cea_timing(FILE *outfile, unsigned char *edid_ext) default: fprintf(outfile, "Unknown Data Block type tag 0x%x, len 0x%x\n", - edid_ext[dbc+DBC_TAG_LENGTH] >> DBC_TAG_SHIFT, + edid_ext[dbc + DBC_TAG_LENGTH] >> DBC_TAG_SHIFT, db_len); break; } @@ -546,15 +497,14 @@ void show_cea_timing(FILE *outfile, unsigned char *edid_ext) /* Find 0,0 when we hit padding */ if ((edid_ext[off_dtd + DTD_SIZE * i + DTD_PCLK_LO] == 0) && (edid_ext[off_dtd + DTD_SIZE * i + DTD_PCLK_HI] == 0)) { - fprintf(outfile, - "End of DTD padding after %d DTDs\n", i); + fprintf(outfile, "End of DTD padding after %d DTDs\n", + i); break; } show_edid_dtd(outfile, edid_ext + (off_dtd + DTD_SIZE * i)); } } - int edid_valid(const unsigned char *edid_data) { return ((edid_data[EDID_HDR + 0] == 0x00) && @@ -598,7 +548,8 @@ int edid_lpcm_support(const unsigned char *edid_data, int ext) /* Audio Data Block, type LPCM, return bitmap of frequencies */ dbc_type = edid_ext[dbc + DBC_TAG_LENGTH] >> DBC_TAG_SHIFT; if ((dbc_type == DBC_TAG_AUDIO) && - (((edid_ext[dbp + DBCA_FORMAT]>>3) & 0xF) == DBCA_FMT_LPCM)) + (((edid_ext[dbp + DBCA_FORMAT] >> 3) & 0xF) == + DBCA_FMT_LPCM)) return edid_ext[dbp + DBCA_RATE]; dbc += db_len + 1; @@ -614,7 +565,6 @@ done_dtd: return 0; } - int edid_has_hdmi_info(const unsigned char *edid_data, int ext) { const unsigned char *edid_ext = edid_data + EDID_SIZE; @@ -671,26 +621,26 @@ void show_edid(FILE *outfile, unsigned char *edid_data, int ext) } /* unsigned edid_data so the right shifts pull in zeros */ fprintf(outfile, "Manufacturer ID %c%c%c, product ID 0x%x\n", - '@' + (edid_data[EDID_MFG_EID]>>2), - '@' + (((edid_data[EDID_MFG_EID] & 3)<<3) + - (edid_data[EDID_MFG_EID+1]>>5)), - '@' + (edid_data[EDID_MFG_EID+1] & 0x1f), - edid_data[EDID_MFG_PROD_LO] + (edid_data[EDID_MFG_PROD_HI]<<8)); - fprintf(outfile, - "Manufactured wk %d of %d. Edid version %d.%d\n", - edid_data[EDID_MFG_WEEK], 1990+edid_data[EDID_MFG_YEAR], + '@' + (edid_data[EDID_MFG_EID] >> 2), + '@' + (((edid_data[EDID_MFG_EID] & 3) << 3) + + (edid_data[EDID_MFG_EID + 1] >> 5)), + '@' + (edid_data[EDID_MFG_EID + 1] & 0x1f), + edid_data[EDID_MFG_PROD_LO] + + (edid_data[EDID_MFG_PROD_HI] << 8)); + fprintf(outfile, "Manufactured wk %d of %d. Edid version %d.%d\n", + edid_data[EDID_MFG_WEEK], 1990 + edid_data[EDID_MFG_YEAR], edidver, edidrev); fprintf(outfile, "Input: %s, vid level %d, %s, %s %s %s %s sync, %dx%dcm, Gamma %f\n", (edid_data[EDID_VIDEO_IN] & 0x80) ? "digital" : "analog", - (edid_data[EDID_VIDEO_IN]>>5) & 3, + (edid_data[EDID_VIDEO_IN] >> 5) & 3, (edid_data[EDID_VIDEO_IN] & 0x10) ? "Blank to black" : "", (edid_data[EDID_VIDEO_IN] & 0x08) ? "Separate" : "", (edid_data[EDID_VIDEO_IN] & 0x04) ? "Composite" : "", (edid_data[EDID_VIDEO_IN] & 0x02) ? "On-green" : "", (edid_data[EDID_VIDEO_IN] & 0x01) ? "Serration V" : "", edid_data[EDID_MAX_HSIZE], edid_data[EDID_MAX_VSIZE], - 1.0+((float)edid_data[EDID_GAMMA]/100.0)); + 1.0 + ((float)edid_data[EDID_GAMMA] / 100.0)); edid_features = edid_data[EDID_FEATURES]; fprintf(outfile, "Features: %s %s %s %s %s %s %s\n", @@ -735,7 +685,7 @@ void show_edid(FILE *outfile, unsigned char *edid_data, int ext) fprintf(outfile, "1024x768@75\n"); if (edid_data[EDID_ESTTIME2] & 0x01) fprintf(outfile, "1280x1024@75\n"); - if (edid_data[EDID_MFGTIME] & 0x80) + if (edid_data[EDID_MFGTIME] & 0x80) fprintf(outfile, "1152x870@75\n"); fprintf(outfile, "Standard timing:\n"); @@ -752,31 +702,30 @@ void show_edid(FILE *outfile, unsigned char *edid_data, int ext) hres = (hinfo * 8) + 248; switch (vinfo >> 6) { case ASPECT_16_10: - vres = (hres * 10)/16; + vres = (hres * 10) / 16; break; case ASPECT_4_3: - vres = (hres * 3)/4; + vres = (hres * 3) / 4; break; case ASPECT_5_4: - vres = (hres * 4)/5; + vres = (hres * 4) / 5; break; case ASPECT_16_9: - vres = (hres * 9)/16; + vres = (hres * 9) / 16; break; /* Default only hit if compiler broken */ default: vres = 0; } - fprintf(outfile, "%d: %dx%d@%d\n", - i, hres, vres, 60 + (vinfo & 0x3f)); + fprintf(outfile, "%d: %dx%d@%d\n", i, hres, vres, + 60 + (vinfo & 0x3f)); } fprintf(outfile, "Descriptor blocks:\n"); for (i = 0; i < EDID_N_DTDS; i++) show_edid_dtd(outfile, edid_data + (EDID_DTD_BASE + i * DTD_SIZE)); - fprintf(outfile, - "EDID contains %d extensions\n", + fprintf(outfile, "EDID contains %d extensions\n", edid_data[EDID_EXT_FLAG]); edid_ext = edid_data + EDID_SIZE; @@ -817,19 +766,17 @@ void show_edid(FILE *outfile, unsigned char *edid_data, int ext) } fprintf(outfile, "EDID %s ext tag 0x%02x rev 0x%02x skipped\n", - tagtype, - edid_ext[EEXT_TAG], + tagtype, edid_ext[EEXT_TAG], edid_ext[EEXT_REV]); } } } - /* Pixel counts normally round to 8 */ -#define CLOSE_ENOUGH(a, b) (abs((a)-(b)) < 16) +#define CLOSE_ENOUGH(a, b) (abs((a) - (b)) < 16) /* These match order of defines ASPECT_x_y in edid_utils.h */ -char *aspect_to_str[]={"16:10","4:3","5:4","16:9"}; +char *aspect_to_str[] = { "16:10", "4:3", "5:4", "16:9" }; int find_aspect(int h, int v) { @@ -866,8 +813,7 @@ int find_aspect_fromisize(unsigned char *edid_data) return res; } -int edid_get_monitor_name(const unsigned char *edid_data, - char *buf, +int edid_get_monitor_name(const unsigned char *edid_data, char *buf, unsigned int buf_size) { int i; @@ -877,8 +823,8 @@ int edid_get_monitor_name(const unsigned char *edid_data, dtd = edid_data + (EDID_DTD_BASE + i * DTD_SIZE); if (dtd[DTD_PCLK_LO] == 0x00 && dtd[DTD_PCLK_HI] == 0x00 && dtd[DTD_TYPETAG] == DTDTYPE_NAME) { - get_dtd_string((const char *)dtd + DTD_STRING, - buf, buf_size); + get_dtd_string((const char *)dtd + DTD_STRING, buf, + buf_size); return 0; } } diff --git a/cras/src/common/edid_utils.h b/cras/src/common/edid_utils.h index 8ee85d66..b43a6bc8 100644 --- a/cras/src/common/edid_utils.h +++ b/cras/src/common/edid_utils.h @@ -5,40 +5,42 @@ #ifndef __EDID_UTILS_H__ #define __EDID_UTILS_H__ +#include "stdio.h" + #ifdef __cplusplus extern "C" { #endif /* These match the EDID encoding for Standard Timing block */ #define ASPECT_16_10 0 -#define ASPECT_4_3 1 -#define ASPECT_5_4 2 -#define ASPECT_16_9 3 -#define N_ASPECTS 4 +#define ASPECT_4_3 1 +#define ASPECT_5_4 2 +#define ASPECT_16_9 3 +#define N_ASPECTS 4 /* Defines based on EDID and CEA-861D descriptions */ -#define EDID_HDR 0 -#define EDID_MFG_EID 0x8 +#define EDID_HDR 0 +#define EDID_MFG_EID 0x8 #define EDID_MFG_PROD_LO 0x0A #define EDID_MFG_PROD_HI 0x0B -#define EDID_MFG_SERIAL 0x0C -#define EDID_MFG_WEEK 0x10 -#define EDID_MFG_YEAR 0x11 -#define EDID_VERSION 0x12 -#define EDID_REVISION 0x13 -#define EDID_VIDEO_IN 0x14 -#define EDID_MAX_HSIZE 0x15 -#define EDID_MAX_VSIZE 0x16 -#define EDID_GAMMA 0x17 -#define EDID_FEATURES 0x18 - -#define EDID_ESTTIME1 0x23 -#define EDID_ESTTIME2 0x24 -#define EDID_MFGTIME 0x25 +#define EDID_MFG_SERIAL 0x0C +#define EDID_MFG_WEEK 0x10 +#define EDID_MFG_YEAR 0x11 +#define EDID_VERSION 0x12 +#define EDID_REVISION 0x13 +#define EDID_VIDEO_IN 0x14 +#define EDID_MAX_HSIZE 0x15 +#define EDID_MAX_VSIZE 0x16 +#define EDID_GAMMA 0x17 +#define EDID_FEATURES 0x18 + +#define EDID_ESTTIME1 0x23 +#define EDID_ESTTIME2 0x24 +#define EDID_MFGTIME 0x25 /* Next two repeat 8 times for standard timings 1-8 */ -#define EDID_STDTIMEH 0x26 -#define EDID_STDTIMEV 0x27 -#define EDID_N_STDTIME 8 +#define EDID_STDTIMEH 0x26 +#define EDID_STDTIMEV 0x27 +#define EDID_N_STDTIME 8 /* There are 4 DTD blocks in the EDID */ #define EDID_DTD_BASE 0x36 @@ -145,7 +147,6 @@ extern "C" { #define DBCVHDMI_IVLAT 10 #define DBCVHDMI_IALAT 11 - #define DBCSP_ALLOC 0 #define DBCSP_SIZE 3 @@ -163,9 +164,9 @@ extern "C" { #define VCDB_TAG 0 #define VCDB_ETAG 1 #define VCDB_FLAGS 2 -#define VCDB_S_PT(x) (((x) & 0x30) >> 4) -#define VCDB_S_IT(x) (((x) & 0x0C) >> 2) -#define VCDB_S_CE(x) (((x) & 0x03)) +#define VCDB_S_PT(x) (((x)&0x30) >> 4) +#define VCDB_S_IT(x) (((x)&0x0C) >> 2) +#define VCDB_S_CE(x) (((x)&0x03)) #define COL_TAG 0 #define COL_ETAG 1 @@ -178,8 +179,8 @@ extern "C" { int edid_valid(const unsigned char *edid_data); int edid_has_hdmi_info(const unsigned char *edid_data, int ext); int edid_lpcm_support(const unsigned char *edid_data, int ext); -void show_edid_data(FILE *outfile, unsigned char *edid_data, - int items, int base); +void show_edid_data(FILE *outfile, unsigned char *edid_data, int items, + int base); void show_edid(FILE *outfile, unsigned char *edid_data, int ext); int find_aspect(int h, int v); int find_aspect_fromisize(unsigned char *edid_data); @@ -193,8 +194,7 @@ int show_test_edid(FILE *outfile, int n); * buf - buffer to store monitor name. * buf_size - buffer size. */ -int edid_get_monitor_name(const unsigned char *edid_data, - char *buf, +int edid_get_monitor_name(const unsigned char *edid_data, char *buf, unsigned int buf_size); #ifdef __cplusplus diff --git a/cras/src/common/rtp.h b/cras/src/common/rtp.h index 45fddcf1..d0fb14af 100644 --- a/cras/src/common/rtp.h +++ b/cras/src/common/rtp.h @@ -24,52 +24,52 @@ #if __BYTE_ORDER == __LITTLE_ENDIAN struct rtp_header { - unsigned cc:4; - unsigned x:1; - unsigned p:1; - unsigned v:2; + unsigned cc : 4; + unsigned x : 1; + unsigned p : 1; + unsigned v : 2; - unsigned pt:7; - unsigned m:1; + unsigned pt : 7; + unsigned m : 1; uint16_t sequence_number; uint32_t timestamp; uint32_t ssrc; uint32_t csrc[0]; -} __attribute__ ((packed)); +} __attribute__((packed)); struct rtp_payload { - unsigned frame_count:4; - unsigned rfa0:1; - unsigned is_last_fragment:1; - unsigned is_first_fragment:1; - unsigned is_fragmented:1; -} __attribute__ ((packed)); + unsigned frame_count : 4; + unsigned rfa0 : 1; + unsigned is_last_fragment : 1; + unsigned is_first_fragment : 1; + unsigned is_fragmented : 1; +} __attribute__((packed)); #elif __BYTE_ORDER == __BIG_ENDIAN struct rtp_header { - unsigned v:2; - unsigned p:1; - unsigned x:1; - unsigned cc:4; + unsigned v : 2; + unsigned p : 1; + unsigned x : 1; + unsigned cc : 4; - unsigned m:1; - unsigned pt:7; + unsigned m : 1; + unsigned pt : 7; uint16_t sequence_number; uint32_t timestamp; uint32_t ssrc; uint32_t csrc[0]; -} __attribute__ ((packed)); +} __attribute__((packed)); struct rtp_payload { - unsigned is_fragmented:1; - unsigned is_first_fragment:1; - unsigned is_last_fragment:1; - unsigned rfa0:1; - unsigned frame_count:4; -} __attribute__ ((packed)); + unsigned is_fragmented : 1; + unsigned is_first_fragment : 1; + unsigned is_last_fragment : 1; + unsigned rfa0 : 1; + unsigned frame_count : 4; +} __attribute__((packed)); #else #error "Unknown byte order" diff --git a/cras/src/common/sfh.c b/cras/src/common/sfh.c index 32cb834b..56ac755f 100644 --- a/cras/src/common/sfh.c +++ b/cras/src/common/sfh.c @@ -30,48 +30,54 @@ #include <stdint.h> #undef get16bits -#if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \ - || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__) -#define get16bits(d) (*((const uint16_t *) (d))) +#if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) || \ + defined(_MSC_VER) || defined(__BORLANDC__) || defined(__TURBOC__) +#define get16bits(d) (*((const uint16_t *)(d))) #endif -#if !defined (get16bits) -#define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)\ - +(uint32_t)(((const uint8_t *)(d))[0]) ) +#if !defined(get16bits) +#define get16bits(d) \ + ((((uint32_t)(((const uint8_t *)(d))[1])) << 8) + \ + (uint32_t)(((const uint8_t *)(d))[0])) #endif -uint32_t SuperFastHash (const char * data, int len, uint32_t hash) { +uint32_t SuperFastHash(const char *data, int len, uint32_t hash) +{ uint32_t tmp; int rem; - if (len <= 0 || data == NULL) return 0; + if (len <= 0 || data == NULL) + return 0; rem = len & 3; len >>= 2; /* Main loop */ - for (;len > 0; len--) { - hash += get16bits (data); - tmp = (get16bits (data+2) << 11) ^ hash; - hash = (hash << 16) ^ tmp; - data += 2*sizeof (uint16_t); - hash += hash >> 11; + for (; len > 0; len--) { + hash += get16bits(data); + tmp = (get16bits(data + 2) << 11) ^ hash; + hash = (hash << 16) ^ tmp; + data += 2 * sizeof(uint16_t); + hash += hash >> 11; } /* Handle end cases */ switch (rem) { - case 3: hash += get16bits (data); - hash ^= hash << 16; - hash ^= ((signed char)data[sizeof (uint16_t)]) << 18; - hash += hash >> 11; - break; - case 2: hash += get16bits (data); - hash ^= hash << 11; - hash += hash >> 17; - break; - case 1: hash += (signed char)*data; - hash ^= hash << 10; - hash += hash >> 1; + case 3: + hash += get16bits(data); + hash ^= hash << 16; + hash ^= ((signed char)data[sizeof(uint16_t)]) << 18; + hash += hash >> 11; + break; + case 2: + hash += get16bits(data); + hash ^= hash << 11; + hash += hash >> 17; + break; + case 1: + hash += (signed char)*data; + hash ^= hash << 10; + hash += hash >> 1; } /* Force "avalanching" of final 127 bits */ diff --git a/cras/src/common/utlist.h b/cras/src/common/utlist.h index a9f19b5b..e3ee6304 100644 --- a/cras/src/common/utlist.h +++ b/cras/src/common/utlist.h @@ -62,36 +62,36 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * Singly linked list macros (non-circular). *****************************************************************************/ #define LL_PREPEND(head, add) \ -do { \ - (add)->next = head; \ - head = add; \ -} while (0) + do { \ + (add)->next = head; \ + head = add; \ + } while (0) #define LL_CONCAT(head1, head2) \ -do { \ - __typeof(head1) _tmp; \ - if (head1) { \ - _tmp = head1; \ - while (_tmp->next) \ - _tmp = _tmp->next; \ - _tmp->next = (head2); \ - } else \ - (head1) = (head2); \ -} while (0) + do { \ + __typeof(head1) _tmp; \ + if (head1) { \ + _tmp = head1; \ + while (_tmp->next) \ + _tmp = _tmp->next; \ + _tmp->next = (head2); \ + } else \ + (head1) = (head2); \ + } while (0) #define LL_APPEND(head, add) \ -do { \ - __typeof(head) _tmp; \ - (add)->next = NULL; \ - if (head) { \ - _tmp = head; \ - while (_tmp->next) \ - _tmp = _tmp->next; \ - _tmp->next = (add); \ - } else { \ - (head) = (add); \ - } \ -} while (0) + do { \ + __typeof(head) _tmp; \ + (add)->next = NULL; \ + if (head) { \ + _tmp = head; \ + while (_tmp->next) \ + _tmp = _tmp->next; \ + _tmp->next = (add); \ + } else { \ + (head) = (add); \ + } \ + } while (0) #define LL_DELETE(head, del) \ do { \ @@ -107,32 +107,31 @@ do { \ } \ } while (0) -#define LL_FOREACH(head, el) \ - for (el = head; el; el = el->next) +#define LL_FOREACH(head, el) for (el = head; el; el = el->next) #define LL_FOREACH_SAFE(head, el, tmp) \ for ((el) = (head); (el) && (tmp = (el)->next, 1); (el) = tmp) #define LL_SEARCH_SCALAR(head, out, field, val) \ do { \ - LL_FOREACH(head, out) \ + LL_FOREACH (head, out) \ if ((out)->field == (val)) \ break; \ } while (0) -#define LL_SEARCH_SCALAR_WITH_CAST(head, out, nout, field, val) \ +#define LL_SEARCH_SCALAR_WITH_CAST(head, out, nout, field, val) \ do { \ - LL_FOREACH(head, out) { \ + LL_FOREACH (head, out) { \ (nout) = (__typeof(nout))out; \ if ((nout)->field == (val)) \ break; \ - (nout) = 0; \ + (nout) = 0; \ } \ } while (0) #define LL_SEARCH(head, out, elt, cmp) \ do { \ - LL_FOREACH(head, out) \ + LL_FOREACH (head, out) \ if ((cmp(out, elt)) == 0) \ break; \ } while (0) @@ -210,19 +209,18 @@ do { \ } \ } while (0) - /* Create a variable name using given prefix and current line number. */ #define MAKE_NAME(prefix) TOKEN_PASTE2(prefix, __LINE__) #define TOKEN_PASTE2(x, y) TOKEN_PASTE(x, y) -#define TOKEN_PASTE(x, y) x ## y +#define TOKEN_PASTE(x, y) x##y /* This version creates a temporary variable to to make it safe for deleting the * elements during iteration. */ -#define DL_FOREACH(head, el) \ - DL_FOREACH_INTERNAL(head, el, MAKE_NAME(_dl_foreach_)) -#define DL_FOREACH_INTERNAL(head, el, tmp) \ - __typeof__(el) tmp; \ - for ((el) = (head); (el) && (tmp = (el)->next, 1); (el) = tmp) +#define DL_FOREACH(head, el) \ + DL_FOREACH_INTERNAL (head, el, MAKE_NAME(_dl_foreach_)) +#define DL_FOREACH_INTERNAL(head, el, tmp) \ + __typeof__(el) tmp; \ + for ((el) = (head); (el) && (tmp = (el)->next, 1); (el) = tmp) /* These are identical to their singly-linked list counterparts. */ #define DL_SEARCH_SCALAR LL_SEARCH_SCALAR @@ -230,4 +228,3 @@ do { \ #define DL_SEARCH LL_SEARCH #endif /* UTLIST_H */ - diff --git a/cras/src/dsp/dcblock.c b/cras/src/dsp/dcblock.c index c6b90c14..53ba9412 100644 --- a/cras/src/dsp/dcblock.c +++ b/cras/src/dsp/dcblock.c @@ -14,6 +14,7 @@ struct dcblock { float y_prev; float ramp_factor; float ramp_increment; + int initialized; }; struct dcblock *dcblock_new(float R, unsigned long sample_rate) @@ -37,6 +38,11 @@ void dcblock_process(struct dcblock *dcblock, float *data, int count) float y_prev = dcblock->y_prev; float R = dcblock->R; + if (!dcblock->initialized) { + x_prev = data[0]; + dcblock->initialized = 1; + } + for (n = 0; n < count; n++) { float x = data[n]; float d = x - x_prev + R * y_prev; diff --git a/cras/src/dsp/tests/cmpraw.c b/cras/src/dsp/tests/cmpraw.c index f5004533..911f19d8 100644 --- a/cras/src/dsp/tests/cmpraw.c +++ b/cras/src/dsp/tests/cmpraw.c @@ -49,8 +49,8 @@ int main(int argc, char **argv) maxdiff = max(fabs(data1[i] - data2[i]), maxdiff); } } - printf("avg diff = %g, max diff = %g, changed = %.3f%%\n", - diff / n, maxdiff * 32768, changed*100.0f/n); + printf("avg diff = %g, max diff = %g, changed = %.3f%%\n", diff / n, + maxdiff * 32768, changed * 100.0f / n); free(data1); free(data2); diff --git a/cras/src/dsp/tests/crossover2_test.c b/cras/src/dsp/tests/crossover2_test.c index c81a181a..f313d38c 100644 --- a/cras/src/dsp/tests/crossover2_test.c +++ b/cras/src/dsp/tests/crossover2_test.c @@ -15,15 +15,18 @@ #include "raw.h" #ifndef min -#define min(a, b) ({ __typeof__(a) _a = (a); \ - __typeof__(b) _b = (b); \ - _a < _b ? _a : _b; }) +#define min(a, b) \ + ({ \ + __typeof__(a) _a = (a); \ + __typeof__(b) _b = (b); \ + _a < _b ? _a : _b; \ + }) #endif static double tp_diff(struct timespec *tp2, struct timespec *tp1) { - return (tp2->tv_sec - tp1->tv_sec) - + (tp2->tv_nsec - tp1->tv_nsec) * 1e-9; + return (tp2->tv_sec - tp1->tv_sec) + + (tp2->tv_nsec - tp1->tv_nsec) * 1e-9; } void process(struct crossover2 *xo2, int count, float *data0L, float *data0R, diff --git a/cras/src/dsp/tests/crossover_test.c b/cras/src/dsp/tests/crossover_test.c index 5207cca8..267438d6 100644 --- a/cras/src/dsp/tests/crossover_test.c +++ b/cras/src/dsp/tests/crossover_test.c @@ -15,15 +15,18 @@ #include "raw.h" #ifndef min -#define min(a, b) ({ __typeof__(a) _a = (a); \ - __typeof__(b) _b = (b); \ - _a < _b ? _a : _b; }) +#define min(a, b) \ + ({ \ + __typeof__(a) _a = (a); \ + __typeof__(b) _b = (b); \ + _a < _b ? _a : _b; \ + }) #endif static double tp_diff(struct timespec *tp2, struct timespec *tp1) { - return (tp2->tv_sec - tp1->tv_sec) - + (tp2->tv_nsec - tp1->tv_nsec) * 1e-9; + return (tp2->tv_sec - tp1->tv_sec) + + (tp2->tv_nsec - tp1->tv_nsec) * 1e-9; } void process(struct crossover *xo, int count, float *data0, float *data1, @@ -31,8 +34,8 @@ void process(struct crossover *xo, int count, float *data0, float *data1, { int start; for (start = 0; start < count; start += 2048) - crossover_process(xo, min(2048, count - start), - data0 + start, data1 + start, data2 + start); + crossover_process(xo, min(2048, count - start), data0 + start, + data1 + start, data2 + start); } int main(int argc, char **argv) @@ -65,8 +68,7 @@ int main(int argc, char **argv) crossover_init(&xo, 400 / NQ, 4000 / NQ); clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp1); - process(&xo, frames, data0 + frames, data1 + frames, - data2 + frames); + process(&xo, frames, data0 + frames, data1 + frames, data2 + frames); clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp2); printf("processing takes %g seconds for %zu samples\n", tp_diff(&tp2, &tp1), frames); diff --git a/cras/src/dsp/tests/dcblock_test.c b/cras/src/dsp/tests/dcblock_test.c index 4a70b966..7beaa9f7 100644 --- a/cras/src/dsp/tests/dcblock_test.c +++ b/cras/src/dsp/tests/dcblock_test.c @@ -13,15 +13,18 @@ #include "raw.h" #ifndef min -#define min(a, b) ({ __typeof__(a) _a = (a); \ - __typeof__(b) _b = (b); \ - _a < _b ? _a : _b; }) +#define min(a, b) \ + ({ \ + __typeof__(a) _a = (a); \ + __typeof__(b) _b = (b); \ + _a < _b ? _a : _b; \ + }) #endif static double tp_diff(struct timespec *tp2, struct timespec *tp1) { - return (tp2->tv_sec - tp1->tv_sec) - + (tp2->tv_nsec - tp1->tv_nsec) * 1e-9; + return (tp2->tv_sec - tp1->tv_sec) + + (tp2->tv_nsec - tp1->tv_nsec) * 1e-9; } /* Processes a buffer of data chunk by chunk using the filter */ @@ -29,9 +32,7 @@ static void process(struct dcblock *dcblock, float *data, int count) { int start; for (start = 0; start < count; start += 128) - dcblock_process(dcblock, - data + start, - min(128, count - start)); + dcblock_process(dcblock, data + start, min(128, count - start)); } /* Runs the filters on an input file */ @@ -48,7 +49,7 @@ static void test_file(const char *input_filename, const char *output_filename) dcblockr = dcblock_new(0.995, 48000); clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp1); process(dcblockl, data, frames); - process(dcblockr, data+frames, frames); + process(dcblockr, data + frames, frames); clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp2); printf("processing takes %g seconds for %zu samples\n", tp_diff(&tp2, &tp1), frames); diff --git a/cras/src/dsp/tests/drc_test.c b/cras/src/dsp/tests/drc_test.c index 800dd797..17ccbcd5 100644 --- a/cras/src/dsp/tests/drc_test.c +++ b/cras/src/dsp/tests/drc_test.c @@ -12,15 +12,18 @@ #include "raw.h" #ifndef min -#define min(a, b) ({ __typeof__(a) _a = (a); \ - __typeof__(b) _b = (b); \ - _a < _b ? _a : _b; }) +#define min(a, b) \ + ({ \ + __typeof__(a) _a = (a); \ + __typeof__(b) _b = (b); \ + _a < _b ? _a : _b; \ + }) #endif static double tp_diff(struct timespec *tp2, struct timespec *tp1) { - return (tp2->tv_sec - tp1->tv_sec) - + (tp2->tv_nsec - tp1->tv_nsec) * 1e-9; + return (tp2->tv_sec - tp1->tv_sec) + + (tp2->tv_nsec - tp1->tv_nsec) * 1e-9; } static void process(struct drc *drc, float *buf, size_t frames) diff --git a/cras/src/dsp/tests/dsp_util_test.c b/cras/src/dsp/tests/dsp_util_test.c index f545fc8f..44f72575 100644 --- a/cras/src/dsp/tests/dsp_util_test.c +++ b/cras/src/dsp/tests/dsp_util_test.c @@ -3,8 +3,8 @@ * found in the LICENSE file. */ -#include <math.h> /* for abs() */ -#include <stdio.h> /* for printf() */ +#include <math.h> /* for abs() */ +#include <stdio.h> /* for printf() */ #include <string.h> /* for memset() */ #include <stdint.h> /* for uint64 definition */ #include <stdlib.h> /* for exit() definition */ @@ -13,24 +13,25 @@ #include "../drc_math.h" #include "../dsp_util.h" - /* Constant for converting time to milliseconds. */ #define BILLION 1000000000LL /* Number of iterations for performance testing. */ #define ITERATIONS 400000 #if defined(__aarch64__) -int16_t float_to_short(float a) { +int16_t float_to_short(float a) +{ int32_t ret; - asm volatile ("fcvtas %s[ret], %s[a]\n" - "sqxtn %h[ret], %s[ret]\n" - : [ret] "=w" (ret) - : [a] "w" (a) - :); + asm volatile("fcvtas %s[ret], %s[a]\n" + "sqxtn %h[ret], %s[ret]\n" + : [ret] "=w"(ret) + : [a] "w"(a) + :); return (int16_t)(ret); } #else -int16_t float_to_short(float a) { +int16_t float_to_short(float a) +{ a += (a >= 0) ? 0.5f : -0.5f; return (int16_t)(max(-32768, min(32767, a))); } @@ -78,13 +79,13 @@ void TestRounding(float in, int16_t expected, int samples) int max_diff; int d; - short* in_shorts = (short*) malloc(MAXSAMPLES * 2 * 2 + PAD); - float* out_floats_left_c = (float*) malloc(MAXSAMPLES * 4 + PAD); - float* out_floats_right_c = (float*) malloc(MAXSAMPLES * 4 + PAD); - float* out_floats_left_opt = (float*) malloc(MAXSAMPLES * 4 + PAD); - float* out_floats_right_opt = (float*) malloc(MAXSAMPLES * 4 + PAD); - short* out_shorts_c = (short*) malloc(MAXSAMPLES * 2 * 2 + PAD); - short* out_shorts_opt = (short*) malloc(MAXSAMPLES * 2 * 2 + PAD); + short *in_shorts = (short *)malloc(MAXSAMPLES * 2 * 2 + PAD); + float *out_floats_left_c = (float *)malloc(MAXSAMPLES * 4 + PAD); + float *out_floats_right_c = (float *)malloc(MAXSAMPLES * 4 + PAD); + float *out_floats_left_opt = (float *)malloc(MAXSAMPLES * 4 + PAD); + float *out_floats_right_opt = (float *)malloc(MAXSAMPLES * 4 + PAD); + short *out_shorts_c = (short *)malloc(MAXSAMPLES * 2 * 2 + PAD); + short *out_shorts_opt = (short *)malloc(MAXSAMPLES * 2 * 2 + PAD); memset(in_shorts, 0xfb, MAXSAMPLES * 2 * 2 + PAD); memset(out_floats_left_c, 0xfb, MAXSAMPLES * 4 + PAD); @@ -125,10 +126,12 @@ void TestRounding(float in, int16_t expected, int samples) } } printf("test interleave compare %6d, %10f %13f %6d %6d %6d %s\n", - max_diff, in, in * 32768.0f, out_shorts_c[0], out_shorts_opt[0], - expected, - max_diff == 0 ? "PASS" : (out_shorts_opt[0] == expected ? - "EXPECTED DIFFERENCE" : "UNEXPECTED DIFFERENCE")); + max_diff, in, in * 32768.0f, out_shorts_c[0], out_shorts_opt[0], + expected, + max_diff == 0 ? "PASS" : + (out_shorts_opt[0] == expected ? + "EXPECTED DIFFERENCE" : + "UNEXPECTED DIFFERENCE")); /* measure reference C deinterleave */ dsp_util_deinterleave_reference(in_shorts, out_floats_ptr_c, 2, @@ -139,11 +142,13 @@ void TestRounding(float in, int16_t expected, int samples) SND_PCM_FORMAT_S16_LE, samples); d = memcmp(out_floats_ptr_c[0], out_floats_ptr_opt[0], samples * 4); - if (d) printf("left compare %d, %f %f\n", d, out_floats_ptr_c[0][0], - out_floats_ptr_opt[0][0]); + if (d) + printf("left compare %d, %f %f\n", d, out_floats_ptr_c[0][0], + out_floats_ptr_opt[0][0]); d = memcmp(out_floats_ptr_c[1], out_floats_ptr_opt[1], samples * 4); - if (d) printf("right compare %d, %f %f\n", d, out_floats_ptr_c[1][0], - out_floats_ptr_opt[1][0]); + if (d) + printf("right compare %d, %f %f\n", d, out_floats_ptr_c[1][0], + out_floats_ptr_opt[1][0]); free(in_shorts); free(out_floats_left_c); @@ -193,11 +198,11 @@ int main(int argc, char **argv) inf.ieee.negative = 0; inf.ieee.exponent = 0xfe; inf.ieee.mantissa = 0x7fffff; - TestRounding(inf.f, EXPECTED_INF_RESULT, samples); // expect fail + TestRounding(inf.f, EXPECTED_INF_RESULT, samples); // expect fail inf.ieee.negative = 1; inf.ieee.exponent = 0xfe; inf.ieee.mantissa = 0x7fffff; - TestRounding(inf.f, EXPECTED_NEGINF_RESULT, samples); // expect fail + TestRounding(inf.f, EXPECTED_NEGINF_RESULT, samples); // expect fail // test rounding TestRounding(0.25f, 8192, samples); @@ -213,10 +218,10 @@ int main(int argc, char **argv) /* Rounding on 'tie' is different for Intel. */ #if defined(__i386__) || defined(__x86_64__) - TestRounding(0.5f / 32768.0f, 0, samples); /* Expect round to even */ + TestRounding(0.5f / 32768.0f, 0, samples); /* Expect round to even */ TestRounding(-0.5f / 32768.0f, 0, samples); #else - TestRounding(0.5f / 32768.0f, 1, samples); /* Expect round away */ + TestRounding(0.5f / 32768.0f, 1, samples); /* Expect round away */ TestRounding(-0.5f / 32768.0f, -1, samples); #endif @@ -249,14 +254,14 @@ int main(int argc, char **argv) #else #define EXPECTED_NAN_RESULT 0 #endif - union ieee754_float nan; /* Quiet NaN */ + union ieee754_float nan; /* Quiet NaN */ nan.ieee.negative = 0; nan.ieee.exponent = 0xff; nan.ieee.mantissa = 0x400001; TestRounding(nan.f, EXPECTED_NAN_RESULT, samples); nan.ieee.negative = 0; nan.ieee.exponent = 0xff; - nan.ieee.mantissa = 0x000001; /* Signalling NaN */ + nan.ieee.mantissa = 0x000001; /* Signalling NaN */ TestRounding(nan.f, EXPECTED_NAN_RESULT, samples); /* Test Performance */ @@ -265,13 +270,13 @@ int main(int argc, char **argv) int i; int d; - short* in_shorts = (short*) malloc(MAXSAMPLES * 2 * 2 + PAD); - float* out_floats_left_c = (float*) malloc(MAXSAMPLES * 4 + PAD); - float* out_floats_right_c = (float*) malloc(MAXSAMPLES * 4 + PAD); - float* out_floats_left_opt = (float*) malloc(MAXSAMPLES * 4 + PAD); - float* out_floats_right_opt = (float*) malloc(MAXSAMPLES * 4 + PAD); - short* out_shorts_c = (short*) malloc(MAXSAMPLES * 2 * 2 + PAD); - short* out_shorts_opt = (short*) malloc(MAXSAMPLES * 2 * 2 + PAD); + short *in_shorts = (short *)malloc(MAXSAMPLES * 2 * 2 + PAD); + float *out_floats_left_c = (float *)malloc(MAXSAMPLES * 4 + PAD); + float *out_floats_right_c = (float *)malloc(MAXSAMPLES * 4 + PAD); + float *out_floats_left_opt = (float *)malloc(MAXSAMPLES * 4 + PAD); + float *out_floats_right_opt = (float *)malloc(MAXSAMPLES * 4 + PAD); + short *out_shorts_c = (short *)malloc(MAXSAMPLES * 2 * 2 + PAD); + short *out_shorts_opt = (short *)malloc(MAXSAMPLES * 2 * 2 + PAD); memset(in_shorts, 0x11, MAXSAMPLES * 2 * 2 + PAD); memset(out_floats_left_c, 0x22, MAXSAMPLES * 4 + PAD); @@ -291,19 +296,18 @@ int main(int argc, char **argv) /* Benchmark dsp_util_interleave */ for (samples = MAXSAMPLES; samples >= MINSAMPLES; samples /= 2) { - /* measure original C interleave */ clock_gettime(CLOCK_MONOTONIC, &start); /* mark start time */ for (i = 0; i < ITERATIONS; ++i) { dsp_util_interleave_reference(out_floats_ptr_c, - out_shorts_c, - 2, samples); + out_shorts_c, 2, samples); } clock_gettime(CLOCK_MONOTONIC, &end); /* mark the end time */ - diff = (BILLION * (end.tv_sec - start.tv_sec) + - end.tv_nsec - start.tv_nsec) / 1000000; + diff = (BILLION * (end.tv_sec - start.tv_sec) + end.tv_nsec - + start.tv_nsec) / + 1000000; printf("interleave ORIG size = %6d, elapsed time = %llu ms\n", - samples, (long long unsigned int) diff); + samples, (long long unsigned int)diff); /* measure optimized interleave */ clock_gettime(CLOCK_MONOTONIC, &start); /* mark start time */ @@ -313,35 +317,36 @@ int main(int argc, char **argv) SND_PCM_FORMAT_S16_LE, samples); } clock_gettime(CLOCK_MONOTONIC, &end); /* mark the end time */ - diff = (BILLION * (end.tv_sec - start.tv_sec) + - end.tv_nsec - start.tv_nsec) / 1000000; + diff = (BILLION * (end.tv_sec - start.tv_sec) + end.tv_nsec - + start.tv_nsec) / + 1000000; printf("interleave SIMD size = %6d, elapsed time = %llu ms\n", - samples, (long long unsigned int) diff); + samples, (long long unsigned int)diff); /* Test C and SIMD output match */ d = memcmp(out_shorts_c, out_shorts_opt, MAXSAMPLES * 2 * 2 + PAD); - if (d) printf("interleave compare %d, %d %d, %d %d\n", d, - out_shorts_c[0], out_shorts_c[1], - out_shorts_opt[0], out_shorts_opt[1]); + if (d) + printf("interleave compare %d, %d %d, %d %d\n", d, + out_shorts_c[0], out_shorts_c[1], + out_shorts_opt[0], out_shorts_opt[1]); } /* Benchmark dsp_util_deinterleave */ for (samples = MAXSAMPLES; samples >= MINSAMPLES; samples /= 2) { - /* Measure original C deinterleave */ clock_gettime(CLOCK_MONOTONIC, &start); /* mark start time */ for (i = 0; i < ITERATIONS; ++i) { - dsp_util_deinterleave_reference(in_shorts, - out_floats_ptr_c, - 2, samples); + dsp_util_deinterleave_reference( + in_shorts, out_floats_ptr_c, 2, samples); } clock_gettime(CLOCK_MONOTONIC, &end); /* mark the end time */ - diff = (BILLION * (end.tv_sec - start.tv_sec) + - end.tv_nsec - start.tv_nsec) / 1000000; - printf("deinterleave ORIG size = %6d, " - "elapsed time = %llu ms\n", - samples, (long long unsigned int) diff); + diff = (BILLION * (end.tv_sec - start.tv_sec) + end.tv_nsec - + start.tv_nsec) / + 1000000; + printf("deinterleave ORIG size = %6d, " + "elapsed time = %llu ms\n", + samples, (long long unsigned int)diff); /* Measure optimized deinterleave */ clock_gettime(CLOCK_MONOTONIC, &start); /* mark start time */ @@ -351,20 +356,25 @@ int main(int argc, char **argv) SND_PCM_FORMAT_S16_LE, samples); } clock_gettime(CLOCK_MONOTONIC, &end); /* mark the end time */ - diff = (BILLION * (end.tv_sec - start.tv_sec) + - end.tv_nsec - start.tv_nsec) / 1000000; + diff = (BILLION * (end.tv_sec - start.tv_sec) + end.tv_nsec - + start.tv_nsec) / + 1000000; printf("deinterleave SIMD size = %6d, elapsed time = %llu ms\n", - samples, (long long unsigned int) diff); + samples, (long long unsigned int)diff); /* Test C and SIMD output match */ d = memcmp(out_floats_ptr_c[0], out_floats_ptr_opt[0], samples * 4); - if (d) printf("left compare %d, %f %f\n", d, - out_floats_ptr_c[0][0], out_floats_ptr_opt[0][0]); + if (d) + printf("left compare %d, %f %f\n", d, + out_floats_ptr_c[0][0], + out_floats_ptr_opt[0][0]); d = memcmp(out_floats_ptr_c[1], out_floats_ptr_opt[1], samples * 4); - if (d) printf("right compare %d, %f %f\n", d, - out_floats_ptr_c[1][0], out_floats_ptr_opt[1][0]); + if (d) + printf("right compare %d, %f %f\n", d, + out_floats_ptr_c[1][0], + out_floats_ptr_opt[1][0]); } free(in_shorts); diff --git a/cras/src/dsp/tests/eq2_test.c b/cras/src/dsp/tests/eq2_test.c index dbcee959..36ce80bd 100644 --- a/cras/src/dsp/tests/eq2_test.c +++ b/cras/src/dsp/tests/eq2_test.c @@ -13,15 +13,18 @@ #include "raw.h" #ifndef min -#define min(a, b) ({ __typeof__(a) _a = (a); \ - __typeof__(b) _b = (b); \ - _a < _b ? _a : _b; }) +#define min(a, b) \ + ({ \ + __typeof__(a) _a = (a); \ + __typeof__(b) _b = (b); \ + _a < _b ? _a : _b; \ + }) #endif static double tp_diff(struct timespec *tp2, struct timespec *tp1) { - return (tp2->tv_sec - tp1->tv_sec) - + (tp2->tv_nsec - tp1->tv_nsec) * 1e-9; + return (tp2->tv_sec - tp1->tv_sec) + + (tp2->tv_nsec - tp1->tv_nsec) * 1e-9; } /* Processes a buffer of data chunk by chunk using eq2 */ @@ -50,18 +53,18 @@ static void test_file(const char *input_filename, const char *output_filename) /* eq chain */ eq2 = eq2_new(); - eq2_append_biquad(eq2, 0, BQ_PEAKING, 380/NQ, 3, -10); - eq2_append_biquad(eq2, 0, BQ_PEAKING, 720/NQ, 3, -12); - eq2_append_biquad(eq2, 0, BQ_PEAKING, 1705/NQ, 3, -8); - eq2_append_biquad(eq2, 0, BQ_HIGHPASS, 218/NQ, 0.7, -10.2); - eq2_append_biquad(eq2, 0, BQ_PEAKING, 580/NQ, 6, -8); - eq2_append_biquad(eq2, 0, BQ_HIGHSHELF, 8000/NQ, 3, 2); - eq2_append_biquad(eq2, 1, BQ_PEAKING, 450/NQ, 3, -12); - eq2_append_biquad(eq2, 1, BQ_PEAKING, 721/NQ, 3, -12); - eq2_append_biquad(eq2, 1, BQ_PEAKING, 1800/NQ, 8, -10.2); - eq2_append_biquad(eq2, 1, BQ_PEAKING, 580/NQ, 6, -8); - eq2_append_biquad(eq2, 1, BQ_HIGHPASS, 250/NQ, 0.6578, 0); - eq2_append_biquad(eq2, 1, BQ_HIGHSHELF, 8000/NQ, 0, 2); + eq2_append_biquad(eq2, 0, BQ_PEAKING, 380 / NQ, 3, -10); + eq2_append_biquad(eq2, 0, BQ_PEAKING, 720 / NQ, 3, -12); + eq2_append_biquad(eq2, 0, BQ_PEAKING, 1705 / NQ, 3, -8); + eq2_append_biquad(eq2, 0, BQ_HIGHPASS, 218 / NQ, 0.7, -10.2); + eq2_append_biquad(eq2, 0, BQ_PEAKING, 580 / NQ, 6, -8); + eq2_append_biquad(eq2, 0, BQ_HIGHSHELF, 8000 / NQ, 3, 2); + eq2_append_biquad(eq2, 1, BQ_PEAKING, 450 / NQ, 3, -12); + eq2_append_biquad(eq2, 1, BQ_PEAKING, 721 / NQ, 3, -12); + eq2_append_biquad(eq2, 1, BQ_PEAKING, 1800 / NQ, 8, -10.2); + eq2_append_biquad(eq2, 1, BQ_PEAKING, 580 / NQ, 6, -8); + eq2_append_biquad(eq2, 1, BQ_HIGHPASS, 250 / NQ, 0.6578, 0); + eq2_append_biquad(eq2, 1, BQ_HIGHSHELF, 8000 / NQ, 0, 2); clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp1); process(eq2, data, data + frames, frames); clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp2); diff --git a/cras/src/dsp/tests/eq_test.c b/cras/src/dsp/tests/eq_test.c index d7991014..4adcecf6 100644 --- a/cras/src/dsp/tests/eq_test.c +++ b/cras/src/dsp/tests/eq_test.c @@ -13,15 +13,18 @@ #include "raw.h" #ifndef min -#define min(a, b) ({ __typeof__(a) _a = (a); \ - __typeof__(b) _b = (b); \ - _a < _b ? _a : _b; }) +#define min(a, b) \ + ({ \ + __typeof__(a) _a = (a); \ + __typeof__(b) _b = (b); \ + _a < _b ? _a : _b; \ + }) #endif static double tp_diff(struct timespec *tp2, struct timespec *tp1) { - return (tp2->tv_sec - tp1->tv_sec) - + (tp2->tv_nsec - tp1->tv_nsec) * 1e-9; + return (tp2->tv_sec - tp1->tv_sec) + + (tp2->tv_nsec - tp1->tv_nsec) * 1e-9; } /* Generates impulse response */ @@ -39,12 +42,12 @@ static void test_ir() data[0] = 1; eq = eq_new(); - eq_append_biquad(eq, BQ_PEAKING, 380/NQ, 3, -10); - eq_append_biquad(eq, BQ_PEAKING, 720/NQ, 3, -12); - eq_append_biquad(eq, BQ_PEAKING, 1705/NQ, 3, -8); - eq_append_biquad(eq, BQ_HIGHPASS, 218/NQ, 0.7, -10.2); - eq_append_biquad(eq, BQ_PEAKING, 580/NQ, 6, -8); - eq_append_biquad(eq, BQ_HIGHSHELF, 8000/NQ, 3, 2); + eq_append_biquad(eq, BQ_PEAKING, 380 / NQ, 3, -10); + eq_append_biquad(eq, BQ_PEAKING, 720 / NQ, 3, -12); + eq_append_biquad(eq, BQ_PEAKING, 1705 / NQ, 3, -8); + eq_append_biquad(eq, BQ_HIGHPASS, 218 / NQ, 0.7, -10.2); + eq_append_biquad(eq, BQ_PEAKING, 580 / NQ, 6, -8); + eq_append_biquad(eq, BQ_HIGHSHELF, 8000 / NQ, 3, 2); clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp1); eq_process(eq, data, N); @@ -84,12 +87,12 @@ static void test_file(const char *input_filename, const char *output_filename) /* Left eq chain */ eq = eq_new(); - eq_append_biquad(eq, BQ_PEAKING, 380/NQ, 3, -10); - eq_append_biquad(eq, BQ_PEAKING, 720/NQ, 3, -12); - eq_append_biquad(eq, BQ_PEAKING, 1705/NQ, 3, -8); - eq_append_biquad(eq, BQ_HIGHPASS, 218/NQ, 0.7, -10.2); - eq_append_biquad(eq, BQ_PEAKING, 580/NQ, 6, -8); - eq_append_biquad(eq, BQ_HIGHSHELF, 8000/NQ, 3, 2); + eq_append_biquad(eq, BQ_PEAKING, 380 / NQ, 3, -10); + eq_append_biquad(eq, BQ_PEAKING, 720 / NQ, 3, -12); + eq_append_biquad(eq, BQ_PEAKING, 1705 / NQ, 3, -8); + eq_append_biquad(eq, BQ_HIGHPASS, 218 / NQ, 0.7, -10.2); + eq_append_biquad(eq, BQ_PEAKING, 580 / NQ, 6, -8); + eq_append_biquad(eq, BQ_HIGHSHELF, 8000 / NQ, 3, 2); clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp1); process(eq, data, frames); clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp2); @@ -99,12 +102,12 @@ static void test_file(const char *input_filename, const char *output_filename) /* Right eq chain */ eq = eq_new(); - eq_append_biquad(eq, BQ_PEAKING, 450/NQ, 3, -12); - eq_append_biquad(eq, BQ_PEAKING, 721/NQ, 3, -12); - eq_append_biquad(eq, BQ_PEAKING, 1800/NQ, 8, -10.2); - eq_append_biquad(eq, BQ_PEAKING, 580/NQ, 6, -8); - eq_append_biquad(eq, BQ_HIGHPASS, 250/NQ, 0.6578, 0); - eq_append_biquad(eq, BQ_HIGHSHELF, 8000/NQ, 0, 2); + eq_append_biquad(eq, BQ_PEAKING, 450 / NQ, 3, -12); + eq_append_biquad(eq, BQ_PEAKING, 721 / NQ, 3, -12); + eq_append_biquad(eq, BQ_PEAKING, 1800 / NQ, 8, -10.2); + eq_append_biquad(eq, BQ_PEAKING, 580 / NQ, 6, -8); + eq_append_biquad(eq, BQ_HIGHPASS, 250 / NQ, 0.6578, 0); + eq_append_biquad(eq, BQ_HIGHSHELF, 8000 / NQ, 0, 2); clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp1); process(eq, data + frames, frames); clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp2); diff --git a/cras/src/dsp/tests/raw.c b/cras/src/dsp/tests/raw.c index 65c1d92c..d75e28fa 100644 --- a/cras/src/dsp/tests/raw.c +++ b/cras/src/dsp/tests/raw.c @@ -43,8 +43,8 @@ float *read_raw(const char *filename, size_t *frames) /* deinterleave and convert to float */ data = (float *)malloc(sizeof(float) * f * 2); for (i = 0; i < f; i++) { - data[i] = buf[2*i] / 32768.0f; - data[i + f] = buf[2*i+1] / 32768.0f; + data[i] = buf[2 * i] / 32768.0f; + data[i + f] = buf[2 * i + 1] / 32768.0f; } free(buf); *frames = f; @@ -72,8 +72,8 @@ int write_raw(const char *filename, float *input, size_t frames) buf = (int16_t *)malloc(n); for (i = 0; i < frames; i++) { - buf[2*i] = f2s16(input[i]); - buf[2*i+1] = f2s16(input[i + frames]); + buf[2 * i] = f2s16(input[i]); + buf[2 * i + 1] = f2s16(input[i + frames]); } int fd = open(filename, O_WRONLY | O_CREAT, 0644); diff --git a/cras/src/fuzz/README b/cras/src/fuzz/README deleted file mode 100644 index 96e9076e..00000000 --- a/cras/src/fuzz/README +++ /dev/null @@ -1,23 +0,0 @@ -This directory contains source code and build scripts for coverage-guided -fuzzers. - -Detailed instructions are available at: - - https://github.com/google/oss-fuzz/blob/master/docs/ - -Quick start: - - Build a container from the cras directory - - $ sudo docker build -t ossfuzz/cras -f src/fuzz/Dockerfile . - - Build fuzzers - - $ sudo docker run -ti --rm -v $(pwd):/src/cras -v /tmp/fuzzers:/out \ - ossfuzz/cras - - Look in /tmp/fuzzers to see the executables. Run them like so: - - $ sudo docker run -ti -v $(pwd)/src/fuzz/corpus:/corpus \ - -v /tmp/fuzzers:/out ossfuzz/base-runner /out/rclient_message \ - /corpus -runs=100 diff --git a/cras/src/fuzz/README.md b/cras/src/fuzz/README.md new file mode 100644 index 00000000..72716023 --- /dev/null +++ b/cras/src/fuzz/README.md @@ -0,0 +1,40 @@ +# OSS-Fuzz for CRAS + +This directory contains source code and build scripts for coverage-guided +fuzzers. + +Detailed instructions are available at: https://github.com/google/oss-fuzz/blob/master/docs/ + +## Quick start + +### Sudoless Docker +``` +sudo adduser $USER docker +``` + +### Build a container from the cras directory +``` +docker build -t ossfuzz/cras -f src/fuzz/Dockerfile . +``` + +### Build fuzzers +``` +docker run --cap-add=SYS_PTRACE -ti --rm -v $(pwd):/src/cras -v /tmp/fuzzers:/out \ + ossfuzz/cras +``` + +### Look in /tmp/fuzzers to see the executables. Run them like so: +``` +docker run --cap-add=SYS_PTRACE -ti -v $(pwd)/src/fuzz/corpus:/corpus \ + -v /tmp/fuzzers:/out ossfuzz/base-runner /out/rclient_message \ + /corpus -runs=100 +``` + +### Debug in docker + +Go into docker console by +``` +docker run --cap-add=SYS_PTRACE -ti -v $(pwd)/src/fuzz/corpus:/corpus \ + -v /tmp/fuzzers:/out ossfuzz/base-runner /bin/bash +``` +and start debugging. diff --git a/cras/src/fuzz/rclient_message.cc b/cras/src/fuzz/rclient_message.cc index 17216c99..a2a5650a 100644 --- a/cras/src/fuzz/rclient_message.cc +++ b/cras/src/fuzz/rclient_message.cc @@ -1,4 +1,4 @@ -/* Copyright 2017 The Chromium Authors. All rights reserved. +/* Copyright 2017 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ @@ -8,7 +8,6 @@ #include <stdint.h> extern "C" { -#include "cras_control_rclient.h" #include "cras_iodev_list.h" #include "cras_mix.h" #include "cras_observer.h" @@ -17,29 +16,25 @@ extern "C" { #include "cras_system_state.h" } -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - cras_rclient *client = cras_control_rclient_create(0, 0); - cras_rclient_buffer_from_client(client, data, size, -1); +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + cras_rclient* client = cras_rclient_create(0, 0, CRAS_CONTROL); + cras_rclient_buffer_from_client(client, data, size, NULL, 0); cras_rclient_destroy(client); return 0; } -extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) { - char *shm_name; +extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) { + char* shm_name; if (asprintf(&shm_name, "/cras-%d", getpid()) < 0) exit(-ENOMEM); - struct cras_server_state *exp_state = (struct cras_server_state *) - calloc(1, sizeof(*exp_state)); + struct cras_server_state* exp_state = + (struct cras_server_state*)calloc(1, sizeof(*exp_state)); if (!exp_state) exit(-1); int rw_shm_fd = open("/dev/null", O_RDWR); int ro_shm_fd = open("/dev/null", O_RDONLY); - cras_system_state_init("/tmp", - shm_name, - rw_shm_fd, - ro_shm_fd, - exp_state, + cras_system_state_init("/tmp", shm_name, rw_shm_fd, ro_shm_fd, exp_state, sizeof(*exp_state)); free(shm_name); diff --git a/cras/src/libcras/cras_client.c b/cras/src/libcras/cras_client.c index 5365a16e..fe54e0e3 100644 --- a/cras/src/libcras/cras_client.c +++ b/cras/src/libcras/cras_client.c @@ -13,7 +13,7 @@ * client_stream struct and send a file descriptor to server. That file * descriptor and aud_fd are a pair created from socketpair(). * client_connected - The server will send a connected message to indicate that - * the client should start receving audio events from aud_fd. This message + * the client should start receiving audio events from aud_fd. This message * also specifies the shared memory region to use to share audio samples. * This region will be shmat'd. * running - Once the connections are established, the client will listen for @@ -125,6 +125,7 @@ struct cras_stream_params { size_t buffer_frames; size_t cb_threshold; enum CRAS_STREAM_TYPE stream_type; + enum CRAS_CLIENT_TYPE client_type; uint32_t flags; uint64_t effects; void *user_data; @@ -132,6 +133,8 @@ struct cras_stream_params { cras_unified_cb_t unified_cb; cras_error_cb_t err_cb; struct cras_audio_format format; + int client_shm_fd; + size_t client_shm_size; }; /* Represents an attached audio stream. @@ -205,10 +208,10 @@ typedef enum cras_socket_state { * last_command_result - Passes back the result of the last user command. * streams - Linked list of streams attached to this client. * server_state - RO shared memory region holding server state. + * atlog_ro - RO shared memory region holding audio thread log. * debug_info_callback - Function to call when debug info is received. + * atlog_access_callback - Function to call when atlog RO fd is received. * get_hotword_models_cb_t - Function to call when hotword models info is ready. - * server_err_cb - Function to call when failed to read messages from server. - * server_err_user_arg - User argument for server_err_cb. * server_connection_cb - Function to called when a connection state changes. * server_connection_user_arg - User argument for server_connection_cb. * thread_priority_cb - Function to call for setting audio thread priority. @@ -233,9 +236,10 @@ struct cras_client { int last_command_result; struct client_stream *streams; const struct cras_server_state *server_state; + struct audio_thread_event_log *atlog_ro; void (*debug_info_callback)(struct cras_client *); + void (*atlog_access_callback)(struct cras_client *); get_hotword_models_cb_t get_hotword_models_cb; - cras_server_error_cb_t server_err_cb; cras_connection_status_cb_t server_connection_cb; void *server_connection_user_arg; cras_thread_priority_cb_t thread_priority_cb; @@ -663,9 +667,6 @@ static void disconnect_transition_action(struct cras_client *client, bool force) client->server_connection_cb( client, CRAS_CONN_STATUS_FAILED, client->server_connection_user_arg); - else if (client->server_err_cb) - client->server_err_cb( - client, client->server_connection_user_arg); break; case CRAS_SOCKET_STATE_WAIT_FOR_SOCKET: case CRAS_SOCKET_STATE_WAIT_FOR_WRITABLE: @@ -1381,7 +1382,8 @@ static int stream_connected(struct client_stream *stream, const struct cras_client_stream_connected *msg, const int stream_fds[2], const unsigned int num_fds) { - int rc, i; + int rc, samples_prot; + unsigned int i; struct cras_audio_format mfmt; struct cras_shm_info header_info, samples_info; @@ -1406,7 +1408,14 @@ static int stream_connected(struct client_stream *stream, goto err_ret; } - rc = cras_audio_shm_create(&header_info, &samples_info, &stream->shm); + samples_prot = 0; + if (stream->direction == CRAS_STREAM_OUTPUT) + samples_prot = PROT_WRITE; + else + samples_prot = PROT_READ; + + rc = cras_audio_shm_create(&header_info, &samples_info, samples_prot, + &stream->shm); if (rc < 0) { syslog(LOG_ERR, "cras_client: Error configuring shm"); goto err_ret; @@ -1434,6 +1443,8 @@ static int send_connect_message(struct cras_client *client, int rc; struct cras_connect_message serv_msg; int sock[2] = { -1, -1 }; + int fds[2] = { -1, -1 }; + unsigned int num_fds; /* Create a socket pair for the server to notify of audio events. */ rc = socketpair(AF_UNIX, SOCK_STREAM, 0, sock); @@ -1443,14 +1454,21 @@ static int send_connect_message(struct cras_client *client, goto fail; } - cras_fill_connect_message(&serv_msg, stream->config->direction, - stream->id, stream->config->stream_type, - stream->config->buffer_frames, - stream->config->cb_threshold, stream->flags, - stream->config->effects, - stream->config->format, dev_idx); + cras_fill_connect_message( + &serv_msg, stream->config->direction, stream->id, + stream->config->stream_type, stream->config->client_type, + stream->config->buffer_frames, stream->config->cb_threshold, + stream->flags, stream->config->effects, stream->config->format, + dev_idx, stream->config->client_shm_size); + + fds[0] = sock[1]; + num_fds = 1; + if (stream->config->client_shm_fd >= 0) { + fds[1] = stream->config->client_shm_fd; + num_fds++; + } rc = cras_send_with_fds(client->server_fd, &serv_msg, sizeof(serv_msg), - &sock[1], 1); + fds, num_fds); if (rc != sizeof(serv_msg)) { rc = EIO; syslog(LOG_ERR, @@ -1460,6 +1478,8 @@ static int send_connect_message(struct cras_client *client, stream->aud_fd = sock[0]; close(sock[1]); + if (stream->config->client_shm_fd != -1) + close(stream->config->client_shm_fd); return 0; fail: @@ -1467,6 +1487,8 @@ fail: close(sock[0]); if (sock[1] != -1) close(sock[1]); + if (stream->config->client_shm_fd != -1) + close(stream->config->client_shm_fd); return rc; } @@ -1580,6 +1602,14 @@ static int client_thread_set_stream_volume(struct cras_client *client, return 0; } +/* Attach to the shm region containing the audio thread log. */ +static void attach_atlog_shm(struct cras_client *client, int fd) +{ + client->atlog_ro = (struct audio_thread_event_log *)mmap( + NULL, sizeof(*client->atlog_ro), PROT_READ, MAP_SHARED, fd, 0); + close(fd); +} + /* Attach to the shm region containing the server state. */ static int client_attach_shm(struct cras_client *client, int shm_fd) { @@ -1691,6 +1721,14 @@ static int handle_message_from_server(struct cras_client *client) client->debug_info_callback(client); client->debug_info_callback = NULL; break; + case CRAS_CLIENT_ATLOG_FD_READY: + if (num_fds != 1 || server_fds[0] < 0) + return -EINVAL; + attach_atlog_shm(client, server_fds[0]); + if (client->atlog_access_callback) + client->atlog_access_callback(client); + client->atlog_access_callback = NULL; + break; case CRAS_CLIENT_GET_HOTWORD_MODELS_READY: { struct cras_client_get_hotword_models_ready *cmsg = (struct cras_client_get_hotword_models_ready *)msg; @@ -2026,25 +2064,44 @@ static int write_message_to_server(struct cras_client *client, return 0; } +/* Fills server socket file to connect by client's connection type. */ +static int fill_socket_file(struct cras_client *client, + enum CRAS_CONNECTION_TYPE conn_type) +{ + int rc; + + client->sock_file = + (const char *)calloc(CRAS_MAX_SOCKET_PATH_SIZE, sizeof(char)); + if (client->sock_file == NULL) + return -ENOMEM; + + rc = cras_fill_socket_path(conn_type, (char *)client->sock_file); + if (rc < 0) { + free((void *)client->sock_file); + return rc; + } + return 0; +} + /* * Exported Client Interface */ -int cras_client_create(struct cras_client **client) +int cras_client_create_with_type(struct cras_client **client, + enum CRAS_CONNECTION_TYPE conn_type) { - const char *sock_dir; - size_t sock_file_size; int rc; struct client_int *client_int; pthread_condattr_t cond_attr; + if (!cras_validate_connection_type(conn_type)) { + syslog(LOG_ERR, "Input connection type is not supported.\n"); + return -EINVAL; + } + /* Ignore SIGPIPE while using this API. */ signal(SIGPIPE, SIG_IGN); - sock_dir = cras_config_get_system_socket_file_dir(); - if (!sock_dir) - return -ENOMEM; - client_int = (struct client_int *)calloc(1, sizeof(*client_int)); if (!client_int) return -ENOMEM; @@ -2083,22 +2140,19 @@ int cras_client_create(struct cras_client **client) goto free_cond; } - sock_file_size = strlen(sock_dir) + strlen(CRAS_SOCKET_FILE) + 2; - (*client)->sock_file = (const char *)malloc(sock_file_size); - if (!(*client)->sock_file) { - rc = -ENOMEM; + rc = fill_socket_file((*client), conn_type); + if (rc < 0) { goto free_error; } - snprintf((char *)(*client)->sock_file, sock_file_size, "%s/%s", - sock_dir, CRAS_SOCKET_FILE); rc = cras_file_wait_create((*client)->sock_file, CRAS_FILE_WAIT_FLAG_NONE, sock_file_wait_callback, *client, &(*client)->sock_file_wait); - if (rc != 0 && rc != -ENOENT) { - syslog(LOG_ERR, "cras_client: Could not setup watch for '%s'.", - (*client)->sock_file); + if (rc < 0 && rc != -ENOENT) { + syslog(LOG_ERR, + "cras_client: Could not setup watch for '%s': %s", + (*client)->sock_file, strerror(-rc)); goto free_error; } (*client)->sock_file_exists = (rc == 0); @@ -2137,6 +2191,11 @@ free_client: return rc; } +int cras_client_create(struct cras_client **client) +{ + return cras_client_create_with_type(client, CRAS_CONTROL); +} + void cras_client_destroy(struct cras_client *client) { struct client_int *client_int; @@ -2144,7 +2203,6 @@ void cras_client_destroy(struct cras_client *client) return; client_int = to_client_int(client); client->server_connection_cb = NULL; - client->server_err_cb = NULL; cras_client_stop(client); server_disconnect(client); close(client->server_event_fd); @@ -2196,15 +2254,24 @@ struct cras_stream_params *cras_client_stream_params_create( params->cb_threshold = cb_threshold; params->effects = 0; params->stream_type = stream_type; + params->client_type = CRAS_CLIENT_TYPE_UNKNOWN; params->flags = flags; params->user_data = user_data; params->aud_cb = aud_cb; params->unified_cb = 0; params->err_cb = err_cb; + params->client_shm_fd = -1; + params->client_shm_size = 0; memcpy(&(params->format), format, sizeof(*format)); return params; } +void cras_client_stream_params_set_client_type( + struct cras_stream_params *params, enum CRAS_CLIENT_TYPE client_type) +{ + params->client_type = client_type; +} + void cras_client_stream_params_enable_aec(struct cras_stream_params *params) { params->effects |= APM_ECHO_CANCELLATION; @@ -2245,6 +2312,14 @@ void cras_client_stream_params_disable_vad(struct cras_stream_params *params) params->effects &= ~APM_VOICE_DETECTION; } +void cras_client_stream_params_configure_client_shm( + struct cras_stream_params *params, int client_shm_fd, + size_t client_shm_size) +{ + params->client_shm_fd = client_shm_fd; + params->client_shm_size = client_shm_size; +} + struct cras_stream_params *cras_client_unified_params_create( enum CRAS_STREAM_DIRECTION direction, unsigned int block_size, enum CRAS_STREAM_TYPE stream_type, uint32_t flags, void *user_data, @@ -2261,12 +2336,15 @@ struct cras_stream_params *cras_client_unified_params_create( params->buffer_frames = block_size * 2; params->cb_threshold = block_size; params->stream_type = stream_type; + params->client_type = CRAS_CLIENT_TYPE_UNKNOWN; params->flags = flags; params->effects = 0; params->user_data = user_data; params->aud_cb = 0; params->unified_cb = unified_cb; params->err_cb = err_cb; + params->client_shm_fd = -1; + params->client_shm_size = 0; memcpy(&(params->format), format, sizeof(*format)); return params; @@ -2696,14 +2774,6 @@ int cras_client_stop(struct cras_client *client) return 0; } -void cras_client_set_server_error_cb(struct cras_client *client, - cras_server_error_cb_t err_cb, - void *user_arg) -{ - client->server_err_cb = err_cb; - client->server_connection_user_arg = user_arg; -} - void cras_client_set_connection_status_cb( struct cras_client *client, cras_connection_status_cb_t connection_cb, void *user_arg) @@ -3066,6 +3136,78 @@ int cras_client_update_audio_debug_info( return write_message_to_server(client, &msg.header); } +int cras_client_get_atlog_access(struct cras_client *client, + void (*atlog_access_cb)(struct cras_client *)) +{ + struct cras_get_atlog_fd msg; + + if (client == NULL) + return -EINVAL; + + if (client->atlog_access_callback != NULL) + return -EINVAL; + client->atlog_access_callback = atlog_access_cb; + + cras_fill_get_atlog_fd(&msg); + return write_message_to_server(client, &msg.header); +} + +int cras_client_read_atlog(struct cras_client *client, uint64_t *read_idx, + uint64_t *missing, + struct audio_thread_event_log *buf) +{ + struct audio_thread_event_log log; + uint64_t i, sync_write_pos, len = 0; + struct timespec timestamp, last_timestamp; + + if (!client->atlog_ro) + return -EINVAL; + + sync_write_pos = client->atlog_ro->sync_write_pos; + __sync_synchronize(); + memcpy(&log, client->atlog_ro, sizeof(log)); + + if (sync_write_pos <= *read_idx) + return 0; + + *missing = 0; + for (i = sync_write_pos - 1; i >= *read_idx; --i) { + uint64_t pos = i % log.len; + timestamp.tv_sec = log.log[pos].tag_sec & 0x00ffffff; + timestamp.tv_nsec = log.log[pos].nsec; + + if (i != sync_write_pos - 1 && + timespec_after(×tamp, &last_timestamp)) { + if (*read_idx) + *missing = i - *read_idx + 1; + *read_idx = i + 1; + break; + } + last_timestamp = timestamp; + + if (!i) + break; + } + + /* Copies the continuous part of log. */ + if ((sync_write_pos - 1) % log.len < *read_idx % log.len) { + len = log.len - *read_idx % log.len; + memcpy(buf->log, &log.log[*read_idx % log.len], + sizeof(struct audio_thread_event) * len); + memcpy(&buf->log[len], log.log, + sizeof(struct audio_thread_event) * + ((sync_write_pos - 1) % log.len + 1)); + len = sync_write_pos - *read_idx; + } else { + len = sync_write_pos - *read_idx; + memcpy(buf->log, &log.log[*read_idx % log.len], + sizeof(struct audio_thread_event) * len); + } + + *read_idx = sync_write_pos; + return len; +} + int cras_client_update_bt_debug_info( struct cras_client *client, void (*debug_info_cb)(struct cras_client *)) { @@ -3315,7 +3457,7 @@ int cras_client_get_aec_group_id(struct cras_client *client) return aec_group_id; } -int cras_client_set_bt_wbs_enabled(struct cras_client * client, bool enabled) +int cras_client_set_bt_wbs_enabled(struct cras_client *client, bool enabled) { struct cras_set_bt_wbs_enabled msg; diff --git a/cras/src/libcras/cras_client.h b/cras/src/libcras/cras_client.h index 245b0dea..7012e2df 100644 --- a/cras/src/libcras/cras_client.h +++ b/cras/src/libcras/cras_client.h @@ -115,24 +115,6 @@ typedef int (*cras_error_cb_t)(struct cras_client *client, cras_stream_id_t stream_id, int error, void *user_arg); -/* Callback for handling server error. DEPRECATED - * - * Deprecated by cras_server_connection_status_cb_t: use that instead. - * This is equivalent to CRAS_CONN_STATUS_FAILED. - * - * This callback is executed rarely: only when the connection to the server has - * already been interrupted and could not be re-established due to resource - * allocation failure (memory or file-descriptors). The caller may attempt - * to reestablish communication once those resources are available with - * cras_client_connect_async(), or (blocking) cras_client_connect(). - * - * Args: - * client - The client created with cras_client_create(). - * user_arg - The argument defined in cras_client_set_server_errro_cb(). - */ -typedef void (*cras_server_error_cb_t)(struct cras_client *client, - void *user_arg); - /* Server connection status. */ typedef enum cras_connection_status { CRAS_CONN_STATUS_FAILED, @@ -198,6 +180,18 @@ typedef int (*cras_hotword_error_cb_t)(struct cras_client *client, */ int cras_client_create(struct cras_client **client); +/* Creates a new client with given connection type. + * Args: + * client - Filled with a pointer to the new client. + * conn_type - enum CRAS_CONNECTION_TYPE + * + * Returns: + * 0 on success (*client is filled with a valid cras_client pointer). + * Negative error code on failure(*client will be NULL). + */ +int cras_client_create_with_type(struct cras_client **client, + enum CRAS_CONNECTION_TYPE conn_type); + /* Destroys a client. * Args: * client - returned from "cras_client_create". @@ -276,19 +270,6 @@ int cras_client_connected_wait(struct cras_client *client); */ int cras_client_connect_async(struct cras_client *client); -/* Sets server error callback. DEPRECATED - * - * See cras_server_error_cb_t for more information about this callback. - * - * Args: - * client - The client from cras_client_create. - * err_cb - The callback function to register. - * user_arg - Pointer that will be passed to the callback. - */ -void cras_client_set_server_error_cb(struct cras_client *client, - cras_server_error_cb_t err_cb, - void *user_arg); - /* Sets server connection status callback. * * See cras_connection_status_t for a description of the connection states @@ -501,11 +482,38 @@ int cras_client_update_audio_debug_info(struct cras_client *client, * client - The client from cras_client_create. * cb - Function to call when debug info is ready. * Returns: - * 0 on sucess, -EINVAL if the client isn't valid or isn't running. + * 0 on success, -EINVAL if the client isn't valid or isn't running. */ int cras_client_update_bt_debug_info(struct cras_client *client, void (*cb)(struct cras_client *)); +/* Gets read-only access to audio thread log. Should be called once before + calling cras_client_read_atlog. + * Args: + * client - The client from cras_client_create. + * atlog_access_cb - Function to call after getting atlog access. + * Returns: + * 0 on success, -EINVAL if the client or atlog_access_cb isn't valid. + */ +int cras_client_get_atlog_access(struct cras_client *client, + void (*atlog_access_cb)(struct cras_client *)); + +/* Reads continuous audio thread log into 'buf', starting from 'read_idx'-th log + * till the latest. The number of missing logs within the range will be stored + * in 'missing'. Requires calling cras_client_get_atlog_access() beforehand + * to get access to audio thread log. + * Args: + * client - The client from cras_client_create. + * read_idx - The log number to start reading with. + * missing - The pointer to store the number of missing logs. + * buf - The buffer to which continuous logs will be copied. + * Returns: + * The number of logs copied. < 0 if failed to read audio thread log. + */ +int cras_client_read_atlog(struct cras_client *client, uint64_t *read_idx, + uint64_t *missing, + struct audio_thread_event_log *buf); + /* Asks the server to dump current audio thread snapshots. * * Args: @@ -544,6 +552,14 @@ struct cras_stream_params *cras_client_stream_params_create( uint32_t flags, void *user_data, cras_playback_cb_t aud_cb, cras_error_cb_t err_cb, struct cras_audio_format *format); +/* Functions to set the client type on given stream parameter. + * Args: + * params - Stream configuration parameters. + * client_type - A client type. + */ +void cras_client_stream_params_set_client_type( + struct cras_stream_params *params, enum CRAS_CLIENT_TYPE client_type); + /* Functions to enable or disable specific effect on given stream parameter. * Args: * params - Stream configuration parameters. @@ -557,6 +573,16 @@ void cras_client_stream_params_disable_agc(struct cras_stream_params *params); void cras_client_stream_params_enable_vad(struct cras_stream_params *params); void cras_client_stream_params_disable_vad(struct cras_stream_params *params); +/* Function to setup client-provided shm to be used as the backing shm for the + * samples area in the cras_audio_shm shared with cras. + * Args: + * client_shm_fd - shm fd to use for samples shm area. + * client_shm_size - size of shm area backed by 'client_shm_fd'. + */ +void cras_client_stream_params_configure_client_shm( + struct cras_stream_params *params, int client_shm_fd, + size_t client_shm_size); + /* Setup stream configuration parameters. DEPRECATED. * TODO(crbug.com/972928): remove this * Use cras_client_stream_params_create instead. @@ -1132,7 +1158,7 @@ int cras_client_get_aec_group_id(struct cras_client *client); /* * Sets the flag to enable bluetooth wideband speech in server. */ -int cras_client_set_bt_wbs_enabled(struct cras_client * client, bool enabled); +int cras_client_set_bt_wbs_enabled(struct cras_client *client, bool enabled); /* Set the context pointer for system state change callbacks. * Args: @@ -1297,7 +1323,6 @@ int cras_client_set_input_node_gain_changed_callback( int cras_client_set_num_active_streams_changed_callback( struct cras_client *client, cras_client_num_active_streams_changed_callback cb); - #ifdef __cplusplus } #endif diff --git a/cras/src/plc/cras_plc.c b/cras/src/plc/cras_plc.c new file mode 100644 index 00000000..ed42ae97 --- /dev/null +++ b/cras/src/plc/cras_plc.c @@ -0,0 +1,220 @@ +/* Copyright 2019 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <float.h> +#include <math.h> +#include <stdlib.h> +#include <string.h> +#include <stdio.h> + +#include "cras_plc.h" + +#define MSBC_SAMPLE_SIZE 2 /* 2 bytes*/ +#define MSBC_PKT_LEN 57 /* Packet length without the header */ +#define MSBC_FS 120 /* Frame Size */ +#define MSBC_CODE_SIZE 240 /* MSBC_SAMPLE_SIZE * MSBC_FS */ + +#define PLC_WL 256 /* 16ms - Window Length for pattern matching */ +#define PLC_TL 64 /* 4ms - Template Length for matching */ +#define PLC_HL (PLC_WL + MSBC_FS - 1) /* Length of History buffer required */ +#define PLC_SBCRL 36 /* SBC Reconvergence sample Length */ +#define PLC_OLAL 16 /* OverLap-Add Length */ + +/* The pre-computed zero input bit stream of mSBC codec, per HFP 1.7 spec. + * This mSBC frame will be decoded into all-zero input PCM. */ +static const uint8_t msbc_zero_frame[] = { + 0xad, 0x00, 0x00, 0xc5, 0x00, 0x00, 0x00, 0x00, 0x77, 0x6d, 0xb6, 0xdd, + 0xdb, 0x6d, 0xb7, 0x76, 0xdb, 0x6d, 0xdd, 0xb6, 0xdb, 0x77, 0x6d, 0xb6, + 0xdd, 0xdb, 0x6d, 0xb7, 0x76, 0xdb, 0x6d, 0xdd, 0xb6, 0xdb, 0x77, 0x6d, + 0xb6, 0xdd, 0xdb, 0x6d, 0xb7, 0x76, 0xdb, 0x6d, 0xdd, 0xb6, 0xdb, 0x77, + 0x6d, 0xb6, 0xdd, 0xdb, 0x6d, 0xb7, 0x76, 0xdb, 0x6c +}; + +/* Raised Cosine table for OLA */ +static const float rcos[PLC_OLAL] = { 0.99148655f, 0.96623611f, 0.92510857f, + 0.86950446f, 0.80131732f, 0.72286918f, + 0.63683150f, 0.54613418f, 0.45386582f, + 0.36316850f, 0.27713082f, 0.19868268f, + 0.13049554f, 0.07489143f, 0.03376389f, + 0.00851345f }; + +/* The PLC is specifically designed for mSBC. The algorithm searches the + * history of receiving samples to find the best match samples and constructs + * substitutions for the lost samples. The selection is based on pattern + * matching a template, composed of a length of samples preceding to the lost + * samples. It then uses the following samples after the best match as the + * replacement samples and applies Overlap-Add to reduce the audible + * distortion. + * + * This structure holds related info needed to conduct the PLC algorithm. + * Members: + * hist - The history buffer for receiving samples, we also use it to + * buffer the processed replacement samples. + * best_lag - The index of the best substitution samples in sample history. + * handled_bad_frames - Number of bad frames handled since the last good + * frame. + * zero_frame - A buffer used for storing the samples from decoding the + * mSBC zero frame packet. + */ +struct cras_msbc_plc { + int16_t hist[PLC_HL + MSBC_FS + PLC_SBCRL + PLC_OLAL]; + unsigned int best_lag; + int handled_bad_frames; + int16_t zero_frame[MSBC_FS]; +}; + +struct cras_msbc_plc *cras_msbc_plc_create() +{ + struct cras_msbc_plc *plc = + (struct cras_msbc_plc *)calloc(1, sizeof(*plc)); + return plc; +} + +void cras_msbc_plc_destroy(struct cras_msbc_plc *plc) +{ + free(plc); +} + +static int16_t f_to_s16(float input) +{ + return input > INT16_MAX ? + INT16_MAX : + input < INT16_MIN ? INT16_MIN : (int16_t)input; +} + +void overlap_add(int16_t *output, float scaler_d, const int16_t *desc, + float scaler_a, const int16_t *asc) +{ + for (int i = 0; i < PLC_OLAL; i++) { + output[i] = + f_to_s16(scaler_d * desc[i] * rcos[i] + + scaler_a * asc[i] * rcos[PLC_OLAL - 1 - i]); + } +} + +int cras_msbc_plc_handle_good_frames(struct cras_msbc_plc *state, + const uint8_t *input, uint8_t *output) +{ + int16_t *frame_head, *input_samples, *output_samples; + if (state->handled_bad_frames == 0) { + /* If there was no packet loss before this good frame, there + * is nothing we need to do to the frame so we'll just pass + * the input to output. + */ + memmove(output, input, MSBC_FS * MSBC_SAMPLE_SIZE); + } else { + frame_head = &state->hist[PLC_HL]; + input_samples = (int16_t *)input; + output_samples = (int16_t *)output; + + /* For the first good frame after packet loss, we need to + * conceal the received samples to have it reconverge with the + * true output. + */ + memcpy(output_samples, frame_head, + PLC_SBCRL * MSBC_SAMPLE_SIZE); + overlap_add(&output_samples[PLC_SBCRL], 1.0, + &frame_head[PLC_SBCRL], 1.0, + &input_samples[PLC_SBCRL]); + memmove(&output_samples[PLC_SBCRL + PLC_OLAL], + &input_samples[PLC_SBCRL + PLC_OLAL], + (MSBC_FS - PLC_SBCRL - PLC_OLAL) * MSBC_SAMPLE_SIZE); + state->handled_bad_frames = 0; + } + + /* Shift the history and update the good frame to the end of it. */ + memmove(state->hist, &state->hist[MSBC_FS], + (PLC_HL - MSBC_FS) * MSBC_SAMPLE_SIZE); + memcpy(&state->hist[PLC_HL - MSBC_FS], output, + MSBC_FS * MSBC_SAMPLE_SIZE); + return MSBC_CODE_SIZE; +} + +float cross_correlation(int16_t *x, int16_t *y) +{ + float sum = 0, x2 = 0, y2 = 0; + + for (int i = 0; i < PLC_TL; i++) { + sum += ((float)x[i]) * y[i]; + x2 += ((float)x[i]) * x[i]; + y2 += ((float)y[i]) * y[i]; + } + return sum / sqrt(x2 * y2); +} + +int pattern_match(int16_t *hist) +{ + int best = 0; + float cn, max_cn = FLT_MIN; + + for (int i = 0; i < PLC_WL; i++) { + cn = cross_correlation(&hist[PLC_HL - PLC_TL], &hist[i]); + if (cn > max_cn) { + best = i; + max_cn = cn; + } + } + return best; +} + +float amplitude_match(int16_t *x, int16_t *y) +{ + uint32_t sum_x = 0, sum_y = 0; + float scaler; + for (int i = 0; i < MSBC_FS; i++) { + sum_x += abs(x[i]); + sum_y += abs(y[i]); + } + + if (sum_y == 0) + return 1.2f; + + scaler = (float)sum_x / sum_y; + return scaler > 1.2f ? 1.2f : scaler < 0.75f ? 0.75f : scaler; +} + +int cras_msbc_plc_handle_bad_frames(struct cras_msbc_plc *state, + struct cras_audio_codec *codec, + uint8_t *output) +{ + float scaler; + int16_t *best_match_hist; + int16_t *frame_head = &state->hist[PLC_HL]; + size_t pcm_decoded = 0; + + codec->decode(codec, msbc_zero_frame, MSBC_PKT_LEN, state->zero_frame, + MSBC_FS, &pcm_decoded); + + if (state->handled_bad_frames == 0) { + /* Finds the best matching samples and amplitude */ + state->best_lag = pattern_match(state->hist) + PLC_TL; + best_match_hist = &state->hist[state->best_lag]; + scaler = amplitude_match(&state->hist[PLC_HL - MSBC_FS], + best_match_hist); + + /* Constructs the substitution samples */ + overlap_add(frame_head, 1.0, state->zero_frame, scaler, + best_match_hist); + for (int i = PLC_OLAL; i < MSBC_FS; i++) + state->hist[PLC_HL + i] = + f_to_s16(scaler * best_match_hist[i]); + overlap_add(&frame_head[MSBC_FS], scaler, + &best_match_hist[MSBC_FS], 1.0, + &best_match_hist[MSBC_FS]); + + memmove(&frame_head[MSBC_FS + PLC_OLAL], + &best_match_hist[MSBC_FS + PLC_OLAL], + PLC_SBCRL * MSBC_SAMPLE_SIZE); + } else { + memmove(frame_head, &state->hist[state->best_lag], + (MSBC_FS + PLC_SBCRL + PLC_OLAL) * MSBC_SAMPLE_SIZE); + } + state->handled_bad_frames++; + + memcpy(output, frame_head, MSBC_CODE_SIZE); + memmove(state->hist, &state->hist[MSBC_FS], + (PLC_HL + PLC_SBCRL + PLC_OLAL) * MSBC_SAMPLE_SIZE); + return MSBC_CODE_SIZE; +} diff --git a/cras/src/plc/cras_plc.h b/cras/src/plc/cras_plc.h new file mode 100644 index 00000000..ccde8bbe --- /dev/null +++ b/cras/src/plc/cras_plc.h @@ -0,0 +1,54 @@ +/* Copyright 2019 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <stdint.h> + +#include "cras_audio_codec.h" + +/* PLC library provides helper functions to mask the effects of lost or + * disrupted packets. It currentyl only supports the mSBC codec. + * + * This struct contains informations needed for applying the PLC algorithm. + */ +struct cras_msbc_plc; + +/* Creates a plc component for mSBC codec, which is used for wideband speech + * mode of HFP + */ +struct cras_msbc_plc *cras_msbc_plc_create(); + +/* Destroys a mSBC PLC. + * Args: + * plc - The PLC to destroy. + */ +void cras_msbc_plc_destroy(struct cras_msbc_plc *plc); + +/* Conceals the packet loss by writing the substitution samples to the ouput + * buffer provided by the caller. The samples will be generated based on the + * informations recorded in the PLC struct passed in. + * Args: + * plc - The PLC you use. + * codec - The mSBC codec. + * output - Pointer to the output buffer. + * Returns: + * The number of bytes written to the output buffer. + */ +int cras_msbc_plc_handle_bad_frames(struct cras_msbc_plc *plc, + struct cras_audio_codec *codec, + uint8_t *output); + +/* Updates informations needed and potentially processes the input samples to + * help it to reconverge after a frame loss. + * + * The memory space input and output pointers point to can be overlapping. + * Args: + * plc - The PLC you use. + * input - Pointer to the true input. + * output - Pointer to the output buffer. + * Returns: + * The number of bytes written to the output buffer. + */ +int cras_msbc_plc_handle_good_frames(struct cras_msbc_plc *plc, + const uint8_t *input, uint8_t *output); diff --git a/cras/src/plc/cras_plc_test.c b/cras/src/plc/cras_plc_test.c new file mode 100644 index 00000000..458f1254 --- /dev/null +++ b/cras/src/plc/cras_plc_test.c @@ -0,0 +1,135 @@ +/* Copyright 2019 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <errno.h> +#include <math.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> + +#include "cras_sbc_codec.h" +#include "cras_plc.h" + +#define MSBC_CODE_SIZE 240 +#define MSBC_PKT_FRAME_LEN 57 +#define RND_SEED 7 + +static const uint8_t msbc_zero_frame[] = { + 0xad, 0x00, 0x00, 0xc5, 0x00, 0x00, 0x00, 0x00, 0x77, 0x6d, 0xb6, 0xdd, + 0xdb, 0x6d, 0xb7, 0x76, 0xdb, 0x6d, 0xdd, 0xb6, 0xdb, 0x77, 0x6d, 0xb6, + 0xdd, 0xdb, 0x6d, 0xb7, 0x76, 0xdb, 0x6d, 0xdd, 0xb6, 0xdb, 0x77, 0x6d, + 0xb6, 0xdd, 0xdb, 0x6d, 0xb7, 0x76, 0xdb, 0x6d, 0xdd, 0xb6, 0xdb, 0x77, + 0x6d, 0xb6, 0xdd, 0xdb, 0x6d, 0xb7, 0x76, 0xdb, 0x6c +}; + +bool *generate_pl_seq(unsigned pk_count, unsigned loss_count) +{ + bool *seq = (bool *)calloc(pk_count, sizeof(*seq)); + srand(RND_SEED); + while (loss_count > 0) { + bool *missed = &seq[rand() % pk_count]; + if (!*missed) { + *missed = true; + loss_count--; + } + } + return seq; +} + +void plc_experiment(char *input_filename, float pl_percent, bool with_plc) +{ + char output_filename[255]; + int input_fd, output_fd, rc; + struct stat st; + bool *pl_seq; + struct cras_audio_codec *msbc_input = cras_msbc_codec_create(); + struct cras_audio_codec *msbc_output = cras_msbc_codec_create(); + struct cras_msbc_plc *plc = cras_msbc_plc_create(); + uint8_t buffer[MSBC_CODE_SIZE], packet_buffer[MSBC_PKT_FRAME_LEN]; + size_t encoded, decoded; + unsigned pk_count, pl_count, count = 0; + + input_fd = open(input_filename, O_RDONLY); + if (input_fd == -1) { + fprintf(stderr, "Cannout open input file %s\n", input_filename); + return; + } + + if (with_plc) + sprintf(output_filename, "output_%2.2f_plc.raw", pl_percent); + else + sprintf(output_filename, "output_%2.2f_zero.raw", pl_percent); + + output_fd = open(output_filename, O_CREAT | O_RDWR | O_TRUNC, 0644); + if (output_fd == -1) { + fprintf(stderr, "Cannot open output file %s\n", + output_filename); + return; + } + + fstat(input_fd, &st); + pk_count = st.st_size / MSBC_CODE_SIZE; + pl_count = pk_count * (pl_percent / 100.0); + pl_seq = generate_pl_seq(pk_count, pl_count); + + while (1) { + rc = read(input_fd, buffer, MSBC_CODE_SIZE); + if (rc < 0) { + fprintf(stderr, "Cannot read file %s", input_filename); + return; + } else if (rc == 0 || rc < MSBC_CODE_SIZE) + break; + + msbc_input->encode(msbc_input, buffer, MSBC_CODE_SIZE, + packet_buffer, MSBC_PKT_FRAME_LEN, &encoded); + + if (pl_seq[count]) { + if (with_plc) { + cras_msbc_plc_handle_bad_frames( + plc, msbc_output, buffer); + decoded = MSBC_CODE_SIZE; + } else + msbc_output->decode(msbc_output, + msbc_zero_frame, + MSBC_PKT_FRAME_LEN, buffer, + MSBC_CODE_SIZE, &decoded); + } else { + msbc_output->decode(msbc_output, packet_buffer, + MSBC_PKT_FRAME_LEN, buffer, + MSBC_CODE_SIZE, &decoded); + cras_msbc_plc_handle_good_frames(plc, buffer, buffer); + } + + count++; + rc = write(output_fd, buffer, decoded); + if (rc < 0) { + fprintf(stderr, "Cannot write file %s\n", + output_filename); + return; + } + } +} + +int main(int argc, char **argv) +{ + if (argc != 3) { + printf("Usage: cras_plc_test input.raw pl_percentage\n" + "This test only supports reading/writing files with " + "format:\n" + "- raw pcm\n" + "- 16000 sample rate\n" + "- mono channel\n" + "- S16_LE sample format\n"); + return 1; + } + + plc_experiment(argv[1], atof(argv[2]), true); + plc_experiment(argv[1], atof(argv[2]), false); +} diff --git a/cras/src/server/audio_thread.c b/cras/src/server/audio_thread.c index 0acf7ef3..d7ef8bd6 100644 --- a/cras/src/server/audio_thread.c +++ b/cras/src/server/audio_thread.c @@ -4,12 +4,13 @@ */ #ifndef _GNU_SOURCE -#define _GNU_SOURCE /* for ppoll */ +#define _GNU_SOURCE /* for ppoll and asprintf*/ #endif #include <pthread.h> #include <poll.h> #include <stdbool.h> +#include <stdio.h> #include <sys/param.h> #include <syslog.h> @@ -20,6 +21,7 @@ #include "cras_fmt_conv.h" #include "cras_iodev.h" #include "cras_rstream.h" +#include "cras_server_metrics.h" #include "cras_system_state.h" #include "cras_types.h" #include "cras_util.h" @@ -102,11 +104,16 @@ struct audio_thread_aec_dump_msg { int fd; }; -/* Audio thread logging. */ +/* Audio thread logging. If atlog is successfully created from cras_shm_setup, + * then the fds should have valid value. Or audio thread will fallback to use + * calloc to create atlog and leave the fds as -1. + */ struct audio_thread_event_log *atlog; +char *atlog_name; +int atlog_rw_shm_fd; +int atlog_ro_shm_fd; static struct iodev_callback_list *iodev_callbacks; -static struct timespec longest_wake; struct iodev_callback_list { int fd; @@ -500,6 +507,8 @@ static void append_dev_dump_info(struct audio_dev_debug_info *di, subtract_timespecs(&now, &adev->dev->open_ts, &time_since); di->runtime_sec = time_since.tv_sec; di->runtime_nsec = time_since.tv_nsec; + di->longest_wake_sec = adev->longest_wake.tv_sec; + di->longest_wake_nsec = adev->longest_wake.tv_nsec; if (fmt) { di->frame_rate = fmt->frame_rate; @@ -526,6 +535,7 @@ static void append_stream_dump_info(struct audio_debug_info *info, si->dev_idx = dev_idx; si->direction = stream->stream->direction; si->stream_type = stream->stream->stream_type; + si->client_type = stream->stream->client_type; si->buffer_frames = stream->stream->buffer_frames; si->cb_threshold = stream->stream->cb_threshold; si->frame_rate = stream->stream->format.frame_rate; @@ -545,9 +555,6 @@ static void append_stream_dump_info(struct audio_debug_info *info, subtract_timespecs(&now, &stream->stream->start_ts, &time_since); si->runtime_sec = time_since.tv_sec; si->runtime_nsec = time_since.tv_nsec; - - longest_wake.tv_sec = 0; - longest_wake.tv_nsec = 0; } /* Handle a message sent to the playback thread */ @@ -755,13 +762,40 @@ static struct pollfd *add_pollfd(struct audio_thread *thread, int fd, } static int continuous_zero_sleep_count = 0; +static unsigned busyloop_count = 0; + +/* + * Logs the number of busyloop during one audio thread running state + * (wait_ts != NULL). + */ +static void log_busyloop(struct timespec *wait_ts) +{ + static struct timespec start_time; + static bool started = false; + struct timespec diff, now; + + /* If wait_ts is NULL, there is no stream running. */ + if (wait_ts && !started) { + started = true; + busyloop_count = 0; + clock_gettime(CLOCK_MONOTONIC_RAW, &start_time); + } else if (!wait_ts && started) { + started = false; + clock_gettime(CLOCK_MONOTONIC_RAW, &now); + subtract_timespecs(&now, &start_time, &diff); + cras_server_metrics_busyloop(&diff, busyloop_count); + } +} + static void check_busyloop(struct timespec *wait_ts) { if (wait_ts->tv_sec == 0 && wait_ts->tv_nsec == 0) { continuous_zero_sleep_count++; if (continuous_zero_sleep_count == - MAX_CONTINUOUS_ZERO_SLEEP_COUNT) - cras_audio_thread_busyloop(); + MAX_CONTINUOUS_ZERO_SLEEP_COUNT) { + busyloop_count++; + cras_audio_thread_event_busyloop(); + } } else { continuous_zero_sleep_count = 0; } @@ -779,7 +813,7 @@ static void *audio_io_thread(void *arg) struct audio_thread *thread = (struct audio_thread *)arg; struct open_dev *adev; struct dev_stream *curr; - struct timespec ts, now, last_wake; + struct timespec ts; int msg_fd; int rc; @@ -789,10 +823,6 @@ static void *audio_io_thread(void *arg) if (cras_set_rt_scheduling(CRAS_SERVER_RT_THREAD_PRIORITY) == 0) cras_set_thread_priority(CRAS_SERVER_RT_THREAD_PRIORITY); - last_wake.tv_sec = 0; - longest_wake.tv_sec = 0; - longest_wake.tv_nsec = 0; - thread->pollfds[0].fd = msg_fd; thread->pollfds[0].events = POLLIN; @@ -843,20 +873,18 @@ static void *audio_io_thread(void *arg) } } - if (last_wake.tv_sec) { - struct timespec this_wake; - clock_gettime(CLOCK_MONOTONIC_RAW, &now); - subtract_timespecs(&now, &last_wake, &this_wake); - if (timespec_after(&this_wake, &longest_wake)) - longest_wake = this_wake; - } + log_busyloop(wait_ts); ATLOG(atlog, AUDIO_THREAD_SLEEP, wait_ts ? wait_ts->tv_sec : 0, - wait_ts ? wait_ts->tv_nsec : 0, longest_wake.tv_nsec); + wait_ts ? wait_ts->tv_nsec : 0, 0); if (wait_ts) check_busyloop(wait_ts); + + /* Sync atlog with shared memory. */ + __sync_synchronize(); + atlog->sync_write_pos = atlog->write_pos; + rc = ppoll(thread->pollfds, thread->num_pollfds, wait_ts, NULL); - clock_gettime(CLOCK_MONOTONIC_RAW, &last_wake); ATLOG(atlog, AUDIO_THREAD_WAKE, rc, 0, 0); if (rc <= 0) continue; @@ -864,7 +892,7 @@ static void *audio_io_thread(void *arg) if (thread->pollfds[0].revents & POLLIN) { rc = handle_playback_thread_message(thread); if (rc < 0) - syslog(LOG_INFO, "handle message %d", rc); + syslog(LOG_ERR, "handle message %d", rc); } DL_FOREACH (iodev_callbacks, iodev_cb) { @@ -978,6 +1006,11 @@ init_device_start_ramp_msg(struct audio_thread_dev_start_ramp_msg *msg, /* Exported Interface */ +int audio_thread_event_log_shm_fd() +{ + return atlog_ro_shm_fd; +} + int audio_thread_add_stream(struct audio_thread *thread, struct cras_rstream *stream, struct cras_iodev **devs, unsigned int num_devs) @@ -1136,7 +1169,12 @@ struct audio_thread *audio_thread_create() return NULL; } - atlog = audio_thread_event_log_init(); + if (asprintf(&atlog_name, "/ATlog-%d", getpid()) < 0) { + syslog(LOG_ERR, "Failed to generate ATlog name."); + exit(-1); + } + + atlog = audio_thread_event_log_init(atlog_name); thread->pollfds_size = 32; thread->pollfds = (struct pollfd *)malloc(sizeof(*thread->pollfds) * @@ -1229,7 +1267,8 @@ void audio_thread_destroy(struct audio_thread *thread) free(thread->pollfds); - audio_thread_event_log_deinit(atlog); + audio_thread_event_log_deinit(atlog, atlog_name); + free(atlog_name); if (thread->to_thread_fds[0] != -1) { close(thread->to_thread_fds[0]); diff --git a/cras/src/server/audio_thread.h b/cras/src/server/audio_thread.h index 4685417f..5e5e9956 100644 --- a/cras/src/server/audio_thread.h +++ b/cras/src/server/audio_thread.h @@ -128,6 +128,9 @@ int audio_thread_start(struct audio_thread *thread); /* Frees an audio thread created with audio_thread_create(). */ void audio_thread_destroy(struct audio_thread *thread); +/* Returns the shm fd for the ATlog. */ +int audio_thread_event_log_shm_fd(); + /* Add a stream to the thread. After this call, the ownership of the stream will * be passed to the audio thread. Audio thread is responsible to release the * stream's resources. diff --git a/cras/src/server/audio_thread_log.h b/cras/src/server/audio_thread_log.h index 24c82fa9..ee5d159c 100644 --- a/cras/src/server/audio_thread_log.h +++ b/cras/src/server/audio_thread_log.h @@ -8,10 +8,13 @@ #ifndef AUDIO_THREAD_LOG_H_ #define AUDIO_THREAD_LOG_H_ +#include <sys/mman.h> #include <pthread.h> #include <stdint.h> +#include <syslog.h> #include "cras_types.h" +#include "cras_shm.h" #define AUDIO_THREAD_LOGGING 1 @@ -23,21 +26,46 @@ #endif extern struct audio_thread_event_log *atlog; +extern int atlog_rw_shm_fd; +extern int atlog_ro_shm_fd; -static inline struct audio_thread_event_log *audio_thread_event_log_init() +static inline struct audio_thread_event_log * +audio_thread_event_log_init(char *name) { struct audio_thread_event_log *log; - log = (struct audio_thread_event_log *)calloc( - 1, sizeof(struct audio_thread_event_log)); + + atlog_ro_shm_fd = -1; + atlog_rw_shm_fd = -1; + + log = (struct audio_thread_event_log *)cras_shm_setup( + name, sizeof(*log), &atlog_rw_shm_fd, &atlog_ro_shm_fd); + /* Fallback to calloc if device shared memory resource is empty and + * cras_shm_setup fails. + */ + if (log == NULL) { + syslog(LOG_ERR, "Failed to create atlog by cras_shm_setup"); + log = (struct audio_thread_event_log *)calloc( + 1, sizeof(struct audio_thread_event_log)); + } log->len = AUDIO_THREAD_EVENT_LOG_SIZE; return log; } static inline void -audio_thread_event_log_deinit(struct audio_thread_event_log *log) +audio_thread_event_log_deinit(struct audio_thread_event_log *log, char *name) { - free(log); + if (log) { + if (atlog_rw_shm_fd >= 0) { + munmap(log, sizeof(*log)); + cras_shm_close_unlink(name, atlog_rw_shm_fd); + } else { + free(log); + } + + if (atlog_ro_shm_fd >= 0) + close(atlog_ro_shm_fd); + } } /* Log a tag and the current time, Uses two words, the first is split @@ -49,17 +77,17 @@ audio_thread_event_log_data(struct audio_thread_event_log *log, uint32_t data2, uint32_t data3) { struct timespec now; - + uint64_t pos_mod_len = log->write_pos % AUDIO_THREAD_EVENT_LOG_SIZE; clock_gettime(CLOCK_MONOTONIC_RAW, &now); - log->log[log->write_pos].tag_sec = + + log->log[pos_mod_len].tag_sec = (event << 24) | (now.tv_sec & 0x00ffffff); - log->log[log->write_pos].nsec = now.tv_nsec; - log->log[log->write_pos].data1 = data1; - log->log[log->write_pos].data2 = data2; - log->log[log->write_pos].data3 = data3; + log->log[pos_mod_len].nsec = now.tv_nsec; + log->log[pos_mod_len].data1 = data1; + log->log[pos_mod_len].data2 = data2; + log->log[pos_mod_len].data3 = data3; log->write_pos++; - log->write_pos %= AUDIO_THREAD_EVENT_LOG_SIZE; } #endif /* AUDIO_THREAD_LOG_H_ */ diff --git a/cras/src/server/config/cras_board_config.c b/cras/src/server/config/cras_board_config.c index 0db054a8..9acdf82c 100644 --- a/cras/src/server/config/cras_board_config.c +++ b/cras/src/server/config/cras_board_config.c @@ -20,9 +20,8 @@ static const int32_t AEC_GROUP_ID_DEFAULT = -1; #define AEC_SUPPORTED_INI_KEY "processing:aec_supported" #define AEC_GROUP_ID_INI_KEY "processing:group_id" - void cras_board_config_get(const char *config_path, - struct cras_board_config *board_config) + struct cras_board_config *board_config) { char ini_name[MAX_INI_NAME_LEN + 1]; char ini_key[MAX_KEY_LEN + 1]; @@ -30,12 +29,11 @@ void cras_board_config_get(const char *config_path, board_config->default_output_buffer_size = DEFAULT_OUTPUT_BUFFER_SIZE; board_config->aec_supported = AEC_SUPPORTED_DEFAULT; - board_config->aec_group_id = AEC_GROUP_ID_DEFAULT; + board_config->aec_group_id = AEC_GROUP_ID_DEFAULT; if (config_path == NULL) return; - snprintf(ini_name, MAX_INI_NAME_LEN, "%s/%s", config_path, - CONFIG_NAME); + snprintf(ini_name, MAX_INI_NAME_LEN, "%s/%s", config_path, CONFIG_NAME); ini_name[MAX_INI_NAME_LEN] = '\0'; ini = iniparser_load_wrapper(ini_name); if (ini == NULL) { @@ -53,7 +51,7 @@ void cras_board_config_get(const char *config_path, board_config->aec_supported = iniparser_getint(ini, ini_key, AEC_SUPPORTED_DEFAULT); - snprintf(ini_key, MAX_KEY_LEN, AEC_GROUP_ID_INI_KEY); + snprintf(ini_key, MAX_KEY_LEN, AEC_GROUP_ID_INI_KEY); ini_key[MAX_KEY_LEN] = 0; board_config->aec_group_id = iniparser_getint(ini, ini_key, AEC_GROUP_ID_DEFAULT); diff --git a/cras/src/server/config/cras_board_config.h b/cras/src/server/config/cras_board_config.h index 2bd6784b..92ef971c 100644 --- a/cras/src/server/config/cras_board_config.h +++ b/cras/src/server/config/cras_board_config.h @@ -11,7 +11,7 @@ struct cras_board_config { int32_t default_output_buffer_size; int32_t aec_supported; - int32_t aec_group_id; + int32_t aec_group_id; }; /* Gets a configuration based on the config file specified. diff --git a/cras/src/server/config/cras_card_config.c b/cras/src/server/config/cras_card_config.c index c6f5edd3..f19d0855 100644 --- a/cras/src/server/config/cras_card_config.c +++ b/cras/src/server/config/cras_card_config.c @@ -18,9 +18,9 @@ struct cras_card_config { dictionary *ini; }; -static struct cras_volume_curve *create_simple_step_curve( - const struct cras_card_config *card_config, - const char *control_name) +static struct cras_volume_curve * +create_simple_step_curve(const struct cras_card_config *card_config, + const char *control_name) { char ini_key[MAX_KEY_LEN + 1]; int max_volume; @@ -36,9 +36,9 @@ static struct cras_volume_curve *create_simple_step_curve( return cras_volume_curve_create_simple_step(max_volume, volume_step); } -static struct cras_volume_curve *create_explicit_curve( - const struct cras_card_config *card_config, - const char *control_name) +static struct cras_volume_curve * +create_explicit_curve(const struct cras_card_config *card_config, + const char *control_name) { unsigned int i; char ini_key[MAX_KEY_LEN + 1]; @@ -91,8 +91,7 @@ void cras_card_config_destroy(struct cras_card_config *card_config) } struct cras_volume_curve *cras_card_config_get_volume_curve_for_control( - const struct cras_card_config *card_config, - const char *control_name) + const struct cras_card_config *card_config, const char *control_name) { char ini_key[MAX_KEY_LEN + 1]; const char *curve_type; diff --git a/cras/src/server/config/cras_card_config.h b/cras/src/server/config/cras_card_config.h index 6ec9ad1c..22ddc398 100644 --- a/cras/src/server/config/cras_card_config.h +++ b/cras/src/server/config/cras_card_config.h @@ -32,7 +32,6 @@ void cras_card_config_destroy(struct cras_card_config *card_config); * The specialized curve for the control if there is one, otherwise NULL. */ struct cras_volume_curve *cras_card_config_get_volume_curve_for_control( - const struct cras_card_config *card_config, - const char *control_name); + const struct cras_card_config *card_config, const char *control_name); #endif /* CRAS_CARD_CONFIG_H_ */ diff --git a/cras/src/server/config/cras_device_blacklist.c b/cras/src/server/config/cras_device_blacklist.c index f3000a80..1d18eb0e 100644 --- a/cras/src/server/config/cras_device_blacklist.c +++ b/cras/src/server/config/cras_device_blacklist.c @@ -19,8 +19,8 @@ struct cras_device_blacklist { * Exported Interface */ -struct cras_device_blacklist *cras_device_blacklist_create( - const char *config_path) +struct cras_device_blacklist * +cras_device_blacklist_create(const char *config_path) { struct cras_device_blacklist *blacklist; char ini_name[MAX_INI_NAME_LEN + 1]; @@ -29,8 +29,8 @@ struct cras_device_blacklist *cras_device_blacklist_create( if (!blacklist) return NULL; - snprintf(ini_name, MAX_INI_NAME_LEN, "%s/%s", - config_path, "device_blacklist"); + snprintf(ini_name, MAX_INI_NAME_LEN, "%s/%s", config_path, + "device_blacklist"); ini_name[MAX_INI_NAME_LEN] = '\0'; blacklist->ini = iniparser_load_wrapper(ini_name); @@ -45,10 +45,8 @@ void cras_device_blacklist_destroy(struct cras_device_blacklist *blacklist) } int cras_device_blacklist_check(struct cras_device_blacklist *blacklist, - unsigned vendor_id, - unsigned product_id, - unsigned desc_checksum, - unsigned device_index) + unsigned vendor_id, unsigned product_id, + unsigned desc_checksum, unsigned device_index) { char ini_key[MAX_KEY_LEN + 1]; diff --git a/cras/src/server/config/cras_device_blacklist.h b/cras/src/server/config/cras_device_blacklist.h index d43f540b..ac7cfe23 100644 --- a/cras/src/server/config/cras_device_blacklist.h +++ b/cras/src/server/config/cras_device_blacklist.h @@ -23,8 +23,8 @@ struct cras_device_blacklist; * Returns: * A pointer to the created blacklist on success, NULL on failure. */ -struct cras_device_blacklist *cras_device_blacklist_create( - const char *config_path); +struct cras_device_blacklist * +cras_device_blacklist_create(const char *config_path); /* Destroys a blacklist returned by cras_device_blacklist_create(). * Args: @@ -42,9 +42,7 @@ void cras_device_blacklist_destroy(struct cras_device_blacklist *blacklist); * 1 if the device is blacklisted, 0 otherwise. */ int cras_device_blacklist_check(struct cras_device_blacklist *blacklist, - unsigned vendor_id, - unsigned product_id, - unsigned desc_checksum, - unsigned device_index); + unsigned vendor_id, unsigned product_id, + unsigned desc_checksum, unsigned device_index); #endif /* CRAS_CARD_DEVICE_BLACKLIST_H_ */ diff --git a/cras/src/server/cras_a2dp_endpoint.c b/cras/src/server/cras_a2dp_endpoint.c index 7c205cac..4cda169d 100644 --- a/cras/src/server/cras_a2dp_endpoint.c +++ b/cras/src/server/cras_a2dp_endpoint.c @@ -145,6 +145,8 @@ static void cras_a2dp_suspend(struct cras_bt_endpoint *endpoint, BTLOG(btlog, BT_A2DP_SUSPENDED, 0, 0); cras_a2dp_suspend_connected_device(device); + cras_bt_device_notify_profile_dropped(device, + CRAS_BT_DEVICE_PROFILE_A2DP_SINK); } static void a2dp_transport_state_changed(struct cras_bt_endpoint *endpoint, diff --git a/cras/src/server/cras_a2dp_iodev.c b/cras/src/server/cras_a2dp_iodev.c index d57cdfaf..f6351aba 100644 --- a/cras/src/server/cras_a2dp_iodev.c +++ b/cras/src/server/cras_a2dp_iodev.c @@ -30,6 +30,11 @@ #define PCM_BUF_MAX_SIZE_FRAMES (4096 * 4) #define PCM_BUF_MAX_SIZE_BYTES (PCM_BUF_MAX_SIZE_FRAMES * 4) +/* no_stream target_frames in timespec. */ +static const struct timespec no_stream_target_frames_ts = { + 0, 10 * 1000 * 1000 /* 10 msec. */ +}; + /* Child of cras_iodev to handle bluetooth A2DP streaming. * Members: * base - The cras_iodev structure "base class" @@ -38,7 +43,6 @@ * sock_depth_frames - Socket depth in frames of the a2dp socket. * pcm_buf - Buffer to hold pcm samples before encode. * destroyed - Flag to note if this a2dp_io is about to destroy. - * pre_fill_complete - Flag to note if socket pre-fill is completed. * bt_written_frames - Accumulated frames written to a2dp socket. Used * together with the device open timestamp to estimate how many virtual * buffer is queued there. @@ -55,7 +59,6 @@ struct a2dp_io { unsigned sock_depth_frames; struct byte_buffer *pcm_buf; int destroyed; - int pre_fill_complete; uint64_t bt_written_frames; struct timespec dev_open_time; bool drain_complete; @@ -141,59 +144,46 @@ static int frames_queued(const struct cras_iodev *iodev, static int no_stream(struct cras_iodev *iodev, int enable) { - unsigned int pcm_bytes; struct a2dp_io *a2dpio = (struct a2dp_io *)iodev; unsigned int buf_avail; unsigned int format_bytes; unsigned int target_bytes; + unsigned int target_total_bytes; + unsigned int bt_queued_bytes; uint8_t *buf; + struct timespec tstamp; int i; format_bytes = cras_get_format_bytes(iodev->format); - pcm_bytes = buf_queued(a2dpio->pcm_buf); if (enable) { - if (!a2dpio->drain_complete && - (pcm_bytes <= a2dpio->filled_zeros_bytes)) - a2dpio->drain_complete = 1; + /* Target to have let hw_level = 2 * (frames in 10ms) */ + bt_queued_bytes = + cras_iodev_frames_queued(iodev, &tstamp) * format_bytes; + target_total_bytes = + 2 * + cras_time_to_frames(&no_stream_target_frames_ts, + iodev->format->frame_rate) * + format_bytes; + if (target_total_bytes <= bt_queued_bytes) + return 0; + target_total_bytes -= bt_queued_bytes; - /* Loop twice to make sure ring buffer is filled. */ + /* Loop twice to make sure target_total_bytes are filled. */ for (i = 0; i < 2; i++) { buf = buf_write_pointer_size(a2dpio->pcm_buf, &buf_avail); - if (buf_avail == 0) + if (buf_avail == 0 || target_total_bytes == 0) break; - target_bytes = iodev->buffer_size * format_bytes; - target_bytes = MIN(buf_avail, target_bytes); + target_bytes = MIN(buf_avail, target_total_bytes); memset(buf, 0, target_bytes); buf_increment_write(a2dpio->pcm_buf, target_bytes); - a2dpio->filled_zeros_bytes += target_bytes; + bt_queued_frames(iodev, target_bytes / format_bytes); + target_total_bytes -= target_bytes; } + flush_data(iodev); return 0; } - /* Leave no stream state. */ - target_bytes = iodev->min_cb_level * format_bytes; - if (a2dpio->drain_complete) { - buf_adjust_readable(a2dpio->pcm_buf, target_bytes); - } else { - unsigned int valid_bytes = 0; - if (pcm_bytes > a2dpio->filled_zeros_bytes) - valid_bytes = pcm_bytes - a2dpio->filled_zeros_bytes; - - target_bytes = MAX(target_bytes, valid_bytes); - if (target_bytes > pcm_bytes) { - target_bytes -= pcm_bytes; - buf = buf_write_pointer_size(a2dpio->pcm_buf, - &buf_avail); - target_bytes = MIN(target_bytes, buf_avail); - memset(buf, 0, target_bytes); - buf_increment_write(a2dpio->pcm_buf, target_bytes); - } else { - buf_adjust_readable(a2dpio->pcm_buf, target_bytes); - } - } - a2dpio->drain_complete = 0; - a2dpio->filled_zeros_bytes = 0; return 0; } @@ -202,6 +192,7 @@ static int configure_dev(struct cras_iodev *iodev) struct a2dp_io *a2dpio = (struct a2dp_io *)iodev; int sock_depth; int err; + socklen_t optlen; err = cras_bt_transport_acquire(a2dpio->transport); if (err < 0) { @@ -233,13 +224,14 @@ static int configure_dev(struct cras_iodev *iodev) setsockopt(cras_bt_transport_fd(a2dpio->transport), SOL_SOCKET, SO_SNDBUF, &sock_depth, sizeof(sock_depth)); - a2dpio->sock_depth_frames = - a2dp_block_size(&a2dpio->a2dp, cras_bt_transport_write_mtu( - a2dpio->transport)) / - cras_get_format_bytes(iodev->format) * 2; + optlen = sizeof(sock_depth); + getsockopt(cras_bt_transport_fd(a2dpio->transport), SOL_SOCKET, + SO_SNDBUF, &sock_depth, &optlen); + a2dpio->sock_depth_frames = a2dp_block_size(&a2dpio->a2dp, sock_depth) / + cras_get_format_bytes(iodev->format); + iodev->min_buffer_level = a2dpio->sock_depth_frames; - a2dpio->pre_fill_complete = 0; a2dpio->drain_complete = 0; a2dpio->filled_zeros_bytes = 0; @@ -282,38 +274,6 @@ static int close_dev(struct cras_iodev *iodev) return 0; } -static int pre_fill_socket(struct a2dp_io *a2dpio) -{ - static const uint16_t zero_buffer[1024 * 2]; - int processed; - int written = 0; - - while (1) { - processed = a2dp_encode( - &a2dpio->a2dp, zero_buffer, sizeof(zero_buffer), - cras_get_format_bytes(a2dpio->base.format), - cras_bt_transport_write_mtu(a2dpio->transport)); - if (processed < 0) - return processed; - if (processed == 0) - break; - - written = a2dp_write( - &a2dpio->a2dp, cras_bt_transport_fd(a2dpio->transport), - cras_bt_transport_write_mtu(a2dpio->transport)); - /* Full when EAGAIN is returned. */ - if (written == -EAGAIN) - break; - else if (written < 0) - return written; - else if (written == 0) - break; - }; - - a2dp_drain(&a2dpio->a2dp); - return 0; -} - /* Flushes queued buffer, including pcm and a2dp buffer. * Returns: * 0 when the flush succeeded, -1 when error occurred. @@ -437,16 +397,11 @@ static int put_buffer(struct cras_iodev *iodev, unsigned nwritten) buf_increment_write(a2dpio->pcm_buf, written_bytes); - bt_queued_frames(iodev, nwritten); - - /* Until the minimum number of frames have been queued, don't send - * anything. */ - if (!a2dpio->pre_fill_complete) { - pre_fill_socket(a2dpio); - a2dpio->pre_fill_complete = 1; - /* Start measuring frames_consumed from now. */ + /* Set dev open time at when the first data arrives. */ + if (nwritten && !a2dpio->bt_written_frames) clock_gettime(CLOCK_MONOTONIC_RAW, &a2dpio->dev_open_time); - } + + bt_queued_frames(iodev, nwritten); return flush_data(iodev); } @@ -533,7 +488,6 @@ struct cras_iodev *a2dp_iodev_create(struct cras_bt_transport *transport) SuperFastHash(cras_bt_device_object_path(device), strlen(cras_bt_device_object_path(device)), strlen(cras_bt_device_object_path(device))); - iodev->info.stable_id_new = iodev->info.stable_id; iodev->configure_dev = configure_dev; iodev->frames_queued = frames_queued; diff --git a/cras/src/server/cras_alsa_io.c b/cras/src/server/cras_alsa_io.c index d8b7ab74..4aec9d68 100644 --- a/cras/src/server/cras_alsa_io.c +++ b/cras/src/server/cras_alsa_io.c @@ -1179,8 +1179,6 @@ static struct alsa_output_node *new_output(struct alsa_io *aio, output->base.idx = aio->next_ionode_index++; output->base.stable_id = SuperFastHash(name, strlen(name), aio->base.info.stable_id); - output->base.stable_id_new = - SuperFastHash(name, strlen(name), aio->base.info.stable_id_new); if (aio->ucm) output->base.dsp_name = ucm_get_dsp_name_for_dev(aio->ucm, name); @@ -1263,8 +1261,6 @@ static struct alsa_input_node *new_input(struct alsa_io *aio, input->base.idx = aio->next_ionode_index++; input->base.stable_id = SuperFastHash(name, strlen(name), aio->base.info.stable_id); - input->base.stable_id_new = - SuperFastHash(name, strlen(name), aio->base.info.stable_id_new); if (strcmp(name, "SCO Line In") == 0) input->base.is_sco_pcm = 1; input->mixer_input = cras_input; @@ -1568,7 +1564,6 @@ static void set_iodev_name(struct cras_iodev *dev, const char *card_name, dev->info.stable_id = SuperFastHash((const char *)&device_index, sizeof(device_index), dev->info.stable_id); - dev->info.stable_id_new = dev->info.stable_id; break; case ALSA_CARD_TYPE_USB: dev->info.stable_id = @@ -1577,17 +1572,14 @@ static void set_iodev_name(struct cras_iodev *dev, const char *card_name, dev->info.stable_id = SuperFastHash((const char *)&usb_pid, sizeof(usb_pid), dev->info.stable_id); - dev->info.stable_id_new = - SuperFastHash(usb_serial_number, - strlen(usb_serial_number), - dev->info.stable_id); + dev->info.stable_id = SuperFastHash(usb_serial_number, + strlen(usb_serial_number), + dev->info.stable_id); break; default: - dev->info.stable_id_new = dev->info.stable_id; break; } - syslog(LOG_DEBUG, "Stable ID=%08x, New Stable ID=%08x", - dev->info.stable_id, dev->info.stable_id_new); + syslog(LOG_DEBUG, "Stable ID=%08x", dev->info.stable_id); } static int get_fixed_rate(struct alsa_io *aio) @@ -1898,8 +1890,9 @@ static unsigned int get_num_severe_underruns(const struct cras_iodev *iodev) static void set_default_hotword_model(struct cras_iodev *iodev) { - const char *default_model = "en_us"; + const char *default_models[] = { "en_all", "en_us" }; cras_node_id_t node_id; + unsigned i; if (!iodev->active_node || iodev->active_node->type != CRAS_NODE_TYPE_HOTWORD) @@ -1907,7 +1900,10 @@ static void set_default_hotword_model(struct cras_iodev *iodev) node_id = cras_make_node_id(iodev->info.idx, iodev->active_node->idx); /* This is a no-op if the default_model is not supported */ - cras_iodev_list_set_hotword_model(node_id, default_model); + for (i = 0; i < ARRAY_SIZE(default_models); ++i) + if (!cras_iodev_list_set_hotword_model(node_id, + default_models[i])) + return; } static int get_valid_frames(const struct cras_iodev *odev, diff --git a/cras/src/server/cras_audio_area.c b/cras/src/server/cras_audio_area.c index 5def7eaf..18615733 100644 --- a/cras/src/server/cras_audio_area.c +++ b/cras/src/server/cras_audio_area.c @@ -37,7 +37,6 @@ unsigned int cras_audio_area_copy(const struct cras_audio_area *dst, /* TODO(dgreid) - this replaces a memcpy, it needs to be way faster. */ for (src_idx = 0; src_idx < src->num_channels; src_idx++) { - for (dst_idx = 0; dst_idx < dst->num_channels; dst_idx++) { if (!(src->channels[src_idx].ch_set & dst->channels[dst_idx].ch_set)) @@ -48,11 +47,11 @@ unsigned int cras_audio_area_copy(const struct cras_audio_area *dst, dchan = dst->channels[dst_idx].buf + dst_offset * dst->channels[dst_idx].step_bytes; - cras_mix_add_scale_stride(dst_fmt->format, dchan, schan, - ncopy, - dst->channels[dst_idx].step_bytes, - src->channels[src_idx].step_bytes, - software_gain_scaler); + cras_mix_add_scale_stride( + dst_fmt->format, dchan, schan, ncopy, + dst->channels[dst_idx].step_bytes, + src->channels[src_idx].step_bytes, + software_gain_scaler); } } @@ -86,9 +85,9 @@ void cras_audio_area_config_channels(struct cras_audio_area *area, area->channels[i].ch_set = 0; for (ch = 0; ch < CRAS_CH_MAX; ch++) if (fmt->channel_layout[ch] == i) - channel_area_set_channel(&area->channels[i], ch); + channel_area_set_channel(&area->channels[i], + ch); } - } void cras_audio_area_config_buf_pointers(struct cras_audio_area *area, @@ -99,7 +98,7 @@ void cras_audio_area_config_buf_pointers(struct cras_audio_area *area, const int sample_size = snd_pcm_format_physical_width(fmt->format) / 8; /* TODO(dgreid) - assuming interleaved audio here for now. */ - for (i = 0 ; i < area->num_channels; i++) { + for (i = 0; i < area->num_channels; i++) { area->channels[i].step_bytes = cras_get_format_bytes(fmt); area->channels[i].buf = base_buffer + i * sample_size; } diff --git a/cras/src/server/cras_audio_area.h b/cras/src/server/cras_audio_area.h index 1111ee41..fe042325 100644 --- a/cras/src/server/cras_audio_area.h +++ b/cras/src/server/cras_audio_area.h @@ -42,9 +42,8 @@ struct cras_audio_area { * ca - the channel area to set channel bit set. * channel - the channel bit to add to the channel area. */ -static -inline void channel_area_set_channel(struct cras_channel_area *ca, - enum CRAS_CHANNEL channel) +static inline void channel_area_set_channel(struct cras_channel_area *ca, + enum CRAS_CHANNEL channel) { ca->ch_set |= (1 << channel); } diff --git a/cras/src/server/cras_audio_thread_monitor.c b/cras/src/server/cras_audio_thread_monitor.c index 9a23b00f..59212459 100644 --- a/cras/src/server/cras_audio_thread_monitor.c +++ b/cras/src/server/cras_audio_thread_monitor.c @@ -23,8 +23,8 @@ static void take_snapshot(enum CRAS_AUDIO_THREAD_EVENT_TYPE event_type) { struct cras_audio_thread_snapshot *snapshot; - snapshot = (struct cras_audio_thread_snapshot*) - calloc(1, sizeof(struct cras_audio_thread_snapshot)); + snapshot = (struct cras_audio_thread_snapshot *)calloc( + 1, sizeof(struct cras_audio_thread_snapshot)); struct timespec now_time; clock_gettime(CLOCK_MONOTONIC_RAW, &now_time); snapshot->timestamp = now_time; @@ -35,8 +35,8 @@ static void take_snapshot(enum CRAS_AUDIO_THREAD_EVENT_TYPE event_type) } static void cras_audio_thread_event_message_init( - struct cras_audio_thread_event_message *msg, - enum CRAS_AUDIO_THREAD_EVENT_TYPE event_type) + struct cras_audio_thread_event_message *msg, + enum CRAS_AUDIO_THREAD_EVENT_TYPE event_type) { msg->header.type = CRAS_MAIN_AUDIO_THREAD_EVENT; msg->header.length = sizeof(*msg); @@ -46,36 +46,33 @@ static void cras_audio_thread_event_message_init( int cras_audio_thread_event_send(enum CRAS_AUDIO_THREAD_EVENT_TYPE event_type) { struct cras_audio_thread_event_message msg; - int err; cras_audio_thread_event_message_init(&msg, event_type); - err = cras_main_message_send(&msg.header); - if (err < 0) { - syslog(LOG_ERR, "Failed to send audio thread event message %d", - event_type); - return err; - } - return 0; + return cras_main_message_send(&msg.header); } -int cras_audio_thread_debug() +int cras_audio_thread_event_debug() { return cras_audio_thread_event_send(AUDIO_THREAD_EVENT_DEBUG); } -int cras_audio_thread_busyloop() +int cras_audio_thread_event_busyloop() { return cras_audio_thread_event_send(AUDIO_THREAD_EVENT_BUSYLOOP); } -int cras_audio_thread_underrun() +int cras_audio_thread_event_underrun() { return cras_audio_thread_event_send(AUDIO_THREAD_EVENT_UNDERRUN); } -int cras_audio_thread_severe_underrun() +int cras_audio_thread_event_severe_underrun() +{ + return cras_audio_thread_event_send(AUDIO_THREAD_EVENT_SEVERE_UNDERRUN); +} + +int cras_audio_thread_event_drop_samples() { - return cras_audio_thread_event_send( - AUDIO_THREAD_EVENT_SEVERE_UNDERRUN); + return cras_audio_thread_event_send(AUDIO_THREAD_EVENT_DROP_SAMPLES); } static struct timespec last_event_snapshot_time[AUDIO_THREAD_EVENT_TYPE_COUNT]; @@ -86,9 +83,9 @@ static struct timespec last_event_snapshot_time[AUDIO_THREAD_EVENT_TYPE_COUNT]; * for the same event type. Events with the same event type within 30 seconds * will be ignored by the handle function. */ -static void handle_audio_thread_event_message( - struct cras_main_message *msg, - void *arg) { +static void handle_audio_thread_event_message(struct cras_main_message *msg, + void *arg) +{ struct cras_audio_thread_event_message *audio_thread_msg = (struct cras_audio_thread_event_message *)msg; struct timespec now_time; @@ -96,7 +93,7 @@ static void handle_audio_thread_event_message( /* * Skip invalid event types */ - if(audio_thread_msg->event_type >= AUDIO_THREAD_EVENT_TYPE_COUNT) + if (audio_thread_msg->event_type >= AUDIO_THREAD_EVENT_TYPE_COUNT) return; struct timespec *last_snapshot_time = @@ -109,10 +106,9 @@ static void handle_audio_thread_event_message( */ struct timespec diff_time; subtract_timespecs(&now_time, last_snapshot_time, &diff_time); - if((last_snapshot_time->tv_sec == 0 && - last_snapshot_time->tv_nsec == 0) || - diff_time.tv_sec >= MIN_WAIT_SECOND) - { + if ((last_snapshot_time->tv_sec == 0 && + last_snapshot_time->tv_nsec == 0) || + diff_time.tv_sec >= MIN_WAIT_SECOND) { take_snapshot(audio_thread_msg->event_type); *last_snapshot_time = now_time; } @@ -120,8 +116,8 @@ static void handle_audio_thread_event_message( int cras_audio_thread_monitor_init() { - memset(last_event_snapshot_time, - 0, sizeof(struct timespec) * AUDIO_THREAD_EVENT_TYPE_COUNT); + memset(last_event_snapshot_time, 0, + sizeof(struct timespec) * AUDIO_THREAD_EVENT_TYPE_COUNT); cras_main_message_add_handler(CRAS_MAIN_AUDIO_THREAD_EVENT, handle_audio_thread_event_message, NULL); return 0; diff --git a/cras/src/server/cras_audio_thread_monitor.h b/cras/src/server/cras_audio_thread_monitor.h index f2044bfb..b7355caa 100644 --- a/cras/src/server/cras_audio_thread_monitor.h +++ b/cras/src/server/cras_audio_thread_monitor.h @@ -9,22 +9,27 @@ /* * Sends a debug event to the audio thread for debugging. */ -int cras_audio_thread_debug(); +int cras_audio_thread_event_debug(); /* * Notifies the main thread when a busyloop event happens. */ -int cras_audio_thread_busyloop(); +int cras_audio_thread_event_busyloop(); /* * Notifies the main thread when a underrun event happens. */ -int cras_audio_thread_underrun(); +int cras_audio_thread_event_underrun(); /* * Notifies the main thread when a severe underrun event happens. */ -int cras_audio_thread_severe_underrun(); +int cras_audio_thread_event_severe_underrun(); + +/* + * Notifies the main thread when a drop samples event happens. + */ +int cras_audio_thread_event_drop_samples(); /* * Initializes audio thread monitor and sets main thread callback. diff --git a/cras/src/server/cras_bt_adapter.c b/cras/src/server/cras_bt_adapter.c index e83c7c1e..bcdecefa 100644 --- a/cras/src/server/cras_bt_adapter.c +++ b/cras/src/server/cras_bt_adapter.c @@ -18,13 +18,28 @@ #include "cras_bt_constants.h" #include "utlist.h" +/* + * Object to represent a bluetooth adapter on the system. Used to query the + * capabilities regarding certain bluetooth audio. + * Members: + * conn - The dbus connection used to send message to bluetoothd. + * object_path - Object path of the bluetooth adapter. + * address - The BT address of this adapter. + * name - The readable name of this adapter. + * bluetooth_class - The bluetooth class of device. + * powered - Powered on or off. + * bus_type - Type of bus this adapter runs on. + * wide_band_speech - If this adapter supports wide band speech. + */ struct cras_bt_adapter { + DBusConnection *conn; char *object_path; char *address; char *name; uint32_t bluetooth_class; int powered; int bus_type; + int wide_band_speech; struct cras_bt_adapter *prev, *next; }; @@ -65,7 +80,8 @@ static int cras_bt_adapter_query_bus_type(struct cras_bt_adapter *adapter) return 0; } -struct cras_bt_adapter *cras_bt_adapter_create(const char *object_path) +struct cras_bt_adapter *cras_bt_adapter_create(DBusConnection *conn, + const char *object_path) { struct cras_bt_adapter *adapter; @@ -73,6 +89,7 @@ struct cras_bt_adapter *cras_bt_adapter_create(const char *object_path) if (adapter == NULL) return NULL; + adapter->conn = conn; adapter->object_path = strdup(object_path); if (adapter->object_path == NULL) { free(adapter); @@ -166,6 +183,18 @@ int cras_bt_adapter_powered(const struct cras_bt_adapter *adapter) return adapter->powered; } +int cras_bt_adapter_wbs_supported(struct cras_bt_adapter *adapter) +{ + return adapter->wide_band_speech; +} + +static void bt_adapter_set_powered(struct cras_bt_adapter *adapter, int powered) +{ + adapter->powered = powered; + if (powered) + cras_bt_adapter_get_supported_capabilities(adapter); +} + void cras_bt_adapter_update_properties(struct cras_bt_adapter *adapter, DBusMessageIter *properties_array_iter, DBusMessageIter *invalidated_array_iter) @@ -213,7 +242,7 @@ void cras_bt_adapter_update_properties(struct cras_bt_adapter *adapter, dbus_message_iter_get_basic(&variant_iter, &value); if (strcmp(key, "Powered") == 0) - adapter->powered = value; + bt_adapter_set_powered(adapter, value); } dbus_message_iter_next(properties_array_iter); @@ -246,3 +275,109 @@ int cras_bt_adapter_on_usb(struct cras_bt_adapter *adapter) { return !!(adapter->bus_type == HCI_USB); } + +/* + * Expect to receive supported capabilities in reply, like below format: + * array [ + * dict entry( + * string "wide band speech" + * variant + * boolean <value> + * ) + * ] + */ +static void on_get_supported_capabilities_reply(DBusPendingCall *pending_call, + void *data) +{ + DBusMessage *reply; + DBusMessageIter message_iter, capabilities; + struct cras_bt_adapter *adapter; + + reply = dbus_pending_call_steal_reply(pending_call); + dbus_pending_call_unref(pending_call); + + if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) { + syslog(LOG_ERR, + "GetSupportedCapabilities message replied error: %s", + dbus_message_get_error_name(reply)); + goto get_supported_capabilities_err; + } + + if (!dbus_message_iter_init(reply, &message_iter)) { + syslog(LOG_ERR, "GetSupportedCapabilities reply doesn't have" + "argument"); + goto get_supported_capabilities_err; + } + + DL_FOREACH (adapters, adapter) { + if (adapter == (struct cras_bt_adapter *)data) + break; + } + if (NULL == adapter) + goto get_supported_capabilities_err; + + dbus_message_iter_recurse(&message_iter, &capabilities); + + while (dbus_message_iter_get_arg_type(&capabilities) != + DBUS_TYPE_INVALID) { + DBusMessageIter cap_dict_iter, variant_iter; + const char *key; + int type; + + dbus_message_iter_recurse(&capabilities, &cap_dict_iter); + + dbus_message_iter_get_basic(&cap_dict_iter, &key); + dbus_message_iter_next(&cap_dict_iter); + + dbus_message_iter_recurse(&cap_dict_iter, &variant_iter); + type = dbus_message_iter_get_arg_type(&variant_iter); + + if (type == DBUS_TYPE_BOOLEAN) { + int value; + + dbus_message_iter_get_basic(&variant_iter, &value); + + if (strcmp(key, "wide band speech") == 0) + adapter->wide_band_speech = value; + } + + dbus_message_iter_next(&capabilities); + } + +get_supported_capabilities_err: + dbus_message_unref(reply); +} + +int cras_bt_adapter_get_supported_capabilities(struct cras_bt_adapter *adapter) +{ + DBusMessage *method_call; + DBusError dbus_error; + DBusPendingCall *pending_call; + + method_call = dbus_message_new_method_call(BLUEZ_SERVICE, + adapter->object_path, + BLUEZ_INTERFACE_ADAPTER, + "GetSupportedCapabilities"); + if (!method_call) + return -ENOMEM; + + dbus_error_init(&dbus_error); + if (!dbus_connection_send_with_reply(adapter->conn, method_call, + &pending_call, + DBUS_TIMEOUT_USE_DEFAULT)) { + dbus_message_unref(method_call); + syslog(LOG_ERR, + "Failed to send GetSupportedCapabilities message"); + return -EIO; + } + + dbus_message_unref(method_call); + if (!dbus_pending_call_set_notify(pending_call, + on_get_supported_capabilities_reply, + adapter, NULL)) { + dbus_pending_call_cancel(pending_call); + dbus_pending_call_unref(pending_call); + return -EIO; + } + return 0; +} diff --git a/cras/src/server/cras_bt_adapter.h b/cras/src/server/cras_bt_adapter.h index 73ffa87e..dc07b685 100644 --- a/cras/src/server/cras_bt_adapter.h +++ b/cras/src/server/cras_bt_adapter.h @@ -10,7 +10,14 @@ struct cras_bt_adapter; -struct cras_bt_adapter *cras_bt_adapter_create(const char *object_path); +/* Creates an bt_adapter instance representing the bluetooth controller + * on the system. + * Args: + * conn - The dbus connection. + * object_path - Object path of the bluetooth controller. + */ +struct cras_bt_adapter *cras_bt_adapter_create(DBusConnection *conn, + const char *object_path); void cras_bt_adapter_destroy(struct cras_bt_adapter *adapter); void cras_bt_adapter_reset(); @@ -23,10 +30,21 @@ const char *cras_bt_adapter_name(const struct cras_bt_adapter *adapter); int cras_bt_adapter_powered(const struct cras_bt_adapter *adapter); +/* + * Returns true if adapter supports wide band speech feature. + */ +int cras_bt_adapter_wbs_supported(struct cras_bt_adapter *adapter); + void cras_bt_adapter_update_properties(struct cras_bt_adapter *adapter, DBusMessageIter *properties_array_iter, DBusMessageIter *invalidated_array_iter); int cras_bt_adapter_on_usb(struct cras_bt_adapter *adapter); +/* + * Queries adapter supported capabilies from bluetooth daemon. This shall + * be called only after adapter powers on. + */ +int cras_bt_adapter_get_supported_capabilities(struct cras_bt_adapter *adapter); + #endif /* CRAS_BT_ADAPTER_H_ */ diff --git a/cras/src/server/cras_bt_constants.h b/cras/src/server/cras_bt_constants.h index 09ae94a1..8d9ad5dd 100644 --- a/cras/src/server/cras_bt_constants.h +++ b/cras/src/server/cras_bt_constants.h @@ -6,7 +6,7 @@ #ifndef CRAS_BT_CONSTANTS_H_ #define CRAS_BT_CONSTANTS_H_ -#define BLUEZ_SERVICE "org.bluez" +#define BLUEZ_SERVICE "org.chromium.Bluetooth" #define BLUEZ_INTERFACE_ADAPTER "org.bluez.Adapter1" #define BLUEZ_INTERFACE_DEVICE "org.bluez.Device1" diff --git a/cras/src/server/cras_bt_device.c b/cras/src/server/cras_bt_device.c index b438e596..bc6b43d9 100644 --- a/cras/src/server/cras_bt_device.c +++ b/cras/src/server/cras_bt_device.c @@ -45,6 +45,7 @@ #define DEFAULT_SCO_PKT_SIZE USB_CVSD_PKT_SIZE static const unsigned int PROFILE_SWITCH_DELAY_MS = 500; +static const unsigned int PROFILE_DROP_SUSPEND_DELAY_MS = 5000; /* Check profile connections every 2 seconds and rerty 30 times maximum. * Attemp to connect profiles which haven't been ready every 3 retries. @@ -53,6 +54,11 @@ static const unsigned int CONN_WATCH_PERIOD_MS = 2000; static const unsigned int CONN_WATCH_MAX_RETRIES = 30; static const unsigned int PROFILE_CONN_RETRIES = 3; +static const unsigned int CRAS_SUPPORTED_PROFILES = + CRAS_BT_DEVICE_PROFILE_A2DP_SINK | + CRAS_BT_DEVICE_PROFILE_HFP_HANDSFREE | + CRAS_BT_DEVICE_PROFILE_HSP_AUDIOGATEWAY; + /* Object to represent a general bluetooth device, and used to * associate with some CRAS modules if it supports audio. * Members: @@ -76,7 +82,6 @@ static const unsigned int PROFILE_CONN_RETRIES = 3; * suspend_timer - The timer used to suspend device. * switch_profile_timer - The timer used to delay enabling iodev after * profile switch. - * append_iodev_cb - The callback to trigger when an iodev is appended. * sco_fd - The file descriptor of the SCO connection. * sco_ref_count - The reference counts of the SCO connection. */ @@ -99,7 +104,6 @@ struct cras_bt_device { struct cras_timer *conn_watch_timer; struct cras_timer *suspend_timer; struct cras_timer *switch_profile_timer; - void (*append_iodev_cb)(void *data); int sco_fd; size_t sco_ref_count; @@ -123,12 +127,6 @@ struct bt_device_msg { static struct cras_bt_device *devices; -void cras_bt_device_set_append_iodev_cb(struct cras_bt_device *device, - void (*cb)(void *data)) -{ - device->append_iodev_cb = cb; -} - enum cras_bt_device_profile cras_bt_device_profile_from_uuid(const char *uuid) { if (strcmp(uuid, HSP_HS_UUID) == 0) @@ -383,10 +381,6 @@ void cras_bt_device_append_iodev(struct cras_bt_device *device, if (bt_iodev) { cras_bt_io_append(bt_iodev, iodev, profile); } else { - if (device->append_iodev_cb) { - device->append_iodev_cb(device); - device->append_iodev_cb = NULL; - } device->bt_iodevs[iodev->direction] = cras_bt_io_create(device, iodev, profile); } @@ -460,39 +454,28 @@ int cras_bt_device_can_switch_to_a2dp(struct cras_bt_device *device) (!idev || !cras_iodev_is_open(idev)); } -int cras_bt_device_audio_gateway_initialized(struct cras_bt_device *device) +static void bt_device_remove_conflict(struct cras_bt_device *device) { - int rc = 0; - struct cras_tm *tm; + struct cras_bt_device *connected; + + /* Suspend other HFP audio gateways that conflict with device. */ + cras_hfp_ag_remove_conflict(device); + + /* Check if there's conflict A2DP headset and suspend it. */ + connected = cras_a2dp_connected_device(); + if (connected && (connected != device)) + cras_a2dp_suspend_connected_device(connected); +} +int cras_bt_device_audio_gateway_initialized(struct cras_bt_device *device) +{ BTLOG(btlog, BT_AUDIO_GATEWAY_INIT, device->profiles, 0); /* Marks HFP/HSP as connected. This is what connection watcher * checks. */ device->connected_profiles |= (CRAS_BT_DEVICE_PROFILE_HFP_HANDSFREE | CRAS_BT_DEVICE_PROFILE_HSP_HEADSET); - /* If this is a HFP/HSP only headset, no need to wait for A2DP. */ - if (!cras_bt_device_supports_profile( - device, CRAS_BT_DEVICE_PROFILE_A2DP_SINK)) { - syslog(LOG_DEBUG, - "Start HFP audio gateway as A2DP is not supported"); - - rc = cras_hfp_ag_start(device); - if (rc) { - syslog(LOG_ERR, "Start audio gateway failed"); - return rc; - } - if (device->conn_watch_timer) { - tm = cras_system_state_get_tm(); - cras_tm_cancel_timer(tm, device->conn_watch_timer); - device->conn_watch_timer = NULL; - } - } else { - syslog(LOG_DEBUG, "HFP audio gateway is connected but A2DP " - "is not connected yet"); - } - - return rc; + return 0; } int cras_bt_device_get_active_profile(const struct cras_bt_device *device) @@ -560,11 +543,16 @@ static void bt_device_conn_watch_cb(struct cras_timer *timer, void *arg) { struct cras_tm *tm; struct cras_bt_device *device = (struct cras_bt_device *)arg; + int rc; BTLOG(btlog, BT_DEV_CONN_WATCH_CB, device->conn_watch_retries, device->profiles); device->conn_watch_timer = NULL; + /* Skip the callback if it is not an audio device. */ + if (!device->profiles) + return; + /* If A2DP is not ready, try connect it after a while. */ if (cras_bt_device_supports_profile(device, CRAS_BT_DEVICE_PROFILE_A2DP_SINK) && @@ -587,21 +575,27 @@ static void bt_device_conn_watch_cb(struct cras_timer *timer, void *arg) goto arm_retry_timer; } - if (cras_bt_device_is_profile_connected( - device, CRAS_BT_DEVICE_PROFILE_A2DP_SINK)) { - /* When A2DP-only device connected, suspend all HFP/HSP audio - * gateways. */ - if (!cras_bt_device_supports_profile( - device, CRAS_BT_DEVICE_PROFILE_HFP_HANDSFREE | - CRAS_BT_DEVICE_PROFILE_HSP_HEADSET)) - cras_hfp_ag_suspend(); + /* Expected profiles are all connected, no more connection watch + * callback will be scheduled. + * Base on the decision that we expose only the latest connected + * BT audio device to user, treat all other connected devices as + * conflict and remove them before we start A2DP/HFP of this device. + */ + bt_device_remove_conflict(device); + if (cras_bt_device_is_profile_connected( + device, CRAS_BT_DEVICE_PROFILE_A2DP_SINK)) cras_a2dp_start(device); - } if (cras_bt_device_is_profile_connected( - device, CRAS_BT_DEVICE_PROFILE_HFP_HANDSFREE)) - cras_hfp_ag_start(device); + device, CRAS_BT_DEVICE_PROFILE_HFP_HANDSFREE)) { + rc = cras_hfp_ag_start(device); + if (rc) { + syslog(LOG_ERR, "Start audio gateway failed, rc %d", + rc); + bt_device_schedule_suspend(device, 0); + } + } return; arm_retry_timer: @@ -632,11 +626,9 @@ cras_bt_device_start_new_conn_watch_timer(struct cras_bt_device *device) tm, CONN_WATCH_PERIOD_MS, bt_device_conn_watch_cb, device); } -static void cras_bt_device_set_connected(struct cras_bt_device *device, - int value) +void cras_bt_device_set_connected(struct cras_bt_device *device, int value) { struct cras_tm *tm = cras_system_state_get_tm(); - if (device->connected || value) BTLOG(btlog, BT_DEV_CONNECTED_CHANGE, device->profiles, value); @@ -648,14 +640,25 @@ static void cras_bt_device_set_connected(struct cras_bt_device *device, device->connected = value; - if (device->connected) { - cras_bt_device_start_new_conn_watch_timer(device); - } else if (device->conn_watch_timer) { + if (!device->connected && device->conn_watch_timer) { cras_tm_cancel_timer(tm, device->conn_watch_timer); device->conn_watch_timer = NULL; } } +void cras_bt_device_notify_profile_dropped(struct cras_bt_device *device, + enum cras_bt_device_profile profile) +{ + device->connected_profiles &= !profile; + + /* If any profile, a2dp or hfp/hsp, has dropped for some reason, + * we shall make sure this device is fully disconnected within + * given time so that user does not see a headset stay connected + * but works with partial function. + */ + bt_device_schedule_suspend(device, PROFILE_DROP_SUSPEND_DELAY_MS); +} + /* * Check if the uuid is of a new audio profile that isn't listed * as supported by device. @@ -665,14 +668,9 @@ static void cras_bt_device_set_connected(struct cras_bt_device *device, * Returns: * True if uuid is a new audio profiles not already supported by device. */ -static int update_supported_profiles(struct cras_bt_device *device, - const char *uuid) +int cras_bt_device_add_supported_profiles(struct cras_bt_device *device, + const char *uuid) { - static unsigned int audio_profiles = - CRAS_BT_DEVICE_PROFILE_A2DP_SINK | - CRAS_BT_DEVICE_PROFILE_HFP_HANDSFREE | - CRAS_BT_DEVICE_PROFILE_HSP_AUDIOGATEWAY; - enum cras_bt_device_profile profile = cras_bt_device_profile_from_uuid(uuid); @@ -685,21 +683,20 @@ static int update_supported_profiles(struct cras_bt_device *device, /* Log this event as we might need to re-intialize the BT audio nodes * if new audio profile is reported for already connected device. */ - if (device->connected && (profile & audio_profiles)) + if (device->connected && (profile & CRAS_SUPPORTED_PROFILES)) BTLOG(btlog, BT_NEW_AUDIO_PROFILE_AFTER_CONNECT, device->profiles, profile); device->profiles |= profile; cras_bt_device_log_profile(device, profile); - return (profile & audio_profiles); + return (profile & CRAS_SUPPORTED_PROFILES); } void cras_bt_device_update_properties(struct cras_bt_device *device, DBusMessageIter *properties_array_iter, DBusMessageIter *invalidated_array_iter) { - int has_new_audio_profile = 0; - + int watch_needed = 0; while (dbus_message_iter_get_arg_type(properties_array_iter) != DBUS_TYPE_INVALID) { DBusMessageIter properties_dict_iter, variant_iter; @@ -750,6 +747,10 @@ void cras_bt_device_update_properties(struct cras_bt_device *device, device->trusted = value; } else if (strcmp(key, "Connected") == 0) { cras_bt_device_set_connected(device, value); + watch_needed = device->connected && + cras_bt_device_supports_profile( + device, + CRAS_SUPPORTED_PROFILES); } } else if (strcmp(dbus_message_iter_get_signature(&variant_iter), @@ -766,8 +767,18 @@ void cras_bt_device_update_properties(struct cras_bt_device *device, dbus_message_iter_get_basic(&uuid_array_iter, &uuid); - has_new_audio_profile = - update_supported_profiles(device, uuid); + /* + * If updated properties includes new audio + * profile, and device is connected, we need + * to start connection watcher. This is needed + * because on some bluetooth device, supported + * profiles do not present when device + * interface is added and they are updated + * later. + */ + if (cras_bt_device_add_supported_profiles( + device, uuid)) + watch_needed = device->connected; dbus_message_iter_next(&uuid_array_iter); } @@ -807,14 +818,8 @@ void cras_bt_device_update_properties(struct cras_bt_device *device, dbus_message_iter_next(invalidated_array_iter); } - /* If updated properties includes new audio profile, and device is - * connected, we need to start connection watcher. This is needed - * because on some bluetooth device, supported profiles do not present - * when device interface is added and they are updated later. - */ - if (has_new_audio_profile && device->connected) { + if (watch_needed) cras_bt_device_start_new_conn_watch_timer(device); - } } /* Converts bluetooth address string into sockaddr structure. The address @@ -1144,11 +1149,13 @@ static void bt_device_suspend_cb(struct cras_timer *timer, void *arg) { struct cras_bt_device *device = (struct cras_bt_device *)arg; - BTLOG(btlog, BT_DEV_SUSPEND_CB, 0, 0); + BTLOG(btlog, BT_DEV_SUSPEND_CB, device->profiles, + device->connected_profiles); device->suspend_timer = NULL; cras_a2dp_suspend_connected_device(device); cras_hfp_ag_suspend_connected_device(device); + cras_bt_device_disconnect(device->conn, device); } static void bt_device_schedule_suspend(struct cras_bt_device *device, diff --git a/cras/src/server/cras_bt_device.h b/cras/src/server/cras_bt_device.h index a2e57289..904a5f47 100644 --- a/cras/src/server/cras_bt_device.h +++ b/cras/src/server/cras_bt_device.h @@ -52,9 +52,9 @@ void cras_bt_device_update_properties(struct cras_bt_device *device, DBusMessageIter *properties_array_iter, DBusMessageIter *invalidated_array_iter); -/* Sets the append_iodev_cb to bt device. */ -void cras_bt_device_set_append_iodev_cb(struct cras_bt_device *device, - void (*cb)(void *data)); +/* Updates the supported profiles on dev. Expose for unit test. */ +int cras_bt_device_add_supported_profiles(struct cras_bt_device *device, + const char *uuid); /* Checks if profile is claimed supported by the device. */ int cras_bt_device_supports_profile(const struct cras_bt_device *device, @@ -72,6 +72,9 @@ void cras_bt_device_set_use_hardware_volume(struct cras_bt_device *device, /* Gets if the BT audio device should use hardware volume. */ int cras_bt_device_get_use_hardware_volume(struct cras_bt_device *device); +/* Sets device connected state. Expose for unit test. */ +void cras_bt_device_set_connected(struct cras_bt_device *device, int value); + /* Forces disconnect the bt device. Used when handling audio error * that we want to make the device be completely disconnected from * host to reflect the state that an error has occurred. @@ -179,6 +182,16 @@ int cras_bt_device_schedule_suspend(struct cras_bt_device *device, int cras_bt_device_audio_gateway_initialized(struct cras_bt_device *device); /* + * Notifies bt device about a profile no longer works. It could be caused + * by initialize failure or fatal error has occurred. + * Args: + * device - The bluetooth audio device. + * profile - The BT audio profile that has dropped. + */ +void cras_bt_device_notify_profile_dropped(struct cras_bt_device *device, + enum cras_bt_device_profile profile); + +/* * Establishes SCO connection if it has not been established on the BT device. * Note: this function should be only used for hfp_alsa_io. * Args: diff --git a/cras/src/server/cras_bt_endpoint.c b/cras/src/server/cras_bt_endpoint.c index 9627967c..5b2b6e06 100644 --- a/cras/src/server/cras_bt_endpoint.c +++ b/cras/src/server/cras_bt_endpoint.c @@ -42,13 +42,24 @@ static void cras_bt_endpoint_suspend(struct cras_bt_endpoint *endpoint) { + struct cras_bt_transport *transport; + if (!endpoint->transport) return; endpoint->suspend(endpoint, endpoint->transport); - cras_bt_transport_set_endpoint(endpoint->transport, NULL); + transport = endpoint->transport; + cras_bt_transport_set_endpoint(transport, NULL); endpoint->transport = NULL; + + /* + * If BT stack has notified this transport interface removed. + * Destroy transport now since all related objects has been + * cleaned up. + */ + if (cras_bt_transport_is_removed(transport)) + cras_bt_transport_destroy(transport); } static DBusHandlerResult diff --git a/cras/src/server/cras_bt_io.c b/cras/src/server/cras_bt_io.c index c44da271..637f0a79 100644 --- a/cras/src/server/cras_bt_io.c +++ b/cras/src/server/cras_bt_io.c @@ -69,7 +69,6 @@ static struct cras_ionode *add_profile_dev(struct cras_iodev *bt_iodev, n->base.type = CRAS_NODE_TYPE_BLUETOOTH; n->base.volume = 100; n->base.stable_id = dev->info.stable_id; - n->base.stable_id_new = dev->info.stable_id_new; n->base.max_software_gain = 0; gettimeofday(&n->base.plugged_time, NULL); @@ -397,7 +396,6 @@ struct cras_iodev *cras_bt_io_create(struct cras_bt_device *device, iodev->direction = dev->direction; strcpy(iodev->info.name, dev->info.name); iodev->info.stable_id = dev->info.stable_id; - iodev->info.stable_id_new = dev->info.stable_id_new; iodev->open_dev = open_dev; iodev->configure_dev = configure_dev; @@ -438,7 +436,6 @@ struct cras_iodev *cras_bt_io_create(struct cras_bt_device *device, SuperFastHash(cras_bt_device_object_path(device), strlen(cras_bt_device_object_path(device)), strlen(cras_bt_device_object_path(device))); - active->base.stable_id_new = active->base.stable_id; active->profile = profile; active->profile_dev = dev; gettimeofday(&active->base.plugged_time, NULL); diff --git a/cras/src/server/cras_bt_manager.c b/cras/src/server/cras_bt_manager.c index 072613a9..3a3ea4ae 100644 --- a/cras/src/server/cras_bt_manager.c +++ b/cras/src/server/cras_bt_manager.c @@ -37,7 +37,7 @@ static void cras_bt_interface_added(DBusConnection *conn, adapter, properties_array_iter, NULL); } else { BTLOG(btlog, BT_ADAPTER_ADDED, 0, 0); - adapter = cras_bt_adapter_create(object_path); + adapter = cras_bt_adapter_create(conn, object_path); if (adapter) { cras_bt_adapter_update_properties( adapter, properties_array_iter, NULL); @@ -137,7 +137,7 @@ static void cras_bt_interface_removed(DBusConnection *conn, if (transport) { syslog(LOG_INFO, "Bluetooth Transport: %s removed", cras_bt_transport_object_path(transport)); - cras_bt_transport_destroy(transport); + cras_bt_transport_remove(transport); } } } diff --git a/cras/src/server/cras_bt_profile.c b/cras/src/server/cras_bt_profile.c index c633dd82..d180a1b4 100644 --- a/cras/src/server/cras_bt_profile.c +++ b/cras/src/server/cras_bt_profile.c @@ -56,6 +56,7 @@ static DBusHandlerResult cras_bt_profile_handle_release(DBusConnection *conn, if (!profile) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + syslog(LOG_ERR, "Profile %s released by bluetoothd", profile->name); profile->release(profile); reply = dbus_message_new_method_return(message); diff --git a/cras/src/server/cras_bt_transport.c b/cras/src/server/cras_bt_transport.c index 5886329e..9e06dacf 100644 --- a/cras/src/server/cras_bt_transport.c +++ b/cras/src/server/cras_bt_transport.c @@ -32,6 +32,7 @@ struct cras_bt_transport { uint16_t read_mtu; uint16_t write_mtu; int volume; + int removed; struct cras_bt_endpoint *endpoint; struct cras_bt_transport *prev, *next; @@ -71,6 +72,25 @@ void cras_bt_transport_set_endpoint(struct cras_bt_transport *transport, transport->endpoint = endpoint; } +int cras_bt_transport_is_removed(struct cras_bt_transport *transport) +{ + return transport->removed; +} + +void cras_bt_transport_remove(struct cras_bt_transport *transport) +{ + /* + * If the transport object is still associated with a valid + * endpoint. Flag it as removed and wait for the ClearConfiguration + * message from BT to actually suspend this A2DP connection and + * destroy the transport. + */ + if (transport->endpoint) + transport->removed = 1; + else + cras_bt_transport_destroy(transport); +} + void cras_bt_transport_destroy(struct cras_bt_transport *transport) { DL_DELETE(transports, transport); diff --git a/cras/src/server/cras_bt_transport.h b/cras/src/server/cras_bt_transport.h index 43462c80..6722fb0a 100644 --- a/cras/src/server/cras_bt_transport.h +++ b/cras/src/server/cras_bt_transport.h @@ -24,6 +24,19 @@ struct cras_bt_transport *cras_bt_transport_create(DBusConnection *conn, const char *object_path); void cras_bt_transport_set_endpoint(struct cras_bt_transport *transport, struct cras_bt_endpoint *endpoint); + +/* Handles the event when BT stack notifies specific transport is removed. + * Args: + * transport - The transport object representing an A2DP connection. + */ +void cras_bt_transport_remove(struct cras_bt_transport *transport); + +/* Queries the state if BT stack has removed given transport. + * Args: + * transport - The transport object representing an A2DP connection. + */ +int cras_bt_transport_is_removed(struct cras_bt_transport *transport); + void cras_bt_transport_destroy(struct cras_bt_transport *transport); void cras_bt_transport_reset(); diff --git a/cras/src/server/cras_capture_rclient.c b/cras/src/server/cras_capture_rclient.c new file mode 100644 index 00000000..c13792cd --- /dev/null +++ b/cras/src/server/cras_capture_rclient.c @@ -0,0 +1,103 @@ +/* Copyright 2019 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <syslog.h> + +#include "cras_iodev_list.h" +#include "cras_messages.h" +#include "cras_observer.h" +#include "cras_rclient.h" +#include "cras_rclient_util.h" +#include "cras_rstream.h" +#include "cras_system_state.h" +#include "cras_types.h" +#include "cras_util.h" +#include "stream_list.h" + +/* Entry point for handling a message from the client. Called from the main + * server context. */ +static int ccr_handle_message_from_client(struct cras_rclient *client, + const struct cras_server_message *msg, + int *fds, unsigned int num_fds) +{ + int rc = 0; + assert(client && msg); + + rc = rclient_validate_message_fds(msg, fds, num_fds); + if (rc < 0) { + for (int i = 0; i < (int)num_fds; i++) + if (fds[i] >= 0) + close(fds[i]); + return rc; + } + int fd = num_fds > 0 ? fds[0] : -1; + + switch (msg->id) { + case CRAS_SERVER_CONNECT_STREAM: { + int client_shm_fd = num_fds > 1 ? fds[1] : -1; + struct cras_connect_message cmsg; + if (MSG_LEN_VALID(msg, struct cras_connect_message)) { + rc = rclient_handle_client_stream_connect( + client, + (const struct cras_connect_message *)msg, fd, + client_shm_fd); + } else if (!convert_connect_message_old(msg, &cmsg)) { + rc = rclient_handle_client_stream_connect( + client, &cmsg, fd, client_shm_fd); + } else { + return -EINVAL; + } + break; + } + case CRAS_SERVER_DISCONNECT_STREAM: + if (!MSG_LEN_VALID(msg, struct cras_disconnect_stream_message)) + return -EINVAL; + rc = rclient_handle_client_stream_disconnect( + client, + (const struct cras_disconnect_stream_message *)msg); + break; + default: + break; + } + + return rc; +} + +/* Declarations of cras_rclient operators for cras_capture_rclient. */ +static const struct cras_rclient_ops cras_capture_rclient_ops = { + .handle_message_from_client = ccr_handle_message_from_client, + .send_message_to_client = rclient_send_message_to_client, + .destroy = rclient_destroy, +}; + +/* + * Exported Functions. + */ + +/* Creates a client structure and sends a message back informing the client that + * the connection has succeeded. */ +struct cras_rclient *cras_capture_rclient_create(int fd, size_t id) +{ + struct cras_rclient *client; + struct cras_client_connected msg; + int state_fd; + + client = (struct cras_rclient *)calloc(1, sizeof(struct cras_rclient)); + if (!client) + return NULL; + + client->fd = fd; + client->id = id; + + client->ops = &cras_capture_rclient_ops; + client->supported_directions = + cras_stream_direction_mask(CRAS_STREAM_INPUT); + + cras_fill_client_connected(&msg, client->id); + state_fd = cras_sys_state_shm_fd(); + client->ops->send_message_to_client(client, &msg.header, &state_fd, 1); + + return client; +} diff --git a/cras/src/server/cras_capture_rclient.h b/cras/src/server/cras_capture_rclient.h new file mode 100644 index 00000000..129e559c --- /dev/null +++ b/cras/src/server/cras_capture_rclient.h @@ -0,0 +1,20 @@ +/* Copyright 2019 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef CRAS_CAPTURE_RCLIENT_H_ +#define CRAS_CAPTURE_RCLIENT_H_ + +struct cras_rclient; + +/* Creates a capture rclient structure. + * Args: + * fd - The file descriptor used for communication with the client. + * id - Unique identifier for this client. + * Returns: + * A pointer to the newly created rclient on success, NULL on failure. + */ +struct cras_rclient *cras_capture_rclient_create(int fd, size_t id); + +#endif /* CRAS_CAPTURE_RCLIENT_H_ */ diff --git a/cras/src/server/cras_control_rclient.c b/cras/src/server/cras_control_rclient.c index 61f4df58..c0eea5d6 100644 --- a/cras/src/server/cras_control_rclient.c +++ b/cras/src/server/cras_control_rclient.c @@ -7,6 +7,7 @@ #include <syslog.h> #include "audio_thread.h" +#include "audio_thread_log.h" #include "cras_apm_list.h" #include "cras_bt_log.h" #include "cras_config.h" @@ -17,125 +18,14 @@ #include "cras_messages.h" #include "cras_observer.h" #include "cras_rclient.h" +#include "cras_rclient_util.h" #include "cras_rstream.h" -#include "cras_server_metrics.h" #include "cras_system_state.h" #include "cras_types.h" #include "cras_util.h" #include "stream_list.h" #include "utlist.h" -/* Handles a message from the client to connect a new stream */ -static int handle_client_stream_connect(struct cras_rclient *client, - const struct cras_connect_message *msg, - int aud_fd) -{ - struct cras_rstream *stream; - struct cras_client_stream_connected stream_connected; - struct cras_client_message *reply; - struct cras_audio_format remote_fmt; - struct cras_rstream_config stream_config; - int rc, header_fd, samples_fd; - int stream_fds[2]; - - unpack_cras_audio_format(&remote_fmt, &msg->format); - - /* check the aud_fd is valid. */ - if (aud_fd < 0) { - syslog(LOG_ERR, "Invalid fd in stream connect.\n"); - rc = -EINVAL; - goto reply_err; - } - /* When full, getting an error is preferable to blocking. */ - cras_make_fd_nonblocking(aud_fd); - - /* Create the stream with the specified parameters. */ - stream_config.stream_id = msg->stream_id; - stream_config.stream_type = msg->stream_type; - stream_config.direction = msg->direction; - stream_config.dev_idx = msg->dev_idx; - stream_config.flags = msg->flags; - stream_config.effects = msg->effects; - stream_config.format = &remote_fmt; - stream_config.buffer_frames = msg->buffer_frames; - stream_config.cb_threshold = msg->cb_threshold; - stream_config.audio_fd = aud_fd; - stream_config.client = client; - stream_config.use_split_shm = msg->proto_version > 2; - rc = stream_list_add(cras_iodev_list_get_stream_list(), &stream_config, - &stream); - if (rc) - goto reply_err; - - /* Tell client about the stream setup. */ - syslog(LOG_DEBUG, "Send connected for stream %x\n", msg->stream_id); - if (stream_config.use_split_shm) { - cras_fill_client_stream_connected( - &stream_connected, 0, /* No error. */ - msg->stream_id, &remote_fmt, - cras_rstream_get_samples_shm_size(stream), - cras_rstream_get_effects(stream)); - reply = &stream_connected.header; - - } else { - cras_fill_client_stream_connected( - &stream_connected, 0, /* No error. */ - msg->stream_id, &remote_fmt, - cras_rstream_get_samples_shm_size(stream) + - cras_shm_header_size(), - cras_rstream_get_effects(stream)); - reply = &stream_connected.header; - } - - rc = cras_rstream_get_shm_fds(stream, &header_fd, &samples_fd); - if (rc) - goto reply_err; - - if (stream_config.use_split_shm) { - stream_fds[0] = header_fd; - stream_fds[1] = samples_fd; - } else { - // for unsplit shm, the client expects both fds to be the same. - stream_fds[0] = header_fd; - stream_fds[1] = header_fd; - } - - rc = client->ops->send_message_to_client(client, reply, stream_fds, 2); - if (rc < 0) { - syslog(LOG_ERR, "Failed to send connected messaged\n"); - stream_list_rm(cras_iodev_list_get_stream_list(), - stream->stream_id); - goto reply_err; - } - - /* Metrics logs the stream configurations. */ - cras_server_metrics_stream_config(&stream_config); - - return 0; - -reply_err: - /* Send the error code to the client. */ - cras_fill_client_stream_connected(&stream_connected, rc, msg->stream_id, - &remote_fmt, 0, msg->effects); - reply = &stream_connected.header; - client->ops->send_message_to_client(client, reply, NULL, 0); - - if (aud_fd >= 0) - close(aud_fd); - - return rc; -} - -/* Handles messages from the client requesting that a stream be removed from the - * server. */ -static int handle_client_stream_disconnect( - struct cras_rclient *client, - const struct cras_disconnect_stream_message *msg) -{ - return stream_list_rm(cras_iodev_list_get_stream_list(), - msg->stream_id); -} - /* Handles dumping audio thread debug info back to the client. */ static void dump_audio_thread_info(struct cras_rclient *client) { @@ -149,6 +39,17 @@ static void dump_audio_thread_info(struct cras_rclient *client) client->ops->send_message_to_client(client, &msg.header, NULL, 0); } +/* Sends shared memory fd for audio thread event log back to the client. */ +static void get_atlog_fd(struct cras_rclient *client) +{ + struct cras_client_atlog_fd_ready msg; + int atlog_fd; + + cras_fill_client_atlog_fd_ready(&msg); + atlog_fd = audio_thread_event_log_shm_fd(); + client->ops->send_message_to_client(client, &msg.header, &atlog_fd, 1); +} + /* Handles dumping audio snapshots to shared memory for the client. */ static void dump_audio_thread_snapshots(struct cras_rclient *client) { @@ -172,7 +73,7 @@ static void handle_get_hotword_models(struct cras_rclient *client, if (!hotword_models) goto empty_reply; hotword_models_size = strlen(hotword_models); - if (hotword_models_size + sizeof(*msg) > CRAS_CLIENT_MAX_MSG_SIZE) { + if (hotword_models_size > CRAS_MAX_HOTWORD_MODELS) { free(hotword_models); goto empty_reply; } @@ -363,60 +264,50 @@ static void register_for_notification(struct cras_rclient *client, } } -/* Removes all streams that the client owns and destroys it. */ -static void ccr_destroy(struct cras_rclient *client) -{ - cras_observer_remove(client->observer); - stream_list_rm_all_client_streams(cras_iodev_list_get_stream_list(), - client); - free(client); -} - static int direction_valid(enum CRAS_STREAM_DIRECTION direction) { return direction < CRAS_NUM_DIRECTIONS && direction != CRAS_STREAM_UNDEFINED; } -#define MSG_LEN_VALID(msg, type) ((msg)->length >= sizeof(type)) - /* Entry point for handling a message from the client. Called from the main * server context. */ static int ccr_handle_message_from_client(struct cras_rclient *client, const struct cras_server_message *msg, - int fd) + int *fds, unsigned int num_fds) { + int rc = 0; assert(client && msg); - /* Most messages should not have a file descriptor. */ - switch (msg->id) { - case CRAS_SERVER_CONNECT_STREAM: - break; - case CRAS_SERVER_SET_AEC_DUMP: - syslog(LOG_ERR, "client msg for APM debug, fd %d", fd); - break; - default: - if (fd != -1) { - syslog(LOG_ERR, - "Message %d should not have fd attached.", - msg->id); - close(fd); - return -1; - } - break; + rc = rclient_validate_message_fds(msg, fds, num_fds); + if (rc < 0) { + for (int i = 0; i < (int)num_fds; i++) + if (fds[i] >= 0) + close(fds[i]); + return rc; } + int fd = num_fds > 0 ? fds[0] : -1; switch (msg->id) { - case CRAS_SERVER_CONNECT_STREAM: - if (!MSG_LEN_VALID(msg, struct cras_connect_message)) + case CRAS_SERVER_CONNECT_STREAM: { + int client_shm_fd = num_fds > 1 ? fds[1] : -1; + struct cras_connect_message cmsg; + if (MSG_LEN_VALID(msg, struct cras_connect_message)) { + return rclient_handle_client_stream_connect( + client, + (const struct cras_connect_message *)msg, fd, + client_shm_fd); + } else if (!convert_connect_message_old(msg, &cmsg)) { + return rclient_handle_client_stream_connect( + client, &cmsg, fd, client_shm_fd); + } else { return -EINVAL; - handle_client_stream_connect( - client, (const struct cras_connect_message *)msg, fd); - break; + } + } case CRAS_SERVER_DISCONNECT_STREAM: if (!MSG_LEN_VALID(msg, struct cras_disconnect_stream_message)) return -EINVAL; - handle_client_stream_disconnect( + rclient_handle_client_stream_disconnect( client, (const struct cras_disconnect_stream_message *)msg); break; @@ -508,6 +399,9 @@ static int ccr_handle_message_from_client(struct cras_rclient *client, case CRAS_SERVER_DUMP_AUDIO_THREAD: dump_audio_thread_info(client); break; + case CRAS_SERVER_GET_ATLOG_FD: + get_atlog_fd(client); + break; case CRAS_SERVER_DUMP_BT: { struct cras_client_audio_debug_info_ready msg; struct cras_server_state *state; @@ -622,20 +516,11 @@ static int ccr_handle_message_from_client(struct cras_rclient *client, return 0; } -/* Sends a message to the client. */ -static int ccr_send_message_to_client(const struct cras_rclient *client, - const struct cras_client_message *msg, - int *fds, unsigned int num_fds) -{ - return cras_send_with_fds(client->fd, (const void *)msg, msg->length, - fds, num_fds); -} - /* Declarations of cras_rclient operators for cras_control_rclient. */ static const struct cras_rclient_ops cras_control_rclient_ops = { .handle_message_from_client = ccr_handle_message_from_client, - .send_message_to_client = ccr_send_message_to_client, - .destroy = ccr_destroy, + .send_message_to_client = rclient_send_message_to_client, + .destroy = rclient_destroy, }; /* @@ -656,8 +541,11 @@ struct cras_rclient *cras_control_rclient_create(int fd, size_t id) client->fd = fd; client->id = id; - client->ops = &cras_control_rclient_ops; + client->supported_directions = CRAS_STREAM_ALL_DIRECTION; + /* Filters CRAS_STREAM_UNDEFINED stream out. */ + client->supported_directions ^= + cras_stream_direction_mask(CRAS_STREAM_UNDEFINED); cras_fill_client_connected(&msg, client->id); state_fd = cras_sys_state_shm_fd(); diff --git a/cras/src/server/cras_dbus_control.c b/cras/src/server/cras_dbus_control.c index 8c331a2d..978c64a3 100644 --- a/cras/src/server/cras_dbus_control.c +++ b/cras/src/server/cras_dbus_control.c @@ -113,6 +113,9 @@ " <method name=\"IsAudioOutputActive\">\n" \ " <arg name=\"active\" type=\"b\" direction=\"out\"/>\n" \ " </method>\n" \ + " <method name=\"SetWbsEnabled\">\n" \ + " <arg name=\"enabled\" type=\"b\" direction=\"in\"/>\n" \ + " </method>\n" \ " </interface>\n" \ " <interface name=\"" DBUS_INTERFACE_INTROSPECTABLE "\">\n" \ " <method name=\"Introspect\">\n" \ @@ -424,7 +427,6 @@ static dbus_bool_t append_node_dict(DBusMessageIter *iter, dbus_uint64_t id; const char *dev_name = dev->name; dbus_uint64_t stable_dev_id = node->stable_id; - dbus_uint64_t stable_dev_id_new = node->stable_id_new; const char *node_type = node->type; const char *node_name = node->name; const char *mic_positions = node->mic_positions; @@ -452,12 +454,13 @@ static dbus_bool_t append_node_dict(DBusMessageIter *iter, if (!append_key_value(&dict, "DeviceName", DBUS_TYPE_STRING, DBUS_TYPE_STRING_AS_STRING, &dev_name)) return FALSE; + /* + * If stable id migration is needed, use key 'StableDeviceIdNew' + * together with 'StableDeviceId'. + */ if (!append_key_value(&dict, "StableDeviceId", DBUS_TYPE_UINT64, DBUS_TYPE_UINT64_AS_STRING, &stable_dev_id)) return FALSE; - if (!append_key_value(&dict, "StableDeviceIdNew", DBUS_TYPE_UINT64, - DBUS_TYPE_UINT64_AS_STRING, &stable_dev_id_new)) - return FALSE; if (!append_key_value(&dict, "Type", DBUS_TYPE_STRING, DBUS_TYPE_STRING_AS_STRING, &node_type)) return FALSE; @@ -761,6 +764,23 @@ static DBusHandlerResult handle_is_audio_active(DBusConnection *conn, return DBUS_HANDLER_RESULT_HANDLED; } +static DBusHandlerResult handle_set_wbs_enabled(DBusConnection *conn, + DBusMessage *message, void *arg) +{ + int rc; + dbus_bool_t enabled; + + rc = get_single_arg(message, DBUS_TYPE_BOOLEAN, &enabled); + if (rc) + return rc; + + cras_system_set_bt_wbs_enabled(enabled); + + send_empty_reply(conn, message); + + return DBUS_HANDLER_RESULT_HANDLED; +} + /* Handle incoming messages. */ static DBusHandlerResult handle_control_message(DBusConnection *conn, DBusMessage *message, void *arg) @@ -877,6 +897,9 @@ static DBusHandlerResult handle_control_message(DBusConnection *conn, } else if (dbus_message_is_method_call(message, CRAS_CONTROL_INTERFACE, "IsAudioOutputActive")) { return handle_is_audio_active(conn, message, arg); + } else if (dbus_message_is_method_call(message, CRAS_CONTROL_INTERFACE, + "SetWbsEnabled")) { + return handle_set_wbs_enabled(conn, message, arg); } return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; diff --git a/cras/src/server/cras_dsp.c b/cras/src/server/cras_dsp.c index a7e36c98..1a2707d3 100644 --- a/cras/src/server/cras_dsp.c +++ b/cras/src/server/cras_dsp.c @@ -48,6 +48,22 @@ static void initialize_environment(struct cras_expr_env *env) cras_expr_env_set_variable_boolean(env, "swap_lr_disabled", 1); } +static void destroy_pipeline(struct pipeline *pipeline) +{ + struct ini *private_ini; + + private_ini = cras_dsp_pipeline_get_ini(pipeline); + cras_dsp_pipeline_free(pipeline); + + /* + * If pipeline is using an dsp ini other than the global one, free + * this ini so its life cycle is aligned with the associated dsp + * pipeline. + */ + if (private_ini && (private_ini != ini)) + cras_dsp_ini_free(private_ini); +} + static struct pipeline *prepare_pipeline(struct cras_dsp_context *ctx, struct ini *target_ini) { @@ -84,7 +100,7 @@ static struct pipeline *prepare_pipeline(struct cras_dsp_context *ctx, bail: if (pipeline) - cras_dsp_pipeline_free(pipeline); + destroy_pipeline(pipeline); return NULL; } @@ -102,7 +118,7 @@ static void cmd_load_pipeline(struct cras_dsp_context *ctx, pthread_mutex_unlock(&ctx->mutex); if (old_pipeline) - cras_dsp_pipeline_free(old_pipeline); + destroy_pipeline(old_pipeline); } static void cmd_reload_ini() @@ -164,7 +180,7 @@ void cras_dsp_context_free(struct cras_dsp_context *ctx) pthread_mutex_destroy(&ctx->mutex); if (ctx->pipeline) { - cras_dsp_pipeline_free(ctx->pipeline); + destroy_pipeline(ctx->pipeline); ctx->pipeline = NULL; } cras_expr_env_free(&ctx->env); @@ -194,8 +210,10 @@ void cras_dsp_load_dummy_pipeline(struct cras_dsp_context *ctx, { struct ini *dummy_ini; dummy_ini = create_dummy_ini(ctx->purpose, num_channels); - cmd_load_pipeline(ctx, dummy_ini); - cras_dsp_ini_free((dummy_ini)); + if (dummy_ini == NULL) + syslog(LOG_ERR, "Failed to create dummy ini"); + else + cmd_load_pipeline(ctx, dummy_ini); } struct pipeline *cras_dsp_get_pipeline(struct cras_dsp_context *ctx) diff --git a/cras/src/server/cras_dsp_pipeline.c b/cras/src/server/cras_dsp_pipeline.c index ff39bf8b..945e5c3e 100644 --- a/cras/src/server/cras_dsp_pipeline.c +++ b/cras/src/server/cras_dsp_pipeline.c @@ -784,6 +784,11 @@ void cras_dsp_pipeline_set_sink_ext_module(struct pipeline *pipeline, ext_module); } +struct ini *cras_dsp_pipeline_get_ini(struct pipeline *pipeline) +{ + return pipeline->ini; +} + void cras_dsp_pipeline_run(struct pipeline *pipeline, int sample_count) { int i; diff --git a/cras/src/server/cras_dsp_pipeline.h b/cras/src/server/cras_dsp_pipeline.h index 76cedd32..1a5a85a7 100644 --- a/cras/src/server/cras_dsp_pipeline.h +++ b/cras/src/server/cras_dsp_pipeline.h @@ -119,6 +119,9 @@ int cras_dsp_pipeline_get_peak_audio_buffers(struct pipeline *pipeline); * or 0 if is has not been called */ int cras_dsp_pipeline_get_sample_rate(struct pipeline *pipeline); +/* Gets the dsp ini that corresponds to the pipeline. */ +struct ini *cras_dsp_pipeline_get_ini(struct pipeline *pipeline); + /* Processes a block of audio samples. sample_count should be no more * than DSP_BUFFER_SIZE */ void cras_dsp_pipeline_run(struct pipeline *pipeline, int sample_count); diff --git a/cras/src/server/cras_hfp_ag_profile.c b/cras/src/server/cras_hfp_ag_profile.c index 34c26826..63201914 100644 --- a/cras/src/server/cras_hfp_ag_profile.c +++ b/cras/src/server/cras_hfp_ag_profile.c @@ -22,58 +22,55 @@ #include "cras_iodev_list.h" #include "utlist.h" -#define STR(s) #s -#define VSTR(id) STR(id) - #define HFP_AG_PROFILE_NAME "Hands-Free Voice gateway" #define HFP_AG_PROFILE_PATH "/org/chromium/Cras/Bluetooth/HFPAG" #define HFP_VERSION_1_5 0x0105 #define HSP_AG_PROFILE_NAME "Headset Voice gateway" #define HSP_AG_PROFILE_PATH "/org/chromium/Cras/Bluetooth/HSPAG" #define HSP_VERSION_1_2 0x0102 - -#define HSP_AG_RECORD \ - "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" \ - "<record>" \ - " <attribute id=\"0x0001\">" \ - " <sequence>" \ - " <uuid value=\"" HSP_AG_UUID "\" />" \ - " <uuid value=\"" GENERIC_AUDIO_UUID "\" />" \ - " </sequence>" \ - " </attribute>" \ - " <attribute id=\"0x0004\">" \ - " <sequence>" \ - " <sequence>" \ - " <uuid value=\"0x0100\" />" \ - " </sequence>" \ - " <sequence>" \ - " <uuid value=\"0x0003\" />" \ - " <uint8 value=\"0x0c\" />" \ - " </sequence>" \ - " </sequence>" \ - " </attribute>" \ - " <attribute id=\"0x0005\">" \ - " <sequence>" \ - " <uuid value=\"0x1002\" />" \ - " </sequence>" \ - " </attribute>" \ - " <attribute id=\"0x0009\">" \ - " <sequence>" \ - " <sequence>" \ - " <uuid value=\"" HSP_HS_UUID "\" />" \ - " <uint16 value=\"" VSTR(HSP_VERSION_1_2) "\" />" \ - " </sequence>" \ - " </sequence>" \ - " </attribute>" \ - " <attribute id=\"0x0100\">" \ - " <text value=\"" HSP_AG_PROFILE_NAME "\" />" \ - " </attribute>" \ - " <attribute id=\"0x0301\" >" \ - " <uint8 value=\"0x01\" />" \ - " </attribute>" \ +#define HSP_VERSION_1_2_STR "0x0102" + +#define HSP_AG_RECORD \ + "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" \ + "<record>" \ + " <attribute id=\"0x0001\">" \ + " <sequence>" \ + " <uuid value=\"" HSP_AG_UUID "\" />" \ + " <uuid value=\"" GENERIC_AUDIO_UUID "\" />" \ + " </sequence>" \ + " </attribute>" \ + " <attribute id=\"0x0004\">" \ + " <sequence>" \ + " <sequence>" \ + " <uuid value=\"0x0100\" />" \ + " </sequence>" \ + " <sequence>" \ + " <uuid value=\"0x0003\" />" \ + " <uint8 value=\"0x0c\" />" \ + " </sequence>" \ + " </sequence>" \ + " </attribute>" \ + " <attribute id=\"0x0005\">" \ + " <sequence>" \ + " <uuid value=\"0x1002\" />" \ + " </sequence>" \ + " </attribute>" \ + " <attribute id=\"0x0009\">" \ + " <sequence>" \ + " <sequence>" \ + " <uuid value=\"" HSP_HS_UUID "\" />" \ + " <uint16 value=\"" HSP_VERSION_1_2_STR "\" />" \ + " </sequence>" \ + " </sequence>" \ + " </attribute>" \ + " <attribute id=\"0x0100\">" \ + " <text value=\"" HSP_AG_PROFILE_NAME "\" />" \ + " </attribute>" \ + " <attribute id=\"0x0301\" >" \ + " <uint8 value=\"0x01\" />" \ + " </attribute>" \ "</record>" - /* Object representing the audio gateway role for HFP/HSP. * Members: * idev - The input iodev for HFP/HSP. @@ -130,11 +127,6 @@ static void destroy_audio_gateway(struct audio_gateway *ag) if (ag->slc_handle) hfp_slc_destroy(ag->slc_handle); - /* If the bt device is not using a2dp, do a deeper clean up - * to force disconnect it. */ - if (!cras_bt_device_has_a2dp(ag->device)) - cras_bt_device_disconnect(ag->conn, ag->device); - free(ag); } @@ -142,7 +134,7 @@ static void destroy_audio_gateway(struct audio_gateway *ag) static int has_audio_gateway(struct cras_bt_device *device) { struct audio_gateway *ag; - DL_FOREACH(connected_ags, ag) { + DL_FOREACH (connected_ags, ag) { if (ag->device == device) return 1; } @@ -151,7 +143,10 @@ static int has_audio_gateway(struct cras_bt_device *device) static void cras_hfp_ag_release(struct cras_bt_profile *profile) { - cras_hfp_ag_suspend(); + struct audio_gateway *ag; + + DL_FOREACH (connected_ags, ag) + destroy_audio_gateway(ag); } /* Callback triggered when SLC is initialized. */ @@ -167,7 +162,7 @@ static int cras_hfp_ag_slc_initialized(struct hfp_slc_handle *handle) * codec negotiation feature means the WBS capability on headset. */ cras_server_metrics_hfp_wideband_support( - hfp_slc_get_hf_codec_negotiation_supported(handle)); + hfp_slc_get_hf_codec_negotiation_supported(handle)); /* Defer the starting of audio gateway to bt_device. */ return cras_bt_device_audio_gateway_initialized(ag->device); @@ -182,6 +177,8 @@ static int cras_hfp_ag_slc_disconnected(struct hfp_slc_handle *handle) return -EINVAL; destroy_audio_gateway(ag); + cras_bt_device_notify_profile_dropped( + ag->device, CRAS_BT_DEVICE_PROFILE_HFP_HANDSFREE); return 0; } @@ -190,62 +187,49 @@ static int check_for_conflict_ag(struct cras_bt_device *new_connected) struct audio_gateway *ag; /* Check if there's already an A2DP/HFP device. */ - DL_FOREACH(connected_ags, ag) { + DL_FOREACH (connected_ags, ag) { if (cras_bt_device_has_a2dp(ag->device)) return -1; } /* Check if there's already an A2DP-only device. */ if (cras_a2dp_connected_device() && - cras_bt_device_supports_profile( - new_connected, CRAS_BT_DEVICE_PROFILE_A2DP_SINK)) + cras_bt_device_supports_profile(new_connected, + CRAS_BT_DEVICE_PROFILE_A2DP_SINK)) return -1; return 0; } -static void possibly_remove_conflict_dev(void *data) +int cras_hfp_ag_remove_conflict(struct cras_bt_device *device) { - struct cras_bt_device *device = (struct cras_bt_device *)data; - struct audio_gateway *ag, *new_ag = NULL; - struct cras_bt_device *a2dp_device; + struct audio_gateway *ag; - /* Check if the device is still connected. */ - DL_FOREACH(connected_ags, ag) { + DL_FOREACH (connected_ags, ag) { if (ag->device == device) - new_ag = ag; - } - if (!new_ag) - return; - - /* Kick out any previously connected hfp iodev. */ - DL_FOREACH(connected_ags, ag) { - if (ag == new_ag) continue; + cras_bt_device_notify_profile_dropped( + ag->device, CRAS_BT_DEVICE_PROFILE_HFP_HANDSFREE); destroy_audio_gateway(ag); } - - /* Kick out any previously connected a2dp iodev. */ - a2dp_device = cras_a2dp_connected_device(); - if (a2dp_device && a2dp_device != device) { - cras_a2dp_suspend_connected_device(a2dp_device); - cras_bt_device_disconnect(new_ag->conn, a2dp_device); - } + return 0; } static int cras_hfp_ag_new_connection(DBusConnection *conn, - struct cras_bt_profile *profile, - struct cras_bt_device *device, - int rfcomm_fd) + struct cras_bt_profile *profile, + struct cras_bt_device *device, + int rfcomm_fd) { + struct cras_bt_adapter *adapter; struct audio_gateway *ag; int ag_features; BTLOG(btlog, BT_HFP_NEW_CONNECTION, 0, 0); if (has_audio_gateway(device)) { - syslog(LOG_ERR, "Audio gateway exists when %s connects for profile %s", - cras_bt_device_name(device), profile->name); + syslog(LOG_ERR, + "Audio gateway exists when %s connects for profile %s", + cras_bt_device_name(device), profile->name); close(rfcomm_fd); return 0; } @@ -253,25 +237,24 @@ static int cras_hfp_ag_new_connection(DBusConnection *conn, if (check_for_conflict_ag(device)) return -1; - cras_bt_device_set_append_iodev_cb(device, possibly_remove_conflict_dev); ag = (struct audio_gateway *)calloc(1, sizeof(*ag)); ag->device = device; ag->conn = conn; ag->profile = cras_bt_device_profile_from_uuid(profile->uuid); + adapter = cras_bt_device_adapter(device); /* - * If the WBS enabled flag is set, add codec negotiation feature. - * TODO(hychao): replace this check by query bluetooth stack whether - * controller supports WBS feature. + * If the WBS enabled flag is set and adapter reports wbs capability + * then add codec negotiation feature. + * TODO(hychao): AND the two conditions to let bluetooth daemon + * control whether to turn on WBS feature. */ ag_features = profile->features; - if (cras_system_get_bt_wbs_enabled()) + if (cras_system_get_bt_wbs_enabled() && + cras_bt_adapter_wbs_supported(adapter)) ag_features |= AG_CODEC_NEGOTIATION; - ag->slc_handle = hfp_slc_create(rfcomm_fd, - 0, - ag_features, - device, + ag->slc_handle = hfp_slc_create(rfcomm_fd, 0, ag_features, device, cras_hfp_ag_slc_initialized, cras_hfp_ag_slc_disconnected); DL_APPEND(connected_ags, ag); @@ -285,9 +268,13 @@ static void cras_hfp_ag_request_disconnection(struct cras_bt_profile *profile, BTLOG(btlog, BT_HFP_REQUEST_DISCONNECT, 0, 0); - DL_FOREACH(connected_ags, ag) { - if (ag->slc_handle && ag->device == device) + DL_FOREACH (connected_ags, ag) { + if (ag->slc_handle && ag->device == device) { destroy_audio_gateway(ag); + cras_bt_device_notify_profile_dropped( + ag->device, + CRAS_BT_DEVICE_PROFILE_HFP_HANDSFREE); + } } } @@ -315,17 +302,18 @@ int cras_hfp_ag_profile_create(DBusConnection *conn) } static int cras_hsp_ag_new_connection(DBusConnection *conn, - struct cras_bt_profile *profile, - struct cras_bt_device *device, - int rfcomm_fd) + struct cras_bt_profile *profile, + struct cras_bt_device *device, + int rfcomm_fd) { struct audio_gateway *ag; BTLOG(btlog, BT_HSP_NEW_CONNECTION, 0, 0); if (has_audio_gateway(device)) { - syslog(LOG_ERR, "Audio gateway exists when %s connects for profile %s", - cras_bt_device_name(device), profile->name); + syslog(LOG_ERR, + "Audio gateway exists when %s connects for profile %s", + cras_bt_device_name(device), profile->name); close(rfcomm_fd); return 0; } @@ -333,17 +321,12 @@ static int cras_hsp_ag_new_connection(DBusConnection *conn, if (check_for_conflict_ag(device)) return -1; - cras_bt_device_set_append_iodev_cb(device, possibly_remove_conflict_dev); ag = (struct audio_gateway *)calloc(1, sizeof(*ag)); ag->device = device; ag->conn = conn; ag->profile = cras_bt_device_profile_from_uuid(profile->uuid); - ag->slc_handle = hfp_slc_create(rfcomm_fd, - 1, - profile->features, - device, - NULL, - cras_hfp_ag_slc_disconnected); + ag->slc_handle = hfp_slc_create(rfcomm_fd, 1, profile->features, device, + NULL, cras_hfp_ag_slc_disconnected); DL_APPEND(connected_ags, ag); cras_hfp_ag_slc_initialized(ag->slc_handle); return 0; @@ -356,9 +339,12 @@ static void cras_hsp_ag_request_disconnection(struct cras_bt_profile *profile, BTLOG(btlog, BT_HSP_REQUEST_DISCONNECT, 0, 0); - DL_FOREACH(connected_ags, ag) { - if (ag->slc_handle && ag->device == device) + DL_FOREACH (connected_ags, ag) { + if (ag->slc_handle && ag->device == device) { destroy_audio_gateway(ag); + cras_bt_device_notify_profile_dropped( + ag->device, CRAS_BT_DEVICE_PROFILE_HSP_HEADSET); + } } } @@ -401,20 +387,18 @@ int cras_hfp_ag_start(struct cras_bt_device *device) out_aio = cras_iodev_list_get_sco_pcm_iodev(CRAS_STREAM_OUTPUT); ag->idev = hfp_alsa_iodev_create(in_aio, ag->device, - ag->slc_handle, - ag->profile); + ag->slc_handle, ag->profile); ag->odev = hfp_alsa_iodev_create(out_aio, ag->device, - ag->slc_handle, - ag->profile); + ag->slc_handle, ag->profile); } else { ag->info = hfp_info_create( - hfp_slc_get_selected_codec(ag->slc_handle)); - ag->idev = hfp_iodev_create(CRAS_STREAM_INPUT, ag->device, - ag->slc_handle, - ag->profile, ag->info); - ag->odev = hfp_iodev_create(CRAS_STREAM_OUTPUT, ag->device, - ag->slc_handle, - ag->profile, ag->info); + hfp_slc_get_selected_codec(ag->slc_handle)); + ag->idev = + hfp_iodev_create(CRAS_STREAM_INPUT, ag->device, + ag->slc_handle, ag->profile, ag->info); + ag->odev = + hfp_iodev_create(CRAS_STREAM_OUTPUT, ag->device, + ag->slc_handle, ag->profile, ag->info); } if (!ag->idev && !ag->odev) { @@ -425,13 +409,6 @@ int cras_hfp_ag_start(struct cras_bt_device *device) return 0; } -void cras_hfp_ag_suspend() -{ - struct audio_gateway *ag; - DL_FOREACH(connected_ags, ag) - destroy_audio_gateway(ag); -} - void cras_hfp_ag_suspend_connected_device(struct cras_bt_device *device) { struct audio_gateway *ag; @@ -451,7 +428,7 @@ struct hfp_slc_handle *cras_hfp_ag_get_active_handle() struct hfp_slc_handle *cras_hfp_ag_get_slc(struct cras_bt_device *device) { struct audio_gateway *ag; - DL_FOREACH(connected_ags, ag) { + DL_FOREACH (connected_ags, ag) { if (ag->device == device) return ag->slc_handle; } diff --git a/cras/src/server/cras_hfp_ag_profile.h b/cras/src/server/cras_hfp_ag_profile.h index aa60f2f7..4c1d49d2 100644 --- a/cras/src/server/cras_hfp_ag_profile.h +++ b/cras/src/server/cras_hfp_ag_profile.h @@ -12,23 +12,27 @@ #include "cras_hfp_slc.h" /* The bitmap of HFP AG feature supported by CRAS */ -#define CRAS_AG_SUPPORTED_FEATURES (AG_ENHANCED_CALL_STATUS) +#define CRAS_AG_SUPPORTED_FEATURES (AG_ENHANCED_CALL_STATUS) struct hfp_slc_handle; /* Adds a profile instance for HFP AG (Hands-Free Profile Audio Gateway). */ int cras_hfp_ag_profile_create(DBusConnection *conn); - /* Adds a profile instance for HSP AG (Headset Profile Audio Gateway). */ int cras_hsp_ag_profile_create(DBusConnection *conn); /* Starts the HFP audio gateway for audio input/output. */ int cras_hfp_ag_start(struct cras_bt_device *device); -/* Suspends all connected audio gateways, used to stop HFP/HSP audio when - * an A2DP only device is connected. */ -void cras_hfp_ag_suspend(); +/* + * Suspends all connected audio gateways except the one associated to device. + * Used to stop previously running HFP/HSP audio when a new device is connected. + * Args: + * device - The device that we want to keep connection while others should + * be removed. + */ +int cras_hfp_ag_remove_conflict(struct cras_bt_device *device); /* Suspends audio gateway associated with given bt device. */ void cras_hfp_ag_suspend_connected_device(struct cras_bt_device *device); diff --git a/cras/src/server/cras_hfp_alsa_iodev.c b/cras/src/server/cras_hfp_alsa_iodev.c index 9109a629..aecc47b9 100644 --- a/cras/src/server/cras_hfp_alsa_iodev.c +++ b/cras/src/server/cras_hfp_alsa_iodev.c @@ -87,7 +87,7 @@ static int hfp_alsa_update_supported_formats(struct cras_iodev *iodev) free(iodev->supported_channel_counts); iodev->supported_channel_counts = - malloc(2 * sizeof(*iodev->supported_channel_counts)); + malloc(2 * sizeof(*iodev->supported_channel_counts)); if (!iodev->supported_channel_counts) return -ENOMEM; iodev->supported_channel_counts[0] = 1; @@ -95,7 +95,7 @@ static int hfp_alsa_update_supported_formats(struct cras_iodev *iodev) free(iodev->supported_formats); iodev->supported_formats = - malloc(2 * sizeof(*iodev->supported_formats)); + malloc(2 * sizeof(*iodev->supported_formats)); if (!iodev->supported_formats) return -ENOMEM; iodev->supported_formats[0] = SND_PCM_FORMAT_S16_LE; @@ -117,8 +117,8 @@ static int hfp_alsa_configure_dev(struct cras_iodev *iodev) } rc = cras_bt_device_get_sco( - hfp_alsa_io->device, - hfp_slc_get_selected_codec(hfp_alsa_io->slc)); + hfp_alsa_io->device, + hfp_slc_get_selected_codec(hfp_alsa_io->slc)); if (rc < 0) { syslog(LOG_ERR, "Failed to get sco: %d\n", rc); return rc; @@ -158,8 +158,7 @@ static int hfp_alsa_delay_frames(const struct cras_iodev *iodev) } static int hfp_alsa_get_buffer(struct cras_iodev *iodev, - struct cras_audio_area **area, - unsigned *frames) + struct cras_audio_area **area, unsigned *frames) { struct hfp_alsa_io *hfp_alsa_io = (struct hfp_alsa_io *)iodev; struct cras_iodev *aio = hfp_alsa_io->aio; @@ -184,8 +183,7 @@ static int hfp_alsa_flush_buffer(struct cras_iodev *iodev) } static void hfp_alsa_update_active_node(struct cras_iodev *iodev, - unsigned node_idx, - unsigned dev_enabled) + unsigned node_idx, unsigned dev_enabled) { struct hfp_alsa_io *hfp_alsa_io = (struct hfp_alsa_io *)iodev; struct cras_iodev *aio = hfp_alsa_io->aio; @@ -236,11 +234,10 @@ static int hfp_alsa_is_free_running(const struct cras_iodev *iodev) return aio->is_free_running(aio); } -struct cras_iodev *hfp_alsa_iodev_create( - struct cras_iodev *aio, - struct cras_bt_device *device, - struct hfp_slc_handle *slc, - enum cras_bt_device_profile profile) +struct cras_iodev *hfp_alsa_iodev_create(struct cras_iodev *aio, + struct cras_bt_device *device, + struct hfp_slc_handle *slc, + enum cras_bt_device_profile profile) { struct hfp_alsa_io *hfp_alsa_io; struct cras_iodev *iodev; @@ -262,14 +259,13 @@ struct cras_iodev *hfp_alsa_iodev_create( name = cras_bt_device_name(device); if (!name) name = cras_bt_device_object_path(device); - snprintf(iodev->info.name, sizeof(iodev->info.name), - "%s.HFP_PCM", name); + snprintf(iodev->info.name, sizeof(iodev->info.name), "%s.HFP_PCM", + name); iodev->info.name[ARRAY_SIZE(iodev->info.name) - 1] = 0; - iodev->info.stable_id = SuperFastHash( - cras_bt_device_object_path(device), - strlen(cras_bt_device_object_path(device)), - strlen(cras_bt_device_object_path(device))); - iodev->info.stable_id_new = iodev->info.stable_id; + iodev->info.stable_id = + SuperFastHash(cras_bt_device_object_path(device), + strlen(cras_bt_device_object_path(device)), + strlen(cras_bt_device_object_path(device))); iodev->open_dev = hfp_alsa_open_dev; iodev->update_supported_formats = hfp_alsa_update_supported_formats; diff --git a/cras/src/server/cras_hfp_alsa_iodev.h b/cras/src/server/cras_hfp_alsa_iodev.h index a3dcf74a..e05af688 100644 --- a/cras/src/server/cras_hfp_alsa_iodev.h +++ b/cras/src/server/cras_hfp_alsa_iodev.h @@ -20,11 +20,10 @@ struct hfp_slc_handle; * * The usage of hfp_alsa_iodev is only for SCO connection over PCM/I2S. */ -struct cras_iodev *hfp_alsa_iodev_create( - struct cras_iodev *aio, - struct cras_bt_device *device, - struct hfp_slc_handle *slc, - enum cras_bt_device_profile profile); +struct cras_iodev *hfp_alsa_iodev_create(struct cras_iodev *aio, + struct cras_bt_device *device, + struct hfp_slc_handle *slc, + enum cras_bt_device_profile profile); void hfp_alsa_iodev_destroy(struct cras_iodev *iodev); diff --git a/cras/src/server/cras_hfp_info.c b/cras/src/server/cras_hfp_info.c index b9b4083c..02bc8b4c 100644 --- a/cras/src/server/cras_hfp_info.c +++ b/cras/src/server/cras_hfp_info.c @@ -11,10 +11,12 @@ #include "audio_thread.h" #include "byte_buffer.h" -#include "cras_iodev_list.h" #include "cras_hfp_info.h" #include "cras_hfp_slc.h" +#include "cras_iodev_list.h" +#include "cras_plc.h" #include "cras_sbc_codec.h" +#include "cras_server_metrics.h" #include "utlist.h" /* The max buffer size. Note that the actual used size must set to multiple @@ -28,36 +30,24 @@ #define HFP_BYTE_RATE 16000 /* Per Bluetooth Core v5.0 and HFP 1.7 specification. */ -#define MSBC_H2_HEADER_LEN 2 -#define MSBC_FRAME_LEN 57 -#define MSBC_FRAME_SIZE 59 -#define MSBC_CODE_SIZE 240 -#define MSBC_SYNC_WORD 0xAD +#define MSBC_H2_HEADER_LEN 2 +#define MSBC_FRAME_LEN 57 +#define MSBC_FRAME_SIZE 59 +#define MSBC_CODE_SIZE 240 +#define MSBC_SYNC_WORD 0xAD /* For one mSBC 1 compressed wideband audio channel the HCI packets will * be 3 octets of HCI header + 60 octets of data. */ #define MSBC_PKT_SIZE 60 -#define WRITE_BUF_SIZE_BYTES MSBC_PKT_SIZE -#define READ_BUF_SIZE_BYTES (2 * MSBC_PKT_SIZE) +#define WRITE_BUF_SIZE_BYTES MSBC_PKT_SIZE +#define HCI_SCO_HDR_SIZE_BYTES 3 +#define HCI_SCO_PKT_SIZE (MSBC_PKT_SIZE + HCI_SCO_HDR_SIZE_BYTES) -#define H2_HEADER_0 0x01 +#define H2_HEADER_0 0x01 /* Second octet of H2 header is composed by 4 bits fixed 0x8 and 4 bits * sequence number 0000, 0011, 1100, 1111. */ -static const uint8_t h2_header_frames_count[] = { - 0x08, 0x38, 0xc8, 0xf8 -}; - -/* The pre-computed zero input bit stream of mSBC codec, per HFP 1.7 spec. - * This mSBC frame will be decoded into all-zero input PCM. */ -static const uint8_t msbc_zero_frame[] = { - 0xad, 0x00, 0x00, 0xc5, 0x00, 0x00, 0x00, 0x00, 0x77, 0x6d, - 0xb6, 0xdd, 0xdb, 0x6d, 0xb7, 0x76, 0xdb, 0x6d, 0xdd, 0xb6, - 0xdb, 0x77, 0x6d, 0xb6, 0xdd, 0xdb, 0x6d, 0xb7, 0x76, 0xdb, - 0x6d, 0xdd, 0xb6, 0xdb, 0x77, 0x6d, 0xb6, 0xdd, 0xdb, 0x6d, - 0xb7, 0x76, 0xdb, 0x6d, 0xdd, 0xb6, 0xdb, 0x77, 0x6d, 0xb6, - 0xdd, 0xdb, 0x6d, 0xb7, 0x76, 0xdb, 0x6c -}; +static const uint8_t h2_header_frames_count[] = { 0x08, 0x38, 0xc8, 0xf8 }; /* Structure to hold variables for a HFP connection. Since HFP supports * bi-direction audio, two iodevs should share one hfp_info if they @@ -72,14 +62,19 @@ static const uint8_t msbc_zero_frame[] = { * playback_buf - The buffer to hold samples about to write to SCO socket. * msbc_read - mSBC codec to decode input audio in wideband speech mode. * msbc_write - mSBC codec to encode output audio in wideband speech mode. + * msbc_plc - PLC component to handle the packet loss of input audio in + * wideband speech mode. * msbc_num_out_frames - Number of total written mSBC frames. * msbc_num_in_frames - Number of total read mSBC frames. - * read_cb - Callback to call when SCO socket can read. + * msbc_num_lost_frames - Number of total lost mSBC frames. + * read_cb - Callback to call when SCO socket can read. It returns the + * number of PCM bytes read. * write_cb - Callback to call when SCO socket can write. - * read_buf - Buffer to hold input audio bytes. - * read_buf_level - Read input audio level in bytes. - * idev - The input iodev using this hfp_info. - * odev - The output iodev using this hfp_info. + * hci_sco_buf - Buffer to read one HCI SCO packet. + * input_format_bytes - The audio format bytes for input device. 0 means + * there is no input device for the hfp_info. + * output_format_bytes - The audio format bytes for output device. 0 means + * there is no output device for the hfp_info. */ struct hfp_info { int fd; @@ -90,29 +85,32 @@ struct hfp_info { struct byte_buffer *playback_buf; struct cras_audio_codec *msbc_read; struct cras_audio_codec *msbc_write; + struct cras_msbc_plc *msbc_plc; unsigned int msbc_num_out_frames; unsigned int msbc_num_in_frames; + unsigned int msbc_num_lost_frames; int (*read_cb)(struct hfp_info *info); int (*write_cb)(struct hfp_info *info); uint8_t write_buf[WRITE_BUF_SIZE_BYTES]; - uint8_t read_buf[READ_BUF_SIZE_BYTES]; - int read_buf_level; - struct cras_iodev *idev; - struct cras_iodev *odev; + uint8_t hci_sco_buf[HCI_SCO_PKT_SIZE]; + size_t input_format_bytes; + size_t output_format_bytes; }; -int hfp_info_add_iodev(struct hfp_info *info, struct cras_iodev *dev) +int hfp_info_add_iodev(struct hfp_info *info, + enum CRAS_STREAM_DIRECTION direction, + struct cras_audio_format *format) { - if (dev->direction == CRAS_STREAM_OUTPUT) { - if (info->odev) + if (direction == CRAS_STREAM_OUTPUT) { + if (info->output_format_bytes) goto invalid; - info->odev = dev; + info->output_format_bytes = cras_get_format_bytes(format); buf_reset(info->playback_buf); - } else if (dev->direction == CRAS_STREAM_INPUT) { - if (info->idev) + } else if (direction == CRAS_STREAM_INPUT) { + if (info->input_format_bytes) goto invalid; - info->idev = dev; + info->input_format_bytes = cras_get_format_bytes(format); buf_reset(info->capture_buf); } @@ -123,112 +121,121 @@ invalid: return -EINVAL; } -int hfp_info_rm_iodev(struct hfp_info *info, struct cras_iodev *dev) +int hfp_info_rm_iodev(struct hfp_info *info, + enum CRAS_STREAM_DIRECTION direction) { - if (dev->direction == CRAS_STREAM_OUTPUT && info->odev == dev) { - info->odev = NULL; - } else if (dev->direction == CRAS_STREAM_INPUT && info->idev == dev){ - info->idev = NULL; - } else + if (direction == CRAS_STREAM_OUTPUT && info->output_format_bytes) { + memset(info->playback_buf->bytes, 0, + info->playback_buf->used_size); + info->output_format_bytes = 0; + } else if (direction == CRAS_STREAM_INPUT && info->input_format_bytes) { + info->input_format_bytes = 0; + } else { return -EINVAL; + } return 0; } int hfp_info_has_iodev(struct hfp_info *info) { - return info->odev || info->idev; + return info->output_format_bytes || info->input_format_bytes; } -void hfp_buf_acquire(struct hfp_info *info, struct cras_iodev *dev, - uint8_t **buf, unsigned *count) +void hfp_buf_acquire(struct hfp_info *info, + enum CRAS_STREAM_DIRECTION direction, uint8_t **buf, + unsigned *count) { size_t format_bytes; unsigned int buf_avail; - format_bytes = cras_get_format_bytes(dev->format); - *count *= format_bytes; - - if (dev->direction == CRAS_STREAM_OUTPUT) + if (direction == CRAS_STREAM_OUTPUT && info->output_format_bytes) { *buf = buf_write_pointer_size(info->playback_buf, &buf_avail); - else + format_bytes = info->output_format_bytes; + } else if (direction == CRAS_STREAM_INPUT && info->input_format_bytes) { *buf = buf_read_pointer_size(info->capture_buf, &buf_avail); + format_bytes = info->input_format_bytes; + } else { + *count = 0; + return; + } - if (*count > buf_avail) - *count = buf_avail; - *count /= format_bytes; + if (*count * format_bytes > buf_avail) + *count = buf_avail / format_bytes; } -int hfp_buf_size(struct hfp_info *info, struct cras_iodev *dev) +int hfp_buf_size(struct hfp_info *info, enum CRAS_STREAM_DIRECTION direction) { - return info->playback_buf->used_size / cras_get_format_bytes(dev->format); + if (direction == CRAS_STREAM_OUTPUT && info->output_format_bytes) + return info->playback_buf->used_size / + info->output_format_bytes; + else if (direction == CRAS_STREAM_INPUT && info->input_format_bytes) + return info->capture_buf->used_size / info->input_format_bytes; + return 0; } -void hfp_buf_release(struct hfp_info *info, struct cras_iodev *dev, +void hfp_buf_release(struct hfp_info *info, + enum CRAS_STREAM_DIRECTION direction, unsigned written_frames) { - size_t format_bytes; - format_bytes = cras_get_format_bytes(dev->format); - - written_frames *= format_bytes; - - if (dev->direction == CRAS_STREAM_OUTPUT) - buf_increment_write(info->playback_buf, written_frames); + if (direction == CRAS_STREAM_OUTPUT && info->output_format_bytes) + buf_increment_write(info->playback_buf, + written_frames * info->output_format_bytes); + else if (direction == CRAS_STREAM_INPUT && info->input_format_bytes) + buf_increment_read(info->capture_buf, + written_frames * info->input_format_bytes); else - buf_increment_read(info->capture_buf, written_frames); + written_frames = 0; } -int hfp_buf_queued(struct hfp_info *info, const struct cras_iodev *dev) +int hfp_buf_queued(struct hfp_info *info, enum CRAS_STREAM_DIRECTION direction) { - size_t format_bytes; - format_bytes = cras_get_format_bytes(dev->format); - - if (dev->direction == CRAS_STREAM_OUTPUT) - return buf_queued(info->playback_buf) / format_bytes; + if (direction == CRAS_STREAM_OUTPUT && info->output_format_bytes) + return buf_queued(info->playback_buf) / + info->output_format_bytes; + else if (direction == CRAS_STREAM_INPUT && info->input_format_bytes) + return buf_queued(info->capture_buf) / info->input_format_bytes; else - return buf_queued(info->capture_buf) / format_bytes; + return 0; } -int hfp_fill_output_with_zeros(struct hfp_info *info, - struct cras_iodev *dev, - unsigned int nframes) +int hfp_fill_output_with_zeros(struct hfp_info *info, unsigned int nframes) { unsigned int buf_avail; - unsigned int format_bytes; unsigned int nbytes; uint8_t *buf; int i; int ret = 0; - format_bytes = cras_get_format_bytes(dev->format); - nbytes = nframes * format_bytes; - /* Loop twice to make sure ring buffer is filled. */ - for (i = 0; i < 2; i++) { - buf = buf_write_pointer_size(info->playback_buf, &buf_avail); - if (buf_avail == 0) - break; - buf_avail = MIN(nbytes, buf_avail); - memset(buf, 0, buf_avail); - buf_increment_write(info->playback_buf, buf_avail); - nbytes -= buf_avail; - ret += buf_avail / format_bytes; + if (info->output_format_bytes) { + nbytes = nframes * info->output_format_bytes; + /* Loop twice to make sure ring buffer is filled. */ + for (i = 0; i < 2; i++) { + buf = buf_write_pointer_size(info->playback_buf, + &buf_avail); + if (buf_avail == 0) + break; + buf_avail = MIN(nbytes, buf_avail); + memset(buf, 0, buf_avail); + buf_increment_write(info->playback_buf, buf_avail); + nbytes -= buf_avail; + ret += buf_avail / info->output_format_bytes; + } } return ret; } -int hfp_force_output_level(struct hfp_info *info, - struct cras_iodev *dev, - unsigned int level) +void hfp_force_output_level(struct hfp_info *info, unsigned int level) { - level *= cras_get_format_bytes(dev->format); - level = MIN(level, MAX_HFP_BUF_SIZE_BYTES); - buf_adjust_readable(info->playback_buf, level); - return 0; + if (info->output_format_bytes) { + level *= info->output_format_bytes; + level = MIN(level, MAX_HFP_BUF_SIZE_BYTES); + buf_adjust_readable(info->playback_buf, level); + } } int hfp_write_msbc(struct hfp_info *info) { - int to_write = 0; size_t encoded; int err; int pcm_encoded; @@ -243,25 +250,28 @@ int hfp_write_msbc(struct hfp_info *info) wp[0] = H2_HEADER_0; wp[1] = h2_header_frames_count[info->msbc_num_out_frames % 4]; pcm_encoded = info->msbc_write->encode( - info->msbc_write, samples, pcm_avail, - wp + MSBC_H2_HEADER_LEN, - WRITE_BUF_SIZE_BYTES - MSBC_H2_HEADER_LEN, - &encoded); + info->msbc_write, samples, pcm_avail, + wp + MSBC_H2_HEADER_LEN, + WRITE_BUF_SIZE_BYTES - MSBC_H2_HEADER_LEN, &encoded); + if (pcm_encoded < 0) { + syslog(LOG_ERR, "msbc encoding err: %s", + strerror(pcm_encoded)); + return pcm_encoded; + } buf_increment_read(info->playback_buf, pcm_encoded); pcm_avail -= pcm_encoded; } else { memset(wp, 0, WRITE_BUF_SIZE_BYTES); } - to_write = info->packet_size; msbc_send_again: - err = send(info->fd, info->write_buf, to_write, 0); + err = send(info->fd, info->write_buf, MSBC_PKT_SIZE, 0); if (err < 0) { if (errno == EINTR) goto msbc_send_again; return err; } - if (err != (int)info->packet_size) { + if (err != MSBC_PKT_SIZE) { syslog(LOG_ERR, "Partially write %d bytes for mSBC", err); return -1; } @@ -293,8 +303,8 @@ send_sample: if (err != (int)info->packet_size) { syslog(LOG_ERR, - "Partially write %d bytes for SCO packet size %u", - err, info->packet_size); + "Partially write %d bytes for SCO packet size %u", err, + info->packet_size); return -1; } @@ -303,7 +313,8 @@ send_sample: return err; } -static int h2_header_get_seq(const uint8_t *p) { +static int h2_header_get_seq(const uint8_t *p) +{ int i; for (i = 0; i < 4; i++) { if (*p == h2_header_frames_count[i]) @@ -318,60 +329,61 @@ static int h2_header_get_seq(const uint8_t *p) { * Args: * input - Pointer to input bytes read from SCO socket. * len - Length of input bytes. - * seq - To be filled by the sequence number of mSBC packet. - * frame_head - To be filled by the starting position of mSBC frame if found. + * seq_out - To be filled by the sequence number of mSBC packet. * Returns: - * The position of input bytes that has been read during the extraction. + * The starting position of mSBC frame if found. */ -static int extract_msbc_frame(const uint8_t *input, int len, - int *seq, const uint8_t **frame_head) +static const uint8_t *extract_msbc_frame(const uint8_t *input, int len, + unsigned int *seq_out) { int rp = 0; + int seq = -1; while (len - rp >= MSBC_FRAME_SIZE) { if ((input[rp] != H2_HEADER_0) || (input[rp + 2] != MSBC_SYNC_WORD)) { rp++; continue; } - *seq = h2_header_get_seq(input + rp + 1); - if (*seq < 0) { + seq = h2_header_get_seq(input + rp + 1); + if (seq < 0) { rp++; continue; } - *frame_head = input + rp; - break; + // `seq` is guaranteed to be positive now. + *seq_out = (unsigned int)seq; + return input + rp; } - return rp; + return NULL; } /* * Handle the case when mSBC frame is considered lost. * Args: - * msbc - The mSBC codec handles audio input. - * capture_buf - The buf to store decoded PCM audio. - * pcm_avail - Available room of capture_buf in bytes. + * info - The hfp_info instance holding mSBC codec and PLC objects. */ -static int handle_packet_loss(struct cras_audio_codec *msbc, - uint8_t *capture_buf, unsigned int pcm_avail) +static int handle_packet_loss(struct hfp_info *info) { - size_t pcm_decoded = 0; int decoded; + unsigned int pcm_avail; + uint8_t *in_bytes; - /* - * Handle packet loss by feeding one zero input bit stream of mSBC. - * TODO(enshuo): add PLC. - */ - decoded = msbc->decode( - msbc, - msbc_zero_frame, - MSBC_FRAME_LEN, - capture_buf, - pcm_avail, - &pcm_decoded); + /* It's possible client doesn't consume data causing overrun. In that + * case we treat it as one mSBC frame read but dropped. */ + info->msbc_num_in_frames++; + info->msbc_num_lost_frames++; + + in_bytes = buf_write_pointer_size(info->capture_buf, &pcm_avail); + if (pcm_avail < MSBC_CODE_SIZE) + return 0; + + decoded = cras_msbc_plc_handle_bad_frames(info->msbc_plc, + info->msbc_read, in_bytes); if (decoded < 0) return decoded; - return pcm_decoded; + buf_increment_write(info->capture_buf, decoded); + + return decoded; } int hfp_read_msbc(struct hfp_info *info) @@ -379,22 +391,16 @@ int hfp_read_msbc(struct hfp_info *info) int err = 0; unsigned int pcm_avail = 0; int decoded; - int rp = 0; size_t pcm_decoded = 0; + size_t pcm_read = 0; uint8_t *capture_buf; const uint8_t *frame_head = NULL; - int seq; - - /* Check if there's room for more PCM. */ - capture_buf = buf_write_pointer_size(info->capture_buf, &pcm_avail); - if (pcm_avail < MSBC_CODE_SIZE) - return 0; + unsigned int seq; recv_msbc_bytes: - err = recv(info->fd, info->read_buf + info->read_buf_level, - info->packet_size, 0); + err = recv(info->fd, info->hci_sco_buf, HCI_SCO_PKT_SIZE, 0); if (err < 0) { - syslog(LOG_ERR, "mSBC read err %s", strerror(errno)); + syslog(LOG_ERR, "HCI SCO packet read err %s", strerror(errno)); if (errno == EINTR) goto recv_msbc_bytes; return err; @@ -403,64 +409,74 @@ recv_msbc_bytes: * Treat return code 0 (socket shutdown) as error here. BT stack * shall send signal to main thread for device disconnection. */ - if (err != (int)info->packet_size) { + if (err != HCI_SCO_PKT_SIZE) { syslog(LOG_ERR, "Partially read %d bytes for mSBC packet", err); return -1; } - info->read_buf_level += err; - rp = extract_msbc_frame(info->read_buf, info->read_buf_level, - &seq, &frame_head); + /* + * HCI SCO packet status flag: + * 0x00 - correctly received data. + * 0x01 - possibly invalid data. + * 0x10 - No data received. + * 0x11 - Data partially lost. + */ + err = (info->hci_sco_buf[1] >> 4); + if (err) { + syslog(LOG_ERR, "HCI SCO status flag %u", err); + return handle_packet_loss(info); + } + + /* There is chance that erroneous data reporting gives us false positive. + * If mSBC frame extraction fails, we shall handle it as packet loss. + */ + frame_head = + extract_msbc_frame(info->hci_sco_buf + HCI_SCO_HDR_SIZE_BYTES, + MSBC_PKT_SIZE, &seq); if (!frame_head) { - info->read_buf_level -= rp; - memmove(info->read_buf, info->read_buf + rp, - info->read_buf_level); - return err; + syslog(LOG_ERR, "Failed to extract msbc frame"); + return handle_packet_loss(info); } /* * Consider packet loss when found discontinuity in sequence number. - * TODO(hychao): Integrate with erroneous data reporting feature from - * controller that sets packet statue flag on HCI SCO packet. */ while (seq != (info->msbc_num_in_frames % 4)) { - err = handle_packet_loss(info->msbc_read, - capture_buf, - pcm_avail); + syslog(LOG_ERR, "SCO packet seq unmatch"); + err = handle_packet_loss(info); if (err < 0) return err; - buf_increment_write(info->capture_buf, err); - info->msbc_num_in_frames++; + pcm_read += err; } - decoded = info->msbc_read->decode( - info->msbc_read, - frame_head + MSBC_H2_HEADER_LEN, - MSBC_FRAME_LEN, - capture_buf, - pcm_avail, - &pcm_decoded); + /* Check if there's room for more PCM. */ + capture_buf = buf_write_pointer_size(info->capture_buf, &pcm_avail); + if (pcm_avail < MSBC_CODE_SIZE) + return pcm_read; + + decoded = info->msbc_read->decode(info->msbc_read, + frame_head + MSBC_H2_HEADER_LEN, + MSBC_FRAME_LEN, capture_buf, + pcm_avail, &pcm_decoded); if (decoded < 0) { /* * If mSBC frame cannot be decoded, consider this packet is * corrupted and lost. */ - err = handle_packet_loss(info->msbc_read, - capture_buf, - pcm_avail); + syslog(LOG_ERR, "mSBC decode failed"); + err = handle_packet_loss(info); if (err < 0) return err; - pcm_decoded = err; + pcm_read += err; + } else { + /* Good mSBC frame decoded. */ + buf_increment_write(info->capture_buf, pcm_decoded); + info->msbc_num_in_frames++; + cras_msbc_plc_handle_good_frames(info->msbc_plc, capture_buf, + capture_buf); + pcm_read += pcm_decoded; } - - rp += MSBC_FRAME_SIZE; - buf_increment_write(info->capture_buf, pcm_decoded); - info->msbc_num_in_frames++; - - info->read_buf_level -= rp; - memmove(info->read_buf, info->read_buf + rp, info->read_buf_level); - - return 0; + return pcm_read; } int hfp_read(struct hfp_info *info) @@ -494,7 +510,8 @@ recv_sample: if (err && (info->packet_size == info->mtu)) { info->packet_size = err; } else { - syslog(LOG_ERR, "Partially read %d bytes for %u size SCO packet", + syslog(LOG_ERR, + "Partially read %d bytes for %u size SCO packet", err, info->packet_size); return -1; } @@ -528,16 +545,22 @@ static int hfp_info_callback(void *arg) goto read_write_error; } - /* Ignore the MTU bytes just read if input dev not in present */ - if (!info->idev) - buf_increment_read(info->capture_buf, info->packet_size); + /* Ignore the bytes just read if input dev not in present */ + if (!info->input_format_bytes) + buf_increment_read(info->capture_buf, err); - if (info->odev) { - err = info->write_cb(info); - if (err < 0) { - syslog(LOG_ERR, "Write error"); - goto read_write_error; - } + /* Without output stream's presence, we shall still send zero packets + * to HF. This is required for some HF devices to start sending non-zero + * data to AG. + */ + if (!info->output_format_bytes) + buf_increment_write(info->playback_buf, + info->msbc_write ? err : info->packet_size); + + err = info->write_cb(info); + if (err < 0) { + syslog(LOG_ERR, "Write error"); + goto read_write_error; } return 0; @@ -575,6 +598,7 @@ struct hfp_info *hfp_info_create(int codec) info->read_cb = hfp_read_msbc; info->msbc_read = cras_msbc_codec_create(); info->msbc_write = cras_msbc_codec_create(); + info->msbc_plc = cras_msbc_plc_create(); } else { info->write_cb = hfp_write; info->read_cb = hfp_read; @@ -610,10 +634,10 @@ int hfp_info_start(int fd, unsigned int mtu, struct hfp_info *info) audio_thread_add_callback(info->fd, hfp_info_callback, info); - info->read_buf_level = 0; info->started = 1; info->msbc_num_out_frames = 0; info->msbc_num_in_frames = 0; + info->msbc_num_lost_frames = 0; return 0; } @@ -623,14 +647,19 @@ int hfp_info_stop(struct hfp_info *info) if (!info->started) return 0; - audio_thread_rm_callback_sync( - cras_iodev_list_get_audio_thread(), - info->fd); + audio_thread_rm_callback_sync(cras_iodev_list_get_audio_thread(), + info->fd); close(info->fd); info->fd = 0; info->started = 0; + if (info->msbc_num_in_frames) { + cras_server_metrics_hfp_packet_loss( + (float)info->msbc_num_lost_frames / + info->msbc_num_in_frames); + } + return 0; } @@ -646,6 +675,8 @@ void hfp_info_destroy(struct hfp_info *info) cras_sbc_codec_destroy(info->msbc_read); if (info->msbc_write) cras_sbc_codec_destroy(info->msbc_write); + if (info->msbc_plc) + cras_msbc_plc_destroy(info->msbc_plc); free(info); } diff --git a/cras/src/server/cras_hfp_info.h b/cras/src/server/cras_hfp_info.h index d40fc285..334278e5 100644 --- a/cras/src/server/cras_hfp_info.h +++ b/cras/src/server/cras_hfp_info.h @@ -6,10 +6,9 @@ #ifndef CRAS_HFP_INFO_H_ #define CRAS_HFP_INFO_H_ -#include "cras_iodev.h" +#include "cras_audio_format.h" #include "cras_types.h" - /* Linked list to hold the information of callbacks to trigger * when the size of SCO packet has changed. */ @@ -49,76 +48,74 @@ int hfp_info_stop(struct hfp_info *info); /* Queries how many frames of data are queued. * Args: * info - The hfp_info holding the buffer to query. - * dev - The iodev to indicate which buffer to query, playback - * or capture, depending on its direction. + * direction - The direction to indicate which buffer to query, playback + * or capture. */ -int hfp_buf_queued(struct hfp_info *info, const struct cras_iodev *dev); +int hfp_buf_queued(struct hfp_info *info, enum CRAS_STREAM_DIRECTION direction); /* Fill output buffer with zero frames. * Args: * info - The hfp_info holding the output buffer. - * dev - The associated output device. * nframes - How many zero frames to fill. * Returns: * The actual number of zero frames filled. */ -int hfp_fill_output_with_zeros(struct hfp_info *info, - struct cras_iodev *dev, - unsigned int nframes); +int hfp_fill_output_with_zeros(struct hfp_info *info, unsigned int nframes); /* Force output buffer level to given value. Calling this may override * existing data so use it only when buffer has been filled by zeros. + * If no output device was added, calling this has no effect. * Args: * info - The hfp_info holding output buffer. - * dev - The associated output device. * level - Value of the target output level. - * Returns: - * 0 for success, otherwise failure. */ -int hfp_force_output_level(struct hfp_info *info, - struct cras_iodev *dev, - unsigned int level); +void hfp_force_output_level(struct hfp_info *info, unsigned int level); -/* Gets how many bytes of the buffer are used. +/* Gets how many frames of the buffer are used. * Args: * info - The hfp_info holding buffer. - * dev - The iodev which uses the buffer. + * direction - The direction of the buffer. */ -int hfp_buf_size(struct hfp_info *info, struct cras_iodev *dev); +int hfp_buf_size(struct hfp_info *info, enum CRAS_STREAM_DIRECTION direction); /* Acquire buffer of count frames for dev to write(or read, * depend on dev's direction). * Args: * info - The hfp_info holding buffer. - * dev - The iodev to acquire buffer for. + * direction - The direction of dev to acquire buffer for. * buf - To hold the returned pointer of acquired buffer. * count - Number of bytes of buffer to acquire, will be filled with the * actual acquired buffer size in bytes. */ -void hfp_buf_acquire(struct hfp_info *info, struct cras_iodev *dev, - uint8_t **buf, unsigned *count); +void hfp_buf_acquire(struct hfp_info *info, + enum CRAS_STREAM_DIRECTION direction, uint8_t **buf, + unsigned *count); /* Releases the previously acquired buffer. * Args: * info - The hfp_info holding the buffer. - * dev - The iodev who releases buffer. + * direction - The direction of dev to release buffer for. * written_frames - The size of the previously acquired buffer in frames * which's been used. */ -void hfp_buf_release(struct hfp_info *info, struct cras_iodev *dev, +void hfp_buf_release(struct hfp_info *info, + enum CRAS_STREAM_DIRECTION direction, unsigned written_frames); /* Adds cras_iodev to given hfp_info. Only when an output iodev is added, * hfp_info starts sending samples to the SCO socket. Similarly, only when an * input iodev is added, it starts to read samples from SCO socket. */ -int hfp_info_add_iodev(struct hfp_info *info, struct cras_iodev *dev); +int hfp_info_add_iodev(struct hfp_info *info, + enum CRAS_STREAM_DIRECTION direction, + struct cras_audio_format *format); /* Removes cras_iodev from hfp_info. hfp_info will stop sending or * reading samples right after the iodev is removed. This function is used for * iodev closure. */ -int hfp_info_rm_iodev(struct hfp_info *info, struct cras_iodev *dev); +int hfp_info_rm_iodev(struct hfp_info *info, + enum CRAS_STREAM_DIRECTION direction); /* Checks if there's any iodev added to the given hfp_info. */ int hfp_info_has_iodev(struct hfp_info *info); diff --git a/cras/src/server/cras_hfp_iodev.c b/cras/src/server/cras_hfp_iodev.c index 96ac34ae..08e26d6d 100644 --- a/cras/src/server/cras_hfp_iodev.c +++ b/cras/src/server/cras_hfp_iodev.c @@ -51,8 +51,9 @@ static int update_supported_formats(struct cras_iodev *iodev) iodev->supported_rates = (size_t *)malloc(2 * sizeof(size_t)); iodev->supported_rates[0] = - (hfp_slc_get_selected_codec(hfpio->slc) == HFP_CODEC_ID_MSBC) - ? 16000 : 8000; + (hfp_slc_get_selected_codec(hfpio->slc) == HFP_CODEC_ID_MSBC) ? + 16000 : + 8000; iodev->supported_rates[1] = 0; free(iodev->supported_channel_counts); @@ -81,19 +82,17 @@ static int no_stream(struct cras_iodev *iodev, int enable) hw_level = iodev->frames_queued(iodev, &hw_tstamp); if (enable) { - if (!hfpio->drain_complete && - (hw_level <= hfpio->filled_zeros)) + if (!hfpio->drain_complete && (hw_level <= hfpio->filled_zeros)) hfpio->drain_complete = 1; - hfpio->filled_zeros += - hfp_fill_output_with_zeros(hfpio->info, iodev, - iodev->buffer_size); + hfpio->filled_zeros += hfp_fill_output_with_zeros( + hfpio->info, iodev->buffer_size); return 0; } /* Leave no stream state.*/ level_target = iodev->min_cb_level; if (hfpio->drain_complete) { - hfp_force_output_level(hfpio->info, iodev, level_target); + hfp_force_output_level(hfpio->info, level_target); } else { unsigned int valid_samples = 0; if (hw_level > hfpio->filled_zeros) @@ -101,11 +100,10 @@ static int no_stream(struct cras_iodev *iodev, int enable) level_target = MAX(level_target, valid_samples); if (level_target > hw_level) - hfp_fill_output_with_zeros(hfpio->info, iodev, + hfp_fill_output_with_zeros(hfpio->info, level_target - hw_level); else - hfp_force_output_level(hfpio->info, iodev, - level_target); + hfp_force_output_level(hfpio->info, level_target); } hfpio->drain_complete = 0; hfpio->filled_zeros = 0; @@ -124,7 +122,7 @@ static int frames_queued(const struct cras_iodev *iodev, /* Do not enable timestamp mechanism on HFP device because last time * stamp might be a long time ago and it is not really useful. */ clock_gettime(CLOCK_MONOTONIC_RAW, tstamp); - return hfp_buf_queued(hfpio->info, iodev); + return hfp_buf_queued(hfpio->info, iodev->direction); } static int configure_dev(struct cras_iodev *iodev) @@ -141,14 +139,13 @@ static int configure_dev(struct cras_iodev *iodev) if (hfp_info_running(hfpio->info)) goto add_dev; - sk = cras_bt_device_sco_connect( - hfpio->device, - hfp_slc_get_selected_codec(hfpio->slc)); + sk = cras_bt_device_sco_connect(hfpio->device, + hfp_slc_get_selected_codec(hfpio->slc)); if (sk < 0) goto error; - mtu = cras_bt_device_sco_packet_size(hfpio->device, sk, - hfp_slc_get_selected_codec(hfpio->slc)); + mtu = cras_bt_device_sco_packet_size( + hfpio->device, sk, hfp_slc_get_selected_codec(hfpio->slc)); /* Start hfp_info */ err = hfp_info_start(sk, mtu, hfpio->info); @@ -158,10 +155,10 @@ static int configure_dev(struct cras_iodev *iodev) hfpio->drain_complete = 0; hfpio->filled_zeros = 0; add_dev: - hfp_info_add_iodev(hfpio->info, iodev); + hfp_info_add_iodev(hfpio->info, iodev->direction, iodev->format); hfp_set_call_status(hfpio->slc, 1); - iodev->buffer_size = hfp_buf_size(hfpio->info, iodev); + iodev->buffer_size = hfp_buf_size(hfpio->info, iodev->direction); return 0; error: @@ -173,7 +170,7 @@ static int close_dev(struct cras_iodev *iodev) { struct hfp_io *hfpio = (struct hfp_io *)iodev; - hfp_info_rm_iodev(hfpio->info, iodev); + hfp_info_rm_iodev(hfpio->info, iodev->direction); if (hfp_info_running(hfpio->info) && !hfp_info_has_iodev(hfpio->info)) { hfp_info_stop(hfpio->info); hfp_set_call_status(hfpio->slc, 0); @@ -191,7 +188,8 @@ static void set_hfp_volume(struct cras_iodev *iodev) volume = cras_system_get_volume(); if (iodev->active_node) - volume = cras_iodev_adjust_node_volume(iodev->active_node, volume); + volume = cras_iodev_adjust_node_volume(iodev->active_node, + volume); hfp_event_speaker_gain(hfpio->slc, volume); } @@ -203,8 +201,7 @@ static int delay_frames(const struct cras_iodev *iodev) return frames_queued(iodev, &tstamp); } -static int get_buffer(struct cras_iodev *iodev, - struct cras_audio_area **area, +static int get_buffer(struct cras_iodev *iodev, struct cras_audio_area **area, unsigned *frames) { struct hfp_io *hfpio = (struct hfp_io *)iodev; @@ -213,7 +210,7 @@ static int get_buffer(struct cras_iodev *iodev, if (!hfp_info_running(hfpio->info)) return -1; - hfp_buf_acquire(hfpio->info, iodev, &dst, frames); + hfp_buf_acquire(hfpio->info, iodev->direction, &dst, frames); iodev->area->frames = *frames; /* HFP is mono only. */ @@ -232,7 +229,7 @@ static int put_buffer(struct cras_iodev *iodev, unsigned nwritten) if (!hfp_info_running(hfpio->info)) return -1; - hfp_buf_release(hfpio->info, iodev, nwritten); + hfp_buf_release(hfpio->info, iodev->direction, nwritten); return 0; } @@ -242,8 +239,8 @@ static int flush_buffer(struct cras_iodev *iodev) unsigned nframes; if (iodev->direction == CRAS_STREAM_INPUT) { - nframes = hfp_buf_queued(hfpio->info, iodev); - hfp_buf_release(hfpio->info, iodev, nframes); + nframes = hfp_buf_queued(hfpio->info, iodev->direction); + hfp_buf_release(hfpio->info, iodev->direction, nframes); } return 0; } @@ -267,12 +264,11 @@ void hfp_free_resources(struct hfp_io *hfpio) cras_iodev_free_resources(&hfpio->base); } -struct cras_iodev *hfp_iodev_create( - enum CRAS_STREAM_DIRECTION dir, - struct cras_bt_device *device, - struct hfp_slc_handle *slc, - enum cras_bt_device_profile profile, - struct hfp_info *info) +struct cras_iodev *hfp_iodev_create(enum CRAS_STREAM_DIRECTION dir, + struct cras_bt_device *device, + struct hfp_slc_handle *slc, + enum cras_bt_device_profile profile, + struct hfp_info *info) { struct hfp_io *hfpio; struct cras_iodev *iodev; @@ -296,13 +292,12 @@ struct cras_iodev *hfp_iodev_create( snprintf(iodev->info.name, sizeof(iodev->info.name), "%s", name); iodev->info.name[ARRAY_SIZE(iodev->info.name) - 1] = 0; - iodev->info.stable_id = SuperFastHash( - cras_bt_device_object_path(device), - strlen(cras_bt_device_object_path(device)), - strlen(cras_bt_device_object_path(device))); - iodev->info.stable_id_new = iodev->info.stable_id; + iodev->info.stable_id = + SuperFastHash(cras_bt_device_object_path(device), + strlen(cras_bt_device_object_path(device)), + strlen(cras_bt_device_object_path(device))); - iodev->configure_dev= configure_dev; + iodev->configure_dev = configure_dev; iodev->frames_queued = frames_queued; iodev->delay_frames = delay_frames; iodev->get_buffer = get_buffer; diff --git a/cras/src/server/cras_hfp_iodev.h b/cras/src/server/cras_hfp_iodev.h index 3a073d00..b2762bef 100644 --- a/cras/src/server/cras_hfp_iodev.h +++ b/cras/src/server/cras_hfp_iodev.h @@ -15,12 +15,11 @@ struct hfp_slc_handle; /* * Creates an hfp iodev. */ -struct cras_iodev *hfp_iodev_create( - enum CRAS_STREAM_DIRECTION dir, - struct cras_bt_device *device, - struct hfp_slc_handle *slc, - enum cras_bt_device_profile profile, - struct hfp_info *info); +struct cras_iodev *hfp_iodev_create(enum CRAS_STREAM_DIRECTION dir, + struct cras_bt_device *device, + struct hfp_slc_handle *slc, + enum cras_bt_device_profile profile, + struct hfp_info *info); void hfp_iodev_destroy(struct cras_iodev *iodev); diff --git a/cras/src/server/cras_hfp_slc.c b/cras/src/server/cras_hfp_slc.c index d7d56e36..6b30a0b3 100644 --- a/cras/src/server/cras_hfp_slc.c +++ b/cras/src/server/cras_hfp_slc.c @@ -15,33 +15,36 @@ #include "cras_system_state.h" #include "cras_tm.h" -#define STR(s) #s -#define VSTR(id) STR(id) +/* Message start and end with "\r\n". refer to spec 4.33. */ +#define AT_CMD(cmd) "\r\n" cmd "\r\n" +/* The timeout between service level initialized and codec negotiation + * completed. */ +#define CODEC_NEGOTIATION_TIMEOUT_MS 500 #define SLC_BUF_SIZE_BYTES 256 /* Indicator update command response and indicator indices. * Note that indicator index starts from '1'. */ -#define BATTERY_IND_INDEX 1 -#define SIGNAL_IND_INDEX 2 -#define SERVICE_IND_INDEX 3 -#define CALL_IND_INDEX 4 -#define CALLSETUP_IND_INDEX 5 -#define CALLHELD_IND_INDEX 6 -#define INDICATOR_UPDATE_RSP \ - "+CIND: " \ - "(\"battchg\",(0-5))," \ - "(\"signal\",(0-5))," \ - "(\"service\",(0,1))," \ - "(\"call\",(0,1))," \ - "(\"callsetup\",(0-3))," \ - "(\"callheld\",(0-2))," \ - "(\"roam\",(0,1))" \ +#define BATTERY_IND_INDEX 1 +#define SIGNAL_IND_INDEX 2 +#define SERVICE_IND_INDEX 3 +#define CALL_IND_INDEX 4 +#define CALLSETUP_IND_INDEX 5 +#define CALLHELD_IND_INDEX 6 +#define INDICATOR_UPDATE_RSP \ + "+CIND: " \ + "(\"battchg\",(0-5))," \ + "(\"signal\",(0-5))," \ + "(\"service\",(0,1))," \ + "(\"call\",(0,1))," \ + "(\"callsetup\",(0-3))," \ + "(\"callheld\",(0-2))," \ + "(\"roam\",(0,1))" \ "" /* Mode values for standard event reporting activation/deactivation AT * command AT+CMER. Used for indicator events reporting in HFP. */ -#define FORWARD_UNSOLICIT_RESULT_CODE 3 +#define FORWARD_UNSOLICIT_RESULT_CODE 3 /* Handle object to hold required info to initialize and maintain * an HFP service level connection. @@ -61,7 +64,14 @@ * hf_codec_supported - Flags to indicate if codec is supported in HF. * hf_supports_codec_negotiation - If the connected HF supports codec * negotiation. - * selected_codec - The selected codec id to use, default to CVSD. + * preferred_codec - CVSD or mSBC based on the situation and strategy. This + * need not to be equal to selected_codec because codec negotiation + * process may fail. + * selected_codec - The codec id defaults to HFP_CODEC_UNUSED and changes + * only if codec negotiation is supported and the negotiation flow + * has completed. + * pending_codec_negotiation - True if codec negotiation process has started + * but haven't got reply from HF. * telephony - A reference of current telephony handle. * device - The associated bt device. */ @@ -82,7 +92,9 @@ struct hfp_slc_handle { int ag_supported_features; bool hf_codec_supported[HFP_MAX_CODECS]; int hf_supports_codec_negotiation; + int preferred_codec; int selected_codec; + int pending_codec_negotiation; struct cras_bt_device *device; struct cras_timer *timer; @@ -92,7 +104,7 @@ struct hfp_slc_handle { /* AT command exchanges between AG(Audio gateway) and HF(Hands-free device) */ struct at_command { const char *cmd; - int (*callback) (struct hfp_slc_handle *handle, const char *cmd); + int (*callback)(struct hfp_slc_handle *handle, const char *cmd); }; /* Sends a response or command to HF */ @@ -103,47 +115,35 @@ static int hfp_send(struct hfp_slc_handle *handle, const char *buf) if (handle->rfcomm_fd < 0) return -EIO; - /* Message start and end with "\r\n". refer to spec 4.33. */ - err = write(handle->rfcomm_fd, "\r\n", 2); - if (err < 0) - return -errno; - len = strlen(buf); written = 0; while (written < len) { - err = write(handle->rfcomm_fd, - buf + written, len - written); + err = write(handle->rfcomm_fd, buf + written, len - written); if (err < 0) return -errno; written += err; } - err = write(handle->rfcomm_fd, "\r\n", 2); - if (err < 0) - return -errno; - return 0; } /* Sends a response for indicator event reporting. */ static int hfp_send_ind_event_report(struct hfp_slc_handle *handle, - int ind_index, - int value) + int ind_index, int value) { char cmd[64]; if (handle->is_hsp || !handle->ind_event_report) return 0; - snprintf(cmd, 64, "+CIEV: %d,%d", ind_index, value); + snprintf(cmd, 64, AT_CMD("+CIEV: %d,%d"), ind_index, value); return hfp_send(handle, cmd); } /* Sends calling line identification unsolicited result code and * standard call waiting notification. */ static int hfp_send_calling_line_identification(struct hfp_slc_handle *handle, - const char *number, - int type) + const char *number, int type) { char cmd[64]; @@ -151,9 +151,9 @@ static int hfp_send_calling_line_identification(struct hfp_slc_handle *handle, return 0; if (handle->telephony->call) { - snprintf(cmd, 64, "+CCWA: \"%s\",%d", number, type); + snprintf(cmd, 64, AT_CMD("+CCWA: \"%s\",%d"), number, type); } else { - snprintf(cmd, 64, "+CLIP: \"%s\",%d", number, type); + snprintf(cmd, 64, AT_CMD("+CLIP: \"%s\",%d"), number, type); } return hfp_send(handle, cmd); } @@ -162,7 +162,7 @@ static int hfp_send_calling_line_identification(struct hfp_slc_handle *handle, static int answer_call(struct hfp_slc_handle *handle, const char *cmd) { int rc; - rc = hfp_send(handle, "OK"); + rc = hfp_send(handle, AT_CMD("OK")); if (rc) return rc; @@ -173,7 +173,7 @@ static int answer_call(struct hfp_slc_handle *handle, const char *cmd) * Mandatory support per spec 4.21. */ static int call_waiting_notify(struct hfp_slc_handle *handle, const char *buf) { - return hfp_send(handle, "OK"); + return hfp_send(handle, AT_CMD("OK")); } /* AT+CLIP command to enable the "Calling Line Identification notification" @@ -182,7 +182,7 @@ static int call_waiting_notify(struct hfp_slc_handle *handle, const char *buf) static int cli_notification(struct hfp_slc_handle *handle, const char *cmd) { handle->cli_active = (cmd[8] == '1'); - return hfp_send(handle, "OK"); + return hfp_send(handle, AT_CMD("OK")); } /* ATDdd...dd command to place call with supplied number, or ATD>nnn... @@ -200,15 +200,15 @@ static int dial_number(struct hfp_slc_handle *handle, const char *cmd) * ATD>nnn...; and lookup. */ int memory_location; memory_location = strtol(cmd + 4, NULL, 0); - if (handle->telephony->dial_number == NULL || memory_location != 1) - return hfp_send(handle, "ERROR"); - } - else { + if (handle->telephony->dial_number == NULL || + memory_location != 1) + return hfp_send(handle, AT_CMD("ERROR")); + } else { /* ATDddddd; Store dial number to the only memory slot. */ cras_telephony_store_dial_number(cmd_len - 3 - 1, cmd + 3); } - rc = hfp_send(handle, "OK"); + rc = hfp_send(handle, AT_CMD("OK")); if (rc) return rc; @@ -219,7 +219,18 @@ static int dial_number(struct hfp_slc_handle *handle, const char *cmd) /* AT+VTS command to generate a DTMF code. Mandatory per spec 4.27. */ static int dtmf_tone(struct hfp_slc_handle *handle, const char *buf) { - return hfp_send(handle, "OK"); + return hfp_send(handle, AT_CMD("OK")); +} + +/* Sends +BCS command to tell HF about our preferred codec. This shall + * be called only if codec negotiation is supported. + */ +static void select_preferred_codec(struct hfp_slc_handle *handle) +{ + char buf[64]; + snprintf(buf, 64, AT_CMD("+BCS:%d"), handle->preferred_codec); + hfp_send(handle, buf); + BTLOG(btlog, BT_CODEC_SELECTION, 0, handle->preferred_codec); } /* Marks SLC handle as initialized and trigger HFP AG's init_cb. */ @@ -228,19 +239,48 @@ static void initialize_slc_handle(struct cras_timer *timer, void *arg) struct hfp_slc_handle *handle = (struct hfp_slc_handle *)arg; if (timer) handle->timer = NULL; + + /* + * Catch the case if mSBC codec negotiation never complete or even + * failed. AG side falls back to use codec CVSD and also tells + * HF to select CVSD again. + */ + if ((handle->selected_codec == HFP_CODEC_UNUSED) && + handle->hf_codec_supported[HFP_CODEC_ID_MSBC]) { + handle->preferred_codec = HFP_CODEC_ID_CVSD; + select_preferred_codec(handle); + } + + /* + * Codec negotiation is considered to be ended at this point. + * The owner of init_cb may use hfp_slc_get_selected_codec() to + * query the final codec to use for this connection. + */ if (handle->init_cb) { handle->init_cb(handle); handle->init_cb = NULL; } } +/* Tasks to execute after receiving an AT command. This is useful because + * some HF replies to command X only after it sends command Y. We rely on + * this function to achieve reliable codec negotiation. + */ +static void post_at_command_tasks(struct hfp_slc_handle *handle) +{ + if (handle->pending_codec_negotiation) + select_preferred_codec(handle); +} + /* Handles the event that headset request to select specific codec. */ static int bluetooth_codec_selection(struct hfp_slc_handle *handle, const char *cmd) { char *tokens = strdup(cmd); char *codec; + int err; + handle->pending_codec_negotiation = 0; strtok(tokens, "="); codec = strtok(NULL, ","); @@ -249,10 +289,10 @@ static int bluetooth_codec_selection(struct hfp_slc_handle *handle, handle->selected_codec = atoi(codec); } + err = hfp_send(handle, AT_CMD("OK")); initialize_slc_handle(NULL, (void *)handle); - free(tokens); - return 0; + return err; } /* @@ -261,19 +301,20 @@ static int bluetooth_codec_selection(struct hfp_slc_handle *handle, */ static void choose_codec_and_init_slc(struct hfp_slc_handle *handle) { - if (handle->hf_supports_codec_negotiation && handle->hf_codec_supported[HFP_CODEC_ID_MSBC]) { - hfp_send(handle, "+BCS:" VSTR(HFP_CODEC_ID_MSBC)); - BTLOG(btlog, BT_CODEC_SELECTION, 0, HFP_CODEC_ID_MSBC); + /* Sets preferred codec to mSBC, and schedule callback to + * select preferred codec until reply received or timeout. + */ + handle->preferred_codec = HFP_CODEC_ID_MSBC; + handle->pending_codec_negotiation = 1; /* Delay init to give headset some time to confirm * codec selection. */ - handle->timer = cras_tm_create_timer( - cras_system_state_get_tm(), - 150, - initialize_slc_handle, - handle); + handle->timer = + cras_tm_create_timer(cras_system_state_get_tm(), + CODEC_NEGOTIATION_TIMEOUT_MS, + initialize_slc_handle, handle); } else { initialize_slc_handle(NULL, (void *)handle); } @@ -301,7 +342,7 @@ static int available_codecs(struct hfp_slc_handle *handle, const char *cmd) } free(tokens); - return hfp_send(handle, "OK"); + return hfp_send(handle, AT_CMD("OK")); } /* AT+CMER command enables the registration status update function in AG. @@ -338,7 +379,7 @@ static int event_reporting(struct hfp_slc_handle *handle, const char *cmd) if (atoi(mode) == FORWARD_UNSOLICIT_RESULT_CODE) handle->ind_event_report = atoi(tmp); - err = hfp_send(handle, "OK"); + err = hfp_send(handle, AT_CMD("OK")); if (err) { syslog(LOG_ERR, "Error sending response for command %s", cmd); goto event_reporting_done; @@ -363,7 +404,7 @@ event_reporting_done: */ static int extended_errors(struct hfp_slc_handle *handle, const char *buf) { - return hfp_send(handle, "OK"); + return hfp_send(handle, AT_CMD("OK")); } /* AT+CKPD command to handle the user initiated action from headset profile @@ -371,7 +412,7 @@ static int extended_errors(struct hfp_slc_handle *handle, const char *buf) */ static int key_press(struct hfp_slc_handle *handle, const char *buf) { - hfp_send(handle, "OK"); + hfp_send(handle, AT_CMD("OK")); /* Release the call and connection. */ if (handle->telephony->call || handle->telephony->callsetup) { @@ -390,9 +431,9 @@ static int last_dialed_number(struct hfp_slc_handle *handle, const char *buf) int rc; if (!handle->telephony->dial_number) - return hfp_send(handle, "ERROR"); + return hfp_send(handle, AT_CMD("ERROR")); - rc = hfp_send(handle, "OK"); + rc = hfp_send(handle, AT_CMD("OK")); if (rc) return rc; @@ -416,23 +457,21 @@ static int list_current_calls(struct hfp_slc_handle *handle, const char *cmd) * This is a hack to pass qualification test which ask us to * handle the basic case that one call is active and * the other is on hold. */ - if (handle->telephony->callheld) - { - snprintf(buf, 64, "+CLCC: %d,1,1,0,0", idx++); + if (handle->telephony->callheld) { + snprintf(buf, 64, AT_CMD("+CLCC: %d,1,1,0,0"), idx++); rc = hfp_send(handle, buf); if (rc) return rc; } - if (handle->telephony->call) - { - snprintf(buf, 64, "+CLCC: %d,1,0,0,0", idx++); + if (handle->telephony->call) { + snprintf(buf, 64, AT_CMD("+CLCC: %d,1,0,0,0"), idx++); rc = hfp_send(handle, buf); if (rc) return rc; } - return hfp_send(handle, "OK"); + return hfp_send(handle, AT_CMD("OK")); } /* AT+COPS command to query currently selected operator or set name format. @@ -441,18 +480,17 @@ static int list_current_calls(struct hfp_slc_handle *handle, const char *cmd) static int operator_selection(struct hfp_slc_handle *handle, const char *buf) { int rc; - if (buf[7] == '?') - { + if (buf[7] == '?') { /* HF sends AT+COPS? command to find current network operator. * AG responds with +COPS:<mode>,<format>,<operator>, where * the mode=0 means automatic for network selection. If no * operator is selected, <format> and <operator> are omitted. */ - rc = hfp_send(handle, "+COPS: 0"); + rc = hfp_send(handle, AT_CMD("+COPS: 0")); if (rc) return rc; } - return hfp_send(handle, "OK"); + return hfp_send(handle, AT_CMD("OK")); } /* AT+CIND command retrieves the supported indicator and its corresponding @@ -466,7 +504,7 @@ static int report_indicators(struct hfp_slc_handle *handle, const char *cmd) if (cmd[7] == '=') { /* Indicator update test command "AT+CIND=?" */ - err = hfp_send(handle, INDICATOR_UPDATE_RSP); + err = hfp_send(handle, AT_CMD(INDICATOR_UPDATE_RSP)); } else { /* Indicator update read command "AT+CIND?". * Respond with current status of AG indicators, @@ -475,21 +513,17 @@ static int report_indicators(struct hfp_slc_handle *handle, const char *cmd) * +CIND: <signal>,<service>,<call>, * <callsetup>,<callheld>,<roam> */ - snprintf(buf, 64, "+CIND: %d,%d,%d,%d,%d,%d,0", - handle->battery, - handle->signal, - handle->service, - handle->telephony->call, - handle->telephony->callsetup, - handle->telephony->callheld - ); + snprintf(buf, 64, AT_CMD("+CIND: %d,%d,%d,%d,%d,%d,0"), + handle->battery, handle->signal, handle->service, + handle->telephony->call, handle->telephony->callsetup, + handle->telephony->callheld); err = hfp_send(handle, buf); } if (err < 0) return err; - return hfp_send(handle, "OK"); + return hfp_send(handle, AT_CMD("OK")); } /* AT+BIA command to change the subset of indicators that shall be @@ -500,14 +534,13 @@ static int indicator_activation(struct hfp_slc_handle *handle, const char *cmd) { /* AT+BIA=[[<indrep 1>][,[<indrep 2>][,...[,[<indrep n>]]]]] */ syslog(LOG_ERR, "Bluetooth indicator activation command %s", cmd); - return hfp_send(handle, "OK"); + return hfp_send(handle, AT_CMD("OK")); } /* AT+VGM and AT+VGS command reports the current mic and speaker gain * level respectively. Optional support per spec 4.28. */ -static int signal_gain_setting(struct hfp_slc_handle *handle, - const char *cmd) +static int signal_gain_setting(struct hfp_slc_handle *handle, const char *cmd) { int gain; @@ -524,7 +557,7 @@ static int signal_gain_setting(struct hfp_slc_handle *handle, (gain + 1) * 100 / 16); } - return hfp_send(handle, "OK"); + return hfp_send(handle, AT_CMD("OK")); } /* AT+CNUM command to query the subscriber number. Mandatory support @@ -532,7 +565,7 @@ static int signal_gain_setting(struct hfp_slc_handle *handle, */ static int subscriber_number(struct hfp_slc_handle *handle, const char *buf) { - return hfp_send(handle, "OK"); + return hfp_send(handle, AT_CMD("OK")); } /* AT+BRSF command notifies the HF(Hands-free device) supported features @@ -566,12 +599,13 @@ static int supported_features(struct hfp_slc_handle *handle, const char *cmd) */ BTLOG(btlog, BT_HFP_SUPPORTED_FEATURES, 1, handle->ag_supported_features); - snprintf(response, 128, "+BRSF: %u", handle->ag_supported_features); + snprintf(response, 128, AT_CMD("+BRSF: %u"), + handle->ag_supported_features); err = hfp_send(handle, response); if (err < 0) return err; - return hfp_send(handle, "OK"); + return hfp_send(handle, AT_CMD("OK")); } int hfp_event_speaker_gain(struct hfp_slc_handle *handle, int gain) @@ -580,7 +614,7 @@ int hfp_event_speaker_gain(struct hfp_slc_handle *handle, int gain) /* Normailize gain value to 0-15 */ gain = gain * 15 / 100; - snprintf(command, 128, "+VGS=%d", gain); + snprintf(command, 128, AT_CMD("+VGS=%d"), gain); return hfp_send(handle, command); } @@ -591,7 +625,7 @@ int hfp_event_speaker_gain(struct hfp_slc_handle *handle, int gain) static int terminate_call(struct hfp_slc_handle *handle, const char *cmd) { int rc; - rc = hfp_send(handle, "OK"); + rc = hfp_send(handle, AT_CMD("OK")); if (rc) return rc; @@ -634,31 +668,30 @@ static int terminate_call(struct hfp_slc_handle *handle, const char *cmd) * AT+CMER= --> * <-- OK */ -static struct at_command at_commands[] = { - { "ATA", answer_call }, - { "ATD", dial_number }, - { "AT+BAC", available_codecs }, - { "AT+BCS", bluetooth_codec_selection }, - { "AT+BIA", indicator_activation }, - { "AT+BLDN", last_dialed_number }, - { "AT+BRSF", supported_features }, - { "AT+CCWA", call_waiting_notify }, - { "AT+CHUP", terminate_call }, - { "AT+CIND", report_indicators }, - { "AT+CKPD", key_press }, - { "AT+CLCC", list_current_calls }, - { "AT+CLIP", cli_notification }, - { "AT+CMEE", extended_errors }, - { "AT+CMER", event_reporting }, - { "AT+CNUM", subscriber_number }, - { "AT+COPS", operator_selection }, - { "AT+VG", signal_gain_setting }, - { "AT+VTS", dtmf_tone }, - { 0 } -}; - -static int handle_at_command(struct hfp_slc_handle *slc_handle, - const char *cmd) { +static struct at_command at_commands[] = { { "ATA", answer_call }, + { "ATD", dial_number }, + { "AT+BAC", available_codecs }, + { "AT+BCS", + bluetooth_codec_selection }, + { "AT+BIA", indicator_activation }, + { "AT+BLDN", last_dialed_number }, + { "AT+BRSF", supported_features }, + { "AT+CCWA", call_waiting_notify }, + { "AT+CHUP", terminate_call }, + { "AT+CIND", report_indicators }, + { "AT+CKPD", key_press }, + { "AT+CLCC", list_current_calls }, + { "AT+CLIP", cli_notification }, + { "AT+CMEE", extended_errors }, + { "AT+CMER", event_reporting }, + { "AT+CNUM", subscriber_number }, + { "AT+COPS", operator_selection }, + { "AT+VG", signal_gain_setting }, + { "AT+VTS", dtmf_tone }, + { 0 } }; + +static int handle_at_command(struct hfp_slc_handle *slc_handle, const char *cmd) +{ struct at_command *atc; for (atc = at_commands; atc->cmd; atc++) @@ -666,7 +699,7 @@ static int handle_at_command(struct hfp_slc_handle *slc_handle, return atc->callback(slc_handle, cmd); syslog(LOG_DEBUG, "AT command %s not supported", cmd); - return hfp_send(slc_handle, "ERROR"); + return hfp_send(slc_handle, AT_CMD("ERROR")); } static void slc_watch_callback(void *arg) @@ -675,9 +708,9 @@ static void slc_watch_callback(void *arg) ssize_t bytes_read; int err; - bytes_read = read(handle->rfcomm_fd, - &handle->buf[handle->buf_write_idx], - SLC_BUF_SIZE_BYTES - handle->buf_write_idx - 1); + bytes_read = + read(handle->rfcomm_fd, &handle->buf[handle->buf_write_idx], + SLC_BUF_SIZE_BYTES - handle->buf_write_idx - 1); if (bytes_read < 0) { syslog(LOG_ERR, "Error reading slc command %s", strerror(errno)); @@ -710,8 +743,7 @@ static void slc_watch_callback(void *arg) /* Handle the case when buffer is full and no command found. */ if (handle->buf_write_idx == SLC_BUF_SIZE_BYTES - 1) { if (handle->buf_read_idx) { - memmove(handle->buf, - &handle->buf[handle->buf_read_idx], + memmove(handle->buf, &handle->buf[handle->buf_read_idx], handle->buf_write_idx - handle->buf_read_idx); handle->buf_write_idx -= handle->buf_read_idx; handle->buf_read_idx = 0; @@ -722,13 +754,14 @@ static void slc_watch_callback(void *arg) } } + post_at_command_tasks(handle); + return; } /* Exported interfaces */ -struct hfp_slc_handle *hfp_slc_create(int fd, - int is_hsp, +struct hfp_slc_handle *hfp_slc_create(int fd, int is_hsp, int ag_supported_features, struct cras_bt_device *device, hfp_slc_init_cb init_cb, @@ -736,7 +769,7 @@ struct hfp_slc_handle *hfp_slc_create(int fd, { struct hfp_slc_handle *handle; - handle = (struct hfp_slc_handle*) calloc(1, sizeof(*handle)); + handle = (struct hfp_slc_handle *)calloc(1, sizeof(*handle)); if (!handle) return NULL; @@ -752,10 +785,11 @@ struct hfp_slc_handle *hfp_slc_create(int fd, handle->service = 1; handle->ind_event_report = 0; handle->telephony = cras_telephony_get(); - handle->selected_codec = HFP_CODEC_ID_CVSD; + handle->preferred_codec = HFP_CODEC_ID_CVSD; + handle->selected_codec = HFP_CODEC_UNUSED; - cras_system_add_select_fd(handle->rfcomm_fd, - slc_watch_callback, handle); + cras_system_add_select_fd(handle->rfcomm_fd, slc_watch_callback, + handle); return handle; } @@ -772,7 +806,12 @@ void hfp_slc_destroy(struct hfp_slc_handle *slc_handle) int hfp_slc_get_selected_codec(struct hfp_slc_handle *handle) { - return handle->selected_codec; + /* If codec negotiation is not supported on HF, or the negotiation + * process never completed. Fallback to the preffered codec. */ + if (handle->selected_codec == HFP_CODEC_UNUSED) + return handle->preferred_codec; + else + return handle->selected_codec; } int hfp_set_call_status(struct hfp_slc_handle *handle, int call) @@ -793,8 +832,7 @@ int hfp_set_call_status(struct hfp_slc_handle *handle, int call) * <-- +CIEV: (callsetup = 1) * <-- RING (ALERT) */ -int hfp_event_incoming_call(struct hfp_slc_handle *handle, - const char *number, +int hfp_event_incoming_call(struct hfp_slc_handle *handle, const char *number, int type) { int rc; @@ -811,7 +849,7 @@ int hfp_event_incoming_call(struct hfp_slc_handle *handle, if (handle->telephony->call) return 0; else - return hfp_send(handle, "RING"); + return hfp_send(handle, AT_CMD("RING")); } int hfp_event_update_call(struct hfp_slc_handle *handle) @@ -856,4 +894,3 @@ int hfp_slc_get_hf_codec_negotiation_supported(struct hfp_slc_handle *handle) { return handle->hf_supports_codec_negotiation; } - diff --git a/cras/src/server/cras_hfp_slc.h b/cras/src/server/cras_hfp_slc.h index 2fe1b452..fd3ee551 100644 --- a/cras/src/server/cras_hfp_slc.h +++ b/cras/src/server/cras_hfp_slc.h @@ -14,35 +14,35 @@ struct cras_bt_device; * Per HFP 1.7.1 specification section 4.34.1, command * AT+BRSF (Bluetooth Retrieve Supported Features) */ -#define HF_EC_ANDOR_NR 0x0001 -#define HF_THREE_WAY_CALLING 0x0002 -#define HF_CLI_PRESENTATION_CAP 0x0004 -#define HF_VOICE_RECOGNITION 0x0008 -#define HF_REMOVE_VOLUME_CTONTROL 0x0010 -#define HF_ENHANCED_CALL_STATUS 0x0020 -#define HF_ENHANCED_CALL_CONTROL 0x0040 -#define HF_CODEC_NEGOTIATION 0x0080 -#define HF_HF_INDICATORS 0x0100 -#define HF_ESCO_S4_T2_SETTINGS 0x0200 - -#define AG_THREE_WAY_CALLING 0x0001 -#define AG_EC_ANDOR_NR 0x0002 -#define AG_VOICE_RECOGNITION 0x0004 -#define AG_INBAND_RINGTONE 0x0008 -#define AG_ATTACH_NUMBER_TO_VOICETAG 0x0010 -#define AG_REJECT_A_CALL 0x0020 -#define AG_ENHANCED_CALL_STATUS 0x0040 -#define AG_ENHANCED_CALL_CONTROL 0x0080 -#define AG_EXTENDED_ERROR_RESULT_CODES 0x0100 -#define AG_CODEC_NEGOTIATION 0x0200 -#define AG_HF_INDICATORS 0x0400 -#define AG_ESCO_S4_T2_SETTINGS 0x0800 +#define HF_EC_ANDOR_NR 0x0001 +#define HF_THREE_WAY_CALLING 0x0002 +#define HF_CLI_PRESENTATION_CAP 0x0004 +#define HF_VOICE_RECOGNITION 0x0008 +#define HF_REMOVE_VOLUME_CTONTROL 0x0010 +#define HF_ENHANCED_CALL_STATUS 0x0020 +#define HF_ENHANCED_CALL_CONTROL 0x0040 +#define HF_CODEC_NEGOTIATION 0x0080 +#define HF_HF_INDICATORS 0x0100 +#define HF_ESCO_S4_T2_SETTINGS 0x0200 + +#define AG_THREE_WAY_CALLING 0x0001 +#define AG_EC_ANDOR_NR 0x0002 +#define AG_VOICE_RECOGNITION 0x0004 +#define AG_INBAND_RINGTONE 0x0008 +#define AG_ATTACH_NUMBER_TO_VOICETAG 0x0010 +#define AG_REJECT_A_CALL 0x0020 +#define AG_ENHANCED_CALL_STATUS 0x0040 +#define AG_ENHANCED_CALL_CONTROL 0x0080 +#define AG_EXTENDED_ERROR_RESULT_CODES 0x0100 +#define AG_CODEC_NEGOTIATION 0x0200 +#define AG_HF_INDICATORS 0x0400 +#define AG_ESCO_S4_T2_SETTINGS 0x0800 /* Codec ids for codec negotiation, per HFP 1.7.1 spec appendix B. */ -#define HFP_CODEC_UNUSED 0 -#define HFP_CODEC_ID_CVSD 1 -#define HFP_CODEC_ID_MSBC 2 -#define HFP_MAX_CODECS 3 +#define HFP_CODEC_UNUSED 0 +#define HFP_CODEC_ID_CVSD 1 +#define HFP_CODEC_ID_MSBC 2 +#define HFP_MAX_CODECS 3 /* Callback to call when service level connection initialized. */ typedef int (*hfp_slc_init_cb)(struct hfp_slc_handle *handle); @@ -75,8 +75,7 @@ void hfp_slc_destroy(struct hfp_slc_handle *handle); int hfp_set_call_status(struct hfp_slc_handle *handle, int call); /* Fakes the incoming call event for qualification test. */ -int hfp_event_incoming_call(struct hfp_slc_handle *handle, - const char *number, +int hfp_event_incoming_call(struct hfp_slc_handle *handle, const char *number, int type); /* Handles the call status changed event. diff --git a/cras/src/server/cras_iodev.c b/cras/src/server/cras_iodev.c index 9b7c303e..cf6b71ef 100644 --- a/cras/src/server/cras_iodev.c +++ b/cras/src/server/cras_iodev.c @@ -1048,6 +1048,17 @@ int cras_iodev_put_output_buffer(struct cras_iodev *iodev, uint8_t *frames, int rc; struct cras_loopback *loopback; + /* Calculate whether the final output was non-empty, if requested. */ + if (is_non_empty) { + unsigned int i; + for (i = 0; i < nframes * cras_get_format_bytes(fmt); i++) { + if (frames[i]) { + *is_non_empty = 1; + break; + } + } + } + DL_FOREACH (iodev->loopbacks, loopback) { if (loopback->type == LOOPBACK_POST_MIX_PRE_DSP) loopback->hook_data(frames, nframes, iodev->format, @@ -1074,9 +1085,6 @@ int cras_iodev_put_output_buffer(struct cras_iodev *iodev, uint8_t *frames, ramp_action.type != CRAS_RAMP_ACTION_PARTIAL) { const unsigned int frame_bytes = cras_get_format_bytes(fmt); cras_mix_mute_buffer(frames, frame_bytes, nframes); - - // Skip non-empty check, since we know it's empty. - is_non_empty = NULL; } /* Compute scaler for software volume if needed. */ @@ -1116,17 +1124,6 @@ int cras_iodev_put_output_buffer(struct cras_iodev *iodev, uint8_t *frames, if (iodev->rate_est) rate_estimator_add_frames(iodev->rate_est, nframes); - // Calculate whether the final output was non-empty, if requested. - if (is_non_empty) { - unsigned int i; - for (i = 0; i < nframes * cras_get_format_bytes(fmt); i++) { - if (frames[i]) { - *is_non_empty = 1; - break; - } - } - } - return iodev->put_buffer(iodev, nframes); } @@ -1247,7 +1244,7 @@ int cras_iodev_frames_queued(struct cras_iodev *iodev, rc = iodev->frames_queued(iodev, hw_tstamp); if (rc == -EPIPE) - cras_audio_thread_severe_underrun(); + cras_audio_thread_event_severe_underrun(); if (rc < 0) return rc; @@ -1309,7 +1306,7 @@ int cras_iodev_fill_odev_zeros(struct cras_iodev *odev, unsigned int frames) int cras_iodev_output_underrun(struct cras_iodev *odev) { - cras_audio_thread_underrun(); + cras_audio_thread_event_underrun(); if (odev->output_underrun) return odev->output_underrun(odev); else @@ -1546,3 +1543,59 @@ void cras_iodev_update_highest_hw_level(struct cras_iodev *iodev, { iodev->highest_hw_level = MAX(iodev->highest_hw_level, hw_level); } + +/* + * Makes an input device drop the given number of frames. + * Args: + * iodev - The device. + * frames - How many frames will be dropped in a device. + * Returns: + * The number of frames have been dropped. Negative error code on failure. + */ +static int cras_iodev_drop_frames(struct cras_iodev *iodev, unsigned int frames) +{ + struct timespec hw_tstamp; + int rc; + + if (iodev->direction != CRAS_STREAM_INPUT) + return -EINVAL; + + rc = cras_iodev_frames_queued(iodev, &hw_tstamp); + if (rc < 0) + return rc; + + frames = MIN(frames, rc); + + rc = iodev->get_buffer(iodev, &iodev->input_data->area, &frames); + if (rc < 0) + return rc; + + rc = iodev->put_buffer(iodev, frames); + if (rc < 0) + return rc; + + /* + * Tell rate estimator that some frames have been dropped to avoid calculating + * the wrong rate. + */ + rate_estimator_add_frames(iodev->rate_est, -frames); + + ATLOG(atlog, AUDIO_THREAD_DEV_DROP_FRAMES, iodev->info.idx, frames, 0); + + return frames; +} + +int cras_iodev_drop_frames_by_time(struct cras_iodev *iodev, struct timespec ts) +{ + int frames_to_set; + double est_rate; + int rc; + + est_rate = iodev->format->frame_rate * + cras_iodev_get_est_rate_ratio(iodev); + frames_to_set = cras_time_to_frames(&ts, est_rate); + + rc = cras_iodev_drop_frames(iodev, frames_to_set); + + return rc; +} diff --git a/cras/src/server/cras_iodev.h b/cras/src/server/cras_iodev.h index f2c95eb2..f6999336 100644 --- a/cras/src/server/cras_iodev.h +++ b/cras/src/server/cras_iodev.h @@ -113,8 +113,6 @@ enum CRAS_IODEV_STATE { * min_software_gain - The minimum software gain in 0.01 dB if needed. * max_software_gain - The maximum software gain in 0.01 dB if needed. * stable_id - id for node that doesn't change after unplug/plug. - * stable_id_new - New stable_id, it will be deprecated and be put on - * stable_id. * is_sco_pcm - Bool to indicate whether the ionode is for SCO over PCM. */ struct cras_ionode { @@ -136,7 +134,6 @@ struct cras_ionode { long min_software_gain; long max_software_gain; unsigned int stable_id; - unsigned int stable_id_new; int is_sco_pcm; struct cras_ionode *prev, *next; }; @@ -816,4 +813,15 @@ int cras_iodev_is_zero_volume(const struct cras_iodev *odev); void cras_iodev_update_highest_hw_level(struct cras_iodev *iodev, unsigned int hw_level); +/* + * Makes an input device drop the specific number of frames by given time. + * Args: + * iodev - The device. + * ts - The time indicates how many frames will be dropped in a device. + * Returns: + * The number of frames have been dropped. Negative error code on failure. + */ +int cras_iodev_drop_frames_by_time(struct cras_iodev *iodev, + struct timespec ts); + #endif /* CRAS_IODEV_H_ */ diff --git a/cras/src/server/cras_iodev_list.c b/cras/src/server/cras_iodev_list.c index 9ef883cb..c581acdf 100644 --- a/cras/src/server/cras_iodev_list.c +++ b/cras/src/server/cras_iodev_list.c @@ -220,6 +220,10 @@ static const char *node_type_to_str(struct cras_ionode *node) return "USB"; case CRAS_NODE_TYPE_BLUETOOTH: return "BLUETOOTH"; + case CRAS_NODE_TYPE_FALLBACK_NORMAL: + return "FALLBACK_NORMAL"; + case CRAS_NODE_TYPE_FALLBACK_ABNORMAL: + return "FALLBACK_ABNORMAL"; case CRAS_NODE_TYPE_UNKNOWN: default: return "UNKNOWN"; @@ -249,7 +253,6 @@ static int fill_node_list(struct iodev_list *list, node_info->left_right_swapped = node->left_right_swapped; node_info->stable_id = node->stable_id; - node_info->stable_id_new = node->stable_id_new; strcpy(node_info->mic_positions, node->mic_positions); strcpy(node_info->name, node->name); strcpy(node_info->active_hotword_model, @@ -572,10 +575,31 @@ static void possibly_disable_fallback(enum CRAS_STREAM_DIRECTION dir) } } -static void possibly_enable_fallback(enum CRAS_STREAM_DIRECTION dir) +/* + * Possibly enables fallback device to handle streams. + * dir - output or input. + * error - true if enable fallback device because no other iodevs can be + * initialized successfully. + */ +static void possibly_enable_fallback(enum CRAS_STREAM_DIRECTION dir, bool error) { if (fallback_devs[dir] == NULL) return; + + /* + * The fallback device is a special device. It doesn't have a real + * device to get a correct node type. Therefore, we need to set it by + * ourselves, which indicates the reason to use this device. + * NORMAL - Use it because of nodes changed. + * ABNORMAL - Use it because there are no other usable devices. + */ + if (error) + syslog(LOG_ERR, + "Enable fallback device because there are no other usable devices."); + + fallback_devs[dir]->active_node->type = + error ? CRAS_NODE_TYPE_FALLBACK_ABNORMAL : + CRAS_NODE_TYPE_FALLBACK_NORMAL; if (!cras_iodev_list_dev_is_enabled(fallback_devs[dir])) enable_device(fallback_devs[dir]); } @@ -798,7 +822,7 @@ static int stream_added_cb(struct cras_rstream *rstream) * cras_iodev_list_select_node() is called to re-select the * active node. */ - possibly_enable_fallback(rstream->direction); + possibly_enable_fallback(rstream->direction, true); } return 0; } @@ -992,10 +1016,10 @@ void cras_iodev_list_init() /* Add an empty device so there is always something to play to or * capture from. */ - fallback_devs[CRAS_STREAM_OUTPUT] = - empty_iodev_create(CRAS_STREAM_OUTPUT, CRAS_NODE_TYPE_UNKNOWN); - fallback_devs[CRAS_STREAM_INPUT] = - empty_iodev_create(CRAS_STREAM_INPUT, CRAS_NODE_TYPE_UNKNOWN); + fallback_devs[CRAS_STREAM_OUTPUT] = empty_iodev_create( + CRAS_STREAM_OUTPUT, CRAS_NODE_TYPE_FALLBACK_NORMAL); + fallback_devs[CRAS_STREAM_INPUT] = empty_iodev_create( + CRAS_STREAM_INPUT, CRAS_NODE_TYPE_FALLBACK_NORMAL); enable_device(fallback_devs[CRAS_STREAM_OUTPUT]); enable_device(fallback_devs[CRAS_STREAM_INPUT]); @@ -1120,6 +1144,9 @@ void cras_iodev_list_suspend_dev(unsigned int dev_idx) struct cras_rstream *rstream; struct cras_iodev *dev = find_dev(dev_idx); + if (!dev) + return; + DL_FOREACH (stream_list_get(stream_list), rstream) { if (rstream->direction != dev->direction) continue; @@ -1142,8 +1169,18 @@ void cras_iodev_list_resume_dev(unsigned int dev_idx) struct cras_iodev *dev = find_dev(dev_idx); int rc; + if (!dev) + return; + + dev->update_active_node(dev, dev->active_node->idx, 1); rc = init_and_attach_streams(dev); - if (rc < 0) { + if (rc == 0) { + /* If dev initialize succeeded and this is not a pinned device, + * disable the silent fallback device because it's just + * unnecessary. */ + if (!stream_list_has_pinned_stream(stream_list, dev_idx)) + possibly_disable_fallback(dev->direction); + } else { syslog(LOG_INFO, "Enable dev fail at resume, rc %d", rc); schedule_init_device_retry(dev); } @@ -1469,7 +1506,7 @@ void cras_iodev_list_select_node(enum CRAS_STREAM_DIRECTION direction, * Note that the fallback node is not needed if the new node is already * enabled - the new node will remain enabled. */ if (!new_node_already_enabled) - possibly_enable_fallback(direction); + possibly_enable_fallback(direction, false); /* Disable all devices except for fallback device, and the new device, * provided it is already enabled. */ diff --git a/cras/src/server/cras_loopback_iodev.c b/cras/src/server/cras_loopback_iodev.c index b30edf9c..dea96169 100644 --- a/cras/src/server/cras_loopback_iodev.c +++ b/cras/src/server/cras_loopback_iodev.c @@ -266,7 +266,6 @@ static struct cras_iodev *create_loopback_iodev(enum CRAS_LOOPBACK_TYPE type) iodev->info.stable_id = SuperFastHash(iodev->info.name, strlen(iodev->info.name), strlen(iodev->info.name)); - iodev->info.stable_id_new = iodev->info.stable_id; iodev->supported_rates = loopback_supported_rates; iodev->supported_channel_counts = loopback_supported_channel_counts; @@ -317,7 +316,6 @@ struct cras_iodev *loopback_iodev_create(enum CRAS_LOOPBACK_TYPE type) node->plugged = 1; node->volume = 100; node->stable_id = iodev->info.stable_id; - node->stable_id_new = iodev->info.stable_id_new; node->software_volume_needed = 0; node->max_software_gain = 0; strcpy(node->name, loopdev_names[type]); diff --git a/cras/src/server/cras_mix.h b/cras/src/server/cras_mix.h index 5ae51f09..5c21df91 100644 --- a/cras/src/server/cras_mix.h +++ b/cras/src/server/cras_mix.h @@ -6,6 +6,8 @@ #ifndef _CRAS_MIX_H #define _CRAS_MIX_H +#include "cras_types.h" + struct cras_audio_shm; /* SIMD optimisation flags */ diff --git a/cras/src/server/cras_playback_rclient.c b/cras/src/server/cras_playback_rclient.c new file mode 100644 index 00000000..a282e8b1 --- /dev/null +++ b/cras/src/server/cras_playback_rclient.c @@ -0,0 +1,103 @@ +/* Copyright 2019 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <syslog.h> + +#include "cras_iodev_list.h" +#include "cras_messages.h" +#include "cras_observer.h" +#include "cras_rclient.h" +#include "cras_rclient_util.h" +#include "cras_rstream.h" +#include "cras_system_state.h" +#include "cras_types.h" +#include "cras_util.h" +#include "stream_list.h" + +/* Entry point for handling a message from the client. Called from the main + * server context. */ +static int cpr_handle_message_from_client(struct cras_rclient *client, + const struct cras_server_message *msg, + int *fds, unsigned int num_fds) +{ + int rc = 0; + assert(client && msg); + + rc = rclient_validate_message_fds(msg, fds, num_fds); + if (rc < 0) { + for (int i = 0; i < (int)num_fds; i++) + if (fds[i] >= 0) + close(fds[i]); + return rc; + } + int fd = num_fds > 0 ? fds[0] : -1; + + switch (msg->id) { + case CRAS_SERVER_CONNECT_STREAM: { + int client_shm_fd = num_fds > 1 ? fds[1] : -1; + struct cras_connect_message cmsg; + if (MSG_LEN_VALID(msg, struct cras_connect_message)) { + rc = rclient_handle_client_stream_connect( + client, + (const struct cras_connect_message *)msg, fd, + client_shm_fd); + } else if (!convert_connect_message_old(msg, &cmsg)) { + rc = rclient_handle_client_stream_connect( + client, &cmsg, fd, client_shm_fd); + } else { + return -EINVAL; + } + break; + } + case CRAS_SERVER_DISCONNECT_STREAM: + if (!MSG_LEN_VALID(msg, struct cras_disconnect_stream_message)) + return -EINVAL; + rc = rclient_handle_client_stream_disconnect( + client, + (const struct cras_disconnect_stream_message *)msg); + break; + default: + break; + } + + return rc; +} + +/* Declarations of cras_rclient operators for cras_playback_rclient. */ +static const struct cras_rclient_ops cras_playback_rclient_ops = { + .handle_message_from_client = cpr_handle_message_from_client, + .send_message_to_client = rclient_send_message_to_client, + .destroy = rclient_destroy, +}; + +/* + * Exported Functions. + */ + +/* Creates a client structure and sends a message back informing the client that + * the connection has succeeded. */ +struct cras_rclient *cras_playback_rclient_create(int fd, size_t id) +{ + struct cras_rclient *client; + struct cras_client_connected msg; + int state_fd; + + client = (struct cras_rclient *)calloc(1, sizeof(struct cras_rclient)); + if (!client) + return NULL; + + client->fd = fd; + client->id = id; + + client->ops = &cras_playback_rclient_ops; + client->supported_directions = + cras_stream_direction_mask(CRAS_STREAM_OUTPUT); + + cras_fill_client_connected(&msg, client->id); + state_fd = cras_sys_state_shm_fd(); + client->ops->send_message_to_client(client, &msg.header, &state_fd, 1); + + return client; +} diff --git a/cras/src/server/cras_playback_rclient.h b/cras/src/server/cras_playback_rclient.h new file mode 100644 index 00000000..37f03cfb --- /dev/null +++ b/cras/src/server/cras_playback_rclient.h @@ -0,0 +1,20 @@ +/* Copyright 2019 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef CRAS_PLAYBACK_RCLIENT_H_ +#define CRAS_PLAYBACK_RCLIENT_H_ + +struct cras_rclient; + +/* Creates a playback rclient structure. + * Args: + * fd - The file descriptor used for communication with the client. + * id - Unique identifier for this client. + * Returns: + * A pointer to the newly created rclient on success, NULL on failure. + */ +struct cras_rclient *cras_playback_rclient_create(int fd, size_t id); + +#endif /* CRAS_PLAYBACK_RCLIENT_H_ */ diff --git a/cras/src/server/cras_rclient.c b/cras/src/server/cras_rclient.c index 63e20bec..38ba5c20 100644 --- a/cras/src/server/cras_rclient.c +++ b/cras/src/server/cras_rclient.c @@ -10,12 +10,15 @@ #include "audio_thread.h" #include "cras_apm_list.h" #include "cras_bt_log.h" +#include "cras_capture_rclient.h" #include "cras_config.h" +#include "cras_control_rclient.h" #include "cras_dsp.h" #include "cras_iodev.h" #include "cras_iodev_list.h" #include "cras_messages.h" #include "cras_observer.h" +#include "cras_playback_rclient.h" #include "cras_rclient.h" #include "cras_rstream.h" #include "cras_server_metrics.h" @@ -34,7 +37,8 @@ void cras_rclient_destroy(struct cras_rclient *client) /* Entry point for handling a message from the client. Called from the main * server context. */ int cras_rclient_buffer_from_client(struct cras_rclient *client, - const uint8_t *buf, size_t buf_len, int fd) + const uint8_t *buf, size_t buf_len, + int *fds, int num_fds) { struct cras_server_message *msg = (struct cras_server_message *)buf; @@ -42,8 +46,8 @@ int cras_rclient_buffer_from_client(struct cras_rclient *client, return -EINVAL; if (msg->length != buf_len) return -EINVAL; - client->ops->handle_message_from_client(client, msg, fd); - return 0; + return client->ops->handle_message_from_client(client, msg, fds, + num_fds); } /* Sends a message to the client. */ @@ -53,3 +57,25 @@ int cras_rclient_send_message(const struct cras_rclient *client, { return client->ops->send_message_to_client(client, msg, fds, num_fds); } + +struct cras_rclient *cras_rclient_create(int fd, size_t id, + enum CRAS_CONNECTION_TYPE conn_type) +{ + if (!cras_validate_connection_type(conn_type)) + goto error; + + switch (conn_type) { + case CRAS_CONTROL: + return cras_control_rclient_create(fd, id); + case CRAS_PLAYBACK: + return cras_playback_rclient_create(fd, id); + case CRAS_CAPTURE: + return cras_capture_rclient_create(fd, id); + default: + goto error; + } + +error: + syslog(LOG_ERR, "unsupported connection type"); + return NULL; +} diff --git a/cras/src/server/cras_rclient.h b/cras/src/server/cras_rclient.h index c18c8c56..6cffb7d8 100644 --- a/cras/src/server/cras_rclient.h +++ b/cras/src/server/cras_rclient.h @@ -9,6 +9,8 @@ #ifndef CRAS_RCLIENT_H_ #define CRAS_RCLIENT_H_ +#include "cras_types.h" + struct cras_client_message; struct cras_message; struct cras_server_message; @@ -17,12 +19,14 @@ struct cras_server_message; * id - The id of the client. * fd - Connection for client communication. * ops - cras_rclient_ops for the cras_rclient. + * supported_directions - Bit mask for supported stream directions. */ struct cras_rclient { struct cras_observer_client *observer; size_t id; int fd; const struct cras_rclient_ops *ops; + int supported_directions; }; /* Operations for cras_rclient. @@ -35,7 +39,7 @@ struct cras_rclient { struct cras_rclient_ops { int (*handle_message_from_client)(struct cras_rclient *, const struct cras_server_message *, - int fd); + int *fds, unsigned int num_fds); int (*send_message_to_client)(const struct cras_rclient *, const struct cras_client_message *, int *fds, unsigned int num_fds); @@ -46,10 +50,12 @@ struct cras_rclient_ops { * Args: * fd - The file descriptor used for communication with the client. * id - Unique identifier for this client. + * conn_type - Client connection type. * Returns: * A pointer to the newly created rclient on success, NULL on failure. */ -struct cras_rclient *cras_rclient_create(int fd, size_t id); +struct cras_rclient *cras_rclient_create(int fd, size_t id, + enum CRAS_CONNECTION_TYPE conn_type); /* Destroys an rclient created with "cras_rclient_create". * Args: @@ -63,13 +69,14 @@ void cras_rclient_destroy(struct cras_rclient *client); * buf - The raw byte buffer the client sent. It should contain a valid * cras_server_message. * buf_len - The length of |buf|. - * fd - The file descriptor that was sent by the remote client (or -1 if no - * file descriptor was sent). + * fds - Array of valid file descriptors sent by the remote client. + * num_fds - Length of |fds|. * Returns: * 0 on success, otherwise a negative error code. */ int cras_rclient_buffer_from_client(struct cras_rclient *client, - const uint8_t *buf, size_t buf_len, int fd); + const uint8_t *buf, size_t buf_len, + int *fds, int num_fds); /* Sends a message to the client. * Args: diff --git a/cras/src/server/cras_rclient_util.c b/cras/src/server/cras_rclient_util.c new file mode 100644 index 00000000..c88df82e --- /dev/null +++ b/cras/src/server/cras_rclient_util.c @@ -0,0 +1,222 @@ +/* Copyright 2019 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <syslog.h> + +#include "cras_iodev_list.h" +#include "cras_messages.h" +#include "cras_observer.h" +#include "cras_rclient.h" +#include "cras_rclient_util.h" +#include "cras_rstream.h" +#include "cras_server_metrics.h" +#include "cras_tm.h" +#include "cras_types.h" +#include "cras_util.h" +#include "stream_list.h" + +int rclient_send_message_to_client(const struct cras_rclient *client, + const struct cras_client_message *msg, + int *fds, unsigned int num_fds) +{ + return cras_send_with_fds(client->fd, (const void *)msg, msg->length, + fds, num_fds); +} + +void rclient_destroy(struct cras_rclient *client) +{ + cras_observer_remove(client->observer); + stream_list_rm_all_client_streams(cras_iodev_list_get_stream_list(), + client); + free(client); +} + +int rclient_validate_message_fds(const struct cras_server_message *msg, + int *fds, unsigned int num_fds) +{ + switch (msg->id) { + case CRAS_SERVER_CONNECT_STREAM: + if (num_fds > 2) + goto error; + break; + case CRAS_SERVER_SET_AEC_DUMP: + if (num_fds != 1) + goto error; + syslog(LOG_ERR, "client msg for APM debug, fd %d", fds[0]); + break; + default: + if (num_fds > 0) + goto error; + break; + } + + return 0; + +error: + syslog(LOG_ERR, "Message %d should not have %u fds attached.", msg->id, + num_fds); + return -EINVAL; +} + +static int +rclient_validate_stream_connect_message(const struct cras_rclient *client, + const struct cras_connect_message *msg) +{ + if (!cras_valid_stream_id(msg->stream_id, client->id)) { + syslog(LOG_ERR, + "stream_connect: invalid stream_id: %x for " + "client: %zx.\n", + msg->stream_id, client->id); + return -EINVAL; + } + + int direction = cras_stream_direction_mask(msg->direction); + if (direction < 0 || !(client->supported_directions & direction)) { + syslog(LOG_ERR, + "stream_connect: invalid stream direction: %x for " + "client: %zx.\n", + msg->direction, client->id); + return -EINVAL; + } + return 0; +} + +static int rclient_validate_stream_connect_fds(int audio_fd, int client_shm_fd, + size_t client_shm_size) +{ + /* check audio_fd is valid. */ + if (audio_fd < 0) { + syslog(LOG_ERR, "Invalid audio fd in stream connect.\n"); + return -EBADF; + } + + /* check client_shm_fd is valid if client wants to use client shm. */ + if (client_shm_size > 0 && client_shm_fd < 0) { + syslog(LOG_ERR, + "client_shm_fd must be valid if client_shm_size > 0.\n"); + return -EBADF; + } else if (client_shm_size == 0 && client_shm_fd >= 0) { + syslog(LOG_ERR, + "client_shm_fd can be valid only if client_shm_size > 0.\n"); + return -EINVAL; + } + return 0; +} + +int rclient_validate_stream_connect_params( + const struct cras_rclient *client, + const struct cras_connect_message *msg, int audio_fd, int client_shm_fd) +{ + int rc; + + rc = rclient_validate_stream_connect_message(client, msg); + if (rc) + return rc; + + rc = rclient_validate_stream_connect_fds(audio_fd, client_shm_fd, + msg->client_shm_size); + if (rc) + return rc; + + return 0; +} + +int rclient_handle_client_stream_connect(struct cras_rclient *client, + const struct cras_connect_message *msg, + int aud_fd, int client_shm_fd) +{ + struct cras_rstream *stream; + struct cras_client_stream_connected stream_connected; + struct cras_client_message *reply; + struct cras_audio_format remote_fmt; + struct cras_rstream_config stream_config; + int rc, header_fd, samples_fd; + int stream_fds[2]; + + rc = rclient_validate_stream_connect_params(client, msg, aud_fd, + client_shm_fd); + if (rc) { + if (client_shm_fd >= 0) + close(client_shm_fd); + if (aud_fd >= 0) + close(aud_fd); + goto reply_err; + } + + unpack_cras_audio_format(&remote_fmt, &msg->format); + + /* When full, getting an error is preferable to blocking. */ + cras_make_fd_nonblocking(aud_fd); + + cras_rstream_config_init_with_message(client, msg, &aud_fd, + &client_shm_fd, &remote_fmt, + &stream_config); + rc = stream_list_add(cras_iodev_list_get_stream_list(), &stream_config, + &stream); + if (rc) + goto cleanup_config; + + /* Tell client about the stream setup. */ + syslog(LOG_DEBUG, "Send connected for stream %x\n", msg->stream_id); + cras_fill_client_stream_connected( + &stream_connected, 0, /* No error. */ + msg->stream_id, &remote_fmt, + cras_rstream_get_samples_shm_size(stream), + cras_rstream_get_effects(stream)); + reply = &stream_connected.header; + + rc = cras_rstream_get_shm_fds(stream, &header_fd, &samples_fd); + if (rc) + goto cleanup_config; + + stream_fds[0] = header_fd; + /* If we're using client-provided shm, samples_fd here refers to the + * same shm area as client_shm_fd */ + stream_fds[1] = samples_fd; + + rc = client->ops->send_message_to_client(client, reply, stream_fds, 2); + if (rc < 0) { + syslog(LOG_ERR, "Failed to send connected messaged\n"); + stream_list_rm(cras_iodev_list_get_stream_list(), + stream->stream_id); + goto cleanup_config; + } + + /* Metrics logs the stream configurations. */ + cras_server_metrics_stream_config(&stream_config); + + /* Cleanup local object explicitly. */ + cras_rstream_config_cleanup(&stream_config); + return 0; + +cleanup_config: + cras_rstream_config_cleanup(&stream_config); + +reply_err: + /* Send the error code to the client. */ + cras_fill_client_stream_connected(&stream_connected, rc, msg->stream_id, + &remote_fmt, 0, msg->effects); + reply = &stream_connected.header; + client->ops->send_message_to_client(client, reply, NULL, 0); + + return rc; +} + +/* Handles messages from the client requesting that a stream be removed from the + * server. */ +int rclient_handle_client_stream_disconnect( + struct cras_rclient *client, + const struct cras_disconnect_stream_message *msg) +{ + if (!cras_valid_stream_id(msg->stream_id, client->id)) { + syslog(LOG_ERR, + "stream_disconnect: invalid stream_id: %x for " + "client: %zx.\n", + msg->stream_id, client->id); + return -EINVAL; + } + return stream_list_rm(cras_iodev_list_get_stream_list(), + msg->stream_id); +} diff --git a/cras/src/server/cras_rclient_util.h b/cras/src/server/cras_rclient_util.h new file mode 100644 index 00000000..4768a476 --- /dev/null +++ b/cras/src/server/cras_rclient_util.h @@ -0,0 +1,115 @@ +/* Copyright 2019 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* + * Common utility functions for rclients. + */ +#ifndef CRAS_RCLIENT_UTIL_H_ +#define CRAS_RCLIENT_UTIL_H_ + +#define MSG_LEN_VALID(msg, type) ((msg)->length >= sizeof(type)) + +struct cras_connect_message; +struct cras_rclient; +struct cras_rclient_message; +struct cras_rstream_config; +struct cras_server_message; + +/* Sends a message to the client. */ +int rclient_send_message_to_client(const struct cras_rclient *client, + const struct cras_client_message *msg, + int *fds, unsigned int num_fds); + +/* Removes all streams that the client owns and destroys it. */ +void rclient_destroy(struct cras_rclient *client); + +/* Checks if the number of incoming fds matches the needs of the message from + * client. + * + * Args: + * msg - The cras_server_message from client. + * fds - The array for incoming fds from client. + * num_fds - The number of fds from client. + * + * Returns: + * 0 on success. Or negative value if the number of fds is invalid. + */ +int rclient_validate_message_fds(const struct cras_server_message *msg, + int *fds, unsigned int num_fds); + +/* Checks if the incoming stream connect message contains + * - stream_id matches client->id. + * - direction supported by the client. + * + * Args: + * client - The cras_rclient which gets the message. + * msg - cras_connect_message from client. + * audio_fd - Audio fd from client. + * client_shm_fd - client shared memory fd from client. It can be -1. + * + * Returns: + * 0 on success, negative error on failure. + */ +int rclient_validate_stream_connect_params( + const struct cras_rclient *client, + const struct cras_connect_message *msg, int audio_fd, + int client_shm_fd); + +/* Handles a message from the client to connect a new stream + * + * Args: + * client - The cras_rclient which gets the message. + * msg - The cras_connect_message from client. + * aud_fd - The audio fd comes from client. Its ownership will be taken. + * client_shm_fd - The client_shm_fd from client. Its ownership will be taken. + * + * Returns: + * 0 on success, negative error on failure. + */ +int rclient_handle_client_stream_connect(struct cras_rclient *client, + const struct cras_connect_message *msg, + int aud_fd, int client_shm_fd); + +/* Handles messages from the client requesting that a stream be removed from the + * server. + * + * Args: + * client - The cras_rclient which gets the message. + * msg - The cras_disconnect_stream_message from client. + * + * Returns: + * 0 on success, negative error on failure. + */ +int rclient_handle_client_stream_disconnect( + struct cras_rclient *client, + const struct cras_disconnect_stream_message *msg); + +/* + * Converts an old version of connect message to the correct + * cras_connect_message. Returns zero on success, negative on failure. + * Note that this is special check only for libcras transition in + * clients, from CRAS_PROTO_VER = 3 to 5. + * TODO(yuhsuan): clean up the function once clients transition is done. + */ +static inline int +convert_connect_message_old(const struct cras_server_message *msg, + struct cras_connect_message *cmsg) +{ + struct cras_connect_message_old *old; + + if (!MSG_LEN_VALID(msg, struct cras_connect_message_old)) + return -EINVAL; + + old = (struct cras_connect_message_old *)msg; + if (old->proto_version != 3 || CRAS_PROTO_VER != 5) + return -EINVAL; + + memcpy(cmsg, old, sizeof(*old)); + cmsg->client_type = CRAS_CLIENT_TYPE_LEGACY; + cmsg->client_shm_size = 0; + return 0; +} + +#endif /* CRAS_RCLIENT_UTIL_H_ */ diff --git a/cras/src/server/cras_rstream.c b/cras/src/server/cras_rstream.c index 12a6f83e..55beed2b 100644 --- a/cras/src/server/cras_rstream.c +++ b/cras/src/server/cras_rstream.c @@ -20,8 +20,60 @@ #include "buffer_share.h" #include "cras_system_state.h" -/* Setup the shared memory area used for audio samples. */ -static inline int setup_shm_area(struct cras_rstream *stream) +void cras_rstream_config_init( + struct cras_rclient *client, cras_stream_id_t stream_id, + enum CRAS_STREAM_TYPE stream_type, enum CRAS_CLIENT_TYPE client_type, + enum CRAS_STREAM_DIRECTION direction, uint32_t dev_idx, uint32_t flags, + uint32_t effects, const struct cras_audio_format *format, + size_t buffer_frames, size_t cb_threshold, int *audio_fd, + int *client_shm_fd, size_t client_shm_size, + struct cras_rstream_config *stream_config) +{ + stream_config->stream_id = stream_id; + stream_config->stream_type = stream_type; + stream_config->client_type = client_type; + stream_config->direction = direction; + stream_config->dev_idx = dev_idx; + stream_config->flags = flags; + stream_config->effects = effects; + stream_config->format = format; + stream_config->buffer_frames = buffer_frames; + stream_config->cb_threshold = cb_threshold; + stream_config->audio_fd = *audio_fd; + *audio_fd = -1; + stream_config->client_shm_fd = *client_shm_fd; + *client_shm_fd = -1; + stream_config->client_shm_size = client_shm_size; + stream_config->client = client; +} + +void cras_rstream_config_init_with_message( + struct cras_rclient *client, const struct cras_connect_message *msg, + int *aud_fd, int *client_shm_fd, + const struct cras_audio_format *remote_fmt, + struct cras_rstream_config *stream_config) +{ + cras_rstream_config_init(client, msg->stream_id, msg->stream_type, + msg->client_type, msg->direction, msg->dev_idx, + msg->flags, msg->effects, remote_fmt, + msg->buffer_frames, msg->cb_threshold, aud_fd, + client_shm_fd, msg->client_shm_size, + stream_config); +} + +void cras_rstream_config_cleanup(struct cras_rstream_config *stream_config) +{ + if (stream_config->audio_fd >= 0) + close(stream_config->audio_fd); + if (stream_config->client_shm_fd >= 0) + close(stream_config->client_shm_fd); +} + +/* Setup the shared memory area used for audio samples. client_shm_fd must be + * closed after calling this function. + */ +static inline int setup_shm_area(struct cras_rstream *stream, int client_shm_fd, + size_t client_shm_size) { const struct cras_audio_format *fmt = &stream->format; char header_name[NAME_MAX]; @@ -30,8 +82,10 @@ static inline int setup_shm_area(struct cras_rstream *stream) uint32_t frame_bytes, used_size; int rc; - if (stream->shm) /* already setup */ + if (stream->shm) { + /* already setup */ return -EEXIST; + } snprintf(header_name, sizeof(header_name), "/cras-%d-stream-%08x-header", getpid(), stream->stream_id); @@ -41,64 +95,35 @@ static inline int setup_shm_area(struct cras_rstream *stream) if (rc) return rc; - snprintf(samples_name, sizeof(samples_name), - "/cras-%d-stream-%08x-samples", getpid(), stream->stream_id); - frame_bytes = snd_pcm_format_physical_width(fmt->format) / 8 * fmt->num_channels; used_size = stream->buffer_frames * frame_bytes; - rc = cras_shm_info_init(samples_name, - cras_shm_calculate_samples_size(used_size), - &samples_info); + if (client_shm_fd >= 0 && client_shm_size > 0) { + rc = cras_shm_info_init_with_fd(client_shm_fd, client_shm_size, + &samples_info); + } else { + snprintf(samples_name, sizeof(samples_name), + "/cras-%d-stream-%08x-samples", getpid(), + stream->stream_id); + rc = cras_shm_info_init( + samples_name, + cras_shm_calculate_samples_size(used_size), + &samples_info); + } if (rc) { cras_shm_info_cleanup(&header_info); return rc; } - rc = cras_audio_shm_create(&header_info, &samples_info, &stream->shm); - if (rc) - return rc; - - cras_shm_set_frame_bytes(stream->shm, frame_bytes); - cras_shm_set_used_size(stream->shm, used_size); - - stream->audio_area = - cras_audio_area_create(stream->format.num_channels); - cras_audio_area_config_channels(stream->audio_area, &stream->format); + int samples_prot = 0; + if (stream->direction == CRAS_STREAM_OUTPUT) + samples_prot = PROT_READ; + else + samples_prot = PROT_WRITE; - return 0; -} - -/* Setup a legacy unsplit shared memory area for audio samples. - * Will be removed once ARC++ transitions to a split shm */ -static inline int setup_unsplit_shm_area(struct cras_rstream *stream) -{ - const struct cras_audio_format *fmt = &stream->format; - char stream_name[NAME_MAX]; - struct cras_shm_info shm_info; - uint32_t frame_bytes, used_size; - int rc; - - if (stream->shm) /* already setup */ - return -EEXIST; - - snprintf(stream_name, sizeof(stream_name), "/cras-%d-stream-%08x", - getpid(), stream->stream_id); - - frame_bytes = snd_pcm_format_physical_width(fmt->format) / 8 * - fmt->num_channels; - used_size = stream->buffer_frames * frame_bytes; - - rc = cras_shm_info_init( - stream_name, - cras_shm_header_size() + - cras_shm_calculate_samples_size(used_size), - &shm_info); - if (rc) - return rc; - - rc = cras_audio_unsplit_shm_create(&shm_info, &stream->shm); + rc = cras_audio_shm_create(&header_info, &samples_info, samples_prot, + &stream->shm); if (rc) return rc; @@ -122,6 +147,7 @@ static int verify_rstream_parameters(enum CRAS_STREAM_DIRECTION direction, const struct cras_audio_format *format, enum CRAS_STREAM_TYPE stream_type, size_t buffer_frames, size_t cb_threshold, + int client_shm_fd, size_t client_shm_size, struct cras_rclient *client, struct cras_rstream **stream_out) { @@ -159,6 +185,11 @@ static int verify_rstream_parameters(enum CRAS_STREAM_DIRECTION direction, syslog(LOG_ERR, "rstream: cb_threshold too low\n"); return -EINVAL; } + if ((client_shm_size > 0 && client_shm_fd < 0) || + (client_shm_size == 0 && client_shm_fd >= 0)) { + syslog(LOG_ERR, "rstream: invalid client-provided shm info\n"); + return -EINVAL; + } return 0; } @@ -249,11 +280,11 @@ int cras_rstream_create(struct cras_rstream_config *config, struct cras_rstream *stream; int rc; - rc = verify_rstream_parameters(config->direction, config->format, - config->stream_type, - config->buffer_frames, - config->cb_threshold, config->client, - stream_out); + rc = verify_rstream_parameters( + config->direction, config->format, config->stream_type, + config->buffer_frames, config->cb_threshold, + config->client_shm_fd, config->client_shm_size, config->client, + stream_out); if (rc < 0) return rc; @@ -263,6 +294,7 @@ int cras_rstream_create(struct cras_rstream_config *config, stream->stream_id = config->stream_id; stream->stream_type = config->stream_type; + stream->client_type = config->client_type; stream->direction = config->direction; stream->flags = config->flags; stream->format = *config->format; @@ -275,19 +307,17 @@ int cras_rstream_create(struct cras_rstream_config *config, stream->num_missed_cb = 0; stream->is_pinned = (config->dev_idx != NO_DEVICE); stream->pinned_dev_idx = config->dev_idx; - stream->fd = config->audio_fd; - if (config->use_split_shm) { - rc = setup_shm_area(stream); - } else { - rc = setup_unsplit_shm_area(stream); - } + rc = setup_shm_area(stream, config->client_shm_fd, + config->client_shm_size); if (rc < 0) { syslog(LOG_ERR, "failed to setup shm %d\n", rc); free(stream); return rc; } + stream->fd = config->audio_fd; + config->audio_fd = -1; stream->buf_state = buffer_share_create(stream->buffer_frames); stream->apm_list = (stream->direction == CRAS_STREAM_INPUT) ? diff --git a/cras/src/server/cras_rstream.h b/cras/src/server/cras_rstream.h index d8919299..3329fe0c 100644 --- a/cras/src/server/cras_rstream.h +++ b/cras/src/server/cras_rstream.h @@ -13,6 +13,7 @@ #include "cras_shm.h" #include "cras_types.h" +struct cras_connect_message; struct cras_rclient; struct dev_mix; @@ -32,6 +33,7 @@ struct master_dev_info { * Members: * stream_id - identifier for this stream. * stream_type - not used. + * client_type - The client type of this stream, like Chrome, ARC++. * direction - input or output. * flags - Indicative of what special handling is needed. * fd - Socket for requesting and sending audio buffer events. @@ -61,6 +63,7 @@ struct master_dev_info { struct cras_rstream { cras_stream_id_t stream_id; enum CRAS_STREAM_TYPE stream_type; + enum CRAS_CLIENT_TYPE client_type; enum CRAS_STREAM_DIRECTION direction; uint32_t flags; int fd; @@ -91,6 +94,7 @@ struct cras_rstream { /* Config for creating an rstream. * stream_type - CRAS_STREAM_TYPE. + * client_type - CRAS_CLIENT_TYPE. * direction - CRAS_STREAM_OUTPUT or CRAS_STREAM_INPUT. * dev_idx - Pin to this device if != NO_DEVICE. * flags - Any special handling for this stream. @@ -98,16 +102,18 @@ struct cras_rstream { * format - The audio format the stream wishes to use. * buffer_frames - Total number of audio frames to buffer. * cb_threshold - # of frames when to request more from the client. - * audio_fd - The fd to read/write audio signals to. + * audio_fd - The fd to read/write audio signals to. May be -1 for server + * stream. Some functions may mutably borrow the config and move + * the fd ownership. + * client_shm_fd - The shm fd to use to back the samples area. May be -1. + * Some functions may dup this fd while borrowing the config. + * client_shm_size - The size of shm area backed by client_shm_fd. * client - The client that owns this stream. - * - * TODO(fletcherw) remove once libcras in ARC++ has been upreved - * use_split_shm - Should this stream use the new split shm area. - * Will be removed after all clients transition to split shm. */ struct cras_rstream_config { cras_stream_id_t stream_id; enum CRAS_STREAM_TYPE stream_type; + enum CRAS_CLIENT_TYPE client_type; enum CRAS_STREAM_DIRECTION direction; uint32_t dev_idx; uint32_t flags; @@ -116,13 +122,59 @@ struct cras_rstream_config { size_t buffer_frames; size_t cb_threshold; int audio_fd; + int client_shm_fd; + size_t client_shm_size; struct cras_rclient *client; - int use_split_shm; }; +/* Fills cras_rstream_config with given parameters. + * + * Args: + * audio_fd - The audio fd pointer from client. Its ownership will be moved to + * stream_config. + * client_shm_fd - The shared memory fd pointer for samples from client. Its + * ownership will be moved to stream_config. + * Other args - See comments in struct cras_rstream_config. + */ +void cras_rstream_config_init( + struct cras_rclient *client, cras_stream_id_t stream_id, + enum CRAS_STREAM_TYPE stream_type, enum CRAS_CLIENT_TYPE client_type, + enum CRAS_STREAM_DIRECTION direction, uint32_t dev_idx, uint32_t flags, + uint32_t effects, const struct cras_audio_format *format, + size_t buffer_frames, size_t cb_threshold, int *audio_fd, + int *client_shm_fd, size_t client_shm_size, + struct cras_rstream_config *stream_config); + +/* Fills cras_rstream_config with given parameters and a cras_connect_message. + * + * Args: + * client - The rclient which handles the connect message. + * msg - The cras_connect_message from client. + * aud_fd - The audio fd pointer from client. Its ownership will be moved to + * stream_config. + * client_shm_fd - The shared memory fd pointer for samples from client. Its + * ownership will be moved to stream_config. + * remote_format - The remote_format for the config. + * stream_config - The cras_rstream_config to be filled. + */ +void cras_rstream_config_init_with_message( + struct cras_rclient *client, const struct cras_connect_message *msg, + int *aud_fd, int *client_shm_fd, + const struct cras_audio_format *remote_format, + struct cras_rstream_config *stream_config); + +/* Cleans up given cras_rstream_config. All fds inside the config will be + * closed. + * + * Args: + * stream_config - The config to be cleaned up. + */ +void cras_rstream_config_cleanup(struct cras_rstream_config *stream_config); + /* Creates an rstream. * Args: - * config - Params for configuration of the new rstream. + * config - Params for configuration of the new rstream. It's a mutable + * borrow. * stream_out - Filled with the newly created stream pointer. * Returns: * 0 on success, EINVAL if an invalid argument is passed, or ENOMEM if out of diff --git a/cras/src/server/cras_server.c b/cras/src/server/cras_server.c index 57c9a912..97c83dfd 100644 --- a/cras/src/server/cras_server.c +++ b/cras/src/server/cras_server.c @@ -45,11 +45,11 @@ #include "cras_non_empty_audio_handler.h" #include "cras_observer.h" #include "cras_rclient.h" -#include "cras_control_rclient.h" #include "cras_server.h" #include "cras_server_metrics.h" #include "cras_system_state.h" #include "cras_tm.h" +#include "cras_types.h" #include "cras_udev.h" #include "cras_util.h" #include "cras_mix.h" @@ -99,6 +99,13 @@ struct system_task { struct system_task *next, *prev; }; +/* A structure wraps data related to server socket. */ +struct server_socket { + struct sockaddr_un addr; + int fd; + enum CRAS_CONNECTION_TYPE type; +}; + /* Local server data. */ struct server_data { struct attached_client *clients_head; @@ -107,8 +114,19 @@ struct server_data { struct system_task *system_tasks; size_t num_client_callbacks; size_t next_client_id; + struct server_socket server_sockets[CRAS_NUM_CONN_TYPE]; } server_instance; +/* Cleanup a given server_socket */ +static void server_socket_cleanup(struct server_socket *socket) +{ + if (socket && socket->fd >= 0) { + close(socket->fd); + socket->fd = -1; + unlink(socket->addr.sun_path); + } +} + /* Remove a client from the list and destroy it. Calling rclient_destroy will * also free all the streams owned by the client */ static void remove_client(struct attached_client *client) @@ -127,19 +145,21 @@ static void handle_message_from_client(struct attached_client *client) { uint8_t buf[CRAS_SERV_MAX_MSG_SIZE]; int nread; - int fd; - unsigned int num_fds = 1; + unsigned int num_fds = 2; + int fds[num_fds]; - nread = cras_recv_with_fds(client->fd, buf, sizeof(buf), &fd, &num_fds); + nread = cras_recv_with_fds(client->fd, buf, sizeof(buf), fds, &num_fds); if (nread < 0) goto read_error; - if (cras_rclient_buffer_from_client(client->client, buf, nread, fd) < 0) + if (cras_rclient_buffer_from_client(client->client, buf, nread, fds, + num_fds) < 0) goto read_error; return; read_error: - if (fd != -1) - close(fd); + for (int i = 0; i < num_fds; i++) + if (fds[i] >= 0) + close(fds[i]); switch (nread) { case 0: break; @@ -194,7 +214,7 @@ static void send_client_list_to_clients(struct server_data *serv) /* Handles requests from a client to attach to the server. Create a local * structure to track the client, assign it a unique id and let it attach */ -static void handle_new_connection(struct sockaddr_un *address, int fd) +static void handle_new_connection(struct server_socket *server_socket) { int connection_fd; struct attached_client *poll_client; @@ -207,7 +227,9 @@ static void handle_new_connection(struct sockaddr_un *address, int fd) } memset(&address_length, 0, sizeof(address_length)); - connection_fd = accept(fd, (struct sockaddr *)address, &address_length); + connection_fd = accept(server_socket->fd, + (struct sockaddr *)&server_socket->addr, + &address_length); if (connection_fd < 0) { syslog(LOG_ERR, "connecting"); free(poll_client); @@ -232,13 +254,12 @@ static void handle_new_connection(struct sockaddr_un *address, int fd) poll_client->next = NULL; poll_client->pollfd = NULL; fill_client_info(poll_client); - poll_client->client = - cras_control_rclient_create(connection_fd, poll_client->id); + + poll_client->client = cras_rclient_create( + connection_fd, poll_client->id, server_socket->type); if (poll_client->client == NULL) { syslog(LOG_ERR, "failed to create client"); - close(connection_fd); - free(poll_client); - return; + goto error; } DL_APPEND(server_instance.clients_head, poll_client); @@ -246,6 +267,11 @@ static void handle_new_connection(struct sockaddr_un *address, int fd) /* Send a current list of available inputs and outputs. */ cras_iodev_list_update_device_list(); send_client_list_to_clients(&server_instance); + return; +error: + close(connection_fd); + free(poll_client); + return; } /* Add a file descriptor to be passed to select in the main loop. This is @@ -431,25 +457,31 @@ int cras_server_init() cras_system_set_add_task_handler(add_task, &server_instance); cras_main_message_init(); + /* Initializes all server_sockets */ + for (int conn_type = 0; conn_type < CRAS_NUM_CONN_TYPE; conn_type++) { + server_instance.server_sockets[conn_type].fd = -1; + } + return 0; } /* - * Creates a server socket with a given socket_file name and listens on it. + * Creates a server socket with given connection type and listens on it. * The socket_file will be created under cras_config_get_system_socket_file_dir * with permission=0770. The socket_fd will be listened with parameter * backlog=5. * - * Returns the socket_fd and leaves the address information in addr. + * Returns 0 on success and leaves the created fd and the address information + * in server_socket. * When error occurs, the created fd will be closed and the file path will be * unlinked. */ -static int create_and_listen_server_socket(const char *socket_file, - struct sockaddr_un *addr) +static int create_and_listen_server_socket(enum CRAS_CONNECTION_TYPE conn_type, + struct server_socket *server_socket) { int socket_fd = -1; int rc = 0; - const char *sockdir; + struct sockaddr_un *addr = &server_socket->addr; socket_fd = socket(PF_UNIX, SOCK_SEQPACKET, 0); if (socket_fd < 0) { @@ -458,16 +490,11 @@ static int create_and_listen_server_socket(const char *socket_file, goto error; } - sockdir = cras_config_get_system_socket_file_dir(); - if (sockdir == NULL) { - rc = -ENOTDIR; - goto error; - } - memset(addr, 0, sizeof(*addr)); addr->sun_family = AF_UNIX; - snprintf(addr->sun_path, sizeof(addr->sun_path), "%s/%s", sockdir, - socket_file); + rc = cras_fill_socket_path(conn_type, addr->sun_path); + if (rc < 0) + goto error; unlink(addr->sun_path); /* Linux quirk: calling fchmod before bind, sets the permissions of the @@ -496,7 +523,9 @@ static int create_and_listen_server_socket(const char *socket_file, goto error; } - return socket_fd; + server_socket->fd = socket_fd; + server_socket->type = conn_type; + return 0; error: if (socket_fd >= 0) { close(socket_fd); @@ -505,15 +534,22 @@ error: return rc; } +/* Cleans up all server_socket in server_instance */ +static void cleanup_server_sockets() +{ + for (int conn_type = 0; conn_type < CRAS_NUM_CONN_TYPE; conn_type++) { + server_socket_cleanup( + &server_instance.server_sockets[conn_type]); + } +} + int cras_server_run(unsigned int profile_disable_mask) { static const unsigned int OUTPUT_CHECK_MS = 5 * 1000; #ifdef CRAS_DBUS DBusConnection *dbus_conn; #endif - int control_fd = -1; int rc = 0; - struct sockaddr_un control_addr; struct attached_client *elm; struct client_callback *client_cb; struct system_task *tasks; @@ -559,10 +595,12 @@ int cras_server_run(unsigned int profile_disable_mask) } #endif - control_fd = create_and_listen_server_socket(CRAS_SOCKET_FILE, - &control_addr); - if (control_fd < 0) - goto bail; + for (int conn_type = 0; conn_type < CRAS_NUM_CONN_TYPE; conn_type++) { + rc = create_and_listen_server_socket( + conn_type, &server_instance.server_sockets[conn_type]); + if (rc < 0) + goto bail; + } tm = cras_system_state_get_tm(); if (!tm) { @@ -576,7 +614,8 @@ int cras_server_run(unsigned int profile_disable_mask) /* Main server loop - client callbacks are run from this context. */ while (1) { - poll_size_needed = 1 + server_instance.num_clients + + poll_size_needed = CRAS_NUM_CONN_TYPE + + server_instance.num_clients + server_instance.num_client_callbacks; if (poll_size_needed > pollfds_size) { pollfds_size = 2 * poll_size_needed; @@ -584,9 +623,13 @@ int cras_server_run(unsigned int profile_disable_mask) sizeof(*pollfds) * pollfds_size); } - pollfds[0].fd = control_fd; - pollfds[0].events = POLLIN; - num_pollfds = 1; + for (int conn_type = 0; conn_type < CRAS_NUM_CONN_TYPE; + conn_type++) { + pollfds[conn_type].fd = + server_instance.server_sockets[conn_type].fd; + pollfds[conn_type].events = POLLIN; + } + num_pollfds = CRAS_NUM_CONN_TYPE; DL_FOREACH (server_instance.clients_head, elm) { pollfds[num_pollfds].fd = elm->fd; @@ -629,8 +672,14 @@ int cras_server_run(unsigned int profile_disable_mask) cras_tm_call_callbacks(tm); /* Check for new connections. */ - if (pollfds[0].revents & POLLIN) - handle_new_connection(&control_addr, control_fd); + for (int conn_type = 0; conn_type < CRAS_NUM_CONN_TYPE; + conn_type++) { + if (pollfds[conn_type].revents & POLLIN) + handle_new_connection( + &server_instance + .server_sockets[conn_type]); + } + /* Check if there are messages pending for any clients. */ DL_FOREACH (server_instance.clients_head, elm) if (elm->pollfd && elm->pollfd->revents & POLLIN) @@ -652,10 +701,7 @@ int cras_server_run(unsigned int profile_disable_mask) } bail: - if (control_fd >= 0) { - close(control_fd); - unlink(control_addr.sun_path); - } + cleanup_server_sockets(); free(pollfds); cras_observer_server_free(); return rc; @@ -667,4 +713,4 @@ void cras_server_send_to_all_clients(const struct cras_client_message *msg) DL_FOREACH (server_instance.clients_head, client) cras_rclient_send_message(client->client, msg, NULL, 0); -} +}
\ No newline at end of file diff --git a/cras/src/server/cras_server_metrics.c b/cras/src/server/cras_server_metrics.c index 12f1bdfb..5f51e83e 100644 --- a/cras/src/server/cras_server_metrics.c +++ b/cras/src/server/cras_server_metrics.c @@ -20,6 +20,9 @@ #define METRICS_NAME_BUFFER_SIZE 50 +const char kBusyloop[] = "Cras.Busyloop"; +const char kDeviceTypeInput[] = "Cras.DeviceTypeInput"; +const char kDeviceTypeOutput[] = "Cras.DeviceTypeOutput"; const char kHighestDeviceDelayInput[] = "Cras.HighestDeviceDelayInput"; const char kHighestDeviceDelayOutput[] = "Cras.HighestDeviceDelayOutput"; const char kHighestInputHardwareLevel[] = "Cras.HighestInputHardwareLevel"; @@ -43,11 +46,14 @@ const char kMissedCallbackSecondTimeOutput[] = const char kNoCodecsFoundMetric[] = "Cras.NoCodecsFoundAtBoot"; const char kStreamTimeoutMilliSeconds[] = "Cras.StreamTimeoutMilliSeconds"; const char kStreamCallbackThreshold[] = "Cras.StreamCallbackThreshold"; +const char kStreamClientTypeInput[] = "Cras.StreamClientTypeInput"; +const char kStreamClientTypeOutput[] = "Cras.StreamClientTypeOutput"; const char kStreamFlags[] = "Cras.StreamFlags"; const char kStreamSamplingFormat[] = "Cras.StreamSamplingFormat"; const char kStreamSamplingRate[] = "Cras.StreamSamplingRate"; const char kUnderrunsPerDevice[] = "Cras.UnderrunsPerDevice"; const char kHfpWidebandSpeechSupported[] = "Cras.HfpWidebandSpeechSupported"; +const char kHfpWidebandSpeechPacketLoss[] = "Cras.HfpWidebandSpeechPacketLoss"; /* * Records missed callback frequency only when the runtime of stream is larger @@ -55,9 +61,23 @@ const char kHfpWidebandSpeechSupported[] = "Cras.HfpWidebandSpeechSupported"; */ const double MISSED_CB_FREQUENCY_SECONDS_MIN = 10.0; +const time_t CRAS_METRICS_SHORT_PERIOD_THRESHOLD_SECONDS = 600; +const time_t CRAS_METRICS_LONG_PERIOD_THRESHOLD_SECONDS = 3600; + +static const char *get_timespec_period_str(struct timespec ts) +{ + if (ts.tv_sec < CRAS_METRICS_SHORT_PERIOD_THRESHOLD_SECONDS) + return "ShortPeriod"; + if (ts.tv_sec < CRAS_METRICS_LONG_PERIOD_THRESHOLD_SECONDS) + return "MediumPeriod"; + return "LongPeriod"; +} + /* Type of metrics to log. */ enum CRAS_SERVER_METRICS_TYPE { + BT_WIDEBAND_PACKET_LOSS, BT_WIDEBAND_SUPPORTED, + BUSYLOOP, DEVICE_RUNTIME, HIGHEST_DEVICE_DELAY_INPUT, HIGHEST_DEVICE_DELAY_OUTPUT, @@ -76,23 +96,60 @@ enum CRAS_SERVER_METRICS_TYPE { STREAM_CONFIG }; +enum CRAS_METRICS_DEVICE_TYPE { + /* Output devices. */ + CRAS_METRICS_DEVICE_INTERNAL_SPEAKER, + CRAS_METRICS_DEVICE_HEADPHONE, + CRAS_METRICS_DEVICE_HDMI, + CRAS_METRICS_DEVICE_HAPTIC, + CRAS_METRICS_DEVICE_LINEOUT, + /* Input devices. */ + CRAS_METRICS_DEVICE_INTERNAL_MIC, + CRAS_METRICS_DEVICE_FRONT_MIC, + CRAS_METRICS_DEVICE_REAR_MIC, + CRAS_METRICS_DEVICE_KEYBOARD_MIC, + CRAS_METRICS_DEVICE_MIC, + CRAS_METRICS_DEVICE_HOTWORD, + CRAS_METRICS_DEVICE_POST_MIX_LOOPBACK, + CRAS_METRICS_DEVICE_POST_DSP_LOOPBACK, + /* Devices supporting input and output function. */ + CRAS_METRICS_DEVICE_USB, + CRAS_METRICS_DEVICE_A2DP, + CRAS_METRICS_DEVICE_HFP, + CRAS_METRICS_DEVICE_HSP, + CRAS_METRICS_DEVICE_BLUETOOTH, + CRAS_METRICS_DEVICE_NO_DEVICE, + CRAS_METRICS_DEVICE_NORMAL_FALLBACK, + CRAS_METRICS_DEVICE_ABNORMAL_FALLBACK, + CRAS_METRICS_DEVICE_SILENT_HOTWORD, + CRAS_METRICS_DEVICE_UNKNOWN, +}; + struct cras_server_metrics_stream_config { + enum CRAS_STREAM_DIRECTION direction; unsigned cb_threshold; unsigned flags; int format; unsigned rate; + enum CRAS_CLIENT_TYPE client_type; }; struct cras_server_metrics_device_data { - const char *type; + enum CRAS_METRICS_DEVICE_TYPE type; enum CRAS_STREAM_DIRECTION direction; struct timespec runtime; }; +struct cras_server_metrics_timespec_data { + struct timespec runtime; + unsigned count; +}; + union cras_server_metrics_data { unsigned value; struct cras_server_metrics_stream_config stream_config; struct cras_server_metrics_device_data device_data; + struct cras_server_metrics_timespec_data timespec_data; }; /* @@ -132,58 +189,156 @@ static int cras_server_metrics_message_send(struct cras_main_message *msg) return cras_main_message_send(msg); } -static const char *get_metrics_device_type_str(struct cras_iodev *iodev) +static inline const char * +metrics_device_type_str(enum CRAS_METRICS_DEVICE_TYPE device_type) +{ + switch (device_type) { + case CRAS_METRICS_DEVICE_INTERNAL_SPEAKER: + return "InternalSpeaker"; + case CRAS_METRICS_DEVICE_HEADPHONE: + return "Headphone"; + case CRAS_METRICS_DEVICE_HDMI: + return "HDMI"; + case CRAS_METRICS_DEVICE_HAPTIC: + return "Haptic"; + case CRAS_METRICS_DEVICE_LINEOUT: + return "Lineout"; + /* Input devices. */ + case CRAS_METRICS_DEVICE_INTERNAL_MIC: + return "InternalMic"; + case CRAS_METRICS_DEVICE_FRONT_MIC: + return "FrontMic"; + case CRAS_METRICS_DEVICE_REAR_MIC: + return "RearMic"; + case CRAS_METRICS_DEVICE_KEYBOARD_MIC: + return "KeyboardMic"; + case CRAS_METRICS_DEVICE_MIC: + return "Mic"; + case CRAS_METRICS_DEVICE_HOTWORD: + return "Hotword"; + case CRAS_METRICS_DEVICE_POST_MIX_LOOPBACK: + return "PostMixLoopback"; + case CRAS_METRICS_DEVICE_POST_DSP_LOOPBACK: + return "PostDspLoopback"; + /* Devices supporting input and output function. */ + case CRAS_METRICS_DEVICE_USB: + return "USB"; + case CRAS_METRICS_DEVICE_A2DP: + return "A2DP"; + case CRAS_METRICS_DEVICE_HFP: + return "HFP"; + case CRAS_METRICS_DEVICE_HSP: + return "HSP"; + case CRAS_METRICS_DEVICE_BLUETOOTH: + return "Bluetooth"; + case CRAS_METRICS_DEVICE_NO_DEVICE: + return "NoDevice"; + /* Other dummy devices. */ + case CRAS_METRICS_DEVICE_NORMAL_FALLBACK: + return "NormalFallback"; + case CRAS_METRICS_DEVICE_ABNORMAL_FALLBACK: + return "AbnormalFallback"; + case CRAS_METRICS_DEVICE_SILENT_HOTWORD: + return "SilentHotword"; + case CRAS_METRICS_DEVICE_UNKNOWN: + return "Unknown"; + default: + return "InvalidType"; + } +} + +static enum CRAS_METRICS_DEVICE_TYPE +get_metrics_device_type(struct cras_iodev *iodev) { + /* Check whether it is a special device. */ + if (iodev->info.idx < MAX_SPECIAL_DEVICE_IDX) { + switch (iodev->info.idx) { + case NO_DEVICE: + syslog(LOG_ERR, "The invalid device has been used."); + return CRAS_METRICS_DEVICE_NO_DEVICE; + case SILENT_RECORD_DEVICE: + case SILENT_PLAYBACK_DEVICE: + if (iodev->active_node->type == + CRAS_NODE_TYPE_FALLBACK_NORMAL) + return CRAS_METRICS_DEVICE_NORMAL_FALLBACK; + else + return CRAS_METRICS_DEVICE_ABNORMAL_FALLBACK; + case SILENT_HOTWORD_DEVICE: + return CRAS_METRICS_DEVICE_SILENT_HOTWORD; + } + } + switch (iodev->active_node->type) { case CRAS_NODE_TYPE_INTERNAL_SPEAKER: - return "InternalSpeaker"; + return CRAS_METRICS_DEVICE_INTERNAL_SPEAKER; case CRAS_NODE_TYPE_HEADPHONE: - return "Headphone"; + return CRAS_METRICS_DEVICE_HEADPHONE; case CRAS_NODE_TYPE_HDMI: - return "HDMI"; + return CRAS_METRICS_DEVICE_HDMI; case CRAS_NODE_TYPE_HAPTIC: - return "Haptic"; + return CRAS_METRICS_DEVICE_HAPTIC; case CRAS_NODE_TYPE_LINEOUT: - return "Lineout"; + return CRAS_METRICS_DEVICE_LINEOUT; case CRAS_NODE_TYPE_MIC: switch (iodev->active_node->position) { case NODE_POSITION_INTERNAL: - return "InternalMic"; + return CRAS_METRICS_DEVICE_INTERNAL_MIC; case NODE_POSITION_FRONT: - return "FrontMic"; + return CRAS_METRICS_DEVICE_FRONT_MIC; case NODE_POSITION_REAR: - return "RearMic"; + return CRAS_METRICS_DEVICE_REAR_MIC; case NODE_POSITION_KEYBOARD: - return "KeyboardMic"; + return CRAS_METRICS_DEVICE_KEYBOARD_MIC; case NODE_POSITION_EXTERNAL: default: - return "Mic"; + return CRAS_METRICS_DEVICE_MIC; } case CRAS_NODE_TYPE_HOTWORD: - return "Hotword"; + return CRAS_METRICS_DEVICE_HOTWORD; case CRAS_NODE_TYPE_POST_MIX_PRE_DSP: - return "PostMixLoopback"; + return CRAS_METRICS_DEVICE_POST_MIX_LOOPBACK; case CRAS_NODE_TYPE_POST_DSP: - return "PostDspLoopback"; + return CRAS_METRICS_DEVICE_POST_DSP_LOOPBACK; case CRAS_NODE_TYPE_USB: - return "USB"; + return CRAS_METRICS_DEVICE_USB; case CRAS_NODE_TYPE_BLUETOOTH: #ifdef CRAS_DBUS if (cras_bt_io_on_profile(iodev, CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE)) - return "A2DP"; + return CRAS_METRICS_DEVICE_A2DP; if (cras_bt_io_on_profile( iodev, CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY)) - return "HFP"; + return CRAS_METRICS_DEVICE_HFP; if (cras_bt_io_on_profile( iodev, CRAS_BT_DEVICE_PROFILE_HSP_AUDIOGATEWAY)) - return "HSP"; + return CRAS_METRICS_DEVICE_HSP; #endif - return "Bluetooth"; + return CRAS_METRICS_DEVICE_BLUETOOTH; case CRAS_NODE_TYPE_UNKNOWN: default: - return "Unknown"; + return CRAS_METRICS_DEVICE_UNKNOWN; + } +} + +int cras_server_metrics_hfp_packet_loss(float packet_loss_ratio) +{ + struct cras_server_metrics_message msg; + union cras_server_metrics_data data; + int err; + + /* Percentage is too coarse for packet loss, so we use number of bad + * packets per thousand packets instead. */ + data.value = (unsigned)(round(packet_loss_ratio * 1000)); + init_server_metrics_msg(&msg, BT_WIDEBAND_PACKET_LOSS, data); + + err = cras_server_metrics_message_send( + (struct cras_main_message *)&msg); + if (err < 0) { + syslog(LOG_ERR, + "Failed to send metrics message: BT_WIDEBAND_PACKET_LOSS"); + return err; } + return 0; } int cras_server_metrics_hfp_wideband_support(bool supported) @@ -212,7 +367,7 @@ int cras_server_metrics_device_runtime(struct cras_iodev *iodev) struct timespec now; int err; - data.device_data.type = get_metrics_device_type_str(iodev); + data.device_data.type = get_metrics_device_type(iodev); data.device_data.direction = iodev->direction; clock_gettime(CLOCK_MONOTONIC_RAW, &now); subtract_timespecs(&now, &iodev->open_ts, &data.device_data.runtime); @@ -506,10 +661,12 @@ int cras_server_metrics_stream_config(struct cras_rstream_config *config) union cras_server_metrics_data data; int err; + data.stream_config.direction = config->direction; data.stream_config.cb_threshold = (unsigned)config->cb_threshold; data.stream_config.flags = (unsigned)config->flags; data.stream_config.format = (int)config->format->format; data.stream_config.rate = (unsigned)config->format->frame_rate; + data.stream_config.client_type = config->client_type; init_server_metrics_msg(&msg, STREAM_CONFIG, data); err = cras_server_metrics_message_send( @@ -523,6 +680,26 @@ int cras_server_metrics_stream_config(struct cras_rstream_config *config) return 0; } +int cras_server_metrics_busyloop(struct timespec *ts, unsigned count) +{ + struct cras_server_metrics_message msg; + union cras_server_metrics_data data; + int err; + + data.timespec_data.runtime = *ts; + data.timespec_data.count = count; + + init_server_metrics_msg(&msg, BUSYLOOP, data); + + err = cras_server_metrics_message_send( + (struct cras_main_message *)&msg); + if (err < 0) { + syslog(LOG_ERR, "Failed to send metrics message: BUSYLOOP"); + return err; + } + return 0; +} + static void metrics_device_runtime(struct cras_server_metrics_device_data data) { char metrics_name[METRICS_NAME_BUFFER_SIZE]; @@ -530,9 +707,25 @@ static void metrics_device_runtime(struct cras_server_metrics_device_data data) snprintf(metrics_name, METRICS_NAME_BUFFER_SIZE, "Cras.%sDevice%sRuntime", data.direction == CRAS_STREAM_INPUT ? "Input" : "Output", - data.type); + metrics_device_type_str(data.type)); cras_metrics_log_histogram(metrics_name, (unsigned)data.runtime.tv_sec, 0, 10000, 20); + + /* Logs the usage of each device. */ + if (data.direction == CRAS_STREAM_INPUT) + cras_metrics_log_sparse_histogram(kDeviceTypeInput, data.type); + else + cras_metrics_log_sparse_histogram(kDeviceTypeOutput, data.type); +} + +static void metrics_busyloop(struct cras_server_metrics_timespec_data data) +{ + char metrics_name[METRICS_NAME_BUFFER_SIZE]; + + snprintf(metrics_name, METRICS_NAME_BUFFER_SIZE, "%s.%s", kBusyloop, + get_timespec_period_str(data.runtime)); + + cras_metrics_log_histogram(metrics_name, data.count, 0, 1000, 20); } static void @@ -550,6 +743,14 @@ metrics_stream_config(struct cras_server_metrics_stream_config config) /* Logs stream sampling rate. */ cras_metrics_log_sparse_histogram(kStreamSamplingRate, config.rate); + + /* Logs stream client type. */ + if (config.direction == CRAS_STREAM_INPUT) + cras_metrics_log_sparse_histogram(kStreamClientTypeInput, + config.client_type); + else + cras_metrics_log_sparse_histogram(kStreamClientTypeOutput, + config.client_type); } static void handle_metrics_message(struct cras_main_message *msg, void *arg) @@ -557,6 +758,11 @@ static void handle_metrics_message(struct cras_main_message *msg, void *arg) struct cras_server_metrics_message *metrics_msg = (struct cras_server_metrics_message *)msg; switch (metrics_msg->metrics_type) { + case BT_WIDEBAND_PACKET_LOSS: + cras_metrics_log_histogram(kHfpWidebandSpeechPacketLoss, + metrics_msg->data.value, 0, 1000, + 20); + break; case BT_WIDEBAND_SUPPORTED: cras_metrics_log_sparse_histogram(kHfpWidebandSpeechSupported, metrics_msg->data.value); @@ -637,6 +843,9 @@ static void handle_metrics_message(struct cras_main_message *msg, void *arg) case STREAM_CONFIG: metrics_stream_config(metrics_msg->data.stream_config); break; + case BUSYLOOP: + metrics_busyloop(metrics_msg->data.timespec_data); + break; default: syslog(LOG_ERR, "Unknown metrics type %u", metrics_msg->metrics_type); diff --git a/cras/src/server/cras_server_metrics.h b/cras/src/server/cras_server_metrics.h index afc85b38..b9eb1216 100644 --- a/cras/src/server/cras_server_metrics.h +++ b/cras/src/server/cras_server_metrics.h @@ -16,6 +16,9 @@ extern const char kNoCodecsFoundMetric[]; /* Logs if connected HFP headset supports wideband speech. */ int cras_server_metrics_hfp_wideband_support(bool supported); +/* Logs the number of packet loss per 1000 packets under HFP capture. */ +int cras_server_metrics_hfp_packet_loss(float packet_loss_ratio); + /* Logs runtime of a device. */ int cras_server_metrics_device_runtime(struct cras_iodev *iodev); @@ -43,6 +46,9 @@ int cras_server_metrics_missed_cb_event(const struct cras_rstream *stream); /* Logs the stream configurations from clients. */ int cras_server_metrics_stream_config(struct cras_rstream_config *config); +/* Logs the number of busyloops for different time periods. */ +int cras_server_metrics_busyloop(struct timespec *ts, unsigned count); + /* Initialize metrics logging stuff. */ int cras_server_metrics_init(); diff --git a/cras/src/server/dev_io.c b/cras/src/server/dev_io.c index 07b89a66..97c61f92 100644 --- a/cras/src/server/dev_io.c +++ b/cras/src/server/dev_io.c @@ -9,6 +9,7 @@ #include "audio_thread_log.h" #include "cras_audio_area.h" +#include "cras_audio_thread_monitor.h" #include "cras_iodev.h" #include "cras_non_empty_audio_handler.h" #include "cras_rstream.h" @@ -16,6 +17,7 @@ #include "dev_stream.h" #include "input_data.h" #include "polled_interval_checker.h" +#include "rate_estimator.h" #include "utlist.h" #include "dev_io.h" @@ -33,6 +35,15 @@ static const int NON_EMPTY_UPDATE_INTERVAL_SEC = 5; */ static const int MIN_EMPTY_PERIOD_SEC = 30; +/* + * When the hw_level is less than this time, do not drop frames. + * (unit: millisecond). + * TODO(yuhsuan): Reduce the threshold when we create the other overrun op for + * boards which captures a lot of frames at one time. + * e.g. Input devices on grunt reads 1024 frames each time. + */ +static const int DROP_FRAMES_THRESHOLD_MS = 50; + /* The number of devices playing/capturing non-empty stream(s). */ static int non_empty_device_count = 0; @@ -323,12 +334,31 @@ static int get_input_dev_max_wake_ts(struct open_dev *adev, return 0; } +/* Returns whether a device can drop samples. */ +static bool input_devices_can_drop_samples(struct cras_iodev *iodev) +{ + if (!cras_iodev_is_open(iodev)) + return false; + if (!iodev->streams) + return false; + if (!iodev->active_node || + iodev->active_node->type == CRAS_NODE_TYPE_HOTWORD) + return false; + return true; +} + /* * Set wake_ts for this device to be the earliest wake up time for * dev_streams. Default value for adev->wake_ts will be now + 20s even if * any error occurs in this function. + * Args: + * adev - The input device. + * need_to_drop - The pointer to store whether we need to drop samples from + * a device in order to keep the lower hw_level. + * Returns: + * 0 on success. Negative error code on failure. */ -static int set_input_dev_wake_ts(struct open_dev *adev) +static int set_input_dev_wake_ts(struct open_dev *adev, bool *need_to_drop) { int rc; struct timespec level_tstamp, wake_time_out, min_ts, now, dev_wake_ts; @@ -351,6 +381,16 @@ static int set_input_dev_wake_ts(struct open_dev *adev) if (!timespec_is_nonzero(&level_tstamp)) clock_gettime(CLOCK_MONOTONIC_RAW, &level_tstamp); + /* + * If any input device has more than largest_cb_level * 1.5 frames, need to + * drop frames from all devices. + */ + if (input_devices_can_drop_samples(adev->dev) && + rc >= adev->dev->largest_cb_level * 1.5 && + cras_frames_to_ms(rc, adev->dev->format->frame_rate) >= + DROP_FRAMES_THRESHOLD_MS) + *need_to_drop = true; + cap_limit = get_stream_limit(adev, UINT_MAX, &cap_limit_stream); /* @@ -378,8 +418,11 @@ static int set_input_dev_wake_ts(struct open_dev *adev) } } + /* If there's no room in streams, don't bother schedule wake for more + * input data. */ if (adev->dev->active_node && - adev->dev->active_node->type != CRAS_NODE_TYPE_HOTWORD) { + adev->dev->active_node->type != CRAS_NODE_TYPE_HOTWORD && + cap_limit) { rc = get_input_dev_max_wake_ts(adev, curr_level, &dev_wake_ts); if (rc < 0) { syslog(LOG_ERR, @@ -758,12 +801,92 @@ int write_output_samples(struct open_dev **odevs, struct open_dev *adev, } /* + * Chooses the smallest difference between hw_level and min_cb_level as the + * drop time. + */ +static void get_input_devices_drop_time(struct open_dev *idev_list, + struct timespec *reset_ts) +{ + struct open_dev *adev; + struct cras_iodev *iodev; + struct timespec tmp; + struct timespec hw_tstamp; + double est_rate; + unsigned int target_level; + bool is_set = false; + int rc; + + DL_FOREACH (idev_list, adev) { + iodev = adev->dev; + if (!input_devices_can_drop_samples(iodev)) + continue; + + rc = cras_iodev_frames_queued(iodev, &hw_tstamp); + if (rc < 0) { + syslog(LOG_ERR, "Get frames from device %d, rc = %d", + iodev->info.idx, rc); + continue; + } + + target_level = iodev->min_cb_level; + if (rc <= target_level) { + reset_ts->tv_sec = 0; + reset_ts->tv_nsec = 0; + return; + } + est_rate = iodev->format->frame_rate * + cras_iodev_get_est_rate_ratio(iodev); + cras_frames_to_time(rc - target_level, est_rate, &tmp); + + if (!is_set || timespec_after(reset_ts, &tmp)) { + *reset_ts = tmp; + is_set = true; + } + } +} + +/* + * Drop samples from all input devices. + */ +static void dev_io_drop_samples(struct open_dev *idev_list) +{ + struct open_dev *adev; + struct timespec drop_time; + int rc; + + get_input_devices_drop_time(idev_list, &drop_time); + ATLOG(atlog, AUDIO_THREAD_CAPTURE_DROP_TIME, drop_time.tv_sec, + drop_time.tv_nsec, 0); + + if (timespec_is_zero(&drop_time)) + return; + + DL_FOREACH (idev_list, adev) { + if (!input_devices_can_drop_samples(adev->dev)) + continue; + + rc = cras_iodev_drop_frames_by_time(adev->dev, drop_time); + if (rc < 0) { + syslog(LOG_ERR, + "Failed to drop frames from device %d, rc = %d", + adev->dev->info.idx, rc); + continue; + } + } + + cras_audio_thread_event_drop_samples(); + + return; +} + +/* * Public funcitons. */ int dev_io_send_captured_samples(struct open_dev *idev_list) { struct open_dev *adev; + bool need_to_drop = false; int rc; // TODO(dgreid) - once per rstream, not once per dev_stream. @@ -779,11 +902,14 @@ int dev_io_send_captured_samples(struct open_dev *idev_list) } /* Set wake_ts for this device. */ - rc = set_input_dev_wake_ts(adev); + rc = set_input_dev_wake_ts(adev, &need_to_drop); if (rc < 0) return rc; } + if (need_to_drop) + dev_io_drop_samples(idev_list); + return 0; } @@ -795,10 +921,9 @@ static void handle_dev_err(int err_rc, struct open_dev **odevs, ATLOG(atlog, AUDIO_THREAD_SEVERE_UNDERRUN, adev->dev->info.idx, 0, 0); cras_iodev_reset_request(adev->dev); - } else { - /* Device error, close it. */ - dev_io_rm_open_dev(odevs, adev); } + /* Device error, remove it. */ + dev_io_rm_open_dev(odevs, adev); } int dev_io_capture(struct open_dev **list) @@ -929,10 +1054,38 @@ int dev_io_playback_write(struct open_dev **odevs, return 0; } +static void update_longest_wake(struct open_dev *dev_list, + const struct timespec *ts) +{ + struct open_dev *adev; + struct timespec wake_interval; + + DL_FOREACH (dev_list, adev) { + if (adev->dev->streams == NULL) + continue; + /* + * Calculate longest wake only when there's stream attached + * and the last wake time has been set. + */ + if (adev->last_wake.tv_sec) { + subtract_timespecs(ts, &adev->last_wake, + &wake_interval); + if (timespec_after(&wake_interval, &adev->longest_wake)) + adev->longest_wake = wake_interval; + } + adev->last_wake = *ts; + } +} + void dev_io_run(struct open_dev **odevs, struct open_dev **idevs, struct cras_fmt_conv *output_converter) { + struct timespec now; + + clock_gettime(CLOCK_MONOTONIC_RAW, &now); pic_update_current_time(); + update_longest_wake(*odevs, &now); + update_longest_wake(*idevs, &now); dev_io_playback_fetch(*odevs); dev_io_capture(idevs); @@ -1118,6 +1271,17 @@ int dev_io_append_stream(struct open_dev **dev_list, continue; /* + * When dev transitions from no stream to the 1st stream, reset + * last_wake and longest_wake so it can start over the tracking. + */ + if (dev->streams == NULL) { + open_dev->last_wake.tv_sec = 0; + open_dev->last_wake.tv_nsec = 0; + open_dev->longest_wake.tv_sec = 0; + open_dev->longest_wake.tv_nsec = 0; + } + + /* * When the first input stream is added, flush the input buffer * so that we can read from multiple input devices of the same * buffer level. @@ -1176,6 +1340,11 @@ int dev_io_append_stream(struct open_dev **dev_list, * by hw_level of input device, set the first cb_ts to zero. The stream * will wake up when it gets enough samples to post. The next_cb_ts will * be updated after its first post. + * + * TODO(yuhsuan) - Align the new stream fetch time to avoid getting a large + * delay. If a new stream with smaller block size starts when the hardware + * level is high, the hardware level will keep high after removing other + * old streams. */ init_cb_ts.tv_sec = 0; init_cb_ts.tv_nsec = 0; diff --git a/cras/src/server/dev_io.h b/cras/src/server/dev_io.h index dd519f32..3184e4c8 100644 --- a/cras/src/server/dev_io.h +++ b/cras/src/server/dev_io.h @@ -16,6 +16,10 @@ /* * Open input/output devices. * dev - The device. + * last_wake - The last timestamp audio thread woke up and there is stream + * on this open device. + * longest_wake - The longest time between consecutive audio thread wakes + * in this open_dev's life cycle. * wake_ts - When callback is needed to avoid xrun. * last_non_empty_ts - The last time we know the device played/captured * non-empty (zero) audio. @@ -23,6 +27,8 @@ */ struct open_dev { struct cras_iodev *dev; + struct timespec last_wake; + struct timespec longest_wake; struct timespec wake_ts; struct polled_interval *non_empty_check_pi; struct polled_interval *empty_pi; diff --git a/cras/src/server/server_stream.c b/cras/src/server/server_stream.c index 639f9487..cc16cd8c 100644 --- a/cras/src/server/server_stream.c +++ b/cras/src/server/server_stream.c @@ -47,6 +47,9 @@ static void server_stream_add_cb(void *data) void server_stream_create(struct stream_list *stream_list, unsigned int dev_idx) { + int audio_fd = -1; + int client_shm_fd = -1; + if (stream_config) { syslog(LOG_ERR, "server stream already exists, dev %u", stream_config->dev_idx); @@ -55,16 +58,14 @@ void server_stream_create(struct stream_list *stream_list, unsigned int dev_idx) stream_config = (struct cras_rstream_config *)calloc(1, sizeof(*stream_config)); - stream_config->format = &format; - stream_config->stream_id = - cras_get_stream_id(SERVER_STREAM_CLIENT_ID, 0); - stream_config->stream_type = CRAS_STREAM_TYPE_DEFAULT; - stream_config->direction = CRAS_STREAM_INPUT; - stream_config->flags = SERVER_ONLY; - stream_config->buffer_frames = server_stream_block_size; - stream_config->cb_threshold = server_stream_block_size; - stream_config->dev_idx = dev_idx; - stream_config->audio_fd = -1; + cras_rstream_config_init( + /*client=*/NULL, cras_get_stream_id(SERVER_STREAM_CLIENT_ID, 0), + CRAS_STREAM_TYPE_DEFAULT, CRAS_CLIENT_TYPE_SERVER_STREAM, + CRAS_STREAM_INPUT, dev_idx, + /*flags=*/SERVER_ONLY, + /*effects=*/0, &format, server_stream_block_size, + server_stream_block_size, &audio_fd, &client_shm_fd, + /*client_shm_size=*/0, stream_config); /* Schedule add stream in next main thread loop. */ cras_system_add_task(server_stream_add_cb, stream_list); diff --git a/cras/src/server/stream_list.h b/cras/src/server/stream_list.h index 858fbe3f..ae77a333 100644 --- a/cras/src/server/stream_list.h +++ b/cras/src/server/stream_list.h @@ -15,6 +15,7 @@ struct cras_audio_format; struct stream_list; typedef int(stream_callback)(struct cras_rstream *rstream); +/* This function will mutably borrow stream_config. */ typedef int(stream_create_func)(struct cras_rstream_config *stream_config, struct cras_rstream **rstream); typedef void(stream_destroy_func)(struct cras_rstream *rstream); @@ -29,6 +30,17 @@ void stream_list_destroy(struct stream_list *list); struct cras_rstream *stream_list_get(struct stream_list *list); +/* Creates a cras_rstream from cras_rstreaem_config and adds the cras_rstream + * to stream_list. + * + * Args: + * list - stream_list to add streams. + * stream_config - A mutable borrow of cras_rstream_config. + * stream - A pointer to place created cras_rstream. + * + * Returns: + * 0 on success. Negative error code on failure. + */ int stream_list_add(struct stream_list *list, struct cras_rstream_config *stream_config, struct cras_rstream **stream); diff --git a/cras/src/tests/a2dp_info_unittest.cc b/cras/src/tests/a2dp_info_unittest.cc index 3c70f871..4858c460 100644 --- a/cras/src/tests/a2dp_info_unittest.cc +++ b/cras/src/tests/a2dp_info_unittest.cc @@ -2,54 +2,28 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <gtest/gtest.h> #include <stdint.h> #include <stdio.h> #include <sys/socket.h> #include <unistd.h> -#include <gtest/gtest.h> extern "C" { - #include <sbc/sbc.h> +#include <sbc/sbc.h> - #include "cras_sbc_codec.h" - #include "cras_a2dp_info.h" +#include "cras_a2dp_info.h" +#include "cras_sbc_codec.h" +#include "sbc_codec_stub.h" } -static size_t cras_sbc_codec_create_called; -static size_t cras_sbc_codec_destroy_called; -static uint8_t codec_create_freq_val; -static uint8_t codec_create_mode_val; -static uint8_t codec_create_subbands_val; -static uint8_t codec_create_alloc_val; -static uint8_t codec_create_blocks_val; -static uint8_t codec_create_bitpool_val; -static int cras_sbc_get_frame_length_val; -static int cras_sbc_get_codesize_val; static size_t a2dp_write_link_mtu_val; -static size_t encode_out_encoded_return_val; -static struct cras_audio_codec *sbc_codec; -static int cras_sbc_codec_create_fail; static struct a2dp_info a2dp; static a2dp_sbc_t sbc; void ResetStubData() { - cras_sbc_codec_create_called = 0; - cras_sbc_codec_destroy_called = 0; - - codec_create_freq_val = 0; - codec_create_mode_val = 0; - codec_create_subbands_val = 0; - codec_create_alloc_val = 0; - codec_create_blocks_val = 0; - codec_create_bitpool_val = 0; - - cras_sbc_get_frame_length_val = 5; - cras_sbc_get_codesize_val = 5; - sbc_codec = NULL; - cras_sbc_codec_create_fail = 0; + sbc_codec_stub_reset(); a2dp_write_link_mtu_val = 40; - encode_out_encoded_return_val = 0; sbc.frequency = SBC_SAMPLING_FREQ_48000; sbc.channel_mode = SBC_CHANNEL_MODE_JOINT_STEREO; @@ -70,15 +44,15 @@ TEST(A2dpInfoInit, InitA2dp) { ResetStubData(); init_a2dp(&a2dp, &sbc); - ASSERT_EQ(1, cras_sbc_codec_create_called); - ASSERT_EQ(SBC_FREQ_48000, codec_create_freq_val); - ASSERT_EQ(SBC_MODE_JOINT_STEREO, codec_create_mode_val); - ASSERT_EQ(SBC_AM_LOUDNESS, codec_create_alloc_val); - ASSERT_EQ(SBC_SB_8, codec_create_subbands_val); - ASSERT_EQ(SBC_BLK_16, codec_create_blocks_val); - ASSERT_EQ(50, codec_create_bitpool_val); + ASSERT_EQ(1, get_sbc_codec_create_called()); + ASSERT_EQ(SBC_FREQ_48000, get_sbc_codec_create_freq_val()); + ASSERT_EQ(SBC_MODE_JOINT_STEREO, get_sbc_codec_create_mode_val()); + ASSERT_EQ(SBC_AM_LOUDNESS, get_sbc_codec_create_alloc_val()); + ASSERT_EQ(SBC_SB_8, get_sbc_codec_create_subbands_val()); + ASSERT_EQ(SBC_BLK_16, get_sbc_codec_create_blocks_val()); + ASSERT_EQ(50, get_sbc_codec_create_bitpool_val()); - ASSERT_NE(a2dp.codec, (void *)NULL); + ASSERT_NE(a2dp.codec, (void*)NULL); ASSERT_EQ(a2dp.a2dp_buf_used, 13); ASSERT_EQ(a2dp.frame_count, 0); ASSERT_EQ(a2dp.seq_num, 0); @@ -90,12 +64,12 @@ TEST(A2dpInfoInit, InitA2dp) { TEST(A2dpInfoInit, InitA2dpFail) { ResetStubData(); int err; - cras_sbc_codec_create_fail = 1; + set_sbc_codec_create_fail(1); err = init_a2dp(&a2dp, &sbc); - ASSERT_EQ(1, cras_sbc_codec_create_called); + ASSERT_EQ(1, get_sbc_codec_create_called()); ASSERT_NE(0, err); - ASSERT_EQ(a2dp.codec, (void *)NULL); + ASSERT_EQ(a2dp.codec, (void*)NULL); } TEST(A2dpInfoInit, DestroyA2dp) { @@ -103,7 +77,7 @@ TEST(A2dpInfoInit, DestroyA2dp) { init_a2dp(&a2dp, &sbc); destroy_a2dp(&a2dp); - ASSERT_EQ(1, cras_sbc_codec_destroy_called); + ASSERT_EQ(1, get_sbc_codec_destroy_called()); } TEST(A2dpInfoInit, DrainA2dp) { @@ -130,7 +104,7 @@ TEST(A2dpEncode, WriteA2dp) { ResetStubData(); init_a2dp(&a2dp, &sbc); - encode_out_encoded_return_val = 4; + set_sbc_codec_encoded_out(4); processed = a2dp_encode(&a2dp, NULL, 20, 4, (size_t)40); ASSERT_EQ(20, processed); @@ -142,7 +116,7 @@ TEST(A2dpEncode, WriteA2dp) { ASSERT_EQ(5, a2dp.nsamples); ASSERT_EQ(0, a2dp.seq_num); - encode_out_encoded_return_val = 15; + set_sbc_codec_encoded_out(15); processed = a2dp_encode(&a2dp, NULL, 20, 4, (size_t)40); ASSERT_EQ(32, a2dp.a2dp_buf_used); @@ -151,61 +125,9 @@ TEST(A2dpEncode, WriteA2dp) { ASSERT_EQ(0, a2dp.seq_num); } -} // namespace +} // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } - -int decode(struct cras_audio_codec *codec, const void *input, - size_t input_len, void *output, size_t output_len, - size_t *count) -{ - return input_len; -} - -int encode(struct cras_audio_codec *codec, const void *input, - size_t input_len, void *output, size_t output_len, - size_t *count) -{ - // Written half the output buffer. - *count = encode_out_encoded_return_val; - return input_len; -} - -struct cras_audio_codec *cras_sbc_codec_create(uint8_t freq, - uint8_t mode, uint8_t subbands, uint8_t alloc, - uint8_t blocks, uint8_t bitpool) -{ - if (!cras_sbc_codec_create_fail) { - sbc_codec = (struct cras_audio_codec *)calloc(1, sizeof(*sbc_codec)); - sbc_codec->decode = decode; - sbc_codec->encode = encode; - } - - cras_sbc_codec_create_called++; - codec_create_freq_val = freq; - codec_create_mode_val = mode; - codec_create_subbands_val = subbands; - codec_create_alloc_val = alloc; - codec_create_blocks_val = blocks; - codec_create_bitpool_val = bitpool; - return sbc_codec; -} - -void cras_sbc_codec_destroy(struct cras_audio_codec *codec) -{ - cras_sbc_codec_destroy_called++; - free(codec); -} - -int cras_sbc_get_codesize(struct cras_audio_codec *codec) -{ - return cras_sbc_get_codesize_val; -} - -int cras_sbc_get_frame_length(struct cras_audio_codec *codec) -{ - return cras_sbc_get_frame_length_val; -} diff --git a/cras/src/tests/a2dp_iodev_unittest.cc b/cras/src/tests/a2dp_iodev_unittest.cc index b8f60504..c85b9d67 100644 --- a/cras/src/tests/a2dp_iodev_unittest.cc +++ b/cras/src/tests/a2dp_iodev_unittest.cc @@ -2,20 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <stdio.h> -#include <stdint.h> #include <gtest/gtest.h> +#include <stdint.h> +#include <stdio.h> extern "C" { #include "a2dp-codecs.h" -#include "cras_audio_area.h" #include "audio_thread.h" #include "audio_thread_log.h" +#include "cras_a2dp_iodev.h" +#include "cras_audio_area.h" #include "cras_bt_transport.h" #include "cras_iodev.h" - -#include "cras_a2dp_iodev.h" } #define FAKE_OBJECT_PATH "/fake/obj/path" @@ -23,11 +22,12 @@ extern "C" { #define MAX_A2DP_ENCODE_CALLS 8 #define MAX_A2DP_WRITE_CALLS 4 -static struct cras_bt_transport *fake_transport; +static struct cras_bt_transport* fake_transport; static cras_audio_format format; static size_t cras_bt_device_append_iodev_called; static size_t cras_bt_device_rm_iodev_called; static size_t cras_iodev_add_node_called; +static int cras_iodev_frames_queued_called; static size_t cras_iodev_rm_node_called; static size_t cras_iodev_set_active_node_called; static size_t cras_bt_transport_acquire_called; @@ -46,17 +46,18 @@ static unsigned int a2dp_encode_processed_bytes_val[MAX_A2DP_ENCODE_CALLS]; static unsigned int a2dp_encode_index; static int a2dp_write_return_val[MAX_A2DP_WRITE_CALLS]; static unsigned int a2dp_write_index; -static cras_audio_area *dummy_audio_area; +static cras_audio_area* dummy_audio_area; static thread_callback write_callback; -static void *write_callback_data; -static const char *fake_device_name = "fake device name"; -static const char *cras_bt_device_name_ret; +static void* write_callback_data; +static const char* fake_device_name = "fake device name"; +static const char* cras_bt_device_name_ret; static unsigned int cras_bt_transport_write_mtu_ret; void ResetStubData() { cras_bt_device_append_iodev_called = 0; cras_bt_device_rm_iodev_called = 0; cras_iodev_add_node_called = 0; + cras_iodev_frames_queued_called = 0; cras_iodev_rm_node_called = 0; cras_iodev_set_active_node_called = 0; cras_bt_transport_acquire_called = 0; @@ -76,19 +77,17 @@ void ResetStubData() { a2dp_write_index = 0; cras_bt_transport_write_mtu_ret = 800; - fake_transport = reinterpret_cast<struct cras_bt_transport *>(0x123); + fake_transport = reinterpret_cast<struct cras_bt_transport*>(0x123); if (!dummy_audio_area) { - dummy_audio_area = (cras_audio_area*)calloc(1, - sizeof(*dummy_audio_area) + sizeof(cras_channel_area) * 2); + dummy_audio_area = (cras_audio_area*)calloc( + 1, sizeof(*dummy_audio_area) + sizeof(cras_channel_area) * 2); } write_callback = NULL; } -int iodev_set_format(struct cras_iodev *iodev, - struct cras_audio_format *fmt) -{ +int iodev_set_format(struct cras_iodev* iodev, struct cras_audio_format* fmt) { fmt->format = SND_PCM_FORMAT_S16_LE; fmt->num_channels = 2; fmt->frame_rate = 44100; @@ -99,29 +98,27 @@ int iodev_set_format(struct cras_iodev *iodev, namespace { static struct timespec time_now; -class A2dpIodev: public testing::Test { - protected: - virtual void SetUp() { - ResetStubData(); - atlog = (audio_thread_event_log *)calloc( - 1, - sizeof(audio_thread_event_log)); - } - - virtual void TearDown() { - free(dummy_audio_area); - dummy_audio_area = NULL; - free(atlog); - } +class A2dpIodev : public testing::Test { + protected: + virtual void SetUp() { + ResetStubData(); + atlog = (audio_thread_event_log*)calloc(1, sizeof(audio_thread_event_log)); + } + + virtual void TearDown() { + free(dummy_audio_area); + dummy_audio_area = NULL; + free(atlog); + } }; TEST_F(A2dpIodev, InitializeA2dpIodev) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; cras_bt_device_name_ret = NULL; iodev = a2dp_iodev_create(fake_transport); - ASSERT_NE(iodev, (void *)NULL); + ASSERT_NE(iodev, (void*)NULL); ASSERT_EQ(iodev->direction, CRAS_STREAM_OUTPUT); ASSERT_EQ(1, cras_bt_transport_configuration_called); ASSERT_EQ(1, init_a2dp_called); @@ -149,12 +146,12 @@ TEST_F(A2dpIodev, InitializeA2dpIodev) { } TEST_F(A2dpIodev, InitializeFail) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; init_a2dp_return_val = -1; iodev = a2dp_iodev_create(fake_transport); - ASSERT_EQ(iodev, (void *)NULL); + ASSERT_EQ(iodev, (void*)NULL); ASSERT_EQ(1, cras_bt_transport_configuration_called); ASSERT_EQ(1, init_a2dp_called); ASSERT_EQ(0, cras_bt_device_append_iodev_called); @@ -164,7 +161,7 @@ TEST_F(A2dpIodev, InitializeFail) { } TEST_F(A2dpIodev, OpenIodev) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; iodev = a2dp_iodev_create(fake_transport); @@ -182,16 +179,16 @@ TEST_F(A2dpIodev, OpenIodev) { } TEST_F(A2dpIodev, GetPutBuffer) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; struct cras_audio_area *area1, *area2, *area3; - uint8_t *area1_buf; + uint8_t* area1_buf; unsigned frames; iodev = a2dp_iodev_create(fake_transport); iodev_set_format(iodev, &format); iodev->configure_dev(iodev); - ASSERT_NE(write_callback, (void *)NULL); + ASSERT_NE(write_callback, (void*)NULL); frames = 256; iodev->get_buffer(iodev, &area1, &frames); @@ -200,16 +197,13 @@ TEST_F(A2dpIodev, GetPutBuffer) { area1_buf = area1->channels[0].buf; /* Test 100 frames(400 bytes) put and all processed. */ - a2dp_encode_processed_bytes_val[0] = 4096 * 4; - a2dp_encode_processed_bytes_val[1] = 400; + a2dp_encode_processed_bytes_val[0] = 400; a2dp_write_index = 0; - a2dp_write_return_val[0] = -EAGAIN; - a2dp_write_return_val[1] = 400; + a2dp_write_return_val[0] = 400; iodev->put_buffer(iodev, 100); write_callback(write_callback_data); // Start with 4k frames. - EXPECT_EQ(4096, pcm_buf_size_val[0]); - EXPECT_EQ(400, pcm_buf_size_val[1]); + EXPECT_EQ(400, pcm_buf_size_val[0]); iodev->get_buffer(iodev, &area2, &frames); ASSERT_EQ(256, frames); @@ -245,8 +239,8 @@ TEST_F(A2dpIodev, GetPutBuffer) { } TEST_F(A2dpIodev, FramesQueued) { - struct cras_iodev *iodev; - struct cras_audio_area *area; + struct cras_iodev* iodev; + struct cras_audio_area* area; struct timespec tstamp; unsigned frames; @@ -256,7 +250,7 @@ TEST_F(A2dpIodev, FramesQueued) { time_now.tv_sec = 0; time_now.tv_nsec = 0; iodev->configure_dev(iodev); - ASSERT_NE(write_callback, (void *)NULL); + ASSERT_NE(write_callback, (void*)NULL); frames = 256; iodev->get_buffer(iodev, &area, &frames); @@ -267,15 +261,13 @@ TEST_F(A2dpIodev, FramesQueued) { * Assume 200 bytes written out, queued 50 frames in a2dp buffer. */ a2dp_encode_processed_bytes_val[0] = 400; - a2dp_encode_processed_bytes_val[1] = 0; - a2dp_write_return_val[0] = 200; - a2dp_write_return_val[1] = -EAGAIN; + a2dp_write_return_val[0] = 50; a2dp_queued_frames_val = 50; time_now.tv_sec = 0; time_now.tv_nsec = 1000000; - iodev->put_buffer(iodev, 300); + iodev->put_buffer(iodev, 200); write_callback(write_callback_data); - EXPECT_EQ(350, iodev->frames_queued(iodev, &tstamp)); + EXPECT_EQ(200, iodev->frames_queued(iodev, &tstamp)); EXPECT_EQ(tstamp.tv_sec, time_now.tv_sec); EXPECT_EQ(tstamp.tv_nsec, time_now.tv_nsec); @@ -284,12 +276,11 @@ TEST_F(A2dpIodev, FramesQueued) { time_now.tv_nsec = 2000000; a2dp_encode_index = 0; a2dp_write_index = 0; - a2dp_encode_processed_bytes_val[0] = 800; + a2dp_encode_processed_bytes_val[0] = 400; write_callback(write_callback_data); /* 1000000 nsec has passed, estimated queued frames adjusted by 44 */ - EXPECT_EQ(256, iodev->frames_queued(iodev, &tstamp)); - EXPECT_EQ(1200, pcm_buf_size_val[0]); - EXPECT_EQ(400, pcm_buf_size_val[1]); + EXPECT_EQ(156, iodev->frames_queued(iodev, &tstamp)); + EXPECT_EQ(400, pcm_buf_size_val[0]); EXPECT_EQ(tstamp.tv_sec, time_now.tv_sec); EXPECT_EQ(tstamp.tv_nsec, time_now.tv_nsec); @@ -305,9 +296,10 @@ TEST_F(A2dpIodev, FramesQueued) { time_now.tv_sec = 0; time_now.tv_nsec = 50000000; a2dp_encode_processed_bytes_val[0] = 600; + a2dp_queued_frames_val = 50; iodev->put_buffer(iodev, 200); - EXPECT_EQ(1200, pcm_buf_size_val[0]); - EXPECT_EQ(200, iodev->frames_queued(iodev, &tstamp)); + EXPECT_EQ(800, pcm_buf_size_val[0]); + EXPECT_EQ(100, iodev->frames_queued(iodev, &tstamp)); EXPECT_EQ(tstamp.tv_sec, time_now.tv_sec); EXPECT_EQ(tstamp.tv_nsec, time_now.tv_nsec); iodev->close_dev(iodev); @@ -315,8 +307,8 @@ TEST_F(A2dpIodev, FramesQueued) { } TEST_F(A2dpIodev, FlushAtLowBufferLevel) { - struct cras_iodev *iodev; - struct cras_audio_area *area; + struct cras_iodev* iodev; + struct cras_audio_area* area; struct timespec tstamp; unsigned frames; @@ -326,7 +318,7 @@ TEST_F(A2dpIodev, FlushAtLowBufferLevel) { time_now.tv_sec = 0; time_now.tv_nsec = 0; iodev->configure_dev(iodev); - ASSERT_NE(write_callback, (void *)NULL); + ASSERT_NE(write_callback, (void*)NULL); ASSERT_EQ(iodev->min_buffer_level, 400); @@ -335,22 +327,18 @@ TEST_F(A2dpIodev, FlushAtLowBufferLevel) { ASSERT_EQ(700, frames); ASSERT_EQ(700, area->frames); - /* Fake 111 frames in pre-fill*/ - a2dp_encode_processed_bytes_val[0] = 111; - a2dp_write_return_val[0] = -EAGAIN; - /* First call to a2dp_encode() processed 800 bytes. */ - a2dp_encode_processed_bytes_val[1] = 800; - a2dp_encode_processed_bytes_val[2] = 0; - a2dp_write_return_val[1] = 200; + a2dp_encode_processed_bytes_val[0] = 800; + a2dp_encode_processed_bytes_val[1] = 0; + a2dp_write_return_val[0] = 200; /* put_buffer shouldn't trigger the 2nd call to a2dp_encode() because * buffer is low. Fake some data to make sure this test case will fail * when a2dp_encode() called twice. */ - a2dp_encode_processed_bytes_val[3] = 800; - a2dp_encode_processed_bytes_val[4] = 0; - a2dp_write_return_val[2] = -EAGAIN; + a2dp_encode_processed_bytes_val[2] = 800; + a2dp_encode_processed_bytes_val[3] = 0; + a2dp_write_return_val[1] = -EAGAIN; time_now.tv_nsec = 10000000; iodev->put_buffer(iodev, 700); @@ -364,8 +352,8 @@ TEST_F(A2dpIodev, FlushAtLowBufferLevel) { } TEST_F(A2dpIodev, NoStreamState) { - struct cras_iodev *iodev; - struct cras_audio_area *area; + struct cras_iodev* iodev; + struct cras_audio_area* area; struct timespec tstamp; unsigned frames; @@ -374,195 +362,179 @@ TEST_F(A2dpIodev, NoStreamState) { time_now.tv_sec = 0; time_now.tv_nsec = 0; iodev->configure_dev(iodev); - ASSERT_NE(write_callback, (void *)NULL); + ASSERT_NE(write_callback, (void*)NULL); + ASSERT_EQ(400, iodev->min_buffer_level); - iodev->min_cb_level = 888; - frames = 700; + iodev->min_cb_level = 480; + frames = 200; iodev->get_buffer(iodev, &area, &frames); - iodev->put_buffer(iodev, 700); + iodev->put_buffer(iodev, 200); iodev->no_stream(iodev, 1); + EXPECT_EQ(1, cras_iodev_frames_queued_called); - /* Full buffer will be filled by zero in no stream state .*/ + /* no_stream will fill the buffer to hw_level = (441 (44100 * 0.01)) * 2 + * frames, but 200 < min_buffer_level so cras_iodev_frames_queued will return + * 0 in no_stream and no_stream will fill 882 frames to device buffer. + */ frames = iodev->frames_queued(iodev, &tstamp); - ASSERT_EQ(iodev->buffer_size, frames); + ASSERT_EQ(1082, frames); - /* After leaving no stream state, output buffer is adjusted to - * min_cb_level */ + /* After leaving no stream state, output buffer won't be adjusted */ iodev->no_stream(iodev, 0); frames = iodev->frames_queued(iodev, &tstamp); - ASSERT_EQ(888, frames); + ASSERT_EQ(1082, frames); } -} // namespace +} // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } extern "C" { -int cras_bt_transport_configuration(const struct cras_bt_transport *transport, - void *configuration, int len) -{ +int cras_bt_transport_configuration(const struct cras_bt_transport* transport, + void* configuration, + int len) { cras_bt_transport_configuration_called++; return 0; } -int cras_bt_transport_acquire(struct cras_bt_transport *transport) -{ +int cras_bt_transport_acquire(struct cras_bt_transport* transport) { cras_bt_transport_acquire_called++; return 0; } -int cras_bt_transport_release(struct cras_bt_transport *transport, - unsigned int blocking) -{ +int cras_bt_transport_release(struct cras_bt_transport* transport, + unsigned int blocking) { cras_bt_transport_release_called++; return 0; } -int cras_bt_transport_fd(const struct cras_bt_transport *transport) -{ +int cras_bt_transport_fd(const struct cras_bt_transport* transport) { return 0; } -const char *cras_bt_transport_object_path( - const struct cras_bt_transport *transport) -{ +const char* cras_bt_transport_object_path( + const struct cras_bt_transport* transport) { return FAKE_OBJECT_PATH; } -uint16_t cras_bt_transport_write_mtu(const struct cras_bt_transport *transport) -{ +uint16_t cras_bt_transport_write_mtu( + const struct cras_bt_transport* transport) { return cras_bt_transport_write_mtu_ret; } -int cras_bt_transport_set_volume(struct cras_bt_transport *transport, - uint16_t volume) -{ +int cras_bt_transport_set_volume(struct cras_bt_transport* transport, + uint16_t volume) { return 0; } -void cras_iodev_free_format(struct cras_iodev *iodev) -{ +void cras_iodev_free_format(struct cras_iodev* iodev) { cras_iodev_free_format_called++; } -void cras_iodev_free_resources(struct cras_iodev *iodev) -{ +void cras_iodev_free_resources(struct cras_iodev* iodev) { cras_iodev_free_resources_called++; } // Cras iodev -void cras_iodev_add_node(struct cras_iodev *iodev, struct cras_ionode *node) -{ +void cras_iodev_add_node(struct cras_iodev* iodev, struct cras_ionode* node) { cras_iodev_add_node_called++; iodev->nodes = node; } -void cras_iodev_rm_node(struct cras_iodev *iodev, struct cras_ionode *node) -{ +void cras_iodev_rm_node(struct cras_iodev* iodev, struct cras_ionode* node) { cras_iodev_rm_node_called++; iodev->nodes = NULL; } -void cras_iodev_set_active_node(struct cras_iodev *iodev, - struct cras_ionode *node) -{ +void cras_iodev_set_active_node(struct cras_iodev* iodev, + struct cras_ionode* node) { cras_iodev_set_active_node_called++; iodev->active_node = node; } // From cras_bt_transport -struct cras_bt_device *cras_bt_transport_device( - const struct cras_bt_transport *transport) -{ - return reinterpret_cast<struct cras_bt_device *>(0x456);; +struct cras_bt_device* cras_bt_transport_device( + const struct cras_bt_transport* transport) { + return reinterpret_cast<struct cras_bt_device*>(0x456); + ; } enum cras_bt_device_profile cras_bt_transport_profile( - const struct cras_bt_transport *transport) -{ + const struct cras_bt_transport* transport) { return CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE; } // From cras_bt_device -const char *cras_bt_device_name(const struct cras_bt_device *device) -{ +const char* cras_bt_device_name(const struct cras_bt_device* device) { return cras_bt_device_name_ret; } -const char *cras_bt_device_object_path(const struct cras_bt_device *device) { +const char* cras_bt_device_object_path(const struct cras_bt_device* device) { return "/org/bluez/hci0/dev_1A_2B_3C_4D_5E_6F"; } -void cras_bt_device_append_iodev(struct cras_bt_device *device, - struct cras_iodev *iodev, - enum cras_bt_device_profile profile) -{ +void cras_bt_device_append_iodev(struct cras_bt_device* device, + struct cras_iodev* iodev, + enum cras_bt_device_profile profile) { cras_bt_device_append_iodev_called++; } -void cras_bt_device_rm_iodev(struct cras_bt_device *device, - struct cras_iodev *iodev) -{ +void cras_bt_device_rm_iodev(struct cras_bt_device* device, + struct cras_iodev* iodev) { cras_bt_device_rm_iodev_called++; } -int cras_bt_device_get_use_hardware_volume(struct cras_bt_device *device) -{ +int cras_bt_device_get_use_hardware_volume(struct cras_bt_device* device) { return 0; } -int cras_bt_device_cancel_suspend(struct cras_bt_device *device) -{ +int cras_bt_device_cancel_suspend(struct cras_bt_device* device) { return 0; } -int cras_bt_device_schedule_suspend(struct cras_bt_device *device, - unsigned int msec) -{ +int cras_bt_device_schedule_suspend(struct cras_bt_device* device, + unsigned int msec) { return 0; } -int init_a2dp(struct a2dp_info *a2dp, a2dp_sbc_t *sbc) -{ +int init_a2dp(struct a2dp_info* a2dp, a2dp_sbc_t* sbc) { init_a2dp_called++; return init_a2dp_return_val; } -void destroy_a2dp(struct a2dp_info *a2dp) -{ +void destroy_a2dp(struct a2dp_info* a2dp) { destroy_a2dp_called++; } -int a2dp_codesize(struct a2dp_info *a2dp) -{ +int a2dp_codesize(struct a2dp_info* a2dp) { return 512; } -int a2dp_block_size(struct a2dp_info *a2dp, int encoded_bytes) -{ +int a2dp_block_size(struct a2dp_info* a2dp, int encoded_bytes) { a2dp_block_size_called++; // Assumes a2dp block size is 1:1 before/after encode. return encoded_bytes; } -int a2dp_queued_frames(struct a2dp_info *a2dp) -{ +int a2dp_queued_frames(struct a2dp_info* a2dp) { return a2dp_queued_frames_val; } -void a2dp_drain(struct a2dp_info *a2dp) -{ +void a2dp_drain(struct a2dp_info* a2dp) { drain_a2dp_called++; } -int a2dp_encode(struct a2dp_info *a2dp, const void *pcm_buf, int pcm_buf_size, - int format_bytes, size_t link_mtu) { +int a2dp_encode(struct a2dp_info* a2dp, + const void* pcm_buf, + int pcm_buf_size, + int format_bytes, + size_t link_mtu) { unsigned int processed; if (a2dp_encode_index == MAX_A2DP_ENCODE_CALLS) @@ -573,47 +545,56 @@ int a2dp_encode(struct a2dp_info *a2dp, const void *pcm_buf, int pcm_buf_size, return processed; } -int a2dp_write(struct a2dp_info *a2dp, int stream_fd, size_t link_mtu) { - return a2dp_write_return_val[a2dp_write_index++];; +int a2dp_write(struct a2dp_info* a2dp, int stream_fd, size_t link_mtu) { + return a2dp_write_return_val[a2dp_write_index++]; + ; } -int clock_gettime(clockid_t clk_id, struct timespec *tp) { +int clock_gettime(clockid_t clk_id, struct timespec* tp) { *tp = time_now; return 0; } -void cras_iodev_init_audio_area(struct cras_iodev *iodev, - int num_channels) { +void cras_iodev_init_audio_area(struct cras_iodev* iodev, int num_channels) { iodev->area = dummy_audio_area; } -void cras_iodev_free_audio_area(struct cras_iodev *iodev) { +void cras_iodev_free_audio_area(struct cras_iodev* iodev) {} + +int cras_iodev_frames_queued(struct cras_iodev* iodev, + struct timespec* hw_tstamp) { + int rc; + cras_iodev_frames_queued_called++; + rc = iodev->frames_queued(iodev, hw_tstamp); + if (rc < 0) + return 0; + unsigned int num_queued = (unsigned int)rc; + if (num_queued < iodev->min_buffer_level) + return 0; + + return num_queued - iodev->min_buffer_level; } -void cras_audio_area_config_buf_pointers(struct cras_audio_area *area, - const struct cras_audio_format *fmt, - uint8_t *base_buffer) -{ +void cras_audio_area_config_buf_pointers(struct cras_audio_area* area, + const struct cras_audio_format* fmt, + uint8_t* base_buffer) { dummy_audio_area->channels[0].buf = base_buffer; } -struct audio_thread *cras_iodev_list_get_audio_thread() -{ +struct audio_thread* cras_iodev_list_get_audio_thread() { return NULL; } // From audio_thread -struct audio_thread_event_log *atlog; +struct audio_thread_event_log* atlog; -void audio_thread_add_write_callback(int fd, thread_callback cb, void *data) { +void audio_thread_add_write_callback(int fd, thread_callback cb, void* data) { write_callback = cb; write_callback_data = data; } -int audio_thread_rm_callback_sync(struct audio_thread *thread, int fd) { +int audio_thread_rm_callback_sync(struct audio_thread* thread, int fd) { return 0; } -void audio_thread_enable_callback(int fd, int enabled) { -} - +void audio_thread_enable_callback(int fd, int enabled) {} } diff --git a/cras/src/tests/alert_unittest.cc b/cras/src/tests/alert_unittest.cc index 5f547f54..ec1efcc4 100644 --- a/cras/src/tests/alert_unittest.cc +++ b/cras/src/tests/alert_unittest.cc @@ -3,17 +3,17 @@ // found in the LICENSE file. #include <gtest/gtest.h> -#include <sys/types.h> #include <sys/socket.h> +#include <sys/types.h> #include <unistd.h> #include "cras_alert.h" namespace { -void callback1(void *arg, void *data); -void callback2(void *arg, void *data); -void prepare(struct cras_alert *alert); +void callback1(void* arg, void* data); +void callback2(void* arg, void* data); +void prepare(struct cras_alert* alert); struct cb_data_struct { int data; @@ -33,18 +33,15 @@ void ResetStub() { cb1_data.data = 0; } -class Alert: public testing::Test { - protected: - virtual void SetUp() { - cb1_data.data = 0; - } +class Alert : public testing::Test { + protected: + virtual void SetUp() { cb1_data.data = 0; } - virtual void TearDown() { - } + virtual void TearDown() {} }; TEST_F(Alert, OneCallback) { - struct cras_alert *alert = cras_alert_create(NULL, 0); + struct cras_alert* alert = cras_alert_create(NULL, 0); cras_alert_add_callback(alert, &callback1, NULL); ResetStub(); cras_alert_pending(alert); @@ -55,7 +52,7 @@ TEST_F(Alert, OneCallback) { } TEST_F(Alert, OneCallbackPost2Call1) { - struct cras_alert *alert = cras_alert_create(NULL, 0); + struct cras_alert* alert = cras_alert_create(NULL, 0); cras_alert_add_callback(alert, &callback1, NULL); ResetStub(); // Alert twice, callback should only be called once. @@ -68,11 +65,11 @@ TEST_F(Alert, OneCallbackPost2Call1) { } TEST_F(Alert, OneCallbackWithData) { - struct cras_alert *alert = cras_alert_create(NULL, 0); + struct cras_alert* alert = cras_alert_create(NULL, 0); struct cb_data_struct data = {1}; cras_alert_add_callback(alert, &callback1, NULL); ResetStub(); - cras_alert_pending_data(alert, (void *)&data, sizeof(struct cb_data_struct)); + cras_alert_pending_data(alert, (void*)&data, sizeof(struct cb_data_struct)); EXPECT_EQ(0, cb1_called); cras_alert_process_all_pending_alerts(); EXPECT_EQ(1, cb1_called); @@ -81,16 +78,14 @@ TEST_F(Alert, OneCallbackWithData) { } TEST_F(Alert, OneCallbackTwoDataCalledOnce) { - struct cras_alert *alert = cras_alert_create(NULL, 0); + struct cras_alert* alert = cras_alert_create(NULL, 0); struct cb_data_struct data = {1}; struct cb_data_struct data2 = {2}; cras_alert_add_callback(alert, &callback1, NULL); ResetStub(); // Callback called with last data only. - cras_alert_pending_data( - alert, (void *)&data, sizeof(struct cb_data_struct)); - cras_alert_pending_data( - alert, (void *)&data2, sizeof(struct cb_data_struct)); + cras_alert_pending_data(alert, (void*)&data, sizeof(struct cb_data_struct)); + cras_alert_pending_data(alert, (void*)&data2, sizeof(struct cb_data_struct)); EXPECT_EQ(0, cb1_called); cras_alert_process_all_pending_alerts(); EXPECT_EQ(1, cb1_called); @@ -99,15 +94,15 @@ TEST_F(Alert, OneCallbackTwoDataCalledOnce) { } TEST_F(Alert, OneCallbackTwoDataKeepAll) { - struct cras_alert *alert = cras_alert_create( - NULL, CRAS_ALERT_FLAG_KEEP_ALL_DATA); + struct cras_alert* alert = + cras_alert_create(NULL, CRAS_ALERT_FLAG_KEEP_ALL_DATA); struct cb_data_struct data = {1}; struct cb_data_struct data2 = {2}; cras_alert_add_callback(alert, &callback1, NULL); ResetStub(); // Callbacks with data should each be called. - cras_alert_pending_data(alert, (void *)&data, sizeof(cb_data_struct)); - cras_alert_pending_data(alert, (void *)&data2, sizeof(cb_data_struct)); + cras_alert_pending_data(alert, (void*)&data, sizeof(cb_data_struct)); + cras_alert_pending_data(alert, (void*)&data2, sizeof(cb_data_struct)); EXPECT_EQ(0, cb1_called); cras_alert_process_all_pending_alerts(); EXPECT_EQ(2, cb1_called); @@ -116,7 +111,7 @@ TEST_F(Alert, OneCallbackTwoDataKeepAll) { } TEST_F(Alert, TwoCallbacks) { - struct cras_alert *alert = cras_alert_create(NULL, 0); + struct cras_alert* alert = cras_alert_create(NULL, 0); cras_alert_add_callback(alert, &callback1, NULL); cras_alert_add_callback(alert, &callback2, NULL); ResetStub(); @@ -130,7 +125,7 @@ TEST_F(Alert, TwoCallbacks) { } TEST_F(Alert, NoPending) { - struct cras_alert *alert = cras_alert_create(NULL, 0); + struct cras_alert* alert = cras_alert_create(NULL, 0); cras_alert_add_callback(alert, &callback1, NULL); ResetStub(); EXPECT_EQ(0, cb1_called); @@ -140,8 +135,8 @@ TEST_F(Alert, NoPending) { } TEST_F(Alert, PendingInCallback) { - struct cras_alert *alert1 = cras_alert_create(NULL, 0); - struct cras_alert *alert2 = cras_alert_create(NULL, 0); + struct cras_alert* alert1 = cras_alert_create(NULL, 0); + struct cras_alert* alert2 = cras_alert_create(NULL, 0); cras_alert_add_callback(alert1, &callback1, NULL); cras_alert_add_callback(alert2, &callback2, alert1); ResetStub(); @@ -157,7 +152,7 @@ TEST_F(Alert, PendingInCallback) { } TEST_F(Alert, Prepare) { - struct cras_alert *alert = cras_alert_create(prepare, 0); + struct cras_alert* alert = cras_alert_create(prepare, 0); cras_alert_add_callback(alert, &callback1, NULL); ResetStub(); cras_alert_pending(alert); @@ -169,8 +164,8 @@ TEST_F(Alert, Prepare) { } TEST_F(Alert, TwoAlerts) { - struct cras_alert *alert1 = cras_alert_create(prepare, 0); - struct cras_alert *alert2 = cras_alert_create(prepare, 0); + struct cras_alert* alert1 = cras_alert_create(prepare, 0); + struct cras_alert* alert2 = cras_alert_create(prepare, 0); cras_alert_add_callback(alert1, &callback1, NULL); cras_alert_add_callback(alert2, &callback2, NULL); @@ -205,31 +200,28 @@ TEST_F(Alert, TwoAlerts) { cras_alert_destroy_all(); } -void callback1(void *arg, void *data) -{ +void callback1(void* arg, void* data) { cb1_called++; - if(data) - cb1_data.data = ((struct cb_data_struct *)data)->data; + if (data) + cb1_data.data = ((struct cb_data_struct*)data)->data; } -void callback2(void *arg, void *data) -{ +void callback2(void* arg, void* data) { cb2_called++; if (cb2_set_pending) { cb2_set_pending = 0; - cras_alert_pending((struct cras_alert *)arg); + cras_alert_pending((struct cras_alert*)arg); } } -void prepare(struct cras_alert *alert) -{ +void prepare(struct cras_alert* alert) { prepare_called++; return; } -} +} // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/alsa_card_unittest.cc b/cras/src/tests/alsa_card_unittest.cc index b2dce1f9..dd75b1d9 100644 --- a/cras/src/tests/alsa_card_unittest.cc +++ b/cras/src/tests/alsa_card_unittest.cc @@ -4,10 +4,11 @@ #include <gtest/gtest.h> #include <iniparser.h> -#include <map> #include <stdio.h> -#include <syslog.h> #include <sys/param.h> +#include <syslog.h> + +#include <map> extern "C" { #include "cras_alsa_card.h" @@ -23,25 +24,25 @@ extern "C" { namespace { static size_t cras_alsa_mixer_create_called; -static struct cras_alsa_mixer *cras_alsa_mixer_create_return; +static struct cras_alsa_mixer* cras_alsa_mixer_create_return; static size_t cras_alsa_mixer_destroy_called; static size_t cras_alsa_iodev_create_called; -static struct cras_iodev **cras_alsa_iodev_create_return; +static struct cras_iodev** cras_alsa_iodev_create_return; static struct cras_iodev fake_dev1, fake_dev2, fake_dev3, fake_dev4; -static struct cras_iodev *cras_alsa_iodev_create_default_return[] = { - &fake_dev1, - &fake_dev2, - &fake_dev3, - &fake_dev4, +static struct cras_iodev* cras_alsa_iodev_create_default_return[] = { + &fake_dev1, + &fake_dev2, + &fake_dev3, + &fake_dev4, }; static size_t cras_alsa_iodev_create_return_size; static size_t cras_alsa_iodev_legacy_complete_init_called; static size_t cras_alsa_iodev_ucm_add_nodes_and_jacks_called; static size_t cras_alsa_iodev_ucm_complete_init_called; static size_t cras_alsa_iodev_destroy_called; -static struct cras_iodev *cras_alsa_iodev_destroy_arg; +static struct cras_iodev* cras_alsa_iodev_destroy_arg; static size_t cras_alsa_iodev_index_called; -static std::map<struct cras_iodev *, unsigned int> cras_alsa_iodev_index_return; +static std::map<struct cras_iodev*, unsigned int> cras_alsa_iodev_index_return; static int alsa_iodev_has_hctl_jacks_return; static size_t snd_ctl_open_called; static size_t snd_ctl_open_return; @@ -49,11 +50,11 @@ static size_t snd_ctl_close_called; static size_t snd_ctl_close_return; static size_t snd_ctl_pcm_next_device_called; static bool snd_ctl_pcm_next_device_return_error; -static int *snd_ctl_pcm_next_device_set_devs; +static int* snd_ctl_pcm_next_device_set_devs; static size_t snd_ctl_pcm_next_device_set_devs_size; static size_t snd_ctl_pcm_next_device_set_devs_index; static size_t snd_ctl_pcm_info_called; -static int *snd_ctl_pcm_info_rets; +static int* snd_ctl_pcm_info_rets; static size_t snd_ctl_pcm_info_rets_size; static size_t snd_ctl_pcm_info_rets_index; static size_t snd_ctl_card_info_called; @@ -62,10 +63,10 @@ static size_t snd_hctl_open_called; static int snd_hctl_open_return_value; static int snd_hctl_close_called; static size_t snd_hctl_nonblock_called; -static snd_hctl_t *snd_hctl_open_pointer_val; +static snd_hctl_t* snd_hctl_open_pointer_val; static size_t snd_hctl_load_called; static int snd_hctl_load_return_value; -static struct pollfd *snd_hctl_poll_descriptors_fds; +static struct pollfd* snd_hctl_poll_descriptors_fds; static size_t snd_hctl_poll_descriptors_num_fds; static size_t snd_hctl_poll_descriptors_called; static size_t cras_system_add_select_fd_called; @@ -75,31 +76,31 @@ static std::vector<int> cras_system_rm_select_fd_values; static size_t snd_hctl_handle_events_called; static size_t iniparser_freedict_called; static size_t iniparser_load_called; -static struct cras_device_blacklist *fake_blacklist; +static struct cras_device_blacklist* fake_blacklist; static int cras_device_blacklist_check_retval; static unsigned ucm_create_called; static unsigned ucm_destroy_called; static size_t ucm_get_dev_for_mixer_called; static size_t ucm_get_flag_called; -static char ucm_get_flag_name[64]; +static char ucm_get_flag_name[65]; static char* device_config_dir; static const char* cras_card_config_dir; -static struct mixer_name *ucm_get_coupled_mixer_names_return_value; -static struct mixer_name *coupled_output_names_value; +static struct mixer_name* ucm_get_coupled_mixer_names_return_value; +static struct mixer_name* coupled_output_names_value; static int ucm_has_fully_specified_ucm_flag_return_value; static int ucm_get_sections_called; -static struct mixer_name *ucm_get_main_volume_names_return_value; -static struct ucm_section *ucm_get_sections_return_value; +static struct mixer_name* ucm_get_main_volume_names_return_value; +static struct ucm_section* ucm_get_sections_return_value; static size_t cras_alsa_mixer_add_controls_in_section_called; static int cras_alsa_mixer_add_controls_in_section_return_value; static int cras_alsa_mixer_add_main_volume_control_by_name_called; static int cras_alsa_mixer_add_main_volume_control_by_name_return_value; static int ucm_get_echo_reference_dev_name_for_dev_called; -static const char *ucm_get_echo_reference_dev_name_for_dev_return_value[4]; +static const char* ucm_get_echo_reference_dev_name_for_dev_return_value[4]; static void ResetStubData() { cras_alsa_mixer_create_called = 0; - cras_alsa_mixer_create_return = reinterpret_cast<struct cras_alsa_mixer *>(1); + cras_alsa_mixer_create_return = reinterpret_cast<struct cras_alsa_mixer*>(1); cras_alsa_mixer_destroy_called = 0; cras_alsa_iodev_destroy_arg = NULL; cras_alsa_iodev_create_called = 0; @@ -128,7 +129,7 @@ static void ResetStubData() { snd_ctl_card_info_ret = 0; snd_hctl_open_called = 0; snd_hctl_open_return_value = 0; - snd_hctl_open_pointer_val = reinterpret_cast<snd_hctl_t *>(0x4323); + snd_hctl_open_pointer_val = reinterpret_cast<snd_hctl_t*>(0x4323); snd_hctl_load_called = 0; snd_hctl_load_return_value = 0; snd_hctl_close_called = 0; @@ -144,14 +145,14 @@ static void ResetStubData() { cras_system_rm_select_fd_values.clear(); iniparser_freedict_called = 0; iniparser_load_called = 0; - fake_blacklist = reinterpret_cast<struct cras_device_blacklist *>(3); + fake_blacklist = reinterpret_cast<struct cras_device_blacklist*>(3); cras_device_blacklist_check_retval = 0; ucm_create_called = 0; ucm_destroy_called = 0; ucm_get_dev_for_mixer_called = 0; ucm_get_flag_called = 0; memset(ucm_get_flag_name, 0, sizeof(ucm_get_flag_name)); - device_config_dir = reinterpret_cast<char *>(3); + device_config_dir = reinterpret_cast<char*>(3); cras_card_config_dir = NULL; ucm_get_coupled_mixer_names_return_value = NULL; ucm_get_main_volume_names_return_value = NULL; @@ -172,46 +173,46 @@ static void ResetStubData() { } TEST(AlsaCard, CreateFailInvalidCard) { - struct cras_alsa_card *c; + struct cras_alsa_card* c; cras_alsa_card_info card_info; ResetStubData(); card_info.card_type = ALSA_CARD_TYPE_INTERNAL; card_info.card_index = 55; - c = cras_alsa_card_create(&card_info, device_config_dir, - fake_blacklist, NULL); - EXPECT_EQ(static_cast<struct cras_alsa_card *>(NULL), c); + c = cras_alsa_card_create(&card_info, device_config_dir, fake_blacklist, + NULL); + EXPECT_EQ(static_cast<struct cras_alsa_card*>(NULL), c); EXPECT_EQ(snd_ctl_close_called, snd_ctl_open_called); EXPECT_EQ(cras_alsa_mixer_create_called, cras_alsa_mixer_destroy_called); } TEST(AlsaCard, CreateFailMixerInit) { - struct cras_alsa_card *c; + struct cras_alsa_card* c; cras_alsa_card_info card_info; ResetStubData(); card_info.card_type = ALSA_CARD_TYPE_INTERNAL; card_info.card_index = 0; - cras_alsa_mixer_create_return = static_cast<struct cras_alsa_mixer *>(NULL); - c = cras_alsa_card_create(&card_info, device_config_dir, - fake_blacklist, NULL); - EXPECT_EQ(static_cast<struct cras_alsa_card *>(NULL), c); + cras_alsa_mixer_create_return = static_cast<struct cras_alsa_mixer*>(NULL); + c = cras_alsa_card_create(&card_info, device_config_dir, fake_blacklist, + NULL); + EXPECT_EQ(static_cast<struct cras_alsa_card*>(NULL), c); EXPECT_EQ(snd_ctl_close_called, snd_ctl_open_called); EXPECT_EQ(1, cras_alsa_mixer_create_called); EXPECT_EQ(0, cras_alsa_mixer_destroy_called); } TEST(AlsaCard, CreateFailCtlOpen) { - struct cras_alsa_card *c; + struct cras_alsa_card* c; cras_alsa_card_info card_info; ResetStubData(); card_info.card_type = ALSA_CARD_TYPE_INTERNAL; card_info.card_index = 0; snd_ctl_open_return = -1; - c = cras_alsa_card_create(&card_info, device_config_dir, - fake_blacklist, NULL); - EXPECT_EQ(static_cast<struct cras_alsa_card *>(NULL), c); + c = cras_alsa_card_create(&card_info, device_config_dir, fake_blacklist, + NULL); + EXPECT_EQ(static_cast<struct cras_alsa_card*>(NULL), c); EXPECT_EQ(1, snd_ctl_open_called); EXPECT_EQ(0, snd_ctl_close_called); EXPECT_EQ(iniparser_load_called, iniparser_freedict_called); @@ -219,7 +220,7 @@ TEST(AlsaCard, CreateFailCtlOpen) { } TEST(AlsaCard, CreateFailHctlOpen) { - struct cras_alsa_card *c; + struct cras_alsa_card* c; cras_alsa_card_info card_info; ResetStubData(); @@ -228,9 +229,9 @@ TEST(AlsaCard, CreateFailHctlOpen) { snd_hctl_open_pointer_val = NULL; snd_hctl_open_return_value = -1; - c = cras_alsa_card_create(&card_info, device_config_dir, - fake_blacklist, NULL); - EXPECT_NE(static_cast<struct cras_alsa_card *>(NULL), c); + c = cras_alsa_card_create(&card_info, device_config_dir, fake_blacklist, + NULL); + EXPECT_NE(static_cast<struct cras_alsa_card*>(NULL), c); EXPECT_EQ(1, snd_ctl_open_called); EXPECT_EQ(1, snd_ctl_close_called); EXPECT_EQ(iniparser_load_called, iniparser_freedict_called); @@ -242,7 +243,7 @@ TEST(AlsaCard, CreateFailHctlOpen) { } TEST(AlsaCard, CreateFailHctlLoad) { - struct cras_alsa_card *c; + struct cras_alsa_card* c; cras_alsa_card_info card_info; ResetStubData(); @@ -250,9 +251,9 @@ TEST(AlsaCard, CreateFailHctlLoad) { card_info.card_index = 0; snd_hctl_load_return_value = -1; - c = cras_alsa_card_create(&card_info, device_config_dir, - fake_blacklist, NULL); - EXPECT_EQ(static_cast<struct cras_alsa_card *>(NULL), c); + c = cras_alsa_card_create(&card_info, device_config_dir, fake_blacklist, + NULL); + EXPECT_EQ(static_cast<struct cras_alsa_card*>(NULL), c); EXPECT_EQ(1, snd_ctl_open_called); EXPECT_EQ(1, snd_ctl_close_called); EXPECT_EQ(iniparser_load_called, iniparser_freedict_called); @@ -264,10 +265,10 @@ TEST(AlsaCard, CreateFailHctlLoad) { TEST(AlsaCard, AddSelectForHctlNoDevices) { struct pollfd poll_fds[] = { - {3, 0, 0}, + {3, 0, 0}, }; - struct cras_alsa_card *c; + struct cras_alsa_card* c; cras_alsa_card_info card_info; ResetStubData(); @@ -276,9 +277,9 @@ TEST(AlsaCard, AddSelectForHctlNoDevices) { snd_hctl_poll_descriptors_fds = poll_fds; snd_hctl_poll_descriptors_num_fds = ARRAY_SIZE(poll_fds); - c = cras_alsa_card_create(&card_info, device_config_dir, - fake_blacklist, NULL); - EXPECT_NE(static_cast<struct cras_alsa_card *>(NULL), c); + c = cras_alsa_card_create(&card_info, device_config_dir, fake_blacklist, + NULL); + EXPECT_NE(static_cast<struct cras_alsa_card*>(NULL), c); EXPECT_EQ(1, snd_ctl_open_called); EXPECT_EQ(1, snd_ctl_close_called); EXPECT_EQ(iniparser_load_called, iniparser_freedict_called); @@ -293,12 +294,12 @@ TEST(AlsaCard, AddSelectForHctlNoDevices) { TEST(AlsaCard, AddSelectForHctlWithDevices) { struct pollfd poll_fds[] = { - {3, 0, 0}, + {3, 0, 0}, }; int dev_nums[] = {0}; int info_rets[] = {0, -1}; - struct cras_alsa_card *c; + struct cras_alsa_card* c; cras_alsa_card_info card_info; ResetStubData(); @@ -311,9 +312,9 @@ TEST(AlsaCard, AddSelectForHctlWithDevices) { snd_hctl_poll_descriptors_fds = poll_fds; snd_hctl_poll_descriptors_num_fds = ARRAY_SIZE(poll_fds); - c = cras_alsa_card_create(&card_info, device_config_dir, - fake_blacklist, NULL); - EXPECT_NE(static_cast<struct cras_alsa_card *>(NULL), c); + c = cras_alsa_card_create(&card_info, device_config_dir, fake_blacklist, + NULL); + EXPECT_NE(static_cast<struct cras_alsa_card*>(NULL), c); EXPECT_EQ(snd_ctl_close_called, snd_ctl_open_called); EXPECT_EQ(2, snd_ctl_pcm_next_device_called); EXPECT_EQ(1, cras_alsa_iodev_create_called); @@ -336,16 +337,16 @@ TEST(AlsaCard, AddSelectForHctlWithDevices) { } TEST(AlsaCard, CreateFailCtlCardInfo) { - struct cras_alsa_card *c; + struct cras_alsa_card* c; cras_alsa_card_info card_info; ResetStubData(); card_info.card_type = ALSA_CARD_TYPE_INTERNAL; card_info.card_index = 0; snd_ctl_card_info_ret = -1; - c = cras_alsa_card_create(&card_info, device_config_dir, - fake_blacklist, NULL); - EXPECT_EQ(static_cast<struct cras_alsa_card *>(NULL), c); + c = cras_alsa_card_create(&card_info, device_config_dir, fake_blacklist, + NULL); + EXPECT_EQ(static_cast<struct cras_alsa_card*>(NULL), c); EXPECT_EQ(1, snd_ctl_open_called); EXPECT_EQ(1, snd_ctl_close_called); EXPECT_EQ(cras_alsa_mixer_create_called, cras_alsa_mixer_destroy_called); @@ -353,15 +354,15 @@ TEST(AlsaCard, CreateFailCtlCardInfo) { } TEST(AlsaCard, CreateNoDevices) { - struct cras_alsa_card *c; + struct cras_alsa_card* c; cras_alsa_card_info card_info; ResetStubData(); card_info.card_type = ALSA_CARD_TYPE_INTERNAL; card_info.card_index = 1; - c = cras_alsa_card_create(&card_info, device_config_dir, - fake_blacklist, NULL); - EXPECT_NE(static_cast<struct cras_alsa_card *>(NULL), c); + c = cras_alsa_card_create(&card_info, device_config_dir, fake_blacklist, + NULL); + EXPECT_NE(static_cast<struct cras_alsa_card*>(NULL), c); EXPECT_EQ(snd_ctl_close_called, snd_ctl_open_called); EXPECT_EQ(1, snd_ctl_pcm_next_device_called); EXPECT_EQ(0, cras_alsa_iodev_create_called); @@ -377,23 +378,23 @@ TEST(AlsaCard, CreateNoDevices) { } TEST(AlsaCard, CreateOneOutputNextDevError) { - struct cras_alsa_card *c; + struct cras_alsa_card* c; cras_alsa_card_info card_info; ResetStubData(); snd_ctl_pcm_next_device_return_error = true; card_info.card_type = ALSA_CARD_TYPE_USB; card_info.card_index = 0; - c = cras_alsa_card_create(&card_info, device_config_dir, - fake_blacklist, NULL); - EXPECT_EQ(static_cast<struct cras_alsa_card *>(NULL), c); + c = cras_alsa_card_create(&card_info, device_config_dir, fake_blacklist, + NULL); + EXPECT_EQ(static_cast<struct cras_alsa_card*>(NULL), c); EXPECT_EQ(cras_alsa_mixer_create_called, cras_alsa_mixer_destroy_called); EXPECT_EQ(snd_ctl_open_called, snd_ctl_close_called); EXPECT_EQ(iniparser_load_called, iniparser_freedict_called); } TEST(AlsaCard, CreateOneOutput) { - struct cras_alsa_card *c; + struct cras_alsa_card* c; int dev_nums[] = {0}; int info_rets[] = {0, -1}; cras_alsa_card_info card_info; @@ -405,9 +406,9 @@ TEST(AlsaCard, CreateOneOutput) { snd_ctl_pcm_info_rets = info_rets; card_info.card_type = ALSA_CARD_TYPE_USB; card_info.card_index = 0; - c = cras_alsa_card_create(&card_info, device_config_dir, - fake_blacklist, NULL); - EXPECT_NE(static_cast<struct cras_alsa_card *>(NULL), c); + c = cras_alsa_card_create(&card_info, device_config_dir, fake_blacklist, + NULL); + EXPECT_NE(static_cast<struct cras_alsa_card*>(NULL), c); EXPECT_EQ(snd_ctl_close_called, snd_ctl_open_called); EXPECT_EQ(2, snd_ctl_pcm_next_device_called); EXPECT_EQ(1, cras_alsa_iodev_create_called); @@ -431,7 +432,7 @@ TEST(AlsaCard, CreateOneOutput) { } TEST(AlsaCard, CreateOneOutputBlacklisted) { - struct cras_alsa_card *c; + struct cras_alsa_card* c; int dev_nums[] = {0}; int info_rets[] = {0, -1}; cras_alsa_card_info card_info; @@ -445,9 +446,9 @@ TEST(AlsaCard, CreateOneOutputBlacklisted) { cras_device_blacklist_check_retval = 1; card_info.card_type = ALSA_CARD_TYPE_USB; card_info.card_index = 0; - c = cras_alsa_card_create(&card_info, device_config_dir, - fake_blacklist, NULL); - EXPECT_NE(static_cast<struct cras_alsa_card *>(NULL), c); + c = cras_alsa_card_create(&card_info, device_config_dir, fake_blacklist, + NULL); + EXPECT_NE(static_cast<struct cras_alsa_card*>(NULL), c); EXPECT_EQ(snd_ctl_close_called, snd_ctl_open_called); EXPECT_EQ(2, snd_ctl_pcm_next_device_called); EXPECT_EQ(1, snd_ctl_card_info_called); @@ -463,7 +464,7 @@ TEST(AlsaCard, CreateOneOutputBlacklisted) { } TEST(AlsaCard, CreateTwoOutputs) { - struct cras_alsa_card *c; + struct cras_alsa_card* c; int dev_nums[] = {0, 3}; int info_rets[] = {0, -1, 0}; cras_alsa_card_info card_info; @@ -475,9 +476,9 @@ TEST(AlsaCard, CreateTwoOutputs) { snd_ctl_pcm_info_rets = info_rets; card_info.card_type = ALSA_CARD_TYPE_INTERNAL; card_info.card_index = 0; - c = cras_alsa_card_create(&card_info, device_config_dir, - fake_blacklist, NULL); - EXPECT_NE(static_cast<struct cras_alsa_card *>(NULL), c); + c = cras_alsa_card_create(&card_info, device_config_dir, fake_blacklist, + NULL); + EXPECT_NE(static_cast<struct cras_alsa_card*>(NULL), c); EXPECT_EQ(snd_ctl_close_called, snd_ctl_open_called); EXPECT_EQ(3, snd_ctl_pcm_next_device_called); EXPECT_EQ(2, cras_alsa_iodev_create_called); @@ -496,7 +497,7 @@ TEST(AlsaCard, CreateTwoOutputs) { } TEST(AlsaCard, CreateTwoDuplicateDeviceIndex) { - struct cras_alsa_card *c; + struct cras_alsa_card* c; int dev_nums[] = {0, 0}; int info_rets[] = {0, -1, 0}; cras_alsa_card_info card_info; @@ -508,9 +509,9 @@ TEST(AlsaCard, CreateTwoDuplicateDeviceIndex) { snd_ctl_pcm_info_rets = info_rets; card_info.card_type = ALSA_CARD_TYPE_INTERNAL; card_info.card_index = 0; - c = cras_alsa_card_create(&card_info, device_config_dir, - fake_blacklist, NULL); - EXPECT_NE(static_cast<struct cras_alsa_card *>(NULL), c); + c = cras_alsa_card_create(&card_info, device_config_dir, fake_blacklist, + NULL); + EXPECT_NE(static_cast<struct cras_alsa_card*>(NULL), c); EXPECT_EQ(snd_ctl_close_called, snd_ctl_open_called); EXPECT_EQ(3, snd_ctl_pcm_next_device_called); EXPECT_EQ(1, cras_alsa_iodev_create_called); @@ -529,7 +530,7 @@ TEST(AlsaCard, CreateTwoDuplicateDeviceIndex) { } TEST(AlsaCard, CreateOneInput) { - struct cras_alsa_card *c; + struct cras_alsa_card* c; int dev_nums[] = {0}; int info_rets[] = {-1, 0}; cras_alsa_card_info card_info; @@ -541,9 +542,9 @@ TEST(AlsaCard, CreateOneInput) { snd_ctl_pcm_info_rets = info_rets; card_info.card_type = ALSA_CARD_TYPE_INTERNAL; card_info.card_index = 0; - c = cras_alsa_card_create(&card_info, device_config_dir, - fake_blacklist, NULL); - EXPECT_NE(static_cast<struct cras_alsa_card *>(NULL), c); + c = cras_alsa_card_create(&card_info, device_config_dir, fake_blacklist, + NULL); + EXPECT_NE(static_cast<struct cras_alsa_card*>(NULL), c); EXPECT_EQ(snd_ctl_close_called, snd_ctl_open_called); EXPECT_EQ(2, snd_ctl_pcm_next_device_called); EXPECT_EQ(1, cras_alsa_iodev_create_called); @@ -561,7 +562,7 @@ TEST(AlsaCard, CreateOneInput) { } TEST(AlsaCard, CreateOneInputAndOneOutput) { - struct cras_alsa_card *c; + struct cras_alsa_card* c; int dev_nums[] = {0}; int info_rets[] = {0, 0}; cras_alsa_card_info card_info; @@ -573,9 +574,9 @@ TEST(AlsaCard, CreateOneInputAndOneOutput) { snd_ctl_pcm_info_rets = info_rets; card_info.card_type = ALSA_CARD_TYPE_INTERNAL; card_info.card_index = 0; - c = cras_alsa_card_create(&card_info, device_config_dir, - fake_blacklist, NULL); - EXPECT_NE(static_cast<struct cras_alsa_card *>(NULL), c); + c = cras_alsa_card_create(&card_info, device_config_dir, fake_blacklist, + NULL); + EXPECT_NE(static_cast<struct cras_alsa_card*>(NULL), c); EXPECT_EQ(snd_ctl_close_called, snd_ctl_open_called); EXPECT_EQ(2, snd_ctl_pcm_next_device_called); EXPECT_EQ(2, cras_alsa_iodev_create_called); @@ -593,7 +594,7 @@ TEST(AlsaCard, CreateOneInputAndOneOutput) { } TEST(AlsaCard, CreateOneInputAndOneOutputTwoDevices) { - struct cras_alsa_card *c; + struct cras_alsa_card* c; int dev_nums[] = {0, 3}; int info_rets[] = {0, -1, -1, 0}; cras_alsa_card_info card_info; @@ -605,9 +606,9 @@ TEST(AlsaCard, CreateOneInputAndOneOutputTwoDevices) { snd_ctl_pcm_info_rets = info_rets; card_info.card_type = ALSA_CARD_TYPE_INTERNAL; card_info.card_index = 0; - c = cras_alsa_card_create(&card_info, device_config_dir, - fake_blacklist, NULL); - EXPECT_NE(static_cast<struct cras_alsa_card *>(NULL), c); + c = cras_alsa_card_create(&card_info, device_config_dir, fake_blacklist, + NULL); + EXPECT_NE(static_cast<struct cras_alsa_card*>(NULL), c); EXPECT_EQ(snd_ctl_close_called, snd_ctl_open_called); EXPECT_EQ(3, snd_ctl_pcm_next_device_called); EXPECT_EQ(2, cras_alsa_iodev_create_called); @@ -625,7 +626,7 @@ TEST(AlsaCard, CreateOneInputAndOneOutputTwoDevices) { } TEST(AlsaCard, CreateOneOutputWithCoupledMixers) { - struct cras_alsa_card *c; + struct cras_alsa_card* c; int dev_nums[] = {0}; int info_rets[] = {0, -1}; struct mixer_name *mixer_name_1, *mixer_name_2; @@ -656,10 +657,10 @@ TEST(AlsaCard, CreateOneOutputWithCoupledMixers) { DL_APPEND(ucm_get_coupled_mixer_names_return_value, mixer_name_1); DL_APPEND(ucm_get_coupled_mixer_names_return_value, mixer_name_2); - c = cras_alsa_card_create(&card_info, device_config_dir, - fake_blacklist, NULL); + c = cras_alsa_card_create(&card_info, device_config_dir, fake_blacklist, + NULL); - EXPECT_NE(static_cast<struct cras_alsa_card *>(NULL), c); + EXPECT_NE(static_cast<struct cras_alsa_card*>(NULL), c); EXPECT_EQ(snd_ctl_close_called, snd_ctl_open_called); EXPECT_EQ(2, snd_ctl_pcm_next_device_called); EXPECT_EQ(1, cras_alsa_iodev_create_called); @@ -676,7 +677,7 @@ TEST(AlsaCard, CreateOneOutputWithCoupledMixers) { /* Checks cras_alsa_card_create can handle the list and pass the names to * cras_alsa_mixer_create. */ - struct mixer_name *m_name = coupled_output_names_value; + struct mixer_name* m_name = coupled_output_names_value; EXPECT_EQ(0, m_name ? strcmp(m_name->name, "MixerName1") : 1); if (m_name) m_name = m_name->next; @@ -694,7 +695,7 @@ TEST(AlsaCard, CreateOneOutputWithCoupledMixers) { } TEST(AlsaCard, CreateFullyUCMNoSections) { - struct cras_alsa_card *c; + struct cras_alsa_card* c; cras_alsa_card_info card_info; ResetStubData(); @@ -702,9 +703,9 @@ TEST(AlsaCard, CreateFullyUCMNoSections) { card_info.card_index = 0; ucm_has_fully_specified_ucm_flag_return_value = 1; ucm_get_sections_return_value = NULL; - c = cras_alsa_card_create(&card_info, device_config_dir, - fake_blacklist, NULL); - EXPECT_EQ(static_cast<struct cras_alsa_card *>(NULL), c); + c = cras_alsa_card_create(&card_info, device_config_dir, fake_blacklist, + NULL); + EXPECT_EQ(static_cast<struct cras_alsa_card*>(NULL), c); EXPECT_EQ(snd_ctl_close_called, snd_ctl_open_called); EXPECT_EQ(0, cras_alsa_iodev_create_called); EXPECT_EQ(0, cras_alsa_iodev_ucm_complete_init_called); @@ -721,7 +722,7 @@ TEST(AlsaCard, CreateFullyUCMNoSections) { } TEST(AlsaCard, CreateFullyUCMTwoMainVolume) { - struct cras_alsa_card *c; + struct cras_alsa_card* c; struct mixer_name *mixer_name_1, *mixer_name_2; const char *name1 = strdup("MixerName1"), *name2 = strdup("MixerName2"); cras_alsa_card_info card_info; @@ -745,10 +746,10 @@ TEST(AlsaCard, CreateFullyUCMTwoMainVolume) { DL_APPEND(ucm_get_main_volume_names_return_value, mixer_name_1); DL_APPEND(ucm_get_main_volume_names_return_value, mixer_name_2); - c = cras_alsa_card_create(&card_info, device_config_dir, - fake_blacklist, NULL); + c = cras_alsa_card_create(&card_info, device_config_dir, fake_blacklist, + NULL); - EXPECT_EQ(static_cast<struct cras_alsa_card *>(NULL), c); + EXPECT_EQ(static_cast<struct cras_alsa_card*>(NULL), c); EXPECT_EQ(snd_ctl_close_called, snd_ctl_open_called); EXPECT_EQ(0, cras_alsa_iodev_create_called); EXPECT_EQ(0, cras_alsa_iodev_ucm_complete_init_called); @@ -757,7 +758,6 @@ TEST(AlsaCard, CreateFullyUCMTwoMainVolume) { EXPECT_EQ(1, ucm_get_sections_called); EXPECT_EQ(0, cras_alsa_mixer_add_controls_in_section_called); - cras_alsa_card_destroy(c); EXPECT_EQ(1, ucm_destroy_called); EXPECT_EQ(0, cras_alsa_iodev_destroy_called); @@ -766,9 +766,9 @@ TEST(AlsaCard, CreateFullyUCMTwoMainVolume) { EXPECT_EQ(iniparser_load_called, iniparser_freedict_called); } -struct ucm_section *GenerateUcmSections (void) { - struct ucm_section *sections = NULL; - struct ucm_section *section; +struct ucm_section* GenerateUcmSections(void) { + struct ucm_section* sections = NULL; + struct ucm_section* section; section = ucm_section_create("Headphone", 0, CRAS_STREAM_OUTPUT, "my-sound-card Headset Jack", "gpio"); @@ -776,14 +776,13 @@ struct ucm_section *GenerateUcmSections (void) { ucm_section_add_coupled(section, "HP-R", MIXER_NAME_VOLUME); DL_APPEND(sections, section); - section = ucm_section_create("Speaker", 0, CRAS_STREAM_OUTPUT, - NULL, NULL); + section = ucm_section_create("Speaker", 0, CRAS_STREAM_OUTPUT, NULL, NULL); ucm_section_add_coupled(section, "SPK-L", MIXER_NAME_VOLUME); ucm_section_add_coupled(section, "SPK-R", MIXER_NAME_VOLUME); DL_APPEND(sections, section); - section = ucm_section_create("Internal Mic", 0, CRAS_STREAM_INPUT, - NULL, NULL); + section = + ucm_section_create("Internal Mic", 0, CRAS_STREAM_INPUT, NULL, NULL); ucm_section_add_coupled(section, "INT-MIC-L", MIXER_NAME_VOLUME); ucm_section_add_coupled(section, "INT-MIC-R", MIXER_NAME_VOLUME); DL_APPEND(sections, section); @@ -794,8 +793,7 @@ struct ucm_section *GenerateUcmSections (void) { ucm_section_add_coupled(section, "MIC-R", MIXER_NAME_VOLUME); DL_APPEND(sections, section); - section = ucm_section_create("HDMI", 2, CRAS_STREAM_OUTPUT, - NULL, NULL); + section = ucm_section_create("HDMI", 2, CRAS_STREAM_OUTPUT, NULL, NULL); ucm_section_set_mixer_name(section, "HDMI"); DL_APPEND(sections, section); @@ -803,7 +801,7 @@ struct ucm_section *GenerateUcmSections (void) { } TEST(AlsaCard, CreateFullyUCMFailureOnControls) { - struct cras_alsa_card *c; + struct cras_alsa_card* c; cras_alsa_card_info card_info; ResetStubData(); @@ -811,14 +809,14 @@ TEST(AlsaCard, CreateFullyUCMFailureOnControls) { card_info.card_index = 0; ucm_has_fully_specified_ucm_flag_return_value = 1; ucm_get_sections_return_value = GenerateUcmSections(); - ASSERT_NE(ucm_get_sections_return_value, (struct ucm_section *)NULL); + ASSERT_NE(ucm_get_sections_return_value, (struct ucm_section*)NULL); cras_alsa_mixer_add_controls_in_section_return_value = -EINVAL; - c = cras_alsa_card_create(&card_info, device_config_dir, - fake_blacklist, NULL); + c = cras_alsa_card_create(&card_info, device_config_dir, fake_blacklist, + NULL); - EXPECT_EQ(static_cast<struct cras_alsa_card *>(NULL), c); + EXPECT_EQ(static_cast<struct cras_alsa_card*>(NULL), c); EXPECT_EQ(snd_ctl_close_called, snd_ctl_open_called); EXPECT_EQ(1, snd_ctl_card_info_called); EXPECT_EQ(1, ucm_get_sections_called); @@ -835,7 +833,7 @@ TEST(AlsaCard, CreateFullyUCMFailureOnControls) { } TEST(AlsaCard, CreateFullyUCMFourDevicesFiveSections) { - struct cras_alsa_card *c; + struct cras_alsa_card* c; cras_alsa_card_info card_info; int info_rets[] = {0, 0, 0, 0, 0, -1}; @@ -850,12 +848,12 @@ TEST(AlsaCard, CreateFullyUCMFourDevicesFiveSections) { cras_alsa_iodev_index_return[cras_alsa_iodev_create_return[1]] = 0; cras_alsa_iodev_index_return[cras_alsa_iodev_create_return[2]] = 1; cras_alsa_iodev_index_return[cras_alsa_iodev_create_return[3]] = 2; - ASSERT_NE(ucm_get_sections_return_value, (struct ucm_section *)NULL); + ASSERT_NE(ucm_get_sections_return_value, (struct ucm_section*)NULL); - c = cras_alsa_card_create(&card_info, device_config_dir, - fake_blacklist, NULL); + c = cras_alsa_card_create(&card_info, device_config_dir, fake_blacklist, + NULL); - EXPECT_NE(static_cast<struct cras_alsa_card *>(NULL), c); + EXPECT_NE(static_cast<struct cras_alsa_card*>(NULL), c); EXPECT_EQ(snd_ctl_close_called, snd_ctl_open_called); EXPECT_EQ(1, snd_ctl_card_info_called); EXPECT_EQ(1, ucm_get_sections_called); @@ -874,11 +872,11 @@ TEST(AlsaCard, CreateFullyUCMFourDevicesFiveSections) { } TEST(AlsaCard, GG) { - struct cras_alsa_card *c; + struct cras_alsa_card* c; cras_alsa_card_info card_info; int info_rets[] = {0, 0, 0, 0, 0, -1}; struct cras_ionode nodes[4]; - const char *echo_ref = "echo ref"; + const char* echo_ref = "echo ref"; ResetStubData(); card_info.card_type = ALSA_CARD_TYPE_INTERNAL; @@ -899,10 +897,10 @@ TEST(AlsaCard, GG) { ucm_get_echo_reference_dev_name_for_dev_return_value[0] = strdup(echo_ref); - c = cras_alsa_card_create(&card_info, device_config_dir, - fake_blacklist, NULL); + c = cras_alsa_card_create(&card_info, device_config_dir, fake_blacklist, + NULL); - EXPECT_NE(static_cast<struct cras_alsa_card *>(NULL), c); + EXPECT_NE(static_cast<struct cras_alsa_card*>(NULL), c); EXPECT_EQ(fake_dev1.echo_reference_dev, &fake_dev4); cras_alsa_card_destroy(c); } @@ -910,78 +908,76 @@ TEST(AlsaCard, GG) { /* Stubs */ extern "C" { -struct cras_alsa_mixer *cras_alsa_mixer_create(const char *card_name) { +struct cras_alsa_mixer* cras_alsa_mixer_create(const char* card_name) { cras_alsa_mixer_create_called++; return cras_alsa_mixer_create_return; } int cras_alsa_mixer_add_controls_by_name_matching( struct cras_alsa_mixer* cmix, - struct mixer_name *extra_controls, - struct mixer_name *coupled_controls) { + struct mixer_name* extra_controls, + struct mixer_name* coupled_controls) { /* Duplicate coupled_output_names to verify in the end of unittest * because names will get freed later in cras_alsa_card_create. */ - struct mixer_name *control; - DL_FOREACH(coupled_controls, control) { + struct mixer_name* control; + DL_FOREACH (coupled_controls, control) { coupled_output_names_value = - mixer_name_add(coupled_output_names_value, - control->name, - CRAS_STREAM_OUTPUT, - control->type); + mixer_name_add(coupled_output_names_value, control->name, + CRAS_STREAM_OUTPUT, control->type); } return 0; } -void cras_alsa_mixer_destroy(struct cras_alsa_mixer *cras_mixer) { +void cras_alsa_mixer_destroy(struct cras_alsa_mixer* cras_mixer) { cras_alsa_mixer_destroy_called++; } -struct cras_iodev *alsa_iodev_create(size_t card_index, - const char *card_name, - size_t device_index, - const char *dev_name, - const char *dev_id, - enum CRAS_ALSA_CARD_TYPE card_type, - int is_first, - struct cras_alsa_mixer *mixer, - const struct cras_card_config *config, - struct cras_use_case_mgr *ucm, - snd_hctl_t *hctl, - enum CRAS_STREAM_DIRECTION direction, - size_t usb_vid, - size_t usb_pid, - char *usb_serial_number) { - struct cras_iodev *result = NULL; +struct cras_iodev* alsa_iodev_create(size_t card_index, + const char* card_name, + size_t device_index, + const char* dev_name, + const char* dev_id, + enum CRAS_ALSA_CARD_TYPE card_type, + int is_first, + struct cras_alsa_mixer* mixer, + const struct cras_card_config* config, + struct cras_use_case_mgr* ucm, + snd_hctl_t* hctl, + enum CRAS_STREAM_DIRECTION direction, + size_t usb_vid, + size_t usb_pid, + char* usb_serial_number) { + struct cras_iodev* result = NULL; if (cras_alsa_iodev_create_called < cras_alsa_iodev_create_return_size) result = cras_alsa_iodev_create_return[cras_alsa_iodev_create_called]; cras_alsa_iodev_create_called++; return result; } -void alsa_iodev_destroy(struct cras_iodev *iodev) { +void alsa_iodev_destroy(struct cras_iodev* iodev) { cras_alsa_iodev_destroy_called++; cras_alsa_iodev_destroy_arg = iodev; } -int alsa_iodev_legacy_complete_init(struct cras_iodev *iodev) { +int alsa_iodev_legacy_complete_init(struct cras_iodev* iodev) { cras_alsa_iodev_legacy_complete_init_called++; return 0; } -int alsa_iodev_ucm_add_nodes_and_jacks(struct cras_iodev *iodev, - struct ucm_section *section) { +int alsa_iodev_ucm_add_nodes_and_jacks(struct cras_iodev* iodev, + struct ucm_section* section) { cras_alsa_iodev_ucm_add_nodes_and_jacks_called++; return 0; } -void alsa_iodev_ucm_complete_init(struct cras_iodev *iodev) { +void alsa_iodev_ucm_complete_init(struct cras_iodev* iodev) { cras_alsa_iodev_ucm_complete_init_called++; } -unsigned alsa_iodev_index(struct cras_iodev *iodev) { - std::map<struct cras_iodev *, unsigned int>::iterator i; +unsigned alsa_iodev_index(struct cras_iodev* iodev) { + std::map<struct cras_iodev*, unsigned int>::iterator i; cras_alsa_iodev_index_called++; i = cras_alsa_iodev_index_return.find(iodev); if (i != cras_alsa_iodev_index_return.end()) return i->second; return 0; } -int alsa_iodev_has_hctl_jacks(struct cras_iodev *iodev) { +int alsa_iodev_has_hctl_jacks(struct cras_iodev* iodev) { return alsa_iodev_has_hctl_jacks_return; } @@ -991,7 +987,7 @@ size_t snd_pcm_info_sizeof() { size_t snd_ctl_card_info_sizeof() { return 10; } -int snd_ctl_open(snd_ctl_t **handle, const char *name, int card) { +int snd_ctl_open(snd_ctl_t** handle, const char* name, int card) { snd_ctl_open_called++; if (snd_ctl_open_return == 0) *handle = reinterpret_cast<snd_ctl_t*>(0xff); @@ -999,11 +995,11 @@ int snd_ctl_open(snd_ctl_t **handle, const char *name, int card) { *handle = NULL; return snd_ctl_open_return; } -int snd_ctl_close(snd_ctl_t *handle) { +int snd_ctl_close(snd_ctl_t* handle) { snd_ctl_close_called++; return snd_ctl_close_return; } -int snd_ctl_pcm_next_device(snd_ctl_t *ctl, int *device) { +int snd_ctl_pcm_next_device(snd_ctl_t* ctl, int* device) { if (snd_ctl_pcm_next_device_return_error) { *device = 10; return -1; @@ -1019,184 +1015,165 @@ int snd_ctl_pcm_next_device(snd_ctl_t *ctl, int *device) { snd_ctl_pcm_next_device_set_devs_index++; return 0; } -void snd_pcm_info_set_device(snd_pcm_info_t *obj, unsigned int val) { -} -void snd_pcm_info_set_subdevice(snd_pcm_info_t *obj, unsigned int val) { -} -void snd_pcm_info_set_stream(snd_pcm_info_t *obj, snd_pcm_stream_t val) { -} -const char *snd_pcm_info_get_name(const snd_pcm_info_t *obj) { +void snd_pcm_info_set_device(snd_pcm_info_t* obj, unsigned int val) {} +void snd_pcm_info_set_subdevice(snd_pcm_info_t* obj, unsigned int val) {} +void snd_pcm_info_set_stream(snd_pcm_info_t* obj, snd_pcm_stream_t val) {} +const char* snd_pcm_info_get_name(const snd_pcm_info_t* obj) { return "Fake device name"; } -const char *snd_pcm_info_get_id(const snd_pcm_info_t *obj) { +const char* snd_pcm_info_get_id(const snd_pcm_info_t* obj) { return "Fake device id"; } -int snd_ctl_pcm_info(snd_ctl_t *ctl, snd_pcm_info_t *info) { +int snd_ctl_pcm_info(snd_ctl_t* ctl, snd_pcm_info_t* info) { int ret; snd_ctl_pcm_info_called++; - if (snd_ctl_pcm_info_rets_index >= - snd_ctl_pcm_info_rets_size) { + if (snd_ctl_pcm_info_rets_index >= snd_ctl_pcm_info_rets_size) { return -1; } ret = snd_ctl_pcm_info_rets[snd_ctl_pcm_info_rets_index]; snd_ctl_pcm_info_rets_index++; return ret; } -int snd_ctl_card_info(snd_ctl_t *ctl, snd_ctl_card_info_t *info) { +int snd_ctl_card_info(snd_ctl_t* ctl, snd_ctl_card_info_t* info) { snd_ctl_card_info_called++; return snd_ctl_card_info_ret; } -const char *snd_ctl_card_info_get_name(const snd_ctl_card_info_t *obj) { +const char* snd_ctl_card_info_get_name(const snd_ctl_card_info_t* obj) { return "TestName"; } -const char *snd_ctl_card_info_get_id(const snd_ctl_card_info_t *obj) { +const char* snd_ctl_card_info_get_id(const snd_ctl_card_info_t* obj) { return "TestId"; } -int snd_hctl_open(snd_hctl_t **hctlp, const char *name, int mode) { +int snd_hctl_open(snd_hctl_t** hctlp, const char* name, int mode) { *hctlp = snd_hctl_open_pointer_val; snd_hctl_open_called++; return snd_hctl_open_return_value; } -int snd_hctl_nonblock(snd_hctl_t *hctl, int nonblock) { +int snd_hctl_nonblock(snd_hctl_t* hctl, int nonblock) { snd_hctl_nonblock_called++; return 0; } -int snd_hctl_load(snd_hctl_t *hctl) { +int snd_hctl_load(snd_hctl_t* hctl) { snd_hctl_load_called++; return snd_hctl_load_return_value; } -int snd_hctl_close(snd_hctl_t *hctl) { +int snd_hctl_close(snd_hctl_t* hctl) { snd_hctl_close_called++; return 0; } -int snd_hctl_poll_descriptors_count(snd_hctl_t *hctl) { +int snd_hctl_poll_descriptors_count(snd_hctl_t* hctl) { return snd_hctl_poll_descriptors_num_fds; } -int snd_hctl_poll_descriptors(snd_hctl_t *hctl, - struct pollfd *pfds, +int snd_hctl_poll_descriptors(snd_hctl_t* hctl, + struct pollfd* pfds, unsigned int space) { unsigned int num = MIN(space, snd_hctl_poll_descriptors_num_fds); memcpy(pfds, snd_hctl_poll_descriptors_fds, num * sizeof(*pfds)); snd_hctl_poll_descriptors_called++; return num; } -int snd_hctl_handle_events(snd_hctl_t *hctl) { +int snd_hctl_handle_events(snd_hctl_t* hctl) { snd_hctl_handle_events_called++; return 0; } int cras_system_add_select_fd(int fd, - void (*callback)(void *data), - void *callback_data) -{ + void (*callback)(void* data), + void* callback_data) { cras_system_add_select_fd_called++; cras_system_add_select_fd_values.push_back(fd); return 0; } -void cras_system_rm_select_fd(int fd) -{ +void cras_system_rm_select_fd(int fd) { cras_system_rm_select_fd_called++; cras_system_rm_select_fd_values.push_back(fd); } -struct cras_card_config *cras_card_config_create(const char *config_path, - const char *card_name) -{ +struct cras_card_config* cras_card_config_create(const char* config_path, + const char* card_name) { cras_card_config_dir = config_path; return NULL; } -void cras_card_config_destroy(struct cras_card_config *card_config) -{ -} +void cras_card_config_destroy(struct cras_card_config* card_config) {} -struct cras_volume_curve *cras_card_config_get_volume_curve_for_control( - const struct cras_card_config *card_config, - const char *control_name) -{ +struct cras_volume_curve* cras_card_config_get_volume_curve_for_control( + const struct cras_card_config* card_config, + const char* control_name) { return NULL; } -int cras_device_blacklist_check( - struct cras_device_blacklist *blacklist, - unsigned vendor_id, - unsigned product_id, - unsigned device_index) { +int cras_device_blacklist_check(struct cras_device_blacklist* blacklist, + unsigned vendor_id, + unsigned product_id, + unsigned device_index) { EXPECT_EQ(fake_blacklist, blacklist); return cras_device_blacklist_check_retval; } -struct cras_use_case_mgr *ucm_create(const char* name) { +struct cras_use_case_mgr* ucm_create(const char* name) { ucm_create_called++; - return reinterpret_cast<struct cras_use_case_mgr *>(0x44); + return reinterpret_cast<struct cras_use_case_mgr*>(0x44); } -void ucm_destroy(struct cras_use_case_mgr *mgr) { +void ucm_destroy(struct cras_use_case_mgr* mgr) { ucm_destroy_called++; } -char *ucm_get_dev_for_mixer(struct cras_use_case_mgr *mgr, const char *mixer, - enum CRAS_STREAM_DIRECTION dir) -{ +char* ucm_get_dev_for_mixer(struct cras_use_case_mgr* mgr, + const char* mixer, + enum CRAS_STREAM_DIRECTION dir) { ucm_get_dev_for_mixer_called++; return strdup("device"); } -char *ucm_get_flag(struct cras_use_case_mgr *mgr, const char *flag_name) { +char* ucm_get_flag(struct cras_use_case_mgr* mgr, const char* flag_name) { ucm_get_flag_called++; - strncpy(ucm_get_flag_name, flag_name, sizeof(ucm_get_flag_name)); + strncpy(ucm_get_flag_name, flag_name, sizeof(ucm_get_flag_name) - 1); return NULL; } -struct mixer_name *ucm_get_coupled_mixer_names( - struct cras_use_case_mgr *mgr, const char *dev) -{ +struct mixer_name* ucm_get_coupled_mixer_names(struct cras_use_case_mgr* mgr, + const char* dev) { return ucm_get_coupled_mixer_names_return_value; } -int ucm_has_fully_specified_ucm_flag(struct cras_use_case_mgr *mgr) -{ +int ucm_has_fully_specified_ucm_flag(struct cras_use_case_mgr* mgr) { return ucm_has_fully_specified_ucm_flag_return_value; } -struct mixer_name *ucm_get_main_volume_names(struct cras_use_case_mgr *mgr) -{ +struct mixer_name* ucm_get_main_volume_names(struct cras_use_case_mgr* mgr) { return ucm_get_main_volume_names_return_value; } -struct ucm_section *ucm_get_sections(struct cras_use_case_mgr *mgr) -{ +struct ucm_section* ucm_get_sections(struct cras_use_case_mgr* mgr) { ucm_get_sections_called++; return ucm_get_sections_return_value; } -const char *ucm_get_echo_reference_dev_name_for_dev( - struct cras_use_case_mgr *mgr, const char *dev) -{ +const char* ucm_get_echo_reference_dev_name_for_dev( + struct cras_use_case_mgr* mgr, + const char* dev) { int idx = ucm_get_echo_reference_dev_name_for_dev_called++; return ucm_get_echo_reference_dev_name_for_dev_return_value[idx]; } int cras_alsa_mixer_add_main_volume_control_by_name( - struct cras_alsa_mixer *cmix, - struct mixer_name *mixer_names) -{ + struct cras_alsa_mixer* cmix, + struct mixer_name* mixer_names) { cras_alsa_mixer_add_main_volume_control_by_name_called++; return cras_alsa_mixer_add_main_volume_control_by_name_return_value; } -int cras_alsa_mixer_add_controls_in_section( - struct cras_alsa_mixer *cmix, - struct ucm_section *section) -{ +int cras_alsa_mixer_add_controls_in_section(struct cras_alsa_mixer* cmix, + struct ucm_section* section) { cras_alsa_mixer_add_controls_in_section_called++; return cras_alsa_mixer_add_controls_in_section_return_value; } -void ucm_free_mixer_names(struct mixer_name *names) -{ - struct mixer_name *m; - DL_FOREACH(names, m) { +void ucm_free_mixer_names(struct mixer_name* names) { + struct mixer_name* m; + DL_FOREACH (names, m) { DL_DELETE(names, m); free((void*)m->name); free(m); @@ -1207,7 +1184,7 @@ void ucm_free_mixer_names(struct mixer_name *names) } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); openlog(NULL, LOG_PERROR, LOG_USER); return RUN_ALL_TESTS(); diff --git a/cras/src/tests/alsa_helpers_unittest.cc b/cras/src/tests/alsa_helpers_unittest.cc index a6139294..0e8112cd 100644 --- a/cras/src/tests/alsa_helpers_unittest.cc +++ b/cras/src/tests/alsa_helpers_unittest.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include <gtest/gtest.h> + #include <vector> extern "C" { @@ -27,28 +28,27 @@ static void ResetStubData() { namespace { -static snd_pcm_chmap_query_t *create_chmap_cap(snd_pcm_chmap_type type, - size_t channels) -{ - snd_pcm_chmap_query_t *c; - c = (snd_pcm_chmap_query_t *)calloc(channels + 2, sizeof(int)); +static snd_pcm_chmap_query_t* create_chmap_cap(snd_pcm_chmap_type type, + size_t channels) { + snd_pcm_chmap_query_t* c; + c = (snd_pcm_chmap_query_t*)calloc(channels + 2, sizeof(int)); c->type = type; c->map.channels = channels; return c; } TEST(AlsaHelper, MatchChannelMapCapabilityStereo) { - snd_pcm_chmap_query_t **caps; - snd_pcm_chmap_query_t *c; - struct cras_audio_format *fmt; + snd_pcm_chmap_query_t** caps; + snd_pcm_chmap_query_t* c; + struct cras_audio_format* fmt; - caps = (snd_pcm_chmap_query_t **)calloc(4, sizeof(*caps)); + caps = (snd_pcm_chmap_query_t**)calloc(4, sizeof(*caps)); /* Layout (CRAS_CH_RL, CRAS_CH_RR) corresponds to * ALSA channel map (5, 6) */ - int8_t channel_layout[CRAS_CH_MAX] = - {-1, -1, 0, 1, -1, -1, -1, -1, -1, -1, -1}; + int8_t channel_layout[CRAS_CH_MAX] = {-1, -1, 0, 1, -1, -1, + -1, -1, -1, -1, -1}; fmt = cras_audio_format_create(SND_PCM_FORMAT_S16_LE, 44100, 2); cras_audio_format_set_channel_layout(fmt, channel_layout); @@ -74,13 +74,13 @@ TEST(AlsaHelper, MatchChannelMapCapabilityStereo) { /* Test if there's a cap matches fmt */ c = cras_chmap_caps_match(caps, fmt); - ASSERT_NE((void *)NULL, c); + ASSERT_NE((void*)NULL, c); caps[1]->map.pos[0] = 5; caps[1]->map.pos[1] = 7; c = cras_chmap_caps_match(caps, fmt); - ASSERT_EQ((void *)NULL, c); + ASSERT_EQ((void*)NULL, c); free(caps[0]); free(caps[1]); @@ -91,17 +91,16 @@ TEST(AlsaHelper, MatchChannelMapCapabilityStereo) { } TEST(AlsaHelper, MatchChannelMapCapability51) { - snd_pcm_chmap_query_t **caps = NULL; - snd_pcm_chmap_query_t *c = NULL; - struct cras_audio_format *fmt; + snd_pcm_chmap_query_t** caps = NULL; + snd_pcm_chmap_query_t* c = NULL; + struct cras_audio_format* fmt; - caps = (snd_pcm_chmap_query_t **)calloc(4, sizeof(*caps)); + caps = (snd_pcm_chmap_query_t**)calloc(4, sizeof(*caps)); /* Layout (CRAS_CH_FL, CRAS_CH_FR, CRAS_CH_RL, CRAS_CH_RR, CRAS_CH_FC) * corresponds to ALSA channel map (3, 4, 5, 6, 7) */ - int8_t channel_layout[CRAS_CH_MAX] = - {0, 1, 2, 3, 4, 5, -1, -1, -1, -1, -1}; + int8_t channel_layout[CRAS_CH_MAX] = {0, 1, 2, 3, 4, 5, -1, -1, -1, -1, -1}; fmt = cras_audio_format_create(SND_PCM_FORMAT_S16_LE, 44100, 6); cras_audio_format_set_channel_layout(fmt, channel_layout); @@ -133,27 +132,27 @@ TEST(AlsaHelper, MatchChannelMapCapability51) { /* Test if there's a cap matches fmt */ c = cras_chmap_caps_match(caps, fmt); - ASSERT_NE((void *)NULL, c); + ASSERT_NE((void*)NULL, c); caps[0]->map.pos[0] = 7; caps[0]->map.pos[1] = 8; caps[0]->map.pos[4] = 3; caps[0]->map.pos[5] = 4; c = cras_chmap_caps_match(caps, fmt); - ASSERT_EQ((void *)NULL, c); + ASSERT_EQ((void*)NULL, c); caps[0]->type = SND_CHMAP_TYPE_PAIRED; c = cras_chmap_caps_match(caps, fmt); - ASSERT_NE((void *)NULL, c); + ASSERT_NE((void*)NULL, c); caps[0]->map.pos[0] = 8; caps[0]->map.pos[1] = 7; c = cras_chmap_caps_match(caps, fmt); - ASSERT_EQ((void *)NULL, c); + ASSERT_EQ((void*)NULL, c); caps[0]->type = SND_CHMAP_TYPE_VAR; c = cras_chmap_caps_match(caps, fmt); - ASSERT_NE((void *)NULL, c); + ASSERT_NE((void*)NULL, c); free(caps[0]); free(caps[1]); @@ -164,12 +163,12 @@ TEST(AlsaHelper, MatchChannelMapCapability51) { } TEST(AlsaHelper, Htimestamp) { - snd_pcm_t *dummy_handle = reinterpret_cast<snd_pcm_t*>(0x1); + snd_pcm_t* dummy_handle = reinterpret_cast<snd_pcm_t*>(0x1); snd_pcm_uframes_t used; snd_pcm_uframes_t severe_underrun_frames = 480; struct timespec tstamp; int htimestamp_enabled = 1; - const char *dev_name = "dev_name"; + const char* dev_name = "dev_name"; // Enable htimestamp use. ResetStubData(); @@ -207,27 +206,27 @@ TEST(AlsaHelper, Htimestamp) { } TEST(AlsaHelper, GetAvailFramesSevereUnderrun) { - snd_pcm_t *dummy_handle = reinterpret_cast<snd_pcm_t*>(0x1); + snd_pcm_t* dummy_handle = reinterpret_cast<snd_pcm_t*>(0x1); snd_pcm_uframes_t avail; snd_pcm_uframes_t severe_underrun_frames = 480; snd_pcm_uframes_t buffer_size = 48000; struct timespec tstamp; int rc; - const char *dev_name = "dev_name"; + const char* dev_name = "dev_name"; ResetStubData(); snd_pcm_htimestamp_avail_ret_val = buffer_size + severe_underrun_frames + 1; rc = cras_alsa_get_avail_frames(dummy_handle, buffer_size, - severe_underrun_frames, dev_name, - &avail, &tstamp); + severe_underrun_frames, dev_name, &avail, + &tstamp); // Returns -EPIPE when severe underrun happens. EXPECT_EQ(rc, -EPIPE); ResetStubData(); snd_pcm_htimestamp_avail_ret_val = buffer_size + severe_underrun_frames; rc = cras_alsa_get_avail_frames(dummy_handle, buffer_size, - severe_underrun_frames, dev_name, - &avail, &tstamp); + severe_underrun_frames, dev_name, &avail, + &tstamp); // Underrun which is not severe enough will be masked. // avail will be adjusted to buffer_size. EXPECT_EQ(avail, buffer_size); @@ -236,57 +235,58 @@ TEST(AlsaHelper, GetAvailFramesSevereUnderrun) { ResetStubData(); snd_pcm_htimestamp_avail_ret_val = buffer_size - 1; rc = cras_alsa_get_avail_frames(dummy_handle, buffer_size, - severe_underrun_frames, dev_name, - &avail, &tstamp); + severe_underrun_frames, dev_name, &avail, + &tstamp); // When avail < buffer_size, there is no underrun. EXPECT_EQ(avail, buffer_size - 1); EXPECT_EQ(rc, 0); } -} // namespace +} // namespace extern "C" { -int snd_pcm_sw_params_current(snd_pcm_t *pcm, snd_pcm_sw_params_t *params) { +int snd_pcm_sw_params_current(snd_pcm_t* pcm, snd_pcm_sw_params_t* params) { return 0; } -int snd_pcm_sw_params_get_boundary(const snd_pcm_sw_params_t *params, - snd_pcm_uframes_t *val) { +int snd_pcm_sw_params_get_boundary(const snd_pcm_sw_params_t* params, + snd_pcm_uframes_t* val) { return 0; } -int snd_pcm_sw_params_set_stop_threshold(snd_pcm_t *pcm, - snd_pcm_sw_params_t *params, +int snd_pcm_sw_params_set_stop_threshold(snd_pcm_t* pcm, + snd_pcm_sw_params_t* params, snd_pcm_uframes_t val) { return 0; } -int snd_pcm_sw_params_set_start_threshold(snd_pcm_t *pcm, - snd_pcm_sw_params_t *params, +int snd_pcm_sw_params_set_start_threshold(snd_pcm_t* pcm, + snd_pcm_sw_params_t* params, snd_pcm_uframes_t val) { return 0; } -int snd_pcm_sw_params_set_period_event(snd_pcm_t *pcm, - snd_pcm_sw_params_t *params, int val) { +int snd_pcm_sw_params_set_period_event(snd_pcm_t* pcm, + snd_pcm_sw_params_t* params, + int val) { return 0; } -int snd_pcm_sw_params_set_tstamp_mode(snd_pcm_t *pcm, - snd_pcm_sw_params_t *params, +int snd_pcm_sw_params_set_tstamp_mode(snd_pcm_t* pcm, + snd_pcm_sw_params_t* params, snd_pcm_tstamp_t val) { snd_pcm_sw_params_set_tstamp_mode_called++; return 0; } -int snd_pcm_sw_params_set_tstamp_type(snd_pcm_t *pcm, - snd_pcm_sw_params_t *params, +int snd_pcm_sw_params_set_tstamp_type(snd_pcm_t* pcm, + snd_pcm_sw_params_t* params, snd_pcm_tstamp_type_t val) { snd_pcm_sw_params_set_tstamp_type_called++; return 0; } -int snd_pcm_sw_params(snd_pcm_t *pcm, snd_pcm_sw_params_t *params) { +int snd_pcm_sw_params(snd_pcm_t* pcm, snd_pcm_sw_params_t* params) { int rc; if (snd_pcm_sw_params_ret_vals.size() == 0) @@ -296,20 +296,20 @@ int snd_pcm_sw_params(snd_pcm_t *pcm, snd_pcm_sw_params_t *params) { return rc; } -snd_pcm_sframes_t snd_pcm_avail(snd_pcm_t *pcm) { +snd_pcm_sframes_t snd_pcm_avail(snd_pcm_t* pcm) { return snd_pcm_htimestamp_avail_ret_val; } -int snd_pcm_htimestamp(snd_pcm_t *pcm, snd_pcm_uframes_t *avail, - snd_htimestamp_t *tstamp) { +int snd_pcm_htimestamp(snd_pcm_t* pcm, + snd_pcm_uframes_t* avail, + snd_htimestamp_t* tstamp) { *avail = snd_pcm_htimestamp_avail_ret_val; *tstamp = snd_pcm_htimestamp_tstamp_ret_val; return 0; } - } -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/alsa_io_unittest.cc b/cras/src/tests/alsa_io_unittest.cc index c6afd704..2211f343 100644 --- a/cras/src/tests/alsa_io_unittest.cc +++ b/cras/src/tests/alsa_io_unittest.cc @@ -3,18 +3,19 @@ // found in the LICENSE file. #include <gtest/gtest.h> -#include <map> #include <stdio.h> #include <syslog.h> + +#include <map> #include <vector> extern "C" { +#include "cras_alsa_mixer.h" #include "cras_iodev.h" #include "cras_shm.h" #include "cras_system_state.h" #include "cras_types.h" -#include "cras_alsa_mixer.h" // Include C file to test static functions. #include "cras_alsa_io.c" @@ -28,23 +29,23 @@ static int cras_iodev_append_stream_ret; static int cras_alsa_get_avail_frames_ret; static int cras_alsa_get_avail_frames_avail; static int cras_alsa_start_called; -static uint8_t *cras_alsa_mmap_begin_buffer; +static uint8_t* cras_alsa_mmap_begin_buffer; static size_t cras_alsa_mmap_begin_frames; static size_t cras_alsa_fill_properties_called; static size_t alsa_mixer_set_dBFS_called; static int alsa_mixer_set_dBFS_value; -static const struct mixer_control *alsa_mixer_set_dBFS_output; +static const struct mixer_control* alsa_mixer_set_dBFS_output; static size_t alsa_mixer_set_capture_dBFS_called; static int alsa_mixer_set_capture_dBFS_value; -static const struct mixer_control *alsa_mixer_set_capture_dBFS_input; -static const struct mixer_control - *cras_alsa_mixer_get_minimum_capture_gain_mixer_input; -static const struct mixer_control - *cras_alsa_mixer_get_maximum_capture_gain_mixer_input; +static const struct mixer_control* alsa_mixer_set_capture_dBFS_input; +static const struct mixer_control* + cras_alsa_mixer_get_minimum_capture_gain_mixer_input; +static const struct mixer_control* + cras_alsa_mixer_get_maximum_capture_gain_mixer_input; static size_t cras_alsa_mixer_list_outputs_called; static size_t cras_alsa_mixer_list_inputs_called; static size_t cras_alsa_mixer_get_control_for_section_called; -static struct mixer_control * +static struct mixer_control* cras_alsa_mixer_get_control_for_section_return_value; static size_t sys_get_volume_called; static size_t sys_get_volume_return_value; @@ -56,31 +57,31 @@ static size_t alsa_mixer_get_dB_range_called; static long alsa_mixer_get_dB_range_value; static size_t alsa_mixer_get_output_dB_range_called; static long alsa_mixer_get_output_dB_range_value; -static const struct mixer_control *alsa_mixer_set_mute_output; +static const struct mixer_control* alsa_mixer_set_mute_output; static size_t alsa_mixer_set_capture_mute_called; static int alsa_mixer_set_capture_mute_value; -static const struct mixer_control *alsa_mixer_set_capture_mute_input; +static const struct mixer_control* alsa_mixer_set_capture_mute_input; static size_t sys_get_mute_called; static int sys_get_mute_return_value; static size_t sys_get_capture_mute_called; static int sys_get_capture_mute_return_value; -static struct cras_alsa_mixer *fake_mixer = (struct cras_alsa_mixer *)1; -static struct cras_card_config *fake_config = (struct cras_card_config *)2; -static struct mixer_control **cras_alsa_mixer_list_outputs_outputs; +static struct cras_alsa_mixer* fake_mixer = (struct cras_alsa_mixer*)1; +static struct cras_card_config* fake_config = (struct cras_card_config*)2; +static struct mixer_control** cras_alsa_mixer_list_outputs_outputs; static size_t cras_alsa_mixer_list_outputs_outputs_length; -static struct mixer_control **cras_alsa_mixer_list_inputs_outputs; +static struct mixer_control** cras_alsa_mixer_list_inputs_outputs; static size_t cras_alsa_mixer_list_inputs_outputs_length; static size_t cras_alsa_mixer_set_output_active_state_called; -static std::vector<struct mixer_control *> +static std::vector<struct mixer_control*> cras_alsa_mixer_set_output_active_state_outputs; static std::vector<int> cras_alsa_mixer_set_output_active_state_values; -static cras_audio_format *fake_format; +static cras_audio_format* fake_format; static size_t sys_set_volume_limits_called; static size_t sys_set_capture_gain_limits_called; static size_t cras_alsa_mixer_get_minimum_capture_gain_called; static size_t cras_alsa_mixer_get_maximum_capture_gain_called; -static struct mixer_control *cras_alsa_jack_get_mixer_output_ret; -static struct mixer_control *cras_alsa_jack_get_mixer_input_ret; +static struct mixer_control* cras_alsa_jack_get_mixer_output_ret; +static struct mixer_control* cras_alsa_jack_get_mixer_input_ret; static size_t cras_alsa_mixer_get_output_volume_curve_called; typedef std::map<const struct mixer_control*, std::string> ControlNameMap; static ControlNameMap cras_alsa_mixer_get_control_name_values; @@ -88,25 +89,25 @@ static size_t cras_alsa_mixer_get_control_name_called; static size_t cras_alsa_jack_list_create_called; static size_t cras_alsa_jack_list_find_jacks_by_name_matching_called; static size_t cras_alsa_jack_list_add_jack_for_section_called; -static struct cras_alsa_jack * +static struct cras_alsa_jack* cras_alsa_jack_list_add_jack_for_section_result_jack; static size_t cras_alsa_jack_list_destroy_called; static int cras_alsa_jack_list_has_hctl_jacks_return_val; -static jack_state_change_callback *cras_alsa_jack_list_create_cb; -static void *cras_alsa_jack_list_create_cb_data; +static jack_state_change_callback* cras_alsa_jack_list_create_cb; +static void* cras_alsa_jack_list_create_cb_data; static char test_card_name[] = "TestCard"; static char test_dev_name[] = "TestDev"; static char test_dev_id[] = "TestDevId"; static size_t cras_iodev_add_node_called; -static struct cras_ionode *cras_iodev_set_node_plugged_ionode; +static struct cras_ionode* cras_iodev_set_node_plugged_ionode; static size_t cras_iodev_set_node_plugged_called; static int cras_iodev_set_node_plugged_value; static unsigned cras_alsa_jack_enable_ucm_called; static unsigned ucm_set_enabled_called; static size_t cras_iodev_update_dsp_called; -static const char *cras_iodev_update_dsp_name; +static const char* cras_iodev_update_dsp_name; static size_t ucm_get_dsp_name_default_called; -static const char *ucm_get_dsp_name_default_value; +static const char* ucm_get_dsp_name_default_value; typedef std::map<const char*, std::string> DspNameMap; static size_t ucm_get_dsp_name_for_dev_called; static DspNameMap ucm_get_dsp_name_for_dev_values; @@ -116,9 +117,9 @@ static int ucm_swap_mode_exists_ret_value; static int ucm_enable_swap_mode_ret_value; static size_t ucm_enable_swap_mode_called; static int is_utf8_string_ret_value; -static const char *cras_alsa_jack_update_monitor_fake_name = 0; +static const char* cras_alsa_jack_update_monitor_fake_name = 0; static int cras_alsa_jack_get_name_called; -static const char *cras_alsa_jack_get_name_ret_value = 0; +static const char* cras_alsa_jack_get_name_ret_value = 0; static char default_jack_name[] = "Something Jack"; static int auto_unplug_input_node_ret = 0; static int auto_unplug_output_node_ret = 0; @@ -133,11 +134,11 @@ static long cras_alsa_mixer_get_minimum_capture_gain_ret_value; static long cras_alsa_mixer_get_maximum_capture_gain_ret_value; static snd_pcm_state_t snd_pcm_state_ret; static int cras_alsa_attempt_resume_called; -static snd_hctl_t *fake_hctl = (snd_hctl_t *)2; +static snd_hctl_t* fake_hctl = (snd_hctl_t*)2; static size_t ucm_get_dma_period_for_dev_called; static unsigned int ucm_get_dma_period_for_dev_ret; static int cras_card_config_get_volume_curve_for_control_called; -typedef std::map<std::string, struct cras_volume_curve *> VolCurveMap; +typedef std::map<std::string, struct cras_volume_curve*> VolCurveMap; static VolCurveMap cras_card_config_get_volume_curve_vals; static int cras_alsa_mmap_get_whole_buffer_called; static int cras_iodev_fill_odev_zeros_called; @@ -147,11 +148,11 @@ static int cras_iodev_buffer_avail_ret; static int cras_alsa_resume_appl_ptr_called; static int cras_alsa_resume_appl_ptr_ahead; static int ucm_get_enable_htimestamp_flag_ret; -static const struct cras_volume_curve *fake_get_dBFS_volume_curve_val; +static const struct cras_volume_curve* fake_get_dBFS_volume_curve_val; static int cras_iodev_dsp_set_swap_mode_for_node_called; static std::map<std::string, long> ucm_get_default_node_gain_values; static thread_callback audio_thread_cb; -static void *audio_thread_cb_data; +static void* audio_thread_cb_data; static int hotword_send_triggered_msg_called; static struct timespec clock_gettime_retspec; @@ -245,159 +246,156 @@ void ResetStubData() { ucm_get_default_node_gain_values.clear(); } -static long fake_get_dBFS(const struct cras_volume_curve *curve, size_t volume) -{ +static long fake_get_dBFS(const struct cras_volume_curve* curve, + size_t volume) { fake_get_dBFS_volume_curve_val = curve; return (volume - 100) * 100; } static cras_volume_curve default_curve = { - .get_dBFS = fake_get_dBFS, + .get_dBFS = fake_get_dBFS, }; -static struct cras_iodev *alsa_iodev_create_with_default_parameters( +static struct cras_iodev* alsa_iodev_create_with_default_parameters( size_t card_index, - const char *dev_id, + const char* dev_id, enum CRAS_ALSA_CARD_TYPE card_type, int is_first, - struct cras_alsa_mixer *mixer, - struct cras_card_config *config, - struct cras_use_case_mgr *ucm, + struct cras_alsa_mixer* mixer, + struct cras_card_config* config, + struct cras_use_case_mgr* ucm, enum CRAS_STREAM_DIRECTION direction) { - return alsa_iodev_create(card_index, test_card_name, 0, test_dev_name, - dev_id, card_type, is_first, - mixer, config, ucm, fake_hctl, - direction, 0, 0, (char *)"123"); + return alsa_iodev_create(card_index, test_card_name, 0, test_dev_name, dev_id, + card_type, is_first, mixer, config, ucm, fake_hctl, + direction, 0, 0, (char*)"123"); } namespace { TEST(AlsaIoInit, InitializeInvalidDirection) { - struct alsa_io *aio; + struct alsa_io* aio; - aio = (struct alsa_io *)alsa_iodev_create_with_default_parameters( + aio = (struct alsa_io*)alsa_iodev_create_with_default_parameters( 0, NULL, ALSA_CARD_TYPE_INTERNAL, 0, fake_mixer, fake_config, NULL, CRAS_NUM_DIRECTIONS); - ASSERT_EQ(aio, (void *)NULL); + ASSERT_EQ(aio, (void*)NULL); } TEST(AlsaIoInit, InitializePlayback) { - struct alsa_io *aio; - struct cras_alsa_mixer * const fake_mixer = (struct cras_alsa_mixer*)2; + struct alsa_io* aio; + struct cras_alsa_mixer* const fake_mixer = (struct cras_alsa_mixer*)2; ResetStubData(); - aio = (struct alsa_io *)alsa_iodev_create_with_default_parameters( + aio = (struct alsa_io*)alsa_iodev_create_with_default_parameters( 0, test_dev_id, ALSA_CARD_TYPE_INTERNAL, 1, fake_mixer, fake_config, NULL, CRAS_STREAM_OUTPUT); - ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev *)aio)); + ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev*)aio)); /* Get volume curve twice for iodev, and default node. */ EXPECT_EQ(2, cras_card_config_get_volume_curve_for_control_called); EXPECT_EQ(SND_PCM_STREAM_PLAYBACK, aio->alsa_stream); EXPECT_EQ(0, cras_alsa_fill_properties_called); EXPECT_EQ(1, cras_alsa_mixer_list_outputs_called); - EXPECT_EQ(0, strncmp(test_card_name, - aio->base.info.name, - strlen(test_card_name))); + EXPECT_EQ( + 0, strncmp(test_card_name, aio->base.info.name, strlen(test_card_name))); EXPECT_EQ(0, ucm_get_dsp_name_default_called); EXPECT_EQ(NULL, cras_iodev_update_dsp_name); - ASSERT_NE(reinterpret_cast<const char *>(NULL), aio->dev_name); + ASSERT_NE(reinterpret_cast<const char*>(NULL), aio->dev_name); EXPECT_EQ(0, strcmp(test_dev_name, aio->dev_name)); - ASSERT_NE(reinterpret_cast<const char *>(NULL), aio->dev_id); + ASSERT_NE(reinterpret_cast<const char*>(NULL), aio->dev_id); EXPECT_EQ(0, strcmp(test_dev_id, aio->dev_id)); - alsa_iodev_destroy((struct cras_iodev *)aio); + alsa_iodev_destroy((struct cras_iodev*)aio); EXPECT_EQ(1, cras_iodev_free_resources_called); } TEST(AlsaIoInit, DefaultNodeInternalCard) { - struct alsa_io *aio; - struct cras_alsa_mixer * const fake_mixer = (struct cras_alsa_mixer*)2; + struct alsa_io* aio; + struct cras_alsa_mixer* const fake_mixer = (struct cras_alsa_mixer*)2; ResetStubData(); - aio = (struct alsa_io *)alsa_iodev_create_with_default_parameters( + aio = (struct alsa_io*)alsa_iodev_create_with_default_parameters( 0, NULL, ALSA_CARD_TYPE_INTERNAL, 0, fake_mixer, fake_config, NULL, CRAS_STREAM_OUTPUT); - ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev *)aio)); + ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev*)aio)); EXPECT_EQ(2, cras_card_config_get_volume_curve_for_control_called); ASSERT_STREQ(DEFAULT, aio->base.active_node->name); ASSERT_EQ(1, aio->base.active_node->plugged); - ASSERT_EQ((void *)no_stream, (void *)aio->base.no_stream); - ASSERT_EQ((void *)is_free_running, (void *)aio->base.is_free_running); - alsa_iodev_destroy((struct cras_iodev *)aio); + ASSERT_EQ((void*)no_stream, (void*)aio->base.no_stream); + ASSERT_EQ((void*)is_free_running, (void*)aio->base.is_free_running); + alsa_iodev_destroy((struct cras_iodev*)aio); - aio = (struct alsa_io *)alsa_iodev_create_with_default_parameters( + aio = (struct alsa_io*)alsa_iodev_create_with_default_parameters( 0, NULL, ALSA_CARD_TYPE_INTERNAL, 1, fake_mixer, fake_config, NULL, CRAS_STREAM_OUTPUT); - ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev *)aio)); + ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev*)aio)); EXPECT_EQ(4, cras_card_config_get_volume_curve_for_control_called); ASSERT_STREQ(INTERNAL_SPEAKER, aio->base.active_node->name); ASSERT_EQ(1, aio->base.active_node->plugged); - ASSERT_EQ((void *)no_stream, (void *)aio->base.no_stream); - ASSERT_EQ((void *)is_free_running, (void *)aio->base.is_free_running); - alsa_iodev_destroy((struct cras_iodev *)aio); + ASSERT_EQ((void*)no_stream, (void*)aio->base.no_stream); + ASSERT_EQ((void*)is_free_running, (void*)aio->base.is_free_running); + alsa_iodev_destroy((struct cras_iodev*)aio); - aio = (struct alsa_io *)alsa_iodev_create_with_default_parameters( + aio = (struct alsa_io*)alsa_iodev_create_with_default_parameters( 0, NULL, ALSA_CARD_TYPE_INTERNAL, 0, fake_mixer, fake_config, NULL, CRAS_STREAM_INPUT); - ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev *)aio)); + ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev*)aio)); /* No more call to get volume curve for input device. */ EXPECT_EQ(4, cras_card_config_get_volume_curve_for_control_called); ASSERT_STREQ(DEFAULT, aio->base.active_node->name); ASSERT_EQ(1, aio->base.active_node->plugged); - ASSERT_EQ((void *)no_stream, (void *)aio->base.no_stream); - ASSERT_EQ((void *)is_free_running, (void *)aio->base.is_free_running); - alsa_iodev_destroy((struct cras_iodev *)aio); + ASSERT_EQ((void*)no_stream, (void*)aio->base.no_stream); + ASSERT_EQ((void*)is_free_running, (void*)aio->base.is_free_running); + alsa_iodev_destroy((struct cras_iodev*)aio); - aio = (struct alsa_io *)alsa_iodev_create_with_default_parameters( + aio = (struct alsa_io*)alsa_iodev_create_with_default_parameters( 0, NULL, ALSA_CARD_TYPE_INTERNAL, 1, fake_mixer, fake_config, NULL, CRAS_STREAM_INPUT); - ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev *)aio)); + ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev*)aio)); EXPECT_EQ(4, cras_card_config_get_volume_curve_for_control_called); ASSERT_STREQ(INTERNAL_MICROPHONE, aio->base.active_node->name); ASSERT_EQ(1, aio->base.active_node->plugged); - ASSERT_EQ((void *)no_stream, (void *)aio->base.no_stream); - ASSERT_EQ((void *)is_free_running, (void *)aio->base.is_free_running); - alsa_iodev_destroy((struct cras_iodev *)aio); + ASSERT_EQ((void*)no_stream, (void*)aio->base.no_stream); + ASSERT_EQ((void*)is_free_running, (void*)aio->base.is_free_running); + alsa_iodev_destroy((struct cras_iodev*)aio); } TEST(AlsaIoInit, DefaultNodeUSBCard) { - struct alsa_io *aio; - struct cras_alsa_mixer * const fake_mixer = (struct cras_alsa_mixer*)2; + struct alsa_io* aio; + struct cras_alsa_mixer* const fake_mixer = (struct cras_alsa_mixer*)2; ResetStubData(); - aio = (struct alsa_io *)alsa_iodev_create_with_default_parameters( + aio = (struct alsa_io*)alsa_iodev_create_with_default_parameters( 0, NULL, ALSA_CARD_TYPE_USB, 1, fake_mixer, fake_config, NULL, CRAS_STREAM_OUTPUT); - ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev *)aio)); + ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev*)aio)); EXPECT_EQ(2, cras_card_config_get_volume_curve_for_control_called); ASSERT_STREQ(DEFAULT, aio->base.active_node->name); ASSERT_EQ(1, aio->base.active_node->plugged); EXPECT_EQ(1, cras_iodev_set_node_plugged_called); - alsa_iodev_destroy((struct cras_iodev *)aio); + alsa_iodev_destroy((struct cras_iodev*)aio); - aio = (struct alsa_io *)alsa_iodev_create_with_default_parameters( + aio = (struct alsa_io*)alsa_iodev_create_with_default_parameters( 0, NULL, ALSA_CARD_TYPE_USB, 1, fake_mixer, fake_config, NULL, CRAS_STREAM_INPUT); - ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev *)aio)); + ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev*)aio)); EXPECT_EQ(2, cras_card_config_get_volume_curve_for_control_called); ASSERT_STREQ(DEFAULT, aio->base.active_node->name); ASSERT_EQ(1, aio->base.active_node->plugged); EXPECT_EQ(2, cras_iodev_set_node_plugged_called); - alsa_iodev_destroy((struct cras_iodev *)aio); + alsa_iodev_destroy((struct cras_iodev*)aio); } TEST(AlsaIoInit, OpenPlayback) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; struct cras_audio_format format; - struct alsa_io *aio; + struct alsa_io* aio; ResetStubData(); - iodev = alsa_iodev_create_with_default_parameters(0, NULL, - ALSA_CARD_TYPE_INTERNAL, 0, - fake_mixer, fake_config, - NULL, CRAS_STREAM_OUTPUT); + iodev = alsa_iodev_create_with_default_parameters( + 0, NULL, ALSA_CARD_TYPE_INTERNAL, 0, fake_mixer, fake_config, NULL, + CRAS_STREAM_OUTPUT); ASSERT_EQ(0, alsa_iodev_legacy_complete_init(iodev)); EXPECT_EQ(2, cras_card_config_get_volume_curve_for_control_called); - aio = (struct alsa_io *)iodev; + aio = (struct alsa_io*)iodev; format.frame_rate = 48000; format.num_channels = 1; cras_iodev_set_format(iodev, &format); @@ -423,13 +421,12 @@ TEST(AlsaIoInit, OpenPlayback) { } TEST(AlsaIoInit, UsbCardAutoPlug) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; ResetStubData(); - iodev = alsa_iodev_create_with_default_parameters(0, NULL, - ALSA_CARD_TYPE_INTERNAL, 1, - fake_mixer, fake_config, - NULL, CRAS_STREAM_OUTPUT); + iodev = alsa_iodev_create_with_default_parameters( + 0, NULL, ALSA_CARD_TYPE_INTERNAL, 1, fake_mixer, fake_config, NULL, + CRAS_STREAM_OUTPUT); ASSERT_EQ(0, alsa_iodev_legacy_complete_init(iodev)); EXPECT_EQ(2, cras_card_config_get_volume_curve_for_control_called); EXPECT_EQ(0, cras_iodev_set_node_plugged_called); @@ -457,7 +454,7 @@ TEST(AlsaIoInit, UsbCardAutoPlug) { } TEST(AlsaIoInit, UsbCardUseSoftwareVolume) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; alsa_mixer_get_dB_range_value = 1000; alsa_mixer_get_output_dB_range_value = 1000; @@ -487,8 +484,8 @@ TEST(AlsaIoInit, UsbCardUseSoftwareVolume) { } TEST(AlsaIoInit, UseSoftwareGain) { - struct cras_iodev *iodev; - struct cras_use_case_mgr * const fake_ucm = (struct cras_use_case_mgr*)3; + struct cras_iodev* iodev; + struct cras_use_case_mgr* const fake_ucm = (struct cras_use_case_mgr*)3; /* MaxSoftwareGain is specified in UCM */ ResetStubData(); @@ -496,11 +493,9 @@ TEST(AlsaIoInit, UseSoftwareGain) { ucm_get_min_software_gain_value = 1; ucm_get_max_software_gain_ret_value = 0; ucm_get_max_software_gain_value = 2000; - iodev = alsa_iodev_create_with_default_parameters(0, NULL, - ALSA_CARD_TYPE_INTERNAL, 1, - fake_mixer, fake_config, - fake_ucm, - CRAS_STREAM_INPUT); + iodev = alsa_iodev_create_with_default_parameters( + 0, NULL, ALSA_CARD_TYPE_INTERNAL, 1, fake_mixer, fake_config, fake_ucm, + CRAS_STREAM_INPUT); ASSERT_EQ(0, alsa_iodev_legacy_complete_init(iodev)); EXPECT_EQ(1, iodev->active_node->software_volume_needed); EXPECT_EQ(DEFAULT_MIN_CAPTURE_GAIN, iodev->active_node->min_software_gain); @@ -508,7 +503,7 @@ TEST(AlsaIoInit, UseSoftwareGain) { ASSERT_EQ(1, sys_set_capture_gain_limits_called); /* The gain range is [DEFAULT_MIN_CAPTURE_GAIN, maximum software gain]. */ ASSERT_EQ(cras_system_set_capture_gain_limits_set_value[0], - DEFAULT_MIN_CAPTURE_GAIN); + DEFAULT_MIN_CAPTURE_GAIN); ASSERT_EQ(cras_system_set_capture_gain_limits_set_value[1], 2000); alsa_iodev_destroy(iodev); @@ -519,11 +514,9 @@ TEST(AlsaIoInit, UseSoftwareGain) { ucm_get_min_software_gain_value = 1000; ucm_get_max_software_gain_ret_value = 0; ucm_get_max_software_gain_value = 2000; - iodev = alsa_iodev_create_with_default_parameters(0, NULL, - ALSA_CARD_TYPE_INTERNAL, 1, - fake_mixer, fake_config, - fake_ucm, - CRAS_STREAM_INPUT); + iodev = alsa_iodev_create_with_default_parameters( + 0, NULL, ALSA_CARD_TYPE_INTERNAL, 1, fake_mixer, fake_config, fake_ucm, + CRAS_STREAM_INPUT); ASSERT_EQ(0, alsa_iodev_legacy_complete_init(iodev)); EXPECT_EQ(1, iodev->active_node->software_volume_needed); EXPECT_EQ(1000, iodev->active_node->min_software_gain); @@ -541,11 +534,9 @@ TEST(AlsaIoInit, UseSoftwareGain) { ucm_get_min_software_gain_value = 3000; ucm_get_max_software_gain_ret_value = 0; ucm_get_max_software_gain_value = 2000; - iodev = alsa_iodev_create_with_default_parameters(0, NULL, - ALSA_CARD_TYPE_INTERNAL, 1, - fake_mixer, fake_config, - fake_ucm, - CRAS_STREAM_INPUT); + iodev = alsa_iodev_create_with_default_parameters( + 0, NULL, ALSA_CARD_TYPE_INTERNAL, 1, fake_mixer, fake_config, fake_ucm, + CRAS_STREAM_INPUT); ASSERT_EQ(0, alsa_iodev_legacy_complete_init(iodev)); EXPECT_EQ(1, iodev->active_node->software_volume_needed); EXPECT_EQ(DEFAULT_MIN_CAPTURE_GAIN, iodev->active_node->min_software_gain); @@ -553,7 +544,7 @@ TEST(AlsaIoInit, UseSoftwareGain) { ASSERT_EQ(1, sys_set_capture_gain_limits_called); /* The gain range is [DEFAULT_MIN_CAPTURE_GAIN, maximum software gain]. */ ASSERT_EQ(cras_system_set_capture_gain_limits_set_value[0], - DEFAULT_MIN_CAPTURE_GAIN); + DEFAULT_MIN_CAPTURE_GAIN); ASSERT_EQ(cras_system_set_capture_gain_limits_set_value[1], 2000); alsa_iodev_destroy(iodev); @@ -564,11 +555,9 @@ TEST(AlsaIoInit, UseSoftwareGain) { ucm_get_max_software_gain_value = 1; cras_alsa_mixer_get_minimum_capture_gain_ret_value = -500; cras_alsa_mixer_get_maximum_capture_gain_ret_value = 500; - iodev = alsa_iodev_create_with_default_parameters(0, NULL, - ALSA_CARD_TYPE_INTERNAL, 1, - fake_mixer, fake_config, - fake_ucm, - CRAS_STREAM_INPUT); + iodev = alsa_iodev_create_with_default_parameters( + 0, NULL, ALSA_CARD_TYPE_INTERNAL, 1, fake_mixer, fake_config, fake_ucm, + CRAS_STREAM_INPUT); ASSERT_EQ(0, alsa_iodev_legacy_complete_init(iodev)); EXPECT_EQ(0, iodev->active_node->software_volume_needed); EXPECT_EQ(0, iodev->active_node->max_software_gain); @@ -581,8 +570,8 @@ TEST(AlsaIoInit, UseSoftwareGain) { } TEST(AlsaIoInit, SoftwareGainWithDefaultNodeGain) { - struct cras_iodev *iodev; - struct cras_use_case_mgr * const fake_ucm = (struct cras_use_case_mgr*)3; + struct cras_iodev* iodev; + struct cras_use_case_mgr* const fake_ucm = (struct cras_use_case_mgr*)3; long system_gain = 500; long default_node_gain = -1000; @@ -596,11 +585,9 @@ TEST(AlsaIoInit, SoftwareGainWithDefaultNodeGain) { ucm_get_default_node_gain_values[INTERNAL_MICROPHONE] = default_node_gain; // Assume this is the first device so it gets internal mic node name. - iodev = alsa_iodev_create_with_default_parameters(0, NULL, - ALSA_CARD_TYPE_INTERNAL, 1, - fake_mixer, fake_config, - fake_ucm, - CRAS_STREAM_INPUT); + iodev = alsa_iodev_create_with_default_parameters( + 0, NULL, ALSA_CARD_TYPE_INTERNAL, 1, fake_mixer, fake_config, fake_ucm, + CRAS_STREAM_INPUT); ASSERT_EQ(0, alsa_iodev_legacy_complete_init(iodev)); // Gain on node is 300 * 0.01 dB. @@ -615,15 +602,15 @@ TEST(AlsaIoInit, SoftwareGainWithDefaultNodeGain) { } TEST(AlsaIoInit, RouteBasedOnJackCallback) { - struct alsa_io *aio; - struct cras_alsa_mixer * const fake_mixer = (struct cras_alsa_mixer*)2; + struct alsa_io* aio; + struct cras_alsa_mixer* const fake_mixer = (struct cras_alsa_mixer*)2; ResetStubData(); - aio = (struct alsa_io *)alsa_iodev_create_with_default_parameters( + aio = (struct alsa_io*)alsa_iodev_create_with_default_parameters( 0, NULL, ALSA_CARD_TYPE_INTERNAL, 1, fake_mixer, fake_config, NULL, CRAS_STREAM_OUTPUT); - ASSERT_NE(aio, (void *)NULL); - ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev *)aio)); + ASSERT_NE(aio, (void*)NULL); + ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev*)aio)); EXPECT_EQ(2, cras_card_config_get_volume_curve_for_control_called); EXPECT_EQ(SND_PCM_STREAM_PLAYBACK, aio->alsa_stream); EXPECT_EQ(0, cras_alsa_fill_properties_called); @@ -639,20 +626,20 @@ TEST(AlsaIoInit, RouteBasedOnJackCallback) { EXPECT_EQ(2, cras_iodev_set_node_plugged_called); EXPECT_EQ(0, cras_iodev_set_node_plugged_value); - alsa_iodev_destroy((struct cras_iodev *)aio); + alsa_iodev_destroy((struct cras_iodev*)aio); EXPECT_EQ(1, cras_alsa_jack_list_destroy_called); } TEST(AlsaIoInit, RouteBasedOnInputJackCallback) { - struct alsa_io *aio; - struct cras_alsa_mixer * const fake_mixer = (struct cras_alsa_mixer*)2; + struct alsa_io* aio; + struct cras_alsa_mixer* const fake_mixer = (struct cras_alsa_mixer*)2; ResetStubData(); - aio = (struct alsa_io *)alsa_iodev_create_with_default_parameters( + aio = (struct alsa_io*)alsa_iodev_create_with_default_parameters( 0, NULL, ALSA_CARD_TYPE_INTERNAL, 0, fake_mixer, fake_config, NULL, CRAS_STREAM_INPUT); - ASSERT_NE(aio, (void *)NULL); - ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev *)aio)); + ASSERT_NE(aio, (void*)NULL); + ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev*)aio)); EXPECT_EQ(SND_PCM_STREAM_CAPTURE, aio->alsa_stream); EXPECT_EQ(0, cras_alsa_fill_properties_called); @@ -667,39 +654,38 @@ TEST(AlsaIoInit, RouteBasedOnInputJackCallback) { EXPECT_EQ(2, cras_iodev_set_node_plugged_called); EXPECT_EQ(0, cras_iodev_set_node_plugged_value); - alsa_iodev_destroy((struct cras_iodev *)aio); + alsa_iodev_destroy((struct cras_iodev*)aio); EXPECT_EQ(1, cras_alsa_jack_list_destroy_called); } TEST(AlsaIoInit, InitializeCapture) { - struct alsa_io *aio; + struct alsa_io* aio; ResetStubData(); - aio = (struct alsa_io *)alsa_iodev_create_with_default_parameters( + aio = (struct alsa_io*)alsa_iodev_create_with_default_parameters( 0, NULL, ALSA_CARD_TYPE_INTERNAL, 1, fake_mixer, fake_config, NULL, CRAS_STREAM_INPUT); - ASSERT_NE(aio, (void *)NULL); - ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev *)aio)); + ASSERT_NE(aio, (void*)NULL); + ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev*)aio)); EXPECT_EQ(SND_PCM_STREAM_CAPTURE, aio->alsa_stream); EXPECT_EQ(0, cras_alsa_fill_properties_called); EXPECT_EQ(1, cras_alsa_mixer_list_inputs_called); - alsa_iodev_destroy((struct cras_iodev *)aio); + alsa_iodev_destroy((struct cras_iodev*)aio); } TEST(AlsaIoInit, OpenCapture) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; struct cras_audio_format format; - struct alsa_io *aio; + struct alsa_io* aio; - iodev = alsa_iodev_create_with_default_parameters(0, NULL, - ALSA_CARD_TYPE_INTERNAL, 0, - fake_mixer, fake_config, - NULL, CRAS_STREAM_INPUT); + iodev = alsa_iodev_create_with_default_parameters( + 0, NULL, ALSA_CARD_TYPE_INTERNAL, 0, fake_mixer, fake_config, NULL, + CRAS_STREAM_INPUT); ASSERT_EQ(0, alsa_iodev_legacy_complete_init(iodev)); - aio = (struct alsa_io *)iodev; + aio = (struct alsa_io*)iodev; format.frame_rate = 48000; format.num_channels = 1; cras_iodev_set_format(iodev, &format); @@ -725,9 +711,9 @@ TEST(AlsaIoInit, OpenCapture) { } TEST(AlsaIoInit, OpenCaptureSetCaptureGainWithDefaultNodeGain) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; struct cras_audio_format format; - struct cras_use_case_mgr * const fake_ucm = (struct cras_use_case_mgr*)3; + struct cras_use_case_mgr* const fake_ucm = (struct cras_use_case_mgr*)3; long system_gain = 2000; long default_node_gain = -1000; @@ -736,11 +722,9 @@ TEST(AlsaIoInit, OpenCaptureSetCaptureGainWithDefaultNodeGain) { ucm_get_default_node_gain_values[INTERNAL_MICROPHONE] = default_node_gain; // Assume this is the first device so it gets internal mic node name. - iodev = alsa_iodev_create_with_default_parameters(0, NULL, - ALSA_CARD_TYPE_INTERNAL, 1, - fake_mixer, fake_config, - fake_ucm, - CRAS_STREAM_INPUT); + iodev = alsa_iodev_create_with_default_parameters( + 0, NULL, ALSA_CARD_TYPE_INTERNAL, 1, fake_mixer, fake_config, fake_ucm, + CRAS_STREAM_INPUT); ASSERT_EQ(0, alsa_iodev_legacy_complete_init(iodev)); cras_iodev_set_format(iodev, &format); @@ -762,20 +746,18 @@ TEST(AlsaIoInit, OpenCaptureSetCaptureGainWithDefaultNodeGain) { } TEST(AlsaIoInit, OpenCaptureSetCaptureGainWithSoftwareGain) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; struct cras_audio_format format; - struct cras_use_case_mgr * const fake_ucm = (struct cras_use_case_mgr*)3; + struct cras_use_case_mgr* const fake_ucm = (struct cras_use_case_mgr*)3; /* Meet the requirements of using software gain. */ ResetStubData(); ucm_get_max_software_gain_ret_value = 0; ucm_get_max_software_gain_value = 2000; - iodev = alsa_iodev_create_with_default_parameters(0, NULL, - ALSA_CARD_TYPE_INTERNAL, 0, - fake_mixer, fake_config, - fake_ucm, - CRAS_STREAM_INPUT); + iodev = alsa_iodev_create_with_default_parameters( + 0, NULL, ALSA_CARD_TYPE_INTERNAL, 0, fake_mixer, fake_config, fake_ucm, + CRAS_STREAM_INPUT); ASSERT_EQ(0, alsa_iodev_legacy_complete_init(iodev)); format.frame_rate = 48000; @@ -806,15 +788,13 @@ TEST(AlsaIoInit, OpenCaptureSetCaptureGainWithSoftwareGain) { } TEST(AlsaIoInit, UpdateActiveNode) { - struct cras_iodev *iodev; - struct cras_alsa_mixer * const fake_mixer = (struct cras_alsa_mixer*)2; + struct cras_iodev* iodev; + struct cras_alsa_mixer* const fake_mixer = (struct cras_alsa_mixer*)2; ResetStubData(); - iodev = alsa_iodev_create_with_default_parameters(0, NULL, - ALSA_CARD_TYPE_INTERNAL, 0, - fake_mixer, fake_config, - NULL, - CRAS_STREAM_OUTPUT); + iodev = alsa_iodev_create_with_default_parameters( + 0, NULL, ALSA_CARD_TYPE_INTERNAL, 0, fake_mixer, fake_config, NULL, + CRAS_STREAM_OUTPUT); ASSERT_EQ(0, alsa_iodev_legacy_complete_init(iodev)); EXPECT_EQ(2, cras_card_config_get_volume_curve_for_control_called); @@ -824,14 +804,13 @@ TEST(AlsaIoInit, UpdateActiveNode) { } TEST(AlsaIoInit, StartDevice) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; int rc; ResetStubData(); - iodev = alsa_iodev_create_with_default_parameters(0, NULL, - ALSA_CARD_TYPE_INTERNAL, 0, - NULL, fake_config, NULL, - CRAS_STREAM_OUTPUT); + iodev = alsa_iodev_create_with_default_parameters( + 0, NULL, ALSA_CARD_TYPE_INTERNAL, 0, NULL, fake_config, NULL, + CRAS_STREAM_OUTPUT); ASSERT_EQ(0, alsa_iodev_legacy_complete_init(iodev)); EXPECT_EQ(2, cras_card_config_get_volume_curve_for_control_called); @@ -851,14 +830,13 @@ TEST(AlsaIoInit, StartDevice) { } TEST(AlsaIoInit, ResumeDevice) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; int rc; ResetStubData(); - iodev = alsa_iodev_create_with_default_parameters(0, NULL, - ALSA_CARD_TYPE_INTERNAL, 0, - NULL, fake_config, NULL, - CRAS_STREAM_OUTPUT); + iodev = alsa_iodev_create_with_default_parameters( + 0, NULL, ALSA_CARD_TYPE_INTERNAL, 0, NULL, fake_config, NULL, + CRAS_STREAM_OUTPUT); ASSERT_EQ(0, alsa_iodev_legacy_complete_init(iodev)); EXPECT_EQ(2, cras_card_config_get_volume_curve_for_control_called); @@ -872,59 +850,59 @@ TEST(AlsaIoInit, ResumeDevice) { } TEST(AlsaIoInit, DspNameDefault) { - struct alsa_io *aio; - struct cras_alsa_mixer * const fake_mixer = (struct cras_alsa_mixer*)2; - struct cras_use_case_mgr * const fake_ucm = (struct cras_use_case_mgr*)3; + struct alsa_io* aio; + struct cras_alsa_mixer* const fake_mixer = (struct cras_alsa_mixer*)2; + struct cras_use_case_mgr* const fake_ucm = (struct cras_use_case_mgr*)3; ResetStubData(); ucm_get_dsp_name_default_value = "hello"; - aio = (struct alsa_io *)alsa_iodev_create_with_default_parameters( + aio = (struct alsa_io*)alsa_iodev_create_with_default_parameters( 0, NULL, ALSA_CARD_TYPE_INTERNAL, 0, fake_mixer, fake_config, fake_ucm, CRAS_STREAM_OUTPUT); - ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev *)aio)); + ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev*)aio)); EXPECT_EQ(2, cras_card_config_get_volume_curve_for_control_called); EXPECT_EQ(SND_PCM_STREAM_PLAYBACK, aio->alsa_stream); EXPECT_EQ(1, ucm_get_dsp_name_for_dev_called); EXPECT_EQ(1, ucm_get_dsp_name_default_called); EXPECT_STREQ("hello", cras_iodev_update_dsp_name); - alsa_iodev_destroy((struct cras_iodev *)aio); + alsa_iodev_destroy((struct cras_iodev*)aio); } TEST(AlsaIoInit, DspNameWithoutDefault) { - struct alsa_io *aio; - struct cras_alsa_mixer * const fake_mixer = (struct cras_alsa_mixer*)2; - struct cras_use_case_mgr * const fake_ucm = (struct cras_use_case_mgr*)3; + struct alsa_io* aio; + struct cras_alsa_mixer* const fake_mixer = (struct cras_alsa_mixer*)2; + struct cras_use_case_mgr* const fake_ucm = (struct cras_use_case_mgr*)3; ResetStubData(); ucm_get_dsp_name_default_value = NULL; ucm_get_dsp_name_for_dev_values[DEFAULT] = "hello"; - aio = (struct alsa_io *)alsa_iodev_create_with_default_parameters( + aio = (struct alsa_io*)alsa_iodev_create_with_default_parameters( 0, NULL, ALSA_CARD_TYPE_INTERNAL, 0, fake_mixer, fake_config, fake_ucm, CRAS_STREAM_OUTPUT); - ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev *)aio)); + ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev*)aio)); EXPECT_EQ(2, cras_card_config_get_volume_curve_for_control_called); EXPECT_EQ(SND_PCM_STREAM_PLAYBACK, aio->alsa_stream); EXPECT_EQ(1, ucm_get_dsp_name_for_dev_called); EXPECT_EQ(1, ucm_get_dsp_name_default_called); EXPECT_STREQ("hello", cras_iodev_update_dsp_name); - alsa_iodev_destroy((struct cras_iodev *)aio); + alsa_iodev_destroy((struct cras_iodev*)aio); } TEST(AlsaIoInit, DspNameJackOverride) { - struct alsa_io *aio; - struct cras_alsa_mixer * const fake_mixer = (struct cras_alsa_mixer*)2; - struct cras_use_case_mgr * const fake_ucm = (struct cras_use_case_mgr*)3; - const struct cras_alsa_jack *jack = (struct cras_alsa_jack*)4; - static const char *jack_name = "jack"; + struct alsa_io* aio; + struct cras_alsa_mixer* const fake_mixer = (struct cras_alsa_mixer*)2; + struct cras_use_case_mgr* const fake_ucm = (struct cras_use_case_mgr*)3; + const struct cras_alsa_jack* jack = (struct cras_alsa_jack*)4; + static const char* jack_name = "jack"; ResetStubData(); ucm_get_dsp_name_default_value = "default_dsp"; - aio = (struct alsa_io *)alsa_iodev_create_with_default_parameters( + aio = (struct alsa_io*)alsa_iodev_create_with_default_parameters( 0, NULL, ALSA_CARD_TYPE_INTERNAL, 0, fake_mixer, fake_config, fake_ucm, CRAS_STREAM_OUTPUT); - ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev *)aio)); + ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev*)aio)); EXPECT_EQ(SND_PCM_STREAM_PLAYBACK, aio->alsa_stream); EXPECT_EQ(1, ucm_get_dsp_name_for_dev_called); EXPECT_EQ(1, ucm_get_dsp_name_default_called); @@ -952,43 +930,43 @@ TEST(AlsaIoInit, DspNameJackOverride) { EXPECT_EQ(3, cras_iodev_update_dsp_called); EXPECT_STREQ("default_dsp", cras_iodev_update_dsp_name); - alsa_iodev_destroy((struct cras_iodev *)aio); + alsa_iodev_destroy((struct cras_iodev*)aio); } TEST(AlsaIoInit, NodeTypeOverride) { - struct alsa_io *aio; - struct cras_alsa_mixer * const fake_mixer = (struct cras_alsa_mixer*)2; - struct cras_use_case_mgr * const fake_ucm = (struct cras_use_case_mgr*)3; - const struct cras_alsa_jack *jack = (struct cras_alsa_jack*)4; + struct alsa_io* aio; + struct cras_alsa_mixer* const fake_mixer = (struct cras_alsa_mixer*)2; + struct cras_use_case_mgr* const fake_ucm = (struct cras_use_case_mgr*)3; + const struct cras_alsa_jack* jack = (struct cras_alsa_jack*)4; ResetStubData(); - aio = (struct alsa_io *)alsa_iodev_create_with_default_parameters( + aio = (struct alsa_io*)alsa_iodev_create_with_default_parameters( 0, NULL, ALSA_CARD_TYPE_INTERNAL, 0, fake_mixer, fake_config, fake_ucm, CRAS_STREAM_OUTPUT); - ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev *)aio)); + ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev*)aio)); // Add the jack node. cras_alsa_jack_list_create_cb(jack, 1, cras_alsa_jack_list_create_cb_data); // Verify that cras_alsa_jack_update_node_type is called when an output device // is created. EXPECT_EQ(1, cras_alsa_jack_update_node_type_called); - alsa_iodev_destroy((struct cras_iodev *)aio); + alsa_iodev_destroy((struct cras_iodev*)aio); } TEST(AlsaIoInit, SwapMode) { - struct alsa_io *aio; - struct cras_alsa_mixer * const fake_mixer = (struct cras_alsa_mixer*)2; - struct cras_use_case_mgr * const fake_ucm = (struct cras_use_case_mgr*)3; - struct cras_ionode * const fake_node = (cras_ionode *)calloc( - 1, sizeof(struct cras_ionode)); + struct alsa_io* aio; + struct cras_alsa_mixer* const fake_mixer = (struct cras_alsa_mixer*)2; + struct cras_use_case_mgr* const fake_ucm = (struct cras_use_case_mgr*)3; + struct cras_ionode* const fake_node = + (cras_ionode*)calloc(1, sizeof(struct cras_ionode)); ResetStubData(); // Stub replies that swap mode does not exist. ucm_swap_mode_exists_ret_value = 0; - aio = (struct alsa_io *)alsa_iodev_create_with_default_parameters( + aio = (struct alsa_io*)alsa_iodev_create_with_default_parameters( 0, NULL, ALSA_CARD_TYPE_INTERNAL, 0, fake_mixer, fake_config, fake_ucm, CRAS_STREAM_OUTPUT); - ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev *)aio)); + ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev*)aio)); aio->base.set_swap_mode_for_node((cras_iodev*)aio, fake_node, 1); /* Swap mode is implemented by dsp. */ @@ -996,12 +974,12 @@ TEST(AlsaIoInit, SwapMode) { // Stub replies that swap mode exists. ucm_swap_mode_exists_ret_value = 1; - alsa_iodev_destroy((struct cras_iodev *)aio); + alsa_iodev_destroy((struct cras_iodev*)aio); - aio = (struct alsa_io *)alsa_iodev_create_with_default_parameters( + aio = (struct alsa_io*)alsa_iodev_create_with_default_parameters( 0, NULL, ALSA_CARD_TYPE_INTERNAL, 0, fake_mixer, fake_config, fake_ucm, CRAS_STREAM_OUTPUT); - ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev *)aio)); + ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev*)aio)); // Enable swap mode. aio->base.set_swap_mode_for_node((cras_iodev*)aio, fake_node, 1); @@ -1009,33 +987,33 @@ TEST(AlsaIoInit, SwapMode) { // swap mode is called. EXPECT_EQ(1, ucm_enable_swap_mode_called); - alsa_iodev_destroy((struct cras_iodev *)aio); + alsa_iodev_destroy((struct cras_iodev*)aio); free(fake_node); } // Test that system settins aren't touched if no streams active. TEST(AlsaOutputNode, SystemSettingsWhenInactive) { int rc; - struct alsa_io *aio; - struct cras_alsa_mixer * const fake_mixer = (struct cras_alsa_mixer*)2; - struct mixer_control *outputs[2]; + struct alsa_io* aio; + struct cras_alsa_mixer* const fake_mixer = (struct cras_alsa_mixer*)2; + struct mixer_control* outputs[2]; ResetStubData(); - outputs[0] = reinterpret_cast<struct mixer_control *>(3); - outputs[1] = reinterpret_cast<struct mixer_control *>(4); + outputs[0] = reinterpret_cast<struct mixer_control*>(3); + outputs[1] = reinterpret_cast<struct mixer_control*>(4); cras_alsa_mixer_list_outputs_outputs = outputs; cras_alsa_mixer_list_outputs_outputs_length = ARRAY_SIZE(outputs); - aio = (struct alsa_io *)alsa_iodev_create_with_default_parameters( + aio = (struct alsa_io*)alsa_iodev_create_with_default_parameters( 0, NULL, ALSA_CARD_TYPE_INTERNAL, 1, fake_mixer, fake_config, NULL, CRAS_STREAM_OUTPUT); - ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev *)aio)); + ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev*)aio)); /* Two mixer controls calls get volume curve. */ EXPECT_EQ(4, cras_card_config_get_volume_curve_for_control_called); EXPECT_EQ(SND_PCM_STREAM_PLAYBACK, aio->alsa_stream); EXPECT_EQ(1, cras_alsa_mixer_list_outputs_called); ResetStubData(); - rc = alsa_iodev_set_active_node((struct cras_iodev *)aio, + rc = alsa_iodev_set_active_node((struct cras_iodev*)aio, aio->base.nodes->next, 1); EXPECT_EQ(0, rc); EXPECT_EQ(0, alsa_mixer_set_mute_called); @@ -1050,33 +1028,33 @@ TEST(AlsaOutputNode, SystemSettingsWhenInactive) { EXPECT_EQ(0, cras_alsa_jack_enable_ucm_called); EXPECT_EQ(0, ucm_set_enabled_called); - alsa_iodev_destroy((struct cras_iodev *)aio); + alsa_iodev_destroy((struct cras_iodev*)aio); } // Test handling of different amounts of outputs. TEST(AlsaOutputNode, TwoOutputs) { int rc; - struct alsa_io *aio; - struct cras_alsa_mixer * const fake_mixer = (struct cras_alsa_mixer*)2; - struct mixer_control *outputs[2]; + struct alsa_io* aio; + struct cras_alsa_mixer* const fake_mixer = (struct cras_alsa_mixer*)2; + struct mixer_control* outputs[2]; ResetStubData(); - outputs[0] = reinterpret_cast<struct mixer_control *>(3); - outputs[1] = reinterpret_cast<struct mixer_control *>(4); + outputs[0] = reinterpret_cast<struct mixer_control*>(3); + outputs[1] = reinterpret_cast<struct mixer_control*>(4); cras_alsa_mixer_list_outputs_outputs = outputs; cras_alsa_mixer_list_outputs_outputs_length = ARRAY_SIZE(outputs); - aio = (struct alsa_io *)alsa_iodev_create_with_default_parameters( + aio = (struct alsa_io*)alsa_iodev_create_with_default_parameters( 0, NULL, ALSA_CARD_TYPE_INTERNAL, 1, fake_mixer, fake_config, NULL, CRAS_STREAM_OUTPUT); - ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev *)aio)); + ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev*)aio)); EXPECT_EQ(4, cras_card_config_get_volume_curve_for_control_called); EXPECT_EQ(SND_PCM_STREAM_PLAYBACK, aio->alsa_stream); EXPECT_EQ(1, cras_alsa_mixer_list_outputs_called); - aio->handle = (snd_pcm_t *)0x24; + aio->handle = (snd_pcm_t*)0x24; ResetStubData(); - rc = alsa_iodev_set_active_node((struct cras_iodev *)aio, + rc = alsa_iodev_set_active_node((struct cras_iodev*)aio, aio->base.nodes->next, 1); EXPECT_EQ(0, rc); EXPECT_EQ(1, alsa_mixer_set_mute_called); @@ -1093,46 +1071,46 @@ TEST(AlsaOutputNode, TwoOutputs) { EXPECT_EQ(0, cras_alsa_jack_enable_ucm_called); EXPECT_EQ(0, ucm_set_enabled_called); - alsa_iodev_destroy((struct cras_iodev *)aio); + alsa_iodev_destroy((struct cras_iodev*)aio); } TEST(AlsaOutputNode, TwoJacksHeadphoneLineout) { - struct alsa_io *aio; - struct cras_alsa_mixer * const fake_mixer = (struct cras_alsa_mixer *)2; - struct cras_use_case_mgr * const fake_ucm = (struct cras_use_case_mgr *)3; - struct cras_iodev *iodev; - struct mixer_control *output; - struct ucm_section *section; + struct alsa_io* aio; + struct cras_alsa_mixer* const fake_mixer = (struct cras_alsa_mixer*)2; + struct cras_use_case_mgr* const fake_ucm = (struct cras_use_case_mgr*)3; + struct cras_iodev* iodev; + struct mixer_control* output; + struct ucm_section* section; ResetStubData(); - output = reinterpret_cast<struct mixer_control *>(3); + output = reinterpret_cast<struct mixer_control*>(3); cras_alsa_mixer_get_control_name_values[output] = HEADPHONE; // Create the iodev iodev = alsa_iodev_create_with_default_parameters( 0, NULL, ALSA_CARD_TYPE_INTERNAL, 1, fake_mixer, fake_config, fake_ucm, CRAS_STREAM_OUTPUT); - ASSERT_NE(iodev, (void *)NULL); - aio = reinterpret_cast<struct alsa_io *>(iodev); + ASSERT_NE(iodev, (void*)NULL); + aio = reinterpret_cast<struct alsa_io*>(iodev); EXPECT_EQ(1, cras_card_config_get_volume_curve_for_control_called); // First node 'Headphone' - section = ucm_section_create(HEADPHONE, 0, CRAS_STREAM_OUTPUT, - "fake-jack", "gpio"); + section = + ucm_section_create(HEADPHONE, 0, CRAS_STREAM_OUTPUT, "fake-jack", "gpio"); ucm_section_set_mixer_name(section, HEADPHONE); cras_alsa_jack_list_add_jack_for_section_result_jack = - reinterpret_cast<struct cras_alsa_jack *>(10); + reinterpret_cast<struct cras_alsa_jack*>(10); cras_alsa_mixer_get_control_for_section_return_value = output; ASSERT_EQ(0, alsa_iodev_ucm_add_nodes_and_jacks(iodev, section)); EXPECT_EQ(4, cras_card_config_get_volume_curve_for_control_called); ucm_section_free_list(section); // Second node 'Line Out' - section = ucm_section_create("Line Out", 0, CRAS_STREAM_OUTPUT, - "fake-jack", "gpio"); + section = ucm_section_create("Line Out", 0, CRAS_STREAM_OUTPUT, "fake-jack", + "gpio"); ucm_section_set_mixer_name(section, HEADPHONE); cras_alsa_jack_list_add_jack_for_section_result_jack = - reinterpret_cast<struct cras_alsa_jack *>(20); + reinterpret_cast<struct cras_alsa_jack*>(20); cras_alsa_mixer_get_control_for_section_return_value = output; ASSERT_EQ(0, alsa_iodev_ucm_add_nodes_and_jacks(iodev, section)); EXPECT_EQ(7, cras_card_config_get_volume_curve_for_control_called); @@ -1141,28 +1119,28 @@ TEST(AlsaOutputNode, TwoJacksHeadphoneLineout) { // Both nodes are associated with the same mixer output. Different jack plug // report should trigger different node attribute change. cras_alsa_jack_get_mixer_output_ret = output; - jack_output_plug_event(reinterpret_cast<struct cras_alsa_jack *>(10), 0, aio); + jack_output_plug_event(reinterpret_cast<struct cras_alsa_jack*>(10), 0, aio); EXPECT_STREQ(cras_iodev_set_node_plugged_ionode->name, HEADPHONE); - jack_output_plug_event(reinterpret_cast<struct cras_alsa_jack *>(20), 0, aio); + jack_output_plug_event(reinterpret_cast<struct cras_alsa_jack*>(20), 0, aio); EXPECT_STREQ(cras_iodev_set_node_plugged_ionode->name, "Line Out"); alsa_iodev_destroy(iodev); } TEST(AlsaOutputNode, OutputsFromUCM) { - struct alsa_io *aio; - struct cras_alsa_mixer * const fake_mixer = (struct cras_alsa_mixer*)2; - struct cras_use_case_mgr * const fake_ucm = (struct cras_use_case_mgr*)3; - struct cras_iodev *iodev; - static const char *jack_name = "TestCard - Headset Jack"; - struct mixer_control *outputs[2]; + struct alsa_io* aio; + struct cras_alsa_mixer* const fake_mixer = (struct cras_alsa_mixer*)2; + struct cras_use_case_mgr* const fake_ucm = (struct cras_use_case_mgr*)3; + struct cras_iodev* iodev; + static const char* jack_name = "TestCard - Headset Jack"; + struct mixer_control* outputs[2]; int rc; - struct ucm_section *section; + struct ucm_section* section; ResetStubData(); - outputs[0] = reinterpret_cast<struct mixer_control *>(3); - outputs[1] = reinterpret_cast<struct mixer_control *>(4); + outputs[0] = reinterpret_cast<struct mixer_control*>(3); + outputs[1] = reinterpret_cast<struct mixer_control*>(4); cras_alsa_mixer_list_outputs_outputs = outputs; cras_alsa_mixer_list_outputs_outputs_length = ARRAY_SIZE(outputs); cras_alsa_mixer_get_control_name_values[outputs[0]] = INTERNAL_SPEAKER; @@ -1170,29 +1148,27 @@ TEST(AlsaOutputNode, OutputsFromUCM) { ucm_get_dma_period_for_dev_ret = 1000; // Create the IO device. - iodev = alsa_iodev_create_with_default_parameters(0, NULL, - ALSA_CARD_TYPE_INTERNAL, 1, - fake_mixer, fake_config, - fake_ucm, - CRAS_STREAM_OUTPUT); - ASSERT_NE(iodev, (void *)NULL); - aio = reinterpret_cast<struct alsa_io *>(iodev); + iodev = alsa_iodev_create_with_default_parameters( + 0, NULL, ALSA_CARD_TYPE_INTERNAL, 1, fake_mixer, fake_config, fake_ucm, + CRAS_STREAM_OUTPUT); + ASSERT_NE(iodev, (void*)NULL); + aio = reinterpret_cast<struct alsa_io*>(iodev); EXPECT_EQ(1, cras_card_config_get_volume_curve_for_control_called); // First node. - section = ucm_section_create(INTERNAL_SPEAKER, 0, CRAS_STREAM_OUTPUT, - NULL, NULL); + section = + ucm_section_create(INTERNAL_SPEAKER, 0, CRAS_STREAM_OUTPUT, NULL, NULL); ucm_section_set_mixer_name(section, INTERNAL_SPEAKER); cras_alsa_jack_list_add_jack_for_section_result_jack = - reinterpret_cast<struct cras_alsa_jack *>(1); + reinterpret_cast<struct cras_alsa_jack*>(1); cras_alsa_mixer_get_control_for_section_return_value = outputs[0]; ASSERT_EQ(0, alsa_iodev_ucm_add_nodes_and_jacks(iodev, section)); ucm_section_free_list(section); EXPECT_EQ(4, cras_card_config_get_volume_curve_for_control_called); // Add a second node (will use the same iodev). - section = ucm_section_create(HEADPHONE, 0, CRAS_STREAM_OUTPUT, - jack_name, "hctl"); + section = + ucm_section_create(HEADPHONE, 0, CRAS_STREAM_OUTPUT, jack_name, "hctl"); ucm_section_add_coupled(section, "HP-L", MIXER_NAME_VOLUME); ucm_section_add_coupled(section, "HP-R", MIXER_NAME_VOLUME); cras_alsa_jack_list_add_jack_for_section_result_jack = NULL; @@ -1206,7 +1182,7 @@ TEST(AlsaOutputNode, OutputsFromUCM) { // Jack plug of an unkonwn device should do nothing. cras_alsa_jack_get_mixer_output_ret = NULL; cras_alsa_jack_get_name_ret_value = "Some other jack"; - jack_output_plug_event(reinterpret_cast<struct cras_alsa_jack *>(4), 0, aio); + jack_output_plug_event(reinterpret_cast<struct cras_alsa_jack*>(4), 0, aio); EXPECT_EQ(0, cras_iodev_set_node_plugged_called); // Complete initialization, and make first node active. @@ -1217,7 +1193,7 @@ TEST(AlsaOutputNode, OutputsFromUCM) { EXPECT_EQ(1, ucm_get_dma_period_for_dev_called); EXPECT_EQ(ucm_get_dma_period_for_dev_ret, aio->dma_period_set_microsecs); - aio->handle = (snd_pcm_t *)0x24; + aio->handle = (snd_pcm_t*)0x24; ResetStubData(); rc = alsa_iodev_set_active_node(iodev, aio->base.nodes->next, 1); @@ -1238,33 +1214,31 @@ TEST(AlsaOutputNode, OutputsFromUCM) { // Simulate jack plug event. cras_alsa_jack_get_mixer_output_ret = outputs[1]; cras_alsa_jack_get_name_ret_value = jack_name; - jack_output_plug_event(reinterpret_cast<struct cras_alsa_jack *>(4), 0, aio); + jack_output_plug_event(reinterpret_cast<struct cras_alsa_jack*>(4), 0, aio); EXPECT_EQ(1, cras_iodev_set_node_plugged_called); alsa_iodev_destroy(iodev); } TEST(AlsaOutputNode, OutputNoControlsUCM) { - struct alsa_io *aio; - struct cras_use_case_mgr * const fake_ucm = (struct cras_use_case_mgr*)3; - struct cras_iodev *iodev; - struct ucm_section *section; + struct alsa_io* aio; + struct cras_use_case_mgr* const fake_ucm = (struct cras_use_case_mgr*)3; + struct cras_iodev* iodev; + struct ucm_section* section; ResetStubData(); // Create the IO device. - iodev = alsa_iodev_create_with_default_parameters(1, NULL, - ALSA_CARD_TYPE_INTERNAL, 1, - fake_mixer, fake_config, - fake_ucm, - CRAS_STREAM_OUTPUT); - ASSERT_NE(iodev, (void *)NULL); - aio = reinterpret_cast<struct alsa_io *>(iodev); + iodev = alsa_iodev_create_with_default_parameters( + 1, NULL, ALSA_CARD_TYPE_INTERNAL, 1, fake_mixer, fake_config, fake_ucm, + CRAS_STREAM_OUTPUT); + ASSERT_NE(iodev, (void*)NULL); + aio = reinterpret_cast<struct alsa_io*>(iodev); EXPECT_EQ(1, cras_card_config_get_volume_curve_for_control_called); // Node without controls or jacks. - section = ucm_section_create(INTERNAL_SPEAKER, 1, CRAS_STREAM_OUTPUT, - NULL, NULL); + section = + ucm_section_create(INTERNAL_SPEAKER, 1, CRAS_STREAM_OUTPUT, NULL, NULL); // Device index doesn't match. EXPECT_EQ(-22, alsa_iodev_ucm_add_nodes_and_jacks(iodev, section)); section->dev_idx = 0; @@ -1286,29 +1260,27 @@ TEST(AlsaOutputNode, OutputNoControlsUCM) { } TEST(AlsaOutputNode, OutputFromJackUCM) { - struct alsa_io *aio; - struct cras_use_case_mgr * const fake_ucm = (struct cras_use_case_mgr*)3; - struct cras_iodev *iodev; - static const char *jack_name = "TestCard - Headset Jack"; - struct ucm_section *section; + struct alsa_io* aio; + struct cras_use_case_mgr* const fake_ucm = (struct cras_use_case_mgr*)3; + struct cras_iodev* iodev; + static const char* jack_name = "TestCard - Headset Jack"; + struct ucm_section* section; ResetStubData(); // Create the IO device. - iodev = alsa_iodev_create_with_default_parameters(1, NULL, - ALSA_CARD_TYPE_INTERNAL, 1, - fake_mixer, fake_config, - fake_ucm, - CRAS_STREAM_OUTPUT); - ASSERT_NE(iodev, (void *)NULL); - aio = reinterpret_cast<struct alsa_io *>(iodev); + iodev = alsa_iodev_create_with_default_parameters( + 1, NULL, ALSA_CARD_TYPE_INTERNAL, 1, fake_mixer, fake_config, fake_ucm, + CRAS_STREAM_OUTPUT); + ASSERT_NE(iodev, (void*)NULL); + aio = reinterpret_cast<struct alsa_io*>(iodev); EXPECT_EQ(1, cras_card_config_get_volume_curve_for_control_called); // Node without controls or jacks. cras_alsa_jack_list_add_jack_for_section_result_jack = - reinterpret_cast<struct cras_alsa_jack *>(1); - section = ucm_section_create(HEADPHONE, 0, CRAS_STREAM_OUTPUT, - jack_name, "hctl"); + reinterpret_cast<struct cras_alsa_jack*>(1); + section = + ucm_section_create(HEADPHONE, 0, CRAS_STREAM_OUTPUT, jack_name, "hctl"); ASSERT_EQ(0, alsa_iodev_ucm_add_nodes_and_jacks(iodev, section)); EXPECT_EQ(4, cras_card_config_get_volume_curve_for_control_called); EXPECT_EQ(1, cras_alsa_mixer_get_control_for_section_called); @@ -1328,37 +1300,35 @@ TEST(AlsaOutputNode, OutputFromJackUCM) { } TEST(AlsaOutputNode, InputsFromUCM) { - struct alsa_io *aio; - struct cras_alsa_mixer * const fake_mixer = (struct cras_alsa_mixer*)2; - struct cras_use_case_mgr * const fake_ucm = (struct cras_use_case_mgr*)3; - struct mixer_control *inputs[2]; - struct cras_iodev *iodev; - static const char *jack_name = "TestCard - Headset Jack"; + struct alsa_io* aio; + struct cras_alsa_mixer* const fake_mixer = (struct cras_alsa_mixer*)2; + struct cras_use_case_mgr* const fake_ucm = (struct cras_use_case_mgr*)3; + struct mixer_control* inputs[2]; + struct cras_iodev* iodev; + static const char* jack_name = "TestCard - Headset Jack"; int rc; - struct ucm_section *section; + struct ucm_section* section; ResetStubData(); - inputs[0] = reinterpret_cast<struct mixer_control *>(3); - inputs[1] = reinterpret_cast<struct mixer_control *>(4); + inputs[0] = reinterpret_cast<struct mixer_control*>(3); + inputs[1] = reinterpret_cast<struct mixer_control*>(4); cras_alsa_mixer_list_inputs_outputs = inputs; cras_alsa_mixer_list_inputs_outputs_length = ARRAY_SIZE(inputs); cras_alsa_mixer_get_control_name_values[inputs[0]] = INTERNAL_MICROPHONE; cras_alsa_mixer_get_control_name_values[inputs[1]] = MIC; // Create the IO device. - iodev = alsa_iodev_create_with_default_parameters(0, NULL, - ALSA_CARD_TYPE_INTERNAL, 1, - fake_mixer, fake_config, - fake_ucm, - CRAS_STREAM_INPUT); - ASSERT_NE(iodev, (void *)NULL); - aio = reinterpret_cast<struct alsa_io *>(iodev); + iodev = alsa_iodev_create_with_default_parameters( + 0, NULL, ALSA_CARD_TYPE_INTERNAL, 1, fake_mixer, fake_config, fake_ucm, + CRAS_STREAM_INPUT); + ASSERT_NE(iodev, (void*)NULL); + aio = reinterpret_cast<struct alsa_io*>(iodev); // First node. cras_alsa_mixer_get_control_for_section_return_value = inputs[0]; ucm_get_max_software_gain_ret_value = -1; - section = ucm_section_create(INTERNAL_MICROPHONE, 0, CRAS_STREAM_INPUT, - NULL, NULL); + section = + ucm_section_create(INTERNAL_MICROPHONE, 0, CRAS_STREAM_INPUT, NULL, NULL); ucm_section_add_coupled(section, "MIC-L", MIXER_NAME_VOLUME); ucm_section_add_coupled(section, "MIC-R", MIXER_NAME_VOLUME); ASSERT_EQ(0, alsa_iodev_ucm_add_nodes_and_jacks(iodev, section)); @@ -1369,7 +1339,7 @@ TEST(AlsaOutputNode, InputsFromUCM) { ucm_get_max_software_gain_ret_value = 0; ucm_get_max_software_gain_value = 2000; cras_alsa_jack_list_add_jack_for_section_result_jack = - reinterpret_cast<struct cras_alsa_jack *>(1); + reinterpret_cast<struct cras_alsa_jack*>(1); cras_alsa_mixer_get_control_for_section_return_value = inputs[1]; section = ucm_section_create(MIC, 0, CRAS_STREAM_INPUT, jack_name, "hctl"); ucm_section_set_mixer_name(section, MIC); @@ -1379,13 +1349,13 @@ TEST(AlsaOutputNode, InputsFromUCM) { // Jack plug of an unkonwn device should do nothing. cras_alsa_jack_get_mixer_input_ret = NULL; cras_alsa_jack_get_name_ret_value = "Some other jack"; - jack_input_plug_event(reinterpret_cast<struct cras_alsa_jack *>(4), 0, aio); + jack_input_plug_event(reinterpret_cast<struct cras_alsa_jack*>(4), 0, aio); EXPECT_EQ(0, cras_iodev_set_node_plugged_called); // Simulate jack plug event. cras_alsa_jack_get_mixer_input_ret = inputs[1]; cras_alsa_jack_get_name_ret_value = jack_name; - jack_input_plug_event(reinterpret_cast<struct cras_alsa_jack *>(4), 0, aio); + jack_input_plug_event(reinterpret_cast<struct cras_alsa_jack*>(4), 0, aio); EXPECT_EQ(1, cras_iodev_set_node_plugged_called); // Complete initialization, and make first node active. @@ -1399,7 +1369,7 @@ TEST(AlsaOutputNode, InputsFromUCM) { EXPECT_EQ(2, ucm_get_dma_period_for_dev_called); EXPECT_EQ(0, aio->dma_period_set_microsecs); - aio->handle = (snd_pcm_t *)0x24; + aio->handle = (snd_pcm_t*)0x24; ResetStubData(); rc = alsa_iodev_set_active_node(iodev, aio->base.nodes->next, 1); @@ -1419,25 +1389,23 @@ TEST(AlsaOutputNode, InputsFromUCM) { } TEST(AlsaOutputNode, InputNoControlsUCM) { - struct alsa_io *aio; - struct cras_use_case_mgr * const fake_ucm = (struct cras_use_case_mgr*)3; - struct cras_iodev *iodev; - struct ucm_section *section; + struct alsa_io* aio; + struct cras_use_case_mgr* const fake_ucm = (struct cras_use_case_mgr*)3; + struct cras_iodev* iodev; + struct ucm_section* section; ResetStubData(); // Create the IO device. - iodev = alsa_iodev_create_with_default_parameters(1, NULL, - ALSA_CARD_TYPE_INTERNAL, 1, - fake_mixer, fake_config, - fake_ucm, - CRAS_STREAM_INPUT); - ASSERT_NE(iodev, (void *)NULL); - aio = reinterpret_cast<struct alsa_io *>(iodev); + iodev = alsa_iodev_create_with_default_parameters( + 1, NULL, ALSA_CARD_TYPE_INTERNAL, 1, fake_mixer, fake_config, fake_ucm, + CRAS_STREAM_INPUT); + ASSERT_NE(iodev, (void*)NULL); + aio = reinterpret_cast<struct alsa_io*>(iodev); // Node without controls or jacks. - section = ucm_section_create(INTERNAL_MICROPHONE, 1, CRAS_STREAM_INPUT, - NULL, NULL); + section = + ucm_section_create(INTERNAL_MICROPHONE, 1, CRAS_STREAM_INPUT, NULL, NULL); // Device index doesn't match. EXPECT_EQ(-22, alsa_iodev_ucm_add_nodes_and_jacks(iodev, section)); section->dev_idx = 0; @@ -1460,26 +1428,24 @@ TEST(AlsaOutputNode, InputNoControlsUCM) { } TEST(AlsaOutputNode, InputFromJackUCM) { - struct alsa_io *aio; - struct cras_use_case_mgr * const fake_ucm = (struct cras_use_case_mgr*)3; - struct cras_iodev *iodev; - static const char *jack_name = "TestCard - Headset Jack"; - struct ucm_section *section; + struct alsa_io* aio; + struct cras_use_case_mgr* const fake_ucm = (struct cras_use_case_mgr*)3; + struct cras_iodev* iodev; + static const char* jack_name = "TestCard - Headset Jack"; + struct ucm_section* section; ResetStubData(); // Create the IO device. - iodev = alsa_iodev_create_with_default_parameters(1, NULL, - ALSA_CARD_TYPE_INTERNAL, 1, - fake_mixer, fake_config, - fake_ucm, - CRAS_STREAM_INPUT); - ASSERT_NE(iodev, (void *)NULL); - aio = reinterpret_cast<struct alsa_io *>(iodev); + iodev = alsa_iodev_create_with_default_parameters( + 1, NULL, ALSA_CARD_TYPE_INTERNAL, 1, fake_mixer, fake_config, fake_ucm, + CRAS_STREAM_INPUT); + ASSERT_NE(iodev, (void*)NULL); + aio = reinterpret_cast<struct alsa_io*>(iodev); // Node without controls or jacks. cras_alsa_jack_list_add_jack_for_section_result_jack = - reinterpret_cast<struct cras_alsa_jack *>(1); + reinterpret_cast<struct cras_alsa_jack*>(1); section = ucm_section_create(MIC, 0, CRAS_STREAM_INPUT, jack_name, "hctl"); ASSERT_EQ(0, alsa_iodev_ucm_add_nodes_and_jacks(iodev, section)); EXPECT_EQ(1, cras_alsa_mixer_get_control_for_section_called); @@ -1499,15 +1465,15 @@ TEST(AlsaOutputNode, InputFromJackUCM) { } TEST(AlsaOutputNode, AutoUnplugOutputNode) { - struct alsa_io *aio; - struct cras_alsa_mixer * const fake_mixer = (struct cras_alsa_mixer*)2; - struct cras_use_case_mgr * const fake_ucm = (struct cras_use_case_mgr*)3; - struct mixer_control *outputs[2]; - const struct cras_alsa_jack *jack = (struct cras_alsa_jack*)4; + struct alsa_io* aio; + struct cras_alsa_mixer* const fake_mixer = (struct cras_alsa_mixer*)2; + struct cras_use_case_mgr* const fake_ucm = (struct cras_use_case_mgr*)3; + struct mixer_control* outputs[2]; + const struct cras_alsa_jack* jack = (struct cras_alsa_jack*)4; ResetStubData(); - outputs[0] = reinterpret_cast<struct mixer_control *>(5); - outputs[1] = reinterpret_cast<struct mixer_control *>(6); + outputs[0] = reinterpret_cast<struct mixer_control*>(5); + outputs[1] = reinterpret_cast<struct mixer_control*>(6); cras_alsa_mixer_list_outputs_outputs = outputs; cras_alsa_mixer_list_outputs_outputs_length = ARRAY_SIZE(outputs); @@ -1516,19 +1482,19 @@ TEST(AlsaOutputNode, AutoUnplugOutputNode) { cras_alsa_mixer_get_control_name_values[outputs[1]] = HEADPHONE; auto_unplug_output_node_ret = 1; - aio = (struct alsa_io *)alsa_iodev_create_with_default_parameters( + aio = (struct alsa_io*)alsa_iodev_create_with_default_parameters( 0, NULL, ALSA_CARD_TYPE_INTERNAL, 1, fake_mixer, fake_config, fake_ucm, CRAS_STREAM_OUTPUT); - ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev *)aio)); + ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev*)aio)); EXPECT_EQ(3, cras_card_config_get_volume_curve_for_control_called); EXPECT_EQ(1, cras_alsa_mixer_list_outputs_called); EXPECT_EQ(2, cras_alsa_mixer_get_control_name_called); // Assert that the the internal speaker is plugged and other nodes aren't. - ASSERT_NE(aio->base.nodes, (void *)NULL); + ASSERT_NE(aio->base.nodes, (void*)NULL); EXPECT_EQ(aio->base.nodes->plugged, 1); - ASSERT_NE(aio->base.nodes->next, (void *)NULL); + ASSERT_NE(aio->base.nodes->next, (void*)NULL); EXPECT_EQ(aio->base.nodes->next->plugged, 0); // Plug headphone jack @@ -1541,19 +1507,19 @@ TEST(AlsaOutputNode, AutoUnplugOutputNode) { EXPECT_EQ(aio->base.nodes->plugged, 0); EXPECT_EQ(aio->base.nodes->next->plugged, 1); - alsa_iodev_destroy((struct cras_iodev *)aio); + alsa_iodev_destroy((struct cras_iodev*)aio); } TEST(AlsaOutputNode, AutoUnplugInputNode) { - struct alsa_io *aio; - struct cras_alsa_mixer * const fake_mixer = (struct cras_alsa_mixer*)2; - struct cras_use_case_mgr * const fake_ucm = (struct cras_use_case_mgr*)3; - struct mixer_control *inputs[2]; - const struct cras_alsa_jack *jack = (struct cras_alsa_jack*)4; + struct alsa_io* aio; + struct cras_alsa_mixer* const fake_mixer = (struct cras_alsa_mixer*)2; + struct cras_use_case_mgr* const fake_ucm = (struct cras_use_case_mgr*)3; + struct mixer_control* inputs[2]; + const struct cras_alsa_jack* jack = (struct cras_alsa_jack*)4; ResetStubData(); - inputs[0] = reinterpret_cast<struct mixer_control *>(5); - inputs[1] = reinterpret_cast<struct mixer_control *>(6); + inputs[0] = reinterpret_cast<struct mixer_control*>(5); + inputs[1] = reinterpret_cast<struct mixer_control*>(6); cras_alsa_mixer_list_inputs_outputs = inputs; cras_alsa_mixer_list_inputs_outputs_length = ARRAY_SIZE(inputs); @@ -1562,17 +1528,17 @@ TEST(AlsaOutputNode, AutoUnplugInputNode) { cras_alsa_mixer_get_control_name_values[inputs[1]] = MIC; auto_unplug_input_node_ret = 1; - aio = (struct alsa_io *)alsa_iodev_create_with_default_parameters( + aio = (struct alsa_io*)alsa_iodev_create_with_default_parameters( 0, NULL, ALSA_CARD_TYPE_INTERNAL, 1, fake_mixer, fake_config, fake_ucm, CRAS_STREAM_INPUT); - ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev *)aio)); + ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev*)aio)); EXPECT_EQ(1, cras_alsa_mixer_list_inputs_called); EXPECT_EQ(2, cras_alsa_mixer_get_control_name_called); // Assert that the the internal speaker is plugged and other nodes aren't. - ASSERT_NE(aio->base.nodes, (void *)NULL); + ASSERT_NE(aio->base.nodes, (void*)NULL); EXPECT_EQ(aio->base.nodes->plugged, 1); - ASSERT_NE(aio->base.nodes->next, (void *)NULL); + ASSERT_NE(aio->base.nodes->next, (void*)NULL); EXPECT_EQ(aio->base.nodes->next->plugged, 0); // Plug headphone jack @@ -1585,7 +1551,7 @@ TEST(AlsaOutputNode, AutoUnplugInputNode) { EXPECT_EQ(aio->base.nodes->plugged, 0); EXPECT_EQ(aio->base.nodes->next->plugged, 1); - alsa_iodev_destroy((struct cras_iodev *)aio); + alsa_iodev_destroy((struct cras_iodev*)aio); } TEST(AlsaInitNode, SetNodeInitialState) { @@ -1787,7 +1753,7 @@ TEST(AlsaInitNode, SetNodeInitialStateDropInvalidUTF8NodeName) { memset(&node, 0, sizeof(node)); node.dev = &dev; strcpy(node.name, "Something USB"); - //0xfe can not appear in a valid UTF-8 string. + // 0xfe can not appear in a valid UTF-8 string. node.name[0] = 0xfe; is_utf8_string_ret_value = 0; dev.direction = CRAS_STREAM_OUTPUT; @@ -1798,7 +1764,7 @@ TEST(AlsaInitNode, SetNodeInitialStateDropInvalidUTF8NodeName) { memset(&node, 0, sizeof(node)); node.dev = &dev; strcpy(node.name, "Something HDMI Jack"); - //0xfe can not appear in a valid UTF-8 string. + // 0xfe can not appear in a valid UTF-8 string. node.name[0] = 0xfe; is_utf8_string_ret_value = 0; dev.direction = CRAS_STREAM_OUTPUT; @@ -1808,16 +1774,16 @@ TEST(AlsaInitNode, SetNodeInitialStateDropInvalidUTF8NodeName) { } TEST(AlsaIoInit, HDMIJackUpdateInvalidUTF8MonitorName) { - struct alsa_io *aio; - struct cras_alsa_mixer * const fake_mixer = (struct cras_alsa_mixer*)2; - struct cras_use_case_mgr * const fake_ucm = (struct cras_use_case_mgr*)3; - const struct cras_alsa_jack *jack = (struct cras_alsa_jack*)4; + struct alsa_io* aio; + struct cras_alsa_mixer* const fake_mixer = (struct cras_alsa_mixer*)2; + struct cras_use_case_mgr* const fake_ucm = (struct cras_use_case_mgr*)3; + const struct cras_alsa_jack* jack = (struct cras_alsa_jack*)4; ResetStubData(); - aio = (struct alsa_io *)alsa_iodev_create_with_default_parameters( + aio = (struct alsa_io*)alsa_iodev_create_with_default_parameters( 0, NULL, ALSA_CARD_TYPE_INTERNAL, 0, fake_mixer, fake_config, fake_ucm, CRAS_STREAM_OUTPUT); - ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev *)aio)); + ASSERT_EQ(0, alsa_iodev_legacy_complete_init((struct cras_iodev*)aio)); // Prepare the stub data such that the jack will be identified as an // HDMI jack, and thus the callback creates an HDMI node. @@ -1834,59 +1800,54 @@ TEST(AlsaIoInit, HDMIJackUpdateInvalidUTF8MonitorName) { // The node name should be "HDMI". ASSERT_STREQ(HDMI, aio->base.nodes->next->name); - alsa_iodev_destroy((struct cras_iodev *)aio); + alsa_iodev_destroy((struct cras_iodev*)aio); } // Test thread add/rm stream, open_alsa, and iodev config. class AlsaVolumeMuteSuite : public testing::Test { - protected: - virtual void SetUp() { - ResetStubData(); - output_control_ = reinterpret_cast<struct mixer_control *>(10); - cras_alsa_mixer_list_outputs_outputs = &output_control_; - cras_alsa_mixer_list_outputs_outputs_length = 1; - cras_alsa_mixer_get_control_name_values[output_control_] = - INTERNAL_SPEAKER; - cras_alsa_mixer_list_outputs_outputs_length = 1; - aio_output_ = (struct alsa_io *)alsa_iodev_create_with_default_parameters( - 0, NULL, - ALSA_CARD_TYPE_INTERNAL, 1, - fake_mixer, fake_config, NULL, - CRAS_STREAM_OUTPUT); - alsa_iodev_legacy_complete_init((struct cras_iodev *)aio_output_); - EXPECT_EQ(2, cras_card_config_get_volume_curve_for_control_called); - - struct cras_ionode *node; - int count = 0; - DL_FOREACH(aio_output_->base.nodes, node) { - printf("node %d \n", count); - } - aio_output_->base.direction = CRAS_STREAM_OUTPUT; - fmt_.frame_rate = 44100; - fmt_.num_channels = 2; - fmt_.format = SND_PCM_FORMAT_S16_LE; - aio_output_->base.format = &fmt_; - cras_alsa_get_avail_frames_ret = -1; - } - - virtual void TearDown() { - alsa_iodev_destroy((struct cras_iodev *)aio_output_); - cras_alsa_get_avail_frames_ret = 0; - } - - struct mixer_control *output_control_; - struct alsa_io *aio_output_; + protected: + virtual void SetUp() { + ResetStubData(); + output_control_ = reinterpret_cast<struct mixer_control*>(10); + cras_alsa_mixer_list_outputs_outputs = &output_control_; + cras_alsa_mixer_list_outputs_outputs_length = 1; + cras_alsa_mixer_get_control_name_values[output_control_] = INTERNAL_SPEAKER; + cras_alsa_mixer_list_outputs_outputs_length = 1; + aio_output_ = (struct alsa_io*)alsa_iodev_create_with_default_parameters( + 0, NULL, ALSA_CARD_TYPE_INTERNAL, 1, fake_mixer, fake_config, NULL, + CRAS_STREAM_OUTPUT); + alsa_iodev_legacy_complete_init((struct cras_iodev*)aio_output_); + EXPECT_EQ(2, cras_card_config_get_volume_curve_for_control_called); + + struct cras_ionode* node; + int count = 0; + DL_FOREACH (aio_output_->base.nodes, node) { printf("node %d \n", count); } + aio_output_->base.direction = CRAS_STREAM_OUTPUT; + fmt_.frame_rate = 44100; + fmt_.num_channels = 2; + fmt_.format = SND_PCM_FORMAT_S16_LE; + aio_output_->base.format = &fmt_; + cras_alsa_get_avail_frames_ret = -1; + } + + virtual void TearDown() { + alsa_iodev_destroy((struct cras_iodev*)aio_output_); + cras_alsa_get_avail_frames_ret = 0; + } + + struct mixer_control* output_control_; + struct alsa_io* aio_output_; struct cras_audio_format fmt_; }; TEST_F(AlsaVolumeMuteSuite, GetDefaultVolumeCurve) { int rc; - struct cras_audio_format *fmt; + struct cras_audio_format* fmt; - fmt = (struct cras_audio_format *)malloc(sizeof(*fmt)); + fmt = (struct cras_audio_format*)malloc(sizeof(*fmt)); memcpy(fmt, &fmt_, sizeof(fmt_)); aio_output_->base.format = fmt; - aio_output_->handle = (snd_pcm_t *)0x24; + aio_output_->handle = (snd_pcm_t*)0x24; rc = aio_output_->base.configure_dev(&aio_output_->base); ASSERT_EQ(0, rc); @@ -1897,20 +1858,19 @@ TEST_F(AlsaVolumeMuteSuite, GetDefaultVolumeCurve) { free(fmt); } -TEST_F(AlsaVolumeMuteSuite, GetVolumeCurveFromNode) -{ +TEST_F(AlsaVolumeMuteSuite, GetVolumeCurveFromNode) { int rc; - struct cras_audio_format *fmt; - struct cras_alsa_jack *jack = (struct cras_alsa_jack*)4; - struct cras_ionode *node; + struct cras_audio_format* fmt; + struct cras_alsa_jack* jack = (struct cras_alsa_jack*)4; + struct cras_ionode* node; struct cras_volume_curve hp_curve = { - .get_dBFS = fake_get_dBFS, + .get_dBFS = fake_get_dBFS, }; - fmt = (struct cras_audio_format *)malloc(sizeof(*fmt)); + fmt = (struct cras_audio_format*)malloc(sizeof(*fmt)); memcpy(fmt, &fmt_, sizeof(fmt_)); aio_output_->base.format = fmt; - aio_output_->handle = (snd_pcm_t *)0x24; + aio_output_->handle = (snd_pcm_t*)0x24; // Headphone jack plugged and has its own volume curve. cras_alsa_jack_get_mixer_output_ret = NULL; @@ -1935,16 +1895,16 @@ TEST_F(AlsaVolumeMuteSuite, GetVolumeCurveFromNode) TEST_F(AlsaVolumeMuteSuite, SetVolume) { int rc; - struct cras_audio_format *fmt; + struct cras_audio_format* fmt; const size_t fake_system_volume = 55; const size_t fake_system_volume_dB = (fake_system_volume - 100) * 100; - fmt = (struct cras_audio_format *)malloc(sizeof(*fmt)); + fmt = (struct cras_audio_format*)malloc(sizeof(*fmt)); memcpy(fmt, &fmt_, sizeof(fmt_)); aio_output_->base.format = fmt; - aio_output_->handle = (snd_pcm_t *)0x24; + aio_output_->handle = (snd_pcm_t*)0x24; - aio_output_->num_underruns = 3; // Something non-zero. + aio_output_->num_underruns = 3; // Something non-zero. sys_get_volume_return_value = fake_system_volume; rc = aio_output_->base.configure_dev(&aio_output_->base); ASSERT_EQ(0, rc); @@ -1978,7 +1938,7 @@ TEST_F(AlsaVolumeMuteSuite, SetVolume) { // close the dev. rc = aio_output_->base.close_dev(&aio_output_->base); EXPECT_EQ(0, rc); - EXPECT_EQ((void *)NULL, aio_output_->handle); + EXPECT_EQ((void*)NULL, aio_output_->handle); free(fmt); } @@ -1986,7 +1946,7 @@ TEST_F(AlsaVolumeMuteSuite, SetVolume) { TEST_F(AlsaVolumeMuteSuite, SetMute) { int muted; - aio_output_->handle = (snd_pcm_t *)0x24; + aio_output_->handle = (snd_pcm_t*)0x24; // Test mute. ResetStubData(); @@ -2016,31 +1976,28 @@ TEST_F(AlsaVolumeMuteSuite, SetMute) { } // Test free run. -class AlsaFreeRunTestSuite: public testing::Test { - protected: - virtual void SetUp() { - ResetStubData(); - memset(&aio, 0, sizeof(aio)); - fmt_.format = SND_PCM_FORMAT_S16_LE; - fmt_.frame_rate = 48000; - fmt_.num_channels = 2; - aio.base.frames_queued = frames_queued; - aio.base.direction = CRAS_STREAM_OUTPUT; - aio.base.format = &fmt_; - aio.base.buffer_size = BUFFER_SIZE; - aio.base.min_cb_level = 240; - aio.base.min_buffer_level = 0; - aio.filled_zeros_for_draining = 0; - cras_alsa_mmap_begin_buffer = (uint8_t *)calloc( - BUFFER_SIZE * 2 * 2, - sizeof(*cras_alsa_mmap_begin_buffer)); - memset(cras_alsa_mmap_begin_buffer, 0xff, - sizeof(*cras_alsa_mmap_begin_buffer)); - } - - virtual void TearDown() { - free(cras_alsa_mmap_begin_buffer); - } +class AlsaFreeRunTestSuite : public testing::Test { + protected: + virtual void SetUp() { + ResetStubData(); + memset(&aio, 0, sizeof(aio)); + fmt_.format = SND_PCM_FORMAT_S16_LE; + fmt_.frame_rate = 48000; + fmt_.num_channels = 2; + aio.base.frames_queued = frames_queued; + aio.base.direction = CRAS_STREAM_OUTPUT; + aio.base.format = &fmt_; + aio.base.buffer_size = BUFFER_SIZE; + aio.base.min_cb_level = 240; + aio.base.min_buffer_level = 0; + aio.filled_zeros_for_draining = 0; + cras_alsa_mmap_begin_buffer = (uint8_t*)calloc( + BUFFER_SIZE * 2 * 2, sizeof(*cras_alsa_mmap_begin_buffer)); + memset(cras_alsa_mmap_begin_buffer, 0xff, + sizeof(*cras_alsa_mmap_begin_buffer)); + } + + virtual void TearDown() { free(cras_alsa_mmap_begin_buffer); } struct alsa_io aio; struct cras_audio_format fmt_; @@ -2048,13 +2005,12 @@ class AlsaFreeRunTestSuite: public testing::Test { TEST_F(AlsaFreeRunTestSuite, FillWholeBufferWithZeros) { int rc; - int16_t *zeros; - + int16_t* zeros; rc = fill_whole_buffer_with_zeros(&aio.base); EXPECT_EQ(0, rc); - zeros = (int16_t *)calloc(BUFFER_SIZE * 2, sizeof(*zeros)); + zeros = (int16_t*)calloc(BUFFER_SIZE * 2, sizeof(*zeros)); EXPECT_EQ(0, memcmp(zeros, cras_alsa_mmap_begin_buffer, BUFFER_SIZE * 2 * 2)); free(zeros); @@ -2227,7 +2183,7 @@ TEST_F(AlsaFreeRunTestSuite, LeaveFreeRunInFreeRun) { // similar. TEST_F(AlsaFreeRunTestSuite, OutputUnderrun) { int rc; - int16_t *zeros; + int16_t* zeros; snd_pcm_uframes_t offset; aio.num_underruns = 0; @@ -2238,13 +2194,13 @@ TEST_F(AlsaFreeRunTestSuite, OutputUnderrun) { EXPECT_EQ(1, aio.num_underruns); // mmap buffer should be filled with zeros. - zeros = (int16_t *)calloc(BUFFER_SIZE * 2, sizeof(*zeros)); + zeros = (int16_t*)calloc(BUFFER_SIZE * 2, sizeof(*zeros)); EXPECT_EQ(0, memcmp(zeros, cras_alsa_mmap_begin_buffer, BUFFER_SIZE * 2 * 2)); // appl_ptr should be moved to min_buffer_level + 1.5 * min_cb_level ahead of // hw_ptr. offset = aio.base.min_buffer_level + aio.base.min_cb_level + - aio.base.min_cb_level / 2; + aio.base.min_cb_level / 2; EXPECT_EQ(1, cras_alsa_resume_appl_ptr_called); EXPECT_EQ(offset, cras_alsa_resume_appl_ptr_ahead); @@ -2252,10 +2208,10 @@ TEST_F(AlsaFreeRunTestSuite, OutputUnderrun) { } TEST(AlsaHotwordNode, HotwordTriggeredSendMessage) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; struct cras_audio_format format; struct alsa_input_node alsa_node; - struct cras_ionode *node = &alsa_node.base; + struct cras_ionode* node = &alsa_node.base; int rc; ResetStubData(); @@ -2335,7 +2291,7 @@ TEST(AlsaGetValidFrames, GetValidFramesFreeRunning) { } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); openlog(NULL, LOG_PERROR, LOG_USER); return RUN_ALL_TESTS(); @@ -2346,172 +2302,152 @@ int main(int argc, char **argv) { extern "C" { // From iodev. -int cras_iodev_list_add_output(struct cras_iodev *output) -{ +int cras_iodev_list_add_output(struct cras_iodev* output) { return 0; } -int cras_iodev_list_rm_output(struct cras_iodev *dev) -{ +int cras_iodev_list_rm_output(struct cras_iodev* dev) { return 0; } -int cras_iodev_list_add_input(struct cras_iodev *input) -{ +int cras_iodev_list_add_input(struct cras_iodev* input) { return 0; } -int cras_iodev_list_rm_input(struct cras_iodev *dev) -{ +int cras_iodev_list_rm_input(struct cras_iodev* dev) { return 0; } -char *cras_iodev_list_get_hotword_models(cras_node_id_t node_id) -{ - return NULL; +char* cras_iodev_list_get_hotword_models(cras_node_id_t node_id) { + return NULL; } int cras_iodev_list_set_hotword_model(cras_node_id_t node_id, - const char *model_name) -{ - return 0; + const char* model_name) { + return 0; } -int cras_iodev_list_suspend_hotword_streams() -{ +int cras_iodev_list_suspend_hotword_streams() { return 0; } -int cras_iodev_list_resume_hotword_stream() -{ +int cras_iodev_list_resume_hotword_stream() { return 0; } -struct audio_thread *cras_iodev_list_get_audio_thread() -{ +struct audio_thread* cras_iodev_list_get_audio_thread() { return NULL; } // From alsa helper. -int cras_alsa_set_channel_map(snd_pcm_t *handle, - struct cras_audio_format *fmt) -{ +int cras_alsa_set_channel_map(snd_pcm_t* handle, + struct cras_audio_format* fmt) { return 0; } -int cras_alsa_get_channel_map(snd_pcm_t *handle, - struct cras_audio_format *fmt) -{ +int cras_alsa_get_channel_map(snd_pcm_t* handle, + struct cras_audio_format* fmt) { return 0; } -int cras_alsa_pcm_open(snd_pcm_t **handle, const char *dev, - snd_pcm_stream_t stream) -{ - *handle = (snd_pcm_t *)0x24; +int cras_alsa_pcm_open(snd_pcm_t** handle, + const char* dev, + snd_pcm_stream_t stream) { + *handle = (snd_pcm_t*)0x24; cras_alsa_open_called++; return 0; } -int cras_alsa_pcm_close(snd_pcm_t *handle) -{ +int cras_alsa_pcm_close(snd_pcm_t* handle) { return 0; } -int cras_alsa_pcm_start(snd_pcm_t *handle) -{ +int cras_alsa_pcm_start(snd_pcm_t* handle) { cras_alsa_start_called++; return 0; } -int cras_alsa_pcm_drain(snd_pcm_t *handle) -{ +int cras_alsa_pcm_drain(snd_pcm_t* handle) { return 0; } -int cras_alsa_fill_properties(snd_pcm_t *handle, - size_t **rates, - size_t **channel_counts, - snd_pcm_format_t **formats) -{ - *rates = (size_t *)malloc(sizeof(**rates) * 3); +int cras_alsa_fill_properties(snd_pcm_t* handle, + size_t** rates, + size_t** channel_counts, + snd_pcm_format_t** formats) { + *rates = (size_t*)malloc(sizeof(**rates) * 3); (*rates)[0] = 44100; (*rates)[1] = 48000; (*rates)[2] = 0; - *channel_counts = (size_t *)malloc(sizeof(**channel_counts) * 2); + *channel_counts = (size_t*)malloc(sizeof(**channel_counts) * 2); (*channel_counts)[0] = 2; (*channel_counts)[1] = 0; - *formats = (snd_pcm_format_t *)malloc(sizeof(**formats) * 2); + *formats = (snd_pcm_format_t*)malloc(sizeof(**formats) * 2); (*formats)[0] = SND_PCM_FORMAT_S16_LE; (*formats)[1] = (snd_pcm_format_t)0; cras_alsa_fill_properties_called++; return 0; } -int cras_alsa_set_hwparams(snd_pcm_t *handle, struct cras_audio_format *format, - snd_pcm_uframes_t *buffer_size, int period_wakeup, - unsigned int dma_period_time) -{ +int cras_alsa_set_hwparams(snd_pcm_t* handle, + struct cras_audio_format* format, + snd_pcm_uframes_t* buffer_size, + int period_wakeup, + unsigned int dma_period_time) { return 0; } -int cras_alsa_set_swparams(snd_pcm_t *handle, int *enable_htimestamp) -{ +int cras_alsa_set_swparams(snd_pcm_t* handle, int* enable_htimestamp) { return 0; } -int cras_alsa_get_avail_frames(snd_pcm_t *handle, snd_pcm_uframes_t buf_size, +int cras_alsa_get_avail_frames(snd_pcm_t* handle, + snd_pcm_uframes_t buf_size, snd_pcm_uframes_t severe_underrun_frames, const char* dev_name, - snd_pcm_uframes_t *used, - struct timespec *tstamp) -{ + snd_pcm_uframes_t* used, + struct timespec* tstamp) { *used = cras_alsa_get_avail_frames_avail; clock_gettime(CLOCK_MONOTONIC_RAW, tstamp); return cras_alsa_get_avail_frames_ret; } -int cras_alsa_get_delay_frames(snd_pcm_t *handle, snd_pcm_uframes_t buf_size, - snd_pcm_sframes_t *delay) -{ +int cras_alsa_get_delay_frames(snd_pcm_t* handle, + snd_pcm_uframes_t buf_size, + snd_pcm_sframes_t* delay) { *delay = 0; return 0; } -int cras_alsa_mmap_begin(snd_pcm_t *handle, unsigned int format_bytes, - uint8_t **dst, snd_pcm_uframes_t *offset, - snd_pcm_uframes_t *frames) -{ +int cras_alsa_mmap_begin(snd_pcm_t* handle, + unsigned int format_bytes, + uint8_t** dst, + snd_pcm_uframes_t* offset, + snd_pcm_uframes_t* frames) { *dst = cras_alsa_mmap_begin_buffer; *frames = cras_alsa_mmap_begin_frames; return 0; } -int cras_alsa_mmap_commit(snd_pcm_t *handle, snd_pcm_uframes_t offset, - snd_pcm_uframes_t frames) -{ +int cras_alsa_mmap_commit(snd_pcm_t* handle, + snd_pcm_uframes_t offset, + snd_pcm_uframes_t frames) { return 0; } -int cras_alsa_attempt_resume(snd_pcm_t *handle) -{ +int cras_alsa_attempt_resume(snd_pcm_t* handle) { cras_alsa_attempt_resume_called++; return 0; } // ALSA stubs. -int snd_pcm_format_physical_width(snd_pcm_format_t format) -{ +int snd_pcm_format_physical_width(snd_pcm_format_t format) { return 16; } -snd_pcm_state_t snd_pcm_state(snd_pcm_t *handle) -{ +snd_pcm_state_t snd_pcm_state(snd_pcm_t* handle) { return snd_pcm_state_ret; } -const char *snd_strerror(int errnum) -{ +const char* snd_strerror(int errnum) { return "Alsa Error in UT"; } -struct mixer_control *cras_alsa_mixer_get_control_for_section( - struct cras_alsa_mixer *cras_mixer, - const struct ucm_section *section) -{ +struct mixer_control* cras_alsa_mixer_get_control_for_section( + struct cras_alsa_mixer* cras_mixer, + const struct ucm_section* section) { cras_alsa_mixer_get_control_for_section_called++; return cras_alsa_mixer_get_control_for_section_return_value; } -const char *cras_alsa_mixer_get_control_name( - const struct mixer_control *control) -{ +const char* cras_alsa_mixer_get_control_name( + const struct mixer_control* control) { ControlNameMap::iterator it; cras_alsa_mixer_get_control_name_called++; it = cras_alsa_mixer_get_control_name_values.find(control); @@ -2521,214 +2457,186 @@ const char *cras_alsa_mixer_get_control_name( } // From system_state. -size_t cras_system_get_volume() -{ +size_t cras_system_get_volume() { sys_get_volume_called++; return sys_get_volume_return_value; } -long cras_system_get_capture_gain() -{ +long cras_system_get_capture_gain() { sys_get_capture_gain_called++; return sys_get_capture_gain_return_value; } -int cras_system_get_mute() -{ +int cras_system_get_mute() { sys_get_mute_called++; return sys_get_mute_return_value; } -int cras_system_get_capture_mute() -{ +int cras_system_get_capture_mute() { sys_get_capture_mute_called++; return sys_get_capture_mute_return_value; } -void cras_system_set_volume_limits(long min, long max) -{ +void cras_system_set_volume_limits(long min, long max) { sys_set_volume_limits_called++; } -void cras_system_set_capture_gain_limits(long min, long max) -{ +void cras_system_set_capture_gain_limits(long min, long max) { cras_system_set_capture_gain_limits_set_value[0] = min; cras_system_set_capture_gain_limits_set_value[1] = max; sys_set_capture_gain_limits_called++; } // From cras_alsa_mixer. -void cras_alsa_mixer_set_dBFS(struct cras_alsa_mixer *m, - long dB_level, - struct mixer_control *output) -{ +void cras_alsa_mixer_set_dBFS(struct cras_alsa_mixer* m, + long dB_level, + struct mixer_control* output) { alsa_mixer_set_dBFS_called++; alsa_mixer_set_dBFS_value = dB_level; alsa_mixer_set_dBFS_output = output; } -void cras_alsa_mixer_set_mute(struct cras_alsa_mixer *cras_mixer, - int muted, - struct mixer_control *mixer_output) -{ +void cras_alsa_mixer_set_mute(struct cras_alsa_mixer* cras_mixer, + int muted, + struct mixer_control* mixer_output) { alsa_mixer_set_mute_called++; alsa_mixer_set_mute_value = muted; alsa_mixer_set_mute_output = mixer_output; } -long cras_alsa_mixer_get_dB_range(struct cras_alsa_mixer *cras_mixer) -{ +long cras_alsa_mixer_get_dB_range(struct cras_alsa_mixer* cras_mixer) { alsa_mixer_get_dB_range_called++; return alsa_mixer_get_dB_range_value; } -long cras_alsa_mixer_get_output_dB_range( - struct mixer_control *mixer_output) -{ +long cras_alsa_mixer_get_output_dB_range(struct mixer_control* mixer_output) { alsa_mixer_get_output_dB_range_called++; return alsa_mixer_get_output_dB_range_value; } -void cras_alsa_mixer_set_capture_dBFS(struct cras_alsa_mixer *m, long dB_level, - struct mixer_control *mixer_input) -{ +void cras_alsa_mixer_set_capture_dBFS(struct cras_alsa_mixer* m, + long dB_level, + struct mixer_control* mixer_input) { alsa_mixer_set_capture_dBFS_called++; alsa_mixer_set_capture_dBFS_value = dB_level; alsa_mixer_set_capture_dBFS_input = mixer_input; } -void cras_alsa_mixer_set_capture_mute(struct cras_alsa_mixer *m, int mute, - struct mixer_control *mixer_input) -{ +void cras_alsa_mixer_set_capture_mute(struct cras_alsa_mixer* m, + int mute, + struct mixer_control* mixer_input) { alsa_mixer_set_capture_mute_called++; alsa_mixer_set_capture_mute_value = mute; alsa_mixer_set_capture_mute_input = mixer_input; } -void cras_alsa_mixer_list_outputs(struct cras_alsa_mixer *cras_mixer, - cras_alsa_mixer_control_callback cb, - void *callback_arg) -{ +void cras_alsa_mixer_list_outputs(struct cras_alsa_mixer* cras_mixer, + cras_alsa_mixer_control_callback cb, + void* callback_arg) { cras_alsa_mixer_list_outputs_called++; for (size_t i = 0; i < cras_alsa_mixer_list_outputs_outputs_length; i++) { cb(cras_alsa_mixer_list_outputs_outputs[i], callback_arg); } } -void cras_alsa_mixer_list_inputs(struct cras_alsa_mixer *cras_mixer, - cras_alsa_mixer_control_callback cb, - void *callback_arg) -{ +void cras_alsa_mixer_list_inputs(struct cras_alsa_mixer* cras_mixer, + cras_alsa_mixer_control_callback cb, + void* callback_arg) { cras_alsa_mixer_list_inputs_called++; for (size_t i = 0; i < cras_alsa_mixer_list_inputs_outputs_length; i++) { cb(cras_alsa_mixer_list_inputs_outputs[i], callback_arg); } } -int cras_alsa_mixer_set_output_active_state( - struct mixer_control *output, - int active) -{ +int cras_alsa_mixer_set_output_active_state(struct mixer_control* output, + int active) { cras_alsa_mixer_set_output_active_state_called++; cras_alsa_mixer_set_output_active_state_outputs.push_back(output); cras_alsa_mixer_set_output_active_state_values.push_back(active); return 0; } -void cras_volume_curve_destroy(struct cras_volume_curve *curve) -{ -} +void cras_volume_curve_destroy(struct cras_volume_curve* curve) {} -long cras_alsa_mixer_get_minimum_capture_gain(struct cras_alsa_mixer *cmix, - struct mixer_control *mixer_input) -{ - cras_alsa_mixer_get_minimum_capture_gain_called++; - cras_alsa_mixer_get_minimum_capture_gain_mixer_input = mixer_input; - return cras_alsa_mixer_get_minimum_capture_gain_ret_value; +long cras_alsa_mixer_get_minimum_capture_gain( + struct cras_alsa_mixer* cmix, + struct mixer_control* mixer_input) { + cras_alsa_mixer_get_minimum_capture_gain_called++; + cras_alsa_mixer_get_minimum_capture_gain_mixer_input = mixer_input; + return cras_alsa_mixer_get_minimum_capture_gain_ret_value; } -long cras_alsa_mixer_get_maximum_capture_gain(struct cras_alsa_mixer *cmix, - struct mixer_control *mixer_input) -{ - cras_alsa_mixer_get_maximum_capture_gain_called++; - cras_alsa_mixer_get_maximum_capture_gain_mixer_input = mixer_input; - return cras_alsa_mixer_get_maximum_capture_gain_ret_value; +long cras_alsa_mixer_get_maximum_capture_gain( + struct cras_alsa_mixer* cmix, + struct mixer_control* mixer_input) { + cras_alsa_mixer_get_maximum_capture_gain_called++; + cras_alsa_mixer_get_maximum_capture_gain_mixer_input = mixer_input; + return cras_alsa_mixer_get_maximum_capture_gain_ret_value; } -int cras_alsa_mixer_has_main_volume(const struct cras_alsa_mixer *cras_mixer) -{ +int cras_alsa_mixer_has_main_volume(const struct cras_alsa_mixer* cras_mixer) { return 1; } -int cras_alsa_mixer_has_volume(const struct mixer_control *mixer_control) -{ +int cras_alsa_mixer_has_volume(const struct mixer_control* mixer_control) { return 1; } // From cras_alsa_jack -struct cras_alsa_jack_list *cras_alsa_jack_list_create( - unsigned int card_index, - const char *card_name, - unsigned int device_index, - int check_gpio_jack, - struct cras_alsa_mixer *mixer, - struct cras_use_case_mgr *ucm, - snd_hctl_t *hctl, - enum CRAS_STREAM_DIRECTION direction, - jack_state_change_callback *cb, - void *cb_data) -{ +struct cras_alsa_jack_list* cras_alsa_jack_list_create( + unsigned int card_index, + const char* card_name, + unsigned int device_index, + int check_gpio_jack, + struct cras_alsa_mixer* mixer, + struct cras_use_case_mgr* ucm, + snd_hctl_t* hctl, + enum CRAS_STREAM_DIRECTION direction, + jack_state_change_callback* cb, + void* cb_data) { cras_alsa_jack_list_create_called++; cras_alsa_jack_list_create_cb = cb; cras_alsa_jack_list_create_cb_data = cb_data; - return (struct cras_alsa_jack_list *)0xfee; + return (struct cras_alsa_jack_list*)0xfee; } int cras_alsa_jack_list_find_jacks_by_name_matching( - struct cras_alsa_jack_list *jack_list) -{ + struct cras_alsa_jack_list* jack_list) { cras_alsa_jack_list_find_jacks_by_name_matching_called++; return 0; } int cras_alsa_jack_list_add_jack_for_section( - struct cras_alsa_jack_list *jack_list, - struct ucm_section *ucm_section, - struct cras_alsa_jack **result_jack) -{ + struct cras_alsa_jack_list* jack_list, + struct ucm_section* ucm_section, + struct cras_alsa_jack** result_jack) { cras_alsa_jack_list_add_jack_for_section_called++; if (result_jack) *result_jack = cras_alsa_jack_list_add_jack_for_section_result_jack; return 0; } -void cras_alsa_jack_list_destroy(struct cras_alsa_jack_list *jack_list) -{ +void cras_alsa_jack_list_destroy(struct cras_alsa_jack_list* jack_list) { cras_alsa_jack_list_destroy_called++; } -int cras_alsa_jack_list_has_hctl_jacks(struct cras_alsa_jack_list *jack_list) -{ +int cras_alsa_jack_list_has_hctl_jacks(struct cras_alsa_jack_list* jack_list) { return cras_alsa_jack_list_has_hctl_jacks_return_val; } -void cras_alsa_jack_list_report(const struct cras_alsa_jack_list *jack_list) -{ -} +void cras_alsa_jack_list_report(const struct cras_alsa_jack_list* jack_list) {} -void cras_alsa_jack_enable_ucm(const struct cras_alsa_jack *jack, int enable) { +void cras_alsa_jack_enable_ucm(const struct cras_alsa_jack* jack, int enable) { cras_alsa_jack_enable_ucm_called++; } -const char *cras_alsa_jack_get_name(const struct cras_alsa_jack *jack) -{ +const char* cras_alsa_jack_get_name(const struct cras_alsa_jack* jack) { cras_alsa_jack_get_name_called++; return cras_alsa_jack_get_name_ret_value; } -const char *ucm_get_dsp_name_default(struct cras_use_case_mgr *mgr, - int direction) -{ +const char* ucm_get_dsp_name_default(struct cras_use_case_mgr* mgr, + int direction) { ucm_get_dsp_name_default_called++; if (ucm_get_dsp_name_default_value) return strdup(ucm_get_dsp_name_default_value); @@ -2736,9 +2644,8 @@ const char *ucm_get_dsp_name_default(struct cras_use_case_mgr *mgr, return NULL; } -const char *ucm_get_dsp_name_for_dev(struct cras_use_case_mgr *mgr, - const char *dev) -{ +const char* ucm_get_dsp_name_for_dev(struct cras_use_case_mgr* mgr, + const char* dev) { DspNameMap::iterator it; ucm_get_dsp_name_for_dev_called++; if (!dev) @@ -2749,30 +2656,29 @@ const char *ucm_get_dsp_name_for_dev(struct cras_use_case_mgr *mgr, return strdup(it->second.c_str()); } -struct mixer_control *cras_alsa_jack_get_mixer_output( - const struct cras_alsa_jack *jack) -{ +struct mixer_control* cras_alsa_jack_get_mixer_output( + const struct cras_alsa_jack* jack) { return cras_alsa_jack_get_mixer_output_ret; } -struct mixer_control *cras_alsa_jack_get_mixer_input( - const struct cras_alsa_jack *jack) -{ +struct mixer_control* cras_alsa_jack_get_mixer_input( + const struct cras_alsa_jack* jack) { return cras_alsa_jack_get_mixer_input_ret; } -int ucm_set_enabled( - struct cras_use_case_mgr *mgr, const char *dev, int enabled) { +int ucm_set_enabled(struct cras_use_case_mgr* mgr, + const char* dev, + int enabled) { ucm_set_enabled_called++; return 0; } -char *ucm_get_flag(struct cras_use_case_mgr *mgr, const char *flag_name) { +char* ucm_get_flag(struct cras_use_case_mgr* mgr, const char* flag_name) { if ((!strcmp(flag_name, "AutoUnplugInputNode") && auto_unplug_input_node_ret) || (!strcmp(flag_name, "AutoUnplugOutputNode") && auto_unplug_output_node_ret)) { - char *ret = (char *)malloc(8); + char* ret = (char*)malloc(8); snprintf(ret, 8, "%s", "1"); return ret; } @@ -2780,99 +2686,88 @@ char *ucm_get_flag(struct cras_use_case_mgr *mgr, const char *flag_name) { return NULL; } -char *ucm_get_mic_positions(struct cras_use_case_mgr *mgr) { +char* ucm_get_mic_positions(struct cras_use_case_mgr* mgr) { return NULL; } -int ucm_swap_mode_exists(struct cras_use_case_mgr *mgr) -{ +int ucm_swap_mode_exists(struct cras_use_case_mgr* mgr) { return ucm_swap_mode_exists_ret_value; } -int ucm_enable_swap_mode(struct cras_use_case_mgr *mgr, const char *node_name, - int enable) -{ +int ucm_enable_swap_mode(struct cras_use_case_mgr* mgr, + const char* node_name, + int enable) { ucm_enable_swap_mode_called++; return ucm_enable_swap_mode_ret_value; } -int ucm_get_min_buffer_level(struct cras_use_case_mgr *mgr, - unsigned int *level) -{ +int ucm_get_min_buffer_level(struct cras_use_case_mgr* mgr, + unsigned int* level) { *level = 0; return 0; } -unsigned int ucm_get_enable_htimestamp_flag(struct cras_use_case_mgr *mgr) -{ +unsigned int ucm_get_enable_htimestamp_flag(struct cras_use_case_mgr* mgr) { return ucm_get_enable_htimestamp_flag_ret; } -unsigned int ucm_get_disable_software_volume(struct cras_use_case_mgr *mgr) -{ +unsigned int ucm_get_disable_software_volume(struct cras_use_case_mgr* mgr) { return 0; } -int ucm_get_min_software_gain(struct cras_use_case_mgr *mgr, const char *dev, - long *gain) -{ +int ucm_get_min_software_gain(struct cras_use_case_mgr* mgr, + const char* dev, + long* gain) { ucm_get_min_software_gain_called++; *gain = ucm_get_min_software_gain_value; return ucm_get_min_software_gain_ret_value; } -int ucm_get_max_software_gain(struct cras_use_case_mgr *mgr, const char *dev, - long *gain) -{ +int ucm_get_max_software_gain(struct cras_use_case_mgr* mgr, + const char* dev, + long* gain) { ucm_get_max_software_gain_called++; *gain = ucm_get_max_software_gain_value; return ucm_get_max_software_gain_ret_value; } -char *ucm_get_hotword_models(struct cras_use_case_mgr *mgr) -{ +char* ucm_get_hotword_models(struct cras_use_case_mgr* mgr) { return NULL; } -int ucm_set_hotword_model(struct cras_use_case_mgr *mgr, const char *model) -{ +int ucm_set_hotword_model(struct cras_use_case_mgr* mgr, const char* model) { return 0; } -unsigned int ucm_get_dma_period_for_dev(struct cras_use_case_mgr *mgr, - const char *dev) -{ +unsigned int ucm_get_dma_period_for_dev(struct cras_use_case_mgr* mgr, + const char* dev) { ucm_get_dma_period_for_dev_called++; return ucm_get_dma_period_for_dev_ret; } -int ucm_get_sample_rate_for_dev(struct cras_use_case_mgr *mgr, const char *dev, - enum CRAS_STREAM_DIRECTION direction) -{ +int ucm_get_sample_rate_for_dev(struct cras_use_case_mgr* mgr, + const char* dev, + enum CRAS_STREAM_DIRECTION direction) { return -EINVAL; } -int ucm_get_capture_chmap_for_dev(struct cras_use_case_mgr *mgr, - const char *dev, - int8_t *channel_layout) -{ +int ucm_get_capture_chmap_for_dev(struct cras_use_case_mgr* mgr, + const char* dev, + int8_t* channel_layout) { return -EINVAL; } -int ucm_get_preempt_hotword(struct cras_use_case_mgr *mgr, const char *dev) -{ +int ucm_get_preempt_hotword(struct cras_use_case_mgr* mgr, const char* dev) { return 0; } -struct cras_volume_curve *cras_volume_curve_create_default() -{ +struct cras_volume_curve* cras_volume_curve_create_default() { return &default_curve; } -struct cras_volume_curve *cras_card_config_get_volume_curve_for_control( - const struct cras_card_config *card_config, - const char *control_name) -{ +struct cras_volume_curve* cras_card_config_get_volume_curve_for_control( + const struct cras_card_config* card_config, + const char* control_name) { VolCurveMap::iterator it; cras_card_config_get_volume_curve_for_control_called++; if (!control_name) @@ -2883,40 +2778,29 @@ struct cras_volume_curve *cras_card_config_get_volume_curve_for_control( return it->second; } -void cras_iodev_free_format(struct cras_iodev *iodev) -{ -} +void cras_iodev_free_format(struct cras_iodev* iodev) {} -int cras_iodev_set_format(struct cras_iodev *iodev, - const struct cras_audio_format *fmt) -{ - fake_format = (struct cras_audio_format *)calloc( - 1, - sizeof(cras_audio_format)); +int cras_iodev_set_format(struct cras_iodev* iodev, + const struct cras_audio_format* fmt) { + fake_format = (struct cras_audio_format*)calloc(1, sizeof(cras_audio_format)); // Copy the content of format from fmt into format of iodev. memcpy(fake_format, fmt, sizeof(cras_audio_format)); iodev->format = fake_format; return 0; } -struct audio_thread *audio_thread_create() { +struct audio_thread* audio_thread_create() { return reinterpret_cast<audio_thread*>(0x323); } -void audio_thread_destroy(audio_thread* thread) { -} - +void audio_thread_destroy(audio_thread* thread) {} - -void cras_iodev_update_dsp(struct cras_iodev *iodev) -{ +void cras_iodev_update_dsp(struct cras_iodev* iodev) { cras_iodev_update_dsp_called++; cras_iodev_update_dsp_name = iodev->dsp_name; } -void cras_iodev_set_node_plugged(struct cras_ionode *ionode, - int plugged) -{ +void cras_iodev_set_node_plugged(struct cras_ionode* ionode, int plugged) { cras_iodev_set_node_plugged_called++; cras_iodev_set_node_plugged_ionode = ionode; cras_iodev_set_node_plugged_value = plugged; @@ -2924,50 +2808,43 @@ void cras_iodev_set_node_plugged(struct cras_ionode *ionode, ionode->plugged = plugged; } -void cras_iodev_add_node(struct cras_iodev *iodev, struct cras_ionode *node) -{ +void cras_iodev_add_node(struct cras_iodev* iodev, struct cras_ionode* node) { cras_iodev_add_node_called++; DL_APPEND(iodev->nodes, node); } -void cras_iodev_rm_node(struct cras_iodev *iodev, struct cras_ionode *node) -{ +void cras_iodev_rm_node(struct cras_iodev* iodev, struct cras_ionode* node) { DL_DELETE(iodev->nodes, node); } -void cras_iodev_set_active_node(struct cras_iodev *iodev, - struct cras_ionode *node) -{ +void cras_iodev_set_active_node(struct cras_iodev* iodev, + struct cras_ionode* node) { iodev->active_node = node; } -void cras_iodev_free_resources(struct cras_iodev *iodev) -{ +void cras_iodev_free_resources(struct cras_iodev* iodev) { cras_iodev_free_resources_called++; } -void cras_alsa_jack_update_monitor_name(const struct cras_alsa_jack *jack, - char *name_buf, - unsigned int buf_size) -{ +void cras_alsa_jack_update_monitor_name(const struct cras_alsa_jack* jack, + char* name_buf, + unsigned int buf_size) { if (cras_alsa_jack_update_monitor_fake_name) strcpy(name_buf, cras_alsa_jack_update_monitor_fake_name); } -void cras_alsa_jack_update_node_type(const struct cras_alsa_jack *jack, - enum CRAS_NODE_TYPE *type) -{ +void cras_alsa_jack_update_node_type(const struct cras_alsa_jack* jack, + enum CRAS_NODE_TYPE* type) { cras_alsa_jack_update_node_type_called++; } -const char *cras_alsa_jack_get_ucm_device(const struct cras_alsa_jack *jack) -{ +const char* cras_alsa_jack_get_ucm_device(const struct cras_alsa_jack* jack) { return NULL; } -int ucm_get_default_node_gain(struct cras_use_case_mgr *mgr, const char *dev, - long *gain) -{ +int ucm_get_default_node_gain(struct cras_use_case_mgr* mgr, + const char* dev, + long* gain) { if (ucm_get_default_node_gain_values.find(dev) == ucm_get_default_node_gain_values.end()) return 1; @@ -2976,70 +2853,57 @@ int ucm_get_default_node_gain(struct cras_use_case_mgr *mgr, const char *dev, return 0; } -void cras_iodev_init_audio_area(struct cras_iodev *iodev, - int num_channels) { -} +void cras_iodev_init_audio_area(struct cras_iodev* iodev, int num_channels) {} -void cras_iodev_free_audio_area(struct cras_iodev *iodev) { -} +void cras_iodev_free_audio_area(struct cras_iodev* iodev) {} -int cras_iodev_reset_rate_estimator(const struct cras_iodev *iodev) -{ +int cras_iodev_reset_rate_estimator(const struct cras_iodev* iodev) { return 0; } -int cras_iodev_frames_queued(struct cras_iodev *iodev, struct timespec *tstamp) -{ +int cras_iodev_frames_queued(struct cras_iodev* iodev, + struct timespec* tstamp) { clock_gettime(CLOCK_MONOTONIC_RAW, tstamp); return cras_iodev_frames_queued_ret; } -int cras_iodev_buffer_avail(struct cras_iodev *iodev, unsigned hw_level) -{ +int cras_iodev_buffer_avail(struct cras_iodev* iodev, unsigned hw_level) { return cras_iodev_buffer_avail_ret; } -int cras_iodev_fill_odev_zeros(struct cras_iodev *odev, unsigned int frames) -{ +int cras_iodev_fill_odev_zeros(struct cras_iodev* odev, unsigned int frames) { cras_iodev_fill_odev_zeros_called++; cras_iodev_fill_odev_zeros_frames = frames; return 0; } -void cras_audio_area_config_buf_pointers(struct cras_audio_area *area, - const struct cras_audio_format *fmt, - uint8_t *base_buffer) -{ -} +void cras_audio_area_config_buf_pointers(struct cras_audio_area* area, + const struct cras_audio_format* fmt, + uint8_t* base_buffer) {} -void audio_thread_add_callback(int fd, thread_callback cb, void *data) -{ +void audio_thread_add_callback(int fd, thread_callback cb, void* data) { audio_thread_cb = cb; audio_thread_cb_data = data; } -void audio_thread_rm_callback(int fd) -{ -} +void audio_thread_rm_callback(int fd) {} -int audio_thread_rm_callback_sync(struct audio_thread *thread, int fd) { +int audio_thread_rm_callback_sync(struct audio_thread* thread, int fd) { return 0; } -int cras_hotword_send_triggered_msg() -{ +int cras_hotword_send_triggered_msg() { hotword_send_triggered_msg_called++; return 0; } -int snd_pcm_poll_descriptors_count(snd_pcm_t *pcm) -{ +int snd_pcm_poll_descriptors_count(snd_pcm_t* pcm) { return 1; } -int snd_pcm_poll_descriptors(snd_pcm_t *pcm, struct pollfd *pfds, - unsigned int space) -{ +int snd_pcm_poll_descriptors(snd_pcm_t* pcm, + struct pollfd* pfds, + unsigned int space) { if (space >= 1) { pfds[0].events = POLLIN; pfds[0].fd = 99; @@ -3047,40 +2911,34 @@ int snd_pcm_poll_descriptors(snd_pcm_t *pcm, struct pollfd *pfds, return 0; } -int is_utf8_string(const char* string) -{ +int is_utf8_string(const char* string) { return is_utf8_string_ret_value; } -int cras_alsa_mmap_get_whole_buffer(snd_pcm_t *handle, uint8_t **dst) -{ +int cras_alsa_mmap_get_whole_buffer(snd_pcm_t* handle, uint8_t** dst) { snd_pcm_uframes_t offset, frames; cras_alsa_mmap_get_whole_buffer_called++; return cras_alsa_mmap_begin(handle, 0, dst, &offset, &frames); } -int cras_alsa_resume_appl_ptr(snd_pcm_t *handle, snd_pcm_uframes_t ahead) -{ +int cras_alsa_resume_appl_ptr(snd_pcm_t* handle, snd_pcm_uframes_t ahead) { cras_alsa_resume_appl_ptr_called++; cras_alsa_resume_appl_ptr_ahead = ahead; return 0; } -int cras_iodev_default_no_stream_playback(struct cras_iodev *odev, int enable) -{ +int cras_iodev_default_no_stream_playback(struct cras_iodev* odev, int enable) { return 0; } -enum CRAS_IODEV_STATE cras_iodev_state(const struct cras_iodev *iodev) -{ +enum CRAS_IODEV_STATE cras_iodev_state(const struct cras_iodev* iodev) { return iodev->state; } -int cras_iodev_dsp_set_swap_mode_for_node(struct cras_iodev *iodev, - struct cras_ionode *node, - int enable) -{ +int cras_iodev_dsp_set_swap_mode_for_node(struct cras_iodev* iodev, + struct cras_ionode* node, + int enable) { cras_iodev_dsp_set_swap_mode_for_node_called++; return 0; } diff --git a/cras/src/tests/alsa_jack_unittest.cc b/cras/src/tests/alsa_jack_unittest.cc index 5f64d3cd..24b43a31 100644 --- a/cras/src/tests/alsa_jack_unittest.cc +++ b/cras/src/tests/alsa_jack_unittest.cc @@ -2,15 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <deque> +#include <gtest/gtest.h> #include <linux/input.h> -#include <map> #include <poll.h> #include <stdio.h> #include <sys/param.h> -#include <gtest/gtest.h> -#include <string> #include <syslog.h> + +#include <deque> +#include <map> +#include <string> #include <vector> extern "C" { @@ -24,51 +25,51 @@ extern "C" { namespace { -#define BITS_PER_BYTE (8) -#define BITS_PER_LONG (sizeof(long) * BITS_PER_BYTE) -#define NBITS(x) ((((x) - 1) / BITS_PER_LONG) + 1) -#define OFF(x) ((x) % BITS_PER_LONG) -#define BIT(x) (1UL << OFF(x)) -#define LONG(x) ((x) / BITS_PER_LONG) -#define IS_BIT_SET(bit, array) !!((array[LONG(bit)]) & (1UL << OFF(bit))) +#define BITS_PER_BYTE (8) +#define BITS_PER_LONG (sizeof(long) * BITS_PER_BYTE) +#define NBITS(x) ((((x)-1) / BITS_PER_LONG) + 1) +#define OFF(x) ((x) % BITS_PER_LONG) +#define BIT(x) (1UL << OFF(x)) +#define LONG(x) ((x) / BITS_PER_LONG) +#define IS_BIT_SET(bit, array) !!((array[LONG(bit)]) & (1UL << OFF(bit))) static int fake_jack_cb_plugged; -static void *fake_jack_cb_data; +static void* fake_jack_cb_data; static size_t fake_jack_cb_called; unsigned int snd_hctl_elem_get_device_return_val; unsigned int snd_hctl_elem_get_device_called; static size_t snd_hctl_first_elem_called; -static snd_hctl_elem_t *snd_hctl_first_elem_return_val; +static snd_hctl_elem_t* snd_hctl_first_elem_return_val; static size_t snd_hctl_elem_next_called; -std::deque<snd_hctl_elem_t *> snd_hctl_elem_next_ret_vals; -std::deque<snd_hctl_elem_t *> snd_hctl_elem_next_ret_vals_poped; +std::deque<snd_hctl_elem_t*> snd_hctl_elem_next_ret_vals; +std::deque<snd_hctl_elem_t*> snd_hctl_elem_next_ret_vals_poped; static size_t snd_hctl_elem_get_name_called; static size_t snd_hctl_elem_set_callback_called; -static snd_hctl_elem_t *snd_hctl_elem_set_callback_obj; +static snd_hctl_elem_t* snd_hctl_elem_set_callback_obj; static snd_hctl_elem_callback_t snd_hctl_elem_set_callback_value; static size_t snd_hctl_find_elem_called; -static std::vector<snd_hctl_elem_t *> snd_hctl_find_elem_return_vals; +static std::vector<snd_hctl_elem_t*> snd_hctl_find_elem_return_vals; static std::map<std::string, size_t> snd_ctl_elem_id_set_name_map; static size_t cras_system_add_select_fd_called; static std::vector<int> cras_system_add_select_fd_values; static size_t cras_system_rm_select_fd_called; static std::vector<int> cras_system_rm_select_fd_values; static size_t snd_hctl_elem_set_callback_private_called; -static void *snd_hctl_elem_set_callback_private_value; +static void* snd_hctl_elem_set_callback_private_value; static size_t snd_hctl_elem_get_hctl_called; -static snd_hctl_t *snd_hctl_elem_get_hctl_return_value; +static snd_hctl_t* snd_hctl_elem_get_hctl_return_value; static size_t snd_ctl_elem_value_get_boolean_called; static int snd_ctl_elem_value_get_boolean_return_value; -static void *fake_jack_cb_arg; -static struct cras_alsa_mixer *fake_mixer; +static void* fake_jack_cb_arg; +static struct cras_alsa_mixer* fake_mixer; static size_t cras_alsa_mixer_get_output_matching_name_called; static size_t cras_alsa_mixer_get_input_matching_name_called; static size_t cras_alsa_mixer_get_control_for_section_called; -static struct mixer_control * +static struct mixer_control* cras_alsa_mixer_get_output_matching_name_return_value; -static struct mixer_control * +static struct mixer_control* cras_alsa_mixer_get_input_matching_name_return_value; -static struct mixer_control * +static struct mixer_control* cras_alsa_mixer_get_control_for_section_return_value; static size_t gpio_switch_list_for_each_called; static std::vector<std::string> gpio_switch_list_for_each_dev_paths; @@ -78,15 +79,15 @@ static size_t gpio_switch_eviocgsw_called; static size_t gpio_switch_eviocgbit_called; static unsigned ucm_get_dev_for_jack_called; static unsigned ucm_get_cap_control_called; -static char *ucm_get_cap_control_value; +static char* ucm_get_cap_control_value; static bool ucm_get_dev_for_jack_return; static int ucm_set_enabled_value; static unsigned long eviocbit_ret[NBITS(SW_CNT)]; static int gpio_switch_eviocgbit_fd; -static const char *edid_file_ret; +static const char* edid_file_ret; static unsigned ucm_get_override_type_name_called; -static char *ucm_get_device_name_for_dev_value; -static snd_hctl_t *fake_hctl = (snd_hctl_t *)2; +static char* ucm_get_device_name_for_dev_value; +static snd_hctl_t* fake_hctl = (snd_hctl_t*)2; static void ResetStubData() { gpio_switch_list_for_each_called = 0; @@ -100,7 +101,7 @@ static void ResetStubData() { snd_hctl_elem_get_device_return_val = 0; snd_hctl_elem_get_device_called = 0; snd_hctl_first_elem_called = 0; - snd_hctl_first_elem_return_val = reinterpret_cast<snd_hctl_elem_t *>(0x87); + snd_hctl_first_elem_return_val = reinterpret_cast<snd_hctl_elem_t*>(0x87); snd_hctl_elem_next_called = 0; snd_hctl_elem_next_ret_vals.clear(); snd_hctl_elem_next_ret_vals_poped.clear(); @@ -120,16 +121,16 @@ static void ResetStubData() { snd_ctl_elem_value_get_boolean_called = 0; fake_jack_cb_called = 0; fake_jack_cb_plugged = 0; - fake_jack_cb_arg = reinterpret_cast<void *>(0x987); - fake_mixer = reinterpret_cast<struct cras_alsa_mixer *>(0x789); + fake_jack_cb_arg = reinterpret_cast<void*>(0x987); + fake_mixer = reinterpret_cast<struct cras_alsa_mixer*>(0x789); cras_alsa_mixer_get_output_matching_name_called = 0; cras_alsa_mixer_get_input_matching_name_called = 0; cras_alsa_mixer_get_control_for_section_called = 0; cras_alsa_mixer_get_output_matching_name_return_value = - reinterpret_cast<struct mixer_control *>(0x456); + reinterpret_cast<struct mixer_control*>(0x456); cras_alsa_mixer_get_input_matching_name_return_value = NULL; cras_alsa_mixer_get_control_for_section_return_value = - reinterpret_cast<struct mixer_control *>(0x456); + reinterpret_cast<struct mixer_control*>(0x456); ucm_get_dev_for_jack_called = 0; ucm_get_cap_control_called = 0; ucm_get_cap_control_value = NULL; @@ -141,10 +142,9 @@ static void ResetStubData() { memset(eviocbit_ret, 0, sizeof(eviocbit_ret)); } -static void fake_jack_cb(const struct cras_alsa_jack *jack, +static void fake_jack_cb(const struct cras_alsa_jack* jack, int plugged, - void *data) -{ + void* data) { fake_jack_cb_called++; fake_jack_cb_plugged = plugged; fake_jack_cb_data = data; @@ -157,15 +157,12 @@ static void fake_jack_cb(const struct cras_alsa_jack *jack, } TEST(AlsaJacks, CreateNullHctl) { - struct cras_alsa_jack_list *jack_list; + struct cras_alsa_jack_list* jack_list; ResetStubData(); - jack_list = cras_alsa_jack_list_create(0, "c1", 0, 1, - fake_mixer, - NULL, NULL, - CRAS_STREAM_OUTPUT, - fake_jack_cb, + jack_list = cras_alsa_jack_list_create(0, "c1", 0, 1, fake_mixer, NULL, NULL, + CRAS_STREAM_OUTPUT, fake_jack_cb, fake_jack_cb_arg); - ASSERT_NE(static_cast<struct cras_alsa_jack_list *>(NULL), jack_list); + ASSERT_NE(static_cast<struct cras_alsa_jack_list*>(NULL), jack_list); EXPECT_EQ(0, cras_alsa_jack_list_find_jacks_by_name_matching(jack_list)); EXPECT_EQ(1, gpio_switch_list_for_each_called); EXPECT_EQ(0, gpio_switch_open_called); @@ -176,17 +173,14 @@ TEST(AlsaJacks, CreateNullHctl) { } TEST(AlsaJacks, CreateNoElements) { - struct cras_alsa_jack_list *jack_list; + struct cras_alsa_jack_list* jack_list; ResetStubData(); snd_hctl_first_elem_return_val = NULL; - jack_list = cras_alsa_jack_list_create(0, "c1", 0, 1, - fake_mixer, - NULL, fake_hctl, - CRAS_STREAM_OUTPUT, - fake_jack_cb, - fake_jack_cb_arg); - ASSERT_NE(static_cast<struct cras_alsa_jack_list *>(NULL), jack_list); + jack_list = cras_alsa_jack_list_create(0, "c1", 0, 1, fake_mixer, NULL, + fake_hctl, CRAS_STREAM_OUTPUT, + fake_jack_cb, fake_jack_cb_arg); + ASSERT_NE(static_cast<struct cras_alsa_jack_list*>(NULL), jack_list); EXPECT_EQ(0, cras_alsa_jack_list_find_jacks_by_name_matching(jack_list)); EXPECT_EQ(1, gpio_switch_list_for_each_called); EXPECT_EQ(0, gpio_switch_open_called); @@ -198,31 +192,25 @@ TEST(AlsaJacks, CreateNoElements) { cras_alsa_jack_list_destroy(jack_list); } -static struct cras_alsa_jack_list *run_test_with_elem_list( +static struct cras_alsa_jack_list* run_test_with_elem_list( CRAS_STREAM_DIRECTION direction, - std::string *elems, + std::string* elems, unsigned int device_index, - struct cras_use_case_mgr *ucm, + struct cras_use_case_mgr* ucm, size_t nelems, size_t nhdmi_jacks, size_t njacks) { - struct cras_alsa_jack_list *jack_list; + struct cras_alsa_jack_list* jack_list; snd_hctl_first_elem_return_val = - reinterpret_cast<snd_hctl_elem_t *>(&elems[0]); + reinterpret_cast<snd_hctl_elem_t*>(&elems[0]); for (unsigned int i = 1; i < nelems; i++) snd_hctl_elem_next_ret_vals.push_front( - reinterpret_cast<snd_hctl_elem_t *>(&elems[i])); - - jack_list = cras_alsa_jack_list_create(0, - "card_name", - device_index, - 1, - fake_mixer, - ucm, fake_hctl, - direction, - fake_jack_cb, - fake_jack_cb_arg); + reinterpret_cast<snd_hctl_elem_t*>(&elems[i])); + + jack_list = cras_alsa_jack_list_create(0, "card_name", device_index, 1, + fake_mixer, ucm, fake_hctl, direction, + fake_jack_cb, fake_jack_cb_arg); if (jack_list == NULL) return jack_list; EXPECT_EQ(0, cras_alsa_jack_list_find_jacks_by_name_matching(jack_list)); @@ -247,17 +235,17 @@ static struct cras_alsa_jack_list *run_test_with_elem_list( return jack_list; } -static struct cras_alsa_jack_list *run_test_with_section( +static struct cras_alsa_jack_list* run_test_with_section( CRAS_STREAM_DIRECTION direction, - std::string *elems, + std::string* elems, size_t nelems, unsigned int device_index, - struct cras_use_case_mgr *ucm, - struct ucm_section *ucm_section, + struct cras_use_case_mgr* ucm, + struct ucm_section* ucm_section, int add_jack_rc, size_t njacks) { - struct cras_alsa_jack_list *jack_list; - struct cras_alsa_jack *jack; + struct cras_alsa_jack_list* jack_list; + struct cras_alsa_jack* jack; for (size_t i = 0; i < nelems; i++) { snd_ctl_elem_id_set_name_map[elems[i]] = i; @@ -265,23 +253,17 @@ static struct cras_alsa_jack_list *run_test_with_section( reinterpret_cast<snd_hctl_elem_t*>(&elems[i])); } - jack_list = cras_alsa_jack_list_create(0, - "card_name", - device_index, - 1, - fake_mixer, - ucm, fake_hctl, - direction, - fake_jack_cb, - fake_jack_cb_arg); + jack_list = cras_alsa_jack_list_create(0, "card_name", device_index, 1, + fake_mixer, ucm, fake_hctl, direction, + fake_jack_cb, fake_jack_cb_arg); if (jack_list == NULL) return jack_list; - EXPECT_EQ(add_jack_rc, - cras_alsa_jack_list_add_jack_for_section(jack_list, ucm_section, &jack)); + EXPECT_EQ(add_jack_rc, cras_alsa_jack_list_add_jack_for_section( + jack_list, ucm_section, &jack)); if (add_jack_rc == 0) { - EXPECT_NE(jack, reinterpret_cast<struct cras_alsa_jack *>(NULL)); + EXPECT_NE(jack, reinterpret_cast<struct cras_alsa_jack*>(NULL)); } else { - EXPECT_EQ(jack, reinterpret_cast<struct cras_alsa_jack *>(NULL)); + EXPECT_EQ(jack, reinterpret_cast<struct cras_alsa_jack*>(NULL)); } if (add_jack_rc != 0) { cras_alsa_jack_list_destroy(jack_list); @@ -299,28 +281,23 @@ TEST(AlsaJacks, ReportNull) { TEST(AlsaJacks, CreateNoJacks) { static std::string elem_names[] = { - "Mic Jack", - "foo", - "bar", + "Mic Jack", + "foo", + "bar", }; - struct cras_alsa_jack_list *jack_list; + struct cras_alsa_jack_list* jack_list; ResetStubData(); - jack_list = run_test_with_elem_list(CRAS_STREAM_OUTPUT, - elem_names, - 0, - NULL, - ARRAY_SIZE(elem_names), - 0, - 0); - ASSERT_NE(static_cast<struct cras_alsa_jack_list *>(NULL), jack_list); + jack_list = run_test_with_elem_list(CRAS_STREAM_OUTPUT, elem_names, 0, NULL, + ARRAY_SIZE(elem_names), 0, 0); + ASSERT_NE(static_cast<struct cras_alsa_jack_list*>(NULL), jack_list); cras_alsa_jack_list_destroy(jack_list); EXPECT_EQ(0, cras_system_rm_select_fd_called); } TEST(AlsaJacks, CreateGPIOHp) { - struct cras_alsa_jack_list *jack_list; + struct cras_alsa_jack_list* jack_list; ResetStubData(); gpio_switch_list_for_each_dev_names.push_back("some-other-device"); @@ -328,13 +305,10 @@ TEST(AlsaJacks, CreateGPIOHp) { eviocbit_ret[LONG(SW_HEADPHONE_INSERT)] |= 1 << OFF(SW_HEADPHONE_INSERT); gpio_switch_eviocgbit_fd = 2; snd_hctl_first_elem_return_val = NULL; - jack_list = cras_alsa_jack_list_create(0, "c1", 0, 1, - fake_mixer, - NULL, fake_hctl, - CRAS_STREAM_OUTPUT, - fake_jack_cb, - fake_jack_cb_arg); - ASSERT_NE(static_cast<struct cras_alsa_jack_list *>(NULL), jack_list); + jack_list = cras_alsa_jack_list_create(0, "c1", 0, 1, fake_mixer, NULL, + fake_hctl, CRAS_STREAM_OUTPUT, + fake_jack_cb, fake_jack_cb_arg); + ASSERT_NE(static_cast<struct cras_alsa_jack_list*>(NULL), jack_list); EXPECT_EQ(0, cras_alsa_jack_list_find_jacks_by_name_matching(jack_list)); cras_alsa_jack_list_destroy(jack_list); EXPECT_EQ(1, gpio_switch_list_for_each_called); @@ -346,7 +320,7 @@ TEST(AlsaJacks, CreateGPIOHp) { } TEST(AlsaJacks, CreateGPIOMic) { - struct cras_alsa_jack_list *jack_list; + struct cras_alsa_jack_list* jack_list; ResetStubData(); ucm_get_dev_for_jack_return = true; gpio_switch_list_for_each_dev_names.push_back("c1 Mic Jack"); @@ -354,23 +328,16 @@ TEST(AlsaJacks, CreateGPIOMic) { eviocbit_ret[LONG(SW_MICROPHONE_INSERT)] |= 1 << OFF(SW_MICROPHONE_INSERT); gpio_switch_eviocgbit_fd = 3; snd_hctl_first_elem_return_val = NULL; - ucm_get_cap_control_value = reinterpret_cast<char *>(0x1); + ucm_get_cap_control_value = reinterpret_cast<char*>(0x1); cras_alsa_mixer_get_input_matching_name_return_value = - reinterpret_cast<struct mixer_control *>(malloc(1)); + reinterpret_cast<struct mixer_control*>(malloc(1)); jack_list = cras_alsa_jack_list_create( - 0, - "c1", - 0, - 1, - fake_mixer, - reinterpret_cast<struct cras_use_case_mgr *>(0x55), - fake_hctl, - CRAS_STREAM_INPUT, - fake_jack_cb, - fake_jack_cb_arg); - ASSERT_NE(static_cast<struct cras_alsa_jack_list *>(NULL), jack_list); + 0, "c1", 0, 1, fake_mixer, + reinterpret_cast<struct cras_use_case_mgr*>(0x55), fake_hctl, + CRAS_STREAM_INPUT, fake_jack_cb, fake_jack_cb_arg); + ASSERT_NE(static_cast<struct cras_alsa_jack_list*>(NULL), jack_list); EXPECT_EQ(0, cras_alsa_jack_list_find_jacks_by_name_matching(jack_list)); EXPECT_EQ(ucm_get_cap_control_called, 1); EXPECT_EQ(cras_alsa_mixer_get_input_matching_name_called, 1); @@ -380,7 +347,7 @@ TEST(AlsaJacks, CreateGPIOMic) { } TEST(AlsaJacks, CreateGPIOHdmi) { - struct cras_alsa_jack_list *jack_list; + struct cras_alsa_jack_list* jack_list; ResetStubData(); gpio_switch_list_for_each_dev_names.push_back("c1 HDMI Jack"); @@ -388,13 +355,10 @@ TEST(AlsaJacks, CreateGPIOHdmi) { eviocbit_ret[LONG(SW_LINEOUT_INSERT)] |= 1 << OFF(SW_LINEOUT_INSERT); gpio_switch_eviocgbit_fd = 3; snd_hctl_first_elem_return_val = NULL; - jack_list = cras_alsa_jack_list_create(0, "c1", 0, 1, - fake_mixer, - NULL, fake_hctl, - CRAS_STREAM_OUTPUT, - fake_jack_cb, - fake_jack_cb_arg); - ASSERT_NE(static_cast<struct cras_alsa_jack_list *>(NULL), jack_list); + jack_list = cras_alsa_jack_list_create(0, "c1", 0, 1, fake_mixer, NULL, + fake_hctl, CRAS_STREAM_OUTPUT, + fake_jack_cb, fake_jack_cb_arg); + ASSERT_NE(static_cast<struct cras_alsa_jack_list*>(NULL), jack_list); EXPECT_EQ(0, cras_alsa_jack_list_find_jacks_by_name_matching(jack_list)); EXPECT_EQ(1, gpio_switch_eviocgsw_called); @@ -411,16 +375,14 @@ TEST(AlsaJacks, CreateGPIOHdmi) { EXPECT_EQ(1, cras_system_rm_select_fd_called); } -void run_gpio_jack_test( - int device_index, - int is_first_device, - enum CRAS_STREAM_DIRECTION direction, - int should_create_jack, - const char* jack_name) -{ - struct cras_alsa_jack_list *jack_list; - struct cras_use_case_mgr *ucm = - reinterpret_cast<struct cras_use_case_mgr *>(0x55); +void run_gpio_jack_test(int device_index, + int is_first_device, + enum CRAS_STREAM_DIRECTION direction, + int should_create_jack, + const char* jack_name) { + struct cras_alsa_jack_list* jack_list; + struct cras_use_case_mgr* ucm = + reinterpret_cast<struct cras_use_case_mgr*>(0x55); gpio_switch_list_for_each_dev_names.push_back("some-other-device one"); gpio_switch_eviocgbit_fd = 2; @@ -432,14 +394,10 @@ void run_gpio_jack_test( gpio_switch_list_for_each_dev_names.push_back(jack_name); snd_hctl_first_elem_return_val = NULL; - jack_list = cras_alsa_jack_list_create(0, "c1", device_index, - is_first_device, - fake_mixer, - ucm, fake_hctl, - direction, - fake_jack_cb, - fake_jack_cb_arg); - ASSERT_NE(static_cast<struct cras_alsa_jack_list *>(NULL), jack_list); + jack_list = cras_alsa_jack_list_create(0, "c1", device_index, is_first_device, + fake_mixer, ucm, fake_hctl, direction, + fake_jack_cb, fake_jack_cb_arg); + ASSERT_NE(static_cast<struct cras_alsa_jack_list*>(NULL), jack_list); EXPECT_EQ(0, cras_alsa_jack_list_find_jacks_by_name_matching(jack_list)); cras_alsa_jack_list_report(jack_list); @@ -461,9 +419,8 @@ TEST(AlsaJacks, CreateGPIOHpUCMPlaybackPCMMatched) { ucm_get_dev_for_jack_return = true; ucm_get_device_name_for_dev_value = strdup("hw:c1,1"); - run_gpio_jack_test( - device_index, is_first_device, direction, should_create_jack, - "c1 Headset Jack"); + run_gpio_jack_test(device_index, is_first_device, direction, + should_create_jack, "c1 Headset Jack"); } TEST(AlsaJacks, CreateGPIOHpUCMCapturePCMMatched) { @@ -478,9 +435,8 @@ TEST(AlsaJacks, CreateGPIOHpUCMCapturePCMMatched) { ucm_get_dev_for_jack_return = true; ucm_get_device_name_for_dev_value = strdup("hw:c1,1"); - run_gpio_jack_test( - device_index, is_first_device, direction, should_create_jack, - "c1 Mic Jack"); + run_gpio_jack_test(device_index, is_first_device, direction, + should_create_jack, "c1 Mic Jack"); } TEST(AlsaJacks, CreateGPIOHpUCMPlaybackPCMNotMatched) { @@ -495,9 +451,8 @@ TEST(AlsaJacks, CreateGPIOHpUCMPlaybackPCMNotMatched) { ucm_get_dev_for_jack_return = true; ucm_get_device_name_for_dev_value = strdup("hw:c1,2"); - run_gpio_jack_test( - device_index, is_first_device, direction, should_create_jack, - "c1 Headset Jack"); + run_gpio_jack_test(device_index, is_first_device, direction, + should_create_jack, "c1 Headset Jack"); } TEST(AlsaJacks, CreateGPIOHpUCMPlaybackPCMNotSpecifiedFirstDevice) { @@ -512,9 +467,8 @@ TEST(AlsaJacks, CreateGPIOHpUCMPlaybackPCMNotSpecifiedFirstDevice) { ucm_get_dev_for_jack_return = true; ucm_get_device_name_for_dev_value = NULL; - run_gpio_jack_test( - device_index, is_first_device, direction, should_create_jack, - "c1 Headset Jack"); + run_gpio_jack_test(device_index, is_first_device, direction, + should_create_jack, "c1 Headset Jack"); } TEST(AlsaJacks, CreateGPIOHpUCMPlaybackPCMNotSpecifiedSecondDevice) { @@ -529,9 +483,8 @@ TEST(AlsaJacks, CreateGPIOHpUCMPlaybackPCMNotSpecifiedSecondDevice) { ucm_get_dev_for_jack_return = true; ucm_get_device_name_for_dev_value = NULL; - run_gpio_jack_test( - device_index, is_first_device, direction, should_create_jack, - "c1 Headset Jack"); + run_gpio_jack_test(device_index, is_first_device, direction, + should_create_jack, "c1 Headset Jack"); } TEST(AlsaJacks, CreateGPIOHpNoUCMFirstDevice) { @@ -546,9 +499,8 @@ TEST(AlsaJacks, CreateGPIOHpNoUCMFirstDevice) { ucm_get_dev_for_jack_return = false; ucm_get_device_name_for_dev_value = NULL; - run_gpio_jack_test( - device_index, is_first_device, direction, should_create_jack, - "c1 Headset Jack"); + run_gpio_jack_test(device_index, is_first_device, direction, + should_create_jack, "c1 Headset Jack"); } TEST(AlsaJacks, CreateGPIOHpNoUCMSecondDevice) { @@ -563,9 +515,8 @@ TEST(AlsaJacks, CreateGPIOHpNoUCMSecondDevice) { ucm_get_dev_for_jack_return = false; ucm_get_device_name_for_dev_value = NULL; - run_gpio_jack_test( - device_index, is_first_device, direction, should_create_jack, - "c1 Headset Jack"); + run_gpio_jack_test(device_index, is_first_device, direction, + should_create_jack, "c1 Headset Jack"); } TEST(AlsaJacks, CreateGPIOMicNoUCMFirstDeviceMicJack) { @@ -581,9 +532,8 @@ TEST(AlsaJacks, CreateGPIOMicNoUCMFirstDeviceMicJack) { ucm_get_device_name_for_dev_value = NULL; // Mic Jack is a valid name for microphone jack. - run_gpio_jack_test( - device_index, is_first_device, direction, should_create_jack, - "c1 Mic Jack"); + run_gpio_jack_test(device_index, is_first_device, direction, + should_create_jack, "c1 Mic Jack"); } TEST(AlsaJacks, CreateGPIOMicNoUCMFirstDeviceHeadsetJack) { @@ -599,9 +549,8 @@ TEST(AlsaJacks, CreateGPIOMicNoUCMFirstDeviceHeadsetJack) { ucm_get_device_name_for_dev_value = NULL; // Headset Jack is a valid name for microphone jack. - run_gpio_jack_test( - device_index, is_first_device, direction, should_create_jack, - "c1 Headset Jack"); + run_gpio_jack_test(device_index, is_first_device, direction, + should_create_jack, "c1 Headset Jack"); } TEST(AlsaJacks, GPIOHdmiWithEdid) { @@ -615,16 +564,9 @@ TEST(AlsaJacks, GPIOHdmiWithEdid) { gpio_switch_eviocgbit_fd = 3; snd_hctl_first_elem_return_val = NULL; jack_list = cras_alsa_jack_list_create( - 0, - "c1", - 0, - 1, - fake_mixer, - reinterpret_cast<struct cras_use_case_mgr *>(0x55), - fake_hctl, - CRAS_STREAM_OUTPUT, - fake_jack_cb, - fake_jack_cb_arg); + 0, "c1", 0, 1, fake_mixer, + reinterpret_cast<struct cras_use_case_mgr*>(0x55), fake_hctl, + CRAS_STREAM_OUTPUT, fake_jack_cb, fake_jack_cb_arg); ASSERT_NE(static_cast<cras_alsa_jack_list*>(NULL), jack_list); EXPECT_EQ(0, cras_alsa_jack_list_find_jacks_by_name_matching(jack_list)); EXPECT_EQ(1, gpio_switch_eviocgsw_called); @@ -643,19 +585,16 @@ TEST(AlsaJacks, GPIOHdmiWithEdid) { } TEST(AlsaJacks, CreateGPIOHpNoNameMatch) { - struct cras_alsa_jack_list *jack_list; + struct cras_alsa_jack_list* jack_list; ResetStubData(); gpio_switch_list_for_each_dev_names.push_back("some-other-device one"); gpio_switch_list_for_each_dev_names.push_back("some-other-device two"); snd_hctl_first_elem_return_val = NULL; - jack_list = cras_alsa_jack_list_create(0, "c2", 0, 1, - fake_mixer, - NULL, fake_hctl, - CRAS_STREAM_OUTPUT, - fake_jack_cb, - fake_jack_cb_arg); - ASSERT_NE(static_cast<struct cras_alsa_jack_list *>(NULL), jack_list); + jack_list = cras_alsa_jack_list_create(0, "c2", 0, 1, fake_mixer, NULL, + fake_hctl, CRAS_STREAM_OUTPUT, + fake_jack_cb, fake_jack_cb_arg); + ASSERT_NE(static_cast<struct cras_alsa_jack_list*>(NULL), jack_list); EXPECT_EQ(0, cras_alsa_jack_list_find_jacks_by_name_matching(jack_list)); cras_alsa_jack_list_destroy(jack_list); @@ -667,35 +606,30 @@ TEST(AlsaJacks, CreateGPIOHpNoNameMatch) { TEST(AlsaJacks, CreateOneHpJack) { std::string elem_names[] = { - "asdf", - "Headphone Jack, klasdjf", - "Mic Jack", + "asdf", + "Headphone Jack, klasdjf", + "Mic Jack", }; - struct cras_alsa_jack_list *jack_list; + struct cras_alsa_jack_list* jack_list; ResetStubData(); - jack_list = run_test_with_elem_list(CRAS_STREAM_OUTPUT, - elem_names, - 0, - NULL, - ARRAY_SIZE(elem_names), - 0, - 1); - ASSERT_NE(static_cast<struct cras_alsa_jack_list *>(NULL), jack_list); + jack_list = run_test_with_elem_list(CRAS_STREAM_OUTPUT, elem_names, 0, NULL, + ARRAY_SIZE(elem_names), 0, 1); + ASSERT_NE(static_cast<struct cras_alsa_jack_list*>(NULL), jack_list); ASSERT_NE(reinterpret_cast<snd_hctl_elem_callback_t>(NULL), snd_hctl_elem_set_callback_value); EXPECT_EQ(1, snd_hctl_elem_set_callback_called); - snd_hctl_elem_get_hctl_return_value = reinterpret_cast<snd_hctl_t *>(0x33); + snd_hctl_elem_get_hctl_return_value = reinterpret_cast<snd_hctl_t*>(0x33); snd_hctl_elem_get_name_called = 0; snd_ctl_elem_value_get_boolean_return_value = 1; snd_hctl_elem_set_callback_value( - reinterpret_cast<snd_hctl_elem_t *>(&elem_names[1]), 0); + reinterpret_cast<snd_hctl_elem_t*>(&elem_names[1]), 0); EXPECT_EQ(1, snd_hctl_elem_get_name_called); EXPECT_EQ(1, fake_jack_cb_plugged); EXPECT_EQ(1, fake_jack_cb_called); EXPECT_EQ(fake_jack_cb_arg, fake_jack_cb_data); - EXPECT_EQ(reinterpret_cast<snd_hctl_elem_t *>(&elem_names[1]), + EXPECT_EQ(reinterpret_cast<snd_hctl_elem_t*>(&elem_names[1]), snd_hctl_elem_set_callback_obj); fake_jack_cb_called = 0; @@ -711,23 +645,15 @@ TEST(AlsaJacks, CreateOneHpJack) { TEST(AlsaJacks, CreateOneMicJack) { static std::string elem_names[] = { - "asdf", - "Headphone Jack", - "HDMI/DP,pcm=5 Jack", - "HDMI/DP,pcm=6 Jack", - "Mic Jack", + "asdf", "Headphone Jack", "HDMI/DP,pcm=5 Jack", "HDMI/DP,pcm=6 Jack", + "Mic Jack", }; - struct cras_alsa_jack_list *jack_list; + struct cras_alsa_jack_list* jack_list; ResetStubData(); - jack_list = run_test_with_elem_list(CRAS_STREAM_INPUT, - elem_names, - 0, - NULL, - ARRAY_SIZE(elem_names), - 0, - 1); - ASSERT_NE(static_cast<struct cras_alsa_jack_list *>(NULL), jack_list); + jack_list = run_test_with_elem_list(CRAS_STREAM_INPUT, elem_names, 0, NULL, + ARRAY_SIZE(elem_names), 0, 1); + ASSERT_NE(static_cast<struct cras_alsa_jack_list*>(NULL), jack_list); ASSERT_NE(reinterpret_cast<snd_hctl_elem_callback_t>(NULL), snd_hctl_elem_set_callback_value); EXPECT_EQ(1, snd_hctl_elem_set_callback_called); @@ -740,26 +666,16 @@ TEST(AlsaJacks, CreateOneMicJack) { } TEST(AlsaJacks, CreateHDMIJacksWithELD) { - std::string elem_names[] = { - "asdf", - "HDMI/DP,pcm=3 Jack", - "ELD", - "HDMI/DP,pcm=4 Jack" - }; - struct cras_alsa_jack_list *jack_list; + std::string elem_names[] = {"asdf", "HDMI/DP,pcm=3 Jack", "ELD", + "HDMI/DP,pcm=4 Jack"}; + struct cras_alsa_jack_list* jack_list; ResetStubData(); snd_hctl_elem_get_device_return_val = 3; - jack_list = run_test_with_elem_list( - CRAS_STREAM_OUTPUT, - elem_names, - 3, - NULL, - ARRAY_SIZE(elem_names), - 1, - 1); - ASSERT_NE(static_cast<struct cras_alsa_jack_list *>(NULL), jack_list); + jack_list = run_test_with_elem_list(CRAS_STREAM_OUTPUT, elem_names, 3, NULL, + ARRAY_SIZE(elem_names), 1, 1); + ASSERT_NE(static_cast<struct cras_alsa_jack_list*>(NULL), jack_list); /* Assert get device is called for the ELD control */ EXPECT_EQ(1, snd_hctl_elem_get_device_called); @@ -768,36 +684,32 @@ TEST(AlsaJacks, CreateHDMIJacksWithELD) { TEST(AlsaJacks, CreateOneHpTwoHDMIJacks) { std::string elem_names[] = { - "asdf", - "Headphone Jack, klasdjf", - "HDMI/DP,pcm=5 Jack", - "HDMI/DP,pcm=6 Jack", - "Mic Jack", + "asdf", + "Headphone Jack, klasdjf", + "HDMI/DP,pcm=5 Jack", + "HDMI/DP,pcm=6 Jack", + "Mic Jack", }; - struct cras_alsa_jack_list *jack_list; + struct cras_alsa_jack_list* jack_list; ResetStubData(); ucm_get_dev_for_jack_return = true; - jack_list = run_test_with_elem_list( - CRAS_STREAM_OUTPUT, - elem_names, - 5, - reinterpret_cast<struct cras_use_case_mgr *>(0x55), - ARRAY_SIZE(elem_names), - 1, - 1); - ASSERT_NE(static_cast<struct cras_alsa_jack_list *>(NULL), jack_list); - - snd_hctl_elem_get_hctl_return_value = reinterpret_cast<snd_hctl_t *>(0x33); + jack_list = + run_test_with_elem_list(CRAS_STREAM_OUTPUT, elem_names, 5, + reinterpret_cast<struct cras_use_case_mgr*>(0x55), + ARRAY_SIZE(elem_names), 1, 1); + ASSERT_NE(static_cast<struct cras_alsa_jack_list*>(NULL), jack_list); + + snd_hctl_elem_get_hctl_return_value = reinterpret_cast<snd_hctl_t*>(0x33); snd_hctl_elem_get_name_called = 0; snd_ctl_elem_value_get_boolean_return_value = 1; snd_hctl_elem_set_callback_value( - reinterpret_cast<snd_hctl_elem_t *>(&elem_names[2]), 0); + reinterpret_cast<snd_hctl_elem_t*>(&elem_names[2]), 0); EXPECT_EQ(1, snd_hctl_elem_get_name_called); EXPECT_EQ(1, fake_jack_cb_plugged); EXPECT_EQ(1, fake_jack_cb_called); EXPECT_EQ(fake_jack_cb_arg, fake_jack_cb_data); - EXPECT_EQ(reinterpret_cast<snd_hctl_elem_t *>(&elem_names[2]), + EXPECT_EQ(reinterpret_cast<snd_hctl_elem_t*>(&elem_names[2]), snd_hctl_elem_set_callback_obj); fake_jack_cb_called = 0; @@ -810,11 +722,11 @@ TEST(AlsaJacks, CreateOneHpTwoHDMIJacks) { TEST(AlsaJacks, CreateHCTLHeadphoneJackFromUCM) { std::string elem_names[] = { - "HP/DP,pcm=5 Jack", - "Headphone Jack", + "HP/DP,pcm=5 Jack", + "Headphone Jack", }; - struct cras_alsa_jack_list *jack_list; - struct ucm_section *section; + struct cras_alsa_jack_list* jack_list; + struct ucm_section* section; section = ucm_section_create("Headphone", 0, CRAS_STREAM_OUTPUT, "Headphone Jack", "hctl"); @@ -823,25 +735,19 @@ TEST(AlsaJacks, CreateHCTLHeadphoneJackFromUCM) { ucm_get_dev_for_jack_return = true; jack_list = run_test_with_section( - CRAS_STREAM_OUTPUT, - elem_names, - ARRAY_SIZE(elem_names), - 5, - reinterpret_cast<struct cras_use_case_mgr *>(0x55), - section, - 0, - 1); - ASSERT_NE(reinterpret_cast<struct cras_alsa_jack_list *>(NULL), jack_list); - - snd_hctl_elem_get_hctl_return_value = reinterpret_cast<snd_hctl_t *>(0x33); + CRAS_STREAM_OUTPUT, elem_names, ARRAY_SIZE(elem_names), 5, + reinterpret_cast<struct cras_use_case_mgr*>(0x55), section, 0, 1); + ASSERT_NE(reinterpret_cast<struct cras_alsa_jack_list*>(NULL), jack_list); + + snd_hctl_elem_get_hctl_return_value = reinterpret_cast<snd_hctl_t*>(0x33); snd_ctl_elem_value_get_boolean_return_value = 1; snd_hctl_elem_set_callback_value( - reinterpret_cast<snd_hctl_elem_t *>(&elem_names[1]), 0); + reinterpret_cast<snd_hctl_elem_t*>(&elem_names[1]), 0); EXPECT_EQ(1, snd_hctl_elem_get_name_called); EXPECT_EQ(1, fake_jack_cb_plugged); EXPECT_EQ(1, fake_jack_cb_called); EXPECT_EQ(fake_jack_cb_arg, fake_jack_cb_data); - EXPECT_EQ(reinterpret_cast<snd_hctl_elem_t *>(&elem_names[1]), + EXPECT_EQ(reinterpret_cast<snd_hctl_elem_t*>(&elem_names[1]), snd_hctl_elem_set_callback_obj); fake_jack_cb_called = 0; @@ -854,9 +760,9 @@ TEST(AlsaJacks, CreateHCTLHeadphoneJackFromUCM) { } TEST(AlsaJacks, CreateGPIOHeadphoneJackFromUCM) { - struct cras_alsa_jack_list *jack_list; - struct cras_alsa_jack *jack; - struct ucm_section *section; + struct cras_alsa_jack_list* jack_list; + struct cras_alsa_jack* jack; + struct ucm_section* section; section = ucm_section_create("Headphone", 0, CRAS_STREAM_OUTPUT, "c1 Headphone Jack", "gpio"); @@ -867,15 +773,12 @@ TEST(AlsaJacks, CreateGPIOHeadphoneJackFromUCM) { eviocbit_ret[LONG(SW_HEADPHONE_INSERT)] |= 1 << OFF(SW_HEADPHONE_INSERT); gpio_switch_eviocgbit_fd = 2; snd_hctl_first_elem_return_val = NULL; - jack_list = cras_alsa_jack_list_create(0, "c1", 0, 1, - fake_mixer, - NULL, fake_hctl, - CRAS_STREAM_OUTPUT, - fake_jack_cb, - fake_jack_cb_arg); - ASSERT_NE(static_cast<struct cras_alsa_jack_list *>(NULL), jack_list); - EXPECT_EQ(0, cras_alsa_jack_list_add_jack_for_section( - jack_list, section, &jack)); + jack_list = cras_alsa_jack_list_create(0, "c1", 0, 1, fake_mixer, NULL, + fake_hctl, CRAS_STREAM_OUTPUT, + fake_jack_cb, fake_jack_cb_arg); + ASSERT_NE(static_cast<struct cras_alsa_jack_list*>(NULL), jack_list); + EXPECT_EQ( + 0, cras_alsa_jack_list_add_jack_for_section(jack_list, section, &jack)); EXPECT_EQ(1, gpio_switch_list_for_each_called); EXPECT_GT(gpio_switch_open_called, 1); EXPECT_EQ(1, gpio_switch_eviocgsw_called); @@ -897,11 +800,11 @@ TEST(AlsaJacks, CreateGPIOHeadphoneJackFromUCM) { TEST(AlsaJacks, BadJackTypeFromUCM) { std::string elem_names[] = { - "HP/DP,pcm=5 Jack", - "Headphone Jack", + "HP/DP,pcm=5 Jack", + "Headphone Jack", }; - struct cras_alsa_jack_list *jack_list; - struct ucm_section *section; + struct cras_alsa_jack_list* jack_list; + struct ucm_section* section; section = ucm_section_create("Headphone", 0, CRAS_STREAM_OUTPUT, "Headphone Jack", "badtype"); @@ -910,26 +813,20 @@ TEST(AlsaJacks, BadJackTypeFromUCM) { ucm_get_dev_for_jack_return = true; jack_list = run_test_with_section( - CRAS_STREAM_OUTPUT, - elem_names, - ARRAY_SIZE(elem_names), - 5, - reinterpret_cast<struct cras_use_case_mgr *>(0x55), - section, - -22, - 1); - EXPECT_EQ(reinterpret_cast<struct cras_alsa_jack_list *>(NULL), jack_list); + CRAS_STREAM_OUTPUT, elem_names, ARRAY_SIZE(elem_names), 5, + reinterpret_cast<struct cras_use_case_mgr*>(0x55), section, -22, 1); + EXPECT_EQ(reinterpret_cast<struct cras_alsa_jack_list*>(NULL), jack_list); ucm_section_free_list(section); } TEST(AlsaJacks, NoJackTypeFromUCM) { std::string elem_names[] = { - "HP/DP,pcm=5 Jack", - "Headphone Jack", + "HP/DP,pcm=5 Jack", + "Headphone Jack", }; - struct cras_alsa_jack_list *jack_list; - struct ucm_section *section; + struct cras_alsa_jack_list* jack_list; + struct ucm_section* section; section = ucm_section_create("Headphone", 0, CRAS_STREAM_OUTPUT, "Headphone Jack", NULL); @@ -938,15 +835,9 @@ TEST(AlsaJacks, NoJackTypeFromUCM) { ucm_get_dev_for_jack_return = true; jack_list = run_test_with_section( - CRAS_STREAM_OUTPUT, - elem_names, - ARRAY_SIZE(elem_names), - 5, - reinterpret_cast<struct cras_use_case_mgr *>(0x55), - section, - -22, - 1); - EXPECT_EQ(reinterpret_cast<struct cras_alsa_jack_list *>(NULL), jack_list); + CRAS_STREAM_OUTPUT, elem_names, ARRAY_SIZE(elem_names), 5, + reinterpret_cast<struct cras_use_case_mgr*>(0x55), section, -22, 1); + EXPECT_EQ(reinterpret_cast<struct cras_alsa_jack_list*>(NULL), jack_list); ucm_section_free_list(section); } @@ -957,87 +848,83 @@ extern "C" { // From cras_system_state int cras_system_add_select_fd(int fd, - void (*callback)(void *data), - void *callback_data) -{ + void (*callback)(void* data), + void* callback_data) { cras_system_add_select_fd_called++; cras_system_add_select_fd_values.push_back(fd); return 0; } -void cras_system_rm_select_fd(int fd) -{ +void cras_system_rm_select_fd(int fd) { cras_system_rm_select_fd_called++; cras_system_rm_select_fd_values.push_back(fd); } // From alsa-lib hcontrol.c -unsigned int snd_hctl_elem_get_device(const snd_hctl_elem_t *obj) { +unsigned int snd_hctl_elem_get_device(const snd_hctl_elem_t* obj) { snd_hctl_elem_get_device_called = 1; return snd_hctl_elem_get_device_return_val; } -snd_hctl_elem_t *snd_hctl_first_elem(snd_hctl_t *hctl) { +snd_hctl_elem_t* snd_hctl_first_elem(snd_hctl_t* hctl) { snd_hctl_first_elem_called++; /* When first elem is called, restored the poped ret values */ while (!snd_hctl_elem_next_ret_vals_poped.empty()) { - snd_hctl_elem_t *tmp = snd_hctl_elem_next_ret_vals_poped.back(); + snd_hctl_elem_t* tmp = snd_hctl_elem_next_ret_vals_poped.back(); snd_hctl_elem_next_ret_vals_poped.pop_back(); snd_hctl_elem_next_ret_vals.push_back(tmp); } return snd_hctl_first_elem_return_val; } -snd_hctl_elem_t *snd_hctl_elem_next(snd_hctl_elem_t *elem) { +snd_hctl_elem_t* snd_hctl_elem_next(snd_hctl_elem_t* elem) { snd_hctl_elem_next_called++; if (snd_hctl_elem_next_ret_vals.empty()) return NULL; - snd_hctl_elem_t *ret_elem = snd_hctl_elem_next_ret_vals.back(); + snd_hctl_elem_t* ret_elem = snd_hctl_elem_next_ret_vals.back(); snd_hctl_elem_next_ret_vals.pop_back(); snd_hctl_elem_next_ret_vals_poped.push_back(ret_elem); return ret_elem; } -const char *snd_hctl_elem_get_name(const snd_hctl_elem_t *obj) { +const char* snd_hctl_elem_get_name(const snd_hctl_elem_t* obj) { snd_hctl_elem_get_name_called++; - const std::string *name = reinterpret_cast<const std::string *>(obj); + const std::string* name = reinterpret_cast<const std::string*>(obj); return name->c_str(); } -snd_ctl_elem_iface_t snd_hctl_elem_get_interface(const snd_hctl_elem_t *obj) { +snd_ctl_elem_iface_t snd_hctl_elem_get_interface(const snd_hctl_elem_t* obj) { return SND_CTL_ELEM_IFACE_CARD; } -void snd_hctl_elem_set_callback(snd_hctl_elem_t *obj, +void snd_hctl_elem_set_callback(snd_hctl_elem_t* obj, snd_hctl_elem_callback_t val) { snd_hctl_elem_set_callback_called++; snd_hctl_elem_set_callback_obj = obj; snd_hctl_elem_set_callback_value = val; } -void snd_hctl_elem_set_callback_private(snd_hctl_elem_t *obj, void * val) { +void snd_hctl_elem_set_callback_private(snd_hctl_elem_t* obj, void* val) { snd_hctl_elem_set_callback_private_called++; snd_hctl_elem_set_callback_private_value = val; } -void *snd_hctl_elem_get_callback_private(const snd_hctl_elem_t *obj) { +void* snd_hctl_elem_get_callback_private(const snd_hctl_elem_t* obj) { return snd_hctl_elem_set_callback_private_value; } -snd_hctl_t *snd_hctl_elem_get_hctl(snd_hctl_elem_t *elem) { +snd_hctl_t* snd_hctl_elem_get_hctl(snd_hctl_elem_t* elem) { snd_hctl_elem_get_hctl_called++; return snd_hctl_elem_get_hctl_return_value; } -int snd_hctl_elem_read(snd_hctl_elem_t *elem, snd_ctl_elem_value_t * value) { +int snd_hctl_elem_read(snd_hctl_elem_t* elem, snd_ctl_elem_value_t* value) { return 0; } -snd_hctl_elem_t *snd_hctl_find_elem(snd_hctl_t *hctl, - const snd_ctl_elem_id_t *id) { +snd_hctl_elem_t* snd_hctl_find_elem(snd_hctl_t* hctl, + const snd_ctl_elem_id_t* id) { const size_t* index = reinterpret_cast<const size_t*>(id); snd_hctl_find_elem_called++; if (*index < snd_hctl_find_elem_return_vals.size()) return snd_hctl_find_elem_return_vals[*index]; return NULL; } -void snd_ctl_elem_id_set_interface(snd_ctl_elem_id_t *obj, - snd_ctl_elem_iface_t val) { -} -void snd_ctl_elem_id_set_device(snd_ctl_elem_id_t *obj, unsigned int val) { -} -void snd_ctl_elem_id_set_name(snd_ctl_elem_id_t *obj, const char *val) { - size_t *obj_id = reinterpret_cast<size_t*>(obj); +void snd_ctl_elem_id_set_interface(snd_ctl_elem_id_t* obj, + snd_ctl_elem_iface_t val) {} +void snd_ctl_elem_id_set_device(snd_ctl_elem_id_t* obj, unsigned int val) {} +void snd_ctl_elem_id_set_name(snd_ctl_elem_id_t* obj, const char* val) { + size_t* obj_id = reinterpret_cast<size_t*>(obj); std::map<std::string, size_t>::iterator id_name_it = snd_ctl_elem_id_set_name_map.find(val); if (id_name_it != snd_ctl_elem_id_set_name_map.end()) @@ -1047,48 +934,44 @@ void snd_ctl_elem_id_set_name(snd_ctl_elem_id_t *obj, const char *val) { } // From alsa-lib control.c -int snd_ctl_elem_value_get_boolean(const snd_ctl_elem_value_t *obj, +int snd_ctl_elem_value_get_boolean(const snd_ctl_elem_value_t* obj, unsigned int idx) { snd_ctl_elem_value_get_boolean_called++; return snd_ctl_elem_value_get_boolean_return_value; } // From cras_alsa_mixer -struct mixer_control *cras_alsa_mixer_get_output_matching_name( - const struct cras_alsa_mixer *cras_mixer, +struct mixer_control* cras_alsa_mixer_get_output_matching_name( + const struct cras_alsa_mixer* cras_mixer, size_t device_index, - const char * const name) -{ + const char* const name) { cras_alsa_mixer_get_output_matching_name_called++; return cras_alsa_mixer_get_output_matching_name_return_value; } -struct mixer_control *cras_alsa_mixer_get_input_matching_name( - struct cras_alsa_mixer *cras_mixer, - const char *control_name) -{ +struct mixer_control* cras_alsa_mixer_get_input_matching_name( + struct cras_alsa_mixer* cras_mixer, + const char* control_name) { cras_alsa_mixer_get_input_matching_name_called++; return cras_alsa_mixer_get_input_matching_name_return_value; } -struct mixer_control *cras_alsa_mixer_get_control_for_section( - struct cras_alsa_mixer *cras_mixer, - struct ucm_section *section) -{ +struct mixer_control* cras_alsa_mixer_get_control_for_section( + struct cras_alsa_mixer* cras_mixer, + struct ucm_section* section) { cras_alsa_mixer_get_control_for_section_called++; return cras_alsa_mixer_get_control_for_section_return_value; } -int gpio_switch_eviocgbit(int fd, void *buf, size_t n_bytes) -{ - unsigned char *p = (unsigned char *)buf; +int gpio_switch_eviocgbit(int fd, void* buf, size_t n_bytes) { + unsigned char* p = (unsigned char*)buf; /* Returns >= 0 if 'sw' is supported, negative if not. * * Set the bit corresponding to 'sw' in 'buf'. 'buf' must have * been allocated by the caller to accommodate this. */ - if (fd == gpio_switch_eviocgbit_fd) + if (fd == gpio_switch_eviocgbit_fd) memcpy(p, eviocbit_ret, n_bytes); else memset(p, 0, n_bytes); @@ -1097,8 +980,7 @@ int gpio_switch_eviocgbit(int fd, void *buf, size_t n_bytes) return 1; } -int gpio_switch_eviocgsw(int fd, void *bits, size_t n_bytes) -{ +int gpio_switch_eviocgsw(int fd, void* bits, size_t n_bytes) { /* Bits set to '1' indicate a switch is enabled. * Bits set to '0' indicate a switch is disabled */ @@ -1107,8 +989,7 @@ int gpio_switch_eviocgsw(int fd, void *bits, size_t n_bytes) return 1; } -int gpio_switch_read(int fd, void *buf, size_t n_bytes) -{ +int gpio_switch_read(int fd, void* buf, size_t n_bytes) { /* This function is only invoked when the 'switch has changed' * callback is invoked. That code is not exercised by this * unittest. @@ -1117,18 +998,16 @@ int gpio_switch_read(int fd, void *buf, size_t n_bytes) return 0; } -int gpio_switch_open(const char *pathname) -{ +int gpio_switch_open(const char* pathname) { ++gpio_switch_open_called; if (strstr(pathname, "event2")) - return 2; + return 2; if (strstr(pathname, "event3")) - return 3; + return 3; return 0; } -void gpio_switch_list_for_each(gpio_switch_list_callback callback, void *arg) -{ +void gpio_switch_list_for_each(gpio_switch_list_callback callback, void* arg) { size_t i = 0; ++gpio_switch_list_for_each_called; @@ -1136,75 +1015,73 @@ void gpio_switch_list_for_each(gpio_switch_list_callback callback, void *arg) while (i < gpio_switch_list_for_each_dev_names.size() && i < gpio_switch_list_for_each_dev_paths.size()) { callback(gpio_switch_list_for_each_dev_paths[i].c_str(), - gpio_switch_list_for_each_dev_names[i].c_str(), - arg); + gpio_switch_list_for_each_dev_names[i].c_str(), arg); i++; } } -int ucm_set_enabled( - struct cras_use_case_mgr *mgr, const char *dev, int enable) { +int ucm_set_enabled(struct cras_use_case_mgr* mgr, + const char* dev, + int enable) { ucm_set_enabled_value = enable; return 0; } -char *ucm_get_cap_control(struct cras_use_case_mgr *mgr, const char *ucm_dev) { +char* ucm_get_cap_control(struct cras_use_case_mgr* mgr, const char* ucm_dev) { ++ucm_get_cap_control_called; return ucm_get_cap_control_value; } -char *ucm_get_dev_for_jack(struct cras_use_case_mgr *mgr, const char *jack, +char* ucm_get_dev_for_jack(struct cras_use_case_mgr* mgr, + const char* jack, CRAS_STREAM_DIRECTION direction) { ++ucm_get_dev_for_jack_called; if (ucm_get_dev_for_jack_return) - return static_cast<char*>(malloc(1)); // Will be freed in jack_list_destroy. + return static_cast<char*>( + malloc(1)); // Will be freed in jack_list_destroy. return NULL; } -const char *ucm_get_edid_file_for_dev(struct cras_use_case_mgr *mgr, - const char *dev) { +const char* ucm_get_edid_file_for_dev(struct cras_use_case_mgr* mgr, + const char* dev) { return edid_file_ret; } -const char *ucm_get_override_type_name(struct cras_use_case_mgr *mgr, - const char *ucm_dev) -{ +const char* ucm_get_override_type_name(struct cras_use_case_mgr* mgr, + const char* ucm_dev) { ++ucm_get_override_type_name_called; return NULL; } -const char *ucm_get_device_name_for_dev(struct cras_use_case_mgr *mgr, - const char *dev, - enum CRAS_STREAM_DIRECTION direction) -{ +const char* ucm_get_device_name_for_dev(struct cras_use_case_mgr* mgr, + const char* dev, + enum CRAS_STREAM_DIRECTION direction) { return ucm_get_device_name_for_dev_value; } -cras_timer *cras_tm_create_timer( - cras_tm *tm, - unsigned int ms, - void (*cb)(cras_timer *t, void *data), - void *cb_data) { +cras_timer* cras_tm_create_timer(cras_tm* tm, + unsigned int ms, + void (*cb)(cras_timer* t, void* data), + void* cb_data) { return reinterpret_cast<cras_timer*>(0x55); } -void cras_tm_cancel_timer(cras_tm *tm, cras_timer *t) { -} +void cras_tm_cancel_timer(cras_tm* tm, cras_timer* t) {} -cras_tm *cras_system_state_get_tm() { +cras_tm* cras_system_state_get_tm() { return reinterpret_cast<cras_tm*>(0x66); } -int edid_valid(const unsigned char *edid_data) { +int edid_valid(const unsigned char* edid_data) { return 0; } -int edid_lpcm_support(const unsigned char *edid_data, int ext) { +int edid_lpcm_support(const unsigned char* edid_data, int ext) { return 0; } -int edid_get_monitor_name(const unsigned char *edid_data, - char *buf, +int edid_get_monitor_name(const unsigned char* edid_data, + char* buf, unsigned int buf_size) { return 0; } @@ -1219,7 +1096,7 @@ int wait_for_dev_input_access() { } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); openlog(NULL, LOG_PERROR, LOG_USER); return RUN_ALL_TESTS(); diff --git a/cras/src/tests/alsa_mixer_unittest.cc b/cras/src/tests/alsa_mixer_unittest.cc index 2deef7fb..d61ba3df 100644 --- a/cras/src/tests/alsa_mixer_unittest.cc +++ b/cras/src/tests/alsa_mixer_unittest.cc @@ -2,11 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <stdio.h> #include <gtest/gtest.h> +#include <stdio.h> +#include <syslog.h> + #include <map> #include <string> -#include <syslog.h> #include <vector> extern "C" { @@ -29,60 +30,60 @@ static int snd_mixer_open_return_value; static size_t snd_mixer_close_called; static size_t snd_mixer_attach_called; static int snd_mixer_attach_return_value; -const char *snd_mixer_attach_mixdev; +const char* snd_mixer_attach_mixdev; static size_t snd_mixer_selem_register_called; static int snd_mixer_selem_register_return_value; static size_t snd_mixer_load_called; static int snd_mixer_load_return_value; static size_t snd_mixer_first_elem_called; -static snd_mixer_elem_t *snd_mixer_first_elem_return_value; +static snd_mixer_elem_t* snd_mixer_first_elem_return_value; static int snd_mixer_elem_next_called; -static snd_mixer_elem_t **snd_mixer_elem_next_return_values; +static snd_mixer_elem_t** snd_mixer_elem_next_return_values; static int snd_mixer_elem_next_return_values_index; static int snd_mixer_elem_next_return_values_length; static int snd_mixer_selem_set_playback_dB_all_called; -static long *snd_mixer_selem_set_playback_dB_all_values; +static long* snd_mixer_selem_set_playback_dB_all_values; static int snd_mixer_selem_set_playback_dB_all_values_length; static int snd_mixer_selem_set_playback_switch_all_called; static int snd_mixer_selem_set_playback_switch_all_value; static int snd_mixer_selem_has_playback_volume_called; -static int *snd_mixer_selem_has_playback_volume_return_values; +static int* snd_mixer_selem_has_playback_volume_return_values; static int snd_mixer_selem_has_playback_volume_return_values_length; static int snd_mixer_selem_has_playback_switch_called; -static int *snd_mixer_selem_has_playback_switch_return_values; +static int* snd_mixer_selem_has_playback_switch_return_values; static int snd_mixer_selem_has_playback_switch_return_values_length; static int snd_mixer_selem_set_capture_dB_all_called; -static long *snd_mixer_selem_set_capture_dB_all_values; +static long* snd_mixer_selem_set_capture_dB_all_values; static int snd_mixer_selem_set_capture_dB_all_values_length; static int snd_mixer_selem_set_capture_switch_all_called; static int snd_mixer_selem_set_capture_switch_all_value; static int snd_mixer_selem_has_capture_volume_called; -static int *snd_mixer_selem_has_capture_volume_return_values; +static int* snd_mixer_selem_has_capture_volume_return_values; static int snd_mixer_selem_has_capture_volume_return_values_length; static int snd_mixer_selem_has_capture_switch_called; -static int *snd_mixer_selem_has_capture_switch_return_values; +static int* snd_mixer_selem_has_capture_switch_return_values; static int snd_mixer_selem_has_capture_switch_return_values_length; static int snd_mixer_selem_get_name_called; -static const char **snd_mixer_selem_get_name_return_values; +static const char** snd_mixer_selem_get_name_return_values; static int snd_mixer_selem_get_name_return_values_length; static int snd_mixer_selem_get_playback_dB_called; -static long *snd_mixer_selem_get_playback_dB_return_values; +static long* snd_mixer_selem_get_playback_dB_return_values; static int snd_mixer_selem_get_playback_dB_return_values_length; static int snd_mixer_selem_get_capture_dB_called; -static long *snd_mixer_selem_get_capture_dB_return_values; +static long* snd_mixer_selem_get_capture_dB_return_values; static int snd_mixer_selem_get_capture_dB_return_values_length; static size_t cras_volume_curve_destroy_called; static size_t snd_mixer_selem_get_playback_dB_range_called; static size_t snd_mixer_selem_get_playback_dB_range_values_length; -static const long *snd_mixer_selem_get_playback_dB_range_min_values; -static const long *snd_mixer_selem_get_playback_dB_range_max_values; +static const long* snd_mixer_selem_get_playback_dB_range_min_values; +static const long* snd_mixer_selem_get_playback_dB_range_max_values; static size_t snd_mixer_selem_get_capture_dB_range_called; static size_t snd_mixer_selem_get_capture_dB_range_values_length; -static const long *snd_mixer_selem_get_capture_dB_range_min_values; -static const long *snd_mixer_selem_get_capture_dB_range_max_values; +static const long* snd_mixer_selem_get_capture_dB_range_min_values; +static const long* snd_mixer_selem_get_capture_dB_range_max_values; static size_t iniparser_getstring_return_index; static size_t iniparser_getstring_return_length; -static char **iniparser_getstring_returns; +static char** iniparser_getstring_returns; static size_t snd_mixer_find_selem_called; static std::map<std::string, snd_mixer_elem_t*> snd_mixer_find_elem_map; static std::string snd_mixer_find_elem_id_name; @@ -95,88 +96,88 @@ static void ResetStubData() { snd_mixer_close_called = 0; snd_mixer_attach_called = 0; snd_mixer_attach_return_value = 0; - snd_mixer_attach_mixdev = static_cast<const char *>(NULL); + snd_mixer_attach_mixdev = static_cast<const char*>(NULL); snd_mixer_selem_register_called = 0; snd_mixer_selem_register_return_value = 0; snd_mixer_load_called = 0; snd_mixer_load_return_value = 0; snd_mixer_first_elem_called = 0; - snd_mixer_first_elem_return_value = static_cast<snd_mixer_elem_t *>(NULL); + snd_mixer_first_elem_return_value = static_cast<snd_mixer_elem_t*>(NULL); snd_mixer_elem_next_called = 0; - snd_mixer_elem_next_return_values = static_cast<snd_mixer_elem_t **>(NULL); + snd_mixer_elem_next_return_values = static_cast<snd_mixer_elem_t**>(NULL); snd_mixer_elem_next_return_values_index = 0; snd_mixer_elem_next_return_values_length = 0; snd_mixer_selem_set_playback_dB_all_called = 0; - snd_mixer_selem_set_playback_dB_all_values = static_cast<long *>(NULL); + snd_mixer_selem_set_playback_dB_all_values = static_cast<long*>(NULL); snd_mixer_selem_set_playback_dB_all_values_length = 0; snd_mixer_selem_set_playback_switch_all_called = 0; snd_mixer_selem_has_playback_volume_called = 0; - snd_mixer_selem_has_playback_volume_return_values = static_cast<int *>(NULL); + snd_mixer_selem_has_playback_volume_return_values = static_cast<int*>(NULL); snd_mixer_selem_has_playback_volume_return_values_length = 0; snd_mixer_selem_has_playback_switch_called = 0; - snd_mixer_selem_has_playback_switch_return_values = static_cast<int *>(NULL); + snd_mixer_selem_has_playback_switch_return_values = static_cast<int*>(NULL); snd_mixer_selem_has_playback_switch_return_values_length = 0; snd_mixer_selem_set_capture_dB_all_called = 0; - snd_mixer_selem_set_capture_dB_all_values = static_cast<long *>(NULL); + snd_mixer_selem_set_capture_dB_all_values = static_cast<long*>(NULL); snd_mixer_selem_set_capture_dB_all_values_length = 0; snd_mixer_selem_set_capture_switch_all_called = 0; snd_mixer_selem_has_capture_volume_called = 0; - snd_mixer_selem_has_capture_volume_return_values = static_cast<int *>(NULL); + snd_mixer_selem_has_capture_volume_return_values = static_cast<int*>(NULL); snd_mixer_selem_has_capture_volume_return_values_length = 0; snd_mixer_selem_has_capture_switch_called = 0; - snd_mixer_selem_has_capture_switch_return_values = static_cast<int *>(NULL); + snd_mixer_selem_has_capture_switch_return_values = static_cast<int*>(NULL); snd_mixer_selem_has_capture_switch_return_values_length = 0; snd_mixer_selem_get_name_called = 0; - snd_mixer_selem_get_name_return_values = static_cast<const char **>(NULL); + snd_mixer_selem_get_name_return_values = static_cast<const char**>(NULL); snd_mixer_selem_get_name_return_values_length = 0; snd_mixer_selem_get_playback_dB_called = 0; - snd_mixer_selem_get_playback_dB_return_values = static_cast<long *>(NULL); + snd_mixer_selem_get_playback_dB_return_values = static_cast<long*>(NULL); snd_mixer_selem_get_playback_dB_return_values_length = 0; snd_mixer_selem_get_capture_dB_called = 0; - snd_mixer_selem_get_capture_dB_return_values = static_cast<long *>(NULL); + snd_mixer_selem_get_capture_dB_return_values = static_cast<long*>(NULL); snd_mixer_selem_get_capture_dB_return_values_length = 0; cras_volume_curve_destroy_called = 0; snd_mixer_selem_get_playback_dB_range_called = 0; snd_mixer_selem_get_playback_dB_range_values_length = 0; - snd_mixer_selem_get_playback_dB_range_min_values = static_cast<long *>(NULL); - snd_mixer_selem_get_playback_dB_range_max_values = static_cast<long *>(NULL); + snd_mixer_selem_get_playback_dB_range_min_values = static_cast<long*>(NULL); + snd_mixer_selem_get_playback_dB_range_max_values = static_cast<long*>(NULL); snd_mixer_selem_get_capture_dB_range_called = 0; snd_mixer_selem_get_capture_dB_range_values_length = 0; - snd_mixer_selem_get_capture_dB_range_min_values = static_cast<long *>(NULL); - snd_mixer_selem_get_capture_dB_range_max_values = static_cast<long *>(NULL); + snd_mixer_selem_get_capture_dB_range_min_values = static_cast<long*>(NULL); + snd_mixer_selem_get_capture_dB_range_max_values = static_cast<long*>(NULL); snd_mixer_find_selem_called = 0; snd_mixer_find_elem_map.clear(); snd_mixer_find_elem_id_name.clear(); } -struct cras_alsa_mixer *create_mixer_and_add_controls_by_name_matching( - const char *card_name, - struct mixer_name *extra_controls, - struct mixer_name *coupled_controls) { - struct cras_alsa_mixer *cmix = cras_alsa_mixer_create(card_name); - cras_alsa_mixer_add_controls_by_name_matching( - cmix, extra_controls, coupled_controls); +struct cras_alsa_mixer* create_mixer_and_add_controls_by_name_matching( + const char* card_name, + struct mixer_name* extra_controls, + struct mixer_name* coupled_controls) { + struct cras_alsa_mixer* cmix = cras_alsa_mixer_create(card_name); + cras_alsa_mixer_add_controls_by_name_matching(cmix, extra_controls, + coupled_controls); return cmix; } TEST(AlsaMixer, CreateFailOpen) { - struct cras_alsa_mixer *c; + struct cras_alsa_mixer* c; ResetStubData(); snd_mixer_open_return_value = -1; c = cras_alsa_mixer_create("hw:0"); - EXPECT_NE(static_cast<struct cras_alsa_mixer *>(NULL), c); + EXPECT_NE(static_cast<struct cras_alsa_mixer*>(NULL), c); EXPECT_EQ(1, snd_mixer_open_called); cras_alsa_mixer_destroy(c); } TEST(AlsaMixer, CreateFailAttach) { - struct cras_alsa_mixer *c; + struct cras_alsa_mixer* c; ResetStubData(); snd_mixer_attach_return_value = -1; c = cras_alsa_mixer_create("hw:0"); - EXPECT_NE(static_cast<struct cras_alsa_mixer *>(NULL), c); + EXPECT_NE(static_cast<struct cras_alsa_mixer*>(NULL), c); EXPECT_EQ(1, snd_mixer_open_called); EXPECT_EQ(1, snd_mixer_attach_called); EXPECT_EQ(0, strcmp(snd_mixer_attach_mixdev, "hw:0")); @@ -185,12 +186,12 @@ TEST(AlsaMixer, CreateFailAttach) { } TEST(AlsaMixer, CreateFailSelemRegister) { - struct cras_alsa_mixer *c; + struct cras_alsa_mixer* c; ResetStubData(); snd_mixer_selem_register_return_value = -1; c = cras_alsa_mixer_create("hw:0"); - EXPECT_NE(static_cast<struct cras_alsa_mixer *>(NULL), c); + EXPECT_NE(static_cast<struct cras_alsa_mixer*>(NULL), c); EXPECT_EQ(1, snd_mixer_open_called); EXPECT_EQ(1, snd_mixer_attach_called); EXPECT_EQ(0, strcmp(snd_mixer_attach_mixdev, "hw:0")); @@ -200,12 +201,12 @@ TEST(AlsaMixer, CreateFailSelemRegister) { } TEST(AlsaMixer, CreateFailLoad) { - struct cras_alsa_mixer *c; + struct cras_alsa_mixer* c; ResetStubData(); snd_mixer_load_return_value = -1; c = cras_alsa_mixer_create("hw:0"); - EXPECT_NE(static_cast<struct cras_alsa_mixer *>(NULL), c); + EXPECT_NE(static_cast<struct cras_alsa_mixer*>(NULL), c); EXPECT_EQ(1, snd_mixer_open_called); EXPECT_EQ(1, snd_mixer_attach_called); EXPECT_EQ(0, strcmp(snd_mixer_attach_mixdev, "hw:0")); @@ -216,12 +217,11 @@ TEST(AlsaMixer, CreateFailLoad) { } TEST(AlsaMixer, CreateNoElements) { - struct cras_alsa_mixer *c; + struct cras_alsa_mixer* c; ResetStubData(); - c = create_mixer_and_add_controls_by_name_matching( - "hw:0", NULL, NULL); - ASSERT_NE(static_cast<struct cras_alsa_mixer *>(NULL), c); + c = create_mixer_and_add_controls_by_name_matching("hw:0", NULL, NULL); + ASSERT_NE(static_cast<struct cras_alsa_mixer*>(NULL), c); EXPECT_EQ(1, snd_mixer_open_called); EXPECT_EQ(1, snd_mixer_attach_called); EXPECT_EQ(0, strcmp(snd_mixer_attach_mixdev, "hw:0")); @@ -241,29 +241,28 @@ TEST(AlsaMixer, CreateNoElements) { } TEST(AlsaMixer, CreateOneUnknownElementWithoutVolume) { - struct cras_alsa_mixer *c; + struct cras_alsa_mixer* c; int element_playback_volume[] = { - 0, + 0, }; int element_playback_switches[] = { - 1, + 1, }; - const char *element_names[] = { - "Unknown", + const char* element_names[] = { + "Unknown", }; - struct mixer_control *mixer_output; + struct mixer_control* mixer_output; int rc; ResetStubData(); - snd_mixer_first_elem_return_value = reinterpret_cast<snd_mixer_elem_t *>(1); + snd_mixer_first_elem_return_value = reinterpret_cast<snd_mixer_elem_t*>(1); snd_mixer_selem_has_playback_volume_return_values = element_playback_volume; snd_mixer_selem_has_playback_volume_return_values_length = ARRAY_SIZE(element_playback_volume); snd_mixer_selem_get_name_return_values = element_names; snd_mixer_selem_get_name_return_values_length = ARRAY_SIZE(element_names); - c = create_mixer_and_add_controls_by_name_matching( - "hw:0", NULL, NULL); - ASSERT_NE(static_cast<struct cras_alsa_mixer *>(NULL), c); + c = create_mixer_and_add_controls_by_name_matching("hw:0", NULL, NULL); + ASSERT_NE(static_cast<struct cras_alsa_mixer*>(NULL), c); EXPECT_EQ(1, snd_mixer_open_called); EXPECT_EQ(1, snd_mixer_attach_called); EXPECT_EQ(0, strcmp(snd_mixer_attach_mixdev, "hw:0")); @@ -285,7 +284,7 @@ TEST(AlsaMixer, CreateOneUnknownElementWithoutVolume) { snd_mixer_selem_get_name_return_values = element_names; snd_mixer_selem_get_name_return_values_length = ARRAY_SIZE(element_names); rc = mixer_control_create(&mixer_output, NULL, - reinterpret_cast<snd_mixer_elem_t *>(1), + reinterpret_cast<snd_mixer_elem_t*>(1), CRAS_STREAM_OUTPUT); EXPECT_EQ(0, rc); EXPECT_EQ(1, snd_mixer_selem_get_name_called); @@ -306,26 +305,26 @@ TEST(AlsaMixer, CreateOneUnknownElementWithoutVolume) { } TEST(AlsaMixer, CreateOneUnknownElementWithVolume) { - struct cras_alsa_mixer *c; + struct cras_alsa_mixer* c; static const long min_volumes[] = {-500}; static const long max_volumes[] = {40}; int element_playback_volume[] = { - 1, - 0, + 1, + 0, }; int element_playback_switches[] = { - 0, - 1, + 0, + 1, }; - const char *element_names[] = { - "Unknown", - "Playback", + const char* element_names[] = { + "Unknown", + "Playback", }; - struct mixer_control *mixer_output; + struct mixer_control* mixer_output; int rc; ResetStubData(); - snd_mixer_first_elem_return_value = reinterpret_cast<snd_mixer_elem_t *>(1); + snd_mixer_first_elem_return_value = reinterpret_cast<snd_mixer_elem_t*>(1); snd_mixer_selem_has_playback_volume_return_values = element_playback_volume; snd_mixer_selem_has_playback_volume_return_values_length = ARRAY_SIZE(element_playback_volume); @@ -334,9 +333,8 @@ TEST(AlsaMixer, CreateOneUnknownElementWithVolume) { snd_mixer_selem_get_playback_dB_range_min_values = min_volumes; snd_mixer_selem_get_playback_dB_range_max_values = max_volumes; snd_mixer_selem_get_playback_dB_range_values_length = ARRAY_SIZE(min_volumes); - c = create_mixer_and_add_controls_by_name_matching( - "hw:0", NULL, NULL); - ASSERT_NE(static_cast<struct cras_alsa_mixer *>(NULL), c); + c = create_mixer_and_add_controls_by_name_matching("hw:0", NULL, NULL); + ASSERT_NE(static_cast<struct cras_alsa_mixer*>(NULL), c); EXPECT_EQ(1, snd_mixer_open_called); EXPECT_EQ(1, snd_mixer_attach_called); EXPECT_EQ(0, strcmp(snd_mixer_attach_mixdev, "hw:0")); @@ -361,7 +359,7 @@ TEST(AlsaMixer, CreateOneUnknownElementWithVolume) { snd_mixer_selem_get_name_return_values = element_names; snd_mixer_selem_get_name_return_values_length = ARRAY_SIZE(element_names); rc = mixer_control_create(&mixer_output, NULL, - reinterpret_cast<snd_mixer_elem_t *>(2), + reinterpret_cast<snd_mixer_elem_t*>(2), CRAS_STREAM_OUTPUT); EXPECT_EQ(0, rc); EXPECT_EQ(1, snd_mixer_selem_get_name_called); @@ -384,27 +382,24 @@ TEST(AlsaMixer, CreateOneUnknownElementWithVolume) { } TEST(AlsaMixer, CreateOneMasterElement) { - struct cras_alsa_mixer *c; + struct cras_alsa_mixer* c; int element_playback_volume[] = { - 1, - 1, + 1, + 1, }; int element_playback_switches[] = { - 1, - 1, - }; - const char *element_names[] = { - "Master", - "Playback" + 1, + 1, }; - struct mixer_control *mixer_output; + const char* element_names[] = {"Master", "Playback"}; + struct mixer_control* mixer_output; int rc; long set_dB_values[3]; static const long min_volumes[] = {0, 0}; static const long max_volumes[] = {950, 950}; ResetStubData(); - snd_mixer_first_elem_return_value = reinterpret_cast<snd_mixer_elem_t *>(1); + snd_mixer_first_elem_return_value = reinterpret_cast<snd_mixer_elem_t*>(1); snd_mixer_selem_has_playback_volume_return_values = element_playback_volume; snd_mixer_selem_has_playback_volume_return_values_length = ARRAY_SIZE(element_playback_volume); @@ -413,9 +408,8 @@ TEST(AlsaMixer, CreateOneMasterElement) { ARRAY_SIZE(element_playback_switches); snd_mixer_selem_get_name_return_values = element_names; snd_mixer_selem_get_name_return_values_length = ARRAY_SIZE(element_names); - c = create_mixer_and_add_controls_by_name_matching( - "hw:0", NULL, NULL); - ASSERT_NE(static_cast<struct cras_alsa_mixer *>(NULL), c); + c = create_mixer_and_add_controls_by_name_matching("hw:0", NULL, NULL); + ASSERT_NE(static_cast<struct cras_alsa_mixer*>(NULL), c); EXPECT_EQ(1, snd_mixer_open_called); EXPECT_EQ(1, snd_mixer_attach_called); EXPECT_EQ(0, strcmp(snd_mixer_attach_mixdev, "hw:0")); @@ -434,8 +428,7 @@ TEST(AlsaMixer, CreateOneMasterElement) { ResetStubData(); snd_mixer_selem_set_playback_dB_all_values = set_dB_values; - snd_mixer_selem_set_playback_dB_all_values_length = - ARRAY_SIZE(set_dB_values); + snd_mixer_selem_set_playback_dB_all_values_length = ARRAY_SIZE(set_dB_values); snd_mixer_selem_get_playback_dB_range_min_values = min_volumes; snd_mixer_selem_get_playback_dB_range_max_values = max_volumes; snd_mixer_selem_get_playback_dB_range_values_length = ARRAY_SIZE(min_volumes); @@ -445,7 +438,7 @@ TEST(AlsaMixer, CreateOneMasterElement) { snd_mixer_selem_get_name_return_values = element_names; snd_mixer_selem_get_name_return_values_length = ARRAY_SIZE(element_names); rc = mixer_control_create(&mixer_output, NULL, - reinterpret_cast<snd_mixer_elem_t *>(2), + reinterpret_cast<snd_mixer_elem_t*>(2), CRAS_STREAM_OUTPUT); EXPECT_EQ(0, rc); EXPECT_EQ(1, snd_mixer_selem_get_name_called); @@ -465,26 +458,26 @@ TEST(AlsaMixer, CreateOneMasterElement) { } TEST(AlsaMixer, CreateTwoMainVolumeElements) { - struct cras_alsa_mixer *c; - snd_mixer_elem_t *elements[] = { - reinterpret_cast<snd_mixer_elem_t *>(2), + struct cras_alsa_mixer* c; + snd_mixer_elem_t* elements[] = { + reinterpret_cast<snd_mixer_elem_t*>(2), }; int element_playback_volume[] = { - 1, - 1, - 1, + 1, + 1, + 1, }; int element_playback_switches[] = { - 1, - 1, - 1, + 1, + 1, + 1, }; - const char *element_names[] = { - "Master", - "PCM", - "Other", + const char* element_names[] = { + "Master", + "PCM", + "Other", }; - struct mixer_control *mixer_output; + struct mixer_control* mixer_output; int rc; static const long min_volumes[] = {-500, -1250, -500}; static const long max_volumes[] = {40, 40, 0}; @@ -492,7 +485,7 @@ TEST(AlsaMixer, CreateTwoMainVolumeElements) { long set_dB_values[3]; ResetStubData(); - snd_mixer_first_elem_return_value = reinterpret_cast<snd_mixer_elem_t *>(1); + snd_mixer_first_elem_return_value = reinterpret_cast<snd_mixer_elem_t*>(1); snd_mixer_elem_next_return_values = elements; snd_mixer_elem_next_return_values_length = ARRAY_SIZE(elements); snd_mixer_selem_has_playback_volume_return_values = element_playback_volume; @@ -508,11 +501,9 @@ TEST(AlsaMixer, CreateTwoMainVolumeElements) { snd_mixer_selem_get_playback_dB_range_max_values = max_volumes; snd_mixer_selem_get_playback_dB_range_values_length = ARRAY_SIZE(min_volumes); snd_mixer_selem_set_playback_dB_all_values = set_dB_values; - snd_mixer_selem_set_playback_dB_all_values_length = - ARRAY_SIZE(set_dB_values); - c = create_mixer_and_add_controls_by_name_matching( - "hw:0", NULL, NULL); - ASSERT_NE(static_cast<struct cras_alsa_mixer *>(NULL), c); + snd_mixer_selem_set_playback_dB_all_values_length = ARRAY_SIZE(set_dB_values); + c = create_mixer_and_add_controls_by_name_matching("hw:0", NULL, NULL); + ASSERT_NE(static_cast<struct cras_alsa_mixer*>(NULL), c); EXPECT_EQ(2, snd_mixer_selem_get_playback_dB_range_called); EXPECT_EQ(1, snd_mixer_open_called); EXPECT_EQ(1, snd_mixer_attach_called); @@ -558,7 +549,7 @@ TEST(AlsaMixer, CreateTwoMainVolumeElements) { snd_mixer_selem_get_name_return_values = element_names; snd_mixer_selem_get_name_return_values_length = ARRAY_SIZE(element_names); rc = mixer_control_create(&mixer_output, NULL, - reinterpret_cast<snd_mixer_elem_t *>(3), + reinterpret_cast<snd_mixer_elem_t*>(3), CRAS_STREAM_OUTPUT); EXPECT_EQ(0, rc); EXPECT_EQ(1, snd_mixer_selem_get_name_called); @@ -579,8 +570,8 @@ TEST(AlsaMixer, CreateTwoMainVolumeElements) { * sorted, Master should get the volume remaining after PCM is set, in this * case -50 - -24 = -26. */ long get_dB_returns2[] = { - -25, - -24, + -25, + -24, }; snd_mixer_selem_get_playback_dB_return_values = get_dB_returns2; snd_mixer_selem_get_playback_dB_return_values_length = @@ -593,8 +584,8 @@ TEST(AlsaMixer, CreateTwoMainVolumeElements) { cras_alsa_mixer_set_dBFS(c, -50, mixer_output); EXPECT_EQ(2, snd_mixer_selem_set_playback_dB_all_called); EXPECT_EQ(2, snd_mixer_selem_get_playback_dB_called); - EXPECT_EQ(54, set_dB_values[0]); // Master - EXPECT_EQ(30, set_dB_values[1]); // PCM + EXPECT_EQ(54, set_dB_values[0]); // Master + EXPECT_EQ(30, set_dB_values[1]); // PCM cras_alsa_mixer_destroy(c); EXPECT_EQ(1, snd_mixer_close_called); @@ -602,30 +593,30 @@ TEST(AlsaMixer, CreateTwoMainVolumeElements) { } TEST(AlsaMixer, CreateTwoMainCaptureElements) { - struct cras_alsa_mixer *c; - snd_mixer_elem_t *elements[] = { - reinterpret_cast<snd_mixer_elem_t *>(2), + struct cras_alsa_mixer* c; + snd_mixer_elem_t* elements[] = { + reinterpret_cast<snd_mixer_elem_t*>(2), }; int element_capture_volume[] = { - 1, - 1, - 1, + 1, + 1, + 1, }; int element_capture_switches[] = { - 1, - 1, - 1, + 1, + 1, + 1, }; - const char *element_names[] = { - "Capture", - "Digital Capture", - "Mic", + const char* element_names[] = { + "Capture", + "Digital Capture", + "Mic", }; - struct mixer_control *mixer_input; + struct mixer_control* mixer_input; int rc; ResetStubData(); - snd_mixer_first_elem_return_value = reinterpret_cast<snd_mixer_elem_t *>(1); + snd_mixer_first_elem_return_value = reinterpret_cast<snd_mixer_elem_t*>(1); snd_mixer_elem_next_return_values = elements; snd_mixer_elem_next_return_values_length = ARRAY_SIZE(elements); snd_mixer_selem_has_capture_volume_return_values = element_capture_volume; @@ -636,9 +627,8 @@ TEST(AlsaMixer, CreateTwoMainCaptureElements) { ARRAY_SIZE(element_capture_switches); snd_mixer_selem_get_name_return_values = element_names; snd_mixer_selem_get_name_return_values_length = ARRAY_SIZE(element_names); - c = create_mixer_and_add_controls_by_name_matching( - "hw:0", NULL, NULL); - ASSERT_NE(static_cast<struct cras_alsa_mixer *>(NULL), c); + c = create_mixer_and_add_controls_by_name_matching("hw:0", NULL, NULL); + ASSERT_NE(static_cast<struct cras_alsa_mixer*>(NULL), c); EXPECT_EQ(1, snd_mixer_open_called); EXPECT_EQ(1, snd_mixer_attach_called); EXPECT_EQ(0, strcmp(snd_mixer_attach_mixdev, "hw:0")); @@ -656,16 +646,15 @@ TEST(AlsaMixer, CreateTwoMainCaptureElements) { * doesn't set to anything but zero then the entire volume should be passed to * the Digital Capture control. */ long get_dB_returns[] = { - 0, - 0, + 0, + 0, }; long set_dB_values[2]; snd_mixer_selem_get_capture_dB_return_values = get_dB_returns; snd_mixer_selem_get_capture_dB_return_values_length = ARRAY_SIZE(get_dB_returns); snd_mixer_selem_set_capture_dB_all_values = set_dB_values; - snd_mixer_selem_set_capture_dB_all_values_length = - ARRAY_SIZE(set_dB_values); + snd_mixer_selem_set_capture_dB_all_values_length = ARRAY_SIZE(set_dB_values); cras_alsa_mixer_set_capture_dBFS(c, -10, NULL); EXPECT_EQ(2, snd_mixer_selem_set_capture_dB_all_called); EXPECT_EQ(2, snd_mixer_selem_get_capture_dB_called); @@ -674,15 +663,14 @@ TEST(AlsaMixer, CreateTwoMainCaptureElements) { /* Set volume should be called for Capture and Digital Capture. Capture should * get the gain remaining after Mic Boos is set, in this case 20 - 25 = -5. */ long get_dB_returns2[] = { - 25, - -5, + 25, + -5, }; snd_mixer_selem_get_capture_dB_return_values = get_dB_returns2; snd_mixer_selem_get_capture_dB_return_values_length = ARRAY_SIZE(get_dB_returns2); snd_mixer_selem_set_capture_dB_all_values = set_dB_values; - snd_mixer_selem_set_capture_dB_all_values_length = - ARRAY_SIZE(set_dB_values); + snd_mixer_selem_set_capture_dB_all_values_length = ARRAY_SIZE(set_dB_values); snd_mixer_selem_set_capture_dB_all_called = 0; snd_mixer_selem_get_capture_dB_called = 0; cras_alsa_mixer_set_capture_dBFS(c, 20, NULL); @@ -695,9 +683,9 @@ TEST(AlsaMixer, CreateTwoMainCaptureElements) { * volume control */ long get_dB_returns3[] = { - 0, - 0, - 0, + 0, + 0, + 0, }; long set_dB_values3[3]; @@ -706,8 +694,7 @@ TEST(AlsaMixer, CreateTwoMainCaptureElements) { ARRAY_SIZE(get_dB_returns3); snd_mixer_selem_get_capture_dB_called = 0; snd_mixer_selem_set_capture_dB_all_values = set_dB_values3; - snd_mixer_selem_set_capture_dB_all_values_length = - ARRAY_SIZE(set_dB_values3); + snd_mixer_selem_set_capture_dB_all_values_length = ARRAY_SIZE(set_dB_values3); snd_mixer_selem_set_capture_dB_all_called = 0; snd_mixer_selem_has_capture_volume_return_values = element_capture_volume; snd_mixer_selem_has_capture_volume_return_values_length = @@ -722,7 +709,7 @@ TEST(AlsaMixer, CreateTwoMainCaptureElements) { snd_mixer_selem_has_capture_switch_called = 0; snd_mixer_selem_get_capture_dB_range_called = 0; rc = mixer_control_create(&mixer_input, NULL, - reinterpret_cast<snd_mixer_elem_t *>(3), + reinterpret_cast<snd_mixer_elem_t*>(3), CRAS_STREAM_INPUT); EXPECT_EQ(0, rc); EXPECT_EQ(1, snd_mixer_selem_get_name_called); @@ -749,86 +736,59 @@ class AlsaMixerOutputs : public testing::Test { virtual void SetUp() { output_called_values_.clear(); output_callback_called_ = 0; - static snd_mixer_elem_t *elements[] = { - reinterpret_cast<snd_mixer_elem_t *>(2), // PCM - reinterpret_cast<snd_mixer_elem_t *>(3), // Headphone - reinterpret_cast<snd_mixer_elem_t *>(4), // Speaker - reinterpret_cast<snd_mixer_elem_t *>(5), // HDMI - reinterpret_cast<snd_mixer_elem_t *>(6), // IEC958 - reinterpret_cast<snd_mixer_elem_t *>(7), // Mic Boost - reinterpret_cast<snd_mixer_elem_t *>(8), // Capture + static snd_mixer_elem_t* elements[] = { + reinterpret_cast<snd_mixer_elem_t*>(2), // PCM + reinterpret_cast<snd_mixer_elem_t*>(3), // Headphone + reinterpret_cast<snd_mixer_elem_t*>(4), // Speaker + reinterpret_cast<snd_mixer_elem_t*>(5), // HDMI + reinterpret_cast<snd_mixer_elem_t*>(6), // IEC958 + reinterpret_cast<snd_mixer_elem_t*>(7), // Mic Boost + reinterpret_cast<snd_mixer_elem_t*>(8), // Capture }; static int element_playback_volume[] = { - 1, - 1, - 1, - 0, - 0, - 1, - 1, + 1, 1, 1, 0, 0, 1, 1, }; static int element_playback_switches[] = { - 1, - 1, - 1, - 0, - 1, - 1, - 1, + 1, 1, 1, 0, 1, 1, 1, }; - static int element_capture_volume[] = {0, 0, 0, 0, 0, 0, - 1, - 1, + static int element_capture_volume[] = { + 0, 0, 0, 0, 0, 0, 1, 1, }; - static int element_capture_switches[] = {0, 0, 0, 0, 0, 0, - 1, - 1, + static int element_capture_switches[] = { + 0, 0, 0, 0, 0, 0, 1, 1, }; static const long min_volumes[] = {0, 0, 0, 0, 0, 0, 500, -1250}; static const long max_volumes[] = {0, 0, 0, 0, 0, 0, 3000, 400}; - static const char *element_names[] = { - "Master", - "PCM", - "Headphone", - "Speaker", - "HDMI", - "IEC958", - "Capture", - "Digital Capture", - }; - static const char *output_names_extra[] = { - "IEC958" + static const char* element_names[] = { + "Master", "PCM", "Headphone", "Speaker", + "HDMI", "IEC958", "Capture", "Digital Capture", }; - static char *iniparser_returns[] = { - NULL, + static const char* output_names_extra[] = {"IEC958"}; + static char* iniparser_returns[] = { + NULL, }; - struct mixer_name *extra_controls = - mixer_name_add_array(NULL, output_names_extra, - ARRAY_SIZE(output_names_extra), - CRAS_STREAM_OUTPUT, - MIXER_NAME_VOLUME); + struct mixer_name* extra_controls = mixer_name_add_array( + NULL, output_names_extra, ARRAY_SIZE(output_names_extra), + CRAS_STREAM_OUTPUT, MIXER_NAME_VOLUME); ResetStubData(); snd_mixer_first_elem_return_value = - reinterpret_cast<snd_mixer_elem_t *>(1); // Master + reinterpret_cast<snd_mixer_elem_t*>(1); // Master snd_mixer_elem_next_return_values = elements; snd_mixer_elem_next_return_values_length = ARRAY_SIZE(elements); - snd_mixer_selem_has_playback_volume_return_values = - element_playback_volume; + snd_mixer_selem_has_playback_volume_return_values = element_playback_volume; snd_mixer_selem_has_playback_volume_return_values_length = - ARRAY_SIZE(element_playback_volume); + ARRAY_SIZE(element_playback_volume); snd_mixer_selem_has_playback_switch_return_values = element_playback_switches; snd_mixer_selem_has_playback_switch_return_values_length = - ARRAY_SIZE(element_playback_switches); - snd_mixer_selem_has_capture_volume_return_values = - element_capture_volume; + ARRAY_SIZE(element_playback_switches); + snd_mixer_selem_has_capture_volume_return_values = element_capture_volume; snd_mixer_selem_has_capture_volume_return_values_length = - ARRAY_SIZE(element_capture_volume); - snd_mixer_selem_has_capture_switch_return_values = - element_capture_switches; + ARRAY_SIZE(element_capture_volume); + snd_mixer_selem_has_capture_switch_return_values = element_capture_switches; snd_mixer_selem_has_capture_switch_return_values_length = - ARRAY_SIZE(element_capture_switches); + ARRAY_SIZE(element_capture_switches); snd_mixer_selem_get_name_return_values = element_names; snd_mixer_selem_get_name_return_values_length = ARRAY_SIZE(element_names); snd_mixer_selem_get_capture_dB_range_called = 0; @@ -840,7 +800,7 @@ class AlsaMixerOutputs : public testing::Test { iniparser_getstring_return_length = ARRAY_SIZE(iniparser_returns); cras_mixer_ = create_mixer_and_add_controls_by_name_matching( "hw:0", extra_controls, NULL); - ASSERT_NE(static_cast<struct cras_alsa_mixer *>(NULL), cras_mixer_); + ASSERT_NE(static_cast<struct cras_alsa_mixer*>(NULL), cras_mixer_); EXPECT_EQ(1, snd_mixer_open_called); EXPECT_EQ(1, snd_mixer_attach_called); EXPECT_EQ(0, strcmp(snd_mixer_attach_mixdev, "hw:0")); @@ -860,62 +820,57 @@ class AlsaMixerOutputs : public testing::Test { EXPECT_EQ(1, snd_mixer_close_called); } - static void OutputCallback(struct mixer_control *out, void *arg) { + static void OutputCallback(struct mixer_control* out, void* arg) { output_callback_called_++; output_called_values_.push_back(out); } - struct cras_alsa_mixer *cras_mixer_; + struct cras_alsa_mixer* cras_mixer_; static size_t output_callback_called_; - static std::vector<struct mixer_control *> output_called_values_; + static std::vector<struct mixer_control*> output_called_values_; }; size_t AlsaMixerOutputs::output_callback_called_; -std::vector<struct mixer_control *> - AlsaMixerOutputs::output_called_values_; +std::vector<struct mixer_control*> AlsaMixerOutputs::output_called_values_; TEST_F(AlsaMixerOutputs, CheckFourOutputs) { - cras_alsa_mixer_list_outputs(cras_mixer_, - AlsaMixerOutputs::OutputCallback, + cras_alsa_mixer_list_outputs(cras_mixer_, AlsaMixerOutputs::OutputCallback, reinterpret_cast<void*>(555)); EXPECT_EQ(4, output_callback_called_); } TEST_F(AlsaMixerOutputs, CheckFindOutputByNameNoMatch) { - struct mixer_control *out; + struct mixer_control* out; - out = cras_alsa_mixer_get_output_matching_name(cras_mixer_, - "AAAAA Jack"); - EXPECT_EQ(static_cast<struct mixer_control *>(NULL), out); + out = cras_alsa_mixer_get_output_matching_name(cras_mixer_, "AAAAA Jack"); + EXPECT_EQ(static_cast<struct mixer_control*>(NULL), out); } TEST_F(AlsaMixerOutputs, CheckFindOutputByName) { - struct mixer_control *out; + struct mixer_control* out; - out = cras_alsa_mixer_get_output_matching_name(cras_mixer_, - "Headphone Jack"); - EXPECT_NE(static_cast<struct mixer_control *>(NULL), out); + out = cras_alsa_mixer_get_output_matching_name(cras_mixer_, "Headphone Jack"); + EXPECT_NE(static_cast<struct mixer_control*>(NULL), out); } TEST_F(AlsaMixerOutputs, CheckFindOutputHDMIByName) { - struct mixer_control *out; + struct mixer_control* out; - out = cras_alsa_mixer_get_output_matching_name(cras_mixer_, - "HDMI Jack"); - EXPECT_NE(static_cast<struct mixer_control *>(NULL), out); + out = cras_alsa_mixer_get_output_matching_name(cras_mixer_, "HDMI Jack"); + EXPECT_NE(static_cast<struct mixer_control*>(NULL), out); } TEST_F(AlsaMixerOutputs, CheckFindInputNameWorkaround) { - struct mixer_control *control; - snd_mixer_elem_t *elements[] = { - reinterpret_cast<snd_mixer_elem_t *>(1), // Speaker - reinterpret_cast<snd_mixer_elem_t *>(2), // Headphone - reinterpret_cast<snd_mixer_elem_t *>(3), // MIC + struct mixer_control* control; + snd_mixer_elem_t* elements[] = { + reinterpret_cast<snd_mixer_elem_t*>(1), // Speaker + reinterpret_cast<snd_mixer_elem_t*>(2), // Headphone + reinterpret_cast<snd_mixer_elem_t*>(3), // MIC }; - const char *element_names[] = { - "Speaker", - "Headphone", - "MIC", + const char* element_names[] = { + "Speaker", + "Headphone", + "MIC", }; size_t i; @@ -926,9 +881,8 @@ TEST_F(AlsaMixerOutputs, CheckFindInputNameWorkaround) { snd_mixer_selem_get_name_called = 0; snd_mixer_selem_get_name_return_values = element_names; snd_mixer_selem_get_name_return_values_length = ARRAY_SIZE(element_names); - control = cras_alsa_mixer_get_input_matching_name(cras_mixer_, - "MIC"); - EXPECT_NE(static_cast<struct mixer_control *>(NULL), control); + control = cras_alsa_mixer_get_input_matching_name(cras_mixer_, "MIC"); + EXPECT_NE(static_cast<struct mixer_control*>(NULL), control); /* This exercises the 'workaround' where the control is added if it was * previouly missing in cras_alsa_mixer_get_input_matching_name(). * snd_mixer_find_selem is called once for the missing control. */ @@ -940,8 +894,7 @@ TEST_F(AlsaMixerOutputs, CheckFindInputNameWorkaround) { TEST_F(AlsaMixerOutputs, ActivateDeactivate) { int rc; - cras_alsa_mixer_list_outputs(cras_mixer_, - AlsaMixerOutputs::OutputCallback, + cras_alsa_mixer_list_outputs(cras_mixer_, AlsaMixerOutputs::OutputCallback, reinterpret_cast<void*>(555)); EXPECT_EQ(4, output_callback_called_); EXPECT_EQ(4, output_called_values_.size()); @@ -955,19 +908,17 @@ TEST_F(AlsaMixerOutputs, ActivateDeactivate) { TEST_F(AlsaMixerOutputs, MinMaxCaptureGain) { long min, max; - min = cras_alsa_mixer_get_minimum_capture_gain(cras_mixer_, - NULL); + min = cras_alsa_mixer_get_minimum_capture_gain(cras_mixer_, NULL); EXPECT_EQ(-750, min); - max = cras_alsa_mixer_get_maximum_capture_gain(cras_mixer_, - NULL); + max = cras_alsa_mixer_get_maximum_capture_gain(cras_mixer_, NULL); EXPECT_EQ(3400, max); } TEST_F(AlsaMixerOutputs, MinMaxCaptureGainWithActiveInput) { - struct mixer_control *mixer_input; + struct mixer_control* mixer_input; long min, max; - mixer_input = (struct mixer_control *)calloc(1, sizeof(*mixer_input)); + mixer_input = (struct mixer_control*)calloc(1, sizeof(*mixer_input)); mixer_input->min_volume_dB = 50; mixer_input->max_volume_dB = 60; mixer_input->has_volume = 1; @@ -976,12 +927,12 @@ TEST_F(AlsaMixerOutputs, MinMaxCaptureGainWithActiveInput) { EXPECT_EQ(-700, min); EXPECT_EQ(3460, max); - free((void *)mixer_input); + free((void*)mixer_input); } TEST(AlsaMixer, CreateWithCoupledOutputControls) { - struct cras_alsa_mixer *c; - struct mixer_control *output_control; + struct cras_alsa_mixer* c; + struct mixer_control* output_control; struct mixer_control_element *c1, *c2, *c3, *c4; static const long min_volumes[] = {-70, -70}; @@ -989,15 +940,11 @@ TEST(AlsaMixer, CreateWithCoupledOutputControls) { long set_dB_values[2]; - const char *coupled_output_names[] = {"Left Master", - "Right Master", - "Left Speaker", - "Right Speaker"}; - struct mixer_name *coupled_controls = - mixer_name_add_array(NULL, coupled_output_names, - ARRAY_SIZE(coupled_output_names), - CRAS_STREAM_OUTPUT, - MIXER_NAME_VOLUME); + const char* coupled_output_names[] = {"Left Master", "Right Master", + "Left Speaker", "Right Speaker"}; + struct mixer_name* coupled_controls = mixer_name_add_array( + NULL, coupled_output_names, ARRAY_SIZE(coupled_output_names), + CRAS_STREAM_OUTPUT, MIXER_NAME_VOLUME); int element_playback_volume[] = {1, 1, 0, 0}; int element_playback_switches[] = {0, 0, 1, 1}; @@ -1007,13 +954,13 @@ TEST(AlsaMixer, CreateWithCoupledOutputControls) { ResetStubData(); snd_mixer_find_elem_map[std::string("Left Master")] = - reinterpret_cast<snd_mixer_elem_t *>(1); + reinterpret_cast<snd_mixer_elem_t*>(1); snd_mixer_find_elem_map[std::string("Right Master")] = - reinterpret_cast<snd_mixer_elem_t *>(2); + reinterpret_cast<snd_mixer_elem_t*>(2); snd_mixer_find_elem_map[std::string("Left Speaker")] = - reinterpret_cast<snd_mixer_elem_t *>(3); + reinterpret_cast<snd_mixer_elem_t*>(3); snd_mixer_find_elem_map[std::string("Right Speaker")] = - reinterpret_cast<snd_mixer_elem_t *>(4); + reinterpret_cast<snd_mixer_elem_t*>(4); snd_mixer_selem_has_playback_volume_return_values = element_playback_volume; snd_mixer_selem_has_playback_volume_return_values_length = @@ -1026,10 +973,10 @@ TEST(AlsaMixer, CreateWithCoupledOutputControls) { snd_mixer_selem_get_playback_dB_range_max_values = max_volumes; snd_mixer_selem_get_playback_dB_range_values_length = ARRAY_SIZE(min_volumes); - c = create_mixer_and_add_controls_by_name_matching( - "hw:0", NULL, coupled_controls); + c = create_mixer_and_add_controls_by_name_matching("hw:0", NULL, + coupled_controls); - ASSERT_NE(static_cast<struct cras_alsa_mixer *>(NULL), c); + ASSERT_NE(static_cast<struct cras_alsa_mixer*>(NULL), c); EXPECT_EQ(1, snd_mixer_open_called); EXPECT_EQ(1, snd_mixer_attach_called); EXPECT_EQ(0, strcmp(snd_mixer_attach_mixdev, "hw:0")); @@ -1043,11 +990,11 @@ TEST(AlsaMixer, CreateWithCoupledOutputControls) { c2 = c1->next; c3 = c2->next; c4 = c3->next; - EXPECT_EQ(c1->elem, reinterpret_cast<snd_mixer_elem_t *>(1)); - EXPECT_EQ(c2->elem, reinterpret_cast<snd_mixer_elem_t *>(2)); - EXPECT_EQ(c3->elem, reinterpret_cast<snd_mixer_elem_t *>(3)); - EXPECT_EQ(c4->elem, reinterpret_cast<snd_mixer_elem_t *>(4)); - EXPECT_EQ(c4->next, reinterpret_cast<mixer_control_element *>(NULL)); + EXPECT_EQ(c1->elem, reinterpret_cast<snd_mixer_elem_t*>(1)); + EXPECT_EQ(c2->elem, reinterpret_cast<snd_mixer_elem_t*>(2)); + EXPECT_EQ(c3->elem, reinterpret_cast<snd_mixer_elem_t*>(3)); + EXPECT_EQ(c4->elem, reinterpret_cast<snd_mixer_elem_t*>(4)); + EXPECT_EQ(c4->next, reinterpret_cast<mixer_control_element*>(NULL)); EXPECT_EQ(c1->has_volume, 1); EXPECT_EQ(c1->has_mute, 0); EXPECT_EQ(c2->has_volume, 1); @@ -1060,8 +1007,7 @@ TEST(AlsaMixer, CreateWithCoupledOutputControls) { EXPECT_EQ(output_control->min_volume_dB, min_volumes[0]); snd_mixer_selem_set_playback_dB_all_values = set_dB_values; - snd_mixer_selem_set_playback_dB_all_values_length = - ARRAY_SIZE(set_dB_values); + snd_mixer_selem_set_playback_dB_all_values_length = ARRAY_SIZE(set_dB_values); cras_alsa_mixer_set_dBFS(c, target_dBFS, output_control); @@ -1089,35 +1035,31 @@ TEST(AlsaMixer, CreateWithCoupledOutputControls) { } TEST(AlsaMixer, CoupledOutputHasMuteNoVolume) { - struct cras_alsa_mixer *c; - struct mixer_control *output_control; + struct cras_alsa_mixer* c; + struct mixer_control* output_control; struct mixer_control_element *c1, *c2, *c3, *c4; static const long min_volumes[] = {-70}; static const long max_volumes[] = {30}; - const char *coupled_output_names[] = {"Left Master", - "Right Master", - "Left Speaker", - "Right Speaker"}; - struct mixer_name *coupled_controls = - mixer_name_add_array(NULL, coupled_output_names, - ARRAY_SIZE(coupled_output_names), - CRAS_STREAM_OUTPUT, - MIXER_NAME_VOLUME); + const char* coupled_output_names[] = {"Left Master", "Right Master", + "Left Speaker", "Right Speaker"}; + struct mixer_name* coupled_controls = mixer_name_add_array( + NULL, coupled_output_names, ARRAY_SIZE(coupled_output_names), + CRAS_STREAM_OUTPUT, MIXER_NAME_VOLUME); int element_playback_volume[] = {0, 0, 0, 0}; int element_playback_switches[] = {0, 0, 1, 1}; ResetStubData(); snd_mixer_find_elem_map[std::string("Left Master")] = - reinterpret_cast<snd_mixer_elem_t *>(1); + reinterpret_cast<snd_mixer_elem_t*>(1); snd_mixer_find_elem_map[std::string("Right Master")] = - reinterpret_cast<snd_mixer_elem_t *>(2); + reinterpret_cast<snd_mixer_elem_t*>(2); snd_mixer_find_elem_map[std::string("Left Speaker")] = - reinterpret_cast<snd_mixer_elem_t *>(3); + reinterpret_cast<snd_mixer_elem_t*>(3); snd_mixer_find_elem_map[std::string("Right Speaker")] = - reinterpret_cast<snd_mixer_elem_t *>(4); + reinterpret_cast<snd_mixer_elem_t*>(4); snd_mixer_selem_has_playback_volume_return_values = element_playback_volume; snd_mixer_selem_has_playback_volume_return_values_length = @@ -1130,10 +1072,10 @@ TEST(AlsaMixer, CoupledOutputHasMuteNoVolume) { snd_mixer_selem_get_playback_dB_range_max_values = max_volumes; snd_mixer_selem_get_playback_dB_range_values_length = ARRAY_SIZE(min_volumes); - c = create_mixer_and_add_controls_by_name_matching( - "hw:0", NULL, coupled_controls); + c = create_mixer_and_add_controls_by_name_matching("hw:0", NULL, + coupled_controls); - ASSERT_NE(static_cast<struct cras_alsa_mixer *>(NULL), c); + ASSERT_NE(static_cast<struct cras_alsa_mixer*>(NULL), c); EXPECT_EQ(1, snd_mixer_open_called); EXPECT_EQ(1, snd_mixer_attach_called); EXPECT_EQ(0, strcmp(snd_mixer_attach_mixdev, "hw:0")); @@ -1147,11 +1089,11 @@ TEST(AlsaMixer, CoupledOutputHasMuteNoVolume) { c2 = c1->next; c3 = c2->next; c4 = c3->next; - EXPECT_EQ(c1->elem, reinterpret_cast<snd_mixer_elem_t *>(1)); - EXPECT_EQ(c2->elem, reinterpret_cast<snd_mixer_elem_t *>(2)); - EXPECT_EQ(c3->elem, reinterpret_cast<snd_mixer_elem_t *>(3)); - EXPECT_EQ(c4->elem, reinterpret_cast<snd_mixer_elem_t *>(4)); - EXPECT_EQ(c4->next, reinterpret_cast<mixer_control_element *>(NULL)); + EXPECT_EQ(c1->elem, reinterpret_cast<snd_mixer_elem_t*>(1)); + EXPECT_EQ(c2->elem, reinterpret_cast<snd_mixer_elem_t*>(2)); + EXPECT_EQ(c3->elem, reinterpret_cast<snd_mixer_elem_t*>(3)); + EXPECT_EQ(c4->elem, reinterpret_cast<snd_mixer_elem_t*>(4)); + EXPECT_EQ(c4->next, reinterpret_cast<mixer_control_element*>(NULL)); EXPECT_EQ(c1->has_volume, 0); EXPECT_EQ(c1->has_mute, 0); EXPECT_EQ(c2->has_volume, 0); @@ -1170,35 +1112,31 @@ TEST(AlsaMixer, CoupledOutputHasMuteNoVolume) { } TEST(AlsaMixer, CoupledOutputHasVolumeNoMute) { - struct cras_alsa_mixer *c; - struct mixer_control *output_control; + struct cras_alsa_mixer* c; + struct mixer_control* output_control; struct mixer_control_element *c1, *c2, *c3, *c4; static const long min_volumes[] = {-70, -70}; static const long max_volumes[] = {30, 30}; - const char *coupled_output_names[] = {"Left Master", - "Right Master", - "Left Speaker", - "Right Speaker"}; - struct mixer_name *coupled_controls = - mixer_name_add_array(NULL, coupled_output_names, - ARRAY_SIZE(coupled_output_names), - CRAS_STREAM_OUTPUT, - MIXER_NAME_VOLUME); + const char* coupled_output_names[] = {"Left Master", "Right Master", + "Left Speaker", "Right Speaker"}; + struct mixer_name* coupled_controls = mixer_name_add_array( + NULL, coupled_output_names, ARRAY_SIZE(coupled_output_names), + CRAS_STREAM_OUTPUT, MIXER_NAME_VOLUME); int element_playback_volume[] = {1, 1, 0, 0}; int element_playback_switches[] = {0, 0, 0, 0}; ResetStubData(); snd_mixer_find_elem_map[std::string("Left Master")] = - reinterpret_cast<snd_mixer_elem_t *>(1); + reinterpret_cast<snd_mixer_elem_t*>(1); snd_mixer_find_elem_map[std::string("Right Master")] = - reinterpret_cast<snd_mixer_elem_t *>(2); + reinterpret_cast<snd_mixer_elem_t*>(2); snd_mixer_find_elem_map[std::string("Left Speaker")] = - reinterpret_cast<snd_mixer_elem_t *>(3); + reinterpret_cast<snd_mixer_elem_t*>(3); snd_mixer_find_elem_map[std::string("Right Speaker")] = - reinterpret_cast<snd_mixer_elem_t *>(4); + reinterpret_cast<snd_mixer_elem_t*>(4); snd_mixer_selem_has_playback_volume_return_values = element_playback_volume; snd_mixer_selem_has_playback_volume_return_values_length = @@ -1211,10 +1149,10 @@ TEST(AlsaMixer, CoupledOutputHasVolumeNoMute) { snd_mixer_selem_get_playback_dB_range_max_values = max_volumes; snd_mixer_selem_get_playback_dB_range_values_length = ARRAY_SIZE(min_volumes); - c = create_mixer_and_add_controls_by_name_matching( - "hw:0", NULL, coupled_controls); + c = create_mixer_and_add_controls_by_name_matching("hw:0", NULL, + coupled_controls); - ASSERT_NE(static_cast<struct cras_alsa_mixer *>(NULL), c); + ASSERT_NE(static_cast<struct cras_alsa_mixer*>(NULL), c); EXPECT_EQ(1, snd_mixer_open_called); EXPECT_EQ(1, snd_mixer_attach_called); EXPECT_EQ(0, strcmp(snd_mixer_attach_mixdev, "hw:0")); @@ -1228,11 +1166,11 @@ TEST(AlsaMixer, CoupledOutputHasVolumeNoMute) { c2 = c1->next; c3 = c2->next; c4 = c3->next; - EXPECT_EQ(c1->elem, reinterpret_cast<snd_mixer_elem_t *>(1)); - EXPECT_EQ(c2->elem, reinterpret_cast<snd_mixer_elem_t *>(2)); - EXPECT_EQ(c3->elem, reinterpret_cast<snd_mixer_elem_t *>(3)); - EXPECT_EQ(c4->elem, reinterpret_cast<snd_mixer_elem_t *>(4)); - EXPECT_EQ(c4->next, reinterpret_cast<mixer_control_element *>(NULL)); + EXPECT_EQ(c1->elem, reinterpret_cast<snd_mixer_elem_t*>(1)); + EXPECT_EQ(c2->elem, reinterpret_cast<snd_mixer_elem_t*>(2)); + EXPECT_EQ(c3->elem, reinterpret_cast<snd_mixer_elem_t*>(3)); + EXPECT_EQ(c4->elem, reinterpret_cast<snd_mixer_elem_t*>(4)); + EXPECT_EQ(c4->next, reinterpret_cast<mixer_control_element*>(NULL)); EXPECT_EQ(c1->has_volume, 1); EXPECT_EQ(c1->has_mute, 0); EXPECT_EQ(c2->has_volume, 1); @@ -1251,55 +1189,45 @@ TEST(AlsaMixer, CoupledOutputHasVolumeNoMute) { } TEST(AlsaMixer, MixerName) { - struct mixer_name *names; - struct mixer_name *control; + struct mixer_name* names; + struct mixer_name* control; size_t mixer_name_count; - static const char *element_names[] = { - "Master", - "PCM", - "Headphone", - "Speaker", - "HDMI", - "IEC958", + static const char* element_names[] = { + "Master", "PCM", "Headphone", "Speaker", "HDMI", "IEC958", }; - names = mixer_name_add_array(NULL, element_names, - ARRAY_SIZE(element_names), + names = mixer_name_add_array(NULL, element_names, ARRAY_SIZE(element_names), CRAS_STREAM_OUTPUT, MIXER_NAME_VOLUME); - names = mixer_name_add(names, "Playback", - CRAS_STREAM_OUTPUT, MIXER_NAME_VOLUME); - names = mixer_name_add(names, "Main", - CRAS_STREAM_OUTPUT, MIXER_NAME_MAIN_VOLUME); - names = mixer_name_add(names, "Mic", - CRAS_STREAM_INPUT, MIXER_NAME_VOLUME); - names = mixer_name_add(names, "Capture", - CRAS_STREAM_INPUT, MIXER_NAME_MAIN_VOLUME); + names = + mixer_name_add(names, "Playback", CRAS_STREAM_OUTPUT, MIXER_NAME_VOLUME); + names = + mixer_name_add(names, "Main", CRAS_STREAM_OUTPUT, MIXER_NAME_MAIN_VOLUME); + names = mixer_name_add(names, "Mic", CRAS_STREAM_INPUT, MIXER_NAME_VOLUME); + names = mixer_name_add(names, "Capture", CRAS_STREAM_INPUT, + MIXER_NAME_MAIN_VOLUME); /* Number of items (test mixer_name_add(_array)). */ mixer_name_count = 0; - DL_FOREACH(names, control) { - mixer_name_count++; - } + DL_FOREACH (names, control) { mixer_name_count++; } EXPECT_EQ(10, mixer_name_count); /* Item not in the list: mismatch direction. */ - control = mixer_name_find(names, "Main", - CRAS_STREAM_INPUT, MIXER_NAME_UNDEFINED); + control = + mixer_name_find(names, "Main", CRAS_STREAM_INPUT, MIXER_NAME_UNDEFINED); EXPECT_EQ(1, control == NULL); /* Item not in the list: mismatch type. */ - control = mixer_name_find(names, "Main", - CRAS_STREAM_OUTPUT, MIXER_NAME_VOLUME); + control = + mixer_name_find(names, "Main", CRAS_STREAM_OUTPUT, MIXER_NAME_VOLUME); EXPECT_EQ(1, control == NULL); /* Find by name and direction. */ - control = mixer_name_find(names, "Main", - CRAS_STREAM_OUTPUT, MIXER_NAME_UNDEFINED); + control = + mixer_name_find(names, "Main", CRAS_STREAM_OUTPUT, MIXER_NAME_UNDEFINED); EXPECT_EQ(0, strcmp("Main", control->name)); /* Find by type and direction. */ - control = mixer_name_find(names, NULL, - CRAS_STREAM_INPUT, MIXER_NAME_VOLUME); + control = mixer_name_find(names, NULL, CRAS_STREAM_INPUT, MIXER_NAME_VOLUME); EXPECT_EQ(0, strcmp("Mic", control->name)); mixer_name_free(names); @@ -1310,67 +1238,45 @@ class AlsaMixerFullySpeced : public testing::Test { virtual void SetUp() { callback_values_.clear(); callback_called_ = 0; - static snd_mixer_elem_t *elements[] = { - reinterpret_cast<snd_mixer_elem_t *>(1), // HP-L - reinterpret_cast<snd_mixer_elem_t *>(2), // HP-R - reinterpret_cast<snd_mixer_elem_t *>(3), // SPK-L - reinterpret_cast<snd_mixer_elem_t *>(4), // SPK-R - reinterpret_cast<snd_mixer_elem_t *>(5), // HDMI - reinterpret_cast<snd_mixer_elem_t *>(6), // CAPTURE - reinterpret_cast<snd_mixer_elem_t *>(7), // MIC-L - reinterpret_cast<snd_mixer_elem_t *>(8), // MIC-R - reinterpret_cast<snd_mixer_elem_t *>(0), // Unknown + static snd_mixer_elem_t* elements[] = { + reinterpret_cast<snd_mixer_elem_t*>(1), // HP-L + reinterpret_cast<snd_mixer_elem_t*>(2), // HP-R + reinterpret_cast<snd_mixer_elem_t*>(3), // SPK-L + reinterpret_cast<snd_mixer_elem_t*>(4), // SPK-R + reinterpret_cast<snd_mixer_elem_t*>(5), // HDMI + reinterpret_cast<snd_mixer_elem_t*>(6), // CAPTURE + reinterpret_cast<snd_mixer_elem_t*>(7), // MIC-L + reinterpret_cast<snd_mixer_elem_t*>(8), // MIC-R + reinterpret_cast<snd_mixer_elem_t*>(0), // Unknown }; static int element_playback_volume[] = { - 1, - 1, - 1, - 1, - 1, - 0, 0, 0, + 1, 1, 1, 1, 1, 0, 0, 0, }; static int element_playback_switches[] = { - 0, - 0, - 0, - 0, - 1, - 0, 0, 0, + 0, 0, 0, 0, 1, 0, 0, 0, }; - static int element_capture_volume[] = {0, 0, 0, 0, 0, - 0, - 1, - 1, + static int element_capture_volume[] = { + 0, 0, 0, 0, 0, 0, 1, 1, }; - static int element_capture_switches[] = {0, 0, 0, 0, 0, - 1, - 0, - 0, + static int element_capture_switches[] = { + 0, 0, 0, 0, 0, 1, 0, 0, }; static const long min_volumes[] = {-84, -84, -84, -84, -84, 0, 0, 0}; static const long max_volumes[] = {0, 0, 0, 0, 0, 0, 84, 84}; - static const char *element_names[] = { - "HP-L", - "HP-R", - "SPK-L", - "SPK-R", - "HDMI", - "CAPTURE", - "MIC-L", - "MIC-R", - "Unknown" - }; - struct ucm_section *sections = NULL; - struct ucm_section *section; + static const char* element_names[] = {"HP-L", "HP-R", "SPK-L", + "SPK-R", "HDMI", "CAPTURE", + "MIC-L", "MIC-R", "Unknown"}; + struct ucm_section* sections = NULL; + struct ucm_section* section; size_t i; ResetStubData(); for (i = 0; i < ARRAY_SIZE(elements); i++) - snd_mixer_find_elem_map[element_names[i]] = elements[i]; + snd_mixer_find_elem_map[element_names[i]] = elements[i]; - section = ucm_section_create("NullElement", 0, CRAS_STREAM_OUTPUT, - NULL, NULL); + section = + ucm_section_create("NullElement", 0, CRAS_STREAM_OUTPUT, NULL, NULL); ucm_section_set_mixer_name(section, "Unknown"); DL_APPEND(sections, section); section = ucm_section_create("Headphone", 0, CRAS_STREAM_OUTPUT, @@ -1378,8 +1284,7 @@ class AlsaMixerFullySpeced : public testing::Test { ucm_section_add_coupled(section, "HP-L", MIXER_NAME_VOLUME); ucm_section_add_coupled(section, "HP-R", MIXER_NAME_VOLUME); DL_APPEND(sections, section); - section = ucm_section_create("Speaker", 0, CRAS_STREAM_OUTPUT, - NULL, NULL); + section = ucm_section_create("Speaker", 0, CRAS_STREAM_OUTPUT, NULL, NULL); ucm_section_add_coupled(section, "SPK-L", MIXER_NAME_VOLUME); ucm_section_add_coupled(section, "SPK-R", MIXER_NAME_VOLUME); DL_APPEND(sections, section); @@ -1387,33 +1292,29 @@ class AlsaMixerFullySpeced : public testing::Test { "my-sound-card Headset Jack", "gpio"); ucm_section_set_mixer_name(section, "CAPTURE"); DL_APPEND(sections, section); - section = ucm_section_create("Internal Mic", 0, CRAS_STREAM_INPUT, - NULL, NULL); + section = + ucm_section_create("Internal Mic", 0, CRAS_STREAM_INPUT, NULL, NULL); ucm_section_add_coupled(section, "MIC-L", MIXER_NAME_VOLUME); ucm_section_add_coupled(section, "MIC-R", MIXER_NAME_VOLUME); DL_APPEND(sections, section); - section = ucm_section_create("HDMI", 0, CRAS_STREAM_OUTPUT, - NULL, NULL); + section = ucm_section_create("HDMI", 0, CRAS_STREAM_OUTPUT, NULL, NULL); ucm_section_set_mixer_name(section, "HDMI"); DL_APPEND(sections, section); - ASSERT_NE(sections, (struct ucm_section *)NULL); + ASSERT_NE(sections, (struct ucm_section*)NULL); - snd_mixer_selem_has_playback_volume_return_values = - element_playback_volume; + snd_mixer_selem_has_playback_volume_return_values = element_playback_volume; snd_mixer_selem_has_playback_volume_return_values_length = - ARRAY_SIZE(element_playback_volume); + ARRAY_SIZE(element_playback_volume); snd_mixer_selem_has_playback_switch_return_values = element_playback_switches; snd_mixer_selem_has_playback_switch_return_values_length = - ARRAY_SIZE(element_playback_switches); - snd_mixer_selem_has_capture_volume_return_values = - element_capture_volume; + ARRAY_SIZE(element_playback_switches); + snd_mixer_selem_has_capture_volume_return_values = element_capture_volume; snd_mixer_selem_has_capture_volume_return_values_length = - ARRAY_SIZE(element_capture_volume); - snd_mixer_selem_has_capture_switch_return_values = - element_capture_switches; + ARRAY_SIZE(element_capture_volume); + snd_mixer_selem_has_capture_switch_return_values = element_capture_switches; snd_mixer_selem_has_capture_switch_return_values_length = - ARRAY_SIZE(element_capture_switches); + ARRAY_SIZE(element_capture_switches); snd_mixer_selem_get_name_return_values = element_names; snd_mixer_selem_get_name_return_values_length = ARRAY_SIZE(element_names); snd_mixer_selem_get_capture_dB_range_min_values = min_volumes; @@ -1422,7 +1323,7 @@ class AlsaMixerFullySpeced : public testing::Test { ARRAY_SIZE(min_volumes); cras_mixer_ = cras_alsa_mixer_create("hw:0"); - ASSERT_NE(static_cast<struct cras_alsa_mixer *>(NULL), cras_mixer_); + ASSERT_NE(static_cast<struct cras_alsa_mixer*>(NULL), cras_mixer_); EXPECT_EQ(1, snd_mixer_open_called); EXPECT_EQ(1, snd_mixer_attach_called); EXPECT_EQ(0, strcmp(snd_mixer_attach_mixdev, "hw:0")); @@ -1431,21 +1332,21 @@ class AlsaMixerFullySpeced : public testing::Test { EXPECT_EQ(0, snd_mixer_close_called); section = sections; - EXPECT_EQ(-ENOENT,\ + EXPECT_EQ(-ENOENT, cras_alsa_mixer_add_controls_in_section(cras_mixer_, section)); - ASSERT_NE((struct ucm_section *)NULL, section->next); + ASSERT_NE((struct ucm_section*)NULL, section->next); section = section->next; EXPECT_EQ(0, cras_alsa_mixer_add_controls_in_section(cras_mixer_, section)); - ASSERT_NE((struct ucm_section *)NULL, section->next); + ASSERT_NE((struct ucm_section*)NULL, section->next); section = section->next; EXPECT_EQ(0, cras_alsa_mixer_add_controls_in_section(cras_mixer_, section)); - ASSERT_NE((struct ucm_section *)NULL, section->next); + ASSERT_NE((struct ucm_section*)NULL, section->next); section = section->next; EXPECT_EQ(0, cras_alsa_mixer_add_controls_in_section(cras_mixer_, section)); - ASSERT_NE((struct ucm_section *)NULL, section->next); + ASSERT_NE((struct ucm_section*)NULL, section->next); section = section->next; EXPECT_EQ(0, cras_alsa_mixer_add_controls_in_section(cras_mixer_, section)); - ASSERT_NE((struct ucm_section *)NULL, section->next); + ASSERT_NE((struct ucm_section*)NULL, section->next); section = section->next; EXPECT_EQ(0, cras_alsa_mixer_add_controls_in_section(cras_mixer_, section)); EXPECT_EQ(section->next, (struct ucm_section*)NULL); @@ -1467,103 +1368,99 @@ class AlsaMixerFullySpeced : public testing::Test { EXPECT_EQ(1, snd_mixer_close_called); } - static void Callback(struct mixer_control *control, void *arg) { + static void Callback(struct mixer_control* control, void* arg) { callback_called_++; callback_values_.push_back(control); } - struct cras_alsa_mixer *cras_mixer_; + struct cras_alsa_mixer* cras_mixer_; static size_t callback_called_; - static std::vector<struct mixer_control *> callback_values_; - struct ucm_section *sections_; + static std::vector<struct mixer_control*> callback_values_; + struct ucm_section* sections_; }; size_t AlsaMixerFullySpeced::callback_called_; -std::vector<struct mixer_control *> AlsaMixerFullySpeced::callback_values_; +std::vector<struct mixer_control*> AlsaMixerFullySpeced::callback_values_; TEST_F(AlsaMixerFullySpeced, CheckControlCounts) { - cras_alsa_mixer_list_outputs(cras_mixer_, - AlsaMixerFullySpeced::Callback, + cras_alsa_mixer_list_outputs(cras_mixer_, AlsaMixerFullySpeced::Callback, reinterpret_cast<void*>(555)); EXPECT_EQ(3, callback_called_); callback_called_ = 0; - cras_alsa_mixer_list_inputs(cras_mixer_, - AlsaMixerFullySpeced::Callback, - reinterpret_cast<void*>(555)); + cras_alsa_mixer_list_inputs(cras_mixer_, AlsaMixerFullySpeced::Callback, + reinterpret_cast<void*>(555)); EXPECT_EQ(2, callback_called_); } TEST_F(AlsaMixerFullySpeced, CheckFindOutputByNameNoMatch) { - struct mixer_control *out; + struct mixer_control* out; - out = cras_alsa_mixer_get_output_matching_name(cras_mixer_, - "AAAAA Jack"); - EXPECT_EQ(static_cast<struct mixer_control *>(NULL), out); + out = cras_alsa_mixer_get_output_matching_name(cras_mixer_, "AAAAA Jack"); + EXPECT_EQ(static_cast<struct mixer_control*>(NULL), out); } TEST_F(AlsaMixerFullySpeced, CheckFindOutputByName) { - struct mixer_control *out; + struct mixer_control* out; - out = cras_alsa_mixer_get_output_matching_name(cras_mixer_, - "Headphone Jack"); - EXPECT_NE(static_cast<struct mixer_control *>(NULL), out); + out = cras_alsa_mixer_get_output_matching_name(cras_mixer_, "Headphone Jack"); + EXPECT_NE(static_cast<struct mixer_control*>(NULL), out); } TEST_F(AlsaMixerFullySpeced, CheckFindControlForSection) { - struct mixer_control *control; - struct ucm_section *section = sections_; + struct mixer_control* control; + struct ucm_section* section = sections_; // Look for the control for the Headphone section. // We've already asserted that section != NULL above. // Matching the control created by CoupledMixers. section = section->next; control = cras_alsa_mixer_get_control_for_section(cras_mixer_, section); - ASSERT_NE(static_cast<struct mixer_control *>(NULL), control); + ASSERT_NE(static_cast<struct mixer_control*>(NULL), control); EXPECT_EQ(0, strcmp(control->name, "Headphone")); // Look for the control for the Mic section. // Matching the control created by MixerName. section = section->next->next; control = cras_alsa_mixer_get_control_for_section(cras_mixer_, section); - ASSERT_NE(static_cast<struct mixer_control *>(NULL), control); + ASSERT_NE(static_cast<struct mixer_control*>(NULL), control); EXPECT_EQ(0, strcmp(control->name, "CAPTURE")); } /* Stubs */ extern "C" { -int snd_mixer_open(snd_mixer_t **mixer, int mode) { +int snd_mixer_open(snd_mixer_t** mixer, int mode) { snd_mixer_open_called++; - *mixer = reinterpret_cast<snd_mixer_t *>(2); + *mixer = reinterpret_cast<snd_mixer_t*>(2); return snd_mixer_open_return_value; } -int snd_mixer_attach(snd_mixer_t *mixer, const char *name) { +int snd_mixer_attach(snd_mixer_t* mixer, const char* name) { snd_mixer_attach_called++; snd_mixer_attach_mixdev = name; return snd_mixer_attach_return_value; } -int snd_mixer_selem_register(snd_mixer_t *mixer, - struct snd_mixer_selem_regopt *options, - snd_mixer_class_t **classp) { +int snd_mixer_selem_register(snd_mixer_t* mixer, + struct snd_mixer_selem_regopt* options, + snd_mixer_class_t** classp) { snd_mixer_selem_register_called++; return snd_mixer_selem_register_return_value; } -int snd_mixer_load(snd_mixer_t *mixer) { +int snd_mixer_load(snd_mixer_t* mixer) { snd_mixer_load_called++; return snd_mixer_load_return_value; } -const char *snd_mixer_selem_get_name(snd_mixer_elem_t *elem) { +const char* snd_mixer_selem_get_name(snd_mixer_elem_t* elem) { int index = reinterpret_cast<size_t>(elem) - 1; snd_mixer_selem_get_name_called++; if (index >= snd_mixer_selem_get_name_return_values_length) - return static_cast<char *>(NULL); + return static_cast<char*>(NULL); return snd_mixer_selem_get_name_return_values[index]; } -unsigned int snd_mixer_selem_get_index(snd_mixer_elem_t *elem) { +unsigned int snd_mixer_selem_get_index(snd_mixer_elem_t* elem) { return 0; } -int snd_mixer_selem_has_playback_volume(snd_mixer_elem_t *elem) { +int snd_mixer_selem_has_playback_volume(snd_mixer_elem_t* elem) { int index = reinterpret_cast<size_t>(elem) - 1; snd_mixer_selem_has_playback_volume_called++; if (index >= snd_mixer_selem_has_playback_volume_return_values_length) @@ -1571,7 +1468,7 @@ int snd_mixer_selem_has_playback_volume(snd_mixer_elem_t *elem) { return snd_mixer_selem_has_playback_volume_return_values[index]; } -int snd_mixer_selem_has_playback_switch(snd_mixer_elem_t *elem) { +int snd_mixer_selem_has_playback_switch(snd_mixer_elem_t* elem) { int index = reinterpret_cast<size_t>(elem) - 1; snd_mixer_selem_has_playback_switch_called++; if (index >= snd_mixer_selem_has_playback_switch_return_values_length) @@ -1579,7 +1476,7 @@ int snd_mixer_selem_has_playback_switch(snd_mixer_elem_t *elem) { return snd_mixer_selem_has_playback_switch_return_values[index]; } -int snd_mixer_selem_has_capture_volume(snd_mixer_elem_t *elem) { +int snd_mixer_selem_has_capture_volume(snd_mixer_elem_t* elem) { int index = reinterpret_cast<size_t>(elem) - 1; snd_mixer_selem_has_capture_volume_called++; if (index >= snd_mixer_selem_has_capture_volume_return_values_length) @@ -1587,7 +1484,7 @@ int snd_mixer_selem_has_capture_volume(snd_mixer_elem_t *elem) { return snd_mixer_selem_has_capture_volume_return_values[index]; } -int snd_mixer_selem_has_capture_switch(snd_mixer_elem_t *elem) { +int snd_mixer_selem_has_capture_switch(snd_mixer_elem_t* elem) { int index = reinterpret_cast<size_t>(elem) - 1; snd_mixer_selem_has_capture_switch_called++; if (index >= snd_mixer_selem_has_capture_switch_return_values_length) @@ -1595,24 +1492,24 @@ int snd_mixer_selem_has_capture_switch(snd_mixer_elem_t *elem) { return snd_mixer_selem_has_capture_switch_return_values[index]; } -snd_mixer_elem_t *snd_mixer_first_elem(snd_mixer_t *mixer) { +snd_mixer_elem_t* snd_mixer_first_elem(snd_mixer_t* mixer) { snd_mixer_first_elem_called++; return snd_mixer_first_elem_return_value; } -snd_mixer_elem_t *snd_mixer_elem_next(snd_mixer_elem_t *elem) { +snd_mixer_elem_t* snd_mixer_elem_next(snd_mixer_elem_t* elem) { snd_mixer_elem_next_called++; if (snd_mixer_elem_next_return_values_index >= snd_mixer_elem_next_return_values_length) - return static_cast<snd_mixer_elem_t *>(NULL); + return static_cast<snd_mixer_elem_t*>(NULL); - return snd_mixer_elem_next_return_values[ - snd_mixer_elem_next_return_values_index++]; + return snd_mixer_elem_next_return_values + [snd_mixer_elem_next_return_values_index++]; } -int snd_mixer_close(snd_mixer_t *mixer) { +int snd_mixer_close(snd_mixer_t* mixer) { snd_mixer_close_called++; return 0; } -int snd_mixer_selem_set_playback_dB_all(snd_mixer_elem_t *elem, +int snd_mixer_selem_set_playback_dB_all(snd_mixer_elem_t* elem, long value, int dir) { int index = reinterpret_cast<size_t>(elem) - 1; @@ -1621,9 +1518,9 @@ int snd_mixer_selem_set_playback_dB_all(snd_mixer_elem_t *elem, snd_mixer_selem_set_playback_dB_all_values[index] = value; return 0; } -int snd_mixer_selem_get_playback_dB(snd_mixer_elem_t *elem, +int snd_mixer_selem_get_playback_dB(snd_mixer_elem_t* elem, snd_mixer_selem_channel_id_t channel, - long *value) { + long* value) { int index = reinterpret_cast<size_t>(elem) - 1; snd_mixer_selem_get_playback_dB_called++; if (index >= snd_mixer_selem_get_playback_dB_return_values_length) @@ -1632,12 +1529,12 @@ int snd_mixer_selem_get_playback_dB(snd_mixer_elem_t *elem, *value = snd_mixer_selem_get_playback_dB_return_values[index]; return 0; } -int snd_mixer_selem_set_playback_switch_all(snd_mixer_elem_t *elem, int value) { +int snd_mixer_selem_set_playback_switch_all(snd_mixer_elem_t* elem, int value) { snd_mixer_selem_set_playback_switch_all_called++; snd_mixer_selem_set_playback_switch_all_value = value; return 0; } -int snd_mixer_selem_set_capture_dB_all(snd_mixer_elem_t *elem, +int snd_mixer_selem_set_capture_dB_all(snd_mixer_elem_t* elem, long value, int dir) { int index = reinterpret_cast<size_t>(elem) - 1; @@ -1646,9 +1543,9 @@ int snd_mixer_selem_set_capture_dB_all(snd_mixer_elem_t *elem, snd_mixer_selem_set_capture_dB_all_values[index] = value; return 0; } -int snd_mixer_selem_get_capture_dB(snd_mixer_elem_t *elem, +int snd_mixer_selem_get_capture_dB(snd_mixer_elem_t* elem, snd_mixer_selem_channel_id_t channel, - long *value) { + long* value) { int index = reinterpret_cast<size_t>(elem) - 1; snd_mixer_selem_get_capture_dB_called++; if (index >= snd_mixer_selem_get_capture_dB_return_values_length) @@ -1657,13 +1554,14 @@ int snd_mixer_selem_get_capture_dB(snd_mixer_elem_t *elem, *value = snd_mixer_selem_get_capture_dB_return_values[index]; return 0; } -int snd_mixer_selem_set_capture_switch_all(snd_mixer_elem_t *elem, int value) { +int snd_mixer_selem_set_capture_switch_all(snd_mixer_elem_t* elem, int value) { snd_mixer_selem_set_capture_switch_all_called++; snd_mixer_selem_set_capture_switch_all_value = value; return 0; } -int snd_mixer_selem_get_capture_dB_range(snd_mixer_elem_t *elem, long *min, - long *max) { +int snd_mixer_selem_get_capture_dB_range(snd_mixer_elem_t* elem, + long* min, + long* max) { size_t index = reinterpret_cast<size_t>(elem) - 1; snd_mixer_selem_get_capture_dB_range_called++; if (index >= snd_mixer_selem_get_capture_dB_range_values_length) { @@ -1675,9 +1573,9 @@ int snd_mixer_selem_get_capture_dB_range(snd_mixer_elem_t *elem, long *min, } return 0; } -int snd_mixer_selem_get_playback_dB_range(snd_mixer_elem_t *elem, - long *min, - long *max) { +int snd_mixer_selem_get_playback_dB_range(snd_mixer_elem_t* elem, + long* min, + long* max) { size_t index = reinterpret_cast<size_t>(elem) - 1; snd_mixer_selem_get_playback_dB_range_called++; if (index >= snd_mixer_selem_get_playback_dB_range_values_length) { @@ -1690,8 +1588,8 @@ int snd_mixer_selem_get_playback_dB_range(snd_mixer_elem_t *elem, return 0; } -snd_mixer_elem_t *snd_mixer_find_selem( - snd_mixer_t *mixer, const snd_mixer_selem_id_t *id) { +snd_mixer_elem_t* snd_mixer_find_selem(snd_mixer_t* mixer, + const snd_mixer_selem_id_t* id) { std::string name(snd_mixer_selem_id_get_name(id)); unsigned int index = snd_mixer_selem_id_get_index(id); snd_mixer_find_selem_called++; @@ -1704,34 +1602,30 @@ snd_mixer_elem_t *snd_mixer_find_selem( } // From cras_volume_curve. -static long get_dBFS_default(const struct cras_volume_curve *curve, - size_t volume) -{ +static long get_dBFS_default(const struct cras_volume_curve* curve, + size_t volume) { return 100 * (volume - 100); } -struct cras_volume_curve *cras_volume_curve_create_default() -{ - struct cras_volume_curve *curve; - curve = (struct cras_volume_curve *)calloc(1, sizeof(*curve)); +struct cras_volume_curve* cras_volume_curve_create_default() { + struct cras_volume_curve* curve; + curve = (struct cras_volume_curve*)calloc(1, sizeof(*curve)); if (curve) curve->get_dBFS = get_dBFS_default; return curve; } -void cras_volume_curve_destroy(struct cras_volume_curve *curve) -{ +void cras_volume_curve_destroy(struct cras_volume_curve* curve) { cras_volume_curve_destroy_called++; free(curve); } // From libiniparser. -struct cras_volume_curve *cras_card_config_get_volume_curve_for_control( - const struct cras_card_config *card_config, - const char *control_name) -{ - struct cras_volume_curve *curve; - curve = (struct cras_volume_curve *)calloc(1, sizeof(*curve)); +struct cras_volume_curve* cras_card_config_get_volume_curve_for_control( + const struct cras_card_config* card_config, + const char* control_name) { + struct cras_volume_curve* curve; + curve = (struct cras_volume_curve*)calloc(1, sizeof(*curve)); if (curve != NULL) curve->get_dBFS = get_dBFS_default; return curve; @@ -1741,7 +1635,7 @@ struct cras_volume_curve *cras_card_config_get_volume_curve_for_control( } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); openlog(NULL, LOG_PERROR, LOG_USER); return RUN_ALL_TESTS(); diff --git a/cras/src/tests/alsa_ucm_unittest.cc b/cras/src/tests/alsa_ucm_unittest.cc index 3199573c..0773079e 100644 --- a/cras/src/tests/alsa_ucm_unittest.cc +++ b/cras/src/tests/alsa_ucm_unittest.cc @@ -6,6 +6,7 @@ #include <iniparser.h> #include <stdio.h> #include <syslog.h> + #include <map> extern "C" { @@ -13,7 +14,6 @@ extern "C" { #include "cras_types.h" #include "cras_util.h" #include "utlist.h" -#include "cras_util.h" // Include C file to test static functions. #include "cras_alsa_ucm.c" @@ -22,7 +22,7 @@ extern "C" { namespace { static int snd_use_case_mgr_open_return; -static snd_use_case_mgr_t *snd_use_case_mgr_open_mgr_ptr; +static snd_use_case_mgr_t* snd_use_case_mgr_open_mgr_ptr; static unsigned snd_use_case_mgr_open_called; static unsigned snd_use_case_mgr_close_called; static unsigned snd_use_case_get_called; @@ -31,13 +31,13 @@ static int snd_use_case_set_return; static std::map<std::string, std::string> snd_use_case_get_value; static unsigned snd_use_case_set_called; static std::vector<std::pair<std::string, std::string> > snd_use_case_set_param; -static std::map<std::string, const char **> fake_list; +static std::map<std::string, const char**> fake_list; static std::map<std::string, unsigned> fake_list_size; static unsigned snd_use_case_free_list_called; static std::vector<std::string> list_devices_callback_names; static std::vector<void*> list_devices_callback_args; static struct cras_use_case_mgr cras_ucm_mgr; -static const char *avail_verbs[] = { "HiFi", "Comment for Verb1" }; +static const char* avail_verbs[] = {"HiFi", "Comment for Verb1"}; static void ResetStubData() { snd_use_case_mgr_open_called = 0; @@ -60,17 +60,16 @@ static void ResetStubData() { cras_ucm_mgr.use_case = CRAS_STREAM_TYPE_DEFAULT; } -static void list_devices_callback(const char* section_name, void *arg) { +static void list_devices_callback(const char* section_name, void* arg) { list_devices_callback_names.push_back(std::string(section_name)); list_devices_callback_args.push_back(arg); } static void SetSectionDeviceData() { - static const char *sections[] = { "Speaker", "Comment for Dev1", - "IntMic", "Comment for Dev2", - "Headphone", "Comment for Dev3", - "ExtMic", "Comment for Dev4", - "HDMI", "Comment for Dev5"}; + static const char* sections[] = { + "Speaker", "Comment for Dev1", "IntMic", "Comment for Dev2", + "Headphone", "Comment for Dev3", "ExtMic", "Comment for Dev4", + "HDMI", "Comment for Dev5"}; fake_list["_devices/HiFi"] = sections; fake_list_size["_devices/HiFi"] = 10; std::string id_1 = "=PlaybackPCM/Speaker/HiFi"; @@ -114,7 +113,7 @@ TEST(AlsaUcm, CreateFailNoHiFi) { } TEST(AlsaUcm, CreateSuccess) { - struct cras_use_case_mgr *mgr; + struct cras_use_case_mgr* mgr; ResetStubData(); @@ -129,7 +128,7 @@ TEST(AlsaUcm, CreateSuccess) { } TEST(AlsaUcm, CheckEnabledEmptyList) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; ResetStubData(); fake_list["_enadevs"] = NULL; @@ -145,8 +144,8 @@ TEST(AlsaUcm, CheckEnabledEmptyList) { } TEST(AlsaUcm, CheckEnabledAlready) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; - const char *enabled[] = { "Dev2", "Dev1" }; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; + const char* enabled[] = {"Dev2", "Dev1"}; ResetStubData(); @@ -163,10 +162,10 @@ TEST(AlsaUcm, CheckEnabledAlready) { } TEST(AlsaUcm, GetEdidForDev) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; std::string id = "=EDIDFile/Dev1/HiFi"; std::string value = "EdidFileName"; - const char *file_name; + const char* file_name; ResetStubData(); @@ -182,8 +181,8 @@ TEST(AlsaUcm, GetEdidForDev) { } TEST(AlsaUcm, GetCapControlForDev) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; - char *cap_control; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; + char* cap_control; std::string id = "=CaptureControl/Dev1/HiFi"; std::string value = "MIC"; @@ -201,8 +200,8 @@ TEST(AlsaUcm, GetCapControlForDev) { } TEST(AlsaUcm, GetOverrideType) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; - const char *override_type_name; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; + const char* override_type_name; std::string id = "=OverrideNodeType/Dev1/HiFi"; std::string value = "HDMI"; @@ -220,14 +219,14 @@ TEST(AlsaUcm, GetOverrideType) { } TEST(AlsaUcm, GetSectionsForVar) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; struct section_name *section_names, *c; ResetStubData(); - const char *sections[] = { "Sec1", "Comment for Sec1", - "Sec2", "Comment for Sec2", - "Sec3", "Comment for Sec3"}; + const char* sections[] = {"Sec1", "Comment for Sec1", + "Sec2", "Comment for Sec2", + "Sec3", "Comment for Sec3"}; fake_list["Identifier"] = sections; fake_list_size["Identifier"] = 6; std::string id_1 = "=Var/Sec1/HiFi"; @@ -253,7 +252,7 @@ TEST(AlsaUcm, GetSectionsForVar) { EXPECT_EQ(snd_use_case_get_id[1], id_2); EXPECT_EQ(snd_use_case_get_id[2], id_3); - DL_FOREACH(section_names, c) { + DL_FOREACH (section_names, c) { DL_DELETE(section_names, c); free((void*)c->name); free(c); @@ -261,10 +260,10 @@ TEST(AlsaUcm, GetSectionsForVar) { } TEST(AlsaUcm, GetDevForJack) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; - const char *dev_name; - const char *devices[] = { "Dev1", "Comment for Dev1", "Dev2", - "Comment for Dev2" }; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; + const char* dev_name; + const char* devices[] = {"Dev1", "Comment for Dev1", "Dev2", + "Comment for Dev2"}; ResetStubData(); @@ -288,10 +287,10 @@ TEST(AlsaUcm, GetDevForJack) { } TEST(AlsaUcm, GetDevForHeadphoneJack) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; - const char *dev_name; - const char *devices[] = { "Mic", "Comment for Dev1", "Headphone", - "Comment for Dev2" }; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; + const char* dev_name; + const char* devices[] = {"Mic", "Comment for Dev1", "Headphone", + "Comment for Dev2"}; ResetStubData(); @@ -314,10 +313,10 @@ TEST(AlsaUcm, GetDevForHeadphoneJack) { } TEST(AlsaUcm, GetDevForMicJack) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; - const char *dev_name; - const char *devices[] = { "Headphone", "Comment for Dev1", "Mic", - "Comment for Dev2" }; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; + const char* dev_name; + const char* devices[] = {"Headphone", "Comment for Dev1", "Mic", + "Comment for Dev2"}; ResetStubData(); @@ -340,10 +339,10 @@ TEST(AlsaUcm, GetDevForMicJack) { } TEST(AlsaUcm, GetDevForMixer) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; const char *dev_name_out, *dev_name_in; - const char *devices[] = { "Dev1", "Comment for Dev1", "Dev2", - "Comment for Dev2" }; + const char* devices[] = {"Dev1", "Comment for Dev1", "Dev2", + "Comment for Dev2"}; ResetStubData(); @@ -356,8 +355,8 @@ TEST(AlsaUcm, GetDevForMixer) { snd_use_case_get_value[id_1] = value_1; snd_use_case_get_value[id_2] = value_2; - dev_name_out = ucm_get_dev_for_mixer( - mgr, value_1.c_str(), CRAS_STREAM_OUTPUT); + dev_name_out = + ucm_get_dev_for_mixer(mgr, value_1.c_str(), CRAS_STREAM_OUTPUT); dev_name_in = ucm_get_dev_for_mixer(mgr, value_2.c_str(), CRAS_STREAM_INPUT); ASSERT_TRUE(dev_name_out); @@ -370,10 +369,10 @@ TEST(AlsaUcm, GetDevForMixer) { } TEST(AlsaUcm, GetDeviceNameForDevice) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; const char *input_dev_name, *output_dev_name; - const char *devices[] = { "Dev1", "Comment for Dev1", "Dev2", - "Comment for Dev2" }; + const char* devices[] = {"Dev1", "Comment for Dev1", "Dev2", + "Comment for Dev2"}; ResetStubData(); @@ -387,7 +386,8 @@ TEST(AlsaUcm, GetDeviceNameForDevice) { snd_use_case_get_value[id_1] = value_1; snd_use_case_get_value[id_2] = value_2; input_dev_name = ucm_get_device_name_for_dev(mgr, "Dev1", CRAS_STREAM_INPUT); - output_dev_name = ucm_get_device_name_for_dev(mgr, "Dev2", CRAS_STREAM_OUTPUT); + output_dev_name = + ucm_get_device_name_for_dev(mgr, "Dev2", CRAS_STREAM_OUTPUT); ASSERT_TRUE(input_dev_name); ASSERT_TRUE(output_dev_name); EXPECT_EQ(0, strcmp(input_dev_name, value_1.c_str())); @@ -396,15 +396,15 @@ TEST(AlsaUcm, GetDeviceNameForDevice) { ASSERT_EQ(2, snd_use_case_get_called); EXPECT_EQ(snd_use_case_get_id[0], id_1); EXPECT_EQ(snd_use_case_get_id[1], id_2); - free((void *)input_dev_name); - free((void *)output_dev_name); + free((void*)input_dev_name); + free((void*)output_dev_name); } TEST(AlsaUcm, GetDeviceRateForDevice) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; int input_dev_rate, output_dev_rate; - const char *devices[] = { "Dev1", "Comment for Dev1", "Dev2", - "Comment for Dev2" }; + const char* devices[] = {"Dev1", "Comment for Dev1", "Dev2", + "Comment for Dev2"}; ResetStubData(); @@ -418,8 +418,8 @@ TEST(AlsaUcm, GetDeviceRateForDevice) { snd_use_case_get_value[id_1] = value_1; snd_use_case_get_value[id_2] = value_2; input_dev_rate = ucm_get_sample_rate_for_dev(mgr, "Dev1", CRAS_STREAM_INPUT); - output_dev_rate = ucm_get_sample_rate_for_dev(mgr, "Dev2", - CRAS_STREAM_OUTPUT); + output_dev_rate = + ucm_get_sample_rate_for_dev(mgr, "Dev2", CRAS_STREAM_OUTPUT); EXPECT_EQ(44100, input_dev_rate); EXPECT_EQ(48000, output_dev_rate); @@ -429,7 +429,7 @@ TEST(AlsaUcm, GetDeviceRateForDevice) { } TEST(AlsaUcm, GetCaptureChannelMapForDevice) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; int8_t channel_layout[CRAS_CH_MAX]; int rc; @@ -459,8 +459,8 @@ TEST(AlsaUcm, GetCaptureChannelMapForDevice) { } TEST(AlsaUcm, GetEchoReferenceDev) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; - const char *echo_ref_dev; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; + const char* echo_ref_dev; ResetStubData(); @@ -473,22 +473,16 @@ TEST(AlsaUcm, GetEchoReferenceDev) { ASSERT_EQ(1, snd_use_case_get_called); EXPECT_EQ(snd_use_case_get_id[0], id_1); EXPECT_EQ(0, strcmp(echo_ref_dev, value_1.c_str())); - free((void *)echo_ref_dev); + free((void*)echo_ref_dev); } TEST(AlsaUcm, GetHotwordModels) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; - const char *models; - const char *modifiers[] = { "Mod1", - "Comment1", - "Hotword Model en", - "Comment2", - "Hotword Model jp", - "Comment3", - "Mod2", - "Comment4", - "Hotword Model de", - "Comment5" }; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; + const char* models; + const char* modifiers[] = {"Mod1", "Comment1", "Hotword Model en", + "Comment2", "Hotword Model jp", "Comment3", + "Mod2", "Comment4", "Hotword Model de", + "Comment5"}; ResetStubData(); fake_list["_modifiers/HiFi"] = modifiers; @@ -497,18 +491,15 @@ TEST(AlsaUcm, GetHotwordModels) { models = ucm_get_hotword_models(mgr); ASSERT_TRUE(models); EXPECT_EQ(0, strcmp(models, "en,jp,de")); - free((void *)models); + free((void*)models); } TEST(AlsaUcm, SetHotwordModel) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; - const char *modifiers[] = { "Hotword Model en", - "Comment1", - "Hotword Model jp", - "Comment2", - "Hotword Model de", - "Comment3" }; - const char *enabled_mods[] = { "Hotword Model en" }; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; + const char* modifiers[] = {"Hotword Model en", "Comment1", + "Hotword Model jp", "Comment2", + "Hotword Model de", "Comment3"}; + const char* enabled_mods[] = {"Hotword Model en"}; ResetStubData(); fake_list["_modifiers/HiFi"] = modifiers; @@ -522,23 +513,23 @@ TEST(AlsaUcm, SetHotwordModel) { ucm_set_hotword_model(mgr, "jp"); EXPECT_EQ(2, snd_use_case_set_called); - EXPECT_EQ(snd_use_case_set_param[0], + EXPECT_EQ( + snd_use_case_set_param[0], std::make_pair(std::string("_dismod"), std::string("Hotword Model en"))); - EXPECT_EQ(snd_use_case_set_param[1], + EXPECT_EQ( + snd_use_case_set_param[1], std::make_pair(std::string("_enamod"), std::string("Hotword Model jp"))); } TEST(AlsaUcm, SwapModeExists) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; int rc; - const char *modifiers_1[] = { "Speaker Swap Mode", - "Comment for Speaker Swap Mode", - "Microphone Swap Mode", - "Comment for Microphone Swap Mode" }; - const char *modifiers_2[] = { "Speaker Some Mode", - "Comment for Speaker Some Mode", - "Microphone Some Mode", - "Comment for Microphone Some Mode" }; + const char* modifiers_1[] = { + "Speaker Swap Mode", "Comment for Speaker Swap Mode", + "Microphone Swap Mode", "Comment for Microphone Swap Mode"}; + const char* modifiers_2[] = { + "Speaker Some Mode", "Comment for Speaker Some Mode", + "Microphone Some Mode", "Comment for Microphone Some Mode"}; ResetStubData(); @@ -554,13 +545,12 @@ TEST(AlsaUcm, SwapModeExists) { } TEST(AlsaUcm, EnableSwapMode) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; int rc; - const char *modifiers[] = { "Speaker Swap Mode", - "Comment for Speaker Swap Mode", - "Microphone Swap Mode", - "Comment for Microphone Swap Mode" }; - const char *modifiers_enabled[] = {"Speaker Swap Mode"}; + const char* modifiers[] = { + "Speaker Swap Mode", "Comment for Speaker Swap Mode", + "Microphone Swap Mode", "Comment for Microphone Swap Mode"}; + const char* modifiers_enabled[] = {"Speaker Swap Mode"}; ResetStubData(); @@ -586,13 +576,12 @@ TEST(AlsaUcm, EnableSwapMode) { } TEST(AlsaUcm, DisableSwapMode) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; int rc; - const char *modifiers[] = { "Speaker Swap Mode", - "Comment for Speaker Swap Mode", - "Microphone Swap Mode", - "Comment for Microphone Swap Mode" }; - const char *modifiers_enabled[] = {"Speaker Swap Mode"}; + const char* modifiers[] = { + "Speaker Swap Mode", "Comment for Speaker Swap Mode", + "Microphone Swap Mode", "Comment for Microphone Swap Mode"}; + const char* modifiers_enabled[] = {"Speaker Swap Mode"}; ResetStubData(); @@ -615,12 +604,11 @@ TEST(AlsaUcm, DisableSwapMode) { rc = ucm_enable_swap_mode(mgr, "Speaker", 0); EXPECT_EQ(0, rc); EXPECT_EQ(1, snd_use_case_set_called); - } TEST(AlsaFlag, GetFlag) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; - char *flag_value; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; + char* flag_value; std::string id = "=FlagName//HiFi"; std::string value = "1"; @@ -638,12 +626,12 @@ TEST(AlsaFlag, GetFlag) { } TEST(AlsaUcm, ModifierEnabled) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; int enabled; ResetStubData(); - const char *mods[] = { "Mod1", "Mod2" }; + const char* mods[] = {"Mod1", "Mod2"}; fake_list["_enamods"] = mods; fake_list_size["_enamods"] = 2; @@ -656,7 +644,7 @@ TEST(AlsaUcm, ModifierEnabled) { } TEST(AlsaUcm, SetModifierEnabled) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; ResetStubData(); @@ -677,9 +665,9 @@ TEST(AlsaUcm, EndWithSuffix) { } TEST(AlsaUcm, SectionExistsWithName) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; - const char *sections[] = { "Sec1", "Comment for Sec1", "Sec2", - "Comment for Sec2" }; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; + const char* sections[] = {"Sec1", "Comment for Sec1", "Sec2", + "Comment for Sec2"}; ResetStubData(); @@ -691,12 +679,12 @@ TEST(AlsaUcm, SectionExistsWithName) { } TEST(AlsaUcm, SectionExistsWithSuffix) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; ResetStubData(); - const char *sections[] = { "Sec1 Suffix1", "Comment for Sec1", - "Sec2 Suffix2", "Comment for Sec2" }; + const char* sections[] = {"Sec1 Suffix1", "Comment for Sec1", "Sec2 Suffix2", + "Comment for Sec2"}; fake_list["Identifier"] = sections; fake_list_size["Identifier"] = 4; EXPECT_EQ(1, ucm_section_exists_with_suffix(mgr, "Suffix1", "Identifier")); @@ -705,7 +693,7 @@ TEST(AlsaUcm, SectionExistsWithSuffix) { } TEST(AlsaUcm, DisableSoftwareVolume) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; unsigned int disable_software_volume; std::string id = "=DisableSoftwareVolume//HiFi"; std::string value = "1"; @@ -722,10 +710,10 @@ TEST(AlsaUcm, DisableSoftwareVolume) { } TEST(AlsaUcm, GetCoupledMixersForDevice) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; struct mixer_name *mixer_names_1, *mixer_names_2, *c; - const char *devices[] = { "Dev1", "Comment for Dev1", "Dev2", - "Comment for Dev2" }; + const char* devices[] = {"Dev1", "Comment for Dev1", "Dev2", + "Comment for Dev2"}; ResetStubData(); @@ -748,7 +736,7 @@ TEST(AlsaUcm, GetCoupledMixersForDevice) { EXPECT_EQ(NULL, mixer_names_2); - DL_FOREACH(mixer_names_1, c) { + DL_FOREACH (mixer_names_1, c) { DL_DELETE(mixer_names_1, c); free((void*)c->name); free(c); @@ -756,9 +744,9 @@ TEST(AlsaUcm, GetCoupledMixersForDevice) { } TEST(AlsaUcm, FreeMixerNames) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; - struct mixer_name *mixer_names_1; - const char *devices[] = { "Dev1", "Comment for Dev1"}; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; + struct mixer_name* mixer_names_1; + const char* devices[] = {"Dev1", "Comment for Dev1"}; ResetStubData(); @@ -769,7 +757,6 @@ TEST(AlsaUcm, FreeMixerNames) { snd_use_case_get_value[id_1] = value_1; mixer_names_1 = ucm_get_coupled_mixer_names(mgr, "Dev1"); - ASSERT_TRUE(mixer_names_1); EXPECT_EQ(0, strcmp(mixer_names_1->name, "Mixer Name1")); EXPECT_EQ(0, strcmp(mixer_names_1->next->name, "Mixer Name2")); @@ -781,7 +768,7 @@ TEST(AlsaUcm, FreeMixerNames) { } TEST(AlsaUcm, MaxSoftwareGain) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; long max_software_gain; int ret; std::string id = "=MaxSoftwareGain/Internal Mic/HiFi"; @@ -806,7 +793,7 @@ TEST(AlsaUcm, MaxSoftwareGain) { } TEST(AlsaUcm, MinSoftwareGain) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; long min_software_gain; int ret; std::string id = "=MinSoftwareGain/Internal Mic/HiFi"; @@ -831,7 +818,7 @@ TEST(AlsaUcm, MinSoftwareGain) { } TEST(AlsaUcm, DefaultNodeGain) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; long default_node_gain; int ret; std::string id = "=DefaultNodeGain/Internal Mic/HiFi"; @@ -856,7 +843,7 @@ TEST(AlsaUcm, DefaultNodeGain) { } TEST(AlsaUcm, UseFullySpecifiedUCMConfig) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; int fully_specified_flag; std::string id = "=FullySpecifiedUCM//HiFi"; @@ -878,7 +865,7 @@ TEST(AlsaUcm, UseFullySpecifiedUCMConfig) { } TEST(AlsaUcm, EnableHtimestampFlag) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; unsigned int enable_htimestamp_flag; std::string id = "=EnableHtimestamp//HiFi"; @@ -900,10 +887,10 @@ TEST(AlsaUcm, EnableHtimestampFlag) { } TEST(AlsaUcm, GetMixerNameForDevice) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; const char *mixer_name_1, *mixer_name_2; - const char *devices[] = { "Dev1", "Comment for Dev1", "Dev2", - "Comment for Dev2" }; + const char* devices[] = {"Dev1", "Comment for Dev1", "Dev2", + "Comment for Dev2"}; ResetStubData(); @@ -921,12 +908,12 @@ TEST(AlsaUcm, GetMixerNameForDevice) { EXPECT_EQ(0, strcmp(mixer_name_1, value_1.c_str())); EXPECT_EQ(0, strcmp(mixer_name_2, value_2.c_str())); - free((void *)mixer_name_1); - free((void *)mixer_name_2); + free((void*)mixer_name_1); + free((void*)mixer_name_2); } TEST(AlsaUcm, GetMainVolumeMixerName) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; struct mixer_name *mixer_names_1, *mixer_names_2, *c; ResetStubData(); @@ -948,7 +935,7 @@ TEST(AlsaUcm, GetMainVolumeMixerName) { EXPECT_EQ(0, strcmp(mixer_names_1->next->next->name, "Mixer Name3")); EXPECT_EQ(NULL, mixer_names_1->next->next->next); - DL_FOREACH(mixer_names_1, c) { + DL_FOREACH (mixer_names_1, c) { DL_DELETE(mixer_names_1, c); free((void*)c->name); free(c); @@ -958,7 +945,7 @@ TEST(AlsaUcm, GetMainVolumeMixerName) { } TEST(AlsaUcm, ListSectionsByDeviceNameOutput) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; void* callback_arg = reinterpret_cast<void*>(0x56); int listed = 0; @@ -973,17 +960,15 @@ TEST(AlsaUcm, ListSectionsByDeviceNameOutput) { EXPECT_EQ(2, list_devices_callback_names.size()); EXPECT_EQ(2, list_devices_callback_args.size()); - EXPECT_EQ( - 0, strcmp(list_devices_callback_names[0].c_str(), "Speaker")); + EXPECT_EQ(0, strcmp(list_devices_callback_names[0].c_str(), "Speaker")); EXPECT_EQ(callback_arg, list_devices_callback_args[0]); - EXPECT_EQ( - 0, strcmp(list_devices_callback_names[1].c_str(), "Headphone")); + EXPECT_EQ(0, strcmp(list_devices_callback_names[1].c_str(), "Headphone")); EXPECT_EQ(callback_arg, list_devices_callback_args[1]); } TEST(AlsaUcm, ListSectionsByDeviceNameInput) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; void* callback_arg = reinterpret_cast<void*>(0x56); int listed = 0; @@ -998,20 +983,18 @@ TEST(AlsaUcm, ListSectionsByDeviceNameInput) { EXPECT_EQ(2, list_devices_callback_names.size()); EXPECT_EQ(2, list_devices_callback_args.size()); - EXPECT_EQ( - 0, strcmp(list_devices_callback_names[0].c_str(), "IntMic")); + EXPECT_EQ(0, strcmp(list_devices_callback_names[0].c_str(), "IntMic")); EXPECT_EQ(callback_arg, list_devices_callback_args[0]); - EXPECT_EQ( - 0, strcmp(list_devices_callback_names[1].c_str(), "ExtMic")); + EXPECT_EQ(0, strcmp(list_devices_callback_names[1].c_str(), "ExtMic")); EXPECT_EQ(callback_arg, list_devices_callback_args[1]); } TEST(AlsaUcm, GetJackNameForDevice) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; const char *jack_name_1, *jack_name_2; - const char *devices[] = { "Dev1", "Comment for Dev1", "Dev2", - "Comment for Dev2" }; + const char* devices[] = {"Dev1", "Comment for Dev1", "Dev2", + "Comment for Dev2"}; ResetStubData(); @@ -1027,17 +1010,16 @@ TEST(AlsaUcm, GetJackNameForDevice) { EXPECT_EQ(0, strcmp(jack_name_1, value_1.c_str())); EXPECT_EQ(NULL, jack_name_2); - free((void *)jack_name_1); - free((void *)jack_name_2); + free((void*)jack_name_1); + free((void*)jack_name_2); } TEST(AlsaUcm, GetJackTypeForDevice) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; const char *jack_type_1, *jack_type_2, *jack_type_3, *jack_type_4; - const char *devices[] = { "Dev1", "Comment for Dev1", - "Dev2", "Comment for Dev2", - "Dev3", "Comment for Dev3", - "Dev4", "Comment for Dev4"}; + const char* devices[] = { + "Dev1", "Comment for Dev1", "Dev2", "Comment for Dev2", + "Dev3", "Comment for Dev3", "Dev4", "Comment for Dev4"}; ResetStubData(); @@ -1065,18 +1047,18 @@ TEST(AlsaUcm, GetJackTypeForDevice) { EXPECT_EQ(NULL, jack_type_3); EXPECT_EQ(NULL, jack_type_4); - free((void *)jack_type_1); - free((void *)jack_type_2); - free((void *)jack_type_3); - free((void *)jack_type_4); + free((void*)jack_type_1); + free((void*)jack_type_2); + free((void*)jack_type_3); + free((void*)jack_type_4); } TEST(AlsaUcm, GetPeriodFramesForDevice) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; int dma_period_1, dma_period_2, dma_period_3; - const char *devices[] = { "Dev1", "Comment for Dev1", - "Dev2", "Comment for Dev2", - "Dev3", "Comment for Dev3" }; + const char* devices[] = {"Dev1", "Comment for Dev1", + "Dev2", "Comment for Dev2", + "Dev3", "Comment for Dev3"}; ResetStubData(); @@ -1101,21 +1083,18 @@ TEST(AlsaUcm, GetPeriodFramesForDevice) { } TEST(AlsaUcm, UcmSection) { - struct ucm_section *section_list = NULL; - struct ucm_section *section; - struct mixer_name *controls = NULL; - struct mixer_name *m_name; + struct ucm_section* section_list = NULL; + struct ucm_section* section; + struct mixer_name* controls = NULL; + struct mixer_name* m_name; int dev_idx = 0; size_t i; enum CRAS_STREAM_DIRECTION dir = CRAS_STREAM_OUTPUT; - static const char *name = "Headphone"; - static const char *jack_name = "my-card-name Headset Jack"; - static const char *jack_type = "gpio"; - static const char *mixer_name = "Control1"; - static const char *coupled_names[] = { - "Coupled1", - "Coupled2" - }; + static const char* name = "Headphone"; + static const char* jack_name = "my-card-name Headset Jack"; + static const char* jack_type = "gpio"; + static const char* mixer_name = "Control1"; + static const char* coupled_names[] = {"Coupled1", "Coupled2"}; section = ucm_section_create(NULL, 0, CRAS_STREAM_OUTPUT, NULL, NULL); EXPECT_EQ(reinterpret_cast<struct ucm_section*>(NULL), section); @@ -1129,7 +1108,7 @@ TEST(AlsaUcm, UcmSection) { EXPECT_NE(jack_name, section->jack_name); EXPECT_NE(jack_type, section->jack_type); EXPECT_EQ(section->prev, section); - EXPECT_EQ(reinterpret_cast<const char *>(NULL), section->mixer_name); + EXPECT_EQ(reinterpret_cast<const char*>(NULL), section->mixer_name); EXPECT_EQ(reinterpret_cast<struct mixer_name*>(NULL), section->coupled); EXPECT_EQ(-EINVAL, ucm_section_set_mixer_name(section, NULL)); @@ -1139,12 +1118,11 @@ TEST(AlsaUcm, UcmSection) { EXPECT_NE(section->mixer_name, mixer_name); EXPECT_EQ(0, strcmp(section->mixer_name, mixer_name)); - EXPECT_EQ(-EINVAL, ucm_section_add_coupled( - section, NULL, MIXER_NAME_VOLUME)); - EXPECT_EQ(-EINVAL, ucm_section_add_coupled( - NULL, coupled_names[0], MIXER_NAME_VOLUME)); - EXPECT_EQ(0, ucm_section_add_coupled( - section, coupled_names[0], MIXER_NAME_VOLUME)); + EXPECT_EQ(-EINVAL, ucm_section_add_coupled(section, NULL, MIXER_NAME_VOLUME)); + EXPECT_EQ(-EINVAL, + ucm_section_add_coupled(NULL, coupled_names[0], MIXER_NAME_VOLUME)); + EXPECT_EQ( + 0, ucm_section_add_coupled(section, coupled_names[0], MIXER_NAME_VOLUME)); EXPECT_EQ(-EINVAL, ucm_section_concat_coupled(section, NULL)); EXPECT_EQ(-EINVAL, ucm_section_concat_coupled( @@ -1152,14 +1130,14 @@ TEST(AlsaUcm, UcmSection) { controls = NULL; for (i = 1; i < ARRAY_SIZE(coupled_names); i++) { - controls = mixer_name_add(controls, coupled_names[i], - CRAS_STREAM_OUTPUT, MIXER_NAME_VOLUME); + controls = mixer_name_add(controls, coupled_names[i], CRAS_STREAM_OUTPUT, + MIXER_NAME_VOLUME); } /* Add controls to the list of coupled controls for this section. */ EXPECT_EQ(0, ucm_section_concat_coupled(section, controls)); i = 0; - DL_FOREACH(section->coupled, m_name) { + DL_FOREACH (section->coupled, m_name) { EXPECT_NE(m_name->name, coupled_names[i]); EXPECT_EQ(0, strcmp(m_name->name, coupled_names[i])); i++; @@ -1171,64 +1149,62 @@ TEST(AlsaUcm, UcmSection) { } TEST(AlsaUcm, GetSections) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; struct ucm_section* sections; struct ucm_section* section; struct mixer_name* m_name; int section_count = 0; int i = 0; - const char *devices[] = { "Headphone", "The headphones jack.", - "Speaker", "The speakers.", - "Mic", "Microphone jack.", - "Internal Mic", "Internal Microphones", - "HDMI", "HDMI output" }; - const char* ids[] = { - "=PlaybackPCM/Headphone/HiFi", - "=JackName/Headphone/HiFi", - "=JackType/Headphone/HiFi", - "=JackSwitch/Headphone/HiFi", - "=CoupledMixers/Headphone/HiFi", - - "=PlaybackPCM/Speaker/HiFi", - "=CoupledMixers/Speaker/HiFi", - - "=CapturePCM/Mic/HiFi", - "=JackName/Mic/HiFi", - "=JackType/Mic/HiFi", - "=JackSwitch/Mic/HiFi", - "=MixerName/Mic/HiFi", - - "=CapturePCM/Internal Mic/HiFi", - "=CoupledMixers/Internal Mic/HiFi", - "=JackSwitch/Internal Mic/HiFi", - - "=PlaybackPCM/HDMI/HiFi", - "=MixerName/HDMI/HiFi", - - NULL - }; + const char* devices[] = {"Headphone", "The headphones jack.", + "Speaker", "The speakers.", + "Mic", "Microphone jack.", + "Internal Mic", "Internal Microphones", + "HDMI", "HDMI output"}; + const char* ids[] = {"=PlaybackPCM/Headphone/HiFi", + "=JackName/Headphone/HiFi", + "=JackType/Headphone/HiFi", + "=JackSwitch/Headphone/HiFi", + "=CoupledMixers/Headphone/HiFi", + + "=PlaybackPCM/Speaker/HiFi", + "=CoupledMixers/Speaker/HiFi", + + "=CapturePCM/Mic/HiFi", + "=JackName/Mic/HiFi", + "=JackType/Mic/HiFi", + "=JackSwitch/Mic/HiFi", + "=MixerName/Mic/HiFi", + + "=CapturePCM/Internal Mic/HiFi", + "=CoupledMixers/Internal Mic/HiFi", + "=JackSwitch/Internal Mic/HiFi", + + "=PlaybackPCM/HDMI/HiFi", + "=MixerName/HDMI/HiFi", + + NULL}; const char* values[] = { - "hw:my-sound-card,0", - "my-sound-card Headset Jack", - "gpio", - "2", - "HP-L,HP-R", - - "hw:my-sound-card,0", - "SPK-L,SPK-R", - - "hw:my-sound-card,0", - "my-sound-card Headset Jack", - "gpio", - "0", - "CAPTURE", - - "hw:my-sound-card,0", - "MIC-L,MIC-R", - "-10", - - "hw:my-sound-card,2", - "HDMI", + "hw:my-sound-card,0", + "my-sound-card Headset Jack", + "gpio", + "2", + "HP-L,HP-R", + + "hw:my-sound-card,0", + "SPK-L,SPK-R", + + "hw:my-sound-card,0", + "my-sound-card Headset Jack", + "gpio", + "0", + "CAPTURE", + + "hw:my-sound-card,0", + "MIC-L,MIC-R", + "-10", + + "hw:my-sound-card,2", + "HDMI", }; ResetStubData(); @@ -1243,9 +1219,7 @@ TEST(AlsaUcm, GetSections) { sections = ucm_get_sections(mgr); ASSERT_NE(sections, (struct ucm_section*)NULL); - DL_FOREACH(sections, section) { - section_count++; - } + DL_FOREACH (sections, section) { section_count++; } EXPECT_EQ(section_count, ARRAY_SIZE(devices) / 2); // Headphone @@ -1288,7 +1262,7 @@ TEST(AlsaUcm, GetSections) { EXPECT_EQ(0, strcmp(section->jack_name, values[1])); EXPECT_EQ(0, strcmp(section->jack_type, values[2])); EXPECT_EQ(0, section->jack_switch); - ASSERT_NE((const char *)NULL, section->mixer_name); + ASSERT_NE((const char*)NULL, section->mixer_name); EXPECT_EQ(0, strcmp(section->mixer_name, "CAPTURE")); EXPECT_EQ(NULL, section->coupled); @@ -1315,7 +1289,7 @@ TEST(AlsaUcm, GetSections) { EXPECT_EQ(NULL, section->jack_name); EXPECT_EQ(NULL, section->jack_type); EXPECT_EQ(-1, section->jack_switch); - ASSERT_NE((const char *)NULL, section->mixer_name); + ASSERT_NE((const char*)NULL, section->mixer_name); EXPECT_EQ(0, strcmp(section->mixer_name, "HDMI")); EXPECT_EQ(NULL, section->next); @@ -1323,18 +1297,15 @@ TEST(AlsaUcm, GetSections) { } TEST(AlsaUcm, GetSectionsMissingPCM) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; struct ucm_section* sections; int i = 0; - const char *devices[] = { "Headphone", "The headphones jack." }; - const char* ids[] = { - "=JackName/Headphone/HiFi", - "=CoupledMixers/Headphone/HiFi", - NULL - }; + const char* devices[] = {"Headphone", "The headphones jack."}; + const char* ids[] = {"=JackName/Headphone/HiFi", + "=CoupledMixers/Headphone/HiFi", NULL}; const char* values[] = { - "my-sound-card Headset Jack", - "HP-L,HP-R", + "my-sound-card Headset Jack", + "HP-L,HP-R", }; ResetStubData(); @@ -1352,20 +1323,17 @@ TEST(AlsaUcm, GetSectionsMissingPCM) { } TEST(AlsaUcm, GetSectionsBadPCM) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; struct ucm_section* sections; int i = 0; - const char *devices[] = { "Headphone", "The headphones jack." }; - const char* ids[] = { - "=PlaybackPCM/Headphone/HiFi", - "=JackName/Headphone/HiFi", - "=CoupledMixers/Headphone/HiFi", - NULL - }; + const char* devices[] = {"Headphone", "The headphones jack."}; + const char* ids[] = {"=PlaybackPCM/Headphone/HiFi", + "=JackName/Headphone/HiFi", + "=CoupledMixers/Headphone/HiFi", NULL}; const char* values[] = { - "hw:my-sound-card:0", - "my-sound-card Headset Jack", - "HP-L,HP-R", + "hw:my-sound-card:0", + "my-sound-card Headset Jack", + "HP-L,HP-R", }; ResetStubData(); @@ -1383,7 +1351,7 @@ TEST(AlsaUcm, GetSectionsBadPCM) { } TEST(AlsaUcm, CheckUseCaseVerbs) { - struct cras_use_case_mgr *mgr = &cras_ucm_mgr; + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; /* Verifies the mapping between stream types and verbs are correct. */ mgr->use_case = CRAS_STREAM_TYPE_DEFAULT; @@ -1399,10 +1367,10 @@ TEST(AlsaUcm, CheckUseCaseVerbs) { } TEST(AlsaUcm, GetAvailUseCases) { - struct cras_use_case_mgr *mgr; - const char *verbs[] = { "HiFi", "Comment for Verb1", - "Voice Call", "Comment for Verb2", - "Speech", "Comment for Verb3" }; + struct cras_use_case_mgr* mgr; + const char* verbs[] = {"HiFi", "Comment for Verb1", + "Voice Call", "Comment for Verb2", + "Speech", "Comment for Verb3"}; ResetStubData(); @@ -1415,10 +1383,10 @@ TEST(AlsaUcm, GetAvailUseCases) { } TEST(AlsaUcm, SetUseCase) { - struct cras_use_case_mgr *mgr; - const char *verbs[] = { "HiFi", "Comment for Verb1", - "Voice Call", "Comment for Verb2", - "Speech", "Comment for Verb3" }; + struct cras_use_case_mgr* mgr; + const char* verbs[] = {"HiFi", "Comment for Verb1", + "Voice Call", "Comment for Verb2", + "Speech", "Comment for Verb3"}; int rc; ResetStubData(); @@ -1428,13 +1396,13 @@ TEST(AlsaUcm, SetUseCase) { mgr = ucm_create("foo"); EXPECT_EQ(snd_use_case_set_param[0], - std::make_pair(std::string("_verb"), std::string("HiFi"))); + std::make_pair(std::string("_verb"), std::string("HiFi"))); rc = ucm_set_use_case(mgr, CRAS_STREAM_TYPE_VOICE_COMMUNICATION); EXPECT_EQ(0, rc); EXPECT_EQ(mgr->use_case, CRAS_STREAM_TYPE_VOICE_COMMUNICATION); EXPECT_EQ(snd_use_case_set_param[1], - std::make_pair(std::string("_verb"), std::string("Voice Call"))); + std::make_pair(std::string("_verb"), std::string("Voice Call"))); /* Request unavailable use case will fail. */ rc = ucm_set_use_case(mgr, CRAS_STREAM_TYPE_PRO_AUDIO); @@ -1457,14 +1425,14 @@ int snd_use_case_mgr_open(snd_use_case_mgr_t** uc_mgr, const char* card_name) { return snd_use_case_mgr_open_return; } -int snd_use_case_mgr_close(snd_use_case_mgr_t *uc_mgr) { +int snd_use_case_mgr_close(snd_use_case_mgr_t* uc_mgr) { snd_use_case_mgr_close_called++; return 0; } int snd_use_case_get(snd_use_case_mgr_t* uc_mgr, - const char *identifier, - const char **value) { + const char* identifier, + const char** value) { snd_use_case_get_called++; snd_use_case_get_id.push_back(std::string(identifier)); if (snd_use_case_get_value.find(identifier) == snd_use_case_get_value.end()) { @@ -1476,22 +1444,22 @@ int snd_use_case_get(snd_use_case_mgr_t* uc_mgr, } int snd_use_case_set(snd_use_case_mgr_t* uc_mgr, - const char *identifier, - const char *value) { + const char* identifier, + const char* value) { snd_use_case_set_called++; snd_use_case_set_param.push_back( std::make_pair(std::string(identifier), std::string(value))); return snd_use_case_set_return; } -int snd_use_case_get_list(snd_use_case_mgr_t *uc_mgr, - const char *identifier, - const char **list[]) { +int snd_use_case_get_list(snd_use_case_mgr_t* uc_mgr, + const char* identifier, + const char** list[]) { *list = fake_list[identifier]; return fake_list_size[identifier]; } -int snd_use_case_free_list(const char *list[], int items) { +int snd_use_case_free_list(const char* list[], int items) { snd_use_case_free_list_called++; return 0; } diff --git a/cras/src/tests/apm_list_unittest.cc b/cras/src/tests/apm_list_unittest.cc index be8839dc..2c91cf9b 100644 --- a/cras/src/tests/apm_list_unittest.cc +++ b/cras/src/tests/apm_list_unittest.cc @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <stdio.h> #include <gtest/gtest.h> +#include <stdio.h> extern "C" { #include "cras_apm_list.h" @@ -18,25 +18,25 @@ extern "C" { namespace { -static void *stream_ptr = reinterpret_cast<void *>(0x123); -static void *dev_ptr = reinterpret_cast<void *>(0x345); -static void *dev_ptr2 = reinterpret_cast<void *>(0x678); -static struct cras_apm_list *list; +static void* stream_ptr = reinterpret_cast<void*>(0x123); +static void* dev_ptr = reinterpret_cast<void*>(0x345); +static void* dev_ptr2 = reinterpret_cast<void*>(0x678); +static struct cras_apm_list* list; static struct cras_audio_area fake_audio_area; static unsigned int dsp_util_interleave_frames; static unsigned int webrtc_apm_process_stream_f_called; static unsigned int webrtc_apm_process_reverse_stream_f_called; static device_enabled_callback_t device_enabled_callback_val; -static struct ext_dsp_module *ext_dsp_module_value; +static struct ext_dsp_module* ext_dsp_module_value; static struct cras_iodev fake_iodev; static int webrtc_apm_create_called; TEST(ApmList, ApmListCreate) { list = cras_apm_list_create(stream_ptr, 0); - EXPECT_EQ((void *)NULL, list); + EXPECT_EQ((void*)NULL, list); list = cras_apm_list_create(stream_ptr, APM_ECHO_CANCELLATION); - EXPECT_NE((void *)NULL, list); + EXPECT_NE((void*)NULL, list); EXPECT_EQ(APM_ECHO_CANCELLATION, cras_apm_list_get_effects(list)); cras_apm_list_destroy(list); @@ -50,36 +50,36 @@ TEST(ApmList, AddRemoveApm) { fmt.format = SND_PCM_FORMAT_S16_LE; list = cras_apm_list_create(stream_ptr, APM_ECHO_CANCELLATION); - EXPECT_NE((void *)NULL, list); + EXPECT_NE((void*)NULL, list); - EXPECT_NE((void *)NULL, cras_apm_list_add(list, dev_ptr, &fmt)); - EXPECT_EQ((void *)NULL, cras_apm_list_get(list, dev_ptr2)); + EXPECT_NE((void*)NULL, cras_apm_list_add(list, dev_ptr, &fmt)); + EXPECT_EQ((void*)NULL, cras_apm_list_get(list, dev_ptr2)); - EXPECT_NE((void *)NULL, cras_apm_list_add(list, dev_ptr2, &fmt)); - EXPECT_NE((void *)NULL, cras_apm_list_get(list, dev_ptr)); + EXPECT_NE((void*)NULL, cras_apm_list_add(list, dev_ptr2, &fmt)); + EXPECT_NE((void*)NULL, cras_apm_list_get(list, dev_ptr)); cras_apm_list_remove(list, dev_ptr); - EXPECT_EQ((void *)NULL, cras_apm_list_get(list, dev_ptr)); - EXPECT_NE((void *)NULL, cras_apm_list_get(list, dev_ptr2)); + EXPECT_EQ((void*)NULL, cras_apm_list_get(list, dev_ptr)); + EXPECT_NE((void*)NULL, cras_apm_list_get(list, dev_ptr2)); cras_apm_list_remove(list, dev_ptr2); - EXPECT_EQ((void *)NULL, cras_apm_list_get(list, dev_ptr2)); + EXPECT_EQ((void*)NULL, cras_apm_list_get(list, dev_ptr2)); cras_apm_list_destroy(list); } TEST(ApmList, ApmProcessForwardBuffer) { - struct cras_apm *apm; + struct cras_apm* apm; struct cras_audio_format fmt; - struct cras_audio_area *area; - struct float_buffer *buf; + struct cras_audio_area* area; + struct float_buffer* buf; fmt.num_channels = 2; fmt.frame_rate = 48000; fmt.format = SND_PCM_FORMAT_S16_LE; list = cras_apm_list_create(stream_ptr, APM_ECHO_CANCELLATION); - EXPECT_NE((void *)NULL, list); + EXPECT_NE((void*)NULL, list); apm = cras_apm_list_add(list, dev_ptr, &fmt); @@ -121,10 +121,10 @@ TEST(ApmList, ApmProcessForwardBuffer) { } TEST(ApmList, ApmProcessReverseData) { - struct cras_apm *apm; + struct cras_apm* apm; struct cras_audio_format fmt; - struct float_buffer *buf; - float *const *rp; + struct float_buffer* buf; + float* const* rp; unsigned int nread; struct cras_iodev fake_iodev; @@ -138,11 +138,11 @@ TEST(ApmList, ApmProcessReverseData) { webrtc_apm_process_reverse_stream_f_called = 0; cras_apm_list_init(""); - EXPECT_NE((void *)NULL, device_enabled_callback_val); + EXPECT_NE((void*)NULL, device_enabled_callback_val); device_enabled_callback_val(&fake_iodev, NULL); - EXPECT_NE((void *)NULL, ext_dsp_module_value); - EXPECT_NE((void *)NULL, ext_dsp_module_value->ports); + EXPECT_NE((void*)NULL, ext_dsp_module_value); + EXPECT_NE((void*)NULL, ext_dsp_module_value->ports); buf = float_buffer_create(500, 2); float_buffer_written(buf, 500); @@ -152,13 +152,12 @@ TEST(ApmList, ApmProcessReverseData) { for (int i = 0; i < buf->num_channels; i++) ext_dsp_module_value->ports[i] = rp[i]; - ext_dsp_module_value->configure(ext_dsp_module_value, - 800, 2, 48000); + ext_dsp_module_value->configure(ext_dsp_module_value, 800, 2, 48000); ext_dsp_module_value->run(ext_dsp_module_value, 500); EXPECT_EQ(0, webrtc_apm_process_reverse_stream_f_called); list = cras_apm_list_create(stream_ptr, APM_ECHO_CANCELLATION); - EXPECT_NE((void *)NULL, list); + EXPECT_NE((void*)NULL, list); apm = cras_apm_list_add(list, dev_ptr, &fmt); @@ -198,103 +197,82 @@ TEST(ApmList, StreamAddToAlreadyOpenedDev) { extern "C" { int cras_iodev_list_set_device_enabled_callback( - device_enabled_callback_t enabled_cb, - device_disabled_callback_t disabled_cb, - void *cb_data) -{ + device_enabled_callback_t enabled_cb, + device_disabled_callback_t disabled_cb, + void* cb_data) { device_enabled_callback_val = enabled_cb; return 0; } -struct cras_iodev *cras_iodev_list_get_first_enabled_iodev( - enum CRAS_STREAM_DIRECTION direction) -{ +struct cras_iodev* cras_iodev_list_get_first_enabled_iodev( + enum CRAS_STREAM_DIRECTION direction) { return &fake_iodev; } -void cras_iodev_set_ext_dsp_module(struct cras_iodev *iodev, - struct ext_dsp_module *ext) -{ +void cras_iodev_set_ext_dsp_module(struct cras_iodev* iodev, + struct ext_dsp_module* ext) { ext_dsp_module_value = ext; } -struct cras_audio_area *cras_audio_area_create(int num_channels) -{ +struct cras_audio_area* cras_audio_area_create(int num_channels) { return &fake_audio_area; } -void cras_audio_area_destroy(struct cras_audio_area *area) -{ -} -void cras_audio_area_config_channels(struct cras_audio_area *area, - const struct cras_audio_format *fmt) -{ -} -void cras_audio_area_config_buf_pointers(struct cras_audio_area *area, - const struct cras_audio_format *fmt, - uint8_t *base_buffer) -{ -} -void dsp_util_interleave(float *const *input, int16_t *output, int channels, - snd_pcm_format_t format, int frames) -{ +void cras_audio_area_destroy(struct cras_audio_area* area) {} +void cras_audio_area_config_channels(struct cras_audio_area* area, + const struct cras_audio_format* fmt) {} +void cras_audio_area_config_buf_pointers(struct cras_audio_area* area, + const struct cras_audio_format* fmt, + uint8_t* base_buffer) {} +void dsp_util_interleave(float* const* input, + int16_t* output, + int channels, + snd_pcm_format_t format, + int frames) { dsp_util_interleave_frames = frames; } -struct aec_config *aec_config_get(const char *device_config_dir) -{ +struct aec_config* aec_config_get(const char* device_config_dir) { return NULL; } -void aec_config_dump(struct aec_config *config) -{ -} -struct apm_config *apm_config_get(const char *device_config_dir) -{ +void aec_config_dump(struct aec_config* config) {} +struct apm_config* apm_config_get(const char* device_config_dir) { return NULL; } -void apm_config_dump(struct apm_config *config) -{ -} +void apm_config_dump(struct apm_config* config) {} webrtc_apm webrtc_apm_create(unsigned int num_channels, - unsigned int frame_rate, - dictionary *aec_ini, - dictionary *apm_ini) -{ + unsigned int frame_rate, + dictionary* aec_ini, + dictionary* apm_ini) { webrtc_apm_create_called++; return reinterpret_cast<webrtc_apm>(0x11); } -void webrtc_apm_dump_configs(dictionary *aec_ini, - dictionary *apm_ini) -{ -} -void webrtc_apm_destroy(webrtc_apm apm) -{ +void webrtc_apm_dump_configs(dictionary* aec_ini, dictionary* apm_ini) {} +void webrtc_apm_destroy(webrtc_apm apm) { return; } int webrtc_apm_process_stream_f(webrtc_apm ptr, - int num_channels, - int rate, - float *const *data) -{ + int num_channels, + int rate, + float* const* data) { webrtc_apm_process_stream_f_called++; return 0; } -int webrtc_apm_process_reverse_stream_f( - webrtc_apm ptr, - int num_channels, int rate, - float *const *data) -{ +int webrtc_apm_process_reverse_stream_f(webrtc_apm ptr, + int num_channels, + int rate, + float* const* data) { webrtc_apm_process_reverse_stream_f_called++; return 0; } -int webrtc_apm_aec_dump(webrtc_apm ptr, void** work_queue, - int start, FILE *handle) -{ +int webrtc_apm_aec_dump(webrtc_apm ptr, + void** work_queue, + int start, + FILE* handle) { return 0; } -} // extern "C" -} // namespace - +} // extern "C" +} // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/array_unittest.cc b/cras/src/tests/array_unittest.cc index 175994ba..e95cd713 100644 --- a/cras/src/tests/array_unittest.cc +++ b/cras/src/tests/array_unittest.cc @@ -2,10 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <gtest/gtest.h> - #include "array.h" +#include <gtest/gtest.h> + namespace { struct point { @@ -20,7 +20,7 @@ TEST(ArrayTest, Basic) { /* create an array {1.0, 2.0} */ ARRAY_APPEND(&a, 1.0); - double *p = ARRAY_APPEND_ZERO(&a); + double* p = ARRAY_APPEND_ZERO(&a); EXPECT_EQ(0.0, *p); *p = 2.0; @@ -85,7 +85,7 @@ TEST(ArrayTest, AppendZeroStruct) { TEST(ArrayTest, ForLoop) { int i; - double *p; + double* p; double_array a = ARRAY_INIT; for (i = 0; i < 100; i++) { @@ -94,7 +94,7 @@ TEST(ArrayTest, ForLoop) { int expectedIndex = 0; double expectedValue = 0; - ARRAY_ELEMENT_FOREACH(&a, i, p) { + ARRAY_ELEMENT_FOREACH (&a, i, p) { EXPECT_EQ(expectedIndex, i); EXPECT_EQ(expectedValue, *p); expectedIndex++; @@ -110,7 +110,7 @@ TEST(ArrayTest, ForLoop) { } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/audio_area_unittest.cc b/cras/src/tests/audio_area_unittest.cc index 7efe3a62..091d8dec 100644 --- a/cras/src/tests/audio_area_unittest.cc +++ b/cras/src/tests/audio_area_unittest.cc @@ -2,28 +2,28 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <stdio.h> #include <gtest/gtest.h> +#include <stdio.h> extern "C" { -#include "cras_audio_format.h" #include "cras_audio_area.h" +#include "cras_audio_format.h" } static const int8_t stereo[CRAS_CH_MAX] = { - 0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, }; static const int8_t mono[CRAS_CH_MAX] = { - -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, }; static const int8_t kb_mic[CRAS_CH_MAX] = { - 0, 1, -1, -1, 2, -1, -1, -1, -1, -1, -1, + 0, 1, -1, -1, 2, -1, -1, -1, -1, -1, -1, }; static uint16_t buf1[32]; static uint16_t buf2[32]; -struct cras_audio_area *a1; -struct cras_audio_area *a2; +struct cras_audio_area* a1; +struct cras_audio_area* a2; namespace { @@ -40,8 +40,8 @@ TEST(AudioArea, CopyAudioArea) { a2 = cras_audio_area_create(2); cras_audio_area_config_channels(a1, &fmt); cras_audio_area_config_channels(a2, &fmt); - cras_audio_area_config_buf_pointers(a1, &fmt, (uint8_t *)buf1); - cras_audio_area_config_buf_pointers(a2, &fmt, (uint8_t *)buf2); + cras_audio_area_config_buf_pointers(a1, &fmt, (uint8_t*)buf1); + cras_audio_area_config_buf_pointers(a2, &fmt, (uint8_t*)buf2); a1->frames = 16; a2->frames = 16; @@ -71,8 +71,8 @@ TEST(AudioArea, CopyAudioAreaWithGain) { a2 = cras_audio_area_create(2); cras_audio_area_config_channels(a1, &fmt); cras_audio_area_config_channels(a2, &fmt); - cras_audio_area_config_buf_pointers(a1, &fmt, (uint8_t *)buf1); - cras_audio_area_config_buf_pointers(a2, &fmt, (uint8_t *)buf2); + cras_audio_area_config_buf_pointers(a1, &fmt, (uint8_t*)buf1); + cras_audio_area_config_buf_pointers(a2, &fmt, (uint8_t*)buf2); a1->frames = 16; a2->frames = 16; @@ -107,8 +107,8 @@ TEST(AudioArea, CopyAudioAreaOffset) { a2 = cras_audio_area_create(2); cras_audio_area_config_channels(a1, &fmt); cras_audio_area_config_channels(a2, &fmt); - cras_audio_area_config_buf_pointers(a1, &fmt, (uint8_t *)buf1); - cras_audio_area_config_buf_pointers(a2, &fmt, (uint8_t *)buf2); + cras_audio_area_config_buf_pointers(a1, &fmt, (uint8_t*)buf1); + cras_audio_area_config_buf_pointers(a2, &fmt, (uint8_t*)buf2); a1->frames = 16; a2->frames = 14; @@ -121,7 +121,7 @@ TEST(AudioArea, CopyAudioAreaOffset) { EXPECT_EQ(buf1[2], 0); EXPECT_EQ(buf1[3], 0); for (i = 4; i < 32; i++) - EXPECT_EQ(buf1[i], buf2[i-4]); + EXPECT_EQ(buf1[i], buf2[i - 4]); cras_audio_area_destroy(a1); cras_audio_area_destroy(a2); @@ -140,8 +140,8 @@ TEST(AudioArea, CopyAudioAreaOffsetLimit) { a2 = cras_audio_area_create(2); cras_audio_area_config_channels(a1, &fmt); cras_audio_area_config_channels(a2, &fmt); - cras_audio_area_config_buf_pointers(a1, &fmt, (uint8_t *)buf1); - cras_audio_area_config_buf_pointers(a2, &fmt, (uint8_t *)buf2); + cras_audio_area_config_buf_pointers(a1, &fmt, (uint8_t*)buf1); + cras_audio_area_config_buf_pointers(a2, &fmt, (uint8_t*)buf2); a1->frames = 14; a2->frames = 14; @@ -154,7 +154,7 @@ TEST(AudioArea, CopyAudioAreaOffsetLimit) { EXPECT_EQ(buf1[2], 0); EXPECT_EQ(buf1[3], 0); for (i = 4; i < 28; i++) - EXPECT_EQ(buf1[i], buf2[i-4]); + EXPECT_EQ(buf1[i], buf2[i - 4]); EXPECT_EQ(buf1[28], 0); EXPECT_EQ(buf1[29], 0); EXPECT_EQ(buf1[30], 0); @@ -176,7 +176,7 @@ TEST(AudioArea, CopyMonoToStereo) { a1 = cras_audio_area_create(2); a1->frames = 16; cras_audio_area_config_channels(a1, &dst_fmt); - cras_audio_area_config_buf_pointers(a1, &dst_fmt, (uint8_t *)buf1); + cras_audio_area_config_buf_pointers(a1, &dst_fmt, (uint8_t*)buf1); src_fmt.num_channels = 1; src_fmt.format = SND_PCM_FORMAT_S16_LE; @@ -185,7 +185,7 @@ TEST(AudioArea, CopyMonoToStereo) { a2 = cras_audio_area_create(1); a2->frames = 16; cras_audio_area_config_channels(a2, &src_fmt); - cras_audio_area_config_buf_pointers(a2, &src_fmt, (uint8_t *)buf2); + cras_audio_area_config_buf_pointers(a2, &src_fmt, (uint8_t*)buf2); memset(buf1, 0, 32 * 2); for (i = 0; i < 32; i++) @@ -211,7 +211,7 @@ TEST(AudioArea, CopyStereoToMono) { a1 = cras_audio_area_create(1); a1->frames = 16; cras_audio_area_config_channels(a1, &fmt); - cras_audio_area_config_buf_pointers(a1, &fmt, (uint8_t *)buf1); + cras_audio_area_config_buf_pointers(a1, &fmt, (uint8_t*)buf1); fmt.num_channels = 2; for (i = 0; i < CRAS_CH_MAX; i++) @@ -219,7 +219,7 @@ TEST(AudioArea, CopyStereoToMono) { a2 = cras_audio_area_create(2); a2->frames = 16; cras_audio_area_config_channels(a2, &fmt); - cras_audio_area_config_buf_pointers(a2, &fmt, (uint8_t *)buf2); + cras_audio_area_config_buf_pointers(a2, &fmt, (uint8_t*)buf2); memset(buf1, 0, 32 * 2); for (i = 0; i < 32; i++) @@ -243,7 +243,7 @@ TEST(AudioArea, KeyboardMicCopyStereo) { a1 = cras_audio_area_create(3); a1->frames = 10; cras_audio_area_config_channels(a1, &fmt); - cras_audio_area_config_buf_pointers(a1, &fmt, (uint8_t *)buf1); + cras_audio_area_config_buf_pointers(a1, &fmt, (uint8_t*)buf1); fmt.num_channels = 2; for (i = 0; i < CRAS_CH_MAX; i++) @@ -251,7 +251,7 @@ TEST(AudioArea, KeyboardMicCopyStereo) { a2 = cras_audio_area_create(2); a2->frames = 10; cras_audio_area_config_channels(a2, &fmt); - cras_audio_area_config_buf_pointers(a2, &fmt, (uint8_t *)buf2); + cras_audio_area_config_buf_pointers(a2, &fmt, (uint8_t*)buf2); memset(buf1, 0, 32 * 2); for (i = 0; i < 32; i++) @@ -279,7 +279,7 @@ TEST(AudioArea, KeyboardMicCopyFrontCenter) { a1 = cras_audio_area_create(3); a1->frames = 10; cras_audio_area_config_channels(a1, &dst_fmt); - cras_audio_area_config_buf_pointers(a1, &dst_fmt, (uint8_t *)buf1); + cras_audio_area_config_buf_pointers(a1, &dst_fmt, (uint8_t*)buf1); /* Test 2 channels area with only front center in layout. */ src_fmt.num_channels = 2; @@ -290,7 +290,7 @@ TEST(AudioArea, KeyboardMicCopyFrontCenter) { a2 = cras_audio_area_create(2); a2->frames = 10; cras_audio_area_config_channels(a2, &src_fmt); - cras_audio_area_config_buf_pointers(a2, &src_fmt, (uint8_t *)buf2); + cras_audio_area_config_buf_pointers(a2, &src_fmt, (uint8_t*)buf2); memset(buf1, 0, 32 * 2); for (i = 0; i < 32; i++) @@ -310,28 +310,31 @@ TEST(AudioArea, KeyboardMicCopyFrontCenter) { extern "C" { -void cras_mix_add_scale_stride(snd_pcm_format_t fmt, uint8_t *dst, uint8_t *src, - unsigned int count, unsigned int dst_stride, - unsigned int src_stride, float scaler) -{ - unsigned int i; - - for (i = 0; i < count; i++) { - int32_t sum; - sum = *(int16_t *)dst + *(int16_t *)src * scaler; - if (sum > INT16_MAX) - sum = INT16_MAX; - else if (sum < INT16_MIN) - sum = INT16_MIN; - *(int16_t*)dst = sum; - dst += dst_stride; - src += src_stride; - } +void cras_mix_add_scale_stride(snd_pcm_format_t fmt, + uint8_t* dst, + uint8_t* src, + unsigned int count, + unsigned int dst_stride, + unsigned int src_stride, + float scaler) { + unsigned int i; + + for (i = 0; i < count; i++) { + int32_t sum; + sum = *(int16_t*)dst + *(int16_t*)src * scaler; + if (sum > INT16_MAX) + sum = INT16_MAX; + else if (sum < INT16_MIN) + sum = INT16_MIN; + *(int16_t*)dst = sum; + dst += dst_stride; + src += src_stride; + } } } // extern "C" -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/audio_format_unittest.cc b/cras/src/tests/audio_format_unittest.cc index 662a8780..f03f6878 100644 --- a/cras/src/tests/audio_format_unittest.cc +++ b/cras/src/tests/audio_format_unittest.cc @@ -12,27 +12,27 @@ extern "C" { namespace { class ChannelConvMtxTestSuite : public testing::Test { - protected: - virtual void SetUp() { - int i; - in_fmt = cras_audio_format_create(SND_PCM_FORMAT_S16_LE, 44100, 6); - out_fmt = cras_audio_format_create(SND_PCM_FORMAT_S16_LE, 44100, 6); - for (i = 0; i < CRAS_CH_MAX; i++) { - in_fmt->channel_layout[i] = -1; - out_fmt->channel_layout[i] = -1; - } + protected: + virtual void SetUp() { + int i; + in_fmt = cras_audio_format_create(SND_PCM_FORMAT_S16_LE, 44100, 6); + out_fmt = cras_audio_format_create(SND_PCM_FORMAT_S16_LE, 44100, 6); + for (i = 0; i < CRAS_CH_MAX; i++) { + in_fmt->channel_layout[i] = -1; + out_fmt->channel_layout[i] = -1; } - - virtual void TearDown() { - cras_audio_format_destroy(in_fmt); - cras_audio_format_destroy(out_fmt); - if (conv_mtx) - cras_channel_conv_matrix_destroy(conv_mtx, 6); - } - - struct cras_audio_format *in_fmt; - struct cras_audio_format *out_fmt; - float **conv_mtx; + } + + virtual void TearDown() { + cras_audio_format_destroy(in_fmt); + cras_audio_format_destroy(out_fmt); + if (conv_mtx) + cras_channel_conv_matrix_destroy(conv_mtx, 6); + } + + struct cras_audio_format* in_fmt; + struct cras_audio_format* out_fmt; + float** conv_mtx; }; TEST_F(ChannelConvMtxTestSuite, MatrixCreateSuccess) { @@ -51,7 +51,7 @@ TEST_F(ChannelConvMtxTestSuite, MatrixCreateSuccess) { out_fmt->channel_layout[5] = 5; conv_mtx = cras_channel_conv_matrix_create(in_fmt, out_fmt); - ASSERT_NE(conv_mtx, (void *)NULL); + ASSERT_NE(conv_mtx, (void*)NULL); } TEST_F(ChannelConvMtxTestSuite, MatrixCreateFail) { @@ -70,7 +70,7 @@ TEST_F(ChannelConvMtxTestSuite, MatrixCreateFail) { out_fmt->channel_layout[7] = 5; conv_mtx = cras_channel_conv_matrix_create(in_fmt, out_fmt); - ASSERT_EQ(conv_mtx, (void *)NULL); + ASSERT_EQ(conv_mtx, (void*)NULL); } TEST_F(ChannelConvMtxTestSuite, SLSRToRRRL) { @@ -91,12 +91,12 @@ TEST_F(ChannelConvMtxTestSuite, SLSRToRRRL) { out_fmt->channel_layout[5] = 3; conv_mtx = cras_channel_conv_matrix_create(in_fmt, out_fmt); - ASSERT_NE(conv_mtx, (void *)NULL); + ASSERT_NE(conv_mtx, (void*)NULL); } -} // namespace +} // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/audio_thread_monitor_unittest.cc b/cras/src/tests/audio_thread_monitor_unittest.cc index d62c5722..9e1de636 100644 --- a/cras/src/tests/audio_thread_monitor_unittest.cc +++ b/cras/src/tests/audio_thread_monitor_unittest.cc @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <stdio.h> #include <gtest/gtest.h> +#include <stdio.h> extern "C" { #include "cras_audio_thread_monitor.c" @@ -21,20 +21,17 @@ struct cras_audio_thread_event_message message; void ResetStubData() { cras_system_state_add_snapshot_called = 0; audio_thread_dump_thread_info_called = 0; - type_set = (enum CRAS_MAIN_MESSAGE_TYPE) 999; + type_set = (enum CRAS_MAIN_MESSAGE_TYPE)999; message.event_type = (enum CRAS_AUDIO_THREAD_EVENT_TYPE)999; } namespace { -class AudioThreadMonitorTestSuite: public testing::Test { - protected: - virtual void SetUp() { - ResetStubData(); - } +class AudioThreadMonitorTestSuite : public testing::Test { + protected: + virtual void SetUp() { ResetStubData(); } - virtual void TearDown() { - } + virtual void TearDown() {} }; TEST_F(AudioThreadMonitorTestSuite, Init) { @@ -43,25 +40,30 @@ TEST_F(AudioThreadMonitorTestSuite, Init) { } TEST_F(AudioThreadMonitorTestSuite, Busyloop) { - cras_audio_thread_busyloop(); + cras_audio_thread_event_busyloop(); EXPECT_EQ(message.event_type, AUDIO_THREAD_EVENT_BUSYLOOP); } TEST_F(AudioThreadMonitorTestSuite, Debug) { - cras_audio_thread_debug(); + cras_audio_thread_event_debug(); EXPECT_EQ(message.event_type, AUDIO_THREAD_EVENT_DEBUG); } TEST_F(AudioThreadMonitorTestSuite, Underrun) { - cras_audio_thread_underrun(); + cras_audio_thread_event_underrun(); EXPECT_EQ(message.event_type, AUDIO_THREAD_EVENT_UNDERRUN); } TEST_F(AudioThreadMonitorTestSuite, SevereUnderrun) { - cras_audio_thread_severe_underrun(); + cras_audio_thread_event_severe_underrun(); EXPECT_EQ(message.event_type, AUDIO_THREAD_EVENT_SEVERE_UNDERRUN); } +TEST_F(AudioThreadMonitorTestSuite, DropSamples) { + cras_audio_thread_event_drop_samples(); + EXPECT_EQ(message.event_type, AUDIO_THREAD_EVENT_DROP_SAMPLES); +} + TEST_F(AudioThreadMonitorTestSuite, TakeSnapshot) { take_snapshot(AUDIO_THREAD_EVENT_DEBUG); EXPECT_EQ(cras_system_state_add_snapshot_called, 1); @@ -71,12 +73,12 @@ TEST_F(AudioThreadMonitorTestSuite, TakeSnapshot) { TEST_F(AudioThreadMonitorTestSuite, EventHandlerDoubleCall) { struct cras_audio_thread_event_message msg; msg.event_type = AUDIO_THREAD_EVENT_DEBUG; - handle_audio_thread_event_message((struct cras_main_message *)&msg, NULL); + handle_audio_thread_event_message((struct cras_main_message*)&msg, NULL); EXPECT_EQ(cras_system_state_add_snapshot_called, 1); EXPECT_EQ(audio_thread_dump_thread_info_called, 1); // take_snapshot shouldn't be called since the time interval is short - handle_audio_thread_event_message((struct cras_main_message *)&msg, NULL); + handle_audio_thread_event_message((struct cras_main_message*)&msg, NULL); EXPECT_EQ(cras_system_state_add_snapshot_called, 1); EXPECT_EQ(audio_thread_dump_thread_info_called, 1); } @@ -84,7 +86,7 @@ TEST_F(AudioThreadMonitorTestSuite, EventHandlerDoubleCall) { TEST_F(AudioThreadMonitorTestSuite, EventHandlerIgnoreInvalidEvent) { struct cras_audio_thread_event_message msg; msg.event_type = (enum CRAS_AUDIO_THREAD_EVENT_TYPE)999; - handle_audio_thread_event_message((struct cras_main_message *)&msg, NULL); + handle_audio_thread_event_message((struct cras_main_message*)&msg, NULL); EXPECT_EQ(cras_system_state_add_snapshot_called, 0); EXPECT_EQ(audio_thread_dump_thread_info_called, 0); } @@ -92,28 +94,28 @@ TEST_F(AudioThreadMonitorTestSuite, EventHandlerIgnoreInvalidEvent) { extern "C" { void cras_system_state_add_snapshot( - struct cras_audio_thread_snapshot *snapshot) { - cras_system_state_add_snapshot_called ++; + struct cras_audio_thread_snapshot* snapshot) { + cras_system_state_add_snapshot_called++; } struct audio_thread* cras_iodev_list_get_audio_thread() { - return reinterpret_cast <struct audio_thread*>(0xff); + return reinterpret_cast<struct audio_thread*>(0xff); } -int audio_thread_dump_thread_info(struct audio_thread *thread, - struct audio_debug_info *info) { - audio_thread_dump_thread_info_called ++; +int audio_thread_dump_thread_info(struct audio_thread* thread, + struct audio_debug_info* info) { + audio_thread_dump_thread_info_called++; return 0; } int cras_main_message_add_handler(enum CRAS_MAIN_MESSAGE_TYPE type, cras_message_callback callback, - void *callback_data) { + void* callback_data) { type_set = type; return 0; } -int cras_main_message_send(struct cras_main_message *msg) { +int cras_main_message_send(struct cras_main_message* msg) { message = *(struct cras_audio_thread_event_message*)msg; return 0; } @@ -121,7 +123,7 @@ int cras_main_message_send(struct cras_main_message *msg) { } // extern "C" } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); int rc = RUN_ALL_TESTS(); diff --git a/cras/src/tests/audio_thread_unittest.cc b/cras/src/tests/audio_thread_unittest.cc index b542d38e..e06514e3 100644 --- a/cras/src/tests/audio_thread_unittest.cc +++ b/cras/src/tests/audio_thread_unittest.cc @@ -4,29 +4,33 @@ extern "C" { #include "audio_thread.c" + #include "cras_audio_area.h" #include "metrics_stub.h" } #include <gtest/gtest.h> + #include <map> #define MAX_CALLS 10 #define BUFFER_SIZE 8192 #define FIRST_CB_LEVEL 480 -static int cras_audio_thread_busyloop_called; +static int cras_audio_thread_event_busyloop_called; static unsigned int cras_rstream_dev_offset_called; static unsigned int cras_rstream_dev_offset_ret[MAX_CALLS]; -static const struct cras_rstream *cras_rstream_dev_offset_rstream_val[MAX_CALLS]; +static const struct cras_rstream* + cras_rstream_dev_offset_rstream_val[MAX_CALLS]; static unsigned int cras_rstream_dev_offset_dev_id_val[MAX_CALLS]; static unsigned int cras_rstream_dev_offset_update_called; -static const struct cras_rstream *cras_rstream_dev_offset_update_rstream_val[MAX_CALLS]; +static const struct cras_rstream* + cras_rstream_dev_offset_update_rstream_val[MAX_CALLS]; static unsigned int cras_rstream_dev_offset_update_frames_val[MAX_CALLS]; static unsigned int cras_rstream_dev_offset_update_dev_id_val[MAX_CALLS]; static int cras_rstream_is_pending_reply_ret; static int cras_iodev_all_streams_written_ret; -static struct cras_audio_area *cras_iodev_get_output_buffer_area; +static struct cras_audio_area* cras_iodev_get_output_buffer_area; static int cras_iodev_put_output_buffer_called; static unsigned int cras_iodev_put_output_buffer_nframes; static unsigned int cras_iodev_fill_odev_zeros_frames; @@ -35,22 +39,24 @@ static int dev_stream_mix_called; static unsigned int dev_stream_update_next_wake_time_called; static unsigned int dev_stream_request_playback_samples_called; static unsigned int cras_iodev_prepare_output_before_write_samples_called; -static enum CRAS_IODEV_STATE cras_iodev_prepare_output_before_write_samples_state; +static enum CRAS_IODEV_STATE + cras_iodev_prepare_output_before_write_samples_state; static unsigned int cras_iodev_get_output_buffer_called; static unsigned int cras_iodev_frames_to_play_in_sleep_called; static int cras_iodev_prepare_output_before_write_samples_ret; static int cras_iodev_reset_request_called; -static struct cras_iodev *cras_iodev_reset_request_iodev; +static struct cras_iodev* cras_iodev_reset_request_iodev; static int cras_iodev_get_valid_frames_ret; static int cras_iodev_output_underrun_called; static int cras_iodev_start_stream_called; static int cras_device_monitor_reset_device_called; -static struct cras_iodev *cras_device_monitor_reset_device_iodev; -static struct cras_iodev *cras_iodev_start_ramp_odev; +static struct cras_iodev* cras_device_monitor_reset_device_iodev; +static struct cras_iodev* cras_iodev_start_ramp_odev; static enum CRAS_IODEV_RAMP_REQUEST cras_iodev_start_ramp_request; static struct timespec clock_gettime_retspec; static struct timespec init_cb_ts_; -static std::map<const struct dev_stream*, struct timespec> dev_stream_wake_time_val; +static std::map<const struct dev_stream*, struct timespec> + dev_stream_wake_time_val; static int cras_device_monitor_set_device_mute_state_called; static int cras_iodev_is_zero_volume_ret; @@ -129,116 +135,112 @@ void TearDownRstream(struct cras_rstream* rstream) { // Test streams and devices manipulation. class StreamDeviceSuite : public testing::Test { - protected: - virtual void SetUp() { - thread_ = audio_thread_create(); - ResetStubData(); - } + protected: + virtual void SetUp() { + thread_ = audio_thread_create(); + ResetStubData(); + } - virtual void TearDown() { - audio_thread_destroy(thread_); - ResetGlobalStubData(); - } + virtual void TearDown() { + audio_thread_destroy(thread_); + ResetGlobalStubData(); + } - virtual void SetupDevice(cras_iodev *iodev, - enum CRAS_STREAM_DIRECTION direction) { - memset(iodev, 0, sizeof(*iodev)); - iodev->info.idx = ++device_id_; - iodev->direction = direction; - iodev->configure_dev = configure_dev; - iodev->close_dev = close_dev; - iodev->frames_queued = frames_queued; - iodev->delay_frames = delay_frames; - iodev->get_buffer = get_buffer; - iodev->put_buffer = put_buffer; - iodev->flush_buffer = flush_buffer; - iodev->format = &format_; - iodev->buffer_size = BUFFER_SIZE; - iodev->min_cb_level = FIRST_CB_LEVEL; - iodev->state = CRAS_IODEV_STATE_NORMAL_RUN; - format_.frame_rate = 48000; - } + virtual void SetupDevice(cras_iodev* iodev, + enum CRAS_STREAM_DIRECTION direction) { + memset(iodev, 0, sizeof(*iodev)); + iodev->info.idx = ++device_id_; + iodev->direction = direction; + iodev->configure_dev = configure_dev; + iodev->close_dev = close_dev; + iodev->frames_queued = frames_queued; + iodev->delay_frames = delay_frames; + iodev->get_buffer = get_buffer; + iodev->put_buffer = put_buffer; + iodev->flush_buffer = flush_buffer; + iodev->format = &format_; + iodev->buffer_size = BUFFER_SIZE; + iodev->min_cb_level = FIRST_CB_LEVEL; + iodev->state = CRAS_IODEV_STATE_NORMAL_RUN; + format_.frame_rate = 48000; + } - void ResetStubData() { - device_id_ = 0; - open_dev_called_ = 0; - close_dev_called_ = 0; - frames_queued_ = 0; - delay_frames_ = 0; - audio_buffer_size_ = 0; - cras_iodev_start_ramp_odev = NULL; - cras_iodev_is_zero_volume_ret = 0; - } + void ResetStubData() { + device_id_ = 0; + open_dev_called_ = 0; + close_dev_called_ = 0; + frames_queued_ = 0; + delay_frames_ = 0; + audio_buffer_size_ = 0; + cras_iodev_start_ramp_odev = NULL; + cras_iodev_is_zero_volume_ret = 0; + } - void SetupPinnedStream(struct cras_rstream *rstream, - enum CRAS_STREAM_DIRECTION direction, - cras_iodev* pin_to_dev) { - SetupRstream(rstream, direction); - rstream->is_pinned = 1; - rstream->pinned_dev_idx = pin_to_dev->info.idx; - } + void SetupPinnedStream(struct cras_rstream* rstream, + enum CRAS_STREAM_DIRECTION direction, + cras_iodev* pin_to_dev) { + SetupRstream(rstream, direction); + rstream->is_pinned = 1; + rstream->pinned_dev_idx = pin_to_dev->info.idx; + } - static int configure_dev(cras_iodev* iodev) { - open_dev_called_++; - return 0; - } + static int configure_dev(cras_iodev* iodev) { + open_dev_called_++; + return 0; + } - static int close_dev(cras_iodev* iodev) { - close_dev_called_++; - return 0; - } + static int close_dev(cras_iodev* iodev) { + close_dev_called_++; + return 0; + } - static int frames_queued(const cras_iodev* iodev, struct timespec* tstamp) { - clock_gettime(CLOCK_MONOTONIC_RAW, tstamp); - return frames_queued_; - } + static int frames_queued(const cras_iodev* iodev, struct timespec* tstamp) { + clock_gettime(CLOCK_MONOTONIC_RAW, tstamp); + return frames_queued_; + } - static int delay_frames(const cras_iodev* iodev) { - return delay_frames_; - } + static int delay_frames(const cras_iodev* iodev) { return delay_frames_; } - static int get_buffer(cras_iodev* iodev, - struct cras_audio_area** area, - unsigned int* num) { - size_t sz = sizeof(*area_) + sizeof(struct cras_channel_area) * 2; - - if (audio_buffer_size_ < *num) - *num = audio_buffer_size_; - - area_ = (cras_audio_area*)calloc(1, sz); - area_->frames = *num; - area_->num_channels = 2; - area_->channels[0].buf = audio_buffer_; - channel_area_set_channel(&area_->channels[0], CRAS_CH_FL); - area_->channels[0].step_bytes = 4; - area_->channels[1].buf = audio_buffer_ + 2; - channel_area_set_channel(&area_->channels[1], CRAS_CH_FR); - area_->channels[1].step_bytes = 4; - - *area = area_; - return 0; - } + static int get_buffer(cras_iodev* iodev, + struct cras_audio_area** area, + unsigned int* num) { + size_t sz = sizeof(*area_) + sizeof(struct cras_channel_area) * 2; - static int put_buffer(cras_iodev* iodev, unsigned int num) { - free(area_); - return 0; - } + if (audio_buffer_size_ < *num) + *num = audio_buffer_size_; - static int flush_buffer(cras_iodev *iodev) { - return 0; - } + area_ = (cras_audio_area*)calloc(1, sz); + area_->frames = *num; + area_->num_channels = 2; + area_->channels[0].buf = audio_buffer_; + channel_area_set_channel(&area_->channels[0], CRAS_CH_FL); + area_->channels[0].step_bytes = 4; + area_->channels[1].buf = audio_buffer_ + 2; + channel_area_set_channel(&area_->channels[1], CRAS_CH_FR); + area_->channels[1].step_bytes = 4; - int device_id_; - struct audio_thread *thread_; - - static int open_dev_called_; - static int close_dev_called_; - static int frames_queued_; - static int delay_frames_; - static struct cras_audio_format format_; - static struct cras_audio_area *area_; - static uint8_t audio_buffer_[BUFFER_SIZE]; - static unsigned int audio_buffer_size_; + *area = area_; + return 0; + } + + static int put_buffer(cras_iodev* iodev, unsigned int num) { + free(area_); + return 0; + } + + static int flush_buffer(cras_iodev* iodev) { return 0; } + + int device_id_; + struct audio_thread* thread_; + + static int open_dev_called_; + static int close_dev_called_; + static int frames_queued_; + static int delay_frames_; + static struct cras_audio_format format_; + static struct cras_audio_area* area_; + static uint8_t audio_buffer_[BUFFER_SIZE]; + static unsigned int audio_buffer_size_; }; int StreamDeviceSuite::open_dev_called_; @@ -246,13 +248,13 @@ int StreamDeviceSuite::close_dev_called_; int StreamDeviceSuite::frames_queued_; int StreamDeviceSuite::delay_frames_; struct cras_audio_format StreamDeviceSuite::format_; -struct cras_audio_area *StreamDeviceSuite::area_; +struct cras_audio_area* StreamDeviceSuite::area_; uint8_t StreamDeviceSuite::audio_buffer_[8192]; unsigned int StreamDeviceSuite::audio_buffer_size_; TEST_F(StreamDeviceSuite, AddRemoveOpenOutputDevice) { struct cras_iodev iodev; - struct open_dev *adev; + struct open_dev* adev; SetupDevice(&iodev, CRAS_STREAM_OUTPUT); @@ -268,7 +270,7 @@ TEST_F(StreamDeviceSuite, AddRemoveOpenOutputDevice) { TEST_F(StreamDeviceSuite, StartRamp) { struct cras_iodev iodev; - struct open_dev *adev; + struct open_dev* adev; int rc; enum CRAS_IODEV_RAMP_REQUEST req; @@ -321,7 +323,7 @@ TEST_F(StreamDeviceSuite, StartRamp) { TEST_F(StreamDeviceSuite, AddRemoveOpenInputDevice) { struct cras_iodev iodev; - struct open_dev *adev; + struct open_dev* adev; SetupDevice(&iodev, CRAS_STREAM_INPUT); @@ -342,7 +344,7 @@ TEST_F(StreamDeviceSuite, AddRemoveMultipleOpenDevices) { struct cras_iodev idev; struct cras_iodev idev2; struct cras_iodev idev3; - struct open_dev *adev; + struct open_dev* adev; SetupDevice(&odev, CRAS_STREAM_OUTPUT); SetupDevice(&odev2, CRAS_STREAM_OUTPUT); @@ -394,7 +396,7 @@ TEST_F(StreamDeviceSuite, AddRemoveMultipleOpenDevices) { TEST_F(StreamDeviceSuite, MultipleInputStreamsCopyFirstStreamOffset) { struct cras_iodev iodev; struct cras_iodev iodev2; - struct cras_iodev *iodevs[] = {&iodev, &iodev2}; + struct cras_iodev* iodevs[] = {&iodev, &iodev2}; struct cras_rstream rstream; struct cras_rstream rstream2; struct cras_rstream rstream3; @@ -409,8 +411,8 @@ TEST_F(StreamDeviceSuite, MultipleInputStreamsCopyFirstStreamOffset) { thread_add_open_dev(thread_, &iodev2); thread_add_stream(thread_, &rstream, iodevs, 2); - EXPECT_NE((void *)NULL, iodev.streams); - EXPECT_NE((void *)NULL, iodev2.streams); + EXPECT_NE((void*)NULL, iodev.streams); + EXPECT_NE((void*)NULL, iodev2.streams); EXPECT_EQ(0, cras_rstream_dev_offset_called); EXPECT_EQ(0, cras_rstream_dev_offset_update_called); @@ -441,11 +443,11 @@ TEST_F(StreamDeviceSuite, MultipleInputStreamsCopyFirstStreamOffset) { TEST_F(StreamDeviceSuite, InputStreamsSetInputDeviceWakeTime) { struct cras_iodev iodev; - struct cras_iodev *iodevs[] = {&iodev}; + struct cras_iodev* iodevs[] = {&iodev}; struct cras_rstream rstream1, rstream2; struct timespec ts_wake_1 = {.tv_sec = 1, .tv_nsec = 500}; struct timespec ts_wake_2 = {.tv_sec = 1, .tv_nsec = 1000}; - struct open_dev *adev; + struct open_dev* adev; SetupDevice(&iodev, CRAS_STREAM_INPUT); SetupRstream(&rstream1, CRAS_STREAM_INPUT); @@ -454,7 +456,7 @@ TEST_F(StreamDeviceSuite, InputStreamsSetInputDeviceWakeTime) { thread_add_open_dev(thread_, &iodev); thread_add_stream(thread_, &rstream1, iodevs, 1); thread_add_stream(thread_, &rstream2, iodevs, 1); - EXPECT_NE((void *)NULL, iodev.streams); + EXPECT_NE((void*)NULL, iodev.streams); // Assume device is running. iodev.state = CRAS_IODEV_STATE_NORMAL_RUN; @@ -485,8 +487,8 @@ TEST_F(StreamDeviceSuite, AddOutputStream) { struct cras_iodev iodev, *piodev = &iodev; struct cras_rstream rstream; struct cras_audio_shm_header* shm_header; - struct dev_stream *dev_stream; - struct open_dev *adev; + struct dev_stream* dev_stream; + struct open_dev* adev; ResetGlobalStubData(); SetupDevice(&iodev, CRAS_STREAM_OUTPUT); @@ -524,7 +526,7 @@ TEST_F(StreamDeviceSuite, AddOutputStream) { TEST_F(StreamDeviceSuite, OutputStreamFetchTime) { struct cras_iodev iodev, *piodev = &iodev; struct cras_rstream rstream1, rstream2; - struct dev_stream *dev_stream; + struct dev_stream* dev_stream; struct timespec expect_ts; ResetGlobalStubData(); @@ -588,7 +590,7 @@ TEST_F(StreamDeviceSuite, AddRemoveMultipleStreamsOnMultipleDevices) { struct cras_rstream rstream; struct cras_rstream rstream2; struct cras_rstream rstream3; - struct dev_stream *dev_stream; + struct dev_stream* dev_stream; SetupDevice(&iodev, CRAS_STREAM_OUTPUT); SetupDevice(&iodev2, CRAS_STREAM_OUTPUT); @@ -631,10 +633,10 @@ TEST_F(StreamDeviceSuite, AddRemoveMultipleStreamsOnMultipleDevices) { EXPECT_EQ(NULL, dev_stream->next); // Remove 2 streams, check the streams are removed from both open devices. - dev_io_remove_stream(&thread_->open_devs[rstream.direction], - &rstream, &iodev); - dev_io_remove_stream(&thread_->open_devs[rstream3.direction], - &rstream3, &iodev2); + dev_io_remove_stream(&thread_->open_devs[rstream.direction], &rstream, + &iodev); + dev_io_remove_stream(&thread_->open_devs[rstream3.direction], &rstream3, + &iodev2); dev_stream = iodev2.streams; EXPECT_EQ(NULL, dev_stream); @@ -654,7 +656,7 @@ TEST_F(StreamDeviceSuite, AddRemoveMultipleStreamsOnMultipleDevices) { TEST_F(StreamDeviceSuite, FetchStreams) { struct cras_iodev iodev, *piodev = &iodev; - struct open_dev *adev; + struct open_dev* adev; struct cras_rstream rstream; struct cras_audio_shm_header* shm_header; @@ -708,7 +710,7 @@ TEST_F(StreamDeviceSuite, FetchStreams) { TEST_F(StreamDeviceSuite, WriteOutputSamplesPrepareOutputFailed) { struct cras_iodev iodev; - struct open_dev *adev; + struct open_dev* adev; ResetGlobalStubData(); @@ -721,7 +723,7 @@ TEST_F(StreamDeviceSuite, WriteOutputSamplesPrepareOutputFailed) { // Assume device is started. iodev.state = CRAS_IODEV_STATE_NO_STREAM_RUN; // Assume device remains in no stream state; - cras_iodev_prepare_output_before_write_samples_state = \ + cras_iodev_prepare_output_before_write_samples_state = CRAS_IODEV_STATE_NO_STREAM_RUN; // Assume there is an error in prepare_output. @@ -729,8 +731,8 @@ TEST_F(StreamDeviceSuite, WriteOutputSamplesPrepareOutputFailed) { // cras_iodev should handle no stream playback. EXPECT_EQ(-EINVAL, - write_output_samples(&thread_->open_devs[CRAS_STREAM_OUTPUT], - adev, nullptr)); + write_output_samples(&thread_->open_devs[CRAS_STREAM_OUTPUT], adev, + nullptr)); // cras_iodev_get_output_buffer in audio_thread write_output_samples is not // called. @@ -741,7 +743,7 @@ TEST_F(StreamDeviceSuite, WriteOutputSamplesPrepareOutputFailed) { TEST_F(StreamDeviceSuite, WriteOutputSamplesNoStream) { struct cras_iodev iodev; - struct open_dev *adev; + struct open_dev* adev; ResetGlobalStubData(); @@ -754,7 +756,7 @@ TEST_F(StreamDeviceSuite, WriteOutputSamplesNoStream) { // Assume device is started. iodev.state = CRAS_IODEV_STATE_NO_STREAM_RUN; // Assume device remains in no stream state; - cras_iodev_prepare_output_before_write_samples_state = \ + cras_iodev_prepare_output_before_write_samples_state = CRAS_IODEV_STATE_NO_STREAM_RUN; // cras_iodev should handle no stream playback. @@ -769,7 +771,7 @@ TEST_F(StreamDeviceSuite, WriteOutputSamplesNoStream) { TEST_F(StreamDeviceSuite, WriteOutputSamplesLeaveNoStream) { struct cras_iodev iodev; - struct open_dev *adev; + struct open_dev* adev; ResetGlobalStubData(); @@ -786,7 +788,7 @@ TEST_F(StreamDeviceSuite, WriteOutputSamplesLeaveNoStream) { iodev.state = CRAS_IODEV_STATE_NO_STREAM_RUN; // Assume device remains in no stream state; - cras_iodev_prepare_output_before_write_samples_state = \ + cras_iodev_prepare_output_before_write_samples_state = CRAS_IODEV_STATE_NO_STREAM_RUN; // cras_iodev should NOT leave no stream state; @@ -797,7 +799,7 @@ TEST_F(StreamDeviceSuite, WriteOutputSamplesLeaveNoStream) { EXPECT_EQ(0, cras_iodev_get_output_buffer_called); // Assume device leaves no stream state; - cras_iodev_prepare_output_before_write_samples_state = \ + cras_iodev_prepare_output_before_write_samples_state = CRAS_IODEV_STATE_NORMAL_RUN; // cras_iodev should write samples from streams. @@ -812,8 +814,8 @@ TEST_F(StreamDeviceSuite, MixOutputSamples) { struct cras_iodev iodev, *piodev = &iodev; struct cras_rstream rstream1; struct cras_rstream rstream2; - struct open_dev *adev; - struct dev_stream *dev_stream; + struct open_dev* adev; + struct dev_stream* dev_stream; ResetGlobalStubData(); @@ -833,7 +835,7 @@ TEST_F(StreamDeviceSuite, MixOutputSamples) { iodev.state = CRAS_IODEV_STATE_NORMAL_RUN; // Assume device in normal run stream state. - cras_iodev_prepare_output_before_write_samples_state = \ + cras_iodev_prepare_output_before_write_samples_state = CRAS_IODEV_STATE_NORMAL_RUN; // cras_iodev should not mix samples because the stream has not started @@ -888,7 +890,7 @@ TEST_F(StreamDeviceSuite, DoPlaybackNoStream) { // Assume device is started. iodev.state = CRAS_IODEV_STATE_NO_STREAM_RUN; // Assume device remains in no stream state; - cras_iodev_prepare_output_before_write_samples_state = \ + cras_iodev_prepare_output_before_write_samples_state = CRAS_IODEV_STATE_NO_STREAM_RUN; // Add 10 frames in queue to prevent underrun frames_queued_ = 10; @@ -933,7 +935,7 @@ TEST_F(StreamDeviceSuite, DoPlaybackUnderrun) { cras_iodev_all_streams_written_ret = 11; // Assume device in normal run stream state; - cras_iodev_prepare_output_before_write_samples_state = \ + cras_iodev_prepare_output_before_write_samples_state = CRAS_IODEV_STATE_NORMAL_RUN; EXPECT_EQ(0, cras_iodev_output_underrun_called); @@ -965,7 +967,7 @@ TEST_F(StreamDeviceSuite, DoPlaybackSevereUnderrun) { frames_queued_ = -EPIPE; // Assume device in normal run stream state; - cras_iodev_prepare_output_before_write_samples_state = \ + cras_iodev_prepare_output_before_write_samples_state = CRAS_IODEV_STATE_NORMAL_RUN; dev_io_playback_write(&thread_->open_devs[CRAS_STREAM_OUTPUT], nullptr); @@ -1003,83 +1005,74 @@ TEST(AudioThreadStreams, DrainStream) { TEST(BusyloopDetectSuite, CheckerTest) { continuous_zero_sleep_count = 0; - cras_audio_thread_busyloop_called = 0; + cras_audio_thread_event_busyloop_called = 0; timespec wait_ts; wait_ts.tv_sec = 0; wait_ts.tv_nsec = 0; check_busyloop(&wait_ts); EXPECT_EQ(continuous_zero_sleep_count, 1); - EXPECT_EQ(cras_audio_thread_busyloop_called, 0); + EXPECT_EQ(cras_audio_thread_event_busyloop_called, 0); check_busyloop(&wait_ts); EXPECT_EQ(continuous_zero_sleep_count, 2); - EXPECT_EQ(cras_audio_thread_busyloop_called, 1); + EXPECT_EQ(cras_audio_thread_event_busyloop_called, 1); check_busyloop(&wait_ts); EXPECT_EQ(continuous_zero_sleep_count, 3); - EXPECT_EQ(cras_audio_thread_busyloop_called, 1); + EXPECT_EQ(cras_audio_thread_event_busyloop_called, 1); wait_ts.tv_sec = 1; check_busyloop(&wait_ts); EXPECT_EQ(continuous_zero_sleep_count, 0); - EXPECT_EQ(cras_audio_thread_busyloop_called, 1); + EXPECT_EQ(cras_audio_thread_event_busyloop_called, 1); } extern "C" { -int cras_iodev_add_stream(struct cras_iodev *iodev, struct dev_stream *stream) -{ +int cras_iodev_add_stream(struct cras_iodev* iodev, struct dev_stream* stream) { DL_APPEND(iodev->streams, stream); return 0; } -void cras_iodev_start_stream(struct cras_iodev *iodev, - struct dev_stream *stream) -{ +void cras_iodev_start_stream(struct cras_iodev* iodev, + struct dev_stream* stream) { dev_stream_set_running(stream); cras_iodev_start_stream_called++; } -unsigned int cras_iodev_all_streams_written(struct cras_iodev *iodev) -{ +unsigned int cras_iodev_all_streams_written(struct cras_iodev* iodev) { return cras_iodev_all_streams_written_ret; } -int cras_iodev_close(struct cras_iodev *iodev) -{ +int cras_iodev_close(struct cras_iodev* iodev) { return 0; } -void cras_iodev_free_format(struct cras_iodev *iodev) -{ +void cras_iodev_free_format(struct cras_iodev* iodev) { return; } -double cras_iodev_get_est_rate_ratio(const struct cras_iodev *iodev) -{ +double cras_iodev_get_est_rate_ratio(const struct cras_iodev* iodev) { return 1.0; } -unsigned int cras_iodev_max_stream_offset(const struct cras_iodev *iodev) -{ +unsigned int cras_iodev_max_stream_offset(const struct cras_iodev* iodev) { return 0; } -int cras_iodev_open(struct cras_iodev *iodev, unsigned int cb_level, - const struct cras_audio_format *fmt) -{ +int cras_iodev_open(struct cras_iodev* iodev, + unsigned int cb_level, + const struct cras_audio_format* fmt) { return 0; } -int cras_iodev_put_buffer(struct cras_iodev *iodev, unsigned int nframes) -{ +int cras_iodev_put_buffer(struct cras_iodev* iodev, unsigned int nframes) { return 0; } -struct dev_stream *cras_iodev_rm_stream(struct cras_iodev *iodev, - const struct cras_rstream *stream) -{ - struct dev_stream *out; - DL_FOREACH(iodev->streams, out) { +struct dev_stream* cras_iodev_rm_stream(struct cras_iodev* iodev, + const struct cras_rstream* stream) { + struct dev_stream* out; + DL_FOREACH (iodev->streams, out) { if (out->stream == stream) { DL_DELETE(iodev->streams, out); return out; @@ -1088,104 +1081,85 @@ struct dev_stream *cras_iodev_rm_stream(struct cras_iodev *iodev, return NULL; } -int cras_iodev_set_format(struct cras_iodev *iodev, - const struct cras_audio_format *fmt) -{ +int cras_iodev_set_format(struct cras_iodev* iodev, + const struct cras_audio_format* fmt) { return 0; } -unsigned int cras_iodev_stream_offset(struct cras_iodev *iodev, - struct dev_stream *stream) -{ +unsigned int cras_iodev_stream_offset(struct cras_iodev* iodev, + struct dev_stream* stream) { return 0; } -int cras_iodev_is_zero_volume(const struct cras_iodev *iodev) -{ +int cras_iodev_is_zero_volume(const struct cras_iodev* iodev) { return cras_iodev_is_zero_volume_ret; } -int dev_stream_attached_devs(const struct dev_stream *dev_stream) -{ +int dev_stream_attached_devs(const struct dev_stream* dev_stream) { return 1; } -void cras_iodev_stream_written(struct cras_iodev *iodev, - struct dev_stream *stream, - unsigned int nwritten) -{ -} +void cras_iodev_stream_written(struct cras_iodev* iodev, + struct dev_stream* stream, + unsigned int nwritten) {} -int cras_iodev_update_rate(struct cras_iodev *iodev, unsigned int level, - struct timespec *level_tstamp) -{ +int cras_iodev_update_rate(struct cras_iodev* iodev, + unsigned int level, + struct timespec* level_tstamp) { return 0; } -int cras_iodev_put_input_buffer(struct cras_iodev *iodev) -{ +int cras_iodev_put_input_buffer(struct cras_iodev* iodev) { return 0; } -int cras_iodev_put_output_buffer(struct cras_iodev *iodev, uint8_t *frames, - unsigned int nframes, int* non_empty, - struct cras_fmt_conv *output_converter) { +int cras_iodev_put_output_buffer(struct cras_iodev* iodev, + uint8_t* frames, + unsigned int nframes, + int* non_empty, + struct cras_fmt_conv* output_converter) { cras_iodev_put_output_buffer_called++; cras_iodev_put_output_buffer_nframes = nframes; return 0; } -int cras_iodev_get_input_buffer(struct cras_iodev *iodev, - unsigned *frames) -{ +int cras_iodev_get_input_buffer(struct cras_iodev* iodev, unsigned* frames) { return 0; } -int cras_iodev_get_output_buffer(struct cras_iodev *iodev, - struct cras_audio_area **area, - unsigned *frames) -{ +int cras_iodev_get_output_buffer(struct cras_iodev* iodev, + struct cras_audio_area** area, + unsigned* frames) { cras_iodev_get_output_buffer_called++; *area = cras_iodev_get_output_buffer_area; return 0; } -int cras_iodev_get_dsp_delay(const struct cras_iodev *iodev) -{ +int cras_iodev_get_dsp_delay(const struct cras_iodev* iodev) { return 0; } -void cras_fmt_conv_destroy(struct cras_fmt_conv **conv) -{ -} +void cras_fmt_conv_destroy(struct cras_fmt_conv** conv) {} -struct cras_fmt_conv *cras_channel_remix_conv_create( - unsigned int num_channels, - const float *coefficient) -{ +struct cras_fmt_conv* cras_channel_remix_conv_create(unsigned int num_channels, + const float* coefficient) { return NULL; } -void cras_rstream_dev_attach(struct cras_rstream *rstream, +void cras_rstream_dev_attach(struct cras_rstream* rstream, unsigned int dev_id, - void *dev_ptr) -{ -} + void* dev_ptr) {} -void cras_rstream_dev_detach(struct cras_rstream *rstream, unsigned int dev_id) -{ -} +void cras_rstream_dev_detach(struct cras_rstream* rstream, + unsigned int dev_id) {} -void cras_rstream_destroy(struct cras_rstream *stream) -{ -} +void cras_rstream_destroy(struct cras_rstream* stream) {} -void cras_rstream_dev_offset_update(struct cras_rstream *rstream, - unsigned int frames, - unsigned int dev_id) -{ +void cras_rstream_dev_offset_update(struct cras_rstream* rstream, + unsigned int frames, + unsigned int dev_id) { int i = cras_rstream_dev_offset_update_called; - if (i < MAX_CALLS) { + if (i < MAX_CALLS) { cras_rstream_dev_offset_update_rstream_val[i] = rstream; cras_rstream_dev_offset_update_frames_val[i] = frames; cras_rstream_dev_offset_update_dev_id_val[i] = dev_id; @@ -1193,9 +1167,8 @@ void cras_rstream_dev_offset_update(struct cras_rstream *rstream, } } -unsigned int cras_rstream_dev_offset(const struct cras_rstream *rstream, - unsigned int dev_id) -{ +unsigned int cras_rstream_dev_offset(const struct cras_rstream* rstream, + unsigned int dev_id) { int i = cras_rstream_dev_offset_called; if (i < MAX_CALLS) { cras_rstream_dev_offset_rstream_val[i] = rstream; @@ -1206,134 +1179,107 @@ unsigned int cras_rstream_dev_offset(const struct cras_rstream *rstream, return 0; } -void cras_rstream_record_fetch_interval(struct cras_rstream *rstream, - const struct timespec *now) -{ -} +void cras_rstream_record_fetch_interval(struct cras_rstream* rstream, + const struct timespec* now) {} -int cras_rstream_is_pending_reply(const struct cras_rstream *stream) -{ +int cras_rstream_is_pending_reply(const struct cras_rstream* stream) { return cras_rstream_is_pending_reply_ret; } -float cras_rstream_get_volume_scaler(struct cras_rstream *rstream) -{ +float cras_rstream_get_volume_scaler(struct cras_rstream* rstream) { return 1.0f; } -int cras_set_rt_scheduling(int rt_lim) -{ +int cras_set_rt_scheduling(int rt_lim) { return 0; } -int cras_set_thread_priority(int priority) -{ +int cras_set_thread_priority(int priority) { return 0; } -void cras_system_rm_select_fd(int fd) -{ -} +void cras_system_rm_select_fd(int fd) {} -unsigned int dev_stream_capture(struct dev_stream *dev_stream, - const struct cras_audio_area *area, +unsigned int dev_stream_capture(struct dev_stream* dev_stream, + const struct cras_audio_area* area, unsigned int area_offset, - float software_gain_scaler) -{ + float software_gain_scaler) { return 0; } -unsigned int dev_stream_capture_avail(const struct dev_stream *dev_stream) -{ +unsigned int dev_stream_capture_avail(const struct dev_stream* dev_stream) { return 0; - } -unsigned int dev_stream_cb_threshold(const struct dev_stream *dev_stream) -{ +unsigned int dev_stream_cb_threshold(const struct dev_stream* dev_stream) { return 0; } -int dev_stream_capture_update_rstream(struct dev_stream *dev_stream) -{ +int dev_stream_capture_update_rstream(struct dev_stream* dev_stream) { return 0; } -struct dev_stream *dev_stream_create(struct cras_rstream *stream, +struct dev_stream* dev_stream_create(struct cras_rstream* stream, unsigned int dev_id, - const struct cras_audio_format *dev_fmt, - void *dev_ptr, struct timespec *cb_ts) -{ - struct dev_stream *out = static_cast<dev_stream*>(calloc(1, sizeof(*out))); + const struct cras_audio_format* dev_fmt, + void* dev_ptr, + struct timespec* cb_ts) { + struct dev_stream* out = static_cast<dev_stream*>(calloc(1, sizeof(*out))); out->stream = stream; init_cb_ts_ = *cb_ts; return out; } -void dev_stream_destroy(struct dev_stream *dev_stream) -{ +void dev_stream_destroy(struct dev_stream* dev_stream) { free(dev_stream); } -int dev_stream_mix(struct dev_stream *dev_stream, - const struct cras_audio_format *fmt, - uint8_t *dst, - unsigned int num_to_write) -{ +int dev_stream_mix(struct dev_stream* dev_stream, + const struct cras_audio_format* fmt, + uint8_t* dst, + unsigned int num_to_write) { dev_stream_mix_called++; return num_to_write; } -int dev_stream_playback_frames(const struct dev_stream *dev_stream) -{ +int dev_stream_playback_frames(const struct dev_stream* dev_stream) { return dev_stream_playback_frames_ret; } -int dev_stream_playback_update_rstream(struct dev_stream *dev_stream) -{ +int dev_stream_playback_update_rstream(struct dev_stream* dev_stream) { return 0; } -int dev_stream_poll_stream_fd(const struct dev_stream *dev_stream) -{ +int dev_stream_poll_stream_fd(const struct dev_stream* dev_stream) { return dev_stream->stream->fd; } -int dev_stream_request_playback_samples(struct dev_stream *dev_stream, - const struct timespec *now) -{ +int dev_stream_request_playback_samples(struct dev_stream* dev_stream, + const struct timespec* now) { dev_stream_request_playback_samples_called++; return 0; } -void dev_stream_set_delay(const struct dev_stream *dev_stream, - unsigned int delay_frames) -{ -} +void dev_stream_set_delay(const struct dev_stream* dev_stream, + unsigned int delay_frames) {} -void dev_stream_set_dev_rate(struct dev_stream *dev_stream, +void dev_stream_set_dev_rate(struct dev_stream* dev_stream, unsigned int dev_rate, double dev_rate_ratio, double master_rate_ratio, - int coarse_rate_adjust) -{ -} + int coarse_rate_adjust) {} -void dev_stream_update_frames(const struct dev_stream *dev_stream) -{ -} +void dev_stream_update_frames(const struct dev_stream* dev_stream) {} -void dev_stream_update_next_wake_time(struct dev_stream *dev_stream) -{ +void dev_stream_update_next_wake_time(struct dev_stream* dev_stream) { dev_stream_update_next_wake_time_called++; } -int dev_stream_wake_time(struct dev_stream *dev_stream, +int dev_stream_wake_time(struct dev_stream* dev_stream, unsigned int curr_level, - struct timespec *level_tstamp, + struct timespec* level_tstamp, unsigned int cap_limit, int is_cap_limit_stream, - struct timespec *wake_time) -{ + struct timespec* wake_time) { if (dev_stream_wake_time_val.find(dev_stream) != dev_stream_wake_time_val.end()) { wake_time->tv_sec = dev_stream_wake_time_val[dev_stream].tv_sec; @@ -1342,179 +1288,163 @@ int dev_stream_wake_time(struct dev_stream *dev_stream, return 0; } -int dev_stream_is_pending_reply(const struct dev_stream *dev_stream) -{ +int dev_stream_is_pending_reply(const struct dev_stream* dev_stream) { return 0; } -int dev_stream_flush_old_audio_messages(struct dev_stream *dev_stream) -{ +int dev_stream_flush_old_audio_messages(struct dev_stream* dev_stream) { return 0; } -int cras_iodev_frames_queued(struct cras_iodev *iodev, struct timespec *tstamp) -{ - return iodev->frames_queued(iodev, tstamp); +int cras_iodev_frames_queued(struct cras_iodev* iodev, + struct timespec* tstamp) { + return iodev->frames_queued(iodev, tstamp); } -int cras_iodev_buffer_avail(struct cras_iodev *iodev, unsigned hw_level) -{ +int cras_iodev_buffer_avail(struct cras_iodev* iodev, unsigned hw_level) { struct timespec tstamp; return iodev->buffer_size - iodev->frames_queued(iodev, &tstamp); } -int cras_iodev_fill_odev_zeros(struct cras_iodev *odev, unsigned int frames) -{ +int cras_iodev_fill_odev_zeros(struct cras_iodev* odev, unsigned int frames) { cras_iodev_fill_odev_zeros_frames = frames; return 0; } -int cras_iodev_output_underrun(struct cras_iodev *odev) -{ +int cras_iodev_output_underrun(struct cras_iodev* odev) { cras_iodev_output_underrun_called++; return 0; } -int cras_iodev_prepare_output_before_write_samples(struct cras_iodev *odev) -{ +int cras_iodev_prepare_output_before_write_samples(struct cras_iodev* odev) { cras_iodev_prepare_output_before_write_samples_called++; odev->state = cras_iodev_prepare_output_before_write_samples_state; return cras_iodev_prepare_output_before_write_samples_ret; } -float cras_iodev_get_software_gain_scaler(const struct cras_iodev *iodev) -{ +float cras_iodev_get_software_gain_scaler(const struct cras_iodev* iodev) { return 1.0f; } -unsigned int cras_iodev_frames_to_play_in_sleep(struct cras_iodev *odev, - unsigned int *hw_level, - struct timespec *hw_tstamp) -{ +unsigned int cras_iodev_frames_to_play_in_sleep(struct cras_iodev* odev, + unsigned int* hw_level, + struct timespec* hw_tstamp) { *hw_level = cras_iodev_frames_queued(odev, hw_tstamp); cras_iodev_frames_to_play_in_sleep_called++; return 0; } -int cras_iodev_odev_should_wake(const struct cras_iodev *odev) -{ +int cras_iodev_odev_should_wake(const struct cras_iodev* odev) { return 1; } -struct cras_audio_area *cras_audio_area_create(int num_channels) -{ - struct cras_audio_area *area; +struct cras_audio_area* cras_audio_area_create(int num_channels) { + struct cras_audio_area* area; size_t sz; sz = sizeof(*area) + num_channels * sizeof(struct cras_channel_area); - area = (cras_audio_area *)calloc(1, sz); + area = (cras_audio_area*)calloc(1, sz); area->num_channels = num_channels; area->channels[0].buf = (uint8_t*)calloc(1, BUFFER_SIZE * 2 * num_channels); return area; } -enum CRAS_IODEV_STATE cras_iodev_state(const struct cras_iodev *iodev) -{ +enum CRAS_IODEV_STATE cras_iodev_state(const struct cras_iodev* iodev) { return iodev->state; } -unsigned int cras_iodev_get_num_underruns(const struct cras_iodev *iodev) -{ +unsigned int cras_iodev_get_num_underruns(const struct cras_iodev* iodev) { return 0; } -int cras_iodev_get_valid_frames(struct cras_iodev *iodev, - struct timespec *hw_tstamp) -{ +int cras_iodev_get_valid_frames(struct cras_iodev* iodev, + struct timespec* hw_tstamp) { clock_gettime(CLOCK_MONOTONIC_RAW, hw_tstamp); return cras_iodev_get_valid_frames_ret; } -int cras_iodev_reset_request(struct cras_iodev *iodev) -{ +int cras_iodev_reset_request(struct cras_iodev* iodev) { cras_iodev_reset_request_called++; cras_iodev_reset_request_iodev = iodev; return 0; } -unsigned int cras_iodev_get_num_severe_underruns(const struct cras_iodev *iodev) -{ +unsigned int cras_iodev_get_num_severe_underruns( + const struct cras_iodev* iodev) { return 0; } -void cras_iodev_update_highest_hw_level(struct cras_iodev *iodev, - unsigned int hw_level) -{ -} +void cras_iodev_update_highest_hw_level(struct cras_iodev* iodev, + unsigned int hw_level) {} -int cras_iodev_start_ramp(struct cras_iodev *odev, - enum CRAS_IODEV_RAMP_REQUEST request) -{ +int cras_iodev_start_ramp(struct cras_iodev* odev, + enum CRAS_IODEV_RAMP_REQUEST request) { cras_iodev_start_ramp_odev = odev; cras_iodev_start_ramp_request = request; return 0; } -int input_data_get_for_stream( - struct input_data *data, - struct cras_rstream *stream, - struct buffer_share *offsets, - struct cras_audio_area **area, - unsigned int *offset) -{ +int input_data_get_for_stream(struct input_data* data, + struct cras_rstream* stream, + struct buffer_share* offsets, + struct cras_audio_area** area, + unsigned int* offset) { return 0; } -int input_data_put_for_stream(struct input_data *data, - struct cras_rstream *stream, - struct buffer_share *offsets, - unsigned int frames) -{ +int input_data_put_for_stream(struct input_data* data, + struct cras_rstream* stream, + struct buffer_share* offsets, + unsigned int frames) { return 0; } -int cras_device_monitor_set_device_mute_state(unsigned int dev_idx) -{ +int cras_device_monitor_set_device_mute_state(unsigned int dev_idx) { cras_device_monitor_set_device_mute_state_called++; return 0; } +int cras_iodev_drop_frames_by_time(struct cras_iodev* iodev, + struct timespec ts) { + return 0; +} + // From librt. -int clock_gettime(clockid_t clk_id, struct timespec *tp) { +int clock_gettime(clockid_t clk_id, struct timespec* tp) { *tp = clock_gettime_retspec; return 0; } #ifdef HAVE_WEBRTC_APM -uint64_t cras_apm_list_get_effects(struct cras_apm_list *list) -{ +uint64_t cras_apm_list_get_effects(struct cras_apm_list* list) { return 0; } -void cras_apm_list_set_debug_recording(struct cras_apm *apm, - unsigned int stream_id, int start, const char *file_name_base) -{ -} -void cras_apm_list_set_aec_dump(struct cras_apm_list *list, - void *dev_ptr, - int start, - int fd) -{ -} +void cras_apm_list_set_debug_recording(struct cras_apm* apm, + unsigned int stream_id, + int start, + const char* file_name_base) {} +void cras_apm_list_set_aec_dump(struct cras_apm_list* list, + void* dev_ptr, + int start, + int fd) {} #endif -int cras_audio_thread_busyloop() -{ - cras_audio_thread_busyloop_called ++; +int cras_audio_thread_event_busyloop() { + cras_audio_thread_event_busyloop_called++; + return 0; +} + +int cras_audio_thread_event_drop_samples() { return 0; } } // extern "C" -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/audio_thread_unittest_obsolete.cc b/cras/src/tests/audio_thread_unittest_obsolete.cc index bf3fd684..0baeb38f 100644 --- a/cras/src/tests/audio_thread_unittest_obsolete.cc +++ b/cras/src/tests/audio_thread_unittest_obsolete.cc @@ -6,21 +6,21 @@ extern "C" { #include "audio_thread.c" } +#include <gtest/gtest.h> #include <stdio.h> #include <sys/select.h> -#include <gtest/gtest.h> extern "C" { struct dev_stream_capture_call { - struct dev_stream *dev_stream; - const struct cras_audio_area *area; + struct dev_stream* dev_stream; + const struct cras_audio_area* area; unsigned int dev_index; unsigned int num_called; }; struct cap_sleep_frames_call { - struct dev_stream *dev_stream; + struct dev_stream* dev_stream; unsigned int written; unsigned int num_called; }; @@ -31,19 +31,19 @@ static unsigned int cras_mix_mute_count; static unsigned int dev_stream_request_playback_samples_called; static unsigned int cras_rstream_destroy_called; static unsigned int cras_metrics_log_histogram_called; -static const char *cras_metrics_log_histogram_name; +static const char* cras_metrics_log_histogram_name; static unsigned int cras_metrics_log_histogram_sample; static unsigned int cras_metrics_log_event_called; -static void (*cras_system_add_select_fd_callback)(void *data); -static void *cras_system_add_select_fd_callback_data; +static void (*cras_system_add_select_fd_callback)(void* data); +static void* cras_system_add_select_fd_callback_data; static int select_return_value; static struct timeval select_timeval; static int select_max_fd; static fd_set select_in_fds; static fd_set select_out_fds; -static uint32_t *select_write_ptr; +static uint32_t* select_write_ptr; static uint32_t select_write_value; static unsigned int cras_iodev_set_format_called; static unsigned int dev_stream_set_delay_called; @@ -52,8 +52,8 @@ static unsigned int dev_stream_mix_called; static struct timespec time_now; static int cras_fmt_conversion_needed_return_val; -static struct cras_audio_area *dummy_audio_area1; -static struct cras_audio_area *dummy_audio_area2; +static struct cras_audio_area* dummy_audio_area1; +static struct cras_audio_area* dummy_audio_area2; static struct cras_audio_format cras_iodev_set_format_val; static struct dev_stream_capture_call dev_stream_capture_call; @@ -66,146 +66,135 @@ static const int CAP_EXTRA_SLEEP_FRAMES = 16; // Test the audio capture path. class ReadStreamSuite : public testing::Test { - protected: - virtual void SetUp() { - memset(&cras_iodev_set_format_val, 0, sizeof(cras_iodev_set_format_val)); - cras_iodev_set_format_val.frame_rate = 44100; - cras_iodev_set_format_val.num_channels = 2; - cras_iodev_set_format_val.format = SND_PCM_FORMAT_S16_LE; - - memset(&iodev_, 0, sizeof(iodev_)); - iodev_.buffer_size = 16384; - cb_threshold_ = 480; - iodev_.direction = CRAS_STREAM_INPUT; - - iodev_.frames_queued = frames_queued; - iodev_.delay_frames = delay_frames; - iodev_.get_buffer = get_buffer; - iodev_.put_buffer = put_buffer; - iodev_.is_open = is_open; - iodev_.open_dev = open_dev; - iodev_.close_dev = close_dev; - iodev_.dev_running = dev_running; - - memcpy(&output_dev_, &iodev_, sizeof(output_dev_)); - output_dev_.direction = CRAS_STREAM_OUTPUT; - - SetupRstream(&rstream_, 1); - shm_ = cras_rstream_input_shm(rstream_); - SetupRstream(&rstream2_, 2); - shm2_ = cras_rstream_input_shm(rstream2_); - - dummy_audio_area1 = (cras_audio_area*)calloc(1, - sizeof(cras_audio_area) + 2 * sizeof(cras_channel_area)); - dummy_audio_area1->num_channels = 2; - channel_area_set_channel(&dummy_audio_area1->channels[0], CRAS_CH_FL); - channel_area_set_channel(&dummy_audio_area1->channels[1], CRAS_CH_FR); - rstream_->input_audio_area = dummy_audio_area1; - dummy_audio_area2 = (cras_audio_area*)calloc(1, - sizeof(cras_audio_area) + 2 * sizeof(cras_channel_area)); - dummy_audio_area2->num_channels = 2; - channel_area_set_channel(&dummy_audio_area2->channels[0], CRAS_CH_FL); - channel_area_set_channel(&dummy_audio_area2->channels[1], CRAS_CH_FR); - rstream2_->input_audio_area = dummy_audio_area2; - - dev_stream_mix_dont_fill_next = 0; - dev_stream_mix_count = 0; - dev_running_called_ = 0; - is_open_ = 0; - close_dev_called_ = 0; - - cras_iodev_set_format_called = 0; - dev_stream_set_delay_called = 0; - } + protected: + virtual void SetUp() { + memset(&cras_iodev_set_format_val, 0, sizeof(cras_iodev_set_format_val)); + cras_iodev_set_format_val.frame_rate = 44100; + cras_iodev_set_format_val.num_channels = 2; + cras_iodev_set_format_val.format = SND_PCM_FORMAT_S16_LE; + + memset(&iodev_, 0, sizeof(iodev_)); + iodev_.buffer_size = 16384; + cb_threshold_ = 480; + iodev_.direction = CRAS_STREAM_INPUT; + + iodev_.frames_queued = frames_queued; + iodev_.delay_frames = delay_frames; + iodev_.get_buffer = get_buffer; + iodev_.put_buffer = put_buffer; + iodev_.is_open = is_open; + iodev_.open_dev = open_dev; + iodev_.close_dev = close_dev; + iodev_.dev_running = dev_running; + + memcpy(&output_dev_, &iodev_, sizeof(output_dev_)); + output_dev_.direction = CRAS_STREAM_OUTPUT; + + SetupRstream(&rstream_, 1); + shm_ = cras_rstream_input_shm(rstream_); + SetupRstream(&rstream2_, 2); + shm2_ = cras_rstream_input_shm(rstream2_); + + dummy_audio_area1 = (cras_audio_area*)calloc( + 1, sizeof(cras_audio_area) + 2 * sizeof(cras_channel_area)); + dummy_audio_area1->num_channels = 2; + channel_area_set_channel(&dummy_audio_area1->channels[0], CRAS_CH_FL); + channel_area_set_channel(&dummy_audio_area1->channels[1], CRAS_CH_FR); + rstream_->input_audio_area = dummy_audio_area1; + dummy_audio_area2 = (cras_audio_area*)calloc( + 1, sizeof(cras_audio_area) + 2 * sizeof(cras_channel_area)); + dummy_audio_area2->num_channels = 2; + channel_area_set_channel(&dummy_audio_area2->channels[0], CRAS_CH_FL); + channel_area_set_channel(&dummy_audio_area2->channels[1], CRAS_CH_FR); + rstream2_->input_audio_area = dummy_audio_area2; - virtual void TearDown() { - free(shm_->area); - free(rstream_); - free(shm2_->area); - free(rstream2_); - free(dummy_audio_area1); - free(dummy_audio_area2); - } + dev_stream_mix_dont_fill_next = 0; + dev_stream_mix_count = 0; + dev_running_called_ = 0; + is_open_ = 0; + close_dev_called_ = 0; - void SetupRstream(struct cras_rstream **rstream, int fd) { - struct cras_audio_shm *shm; - - *rstream = (struct cras_rstream *)calloc(1, sizeof(**rstream)); - memcpy(&(*rstream)->format, &cras_iodev_set_format_val, - sizeof(cras_iodev_set_format_val)); - (*rstream)->direction = CRAS_STREAM_INPUT; - (*rstream)->cb_threshold = cb_threshold_; - (*rstream)->client = (struct cras_rclient *)this; - - shm = cras_rstream_input_shm(*rstream); - shm->header = (struct cras_audio_shm_header*)calloc( - 1, sizeof(*shm->header) + cb_threshold_ * 8); - cras_shm_set_frame_bytes(shm, 4); - cras_shm_set_used_size( - shm, cb_threshold_ * cras_shm_frame_bytes(shm)); - } + cras_iodev_set_format_called = 0; + dev_stream_set_delay_called = 0; + } - unsigned int GetCaptureSleepFrames() { - // Account for padding the sleep interval to ensure the wake up happens - // after the last desired frame is received. - return cb_threshold_ + 16; - } + virtual void TearDown() { + free(shm_->area); + free(rstream_); + free(shm2_->area); + free(rstream2_); + free(dummy_audio_area1); + free(dummy_audio_area2); + } - // Stub functions for the iodev structure. - static int frames_queued(const cras_iodev* iodev) { - return frames_queued_; - } + void SetupRstream(struct cras_rstream** rstream, int fd) { + struct cras_audio_shm* shm; + + *rstream = (struct cras_rstream*)calloc(1, sizeof(**rstream)); + memcpy(&(*rstream)->format, &cras_iodev_set_format_val, + sizeof(cras_iodev_set_format_val)); + (*rstream)->direction = CRAS_STREAM_INPUT; + (*rstream)->cb_threshold = cb_threshold_; + (*rstream)->client = (struct cras_rclient*)this; + + shm = cras_rstream_input_shm(*rstream); + shm->header = (struct cras_audio_shm_header*)calloc( + 1, sizeof(*shm->header) + cb_threshold_ * 8); + cras_shm_set_frame_bytes(shm, 4); + cras_shm_set_used_size(shm, cb_threshold_ * cras_shm_frame_bytes(shm)); + } - static int delay_frames(const cras_iodev* iodev) { - return delay_frames_; - } + unsigned int GetCaptureSleepFrames() { + // Account for padding the sleep interval to ensure the wake up happens + // after the last desired frame is received. + return cb_threshold_ + 16; + } - static int get_buffer(cras_iodev* iodev, - struct cras_audio_area** area, - unsigned int* num) { - size_t sz = sizeof(*area_) + sizeof(struct cras_channel_area) * 2; - - if (audio_buffer_size_ < *num) - *num = audio_buffer_size_; - - area_ = (cras_audio_area*)calloc(1, sz); - area_->frames = *num; - area_->num_channels = 2; - area_->channels[0].buf = audio_buffer_; - channel_area_set_channel(&area_->channels[0], CRAS_CH_FL); - area_->channels[0].step_bytes = 4; - area_->channels[1].buf = audio_buffer_ + 2; - channel_area_set_channel(&area_->channels[1], CRAS_CH_FR); - area_->channels[1].step_bytes = 4; - - *area = area_; - return 0; - } + // Stub functions for the iodev structure. + static int frames_queued(const cras_iodev* iodev) { return frames_queued_; } - static int put_buffer(cras_iodev* iodev, - unsigned int num) { - free(area_); - return 0; - } + static int delay_frames(const cras_iodev* iodev) { return delay_frames_; } - static int is_open(const cras_iodev* iodev) { - return is_open_; - } + static int get_buffer(cras_iodev* iodev, + struct cras_audio_area** area, + unsigned int* num) { + size_t sz = sizeof(*area_) + sizeof(struct cras_channel_area) * 2; - static int open_dev(cras_iodev* iodev) { - return 0; - } + if (audio_buffer_size_ < *num) + *num = audio_buffer_size_; - static int close_dev(cras_iodev* iodev) { - close_dev_called_++; - return 0; - } + area_ = (cras_audio_area*)calloc(1, sz); + area_->frames = *num; + area_->num_channels = 2; + area_->channels[0].buf = audio_buffer_; + channel_area_set_channel(&area_->channels[0], CRAS_CH_FL); + area_->channels[0].step_bytes = 4; + area_->channels[1].buf = audio_buffer_ + 2; + channel_area_set_channel(&area_->channels[1], CRAS_CH_FR); + area_->channels[1].step_bytes = 4; - static int dev_running(const cras_iodev* iodev) { - dev_running_called_++; - return 1; - } + *area = area_; + return 0; + } + + static int put_buffer(cras_iodev* iodev, unsigned int num) { + free(area_); + return 0; + } + static int is_open(const cras_iodev* iodev) { return is_open_; } + + static int open_dev(cras_iodev* iodev) { return 0; } + + static int close_dev(cras_iodev* iodev) { + close_dev_called_++; + return 0; + } + + static int dev_running(const cras_iodev* iodev) { + dev_running_called_++; + return 1; + } struct cras_iodev iodev_; struct cras_iodev output_dev_; @@ -214,14 +203,14 @@ class ReadStreamSuite : public testing::Test { static int delay_frames_; static unsigned int cb_threshold_; static uint8_t audio_buffer_[8192]; - static struct cras_audio_area *area_; + static struct cras_audio_area* area_; static unsigned int audio_buffer_size_; static unsigned int dev_running_called_; static unsigned int close_dev_called_; - struct cras_rstream *rstream_; - struct cras_rstream *rstream2_; - struct cras_audio_shm *shm_; - struct cras_audio_shm *shm2_; + struct cras_rstream* rstream_; + struct cras_rstream* rstream2_; + struct cras_audio_shm* shm_; + struct cras_audio_shm* shm2_; }; int ReadStreamSuite::is_open_ = 0; @@ -232,12 +221,12 @@ uint8_t ReadStreamSuite::audio_buffer_[8192]; unsigned int ReadStreamSuite::audio_buffer_size_ = 0; unsigned int ReadStreamSuite::dev_running_called_ = 0; unsigned int ReadStreamSuite::cb_threshold_ = 0; -struct cras_audio_area *ReadStreamSuite::area_; +struct cras_audio_area* ReadStreamSuite::area_; TEST_F(ReadStreamSuite, PossiblyReadGetAvailError) { struct timespec ts; int rc; - struct audio_thread *thread; + struct audio_thread* thread; thread = audio_thread_create(); ASSERT_TRUE(thread); @@ -262,7 +251,7 @@ TEST_F(ReadStreamSuite, PossiblyReadEmpty) { struct timespec ts; int rc; uint64_t nsec_expected; - struct audio_thread *thread; + struct audio_thread* thread; thread = audio_thread_create(); ASSERT_TRUE(thread); @@ -293,7 +282,7 @@ TEST_F(ReadStreamSuite, PossiblyReadTooLittleData) { int rc; uint64_t nsec_expected; static const uint64_t num_frames_short = 40; - struct audio_thread *thread; + struct audio_thread* thread; thread = audio_thread_create(); ASSERT_TRUE(thread); @@ -325,7 +314,7 @@ TEST_F(ReadStreamSuite, PossiblyReadHasDataWriteStream) { struct timespec ts; int rc; uint64_t nsec_expected; - struct audio_thread *thread; + struct audio_thread* thread; thread = audio_thread_create(); ASSERT_TRUE(thread); @@ -338,7 +327,7 @@ TEST_F(ReadStreamSuite, PossiblyReadHasDataWriteStream) { audio_buffer_size_ = frames_queued_; for (unsigned int i = 0; i < sizeof(audio_buffer_); i++) - audio_buffer_[i] = i; + audio_buffer_[i] = i; uint64_t sleep_frames = GetCaptureSleepFrames() - 4; nsec_expected = (uint64_t)sleep_frames * 1000000000ULL / @@ -363,7 +352,7 @@ TEST_F(ReadStreamSuite, PossiblyReadHasDataWriteTwoStreams) { struct timespec ts; int rc; uint64_t nsec_expected; - struct audio_thread *thread; + struct audio_thread* thread; dev_stream_capture_call.num_called = 0; cap_sleep_frames_call.num_called = 0; @@ -382,7 +371,7 @@ TEST_F(ReadStreamSuite, PossiblyReadHasDataWriteTwoStreams) { audio_buffer_size_ = frames_queued_; for (unsigned int i = 0; i < sizeof(audio_buffer_); i++) - audio_buffer_[i] = i; + audio_buffer_[i] = i; uint64_t sleep_frames = GetCaptureSleepFrames() - 4; nsec_expected = (uint64_t)sleep_frames * 1000000000ULL / @@ -404,7 +393,7 @@ TEST_F(ReadStreamSuite, PossiblyReadHasDataWriteTwoDifferentStreams) { struct timespec ts; int rc; uint64_t nsec_expected; - struct audio_thread *thread; + struct audio_thread* thread; thread = audio_thread_create(); ASSERT_TRUE(thread); @@ -452,7 +441,7 @@ TEST_F(ReadStreamSuite, PossiblyReadHasDataWriteTwoDifferentStreams) { TEST_F(ReadStreamSuite, PossiblyReadWriteThreeBuffers) { struct timespec ts; int rc; - struct audio_thread *thread; + struct audio_thread* thread; thread = audio_thread_create(); ASSERT_TRUE(thread); @@ -496,147 +485,141 @@ TEST_F(ReadStreamSuite, PossiblyReadWriteThreeBuffers) { // Test the audio playback path. class WriteStreamSuite : public testing::Test { - protected: - virtual void SetUp() { - memset(&fmt_, 0, sizeof(fmt_)); - fmt_.frame_rate = 44100; - fmt_.num_channels = 2; - fmt_.format = SND_PCM_FORMAT_S16_LE; - - memset(&iodev_, 0, sizeof(iodev_)); - iodev_.format = &fmt_; - iodev_.buffer_size = 16384; - iodev_.direction = CRAS_STREAM_OUTPUT; - - iodev_.frames_queued = frames_queued; - iodev_.delay_frames = delay_frames; - iodev_.get_buffer = get_buffer; - iodev_.put_buffer = put_buffer; - iodev_.dev_running = dev_running; - iodev_.is_open = is_open; - iodev_.open_dev = open_dev; - iodev_.close_dev = close_dev; - iodev_.buffer_size = 480; - - buffer_frames_ = iodev_.buffer_size; - cb_threshold_ = 96; - SetupRstream(&rstream_, 1); - shm_ = cras_rstream_output_shm(rstream_); - SetupRstream(&rstream2_, 2); - shm2_ = cras_rstream_output_shm(rstream2_); - - thread_ = audio_thread_create(); - ASSERT_TRUE(thread_); - thread_set_active_dev(thread_, &iodev_); - - dev_stream_mix_dont_fill_next = 0; - dev_stream_mix_count = 0; - select_max_fd = -1; - select_write_ptr = NULL; - cras_metrics_log_event_called = 0; - dev_stream_request_playback_samples_called = 0; - cras_rstream_destroy_called = 0; - dev_stream_mix_called = 0; - is_open_ = 0; - close_dev_called_ = 0; - - dev_running_called_ = 0; - - audio_buffer_size_ = 8196; - thread_add_stream(thread_, rstream_); - frames_written_ = 0; - } + protected: + virtual void SetUp() { + memset(&fmt_, 0, sizeof(fmt_)); + fmt_.frame_rate = 44100; + fmt_.num_channels = 2; + fmt_.format = SND_PCM_FORMAT_S16_LE; + + memset(&iodev_, 0, sizeof(iodev_)); + iodev_.format = &fmt_; + iodev_.buffer_size = 16384; + iodev_.direction = CRAS_STREAM_OUTPUT; + + iodev_.frames_queued = frames_queued; + iodev_.delay_frames = delay_frames; + iodev_.get_buffer = get_buffer; + iodev_.put_buffer = put_buffer; + iodev_.dev_running = dev_running; + iodev_.is_open = is_open; + iodev_.open_dev = open_dev; + iodev_.close_dev = close_dev; + iodev_.buffer_size = 480; + + buffer_frames_ = iodev_.buffer_size; + cb_threshold_ = 96; + SetupRstream(&rstream_, 1); + shm_ = cras_rstream_output_shm(rstream_); + SetupRstream(&rstream2_, 2); + shm2_ = cras_rstream_output_shm(rstream2_); + + thread_ = audio_thread_create(); + ASSERT_TRUE(thread_); + thread_set_active_dev(thread_, &iodev_); - virtual void TearDown() { - free(shm_->area); - free(rstream_); - free(shm2_->area); - free(rstream2_); - audio_thread_destroy(thread_); - } + dev_stream_mix_dont_fill_next = 0; + dev_stream_mix_count = 0; + select_max_fd = -1; + select_write_ptr = NULL; + cras_metrics_log_event_called = 0; + dev_stream_request_playback_samples_called = 0; + cras_rstream_destroy_called = 0; + dev_stream_mix_called = 0; + is_open_ = 0; + close_dev_called_ = 0; + + dev_running_called_ = 0; + + audio_buffer_size_ = 8196; + thread_add_stream(thread_, rstream_); + frames_written_ = 0; + } - void SetupRstream(struct cras_rstream **rstream, int fd) { - struct cras_audio_shm *shm; - - *rstream = (struct cras_rstream *)calloc(1, sizeof(**rstream)); - memcpy(&(*rstream)->format, &fmt_, sizeof(fmt_)); - (*rstream)->fd = fd; - (*rstream)->buffer_frames = buffer_frames_; - (*rstream)->cb_threshold = cb_threshold_; - (*rstream)->client = (struct cras_rclient *)this; - - shm = cras_rstream_output_shm(*rstream); - shm->header = (struct cras_audio_shm_header*)calloc( - 1, sizeof(*shm->header) + cb_threshold_ * 8); - cras_shm_set_frame_bytes(shm, 4); - cras_shm_set_used_size( - shm, buffer_frames_ * cras_shm_frame_bytes(shm)); - } + virtual void TearDown() { + free(shm_->area); + free(rstream_); + free(shm2_->area); + free(rstream2_); + audio_thread_destroy(thread_); + } - uint64_t GetCaptureSleepFrames() { - // Account for padding the sleep interval to ensure the wake up happens - // after the last desired frame is received. - return cb_threshold_ + CAP_EXTRA_SLEEP_FRAMES; - } + void SetupRstream(struct cras_rstream** rstream, int fd) { + struct cras_audio_shm* shm; + + *rstream = (struct cras_rstream*)calloc(1, sizeof(**rstream)); + memcpy(&(*rstream)->format, &fmt_, sizeof(fmt_)); + (*rstream)->fd = fd; + (*rstream)->buffer_frames = buffer_frames_; + (*rstream)->cb_threshold = cb_threshold_; + (*rstream)->client = (struct cras_rclient*)this; + + shm = cras_rstream_output_shm(*rstream); + shm->header = (struct cras_audio_shm_header*)calloc( + 1, sizeof(*shm->header) + cb_threshold_ * 8); + cras_shm_set_frame_bytes(shm, 4); + cras_shm_set_used_size(shm, buffer_frames_ * cras_shm_frame_bytes(shm)); + } - // Stub functions for the iodev structure. - static int frames_queued(const cras_iodev* iodev) { - return frames_queued_ + frames_written_; - } + uint64_t GetCaptureSleepFrames() { + // Account for padding the sleep interval to ensure the wake up happens + // after the last desired frame is received. + return cb_threshold_ + CAP_EXTRA_SLEEP_FRAMES; + } - static int delay_frames(const cras_iodev* iodev) { - return delay_frames_; - } + // Stub functions for the iodev structure. + static int frames_queued(const cras_iodev* iodev) { + return frames_queued_ + frames_written_; + } - static int get_buffer(cras_iodev* iodev, - struct cras_audio_area** area, - unsigned int* num) { - size_t sz = sizeof(*area_) + sizeof(struct cras_channel_area) * 2; - - if (audio_buffer_size_ < *num) - *num = audio_buffer_size_; - - area_ = (cras_audio_area*)calloc(1, sz); - area_->frames = *num; - area_->num_channels = 2; - area_->channels[0].buf = audio_buffer_; - channel_area_set_channel(&area_->channels[0], CRAS_CH_FL); - area_->channels[0].step_bytes = 4; - area_->channels[1].buf = audio_buffer_ + 2; - channel_area_set_channel(&area_->channels[1], CRAS_CH_FR); - area_->channels[1].step_bytes = 4; - - *area = area_; - return 0; - } + static int delay_frames(const cras_iodev* iodev) { return delay_frames_; } - static int put_buffer(cras_iodev* iodev, - unsigned int num) { - free(area_); - frames_written_ += num; - return 0; - } + static int get_buffer(cras_iodev* iodev, + struct cras_audio_area** area, + unsigned int* num) { + size_t sz = sizeof(*area_) + sizeof(struct cras_channel_area) * 2; - static int dev_running(const cras_iodev* iodev) { - dev_running_called_++; - return dev_running_; - } + if (audio_buffer_size_ < *num) + *num = audio_buffer_size_; - static int is_open(const cras_iodev* iodev) { - return is_open_; - } + area_ = (cras_audio_area*)calloc(1, sz); + area_->frames = *num; + area_->num_channels = 2; + area_->channels[0].buf = audio_buffer_; + channel_area_set_channel(&area_->channels[0], CRAS_CH_FL); + area_->channels[0].step_bytes = 4; + area_->channels[1].buf = audio_buffer_ + 2; + channel_area_set_channel(&area_->channels[1], CRAS_CH_FR); + area_->channels[1].step_bytes = 4; - static int open_dev(cras_iodev* iodev) { - is_open_ = 1; - open_dev_called_++; - return 0; - } + *area = area_; + return 0; + } - static int close_dev(cras_iodev* iodev) { - close_dev_called_++; - is_open_ = 0; - return 0; - } + static int put_buffer(cras_iodev* iodev, unsigned int num) { + free(area_); + frames_written_ += num; + return 0; + } + + static int dev_running(const cras_iodev* iodev) { + dev_running_called_++; + return dev_running_; + } + + static int is_open(const cras_iodev* iodev) { return is_open_; } + + static int open_dev(cras_iodev* iodev) { + is_open_ = 1; + open_dev_called_++; + return 0; + } + + static int close_dev(cras_iodev* iodev) { + close_dev_called_++; + is_open_ = 0; + return 0; + } struct cras_iodev iodev_; static int is_open_; @@ -651,13 +634,13 @@ class WriteStreamSuite : public testing::Test { static unsigned int dev_running_called_; static unsigned int close_dev_called_; static unsigned int open_dev_called_; - static struct cras_audio_area *area_; + static struct cras_audio_area* area_; struct cras_audio_format fmt_; struct cras_rstream* rstream_; struct cras_rstream* rstream2_; struct cras_audio_shm* shm_; struct cras_audio_shm* shm2_; - struct audio_thread *thread_; + struct audio_thread* thread_; }; int WriteStreamSuite::is_open_ = 0; @@ -672,7 +655,7 @@ int WriteStreamSuite::dev_running_ = 1; unsigned int WriteStreamSuite::dev_running_called_ = 0; unsigned int WriteStreamSuite::close_dev_called_ = 0; unsigned int WriteStreamSuite::open_dev_called_ = 0; -struct cras_audio_area *WriteStreamSuite::area_; +struct cras_audio_area* WriteStreamSuite::area_; TEST_F(WriteStreamSuite, PossiblyFillGetAvailError) { struct timespec ts; @@ -711,8 +694,8 @@ TEST_F(WriteStreamSuite, PossiblyFillGetFromStreamFull) { // Have cb_threshold samples left. frames_queued_ = cb_threshold_; audio_buffer_size_ = buffer_frames_ - frames_queued_; - nsec_expected = (uint64_t)cb_threshold_ * - 1000000000ULL / (uint64_t)fmt_.frame_rate; + nsec_expected = + (uint64_t)cb_threshold_ * 1000000000ULL / (uint64_t)fmt_.frame_rate; // shm has plenty of data in it. shm_->area->write_offset[0] = cb_threshold_ * 4; @@ -758,8 +741,8 @@ TEST_F(WriteStreamSuite, PossiblyFillGetFromStreamMinSet) { // cb_thresh x 2 data in the hardware (frames_queued_) = 3 cb_thresh total. // It should sleep until there is a total of cb_threshold + min_buffer_level // left, or 3 - 2 = 1 cb_thresh worth of delay. - nsec_expected = (uint64_t)cb_threshold_ * - 1000000000ULL / (uint64_t)fmt_.frame_rate; + nsec_expected = + (uint64_t)cb_threshold_ * 1000000000ULL / (uint64_t)fmt_.frame_rate; rc = unified_io(thread_, &ts); EXPECT_EQ(0, rc); @@ -835,8 +818,8 @@ TEST_F(WriteStreamSuite, PossiblyFillGetFromStreamNeedFill) { select_write_ptr = &shm_->area->write_offset[0]; select_write_value = (buffer_frames_ - cb_threshold_) * 4; - nsec_expected = (buffer_frames_ - cb_threshold_) * - 1000000000ULL / (uint64_t)fmt_.frame_rate; + nsec_expected = (buffer_frames_ - cb_threshold_) * 1000000000ULL / + (uint64_t)fmt_.frame_rate; is_open_ = 1; rc = unified_io(thread_, &ts); @@ -860,7 +843,7 @@ TEST_F(WriteStreamSuite, PossiblyFillGetFromTwoStreamsFull) { frames_queued_ = cras_rstream_get_cb_threshold(rstream_); audio_buffer_size_ = buffer_frames_ - frames_queued_; nsec_expected = (uint64_t)cras_rstream_get_cb_threshold(rstream_) * - 1000000000ULL / (uint64_t)fmt_.frame_rate; + 1000000000ULL / (uint64_t)fmt_.frame_rate; // shm has plenty of data in it. shm_->area->write_offset[0] = cras_rstream_get_cb_threshold(rstream_) * 4; @@ -875,8 +858,7 @@ TEST_F(WriteStreamSuite, PossiblyFillGetFromTwoStreamsFull) { EXPECT_EQ(0, ts.tv_sec); EXPECT_GE(ts.tv_nsec, nsec_expected - 1000); EXPECT_LE(ts.tv_nsec, nsec_expected + 1000); - EXPECT_EQ(cras_rstream_get_cb_threshold(rstream_), - dev_stream_mix_count); + EXPECT_EQ(cras_rstream_get_cb_threshold(rstream_), dev_stream_mix_count); EXPECT_EQ(0, dev_stream_request_playback_samples_called); EXPECT_EQ(-1, select_max_fd); } @@ -980,8 +962,8 @@ TEST_F(WriteStreamSuite, PossiblyFillGetFromTwoStreamsOneLimited) { // Have cb_threshold samples left. frames_queued_ = cb_threshold_; audio_buffer_size_ = buffer_frames_ - frames_queued_; - nsec_expected = (uint64_t)smaller_frames * - (1000000000ULL / (uint64_t)fmt_.frame_rate); + nsec_expected = + (uint64_t)smaller_frames * (1000000000ULL / (uint64_t)fmt_.frame_rate); // One has too little the other is full. shm_->area->write_offset[0] = smaller_frames * 4; @@ -1015,7 +997,6 @@ TEST_F(WriteStreamSuite, DrainOutputBufferCompelete) { EXPECT_EQ(1, close_dev_called_); } - TEST_F(WriteStreamSuite, DrainOutputBufferWaitForPlayback) { // Hardware buffer is full. frames_queued_ = buffer_frames_; @@ -1101,182 +1082,180 @@ TEST_F(WriteStreamSuite, DrainOutputStream) { // Test adding and removing streams. class AddStreamSuite : public testing::Test { - protected: - virtual void SetUp() { - memset(&cras_iodev_set_format_val, 0, sizeof(cras_iodev_set_format_val)); - cras_iodev_set_format_val.frame_rate = 44100; - cras_iodev_set_format_val.num_channels = 2; - cras_iodev_set_format_val.format = SND_PCM_FORMAT_S16_LE; - - memset(&iodev_, 0, sizeof(iodev_)); - iodev_.buffer_size = 16384; - used_size_ = 480; - cb_threshold_ = 96; - iodev_.direction = CRAS_STREAM_OUTPUT; - - iodev_.is_open = is_open; - iodev_.open_dev = open_dev; - iodev_.close_dev = close_dev; - iodev_.get_buffer = get_buffer; - iodev_.put_buffer = put_buffer; - - is_open_ = 0; - is_open_called_ = 0; - open_dev_called_ = 0; - close_dev_called_ = 0; - open_dev_return_val_ = 0; - - cras_iodev_set_format_called = 0; - cras_rstream_destroy_called = 0; - cras_metrics_log_histogram_called = 0; - cras_metrics_log_histogram_name = NULL; - cras_metrics_log_histogram_sample = 0; - - audio_buffer_size_ = 8196; - } + protected: + virtual void SetUp() { + memset(&cras_iodev_set_format_val, 0, sizeof(cras_iodev_set_format_val)); + cras_iodev_set_format_val.frame_rate = 44100; + cras_iodev_set_format_val.num_channels = 2; + cras_iodev_set_format_val.format = SND_PCM_FORMAT_S16_LE; + + memset(&iodev_, 0, sizeof(iodev_)); + iodev_.buffer_size = 16384; + used_size_ = 480; + cb_threshold_ = 96; + iodev_.direction = CRAS_STREAM_OUTPUT; + + iodev_.is_open = is_open; + iodev_.open_dev = open_dev; + iodev_.close_dev = close_dev; + iodev_.get_buffer = get_buffer; + iodev_.put_buffer = put_buffer; + + is_open_ = 0; + is_open_called_ = 0; + open_dev_called_ = 0; + close_dev_called_ = 0; + open_dev_return_val_ = 0; + + cras_iodev_set_format_called = 0; + cras_rstream_destroy_called = 0; + cras_metrics_log_histogram_called = 0; + cras_metrics_log_histogram_name = NULL; + cras_metrics_log_histogram_sample = 0; + + audio_buffer_size_ = 8196; + } - virtual void TearDown() { - } + virtual void TearDown() {} - unsigned int GetCaptureSleepFrames() { - // Account for padding the sleep interval to ensure the wake up happens - // after the last desired frame is received. - return cb_threshold_ + 16; - } + unsigned int GetCaptureSleepFrames() { + // Account for padding the sleep interval to ensure the wake up happens + // after the last desired frame is received. + return cb_threshold_ + 16; + } - // Stub functions for the iodev structure. - static int get_buffer(cras_iodev* iodev, - struct cras_audio_area** area, - unsigned int* num) { - size_t sz = sizeof(*area_) + sizeof(struct cras_channel_area) * 2; - - if (audio_buffer_size_ < *num) - *num = audio_buffer_size_; - - area_ = (cras_audio_area*)calloc(1, sz); - area_->frames = *num; - area_->num_channels = 2; - area_->channels[0].buf = audio_buffer_; - channel_area_set_channel(&area_->channels[0], CRAS_CH_FL); - area_->channels[0].step_bytes = 4; - area_->channels[1].buf = audio_buffer_ + 2; - channel_area_set_channel(&area_->channels[1], CRAS_CH_FR); - area_->channels[1].step_bytes = 4; - - *area = area_; - return 0; - } + // Stub functions for the iodev structure. + static int get_buffer(cras_iodev* iodev, + struct cras_audio_area** area, + unsigned int* num) { + size_t sz = sizeof(*area_) + sizeof(struct cras_channel_area) * 2; + + if (audio_buffer_size_ < *num) + *num = audio_buffer_size_; + + area_ = (cras_audio_area*)calloc(1, sz); + area_->frames = *num; + area_->num_channels = 2; + area_->channels[0].buf = audio_buffer_; + channel_area_set_channel(&area_->channels[0], CRAS_CH_FL); + area_->channels[0].step_bytes = 4; + area_->channels[1].buf = audio_buffer_ + 2; + channel_area_set_channel(&area_->channels[1], CRAS_CH_FR); + area_->channels[1].step_bytes = 4; + + *area = area_; + return 0; + } - static int put_buffer(cras_iodev* iodev, - unsigned int num) { - free(area_); - return 0; - } + static int put_buffer(cras_iodev* iodev, unsigned int num) { + free(area_); + return 0; + } - static int is_open(const cras_iodev* iodev) { - is_open_called_++; - return is_open_; - } + static int is_open(const cras_iodev* iodev) { + is_open_called_++; + return is_open_; + } - static int open_dev(cras_iodev* iodev) { - open_dev_called_++; - is_open_ = true; - return open_dev_return_val_; - } + static int open_dev(cras_iodev* iodev) { + open_dev_called_++; + is_open_ = true; + return open_dev_return_val_; + } - static int close_dev(cras_iodev* iodev) { - close_dev_called_++; - is_open_ = false; - return 0; - } + static int close_dev(cras_iodev* iodev) { + close_dev_called_++; + is_open_ = false; + return 0; + } - void add_rm_two_streams(CRAS_STREAM_DIRECTION direction) { - int rc; - struct cras_rstream *new_stream, *second_stream; - cras_audio_shm *shm; - struct cras_audio_format *fmt; - struct audio_thread *thread; - - thread = audio_thread_create(); - - fmt = (struct cras_audio_format *)malloc(sizeof(*fmt)); - memcpy(fmt, &cras_iodev_set_format_val, sizeof(*fmt)); - iodev_.direction = direction; - new_stream = (struct cras_rstream *)calloc(1, sizeof(*new_stream)); - new_stream->fd = 55; - new_stream->buffer_frames = 65; - new_stream->cb_threshold = 80; - new_stream->direction = direction; - memcpy(&new_stream->format, fmt, sizeof(*fmt)); - shm = cras_rstream_output_shm(new_stream); - shm->header = - (struct cras_audio_shm_header*)calloc(1, sizeof(*shm->header)); - - if (direction == CRAS_STREAM_INPUT) - thread_set_active_dev(thread, &iodev_); - else - thread_set_active_dev(thread, &iodev_); - - thread_add_stream(thread, new_stream); - EXPECT_EQ(1, thread->devs_open[direction]); - EXPECT_EQ(1, open_dev_called_); - EXPECT_EQ(65, thread->buffer_frames[direction]); - if (direction == CRAS_STREAM_OUTPUT) - EXPECT_EQ(32, thread->cb_threshold[direction]); - else - EXPECT_EQ(80, thread->cb_threshold[direction]); - - is_open_ = 1; - - second_stream = (struct cras_rstream *)calloc(1, sizeof(*second_stream)); - second_stream->fd = 56; - second_stream->buffer_frames = 25; - second_stream->cb_threshold = 12; - second_stream->direction = direction; - memcpy(&second_stream->format, fmt, sizeof(*fmt)); - shm = cras_rstream_output_shm(second_stream); - shm->header = - (struct cras_audio_shm_header*)calloc(1, sizeof(*shm->header)); - - is_open_called_ = 0; - thread_add_stream(thread, second_stream); - EXPECT_EQ(1, thread->devs_open[direction]); - EXPECT_EQ(1, open_dev_called_); - EXPECT_EQ(25, thread->buffer_frames[direction]); - EXPECT_EQ(12, thread->cb_threshold[direction]); - - // Remove the streams. - rc = thread_remove_stream(thread, second_stream); - EXPECT_EQ(1, rc); - EXPECT_EQ(0, close_dev_called_); - if (direction == CRAS_STREAM_OUTPUT) - EXPECT_EQ(32, thread->cb_threshold[direction]); - else - EXPECT_EQ(80, thread->cb_threshold[direction]); - - rc = thread_remove_stream(thread, new_stream); - EXPECT_EQ(0, rc); - - // For output stream, we enter the draining mode; - // for input stream, we close the device directly. - if (direction == CRAS_STREAM_INPUT) { - EXPECT_EQ(0, thread->devs_open[direction]); - EXPECT_EQ(0, thread->buffer_frames[direction]); - EXPECT_EQ(0, thread->cb_threshold[direction]); - } else { - EXPECT_EQ(1, iodev_.is_draining); - } - - free(fmt); - shm = cras_rstream_output_shm(new_stream); - audio_thread_destroy(thread); - free(shm->header); - free(new_stream); - shm = cras_rstream_output_shm(second_stream); - free(shm->header); - free(second_stream); + void add_rm_two_streams(CRAS_STREAM_DIRECTION direction) { + int rc; + struct cras_rstream *new_stream, *second_stream; + cras_audio_shm* shm; + struct cras_audio_format* fmt; + struct audio_thread* thread; + + thread = audio_thread_create(); + + fmt = (struct cras_audio_format*)malloc(sizeof(*fmt)); + memcpy(fmt, &cras_iodev_set_format_val, sizeof(*fmt)); + iodev_.direction = direction; + new_stream = (struct cras_rstream*)calloc(1, sizeof(*new_stream)); + new_stream->fd = 55; + new_stream->buffer_frames = 65; + new_stream->cb_threshold = 80; + new_stream->direction = direction; + memcpy(&new_stream->format, fmt, sizeof(*fmt)); + shm = cras_rstream_output_shm(new_stream); + shm->header = + (struct cras_audio_shm_header*)calloc(1, sizeof(*shm->header)); + + if (direction == CRAS_STREAM_INPUT) + thread_set_active_dev(thread, &iodev_); + else + thread_set_active_dev(thread, &iodev_); + + thread_add_stream(thread, new_stream); + EXPECT_EQ(1, thread->devs_open[direction]); + EXPECT_EQ(1, open_dev_called_); + EXPECT_EQ(65, thread->buffer_frames[direction]); + if (direction == CRAS_STREAM_OUTPUT) + EXPECT_EQ(32, thread->cb_threshold[direction]); + else + EXPECT_EQ(80, thread->cb_threshold[direction]); + + is_open_ = 1; + + second_stream = (struct cras_rstream*)calloc(1, sizeof(*second_stream)); + second_stream->fd = 56; + second_stream->buffer_frames = 25; + second_stream->cb_threshold = 12; + second_stream->direction = direction; + memcpy(&second_stream->format, fmt, sizeof(*fmt)); + shm = cras_rstream_output_shm(second_stream); + shm->header = + (struct cras_audio_shm_header*)calloc(1, sizeof(*shm->header)); + + is_open_called_ = 0; + thread_add_stream(thread, second_stream); + EXPECT_EQ(1, thread->devs_open[direction]); + EXPECT_EQ(1, open_dev_called_); + EXPECT_EQ(25, thread->buffer_frames[direction]); + EXPECT_EQ(12, thread->cb_threshold[direction]); + + // Remove the streams. + rc = thread_remove_stream(thread, second_stream); + EXPECT_EQ(1, rc); + EXPECT_EQ(0, close_dev_called_); + if (direction == CRAS_STREAM_OUTPUT) + EXPECT_EQ(32, thread->cb_threshold[direction]); + else + EXPECT_EQ(80, thread->cb_threshold[direction]); + + rc = thread_remove_stream(thread, new_stream); + EXPECT_EQ(0, rc); + + // For output stream, we enter the draining mode; + // for input stream, we close the device directly. + if (direction == CRAS_STREAM_INPUT) { + EXPECT_EQ(0, thread->devs_open[direction]); + EXPECT_EQ(0, thread->buffer_frames[direction]); + EXPECT_EQ(0, thread->cb_threshold[direction]); + } else { + EXPECT_EQ(1, iodev_.is_draining); } + free(fmt); + shm = cras_rstream_output_shm(new_stream); + audio_thread_destroy(thread); + free(shm->header); + free(new_stream); + shm = cras_rstream_output_shm(second_stream); + free(shm->header); + free(second_stream); + } + struct cras_iodev iodev_; static int is_open_; static int is_open_called_; @@ -1286,7 +1265,7 @@ class AddStreamSuite : public testing::Test { static int used_size_; static int cb_threshold_; struct cras_audio_format fmt_; - static struct cras_audio_area *area_; + static struct cras_audio_area* area_; static uint8_t audio_buffer_[8192]; static unsigned int audio_buffer_size_; }; @@ -1298,20 +1277,20 @@ int AddStreamSuite::open_dev_return_val_ = 0; int AddStreamSuite::close_dev_called_ = 0; int AddStreamSuite::used_size_ = 0; int AddStreamSuite::cb_threshold_ = 0; -struct cras_audio_area *AddStreamSuite::area_; +struct cras_audio_area* AddStreamSuite::area_; uint8_t AddStreamSuite::audio_buffer_[8192]; unsigned int AddStreamSuite::audio_buffer_size_ = 0; TEST_F(AddStreamSuite, SimpleAddOutputStream) { int rc; cras_rstream* new_stream; - cras_audio_shm *shm; - struct audio_thread *thread; + cras_audio_shm* shm; + struct audio_thread* thread; thread = audio_thread_create(); - new_stream = (struct cras_rstream *)calloc(1, sizeof(*new_stream)); - new_stream->client = (struct cras_rclient* )this; + new_stream = (struct cras_rstream*)calloc(1, sizeof(*new_stream)); + new_stream->client = (struct cras_rclient*)this; new_stream->fd = 55; new_stream->buffer_frames = 65; new_stream->cb_threshold = 80; @@ -1347,11 +1326,10 @@ TEST_F(AddStreamSuite, SimpleAddOutputStream) { free(new_stream); } - TEST_F(AddStreamSuite, AddStreamOpenFail) { - struct audio_thread *thread; + struct audio_thread* thread; cras_rstream new_stream; - cras_audio_shm *shm; + cras_audio_shm* shm; thread = audio_thread_create(); ASSERT_TRUE(thread); @@ -1384,12 +1362,12 @@ TEST_F(AddStreamSuite, AddRmTwoInputStreams) { TEST_F(AddStreamSuite, RmStreamLogLongestTimeout) { int rc; cras_rstream* new_stream; - cras_audio_shm *shm; - struct audio_thread *thread; + cras_audio_shm* shm; + struct audio_thread* thread; thread = audio_thread_create(); - new_stream = (struct cras_rstream *)calloc(1, sizeof(*new_stream)); + new_stream = (struct cras_rstream*)calloc(1, sizeof(*new_stream)); new_stream->fd = 55; new_stream->buffer_frames = 65; new_stream->cb_threshold = 80; @@ -1427,170 +1405,163 @@ TEST_F(AddStreamSuite, RmStreamLogLongestTimeout) { } class ActiveDevicesSuite : public testing::Test { - protected: - virtual void SetUp() { - memset(&cras_iodev_set_format_val, 0, sizeof(cras_iodev_set_format_val)); - cras_iodev_set_format_val.frame_rate = 44100; - cras_iodev_set_format_val.num_channels = 2; - cras_iodev_set_format_val.format = SND_PCM_FORMAT_S16_LE; - - memset(&iodev_, 0, sizeof(iodev_)); - memset(&iodev2_, 0, sizeof(iodev2_)); - iodev_.close_dev = close_dev; - iodev_.is_open = is_open; - iodev_.open_dev = open_dev; - iodev_.delay_frames = delay_frames; - iodev_.get_buffer = get_buffer; - iodev_.put_buffer = put_buffer; - iodev_.frames_queued = frames_queued; - iodev_.delay_frames = delay_frames; - iodev_.dev_running = dev_running; - iodev_.buffer_size = 2048; - iodev2_.close_dev = close_dev; - iodev2_.is_open = is_open; - iodev2_.open_dev = open_dev; - iodev2_.delay_frames = delay_frames; - iodev2_.get_buffer = get_buffer; - iodev2_.put_buffer = put_buffer; - iodev2_.frames_queued = frames_queued; - iodev2_.delay_frames = delay_frames; - iodev2_.dev_running = dev_running; - iodev2_.buffer_size = 2048; - thread_ = audio_thread_create(); - ASSERT_TRUE(thread_); - - buffer_frames_ = 500; - cb_threshold_ = 250; - SetupRstream(&rstream_); - SetupRstream(&rstream2_); - rstream2_->buffer_frames -= 50; - rstream2_->cb_threshold -= 50; - - dummy_audio_area1 = (cras_audio_area*)calloc(1, - sizeof(cras_audio_area) + 2 * sizeof(cras_channel_area)); - dummy_audio_area1->num_channels = 2; - channel_area_set_channel(&dummy_audio_area1->channels[0], CRAS_CH_FL); - channel_area_set_channel(&dummy_audio_area1->channels[1], CRAS_CH_FR); - rstream_->input_audio_area = dummy_audio_area1; - dummy_audio_area2 = (cras_audio_area*)calloc(1, - sizeof(cras_audio_area) + 2 * sizeof(cras_channel_area)); - dummy_audio_area2->num_channels = 2; - channel_area_set_channel(&dummy_audio_area2->channels[0], CRAS_CH_FL); - channel_area_set_channel(&dummy_audio_area2->channels[1], CRAS_CH_FR); - rstream2_->input_audio_area = dummy_audio_area2; - - cras_iodev_set_format_called = 0; - close_dev_called_ = 0; - is_open_ = 0; - cras_fmt_conversion_needed_return_val = 0; - open_dev_val_idx_ = 0; - delay_frames_val_idx_ = 0; - frames_queued_val_idx_ = 0; - frames_queued_[0] = 250; - frames_queued_[1] = 250; - get_buffer_val_idx_ = 0; - put_buffer_val_idx_ = 0; - for (int i = 0; i < 8; i++) { - open_dev_val_[i] = 0; - delay_frames_[i] = 0; - audio_buffer_size_[i] = 250; - get_buffer_rc_[i] = 0; - put_buffer_rc_[i] = 0; - } + protected: + virtual void SetUp() { + memset(&cras_iodev_set_format_val, 0, sizeof(cras_iodev_set_format_val)); + cras_iodev_set_format_val.frame_rate = 44100; + cras_iodev_set_format_val.num_channels = 2; + cras_iodev_set_format_val.format = SND_PCM_FORMAT_S16_LE; + + memset(&iodev_, 0, sizeof(iodev_)); + memset(&iodev2_, 0, sizeof(iodev2_)); + iodev_.close_dev = close_dev; + iodev_.is_open = is_open; + iodev_.open_dev = open_dev; + iodev_.delay_frames = delay_frames; + iodev_.get_buffer = get_buffer; + iodev_.put_buffer = put_buffer; + iodev_.frames_queued = frames_queued; + iodev_.delay_frames = delay_frames; + iodev_.dev_running = dev_running; + iodev_.buffer_size = 2048; + iodev2_.close_dev = close_dev; + iodev2_.is_open = is_open; + iodev2_.open_dev = open_dev; + iodev2_.delay_frames = delay_frames; + iodev2_.get_buffer = get_buffer; + iodev2_.put_buffer = put_buffer; + iodev2_.frames_queued = frames_queued; + iodev2_.delay_frames = delay_frames; + iodev2_.dev_running = dev_running; + iodev2_.buffer_size = 2048; + thread_ = audio_thread_create(); + ASSERT_TRUE(thread_); + + buffer_frames_ = 500; + cb_threshold_ = 250; + SetupRstream(&rstream_); + SetupRstream(&rstream2_); + rstream2_->buffer_frames -= 50; + rstream2_->cb_threshold -= 50; + + dummy_audio_area1 = (cras_audio_area*)calloc( + 1, sizeof(cras_audio_area) + 2 * sizeof(cras_channel_area)); + dummy_audio_area1->num_channels = 2; + channel_area_set_channel(&dummy_audio_area1->channels[0], CRAS_CH_FL); + channel_area_set_channel(&dummy_audio_area1->channels[1], CRAS_CH_FR); + rstream_->input_audio_area = dummy_audio_area1; + dummy_audio_area2 = (cras_audio_area*)calloc( + 1, sizeof(cras_audio_area) + 2 * sizeof(cras_channel_area)); + dummy_audio_area2->num_channels = 2; + channel_area_set_channel(&dummy_audio_area2->channels[0], CRAS_CH_FL); + channel_area_set_channel(&dummy_audio_area2->channels[1], CRAS_CH_FR); + rstream2_->input_audio_area = dummy_audio_area2; + + cras_iodev_set_format_called = 0; + close_dev_called_ = 0; + is_open_ = 0; + cras_fmt_conversion_needed_return_val = 0; + open_dev_val_idx_ = 0; + delay_frames_val_idx_ = 0; + frames_queued_val_idx_ = 0; + frames_queued_[0] = 250; + frames_queued_[1] = 250; + get_buffer_val_idx_ = 0; + put_buffer_val_idx_ = 0; + for (int i = 0; i < 8; i++) { + open_dev_val_[i] = 0; + delay_frames_[i] = 0; + audio_buffer_size_[i] = 250; + get_buffer_rc_[i] = 0; + put_buffer_rc_[i] = 0; } + } - virtual void TearDown() { - struct cras_audio_shm *shm; - audio_thread_destroy(thread_); - shm = cras_rstream_output_shm(rstream_); - free(shm->header); - free(rstream_); - free(dummy_audio_area1); - free(dummy_audio_area2); - } + virtual void TearDown() { + struct cras_audio_shm* shm; + audio_thread_destroy(thread_); + shm = cras_rstream_output_shm(rstream_); + free(shm->header); + free(rstream_); + free(dummy_audio_area1); + free(dummy_audio_area2); + } - void SetupRstream(struct cras_rstream **rstream) { - struct cras_audio_shm *shm; - *rstream = (struct cras_rstream *)calloc(1, sizeof(**rstream)); - memcpy(&(*rstream)->format, &cras_iodev_set_format_val, - sizeof(cras_iodev_set_format_val)); - (*rstream)->direction = CRAS_STREAM_OUTPUT; - (*rstream)->buffer_frames = buffer_frames_; - (*rstream)->cb_threshold = cb_threshold_; - shm = cras_rstream_output_shm(*rstream); - shm->header = (struct cras_audio_shm_header*)calloc( - 1, sizeof(*shm->header) + cb_threshold_ * 8); - cras_shm_set_frame_bytes(shm, 4); - cras_shm_set_used_size( - shm, buffer_frames_ * cras_shm_frame_bytes(shm)); - shm = cras_rstream_input_shm(*rstream); - shm->header = (struct cras_audio_shm_header*)calloc( - 1, sizeof(*shm->header) + buffer_frames_ * 8); - cras_shm_set_frame_bytes(shm, 4); - cras_shm_set_used_size( - shm, cb_threshold_* cras_shm_frame_bytes(shm)); - } + void SetupRstream(struct cras_rstream** rstream) { + struct cras_audio_shm* shm; + *rstream = (struct cras_rstream*)calloc(1, sizeof(**rstream)); + memcpy(&(*rstream)->format, &cras_iodev_set_format_val, + sizeof(cras_iodev_set_format_val)); + (*rstream)->direction = CRAS_STREAM_OUTPUT; + (*rstream)->buffer_frames = buffer_frames_; + (*rstream)->cb_threshold = cb_threshold_; + shm = cras_rstream_output_shm(*rstream); + shm->header = (struct cras_audio_shm_header*)calloc( + 1, sizeof(*shm->header) + cb_threshold_ * 8); + cras_shm_set_frame_bytes(shm, 4); + cras_shm_set_used_size(shm, buffer_frames_ * cras_shm_frame_bytes(shm)); + shm = cras_rstream_input_shm(*rstream); + shm->header = (struct cras_audio_shm_header*)calloc( + 1, sizeof(*shm->header) + buffer_frames_ * 8); + cras_shm_set_frame_bytes(shm, 4); + cras_shm_set_used_size(shm, cb_threshold_ * cras_shm_frame_bytes(shm)); + } - static int close_dev(struct cras_iodev *iodev) { - close_dev_called_++; - return 0; - } + static int close_dev(struct cras_iodev* iodev) { + close_dev_called_++; + return 0; + } - static int is_open(const cras_iodev *iodev) { - return is_open_; - } + static int is_open(const cras_iodev* iodev) { return is_open_; } - static int open_dev(struct cras_iodev *iodev) { - open_dev_val_idx_ %= 8; - is_open_ = 1; - return open_dev_val_[open_dev_val_idx_++]; - } + static int open_dev(struct cras_iodev* iodev) { + open_dev_val_idx_ %= 8; + is_open_ = 1; + return open_dev_val_[open_dev_val_idx_++]; + } - static int delay_frames(const cras_iodev* iodev) { - delay_frames_val_idx_ %= 8; - return delay_frames_[delay_frames_val_idx_++]; - } + static int delay_frames(const cras_iodev* iodev) { + delay_frames_val_idx_ %= 8; + return delay_frames_[delay_frames_val_idx_++]; + } - static int dev_running(const cras_iodev* iodev) { - return 1; - } + static int dev_running(const cras_iodev* iodev) { return 1; } - static int frames_queued(const cras_iodev* iodev) { - frames_queued_val_idx_ %= 2; - return frames_queued_[frames_queued_val_idx_++]; - } + static int frames_queued(const cras_iodev* iodev) { + frames_queued_val_idx_ %= 2; + return frames_queued_[frames_queued_val_idx_++]; + } - static int get_buffer(cras_iodev* iodev, - struct cras_audio_area** area, - unsigned int* num) { - size_t sz = sizeof(*area_) + sizeof(struct cras_channel_area) * 2; - - get_buffer_val_idx_ %= 8; - if (audio_buffer_size_[get_buffer_val_idx_] < *num) - *num = audio_buffer_size_[get_buffer_val_idx_]; - - area_ = (cras_audio_area*)calloc(1, sz); - area_->frames = *num; - area_->num_channels = 2; - area_->channels[0].buf = audio_buffer_[get_buffer_val_idx_]; - channel_area_set_channel(&area_->channels[0], CRAS_CH_FL); - area_->channels[0].step_bytes = 4; - area_->channels[1].buf = audio_buffer_[get_buffer_val_idx_] + 2; - channel_area_set_channel(&area_->channels[1], CRAS_CH_FR); - area_->channels[1].step_bytes = 4; - - *area = area_; - - get_buffer_val_idx_++; - return 0; - } + static int get_buffer(cras_iodev* iodev, + struct cras_audio_area** area, + unsigned int* num) { + size_t sz = sizeof(*area_) + sizeof(struct cras_channel_area) * 2; - static int put_buffer(cras_iodev* iodev, - unsigned int num) { - free(area_); - put_buffer_val_idx_ %= 8; - return put_buffer_rc_[put_buffer_val_idx_++]; - } + get_buffer_val_idx_ %= 8; + if (audio_buffer_size_[get_buffer_val_idx_] < *num) + *num = audio_buffer_size_[get_buffer_val_idx_]; + + area_ = (cras_audio_area*)calloc(1, sz); + area_->frames = *num; + area_->num_channels = 2; + area_->channels[0].buf = audio_buffer_[get_buffer_val_idx_]; + channel_area_set_channel(&area_->channels[0], CRAS_CH_FL); + area_->channels[0].step_bytes = 4; + area_->channels[1].buf = audio_buffer_[get_buffer_val_idx_] + 2; + channel_area_set_channel(&area_->channels[1], CRAS_CH_FR); + area_->channels[1].step_bytes = 4; + + *area = area_; + + get_buffer_val_idx_++; + return 0; + } + + static int put_buffer(cras_iodev* iodev, unsigned int num) { + free(area_); + put_buffer_val_idx_ %= 8; + return put_buffer_rc_[put_buffer_val_idx_++]; + } static int is_open_; static int open_dev_val_[8]; @@ -1608,10 +1579,10 @@ class ActiveDevicesSuite : public testing::Test { static int put_buffer_val_idx_; struct cras_iodev iodev_; struct cras_iodev iodev2_; - struct cras_rstream *rstream_; - struct cras_rstream *rstream2_; - struct audio_thread *thread_; - static struct cras_audio_area *area_; + struct cras_rstream* rstream_; + struct cras_rstream* rstream2_; + struct audio_thread* thread_; + static struct cras_audio_area* area_; static int delay_frames_val_idx_; static int delay_frames_[8]; }; @@ -1632,10 +1603,10 @@ int ActiveDevicesSuite::get_buffer_val_idx_ = 0; int ActiveDevicesSuite::put_buffer_val_idx_ = 0; int ActiveDevicesSuite::get_buffer_rc_[8]; int ActiveDevicesSuite::put_buffer_rc_[8]; -struct cras_audio_area *ActiveDevicesSuite::area_; +struct cras_audio_area* ActiveDevicesSuite::area_; TEST_F(ActiveDevicesSuite, SetActiveDevRemoveOld) { - struct active_dev *adevs; + struct active_dev* adevs; struct cras_iodev iodev3_; iodev_.direction = CRAS_STREAM_INPUT; @@ -1644,7 +1615,7 @@ TEST_F(ActiveDevicesSuite, SetActiveDevRemoveOld) { thread_set_active_dev(thread_, &iodev_); adevs = thread_->active_devs[CRAS_STREAM_INPUT]; - EXPECT_NE((void *)NULL, adevs); + EXPECT_NE((void*)NULL, adevs); EXPECT_EQ(adevs->dev, &iodev_); EXPECT_EQ(1, iodev_.is_active); @@ -1661,7 +1632,7 @@ TEST_F(ActiveDevicesSuite, SetActiveDevRemoveOld) { } TEST_F(ActiveDevicesSuite, SetActiveDevAlreadyInList) { - struct active_dev *adevs; + struct active_dev* adevs; iodev_.direction = CRAS_STREAM_INPUT; iodev2_.direction = CRAS_STREAM_INPUT; @@ -1680,30 +1651,30 @@ TEST_F(ActiveDevicesSuite, SetActiveDevAlreadyInList) { } TEST_F(ActiveDevicesSuite, AddRemoveActiveDevice) { - struct active_dev *adevs; + struct active_dev* adevs; iodev_.direction = CRAS_STREAM_INPUT; iodev2_.direction = CRAS_STREAM_INPUT; thread_set_active_dev(thread_, &iodev_); adevs = thread_->active_devs[CRAS_STREAM_INPUT]; - EXPECT_NE((void *)NULL, adevs); + EXPECT_NE((void*)NULL, adevs); EXPECT_EQ(adevs->dev, &iodev_); EXPECT_EQ(1, iodev_.is_active); thread_add_active_dev(thread_, &iodev2_); - EXPECT_NE((void *)NULL, adevs->next); + EXPECT_NE((void*)NULL, adevs->next); EXPECT_EQ(adevs->next->dev, &iodev2_); EXPECT_EQ(1, iodev2_.is_active); thread_rm_active_dev(thread_, &iodev_); adevs = thread_->active_devs[CRAS_STREAM_INPUT]; - EXPECT_EQ((void *)NULL, adevs->next); + EXPECT_EQ((void*)NULL, adevs->next); EXPECT_EQ(adevs->dev, &iodev2_); EXPECT_EQ(0, iodev_.is_active); iodev_.direction = CRAS_STREAM_POST_MIX_PRE_DSP; thread_add_active_dev(thread_, &iodev_); - EXPECT_NE((void *)NULL, thread_->active_devs[CRAS_STREAM_POST_MIX_PRE_DSP]); + EXPECT_NE((void*)NULL, thread_->active_devs[CRAS_STREAM_POST_MIX_PRE_DSP]); EXPECT_EQ(1, iodev_.is_active); } @@ -1713,12 +1684,12 @@ TEST_F(ActiveDevicesSuite, ClearActiveDevices) { thread_set_active_dev(thread_, &iodev_); thread_add_active_dev(thread_, &iodev2_); - EXPECT_NE((void *)NULL, thread_->active_devs[CRAS_STREAM_OUTPUT]); + EXPECT_NE((void*)NULL, thread_->active_devs[CRAS_STREAM_OUTPUT]); EXPECT_EQ(1, iodev_.is_active); EXPECT_EQ(1, iodev2_.is_active); thread_clear_active_devs(thread_, CRAS_STREAM_OUTPUT); - EXPECT_EQ((void *)NULL, thread_->active_devs[CRAS_STREAM_OUTPUT]); + EXPECT_EQ((void*)NULL, thread_->active_devs[CRAS_STREAM_OUTPUT]); EXPECT_EQ(0, iodev_.is_active); EXPECT_EQ(0, iodev2_.is_active); } @@ -1767,7 +1738,7 @@ TEST_F(ActiveDevicesSuite, OpenSecondActiveDeviceFail) { EXPECT_EQ(500, thread_->buffer_frames[CRAS_STREAM_OUTPUT]); EXPECT_EQ(250, thread_->cb_threshold[CRAS_STREAM_OUTPUT]); EXPECT_EQ(0, close_dev_called_); - EXPECT_EQ((void *)NULL, thread_->active_devs[CRAS_STREAM_OUTPUT]->next); + EXPECT_EQ((void*)NULL, thread_->active_devs[CRAS_STREAM_OUTPUT]->next); } TEST_F(ActiveDevicesSuite, OpenSecondActiveDeviceFormatIncompatible) { @@ -1785,7 +1756,7 @@ TEST_F(ActiveDevicesSuite, OpenSecondActiveDeviceFormatIncompatible) { EXPECT_EQ(500, thread_->buffer_frames[CRAS_STREAM_OUTPUT]); EXPECT_EQ(250, thread_->cb_threshold[CRAS_STREAM_OUTPUT]); EXPECT_EQ(1, close_dev_called_); - EXPECT_EQ((void *)NULL, thread_->active_devs[CRAS_STREAM_OUTPUT]->next); + EXPECT_EQ((void*)NULL, thread_->active_devs[CRAS_STREAM_OUTPUT]->next); } TEST_F(ActiveDevicesSuite, CloseActiveDevices) { @@ -1859,7 +1830,7 @@ TEST_F(ActiveDevicesSuite, MixMultipleInputs) { rstream2_->direction = CRAS_STREAM_INPUT; for (unsigned int dev = 0; dev < 8; dev++) { - int16_t *buff = (int16_t*)audio_buffer_[dev]; + int16_t* buff = (int16_t*)audio_buffer_[dev]; for (unsigned int i = 0; i < 250; i++) buff[i] = i; } @@ -1881,66 +1852,64 @@ extern "C" { const char kNoCodecsFoundMetric[] = "Cras.NoCodecsFoundAtBoot"; const char kStreamTimeoutMilliSeconds[] = "Cras.StreamTimeoutMilliSeconds"; -int cras_iodev_get_thread_poll_fd(const struct cras_iodev *iodev) { +int cras_iodev_get_thread_poll_fd(const struct cras_iodev* iodev) { return 0; } -int cras_iodev_read_thread_command(struct cras_iodev *iodev, - uint8_t *buf, - size_t max_len) { +int cras_iodev_read_thread_command(struct cras_iodev* iodev, + uint8_t* buf, + size_t max_len) { return 0; } -int cras_iodev_send_command_response(struct cras_iodev *iodev, int rc) { +int cras_iodev_send_command_response(struct cras_iodev* iodev, int rc) { return 0; } void cras_iodev_fill_time_from_frames(size_t frames, size_t frame_rate, - struct timespec *ts) { - uint64_t to_play_usec; + struct timespec* ts) { + uint64_t to_play_usec; - ts->tv_sec = 0; - /* adjust sleep time to target our callback threshold */ - to_play_usec = (uint64_t)frames * 1000000L / (uint64_t)frame_rate; + ts->tv_sec = 0; + /* adjust sleep time to target our callback threshold */ + to_play_usec = (uint64_t)frames * 1000000L / (uint64_t)frame_rate; - while (to_play_usec > 1000000) { - ts->tv_sec++; - to_play_usec -= 1000000; - } - ts->tv_nsec = to_play_usec * 1000; + while (to_play_usec > 1000000) { + ts->tv_sec++; + to_play_usec -= 1000000; + } + ts->tv_nsec = to_play_usec * 1000; } -void dev_stream_set_delay(const struct dev_stream *dev_stream, +void dev_stream_set_delay(const struct dev_stream* dev_stream, unsigned int delay_frames) { dev_stream_set_delay_called++; } void cras_set_capture_timestamp(size_t frame_rate, - size_t frames, - struct cras_timespec *ts) { -} + size_t frames, + struct cras_timespec* ts) {} -int cras_iodev_set_format(struct cras_iodev *iodev, - struct cras_audio_format *fmt) -{ +int cras_iodev_set_format(struct cras_iodev* iodev, + struct cras_audio_format* fmt) { cras_iodev_set_format_called++; iodev->format = &cras_iodev_set_format_val; return 0; } // From mixer. -unsigned int dev_stream_mix(struct dev_stream *dev_stream, +unsigned int dev_stream_mix(struct dev_stream* dev_stream, size_t num_channels, - uint8_t *dst, - size_t *count, - size_t *index) { - int16_t *src; - int16_t *target = (int16_t *)dst; + uint8_t* dst, + size_t* count, + size_t* index) { + int16_t* src; + int16_t* target = (int16_t*)dst; size_t fr_written, fr_in_buf; size_t num_samples; size_t frames = 0; - struct cras_audio_shm *shm; + struct cras_audio_shm* shm; if (dev_stream->stream->direction == CRAS_STREAM_OUTPUT) { shm = &dev_stream->stream->output_shm; @@ -1965,8 +1934,7 @@ unsigned int dev_stream_mix(struct dev_stream *dev_stream, fr_written = 0; while (fr_written < *count) { - src = cras_shm_get_readable_frames(shm, - fr_written, &frames); + src = cras_shm_get_readable_frames(shm, fr_written, &frames); if (frames > *count - fr_written) frames = *count - fr_written; num_samples = frames * num_channels; @@ -1980,17 +1948,14 @@ unsigned int dev_stream_mix(struct dev_stream *dev_stream, return *count; } -void cras_scale_buffer(int16_t *buffer, unsigned int count, float scaler) { -} +void cras_scale_buffer(int16_t* buffer, unsigned int count, float scaler) {} -size_t cras_mix_mute_buffer(uint8_t *dst, - size_t frame_bytes, - size_t count) { +size_t cras_mix_mute_buffer(uint8_t* dst, size_t frame_bytes, size_t count) { cras_mix_mute_count = count; return count; } -void cras_mix_add_clip(int16_t *dst, const int16_t *src, size_t count) { +void cras_mix_add_clip(int16_t* dst, const int16_t* src, size_t count) { int32_t sum; unsigned int i; @@ -2005,14 +1970,15 @@ void cras_mix_add_clip(int16_t *dst, const int16_t *src, size_t count) { } // From cras_metrics.c -void cras_metrics_log_event(const char *event) -{ +void cras_metrics_log_event(const char* event) { cras_metrics_log_event_called++; } -void cras_metrics_log_histogram(const char *name, int sample, int min, - int max, int nbuckets) -{ +void cras_metrics_log_histogram(const char* name, + int sample, + int min, + int max, + int nbuckets) { cras_metrics_log_histogram_called++; cras_metrics_log_histogram_name = name; cras_metrics_log_histogram_sample = sample; @@ -2028,25 +1994,21 @@ int cras_set_thread_priority(int priority) { } // From rstream. -int cras_rstream_get_audio_request_reply(const struct cras_rstream *stream) { +int cras_rstream_get_audio_request_reply(const struct cras_rstream* stream) { return 0; } -void cras_rstream_log_overrun(const struct cras_rstream *stream) { -} +void cras_rstream_log_overrun(const struct cras_rstream* stream) {} int cras_system_add_select_fd(int fd, - void (*callback)(void *data), - void *callback_data) -{ + void (*callback)(void* data), + void* callback_data) { cras_system_add_select_fd_callback = callback; cras_system_add_select_fd_callback_data = callback_data; return 0; } -void cras_system_rm_select_fd(int fd) -{ -} +void cras_system_rm_select_fd(int fd) {} size_t cras_system_get_volume() { return cras_system_get_volume_return; @@ -2060,65 +2022,63 @@ int cras_system_get_capture_mute() { return 0; } -void cras_rstream_destroy(struct cras_rstream *stream) { +void cras_rstream_destroy(struct cras_rstream* stream) { cras_rstream_destroy_called++; } -void loopback_iodev_set_format(struct cras_iodev *loopback_dev, - const struct cras_audio_format *fmt) { -} +void loopback_iodev_set_format(struct cras_iodev* loopback_dev, + const struct cras_audio_format* fmt) {} -int loopback_iodev_add_audio(struct cras_iodev *loopback_dev, - const uint8_t *audio, +int loopback_iodev_add_audio(struct cras_iodev* loopback_dev, + const uint8_t* audio, unsigned int count) { return 0; } -int loopback_iodev_add_zeros(struct cras_iodev *dev, - unsigned int count) { +int loopback_iodev_add_zeros(struct cras_iodev* dev, unsigned int count) { return 0; } -int cras_fmt_conversion_needed(const struct cras_audio_format *a, - const struct cras_audio_format *b) -{ +int cras_fmt_conversion_needed(const struct cras_audio_format* a, + const struct cras_audio_format* b) { return cras_fmt_conversion_needed_return_val; } -void cras_audio_area_config_buf_pointers(struct cras_audio_area *area, - const struct cras_audio_format *fmt, - uint8_t *base_buffer) { +void cras_audio_area_config_buf_pointers(struct cras_audio_area* area, + const struct cras_audio_format* fmt, + uint8_t* base_buffer) { unsigned int i; const int sample_size = snd_pcm_format_physical_width(fmt->format) / 8; /* TODO(dgreid) - assuming interleaved audio here for now. */ - for (i = 0 ; i < area->num_channels; i++) { + for (i = 0; i < area->num_channels; i++) { area->channels[i].step_bytes = cras_get_format_bytes(fmt); area->channels[i].buf = base_buffer + i * sample_size; } } -void cras_audio_area_copy(const struct cras_audio_area *dst, - unsigned int dst_offset, unsigned int dst_format_bytes, - const struct cras_audio_area *src, unsigned int src_index) -{ +void cras_audio_area_copy(const struct cras_audio_area* dst, + unsigned int dst_offset, + unsigned int dst_format_bytes, + const struct cras_audio_area* src, + unsigned int src_index) { unsigned count, i; int16_t *dchan, *schan; if (src_index == 0) memset(dst->channels[0].buf, 0, src->frames * dst_format_bytes); - dchan = (int16_t *)(dst->channels[0].buf + - dst_offset * dst->channels[0].step_bytes); - schan = (int16_t *)src->channels[0].buf; + dchan = (int16_t*)(dst->channels[0].buf + + dst_offset * dst->channels[0].step_bytes); + schan = (int16_t*)src->channels[0].buf; count = src->frames * src->num_channels; for (i = 0; i < count; i++) { int32_t sum; sum = *dchan + *schan; if (sum > 0x7fff) - sum = 0x7fff; + sum = 0x7fff; else if (sum < -0x8000) - sum = -0x8000; + sum = -0x8000; *dchan = sum; dchan++; schan++; @@ -2127,49 +2087,48 @@ void cras_audio_area_copy(const struct cras_audio_area *dst, // Override select so it can be stubbed. int select(int nfds, - fd_set *readfds, - fd_set *writefds, - fd_set *exceptfds, - struct timeval *timeout) { + fd_set* readfds, + fd_set* writefds, + fd_set* exceptfds, + struct timeval* timeout) { select_max_fd = nfds; select_timeval.tv_sec = timeout->tv_sec; select_timeval.tv_usec = timeout->tv_usec; select_in_fds = *readfds; *readfds = select_out_fds; if (select_write_ptr) - *select_write_ptr = select_write_value; + *select_write_ptr = select_write_value; return select_return_value; } -int clock_gettime(clockid_t clk_id, struct timespec *tp) { +int clock_gettime(clockid_t clk_id, struct timespec* tp) { *tp = time_now; return 0; } -struct dev_stream *dev_stream_create(struct cras_rstream *stream, - const struct cras_audio_format *fmt) { - struct dev_stream *out = static_cast<dev_stream*>(calloc(1, sizeof(*out))); +struct dev_stream* dev_stream_create(struct cras_rstream* stream, + const struct cras_audio_format* fmt) { + struct dev_stream* out = static_cast<dev_stream*>(calloc(1, sizeof(*out))); out->stream = stream; return out; } -void dev_stream_destroy(struct dev_stream *dev_stream) { +void dev_stream_destroy(struct dev_stream* dev_stream) { free(dev_stream); } -void dev_stream_capture(struct dev_stream *dev_stream, - const struct cras_audio_area *area, - unsigned int dev_index) -{ +void dev_stream_capture(struct dev_stream* dev_stream, + const struct cras_audio_area* area, + unsigned int dev_index) { dev_stream_capture_call.dev_stream = dev_stream; dev_stream_capture_call.area = area; dev_stream_capture_call.dev_index = dev_index; dev_stream_capture_call.num_called++; } -int dev_stream_playback_frames(const struct dev_stream *dev_stream) { - struct cras_audio_shm *shm; +int dev_stream_playback_frames(const struct dev_stream* dev_stream) { + struct cras_audio_shm* shm; int frames; shm = cras_rstream_output_shm(dev_stream->stream); @@ -2184,10 +2143,9 @@ int dev_stream_playback_frames(const struct dev_stream *dev_stream) { return cras_fmt_conv_in_frames_to_out(dev_stream->conv, frames); } -unsigned int dev_stream_capture_avail(const struct dev_stream *dev_stream) -{ - struct cras_audio_shm *shm; - struct cras_rstream *rstream = dev_stream->stream; +unsigned int dev_stream_capture_avail(const struct dev_stream* dev_stream) { + struct cras_audio_shm* shm; + struct cras_rstream* rstream = dev_stream->stream; unsigned int cb_threshold = cras_rstream_get_cb_threshold(rstream); unsigned int frames_avail; @@ -2198,7 +2156,7 @@ unsigned int dev_stream_capture_avail(const struct dev_stream *dev_stream) return frames_avail; } -int dev_stream_capture_sleep_frames(struct dev_stream *dev_stream, +int dev_stream_capture_sleep_frames(struct dev_stream* dev_stream, unsigned int written) { cap_sleep_frames_call.dev_stream = dev_stream; cap_sleep_frames_call.written = written; @@ -2206,9 +2164,8 @@ int dev_stream_capture_sleep_frames(struct dev_stream *dev_stream, return 0; } -int dev_stream_request_playback_samples(struct dev_stream *dev_stream) -{ - struct cras_rstream *rstream = dev_stream->stream; +int dev_stream_request_playback_samples(struct dev_stream* dev_stream) { + struct cras_rstream* rstream = dev_stream->stream; dev_stream_request_playback_samples_called++; @@ -2216,21 +2173,19 @@ int dev_stream_request_playback_samples(struct dev_stream *dev_stream) return 0; } -size_t cras_fmt_conv_in_frames_to_out(struct cras_fmt_conv *conv, - size_t in_frames) -{ - return in_frames; +size_t cras_fmt_conv_in_frames_to_out(struct cras_fmt_conv* conv, + size_t in_frames) { + return in_frames; } -size_t cras_fmt_conv_out_frames_to_in(struct cras_fmt_conv *conv, - size_t out_frames) -{ - return out_frames; +size_t cras_fmt_conv_out_frames_to_in(struct cras_fmt_conv* conv, + size_t out_frames) { + return out_frames; } } // extern "C" -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/biquad_unittest.cc b/cras/src/tests/biquad_unittest.cc index f83200f5..30e67ea9 100644 --- a/cras/src/tests/biquad_unittest.cc +++ b/cras/src/tests/biquad_unittest.cc @@ -1,11 +1,12 @@ -// Copyright (c) 2019 The Chromium OS Authors. All rights reserved. +// Copyright 2019 The Chromium OS Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <gtest/gtest.h> +#include "biquad.h" + #include <assert.h> +#include <gtest/gtest.h> #include <math.h> -#include "biquad.h" namespace { @@ -209,7 +210,7 @@ TEST(InvalidQTest, All) { } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/bt_device_unittest.cc b/cras/src/tests/bt_device_unittest.cc index 50498f16..d2e9a13f 100644 --- a/cras/src/tests/bt_device_unittest.cc +++ b/cras/src/tests/bt_device_unittest.cc @@ -5,8 +5,9 @@ #include <gtest/gtest.h> extern "C" { -#include "cras_bt_io.h" +#include "cras_bt_constants.h" #include "cras_bt_device.h" +#include "cras_bt_io.h" #include "cras_bt_log.h" #include "cras_iodev.h" #include "cras_main_message.h" @@ -14,8 +15,8 @@ extern "C" { #define FAKE_OBJ_PATH "/obj/path" } -static struct cras_iodev *cras_bt_io_create_profile_ret; -static struct cras_iodev *cras_bt_io_append_btio_val; +static struct cras_iodev* cras_bt_io_create_profile_ret; +static struct cras_iodev* cras_bt_io_append_btio_val; static struct cras_ionode* cras_bt_io_get_profile_ret; static unsigned int cras_bt_io_create_called; static unsigned int cras_bt_io_append_called; @@ -25,9 +26,28 @@ static enum cras_bt_device_profile cras_bt_io_create_profile_val; static enum cras_bt_device_profile cras_bt_io_append_profile_val; static unsigned int cras_bt_io_try_remove_ret; -static cras_main_message *cras_main_message_send_msg; +static cras_main_message* cras_main_message_send_msg; static cras_message_callback cras_main_message_add_handler_callback; -static void *cras_main_message_add_handler_callback_data; +static void* cras_main_message_add_handler_callback_data; +static int cras_tm_create_timer_called; +static int cras_a2dp_start_called; +static int cras_a2dp_suspend_connected_device_called; +static int cras_hfp_ag_remove_conflict_called; +static int cras_hfp_ag_start_called; +static int cras_hfp_ag_suspend_connected_device_called; +static void (*cras_tm_create_timer_cb)(struct cras_timer* t, void* data); +static void* cras_tm_create_timer_cb_data; +static int dbus_message_new_method_call_called; +static const char* dbus_message_new_method_call_method; +static struct cras_bt_device* cras_a2dp_connected_device_ret; +static struct cras_bt_device* cras_a2dp_suspend_connected_device_dev; + +struct MockDBusMessage { + int type; + void* value; + MockDBusMessage* next; + MockDBusMessage* recurse; +}; void ResetStubData() { cras_bt_io_get_profile_ret = NULL; @@ -37,86 +57,113 @@ void ResetStubData() { cras_bt_io_destroy_called = 0; cras_bt_io_try_remove_ret = 0; cras_main_message_send_msg = NULL; + cras_tm_create_timer_called = 0; + cras_a2dp_start_called = 0; + cras_a2dp_suspend_connected_device_called = 0; + cras_hfp_ag_remove_conflict_called = 0; + cras_hfp_ag_start_called = 0; + cras_hfp_ag_suspend_connected_device_called = 0; + dbus_message_new_method_call_method = NULL; + dbus_message_new_method_call_called = 0; + cras_a2dp_connected_device_ret = NULL; +} + +static void FreeMockDBusMessage(MockDBusMessage* head) { + if (head->next != NULL) + FreeMockDBusMessage(head->next); + if (head->recurse != NULL) + FreeMockDBusMessage(head->recurse); + if (head->type == DBUS_TYPE_STRING) + free((char*)head->value); + delete head; +} + +static struct MockDBusMessage* NewMockDBusConnectedMessage() { + MockDBusMessage* msg = new MockDBusMessage{DBUS_TYPE_ARRAY, NULL}; + MockDBusMessage* dict = + new MockDBusMessage{DBUS_TYPE_STRING, (void*)strdup("Connected")}; + MockDBusMessage* variant = new MockDBusMessage{DBUS_TYPE_BOOLEAN, (void*)1}; + + msg->recurse = dict; + dict->next = new MockDBusMessage{DBUS_TYPE_INVALID, NULL}; + dict->next->recurse = variant; + return msg; } namespace { class BtDeviceTestSuite : public testing::Test { - protected: - virtual void SetUp() { - ResetStubData(); - bt_iodev1.direction = CRAS_STREAM_OUTPUT; - bt_iodev1.update_active_node = update_active_node; - bt_iodev2.direction = CRAS_STREAM_INPUT; - bt_iodev2.update_active_node = update_active_node; - d1_.direction = CRAS_STREAM_OUTPUT; - d1_.update_active_node = update_active_node; - d2_.direction = CRAS_STREAM_OUTPUT; - d2_.update_active_node = update_active_node; - d3_.direction = CRAS_STREAM_INPUT; - d3_.update_active_node = update_active_node; - btlog = cras_bt_event_log_init(); - } - - virtual void TearDown() { - if(cras_main_message_send_msg) - free(cras_main_message_send_msg); - cras_bt_event_log_deinit(btlog); - } - - static void update_active_node(struct cras_iodev *iodev, - unsigned node_idx, - unsigned dev_enabled) { - } - - struct cras_iodev bt_iodev1; - struct cras_iodev bt_iodev2; - struct cras_iodev d3_; - struct cras_iodev d2_; - struct cras_iodev d1_; + protected: + virtual void SetUp() { + ResetStubData(); + bt_iodev1.direction = CRAS_STREAM_OUTPUT; + bt_iodev1.update_active_node = update_active_node; + bt_iodev2.direction = CRAS_STREAM_INPUT; + bt_iodev2.update_active_node = update_active_node; + d1_.direction = CRAS_STREAM_OUTPUT; + d1_.update_active_node = update_active_node; + d2_.direction = CRAS_STREAM_OUTPUT; + d2_.update_active_node = update_active_node; + d3_.direction = CRAS_STREAM_INPUT; + d3_.update_active_node = update_active_node; + btlog = cras_bt_event_log_init(); + } + + virtual void TearDown() { + if (cras_main_message_send_msg) + free(cras_main_message_send_msg); + cras_bt_event_log_deinit(btlog); + } + + static void update_active_node(struct cras_iodev* iodev, + unsigned node_idx, + unsigned dev_enabled) {} + + struct cras_iodev bt_iodev1; + struct cras_iodev bt_iodev2; + struct cras_iodev d3_; + struct cras_iodev d2_; + struct cras_iodev d1_; }; TEST(BtDeviceSuite, CreateBtDevice) { - struct cras_bt_device *device; + struct cras_bt_device* device; device = cras_bt_device_create(NULL, FAKE_OBJ_PATH); - EXPECT_NE((void *)NULL, device); + EXPECT_NE((void*)NULL, device); device = cras_bt_device_get(FAKE_OBJ_PATH); - EXPECT_NE((void *)NULL, device); + EXPECT_NE((void*)NULL, device); cras_bt_device_remove(device); device = cras_bt_device_get(FAKE_OBJ_PATH); - EXPECT_EQ((void *)NULL, device); + EXPECT_EQ((void*)NULL, device); } TEST_F(BtDeviceTestSuite, AppendRmIodev) { - struct cras_bt_device *device; + struct cras_bt_device* device; device = cras_bt_device_create(NULL, FAKE_OBJ_PATH); bt_iodev1.nodes = reinterpret_cast<struct cras_ionode*>(0x123); cras_bt_io_create_profile_ret = &bt_iodev1; - cras_bt_device_append_iodev(device, &d1_, - CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE); + cras_bt_device_append_iodev(device, &d1_, CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE); EXPECT_EQ(1, cras_bt_io_create_called); EXPECT_EQ(0, cras_bt_io_append_called); - EXPECT_EQ(CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE, - cras_bt_io_create_profile_val); - cras_bt_device_set_active_profile(device, - CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE); + EXPECT_EQ(CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE, cras_bt_io_create_profile_val); + cras_bt_device_set_active_profile(device, CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE); cras_bt_device_append_iodev(device, &d2_, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); EXPECT_EQ(1, cras_bt_io_create_called); EXPECT_EQ(1, cras_bt_io_append_called); EXPECT_EQ(CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY, - cras_bt_io_append_profile_val); + cras_bt_io_append_profile_val); EXPECT_EQ(&bt_iodev1, cras_bt_io_append_btio_val); /* Test HFP disconnected and switch to A2DP. */ cras_bt_io_get_profile_ret = bt_iodev1.nodes; cras_bt_io_try_remove_ret = CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE; - cras_bt_device_set_active_profile( - device, CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); + cras_bt_device_set_active_profile(device, + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); cras_bt_device_rm_iodev(device, &d2_); EXPECT_EQ(1, cras_bt_io_remove_called); @@ -130,219 +177,501 @@ TEST_F(BtDeviceTestSuite, AppendRmIodev) { } TEST_F(BtDeviceTestSuite, SwitchProfile) { - struct cras_bt_device *device; + struct cras_bt_device* device; ResetStubData(); device = cras_bt_device_create(NULL, FAKE_OBJ_PATH); cras_bt_io_create_profile_ret = &bt_iodev1; - cras_bt_device_append_iodev(device, &d1_, - CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE); + cras_bt_device_append_iodev(device, &d1_, CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE); cras_bt_io_create_profile_ret = &bt_iodev2; cras_bt_device_append_iodev(device, &d3_, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); cras_bt_device_start_monitor(); cras_bt_device_switch_profile_enable_dev(device, &bt_iodev1); /* Two bt iodevs were all active. */ cras_main_message_add_handler_callback( - cras_main_message_send_msg, - cras_main_message_add_handler_callback_data); + cras_main_message_send_msg, cras_main_message_add_handler_callback_data); /* One bt iodev was active, the other was not. */ cras_bt_device_switch_profile_enable_dev(device, &bt_iodev2); cras_main_message_add_handler_callback( - cras_main_message_send_msg, - cras_main_message_add_handler_callback_data); + cras_main_message_send_msg, cras_main_message_add_handler_callback_data); /* Output bt iodev wasn't active, close the active input iodev. */ cras_bt_device_switch_profile(device, &bt_iodev2); cras_main_message_add_handler_callback( - cras_main_message_send_msg, - cras_main_message_add_handler_callback_data); + cras_main_message_send_msg, cras_main_message_add_handler_callback_data); + cras_bt_device_remove(device); +} + +TEST_F(BtDeviceTestSuite, SetDeviceConnectedA2dpOnly) { + struct cras_bt_device* device; + struct MockDBusMessage *msg_root, *cur; + ResetStubData(); + + device = cras_bt_device_create(NULL, FAKE_OBJ_PATH); + EXPECT_NE((void*)NULL, device); + + cras_bt_device_add_supported_profiles(device, A2DP_SINK_UUID); + + cur = msg_root = NewMockDBusConnectedMessage(); + cras_bt_device_update_properties(device, (DBusMessageIter*)&cur, NULL); + EXPECT_EQ(1, cras_tm_create_timer_called); + EXPECT_NE((void*)NULL, cras_tm_create_timer_cb); + + /* Schedule another timer, if A2DP not yet configured. */ + cras_tm_create_timer_cb(NULL, cras_tm_create_timer_cb_data); + EXPECT_EQ(2, cras_tm_create_timer_called); + EXPECT_EQ(1, dbus_message_new_method_call_called); + EXPECT_STREQ("ConnectProfile", dbus_message_new_method_call_method); + + cras_bt_device_a2dp_configured(device); + cras_tm_create_timer_cb(NULL, cras_tm_create_timer_cb_data); + EXPECT_EQ(2, cras_tm_create_timer_called); + EXPECT_EQ(1, cras_hfp_ag_remove_conflict_called); + EXPECT_EQ(1, cras_a2dp_start_called); + cras_bt_device_remove(device); + FreeMockDBusMessage(msg_root); +} + +TEST_F(BtDeviceTestSuite, SetDeviceConnectedHfpHspOnly) { + struct cras_bt_device* device; + struct MockDBusMessage *msg_root, *cur; + + ResetStubData(); + + device = cras_bt_device_create(NULL, FAKE_OBJ_PATH); + EXPECT_NE((void*)NULL, device); + + cras_bt_device_add_supported_profiles(device, HSP_HS_UUID); + cras_bt_device_add_supported_profiles(device, HFP_HF_UUID); + + cur = msg_root = NewMockDBusConnectedMessage(); + cras_bt_device_update_properties(device, (DBusMessageIter*)&cur, NULL); + EXPECT_EQ(1, cras_tm_create_timer_called); + EXPECT_NE((void*)NULL, cras_tm_create_timer_cb); + + /* Schedule another timer, if HFP AG not yet intialized. */ + cras_tm_create_timer_cb(NULL, cras_tm_create_timer_cb_data); + EXPECT_EQ(2, cras_tm_create_timer_called); + EXPECT_EQ(1, dbus_message_new_method_call_called); + EXPECT_STREQ("ConnectProfile", dbus_message_new_method_call_method); + + cras_bt_device_audio_gateway_initialized(device); + + cras_tm_create_timer_cb(NULL, cras_tm_create_timer_cb_data); + EXPECT_EQ(2, cras_tm_create_timer_called); + EXPECT_EQ(1, cras_hfp_ag_remove_conflict_called); + EXPECT_EQ(1, cras_hfp_ag_start_called); + + cras_bt_device_remove(device); + FreeMockDBusMessage(msg_root); +} + +TEST_F(BtDeviceTestSuite, SetDeviceConnectedA2dpHfpHsp) { + struct cras_bt_device* device; + struct MockDBusMessage *msg_root, *cur; + + ResetStubData(); + + device = cras_bt_device_create(NULL, FAKE_OBJ_PATH); + EXPECT_NE((void*)NULL, device); + + cras_bt_device_add_supported_profiles(device, A2DP_SINK_UUID); + cras_bt_device_add_supported_profiles(device, HSP_HS_UUID); + cras_bt_device_add_supported_profiles(device, HFP_HF_UUID); + + cur = msg_root = NewMockDBusConnectedMessage(); + cras_bt_device_update_properties(device, (DBusMessageIter*)&cur, NULL); + EXPECT_EQ(1, cras_tm_create_timer_called); + EXPECT_NE((void*)NULL, cras_tm_create_timer_cb); + + /* Schedule another timer, if not HFP nor A2DP is ready. */ + cras_tm_create_timer_cb(NULL, cras_tm_create_timer_cb_data); + EXPECT_EQ(2, cras_tm_create_timer_called); + + cras_bt_device_audio_gateway_initialized(device); + + /* Schedule another timer, because A2DP is not ready. */ + cras_tm_create_timer_cb(NULL, cras_tm_create_timer_cb_data); + EXPECT_EQ(3, cras_tm_create_timer_called); + EXPECT_EQ(0, cras_hfp_ag_start_called); + EXPECT_EQ(1, dbus_message_new_method_call_called); + EXPECT_STREQ("ConnectProfile", dbus_message_new_method_call_method); + + cras_bt_device_a2dp_configured(device); + + cras_tm_create_timer_cb(NULL, cras_tm_create_timer_cb_data); + EXPECT_EQ(3, cras_tm_create_timer_called); + EXPECT_EQ(1, cras_hfp_ag_remove_conflict_called); + EXPECT_EQ(1, cras_a2dp_start_called); + EXPECT_EQ(1, cras_hfp_ag_start_called); + + cras_bt_device_remove(device); + FreeMockDBusMessage(msg_root); +} + +TEST_F(BtDeviceTestSuite, DevConnectedConflictCheck) { + struct cras_bt_device* device; + struct MockDBusMessage *msg_root, *cur; + + ResetStubData(); + + device = cras_bt_device_create(NULL, FAKE_OBJ_PATH); + EXPECT_NE((void*)NULL, device); + + cras_bt_device_add_supported_profiles(device, A2DP_SINK_UUID); + cras_bt_device_add_supported_profiles(device, HSP_HS_UUID); + cras_bt_device_add_supported_profiles(device, HFP_HF_UUID); + + cur = msg_root = NewMockDBusConnectedMessage(); + cras_bt_device_update_properties(device, (DBusMessageIter*)&cur, NULL); + cras_bt_device_audio_gateway_initialized(device); + cras_bt_device_a2dp_configured(device); + EXPECT_EQ(1, cras_tm_create_timer_called); + + /* Fake that a different device already connected with A2DP */ + cras_a2dp_connected_device_ret = + reinterpret_cast<struct cras_bt_device*>(0x99); + cras_tm_create_timer_cb(NULL, cras_tm_create_timer_cb_data); + EXPECT_EQ(1, cras_tm_create_timer_called); + + /* Expect check conflict in HFP AG and A2DP. */ + EXPECT_EQ(1, cras_hfp_ag_remove_conflict_called); + EXPECT_EQ(1, cras_a2dp_suspend_connected_device_called); + EXPECT_EQ(cras_a2dp_suspend_connected_device_dev, + cras_a2dp_connected_device_ret); + + EXPECT_EQ(1, cras_a2dp_start_called); + EXPECT_EQ(1, cras_hfp_ag_start_called); + + cras_bt_device_remove(device); + FreeMockDBusMessage(msg_root); +} + +TEST_F(BtDeviceTestSuite, A2dpDropped) { + struct cras_bt_device* device; + struct MockDBusMessage *msg_root, *cur; + + ResetStubData(); + + device = cras_bt_device_create(NULL, FAKE_OBJ_PATH); + EXPECT_NE((void*)NULL, device); + + cras_bt_device_add_supported_profiles(device, A2DP_SINK_UUID); + cras_bt_device_add_supported_profiles(device, HSP_HS_UUID); + cras_bt_device_add_supported_profiles(device, HFP_HF_UUID); + + cur = msg_root = NewMockDBusConnectedMessage(); + cras_bt_device_update_properties(device, (DBusMessageIter*)&cur, NULL); + EXPECT_EQ(1, cras_tm_create_timer_called); + EXPECT_NE((void*)NULL, cras_tm_create_timer_cb); + + /* Schedule another timer, if HFP AG not yet intialized. */ + cras_tm_create_timer_cb(NULL, cras_tm_create_timer_cb_data); + EXPECT_EQ(2, cras_tm_create_timer_called); + EXPECT_EQ(1, dbus_message_new_method_call_called); + EXPECT_STREQ("ConnectProfile", dbus_message_new_method_call_method); + + cras_bt_device_a2dp_configured(device); + + cras_tm_create_timer_cb(NULL, cras_tm_create_timer_cb_data); + EXPECT_EQ(3, cras_tm_create_timer_called); + + cras_bt_device_notify_profile_dropped(device, + CRAS_BT_DEVICE_PROFILE_A2DP_SINK); + EXPECT_EQ(4, cras_tm_create_timer_called); + + /* Expect suspend timer is scheduled. */ + cras_tm_create_timer_cb(NULL, cras_tm_create_timer_cb_data); + EXPECT_EQ(1, cras_a2dp_suspend_connected_device_called); + EXPECT_EQ(1, cras_hfp_ag_suspend_connected_device_called); + EXPECT_EQ(2, dbus_message_new_method_call_called); + EXPECT_STREQ("Disconnect", dbus_message_new_method_call_method); + + cras_bt_device_remove(device); + FreeMockDBusMessage(msg_root); +} + +TEST_F(BtDeviceTestSuite, ConnectionWatchTimeout) { + struct cras_bt_device* device; + struct MockDBusMessage *msg_root, *cur; + + ResetStubData(); + + device = cras_bt_device_create(NULL, FAKE_OBJ_PATH); + EXPECT_NE((void*)NULL, device); + + cras_bt_device_add_supported_profiles(device, A2DP_SINK_UUID); + cras_bt_device_add_supported_profiles(device, HSP_HS_UUID); + cras_bt_device_add_supported_profiles(device, HFP_HF_UUID); + + cur = msg_root = NewMockDBusConnectedMessage(); + cras_bt_device_update_properties(device, (DBusMessageIter*)&cur, NULL); + EXPECT_EQ(1, cras_tm_create_timer_called); + EXPECT_NE((void*)NULL, cras_tm_create_timer_cb); + + /* Schedule another timer, if HFP AG not yet intialized. */ + cras_tm_create_timer_cb(NULL, cras_tm_create_timer_cb_data); + EXPECT_EQ(2, cras_tm_create_timer_called); + EXPECT_EQ(1, dbus_message_new_method_call_called); + EXPECT_STREQ("ConnectProfile", dbus_message_new_method_call_method); + + cras_bt_device_a2dp_configured(device); + + for (int i = 0; i < 29; i++) { + cras_tm_create_timer_cb(NULL, cras_tm_create_timer_cb_data); + EXPECT_EQ(i + 3, cras_tm_create_timer_called); + EXPECT_EQ(0, cras_a2dp_start_called); + EXPECT_EQ(0, cras_hfp_ag_start_called); + EXPECT_EQ(0, cras_hfp_ag_remove_conflict_called); + } + + dbus_message_new_method_call_called = 0; + + /* Expect suspend timer is scheduled. */ + cras_tm_create_timer_cb(NULL, cras_tm_create_timer_cb_data); + EXPECT_EQ(1, cras_a2dp_suspend_connected_device_called); + EXPECT_EQ(1, cras_hfp_ag_suspend_connected_device_called); + EXPECT_EQ(1, dbus_message_new_method_call_called); + EXPECT_STREQ("Disconnect", dbus_message_new_method_call_method); + + cras_bt_device_remove(device); + FreeMockDBusMessage(msg_root); } /* Stubs */ extern "C" { -struct cras_bt_event_log *btlog; +struct cras_bt_event_log* btlog; /* From bt_io */ -struct cras_iodev *cras_bt_io_create( - struct cras_bt_device *device, - struct cras_iodev *dev, - enum cras_bt_device_profile profile) -{ +struct cras_iodev* cras_bt_io_create(struct cras_bt_device* device, + struct cras_iodev* dev, + enum cras_bt_device_profile profile) { cras_bt_io_create_called++; cras_bt_io_create_profile_val = profile; return cras_bt_io_create_profile_ret; } -void cras_bt_io_destroy(struct cras_iodev *bt_iodev) -{ +void cras_bt_io_destroy(struct cras_iodev* bt_iodev) { cras_bt_io_destroy_called++; } struct cras_ionode* cras_bt_io_get_profile( - struct cras_iodev *bt_iodev, - enum cras_bt_device_profile profile) -{ + struct cras_iodev* bt_iodev, + enum cras_bt_device_profile profile) { return cras_bt_io_get_profile_ret; } -int cras_bt_io_append(struct cras_iodev *bt_iodev, - struct cras_iodev *dev, - enum cras_bt_device_profile profile) -{ +int cras_bt_io_append(struct cras_iodev* bt_iodev, + struct cras_iodev* dev, + enum cras_bt_device_profile profile) { cras_bt_io_append_called++; cras_bt_io_append_profile_val = profile; cras_bt_io_append_btio_val = bt_iodev; return 0; } -int cras_bt_io_on_profile(struct cras_iodev *bt_iodev, - enum cras_bt_device_profile profile) -{ +int cras_bt_io_on_profile(struct cras_iodev* bt_iodev, + enum cras_bt_device_profile profile) { return 0; } -unsigned int cras_bt_io_try_remove(struct cras_iodev *bt_iodev, - struct cras_iodev *dev) -{ +unsigned int cras_bt_io_try_remove(struct cras_iodev* bt_iodev, + struct cras_iodev* dev) { return cras_bt_io_try_remove_ret; } -int cras_bt_io_remove(struct cras_iodev *bt_iodev, - struct cras_iodev *dev) -{ +int cras_bt_io_remove(struct cras_iodev* bt_iodev, struct cras_iodev* dev) { cras_bt_io_remove_called++; return 0; } /* From bt_adapter */ -struct cras_bt_adapter *cras_bt_adapter_get(const char *object_path) -{ +struct cras_bt_adapter* cras_bt_adapter_get(const char* object_path) { return NULL; } -const char *cras_bt_adapter_address(const struct cras_bt_adapter *adapter) -{ +const char* cras_bt_adapter_address(const struct cras_bt_adapter* adapter) { return NULL; } -int cras_bt_adapter_on_usb(struct cras_bt_adapter *adapter) -{ +int cras_bt_adapter_on_usb(struct cras_bt_adapter* adapter) { return 1; } /* From bt_profile */ -void cras_bt_profile_on_device_disconnected(struct cras_bt_device *device) -{ -} +void cras_bt_profile_on_device_disconnected(struct cras_bt_device* device) {} /* From hfp_ag_profile */ -struct hfp_slc_handle *cras_hfp_ag_get_slc(struct cras_bt_device *device) -{ +struct hfp_slc_handle* cras_hfp_ag_get_slc(struct cras_bt_device* device) { return NULL; } -void cras_hfp_ag_suspend_connected_device(struct cras_bt_device *device) -{ +void cras_hfp_ag_suspend_connected_device(struct cras_bt_device* device) { + cras_hfp_ag_suspend_connected_device_called++; +} + +void cras_a2dp_suspend_connected_device(struct cras_bt_device* device) { + cras_a2dp_suspend_connected_device_called++; + cras_a2dp_suspend_connected_device_dev = device; } -void cras_a2dp_suspend_connected_device(struct cras_bt_device *device) -{ +void cras_a2dp_start(struct cras_bt_device* device) { + cras_a2dp_start_called++; } -void cras_a2dp_start(struct cras_bt_device *device) -{ +struct cras_bt_device* cras_a2dp_connected_device() { + return cras_a2dp_connected_device_ret; } -int cras_hfp_ag_start(struct cras_bt_device *device) -{ +int cras_hfp_ag_remove_conflict(struct cras_bt_device* device) { + cras_hfp_ag_remove_conflict_called++; return 0; } -void cras_hfp_ag_suspend() -{ +int cras_hfp_ag_start(struct cras_bt_device* device) { + cras_hfp_ag_start_called++; + return 0; } +void cras_hfp_ag_suspend() {} + /* From hfp_slc */ -int hfp_event_speaker_gain(struct hfp_slc_handle *handle, int gain) -{ +int hfp_event_speaker_gain(struct hfp_slc_handle* handle, int gain) { return 0; } /* From iodev_list */ -int cras_iodev_open(struct cras_iodev *dev, unsigned int cb_level, - const struct cras_audio_format *fmt) -{ +int cras_iodev_open(struct cras_iodev* dev, + unsigned int cb_level, + const struct cras_audio_format* fmt) { return 0; } -int cras_iodev_close(struct cras_iodev *dev) { +int cras_iodev_close(struct cras_iodev* dev) { return 0; } -int cras_iodev_list_dev_is_enabled(const struct cras_iodev *dev) -{ +int cras_iodev_list_dev_is_enabled(const struct cras_iodev* dev) { return 0; } -void cras_iodev_list_suspend_dev(struct cras_iodev *dev) -{ -} +void cras_iodev_list_suspend_dev(struct cras_iodev* dev) {} -void cras_iodev_list_resume_dev(struct cras_iodev *dev) -{ -} +void cras_iodev_list_resume_dev(struct cras_iodev* dev) {} -void cras_iodev_list_notify_node_volume(struct cras_ionode *node) -{ -} +void cras_iodev_list_notify_node_volume(struct cras_ionode* node) {} -int cras_main_message_send(struct cras_main_message *msg) -{ +int cras_main_message_send(struct cras_main_message* msg) { // cras_main_message is a local variable from caller, we should allocate // memory from heap and copy its data - if(cras_main_message_send_msg) + if (cras_main_message_send_msg) free(cras_main_message_send_msg); cras_main_message_send_msg = - (struct cras_main_message *)calloc(1, msg->length); - memcpy((void *)cras_main_message_send_msg, (void *)msg, msg->length); + (struct cras_main_message*)calloc(1, msg->length); + memcpy((void*)cras_main_message_send_msg, (void*)msg, msg->length); return 0; } int cras_main_message_add_handler(enum CRAS_MAIN_MESSAGE_TYPE type, - cras_message_callback callback, - void *callback_data) -{ + cras_message_callback callback, + void* callback_data) { cras_main_message_add_handler_callback = callback; cras_main_message_add_handler_callback_data = callback_data; return 0; } /* From cras_system_state */ -struct cras_tm *cras_system_state_get_tm() -{ +struct cras_tm* cras_system_state_get_tm() { return NULL; } /* From cras_tm */ -struct cras_timer *cras_tm_create_timer( - struct cras_tm *tm, - unsigned int ms, - void (*cb)(struct cras_timer *t, void *data), - void *cb_data) -{ +struct cras_timer* cras_tm_create_timer(struct cras_tm* tm, + unsigned int ms, + void (*cb)(struct cras_timer* t, + void* data), + void* cb_data) { + cras_tm_create_timer_called++; + cras_tm_create_timer_cb = cb; + cras_tm_create_timer_cb_data = cb_data; return NULL; } -void cras_tm_cancel_timer(struct cras_tm *tm, struct cras_timer *t) -{ +void cras_tm_cancel_timer(struct cras_tm* tm, struct cras_timer* t) {} + +DBusMessage* dbus_message_new_method_call(const char* destination, + const char* path, + const char* iface, + const char* method) { + dbus_message_new_method_call_called++; + dbus_message_new_method_call_method = method; + return reinterpret_cast<DBusMessage*>(0x456); +} + +void dbus_message_unref(DBusMessage* message) {} + +dbus_bool_t dbus_message_append_args(DBusMessage* message, + int first_arg_type, + ...) { + return true; } -} // extern "C" -} // namespace +dbus_bool_t dbus_connection_send_with_reply(DBusConnection* connection, + DBusMessage* message, + DBusPendingCall** pending_return, + int timeout_milliseconds) { + return true; +} -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); +dbus_bool_t dbus_pending_call_set_notify(DBusPendingCall* pending, + DBusPendingCallNotifyFunction function, + void* user_data, + DBusFreeFunction free_user_data) { + return true; } +void dbus_message_iter_recurse(DBusMessageIter* iter, DBusMessageIter* sub) { + MockDBusMessage* msg = *(MockDBusMessage**)iter; + MockDBusMessage** cur = (MockDBusMessage**)sub; + *cur = msg->recurse; +} +dbus_bool_t dbus_message_iter_next(DBusMessageIter* iter) { + MockDBusMessage** cur = (MockDBusMessage**)iter; + MockDBusMessage* msg = *cur; + *cur = msg->next; + return true; +} + +int dbus_message_iter_get_arg_type(DBusMessageIter* iter) { + MockDBusMessage* msg; + + if (iter == NULL) + return DBUS_TYPE_INVALID; + + msg = *(MockDBusMessage**)iter; + if (msg == NULL) + return DBUS_TYPE_INVALID; + + return msg->type; +} + +void dbus_message_iter_get_basic(DBusMessageIter* iter, void* value) { + MockDBusMessage* msg = *(MockDBusMessage**)iter; + switch (msg->type) { + case DBUS_TYPE_BOOLEAN: + memcpy(value, &msg->value, sizeof(int)); + break; + case DBUS_TYPE_STRING: + memcpy(value, &msg->value, sizeof(char*)); + break; + } +} + +} // extern "C" +} // namespace + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/cras/src/tests/bt_io_unittest.cc b/cras/src/tests/bt_io_unittest.cc index c5a09b86..97f4dae4 100644 --- a/cras/src/tests/bt_io_unittest.cc +++ b/cras/src/tests/bt_io_unittest.cc @@ -11,7 +11,7 @@ extern "C" { #include "utlist.h" } -static struct cras_bt_device *fake_device = +static struct cras_bt_device* fake_device = reinterpret_cast<struct cras_bt_device*>(0x123); static unsigned int cras_iodev_add_node_called; static unsigned int cras_iodev_rm_node_called; @@ -44,7 +44,7 @@ void ResetStubData() { cras_bt_device_set_active_profile_called = 0; cras_bt_device_set_active_profile_val = 0; cras_bt_device_get_active_profile_ret = 0; - cras_bt_device_switch_profile_enable_dev_called= 0; + cras_bt_device_switch_profile_enable_dev_called = 0; cras_bt_device_switch_profile_called = 0; cras_bt_device_can_switch_to_a2dp_ret = 0; cras_bt_device_has_a2dp_ret = 0; @@ -54,91 +54,87 @@ void ResetStubData() { namespace { class BtIoBasicSuite : public testing::Test { - protected: - virtual void SetUp() { - ResetStubData(); - SetUpIodev(&iodev_, CRAS_STREAM_OUTPUT); - SetUpIodev(&iodev2_, CRAS_STREAM_OUTPUT); - - update_supported_formats_called_ = 0; - frames_queued_called_ = 0; - delay_frames_called_ = 0; - get_buffer_called_ = 0; - put_buffer_called_ = 0; - configure_dev_called_ = 0; - close_dev_called_ = 0; - } - - virtual void TearDown() { - } - - static void SetUpIodev(struct cras_iodev *d, - enum CRAS_STREAM_DIRECTION dir) { - d->direction = dir; - d->update_supported_formats = update_supported_formats; - d->frames_queued = frames_queued; - d->delay_frames = delay_frames; - d->get_buffer = get_buffer; - d->put_buffer = put_buffer; - d->configure_dev = configure_dev; - d->close_dev = close_dev; - d->supported_rates = NULL; - d->supported_channel_counts = NULL; - d->supported_formats = NULL; - } - - // Stub functions for the iodev structure. - static int update_supported_formats(struct cras_iodev *iodev) { - free(iodev->supported_rates); - free(iodev->supported_channel_counts); - free(iodev->supported_formats); - iodev->supported_rates = (size_t *)calloc( - 2, sizeof(*iodev->supported_rates)); - iodev->supported_rates[0] = 48000; - iodev->supported_rates[1] = 0; - iodev->supported_channel_counts = (size_t *)calloc( - 2, sizeof(*iodev->supported_channel_counts)); - iodev->supported_channel_counts[0] = 2; - iodev->supported_channel_counts[1] = 0; - iodev->supported_formats = (snd_pcm_format_t *)calloc( - 2, sizeof(*iodev->supported_formats)); - iodev->supported_formats[0] = SND_PCM_FORMAT_S16_LE; - iodev->supported_formats[1] = (snd_pcm_format_t)0; - update_supported_formats_called_++; - return 0; - } - static int frames_queued(const cras_iodev* iodev, - struct timespec *tstamp) { - frames_queued_called_++; - return 0; - } - static int delay_frames(const cras_iodev* iodev) { - delay_frames_called_++; - return 0; - } - static int get_buffer(cras_iodev* iodev, - struct cras_audio_area** area, - unsigned int* num) { - get_buffer_called_++; - return 0; - } - static int put_buffer(cras_iodev* iodev, - unsigned int num) { - put_buffer_called_++; - return 0; - } - static int configure_dev(cras_iodev* iodev) { - configure_dev_called_++; - return 0; - } - static int close_dev(cras_iodev* iodev) { - free(iodev->format); - iodev->format = NULL; - close_dev_called_++; - return 0; - } - - static struct cras_iodev *bt_iodev; + protected: + virtual void SetUp() { + ResetStubData(); + SetUpIodev(&iodev_, CRAS_STREAM_OUTPUT); + SetUpIodev(&iodev2_, CRAS_STREAM_OUTPUT); + + update_supported_formats_called_ = 0; + frames_queued_called_ = 0; + delay_frames_called_ = 0; + get_buffer_called_ = 0; + put_buffer_called_ = 0; + configure_dev_called_ = 0; + close_dev_called_ = 0; + } + + virtual void TearDown() {} + + static void SetUpIodev(struct cras_iodev* d, enum CRAS_STREAM_DIRECTION dir) { + d->direction = dir; + d->update_supported_formats = update_supported_formats; + d->frames_queued = frames_queued; + d->delay_frames = delay_frames; + d->get_buffer = get_buffer; + d->put_buffer = put_buffer; + d->configure_dev = configure_dev; + d->close_dev = close_dev; + d->supported_rates = NULL; + d->supported_channel_counts = NULL; + d->supported_formats = NULL; + } + + // Stub functions for the iodev structure. + static int update_supported_formats(struct cras_iodev* iodev) { + free(iodev->supported_rates); + free(iodev->supported_channel_counts); + free(iodev->supported_formats); + iodev->supported_rates = + (size_t*)calloc(2, sizeof(*iodev->supported_rates)); + iodev->supported_rates[0] = 48000; + iodev->supported_rates[1] = 0; + iodev->supported_channel_counts = + (size_t*)calloc(2, sizeof(*iodev->supported_channel_counts)); + iodev->supported_channel_counts[0] = 2; + iodev->supported_channel_counts[1] = 0; + iodev->supported_formats = + (snd_pcm_format_t*)calloc(2, sizeof(*iodev->supported_formats)); + iodev->supported_formats[0] = SND_PCM_FORMAT_S16_LE; + iodev->supported_formats[1] = (snd_pcm_format_t)0; + update_supported_formats_called_++; + return 0; + } + static int frames_queued(const cras_iodev* iodev, struct timespec* tstamp) { + frames_queued_called_++; + return 0; + } + static int delay_frames(const cras_iodev* iodev) { + delay_frames_called_++; + return 0; + } + static int get_buffer(cras_iodev* iodev, + struct cras_audio_area** area, + unsigned int* num) { + get_buffer_called_++; + return 0; + } + static int put_buffer(cras_iodev* iodev, unsigned int num) { + put_buffer_called_++; + return 0; + } + static int configure_dev(cras_iodev* iodev) { + configure_dev_called_++; + return 0; + } + static int close_dev(cras_iodev* iodev) { + free(iodev->format); + iodev->format = NULL; + close_dev_called_++; + return 0; + } + + static struct cras_iodev* bt_iodev; static struct cras_iodev iodev_; static struct cras_iodev iodev2_; static unsigned int update_supported_formats_called_; @@ -150,7 +146,7 @@ class BtIoBasicSuite : public testing::Test { static unsigned int close_dev_called_; }; -struct cras_iodev *BtIoBasicSuite::bt_iodev; +struct cras_iodev* BtIoBasicSuite::bt_iodev; struct cras_iodev BtIoBasicSuite::iodev_; struct cras_iodev BtIoBasicSuite::iodev2_; unsigned int BtIoBasicSuite::update_supported_formats_called_; @@ -162,13 +158,13 @@ unsigned int BtIoBasicSuite::configure_dev_called_; unsigned int BtIoBasicSuite::close_dev_called_; TEST_F(BtIoBasicSuite, CreateBtIo) { - struct cras_audio_area *fake_area; + struct cras_audio_area* fake_area; struct cras_audio_format fake_fmt; struct timespec tstamp; unsigned fr; bt_iodev = cras_bt_io_create(fake_device, &iodev_, - CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE); - EXPECT_NE((void *)NULL, bt_iodev); + CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE); + EXPECT_NE((void*)NULL, bt_iodev); EXPECT_EQ(&iodev_, active_profile_dev(bt_iodev)); EXPECT_EQ(1, cras_iodev_list_add_output_called); bt_iodev->open_dev(bt_iodev); @@ -200,13 +196,13 @@ TEST_F(BtIoBasicSuite, SwitchProfileOnOpenDevForInputDev) { ResetStubData(); iodev_.direction = CRAS_STREAM_INPUT; bt_iodev = cras_bt_io_create(fake_device, &iodev_, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); cras_bt_device_get_active_profile_ret = CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE; bt_iodev->open_dev(bt_iodev); EXPECT_EQ(CRAS_BT_DEVICE_PROFILE_HSP_AUDIOGATEWAY | - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY, + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY, cras_bt_device_set_active_profile_val); EXPECT_EQ(1, cras_bt_device_switch_profile_enable_dev_called); cras_bt_io_destroy(bt_iodev); @@ -216,7 +212,7 @@ TEST_F(BtIoBasicSuite, NoSwitchProfileOnOpenDevForInputDevAlreadyOnHfp) { ResetStubData(); iodev_.direction = CRAS_STREAM_INPUT; bt_iodev = cras_bt_io_create(fake_device, &iodev_, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); /* No need to switch profile if already on HFP. */ cras_bt_device_get_active_profile_ret = @@ -231,7 +227,7 @@ TEST_F(BtIoBasicSuite, SwitchProfileOnCloseInputDev) { ResetStubData(); iodev_.direction = CRAS_STREAM_INPUT; bt_iodev = cras_bt_io_create(fake_device, &iodev_, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); cras_bt_device_get_active_profile_ret = CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY | @@ -249,7 +245,7 @@ TEST_F(BtIoBasicSuite, NoSwitchProfileOnCloseInputDevNoSupportA2dp) { ResetStubData(); iodev_.direction = CRAS_STREAM_INPUT; bt_iodev = cras_bt_io_create(fake_device, &iodev_, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); cras_bt_device_get_active_profile_ret = CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY | @@ -264,11 +260,10 @@ TEST_F(BtIoBasicSuite, NoSwitchProfileOnCloseInputDevNoSupportA2dp) { TEST_F(BtIoBasicSuite, SwitchProfileOnAppendA2dpDev) { ResetStubData(); bt_iodev = cras_bt_io_create(fake_device, &iodev_, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); cras_bt_device_can_switch_to_a2dp_ret = 1; - cras_bt_io_append(bt_iodev, &iodev2_, - CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE); + cras_bt_io_append(bt_iodev, &iodev2_, CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE); EXPECT_EQ(CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE, cras_bt_device_set_active_profile_val); @@ -280,11 +275,11 @@ TEST_F(BtIoBasicSuite, SwitchProfileOnAppendA2dpDev) { TEST_F(BtIoBasicSuite, NoSwitchProfileOnAppendHfpDev) { ResetStubData(); bt_iodev = cras_bt_io_create(fake_device, &iodev_, - CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE); + CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE); cras_bt_device_can_switch_to_a2dp_ret = 1; cras_bt_io_append(bt_iodev, &iodev2_, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); EXPECT_EQ(0, cras_bt_device_switch_profile_enable_dev_called); cras_bt_io_destroy(bt_iodev); @@ -296,11 +291,11 @@ TEST_F(BtIoBasicSuite, CreateSetDeviceActiveProfileToA2DP) { CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY; cras_bt_device_can_switch_to_a2dp_ret = 1; bt_iodev = cras_bt_io_create(fake_device, &iodev_, - CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE); + CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE); EXPECT_EQ(1, cras_bt_device_set_active_profile_called); EXPECT_EQ(CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE, - cras_bt_device_set_active_profile_val); + cras_bt_device_set_active_profile_val); cras_bt_io_destroy(bt_iodev); } @@ -310,7 +305,7 @@ TEST_F(BtIoBasicSuite, CreateNoSetDeviceActiveProfileToA2DP) { CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY; cras_bt_device_can_switch_to_a2dp_ret = 0; bt_iodev = cras_bt_io_create(fake_device, &iodev_, - CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE); + CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE); EXPECT_EQ(0, cras_bt_device_set_active_profile_called); cras_bt_io_destroy(bt_iodev); @@ -320,12 +315,11 @@ TEST_F(BtIoBasicSuite, CreateSetDeviceActiveProfileToHFP) { ResetStubData(); cras_bt_device_get_active_profile_ret = 0; bt_iodev = cras_bt_io_create(fake_device, &iodev_, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); - EXPECT_EQ( - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY | - CRAS_BT_DEVICE_PROFILE_HSP_AUDIOGATEWAY, - cras_bt_device_set_active_profile_val); + EXPECT_EQ(CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY | + CRAS_BT_DEVICE_PROFILE_HSP_AUDIOGATEWAY, + cras_bt_device_set_active_profile_val); cras_bt_io_destroy(bt_iodev); } @@ -335,15 +329,15 @@ TEST_F(BtIoBasicSuite, CreateDeviceWithInvalidUTF8Name) { iodev_.info.name[0] = 0xfe; is_utf8_string_ret_value = 0; bt_iodev = cras_bt_io_create(fake_device, &iodev_, - CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE); + CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE); ASSERT_STREQ("BLUETOOTH", bt_iodev->active_node->name); cras_bt_io_destroy(bt_iodev); } -} // namespace +} // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } @@ -351,121 +345,102 @@ int main(int argc, char **argv) { extern "C" { // Cras iodev -void cras_iodev_add_node(struct cras_iodev *iodev, struct cras_ionode *node) -{ +void cras_iodev_add_node(struct cras_iodev* iodev, struct cras_ionode* node) { cras_iodev_add_node_called++; DL_APPEND(iodev->nodes, node); } -void cras_iodev_rm_node(struct cras_iodev *iodev, struct cras_ionode *node) -{ +void cras_iodev_rm_node(struct cras_iodev* iodev, struct cras_ionode* node) { cras_iodev_rm_node_called++; DL_DELETE(iodev->nodes, node); } -void cras_iodev_free_format(struct cras_iodev *iodev) -{ +void cras_iodev_free_format(struct cras_iodev* iodev) { cras_iodev_free_format_called++; } -void cras_iodev_set_active_node(struct cras_iodev *iodev, - struct cras_ionode *node) -{ +void cras_iodev_set_active_node(struct cras_iodev* iodev, + struct cras_ionode* node) { cras_iodev_set_active_node_called++; iodev->active_node = node; } -int cras_iodev_set_node_attr(struct cras_ionode *ionode, - enum ionode_attr attr, int value) -{ +int cras_iodev_set_node_attr(struct cras_ionode* ionode, + enum ionode_attr attr, + int value) { return 0; } -void cras_iodev_free_resources(struct cras_iodev *iodev) -{ - cras_iodev_free_resources_called++; +void cras_iodev_free_resources(struct cras_iodev* iodev) { + cras_iodev_free_resources_called++; } // From iodev list. -int cras_iodev_list_add_output(struct cras_iodev *output) -{ +int cras_iodev_list_add_output(struct cras_iodev* output) { cras_iodev_list_add_output_called++; return 0; } -int cras_iodev_list_rm_output(struct cras_iodev *dev) -{ +int cras_iodev_list_rm_output(struct cras_iodev* dev) { cras_iodev_list_rm_output_called++; return 0; } -int cras_iodev_list_add_input(struct cras_iodev *output) -{ +int cras_iodev_list_add_input(struct cras_iodev* output) { cras_iodev_list_add_input_called++; return 0; } -int cras_iodev_list_rm_input(struct cras_iodev *dev) -{ +int cras_iodev_list_rm_input(struct cras_iodev* dev) { cras_iodev_list_rm_input_called++; return 0; } // From bt device -int cras_bt_device_get_active_profile(const struct cras_bt_device *device) -{ +int cras_bt_device_get_active_profile(const struct cras_bt_device* device) { return cras_bt_device_get_active_profile_ret; } -void cras_bt_device_set_active_profile(struct cras_bt_device *device, - unsigned int profile) -{ +void cras_bt_device_set_active_profile(struct cras_bt_device* device, + unsigned int profile) { cras_bt_device_set_active_profile_called++; cras_bt_device_set_active_profile_val = profile; } -int cras_bt_device_has_a2dp(struct cras_bt_device *device) -{ +int cras_bt_device_has_a2dp(struct cras_bt_device* device) { return cras_bt_device_has_a2dp_ret; } -int cras_bt_device_can_switch_to_a2dp(struct cras_bt_device *device) -{ +int cras_bt_device_can_switch_to_a2dp(struct cras_bt_device* device) { return cras_bt_device_can_switch_to_a2dp_ret; } -int cras_bt_device_switch_profile(struct cras_bt_device *device, - struct cras_iodev *bt_iodev) -{ +int cras_bt_device_switch_profile(struct cras_bt_device* device, + struct cras_iodev* bt_iodev) { cras_bt_device_switch_profile_called++; return 0; } -int cras_bt_device_switch_profile_enable_dev(struct cras_bt_device *device, - struct cras_iodev *bt_iodev) -{ +int cras_bt_device_switch_profile_enable_dev(struct cras_bt_device* device, + struct cras_iodev* bt_iodev) { cras_bt_device_switch_profile_enable_dev_called++; return 0; } -const char *cras_bt_device_object_path(const struct cras_bt_device *device) -{ +const char* cras_bt_device_object_path(const struct cras_bt_device* device) { return "/fake/object/path"; } -int cras_bt_device_get_use_hardware_volume(struct cras_bt_device *device) -{ +int cras_bt_device_get_use_hardware_volume(struct cras_bt_device* device) { return 1; } -int is_utf8_string(const char* string) -{ +int is_utf8_string(const char* string) { return is_utf8_string_ret_value; } -int cras_iodev_default_no_stream_playback(struct cras_iodev *odev, int enable) -{ +int cras_iodev_default_no_stream_playback(struct cras_iodev* odev, int enable) { return 0; } -} // extern "C" +} // extern "C" diff --git a/cras/src/tests/bt_profile_unittest.cc b/cras/src/tests/bt_profile_unittest.cc index 103d3ce5..0758b448 100644 --- a/cras/src/tests/bt_profile_unittest.cc +++ b/cras/src/tests/bt_profile_unittest.cc @@ -18,24 +18,24 @@ extern "C" { namespace { static struct cras_bt_profile fake_profile; -static struct cras_bt_transport *fake_transport; +static struct cras_bt_transport* fake_transport; static int profile_release_called; -static struct cras_bt_profile *profile_release_arg_value; +static struct cras_bt_profile* profile_release_arg_value; static int profile_new_connection_called; -static struct cras_bt_transport *profile_new_connection_arg_value; +static struct cras_bt_transport* profile_new_connection_arg_value; static int profile_request_disconnection_called; -static struct cras_bt_transport *profile_request_disconnection_arg_value; +static struct cras_bt_transport* profile_request_disconnection_arg_value; static int profile_cancel_called; -static struct cras_bt_profile *profile_cancel_arg_value; +static struct cras_bt_profile* profile_cancel_arg_value; static int cras_bt_transport_get_called; -static const char *cras_bt_transport_get_arg_value; +static const char* cras_bt_transport_get_arg_value; -void fake_profile_release(struct cras_bt_profile *profile); -void fake_profile_new_connection(struct cras_bt_profile *profile, - struct cras_bt_transport *transport); -void fake_profile_request_disconnection(struct cras_bt_profile *profile, - struct cras_bt_transport *transport); -void fake_profile_cancel(struct cras_bt_profile *profile); +void fake_profile_release(struct cras_bt_profile* profile); +void fake_profile_new_connection(struct cras_bt_profile* profile, + struct cras_bt_transport* transport); +void fake_profile_request_disconnection(struct cras_bt_profile* profile, + struct cras_bt_transport* transport); +void fake_profile_cancel(struct cras_bt_profile* profile); class BtProfileTestSuite : public DBusTest { virtual void SetUp() { @@ -63,7 +63,7 @@ class BtProfileTestSuite : public DBusTest { }; TEST_F(BtProfileTestSuite, RegisterProfile) { - struct cras_bt_profile *profile; + struct cras_bt_profile* profile; ExpectMethodCall(PROFILE_MANAGER_OBJ_PATH, BLUEZ_PROFILE_MGMT_INTERFACE, "RegisterProfile") @@ -88,7 +88,7 @@ TEST_F(BtProfileTestSuite, ResetProfile) { TEST_F(BtProfileTestSuite, HandleMessage) { ExpectMethodCall(PROFILE_MANAGER_OBJ_PATH, BLUEZ_PROFILE_MGMT_INTERFACE, - "RegisterProfile") + "RegisterProfile") .WithObjectPath("/fake") .SendReply(); @@ -117,75 +117,66 @@ TEST_F(BtProfileTestSuite, HandleMessage) { ASSERT_EQ(1, profile_request_disconnection_called); ASSERT_EQ(fake_transport, profile_request_disconnection_arg_value); - CreateMessageCall("/fake", "org.bluez.Profile1", "Release") - .Send(); + CreateMessageCall("/fake", "org.bluez.Profile1", "Release").Send(); WaitForMatches(); ASSERT_EQ(1, profile_release_called); ASSERT_EQ(&fake_profile, profile_release_arg_value); - CreateMessageCall("/fake", "org.bluez.Profile1", "Cancel") - .Send(); + CreateMessageCall("/fake", "org.bluez.Profile1", "Cancel").Send(); WaitForMatches(); ASSERT_EQ(1, profile_cancel_called); ASSERT_EQ(&fake_profile, profile_cancel_arg_value); } -void fake_profile_release(struct cras_bt_profile *profile) -{ +void fake_profile_release(struct cras_bt_profile* profile) { profile_release_arg_value = profile; profile_release_called++; } -void fake_profile_new_connection(struct cras_bt_profile *profile, - struct cras_bt_transport *transport) -{ +void fake_profile_new_connection(struct cras_bt_profile* profile, + struct cras_bt_transport* transport) { profile_new_connection_arg_value = transport; profile_new_connection_called++; } -void fake_profile_request_disconnection(struct cras_bt_profile *profile, - struct cras_bt_transport *transport) -{ +void fake_profile_request_disconnection(struct cras_bt_profile* profile, + struct cras_bt_transport* transport) { profile_request_disconnection_arg_value = transport; profile_request_disconnection_called++; } -void fake_profile_cancel(struct cras_bt_profile *profile) -{ +void fake_profile_cancel(struct cras_bt_profile* profile) { profile_cancel_arg_value = profile; profile_cancel_called++; } -} // namespace +} // namespace extern "C" { -dbus_bool_t append_key_value(DBusMessageIter *iter, const char *key, - int type, const char *type_string, - void *value) -{ +dbus_bool_t append_key_value(DBusMessageIter* iter, + const char* key, + int type, + const char* type_string, + void* value) { return TRUE; } -struct cras_bt_transport *cras_bt_transport_get(const char *object_path) -{ +struct cras_bt_transport* cras_bt_transport_get(const char* object_path) { cras_bt_transport_get_called++; cras_bt_transport_get_arg_value = object_path; return fake_transport; } -void cras_bt_transport_destroy(struct cras_bt_transport *transport) -{ -} +void cras_bt_transport_destroy(struct cras_bt_transport* transport) {} -struct cras_bt_transport *cras_bt_transport_create(DBusConnection *conn, - const char *object_path) -{ +struct cras_bt_transport* cras_bt_transport_create(DBusConnection* conn, + const char* object_path) { return fake_transport; } -} // extern "C" +} // extern "C" -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/buffer_share_unittest.cc b/cras/src/tests/buffer_share_unittest.cc index fd7634f5..f16456bf 100644 --- a/cras/src/tests/buffer_share_unittest.cc +++ b/cras/src/tests/buffer_share_unittest.cc @@ -2,34 +2,31 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <stdio.h> #include <gtest/gtest.h> +#include <stdio.h> extern "C" { -#include "cras_types.h" #include "buffer_share.h" +#include "cras_types.h" } namespace { -class BufferShareTestSuite : public testing::Test{ - protected: - virtual void SetUp() { - } - - virtual void TearDown() { - } +class BufferShareTestSuite : public testing::Test { + protected: + virtual void SetUp() {} + virtual void TearDown() {} }; TEST_F(BufferShareTestSuite, Create) { - buffer_share *dm = buffer_share_create(1024); - EXPECT_NE(static_cast<buffer_share *>(NULL), dm); + buffer_share* dm = buffer_share_create(1024); + EXPECT_NE(static_cast<buffer_share*>(NULL), dm); buffer_share_destroy(dm); } TEST_F(BufferShareTestSuite, AddRmDev) { - buffer_share *dm = buffer_share_create(1024); + buffer_share* dm = buffer_share_create(1024); int rc; rc = buffer_share_add_id(dm, 0xf00, NULL); @@ -46,7 +43,7 @@ TEST_F(BufferShareTestSuite, AddRmDev) { } TEST_F(BufferShareTestSuite, AddManyDevs) { - buffer_share *dm = buffer_share_create(1024); + buffer_share* dm = buffer_share_create(1024); for (unsigned int i = 0; i < INITIAL_ID_SIZE; i++) EXPECT_EQ(0, buffer_share_add_id(dm, 0xf00 + i, NULL)); @@ -61,7 +58,7 @@ TEST_F(BufferShareTestSuite, AddManyDevs) { } TEST_F(BufferShareTestSuite, OneDev) { - buffer_share *dm = buffer_share_create(1024); + buffer_share* dm = buffer_share_create(1024); int rc; rc = buffer_share_add_id(dm, 0xf00, NULL); @@ -83,7 +80,7 @@ TEST_F(BufferShareTestSuite, OneDev) { } TEST_F(BufferShareTestSuite, TwoDevs) { - buffer_share *dm = buffer_share_create(1024); + buffer_share* dm = buffer_share_create(1024); int rc; rc = buffer_share_add_id(dm, 0xf00, NULL); @@ -111,7 +108,7 @@ TEST_F(BufferShareTestSuite, TwoDevs) { } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/byte_buffer_unittest.cc b/cras/src/tests/byte_buffer_unittest.cc index e0e7bbfc..7b28b0fd 100644 --- a/cras/src/tests/byte_buffer_unittest.cc +++ b/cras/src/tests/byte_buffer_unittest.cc @@ -2,15 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <gtest/gtest.h> - #include "byte_buffer.h" +#include <gtest/gtest.h> + namespace { TEST(ByteBuffer, ReadWrite) { - struct byte_buffer *b; - uint8_t *data; + struct byte_buffer* b; + uint8_t* data; unsigned int data_size; b = byte_buffer_create(100); @@ -18,16 +18,16 @@ TEST(ByteBuffer, ReadWrite) { EXPECT_EQ(0, buf_queued(b)); data = buf_read_pointer_size(b, &data_size); - EXPECT_NE((void *)NULL, data); + EXPECT_NE((void*)NULL, data); EXPECT_EQ(0, data_size); data = buf_write_pointer_size(b, &data_size); - EXPECT_NE((void *)NULL, data); + EXPECT_NE((void*)NULL, data); EXPECT_EQ(100, data_size); buf_increment_write(b, 50); data = buf_read_pointer_size(b, &data_size); - EXPECT_NE((void *)NULL, data); + EXPECT_NE((void*)NULL, data); EXPECT_EQ(50, data_size); buf_increment_read(b, 40); @@ -36,20 +36,20 @@ TEST(ByteBuffer, ReadWrite) { /* Test write to the end of ring buffer. */ data = buf_write_pointer_size(b, &data_size); - EXPECT_NE((void *)NULL, data); + EXPECT_NE((void*)NULL, data); EXPECT_EQ(50, data_size); buf_increment_write(b, 50); data = buf_write_pointer_size(b, &data_size); - EXPECT_NE((void *)NULL, data); + EXPECT_NE((void*)NULL, data); EXPECT_EQ(40, data_size); byte_buffer_destroy(&b); } TEST(ByteBuffer, SetUsedSizeReadWrite) { - struct byte_buffer *b; - uint8_t *data; + struct byte_buffer* b; + uint8_t* data; unsigned int data_size; b = byte_buffer_create(100); @@ -61,12 +61,12 @@ TEST(ByteBuffer, SetUsedSizeReadWrite) { EXPECT_EQ(90, buf_available(b)); data = buf_write_pointer_size(b, &data_size); - EXPECT_NE((void *)NULL, data); + EXPECT_NE((void*)NULL, data); EXPECT_EQ(90, data_size); buf_increment_write(b, 90); data = buf_read_pointer_size(b, &data_size); - EXPECT_NE((void *)NULL, data); + EXPECT_NE((void*)NULL, data); EXPECT_EQ(90, data_size); buf_increment_read(b, 50); @@ -74,30 +74,30 @@ TEST(ByteBuffer, SetUsedSizeReadWrite) { EXPECT_EQ(40, buf_queued(b)); data = buf_write_pointer_size(b, &data_size); - EXPECT_NE((void *)NULL, data); + EXPECT_NE((void*)NULL, data); EXPECT_EQ(50, data_size); buf_increment_write(b, 50); data = buf_write_pointer_size(b, &data_size); - EXPECT_NE((void *)NULL, data); + EXPECT_NE((void*)NULL, data); EXPECT_EQ(0, data_size); /* Test read to the end of ring buffer. */ data = buf_read_pointer_size(b, &data_size); - EXPECT_NE((void *)NULL, data); + EXPECT_NE((void*)NULL, data); EXPECT_EQ(40, data_size); buf_increment_read(b, 40); data = buf_read_pointer_size(b, &data_size); - EXPECT_NE((void *)NULL, data); + EXPECT_NE((void*)NULL, data); EXPECT_EQ(50, data_size); byte_buffer_destroy(&b); } -} // namespace +} // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }
\ No newline at end of file diff --git a/cras/src/tests/capture_rclient_unittest.cc b/cras/src/tests/capture_rclient_unittest.cc new file mode 100644 index 00000000..5e0bc58c --- /dev/null +++ b/cras/src/tests/capture_rclient_unittest.cc @@ -0,0 +1,331 @@ +// Copyright 2019 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <gtest/gtest.h> +#include <stdio.h> +#include <unistd.h> + +extern "C" { +#include "audio_thread.h" +#include "cras_bt_log.h" +#include "cras_messages.h" +#include "cras_rclient.h" +#include "cras_rstream.h" +#include "cras_system_state.h" + +// Access to data structures and static functions. +#include "cras_capture_rclient.c" +#include "cras_rclient_util.c" +} +static unsigned int cras_make_fd_nonblocking_called; +static unsigned int cras_observer_remove_called; +static unsigned int cras_server_metrics_stream_config_called; +static int stream_list_add_called; +static int stream_list_add_return; +static unsigned int stream_list_rm_called; +static struct cras_audio_shm dummy_shm; +static struct cras_rstream dummy_rstream; +static unsigned int cras_rstream_config_init_with_message_called; + +void ResetStubData() { + cras_make_fd_nonblocking_called = 0; + cras_observer_remove_called = 0; + cras_server_metrics_stream_config_called = 0; + stream_list_add_called = 0; + stream_list_add_return = 0; + stream_list_rm_called = 0; + cras_rstream_config_init_with_message_called = 0; +} + +namespace { + +TEST(RClientSuite, CreateSendMessage) { + struct cras_rclient* rclient; + int rc; + struct cras_client_connected msg; + int pipe_fds[2]; + + ResetStubData(); + + rc = pipe(pipe_fds); + ASSERT_EQ(0, rc); + + rclient = cras_capture_rclient_create(pipe_fds[1], 800); + ASSERT_NE((void*)NULL, rclient); + EXPECT_EQ(800, rclient->id); + + rc = read(pipe_fds[0], &msg, sizeof(msg)); + EXPECT_EQ(sizeof(msg), rc); + EXPECT_EQ(CRAS_CLIENT_CONNECTED, msg.header.id); + + rclient->ops->destroy(rclient); + EXPECT_EQ(1, cras_observer_remove_called); + close(pipe_fds[0]); + close(pipe_fds[1]); +} + +class CCRMessageSuite : public testing::Test { + protected: + virtual void SetUp() { + int rc; + struct cras_client_connected msg; + + rc = pipe(pipe_fds_); + if (rc < 0) + return; + + rclient_ = cras_capture_rclient_create(pipe_fds_[1], 1); + rc = read(pipe_fds_[0], &msg, sizeof(msg)); + if (rc < 0) + return; + + fmt = { + .format = SND_PCM_FORMAT_S16_LE, + .frame_rate = 48000, + .num_channels = 2, + }; + cras_audio_format_set_default_channel_layout(&fmt); + ResetStubData(); + } + + virtual void TearDown() { + rclient_->ops->destroy(rclient_); + close(pipe_fds_[0]); + close(pipe_fds_[1]); + } + + struct cras_rclient* rclient_; + struct cras_audio_format fmt; + int pipe_fds_[2]; + int fd_; +}; + +TEST_F(CCRMessageSuite, StreamConnectMessage) { + struct cras_client_stream_connected out_msg; + int rc; + + struct cras_connect_message msg; + cras_stream_id_t stream_id = 0x10002; + cras_fill_connect_message(&msg, CRAS_STREAM_INPUT, stream_id, + CRAS_STREAM_TYPE_DEFAULT, CRAS_CLIENT_TYPE_UNKNOWN, + 480, 240, /*flags=*/0, /*effects=*/0, fmt, + NO_DEVICE, /*client_shm_size=*/0); + ASSERT_EQ(stream_id, msg.stream_id); + + fd_ = 100; + rclient_->ops->handle_message_from_client(rclient_, &msg.header, &fd_, 1); + EXPECT_EQ(1, cras_make_fd_nonblocking_called); + EXPECT_EQ(1, cras_rstream_config_init_with_message_called); + EXPECT_EQ(1, stream_list_add_called); + EXPECT_EQ(0, stream_list_rm_called); + + rc = read(pipe_fds_[0], &out_msg, sizeof(out_msg)); + EXPECT_EQ(sizeof(out_msg), rc); + EXPECT_EQ(stream_id, out_msg.stream_id); +} + +TEST_F(CCRMessageSuite, StreamConnectMessageInvalidDirection) { + struct cras_client_stream_connected out_msg; + int rc; + + struct cras_connect_message msg; + cras_stream_id_t stream_id = 0x10002; + + for (int i = 0; i < CRAS_NUM_DIRECTIONS; i++) { + const auto dir = static_cast<CRAS_STREAM_DIRECTION>(i); + if (dir == CRAS_STREAM_INPUT) + continue; + cras_fill_connect_message(&msg, dir, stream_id, CRAS_STREAM_TYPE_DEFAULT, + CRAS_CLIENT_TYPE_UNKNOWN, 480, 240, /*flags=*/0, + /*effects=*/0, fmt, NO_DEVICE, + /*client_shm_size=*/0); + ASSERT_EQ(stream_id, msg.stream_id); + + fd_ = 100; + rc = rclient_->ops->handle_message_from_client(rclient_, &msg.header, &fd_, + 1); + EXPECT_EQ(-EINVAL, rc); + EXPECT_EQ(0, cras_make_fd_nonblocking_called); + EXPECT_EQ(0, cras_rstream_config_init_with_message_called); + EXPECT_EQ(0, stream_list_add_called); + EXPECT_EQ(0, stream_list_rm_called); + + rc = read(pipe_fds_[0], &out_msg, sizeof(out_msg)); + EXPECT_EQ(sizeof(out_msg), rc); + EXPECT_EQ(-EINVAL, out_msg.err); + EXPECT_EQ(stream_id, out_msg.stream_id); + } +} + +TEST_F(CCRMessageSuite, StreamConnectMessageInvalidClientId) { + struct cras_client_stream_connected out_msg; + int rc; + + struct cras_connect_message msg; + cras_stream_id_t stream_id = 0x20002; // stream_id with invalid client_id + cras_fill_connect_message(&msg, CRAS_STREAM_INPUT, stream_id, + CRAS_STREAM_TYPE_DEFAULT, CRAS_CLIENT_TYPE_UNKNOWN, + 480, 240, /*flags=*/0, /*effects=*/0, fmt, + NO_DEVICE, /*client_shm_size=*/0); + ASSERT_EQ(stream_id, msg.stream_id); + + fd_ = 100; + rc = + rclient_->ops->handle_message_from_client(rclient_, &msg.header, &fd_, 1); + EXPECT_EQ(-EINVAL, rc); + EXPECT_EQ(0, cras_make_fd_nonblocking_called); + EXPECT_EQ(0, cras_rstream_config_init_with_message_called); + EXPECT_EQ(0, stream_list_add_called); + EXPECT_EQ(0, stream_list_rm_called); + + rc = read(pipe_fds_[0], &out_msg, sizeof(out_msg)); + EXPECT_EQ(sizeof(out_msg), rc); + EXPECT_EQ(-EINVAL, out_msg.err); + EXPECT_EQ(stream_id, out_msg.stream_id); +} + +/* + * TODO(yuhsaun): Remove this test when there are no client uses the old + * craslib. (CRAS_PROTO_VER = 3) + */ +TEST_F(CCRMessageSuite, StreamConnectMessageOldProtocal) { + struct cras_client_stream_connected out_msg; + int rc; + + struct cras_connect_message_old msg; + cras_stream_id_t stream_id = 0x10002; + + msg.proto_version = 3; + msg.direction = CRAS_STREAM_INPUT; + msg.stream_id = stream_id; + msg.stream_type = CRAS_STREAM_TYPE_DEFAULT; + msg.buffer_frames = 480; + msg.cb_threshold = 240; + msg.flags = 0; + msg.effects = 0; + pack_cras_audio_format(&msg.format, &fmt); + msg.dev_idx = NO_DEVICE; + msg.header.id = CRAS_SERVER_CONNECT_STREAM; + msg.header.length = sizeof(struct cras_connect_message_old); + + fd_ = 100; + rc = + rclient_->ops->handle_message_from_client(rclient_, &msg.header, &fd_, 1); + EXPECT_EQ(1, cras_make_fd_nonblocking_called); + EXPECT_EQ(1, cras_rstream_config_init_with_message_called); + EXPECT_EQ(1, stream_list_add_called); + EXPECT_EQ(0, stream_list_rm_called); + + rc = read(pipe_fds_[0], &out_msg, sizeof(out_msg)); + EXPECT_EQ(sizeof(out_msg), rc); + EXPECT_EQ(stream_id, out_msg.stream_id); +} + +TEST_F(CCRMessageSuite, StreamDisconnectMessage) { + struct cras_disconnect_stream_message msg; + cras_stream_id_t stream_id = 0x10002; + cras_fill_disconnect_stream_message(&msg, stream_id); + + rclient_->ops->handle_message_from_client(rclient_, &msg.header, NULL, 0); + EXPECT_EQ(0, stream_list_add_called); + EXPECT_EQ(1, stream_list_rm_called); +} + +TEST_F(CCRMessageSuite, StreamDisconnectMessageInvalidClientId) { + struct cras_disconnect_stream_message msg; + cras_stream_id_t stream_id = 0x20002; // stream_id with invalid client_id + cras_fill_disconnect_stream_message(&msg, stream_id); + + rclient_->ops->handle_message_from_client(rclient_, &msg.header, NULL, 0); + EXPECT_EQ(0, stream_list_add_called); + EXPECT_EQ(0, stream_list_rm_called); +} +} // namespace + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + +/* stubs */ +extern "C" { + +struct stream_list* cras_iodev_list_get_stream_list() { + return NULL; +} + +int cras_make_fd_nonblocking(int fd) { + cras_make_fd_nonblocking_called++; + return 0; +} + +void cras_observer_remove(struct cras_observer_client* client) { + cras_observer_remove_called++; +} + +unsigned int cras_rstream_get_effects(const struct cras_rstream* stream) { + return 0; +} + +int cras_server_metrics_stream_config(struct cras_rstream_config* config) { + cras_server_metrics_stream_config_called++; + return 0; +} + +int cras_send_with_fds(int sockfd, + const void* buf, + size_t len, + int* fd, + unsigned int num_fds) { + return write(sockfd, buf, len); +} + +key_t cras_sys_state_shm_fd() { + return 1; +} + +void cras_system_set_suspended(int suspended) {} + +int stream_list_rm_all_client_streams(struct stream_list* list, + struct cras_rclient* rclient) { + return 0; +} + +int stream_list_rm(struct stream_list* list, cras_stream_id_t id) { + stream_list_rm_called++; + return 0; +} + +int stream_list_add(struct stream_list* list, + struct cras_rstream_config* config, + struct cras_rstream** stream) { + int ret; + + *stream = &dummy_rstream; + + stream_list_add_called++; + ret = stream_list_add_return; + if (ret) + stream_list_add_return = -EINVAL; + + dummy_rstream.shm = &dummy_shm; + dummy_rstream.direction = config->direction; + dummy_rstream.stream_id = config->stream_id; + + return ret; +} + +void cras_rstream_config_init_with_message( + struct cras_rclient* client, + const struct cras_connect_message* msg, + int* aud_fd, + int* client_shm_fd, + const struct cras_audio_format* remote_fmt, + struct cras_rstream_config* stream_config) { + cras_rstream_config_init_with_message_called++; +} + +void cras_rstream_config_cleanup(struct cras_rstream_config* stream_config) {} + +} // extern "C" diff --git a/cras/src/tests/card_config_unittest.cc b/cras/src/tests/card_config_unittest.cc index e4bed40e..4616515b 100644 --- a/cras/src/tests/card_config_unittest.cc +++ b/cras/src/tests/card_config_unittest.cc @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <stdio.h> #include <gtest/gtest.h> +#include <stdio.h> extern "C" { #include "cras_card_config.h" @@ -38,21 +38,21 @@ void CreateConfigFile(const char* name, const char* config_text) { fclose(f); } -class CardConfigTestSuite : public testing::Test{ - protected: - virtual void SetUp() { - cras_volume_curve_create_default_called = 0; - cras_volume_curve_create_default_return = - reinterpret_cast<struct cras_volume_curve*>(0x55); - cras_volume_curve_create_simple_step_return = - reinterpret_cast<struct cras_volume_curve*>(0x56); - cras_volume_curve_create_explicit_return = - reinterpret_cast<struct cras_volume_curve*>(0x57); - cras_volume_curve_create_simple_step_called = 0; - cras_volume_curve_create_simple_step_return = NULL; - cras_volume_curve_create_explicit_called = 0; - cras_volume_curve_create_explicit_return = NULL; - } +class CardConfigTestSuite : public testing::Test { + protected: + virtual void SetUp() { + cras_volume_curve_create_default_called = 0; + cras_volume_curve_create_default_return = + reinterpret_cast<struct cras_volume_curve*>(0x55); + cras_volume_curve_create_simple_step_return = + reinterpret_cast<struct cras_volume_curve*>(0x56); + cras_volume_curve_create_explicit_return = + reinterpret_cast<struct cras_volume_curve*>(0x57); + cras_volume_curve_create_simple_step_called = 0; + cras_volume_curve_create_simple_step_return = NULL; + cras_volume_curve_create_explicit_called = 0; + cras_volume_curve_create_explicit_return = NULL; + } }; // Test that no config is returned if the file doesn't exist. @@ -95,10 +95,10 @@ TEST_F(CardConfigTestSuite, NullConfigGivesDefaultVolumeCurve) { TEST_F(CardConfigTestSuite, SimpleStepConfig) { static const char simple_config_name[] = "simple"; static const char simple_config_text[] = - "[Card1]\n" - "volume_curve = simple_step\n" - "volume_step = 75\n" - "max_volume = -600\n"; + "[Card1]\n" + "volume_curve = simple_step\n" + "volume_step = 75\n" + "max_volume = -600\n"; struct cras_card_config* config; struct cras_volume_curve* curve; @@ -127,109 +127,109 @@ TEST_F(CardConfigTestSuite, SimpleStepConfig) { TEST_F(CardConfigTestSuite, ExplicitCurveConfig) { static const char explicit_config_name[] = "explicit"; static const char explicit_config_text[] = - "[Card1]\n" - "volume_curve = explicit\n" - "dB_at_0 = -9950\n" - "dB_at_1 = -9850\n" - "dB_at_2 = -9750\n" - "dB_at_3 = -9650\n" - "dB_at_4 = -9550\n" - "dB_at_5 = -9450\n" - "dB_at_6 = -9350\n" - "dB_at_7 = -9250\n" - "dB_at_8 = -9150\n" - "dB_at_9 = -9050\n" - "dB_at_10 = -8950\n" - "dB_at_11 = -8850\n" - "dB_at_12 = -8750\n" - "dB_at_13 = -8650\n" - "dB_at_14 = -8550\n" - "dB_at_15 = -8450\n" - "dB_at_16 = -8350\n" - "dB_at_17 = -8250\n" - "dB_at_18 = -8150\n" - "dB_at_19 = -8050\n" - "dB_at_20 = -7950\n" - "dB_at_21 = -7850\n" - "dB_at_22 = -7750\n" - "dB_at_23 = -7650\n" - "dB_at_24 = -7550\n" - "dB_at_25 = -7450\n" - "dB_at_26 = -7350\n" - "dB_at_27 = -7250\n" - "dB_at_28 = -7150\n" - "dB_at_29 = -7050\n" - "dB_at_30 = -6950\n" - "dB_at_31 = -6850\n" - "dB_at_32 = -6750\n" - "dB_at_33 = -6650\n" - "dB_at_34 = -6550\n" - "dB_at_35 = -6450\n" - "dB_at_36 = -6350\n" - "dB_at_37 = -6250\n" - "dB_at_38 = -6150\n" - "dB_at_39 = -6050\n" - "dB_at_40 = -5950\n" - "dB_at_41 = -5850\n" - "dB_at_42 = -5750\n" - "dB_at_43 = -5650\n" - "dB_at_44 = -5550\n" - "dB_at_45 = -5450\n" - "dB_at_46 = -5350\n" - "dB_at_47 = -5250\n" - "dB_at_48 = -5150\n" - "dB_at_49 = -5050\n" - "dB_at_50 = -4950\n" - "dB_at_51 = -4850\n" - "dB_at_52 = -4750\n" - "dB_at_53 = -4650\n" - "dB_at_54 = -4550\n" - "dB_at_55 = -4450\n" - "dB_at_56 = -4350\n" - "dB_at_57 = -4250\n" - "dB_at_58 = -4150\n" - "dB_at_59 = -4050\n" - "dB_at_60 = -3950\n" - "dB_at_61 = -3850\n" - "dB_at_62 = -3750\n" - "dB_at_63 = -3650\n" - "dB_at_64 = -3550\n" - "dB_at_65 = -3450\n" - "dB_at_66 = -3350\n" - "dB_at_67 = -3250\n" - "dB_at_68 = -3150\n" - "dB_at_69 = -3050\n" - "dB_at_70 = -2950\n" - "dB_at_71 = -2850\n" - "dB_at_72 = -2750\n" - "dB_at_73 = -2650\n" - "dB_at_74 = -2550\n" - "dB_at_75 = -2450\n" - "dB_at_76 = -2350\n" - "dB_at_77 = -2250\n" - "dB_at_78 = -2150\n" - "dB_at_79 = -2050\n" - "dB_at_80 = -1950\n" - "dB_at_81 = -1850\n" - "dB_at_82 = -1750\n" - "dB_at_83 = -1650\n" - "dB_at_84 = -1550\n" - "dB_at_85 = -1450\n" - "dB_at_86 = -1350\n" - "dB_at_87 = -1250\n" - "dB_at_88 = -1150\n" - "dB_at_89 = -1050\n" - "dB_at_90 = -950\n" - "dB_at_91 = -850\n" - "dB_at_92 = -750\n" - "dB_at_93 = -650\n" - "dB_at_94 = -550\n" - "dB_at_95 = -450\n" - "dB_at_96 = -350\n" - "dB_at_97 = -250\n" - "dB_at_98 = -150\n" - "dB_at_99 = -50\n" - "dB_at_100 = 50\n"; + "[Card1]\n" + "volume_curve = explicit\n" + "dB_at_0 = -9950\n" + "dB_at_1 = -9850\n" + "dB_at_2 = -9750\n" + "dB_at_3 = -9650\n" + "dB_at_4 = -9550\n" + "dB_at_5 = -9450\n" + "dB_at_6 = -9350\n" + "dB_at_7 = -9250\n" + "dB_at_8 = -9150\n" + "dB_at_9 = -9050\n" + "dB_at_10 = -8950\n" + "dB_at_11 = -8850\n" + "dB_at_12 = -8750\n" + "dB_at_13 = -8650\n" + "dB_at_14 = -8550\n" + "dB_at_15 = -8450\n" + "dB_at_16 = -8350\n" + "dB_at_17 = -8250\n" + "dB_at_18 = -8150\n" + "dB_at_19 = -8050\n" + "dB_at_20 = -7950\n" + "dB_at_21 = -7850\n" + "dB_at_22 = -7750\n" + "dB_at_23 = -7650\n" + "dB_at_24 = -7550\n" + "dB_at_25 = -7450\n" + "dB_at_26 = -7350\n" + "dB_at_27 = -7250\n" + "dB_at_28 = -7150\n" + "dB_at_29 = -7050\n" + "dB_at_30 = -6950\n" + "dB_at_31 = -6850\n" + "dB_at_32 = -6750\n" + "dB_at_33 = -6650\n" + "dB_at_34 = -6550\n" + "dB_at_35 = -6450\n" + "dB_at_36 = -6350\n" + "dB_at_37 = -6250\n" + "dB_at_38 = -6150\n" + "dB_at_39 = -6050\n" + "dB_at_40 = -5950\n" + "dB_at_41 = -5850\n" + "dB_at_42 = -5750\n" + "dB_at_43 = -5650\n" + "dB_at_44 = -5550\n" + "dB_at_45 = -5450\n" + "dB_at_46 = -5350\n" + "dB_at_47 = -5250\n" + "dB_at_48 = -5150\n" + "dB_at_49 = -5050\n" + "dB_at_50 = -4950\n" + "dB_at_51 = -4850\n" + "dB_at_52 = -4750\n" + "dB_at_53 = -4650\n" + "dB_at_54 = -4550\n" + "dB_at_55 = -4450\n" + "dB_at_56 = -4350\n" + "dB_at_57 = -4250\n" + "dB_at_58 = -4150\n" + "dB_at_59 = -4050\n" + "dB_at_60 = -3950\n" + "dB_at_61 = -3850\n" + "dB_at_62 = -3750\n" + "dB_at_63 = -3650\n" + "dB_at_64 = -3550\n" + "dB_at_65 = -3450\n" + "dB_at_66 = -3350\n" + "dB_at_67 = -3250\n" + "dB_at_68 = -3150\n" + "dB_at_69 = -3050\n" + "dB_at_70 = -2950\n" + "dB_at_71 = -2850\n" + "dB_at_72 = -2750\n" + "dB_at_73 = -2650\n" + "dB_at_74 = -2550\n" + "dB_at_75 = -2450\n" + "dB_at_76 = -2350\n" + "dB_at_77 = -2250\n" + "dB_at_78 = -2150\n" + "dB_at_79 = -2050\n" + "dB_at_80 = -1950\n" + "dB_at_81 = -1850\n" + "dB_at_82 = -1750\n" + "dB_at_83 = -1650\n" + "dB_at_84 = -1550\n" + "dB_at_85 = -1450\n" + "dB_at_86 = -1350\n" + "dB_at_87 = -1250\n" + "dB_at_88 = -1150\n" + "dB_at_89 = -1050\n" + "dB_at_90 = -950\n" + "dB_at_91 = -850\n" + "dB_at_92 = -750\n" + "dB_at_93 = -650\n" + "dB_at_94 = -550\n" + "dB_at_95 = -450\n" + "dB_at_96 = -350\n" + "dB_at_97 = -250\n" + "dB_at_98 = -150\n" + "dB_at_99 = -50\n" + "dB_at_100 = 50\n"; struct cras_card_config* config; struct cras_volume_curve* curve; @@ -259,7 +259,7 @@ struct cras_volume_curve* cras_volume_curve_create_default() { return cras_volume_curve_create_default_return; } -struct cras_volume_curve *cras_volume_curve_create_simple_step( +struct cras_volume_curve* cras_volume_curve_create_simple_step( long max_volume, long volume_step) { cras_volume_curve_create_simple_step_called++; @@ -268,13 +268,11 @@ struct cras_volume_curve *cras_volume_curve_create_simple_step( return cras_volume_curve_create_simple_step_return; } -struct cras_volume_curve *cras_volume_curve_create_explicit( - long dB_vals[101]) { +struct cras_volume_curve* cras_volume_curve_create_explicit(long dB_vals[101]) { cras_volume_curve_create_explicit_called++; memcpy(cras_explicit_curve, dB_vals, sizeof(cras_explicit_curve)); return cras_volume_curve_create_explicit_return; } - } } // namespace diff --git a/cras/src/tests/checksum_unittest.cc b/cras/src/tests/checksum_unittest.cc index 5974034c..4d54b2c2 100644 --- a/cras/src/tests/checksum_unittest.cc +++ b/cras/src/tests/checksum_unittest.cc @@ -10,29 +10,28 @@ namespace { struct TestCase { - const char *input; + const char* input; uint32_t output; }; -static TestCase test_case[] = -{ - /* The answers can be obtained by a command like "echo -n a | cksum" */ - { "", 4294967295U }, - { "a", 1220704766U }, - { "12345678901234567890", 970143720U }, +static TestCase test_case[] = { + /* The answers can be obtained by a command like "echo -n a | cksum" */ + {"", 4294967295U}, + {"a", 1220704766U}, + {"12345678901234567890", 970143720U}, }; TEST(ChecksumTest, All) { for (size_t i = 0; i < ARRAY_SIZE(test_case); i++) { - const char *input = test_case[i].input; + const char* input = test_case[i].input; uint32_t output = test_case[i].output; - EXPECT_EQ(output, crc32_checksum((unsigned char *)input, strlen(input))); + EXPECT_EQ(output, crc32_checksum((unsigned char*)input, strlen(input))); } } } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/control_rclient_unittest.cc b/cras/src/tests/control_rclient_unittest.cc index 7a3b4800..634bfe1a 100644 --- a/cras/src/tests/control_rclient_unittest.cc +++ b/cras/src/tests/control_rclient_unittest.cc @@ -16,6 +16,7 @@ extern "C" { // Access to data structures and static functions. #include "cras_control_rclient.c" +#include "cras_rclient_util.c" } // Stub data. @@ -58,6 +59,7 @@ static size_t cras_observer_set_ops_called; static size_t cras_observer_ops_are_empty_called; static struct cras_observer_ops cras_observer_ops_are_empty_empty_ops; static size_t cras_observer_remove_called; +static unsigned int cras_rstream_config_init_with_message_called; void ResetStubData() { cras_rstream_create_return = 0; @@ -99,6 +101,7 @@ void ResetStubData() { memset(&cras_observer_ops_are_empty_empty_ops, 0, sizeof(cras_observer_ops_are_empty_empty_ops)); cras_observer_remove_called = 0; + cras_rstream_config_init_with_message_called = 0; } namespace { @@ -135,7 +138,7 @@ class RClientMessagesSuite : public testing::Test { rc = pipe(pipe_fds_); if (rc < 0) return; - rclient_ = cras_control_rclient_create(pipe_fds_[1], 800); + rclient_ = cras_control_rclient_create(pipe_fds_[1], 1); rc = read(pipe_fds_[0], &msg, sizeof(msg)); if (rc < 0) return; @@ -156,6 +159,7 @@ class RClientMessagesSuite : public testing::Test { connect_msg_.format.frame_rate = 48000; connect_msg_.format.format = SND_PCM_FORMAT_S16_LE; connect_msg_.dev_idx = NO_DEVICE; + connect_msg_.client_shm_size = 0; btlog = cras_bt_event_log_init(); ResetStubData(); } @@ -177,6 +181,7 @@ class RClientMessagesSuite : public testing::Test { struct cras_rstream* rstream_; size_t stream_id_; int pipe_fds_[2]; + int fd_; }; TEST_F(RClientMessagesSuite, AudThreadAttachFail) { @@ -186,15 +191,17 @@ TEST_F(RClientMessagesSuite, AudThreadAttachFail) { cras_rstream_create_stream_out = rstream_; stream_list_add_stream_return = -EINVAL; + fd_ = 100; rc = rclient_->ops->handle_message_from_client(rclient_, &connect_msg_.header, - 100); - EXPECT_EQ(0, rc); + &fd_, 1); + EXPECT_EQ(-EINVAL, rc); rc = read(pipe_fds_[0], &out_msg, sizeof(out_msg)); EXPECT_EQ(sizeof(out_msg), rc); EXPECT_EQ(stream_id_, out_msg.stream_id); EXPECT_NE(0, out_msg.err); EXPECT_EQ(0, cras_iodev_list_rm_output_called); + EXPECT_EQ(1, cras_rstream_config_init_with_message_called); EXPECT_EQ(1, stream_list_add_stream_called); EXPECT_EQ(0, stream_list_disconnect_stream_called); EXPECT_EQ(0, cras_server_metrics_stream_config_called); @@ -205,8 +212,8 @@ TEST_F(RClientMessagesSuite, ConnectMsgWithBadFd) { int rc; rc = rclient_->ops->handle_message_from_client(rclient_, &connect_msg_.header, - -1); - EXPECT_EQ(0, rc); + NULL, 0); + EXPECT_EQ(-EBADF, rc); rc = read(pipe_fds_[0], &out_msg, sizeof(out_msg)); EXPECT_EQ(sizeof(out_msg), rc); @@ -217,6 +224,106 @@ TEST_F(RClientMessagesSuite, ConnectMsgWithBadFd) { EXPECT_EQ(0, cras_server_metrics_stream_config_called); } +TEST_F(RClientMessagesSuite, ConnectMsgFromOldClient) { + struct cras_client_stream_connected out_msg; + int rc; + + cras_rstream_create_stream_out = rstream_; + cras_iodev_attach_stream_retval = 0; + + connect_msg_.header.length = sizeof(struct cras_connect_message_old); + connect_msg_.proto_version = 3; + + fd_ = 100; + rc = rclient_->ops->handle_message_from_client(rclient_, &connect_msg_.header, + &fd_, 1); + EXPECT_EQ(0, rc); + EXPECT_EQ(1, cras_make_fd_nonblocking_called); + + rc = read(pipe_fds_[0], &out_msg, sizeof(out_msg)); + EXPECT_EQ(sizeof(out_msg), rc); + EXPECT_EQ(stream_id_, out_msg.stream_id); + EXPECT_EQ(0, out_msg.err); + EXPECT_EQ(1, cras_rstream_config_init_with_message_called); + EXPECT_EQ(1, stream_list_add_stream_called); + EXPECT_EQ(0, stream_list_disconnect_stream_called); + EXPECT_EQ(1, cras_server_metrics_stream_config_called); +} + +TEST_F(RClientMessagesSuite, StreamConnectMessageValidDirection) { + struct cras_client_stream_connected out_msg; + int rc; + int called = 0; + + for (int i = 0; i < CRAS_NUM_DIRECTIONS; i++) { + connect_msg_.direction = static_cast<CRAS_STREAM_DIRECTION>(i); + if (connect_msg_.direction == CRAS_STREAM_UNDEFINED) + continue; + called++; + cras_rstream_create_stream_out = rstream_; + cras_iodev_attach_stream_retval = 0; + + fd_ = 100; + rc = rclient_->ops->handle_message_from_client( + rclient_, &connect_msg_.header, &fd_, 1); + EXPECT_EQ(0, rc); + EXPECT_EQ(called, cras_make_fd_nonblocking_called); + + rc = read(pipe_fds_[0], &out_msg, sizeof(out_msg)); + EXPECT_EQ(sizeof(out_msg), rc); + EXPECT_EQ(stream_id_, out_msg.stream_id); + EXPECT_EQ(0, out_msg.err); + EXPECT_EQ(called, cras_rstream_config_init_with_message_called); + EXPECT_EQ(called, stream_list_add_stream_called); + EXPECT_EQ(0, stream_list_disconnect_stream_called); + EXPECT_EQ(called, cras_server_metrics_stream_config_called); + } +} + +TEST_F(RClientMessagesSuite, StreamConnectMessageInvalidDirection) { + struct cras_client_stream_connected out_msg; + int rc; + + connect_msg_.direction = CRAS_STREAM_UNDEFINED; + cras_rstream_create_stream_out = rstream_; + cras_iodev_attach_stream_retval = 0; + + fd_ = 100; + rc = rclient_->ops->handle_message_from_client(rclient_, &connect_msg_.header, + &fd_, 1); + EXPECT_EQ(-EINVAL, rc); + EXPECT_EQ(0, cras_make_fd_nonblocking_called); + + rc = read(pipe_fds_[0], &out_msg, sizeof(out_msg)); + EXPECT_EQ(sizeof(out_msg), rc); + EXPECT_EQ(stream_id_, out_msg.stream_id); + EXPECT_EQ(-EINVAL, out_msg.err); + EXPECT_EQ(0, stream_list_add_stream_called); + EXPECT_EQ(0, stream_list_disconnect_stream_called); + EXPECT_EQ(0, cras_server_metrics_stream_config_called); +} + +TEST_F(RClientMessagesSuite, StreamConnectMessageInvalidClientId) { + struct cras_client_stream_connected out_msg; + int rc; + + connect_msg_.stream_id = 0x20002; // stream_id with invalid client_id + + fd_ = 100; + rc = rclient_->ops->handle_message_from_client(rclient_, &connect_msg_.header, + &fd_, 1); + EXPECT_EQ(-EINVAL, rc); + EXPECT_EQ(0, cras_make_fd_nonblocking_called); + EXPECT_EQ(0, cras_rstream_config_init_with_message_called); + EXPECT_EQ(0, stream_list_add_stream_called); + EXPECT_EQ(0, stream_list_disconnect_stream_called); + + rc = read(pipe_fds_[0], &out_msg, sizeof(out_msg)); + EXPECT_EQ(sizeof(out_msg), rc); + EXPECT_EQ(-EINVAL, out_msg.err); + EXPECT_EQ(connect_msg_.stream_id, out_msg.stream_id); +} + TEST_F(RClientMessagesSuite, SuccessReply) { struct cras_client_stream_connected out_msg; int rc; @@ -224,8 +331,9 @@ TEST_F(RClientMessagesSuite, SuccessReply) { cras_rstream_create_stream_out = rstream_; cras_iodev_attach_stream_retval = 0; + fd_ = 100; rc = rclient_->ops->handle_message_from_client(rclient_, &connect_msg_.header, - 100); + &fd_, 1); EXPECT_EQ(0, rc); EXPECT_EQ(1, cras_make_fd_nonblocking_called); @@ -233,6 +341,7 @@ TEST_F(RClientMessagesSuite, SuccessReply) { EXPECT_EQ(sizeof(out_msg), rc); EXPECT_EQ(stream_id_, out_msg.stream_id); EXPECT_EQ(0, out_msg.err); + EXPECT_EQ(1, cras_rstream_config_init_with_message_called); EXPECT_EQ(1, stream_list_add_stream_called); EXPECT_EQ(0, stream_list_disconnect_stream_called); EXPECT_EQ(1, cras_server_metrics_stream_config_called); @@ -245,8 +354,9 @@ TEST_F(RClientMessagesSuite, SuccessCreateThreadReply) { cras_rstream_create_stream_out = rstream_; cras_iodev_attach_stream_retval = 0; + fd_ = 100; rc = rclient_->ops->handle_message_from_client(rclient_, &connect_msg_.header, - 100); + &fd_, 1); EXPECT_EQ(0, rc); EXPECT_EQ(1, cras_make_fd_nonblocking_called); @@ -254,6 +364,7 @@ TEST_F(RClientMessagesSuite, SuccessCreateThreadReply) { EXPECT_EQ(sizeof(out_msg), rc); EXPECT_EQ(stream_id_, out_msg.stream_id); EXPECT_EQ(0, out_msg.err); + EXPECT_EQ(1, cras_rstream_config_init_with_message_called); EXPECT_EQ(1, stream_list_add_stream_called); EXPECT_EQ(0, stream_list_disconnect_stream_called); EXPECT_EQ(1, cras_server_metrics_stream_config_called); @@ -267,7 +378,8 @@ TEST_F(RClientMessagesSuite, SetVolume) { msg.header.length = sizeof(msg); msg.volume = 66; - rc = rclient_->ops->handle_message_from_client(rclient_, &msg.header, -1); + rc = + rclient_->ops->handle_message_from_client(rclient_, &msg.header, NULL, 0); EXPECT_EQ(0, rc); EXPECT_EQ(1, cras_system_set_volume_called); EXPECT_EQ(66, cras_system_set_volume_value); @@ -281,7 +393,8 @@ TEST_F(RClientMessagesSuite, SetCaptureVolume) { msg.header.length = sizeof(msg); msg.volume = 66; - rc = rclient_->ops->handle_message_from_client(rclient_, &msg.header, -1); + rc = + rclient_->ops->handle_message_from_client(rclient_, &msg.header, NULL, 0); EXPECT_EQ(0, rc); EXPECT_EQ(1, cras_system_set_capture_gain_called); EXPECT_EQ(66, cras_system_set_capture_gain_value); @@ -295,13 +408,15 @@ TEST_F(RClientMessagesSuite, SetMute) { msg.header.length = sizeof(msg); msg.mute = 1; - rc = rclient_->ops->handle_message_from_client(rclient_, &msg.header, -1); + rc = + rclient_->ops->handle_message_from_client(rclient_, &msg.header, NULL, 0); EXPECT_EQ(0, rc); EXPECT_EQ(1, cras_system_set_mute_called); EXPECT_EQ(1, cras_system_set_mute_value); msg.header.id = CRAS_SERVER_SET_SYSTEM_MUTE_LOCKED; - rc = rclient_->ops->handle_message_from_client(rclient_, &msg.header, -1); + rc = + rclient_->ops->handle_message_from_client(rclient_, &msg.header, NULL, 0); EXPECT_EQ(0, rc); EXPECT_EQ(1, cras_system_set_mute_locked_called); EXPECT_EQ(1, cras_system_set_mute_locked_value); @@ -315,7 +430,8 @@ TEST_F(RClientMessagesSuite, SetUserMute) { msg.header.length = sizeof(msg); msg.mute = 1; - rc = rclient_->ops->handle_message_from_client(rclient_, &msg.header, -1); + rc = + rclient_->ops->handle_message_from_client(rclient_, &msg.header, NULL, 0); EXPECT_EQ(0, rc); EXPECT_EQ(1, cras_system_set_user_mute_called); EXPECT_EQ(1, cras_system_set_user_mute_value); @@ -329,13 +445,15 @@ TEST_F(RClientMessagesSuite, SetCaptureMute) { msg.header.length = sizeof(msg); msg.mute = 1; - rc = rclient_->ops->handle_message_from_client(rclient_, &msg.header, -1); + rc = + rclient_->ops->handle_message_from_client(rclient_, &msg.header, NULL, 0); EXPECT_EQ(0, rc); EXPECT_EQ(1, cras_system_set_capture_mute_called); EXPECT_EQ(1, cras_system_set_capture_mute_value); msg.header.id = CRAS_SERVER_SET_SYSTEM_CAPTURE_MUTE_LOCKED; - rc = rclient_->ops->handle_message_from_client(rclient_, &msg.header, -1); + rc = + rclient_->ops->handle_message_from_client(rclient_, &msg.header, NULL, 0); EXPECT_EQ(0, rc); EXPECT_EQ(1, cras_system_set_capture_mute_locked_called); EXPECT_EQ(1, cras_system_set_capture_mute_locked_value); @@ -345,7 +463,8 @@ TEST_F(RClientMessagesSuite, DumpSnapshots) { struct cras_dump_snapshots msg; int rc; cras_fill_dump_snapshots(&msg); - rc = rclient_->ops->handle_message_from_client(rclient_, &msg.header, -1); + rc = + rclient_->ops->handle_message_from_client(rclient_, &msg.header, NULL, 0); EXPECT_EQ(0, rc); EXPECT_EQ(1, cras_system_state_dump_snapshots_called); } @@ -366,7 +485,8 @@ void RClientMessagesSuite::RegisterNotification( EXPECT_EQ(msg.do_register, do_register); EXPECT_EQ(msg.msg_id, msg_id); - rc = rclient_->ops->handle_message_from_client(rclient_, &msg.header, -1); + rc = + rclient_->ops->handle_message_from_client(rclient_, &msg.header, NULL, 0); EXPECT_EQ(0, rc); EXPECT_EQ(cras_observer_register_notify_called, cras_observer_get_ops_called); EXPECT_EQ(cras_observer_register_notify_called, @@ -686,6 +806,10 @@ int audio_thread_set_aec_dump(struct audio_thread* thread, return 0; } +int audio_thread_event_log_shm_fd() { + return -1; +} + #ifdef HAVE_WEBRTC_APM void cras_apm_list_reload_aec_config() {} #endif @@ -890,4 +1014,16 @@ int cras_server_metrics_stream_config(struct cras_rstream_config* config) { return 0; } +void cras_rstream_config_init_with_message( + struct cras_rclient* client, + const struct cras_connect_message* msg, + int* aud_fd, + int* client_shm_fd, + const struct cras_audio_format* remote_fmt, + struct cras_rstream_config* stream_config) { + cras_rstream_config_init_with_message_called++; +} + +void cras_rstream_config_cleanup(struct cras_rstream_config* stream_config) {} + } // extern "C" diff --git a/cras/src/tests/cras_client_unittest.cc b/cras/src/tests/cras_client_unittest.cc index d70979e6..c1103afb 100644 --- a/cras/src/tests/cras_client_unittest.cc +++ b/cras/src/tests/cras_client_unittest.cc @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <stdio.h> #include <gtest/gtest.h> +#include <stdio.h> extern "C" { #include "cras_messages.h" @@ -20,10 +20,10 @@ static int pthread_cond_timedwait_called; static int pthread_cond_timedwait_retval; static int close_called; static int sendmsg_called; -static void *mmap_return_value; +static void* mmap_return_value; static int samples_ready_called; static int samples_ready_frames_value; -static uint8_t *samples_ready_samples_value; +static uint8_t* samples_ready_samples_value; static int pthread_create_returned_value; @@ -43,54 +43,56 @@ void InitStaticVariables() { } class CrasClientTestSuite : public testing::Test { - protected: - struct cras_audio_shm* InitShm() { - struct cras_audio_shm* shm = - static_cast<struct cras_audio_shm*>(calloc(1, sizeof(*shm))); - shm->header = - static_cast<cras_audio_shm_header*>(calloc(1, sizeof(*shm->header))); - cras_shm_set_frame_bytes(shm, 4); - cras_shm_set_used_size(shm, shm_writable_frames_ * 4); - memcpy(&shm->header->config, &shm->config, sizeof(shm->config)); - return shm; - } - - virtual void SetUp() { - shm_writable_frames_ = 100; - InitStaticVariables(); - - memset(&client_, 0, sizeof(client_)); - client_.server_fd_state = CRAS_SOCKET_STATE_CONNECTED; - memset(&stream_, 0, sizeof(stream_)); - stream_.id = FIRST_STREAM_ID; - - struct cras_stream_params* config = - static_cast<cras_stream_params*>(calloc(1, sizeof(*config))); - config->buffer_frames = 1024; - config->cb_threshold = 512; - stream_.config = config; + protected: + struct cras_audio_shm* InitShm() { + struct cras_audio_shm* shm = + static_cast<struct cras_audio_shm*>(calloc(1, sizeof(*shm))); + shm->header = + static_cast<cras_audio_shm_header*>(calloc(1, sizeof(*shm->header))); + cras_shm_set_frame_bytes(shm, 4); + uint32_t used_size = shm_writable_frames_ * 4; + cras_shm_set_used_size(shm, used_size); + shm->samples_info.length = used_size * 2; + memcpy(&shm->header->config, &shm->config, sizeof(shm->config)); + return shm; + } + + virtual void SetUp() { + shm_writable_frames_ = 100; + InitStaticVariables(); + + memset(&client_, 0, sizeof(client_)); + client_.server_fd_state = CRAS_SOCKET_STATE_CONNECTED; + memset(&stream_, 0, sizeof(stream_)); + stream_.id = FIRST_STREAM_ID; + + struct cras_stream_params* config = + static_cast<cras_stream_params*>(calloc(1, sizeof(*config))); + config->buffer_frames = 1024; + config->cb_threshold = 512; + stream_.config = config; + } + + virtual void TearDown() { + if (stream_.config) { + free(stream_.config); + stream_.config = NULL; } - virtual void TearDown() { - if (stream_.config) { - free(stream_.config); - stream_.config = NULL; - } - - if (stream_.shm) { - free(stream_.shm->header); - } - free(stream_.shm); - stream_.shm = NULL; + if (stream_.shm) { + free(stream_.shm->header); } + free(stream_.shm); + stream_.shm = NULL; + } - void StreamConnected(CRAS_STREAM_DIRECTION direction); + void StreamConnected(CRAS_STREAM_DIRECTION direction); - void StreamConnectedFail(CRAS_STREAM_DIRECTION direction); + void StreamConnectedFail(CRAS_STREAM_DIRECTION direction); - struct client_stream stream_; - struct cras_client client_; - int shm_writable_frames_; + struct client_stream stream_; + struct cras_client client_; + int shm_writable_frames_; }; void set_audio_format(struct cras_audio_format* format, @@ -186,13 +188,8 @@ void CrasClientTestSuite::StreamConnected(CRAS_STREAM_DIRECTION direction) { mmap_return_value = header; - cras_fill_client_stream_connected( - &msg, - 0, - stream_.id, - &server_format, - shm_max_size, - effects); + cras_fill_client_stream_connected(&msg, 0, stream_.id, &server_format, + shm_max_size, effects); stream_connected(&stream_, &msg, shm_fds, 2); @@ -208,9 +205,7 @@ TEST_F(CrasClientTestSuite, OutputStreamConnected) { StreamConnected(CRAS_STREAM_OUTPUT); } -void CrasClientTestSuite::StreamConnectedFail( - CRAS_STREAM_DIRECTION direction) { - +void CrasClientTestSuite::StreamConnectedFail(CRAS_STREAM_DIRECTION direction) { struct cras_client_stream_connected msg; int shm_fds[2] = {0, 1}; int shm_max_size = 600; @@ -239,18 +234,13 @@ void CrasClientTestSuite::StreamConnectedFail( mmap_return_value = &header; // Put an error in the message. - cras_fill_client_stream_connected( - &msg, - 1, - stream_.id, - &server_format, - shm_max_size, - effects); + cras_fill_client_stream_connected(&msg, 1, stream_.id, &server_format, + shm_max_size, effects); stream_connected(&stream_, &msg, shm_fds, 2); EXPECT_EQ(CRAS_THREAD_STOP, stream_.thread.state); - EXPECT_EQ(4, close_called); // close the pipefds and shm_fds + EXPECT_EQ(4, close_called); // close the pipefds and shm_fds } TEST_F(CrasClientTestSuite, InputStreamConnectedFail) { @@ -268,32 +258,32 @@ TEST_F(CrasClientTestSuite, AddAndRemoveStream) { int rc; // Dynamically allocate the stream so that it can be freed later. - struct client_stream* stream_ptr = (struct client_stream *) - malloc(sizeof(*stream_ptr)); + struct client_stream* stream_ptr = + (struct client_stream*)malloc(sizeof(*stream_ptr)); memcpy(stream_ptr, &stream_, sizeof(client_stream)); - stream_ptr->config = (struct cras_stream_params *) - malloc(sizeof(*(stream_ptr->config))); + stream_ptr->config = + (struct cras_stream_params*)malloc(sizeof(*(stream_ptr->config))); memcpy(stream_ptr->config, stream_.config, sizeof(*(stream_.config))); stream_ptr->wake_fds[0] = -1; stream_ptr->wake_fds[1] = -1; pthread_cond_timedwait_retval = ETIMEDOUT; - EXPECT_EQ(-ETIMEDOUT, client_thread_add_stream( - &client_, stream_ptr, &stream_id, NO_DEVICE)); + EXPECT_EQ(-ETIMEDOUT, client_thread_add_stream(&client_, stream_ptr, + &stream_id, NO_DEVICE)); EXPECT_EQ(pthread_cond_timedwait_called, 1); EXPECT_EQ(pthread_join_called, 0); InitStaticVariables(); - EXPECT_EQ(0, client_thread_add_stream( - &client_, stream_ptr, &stream_id, NO_DEVICE)); + EXPECT_EQ( + 0, client_thread_add_stream(&client_, stream_ptr, &stream_id, NO_DEVICE)); EXPECT_EQ(&client_, stream_ptr->client); EXPECT_EQ(stream_id, stream_ptr->id); EXPECT_EQ(pthread_create_called, 1); EXPECT_NE(-1, stream_ptr->wake_fds[0]); EXPECT_NE(-1, stream_ptr->wake_fds[1]); - EXPECT_EQ(1, sendmsg_called); // send connect message to server + EXPECT_EQ(1, sendmsg_called); // send connect message to server EXPECT_EQ(stream_ptr, stream_from_id(&client_, stream_id)); stream_ptr->thread.state = CRAS_THREAD_RUNNING; @@ -352,6 +342,7 @@ TEST(CrasClientTest, InitStreamVolume) { struct cras_client client; memset(&client, 0, sizeof(client)); + memset(&config, 0, sizeof(config)); client.server_fd_state = CRAS_SOCKET_STATE_CONNECTED; config.aud_cb = reinterpret_cast<cras_playback_cb_t>(0x123); @@ -367,7 +358,7 @@ TEST(CrasClientTest, InitStreamVolume) { rc = read(client.command_fds[0], &cmd_msg, sizeof(cmd_msg)); EXPECT_EQ(sizeof(cmd_msg), rc); - EXPECT_NE((void *)NULL, cmd_msg.stream); + EXPECT_NE((void*)NULL, cmd_msg.stream); EXPECT_EQ(1.0f, cmd_msg.stream->volume_scaler); @@ -376,9 +367,9 @@ TEST(CrasClientTest, InitStreamVolume) { free(cmd_msg.stream); } -} // namepsace +} // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } @@ -386,7 +377,7 @@ int main(int argc, char **argv) { /* stubs */ extern "C" { -ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags) { +ssize_t sendmsg(int sockfd, const struct msghdr* msg, int flags) { ++sendmsg_called; return msg->msg_iov->iov_len; } @@ -396,46 +387,46 @@ int close(int fd) { return 0; } -int pthread_create(pthread_t *thread, - const pthread_attr_t *attr, - void *(*start_routine)(void *), - void *arg) { +int pthread_create(pthread_t* thread, + const pthread_attr_t* attr, + void* (*start_routine)(void*), + void* arg) { ++pthread_create_called; return pthread_create_returned_value; } -int pthread_join(pthread_t thread, void **retval) { +int pthread_join(pthread_t thread, void** retval) { ++pthread_join_called; return 0; } -int pthread_cond_timedwait(pthread_cond_t *__restrict cond, - pthread_mutex_t *__restrict mutex, - const struct timespec *__restrict timeout) { +int pthread_cond_timedwait(pthread_cond_t* __restrict cond, + pthread_mutex_t* __restrict mutex, + const struct timespec* __restrict timeout) { ++pthread_cond_timedwait_called; return pthread_cond_timedwait_retval; } -int clock_gettime(clockid_t clk_id, struct timespec *tp) { +int clock_gettime(clockid_t clk_id, struct timespec* tp) { tp->tv_sec = 0; tp->tv_nsec = 0; return 0; } -void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) -{ +void* mmap(void* addr, + size_t length, + int prot, + int flags, + int fd, + off_t offset) { return mmap_return_value; } -struct cras_audio_format *cras_audio_format_create(snd_pcm_format_t format, +struct cras_audio_format* cras_audio_format_create(snd_pcm_format_t format, size_t frame_rate, - size_t num_channels) -{ + size_t num_channels) { return reinterpret_cast<struct cras_audio_format*>(0x123); } -void cras_audio_format_destroy(struct cras_audio_format *fmt) -{ -} - +void cras_audio_format_destroy(struct cras_audio_format* fmt) {} } diff --git a/cras/src/tests/cras_dsp_pipeline_unittest.cc b/cras/src/tests/cras_dsp_pipeline_unittest.cc index 21cbc10f..b6c733ac 100644 --- a/cras/src/tests/cras_dsp_pipeline_unittest.cc +++ b/cras/src/tests/cras_dsp_pipeline_unittest.cc @@ -2,24 +2,23 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "cras_dsp_pipeline.h" + #include <gtest/gtest.h> #include "cras_config.h" #include "cras_dsp_module.h" -#include "cras_dsp_pipeline.h" #define MAX_MODULES 10 #define MAX_MOCK_PORTS 30 #define FILENAME_TEMPLATE "DspIniTest.XXXXXX" -static void fill_test_data(int16_t *data, size_t size) -{ +static void fill_test_data(int16_t* data, size_t size) { for (size_t i = 0; i < size; i++) data[i] = i; } -static void verify_processed_data(int16_t *data, size_t size, int times) -{ +static void verify_processed_data(int16_t* data, size_t size, int times) { /* Each time the audio data flow through the mock plugin, the data * will be multiplied by 2 in module->run() below, so if there are n * plugins, the data will be multiplied by (1 << n). */ @@ -32,7 +31,7 @@ static void verify_processed_data(int16_t *data, size_t size, int times) } struct data { - const char *title; + const char* title; int nr_ports; port_direction port_dir[MAX_MOCK_PORTS]; int nr_in_audio; @@ -49,7 +48,7 @@ struct data { int sample_rate; int connect_port_called[MAX_MOCK_PORTS]; - float *data_location[MAX_MOCK_PORTS]; + float* data_location[MAX_MOCK_PORTS]; int run_called; float input[MAX_MOCK_PORTS]; @@ -63,25 +62,23 @@ struct data { int get_properties_called; }; -static int instantiate(struct dsp_module *module, unsigned long sample_rate) -{ - struct data *data = (struct data *)module->data; +static int instantiate(struct dsp_module* module, unsigned long sample_rate) { + struct data* data = (struct data*)module->data; data->instantiate_called++; data->sample_rate = sample_rate; return 0; } -static void connect_port(struct dsp_module *module, unsigned long port, - float *data_location) -{ - struct data *data = (struct data *)module->data; +static void connect_port(struct dsp_module* module, + unsigned long port, + float* data_location) { + struct data* data = (struct data*)module->data; data->connect_port_called[port]++; data->data_location[port] = data_location; } -static int get_delay(struct dsp_module *module) -{ - struct data *data = (struct data *)module->data; +static int get_delay(struct dsp_module* module) { + struct data* data = (struct data*)module->data; data->get_delay_called++; /* If the module title is "mN", then use N as the delay. */ @@ -90,9 +87,8 @@ static int get_delay(struct dsp_module *module) return delay; } -static void run(struct dsp_module *module, unsigned long sample_count) -{ - struct data *data = (struct data *)module->data; +static void run(struct dsp_module* module, unsigned long sample_count) { + struct data* data = (struct data*)module->data; data->run_called++; data->sample_count = sample_count; @@ -102,7 +98,8 @@ static void run(struct dsp_module *module, unsigned long sample_count) } /* copy the control port data */ - for (int i = 0; i < std::min(data->nr_in_control, data->nr_out_control); i++) { + for (int i = 0; i < std::min(data->nr_in_control, data->nr_out_control); + i++) { int from = data->in_control[i]; int to = data->out_control[i]; data->data_location[to][0] = data->data_location[from][0]; @@ -117,43 +114,38 @@ static void run(struct dsp_module *module, unsigned long sample_count) } } -static void deinstantiate(struct dsp_module *module) -{ - struct data *data = (struct data *)module->data; +static void deinstantiate(struct dsp_module* module) { + struct data* data = (struct data*)module->data; data->deinstantiate_called++; } -static void free_module(struct dsp_module *module) -{ - struct data *data = (struct data *)module->data; +static void free_module(struct dsp_module* module) { + struct data* data = (struct data*)module->data; data->free_module_called++; } -static void really_free_module(struct dsp_module *module) -{ - struct data *data = (struct data *)module->data; - free(data); - free(module); +static void really_free_module(struct dsp_module* module) { + struct data* data = (struct data*)module->data; + free(data); + free(module); } -static int get_properties(struct dsp_module *module) -{ - struct data *data = (struct data *)module->data; +static int get_properties(struct dsp_module* module) { + struct data* data = (struct data*)module->data; data->get_properties_called++; return data->properties; } -static void dump(struct dsp_module *module, struct dumper *d) {} +static void dump(struct dsp_module* module, struct dumper* d) {} -static struct dsp_module *create_mock_module(struct plugin *plugin) -{ - struct data *data; - struct dsp_module *module; +static struct dsp_module* create_mock_module(struct plugin* plugin) { + struct data* data; + struct dsp_module* module; - data = (struct data *)calloc(1, sizeof(struct data)); + data = (struct data*)calloc(1, sizeof(struct data)); data->title = plugin->title; data->nr_ports = ARRAY_COUNT(&plugin->ports); for (int i = 0; i < data->nr_ports; i++) { - struct port *port = ARRAY_ELEMENT(&plugin->ports, i); + struct port* port = ARRAY_ELEMENT(&plugin->ports, i); data->port_dir[i] = port->direction; if (port->direction == PORT_INPUT) { @@ -187,13 +179,12 @@ static struct dsp_module *create_mock_module(struct plugin *plugin) return module; } -static struct dsp_module *modules[MAX_MODULES]; -static struct dsp_module *cras_dsp_module_set_sink_ext_module_val; +static struct dsp_module* modules[MAX_MODULES]; +static struct dsp_module* cras_dsp_module_set_sink_ext_module_val; static int num_modules; -static struct dsp_module *find_module(const char *name) -{ +static struct dsp_module* find_module(const char* name) { for (int i = 0; i < num_modules; i++) { - struct data *data = (struct data *)modules[i]->data; + struct data* data = (struct data*)modules[i]->data; if (strcmp(name, data->title) == 0) return modules[i]; } @@ -201,19 +192,16 @@ static struct dsp_module *find_module(const char *name) } extern "C" { -struct dsp_module *cras_dsp_module_load_ladspa(struct plugin *plugin) -{ +struct dsp_module* cras_dsp_module_load_ladspa(struct plugin* plugin) { return NULL; } -struct dsp_module *cras_dsp_module_load_builtin(struct plugin *plugin) -{ - struct dsp_module *module = create_mock_module(plugin); +struct dsp_module* cras_dsp_module_load_builtin(struct plugin* plugin) { + struct dsp_module* module = create_mock_module(plugin); modules[num_modules++] = module; return module; } -void cras_dsp_module_set_sink_ext_module(struct dsp_module *module, - struct ext_dsp_module *ext_module) -{ +void cras_dsp_module_set_sink_ext_module(struct dsp_module* module, + struct ext_dsp_module* ext_module) { cras_dsp_module_set_sink_ext_module_val = module; } } @@ -224,7 +212,7 @@ class DspPipelineTestSuite : public testing::Test { protected: virtual void SetUp() { num_modules = 0; - strcpy(filename, FILENAME_TEMPLATE); + strcpy(filename, FILENAME_TEMPLATE); int fd = mkstemp(filename); fp = fdopen(fd, "w"); } @@ -242,12 +230,12 @@ class DspPipelineTestSuite : public testing::Test { } char filename[sizeof(FILENAME_TEMPLATE) + 1]; - FILE *fp; + FILE* fp; struct ext_dsp_module ext_mod; }; TEST_F(DspPipelineTestSuite, Simple) { - const char *content = + const char* content = "[M1]\n" "library=builtin\n" "label=source\n" @@ -266,23 +254,23 @@ TEST_F(DspPipelineTestSuite, Simple) { CloseFile(); struct cras_expr_env env = CRAS_EXPR_ENV_INIT; - struct ini *ini = cras_dsp_ini_create(filename); + struct ini* ini = cras_dsp_ini_create(filename); ASSERT_TRUE(ini); - struct pipeline *p = cras_dsp_pipeline_create(ini, &env, "capture"); + struct pipeline* p = cras_dsp_pipeline_create(ini, &env, "capture"); ASSERT_TRUE(p); ASSERT_EQ(0, cras_dsp_pipeline_load(p)); ASSERT_EQ(2, num_modules); - struct dsp_module *m1 = find_module("m1"); - struct dsp_module *m2 = find_module("m2"); + struct dsp_module* m1 = find_module("m1"); + struct dsp_module* m2 = find_module("m2"); ASSERT_TRUE(m1); ASSERT_TRUE(m2); ASSERT_EQ(1, cras_dsp_pipeline_get_num_input_channels(p)); ASSERT_EQ(0, cras_dsp_pipeline_instantiate(p, 48000)); - struct data *d1 = (struct data *)m1->data; - struct data *d2 = (struct data *)m2->data; + struct data* d1 = (struct data*)m1->data; + struct data* d2 = (struct data*)m2->data; /* check m1 */ ASSERT_STREQ("m1", d1->title); @@ -344,8 +332,7 @@ TEST_F(DspPipelineTestSuite, Simple) { /* Expect the sink module "m2" is set. */ cras_dsp_pipeline_set_sink_ext_module(p, &ext_mod); - struct data *d = (struct data *) - cras_dsp_module_set_sink_ext_module_val->data; + struct data* d = (struct data*)cras_dsp_module_set_sink_ext_module_val->data; ASSERT_STREQ("m2", d->title); cras_dsp_pipeline_deinstantiate(p); @@ -373,7 +360,7 @@ TEST_F(DspPipelineTestSuite, Complex) { * --(g)-- 6 --(h)-- */ - const char *content = + const char* content = "[M6]\n" "library=builtin\n" "label=foo\n" @@ -426,18 +413,18 @@ TEST_F(DspPipelineTestSuite, Complex) { cras_expr_env_set_variable_string(&env, "output_device", "HDMI"); cras_expr_env_set_variable_boolean(&env, "swap_lr_disabled", 1); - struct ini *ini = cras_dsp_ini_create(filename); + struct ini* ini = cras_dsp_ini_create(filename); ASSERT_TRUE(ini); - struct pipeline *p = cras_dsp_pipeline_create(ini, &env, "playback"); + struct pipeline* p = cras_dsp_pipeline_create(ini, &env, "playback"); ASSERT_TRUE(p); ASSERT_EQ(0, cras_dsp_pipeline_load(p)); - ASSERT_EQ(5, num_modules); /* one not connected, one disabled */ - struct dsp_module *m0 = find_module("m0"); - struct dsp_module *m1 = find_module("m1"); - struct dsp_module *m2 = find_module("m2"); - struct dsp_module *m3 = find_module("m3"); - struct dsp_module *m5 = find_module("m5"); + ASSERT_EQ(5, num_modules); /* one not connected, one disabled */ + struct dsp_module* m0 = find_module("m0"); + struct dsp_module* m1 = find_module("m1"); + struct dsp_module* m2 = find_module("m2"); + struct dsp_module* m3 = find_module("m3"); + struct dsp_module* m5 = find_module("m5"); ASSERT_TRUE(m0); ASSERT_TRUE(m1); @@ -450,11 +437,11 @@ TEST_F(DspPipelineTestSuite, Complex) { ASSERT_EQ(2, cras_dsp_pipeline_get_num_input_channels(p)); ASSERT_EQ(0, cras_dsp_pipeline_instantiate(p, 48000)); - struct data *d0 = (struct data *)m0->data; - struct data *d1 = (struct data *)m1->data; - struct data *d2 = (struct data *)m2->data; - struct data *d3 = (struct data *)m3->data; - struct data *d5 = (struct data *)m5->data; + struct data* d0 = (struct data*)m0->data; + struct data* d1 = (struct data*)m1->data; + struct data* d2 = (struct data*)m2->data; + struct data* d3 = (struct data*)m3->data; + struct data* d5 = (struct data*)m5->data; /* * / --(b)-- 2 --(c)-- \ @@ -476,7 +463,7 @@ TEST_F(DspPipelineTestSuite, Complex) { /* need 3 buffers because m2 has inplace-broken flag */ ASSERT_EQ(3, cras_dsp_pipeline_get_peak_audio_buffers(p)); - int16_t *samples = new int16_t[DSP_BUFFER_SIZE]; + int16_t* samples = new int16_t[DSP_BUFFER_SIZE]; fill_test_data(samples, DSP_BUFFER_SIZE); cras_dsp_pipeline_apply(p, (uint8_t*)samples, SND_PCM_FORMAT_S16_LE, 100); /* the data flow through 2 plugins because m4 is disabled. */ @@ -492,8 +479,7 @@ TEST_F(DspPipelineTestSuite, Complex) { /* Expect the sink module "m5" is set. */ cras_dsp_pipeline_set_sink_ext_module(p, &ext_mod); - struct data *d = (struct data *) - cras_dsp_module_set_sink_ext_module_val->data; + struct data* d = (struct data*)cras_dsp_module_set_sink_ext_module_val->data; ASSERT_STREQ("m5", d->title); /* re-instantiate */ @@ -526,7 +512,7 @@ TEST_F(DspPipelineTestSuite, Complex) { } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/cras_selinux_helper_unittest.c b/cras/src/tests/cras_selinux_helper_unittest.c index 0e7efad6..64fce142 100644 --- a/cras/src/tests/cras_selinux_helper_unittest.c +++ b/cras/src/tests/cras_selinux_helper_unittest.c @@ -6,5 +6,5 @@ /* Define a stub cras_selinux_restorecon() which doesn't do anything */ int cras_selinux_restorecon(const char* pathname) { - return 0; + return 0; } diff --git a/cras/src/tests/cras_tm_unittest.cc b/cras/src/tests/cras_tm_unittest.cc index a2cc80a3..3f5521eb 100644 --- a/cras/src/tests/cras_tm_unittest.cc +++ b/cras/src/tests/cras_tm_unittest.cc @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <stdio.h> #include <gtest/gtest.h> +#include <stdio.h> extern "C" { #include "cras_tm.h" @@ -12,29 +12,27 @@ extern "C" { namespace { -class TimerTestSuite : public testing::Test{ - protected: - virtual void SetUp() { - tm_ = cras_tm_init(); - ASSERT_TRUE(tm_); - } +class TimerTestSuite : public testing::Test { + protected: + virtual void SetUp() { + tm_ = cras_tm_init(); + ASSERT_TRUE(tm_); + } - virtual void TearDown() { - cras_tm_deinit(tm_); - } + virtual void TearDown() { cras_tm_deinit(tm_); } - struct cras_tm *tm_; + struct cras_tm* tm_; }; static struct timespec time_now; static unsigned int test_cb_called; static unsigned int test_cb2_called; -void test_cb(struct cras_timer *t, void *data) { +void test_cb(struct cras_timer* t, void* data) { test_cb_called++; } -void test_cb2(struct cras_timer *t, void *data) { +void test_cb2(struct cras_timer* t, void* data) { test_cb2_called++; } @@ -47,7 +45,7 @@ TEST_F(TimerTestSuite, InitNoTimers) { } TEST_F(TimerTestSuite, AddTimer) { - struct cras_timer *t; + struct cras_timer* t; t = cras_tm_create_timer(tm_, 10, test_cb, this); EXPECT_TRUE(t); @@ -55,7 +53,7 @@ TEST_F(TimerTestSuite, AddTimer) { TEST_F(TimerTestSuite, AddLongTimer) { struct timespec ts; - struct cras_timer *t; + struct cras_timer* t; int timers_active; time_now.tv_sec = 0; @@ -83,7 +81,7 @@ TEST_F(TimerTestSuite, AddLongTimer) { TEST_F(TimerTestSuite, AddRemoveTimer) { struct timespec ts; - struct cras_timer *t; + struct cras_timer* t; int timers_active; time_now.tv_sec = 0; @@ -185,7 +183,7 @@ TEST_F(TimerTestSuite, AddTwoTimers) { /* Stubs */ extern "C" { -int clock_gettime(clockid_t clk_id, struct timespec *tp) { +int clock_gettime(clockid_t clk_id, struct timespec* tp) { *tp = time_now; return 0; } @@ -194,7 +192,7 @@ int clock_gettime(clockid_t clk_id, struct timespec *tp) { } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/dbus_test.cc b/cras/src/tests/dbus_test.cc index f3e5b17e..b435825d 100644 --- a/cras/src/tests/dbus_test.cc +++ b/cras/src/tests/dbus_test.cc @@ -2,13 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <algorithm> +#include "dbus_test.h" -#include <sys/select.h> #include <stdlib.h> +#include <sys/select.h> #include <unistd.h> -#include "dbus_test.h" +#include <algorithm> namespace { @@ -22,9 +22,7 @@ DBusMatch::DBusMatch() send_reply_(false), send_error_(false), expect_serial_(false), - matched_(false) { - -} + matched_(false) {} DBusMatch& DBusMatch::WithString(std::string value) { Arg arg; @@ -104,7 +102,6 @@ DBusMatch& DBusMatch::AsPropertyDictionary() { return *this; } - DBusMatch& DBusMatch::SendReply() { send_reply_ = true; expect_serial_ = true; @@ -126,18 +123,14 @@ DBusMatch& DBusMatch::SendReplyNoWait() { return *this; } - DBusMatch& DBusMatch::Send() { - DBusMessage *message; + DBusMessage* message; if (message_type_ == DBUS_MESSAGE_TYPE_SIGNAL) - message = dbus_message_new_signal(path_.c_str(), - interface_.c_str(), + message = dbus_message_new_signal(path_.c_str(), interface_.c_str(), member_.c_str()); else if (message_type_ == DBUS_MESSAGE_TYPE_METHOD_CALL) - message = dbus_message_new_method_call(NULL, - path_.c_str(), - interface_.c_str(), - member_.c_str()); + message = dbus_message_new_method_call(NULL, path_.c_str(), + interface_.c_str(), member_.c_str()); else return *this; @@ -149,7 +142,6 @@ DBusMatch& DBusMatch::Send() { return *this; } - void DBusMatch::ExpectMethodCall(std::string path, std::string interface, std::string method) { @@ -159,8 +151,7 @@ void DBusMatch::ExpectMethodCall(std::string path, member_ = method; } - -void DBusMatch::CreateSignal(DBusConnection *conn, +void DBusMatch::CreateSignal(DBusConnection* conn, std::string path, std::string interface, std::string signal_name) { @@ -174,7 +165,7 @@ void DBusMatch::CreateSignal(DBusConnection *conn, matched_ = true; } -void DBusMatch::CreateMessageCall(DBusConnection *conn, +void DBusMatch::CreateMessageCall(DBusConnection* conn, std::string path, std::string interface, std::string method_name) { @@ -188,22 +179,18 @@ void DBusMatch::CreateMessageCall(DBusConnection *conn, matched_ = true; } - -bool DBusMatch::MatchMessageArgs(DBusMessage *message, - std::vector<Arg> *args) -{ +bool DBusMatch::MatchMessageArgs(DBusMessage* message, std::vector<Arg>* args) { DBusMessageIter iter; dbus_message_iter_init(message, &iter); for (std::vector<Arg>::iterator it = args->begin(); it != args->end(); ++it) { - Arg &arg = *it; + Arg& arg = *it; int type = dbus_message_iter_get_arg_type(&iter); if (type != arg.type) return false; - if (arg.type == DBUS_TYPE_STRING - || arg.type == DBUS_TYPE_OBJECT_PATH) { - const char *str_value; + if (arg.type == DBUS_TYPE_STRING || arg.type == DBUS_TYPE_OBJECT_PATH) { + const char* str_value; dbus_message_iter_get_basic(&iter, &str_value); if (strcmp(str_value, arg.string_value.c_str()) != 0) return false; @@ -216,9 +203,8 @@ bool DBusMatch::MatchMessageArgs(DBusMessage *message, return true; } -void DBusMatch::AppendArgsToMessage(DBusMessage *message, - std::vector<Arg> *args) -{ +void DBusMatch::AppendArgsToMessage(DBusMessage* message, + std::vector<Arg>* args) { DBusMessageIter message_iter; DBusMessageIter dict_array_iter; DBusMessageIter struct_iter; @@ -226,22 +212,20 @@ void DBusMatch::AppendArgsToMessage(DBusMessage *message, if (as_property_dictionary_) { dbus_message_iter_init_append(message, &message_iter); - dbus_message_iter_open_container(&message_iter, - DBUS_TYPE_ARRAY, "{sv}", + dbus_message_iter_open_container(&message_iter, DBUS_TYPE_ARRAY, "{sv}", &dict_array_iter); } else { dbus_message_iter_init_append(message, &iter); } for (std::vector<Arg>::iterator it = args->begin(); it != args->end(); ++it) { - Arg &arg = *it; + Arg& arg = *it; if (as_property_dictionary_) { - dbus_message_iter_open_container(&dict_array_iter, - DBUS_TYPE_DICT_ENTRY, NULL, - &struct_iter); + dbus_message_iter_open_container(&dict_array_iter, DBUS_TYPE_DICT_ENTRY, + NULL, &struct_iter); - const char *str_value = arg.string_value.c_str(); + const char* str_value = arg.string_value.c_str(); dbus_message_iter_append_basic(&struct_iter, arg.type, &str_value); arg = *(++it); @@ -267,24 +251,21 @@ void DBusMatch::AppendArgsToMessage(DBusMessage *message, } if (as_property_dictionary_) { - dbus_message_iter_open_container(&struct_iter, - DBUS_TYPE_VARIANT, + dbus_message_iter_open_container(&struct_iter, DBUS_TYPE_VARIANT, arg.array ? array_type : element_type, &iter); } DBusMessageIter array_iter; if (arg.array) { - dbus_message_iter_open_container(&iter, - DBUS_TYPE_ARRAY, element_type, + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, element_type, &array_iter); - if (arg.type == DBUS_TYPE_STRING - || arg.type == DBUS_TYPE_OBJECT_PATH) { + if (arg.type == DBUS_TYPE_STRING || arg.type == DBUS_TYPE_OBJECT_PATH) { for (std::vector<std::string>::const_iterator vit = - arg.string_values.begin(); vit != arg.string_values.end(); - ++vit) { - const char *str_value = vit->c_str(); + arg.string_values.begin(); + vit != arg.string_values.end(); ++vit) { + const char* str_value = vit->c_str(); dbus_message_iter_append_basic(&array_iter, arg.type, &str_value); } } @@ -292,9 +273,8 @@ void DBusMatch::AppendArgsToMessage(DBusMessage *message, dbus_message_iter_close_container(&iter, &array_iter); } else { - if (arg.type == DBUS_TYPE_STRING - || arg.type == DBUS_TYPE_OBJECT_PATH) { - const char *str_value = arg.string_value.c_str(); + if (arg.type == DBUS_TYPE_STRING || arg.type == DBUS_TYPE_OBJECT_PATH) { + const char* str_value = arg.string_value.c_str(); dbus_message_iter_append_basic(&iter, arg.type, &str_value); } else if (arg.type == DBUS_TYPE_UNIX_FD) { dbus_message_iter_append_basic(&iter, arg.type, &arg.int_value); @@ -312,7 +292,7 @@ void DBusMatch::AppendArgsToMessage(DBusMessage *message, dbus_message_iter_close_container(&message_iter, &dict_array_iter); } -void DBusMatch::SendMessage(DBusConnection *conn, DBusMessage *message) { +void DBusMatch::SendMessage(DBusConnection* conn, DBusMessage* message) { dbus_bool_t success; dbus_uint32_t serial; success = dbus_connection_send(conn, message, &serial); @@ -321,17 +301,16 @@ void DBusMatch::SendMessage(DBusConnection *conn, DBusMessage *message) { expected_serials_.push_back(serial); } - -bool DBusMatch::HandleServerMessage(DBusConnection *conn, - DBusMessage *message) { +bool DBusMatch::HandleServerMessage(DBusConnection* conn, + DBusMessage* message) { // Make sure we're expecting a method call or signal of this name if (message_type_ == DBUS_MESSAGE_TYPE_METHOD_CALL && - !dbus_message_is_method_call(message, - interface_.c_str(), member_.c_str())) + !dbus_message_is_method_call(message, interface_.c_str(), + member_.c_str())) return false; else if (message_type_ == DBUS_MESSAGE_TYPE_SIGNAL && - !dbus_message_is_signal(message, - interface_.c_str(), member_.c_str())) + !dbus_message_is_signal(message, interface_.c_str(), + member_.c_str())) return false; // Make sure the path is what we expected. @@ -347,12 +326,11 @@ bool DBusMatch::HandleServerMessage(DBusConnection *conn, matched_ = true; if (send_reply_ || send_error_) { // Send out the reply - DBusMessage *reply = NULL; + DBusMessage* reply = NULL; if (send_reply_) reply = dbus_message_new_method_return(message); else if (send_error_) - reply = dbus_message_new_error(message, - error_name_.c_str(), + reply = dbus_message_new_error(message, error_name_.c_str(), error_message_.c_str()); AppendArgsToMessage(reply, &reply_args_); @@ -364,8 +342,8 @@ bool DBusMatch::HandleServerMessage(DBusConnection *conn, return true; } -bool DBusMatch::HandleClientMessage(DBusConnection *conn, - DBusMessage *message) { +bool DBusMatch::HandleClientMessage(DBusConnection* conn, + DBusMessage* message) { // From the client side we check whether the message has a serial number // we generated on our server side, and if so, remove it from the list of // those we're expecting to see. @@ -384,17 +362,10 @@ bool DBusMatch::Complete() { return matched_ && expected_serials_.size() == 0; } - DBusTest::DBusTest() - : conn_(NULL), - server_(NULL), - server_conn_(NULL), - dispatch_(false) { -} - -DBusTest::~DBusTest() { -} + : conn_(NULL), server_(NULL), server_conn_(NULL), dispatch_(false) {} +DBusTest::~DBusTest() {} DBusMatch& DBusTest::ExpectMethodCall(std::string path, std::string interface, @@ -403,12 +374,11 @@ DBusMatch& DBusTest::ExpectMethodCall(std::string path, match.ExpectMethodCall(path, interface, method); pthread_mutex_lock(&mutex_); matches_.push_back(match); - DBusMatch &ref = matches_.back(); + DBusMatch& ref = matches_.back(); pthread_mutex_unlock(&mutex_); return ref; } - DBusMatch& DBusTest::CreateSignal(std::string path, std::string interface, std::string signal_name) { @@ -416,7 +386,7 @@ DBusMatch& DBusTest::CreateSignal(std::string path, match.CreateSignal(server_conn_, path, interface, signal_name); pthread_mutex_lock(&mutex_); matches_.push_back(match); - DBusMatch &ref = matches_.back(); + DBusMatch& ref = matches_.back(); pthread_mutex_unlock(&mutex_); return ref; } @@ -428,19 +398,18 @@ DBusMatch& DBusTest::CreateMessageCall(std::string path, match.CreateMessageCall(server_conn_, path, interface, signal_name); pthread_mutex_lock(&mutex_); matches_.push_back(match); - DBusMatch &ref = matches_.back(); + DBusMatch& ref = matches_.back(); pthread_mutex_unlock(&mutex_); return ref; } - void DBusTest::WaitForMatches() { for (;;) { pthread_mutex_lock(&mutex_); size_t incomplete_matches = 0; for (std::vector<DBusMatch>::iterator it = matches_.begin(); it != matches_.end(); ++it) { - DBusMatch &match = *it; + DBusMatch& match = *it; if (!match.Complete()) ++incomplete_matches; } @@ -450,7 +419,7 @@ void DBusTest::WaitForMatches() { break; // Fish a message from the queue. - DBusMessage *message; + DBusMessage* message; while ((message = dbus_connection_borrow_message(conn_)) == NULL) dbus_connection_read_write(conn_, -1); @@ -458,10 +427,10 @@ void DBusTest::WaitForMatches() { pthread_mutex_lock(&mutex_); for (std::vector<DBusMatch>::iterator it = matches_.begin(); it != matches_.end(); ++it) { - DBusMatch &match = *it; + DBusMatch& match = *it; if (match.HandleClientMessage(conn_, message)) - break; + break; } pthread_mutex_unlock(&mutex_); @@ -475,7 +444,6 @@ void DBusTest::WaitForMatches() { pthread_mutex_unlock(&mutex_); } - void DBusTest::SetUp() { dbus_threads_init_default(); @@ -484,22 +452,17 @@ void DBusTest::SetUp() { server_ = dbus_server_listen(kServerAddress, NULL); ASSERT_TRUE(server_ != NULL); - dbus_server_set_new_connection_function(server_, NewConnectionThunk, - this, NULL); + dbus_server_set_new_connection_function(server_, NewConnectionThunk, this, + NULL); dbus_bool_t success; - success = dbus_server_set_watch_functions(server_, - AddWatchThunk, - RemoveWatchThunk, - WatchToggledThunk, - this, NULL); + success = dbus_server_set_watch_functions( + server_, AddWatchThunk, RemoveWatchThunk, WatchToggledThunk, this, NULL); ASSERT_TRUE(success); - success = dbus_server_set_timeout_functions(server_, - AddTimeoutThunk, + success = dbus_server_set_timeout_functions(server_, AddTimeoutThunk, RemoveTimeoutThunk, - TimeoutToggledThunk, - this, NULL); + TimeoutToggledThunk, this, NULL); ASSERT_TRUE(success); // Open a connection to our server, this returns the "client" side of the @@ -555,109 +518,100 @@ void DBusTest::TearDown() { dbus_shutdown(); } -void DBusTest::NewConnectionThunk(DBusServer *server, - DBusConnection *conn, - void *data) { - DBusTest *test = static_cast<DBusTest *>(data); +void DBusTest::NewConnectionThunk(DBusServer* server, + DBusConnection* conn, + void* data) { + DBusTest* test = static_cast<DBusTest*>(data); test->NewConnection(server, conn); } -void DBusTest::NewConnection(DBusServer *server, DBusConnection *conn) { +void DBusTest::NewConnection(DBusServer* server, DBusConnection* conn) { ASSERT_TRUE(server_conn_ == NULL); dbus_bool_t success; - success = dbus_connection_set_watch_functions(conn, - AddWatchThunk, - RemoveWatchThunk, - WatchToggledThunk, - this, NULL); + success = dbus_connection_set_watch_functions( + conn, AddWatchThunk, RemoveWatchThunk, WatchToggledThunk, this, NULL); ASSERT_TRUE(success); - success = dbus_connection_set_timeout_functions(conn, - AddTimeoutThunk, - RemoveTimeoutThunk, - TimeoutToggledThunk, - this, NULL); + success = dbus_connection_set_timeout_functions( + conn, AddTimeoutThunk, RemoveTimeoutThunk, TimeoutToggledThunk, this, + NULL); ASSERT_TRUE(success); - success = dbus_connection_add_filter(conn, - HandleMessageThunk, - this, NULL); + success = dbus_connection_add_filter(conn, HandleMessageThunk, this, NULL); ASSERT_TRUE(success); server_conn_ = conn; dbus_connection_ref(server_conn_); } -dbus_bool_t DBusTest::AddWatchThunk(DBusWatch *watch, void *data) { - DBusTest *test = static_cast<DBusTest *>(data); +dbus_bool_t DBusTest::AddWatchThunk(DBusWatch* watch, void* data) { + DBusTest* test = static_cast<DBusTest*>(data); return test->AddWatch(watch); } -dbus_bool_t DBusTest::AddWatch(DBusWatch *watch) { +dbus_bool_t DBusTest::AddWatch(DBusWatch* watch) { watches_.push_back(watch); return TRUE; } -void DBusTest::RemoveWatchThunk(DBusWatch *watch, void *data) { - DBusTest *test = static_cast<DBusTest *>(data); +void DBusTest::RemoveWatchThunk(DBusWatch* watch, void* data) { + DBusTest* test = static_cast<DBusTest*>(data); test->RemoveWatch(watch); } -void DBusTest::RemoveWatch(DBusWatch *watch) { - std::vector<DBusWatch *>::iterator it = +void DBusTest::RemoveWatch(DBusWatch* watch) { + std::vector<DBusWatch*>::iterator it = find(watches_.begin(), watches_.end(), watch); if (it != watches_.end()) watches_.erase(it); } -void DBusTest::WatchToggledThunk(DBusWatch *watch, void *data) { - DBusTest *test = static_cast<DBusTest *>(data); +void DBusTest::WatchToggledThunk(DBusWatch* watch, void* data) { + DBusTest* test = static_cast<DBusTest*>(data); test->WatchToggled(watch); } -void DBusTest::WatchToggled(DBusWatch *watch) { -} +void DBusTest::WatchToggled(DBusWatch* watch) {} -dbus_bool_t DBusTest::AddTimeoutThunk(DBusTimeout *timeout, void *data) { - DBusTest *test = static_cast<DBusTest *>(data); +dbus_bool_t DBusTest::AddTimeoutThunk(DBusTimeout* timeout, void* data) { + DBusTest* test = static_cast<DBusTest*>(data); return test->AddTimeout(timeout); } -dbus_bool_t DBusTest::AddTimeout(DBusTimeout *timeout) { +dbus_bool_t DBusTest::AddTimeout(DBusTimeout* timeout) { timeouts_.push_back(timeout); return TRUE; } -void DBusTest::RemoveTimeoutThunk(DBusTimeout *timeout, void *data) { - DBusTest *test = static_cast<DBusTest *>(data); +void DBusTest::RemoveTimeoutThunk(DBusTimeout* timeout, void* data) { + DBusTest* test = static_cast<DBusTest*>(data); test->RemoveTimeout(timeout); } -void DBusTest::RemoveTimeout(DBusTimeout *timeout) { - std::vector<DBusTimeout *>::iterator it = +void DBusTest::RemoveTimeout(DBusTimeout* timeout) { + std::vector<DBusTimeout*>::iterator it = find(timeouts_.begin(), timeouts_.end(), timeout); if (it != timeouts_.end()) timeouts_.erase(it); } -void DBusTest::TimeoutToggledThunk(DBusTimeout *timeout, void *data) { - DBusTest *test = static_cast<DBusTest *>(data); +void DBusTest::TimeoutToggledThunk(DBusTimeout* timeout, void* data) { + DBusTest* test = static_cast<DBusTest*>(data); test->TimeoutToggled(timeout); } -void DBusTest::TimeoutToggled(DBusTimeout *timeout) { -} +void DBusTest::TimeoutToggled(DBusTimeout* timeout) {} -DBusHandlerResult DBusTest::HandleMessageThunk(DBusConnection *conn, - DBusMessage *message, - void *data) { - DBusTest *test = static_cast<DBusTest *>(data); +DBusHandlerResult DBusTest::HandleMessageThunk(DBusConnection* conn, + DBusMessage* message, + void* data) { + DBusTest* test = static_cast<DBusTest*>(data); return test->HandleMessage(conn, message); } -DBusHandlerResult DBusTest::HandleMessage(DBusConnection *conn, - DBusMessage *message) { +DBusHandlerResult DBusTest::HandleMessage(DBusConnection* conn, + DBusMessage* message) { if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconnected")) { dispatch_ = false; return DBUS_HANDLER_RESULT_HANDLED; @@ -666,7 +620,7 @@ DBusHandlerResult DBusTest::HandleMessage(DBusConnection *conn, pthread_mutex_lock(&mutex_); for (std::vector<DBusMatch>::iterator it = matches_.begin(); it != matches_.end(); ++it) { - DBusMatch &match = *it; + DBusMatch& match = *it; if (match.HandleServerMessage(conn, message)) { pthread_mutex_unlock(&mutex_); @@ -678,13 +632,12 @@ DBusHandlerResult DBusTest::HandleMessage(DBusConnection *conn, return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } - -void *DBusTest::DispatchLoopThunk(void *ptr) { - DBusTest *test = static_cast<DBusTest *>(ptr); +void* DBusTest::DispatchLoopThunk(void* ptr) { + DBusTest* test = static_cast<DBusTest*>(ptr); return test->DispatchLoop(); } -void *DBusTest::DispatchLoop() { +void* DBusTest::DispatchLoop() { while (dispatch_) DispatchOnce(); @@ -702,9 +655,9 @@ void DBusTest::DispatchOnce() { FD_ZERO(&readfds); FD_ZERO(&writefds); - for (std::vector<DBusWatch *>::iterator it = watches_.begin(); + for (std::vector<DBusWatch*>::iterator it = watches_.begin(); it != watches_.end(); ++it) { - DBusWatch *watch = *it; + DBusWatch* watch = *it; if (!dbus_watch_get_enabled(watch)) continue; @@ -724,12 +677,12 @@ void DBusTest::DispatchOnce() { // isn't quite right according to the D-Bus spec, since the interval is // supposed to be since the time the timeout was added or toggled, but // it's good enough for the purposes of testing. - DBusTimeout *earliest_timeout = NULL; + DBusTimeout* earliest_timeout = NULL; struct timeval timeval; - for (std::vector<DBusTimeout *>::iterator it = timeouts_.begin(); + for (std::vector<DBusTimeout*>::iterator it = timeouts_.begin(); it != timeouts_.end(); ++it) { - DBusTimeout *timeout = *it; + DBusTimeout* timeout = *it; if (!dbus_timeout_get_enabled(timeout)) continue; @@ -757,10 +710,10 @@ void DBusTest::DispatchOnce() { // Handle the watches, use a copy of the vector since a watch handler // might remove other watches in the vector. - std::vector<DBusWatch *> immutable_watches = watches_; - for (std::vector<DBusWatch *>::iterator it = immutable_watches.begin(); + std::vector<DBusWatch*> immutable_watches = watches_; + for (std::vector<DBusWatch*>::iterator it = immutable_watches.begin(); it != immutable_watches.end(); ++it) { - DBusWatch *watch = *it; + DBusWatch* watch = *it; int fd = dbus_watch_get_unix_fd(watch); unsigned int flags = 0; diff --git a/cras/src/tests/dbus_test.h b/cras/src/tests/dbus_test.h index 1a738b6d..d266037b 100644 --- a/cras/src/tests/dbus_test.h +++ b/cras/src/tests/dbus_test.h @@ -6,13 +6,13 @@ #ifndef CRAS_DBUS_TEST_H_ #define CRAS_DBUS_TEST_H_ -#include <string> -#include <vector> - -#include <stdint.h> #include <dbus/dbus.h> #include <gtest/gtest.h> #include <pthread.h> +#include <stdint.h> + +#include <string> +#include <vector> /* DBusTest, and the related DBusMatch class, are used to provide a * GMock-like experience for testing D-Bus code within cras. @@ -187,31 +187,34 @@ class DBusMatch { // Methods used by DBusTest after constructing the DBusMatch instance // to set the type of match. - void ExpectMethodCall(std::string path, std::string interface, + void ExpectMethodCall(std::string path, + std::string interface, std::string method); - void CreateSignal(DBusConnection *conn, - std::string path, std::string interface, + void CreateSignal(DBusConnection* conn, + std::string path, + std::string interface, std::string signal_name); - void CreateMessageCall(DBusConnection *conn, - std::string path, std::string interface, + void CreateMessageCall(DBusConnection* conn, + std::string path, + std::string interface, std::string signal_name); // Determine whether a message matches a set of arguments. - bool MatchMessageArgs(DBusMessage *message, std::vector<Arg> *args); + bool MatchMessageArgs(DBusMessage* message, std::vector<Arg>* args); // Append a set of arguments to a message. - void AppendArgsToMessage(DBusMessage *message, std::vector<Arg> *args); + void AppendArgsToMessage(DBusMessage* message, std::vector<Arg>* args); // Send a message on a connection. - void SendMessage(DBusConnection *conn, DBusMessage *message); + void SendMessage(DBusConnection* conn, DBusMessage* message); // Handle a message received by the server connection. - bool HandleServerMessage(DBusConnection *conn, DBusMessage *message); + bool HandleServerMessage(DBusConnection* conn, DBusMessage* message); // Handle a message received by the client connection. - bool HandleClientMessage(DBusConnection *conn, DBusMessage *message); + bool HandleClientMessage(DBusConnection* conn, DBusMessage* message); // Verify whether the match is complete. bool Complete(); @@ -224,7 +227,7 @@ class DBusMatch { bool as_property_dictionary_; std::vector<Arg> args_; - DBusConnection *conn_; + DBusConnection* conn_; bool send_reply_; std::vector<Arg> reply_args_; @@ -247,18 +250,21 @@ class DBusTest : public ::testing::Test { protected: // Connection to the D-Bus server, this may be used during tests as the // "bus" connection, all messages go to and from the internal D-Bus server. - DBusConnection *conn_; + DBusConnection* conn_; // Expect a method call to be received by the server. - DBusMatch& ExpectMethodCall(std::string path, std::string interface, + DBusMatch& ExpectMethodCall(std::string path, + std::string interface, std::string method); // Send a signal from the client to the server. - DBusMatch& CreateSignal(std::string path, std::string interface, + DBusMatch& CreateSignal(std::string path, + std::string interface, std::string signal_name); // Send a message from the client to the server. - DBusMatch& CreateMessageCall(std::string path, std::string interface, + DBusMatch& CreateMessageCall(std::string path, + std::string interface, std::string signal_name); // Wait for all matches created by Expect*() or Create*() methods to @@ -271,11 +277,11 @@ class DBusTest : public ::testing::Test { virtual void TearDown(); private: - DBusServer *server_; - DBusConnection *server_conn_; + DBusServer* server_; + DBusConnection* server_conn_; - std::vector<DBusWatch *> watches_; - std::vector<DBusTimeout *> timeouts_; + std::vector<DBusWatch*> watches_; + std::vector<DBusTimeout*> timeouts_; pthread_t thread_id_; pthread_mutex_t mutex_; @@ -283,36 +289,37 @@ class DBusTest : public ::testing::Test { std::vector<DBusMatch> matches_; - static void NewConnectionThunk(DBusServer *server, DBusConnection *conn, - void *data); - void NewConnection(DBusServer *server, DBusConnection *conn); + static void NewConnectionThunk(DBusServer* server, + DBusConnection* conn, + void* data); + void NewConnection(DBusServer* server, DBusConnection* conn); - static dbus_bool_t AddWatchThunk(DBusWatch *watch, void *data); - dbus_bool_t AddWatch(DBusWatch *watch); + static dbus_bool_t AddWatchThunk(DBusWatch* watch, void* data); + dbus_bool_t AddWatch(DBusWatch* watch); - static void RemoveWatchThunk(DBusWatch *watch, void *data); - void RemoveWatch(DBusWatch *watch); + static void RemoveWatchThunk(DBusWatch* watch, void* data); + void RemoveWatch(DBusWatch* watch); - static void WatchToggledThunk(DBusWatch *watch, void *data); - void WatchToggled(DBusWatch *watch); + static void WatchToggledThunk(DBusWatch* watch, void* data); + void WatchToggled(DBusWatch* watch); - static dbus_bool_t AddTimeoutThunk(DBusTimeout *timeout, void *data); - dbus_bool_t AddTimeout(DBusTimeout *timeout); + static dbus_bool_t AddTimeoutThunk(DBusTimeout* timeout, void* data); + dbus_bool_t AddTimeout(DBusTimeout* timeout); - static void RemoveTimeoutThunk(DBusTimeout *timeout, void *data); - void RemoveTimeout(DBusTimeout *timeout); + static void RemoveTimeoutThunk(DBusTimeout* timeout, void* data); + void RemoveTimeout(DBusTimeout* timeout); - static void TimeoutToggledThunk(DBusTimeout *timeout, void *data); - void TimeoutToggled(DBusTimeout *timeout); + static void TimeoutToggledThunk(DBusTimeout* timeout, void* data); + void TimeoutToggled(DBusTimeout* timeout); - static DBusHandlerResult HandleMessageThunk(DBusConnection *conn, - DBusMessage *message, void *data); - DBusHandlerResult HandleMessage(DBusConnection *conn, DBusMessage *message); + static DBusHandlerResult HandleMessageThunk(DBusConnection* conn, + DBusMessage* message, + void* data); + DBusHandlerResult HandleMessage(DBusConnection* conn, DBusMessage* message); - static void *DispatchLoopThunk(void *ptr); - void *DispatchLoop(); + static void* DispatchLoopThunk(void* ptr); + void* DispatchLoop(); void DispatchOnce(); }; - #endif /* CRAS_DBUS_TEST_H_ */ diff --git a/cras/src/tests/dev_io_stubs.cc b/cras/src/tests/dev_io_stubs.cc index 73031da1..b74162b8 100644 --- a/cras/src/tests/dev_io_stubs.cc +++ b/cras/src/tests/dev_io_stubs.cc @@ -2,18 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <algorithm> -#include <memory> #include <stdint.h> #include <stdio.h> #include <time.h> +#include <algorithm> +#include <memory> + extern "C" { -#include "dev_stream.h" -#include "cras_rstream.h" #include "cras_iodev.h" +#include "cras_rstream.h" #include "cras_shm.h" #include "cras_types.h" +#include "dev_stream.h" #include "utlist.h" } @@ -33,8 +34,9 @@ ShmPtr create_shm(size_t cb_threshold) { shm->header->config.frame_bytes = frame_bytes; shm->config = shm->header->config; - shm->samples = reinterpret_cast<uint8_t*>( - calloc(1, cras_shm_calculate_samples_size(used_size))); + uint32_t samples_size = cras_shm_calculate_samples_size(used_size); + shm->samples = reinterpret_cast<uint8_t*>(calloc(1, samples_size)); + shm->samples_info.length = samples_size; return shm; } @@ -58,16 +60,14 @@ RstreamPtr create_rstream(cras_stream_id_t id, rstream->cb_threshold = cb_threshold; rstream->shm = shm; rstream->format = *format; - cras_frames_to_time(cb_threshold, - rstream->format.frame_rate, + cras_frames_to_time(cb_threshold, rstream->format.frame_rate, &rstream->sleep_interval_ts); return rstream; } DevStreamPtr create_dev_stream(unsigned int dev_id, cras_rstream* rstream) { DevStreamPtr dstream( - reinterpret_cast<dev_stream*>(calloc(1, sizeof(dev_stream))), - free); + reinterpret_cast<dev_stream*>(calloc(1, sizeof(dev_stream))), free); dstream->dev_id = dev_id; dstream->stream = rstream; dstream->dev_rate = rstream->format.frame_rate; @@ -81,8 +81,8 @@ StreamPtr create_stream(cras_stream_id_t id, size_t cb_threshold, const cras_audio_format* format) { ShmPtr shm = create_shm(cb_threshold); - RstreamPtr rstream = create_rstream(1, CRAS_STREAM_INPUT, cb_threshold, - format, shm.get()); + RstreamPtr rstream = + create_rstream(1, CRAS_STREAM_INPUT, cb_threshold, format, shm.get()); DevStreamPtr dstream = create_dev_stream(1, rstream.get()); StreamPtr s( new Stream(std::move(shm), std::move(rstream), std::move(dstream))); @@ -114,7 +114,7 @@ IodevPtr create_open_iodev(CRAS_STREAM_DIRECTION direction, cras_audio_format* format, cras_ionode* active_node) { IodevPtr iodev(reinterpret_cast<cras_iodev*>(calloc(1, sizeof(cras_iodev))), - free); + free); iodev->is_enabled = 1; iodev->direction = direction; iodev->format = format; @@ -124,6 +124,7 @@ IodevPtr create_open_iodev(CRAS_STREAM_DIRECTION direction, iodev->buffer_size = cb_threshold * 2; iodev->min_cb_level = UINT_MAX; iodev->max_cb_level = 0; + iodev->largest_cb_level = 0; iodev->flush_buffer = &fake_flush_buffer; return iodev; } @@ -134,8 +135,8 @@ DevicePtr create_device(CRAS_STREAM_DIRECTION direction, CRAS_NODE_TYPE active_node_type) { IonodePtr node = create_ionode(active_node_type); IodevPtr dev = create_open_iodev(direction, cb_threshold, format, node.get()); - OpendevPtr odev( - reinterpret_cast<open_dev*>(calloc(1, sizeof(open_dev))), free); + OpendevPtr odev(reinterpret_cast<open_dev*>(calloc(1, sizeof(open_dev))), + free); odev->dev = dev.get(); DevicePtr d(new Device(std::move(dev), std::move(node), std::move(odev))); @@ -148,6 +149,8 @@ void add_stream_to_dev(IodevPtr& dev, const StreamPtr& stream) { static_cast<size_t>(dev->min_cb_level)); dev->max_cb_level = std::max(stream->rstream->cb_threshold, static_cast<size_t>(dev->max_cb_level)); + dev->largest_cb_level = std::max(stream->rstream->cb_threshold, + static_cast<size_t>(dev->max_cb_level)); } void fill_audio_format(cras_audio_format* format, unsigned int rate) { diff --git a/cras/src/tests/dev_io_stubs.h b/cras/src/tests/dev_io_stubs.h index ef5f79ac..9db193c5 100644 --- a/cras/src/tests/dev_io_stubs.h +++ b/cras/src/tests/dev_io_stubs.h @@ -2,18 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <memory> #include <stdint.h> #include <stdio.h> #include <time.h> +#include <memory> + extern "C" { -#include "dev_io.h" -#include "dev_stream.h" -#include "cras_rstream.h" #include "cras_iodev.h" +#include "cras_rstream.h" #include "cras_shm.h" #include "cras_types.h" +#include "dev_io.h" +#include "dev_stream.h" #include "utlist.h" } @@ -34,9 +35,7 @@ ShmPtr create_shm(size_t cb_threshold); // Holds the rstream and devstream pointers for an attached stream. struct Stream { - Stream(ShmPtr shm, - RstreamPtr rstream, - DevStreamPtr dstream) + Stream(ShmPtr shm, RstreamPtr rstream, DevStreamPtr dstream) : shm(std::move(shm)), rstream(std::move(rstream)), dstream(std::move(dstream)) {} @@ -48,11 +47,8 @@ using StreamPtr = std::unique_ptr<Stream>; // Holds the iodev and ionode pointers for an attached device. struct Device { - Device(IodevPtr dev, IonodePtr node, OpendevPtr odev) : - dev(std::move(dev)), - node(std::move(node)), - odev(std::move(odev)) { - } + Device(IodevPtr dev, IonodePtr node, OpendevPtr odev) + : dev(std::move(dev)), node(std::move(node)), odev(std::move(odev)) {} IodevPtr dev; IonodePtr node; OpendevPtr odev; diff --git a/cras/src/tests/dev_io_unittest.cc b/cras/src/tests/dev_io_unittest.cc index cb6e40e0..a18dd48a 100644 --- a/cras/src/tests/dev_io_unittest.cc +++ b/cras/src/tests/dev_io_unittest.cc @@ -2,20 +2,20 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <memory> +#include <gtest/gtest.h> #include <stdint.h> #include <stdio.h> #include <time.h> -#include <gtest/gtest.h> +#include <memory> extern "C" { -#include "dev_io.h" // tested -#include "dev_stream.h" // stubbed -#include "cras_rstream.h" // stubbed -#include "cras_iodev.h" // stubbed +#include "cras_iodev.h" // stubbed +#include "cras_rstream.h" // stubbed #include "cras_shm.h" #include "cras_types.h" +#include "dev_io.h" // tested +#include "dev_stream.h" // stubbed #include "utlist.h" struct audio_thread_event_log* atlog; @@ -31,8 +31,7 @@ static unsigned int dev_stream_capture_avail_ret = 480; namespace { - -class DevIoSuite : public testing::Test{ +class DevIoSuite : public testing::Test { protected: virtual void SetUp() { atlog = static_cast<audio_thread_event_log*>(calloc(1, sizeof(*atlog))); @@ -42,9 +41,7 @@ class DevIoSuite : public testing::Test{ stream = create_stream(1, 1, CRAS_STREAM_INPUT, cb_threshold, &format); } - virtual void TearDown() { - free(atlog); - } + virtual void TearDown() { free(atlog); } size_t cb_threshold = 480; cras_audio_format format; @@ -52,8 +49,6 @@ class DevIoSuite : public testing::Test{ }; TEST_F(DevIoSuite, SendCapturedFails) { - - // rstream's next callback is now and there is enough data to fill. struct timespec start; clock_gettime(CLOCK_MONOTONIC_RAW, &start); @@ -61,8 +56,8 @@ TEST_F(DevIoSuite, SendCapturedFails) { AddFakeDataToStream(stream.get(), 480); struct open_dev* dev_list = NULL; - DevicePtr dev = create_device(CRAS_STREAM_INPUT, cb_threshold, - &format, CRAS_NODE_TYPE_MIC); + DevicePtr dev = create_device(CRAS_STREAM_INPUT, cb_threshold, &format, + CRAS_NODE_TYPE_MIC); DL_APPEND(dev_list, dev->odev.get()); add_stream_to_dev(dev->dev, stream); @@ -75,8 +70,8 @@ TEST_F(DevIoSuite, SendCapturedFails) { TEST_F(DevIoSuite, CaptureGain) { struct open_dev* dev_list = NULL; struct timespec ts; - DevicePtr dev = create_device(CRAS_STREAM_INPUT, cb_threshold, - &format, CRAS_NODE_TYPE_MIC); + DevicePtr dev = create_device(CRAS_STREAM_INPUT, cb_threshold, &format, + CRAS_NODE_TYPE_MIC); dev->dev->state = CRAS_IODEV_STATE_NORMAL_RUN; dev->dev->software_gain_scaler = 0.99f; @@ -86,7 +81,7 @@ TEST_F(DevIoSuite, CaptureGain) { /* For stream that uses APM, always apply gain scaler 1.0f regardless of * what node/stream gains are. */ - stream->rstream->apm_list = reinterpret_cast<struct cras_apm_list *>(0xf0f); + stream->rstream->apm_list = reinterpret_cast<struct cras_apm_list*>(0xf0f); dev_io_capture(&dev_list); EXPECT_EQ(1.0f, dev_stream_capture_software_gain_scaler_val); @@ -95,101 +90,178 @@ TEST_F(DevIoSuite, CaptureGain) { EXPECT_EQ(0.99f, dev_stream_capture_software_gain_scaler_val); } +/* + * If any hw_level is larger than 1.5 * largest_cb_level and + * DROP_FRAMES_THRESHOLD_MS, reset all input devices. + */ +TEST_F(DevIoSuite, SendCapturedNeedToResetDevices) { + struct timespec start; + struct timespec drop_time; + struct open_dev* dev_list = NULL; + bool rc; + + clock_gettime(CLOCK_MONOTONIC_RAW, &start); + AddFakeDataToStream(stream.get(), 0); + + DevicePtr dev1 = + create_device(CRAS_STREAM_INPUT, 1000, &format, CRAS_NODE_TYPE_MIC); + DevicePtr dev2 = + create_device(CRAS_STREAM_INPUT, 10000, &format, CRAS_NODE_TYPE_MIC); + DL_APPEND(dev_list, dev1->odev.get()); + DL_APPEND(dev_list, dev2->odev.get()); + add_stream_to_dev(dev1->dev, stream); + add_stream_to_dev(dev2->dev, stream); + + iodev_stub_frames_queued(dev1->dev.get(), 2880, start); + iodev_stub_frames_queued(dev2->dev.get(), 4800, start); + EXPECT_EQ(0, dev_io_send_captured_samples(dev_list)); + + /* + * Should drop frames to one min_cb_level, which is MIN(2880, 4800) - 480 = + * 2400 (50ms). + */ + rc = iodev_stub_get_drop_time(dev1->dev.get(), &drop_time); + EXPECT_EQ(true, rc); + EXPECT_EQ(0, drop_time.tv_sec); + EXPECT_EQ(50000000, drop_time.tv_nsec); + + rc = iodev_stub_get_drop_time(dev2->dev.get(), &drop_time); + EXPECT_EQ(true, rc); + EXPECT_EQ(0, drop_time.tv_sec); + EXPECT_EQ(50000000, drop_time.tv_nsec); +} + +/* + * If the hw_level is larger than 1.5 * largest_cb_level but less than + * DROP_FRAMES_THRESHOLD_MS, do nothing. + */ +TEST_F(DevIoSuite, SendCapturedLevelLessThanThreshold) { + struct timespec start; + struct timespec drop_time; + struct open_dev* dev_list = NULL; + bool rc; + + clock_gettime(CLOCK_MONOTONIC_RAW, &start); + AddFakeDataToStream(stream.get(), 0); + + DevicePtr dev = + create_device(CRAS_STREAM_INPUT, 480, &format, CRAS_NODE_TYPE_MIC); + DL_APPEND(dev_list, dev->odev.get()); + add_stream_to_dev(dev->dev, stream); + + iodev_stub_frames_queued(dev->dev.get(), 2048, start); + EXPECT_EQ(0, dev_io_send_captured_samples(dev_list)); + + rc = iodev_stub_get_drop_time(dev->dev.get(), &drop_time); + EXPECT_EQ(false, rc); +} + +/* If all hw_level is less than 1.5 * largest_cb_level, do nothing. */ +TEST_F(DevIoSuite, SendCapturedNoNeedToResetDevices) { + struct timespec start; + struct timespec drop_time; + struct open_dev* dev_list = NULL; + bool rc; + + clock_gettime(CLOCK_MONOTONIC_RAW, &start); + AddFakeDataToStream(stream.get(), 0); + + DevicePtr dev1 = + create_device(CRAS_STREAM_INPUT, 1000, &format, CRAS_NODE_TYPE_MIC); + DevicePtr dev2 = + create_device(CRAS_STREAM_INPUT, 10000, &format, CRAS_NODE_TYPE_MIC); + DL_APPEND(dev_list, dev1->odev.get()); + DL_APPEND(dev_list, dev2->odev.get()); + add_stream_to_dev(dev1->dev, stream); + add_stream_to_dev(dev2->dev, stream); + + iodev_stub_frames_queued(dev1->dev.get(), 400, start); + iodev_stub_frames_queued(dev2->dev.get(), 400, start); + EXPECT_EQ(0, dev_io_send_captured_samples(dev_list)); + + rc = iodev_stub_get_drop_time(dev1->dev.get(), &drop_time); + EXPECT_EQ(false, rc); + + rc = iodev_stub_get_drop_time(dev2->dev.get(), &drop_time); + EXPECT_EQ(false, rc); +} + /* Stubs */ extern "C" { -int input_data_get_for_stream( - struct input_data *data, - struct cras_rstream *stream, - struct buffer_share *offsets, - struct cras_audio_area **area, - unsigned int *offset) -{ +int input_data_get_for_stream(struct input_data* data, + struct cras_rstream* stream, + struct buffer_share* offsets, + struct cras_audio_area** area, + unsigned int* offset) { return 0; } -int input_data_put_for_stream(struct input_data *data, - struct cras_rstream *stream, - struct buffer_share *offsets, - unsigned int frames) -{ +int input_data_put_for_stream(struct input_data* data, + struct cras_rstream* stream, + struct buffer_share* offsets, + unsigned int frames) { return 0; } -int dev_stream_attached_devs(const struct dev_stream *dev_stream) -{ + +int cras_audio_thread_event_drop_samples() { return 0; } -void dev_stream_update_frames(const struct dev_stream *dev_stream) -{ -} -int dev_stream_playback_frames(const struct dev_stream *dev_stream) -{ + +int dev_stream_attached_devs(const struct dev_stream* dev_stream) { return 0; } -int dev_stream_is_pending_reply(const struct dev_stream *dev_stream) -{ +void dev_stream_update_frames(const struct dev_stream* dev_stream) {} +int dev_stream_playback_frames(const struct dev_stream* dev_stream) { return 0; } -int dev_stream_mix(struct dev_stream *dev_stream, - const struct cras_audio_format *fmt, - uint8_t *dst, - unsigned int num_to_write) -{ +int dev_stream_is_pending_reply(const struct dev_stream* dev_stream) { return 0; } -void dev_stream_set_dev_rate(struct dev_stream *dev_stream, - unsigned int dev_rate, - double dev_rate_ratio, - double master_rate_ratio, - int coarse_rate_adjust) -{ -} -int dev_stream_capture_update_rstream(struct dev_stream *dev_stream) -{ +int dev_stream_mix(struct dev_stream* dev_stream, + const struct cras_audio_format* fmt, + uint8_t* dst, + unsigned int num_to_write) { return 0; } -int dev_stream_wake_time(struct dev_stream *dev_stream, - unsigned int curr_level, - struct timespec *level_tstamp, - unsigned int cap_limit, - int is_cap_limit_stream, - struct timespec *wake_time_out) -{ +void dev_stream_set_dev_rate(struct dev_stream* dev_stream, + unsigned int dev_rate, + double dev_rate_ratio, + double master_rate_ratio, + int coarse_rate_adjust) {} +int dev_stream_capture_update_rstream(struct dev_stream* dev_stream) { return 0; } -int dev_stream_flush_old_audio_messages(struct dev_stream *dev_stream) -{ +int dev_stream_wake_time(struct dev_stream* dev_stream, + unsigned int curr_level, + struct timespec* level_tstamp, + unsigned int cap_limit, + int is_cap_limit_stream, + struct timespec* wake_time_out) { return 0; } -void dev_stream_set_delay(const struct dev_stream *dev_stream, - unsigned int delay_frames) -{ +int dev_stream_flush_old_audio_messages(struct dev_stream* dev_stream) { + return 0; } -unsigned int dev_stream_capture(struct dev_stream *dev_stream, - const struct cras_audio_area *area, - unsigned int area_offset, - float software_gain_scaler) -{ +void dev_stream_set_delay(const struct dev_stream* dev_stream, + unsigned int delay_frames) {} +unsigned int dev_stream_capture(struct dev_stream* dev_stream, + const struct cras_audio_area* area, + unsigned int area_offset, + float software_gain_scaler) { dev_stream_capture_software_gain_scaler_val = software_gain_scaler; return 0; } -void dev_stream_update_next_wake_time(struct dev_stream *dev_stream) -{ -} -int dev_stream_request_playback_samples(struct dev_stream *dev_stream, - const struct timespec *now) -{ +void dev_stream_update_next_wake_time(struct dev_stream* dev_stream) {} +int dev_stream_request_playback_samples(struct dev_stream* dev_stream, + const struct timespec* now) { return 0; } -int dev_stream_playback_update_rstream(struct dev_stream *dev_stream) -{ +int dev_stream_playback_update_rstream(struct dev_stream* dev_stream) { return 0; } -void dev_stream_destroy(struct dev_stream *dev_stream) -{ -} -unsigned int dev_stream_capture_avail(const struct dev_stream *dev_stream) -{ +void dev_stream_destroy(struct dev_stream* dev_stream) {} +unsigned int dev_stream_capture_avail(const struct dev_stream* dev_stream) { return dev_stream_capture_avail_ret; } struct dev_stream* dev_stream_create(struct cras_rstream* stream, diff --git a/cras/src/tests/dev_stream_unittest.cc b/cras/src/tests/dev_stream_unittest.cc index 5349a97a..39c16e48 100644 --- a/cras/src/tests/dev_stream_unittest.cc +++ b/cras/src/tests/dev_stream_unittest.cc @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <stdio.h> #include <gtest/gtest.h> +#include <stdio.h> extern "C" { #include "audio_thread_log.h" @@ -18,11 +18,13 @@ extern "C" { namespace { extern "C" { -struct audio_thread_event_log *atlog; -unsigned int max_frames_for_conversion( - unsigned int stream_frames, - unsigned int stream_rate, - unsigned int device_rate); +struct audio_thread_event_log* atlog; +// For audio_thread_log.h use. +int atlog_rw_shm_fd; +int atlog_ro_shm_fd; +unsigned int max_frames_for_conversion(unsigned int stream_frames, + unsigned int stream_rate, + unsigned int device_rate); }; static struct timespec clock_gettime_retspec; @@ -30,46 +32,46 @@ static struct timespec cb_ts; static const int kBufferFrames = 1024; static const struct cras_audio_format fmt_s16le_44_1 = { - SND_PCM_FORMAT_S16_LE, - 44100, - 2, + SND_PCM_FORMAT_S16_LE, + 44100, + 2, }; static const struct cras_audio_format fmt_s16le_48 = { - SND_PCM_FORMAT_S16_LE, - 48000, - 2, + SND_PCM_FORMAT_S16_LE, + 48000, + 2, }; static const struct cras_audio_format fmt_s16le_48_mono = { - SND_PCM_FORMAT_S16_LE, - 48000, - 1, + SND_PCM_FORMAT_S16_LE, + 48000, + 1, }; static const struct cras_audio_format fmt_s16le_8 = { - SND_PCM_FORMAT_S16_LE, - 8000, - 2, + SND_PCM_FORMAT_S16_LE, + 8000, + 2, }; struct cras_audio_area_copy_call { - const struct cras_audio_area *dst; + const struct cras_audio_area* dst; unsigned int dst_offset; unsigned int dst_format_bytes; - const struct cras_audio_area *src; + const struct cras_audio_area* src; unsigned int src_offset; float software_gain_scaler; }; struct fmt_conv_call { - struct cras_fmt_conv *conv; - uint8_t *in_buf; - uint8_t *out_buf; + struct cras_fmt_conv* conv; + uint8_t* in_buf; + uint8_t* out_buf; size_t in_frames; size_t out_frames; }; struct mix_add_call { - int16_t *dst; - int16_t *src; + int16_t* dst; + int16_t* src; unsigned int count; unsigned int index; int mute; @@ -77,15 +79,15 @@ struct mix_add_call { }; struct rstream_get_readable_call { - struct cras_rstream *rstream; + struct cras_rstream* rstream; unsigned int offset; unsigned int num_called; }; static int config_format_converter_called; -static const struct cras_audio_format *config_format_converter_from_fmt; +static const struct cras_audio_format* config_format_converter_from_fmt; static int config_format_converter_frames; -static struct cras_fmt_conv *config_format_converter_conv; +static struct cras_fmt_conv* config_format_converter_conv; static struct cras_audio_format in_fmt; static struct cras_audio_format out_fmt; static struct cras_audio_area_copy_call copy_area_call; @@ -100,137 +102,147 @@ static unsigned int rstream_playable_frames_ret; static struct mix_add_call mix_add_call; static struct rstream_get_readable_call rstream_get_readable_call; static unsigned int rstream_get_readable_num; -static uint8_t *rstream_get_readable_ptr; +static uint8_t* rstream_get_readable_ptr; -static struct cras_audio_format *cras_rstream_post_processing_format_val; +static struct cras_audio_format* cras_rstream_post_processing_format_val; static int cras_rstream_audio_ready_called; static int cras_rstream_audio_ready_count; static int cras_rstream_is_pending_reply_ret; static int cras_rstream_flush_old_audio_messages_called; static int cras_server_metrics_missed_cb_event_called; -class CreateSuite : public testing::Test{ - protected: - virtual void SetUp() { - in_fmt.format = SND_PCM_FORMAT_S16_LE; - out_fmt.format = SND_PCM_FORMAT_S16_LE; - in_fmt.num_channels = 2; - out_fmt.num_channels = 2; - - SetupShm(&rstream_.shm); - - rstream_.stream_id = 0x10001; - rstream_.buffer_frames = kBufferFrames; - rstream_.cb_threshold = kBufferFrames / 2; - rstream_.is_draining = 0; - rstream_.stream_type = CRAS_STREAM_TYPE_DEFAULT; - rstream_.direction = CRAS_STREAM_OUTPUT; - rstream_.format.format = SND_PCM_FORMAT_S16_LE; - rstream_.format.num_channels = 2; - rstream_.format = fmt_s16le_44_1; - rstream_.flags = 0; - rstream_.num_missed_cb = 0; - - config_format_converter_from_fmt = NULL; - config_format_converter_called = 0; - cras_fmt_conversion_needed_val = 0; - cras_fmt_conv_set_linear_resample_rates_called = 0; - - cras_rstream_audio_ready_called = 0; - cras_rstream_audio_ready_count = 0; - cras_rstream_is_pending_reply_ret = 0; - cras_rstream_flush_old_audio_messages_called = 0; - cras_server_metrics_missed_cb_event_called = 0; - - memset(©_area_call, 0xff, sizeof(copy_area_call)); - memset(&conv_frames_call, 0xff, sizeof(conv_frames_call)); - - atlog = audio_thread_event_log_init(); - - devstr.stream = &rstream_; - devstr.conv = NULL; - devstr.conv_buffer = NULL; - devstr.conv_buffer_size_frames = 0; - - area = (struct cras_audio_area*)calloc(1, - sizeof(*area) + 2 * sizeof(struct cras_channel_area)); - area->num_channels = 2; - channel_area_set_channel(&area->channels[0], CRAS_CH_FL); - channel_area_set_channel(&area->channels[1], CRAS_CH_FR); - area->channels[0].step_bytes = 4; - area->channels[0].buf = (uint8_t *)(cap_buf); - area->channels[1].step_bytes = 4; - area->channels[1].buf = (uint8_t *)(cap_buf + 1); - area->frames = kBufferFrames; - - stream_area = (struct cras_audio_area*)calloc(1, - sizeof(*area) + 2 * sizeof(struct cras_channel_area)); - stream_area->num_channels = 2; - rstream_.audio_area = stream_area; - int16_t* shm_samples = (int16_t*)rstream_.shm->samples; - stream_area->channels[0].step_bytes = 4; - stream_area->channels[0].buf = (uint8_t *)(shm_samples); - stream_area->channels[1].step_bytes = 4; - stream_area->channels[1].buf = (uint8_t *)(shm_samples + 1); - } - - virtual void TearDown() { - free(area); - free(stream_area); - free(rstream_.shm->header); - free(rstream_.shm->samples); - free(rstream_.shm); - audio_thread_event_log_deinit(atlog); - } - - void SetupShm(struct cras_audio_shm** shm_out) { - int16_t *buf; - struct cras_audio_shm* shm; - - shm = static_cast<struct cras_audio_shm*>( - calloc(1, sizeof(struct cras_audio_shm))); - - shm->header = static_cast<struct cras_audio_shm_header*>( - calloc(1, sizeof(struct cras_audio_shm_header))); - cras_shm_set_frame_bytes(shm, 4); - cras_shm_set_used_size(shm, kBufferFrames * cras_shm_frame_bytes(shm)); - - shm->samples = - static_cast<uint8_t*>(calloc(1, cras_shm_samples_size(shm))); - - buf = (int16_t*)shm->samples; - for (size_t i = 0; i < kBufferFrames * 2; i++) - buf[i] = i; - cras_shm_set_mute(shm, 0); - cras_shm_set_volume_scaler(shm, 1.0); - - *shm_out = shm; - } - - void SetUpFmtConv(unsigned int in_rate, unsigned int out_rate, - unsigned int conv_buf_size) { - in_fmt.frame_rate = in_rate; - out_fmt.frame_rate = out_rate; - cras_fmt_conversion_needed_val = 1; - - devstr.conv = (struct cras_fmt_conv *)0xdead; - devstr.conv_buffer = - (struct byte_buffer *)byte_buffer_create(conv_buf_size * 4); - devstr.conv_buffer_size_frames = kBufferFrames * 2; - - devstr.conv_area = (struct cras_audio_area*)calloc(1, - sizeof(*area) + 2 * sizeof(*area->channels)); - devstr.conv_area->num_channels = 2; - devstr.conv_area->channels[0].step_bytes = 4; - devstr.conv_area->channels[0].buf = (uint8_t *)(devstr.conv_buffer->bytes); - devstr.conv_area->channels[1].step_bytes = 4; - devstr.conv_area->channels[1].buf = - (uint8_t *)(devstr.conv_buffer->bytes + 1); - } +static char* atlog_name; + +class CreateSuite : public testing::Test { + protected: + virtual void SetUp() { + in_fmt.format = SND_PCM_FORMAT_S16_LE; + out_fmt.format = SND_PCM_FORMAT_S16_LE; + in_fmt.num_channels = 2; + out_fmt.num_channels = 2; + + SetupShm(&rstream_.shm); + + rstream_.stream_id = 0x10001; + rstream_.buffer_frames = kBufferFrames; + rstream_.cb_threshold = kBufferFrames / 2; + rstream_.is_draining = 0; + rstream_.stream_type = CRAS_STREAM_TYPE_DEFAULT; + rstream_.direction = CRAS_STREAM_OUTPUT; + rstream_.format.format = SND_PCM_FORMAT_S16_LE; + rstream_.format.num_channels = 2; + rstream_.format = fmt_s16le_44_1; + rstream_.flags = 0; + rstream_.num_missed_cb = 0; + + config_format_converter_from_fmt = NULL; + config_format_converter_called = 0; + cras_fmt_conversion_needed_val = 0; + cras_fmt_conv_set_linear_resample_rates_called = 0; + + cras_rstream_audio_ready_called = 0; + cras_rstream_audio_ready_count = 0; + cras_rstream_is_pending_reply_ret = 0; + cras_rstream_flush_old_audio_messages_called = 0; + cras_server_metrics_missed_cb_event_called = 0; + + memset(©_area_call, 0xff, sizeof(copy_area_call)); + memset(&conv_frames_call, 0xff, sizeof(conv_frames_call)); + + ASSERT_FALSE(asprintf(&atlog_name, "/ATlog-%d", getpid()) < 0); + /* To avoid un-used variable warning. */ + atlog_rw_shm_fd = atlog_ro_shm_fd = -1; + atlog = audio_thread_event_log_init(atlog_name); + + devstr.stream = &rstream_; + devstr.conv = NULL; + devstr.conv_buffer = NULL; + devstr.conv_buffer_size_frames = 0; + + area = (struct cras_audio_area*)calloc( + 1, sizeof(*area) + 2 * sizeof(struct cras_channel_area)); + area->num_channels = 2; + channel_area_set_channel(&area->channels[0], CRAS_CH_FL); + channel_area_set_channel(&area->channels[1], CRAS_CH_FR); + area->channels[0].step_bytes = 4; + area->channels[0].buf = (uint8_t*)(cap_buf); + area->channels[1].step_bytes = 4; + area->channels[1].buf = (uint8_t*)(cap_buf + 1); + area->frames = kBufferFrames; + + stream_area = (struct cras_audio_area*)calloc( + 1, sizeof(*area) + 2 * sizeof(struct cras_channel_area)); + stream_area->num_channels = 2; + rstream_.audio_area = stream_area; + int16_t* shm_samples = (int16_t*)rstream_.shm->samples; + stream_area->channels[0].step_bytes = 4; + stream_area->channels[0].buf = (uint8_t*)(shm_samples); + stream_area->channels[1].step_bytes = 4; + stream_area->channels[1].buf = (uint8_t*)(shm_samples + 1); + } + + virtual void TearDown() { + free(area); + free(stream_area); + free(rstream_.shm->header); + free(rstream_.shm->samples); + free(rstream_.shm); + audio_thread_event_log_deinit(atlog, atlog_name); + free(atlog_name); + } + + void SetupShm(struct cras_audio_shm** shm_out) { + int16_t* buf; + struct cras_audio_shm* shm; + uint32_t used_size; + + shm = static_cast<struct cras_audio_shm*>( + calloc(1, sizeof(struct cras_audio_shm))); + + shm->header = static_cast<struct cras_audio_shm_header*>( + calloc(1, sizeof(struct cras_audio_shm_header))); + cras_shm_set_frame_bytes(shm, 4); + used_size = kBufferFrames * cras_shm_frame_bytes(shm); + cras_shm_set_used_size(shm, used_size); + + shm->samples = static_cast<uint8_t*>( + calloc(1, cras_shm_calculate_samples_size(used_size))); + shm->samples_info.length = cras_shm_calculate_samples_size(used_size); + + buf = (int16_t*)shm->samples; + for (size_t i = 0; i < kBufferFrames * 2; i++) + buf[i] = i; + cras_shm_set_mute(shm, 0); + cras_shm_set_volume_scaler(shm, 1.0); + + *shm_out = shm; + } + + void SetUpFmtConv(unsigned int in_rate, + unsigned int out_rate, + unsigned int conv_buf_size) { + in_fmt.frame_rate = in_rate; + out_fmt.frame_rate = out_rate; + cras_fmt_conversion_needed_val = 1; + + devstr.conv = (struct cras_fmt_conv*)0xdead; + devstr.conv_buffer = + (struct byte_buffer*)byte_buffer_create(conv_buf_size * 4); + devstr.conv_buffer_size_frames = kBufferFrames * 2; + + devstr.conv_area = (struct cras_audio_area*)calloc( + 1, sizeof(*area) + 2 * sizeof(*area->channels)); + devstr.conv_area->num_channels = 2; + devstr.conv_area->channels[0].step_bytes = 4; + devstr.conv_area->channels[0].buf = (uint8_t*)(devstr.conv_buffer->bytes); + devstr.conv_area->channels[1].step_bytes = 4; + devstr.conv_area->channels[1].buf = + (uint8_t*)(devstr.conv_buffer->bytes + 1); + } struct dev_stream devstr; - struct cras_audio_area *area; - struct cras_audio_area *stream_area; + struct cras_audio_area* area; + struct cras_audio_area* stream_area; int16_t cap_buf[kBufferFrames * 2]; struct cras_rstream rstream_; }; @@ -245,7 +257,6 @@ TEST_F(CreateSuite, CaptureNoSRC) { EXPECT_EQ(4, copy_area_call.dst_format_bytes); EXPECT_EQ(area, copy_area_call.src); EXPECT_EQ(software_gain_scaler, copy_area_call.software_gain_scaler); - } TEST_F(CreateSuite, CaptureSRCSmallConverterBuffer) { @@ -257,14 +268,12 @@ TEST_F(CreateSuite, CaptureSRCSmallConverterBuffer) { nread = dev_stream_capture(&devstr, area, 0, software_gain_scaler); // |nread| is bound by small converter buffer size (kBufferFrames / 4) - conv_buf_avail_at_input_rate = - cras_frames_at_rate(out_fmt.frame_rate, - (kBufferFrames / 4), - in_fmt.frame_rate); + conv_buf_avail_at_input_rate = cras_frames_at_rate( + out_fmt.frame_rate, (kBufferFrames / 4), in_fmt.frame_rate); EXPECT_EQ(conv_buf_avail_at_input_rate, nread); - EXPECT_EQ((struct cras_fmt_conv *)0xdead, conv_frames_call.conv); - EXPECT_EQ((uint8_t *)cap_buf, conv_frames_call.in_buf); + EXPECT_EQ((struct cras_fmt_conv*)0xdead, conv_frames_call.conv); + EXPECT_EQ((uint8_t*)cap_buf, conv_frames_call.in_buf); EXPECT_EQ(devstr.conv_buffer->bytes, conv_frames_call.out_buf); EXPECT_EQ(conv_buf_avail_at_input_rate, conv_frames_call.in_frames); @@ -292,14 +301,12 @@ TEST_F(CreateSuite, CaptureSRCLargeConverterBuffer) { // Available frames at stream side is bound by cb_threshold, which // equals to kBufferFrames / 2. - stream_avail_at_input_rate = - cras_frames_at_rate(out_fmt.frame_rate, - (kBufferFrames / 2), - in_fmt.frame_rate); + stream_avail_at_input_rate = cras_frames_at_rate( + out_fmt.frame_rate, (kBufferFrames / 2), in_fmt.frame_rate); EXPECT_EQ(stream_avail_at_input_rate, nread); - EXPECT_EQ((struct cras_fmt_conv *)0xdead, conv_frames_call.conv); - EXPECT_EQ((uint8_t *)cap_buf, conv_frames_call.in_buf); + EXPECT_EQ((struct cras_fmt_conv*)0xdead, conv_frames_call.conv); + EXPECT_EQ((uint8_t*)cap_buf, conv_frames_call.in_buf); EXPECT_EQ(devstr.conv_buffer->bytes, conv_frames_call.out_buf); // Expect number of input frames is limited by |stream_avail_at_input_rate| @@ -320,46 +327,44 @@ TEST_F(CreateSuite, CaptureSRCLargeConverterBuffer) { } TEST_F(CreateSuite, CreateSRC44to48) { - struct dev_stream *dev_stream; + struct dev_stream* dev_stream; rstream_.format = fmt_s16le_44_1; - in_fmt.frame_rate = 44100; // Input to converter is stream rate. + in_fmt.frame_rate = 44100; // Input to converter is stream rate. out_fmt.frame_rate = 48000; // Output from converter is device rate. config_format_converter_conv = reinterpret_cast<struct cras_fmt_conv*>(0x33); - dev_stream = dev_stream_create(&rstream_, 0, &fmt_s16le_48, (void *)0x55, - &cb_ts); + dev_stream = + dev_stream_create(&rstream_, 0, &fmt_s16le_48, (void*)0x55, &cb_ts); EXPECT_EQ(1, config_format_converter_called); EXPECT_NE(static_cast<byte_buffer*>(NULL), dev_stream->conv_buffer); // Converter tmp and output buffers are large enough for device output. unsigned int device_frames = - cras_frames_at_rate(in_fmt.frame_rate, kBufferFrames, - out_fmt.frame_rate); - EXPECT_LE(kBufferFrames, device_frames); // Sanity check. + cras_frames_at_rate(in_fmt.frame_rate, kBufferFrames, out_fmt.frame_rate); + EXPECT_LE(kBufferFrames, device_frames); // Sanity check. EXPECT_LE(device_frames, config_format_converter_frames); EXPECT_LE(device_frames, dev_stream->conv_buffer_size_frames); dev_stream_destroy(dev_stream); } TEST_F(CreateSuite, CreateSRC44from48Input) { - struct dev_stream *dev_stream; + struct dev_stream* dev_stream; struct cras_audio_format processed_fmt = fmt_s16le_48; processed_fmt.num_channels = 1; rstream_.format = fmt_s16le_44_1; rstream_.direction = CRAS_STREAM_INPUT; - in_fmt.frame_rate = 48000; // Input to converter is device rate. + in_fmt.frame_rate = 48000; // Input to converter is device rate. out_fmt.frame_rate = 44100; // Output from converter is stream rate. config_format_converter_conv = reinterpret_cast<struct cras_fmt_conv*>(0x33); cras_rstream_post_processing_format_val = &processed_fmt; - dev_stream = dev_stream_create(&rstream_, 0, &fmt_s16le_48, (void *)0x55, - &cb_ts); + dev_stream = + dev_stream_create(&rstream_, 0, &fmt_s16le_48, (void*)0x55, &cb_ts); EXPECT_EQ(1, config_format_converter_called); EXPECT_NE(static_cast<byte_buffer*>(NULL), dev_stream->conv_buffer); // Converter tmp and output buffers are large enough for device input. unsigned int device_frames = - cras_frames_at_rate(out_fmt.frame_rate, kBufferFrames, - in_fmt.frame_rate); - EXPECT_LE(kBufferFrames, device_frames); // Sanity check. + cras_frames_at_rate(out_fmt.frame_rate, kBufferFrames, in_fmt.frame_rate); + EXPECT_LE(kBufferFrames, device_frames); // Sanity check. EXPECT_LE(device_frames, config_format_converter_frames); EXPECT_EQ(&processed_fmt, config_format_converter_from_fmt); EXPECT_LE(device_frames, dev_stream->conv_buffer_size_frames); @@ -367,14 +372,14 @@ TEST_F(CreateSuite, CreateSRC44from48Input) { } TEST_F(CreateSuite, CreateSRC48to44) { - struct dev_stream *dev_stream; + struct dev_stream* dev_stream; rstream_.format = fmt_s16le_48; - in_fmt.frame_rate = 48000; // Stream rate. + in_fmt.frame_rate = 48000; // Stream rate. out_fmt.frame_rate = 44100; // Device rate. config_format_converter_conv = reinterpret_cast<struct cras_fmt_conv*>(0x33); - dev_stream = dev_stream_create(&rstream_, 0, &fmt_s16le_44_1, (void *)0x55, - &cb_ts); + dev_stream = + dev_stream_create(&rstream_, 0, &fmt_s16le_44_1, (void*)0x55, &cb_ts); EXPECT_EQ(1, config_format_converter_called); EXPECT_NE(static_cast<byte_buffer*>(NULL), dev_stream->conv_buffer); // Converter tmp and output buffers are large enough for stream input. @@ -384,15 +389,15 @@ TEST_F(CreateSuite, CreateSRC48to44) { } TEST_F(CreateSuite, CreateSRC48from44Input) { - struct dev_stream *dev_stream; + struct dev_stream* dev_stream; rstream_.format = fmt_s16le_48; rstream_.direction = CRAS_STREAM_INPUT; - in_fmt.frame_rate = 44100; // Device rate. + in_fmt.frame_rate = 44100; // Device rate. out_fmt.frame_rate = 48000; // Stream rate. config_format_converter_conv = reinterpret_cast<struct cras_fmt_conv*>(0x33); - dev_stream = dev_stream_create(&rstream_, 0, &fmt_s16le_44_1, (void *)0x55, - &cb_ts); + dev_stream = + dev_stream_create(&rstream_, 0, &fmt_s16le_44_1, (void*)0x55, &cb_ts); EXPECT_EQ(1, config_format_converter_called); EXPECT_NE(static_cast<byte_buffer*>(NULL), dev_stream->conv_buffer); // Converter tmp and output buffers are large enough for stream output. @@ -402,57 +407,55 @@ TEST_F(CreateSuite, CreateSRC48from44Input) { } TEST_F(CreateSuite, CreateSRC8to48) { - struct dev_stream *dev_stream; + struct dev_stream* dev_stream; rstream_.format = fmt_s16le_8; - in_fmt.frame_rate = 8000; // Stream rate. + in_fmt.frame_rate = 8000; // Stream rate. out_fmt.frame_rate = 48000; // Device rate. config_format_converter_conv = reinterpret_cast<struct cras_fmt_conv*>(0x33); - dev_stream = dev_stream_create(&rstream_, 0, &fmt_s16le_48, (void *)0x55, - &cb_ts); + dev_stream = + dev_stream_create(&rstream_, 0, &fmt_s16le_48, (void*)0x55, &cb_ts); EXPECT_EQ(1, config_format_converter_called); EXPECT_NE(static_cast<byte_buffer*>(NULL), dev_stream->conv_buffer); // Converter tmp and output buffers are large enough for device output. unsigned int device_frames = - cras_frames_at_rate(in_fmt.frame_rate, kBufferFrames, - out_fmt.frame_rate); - EXPECT_LE(kBufferFrames, device_frames); // Sanity check. + cras_frames_at_rate(in_fmt.frame_rate, kBufferFrames, out_fmt.frame_rate); + EXPECT_LE(kBufferFrames, device_frames); // Sanity check. EXPECT_LE(device_frames, config_format_converter_frames); EXPECT_LE(device_frames, dev_stream->conv_buffer_size_frames); dev_stream_destroy(dev_stream); } TEST_F(CreateSuite, CreateSRC8from48Input) { - struct dev_stream *dev_stream; + struct dev_stream* dev_stream; rstream_.format = fmt_s16le_8; rstream_.direction = CRAS_STREAM_INPUT; in_fmt.frame_rate = 48000; // Device rate. out_fmt.frame_rate = 8000; // Stream rate. config_format_converter_conv = reinterpret_cast<struct cras_fmt_conv*>(0x33); - dev_stream = dev_stream_create(&rstream_, 0, &fmt_s16le_48, (void *)0x55, - &cb_ts); + dev_stream = + dev_stream_create(&rstream_, 0, &fmt_s16le_48, (void*)0x55, &cb_ts); EXPECT_EQ(1, config_format_converter_called); EXPECT_NE(static_cast<byte_buffer*>(NULL), dev_stream->conv_buffer); // Converter tmp and output buffers are large enough for device input. unsigned int device_frames = - cras_frames_at_rate(out_fmt.frame_rate, kBufferFrames, - in_fmt.frame_rate); - EXPECT_LE(kBufferFrames, device_frames); // Sanity check. + cras_frames_at_rate(out_fmt.frame_rate, kBufferFrames, in_fmt.frame_rate); + EXPECT_LE(kBufferFrames, device_frames); // Sanity check. EXPECT_LE(device_frames, config_format_converter_frames); EXPECT_LE(device_frames, dev_stream->conv_buffer_size_frames); dev_stream_destroy(dev_stream); } TEST_F(CreateSuite, CreateSRC48to8) { - struct dev_stream *dev_stream; + struct dev_stream* dev_stream; rstream_.format = fmt_s16le_48; in_fmt.frame_rate = 48000; // Stream rate. out_fmt.frame_rate = 8000; // Device rate. config_format_converter_conv = reinterpret_cast<struct cras_fmt_conv*>(0x33); - dev_stream = dev_stream_create(&rstream_, 0, &fmt_s16le_8, (void *)0x55, - &cb_ts); + dev_stream = + dev_stream_create(&rstream_, 0, &fmt_s16le_8, (void*)0x55, &cb_ts); EXPECT_EQ(1, config_format_converter_called); EXPECT_NE(static_cast<byte_buffer*>(NULL), dev_stream->conv_buffer); // Converter tmp and output buffers are large enough for stream input. @@ -462,15 +465,15 @@ TEST_F(CreateSuite, CreateSRC48to8) { } TEST_F(CreateSuite, CreateSRC48from8Input) { - struct dev_stream *dev_stream; + struct dev_stream* dev_stream; rstream_.format = fmt_s16le_48; rstream_.direction = CRAS_STREAM_INPUT; - in_fmt.frame_rate = 8000; // Device rate. + in_fmt.frame_rate = 8000; // Device rate. out_fmt.frame_rate = 48000; // Stream rate. config_format_converter_conv = reinterpret_cast<struct cras_fmt_conv*>(0x33); - dev_stream = dev_stream_create(&rstream_, 0, &fmt_s16le_8, (void *)0x55, - &cb_ts); + dev_stream = + dev_stream_create(&rstream_, 0, &fmt_s16le_8, (void*)0x55, &cb_ts); EXPECT_EQ(1, config_format_converter_called); EXPECT_NE(static_cast<byte_buffer*>(NULL), dev_stream->conv_buffer); // Converter tmp and output buffers are large enough for stream output. @@ -480,15 +483,15 @@ TEST_F(CreateSuite, CreateSRC48from8Input) { } TEST_F(CreateSuite, CreateSRC48MonoFrom44StereoInput) { - struct dev_stream *dev_stream; + struct dev_stream* dev_stream; rstream_.format = fmt_s16le_48_mono; rstream_.direction = CRAS_STREAM_INPUT; - in_fmt.frame_rate = 44100; // Device rate. + in_fmt.frame_rate = 44100; // Device rate. out_fmt.frame_rate = 48000; // Stream rate. config_format_converter_conv = reinterpret_cast<struct cras_fmt_conv*>(0x33); - dev_stream = dev_stream_create(&rstream_, 0, &fmt_s16le_44_1, (void *)0x55, - &cb_ts); + dev_stream = + dev_stream_create(&rstream_, 0, &fmt_s16le_44_1, (void*)0x55, &cb_ts); EXPECT_EQ(1, config_format_converter_called); EXPECT_NE(static_cast<byte_buffer*>(NULL), dev_stream->conv_buffer); // Converter tmp and output buffers are large enough for stream output. @@ -501,19 +504,19 @@ TEST_F(CreateSuite, CreateSRC48MonoFrom44StereoInput) { } TEST_F(CreateSuite, CaptureAvailConvBufHasSamples) { - struct dev_stream *dev_stream; + struct dev_stream* dev_stream; unsigned int avail; rstream_.format = fmt_s16le_48; rstream_.direction = CRAS_STREAM_INPUT; config_format_converter_conv = reinterpret_cast<struct cras_fmt_conv*>(0x33); - dev_stream = dev_stream_create(&rstream_, 0, &fmt_s16le_44_1, (void *)0x55, - &cb_ts); + dev_stream = + dev_stream_create(&rstream_, 0, &fmt_s16le_44_1, (void*)0x55, &cb_ts); EXPECT_EQ(1, config_format_converter_called); EXPECT_NE(static_cast<byte_buffer*>(NULL), dev_stream->conv_buffer); - EXPECT_LE(cras_frames_at_rate(in_fmt.frame_rate, kBufferFrames, - out_fmt.frame_rate), - dev_stream->conv_buffer_size_frames); + EXPECT_LE( + cras_frames_at_rate(in_fmt.frame_rate, kBufferFrames, out_fmt.frame_rate), + dev_stream->conv_buffer_size_frames); EXPECT_EQ(dev_stream->conv_buffer_size_frames * 4, dev_stream->conv_buffer->max_size); EXPECT_EQ(2, cras_audio_area_create_num_channels_val); @@ -527,16 +530,15 @@ TEST_F(CreateSuite, CaptureAvailConvBufHasSamples) { } TEST_F(CreateSuite, SetDevRateNotMasterDev) { - struct dev_stream *dev_stream; + struct dev_stream* dev_stream; unsigned int dev_id = 9; rstream_.format = fmt_s16le_48; rstream_.direction = CRAS_STREAM_INPUT; rstream_.master_dev.dev_id = 4; - config_format_converter_conv = - reinterpret_cast<struct cras_fmt_conv*>(0x33); + config_format_converter_conv = reinterpret_cast<struct cras_fmt_conv*>(0x33); dev_stream = dev_stream_create(&rstream_, dev_id, &fmt_s16le_44_1, - (void *)0x55, &cb_ts); + (void*)0x55, &cb_ts); dev_stream_set_dev_rate(dev_stream, 44100, 1.01, 1.0, 0); EXPECT_EQ(1, cras_fmt_conv_set_linear_resample_rates_called); @@ -556,17 +558,16 @@ TEST_F(CreateSuite, SetDevRateNotMasterDev) { } TEST_F(CreateSuite, SetDevRateMasterDev) { - struct dev_stream *dev_stream; + struct dev_stream* dev_stream; unsigned int dev_id = 9; unsigned int expected_ts_nsec; rstream_.format = fmt_s16le_48; rstream_.direction = CRAS_STREAM_INPUT; rstream_.master_dev.dev_id = dev_id; - config_format_converter_conv = - reinterpret_cast<struct cras_fmt_conv*>(0x33); + config_format_converter_conv = reinterpret_cast<struct cras_fmt_conv*>(0x33); dev_stream = dev_stream_create(&rstream_, dev_id, &fmt_s16le_44_1, - (void *)0x55, &cb_ts); + (void*)0x55, &cb_ts); dev_stream_set_dev_rate(dev_stream, 44100, 1.01, 1.0, 0); EXPECT_EQ(1, cras_fmt_conv_set_linear_resample_rates_called); @@ -651,16 +652,16 @@ TEST_F(CreateSuite, StreamMixNoConvTwoPass) { EXPECT_EQ(nfr / 2 * num_channels, mix_add_call.count); EXPECT_EQ(1, mix_add_call.index); EXPECT_EQ(dev_stream.stream, rstream_get_readable_call.rstream); - EXPECT_EQ(nfr/2, rstream_get_readable_call.offset); + EXPECT_EQ(nfr / 2, rstream_get_readable_call.offset); EXPECT_EQ(2, rstream_get_readable_call.num_called); } TEST_F(CreateSuite, DevStreamFlushAudioMessages) { - struct dev_stream *dev_stream; + struct dev_stream* dev_stream; unsigned int dev_id = 9; dev_stream = dev_stream_create(&rstream_, dev_id, &fmt_s16le_44_1, - (void *)0x55, &cb_ts); + (void*)0x55, &cb_ts); dev_stream_flush_old_audio_messages(dev_stream); EXPECT_EQ(1, cras_rstream_flush_old_audio_messages_called); @@ -668,11 +669,11 @@ TEST_F(CreateSuite, DevStreamFlushAudioMessages) { } TEST_F(CreateSuite, DevStreamIsPending) { - struct dev_stream *dev_stream; + struct dev_stream* dev_stream; unsigned int dev_id = 9; dev_stream = dev_stream_create(&rstream_, dev_id, &fmt_s16le_44_1, - (void *)0x55, &cb_ts); + (void*)0x55, &cb_ts); // dev_stream_is_pending_reply is only a wrapper. cras_rstream_is_pending_reply_ret = 0; @@ -685,7 +686,7 @@ TEST_F(CreateSuite, DevStreamIsPending) { } TEST_F(CreateSuite, StreamCanSend) { - struct dev_stream *dev_stream; + struct dev_stream* dev_stream; unsigned int dev_id = 9; int written_frames; int rc; @@ -693,7 +694,7 @@ TEST_F(CreateSuite, StreamCanSend) { rstream_.direction = CRAS_STREAM_INPUT; dev_stream = dev_stream_create(&rstream_, dev_id, &fmt_s16le_44_1, - (void *)0x55, &cb_ts); + (void*)0x55, &cb_ts); // Assume there is a next_cb_ts on rstream. rstream_.next_cb_ts.tv_sec = 1; @@ -749,8 +750,7 @@ TEST_F(CreateSuite, StreamCanSend) { // Check next_cb_ts is increased by one sleep interval. expected_next_cb_ts.tv_sec = 1; expected_next_cb_ts.tv_nsec = 0; - add_timespecs(&expected_next_cb_ts, - &rstream_.sleep_interval_ts); + add_timespecs(&expected_next_cb_ts, &rstream_.sleep_interval_ts); EXPECT_EQ(expected_next_cb_ts.tv_sec, rstream_.next_cb_ts.tv_sec); EXPECT_EQ(expected_next_cb_ts.tv_nsec, rstream_.next_cb_ts.tv_nsec); @@ -774,8 +774,7 @@ TEST_F(CreateSuite, StreamCanSend) { // Check next_cb_ts is rest to be now plus one sleep interval. expected_next_cb_ts.tv_sec = 2; expected_next_cb_ts.tv_nsec = 0; - add_timespecs(&expected_next_cb_ts, - &rstream_.sleep_interval_ts); + add_timespecs(&expected_next_cb_ts, &rstream_.sleep_interval_ts); EXPECT_EQ(expected_next_cb_ts.tv_sec, rstream_.next_cb_ts.tv_sec); EXPECT_EQ(expected_next_cb_ts.tv_nsec, rstream_.next_cb_ts.tv_nsec); @@ -783,7 +782,7 @@ TEST_F(CreateSuite, StreamCanSend) { } TEST_F(CreateSuite, StreamCanSendBulkAudio) { - struct dev_stream *dev_stream; + struct dev_stream* dev_stream; unsigned int dev_id = 9; int written_frames; int rc; @@ -792,7 +791,7 @@ TEST_F(CreateSuite, StreamCanSendBulkAudio) { rstream_.direction = CRAS_STREAM_INPUT; rstream_.flags |= BULK_AUDIO_OK; dev_stream = dev_stream_create(&rstream_, dev_id, &fmt_s16le_44_1, - (void *)0x55, &cb_ts); + (void*)0x55, &cb_ts); // Assume there is a next_cb_ts on rstream. rstream_.next_cb_ts.tv_sec = 1; @@ -852,8 +851,7 @@ TEST_F(CreateSuite, StreamCanSendBulkAudio) { // Check next_cb_ts is increased by one sleep interval. expected_next_cb_ts.tv_sec = 1; expected_next_cb_ts.tv_nsec = 0; - add_timespecs(&expected_next_cb_ts, - &rstream_.sleep_interval_ts); + add_timespecs(&expected_next_cb_ts, &rstream_.sleep_interval_ts); EXPECT_EQ(expected_next_cb_ts.tv_sec, rstream_.next_cb_ts.tv_sec); EXPECT_EQ(expected_next_cb_ts.tv_nsec, rstream_.next_cb_ts.tv_nsec); @@ -861,12 +859,12 @@ TEST_F(CreateSuite, StreamCanSendBulkAudio) { } TEST_F(CreateSuite, TriggerOnlyStreamSendOnlyOnce) { - struct dev_stream *dev_stream; + struct dev_stream* dev_stream; unsigned int dev_id = 9; rstream_.direction = CRAS_STREAM_INPUT; dev_stream = dev_stream_create(&rstream_, dev_id, &fmt_s16le_44_1, - (void *) 0x55, &cb_ts); + (void*)0x55, &cb_ts); dev_stream->stream->flags = TRIGGER_ONLY; dev_stream->stream->triggered = 0; @@ -888,7 +886,7 @@ TEST_F(CreateSuite, TriggerOnlyStreamSendOnlyOnce) { } TEST_F(CreateSuite, InputDevStreamWakeTimeByNextCbTs) { - struct dev_stream *dev_stream; + struct dev_stream* dev_stream; unsigned int dev_id = 9; int rc; unsigned int curr_level = 0; @@ -898,7 +896,7 @@ TEST_F(CreateSuite, InputDevStreamWakeTimeByNextCbTs) { rstream_.direction = CRAS_STREAM_INPUT; dev_stream = dev_stream_create(&rstream_, dev_id, &fmt_s16le_44_1, - (void *)0x55, &cb_ts); + (void*)0x55, &cb_ts); // Assume there is a next_cb_ts on rstream. rstream_.next_cb_ts.tv_sec = 1; @@ -908,9 +906,8 @@ TEST_F(CreateSuite, InputDevStreamWakeTimeByNextCbTs) { written_frames = rstream_.cb_threshold + 10; cras_shm_buffer_written(rstream_.shm, written_frames); - rc = dev_stream_wake_time(dev_stream, curr_level, - &level_tstamp, rstream_.cb_threshold, 0, - &wake_time_out); + rc = dev_stream_wake_time(dev_stream, curr_level, &level_tstamp, + rstream_.cb_threshold, 0, &wake_time_out); // The next wake up time is determined by next_cb_ts on dev_stream. EXPECT_EQ(rstream_.next_cb_ts.tv_sec, wake_time_out.tv_sec); @@ -920,7 +917,7 @@ TEST_F(CreateSuite, InputDevStreamWakeTimeByNextCbTs) { } TEST_F(CreateSuite, InputDevStreamWakeTimeByDevice) { - struct dev_stream *dev_stream; + struct dev_stream* dev_stream; unsigned int dev_id = 9; int rc; unsigned int curr_level = 100; @@ -932,12 +929,12 @@ TEST_F(CreateSuite, InputDevStreamWakeTimeByDevice) { int needed_frames_from_device = 0; rstream_.direction = CRAS_STREAM_INPUT; - dev_stream = dev_stream_create(&rstream_, dev_id, &fmt_s16le_48, - (void *)0x55, &cb_ts); + dev_stream = + dev_stream_create(&rstream_, dev_id, &fmt_s16le_48, (void*)0x55, &cb_ts); // Assume there is a next_cb_ts on rstream, that is, 1.005 seconds. rstream_.next_cb_ts.tv_sec = 1; - rstream_.next_cb_ts.tv_nsec = 5000000; // 5ms + rstream_.next_cb_ts.tv_nsec = 5000000; // 5ms // Assume there are not enough samples for stream. written_frames = 123; @@ -955,8 +952,8 @@ TEST_F(CreateSuite, InputDevStreamWakeTimeByDevice) { // Time for 252 samples = 324 / 48000 = 0.00675 sec. // So expected wake up time for samples is at level_tstamp + 0.00675 sec = // 1.00675 seconds. - needed_frames_from_device = cras_frames_at_rate( - 44100, rstream_.cb_threshold - written_frames, 48000); + needed_frames_from_device = + cras_frames_at_rate(44100, rstream_.cb_threshold - written_frames, 48000); needed_frames_from_device -= curr_level; cras_frames_to_time(needed_frames_from_device, 48000, &needed_time_for_device); @@ -970,9 +967,8 @@ TEST_F(CreateSuite, InputDevStreamWakeTimeByDevice) { out_fmt.frame_rate = 44100; in_fmt.frame_rate = 48000; - rc = dev_stream_wake_time(dev_stream, curr_level, - &level_tstamp, rstream_.cb_threshold, 0, - &wake_time_out); + rc = dev_stream_wake_time(dev_stream, curr_level, &level_tstamp, + rstream_.cb_threshold, 0, &wake_time_out); // The next wake up time is determined by needed time for device level // to reach enough samples for one cb_threshold. @@ -983,9 +979,8 @@ TEST_F(CreateSuite, InputDevStreamWakeTimeByDevice) { // Assume current level is larger than cb_threshold. // The wake up time is determined by next_cb_ts. curr_level += rstream_.cb_threshold; - rc = dev_stream_wake_time(dev_stream, curr_level, - &level_tstamp, rstream_.cb_threshold, 0, - &wake_time_out); + rc = dev_stream_wake_time(dev_stream, curr_level, &level_tstamp, + rstream_.cb_threshold, 0, &wake_time_out); EXPECT_EQ(rstream_.next_cb_ts.tv_sec, wake_time_out.tv_sec); EXPECT_EQ(rstream_.next_cb_ts.tv_nsec, wake_time_out.tv_nsec); EXPECT_EQ(0, rc); @@ -993,13 +988,13 @@ TEST_F(CreateSuite, InputDevStreamWakeTimeByDevice) { } TEST_F(CreateSuite, UpdateNextWakeTime) { - struct dev_stream *dev_stream; + struct dev_stream* dev_stream; unsigned int dev_id = 9; struct timespec expected_next_cb_ts; rstream_.direction = CRAS_STREAM_OUTPUT; dev_stream = dev_stream_create(&rstream_, dev_id, &fmt_s16le_44_1, - (void *) 0x55, &cb_ts); + (void*)0x55, &cb_ts); // Case 1: The new next_cb_ts is greater than now. Do not need to reschedule. rstream_.next_cb_ts.tv_sec = 2; @@ -1010,8 +1005,7 @@ TEST_F(CreateSuite, UpdateNextWakeTime) { dev_stream_update_next_wake_time(dev_stream); EXPECT_EQ(0, cras_server_metrics_missed_cb_event_called); - add_timespecs(&expected_next_cb_ts, - &rstream_.sleep_interval_ts); + add_timespecs(&expected_next_cb_ts, &rstream_.sleep_interval_ts); EXPECT_EQ(expected_next_cb_ts.tv_sec, rstream_.next_cb_ts.tv_sec); EXPECT_EQ(expected_next_cb_ts.tv_nsec, rstream_.next_cb_ts.tv_nsec); @@ -1024,8 +1018,7 @@ TEST_F(CreateSuite, UpdateNextWakeTime) { dev_stream_update_next_wake_time(dev_stream); EXPECT_EQ(1, cras_server_metrics_missed_cb_event_called); - add_timespecs(&expected_next_cb_ts, - &rstream_.sleep_interval_ts); + add_timespecs(&expected_next_cb_ts, &rstream_.sleep_interval_ts); EXPECT_EQ(expected_next_cb_ts.tv_sec, rstream_.next_cb_ts.tv_sec); EXPECT_EQ(expected_next_cb_ts.tv_nsec, rstream_.next_cb_ts.tv_nsec); dev_stream_destroy(dev_stream); @@ -1100,72 +1093,66 @@ TEST(DevStreamTimimg, SetCaptureTimeStampWrapPartial) { } TEST(MaxFramesForConverter, 8to48) { - EXPECT_EQ(481, max_frames_for_conversion(80, // Stream frames. - 8000, // Stream rate. + EXPECT_EQ(481, max_frames_for_conversion(80, // Stream frames. + 8000, // Stream rate. 48000)); // Device rate. } TEST(MaxFramesForConverter, 48to8) { - EXPECT_EQ(81, max_frames_for_conversion(80, // Stream frames. - 48000, // Stream rate. + EXPECT_EQ(81, max_frames_for_conversion(80, // Stream frames. + 48000, // Stream rate. 8000)); // Device rate. } /* Stubs */ extern "C" { -int cras_rstream_audio_ready(struct cras_rstream *stream, size_t count) { +int cras_rstream_audio_ready(struct cras_rstream* stream, size_t count) { cras_rstream_audio_ready_count = count; cras_rstream_audio_ready_called++; return 0; } -int cras_rstream_request_audio(struct cras_rstream *stream, - const struct timespec *now) { +int cras_rstream_request_audio(struct cras_rstream* stream, + const struct timespec* now) { return 0; } -void cras_rstream_record_fetch_interval(struct cras_rstream *rstream, - const struct timespec *now) { -} +void cras_rstream_record_fetch_interval(struct cras_rstream* rstream, + const struct timespec* now) {} -void cras_rstream_update_input_write_pointer(struct cras_rstream *rstream) { -} +void cras_rstream_update_input_write_pointer(struct cras_rstream* rstream) {} -void cras_rstream_update_output_read_pointer(struct cras_rstream *rstream) { -} +void cras_rstream_update_output_read_pointer(struct cras_rstream* rstream) {} -void cras_rstream_dev_offset_update(struct cras_rstream *rstream, - unsigned int frames, - unsigned int dev_id) { -} +void cras_rstream_dev_offset_update(struct cras_rstream* rstream, + unsigned int frames, + unsigned int dev_id) {} -void cras_rstream_dev_attach(struct cras_rstream *rstream, unsigned int dev_id, - void *dev_ptr) -{ -} +void cras_rstream_dev_attach(struct cras_rstream* rstream, + unsigned int dev_id, + void* dev_ptr) {} -void cras_rstream_dev_detach(struct cras_rstream *rstream, unsigned int dev_id) -{ -} +void cras_rstream_dev_detach(struct cras_rstream* rstream, + unsigned int dev_id) {} -unsigned int cras_rstream_dev_offset(const struct cras_rstream *rstream, +unsigned int cras_rstream_dev_offset(const struct cras_rstream* rstream, unsigned int dev_id) { return 0; } -unsigned int cras_rstream_playable_frames(struct cras_rstream *rstream, - unsigned int dev_id) { +unsigned int cras_rstream_playable_frames(struct cras_rstream* rstream, + unsigned int dev_id) { return rstream_playable_frames_ret; } -float cras_rstream_get_volume_scaler(struct cras_rstream *rstream) { +float cras_rstream_get_volume_scaler(struct cras_rstream* rstream) { return 1.0; } -uint8_t *cras_rstream_get_readable_frames(struct cras_rstream *rstream, +uint8_t* cras_rstream_get_readable_frames(struct cras_rstream* rstream, unsigned int offset, - size_t *frames) { + size_t* frames) { rstream_get_readable_call.rstream = rstream; rstream_get_readable_call.offset = offset; rstream_get_readable_call.num_called++; @@ -1173,24 +1160,22 @@ uint8_t *cras_rstream_get_readable_frames(struct cras_rstream *rstream, return rstream_get_readable_ptr; } -int cras_rstream_get_mute(const struct cras_rstream *rstream) { +int cras_rstream_get_mute(const struct cras_rstream* rstream) { return 0; } -void cras_rstream_update_queued_frames(struct cras_rstream *rstream) -{ -} +void cras_rstream_update_queued_frames(struct cras_rstream* rstream) {} -struct cras_audio_format *cras_rstream_post_processing_format( - const struct cras_rstream *stream, void *dev_ptr) -{ +struct cras_audio_format* cras_rstream_post_processing_format( + const struct cras_rstream* stream, + void* dev_ptr) { return cras_rstream_post_processing_format_val; } -int config_format_converter(struct cras_fmt_conv **conv, - enum CRAS_STREAM_DIRECTION dir, - const struct cras_audio_format *from, - const struct cras_audio_format *to, - unsigned int frames) { +int config_format_converter(struct cras_fmt_conv** conv, + enum CRAS_STREAM_DIRECTION dir, + const struct cras_audio_format* from, + const struct cras_audio_format* to, + unsigned int frames) { config_format_converter_called++; config_format_converter_from_fmt = from; config_format_converter_frames = frames; @@ -1198,65 +1183,62 @@ int config_format_converter(struct cras_fmt_conv **conv, return 0; } -void cras_fmt_conv_destroy(struct cras_fmt_conv *conv) { -} +void cras_fmt_conv_destroy(struct cras_fmt_conv* conv) {} -size_t cras_fmt_conv_convert_frames(struct cras_fmt_conv *conv, - uint8_t *in_buf, - uint8_t *out_buf, - unsigned int *in_frames, - unsigned int out_frames) { +size_t cras_fmt_conv_convert_frames(struct cras_fmt_conv* conv, + uint8_t* in_buf, + uint8_t* out_buf, + unsigned int* in_frames, + unsigned int out_frames) { unsigned int ret; conv_frames_call.conv = conv; conv_frames_call.in_buf = in_buf; conv_frames_call.out_buf = out_buf; conv_frames_call.in_frames = *in_frames; - ret = cras_frames_at_rate(in_fmt.frame_rate, - *in_frames, - out_fmt.frame_rate); + ret = cras_frames_at_rate(in_fmt.frame_rate, *in_frames, out_fmt.frame_rate); conv_frames_call.out_frames = out_frames; if (ret > out_frames) { ret = out_frames; - *in_frames = cras_frames_at_rate( - out_fmt.frame_rate, - ret, in_fmt.frame_rate); + *in_frames = + cras_frames_at_rate(out_fmt.frame_rate, ret, in_fmt.frame_rate); } return ret; } -void cras_mix_add(snd_pcm_format_t fmt, uint8_t *dst, uint8_t *src, - unsigned int count, unsigned int index, - int mute, float mix_vol) { - mix_add_call.dst = (int16_t *)dst; - mix_add_call.src = (int16_t *)src; +void cras_mix_add(snd_pcm_format_t fmt, + uint8_t* dst, + uint8_t* src, + unsigned int count, + unsigned int index, + int mute, + float mix_vol) { + mix_add_call.dst = (int16_t*)dst; + mix_add_call.src = (int16_t*)src; mix_add_call.count = count; mix_add_call.index = index; mix_add_call.mute = mute; mix_add_call.mix_vol = mix_vol; } -struct cras_audio_area *cras_audio_area_create(int num_channels) { +struct cras_audio_area* cras_audio_area_create(int num_channels) { cras_audio_area_create_num_channels_val = num_channels; return NULL; } -void cras_audio_area_destroy(struct cras_audio_area *area) { -} +void cras_audio_area_destroy(struct cras_audio_area* area) {} -void cras_audio_area_config_buf_pointers(struct cras_audio_area *area, - const struct cras_audio_format *fmt, - uint8_t *base_buffer) { -} +void cras_audio_area_config_buf_pointers(struct cras_audio_area* area, + const struct cras_audio_format* fmt, + uint8_t* base_buffer) {} -void cras_audio_area_config_channels(struct cras_audio_area *area, - const struct cras_audio_format *fmt) { -} +void cras_audio_area_config_channels(struct cras_audio_area* area, + const struct cras_audio_format* fmt) {} -unsigned int cras_audio_area_copy(const struct cras_audio_area *dst, +unsigned int cras_audio_area_copy(const struct cras_audio_area* dst, unsigned int dst_offset, - const struct cras_audio_format *dst_fmt, - const struct cras_audio_area *src, + const struct cras_audio_format* dst_fmt, + const struct cras_audio_area* src, unsigned int src_offset, float software_gain_scaler) { copy_area_call.dst = dst; @@ -1268,52 +1250,43 @@ unsigned int cras_audio_area_copy(const struct cras_audio_area *dst, return src->frames; } -size_t cras_fmt_conv_in_frames_to_out(struct cras_fmt_conv *conv, - size_t in_frames) -{ - return cras_frames_at_rate(in_fmt.frame_rate, - in_frames, - out_fmt.frame_rate); +size_t cras_fmt_conv_in_frames_to_out(struct cras_fmt_conv* conv, + size_t in_frames) { + return cras_frames_at_rate(in_fmt.frame_rate, in_frames, out_fmt.frame_rate); } -size_t cras_fmt_conv_out_frames_to_in(struct cras_fmt_conv *conv, +size_t cras_fmt_conv_out_frames_to_in(struct cras_fmt_conv* conv, size_t out_frames) { - return cras_frames_at_rate(out_fmt.frame_rate, - out_frames, - in_fmt.frame_rate); + return cras_frames_at_rate(out_fmt.frame_rate, out_frames, in_fmt.frame_rate); } -const struct cras_audio_format *cras_fmt_conv_in_format( - const struct cras_fmt_conv *conv) { +const struct cras_audio_format* cras_fmt_conv_in_format( + const struct cras_fmt_conv* conv) { return &in_fmt; } -const struct cras_audio_format *cras_fmt_conv_out_format( - const struct cras_fmt_conv *conv) { +const struct cras_audio_format* cras_fmt_conv_out_format( + const struct cras_fmt_conv* conv) { return &out_fmt; } -int cras_fmt_conversion_needed(const struct cras_fmt_conv *conv) -{ +int cras_fmt_conversion_needed(const struct cras_fmt_conv* conv) { return cras_fmt_conversion_needed_val; } -void cras_fmt_conv_set_linear_resample_rates(struct cras_fmt_conv *conv, +void cras_fmt_conv_set_linear_resample_rates(struct cras_fmt_conv* conv, float from, - float to) -{ + float to) { cras_fmt_conv_set_linear_resample_rates_from = from; cras_fmt_conv_set_linear_resample_rates_to = to; cras_fmt_conv_set_linear_resample_rates_called++; } -int cras_rstream_is_pending_reply(const struct cras_rstream *stream) -{ +int cras_rstream_is_pending_reply(const struct cras_rstream* stream) { return cras_rstream_is_pending_reply_ret; } -int cras_rstream_flush_old_audio_messages(struct cras_rstream *stream) -{ +int cras_rstream_flush_old_audio_messages(struct cras_rstream* stream) { cras_rstream_flush_old_audio_messages_called++; return 0; } @@ -1334,7 +1307,7 @@ int clock_gettime(clockid_t clk_id, struct timespec* tp) { } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/device_blacklist_unittest.cc b/cras/src/tests/device_blacklist_unittest.cc index 812ac4cc..2c1edf06 100644 --- a/cras/src/tests/device_blacklist_unittest.cc +++ b/cras/src/tests/device_blacklist_unittest.cc @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <stdio.h> #include <gtest/gtest.h> +#include <stdio.h> extern "C" { #include "cras_device_blacklist.h" @@ -30,7 +30,7 @@ void CreateConfigFile(const char* config_text) { TEST(Blacklist, EmptyBlacklist) { static const char empty_config_text[] = ""; - struct cras_device_blacklist *blacklist; + struct cras_device_blacklist* blacklist; CreateConfigFile(empty_config_text); @@ -45,7 +45,7 @@ TEST(Blacklist, BlackListOneUsbOutput) { static const char usb_output_config_text[] = "[USB_Outputs]\n" "0d8c_0008_00000012_0 = 1\n"; - struct cras_device_blacklist *blacklist; + struct cras_device_blacklist* blacklist; CreateConfigFile(usb_output_config_text); @@ -66,7 +66,7 @@ TEST(Blacklist, BlackListTwoUsbOutput) { "[USB_Outputs]\n" "0d8c_0008_00000000_0 = 1\n" "0d8c_0009_00000000_0 = 1\n"; - struct cras_device_blacklist *blacklist; + struct cras_device_blacklist* blacklist; CreateConfigFile(usb_output_config_text); @@ -82,7 +82,7 @@ TEST(Blacklist, BlackListTwoUsbOutput) { } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/device_monitor_unittest.cc b/cras/src/tests/device_monitor_unittest.cc index 628702c6..31c2e8c6 100644 --- a/cras/src/tests/device_monitor_unittest.cc +++ b/cras/src/tests/device_monitor_unittest.cc @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <stdio.h> #include <gtest/gtest.h> +#include <stdio.h> extern "C" { #include "cras_device_monitor.c" @@ -12,7 +12,7 @@ extern "C" { } static enum CRAS_MAIN_MESSAGE_TYPE type_set; -static struct cras_device_monitor_message *sent_msg; +static struct cras_device_monitor_message* sent_msg; static int resume_dev_called; unsigned int resume_dev_idx; static int suspend_dev_called; @@ -44,7 +44,7 @@ TEST(DeviceMonitorTestSuite, Init) { TEST(DeviceMonitorTestSuite, ResetDevice) { ResetStubData(); // sent_msg will be filled with message content in cras_main_message_send. - sent_msg = (struct cras_device_monitor_message *)calloc(1, sizeof(*sent_msg)); + sent_msg = (struct cras_device_monitor_message*)calloc(1, sizeof(*sent_msg)); cras_device_monitor_reset_device(fake_dev_idx); @@ -58,8 +58,8 @@ TEST(DeviceMonitorTestSuite, ResetDevice) { TEST(DeviceMonitorTestSuite, HandleResetDevice) { struct cras_device_monitor_message msg; - struct cras_main_message *main_message = - reinterpret_cast<struct cras_main_message *>(&msg); + struct cras_main_message* main_message = + reinterpret_cast<struct cras_main_message*>(&msg); ResetStubData(); @@ -79,7 +79,7 @@ TEST(DeviceMonitorTestSuite, HandleResetDevice) { TEST(DeviceMonitorTestSuite, MuteDevice) { ResetStubData(); // sent_msg will be filled with message content in cras_main_message_send. - sent_msg = (struct cras_device_monitor_message *)calloc(1, sizeof(*sent_msg)); + sent_msg = (struct cras_device_monitor_message*)calloc(1, sizeof(*sent_msg)); cras_device_monitor_set_device_mute_state(fake_dev_idx); @@ -93,8 +93,8 @@ TEST(DeviceMonitorTestSuite, MuteDevice) { TEST(DeviceMonitorTestSuite, HandleMuteDevice) { struct cras_device_monitor_message msg; - struct cras_main_message *main_message = - reinterpret_cast<struct cras_main_message *>(&msg); + struct cras_main_message* main_message = + reinterpret_cast<struct cras_main_message*>(&msg); ResetStubData(); @@ -113,12 +113,12 @@ extern "C" { int cras_main_message_add_handler(enum CRAS_MAIN_MESSAGE_TYPE type, cras_message_callback callback, - void *callback_data) { + void* callback_data) { type_set = type; return 0; } -int cras_main_message_send(struct cras_main_message *msg) { +int cras_main_message_send(struct cras_main_message* msg) { // Copy the sent message so we can examine it in the test later. memcpy(sent_msg, msg, sizeof(*sent_msg)); return 0; @@ -142,7 +142,7 @@ void cras_iodev_list_set_dev_mute(unsigned int dev_idx) { } // extern "C" } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); int rc = RUN_ALL_TESTS(); diff --git a/cras/src/tests/dsp_core_unittest.cc b/cras/src/tests/dsp_core_unittest.cc index 09577950..82c7957b 100644 --- a/cras/src/tests/dsp_core_unittest.cc +++ b/cras/src/tests/dsp_core_unittest.cc @@ -4,6 +4,7 @@ #include <gtest/gtest.h> #include <math.h> + #include "crossover.h" #include "crossover2.h" #include "drc.h" @@ -14,17 +15,18 @@ namespace { /* Adds amplitude * sin(pi*freq*i + offset) to the data array. */ -static void add_sine(float *data, size_t len, float freq, float offset, - float amplitude) -{ +static void add_sine(float* data, + size_t len, + float freq, + float offset, + float amplitude) { for (size_t i = 0; i < len; i++) - data[i] += amplitude * sinf((float)M_PI*freq*i + offset); + data[i] += amplitude * sinf((float)M_PI * freq * i + offset); } /* Calculates the magnitude at normalized frequency f. The output is * the result of DFT, multiplied by 2/len. */ -static float magnitude_at(float *data, size_t len, float f) -{ +static float magnitude_at(float* data, size_t len, float f) { double re = 0, im = 0; f *= (float)M_PI; for (size_t i = 0; i < len; i++) { @@ -41,49 +43,66 @@ TEST(InterleaveTest, All) { /* Repeat the same data twice, so it will exercise neon/sse * optimized functions. */ int16_t input[SAMPLES] = { - -32768, -32767, -32766, -2, -1, 0, 1, 2, 3, 32765, 32766, 32767, - -32768, -32767, -32766, -2, -1, 0, 1, 2, 3, 32765, 32766, 32767 - }; - - float answer[SAMPLES] = { - -1, -32766/32768.0f, -1/32768.0f, 1/32768.0f, 3/32768.0f, 32766/32768.0f, - -1, -32766/32768.0f, -1/32768.0f, 1/32768.0f, 3/32768.0f, 32766/32768.0f, - -32767/32768.0f, -2/32768.0f, 0, 2/32768.0f, 32765/32768.0f, 32767/32768.0f, - -32767/32768.0f, -2/32768.0f, 0, 2/32768.0f, 32765/32768.0f, 32767/32768.0f - }; + -32768, -32767, -32766, -2, -1, 0, 1, 2, 3, 32765, 32766, 32767, + -32768, -32767, -32766, -2, -1, 0, 1, 2, 3, 32765, 32766, 32767}; + + float answer[SAMPLES] = {-1, + -32766 / 32768.0f, + -1 / 32768.0f, + 1 / 32768.0f, + 3 / 32768.0f, + 32766 / 32768.0f, + -1, + -32766 / 32768.0f, + -1 / 32768.0f, + 1 / 32768.0f, + 3 / 32768.0f, + 32766 / 32768.0f, + -32767 / 32768.0f, + -2 / 32768.0f, + 0, + 2 / 32768.0f, + 32765 / 32768.0f, + 32767 / 32768.0f, + -32767 / 32768.0f, + -2 / 32768.0f, + 0, + 2 / 32768.0f, + 32765 / 32768.0f, + 32767 / 32768.0f}; float output[SAMPLES]; - float *out_ptr[] = {output, output + FRAMES}; + float* out_ptr[] = {output, output + FRAMES}; - dsp_util_deinterleave((uint8_t *)input, out_ptr, 2, - SND_PCM_FORMAT_S16_LE, FRAMES); + dsp_util_deinterleave((uint8_t*)input, out_ptr, 2, SND_PCM_FORMAT_S16_LE, + FRAMES); - for (int i = 0 ; i < SAMPLES; i++) { + for (int i = 0; i < SAMPLES; i++) { EXPECT_EQ(answer[i], output[i]); } /* dsp_util_interleave() should round to nearest number. */ - for (int i = 0 ; i < SAMPLES; i += 2) { + for (int i = 0; i < SAMPLES; i += 2) { output[i] += 0.499 / 32768.0f; output[i + 1] -= 0.499 / 32768.0f; } int16_t output2[SAMPLES]; - dsp_util_interleave(out_ptr, (uint8_t *)output2, 2, - SND_PCM_FORMAT_S16_LE, FRAMES); - for (int i = 0 ; i < SAMPLES; i++) { + dsp_util_interleave(out_ptr, (uint8_t*)output2, 2, SND_PCM_FORMAT_S16_LE, + FRAMES); + for (int i = 0; i < SAMPLES; i++) { EXPECT_EQ(input[i], output2[i]); } } TEST(EqTest, All) { - struct eq *eq; + struct eq* eq; size_t len = 44100; float NQ = len / 2; float f_low = 10 / NQ; float f_mid = 100 / NQ; float f_high = 1000 / NQ; - float *data = (float *)malloc(sizeof(float) * len); + float* data = (float*)malloc(sizeof(float) * len); dsp_enable_flush_denormal_to_zero(); /* low pass */ @@ -123,7 +142,8 @@ TEST(EqTest, All) { add_sine(data, len, f_high, 0, 1); eq = eq_new(); - EXPECT_EQ(0, eq_append_biquad(eq, BQ_PEAKING, f_high, 5, 6)); // Q=5, 6dB gain + EXPECT_EQ(0, + eq_append_biquad(eq, BQ_PEAKING, f_high, 5, 6)); // Q=5, 6dB gain eq_process(eq, data, len); EXPECT_NEAR(1, magnitude_at(data, len, f_low), 0.01); EXPECT_NEAR(2, magnitude_at(data, len, f_high), 0.01); @@ -141,23 +161,23 @@ TEST(EqTest, All) { } TEST(Eq2Test, All) { - struct eq2 *eq2; + struct eq2* eq2; size_t len = 44100; float NQ = len / 2; float f_low = 10 / NQ; float f_mid = 100 / NQ; float f_high = 1000 / NQ; - float *data0 = (float *)malloc(sizeof(float) * len); - float *data1 = (float *)malloc(sizeof(float) * len); + float* data0 = (float*)malloc(sizeof(float) * len); + float* data1 = (float*)malloc(sizeof(float) * len); dsp_enable_flush_denormal_to_zero(); /* a mixture of 10Hz an 1000Hz sine */ memset(data0, 0, sizeof(float) * len); memset(data1, 0, sizeof(float) * len); - add_sine(data0, len, f_low, 0, 1); // 10Hz sine, magnitude = 1 + add_sine(data0, len, f_low, 0, 1); // 10Hz sine, magnitude = 1 add_sine(data0, len, f_high, 0, 1); // 1000Hz sine, magnitude = 1 - add_sine(data1, len, f_low, 0, 1); // 10Hz sine, magnitude = 1 + add_sine(data1, len, f_low, 0, 1); // 10Hz sine, magnitude = 1 add_sine(data1, len, f_high, 0, 1); // 1000Hz sine, magnitude = 1 /* low pass at left and high pass at right */ @@ -218,9 +238,9 @@ TEST(CrossoverTest, All) { float f2 = 1000 / NQ; float f3 = 4000 / NQ; float f4 = 16000 / NQ; - float *data = (float *)malloc(sizeof(float) * len); - float *data1 = (float *)malloc(sizeof(float) * len); - float *data2 = (float *)malloc(sizeof(float) * len); + float* data = (float*)malloc(sizeof(float) * len); + float* data1 = (float*)malloc(sizeof(float) * len); + float* data2 = (float*)malloc(sizeof(float) * len); dsp_enable_flush_denormal_to_zero(); crossover_init(&xo, f1, f3); @@ -263,12 +283,12 @@ TEST(Crossover2Test, All) { float f2 = 1000 / NQ; float f3 = 4000 / NQ; float f4 = 16000 / NQ; - float *data0L = (float *)malloc(sizeof(float) * len); - float *data1L = (float *)malloc(sizeof(float) * len); - float *data2L = (float *)malloc(sizeof(float) * len); - float *data0R = (float *)malloc(sizeof(float) * len); - float *data1R = (float *)malloc(sizeof(float) * len); - float *data2R = (float *)malloc(sizeof(float) * len); + float* data0L = (float*)malloc(sizeof(float) * len); + float* data1L = (float*)malloc(sizeof(float) * len); + float* data2L = (float*)malloc(sizeof(float) * len); + float* data0R = (float*)malloc(sizeof(float) * len); + float* data1R = (float*)malloc(sizeof(float) * len); + float* data2R = (float*)malloc(sizeof(float) * len); dsp_enable_flush_denormal_to_zero(); crossover2_init(&xo2, f1, f3); @@ -334,11 +354,11 @@ TEST(DrcTest, All) { float f2 = 1000 / NQ; float f3 = 4000 / NQ; float f4 = 16000 / NQ; - float *data_left = (float *)malloc(sizeof(float) * len); - float *data_right = (float *)malloc(sizeof(float) * len); - float *data[] = {data_left, data_right}; - float *data_empty[] = {NULL, NULL}; - struct drc *drc; + float* data_left = (float*)malloc(sizeof(float) * len); + float* data_right = (float*)malloc(sizeof(float) * len); + float* data[] = {data_left, data_right}; + float* data_empty[] = {NULL, NULL}; + struct drc* drc; dsp_enable_flush_denormal_to_zero(); drc = drc_new(44100); @@ -407,7 +427,7 @@ TEST(DrcTest, All) { } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/dsp_ini_unittest.cc b/cras/src/tests/dsp_ini_unittest.cc index b7f488de..ee187906 100644 --- a/cras/src/tests/dsp_ini_unittest.cc +++ b/cras/src/tests/dsp_ini_unittest.cc @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <gtest/gtest.h> #include <stdio.h> #include <stdlib.h> -#include <gtest/gtest.h> #include "cras_dsp_ini.h" @@ -15,7 +15,7 @@ namespace { class DspIniTestSuite : public testing::Test { protected: virtual void SetUp() { - strcpy(filename, FILENAME_TEMPLATE); + strcpy(filename, FILENAME_TEMPLATE); int fd = mkstemp(filename); fp = fdopen(fd, "w"); } @@ -33,11 +33,11 @@ class DspIniTestSuite : public testing::Test { } char filename[sizeof(FILENAME_TEMPLATE) + 1]; - FILE *fp; + FILE* fp; }; TEST_F(DspIniTestSuite, EmptyIni) { - struct ini *ini = cras_dsp_ini_create(filename); + struct ini* ini = cras_dsp_ini_create(filename); EXPECT_EQ(0, ARRAY_COUNT(&ini->plugins)); EXPECT_EQ(0, ARRAY_COUNT(&ini->flows)); cras_dsp_ini_free(ini); @@ -47,7 +47,7 @@ TEST_F(DspIniTestSuite, NoLibraryOrLabel) { fprintf(fp, "[Test]\n"); CloseFile(); - struct ini *ini = cras_dsp_ini_create(filename); + struct ini* ini = cras_dsp_ini_create(filename); /* NULL because a plugin doesn't have library or label */ EXPECT_EQ(NULL, ini); } @@ -59,11 +59,11 @@ TEST_F(DspIniTestSuite, OneSimplePlugin) { fprintf(fp, "disable=\"#f\"\n"); CloseFile(); - struct ini *ini = cras_dsp_ini_create(filename); + struct ini* ini = cras_dsp_ini_create(filename); EXPECT_EQ(1, ARRAY_COUNT(&ini->plugins)); EXPECT_EQ(0, ARRAY_COUNT(&ini->flows)); - struct plugin *plugin = ARRAY_ELEMENT(&ini->plugins, 0); + struct plugin* plugin = ARRAY_ELEMENT(&ini->plugins, 0); EXPECT_STREQ("test", plugin->title); EXPECT_STREQ("foo.so", plugin->library); EXPECT_STREQ("bar", plugin->label); @@ -84,7 +84,7 @@ TEST_F(DspIniTestSuite, BuiltinPlugin) { fprintf(fp, "purpose=capture\n"); CloseFile(); - struct ini *ini = cras_dsp_ini_create(filename); + struct ini* ini = cras_dsp_ini_create(filename); EXPECT_EQ(2, ARRAY_COUNT(&ini->plugins)); EXPECT_EQ(0, ARRAY_COUNT(&ini->flows)); EXPECT_STREQ(ARRAY_ELEMENT(&ini->plugins, 0)->purpose, "playback"); @@ -99,12 +99,12 @@ TEST_F(DspIniTestSuite, Ports) { fprintf(fp, "input_0=10\n"); CloseFile(); - struct ini *ini = cras_dsp_ini_create(filename); + struct ini* ini = cras_dsp_ini_create(filename); EXPECT_EQ(1, ARRAY_COUNT(&ini->plugins)); EXPECT_EQ(0, ARRAY_COUNT(&ini->flows)); - struct plugin *plugin = ARRAY_ELEMENT(&ini->plugins, 0); + struct plugin* plugin = ARRAY_ELEMENT(&ini->plugins, 0); EXPECT_EQ(1, ARRAY_COUNT(&plugin->ports)); - struct port *port = ARRAY_ELEMENT(&plugin->ports, 0); + struct port* port = ARRAY_ELEMENT(&plugin->ports, 0); EXPECT_EQ(PORT_INPUT, port->direction); EXPECT_EQ(PORT_CONTROL, port->type); EXPECT_EQ(INVALID_FLOW_ID, port->flow_id); @@ -126,15 +126,15 @@ TEST_F(DspIniTestSuite, Flows) { CloseFile(); - struct ini *ini = cras_dsp_ini_create(filename); + struct ini* ini = cras_dsp_ini_create(filename); EXPECT_EQ(2, ARRAY_COUNT(&ini->plugins)); - struct plugin *foo = ARRAY_ELEMENT(&ini->plugins, 0); - struct plugin *bar = ARRAY_ELEMENT(&ini->plugins, 1); + struct plugin* foo = ARRAY_ELEMENT(&ini->plugins, 0); + struct plugin* bar = ARRAY_ELEMENT(&ini->plugins, 1); EXPECT_EQ(2, ARRAY_COUNT(&foo->ports)); EXPECT_EQ(2, ARRAY_COUNT(&bar->ports)); - struct port *foo0 = ARRAY_ELEMENT(&foo->ports, 0); - struct port *foo1 = ARRAY_ELEMENT(&foo->ports, 1); + struct port* foo0 = ARRAY_ELEMENT(&foo->ports, 0); + struct port* foo1 = ARRAY_ELEMENT(&foo->ports, 1); EXPECT_EQ(PORT_OUTPUT, foo0->direction); EXPECT_EQ(PORT_CONTROL, foo0->type); EXPECT_EQ(PORT_OUTPUT, foo1->direction); @@ -142,8 +142,8 @@ TEST_F(DspIniTestSuite, Flows) { EXPECT_EQ(0, foo0->flow_id); EXPECT_EQ(1, foo1->flow_id); - struct port *bar0 = ARRAY_ELEMENT(&bar->ports, 0); - struct port *bar1 = ARRAY_ELEMENT(&bar->ports, 1); + struct port* bar0 = ARRAY_ELEMENT(&bar->ports, 0); + struct port* bar1 = ARRAY_ELEMENT(&bar->ports, 1); EXPECT_EQ(PORT_INPUT, bar0->direction); EXPECT_EQ(PORT_AUDIO, bar0->type); EXPECT_EQ(PORT_INPUT, bar1->direction); @@ -152,8 +152,8 @@ TEST_F(DspIniTestSuite, Flows) { EXPECT_EQ(0, bar1->flow_id); EXPECT_EQ(2, ARRAY_COUNT(&ini->flows)); - struct flow *flow0 = ARRAY_ELEMENT(&ini->flows, 0); - struct flow *flow1 = ARRAY_ELEMENT(&ini->flows, 1); + struct flow* flow0 = ARRAY_ELEMENT(&ini->flows, 0); + struct flow* flow1 = ARRAY_ELEMENT(&ini->flows, 1); EXPECT_EQ(PORT_CONTROL, flow0->type); EXPECT_STREQ("<control>", flow0->name); @@ -175,7 +175,6 @@ TEST_F(DspIniTestSuite, Flows) { } TEST_F(DspIniTestSuite, TwoChannelWithSwap) { - /* * Stated in ini: * @@ -187,7 +186,7 @@ TEST_F(DspIniTestSuite, TwoChannelWithSwap) { * */ - const char *content = + const char* content = "[M0]\n" "library=builtin\n" "label=source\n" @@ -211,33 +210,33 @@ TEST_F(DspIniTestSuite, TwoChannelWithSwap) { fprintf(fp, "%s", content); CloseFile(); - struct ini *ini = cras_dsp_ini_create(filename); + struct ini* ini = cras_dsp_ini_create(filename); /* 3 plugins and 1 swap_lr plugin. */ EXPECT_EQ(4, ARRAY_COUNT(&ini->plugins)); - struct plugin *m0= ARRAY_ELEMENT(&ini->plugins, 0); - struct plugin *m1 = ARRAY_ELEMENT(&ini->plugins, 1); - struct plugin *m2 = ARRAY_ELEMENT(&ini->plugins, 2); - struct plugin *m_swap_lr = ARRAY_ELEMENT(&ini->plugins, 3); + struct plugin* m0 = ARRAY_ELEMENT(&ini->plugins, 0); + struct plugin* m1 = ARRAY_ELEMENT(&ini->plugins, 1); + struct plugin* m2 = ARRAY_ELEMENT(&ini->plugins, 2); + struct plugin* m_swap_lr = ARRAY_ELEMENT(&ini->plugins, 3); EXPECT_EQ(2, ARRAY_COUNT(&m0->ports)); EXPECT_EQ(4, ARRAY_COUNT(&m1->ports)); EXPECT_EQ(4, ARRAY_COUNT(&m_swap_lr->ports)); EXPECT_EQ(2, ARRAY_COUNT(&m2->ports)); - struct port *m0_0 = ARRAY_ELEMENT(&m0->ports, 0); - struct port *m0_1 = ARRAY_ELEMENT(&m0->ports, 1); - struct port *m1_0 = ARRAY_ELEMENT(&m1->ports, 0); - struct port *m1_1 = ARRAY_ELEMENT(&m1->ports, 1); - struct port *m1_2 = ARRAY_ELEMENT(&m1->ports, 2); - struct port *m1_3 = ARRAY_ELEMENT(&m1->ports, 3); - struct port *m_swap_lr_0 = ARRAY_ELEMENT(&m_swap_lr->ports, 0); - struct port *m_swap_lr_1 = ARRAY_ELEMENT(&m_swap_lr->ports, 1); - struct port *m_swap_lr_2 = ARRAY_ELEMENT(&m_swap_lr->ports, 2); - struct port *m_swap_lr_3 = ARRAY_ELEMENT(&m_swap_lr->ports, 3); - struct port *m2_0 = ARRAY_ELEMENT(&m2->ports, 0); - struct port *m2_1 = ARRAY_ELEMENT(&m2->ports, 1); + struct port* m0_0 = ARRAY_ELEMENT(&m0->ports, 0); + struct port* m0_1 = ARRAY_ELEMENT(&m0->ports, 1); + struct port* m1_0 = ARRAY_ELEMENT(&m1->ports, 0); + struct port* m1_1 = ARRAY_ELEMENT(&m1->ports, 1); + struct port* m1_2 = ARRAY_ELEMENT(&m1->ports, 2); + struct port* m1_3 = ARRAY_ELEMENT(&m1->ports, 3); + struct port* m_swap_lr_0 = ARRAY_ELEMENT(&m_swap_lr->ports, 0); + struct port* m_swap_lr_1 = ARRAY_ELEMENT(&m_swap_lr->ports, 1); + struct port* m_swap_lr_2 = ARRAY_ELEMENT(&m_swap_lr->ports, 2); + struct port* m_swap_lr_3 = ARRAY_ELEMENT(&m_swap_lr->ports, 3); + struct port* m2_0 = ARRAY_ELEMENT(&m2->ports, 0); + struct port* m2_1 = ARRAY_ELEMENT(&m2->ports, 1); /* flow flow_id from port to port * ------------------------------------------------------------ @@ -261,12 +260,12 @@ TEST_F(DspIniTestSuite, TwoChannelWithSwap) { EXPECT_EQ(4, m2_0->flow_id); EXPECT_EQ(5, m2_1->flow_id); - struct flow *flow_a0 = ARRAY_ELEMENT(&ini->flows, 0); - struct flow *flow_a1 = ARRAY_ELEMENT(&ini->flows, 1); - struct flow *flow_b0 = ARRAY_ELEMENT(&ini->flows, 2); - struct flow *flow_b1 = ARRAY_ELEMENT(&ini->flows, 3); - struct flow *flow_swap_lr_0 = ARRAY_ELEMENT(&ini->flows, 4); - struct flow *flow_swap_lr_1 = ARRAY_ELEMENT(&ini->flows, 5); + struct flow* flow_a0 = ARRAY_ELEMENT(&ini->flows, 0); + struct flow* flow_a1 = ARRAY_ELEMENT(&ini->flows, 1); + struct flow* flow_b0 = ARRAY_ELEMENT(&ini->flows, 2); + struct flow* flow_b1 = ARRAY_ELEMENT(&ini->flows, 3); + struct flow* flow_swap_lr_0 = ARRAY_ELEMENT(&ini->flows, 4); + struct flow* flow_swap_lr_1 = ARRAY_ELEMENT(&ini->flows, 5); EXPECT_EQ(flow_a0->from, m0); EXPECT_EQ(flow_a0->from_port, 0); @@ -303,7 +302,7 @@ TEST_F(DspIniTestSuite, TwoChannelWithSwap) { } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/dsp_unittest.cc b/cras/src/tests/dsp_unittest.cc index 22029905..b1f4c4ee 100644 --- a/cras/src/tests/dsp_unittest.cc +++ b/cras/src/tests/dsp_unittest.cc @@ -12,8 +12,7 @@ namespace { extern "C" { -struct dsp_module *cras_dsp_module_load_ladspa(struct plugin *plugin) -{ +struct dsp_module* cras_dsp_module_load_ladspa(struct plugin* plugin) { return NULL; } } @@ -21,7 +20,7 @@ struct dsp_module *cras_dsp_module_load_ladspa(struct plugin *plugin) class DspTestSuite : public testing::Test { protected: virtual void SetUp() { - strcpy(filename, FILENAME_TEMPLATE); + strcpy(filename, FILENAME_TEMPLATE); int fd = mkstemp(filename); fp = fdopen(fd, "w"); } @@ -39,11 +38,11 @@ class DspTestSuite : public testing::Test { } char filename[sizeof(FILENAME_TEMPLATE) + 1]; - FILE *fp; + FILE* fp; }; TEST_F(DspTestSuite, Simple) { - const char *content = + const char* content = "[M1]\n" "library=builtin\n" "label=source\n" @@ -61,12 +60,12 @@ TEST_F(DspTestSuite, Simple) { cras_dsp_init(filename); struct cras_dsp_context *ctx1, *ctx3, *ctx4; - ctx1 = cras_dsp_context_new(44100, "playback"); /* wrong purpose */ + ctx1 = cras_dsp_context_new(44100, "playback"); /* wrong purpose */ ctx3 = cras_dsp_context_new(44100, "capture"); ctx4 = cras_dsp_context_new(44100, "capture"); cras_dsp_set_variable_string(ctx1, "variable", "foo"); - cras_dsp_set_variable_string(ctx3, "variable", "bar"); /* wrong value */ + cras_dsp_set_variable_string(ctx3, "variable", "bar"); /* wrong value */ cras_dsp_set_variable_string(ctx4, "variable", "foo"); cras_dsp_load_pipeline(ctx1); @@ -77,7 +76,7 @@ TEST_F(DspTestSuite, Simple) { ASSERT_EQ(NULL, cras_dsp_get_pipeline(ctx1)); ASSERT_EQ(NULL, cras_dsp_get_pipeline(ctx3)); - struct pipeline *pipeline = cras_dsp_get_pipeline(ctx4); + struct pipeline* pipeline = cras_dsp_get_pipeline(ctx4); ASSERT_TRUE(pipeline); cras_dsp_put_pipeline(ctx4); @@ -97,38 +96,36 @@ TEST_F(DspTestSuite, Simple) { cras_dsp_stop(); } -static int empty_instantiate(struct dsp_module *module, - unsigned long sample_rate) -{ +static int empty_instantiate(struct dsp_module* module, + unsigned long sample_rate) { return 0; } -static void empty_connect_port(struct dsp_module *module, unsigned long port, - float *data_location) {} +static void empty_connect_port(struct dsp_module* module, + unsigned long port, + float* data_location) {} -static int empty_get_delay(struct dsp_module *module) -{ - return 0; +static int empty_get_delay(struct dsp_module* module) { + return 0; } -static void empty_run(struct dsp_module *module, unsigned long sample_count) {} +static void empty_run(struct dsp_module* module, unsigned long sample_count) {} -static void empty_deinstantiate(struct dsp_module *module) {} +static void empty_deinstantiate(struct dsp_module* module) {} -static void empty_free_module(struct dsp_module *module) -{ +static void empty_free_module(struct dsp_module* module) { free(module); } -static int empty_get_properties(struct dsp_module *module) { return 0; } +static int empty_get_properties(struct dsp_module* module) { + return 0; +} -static void empty_dump(struct dsp_module *module, struct dumper *d) -{ +static void empty_dump(struct dsp_module* module, struct dumper* d) { dumpf(d, "built-in module\n"); } -static void empty_init_module(struct dsp_module *module) -{ +static void empty_init_module(struct dsp_module* module) { module->instantiate = &empty_instantiate; module->connect_port = &empty_connect_port; module->get_delay = &empty_get_delay; @@ -141,22 +138,18 @@ static void empty_init_module(struct dsp_module *module) } // namespace -extern "C" -{ -struct dsp_module *cras_dsp_module_load_builtin(struct plugin *plugin) -{ - struct dsp_module *module; - module = (struct dsp_module *)calloc(1, sizeof(struct dsp_module)); +extern "C" { +struct dsp_module* cras_dsp_module_load_builtin(struct plugin* plugin) { + struct dsp_module* module; + module = (struct dsp_module*)calloc(1, sizeof(struct dsp_module)); empty_init_module(module); return module; } -void cras_dsp_module_set_sink_ext_module(struct dsp_module *module, - struct ext_dsp_module *ext_module) -{ -} -} // extern "C" +void cras_dsp_module_set_sink_ext_module(struct dsp_module* module, + struct ext_dsp_module* ext_module) {} +} // extern "C" -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/dumper_unittest.cc b/cras/src/tests/dumper_unittest.cc index af19046d..7bd1421a 100644 --- a/cras/src/tests/dumper_unittest.cc +++ b/cras/src/tests/dumper_unittest.cc @@ -2,15 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <syslog.h> -#include <gtest/gtest.h> - #include "dumper.h" +#include <gtest/gtest.h> +#include <syslog.h> + namespace { TEST(DumperTest, SyslogDumper) { - struct dumper *dumper = syslog_dumper_create(LOG_ERR); + struct dumper* dumper = syslog_dumper_create(LOG_ERR); dumpf(dumper, "hello %d", 1); dumpf(dumper, "world %d\n123", 2); dumpf(dumper, "456\n"); @@ -21,8 +21,8 @@ TEST(DumperTest, SyslogDumper) { } TEST(DumperTest, MemDumper) { - struct dumper *dumper = mem_dumper_create(); - char *buf; + struct dumper* dumper = mem_dumper_create(); + char* buf; int size, i; mem_dumper_get(dumper, &buf, &size); @@ -55,7 +55,7 @@ TEST(DumperTest, MemDumper) { } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/edid_utils_unittest.cc b/cras/src/tests/edid_utils_unittest.cc index 291db716..6b059afc 100644 --- a/cras/src/tests/edid_utils_unittest.cc +++ b/cras/src/tests/edid_utils_unittest.cc @@ -2,34 +2,35 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "edid_utils.h" + +#include <gtest/gtest.h> #include <stdint.h> #include <stdio.h> -#include <gtest/gtest.h> #include "cras_util.h" -#include "edid_utils.h" namespace { -class EDIDTestSuite : public testing::Test{ - protected: - virtual void SetUp() { - static const uint8_t header[] = { +class EDIDTestSuite : public testing::Test { + protected: + virtual void SetUp() { + static const uint8_t header[] = { 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, - }; + }; - memcpy(edid_, header, sizeof(header)); - SetChecksum(); - } + memcpy(edid_, header, sizeof(header)); + SetChecksum(); + } - void SetChecksum() { - uint8_t sum = 0; + void SetChecksum() { + uint8_t sum = 0; - for (unsigned int i = 0; i < 127; i++) - sum += edid_[i]; + for (unsigned int i = 0; i < 127; i++) + sum += edid_[i]; - edid_[127] = 256 - sum; - } + edid_[127] = 256 - sum; + } uint8_t edid_[2048]; }; @@ -40,7 +41,7 @@ TEST_F(EDIDTestSuite, EDIDValid) { TEST_F(EDIDTestSuite, EDIDBadHeader) { static const uint8_t bad_header[] = { - 0x00, 0xff, 0xff, 0xff, 0xff, 0xee, 0xff, 0x00, + 0x00, 0xff, 0xff, 0xff, 0xff, 0xee, 0xff, 0x00, }; memcpy(edid_, bad_header, sizeof(bad_header)); @@ -52,256 +53,184 @@ TEST_F(EDIDTestSuite, EDIDBadHeader) { // Actual EDIDs read from sinks. static const uint8_t test_no_aud_edid1[256] = { - 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, - 0x06, 0xaf, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x12, 0x01, 0x03, 0x80, 0x1a, 0x0e, 0x78, - 0x0a, 0x99, 0x85, 0x95, 0x55, 0x56, 0x92, 0x28, - 0x22, 0x50, 0x54, 0x00, 0x00, 0x00, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x96, 0x19, - 0x56, 0x28, 0x50, 0x00, 0x08, 0x30, 0x18, 0x10, - 0x24, 0x00, 0x00, 0x90, 0x10, 0x00, 0x00, 0x18, - 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x20, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x41, - 0x55, 0x4f, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfe, - 0x00, 0x42, 0x31, 0x31, 0x36, 0x58, 0x57, 0x30, - 0x32, 0x20, 0x56, 0x30, 0x20, 0x0a, 0x00, 0xf8 -}; + 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x06, 0xaf, 0x5c, 0x20, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x12, 0x01, 0x03, 0x80, 0x1a, 0x0e, 0x78, + 0x0a, 0x99, 0x85, 0x95, 0x55, 0x56, 0x92, 0x28, 0x22, 0x50, 0x54, 0x00, + 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x96, 0x19, 0x56, 0x28, 0x50, 0x00, + 0x08, 0x30, 0x18, 0x10, 0x24, 0x00, 0x00, 0x90, 0x10, 0x00, 0x00, 0x18, + 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x41, + 0x55, 0x4f, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x00, 0x00, 0x00, 0xfe, 0x00, 0x42, 0x31, 0x31, 0x36, 0x58, 0x57, 0x30, + 0x32, 0x20, 0x56, 0x30, 0x20, 0x0a, 0x00, 0xf8}; static const uint8_t test_no_aud_edid2[256] = { - 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, - 0x30, 0xe4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x14, 0x01, 0x03, 0x80, 0x1a, 0x0e, 0x78, - 0x0a, 0xbf, 0x45, 0x95, 0x58, 0x52, 0x8a, 0x28, - 0x25, 0x50, 0x54, 0x00, 0x00, 0x00, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x84, 0x1c, - 0x56, 0xa8, 0x50, 0x00, 0x19, 0x30, 0x30, 0x20, - 0x35, 0x00, 0x00, 0x90, 0x10, 0x00, 0x00, 0x1b, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x4c, - 0x47, 0x20, 0x44, 0x69, 0x73, 0x70, 0x6c, 0x61, - 0x79, 0x0a, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfc, - 0x00, 0x4c, 0x50, 0x31, 0x31, 0x36, 0x57, 0x48, - 0x31, 0x2d, 0x54, 0x4c, 0x4e, 0x31, 0x00, 0x4e -}; + 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x30, 0xe4, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x01, 0x03, 0x80, 0x1a, 0x0e, 0x78, + 0x0a, 0xbf, 0x45, 0x95, 0x58, 0x52, 0x8a, 0x28, 0x25, 0x50, 0x54, 0x00, + 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x84, 0x1c, 0x56, 0xa8, 0x50, 0x00, + 0x19, 0x30, 0x30, 0x20, 0x35, 0x00, 0x00, 0x90, 0x10, 0x00, 0x00, 0x1b, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x4c, + 0x47, 0x20, 0x44, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x0a, 0x20, 0x20, + 0x00, 0x00, 0x00, 0xfc, 0x00, 0x4c, 0x50, 0x31, 0x31, 0x36, 0x57, 0x48, + 0x31, 0x2d, 0x54, 0x4c, 0x4e, 0x31, 0x00, 0x4e}; /* Has DTD that is too wide */ static const uint8_t test_no_aud_edid3[256] = { - 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, - 0x10, 0xac, 0x63, 0x40, 0x4c, 0x35, 0x31, 0x33, - 0x0c, 0x15, 0x01, 0x03, 0x80, 0x40, 0x28, 0x78, - 0xea, 0x8d, 0x85, 0xad, 0x4f, 0x35, 0xb1, 0x25, - 0x0e, 0x50, 0x54, 0xa5, 0x4b, 0x00, 0x71, 0x4f, - 0x81, 0x00, 0x81, 0x80, 0xa9, 0x40, 0xd1, 0x00, - 0xd1, 0x40, 0x01, 0x01, 0x01, 0x01, 0xe2, 0x68, - 0x00, 0xa0, 0xa0, 0x40, 0x2e, 0x60, 0x30, 0x20, - 0x36, 0x00, 0x81, 0x91, 0x21, 0x00, 0x00, 0x1a, - 0x00, 0x00, 0x00, 0xff, 0x00, 0x50, 0x48, 0x35, - 0x4e, 0x59, 0x31, 0x33, 0x4d, 0x33, 0x31, 0x35, - 0x4c, 0x0a, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x44, - 0x45, 0x4c, 0x4c, 0x20, 0x55, 0x33, 0x30, 0x31, - 0x31, 0x0a, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfd, - 0x00, 0x31, 0x56, 0x1d, 0x71, 0x1c, 0x00, 0x0a, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0xb0 -}; + 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x10, 0xac, 0x63, 0x40, + 0x4c, 0x35, 0x31, 0x33, 0x0c, 0x15, 0x01, 0x03, 0x80, 0x40, 0x28, 0x78, + 0xea, 0x8d, 0x85, 0xad, 0x4f, 0x35, 0xb1, 0x25, 0x0e, 0x50, 0x54, 0xa5, + 0x4b, 0x00, 0x71, 0x4f, 0x81, 0x00, 0x81, 0x80, 0xa9, 0x40, 0xd1, 0x00, + 0xd1, 0x40, 0x01, 0x01, 0x01, 0x01, 0xe2, 0x68, 0x00, 0xa0, 0xa0, 0x40, + 0x2e, 0x60, 0x30, 0x20, 0x36, 0x00, 0x81, 0x91, 0x21, 0x00, 0x00, 0x1a, + 0x00, 0x00, 0x00, 0xff, 0x00, 0x50, 0x48, 0x35, 0x4e, 0x59, 0x31, 0x33, + 0x4d, 0x33, 0x31, 0x35, 0x4c, 0x0a, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x44, + 0x45, 0x4c, 0x4c, 0x20, 0x55, 0x33, 0x30, 0x31, 0x31, 0x0a, 0x20, 0x20, + 0x00, 0x00, 0x00, 0xfd, 0x00, 0x31, 0x56, 0x1d, 0x71, 0x1c, 0x00, 0x0a, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0xb0}; static const uint8_t test_edid1[256] = { - 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, - 0x4d, 0xd9, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x11, 0x01, 0x03, 0x80, 0x00, 0x00, 0x78, - 0x0a, 0x0d, 0xc9, 0xa0, 0x57, 0x47, 0x98, 0x27, - 0x12, 0x48, 0x4c, 0x00, 0x00, 0x00, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1d, - 0x80, 0xd0, 0x72, 0x1c, 0x16, 0x20, 0x10, 0x2c, - 0x25, 0x80, 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x9e, - 0x01, 0x1d, 0x80, 0x18, 0x71, 0x1c, 0x16, 0x20, - 0x58, 0x2c, 0x25, 0x00, 0xc4, 0x8e, 0x21, 0x00, - 0x00, 0x9e, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x48, - 0x44, 0x4d, 0x49, 0x20, 0x4c, 0x4c, 0x43, 0x0a, - 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfd, - 0x00, 0x3b, 0x3d, 0x0f, 0x2d, 0x08, 0x00, 0x0a, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0xc0, - 0x02, 0x03, 0x1e, 0x47, 0x4f, 0x94, 0x13, 0x05, - 0x03, 0x04, 0x02, 0x01, 0x16, 0x15, 0x07, 0x06, - 0x11, 0x10, 0x12, 0x1f, 0x23, 0x09, 0x07, 0x01, - 0x65, 0x03, 0x0c, 0x00, 0x10, 0x00, 0x8c, 0x0a, - 0xd0, 0x90, 0x20, 0x40, 0x31, 0x20, 0x0c, 0x40, - 0x55, 0x00, 0x13, 0x8e, 0x21, 0x00, 0x00, 0x18, - 0x01, 0x1d, 0x00, 0xbc, 0x52, 0xd0, 0x1e, 0x20, - 0xb8, 0x28, 0x55, 0x40, 0xc4, 0x8e, 0x21, 0x00, - 0x00, 0x1e, 0x8c, 0x0a, 0xd0, 0x8a, 0x20, 0xe0, - 0x2d, 0x10, 0x10, 0x3e, 0x96, 0x00, 0xc4, 0x8e, - 0x21, 0x00, 0x00, 0x18, 0x01, 0x1d, 0x00, 0x72, - 0x51, 0xd0, 0x1e, 0x20, 0x6e, 0x28, 0x55, 0x00, - 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x1e, 0x8c, 0x0a, - 0xd0, 0x8a, 0x20, 0xe0, 0x2d, 0x10, 0x10, 0x3e, - 0x96, 0x00, 0x13, 0x8e, 0x21, 0x00, 0x00, 0x18, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb -}; + 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x4d, 0xd9, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x01, 0x03, 0x80, 0x00, 0x00, 0x78, + 0x0a, 0x0d, 0xc9, 0xa0, 0x57, 0x47, 0x98, 0x27, 0x12, 0x48, 0x4c, 0x00, + 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1d, 0x80, 0xd0, 0x72, 0x1c, + 0x16, 0x20, 0x10, 0x2c, 0x25, 0x80, 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x9e, + 0x01, 0x1d, 0x80, 0x18, 0x71, 0x1c, 0x16, 0x20, 0x58, 0x2c, 0x25, 0x00, + 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x9e, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x48, + 0x44, 0x4d, 0x49, 0x20, 0x4c, 0x4c, 0x43, 0x0a, 0x20, 0x20, 0x20, 0x20, + 0x00, 0x00, 0x00, 0xfd, 0x00, 0x3b, 0x3d, 0x0f, 0x2d, 0x08, 0x00, 0x0a, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0xc0, 0x02, 0x03, 0x1e, 0x47, + 0x4f, 0x94, 0x13, 0x05, 0x03, 0x04, 0x02, 0x01, 0x16, 0x15, 0x07, 0x06, + 0x11, 0x10, 0x12, 0x1f, 0x23, 0x09, 0x07, 0x01, 0x65, 0x03, 0x0c, 0x00, + 0x10, 0x00, 0x8c, 0x0a, 0xd0, 0x90, 0x20, 0x40, 0x31, 0x20, 0x0c, 0x40, + 0x55, 0x00, 0x13, 0x8e, 0x21, 0x00, 0x00, 0x18, 0x01, 0x1d, 0x00, 0xbc, + 0x52, 0xd0, 0x1e, 0x20, 0xb8, 0x28, 0x55, 0x40, 0xc4, 0x8e, 0x21, 0x00, + 0x00, 0x1e, 0x8c, 0x0a, 0xd0, 0x8a, 0x20, 0xe0, 0x2d, 0x10, 0x10, 0x3e, + 0x96, 0x00, 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x18, 0x01, 0x1d, 0x00, 0x72, + 0x51, 0xd0, 0x1e, 0x20, 0x6e, 0x28, 0x55, 0x00, 0xc4, 0x8e, 0x21, 0x00, + 0x00, 0x1e, 0x8c, 0x0a, 0xd0, 0x8a, 0x20, 0xe0, 0x2d, 0x10, 0x10, 0x3e, + 0x96, 0x00, 0x13, 0x8e, 0x21, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xfb}; static const uint8_t test_edid2[256] = { - 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, - 0x4c, 0x2d, 0x10, 0x02, 0x00, 0x00, 0x00, 0x00, - 0x31, 0x0f, 0x01, 0x03, 0x80, 0x10, 0x09, 0x8c, - 0x0a, 0xe2, 0xbd, 0xa1, 0x5b, 0x4a, 0x98, 0x24, - 0x15, 0x47, 0x4a, 0x20, 0x00, 0x00, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1d, - 0x00, 0x72, 0x51, 0xd0, 0x1e, 0x20, 0x6e, 0x28, - 0x55, 0x00, 0xa0, 0x5a, 0x00, 0x00, 0x00, 0x1e, - 0x01, 0x1d, 0x80, 0x18, 0x71, 0x1c, 0x16, 0x20, - 0x58, 0x2c, 0x25, 0x00, 0xa0, 0x5a, 0x00, 0x00, - 0x00, 0x9e, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x3b, - 0x3d, 0x1e, 0x2e, 0x08, 0x00, 0x0a, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfc, - 0x00, 0x53, 0x41, 0x4d, 0x53, 0x55, 0x4e, 0x47, - 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0x8d, - 0x02, 0x03, 0x16, 0x71, 0x43, 0x84, 0x05, 0x03, - 0x23, 0x09, 0x07, 0x07, 0x83, 0x01, 0x00, 0x00, - 0x65, 0x03, 0x0c, 0x00, 0x20, 0x00, 0x8c, 0x0a, - 0xd0, 0x8a, 0x20, 0xe0, 0x2d, 0x10, 0x10, 0x3e, - 0x96, 0x00, 0xa0, 0x5a, 0x00, 0x00, 0x00, 0x18, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30 -}; + 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x4c, 0x2d, 0x10, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x31, 0x0f, 0x01, 0x03, 0x80, 0x10, 0x09, 0x8c, + 0x0a, 0xe2, 0xbd, 0xa1, 0x5b, 0x4a, 0x98, 0x24, 0x15, 0x47, 0x4a, 0x20, + 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1d, 0x00, 0x72, 0x51, 0xd0, + 0x1e, 0x20, 0x6e, 0x28, 0x55, 0x00, 0xa0, 0x5a, 0x00, 0x00, 0x00, 0x1e, + 0x01, 0x1d, 0x80, 0x18, 0x71, 0x1c, 0x16, 0x20, 0x58, 0x2c, 0x25, 0x00, + 0xa0, 0x5a, 0x00, 0x00, 0x00, 0x9e, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x3b, + 0x3d, 0x1e, 0x2e, 0x08, 0x00, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x00, 0x00, 0x00, 0xfc, 0x00, 0x53, 0x41, 0x4d, 0x53, 0x55, 0x4e, 0x47, + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0x8d, 0x02, 0x03, 0x16, 0x71, + 0x43, 0x84, 0x05, 0x03, 0x23, 0x09, 0x07, 0x07, 0x83, 0x01, 0x00, 0x00, + 0x65, 0x03, 0x0c, 0x00, 0x20, 0x00, 0x8c, 0x0a, 0xd0, 0x8a, 0x20, 0xe0, + 0x2d, 0x10, 0x10, 0x3e, 0x96, 0x00, 0xa0, 0x5a, 0x00, 0x00, 0x00, 0x18, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x30}; static const uint8_t test_edid3[256] = { - 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, - 0x3d, 0xcb, 0x61, 0x07, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x11, 0x01, 0x03, 0x80, 0x00, 0x00, 0x78, - 0x0a, 0x0d, 0xc9, 0xa0, 0x57, 0x47, 0x98, 0x27, - 0x12, 0x48, 0x4c, 0x00, 0x00, 0x00, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1d, - 0x80, 0x18, 0x71, 0x1c, 0x16, 0x20, 0x58, 0x2c, - 0x25, 0x00, 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x9e, - 0x01, 0x1d, 0x80, 0xd0, 0x72, 0x1c, 0x16, 0x20, - 0x10, 0x2c, 0x25, 0x80, 0xc4, 0x8e, 0x21, 0x00, - 0x00, 0x9e, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x54, - 0x58, 0x2d, 0x53, 0x52, 0x36, 0x30, 0x35, 0x0a, - 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfd, - 0x00, 0x17, 0xf0, 0x0f, 0x7e, 0x11, 0x00, 0x0a, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0x93, - 0x02, 0x03, 0x3b, 0x72, 0x55, 0x85, 0x04, 0x03, - 0x02, 0x0e, 0x0f, 0x07, 0x23, 0x24, 0x10, 0x94, - 0x13, 0x12, 0x11, 0x1d, 0x1e, 0x16, 0x25, 0x26, - 0x01, 0x1f, 0x35, 0x09, 0x7f, 0x07, 0x0f, 0x7f, - 0x07, 0x17, 0x07, 0x50, 0x3f, 0x06, 0xc0, 0x57, - 0x06, 0x00, 0x5f, 0x7e, 0x01, 0x67, 0x5e, 0x00, - 0x83, 0x4f, 0x00, 0x00, 0x66, 0x03, 0x0c, 0x00, - 0x20, 0x00, 0x80, 0x8c, 0x0a, 0xd0, 0x8a, 0x20, - 0xe0, 0x2d, 0x10, 0x10, 0x3e, 0x96, 0x00, 0xc4, - 0x8e, 0x21, 0x00, 0x00, 0x18, 0x8c, 0x0a, 0xd0, - 0x90, 0x20, 0x40, 0x31, 0x20, 0x0c, 0x40, 0x55, - 0x00, 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x18, 0x01, - 0x1d, 0x00, 0x72, 0x51, 0xd0, 0x1e, 0x20, 0x6e, - 0x28, 0x55, 0x00, 0xc4, 0x8e, 0x21, 0x00, 0x00, - 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdd -}; + 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x3d, 0xcb, 0x61, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x01, 0x03, 0x80, 0x00, 0x00, 0x78, + 0x0a, 0x0d, 0xc9, 0xa0, 0x57, 0x47, 0x98, 0x27, 0x12, 0x48, 0x4c, 0x00, + 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1d, 0x80, 0x18, 0x71, 0x1c, + 0x16, 0x20, 0x58, 0x2c, 0x25, 0x00, 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x9e, + 0x01, 0x1d, 0x80, 0xd0, 0x72, 0x1c, 0x16, 0x20, 0x10, 0x2c, 0x25, 0x80, + 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x9e, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x54, + 0x58, 0x2d, 0x53, 0x52, 0x36, 0x30, 0x35, 0x0a, 0x20, 0x20, 0x20, 0x20, + 0x00, 0x00, 0x00, 0xfd, 0x00, 0x17, 0xf0, 0x0f, 0x7e, 0x11, 0x00, 0x0a, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0x93, 0x02, 0x03, 0x3b, 0x72, + 0x55, 0x85, 0x04, 0x03, 0x02, 0x0e, 0x0f, 0x07, 0x23, 0x24, 0x10, 0x94, + 0x13, 0x12, 0x11, 0x1d, 0x1e, 0x16, 0x25, 0x26, 0x01, 0x1f, 0x35, 0x09, + 0x7f, 0x07, 0x0f, 0x7f, 0x07, 0x17, 0x07, 0x50, 0x3f, 0x06, 0xc0, 0x57, + 0x06, 0x00, 0x5f, 0x7e, 0x01, 0x67, 0x5e, 0x00, 0x83, 0x4f, 0x00, 0x00, + 0x66, 0x03, 0x0c, 0x00, 0x20, 0x00, 0x80, 0x8c, 0x0a, 0xd0, 0x8a, 0x20, + 0xe0, 0x2d, 0x10, 0x10, 0x3e, 0x96, 0x00, 0xc4, 0x8e, 0x21, 0x00, 0x00, + 0x18, 0x8c, 0x0a, 0xd0, 0x90, 0x20, 0x40, 0x31, 0x20, 0x0c, 0x40, 0x55, + 0x00, 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x18, 0x01, 0x1d, 0x00, 0x72, 0x51, + 0xd0, 0x1e, 0x20, 0x6e, 0x28, 0x55, 0x00, 0xc4, 0x8e, 0x21, 0x00, 0x00, + 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xdd}; static const uint8_t test_edid4[256] = { - 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, - 0x04, 0x72, 0x30, 0x02, 0x01, 0x00, 0x00, 0x00, - 0x18, 0x14, 0x01, 0x03, 0x80, 0x33, 0x1d, 0x78, - 0x0a, 0xdc, 0x55, 0xa3, 0x59, 0x48, 0x9e, 0x24, - 0x11, 0x50, 0x54, 0xbf, 0x6f, 0x00, 0x71, 0x4f, - 0x81, 0xc0, 0xd1, 0xc0, 0xb3, 0x00, 0x81, 0x80, - 0x95, 0x00, 0x01, 0x01, 0x01, 0x01, 0x02, 0x3a, - 0x80, 0x18, 0x71, 0x38, 0x2d, 0x40, 0x58, 0x2c, - 0x45, 0x00, 0xfe, 0x22, 0x11, 0x00, 0x00, 0x18, - 0x01, 0x1d, 0x00, 0x72, 0x51, 0xd0, 0x1e, 0x20, - 0x6e, 0x28, 0x55, 0x00, 0xfe, 0x22, 0x11, 0x00, - 0x00, 0x1e, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x38, - 0x4c, 0x1e, 0x4b, 0x0f, 0x00, 0x0a, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfc, - 0x00, 0x4d, 0x32, 0x33, 0x30, 0x41, 0x0a, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0xf0, - 0x02, 0x03, 0x18, 0x74, 0x45, 0x04, 0x05, 0x90, - 0x03, 0x01, 0x23, 0x09, 0x17, 0x07, 0x83, 0x01, - 0x00, 0x00, 0x65, 0x03, 0x0c, 0x00, 0x30, 0x00, - 0x01, 0x1d, 0x80, 0x18, 0x71, 0x1c, 0x16, 0x20, - 0x58, 0x2c, 0x25, 0x00, 0xfe, 0x22, 0x11, 0x00, - 0x00, 0x9e, 0x8c, 0x0a, 0xd0, 0x8a, 0x20, 0xe0, - 0x2d, 0x10, 0x10, 0x3e, 0x96, 0x00, 0xfe, 0x22, - 0x11, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, + 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x04, 0x72, 0x30, 0x02, + 0x01, 0x00, 0x00, 0x00, 0x18, 0x14, 0x01, 0x03, 0x80, 0x33, 0x1d, 0x78, + 0x0a, 0xdc, 0x55, 0xa3, 0x59, 0x48, 0x9e, 0x24, 0x11, 0x50, 0x54, 0xbf, + 0x6f, 0x00, 0x71, 0x4f, 0x81, 0xc0, 0xd1, 0xc0, 0xb3, 0x00, 0x81, 0x80, + 0x95, 0x00, 0x01, 0x01, 0x01, 0x01, 0x02, 0x3a, 0x80, 0x18, 0x71, 0x38, + 0x2d, 0x40, 0x58, 0x2c, 0x45, 0x00, 0xfe, 0x22, 0x11, 0x00, 0x00, 0x18, + 0x01, 0x1d, 0x00, 0x72, 0x51, 0xd0, 0x1e, 0x20, 0x6e, 0x28, 0x55, 0x00, + 0xfe, 0x22, 0x11, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x38, + 0x4c, 0x1e, 0x4b, 0x0f, 0x00, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x00, 0x00, 0x00, 0xfc, 0x00, 0x4d, 0x32, 0x33, 0x30, 0x41, 0x0a, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0xf0, 0x02, 0x03, 0x18, 0x74, + 0x45, 0x04, 0x05, 0x90, 0x03, 0x01, 0x23, 0x09, 0x17, 0x07, 0x83, 0x01, + 0x00, 0x00, 0x65, 0x03, 0x0c, 0x00, 0x30, 0x00, 0x01, 0x1d, 0x80, 0x18, + 0x71, 0x1c, 0x16, 0x20, 0x58, 0x2c, 0x25, 0x00, 0xfe, 0x22, 0x11, 0x00, + 0x00, 0x9e, 0x8c, 0x0a, 0xd0, 0x8a, 0x20, 0xe0, 0x2d, 0x10, 0x10, 0x3e, + 0x96, 0x00, 0xfe, 0x22, 0x11, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xd0, }; static const uint8_t test_monitor_edid[256] = { - 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, - 0x4d, 0xd9, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x11, 0x01, 0x03, 0x80, 0x00, 0x00, 0x78, - 0x0a, 0x0d, 0xc9, 0xa0, 0x57, 0x47, 0x98, 0x27, - 0x12, 0x48, 0x4c, 0x00, 0x00, 0x00, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1d, - 0x80, 0xd0, 0x72, 0x1c, 0x16, 0x20, 0x10, 0x2c, - 0x25, 0x80, 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x9e, - 0x01, 0x1d, 0x80, 0x18, 0x71, 0x1c, 0x16, 0x20, - 0x58, 0x2c, 0x25, 0x00, 0xc4, 0x8e, 0x21, 0x00, - 0x00, 0x9e, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x48, - 0x44, 0x4d, 0x49, 0x20, 0x4c, 0x4c, 0x43, 0x20, - 0x41, 0x42, 0x43, 0x44, 0x00, 0x00, 0x00, 0xfd, - 0x00, 0x3b, 0x3d, 0x0f, 0x2d, 0x08, 0x00, 0x0a, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0xc0, - 0x02, 0x03, 0x1e, 0x47, 0x4f, 0x94, 0x13, 0x05, - 0x03, 0x04, 0x02, 0x01, 0x16, 0x15, 0x07, 0x06, - 0x11, 0x10, 0x12, 0x1f, 0x23, 0x09, 0x07, 0x01, - 0x65, 0x03, 0x0c, 0x00, 0x10, 0x00, 0x8c, 0x0a, - 0xd0, 0x90, 0x20, 0x40, 0x31, 0x20, 0x0c, 0x40, - 0x55, 0x00, 0x13, 0x8e, 0x21, 0x00, 0x00, 0x18, - 0x01, 0x1d, 0x00, 0xbc, 0x52, 0xd0, 0x1e, 0x20, - 0xb8, 0x28, 0x55, 0x40, 0xc4, 0x8e, 0x21, 0x00, - 0x00, 0x1e, 0x8c, 0x0a, 0xd0, 0x8a, 0x20, 0xe0, - 0x2d, 0x10, 0x10, 0x3e, 0x96, 0x00, 0xc4, 0x8e, - 0x21, 0x00, 0x00, 0x18, 0x01, 0x1d, 0x00, 0x72, - 0x51, 0xd0, 0x1e, 0x20, 0x6e, 0x28, 0x55, 0x00, - 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x1e, 0x8c, 0x0a, - 0xd0, 0x8a, 0x20, 0xe0, 0x2d, 0x10, 0x10, 0x3e, - 0x96, 0x00, 0x13, 0x8e, 0x21, 0x00, 0x00, 0x18, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb -}; - -static const uint8_t *test_no_aud_edids[] = { - test_no_aud_edid1, - test_no_aud_edid2, - test_no_aud_edid3, + 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x4d, 0xd9, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x01, 0x03, 0x80, 0x00, 0x00, 0x78, + 0x0a, 0x0d, 0xc9, 0xa0, 0x57, 0x47, 0x98, 0x27, 0x12, 0x48, 0x4c, 0x00, + 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1d, 0x80, 0xd0, 0x72, 0x1c, + 0x16, 0x20, 0x10, 0x2c, 0x25, 0x80, 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x9e, + 0x01, 0x1d, 0x80, 0x18, 0x71, 0x1c, 0x16, 0x20, 0x58, 0x2c, 0x25, 0x00, + 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x9e, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x48, + 0x44, 0x4d, 0x49, 0x20, 0x4c, 0x4c, 0x43, 0x20, 0x41, 0x42, 0x43, 0x44, + 0x00, 0x00, 0x00, 0xfd, 0x00, 0x3b, 0x3d, 0x0f, 0x2d, 0x08, 0x00, 0x0a, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0xc0, 0x02, 0x03, 0x1e, 0x47, + 0x4f, 0x94, 0x13, 0x05, 0x03, 0x04, 0x02, 0x01, 0x16, 0x15, 0x07, 0x06, + 0x11, 0x10, 0x12, 0x1f, 0x23, 0x09, 0x07, 0x01, 0x65, 0x03, 0x0c, 0x00, + 0x10, 0x00, 0x8c, 0x0a, 0xd0, 0x90, 0x20, 0x40, 0x31, 0x20, 0x0c, 0x40, + 0x55, 0x00, 0x13, 0x8e, 0x21, 0x00, 0x00, 0x18, 0x01, 0x1d, 0x00, 0xbc, + 0x52, 0xd0, 0x1e, 0x20, 0xb8, 0x28, 0x55, 0x40, 0xc4, 0x8e, 0x21, 0x00, + 0x00, 0x1e, 0x8c, 0x0a, 0xd0, 0x8a, 0x20, 0xe0, 0x2d, 0x10, 0x10, 0x3e, + 0x96, 0x00, 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x18, 0x01, 0x1d, 0x00, 0x72, + 0x51, 0xd0, 0x1e, 0x20, 0x6e, 0x28, 0x55, 0x00, 0xc4, 0x8e, 0x21, 0x00, + 0x00, 0x1e, 0x8c, 0x0a, 0xd0, 0x8a, 0x20, 0xe0, 0x2d, 0x10, 0x10, 0x3e, + 0x96, 0x00, 0x13, 0x8e, 0x21, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xfb}; + +static const uint8_t* test_no_aud_edids[] = { + test_no_aud_edid1, + test_no_aud_edid2, + test_no_aud_edid3, }; -static const uint8_t *test_edids[] = { - test_edid1, - test_edid2, - test_edid3, - test_edid4, +static const uint8_t* test_edids[] = { + test_edid1, + test_edid2, + test_edid3, + test_edid4, }; -static const char *monitor_names[] = { - "HDMI LLC", - "SAMSUNG", - "TX-SR605", - "M230A", +static const char* monitor_names[] = { + "HDMI LLC", + "SAMSUNG", + "TX-SR605", + "M230A", }; TEST_F(EDIDTestSuite, NoAudEDID) { @@ -339,7 +268,7 @@ TEST_F(EDIDTestSuite, EDIDMonitorName) { } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/empty_audio_stub.cc b/cras/src/tests/empty_audio_stub.cc index e15af00d..00ede69f 100644 --- a/cras/src/tests/empty_audio_stub.cc +++ b/cras/src/tests/empty_audio_stub.cc @@ -6,17 +6,17 @@ extern "C" { #include "polled_interval_checker.h" -struct polled_interval *pic_polled_interval_create(int interval_sec) { - return NULL; +struct polled_interval* pic_polled_interval_create(int interval_sec) { + return NULL; } -int pic_interval_elapsed(const struct polled_interval *interval) { - return 0; +int pic_interval_elapsed(const struct polled_interval* interval) { + return 0; } -void pic_interval_reset(struct polled_interval *interval) {} +void pic_interval_reset(struct polled_interval* interval) {} -void pic_polled_interval_destroy(struct polled_interval **interval) {} +void pic_polled_interval_destroy(struct polled_interval** interval) {} void pic_update_current_time() {} diff --git a/cras/src/tests/empty_iodev_unittest.cc b/cras/src/tests/empty_iodev_unittest.cc index 8de238c3..585fba32 100644 --- a/cras/src/tests/empty_iodev_unittest.cc +++ b/cras/src/tests/empty_iodev_unittest.cc @@ -18,12 +18,12 @@ static cras_audio_area dummy_audio_area; namespace { TEST(EmptyIodev, GetInputBuffer) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; struct timespec ts; - cras_audio_area *area; + cras_audio_area* area; unsigned nframes; - iodev = empty_iodev_create(CRAS_STREAM_INPUT, CRAS_NODE_TYPE_UNKNOWN); + iodev = empty_iodev_create(CRAS_STREAM_INPUT, CRAS_NODE_TYPE_FALLBACK_NORMAL); clock_gettime_retspec.tv_sec = 0; clock_gettime_retspec.tv_nsec = 10000000; @@ -46,70 +46,55 @@ TEST(EmptyIodev, GetInputBuffer) { empty_iodev_destroy(iodev); } -} // namespace +} // namespace extern "C" { -void cras_iodev_free_format(struct cras_iodev *iodev) -{ -} +void cras_iodev_free_format(struct cras_iodev* iodev) {} -int cras_iodev_default_no_stream_playback(struct cras_iodev *odev, int enable) -{ +int cras_iodev_default_no_stream_playback(struct cras_iodev* odev, int enable) { return 0; } -void cras_iodev_init_audio_area(struct cras_iodev *iodev, - int num_channels) -{ +void cras_iodev_init_audio_area(struct cras_iodev* iodev, int num_channels) { iodev->area = &dummy_audio_area; } -void cras_iodev_free_audio_area(struct cras_iodev *iodev) -{ -} +void cras_iodev_free_audio_area(struct cras_iodev* iodev) {} -void cras_audio_area_config_buf_pointers(struct cras_audio_area *area, - const struct cras_audio_format *fmt, - uint8_t *base_buffer) -{ -} +void cras_audio_area_config_buf_pointers(struct cras_audio_area* area, + const struct cras_audio_format* fmt, + uint8_t* base_buffer) {} -int cras_iodev_list_rm_input(struct cras_iodev *input) -{ +int cras_iodev_list_rm_input(struct cras_iodev* input) { return 0; } -int cras_iodev_list_rm_output(struct cras_iodev *output) -{ +int cras_iodev_list_rm_output(struct cras_iodev* output) { return 0; } -void cras_iodev_free_resources(struct cras_iodev *iodev) -{ -} +void cras_iodev_free_resources(struct cras_iodev* iodev) {} -void cras_iodev_add_node(struct cras_iodev *iodev, struct cras_ionode *node) -{ +void cras_iodev_add_node(struct cras_iodev* iodev, struct cras_ionode* node) { iodev->nodes = node; } -void cras_iodev_set_active_node(struct cras_iodev *iodev, - struct cras_ionode *node) -{ +void cras_iodev_set_active_node(struct cras_iodev* iodev, + struct cras_ionode* node) { iodev->active_node = node; } // From librt. -int clock_gettime(clockid_t clk_id, struct timespec *tp) { +int clock_gettime(clockid_t clk_id, struct timespec* tp) { tp->tv_sec = clock_gettime_retspec.tv_sec; tp->tv_nsec = clock_gettime_retspec.tv_nsec; return 0; } -} // extern "C" +} // extern "C" -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/expr_unittest.cc b/cras/src/tests/expr_unittest.cc index 2fec2dfb..dbfdb46b 100644 --- a/cras/src/tests/expr_unittest.cc +++ b/cras/src/tests/expr_unittest.cc @@ -9,7 +9,7 @@ namespace { TEST(ExprTest, UnparsibleExpression) { - struct cras_expr_expression *expr; + struct cras_expr_expression* expr; /* un-parsable input */ expr = cras_expr_expression_parse("#"); @@ -22,7 +22,7 @@ TEST(ExprTest, UnparsibleExpression) { } TEST(ExprTest, LiteralExpression) { - struct cras_expr_expression *expr; + struct cras_expr_expression* expr; struct cras_expr_value value = CRAS_EXPR_VALUE_INIT; struct cras_expr_env env = CRAS_EXPR_ENV_INIT; int integer = 0; @@ -59,7 +59,7 @@ TEST(ExprTest, LiteralExpression) { } TEST(ExprTest, Variable) { - struct cras_expr_expression *expr; + struct cras_expr_expression* expr; struct cras_expr_value value = CRAS_EXPR_VALUE_INIT; struct cras_expr_env env = CRAS_EXPR_ENV_INIT; int integer = 0; @@ -137,7 +137,7 @@ TEST(ExprTest, Compound) { } TEST(ExprTest, Environment) { - struct cras_expr_expression *expr; + struct cras_expr_expression* expr; struct cras_expr_value value = CRAS_EXPR_VALUE_INIT; struct cras_expr_env env1 = CRAS_EXPR_ENV_INIT; struct cras_expr_env env2 = CRAS_EXPR_ENV_INIT; @@ -173,9 +173,10 @@ TEST(ExprTest, Environment) { cras_expr_env_free(&env2); } -static void expect_int(int expected, const char *str, struct cras_expr_env *env) -{ - struct cras_expr_expression *expr; +static void expect_int(int expected, + const char* str, + struct cras_expr_env* env) { + struct cras_expr_expression* expr; struct cras_expr_value value = CRAS_EXPR_VALUE_INIT; expr = cras_expr_expression_parse(str); @@ -185,10 +186,10 @@ static void expect_int(int expected, const char *str, struct cras_expr_env *env) cras_expr_expression_free(expr); } -static void expect_boolean(char expected, const char *str, - struct cras_expr_env *env) -{ - struct cras_expr_expression *expr; +static void expect_boolean(char expected, + const char* str, + struct cras_expr_env* env) { + struct cras_expr_expression* expr; struct cras_expr_value value = CRAS_EXPR_VALUE_INIT; expr = cras_expr_expression_parse(str); @@ -199,7 +200,7 @@ static void expect_boolean(char expected, const char *str, } TEST(ExprTest, Builtin) { - struct cras_expr_expression *expr; + struct cras_expr_expression* expr; struct cras_expr_value value = CRAS_EXPR_VALUE_INIT; struct cras_expr_env env = CRAS_EXPR_ENV_INIT; @@ -241,7 +242,7 @@ TEST(ExprTest, Builtin) { } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/file_wait_unittest.cc b/cras/src/tests/file_wait_unittest.cc index 6bd76f32..87cd53c9 100644 --- a/cras/src/tests/file_wait_unittest.cc +++ b/cras/src/tests/file_wait_unittest.cc @@ -2,17 +2,18 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <gtest/gtest.h> #include <fcntl.h> +#include <gtest/gtest.h> #include <stdlib.h> + #include <string> -#include "cras_util.h" #include "cras_file_wait.h" +#include "cras_util.h" extern "C" { // This function is not exported in cras_util.h. -void cras_file_wait_mock_race_condition(struct cras_file_wait *file_wait); +void cras_file_wait_mock_race_condition(struct cras_file_wait* file_wait); } namespace { @@ -38,18 +39,17 @@ struct FileWaitResult { }; // Called by the file wait code for an event. -static void FileWaitCallback(void *context, - cras_file_wait_event_t event, - const char *filename) -{ - FileWaitResult *result = reinterpret_cast<FileWaitResult*>(context); +static void FileWaitCallback(void* context, + cras_file_wait_event_t event, + const char* filename) { + FileWaitResult* result = reinterpret_cast<FileWaitResult*>(context); result->called++; result->event = event; } // Do all of the EXPECTed steps for a simple wait for one file. -static void SimpleFileWait(const char *file_path) { - struct cras_file_wait *file_wait; +static void SimpleFileWait(const char* file_path) { + struct cras_file_wait* file_wait; FileWaitResult file_wait_result; struct pollfd poll_fd; struct timespec timeout = {0, 100000000}; @@ -64,7 +64,7 @@ static void SimpleFileWait(const char *file_path) { EXPECT_EQ(0, cras_file_wait_create(file_path, CRAS_FILE_WAIT_FLAG_NONE, FileWaitCallback, &file_wait_result, &file_wait)); - EXPECT_NE(reinterpret_cast<struct cras_file_wait *>(NULL), file_wait); + EXPECT_NE(reinterpret_cast<struct cras_file_wait*>(NULL), file_wait); if (stat_rc == 0) { EXPECT_EQ(1, file_wait_result.called); EXPECT_EQ(CRAS_FILE_WAIT_EVENT_CREATED, file_wait_result.event); @@ -93,7 +93,7 @@ static void SimpleFileWait(const char *file_path) { // Test the cras_file_wait functions including multiple path components // missing and path components deleted and recreated. TEST(Util, FileWait) { - struct cras_file_wait *file_wait; + struct cras_file_wait* file_wait; FileWaitResult file_wait_result; pid_t pid = getpid(); struct pollfd poll_fd; @@ -112,21 +112,20 @@ TEST(Util, FileWait) { // Test arguments. // Null file path. - EXPECT_EQ(-EINVAL, cras_file_wait_create( - NULL, CRAS_FILE_WAIT_FLAG_NONE, - FileWaitCallback, &file_wait_result, &file_wait)); + EXPECT_EQ(-EINVAL, cras_file_wait_create(NULL, CRAS_FILE_WAIT_FLAG_NONE, + FileWaitCallback, &file_wait_result, + &file_wait)); // Empty file path. - EXPECT_EQ(-EINVAL, cras_file_wait_create( - "", CRAS_FILE_WAIT_FLAG_NONE, - FileWaitCallback, &file_wait_result, &file_wait)); + EXPECT_EQ(-EINVAL, cras_file_wait_create("", CRAS_FILE_WAIT_FLAG_NONE, + FileWaitCallback, &file_wait_result, + &file_wait)); // No callback structure. - EXPECT_EQ(-EINVAL, cras_file_wait_create( - ".", CRAS_FILE_WAIT_FLAG_NONE, - NULL, NULL, &file_wait)); + EXPECT_EQ(-EINVAL, cras_file_wait_create(".", CRAS_FILE_WAIT_FLAG_NONE, NULL, + NULL, &file_wait)); // No file wait structure. - EXPECT_EQ(-EINVAL, cras_file_wait_create( - ".", CRAS_FILE_WAIT_FLAG_NONE, - FileWaitCallback, &file_wait_result, NULL)); + EXPECT_EQ(-EINVAL, + cras_file_wait_create(".", CRAS_FILE_WAIT_FLAG_NONE, + FileWaitCallback, &file_wait_result, NULL)); EXPECT_EQ(-EINVAL, cras_file_wait_dispatch(NULL)); EXPECT_EQ(-EINVAL, cras_file_wait_get_fd(NULL)); @@ -135,7 +134,7 @@ TEST(Util, FileWait) { EXPECT_EQ(0, cras_file_wait_create(CRAS_UT_TMPDIR, CRAS_FILE_WAIT_FLAG_NONE, FileWaitCallback, &file_wait_result, &file_wait)); - EXPECT_NE(reinterpret_cast<struct cras_file_wait *>(NULL), file_wait); + EXPECT_NE(reinterpret_cast<struct cras_file_wait*>(NULL), file_wait); EXPECT_EQ(file_wait_result.called, 1); ASSERT_EQ(file_wait_result.event, CRAS_FILE_WAIT_EVENT_CREATED); cras_file_wait_destroy(file_wait); @@ -146,10 +145,9 @@ TEST(Util, FileWait) { // Start looking for our file '.../does_not_exist'. EXPECT_EQ(0, cras_file_wait_create(file_path.c_str(), - CRAS_FILE_WAIT_FLAG_NONE, - FileWaitCallback, &file_wait_result, - &file_wait)); - EXPECT_NE(reinterpret_cast<struct cras_file_wait *>(NULL), file_wait); + CRAS_FILE_WAIT_FLAG_NONE, FileWaitCallback, + &file_wait_result, &file_wait)); + EXPECT_NE(reinterpret_cast<struct cras_file_wait*>(NULL), file_wait); poll_fd.events = POLLIN; poll_fd.fd = cras_file_wait_get_fd(file_wait); EXPECT_NE(0, poll_fd.fd >= 0); @@ -251,7 +249,7 @@ TEST(Util, FileWait) { SimpleFileWait(file_path.c_str()); // Stash the current directory. - current_dir = open(".", O_RDONLY|O_PATH|O_DIRECTORY); + current_dir = open(".", O_RDONLY | O_PATH | O_DIRECTORY); ASSERT_NE(0, current_dir >= 0); // Search for a file in the current directory. @@ -273,7 +271,7 @@ TEST(Util, FileWait) { } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/float_buffer_unittest.cc b/cras/src/tests/float_buffer_unittest.cc index 20d392e3..eee523b1 100644 --- a/cras/src/tests/float_buffer_unittest.cc +++ b/cras/src/tests/float_buffer_unittest.cc @@ -2,14 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <gtest/gtest.h> - #include "float_buffer.h" +#include <gtest/gtest.h> + namespace { TEST(FloatBuffer, ReadWrite) { unsigned int readable = 10; - struct float_buffer *b = float_buffer_create(10, 2); + struct float_buffer* b = float_buffer_create(10, 2); EXPECT_EQ(10, float_buffer_writable(b)); // (w, r)=(8, 0) @@ -45,9 +45,9 @@ TEST(FloatBuffer, ReadWrite) { float_buffer_destroy(&b); } -} // namespace +} // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/fmt_conv_ops_unittest.cc b/cras/src/tests/fmt_conv_ops_unittest.cc index 0668633c..d58d618e 100644 --- a/cras/src/tests/fmt_conv_ops_unittest.cc +++ b/cras/src/tests/fmt_conv_ops_unittest.cc @@ -3,8 +3,9 @@ // found in the LICENSE file. #include <gtest/gtest.h> -#include <sys/param.h> #include <limits.h> +#include <sys/param.h> + #include <memory> extern "C" { @@ -12,8 +13,8 @@ extern "C" { #include "cras_types.h" } -static uint8_t *AllocateRandomBytes(size_t size) { - uint8_t *buf = (uint8_t *)malloc(size); +static uint8_t* AllocateRandomBytes(size_t size) { + uint8_t* buf = (uint8_t*)malloc(size); while (size--) buf[size] = rand() & 0xff; return buf; @@ -27,44 +28,44 @@ using S32LEPtr = std::unique_ptr<int32_t[], decltype(free)*>; using FloatPtr = std::unique_ptr<float[], decltype(free)*>; static U8Ptr CreateU8(size_t size) { - uint8_t *buf = AllocateRandomBytes(size * sizeof(uint8_t)); + uint8_t* buf = AllocateRandomBytes(size * sizeof(uint8_t)); U8Ptr ret(buf, free); return ret; } static S16LEPtr CreateS16LE(size_t size) { - uint8_t *buf = AllocateRandomBytes(size * sizeof(int16_t)); - S16LEPtr ret(reinterpret_cast<int16_t *>(buf), free); + uint8_t* buf = AllocateRandomBytes(size * sizeof(int16_t)); + S16LEPtr ret(reinterpret_cast<int16_t*>(buf), free); return ret; } static S243LEPtr CreateS243LE(size_t size) { - uint8_t *buf = AllocateRandomBytes(size * sizeof(uint8_t) * 3); + uint8_t* buf = AllocateRandomBytes(size * sizeof(uint8_t) * 3); S243LEPtr ret(buf, free); return ret; } static S24LEPtr CreateS24LE(size_t size) { - uint8_t *buf = AllocateRandomBytes(size * sizeof(int32_t)); - S24LEPtr ret(reinterpret_cast<int32_t *>(buf), free); + uint8_t* buf = AllocateRandomBytes(size * sizeof(int32_t)); + S24LEPtr ret(reinterpret_cast<int32_t*>(buf), free); return ret; } static S32LEPtr CreateS32LE(size_t size) { - uint8_t *buf = AllocateRandomBytes(size * sizeof(int32_t)); - S32LEPtr ret(reinterpret_cast<int32_t *>(buf), free); + uint8_t* buf = AllocateRandomBytes(size * sizeof(int32_t)); + S32LEPtr ret(reinterpret_cast<int32_t*>(buf), free); return ret; } static FloatPtr CreateFloat(size_t size) { - float *buf = (float *)malloc(size * sizeof(float)); + float* buf = (float*)malloc(size * sizeof(float)); while (size--) buf[size] = (float)(rand() & 0xff) / 0xfff; FloatPtr ret(buf, free); return ret; } -static int32_t ToS243LE(const uint8_t *in) { +static int32_t ToS243LE(const uint8_t* in) { int32_t ret = 0; ret |= in[2]; @@ -93,7 +94,7 @@ TEST(FormatConverterOpsTest, ConvertU8ToS16LE) { U8Ptr src = CreateU8(frames * in_ch); S16LEPtr dst = CreateS16LE(frames * out_ch); - convert_u8_to_s16le(src.get(), frames * in_ch, (uint8_t *)dst.get()); + convert_u8_to_s16le(src.get(), frames * in_ch, (uint8_t*)dst.get()); for (size_t i = 0; i < frames * in_ch; ++i) { EXPECT_EQ((int16_t)((uint16_t)((int16_t)(int8_t)src[i] - 0x80) << 8), @@ -110,9 +111,9 @@ TEST(FormatConverterOpsTest, ConvertS243LEToS16LE) { S243LEPtr src = CreateS243LE(frames * in_ch); S16LEPtr dst = CreateS16LE(frames * out_ch); - convert_s243le_to_s16le(src.get(), frames * in_ch, (uint8_t *)dst.get()); + convert_s243le_to_s16le(src.get(), frames * in_ch, (uint8_t*)dst.get()); - uint8_t *p = src.get(); + uint8_t* p = src.get(); for (size_t i = 0; i < frames * in_ch; ++i) { EXPECT_EQ((int16_t)(ToS243LE(p) >> 8), dst[i]); p += 3; @@ -128,8 +129,8 @@ TEST(FormatConverterOpsTest, ConvertS24LEToS16LE) { S24LEPtr src = CreateS24LE(frames * in_ch); S16LEPtr dst = CreateS16LE(frames * out_ch); - convert_s24le_to_s16le((uint8_t *)src.get(), frames * in_ch, - (uint8_t *)dst.get()); + convert_s24le_to_s16le((uint8_t*)src.get(), frames * in_ch, + (uint8_t*)dst.get()); for (size_t i = 0; i < frames * in_ch; ++i) { EXPECT_EQ((int16_t)(src[i] >> 8), dst[i]); @@ -145,8 +146,8 @@ TEST(FormatConverterOpsTest, ConvertS32LEToS16LE) { S32LEPtr src = CreateS32LE(frames * in_ch); S16LEPtr dst = CreateS16LE(frames * out_ch); - convert_s32le_to_s16le((uint8_t *)src.get(), frames * in_ch, - (uint8_t *)dst.get()); + convert_s32le_to_s16le((uint8_t*)src.get(), frames * in_ch, + (uint8_t*)dst.get()); for (size_t i = 0; i < frames * in_ch; ++i) { EXPECT_EQ((int16_t)(src[i] >> 16), dst[i]); @@ -162,7 +163,7 @@ TEST(FormatConverterOpsTest, ConvertS16LEToU8) { S16LEPtr src = CreateS16LE(frames * in_ch); U8Ptr dst = CreateU8(frames * out_ch); - convert_s16le_to_u8((uint8_t *)src.get(), frames * in_ch, dst.get()); + convert_s16le_to_u8((uint8_t*)src.get(), frames * in_ch, dst.get()); for (size_t i = 0; i < frames * in_ch; ++i) { EXPECT_EQ((uint8_t)(int8_t)((src[i] >> 8) + 0x80), dst[i]); @@ -178,9 +179,9 @@ TEST(FormatConverterOpsTest, ConvertS16LEToS243LE) { S16LEPtr src = CreateS16LE(frames * in_ch); S243LEPtr dst = CreateS243LE(frames * out_ch); - convert_s16le_to_s243le((uint8_t *)src.get(), frames * in_ch, dst.get()); + convert_s16le_to_s243le((uint8_t*)src.get(), frames * in_ch, dst.get()); - uint8_t *p = dst.get(); + uint8_t* p = dst.get(); for (size_t i = 0; i < frames * in_ch; ++i) { EXPECT_EQ((int32_t)((uint32_t)src[i] << 8) & 0x00ffffff, ToS243LE(p) & 0x00ffffff); @@ -197,8 +198,8 @@ TEST(FormatConverterOpsTest, ConvertS16LEToS24LE) { S16LEPtr src = CreateS16LE(frames * in_ch); S24LEPtr dst = CreateS24LE(frames * out_ch); - convert_s16le_to_s24le((uint8_t *)src.get(), frames * in_ch, - (uint8_t *)dst.get()); + convert_s16le_to_s24le((uint8_t*)src.get(), frames * in_ch, + (uint8_t*)dst.get()); for (size_t i = 0; i < frames * in_ch; ++i) { EXPECT_EQ((int32_t)((uint32_t)src[i] << 8) & 0x00ffffff, @@ -215,8 +216,8 @@ TEST(FormatConverterOpsTest, ConvertS16LEToS32LE) { S16LEPtr src = CreateS16LE(frames * in_ch); S32LEPtr dst = CreateS32LE(frames * out_ch); - convert_s16le_to_s32le((uint8_t *)src.get(), frames * in_ch, - (uint8_t *)dst.get()); + convert_s16le_to_s32le((uint8_t*)src.get(), frames * in_ch, + (uint8_t*)dst.get()); for (size_t i = 0; i < frames * in_ch; ++i) { EXPECT_EQ((int32_t)((uint32_t)src[i] << 16) & 0xffffff00, @@ -233,8 +234,8 @@ TEST(FormatConverterOpsTest, MonoToStereoS16LE) { S16LEPtr src = CreateS16LE(frames * in_ch); S16LEPtr dst = CreateS16LE(frames * out_ch); - size_t ret = s16_mono_to_stereo((uint8_t *)src.get(), frames, - (uint8_t *)dst.get()); + size_t ret = + s16_mono_to_stereo((uint8_t*)src.get(), frames, (uint8_t*)dst.get()); EXPECT_EQ(ret, frames); for (size_t i = 0; i < frames; ++i) { @@ -256,8 +257,8 @@ TEST(FormatConverterOpsTest, StereoToMonoS16LE) { src[i * 2 + 1] = -13449; } - size_t ret = s16_stereo_to_mono((uint8_t *)src.get(), frames, - (uint8_t *)dst.get()); + size_t ret = + s16_stereo_to_mono((uint8_t*)src.get(), frames, (uint8_t*)dst.get()); EXPECT_EQ(ret, frames); for (size_t i = 0; i < frames; ++i) { @@ -278,8 +279,8 @@ TEST(FormatConverterOpsTest, StereoToMonoS16LEOverflow) { src[i * 2 + 1] = 1; } - size_t ret = s16_stereo_to_mono((uint8_t *)src.get(), frames, - (uint8_t *)dst.get()); + size_t ret = + s16_stereo_to_mono((uint8_t*)src.get(), frames, (uint8_t*)dst.get()); EXPECT_EQ(ret, frames); for (size_t i = 0; i < frames; ++i) { @@ -300,8 +301,8 @@ TEST(FormatConverterOpsTest, StereoToMonoS16LEUnderflow) { src[i * 2 + 1] = -0x1; } - size_t ret = s16_stereo_to_mono((uint8_t *)src.get(), frames, - (uint8_t *)dst.get()); + size_t ret = + s16_stereo_to_mono((uint8_t*)src.get(), frames, (uint8_t*)dst.get()); EXPECT_EQ(ret, frames); for (size_t i = 0; i < frames; ++i) { @@ -321,8 +322,8 @@ TEST(FormatConverterOpsTest, MonoTo51S16LECenter) { S16LEPtr src = CreateS16LE(frames * in_ch); S16LEPtr dst = CreateS16LE(frames * out_ch); - size_t ret = s16_mono_to_51(left, right, center, (uint8_t *)src.get(), frames, - (uint8_t *)dst.get()); + size_t ret = s16_mono_to_51(left, right, center, (uint8_t*)src.get(), frames, + (uint8_t*)dst.get()); EXPECT_EQ(ret, frames); for (size_t i = 0; i < frames; ++i) { @@ -347,8 +348,8 @@ TEST(FormatConverterOpsTest, MonoTo51S16LELeftRight) { S16LEPtr src = CreateS16LE(frames * in_ch); S16LEPtr dst = CreateS16LE(frames * out_ch); - size_t ret = s16_mono_to_51(left, right, center, (uint8_t *)src.get(), frames, - (uint8_t *)dst.get()); + size_t ret = s16_mono_to_51(left, right, center, (uint8_t*)src.get(), frames, + (uint8_t*)dst.get()); EXPECT_EQ(ret, frames); for (size_t i = 0; i < frames; ++i) { @@ -375,8 +376,8 @@ TEST(FormatConverterOpsTest, MonoTo51S16LEUnknown) { S16LEPtr src = CreateS16LE(frames * in_ch); S16LEPtr dst = CreateS16LE(frames * out_ch); - size_t ret = s16_mono_to_51(left, right, center, (uint8_t *)src.get(), frames, - (uint8_t *)dst.get()); + size_t ret = s16_mono_to_51(left, right, center, (uint8_t*)src.get(), frames, + (uint8_t*)dst.get()); EXPECT_EQ(ret, frames); for (size_t i = 0; i < frames; ++i) { @@ -401,15 +402,14 @@ TEST(FormatConverterOpsTest, StereoTo51S16LECenter) { S16LEPtr src = CreateS16LE(frames * in_ch); S16LEPtr dst = CreateS16LE(frames * out_ch); - size_t ret = s16_stereo_to_51(left, right, center, (uint8_t *)src.get(), - frames, (uint8_t *)dst.get()); + size_t ret = s16_stereo_to_51(left, right, center, (uint8_t*)src.get(), + frames, (uint8_t*)dst.get()); EXPECT_EQ(ret, frames); for (size_t i = 0; i < frames; ++i) { for (size_t k = 0; k < 6; ++k) { if (k == center) - EXPECT_EQ(S16AddAndClip(src[i * 2], src[i * 2 + 1]), - dst[i * 6 + k]); + EXPECT_EQ(S16AddAndClip(src[i * 2], src[i * 2 + 1]), dst[i * 6 + k]); else EXPECT_EQ(0, dst[i * 6 + k]); } @@ -428,8 +428,8 @@ TEST(FormatConverterOpsTest, StereoTo51S16LELeftRight) { S16LEPtr src = CreateS16LE(frames * in_ch); S16LEPtr dst = CreateS16LE(frames * out_ch); - size_t ret = s16_stereo_to_51(left, right, center, (uint8_t *)src.get(), - frames, (uint8_t *)dst.get()); + size_t ret = s16_stereo_to_51(left, right, center, (uint8_t*)src.get(), + frames, (uint8_t*)dst.get()); EXPECT_EQ(ret, frames); for (size_t i = 0; i < frames; ++i) { @@ -456,8 +456,8 @@ TEST(FormatConverterOpsTest, StereoTo51S16LEUnknown) { S16LEPtr src = CreateS16LE(frames * in_ch); S16LEPtr dst = CreateS16LE(frames * out_ch); - size_t ret = s16_stereo_to_51(left, right, center, (uint8_t *)src.get(), - frames, (uint8_t *)dst.get()); + size_t ret = s16_stereo_to_51(left, right, center, (uint8_t*)src.get(), + frames, (uint8_t*)dst.get()); EXPECT_EQ(ret, frames); for (size_t i = 0; i < frames; ++i) { @@ -482,14 +482,13 @@ TEST(FormatConverterOpsTest, _51ToStereoS16LE) { S16LEPtr src = CreateS16LE(frames * in_ch); S16LEPtr dst = CreateS16LE(frames * out_ch); - size_t ret = s16_51_to_stereo((uint8_t *)src.get(), frames, - (uint8_t *)dst.get()); + size_t ret = + s16_51_to_stereo((uint8_t*)src.get(), frames, (uint8_t*)dst.get()); EXPECT_EQ(ret, frames); for (size_t i = 0; i < frames; ++i) { int16_t half_center = src[i * 6 + center] / 2; - EXPECT_EQ(S16AddAndClip(src[i * 6 + left], half_center), - dst[i * 2 + left]); + EXPECT_EQ(S16AddAndClip(src[i * 6 + left], half_center), dst[i * 2 + left]); EXPECT_EQ(S16AddAndClip(src[i * 6 + right], half_center), dst[i * 2 + right]); } @@ -508,10 +507,9 @@ TEST(FormatConverterOpsTest, StereoToQuadS16LESpecify) { S16LEPtr src = CreateS16LE(frames * in_ch); S16LEPtr dst = CreateS16LE(frames * out_ch); - size_t ret = s16_stereo_to_quad(front_left, front_right, - rear_left, rear_right, - (uint8_t *)src.get(), frames, - (uint8_t *)dst.get()); + size_t ret = + s16_stereo_to_quad(front_left, front_right, rear_left, rear_right, + (uint8_t*)src.get(), frames, (uint8_t*)dst.get()); EXPECT_EQ(ret, frames); for (size_t i = 0; i < frames; ++i) { @@ -535,10 +533,9 @@ TEST(FormatConverterOpsTest, StereoToQuadS16LEDefault) { S16LEPtr src = CreateS16LE(frames * in_ch); S16LEPtr dst = CreateS16LE(frames * out_ch); - size_t ret = s16_stereo_to_quad(front_left, front_right, - rear_left, rear_right, - (uint8_t *)src.get(), frames, - (uint8_t *)dst.get()); + size_t ret = + s16_stereo_to_quad(front_left, front_right, rear_left, rear_right, + (uint8_t*)src.get(), frames, (uint8_t*)dst.get()); EXPECT_EQ(ret, frames); for (size_t i = 0; i < frames; ++i) { @@ -562,17 +559,16 @@ TEST(FormatConverterOpsTest, QuadToStereoS16LESpecify) { S16LEPtr src = CreateS16LE(frames * in_ch); S16LEPtr dst = CreateS16LE(frames * out_ch); - size_t ret = s16_quad_to_stereo(front_left, front_right, - rear_left, rear_right, - (uint8_t *)src.get(), frames, - (uint8_t *)dst.get()); + size_t ret = + s16_quad_to_stereo(front_left, front_right, rear_left, rear_right, + (uint8_t*)src.get(), frames, (uint8_t*)dst.get()); EXPECT_EQ(ret, frames); for (size_t i = 0; i < frames; ++i) { - int16_t left = S16AddAndClip(src[i * 4 + front_left], - src[i * 4 + rear_left] / 4); - int16_t right = S16AddAndClip(src[i * 4 + front_right], - src[i * 4 + rear_right] / 4); + int16_t left = + S16AddAndClip(src[i * 4 + front_left], src[i * 4 + rear_left] / 4); + int16_t right = + S16AddAndClip(src[i * 4 + front_right], src[i * 4 + rear_right] / 4); EXPECT_EQ(left, dst[i * 2 + 0]); EXPECT_EQ(right, dst[i * 2 + 1]); } @@ -591,17 +587,14 @@ TEST(FormatConverterOpsTest, QuadToStereoS16LEDefault) { S16LEPtr src = CreateS16LE(frames * in_ch); S16LEPtr dst = CreateS16LE(frames * out_ch); - size_t ret = s16_quad_to_stereo(front_left, front_right, - rear_left, rear_right, - (uint8_t *)src.get(), frames, - (uint8_t *)dst.get()); + size_t ret = + s16_quad_to_stereo(front_left, front_right, rear_left, rear_right, + (uint8_t*)src.get(), frames, (uint8_t*)dst.get()); EXPECT_EQ(ret, frames); for (size_t i = 0; i < frames; ++i) { - int16_t left = S16AddAndClip(src[i * 4 + 0], - src[i * 4 + 2] / 4); - int16_t right = S16AddAndClip(src[i * 4 + 1], - src[i * 4 + 3] / 4); + int16_t left = S16AddAndClip(src[i * 4 + 0], src[i * 4 + 2] / 4); + int16_t right = S16AddAndClip(src[i * 4 + 1], src[i * 4 + 3] / 4); EXPECT_EQ(left, dst[i * 2 + 0]); EXPECT_EQ(right, dst[i * 2 + 1]); } @@ -613,17 +606,16 @@ TEST(FormatConverterOpsTest, StereoTo3chS16LE) { const size_t in_ch = 2; const size_t out_ch = 3; struct cras_audio_format fmt = { - .format = SND_PCM_FORMAT_S16_LE, - .frame_rate = 48000, - .num_channels = 3, + .format = SND_PCM_FORMAT_S16_LE, + .frame_rate = 48000, + .num_channels = 3, }; S16LEPtr src = CreateS16LE(frames * in_ch); S16LEPtr dst = CreateS16LE(frames * out_ch); - size_t ret = s16_default_all_to_all(&fmt, in_ch, out_ch, - (uint8_t *)src.get(), frames, - (uint8_t *)dst.get()); + size_t ret = s16_default_all_to_all(&fmt, in_ch, out_ch, (uint8_t*)src.get(), + frames, (uint8_t*)dst.get()); EXPECT_EQ(ret, frames); for (size_t i = 0; i < frames; ++i) { @@ -664,13 +656,13 @@ TEST(FormatConverterOpsTest, ConvertChannelsS16LE) { S16LEPtr src = CreateS16LE(frames * in_ch); S16LEPtr dst = CreateS16LE(frames * out_ch); FloatPtr ch_conv_mtx = CreateFloat(out_ch * in_ch); - std::unique_ptr<float *[]> mtx(new float *[out_ch]); + std::unique_ptr<float*[]> mtx(new float*[out_ch]); for (size_t i = 0; i < out_ch; ++i) mtx[i] = &ch_conv_mtx[i * in_ch]; - size_t ret = s16_convert_channels(mtx.get(), in_ch, out_ch, - (uint8_t *)src.get(), frames, - (uint8_t *)dst.get()); + size_t ret = + s16_convert_channels(mtx.get(), in_ch, out_ch, (uint8_t*)src.get(), + frames, (uint8_t*)dst.get()); EXPECT_EQ(ret, frames); for (size_t fr = 0; fr < frames; ++fr) { @@ -684,11 +676,9 @@ TEST(FormatConverterOpsTest, ConvertChannelsS16LE) { } } -extern "C" { - -} // extern "C" +extern "C" {} // extern "C" -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/fmt_conv_unittest.cc b/cras/src/tests/fmt_conv_unittest.cc index 0226e172..5474f172 100644 --- a/cras/src/tests/fmt_conv_unittest.cc +++ b/cras/src/tests/fmt_conv_unittest.cc @@ -10,18 +10,18 @@ extern "C" { #include "cras_types.h" } -static int mono_channel_layout[CRAS_CH_MAX] = - {-1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1}; -static int stereo_channel_layout[CRAS_CH_MAX] = - {0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; -static int surround_channel_center_layout[CRAS_CH_MAX] = - {0, 1, 2, 3, 4, 5, -1, -1, -1, -1, -1}; -static int surround_channel_left_right_layout[CRAS_CH_MAX] = - {0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; -static int surround_channel_unknown_layout[CRAS_CH_MAX] = - {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; -static int quad_channel_layout[CRAS_CH_MAX] = - {0, 1, 2, 3, -1, -1, -1, -1, -1, -1, -1}; +static int mono_channel_layout[CRAS_CH_MAX] = {-1, -1, -1, -1, 0, -1, + -1, -1, -1, -1, -1}; +static int stereo_channel_layout[CRAS_CH_MAX] = {0, 1, -1, -1, -1, -1, + -1, -1, -1, -1, -1}; +static int surround_channel_center_layout[CRAS_CH_MAX] = {0, 1, 2, 3, 4, 5, + -1, -1, -1, -1, -1}; +static int surround_channel_left_right_layout[CRAS_CH_MAX] = { + 0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; +static int surround_channel_unknown_layout[CRAS_CH_MAX] = { + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; +static int quad_channel_layout[CRAS_CH_MAX] = {0, 1, 2, 3, -1, -1, + -1, -1, -1, -1, -1}; static int linear_resampler_needed_val; static double linear_resampler_ratio = 1.0; static unsigned int linear_resampler_num_channels; @@ -35,27 +35,27 @@ void ResetStub() { } // Like malloc or calloc, but fill the memory with random bytes. -static void *ralloc(size_t size) { - unsigned char *buf = (unsigned char *)malloc(size); +static void* ralloc(size_t size) { + unsigned char* buf = (unsigned char*)malloc(size); while (size--) buf[size] = rand() & 0xff; return buf; } -static void swap_channel_layout(int8_t *layout, +static void swap_channel_layout(int8_t* layout, CRAS_CHANNEL a, - CRAS_CHANNEL b) { - int8_t tmp = layout[a]; - layout[a] = layout[b]; - layout[b] = tmp; + CRAS_CHANNEL b) { + int8_t tmp = layout[a]; + layout[a] = layout[b]; + layout[b] = tmp; } TEST(FormatConverterTest, SmallFramesSRCWithLinearResampler) { struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; - struct cras_fmt_conv *c; - int16_t *in_buf; - int16_t *out_buf; + struct cras_fmt_conv* c; + int16_t* in_buf; + int16_t* out_buf; unsigned int in_frames = 1; unsigned int out_frames = 2; @@ -66,11 +66,11 @@ TEST(FormatConverterTest, SmallFramesSRCWithLinearResampler) { out_fmt.frame_rate = 48000; linear_resampler_needed_val = 1; - in_buf = (int16_t *)malloc(10 * 2 * 2); - out_buf = (int16_t *)malloc(10 * 2 * 2); + in_buf = (int16_t*)malloc(10 * 2 * 2); + out_buf = (int16_t*)malloc(10 * 2 * 2); c = cras_fmt_conv_create(&in_fmt, &out_fmt, 10, 1); - EXPECT_NE((void *)NULL, c); + EXPECT_NE((void*)NULL, c); EXPECT_EQ(out_fmt.frame_rate, linear_resampler_src_rate); EXPECT_EQ(out_fmt.frame_rate, linear_resampler_dst_rate); @@ -83,19 +83,15 @@ TEST(FormatConverterTest, SmallFramesSRCWithLinearResampler) { * Total result is 1 frame consumed in input and generated * 3 frames in output. */ - out_frames = cras_fmt_conv_convert_frames(c, (uint8_t *)in_buf, - (uint8_t *)out_buf, - &in_frames, - out_frames); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buf, (uint8_t*)out_buf, &in_frames, out_frames); EXPECT_EQ(2, out_frames); EXPECT_EQ(0, in_frames); in_frames = 1; out_frames = 2; - out_frames = cras_fmt_conv_convert_frames(c, (uint8_t *)in_buf, - (uint8_t *)out_buf, - &in_frames, - out_frames); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buf, (uint8_t*)out_buf, &in_frames, out_frames); EXPECT_EQ(1, out_frames); EXPECT_EQ(1, in_frames); @@ -105,10 +101,10 @@ TEST(FormatConverterTest, SmallFramesSRCWithLinearResampler) { } // Only support LE, BE should fail. -TEST(FormatConverterTest, InvalidParamsOnlyLE) { +TEST(FormatConverterTest, InvalidParamsOnlyLE) { struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; ResetStub(); in_fmt.format = out_fmt.format = SND_PCM_FORMAT_S32_BE; @@ -119,13 +115,13 @@ TEST(FormatConverterTest, InvalidParamsOnlyLE) { // Test Mono to Stereo mix. TEST(FormatConverterTest, MonoToStereo) { - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; - int16_t *in_buff; - int16_t *out_buff; + int16_t* in_buff; + int16_t* out_buff; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; @@ -138,7 +134,7 @@ TEST(FormatConverterTest, MonoToStereo) { out_fmt.frame_rate = 48000; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_out_frames_to_in(c, buf_size); EXPECT_EQ(buf_size, out_frames); @@ -146,17 +142,13 @@ TEST(FormatConverterTest, MonoToStereo) { out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_EQ(buf_size, out_frames); - in_buff = (int16_t *)ralloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); - out_buff = (int16_t *)ralloc(buf_size * 2 * cras_get_format_bytes(&out_fmt)); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + in_buff = (int16_t*)ralloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); + out_buff = (int16_t*)ralloc(buf_size * 2 * cras_get_format_bytes(&out_fmt)); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(buf_size, out_frames); for (size_t i = 0; i < buf_size; i++) { - if (in_buff[i] != out_buff[i*2] || - in_buff[i] != out_buff[i*2 + 1]) { + if (in_buff[i] != out_buff[i * 2] || in_buff[i] != out_buff[i * 2 + 1]) { EXPECT_TRUE(false); break; } @@ -169,13 +161,13 @@ TEST(FormatConverterTest, MonoToStereo) { // Test Stereo to Mono mix. TEST(FormatConverterTest, StereoToMono) { - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; - int16_t *in_buff; - int16_t *out_buff; + int16_t* in_buff; + int16_t* out_buff; unsigned int i; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; @@ -189,7 +181,7 @@ TEST(FormatConverterTest, StereoToMono) { out_fmt.frame_rate = 48000; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_out_frames_to_in(c, buf_size); EXPECT_EQ(buf_size, out_frames); @@ -197,17 +189,14 @@ TEST(FormatConverterTest, StereoToMono) { out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_EQ(buf_size, out_frames); - in_buff = (int16_t *)malloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); - out_buff = (int16_t *)malloc(buf_size * cras_get_format_bytes(&out_fmt)); + in_buff = (int16_t*)malloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); + out_buff = (int16_t*)malloc(buf_size * cras_get_format_bytes(&out_fmt)); for (i = 0; i < buf_size; i++) { in_buff[i * 2] = 13450; in_buff[i * 2 + 1] = -13449; } - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(buf_size, out_frames); for (i = 0; i < buf_size; i++) { EXPECT_EQ(1, out_buff[i]); @@ -220,13 +209,13 @@ TEST(FormatConverterTest, StereoToMono) { // Test Stereo to Mono mix. Overflow. TEST(FormatConverterTest, StereoToMonoOverflow) { - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; - int16_t *in_buff; - int16_t *out_buff; + int16_t* in_buff; + int16_t* out_buff; unsigned int i; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; @@ -240,7 +229,7 @@ TEST(FormatConverterTest, StereoToMonoOverflow) { out_fmt.frame_rate = 48000; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_out_frames_to_in(c, buf_size); EXPECT_EQ(buf_size, out_frames); @@ -248,17 +237,14 @@ TEST(FormatConverterTest, StereoToMonoOverflow) { out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_EQ(buf_size, out_frames); - in_buff = (int16_t *)malloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); - out_buff = (int16_t *)malloc(buf_size * cras_get_format_bytes(&out_fmt)); + in_buff = (int16_t*)malloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); + out_buff = (int16_t*)malloc(buf_size * cras_get_format_bytes(&out_fmt)); for (i = 0; i < buf_size; i++) { in_buff[i * 2] = 0x7fff; in_buff[i * 2 + 1] = 1; } - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(buf_size, out_frames); for (i = 0; i < buf_size; i++) { EXPECT_EQ(0x7fff, out_buff[i]); @@ -271,13 +257,13 @@ TEST(FormatConverterTest, StereoToMonoOverflow) { // Test Stereo to Mono mix. Underflow. TEST(FormatConverterTest, StereoToMonoUnderflow) { - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; - int16_t *in_buff; - int16_t *out_buff; + int16_t* in_buff; + int16_t* out_buff; unsigned int i; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; @@ -291,7 +277,7 @@ TEST(FormatConverterTest, StereoToMonoUnderflow) { out_fmt.frame_rate = 48000; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_out_frames_to_in(c, buf_size); EXPECT_EQ(buf_size, out_frames); @@ -299,17 +285,14 @@ TEST(FormatConverterTest, StereoToMonoUnderflow) { out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_EQ(buf_size, out_frames); - in_buff = (int16_t *)malloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); - out_buff = (int16_t *)malloc(buf_size * cras_get_format_bytes(&out_fmt)); + in_buff = (int16_t*)malloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); + out_buff = (int16_t*)malloc(buf_size * cras_get_format_bytes(&out_fmt)); for (i = 0; i < buf_size; i++) { in_buff[i * 2] = -0x8000; in_buff[i * 2 + 1] = -1; } - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(buf_size, out_frames); for (i = 0; i < buf_size; i++) { EXPECT_EQ(-0x8000, out_buff[i]); @@ -322,13 +305,13 @@ TEST(FormatConverterTest, StereoToMonoUnderflow) { // Test Stereo to Mono mix 24 and 32 bit. TEST(FormatConverterTest, StereoToMono24bit) { - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; - int32_t *in_buff; - int32_t *out_buff; + int32_t* in_buff; + int32_t* out_buff; unsigned int i; const size_t buf_size = 100; unsigned int in_buf_size = 100; @@ -349,7 +332,7 @@ TEST(FormatConverterTest, StereoToMono24bit) { out_fmt.frame_rate = 48000; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_out_frames_to_in(c, buf_size); EXPECT_EQ(buf_size, out_frames); @@ -357,21 +340,18 @@ TEST(FormatConverterTest, StereoToMono24bit) { out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_EQ(buf_size, out_frames); - in_buff = (int32_t *)malloc(buf_size * cras_get_format_bytes(&in_fmt)); - out_buff = (int32_t *)malloc(buf_size * cras_get_format_bytes(&out_fmt)); + in_buff = (int32_t*)malloc(buf_size * cras_get_format_bytes(&in_fmt)); + out_buff = (int32_t*)malloc(buf_size * cras_get_format_bytes(&out_fmt)); // TODO(dgreid) - s/0x10000/1/ once it stays full bits the whole way. for (i = 0; i < buf_size; i++) { - in_buff[i * 2] = 13450 << 16; - in_buff[i * 2 + 1] = -in_buff[i * 2] + 0x10000; + in_buff[i * 2] = 13450 << 16; + in_buff[i * 2 + 1] = -in_buff[i * 2] + 0x10000; } - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(buf_size, out_frames); for (i = 0; i < buf_size; i++) { - EXPECT_EQ(0x10000, out_buff[i]); + EXPECT_EQ(0x10000, out_buff[i]); } cras_fmt_conv_destroy(&c); @@ -382,13 +362,13 @@ TEST(FormatConverterTest, StereoToMono24bit) { // Test 5.1 to Stereo mix. TEST(FormatConverterTest, SurroundToStereo) { - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; - int16_t *in_buff; - int16_t *out_buff; + int16_t* in_buff; + int16_t* out_buff; unsigned int i; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; @@ -404,7 +384,7 @@ TEST(FormatConverterTest, SurroundToStereo) { in_fmt.channel_layout[i] = surround_channel_center_layout[i]; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_out_frames_to_in(c, buf_size); EXPECT_EQ(buf_size, out_frames); @@ -412,7 +392,7 @@ TEST(FormatConverterTest, SurroundToStereo) { out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_EQ(buf_size, out_frames); - in_buff = (int16_t *)malloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); + in_buff = (int16_t*)malloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); /* Swap channel to FL = 13450, RL = -100. * Assert right channel is silent. @@ -425,12 +405,9 @@ TEST(FormatConverterTest, SurroundToStereo) { in_buff[i * 6 + 4] = 0; in_buff[i * 6 + 5] = 0; } - out_buff = (int16_t *)malloc(buf_size * 2 * cras_get_format_bytes(&out_fmt)); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + out_buff = (int16_t*)malloc(buf_size * 2 * cras_get_format_bytes(&out_fmt)); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(buf_size, out_frames); for (i = 0; i < buf_size; i++) EXPECT_LT(0, out_buff[i * 2]); @@ -442,11 +419,8 @@ TEST(FormatConverterTest, SurroundToStereo) { swap_channel_layout(in_fmt.channel_layout, CRAS_CH_FL, CRAS_CH_FR); swap_channel_layout(in_fmt.channel_layout, CRAS_CH_RL, CRAS_CH_RR); c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(buf_size, out_frames); for (i = 0; i < buf_size; i++) EXPECT_LT(0, out_buff[i * 2 + 1]); @@ -458,11 +432,8 @@ TEST(FormatConverterTest, SurroundToStereo) { swap_channel_layout(in_fmt.channel_layout, CRAS_CH_FR, CRAS_CH_FC); swap_channel_layout(in_fmt.channel_layout, CRAS_CH_RR, CRAS_CH_LFE); c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(buf_size, out_frames); for (i = 0; i < buf_size; i++) { EXPECT_NE(0, out_buff[i * 2]); @@ -475,11 +446,8 @@ TEST(FormatConverterTest, SurroundToStereo) { swap_channel_layout(in_fmt.channel_layout, CRAS_CH_LFE, CRAS_CH_FR); swap_channel_layout(in_fmt.channel_layout, CRAS_CH_FC, CRAS_CH_FL); c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(buf_size, out_frames); for (i = 0; i < buf_size; i++) { EXPECT_LT(0, out_buff[i * 2]); @@ -493,13 +461,13 @@ TEST(FormatConverterTest, SurroundToStereo) { // Test Quad to Stereo mix. TEST(FormatConverterTest, QuadToStereo) { - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; - int16_t *in_buff; - int16_t *out_buff; + int16_t* in_buff; + int16_t* out_buff; unsigned int i; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; @@ -515,7 +483,7 @@ TEST(FormatConverterTest, QuadToStereo) { in_fmt.channel_layout[i] = quad_channel_layout[i]; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_out_frames_to_in(c, buf_size); EXPECT_EQ(buf_size, out_frames); @@ -523,7 +491,7 @@ TEST(FormatConverterTest, QuadToStereo) { out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_EQ(buf_size, out_frames); - in_buff = (int16_t *)malloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); + in_buff = (int16_t*)malloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); /* * Set left channel positive, right channel negative, assert values are @@ -535,13 +503,10 @@ TEST(FormatConverterTest, QuadToStereo) { in_buff[i * 4 + 2] = 80; in_buff[i * 4 + 3] = -80; } - out_buff = (int16_t *)malloc(buf_size * 2 * cras_get_format_bytes(&out_fmt)); + out_buff = (int16_t*)malloc(buf_size * 2 * cras_get_format_bytes(&out_fmt)); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(buf_size, out_frames); for (i = 0; i < buf_size; i++) { EXPECT_EQ(820, out_buff[i * 2]); @@ -555,11 +520,8 @@ TEST(FormatConverterTest, QuadToStereo) { swap_channel_layout(in_fmt.channel_layout, CRAS_CH_FL, CRAS_CH_FR); swap_channel_layout(in_fmt.channel_layout, CRAS_CH_RL, CRAS_CH_RR); c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(buf_size, out_frames); for (i = 0; i < buf_size; i++) { EXPECT_EQ(-820, out_buff[i * 2]); @@ -573,11 +535,8 @@ TEST(FormatConverterTest, QuadToStereo) { swap_channel_layout(in_fmt.channel_layout, CRAS_CH_FR, CRAS_CH_RR); swap_channel_layout(in_fmt.channel_layout, CRAS_CH_FL, CRAS_CH_RL); c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(buf_size, out_frames); for (i = 0; i < buf_size; i++) { EXPECT_EQ(-280, out_buff[i * 2]); @@ -591,11 +550,8 @@ TEST(FormatConverterTest, QuadToStereo) { for (i = 0; i < CRAS_CH_MAX; i++) in_fmt.channel_layout[i] = -1; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(buf_size, out_frames); for (i = 0; i < buf_size; i++) { EXPECT_EQ(820, out_buff[i * 2]); @@ -608,14 +564,14 @@ TEST(FormatConverterTest, QuadToStereo) { } // Test 2 to 1 SRC. -TEST(FormatConverterTest, Convert2To1) { - struct cras_fmt_conv *c; +TEST(FormatConverterTest, Convert2To1) { + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; - int16_t *in_buff; - int16_t *out_buff; + int16_t* in_buff; + int16_t* out_buff; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; @@ -626,31 +582,28 @@ TEST(FormatConverterTest, Convert2To1) { out_fmt.frame_rate = 48000; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); - EXPECT_EQ(buf_size/2, out_frames); - - in_buff = (int16_t *)ralloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); - out_buff = (int16_t *)ralloc(buf_size/2 * cras_get_format_bytes(&out_fmt)); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size / 2); + EXPECT_EQ(buf_size / 2, out_frames); + + in_buff = (int16_t*)ralloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); + out_buff = (int16_t*)ralloc(buf_size / 2 * cras_get_format_bytes(&out_fmt)); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size / 2); cras_fmt_conv_destroy(&c); free(in_buff); free(out_buff); } // Test 1 to 2 SRC. -TEST(FormatConverterTest, Convert1To2) { - struct cras_fmt_conv *c; +TEST(FormatConverterTest, Convert1To2) { + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; - int16_t *in_buff; - int16_t *out_buff; + int16_t* in_buff; + int16_t* out_buff; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; @@ -661,31 +614,28 @@ TEST(FormatConverterTest, Convert1To2) { out_fmt.frame_rate = 44100; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); - EXPECT_EQ(buf_size*2, out_frames); - - in_buff = (int16_t *)ralloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); - out_buff = (int16_t *)ralloc(buf_size*2 * cras_get_format_bytes(&out_fmt)); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size * 2); + EXPECT_EQ(buf_size * 2, out_frames); + + in_buff = (int16_t*)ralloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); + out_buff = (int16_t*)ralloc(buf_size * 2 * cras_get_format_bytes(&out_fmt)); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size * 2); cras_fmt_conv_destroy(&c); free(in_buff); free(out_buff); } // Test 1 to 2 SRC with mono to stereo conversion. -TEST(FormatConverterTest, Convert1To2MonoToStereo) { - struct cras_fmt_conv *c; +TEST(FormatConverterTest, Convert1To2MonoToStereo) { + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; - int16_t *in_buff; - int16_t *out_buff; + int16_t* in_buff; + int16_t* out_buff; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; @@ -697,7 +647,7 @@ TEST(FormatConverterTest, Convert1To2MonoToStereo) { out_fmt.frame_rate = 44100; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_out_frames_to_in(c, buf_size); EXPECT_EQ(buf_size / 2, out_frames); @@ -705,13 +655,10 @@ TEST(FormatConverterTest, Convert1To2MonoToStereo) { out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_EQ(buf_size * 2, out_frames); - in_buff = (int16_t *)ralloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); - out_buff = (int16_t *)ralloc(buf_size * 2 * cras_get_format_bytes(&out_fmt)); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size * 2); + in_buff = (int16_t*)ralloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); + out_buff = (int16_t*)ralloc(buf_size * 2 * cras_get_format_bytes(&out_fmt)); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size * 2); cras_fmt_conv_destroy(&c); free(in_buff); free(out_buff); @@ -719,13 +666,13 @@ TEST(FormatConverterTest, Convert1To2MonoToStereo) { // Test 32 to 16 bit conversion. TEST(FormatConverterTest, ConvertS32LEToS16LE) { - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; - int32_t *in_buff; - int16_t *out_buff; + int32_t* in_buff; + int16_t* out_buff; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; @@ -737,18 +684,15 @@ TEST(FormatConverterTest, ConvertS32LEToS16LE) { out_fmt.frame_rate = 48000; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_EQ(buf_size, out_frames); - in_buff = (int32_t *)ralloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); - out_buff = (int16_t *)ralloc(buf_size * cras_get_format_bytes(&out_fmt)); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + in_buff = (int32_t*)ralloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); + out_buff = (int16_t*)ralloc(buf_size * cras_get_format_bytes(&out_fmt)); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(buf_size, out_frames); for (unsigned int i = 0; i < buf_size; i++) EXPECT_EQ((int16_t)(in_buff[i] >> 16), out_buff[i]); @@ -760,13 +704,13 @@ TEST(FormatConverterTest, ConvertS32LEToS16LE) { // Test 24 to 16 bit conversion. TEST(FormatConverterTest, ConvertS24LEToS16LE) { - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; - int32_t *in_buff; - int16_t *out_buff; + int32_t* in_buff; + int16_t* out_buff; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; @@ -778,18 +722,15 @@ TEST(FormatConverterTest, ConvertS24LEToS16LE) { out_fmt.frame_rate = 48000; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_EQ(buf_size, out_frames); - in_buff = (int32_t *)ralloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); - out_buff = (int16_t *)ralloc(buf_size * cras_get_format_bytes(&out_fmt)); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + in_buff = (int32_t*)ralloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); + out_buff = (int16_t*)ralloc(buf_size * cras_get_format_bytes(&out_fmt)); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(buf_size, out_frames); for (unsigned int i = 0; i < buf_size; i++) EXPECT_EQ((int16_t)(in_buff[i] >> 8), out_buff[i]); @@ -801,13 +742,13 @@ TEST(FormatConverterTest, ConvertS24LEToS16LE) { // Test 8 to 16 bit conversion. TEST(FormatConverterTest, ConvertU8LEToS16LE) { - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; - uint8_t *in_buff; - int16_t *out_buff; + uint8_t* in_buff; + int16_t* out_buff; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; @@ -820,18 +761,15 @@ TEST(FormatConverterTest, ConvertU8LEToS16LE) { out_fmt.frame_rate = 48000; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_EQ(buf_size, out_frames); - in_buff = (uint8_t *)ralloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); - out_buff = (int16_t *)ralloc(buf_size * cras_get_format_bytes(&out_fmt)); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + in_buff = (uint8_t*)ralloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); + out_buff = (int16_t*)ralloc(buf_size * cras_get_format_bytes(&out_fmt)); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(buf_size, out_frames); for (unsigned int i = 0; i < buf_size; i++) EXPECT_EQ((int16_t)((uint16_t)((int16_t)(in_buff[i]) - 128) << 8), @@ -844,13 +782,13 @@ TEST(FormatConverterTest, ConvertU8LEToS16LE) { // Test 16 to 32 bit conversion. TEST(FormatConverterTest, ConvertS16LEToS32LE) { - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; - int16_t *in_buff; - int32_t *out_buff; + int16_t* in_buff; + int32_t* out_buff; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; @@ -862,18 +800,15 @@ TEST(FormatConverterTest, ConvertS16LEToS32LE) { out_fmt.frame_rate = 48000; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_EQ(buf_size, out_frames); - in_buff = (int16_t *)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); - out_buff = (int32_t *)ralloc(buf_size * cras_get_format_bytes(&out_fmt)); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + in_buff = (int16_t*)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); + out_buff = (int32_t*)ralloc(buf_size * cras_get_format_bytes(&out_fmt)); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(buf_size, out_frames); for (unsigned int i = 0; i < buf_size; i++) EXPECT_EQ((int32_t)((uint32_t)(int32_t)in_buff[i] << 16), out_buff[i]); @@ -885,13 +820,13 @@ TEST(FormatConverterTest, ConvertS16LEToS32LE) { // Test 16 to 24 bit conversion. TEST(FormatConverterTest, ConvertS16LEToS24LE) { - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; - int16_t *in_buff; - int32_t *out_buff; + int16_t* in_buff; + int32_t* out_buff; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; @@ -903,18 +838,15 @@ TEST(FormatConverterTest, ConvertS16LEToS24LE) { out_fmt.frame_rate = 48000; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_EQ(buf_size, out_frames); - in_buff = (int16_t *)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); - out_buff = (int32_t *)ralloc(buf_size * 2 * cras_get_format_bytes(&out_fmt)); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + in_buff = (int16_t*)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); + out_buff = (int32_t*)ralloc(buf_size * 2 * cras_get_format_bytes(&out_fmt)); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(buf_size, out_frames); for (unsigned int i = 0; i < buf_size; i++) EXPECT_EQ((int32_t)((uint32_t)(int32_t)in_buff[i] << 8), out_buff[i]); @@ -926,13 +858,13 @@ TEST(FormatConverterTest, ConvertS16LEToS24LE) { // Test 16 to 8 bit conversion. TEST(FormatConverterTest, ConvertS16LEToU8) { - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; - int16_t *in_buff; - uint8_t *out_buff; + int16_t* in_buff; + uint8_t* out_buff; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; @@ -945,18 +877,15 @@ TEST(FormatConverterTest, ConvertS16LEToU8) { out_fmt.frame_rate = 48000; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_EQ(buf_size, out_frames); - in_buff = (int16_t *)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); - out_buff = (uint8_t *)ralloc(buf_size * cras_get_format_bytes(&out_fmt)); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + in_buff = (int16_t*)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); + out_buff = (uint8_t*)ralloc(buf_size * cras_get_format_bytes(&out_fmt)); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(buf_size, out_frames); for (unsigned int i = 0; i < buf_size; i++) EXPECT_EQ((in_buff[i] >> 8) + 128, out_buff[i]); @@ -968,13 +897,13 @@ TEST(FormatConverterTest, ConvertS16LEToU8) { // Test 32 bit 5.1 to 16 bit stereo conversion. TEST(FormatConverterTest, ConvertS32LEToS16LEDownmix51ToStereo) { - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; - int32_t *in_buff; - int16_t *out_buff; + int32_t* in_buff; + int16_t* out_buff; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; int i; @@ -990,18 +919,15 @@ TEST(FormatConverterTest, ConvertS32LEToS16LEDownmix51ToStereo) { in_fmt.channel_layout[i] = surround_channel_center_layout[i]; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_EQ(buf_size, out_frames); - in_buff = (int32_t *)ralloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); - out_buff = (int16_t *)ralloc(buf_size * cras_get_format_bytes(&out_fmt)); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + in_buff = (int32_t*)ralloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); + out_buff = (int16_t*)ralloc(buf_size * cras_get_format_bytes(&out_fmt)); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(buf_size, out_frames); cras_fmt_conv_destroy(&c); @@ -1011,13 +937,13 @@ TEST(FormatConverterTest, ConvertS32LEToS16LEDownmix51ToStereo) { // Test 16 bit stereo to 5.1 conversion. TEST(FormatConverterTest, ConvertS16LEToS16LEStereoTo51) { - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; - int16_t *in_buff; - int16_t *out_buff; + int16_t* in_buff; + int16_t* out_buff; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; int i; @@ -1033,18 +959,15 @@ TEST(FormatConverterTest, ConvertS16LEToS16LEStereoTo51) { out_fmt.channel_layout[i] = surround_channel_center_layout[i]; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_EQ(buf_size, out_frames); - in_buff = (int16_t *)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); - out_buff = (int16_t *)ralloc(buf_size * cras_get_format_bytes(&out_fmt)); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + in_buff = (int16_t*)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); + out_buff = (int16_t*)ralloc(buf_size * cras_get_format_bytes(&out_fmt)); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(buf_size, out_frames); for (unsigned int i = 0; i < buf_size; i++) { /* Check mono be converted to CRAS_CH_FL and CRAS_CH_FR */ @@ -1063,13 +986,13 @@ TEST(FormatConverterTest, ConvertS16LEToS16LEStereoTo51) { // Test 16 bit mono to 5.1 conversion. Center. TEST(FormatConverterTest, ConvertS16LEToS16LEMonoTo51Center) { - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; - int16_t *in_buff; - int16_t *out_buff; + int16_t* in_buff; + int16_t* out_buff; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; int i; @@ -1085,18 +1008,15 @@ TEST(FormatConverterTest, ConvertS16LEToS16LEMonoTo51Center) { out_fmt.channel_layout[i] = surround_channel_center_layout[i]; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_EQ(buf_size, out_frames); - in_buff = (int16_t *)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); - out_buff = (int16_t *)ralloc(buf_size * cras_get_format_bytes(&out_fmt)); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + in_buff = (int16_t*)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); + out_buff = (int16_t*)ralloc(buf_size * cras_get_format_bytes(&out_fmt)); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(buf_size, out_frames); for (unsigned int i = 0; i < buf_size; i++) { /* Check mono be converted to CRAS_CH_FC */ @@ -1115,13 +1035,13 @@ TEST(FormatConverterTest, ConvertS16LEToS16LEMonoTo51Center) { // Test 16 bit mono to 5.1 conversion. Left Right. TEST(FormatConverterTest, ConvertS16LEToS16LEMonoTo51LeftRight) { - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; - int16_t *in_buff; - int16_t *out_buff; + int16_t* in_buff; + int16_t* out_buff; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; unsigned int i, left, right; @@ -1139,18 +1059,15 @@ TEST(FormatConverterTest, ConvertS16LEToS16LEMonoTo51LeftRight) { right = surround_channel_left_right_layout[CRAS_CH_FR]; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_EQ(buf_size, out_frames); - in_buff = (int16_t *)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); - out_buff = (int16_t *)ralloc(buf_size * cras_get_format_bytes(&out_fmt)); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + in_buff = (int16_t*)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); + out_buff = (int16_t*)ralloc(buf_size * cras_get_format_bytes(&out_fmt)); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(buf_size, out_frames); for (unsigned int i = 0; i < buf_size; i++) { /* Check mono be converted to CRAS_CH_FL and CRAS_CH_FR */ @@ -1171,13 +1088,13 @@ TEST(FormatConverterTest, ConvertS16LEToS16LEMonoTo51LeftRight) { // Test 16 bit mono to 5.1 conversion. Unknown. TEST(FormatConverterTest, ConvertS16LEToS16LEMonoTo51Unknown) { - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; - int16_t *in_buff; - int16_t *out_buff; + int16_t* in_buff; + int16_t* out_buff; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; int i; @@ -1193,18 +1110,15 @@ TEST(FormatConverterTest, ConvertS16LEToS16LEMonoTo51Unknown) { out_fmt.channel_layout[i] = surround_channel_unknown_layout[i]; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_EQ(buf_size, out_frames); - in_buff = (int16_t *)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); - out_buff = (int16_t *)ralloc(buf_size * cras_get_format_bytes(&out_fmt)); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + in_buff = (int16_t*)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); + out_buff = (int16_t*)ralloc(buf_size * cras_get_format_bytes(&out_fmt)); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(buf_size, out_frames); for (unsigned int i = 0; i < buf_size; i++) { /* Check mono be converted to CRAS_CH_FL */ @@ -1223,13 +1137,13 @@ TEST(FormatConverterTest, ConvertS16LEToS16LEMonoTo51Unknown) { // Test 16 bit stereo to quad conversion. TEST(FormatConverterTest, ConvertS16LEToS16LEStereoToQuad) { - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; - int16_t *in_buff; - int16_t *out_buff; + int16_t* in_buff; + int16_t* out_buff; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; @@ -1244,23 +1158,20 @@ TEST(FormatConverterTest, ConvertS16LEToS16LEStereoToQuad) { out_fmt.channel_layout[i] = quad_channel_layout[i]; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_EQ(buf_size, out_frames); - in_buff = (int16_t *)malloc(buf_size * cras_get_format_bytes(&in_fmt)); + in_buff = (int16_t*)malloc(buf_size * cras_get_format_bytes(&in_fmt)); for (unsigned int i = 0; i < in_buf_size; i++) { in_buff[i * 2] = 40; in_buff[i * 2 + 1] = 80; } - out_buff = (int16_t *)malloc(buf_size * cras_get_format_bytes(&out_fmt)); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + out_buff = (int16_t*)malloc(buf_size * cras_get_format_bytes(&out_fmt)); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(buf_size, out_frames); for (unsigned int i = 0; i < buf_size; i++) { EXPECT_EQ(40, out_buff[4 * i]); @@ -1274,11 +1185,8 @@ TEST(FormatConverterTest, ConvertS16LEToS16LEStereoToQuad) { swap_channel_layout(out_fmt.channel_layout, CRAS_CH_FL, CRAS_CH_RR); swap_channel_layout(out_fmt.channel_layout, CRAS_CH_RL, CRAS_CH_FR); c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(buf_size, out_frames); for (unsigned int i = 0; i < buf_size; i++) { EXPECT_EQ(80, out_buff[4 * i]); @@ -1294,13 +1202,13 @@ TEST(FormatConverterTest, ConvertS16LEToS16LEStereoToQuad) { // Test 32 bit 5.1 to 16 bit stereo conversion with SRC 1 to 2. TEST(FormatConverterTest, ConvertS32LEToS16LEDownmix51ToStereo48To96) { - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; - int32_t *in_buff; - int16_t *out_buff; + int32_t* in_buff; + int16_t* out_buff; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; int i; @@ -1316,18 +1224,15 @@ TEST(FormatConverterTest, ConvertS32LEToS16LEDownmix51ToStereo48To96) { in_fmt.channel_layout[i] = surround_channel_center_layout[i]; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_EQ(buf_size * 2, out_frames); - in_buff = (int32_t *)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); - out_buff = (int16_t *)ralloc(buf_size * 2 * cras_get_format_bytes(&out_fmt)); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size * 2); + in_buff = (int32_t*)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); + out_buff = (int16_t*)ralloc(buf_size * 2 * cras_get_format_bytes(&out_fmt)); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size * 2); EXPECT_EQ(buf_size * 2, out_frames); cras_fmt_conv_destroy(&c); @@ -1337,13 +1242,13 @@ TEST(FormatConverterTest, ConvertS32LEToS16LEDownmix51ToStereo48To96) { // Test 32 bit 5.1 to 16 bit stereo conversion with SRC 2 to 1. TEST(FormatConverterTest, ConvertS32LEToS16LEDownmix51ToStereo96To48) { - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; - int32_t *in_buff; - int16_t *out_buff; + int32_t* in_buff; + int16_t* out_buff; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; int i; @@ -1359,18 +1264,15 @@ TEST(FormatConverterTest, ConvertS32LEToS16LEDownmix51ToStereo96To48) { in_fmt.channel_layout[i] = surround_channel_center_layout[i]; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_EQ(buf_size / 2, out_frames); - in_buff = (int32_t *)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); - out_buff = (int16_t *)ralloc(buf_size / 2 * cras_get_format_bytes(&out_fmt)); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size / 2); + in_buff = (int32_t*)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); + out_buff = (int16_t*)ralloc(buf_size / 2 * cras_get_format_bytes(&out_fmt)); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size / 2); EXPECT_EQ(buf_size / 2, out_frames); cras_fmt_conv_destroy(&c); @@ -1380,14 +1282,14 @@ TEST(FormatConverterTest, ConvertS32LEToS16LEDownmix51ToStereo96To48) { // Test 32 bit 5.1 to 16 bit stereo conversion with SRC 48 to 44.1. TEST(FormatConverterTest, ConvertS32LEToS16LEDownmix51ToStereo48To441) { - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; size_t ret_frames; - int32_t *in_buff; - int16_t *out_buff; + int32_t* in_buff; + int16_t* out_buff; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; int i; @@ -1403,18 +1305,15 @@ TEST(FormatConverterTest, ConvertS32LEToS16LEDownmix51ToStereo48To441) { in_fmt.channel_layout[i] = surround_channel_center_layout[i]; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_LT(out_frames, buf_size); - in_buff = (int32_t *)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); - out_buff = (int16_t *)ralloc(out_frames * cras_get_format_bytes(&out_fmt)); - ret_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - out_frames); + in_buff = (int32_t*)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); + out_buff = (int16_t*)ralloc(out_frames * cras_get_format_bytes(&out_fmt)); + ret_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, out_frames); EXPECT_EQ(out_frames, ret_frames); cras_fmt_conv_destroy(&c); @@ -1424,14 +1323,14 @@ TEST(FormatConverterTest, ConvertS32LEToS16LEDownmix51ToStereo48To441) { // Test 32 bit 5.1 to 16 bit stereo conversion with SRC 441 to 48. TEST(FormatConverterTest, ConvertS32LEToS16LEDownmix51ToStereo441To48) { - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; size_t ret_frames; - int32_t *in_buff; - int16_t *out_buff; + int32_t* in_buff; + int16_t* out_buff; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; int i; @@ -1447,19 +1346,16 @@ TEST(FormatConverterTest, ConvertS32LEToS16LEDownmix51ToStereo441To48) { in_fmt.channel_layout[i] = surround_channel_center_layout[i]; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_GT(out_frames, buf_size); - in_buff = (int32_t *)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); - out_buff = (int16_t *)ralloc((out_frames - 1) * - cras_get_format_bytes(&out_fmt)); - ret_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - out_frames - 1); + in_buff = (int32_t*)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); + out_buff = + (int16_t*)ralloc((out_frames - 1) * cras_get_format_bytes(&out_fmt)); + ret_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, out_frames - 1); EXPECT_EQ(out_frames - 1, ret_frames); cras_fmt_conv_destroy(&c); @@ -1469,14 +1365,14 @@ TEST(FormatConverterTest, ConvertS32LEToS16LEDownmix51ToStereo441To48) { // Test Invalid buffer length just truncates. TEST(FormatConverterTest, ConvertS32LEToS16LEDownmix51ToStereo96To48Short) { - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; size_t ret_frames; - int32_t *in_buff; - int16_t *out_buff; + int32_t* in_buff; + int16_t* out_buff; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; int i; @@ -1492,19 +1388,16 @@ TEST(FormatConverterTest, ConvertS32LEToS16LEDownmix51ToStereo96To48Short) { in_fmt.channel_layout[i] = surround_channel_center_layout[i]; c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_EQ(buf_size / 2, out_frames); - in_buff = (int32_t *)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); - out_buff = (int16_t *)ralloc((out_frames - 2) * - cras_get_format_bytes(&out_fmt)); - ret_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - out_frames - 2); + in_buff = (int32_t*)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); + out_buff = + (int16_t*)ralloc((out_frames - 2) * cras_get_format_bytes(&out_fmt)); + ret_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, out_frames - 2); EXPECT_EQ(out_frames - 2, ret_frames); cras_fmt_conv_destroy(&c); @@ -1514,13 +1407,13 @@ TEST(FormatConverterTest, ConvertS32LEToS16LEDownmix51ToStereo96To48Short) { // Test format convert pre linear resample and then follows SRC from 96 to 48. TEST(FormatConverterTest, Convert96to48PreLinearResample) { - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; - int32_t *in_buff; - int16_t *out_buff; + int32_t* in_buff; + int16_t* out_buff; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; unsigned int expected_fr; @@ -1539,7 +1432,7 @@ TEST(FormatConverterTest, Convert96to48PreLinearResample) { } c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size * 2, 1); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); EXPECT_EQ(out_fmt.frame_rate, linear_resampler_src_rate); EXPECT_EQ(out_fmt.frame_rate, linear_resampler_dst_rate); @@ -1549,13 +1442,10 @@ TEST(FormatConverterTest, Convert96to48PreLinearResample) { out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_EQ(expected_fr, out_frames); - in_buff = (int32_t *)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); - out_buff = (int16_t *)ralloc(buf_size * cras_get_format_bytes(&out_fmt)); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - out_frames); + in_buff = (int32_t*)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); + out_buff = (int16_t*)ralloc(buf_size * cras_get_format_bytes(&out_fmt)); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, out_frames); EXPECT_EQ(expected_fr, out_frames); cras_fmt_conv_destroy(&c); @@ -1565,13 +1455,13 @@ TEST(FormatConverterTest, Convert96to48PreLinearResample) { // Test format convert SRC from 96 to 48 and then post linear resample. TEST(FormatConverterTest, Convert96to48PostLinearResample) { - struct cras_fmt_conv *c; + struct cras_fmt_conv* c; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; size_t out_frames; - int32_t *in_buff; - int16_t *out_buff; + int32_t* in_buff; + int16_t* out_buff; const size_t buf_size = 4096; unsigned int in_buf_size = 4096; unsigned int expected_fr; @@ -1590,7 +1480,7 @@ TEST(FormatConverterTest, Convert96to48PostLinearResample) { } c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size * 2, 0); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); EXPECT_EQ(out_fmt.frame_rate, linear_resampler_src_rate); EXPECT_EQ(out_fmt.frame_rate, linear_resampler_dst_rate); @@ -1600,13 +1490,10 @@ TEST(FormatConverterTest, Convert96to48PostLinearResample) { out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); EXPECT_EQ(expected_fr, out_frames); - in_buff = (int32_t *)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); - out_buff = (int16_t *)ralloc(buf_size * cras_get_format_bytes(&out_fmt)); - out_frames = cras_fmt_conv_convert_frames(c, - (uint8_t *)in_buff, - (uint8_t *)out_buff, - &in_buf_size, - buf_size); + in_buff = (int32_t*)ralloc(buf_size * cras_get_format_bytes(&in_fmt)); + out_buff = (int16_t*)ralloc(buf_size * cras_get_format_bytes(&out_fmt)); + out_frames = cras_fmt_conv_convert_frames( + c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); EXPECT_EQ(expected_fr, out_frames); cras_fmt_conv_destroy(&c); @@ -1617,7 +1504,7 @@ TEST(FormatConverterTest, Convert96to48PostLinearResample) { // Test format converter created in config_format_converter TEST(FormatConverterTest, ConfigConverter) { int i; - struct cras_fmt_conv *c = NULL; + struct cras_fmt_conv* c = NULL; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; @@ -1634,7 +1521,7 @@ TEST(FormatConverterTest, ConfigConverter) { } config_format_converter(&c, CRAS_STREAM_OUTPUT, &in_fmt, &out_fmt, 4096); - ASSERT_NE(c, (void *)NULL); + ASSERT_NE(c, (void*)NULL); cras_fmt_conv_destroy(&c); } @@ -1643,7 +1530,7 @@ TEST(FormatConverterTest, ConfigConverter) { // needed. TEST(FormatConverterTest, ConfigConverterNoNeed) { int i; - struct cras_fmt_conv *c = NULL; + struct cras_fmt_conv* c = NULL; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; @@ -1660,7 +1547,7 @@ TEST(FormatConverterTest, ConfigConverterNoNeed) { } config_format_converter(&c, CRAS_STREAM_OUTPUT, &in_fmt, &out_fmt, 4096); - EXPECT_NE(c, (void *)NULL); + EXPECT_NE(c, (void*)NULL); EXPECT_EQ(0, cras_fmt_conversion_needed(c)); cras_fmt_conv_destroy(&c); } @@ -1668,10 +1555,10 @@ TEST(FormatConverterTest, ConfigConverterNoNeed) { // Test format converter not created for input when in/out format differs // at channel count or layout. TEST(FormatConverterTest, ConfigConverterNoNeedForInput) { - static int kmic_channel_layout[CRAS_CH_MAX] = - {0, 1, -1, -1, 2, -1, -1, -1, -1, -1, -1}; + static int kmic_channel_layout[CRAS_CH_MAX] = {0, 1, -1, -1, 2, -1, + -1, -1, -1, -1, -1}; int i; - struct cras_fmt_conv *c = NULL; + struct cras_fmt_conv* c = NULL; struct cras_audio_format in_fmt; struct cras_audio_format out_fmt; @@ -1688,14 +1575,14 @@ TEST(FormatConverterTest, ConfigConverterNoNeedForInput) { } config_format_converter(&c, CRAS_STREAM_INPUT, &in_fmt, &out_fmt, 4096); - EXPECT_NE(c, (void *)NULL); + EXPECT_NE(c, (void*)NULL); EXPECT_EQ(0, cras_fmt_conversion_needed(c)); cras_fmt_conv_destroy(&c); } TEST(ChannelRemixTest, ChannelRemixAppliedOrNot) { float coeff[4] = {0.5, 0.5, 0.26, 0.73}; - struct cras_fmt_conv *conv; + struct cras_fmt_conv* conv; struct cras_audio_format fmt; int16_t *buf, *res; unsigned i; @@ -1703,16 +1590,16 @@ TEST(ChannelRemixTest, ChannelRemixAppliedOrNot) { fmt.num_channels = 2; conv = cras_channel_remix_conv_create(2, coeff); - buf = (int16_t *)ralloc(50 * 4); - res = (int16_t *)malloc(50 * 4); + buf = (int16_t*)ralloc(50 * 4); + res = (int16_t*)malloc(50 * 4); memcpy(res, buf, 50 * 4); /* Remix conversion will not apply for non S16_LE format. */ fmt.format = SND_PCM_FORMAT_S24_LE; - cras_channel_remix_convert(conv, &fmt, (uint8_t *)buf, 50); + cras_channel_remix_convert(conv, &fmt, (uint8_t*)buf, 50); for (i = 0; i < 100; i++) - EXPECT_EQ(res[i], buf[i]); + EXPECT_EQ(res[i], buf[i]); for (i = 0; i < 100; i += 2) { res[i] = coeff[0] * buf[i]; @@ -1722,93 +1609,84 @@ TEST(ChannelRemixTest, ChannelRemixAppliedOrNot) { } fmt.format = SND_PCM_FORMAT_S16_LE; - cras_channel_remix_convert(conv, &fmt, (uint8_t *)buf, 50); + cras_channel_remix_convert(conv, &fmt, (uint8_t*)buf, 50); for (i = 0; i < 100; i++) - EXPECT_EQ(res[i], buf[i]); + EXPECT_EQ(res[i], buf[i]); /* If num_channels not match, remix conversion will not apply. */ fmt.num_channels = 6; - cras_channel_remix_convert(conv, &fmt, (uint8_t *)buf, 50); + cras_channel_remix_convert(conv, &fmt, (uint8_t*)buf, 50); for (i = 0; i < 100; i++) - EXPECT_EQ(res[i], buf[i]); + EXPECT_EQ(res[i], buf[i]); cras_fmt_conv_destroy(&conv); free(buf); free(res); } -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } extern "C" { -float** cras_channel_conv_matrix_alloc(size_t in_ch, size_t out_ch) -{ +float** cras_channel_conv_matrix_alloc(size_t in_ch, size_t out_ch) { int i; float** conv_mtx; - conv_mtx = (float **)calloc(CRAS_CH_MAX, sizeof(*conv_mtx)); + conv_mtx = (float**)calloc(CRAS_CH_MAX, sizeof(*conv_mtx)); for (i = 0; i < CRAS_CH_MAX; i++) - conv_mtx[i] = (float *)calloc(CRAS_CH_MAX, sizeof(*conv_mtx[i])); + conv_mtx[i] = (float*)calloc(CRAS_CH_MAX, sizeof(*conv_mtx[i])); return conv_mtx; } -void cras_channel_conv_matrix_destroy(float **mtx, size_t out_ch) -{ +void cras_channel_conv_matrix_destroy(float** mtx, size_t out_ch) { int i; for (i = 0; i < CRAS_CH_MAX; i++) free(mtx[i]); free(mtx); } -float **cras_channel_conv_matrix_create(const struct cras_audio_format *in, - const struct cras_audio_format *out) -{ - return cras_channel_conv_matrix_alloc(in->num_channels, - out->num_channels); +float** cras_channel_conv_matrix_create(const struct cras_audio_format* in, + const struct cras_audio_format* out) { + return cras_channel_conv_matrix_alloc(in->num_channels, out->num_channels); } -struct linear_resampler *linear_resampler_create(unsigned int num_channels, - unsigned int format_bytes, - float src_rate, - float dst_rate) -{ +struct linear_resampler* linear_resampler_create(unsigned int num_channels, + unsigned int format_bytes, + float src_rate, + float dst_rate) { linear_resampler_format_bytes = format_bytes; linear_resampler_num_channels = num_channels; linear_resampler_src_rate = src_rate; linear_resampler_dst_rate = dst_rate; - return reinterpret_cast<struct linear_resampler*>(0x33);; + return reinterpret_cast<struct linear_resampler*>(0x33); + ; } -int linear_resampler_needed(struct linear_resampler *lr) -{ +int linear_resampler_needed(struct linear_resampler* lr) { return linear_resampler_needed_val; } -void linear_resampler_set_rates(struct linear_resampler *lr, +void linear_resampler_set_rates(struct linear_resampler* lr, unsigned int from, - unsigned int to) -{ + unsigned int to) { linear_resampler_src_rate = from; linear_resampler_dst_rate = to; } -unsigned int linear_resampler_out_frames_to_in(struct linear_resampler *lr, - unsigned int frames) -{ +unsigned int linear_resampler_out_frames_to_in(struct linear_resampler* lr, + unsigned int frames) { return (double)frames / linear_resampler_ratio; } /* Converts the frames count from input rate to output rate. */ -unsigned int linear_resampler_in_frames_to_out(struct linear_resampler *lr, - unsigned int frames) -{ +unsigned int linear_resampler_in_frames_to_out(struct linear_resampler* lr, + unsigned int frames) { return (double)frames * linear_resampler_ratio; } -unsigned int linear_resampler_resample(struct linear_resampler *lr, - uint8_t *src, - unsigned int *src_frames, - uint8_t *dst, - unsigned dst_frames) -{ +unsigned int linear_resampler_resample(struct linear_resampler* lr, + uint8_t* src, + unsigned int* src_frames, + uint8_t* dst, + unsigned dst_frames) { unsigned int resampled_fr = *src_frames * linear_resampler_ratio; if (resampled_fr > dst_frames) { @@ -1817,13 +1695,11 @@ unsigned int linear_resampler_resample(struct linear_resampler *lr, } unsigned int resampled_bytes = resampled_fr * linear_resampler_format_bytes * linear_resampler_num_channels; - for(size_t i = 0; i < resampled_bytes; i++) + for (size_t i = 0; i < resampled_bytes; i++) dst[i] = (uint8_t)rand() & 0xff; return resampled_fr; } -void linear_resampler_destroy(struct linear_resampler *lr) -{ -} -} // extern "C" +void linear_resampler_destroy(struct linear_resampler* lr) {} +} // extern "C" diff --git a/cras/src/tests/hfp_ag_profile_unittest.cc b/cras/src/tests/hfp_ag_profile_unittest.cc index 36727d7a..56c99088 100644 --- a/cras/src/tests/hfp_ag_profile_unittest.cc +++ b/cras/src/tests/hfp_ag_profile_unittest.cc @@ -6,49 +6,52 @@ #include <gtest/gtest.h> extern "C" { -#include "cras_iodev.h" -#include "cras_hfp_ag_profile.h" #include "cras_bt_log.h" #include "cras_bt_profile.h" +#include "cras_hfp_ag_profile.h" +#include "cras_iodev.h" } static int with_sco_pcm; static struct cras_iodev fake_sco_out, fake_sco_in; -static struct cras_bt_device *fake_device; -static struct cras_bt_profile *internal_bt_profile; +static struct cras_bt_device* fake_device; +static struct cras_bt_profile* internal_bt_profile; static size_t hfp_alsa_iodev_create_called; static size_t hfp_alsa_iodev_destroy_called; static size_t hfp_iodev_create_called; static size_t hfp_iodev_destroy_called; +static size_t cras_bt_device_notify_profile_dropped_called; +static struct cras_bt_device* cras_bt_device_notify_profile_dropped_dev; +static enum cras_bt_device_profile + cras_bt_device_notify_profile_dropped_profile; static void ResetStubData() { hfp_alsa_iodev_create_called = 0; hfp_alsa_iodev_destroy_called = 0; hfp_iodev_create_called = 0; hfp_iodev_destroy_called = 0; + cras_bt_device_notify_profile_dropped_called = 0; } namespace { -class HfpAgProfile: public testing::Test { - protected: - virtual void SetUp() { - btlog = cras_bt_event_log_init(); - ResetStubData(); - } +class HfpAgProfile : public testing::Test { + protected: + virtual void SetUp() { + btlog = cras_bt_event_log_init(); + ResetStubData(); + } - virtual void TearDown() { - cras_bt_event_log_deinit(btlog); - } + virtual void TearDown() { cras_bt_event_log_deinit(btlog); } }; TEST_F(HfpAgProfile, StartWithoutScoPCM) { int ret; - struct cras_bt_profile *bt_profile; + struct cras_bt_profile* bt_profile; with_sco_pcm = 0; - fake_device = (struct cras_bt_device *)0xdeadbeef; + fake_device = (struct cras_bt_device*)0xdeadbeef; /* to get the cras_hfp_ag_profile */ cras_hfp_ag_profile_create(NULL); bt_profile = internal_bt_profile; @@ -64,17 +67,17 @@ TEST_F(HfpAgProfile, StartWithoutScoPCM) { EXPECT_EQ(0, ret); EXPECT_EQ(2, hfp_iodev_create_called); - cras_hfp_ag_suspend(); + bt_profile->release(bt_profile); EXPECT_EQ(2, hfp_iodev_destroy_called); } TEST_F(HfpAgProfile, StartWithScoPCM) { int ret; - struct cras_bt_profile *bt_profile; + struct cras_bt_profile* bt_profile; with_sco_pcm = 1; - fake_device = (struct cras_bt_device *)0xdeadbeef; + fake_device = (struct cras_bt_device*)0xdeadbeef; /* to get the cras_hfp_ag_profile */ cras_hfp_ag_profile_create(NULL); bt_profile = internal_bt_profile; @@ -85,18 +88,44 @@ TEST_F(HfpAgProfile, StartWithScoPCM) { EXPECT_EQ(0, ret); EXPECT_EQ(2, hfp_alsa_iodev_create_called); - cras_hfp_ag_suspend(); + bt_profile->release(bt_profile); EXPECT_EQ(2, hfp_alsa_iodev_destroy_called); } -} // namespace +TEST_F(HfpAgProfile, RemoveConflictAG) { + struct cras_bt_profile* bt_profile; + struct cras_bt_device* new_dev = + reinterpret_cast<struct cras_bt_device*>(0x123); + ; + + with_sco_pcm = 0; + fake_device = (struct cras_bt_device*)0xdeadbeef; + /* to get the cras_hfp_ag_profile */ + cras_hfp_ag_profile_create(NULL); + bt_profile = internal_bt_profile; + bt_profile->new_connection(NULL, bt_profile, fake_device, 0); + + bt_profile->new_connection(NULL, bt_profile, new_dev, 0); + + /* Expect removing conflict of new_dev triggers profile drop on + * fake_device. */ + cras_hfp_ag_remove_conflict(new_dev); + EXPECT_EQ(1, cras_bt_device_notify_profile_dropped_called); + EXPECT_EQ(fake_device, cras_bt_device_notify_profile_dropped_dev); + EXPECT_EQ(CRAS_BT_DEVICE_PROFILE_HFP_HANDSFREE, + cras_bt_device_notify_profile_dropped_profile); + + bt_profile->release(bt_profile); +} + +} // namespace extern "C" { -struct cras_bt_event_log *btlog; +struct cras_bt_event_log* btlog; -struct cras_iodev *cras_iodev_list_get_sco_pcm_iodev( +struct cras_iodev* cras_iodev_list_get_sco_pcm_iodev( enum CRAS_STREAM_DIRECTION direction) { if (with_sco_pcm) { if (direction == CRAS_STREAM_OUTPUT) @@ -108,125 +137,128 @@ struct cras_iodev *cras_iodev_list_get_sco_pcm_iodev( return NULL; } -struct cras_iodev *hfp_alsa_iodev_create( - enum CRAS_STREAM_DIRECTION dir, - struct cras_bt_device *device, - struct hfp_slc_handle *slc, - enum cras_bt_device_profile profile) { +struct cras_iodev* hfp_alsa_iodev_create(enum CRAS_STREAM_DIRECTION dir, + struct cras_bt_device* device, + struct hfp_slc_handle* slc, + enum cras_bt_device_profile profile) { hfp_alsa_iodev_create_called++; - return (struct cras_iodev *)0xdeadbeef; + return (struct cras_iodev*)0xdeadbeef; } -void hfp_alsa_iodev_destroy(struct cras_iodev *iodev) { +void hfp_alsa_iodev_destroy(struct cras_iodev* iodev) { hfp_alsa_iodev_destroy_called++; } -struct cras_iodev *hfp_iodev_create( - enum CRAS_STREAM_DIRECTION dir, - struct cras_bt_device *device, - struct hfp_slc_handle *slc, - enum cras_bt_device_profile profile, - struct hfp_info *info) { +struct cras_iodev* hfp_iodev_create(enum CRAS_STREAM_DIRECTION dir, + struct cras_bt_device* device, + struct hfp_slc_handle* slc, + enum cras_bt_device_profile profile, + struct hfp_info* info) { hfp_iodev_create_called++; - return (struct cras_iodev *)0xdeadbeef; + return (struct cras_iodev*)0xdeadbeef; } -void hfp_iodev_destroy(struct cras_iodev *iodev) { +void hfp_iodev_destroy(struct cras_iodev* iodev) { hfp_iodev_destroy_called++; } -int cras_bt_add_profile(DBusConnection *conn, struct cras_bt_profile *profile) { +int cras_bt_add_profile(DBusConnection* conn, struct cras_bt_profile* profile) { internal_bt_profile = profile; return 0; } -struct hfp_info *hfp_info_create() { +struct hfp_info* hfp_info_create() { return NULL; } -int hfp_info_running(struct hfp_info *info) { +int hfp_info_running(struct hfp_info* info) { return 0; } -int hfp_info_stop(struct hfp_info *info) { +int hfp_info_stop(struct hfp_info* info) { return 0; } -void hfp_info_destroy(struct hfp_info *info) { -} +void hfp_info_destroy(struct hfp_info* info) {} -void hfp_slc_destroy(struct hfp_slc_handle *slc_handle) { -} +void hfp_slc_destroy(struct hfp_slc_handle* slc_handle) {} -int cras_bt_device_has_a2dp(struct cras_bt_device *device) { +int cras_bt_device_has_a2dp(struct cras_bt_device* device) { return 0; } -int cras_bt_device_disconnect(DBusConnection *conn, - struct cras_bt_device *device) { +int cras_bt_device_disconnect(DBusConnection* conn, + struct cras_bt_device* device) { return 0; } -const char *cras_bt_device_name(const struct cras_bt_device *device) { +const char* cras_bt_device_name(const struct cras_bt_device* device) { return NULL; } -void cras_bt_device_set_append_iodev_cb(struct cras_bt_device *device, - void (*cb)(void *data)) { -} +void cras_bt_device_set_append_iodev_cb(struct cras_bt_device* device, + void (*cb)(void* data)) {} -enum cras_bt_device_profile cras_bt_device_profile_from_uuid(const char *uuid) { +enum cras_bt_device_profile cras_bt_device_profile_from_uuid(const char* uuid) { return CRAS_BT_DEVICE_PROFILE_HSP_AUDIOGATEWAY; } -struct hfp_slc_handle *hfp_slc_create( - int fd, int is_hsp, - int ag_supported_features, - struct cras_bt_device *device, - hfp_slc_init_cb init_cb, - hfp_slc_disconnect_cb disconnect_cb) { +struct cras_bt_adapter* cras_bt_device_adapter( + const struct cras_bt_device* device) { + return reinterpret_cast<struct cras_bt_adapter*>(0x123); +} + +int cras_bt_adapter_wbs_supported(struct cras_bt_adapter* adapter) { + return 1; +} + +struct hfp_slc_handle* hfp_slc_create(int fd, + int is_hsp, + int ag_supported_features, + struct cras_bt_device* device, + hfp_slc_init_cb init_cb, + hfp_slc_disconnect_cb disconnect_cb) { return NULL; } -int hfp_slc_get_selected_codec(struct hfp_slc_handle *handle) -{ +int hfp_slc_get_selected_codec(struct hfp_slc_handle* handle) { return HFP_CODEC_ID_CVSD; } -int hfp_slc_get_hf_codec_negotiation_supported(struct hfp_slc_handle *handle) -{ +int hfp_slc_get_hf_codec_negotiation_supported(struct hfp_slc_handle* handle) { return 1; } -int cras_server_metrics_hfp_wideband_support(bool supported) -{ - return 0; -} - -struct cras_bt_device *cras_a2dp_connected_device() { +struct cras_bt_device* cras_a2dp_connected_device() { return NULL; } -int cras_bt_device_supports_profile(const struct cras_bt_device *device, - enum cras_bt_device_profile profile) { +int cras_bt_device_supports_profile(const struct cras_bt_device* device, + enum cras_bt_device_profile profile) { return 0; } -void cras_a2dp_suspend_connected_device(struct cras_bt_device *device) { -} +void cras_a2dp_suspend_connected_device(struct cras_bt_device* device) {} -int cras_bt_device_audio_gateway_initialized(struct cras_bt_device *device) { +int cras_bt_device_audio_gateway_initialized(struct cras_bt_device* device) { return 0; } -bool cras_system_get_bt_wbs_enabled() -{ +void cras_bt_device_notify_profile_dropped( + struct cras_bt_device* device, + enum cras_bt_device_profile profile) { + cras_bt_device_notify_profile_dropped_called++; + cras_bt_device_notify_profile_dropped_dev = device; + cras_bt_device_notify_profile_dropped_profile = profile; +} + +bool cras_system_get_bt_wbs_enabled() { return true; } -} // extern "C" +} // extern "C" -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/hfp_alsa_iodev_unittest.cc b/cras/src/tests/hfp_alsa_iodev_unittest.cc index 77e113f8..a4d5ba94 100644 --- a/cras/src/tests/hfp_alsa_iodev_unittest.cc +++ b/cras/src/tests/hfp_alsa_iodev_unittest.cc @@ -6,22 +6,22 @@ #include <gtest/gtest.h> extern "C" { +#include "cras_audio_format.h" #include "cras_hfp_alsa_iodev.h" #include "cras_hfp_slc.h" #include "cras_iodev.h" -#include "cras_audio_format.h" } struct hfp_alsa_io { struct cras_iodev base; - struct cras_bt_device *device; - struct hfp_slc_handle *slc; - struct cras_iodev *aio; + struct cras_bt_device* device; + struct hfp_slc_handle* slc; + struct cras_iodev* aio; }; static struct cras_iodev fake_sco_out, fake_sco_in; -static struct cras_bt_device *fake_device; -static struct hfp_slc_handle *fake_slc; +static struct cras_bt_device* fake_device; +static struct hfp_slc_handle* fake_slc; static size_t cras_bt_device_append_iodev_called; static size_t cras_bt_device_rm_iodev_called; @@ -34,23 +34,23 @@ static size_t cras_iodev_set_format_called; static size_t hfp_set_call_status_called; static size_t hfp_event_speaker_gain_called; -#define _FAKE_CALL1(name) \ +#define _FAKE_CALL1(name) \ static size_t fake_##name##_called; \ - static int fake_##name(void *a) { \ - fake_##name##_called++; \ - return 0; \ + static int fake_##name(void* a) { \ + fake_##name##_called++; \ + return 0; \ } -#define _FAKE_CALL2(name) \ - static size_t fake_##name##_called; \ - static int fake_##name(void *a, void *b) { \ - fake_##name##_called++; \ - return 0; \ +#define _FAKE_CALL2(name) \ + static size_t fake_##name##_called; \ + static int fake_##name(void* a, void* b) { \ + fake_##name##_called++; \ + return 0; \ } -#define _FAKE_CALL3(name) \ - static size_t fake_##name##_called; \ - static int fake_##name(void *a, void *b, void *c) { \ - fake_##name##_called++; \ - return 0; \ +#define _FAKE_CALL3(name) \ + static size_t fake_##name##_called; \ + static int fake_##name(void* a, void* b, void* c) { \ + fake_##name##_called++; \ + return 0; \ } _FAKE_CALL1(open_dev); @@ -80,79 +80,75 @@ static void ResetStubData() { hfp_event_speaker_gain_called = 0; fake_sco_out.open_dev = fake_sco_in.open_dev = - (int (*)(struct cras_iodev *))fake_open_dev; + (int (*)(struct cras_iodev*))fake_open_dev; fake_open_dev_called = 0; fake_sco_out.update_supported_formats = fake_sco_in.update_supported_formats = - (int (*)(struct cras_iodev *))fake_update_supported_formats; + (int (*)(struct cras_iodev*))fake_update_supported_formats; fake_update_supported_formats_called = 0; fake_sco_out.configure_dev = fake_sco_in.configure_dev = - (int (*)(struct cras_iodev *))fake_configure_dev; + (int (*)(struct cras_iodev*))fake_configure_dev; fake_configure_dev_called = 0; fake_sco_out.close_dev = fake_sco_in.close_dev = - (int (*)(struct cras_iodev *))fake_close_dev; + (int (*)(struct cras_iodev*))fake_close_dev; fake_close_dev_called = 0; fake_sco_out.frames_queued = fake_sco_in.frames_queued = - (int (*)(const struct cras_iodev *, struct timespec *))fake_frames_queued; + (int (*)(const struct cras_iodev*, struct timespec*))fake_frames_queued; fake_frames_queued_called = 0; fake_sco_out.delay_frames = fake_sco_in.delay_frames = - (int (*)(const struct cras_iodev *))fake_delay_frames; + (int (*)(const struct cras_iodev*))fake_delay_frames; fake_delay_frames_called = 0; - fake_sco_out.get_buffer = fake_sco_in.get_buffer = - (int (*)(struct cras_iodev *, struct cras_audio_area **, unsigned *)) - fake_get_buffer; + fake_sco_out.get_buffer = fake_sco_in.get_buffer = (int (*)( + struct cras_iodev*, struct cras_audio_area**, unsigned*))fake_get_buffer; fake_get_buffer_called = 0; fake_sco_out.put_buffer = fake_sco_in.put_buffer = - (int (*)(struct cras_iodev *, unsigned))fake_put_buffer; + (int (*)(struct cras_iodev*, unsigned))fake_put_buffer; fake_put_buffer_called = 0; fake_sco_out.flush_buffer = fake_sco_in.flush_buffer = - (int (*)(struct cras_iodev *))fake_flush_buffer; + (int (*)(struct cras_iodev*))fake_flush_buffer; fake_flush_buffer_called = 0; fake_sco_out.update_active_node = fake_sco_in.update_active_node = - (void (*)(struct cras_iodev *, unsigned, unsigned))fake_update_active_node; + (void (*)(struct cras_iodev*, unsigned, unsigned))fake_update_active_node; fake_update_active_node_called = 0; fake_sco_out.start = fake_sco_in.start = - (int (*)(const struct cras_iodev *))fake_start; + (int (*)(const struct cras_iodev*))fake_start; fake_start_called = 0; fake_sco_out.no_stream = fake_sco_in.no_stream = - (int (*)(struct cras_iodev *, int))fake_no_stream; + (int (*)(struct cras_iodev*, int))fake_no_stream; fake_no_stream_called = 0; fake_sco_out.is_free_running = fake_sco_in.is_free_running = - (int (*)(const struct cras_iodev *))fake_is_free_running; + (int (*)(const struct cras_iodev*))fake_is_free_running; fake_is_free_running_called = 0; } namespace { -class HfpAlsaIodev: public testing::Test { - protected: - virtual void SetUp() { - ResetStubData(); - } +class HfpAlsaIodev : public testing::Test { + protected: + virtual void SetUp() { ResetStubData(); } - virtual void TearDown() { - } + virtual void TearDown() {} }; TEST_F(HfpAlsaIodev, CreateHfpAlsaOutputIodev) { - struct cras_iodev *iodev; - struct hfp_alsa_io *hfp_alsa_io; + struct cras_iodev* iodev; + struct hfp_alsa_io* hfp_alsa_io; fake_sco_out.direction = CRAS_STREAM_OUTPUT; iodev = hfp_alsa_iodev_create(&fake_sco_out, fake_device, fake_slc, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); - hfp_alsa_io = (struct hfp_alsa_io *)iodev; + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); + hfp_alsa_io = (struct hfp_alsa_io*)iodev; EXPECT_EQ(CRAS_STREAM_OUTPUT, iodev->direction); EXPECT_EQ(1, cras_bt_device_append_iodev_called); @@ -168,13 +164,13 @@ TEST_F(HfpAlsaIodev, CreateHfpAlsaOutputIodev) { } TEST_F(HfpAlsaIodev, CreateHfpAlsaInputIodev) { - struct cras_iodev *iodev; - struct hfp_alsa_io *hfp_alsa_io; + struct cras_iodev* iodev; + struct hfp_alsa_io* hfp_alsa_io; fake_sco_in.direction = CRAS_STREAM_INPUT; iodev = hfp_alsa_iodev_create(&fake_sco_in, fake_device, fake_slc, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); - hfp_alsa_io = (struct hfp_alsa_io *)iodev; + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); + hfp_alsa_io = (struct hfp_alsa_io*)iodev; EXPECT_EQ(CRAS_STREAM_INPUT, iodev->direction); EXPECT_EQ(1, cras_bt_device_append_iodev_called); @@ -192,11 +188,11 @@ TEST_F(HfpAlsaIodev, CreateHfpAlsaInputIodev) { } TEST_F(HfpAlsaIodev, OpenDev) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; fake_sco_out.direction = CRAS_STREAM_OUTPUT; iodev = hfp_alsa_iodev_create(&fake_sco_out, fake_device, fake_slc, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); iodev->open_dev(iodev); EXPECT_EQ(1, fake_open_dev_called); @@ -205,13 +201,11 @@ TEST_F(HfpAlsaIodev, OpenDev) { } TEST_F(HfpAlsaIodev, UpdateSupportedFormat) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; size_t supported_rates[] = {8000, 0}; size_t supported_channel_counts[] = {1, 0}; - snd_pcm_format_t supported_formats[] = { - SND_PCM_FORMAT_S16_LE, - (snd_pcm_format_t)0 - }; + snd_pcm_format_t supported_formats[] = {SND_PCM_FORMAT_S16_LE, + (snd_pcm_format_t)0}; fake_sco_out.supported_rates = supported_rates; fake_sco_out.supported_channel_counts = supported_channel_counts; @@ -219,7 +213,7 @@ TEST_F(HfpAlsaIodev, UpdateSupportedFormat) { fake_sco_out.direction = CRAS_STREAM_OUTPUT; iodev = hfp_alsa_iodev_create(&fake_sco_out, fake_device, fake_slc, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); iodev->update_supported_formats(iodev); EXPECT_EQ(1, fake_update_supported_formats_called); @@ -233,13 +227,13 @@ TEST_F(HfpAlsaIodev, UpdateSupportedFormat) { } TEST_F(HfpAlsaIodev, ConfigureDev) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; size_t buf_size = 8192; fake_sco_out.direction = CRAS_STREAM_OUTPUT; fake_sco_out.buffer_size = buf_size; iodev = hfp_alsa_iodev_create(&fake_sco_out, fake_device, fake_slc, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); iodev->configure_dev(iodev); EXPECT_EQ(1, fake_configure_dev_called); @@ -250,11 +244,11 @@ TEST_F(HfpAlsaIodev, ConfigureDev) { } TEST_F(HfpAlsaIodev, CloseDev) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; fake_sco_out.direction = CRAS_STREAM_OUTPUT; iodev = hfp_alsa_iodev_create(&fake_sco_out, fake_device, fake_slc, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); iodev->close_dev(iodev); EXPECT_EQ(1, cras_iodev_free_format_called); @@ -264,12 +258,12 @@ TEST_F(HfpAlsaIodev, CloseDev) { } TEST_F(HfpAlsaIodev, FramesQueued) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; fake_sco_out.direction = CRAS_STREAM_OUTPUT; iodev = hfp_alsa_iodev_create(&fake_sco_out, fake_device, fake_slc, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); - iodev->frames_queued(iodev, (struct timespec *)NULL); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); + iodev->frames_queued(iodev, (struct timespec*)NULL); EXPECT_EQ(1, fake_frames_queued_called); @@ -277,11 +271,11 @@ TEST_F(HfpAlsaIodev, FramesQueued) { } TEST_F(HfpAlsaIodev, DelayFrames) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; fake_sco_out.direction = CRAS_STREAM_OUTPUT; iodev = hfp_alsa_iodev_create(&fake_sco_out, fake_device, fake_slc, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); iodev->delay_frames(iodev); EXPECT_EQ(1, fake_delay_frames_called); @@ -290,12 +284,12 @@ TEST_F(HfpAlsaIodev, DelayFrames) { } TEST_F(HfpAlsaIodev, GetBuffer) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; fake_sco_out.direction = CRAS_STREAM_OUTPUT; iodev = hfp_alsa_iodev_create(&fake_sco_out, fake_device, fake_slc, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); - iodev->get_buffer(iodev, (struct cras_audio_area **)NULL, (unsigned *)NULL); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); + iodev->get_buffer(iodev, (struct cras_audio_area**)NULL, (unsigned*)NULL); EXPECT_EQ(1, fake_get_buffer_called); @@ -303,11 +297,11 @@ TEST_F(HfpAlsaIodev, GetBuffer) { } TEST_F(HfpAlsaIodev, PutBuffer) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; fake_sco_out.direction = CRAS_STREAM_OUTPUT; iodev = hfp_alsa_iodev_create(&fake_sco_out, fake_device, fake_slc, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); iodev->put_buffer(iodev, 0xdeadbeef); EXPECT_EQ(1, fake_put_buffer_called); @@ -316,11 +310,11 @@ TEST_F(HfpAlsaIodev, PutBuffer) { } TEST_F(HfpAlsaIodev, FlushBuffer) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; fake_sco_out.direction = CRAS_STREAM_OUTPUT; iodev = hfp_alsa_iodev_create(&fake_sco_out, fake_device, fake_slc, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); iodev->flush_buffer(iodev); EXPECT_EQ(1, fake_flush_buffer_called); @@ -329,11 +323,11 @@ TEST_F(HfpAlsaIodev, FlushBuffer) { } TEST_F(HfpAlsaIodev, UpdateActiveNode) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; fake_sco_out.direction = CRAS_STREAM_OUTPUT; iodev = hfp_alsa_iodev_create(&fake_sco_out, fake_device, fake_slc, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); iodev->update_active_node(iodev, 0xdeadbeef, 0xdeadbeef); EXPECT_EQ(1, fake_update_active_node_called); @@ -342,11 +336,11 @@ TEST_F(HfpAlsaIodev, UpdateActiveNode) { } TEST_F(HfpAlsaIodev, Start) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; fake_sco_out.direction = CRAS_STREAM_OUTPUT; iodev = hfp_alsa_iodev_create(&fake_sco_out, fake_device, fake_slc, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); iodev->start(iodev); EXPECT_EQ(1, fake_start_called); @@ -355,11 +349,11 @@ TEST_F(HfpAlsaIodev, Start) { } TEST_F(HfpAlsaIodev, SetVolume) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; fake_sco_out.direction = CRAS_STREAM_OUTPUT; iodev = hfp_alsa_iodev_create(&fake_sco_out, fake_device, fake_slc, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); iodev->set_volume(iodev); EXPECT_EQ(1, hfp_event_speaker_gain_called); @@ -368,11 +362,11 @@ TEST_F(HfpAlsaIodev, SetVolume) { } TEST_F(HfpAlsaIodev, NoStream) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; fake_sco_out.direction = CRAS_STREAM_OUTPUT; iodev = hfp_alsa_iodev_create(&fake_sco_out, fake_device, fake_slc, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); iodev->min_cb_level = 0xab; iodev->max_cb_level = 0xcd; @@ -386,11 +380,11 @@ TEST_F(HfpAlsaIodev, NoStream) { } TEST_F(HfpAlsaIodev, IsFreeRunning) { - struct cras_iodev *iodev; + struct cras_iodev* iodev; fake_sco_out.direction = CRAS_STREAM_OUTPUT; iodev = hfp_alsa_iodev_create(&fake_sco_out, fake_device, fake_slc, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY); iodev->is_free_running(iodev); EXPECT_EQ(1, fake_is_free_running_called); @@ -398,32 +392,32 @@ TEST_F(HfpAlsaIodev, IsFreeRunning) { hfp_alsa_iodev_destroy(iodev); } -} // namespace +} // namespace extern "C" { -int cras_iodev_set_format(struct cras_iodev *iodev, - const struct cras_audio_format *fmt) { +int cras_iodev_set_format(struct cras_iodev* iodev, + const struct cras_audio_format* fmt) { cras_iodev_set_format_called++; return 0; } -void cras_iodev_free_format(struct cras_iodev *iodev) { +void cras_iodev_free_format(struct cras_iodev* iodev) { cras_iodev_free_format_called++; } -void cras_iodev_add_node(struct cras_iodev *iodev, struct cras_ionode *node) { +void cras_iodev_add_node(struct cras_iodev* iodev, struct cras_ionode* node) { cras_iodev_add_node_called++; iodev->nodes = node; } -void cras_iodev_rm_node(struct cras_iodev *iodev, struct cras_ionode *node) { +void cras_iodev_rm_node(struct cras_iodev* iodev, struct cras_ionode* node) { cras_iodev_rm_node_called++; iodev->nodes = NULL; } -void cras_iodev_set_active_node(struct cras_iodev *iodev, - struct cras_ionode *node) { +void cras_iodev_set_active_node(struct cras_iodev* iodev, + struct cras_ionode* node) { cras_iodev_set_active_node_called++; iodev->active_node = node; } @@ -432,58 +426,56 @@ size_t cras_system_get_volume() { return 0; } -const char *cras_bt_device_name(const struct cras_bt_device *device) { +const char* cras_bt_device_name(const struct cras_bt_device* device) { return "fake-device-name"; } -const char *cras_bt_device_address(const struct cras_bt_device *device) { +const char* cras_bt_device_address(const struct cras_bt_device* device) { return "1A:2B:3C:4D:5E:6F"; } -void cras_bt_device_append_iodev(struct cras_bt_device *device, - struct cras_iodev *iodev, - enum cras_bt_device_profile profile) { +void cras_bt_device_append_iodev(struct cras_bt_device* device, + struct cras_iodev* iodev, + enum cras_bt_device_profile profile) { cras_bt_device_append_iodev_called++; } -void cras_bt_device_rm_iodev(struct cras_bt_device *device, - struct cras_iodev *iodev) { +void cras_bt_device_rm_iodev(struct cras_bt_device* device, + struct cras_iodev* iodev) { cras_bt_device_rm_iodev_called++; } -const char *cras_bt_device_object_path(const struct cras_bt_device *device) { +const char* cras_bt_device_object_path(const struct cras_bt_device* device) { return "/fake/object/path"; } -void cras_iodev_free_resources(struct cras_iodev *iodev) { +void cras_iodev_free_resources(struct cras_iodev* iodev) { cras_iodev_free_resources_called++; } -int hfp_set_call_status(struct hfp_slc_handle *handle, int call) { +int hfp_set_call_status(struct hfp_slc_handle* handle, int call) { hfp_set_call_status_called++; return 0; } -int hfp_event_speaker_gain(struct hfp_slc_handle *handle, int gain) { +int hfp_event_speaker_gain(struct hfp_slc_handle* handle, int gain) { hfp_event_speaker_gain_called++; return 0; } -int cras_bt_device_get_sco(struct cras_bt_device *device, int codec) { +int cras_bt_device_get_sco(struct cras_bt_device* device, int codec) { return 0; } -void cras_bt_device_put_sco(struct cras_bt_device *device) { -} +void cras_bt_device_put_sco(struct cras_bt_device* device) {} -int hfp_slc_get_selected_codec(struct hfp_slc_handle *handle) -{ +int hfp_slc_get_selected_codec(struct hfp_slc_handle* handle) { return HFP_CODEC_ID_CVSD; } -} // extern "C" +} // extern "C" -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/hfp_info_unittest.cc b/cras/src/tests/hfp_info_unittest.cc index 5537ce61..482c3a99 100644 --- a/cras/src/tests/hfp_info_unittest.cc +++ b/cras/src/tests/hfp_info_unittest.cc @@ -8,18 +8,25 @@ #include <time.h> extern "C" { - #include "cras_hfp_info.c" +#include "cras_hfp_info.c" +#include "sbc_codec_stub.h" } - -static struct hfp_info *info; +static struct hfp_info* info; static struct cras_iodev dev; static cras_audio_format format; +static int cras_msbc_plc_create_called; +static int cras_msbc_plc_handle_good_frames_called; +static int cras_msbc_plc_handle_bad_frames_called; + static thread_callback thread_cb; -static void *cb_data; +static void* cb_data; static timespec ts; void ResetStubData() { + sbc_codec_stub_reset(); + cras_msbc_plc_create_called = 0; + format.format = SND_PCM_FORMAT_S16_LE; format.num_channels = 1; format.frame_rate = 8000; @@ -29,79 +36,83 @@ void ResetStubData() { namespace { TEST(HfpInfo, AddRmDev) { + ResetStubData(); + info = hfp_info_create(HFP_CODEC_ID_CVSD); - ASSERT_NE(info, (void *)NULL); + ASSERT_NE(info, (void*)NULL); dev.direction = CRAS_STREAM_OUTPUT; /* Test add dev */ - ASSERT_EQ(0, hfp_info_add_iodev(info, &dev)); + ASSERT_EQ(0, hfp_info_add_iodev(info, dev.direction, dev.format)); ASSERT_TRUE(hfp_info_has_iodev(info)); /* Test remove dev */ - ASSERT_EQ(0, hfp_info_rm_iodev(info, &dev)); + ASSERT_EQ(0, hfp_info_rm_iodev(info, dev.direction)); ASSERT_FALSE(hfp_info_has_iodev(info)); hfp_info_destroy(info); } TEST(HfpInfo, AddRmDevInvalid) { + ResetStubData(); + info = hfp_info_create(HFP_CODEC_ID_CVSD); - ASSERT_NE(info, (void *)NULL); + ASSERT_NE(info, (void*)NULL); dev.direction = CRAS_STREAM_OUTPUT; /* Remove an iodev which doesn't exist */ - ASSERT_NE(0, hfp_info_rm_iodev(info, &dev)); + ASSERT_NE(0, hfp_info_rm_iodev(info, dev.direction)); /* Adding an iodev twice returns error code */ - ASSERT_EQ(0, hfp_info_add_iodev(info, &dev)); - ASSERT_NE(0, hfp_info_add_iodev(info, &dev)); + ASSERT_EQ(0, hfp_info_add_iodev(info, dev.direction, dev.format)); + ASSERT_NE(0, hfp_info_add_iodev(info, dev.direction, dev.format)); hfp_info_destroy(info); } TEST(HfpInfo, AcquirePlaybackBuffer) { unsigned buffer_frames, buffer_frames2, queued; - uint8_t *samples; + uint8_t* samples; ResetStubData(); info = hfp_info_create(HFP_CODEC_ID_CVSD); - ASSERT_NE(info, (void *)NULL); + ASSERT_NE(info, (void*)NULL); hfp_info_start(1, 48, info); dev.direction = CRAS_STREAM_OUTPUT; - ASSERT_EQ(0, hfp_info_add_iodev(info, &dev)); + ASSERT_EQ(0, hfp_info_add_iodev(info, dev.direction, dev.format)); buffer_frames = 500; - hfp_buf_acquire(info, &dev, &samples, &buffer_frames); + hfp_buf_acquire(info, dev.direction, &samples, &buffer_frames); ASSERT_EQ(500, buffer_frames); - hfp_buf_release(info, &dev, 500); - ASSERT_EQ(500, hfp_buf_queued(info, &dev)); + hfp_buf_release(info, dev.direction, 500); + ASSERT_EQ(500, hfp_buf_queued(info, dev.direction)); /* Assert the amount of frames of available buffer + queued buf is * greater than or equal to the buffer size, 2 bytes per frame */ - queued = hfp_buf_queued(info, &dev); + queued = hfp_buf_queued(info, dev.direction); buffer_frames = 500; - hfp_buf_acquire(info, &dev, &samples, &buffer_frames); + hfp_buf_acquire(info, dev.direction, &samples, &buffer_frames); ASSERT_GE(info->playback_buf->used_size / 2, buffer_frames + queued); /* Consume all queued data from read buffer */ buf_increment_read(info->playback_buf, queued * 2); - queued = hfp_buf_queued(info, &dev); + queued = hfp_buf_queued(info, dev.direction); ASSERT_EQ(0, queued); /* Assert consecutive acquire buffer will acquire full used size of buffer */ buffer_frames = 500; - hfp_buf_acquire(info, &dev, &samples, &buffer_frames); - hfp_buf_release(info, &dev, buffer_frames); + hfp_buf_acquire(info, dev.direction, &samples, &buffer_frames); + hfp_buf_release(info, dev.direction, buffer_frames); buffer_frames2 = 500; - hfp_buf_acquire(info, &dev, &samples, &buffer_frames2); - hfp_buf_release(info, &dev, buffer_frames2); + hfp_buf_acquire(info, dev.direction, &samples, &buffer_frames2); + hfp_buf_release(info, dev.direction, buffer_frames2); ASSERT_GE(info->playback_buf->used_size / 2, buffer_frames + buffer_frames2); @@ -110,27 +121,27 @@ TEST(HfpInfo, AcquirePlaybackBuffer) { TEST(HfpInfo, AcquireCaptureBuffer) { unsigned buffer_frames, buffer_frames2; - uint8_t *samples; + uint8_t* samples; ResetStubData(); info = hfp_info_create(HFP_CODEC_ID_CVSD); - ASSERT_NE(info, (void *)NULL); + ASSERT_NE(info, (void*)NULL); hfp_info_start(1, 48, info); dev.direction = CRAS_STREAM_INPUT; - ASSERT_EQ(0, hfp_info_add_iodev(info, &dev)); + ASSERT_EQ(0, hfp_info_add_iodev(info, dev.direction, dev.format)); /* Put fake data 100 bytes(50 frames) in capture buf for test */ buf_increment_write(info->capture_buf, 100); /* Assert successfully acquire and release 100 bytes of data */ buffer_frames = 50; - hfp_buf_acquire(info, &dev, &samples, &buffer_frames); + hfp_buf_acquire(info, dev.direction, &samples, &buffer_frames); ASSERT_EQ(50, buffer_frames); - hfp_buf_release(info, &dev, buffer_frames); - ASSERT_EQ(0, hfp_buf_queued(info, &dev)); + hfp_buf_release(info, dev.direction, buffer_frames); + ASSERT_EQ(0, hfp_buf_queued(info, dev.direction)); /* Push fake data to capture buffer */ buf_increment_write(info->capture_buf, info->capture_buf->used_size - 100); @@ -138,13 +149,13 @@ TEST(HfpInfo, AcquireCaptureBuffer) { /* Assert consecutive acquire call will consume the whole buffer */ buffer_frames = 1000; - hfp_buf_acquire(info, &dev, &samples, &buffer_frames); - hfp_buf_release(info, &dev, buffer_frames); + hfp_buf_acquire(info, dev.direction, &samples, &buffer_frames); + hfp_buf_release(info, dev.direction, buffer_frames); ASSERT_GE(1000, buffer_frames); buffer_frames2 = 1000; - hfp_buf_acquire(info, &dev, &samples, &buffer_frames2); - hfp_buf_release(info, &dev, buffer_frames2); + hfp_buf_acquire(info, dev.direction, &samples, &buffer_frames2); + hfp_buf_release(info, dev.direction, buffer_frames2); ASSERT_GE(info->capture_buf->used_size / 2, buffer_frames + buffer_frames2); @@ -155,17 +166,19 @@ TEST(HfpInfo, HfpReadWriteFD) { int rc; int sock[2]; uint8_t sample[480]; - uint8_t *buf; + uint8_t* buf; unsigned buffer_count; + ResetStubData(); + ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, sock)); info = hfp_info_create(HFP_CODEC_ID_CVSD); - ASSERT_NE(info, (void *)NULL); + ASSERT_NE(info, (void*)NULL); dev.direction = CRAS_STREAM_INPUT; hfp_info_start(sock[1], 48, info); - ASSERT_EQ(0, hfp_info_add_iodev(info, &dev)); + ASSERT_EQ(0, hfp_info_add_iodev(info, dev.direction, dev.format)); /* Mock the sco fd and send some fake data */ send(sock[0], sample, 48, 0); @@ -173,21 +186,21 @@ TEST(HfpInfo, HfpReadWriteFD) { rc = hfp_read(info); ASSERT_EQ(48, rc); - rc = hfp_buf_queued(info, &dev); + rc = hfp_buf_queued(info, dev.direction); ASSERT_EQ(48 / 2, rc); /* Fill the write buffer*/ buffer_count = info->capture_buf->used_size; buf = buf_write_pointer_size(info->capture_buf, &buffer_count); buf_increment_write(info->capture_buf, buffer_count); - ASSERT_NE((void *)NULL, buf); + ASSERT_NE((void*)NULL, buf); rc = hfp_read(info); ASSERT_EQ(0, rc); - ASSERT_EQ(0, hfp_info_rm_iodev(info, &dev)); + ASSERT_EQ(0, hfp_info_rm_iodev(info, dev.direction)); dev.direction = CRAS_STREAM_OUTPUT; - ASSERT_EQ(0, hfp_info_add_iodev(info, &dev)); + ASSERT_EQ(0, hfp_info_add_iodev(info, dev.direction, dev.format)); /* Initial buffer is empty */ rc = hfp_write(info); @@ -212,11 +225,11 @@ TEST(HfpInfo, StartHfpInfo) { ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, sock)); info = hfp_info_create(HFP_CODEC_ID_CVSD); - ASSERT_NE(info, (void *)NULL); + ASSERT_NE(info, (void*)NULL); hfp_info_start(sock[0], 48, info); ASSERT_EQ(1, hfp_info_running(info)); - ASSERT_EQ(cb_data, (void *)info); + ASSERT_EQ(cb_data, (void*)info); hfp_info_stop(info); ASSERT_EQ(0, hfp_info_running(info)); @@ -235,29 +248,29 @@ TEST(HfpInfo, StartHfpInfoAndRead) { ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, sock)); info = hfp_info_create(HFP_CODEC_ID_CVSD); - ASSERT_NE(info, (void *)NULL); + ASSERT_NE(info, (void*)NULL); /* Start and send two chunk of fake data */ hfp_info_start(sock[1], 48, info); - send(sock[0], sample ,48, 0); - send(sock[0], sample ,48, 0); + send(sock[0], sample, 48, 0); + send(sock[0], sample, 48, 0); /* Trigger thread callback */ - thread_cb((struct hfp_info *)cb_data); + thread_cb((struct hfp_info*)cb_data); dev.direction = CRAS_STREAM_INPUT; - ASSERT_EQ(0, hfp_info_add_iodev(info, &dev)); + ASSERT_EQ(0, hfp_info_add_iodev(info, dev.direction, dev.format)); /* Expect no data read, since no idev present at previous thread callback */ - rc = hfp_buf_queued(info, &dev); + rc = hfp_buf_queued(info, dev.direction); ASSERT_EQ(0, rc); /* Trigger thread callback after idev added. */ ts.tv_sec = 0; ts.tv_nsec = 5000000; - thread_cb((struct hfp_info *)cb_data); + thread_cb((struct hfp_info*)cb_data); - rc = hfp_buf_queued(info, &dev); + rc = hfp_buf_queued(info, dev.direction); ASSERT_EQ(48 / 2, rc); /* Assert wait time is unchanged. */ @@ -275,77 +288,251 @@ TEST(HfpInfo, StartHfpInfoAndWrite) { int sock[2]; uint8_t sample[480]; + ResetStubData(); + ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, sock)); info = hfp_info_create(HFP_CODEC_ID_CVSD); - ASSERT_NE(info, (void *)NULL); + ASSERT_NE(info, (void*)NULL); hfp_info_start(sock[1], 48, info); - send(sock[0], sample ,48, 0); - send(sock[0], sample ,48, 0); + send(sock[0], sample, 48, 0); + send(sock[0], sample, 48, 0); /* Trigger thread callback */ - thread_cb((struct hfp_info *)cb_data); + thread_cb((struct hfp_info*)cb_data); + + /* Without odev in presence, zero packet should be sent. */ + rc = recv(sock[0], sample, 48, 0); + ASSERT_EQ(48, rc); dev.direction = CRAS_STREAM_OUTPUT; - ASSERT_EQ(0, hfp_info_add_iodev(info, &dev)); + ASSERT_EQ(0, hfp_info_add_iodev(info, dev.direction, dev.format)); /* Assert queued samples unchanged before output device added */ - ASSERT_EQ(0, hfp_buf_queued(info, &dev)); + ASSERT_EQ(0, hfp_buf_queued(info, dev.direction)); /* Put some fake data and trigger thread callback again */ buf_increment_write(info->playback_buf, 1008); - thread_cb((struct hfp_info *)cb_data); + thread_cb((struct hfp_info*)cb_data); /* Assert some samples written */ - rc = recv(sock[0], sample ,48, 0); + rc = recv(sock[0], sample, 48, 0); ASSERT_EQ(48, rc); - ASSERT_EQ(480, hfp_buf_queued(info, &dev)); + ASSERT_EQ(480, hfp_buf_queued(info, dev.direction)); hfp_info_stop(info); hfp_info_destroy(info); } -} // namespace +void send_mSBC_packet(int fd, unsigned seq, int broken_pkt) { + /* These three bytes are h2 header, frame count and mSBC sync word. + * The second octet of H2 header is composed by 4 bits fixed 0x8 and 4 bits + * sequence number 0000, 0011, 1100, 1111. + */ + uint8_t headers[4][3] = {{0x01, 0x08, 0xAD}, + {0x01, 0x38, 0xAD}, + {0x01, 0xc8, 0xAD}, + {0x01, 0xf8, 0xAD}}; + /* These three bytes are HCI SCO Data packet header, we only care the + * Packet_Status_Flag bits, which are the bit 4 to 5 in the second octet. + */ + uint8_t sco_header[] = {0x01, 0x01, 0x3c}; + uint8_t zero_frame[] = { + 0xad, 0x00, 0x00, 0xc5, 0x00, 0x00, 0x00, 0x00, 0x77, 0x6d, 0xb6, 0xdd, + 0xdb, 0x6d, 0xb7, 0x76, 0xdb, 0x6d, 0xdd, 0xb6, 0xdb, 0x77, 0x6d, 0xb6, + 0xdd, 0xdb, 0x6d, 0xb7, 0x76, 0xdb, 0x6d, 0xdd, 0xb6, 0xdb, 0x77, 0x6d, + 0xb6, 0xdd, 0xdb, 0x6d, 0xb7, 0x76, 0xdb, 0x6d, 0xdd, 0xb6, 0xdb, 0x77, + 0x6d, 0xb6, 0xdd, 0xdb, 0x6d, 0xb7, 0x76, 0xdb, 0x6c}; + if (broken_pkt) + sco_header[1] = 0x11; + + send(fd, sco_header, 3, 0); + send(fd, headers[seq % 4], 3, 0); + send(fd, zero_frame, 57, 0); +} + +TEST(HfpInfo, StartHfpInfoAndReadMsbc) { + int sock[2]; + int pkt_count = 0; + int rc; + uint8_t sample[480]; + ResetStubData(); + + ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, sock)); + + set_sbc_codec_decoded_out(MSBC_CODE_SIZE); + + info = hfp_info_create(HFP_CODEC_ID_MSBC); + ASSERT_NE(info, (void*)NULL); + ASSERT_EQ(2, get_msbc_codec_create_called()); + ASSERT_EQ(1, cras_msbc_plc_create_called); + + /* Start and send an mSBC packets with all zero samples */ + hfp_info_start(sock[1], 63, info); + send_mSBC_packet(sock[0], pkt_count++, 0); + + /* Trigger thread callback */ + thread_cb((struct hfp_info*)cb_data); + + /* Expect one empty mSBC packet is send, because no odev in presence. */ + rc = recv(sock[0], sample, MSBC_PKT_SIZE, 0); + ASSERT_EQ(MSBC_PKT_SIZE, rc); + + dev.direction = CRAS_STREAM_INPUT; + ASSERT_EQ(0, hfp_info_add_iodev(info, dev.direction, dev.format)); + + /* Expect no data read, since no idev present at previous thread callback */ + ASSERT_EQ(0, hfp_buf_queued(info, dev.direction)); + + send_mSBC_packet(sock[0], pkt_count, 0); + + /* Trigger thread callback after idev added. */ + thread_cb((struct hfp_info*)cb_data); + rc = recv(sock[0], sample, MSBC_PKT_SIZE, 0); + ASSERT_EQ(MSBC_PKT_SIZE, rc); + + ASSERT_EQ(pkt_count * MSBC_CODE_SIZE / 2, + hfp_buf_queued(info, dev.direction)); + ASSERT_EQ(2, cras_msbc_plc_handle_good_frames_called); + pkt_count++; + /* When the third packet is lost, we should call the handle_bad_packet and + * still have right size of samples queued + */ + pkt_count++; + send_mSBC_packet(sock[0], pkt_count, 0); + thread_cb((struct hfp_info*)cb_data); + rc = recv(sock[0], sample, MSBC_PKT_SIZE, 0); + ASSERT_EQ(MSBC_PKT_SIZE, rc); + + /* Packet 1, 2, 4 are all good frames */ + ASSERT_EQ(3, cras_msbc_plc_handle_good_frames_called); + ASSERT_EQ(1, cras_msbc_plc_handle_bad_frames_called); + ASSERT_EQ(pkt_count * MSBC_CODE_SIZE / 2, + hfp_buf_queued(info, dev.direction)); + pkt_count++; + /* If the erroneous data reporting marks the packet as broken, we should + * also call the handle_bad_packet and have the right size of samples queued. + */ + send_mSBC_packet(sock[0], pkt_count, 1); + + set_sbc_codec_decoded_fail(1); + + thread_cb((struct hfp_info*)cb_data); + rc = recv(sock[0], sample, MSBC_PKT_SIZE, 0); + ASSERT_EQ(MSBC_PKT_SIZE, rc); + + ASSERT_EQ(3, cras_msbc_plc_handle_good_frames_called); + ASSERT_EQ(2, cras_msbc_plc_handle_bad_frames_called); + ASSERT_EQ(pkt_count * MSBC_CODE_SIZE / 2, + hfp_buf_queued(info, dev.direction)); + pkt_count++; + /* If we can't decode the packet, we should also call the handle_bad_packet + * and have the right size of samples queued + */ + send_mSBC_packet(sock[0], pkt_count, 0); + + set_sbc_codec_decoded_fail(1); + + thread_cb((struct hfp_info*)cb_data); + rc = recv(sock[0], sample, MSBC_PKT_SIZE, 0); + ASSERT_EQ(MSBC_PKT_SIZE, rc); + + ASSERT_EQ(3, cras_msbc_plc_handle_good_frames_called); + ASSERT_EQ(3, cras_msbc_plc_handle_bad_frames_called); + ASSERT_EQ(pkt_count * MSBC_CODE_SIZE / 2, + hfp_buf_queued(info, dev.direction)); + + hfp_info_stop(info); + ASSERT_EQ(0, hfp_info_running(info)); + + hfp_info_destroy(info); +} + +TEST(HfpInfo, StartHfpInfoAndWriteMsbc) { + int rc; + int sock[2]; + uint8_t sample[480]; + + ResetStubData(); + + set_sbc_codec_encoded_out(57); + ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, sock)); + + info = hfp_info_create(HFP_CODEC_ID_MSBC); + ASSERT_NE(info, (void*)NULL); + + hfp_info_start(sock[1], 63, info); + send(sock[0], sample, 63, 0); + + /* Trigger thread callback */ + thread_cb((struct hfp_info*)cb_data); + + dev.direction = CRAS_STREAM_OUTPUT; + ASSERT_EQ(0, hfp_info_add_iodev(info, dev.direction, dev.format)); + + /* Assert queued samples unchanged before output device added */ + ASSERT_EQ(0, hfp_buf_queued(info, dev.direction)); + + /* Put some fake data and trigger thread callback again */ + send(sock[0], sample, 63, 0); + buf_increment_write(info->playback_buf, 240); + thread_cb((struct hfp_info*)cb_data); + + /* Assert some samples written */ + rc = recv(sock[0], sample, 60, 0); + ASSERT_EQ(60, rc); + ASSERT_EQ(0, hfp_buf_queued(info, dev.direction)); + + hfp_info_stop(info); + hfp_info_destroy(info); +} + +} // namespace extern "C" { -struct audio_thread *cras_iodev_list_get_audio_thread() -{ +struct audio_thread* cras_iodev_list_get_audio_thread() { return NULL; } -void audio_thread_add_callback(int fd, thread_callback cb, - void *data) -{ +void audio_thread_add_callback(int fd, thread_callback cb, void* data) { thread_cb = cb; cb_data = data; return; } -int audio_thread_rm_callback_sync(struct audio_thread *thread, int fd) -{ +int audio_thread_rm_callback_sync(struct audio_thread* thread, int fd) { thread_cb = NULL; cb_data = NULL; return 0; } -void audio_thread_rm_callback(int fd) -{ -} +void audio_thread_rm_callback(int fd) {} -struct cras_audio_codec *cras_msbc_codec_create() -{ +struct cras_msbc_plc* cras_msbc_plc_create() { + cras_msbc_plc_create_called++; return NULL; } -void cras_sbc_codec_destroy(struct cras_audio_codec *codec) -{ +void cras_msbc_plc_destroy(struct cras_msbc_plc* plc) {} + +int cras_msbc_plc_handle_bad_frames(struct cras_msbc_plc* plc, + struct cras_audio_codec* codec, + uint8_t* output) { + cras_msbc_plc_handle_bad_frames_called++; + return MSBC_CODE_SIZE; } +int cras_msbc_plc_handle_good_frames(struct cras_msbc_plc* plc, + const uint8_t* input, + uint8_t* output) { + cras_msbc_plc_handle_good_frames_called++; + return MSBC_CODE_SIZE; +} } -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/hfp_iodev_unittest.cc b/cras/src/tests/hfp_iodev_unittest.cc index 6d70c311..9bfb2dda 100644 --- a/cras/src/tests/hfp_iodev_unittest.cc +++ b/cras/src/tests/hfp_iodev_unittest.cc @@ -7,16 +7,16 @@ extern "C" { #include "cras_audio_area.h" +#include "cras_hfp_info.h" #include "cras_hfp_iodev.h" #include "cras_hfp_slc.h" #include "cras_iodev.h" -#include "cras_hfp_info.h" } -static struct cras_iodev *iodev; -static struct cras_bt_device *fake_device; -static struct hfp_slc_handle *fake_slc; -static struct hfp_info *fake_info; +static struct cras_iodev* iodev; +static struct cras_bt_device* fake_device; +static struct hfp_slc_handle* fake_slc; +static struct hfp_info* fake_info; struct cras_audio_format fake_format; static size_t cras_bt_device_append_iodev_called; static size_t cras_bt_device_rm_iodev_called; @@ -43,7 +43,7 @@ static size_t hfp_fill_output_with_zeros_called; static size_t hfp_force_output_level_called; static size_t hfp_force_output_level_target; static size_t fake_buffer_size = 500; -static cras_audio_area *dummy_audio_area; +static cras_audio_area* dummy_audio_area; void ResetStubData() { cras_bt_device_append_iodev_called = 0; @@ -71,32 +71,29 @@ void ResetStubData() { hfp_force_output_level_called = 0; hfp_force_output_level_target = 0; - fake_info = reinterpret_cast<struct hfp_info *>(0x123); + fake_info = reinterpret_cast<struct hfp_info*>(0x123); if (!dummy_audio_area) { - dummy_audio_area = (cras_audio_area*)calloc(1, - sizeof(*dummy_audio_area) + sizeof(cras_channel_area) * 2); + dummy_audio_area = (cras_audio_area*)calloc( + 1, sizeof(*dummy_audio_area) + sizeof(cras_channel_area) * 2); } } namespace { -class HfpIodev: public testing::Test { - protected: - virtual void SetUp() { - ResetStubData(); - } +class HfpIodev : public testing::Test { + protected: + virtual void SetUp() { ResetStubData(); } - virtual void TearDown() { - free(dummy_audio_area); - dummy_audio_area = NULL; - } + virtual void TearDown() { + free(dummy_audio_area); + dummy_audio_area = NULL; + } }; TEST_F(HfpIodev, CreateHfpOutputIodev) { iodev = hfp_iodev_create(CRAS_STREAM_OUTPUT, fake_device, fake_slc, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY, - fake_info); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY, fake_info); ASSERT_EQ(CRAS_STREAM_OUTPUT, iodev->direction); ASSERT_EQ(1, cras_bt_device_append_iodev_called); @@ -130,8 +127,7 @@ TEST_F(HfpIodev, CreateHfpInputIodev) { TEST_F(HfpIodev, OpenHfpIodev) { iodev = hfp_iodev_create(CRAS_STREAM_OUTPUT, fake_device, fake_slc, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY, - fake_info); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY, fake_info); iodev->format = &fake_format; /* hfp_info not start yet */ @@ -155,8 +151,7 @@ TEST_F(HfpIodev, OpenHfpIodev) { TEST_F(HfpIodev, OpenIodevWithHfpInfoAlreadyRunning) { iodev = hfp_iodev_create(CRAS_STREAM_INPUT, fake_device, fake_slc, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY, - fake_info); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY, fake_info); iodev->format = &fake_format; @@ -178,13 +173,12 @@ TEST_F(HfpIodev, OpenIodevWithHfpInfoAlreadyRunning) { } TEST_F(HfpIodev, PutGetBuffer) { - cras_audio_area *area; + cras_audio_area* area; unsigned frames; ResetStubData(); iodev = hfp_iodev_create(CRAS_STREAM_OUTPUT, fake_device, fake_slc, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY, - fake_info); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY, fake_info); iodev->format = &fake_format; iodev->configure_dev(iodev); @@ -202,13 +196,12 @@ TEST_F(HfpIodev, PutGetBuffer) { } TEST_F(HfpIodev, NoStreamState) { - cras_audio_area *area; + cras_audio_area* area; unsigned frames; ResetStubData(); iodev = hfp_iodev_create(CRAS_STREAM_OUTPUT, fake_device, fake_slc, - CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY, - fake_info); + CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY, fake_info); iodev->format = &fake_format; iodev->configure_dev(iodev); iodev->min_cb_level = iodev->buffer_size / 2; @@ -227,194 +220,167 @@ TEST_F(HfpIodev, NoStreamState) { hfp_iodev_destroy(iodev); } -} // namespace +} // namespace extern "C" { -void cras_iodev_free_format(struct cras_iodev *iodev) -{ +void cras_iodev_free_format(struct cras_iodev* iodev) { cras_iodev_free_format_called++; } -void cras_iodev_add_node(struct cras_iodev *iodev, struct cras_ionode *node) -{ +void cras_iodev_add_node(struct cras_iodev* iodev, struct cras_ionode* node) { cras_iodev_add_node_called++; iodev->nodes = node; } -void cras_iodev_rm_node(struct cras_iodev *iodev, struct cras_ionode *node) -{ +void cras_iodev_rm_node(struct cras_iodev* iodev, struct cras_ionode* node) { cras_iodev_rm_node_called++; iodev->nodes = NULL; } -void cras_iodev_set_active_node(struct cras_iodev *iodev, - struct cras_ionode *node) -{ +void cras_iodev_set_active_node(struct cras_iodev* iodev, + struct cras_ionode* node) { cras_iodev_set_active_node_called++; iodev->active_node = node; } // From system_state. -size_t cras_system_get_volume() -{ +size_t cras_system_get_volume() { return 0; } // From bt device -int cras_bt_device_sco_connect(struct cras_bt_device *device, int codec) -{ +int cras_bt_device_sco_connect(struct cras_bt_device* device, int codec) { cras_bt_device_sco_connect_called++; return cras_bt_transport_sco_connect_return_val; } -const char *cras_bt_device_name(const struct cras_bt_device *device) -{ +const char* cras_bt_device_name(const struct cras_bt_device* device) { return "fake-device-name"; } -const char *cras_bt_device_address(const struct cras_bt_device *device) { +const char* cras_bt_device_address(const struct cras_bt_device* device) { return "1A:2B:3C:4D:5E:6F"; } -void cras_bt_device_append_iodev(struct cras_bt_device *device, - struct cras_iodev *iodev, - enum cras_bt_device_profile profile) -{ +void cras_bt_device_append_iodev(struct cras_bt_device* device, + struct cras_iodev* iodev, + enum cras_bt_device_profile profile) { cras_bt_device_append_iodev_called++; } -void cras_bt_device_rm_iodev(struct cras_bt_device *device, - struct cras_iodev *iodev) -{ +void cras_bt_device_rm_iodev(struct cras_bt_device* device, + struct cras_iodev* iodev) { cras_bt_device_rm_iodev_called++; } -int cras_bt_device_sco_packet_size(struct cras_bt_device *device, +int cras_bt_device_sco_packet_size(struct cras_bt_device* device, int sco_socket, - int codec) -{ + int codec) { return 48; } -const char *cras_bt_device_object_path(const struct cras_bt_device *device) -{ +const char* cras_bt_device_object_path(const struct cras_bt_device* device) { return "/fake/object/path"; } // From cras_hfp_info -int hfp_info_add_iodev(struct hfp_info *info, struct cras_iodev *dev) -{ +int hfp_info_add_iodev(struct hfp_info* info, + enum CRAS_STREAM_DIRECTION direction, + struct cras_audio_format* format) { hfp_info_add_iodev_called++; return 0; } -int hfp_info_rm_iodev(struct hfp_info *info, struct cras_iodev *dev) -{ +int hfp_info_rm_iodev(struct hfp_info* info, + enum CRAS_STREAM_DIRECTION direction) { hfp_info_rm_iodev_called++; return 0; } -int hfp_info_has_iodev(struct hfp_info *info) -{ +int hfp_info_has_iodev(struct hfp_info* info) { hfp_info_has_iodev_called++; return hfp_info_has_iodev_return_val; } -int hfp_info_running(struct hfp_info *info) -{ +int hfp_info_running(struct hfp_info* info) { hfp_info_running_called++; return hfp_info_running_return_val; } -int hfp_info_start(int fd, unsigned int mtu, struct hfp_info *info) -{ +int hfp_info_start(int fd, unsigned int mtu, struct hfp_info* info) { hfp_info_start_called++; return 0; } -int hfp_info_stop(struct hfp_info *info) -{ +int hfp_info_stop(struct hfp_info* info) { hfp_info_stop_called++; return 0; } -int hfp_buf_queued(struct hfp_info *info, const struct cras_iodev *dev) -{ +int hfp_buf_queued(struct hfp_info* info, + const enum CRAS_STREAM_DIRECTION direction) { return 0; } -int hfp_buf_size(struct hfp_info *info, struct cras_iodev *dev) -{ +int hfp_buf_size(struct hfp_info* info, enum CRAS_STREAM_DIRECTION direction) { return fake_buffer_size; } -void hfp_buf_acquire(struct hfp_info *info, struct cras_iodev *dev, - uint8_t **buf, unsigned *count) -{ +void hfp_buf_acquire(struct hfp_info* info, + enum CRAS_STREAM_DIRECTION direction, + uint8_t** buf, + unsigned* count) { hfp_buf_acquire_called++; *count = hfp_buf_acquire_return_val; } -void hfp_buf_release(struct hfp_info *info, struct cras_iodev *dev, - unsigned written_bytes) -{ +void hfp_buf_release(struct hfp_info* info, + enum CRAS_STREAM_DIRECTION direction, + unsigned written_bytes) { hfp_buf_release_called++; hfp_buf_release_nwritten_val = written_bytes; } -int hfp_fill_output_with_zeros(struct hfp_info *info, - struct cras_iodev *dev, - unsigned int nframes) -{ +int hfp_fill_output_with_zeros(struct hfp_info* info, unsigned int nframes) { hfp_fill_output_with_zeros_called++; return 0; } -int hfp_force_output_level(struct hfp_info *info, - struct cras_iodev *dev, - unsigned int level) -{ +void hfp_force_output_level(struct hfp_info* info, unsigned int level) { hfp_force_output_level_called++; hfp_force_output_level_target = level; - return 0; } -void cras_iodev_init_audio_area(struct cras_iodev *iodev, - int num_channels) { +void cras_iodev_init_audio_area(struct cras_iodev* iodev, int num_channels) { iodev->area = dummy_audio_area; } -void cras_iodev_free_audio_area(struct cras_iodev *iodev) { -} +void cras_iodev_free_audio_area(struct cras_iodev* iodev) {} -void cras_iodev_free_resources(struct cras_iodev *iodev) { - cras_iodev_free_resources_called++; +void cras_iodev_free_resources(struct cras_iodev* iodev) { + cras_iodev_free_resources_called++; } -void cras_audio_area_config_buf_pointers(struct cras_audio_area *area, - const struct cras_audio_format *fmt, - uint8_t *base_buffer) -{ +void cras_audio_area_config_buf_pointers(struct cras_audio_area* area, + const struct cras_audio_format* fmt, + uint8_t* base_buffer) { dummy_audio_area->channels[0].buf = base_buffer; } -int hfp_set_call_status(struct hfp_slc_handle *handle, int call) -{ +int hfp_set_call_status(struct hfp_slc_handle* handle, int call) { return 0; } -int hfp_event_speaker_gain(struct hfp_slc_handle *handle, int gain) -{ +int hfp_event_speaker_gain(struct hfp_slc_handle* handle, int gain) { return 0; } -int hfp_slc_get_selected_codec(struct hfp_slc_handle *handle) -{ +int hfp_slc_get_selected_codec(struct hfp_slc_handle* handle) { return HFP_CODEC_ID_CVSD; } -} // extern "C" +} // extern "C" -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/hfp_slc_unittest.cc b/cras/src/tests/hfp_slc_unittest.cc index c4c7ac7e..f98a1f3e 100644 --- a/cras/src/tests/hfp_slc_unittest.cc +++ b/cras/src/tests/hfp_slc_unittest.cc @@ -5,30 +5,31 @@ #include <gtest/gtest.h> #include <stdint.h> -#include <sys/socket.h> - #include <stdio.h> +#include <sys/socket.h> extern "C" { - #include "cras_bt_log.h" - #include "cras_hfp_slc.h" - #include "cras_telephony.h" +#include "cras_bt_log.h" +#include "cras_hfp_slc.h" +#include "cras_telephony.h" } -static struct hfp_slc_handle *handle; +static struct hfp_slc_handle* handle; static struct cras_telephony_handle fake_telephony; static int cras_bt_device_update_hardware_volume_called; static int slc_initialized_cb_called; static int slc_disconnected_cb_called; static int cras_system_add_select_fd_called; -static void(*slc_cb)(void *data); -static void *slc_cb_data; +static void (*slc_cb)(void* data); +static void* slc_cb_data; static int fake_errno; -static struct cras_bt_device *device = - reinterpret_cast<struct cras_bt_device *>(2); +static struct cras_bt_device* device = + reinterpret_cast<struct cras_bt_device*>(2); +static void (*cras_tm_timer_cb)(struct cras_timer* t, void* data); +static void* cras_tm_timer_cb_data; -int slc_initialized_cb(struct hfp_slc_handle *handle); -int slc_disconnected_cb(struct hfp_slc_handle *handle); +int slc_initialized_cb(struct hfp_slc_handle* handle); +int slc_disconnected_cb(struct hfp_slc_handle* handle); void ResetStubData() { slc_initialized_cb_called = 0; @@ -43,10 +44,8 @@ namespace { TEST(HfpSlc, CreateSlcHandle) { ResetStubData(); - handle = hfp_slc_create(0, 0, - AG_ENHANCED_CALL_STATUS, - device, slc_initialized_cb, - slc_disconnected_cb); + handle = hfp_slc_create(0, 0, AG_ENHANCED_CALL_STATUS, device, + slc_initialized_cb, slc_disconnected_cb); ASSERT_EQ(1, cras_system_add_select_fd_called); ASSERT_EQ(handle, slc_cb_data); @@ -57,14 +56,12 @@ TEST(HfpSlc, InitializeSlc) { int err; int sock[2]; char buf[256]; - char *chp; + char* chp; ResetStubData(); ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, sock)); - handle = hfp_slc_create(sock[0], 0, - AG_ENHANCED_CALL_STATUS, - device, slc_initialized_cb, - slc_disconnected_cb); + handle = hfp_slc_create(sock[0], 0, AG_ENHANCED_CALL_STATUS, device, + slc_initialized_cb, slc_disconnected_cb); err = write(sock[1], "AT+CIND=?\r", 10); ASSERT_EQ(10, err); @@ -73,16 +70,16 @@ TEST(HfpSlc, InitializeSlc) { /* Assert "\r\n+CIND: ... \r\n" response is received */ chp = strstr(buf, "\r\n"); - ASSERT_NE((void *)NULL, (void *)chp); + ASSERT_NE((void*)NULL, (void*)chp); ASSERT_EQ(0, strncmp("\r\n+CIND:", chp, 8)); - chp+=2; + chp += 2; chp = strstr(chp, "\r\n"); - ASSERT_NE((void *)NULL, (void *)chp); + ASSERT_NE((void*)NULL, (void*)chp); /* Assert "\r\nOK\r\n" response is received */ - chp+=2; + chp += 2; chp = strstr(chp, "\r\n"); - ASSERT_NE((void *)NULL, (void *)chp); + ASSERT_NE((void*)NULL, (void*)chp); ASSERT_EQ(0, strncmp("\r\nOK", chp, 4)); err = write(sock[1], "AT+CMER=3,0,0,1\r", 16); @@ -95,7 +92,7 @@ TEST(HfpSlc, InitializeSlc) { err = read(sock[1], buf, 256); chp = strstr(buf, "\r\n"); - ASSERT_NE((void *)NULL, (void *)chp); + ASSERT_NE((void*)NULL, (void*)chp); ASSERT_EQ(0, strncmp("\r\nOK", chp, 4)); err = write(sock[1], "AT+VGS=13\r", 10); @@ -105,7 +102,7 @@ TEST(HfpSlc, InitializeSlc) { err = read(sock[1], buf, 256); chp = strstr(buf, "\r\n"); - ASSERT_NE((void *)NULL, (void *)chp); + ASSERT_NE((void*)NULL, (void*)chp); ASSERT_EQ(0, strncmp("\r\nOK", chp, 4)); ASSERT_EQ(1, cras_bt_device_update_hardware_volume_called); @@ -118,10 +115,8 @@ TEST(HfpSlc, DisconnectSlc) { ResetStubData(); ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, sock)); - handle = hfp_slc_create(sock[0], 0, - AG_ENHANCED_CALL_STATUS, - device, slc_initialized_cb, - slc_disconnected_cb); + handle = hfp_slc_create(sock[0], 0, AG_ENHANCED_CALL_STATUS, device, + slc_initialized_cb, slc_disconnected_cb); /* Close socket right away to make read() get negative err code, and * fake the errno to ECONNRESET. */ close(sock[0]); @@ -133,86 +128,207 @@ TEST(HfpSlc, DisconnectSlc) { hfp_slc_destroy(handle); } -} // namespace -int slc_initialized_cb(struct hfp_slc_handle *handle) { +TEST(HfpSlc, CodecNegotiation) { + int codec; + int err; + int sock[2]; + char buf[256]; + char* pos; + ResetStubData(); + + btlog = cras_bt_event_log_init(); + + ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, sock)); + handle = hfp_slc_create(sock[0], 0, AG_CODEC_NEGOTIATION, device, + slc_initialized_cb, slc_disconnected_cb); + + codec = hfp_slc_get_selected_codec(handle); + EXPECT_EQ(HFP_CODEC_ID_CVSD, codec); + + /* Fake that HF supports codec negotiation. */ + err = write(sock[1], "AT+BRSF=128\r", 12); + ASSERT_EQ(err, 12); + slc_cb(slc_cb_data); + err = read(sock[1], buf, 256); + + /* Fake that HF supports mSBC codec. */ + err = write(sock[1], "AT+BAC=1,2\r", 11); + ASSERT_EQ(err, 11); + slc_cb(slc_cb_data); + err = read(sock[1], buf, 256); + + /* Fake event reporting command to indicate SLC established. */ + err = write(sock[1], "AT+CMER=3,0,0,1\r", 16); + ASSERT_EQ(err, 16); + slc_cb(slc_cb_data); + + /* Assert that AG side prefers mSBC codec. */ + codec = hfp_slc_get_selected_codec(handle); + EXPECT_EQ(HFP_CODEC_ID_MSBC, codec); + + /* Assert CRAS initiates codec selection to mSBC. */ + memset(buf, 0, 256); + err = read(sock[1], buf, 256); + pos = strstr(buf, "\r\n+BCS:2\r\n"); + ASSERT_NE((void*)NULL, pos); + + err = write(sock[1], "AT+VGS=9\r", 9); + ASSERT_EQ(err, 9); + slc_cb(slc_cb_data); + + /* Assert CRAS initiates codec selection to mSBC. */ + memset(buf, 0, 256); + err = read(sock[1], buf, 256); + pos = strstr(buf, "\r\n+BCS:2\r\n"); + ASSERT_NE((void*)NULL, pos); + + /* Fake that receiving codec selection from HF. */ + err = write(sock[1], "AT+BCS=2\r", 9); + ASSERT_EQ(err, 9); + slc_cb(slc_cb_data); + + memset(buf, 0, 256); + err = read(sock[1], buf, 256); + pos = strstr(buf, "\r\n+BCS:2\r\n"); + ASSERT_EQ((void*)NULL, pos); + + hfp_slc_destroy(handle); + cras_bt_event_log_deinit(btlog); +} + +TEST(HfpSlc, CodecNegotiationTimeout) { + int codec; + int err; + int sock[2]; + char buf[256]; + char* pos; + ResetStubData(); + + btlog = cras_bt_event_log_init(); + + ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, sock)); + handle = hfp_slc_create(sock[0], 0, AG_CODEC_NEGOTIATION, device, + slc_initialized_cb, slc_disconnected_cb); + + codec = hfp_slc_get_selected_codec(handle); + EXPECT_EQ(HFP_CODEC_ID_CVSD, codec); + + /* Fake that HF supports codec negotiation. */ + err = write(sock[1], "AT+BRSF=128\r", 12); + ASSERT_EQ(err, 12); + slc_cb(slc_cb_data); + err = read(sock[1], buf, 256); + + /* Fake that HF supports mSBC codec. */ + err = write(sock[1], "AT+BAC=1,2\r", 11); + ASSERT_EQ(err, 11); + slc_cb(slc_cb_data); + err = read(sock[1], buf, 256); + + /* Fake event reporting command to indicate SLC established. */ + err = write(sock[1], "AT+CMER=3,0,0,1\r", 16); + ASSERT_EQ(err, 16); + slc_cb(slc_cb_data); + + ASSERT_NE((void*)NULL, cras_tm_timer_cb); + + /* Assert that AG side prefers mSBC codec. */ + codec = hfp_slc_get_selected_codec(handle); + EXPECT_EQ(HFP_CODEC_ID_MSBC, codec); + + /* Assert CRAS initiates codec selection to mSBC. */ + memset(buf, 0, 256); + err = read(sock[1], buf, 256); + pos = strstr(buf, "\r\n+BCS:2\r\n"); + ASSERT_NE((void*)NULL, pos); + + /* Assume codec negotiation failed. so timeout is reached. */ + cras_tm_timer_cb(NULL, cras_tm_timer_cb_data); + + codec = hfp_slc_get_selected_codec(handle); + EXPECT_EQ(HFP_CODEC_ID_CVSD, codec); + + /* Expects CRAS fallback and selects to CVSD codec. */ + memset(buf, 0, 256); + err = read(sock[1], buf, 256); + pos = strstr(buf, "\r\n+BCS:1\r\n"); + ASSERT_NE((void*)NULL, pos); + + hfp_slc_destroy(handle); + cras_bt_event_log_deinit(btlog); +} + +} // namespace + +int slc_initialized_cb(struct hfp_slc_handle* handle) { slc_initialized_cb_called++; return 0; } -int slc_disconnected_cb(struct hfp_slc_handle *handle) { +int slc_disconnected_cb(struct hfp_slc_handle* handle) { slc_disconnected_cb_called++; return 0; } extern "C" { -struct cras_bt_event_log *btlog; +struct cras_bt_event_log* btlog; int cras_system_add_select_fd(int fd, - void (*callback)(void *data), - void *callback_data) { + void (*callback)(void* data), + void* callback_data) { cras_system_add_select_fd_called++; slc_cb = callback; slc_cb_data = callback_data; return 0; } -void cras_system_rm_select_fd(int fd) { -} +void cras_system_rm_select_fd(int fd) {} -void cras_bt_device_update_hardware_volume(struct cras_bt_device *device, - int volume) -{ +void cras_bt_device_update_hardware_volume(struct cras_bt_device* device, + int volume) { cras_bt_device_update_hardware_volume_called++; } /* To return fake errno */ -int *__errno_location() { +int* __errno_location() { return &fake_errno; } -struct cras_tm *cras_system_state_get_tm() -{ +struct cras_tm* cras_system_state_get_tm() { return NULL; } -struct cras_timer *cras_tm_create_timer( - struct cras_tm *tm, - unsigned int ms, - void (*cb)(struct cras_timer *t, void *data), - void *cb_data) -{ - return NULL; -} - -void cras_tm_cancel_timer(struct cras_tm *tm, struct cras_timer *t) -{ +struct cras_timer* cras_tm_create_timer(struct cras_tm* tm, + unsigned int ms, + void (*cb)(struct cras_timer* t, + void* data), + void* cb_data) { + cras_tm_timer_cb = cb; + cras_tm_timer_cb_data = cb_data; + return reinterpret_cast<struct cras_timer*>(0x404); } +void cras_tm_cancel_timer(struct cras_tm* tm, struct cras_timer* t) {} } // For telephony -struct cras_telephony_handle* cras_telephony_get() -{ +struct cras_telephony_handle* cras_telephony_get() { return &fake_telephony; } -void cras_telephony_store_dial_number(int len, const char* num) -{ -} +void cras_telephony_store_dial_number(int len, const char* num) {} -int cras_telephony_event_answer_call() -{ +int cras_telephony_event_answer_call() { return 0; } -int cras_telephony_event_terminate_call() -{ +int cras_telephony_event_terminate_call() { return 0; } -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/input_data_unittest.cc b/cras/src/tests/input_data_unittest.cc index 49657fb5..f1c3fd71 100644 --- a/cras/src/tests/input_data_unittest.cc +++ b/cras/src/tests/input_data_unittest.cc @@ -14,10 +14,12 @@ extern "C" { namespace { -static unsigned int cras_apm_list_process_called; +#ifdef HAVE_WEBRTC_APM +static struct cras_audio_area apm_area; static unsigned int cras_apm_list_process_offset_val; +static unsigned int cras_apm_list_process_called; static struct cras_apm* cras_apm_list_get_ret = NULL; -static struct cras_audio_area apm_area; +#endif // HAVE_WEBRTC_APM TEST(InputData, GetForInputStream) { void* dev_ptr = reinterpret_cast<void*>(0x123); @@ -28,7 +30,9 @@ TEST(InputData, GetForInputStream) { struct cras_audio_area dev_area; unsigned int offset; +#ifdef HAVE_WEBRTC_APM cras_apm_list_process_called = 0; +#endif // HAVE_WEBRTC_APM stream.stream_id = 111; data = input_data_create(dev_ptr); @@ -49,22 +53,30 @@ TEST(InputData, GetForInputStream) { // Assert offset is clipped by area->frames EXPECT_EQ(600, area->frames); EXPECT_EQ(600, offset); +#ifdef HAVE_WEBRTC_APM EXPECT_EQ(0, cras_apm_list_process_called); - cras_apm_list_get_ret = reinterpret_cast<struct cras_apm*>(0x99); +#endif // HAVE_WEBRTC_APM + input_data_get_for_stream(data, &stream, offsets, &area, &offset); +#ifdef HAVE_WEBRTC_APM // Assert APM process uses correct stream offset not the clipped one // used for audio area. EXPECT_EQ(1, cras_apm_list_process_called); EXPECT_EQ(2048, cras_apm_list_process_offset_val); EXPECT_EQ(0, offset); +#else + // Without the APM, the offset shouldn't be changed. + EXPECT_EQ(600, offset); +#endif // HAVE_WEBRTC_APM input_data_destroy(&data); buffer_share_destroy(offsets); } extern "C" { +#ifdef HAVE_WEBRTC_APM struct cras_apm* cras_apm_list_get(struct cras_apm_list* list, void* dev_ptr) { return cras_apm_list_get_ret; } @@ -81,6 +93,7 @@ struct cras_audio_area* cras_apm_list_get_processed(struct cras_apm* apm) { } void cras_apm_list_remove(struct cras_apm_list* list, void* dev_ptr) {} void cras_apm_list_put_processed(struct cras_apm* apm, unsigned int frames) {} +#endif // HAVE_WEBRTC_APM } // extern "C" } // namespace diff --git a/cras/src/tests/iodev_list_unittest.cc b/cras/src/tests/iodev_list_unittest.cc index 07c7c874..798f2955 100644 --- a/cras/src/tests/iodev_list_unittest.cc +++ b/cras/src/tests/iodev_list_unittest.cc @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <algorithm> -#include <stdio.h> #include <gtest/gtest.h> +#include <stdio.h> + +#include <algorithm> #include <map> extern "C" { @@ -23,55 +24,55 @@ extern "C" { namespace { struct cras_server_state server_state_stub; -struct cras_server_state *server_state_update_begin_return; +struct cras_server_state* server_state_update_begin_return; int system_get_mute_return; /* Data for stubs. */ -static struct cras_observer_ops *observer_ops; +static struct cras_observer_ops* observer_ops; static int add_stream_called; static int rm_stream_called; static unsigned int set_node_plugged_called; -static cras_iodev *audio_thread_remove_streams_active_dev; -static cras_iodev *audio_thread_set_active_dev_val; +static cras_iodev* audio_thread_remove_streams_active_dev; +static cras_iodev* audio_thread_set_active_dev_val; static int audio_thread_set_active_dev_called; -static cras_iodev *audio_thread_add_open_dev_dev; +static cras_iodev* audio_thread_add_open_dev_dev; static int audio_thread_add_open_dev_called; static int audio_thread_rm_open_dev_called; static int audio_thread_is_dev_open_ret; static struct audio_thread thread; static struct cras_iodev loopback_input; static int cras_iodev_close_called; -static struct cras_iodev *cras_iodev_close_dev; +static struct cras_iodev* cras_iodev_close_dev; static struct cras_iodev dummy_hotword_iodev; static struct cras_iodev dummy_empty_iodev[2]; -static stream_callback *stream_add_cb; -static stream_callback *stream_rm_cb; -static struct cras_rstream *stream_list_get_ret; +static stream_callback* stream_add_cb; +static stream_callback* stream_rm_cb; +static struct cras_rstream* stream_list_get_ret; static int server_stream_create_called; static int server_stream_destroy_called; static int audio_thread_drain_stream_return; static int audio_thread_drain_stream_called; static int cras_tm_create_timer_called; static int cras_tm_cancel_timer_called; -static void (*cras_tm_timer_cb)(struct cras_timer *t, void *data); -static void *cras_tm_timer_cb_data; +static void (*cras_tm_timer_cb)(struct cras_timer* t, void* data); +static void* cras_tm_timer_cb_data; static struct timespec clock_gettime_retspec; -static struct cras_iodev *device_enabled_dev; +static struct cras_iodev* device_enabled_dev; static int device_enabled_count; -static struct cras_iodev *device_disabled_dev; +static struct cras_iodev* device_disabled_dev; static int device_disabled_count; -static void *device_enabled_cb_data; -static void *device_disabled_cb_data; -static struct cras_rstream *audio_thread_add_stream_stream; -static struct cras_iodev *audio_thread_add_stream_dev; -static struct cras_iodev *audio_thread_disconnect_stream_dev; +static void* device_enabled_cb_data; +static void* device_disabled_cb_data; +static struct cras_rstream* audio_thread_add_stream_stream; +static struct cras_iodev* audio_thread_add_stream_dev; +static struct cras_iodev* audio_thread_disconnect_stream_dev; static int audio_thread_add_stream_called; static unsigned update_active_node_called; -static struct cras_iodev *update_active_node_iodev_val[5]; +static struct cras_iodev* update_active_node_iodev_val[5]; static unsigned update_active_node_node_idx_val[5]; static unsigned update_active_node_dev_enabled_val[5]; -static int set_swap_mode_for_node_called; -static int set_swap_mode_for_node_enable; +static int set_swap_mode_for_node_called; +static int set_swap_mode_for_node_enable; static int cras_iodev_start_volume_ramp_called; static size_t cras_observer_add_called; static size_t cras_observer_remove_called; @@ -86,198 +87,191 @@ static int set_mute_called; static std::vector<struct cras_iodev*> set_mute_dev_vector; static std::vector<unsigned int> audio_thread_dev_start_ramp_dev_vector; static int audio_thread_dev_start_ramp_called; -static enum CRAS_IODEV_RAMP_REQUEST audio_thread_dev_start_ramp_req ; +static enum CRAS_IODEV_RAMP_REQUEST audio_thread_dev_start_ramp_req; static std::map<int, bool> stream_list_has_pinned_stream_ret; -static struct cras_rstream *audio_thread_disconnect_stream_stream; +static struct cras_rstream* audio_thread_disconnect_stream_stream; static int audio_thread_disconnect_stream_called; static struct cras_iodev fake_sco_in_dev, fake_sco_out_dev; static struct cras_ionode fake_sco_in_node, fake_sco_out_node; -int dev_idx_in_vector(std::vector<unsigned int> v, unsigned int idx) -{ +int dev_idx_in_vector(std::vector<unsigned int> v, unsigned int idx) { return std::find(v.begin(), v.end(), idx) != v.end(); } -int device_in_vector(std::vector<struct cras_iodev*> v, struct cras_iodev *dev) -{ +int device_in_vector(std::vector<struct cras_iodev*> v, + struct cras_iodev* dev) { return std::find(v.begin(), v.end(), dev) != v.end(); } class IoDevTestSuite : public testing::Test { - protected: - virtual void SetUp() { - cras_iodev_list_reset(); - - cras_iodev_close_called = 0; - stream_list_get_ret = 0; - server_stream_create_called = 0; - server_stream_destroy_called = 0; - audio_thread_drain_stream_return = 0; - audio_thread_drain_stream_called = 0; - cras_tm_create_timer_called = 0; - cras_tm_cancel_timer_called = 0; - - audio_thread_disconnect_stream_called = 0; - audio_thread_disconnect_stream_stream = NULL; - audio_thread_is_dev_open_ret = 0; - stream_list_has_pinned_stream_ret.clear(); - - sample_rates_[0] = 44100; - sample_rates_[1] = 48000; - sample_rates_[2] = 0; - - channel_counts_[0] = 2; - channel_counts_[1] = 0; - - memset(&d1_, 0, sizeof(d1_)); - memset(&d2_, 0, sizeof(d2_)); - memset(&d3_, 0, sizeof(d3_)); - - memset(&node1, 0, sizeof(node1)); - memset(&node2, 0, sizeof(node2)); - memset(&node3, 0, sizeof(node3)); - - d1_.set_volume = NULL; - d1_.set_capture_gain = NULL; - d1_.set_capture_mute = NULL; - d1_.update_supported_formats = NULL; - d1_.update_active_node = update_active_node; - d1_.set_swap_mode_for_node = set_swap_mode_for_node; - d1_.format = NULL; - d1_.direction = CRAS_STREAM_OUTPUT; - d1_.info.idx = -999; - d1_.nodes = &node1; - d1_.active_node = &node1; - strcpy(d1_.info.name, "d1"); - d1_.supported_rates = sample_rates_; - d1_.supported_channel_counts = channel_counts_; - d2_.set_volume = NULL; - d2_.set_capture_gain = NULL; - d2_.set_capture_mute = NULL; - d2_.update_supported_formats = NULL; - d2_.update_active_node = update_active_node; - d2_.format = NULL; - d2_.direction = CRAS_STREAM_OUTPUT; - d2_.info.idx = -999; - d2_.nodes = &node2; - d2_.active_node = &node2; - strcpy(d2_.info.name, "d2"); - d2_.supported_rates = sample_rates_; - d2_.supported_channel_counts = channel_counts_; - d3_.set_volume = NULL; - d3_.set_capture_gain = NULL; - d3_.set_capture_mute = NULL; - d3_.update_supported_formats = NULL; - d3_.update_active_node = update_active_node; - d3_.format = NULL; - d3_.direction = CRAS_STREAM_OUTPUT; - d3_.info.idx = -999; - d3_.nodes = &node3; - d3_.active_node = &node3; - strcpy(d3_.info.name, "d3"); - d3_.supported_rates = sample_rates_; - d3_.supported_channel_counts = channel_counts_; - - loopback_input.set_volume = NULL; - loopback_input.set_capture_gain = NULL; - loopback_input.set_capture_mute = NULL; - loopback_input.update_supported_formats = NULL; - loopback_input.update_active_node = update_active_node; - loopback_input.format = NULL; - loopback_input.direction = CRAS_STREAM_INPUT; - loopback_input.info.idx = -999; - loopback_input.nodes = &node3; - loopback_input.active_node = &node3; - strcpy(loopback_input.info.name, "loopback_input"); - loopback_input.supported_rates = sample_rates_; - loopback_input.supported_channel_counts = channel_counts_; - - server_state_update_begin_return = &server_state_stub; - system_get_mute_return = false; - - /* Reset stub data. */ - add_stream_called = 0; - rm_stream_called = 0; - set_node_plugged_called = 0; - audio_thread_rm_open_dev_called = 0; - audio_thread_add_open_dev_called = 0; - audio_thread_set_active_dev_called = 0; - audio_thread_add_stream_called = 0; - update_active_node_called = 0; - cras_observer_add_called = 0; - cras_observer_remove_called = 0; - cras_observer_notify_nodes_called = 0; - cras_observer_notify_active_node_called = 0; - cras_observer_notify_output_node_volume_called = 0; - cras_observer_notify_node_left_right_swapped_called = 0; - cras_observer_notify_input_node_gain_called = 0; - cras_iodev_open_called = 0; - memset(cras_iodev_open_ret, 0, sizeof(cras_iodev_open_ret)); - set_mute_called = 0; - set_mute_dev_vector.clear(); - set_swap_mode_for_node_called = 0; - set_swap_mode_for_node_enable = 0; - cras_iodev_start_volume_ramp_called = 0; - audio_thread_dev_start_ramp_dev_vector.clear(); - audio_thread_dev_start_ramp_called = 0; - audio_thread_dev_start_ramp_req = - CRAS_IODEV_RAMP_REQUEST_UP_START_PLAYBACK; - for (int i = 0; i < 5 ; i++) - update_active_node_iodev_val[i] = NULL; - DL_APPEND(fake_sco_in_dev.nodes, &fake_sco_in_node); - DL_APPEND(fake_sco_out_dev.nodes, &fake_sco_out_node); - fake_sco_in_node.is_sco_pcm = 0; - fake_sco_out_node.is_sco_pcm = 0; - dummy_empty_iodev[0].state = CRAS_IODEV_STATE_CLOSE; - dummy_empty_iodev[0].update_active_node = update_active_node; - dummy_empty_iodev[1].state = CRAS_IODEV_STATE_CLOSE; - dummy_empty_iodev[1].update_active_node = update_active_node; - dummy_hotword_iodev.update_active_node = update_active_node; - } + protected: + virtual void SetUp() { + cras_iodev_list_reset(); + + cras_iodev_close_called = 0; + stream_list_get_ret = 0; + server_stream_create_called = 0; + server_stream_destroy_called = 0; + audio_thread_drain_stream_return = 0; + audio_thread_drain_stream_called = 0; + cras_tm_create_timer_called = 0; + cras_tm_cancel_timer_called = 0; + + audio_thread_disconnect_stream_called = 0; + audio_thread_disconnect_stream_stream = NULL; + audio_thread_is_dev_open_ret = 0; + stream_list_has_pinned_stream_ret.clear(); + + sample_rates_[0] = 44100; + sample_rates_[1] = 48000; + sample_rates_[2] = 0; + + channel_counts_[0] = 2; + channel_counts_[1] = 0; + + memset(&d1_, 0, sizeof(d1_)); + memset(&d2_, 0, sizeof(d2_)); + memset(&d3_, 0, sizeof(d3_)); + + memset(&node1, 0, sizeof(node1)); + memset(&node2, 0, sizeof(node2)); + memset(&node3, 0, sizeof(node3)); + + d1_.set_volume = NULL; + d1_.set_capture_gain = NULL; + d1_.set_capture_mute = NULL; + d1_.update_supported_formats = NULL; + d1_.update_active_node = update_active_node; + d1_.set_swap_mode_for_node = set_swap_mode_for_node; + d1_.format = NULL; + d1_.direction = CRAS_STREAM_OUTPUT; + d1_.info.idx = -999; + d1_.nodes = &node1; + d1_.active_node = &node1; + strcpy(d1_.info.name, "d1"); + d1_.supported_rates = sample_rates_; + d1_.supported_channel_counts = channel_counts_; + d2_.set_volume = NULL; + d2_.set_capture_gain = NULL; + d2_.set_capture_mute = NULL; + d2_.update_supported_formats = NULL; + d2_.update_active_node = update_active_node; + d2_.format = NULL; + d2_.direction = CRAS_STREAM_OUTPUT; + d2_.info.idx = -999; + d2_.nodes = &node2; + d2_.active_node = &node2; + strcpy(d2_.info.name, "d2"); + d2_.supported_rates = sample_rates_; + d2_.supported_channel_counts = channel_counts_; + d3_.set_volume = NULL; + d3_.set_capture_gain = NULL; + d3_.set_capture_mute = NULL; + d3_.update_supported_formats = NULL; + d3_.update_active_node = update_active_node; + d3_.format = NULL; + d3_.direction = CRAS_STREAM_OUTPUT; + d3_.info.idx = -999; + d3_.nodes = &node3; + d3_.active_node = &node3; + strcpy(d3_.info.name, "d3"); + d3_.supported_rates = sample_rates_; + d3_.supported_channel_counts = channel_counts_; + + loopback_input.set_volume = NULL; + loopback_input.set_capture_gain = NULL; + loopback_input.set_capture_mute = NULL; + loopback_input.update_supported_formats = NULL; + loopback_input.update_active_node = update_active_node; + loopback_input.format = NULL; + loopback_input.direction = CRAS_STREAM_INPUT; + loopback_input.info.idx = -999; + loopback_input.nodes = &node3; + loopback_input.active_node = &node3; + strcpy(loopback_input.info.name, "loopback_input"); + loopback_input.supported_rates = sample_rates_; + loopback_input.supported_channel_counts = channel_counts_; + + server_state_update_begin_return = &server_state_stub; + system_get_mute_return = false; + + /* Reset stub data. */ + add_stream_called = 0; + rm_stream_called = 0; + set_node_plugged_called = 0; + audio_thread_rm_open_dev_called = 0; + audio_thread_add_open_dev_called = 0; + audio_thread_set_active_dev_called = 0; + audio_thread_add_stream_called = 0; + update_active_node_called = 0; + cras_observer_add_called = 0; + cras_observer_remove_called = 0; + cras_observer_notify_nodes_called = 0; + cras_observer_notify_active_node_called = 0; + cras_observer_notify_output_node_volume_called = 0; + cras_observer_notify_node_left_right_swapped_called = 0; + cras_observer_notify_input_node_gain_called = 0; + cras_iodev_open_called = 0; + memset(cras_iodev_open_ret, 0, sizeof(cras_iodev_open_ret)); + set_mute_called = 0; + set_mute_dev_vector.clear(); + set_swap_mode_for_node_called = 0; + set_swap_mode_for_node_enable = 0; + cras_iodev_start_volume_ramp_called = 0; + audio_thread_dev_start_ramp_dev_vector.clear(); + audio_thread_dev_start_ramp_called = 0; + audio_thread_dev_start_ramp_req = CRAS_IODEV_RAMP_REQUEST_UP_START_PLAYBACK; + for (int i = 0; i < 5; i++) + update_active_node_iodev_val[i] = NULL; + DL_APPEND(fake_sco_in_dev.nodes, &fake_sco_in_node); + DL_APPEND(fake_sco_out_dev.nodes, &fake_sco_out_node); + fake_sco_in_node.is_sco_pcm = 0; + fake_sco_out_node.is_sco_pcm = 0; + dummy_empty_iodev[0].state = CRAS_IODEV_STATE_CLOSE; + dummy_empty_iodev[0].update_active_node = update_active_node; + dummy_empty_iodev[1].state = CRAS_IODEV_STATE_CLOSE; + dummy_empty_iodev[1].update_active_node = update_active_node; + dummy_hotword_iodev.update_active_node = update_active_node; + } - virtual void TearDown() { - cras_iodev_list_reset(); - } + virtual void TearDown() { cras_iodev_list_reset(); } - static void set_volume_1(struct cras_iodev* iodev) { - set_volume_1_called_++; - } + static void set_volume_1(struct cras_iodev* iodev) { set_volume_1_called_++; } - static void set_capture_gain_1(struct cras_iodev* iodev) { - set_capture_gain_1_called_++; - } + static void set_capture_gain_1(struct cras_iodev* iodev) { + set_capture_gain_1_called_++; + } - static void set_capture_mute_1(struct cras_iodev* iodev) { - set_capture_mute_1_called_++; - } + static void set_capture_mute_1(struct cras_iodev* iodev) { + set_capture_mute_1_called_++; + } - static void update_active_node(struct cras_iodev *iodev, - unsigned node_idx, - unsigned dev_enabled) { - int i = update_active_node_called++ % 5; - update_active_node_iodev_val[i] = iodev; - update_active_node_node_idx_val[i] = node_idx; - update_active_node_dev_enabled_val[i] = dev_enabled; - } + static void update_active_node(struct cras_iodev* iodev, + unsigned node_idx, + unsigned dev_enabled) { + int i = update_active_node_called++ % 5; + update_active_node_iodev_val[i] = iodev; + update_active_node_node_idx_val[i] = node_idx; + update_active_node_dev_enabled_val[i] = dev_enabled; + } - static int set_swap_mode_for_node(struct cras_iodev *iodev, - struct cras_ionode *node, - int enable) - { - set_swap_mode_for_node_called++; - set_swap_mode_for_node_enable = enable; - return 0; - } + static int set_swap_mode_for_node(struct cras_iodev* iodev, + struct cras_ionode* node, + int enable) { + set_swap_mode_for_node_called++; + set_swap_mode_for_node_enable = enable; + return 0; + } - struct cras_iodev d1_; - struct cras_iodev d2_; - struct cras_iodev d3_; - size_t sample_rates_[3]; - size_t channel_counts_[2]; - static int set_volume_1_called_; - static int set_capture_gain_1_called_; - static int set_capture_mute_1_called_; - struct cras_ionode node1, node2, node3; + struct cras_iodev d1_; + struct cras_iodev d2_; + struct cras_iodev d3_; + size_t sample_rates_[3]; + size_t channel_counts_[2]; + static int set_volume_1_called_; + static int set_capture_gain_1_called_; + static int set_capture_mute_1_called_; + struct cras_ionode node1, node2, node3; }; int IoDevTestSuite::set_volume_1_called_; @@ -296,7 +290,7 @@ TEST_F(IoDevTestSuite, InitSetup) { * and resume call of all iodevs. */ TEST_F(IoDevTestSuite, SetSuspendResume) { struct cras_rstream rstream, rstream2, rstream3; - struct cras_rstream *stream_list = NULL; + struct cras_rstream* stream_list = NULL; int rc; memset(&rstream, 0, sizeof(rstream)); @@ -311,7 +305,7 @@ TEST_F(IoDevTestSuite, SetSuspendResume) { audio_thread_add_open_dev_called = 0; cras_iodev_list_add_active_node(CRAS_STREAM_OUTPUT, - cras_make_node_id(d1_.info.idx, 1)); + cras_make_node_id(d1_.info.idx, 1)); DL_APPEND(stream_list, &rstream); stream_add_cb(&rstream); EXPECT_EQ(1, audio_thread_add_stream_called); @@ -357,7 +351,7 @@ TEST_F(IoDevTestSuite, SetSuspendResume) { TEST_F(IoDevTestSuite, InitDevFailShouldEnableFallback) { int rc; struct cras_rstream rstream; - struct cras_rstream *stream_list = NULL; + struct cras_rstream* stream_list = NULL; memset(&rstream, 0, sizeof(rstream)); cras_iodev_list_init(); @@ -367,7 +361,7 @@ TEST_F(IoDevTestSuite, InitDevFailShouldEnableFallback) { ASSERT_EQ(0, rc); cras_iodev_list_select_node(CRAS_STREAM_OUTPUT, - cras_make_node_id(d1_.info.idx, 0)); + cras_make_node_id(d1_.info.idx, 0)); cras_iodev_open_ret[0] = -5; cras_iodev_open_ret[1] = 0; @@ -384,7 +378,7 @@ TEST_F(IoDevTestSuite, InitDevFailShouldEnableFallback) { TEST_F(IoDevTestSuite, InitDevWithEchoRef) { int rc; struct cras_rstream rstream; - struct cras_rstream *stream_list = NULL; + struct cras_rstream* stream_list = NULL; memset(&rstream, 0, sizeof(rstream)); cras_iodev_list_init(); @@ -400,7 +394,7 @@ TEST_F(IoDevTestSuite, InitDevWithEchoRef) { ASSERT_EQ(0, rc); cras_iodev_list_select_node(CRAS_STREAM_OUTPUT, - cras_make_node_id(d1_.info.idx, 0)); + cras_make_node_id(d1_.info.idx, 0)); /* No close call happened, because no stream exists. */ EXPECT_EQ(0, cras_iodev_close_called); @@ -430,7 +424,7 @@ TEST_F(IoDevTestSuite, InitDevWithEchoRef) { TEST_F(IoDevTestSuite, SelectNodeOpenFailShouldScheduleRetry) { struct cras_rstream rstream; - struct cras_rstream *stream_list = NULL; + struct cras_rstream* stream_list = NULL; int rc; memset(&rstream, 0, sizeof(rstream)); @@ -445,7 +439,7 @@ TEST_F(IoDevTestSuite, SelectNodeOpenFailShouldScheduleRetry) { ASSERT_EQ(0, rc); cras_iodev_list_select_node(CRAS_STREAM_OUTPUT, - cras_make_node_id(d1_.info.idx, 1)); + cras_make_node_id(d1_.info.idx, 1)); DL_APPEND(stream_list, &rstream); stream_list_get_ret = stream_list; stream_add_cb(&rstream); @@ -454,7 +448,7 @@ TEST_F(IoDevTestSuite, SelectNodeOpenFailShouldScheduleRetry) { cras_iodev_close_called = 0; cras_iodev_open_called = 0; cras_iodev_list_select_node(CRAS_STREAM_OUTPUT, - cras_make_node_id(d2_.info.idx, 1)); + cras_make_node_id(d2_.info.idx, 1)); EXPECT_EQ(2, cras_iodev_close_called); EXPECT_EQ(2, cras_iodev_open_called); EXPECT_EQ(0, cras_tm_create_timer_called); @@ -467,14 +461,14 @@ TEST_F(IoDevTestSuite, SelectNodeOpenFailShouldScheduleRetry) { cras_iodev_open_ret[2] = 0; cras_tm_timer_cb = NULL; cras_iodev_list_select_node(CRAS_STREAM_OUTPUT, - cras_make_node_id(d1_.info.idx, 1)); + cras_make_node_id(d1_.info.idx, 1)); EXPECT_EQ(3, cras_iodev_close_called); EXPECT_EQ(&d2_, cras_iodev_close_dev); EXPECT_EQ(2, cras_iodev_open_called); EXPECT_EQ(0, cras_tm_cancel_timer_called); /* Assert a timer is scheduled to retry open. */ - EXPECT_NE((void *)NULL, cras_tm_timer_cb); + EXPECT_NE((void*)NULL, cras_tm_timer_cb); EXPECT_EQ(1, cras_tm_create_timer_called); audio_thread_add_stream_called = 0; @@ -493,16 +487,16 @@ TEST_F(IoDevTestSuite, SelectNodeOpenFailShouldScheduleRetry) { cras_iodev_open_ret[1] = -5; cras_iodev_open_ret[2] = 0; cras_iodev_list_select_node(CRAS_STREAM_OUTPUT, - cras_make_node_id(d2_.info.idx, 1)); + cras_make_node_id(d2_.info.idx, 1)); EXPECT_EQ(1, cras_iodev_close_called); EXPECT_EQ(&d1_, cras_iodev_close_dev); EXPECT_EQ(2, cras_tm_create_timer_called); - EXPECT_NE((void *)NULL, cras_tm_timer_cb); + EXPECT_NE((void*)NULL, cras_tm_timer_cb); /* Select to another iodev should cancel the timer. */ memset(cras_iodev_open_ret, 0, sizeof(cras_iodev_open_ret)); cras_iodev_list_select_node(CRAS_STREAM_OUTPUT, - cras_make_node_id(d2_.info.idx, 1)); + cras_make_node_id(d2_.info.idx, 1)); EXPECT_EQ(1, cras_tm_cancel_timer_called); cras_iodev_list_deinit(); } @@ -510,7 +504,7 @@ TEST_F(IoDevTestSuite, SelectNodeOpenFailShouldScheduleRetry) { TEST_F(IoDevTestSuite, InitDevFailShouldScheduleRetry) { int rc; struct cras_rstream rstream; - struct cras_rstream *stream_list = NULL; + struct cras_rstream* stream_list = NULL; memset(&rstream, 0, sizeof(rstream)); cras_iodev_list_init(); @@ -520,7 +514,7 @@ TEST_F(IoDevTestSuite, InitDevFailShouldScheduleRetry) { ASSERT_EQ(0, rc); cras_iodev_list_select_node(CRAS_STREAM_OUTPUT, - cras_make_node_id(d1_.info.idx, 0)); + cras_make_node_id(d1_.info.idx, 0)); update_active_node_called = 0; cras_iodev_open_ret[0] = -5; @@ -536,7 +530,7 @@ TEST_F(IoDevTestSuite, InitDevFailShouldScheduleRetry) { EXPECT_EQ(&dummy_empty_iodev[CRAS_STREAM_OUTPUT], audio_thread_add_stream_dev); - EXPECT_NE((void *)NULL, cras_tm_timer_cb); + EXPECT_NE((void*)NULL, cras_tm_timer_cb); EXPECT_EQ(1, cras_tm_create_timer_called); /* If retry still fail, won't schedule more retry. */ @@ -548,7 +542,7 @@ TEST_F(IoDevTestSuite, InitDevFailShouldScheduleRetry) { cras_tm_timer_cb = NULL; cras_iodev_open_ret[3] = -5; stream_add_cb(&rstream); - EXPECT_NE((void *)NULL, cras_tm_timer_cb); + EXPECT_NE((void*)NULL, cras_tm_timer_cb); EXPECT_EQ(2, cras_tm_create_timer_called); cras_iodev_list_rm_output(&d1_); @@ -559,7 +553,7 @@ TEST_F(IoDevTestSuite, InitDevFailShouldScheduleRetry) { TEST_F(IoDevTestSuite, PinnedStreamInitFailShouldScheduleRetry) { int rc; struct cras_rstream rstream; - struct cras_rstream *stream_list = NULL; + struct cras_rstream* stream_list = NULL; memset(&rstream, 0, sizeof(rstream)); cras_iodev_list_init(); @@ -581,7 +575,7 @@ TEST_F(IoDevTestSuite, PinnedStreamInitFailShouldScheduleRetry) { EXPECT_EQ(1, cras_iodev_open_called); EXPECT_EQ(0, audio_thread_add_stream_called); - EXPECT_NE((void *)NULL, cras_tm_timer_cb); + EXPECT_NE((void*)NULL, cras_tm_timer_cb); EXPECT_EQ(1, cras_tm_create_timer_called); cras_tm_timer_cb(NULL, cras_tm_timer_cb_data); @@ -592,15 +586,13 @@ TEST_F(IoDevTestSuite, PinnedStreamInitFailShouldScheduleRetry) { cras_iodev_list_deinit(); } -static void device_enabled_cb(struct cras_iodev *dev, void *cb_data) -{ +static void device_enabled_cb(struct cras_iodev* dev, void* cb_data) { device_enabled_dev = dev; device_enabled_count++; device_enabled_cb_data = cb_data; } -static void device_disabled_cb(struct cras_iodev *dev, void *cb_data) -{ +static void device_disabled_cb(struct cras_iodev* dev, void* cb_data) { device_disabled_dev = dev; device_disabled_count++; device_disabled_cb_data = cb_data; @@ -632,10 +624,10 @@ TEST_F(IoDevTestSuite, SelectNode) { device_disabled_count = 0; EXPECT_EQ(0, cras_iodev_list_set_device_enabled_callback( - device_enabled_cb, device_disabled_cb, (void *)0xABCD)); + device_enabled_cb, device_disabled_cb, (void*)0xABCD)); cras_iodev_list_add_active_node(CRAS_STREAM_OUTPUT, - cras_make_node_id(d1_.info.idx, 1)); + cras_make_node_id(d1_.info.idx, 1)); EXPECT_EQ(1, device_enabled_count); EXPECT_EQ(1, cras_observer_notify_active_node_called); @@ -660,7 +652,7 @@ TEST_F(IoDevTestSuite, SelectNode) { EXPECT_EQ(1, audio_thread_add_open_dev_called); cras_iodev_list_select_node(CRAS_STREAM_OUTPUT, - cras_make_node_id(d2_.info.idx, 2)); + cras_make_node_id(d2_.info.idx, 2)); // Additional enabled devices: fallback device, d2_. EXPECT_EQ(3, device_enabled_count); @@ -701,11 +693,11 @@ TEST_F(IoDevTestSuite, SelectPreviouslyEnabledNode) { device_disabled_count = 0; EXPECT_EQ(0, cras_iodev_list_set_device_enabled_callback( - device_enabled_cb, device_disabled_cb, (void *)0xABCD)); + device_enabled_cb, device_disabled_cb, (void*)0xABCD)); // Add an active node. cras_iodev_list_add_active_node(CRAS_STREAM_OUTPUT, - cras_make_node_id(d1_.info.idx, 1)); + cras_make_node_id(d1_.info.idx, 1)); EXPECT_EQ(1, device_enabled_count); EXPECT_EQ(1, cras_observer_notify_active_node_called); @@ -724,7 +716,7 @@ TEST_F(IoDevTestSuite, SelectPreviouslyEnabledNode) { // Add a second active node. cras_iodev_list_add_active_node(CRAS_STREAM_OUTPUT, - cras_make_node_id(d2_.info.idx, 2)); + cras_make_node_id(d2_.info.idx, 2)); EXPECT_EQ(2, device_enabled_count); EXPECT_EQ(1, device_disabled_count); @@ -738,7 +730,7 @@ TEST_F(IoDevTestSuite, SelectPreviouslyEnabledNode) { // Select the second added active node - the initially added node should get // disabled. cras_iodev_list_select_node(CRAS_STREAM_OUTPUT, - cras_make_node_id(d2_.info.idx, 2)); + cras_make_node_id(d2_.info.idx, 2)); EXPECT_EQ(2, device_enabled_count); EXPECT_EQ(2, device_disabled_count); @@ -769,7 +761,7 @@ TEST_F(IoDevTestSuite, UpdateActiveNode) { ASSERT_EQ(0, rc); cras_iodev_list_select_node(CRAS_STREAM_OUTPUT, - cras_make_node_id(d2_.info.idx, 1)); + cras_make_node_id(d2_.info.idx, 1)); EXPECT_EQ(2, update_active_node_called); EXPECT_EQ(&d2_, update_active_node_iodev_val[0]); @@ -780,7 +772,7 @@ TEST_F(IoDevTestSuite, UpdateActiveNode) { * called for update_active_node when d2_ disabled. */ d2_.active_node->idx = 2; cras_iodev_list_select_node(CRAS_STREAM_OUTPUT, - cras_make_node_id(d1_.info.idx, 0)); + cras_make_node_id(d1_.info.idx, 0)); EXPECT_EQ(5, update_active_node_called); EXPECT_EQ(&d2_, update_active_node_iodev_val[2]); @@ -802,12 +794,11 @@ TEST_F(IoDevTestSuite, SelectNonExistingNode) { ASSERT_EQ(0, rc); cras_iodev_list_select_node(CRAS_STREAM_OUTPUT, - cras_make_node_id(d1_.info.idx, 0)); + cras_make_node_id(d1_.info.idx, 0)); EXPECT_EQ(1, d1_.is_enabled); /* Select non-existing node should disable all devices. */ - cras_iodev_list_select_node(CRAS_STREAM_OUTPUT, - cras_make_node_id(2, 1)); + cras_iodev_list_select_node(CRAS_STREAM_OUTPUT, cras_make_node_id(2, 1)); EXPECT_EQ(0, d1_.is_enabled); EXPECT_EQ(2, cras_observer_notify_active_node_called); cras_iodev_list_deinit(); @@ -826,7 +817,7 @@ TEST_F(IoDevTestSuite, AddWrongDirection) { // Test adding/removing an iodev to the list. TEST_F(IoDevTestSuite, AddRemoveOutput) { - struct cras_iodev_info *dev_info; + struct cras_iodev_info* dev_info; int rc; rc = cras_iodev_list_add_output(&d1_); @@ -884,10 +875,10 @@ TEST_F(IoDevTestSuite, OutputMuteChangedToMute) { // d1_ and d2_ should set mute state through audio_thread_dev_start_ramp // because they are both open. EXPECT_EQ(2, audio_thread_dev_start_ramp_called); - ASSERT_TRUE(dev_idx_in_vector(audio_thread_dev_start_ramp_dev_vector, - d2_.info.idx)); - ASSERT_TRUE(dev_idx_in_vector(audio_thread_dev_start_ramp_dev_vector, - d1_.info.idx)); + ASSERT_TRUE( + dev_idx_in_vector(audio_thread_dev_start_ramp_dev_vector, d2_.info.idx)); + ASSERT_TRUE( + dev_idx_in_vector(audio_thread_dev_start_ramp_dev_vector, d1_.info.idx)); EXPECT_EQ(CRAS_IODEV_RAMP_REQUEST_DOWN_MUTE, audio_thread_dev_start_ramp_req); // d3_ should set mute state right away without calling ramp @@ -921,10 +912,9 @@ TEST_F(IoDevTestSuite, OutputMuteChangedToUnmute) { // d1_ should set mute state through audio_thread_dev_start_ramp. EXPECT_EQ(1, audio_thread_dev_start_ramp_called); - ASSERT_TRUE(dev_idx_in_vector(audio_thread_dev_start_ramp_dev_vector, - d1_.info.idx)); - EXPECT_EQ(CRAS_IODEV_RAMP_REQUEST_UP_UNMUTE, - audio_thread_dev_start_ramp_req); + ASSERT_TRUE( + dev_idx_in_vector(audio_thread_dev_start_ramp_dev_vector, d1_.info.idx)); + EXPECT_EQ(CRAS_IODEV_RAMP_REQUEST_UP_UNMUTE, audio_thread_dev_start_ramp_req); // d2_ and d3_ should set mute state right away because they both // are closed. @@ -944,12 +934,12 @@ TEST_F(IoDevTestSuite, EnableDisableDevice) { EXPECT_EQ(0, cras_iodev_list_add_output(&d1_)); EXPECT_EQ(0, cras_iodev_list_set_device_enabled_callback( - device_enabled_cb, device_disabled_cb, (void *)0xABCD)); + device_enabled_cb, device_disabled_cb, (void*)0xABCD)); // Enable a device. cras_iodev_list_enable_dev(&d1_); EXPECT_EQ(&d1_, device_enabled_dev); - EXPECT_EQ((void *)0xABCD, device_enabled_cb_data); + EXPECT_EQ((void*)0xABCD, device_enabled_cb_data); EXPECT_EQ(1, device_enabled_count); EXPECT_EQ(&d1_, cras_iodev_list_get_first_enabled_iodev(CRAS_STREAM_OUTPUT)); @@ -957,10 +947,10 @@ TEST_F(IoDevTestSuite, EnableDisableDevice) { cras_iodev_list_disable_dev(&d1_, false); EXPECT_EQ(&d1_, device_disabled_dev); EXPECT_EQ(1, device_disabled_count); - EXPECT_EQ((void *)0xABCD, device_disabled_cb_data); + EXPECT_EQ((void*)0xABCD, device_disabled_cb_data); EXPECT_EQ(0, cras_iodev_list_set_device_enabled_callback( - device_enabled_cb, device_disabled_cb, (void *)0xCDEF)); + device_enabled_cb, device_disabled_cb, (void*)0xCDEF)); EXPECT_EQ(2, cras_observer_notify_active_node_called); EXPECT_EQ(0, cras_iodev_list_set_device_enabled_callback(NULL, NULL, NULL)); @@ -968,7 +958,7 @@ TEST_F(IoDevTestSuite, EnableDisableDevice) { // Test adding/removing an input dev to the list. TEST_F(IoDevTestSuite, AddRemoveInput) { - struct cras_iodev_info *dev_info; + struct cras_iodev_info* dev_info; int rc, i; uint32_t found_mask; @@ -1054,7 +1044,7 @@ TEST_F(IoDevTestSuite, AddRemoveInputNoSem) { // Test removing the last input. TEST_F(IoDevTestSuite, RemoveLastInput) { - struct cras_iodev_info *dev_info; + struct cras_iodev_info* dev_info; int rc; d1_.direction = CRAS_STREAM_INPUT; @@ -1111,7 +1101,6 @@ TEST_F(IoDevTestSuite, NodesChangedNotification) { // Test callback function for left right swap mode is set and called. TEST_F(IoDevTestSuite, NodesLeftRightSwappedCallback) { - struct cras_iodev iodev; struct cras_ionode ionode; memset(&iodev, 0, sizeof(iodev)); @@ -1123,7 +1112,6 @@ TEST_F(IoDevTestSuite, NodesLeftRightSwappedCallback) { // Test callback function for volume and gain are set and called. TEST_F(IoDevTestSuite, VolumeGainCallback) { - struct cras_iodev iodev; struct cras_ionode ionode; memset(&iodev, 0, sizeof(iodev)); @@ -1221,8 +1209,7 @@ TEST_F(IoDevTestSuite, SetNodeVolumeCaptureGain) { cras_iodev_list_deinit(); } -TEST_F(IoDevTestSuite, SetNodeSwapLeftRight) -{ +TEST_F(IoDevTestSuite, SetNodeSwapLeftRight) { int rc; cras_iodev_list_init(); @@ -1268,7 +1255,7 @@ TEST_F(IoDevTestSuite, AddActiveNode) { audio_thread_add_open_dev_called = 0; cras_iodev_list_add_active_node(CRAS_STREAM_OUTPUT, - cras_make_node_id(d3_.info.idx, 1)); + cras_make_node_id(d3_.info.idx, 1)); ASSERT_EQ(audio_thread_add_open_dev_called, 0); ASSERT_EQ(audio_thread_rm_open_dev_called, 0); @@ -1316,7 +1303,7 @@ TEST_F(IoDevTestSuite, DrainTimerCancel) { audio_thread_add_open_dev_called = 0; cras_iodev_list_add_active_node(CRAS_STREAM_OUTPUT, - cras_make_node_id(d1_.info.idx, 1)); + cras_make_node_id(d1_.info.idx, 1)); EXPECT_EQ(0, audio_thread_add_open_dev_called); EXPECT_EQ(0, audio_thread_rm_open_dev_called); @@ -1388,7 +1375,7 @@ TEST_F(IoDevTestSuite, AddRemovePinnedStream) { d1_.info.idx = 1; EXPECT_EQ(0, cras_iodev_list_add_output(&d1_)); cras_iodev_list_select_node(CRAS_STREAM_OUTPUT, - cras_make_node_id(d1_.info.idx, 0)); + cras_make_node_id(d1_.info.idx, 0)); EXPECT_EQ(2, update_active_node_called); EXPECT_EQ(&d1_, update_active_node_iodev_val[0]); @@ -1415,7 +1402,7 @@ TEST_F(IoDevTestSuite, AddRemovePinnedStream) { update_active_node_called = 0; stream_list_has_pinned_stream_ret[d1_.info.idx] = 1; cras_iodev_list_select_node(CRAS_STREAM_OUTPUT, - cras_make_node_id(d2_.info.idx, 0)); + cras_make_node_id(d2_.info.idx, 0)); EXPECT_EQ(1, audio_thread_add_stream_called); EXPECT_EQ(2, update_active_node_called); // Unselect d1_ and select to d2_ @@ -1472,7 +1459,8 @@ TEST_F(IoDevTestSuite, SuspendResumePinnedStream) { // Device state enters no_stream after stream is disconnected. d1_.state = CRAS_IODEV_STATE_NO_STREAM_RUN; - // Device has no pinned stream now. But this pinned stream remains in stream_list. + // Device has no pinned stream now. But this pinned stream remains in + // stream_list. stream_list_has_pinned_stream_ret[d1_.info.idx] = 0; // Suspend @@ -1502,7 +1490,7 @@ TEST_F(IoDevTestSuite, SuspendResumePinnedStream) { TEST_F(IoDevTestSuite, HotwordStreamsAddedThenSuspendResume) { struct cras_rstream rstream; - struct cras_rstream *stream_list = NULL; + struct cras_rstream* stream_list = NULL; cras_iodev_list_init(); node1.type = CRAS_NODE_TYPE_HOTWORD; @@ -1547,7 +1535,7 @@ TEST_F(IoDevTestSuite, HotwordStreamsAddedThenSuspendResume) { TEST_F(IoDevTestSuite, HotwordStreamsAddedAfterSuspend) { struct cras_rstream rstream; - struct cras_rstream *stream_list = NULL; + struct cras_rstream* stream_list = NULL; cras_iodev_list_init(); node1.type = CRAS_NODE_TYPE_HOTWORD; @@ -1596,16 +1584,16 @@ TEST_F(IoDevTestSuite, GetSCOPCMIodevs) { cras_iodev_list_add_output(&fake_sco_out_dev); EXPECT_EQ(&fake_sco_in_dev, - cras_iodev_list_get_sco_pcm_iodev(CRAS_STREAM_INPUT)); + cras_iodev_list_get_sco_pcm_iodev(CRAS_STREAM_INPUT)); EXPECT_EQ(&fake_sco_out_dev, - cras_iodev_list_get_sco_pcm_iodev(CRAS_STREAM_OUTPUT)); + cras_iodev_list_get_sco_pcm_iodev(CRAS_STREAM_OUTPUT)); cras_iodev_list_deinit(); } } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } @@ -1614,93 +1602,85 @@ extern "C" { // Stubs -struct cras_server_state *cras_system_state_update_begin() { +struct cras_server_state* cras_system_state_update_begin() { return server_state_update_begin_return; } -void cras_system_state_update_complete() { -} +void cras_system_state_update_complete() {} int cras_system_get_mute() { return system_get_mute_return; } -struct audio_thread *audio_thread_create() { +struct audio_thread* audio_thread_create() { return &thread; } -int audio_thread_start(struct audio_thread *thread) { +int audio_thread_start(struct audio_thread* thread) { return 0; } -void audio_thread_destroy(struct audio_thread *thread) { -} +void audio_thread_destroy(struct audio_thread* thread) {} -int audio_thread_set_active_dev(struct audio_thread *thread, - struct cras_iodev *dev) { +int audio_thread_set_active_dev(struct audio_thread* thread, + struct cras_iodev* dev) { audio_thread_set_active_dev_called++; audio_thread_set_active_dev_val = dev; return 0; } -void audio_thread_remove_streams(struct audio_thread *thread, - enum CRAS_STREAM_DIRECTION dir) { +void audio_thread_remove_streams(struct audio_thread* thread, + enum CRAS_STREAM_DIRECTION dir) { audio_thread_remove_streams_active_dev = audio_thread_set_active_dev_val; } -int audio_thread_add_open_dev(struct audio_thread *thread, - struct cras_iodev *dev) -{ +int audio_thread_add_open_dev(struct audio_thread* thread, + struct cras_iodev* dev) { audio_thread_add_open_dev_dev = dev; audio_thread_add_open_dev_called++; return 0; } -int audio_thread_rm_open_dev(struct audio_thread *thread, +int audio_thread_rm_open_dev(struct audio_thread* thread, enum CRAS_STREAM_DIRECTION dir, - unsigned int dev_idx) -{ + unsigned int dev_idx) { audio_thread_rm_open_dev_called++; return 0; } -int audio_thread_is_dev_open(struct audio_thread *thread, - struct cras_iodev *dev) -{ +int audio_thread_is_dev_open(struct audio_thread* thread, + struct cras_iodev* dev) { return audio_thread_is_dev_open_ret; } -int audio_thread_add_stream(struct audio_thread *thread, - struct cras_rstream *stream, - struct cras_iodev **devs, - unsigned int num_devs) -{ +int audio_thread_add_stream(struct audio_thread* thread, + struct cras_rstream* stream, + struct cras_iodev** devs, + unsigned int num_devs) { audio_thread_add_stream_called++; audio_thread_add_stream_stream = stream; audio_thread_add_stream_dev = (num_devs ? devs[0] : NULL); return 0; } -int audio_thread_disconnect_stream(struct audio_thread *thread, - struct cras_rstream *stream, - struct cras_iodev *iodev) -{ +int audio_thread_disconnect_stream(struct audio_thread* thread, + struct cras_rstream* stream, + struct cras_iodev* iodev) { audio_thread_disconnect_stream_called++; audio_thread_disconnect_stream_stream = stream; audio_thread_disconnect_stream_dev = iodev; return 0; } -int audio_thread_drain_stream(struct audio_thread *thread, - struct cras_rstream *stream) -{ - audio_thread_drain_stream_called++; - return audio_thread_drain_stream_return; +int audio_thread_drain_stream(struct audio_thread* thread, + struct cras_rstream* stream) { + audio_thread_drain_stream_called++; + return audio_thread_drain_stream_return; } -struct cras_iodev *empty_iodev_create(enum CRAS_STREAM_DIRECTION direction, +struct cras_iodev* empty_iodev_create(enum CRAS_STREAM_DIRECTION direction, enum CRAS_NODE_TYPE node_type) { - struct cras_iodev *dev; + struct cras_iodev* dev; if (node_type == CRAS_NODE_TYPE_HOTWORD) { dev = &dummy_hotword_iodev; } else { @@ -1708,55 +1688,53 @@ struct cras_iodev *empty_iodev_create(enum CRAS_STREAM_DIRECTION direction, } dev->direction = direction; if (dev->active_node == NULL) { - struct cras_ionode *node = (struct cras_ionode *)calloc(1, sizeof(*node)); + struct cras_ionode* node = (struct cras_ionode*)calloc(1, sizeof(*node)); node->type = node_type; dev->active_node = node; } return dev; } -void empty_iodev_destroy(struct cras_iodev *iodev) { +void empty_iodev_destroy(struct cras_iodev* iodev) { if (iodev->active_node) { free(iodev->active_node); iodev->active_node = NULL; } } -struct cras_iodev *test_iodev_create(enum CRAS_STREAM_DIRECTION direction, +struct cras_iodev* test_iodev_create(enum CRAS_STREAM_DIRECTION direction, enum TEST_IODEV_TYPE type) { return NULL; } -void test_iodev_command(struct cras_iodev *iodev, +void test_iodev_command(struct cras_iodev* iodev, enum CRAS_TEST_IODEV_CMD command, unsigned int data_len, - const uint8_t *data) { -} + const uint8_t* data) {} -struct cras_iodev *loopback_iodev_create(enum CRAS_LOOPBACK_TYPE type) { +struct cras_iodev* loopback_iodev_create(enum CRAS_LOOPBACK_TYPE type) { return &loopback_input; } -void loopback_iodev_destroy(struct cras_iodev *iodev) { -} +void loopback_iodev_destroy(struct cras_iodev* iodev) {} -int cras_iodev_open(struct cras_iodev *iodev, unsigned int cb_level, - const struct cras_audio_format *fmt) -{ +int cras_iodev_open(struct cras_iodev* iodev, + unsigned int cb_level, + const struct cras_audio_format* fmt) { if (cras_iodev_open_ret[cras_iodev_open_called] == 0) iodev->state = CRAS_IODEV_STATE_OPEN; return cras_iodev_open_ret[cras_iodev_open_called++]; } -int cras_iodev_close(struct cras_iodev *iodev) { +int cras_iodev_close(struct cras_iodev* iodev) { iodev->state = CRAS_IODEV_STATE_CLOSE; cras_iodev_close_called++; cras_iodev_close_dev = iodev; return 0; } -int cras_iodev_set_format(struct cras_iodev *iodev, - const struct cras_audio_format *fmt) { +int cras_iodev_set_format(struct cras_iodev* iodev, + const struct cras_audio_format* fmt) { return 0; } @@ -1766,106 +1744,93 @@ int cras_iodev_set_mute(struct cras_iodev* iodev) { return 0; } -void cras_iodev_set_node_plugged(struct cras_ionode *node, int plugged) -{ +void cras_iodev_set_node_plugged(struct cras_ionode* node, int plugged) { set_node_plugged_called++; } -int cras_iodev_start_volume_ramp(struct cras_iodev *odev, +int cras_iodev_start_volume_ramp(struct cras_iodev* odev, unsigned int old_volume, - unsigned int new_volume) -{ + unsigned int new_volume) { cras_iodev_start_volume_ramp_called++; return 0; } -bool stream_list_has_pinned_stream(struct stream_list *list, - unsigned int dev_idx) -{ +bool stream_list_has_pinned_stream(struct stream_list* list, + unsigned int dev_idx) { return stream_list_has_pinned_stream_ret[dev_idx]; } -struct stream_list *stream_list_create(stream_callback *add_cb, - stream_callback *rm_cb, - stream_create_func *create_cb, - stream_destroy_func *destroy_cb, - struct cras_tm *timer_manager) { +struct stream_list* stream_list_create(stream_callback* add_cb, + stream_callback* rm_cb, + stream_create_func* create_cb, + stream_destroy_func* destroy_cb, + struct cras_tm* timer_manager) { stream_add_cb = add_cb; stream_rm_cb = rm_cb; - return reinterpret_cast<stream_list *>(0xf00); + return reinterpret_cast<stream_list*>(0xf00); } -void stream_list_destroy(struct stream_list *list) { -} +void stream_list_destroy(struct stream_list* list) {} -struct cras_rstream *stream_list_get(struct stream_list *list) { +struct cras_rstream* stream_list_get(struct stream_list* list) { return stream_list_get_ret; } -void server_stream_create(struct stream_list *stream_list, - unsigned int dev_idx) -{ +void server_stream_create(struct stream_list* stream_list, + unsigned int dev_idx) { server_stream_create_called++; } -void server_stream_destroy(struct stream_list *stream_list, - unsigned int dev_idx) -{ +void server_stream_destroy(struct stream_list* stream_list, + unsigned int dev_idx) { server_stream_destroy_called++; } -int cras_rstream_create(struct cras_rstream_config *config, - struct cras_rstream **stream_out) { +int cras_rstream_create(struct cras_rstream_config* config, + struct cras_rstream** stream_out) { return 0; } -void cras_rstream_destroy(struct cras_rstream *rstream) { -} +void cras_rstream_destroy(struct cras_rstream* rstream) {} -struct cras_tm *cras_system_state_get_tm() { +struct cras_tm* cras_system_state_get_tm() { return NULL; } -struct cras_timer *cras_tm_create_timer( - struct cras_tm *tm, - unsigned int ms, - void (*cb)(struct cras_timer *t, void *data), - void *cb_data) { +struct cras_timer* cras_tm_create_timer(struct cras_tm* tm, + unsigned int ms, + void (*cb)(struct cras_timer* t, + void* data), + void* cb_data) { cras_tm_timer_cb = cb; cras_tm_timer_cb_data = cb_data; cras_tm_create_timer_called++; - return reinterpret_cast<struct cras_timer *>(0x404); + return reinterpret_cast<struct cras_timer*>(0x404); } -void cras_tm_cancel_timer(struct cras_tm *tm, struct cras_timer *t) { +void cras_tm_cancel_timer(struct cras_tm* tm, struct cras_timer* t) { cras_tm_cancel_timer_called++; } -void cras_fmt_conv_destroy(struct cras_fmt_conv *conv) -{ -} +void cras_fmt_conv_destroy(struct cras_fmt_conv* conv) {} -struct cras_fmt_conv *cras_channel_remix_conv_create( - unsigned int num_channels, const float *coefficient) -{ +struct cras_fmt_conv* cras_channel_remix_conv_create(unsigned int num_channels, + const float* coefficient) { return NULL; } -void cras_channel_remix_convert(struct cras_fmt_conv *conv, - uint8_t *in_buf, size_t frames) -{ -} +void cras_channel_remix_convert(struct cras_fmt_conv* conv, + uint8_t* in_buf, + size_t frames) {} -struct cras_observer_client *cras_observer_add( - const struct cras_observer_ops *ops, - void *context) -{ - observer_ops = (struct cras_observer_ops *)calloc(1, sizeof(*ops)); +struct cras_observer_client* cras_observer_add( + const struct cras_observer_ops* ops, + void* context) { + observer_ops = (struct cras_observer_ops*)calloc(1, sizeof(*ops)); memcpy(observer_ops, ops, sizeof(*ops)); cras_observer_add_called++; - return reinterpret_cast<struct cras_observer_client *>(0x55); + return reinterpret_cast<struct cras_observer_client*>(0x55); } -void cras_observer_remove(struct cras_observer_client *client) -{ +void cras_observer_remove(struct cras_observer_client* client) { if (observer_ops) free(observer_ops); cras_observer_remove_called++; @@ -1876,33 +1841,28 @@ void cras_observer_notify_nodes(void) { } void cras_observer_notify_active_node(enum CRAS_STREAM_DIRECTION direction, - cras_node_id_t node_id) -{ + cras_node_id_t node_id) { cras_observer_notify_active_node_called++; } void cras_observer_notify_output_node_volume(cras_node_id_t node_id, - int32_t volume) -{ + int32_t volume) { cras_observer_notify_output_node_volume_called++; } void cras_observer_notify_node_left_right_swapped(cras_node_id_t node_id, - int swapped) -{ + int swapped) { cras_observer_notify_node_left_right_swapped_called++; } void cras_observer_notify_input_node_gain(cras_node_id_t node_id, - int32_t gain) -{ + int32_t gain) { cras_observer_notify_input_node_gain_called++; } -int audio_thread_dev_start_ramp(struct audio_thread *thread, +int audio_thread_dev_start_ramp(struct audio_thread* thread, unsigned int dev_idx, - enum CRAS_IODEV_RAMP_REQUEST request) -{ + enum CRAS_IODEV_RAMP_REQUEST request) { audio_thread_dev_start_ramp_called++; audio_thread_dev_start_ramp_dev_vector.push_back(dev_idx); audio_thread_dev_start_ramp_req = request; @@ -1910,23 +1870,19 @@ int audio_thread_dev_start_ramp(struct audio_thread *thread, } #ifdef HAVE_WEBRTC_APM -struct cras_apm *cras_apm_list_add(struct cras_apm_list *list, - void *dev_ptr, - const struct cras_audio_format *fmt) -{ +struct cras_apm* cras_apm_list_add(struct cras_apm_list* list, + void* dev_ptr, + const struct cras_audio_format* fmt) { return NULL; } -void cras_apm_list_remove(struct cras_apm_list *list, void *dev_ptr) -{ -} -int cras_apm_list_init(const char *device_config_dir) -{ +void cras_apm_list_remove(struct cras_apm_list* list, void* dev_ptr) {} +int cras_apm_list_init(const char* device_config_dir) { return 0; } #endif // From librt. -int clock_gettime(clockid_t clk_id, struct timespec *tp) { +int clock_gettime(clockid_t clk_id, struct timespec* tp) { tp->tv_sec = clock_gettime_retspec.tv_sec; tp->tv_nsec = clock_gettime_retspec.tv_nsec; return 0; diff --git a/cras/src/tests/iodev_stub.cc b/cras/src/tests/iodev_stub.cc index b47af1a1..25d59da0 100644 --- a/cras/src/tests/iodev_stub.cc +++ b/cras/src/tests/iodev_stub.cc @@ -4,6 +4,7 @@ */ #include <time.h> + #include <unordered_map> extern "C" { @@ -13,17 +14,19 @@ extern "C" { } namespace { - struct cb_data { - int frames_queued_ret; - timespec frames_queued_ts; - }; - std::unordered_map<cras_iodev*, cb_data> frames_queued_map; - std::unordered_map<cras_iodev*, cb_data> valid_frames_map; -} // namespace +struct cb_data { + int frames_queued_ret; + timespec frames_queued_ts; +}; +std::unordered_map<cras_iodev*, cb_data> frames_queued_map; +std::unordered_map<cras_iodev*, cb_data> valid_frames_map; +std::unordered_map<cras_iodev*, timespec> drop_time_map; +} // namespace void iodev_stub_reset() { frames_queued_map.clear(); valid_frames_map.clear(); + drop_time_map.clear(); } void iodev_stub_frames_queued(cras_iodev* iodev, int ret, timespec ts) { @@ -36,6 +39,15 @@ void iodev_stub_valid_frames(cras_iodev* iodev, int ret, timespec ts) { valid_frames_map.insert({iodev, data}); } +bool iodev_stub_get_drop_time(cras_iodev* iodev, timespec* ts) { + auto elem = drop_time_map.find(iodev); + if (elem != drop_time_map.end()) { + *ts = elem->second; + return true; + } + return false; +} + extern "C" { int cras_iodev_add_stream(struct cras_iodev* iodev, struct dev_stream* stream) { @@ -54,16 +66,16 @@ int cras_iodev_get_valid_frames(struct cras_iodev* iodev, return 0; } -double cras_iodev_get_est_rate_ratio(const struct cras_iodev *iodev) { - return 48000.0; +double cras_iodev_get_est_rate_ratio(const struct cras_iodev* iodev) { + return 1.0; } -int cras_iodev_get_dsp_delay(const struct cras_iodev *iodev) { +int cras_iodev_get_dsp_delay(const struct cras_iodev* iodev) { return 0; } -int cras_iodev_frames_queued(struct cras_iodev *iodev, - struct timespec *tstamp) { +int cras_iodev_frames_queued(struct cras_iodev* iodev, + struct timespec* tstamp) { auto elem = frames_queued_map.find(iodev); if (elem != frames_queued_map.end()) { *tstamp = elem->second.frames_queued_ts; @@ -73,72 +85,72 @@ int cras_iodev_frames_queued(struct cras_iodev *iodev, return 0; } -struct dev_stream *cras_iodev_rm_stream(struct cras_iodev *iodev, - const struct cras_rstream *stream) { +struct dev_stream* cras_iodev_rm_stream(struct cras_iodev* iodev, + const struct cras_rstream* stream) { return NULL; } -int cras_iodev_update_rate(struct cras_iodev *iodev, unsigned int level, - struct timespec *level_tstamp) { +int cras_iodev_update_rate(struct cras_iodev* iodev, + unsigned int level, + struct timespec* level_tstamp) { return 0; } -enum CRAS_IODEV_STATE cras_iodev_state(const struct cras_iodev *iodev) { +enum CRAS_IODEV_STATE cras_iodev_state(const struct cras_iodev* iodev) { return iodev->state; } -unsigned int cras_iodev_all_streams_written(struct cras_iodev *iodev) { +unsigned int cras_iodev_all_streams_written(struct cras_iodev* iodev) { return 0; } -int cras_iodev_put_input_buffer(struct cras_iodev *iodev) { +int cras_iodev_put_input_buffer(struct cras_iodev* iodev) { return 0; } -int cras_iodev_put_output_buffer(struct cras_iodev *iodev, uint8_t *frames, - unsigned int nframes, int* non_empty, - struct cras_fmt_conv *output_converter) { +int cras_iodev_put_output_buffer(struct cras_iodev* iodev, + uint8_t* frames, + unsigned int nframes, + int* non_empty, + struct cras_fmt_conv* output_converter) { return 0; } -int cras_iodev_get_input_buffer(struct cras_iodev *iodev, - unsigned *frames) { +int cras_iodev_get_input_buffer(struct cras_iodev* iodev, unsigned* frames) { return 0; } -int cras_iodev_get_output_buffer(struct cras_iodev *iodev, - struct cras_audio_area **area, - unsigned *frames) { +int cras_iodev_get_output_buffer(struct cras_iodev* iodev, + struct cras_audio_area** area, + unsigned* frames) { return 0; } -float cras_iodev_get_software_gain_scaler(const struct cras_iodev *iodev) { +float cras_iodev_get_software_gain_scaler(const struct cras_iodev* iodev) { return 0.0; } -void cras_iodev_stream_written(struct cras_iodev *iodev, - struct dev_stream *stream, - unsigned int nwritten) { -} +void cras_iodev_stream_written(struct cras_iodev* iodev, + struct dev_stream* stream, + unsigned int nwritten) {} -int cras_iodev_prepare_output_before_write_samples(struct cras_iodev *odev) -{ return 0; +int cras_iodev_prepare_output_before_write_samples(struct cras_iodev* odev) { + return 0; } -int cras_iodev_buffer_avail(struct cras_iodev *iodev, unsigned hw_level) { +int cras_iodev_buffer_avail(struct cras_iodev* iodev, unsigned hw_level) { return 0; } -unsigned int cras_iodev_max_stream_offset(const struct cras_iodev *iodev) { +unsigned int cras_iodev_max_stream_offset(const struct cras_iodev* iodev) { return 0; } -int cras_iodev_odev_should_wake(const struct cras_iodev *odev) -{ +int cras_iodev_odev_should_wake(const struct cras_iodev* odev) { return 1; } -int cras_iodev_output_underrun(struct cras_iodev *odev) { +int cras_iodev_output_underrun(struct cras_iodev* odev) { return 0; } @@ -146,33 +158,32 @@ int cras_iodev_reset_request(struct cras_iodev* iodev) { return 0; } -unsigned int cras_iodev_stream_offset(struct cras_iodev *iodev, - struct dev_stream *stream) { +unsigned int cras_iodev_stream_offset(struct cras_iodev* iodev, + struct dev_stream* stream) { return 0; } -unsigned int cras_iodev_get_num_underruns(const struct cras_iodev *iodev) -{ +unsigned int cras_iodev_get_num_underruns(const struct cras_iodev* iodev) { return 0; } -unsigned int cras_iodev_frames_to_play_in_sleep(struct cras_iodev *odev, - unsigned int *hw_level, - struct timespec *hw_tstamp) -{ +unsigned int cras_iodev_frames_to_play_in_sleep(struct cras_iodev* odev, + unsigned int* hw_level, + struct timespec* hw_tstamp) { clock_gettime(CLOCK_MONOTONIC_RAW, hw_tstamp); *hw_level = 0; return 0; } -void cras_iodev_update_highest_hw_level(struct cras_iodev *iodev, - unsigned int hw_level) -{ -} +void cras_iodev_update_highest_hw_level(struct cras_iodev* iodev, + unsigned int hw_level) {} -void cras_iodev_start_stream(struct cras_iodev *iodev, - struct dev_stream *stream) -{ -} +void cras_iodev_start_stream(struct cras_iodev* iodev, + struct dev_stream* stream) {} -} // extern "C" +int cras_iodev_drop_frames_by_time(struct cras_iodev* iodev, + struct timespec ts) { + drop_time_map.insert({iodev, ts}); + return 0; +} +} // extern "C" diff --git a/cras/src/tests/iodev_stub.h b/cras/src/tests/iodev_stub.h index a07f2602..dde1b9f4 100644 --- a/cras/src/tests/iodev_stub.h +++ b/cras/src/tests/iodev_stub.h @@ -14,4 +14,6 @@ void iodev_stub_frames_queued(cras_iodev* iodev, int ret, timespec ts); void iodev_stub_valid_frames(cras_iodev* iodev, int ret, timespec ts); -#endif // IODEV_STUB_H_ +bool iodev_stub_get_drop_time(cras_iodev* iodev, timespec* ts); + +#endif // IODEV_STUB_H_ diff --git a/cras/src/tests/iodev_unittest.cc b/cras/src/tests/iodev_unittest.cc index 1e5f1bbd..61f8f694 100644 --- a/cras/src/tests/iodev_unittest.cc +++ b/cras/src/tests/iodev_unittest.cc @@ -2,21 +2,25 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <stdio.h> #include <gtest/gtest.h> +#include <stdio.h> extern "C" { +#include "audio_thread_log.h" +#include "cras_audio_area.h" #include "cras_iodev.h" #include "cras_ramp.h" #include "cras_rstream.h" #include "dev_stream.h" -#include "utlist.h" -#include "cras_audio_area.h" -#include "audio_thread_log.h" #include "input_data.h" +#include "utlist.h" // Mock software volume scalers. float softvol_scalers[101]; + +// For audio_thread_log.h use. +int atlog_rw_shm_fd; +int atlog_ro_shm_fd; } #define BUFFER_SIZE 8192 @@ -30,11 +34,11 @@ static int cras_iodev_list_disable_dev_called; static int select_node_called; static enum CRAS_STREAM_DIRECTION select_node_direction; static cras_node_id_t select_node_id; -static struct cras_ionode *node_selected; +static struct cras_ionode* node_selected; static size_t notify_nodes_changed_called; static size_t notify_active_node_changed_called; static int dsp_context_new_sample_rate; -static const char *dsp_context_new_purpose; +static const char* dsp_context_new_purpose; static int dsp_context_free_called; static int update_channel_layout_called; static int update_channel_layout_return_val; @@ -54,7 +58,7 @@ static int cras_dsp_pipeline_apply_sample_count; static unsigned int cras_mix_mute_count; static unsigned int cras_dsp_num_input_channels_return; static unsigned int cras_dsp_num_output_channels_return; -struct cras_dsp_context *cras_dsp_context_new_return; +struct cras_dsp_context* cras_dsp_context_new_return; static unsigned int cras_dsp_load_dummy_pipeline_called; static unsigned int rate_estimator_add_frames_num_frames; static unsigned int rate_estimator_add_frames_called; @@ -63,21 +67,21 @@ static snd_pcm_format_t cras_scale_buffer_fmt; static float cras_scale_buffer_scaler; static int cras_scale_buffer_called; static unsigned int pre_dsp_hook_called; -static const uint8_t *pre_dsp_hook_frames; -static void *pre_dsp_hook_cb_data; +static const uint8_t* pre_dsp_hook_frames; +static void* pre_dsp_hook_cb_data; static unsigned int post_dsp_hook_called; -static const uint8_t *post_dsp_hook_frames; -static void *post_dsp_hook_cb_data; +static const uint8_t* post_dsp_hook_frames; +static void* post_dsp_hook_cb_data; static int iodev_buffer_size; static long cras_system_get_capture_gain_ret_value; static uint8_t audio_buffer[BUFFER_SIZE]; -static struct cras_audio_area *audio_area; +static struct cras_audio_area* audio_area; static unsigned int put_buffer_nframes; static int is_free_running_ret; static int no_stream_called; static int no_stream_enable; // This will be used extensively in cras_iodev. -struct audio_thread_event_log *atlog; +struct audio_thread_event_log* atlog; static unsigned int simple_no_stream_called; static int simple_no_stream_enable; static int dev_stream_playback_frames_ret; @@ -98,7 +102,7 @@ static void* cras_ramp_start_cb_data; static int cras_device_monitor_set_device_mute_state_called; unsigned int cras_device_monitor_set_device_mute_state_dev_idx; static snd_pcm_format_t cras_scale_buffer_increment_fmt; -static uint8_t *cras_scale_buffer_increment_buff; +static uint8_t* cras_scale_buffer_increment_buff; static unsigned int cras_scale_buffer_increment_frame; static float cras_scale_buffer_increment_scaler; static float cras_scale_buffer_increment_increment; @@ -108,10 +112,13 @@ static struct cras_audio_format audio_fmt; static int buffer_share_add_id_called; static int buffer_share_get_new_write_point_ret; static int ext_mod_configure_called; -static struct input_data *input_data_create_ret; +static struct input_data* input_data_create_ret; +static double rate_estimator_get_rate_ret; + +static char* atlog_name; // Iodev callback -int update_channel_layout(struct cras_iodev *iodev) { +int update_channel_layout(struct cras_iodev* iodev) { update_channel_layout_called = 1; return update_channel_layout_return_val; } @@ -150,7 +157,8 @@ void ResetStubData() { pre_dsp_hook_called = 0; pre_dsp_hook_frames = NULL; post_dsp_hook_called = 0; - post_dsp_hook_frames = NULL; iodev_buffer_size = 0; + post_dsp_hook_frames = NULL; + iodev_buffer_size = 0; cras_system_get_capture_gain_ret_value = 0; // Assume there is some data in audio buffer. memset(audio_buffer, 0xff, sizeof(audio_buffer)); @@ -159,14 +167,20 @@ void ResetStubData() { audio_area = NULL; } put_buffer_nframes = 0; - is_free_running_ret= 0; + is_free_running_ret = 0; no_stream_called = 0; no_stream_enable = 0; simple_no_stream_called = 0; simple_no_stream_enable = 0; dev_stream_playback_frames_ret = 0; - if (!atlog) - atlog = audio_thread_event_log_init(); + if (!atlog) { + if (asprintf(&atlog_name, "/ATlog-%d", getpid()) < 0) { + exit(-1); + } + /* To avoid un-used variable warning. */ + atlog_rw_shm_fd = atlog_ro_shm_fd = -1; + atlog = audio_thread_event_log_init(atlog_name); + } get_num_underruns_ret = 0; device_monitor_reset_device_called = 0; output_underrun_called = 0; @@ -196,6 +210,7 @@ void ResetStubData() { audio_fmt.num_channels = 2; buffer_share_add_id_called = 0; ext_mod_configure_called = 0; + rate_estimator_get_rate_ret = 0; } namespace { @@ -228,42 +243,40 @@ TEST(IoDevTestSuite, FillTimeFromFramesShort) { } class IoDevSetFormatTestSuite : public testing::Test { - protected: - virtual void SetUp() { - ResetStubData(); - sample_rates_[0] = 44100; - sample_rates_[1] = 48000; - sample_rates_[2] = 0; - - channel_counts_[0] = 2; - channel_counts_[1] = 0; - channel_counts_[2] = 0; - - pcm_formats_[0] = SND_PCM_FORMAT_S16_LE; - pcm_formats_[1] = SND_PCM_FORMAT_S32_LE; - pcm_formats_[2] = static_cast<snd_pcm_format_t>(0); - - update_channel_layout_called = 0; - update_channel_layout_return_val = 0; - - memset(&iodev_, 0, sizeof(iodev_)); - iodev_.update_channel_layout = update_channel_layout; - iodev_.supported_rates = sample_rates_; - iodev_.supported_channel_counts = channel_counts_; - iodev_.supported_formats = pcm_formats_; - iodev_.dsp_context = NULL; - - cras_audio_format_set_channel_layout_called = 0; - } + protected: + virtual void SetUp() { + ResetStubData(); + sample_rates_[0] = 44100; + sample_rates_[1] = 48000; + sample_rates_[2] = 0; + + channel_counts_[0] = 2; + channel_counts_[1] = 0; + channel_counts_[2] = 0; + + pcm_formats_[0] = SND_PCM_FORMAT_S16_LE; + pcm_formats_[1] = SND_PCM_FORMAT_S32_LE; + pcm_formats_[2] = static_cast<snd_pcm_format_t>(0); + + update_channel_layout_called = 0; + update_channel_layout_return_val = 0; + + memset(&iodev_, 0, sizeof(iodev_)); + iodev_.update_channel_layout = update_channel_layout; + iodev_.supported_rates = sample_rates_; + iodev_.supported_channel_counts = channel_counts_; + iodev_.supported_formats = pcm_formats_; + iodev_.dsp_context = NULL; + + cras_audio_format_set_channel_layout_called = 0; + } - virtual void TearDown() { - cras_iodev_free_format(&iodev_); - } + virtual void TearDown() { cras_iodev_free_format(&iodev_); } - struct cras_iodev iodev_; - size_t sample_rates_[3]; - size_t channel_counts_[3]; - snd_pcm_format_t pcm_formats_[3]; + struct cras_iodev iodev_; + size_t sample_rates_[3]; + size_t channel_counts_[3]; + snd_pcm_format_t pcm_formats_[3]; }; TEST_F(IoDevSetFormatTestSuite, SupportedFormatSecondary) { @@ -417,8 +430,8 @@ TEST_F(IoDevSetFormatTestSuite, UpdateChannelLayoutSuccess) { } TEST_F(IoDevSetFormatTestSuite, UpdateChannelLayoutFail) { - static const int8_t stereo_layout[] = - {0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; + static const int8_t stereo_layout[] = {0, 1, -1, -1, -1, -1, + -1, -1, -1, -1, -1}; struct cras_audio_format fmt; int rc, i; @@ -426,7 +439,7 @@ TEST_F(IoDevSetFormatTestSuite, UpdateChannelLayoutFail) { fmt.frame_rate = 48000; fmt.num_channels = 2; - cras_dsp_context_new_return = reinterpret_cast<cras_dsp_context *>(0xf0f); + cras_dsp_context_new_return = reinterpret_cast<cras_dsp_context*>(0xf0f); update_channel_layout_return_val = -1; iodev_.supported_channel_counts[0] = 6; @@ -443,8 +456,8 @@ TEST_F(IoDevSetFormatTestSuite, UpdateChannelLayoutFail) { } TEST_F(IoDevSetFormatTestSuite, UpdateChannelLayoutFail6ch) { - static const int8_t default_6ch_layout[] = - {0, 1, 2, 3, 4, 5, -1, -1, -1, -1, -1}; + static const int8_t default_6ch_layout[] = {0, 1, 2, 3, 4, 5, + -1, -1, -1, -1, -1}; struct cras_audio_format fmt; int rc, i; @@ -452,7 +465,7 @@ TEST_F(IoDevSetFormatTestSuite, UpdateChannelLayoutFail6ch) { fmt.frame_rate = 48000; fmt.num_channels = 6; - cras_dsp_context_new_return = reinterpret_cast<cras_dsp_context *>(0xf0f); + cras_dsp_context_new_return = reinterpret_cast<cras_dsp_context*>(0xf0f); update_channel_layout_return_val = -1; iodev_.supported_channel_counts[0] = 6; @@ -470,8 +483,9 @@ TEST_F(IoDevSetFormatTestSuite, UpdateChannelLayoutFail6ch) { // Put buffer tests -static int get_buffer(cras_iodev* iodev, struct cras_audio_area** area, - unsigned int* num) { +static int get_buffer(cras_iodev* iodev, + struct cras_audio_area** area, + unsigned int* num) { size_t sz = sizeof(*audio_area) + sizeof(struct cras_channel_area) * 2; audio_area = (cras_audio_area*)calloc(1, sz); @@ -488,8 +502,7 @@ static int get_buffer(cras_iodev* iodev, struct cras_audio_area** area, return 0; } -static int put_buffer(struct cras_iodev *iodev, unsigned int nframes) -{ +static int put_buffer(struct cras_iodev* iodev, unsigned int nframes) { put_buffer_nframes = nframes; if (audio_area) { free(audio_area); @@ -498,46 +511,45 @@ static int put_buffer(struct cras_iodev *iodev, unsigned int nframes) return 0; } -static int no_stream(struct cras_iodev *odev, int enable) -{ +static int no_stream(struct cras_iodev* odev, int enable) { no_stream_called++; no_stream_enable = enable; // Use default no stream playback to test default behavior. return cras_iodev_default_no_stream_playback(odev, enable); } -static int is_free_running(const struct cras_iodev *odev) -{ +static int is_free_running(const struct cras_iodev* odev) { return is_free_running_ret; } -static int pre_dsp_hook(const uint8_t *frames, unsigned int nframes, - const struct cras_audio_format *fmt, void *cb_data) -{ +static int pre_dsp_hook(const uint8_t* frames, + unsigned int nframes, + const struct cras_audio_format* fmt, + void* cb_data) { pre_dsp_hook_called++; pre_dsp_hook_frames = frames; pre_dsp_hook_cb_data = cb_data; return 0; } -static int post_dsp_hook(const uint8_t *frames, unsigned int nframes, - const struct cras_audio_format *fmt, void *cb_data) -{ +static int post_dsp_hook(const uint8_t* frames, + unsigned int nframes, + const struct cras_audio_format* fmt, + void* cb_data) { post_dsp_hook_called++; post_dsp_hook_frames = frames; post_dsp_hook_cb_data = cb_data; return 0; } -static int loopback_hook_control(bool start, void *cb_data) -{ +static int loopback_hook_control(bool start, void* cb_data) { return 0; } TEST(IoDevPutOutputBuffer, SystemMuted) { struct cras_audio_format fmt; struct cras_iodev iodev; - uint8_t *frames = reinterpret_cast<uint8_t*>(0x44); + uint8_t* frames = reinterpret_cast<uint8_t*>(0x44); int rc; ResetStubData(); @@ -549,7 +561,7 @@ TEST(IoDevPutOutputBuffer, SystemMuted) { fmt.num_channels = 2; iodev.format = &fmt; iodev.put_buffer = put_buffer; - iodev.rate_est = reinterpret_cast<struct rate_estimator *>(0xdeadbeef); + iodev.rate_est = reinterpret_cast<struct rate_estimator*>(0xdeadbeef); rc = cras_iodev_put_output_buffer(&iodev, frames, 20, NULL, nullptr); EXPECT_EQ(0, rc); @@ -595,7 +607,7 @@ TEST(IoDevPutOutputBuffer, NodeVolumeZeroShouldMute) { struct cras_audio_format fmt; struct cras_iodev iodev; struct cras_ionode ionode; - uint8_t *frames = reinterpret_cast<uint8_t*>(0x44); + uint8_t* frames = reinterpret_cast<uint8_t*>(0x44); int rc; ResetStubData(); @@ -612,7 +624,7 @@ TEST(IoDevPutOutputBuffer, NodeVolumeZeroShouldMute) { fmt.num_channels = 2; iodev.format = &fmt; iodev.put_buffer = put_buffer; - iodev.rate_est = reinterpret_cast<struct rate_estimator *>(0xdeadbeef); + iodev.rate_est = reinterpret_cast<struct rate_estimator*>(0xdeadbeef); rc = cras_iodev_put_output_buffer(&iodev, frames, 20, NULL, nullptr); EXPECT_EQ(0, rc); @@ -624,7 +636,7 @@ TEST(IoDevPutOutputBuffer, NodeVolumeZeroShouldMute) { TEST(IoDevPutOutputBuffer, SystemMutedWithRamp) { struct cras_audio_format fmt; struct cras_iodev iodev; - uint8_t *frames = reinterpret_cast<uint8_t*>(0x44); + uint8_t* frames = reinterpret_cast<uint8_t*>(0x44); int rc; ResetStubData(); @@ -639,7 +651,7 @@ TEST(IoDevPutOutputBuffer, SystemMutedWithRamp) { // Assume device has ramp member. iodev.ramp = reinterpret_cast<struct cras_ramp*>(0x1); - iodev.rate_est = reinterpret_cast<struct rate_estimator *>(0xdeadbeef); + iodev.rate_est = reinterpret_cast<struct rate_estimator*>(0xdeadbeef); // Assume ramping is done. cras_ramp_get_current_action_ret.type = CRAS_RAMP_ACTION_NONE; @@ -669,7 +681,7 @@ TEST(IoDevPutOutputBuffer, NodeVolumeZeroShouldMuteWithRamp) { struct cras_audio_format fmt; struct cras_iodev iodev; struct cras_ionode ionode; - uint8_t *frames = reinterpret_cast<uint8_t*>(0x44); + uint8_t* frames = reinterpret_cast<uint8_t*>(0x44); int rc; ResetStubData(); @@ -686,7 +698,7 @@ TEST(IoDevPutOutputBuffer, NodeVolumeZeroShouldMuteWithRamp) { fmt.num_channels = 2; iodev.format = &fmt; iodev.put_buffer = put_buffer; - iodev.rate_est = reinterpret_cast<struct rate_estimator *>(0xdeadbeef); + iodev.rate_est = reinterpret_cast<struct rate_estimator*>(0xdeadbeef); // Assume device has ramp member. iodev.ramp = reinterpret_cast<struct cras_ramp*>(0x1); @@ -717,7 +729,7 @@ TEST(IoDevPutOutputBuffer, NoDSP) { struct cras_audio_format fmt; struct cras_iodev iodev; struct cras_ionode ionode; - uint8_t *frames = reinterpret_cast<uint8_t*>(0x44); + uint8_t* frames = reinterpret_cast<uint8_t*>(0x44); int rc; ResetStubData(); @@ -734,7 +746,7 @@ TEST(IoDevPutOutputBuffer, NoDSP) { fmt.num_channels = 2; iodev.format = &fmt; iodev.put_buffer = put_buffer; - iodev.rate_est = reinterpret_cast<struct rate_estimator *>(0xdeadbeef); + iodev.rate_est = reinterpret_cast<struct rate_estimator*>(0xdeadbeef); rc = cras_iodev_put_output_buffer(&iodev, frames, 22, NULL, nullptr); EXPECT_EQ(0, rc); @@ -746,7 +758,7 @@ TEST(IoDevPutOutputBuffer, NoDSP) { TEST(IoDevPutOutputBuffer, DSP) { struct cras_audio_format fmt; struct cras_iodev iodev; - uint8_t *frames = reinterpret_cast<uint8_t*>(0x44); + uint8_t* frames = reinterpret_cast<uint8_t*>(0x44); int rc; struct cras_loopback pre_dsp; struct cras_loopback post_dsp; @@ -761,16 +773,16 @@ TEST(IoDevPutOutputBuffer, DSP) { fmt.num_channels = 2; iodev.format = &fmt; iodev.put_buffer = put_buffer; - iodev.rate_est = reinterpret_cast<struct rate_estimator *>(0xdeadbeef); + iodev.rate_est = reinterpret_cast<struct rate_estimator*>(0xdeadbeef); pre_dsp.type = LOOPBACK_POST_MIX_PRE_DSP; pre_dsp.hook_data = pre_dsp_hook; pre_dsp.hook_control = loopback_hook_control; - pre_dsp.cb_data = (void *)0x1234; + pre_dsp.cb_data = (void*)0x1234; DL_APPEND(iodev.loopbacks, &pre_dsp); post_dsp.type = LOOPBACK_POST_DSP; post_dsp.hook_data = post_dsp_hook; post_dsp.hook_control = loopback_hook_control; - post_dsp.cb_data = (void *)0x5678; + post_dsp.cb_data = (void*)0x5678; DL_APPEND(iodev.loopbacks, &post_dsp); rc = cras_iodev_put_output_buffer(&iodev, frames, 32, NULL, nullptr); @@ -778,9 +790,9 @@ TEST(IoDevPutOutputBuffer, DSP) { EXPECT_EQ(0, cras_mix_mute_count); EXPECT_EQ(1, pre_dsp_hook_called); EXPECT_EQ(frames, pre_dsp_hook_frames); - EXPECT_EQ((void *)0x1234, pre_dsp_hook_cb_data); + EXPECT_EQ((void*)0x1234, pre_dsp_hook_cb_data); EXPECT_EQ(1, post_dsp_hook_called); - EXPECT_EQ((void *)0x5678, post_dsp_hook_cb_data); + EXPECT_EQ((void*)0x5678, post_dsp_hook_cb_data); EXPECT_EQ(32, put_buffer_nframes); EXPECT_EQ(32, rate_estimator_add_frames_num_frames); EXPECT_EQ(32, cras_dsp_pipeline_apply_sample_count); @@ -790,7 +802,7 @@ TEST(IoDevPutOutputBuffer, DSP) { TEST(IoDevPutOutputBuffer, SoftVol) { struct cras_audio_format fmt; struct cras_iodev iodev; - uint8_t *frames = reinterpret_cast<uint8_t*>(0x44); + uint8_t* frames = reinterpret_cast<uint8_t*>(0x44); int rc; ResetStubData(); @@ -802,7 +814,7 @@ TEST(IoDevPutOutputBuffer, SoftVol) { fmt.num_channels = 2; iodev.format = &fmt; iodev.put_buffer = put_buffer; - iodev.rate_est = reinterpret_cast<struct rate_estimator *>(0xdeadbeef); + iodev.rate_est = reinterpret_cast<struct rate_estimator*>(0xdeadbeef); cras_system_get_volume_return = 13; softvol_scalers[13] = 0.435; @@ -819,7 +831,7 @@ TEST(IoDevPutOutputBuffer, SoftVol) { TEST(IoDevPutOutputBuffer, SoftVolWithRamp) { struct cras_audio_format fmt; struct cras_iodev iodev; - uint8_t *frames = reinterpret_cast<uint8_t*>(0x44); + uint8_t* frames = reinterpret_cast<uint8_t*>(0x44); int rc; int n_frames = 53; float ramp_scaler = 0.2; @@ -839,7 +851,7 @@ TEST(IoDevPutOutputBuffer, SoftVolWithRamp) { iodev.put_buffer = put_buffer; // Assume device has ramp member. iodev.ramp = reinterpret_cast<struct cras_ramp*>(0x1); - iodev.rate_est = reinterpret_cast<struct rate_estimator *>(0xdeadbeef); + iodev.rate_est = reinterpret_cast<struct rate_estimator*>(0xdeadbeef); // Assume ramping is done. cras_ramp_get_current_action_ret.type = CRAS_RAMP_ACTION_NONE; @@ -894,7 +906,7 @@ TEST(IoDevPutOutputBuffer, SoftVolWithRamp) { TEST(IoDevPutOutputBuffer, NoSoftVolWithRamp) { struct cras_audio_format fmt; struct cras_iodev iodev; - uint8_t *frames = reinterpret_cast<uint8_t*>(0x44); + uint8_t* frames = reinterpret_cast<uint8_t*>(0x44); int rc; int n_frames = 53; float ramp_scaler = 0.2; @@ -912,7 +924,7 @@ TEST(IoDevPutOutputBuffer, NoSoftVolWithRamp) { iodev.put_buffer = put_buffer; // Assume device has ramp member. iodev.ramp = reinterpret_cast<struct cras_ramp*>(0x1); - iodev.rate_est = reinterpret_cast<struct rate_estimator *>(0xdeadbeef); + iodev.rate_est = reinterpret_cast<struct rate_estimator*>(0xdeadbeef); // Assume ramping is done. cras_ramp_get_current_action_ret.type = CRAS_RAMP_ACTION_NONE; @@ -954,7 +966,7 @@ TEST(IoDevPutOutputBuffer, NoSoftVolWithRamp) { TEST(IoDevPutOutputBuffer, Scale32Bit) { struct cras_audio_format fmt; struct cras_iodev iodev; - uint8_t *frames = reinterpret_cast<uint8_t*>(0x44); + uint8_t* frames = reinterpret_cast<uint8_t*>(0x44); int rc; ResetStubData(); @@ -969,7 +981,7 @@ TEST(IoDevPutOutputBuffer, Scale32Bit) { fmt.num_channels = 2; iodev.format = &fmt; iodev.put_buffer = put_buffer; - iodev.rate_est = reinterpret_cast<struct rate_estimator *>(0xdeadbeef); + iodev.rate_est = reinterpret_cast<struct rate_estimator*>(0xdeadbeef); rc = cras_iodev_put_output_buffer(&iodev, frames, 53, NULL, nullptr); EXPECT_EQ(0, rc); @@ -983,9 +995,8 @@ TEST(IoDevPutOutputBuffer, Scale32Bit) { static unsigned fr_queued = 0; -static int frames_queued(const struct cras_iodev *iodev, - struct timespec *tstamp) -{ +static int frames_queued(const struct cras_iodev* iodev, + struct timespec* tstamp) { clock_gettime(CLOCK_MONOTONIC_RAW, tstamp); return fr_queued; } @@ -1035,14 +1046,11 @@ TEST(IoDevQueuedBuffer, NonZeroMinBufferLevel) { EXPECT_EQ(100, rc); } -static void update_active_node(struct cras_iodev *iodev, +static void update_active_node(struct cras_iodev* iodev, unsigned node_idx, - unsigned dev_enabled) -{ -} + unsigned dev_enabled) {} -static void dev_set_mute(struct cras_iodev *iodev) -{ +static void dev_set_mute(struct cras_iodev* iodev) { set_mute_called++; } @@ -1134,7 +1142,6 @@ TEST(IoDev, SoftwareVolume) { iodev.active_node->volume = 100; iodev.software_volume_needed = 0; - softvol_scalers[80] = 0.5; softvol_scalers[70] = 0.3; @@ -1162,7 +1169,7 @@ TEST(IoDev, SoftwareGain) { iodev.active_node = &ionode; iodev.active_node->dev = &iodev; - ionode.capture_gain= 400; + ionode.capture_gain = 400; ionode.software_volume_needed = 1; ionode.max_software_gain = 3000; @@ -1181,10 +1188,9 @@ TEST(IoDev, SoftwareGain) { // This get_buffer implementation set returned frames larger than requested // frames. -static int bad_get_buffer(struct cras_iodev *iodev, - struct cras_audio_area **area, - unsigned *frames) -{ +static int bad_get_buffer(struct cras_iodev* iodev, + struct cras_audio_area** area, + unsigned* frames) { *frames = *frames + 1; return 0; } @@ -1194,7 +1200,7 @@ static int bad_get_buffer(struct cras_iodev *iodev, // error. TEST(IoDev, GetBufferInvalidFrames) { struct cras_iodev iodev; - struct cras_audio_area **area = NULL; + struct cras_audio_area** area = NULL; unsigned int frames = 512; struct cras_audio_format fmt; @@ -1214,7 +1220,7 @@ TEST(IoDev, GetBufferInvalidFrames) { EXPECT_EQ(-EINVAL, cras_iodev_get_input_buffer(&iodev, &frames)); } -static int configure_dev(struct cras_iodev *iodev) { +static int configure_dev(struct cras_iodev* iodev) { iodev->buffer_size = iodev_buffer_size; return 0; } @@ -1261,7 +1267,7 @@ TEST(IoDev, OpenOutputDeviceWithLowRateFmt) { EXPECT_EQ(240, iodev.min_cb_level); } -int fake_start(const struct cras_iodev *iodev) { +int fake_start(const struct cras_iodev* iodev) { return 0; } @@ -1349,8 +1355,7 @@ TEST(IoDev, OpenInputDeviceWithLowRateFmt) { EXPECT_EQ(240, iodev.min_cb_level); } -static int simple_no_stream(struct cras_iodev *dev, int enable) -{ +static int simple_no_stream(struct cras_iodev* dev, int enable) { simple_no_stream_enable = enable; simple_no_stream_called++; return 0; @@ -1518,7 +1523,7 @@ TEST(IoDev, FillZeros) { struct cras_iodev iodev; struct cras_audio_format fmt; unsigned int frames = 50; - int16_t *zeros; + int16_t* zeros; int rc; ResetStubData(); @@ -1540,7 +1545,7 @@ TEST(IoDev, FillZeros) { EXPECT_EQ(0, rc); EXPECT_EQ(frames, put_buffer_nframes); - zeros = (int16_t *)calloc(frames * 2, sizeof(*zeros)); + zeros = (int16_t*)calloc(frames * 2, sizeof(*zeros)); rc = memcmp(audio_buffer, zeros, frames * 2 * 2); free(zeros); EXPECT_EQ(0, rc); @@ -1552,7 +1557,7 @@ TEST(IoDev, DefaultNoStreamPlaybackRunning) { unsigned int hw_level = 50; unsigned int min_cb_level = 240; unsigned int zeros_to_fill; - int16_t *zeros; + int16_t* zeros; int rc; memset(&iodev, 0, sizeof(iodev)); @@ -1583,7 +1588,7 @@ TEST(IoDev, DefaultNoStreamPlaybackRunning) { EXPECT_EQ(0, rc); EXPECT_EQ(CRAS_IODEV_STATE_NO_STREAM_RUN, iodev.state); EXPECT_EQ(zeros_to_fill, put_buffer_nframes); - zeros = (int16_t *)calloc(zeros_to_fill * 2, sizeof(*zeros)); + zeros = (int16_t*)calloc(zeros_to_fill * 2, sizeof(*zeros)); EXPECT_EQ(0, memcmp(audio_buffer, zeros, zeros_to_fill * 2 * 2)); free(zeros); @@ -1958,8 +1963,7 @@ TEST(IoDev, StartVolumeRamp) { EXPECT_EQ(0, cras_ramp_start_mute_ramp); EXPECT_FLOAT_EQ(0.25, cras_ramp_start_from); EXPECT_FLOAT_EQ(1.0, cras_ramp_start_to); - EXPECT_EQ(expected_frames, - cras_ramp_start_duration_frames); + EXPECT_EQ(expected_frames, cras_ramp_start_duration_frames); EXPECT_EQ(NULL, cras_ramp_start_cb); EXPECT_EQ(NULL, cras_ramp_start_cb_data); @@ -1979,8 +1983,7 @@ TEST(IoDev, StartVolumeRamp) { EXPECT_EQ(0, cras_ramp_start_mute_ramp); EXPECT_FLOAT_EQ(1.25, cras_ramp_start_from); EXPECT_FLOAT_EQ(1.0, cras_ramp_start_to); - EXPECT_EQ(expected_frames, - cras_ramp_start_duration_frames); + EXPECT_EQ(expected_frames, cras_ramp_start_duration_frames); EXPECT_EQ(NULL, cras_ramp_start_cb); EXPECT_EQ(NULL, cras_ramp_start_cb_data); } @@ -2053,8 +2056,8 @@ TEST(IoDev, FramesToPlayInSleep) { dev_stream_playback_frames_ret = 100; hw_level = min_cb_level + 50; fr_queued = hw_level; - got_frames = cras_iodev_frames_to_play_in_sleep( - &iodev, &got_hw_level, &hw_tstamp); + got_frames = + cras_iodev_frames_to_play_in_sleep(&iodev, &got_hw_level, &hw_tstamp); EXPECT_EQ(got_hw_level, hw_level); EXPECT_EQ(got_frames, 50); dev_stream_playback_frames_ret = 0; @@ -2063,8 +2066,8 @@ TEST(IoDev, FramesToPlayInSleep) { // hw_level is greater than min_cb_level. hw_level = min_cb_level + 50; fr_queued = hw_level; - got_frames = cras_iodev_frames_to_play_in_sleep( - &iodev, &got_hw_level, &hw_tstamp); + got_frames = + cras_iodev_frames_to_play_in_sleep(&iodev, &got_hw_level, &hw_tstamp); EXPECT_EQ(got_hw_level, hw_level); EXPECT_EQ(got_frames, 514); @@ -2072,8 +2075,8 @@ TEST(IoDev, FramesToPlayInSleep) { // hw_level is 2x greater than min_cb_level. hw_level = 2 * min_cb_level + 50; fr_queued = hw_level; - got_frames = cras_iodev_frames_to_play_in_sleep( - &iodev, &got_hw_level, &hw_tstamp); + got_frames = + cras_iodev_frames_to_play_in_sleep(&iodev, &got_hw_level, &hw_tstamp); EXPECT_EQ(got_hw_level, hw_level); EXPECT_EQ(got_frames, 1026); @@ -2081,8 +2084,8 @@ TEST(IoDev, FramesToPlayInSleep) { // hw_level is less than min_cb_level. hw_level = min_cb_level / 2; fr_queued = hw_level; - got_frames = cras_iodev_frames_to_play_in_sleep( - &iodev, &got_hw_level, &hw_tstamp); + got_frames = + cras_iodev_frames_to_play_in_sleep(&iodev, &got_hw_level, &hw_tstamp); EXPECT_EQ(got_hw_level, hw_level); EXPECT_EQ(got_frames, 208); @@ -2092,13 +2095,13 @@ TEST(IoDev, FramesToPlayInSleep) { iodev.streams = NULL; hw_level = min_cb_level; fr_queued = hw_level; - got_frames = cras_iodev_frames_to_play_in_sleep( - &iodev, &got_hw_level, &hw_tstamp); + got_frames = + cras_iodev_frames_to_play_in_sleep(&iodev, &got_hw_level, &hw_tstamp); EXPECT_EQ(got_hw_level, hw_level); EXPECT_EQ(got_frames, hw_level - fmt.frame_rate / 1000 * 5); } -static unsigned int get_num_underruns(const struct cras_iodev *iodev) { +static unsigned int get_num_underruns(const struct cras_iodev* iodev) { return get_num_underruns_ret; } @@ -2145,17 +2148,16 @@ TEST(IoDev, RequestReset) { EXPECT_EQ(2, device_monitor_reset_device_called); } -static int output_underrun(struct cras_iodev *iodev) { +static int output_underrun(struct cras_iodev* iodev) { output_underrun_called++; return 0; } - TEST(IoDev, HandleOutputUnderrun) { struct cras_iodev iodev; struct cras_audio_format fmt; unsigned int frames = 240; - int16_t *zeros; + int16_t* zeros; int rc; ResetStubData(); @@ -2174,7 +2176,7 @@ TEST(IoDev, HandleOutputUnderrun) { EXPECT_EQ(0, cras_iodev_output_underrun(&iodev)); EXPECT_EQ(frames, put_buffer_nframes); - zeros = (int16_t *)calloc(frames * 2, sizeof(*zeros)); + zeros = (int16_t*)calloc(frames * 2, sizeof(*zeros)); rc = memcmp(audio_buffer, zeros, frames * 2 * 2); free(zeros); EXPECT_EQ(0, rc); @@ -2185,12 +2187,10 @@ TEST(IoDev, HandleOutputUnderrun) { EXPECT_EQ(1, output_underrun_called); } -static void ext_mod_configure( - struct ext_dsp_module *ext, - unsigned int buffer_size, - unsigned int num_channels, - unsigned int rate) -{ +static void ext_mod_configure(struct ext_dsp_module* ext, + unsigned int buffer_size, + unsigned int num_channels, + unsigned int rate) { ext_mod_configure_called++; } @@ -2211,7 +2211,7 @@ TEST(IoDev, SetExtDspMod) { iodev.state = CRAS_IODEV_STATE_CLOSE; ext.configure = ext_mod_configure; - iodev.dsp_context = reinterpret_cast<cras_dsp_context *>(0xf0f); + iodev.dsp_context = reinterpret_cast<cras_dsp_context*>(0xf0f); cras_dsp_get_pipeline_ret = 0x25; cras_iodev_set_ext_dsp_module(&iodev, &ext); @@ -2269,7 +2269,7 @@ TEST(IoDev, InputDspOffset) { iodev.direction = CRAS_STREAM_INPUT; iodev.buffer_size = 480; - iodev.dsp_context = reinterpret_cast<cras_dsp_context *>(0xf0f); + iodev.dsp_context = reinterpret_cast<cras_dsp_context*>(0xf0f); cras_dsp_get_pipeline_ret = 0x25; input_data_create_ret = &data; @@ -2293,214 +2293,239 @@ TEST(IoDev, InputDspOffset) { EXPECT_EQ(80, rc); } +TEST(IoDev, DropDeviceFramesByTime) { + struct cras_iodev iodev; + struct cras_audio_format fmt; + struct input_data data; + struct timespec ts; + int rc; + + ResetStubData(); + + memset(&iodev, 0, sizeof(iodev)); + fmt.format = SND_PCM_FORMAT_S16_LE; + fmt.frame_rate = 48000; + fmt.num_channels = 2; + iodev.configure_dev = configure_dev; + iodev.format = &fmt; + iodev.state = CRAS_IODEV_STATE_CLOSE; + iodev.get_buffer = get_buffer; + iodev.put_buffer = put_buffer; + iodev.frames_queued = frames_queued; + iodev.direction = CRAS_STREAM_INPUT; + iodev.buffer_size = 480; + input_data_create_ret = &data; + cras_iodev_open(&iodev, 240, &fmt); + rate_estimator_get_rate_ret = 48000.0; + + /* hw_level: 240, drop: 48(1ms). */ + fr_queued = 240; + ts.tv_sec = 0; + ts.tv_nsec = 1000000; + rc = cras_iodev_drop_frames_by_time(&iodev, ts); + EXPECT_EQ(48, rc); + EXPECT_EQ(48, put_buffer_nframes); + EXPECT_EQ(1, rate_estimator_add_frames_called); + EXPECT_EQ(-48, rate_estimator_add_frames_num_frames); + + /* hw_level: 360, drop: 240(5ms). */ + fr_queued = 360; + ts.tv_sec = 0; + ts.tv_nsec = 5000000; + rc = cras_iodev_drop_frames_by_time(&iodev, ts); + EXPECT_EQ(240, rc); + EXPECT_EQ(240, put_buffer_nframes); + EXPECT_EQ(2, rate_estimator_add_frames_called); + EXPECT_EQ(-240, rate_estimator_add_frames_num_frames); + + /* hw_level: 360, drop: 480(10ms). Only drop 360 because of lower hw_level. */ + fr_queued = 360; + ts.tv_sec = 0; + ts.tv_nsec = 10000000; + rc = cras_iodev_drop_frames_by_time(&iodev, ts); + EXPECT_EQ(360, rc); + EXPECT_EQ(360, put_buffer_nframes); + EXPECT_EQ(3, rate_estimator_add_frames_called); + EXPECT_EQ(-360, rate_estimator_add_frames_num_frames); +} + extern "C" { // From libpthread. -int pthread_create(pthread_t *thread, const pthread_attr_t *attr, - void *(*start_routine)(void*), void *arg) { +int pthread_create(pthread_t* thread, + const pthread_attr_t* attr, + void* (*start_routine)(void*), + void* arg) { return 0; } -int pthread_join(pthread_t thread, void **value_ptr) { +int pthread_join(pthread_t thread, void** value_ptr) { return 0; } // Fromt fmt_conv -void cras_channel_remix_convert(struct cras_fmt_conv *conv, - uint8_t *in_buf, - size_t frames) -{ -} +void cras_channel_remix_convert(struct cras_fmt_conv* conv, + uint8_t* in_buf, + size_t frames) {} -size_t cras_fmt_conv_in_frames_to_out(struct cras_fmt_conv *conv, - size_t in_frames) -{ - return in_frames; +size_t cras_fmt_conv_in_frames_to_out(struct cras_fmt_conv* conv, + size_t in_frames) { + return in_frames; } // From buffer_share -struct buffer_share *buffer_share_create(unsigned int buf_sz) { +struct buffer_share* buffer_share_create(unsigned int buf_sz) { return NULL; } -void buffer_share_destroy(struct buffer_share *mix) -{ -} +void buffer_share_destroy(struct buffer_share* mix) {} -int buffer_share_offset_update(struct buffer_share *mix, unsigned int id, +int buffer_share_offset_update(struct buffer_share* mix, + unsigned int id, unsigned int frames) { return 0; } -unsigned int buffer_share_get_new_write_point(struct buffer_share *mix) { +unsigned int buffer_share_get_new_write_point(struct buffer_share* mix) { return buffer_share_get_new_write_point_ret; } -int buffer_share_add_id(struct buffer_share *mix, unsigned int id) { +int buffer_share_add_id(struct buffer_share* mix, unsigned int id) { buffer_share_add_id_called++; return 0; } -int buffer_share_rm_id(struct buffer_share *mix, unsigned int id) { +int buffer_share_rm_id(struct buffer_share* mix, unsigned int id) { return 0; } -unsigned int buffer_share_id_offset(const struct buffer_share *mix, - unsigned int id) -{ +unsigned int buffer_share_id_offset(const struct buffer_share* mix, + unsigned int id) { return 0; } // From cras_system_state. -void cras_system_state_stream_added(enum CRAS_STREAM_DIRECTION direction) { -} +void cras_system_state_stream_added(enum CRAS_STREAM_DIRECTION direction) {} -void cras_system_state_stream_removed(enum CRAS_STREAM_DIRECTION direction) { -} +void cras_system_state_stream_removed(enum CRAS_STREAM_DIRECTION direction) {} // From cras_dsp -struct cras_dsp_context *cras_dsp_context_new(int sample_rate, - const char *purpose) -{ +struct cras_dsp_context* cras_dsp_context_new(int sample_rate, + const char* purpose) { dsp_context_new_sample_rate = sample_rate; dsp_context_new_purpose = purpose; return cras_dsp_context_new_return; } -void cras_dsp_context_free(struct cras_dsp_context *ctx) -{ +void cras_dsp_context_free(struct cras_dsp_context* ctx) { dsp_context_free_called++; } -void cras_dsp_load_pipeline(struct cras_dsp_context *ctx) -{ -} -void cras_dsp_load_dummy_pipeline(struct cras_dsp_context *ctx, - unsigned int num_channels) -{ +void cras_dsp_load_pipeline(struct cras_dsp_context* ctx) {} +void cras_dsp_load_dummy_pipeline(struct cras_dsp_context* ctx, + unsigned int num_channels) { cras_dsp_load_dummy_pipeline_called++; } -void cras_dsp_set_variable_string(struct cras_dsp_context *ctx, const char *key, - const char *value) -{ -} +void cras_dsp_set_variable_string(struct cras_dsp_context* ctx, + const char* key, + const char* value) {} -void cras_dsp_set_variable_boolean(struct cras_dsp_context *ctx, - const char *key, - char value) -{ -} +void cras_dsp_set_variable_boolean(struct cras_dsp_context* ctx, + const char* key, + char value) {} -struct pipeline *cras_dsp_get_pipeline(struct cras_dsp_context *ctx) -{ +struct pipeline* cras_dsp_get_pipeline(struct cras_dsp_context* ctx) { cras_dsp_get_pipeline_called++; - return reinterpret_cast<struct pipeline *>(cras_dsp_get_pipeline_ret); + return reinterpret_cast<struct pipeline*>(cras_dsp_get_pipeline_ret); } -void cras_dsp_put_pipeline(struct cras_dsp_context *ctx) -{ +void cras_dsp_put_pipeline(struct cras_dsp_context* ctx) { cras_dsp_put_pipeline_called++; } -float *cras_dsp_pipeline_get_source_buffer(struct pipeline *pipeline, - int index) -{ +float* cras_dsp_pipeline_get_source_buffer(struct pipeline* pipeline, + int index) { cras_dsp_pipeline_get_source_buffer_called++; return cras_dsp_pipeline_source_buffer[index]; } -float *cras_dsp_pipeline_get_sink_buffer(struct pipeline *pipeline, int index) -{ +float* cras_dsp_pipeline_get_sink_buffer(struct pipeline* pipeline, int index) { cras_dsp_pipeline_get_sink_buffer_called++; return cras_dsp_pipeline_sink_buffer[index]; } -int cras_dsp_pipeline_get_delay(struct pipeline *pipeline) -{ +int cras_dsp_pipeline_get_delay(struct pipeline* pipeline) { cras_dsp_pipeline_get_delay_called++; return 0; } -int cras_dsp_pipeline_apply(struct pipeline *pipeline, - uint8_t *buf, snd_pcm_format_t format, - unsigned int frames) -{ +int cras_dsp_pipeline_apply(struct pipeline* pipeline, + uint8_t* buf, + snd_pcm_format_t format, + unsigned int frames) { cras_dsp_pipeline_apply_called++; cras_dsp_pipeline_apply_sample_count = frames; return 0; } -void cras_dsp_pipeline_add_statistic(struct pipeline *pipeline, - const struct timespec *time_delta, - int samples) -{ -} -void cras_dsp_pipeline_set_sink_ext_module(struct pipeline *pipeline, - struct ext_dsp_module *ext_module) -{ +void cras_dsp_pipeline_add_statistic(struct pipeline* pipeline, + const struct timespec* time_delta, + int samples) {} +void cras_dsp_pipeline_set_sink_ext_module(struct pipeline* pipeline, + struct ext_dsp_module* ext_module) { cras_dsp_pipeline_set_sink_ext_module_called++; } -unsigned int cras_dsp_num_output_channels(const struct cras_dsp_context *ctx) -{ - return cras_dsp_num_output_channels_return; +unsigned int cras_dsp_num_output_channels(const struct cras_dsp_context* ctx) { + return cras_dsp_num_output_channels_return; } -unsigned int cras_dsp_num_input_channels(const struct cras_dsp_context *ctx) -{ - return cras_dsp_num_input_channels_return; +unsigned int cras_dsp_num_input_channels(const struct cras_dsp_context* ctx) { + return cras_dsp_num_input_channels_return; } // From audio thread -int audio_thread_post_message(struct audio_thread *thread, - struct audio_thread_msg *msg) { +int audio_thread_post_message(struct audio_thread* thread, + struct audio_thread_msg* msg) { return 0; } void cras_iodev_list_select_node(enum CRAS_STREAM_DIRECTION direction, - cras_node_id_t node_id) -{ + cras_node_id_t node_id) { select_node_called++; select_node_direction = direction; select_node_id = node_id; } -int cras_iodev_list_node_selected(struct cras_ionode *node) -{ +int cras_iodev_list_node_selected(struct cras_ionode* node) { return node == node_selected; } -void cras_iodev_list_disable_dev(struct cras_iodev *dev) -{ +void cras_iodev_list_disable_dev(struct cras_iodev* dev) { cras_iodev_list_disable_dev_called++; } -void cras_iodev_list_notify_nodes_changed() -{ +void cras_iodev_list_notify_nodes_changed() { notify_nodes_changed_called++; } void cras_iodev_list_notify_active_node_changed( - enum CRAS_STREAM_DIRECTION direction) -{ + enum CRAS_STREAM_DIRECTION direction) { notify_active_node_changed_called++; } -struct cras_audio_area *cras_audio_area_create(int num_channels) { - return NULL; +struct cras_audio_area* cras_audio_area_create(int num_channels) { + return NULL; } -void cras_audio_area_destroy(struct cras_audio_area *area) { -} +void cras_audio_area_destroy(struct cras_audio_area* area) {} -void cras_audio_area_config_channels(struct cras_audio_area *area, - const struct cras_audio_format *fmt) { -} +void cras_audio_area_config_channels(struct cras_audio_area* area, + const struct cras_audio_format* fmt) {} -int cras_audio_format_set_channel_layout(struct cras_audio_format *format, - const int8_t layout[CRAS_CH_MAX]) -{ +int cras_audio_format_set_channel_layout(struct cras_audio_format* format, + const int8_t layout[CRAS_CH_MAX]) { int i; cras_audio_format_set_channel_layout_called++; for (i = 0; i < CRAS_CH_MAX; i++) @@ -2508,9 +2533,8 @@ int cras_audio_format_set_channel_layout(struct cras_audio_format *format, return 0; } -float softvol_get_scaler(unsigned int volume_index) -{ - return softvol_scalers[volume_index]; +float softvol_get_scaler(unsigned int volume_index) { + return softvol_scalers[volume_index]; } size_t cras_system_get_volume() { @@ -2529,17 +2553,22 @@ int cras_system_get_capture_mute() { return 0; } -void cras_scale_buffer(snd_pcm_format_t fmt, uint8_t *buffer, - unsigned int count, float scaler) { +void cras_scale_buffer(snd_pcm_format_t fmt, + uint8_t* buffer, + unsigned int count, + float scaler) { cras_scale_buffer_called++; cras_scale_buffer_fmt = fmt; cras_scale_buffer_scaler = scaler; } -void cras_scale_buffer_increment(snd_pcm_format_t fmt, uint8_t *buff, - unsigned int frame, float scaler, - float increment, float target, int channel) -{ +void cras_scale_buffer_increment(snd_pcm_format_t fmt, + uint8_t* buff, + unsigned int frame, + float scaler, + float increment, + float target, + int channel) { cras_scale_buffer_increment_fmt = fmt; cras_scale_buffer_increment_buff = buff; cras_scale_buffer_increment_frame = frame; @@ -2549,57 +2578,53 @@ void cras_scale_buffer_increment(snd_pcm_format_t fmt, uint8_t *buff, cras_scale_buffer_increment_channel = channel; } -size_t cras_mix_mute_buffer(uint8_t *dst, - size_t frame_bytes, - size_t count) { +size_t cras_mix_mute_buffer(uint8_t* dst, size_t frame_bytes, size_t count) { cras_mix_mute_count = count; return count; } -struct rate_estimator *rate_estimator_create(unsigned int rate, - const struct timespec *window_size, +struct rate_estimator* rate_estimator_create(unsigned int rate, + const struct timespec* window_size, double smooth_factor) { return NULL; } -void rate_estimator_destroy(struct rate_estimator *re) { -} +void rate_estimator_destroy(struct rate_estimator* re) {} -void rate_estimator_add_frames(struct rate_estimator *re, int fr) { +void rate_estimator_add_frames(struct rate_estimator* re, int fr) { rate_estimator_add_frames_called++; rate_estimator_add_frames_num_frames = fr; } -int rate_estimator_check(struct rate_estimator *re, int level, - struct timespec *now) { +int rate_estimator_check(struct rate_estimator* re, + int level, + struct timespec* now) { return 0; } -void rate_estimator_reset_rate(struct rate_estimator *re, unsigned int rate) { -} +void rate_estimator_reset_rate(struct rate_estimator* re, unsigned int rate) {} -double rate_estimator_get_rate(struct rate_estimator *re) { - return 0.0; +double rate_estimator_get_rate(struct rate_estimator* re) { + return rate_estimator_get_rate_ret; } -unsigned int dev_stream_cb_threshold(const struct dev_stream *dev_stream) { +unsigned int dev_stream_cb_threshold(const struct dev_stream* dev_stream) { if (dev_stream->stream) return dev_stream->stream->cb_threshold; return 0; } -int dev_stream_attached_devs(const struct dev_stream *dev_stream) { +int dev_stream_attached_devs(const struct dev_stream* dev_stream) { return 1; } -void dev_stream_update_frames(const struct dev_stream *dev_stream) { -} +void dev_stream_update_frames(const struct dev_stream* dev_stream) {} -int dev_stream_playback_frames(const struct dev_stream *dev_stream) { +int dev_stream_playback_frames(const struct dev_stream* dev_stream) { return dev_stream_playback_frames_ret; } -int cras_device_monitor_reset_device(struct cras_iodev *iodev) { +int cras_device_monitor_reset_device(struct cras_iodev* iodev) { device_monitor_reset_device_called++; return 0; } @@ -2608,9 +2633,13 @@ void cras_ramp_destroy(struct cras_ramp* ramp) { return; } -int cras_ramp_start(struct cras_ramp *ramp, int mute_ramp, float from, float to, - int duration_frames, cras_ramp_cb cb, void *cb_data) -{ +int cras_ramp_start(struct cras_ramp* ramp, + int mute_ramp, + float from, + float to, + int duration_frames, + cras_ramp_cb cb, + void* cb_data) { cras_ramp_start_is_called++; cras_ramp_start_mute_ramp = mute_ramp; cras_ramp_start_from = from; @@ -2621,43 +2650,35 @@ int cras_ramp_start(struct cras_ramp *ramp, int mute_ramp, float from, float to, return 0; } -int cras_ramp_reset(struct cras_ramp *ramp) { +int cras_ramp_reset(struct cras_ramp* ramp) { cras_ramp_reset_is_called++; return 0; } struct cras_ramp_action cras_ramp_get_current_action( - const struct cras_ramp *ramp) { + const struct cras_ramp* ramp) { return cras_ramp_get_current_action_ret; } -int cras_ramp_update_ramped_frames( - struct cras_ramp *ramp, int num_frames) { +int cras_ramp_update_ramped_frames(struct cras_ramp* ramp, int num_frames) { cras_ramp_update_ramped_frames_num_frames = num_frames; return 0; } -int cras_device_monitor_set_device_mute_state(unsigned int dev_idx) -{ +int cras_device_monitor_set_device_mute_state(unsigned int dev_idx) { cras_device_monitor_set_device_mute_state_called++; cras_device_monitor_set_device_mute_state_dev_idx = dev_idx; return 0; } -static void mod_run(struct ext_dsp_module *ext, - unsigned int nframes) -{ -} +static void mod_run(struct ext_dsp_module* ext, unsigned int nframes) {} -static void mod_configure(struct ext_dsp_module *ext, +static void mod_configure(struct ext_dsp_module* ext, unsigned int buffer_size, unsigned int num_channels, - unsigned int rate) -{ -} + unsigned int rate) {} -struct input_data *input_data_create(void *dev_ptr) -{ +struct input_data* input_data_create(void* dev_ptr) { if (input_data_create_ret) { input_data_create_ret->ext.run = mod_run; input_data_create_ret->ext.configure = mod_configure; @@ -2665,21 +2686,15 @@ struct input_data *input_data_create(void *dev_ptr) return input_data_create_ret; } -void input_data_destroy(struct input_data **data) -{ -} -void input_data_set_all_streams_read(struct input_data *data, - unsigned int nframes) -{ -} +void input_data_destroy(struct input_data** data) {} +void input_data_set_all_streams_read(struct input_data* data, + unsigned int nframes) {} -int cras_audio_thread_severe_underrun() -{ +int cras_audio_thread_event_severe_underrun() { return 0; } -int cras_audio_thread_underrun() -{ +int cras_audio_thread_event_underrun() { return 0; } @@ -2690,10 +2705,11 @@ int cras_server_metrics_device_runtime(struct cras_iodev* iodev) { } // extern "C" } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); int rc = RUN_ALL_TESTS(); - audio_thread_event_log_deinit(atlog); + audio_thread_event_log_deinit(atlog, atlog_name); + free(atlog_name); return rc; } diff --git a/cras/src/tests/linear_resampler_unittest.cc b/cras/src/tests/linear_resampler_unittest.cc index 6dbab94e..6095d5b6 100644 --- a/cras/src/tests/linear_resampler_unittest.cc +++ b/cras/src/tests/linear_resampler_unittest.cc @@ -2,10 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <gtest/gtest.h> #include <limits.h> -#include <stdio.h> #include <stdint.h> -#include <gtest/gtest.h> +#include <stdio.h> extern "C" { #include "linear_resampler.h" @@ -17,208 +17,204 @@ static uint8_t in_buf[BUF_SIZE]; static uint8_t out_buf[BUF_SIZE]; TEST(LinearResampler, ReampleToSlightlyLargerRate) { - int i, rc; - unsigned int count; - unsigned int in_offset = 0; - unsigned int out_offset = 0; - struct linear_resampler *lr; - - - memset(in_buf, 0, BUF_SIZE); - memset(out_buf, 0, BUF_SIZE); - for (i = 0; i < 100; i++) { - *((int16_t *)(in_buf + i * 4)) = i * 10; - *((int16_t *)(in_buf + i * 4 + 2)) = i * 20; - } - - lr = linear_resampler_create(2, 4, 48000, 48001); - - count = 20; - rc = linear_resampler_resample(lr, in_buf + 4 * in_offset, &count, - out_buf + 4 * out_offset, 50); - EXPECT_EQ(20, rc); - EXPECT_EQ(20, count); - - in_offset += count; - out_offset += rc; - count = 20; - rc = linear_resampler_resample(lr, in_buf + 4 * in_offset, &count, - out_buf + 4 * out_offset, 15); - EXPECT_EQ(15, rc); - EXPECT_EQ(15, count); - - /* Assert linear interpotation result. */ - for (i = 0; i < 34; i++) { - EXPECT_GE(*(int16_t *)(in_buf + 4 * i), - *(int16_t *)(out_buf + 4 * i)); - EXPECT_LE(*(int16_t *)(in_buf + 4 * i), - *(int16_t *)(out_buf + 4 * (i + 1))); - } - linear_resampler_destroy(lr); + int i, rc; + unsigned int count; + unsigned int in_offset = 0; + unsigned int out_offset = 0; + struct linear_resampler* lr; + + memset(in_buf, 0, BUF_SIZE); + memset(out_buf, 0, BUF_SIZE); + for (i = 0; i < 100; i++) { + *((int16_t*)(in_buf + i * 4)) = i * 10; + *((int16_t*)(in_buf + i * 4 + 2)) = i * 20; + } + + lr = linear_resampler_create(2, 4, 48000, 48001); + + count = 20; + rc = linear_resampler_resample(lr, in_buf + 4 * in_offset, &count, + out_buf + 4 * out_offset, 50); + EXPECT_EQ(20, rc); + EXPECT_EQ(20, count); + + in_offset += count; + out_offset += rc; + count = 20; + rc = linear_resampler_resample(lr, in_buf + 4 * in_offset, &count, + out_buf + 4 * out_offset, 15); + EXPECT_EQ(15, rc); + EXPECT_EQ(15, count); + + /* Assert linear interpotation result. */ + for (i = 0; i < 34; i++) { + EXPECT_GE(*(int16_t*)(in_buf + 4 * i), *(int16_t*)(out_buf + 4 * i)); + EXPECT_LE(*(int16_t*)(in_buf + 4 * i), *(int16_t*)(out_buf + 4 * (i + 1))); + } + linear_resampler_destroy(lr); } TEST(LinearResampler, ResampleIntegerFractionToLarger) { - int i, rc; - unsigned int count; - unsigned int in_offset = 0; - unsigned int out_offset = 0; - struct linear_resampler *lr; - - memset(in_buf, 0, BUF_SIZE); - memset(out_buf, 0, BUF_SIZE); - for (i = 0; i < 100; i++) { - *((int16_t *)(in_buf + i * 4)) = SHRT_MAX - i; - *((int16_t *)(in_buf + i * 4 + 2)) = SHRT_MAX - i * 10; - } - - /* Rate 10 -> 11 */ - lr = linear_resampler_create(2, 4, 10, 11); - - count = 5; - rc = linear_resampler_resample(lr, in_buf + 4 * in_offset, &count, - out_buf + 4 * out_offset, 10); - EXPECT_EQ(5, rc); - EXPECT_EQ(5, count); - - in_offset += count; - out_offset += rc; - count = 6; - /* Assert source rate + 1 frames resample to destination rate + 1 - * frames. */ - rc = linear_resampler_resample(lr, in_buf + 4 * in_offset, &count, - out_buf + 4 * out_offset, 10); - EXPECT_EQ(7, rc); - EXPECT_EQ(6, count); - - in_offset += count; - out_offset += rc; - count = 89; - rc = linear_resampler_resample(lr, in_buf + 4 * in_offset, &count, - out_buf + 4 * out_offset, 100); - EXPECT_EQ(97, rc); - EXPECT_EQ(89, count); - - /* Assert linear interpotation result. */ - for (i = 0; i < 90; i++) { - EXPECT_LE(*(int16_t *)(in_buf + 4 * i), - *(int16_t *)(out_buf + 4 * i)); - EXPECT_LE(*(int16_t *)(in_buf + 4 * i + 2), - *(int16_t *)(out_buf + 4 * i + 2)); - } - linear_resampler_destroy(lr); + int i, rc; + unsigned int count; + unsigned int in_offset = 0; + unsigned int out_offset = 0; + struct linear_resampler* lr; + + memset(in_buf, 0, BUF_SIZE); + memset(out_buf, 0, BUF_SIZE); + for (i = 0; i < 100; i++) { + *((int16_t*)(in_buf + i * 4)) = SHRT_MAX - i; + *((int16_t*)(in_buf + i * 4 + 2)) = SHRT_MAX - i * 10; + } + + /* Rate 10 -> 11 */ + lr = linear_resampler_create(2, 4, 10, 11); + + count = 5; + rc = linear_resampler_resample(lr, in_buf + 4 * in_offset, &count, + out_buf + 4 * out_offset, 10); + EXPECT_EQ(5, rc); + EXPECT_EQ(5, count); + + in_offset += count; + out_offset += rc; + count = 6; + /* Assert source rate + 1 frames resample to destination rate + 1 + * frames. */ + rc = linear_resampler_resample(lr, in_buf + 4 * in_offset, &count, + out_buf + 4 * out_offset, 10); + EXPECT_EQ(7, rc); + EXPECT_EQ(6, count); + + in_offset += count; + out_offset += rc; + count = 89; + rc = linear_resampler_resample(lr, in_buf + 4 * in_offset, &count, + out_buf + 4 * out_offset, 100); + EXPECT_EQ(97, rc); + EXPECT_EQ(89, count); + + /* Assert linear interpotation result. */ + for (i = 0; i < 90; i++) { + EXPECT_LE(*(int16_t*)(in_buf + 4 * i), *(int16_t*)(out_buf + 4 * i)); + EXPECT_LE(*(int16_t*)(in_buf + 4 * i + 2), + *(int16_t*)(out_buf + 4 * i + 2)); + } + linear_resampler_destroy(lr); } TEST(LinearResampler, ResampleIntegerFractionToLess) { - int i, rc; - unsigned int count; - unsigned int in_offset = 0; - unsigned int out_offset = 0; - struct linear_resampler *lr; - - memset(in_buf, 0, BUF_SIZE); - memset(out_buf, 0, BUF_SIZE); - for (i = 0; i < 100; i++) { - *((int16_t *)(in_buf + i * 4)) = SHRT_MIN + i * 10; - *((int16_t *)(in_buf + i * 4 + 2)) = SHRT_MIN + i * 20; - } - - /* Rate 10 -> 9 */ - lr = linear_resampler_create(2, 4, 10, 9); - - count = 6; - rc = linear_resampler_resample(lr, in_buf + 4 * in_offset, &count, - out_buf + 4 * out_offset, 6); - EXPECT_EQ(5, rc); - EXPECT_EQ(6, count); - - in_offset += count; - out_offset += rc; - count = 4; - - /* Assert source rate frames resample to destination rate frames. */ - rc = linear_resampler_resample(lr, in_buf + 4 * in_offset, &count, - out_buf + 4 * out_offset, 4); - EXPECT_EQ(4, rc); - EXPECT_EQ(4, count); - - in_offset += count; - out_offset += rc; - count = 90; - rc = linear_resampler_resample(lr, in_buf + 4 * in_offset, &count, - out_buf + 4 * out_offset, 90); - - /* Assert linear interpotation result. */ - for (i = 0; i < 90; i++) { - EXPECT_LE(*(int16_t *)(in_buf + 4 * i), - *(int16_t *)(out_buf + 4 * i)); - EXPECT_LE(*(int16_t *)(in_buf + 4 * i + 2), - *(int16_t *)(out_buf + 4 * i + 2)); - } - linear_resampler_destroy(lr); + int i, rc; + unsigned int count; + unsigned int in_offset = 0; + unsigned int out_offset = 0; + struct linear_resampler* lr; + + memset(in_buf, 0, BUF_SIZE); + memset(out_buf, 0, BUF_SIZE); + for (i = 0; i < 100; i++) { + *((int16_t*)(in_buf + i * 4)) = SHRT_MIN + i * 10; + *((int16_t*)(in_buf + i * 4 + 2)) = SHRT_MIN + i * 20; + } + + /* Rate 10 -> 9 */ + lr = linear_resampler_create(2, 4, 10, 9); + + count = 6; + rc = linear_resampler_resample(lr, in_buf + 4 * in_offset, &count, + out_buf + 4 * out_offset, 6); + EXPECT_EQ(5, rc); + EXPECT_EQ(6, count); + + in_offset += count; + out_offset += rc; + count = 4; + + /* Assert source rate frames resample to destination rate frames. */ + rc = linear_resampler_resample(lr, in_buf + 4 * in_offset, &count, + out_buf + 4 * out_offset, 4); + EXPECT_EQ(4, rc); + EXPECT_EQ(4, count); + + in_offset += count; + out_offset += rc; + count = 90; + rc = linear_resampler_resample(lr, in_buf + 4 * in_offset, &count, + out_buf + 4 * out_offset, 90); + + /* Assert linear interpotation result. */ + for (i = 0; i < 90; i++) { + EXPECT_LE(*(int16_t*)(in_buf + 4 * i), *(int16_t*)(out_buf + 4 * i)); + EXPECT_LE(*(int16_t*)(in_buf + 4 * i + 2), + *(int16_t*)(out_buf + 4 * i + 2)); + } + linear_resampler_destroy(lr); } TEST(LinearResampler, ResampleIntegerNoSrcBuffer) { - int rc; - unsigned int count; - struct linear_resampler *lr; - - memset(in_buf, 0, BUF_SIZE); - memset(out_buf, 0, BUF_SIZE); - - /* Rate 10 -> 9 */ - lr = linear_resampler_create(2, 4, 10, 9); - - count = 0; - rc = linear_resampler_resample(lr, in_buf, &count, - out_buf, BUF_SIZE); - EXPECT_EQ(0, rc); - EXPECT_EQ(0, count); - linear_resampler_destroy(lr); + int rc; + unsigned int count; + struct linear_resampler* lr; + + memset(in_buf, 0, BUF_SIZE); + memset(out_buf, 0, BUF_SIZE); + + /* Rate 10 -> 9 */ + lr = linear_resampler_create(2, 4, 10, 9); + + count = 0; + rc = linear_resampler_resample(lr, in_buf, &count, out_buf, BUF_SIZE); + EXPECT_EQ(0, rc); + EXPECT_EQ(0, count); + linear_resampler_destroy(lr); } TEST(LinearResampler, ResampleIntegerNoDstBuffer) { - int rc; - unsigned int count; - struct linear_resampler *lr; - - memset(in_buf, 0, BUF_SIZE); - memset(out_buf, 0, BUF_SIZE); - - /* Rate 10 -> 9 */ - lr = linear_resampler_create(2, 4, 10, 9); - - count = BUF_SIZE; - rc = linear_resampler_resample(lr, in_buf, &count, - out_buf, 0); - EXPECT_EQ(0, rc); - EXPECT_EQ(0, count); - linear_resampler_destroy(lr); + int rc; + unsigned int count; + struct linear_resampler* lr; + + memset(in_buf, 0, BUF_SIZE); + memset(out_buf, 0, BUF_SIZE); + + /* Rate 10 -> 9 */ + lr = linear_resampler_create(2, 4, 10, 9); + + count = BUF_SIZE; + rc = linear_resampler_resample(lr, in_buf, &count, out_buf, 0); + EXPECT_EQ(0, rc); + EXPECT_EQ(0, count); + linear_resampler_destroy(lr); } extern "C" { -void cras_mix_add_scale_stride(int fmt, uint8_t *dst, uint8_t *src, - unsigned int count, unsigned int dst_stride, - unsigned int src_stride, float scaler) -{ - unsigned int i; - - for (i = 0; i < count; i++) { - int32_t sum; - sum = *(int16_t *)dst + *(int16_t *)src * scaler; - if (sum > INT16_MAX) - sum = INT16_MAX; - else if (sum < INT16_MIN) - sum = INT16_MIN; - *(int16_t*)dst = sum; - dst += dst_stride; - src += src_stride; - } +void cras_mix_add_scale_stride(int fmt, + uint8_t* dst, + uint8_t* src, + unsigned int count, + unsigned int dst_stride, + unsigned int src_stride, + float scaler) { + unsigned int i; + + for (i = 0; i < count; i++) { + int32_t sum; + sum = *(int16_t*)dst + *(int16_t*)src * scaler; + if (sum > INT16_MAX) + sum = INT16_MAX; + else if (sum < INT16_MIN) + sum = INT16_MIN; + *(int16_t*)dst = sum; + dst += dst_stride; + src += src_stride; + } } } // extern "C" -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/loopback_iodev_unittest.cc b/cras/src/tests/loopback_iodev_unittest.cc index 0a525f91..3cdaffb6 100644 --- a/cras/src/tests/loopback_iodev_unittest.cc +++ b/cras/src/tests/loopback_iodev_unittest.cc @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <gtest/gtest.h> #include <stdio.h> #include <stdlib.h> -#include <gtest/gtest.h> extern "C" { #include "cras_audio_area.h" @@ -24,53 +24,53 @@ static const unsigned int kFrameBytes = 4; static const unsigned int kBufferSize = kBufferFrames * kFrameBytes; static struct timespec time_now; -static cras_audio_area *dummy_audio_area; +static cras_audio_area* dummy_audio_area; static loopback_hook_data_t loop_hook; -static struct cras_iodev *enabled_dev; +static struct cras_iodev* enabled_dev; static unsigned int cras_iodev_list_add_input_called; static unsigned int cras_iodev_list_rm_input_called; static unsigned int cras_iodev_list_set_device_enabled_callback_called; static device_enabled_callback_t device_enabled_callback_cb; static device_disabled_callback_t device_disabled_callback_cb; -static void *device_enabled_callback_cb_data; +static void* device_enabled_callback_cb_data; static int cras_iodev_list_register_loopback_called; static int cras_iodev_list_unregister_loopback_called; -class LoopBackTestSuite : public testing::Test{ - protected: - virtual void SetUp() { - dummy_audio_area = (cras_audio_area*)calloc( - 1, sizeof(*dummy_audio_area) + sizeof(cras_channel_area) * 2); - for (unsigned int i = 0; i < kBufferSize; i++) { - buf_[i] = rand(); - } - fmt_.frame_rate = 48000; - fmt_.num_channels = 2; - fmt_.format = SND_PCM_FORMAT_S16_LE; - - loop_in_ = loopback_iodev_create(LOOPBACK_POST_MIX_PRE_DSP); - EXPECT_EQ(1, cras_iodev_list_add_input_called); - loop_in_->format = &fmt_; - - loop_hook = NULL; - cras_iodev_list_add_input_called = 0; - cras_iodev_list_rm_input_called = 0; - cras_iodev_list_set_device_enabled_callback_called = 0; - cras_iodev_list_register_loopback_called = 0; - cras_iodev_list_unregister_loopback_called = 0; - } - - virtual void TearDown() { - loopback_iodev_destroy(loop_in_); - EXPECT_EQ(1, cras_iodev_list_rm_input_called); - EXPECT_EQ(NULL, device_enabled_callback_cb); - EXPECT_EQ(NULL, device_disabled_callback_cb); - free(dummy_audio_area); +class LoopBackTestSuite : public testing::Test { + protected: + virtual void SetUp() { + dummy_audio_area = (cras_audio_area*)calloc( + 1, sizeof(*dummy_audio_area) + sizeof(cras_channel_area) * 2); + for (unsigned int i = 0; i < kBufferSize; i++) { + buf_[i] = rand(); } - - uint8_t buf_[kBufferSize]; - struct cras_audio_format fmt_; - struct cras_iodev *loop_in_; + fmt_.frame_rate = 48000; + fmt_.num_channels = 2; + fmt_.format = SND_PCM_FORMAT_S16_LE; + + loop_in_ = loopback_iodev_create(LOOPBACK_POST_MIX_PRE_DSP); + EXPECT_EQ(1, cras_iodev_list_add_input_called); + loop_in_->format = &fmt_; + + loop_hook = NULL; + cras_iodev_list_add_input_called = 0; + cras_iodev_list_rm_input_called = 0; + cras_iodev_list_set_device_enabled_callback_called = 0; + cras_iodev_list_register_loopback_called = 0; + cras_iodev_list_unregister_loopback_called = 0; + } + + virtual void TearDown() { + loopback_iodev_destroy(loop_in_); + EXPECT_EQ(1, cras_iodev_list_rm_input_called); + EXPECT_EQ(NULL, device_enabled_callback_cb); + EXPECT_EQ(NULL, device_disabled_callback_cb); + free(dummy_audio_area); + } + + uint8_t buf_[kBufferSize]; + struct cras_audio_format fmt_; + struct cras_iodev* loop_in_; }; TEST_F(LoopBackTestSuite, InstallLoopHook) { @@ -140,7 +140,7 @@ TEST_F(LoopBackTestSuite, SelectDevFromAToB) { // Test how loopback works if there isn't any output devices open. TEST_F(LoopBackTestSuite, OpenIdleSystem) { - cras_audio_area *area; + cras_audio_area* area; unsigned int nread = 1024; struct timespec tstamp; int rc; @@ -172,7 +172,7 @@ TEST_F(LoopBackTestSuite, OpenIdleSystem) { } TEST_F(LoopBackTestSuite, SimpleLoopback) { - cras_audio_area *area; + cras_audio_area* area; unsigned int nframes = 1024; unsigned int nread = 1024; int rc; @@ -184,7 +184,7 @@ TEST_F(LoopBackTestSuite, SimpleLoopback) { enabled_dev = &iodev; loop_in_->configure_dev(loop_in_); - ASSERT_NE(reinterpret_cast<void *>(NULL), loop_hook); + ASSERT_NE(reinterpret_cast<void*>(NULL), loop_hook); // Loopback callback for the hook. loop_hook(buf_, nframes, &fmt_, loop_in_); @@ -207,62 +207,47 @@ TEST_F(LoopBackTestSuite, SimpleLoopback) { /* Stubs */ extern "C" { -void cras_audio_area_config_buf_pointers(struct cras_audio_area *area, - const struct cras_audio_format *fmt, - uint8_t *base_buffer) -{ +void cras_audio_area_config_buf_pointers(struct cras_audio_area* area, + const struct cras_audio_format* fmt, + uint8_t* base_buffer) { dummy_audio_area->channels[0].buf = base_buffer; } -void cras_iodev_free_audio_area(struct cras_iodev *iodev) -{ -} +void cras_iodev_free_audio_area(struct cras_iodev* iodev) {} -void cras_iodev_free_format(struct cras_iodev *iodev) -{ -} +void cras_iodev_free_format(struct cras_iodev* iodev) {} -void cras_iodev_init_audio_area(struct cras_iodev *iodev, int num_channels) -{ +void cras_iodev_init_audio_area(struct cras_iodev* iodev, int num_channels) { iodev->area = dummy_audio_area; } -void cras_iodev_add_node(struct cras_iodev *iodev, struct cras_ionode *node) -{ +void cras_iodev_add_node(struct cras_iodev* iodev, struct cras_ionode* node) { DL_APPEND(iodev->nodes, node); } -void cras_iodev_set_active_node(struct cras_iodev *iodev, - struct cras_ionode *node) -{ -} -void cras_iodev_list_register_loopback( - enum CRAS_LOOPBACK_TYPE loopback_type, - unsigned int output_dev_idx, - loopback_hook_data_t hook_data, - loopback_hook_control_t hook_start, - unsigned int loopback_dev_idx) -{ +void cras_iodev_set_active_node(struct cras_iodev* iodev, + struct cras_ionode* node) {} +void cras_iodev_list_register_loopback(enum CRAS_LOOPBACK_TYPE loopback_type, + unsigned int output_dev_idx, + loopback_hook_data_t hook_data, + loopback_hook_control_t hook_start, + unsigned int loopback_dev_idx) { cras_iodev_list_register_loopback_called++; loop_hook = hook_data; } -void cras_iodev_list_unregister_loopback( - enum CRAS_LOOPBACK_TYPE loopback_type, - unsigned int output_dev_idx, - unsigned int loopback_dev_idx) -{ +void cras_iodev_list_unregister_loopback(enum CRAS_LOOPBACK_TYPE loopback_type, + unsigned int output_dev_idx, + unsigned int loopback_dev_idx) { cras_iodev_list_unregister_loopback_called++; } -int cras_iodev_list_add_input(struct cras_iodev *input) -{ +int cras_iodev_list_add_input(struct cras_iodev* input) { cras_iodev_list_add_input_called++; return 0; } -int cras_iodev_list_rm_input(struct cras_iodev *input) -{ +int cras_iodev_list_rm_input(struct cras_iodev* input) { cras_iodev_list_rm_input_called++; return 0; } @@ -270,8 +255,7 @@ int cras_iodev_list_rm_input(struct cras_iodev *input) int cras_iodev_list_set_device_enabled_callback( device_enabled_callback_t enabled_cb, device_disabled_callback_t disabled_cb, - void *cb_data) -{ + void* cb_data) { cras_iodev_list_set_device_enabled_callback_called++; device_enabled_callback_cb = enabled_cb; device_disabled_callback_cb = disabled_cb; @@ -279,14 +263,13 @@ int cras_iodev_list_set_device_enabled_callback( return 0; } -int clock_gettime(clockid_t clk_id, struct timespec *tp) { +int clock_gettime(clockid_t clk_id, struct timespec* tp) { *tp = time_now; return 0; } -struct cras_iodev *cras_iodev_list_get_first_enabled_iodev( - enum CRAS_STREAM_DIRECTION direction) -{ +struct cras_iodev* cras_iodev_list_get_first_enabled_iodev( + enum CRAS_STREAM_DIRECTION direction) { return enabled_dev; } @@ -294,7 +277,7 @@ struct cras_iodev *cras_iodev_list_get_first_enabled_iodev( } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/metrics_stub.cc b/cras/src/tests/metrics_stub.cc index 78bf2c12..d0f19c37 100644 --- a/cras/src/tests/metrics_stub.cc +++ b/cras/src/tests/metrics_stub.cc @@ -34,4 +34,16 @@ int cras_server_metrics_num_underruns(unsigned num_underruns) { return 0; } -} // extern "C" +int cras_server_metrics_hfp_wideband_support(bool supported) { + return 0; +} + +int cras_server_metrics_hfp_packet_loss(float packet_loss_ratio) { + return 0; +} + +int cras_server_metrics_busyloop(struct timespec* ts, unsigned count) { + return 0; +} + +} // extern "C" diff --git a/cras/src/tests/metrics_stub.h b/cras/src/tests/metrics_stub.h index 32b101a1..1d07e3e0 100644 --- a/cras/src/tests/metrics_stub.h +++ b/cras/src/tests/metrics_stub.h @@ -6,4 +6,4 @@ #ifndef METRICS_STUB_H_ #define METRICS_STUB_H_ -#endif // METRICS_STUB_H_ +#endif // METRICS_STUB_H_ diff --git a/cras/src/tests/mix_unittest.cc b/cras/src/tests/mix_unittest.cc index 1d882e1e..dbbbdb07 100644 --- a/cras/src/tests/mix_unittest.cc +++ b/cras/src/tests/mix_unittest.cc @@ -2,14 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <stdio.h> #include <gtest/gtest.h> +#include <stdio.h> extern "C" { -#include "cras_shm.h" #include "cras_mix.h" +#include "cras_shm.h" #include "cras_types.h" - } namespace { @@ -24,156 +23,156 @@ static inline int need_to_scale(float scaler) { return (scaler < 0.99 || scaler > 1.01); } -class MixTestSuiteS16_LE : public testing::Test{ - protected: - virtual void SetUp() { - fmt_ = SND_PCM_FORMAT_S16_LE; - mix_buffer_ = (int16_t *)malloc(kBufferFrames * 4); - src_buffer_ = static_cast<int16_t*>( - calloc(1, kBufferFrames * 4 + sizeof(cras_audio_shm_header))); +class MixTestSuiteS16_LE : public testing::Test { + protected: + virtual void SetUp() { + fmt_ = SND_PCM_FORMAT_S16_LE; + mix_buffer_ = (int16_t*)malloc(kBufferFrames * 4); + src_buffer_ = static_cast<int16_t*>( + calloc(1, kBufferFrames * 4 + sizeof(cras_audio_shm_header))); - for (size_t i = 0; i < kBufferFrames * 2; i++) { - src_buffer_[i] = i; - mix_buffer_[i] = -i; - } - - compare_buffer_ = (int16_t *)malloc(kBufferFrames * 4); - } - - virtual void TearDown() { - free(mix_buffer_); - free(compare_buffer_); - free(src_buffer_); + for (size_t i = 0; i < kBufferFrames * 2; i++) { + src_buffer_[i] = i; + mix_buffer_[i] = -i; } - void _SetupBuffer() { - for (size_t i = 0; i < kBufferFrames; i++) { - src_buffer_[i] = i + (INT16_MAX >> 2); - mix_buffer_[i] = i + (INT16_MAX >> 2); - compare_buffer_[i] = mix_buffer_[i]; - } - for (size_t i = kBufferFrames; i < kBufferFrames * 2; i++) { - src_buffer_[i] = i - (INT16_MAX >> 2); - mix_buffer_[i] = i - (INT16_MAX >> 2); - compare_buffer_[i] = mix_buffer_[i]; - } - } + compare_buffer_ = (int16_t*)malloc(kBufferFrames * 4); + } - void TestScaleStride(float scaler) { - _SetupBuffer(); - for (size_t i = 0; i < kBufferFrames * 2; i += 2) { - int32_t tmp; - if (need_to_scale(scaler)) - tmp = mix_buffer_[i] + src_buffer_[i/2] * scaler; - else - tmp = mix_buffer_[i] + src_buffer_[i/2]; - if (tmp > INT16_MAX) - tmp = INT16_MAX; - else if (tmp < INT16_MIN) - tmp = INT16_MIN; - compare_buffer_[i] = tmp; - } + virtual void TearDown() { + free(mix_buffer_); + free(compare_buffer_); + free(src_buffer_); + } - cras_mix_add_scale_stride( - fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kBufferFrames, 4, 2, scaler); + void _SetupBuffer() { + for (size_t i = 0; i < kBufferFrames; i++) { + src_buffer_[i] = i + (INT16_MAX >> 2); + mix_buffer_[i] = i + (INT16_MAX >> 2); + compare_buffer_[i] = mix_buffer_[i]; + } + for (size_t i = kBufferFrames; i < kBufferFrames * 2; i++) { + src_buffer_[i] = i - (INT16_MAX >> 2); + mix_buffer_[i] = i - (INT16_MAX >> 2); + compare_buffer_[i] = mix_buffer_[i]; + } + } - EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4)); + void TestScaleStride(float scaler) { + _SetupBuffer(); + for (size_t i = 0; i < kBufferFrames * 2; i += 2) { + int32_t tmp; + if (need_to_scale(scaler)) + tmp = mix_buffer_[i] + src_buffer_[i / 2] * scaler; + else + tmp = mix_buffer_[i] + src_buffer_[i / 2]; + if (tmp > INT16_MAX) + tmp = INT16_MAX; + else if (tmp < INT16_MIN) + tmp = INT16_MIN; + compare_buffer_[i] = tmp; } - void ScaleIncrement(float start_scaler, float increment, float target) { - float scaler = start_scaler; - for (size_t i = 0; i < kBufferFrames * 2; i++) { - float applied_scaler = scaler; + cras_mix_add_scale_stride(fmt_, (uint8_t*)mix_buffer_, + (uint8_t*)src_buffer_, kBufferFrames, 4, 2, + scaler); - if ((applied_scaler > target && increment > 0) || - (applied_scaler < target && increment < 0)) - applied_scaler = target; + EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4)); + } - if (applied_scaler > kMaxVolumeToScale) { - } else if (applied_scaler < kMinVolumeToScale) { - compare_buffer_[i] = 0; - } else { - compare_buffer_[i] = mix_buffer_[i] * applied_scaler; - } + void ScaleIncrement(float start_scaler, float increment, float target) { + float scaler = start_scaler; + for (size_t i = 0; i < kBufferFrames * 2; i++) { + float applied_scaler = scaler; - if (i % 2 == 1) - scaler += increment; + if ((applied_scaler > target && increment > 0) || + (applied_scaler < target && increment < 0)) + applied_scaler = target; + + if (applied_scaler > kMaxVolumeToScale) { + } else if (applied_scaler < kMinVolumeToScale) { + compare_buffer_[i] = 0; + } else { + compare_buffer_[i] = mix_buffer_[i] * applied_scaler; } + + if (i % 2 == 1) + scaler += increment; } + } - int16_t *mix_buffer_; - int16_t *src_buffer_; - int16_t *compare_buffer_; + int16_t* mix_buffer_; + int16_t* src_buffer_; + int16_t* compare_buffer_; snd_pcm_format_t fmt_; }; TEST_F(MixTestSuiteS16_LE, MixFirst) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 0, 1.0); - EXPECT_EQ(0, memcmp(mix_buffer_, src_buffer_, kBufferFrames*4)); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 0, 1.0); + EXPECT_EQ(0, memcmp(mix_buffer_, src_buffer_, kBufferFrames * 4)); } TEST_F(MixTestSuiteS16_LE, MixTwo) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 0, 1.0); - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 1, 0, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 0, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 1, 0, 1.0); for (size_t i = 0; i < kBufferFrames * 2; i++) compare_buffer_[i] = src_buffer_[i] * 2; - EXPECT_EQ(0, memcmp(mix_buffer_, compare_buffer_, kBufferFrames*4)); + EXPECT_EQ(0, memcmp(mix_buffer_, compare_buffer_, kBufferFrames * 4)); } TEST_F(MixTestSuiteS16_LE, MixTwoClip) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 0, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 0, 1.0); for (size_t i = 0; i < kBufferFrames * 2; i++) src_buffer_[i] = INT16_MAX; - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 1, 0, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 1, 0, 1.0); for (size_t i = 0; i < kBufferFrames * 2; i++) compare_buffer_[i] = INT16_MAX; - EXPECT_EQ(0, memcmp(mix_buffer_, compare_buffer_, kBufferFrames*4)); + EXPECT_EQ(0, memcmp(mix_buffer_, compare_buffer_, kBufferFrames * 4)); } TEST_F(MixTestSuiteS16_LE, MixFirstMuted) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 1, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 1, 1.0); for (size_t i = 0; i < kBufferFrames * 2; i++) compare_buffer_[i] = 0; - EXPECT_EQ(0, memcmp(mix_buffer_, compare_buffer_, kBufferFrames*4)); + EXPECT_EQ(0, memcmp(mix_buffer_, compare_buffer_, kBufferFrames * 4)); } TEST_F(MixTestSuiteS16_LE, MixFirstZeroVolume) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 0, 0.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 0, 0.0); for (size_t i = 0; i < kBufferFrames * 2; i++) compare_buffer_[i] = 0; - EXPECT_EQ(0, memcmp(mix_buffer_, compare_buffer_, kBufferFrames*4)); + EXPECT_EQ(0, memcmp(mix_buffer_, compare_buffer_, kBufferFrames * 4)); } TEST_F(MixTestSuiteS16_LE, MixFirstHalfVolume) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 0, 0.5); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 0, 0.5); for (size_t i = 0; i < kBufferFrames * 2; i++) compare_buffer_[i] = src_buffer_[i] * 0.5; - EXPECT_EQ(0, memcmp(mix_buffer_, compare_buffer_, kBufferFrames*4)); + EXPECT_EQ(0, memcmp(mix_buffer_, compare_buffer_, kBufferFrames * 4)); } TEST_F(MixTestSuiteS16_LE, MixTwoSecondHalfVolume) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 0, 1.0); - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 1, 0, 0.5); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 0, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 1, 0, 0.5); for (size_t i = 0; i < kBufferFrames * 2; i++) compare_buffer_[i] = src_buffer_[i] + (int16_t)(src_buffer_[i] * 0.5); - EXPECT_EQ(0, memcmp(mix_buffer_, compare_buffer_, kBufferFrames*4)); + EXPECT_EQ(0, memcmp(mix_buffer_, compare_buffer_, kBufferFrames * 4)); } TEST_F(MixTestSuiteS16_LE, ScaleFullVolumeIncrement) { @@ -185,9 +184,8 @@ TEST_F(MixTestSuiteS16_LE, ScaleFullVolumeIncrement) { _SetupBuffer(); // Scale full volume with positive increment will not change buffer. memcpy(compare_buffer_, src_buffer_, kBufferFrames * 4); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4)); } @@ -201,9 +199,8 @@ TEST_F(MixTestSuiteS16_LE, ScaleMinVolumeIncrement) { _SetupBuffer(); // Scale min volume with negative increment will change buffer to zeros. memset(compare_buffer_, 0, kBufferFrames * 4); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4)); } @@ -217,9 +214,8 @@ TEST_F(MixTestSuiteS16_LE, ScaleVolumePositiveIncrement) { _SetupBuffer(); ScaleIncrement(start_scaler, increment, target); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4)); } @@ -232,9 +228,8 @@ TEST_F(MixTestSuiteS16_LE, ScaleVolumeNegativeIncrement) { _SetupBuffer(); ScaleIncrement(start_scaler, increment, target); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4)); } @@ -248,9 +243,8 @@ TEST_F(MixTestSuiteS16_LE, ScaleVolumeStartFullNegativeIncrement) { _SetupBuffer(); ScaleIncrement(start_scaler, increment, target); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4)); } @@ -264,9 +258,8 @@ TEST_F(MixTestSuiteS16_LE, ScaleVolumeStartZeroPositiveIncrement) { _SetupBuffer(); ScaleIncrement(start_scaler, increment, target); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4)); } @@ -280,9 +273,8 @@ TEST_F(MixTestSuiteS16_LE, ScaleVolumePositiveIncrementCappedByTarget) { _SetupBuffer(); ScaleIncrement(start_scaler, increment, target); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4)); } @@ -295,22 +287,21 @@ TEST_F(MixTestSuiteS16_LE, ScaleVolumeNegativeIncrementCappedByTarget) { _SetupBuffer(); ScaleIncrement(start_scaler, increment, target); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4)); } TEST_F(MixTestSuiteS16_LE, ScaleFullVolume) { memcpy(compare_buffer_, src_buffer_, kBufferFrames * 4); - cras_scale_buffer(fmt_, (uint8_t *)mix_buffer_, kNumSamples, 0.999999999); + cras_scale_buffer(fmt_, (uint8_t*)mix_buffer_, kNumSamples, 0.999999999); EXPECT_EQ(0, memcmp(compare_buffer_, src_buffer_, kBufferFrames * 4)); } TEST_F(MixTestSuiteS16_LE, ScaleMinVolume) { memset(compare_buffer_, 0, kBufferFrames * 4); - cras_scale_buffer(fmt_, (uint8_t *)src_buffer_, kNumSamples, 0.0000000001); + cras_scale_buffer(fmt_, (uint8_t*)src_buffer_, kNumSamples, 0.0000000001); EXPECT_EQ(0, memcmp(compare_buffer_, src_buffer_, kBufferFrames * 4)); } @@ -318,124 +309,121 @@ TEST_F(MixTestSuiteS16_LE, ScaleMinVolume) { TEST_F(MixTestSuiteS16_LE, ScaleHalfVolume) { for (size_t i = 0; i < kBufferFrames * 2; i++) compare_buffer_[i] = src_buffer_[i] * 0.5; - cras_scale_buffer(fmt_, (uint8_t *)src_buffer_, kNumSamples, 0.5); + cras_scale_buffer(fmt_, (uint8_t*)src_buffer_, kNumSamples, 0.5); EXPECT_EQ(0, memcmp(compare_buffer_, src_buffer_, kBufferFrames * 4)); } - - TEST_F(MixTestSuiteS16_LE, StrideCopy) { TestScaleStride(1.0); TestScaleStride(100); TestScaleStride(0.5); } -class MixTestSuiteS24_LE : public testing::Test{ - protected: - virtual void SetUp() { - fmt_ = SND_PCM_FORMAT_S24_LE; - fr_bytes_ = 4 * kNumChannels; - mix_buffer_ = (int32_t *)malloc(kBufferFrames * fr_bytes_); - src_buffer_ = static_cast<int32_t*>( - calloc(1, kBufferFrames * fr_bytes_ + sizeof(cras_audio_shm_header))); - - for (size_t i = 0; i < kBufferFrames * 2; i++) { - src_buffer_[i] = i; - mix_buffer_[i] = -i; - } - - compare_buffer_ = (int32_t *)malloc(kBufferFrames * fr_bytes_); - } +class MixTestSuiteS24_LE : public testing::Test { + protected: + virtual void SetUp() { + fmt_ = SND_PCM_FORMAT_S24_LE; + fr_bytes_ = 4 * kNumChannels; + mix_buffer_ = (int32_t*)malloc(kBufferFrames * fr_bytes_); + src_buffer_ = static_cast<int32_t*>( + calloc(1, kBufferFrames * fr_bytes_ + sizeof(cras_audio_shm_header))); - virtual void TearDown() { - free(mix_buffer_); - free(compare_buffer_); - free(src_buffer_); + for (size_t i = 0; i < kBufferFrames * 2; i++) { + src_buffer_[i] = i; + mix_buffer_[i] = -i; } - void _SetupBuffer() { - for (size_t i = 0; i < kBufferFrames; i++) { - src_buffer_[i] = i + (0x007fffff >> 2); - mix_buffer_[i] = i + (0x007fffff >> 2); - compare_buffer_[i] = mix_buffer_[i]; - } - for (size_t i = kBufferFrames; i < kBufferFrames * 2; i++) { - src_buffer_[i] = -i - (0x007fffff >> 2); - mix_buffer_[i] = -i - (0x007fffff >> 2); - compare_buffer_[i] = mix_buffer_[i]; - } - } + compare_buffer_ = (int32_t*)malloc(kBufferFrames * fr_bytes_); + } - void TestScaleStride(float scaler) { - _SetupBuffer(); - for (size_t i = 0; i < kBufferFrames * 2; i += 2) { - int32_t tmp; - if (need_to_scale(scaler)) - tmp = mix_buffer_[i] + Scale(src_buffer_[i/2], scaler); - else - tmp = mix_buffer_[i] + src_buffer_[i/2]; - if (tmp > 0x007fffff) - tmp = 0x007fffff; - else if (tmp < (int32_t)0xff800000) - tmp = (int32_t)0xff800000; - compare_buffer_[i] = tmp; - } + virtual void TearDown() { + free(mix_buffer_); + free(compare_buffer_); + free(src_buffer_); + } - cras_mix_add_scale_stride( - fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kBufferFrames, 8, 4, scaler); + void _SetupBuffer() { + for (size_t i = 0; i < kBufferFrames; i++) { + src_buffer_[i] = i + (0x007fffff >> 2); + mix_buffer_[i] = i + (0x007fffff >> 2); + compare_buffer_[i] = mix_buffer_[i]; + } + for (size_t i = kBufferFrames; i < kBufferFrames * 2; i++) { + src_buffer_[i] = -i - (0x007fffff >> 2); + mix_buffer_[i] = -i - (0x007fffff >> 2); + compare_buffer_[i] = mix_buffer_[i]; + } + } - EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 8)); + void TestScaleStride(float scaler) { + _SetupBuffer(); + for (size_t i = 0; i < kBufferFrames * 2; i += 2) { + int32_t tmp; + if (need_to_scale(scaler)) + tmp = mix_buffer_[i] + Scale(src_buffer_[i / 2], scaler); + else + tmp = mix_buffer_[i] + src_buffer_[i / 2]; + if (tmp > 0x007fffff) + tmp = 0x007fffff; + else if (tmp < (int32_t)0xff800000) + tmp = (int32_t)0xff800000; + compare_buffer_[i] = tmp; } - void ScaleIncrement(float start_scaler, float increment, float target) { - float scaler = start_scaler; + cras_mix_add_scale_stride(fmt_, (uint8_t*)mix_buffer_, + (uint8_t*)src_buffer_, kBufferFrames, 8, 4, + scaler); - for (size_t i = 0; i < kBufferFrames * 2; i++) { - float applied_scaler = scaler; + EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 8)); + } - if ((applied_scaler > target && increment > 0) || - (applied_scaler < target && increment < 0)) - applied_scaler = target; + void ScaleIncrement(float start_scaler, float increment, float target) { + float scaler = start_scaler; + for (size_t i = 0; i < kBufferFrames * 2; i++) { + float applied_scaler = scaler; - if (applied_scaler > kMaxVolumeToScale) { - } else if (applied_scaler < kMinVolumeToScale) { - compare_buffer_[i] = 0; - } else { - compare_buffer_[i] = Scale(mix_buffer_[i], applied_scaler); - } + if ((applied_scaler > target && increment > 0) || + (applied_scaler < target && increment < 0)) + applied_scaler = target; - if (i % 2 == 1) - scaler += increment; + if (applied_scaler > kMaxVolumeToScale) { + } else if (applied_scaler < kMinVolumeToScale) { + compare_buffer_[i] = 0; + } else { + compare_buffer_[i] = Scale(mix_buffer_[i], applied_scaler); } - } - int32_t Scale(int32_t value, float scaler) { - value = ((uint32_t)(value & 0x00ffffff)) << 8; - value *= scaler; - return (value >> 8) & 0x00ffffff; + if (i % 2 == 1) + scaler += increment; } + } - int32_t *mix_buffer_; - int32_t *src_buffer_; - int32_t *compare_buffer_; + int32_t Scale(int32_t value, float scaler) { + value = ((uint32_t)(value & 0x00ffffff)) << 8; + value *= scaler; + return (value >> 8) & 0x00ffffff; + } + + int32_t* mix_buffer_; + int32_t* src_buffer_; + int32_t* compare_buffer_; snd_pcm_format_t fmt_; unsigned int fr_bytes_; }; TEST_F(MixTestSuiteS24_LE, MixFirst) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 0, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 0, 1.0); EXPECT_EQ(0, memcmp(mix_buffer_, src_buffer_, kBufferFrames * fr_bytes_)); } TEST_F(MixTestSuiteS24_LE, MixTwo) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 0, 1.0); - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 1, 0, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 0, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 1, 0, 1.0); for (size_t i = 0; i < kBufferFrames * 2; i++) compare_buffer_[i] = Scale(src_buffer_[i], 2); @@ -443,12 +431,12 @@ TEST_F(MixTestSuiteS24_LE, MixTwo) { } TEST_F(MixTestSuiteS24_LE, MixTwoClip) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 0, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 0, 1.0); for (size_t i = 0; i < kBufferFrames * 2; i++) src_buffer_[i] = 0x007fffff; - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 1, 0, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 1, 0, 1.0); for (size_t i = 0; i < kBufferFrames * 2; i++) compare_buffer_[i] = 0x007fffff; @@ -456,8 +444,8 @@ TEST_F(MixTestSuiteS24_LE, MixTwoClip) { } TEST_F(MixTestSuiteS24_LE, MixFirstMuted) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 1, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 1, 1.0); for (size_t i = 0; i < kBufferFrames * 2; i++) compare_buffer_[i] = 0; @@ -465,8 +453,8 @@ TEST_F(MixTestSuiteS24_LE, MixFirstMuted) { } TEST_F(MixTestSuiteS24_LE, MixFirstZeroVolume) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 0, 0.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 0, 0.0); for (size_t i = 0; i < kBufferFrames * 2; i++) compare_buffer_[i] = 0; @@ -474,8 +462,8 @@ TEST_F(MixTestSuiteS24_LE, MixFirstZeroVolume) { } TEST_F(MixTestSuiteS24_LE, MixFirstHalfVolume) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 0, 0.5); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 0, 0.5); for (size_t i = 0; i < kBufferFrames * 2; i++) compare_buffer_[i] = Scale(src_buffer_[i], 0.5); @@ -483,10 +471,10 @@ TEST_F(MixTestSuiteS24_LE, MixFirstHalfVolume) { } TEST_F(MixTestSuiteS24_LE, MixTwoSecondHalfVolume) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 0, 1.0); - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 1, 0, 0.5); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 0, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 1, 0, 0.5); for (size_t i = 0; i < kBufferFrames * 2; i++) compare_buffer_[i] = src_buffer_[i] + Scale(src_buffer_[i], 0.5); @@ -502,9 +490,8 @@ TEST_F(MixTestSuiteS24_LE, ScaleFullVolumeIncrement) { _SetupBuffer(); // Scale full volume with positive increment will not change buffer. memcpy(compare_buffer_, src_buffer_, kBufferFrames * fr_bytes_); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_)); } @@ -518,9 +505,8 @@ TEST_F(MixTestSuiteS24_LE, ScaleMinVolumeIncrement) { _SetupBuffer(); // Scale min volume with negative increment will change buffer to zeros. memset(compare_buffer_, 0, kBufferFrames * fr_bytes_); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_)); } @@ -534,9 +520,8 @@ TEST_F(MixTestSuiteS24_LE, ScaleVolumePositiveIncrement) { _SetupBuffer(); ScaleIncrement(start_scaler, increment, target); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_)); } @@ -549,9 +534,8 @@ TEST_F(MixTestSuiteS24_LE, ScaleVolumeNegativeIncrement) { _SetupBuffer(); ScaleIncrement(start_scaler, increment, target); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_)); } @@ -565,9 +549,8 @@ TEST_F(MixTestSuiteS24_LE, ScaleVolumeStartFullNegativeIncrement) { _SetupBuffer(); ScaleIncrement(start_scaler, increment, target); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4)); } @@ -581,9 +564,8 @@ TEST_F(MixTestSuiteS24_LE, ScaleVolumeStartZeroPositiveIncrement) { _SetupBuffer(); ScaleIncrement(start_scaler, increment, target); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4)); } @@ -597,9 +579,8 @@ TEST_F(MixTestSuiteS24_LE, ScaleVolumePositiveIncrementCappedByTarget) { _SetupBuffer(); ScaleIncrement(start_scaler, increment, target); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_)); } @@ -612,22 +593,21 @@ TEST_F(MixTestSuiteS24_LE, ScaleVolumeNegativeIncrementCappedByTarget) { _SetupBuffer(); ScaleIncrement(start_scaler, increment, target); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_)); } TEST_F(MixTestSuiteS24_LE, ScaleFullVolume) { - memcpy(compare_buffer_, src_buffer_, kBufferFrames * fr_bytes_); - cras_scale_buffer(fmt_, (uint8_t *)mix_buffer_, kNumSamples, 0.999999999); + memcpy(compare_buffer_, src_buffer_, kBufferFrames * fr_bytes_); + cras_scale_buffer(fmt_, (uint8_t*)mix_buffer_, kNumSamples, 0.999999999); EXPECT_EQ(0, memcmp(compare_buffer_, src_buffer_, kBufferFrames * fr_bytes_)); } TEST_F(MixTestSuiteS24_LE, ScaleMinVolume) { memset(compare_buffer_, 0, kBufferFrames * fr_bytes_); - cras_scale_buffer(fmt_, (uint8_t *)src_buffer_, kNumSamples, 0.0000000001); + cras_scale_buffer(fmt_, (uint8_t*)src_buffer_, kNumSamples, 0.0000000001); EXPECT_EQ(0, memcmp(compare_buffer_, src_buffer_, kBufferFrames * fr_bytes_)); } @@ -635,7 +615,7 @@ TEST_F(MixTestSuiteS24_LE, ScaleMinVolume) { TEST_F(MixTestSuiteS24_LE, ScaleHalfVolume) { for (size_t i = 0; i < kBufferFrames * 2; i++) compare_buffer_[i] = Scale(src_buffer_[i], 0.5); - cras_scale_buffer(fmt_, (uint8_t *)src_buffer_, kNumSamples, 0.5); + cras_scale_buffer(fmt_, (uint8_t*)src_buffer_, kNumSamples, 0.5); EXPECT_EQ(0, memcmp(compare_buffer_, src_buffer_, kBufferFrames * fr_bytes_)); } @@ -646,104 +626,104 @@ TEST_F(MixTestSuiteS24_LE, StrideCopy) { TestScaleStride(0.1); } -class MixTestSuiteS32_LE : public testing::Test{ - protected: - virtual void SetUp() { - fmt_ = SND_PCM_FORMAT_S32_LE; - fr_bytes_ = 4 * kNumChannels; - mix_buffer_ = (int32_t *)malloc(kBufferFrames * fr_bytes_); - src_buffer_ = static_cast<int32_t*>( - calloc(1, kBufferFrames * fr_bytes_ + sizeof(cras_audio_shm_header))); - - for (size_t i = 0; i < kBufferFrames * 2; i++) { - src_buffer_[i] = i; - mix_buffer_[i] = -i; - } - - compare_buffer_ = (int32_t *)malloc(kBufferFrames * fr_bytes_); - } +class MixTestSuiteS32_LE : public testing::Test { + protected: + virtual void SetUp() { + fmt_ = SND_PCM_FORMAT_S32_LE; + fr_bytes_ = 4 * kNumChannels; + mix_buffer_ = (int32_t*)malloc(kBufferFrames * fr_bytes_); + src_buffer_ = static_cast<int32_t*>( + calloc(1, kBufferFrames * fr_bytes_ + sizeof(cras_audio_shm_header))); - virtual void TearDown() { - free(mix_buffer_); - free(compare_buffer_); - free(src_buffer_); + for (size_t i = 0; i < kBufferFrames * 2; i++) { + src_buffer_[i] = i; + mix_buffer_[i] = -i; } - void _SetupBuffer() { - for (size_t i = 0; i < kBufferFrames; i++) { - src_buffer_[i] = i + (INT32_MAX >> 2); - mix_buffer_[i] = i + (INT32_MAX >> 2); - compare_buffer_[i] = mix_buffer_[i]; - } - for (size_t i = kBufferFrames; i < kBufferFrames * 2; i++) { - src_buffer_[i] = i - (INT32_MAX >> 2); - mix_buffer_[i] = i - (INT32_MAX >> 2); - compare_buffer_[i] = mix_buffer_[i]; - } - } + compare_buffer_ = (int32_t*)malloc(kBufferFrames * fr_bytes_); + } - void TestScaleStride(float scaler) { - _SetupBuffer(); - for (size_t i = 0; i < kBufferFrames * 2; i += 2) { - int64_t tmp; - if (need_to_scale(scaler)) - tmp = mix_buffer_[i] + src_buffer_[i/2] * scaler; - else - tmp = mix_buffer_[i] + src_buffer_[i/2]; - if (tmp > INT32_MAX) - tmp = INT32_MAX; - else if (tmp < INT32_MIN) - tmp = INT32_MIN; - compare_buffer_[i] = tmp; - } + virtual void TearDown() { + free(mix_buffer_); + free(compare_buffer_); + free(src_buffer_); + } - cras_mix_add_scale_stride( - fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kBufferFrames, 8, 4, scaler); + void _SetupBuffer() { + for (size_t i = 0; i < kBufferFrames; i++) { + src_buffer_[i] = i + (INT32_MAX >> 2); + mix_buffer_[i] = i + (INT32_MAX >> 2); + compare_buffer_[i] = mix_buffer_[i]; + } + for (size_t i = kBufferFrames; i < kBufferFrames * 2; i++) { + src_buffer_[i] = i - (INT32_MAX >> 2); + mix_buffer_[i] = i - (INT32_MAX >> 2); + compare_buffer_[i] = mix_buffer_[i]; + } + } - EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 8)); + void TestScaleStride(float scaler) { + _SetupBuffer(); + for (size_t i = 0; i < kBufferFrames * 2; i += 2) { + int64_t tmp; + if (need_to_scale(scaler)) + tmp = mix_buffer_[i] + src_buffer_[i / 2] * scaler; + else + tmp = mix_buffer_[i] + src_buffer_[i / 2]; + if (tmp > INT32_MAX) + tmp = INT32_MAX; + else if (tmp < INT32_MIN) + tmp = INT32_MIN; + compare_buffer_[i] = tmp; } - void ScaleIncrement(float start_scaler, float increment, float target) { - float scaler = start_scaler; + cras_mix_add_scale_stride(fmt_, (uint8_t*)mix_buffer_, + (uint8_t*)src_buffer_, kBufferFrames, 8, 4, + scaler); - for (size_t i = 0; i < kBufferFrames * 2; i++) { - float applied_scaler = scaler; + EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 8)); + } + + void ScaleIncrement(float start_scaler, float increment, float target) { + float scaler = start_scaler; - if ((applied_scaler > target && increment > 0) || - (applied_scaler < target && increment < 0)) - applied_scaler = target; + for (size_t i = 0; i < kBufferFrames * 2; i++) { + float applied_scaler = scaler; - if (applied_scaler > kMaxVolumeToScale) { - } else if (applied_scaler < kMinVolumeToScale) { - compare_buffer_[i] = 0; - } else { - compare_buffer_[i] = mix_buffer_[i] * applied_scaler; - } + if ((applied_scaler > target && increment > 0) || + (applied_scaler < target && increment < 0)) + applied_scaler = target; - if (i % 2 == 1) - scaler += increment; + if (applied_scaler > kMaxVolumeToScale) { + } else if (applied_scaler < kMinVolumeToScale) { + compare_buffer_[i] = 0; + } else { + compare_buffer_[i] = mix_buffer_[i] * applied_scaler; } + + if (i % 2 == 1) + scaler += increment; } + } - int32_t *mix_buffer_; - int32_t *src_buffer_; - int32_t *compare_buffer_; + int32_t* mix_buffer_; + int32_t* src_buffer_; + int32_t* compare_buffer_; snd_pcm_format_t fmt_; unsigned int fr_bytes_; }; TEST_F(MixTestSuiteS32_LE, MixFirst) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 0, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 0, 1.0); EXPECT_EQ(0, memcmp(mix_buffer_, src_buffer_, kBufferFrames * fr_bytes_)); } TEST_F(MixTestSuiteS32_LE, MixTwo) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 0, 1.0); - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 1, 0, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 0, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 1, 0, 1.0); for (size_t i = 0; i < kBufferFrames * 2; i++) compare_buffer_[i] = src_buffer_[i] * 2; @@ -751,12 +731,12 @@ TEST_F(MixTestSuiteS32_LE, MixTwo) { } TEST_F(MixTestSuiteS32_LE, MixTwoClip) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 0, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 0, 1.0); for (size_t i = 0; i < kBufferFrames * 2; i++) src_buffer_[i] = INT32_MAX; - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 1, 0, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 1, 0, 1.0); for (size_t i = 0; i < kBufferFrames * 2; i++) compare_buffer_[i] = INT32_MAX; @@ -764,8 +744,8 @@ TEST_F(MixTestSuiteS32_LE, MixTwoClip) { } TEST_F(MixTestSuiteS32_LE, MixFirstMuted) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 1, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 1, 1.0); for (size_t i = 0; i < kBufferFrames * 2; i++) compare_buffer_[i] = 0; @@ -773,8 +753,8 @@ TEST_F(MixTestSuiteS32_LE, MixFirstMuted) { } TEST_F(MixTestSuiteS32_LE, MixFirstZeroVolume) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 0, 0.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 0, 0.0); for (size_t i = 0; i < kBufferFrames * 2; i++) compare_buffer_[i] = 0; @@ -782,8 +762,8 @@ TEST_F(MixTestSuiteS32_LE, MixFirstZeroVolume) { } TEST_F(MixTestSuiteS32_LE, MixFirstHalfVolume) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 0, 0.5); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 0, 0.5); for (size_t i = 0; i < kBufferFrames * 2; i++) compare_buffer_[i] = src_buffer_[i] * 0.5; @@ -791,10 +771,10 @@ TEST_F(MixTestSuiteS32_LE, MixFirstHalfVolume) { } TEST_F(MixTestSuiteS32_LE, MixTwoSecondHalfVolume) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 0, 1.0); - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 1, 0, 0.5); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 0, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 1, 0, 0.5); for (size_t i = 0; i < kBufferFrames * 2; i++) compare_buffer_[i] = src_buffer_[i] + (int32_t)(src_buffer_[i] * 0.5); @@ -810,9 +790,8 @@ TEST_F(MixTestSuiteS32_LE, ScaleFullVolumeIncrement) { _SetupBuffer(); // Scale full volume with positive increment will not change buffer. memcpy(compare_buffer_, src_buffer_, kBufferFrames * fr_bytes_); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_)); } @@ -826,9 +805,8 @@ TEST_F(MixTestSuiteS32_LE, ScaleMinVolumeIncrement) { _SetupBuffer(); // Scale min volume with negative increment will change buffer to zeros. memset(compare_buffer_, 0, kBufferFrames * fr_bytes_); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_)); } @@ -842,9 +820,8 @@ TEST_F(MixTestSuiteS32_LE, ScaleVolumePositiveIncrement) { _SetupBuffer(); ScaleIncrement(start_scaler, increment, target); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_)); } @@ -857,9 +834,8 @@ TEST_F(MixTestSuiteS32_LE, ScaleVolumeNegativeIncrement) { _SetupBuffer(); ScaleIncrement(start_scaler, increment, target); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_)); } @@ -873,9 +849,8 @@ TEST_F(MixTestSuiteS32_LE, ScaleVolumeStartFullNegativeIncrement) { _SetupBuffer(); ScaleIncrement(start_scaler, increment, target); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4)); } @@ -889,9 +864,8 @@ TEST_F(MixTestSuiteS32_LE, ScaleVolumeStartZeroPositiveIncrement) { _SetupBuffer(); ScaleIncrement(start_scaler, increment, target); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4)); } @@ -905,9 +879,8 @@ TEST_F(MixTestSuiteS32_LE, ScaleVolumePositiveIncrementCappedByTarget) { _SetupBuffer(); ScaleIncrement(start_scaler, increment, target); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_)); } @@ -920,22 +893,21 @@ TEST_F(MixTestSuiteS32_LE, ScaleVolumeNegativeIncrementCappedByTarget) { _SetupBuffer(); ScaleIncrement(start_scaler, increment, target); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_)); } TEST_F(MixTestSuiteS32_LE, ScaleFullVolume) { - memcpy(compare_buffer_, src_buffer_, kBufferFrames * fr_bytes_); - cras_scale_buffer(fmt_, (uint8_t *)mix_buffer_, kNumSamples, 0.999999999); + memcpy(compare_buffer_, src_buffer_, kBufferFrames * fr_bytes_); + cras_scale_buffer(fmt_, (uint8_t*)mix_buffer_, kNumSamples, 0.999999999); EXPECT_EQ(0, memcmp(compare_buffer_, src_buffer_, kBufferFrames * fr_bytes_)); } TEST_F(MixTestSuiteS32_LE, ScaleMinVolume) { memset(compare_buffer_, 0, kBufferFrames * fr_bytes_); - cras_scale_buffer(fmt_, (uint8_t *)src_buffer_, kNumSamples, 0.0000000001); + cras_scale_buffer(fmt_, (uint8_t*)src_buffer_, kNumSamples, 0.0000000001); EXPECT_EQ(0, memcmp(compare_buffer_, src_buffer_, kBufferFrames * fr_bytes_)); } @@ -943,7 +915,7 @@ TEST_F(MixTestSuiteS32_LE, ScaleMinVolume) { TEST_F(MixTestSuiteS32_LE, ScaleHalfVolume) { for (size_t i = 0; i < kBufferFrames * 2; i++) compare_buffer_[i] = src_buffer_[i] * 0.5; - cras_scale_buffer(fmt_, (uint8_t *)src_buffer_, kNumSamples, 0.5); + cras_scale_buffer(fmt_, (uint8_t*)src_buffer_, kNumSamples, 0.5); EXPECT_EQ(0, memcmp(compare_buffer_, src_buffer_, kBufferFrames * fr_bytes_)); } @@ -954,187 +926,187 @@ TEST_F(MixTestSuiteS32_LE, StrideCopy) { TestScaleStride(0.1); } -class MixTestSuiteS24_3LE : public testing::Test{ - protected: - virtual void SetUp() { - fmt_ = SND_PCM_FORMAT_S24_3LE; - fr_bytes_ = 3 * kNumChannels; - mix_buffer_ = (uint8_t *)malloc(kBufferFrames * fr_bytes_); - src_buffer_ = static_cast<uint8_t*>( - calloc(1, kBufferFrames * fr_bytes_ + sizeof(cras_audio_shm_header))); +class MixTestSuiteS24_3LE : public testing::Test { + protected: + virtual void SetUp() { + fmt_ = SND_PCM_FORMAT_S24_3LE; + fr_bytes_ = 3 * kNumChannels; + mix_buffer_ = (uint8_t*)malloc(kBufferFrames * fr_bytes_); + src_buffer_ = static_cast<uint8_t*>( + calloc(1, kBufferFrames * fr_bytes_ + sizeof(cras_audio_shm_header))); - for (size_t i = 0; i < kBufferFrames * kNumChannels; i++) { - memcpy(src_buffer_ + 3*i, &i, 3); - int32_t tmp = -i * 256; - memcpy(mix_buffer_ + 3*i, (uint8_t *)&tmp + 1, 3); - } - - compare_buffer_ = (uint8_t *)malloc(kBufferFrames * fr_bytes_); + for (size_t i = 0; i < kBufferFrames * kNumChannels; i++) { + memcpy(src_buffer_ + 3 * i, &i, 3); + int32_t tmp = -i * 256; + memcpy(mix_buffer_ + 3 * i, (uint8_t*)&tmp + 1, 3); } - virtual void TearDown() { - free(mix_buffer_); - free(compare_buffer_); - free(src_buffer_); - } - - void _SetupBuffer() { - memset(compare_buffer_, 0, kBufferFrames * fr_bytes_); - for (size_t i = 0; i < kBufferFrames; i++) { - int32_t tmp = (i << 8) + (INT32_MAX >> 2); - memcpy(src_buffer_ + 3*i, (uint8_t *)&tmp + 1, 3); - memcpy(mix_buffer_ + 3*i, (uint8_t *)&tmp + 1, 3); - memcpy(compare_buffer_ + 3*i, (uint8_t *)&tmp + 1, 3); - } - for (size_t i = kBufferFrames; i < kBufferFrames * 2; i++) { - int32_t tmp = (i << 8) - (INT32_MAX >> 2); - memcpy(src_buffer_ + 3*i, (uint8_t *)&tmp + 1, 3); - memcpy(mix_buffer_ + 3*i, (uint8_t *)&tmp + 1, 3); - memcpy(compare_buffer_ + 3*i, (uint8_t *)&tmp + 1, 3); - } - } + compare_buffer_ = (uint8_t*)malloc(kBufferFrames * fr_bytes_); + } - void TestScaleStride(float scaler) { - _SetupBuffer(); - for (size_t i = 0; i < kBufferFrames * kNumChannels; i += 2) { - int64_t tmp; - int32_t src_frame = 0; - int32_t dst_frame = 0; - memcpy((uint8_t *)&src_frame + 1, src_buffer_ + 3*i/2, 3); - memcpy((uint8_t *)&dst_frame + 1, mix_buffer_ + 3*i, 3); - if (need_to_scale(scaler)) - tmp = (int64_t)dst_frame + (int64_t)src_frame * scaler; - else - tmp = (int64_t)dst_frame + (int64_t)src_frame; - if (tmp > INT32_MAX) - tmp = INT32_MAX; - else if (tmp < INT32_MIN) - tmp = INT32_MIN; - dst_frame = (int32_t)tmp; - memcpy(compare_buffer_ + 3*i, (uint8_t *)&dst_frame + 1, 3); - } + virtual void TearDown() { + free(mix_buffer_); + free(compare_buffer_); + free(src_buffer_); + } - cras_mix_add_scale_stride( - fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kBufferFrames, 6, 3, scaler); + void _SetupBuffer() { + memset(compare_buffer_, 0, kBufferFrames * fr_bytes_); + for (size_t i = 0; i < kBufferFrames; i++) { + int32_t tmp = (i << 8) + (INT32_MAX >> 2); + memcpy(src_buffer_ + 3 * i, (uint8_t*)&tmp + 1, 3); + memcpy(mix_buffer_ + 3 * i, (uint8_t*)&tmp + 1, 3); + memcpy(compare_buffer_ + 3 * i, (uint8_t*)&tmp + 1, 3); + } + for (size_t i = kBufferFrames; i < kBufferFrames * 2; i++) { + int32_t tmp = (i << 8) - (INT32_MAX >> 2); + memcpy(src_buffer_ + 3 * i, (uint8_t*)&tmp + 1, 3); + memcpy(mix_buffer_ + 3 * i, (uint8_t*)&tmp + 1, 3); + memcpy(compare_buffer_ + 3 * i, (uint8_t*)&tmp + 1, 3); + } + } - EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 6)); + void TestScaleStride(float scaler) { + _SetupBuffer(); + for (size_t i = 0; i < kBufferFrames * kNumChannels; i += 2) { + int64_t tmp; + int32_t src_frame = 0; + int32_t dst_frame = 0; + memcpy((uint8_t*)&src_frame + 1, src_buffer_ + 3 * i / 2, 3); + memcpy((uint8_t*)&dst_frame + 1, mix_buffer_ + 3 * i, 3); + if (need_to_scale(scaler)) + tmp = (int64_t)dst_frame + (int64_t)src_frame * scaler; + else + tmp = (int64_t)dst_frame + (int64_t)src_frame; + if (tmp > INT32_MAX) + tmp = INT32_MAX; + else if (tmp < INT32_MIN) + tmp = INT32_MIN; + dst_frame = (int32_t)tmp; + memcpy(compare_buffer_ + 3 * i, (uint8_t*)&dst_frame + 1, 3); } - void ScaleIncrement(float start_scaler, float increment, float target) { - float scaler = start_scaler; + cras_mix_add_scale_stride(fmt_, (uint8_t*)mix_buffer_, + (uint8_t*)src_buffer_, kBufferFrames, 6, 3, + scaler); - for (size_t i = 0; i < kBufferFrames * kNumChannels; i++) { - float applied_scaler = scaler; - int32_t tmp = 0; - memcpy((uint8_t *)&tmp + 1, src_buffer_ + 3*i, 3); + EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 6)); + } - if ((applied_scaler > target && increment > 0) || - (applied_scaler < target && increment < 0)) - applied_scaler = target; + void ScaleIncrement(float start_scaler, float increment, float target) { + float scaler = start_scaler; - if (applied_scaler > kMaxVolumeToScale) { - } else if (applied_scaler < kMinVolumeToScale) { - tmp = 0; - } else { - tmp *= applied_scaler; - } + for (size_t i = 0; i < kBufferFrames * kNumChannels; i++) { + float applied_scaler = scaler; + int32_t tmp = 0; + memcpy((uint8_t*)&tmp + 1, src_buffer_ + 3 * i, 3); - memcpy(compare_buffer_ + 3*i, (uint8_t *)&tmp + 1, 3); + if ((applied_scaler > target && increment > 0) || + (applied_scaler < target && increment < 0)) + applied_scaler = target; - if (i % 2 == 1) - scaler += increment; + if (applied_scaler > kMaxVolumeToScale) { + } else if (applied_scaler < kMinVolumeToScale) { + tmp = 0; + } else { + tmp *= applied_scaler; } + + memcpy(compare_buffer_ + 3 * i, (uint8_t*)&tmp + 1, 3); + + if (i % 2 == 1) + scaler += increment; } + } - uint8_t *mix_buffer_; - uint8_t *src_buffer_; - uint8_t *compare_buffer_; + uint8_t* mix_buffer_; + uint8_t* src_buffer_; + uint8_t* compare_buffer_; snd_pcm_format_t fmt_; unsigned int fr_bytes_; }; TEST_F(MixTestSuiteS24_3LE, MixFirst) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 0, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 0, 1.0); EXPECT_EQ(0, memcmp(mix_buffer_, src_buffer_, kBufferFrames * fr_bytes_)); } TEST_F(MixTestSuiteS24_3LE, MixTwo) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 0, 1.0); - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 1, 0, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 0, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 1, 0, 1.0); for (size_t i = 0; i < kBufferFrames * kNumChannels; i++) { int32_t tmp = 0; - memcpy((uint8_t *)&tmp + 1, src_buffer_ + 3*i, 3); + memcpy((uint8_t*)&tmp + 1, src_buffer_ + 3 * i, 3); tmp *= 2; - memcpy(compare_buffer_ + 3*i, (uint8_t *)&tmp + 1, 3); + memcpy(compare_buffer_ + 3 * i, (uint8_t*)&tmp + 1, 3); } EXPECT_EQ(0, memcmp(mix_buffer_, compare_buffer_, kBufferFrames * fr_bytes_)); } TEST_F(MixTestSuiteS24_3LE, MixTwoClip) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 0, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 0, 1.0); for (size_t i = 0; i < kBufferFrames * kNumChannels; i++) { int32_t tmp = INT32_MAX; - memcpy(src_buffer_ + 3*i, (uint8_t *)&tmp + 1, 3); + memcpy(src_buffer_ + 3 * i, (uint8_t*)&tmp + 1, 3); } - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 1, 0, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 1, 0, 1.0); for (size_t i = 0; i < kBufferFrames * kNumChannels; i++) { int32_t tmp = INT32_MAX; - memcpy(compare_buffer_ + 3*i, (uint8_t *)&tmp + 1, 3); + memcpy(compare_buffer_ + 3 * i, (uint8_t*)&tmp + 1, 3); } EXPECT_EQ(0, memcmp(mix_buffer_, compare_buffer_, kBufferFrames * fr_bytes_)); } TEST_F(MixTestSuiteS24_3LE, MixFirstMuted) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 1, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 1, 1.0); for (size_t i = 0; i < kBufferFrames * kNumChannels; i++) - memset(compare_buffer_ + 3*i, 0, 3); + memset(compare_buffer_ + 3 * i, 0, 3); EXPECT_EQ(0, memcmp(mix_buffer_, compare_buffer_, kBufferFrames * fr_bytes_)); } TEST_F(MixTestSuiteS24_3LE, MixFirstZeroVolume) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 0, 0.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 0, 0.0); for (size_t i = 0; i < kBufferFrames * kNumChannels; i++) - memset(compare_buffer_ + 3*i, 0, 3); + memset(compare_buffer_ + 3 * i, 0, 3); EXPECT_EQ(0, memcmp(mix_buffer_, compare_buffer_, kBufferFrames * fr_bytes_)); } TEST_F(MixTestSuiteS24_3LE, MixFirstHalfVolume) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 0, 0.5); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 0, 0.5); for (size_t i = 0; i < kBufferFrames * kNumChannels; i++) { int32_t tmp = 0; - memcpy((uint8_t *)&tmp + 1, src_buffer_ + 3*i, 3); + memcpy((uint8_t*)&tmp + 1, src_buffer_ + 3 * i, 3); tmp *= 0.5; - memcpy(compare_buffer_ + 3*i, (uint8_t *)&tmp + 1, 3); + memcpy(compare_buffer_ + 3 * i, (uint8_t*)&tmp + 1, 3); } EXPECT_EQ(0, memcmp(mix_buffer_, compare_buffer_, kBufferFrames * fr_bytes_)); } TEST_F(MixTestSuiteS24_3LE, MixTwoSecondHalfVolume) { - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 0, 0, 1.0); - cras_mix_add(fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_, - kNumSamples, 1, 0, 0.5); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 0, 0, 1.0); + cras_mix_add(fmt_, (uint8_t*)mix_buffer_, (uint8_t*)src_buffer_, kNumSamples, + 1, 0, 0.5); for (size_t i = 0; i < kBufferFrames * kNumChannels; i++) { int32_t tmp1 = 0, tmp2 = 0; - memcpy((uint8_t *)&tmp1 + 1, src_buffer_ + 3*i, 3); - memcpy((uint8_t *)&tmp2 + 1, src_buffer_ + 3*i, 3); + memcpy((uint8_t*)&tmp1 + 1, src_buffer_ + 3 * i, 3); + memcpy((uint8_t*)&tmp2 + 1, src_buffer_ + 3 * i, 3); tmp1 = tmp1 + (int32_t)(tmp2 * 0.5); - memcpy(compare_buffer_ + 3*i, (uint8_t *)&tmp1 + 1, 3); + memcpy(compare_buffer_ + 3 * i, (uint8_t*)&tmp1 + 1, 3); } EXPECT_EQ(0, memcmp(mix_buffer_, compare_buffer_, kBufferFrames * fr_bytes_)); } @@ -1148,9 +1120,8 @@ TEST_F(MixTestSuiteS24_3LE, ScaleFullVolumeIncrement) { _SetupBuffer(); // Scale full volume with positive increment will not change buffer. memcpy(compare_buffer_, src_buffer_, kBufferFrames * fr_bytes_); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_)); } @@ -1164,9 +1135,8 @@ TEST_F(MixTestSuiteS24_3LE, ScaleMinVolumeIncrement) { _SetupBuffer(); // Scale min volume with negative increment will change buffer to zeros. memset(compare_buffer_, 0, kBufferFrames * fr_bytes_); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_)); } @@ -1180,9 +1150,8 @@ TEST_F(MixTestSuiteS24_3LE, ScaleVolumePositiveIncrement) { _SetupBuffer(); ScaleIncrement(start_scaler, increment, target); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_)); } @@ -1195,9 +1164,8 @@ TEST_F(MixTestSuiteS24_3LE, ScaleVolumeNegativeIncrement) { _SetupBuffer(); ScaleIncrement(start_scaler, increment, target); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_)); } @@ -1211,9 +1179,8 @@ TEST_F(MixTestSuiteS24_3LE, ScaleVolumeStartFullNegativeIncrement) { _SetupBuffer(); ScaleIncrement(start_scaler, increment, target); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4)); } @@ -1227,9 +1194,8 @@ TEST_F(MixTestSuiteS24_3LE, ScaleVolumeStartZeroPositiveIncrement) { _SetupBuffer(); ScaleIncrement(start_scaler, increment, target); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4)); } @@ -1243,9 +1209,8 @@ TEST_F(MixTestSuiteS24_3LE, ScaleVolumePositiveIncrementCappedByTarget) { _SetupBuffer(); ScaleIncrement(start_scaler, increment, target); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_)); } @@ -1258,22 +1223,21 @@ TEST_F(MixTestSuiteS24_3LE, ScaleVolumeNegativeIncrementCappedByTarget) { _SetupBuffer(); ScaleIncrement(start_scaler, increment, target); - cras_scale_buffer_increment( - fmt_, (uint8_t *)mix_buffer_, kBufferFrames, start_scaler, - increment, target, step); + cras_scale_buffer_increment(fmt_, (uint8_t*)mix_buffer_, kBufferFrames, + start_scaler, increment, target, step); EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_)); } TEST_F(MixTestSuiteS24_3LE, ScaleFullVolume) { - memcpy(compare_buffer_, src_buffer_, kBufferFrames * fr_bytes_); - cras_scale_buffer(fmt_, (uint8_t *)mix_buffer_, kNumSamples, 0.999999999); + memcpy(compare_buffer_, src_buffer_, kBufferFrames * fr_bytes_); + cras_scale_buffer(fmt_, (uint8_t*)mix_buffer_, kNumSamples, 0.999999999); EXPECT_EQ(0, memcmp(compare_buffer_, src_buffer_, kBufferFrames * fr_bytes_)); } TEST_F(MixTestSuiteS24_3LE, ScaleMinVolume) { memset(compare_buffer_, 0, kBufferFrames * fr_bytes_); - cras_scale_buffer(fmt_, (uint8_t *)src_buffer_, kNumSamples, 0.0000000001); + cras_scale_buffer(fmt_, (uint8_t*)src_buffer_, kNumSamples, 0.0000000001); EXPECT_EQ(0, memcmp(compare_buffer_, src_buffer_, kBufferFrames * fr_bytes_)); } @@ -1281,11 +1245,11 @@ TEST_F(MixTestSuiteS24_3LE, ScaleMinVolume) { TEST_F(MixTestSuiteS24_3LE, ScaleHalfVolume) { for (size_t i = 0; i < kBufferFrames * kNumChannels; i++) { int32_t tmp = 0; - memcpy((uint8_t *)&tmp + 1, src_buffer_ + 3*i, 3); + memcpy((uint8_t*)&tmp + 1, src_buffer_ + 3 * i, 3); tmp *= 0.5; - memcpy(compare_buffer_ + 3*i, (uint8_t *)&tmp + 1, 3); + memcpy(compare_buffer_ + 3 * i, (uint8_t*)&tmp + 1, 3); } - cras_scale_buffer(fmt_, (uint8_t *)src_buffer_, kNumSamples, 0.5); + cras_scale_buffer(fmt_, (uint8_t*)src_buffer_, kNumSamples, 0.5); EXPECT_EQ(0, memcmp(compare_buffer_, src_buffer_, kBufferFrames * fr_bytes_)); } @@ -1297,13 +1261,11 @@ TEST_F(MixTestSuiteS24_3LE, StrideCopy) { } /* Stubs */ -extern "C" { - -} // extern "C" +extern "C" {} // extern "C" } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/observer_unittest.cc b/cras/src/tests/observer_unittest.cc index 899590f2..5c9ca141 100644 --- a/cras/src/tests/observer_unittest.cc +++ b/cras/src/tests/observer_unittest.cc @@ -6,8 +6,8 @@ #include <stdio.h> #include <syslog.h> -#include <vector> #include <map> +#include <vector> extern "C" { #include "cras_observer.c" @@ -17,17 +17,17 @@ namespace { static size_t cras_alert_destroy_called; static size_t cras_alert_create_called; -static std::vector<struct cras_alert *> cras_alert_create_return_values; -typedef std::map<struct cras_alert *, void *> alert_callback_map; +static std::vector<struct cras_alert*> cras_alert_create_return_values; +typedef std::map<struct cras_alert*, void*> alert_callback_map; static alert_callback_map cras_alert_create_prepare_map; static alert_callback_map cras_alert_add_callback_map; -typedef std::map<struct cras_alert *, unsigned int> alert_flags_map; +typedef std::map<struct cras_alert*, unsigned int> alert_flags_map; static alert_flags_map cras_alert_create_flags_map; -static struct cras_alert *cras_alert_pending_alert_value; -static void *cras_alert_pending_data_value = NULL; +static struct cras_alert* cras_alert_pending_alert_value; +static void* cras_alert_pending_data_value = NULL; static size_t cras_alert_pending_data_size_value; static size_t cras_iodev_list_update_device_list_called; -static std::vector<void *> cb_context; +static std::vector<void*> cb_context; static size_t cb_output_volume_changed_called; static std::vector<int32_t> cb_output_volume_changed_volume; static size_t cb_output_mute_changed_called; @@ -102,14 +102,16 @@ static void ResetStubData() { } /* System output volume changed. */ -void cb_output_volume_changed(void *context, int32_t volume) { +void cb_output_volume_changed(void* context, int32_t volume) { cb_output_volume_changed_called++; cb_context.push_back(context); cb_output_volume_changed_volume.push_back(volume); } /* System output mute changed. */ -void cb_output_mute_changed(void *context, - int muted, int user_muted, int mute_locked) { +void cb_output_mute_changed(void* context, + int muted, + int user_muted, + int mute_locked) { cb_output_mute_changed_called++; cb_context.push_back(context); cb_output_mute_changed_muted.push_back(muted); @@ -117,14 +119,14 @@ void cb_output_mute_changed(void *context, cb_output_mute_changed_mute_locked.push_back(mute_locked); } /* System input/capture gain changed. */ -void cb_capture_gain_changed(void *context, int32_t gain) { +void cb_capture_gain_changed(void* context, int32_t gain) { cb_capture_gain_changed_called++; cb_context.push_back(context); cb_capture_gain_changed_gain.push_back(gain); } /* System input/capture mute changed. */ -void cb_capture_mute_changed(void *context, int muted, int mute_locked) { +void cb_capture_mute_changed(void* context, int muted, int mute_locked) { cb_capture_mute_changed_called++; cb_context.push_back(context); cb_capture_mute_changed_muted.push_back(muted); @@ -132,14 +134,14 @@ void cb_capture_mute_changed(void *context, int muted, int mute_locked) { } /* Device or node topology changed. */ -void cb_nodes_changed(void *context) { +void cb_nodes_changed(void* context) { cb_nodes_changed_called++; cb_context.push_back(context); } /* Active node changed. A notification is sent for every change. * When there is no active node, node_id is 0. */ -void cb_active_node_changed(void *context, +void cb_active_node_changed(void* context, enum CRAS_STREAM_DIRECTION dir, cras_node_id_t node_id) { cb_active_node_changed_called++; @@ -149,7 +151,7 @@ void cb_active_node_changed(void *context, } /* Output node volume changed. */ -void cb_output_node_volume_changed(void *context, +void cb_output_node_volume_changed(void* context, cras_node_id_t node_id, int32_t volume) { cb_output_node_volume_changed_called++; @@ -159,7 +161,7 @@ void cb_output_node_volume_changed(void *context, } /* Node left/right swapped state change. */ -void cb_node_left_right_swapped_changed(void *context, +void cb_node_left_right_swapped_changed(void* context, cras_node_id_t node_id, int swapped) { cb_node_left_right_swapped_changed_called++; @@ -169,7 +171,7 @@ void cb_node_left_right_swapped_changed(void *context, } /* Input gain changed. */ -void cb_input_node_gain_changed(void *context, +void cb_input_node_gain_changed(void* context, cras_node_id_t node_id, int32_t gain) { cb_input_node_gain_changed_called++; @@ -179,9 +181,9 @@ void cb_input_node_gain_changed(void *context, } /* Number of active streams changed. */ -void cb_num_active_streams_changed(void *context, - enum CRAS_STREAM_DIRECTION dir, - uint32_t num_active_streams) { +void cb_num_active_streams_changed(void* context, + enum CRAS_STREAM_DIRECTION dir, + uint32_t num_active_streams) { cb_num_active_streams_changed_called++; cb_context.push_back(context); cb_num_active_streams_changed_dir.push_back(dir); @@ -197,44 +199,47 @@ class ObserverTest : public testing::Test { rc = cras_observer_server_init(); ASSERT_EQ(0, rc); EXPECT_EQ(15, cras_alert_create_called); - EXPECT_EQ(reinterpret_cast<void *>(output_volume_alert), + EXPECT_EQ(reinterpret_cast<void*>(output_volume_alert), cras_alert_add_callback_map[g_observer->alerts.output_volume]); - EXPECT_EQ(reinterpret_cast<void *>(output_mute_alert), + EXPECT_EQ(reinterpret_cast<void*>(output_mute_alert), cras_alert_add_callback_map[g_observer->alerts.output_mute]); - EXPECT_EQ(reinterpret_cast<void *>(capture_gain_alert), + EXPECT_EQ(reinterpret_cast<void*>(capture_gain_alert), cras_alert_add_callback_map[g_observer->alerts.capture_gain]); - EXPECT_EQ(reinterpret_cast<void *>(capture_mute_alert), + EXPECT_EQ(reinterpret_cast<void*>(capture_mute_alert), cras_alert_add_callback_map[g_observer->alerts.capture_mute]); - EXPECT_EQ(reinterpret_cast<void *>(nodes_alert), + EXPECT_EQ(reinterpret_cast<void*>(nodes_alert), cras_alert_add_callback_map[g_observer->alerts.nodes]); - EXPECT_EQ(reinterpret_cast<void *>(nodes_prepare), + EXPECT_EQ(reinterpret_cast<void*>(nodes_prepare), cras_alert_create_prepare_map[g_observer->alerts.nodes]); - EXPECT_EQ(reinterpret_cast<void *>(active_node_alert), + EXPECT_EQ(reinterpret_cast<void*>(active_node_alert), cras_alert_add_callback_map[g_observer->alerts.active_node]); EXPECT_EQ(CRAS_ALERT_FLAG_KEEP_ALL_DATA, cras_alert_create_flags_map[g_observer->alerts.active_node]); - EXPECT_EQ(reinterpret_cast<void *>(output_node_volume_alert), - cras_alert_add_callback_map[g_observer->alerts.output_node_volume]); - EXPECT_EQ(reinterpret_cast<void *>(node_left_right_swapped_alert), - cras_alert_add_callback_map[g_observer->alerts.node_left_right_swapped]); - EXPECT_EQ(reinterpret_cast<void *>(input_node_gain_alert), - cras_alert_add_callback_map[g_observer->alerts.input_node_gain]); - EXPECT_EQ(reinterpret_cast<void *>(num_active_streams_alert), - cras_alert_add_callback_map[g_observer->alerts.num_active_streams[ - CRAS_STREAM_OUTPUT]]); - EXPECT_EQ(reinterpret_cast<void *>(num_active_streams_alert), - cras_alert_add_callback_map[g_observer->alerts.num_active_streams[ - CRAS_STREAM_INPUT]]); - EXPECT_EQ(reinterpret_cast<void *>(num_active_streams_alert), - cras_alert_add_callback_map[g_observer->alerts.num_active_streams[ - CRAS_STREAM_POST_MIX_PRE_DSP]]); - EXPECT_EQ(reinterpret_cast<void *>(suspend_changed_alert), - cras_alert_add_callback_map[g_observer->alerts.suspend_changed]); - EXPECT_EQ(reinterpret_cast<void *>(hotword_triggered_alert), + EXPECT_EQ( + reinterpret_cast<void*>(output_node_volume_alert), + cras_alert_add_callback_map[g_observer->alerts.output_node_volume]); + EXPECT_EQ(reinterpret_cast<void*>(node_left_right_swapped_alert), + cras_alert_add_callback_map[g_observer->alerts + .node_left_right_swapped]); + EXPECT_EQ(reinterpret_cast<void*>(input_node_gain_alert), + cras_alert_add_callback_map[g_observer->alerts.input_node_gain]); + EXPECT_EQ(reinterpret_cast<void*>(num_active_streams_alert), + cras_alert_add_callback_map + [g_observer->alerts.num_active_streams[CRAS_STREAM_OUTPUT]]); + EXPECT_EQ(reinterpret_cast<void*>(num_active_streams_alert), + cras_alert_add_callback_map + [g_observer->alerts.num_active_streams[CRAS_STREAM_INPUT]]); + EXPECT_EQ(reinterpret_cast<void*>(num_active_streams_alert), + cras_alert_add_callback_map[g_observer->alerts.num_active_streams + [CRAS_STREAM_POST_MIX_PRE_DSP]]); + EXPECT_EQ(reinterpret_cast<void*>(suspend_changed_alert), + cras_alert_add_callback_map[g_observer->alerts.suspend_changed]); + EXPECT_EQ( + reinterpret_cast<void*>(hotword_triggered_alert), cras_alert_add_callback_map[g_observer->alerts.hotword_triggered]); - EXPECT_EQ(reinterpret_cast<void *>(non_empty_audio_state_changed_alert), - cras_alert_add_callback_map[ - g_observer->alerts.non_empty_audio_state_changed]); + EXPECT_EQ(reinterpret_cast<void*>(non_empty_audio_state_changed_alert), + cras_alert_add_callback_map[g_observer->alerts + .non_empty_audio_state_changed]); cras_observer_get_ops(NULL, &ops1_); EXPECT_NE(0, cras_observer_ops_are_empty(&ops1_)); @@ -242,8 +247,8 @@ class ObserverTest : public testing::Test { cras_observer_get_ops(NULL, &ops2_); EXPECT_NE(0, cras_observer_ops_are_empty(&ops2_)); - context1_ = reinterpret_cast<void *>(1); - context2_ = reinterpret_cast<void *>(2); + context1_ = reinterpret_cast<void*>(1); + context2_ = reinterpret_cast<void*>(2); } virtual void TearDown() { @@ -252,11 +257,11 @@ class ObserverTest : public testing::Test { ResetStubData(); } - void DoObserverAlert(cras_alert_cb alert, void *data) { + void DoObserverAlert(cras_alert_cb alert, void* data) { client1_ = cras_observer_add(&ops1_, context1_); client2_ = cras_observer_add(&ops2_, context2_); - ASSERT_NE(client1_, reinterpret_cast<struct cras_observer_client *>(NULL)); - ASSERT_NE(client2_, reinterpret_cast<struct cras_observer_client *>(NULL)); + ASSERT_NE(client1_, reinterpret_cast<struct cras_observer_client*>(NULL)); + ASSERT_NE(client2_, reinterpret_cast<struct cras_observer_client*>(NULL)); ASSERT_NE(alert, reinterpret_cast<cras_alert_cb>(NULL)); alert(NULL, data); @@ -265,10 +270,10 @@ class ObserverTest : public testing::Test { EXPECT_EQ(cb_context[1], context2_); } - void DoObserverRemoveClear(cras_alert_cb alert, void *data) { + void DoObserverRemoveClear(cras_alert_cb alert, void* data) { ASSERT_NE(alert, reinterpret_cast<cras_alert_cb>(NULL)); - ASSERT_NE(client1_, reinterpret_cast<struct cras_observer_client *>(NULL)); - ASSERT_NE(client2_, reinterpret_cast<struct cras_observer_client *>(NULL)); + ASSERT_NE(client1_, reinterpret_cast<struct cras_observer_client*>(NULL)); + ASSERT_NE(client2_, reinterpret_cast<struct cras_observer_client*>(NULL)); // Test observer removal. cras_observer_remove(client1_); @@ -283,7 +288,7 @@ class ObserverTest : public testing::Test { // Get the current value of ops2_ into ops1_. cras_observer_get_ops(client2_, &ops1_); - EXPECT_EQ(0, memcmp((void *)&ops1_, (void *)&ops2_, sizeof(ops1_))); + EXPECT_EQ(0, memcmp((void*)&ops1_, (void*)&ops2_, sizeof(ops1_))); // Clear out opts for client2. cras_observer_get_ops(NULL, &ops2_); @@ -297,24 +302,24 @@ class ObserverTest : public testing::Test { EXPECT_EQ(cb_context.size(), 0); } - struct cras_observer_client *client1_; - struct cras_observer_client *client2_; + struct cras_observer_client* client1_; + struct cras_observer_client* client2_; struct cras_observer_ops ops1_; struct cras_observer_ops ops2_; - void *context1_; - void *context2_; + void* context1_; + void* context2_; }; TEST_F(ObserverTest, NotifyOutputVolume) { - struct cras_observer_alert_data_volume *data; + struct cras_observer_alert_data_volume* data; const int32_t volume = 100; cras_observer_notify_output_volume(volume); EXPECT_EQ(cras_alert_pending_alert_value, g_observer->alerts.output_volume); ASSERT_EQ(cras_alert_pending_data_size_value, sizeof(*data)); - ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void *>(NULL)); - data = reinterpret_cast<struct cras_observer_alert_data_volume *>( - cras_alert_pending_data_value); + ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void*>(NULL)); + data = reinterpret_cast<struct cras_observer_alert_data_volume*>( + cras_alert_pending_data_value); EXPECT_EQ(data->volume, volume); ops1_.output_volume_changed = cb_output_volume_changed; @@ -328,7 +333,7 @@ TEST_F(ObserverTest, NotifyOutputVolume) { }; TEST_F(ObserverTest, NotifyOutputMute) { - struct cras_observer_alert_data_mute *data; + struct cras_observer_alert_data_mute* data; const int muted = 1; const int user_muted = 0; const int mute_locked = 0; @@ -336,9 +341,9 @@ TEST_F(ObserverTest, NotifyOutputMute) { cras_observer_notify_output_mute(muted, user_muted, mute_locked); EXPECT_EQ(cras_alert_pending_alert_value, g_observer->alerts.output_mute); ASSERT_EQ(cras_alert_pending_data_size_value, sizeof(*data)); - ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void *>(NULL)); - data = reinterpret_cast<struct cras_observer_alert_data_mute *>( - cras_alert_pending_data_value); + ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void*>(NULL)); + data = reinterpret_cast<struct cras_observer_alert_data_mute*>( + cras_alert_pending_data_value); EXPECT_EQ(data->muted, muted); EXPECT_EQ(data->user_muted, user_muted); EXPECT_EQ(data->mute_locked, mute_locked); @@ -358,15 +363,15 @@ TEST_F(ObserverTest, NotifyOutputMute) { }; TEST_F(ObserverTest, NotifyCaptureGain) { - struct cras_observer_alert_data_volume *data; + struct cras_observer_alert_data_volume* data; const int32_t gain = -20; cras_observer_notify_capture_gain(gain); EXPECT_EQ(cras_alert_pending_alert_value, g_observer->alerts.capture_gain); ASSERT_EQ(cras_alert_pending_data_size_value, sizeof(*data)); - ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void *>(NULL)); - data = reinterpret_cast<struct cras_observer_alert_data_volume *>( - cras_alert_pending_data_value); + ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void*>(NULL)); + data = reinterpret_cast<struct cras_observer_alert_data_volume*>( + cras_alert_pending_data_value); EXPECT_EQ(data->volume, gain); ops1_.capture_gain_changed = cb_capture_gain_changed; @@ -380,16 +385,16 @@ TEST_F(ObserverTest, NotifyCaptureGain) { }; TEST_F(ObserverTest, NotifyCaptureMute) { - struct cras_observer_alert_data_mute *data; + struct cras_observer_alert_data_mute* data; const int muted = 1; const int mute_locked = 0; cras_observer_notify_capture_mute(muted, mute_locked); EXPECT_EQ(cras_alert_pending_alert_value, g_observer->alerts.capture_mute); ASSERT_EQ(cras_alert_pending_data_size_value, sizeof(*data)); - ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void *>(NULL)); - data = reinterpret_cast<struct cras_observer_alert_data_mute *>( - cras_alert_pending_data_value); + ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void*>(NULL)); + data = reinterpret_cast<struct cras_observer_alert_data_mute*>( + cras_alert_pending_data_value); EXPECT_EQ(data->muted, muted); EXPECT_EQ(data->mute_locked, mute_locked); @@ -418,16 +423,16 @@ TEST_F(ObserverTest, NotifyNodes) { }; TEST_F(ObserverTest, NotifyActiveNode) { - struct cras_observer_alert_data_active_node *data; + struct cras_observer_alert_data_active_node* data; const enum CRAS_STREAM_DIRECTION dir = CRAS_STREAM_INPUT; const cras_node_id_t node_id = 0x0001000100020002; cras_observer_notify_active_node(dir, node_id); EXPECT_EQ(cras_alert_pending_alert_value, g_observer->alerts.active_node); ASSERT_EQ(cras_alert_pending_data_size_value, sizeof(*data)); - ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void *>(NULL)); - data = reinterpret_cast<struct cras_observer_alert_data_active_node *>( - cras_alert_pending_data_value); + ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void*>(NULL)); + data = reinterpret_cast<struct cras_observer_alert_data_active_node*>( + cras_alert_pending_data_value); EXPECT_EQ(data->node_id, node_id); EXPECT_EQ(data->direction, dir); @@ -444,7 +449,7 @@ TEST_F(ObserverTest, NotifyActiveNode) { }; TEST_F(ObserverTest, NotifyOutputNodeVolume) { - struct cras_observer_alert_data_node_volume *data; + struct cras_observer_alert_data_node_volume* data; const cras_node_id_t node_id = 0x0001000100020002; const int32_t volume = 100; @@ -452,9 +457,9 @@ TEST_F(ObserverTest, NotifyOutputNodeVolume) { EXPECT_EQ(cras_alert_pending_alert_value, g_observer->alerts.output_node_volume); ASSERT_EQ(cras_alert_pending_data_size_value, sizeof(*data)); - ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void *>(NULL)); - data = reinterpret_cast<struct cras_observer_alert_data_node_volume *>( - cras_alert_pending_data_value); + ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void*>(NULL)); + data = reinterpret_cast<struct cras_observer_alert_data_node_volume*>( + cras_alert_pending_data_value); EXPECT_EQ(data->node_id, node_id); EXPECT_EQ(data->volume, volume); @@ -471,7 +476,7 @@ TEST_F(ObserverTest, NotifyOutputNodeVolume) { }; TEST_F(ObserverTest, NotifyNodeLeftRightSwapped) { - struct cras_observer_alert_data_node_lr_swapped *data; + struct cras_observer_alert_data_node_lr_swapped* data; const cras_node_id_t node_id = 0x0001000100020002; const int swapped = 1; @@ -479,9 +484,9 @@ TEST_F(ObserverTest, NotifyNodeLeftRightSwapped) { EXPECT_EQ(cras_alert_pending_alert_value, g_observer->alerts.node_left_right_swapped); ASSERT_EQ(cras_alert_pending_data_size_value, sizeof(*data)); - ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void *>(NULL)); - data = reinterpret_cast<struct cras_observer_alert_data_node_lr_swapped *>( - cras_alert_pending_data_value); + ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void*>(NULL)); + data = reinterpret_cast<struct cras_observer_alert_data_node_lr_swapped*>( + cras_alert_pending_data_value); EXPECT_EQ(data->node_id, node_id); EXPECT_EQ(data->swapped, swapped); @@ -498,17 +503,16 @@ TEST_F(ObserverTest, NotifyNodeLeftRightSwapped) { }; TEST_F(ObserverTest, NotifyInputNodeGain) { - struct cras_observer_alert_data_node_volume *data; + struct cras_observer_alert_data_node_volume* data; const cras_node_id_t node_id = 0x0001000100020002; const int32_t gain = -20; cras_observer_notify_input_node_gain(node_id, gain); - EXPECT_EQ(cras_alert_pending_alert_value, - g_observer->alerts.input_node_gain); + EXPECT_EQ(cras_alert_pending_alert_value, g_observer->alerts.input_node_gain); ASSERT_EQ(cras_alert_pending_data_size_value, sizeof(*data)); - ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void *>(NULL)); - data = reinterpret_cast<struct cras_observer_alert_data_node_volume *>( - cras_alert_pending_data_value); + ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void*>(NULL)); + data = reinterpret_cast<struct cras_observer_alert_data_node_volume*>( + cras_alert_pending_data_value); EXPECT_EQ(data->node_id, node_id); EXPECT_EQ(data->volume, gain); @@ -525,29 +529,27 @@ TEST_F(ObserverTest, NotifyInputNodeGain) { }; TEST_F(ObserverTest, NotifySuspendChanged) { - struct cras_observer_alert_data_suspend *data; + struct cras_observer_alert_data_suspend* data; cras_observer_notify_suspend_changed(1); - EXPECT_EQ(cras_alert_pending_alert_value, - g_observer->alerts.suspend_changed); + EXPECT_EQ(cras_alert_pending_alert_value, g_observer->alerts.suspend_changed); ASSERT_EQ(cras_alert_pending_data_size_value, sizeof(*data)); - ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void *>(NULL)); - data = reinterpret_cast<struct cras_observer_alert_data_suspend *>( + ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void*>(NULL)); + data = reinterpret_cast<struct cras_observer_alert_data_suspend*>( cras_alert_pending_data_value); EXPECT_EQ(data->suspended, 1); cras_observer_notify_suspend_changed(0); - EXPECT_EQ(cras_alert_pending_alert_value, - g_observer->alerts.suspend_changed); + EXPECT_EQ(cras_alert_pending_alert_value, g_observer->alerts.suspend_changed); ASSERT_EQ(cras_alert_pending_data_size_value, sizeof(*data)); - ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void *>(NULL)); - data = reinterpret_cast<struct cras_observer_alert_data_suspend *>( + ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void*>(NULL)); + data = reinterpret_cast<struct cras_observer_alert_data_suspend*>( cras_alert_pending_data_value); EXPECT_EQ(data->suspended, 0); } TEST_F(ObserverTest, NotifyNumActiveStreams) { - struct cras_observer_alert_data_streams *data; + struct cras_observer_alert_data_streams* data; const enum CRAS_STREAM_DIRECTION dir = CRAS_STREAM_INPUT; const uint32_t active_streams = 10; @@ -555,9 +557,9 @@ TEST_F(ObserverTest, NotifyNumActiveStreams) { EXPECT_EQ(cras_alert_pending_alert_value, g_observer->alerts.num_active_streams[CRAS_STREAM_INPUT]); ASSERT_EQ(cras_alert_pending_data_size_value, sizeof(*data)); - ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void *>(NULL)); - data = reinterpret_cast<struct cras_observer_alert_data_streams *>( - cras_alert_pending_data_value); + ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void*>(NULL)); + data = reinterpret_cast<struct cras_observer_alert_data_streams*>( + cras_alert_pending_data_value); EXPECT_EQ(data->num_active_streams, active_streams); EXPECT_EQ(data->direction, dir); @@ -574,63 +576,65 @@ TEST_F(ObserverTest, NotifyNumActiveStreams) { }; TEST_F(ObserverTest, NotifyHotwordTriggered) { - struct cras_observer_alert_data_hotword_triggered *data; + struct cras_observer_alert_data_hotword_triggered* data; cras_observer_notify_hotword_triggered(100, 200); EXPECT_EQ(cras_alert_pending_alert_value, - g_observer->alerts.hotword_triggered); + g_observer->alerts.hotword_triggered); ASSERT_EQ(cras_alert_pending_data_size_value, sizeof(*data)); - ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void *>(NULL)); - data = reinterpret_cast<struct cras_observer_alert_data_hotword_triggered *>( - cras_alert_pending_data_value); + ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void*>(NULL)); + data = reinterpret_cast<struct cras_observer_alert_data_hotword_triggered*>( + cras_alert_pending_data_value); EXPECT_EQ(data->tv_sec, 100); EXPECT_EQ(data->tv_nsec, 200); } TEST_F(ObserverTest, NonEmpyAudioStateChanged) { - struct cras_observer_non_empty_audio_state *data; + struct cras_observer_non_empty_audio_state* data; cras_observer_notify_non_empty_audio_state_changed(1); EXPECT_EQ(cras_alert_pending_alert_value, - g_observer->alerts.non_empty_audio_state_changed); + g_observer->alerts.non_empty_audio_state_changed); ASSERT_EQ(cras_alert_pending_data_size_value, sizeof(*data)); - ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void *>(NULL)); - data = reinterpret_cast<struct cras_observer_non_empty_audio_state *>( - cras_alert_pending_data_value); + ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void*>(NULL)); + data = reinterpret_cast<struct cras_observer_non_empty_audio_state*>( + cras_alert_pending_data_value); EXPECT_EQ(data->non_empty, 1); } // Stubs extern "C" { -void cras_alert_destroy(struct cras_alert *alert) { +void cras_alert_destroy(struct cras_alert* alert) { cras_alert_destroy_called++; } -struct cras_alert *cras_alert_create(cras_alert_prepare prepare, +struct cras_alert* cras_alert_create(cras_alert_prepare prepare, unsigned int flags) { - struct cras_alert *alert = NULL; + struct cras_alert* alert = NULL; cras_alert_create_called++; alert = reinterpret_cast<struct cras_alert*>(cras_alert_create_called); cras_alert_create_return_values.push_back(alert); cras_alert_create_flags_map[alert] = flags; - cras_alert_create_prepare_map[alert] = reinterpret_cast<void *>(prepare); + cras_alert_create_prepare_map[alert] = reinterpret_cast<void*>(prepare); return alert; } -int cras_alert_add_callback(struct cras_alert *alert, cras_alert_cb cb, - void *arg) { - cras_alert_add_callback_map[alert] = reinterpret_cast<void *>(cb); +int cras_alert_add_callback(struct cras_alert* alert, + cras_alert_cb cb, + void* arg) { + cras_alert_add_callback_map[alert] = reinterpret_cast<void*>(cb); return 0; } -void cras_alert_pending(struct cras_alert *alert) { +void cras_alert_pending(struct cras_alert* alert) { cras_alert_pending_alert_value = alert; } -void cras_alert_pending_data(struct cras_alert *alert, - void *data, size_t data_size) { +void cras_alert_pending_data(struct cras_alert* alert, + void* data, + size_t data_size) { cras_alert_pending_alert_value = alert; cras_alert_pending_data_size_value = data_size; if (cras_alert_pending_data_value) @@ -638,8 +642,7 @@ void cras_alert_pending_data(struct cras_alert *alert, if (data) { cras_alert_pending_data_value = malloc(data_size); memcpy(cras_alert_pending_data_value, data, data_size); - } - else + } else cras_alert_pending_data_value = NULL; } @@ -651,7 +654,7 @@ void cras_iodev_list_update_device_list() { } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); openlog(NULL, LOG_PERROR, LOG_USER); return RUN_ALL_TESTS(); diff --git a/cras/src/tests/playback_rclient_unittest.cc b/cras/src/tests/playback_rclient_unittest.cc new file mode 100644 index 00000000..aa24bc28 --- /dev/null +++ b/cras/src/tests/playback_rclient_unittest.cc @@ -0,0 +1,331 @@ +// Copyright 2019 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <gtest/gtest.h> +#include <stdio.h> +#include <unistd.h> + +extern "C" { +#include "audio_thread.h" +#include "cras_bt_log.h" +#include "cras_messages.h" +#include "cras_rclient.h" +#include "cras_rstream.h" +#include "cras_system_state.h" + +// Access to data structures and static functions. +#include "cras_playback_rclient.c" +#include "cras_rclient_util.c" +} +static unsigned int cras_make_fd_nonblocking_called; +static unsigned int cras_observer_remove_called; +static unsigned int cras_server_metrics_stream_config_called; +static int stream_list_add_called; +static int stream_list_add_return; +static unsigned int stream_list_rm_called; +static struct cras_audio_shm dummy_shm; +static struct cras_rstream dummy_rstream; +static unsigned int cras_rstream_config_init_with_message_called; + +void ResetStubData() { + cras_make_fd_nonblocking_called = 0; + cras_observer_remove_called = 0; + cras_server_metrics_stream_config_called = 0; + stream_list_add_called = 0; + stream_list_add_return = 0; + stream_list_rm_called = 0; + cras_rstream_config_init_with_message_called = 0; +} + +namespace { + +TEST(RClientSuite, CreateSendMessage) { + struct cras_rclient* rclient; + int rc; + struct cras_client_connected msg; + int pipe_fds[2]; + + ResetStubData(); + + rc = pipe(pipe_fds); + ASSERT_EQ(0, rc); + + rclient = cras_playback_rclient_create(pipe_fds[1], 800); + ASSERT_NE((void*)NULL, rclient); + EXPECT_EQ(800, rclient->id); + + rc = read(pipe_fds[0], &msg, sizeof(msg)); + EXPECT_EQ(sizeof(msg), rc); + EXPECT_EQ(CRAS_CLIENT_CONNECTED, msg.header.id); + + rclient->ops->destroy(rclient); + EXPECT_EQ(1, cras_observer_remove_called); + close(pipe_fds[0]); + close(pipe_fds[1]); +} + +class CPRMessageSuite : public testing::Test { + protected: + virtual void SetUp() { + int rc; + struct cras_client_connected msg; + + rc = pipe(pipe_fds_); + if (rc < 0) + return; + + rclient_ = cras_playback_rclient_create(pipe_fds_[1], 1); + rc = read(pipe_fds_[0], &msg, sizeof(msg)); + if (rc < 0) + return; + + fmt = { + .format = SND_PCM_FORMAT_S16_LE, + .frame_rate = 48000, + .num_channels = 2, + }; + cras_audio_format_set_default_channel_layout(&fmt); + ResetStubData(); + } + + virtual void TearDown() { + rclient_->ops->destroy(rclient_); + close(pipe_fds_[0]); + close(pipe_fds_[1]); + } + + struct cras_rclient* rclient_; + struct cras_audio_format fmt; + int pipe_fds_[2]; + int fd_; +}; + +TEST_F(CPRMessageSuite, StreamConnectMessage) { + struct cras_client_stream_connected out_msg; + int rc; + + struct cras_connect_message msg; + cras_stream_id_t stream_id = 0x10002; + cras_fill_connect_message(&msg, CRAS_STREAM_OUTPUT, stream_id, + CRAS_STREAM_TYPE_DEFAULT, CRAS_CLIENT_TYPE_UNKNOWN, + 480, 240, /*flags=*/0, /*effects=*/0, fmt, + NO_DEVICE, /*client_shm_size=*/0); + ASSERT_EQ(stream_id, msg.stream_id); + + fd_ = 100; + rclient_->ops->handle_message_from_client(rclient_, &msg.header, &fd_, 1); + EXPECT_EQ(1, cras_make_fd_nonblocking_called); + EXPECT_EQ(1, cras_rstream_config_init_with_message_called); + EXPECT_EQ(1, stream_list_add_called); + EXPECT_EQ(0, stream_list_rm_called); + + rc = read(pipe_fds_[0], &out_msg, sizeof(out_msg)); + EXPECT_EQ(sizeof(out_msg), rc); + EXPECT_EQ(stream_id, out_msg.stream_id); +} + +TEST_F(CPRMessageSuite, StreamConnectMessageInvalidDirection) { + struct cras_client_stream_connected out_msg; + int rc; + + struct cras_connect_message msg; + cras_stream_id_t stream_id = 0x10002; + + for (int i = 0; i < CRAS_NUM_DIRECTIONS; i++) { + const auto dir = static_cast<CRAS_STREAM_DIRECTION>(i); + if (dir == CRAS_STREAM_OUTPUT) + continue; + cras_fill_connect_message(&msg, dir, stream_id, CRAS_STREAM_TYPE_DEFAULT, + CRAS_CLIENT_TYPE_UNKNOWN, 480, 240, /*flags=*/0, + /*effects=*/0, fmt, NO_DEVICE, + /*client_shm_size=*/0); + ASSERT_EQ(stream_id, msg.stream_id); + + fd_ = 100; + rc = rclient_->ops->handle_message_from_client(rclient_, &msg.header, &fd_, + 1); + EXPECT_EQ(-EINVAL, rc); + EXPECT_EQ(0, cras_make_fd_nonblocking_called); + EXPECT_EQ(0, cras_rstream_config_init_with_message_called); + EXPECT_EQ(0, stream_list_add_called); + EXPECT_EQ(0, stream_list_rm_called); + + rc = read(pipe_fds_[0], &out_msg, sizeof(out_msg)); + EXPECT_EQ(sizeof(out_msg), rc); + EXPECT_EQ(-EINVAL, out_msg.err); + EXPECT_EQ(stream_id, out_msg.stream_id); + } +} + +TEST_F(CPRMessageSuite, StreamConnectMessageInvalidClientId) { + struct cras_client_stream_connected out_msg; + int rc; + + struct cras_connect_message msg; + cras_stream_id_t stream_id = 0x20002; // stream_id with invalid client_id + cras_fill_connect_message(&msg, CRAS_STREAM_OUTPUT, stream_id, + CRAS_STREAM_TYPE_DEFAULT, CRAS_CLIENT_TYPE_UNKNOWN, + 480, 240, /*flags=*/0, /*effects=*/0, fmt, + NO_DEVICE, /*client_shm_size=*/0); + ASSERT_EQ(stream_id, msg.stream_id); + + fd_ = 100; + rc = + rclient_->ops->handle_message_from_client(rclient_, &msg.header, &fd_, 1); + EXPECT_EQ(-EINVAL, rc); + EXPECT_EQ(0, cras_make_fd_nonblocking_called); + EXPECT_EQ(0, cras_rstream_config_init_with_message_called); + EXPECT_EQ(0, stream_list_add_called); + EXPECT_EQ(0, stream_list_rm_called); + + rc = read(pipe_fds_[0], &out_msg, sizeof(out_msg)); + EXPECT_EQ(sizeof(out_msg), rc); + EXPECT_EQ(-EINVAL, out_msg.err); + EXPECT_EQ(stream_id, out_msg.stream_id); +} + +/* + * TODO(yuhsaun): Remove this test when there are no client uses the old + * craslib. (CRAS_PROTO_VER = 3) + */ +TEST_F(CPRMessageSuite, StreamConnectMessageOldProtocal) { + struct cras_client_stream_connected out_msg; + int rc; + + struct cras_connect_message_old msg; + cras_stream_id_t stream_id = 0x10002; + + msg.proto_version = 3; + msg.direction = CRAS_STREAM_OUTPUT; + msg.stream_id = stream_id; + msg.stream_type = CRAS_STREAM_TYPE_DEFAULT; + msg.buffer_frames = 480; + msg.cb_threshold = 240; + msg.flags = 0; + msg.effects = 0; + pack_cras_audio_format(&msg.format, &fmt); + msg.dev_idx = NO_DEVICE; + msg.header.id = CRAS_SERVER_CONNECT_STREAM; + msg.header.length = sizeof(struct cras_connect_message_old); + + fd_ = 100; + rc = + rclient_->ops->handle_message_from_client(rclient_, &msg.header, &fd_, 1); + EXPECT_EQ(1, cras_make_fd_nonblocking_called); + EXPECT_EQ(1, cras_rstream_config_init_with_message_called); + EXPECT_EQ(1, stream_list_add_called); + EXPECT_EQ(0, stream_list_rm_called); + + rc = read(pipe_fds_[0], &out_msg, sizeof(out_msg)); + EXPECT_EQ(sizeof(out_msg), rc); + EXPECT_EQ(stream_id, out_msg.stream_id); +} + +TEST_F(CPRMessageSuite, StreamDisconnectMessage) { + struct cras_disconnect_stream_message msg; + cras_stream_id_t stream_id = 0x10002; + cras_fill_disconnect_stream_message(&msg, stream_id); + + rclient_->ops->handle_message_from_client(rclient_, &msg.header, NULL, 0); + EXPECT_EQ(0, stream_list_add_called); + EXPECT_EQ(1, stream_list_rm_called); +} + +TEST_F(CPRMessageSuite, StreamDisconnectMessageInvalidClientId) { + struct cras_disconnect_stream_message msg; + cras_stream_id_t stream_id = 0x20002; // stream_id with invalid client_id + cras_fill_disconnect_stream_message(&msg, stream_id); + + rclient_->ops->handle_message_from_client(rclient_, &msg.header, NULL, 0); + EXPECT_EQ(0, stream_list_add_called); + EXPECT_EQ(0, stream_list_rm_called); +} +} // namespace + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + +/* stubs */ +extern "C" { + +struct stream_list* cras_iodev_list_get_stream_list() { + return NULL; +} + +int cras_make_fd_nonblocking(int fd) { + cras_make_fd_nonblocking_called++; + return 0; +} + +void cras_observer_remove(struct cras_observer_client* client) { + cras_observer_remove_called++; +} + +unsigned int cras_rstream_get_effects(const struct cras_rstream* stream) { + return 0; +} + +int cras_server_metrics_stream_config(struct cras_rstream_config* config) { + cras_server_metrics_stream_config_called++; + return 0; +} + +int cras_send_with_fds(int sockfd, + const void* buf, + size_t len, + int* fd, + unsigned int num_fds) { + return write(sockfd, buf, len); +} + +key_t cras_sys_state_shm_fd() { + return 1; +} + +void cras_system_set_suspended(int suspended) {} + +int stream_list_rm_all_client_streams(struct stream_list* list, + struct cras_rclient* rclient) { + return 0; +} + +int stream_list_rm(struct stream_list* list, cras_stream_id_t id) { + stream_list_rm_called++; + return 0; +} + +int stream_list_add(struct stream_list* list, + struct cras_rstream_config* config, + struct cras_rstream** stream) { + int ret; + + *stream = &dummy_rstream; + + stream_list_add_called++; + ret = stream_list_add_return; + if (ret) + stream_list_add_return = -EINVAL; + + dummy_rstream.shm = &dummy_shm; + dummy_rstream.direction = config->direction; + dummy_rstream.stream_id = config->stream_id; + + return ret; +} + +void cras_rstream_config_init_with_message( + struct cras_rclient* client, + const struct cras_connect_message* msg, + int* aud_fd, + int* client_shm_fd, + const struct cras_audio_format* remote_fmt, + struct cras_rstream_config* stream_config) { + cras_rstream_config_init_with_message_called++; +} + +void cras_rstream_config_cleanup(struct cras_rstream_config* stream_config) {} + +} // extern "C" diff --git a/cras/src/tests/polled_interval_checker_unittest.cc b/cras/src/tests/polled_interval_checker_unittest.cc index c7993878..c18fdf7e 100644 --- a/cras/src/tests/polled_interval_checker_unittest.cc +++ b/cras/src/tests/polled_interval_checker_unittest.cc @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <stdio.h> #include <gtest/gtest.h> +#include <stdio.h> extern "C" { #include "polled_interval_checker.h" @@ -14,15 +14,15 @@ static const int INTERVAL_DURATION = 5; static struct timespec time_now; static struct polled_interval* create_interval() { - struct polled_interval *interval = - pic_polled_interval_create(INTERVAL_DURATION); + struct polled_interval* interval = + pic_polled_interval_create(INTERVAL_DURATION); EXPECT_NE(interval, static_cast<struct polled_interval*>(NULL)); return interval; } TEST(PolledIntervalCheckerTest, CreateDestroy) { // Create an interval, checks it is non-null. - struct polled_interval *interval = create_interval(); + struct polled_interval* interval = create_interval(); pic_polled_interval_destroy(&interval); @@ -37,7 +37,7 @@ TEST(PolledIntervalCheckerTest, BasicFlow) { pic_update_current_time(); // Create interval starting at initial time. - struct polled_interval *interval = create_interval(); + struct polled_interval* interval = create_interval(); // Check it hasn't elapsed. EXPECT_FALSE(pic_interval_elapsed(interval)); @@ -68,7 +68,7 @@ TEST(PolledIntervalCheckerTest, DoesNotResetAutomatically) { time_now.tv_nsec = 0; pic_update_current_time(); - struct polled_interval *interval = create_interval(); + struct polled_interval* interval = create_interval(); // Sanity check. EXPECT_FALSE(pic_interval_elapsed(interval)); @@ -98,7 +98,7 @@ TEST(PolledIntervalCheckerTest, Reset) { time_now.tv_nsec = 0; pic_update_current_time(); - struct polled_interval *interval = create_interval(); + struct polled_interval* interval = create_interval(); // Sanity check. EXPECT_FALSE(pic_interval_elapsed(interval)); @@ -142,14 +142,14 @@ TEST(PolledIntervalCheckerTest, Reset) { /* Stubs */ extern "C" { -int clock_gettime(clockid_t clk_id, struct timespec *tp) { +int clock_gettime(clockid_t clk_id, struct timespec* tp) { *tp = time_now; return 0; } } // extern "C" -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/ramp_unittest.cc b/cras/src/tests/ramp_unittest.cc index c302ed7f..8d674799 100644 --- a/cras/src/tests/ramp_unittest.cc +++ b/cras/src/tests/ramp_unittest.cc @@ -2,15 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <stdio.h> #include <gtest/gtest.h> +#include <stdio.h> extern "C" { #include "cras_ramp.c" } static int callback_called; -static void *callback_arg; +static void* callback_arg; void ResetStubData() { callback_called = 0; @@ -20,7 +20,7 @@ void ResetStubData() { namespace { TEST(RampTestSuite, Init) { - struct cras_ramp *ramp; + struct cras_ramp* ramp; struct cras_ramp_action action; ResetStubData(); @@ -41,7 +41,7 @@ TEST(RampTestSuite, RampUpInitialIncrement) { float to = 1.0; int duration_frames = 48000; float increment = 1.0 / 48000; - cras_ramp *ramp; + cras_ramp* ramp; cras_ramp_action action; ResetStubData(); @@ -66,7 +66,7 @@ TEST(RampTestSuite, RampUpUpdateRampedFrames) { float increment = 1.0 / 48000; int rc; int ramped_frames = 512; - struct cras_ramp *ramp; + struct cras_ramp* ramp; struct cras_ramp_action action; float scaler = increment * ramped_frames; @@ -94,7 +94,7 @@ TEST(RampTestSuite, RampUpPassedRamp) { int duration_frames = 48000; int rc; int ramped_frames = 48000; - struct cras_ramp *ramp; + struct cras_ramp* ramp; struct cras_ramp_action action; ResetStubData(); @@ -121,7 +121,7 @@ TEST(RampTestSuite, RampUpWhileHalfWayRampDown) { int duration_frames = 48000; int rc; int ramped_frames = 24000; - struct cras_ramp *ramp; + struct cras_ramp* ramp; struct cras_ramp_action action; float down_increment = -1.0 / 48000; float up_increment; @@ -162,7 +162,7 @@ TEST(RampTestSuite, RampUpWhileHalfWayRampUp) { int duration_frames = 48000; int rc; int ramped_frames = 24000; - struct cras_ramp *ramp; + struct cras_ramp* ramp; struct cras_ramp_action action; float first_increment = 1.0 / 48000; float second_increment; @@ -198,7 +198,7 @@ TEST(RampTestSuite, RampDownInitialIncrement) { float to = 0.0; int duration_frames = 48000; float increment = -1.0 / 48000; - cras_ramp *ramp; + cras_ramp* ramp; cras_ramp_action action; ResetStubData(); @@ -223,7 +223,7 @@ TEST(RampTestSuite, RampDownUpdateRampedFrames) { float increment = -1.0 / 48000; int rc; int ramped_frames = 512; - struct cras_ramp *ramp; + struct cras_ramp* ramp; struct cras_ramp_action action; float scaler = 1 + increment * ramped_frames; @@ -251,7 +251,7 @@ TEST(RampTestSuite, RampDownPassedRamp) { int duration_frames = 48000; int rc; int ramped_frames = 48000; - struct cras_ramp *ramp; + struct cras_ramp* ramp; struct cras_ramp_action action; ResetStubData(); @@ -278,7 +278,7 @@ TEST(RampTestSuite, RampDownWhileHalfWayRampUp) { int duration_frames = 48000; int rc; int ramped_frames = 24000; - struct cras_ramp *ramp; + struct cras_ramp* ramp; struct cras_ramp_action action; float up_increment = 1.0 / 48000; float down_increment; @@ -299,7 +299,6 @@ TEST(RampTestSuite, RampDownWhileHalfWayRampUp) { // The increment will be calculated by ramping to 0 starting from scaler. down_increment = -scaler / duration_frames; - // Ramp down will start from current scaler. from = 1.0; to = 0.0; @@ -322,7 +321,7 @@ TEST(RampTestSuite, RampDownWhileHalfWayRampDown) { int duration_frames = 48000; int rc; int ramped_frames = 24000; - struct cras_ramp *ramp; + struct cras_ramp* ramp; struct cras_ramp_action action; float down_increment = -1.0 / 48000; float second_down_increment; @@ -341,7 +340,6 @@ TEST(RampTestSuite, RampDownWhileHalfWayRampDown) { // The increment will be calculated by ramping to 0 starting from scaler. second_down_increment = -scaler / duration_frames; - // Ramp down starting from current scaler. cras_mute_ramp_start(ramp, from, to, duration_frames, NULL, NULL); @@ -364,7 +362,7 @@ TEST(RampTestSuite, PartialRamp) { int duration_frames = 1200; int rc; int ramped_frames = 600; - struct cras_ramp *ramp; + struct cras_ramp* ramp; struct cras_ramp_action action; float down_increment = (to_one - from_one) / duration_frames; float up_increment; @@ -402,7 +400,7 @@ TEST(RampTestSuite, PartialRamp) { cras_ramp_destroy(ramp); } -void ramp_callback(void *arg) { +void ramp_callback(void* arg) { callback_called++; callback_arg = arg; } @@ -413,9 +411,9 @@ TEST(RampTestSuite, RampUpPassedRampCallback) { int duration_frames = 48000; int rc; int ramped_frames = 48000; - struct cras_ramp *ramp; + struct cras_ramp* ramp; struct cras_ramp_action action; - void *cb_data = reinterpret_cast<void*>(0x123); + void* cb_data = reinterpret_cast<void*>(0x123); ResetStubData(); @@ -443,9 +441,9 @@ TEST(RampTestSuite, RampDownPassedRampCallback) { int duration_frames = 48000; int rc; int ramped_frames = 48000; - struct cras_ramp *ramp; + struct cras_ramp* ramp; struct cras_ramp_action action; - void *cb_data = reinterpret_cast<void*>(0x123); + void* cb_data = reinterpret_cast<void*>(0x123); ResetStubData(); @@ -469,7 +467,7 @@ TEST(RampTestSuite, RampDownPassedRampCallback) { } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); int rc = RUN_ALL_TESTS(); diff --git a/cras/src/tests/rate_estimator_unittest.cc b/cras/src/tests/rate_estimator_unittest.cc index 23922c14..66f7c586 100644 --- a/cras/src/tests/rate_estimator_unittest.cc +++ b/cras/src/tests/rate_estimator_unittest.cc @@ -8,17 +8,11 @@ extern "C" { #include "rate_estimator.h" } -static struct timespec window = { - .tv_sec = 0, - .tv_nsec = 10000000 -}; +static struct timespec window = {.tv_sec = 0, .tv_nsec = 10000000}; TEST(RateEstimatorTest, EstimateOutputLinear) { - struct rate_estimator *re; - struct timespec t = { - .tv_sec = 1, - .tv_nsec = 0 - }; + struct rate_estimator* re; + struct timespec t = {.tv_sec = 1, .tv_nsec = 0}; int i, rc, level, tmp; re = rate_estimator_create(10000, &window, 0.0f); @@ -43,11 +37,8 @@ TEST(RateEstimatorTest, EstimateOutputLinear) { } TEST(RateEstimatorTest, EstimateOutputLinear2) { - struct rate_estimator *re; - struct timespec t = { - .tv_sec = 1, - .tv_nsec = 0 - }; + struct rate_estimator* re; + struct timespec t = {.tv_sec = 1, .tv_nsec = 0}; int level = 240; int i, rc, tmp; @@ -75,11 +66,8 @@ TEST(RateEstimatorTest, EstimateOutputLinear2) { } TEST(RateEstimatorTest, EstimateRateSkewTooLarge) { - struct rate_estimator *re; - struct timespec t = { - .tv_sec = 1, - .tv_nsec = 0 - }; + struct rate_estimator* re; + struct timespec t = {.tv_sec = 1, .tv_nsec = 0}; int level = 240; int i, rc, tmp; @@ -106,7 +94,7 @@ TEST(RateEstimatorTest, EstimateRateSkewTooLarge) { } TEST(RateEstimatorTest, EstimateOutputSmooth) { - struct rate_estimator *re; + struct rate_estimator* re; struct timespec t; int rc; @@ -135,7 +123,7 @@ TEST(RateEstimatorTest, EstimateOutputSmooth) { } TEST(RateEstimatorTest, EstimateInputLinear) { - struct rate_estimator *re; + struct rate_estimator* re; struct timespec t; int i, rc, level, tmp; @@ -162,13 +150,10 @@ TEST(RateEstimatorTest, EstimateInputLinear) { } TEST(RateEstimatorTest, EstimateInputLinear2) { - struct rate_estimator *re; + struct rate_estimator* re; struct timespec t; int rc; - static struct timespec this_window = { - .tv_sec = 0, - .tv_nsec = 100000000 - }; + static struct timespec this_window = {.tv_sec = 0, .tv_nsec = 100000000}; re = rate_estimator_create(10000, &this_window, 0.0f); t.tv_sec = 1; @@ -193,7 +178,7 @@ TEST(RateEstimatorTest, EstimateInputLinear2) { rate_estimator_destroy(re); } -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/rstream_stub.cc b/cras/src/tests/rstream_stub.cc index f6bb2e2d..18f6f951 100644 --- a/cras/src/tests/rstream_stub.cc +++ b/cras/src/tests/rstream_stub.cc @@ -12,12 +12,12 @@ extern "C" { namespace { struct cb_data { - std::unordered_map<unsigned int, unsigned int> dev_offset; - int pending_reply; + std::unordered_map<unsigned int, unsigned int> dev_offset; + int pending_reply; }; std::unordered_map<const cras_rstream*, cb_data> data_map; -}; +}; // namespace void rstream_stub_reset() { data_map.clear(); @@ -36,8 +36,7 @@ void rstream_stub_dev_offset(const cras_rstream* rstream, } } -void rstream_stub_pending_reply(const cras_rstream* rstream, - int ret_value) { +void rstream_stub_pending_reply(const cras_rstream* rstream, int ret_value) { auto data = data_map.find(rstream); if (data == data_map.end()) { cb_data new_data; @@ -50,19 +49,17 @@ void rstream_stub_pending_reply(const cras_rstream* rstream, extern "C" { -void cras_rstream_record_fetch_interval(struct cras_rstream *rstream, - const struct timespec *now) { -} +void cras_rstream_record_fetch_interval(struct cras_rstream* rstream, + const struct timespec* now) {} -void cras_rstream_dev_attach(struct cras_rstream *rstream, +void cras_rstream_dev_attach(struct cras_rstream* rstream, unsigned int dev_id, - void *dev_ptr) { -} + void* dev_ptr) {} -void cras_rstream_dev_detach(struct cras_rstream *rstream, unsigned int dev_id) { -} +void cras_rstream_dev_detach(struct cras_rstream* rstream, + unsigned int dev_id) {} -unsigned int cras_rstream_dev_offset(const struct cras_rstream *rstream, +unsigned int cras_rstream_dev_offset(const struct cras_rstream* rstream, unsigned int dev_id) { auto elem = data_map.find(rstream); if (elem != data_map.end()) @@ -70,61 +67,54 @@ unsigned int cras_rstream_dev_offset(const struct cras_rstream *rstream, return 0; } -void cras_rstream_dev_offset_update(struct cras_rstream *rstream, +void cras_rstream_dev_offset_update(struct cras_rstream* rstream, unsigned int frames, - unsigned int dev_id) { -} + unsigned int dev_id) {} -unsigned int cras_rstream_playable_frames(struct cras_rstream *rstream, +unsigned int cras_rstream_playable_frames(struct cras_rstream* rstream, unsigned int dev_id) { return 0; } -float cras_rstream_get_volume_scaler(struct cras_rstream *rstream) { +float cras_rstream_get_volume_scaler(struct cras_rstream* rstream) { return 1.0; } -int cras_rstream_get_mute(const struct cras_rstream *rstream) { +int cras_rstream_get_mute(const struct cras_rstream* rstream) { return 0; } -uint8_t *cras_rstream_get_readable_frames(struct cras_rstream *rstream, +uint8_t* cras_rstream_get_readable_frames(struct cras_rstream* rstream, unsigned int offset, - size_t *frames) { + size_t* frames) { return NULL; } -void cras_rstream_update_input_write_pointer(struct cras_rstream *rstream) { -} +void cras_rstream_update_input_write_pointer(struct cras_rstream* rstream) {} -void cras_rstream_update_output_read_pointer(struct cras_rstream *rstream) { -} +void cras_rstream_update_output_read_pointer(struct cras_rstream* rstream) {} -int cras_rstream_audio_ready(struct cras_rstream *stream, size_t count) { +int cras_rstream_audio_ready(struct cras_rstream* stream, size_t count) { cras_shm_buffer_write_complete(stream->shm); return 0; } -int cras_rstream_request_audio(struct cras_rstream *stream, - const struct timespec *now) { +int cras_rstream_request_audio(struct cras_rstream* stream, + const struct timespec* now) { return 0; } -void cras_rstream_update_queued_frames(struct cras_rstream *rstream) -{ -} +void cras_rstream_update_queued_frames(struct cras_rstream* rstream) {} -int cras_rstream_is_pending_reply(const struct cras_rstream *rstream) -{ +int cras_rstream_is_pending_reply(const struct cras_rstream* rstream) { auto elem = data_map.find(rstream); if (elem != data_map.end()) return elem->second.pending_reply; return 0; } -int cras_rstream_flush_old_audio_messages(struct cras_rstream *rstream) -{ +int cras_rstream_flush_old_audio_messages(struct cras_rstream* rstream) { return 0; } -} // extern "C" +} // extern "C" diff --git a/cras/src/tests/rstream_stub.h b/cras/src/tests/rstream_stub.h index 39a48b2c..249bcb76 100644 --- a/cras/src/tests/rstream_stub.h +++ b/cras/src/tests/rstream_stub.h @@ -11,11 +11,10 @@ void rstream_stub_reset(); void rstream_stub_dev_offset(const cras_rstream* rstream, - unsigned int dev_id, - unsigned int offset); + unsigned int dev_id, + unsigned int offset); // Stub that rstream is pending the reply from client or not. -void rstream_stub_pending_reply(const cras_rstream* rstream, - int ret_value); +void rstream_stub_pending_reply(const cras_rstream* rstream, int ret_value); -#endif // RSTREAM_STUB_H_ +#endif // RSTREAM_STUB_H_ diff --git a/cras/src/tests/rstream_unittest.cc b/cras/src/tests/rstream_unittest.cc index 2aa9a4ed..69523f5f 100644 --- a/cras/src/tests/rstream_unittest.cc +++ b/cras/src/tests/rstream_unittest.cc @@ -3,11 +3,11 @@ // found in the LICENSE file. #include <fcntl.h> +#include <gtest/gtest.h> #include <stdio.h> #include <sys/mman.h> #include <sys/socket.h> #include <sys/types.h> -#include <gtest/gtest.h> extern "C" { #include "cras_audio_area.h" @@ -19,65 +19,67 @@ extern "C" { namespace { class RstreamTestSuite : public testing::Test { - protected: - virtual void SetUp() { - int rc; - int sock[2] = {-1, -1}; - - fmt_.format = SND_PCM_FORMAT_S16_LE; - fmt_.frame_rate = 48000; - fmt_.num_channels = 2; - - config_.stream_id = 555; - config_.stream_type = CRAS_STREAM_TYPE_DEFAULT; - config_.direction = CRAS_STREAM_OUTPUT; - config_.dev_idx = NO_DEVICE; - config_.flags = 0; - config_.format = &fmt_; - config_.buffer_frames = 4096; - config_.cb_threshold = 2048; - - // Create a socket pair because it will be used in rstream. - rc = socketpair(AF_UNIX, SOCK_STREAM, 0, sock); - ASSERT_EQ(0, rc); - config_.audio_fd = sock[1]; - client_fd_ = sock[0]; - - config_.client = NULL; - } - - virtual void TearDown() { - close(config_.audio_fd); - close(client_fd_); - } - - static bool format_equal(cras_audio_format *fmt1, cras_audio_format *fmt2) { - return fmt1->format == fmt2->format && - fmt1->frame_rate == fmt2->frame_rate && - fmt1->num_channels == fmt2->num_channels; - } - - void stub_client_reply(enum CRAS_AUDIO_MESSAGE_ID id, int frames, int err) { - int rc; - struct audio_message aud_msg; - // Create a message. - aud_msg.id = id; - aud_msg.frames = frames; - aud_msg.error = err; - - // Use socket fd to stub message from client. - rc = write(client_fd_, &aud_msg, sizeof(aud_msg)); - EXPECT_EQ(sizeof(aud_msg), rc); - return; - } - - struct cras_audio_format fmt_; - struct cras_rstream_config config_; - int client_fd_; + protected: + virtual void SetUp() { + int rc; + int sock[2] = {-1, -1}; + + fmt_.format = SND_PCM_FORMAT_S16_LE; + fmt_.frame_rate = 48000; + fmt_.num_channels = 2; + + config_.stream_id = 555; + config_.stream_type = CRAS_STREAM_TYPE_DEFAULT; + config_.direction = CRAS_STREAM_OUTPUT; + config_.dev_idx = NO_DEVICE; + config_.flags = 0; + config_.format = &fmt_; + config_.buffer_frames = 4096; + config_.cb_threshold = 2048; + config_.client_shm_size = 0; + config_.client_shm_fd = -1; + + // Create a socket pair because it will be used in rstream. + rc = socketpair(AF_UNIX, SOCK_STREAM, 0, sock); + ASSERT_EQ(0, rc); + config_.audio_fd = sock[1]; + client_fd_ = sock[0]; + + config_.client = NULL; + } + + virtual void TearDown() { + close(config_.audio_fd); + close(client_fd_); + } + + static bool format_equal(cras_audio_format* fmt1, cras_audio_format* fmt2) { + return fmt1->format == fmt2->format && + fmt1->frame_rate == fmt2->frame_rate && + fmt1->num_channels == fmt2->num_channels; + } + + void stub_client_reply(enum CRAS_AUDIO_MESSAGE_ID id, int frames, int err) { + int rc; + struct audio_message aud_msg; + // Create a message. + aud_msg.id = id; + aud_msg.frames = frames; + aud_msg.error = err; + + // Use socket fd to stub message from client. + rc = write(client_fd_, &aud_msg, sizeof(aud_msg)); + EXPECT_EQ(sizeof(aud_msg), rc); + return; + } + + struct cras_audio_format fmt_; + struct cras_rstream_config config_; + int client_fd_; }; TEST_F(RstreamTestSuite, InvalidDirection) { - struct cras_rstream *s; + struct cras_rstream* s; int rc; config_.direction = (enum CRAS_STREAM_DIRECTION)66; @@ -86,7 +88,7 @@ TEST_F(RstreamTestSuite, InvalidDirection) { } TEST_F(RstreamTestSuite, InvalidStreamType) { - struct cras_rstream *s; + struct cras_rstream* s; int rc; config_.stream_type = (enum CRAS_STREAM_TYPE)7; @@ -95,7 +97,7 @@ TEST_F(RstreamTestSuite, InvalidStreamType) { } TEST_F(RstreamTestSuite, InvalidBufferSize) { - struct cras_rstream *s; + struct cras_rstream* s; int rc; config_.buffer_frames = 3; @@ -104,7 +106,7 @@ TEST_F(RstreamTestSuite, InvalidBufferSize) { } TEST_F(RstreamTestSuite, InvalidCallbackThreshold) { - struct cras_rstream *s; + struct cras_rstream* s; int rc; config_.cb_threshold = 3; @@ -120,16 +122,16 @@ TEST_F(RstreamTestSuite, InvalidStreamPointer) { } TEST_F(RstreamTestSuite, CreateOutput) { - struct cras_rstream *s; + struct cras_rstream* s; struct cras_audio_format fmt_ret; - struct cras_audio_shm *shm_ret; + struct cras_audio_shm* shm_ret; struct cras_audio_shm shm_mapped; int rc, header_fd = -1, samples_fd = -1; size_t shm_size; rc = cras_rstream_create(&config_, &s); EXPECT_EQ(0, rc); - EXPECT_NE((void *)NULL, s); + EXPECT_NE((void*)NULL, s); EXPECT_EQ(4096, cras_rstream_get_buffer_frames(s)); EXPECT_EQ(2048, cras_rstream_get_cb_threshold(s)); EXPECT_EQ(CRAS_STREAM_TYPE_DEFAULT, cras_rstream_get_type(s)); @@ -141,7 +143,7 @@ TEST_F(RstreamTestSuite, CreateOutput) { // Check if shm is really set up. shm_ret = cras_rstream_shm(s); - ASSERT_NE((void *)NULL, shm_ret); + ASSERT_NE((void*)NULL, shm_ret); cras_rstream_get_shm_fds(s, &header_fd, &samples_fd); shm_size = cras_shm_samples_size(shm_ret); EXPECT_EQ(shm_size, 32768); @@ -157,9 +159,9 @@ TEST_F(RstreamTestSuite, CreateOutput) { } TEST_F(RstreamTestSuite, CreateInput) { - struct cras_rstream *s; + struct cras_rstream* s; struct cras_audio_format fmt_ret; - struct cras_audio_shm *shm_ret; + struct cras_audio_shm* shm_ret; struct cras_audio_shm shm_mapped; int rc, header_fd = -1, samples_fd = -1; size_t shm_size; @@ -167,7 +169,7 @@ TEST_F(RstreamTestSuite, CreateInput) { config_.direction = CRAS_STREAM_INPUT; rc = cras_rstream_create(&config_, &s); EXPECT_EQ(0, rc); - EXPECT_NE((void *)NULL, s); + EXPECT_NE((void*)NULL, s); EXPECT_EQ(4096, cras_rstream_get_buffer_frames(s)); EXPECT_EQ(2048, cras_rstream_get_cb_threshold(s)); EXPECT_EQ(CRAS_STREAM_TYPE_DEFAULT, cras_rstream_get_type(s)); @@ -179,7 +181,7 @@ TEST_F(RstreamTestSuite, CreateInput) { // Check if shm is really set up. shm_ret = cras_rstream_shm(s); - ASSERT_NE((void *)NULL, shm_ret); + ASSERT_NE((void*)NULL, shm_ret); cras_rstream_get_shm_fds(s, &header_fd, &samples_fd); shm_size = cras_shm_samples_size(shm_ret); EXPECT_EQ(shm_size, 32768); @@ -195,7 +197,7 @@ TEST_F(RstreamTestSuite, CreateInput) { } TEST_F(RstreamTestSuite, VerifyStreamTypes) { - struct cras_rstream *s; + struct cras_rstream* s; int rc; config_.stream_type = CRAS_STREAM_TYPE_DEFAULT; @@ -226,7 +228,7 @@ TEST_F(RstreamTestSuite, VerifyStreamTypes) { } TEST_F(RstreamTestSuite, OutputStreamIsPendingReply) { - struct cras_rstream *s; + struct cras_rstream* s; int rc; struct timespec ts; @@ -249,7 +251,7 @@ TEST_F(RstreamTestSuite, OutputStreamIsPendingReply) { } TEST_F(RstreamTestSuite, OutputStreamFlushMessages) { - struct cras_rstream *s; + struct cras_rstream* s; int rc; struct timespec ts; @@ -282,7 +284,7 @@ TEST_F(RstreamTestSuite, OutputStreamFlushMessages) { } TEST_F(RstreamTestSuite, InputStreamIsPendingReply) { - struct cras_rstream *s; + struct cras_rstream* s; int rc; config_.direction = CRAS_STREAM_INPUT; @@ -306,7 +308,7 @@ TEST_F(RstreamTestSuite, InputStreamIsPendingReply) { } TEST_F(RstreamTestSuite, InputStreamFlushMessages) { - struct cras_rstream *s; + struct cras_rstream* s; int rc; config_.direction = CRAS_STREAM_INPUT; @@ -341,7 +343,7 @@ TEST_F(RstreamTestSuite, InputStreamFlushMessages) { } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } @@ -349,79 +351,66 @@ int main(int argc, char **argv) { /* stubs */ extern "C" { -struct cras_audio_area *cras_audio_area_create(int num_channels) { +struct cras_audio_area* cras_audio_area_create(int num_channels) { return NULL; } -void cras_audio_area_destroy(struct cras_audio_area *area) { -} +void cras_audio_area_destroy(struct cras_audio_area* area) {} -void cras_audio_area_config_channels(struct cras_audio_area *area, - const struct cras_audio_format *fmt) { -} +void cras_audio_area_config_channels(struct cras_audio_area* area, + const struct cras_audio_format* fmt) {} -struct buffer_share *buffer_share_create(unsigned int buf_sz) { +struct buffer_share* buffer_share_create(unsigned int buf_sz) { return NULL; } -void buffer_share_destroy(struct buffer_share *mix) { -} +void buffer_share_destroy(struct buffer_share* mix) {} -int buffer_share_offset_update(struct buffer_share *mix, unsigned int id, +int buffer_share_offset_update(struct buffer_share* mix, + unsigned int id, unsigned int frames) { return 0; } -unsigned int buffer_share_get_new_write_point(struct buffer_share *mix) { +unsigned int buffer_share_get_new_write_point(struct buffer_share* mix) { return 0; } -int buffer_share_add_id(struct buffer_share *mix, unsigned int id) { +int buffer_share_add_id(struct buffer_share* mix, unsigned int id) { return 0; } -int buffer_share_rm_id(struct buffer_share *mix, unsigned int id) { +int buffer_share_rm_id(struct buffer_share* mix, unsigned int id) { return 0; } -unsigned int buffer_share_id_offset(const struct buffer_share *mix, - unsigned int id) -{ +unsigned int buffer_share_id_offset(const struct buffer_share* mix, + unsigned int id) { return 0; } -void cras_system_state_stream_added(enum CRAS_STREAM_DIRECTION direction) { -} +void cras_system_state_stream_added(enum CRAS_STREAM_DIRECTION direction) {} -void cras_system_state_stream_removed(enum CRAS_STREAM_DIRECTION direction) { -} +void cras_system_state_stream_removed(enum CRAS_STREAM_DIRECTION direction) {} #ifdef HAVE_WEBRTC_APM -struct cras_apm_list *cras_apm_list_create(void *stream_ptr, - uint64_t effects) -{ +struct cras_apm_list* cras_apm_list_create(void* stream_ptr, uint64_t effects) { return NULL; } -int cras_apm_list_destroy(struct cras_apm_list *list) -{ +int cras_apm_list_destroy(struct cras_apm_list* list) { return 0; } -uint64_t cras_apm_list_get_effects(struct cras_apm_list *list) -{ +uint64_t cras_apm_list_get_effects(struct cras_apm_list* list) { return APM_ECHO_CANCELLATION; } -struct cras_apm *cras_apm_list_get(struct cras_apm_list *list, - void *dev_ptr) -{ +struct cras_apm* cras_apm_list_get(struct cras_apm_list* list, void* dev_ptr) { return NULL; } -struct cras_audio_format *cras_apm_list_get_format(struct cras_apm *apm) -{ +struct cras_audio_format* cras_apm_list_get_format(struct cras_apm* apm) { return NULL; } #endif -int cras_server_metrics_missed_cb_frequency(const struct cras_rstream *stream) -{ +int cras_server_metrics_missed_cb_frequency(const struct cras_rstream* stream) { return 0; } } diff --git a/cras/src/tests/sbc_codec_stub.cc b/cras/src/tests/sbc_codec_stub.cc new file mode 100644 index 00000000..95bd091c --- /dev/null +++ b/cras/src/tests/sbc_codec_stub.cc @@ -0,0 +1,174 @@ +/* Copyright 2019 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#include <stdlib.h> + +extern "C" { +#include "cras_audio_codec.h" +#include "sbc_codec_stub.h" +} + +namespace { + +static int create_fail; +static int create_called; +static int msbc_create_called; +static int destroy_called; +static uint8_t freq_val; +static uint8_t mode_val; +static uint8_t subbands_val; +static uint8_t alloc_val; +static uint8_t blocks_val; +static uint8_t bitpool_val; +static struct cras_audio_codec* sbc_codec; +static size_t decode_out_decoded_return_val; +static int decode_fail; +static size_t encode_out_encoded_return_val; +static int encode_fail; +static int cras_sbc_get_frame_length_val; +static int cras_sbc_get_codesize_val; + +}; // namespace + +void sbc_codec_stub_reset() { + create_fail = 0; + create_called = 0; + msbc_create_called = 0; + destroy_called = 0; + freq_val = 0; + mode_val = 0; + subbands_val = 0; + alloc_val = 0; + blocks_val = 0; + bitpool_val = 0; + + sbc_codec = NULL; + decode_out_decoded_return_val = 0; + encode_out_encoded_return_val = 0; + decode_fail = 0; + encode_fail = 0; + + cras_sbc_get_frame_length_val = 5; + cras_sbc_get_codesize_val = 5; +} + +void set_sbc_codec_create_fail(int fail) { + create_fail = fail; +} + +int get_sbc_codec_create_called() { + return create_called; +} + +int get_msbc_codec_create_called() { + return msbc_create_called; +} + +uint8_t get_sbc_codec_create_freq_val() { + return freq_val; +} + +uint8_t get_sbc_codec_create_mode_val() { + return mode_val; +} + +uint8_t get_sbc_codec_create_subbands_val() { + return subbands_val; +} + +uint8_t get_sbc_codec_create_alloc_val() { + return alloc_val; +} + +uint8_t get_sbc_codec_create_blocks_val() { + return blocks_val; +} + +uint8_t get_sbc_codec_create_bitpool_val() { + return bitpool_val; +} + +int get_sbc_codec_destroy_called() { + return destroy_called; +} + +void set_sbc_codec_decoded_out(size_t ret) { + decode_out_decoded_return_val = ret; +} + +void set_sbc_codec_decoded_fail(int fail) { + decode_fail = fail; +} + +void set_sbc_codec_encoded_out(size_t ret) { + encode_out_encoded_return_val = ret; +} + +void set_sbc_codec_encoded_fail(int fail) { + encode_fail = fail; +} + +int decode(struct cras_audio_codec* codec, + const void* input, + size_t input_len, + void* output, + size_t output_len, + size_t* count) { + *count = decode_out_decoded_return_val; + return decode_fail ? -1 : input_len; +} + +int encode(struct cras_audio_codec* codec, + const void* input, + size_t input_len, + void* output, + size_t output_len, + size_t* count) { + // Written half the output buffer. + *count = encode_out_encoded_return_val; + return encode_fail ? -1 : input_len; +} + +struct cras_audio_codec* cras_sbc_codec_create(uint8_t freq, + uint8_t mode, + uint8_t subbands, + uint8_t alloc, + uint8_t blocks, + uint8_t bitpool) { + if (!create_fail) { + sbc_codec = (struct cras_audio_codec*)calloc(1, sizeof(*sbc_codec)); + sbc_codec->decode = decode; + sbc_codec->encode = encode; + } + + create_called++; + freq_val = freq; + mode_val = mode; + subbands_val = subbands; + alloc_val = alloc; + blocks_val = blocks; + bitpool_val = bitpool; + return sbc_codec; +} + +struct cras_audio_codec* cras_msbc_codec_create() { + msbc_create_called++; + sbc_codec = (struct cras_audio_codec*)calloc(1, sizeof(*sbc_codec)); + sbc_codec->decode = decode; + sbc_codec->encode = encode; + return sbc_codec; +} + +void cras_sbc_codec_destroy(struct cras_audio_codec* codec) { + destroy_called++; + free(codec); +} + +int cras_sbc_get_codesize(struct cras_audio_codec* codec) { + return cras_sbc_get_codesize_val; +} + +int cras_sbc_get_frame_length(struct cras_audio_codec* codec) { + return cras_sbc_get_frame_length_val; +} diff --git a/cras/src/tests/sbc_codec_stub.h b/cras/src/tests/sbc_codec_stub.h new file mode 100644 index 00000000..b166b399 --- /dev/null +++ b/cras/src/tests/sbc_codec_stub.h @@ -0,0 +1,39 @@ +/* Copyright 2019 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SBC_CODEC_STUB_H_ +#define SBC_CODEC_STUB_H_ + +#include <stdint.h> +#include <stdlib.h> + +void sbc_codec_stub_reset(); +void set_sbc_codec_create_fail(int fail); +int get_sbc_codec_create_called(); +int get_msbc_codec_create_called(); +uint8_t get_sbc_codec_create_freq_val(); +uint8_t get_sbc_codec_create_mode_val(); +uint8_t get_sbc_codec_create_subbands_val(); +uint8_t get_sbc_codec_create_alloc_val(); +uint8_t get_sbc_codec_create_blocks_val(); +uint8_t get_sbc_codec_create_bitpool_val(); +int get_sbc_codec_destroy_called(); +void set_sbc_codec_decoded_out(size_t ret); +void set_sbc_codec_decoded_fail(int fail); +void set_sbc_codec_encoded_out(size_t ret); +void set_sbc_codec_encoded_fail(int fail); + +struct cras_audio_codec* cras_sbc_codec_create(uint8_t freq, + uint8_t mode, + uint8_t subbands, + uint8_t alloc, + uint8_t blocks, + uint8_t bitpool); +struct cras_audio_codec* cras_msbc_codec_create(); +void cras_sbc_codec_destroy(struct cras_audio_codec* codec); +int cras_sbc_get_codesize(struct cras_audio_codec* codec); +int cras_sbc_get_frame_length(struct cras_audio_codec* codec); + +#endif // SBC_CODEC_STUB_H_ diff --git a/cras/src/tests/server_metrics_unittest.cc b/cras/src/tests/server_metrics_unittest.cc index 7b8fc8c9..94a689c5 100644 --- a/cras/src/tests/server_metrics_unittest.cc +++ b/cras/src/tests/server_metrics_unittest.cc @@ -39,6 +39,7 @@ TEST(ServerMetricsTestSuite, SetMetricsDeviceRuntime) { clock_gettime_retspec.tv_sec = 200; clock_gettime_retspec.tv_nsec = 0; + iodev.info.idx = MAX_SPECIAL_DEVICE_IDX; iodev.open_ts.tv_sec = 100; iodev.open_ts.tv_nsec = 0; iodev.direction = CRAS_STREAM_INPUT; @@ -52,7 +53,7 @@ TEST(ServerMetricsTestSuite, SetMetricsDeviceRuntime) { EXPECT_EQ(sent_msgs[0].header.length, sizeof(struct cras_server_metrics_message)); EXPECT_EQ(sent_msgs[0].metrics_type, DEVICE_RUNTIME); - EXPECT_STREQ(sent_msgs[0].data.device_data.type, "USB"); + EXPECT_EQ(sent_msgs[0].data.device_data.type, CRAS_METRICS_DEVICE_USB); EXPECT_EQ(sent_msgs[0].data.device_data.direction, CRAS_STREAM_INPUT); EXPECT_EQ(sent_msgs[0].data.device_data.runtime.tv_sec, 100); @@ -73,7 +74,7 @@ TEST(ServerMetricsTestSuite, SetMetricsDeviceRuntime) { EXPECT_EQ(sent_msgs[0].header.length, sizeof(struct cras_server_metrics_message)); EXPECT_EQ(sent_msgs[0].metrics_type, DEVICE_RUNTIME); - EXPECT_STREQ(sent_msgs[0].data.device_data.type, "Headphone"); + EXPECT_EQ(sent_msgs[0].data.device_data.type, CRAS_METRICS_DEVICE_HEADPHONE); EXPECT_EQ(sent_msgs[0].data.device_data.direction, CRAS_STREAM_OUTPUT); EXPECT_EQ(sent_msgs[0].data.device_data.runtime.tv_sec, 200); } @@ -319,10 +320,12 @@ TEST(ServerMetricsTestSuite, SetMetricsStreamConfig) { struct cras_rstream_config config; struct cras_audio_format format; + config.direction = CRAS_STREAM_INPUT; config.cb_threshold = 1024; config.flags = BULK_AUDIO_OK; format.format = SND_PCM_FORMAT_S16_LE; format.frame_rate = 48000; + config.client_type = CRAS_CLIENT_TYPE_TEST; config.format = &format; cras_server_metrics_stream_config(&config); @@ -332,10 +335,29 @@ TEST(ServerMetricsTestSuite, SetMetricsStreamConfig) { EXPECT_EQ(sent_msgs[0].header.length, sizeof(struct cras_server_metrics_message)); EXPECT_EQ(sent_msgs[0].metrics_type, STREAM_CONFIG); + EXPECT_EQ(sent_msgs[0].data.stream_config.direction, CRAS_STREAM_INPUT); EXPECT_EQ(sent_msgs[0].data.stream_config.cb_threshold, 1024); EXPECT_EQ(sent_msgs[0].data.stream_config.flags, BULK_AUDIO_OK); EXPECT_EQ(sent_msgs[0].data.stream_config.format, SND_PCM_FORMAT_S16_LE); EXPECT_EQ(sent_msgs[0].data.stream_config.rate, 48000); + EXPECT_EQ(sent_msgs[0].data.stream_config.client_type, CRAS_CLIENT_TYPE_TEST); +} + +TEST(ServerMetricsTestSuite, SetMetricsBusyloop) { + ResetStubData(); + struct timespec time = {40, 0}; + unsigned count = 3; + + cras_server_metrics_busyloop(&time, count); + + EXPECT_EQ(sent_msgs.size(), 1); + EXPECT_EQ(sent_msgs[0].header.type, CRAS_MAIN_METRICS); + EXPECT_EQ(sent_msgs[0].header.length, + sizeof(struct cras_server_metrics_message)); + EXPECT_EQ(sent_msgs[0].metrics_type, BUSYLOOP); + EXPECT_EQ(sent_msgs[0].data.timespec_data.runtime.tv_sec, 40); + EXPECT_EQ(sent_msgs[0].data.timespec_data.runtime.tv_nsec, 0); + EXPECT_EQ(sent_msgs[0].data.timespec_data.count, 3); } extern "C" { diff --git a/cras/src/tests/shm_unittest.cc b/cras/src/tests/shm_unittest.cc index 07e25d12..b5df1f69 100644 --- a/cras/src/tests/shm_unittest.cc +++ b/cras/src/tests/shm_unittest.cc @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <stdio.h> #include <gtest/gtest.h> +#include <stdio.h> extern "C" { #include "cras_shm.h" @@ -12,28 +12,30 @@ extern "C" { namespace { -class ShmTestSuite : public testing::Test{ - protected: - virtual void SetUp() { - memset(&shm_, 0, sizeof(shm_)); - shm_.header = - static_cast<cras_audio_shm_header*>(calloc(1, sizeof(*shm_.header))); - shm_.samples = static_cast<uint8_t*>(calloc(1, 2048)); - cras_shm_set_frame_bytes(&shm_, 4); - cras_shm_set_used_size(&shm_, 1024); - memcpy(&shm_.header->config, &shm_.config, sizeof(shm_.config)); - - frames_ = 0; - } - - virtual void TearDown() { - free(shm_.header); - free(shm_.samples); - } - - struct cras_audio_shm shm_; - uint8_t *buf_; - size_t frames_; +class ShmTestSuite : public testing::Test { + protected: + virtual void SetUp() { + memset(&shm_, 0, sizeof(shm_)); + shm_.header = + static_cast<cras_audio_shm_header*>(calloc(1, sizeof(*shm_.header))); + shm_.samples = static_cast<uint8_t*>(calloc(1, 2048)); + shm_.samples_info.length = 2048; + cras_shm_set_frame_bytes(&shm_, 4); + + cras_shm_set_used_size(&shm_, 1024); + memcpy(&shm_.header->config, &shm_.config, sizeof(shm_.config)); + + frames_ = 0; + } + + virtual void TearDown() { + free(shm_.header); + free(shm_.samples); + } + + struct cras_audio_shm shm_; + uint8_t* buf_; + size_t frames_; }; // Test that and empty buffer returns 0 readable bytes. @@ -85,34 +87,40 @@ TEST_F(ShmTestSuite, OneHundredFilled50Read25offset) { // Test wrapping across buffers. TEST_F(ShmTestSuite, WrapToNextBuffer) { - shm_.config.used_size = 480 * shm_.config.frame_bytes; - shm_.header->write_offset[0] = 240 * shm_.config.frame_bytes; - shm_.header->read_offset[0] = 120 * shm_.config.frame_bytes; - shm_.header->write_offset[1] = 240 * shm_.config.frame_bytes; + uint32_t used_size = cras_shm_used_size(&shm_); + uint32_t used_frames = used_size / cras_shm_frame_bytes(&shm_); + shm_.header->write_offset[0] = (used_size / 2); + shm_.header->read_offset[0] = (used_size / 4); + shm_.header->write_offset[1] = (used_size / 2); buf_ = cras_shm_get_readable_frames(&shm_, 0, &frames_); - EXPECT_EQ(120, frames_); - EXPECT_EQ(shm_.samples + shm_.header->read_offset[0], (uint8_t*)buf_); + EXPECT_EQ(used_frames / 4, frames_); + EXPECT_EQ(cras_shm_buff_for_idx(&shm_, 0) + (used_size / 4), (uint8_t*)buf_); buf_ = cras_shm_get_readable_frames(&shm_, frames_, &frames_); - EXPECT_EQ(240, frames_); - EXPECT_EQ(shm_.samples + shm_.config.used_size, (uint8_t*)buf_); - cras_shm_buffer_read(&shm_, 350); /* Mark all-10 as read */ + EXPECT_EQ(used_frames / 2, frames_); + EXPECT_EQ(cras_shm_buff_for_idx(&shm_, 1), (uint8_t*)buf_); + /* Mark all but 10 frames as read */ + cras_shm_buffer_read(&shm_, (used_frames / 2) + (used_frames / 4) - 10); EXPECT_EQ(0, shm_.header->read_offset[0]); - EXPECT_EQ(230 * shm_.config.frame_bytes, shm_.header->read_offset[1]); + EXPECT_EQ(((used_frames / 2) - 10) * shm_.config.frame_bytes, + shm_.header->read_offset[1]); + EXPECT_EQ(1, shm_.header->read_buf_idx); } // Test wrapping across buffers reading all samples. TEST_F(ShmTestSuite, WrapToNextBufferReadAll) { - shm_.config.used_size = 480 * shm_.config.frame_bytes; - shm_.header->write_offset[0] = 240 * shm_.config.frame_bytes; - shm_.header->read_offset[0] = 120 * shm_.config.frame_bytes; - shm_.header->write_offset[1] = 240 * shm_.config.frame_bytes; + uint32_t used_size = cras_shm_used_size(&shm_); + uint32_t used_frames = used_size / cras_shm_frame_bytes(&shm_); + shm_.header->write_offset[0] = (used_size / 2); + shm_.header->read_offset[0] = (used_size / 4); + shm_.header->write_offset[1] = (used_size / 2); buf_ = cras_shm_get_readable_frames(&shm_, 0, &frames_); - EXPECT_EQ(120, frames_); - EXPECT_EQ(shm_.samples + shm_.header->read_offset[0], (uint8_t*)buf_); + EXPECT_EQ(used_frames / 4, frames_); + EXPECT_EQ(cras_shm_buff_for_idx(&shm_, 0) + (used_size / 4), (uint8_t*)buf_); buf_ = cras_shm_get_readable_frames(&shm_, frames_, &frames_); - EXPECT_EQ(240, frames_); - EXPECT_EQ(shm_.samples + shm_.config.used_size, (uint8_t*)buf_); - cras_shm_buffer_read(&shm_, 360); /* Mark all as read */ + EXPECT_EQ(used_frames / 2, frames_); + EXPECT_EQ(cras_shm_buff_for_idx(&shm_, 1), (uint8_t*)buf_); + /* Mark all frames as read */ + cras_shm_buffer_read(&shm_, (used_frames / 2) + (used_frames / 4)); EXPECT_EQ(0, shm_.header->read_offset[0]); EXPECT_EQ(0, shm_.header->read_offset[1]); EXPECT_EQ(0, shm_.header->read_buf_idx); @@ -120,24 +128,28 @@ TEST_F(ShmTestSuite, WrapToNextBufferReadAll) { // Test wrapping last buffer. TEST_F(ShmTestSuite, WrapFromFinalBuffer) { - shm_.header->read_buf_idx = CRAS_NUM_SHM_BUFFERS - 1; - shm_.config.used_size = 480 * shm_.config.frame_bytes; - shm_.header->write_offset[shm_.header->read_buf_idx] = - 240 * shm_.config.frame_bytes; - shm_.header->read_offset[shm_.header->read_buf_idx] = - 120 * shm_.config.frame_bytes; - shm_.header->write_offset[0] = 240 * shm_.config.frame_bytes; + uint32_t used_size = cras_shm_used_size(&shm_); + uint32_t used_frames = used_size / cras_shm_frame_bytes(&shm_); + uint32_t buf_idx = CRAS_NUM_SHM_BUFFERS - 1; + + shm_.header->read_buf_idx = buf_idx; + shm_.header->write_offset[buf_idx] = (used_size / 2); + shm_.header->read_offset[buf_idx] = (used_size / 4); + shm_.header->write_offset[0] = (used_size / 2); buf_ = cras_shm_get_readable_frames(&shm_, 0, &frames_); - EXPECT_EQ(120, frames_); - EXPECT_EQ((uint8_t*)buf_, - shm_.samples + shm_.config.used_size * shm_.header->read_buf_idx + - shm_.header->read_offset[shm_.header->read_buf_idx]); + EXPECT_EQ(used_frames / 4, frames_); + EXPECT_EQ(cras_shm_buff_for_idx(&shm_, buf_idx) + (used_size / 4), + (uint8_t*)buf_); + buf_ = cras_shm_get_readable_frames(&shm_, frames_, &frames_); - EXPECT_EQ(240, frames_); - EXPECT_EQ(shm_.samples, (uint8_t*)buf_); - cras_shm_buffer_read(&shm_, 350); /* Mark all-10 as read */ - EXPECT_EQ(0, shm_.header->read_offset[1]); - EXPECT_EQ(230 * shm_.config.frame_bytes, shm_.header->read_offset[0]); + EXPECT_EQ(used_frames / 2, frames_); + EXPECT_EQ(cras_shm_buff_for_idx(&shm_, 0), (uint8_t*)buf_); + /* Mark all but 10 frames as read */ + cras_shm_buffer_read(&shm_, (used_frames / 2) + (used_frames / 4) - 10); + EXPECT_EQ(0, shm_.header->read_offset[buf_idx]); + EXPECT_EQ(((used_frames / 2) - 10) * shm_.config.frame_bytes, + shm_.header->read_offset[0]); + EXPECT_EQ(0, shm_.header->read_buf_idx); } // Test Check available to write returns 0 if not free buffer. @@ -177,9 +189,8 @@ TEST_F(ShmTestSuite, GetWriteBufferBase) { uint8_t* ret; shm_.header->write_buf_idx = 0; - shm_.config.used_size = 480 * shm_.config.frame_bytes; - shm_.header->write_offset[0] = 200 * shm_.config.frame_bytes; - shm_.header->write_offset[1] = 200 * shm_.config.frame_bytes; + shm_.header->write_offset[0] = 128 * shm_.config.frame_bytes; + shm_.header->write_offset[1] = 128 * shm_.config.frame_bytes; shm_.header->read_offset[0] = 0; shm_.header->read_offset[1] = 0; ret = cras_shm_get_write_buffer_base(&shm_); @@ -279,9 +290,283 @@ TEST_F(ShmTestSuite, GetWritableFramesNoNeedToWrite) { EXPECT_EQ(shm_.samples + shm_.header->write_offset[0], buf_); } +// Test wrapping of buffers that don't start at normal offsets. +TEST_F(ShmTestSuite, WrapWithNonstandardBufferLocations) { + uint32_t frame_bytes = cras_shm_frame_bytes(&shm_); + uint32_t used_frames = 24; + uint32_t used_size = used_frames * frame_bytes; + cras_shm_set_used_size(&shm_, used_size); + cras_shm_set_buffer_offset(&shm_, 0, 15); + cras_shm_set_buffer_offset(&shm_, 1, 479); + + shm_.header->read_offset[0] = (used_frames / 4) * shm_.config.frame_bytes; + shm_.header->write_offset[0] = (used_frames / 2) * shm_.config.frame_bytes; + shm_.header->read_offset[1] = 0; + shm_.header->write_offset[1] = (used_frames / 3) * shm_.config.frame_bytes; + buf_ = cras_shm_get_readable_frames(&shm_, 0, &frames_); + EXPECT_EQ(used_frames / 4, frames_); + EXPECT_EQ(cras_shm_buff_for_idx(&shm_, 0) + shm_.header->read_offset[0], + (uint8_t*)buf_); + buf_ = cras_shm_get_readable_frames(&shm_, frames_, &frames_); + EXPECT_EQ(used_frames / 3, frames_); + EXPECT_EQ(cras_shm_buff_for_idx(&shm_, 1), (uint8_t*)buf_); + /* Mark all but 5 frames as read */ + cras_shm_buffer_read(&shm_, (used_frames / 4) + (used_frames / 3) - 5); + EXPECT_EQ(0, shm_.header->read_offset[0]); + EXPECT_EQ(((used_frames / 3) - 5) * shm_.config.frame_bytes, + shm_.header->read_offset[1]); +} + +TEST_F(ShmTestSuite, PlaybackWithDifferentSequentialBufferLocations) { + uint32_t frame_bytes = cras_shm_frame_bytes(&shm_); + uint32_t used_frames = 24; + uint32_t used_size = used_frames * frame_bytes; + cras_shm_set_used_size(&shm_, used_size); + + uint32_t first_offset = 2.7 * used_size; + /* Make samples area long enough to hold all of the buffers starting from + * first_offset, with an extra 'used_size' bytes of free space at the end. */ + uint32_t samples_length = + first_offset + used_size * (CRAS_NUM_SHM_BUFFERS + 1); + free(shm_.samples); + shm_.samples = static_cast<uint8_t*>(calloc(1, samples_length)); + shm_.samples_info.length = samples_length; + uint32_t total_frames_written = 0; + + // Fill all of the buffers. + for (unsigned int i = 0; i < CRAS_NUM_SHM_BUFFERS; i++) { + cras_shm_set_buffer_offset(&shm_, i, first_offset + i * used_size); + shm_.header->write_in_progress[i] = 1; + shm_.header->write_offset[i] = 0; + frames_ = MIN(10 + i, used_frames); + cras_shm_buffer_written(&shm_, frames_); + total_frames_written += frames_; + cras_shm_buffer_write_complete(&shm_); + } + + uint32_t total_frames_available = 0; + + // Consume all available frames. + while ((buf_ = cras_shm_get_readable_frames(&shm_, 0, &frames_))) { + total_frames_available += frames_; + + EXPECT_GE(buf_, shm_.samples); + EXPECT_LE(buf_ + frames_, shm_.samples + samples_length); + cras_shm_buffer_read(&shm_, frames_); + } + + EXPECT_EQ(total_frames_written, total_frames_available); + + uint32_t second_offset = 1.2 * used_size; + + // Fill half of the buffers. + for (unsigned int i = 0; i < CRAS_NUM_SHM_BUFFERS / 2; i++) { + cras_shm_set_buffer_offset(&shm_, i, second_offset + i * used_size); + shm_.header->write_in_progress[i] = 1; + shm_.header->write_offset[i] = 0; + frames_ = MIN(3 + 2 * i, used_frames); + cras_shm_buffer_written(&shm_, frames_); + total_frames_written += frames_; + cras_shm_buffer_write_complete(&shm_); + } + + // Consume all available frames. + while ((buf_ = cras_shm_get_readable_frames(&shm_, 0, &frames_))) { + total_frames_available += frames_; + + EXPECT_GE(buf_, shm_.samples); + EXPECT_LE(buf_ + frames_, shm_.samples + samples_length); + cras_shm_buffer_read(&shm_, frames_); + } + + EXPECT_EQ(total_frames_written, total_frames_available); + + // Fill rest of the buffers. + for (unsigned int i = CRAS_NUM_SHM_BUFFERS / 2; i < CRAS_NUM_SHM_BUFFERS; + i++) { + cras_shm_set_buffer_offset(&shm_, i, second_offset + i * used_size); + shm_.header->write_in_progress[i] = 1; + shm_.header->write_offset[i] = 0; + frames_ = MIN(3 + 2 * i, used_frames); + cras_shm_buffer_written(&shm_, frames_); + total_frames_written += frames_; + cras_shm_buffer_write_complete(&shm_); + } + + // Consume all available frames. + while ((buf_ = cras_shm_get_readable_frames(&shm_, 0, &frames_))) { + total_frames_available += frames_; + + EXPECT_GE(buf_, shm_.samples); + EXPECT_LE(buf_ + frames_, shm_.samples + samples_length); + cras_shm_buffer_read(&shm_, frames_); + } + + EXPECT_EQ(total_frames_written, total_frames_available); +} + +TEST_F(ShmTestSuite, GetCheckedBufferOffset) { + uint32_t used_size = cras_shm_used_size(&shm_); + uint32_t samples_length = used_size * 8; + shm_.samples_info.length = samples_length; + + uint32_t offset; + + for (unsigned int i = 0; i < CRAS_NUM_SHM_BUFFERS; i++) { + shm_.header->buffer_offset[i] = 0; + offset = cras_shm_get_checked_buffer_offset(&shm_, i); + EXPECT_EQ(0, offset) << "Expected valid buffer offset for buffer " << i; + + shm_.header->buffer_offset[i] = used_size; + offset = cras_shm_get_checked_buffer_offset(&shm_, i); + EXPECT_EQ(used_size, offset) + << "Expected valid buffer offset for buffer " << i; + + shm_.header->buffer_offset[i] = samples_length - 1; + offset = cras_shm_get_checked_buffer_offset(&shm_, i); + EXPECT_EQ(samples_length - 1, offset) + << "Expected valid buffer offset for buffer " << i; + + shm_.header->buffer_offset[i] = samples_length; + offset = cras_shm_get_checked_buffer_offset(&shm_, i); + EXPECT_EQ(samples_length, offset) + << "Expected valid buffer offset for buffer " << i; + + shm_.header->buffer_offset[i] = samples_length + 1; + offset = cras_shm_get_checked_buffer_offset(&shm_, i); + EXPECT_EQ(samples_length, offset) + << "Expected invalid buffer offset for buffer " << i; + + shm_.header->buffer_offset[i] = samples_length + used_size; + offset = cras_shm_get_checked_buffer_offset(&shm_, i); + EXPECT_EQ(samples_length, offset) + << "Expected invalid buffer offset for buffer " << i; + } +} + +TEST_F(ShmTestSuite, GetCheckedReadOffset) { + uint32_t used_size = cras_shm_used_size(&shm_); + uint32_t samples_length = used_size * 8; + shm_.samples_info.length = samples_length; + + uint32_t offset; + + for (unsigned int i = 0; i < CRAS_NUM_SHM_BUFFERS; i++) { + shm_.header->read_offset[i] = 0; + offset = cras_shm_get_checked_read_offset(&shm_, i); + EXPECT_EQ(0, offset) << "Expected valid read offset for buffer " << i; + + shm_.header->read_offset[i] = used_size / 2; + offset = cras_shm_get_checked_read_offset(&shm_, i); + EXPECT_EQ(used_size / 2, offset) + << "Expected valid read offset for buffer " << i; + + shm_.header->read_offset[i] = used_size; + offset = cras_shm_get_checked_read_offset(&shm_, i); + EXPECT_EQ(used_size, offset) + << "Expected valid read offset for buffer " << i; + + // Read offsets should not be greater than used_size. + shm_.header->read_offset[i] = used_size + 1; + offset = cras_shm_get_checked_read_offset(&shm_, i); + EXPECT_EQ(0, offset) << "Expected invalid read offset for buffer " << i; + + shm_.header->buffer_offset[i] = samples_length - used_size / 2; + + shm_.header->read_offset[i] = 0; + offset = cras_shm_get_checked_read_offset(&shm_, i); + EXPECT_EQ(0, offset) << "Expected valid read offset for buffer " << i; + + shm_.header->read_offset[i] = used_size / 4; + offset = cras_shm_get_checked_read_offset(&shm_, i); + EXPECT_EQ(used_size / 4, offset) + << "Expected valid read offset for buffer " << i; + + shm_.header->read_offset[i] = used_size / 2; + offset = cras_shm_get_checked_read_offset(&shm_, i); + EXPECT_EQ(used_size / 2, offset) + << "Expected valid read offset for buffer " << i; + + shm_.header->read_offset[i] = used_size / 2 + 1; + offset = cras_shm_get_checked_read_offset(&shm_, i); + EXPECT_EQ(0, offset) << "Expected invalid read offset for buffer " << i; + + shm_.header->read_offset[i] = used_size; + offset = cras_shm_get_checked_read_offset(&shm_, i); + EXPECT_EQ(0, offset) << "Expected invalid read offset for buffer " << i; + + shm_.header->read_offset[i] = used_size + 1; + offset = cras_shm_get_checked_read_offset(&shm_, i); + EXPECT_EQ(0, offset) << "Expected invalid read offset for buffer " << i; + } +} + +TEST_F(ShmTestSuite, GetCheckedWriteOffset) { + uint32_t used_size = cras_shm_used_size(&shm_); + uint32_t samples_length = used_size * 8; + shm_.samples_info.length = samples_length; + + uint32_t offset; + + for (unsigned int i = 0; i < CRAS_NUM_SHM_BUFFERS; i++) { + shm_.header->write_offset[i] = 0; + offset = cras_shm_get_checked_write_offset(&shm_, i); + EXPECT_EQ(0, offset) << "Expected valid write offset for buffer " << i; + + shm_.header->write_offset[i] = used_size / 2; + offset = cras_shm_get_checked_write_offset(&shm_, i); + EXPECT_EQ(used_size / 2, offset) + << "Expected valid write offset for buffer " << i; + + shm_.header->write_offset[i] = used_size; + offset = cras_shm_get_checked_write_offset(&shm_, i); + EXPECT_EQ(used_size, offset) + << "Expected valid write offset for buffer " << i; + + // Write offsets should not be greater than used_size. + shm_.header->write_offset[i] = used_size + 1; + offset = cras_shm_get_checked_write_offset(&shm_, i); + EXPECT_EQ(used_size, offset) + << "Expected invalid write offset for buffer " << i; + + uint32_t buffer_offset = samples_length - used_size / 2; + shm_.header->buffer_offset[i] = buffer_offset; + + shm_.header->write_offset[i] = 0; + offset = cras_shm_get_checked_write_offset(&shm_, i); + EXPECT_EQ(0, offset) << "Expected valid write offset for buffer " << i; + + shm_.header->write_offset[i] = used_size / 4; + offset = cras_shm_get_checked_write_offset(&shm_, i); + EXPECT_EQ(used_size / 4, offset) + << "Expected valid write offset for buffer " << i; + + shm_.header->write_offset[i] = used_size / 2; + offset = cras_shm_get_checked_write_offset(&shm_, i); + EXPECT_EQ(used_size / 2, offset) + << "Expected valid write offset for buffer " << i; + + // Write offsets should not be longer than the samples area. + shm_.header->write_offset[i] = used_size / 2 + 1; + offset = cras_shm_get_checked_write_offset(&shm_, i); + EXPECT_EQ(samples_length - buffer_offset, offset) + << "Expected invalid write offset for buffer " << i; + + shm_.header->write_offset[i] = used_size; + offset = cras_shm_get_checked_write_offset(&shm_, i); + EXPECT_EQ(samples_length - buffer_offset, offset) + << "Expected invalid write offset for buffer " << i; + + shm_.header->write_offset[i] = used_size + 1; + offset = cras_shm_get_checked_write_offset(&shm_, i); + EXPECT_EQ(samples_length - buffer_offset, offset) + << "Expected invalid write offset for buffer " << i; + } +} + } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/softvol_curve_unittest.cc b/cras/src/tests/softvol_curve_unittest.cc index d2e5ea6e..d1444588 100644 --- a/cras/src/tests/softvol_curve_unittest.cc +++ b/cras/src/tests/softvol_curve_unittest.cc @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <stdio.h> #include <gtest/gtest.h> +#include <stdio.h> extern "C" { #include "softvol_curve.h" @@ -28,12 +28,9 @@ TEST(SoftvolCurveTest, ScalerDecibelConvert) { } // namespace /* Stubs */ -extern "C" { +extern "C" {} // extern "C" -} // extern "C" - -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } - diff --git a/cras/src/tests/stream_list_unittest.cc b/cras/src/tests/stream_list_unittest.cc index f2e8fbbf..8f3c2e3e 100644 --- a/cras/src/tests/stream_list_unittest.cc +++ b/cras/src/tests/stream_list_unittest.cc @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <stdio.h> #include <gtest/gtest.h> +#include <stdio.h> extern "C" { #include "cras_rstream.h" @@ -13,24 +13,24 @@ extern "C" { namespace { static unsigned int add_called; -static int added_cb(struct cras_rstream *rstream) { +static int added_cb(struct cras_rstream* rstream) { add_called++; return 0; } static unsigned int rm_called; -static struct cras_rstream *rmed_stream; -static int removed_cb(struct cras_rstream *rstream) { +static struct cras_rstream* rmed_stream; +static int removed_cb(struct cras_rstream* rstream) { rm_called++; rmed_stream = rstream; return 0; } static unsigned int create_called; -static struct cras_rstream_config *create_config; +static struct cras_rstream_config* create_config; static struct cras_rstream dummy_rstream; -static int create_rstream_cb(struct cras_rstream_config *stream_config, - struct cras_rstream **stream) { +static int create_rstream_cb(struct cras_rstream_config* stream_config, + struct cras_rstream** stream) { create_called++; create_config = stream_config; *stream = &dummy_rstream; @@ -39,8 +39,8 @@ static int create_rstream_cb(struct cras_rstream_config *stream_config, } static unsigned int destroy_called; -static struct cras_rstream *destroyed_stream; -static void destroy_rstream_cb(struct cras_rstream *rstream) { +static struct cras_rstream* destroyed_stream; +static void destroy_rstream_cb(struct cras_rstream* rstream) { destroy_called++; destroyed_stream = rstream; } @@ -53,8 +53,8 @@ static void reset_test_data() { } TEST(StreamList, AddRemove) { - struct stream_list *l; - struct cras_rstream *s1; + struct stream_list* l; + struct cras_rstream* s1; struct cras_rstream_config s1_config; reset_test_data(); @@ -74,22 +74,20 @@ TEST(StreamList, AddRemove) { extern "C" { -struct cras_timer *cras_tm_create_timer( - struct cras_tm *tm, - unsigned int ms, - void (*cb)(struct cras_timer *t, void *data), - void *cb_data) { - return reinterpret_cast<struct cras_timer *>(0x404); -} - -void cras_tm_cancel_timer(struct cras_tm *tm, struct cras_timer *t) { +struct cras_timer* cras_tm_create_timer(struct cras_tm* tm, + unsigned int ms, + void (*cb)(struct cras_timer* t, + void* data), + void* cb_data) { + return reinterpret_cast<struct cras_timer*>(0x404); } +void cras_tm_cancel_timer(struct cras_tm* tm, struct cras_timer* t) {} } -} // namespace +} // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/system_state_unittest.cc b/cras/src/tests/system_state_unittest.cc index d71d5f50..9e7ecc8b 100644 --- a/cras/src/tests/system_state_unittest.cc +++ b/cras/src/tests/system_state_unittest.cc @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <stdio.h> #include <gtest/gtest.h> +#include <stdio.h> extern "C" { #include "cras_alert.h" @@ -20,14 +20,14 @@ static size_t add_stub_called; static size_t rm_stub_called; static size_t add_task_stub_called; static size_t callback_stub_called; -static void *select_data_value; -static void *task_data_value; +static void* select_data_value; +static void* task_data_value; static size_t add_callback_called; static cras_alert_cb add_callback_cb; -static void *add_callback_arg; +static void* add_callback_arg; static size_t rm_callback_called; static cras_alert_cb rm_callback_cb; -static void *rm_callback_arg; +static void* rm_callback_arg; static size_t alert_pending_called; static char* device_config_dir; static const char* cras_alsa_card_config_dir; @@ -59,49 +59,44 @@ static void ResetStubData() { cras_observer_notify_num_active_streams_called = 0; } -static int add_stub(int fd, void (*cb)(void *data), - void *callback_data, void *select_data) { +static int add_stub(int fd, + void (*cb)(void* data), + void* callback_data, + void* select_data) { add_stub_called++; select_data_value = select_data; return 0; } -static void rm_stub(int fd, void *select_data) { +static void rm_stub(int fd, void* select_data) { rm_stub_called++; select_data_value = select_data; } -static int add_task_stub(void (*cb)(void *data), - void *callback_data, - void *task_data) -{ +static int add_task_stub(void (*cb)(void* data), + void* callback_data, + void* task_data) { add_task_stub_called++; task_data_value = task_data; return 0; } -static void callback_stub(void *data) { +static void callback_stub(void* data) { callback_stub_called++; } static void do_sys_init() { - char *shm_name; + char* shm_name; ASSERT_GT(asprintf(&shm_name, "/cras-%d", getpid()), 0); int rw_shm_fd; int ro_shm_fd; - struct cras_server_state *exp_state = (struct cras_server_state *) - cras_shm_setup(shm_name, - sizeof(*exp_state), - &rw_shm_fd, - &ro_shm_fd); + struct cras_server_state* exp_state = + (struct cras_server_state*)cras_shm_setup(shm_name, sizeof(*exp_state), + &rw_shm_fd, &ro_shm_fd); if (!exp_state) exit(-1); - cras_system_state_init(device_config_dir, - shm_name, - rw_shm_fd, - ro_shm_fd, - exp_state, - sizeof(*exp_state)); + cras_system_state_init(device_config_dir, shm_name, rw_shm_fd, ro_shm_fd, + exp_state, sizeof(*exp_state)); free(shm_name); } @@ -356,8 +351,8 @@ TEST(SystemStateSuite, AddCard) { } TEST(SystemSettingsRegisterSelectDescriptor, AddSelectFd) { - void *stub_data = reinterpret_cast<void *>(44); - void *select_data = reinterpret_cast<void *>(33); + void* stub_data = reinterpret_cast<void*>(44); + void* select_data = reinterpret_cast<void*>(33); int rc; ResetStubData(); @@ -386,8 +381,8 @@ TEST(SystemSettingsRegisterSelectDescriptor, AddSelectFd) { } TEST(SystemSettingsAddTask, AddTask) { - void *stub_data = reinterpret_cast<void *>(44); - void *task_data = reinterpret_cast<void *>(33); + void* stub_data = reinterpret_cast<void*>(44); + void* task_data = reinterpret_cast<void*>(33); int rc; do_sys_init(); @@ -430,29 +425,23 @@ TEST(SystemSettingsStreamCount, StreamCountByDirection) { cras_system_state_stream_added(CRAS_STREAM_OUTPUT); cras_system_state_stream_added(CRAS_STREAM_INPUT); cras_system_state_stream_added(CRAS_STREAM_POST_MIX_PRE_DSP); - EXPECT_EQ(1, - cras_system_state_get_active_streams_by_direction( - CRAS_STREAM_OUTPUT)); - EXPECT_EQ(1, - cras_system_state_get_active_streams_by_direction( - CRAS_STREAM_INPUT)); - EXPECT_EQ(1, - cras_system_state_get_active_streams_by_direction( - CRAS_STREAM_POST_MIX_PRE_DSP)); + EXPECT_EQ( + 1, cras_system_state_get_active_streams_by_direction(CRAS_STREAM_OUTPUT)); + EXPECT_EQ( + 1, cras_system_state_get_active_streams_by_direction(CRAS_STREAM_INPUT)); + EXPECT_EQ(1, cras_system_state_get_active_streams_by_direction( + CRAS_STREAM_POST_MIX_PRE_DSP)); EXPECT_EQ(3, cras_system_state_get_active_streams()); EXPECT_EQ(3, cras_observer_notify_num_active_streams_called); cras_system_state_stream_removed(CRAS_STREAM_OUTPUT); cras_system_state_stream_removed(CRAS_STREAM_INPUT); cras_system_state_stream_removed(CRAS_STREAM_POST_MIX_PRE_DSP); - EXPECT_EQ(0, - cras_system_state_get_active_streams_by_direction( - CRAS_STREAM_OUTPUT)); - EXPECT_EQ(0, - cras_system_state_get_active_streams_by_direction( - CRAS_STREAM_INPUT)); - EXPECT_EQ(0, - cras_system_state_get_active_streams_by_direction( - CRAS_STREAM_POST_MIX_PRE_DSP)); + EXPECT_EQ( + 0, cras_system_state_get_active_streams_by_direction(CRAS_STREAM_OUTPUT)); + EXPECT_EQ( + 0, cras_system_state_get_active_streams_by_direction(CRAS_STREAM_INPUT)); + EXPECT_EQ(0, cras_system_state_get_active_streams_by_direction( + CRAS_STREAM_POST_MIX_PRE_DSP)); EXPECT_EQ(0, cras_system_state_get_active_streams()); EXPECT_EQ(6, cras_observer_notify_num_active_streams_called); @@ -461,110 +450,98 @@ TEST(SystemSettingsStreamCount, StreamCountByDirection) { extern "C" { - -struct cras_alsa_card *cras_alsa_card_create(struct cras_alsa_card_info *info, - const char *device_config_dir, - struct cras_device_blacklist *blacklist) { +struct cras_alsa_card* cras_alsa_card_create( + struct cras_alsa_card_info* info, + const char* device_config_dir, + struct cras_device_blacklist* blacklist) { cras_alsa_card_create_called++; cras_alsa_card_config_dir = device_config_dir; return kFakeAlsaCard; } -void cras_alsa_card_destroy(struct cras_alsa_card *alsa_card) { +void cras_alsa_card_destroy(struct cras_alsa_card* alsa_card) { cras_alsa_card_destroy_called++; } -size_t cras_alsa_card_get_index(const struct cras_alsa_card *alsa_card) { +size_t cras_alsa_card_get_index(const struct cras_alsa_card* alsa_card) { return 0; } -struct cras_device_blacklist *cras_device_blacklist_create( - const char *config_path) -{ - return NULL; +struct cras_device_blacklist* cras_device_blacklist_create( + const char* config_path) { + return NULL; } -void cras_device_blacklist_destroy(struct cras_device_blacklist *blacklist) -{ -} +void cras_device_blacklist_destroy(struct cras_device_blacklist* blacklist) {} -struct cras_alert *cras_alert_create(cras_alert_prepare prepare, - unsigned int flags) -{ +struct cras_alert* cras_alert_create(cras_alert_prepare prepare, + unsigned int flags) { return NULL; } -void cras_alert_destroy(struct cras_alert *alert) -{ -} +void cras_alert_destroy(struct cras_alert* alert) {} -int cras_alert_add_callback(struct cras_alert *alert, cras_alert_cb cb, - void *arg) -{ +int cras_alert_add_callback(struct cras_alert* alert, + cras_alert_cb cb, + void* arg) { add_callback_called++; add_callback_cb = cb; add_callback_arg = arg; return 0; } -int cras_alert_rm_callback(struct cras_alert *alert, cras_alert_cb cb, - void *arg) -{ +int cras_alert_rm_callback(struct cras_alert* alert, + cras_alert_cb cb, + void* arg) { rm_callback_called++; rm_callback_cb = cb; rm_callback_arg = arg; return 0; } -void cras_alert_pending(struct cras_alert *alert) -{ +void cras_alert_pending(struct cras_alert* alert) { alert_pending_called++; } -cras_tm *cras_tm_init() { +cras_tm* cras_tm_init() { return static_cast<cras_tm*>(malloc(sizeof(unsigned int))); } -void cras_tm_deinit(cras_tm *tm) { +void cras_tm_deinit(cras_tm* tm) { free(tm); } -void cras_observer_notify_output_volume(int32_t volume) -{ +void cras_observer_notify_output_volume(int32_t volume) { cras_observer_notify_output_volume_called++; } -void cras_observer_notify_output_mute(int muted, int user_muted, - int mute_locked) -{ +void cras_observer_notify_output_mute(int muted, + int user_muted, + int mute_locked) { cras_observer_notify_output_mute_called++; } -void cras_observer_notify_capture_gain(int32_t gain) -{ +void cras_observer_notify_capture_gain(int32_t gain) { cras_observer_notify_capture_gain_called++; } -void cras_observer_notify_capture_mute(int muted, int mute_locked) -{ +void cras_observer_notify_capture_mute(int muted, int mute_locked) { cras_observer_notify_capture_mute_called++; } -void cras_observer_notify_suspend_changed(int suspended) -{ +void cras_observer_notify_suspend_changed(int suspended) { cras_observer_notify_suspend_changed_called++; } void cras_observer_notify_num_active_streams(enum CRAS_STREAM_DIRECTION dir, - uint32_t num_active_streams) -{ + uint32_t num_active_streams) { cras_observer_notify_num_active_streams_called++; } } // extern "C" } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/timing_unittest.cc b/cras/src/tests/timing_unittest.cc index ae9b548b..beba2f72 100644 --- a/cras/src/tests/timing_unittest.cc +++ b/cras/src/tests/timing_unittest.cc @@ -2,22 +2,21 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <memory> +#include <gtest/gtest.h> #include <stdint.h> #include <stdio.h> +#include <syslog.h> #include <time.h> -#include <gtest/gtest.h> - -#include <syslog.h> +#include <memory> extern "C" { -#include "dev_io.h" // tested -#include "dev_stream.h" // tested -#include "cras_rstream.h" // stubbed -#include "cras_iodev.h" // stubbed +#include "cras_iodev.h" // stubbed +#include "cras_rstream.h" // stubbed #include "cras_shm.h" #include "cras_types.h" +#include "dev_io.h" // tested +#include "dev_stream.h" // tested #include "utlist.h" struct audio_thread_event_log* atlog; @@ -32,7 +31,7 @@ struct audio_thread_event_log* atlog; namespace { -class TimingSuite : public testing::Test{ +class TimingSuite : public testing::Test { protected: virtual void SetUp() { atlog = static_cast<audio_thread_event_log*>(calloc(1, sizeof(*atlog))); @@ -40,9 +39,7 @@ class TimingSuite : public testing::Test{ rstream_stub_reset(); } - virtual void TearDown() { - free(atlog); - } + virtual void TearDown() { free(atlog); } timespec SingleInputDevNextWake( size_t dev_cb_threshold, @@ -68,7 +65,7 @@ class TimingSuite : public testing::Test{ dev_io_send_captured_samples(dev_list_); struct timespec dev_time; - dev_time.tv_sec = level_timestamp->tv_sec + 500; // Far in the future. + dev_time.tv_sec = level_timestamp->tv_sec + 500; // Far in the future. dev_io_next_input_wake(&dev_list_, &dev_time); return dev_time; } @@ -146,8 +143,9 @@ TEST_F(TimingSuite, NewInputStreamInit) { // for stream in dev: // wake_ts = MIN(get_input_wake_time(stream, cap_limit), wake_ts) // for stream on dev #rule_2 +// if cap_limit: +// wake_ts = MIN(get_input_dev_max_wake_ts(dev), wake_ts) #rule_3 // -// wake_ts = MIN(get_input_dev_max_wake_ts(dev), wake_ts) #rule_3 // device.wake_ts = wake_ts // // function get_input_wake_time(stream, cap_limit): @@ -256,6 +254,37 @@ TEST_F(TimingSuite, InputWakeTimeTwoEmptyStreams) { EXPECT_EQ(start.tv_nsec, dev_time.tv_nsec); } +// Test rule_3. +// If cap_limit is zero from stream, input_dev_max_wake_ts should not +// be taken into account. +TEST_F(TimingSuite, InputWakeTimeOneFullStreamWithDeviceWakeUp) { + cras_audio_format format; + fill_audio_format(&format, 48000); + + StreamPtr stream = create_stream(1, 1, CRAS_STREAM_INPUT, 480, &format); + + struct timespec start, stream_wake; + clock_gettime(CLOCK_MONOTONIC_RAW, &start); + + // Set the next stream wake to be 10ms from now. + const timespec ten_millis = {0, 10 * 1000 * 1000}; + stream_wake = start; + add_timespecs(&stream_wake, &ten_millis); + stream->rstream->next_cb_ts = stream_wake; + + // Add fake data so the stream has no room for more data. + AddFakeDataToStream(stream.get(), 480); + + std::vector<StreamPtr> streams; + streams.emplace_back(std::move(stream)); + timespec wake_time = SingleInputDevNextWake(240, 0, &start, &format, streams); + + // Input device would wake at 5ms from now, but since stream cap_limit == 0 + // the final wake_time is determined by stream. + EXPECT_EQ(stream_wake.tv_sec, wake_time.tv_sec); + EXPECT_EQ(stream_wake.tv_nsec, wake_time.tv_nsec); +} + // Test rule_3 and rule_9. // One empty stream with small device buffer. It should wake up when there are // buffer_size / 2 frames in device buffer. @@ -334,7 +363,7 @@ TEST_F(TimingSuite, InputWakeTimeOneStreamWithEmptyDevice) { // The device wake up time should be 10ms from now. At that time the // stream will have 480 samples to post. - const timespec ten_millis = { 0, 10 * 1000 * 1000 }; + const timespec ten_millis = {0, 10 * 1000 * 1000}; add_timespecs(&start, &ten_millis); EXPECT_EQ(0, streams[0]->rstream->next_cb_ts.tv_sec); EXPECT_EQ(0, streams[0]->rstream->next_cb_ts.tv_nsec); @@ -462,8 +491,8 @@ TEST_F(TimingSuite, WaitAfterFill) { std::vector<StreamPtr> streams; streams.emplace_back(std::move(stream)); - timespec dev_time = SingleInputDevNextWake(cb_threshold, 0, &start, - &format, streams); + timespec dev_time = + SingleInputDevNextWake(cb_threshold, 0, &start, &format, streams); // The next callback should be scheduled 10ms in the future. // And the next wake up should reflect the only attached stream. @@ -494,8 +523,8 @@ TEST_F(TimingSuite, LargeCallbackStreamWithEmptyBuffer) { std::vector<StreamPtr> streams; streams.emplace_back(std::move(stream)); - timespec dev_time = SingleInputDevNextWake( - dev_cb_threshold, dev_level, &start, &format, streams); + timespec dev_time = SingleInputDevNextWake(dev_cb_threshold, dev_level, + &start, &format, streams); struct timespec delta; subtract_timespecs(&dev_time, &start, &delta); @@ -525,8 +554,8 @@ TEST_F(TimingSuite, LargeCallbackStreamWithHalfFullBuffer) { std::vector<StreamPtr> streams; streams.emplace_back(std::move(stream)); - timespec dev_time = SingleInputDevNextWake( - dev_cb_threshold, dev_level, &start, &format, streams); + timespec dev_time = SingleInputDevNextWake(dev_cb_threshold, dev_level, + &start, &format, streams); struct timespec delta; subtract_timespecs(&dev_time, &start, &delta); @@ -554,8 +583,8 @@ TEST_F(TimingSuite, WaitAfterFillSRC) { std::vector<StreamPtr> streams; streams.emplace_back(std::move(stream)); - timespec dev_time = SingleInputDevNextWake(480, 0, &start, - &dev_format, streams); + timespec dev_time = + SingleInputDevNextWake(480, 0, &start, &dev_format, streams); // The next callback should be scheduled 10ms in the future. struct timespec delta; @@ -582,7 +611,7 @@ TEST_F(TimingSuite, WaitTwoStreamsSameFormat) { AddFakeDataToStream(stream1.get(), cb_threshold); // stream2 is only half full. - StreamPtr stream2 = + StreamPtr stream2 = create_stream(1, 1, CRAS_STREAM_INPUT, cb_threshold, &format); stream2->rstream->next_cb_ts = start; AddFakeDataToStream(stream2.get(), 240); @@ -590,8 +619,8 @@ TEST_F(TimingSuite, WaitTwoStreamsSameFormat) { std::vector<StreamPtr> streams; streams.emplace_back(std::move(stream1)); streams.emplace_back(std::move(stream2)); - timespec dev_time = SingleInputDevNextWake(cb_threshold, 0, &start, - &format, streams); + timespec dev_time = + SingleInputDevNextWake(cb_threshold, 0, &start, &format, streams); // Should wait for approximately 5 milliseconds for 240 samples at 48k. struct timespec delta2; @@ -610,23 +639,21 @@ TEST_F(TimingSuite, WaitTwoStreamsDifferentRates) { fill_audio_format(&s2_format, 48000); // stream1's next callback is now and there is enough data to fill. - StreamPtr stream1 = - create_stream(1, 1, CRAS_STREAM_INPUT, 441, &s1_format); + StreamPtr stream1 = create_stream(1, 1, CRAS_STREAM_INPUT, 441, &s1_format); struct timespec start; clock_gettime(CLOCK_MONOTONIC_RAW, &start); stream1->rstream->next_cb_ts = start; AddFakeDataToStream(stream1.get(), 441); // stream2's next callback is now but there is only half a callback of data. - StreamPtr stream2 = - create_stream(1, 1, CRAS_STREAM_INPUT, 480, &s2_format); + StreamPtr stream2 = create_stream(1, 1, CRAS_STREAM_INPUT, 480, &s2_format); stream2->rstream->next_cb_ts = start; AddFakeDataToStream(stream2.get(), 240); std::vector<StreamPtr> streams; streams.emplace_back(std::move(stream1)); streams.emplace_back(std::move(stream2)); - timespec dev_time = SingleInputDevNextWake(441, 0, &start, - &s1_format, streams); + timespec dev_time = + SingleInputDevNextWake(441, 0, &start, &s1_format, streams); // Should wait for approximately 5 milliseconds for 240 48k samples from the // 44.1k device. @@ -648,25 +675,23 @@ TEST_F(TimingSuite, WaitTwoStreamsDifferentWakeupTimes) { clock_gettime(CLOCK_MONOTONIC_RAW, &start); // stream1's next callback is in 3ms. - StreamPtr stream1 = - create_stream(1, 1, CRAS_STREAM_INPUT, 441, &s1_format); + StreamPtr stream1 = create_stream(1, 1, CRAS_STREAM_INPUT, 441, &s1_format); stream1->rstream->next_cb_ts = start; - const timespec three_millis = { 0, 3 * 1000 * 1000 }; + const timespec three_millis = {0, 3 * 1000 * 1000}; add_timespecs(&stream1->rstream->next_cb_ts, &three_millis); AddFakeDataToStream(stream1.get(), 441); // stream2 is also ready next cb in 5ms.. - StreamPtr stream2 = - create_stream(1, 1, CRAS_STREAM_INPUT, 480, &s2_format); + StreamPtr stream2 = create_stream(1, 1, CRAS_STREAM_INPUT, 480, &s2_format); stream2->rstream->next_cb_ts = start; - const timespec five_millis = { 0, 5 * 1000 * 1000 }; + const timespec five_millis = {0, 5 * 1000 * 1000}; add_timespecs(&stream2->rstream->next_cb_ts, &five_millis); AddFakeDataToStream(stream1.get(), 480); std::vector<StreamPtr> streams; streams.emplace_back(std::move(stream1)); streams.emplace_back(std::move(stream2)); - timespec dev_time = SingleInputDevNextWake(441, 441, &start, - &s1_format, streams); + timespec dev_time = + SingleInputDevNextWake(441, 441, &start, &s1_format, streams); // Should wait for approximately 3 milliseconds for stream 1 first. struct timespec delta2; @@ -685,8 +710,7 @@ TEST_F(TimingSuite, HotwordStreamUseDevTiming) { struct timespec start, delay; clock_gettime(CLOCK_MONOTONIC_RAW, &start); - StreamPtr stream = - create_stream(1, 1, CRAS_STREAM_INPUT, 240, &fmt); + StreamPtr stream = create_stream(1, 1, CRAS_STREAM_INPUT, 240, &fmt); stream->rstream->flags = HOTWORD_STREAM; stream->rstream->next_cb_ts = start; delay.tv_sec = 0; @@ -699,8 +723,7 @@ TEST_F(TimingSuite, HotwordStreamUseDevTiming) { AddFakeDataToStream(stream.get(), 192); std::vector<StreamPtr> streams; streams.emplace_back(std::move(stream)); - timespec dev_time = SingleInputDevNextWake(4096, 0, &start, - &fmt, streams); + timespec dev_time = SingleInputDevNextWake(4096, 0, &start, &fmt, streams); struct timespec delta; subtract_timespecs(&dev_time, &start, &delta); // 288 frames worth of time = 6 ms. @@ -719,8 +742,7 @@ TEST_F(TimingSuite, HotwordStreamBulkDataIsPending) { struct timespec start; clock_gettime(CLOCK_MONOTONIC_RAW, &start); - StreamPtr stream = - create_stream(1, 1, CRAS_STREAM_INPUT, 240, &fmt); + StreamPtr stream = create_stream(1, 1, CRAS_STREAM_INPUT, 240, &fmt); stream->rstream->flags = HOTWORD_STREAM; stream->rstream->next_cb_ts = start; @@ -731,8 +753,8 @@ TEST_F(TimingSuite, HotwordStreamBulkDataIsPending) { rstream_stub_pending_reply(streams[0]->rstream.get(), 1); // There is more than 1 cb_threshold of data in device. - timespec dev_time = SingleInputDevNextWake( - 4096, 7000, &start, &fmt, streams, CRAS_NODE_TYPE_HOTWORD); + timespec dev_time = SingleInputDevNextWake(4096, 7000, &start, &fmt, streams, + CRAS_NODE_TYPE_HOTWORD); // Need to wait for stream fd in the next ppoll. poll_fd = dev_stream_poll_stream_fd(streams[0]->dstream.get()); @@ -759,8 +781,7 @@ TEST_F(TimingSuite, HotwordStreamBulkDataIsNotPending) { struct timespec start; clock_gettime(CLOCK_MONOTONIC_RAW, &start); - StreamPtr stream = - create_stream(1, 1, CRAS_STREAM_INPUT, 240, &fmt); + StreamPtr stream = create_stream(1, 1, CRAS_STREAM_INPUT, 240, &fmt); stream->rstream->flags = HOTWORD_STREAM; stream->rstream->next_cb_ts = start; @@ -771,8 +792,7 @@ TEST_F(TimingSuite, HotwordStreamBulkDataIsNotPending) { rstream_stub_pending_reply(streams[0]->rstream.get(), 0); // There is more than 1 cb_threshold of data in device. - timespec dev_time = SingleInputDevNextWake(4096, 7000, &start, - &fmt, streams); + timespec dev_time = SingleInputDevNextWake(4096, 7000, &start, &fmt, streams); // Does not need to wait for stream fd in the next ppoll. poll_fd = dev_stream_poll_stream_fd(streams[0]->dstream.get()); @@ -1128,28 +1148,31 @@ TEST_F(TimingSuite, OutputStreamsUpdateAfterFetching) { /* Stubs */ extern "C" { -int input_data_get_for_stream( - struct input_data *data, - struct cras_rstream *stream, - struct buffer_share *offsets, - struct cras_audio_area **area, - unsigned int *offset) -{ +int input_data_get_for_stream(struct input_data* data, + struct cras_rstream* stream, + struct buffer_share* offsets, + struct cras_audio_area** area, + unsigned int* offset) { return 0; } -int input_data_put_for_stream(struct input_data *data, - struct cras_rstream *stream, - struct buffer_share *offsets, - unsigned int frames) -{ +int input_data_put_for_stream(struct input_data* data, + struct cras_rstream* stream, + struct buffer_share* offsets, + unsigned int frames) { return 0; } -struct cras_audio_format *cras_rstream_post_processing_format( - const struct cras_rstream *stream, void *dev_ptr) -{ + +struct cras_audio_format* cras_rstream_post_processing_format( + const struct cras_rstream* stream, + void* dev_ptr) { return NULL; } + +int cras_audio_thread_event_drop_samples() { + return 0; +} + } // extern "C" } // namespace diff --git a/cras/src/tests/utf8_unittest.cc b/cras/src/tests/utf8_unittest.cc index 34360c36..4a13fcfa 100644 --- a/cras/src/tests/utf8_unittest.cc +++ b/cras/src/tests/utf8_unittest.cc @@ -19,7 +19,8 @@ TEST(UTF8, ValidStress) { EXPECT_EQ(1, valid_utf8_string("The greek word 'kosme': " "\xce\xba\xe1\xbd\xb9\xcf\x83\xce" - "\xbc\xce\xb5", &pos)); + "\xbc\xce\xb5", + &pos)); EXPECT_EQ(35, pos); EXPECT_EQ(1, valid_utf8_string("Playback", &pos)); @@ -115,18 +116,22 @@ TEST(UTF8, InvalidStress) { /* Overlong representations of ASCII characters. */ EXPECT_EQ(0, valid_utf8_string("This represents the / character with too" - "many bytes: \xe0\x80\xaf", &pos)); + "many bytes: \xe0\x80\xaf", + &pos)); EXPECT_EQ(53, pos); EXPECT_EQ(0, valid_utf8_string("This represents the / character with too" - "many bytes: \xf0\x80\x80\xaf", &pos)); + "many bytes: \xf0\x80\x80\xaf", + &pos)); EXPECT_EQ(53, pos); /* Should not be interpreted as the ASCII NUL character. */ EXPECT_EQ(0, valid_utf8_string("This represents the NUL character with too" - "many bytes: \xe0\x80\x80", &pos)); + "many bytes: \xe0\x80\x80", + &pos)); EXPECT_EQ(55, pos); EXPECT_EQ(0, valid_utf8_string("This represents the NUL character with too" - "many bytes: \xf0\x80\x80\x80", &pos)); + "many bytes: \xf0\x80\x80\x80", + &pos)); EXPECT_EQ(55, pos); /* Single UTF-16 surrogates. */ @@ -148,7 +153,7 @@ TEST(UTF8, InvalidStress) { } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/util_unittest.cc b/cras/src/tests/util_unittest.cc index 43245d35..e61336ad 100644 --- a/cras/src/tests/util_unittest.cc +++ b/cras/src/tests/util_unittest.cc @@ -3,10 +3,11 @@ // found in the LICENSE file. #include <gtest/gtest.h> -#include <string> -#include <sys/types.h> #include <sys/socket.h> +#include <sys/types.h> #include <unistd.h> + +#include <string> #include <vector> #include "cras_util.h" @@ -208,7 +209,6 @@ TEST(Util, TimeToFrames) { } TEST(Util, FramesToMs) { - EXPECT_EQ(500, cras_frames_to_ms(24000, 48000)); EXPECT_EQ(0, cras_frames_to_ms(1, 48000)); EXPECT_EQ(10, cras_frames_to_ms(480, 48000)); @@ -310,13 +310,12 @@ TEST(Util, CrasPoll) { /* Stubs */ extern "C" { -int clock_gettime(clockid_t clk_id, struct timespec *tp) { +int clock_gettime(clockid_t clk_id, struct timespec* tp) { std::vector<struct timespec>::iterator i = time_now.begin(); if (i != time_now.end()) { *tp = *i; time_now.erase(i); - } - else + } else memset(tp, 0, sizeof(*tp)); return 0; } @@ -325,7 +324,7 @@ int clock_gettime(clockid_t clk_id, struct timespec *tp) { } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/volume_curve_unittest.cc b/cras/src/tests/volume_curve_unittest.cc index 2f8c300a..267452aa 100644 --- a/cras/src/tests/volume_curve_unittest.cc +++ b/cras/src/tests/volume_curve_unittest.cc @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <stdio.h> #include <gtest/gtest.h> +#include <stdio.h> extern "C" { #include "cras_volume_curve.h" @@ -12,9 +12,9 @@ extern "C" { namespace { TEST(VolumeCurve, DefaultCurve) { - struct cras_volume_curve *curve; + struct cras_volume_curve* curve; curve = cras_volume_curve_create_default(); - ASSERT_NE(static_cast<struct cras_volume_curve *>(NULL), curve); + ASSERT_NE(static_cast<struct cras_volume_curve*>(NULL), curve); EXPECT_EQ(0 - 50 * 50, curve->get_dBFS(curve, 50)); EXPECT_EQ(0, curve->get_dBFS(curve, 100)); EXPECT_EQ(0 - 100 * 50, curve->get_dBFS(curve, 0)); @@ -23,9 +23,9 @@ TEST(VolumeCurve, DefaultCurve) { } TEST(VolumeCurve, SteppedCurve) { - struct cras_volume_curve *curve; + struct cras_volume_curve* curve; curve = cras_volume_curve_create_simple_step(-600, 75); - ASSERT_NE(static_cast<struct cras_volume_curve *>(NULL), curve); + ASSERT_NE(static_cast<struct cras_volume_curve*>(NULL), curve); EXPECT_EQ(-600 - 50 * 75, curve->get_dBFS(curve, 50)); EXPECT_EQ(-600, curve->get_dBFS(curve, 100)); EXPECT_EQ(-600 - 100 * 75, curve->get_dBFS(curve, 0)); @@ -34,21 +34,21 @@ TEST(VolumeCurve, SteppedCurve) { } TEST(VolumeCurve, ExplicitCurve) { - struct cras_volume_curve *curve; + struct cras_volume_curve* curve; long dB_vals[101]; for (unsigned int i = 0; i < 101; i++) - dB_vals[i] = i * 2 + -400; + dB_vals[i] = i * 2 + -400; curve = cras_volume_curve_create_explicit(dB_vals); - ASSERT_NE(static_cast<struct cras_volume_curve *>(NULL), curve); + ASSERT_NE(static_cast<struct cras_volume_curve*>(NULL), curve); for (unsigned int i = 0; i < 101; i++) - EXPECT_EQ(i * 2 - 400, curve->get_dBFS(curve, i)); + EXPECT_EQ(i * 2 - 400, curve->get_dBFS(curve, i)); cras_volume_curve_destroy(curve); } } // namespace -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/cras/src/tests/cras_monitor.c b/cras/src/tools/cras_monitor/cras_monitor.c index f09b9f88..d021669a 100644 --- a/cras/src/tests/cras_monitor.c +++ b/cras/src/tools/cras_monitor/cras_monitor.c @@ -24,8 +24,8 @@ static void output_volume_changed(void *context, int32_t volume) printf("output volume: %d/100\n", volume); } -static void output_mute_changed(void *context, int muted, - int user_muted, int mute_locked) +static void output_mute_changed(void *context, int muted, int user_muted, + int mute_locked) { printf("output mute: muted: %d, user_muted: %d, mute_locked: %d\n", muted, user_muted, mute_locked); @@ -38,8 +38,8 @@ static void capture_gain_changed(void *context, int32_t gain) static void capture_mute_changed(void *context, int muted, int mute_locked) { - printf("capture mute: muted: %d, mute_locked: %d\n", - muted, mute_locked); + printf("capture mute: muted: %d, mute_locked: %d\n", muted, + mute_locked); } static void nodes_changed(void *context) @@ -49,23 +49,22 @@ static void nodes_changed(void *context) static const char *string_for_direction(enum CRAS_STREAM_DIRECTION dir) { - switch(dir) { - case CRAS_STREAM_OUTPUT: - return "output"; - case CRAS_STREAM_INPUT: - return "input"; - case CRAS_STREAM_POST_MIX_PRE_DSP: - return "post_mix_pre_dsp"; - default: - break; + switch (dir) { + case CRAS_STREAM_OUTPUT: + return "output"; + case CRAS_STREAM_INPUT: + return "input"; + case CRAS_STREAM_POST_MIX_PRE_DSP: + return "post_mix_pre_dsp"; + default: + break; } return "undefined"; } size_t node_array_index_of_node_id(struct cras_ionode_info *nodes, - size_t num_nodes, - cras_node_id_t node_id) + size_t num_nodes, cras_node_id_t node_id) { uint32_t dev_index = dev_index_of(node_id); uint32_t node_index = node_index_of(node_id); @@ -102,10 +101,10 @@ const char *node_name_for_node_id(struct cras_client *client, return strdup(buf); } else if (dir == CRAS_STREAM_OUTPUT) { rc = cras_client_get_output_devices(client, devs, nodes, - &num_devs, &num_nodes); + &num_devs, &num_nodes); } else if (dir == CRAS_STREAM_INPUT) { rc = cras_client_get_input_devices(client, devs, nodes, - &num_devs, &num_nodes); + &num_devs, &num_nodes); } else { return strdup("unknown"); } @@ -113,24 +112,22 @@ const char *node_name_for_node_id(struct cras_client *client, if (rc != 0) { syslog(LOG_ERR, "Couldn't get output devices: %s\n", strerror(-rc)); - snprintf(buf, sizeof(buf), "%u:%u", - iodev_idx, node_index_of(node_id)); + snprintf(buf, sizeof(buf), "%u:%u", iodev_idx, + node_index_of(node_id)); return strdup(buf); } node_index = node_array_index_of_node_id(nodes, num_nodes, node_id); if (node_index >= num_nodes) - snprintf(buf, sizeof(buf), - "unknown: %zu >= %zu", node_index, num_nodes); + snprintf(buf, sizeof(buf), "unknown: %zu >= %zu", node_index, + num_nodes); else snprintf(buf, sizeof(buf), "%u:%u: %s", nodes[node_index].iodev_idx, - nodes[node_index].ionode_idx, - nodes[node_index].name); + nodes[node_index].ionode_idx, nodes[node_index].name); return strdup(buf); } -static void active_node_changed(void *context, - enum CRAS_STREAM_DIRECTION dir, +static void active_node_changed(void *context, enum CRAS_STREAM_DIRECTION dir, cras_node_id_t node_id) { struct cras_client *client = (struct cras_client *)context; @@ -139,8 +136,8 @@ static void active_node_changed(void *context, free((void *)node_name); } -static void output_node_volume_changed(void *context, - cras_node_id_t node_id, int32_t volume) +static void output_node_volume_changed(void *context, cras_node_id_t node_id, + int32_t volume) { struct cras_client *client = (struct cras_client *)context; const char *node_name = @@ -159,8 +156,8 @@ static void node_left_right_swapped_changed(void *context, free((void *)node_name); } -static void input_node_gain_changed(void *context, - cras_node_id_t node_id, int32_t gain) +static void input_node_gain_changed(void *context, cras_node_id_t node_id, + int32_t gain) { struct cras_client *client = (struct cras_client *)context; const char *node_name = @@ -173,8 +170,8 @@ static void num_active_streams_changed(void *context, enum CRAS_STREAM_DIRECTION dir, uint32_t num_active_streams) { - printf("num active %s streams: %u\n", - string_for_direction(dir), num_active_streams); + printf("num active %s streams: %u\n", string_for_direction(dir), + num_active_streams); } static void server_connection_callback(struct cras_client *client, @@ -183,26 +180,27 @@ static void server_connection_callback(struct cras_client *client, { const char *status_str = "undefined"; switch (status) { - case CRAS_CONN_STATUS_FAILED: - status_str = "error"; - break; - case CRAS_CONN_STATUS_DISCONNECTED: - status_str = "disconnected"; - break; - case CRAS_CONN_STATUS_CONNECTED: - status_str = "connected"; - break; + case CRAS_CONN_STATUS_FAILED: + status_str = "error"; + break; + case CRAS_CONN_STATUS_DISCONNECTED: + status_str = "disconnected"; + break; + case CRAS_CONN_STATUS_CONNECTED: + status_str = "connected"; + break; } printf("server %s\n", status_str); } -static void print_usage(const char *command) { +static void print_usage(const char *command) +{ fprintf(stderr, "%s [options]\n" " Where [options] are:\n" " --sync|-s - Use the synchronous connection functions.\n" " --log-level|-l <n> - Set the syslog level (7 == " - "LOG_DEBUG).\n", + "LOG_DEBUG).\n", command); } @@ -214,16 +212,16 @@ int main(int argc, char **argv) bool synchronous = false; int log_level = LOG_WARNING; static struct option long_options[] = { - {"sync", no_argument, NULL, 's'}, - {"log-level", required_argument, NULL, 'l'}, - {NULL, 0, NULL, 0}, + { "sync", no_argument, NULL, 's' }, + { "log-level", required_argument, NULL, 'l' }, + { NULL, 0, NULL, 0 }, }; - while(true) { + while (true) { int option_index = 0; - option_character = getopt_long(argc, argv, "sl:", - long_options, &option_index); + option_character = getopt_long(argc, argv, "sl:", long_options, + &option_index); if (option_character == -1) break; switch (option_character) { @@ -258,8 +256,8 @@ int main(int argc, char **argv) return rc; } - cras_client_set_connection_status_cb( - client, server_connection_callback, NULL); + cras_client_set_connection_status_cb(client, server_connection_callback, + NULL); if (synchronous) { rc = cras_client_connect(client); @@ -269,26 +267,25 @@ int main(int argc, char **argv) } } - cras_client_set_output_volume_changed_callback( - client, output_volume_changed); - cras_client_set_output_mute_changed_callback( - client, output_mute_changed); - cras_client_set_capture_gain_changed_callback( - client, capture_gain_changed); - cras_client_set_capture_mute_changed_callback( - client, capture_mute_changed); - cras_client_set_nodes_changed_callback( - client, nodes_changed); - cras_client_set_active_node_changed_callback( - client, active_node_changed); + cras_client_set_output_volume_changed_callback(client, + output_volume_changed); + cras_client_set_output_mute_changed_callback(client, + output_mute_changed); + cras_client_set_capture_gain_changed_callback(client, + capture_gain_changed); + cras_client_set_capture_mute_changed_callback(client, + capture_mute_changed); + cras_client_set_nodes_changed_callback(client, nodes_changed); + cras_client_set_active_node_changed_callback(client, + active_node_changed); cras_client_set_output_node_volume_changed_callback( - client, output_node_volume_changed); + client, output_node_volume_changed); cras_client_set_node_left_right_swapped_changed_callback( - client, node_left_right_swapped_changed); + client, node_left_right_swapped_changed); cras_client_set_input_node_gain_changed_callback( - client, input_node_gain_changed); + client, input_node_gain_changed); cras_client_set_num_active_streams_changed_callback( - client, num_active_streams_changed); + client, num_active_streams_changed); cras_client_set_state_change_callback_context(client, client); rc = cras_client_run_thread(client); @@ -305,7 +302,7 @@ int main(int argc, char **argv) } } - while(1) { + while (1) { int rc; char c; rc = read(STDIN_FILENO, &c, 1); diff --git a/cras/src/tests/cras_router.c b/cras/src/tools/cras_router/cras_router.c index d813bc64..b65b0525 100644 --- a/cras/src/tests/cras_router.c +++ b/cras/src/tools/cras_router/cras_router.c @@ -42,14 +42,11 @@ static size_t get_block_size(uint64_t buffer_time_in_ns, size_t rate) } /* Run from callback thread. */ -static int got_samples(struct cras_client *client, - cras_stream_id_t stream_id, - uint8_t *captured_samples, - uint8_t *playback_samples, +static int got_samples(struct cras_client *client, cras_stream_id_t stream_id, + uint8_t *captured_samples, uint8_t *playback_samples, unsigned int frames, const struct timespec *captured_time, - const struct timespec *playback_time, - void *user_arg) + const struct timespec *playback_time, void *user_arg) { int *fd = (int *)user_arg; int ret; @@ -65,14 +62,11 @@ static int got_samples(struct cras_client *client, } /* Run from callback thread. */ -static int put_samples(struct cras_client *client, - cras_stream_id_t stream_id, - uint8_t *captured_samples, - uint8_t *playback_samples, +static int put_samples(struct cras_client *client, cras_stream_id_t stream_id, + uint8_t *captured_samples, uint8_t *playback_samples, unsigned int frames, const struct timespec *captured_time, - const struct timespec *playback_time, - void *user_arg) + const struct timespec *playback_time, void *user_arg) { uint32_t frame_bytes = cras_client_format_bytes_per_frame(aud_format); int fd = *(int *)user_arg; @@ -89,20 +83,16 @@ static int put_samples(struct cras_client *client, return nread / frame_bytes; } -static int stream_error(struct cras_client *client, - cras_stream_id_t stream_id, - int err, - void *arg) +static int stream_error(struct cras_client *client, cras_stream_id_t stream_id, + int err, void *arg) { printf("Stream error %d\n", err); terminate_stream_loop(); return 0; } -static int start_stream(struct cras_client *client, - cras_stream_id_t *stream_id, - struct cras_stream_params *params, - float stream_volume) +static int start_stream(struct cras_client *client, cras_stream_id_t *stream_id, + struct cras_stream_params *params, float stream_volume) { int rc; @@ -111,17 +101,12 @@ static int start_stream(struct cras_client *client, fprintf(stderr, "adding a stream %d\n", rc); return rc; } - return cras_client_set_stream_volume(client, - *stream_id, - stream_volume); + return cras_client_set_stream_volume(client, *stream_id, stream_volume); } -static int run_file_io_stream(struct cras_client *client, - int fd, - int loop_fd, +static int run_file_io_stream(struct cras_client *client, int fd, int loop_fd, enum CRAS_STREAM_DIRECTION direction, - size_t block_size, - size_t rate, + size_t block_size, size_t rate, size_t num_channels) { struct cras_stream_params *params; @@ -140,14 +125,9 @@ static int run_file_io_stream(struct cras_client *client, if (aud_format == NULL) return -ENOMEM; - params = cras_client_unified_params_create(direction, - block_size, - 0, - 0, - pfd, - got_samples, - stream_error, - aud_format); + params = cras_client_unified_params_create(direction, block_size, 0, 0, + pfd, got_samples, + stream_error, aud_format); if (params == NULL) return -ENOMEM; @@ -164,17 +144,12 @@ static int run_file_io_stream(struct cras_client *client, direction = CRAS_STREAM_OUTPUT; - loop_params = cras_client_unified_params_create(direction, - block_size, - 0, - 0, - pfd1, - put_samples, - stream_error, - aud_format); - stream_playing = - start_stream(client, &loop_stream_id, - loop_params, volume_scaler) == 0; + loop_params = + cras_client_unified_params_create(direction, block_size, 0, 0, + pfd1, put_samples, + stream_error, aud_format); + stream_playing = start_stream(client, &loop_stream_id, loop_params, + volume_scaler) == 0; if (!stream_playing) return -EINVAL; @@ -194,11 +169,9 @@ static int run_file_io_stream(struct cras_client *client, return 0; } -static struct option long_options[] = { - {"help", no_argument, 0, 'h'}, - {"rate", required_argument, 0, 'r'}, - {0, 0, 0, 0} -}; +static struct option long_options[] = { { "help", no_argument, 0, 'h' }, + { "rate", required_argument, 0, 'r' }, + { 0, 0, 0, 0 } }; static void show_usage(void) { @@ -234,8 +207,7 @@ int main(int argc, char **argv) } while (1) { - c = getopt_long(argc, argv, "hr:", - long_options, &option_index); + c = getopt_long(argc, argv, "hr:", long_options, &option_index); if (c == -1) break; switch (c) { @@ -246,7 +218,7 @@ int main(int argc, char **argv) rate = atoi(optarg); break; default: - break; + break; } } diff --git a/cras/src/tests/cras_test_client.c b/cras/src/tools/cras_test_client/cras_test_client.c index 610fc729..a7845069 100644 --- a/cras/src/tests/cras_test_client.c +++ b/cras/src/tools/cras_test_client/cras_test_client.c @@ -7,6 +7,7 @@ #include <fcntl.h> #include <getopt.h> #include <inttypes.h> +#include <limits.h> #include <math.h> #include <pthread.h> #include <stdio.h> @@ -14,6 +15,7 @@ #include <stdlib.h> #include <string.h> #include <syslog.h> +#include <sys/mman.h> #include <sys/param.h> #include <sys/select.h> #include <sys/stat.h> @@ -64,6 +66,11 @@ static int effect_vad = 0; static char *aecdump_file = NULL; static char time_str[128]; +/* Sleep interval between cras_client_read_atlog calls. */ +static const struct timespec follow_atlog_sleep_ts = { + 0, 50 * 1000 * 1000 /* 50 ms. */ +}; + /* Conditional so the client thread can signal that main should exit. */ static pthread_mutex_t done_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t done_cond = PTHREAD_COND_INITIALIZER; @@ -100,6 +107,16 @@ static void check_stream_terminate(size_t frames) } } +static void fill_time_offset(time_t *sec_offset, int32_t *nsec_offset) +{ + struct timespec mono_time, real_time; + + clock_gettime(CLOCK_MONOTONIC_RAW, &mono_time); + clock_gettime(CLOCK_REALTIME, &real_time); + *sec_offset = real_time.tv_sec - mono_time.tv_sec; + *nsec_offset = real_time.tv_nsec - mono_time.tv_nsec; +} + /* Compute square sum of samples (for calculation of RMS value). */ float compute_sqr_sum_16(const int16_t *samples, int size) { @@ -117,7 +134,8 @@ int update_rms(const uint8_t *samples, int size) { switch (aud_format->format) { case SND_PCM_FORMAT_S16_LE: { - last_rms_sqr_sum = compute_sqr_sum_16((int16_t *)samples, size / 2); + last_rms_sqr_sum = + compute_sqr_sum_16((int16_t *)samples, size / 2); last_rms_size = size / 2; break; } @@ -131,15 +149,82 @@ int update_rms(const uint8_t *samples, int size) return 0; } +/* Parses a string with format <N>:<M> into a node id*/ +static int parse_node_id(char *input, cras_node_id_t *id_out) +{ + const char *s; + char *endptr; + int dev_index; + int node_index; + + if (!id_out) + return -EINVAL; + + s = strtok(input, ":"); + if (!s) + return -EINVAL; + dev_index = strtol(s, &endptr, 10); + if (*endptr) + return -EINVAL; + + s = strtok(NULL, ":"); + if (!s) + return -EINVAL; + node_index = strtol(s, &endptr, 10); + if (*endptr) + return -EINVAL; + + *id_out = cras_make_node_id(dev_index, node_index); + return 0; +} + +/* Parses a string with format <N>:<M>:<0-100> into a node id and a value */ +static int parse_node_id_with_value(char *input, cras_node_id_t *id_out, + int *value_out) +{ + const char *s; + char *endptr; + int dev_index; + int node_index; + long int value; + + if (!id_out || !value_out) + return -EINVAL; + + s = strtok(input, ":"); + if (!s) + return -EINVAL; + dev_index = strtol(s, &endptr, 10); + if (*endptr) + return -EINVAL; + + s = strtok(NULL, ":"); + if (!s) + return -EINVAL; + node_index = strtol(s, &endptr, 10); + if (*endptr) + return -EINVAL; + + s = strtok(NULL, ":"); + if (!s) + return -EINVAL; + value = strtol(s, &endptr, 10); + if (*endptr) + return -EINVAL; + if (value > INT_MAX || value < INT_MIN) + return -EOVERFLOW; + + *id_out = cras_make_node_id(dev_index, node_index); + *value_out = value; + return 0; +} + /* Run from callback thread. */ -static int got_samples(struct cras_client *client, - cras_stream_id_t stream_id, - uint8_t *captured_samples, - uint8_t *playback_samples, +static int got_samples(struct cras_client *client, cras_stream_id_t stream_id, + uint8_t *captured_samples, uint8_t *playback_samples, unsigned int frames, const struct timespec *captured_time, - const struct timespec *playback_time, - void *user_arg) + const struct timespec *playback_time, void *user_arg) { int *fd = (int *)user_arg; int ret; @@ -169,14 +254,11 @@ static int got_samples(struct cras_client *client, } /* Run from callback thread. */ -static int put_samples(struct cras_client *client, - cras_stream_id_t stream_id, - uint8_t *captured_samples, - uint8_t *playback_samples, +static int put_samples(struct cras_client *client, cras_stream_id_t stream_id, + uint8_t *captured_samples, uint8_t *playback_samples, unsigned int frames, const struct timespec *captured_time, - const struct timespec *playback_time, - void *user_arg) + const struct timespec *playback_time, void *user_arg) { uint32_t frame_bytes = cras_client_format_bytes_per_frame(aud_format); int fd = *(int *)user_arg; @@ -219,14 +301,11 @@ static int put_samples(struct cras_client *client, } /* Run from callback thread. */ -static int put_stdin_samples(struct cras_client *client, - cras_stream_id_t stream_id, - uint8_t *captured_samples, - uint8_t *playback_samples, - unsigned int frames, - const struct timespec *captured_time, - const struct timespec *playback_time, - void *user_arg) +static int +put_stdin_samples(struct cras_client *client, cras_stream_id_t stream_id, + uint8_t *captured_samples, uint8_t *playback_samples, + unsigned int frames, const struct timespec *captured_time, + const struct timespec *playback_time, void *user_arg) { int rc = 0; uint32_t frame_bytes = cras_client_format_bytes_per_frame(aud_format); @@ -240,10 +319,8 @@ static int put_stdin_samples(struct cras_client *client, return rc / frame_bytes; } -static int stream_error(struct cras_client *client, - cras_stream_id_t stream_id, - int err, - void *arg) +static int stream_error(struct cras_client *client, cras_stream_id_t stream_id, + int err, void *arg) { printf("Stream error %d\n", err); terminate_stream_loop(); @@ -288,21 +365,19 @@ static void print_node_info(const struct cras_ionode_info *nodes, int num_nodes, unsigned i; printf("\tStable Id\t ID\t%4s Plugged\tL/R swapped\t " - "Time Hotword\tType\t\t Name\n", is_input ? "Gain" : " Vol"); + "Time Hotword\tType\t\t Name\n", + is_input ? "Gain" : " Vol"); for (i = 0; i < num_nodes; i++) printf("\t(%08x)\t%u:%u\t%5g %7s\t%14s\t%10ld %-7s\t%-16s%c%s\n", - nodes[i].stable_id, - nodes[i].iodev_idx, + nodes[i].stable_id, nodes[i].iodev_idx, nodes[i].ionode_idx, - is_input ? nodes[i].capture_gain / 100.0 - : (double) nodes[i].volume, + is_input ? nodes[i].capture_gain / 100.0 : + (double)nodes[i].volume, nodes[i].plugged ? "yes" : "no", nodes[i].left_right_swapped ? "yes" : "no", - (long) nodes[i].plugged_time.tv_sec, - nodes[i].active_hotword_model, - nodes[i].type, - nodes[i].active ? '*' : ' ', - nodes[i].name); + (long)nodes[i].plugged_time.tv_sec, + nodes[i].active_hotword_model, nodes[i].type, + nodes[i].active ? '*' : ' ', nodes[i].name); } static void print_device_lists(struct cras_client *client) @@ -339,8 +414,7 @@ static void print_attached_client_list(struct cras_client *client) size_t i; int num_clients; - num_clients = cras_client_get_attached_clients(client, - clients, + num_clients = cras_client_get_attached_clients(client, clients, MAX_ATTACHED_CLIENTS); if (num_clients < 0) return; @@ -348,9 +422,7 @@ static void print_attached_client_list(struct cras_client *client) printf("Attached clients:\n"); printf("\tID\tpid\tuid\n"); for (i = 0; i < num_clients; i++) - printf("\t%u\t%d\t%d\n", - clients[i].id, - clients[i].pid, + printf("\t%u\t%d\t%d\n", clients[i].id, clients[i].pid, clients[i].gid); } @@ -361,8 +433,8 @@ static void print_active_stream_info(struct cras_client *client) num_streams = cras_client_get_num_active_streams(client, &ts); printf("Num active streams: %u\n", num_streams); - printf("Last audio active time: %llu, %llu\n", - (long long)ts.tv_sec, (long long)ts.tv_nsec); + printf("Last audio active time: %llu, %llu\n", (long long)ts.tv_sec, + (long long)ts.tv_nsec); } static void print_system_volumes(struct cras_client *client) @@ -388,7 +460,7 @@ static void print_user_muted(struct cras_client *client) * in sec and nsec. */ static void convert_time(unsigned int *sec, unsigned int *nsec, - int32_t sec_offset, int32_t nsec_offset) + time_t sec_offset, int32_t nsec_offset) { sec_offset += *sec; nsec_offset += *nsec; @@ -450,16 +522,16 @@ static void show_alog_tag(const struct audio_thread_event_log *log, printf("%-30s num_fds:%d\n", "WAKE", (int)data1); break; case AUDIO_THREAD_SLEEP: - printf("%-30s sleep:%09d.%09d longest_wake:%09d\n", - "SLEEP", (int)data1, (int)data2, (int)data3); + printf("%-30s sleep:%09d.%09d\n", "SLEEP", (int)data1, + (int)data2); break; case AUDIO_THREAD_READ_AUDIO: - printf("%-30s dev:%u hw_level:%u read:%u\n", - "READ_AUDIO", data1, data2, data3); + printf("%-30s dev:%u hw_level:%u read:%u\n", "READ_AUDIO", + data1, data2, data3); break; case AUDIO_THREAD_READ_AUDIO_TSTAMP: - printf("%-30s dev:%u tstamp:%s.%09u\n", - "READ_AUDIO_TSTAMP", data1, time_str, nsec); + printf("%-30s dev:%u tstamp:%s.%09u\n", "READ_AUDIO_TSTAMP", + data1, time_str, nsec); break; case AUDIO_THREAD_READ_AUDIO_DONE: printf("%-30s read_remainder:%u\n", "READ_AUDIO_DONE", data1); @@ -469,12 +541,12 @@ static void show_alog_tag(const struct audio_thread_event_log *log, "READ_AUDIO_OVERRUN", data1, data2, data3); break; case AUDIO_THREAD_FILL_AUDIO: - printf("%-30s dev:%u hw_level:%u\n", - "FILL_AUDIO", data1, data2); + printf("%-30s dev:%u hw_level:%u\n", "FILL_AUDIO", data1, + data2); break; case AUDIO_THREAD_FILL_AUDIO_TSTAMP: - printf("%-30s dev:%u tstamp:%s.%09u\n", - "FILL_AUDIO_TSTAMP", data1, time_str, nsec); + printf("%-30s dev:%u tstamp:%s.%09u\n", "FILL_AUDIO_TSTAMP", + data1, time_str, nsec); break; case AUDIO_THREAD_FILL_AUDIO_DONE: printf("%-30s hw_level:%u total_written:%u min_cb_level:%u\n", @@ -502,31 +574,30 @@ static void show_alog_tag(const struct audio_thread_event_log *log, "WRITE_STREAMS_FETCH_STREAM", data1, data2, data3); break; case AUDIO_THREAD_STREAM_ADDED: - printf("%-30s id:%x dev:%u\n", - "STREAM_ADDED", data1, data2); + printf("%-30s id:%x dev:%u\n", "STREAM_ADDED", data1, data2); break; case AUDIO_THREAD_STREAM_REMOVED: printf("%-30s id:%x\n", "STREAM_REMOVED", data1); break; case AUDIO_THREAD_A2DP_ENCODE: - printf("%-30s proc:%d queued:%u readable:%u\n", - "A2DP_ENCODE", data1, data2, data3); + printf("%-30s proc:%d queued:%u readable:%u\n", "A2DP_ENCODE", + data1, data2, data3); break; case AUDIO_THREAD_A2DP_WRITE: - printf("%-30s written:%d queued:%u\n", - "A2DP_WRITE", data1, data2); + printf("%-30s written:%d queued:%u\n", "A2DP_WRITE", data1, + data2); break; case AUDIO_THREAD_DEV_STREAM_MIX: - printf("%-30s written:%u read:%u\n", - "DEV_STREAM_MIX", data1, data2); + printf("%-30s written:%u read:%u\n", "DEV_STREAM_MIX", data1, + data2); break; case AUDIO_THREAD_CAPTURE_POST: - printf("%-30s stream:%x thresh:%u rd_buf:%u\n", - "CAPTURE_POST", data1, data2, data3); + printf("%-30s stream:%x thresh:%u rd_buf:%u\n", "CAPTURE_POST", + data1, data2, data3); break; case AUDIO_THREAD_CAPTURE_WRITE: - printf("%-30s stream:%x write:%u shm_fr:%u\n", - "CAPTURE_WRITE", data1, data2, data3); + printf("%-30s stream:%x write:%u shm_fr:%u\n", "CAPTURE_WRITE", + data1, data2, data3); break; case AUDIO_THREAD_CONV_COPY: printf("%-30s wr_buf:%u shm_writable:%u offset:%u\n", @@ -536,28 +607,28 @@ static void show_alog_tag(const struct audio_thread_event_log *log, printf("%-30s id:%x\n", "STREAM_FETCH_PENGING", data1); break; case AUDIO_THREAD_STREAM_RESCHEDULE: - printf("%-30s id:%x next_cb_ts:%s.%09u\n", - "STREAM_RESCHEDULE", data1, time_str, nsec); + printf("%-30s id:%x next_cb_ts:%s.%09u\n", "STREAM_RESCHEDULE", + data1, time_str, nsec); break; case AUDIO_THREAD_STREAM_SLEEP_TIME: - printf("%-30s id:%x wake:%s.%09u\n", - "STREAM_SLEEP_TIME", data1, time_str, nsec); + printf("%-30s id:%x wake:%s.%09u\n", "STREAM_SLEEP_TIME", data1, + time_str, nsec); break; case AUDIO_THREAD_STREAM_SLEEP_ADJUST: - printf("%-30s id:%x from:%s.%09u\n", - "STREAM_SLEEP_ADJUST", data1, time_str, nsec); + printf("%-30s id:%x from:%s.%09u\n", "STREAM_SLEEP_ADJUST", + data1, time_str, nsec); break; case AUDIO_THREAD_STREAM_SKIP_CB: printf("%-30s id:%x write_offset_0:%u write_offset_1:%u\n", "STREAM_SKIP_CB", data1, data2, data3); break; case AUDIO_THREAD_DEV_SLEEP_TIME: - printf("%-30s dev:%u wake:%s.%09u\n", - "DEV_SLEEP_TIME", data1, time_str, nsec); + printf("%-30s dev:%u wake:%s.%09u\n", "DEV_SLEEP_TIME", data1, + time_str, nsec); break; case AUDIO_THREAD_SET_DEV_WAKE: - printf("%-30s dev:%u hw_level:%u sleep:%u\n", - "SET_DEV_WAKE", data1, data2, data3); + printf("%-30s dev:%u hw_level:%u sleep:%u\n", "SET_DEV_WAKE", + data1, data2, data3); break; case AUDIO_THREAD_DEV_ADDED: printf("%-30s dev:%u\n", "DEV_ADDED", data1); @@ -572,20 +643,18 @@ static void show_alog_tag(const struct audio_thread_event_log *log, printf("%-30s msg_id:%u\n", "PB_MSG", data1); break; case AUDIO_THREAD_ODEV_NO_STREAMS: - printf("%-30s dev:%u\n", - "ODEV_NO_STREAMS", data1); + printf("%-30s dev:%u\n", "ODEV_NO_STREAMS", data1); break; case AUDIO_THREAD_ODEV_LEAVE_NO_STREAMS: - printf("%-30s dev:%u\n", - "ODEV_LEAVE_NO_STREAMS", data1); + printf("%-30s dev:%u\n", "ODEV_LEAVE_NO_STREAMS", data1); break; case AUDIO_THREAD_ODEV_START: - printf("%-30s dev:%u min_cb_level:%u\n", - "ODEV_START", data1, data2); + printf("%-30s dev:%u min_cb_level:%u\n", "ODEV_START", data1, + data2); break; case AUDIO_THREAD_FILL_ODEV_ZEROS: - printf("%-30s dev:%u write:%u\n", - "FILL_ODEV_ZEROS", data1, data2); + printf("%-30s dev:%u write:%u\n", "FILL_ODEV_ZEROS", data1, + data2); break; case AUDIO_THREAD_ODEV_DEFAULT_NO_STREAMS: printf("%-30s dev:%u hw_level:%u target:%u\n", @@ -598,16 +667,23 @@ static void show_alog_tag(const struct audio_thread_event_log *log, case AUDIO_THREAD_SEVERE_UNDERRUN: printf("%-30s dev:%u\n", "SEVERE_UNDERRUN", data1); break; + case AUDIO_THREAD_CAPTURE_DROP_TIME: + printf("%-30s time:%09u.%09d\n", "CAPTURE_DROP_TIME", data1, + data2); + break; + case AUDIO_THREAD_DEV_DROP_FRAMES: + printf("%-30s dev:%u frames:%u\n", "DEV_DROP_FRAMES", data1, + data2); + break; default: - printf("%-30s tag:%u\n","UNKNOWN", tag); + printf("%-30s tag:%u\n", "UNKNOWN", tag); break; } } static void print_audio_debug_info(const struct audio_debug_info *info) { - struct timespec mono_time, real_time; - int32_t sec_offset; + time_t sec_offset; int32_t nsec_offset; int i, j; @@ -618,8 +694,9 @@ static void print_audio_debug_info(const struct audio_debug_info *info) for (i = 0; i < info->num_devs; i++) { printf("%s dev: %s\n", - (info->devs[i].direction == CRAS_STREAM_INPUT) - ? "Input" : "Output", + (info->devs[i].direction == CRAS_STREAM_INPUT) ? + "Input" : + "Output", info->devs[i].dev_name); printf("buffer_size: %u\n" "min_buffer_level: %u\n" @@ -632,6 +709,7 @@ static void print_audio_debug_info(const struct audio_debug_info *info) "num_severe_underruns: %u\n" "highest_hw_level: %u\n" "runtime: %u.%09u\n" + "longest_wake: %u.%09u\n" "software_gain_scaler: %lf\n", (unsigned int)info->devs[i].buffer_size, (unsigned int)info->devs[i].min_buffer_level, @@ -645,6 +723,8 @@ static void print_audio_debug_info(const struct audio_debug_info *info) (unsigned int)info->devs[i].highest_hw_level, (unsigned int)info->devs[i].runtime_sec, (unsigned int)info->devs[i].runtime_nsec, + (unsigned int)info->devs[i].longest_wake_sec, + (unsigned int)info->devs[i].longest_wake_nsec, info->devs[i].software_gain_scaler); printf("\n"); } @@ -659,10 +739,13 @@ static void print_audio_debug_info(const struct audio_debug_info *info) (unsigned long long)info->streams[i].stream_id, (unsigned int)info->streams[i].dev_idx); printf("direction: %s\n", - (info->streams[i].direction == CRAS_STREAM_INPUT) - ? "Input" : "Output"); + (info->streams[i].direction == CRAS_STREAM_INPUT) ? + "Input" : + "Output"); printf("stream_type: %s\n", cras_stream_type_str(info->streams[i].stream_type)); + printf("client_type: %s\n", + cras_client_type_str(info->streams[i].client_type)); printf("buffer_frames: %u\n" "cb_threshold: %u\n" "effects: 0x%.4x\n" @@ -686,8 +769,9 @@ static void print_audio_debug_info(const struct audio_debug_info *info) (unsigned int)info->streams[i].is_pinned, (unsigned int)info->streams[i].pinned_dev_idx, (unsigned int)info->streams[i].num_missed_cb, - (info->streams[i].direction == CRAS_STREAM_INPUT) - ? "gain" : "volume", + (info->streams[i].direction == CRAS_STREAM_INPUT) ? + "gain" : + "volume", info->streams[i].stream_volume, (unsigned int)info->streams[i].runtime_sec, (unsigned int)info->streams[i].runtime_nsec); @@ -699,11 +783,8 @@ static void print_audio_debug_info(const struct audio_debug_info *info) printf("Audio Thread Event Log:\n"); - clock_gettime(CLOCK_MONOTONIC_RAW, &mono_time); - clock_gettime(CLOCK_REALTIME, &real_time); - sec_offset = real_time.tv_sec - mono_time.tv_sec; - nsec_offset = real_time.tv_nsec - mono_time.tv_nsec; - j = info->log.write_pos; + fill_time_offset(&sec_offset, &nsec_offset); + j = info->log.write_pos % info->log.len; i = 0; printf("start at %d\n", j); for (; i < info->log.len; i++) { @@ -728,8 +809,8 @@ static void audio_debug_info(struct cras_client *client) } static void show_btlog_tag(const struct cras_bt_event_log *log, - unsigned int tag_idx, int32_t sec_offset, - int32_t nsec_offset) + unsigned int tag_idx, int32_t sec_offset, + int32_t nsec_offset) { unsigned int tag = (log->log[tag_idx].tag_sec >> 24) & 0xff; unsigned int sec = log->log[tag_idx].tag_sec & 0x00ffffff; @@ -776,10 +857,12 @@ static void show_btlog_tag(const struct cras_bt_event_log *log, printf("%-30s \n", "AUDIO_GATEWAY_START"); break; case BT_AVAILABLE_CODECS: - printf("%-30s codec #%u id %u\n", "AVAILABLE_CODECS", data1, data2); + printf("%-30s codec #%u id %u\n", "AVAILABLE_CODECS", data1, + data2); break; case BT_CODEC_SELECTION: - printf("%-30s dir %u codec id %u\n", "CODEC_SELECTION", data1, data2); + printf("%-30s dir %u codec id %u\n", "CODEC_SELECTION", data1, + data2); break; case BT_DEV_CONNECTED_CHANGE: printf("%-30s profiles %u now %u\n", "DEV_CONENCTED_CHANGE", @@ -790,7 +873,8 @@ static void show_btlog_tag(const struct cras_bt_event_log *log, "DEV_CONN_WATCH_CB", data1, data2); break; case BT_DEV_SUSPEND_CB: - printf("%-30s\n", "DEV_SUSPEND_CB"); + printf("%-30s profiles supported %u, connected %u\n", + "DEV_SUSPEND_CB", data1, data2); break; case BT_HFP_NEW_CONNECTION: printf("%-30s\n", "HFP_NEW_CONNECTION"); @@ -809,15 +893,15 @@ static void show_btlog_tag(const struct cras_bt_event_log *log, printf("%-30s\n", "HSP_REQUEST_DISCONNECT"); break; case BT_NEW_AUDIO_PROFILE_AFTER_CONNECT: - printf("%-30s old %u, new %u\n", "NEW_AUDIO_PROFILE_AFTER_CONNECT", - data1, data2); + printf("%-30s old %u, new %u\n", + "NEW_AUDIO_PROFILE_AFTER_CONNECT", data1, data2); break; case BT_RESET: printf("%-30s\n", "RESET"); break; case BT_SCO_CONNECT: - printf("%-30s %s sk %d\n", "SCO_CONNECT", data1 ? "success" : "failed", - (int)data2); + printf("%-30s %s sk %d\n", "SCO_CONNECT", + data1 ? "success" : "failed", (int)data2); break; case BT_TRANSPORT_ACQUIRE: printf("%-30s %s fd %d\n", "TRANSPORT_ACQUIRE", @@ -835,16 +919,12 @@ static void show_btlog_tag(const struct cras_bt_event_log *log, static void cras_bt_debug_info(struct cras_client *client) { const struct cras_bt_debug_info *info; - struct timespec mono_time, real_time; - int32_t sec_offset; + time_t sec_offset; int32_t nsec_offset; int i, j; info = cras_client_get_bt_debug_info(client); - clock_gettime(CLOCK_MONOTONIC_RAW, &mono_time); - clock_gettime(CLOCK_REALTIME, &real_time); - sec_offset = real_time.tv_sec - mono_time.tv_sec; - nsec_offset = real_time.tv_nsec - mono_time.tv_nsec; + fill_time_offset(&sec_offset, &nsec_offset); j = info->bt_log.write_pos; i = 0; printf("BT debug log:\n"); @@ -869,7 +949,7 @@ static void print_cras_audio_thread_snapshot( snapshot->timestamp.tv_nsec); printf("Event type: "); - switch(snapshot->event_type) { + switch (snapshot->event_type) { case AUDIO_THREAD_EVENT_BUSYLOOP: printf("busyloop\n"); break; @@ -879,6 +959,9 @@ static void print_cras_audio_thread_snapshot( case AUDIO_THREAD_EVENT_SEVERE_UNDERRUN: printf("severe underrun\n"); break; + case AUDIO_THREAD_EVENT_DROP_SAMPLES: + printf("drop samples\n"); + break; case AUDIO_THREAD_EVENT_DEBUG: printf("debug\n"); break; @@ -897,11 +980,9 @@ static void audio_thread_snapshots(struct cras_client *client) snapshot_buffer = cras_client_get_audio_thread_snapshot_buffer(client); i = snapshot_buffer->pos; - for(j = 0; j < CRAS_MAX_AUDIO_THREAD_SNAPSHOTS; j++) - { - if(snapshot_buffer->snapshots[i].timestamp.tv_sec || - snapshot_buffer->snapshots[i].timestamp.tv_nsec) - { + for (j = 0; j < CRAS_MAX_AUDIO_THREAD_SNAPSHOTS; j++) { + if (snapshot_buffer->snapshots[i].timestamp.tv_sec || + snapshot_buffer->snapshots[i].timestamp.tv_nsec) { print_cras_audio_thread_snapshot( &snapshot_buffer->snapshots[i]); count++; @@ -917,10 +998,8 @@ static void audio_thread_snapshots(struct cras_client *client) pthread_mutex_unlock(&done_mutex); } -static int start_stream(struct cras_client *client, - cras_stream_id_t *stream_id, - struct cras_stream_params *params, - float stream_volume) +static int start_stream(struct cras_client *client, cras_stream_id_t *stream_id, + struct cras_stream_params *params, float stream_volume) { int rc; @@ -956,8 +1035,8 @@ static void run_aecdump(struct cras_client *client, uint64_t stream_id, { int aecdump_fd; if (start) { - aecdump_fd = open(aecdump_file, O_CREAT | O_RDWR | O_TRUNC, - 0666); + aecdump_fd = + open(aecdump_file, O_CREAT | O_RDWR | O_TRUNC, 0666); if (aecdump_fd == -1) { printf("Fail to open file %s", aecdump_file); return; @@ -972,17 +1051,12 @@ static void run_aecdump(struct cras_client *client, uint64_t stream_id, } } -static int run_file_io_stream(struct cras_client *client, - int fd, +static int run_file_io_stream(struct cras_client *client, int fd, enum CRAS_STREAM_DIRECTION direction, size_t block_size, - enum CRAS_STREAM_TYPE stream_type, - size_t rate, - snd_pcm_format_t format, - size_t num_channels, - uint32_t flags, - int is_loopback, - int is_post_dsp) + enum CRAS_STREAM_TYPE stream_type, size_t rate, + snd_pcm_format_t format, size_t num_channels, + uint32_t flags, int is_loopback, int is_post_dsp) { int rc, tty; struct cras_stream_params *params; @@ -1035,17 +1109,16 @@ static int run_file_io_stream(struct cras_client *client, cras_audio_format_set_channel_layout(aud_format, layout); } - params = cras_client_unified_params_create(direction, - block_size, - stream_type, - flags, - pfd, - aud_cb, - stream_error, + params = cras_client_unified_params_create(direction, block_size, + stream_type, flags, pfd, + aud_cb, stream_error, aud_format); if (params == NULL) return -ENOMEM; + cras_client_stream_params_set_client_type(params, + CRAS_CLIENT_TYPE_TEST); + if (effect_aec) cras_client_stream_params_enable_aec(params); if (effect_ns) @@ -1057,13 +1130,13 @@ static int run_file_io_stream(struct cras_client *client, cras_client_run_thread(client); if (is_loopback) { - enum CRAS_NODE_TYPE type = (is_post_dsp ? - CRAS_NODE_TYPE_POST_DSP : - CRAS_NODE_TYPE_POST_MIX_PRE_DSP); + enum CRAS_NODE_TYPE type = + (is_post_dsp ? CRAS_NODE_TYPE_POST_DSP : + CRAS_NODE_TYPE_POST_MIX_PRE_DSP); cras_client_connected_wait(client); pin_device_id = cras_client_get_first_dev_type_idx( - client, type, CRAS_STREAM_INPUT); + client, type, CRAS_STREAM_INPUT); } stream_playing = @@ -1083,12 +1156,8 @@ static int run_file_io_stream(struct cras_client *client, if (tty >= 0) FD_SET(tty, &poll_set); FD_SET(pipefd[0], &poll_set); - pselect(MAX(tty, pipefd[0]) + 1, - &poll_set, - NULL, - NULL, - show_latency || show_rms ? &sleep_ts : NULL, - NULL); + pselect(MAX(tty, pipefd[0]) + 1, &poll_set, NULL, NULL, + show_latency || show_rms ? &sleep_ts : NULL, NULL); if (stream_playing && show_latency) print_last_latency(); @@ -1121,10 +1190,9 @@ static int run_file_io_stream(struct cras_client *client, /* If started by hand keep running after it finishes. */ exit_after_done_playing = 0; - stream_playing = start_stream(client, - &stream_id, - params, - volume_scaler) == 0; + stream_playing = + start_stream(client, &stream_id, params, + volume_scaler) == 0; break; case 'r': if (!stream_playing) @@ -1134,14 +1202,12 @@ static int run_file_io_stream(struct cras_client *client, break; case 'u': volume_scaler = MIN(volume_scaler + 0.1, 1.0); - cras_client_set_stream_volume(client, - stream_id, + cras_client_set_stream_volume(client, stream_id, volume_scaler); break; case 'd': volume_scaler = MAX(volume_scaler - 0.1, 0.0); - cras_client_set_stream_volume(client, - stream_id, + cras_client_set_stream_volume(client, stream_id, volume_scaler); break; case 'k': @@ -1174,18 +1240,21 @@ static int run_file_io_stream(struct cras_client *client, printf("Volume: %zu%s Min dB: %ld Max dB: %ld\n" "Capture: %ld%s Min dB: %ld Max dB: %ld\n", cras_client_get_system_volume(client), - cras_client_get_system_muted(client) ? "(Muted)" - : "", + cras_client_get_system_muted(client) ? + "(Muted)" : + "", cras_client_get_system_min_volume(client), cras_client_get_system_max_volume(client), cras_client_get_system_capture_gain(client), cras_client_get_system_capture_muted(client) ? - "(Muted)" : "", + "(Muted)" : + "", cras_client_get_system_min_capture_gain(client), cras_client_get_system_max_capture_gain(client)); break; case '\'': - play_short_sound_periods_left = play_short_sound_periods; + play_short_sound_periods_left = + play_short_sound_periods; break; case '\n': break; @@ -1210,15 +1279,10 @@ static int run_file_io_stream(struct cras_client *client, return 0; } -static int run_capture(struct cras_client *client, - const char *file, - size_t block_size, - enum CRAS_STREAM_TYPE stream_type, - size_t rate, - snd_pcm_format_t format, - size_t num_channels, - uint32_t flags, - int is_loopback, +static int run_capture(struct cras_client *client, const char *file, + size_t block_size, enum CRAS_STREAM_TYPE stream_type, + size_t rate, snd_pcm_format_t format, + size_t num_channels, uint32_t flags, int is_loopback, int is_post_dsp) { int fd = open(file, O_CREAT | O_RDWR | O_TRUNC, 0666); @@ -1235,12 +1299,9 @@ static int run_capture(struct cras_client *client, return 0; } -static int run_playback(struct cras_client *client, - const char *file, - size_t block_size, - enum CRAS_STREAM_TYPE stream_type, - size_t rate, - snd_pcm_format_t format, +static int run_playback(struct cras_client *client, const char *file, + size_t block_size, enum CRAS_STREAM_TYPE stream_type, + size_t rate, snd_pcm_format_t format, size_t num_channels) { int fd; @@ -1316,7 +1377,6 @@ static void show_cras_bt_debug_info(struct cras_client *client) pthread_mutex_lock(&done_mutex); pthread_cond_timedwait(&done_cond, &done_mutex, &wait_time); pthread_mutex_unlock(&done_mutex); - } static void hotword_models_cb(struct cras_client *client, @@ -1325,15 +1385,13 @@ static void hotword_models_cb(struct cras_client *client, printf("Hotword models: %s\n", hotword_models); } -static void print_hotword_models(struct cras_client *client, - cras_node_id_t id) +static void print_hotword_models(struct cras_client *client, cras_node_id_t id) { struct timespec wait_time; cras_client_run_thread(client); cras_client_connected_wait(client); - cras_client_get_hotword_models(client, id, - hotword_models_cb); + cras_client_get_hotword_models(client, id, hotword_models_cb); clock_gettime(CLOCK_REALTIME, &wait_time); wait_time.tv_sec += 2; @@ -1359,7 +1417,7 @@ static void mute_loop_test(struct cras_client *client, int auto_reconnect) if (auto_reconnect) cras_client_run_thread(client); - while(1) { + while (1) { rc = cras_client_set_user_mute(client, mute); printf("cras_client_set_user_mute(%d): %d\n", mute, rc); if (rc != 0 && !auto_reconnect) @@ -1369,133 +1427,281 @@ static void mute_loop_test(struct cras_client *client, int auto_reconnect) } } +static void show_atlog(time_t sec_offset, int32_t nsec_offset, + struct audio_thread_event_log *log, int len, + uint64_t missing) +{ + int i; + printf("Audio Thread Event Log:\n"); + + if (missing) + printf("%" PRIu64 " logs are missing.\n", missing); + + for (i = 0; i < len; ++i) { + show_alog_tag(log, i, sec_offset, nsec_offset); + } +} + +static void unlock_main_thread(struct cras_client *client) +{ + pthread_mutex_lock(&done_mutex); + pthread_cond_signal(&done_cond); + pthread_mutex_unlock(&done_mutex); +} + +static void cras_show_continuous_atlog(struct cras_client *client) +{ + struct audio_thread_event_log log; + struct timespec wait_time; + static time_t sec_offset; + static int32_t nsec_offset; + static uint64_t atlog_read_idx = 0, missing; + int len, rc; + + cras_client_run_thread(client); + cras_client_connected_wait(client); /* To synchronize data. */ + cras_client_get_atlog_access(client, unlock_main_thread); + + clock_gettime(CLOCK_REALTIME, &wait_time); + wait_time.tv_sec += 2; + + pthread_mutex_lock(&done_mutex); + rc = pthread_cond_timedwait(&done_cond, &done_mutex, &wait_time); + pthread_mutex_unlock(&done_mutex); + + if (rc) + goto fail; + + fill_time_offset(&sec_offset, &nsec_offset); + + while (1) { + len = cras_client_read_atlog(client, &atlog_read_idx, &missing, + &log); + + if (len < 0) + break; + if (len > 0) + show_atlog(sec_offset, nsec_offset, &log, len, missing); + nanosleep(&follow_atlog_sleep_ts, NULL); + } +fail: + printf("Failed to get audio thread log.\n"); +} + +// clang-format off static struct option long_options[] = { - {"show_latency", no_argument, &show_latency, 1}, - {"show_rms", no_argument, &show_rms, 1}, - {"show_total_rms", no_argument, &show_total_rms, 1}, + {"show_latency", no_argument, &show_latency, 1}, + {"show_rms", no_argument, &show_rms, 1}, + {"show_total_rms", no_argument, &show_total_rms, 1}, {"select_input", required_argument, 0, 'a'}, - {"block_size", required_argument, 0, 'b'}, + {"block_size", required_argument, 0, 'b'}, {"num_channels", required_argument, 0, 'c'}, - {"duration_seconds", required_argument, 0, 'd'}, - {"dump_events", no_argument, 0, 'e'}, - {"format", required_argument, 0, 'f'}, + {"duration_seconds", required_argument, 0, 'd'}, + {"dump_events", no_argument, 0, 'e'}, + {"format", required_argument, 0, 'f'}, {"capture_gain", required_argument, 0, 'g'}, {"help", no_argument, 0, 'h'}, {"dump_server_info", no_argument, 0, 'i'}, {"check_output_plugged",required_argument, 0, 'j'}, - {"add_active_input", required_argument, 0, 'k'}, + {"add_active_input", required_argument, 0, 'k'}, {"dump_dsp", no_argument, 0, 'l'}, {"dump_audio_thread", no_argument, 0, 'm'}, - {"syslog_mask", required_argument, 0, 'n'}, + {"syslog_mask", required_argument, 0, 'n'}, {"channel_layout", required_argument, 0, 'o'}, - {"get_aec_group_id", no_argument, 0, 'p'}, + {"get_aec_group_id", no_argument, 0, 'p'}, {"user_mute", required_argument, 0, 'q'}, - {"rate", required_argument, 0, 'r'}, + {"rate", required_argument, 0, 'r'}, {"reload_dsp", no_argument, 0, 's'}, - {"add_active_output", required_argument, 0, 't'}, + {"add_active_output", required_argument, 0, 't'}, {"mute", required_argument, 0, 'u'}, {"volume", required_argument, 0, 'v'}, - {"set_node_volume", required_argument, 0, 'w'}, + {"set_node_volume", required_argument, 0, 'w'}, {"plug", required_argument, 0, 'x'}, {"select_output", required_argument, 0, 'y'}, {"playback_delay_us", required_argument, 0, 'z'}, {"capture_mute", required_argument, 0, '0'}, - {"rm_active_input", required_argument, 0, '1'}, - {"rm_active_output", required_argument, 0, '2'}, + {"rm_active_input", required_argument, 0, '1'}, + {"rm_active_output", required_argument, 0, '2'}, {"swap_left_right", required_argument, 0, '3'}, {"version", no_argument, 0, '4'}, {"add_test_dev", required_argument, 0, '5'}, {"test_hotword_file", required_argument, 0, '6'}, {"listen_for_hotword", required_argument, 0, '7'}, - {"pin_device", required_argument, 0, '8'}, - {"suspend", required_argument, 0, '9'}, - {"set_node_gain", required_argument, 0, ':'}, - {"play_short_sound", required_argument, 0, '!'}, - {"config_global_remix", required_argument, 0, ';'}, - {"set_hotword_model", required_argument, 0, '<'}, - {"get_hotword_models", required_argument, 0, '>'}, - {"post_dsp", required_argument, 0, 'A'}, - {"stream_id", required_argument, 0, 'B'}, - {"capture_file", required_argument, 0, 'C'}, - {"reload_aec_config", no_argument, 0, 'D'}, - {"effects", required_argument, 0, 'E'}, - {"get_aec_supported", no_argument, 0, 'F'}, - {"aecdump", required_argument, 0, 'G'}, - {"dump_bt", no_argument, 0, 'H'}, - {"set_wbs_enabled", required_argument, 0, 'I'}, - {"loopback_file", required_argument, 0, 'L'}, - {"mute_loop_test", required_argument, 0, 'M'}, - {"playback_file", required_argument, 0, 'P'}, - {"stream_type", required_argument, 0, 'T'}, + {"pin_device", required_argument, 0, '8'}, + {"suspend", required_argument, 0, '9'}, + {"set_node_gain", required_argument, 0, ':'}, + {"play_short_sound", required_argument, 0, '!'}, + {"config_global_remix", required_argument, 0, ';'}, + {"set_hotword_model", required_argument, 0, '<'}, + {"get_hotword_models", required_argument, 0, '>'}, + {"post_dsp", required_argument, 0, 'A'}, + {"stream_id", required_argument, 0, 'B'}, + {"capture_file", required_argument, 0, 'C'}, + {"reload_aec_config", no_argument, 0, 'D'}, + {"effects", required_argument, 0, 'E'}, + {"get_aec_supported", no_argument, 0, 'F'}, + {"aecdump", required_argument, 0, 'G'}, + {"dump_bt", no_argument, 0, 'H'}, + {"set_wbs_enabled", required_argument, 0, 'I'}, + {"follow_atlog", no_argument, 0, 'J'}, + {"connection_type", required_argument, 0, 'K'}, + {"loopback_file", required_argument, 0, 'L'}, + {"mute_loop_test", required_argument, 0, 'M'}, + {"playback_file", required_argument, 0, 'P'}, + {"stream_type", required_argument, 0, 'T'}, {0, 0, 0, 0} }; +// clang-format on static void show_usage() { int i; - printf("--add_active_input <N>:<M> - Add the ionode with the given id" - "to active input device list\n"); - printf("--add_active_output <N>:<M> - Add the ionode with the given id" - "to active output device list\n"); - printf("--add_test_dev <type> - add a test iodev.\n"); - printf("--block_size <N> - The number for frames per callback(dictates latency).\n"); - printf("--capture_file <name> - Name of file to record to.\n"); - printf("--capture_gain <dB> - Set system caputre gain in dB*100 (100 = 1dB).\n"); - printf("--capture_mute <0|1> - Set capture mute state.\n"); - printf("--channel_layout <layout_str> - Set multiple channel layout.\n"); - printf("--check_output_plugged <output name> - Check if the output is plugged in\n"); - printf("--dump_audio_thread - Dumps audio thread info.\n"); - printf("--dump_bt - Dumps debug info for bt audio\n"); - printf("--dump_dsp - Print status of dsp to syslog.\n"); - printf("--dump_server_info - Print status of the server.\n"); - printf("--duration_seconds <N> - Seconds to record or playback.\n"); - printf("--format <name> - The sample format. Either"); + printf("--add_active_input <N>:<M> - " + "Add the ionode with the given id to active input device " + "list\n"); + printf("--add_active_output <N>:<M> - " + "Add the ionode with the given id to active output device " + "list\n"); + printf("--add_test_dev <type> - " + "Add a test iodev.\n"); + printf("--block_size <N> - " + "The number for frames per callback(dictates latency).\n"); + printf("--capture_file <name> - " + "Name of file to record to.\n"); + printf("--capture_gain <dB> - " + "Set system caputre gain in dB*100 (100 = 1dB).\n"); + printf("--capture_mute <0|1> - " + "Set capture mute state.\n"); + printf("--channel_layout <layout_str> - " + "Set multiple channel layout.\n"); + printf("--check_output_plugged <output name> - " + "Check if the output is plugged in\n"); + printf("--connection_type <connection_type> - " + "Set cras_client connection_type (default to 0).\n" + " " + "Argument: 0 - For control client.\n" + " " + " 1 - For playback client.\n" + " " + " 2 - For capture client.\n"); + printf("--dump_audio_thread - " + "Dumps audio thread info.\n"); + printf("--dump_bt - " + "Dumps debug info for bt audio\n"); + printf("--dump_dsp - " + "Print status of dsp to syslog.\n"); + printf("--dump_server_info - " + "Print status of the server.\n"); + printf("--duration_seconds <N> - " + "Seconds to record or playback.\n"); + printf("--follow_atlog - " + "Continuously dumps audio thread event log.\n"); + printf("--format <name> - " + "The sample format. Either "); for (i = 0; supported_formats[i].name; ++i) - printf(" %s", supported_formats[i].name); - printf(" (default to S16_LE).\n"); - printf("--get_hotword_models <N>:<M> - Get the supported hotword models of node\n"); - printf("--help - Print this message.\n"); - printf("--listen_for_hotword <name> - Listen and capture hotword stream if supported\n"); - printf("--loopback_file <name> - Name of file to record from loopback device.\n"); - printf("--mute <0|1> - Set system mute state.\n"); - printf("--mute_loop_test <0|1> - Continuously loop mute/umute. Argument: 0 - stop on error.\n" - " 1 - automatically reconnect to CRAS.\n"); - printf("--num_channels <N> - Two for stereo.\n"); - printf("--pin_device <N> - Playback/Capture only on the given device." - "\n"); - printf("--playback_file <name> - Name of file to play, " + printf("%s ", supported_formats[i].name); + printf("(default to S16_LE).\n"); + printf("--get_hotword_models <N>:<M> - " + "Get the supported hotword models of node\n"); + printf("--help - " + "Print this message.\n"); + printf("--listen_for_hotword <name> - " + "Listen and capture hotword stream if supported\n"); + printf("--loopback_file <name> - " + "Name of file to record from loopback device.\n"); + printf("--mute <0|1> - " + "Set system mute state.\n"); + printf("--mute_loop_test <0|1> - " + "Continuously loop mute/umute.\n" + " " + "Argument: 0 - stop on error.\n" + " " + " 1 - automatically reconnect to CRAS.\n"); + printf("--num_channels <N> - " + "Two for stereo.\n"); + printf("--pin_device <N> - " + "Playback/Capture only on the given device.\n"); + printf("--playback_file <name> - " + "Name of file to play, " "\"-\" to playback raw audio from stdin.\n"); - printf("--play_short_sound <N> - Plays the content in the file for N periods when ' is pressed.\n"); - printf("--plug <N>:<M>:<0|1> - Set the plug state (0 or 1) for the" - " ionode with the given index M on the device with index N\n"); - printf("--rate <N> - Specifies the sample rate in Hz.\n"); - printf("--reload_dsp - Reload dsp configuration from the ini file\n"); - printf("--rm_active_input <N>:<M> - Removes the ionode with the given" - "id from active input device list\n"); - printf("--rm_active_output <N>:<M> - Removes the ionode with the given" - "id from active output device list\n"); - printf("--select_input <N>:<M> - Select the ionode with the given id as preferred input\n"); - printf("--select_output <N>:<M> - Select the ionode with the given id as preferred output\n"); - printf("--set_hotword_model <N>:<M>:<model> - Set the model to node\n"); - printf("--playback_delay_us <N> - Set the time in us to delay a reply for playback when i is pressed\n"); - printf("--post_dsp <0|1> - Use this flag with --loopback_file. The default value is 0.\n" - " Argument: 0 - Record from post-mix, pre-DSP loopback device.\n" - " 1 - Record from post-DSP loopback device.\n"); - printf("--set_node_volume <N>:<M>:<0-100> - Set the volume of the ionode with the given id\n"); - printf("--show_latency - Display latency while playing or recording.\n"); - printf("--show_rms - Display RMS value of loopback stream.\n"); - printf("--show_total_rms - Display total RMS value of loopback stream at the end.\n"); - printf("--suspend <0|1> - Set audio suspend state.\n"); - printf("--swap_left_right <N>:<M>:<0|1> - Swap or unswap (1 or 0) the" - " left and right channel for the ionode with the given index M" - " on the device with index N\n"); - printf("--stream_type <N> - Specify the type of the stream.\n"); - printf("--syslog_mask <n> - Set the syslog mask to the given log level.\n"); - printf("--test_hotword_file <N>:<filename> - Use filename as a hotword buffer for device N\n"); - printf("--user_mute <0|1> - Set user mute state.\n"); - printf("--version - Print the git commit ID that was used to build the client.\n"); - printf("--volume <0-100> - Set system output volume.\n"); + printf("--play_short_sound <N> - " + "Plays the content in the file for N periods when ' " + "is pressed.\n"); + printf("--plug <N>:<M>:<0|1> - " + "Set the plug state (0 or 1) for the ionode with the given " + "index M on the device with index N\n"); + printf("--rate <N> - " + "Specifies the sample rate in Hz.\n"); + printf("--reload_dsp - " + "Reload dsp configuration from the ini file\n"); + printf("--rm_active_input <N>:<M> - " + "Removes the ionode with the given id from active input device " + "list\n"); + printf("--rm_active_output <N>:<M> - " + "Removes the ionode with the given id from active output device " + "list\n"); + printf("--select_input <N>:<M> - " + "Select the ionode with the given id as preferred input\n"); + printf("--select_output <N>:<M> - " + "Select the ionode with the given id as preferred output\n"); + printf("--set_hotword_model <N>:<M>:<model> - " + "Set the model to node\n"); + printf("--playback_delay_us <N> - " + "Set the time in us to delay a reply for playback when i is " + "pressed\n"); + printf("--post_dsp <0|1> - " + "Use this flag with --loopback_file. The default value is 0.\n" + " " + "Argument: 0 - Record from post-mix, pre-DSP loopback device.\n" + " " + " 1 - Record from post-DSP loopback device.\n"); + printf("--set_node_volume <N>:<M>:<0-100> - " + "Set the volume of the ionode with the given id\n"); + printf("--show_latency - " + "Display latency while playing or recording.\n"); + printf("--show_rms - " + "Display RMS value of loopback stream.\n"); + printf("--show_total_rms - " + "Display total RMS value of loopback stream at the end.\n"); + printf("--suspend <0|1> - " + "Set audio suspend state.\n"); + printf("--swap_left_right <N>:<M>:<0|1> - " + "Swap or unswap (1 or 0) the left and right channel for the " + "ionode with the given index M on the device with index N\n"); + printf("--stream_type <N> - " + "Specify the type of the stream.\n"); + printf("--syslog_mask <n> - " + "Set the syslog mask to the given log level.\n"); + printf("--test_hotword_file <N>:<filename> - " + "Use filename as a hotword buffer for device N\n"); + printf("--user_mute <0|1> - " + "Set user mute state.\n"); + printf("--version - " + "Print the git commit ID that was used to build the client.\n"); + printf("--volume <0-100> - " + "Set system output volume.\n"); +} + +static int cras_client_create_and_connect(struct cras_client **client, + enum CRAS_CONNECTION_TYPE conn_type) +{ + int rc; + + rc = cras_client_create_with_type(client, conn_type); + if (rc < 0) { + fprintf(stderr, "Couldn't create client.\n"); + return rc; + } + + rc = cras_client_connect_timeout(*client, 1000); + if (rc) { + fprintf(stderr, "Couldn't connect to server.\n"); + cras_client_destroy(*client); + return rc; + } + + return 0; } int main(int argc, char **argv) @@ -1515,21 +1721,16 @@ int main(int argc, char **argv) uint32_t stream_flags = 0; cras_stream_id_t stream_id = 0; snd_pcm_format_t format = SND_PCM_FORMAT_S16_LE; + enum CRAS_CONNECTION_TYPE conn_type = CRAS_CONTROL; + enum CRAS_CONNECTION_TYPE new_conn_type; option_index = 0; openlog("cras_test_client", LOG_PERROR, LOG_USER); setlogmask(LOG_UPTO(LOG_INFO)); - rc = cras_client_create(&client); - if (rc < 0) { - fprintf(stderr, "Couldn't create client.\n"); - return rc; - } - - rc = cras_client_connect_timeout(client, 1000); + rc = cras_client_create_and_connect(&client, conn_type); if (rc) { - fprintf(stderr, "Couldn't connect to server.\n"); - goto destroy_exit; + return rc; } if (argc == 1) { @@ -1539,20 +1740,23 @@ int main(int argc, char **argv) } while (1) { - c = getopt_long(argc, argv, "o:s:P:C:r:c:f:h", - long_options, &option_index); + c = getopt_long(argc, argv, "o:s:P:C:r:c:f:h", long_options, + &option_index); if (c == -1) break; switch (c) { case 'y': case 'a': { - int dev_index = atoi(strtok(optarg, ":")); - int node_index = atoi(strtok(NULL, ":")); - cras_node_id_t id = cras_make_node_id(dev_index, - node_index); + cras_node_id_t id; + rc = parse_node_id(optarg, &id); + if (rc) { + show_usage(); + return rc; + } - enum CRAS_STREAM_DIRECTION direction = (c == 'y') ? - CRAS_STREAM_OUTPUT : CRAS_STREAM_INPUT; + enum CRAS_STREAM_DIRECTION direction = + (c == 'y') ? CRAS_STREAM_OUTPUT : + CRAS_STREAM_INPUT; cras_client_select_node(client, direction, id); break; } @@ -1573,7 +1777,8 @@ int main(int argc, char **argv) for (i = 0; supported_formats[i].name; ++i) { if (strcasecmp(optarg, - supported_formats[i].name) == 0) { + supported_formats[i].name) == + 0) { format = supported_formats[i].format; break; } @@ -1607,12 +1812,14 @@ int main(int argc, char **argv) case 't': case '1': case '2': { - int dev_index = atoi(strtok(optarg, ":")); - int node_index = atoi(strtok(NULL, ":")); - enum CRAS_STREAM_DIRECTION dir; - cras_node_id_t id = cras_make_node_id(dev_index, - node_index); + cras_node_id_t id; + rc = parse_node_id(optarg, &id); + if (rc) { + show_usage(); + return rc; + } + enum CRAS_STREAM_DIRECTION dir; if (c == 't' || c == '2') dir = CRAS_STREAM_OUTPUT; else @@ -1641,7 +1848,7 @@ int main(int argc, char **argv) break; case 'p': printf("AEC group ID %d\n", - cras_client_get_aec_group_id(client)); + cras_client_get_aec_group_id(client)); break; case 'q': { int mute = atoi(optarg); @@ -1679,48 +1886,30 @@ int main(int argc, char **argv) } case ':': case 'w': { - const char *s; - int dev_index; - int node_index; + cras_node_id_t id; int value; - - s = strtok(optarg, ":"); - if (!s) { + rc = parse_node_id_with_value(optarg, &id, &value); + if (rc) { show_usage(); - return -EINVAL; + return rc; } - dev_index = atoi(s); - - s = strtok(NULL, ":"); - if (!s) { - show_usage(); - return -EINVAL; - } - node_index = atoi(s); - - s = strtok(NULL, ":"); - if (!s) { - show_usage(); - return -EINVAL; - } - value = atoi(s) ; - - cras_node_id_t id = cras_make_node_id(dev_index, - node_index); if (c == 'w') cras_client_set_node_volume(client, id, value); else - cras_client_set_node_capture_gain( - client, id, value); + cras_client_set_node_capture_gain(client, id, + value); break; } case 'x': { - int dev_index = atoi(strtok(optarg, ":")); - int node_index = atoi(strtok(NULL, ":")); - int value = atoi(strtok(NULL, ":")) ; - cras_node_id_t id = cras_make_node_id(dev_index, - node_index); + cras_node_id_t id; + int value; + rc = parse_node_id_with_value(optarg, &id, &value); + if (rc) { + show_usage(); + return rc; + } + enum ionode_attr attr = IONODE_ATTR_PLUGGED; cras_client_set_node_attr(client, id, attr, value); break; @@ -1739,11 +1928,14 @@ int main(int argc, char **argv) break; } case '3': { - int dev_index = atoi(strtok(optarg, ":")); - int node_index = atoi(strtok(NULL, ":")); - int value = atoi(strtok(NULL, ":")) ; - cras_node_id_t id = cras_make_node_id(dev_index, - node_index); + cras_node_id_t id; + int value; + rc = parse_node_id_with_value(optarg, &id, &value); + if (rc) { + show_usage(); + return rc; + } + cras_client_swap_node_left_right(client, id, value); break; } @@ -1755,12 +1947,25 @@ int main(int argc, char **argv) break; } case '6': { - int dev_index = atoi(strtok(optarg, ":")); + const char *s; + int dev_index; + + s = strtok(optarg, ":"); + if (!s) { + show_usage(); + return -EINVAL; + } + dev_index = atoi(s); + const char *file_name = strtok(NULL, ":"); - cras_client_test_iodev_command(client, dev_index, - TEST_IODEV_CMD_HOTWORD_TRIGGER, - strlen(file_name) + 1, - (uint8_t *)file_name); + if (!file_name) { + show_usage(); + return -EINVAL; + } + cras_client_test_iodev_command( + client, dev_index, + TEST_IODEV_CMD_HOTWORD_TRIGGER, + strlen(file_name) + 1, (uint8_t *)file_name); break; } case '7': { @@ -1790,8 +1995,7 @@ int main(int argc, char **argv) s = strtok(optarg, ":"); nch = atoi(s); - coeff = (float *)calloc(nch * nch, - sizeof(*coeff)); + coeff = (float *)calloc(nch * nch, sizeof(*coeff)); for (size = 0; size < nch * nch; size++) { s = strtok(NULL, ","); if (NULL == s) @@ -1829,8 +2033,8 @@ int main(int argc, char **argv) return -EINVAL; } - cras_node_id_t id = cras_make_node_id(dev_index, - node_index); + cras_node_id_t id = + cras_make_node_id(dev_index, node_index); if (c == '<') cras_client_set_hotword_model(client, id, s); else @@ -1882,6 +2086,30 @@ int main(int argc, char **argv) case 'I': cras_client_set_bt_wbs_enabled(client, atoi(optarg)); break; + case 'J': + cras_show_continuous_atlog(client); + break; + case 'K': + new_conn_type = atoi(optarg); + if (cras_validate_connection_type(new_conn_type)) { + if (new_conn_type != conn_type) { + cras_client_destroy(client); + client = NULL; + rc = cras_client_create_and_connect( + &client, new_conn_type); + if (rc) { + fprintf(stderr, + "Couldn't connect to " + "server.\n"); + return rc; + } + conn_type = new_conn_type; + } + } else { + printf("Input connection type is not " + "supported.\n"); + } + break; case 'L': loopback_file = optarg; break; @@ -1907,8 +2135,9 @@ int main(int argc, char **argv) if (capture_file != NULL) { if (strcmp(capture_file, "-") == 0) rc = run_file_io_stream(client, 1, CRAS_STREAM_INPUT, - block_size, stream_type, rate, format, - num_channels, stream_flags, 0, 0); + block_size, stream_type, rate, + format, num_channels, + stream_flags, 0, 0); else rc = run_capture(client, capture_file, block_size, stream_type, rate, format, @@ -1916,16 +2145,17 @@ int main(int argc, char **argv) } else if (playback_file != NULL) { if (strcmp(playback_file, "-") == 0) rc = run_file_io_stream(client, 0, CRAS_STREAM_OUTPUT, - block_size, stream_type, rate, format, - num_channels, stream_flags, 0, 0); + block_size, stream_type, rate, + format, num_channels, + stream_flags, 0, 0); else rc = run_playback(client, playback_file, block_size, stream_type, rate, format, num_channels); } else if (loopback_file != NULL) { - rc = run_capture(client, loopback_file, block_size, - stream_type, rate, format, num_channels, - stream_flags, 1, post_dsp); + rc = run_capture(client, loopback_file, block_size, stream_type, + rate, format, num_channels, stream_flags, 1, + post_dsp); } else if (aecdump_file != NULL) { run_aecdump(client, stream_id, 1); sleep(duration_seconds); diff --git a/scripts/audio_thread_log_viewer/README.md b/scripts/audio_thread_log_viewer/README.md new file mode 100644 index 00000000..7b2612d3 --- /dev/null +++ b/scripts/audio_thread_log_viewer/README.md @@ -0,0 +1,45 @@ +# Audio thread log viewer +It is a tool to draw a time chart from audio thread log. It can make debug +easier. + +[TOC] + +## Prepare an audio thread log +The easiest way to get audio thread log is typing `cras_test_client --dump_a` +in ChromeOS shell. + +The format should be like +``` +Audio Thread Event Log: +start at 4434i +2019-07-02T15:30:46.539479158 cras atlog SET_DEV_WAKE dev:7 hw_level:216 sleep:168 +2019-07-02T15:30:46.539482658 cras atlog DEV_SLEEP_TIME dev:7 wake: 15:30:46.542974324 +2019-07-02T15:30:46.539492991 cras atlog DEV_SLEEP_TIME dev:8 wake: 15:30:46.539358095 +2019-07-02T15:30:46.539501241 cras atlog SLEEP sleep:000000000.000000000 longest_wake:001553999 +... +``` + +## Generate an HTML file +``` +usage: viewer_c3.py [-h] [-o OUTPUT] [-d] FILE + +Draw time chart from audio thread log + +positional arguments: + FILE The audio thread log file + +optional arguments: + -h, --help show this help message and exit + -o OUTPUT The output HTML file (default: view.html) + -d Show debug message (default: False) +``` + +## View the result +Open the output from vierwe_c3.py by Chrome. There are several functions in +this site: ++ The blue points show the hardware level change of the audio thread logs. + Click a point can jump to a corresponding line in the log area. ++ There are some options can be selected. It can show the event in the chart + so that users can easily see when a stream is added, when a stream is fetched + , and so on. ++ The textarea in the lower right corner can be used to note. diff --git a/scripts/audio_thread_log_viewer/example.html b/scripts/audio_thread_log_viewer/example.html new file mode 100644 index 00000000..2fd7c9c7 --- /dev/null +++ b/scripts/audio_thread_log_viewer/example.html @@ -0,0 +1,783 @@ + +<html meta charset="UTF8"> +<head> + <!-- Load c3.css --> + <link href="https://rawgit.com/masayuki0812/c3/master/c3.css" rel="stylesheet" type="text/css"> + <!-- Load d3.js and c3.js --> + <script src="https://d3js.org/d3.v4.min.js" charset="utf-8"></script> + <script src="https://rawgit.com/masayuki0812/c3/master/c3.js" charset="utf-8"></script> + <style type="text/css"> + .c3-grid text { + fill: grey; + } + .event_log_box { + font-family: 'Courier New', Courier, 'Lucida Sans Typewriter', 'Lucida Typewriter', monospace; + font-size: 20px; + font-style: normal; + font-variant: normal; + font-weight: 300; + line-height: 26.4px; + white-space: pre; + height:50%; + width:48%; + border:1px solid #ccc; + overflow:auto; + } + .checkbox { + font-size: 30px; + border: 2px; + } + .device { + font-size: 15px; + } + .stream{ + font-size: 15px; + } + .fetch{ + } + .wake{ + } + </style> + <script type="text/javascript"> + var selected = null; + draw_chart = function() { + var chart = c3.generate({ + data: { + x: 'time', + columns: [ + ['time', 38274.654909156, 38274.657371167, 38274.657668959, 38274.676688159, 38274.676725281, 38274.676926906, 38274.677252890, 38274.697879928, 38274.697916480, 38274.698114806, 38274.698417024, 38274.719199290, 38274.719236981, 38274.719359698, 38274.719663005, 38274.740686503, 38274.740723661, 38274.740850997, 38274.741173582, 38274.762025805, 38274.762062690, 38274.762153748, 38274.762452548, 38274.783326364, 38274.783362532, 38274.783489920, 38274.783790725, 38274.804671376, 38274.804708721, 38274.804838233, 38274.805159078, 38274.826024162, 38274.826062337, 38274.826152748, 38274.826451927, 38274.847346397, 38274.847382560, 38274.847510294, 38274.847815798, 38274.868739650, 38274.868776554, 38274.868889760, 38274.869207769, 38274.890021859, 38274.890059702, 38274.890149892, 38274.890446925, 38274.911642356, 38274.911677780, 38274.911875825, 38274.912200713, 38274.932637511, 38274.932673739, 38274.932804355, 38274.933129716, 38274.954030314, 38274.954067674, 38274.954159335, 38274.954466654, 38274.975643692, 38274.975680354, 38274.975807387, 38274.976120622, 38274.996667671, 38274.996704048, 38274.996833804, 38274.997146185, 38275.017877797, 38275.017914904, 38275.018030670, 38275.018320047, 38275.039145228, 38275.039181369, 38275.039303282, 38275.039595139, 38275.060732607, 38275.060769291, 38275.060896906, 38275.061209809, 38275.082027553, 38275.082064736, 38275.082153665, 38275.082440331, 38275.103326735, 38275.103362951, 38275.103561185, 38275.103915541, 38275.124657946, 38275.124694671, 38275.124818548, 38275.125130858, 38275.146029029, 38275.146065845, 38275.146157000, 38275.146444659, 38275.167643000, 38275.167679011, 38275.167806856, 38275.168119122, 38275.188729928, 38275.188766573, 38275.188894276, 38275.189205852, 38275.210020752, 38275.210058744, 38275.210148466, 38275.210434597], + ['buffer_level', null, 928, 1952, 1040, 1040, 1040, 2016, 1056, 1056, 1008, 2032, 1024, 1024, 1024, 2048, 1040, 1040, 1040, 2016, 1008, 1008, 1008, 2032, 1024, 1024, 1024, 2048, 1040, 1040, 1040, 2016, 1008, 1008, 1008, 2032, 1024, 1024, 1024, 2048, 1040, 1040, 1040, 2016, 1008, 1008, 1008, 2032, 1024, 1024, 1024, 2000, 1040, 1040, 1040, 2016, 1008, 1008, 1008, 2032, 1024, 1024, 1024, 2000, 1040, 1040, 1040, 2016, 1056, 1056, 1008, 2032, 1024, 1024, 1024, 2048, 1040, 1040, 1040, 2016, 1008, 1008, 1008, 2032, 1024, 1024, 1024, 2048, 1040, 1040, 1040, 2016, 1008, 1008, 1008, 2032, 1024, 1024, 1024, 2000, 1040, 1040, 1040, 2016, 1008, 1008, 1008, 2032], + ], + type: 'bar', + types: { + buffer_level: 'line', + }, + onclick: function (d, i) { + elm = document.getElementById(d.x.toFixed(9)); + if (selected) + selected.style.color = ''; + if (elm === null) { + console.error("Can not find element by ID %s", d.x.toFixed(9)); + return; + } + elm.style.color = 'blue'; + elm.scrollIntoView(); + selected = elm; + }, + }, + zoom: { + enabled: true, + }, + + grid: { + x: { + lines: [ + {value: 38274.654888011, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38274.654909156, text: "Added Device 6", position: "start", class: "device"}, {value: 38274.654958862, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38274.655022911, text: "Add stream 1d0000", position: "middle", class: "stream"}, {value: 38274.655046329, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38274.656503188, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38274.676639948, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38274.676860551, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38274.697833022, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38274.698048577, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38274.719153430, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38274.719301220, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38274.740639477, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38274.740793102, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38274.761962963, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38274.762102057, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38274.783277641, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38274.783432165, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38274.804623390, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38274.804780617, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38274.825958417, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38274.826100424, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38274.847298285, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38274.847453266, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38274.868691938, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38274.868834120, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38274.889955591, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38274.890097300, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38274.911593780, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38274.911810046, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38274.932589800, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38274.932746675, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38274.953964062, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38274.954106963, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38274.975595442, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38274.975750291, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38274.996619059, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38274.996775539, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38275.017830417, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38275.017961913, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38275.039099808, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38275.039242696, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38275.060684606, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38275.060839575, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38275.081962397, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38275.082101703, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38275.103278902, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38275.103495004, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38275.124610042, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38275.124760504, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38275.145964152, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38275.146104176, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38275.167594886, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38275.167749677, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38275.188682360, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38275.188837092, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38275.209955429, text: "Fetch 1d0000", position: "end", class: "fetch"}, {value: 38275.210096165, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38275.222778298, text: "num_fds 1", position: "middle", class: "wake"}, {value: 38275.222796197, text: "Remove stream 1d0000", position: "middle", class: "stream"}, + ], + }, + }, + + axis: { + y: {min: 0, max: 2048}, + }, + }); + }; + + logs = `Audio Debug Stats: +-------------devices------------ +Output dev: kbl_r5514_5663_max: :0,0 +buffer_size: 16384 +min_buffer_level: 0 +min_cb_level: 8192 +max_cb_level: 0 +frame_rate: 48000 +num_channels: 2 +est_rate_ratio: 1.000000 +num_underruns: 0 +num_severe_underruns: 0 +highest_hw_level: 2048 +runtime: 2.148581272 +software_gain_scaler: 0.000000 + +-------------stream_dump------------ +Audio Thread Event Log: +start at 2874 +<label id="38204.803651654">2019-08-19T10:36:44.803651654 cras atlog SLEEP sleep:000000000.000000000 longest_wake:001565104</label> +<label id="38274.654888011">2019-08-19T10:37:54.654888011 cras atlog WAKE num_fds:1</label> +<label id="38274.654901579">2019-08-19T10:37:54.654901579 cras atlog PB_MSG msg_id:0</label> +<label id="38274.654906341">2019-08-19T10:37:54.654906341 cras atlog FILL_ODEV_ZEROS dev:6 write:0</label> +<label id="38274.654909156">2019-08-19T10:37:54.654909156 cras atlog DEV_ADDED dev:6</label> +<label id="38274.654950513">2019-08-19T10:37:54.654950513 cras atlog SLEEP sleep:000000000.000000000 longest_wake:001565104</label> +<label id="38274.654958862">2019-08-19T10:37:54.654958862 cras atlog WAKE num_fds:1</label> +<label id="38274.654966799">2019-08-19T10:37:54.654966799 cras atlog PB_MSG msg_id:3</label> +<label id="38274.654969277">2019-08-19T10:37:54.654969277 cras atlog WRITE_STREAMS_WAIT stream:1d0000</label> +<label id="38274.655022911">2019-08-19T10:37:54.655022911 cras atlog STREAM_ADDED id:1d0000 dev:6</label> +<label id="38274.655046329">2019-08-19T10:37:54.655046329 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:288</label> +<label id="38274.655069609">2019-08-19T10:37:54.655069609 cras atlog SLEEP sleep:000000000.000000000 longest_wake:001565104</label> +<label id="38274.656503188">2019-08-19T10:37:54.656503188 cras atlog WAKE num_fds:1</label> +<label id="38274.656538337">2019-08-19T10:37:54.656538337 cras atlog FILL_ODEV_ZEROS dev:6 write:1024</label> +<label id="38274.656869440">2019-08-19T10:37:54.656869440 cras atlog ODEV_START dev:6 min_cb_level:1024</label> +<label id="38274.657368663">2019-08-19T10:37:54.657368663 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.657365837</label> +<label id="38274.657371167">2019-08-19T10:37:54.657371167 cras atlog FILL_AUDIO dev:6 hw_level:928</label> +<label id="38274.657376118">2019-08-19T10:37:54.657376118 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38274.657385868">2019-08-19T10:37:54.657385868 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38274.657395667">2019-08-19T10:37:54.657395667 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38274.657398033">2019-08-19T10:37:54.657398033 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38274.657646876">2019-08-19T10:37:54.657646876 cras atlog FILL_AUDIO_DONE hw_level:928 total_written:1024 min_cb_level:1024</label> +<label id="38274.657668959">2019-08-19T10:37:54.657668959 cras atlog SET_DEV_WAKE dev:6 hw_level:1952 sleep:1904</label> +<label id="38274.657671042">2019-08-19T10:37:54.657671042 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.697332693</label> +<label id="38274.657676157">2019-08-19T10:37:54.657676157 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:54.676321391</label> +<label id="38274.657680973">2019-08-19T10:37:54.657680973 cras atlog SLEEP sleep:000000000.018647412 longest_wake:001565104</label> +<label id="38274.676595788">2019-08-19T10:37:54.676595788 cras atlog WAKE num_fds:0</label> +<label id="38274.676639948">2019-08-19T10:37:54.676639948 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:1328</label> +<label id="38274.676685281">2019-08-19T10:37:54.676685281 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.676683159</label> +<label id="38274.676688159">2019-08-19T10:37:54.676688159 cras atlog FILL_AUDIO dev:6 hw_level:1040</label> +<label id="38274.676694319">2019-08-19T10:37:54.676694319 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:1</label> +<label id="38274.676696512">2019-08-19T10:37:54.676696512 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38274.676699365">2019-08-19T10:37:54.676699365 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38274.676705462">2019-08-19T10:37:54.676705462 cras atlog FILL_AUDIO_DONE hw_level:1040 total_written:0 min_cb_level:1024</label> +<label id="38274.676725281">2019-08-19T10:37:54.676725281 cras atlog SET_DEV_WAKE dev:6 hw_level:1040 sleep:992</label> +<label id="38274.676727345">2019-08-19T10:37:54.676727345 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.697389256</label> +<label id="38274.676734968">2019-08-19T10:37:54.676734968 cras atlog SLEEP sleep:000000000.020659324 longest_wake:001565104</label> +<label id="38274.676860551">2019-08-19T10:37:54.676860551 cras atlog WAKE num_fds:1</label> +<label id="38274.676924328">2019-08-19T10:37:54.676924328 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.676922156</label> +<label id="38274.676926906">2019-08-19T10:37:54.676926906 cras atlog FILL_AUDIO dev:6 hw_level:1040</label> +<label id="38274.676931349">2019-08-19T10:37:54.676931349 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38274.676943036">2019-08-19T10:37:54.676943036 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38274.676953027">2019-08-19T10:37:54.676953027 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38274.676955453">2019-08-19T10:37:54.676955453 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38274.677231898">2019-08-19T10:37:54.677231898 cras atlog FILL_AUDIO_DONE hw_level:1040 total_written:1024 min_cb_level:1024</label> +<label id="38274.677252890">2019-08-19T10:37:54.677252890 cras atlog SET_DEV_WAKE dev:6 hw_level:2016 sleep:1968</label> +<label id="38274.677254980">2019-08-19T10:37:54.677254980 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.718250167</label> +<label id="38274.677259823">2019-08-19T10:37:54.677259823 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:54.697654724</label> +<label id="38274.677264536">2019-08-19T10:37:54.677264536 cras atlog SLEEP sleep:000000000.020396980 longest_wake:001565104</label> +<label id="38274.697789394">2019-08-19T10:37:54.697789394 cras atlog WAKE num_fds:0</label> +<label id="38274.697833022">2019-08-19T10:37:54.697833022 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:1344</label> +<label id="38274.697876956">2019-08-19T10:37:54.697876956 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.697874846</label> +<label id="38274.697879928">2019-08-19T10:37:54.697879928 cras atlog FILL_AUDIO dev:6 hw_level:1056</label> +<label id="38274.697885964">2019-08-19T10:37:54.697885964 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:1</label> +<label id="38274.697888192">2019-08-19T10:37:54.697888192 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38274.697891024">2019-08-19T10:37:54.697891024 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38274.697897003">2019-08-19T10:37:54.697897003 cras atlog FILL_AUDIO_DONE hw_level:1056 total_written:0 min_cb_level:1024</label> +<label id="38274.697916480">2019-08-19T10:37:54.697916480 cras atlog SET_DEV_WAKE dev:6 hw_level:1056 sleep:1008</label> +<label id="38274.697918569">2019-08-19T10:37:54.697918569 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.718913723</label> +<label id="38274.697926449">2019-08-19T10:37:54.697926449 cras atlog SLEEP sleep:000000000.020992361 longest_wake:001565104</label> +<label id="38274.698048577">2019-08-19T10:37:54.698048577 cras atlog WAKE num_fds:1</label> +<label id="38274.698112219">2019-08-19T10:37:54.698112219 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.698110036</label> +<label id="38274.698114806">2019-08-19T10:37:54.698114806 cras atlog FILL_AUDIO dev:6 hw_level:1008</label> +<label id="38274.698119339">2019-08-19T10:37:54.698119339 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38274.698133295">2019-08-19T10:37:54.698133295 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38274.698138449">2019-08-19T10:37:54.698138449 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38274.698140835">2019-08-19T10:37:54.698140835 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38274.698396787">2019-08-19T10:37:54.698396787 cras atlog FILL_AUDIO_DONE hw_level:1008 total_written:1024 min_cb_level:1024</label> +<label id="38274.698417024">2019-08-19T10:37:54.698417024 cras atlog SET_DEV_WAKE dev:6 hw_level:2032 sleep:1984</label> +<label id="38274.698419100">2019-08-19T10:37:54.698419100 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.739747637</label> +<label id="38274.698423907">2019-08-19T10:37:54.698423907 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:54.718988057</label> +<label id="38274.698428623">2019-08-19T10:37:54.698428623 cras atlog SLEEP sleep:000000000.020566258 longest_wake:001565104</label> +<label id="38274.719109903">2019-08-19T10:37:54.719109903 cras atlog WAKE num_fds:0</label> +<label id="38274.719153430">2019-08-19T10:37:54.719153430 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:1312</label> +<label id="38274.719196387">2019-08-19T10:37:54.719196387 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.719194274</label> +<label id="38274.719199290">2019-08-19T10:37:54.719199290 cras atlog FILL_AUDIO dev:6 hw_level:1024</label> +<label id="38274.719205301">2019-08-19T10:37:54.719205301 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:1</label> +<label id="38274.719207458">2019-08-19T10:37:54.719207458 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38274.719210354">2019-08-19T10:37:54.719210354 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38274.719216842">2019-08-19T10:37:54.719216842 cras atlog FILL_AUDIO_DONE hw_level:1024 total_written:0 min_cb_level:1024</label> +<label id="38274.719236981">2019-08-19T10:37:54.719236981 cras atlog SET_DEV_WAKE dev:6 hw_level:1024 sleep:976</label> +<label id="38274.719239068">2019-08-19T10:37:54.719239068 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.739567597</label> +<label id="38274.719246952">2019-08-19T10:37:54.719246952 cras atlog SLEEP sleep:000000000.020325687 longest_wake:001565104</label> +<label id="38274.719301220">2019-08-19T10:37:54.719301220 cras atlog WAKE num_fds:1</label> +<label id="38274.719357382">2019-08-19T10:37:54.719357382 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.719355237</label> +<label id="38274.719359698">2019-08-19T10:37:54.719359698 cras atlog FILL_AUDIO dev:6 hw_level:1024</label> +<label id="38274.719362947">2019-08-19T10:37:54.719362947 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38274.719377071">2019-08-19T10:37:54.719377071 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38274.719382615">2019-08-19T10:37:54.719382615 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38274.719384824">2019-08-19T10:37:54.719384824 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38274.719643101">2019-08-19T10:37:54.719643101 cras atlog FILL_AUDIO_DONE hw_level:1024 total_written:1024 min_cb_level:1024</label> +<label id="38274.719663005">2019-08-19T10:37:54.719663005 cras atlog SET_DEV_WAKE dev:6 hw_level:2048 sleep:2000</label> +<label id="38274.719664987">2019-08-19T10:37:54.719664987 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.761327047</label> +<label id="38274.719669473">2019-08-19T10:37:54.719669473 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:54.740321390</label> +<label id="38274.719673899">2019-08-19T10:37:54.719673899 cras atlog SLEEP sleep:000000000.020654025 longest_wake:001565104</label> +<label id="38274.740595499">2019-08-19T10:37:54.740595499 cras atlog WAKE num_fds:0</label> +<label id="38274.740639477">2019-08-19T10:37:54.740639477 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:1328</label> +<label id="38274.740683615">2019-08-19T10:37:54.740683615 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.740681512</label> +<label id="38274.740686503">2019-08-19T10:37:54.740686503 cras atlog FILL_AUDIO dev:6 hw_level:1040</label> +<label id="38274.740692464">2019-08-19T10:37:54.740692464 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:1</label> +<label id="38274.740694600">2019-08-19T10:37:54.740694600 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38274.740697433">2019-08-19T10:37:54.740697433 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38274.740703643">2019-08-19T10:37:54.740703643 cras atlog FILL_AUDIO_DONE hw_level:1040 total_written:0 min_cb_level:1024</label> +<label id="38274.740723661">2019-08-19T10:37:54.740723661 cras atlog SET_DEV_WAKE dev:6 hw_level:1040 sleep:992</label> +<label id="38274.740725763">2019-08-19T10:37:54.740725763 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.761387612</label> +<label id="38274.740733471">2019-08-19T10:37:54.740733471 cras atlog SLEEP sleep:000000000.020659319 longest_wake:001565104</label> +<label id="38274.740793102">2019-08-19T10:37:54.740793102 cras atlog WAKE num_fds:1</label> +<label id="38274.740848639">2019-08-19T10:37:54.740848639 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.740846573</label> +<label id="38274.740850997">2019-08-19T10:37:54.740850997 cras atlog FILL_AUDIO dev:6 hw_level:1040</label> +<label id="38274.740854311">2019-08-19T10:37:54.740854311 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38274.740868736">2019-08-19T10:37:54.740868736 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38274.740873892">2019-08-19T10:37:54.740873892 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38274.740875997">2019-08-19T10:37:54.740875997 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38274.741153121">2019-08-19T10:37:54.741153121 cras atlog FILL_AUDIO_DONE hw_level:1040 total_written:1024 min_cb_level:1024</label> +<label id="38274.741173582">2019-08-19T10:37:54.741173582 cras atlog SET_DEV_WAKE dev:6 hw_level:2016 sleep:1968</label> +<label id="38274.741175606">2019-08-19T10:37:54.741175606 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.782171115</label> +<label id="38274.741180302">2019-08-19T10:37:54.741180302 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:54.761654723</label> +<label id="38274.741184669">2019-08-19T10:37:54.741184669 cras atlog SLEEP sleep:000000000.020476747 longest_wake:001565104</label> +<label id="38274.761922026">2019-08-19T10:37:54.761922026 cras atlog WAKE num_fds:0</label> +<label id="38274.761962963">2019-08-19T10:37:54.761962963 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:1344</label> +<label id="38274.762022826">2019-08-19T10:37:54.762022826 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.762020513</label> +<label id="38274.762025805">2019-08-19T10:37:54.762025805 cras atlog FILL_AUDIO dev:6 hw_level:1008</label> +<label id="38274.762031594">2019-08-19T10:37:54.762031594 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:1</label> +<label id="38274.762033738">2019-08-19T10:37:54.762033738 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38274.762036536">2019-08-19T10:37:54.762036536 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38274.762042425">2019-08-19T10:37:54.762042425 cras atlog FILL_AUDIO_DONE hw_level:1008 total_written:0 min_cb_level:1024</label> +<label id="38274.762062690">2019-08-19T10:37:54.762062690 cras atlog SET_DEV_WAKE dev:6 hw_level:1008 sleep:960</label> +<label id="38274.762065186">2019-08-19T10:37:54.762065186 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.782060173</label> +<label id="38274.762072982">2019-08-19T10:37:54.762072982 cras atlog SLEEP sleep:000000000.019992102 longest_wake:001565104</label> +<label id="38274.762102057">2019-08-19T10:37:54.762102057 cras atlog WAKE num_fds:1</label> +<label id="38274.762151699">2019-08-19T10:37:54.762151699 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.762149704</label> +<label id="38274.762153748">2019-08-19T10:37:54.762153748 cras atlog FILL_AUDIO dev:6 hw_level:1008</label> +<label id="38274.762156523">2019-08-19T10:37:54.762156523 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38274.762170916">2019-08-19T10:37:54.762170916 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38274.762175916">2019-08-19T10:37:54.762175916 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38274.762178058">2019-08-19T10:37:54.762178058 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38274.762432618">2019-08-19T10:37:54.762432618 cras atlog FILL_AUDIO_DONE hw_level:1008 total_written:1024 min_cb_level:1024</label> +<label id="38274.762452548">2019-08-19T10:37:54.762452548 cras atlog SET_DEV_WAKE dev:6 hw_level:2032 sleep:1984</label> +<label id="38274.762454582">2019-08-19T10:37:54.762454582 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.803783385</label> +<label id="38274.762458984">2019-08-19T10:37:54.762458984 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:54.782988056</label> +<label id="38274.762463390">2019-08-19T10:37:54.762463390 cras atlog SLEEP sleep:000000000.020531186 longest_wake:001565104</label> +<label id="38274.783234058">2019-08-19T10:37:54.783234058 cras atlog WAKE num_fds:0</label> +<label id="38274.783277641">2019-08-19T10:37:54.783277641 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:1312</label> +<label id="38274.783323456">2019-08-19T10:37:54.783323456 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.783321345</label> +<label id="38274.783326364">2019-08-19T10:37:54.783326364 cras atlog FILL_AUDIO dev:6 hw_level:1024</label> +<label id="38274.783332069">2019-08-19T10:37:54.783332069 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:1</label> +<label id="38274.783334227">2019-08-19T10:37:54.783334227 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38274.783337045">2019-08-19T10:37:54.783337045 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38274.783343042">2019-08-19T10:37:54.783343042 cras atlog FILL_AUDIO_DONE hw_level:1024 total_written:0 min_cb_level:1024</label> +<label id="38274.783362532">2019-08-19T10:37:54.783362532 cras atlog SET_DEV_WAKE dev:6 hw_level:1024 sleep:976</label> +<label id="38274.783364628">2019-08-19T10:37:54.783364628 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.803693148</label> +<label id="38274.783372345">2019-08-19T10:37:54.783372345 cras atlog SLEEP sleep:000000000.020325873 longest_wake:001565104</label> +<label id="38274.783432165">2019-08-19T10:37:54.783432165 cras atlog WAKE num_fds:1</label> +<label id="38274.783487514">2019-08-19T10:37:54.783487514 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.783485428</label> +<label id="38274.783489920">2019-08-19T10:37:54.783489920 cras atlog FILL_AUDIO dev:6 hw_level:1024</label> +<label id="38274.783493117">2019-08-19T10:37:54.783493117 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38274.783507178">2019-08-19T10:37:54.783507178 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38274.783512206">2019-08-19T10:37:54.783512206 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38274.783514361">2019-08-19T10:37:54.783514361 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38274.783772851">2019-08-19T10:37:54.783772851 cras atlog FILL_AUDIO_DONE hw_level:1024 total_written:1024 min_cb_level:1024</label> +<label id="38274.783790725">2019-08-19T10:37:54.783790725 cras atlog SET_DEV_WAKE dev:6 hw_level:2048 sleep:2000</label> +<label id="38274.783792763">2019-08-19T10:37:54.783792763 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.825454687</label> +<label id="38274.783797423">2019-08-19T10:37:54.783797423 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:54.804321389</label> +<label id="38274.783801803">2019-08-19T10:37:54.783801803 cras atlog SLEEP sleep:000000000.020526265 longest_wake:001565104</label> +<label id="38274.804579013">2019-08-19T10:37:54.804579013 cras atlog WAKE num_fds:0</label> +<label id="38274.804623390">2019-08-19T10:37:54.804623390 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:1328</label> +<label id="38274.804668478">2019-08-19T10:37:54.804668478 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.804666367</label> +<label id="38274.804671376">2019-08-19T10:37:54.804671376 cras atlog FILL_AUDIO dev:6 hw_level:1040</label> +<label id="38274.804677338">2019-08-19T10:37:54.804677338 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:1</label> +<label id="38274.804679504">2019-08-19T10:37:54.804679504 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38274.804682310">2019-08-19T10:37:54.804682310 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38274.804688741">2019-08-19T10:37:54.804688741 cras atlog FILL_AUDIO_DONE hw_level:1040 total_written:0 min_cb_level:1024</label> +<label id="38274.804708721">2019-08-19T10:37:54.804708721 cras atlog SET_DEV_WAKE dev:6 hw_level:1040 sleep:992</label> +<label id="38274.804710807">2019-08-19T10:37:54.804710807 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.825372685</label> +<label id="38274.804718659">2019-08-19T10:37:54.804718659 cras atlog SLEEP sleep:000000000.020659270 longest_wake:001565104</label> +<label id="38274.804780617">2019-08-19T10:37:54.804780617 cras atlog WAKE num_fds:1</label> +<label id="38274.804835890">2019-08-19T10:37:54.804835890 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.804833797</label> +<label id="38274.804838233">2019-08-19T10:37:54.804838233 cras atlog FILL_AUDIO dev:6 hw_level:1040</label> +<label id="38274.804841501">2019-08-19T10:37:54.804841501 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38274.804855352">2019-08-19T10:37:54.804855352 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38274.804860473">2019-08-19T10:37:54.804860473 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38274.804862636">2019-08-19T10:37:54.804862636 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38274.805138821">2019-08-19T10:37:54.805138821 cras atlog FILL_AUDIO_DONE hw_level:1040 total_written:1024 min_cb_level:1024</label> +<label id="38274.805159078">2019-08-19T10:37:54.805159078 cras atlog SET_DEV_WAKE dev:6 hw_level:2016 sleep:1968</label> +<label id="38274.805161124">2019-08-19T10:37:54.805161124 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.846156596</label> +<label id="38274.805165757">2019-08-19T10:37:54.805165757 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:54.825654722</label> +<label id="38274.805170306">2019-08-19T10:37:54.805170306 cras atlog SLEEP sleep:000000000.020491218 longest_wake:001565104</label> +<label id="38274.825913546">2019-08-19T10:37:54.825913546 cras atlog WAKE num_fds:0</label> +<label id="38274.825958417">2019-08-19T10:37:54.825958417 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:1344</label> +<label id="38274.826020986">2019-08-19T10:37:54.826020986 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.826018114</label> +<label id="38274.826024162">2019-08-19T10:37:54.826024162 cras atlog FILL_AUDIO dev:6 hw_level:1008</label> +<label id="38274.826030236">2019-08-19T10:37:54.826030236 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:1</label> +<label id="38274.826032511">2019-08-19T10:37:54.826032511 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38274.826035326">2019-08-19T10:37:54.826035326 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38274.826041230">2019-08-19T10:37:54.826041230 cras atlog FILL_AUDIO_DONE hw_level:1008 total_written:0 min_cb_level:1024</label> +<label id="38274.826062337">2019-08-19T10:37:54.826062337 cras atlog SET_DEV_WAKE dev:6 hw_level:1008 sleep:960</label> +<label id="38274.826064399">2019-08-19T10:37:54.826064399 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.846059769</label> +<label id="38274.826072024">2019-08-19T10:37:54.826072024 cras atlog SLEEP sleep:000000000.019992730 longest_wake:001565104</label> +<label id="38274.826100424">2019-08-19T10:37:54.826100424 cras atlog WAKE num_fds:1</label> +<label id="38274.826150628">2019-08-19T10:37:54.826150628 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.826148583</label> +<label id="38274.826152748">2019-08-19T10:37:54.826152748 cras atlog FILL_AUDIO dev:6 hw_level:1008</label> +<label id="38274.826155423">2019-08-19T10:37:54.826155423 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38274.826170179">2019-08-19T10:37:54.826170179 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38274.826175702">2019-08-19T10:37:54.826175702 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38274.826177885">2019-08-19T10:37:54.826177885 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38274.826431854">2019-08-19T10:37:54.826431854 cras atlog FILL_AUDIO_DONE hw_level:1008 total_written:1024 min_cb_level:1024</label> +<label id="38274.826451927">2019-08-19T10:37:54.826451927 cras atlog SET_DEV_WAKE dev:6 hw_level:2032 sleep:1984</label> +<label id="38274.826453912">2019-08-19T10:37:54.826453912 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.867782437</label> +<label id="38274.826458354">2019-08-19T10:37:54.826458354 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:54.846988055</label> +<label id="38274.826462711">2019-08-19T10:37:54.826462711 cras atlog SLEEP sleep:000000000.020531841 longest_wake:001565104</label> +<label id="38274.847254169">2019-08-19T10:37:54.847254169 cras atlog WAKE num_fds:0</label> +<label id="38274.847298285">2019-08-19T10:37:54.847298285 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:1312</label> +<label id="38274.847343532">2019-08-19T10:37:54.847343532 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.847341437</label> +<label id="38274.847346397">2019-08-19T10:37:54.847346397 cras atlog FILL_AUDIO dev:6 hw_level:1024</label> +<label id="38274.847352242">2019-08-19T10:37:54.847352242 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:1</label> +<label id="38274.847354402">2019-08-19T10:37:54.847354402 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38274.847357232">2019-08-19T10:37:54.847357232 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38274.847363049">2019-08-19T10:37:54.847363049 cras atlog FILL_AUDIO_DONE hw_level:1024 total_written:0 min_cb_level:1024</label> +<label id="38274.847382560">2019-08-19T10:37:54.847382560 cras atlog SET_DEV_WAKE dev:6 hw_level:1024 sleep:976</label> +<label id="38274.847384657">2019-08-19T10:37:54.847384657 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.867713298</label> +<label id="38274.847392466">2019-08-19T10:37:54.847392466 cras atlog SLEEP sleep:000000000.020325941 longest_wake:001565104</label> +<label id="38274.847453266">2019-08-19T10:37:54.847453266 cras atlog WAKE num_fds:1</label> +<label id="38274.847507893">2019-08-19T10:37:54.847507893 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.847505842</label> +<label id="38274.847510294">2019-08-19T10:37:54.847510294 cras atlog FILL_AUDIO dev:6 hw_level:1024</label> +<label id="38274.847513378">2019-08-19T10:37:54.847513378 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38274.847527509">2019-08-19T10:37:54.847527509 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38274.847532608">2019-08-19T10:37:54.847532608 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38274.847534792">2019-08-19T10:37:54.847534792 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38274.847794682">2019-08-19T10:37:54.847794682 cras atlog FILL_AUDIO_DONE hw_level:1024 total_written:1024 min_cb_level:1024</label> +<label id="38274.847815798">2019-08-19T10:37:54.847815798 cras atlog SET_DEV_WAKE dev:6 hw_level:2048 sleep:2000</label> +<label id="38274.847818230">2019-08-19T10:37:54.847818230 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.889479489</label> +<label id="38274.847822643">2019-08-19T10:37:54.847822643 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:54.868321388</label> +<label id="38274.847827174">2019-08-19T10:37:54.847827174 cras atlog SLEEP sleep:000000000.020500850 longest_wake:001565104</label> +<label id="38274.868647280">2019-08-19T10:37:54.868647280 cras atlog WAKE num_fds:0</label> +<label id="38274.868691938">2019-08-19T10:37:54.868691938 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:1328</label> +<label id="38274.868736756">2019-08-19T10:37:54.868736756 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.868734631</label> +<label id="38274.868739650">2019-08-19T10:37:54.868739650 cras atlog FILL_AUDIO dev:6 hw_level:1040</label> +<label id="38274.868745553">2019-08-19T10:37:54.868745553 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:1</label> +<label id="38274.868747712">2019-08-19T10:37:54.868747712 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38274.868750515">2019-08-19T10:37:54.868750515 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38274.868756826">2019-08-19T10:37:54.868756826 cras atlog FILL_AUDIO_DONE hw_level:1040 total_written:0 min_cb_level:1024</label> +<label id="38274.868776554">2019-08-19T10:37:54.868776554 cras atlog SET_DEV_WAKE dev:6 hw_level:1040 sleep:992</label> +<label id="38274.868778635">2019-08-19T10:37:54.868778635 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.889440503</label> +<label id="38274.868786877">2019-08-19T10:37:54.868786877 cras atlog SLEEP sleep:000000000.020658858 longest_wake:001565104</label> +<label id="38274.868834120">2019-08-19T10:37:54.868834120 cras atlog WAKE num_fds:1</label> +<label id="38274.868887396">2019-08-19T10:37:54.868887396 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.868885395</label> +<label id="38274.868889760">2019-08-19T10:37:54.868889760 cras atlog FILL_AUDIO dev:6 hw_level:1040</label> +<label id="38274.868892743">2019-08-19T10:37:54.868892743 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38274.868906663">2019-08-19T10:37:54.868906663 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38274.868911746">2019-08-19T10:37:54.868911746 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38274.868913920">2019-08-19T10:37:54.868913920 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38274.869187106">2019-08-19T10:37:54.869187106 cras atlog FILL_AUDIO_DONE hw_level:1040 total_written:1024 min_cb_level:1024</label> +<label id="38274.869207769">2019-08-19T10:37:54.869207769 cras atlog SET_DEV_WAKE dev:6 hw_level:2016 sleep:1968</label> +<label id="38274.869209841">2019-08-19T10:37:54.869209841 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.910204925</label> +<label id="38274.869214453">2019-08-19T10:37:54.869214453 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:54.889654721</label> +<label id="38274.869218854">2019-08-19T10:37:54.869218854 cras atlog SLEEP sleep:000000000.020442575 longest_wake:001565104</label> +<label id="38274.889911594">2019-08-19T10:37:54.889911594 cras atlog WAKE num_fds:0</label> +<label id="38274.889955591">2019-08-19T10:37:54.889955591 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:1344</label> +<label id="38274.890001028">2019-08-19T10:37:54.890001028 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.889998910</label> +<label id="38274.890021859">2019-08-19T10:37:54.890021859 cras atlog FILL_AUDIO dev:6 hw_level:1008</label> +<label id="38274.890028088">2019-08-19T10:37:54.890028088 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:1</label> +<label id="38274.890030382">2019-08-19T10:37:54.890030382 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38274.890033213">2019-08-19T10:37:54.890033213 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38274.890039166">2019-08-19T10:37:54.890039166 cras atlog FILL_AUDIO_DONE hw_level:1008 total_written:0 min_cb_level:1024</label> +<label id="38274.890059702">2019-08-19T10:37:54.890059702 cras atlog SET_DEV_WAKE dev:6 hw_level:1008 sleep:960</label> +<label id="38274.890061783">2019-08-19T10:37:54.890061783 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.910057166</label> +<label id="38274.890069206">2019-08-19T10:37:54.890069206 cras atlog SLEEP sleep:000000000.019992855 longest_wake:001565104</label> +<label id="38274.890097300">2019-08-19T10:37:54.890097300 cras atlog WAKE num_fds:1</label> +<label id="38274.890147785">2019-08-19T10:37:54.890147785 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.890145728</label> +<label id="38274.890149892">2019-08-19T10:37:54.890149892 cras atlog FILL_AUDIO dev:6 hw_level:1008</label> +<label id="38274.890152824">2019-08-19T10:37:54.890152824 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38274.890166719">2019-08-19T10:37:54.890166719 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38274.890171766">2019-08-19T10:37:54.890171766 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38274.890173949">2019-08-19T10:37:54.890173949 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38274.890427138">2019-08-19T10:37:54.890427138 cras atlog FILL_AUDIO_DONE hw_level:1008 total_written:1024 min_cb_level:1024</label> +<label id="38274.890446925">2019-08-19T10:37:54.890446925 cras atlog SET_DEV_WAKE dev:6 hw_level:2032 sleep:1984</label> +<label id="38274.890448924">2019-08-19T10:37:54.890448924 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.931777812</label> +<label id="38274.890453296">2019-08-19T10:37:54.890453296 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:54.910988054</label> +<label id="38274.890457622">2019-08-19T10:37:54.890457622 cras atlog SLEEP sleep:000000000.020536883 longest_wake:001565104</label> +<label id="38274.911549604">2019-08-19T10:37:54.911549604 cras atlog WAKE num_fds:0</label> +<label id="38274.911593780">2019-08-19T10:37:54.911593780 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:1312</label> +<label id="38274.911639463">2019-08-19T10:37:54.911639463 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.911637349</label> +<label id="38274.911642356">2019-08-19T10:37:54.911642356 cras atlog FILL_AUDIO dev:6 hw_level:1024</label> +<label id="38274.911648354">2019-08-19T10:37:54.911648354 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:1</label> +<label id="38274.911650495">2019-08-19T10:37:54.911650495 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38274.911653308">2019-08-19T10:37:54.911653308 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38274.911659036">2019-08-19T10:37:54.911659036 cras atlog FILL_AUDIO_DONE hw_level:1024 total_written:0 min_cb_level:1024</label> +<label id="38274.911677780">2019-08-19T10:37:54.911677780 cras atlog SET_DEV_WAKE dev:6 hw_level:1024 sleep:976</label> +<label id="38274.911679870">2019-08-19T10:37:54.911679870 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.932008544</label> +<label id="38274.911687437">2019-08-19T10:37:54.911687437 cras atlog SLEEP sleep:000000000.020326063 longest_wake:001565104</label> +<label id="38274.911810046">2019-08-19T10:37:54.911810046 cras atlog WAKE num_fds:1</label> +<label id="38274.911873260">2019-08-19T10:37:54.911873260 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.911871103</label> +<label id="38274.911875825">2019-08-19T10:37:54.911875825 cras atlog FILL_AUDIO dev:6 hw_level:1024</label> +<label id="38274.911880257">2019-08-19T10:37:54.911880257 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38274.911894516">2019-08-19T10:37:54.911894516 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38274.911899775">2019-08-19T10:37:54.911899775 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38274.911902141">2019-08-19T10:37:54.911902141 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38274.912179567">2019-08-19T10:37:54.912179567 cras atlog FILL_AUDIO_DONE hw_level:1024 total_written:1024 min_cb_level:1024</label> +<label id="38274.912200713">2019-08-19T10:37:54.912200713 cras atlog SET_DEV_WAKE dev:6 hw_level:2000 sleep:1952</label> +<label id="38274.912202795">2019-08-19T10:37:54.912202795 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.952864609</label> +<label id="38274.912207619">2019-08-19T10:37:54.912207619 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:54.932321387</label> +<label id="38274.912212340">2019-08-19T10:37:54.912212340 cras atlog SLEEP sleep:000000000.020115853 longest_wake:001565104</label> +<label id="38274.932544653">2019-08-19T10:37:54.932544653 cras atlog WAKE num_fds:0</label> +<label id="38274.932589800">2019-08-19T10:37:54.932589800 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:1328</label> +<label id="38274.932634557">2019-08-19T10:37:54.932634557 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.932632438</label> +<label id="38274.932637511">2019-08-19T10:37:54.932637511 cras atlog FILL_AUDIO dev:6 hw_level:1040</label> +<label id="38274.932643460">2019-08-19T10:37:54.932643460 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:1</label> +<label id="38274.932645626">2019-08-19T10:37:54.932645626 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38274.932648431">2019-08-19T10:37:54.932648431 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38274.932654361">2019-08-19T10:37:54.932654361 cras atlog FILL_AUDIO_DONE hw_level:1040 total_written:0 min_cb_level:1024</label> +<label id="38274.932673739">2019-08-19T10:37:54.932673739 cras atlog SET_DEV_WAKE dev:6 hw_level:1040 sleep:992</label> +<label id="38274.932675817">2019-08-19T10:37:54.932675817 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.953337688</label> +<label id="38274.932683307">2019-08-19T10:37:54.932683307 cras atlog SLEEP sleep:000000000.020659279 longest_wake:001565104</label> +<label id="38274.932746675">2019-08-19T10:37:54.932746675 cras atlog WAKE num_fds:1</label> +<label id="38274.932802037">2019-08-19T10:37:54.932802037 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.932799966</label> +<label id="38274.932804355">2019-08-19T10:37:54.932804355 cras atlog FILL_AUDIO dev:6 hw_level:1040</label> +<label id="38274.932807409">2019-08-19T10:37:54.932807409 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38274.932821550">2019-08-19T10:37:54.932821550 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38274.932826892">2019-08-19T10:37:54.932826892 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38274.932829082">2019-08-19T10:37:54.932829082 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38274.933108135">2019-08-19T10:37:54.933108135 cras atlog FILL_AUDIO_DONE hw_level:1040 total_written:1024 min_cb_level:1024</label> +<label id="38274.933129716">2019-08-19T10:37:54.933129716 cras atlog SET_DEV_WAKE dev:6 hw_level:2016 sleep:1968</label> +<label id="38274.933131709">2019-08-19T10:37:54.933131709 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.974126349</label> +<label id="38274.933136150">2019-08-19T10:37:54.933136150 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:54.953654720</label> +<label id="38274.933140489">2019-08-19T10:37:54.933140489 cras atlog SLEEP sleep:000000000.020520690 longest_wake:001565104</label> +<label id="38274.953927204">2019-08-19T10:37:54.953927204 cras atlog WAKE num_fds:0</label> +<label id="38274.953964062">2019-08-19T10:37:54.953964062 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:1296</label> +<label id="38274.954027217">2019-08-19T10:37:54.954027217 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.954024954</label> +<label id="38274.954030314">2019-08-19T10:37:54.954030314 cras atlog FILL_AUDIO dev:6 hw_level:1008</label> +<label id="38274.954036483">2019-08-19T10:37:54.954036483 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:1</label> +<label id="38274.954038676">2019-08-19T10:37:54.954038676 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38274.954041528">2019-08-19T10:37:54.954041528 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38274.954047105">2019-08-19T10:37:54.954047105 cras atlog FILL_AUDIO_DONE hw_level:1008 total_written:0 min_cb_level:1024</label> +<label id="38274.954067674">2019-08-19T10:37:54.954067674 cras atlog SET_DEV_WAKE dev:6 hw_level:1008 sleep:960</label> +<label id="38274.954069771">2019-08-19T10:37:54.954069771 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.974064924</label> +<label id="38274.954077360">2019-08-19T10:37:54.954077360 cras atlog SLEEP sleep:000000000.019992481 longest_wake:001565104</label> +<label id="38274.954106963">2019-08-19T10:37:54.954106963 cras atlog WAKE num_fds:1</label> +<label id="38274.954157230">2019-08-19T10:37:54.954157230 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.954155178</label> +<label id="38274.954159335">2019-08-19T10:37:54.954159335 cras atlog FILL_AUDIO dev:6 hw_level:1008</label> +<label id="38274.954162037">2019-08-19T10:37:54.954162037 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38274.954177049">2019-08-19T10:37:54.954177049 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38274.954182292">2019-08-19T10:37:54.954182292 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38274.954184412">2019-08-19T10:37:54.954184412 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38274.954439987">2019-08-19T10:37:54.954439987 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:0</label> +<label id="38274.954442042">2019-08-19T10:37:54.954442042 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38274.954444204">2019-08-19T10:37:54.954444204 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38274.954446985">2019-08-19T10:37:54.954446985 cras atlog FILL_AUDIO_DONE hw_level:1008 total_written:1024 min_cb_level:1024</label> +<label id="38274.954466654">2019-08-19T10:37:54.954466654 cras atlog SET_DEV_WAKE dev:6 hw_level:2032 sleep:1984</label> +<label id="38274.954468696">2019-08-19T10:37:54.954468696 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.995797668</label> +<label id="38274.954473224">2019-08-19T10:37:54.954473224 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:54.974988053</label> +<label id="38274.954477555">2019-08-19T10:37:54.954477555 cras atlog SLEEP sleep:000000000.020517058 longest_wake:001565104</label> +<label id="38274.975550997">2019-08-19T10:37:54.975550997 cras atlog WAKE num_fds:0</label> +<label id="38274.975595442">2019-08-19T10:37:54.975595442 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:1312</label> +<label id="38274.975640808">2019-08-19T10:37:54.975640808 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.975638709</label> +<label id="38274.975643692">2019-08-19T10:37:54.975643692 cras atlog FILL_AUDIO dev:6 hw_level:1024</label> +<label id="38274.975649536">2019-08-19T10:37:54.975649536 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:1</label> +<label id="38274.975651738">2019-08-19T10:37:54.975651738 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38274.975654643">2019-08-19T10:37:54.975654643 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38274.975660861">2019-08-19T10:37:54.975660861 cras atlog FILL_AUDIO_DONE hw_level:1024 total_written:0 min_cb_level:1024</label> +<label id="38274.975680354">2019-08-19T10:37:54.975680354 cras atlog SET_DEV_WAKE dev:6 hw_level:1024 sleep:976</label> +<label id="38274.975682447">2019-08-19T10:37:54.975682447 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:54.996011143</label> +<label id="38274.975690215">2019-08-19T10:37:54.975690215 cras atlog SLEEP sleep:000000000.020326081 longest_wake:001565104</label> +<label id="38274.975750291">2019-08-19T10:37:54.975750291 cras atlog WAKE num_fds:1</label> +<label id="38274.975805101">2019-08-19T10:37:54.975805101 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.975802996</label> +<label id="38274.975807387">2019-08-19T10:37:54.975807387 cras atlog FILL_AUDIO dev:6 hw_level:1024</label> +<label id="38274.975810666">2019-08-19T10:37:54.975810666 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38274.975813858">2019-08-19T10:37:54.975813858 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38274.975818840">2019-08-19T10:37:54.975818840 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38274.975820997">2019-08-19T10:37:54.975820997 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38274.976100465">2019-08-19T10:37:54.976100465 cras atlog FILL_AUDIO_DONE hw_level:1024 total_written:1024 min_cb_level:1024</label> +<label id="38274.976120622">2019-08-19T10:37:54.976120622 cras atlog SET_DEV_WAKE dev:6 hw_level:2000 sleep:1952</label> +<label id="38274.976122691">2019-08-19T10:37:54.976122691 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:55.016784703</label> +<label id="38274.976127066">2019-08-19T10:37:54.976127066 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:54.996321386</label> +<label id="38274.976131378">2019-08-19T10:37:54.976131378 cras atlog SLEEP sleep:000000000.020196437 longest_wake:001565104</label> +<label id="38274.996575651">2019-08-19T10:37:54.996575651 cras atlog WAKE num_fds:0</label> +<label id="38274.996619059">2019-08-19T10:37:54.996619059 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:1328</label> +<label id="38274.996664756">2019-08-19T10:37:54.996664756 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.996662645</label> +<label id="38274.996667671">2019-08-19T10:37:54.996667671 cras atlog FILL_AUDIO dev:6 hw_level:1040</label> +<label id="38274.996673482">2019-08-19T10:37:54.996673482 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:1</label> +<label id="38274.996675649">2019-08-19T10:37:54.996675649 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38274.996678438">2019-08-19T10:37:54.996678438 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38274.996684371">2019-08-19T10:37:54.996684371 cras atlog FILL_AUDIO_DONE hw_level:1040 total_written:0 min_cb_level:1024</label> +<label id="38274.996704048">2019-08-19T10:37:54.996704048 cras atlog SET_DEV_WAKE dev:6 hw_level:1040 sleep:992</label> +<label id="38274.996706108">2019-08-19T10:37:54.996706108 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:55.017368028</label> +<label id="38274.996713503">2019-08-19T10:37:54.996713503 cras atlog SLEEP sleep:000000000.020659377 longest_wake:001565104</label> +<label id="38274.996775539">2019-08-19T10:37:54.996775539 cras atlog WAKE num_fds:1</label> +<label id="38274.996831459">2019-08-19T10:37:54.996831459 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:54.996829346</label> +<label id="38274.996833804">2019-08-19T10:37:54.996833804 cras atlog FILL_AUDIO dev:6 hw_level:1040</label> +<label id="38274.996837127">2019-08-19T10:37:54.996837127 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38274.996840252">2019-08-19T10:37:54.996840252 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38274.996845333">2019-08-19T10:37:54.996845333 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38274.996847487">2019-08-19T10:37:54.996847487 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38274.997125727">2019-08-19T10:37:54.997125727 cras atlog FILL_AUDIO_DONE hw_level:1040 total_written:1024 min_cb_level:1024</label> +<label id="38274.997146185">2019-08-19T10:37:54.997146185 cras atlog SET_DEV_WAKE dev:6 hw_level:2016 sleep:1968</label> +<label id="38274.997148232">2019-08-19T10:37:54.997148232 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:55.038143682</label> +<label id="38274.997152901">2019-08-19T10:37:54.997152901 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:55.017654719</label> +<label id="38274.997157330">2019-08-19T10:37:54.997157330 cras atlog SLEEP sleep:000000000.020504113 longest_wake:001565104</label> +<label id="38275.017787246">2019-08-19T10:37:55.017787246 cras atlog WAKE num_fds:0</label> +<label id="38275.017830417">2019-08-19T10:37:55.017830417 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:1344</label> +<label id="38275.017874949">2019-08-19T10:37:55.017874949 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:55.017872854</label> +<label id="38275.017877797">2019-08-19T10:37:55.017877797 cras atlog FILL_AUDIO dev:6 hw_level:1056</label> +<label id="38275.017883494">2019-08-19T10:37:55.017883494 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:1</label> +<label id="38275.017885650">2019-08-19T10:37:55.017885650 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38275.017888461">2019-08-19T10:37:55.017888461 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38275.017894387">2019-08-19T10:37:55.017894387 cras atlog FILL_AUDIO_DONE hw_level:1056 total_written:0 min_cb_level:1024</label> +<label id="38275.017914904">2019-08-19T10:37:55.017914904 cras atlog SET_DEV_WAKE dev:6 hw_level:1056 sleep:1008</label> +<label id="38275.017917003">2019-08-19T10:37:55.017917003 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:55.038912232</label> +<label id="38275.017924426">2019-08-19T10:37:55.017924426 cras atlog SLEEP sleep:000000000.020992719 longest_wake:001565104</label> +<label id="38275.017961913">2019-08-19T10:37:55.017961913 cras atlog WAKE num_fds:1</label> +<label id="38275.018028433">2019-08-19T10:37:55.018028433 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:55.018026226</label> +<label id="38275.018030670">2019-08-19T10:37:55.018030670 cras atlog FILL_AUDIO dev:6 hw_level:1008</label> +<label id="38275.018034173">2019-08-19T10:37:55.018034173 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38275.018037396">2019-08-19T10:37:55.018037396 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38275.018042811">2019-08-19T10:37:55.018042811 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38275.018044970">2019-08-19T10:37:55.018044970 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38275.018299235">2019-08-19T10:37:55.018299235 cras atlog FILL_AUDIO_DONE hw_level:1008 total_written:1024 min_cb_level:1024</label> +<label id="38275.018320047">2019-08-19T10:37:55.018320047 cras atlog SET_DEV_WAKE dev:6 hw_level:2032 sleep:1984</label> +<label id="38275.018322052">2019-08-19T10:37:55.018322052 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:55.059651033</label> +<label id="38275.018326693">2019-08-19T10:37:55.018326693 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:55.038988052</label> +<label id="38275.018331332">2019-08-19T10:37:55.018331332 cras atlog SLEEP sleep:000000000.020663485 longest_wake:001565104</label> +<label id="38275.039056011">2019-08-19T10:37:55.039056011 cras atlog WAKE num_fds:0</label> +<label id="38275.039099808">2019-08-19T10:37:55.039099808 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:1312</label> +<label id="38275.039142359">2019-08-19T10:37:55.039142359 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:55.039140236</label> +<label id="38275.039145228">2019-08-19T10:37:55.039145228 cras atlog FILL_AUDIO dev:6 hw_level:1024</label> +<label id="38275.039150986">2019-08-19T10:37:55.039150986 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:1</label> +<label id="38275.039153113">2019-08-19T10:37:55.039153113 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38275.039155910">2019-08-19T10:37:55.039155910 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38275.039161845">2019-08-19T10:37:55.039161845 cras atlog FILL_AUDIO_DONE hw_level:1024 total_written:0 min_cb_level:1024</label> +<label id="38275.039181369">2019-08-19T10:37:55.039181369 cras atlog SET_DEV_WAKE dev:6 hw_level:1024 sleep:976</label> +<label id="38275.039183576">2019-08-19T10:37:55.039183576 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:55.059512041</label> +<label id="38275.039191418">2019-08-19T10:37:55.039191418 cras atlog SLEEP sleep:000000000.020325678 longest_wake:001565104</label> +<label id="38275.039242696">2019-08-19T10:37:55.039242696 cras atlog WAKE num_fds:1</label> +<label id="38275.039300872">2019-08-19T10:37:55.039300872 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:55.039298791</label> +<label id="38275.039303282">2019-08-19T10:37:55.039303282 cras atlog FILL_AUDIO dev:6 hw_level:1024</label> +<label id="38275.039307147">2019-08-19T10:37:55.039307147 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38275.039310453">2019-08-19T10:37:55.039310453 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38275.039315591">2019-08-19T10:37:55.039315591 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38275.039317911">2019-08-19T10:37:55.039317911 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38275.039574431">2019-08-19T10:37:55.039574431 cras atlog FILL_AUDIO_DONE hw_level:1024 total_written:1024 min_cb_level:1024</label> +<label id="38275.039595139">2019-08-19T10:37:55.039595139 cras atlog SET_DEV_WAKE dev:6 hw_level:2048 sleep:2000</label> +<label id="38275.039597215">2019-08-19T10:37:55.039597215 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:55.081259079</label> +<label id="38275.039602049">2019-08-19T10:37:55.039602049 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:55.060321385</label> +<label id="38275.039606641">2019-08-19T10:37:55.039606641 cras atlog SLEEP sleep:000000000.020721508 longest_wake:001565104</label> +<label id="38275.060641094">2019-08-19T10:37:55.060641094 cras atlog WAKE num_fds:0</label> +<label id="38275.060684606">2019-08-19T10:37:55.060684606 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:1328</label> +<label id="38275.060729748">2019-08-19T10:37:55.060729748 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:55.060727630</label> +<label id="38275.060732607">2019-08-19T10:37:55.060732607 cras atlog FILL_AUDIO dev:6 hw_level:1040</label> +<label id="38275.060738367">2019-08-19T10:37:55.060738367 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:1</label> +<label id="38275.060740520">2019-08-19T10:37:55.060740520 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38275.060743314">2019-08-19T10:37:55.060743314 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38275.060749371">2019-08-19T10:37:55.060749371 cras atlog FILL_AUDIO_DONE hw_level:1040 total_written:0 min_cb_level:1024</label> +<label id="38275.060769291">2019-08-19T10:37:55.060769291 cras atlog SET_DEV_WAKE dev:6 hw_level:1040 sleep:992</label> +<label id="38275.060771405">2019-08-19T10:37:55.060771405 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:55.081432962</label> +<label id="38275.060778851">2019-08-19T10:37:55.060778851 cras atlog SLEEP sleep:000000000.020659012 longest_wake:001565104</label> +<label id="38275.060839575">2019-08-19T10:37:55.060839575 cras atlog WAKE num_fds:1</label> +<label id="38275.060894607">2019-08-19T10:37:55.060894607 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:55.060892493</label> +<label id="38275.060896906">2019-08-19T10:37:55.060896906 cras atlog FILL_AUDIO dev:6 hw_level:1040</label> +<label id="38275.060900273">2019-08-19T10:37:55.060900273 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38275.060903465">2019-08-19T10:37:55.060903465 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38275.060908541">2019-08-19T10:37:55.060908541 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38275.060910667">2019-08-19T10:37:55.060910667 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38275.061189546">2019-08-19T10:37:55.061189546 cras atlog FILL_AUDIO_DONE hw_level:1040 total_written:1024 min_cb_level:1024</label> +<label id="38275.061209809">2019-08-19T10:37:55.061209809 cras atlog SET_DEV_WAKE dev:6 hw_level:2016 sleep:1968</label> +<label id="38275.061211862">2019-08-19T10:37:55.061211862 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:55.102207100</label> +<label id="38275.061216513">2019-08-19T10:37:55.061216513 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:55.081654718</label> +<label id="38275.061221096">2019-08-19T10:37:55.061221096 cras atlog SLEEP sleep:000000000.020440532 longest_wake:001565104</label> +<label id="38275.081923521">2019-08-19T10:37:55.081923521 cras atlog WAKE num_fds:0</label> +<label id="38275.081962397">2019-08-19T10:37:55.081962397 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:1344</label> +<label id="38275.082024685">2019-08-19T10:37:55.082024685 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:55.082022354</label> +<label id="38275.082027553">2019-08-19T10:37:55.082027553 cras atlog FILL_AUDIO dev:6 hw_level:1008</label> +<label id="38275.082033348">2019-08-19T10:37:55.082033348 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:1</label> +<label id="38275.082035492">2019-08-19T10:37:55.082035492 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38275.082038363">2019-08-19T10:37:55.082038363 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38275.082044372">2019-08-19T10:37:55.082044372 cras atlog FILL_AUDIO_DONE hw_level:1008 total_written:0 min_cb_level:1024</label> +<label id="38275.082064736">2019-08-19T10:37:55.082064736 cras atlog SET_DEV_WAKE dev:6 hw_level:1008 sleep:960</label> +<label id="38275.082066844">2019-08-19T10:37:55.082066844 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:55.102062036</label> +<label id="38275.082074672">2019-08-19T10:37:55.082074672 cras atlog SLEEP sleep:000000000.019992279 longest_wake:001565104</label> +<label id="38275.082101703">2019-08-19T10:37:55.082101703 cras atlog WAKE num_fds:1</label> +<label id="38275.082151613">2019-08-19T10:37:55.082151613 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:55.082149632</label> +<label id="38275.082153665">2019-08-19T10:37:55.082153665 cras atlog FILL_AUDIO dev:6 hw_level:1008</label> +<label id="38275.082156304">2019-08-19T10:37:55.082156304 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38275.082159578">2019-08-19T10:37:55.082159578 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38275.082164588">2019-08-19T10:37:55.082164588 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38275.082166781">2019-08-19T10:37:55.082166781 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38275.082420700">2019-08-19T10:37:55.082420700 cras atlog FILL_AUDIO_DONE hw_level:1008 total_written:1024 min_cb_level:1024</label> +<label id="38275.082440331">2019-08-19T10:37:55.082440331 cras atlog SET_DEV_WAKE dev:6 hw_level:2032 sleep:1984</label> +<label id="38275.082442354">2019-08-19T10:37:55.082442354 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:55.123771185</label> +<label id="38275.082446864">2019-08-19T10:37:55.082446864 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:55.102988051</label> +<label id="38275.082451229">2019-08-19T10:37:55.082451229 cras atlog SLEEP sleep:000000000.020543317 longest_wake:001565104</label> +<label id="38275.103235081">2019-08-19T10:37:55.103235081 cras atlog WAKE num_fds:0</label> +<label id="38275.103278902">2019-08-19T10:37:55.103278902 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:1312</label> +<label id="38275.103323855">2019-08-19T10:37:55.103323855 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:55.103321735</label> +<label id="38275.103326735">2019-08-19T10:37:55.103326735 cras atlog FILL_AUDIO dev:6 hw_level:1024</label> +<label id="38275.103332368">2019-08-19T10:37:55.103332368 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:1</label> +<label id="38275.103334547">2019-08-19T10:37:55.103334547 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38275.103337442">2019-08-19T10:37:55.103337442 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38275.103343414">2019-08-19T10:37:55.103343414 cras atlog FILL_AUDIO_DONE hw_level:1024 total_written:0 min_cb_level:1024</label> +<label id="38275.103362951">2019-08-19T10:37:55.103362951 cras atlog SET_DEV_WAKE dev:6 hw_level:1024 sleep:976</label> +<label id="38275.103365027">2019-08-19T10:37:55.103365027 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:55.123693749</label> +<label id="38275.103372515">2019-08-19T10:37:55.103372515 cras atlog SLEEP sleep:000000000.020326206 longest_wake:001565104</label> +<label id="38275.103495004">2019-08-19T10:37:55.103495004 cras atlog WAKE num_fds:1</label> +<label id="38275.103558662">2019-08-19T10:37:55.103558662 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:55.103556509</label> +<label id="38275.103561185">2019-08-19T10:37:55.103561185 cras atlog FILL_AUDIO dev:6 hw_level:1024</label> +<label id="38275.103565634">2019-08-19T10:37:55.103565634 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38275.103568909">2019-08-19T10:37:55.103568909 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38275.103574106">2019-08-19T10:37:55.103574106 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38275.103576534">2019-08-19T10:37:55.103576534 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38275.103894760">2019-08-19T10:37:55.103894760 cras atlog FILL_AUDIO_DONE hw_level:1024 total_written:1024 min_cb_level:1024</label> +<label id="38275.103915541">2019-08-19T10:37:55.103915541 cras atlog SET_DEV_WAKE dev:6 hw_level:2048 sleep:2000</label> +<label id="38275.103917608">2019-08-19T10:37:55.103917608 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:55.145579387</label> +<label id="38275.103922443">2019-08-19T10:37:55.103922443 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:55.124321384</label> +<label id="38275.103927126">2019-08-19T10:37:55.103927126 cras atlog SLEEP sleep:000000000.020401063 longest_wake:001565104</label> +<label id="38275.124565623">2019-08-19T10:37:55.124565623 cras atlog WAKE num_fds:0</label> +<label id="38275.124610042">2019-08-19T10:37:55.124610042 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:1328</label> +<label id="38275.124655051">2019-08-19T10:37:55.124655051 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:55.124652899</label> +<label id="38275.124657946">2019-08-19T10:37:55.124657946 cras atlog FILL_AUDIO dev:6 hw_level:1040</label> +<label id="38275.124663566">2019-08-19T10:37:55.124663566 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:1</label> +<label id="38275.124665720">2019-08-19T10:37:55.124665720 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38275.124668612">2019-08-19T10:37:55.124668612 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38275.124674855">2019-08-19T10:37:55.124674855 cras atlog FILL_AUDIO_DONE hw_level:1040 total_written:0 min_cb_level:1024</label> +<label id="38275.124694671">2019-08-19T10:37:55.124694671 cras atlog SET_DEV_WAKE dev:6 hw_level:1040 sleep:992</label> +<label id="38275.124696783">2019-08-19T10:37:55.124696783 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:55.145358605</label> +<label id="38275.124704191">2019-08-19T10:37:55.124704191 cras atlog SLEEP sleep:000000000.020659309 longest_wake:001565104</label> +<label id="38275.124760504">2019-08-19T10:37:55.124760504 cras atlog WAKE num_fds:1</label> +<label id="38275.124816244">2019-08-19T10:37:55.124816244 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:55.124814108</label> +<label id="38275.124818548">2019-08-19T10:37:55.124818548 cras atlog FILL_AUDIO dev:6 hw_level:1040</label> +<label id="38275.124821764">2019-08-19T10:37:55.124821764 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38275.124825000">2019-08-19T10:37:55.124825000 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38275.124830095">2019-08-19T10:37:55.124830095 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38275.124832256">2019-08-19T10:37:55.124832256 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38275.125110455">2019-08-19T10:37:55.125110455 cras atlog FILL_AUDIO_DONE hw_level:1040 total_written:1024 min_cb_level:1024</label> +<label id="38275.125130858">2019-08-19T10:37:55.125130858 cras atlog SET_DEV_WAKE dev:6 hw_level:2016 sleep:1968</label> +<label id="38275.125132923">2019-08-19T10:37:55.125132923 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:55.166128332</label> +<label id="38275.125137438">2019-08-19T10:37:55.125137438 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:55.145654717</label> +<label id="38275.125141823">2019-08-19T10:37:55.125141823 cras atlog SLEEP sleep:000000000.020519397 longest_wake:001565104</label> +<label id="38275.145927558">2019-08-19T10:37:55.145927558 cras atlog WAKE num_fds:0</label> +<label id="38275.145964152">2019-08-19T10:37:55.145964152 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:1296</label> +<label id="38275.146026003">2019-08-19T10:37:55.146026003 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:55.146023734</label> +<label id="38275.146029029">2019-08-19T10:37:55.146029029 cras atlog FILL_AUDIO dev:6 hw_level:1008</label> +<label id="38275.146034797">2019-08-19T10:37:55.146034797 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:1</label> +<label id="38275.146036944">2019-08-19T10:37:55.146036944 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38275.146039804">2019-08-19T10:37:55.146039804 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38275.146045532">2019-08-19T10:37:55.146045532 cras atlog FILL_AUDIO_DONE hw_level:1008 total_written:0 min_cb_level:1024</label> +<label id="38275.146065845">2019-08-19T10:37:55.146065845 cras atlog SET_DEV_WAKE dev:6 hw_level:1008 sleep:960</label> +<label id="38275.146067907">2019-08-19T10:37:55.146067907 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:55.166063093</label> +<label id="38275.146075679">2019-08-19T10:37:55.146075679 cras atlog SLEEP sleep:000000000.019992516 longest_wake:001565104</label> +<label id="38275.146104176">2019-08-19T10:37:55.146104176 cras atlog WAKE num_fds:1</label> +<label id="38275.146154911">2019-08-19T10:37:55.146154911 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:55.146152940</label> +<label id="38275.146157000">2019-08-19T10:37:55.146157000 cras atlog FILL_AUDIO dev:6 hw_level:1008</label> +<label id="38275.146159732">2019-08-19T10:37:55.146159732 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38275.146162656">2019-08-19T10:37:55.146162656 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38275.146167707">2019-08-19T10:37:55.146167707 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38275.146169907">2019-08-19T10:37:55.146169907 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38275.146425051">2019-08-19T10:37:55.146425051 cras atlog FILL_AUDIO_DONE hw_level:1008 total_written:1024 min_cb_level:1024</label> +<label id="38275.146444659">2019-08-19T10:37:55.146444659 cras atlog SET_DEV_WAKE dev:6 hw_level:2032 sleep:1984</label> +<label id="38275.146446660">2019-08-19T10:37:55.146446660 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:55.187775515</label> +<label id="38275.146451169">2019-08-19T10:37:55.146451169 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:55.166988050</label> +<label id="38275.146455570">2019-08-19T10:37:55.146455570 cras atlog SLEEP sleep:000000000.020539017 longest_wake:001565104</label> +<label id="38275.167553074">2019-08-19T10:37:55.167553074 cras atlog WAKE num_fds:0</label> +<label id="38275.167594886">2019-08-19T10:37:55.167594886 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:1312</label> +<label id="38275.167640114">2019-08-19T10:37:55.167640114 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:55.167637997</label> +<label id="38275.167643000">2019-08-19T10:37:55.167643000 cras atlog FILL_AUDIO dev:6 hw_level:1024</label> +<label id="38275.167648699">2019-08-19T10:37:55.167648699 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:1</label> +<label id="38275.167650882">2019-08-19T10:37:55.167650882 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38275.167653697">2019-08-19T10:37:55.167653697 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38275.167659615">2019-08-19T10:37:55.167659615 cras atlog FILL_AUDIO_DONE hw_level:1024 total_written:0 min_cb_level:1024</label> +<label id="38275.167679011">2019-08-19T10:37:55.167679011 cras atlog SET_DEV_WAKE dev:6 hw_level:1024 sleep:976</label> +<label id="38275.167681098">2019-08-19T10:37:55.167681098 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:55.188009795</label> +<label id="38275.167688811">2019-08-19T10:37:55.167688811 cras atlog SLEEP sleep:000000000.020326143 longest_wake:001565104</label> +<label id="38275.167749677">2019-08-19T10:37:55.167749677 cras atlog WAKE num_fds:1</label> +<label id="38275.167804583">2019-08-19T10:37:55.167804583 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:55.167802506</label> +<label id="38275.167806856">2019-08-19T10:37:55.167806856 cras atlog FILL_AUDIO dev:6 hw_level:1024</label> +<label id="38275.167810111">2019-08-19T10:37:55.167810111 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38275.167813451">2019-08-19T10:37:55.167813451 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38275.167818458">2019-08-19T10:37:55.167818458 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38275.167820591">2019-08-19T10:37:55.167820591 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38275.168098935">2019-08-19T10:37:55.168098935 cras atlog FILL_AUDIO_DONE hw_level:1024 total_written:1024 min_cb_level:1024</label> +<label id="38275.168119122">2019-08-19T10:37:55.168119122 cras atlog SET_DEV_WAKE dev:6 hw_level:2000 sleep:1952</label> +<label id="38275.168121172">2019-08-19T10:37:55.168121172 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:55.208783150</label> +<label id="38275.168125546">2019-08-19T10:37:55.168125546 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:55.188321383</label> +<label id="38275.168129938">2019-08-19T10:37:55.168129938 cras atlog SLEEP sleep:000000000.020197922 longest_wake:001565104</label> +<label id="38275.188638183">2019-08-19T10:37:55.188638183 cras atlog WAKE num_fds:0</label> +<label id="38275.188682360">2019-08-19T10:37:55.188682360 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:1328</label> +<label id="38275.188727068">2019-08-19T10:37:55.188727068 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:55.188724948</label> +<label id="38275.188729928">2019-08-19T10:37:55.188729928 cras atlog FILL_AUDIO dev:6 hw_level:1040</label> +<label id="38275.188735860">2019-08-19T10:37:55.188735860 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:1</label> +<label id="38275.188738005">2019-08-19T10:37:55.188738005 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38275.188740801">2019-08-19T10:37:55.188740801 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38275.188746886">2019-08-19T10:37:55.188746886 cras atlog FILL_AUDIO_DONE hw_level:1040 total_written:0 min_cb_level:1024</label> +<label id="38275.188766573">2019-08-19T10:37:55.188766573 cras atlog SET_DEV_WAKE dev:6 hw_level:1040 sleep:992</label> +<label id="38275.188768680">2019-08-19T10:37:55.188768680 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:55.209430581</label> +<label id="38275.188776647">2019-08-19T10:37:55.188776647 cras atlog SLEEP sleep:000000000.020659030 longest_wake:001565104</label> +<label id="38275.188837092">2019-08-19T10:37:55.188837092 cras atlog WAKE num_fds:1</label> +<label id="38275.188891865">2019-08-19T10:37:55.188891865 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:55.188889848</label> +<label id="38275.188894276">2019-08-19T10:37:55.188894276 cras atlog FILL_AUDIO dev:6 hw_level:1040</label> +<label id="38275.188897503">2019-08-19T10:37:55.188897503 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38275.188900748">2019-08-19T10:37:55.188900748 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38275.188905918">2019-08-19T10:37:55.188905918 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38275.188908049">2019-08-19T10:37:55.188908049 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38275.189185844">2019-08-19T10:37:55.189185844 cras atlog FILL_AUDIO_DONE hw_level:1040 total_written:1024 min_cb_level:1024</label> +<label id="38275.189205852">2019-08-19T10:37:55.189205852 cras atlog SET_DEV_WAKE dev:6 hw_level:2016 sleep:1968</label> +<label id="38275.189207862">2019-08-19T10:37:55.189207862 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:55.230203316</label> +<label id="38275.189212302">2019-08-19T10:37:55.189212302 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:55.209654716</label> +<label id="38275.189216722">2019-08-19T10:37:55.189216722 cras atlog SLEEP sleep:000000000.020444572 longest_wake:001565104</label> +<label id="38275.209911683">2019-08-19T10:37:55.209911683 cras atlog WAKE num_fds:0</label> +<label id="38275.209955429">2019-08-19T10:37:55.209955429 cras atlog WRITE_STREAMS_FETCH_STREAM id:1d0000 cbth:1024 delay:1344</label> +<label id="38275.210000864">2019-08-19T10:37:55.210000864 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:55.209998749</label> +<label id="38275.210020752">2019-08-19T10:37:55.210020752 cras atlog FILL_AUDIO dev:6 hw_level:1008</label> +<label id="38275.210026614">2019-08-19T10:37:55.210026614 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:0 cb_pending:1</label> +<label id="38275.210028898">2019-08-19T10:37:55.210028898 cras atlog WRITE_STREAMS_MIX write_limit:0 max_offset:0</label> +<label id="38275.210031723">2019-08-19T10:37:55.210031723 cras atlog WRITE_STREAMS_MIXED write_limit:0</label> +<label id="38275.210038139">2019-08-19T10:37:55.210038139 cras atlog FILL_AUDIO_DONE hw_level:1008 total_written:0 min_cb_level:1024</label> +<label id="38275.210058744">2019-08-19T10:37:55.210058744 cras atlog SET_DEV_WAKE dev:6 hw_level:1008 sleep:960</label> +<label id="38275.210060812">2019-08-19T10:37:55.210060812 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:55.230056030</label> +<label id="38275.210068424">2019-08-19T10:37:55.210068424 cras atlog SLEEP sleep:000000000.019992546 longest_wake:001565104</label> +<label id="38275.210096165">2019-08-19T10:37:55.210096165 cras atlog WAKE num_fds:1</label> +<label id="38275.210146366">2019-08-19T10:37:55.210146366 cras atlog FILL_AUDIO_TSTAMP dev:6 tstamp: 10:37:55.210144294</label> +<label id="38275.210148466">2019-08-19T10:37:55.210148466 cras atlog FILL_AUDIO dev:6 hw_level:1008</label> +<label id="38275.210151084">2019-08-19T10:37:55.210151084 cras atlog WRITE_STREAMS_STREAM id:1d0000 shm_frames:1024 cb_pending:0</label> +<label id="38275.210154312">2019-08-19T10:37:55.210154312 cras atlog WRITE_STREAMS_MIX write_limit:1024 max_offset:0</label> +<label id="38275.210159347">2019-08-19T10:37:55.210159347 cras atlog DEV_STREAM_MIX written:1024 read:1024</label> +<label id="38275.210161490">2019-08-19T10:37:55.210161490 cras atlog WRITE_STREAMS_MIXED write_limit:1024</label> +<label id="38275.210414903">2019-08-19T10:37:55.210414903 cras atlog FILL_AUDIO_DONE hw_level:1008 total_written:1024 min_cb_level:1024</label> +<label id="38275.210434597">2019-08-19T10:37:55.210434597 cras atlog SET_DEV_WAKE dev:6 hw_level:2032 sleep:1984</label> +<label id="38275.210436597">2019-08-19T10:37:55.210436597 cras atlog DEV_SLEEP_TIME dev:6 wake: 10:37:55.251765477</label> +<label id="38275.210441028">2019-08-19T10:37:55.210441028 cras atlog STREAM_SLEEP_TIME id:1d0000 wake: 10:37:55.230988049</label> +<label id="38275.210445345">2019-08-19T10:37:55.210445345 cras atlog SLEEP sleep:000000000.020549158 longest_wake:001565104</label> +<label id="38275.222778298">2019-08-19T10:37:55.222778298 cras atlog WAKE num_fds:1</label> +<label id="38275.222790909">2019-08-19T10:37:55.222790909 cras atlog PB_MSG msg_id:7</label> +<label id="38275.222796197">2019-08-19T10:37:55.222796197 cras atlog STREAM_REMOVED id:1d0000</label>`; + put_logs = function () { + document.getElementById('logs').innerHTML = logs; + }; + + set_initial_checkbox_value = function () { + document.getElementById('device').checked = true; + document.getElementById('stream').checked = true; + document.getElementById('fetch').checked = true; + document.getElementById('wake').checked = true; + } + + window.onload = function() { + draw_chart(); + put_logs(); + set_initial_checkbox_value(); + }; + + function handleClick(checkbox) { + var class_name = checkbox.id; + var elements = document.getElementsByClassName(class_name); + var i; + + if (checkbox.checked) { + display_value = "block"; + } else { + display_value = "none" + } + + console.log("change " + class_name + " to " + display_value); + for (i = 0; i < elements.length; i++) { + elements[i].style.display = display_value; + } + } + + </script> +</head> + +<body> + <div id="chart" style="height:50%; width:100%" ></div> + <div style="margin:0 auto"; class="checkbox"> + <label><input type="checkbox" onclick="handleClick(this);" id="device">Show device removed/added event</label> + <label><input type="checkbox" onclick="handleClick(this);" id="stream">Show stream removed/added event</label> + <label><input type="checkbox" onclick="handleClick(this);" id="fetch">Show fetch event</label> + <label><input type="checkbox" onclick="handleClick(this);" id="wake">Show wake by num_fds=1 event</label> + </div> + <div class="event_log_box", id="logs", style="float:left;"></div> + <textarea class="event_log_box", id="text", style="float:right;"></textarea> +</body> +</html> diff --git a/scripts/audio_thread_log_viewer/viewer_c3.py b/scripts/audio_thread_log_viewer/viewer_c3.py index 2f23dd5d..f8d4f57a 100755 --- a/scripts/audio_thread_log_viewer/viewer_c3.py +++ b/scripts/audio_thread_log_viewer/viewer_c3.py @@ -11,6 +11,7 @@ import argparse import collections import logging import string +import time page_content = string.Template(""" <html meta charset="UTF8"> @@ -53,17 +54,30 @@ page_content = string.Template(""" } </style> <script type="text/javascript"> + var selected = null; draw_chart = function() { var chart = c3.generate({ data: { x: 'time', columns: [ - ['time', $times], - ['buffer_level', $buffer_levels], + ['time', $times], + ['buffer_level', $buffer_levels], ], type: 'bar', types: { - buffer_level: 'line', + buffer_level: 'line', + }, + onclick: function (d, i) { + elm = document.getElementById(d.x.toFixed(9)); + if (selected) + selected.style.color = ''; + if (elm === null) { + console.error("Can not find element by ID %s", d.x.toFixed(9)); + return; + } + elm.style.color = 'blue'; + elm.scrollIntoView(); + selected = elm; }, }, zoom: { @@ -137,7 +151,22 @@ page_content = string.Template(""" """) -Tag = collections.namedtuple('Tag', {'time', 'text', 'position', 'class_name'}) +def StrToTimestamp(s): + """Converts a time string to a timestamp. + + @param s: A time string like "2019-07-02T15:30:46.684190644". + + @returns: Returns a timestamp string like "55846.684190644". + + """ + fmt = "%Y-%m-%dT%H:%M:%S" + t = time.strptime(s[:-10], fmt) + # Ignore date to avoid a long timestamp. + ts = t.tm_hour * 3600 + t.tm_min * 60 + t.tm_sec + return "{:d}.{}".format(ts, s[-9:]) + + +Tag = collections.namedtuple('Tag', ['time', 'text', 'position', 'class_name']) """ The tuple for tags shown on the plot on certain time. text is the tag to show, position is the tag position, which is one of @@ -411,9 +440,9 @@ class EventLogParser(object): """Parses one line of event log. Split a line like - 169536.504763588 WRITE_STREAMS_FETCH_STREAM id:0 cbth:512 delay:1136 + 2019-07-02T15:30:46.683829810 cras atlog WRITE_STREAMS_FETCH_STREAM id:1e0000 cbth:512 delay:1136 into time, name, and props where - time = '169536.504763588' + time = '54946.683829810' name = 'WRITE_STREAMS_FETCH_STREAM' props = { 'id': 0, @@ -427,11 +456,11 @@ class EventLogParser(object): """ line_split = line.split() - time, name = line_split[0], line_split[1] + time, name = StrToTimestamp(line_split[0]), line_split[3] logging.debug('time: %s, name: %s', time, name) props = {} - for index in xrange(2, len(line_split)): - key, value = line_split[index].split(':') + for index in xrange(4, len(line_split)): + key, value = line_split[index].split(':')[:2] props[key] = value logging.debug('props: %s', props) return self._CreateEventData(time, name, props) @@ -509,7 +538,15 @@ class AudioThreadLogParser(object): @returns: A string for filled page. """ - logs = '\n<br>'.join(self.content) + logs = [] + for s in self.content: + if 'atlog' in s: + time = StrToTimestamp(s.split()[0]) + logs.append('<label id="{}">{}</label>'.format(time, s)) + else: + logs.append(s) + logs = '\n'.join(logs) + return page_template.substitute(logs=logs) diff --git a/seccomp/cras-seccomp-amd64.policy b/seccomp/cras-seccomp-amd64.policy index 0c1c46fa..06dc2243 100644 --- a/seccomp/cras-seccomp-amd64.policy +++ b/seccomp/cras-seccomp-amd64.policy @@ -85,3 +85,4 @@ getpid: 1 prlimit64: 1 tgkill: 1 mremap: 1 +dup: 1 diff --git a/seccomp/cras-seccomp-arm.policy b/seccomp/cras-seccomp-arm.policy index 3805b62b..f917036f 100644 --- a/seccomp/cras-seccomp-arm.policy +++ b/seccomp/cras-seccomp-arm.policy @@ -91,3 +91,4 @@ getpid: 1 prlimit64: 1 tgkill: 1 mremap: 1 +dup: 1 diff --git a/seccomp/cras-seccomp-arm64.policy b/seccomp/cras-seccomp-arm64.policy index 68eb6056..64f32440 100644 --- a/seccomp/cras-seccomp-arm64.policy +++ b/seccomp/cras-seccomp-arm64.policy @@ -83,3 +83,4 @@ getpid: 1 prlimit64: 1 tgkill: 1 mremap: 1 +dup: 1 diff --git a/ucm-config/auron/HDA Intel PCH/HDA Intel PCH.conf b/ucm-config/auron/HDA Intel PCH/HDA Intel PCH.conf deleted file mode 100644 index aa3c8dd5..00000000 --- a/ucm-config/auron/HDA Intel PCH/HDA Intel PCH.conf +++ /dev/null @@ -1,6 +0,0 @@ -Comment "Auron internal card" - -SectionUseCase."HiFi" { - File "HiFi.conf" - Comment "Default" -} diff --git a/ucm-config/auron/HDA Intel PCH/HiFi.conf b/ucm-config/auron/HDA Intel PCH/HiFi.conf deleted file mode 100644 index 6174c0b9..00000000 --- a/ucm-config/auron/HDA Intel PCH/HiFi.conf +++ /dev/null @@ -1,55 +0,0 @@ -SectionVerb { - Value { - OutputDspName "speaker_eq" - } - EnableSequence [ - cdev "hw:PCH" - - cset "name='Master Playback Switch' on" - cset "name='Headphone Playback Switch' off" - cset "name='Speaker Playback Switch' on" - - cset "name='Capture Switch' on" - cset "name='Capture Volume' 39" - cset "name='Mic Boost Volume' 2" - cset "name='Internal Mic Boost Volume' 1" - cset "name='Capture Source' 0" - ] - DisableSequence [ - ] -} - -SectionDevice."Headphone".0 { - Value { - JackName "Headphone Jack" - DspName "" - } - EnableSequence [ - cdev "hw:PCH" - - cset "name='Speaker Playback Switch' off" - cset "name='Headphone Playback Switch' on" - ] - DisableSequence [ - cdev "hw:PCH" - - cset "name='Headphone Playback Switch' off" - cset "name='Speaker Playback Switch' on" - ] -} - -SectionDevice."Mic".0 { - Value { - JackName "Mic Jack" - } - EnableSequence [ - cdev "hw:PCH" - - cset "name='Capture Source' 1" - ] - DisableSequence [ - cdev "hw:PCH" - - cset "name='Capture Source' 0" - ] -} diff --git a/ucm-config/auron_paine/HDA Intel PCH/HDA Intel PCH.conf b/ucm-config/auron_paine/HDA Intel PCH/HDA Intel PCH.conf deleted file mode 100644 index 7a62b05b..00000000 --- a/ucm-config/auron_paine/HDA Intel PCH/HDA Intel PCH.conf +++ /dev/null @@ -1,6 +0,0 @@ -Comment "Paine internal card" - -SectionUseCase."HiFi" { - File "HiFi.conf" - Comment "Default" -} diff --git a/ucm-config/auron_paine/HDA Intel PCH/HiFi.conf b/ucm-config/auron_paine/HDA Intel PCH/HiFi.conf deleted file mode 100644 index c10d41e4..00000000 --- a/ucm-config/auron_paine/HDA Intel PCH/HiFi.conf +++ /dev/null @@ -1,90 +0,0 @@ -SectionVerb { - Value { - InputDspName "dmic_eq" - OutputDspName "speaker_eq" - FullySpecifiedUCM "1" - } - EnableSequence [ - cdev "hw:PCH" - - cset "name='Master Playback Switch' on" - cset "name='Headphone Playback Switch' off" - cset "name='Speaker Playback Switch' off" - - cset "name='Capture Switch' on" - cset "name='Capture Volume' 39" - cset "name='Mic Boost Volume' 2" - cset "name='Internal Mic Boost Volume' 1" - cset "name='Input Source' 1" - ] - DisableSequence [ - ] -} - -SectionDevice."Speaker".0 { - Value { - PlaybackPCM "hw:HDA Intel PCH,0" - MixerName "Master" - } - - EnableSequence [ - cdev "hw:PCH" - - cset "name='Speaker Playback Switch' on" - ] - DisableSequence [ - cdev "hw:PCH" - - cset "name='Speaker Playback Switch' off" - ] -} - -SectionDevice."Headphone".0 { - Value { - PlaybackPCM "hw:HDA Intel PCH,0" - JackName "Headphone Jack" - JackType "hctl" - MixerName "Master" - DspName "" - } - EnableSequence [ - cdev "hw:PCH" - - cset "name='Headphone Playback Switch' on" - ] - DisableSequence [ - cdev "hw:PCH" - - cset "name='Headphone Playback Switch' off" - ] -} - -SectionDevice."Internal Mic" { - Value { - InputDspName "" - CapturePCM "hw:HDA Intel PCH,0" - } - EnableSequence [ - ] - DisableSequence [ - ] -} - -SectionDevice."Mic" { - Value { - CapturePCM "hw:HDA Intel PCH,0" - JackName "Mic Jack" - JackType "hctl" - DefaultNodeGain "-400" - } - EnableSequence [ - cdev "hw:PCH" - - cset "name='Input Source' 0" - ] - DisableSequence [ - cdev "hw:PCH" - - cset "name='Input Source' 1" - ] -} diff --git a/ucm-config/auron_yuna/HDA Intel PCH/HDA Intel PCH.conf b/ucm-config/auron_yuna/HDA Intel PCH/HDA Intel PCH.conf deleted file mode 100644 index 5133a987..00000000 --- a/ucm-config/auron_yuna/HDA Intel PCH/HDA Intel PCH.conf +++ /dev/null @@ -1,6 +0,0 @@ -Comment "Yuna internal card" - -SectionUseCase."HiFi" { - File "HiFi.conf" - Comment "Default" -} diff --git a/ucm-config/auron_yuna/HDA Intel PCH/HiFi.conf b/ucm-config/auron_yuna/HDA Intel PCH/HiFi.conf deleted file mode 100644 index 6174c0b9..00000000 --- a/ucm-config/auron_yuna/HDA Intel PCH/HiFi.conf +++ /dev/null @@ -1,55 +0,0 @@ -SectionVerb { - Value { - OutputDspName "speaker_eq" - } - EnableSequence [ - cdev "hw:PCH" - - cset "name='Master Playback Switch' on" - cset "name='Headphone Playback Switch' off" - cset "name='Speaker Playback Switch' on" - - cset "name='Capture Switch' on" - cset "name='Capture Volume' 39" - cset "name='Mic Boost Volume' 2" - cset "name='Internal Mic Boost Volume' 1" - cset "name='Capture Source' 0" - ] - DisableSequence [ - ] -} - -SectionDevice."Headphone".0 { - Value { - JackName "Headphone Jack" - DspName "" - } - EnableSequence [ - cdev "hw:PCH" - - cset "name='Speaker Playback Switch' off" - cset "name='Headphone Playback Switch' on" - ] - DisableSequence [ - cdev "hw:PCH" - - cset "name='Headphone Playback Switch' off" - cset "name='Speaker Playback Switch' on" - ] -} - -SectionDevice."Mic".0 { - Value { - JackName "Mic Jack" - } - EnableSequence [ - cdev "hw:PCH" - - cset "name='Capture Source' 1" - ] - DisableSequence [ - cdev "hw:PCH" - - cset "name='Capture Source' 0" - ] -} diff --git a/ucm-config/cyan/chtmax98090/HiFi.conf b/ucm-config/cyan/chtmax98090/HiFi.conf deleted file mode 100644 index 5d880aba..00000000 --- a/ucm-config/cyan/chtmax98090/HiFi.conf +++ /dev/null @@ -1,135 +0,0 @@ -SectionVerb { - Value { - OutputDspName "speaker_eq" - } - - EnableSequence [ - cdev "hw:chtmax98090" - - cset "name='codec_out0 mix 0 pcm0_in Switch' on" - cset "name='media0_out mix 0 media1_in Switch' on" - cset "name='media1_in Gain 0 Ramp Delay' 50" - cset "name='media1_in Gain 0 Switch' off" - cset "name='media1_in Gain 0 Volume' 80% 80%" - cset "name='pcm0_in Gain 0 Ramp Delay' 50" - cset "name='pcm0_in Gain 0 Switch' off" - cset "name='pcm0_in Gain 0 Volume' 80% 80%" - cset "name='codec_out0 Gain 0 Ramp Delay' 50" - cset "name='codec_out0 Gain 0 Switch' off" - cset "name='codec_out0 Gain 0 Volume' 80% 80%" - cset "name='pcm1_out mix 0 media_loop2_in Switch' 1" - cset "name='media_loop2_out mix 0 codec_in0 Switch' 1" - cset "name='codec_in0 Gain 0 Ramp Delay' 50" - cset "name='codec_in0 Gain 0 Switch' off" - cset "name='codec_in0 Gain 0 Volume' 80% 80%" - cset "name='media_loop2_out Gain 0 Ramp Delay' 50" - cset "name='media_loop2_out Gain 0 Switch' off" - cset "name='media_loop2_out Gain 0 Volume' 80% 80%" - cset "name='pcm1_out Gain 0 Ramp Delay' 50" - cset "name='pcm1_out Gain 0 Switch' off" - cset "name='pcm1_out Gain 0 Volume' 80% 80%" - cset "name='Digital EQ 3 Band Switch' off" - cset "name='Digital EQ 5 Band Switch' off" - cset "name='Digital EQ 7 Band Switch' off" - cset "name='Biquad Switch' off" - cset "name='Filter Mode' Music" - cset "name='ADC Oversampling Rate' 0" - - cset "name='DMIC Mux' DMIC" - cset "name='MIC2 Mux' IN34" - cset "name='Right ADC Mixer MIC2 Switch' on" - cset "name='Left ADC Mixer MIC2 Switch' on" - cset "name='MIC2 Volume' 20" - cset "name='Int Mic Switch' on" - - cset "name='ADCR Boost Volume' 4" - cset "name='ADCL Boost Volume' 4" - cset "name='ADCR Volume' 11" - cset "name='ADCL Volume' 11" - - cset "name='Left Speaker Mixer Left DAC Switch' on" - cset "name='Right Speaker Mixer Right DAC Switch' on" - cset "name='Speaker Left Mixer Volume' 2" - cset "name='Speaker Right Mixer Volume' 2" - cset "name='Record Path DC Blocking' on" - cset "name='Playback Path DC Blocking' on" - - cset "name='Headphone Left Switch' on" - cset "name='Headphone Right Switch' on" - cset "name='Ext HP Switch' off" - - cset "name='Speaker Left Switch' on" - cset "name='Speaker Right Switch' on" - cset "name='Ext Spk Switch' on" - - ] - - DisableSequence [ - ] -} - -SectionDevice."Headphone".0 { - Value { - JackName "chtmax98090 Headset Jack" - DspName "" - } - - EnableSequence [ - cdev "hw:chtmax98090" - cset "name='Ext Spk Switch' off" - cset "name='Speaker Left Switch' off" - cset "name='Speaker Right Switch' off" - cset "name='Ext HP Switch' on" - ] - DisableSequence [ - cdev "hw:chtmax98090" - cset "name='Ext HP Switch' off" - cset "name='Ext Spk Switch' on" - cset "name='Speaker Left Switch' on" - cset "name='Speaker Right Switch' on" - ] -} - -SectionDevice."Mic".0 { - Value { - JackName "chtmax98090 Headset Jack" - } - - EnableSequence [ - cdev "hw:chtmax98090" - cset "name='Int Mic Switch' off" - cset "name='Headset Mic Switch' on" - cset "name='DMIC Mux' ADC" - cset "name='Record Path DC Blocking' on" - ] - - DisableSequence [ - cdev "hw:chtmax98090" - cset "name='Headset Mic Switch' off" - cset "name='Int Mic Switch' on" - cset "name='DMIC Mux' DMIC" - cset "name='Record Path DC Blocking' off" - ] -} - -SectionModifier."Speaker Swap Mode".0 { - Comment "Swap the left and right channels of speaker." - - EnableSequence [ - cdev "hw:chtmax98090" - - cset "name='Left Speaker Mixer Left DAC Switch' off" - cset "name='Right Speaker Mixer Right DAC Switch' off" - cset "name='Left Speaker Mixer Right DAC Switch' on" - cset "name='Right Speaker Mixer Left DAC Switch' on" - ] - - DisableSequence [ - cdev "hw:chtmax98090" - - cset "name='Left Speaker Mixer Right DAC Switch' off" - cset "name='Right Speaker Mixer Left DAC Switch' off" - cset "name='Left Speaker Mixer Left DAC Switch' on" - cset "name='Right Speaker Mixer Right DAC Switch' on" - ] -} diff --git a/ucm-config/cyan/chtmax98090/chtmax98090.conf b/ucm-config/cyan/chtmax98090/chtmax98090.conf deleted file mode 100644 index 2263279f..00000000 --- a/ucm-config/cyan/chtmax98090/chtmax98090.conf +++ /dev/null @@ -1,6 +0,0 @@ -Comment "Cyan internal card" - -SectionUseCase."HiFi" { - File "HiFi.conf" - Comment "Default" -} diff --git a/ucm-config/cyan/sof-chtmax98090/HiFi.conf b/ucm-config/cyan/sof-chtmax98090/HiFi.conf deleted file mode 100644 index 8b7aacd0..00000000 --- a/ucm-config/cyan/sof-chtmax98090/HiFi.conf +++ /dev/null @@ -1,185 +0,0 @@ -# command-line sequence to switch playback/capture -# alsaucm -c sof-chtmax98090 set _verb HiFi set _enadev Headphone -# alsaucm -c sof-chtmax98090 set _verb HiFi set _enadev Speakers -# alsaucm -c sof-chtmax98090 set _verb HiFi set _enadev HeadsetMic -# alsaucm -c sof-chtmax98090 set _verb HiFi set _enadev InternalMic - - -SectionVerb { - - EnableSequence [ - cdev "hw:sofchtmax98090" - - cset "name='Left Speaker Mixer Left DAC Switch' on" - cset "name='Right Speaker Mixer Right DAC Switch' on" - cset "name='Digital EQ 3 Band Switch' off" - cset "name='Digital EQ 5 Band Switch' off" - cset "name='Digital EQ 7 Band Switch' off" - cset "name='Biquad Switch' off" - cset "name='Filter Mode' Music" - cset "name='ADC Oversampling Rate' 0" - - cset "name='DMIC Mux' DMIC" - cset "name='MIC2 Mux' IN34" - cset "name='MIC2 Volume' 10" - cset "name='MIC2 Boost Volume' 0" - - cset "name='ADCR Boost Volume' 4" - cset "name='ADCL Boost Volume' 4" - cset "name='ADCR Volume' 11" - cset "name='ADCL Volume' 11" - - cset "name='Headphone Volume' 10" - cset "name='Speaker Volume' 10" - - cset "name='Speaker Left Mixer Volume' 3" - cset "name='Speaker Right Mixer Volume' 3" - cset "name='Record Path DC Blocking' on" - cset "name='Playback Path DC Blocking' on" - - cset "name='Headphone Left Switch' off" - cset "name='Headphone Right Switch' off" - cset "name='Headphone Switch' off" - - cset "name='Speaker Left Switch' off" - cset "name='Speaker Right Switch' off" - cset "name='Ext Spk Switch' off" - - cset "name='Headset Mic Switch' off" - cset "name='Int Mic Switch' off" - ] - - DisableSequence [ - ] - - # ALSA PCM - Value { - # ALSA PCM device for HiFi - PlaybackPCM "hw:sofchtmax98090" - CapturePCM "hw:sofchtmax98090" - } -} - -SectionDevice."Headphone" { - Comment "Headphone" - - ConflictingDevice [ - "Speakers" - ] - - Value { - JackControl "Headphone Jack" - JackHWMute "Speakers" - } - - EnableSequence [ - cdev "hw:sofchtmax98090" - - cset "name='Headphone Left Switch' on" - cset "name='Headphone Right Switch' on" - cset "name='Headphone Switch' on" - ] - DisableSequence [ - cdev "hw:sofchtmax98090" - - cset "name='Headphone Left Switch' off" - cset "name='Headphone Right Switch' off" - cset "name='Headphone Switch' off" - ] - - Value { - PlaybackChannels 2 - } -} - -SectionDevice."Speakers" { - Comment "Speakers" - - ConflictingDevice [ - "Headphone" - ] - - EnableSequence [ - cdev "hw:sofchtmax98090" - - cset "name='Speaker Left Switch' on" - cset "name='Speaker Right Switch' on" - cset "name='Ext Spk Switch' on" - ] - DisableSequence [ - cdev "hw:sofchtmax98090" - - cset "name='Speaker Left Switch' off" - cset "name='Speaker Right Switch' off" - cset "name='Ext Spk Switch' off" - ] - - Value { - PlaybackChannels 2 - } -} - -SectionDevice."HeadsetMic" { - Comment "Headset Mic" - - Value { - JackControl "Headset Mic Jack" - #FIXME CaptureControl "MIC2" - } - - ConflictingDevice [ - "InternalMic" - ] - - EnableSequence [ - cdev "hw:sofchtmax98090" - - cset "name='Headset Mic Switch' on" - cset "name='DMIC Mux' ADC" - cset "name='Record Path DC Blocking' on" - ] - - DisableSequence [ - cdev "hw:sofchtmax98090" - - cset "name='Headset Mic Switch' off" - cset "name='DMIC Mux' DMIC" - cset "name='Record Path DC Blocking' off" - ] - - Value { - CaptureChannels 2 - } -} - -SectionDevice."InternalMic" { - Comment "Internal Mic" - - Value { - #FIXME CaptureControl "MIC2" - } - - ConflictingDevice [ - "HeadsetMic" - ] - - EnableSequence [ - cdev "hw:sofchtmax98090" - - cset "name='Int Mic Switch' on" - cset "name='DMIC Mux' DMIC" - cset "name='Record Path DC Blocking' off" - ] - - DisableSequence [ - cdev "hw:sofchtmax98090" - - cset "name='Int Mic Switch' off" - cset "name='DMIC Mux' ADC" - cset "name='Record Path DC Blocking' on" - ] - - Value { - CaptureChannels 2 - } -} diff --git a/ucm-config/cyan/sof-chtmax98090/sof-chtmax98090.conf b/ucm-config/cyan/sof-chtmax98090/sof-chtmax98090.conf deleted file mode 100644 index 6f735332..00000000 --- a/ucm-config/cyan/sof-chtmax98090/sof-chtmax98090.conf +++ /dev/null @@ -1,6 +0,0 @@ -Comment "sof-chtmax98090 internal card" - -SectionUseCase."HiFi" { - File "HiFi.conf" - Comment "Default" -} diff --git a/ucm-config/for_all_boards/Dell-WD15-Dock/Dell-WD15-Dock.conf b/ucm-config/for_all_boards/Dell-WD15-Dock/Dell-WD15-Dock.conf deleted file mode 100644 index 290758a3..00000000 --- a/ucm-config/for_all_boards/Dell-WD15-Dock/Dell-WD15-Dock.conf +++ /dev/null @@ -1,5 +0,0 @@ -Comment "USB-audio on Dell docking station" -SectionUseCase."HiFi" { - File "HiFi.conf" - Comment "Default" -} diff --git a/ucm-config/for_all_boards/Dell-WD15-Dock/HiFi.conf b/ucm-config/for_all_boards/Dell-WD15-Dock/HiFi.conf deleted file mode 100644 index 9b122582..00000000 --- a/ucm-config/for_all_boards/Dell-WD15-Dock/HiFi.conf +++ /dev/null @@ -1,43 +0,0 @@ -SectionVerb { - Value { - FullySpecifiedUCM "1" - } - EnableSequence [ - cdev "hw:Dock" - ] - DisableSequence [ - ] -} - -SectionDevice."Dock Headphone".0 { - Comment "Headphone" - - Value { - PlaybackPCM "hw:Dock,0" - JackType "always" - } -} - -SectionDevice."Dock Line Out".0 { - Value { - PlaybackPCM "hw:Dock,1" - JackType "always" - } - EnableSequence [ - cdev "hw:Dock" - cset "name='Line Playback Switch' on" - ] - DisableSequence [ - cdev "hw:Dock" - cset "name='Line Playback Switch' off" - ] -} - -SectionDevice."Dock Microphone".0 { - Comment "Microphone" - - Value { - CapturePCM "hw:Dock,0" - JackType "always" - } -} diff --git a/ucm-config/for_all_boards/README b/ucm-config/for_all_boards/README new file mode 100644 index 00000000..b5384358 --- /dev/null +++ b/ucm-config/for_all_boards/README @@ -0,0 +1,8 @@ +Regarding the two dead sym links WD15 Dock and WD19 Dock + +ALSA has added a ucm for the ucm the sym links they point to and the ucm +has been patched in the chromiumos overlay. Unfortunately the alsa-lib +installs via Makefile and make HATES files with spaces, so we are keeping +the sym links here (even though they appear dead) they are NOT. Once +deployed with alsa-lib 1.1.8 they will have a proper target on a dut. + diff --git a/ucm-config/gandof/HDA Intel PCH/HDA Intel PCH.conf b/ucm-config/gandof/HDA Intel PCH/HDA Intel PCH.conf deleted file mode 100644 index b38ce172..00000000 --- a/ucm-config/gandof/HDA Intel PCH/HDA Intel PCH.conf +++ /dev/null @@ -1,6 +0,0 @@ -Comment "Gandof internal card" - -SectionUseCase."HiFi" { - File "HiFi.conf" - Comment "Default" -} diff --git a/ucm-config/gandof/HDA Intel PCH/HiFi.conf b/ucm-config/gandof/HDA Intel PCH/HiFi.conf deleted file mode 100644 index 6174c0b9..00000000 --- a/ucm-config/gandof/HDA Intel PCH/HiFi.conf +++ /dev/null @@ -1,55 +0,0 @@ -SectionVerb { - Value { - OutputDspName "speaker_eq" - } - EnableSequence [ - cdev "hw:PCH" - - cset "name='Master Playback Switch' on" - cset "name='Headphone Playback Switch' off" - cset "name='Speaker Playback Switch' on" - - cset "name='Capture Switch' on" - cset "name='Capture Volume' 39" - cset "name='Mic Boost Volume' 2" - cset "name='Internal Mic Boost Volume' 1" - cset "name='Capture Source' 0" - ] - DisableSequence [ - ] -} - -SectionDevice."Headphone".0 { - Value { - JackName "Headphone Jack" - DspName "" - } - EnableSequence [ - cdev "hw:PCH" - - cset "name='Speaker Playback Switch' off" - cset "name='Headphone Playback Switch' on" - ] - DisableSequence [ - cdev "hw:PCH" - - cset "name='Headphone Playback Switch' off" - cset "name='Speaker Playback Switch' on" - ] -} - -SectionDevice."Mic".0 { - Value { - JackName "Mic Jack" - } - EnableSequence [ - cdev "hw:PCH" - - cset "name='Capture Source' 1" - ] - DisableSequence [ - cdev "hw:PCH" - - cset "name='Capture Source' 0" - ] -} diff --git a/ucm-config/glados/sklnau8825adi/HiFi.conf b/ucm-config/glados/sklnau8825adi/HiFi.conf index 3ca7f2a5..c10104dc 100644 --- a/ucm-config/glados/sklnau8825adi/HiFi.conf +++ b/ucm-config/glados/sklnau8825adi/HiFi.conf @@ -12,7 +12,7 @@ SectionVerb { cset "name='Headset Mic Switch' off" cset "name='BIQ Path Select' ADC" cset "name='BIQ Coefficients' 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" - cset "name='codec0_iv_in Switch' 1" + cset "name='codec0_iv_in Switch' 0" cset "name='media0_out mo codec0_in mi Switch' off" cset "name='media0_out mo dmic01_hifi_in mi Switch' on" cset "name='Pin 5 Mux' cvt 2" @@ -84,7 +84,6 @@ SectionDevice."Headphone".0 { EnableSequence [ cdev "hw:sklnau8825adi" - cset "name='codec0_iv_in Switch' 0" cset "name='codec0_out mo media0_in mi Switch' off" cset "name='codec1_out mo media0_in mi Switch' on" cset "name='Headphone Jack Switch' on" @@ -95,7 +94,6 @@ SectionDevice."Headphone".0 { cset "name='codec0_out mo media0_in mi Switch' on" cset "name='codec1_out mo media0_in mi Switch' off" cset "name='Headphone Jack Switch' off" - cset "name='codec0_iv_in Switch' 1" ] } diff --git a/ucm-config/lulu/HDA Intel PCH/HDA Intel PCH.conf b/ucm-config/lulu/HDA Intel PCH/HDA Intel PCH.conf deleted file mode 100644 index f5bbcb2f..00000000 --- a/ucm-config/lulu/HDA Intel PCH/HDA Intel PCH.conf +++ /dev/null @@ -1,6 +0,0 @@ -Comment "Lulu internal card" - -SectionUseCase."HiFi" { - File "HiFi.conf" - Comment "Default" -} diff --git a/ucm-config/lulu/HDA Intel PCH/HiFi.conf b/ucm-config/lulu/HDA Intel PCH/HiFi.conf deleted file mode 100644 index 6174c0b9..00000000 --- a/ucm-config/lulu/HDA Intel PCH/HiFi.conf +++ /dev/null @@ -1,55 +0,0 @@ -SectionVerb { - Value { - OutputDspName "speaker_eq" - } - EnableSequence [ - cdev "hw:PCH" - - cset "name='Master Playback Switch' on" - cset "name='Headphone Playback Switch' off" - cset "name='Speaker Playback Switch' on" - - cset "name='Capture Switch' on" - cset "name='Capture Volume' 39" - cset "name='Mic Boost Volume' 2" - cset "name='Internal Mic Boost Volume' 1" - cset "name='Capture Source' 0" - ] - DisableSequence [ - ] -} - -SectionDevice."Headphone".0 { - Value { - JackName "Headphone Jack" - DspName "" - } - EnableSequence [ - cdev "hw:PCH" - - cset "name='Speaker Playback Switch' off" - cset "name='Headphone Playback Switch' on" - ] - DisableSequence [ - cdev "hw:PCH" - - cset "name='Headphone Playback Switch' off" - cset "name='Speaker Playback Switch' on" - ] -} - -SectionDevice."Mic".0 { - Value { - JackName "Mic Jack" - } - EnableSequence [ - cdev "hw:PCH" - - cset "name='Capture Source' 1" - ] - DisableSequence [ - cdev "hw:PCH" - - cset "name='Capture Source' 0" - ] -} diff --git a/ucm-config/veyron/VEYRON-I2S/HiFi.conf b/ucm-config/veyron/VEYRON-I2S/HiFi.conf index 0444d5d5..2698529d 100644 --- a/ucm-config/veyron/VEYRON-I2S/HiFi.conf +++ b/ucm-config/veyron/VEYRON-I2S/HiFi.conf @@ -10,8 +10,6 @@ SectionVerb { cset "name='Left Speaker Mixer Left DAC Switch' on" cset "name='Right Speaker Mixer Right DAC Switch' on" - cset "name='Headphone Left Switch' off" - cset "name='Headphone Right Switch' off" cset "name='Digital EQ 3 Band Switch' off" cset "name='Digital EQ 5 Band Switch' off" cset "name='Digital EQ 7 Band Switch' off" @@ -39,9 +37,15 @@ SectionVerb { cset "name='Record Path DC Blocking' on" cset "name='Playback Path DC Blocking' on" - cset "name='Speaker Left Switch' on" - cset "name='Speaker Right Switch' on" - cset "name='Speaker Switch' on" + cset "name='Speaker Left Switch' off" + cset "name='Speaker Right Switch' off" + cset "name='Speaker Switch' off" + + cset "name='Headphone Switch' off" + cset "name='HP Left Out Switch' off" + cset "name='HP Right Out Switch' off" + cset "name='Headphone Left Switch' on" + cset "name='Headphone Right Switch' on" ] DisableSequence [ @@ -56,12 +60,16 @@ SectionDevice."Speaker".0 { EnableSequence [ cdev "hw:VEYRONI2S" + cset "name='Speaker Left Switch' on" + cset "name='Speaker Right Switch' on" cset "name='Speaker Switch' on" ] DisableSequence [ cdev "hw:VEYRONI2S" cset "name='Speaker Switch' off" + cset "name='Speaker Left Switch' off" + cset "name='Speaker Right Switch' off" ] } @@ -87,25 +95,23 @@ SectionDevice."Headphone".0 { PlaybackPCM "hw:VEYRONI2S,0" MixerName "Headphone" JackType "gpio" - JackName "ROCKCHIP-I2S Headset Jack" + JackName "VEYRON-I2S Headset Jack" OutputDspName "" } EnableSequence [ cdev "hw:VEYRONI2S" - cset "name='Speaker Switch' off" + cset "name='HP Left Out Switch' on" + cset "name='HP Right Out Switch' on" cset "name='Headphone Switch' on" - cset "name='Headphone Left Switch' on" - cset "name='Headphone Right Switch' on" ] DisableSequence [ cdev "hw:VEYRONI2S" - cset "name='Headphone Left Switch' off" - cset "name='Headphone Right Switch' off" cset "name='Headphone Switch' off" - cset "name='Speaker Switch' on" + cset "name='HP Left Out Switch' off" + cset "name='HP Right Out Switch' off" ] } @@ -114,7 +120,7 @@ SectionDevice."Mic".0 { CapturePCM "hw:VEYRONI2S,0" MixerName "Headset Mic" JackType "gpio" - JackName "ROCKCHIP-I2S Headset Jack" + JackName "VEYRON-I2S Headset Jack" } EnableSequence [ @@ -135,3 +141,18 @@ SectionDevice."Mic".0 { cset "name='Record Path DC Blocking' off" ] } + +SectionDevice."HDMI".0 { + Value { + PlaybackPCM "hw:VEYRONI2S,1" + JackName "VEYRON-I2S HDMI Jack" + JackType "gpio" + EDIDFile "/sys/class/drm/card1-HDMI-A-1/edid" + } + EnableSequence [ + cdev "hw:VEYRONI2S" + ] + DisableSequence [ + cdev "hw:VEYRONI2S" + ] +} diff --git a/ucm-config/veyron_fievel/VEYRON-I2S/HiFi.conf b/ucm-config/veyron_fievel/VEYRON-I2S/HiFi.conf index b5c120da..f23f3bc4 100644 --- a/ucm-config/veyron_fievel/VEYRON-I2S/HiFi.conf +++ b/ucm-config/veyron_fievel/VEYRON-I2S/HiFi.conf @@ -10,8 +10,6 @@ SectionVerb { cset "name='Left Speaker Mixer Left DAC Switch' on" cset "name='Right Speaker Mixer Right DAC Switch' on" - cset "name='Headphone Left Switch' off" - cset "name='Headphone Right Switch' off" cset "name='Digital EQ 3 Band Switch' off" cset "name='Digital EQ 5 Band Switch' off" cset "name='Digital EQ 7 Band Switch' off" @@ -39,9 +37,15 @@ SectionVerb { cset "name='Record Path DC Blocking' on" cset "name='Playback Path DC Blocking' on" - cset "name='Speaker Left Switch' on" - cset "name='Speaker Right Switch' on" - cset "name='Speaker Switch' on" + cset "name='Speaker Left Switch' off" + cset "name='Speaker Right Switch' off" + cset "name='Speaker Switch' off" + + cset "name='Headphone Switch' off" + cset "name='HP Left Out Switch' off" + cset "name='HP Right Out Switch' off" + cset "name='Headphone Left Switch' on" + cset "name='Headphone Right Switch' on" ] DisableSequence [ @@ -53,25 +57,23 @@ SectionDevice."Headphone".0 { PlaybackPCM "hw:VEYRONI2S,0" MixerName "Headphone" JackType "gpio" - JackName "ROCKCHIP-I2S Headset Jack" + JackName "VEYRON-I2S Headset Jack" OutputDspName "" } EnableSequence [ cdev "hw:VEYRONI2S" - cset "name='Speaker Switch' off" + cset "name='HP Left Out Switch' on" + cset "name='HP Right Out Switch' on" cset "name='Headphone Switch' on" - cset "name='Headphone Left Switch' on" - cset "name='Headphone Right Switch' on" ] DisableSequence [ cdev "hw:VEYRONI2S" - cset "name='Headphone Left Switch' off" - cset "name='Headphone Right Switch' off" cset "name='Headphone Switch' off" - cset "name='Speaker Switch' on" + cset "name='HP Left Out Switch' off" + cset "name='HP Right Out Switch' off" ] } @@ -80,7 +82,7 @@ SectionDevice."Mic".0 { CapturePCM "hw:VEYRONI2S,0" MixerName "Headset Mic" JackType "gpio" - JackName "ROCKCHIP-I2S Headset Jack" + JackName "VEYRON-I2S Headset Jack" } EnableSequence [ @@ -101,3 +103,18 @@ SectionDevice."Mic".0 { cset "name='Record Path DC Blocking' off" ] } + +SectionDevice."HDMI".0 { + Value { + PlaybackPCM "hw:VEYRONI2S,1" + JackName "VEYRON-I2S HDMI Jack" + JackType "gpio" + EDIDFile "/sys/class/drm/card1-HDMI-A-1/edid" + } + EnableSequence [ + cdev "hw:VEYRONI2S" + ] + DisableSequence [ + cdev "hw:VEYRONI2S" + ] +} diff --git a/ucm-config/veyron_jaq/VEYRON-I2S/HiFi.conf b/ucm-config/veyron_jaq/VEYRON-I2S/HiFi.conf index 672ddc7e..2698529d 100644 --- a/ucm-config/veyron_jaq/VEYRON-I2S/HiFi.conf +++ b/ucm-config/veyron_jaq/VEYRON-I2S/HiFi.conf @@ -10,8 +10,6 @@ SectionVerb { cset "name='Left Speaker Mixer Left DAC Switch' on" cset "name='Right Speaker Mixer Right DAC Switch' on" - cset "name='Headphone Left Switch' off" - cset "name='Headphone Right Switch' off" cset "name='Digital EQ 3 Band Switch' off" cset "name='Digital EQ 5 Band Switch' off" cset "name='Digital EQ 7 Band Switch' off" @@ -39,14 +37,15 @@ SectionVerb { cset "name='Record Path DC Blocking' on" cset "name='Playback Path DC Blocking' on" - cset "name='Speaker Left Switch' on" - cset "name='Speaker Right Switch' on" - cset "name='Speaker Switch' on" + cset "name='Speaker Left Switch' off" + cset "name='Speaker Right Switch' off" + cset "name='Speaker Switch' off" - cset "name='Left Speaker Mixer Left DAC Switch' off" - cset "name='Right Speaker Mixer Right DAC Switch' off" - cset "name='Left Speaker Mixer Right DAC Switch' on" - cset "name='Right Speaker Mixer Left DAC Switch' on" + cset "name='Headphone Switch' off" + cset "name='HP Left Out Switch' off" + cset "name='HP Right Out Switch' off" + cset "name='Headphone Left Switch' on" + cset "name='Headphone Right Switch' on" ] DisableSequence [ @@ -61,12 +60,16 @@ SectionDevice."Speaker".0 { EnableSequence [ cdev "hw:VEYRONI2S" + cset "name='Speaker Left Switch' on" + cset "name='Speaker Right Switch' on" cset "name='Speaker Switch' on" ] DisableSequence [ cdev "hw:VEYRONI2S" cset "name='Speaker Switch' off" + cset "name='Speaker Left Switch' off" + cset "name='Speaker Right Switch' off" ] } @@ -92,25 +95,23 @@ SectionDevice."Headphone".0 { PlaybackPCM "hw:VEYRONI2S,0" MixerName "Headphone" JackType "gpio" - JackName "ROCKCHIP-I2S Headset Jack" + JackName "VEYRON-I2S Headset Jack" OutputDspName "" } EnableSequence [ cdev "hw:VEYRONI2S" - cset "name='Speaker Switch' off" + cset "name='HP Left Out Switch' on" + cset "name='HP Right Out Switch' on" cset "name='Headphone Switch' on" - cset "name='Headphone Left Switch' on" - cset "name='Headphone Right Switch' on" ] DisableSequence [ cdev "hw:VEYRONI2S" - cset "name='Headphone Left Switch' off" - cset "name='Headphone Right Switch' off" cset "name='Headphone Switch' off" - cset "name='Speaker Switch' on" + cset "name='HP Left Out Switch' off" + cset "name='HP Right Out Switch' off" ] } @@ -119,7 +120,7 @@ SectionDevice."Mic".0 { CapturePCM "hw:VEYRONI2S,0" MixerName "Headset Mic" JackType "gpio" - JackName "ROCKCHIP-I2S Headset Jack" + JackName "VEYRON-I2S Headset Jack" } EnableSequence [ @@ -140,3 +141,18 @@ SectionDevice."Mic".0 { cset "name='Record Path DC Blocking' off" ] } + +SectionDevice."HDMI".0 { + Value { + PlaybackPCM "hw:VEYRONI2S,1" + JackName "VEYRON-I2S HDMI Jack" + JackType "gpio" + EDIDFile "/sys/class/drm/card1-HDMI-A-1/edid" + } + EnableSequence [ + cdev "hw:VEYRONI2S" + ] + DisableSequence [ + cdev "hw:VEYRONI2S" + ] +} diff --git a/ucm-config/veyron_minnie/VEYRON-I2S/HiFi.conf b/ucm-config/veyron_minnie/VEYRON-I2S/HiFi.conf index ba9f535c..fd4e6a84 100644 --- a/ucm-config/veyron_minnie/VEYRON-I2S/HiFi.conf +++ b/ucm-config/veyron_minnie/VEYRON-I2S/HiFi.conf @@ -10,8 +10,6 @@ SectionVerb { cset "name='Left Speaker Mixer Left DAC Switch' on" cset "name='Right Speaker Mixer Right DAC Switch' on" - cset "name='Headphone Left Switch' off" - cset "name='Headphone Right Switch' off" cset "name='Digital EQ 3 Band Switch' off" cset "name='Digital EQ 5 Band Switch' off" cset "name='Digital EQ 7 Band Switch' off" @@ -39,9 +37,15 @@ SectionVerb { cset "name='Record Path DC Blocking' on" cset "name='Playback Path DC Blocking' on" - cset "name='Speaker Left Switch' on" - cset "name='Speaker Right Switch' on" - cset "name='Speaker Switch' on" + cset "name='Speaker Left Switch' off" + cset "name='Speaker Right Switch' off" + cset "name='Speaker Switch' off" + + cset "name='Headphone Switch' off" + cset "name='HP Left Out Switch' off" + cset "name='HP Right Out Switch' off" + cset "name='Headphone Left Switch' on" + cset "name='Headphone Right Switch' on" ] DisableSequence [ @@ -56,12 +60,16 @@ SectionDevice."Speaker".0 { EnableSequence [ cdev "hw:VEYRONI2S" + cset "name='Speaker Left Switch' on" + cset "name='Speaker Right Switch' on" cset "name='Speaker Switch' on" ] DisableSequence [ cdev "hw:VEYRONI2S" cset "name='Speaker Switch' off" + cset "name='Speaker Left Switch' off" + cset "name='Speaker Right Switch' off" ] } @@ -87,25 +95,23 @@ SectionDevice."Headphone".0 { PlaybackPCM "hw:VEYRONI2S,0" MixerName "Headphone" JackType "gpio" - JackName "ROCKCHIP-I2S Headset Jack" + JackName "VEYRON-I2S Headset Jack" OutputDspName "" } EnableSequence [ cdev "hw:VEYRONI2S" - cset "name='Speaker Switch' off" + cset "name='HP Left Out Switch' on" + cset "name='HP Right Out Switch' on" cset "name='Headphone Switch' on" - cset "name='Headphone Left Switch' on" - cset "name='Headphone Right Switch' on" ] DisableSequence [ cdev "hw:VEYRONI2S" - cset "name='Headphone Left Switch' off" - cset "name='Headphone Right Switch' off" cset "name='Headphone Switch' off" - cset "name='Speaker Switch' on" + cset "name='HP Left Out Switch' off" + cset "name='HP Right Out Switch' off" ] } @@ -114,7 +120,7 @@ SectionDevice."Mic".0 { CapturePCM "hw:VEYRONI2S,0" MixerName "Headset Mic" JackType "gpio" - JackName "ROCKCHIP-I2S Headset Jack" + JackName "VEYRON-I2S Headset Jack" } EnableSequence [ @@ -135,3 +141,18 @@ SectionDevice."Mic".0 { cset "name='Record Path DC Blocking' off" ] } + +SectionDevice."HDMI".0 { + Value { + PlaybackPCM "hw:VEYRONI2S,1" + JackName "VEYRON-I2S HDMI Jack" + JackType "gpio" + EDIDFile "/sys/class/drm/card1-HDMI-A-1/edid" + } + EnableSequence [ + cdev "hw:VEYRONI2S" + ] + DisableSequence [ + cdev "hw:VEYRONI2S" + ] +} diff --git a/ucm-config/veyron_speedy/VEYRON-I2S/HiFi.conf b/ucm-config/veyron_speedy/VEYRON-I2S/HiFi.conf index ba9f535c..fd4e6a84 100644 --- a/ucm-config/veyron_speedy/VEYRON-I2S/HiFi.conf +++ b/ucm-config/veyron_speedy/VEYRON-I2S/HiFi.conf @@ -10,8 +10,6 @@ SectionVerb { cset "name='Left Speaker Mixer Left DAC Switch' on" cset "name='Right Speaker Mixer Right DAC Switch' on" - cset "name='Headphone Left Switch' off" - cset "name='Headphone Right Switch' off" cset "name='Digital EQ 3 Band Switch' off" cset "name='Digital EQ 5 Band Switch' off" cset "name='Digital EQ 7 Band Switch' off" @@ -39,9 +37,15 @@ SectionVerb { cset "name='Record Path DC Blocking' on" cset "name='Playback Path DC Blocking' on" - cset "name='Speaker Left Switch' on" - cset "name='Speaker Right Switch' on" - cset "name='Speaker Switch' on" + cset "name='Speaker Left Switch' off" + cset "name='Speaker Right Switch' off" + cset "name='Speaker Switch' off" + + cset "name='Headphone Switch' off" + cset "name='HP Left Out Switch' off" + cset "name='HP Right Out Switch' off" + cset "name='Headphone Left Switch' on" + cset "name='Headphone Right Switch' on" ] DisableSequence [ @@ -56,12 +60,16 @@ SectionDevice."Speaker".0 { EnableSequence [ cdev "hw:VEYRONI2S" + cset "name='Speaker Left Switch' on" + cset "name='Speaker Right Switch' on" cset "name='Speaker Switch' on" ] DisableSequence [ cdev "hw:VEYRONI2S" cset "name='Speaker Switch' off" + cset "name='Speaker Left Switch' off" + cset "name='Speaker Right Switch' off" ] } @@ -87,25 +95,23 @@ SectionDevice."Headphone".0 { PlaybackPCM "hw:VEYRONI2S,0" MixerName "Headphone" JackType "gpio" - JackName "ROCKCHIP-I2S Headset Jack" + JackName "VEYRON-I2S Headset Jack" OutputDspName "" } EnableSequence [ cdev "hw:VEYRONI2S" - cset "name='Speaker Switch' off" + cset "name='HP Left Out Switch' on" + cset "name='HP Right Out Switch' on" cset "name='Headphone Switch' on" - cset "name='Headphone Left Switch' on" - cset "name='Headphone Right Switch' on" ] DisableSequence [ cdev "hw:VEYRONI2S" - cset "name='Headphone Left Switch' off" - cset "name='Headphone Right Switch' off" cset "name='Headphone Switch' off" - cset "name='Speaker Switch' on" + cset "name='HP Left Out Switch' off" + cset "name='HP Right Out Switch' off" ] } @@ -114,7 +120,7 @@ SectionDevice."Mic".0 { CapturePCM "hw:VEYRONI2S,0" MixerName "Headset Mic" JackType "gpio" - JackName "ROCKCHIP-I2S Headset Jack" + JackName "VEYRON-I2S Headset Jack" } EnableSequence [ @@ -135,3 +141,18 @@ SectionDevice."Mic".0 { cset "name='Record Path DC Blocking' off" ] } + +SectionDevice."HDMI".0 { + Value { + PlaybackPCM "hw:VEYRONI2S,1" + JackName "VEYRON-I2S HDMI Jack" + JackType "gpio" + EDIDFile "/sys/class/drm/card1-HDMI-A-1/edid" + } + EnableSequence [ + cdev "hw:VEYRONI2S" + ] + DisableSequence [ + cdev "hw:VEYRONI2S" + ] +} |