Snap for 6439596 from 068d7ff1228db05a89b69066f37816d76275fdf3 to qt-aml-tzdata-release

Change-Id: I1c3706d08346fdf15db691d4ef1b10f020aa5655
diff --git a/.clang-format b/.clang-format
deleted file mode 100644
index c2b2075..0000000
--- a/.clang-format
+++ /dev/null
@@ -1,129 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0
-#
-# clang-format configuration file. Intended for clang-format >= 4.
-#
-# For more information, see:
-#
-#   Documentation/process/clang-format.rst
-#   https://clang.llvm.org/docs/ClangFormat.html
-#   https://clang.llvm.org/docs/ClangFormatStyleOptions.html
-#
----
-AccessModifierOffset: -4
-AlignAfterOpenBracket: Align
-AlignConsecutiveAssignments: false
-AlignConsecutiveDeclarations: false
-#AlignEscapedNewlines: Left # Unknown to clang-format-4.0
-AlignOperands: true
-AlignTrailingComments: false
-AllowAllParametersOfDeclarationOnNextLine: false
-AllowShortBlocksOnASingleLine: false
-AllowShortCaseLabelsOnASingleLine: false
-AllowShortFunctionsOnASingleLine: None
-AllowShortIfStatementsOnASingleLine: false
-AllowShortLoopsOnASingleLine: false
-AlwaysBreakAfterDefinitionReturnType: None
-AlwaysBreakAfterReturnType: None
-AlwaysBreakBeforeMultilineStrings: false
-AlwaysBreakTemplateDeclarations: false
-BinPackArguments: true
-BinPackParameters: true
-BraceWrapping:
-  AfterClass: false
-  AfterControlStatement: false
-  AfterEnum: false
-  AfterFunction: true
-  AfterNamespace: true
-  AfterObjCDeclaration: false
-  AfterStruct: false
-  AfterUnion: false
-  #AfterExternBlock: false # Unknown to clang-format-5.0
-  BeforeCatch: false
-  BeforeElse: false
-  IndentBraces: false
-  #SplitEmptyFunction: true # Unknown to clang-format-4.0
-  #SplitEmptyRecord: true # Unknown to clang-format-4.0
-  #SplitEmptyNamespace: true # Unknown to clang-format-4.0
-BreakBeforeBinaryOperators: None
-BreakBeforeBraces: Custom
-#BreakBeforeInheritanceComma: false # Unknown to clang-format-4.0
-BreakBeforeTernaryOperators: false
-BreakConstructorInitializersBeforeComma: false
-#BreakConstructorInitializers: BeforeComma # Unknown to clang-format-4.0
-BreakAfterJavaFieldAnnotations: false
-BreakStringLiterals: false
-ColumnLimit: 80
-CommentPragmas: '^ IWYU pragma:'
-#CompactNamespaces: false # Unknown to clang-format-4.0
-ConstructorInitializerAllOnOneLineOrOnePerLine: false
-ConstructorInitializerIndentWidth: 8
-ContinuationIndentWidth: 8
-Cpp11BracedListStyle: false
-DerivePointerAlignment: false
-DisableFormat: false
-ExperimentalAutoDetectBinPacking: false
-#FixNamespaceComments: false # Unknown to clang-format-4.0
-
-# Taken from:
-#   git grep -h '^#define [^[:space:]]*FOREACH[^[:space:]]*(' cras/ \
-#   | sed "s,^#define \([^[:space:]]*FOREACH[^[:space:]]*\)(.*$,  - '\1'," \
-#   | sort | uniq
-ForEachMacros:
-  - 'ARRAY_ELEMENT_FOREACH'
-  - 'DL_FOREACH'
-  - 'DL_FOREACH_INTERNAL'
-  - 'LL_FOREACH'
-  - 'LL_FOREACH_SAFE'
-
-#IncludeBlocks: Preserve # Unknown to clang-format-5.0
-IncludeCategories:
-  - Regex: '.*'
-    Priority: 1
-IncludeIsMainRegex: '(Test)?$'
-IndentCaseLabels: false
-#IndentPPDirectives: None # Unknown to clang-format-5.0
-IndentWidth: 8
-IndentWrappedFunctionNames: false
-JavaScriptQuotes: Leave
-JavaScriptWrapImports: true
-KeepEmptyLinesAtTheStartOfBlocks: false
-MacroBlockBegin: ''
-MacroBlockEnd: ''
-MaxEmptyLinesToKeep: 1
-NamespaceIndentation: Inner
-#ObjCBinPackProtocolList: Auto # Unknown to clang-format-5.0
-ObjCBlockIndentWidth: 8
-ObjCSpaceAfterProperty: true
-ObjCSpaceBeforeProtocolList: true
-
-# Taken from git's rules
-#PenaltyBreakAssignment: 10 # Unknown to clang-format-4.0
-PenaltyBreakBeforeFirstCallParameter: 30
-PenaltyBreakComment: 10
-PenaltyBreakFirstLessLess: 0
-PenaltyBreakString: 10
-PenaltyExcessCharacter: 100
-PenaltyReturnTypeOnItsOwnLine: 60
-
-PointerAlignment: Right
-ReflowComments: false
-SortIncludes: false
-#SortUsingDeclarations: false # Unknown to clang-format-4.0
-SpaceAfterCStyleCast: false
-SpaceAfterTemplateKeyword: true
-SpaceBeforeAssignmentOperators: true
-#SpaceBeforeCtorInitializerColon: true # Unknown to clang-format-5.0
-#SpaceBeforeInheritanceColon: true # Unknown to clang-format-5.0
-SpaceBeforeParens: ControlStatements
-#SpaceBeforeRangeBasedForLoopColon: true # Unknown to clang-format-5.0
-SpaceInEmptyParentheses: false
-SpacesBeforeTrailingComments: 1
-SpacesInAngles: false
-SpacesInContainerLiterals: false
-SpacesInCStyleCastParentheses: false
-SpacesInParentheses: false
-SpacesInSquareBrackets: false
-Standard: Cpp03
-TabWidth: 8
-UseTab: Always
-...
diff --git a/Makefile b/Makefile
index 798f576..2be9ec9 100644
--- a/Makefile
+++ b/Makefile
@@ -18,8 +18,6 @@
 	$(INSTALL) --mode 755 -d $(DESTDIR)usr/bin/
 	$(INSTALL) --mode 755 -D $(ADHD_DIR)/scripts/audio_diagnostics \
 		$(DESTDIR)usr/bin/
-	$(INSTALL) --mode 755 -D $(ADHD_DIR)/scripts/asoc_dapm_graph \
-		$(DESTDIR)usr/bin/
 
 cras_init_upstart:	$(ADHD_DIR)/init/cras.conf
 	$(ECHO) "Installing upstart file"
@@ -56,9 +54,6 @@
 	$(ECHO) "Installing '$<' to '$@'"
 	$(INSTALL) --mode 644 -D $< $@
 
-# Note: $(BOARD) usage is deprecated.  Configs should be added in board overlays
-# or via cros_config data for newer unibuild systems.
-
 optional_alsa_conf := $(wildcard $(ADHD_DIR)/alsa-module-config/alsa-$(BOARD).conf)
 
 ifneq ($(strip $(optional_alsa_conf)),)
diff --git a/OWNERS b/OWNERS
index d8563fb..79cff9d 100644
--- a/OWNERS
+++ b/OWNERS
@@ -1,17 +1,18 @@
 cychiang@chromium.org
 dgreid@chromium.org
 hychao@chromium.org
+louiscollard@chromium.org
 paulhsia@chromium.org
 tzungbi@chromium.org
+wuchengli@chromium.org
 yuhsuan@chromium.org
 
 # For AOSP
 cychiang@google.com
 dgreid@google.com
 hychao@google.com
+louiscollard@google.com
 paulhsia@google.com
 tzungbi@google.com
+wuchengli@google.com
 yuhsuan@google.com
-
-# So any team members can +2
-*
diff --git a/OWNERS.android b/OWNERS.android
deleted file mode 100644
index 47d8383..0000000
--- a/OWNERS.android
+++ /dev/null
@@ -1,4 +0,0 @@
-adelva@google.com
-jemoreira@google.com
-jeffv@google.com
-ivanlozano@google.com
diff --git a/PRESUBMIT.cfg b/PRESUBMIT.cfg
index c0e6ae9..d4d5410 100644
--- a/PRESUBMIT.cfg
+++ b/PRESUBMIT.cfg
@@ -1,12 +1,2 @@
 [Hook Overrides]
 tab_check: false
-clang_format_check: true
-
-# On by default, but required for options below.
-cros_license_check: true
-
-[Hook Overrides Options]
-# Ignore HiFi file
-cros_license_check: --exclude_regex=HiFi\.conf$
-clang_format_check:
-  cras/
diff --git a/adhdinfo/Makefile b/adhdinfo/Makefile
new file mode 100644
index 0000000..0819a58
--- /dev/null
+++ b/adhdinfo/Makefile
@@ -0,0 +1,15 @@
+# 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
new file mode 100644
index 0000000..0589238
--- /dev/null
+++ b/adhdinfo/main.c
@@ -0,0 +1,69 @@
+/* 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
new file mode 100644
index 0000000..6e595b0
--- /dev/null
+++ b/alsa-module-config/alsa-auron.conf
@@ -0,0 +1 @@
+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
new file mode 100644
index 0000000..e0925ea
--- /dev/null
+++ b/alsa-module-config/alsa-auron_paine.conf
@@ -0,0 +1 @@
+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
new file mode 100644
index 0000000..937e048
--- /dev/null
+++ b/alsa-module-config/alsa-auron_yuna.conf
@@ -0,0 +1 @@
+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
new file mode 100644
index 0000000..5578f5c
--- /dev/null
+++ b/alsa-module-config/alsa-gandof.conf
@@ -0,0 +1 @@
+options snd_hda_intel model=gandof patch=,gandof_alsa.fw
diff --git a/alsa-module-config/alsa-guado.conf b/alsa-module-config/alsa-guado.conf
new file mode 100644
index 0000000..687aeb6
--- /dev/null
+++ b/alsa-module-config/alsa-guado.conf
@@ -0,0 +1 @@
+options snd_hda_intel model=guado patch=,guado_alsa.fw
diff --git a/alsa-module-config/alsa-lulu.conf b/alsa-module-config/alsa-lulu.conf
new file mode 100644
index 0000000..b4f05d8
--- /dev/null
+++ b/alsa-module-config/alsa-lulu.conf
@@ -0,0 +1 @@
+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
new file mode 100644
index 0000000..40ac817
--- /dev/null
+++ b/alsa-module-config/auron_alsa.fw
@@ -0,0 +1,9 @@
+[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
new file mode 100644
index 0000000..40ac817
--- /dev/null
+++ b/alsa-module-config/auron_paine_alsa.fw
@@ -0,0 +1,9 @@
+[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
new file mode 100644
index 0000000..40ac817
--- /dev/null
+++ b/alsa-module-config/auron_yuna_alsa.fw
@@ -0,0 +1,9 @@
+[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
new file mode 100644
index 0000000..40ac817
--- /dev/null
+++ b/alsa-module-config/gandof_alsa.fw
@@ -0,0 +1,9 @@
+[codec]
+0x10ec0283 0x10ec0283 0
+
+[model]
+alc283-dac-wcaps
+
+[hint]
+auto_mute = no
+auto_mic = no
diff --git a/alsa-module-config/guado_alsa.fw b/alsa-module-config/guado_alsa.fw
new file mode 100644
index 0000000..40ac817
--- /dev/null
+++ b/alsa-module-config/guado_alsa.fw
@@ -0,0 +1,9 @@
+[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
new file mode 100644
index 0000000..40ac817
--- /dev/null
+++ b/alsa-module-config/lulu_alsa.fw
@@ -0,0 +1,9 @@
+[codec]
+0x10ec0283 0x10ec0283 0
+
+[model]
+alc283-dac-wcaps
+
+[hint]
+auto_mute = no
+auto_mic = no
diff --git a/audio_streams/Android.bp b/audio_streams/Android.bp
deleted file mode 100644
index 3e78e56..0000000
--- a/audio_streams/Android.bp
+++ /dev/null
@@ -1,7 +0,0 @@
-rust_library_host_rlib {
-    name: "libaudio_streams",
-    deny_warnings: false,
-    crate_name: "audio_streams",
-    edition: "2018",
-    srcs: ["src/audio_streams.rs"],
-}
diff --git a/audio_streams/Cargo.toml b/audio_streams/Cargo.toml
deleted file mode 100644
index 54e6af6..0000000
--- a/audio_streams/Cargo.toml
+++ /dev/null
@@ -1,10 +0,0 @@
-[package]
-name = "audio_streams"
-version = "0.1.0"
-authors = ["The Chromium OS Authors"]
-edition = "2018"
-
-[lib]
-path = "src/audio_streams.rs"
-
-[dependencies]
diff --git a/audio_streams/README.md b/audio_streams/README.md
deleted file mode 100644
index b62c294..0000000
--- a/audio_streams/README.md
+++ /dev/null
@@ -1,6 +0,0 @@
-# Audio Server and Stream interfaces
-
-The `audio_streams` crate provides a basic interface for playing audio.
-This will be used to enable playback to various audio subsystems such as
-Alsa and cras. To start, an empty playback example `DummyStreamSource`
-is provided.
diff --git a/audio_streams/src/audio_streams.rs b/audio_streams/src/audio_streams.rs
deleted file mode 100644
index 672034b..0000000
--- a/audio_streams/src/audio_streams.rs
+++ /dev/null
@@ -1,363 +0,0 @@
-// 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.
-
-//! Provides an interface for playing and recording audio.
-//!
-//! When implementing an audio playback system, the `StreamSource` trait is implemented.
-//! Implementors of this trait allow creation of `PlaybackBufferStream` objects. The
-//! `PlaybackBufferStream` provides the actual audio buffers to be filled with audio samples. These
-//! buffers are obtained by calling `next_playback_buffer`.
-//!
-//! Users playing audio fill the provided buffers with audio. When a `PlaybackBuffer` is dropped,
-//! the samples written to it are committed to the `PlaybackBufferStream` it came from.
-//!
-//! ```
-//! use audio_streams::{StreamSource, DummyStreamSource};
-//! use std::io::Write;
-//!
-//! const buffer_size: usize = 120;
-//! const num_channels: usize = 2;
-//! const frame_size: usize = num_channels * 2; // 16-bit samples are two bytes.
-//!
-//! # fn main() -> std::result::Result<(), Box<std::error::Error>> {
-//! let mut stream_source = DummyStreamSource::new();
-//!
-//! let (_, mut stream) = stream_source
-//!     .new_playback_stream(num_channels, 48000, buffer_size)?;
-//! // Play 10 buffers of DC.
-//! let pb_bufs = [[0xa5u8; buffer_size * frame_size]; 10];
-//! for pb_buf in &pb_bufs {
-//!     let mut stream_buffer = stream.next_playback_buffer()?;
-//!     assert_eq!(stream_buffer.write(pb_buf)?, buffer_size * frame_size);
-//! }
-//! # Ok (())
-//! # }
-//! ```
-
-use std::error;
-use std::fmt::{self, Display};
-use std::io::{self, Write};
-use std::os::unix::io::RawFd;
-use std::result::Result;
-use std::time::{Duration, Instant};
-
-pub mod capture;
-
-/// `StreamSource` creates streams for playback or capture of audio.
-pub trait StreamSource: Send {
-    /// Returns a stream control and buffer generator object. These are separate as the buffer
-    /// generator might want to be passed to the audio stream.
-    fn new_playback_stream(
-        &mut self,
-        num_channels: usize,
-        frame_rate: usize,
-        buffer_size: usize,
-    ) -> 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.
-    /// Default implementation returns `DummyStreamControl` and `DummyCaptureStream`.
-    fn new_capture_stream(
-        &mut self,
-        num_channels: usize,
-        frame_rate: usize,
-        buffer_size: usize,
-    ) -> Result<
-        (
-            Box<dyn StreamControl>,
-            Box<dyn capture::CaptureBufferStream>,
-        ),
-        Box<dyn error::Error>,
-    > {
-        Ok((
-            Box::new(DummyStreamControl::new()),
-            Box::new(capture::DummyCaptureStream::new(
-                num_channels,
-                frame_rate,
-                buffer_size,
-            )),
-        ))
-    }
-
-    /// Returns any open file descriptors needed by the implementor. The FD list helps users of the
-    /// StreamSource enter Linux jails making sure not to close needed FDs.
-    fn keep_fds(&self) -> Option<Vec<RawFd>> {
-        None
-    }
-}
-
-/// `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<dyn error::Error>>;
-}
-
-/// `StreamControl` provides a way to set the volume and mute states of a stream. `StreamControl`
-/// is separate from the stream so it can be owned by a different thread if needed.
-pub trait StreamControl: Send + Sync {
-    fn set_volume(&mut self, _scaler: f64) {}
-    fn set_mute(&mut self, _mute: bool) {}
-}
-
-/// `BufferDrop` is used as a callback mechanism for `PlaybackBuffer` objects. It is meant to be
-/// implemented by the audio stream, allowing arbitrary code to be run after a buffer is filled or
-/// read by the user.
-pub trait BufferDrop {
-    /// Called when an audio buffer is dropped. `nframes` indicates the number of audio frames that
-    /// were read or written to the device.
-    fn trigger(&mut self, nframes: usize);
-}
-
-/// Errors that are possible from a `PlaybackBuffer`.
-#[derive(Debug)]
-pub enum PlaybackBufferError {
-    InvalidLength,
-}
-
-impl error::Error for PlaybackBufferError {}
-
-impl Display for PlaybackBufferError {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        match self {
-            PlaybackBufferError::InvalidLength => write!(f, "Invalid buffer length"),
-        }
-    }
-}
-
-/// `AudioBuffer` is one buffer that holds buffer_size audio frames and its drop function.
-/// It is the inner data of `PlaybackBuffer` and `CaptureBuffer`.
-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 dyn BufferDrop,
-}
-
-/// `PlaybackBuffer` is one buffer that holds buffer_size audio frames. It is used to temporarily
-/// allow access to an audio buffer and notifes the owning stream of write completion when dropped.
-pub struct PlaybackBuffer<'a> {
-    buffer: AudioBuffer<'a>,
-}
-
-impl<'a> PlaybackBuffer<'a> {
-    /// Creates a new `PlaybackBuffer` that holds a reference to the backing memory specified in
-    /// `buffer`.
-    pub fn new<F>(
-        frame_size: usize,
-        buffer: &'a mut [u8],
-        drop: &'a mut F,
-    ) -> Result<Self, PlaybackBufferError>
-    where
-        F: BufferDrop,
-    {
-        if buffer.len() % frame_size != 0 {
-            return Err(PlaybackBufferError::InvalidLength);
-        }
-
-        Ok(PlaybackBuffer {
-            buffer: AudioBuffer {
-                buffer,
-                offset: 0,
-                frame_size,
-                drop,
-            },
-        })
-    }
-
-    /// Returns the number of audio frames that fit in the buffer.
-    pub fn frame_capacity(&self) -> usize {
-        self.buffer.buffer.len() / self.buffer.frame_size
-    }
-
-    /// Writes up to `size` bytes directly to this buffer inside of the given callback function.
-    pub fn copy_cb<F: FnOnce(&mut [u8])>(&mut self, size: usize, cb: F) {
-        // only write complete frames.
-        let len = size / self.buffer.frame_size * self.buffer.frame_size;
-        cb(&mut self.buffer.buffer[self.buffer.offset..(self.buffer.offset + len)]);
-        self.buffer.offset += len;
-    }
-}
-
-impl<'a> Write for PlaybackBuffer<'a> {
-    fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
-        // only write complete frames.
-        let len = buf.len() / self.buffer.frame_size * self.buffer.frame_size;
-        let written = (&mut self.buffer.buffer[self.buffer.offset..]).write(&buf[..len])?;
-        self.buffer.offset += written;
-        Ok(written)
-    }
-
-    fn flush(&mut self) -> io::Result<()> {
-        Ok(())
-    }
-}
-
-impl<'a> Drop for PlaybackBuffer<'a> {
-    fn drop(&mut self) {
-        self.buffer
-            .drop
-            .trigger(self.buffer.offset / self.buffer.frame_size);
-    }
-}
-
-/// Stream that accepts playback samples but drops them.
-pub struct DummyStream {
-    buffer: Vec<u8>,
-    frame_size: usize,
-    interval: Duration,
-    next_frame: Duration,
-    start_time: Option<Instant>,
-    buffer_drop: DummyBufferDrop,
-}
-
-/// DummyStream data that is needed from the buffer complete callback.
-struct DummyBufferDrop {
-    which_buffer: bool,
-}
-
-impl BufferDrop for DummyBufferDrop {
-    fn trigger(&mut self, _nwritten: usize) {
-        // When a buffer completes, switch to the other one.
-        self.which_buffer ^= true;
-    }
-}
-
-impl DummyStream {
-    // TODO(allow other formats)
-    pub fn new(num_channels: usize, frame_rate: usize, buffer_size: usize) -> Self {
-        const S16LE_SIZE: usize = 2;
-        let frame_size = S16LE_SIZE * num_channels;
-        let interval = Duration::from_millis(buffer_size as u64 * 1000 / frame_rate as u64);
-        DummyStream {
-            buffer: vec![0; buffer_size * frame_size],
-            frame_size,
-            interval,
-            next_frame: interval,
-            start_time: None,
-            buffer_drop: DummyBufferDrop {
-                which_buffer: false,
-            },
-        }
-    }
-}
-
-impl PlaybackBufferStream for DummyStream {
-    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());
-            }
-            self.next_frame += self.interval;
-        } else {
-            self.start_time = Some(Instant::now());
-            self.next_frame = self.interval;
-        }
-        Ok(PlaybackBuffer::new(
-            self.frame_size,
-            &mut self.buffer,
-            &mut self.buffer_drop,
-        )?)
-    }
-}
-
-/// No-op control for `DummyStream`s.
-#[derive(Default)]
-pub struct DummyStreamControl;
-
-impl DummyStreamControl {
-    pub fn new() -> Self {
-        DummyStreamControl {}
-    }
-}
-
-impl StreamControl for DummyStreamControl {}
-
-/// Source of `DummyStream` and `DummyStreamControl` objects.
-#[derive(Default)]
-pub struct DummyStreamSource;
-
-impl DummyStreamSource {
-    pub fn new() -> Self {
-        DummyStreamSource {}
-    }
-}
-
-impl StreamSource for DummyStreamSource {
-    fn new_playback_stream(
-        &mut self,
-        num_channels: usize,
-        frame_rate: usize,
-        buffer_size: usize,
-    ) -> 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)),
-        ))
-    }
-}
-
-#[cfg(test)]
-mod tests {
-    use super::*;
-
-    #[test]
-    fn invalid_buffer_length() {
-        // Playback buffers can't be created with a size that isn't divisible by the frame size.
-        let mut pb_buf = [0xa5u8; 480 * 2 * 2 + 1];
-        let mut buffer_drop = DummyBufferDrop {
-            which_buffer: false,
-        };
-        assert!(PlaybackBuffer::new(2, &mut pb_buf, &mut buffer_drop).is_err());
-    }
-
-    #[test]
-    fn trigger() {
-        struct TestDrop {
-            frame_count: usize,
-        };
-        impl BufferDrop for TestDrop {
-            fn trigger(&mut self, nwritten: usize) {
-                self.frame_count += nwritten;
-            }
-        }
-        let mut test_drop = TestDrop { frame_count: 0 };
-        {
-            const FRAME_SIZE: usize = 4;
-            let mut buf = [0u8; 480 * FRAME_SIZE];
-            let mut pb_buf = PlaybackBuffer::new(FRAME_SIZE, &mut buf, &mut test_drop).unwrap();
-            pb_buf.write(&[0xa5u8; 480 * FRAME_SIZE]).unwrap();
-        }
-        assert_eq!(test_drop.frame_count, 480);
-    }
-
-    #[test]
-    fn sixteen_bit_stereo() {
-        let mut server = DummyStreamSource::new();
-        let (_, mut stream) = server.new_playback_stream(2, 48000, 480).unwrap();
-        let mut stream_buffer = stream.next_playback_buffer().unwrap();
-        assert_eq!(stream_buffer.frame_capacity(), 480);
-        let pb_buf = [0xa5u8; 480 * 2 * 2];
-        assert_eq!(stream_buffer.write(&pb_buf).unwrap(), 480 * 2 * 2);
-    }
-
-    #[test]
-    fn consumption_rate() {
-        let mut server = DummyStreamSource::new();
-        let (_, mut stream) = server.new_playback_stream(2, 48000, 480).unwrap();
-        let start = Instant::now();
-        {
-            let mut stream_buffer = stream.next_playback_buffer().unwrap();
-            let pb_buf = [0xa5u8; 480 * 2 * 2];
-            assert_eq!(stream_buffer.write(&pb_buf).unwrap(), 480 * 2 * 2);
-        }
-        // The second call should block until the first buffer is consumed.
-        let _stream_buffer = stream.next_playback_buffer().unwrap();
-        let elapsed = start.elapsed();
-        assert!(
-            elapsed > Duration::from_millis(10),
-            "next_playback_buffer didn't block long enough {}",
-            elapsed.subsec_millis()
-        );
-    }
-}
diff --git a/audio_streams/src/capture.rs b/audio_streams/src/capture.rs
deleted file mode 100644
index 0e58dc8..0000000
--- a/audio_streams/src/capture.rs
+++ /dev/null
@@ -1,237 +0,0 @@
-// 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 audio_streams::{StreamSource, DummyStreamSource};
-//! use std::io::Read;
-//!
-//! const buffer_size: usize = 120;
-//! const num_channels: usize = 2;
-//! const frame_size: usize = num_channels * 2; // 16-bit samples are two bytes.
-//!
-//! # fn main() -> std::result::Result<(), Box<std::error::Error>> {
-//! let mut stream_source = DummyStreamSource::new();
-//!
-//! let (_, mut stream) = stream_source
-//!     .new_capture_stream(num_channels, 48000, buffer_size)?;
-//! // Capture 10 buffers of zeros.
-//! let mut cp_bufs = [[0xa5u8; buffer_size * frame_size]; 10];
-//! for cp_buf in &mut cp_bufs {
-//!     let mut stream_buffer = stream.next_capture_buffer()?;
-//!     assert_eq!(stream_buffer.read(cp_buf)?, buffer_size * frame_size);
-//! }
-//! # Ok (())
-//! # }
-//! ```
-
-use std::{
-    error,
-    fmt::{self, Display},
-    io::{self, Read, Write},
-    time::{Duration, Instant},
-};
-
-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<dyn error::Error>>;
-}
-
-/// `CaptureBuffer` contains a block of audio samples got from capture stream. It provides
-/// temporary view to those samples and will notifies capture stream when dropped.
-/// Note that it'll always send `buffer.len() / frame_size` to drop function when it got destroyed
-/// since `CaptureBufferStream` assumes that users get all the samples from the buffer.
-pub struct CaptureBuffer<'a> {
-    buffer: AudioBuffer<'a>,
-}
-
-/// Errors that are possible from a `CaptureBuffer`.
-#[derive(Debug)]
-pub enum CaptureBufferError {
-    InvalidLength,
-}
-
-impl error::Error for CaptureBufferError {}
-
-impl Display for CaptureBufferError {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        match self {
-            CaptureBufferError::InvalidLength => write!(f, "Invalid buffer length"),
-        }
-    }
-}
-
-impl<'a> CaptureBuffer<'a> {
-    /// Creates a new `CaptureBuffer` that holds a reference to the backing memory specified in
-    /// `buffer`.
-    pub fn new<F>(
-        frame_size: usize,
-        buffer: &'a mut [u8],
-        drop: &'a mut F,
-    ) -> Result<Self, CaptureBufferError>
-    where
-        F: BufferDrop,
-    {
-        if buffer.len() % frame_size != 0 {
-            return Err(CaptureBufferError::InvalidLength);
-        }
-
-        Ok(CaptureBuffer {
-            buffer: AudioBuffer {
-                buffer,
-                frame_size,
-                offset: 0,
-                drop,
-            },
-        })
-    }
-
-    /// Returns the number of audio frames that fit in the buffer.
-    pub fn frame_capacity(&self) -> usize {
-        self.buffer.buffer.len() / self.buffer.frame_size
-    }
-
-    /// Reads up to `size` bytes directly from this buffer inside of the given callback function.
-    pub fn copy_cb<F: FnOnce(&[u8])>(&mut self, size: usize, cb: F) {
-        let len = size / self.buffer.frame_size * self.buffer.frame_size;
-        cb(&self.buffer.buffer[self.buffer.offset..(self.buffer.offset + len)]);
-        self.buffer.offset += len;
-    }
-}
-
-impl<'a> Read for CaptureBuffer<'a> {
-    fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
-        let len = buf.len() / self.buffer.frame_size * self.buffer.frame_size;
-        let written = (&mut buf[..len]).write(&self.buffer.buffer[self.buffer.offset..])?;
-        self.buffer.offset += written;
-        Ok(written)
-    }
-}
-
-/// Always sends `frame_capacity` when it drops.
-impl<'a> Drop for CaptureBuffer<'a> {
-    fn drop(&mut self) {
-        self.buffer.drop.trigger(self.frame_capacity());
-    }
-}
-
-/// Stream that provides null capture samples.
-pub struct DummyCaptureStream {
-    buffer: Vec<u8>,
-    frame_size: usize,
-    interval: Duration,
-    next_frame: Duration,
-    start_time: Option<Instant>,
-    buffer_drop: DummyBufferDrop,
-}
-
-impl DummyCaptureStream {
-    // TODO(allow other formats)
-    pub fn new(num_channels: usize, frame_rate: usize, buffer_size: usize) -> Self {
-        const S16LE_SIZE: usize = 2;
-        let frame_size = S16LE_SIZE * num_channels;
-        let interval = Duration::from_millis(buffer_size as u64 * 1000 / frame_rate as u64);
-        DummyCaptureStream {
-            buffer: vec![0; buffer_size * frame_size],
-            frame_size,
-            interval,
-            next_frame: interval,
-            start_time: None,
-            buffer_drop: DummyBufferDrop {
-                which_buffer: false,
-            },
-        }
-    }
-}
-
-impl CaptureBufferStream for DummyCaptureStream {
-    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());
-            }
-            self.next_frame += self.interval;
-        } else {
-            self.start_time = Some(Instant::now());
-            self.next_frame = self.interval;
-        }
-        Ok(CaptureBuffer::new(
-            self.frame_size,
-            &mut self.buffer,
-            &mut self.buffer_drop,
-        )?)
-    }
-}
-
-#[cfg(test)]
-mod tests {
-    use super::super::*;
-    use super::*;
-
-    #[test]
-    fn invalid_buffer_length() {
-        // Capture buffers can't be created with a size that isn't divisible by the frame size.
-        let mut cp_buf = [0xa5u8; 480 * 2 * 2 + 1];
-        let mut buffer_drop = DummyBufferDrop {
-            which_buffer: false,
-        };
-        assert!(CaptureBuffer::new(2, &mut cp_buf, &mut buffer_drop).is_err());
-    }
-
-    #[test]
-    fn trigger() {
-        struct TestDrop {
-            frame_count: usize,
-        };
-        impl BufferDrop for TestDrop {
-            fn trigger(&mut self, nwritten: usize) {
-                self.frame_count += nwritten;
-            }
-        }
-        let mut test_drop = TestDrop { frame_count: 0 };
-        {
-            const FRAME_SIZE: usize = 4;
-            let mut buf = [0u8; 480 * FRAME_SIZE];
-            let mut cp_buf = CaptureBuffer::new(FRAME_SIZE, &mut buf, &mut test_drop).unwrap();
-            let mut local_buf = [0u8; 240 * FRAME_SIZE];
-            assert_eq!(cp_buf.read(&mut local_buf).unwrap(), 240 * FRAME_SIZE);
-        }
-        // This should be 480 no matter how many samples are read.
-        assert_eq!(test_drop.frame_count, 480);
-    }
-
-    #[test]
-    fn sixteen_bit_stereo() {
-        let mut server = DummyStreamSource::new();
-        let (_, mut stream) = server.new_capture_stream(2, 48000, 480).unwrap();
-        let mut stream_buffer = stream.next_capture_buffer().unwrap();
-        assert_eq!(stream_buffer.frame_capacity(), 480);
-        let mut pb_buf = [0xa5u8; 480 * 2 * 2];
-        assert_eq!(stream_buffer.read(&mut pb_buf).unwrap(), 480 * 2 * 2);
-    }
-
-    #[test]
-    fn consumption_rate() {
-        let mut server = DummyStreamSource::new();
-        let (_, mut stream) = server.new_capture_stream(2, 48000, 480).unwrap();
-        let start = Instant::now();
-        {
-            let mut stream_buffer = stream.next_capture_buffer().unwrap();
-            let mut cp_buf = [0xa5u8; 480 * 2 * 2];
-            assert_eq!(stream_buffer.read(&mut cp_buf).unwrap(), 480 * 2 * 2);
-            for i in 0..cp_buf.len() {
-                assert_eq!(cp_buf[i], 0, "Read samples should all be zeros.");
-            }
-        }
-        // The second call should block until the first buffer is consumed.
-        let _stream_buffer = stream.next_capture_buffer().unwrap();
-        let elapsed = start.elapsed();
-        assert!(
-            elapsed > Duration::from_millis(10),
-            "next_capture_buffer didn't block long enough {}",
-            elapsed.subsec_millis()
-        );
-    }
-
-}
diff --git a/cras-config/auron/HDA Intel PCH b/cras-config/auron/HDA Intel PCH
new file mode 100644
index 0000000..e0adc3e
--- /dev/null
+++ b/cras-config/auron/HDA Intel PCH
@@ -0,0 +1,107 @@
+[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
new file mode 100644
index 0000000..e229b19
--- /dev/null
+++ b/cras-config/auron/dsp.ini
@@ -0,0 +1,119 @@
+[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
new file mode 100644
index 0000000..d2ae47c
--- /dev/null
+++ b/cras-config/auron_paine/HDA Intel PCH
@@ -0,0 +1,107 @@
+[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
new file mode 100644
index 0000000..c7eab22
--- /dev/null
+++ b/cras-config/auron_paine/dsp.ini
@@ -0,0 +1,119 @@
+[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
diff --git a/cras-config/auron_yuna/HDA Intel PCH b/cras-config/auron_yuna/HDA Intel PCH
new file mode 100644
index 0000000..d7a71e9
--- /dev/null
+++ b/cras-config/auron_yuna/HDA Intel PCH
@@ -0,0 +1,107 @@
+[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
new file mode 100644
index 0000000..17f5350
--- /dev/null
+++ b/cras-config/auron_yuna/dsp.ini
@@ -0,0 +1,119 @@
+[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-cheets b/cras-config/cyan-cheets
new file mode 120000
index 0000000..d8fcd90
--- /dev/null
+++ b/cras-config/cyan-cheets
@@ -0,0 +1 @@
+cyan
\ No newline at end of file
diff --git a/cras-config/cyan/cht-bsw-max98090 b/cras-config/cyan/cht-bsw-max98090
new file mode 100644
index 0000000..fba7d1b
--- /dev/null
+++ b/cras-config/cyan/cht-bsw-max98090
@@ -0,0 +1,107 @@
+[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
new file mode 100644
index 0000000..e121f1d
--- /dev/null
+++ b/cras-config/cyan/chtmax98090
@@ -0,0 +1,107 @@
+[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
new file mode 100644
index 0000000..5f9a349
--- /dev/null
+++ b/cras-config/cyan/dsp.ini
@@ -0,0 +1,111 @@
+[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/for_all_boards/Logitech MeetUp Speakerphone b/cras-config/for_all_boards/Logitech MeetUp Speakerphone
deleted file mode 100644
index 429835f..0000000
--- a/cras-config/for_all_boards/Logitech MeetUp Speakerphone
+++ /dev/null
@@ -1,103 +0,0 @@
-[Default]
-  volume_curve = explicit
-  db_at_100 = 0
-  db_at_99 = -30
-  db_at_98 = -60
-  db_at_97 = -90
-  db_at_96 = -120
-  db_at_95 = -150
-  db_at_94 = -180
-  db_at_93 = -210
-  db_at_92 = -240
-  db_at_91 = -270
-  db_at_90 = -300
-  db_at_89 = -330
-  db_at_88 = -360
-  db_at_87 = -390
-  db_at_86 = -420
-  db_at_85 = -450
-  db_at_84 = -480
-  db_at_83 = -510
-  db_at_82 = -540
-  db_at_81 = -570
-  db_at_80 = -600
-  db_at_79 = -630
-  db_at_78 = -660
-  db_at_77 = -690
-  db_at_76 = -720
-  db_at_75 = -750
-  db_at_74 = -780
-  db_at_73 = -810
-  db_at_72 = -840
-  db_at_71 = -870
-  db_at_70 = -900
-  db_at_69 = -930
-  db_at_68 = -960
-  db_at_67 = -990
-  db_at_66 = -1020
-  db_at_65 = -1050
-  db_at_64 = -1080
-  db_at_63 = -1110
-  db_at_62 = -1140
-  db_at_61 = -1170
-  db_at_60 = -1200
-  db_at_59 = -1230
-  db_at_58 = -1260
-  db_at_57 = -1290
-  db_at_56 = -1320
-  db_at_55 = -1350
-  db_at_54 = -1380
-  db_at_53 = -1410
-  db_at_52 = -1440
-  db_at_51 = -1470
-  db_at_50 = -1500
-  db_at_49 = -1560
-  db_at_48 = -1620
-  db_at_47 = -1680
-  db_at_46 = -1740
-  db_at_45 = -1800
-  db_at_44 = -1860
-  db_at_43 = -1920
-  db_at_42 = -1980
-  db_at_41 = -2040
-  db_at_40 = -2100
-  db_at_39 = -2160
-  db_at_38 = -2220
-  db_at_37 = -2280
-  db_at_36 = -2340
-  db_at_35 = -2400
-  db_at_34 = -2460
-  db_at_33 = -2520
-  db_at_32 = -2580
-  db_at_31 = -2640
-  db_at_30 = -2700
-  db_at_29 = -2760
-  db_at_28 = -2820
-  db_at_27 = -2880
-  db_at_26 = -2940
-  db_at_25 = -3000
-  db_at_24 = -3060
-  db_at_23 = -3120
-  db_at_22 = -3180
-  db_at_21 = -3240
-  db_at_20 = -3300
-  db_at_19 = -3360
-  db_at_18 = -3420
-  db_at_17 = -3480
-  db_at_16 = -3540
-  db_at_15 = -3600
-  db_at_14 = -3660
-  db_at_13 = -3720
-  db_at_12 = -3780
-  db_at_11 = -3840
-  db_at_10 = -3900
-  db_at_9 = -3960
-  db_at_8 = -4020
-  db_at_7 = -4080
-  db_at_6 = -4140
-  db_at_5 = -4200
-  db_at_4 = -4260
-  db_at_3 = -4320
-  db_at_2 = -4380
-  db_at_1 = -4440
-  db_at_0 = -4500
diff --git a/cras-config/gandof/HDA Intel PCH b/cras-config/gandof/HDA Intel PCH
new file mode 100644
index 0000000..900fc1e
--- /dev/null
+++ b/cras-config/gandof/HDA Intel PCH
@@ -0,0 +1,107 @@
+[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
new file mode 100644
index 0000000..6853c4d
--- /dev/null
+++ b/cras-config/gandof/dsp.ini
@@ -0,0 +1,71 @@
+[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/glimmer-cheets/byt-max98090 b/cras-config/glimmer-cheets/byt-max98090
new file mode 100644
index 0000000..5bea604
--- /dev/null
+++ b/cras-config/glimmer-cheets/byt-max98090
@@ -0,0 +1,107 @@
+[Speaker]
+  volume_curve = explicit
+  db_at_100 = -400
+  db_at_99 = -450
+  db_at_98 = -450
+  db_at_97 = -500
+  db_at_96 = -500
+  db_at_95 = -550
+  db_at_94 = -600
+  db_at_93 = -600
+  db_at_92 = -650
+  db_at_91 = -650
+  db_at_90 = -700
+  db_at_89 = -750
+  db_at_88 = -750
+  db_at_87 = -800
+  db_at_86 = -800
+  db_at_85 = -850
+  db_at_84 = -900
+  db_at_83 = -900
+  db_at_82 = -950
+  db_at_81 = -950
+  db_at_80 = -1000
+  db_at_79 = -1050
+  db_at_78 = -1050
+  db_at_77 = -1100
+  db_at_76 = -1100
+  db_at_75 = -1150
+  db_at_74 = -1200
+  db_at_73 = -1200
+  db_at_72 = -1250
+  db_at_71 = -1250
+  db_at_70 = -1300
+  db_at_69 = -1350
+  db_at_68 = -1350
+  db_at_67 = -1400
+  db_at_66 = -1400
+  db_at_65 = -1450
+  db_at_64 = -1500
+  db_at_63 = -1500
+  db_at_62 = -1550
+  db_at_61 = -1550
+  db_at_60 = -1600
+  db_at_59 = -1650
+  db_at_58 = -1700
+  db_at_57 = -1750
+  db_at_56 = -1800
+  db_at_55 = -1850
+  db_at_54 = -1850
+  db_at_53 = -1900
+  db_at_52 = -1950
+  db_at_51 = -2000
+  db_at_50 = -2050
+  db_at_49 = -2100
+  db_at_48 = -2150
+  db_at_47 = -2200
+  db_at_46 = -2250
+  db_at_45 = -2300
+  db_at_44 = -2350
+  db_at_43 = -2350
+  db_at_42 = -2400
+  db_at_41 = -2450
+  db_at_40 = -2500
+  db_at_39 = -2550
+  db_at_38 = -2600
+  db_at_37 = -2650
+  db_at_36 = -2700
+  db_at_35 = -2750
+  db_at_34 = -2800
+  db_at_33 = -2850
+  db_at_32 = -2850
+  db_at_31 = -2900
+  db_at_30 = -2950
+  db_at_29 = -3000
+  db_at_28 = -3050
+  db_at_27 = -3100
+  db_at_26 = -3150
+  db_at_25 = -3200
+  db_at_24 = -3250
+  db_at_23 = -3300
+  db_at_22 = -3350
+  db_at_21 = -3350
+  db_at_20 = -3400
+  db_at_19 = -3450
+  db_at_18 = -3500
+  db_at_17 = -3550
+  db_at_16 = -3600
+  db_at_15 = -3650
+  db_at_14 = -3750
+  db_at_13 = -3800
+  db_at_12 = -3900
+  db_at_11 = -3950
+  db_at_10 = -4050
+  db_at_9 = -4100
+  db_at_8 = -4200
+  db_at_7 = -4250
+  db_at_6 = -4350
+  db_at_5 = -4400
+  db_at_4 = -4500
+  db_at_3 = -4550
+  db_at_2 = -4650
+  db_at_1 = -4700
+  db_at_0 = -4800
+[Headphone]
+  volume_curve = simple_step
+  volume_step = 50
+  max_volume = 0
diff --git a/cras-config/glimmer-cheets/dsp.ini b/cras-config/glimmer-cheets/dsp.ini
new file mode 100644
index 0000000..856a220
--- /dev/null
+++ b/cras-config/glimmer-cheets/dsp.ini
@@ -0,0 +1,111 @@
+[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=-33       ; threshold
+input_8=27        ; knee
+input_9=15        ; ratio
+input_10=0.003     ; attack
+input_11=0.25      ; release
+input_12=0         ; boost
+input_13=750       ; f
+input_14=1         ; enable
+input_15=-33       ; threshold
+input_16=36        ; knee
+input_17=15        ; ratio
+input_18=0.003     ; attack
+input_19=0.25      ; release
+input_20=0         ; boost
+input_21=1300      ; f
+input_22=1         ; enable
+input_23=-33       ; threshold
+input_24=30        ; knee
+input_25=15        ; ratio
+input_26=0.003     ; attack
+input_27=0.25      ; release
+input_28=0         ; 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=420     ; freq
+input_6=0       ; Q
+input_7=0       ; gain
+input_8=2       ; highpass
+input_9=435     ; freq
+input_10=0       ; Q
+input_11=0       ; gain
+input_12=6       ; peaking
+input_13=516     ; freq
+input_14=6       ; Q
+input_15=-6      ; gain
+input_16=6       ; peaking
+input_17=520     ; freq
+input_18=5       ; Q
+input_19=-12     ; gain
+input_20=6       ; peaking
+input_21=750     ; freq
+input_22=5       ; Q
+input_23=-5      ; gain
+input_24=6       ; peaking
+input_25=745     ; freq
+input_26=6       ; Q
+input_27=-7      ; gain
+input_28=6       ; peaking
+input_29=1090    ; freq
+input_30=4       ; Q
+input_31=-6      ; gain
+input_32=6       ; peaking
+input_33=1050    ; freq
+input_34=5       ; Q
+input_35=-6      ; gain
+input_36=6       ; peaking
+input_37=2000    ; freq
+input_38=3       ; Q
+input_39=-7      ; gain
+input_40=6       ; peaking
+input_41=1850    ; freq
+input_42=3       ; Q
+input_43=-5      ; gain
+input_44=1       ; lowpass
+input_45=12000   ; freq
+input_46=0       ; Q
+input_47=0       ; gain
+input_48=1       ; lowpass
+input_49=12000   ; freq
+input_50=0       ; Q
+input_51=0       ; gain
+input_52=0       ; none
+input_53=0       ; freq
+input_54=0       ; Q
+input_55=0       ; gain
+input_56=6       ; peaking
+input_57=2800    ; freq
+input_58=3       ; Q
+input_59=-3      ; gain
diff --git a/cras-config/lulu/HDA Intel PCH b/cras-config/lulu/HDA Intel PCH
new file mode 100644
index 0000000..52f775f
--- /dev/null
+++ b/cras-config/lulu/HDA Intel PCH
@@ -0,0 +1,107 @@
+[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
new file mode 100644
index 0000000..2e445c8
--- /dev/null
+++ b/cras-config/lulu/dsp.ini
@@ -0,0 +1,95 @@
+[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-config/peppy_freon/HDA Intel PCH b/cras-config/peppy_freon/HDA Intel PCH
new file mode 100644
index 0000000..e0adc3e
--- /dev/null
+++ b/cras-config/peppy_freon/HDA Intel PCH
@@ -0,0 +1,107 @@
+[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/peppy_freon/dsp.ini b/cras-config/peppy_freon/dsp.ini
new file mode 100644
index 0000000..e229b19
--- /dev/null
+++ b/cras-config/peppy_freon/dsp.ini
@@ -0,0 +1,119 @@
+[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/rush_ryu/dsp.ini b/cras-config/rush_ryu/dsp.ini
new file mode 100644
index 0000000..d9254eb
--- /dev/null
+++ b/cras-config/rush_ryu/dsp.ini
@@ -0,0 +1,79 @@
+[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=-38       ; threshold
+input_8=27        ; knee
+input_9=11.427    ; ratio
+input_10=0.003     ; attack
+input_11=0.25      ; release
+input_12=0         ; boost
+input_13=400       ; f
+input_14=1         ; enable
+input_15=-35       ; threshold
+input_16=30        ; knee
+input_17=12        ; ratio
+input_18=0.003     ; attack
+input_19=0.25      ; release
+input_20=0         ; boost
+input_21=1600      ; f
+input_22=1         ; enable
+input_23=-30       ; threshold
+input_24=32        ; knee
+input_25=6         ; ratio
+input_26=0.003     ; attack
+input_27=0.25      ; release
+input_28=-1        ; 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=360     ; freq
+input_6=0       ; Q
+input_7=0       ; gain
+input_8=2       ; highpass
+input_9=360     ; freq
+input_10=0       ; Q
+input_11=0       ; gain
+input_12=6       ; peaking
+input_13=510     ; freq
+input_14=4       ; Q
+input_15=-6      ; gain
+input_16=6       ; peaking
+input_17=510     ; freq
+input_18=4       ; Q
+input_19=-6      ; gain
+input_20=6       ; peaking
+input_21=650     ; freq
+input_22=8       ; Q
+input_23=-6      ; gain
+input_24=6       ; peaking
+input_25=650     ; freq
+input_26=8       ; Q
+input_27=-6      ; gain
diff --git a/cras-config/stout32/HDA Intel PCH b/cras-config/stout32/HDA Intel PCH
new file mode 120000
index 0000000..16c6a1c
--- /dev/null
+++ b/cras-config/stout32/HDA Intel PCH
@@ -0,0 +1 @@
+../stout/HDA Intel PCH
\ No newline at end of file
diff --git a/cras-config/veryon_jerry-kernelnext b/cras-config/veryon_jerry-kernelnext
deleted file mode 120000
index 0462d3a..0000000
--- a/cras-config/veryon_jerry-kernelnext
+++ /dev/null
@@ -1 +0,0 @@
-veyron_jerry
\ No newline at end of file
diff --git a/cras-config/veyron_jaq/VEYRON-I2S b/cras-config/veyron_jaq/VEYRON-I2S
deleted file mode 100644
index 2b946ca..0000000
--- a/cras-config/veyron_jaq/VEYRON-I2S
+++ /dev/null
@@ -1,107 +0,0 @@
-[Speaker]
-  volume_curve = explicit
-  db_at_100 = -100
-  db_at_99 = -100
-  db_at_98 = -100
-  db_at_97 = -100
-  db_at_96 = -200
-  db_at_95 = -200
-  db_at_94 = -200
-  db_at_93 = -200
-  db_at_92 = -200
-  db_at_91 = -200
-  db_at_90 = -200
-  db_at_89 = -200
-  db_at_88 = -300
-  db_at_87 = -300
-  db_at_86 = -300
-  db_at_85 = -300
-  db_at_84 = -300
-  db_at_83 = -300
-  db_at_82 = -300
-  db_at_81 = -400
-  db_at_80 = -400
-  db_at_79 = -400
-  db_at_78 = -400
-  db_at_77 = -400
-  db_at_76 = -400
-  db_at_75 = -400
-  db_at_74 = -500
-  db_at_73 = -500
-  db_at_72 = -500
-  db_at_71 = -500
-  db_at_70 = -500
-  db_at_69 = -500
-  db_at_68 = -500
-  db_at_67 = -500
-  db_at_66 = -600
-  db_at_65 = -600
-  db_at_64 = -600
-  db_at_63 = -600
-  db_at_62 = -600
-  db_at_61 = -600
-  db_at_60 = -600
-  db_at_59 = -700
-  db_at_58 = -700
-  db_at_57 = -700
-  db_at_56 = -700
-  db_at_55 = -700
-  db_at_54 = -800
-  db_at_53 = -800
-  db_at_52 = -800
-  db_at_51 = -900
-  db_at_50 = -900
-  db_at_49 = -900
-  db_at_48 = -900
-  db_at_47 = -1000
-  db_at_46 = -1000
-  db_at_45 = -1000
-  db_at_44 = -1100
-  db_at_43 = -1100
-  db_at_42 = -1100
-  db_at_41 = -1200
-  db_at_40 = -1200
-  db_at_39 = -1200
-  db_at_38 = -1200
-  db_at_37 = -1300
-  db_at_36 = -1300
-  db_at_35 = -1300
-  db_at_34 = -1400
-  db_at_33 = -1400
-  db_at_32 = -1400
-  db_at_31 = -1500
-  db_at_30 = -1500
-  db_at_29 = -1500
-  db_at_28 = -1500
-  db_at_27 = -1600
-  db_at_26 = -1600
-  db_at_25 = -1600
-  db_at_24 = -1700
-  db_at_23 = -1700
-  db_at_22 = -1700
-  db_at_21 = -1800
-  db_at_20 = -1800
-  db_at_19 = -1800
-  db_at_18 = -1900
-  db_at_17 = -1900
-  db_at_16 = -1900
-  db_at_15 = -1900
-  db_at_14 = -2000
-  db_at_13 = -2000
-  db_at_12 = -2000
-  db_at_11 = -2100
-  db_at_10 = -2100
-  db_at_9 = -2100
-  db_at_8 = -2200
-  db_at_7 = -2200
-  db_at_6 = -2200
-  db_at_5 = -2200
-  db_at_4 = -2300
-  db_at_3 = -2300
-  db_at_2 = -2300
-  db_at_1 = -2400
-  db_at_0 = -2400
-[Headphone]
-  volume_curve = simple_step
-  volume_step = 70
-  max_volume = 0
diff --git a/cras-config/veyron_jerry/VEYRON-I2S b/cras-config/veyron_jerry/VEYRON-I2S
deleted file mode 100644
index d59988f..0000000
--- a/cras-config/veyron_jerry/VEYRON-I2S
+++ /dev/null
@@ -1,107 +0,0 @@
-[Speaker]
-  volume_curve = explicit
-  db_at_100 = -500
-  db_at_99 = -520
-  db_at_98 = -520
-  db_at_97 = -540
-  db_at_96 = -540
-  db_at_95 = -560
-  db_at_94 = -580
-  db_at_93 = -580
-  db_at_92 = -600
-  db_at_91 = -620
-  db_at_90 = -620
-  db_at_89 = -640
-  db_at_88 = -640
-  db_at_87 = -660
-  db_at_86 = -680
-  db_at_85 = -680
-  db_at_84 = -700
-  db_at_83 = -720
-  db_at_82 = -740
-  db_at_81 = -760
-  db_at_80 = -780
-  db_at_79 = -800
-  db_at_78 = -820
-  db_at_77 = -840
-  db_at_76 = -860
-  db_at_75 = -880
-  db_at_74 = -880
-  db_at_73 = -880
-  db_at_72 = -900
-  db_at_71 = -920
-  db_at_70 = -940
-  db_at_69 = -980
-  db_at_68 = -1000
-  db_at_67 = -1020
-  db_at_66 = -1040
-  db_at_65 = -1080
-  db_at_64 = -1100
-  db_at_63 = -1120
-  db_at_62 = -1140
-  db_at_61 = -1180
-  db_at_60 = -1200
-  db_at_59 = -1220
-  db_at_58 = -1240
-  db_at_57 = -1280
-  db_at_56 = -1300
-  db_at_55 = -1320
-  db_at_54 = -1340
-  db_at_53 = -1380
-  db_at_52 = -1400
-  db_at_51 = -1460
-  db_at_50 = -1540
-  db_at_49 = -1600
-  db_at_48 = -1660
-  db_at_47 = -1720
-  db_at_46 = -1800
-  db_at_45 = -1860
-  db_at_44 = -1920
-  db_at_43 = -1980
-  db_at_42 = -2060
-  db_at_41 = -2120
-  db_at_40 = -2180
-  db_at_39 = -2240
-  db_at_38 = -2320
-  db_at_37 = -2380
-  db_at_36 = -2440
-  db_at_35 = -2520
-  db_at_34 = -2580
-  db_at_33 = -2640
-  db_at_32 = -2700
-  db_at_31 = -2780
-  db_at_30 = -2840
-  db_at_29 = -2900
-  db_at_28 = -2960
-  db_at_27 = -3040
-  db_at_26 = -3100
-  db_at_25 = -3160
-  db_at_24 = -3240
-  db_at_23 = -3300
-  db_at_22 = -3360
-  db_at_21 = -3420
-  db_at_20 = -3500
-  db_at_19 = -3560
-  db_at_18 = -3620
-  db_at_17 = -3680
-  db_at_16 = -3760
-  db_at_15 = -3820
-  db_at_14 = -3880
-  db_at_13 = -3940
-  db_at_12 = -4020
-  db_at_11 = -4080
-  db_at_10 = -4140
-  db_at_9 = -4220
-  db_at_8 = -4280
-  db_at_7 = -4340
-  db_at_6 = -4400
-  db_at_5 = -4480
-  db_at_4 = -4540
-  db_at_3 = -4600
-  db_at_2 = -4660
-  db_at_1 = -4740
-  db_at_0 = -4800
-[Headphone]
-  volume_curve = simple_step
-  volume_step = 70
-  max_volume = 0
diff --git a/cras-config/veyron_mighty/VEYRON-I2S b/cras-config/veyron_mighty/VEYRON-I2S
deleted file mode 100644
index 2b946ca..0000000
--- a/cras-config/veyron_mighty/VEYRON-I2S
+++ /dev/null
@@ -1,107 +0,0 @@
-[Speaker]
-  volume_curve = explicit
-  db_at_100 = -100
-  db_at_99 = -100
-  db_at_98 = -100
-  db_at_97 = -100
-  db_at_96 = -200
-  db_at_95 = -200
-  db_at_94 = -200
-  db_at_93 = -200
-  db_at_92 = -200
-  db_at_91 = -200
-  db_at_90 = -200
-  db_at_89 = -200
-  db_at_88 = -300
-  db_at_87 = -300
-  db_at_86 = -300
-  db_at_85 = -300
-  db_at_84 = -300
-  db_at_83 = -300
-  db_at_82 = -300
-  db_at_81 = -400
-  db_at_80 = -400
-  db_at_79 = -400
-  db_at_78 = -400
-  db_at_77 = -400
-  db_at_76 = -400
-  db_at_75 = -400
-  db_at_74 = -500
-  db_at_73 = -500
-  db_at_72 = -500
-  db_at_71 = -500
-  db_at_70 = -500
-  db_at_69 = -500
-  db_at_68 = -500
-  db_at_67 = -500
-  db_at_66 = -600
-  db_at_65 = -600
-  db_at_64 = -600
-  db_at_63 = -600
-  db_at_62 = -600
-  db_at_61 = -600
-  db_at_60 = -600
-  db_at_59 = -700
-  db_at_58 = -700
-  db_at_57 = -700
-  db_at_56 = -700
-  db_at_55 = -700
-  db_at_54 = -800
-  db_at_53 = -800
-  db_at_52 = -800
-  db_at_51 = -900
-  db_at_50 = -900
-  db_at_49 = -900
-  db_at_48 = -900
-  db_at_47 = -1000
-  db_at_46 = -1000
-  db_at_45 = -1000
-  db_at_44 = -1100
-  db_at_43 = -1100
-  db_at_42 = -1100
-  db_at_41 = -1200
-  db_at_40 = -1200
-  db_at_39 = -1200
-  db_at_38 = -1200
-  db_at_37 = -1300
-  db_at_36 = -1300
-  db_at_35 = -1300
-  db_at_34 = -1400
-  db_at_33 = -1400
-  db_at_32 = -1400
-  db_at_31 = -1500
-  db_at_30 = -1500
-  db_at_29 = -1500
-  db_at_28 = -1500
-  db_at_27 = -1600
-  db_at_26 = -1600
-  db_at_25 = -1600
-  db_at_24 = -1700
-  db_at_23 = -1700
-  db_at_22 = -1700
-  db_at_21 = -1800
-  db_at_20 = -1800
-  db_at_19 = -1800
-  db_at_18 = -1900
-  db_at_17 = -1900
-  db_at_16 = -1900
-  db_at_15 = -1900
-  db_at_14 = -2000
-  db_at_13 = -2000
-  db_at_12 = -2000
-  db_at_11 = -2100
-  db_at_10 = -2100
-  db_at_9 = -2100
-  db_at_8 = -2200
-  db_at_7 = -2200
-  db_at_6 = -2200
-  db_at_5 = -2200
-  db_at_4 = -2300
-  db_at_3 = -2300
-  db_at_2 = -2300
-  db_at_1 = -2400
-  db_at_0 = -2400
-[Headphone]
-  volume_curve = simple_step
-  volume_step = 70
-  max_volume = 0
diff --git a/cras-config/veyron_minnie-kernelnext b/cras-config/veyron_minnie-kernelnext
deleted file mode 120000
index 5fea6bb..0000000
--- a/cras-config/veyron_minnie-kernelnext
+++ /dev/null
@@ -1 +0,0 @@
-veyron_minnie
\ No newline at end of file
diff --git a/cras-config/veyron_minnie/VEYRON-I2S b/cras-config/veyron_minnie/VEYRON-I2S
deleted file mode 100644
index 297ac51..0000000
--- a/cras-config/veyron_minnie/VEYRON-I2S
+++ /dev/null
@@ -1,107 +0,0 @@
-[Speaker]
-  volume_curve = explicit
-  db_at_100 = -500
-  db_at_99 = -500
-  db_at_98 = -500
-  db_at_97 = -600
-  db_at_96 = -600
-  db_at_95 = -600
-  db_at_94 = -600
-  db_at_93 = -700
-  db_at_92 = -700
-  db_at_91 = -700
-  db_at_90 = -700
-  db_at_89 = -800
-  db_at_88 = -800
-  db_at_87 = -800
-  db_at_86 = -800
-  db_at_85 = -900
-  db_at_84 = -900
-  db_at_83 = -900
-  db_at_82 = -900
-  db_at_81 = -1000
-  db_at_80 = -1000
-  db_at_79 = -1000
-  db_at_78 = -1000
-  db_at_77 = -1100
-  db_at_76 = -1100
-  db_at_75 = -1100
-  db_at_74 = -1100
-  db_at_73 = -1200
-  db_at_72 = -1200
-  db_at_71 = -1200
-  db_at_70 = -1200
-  db_at_69 = -1300
-  db_at_68 = -1300
-  db_at_67 = -1300
-  db_at_66 = -1300
-  db_at_65 = -1400
-  db_at_64 = -1400
-  db_at_63 = -1400
-  db_at_62 = -1400
-  db_at_61 = -1500
-  db_at_60 = -1500
-  db_at_59 = -1500
-  db_at_58 = -1500
-  db_at_57 = -1600
-  db_at_56 = -1600
-  db_at_55 = -1600
-  db_at_54 = -1600
-  db_at_53 = -1700
-  db_at_52 = -1700
-  db_at_51 = -1700
-  db_at_50 = -1700
-  db_at_49 = -1800
-  db_at_48 = -1800
-  db_at_47 = -1800
-  db_at_46 = -1800
-  db_at_45 = -1900
-  db_at_44 = -1900
-  db_at_43 = -1900
-  db_at_42 = -1900
-  db_at_41 = -2000
-  db_at_40 = -2000
-  db_at_39 = -2000
-  db_at_38 = -2100
-  db_at_37 = -2100
-  db_at_36 = -2200
-  db_at_35 = -2200
-  db_at_34 = -2300
-  db_at_33 = -2300
-  db_at_32 = -2400
-  db_at_31 = -2400
-  db_at_30 = -2500
-  db_at_29 = -2500
-  db_at_28 = -2600
-  db_at_27 = -2600
-  db_at_26 = -2700
-  db_at_25 = -2700
-  db_at_24 = -2800
-  db_at_23 = -2900
-  db_at_22 = -2900
-  db_at_21 = -3000
-  db_at_20 = -3100
-  db_at_19 = -3200
-  db_at_18 = -3200
-  db_at_17 = -3300
-  db_at_16 = -3400
-  db_at_15 = -3500
-  db_at_14 = -3500
-  db_at_13 = -3600
-  db_at_12 = -3700
-  db_at_11 = -3800
-  db_at_10 = -3800
-  db_at_9 = -3900
-  db_at_8 = -4000
-  db_at_7 = -4100
-  db_at_6 = -4100
-  db_at_5 = -4200
-  db_at_4 = -4300
-  db_at_3 = -4400
-  db_at_2 = -4400
-  db_at_1 = -4500
-  db_at_0 = -4600
-[Headphone]
-  volume_curve = simple_step
-  volume_step = 70
-  max_volume = 0
diff --git a/cras-config/veyron_speedy/VEYRON-I2S b/cras-config/veyron_speedy/VEYRON-I2S
deleted file mode 100644
index 297ac51..0000000
--- a/cras-config/veyron_speedy/VEYRON-I2S
+++ /dev/null
@@ -1,107 +0,0 @@
-[Speaker]
-  volume_curve = explicit
-  db_at_100 = -500
-  db_at_99 = -500
-  db_at_98 = -500
-  db_at_97 = -600
-  db_at_96 = -600
-  db_at_95 = -600
-  db_at_94 = -600
-  db_at_93 = -700
-  db_at_92 = -700
-  db_at_91 = -700
-  db_at_90 = -700
-  db_at_89 = -800
-  db_at_88 = -800
-  db_at_87 = -800
-  db_at_86 = -800
-  db_at_85 = -900
-  db_at_84 = -900
-  db_at_83 = -900
-  db_at_82 = -900
-  db_at_81 = -1000
-  db_at_80 = -1000
-  db_at_79 = -1000
-  db_at_78 = -1000
-  db_at_77 = -1100
-  db_at_76 = -1100
-  db_at_75 = -1100
-  db_at_74 = -1100
-  db_at_73 = -1200
-  db_at_72 = -1200
-  db_at_71 = -1200
-  db_at_70 = -1200
-  db_at_69 = -1300
-  db_at_68 = -1300
-  db_at_67 = -1300
-  db_at_66 = -1300
-  db_at_65 = -1400
-  db_at_64 = -1400
-  db_at_63 = -1400
-  db_at_62 = -1400
-  db_at_61 = -1500
-  db_at_60 = -1500
-  db_at_59 = -1500
-  db_at_58 = -1500
-  db_at_57 = -1600
-  db_at_56 = -1600
-  db_at_55 = -1600
-  db_at_54 = -1600
-  db_at_53 = -1700
-  db_at_52 = -1700
-  db_at_51 = -1700
-  db_at_50 = -1700
-  db_at_49 = -1800
-  db_at_48 = -1800
-  db_at_47 = -1800
-  db_at_46 = -1800
-  db_at_45 = -1900
-  db_at_44 = -1900
-  db_at_43 = -1900
-  db_at_42 = -1900
-  db_at_41 = -2000
-  db_at_40 = -2000
-  db_at_39 = -2000
-  db_at_38 = -2100
-  db_at_37 = -2100
-  db_at_36 = -2200
-  db_at_35 = -2200
-  db_at_34 = -2300
-  db_at_33 = -2300
-  db_at_32 = -2400
-  db_at_31 = -2400
-  db_at_30 = -2500
-  db_at_29 = -2500
-  db_at_28 = -2600
-  db_at_27 = -2600
-  db_at_26 = -2700
-  db_at_25 = -2700
-  db_at_24 = -2800
-  db_at_23 = -2900
-  db_at_22 = -2900
-  db_at_21 = -3000
-  db_at_20 = -3100
-  db_at_19 = -3200
-  db_at_18 = -3200
-  db_at_17 = -3300
-  db_at_16 = -3400
-  db_at_15 = -3500
-  db_at_14 = -3500
-  db_at_13 = -3600
-  db_at_12 = -3700
-  db_at_11 = -3800
-  db_at_10 = -3800
-  db_at_9 = -3900
-  db_at_8 = -4000
-  db_at_7 = -4100
-  db_at_6 = -4100
-  db_at_5 = -4200
-  db_at_4 = -4300
-  db_at_3 = -4400
-  db_at_2 = -4400
-  db_at_1 = -4500
-  db_at_0 = -4600
-[Headphone]
-  volume_curve = simple_step
-  volume_step = 70
-  max_volume = 0
diff --git a/cras/README.dbus-api b/cras/README.dbus-api
index cac2f03..653bc5d 100644
--- a/cras/README.dbus-api
+++ b/cras/README.dbus-api
@@ -115,10 +115,6 @@
 				string MicPositions
 					The string formed by floating numbers
 					describing the position of mic array.
-				unit64 NodeVolume
-					The node volume indexed from 0 to 100.
-				unit64 NodeCaptureGain
-					The capture gain of node in dBFS * 100.
 				string HotwordModels
 					A string of comma-separated hotword
 					language model locales supported by this
diff --git a/cras/client/cras-sys/.gitignore b/cras/client/cras-sys/.gitignore
deleted file mode 100644
index 5245cb5..0000000
--- a/cras/client/cras-sys/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-target/
-lib_gen.rs
diff --git a/cras/client/cras-sys/.rustfmt.toml b/cras/client/cras-sys/.rustfmt.toml
deleted file mode 100644
index a2db301..0000000
--- a/cras/client/cras-sys/.rustfmt.toml
+++ /dev/null
@@ -1,2 +0,0 @@
-use_field_init_shorthand = true
-use_try_shorthand = true
diff --git a/cras/client/cras-sys/Android.bp b/cras/client/cras-sys/Android.bp
deleted file mode 100644
index 0e061b1..0000000
--- a/cras/client/cras-sys/Android.bp
+++ /dev/null
@@ -1,8 +0,0 @@
-rust_library_host_rlib {
-    name: "libcras_sys",
-    deny_warnings: false,
-    crate_name: "cras_sys",
-    edition: "2015",
-    rlibs: ["libdata_model"],
-    srcs: ["src/lib.rs"],
-}
diff --git a/cras/client/cras-sys/Cargo.toml b/cras/client/cras-sys/Cargo.toml
deleted file mode 100644
index f71e540..0000000
--- a/cras/client/cras-sys/Cargo.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[package]
-name = "cras-sys"
-version = "0.1.0"
-authors = ["The Chromium OS Authors"]
-
-[dependencies]
-data_model = { path = "../../../../../platform/crosvm/data_model" } # provided by ebuild
diff --git a/cras/client/cras-sys/generator/.gitignore b/cras/client/cras-sys/generator/.gitignore
deleted file mode 100644
index 0e8b881..0000000
--- a/cras/client/cras-sys/generator/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-*.h
-Cargo.lock
diff --git a/cras/client/cras-sys/generator/Cargo.toml b/cras/client/cras-sys/generator/Cargo.toml
deleted file mode 100644
index 87c826e..0000000
--- a/cras/client/cras-sys/generator/Cargo.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[package]
-name = "generator"
-version = "0.1.0"
-authors = ["paulhsia <paulhsia@chromium.org>"]
-
-[dependencies]
-bindgen = "0.43.0"
diff --git a/cras/client/cras-sys/generator/README.md b/cras/client/cras-sys/generator/README.md
deleted file mode 100644
index 0ca9906..0000000
--- a/cras/client/cras-sys/generator/README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-1. Use `cargo run` to generate rust bindings at `lib_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
deleted file mode 100644
index 7b47f02..0000000
--- a/cras/client/cras-sys/generator/src/main.rs
+++ /dev/null
@@ -1,152 +0,0 @@
-// 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.
-extern crate bindgen;
-
-use bindgen::builder;
-
-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")
-        .header("c_headers/cras_types.h")
-        .header("c_headers/cras_audio_format.h")
-        .header("c_headers/cras_shm.h")
-        .whitelist_type("cras_.*")
-        .whitelist_var("cras_.*")
-        .whitelist_type("CRAS_.*")
-        .whitelist_var("CRAS_.*")
-        .whitelist_type("audio_message")
-        .rustified_enum("CRAS_.*")
-        .rustified_enum("_snd_pcm_.*")
-        .generate()
-        .expect(format!("Unable to generate {} code", name).as_str());
-
-    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() {
-    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
deleted file mode 100644
index 59d146a..0000000
--- a/cras/client/cras-sys/src/gen.rs
+++ /dev/null
@@ -1,4734 +0,0 @@
-// 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
- */
-/* automatically generated by rust-bindgen */
-
-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;
-pub const CRAS_NODE_NAME_BUFFER_SIZE: u32 = 64;
-pub const CRAS_NODE_HOTWORD_MODEL_BUFFER_SIZE: u32 = 16;
-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 = 12;
-pub const CRAS_BT_EVENT_LOG_SIZE: u32 = 1024;
-pub const CRAS_SERVER_STATE_VERSION: u32 = 2;
-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_MAX_HOTWORD_MODELS: u32 = 244;
-pub const CRAS_MAX_REMIX_CHANNELS: u32 = 32;
-pub const CRAS_MAX_TEST_DATA_LEN: u32 = 224;
-pub const CRAS_AEC_DUMP_FILE_NAME_LEN: u32 = 128;
-pub const CRAS_NUM_SHM_BUFFERS: u32 = 2;
-pub const CRAS_SHM_BUFFERS_MASK: u32 = 1;
-pub type __int8_t = ::std::os::raw::c_schar;
-pub type __uint8_t = ::std::os::raw::c_uchar;
-pub type __int32_t = ::std::os::raw::c_int;
-pub type __uint32_t = ::std::os::raw::c_uint;
-pub type __int64_t = ::std::os::raw::c_long;
-pub type __uint64_t = ::std::os::raw::c_ulong;
-pub type __time_t = ::std::os::raw::c_long;
-pub type __syscall_slong_t = ::std::os::raw::c_long;
-#[repr(C, packed)]
-#[derive(Copy, Clone)]
-pub struct cras_iodev_info {
-    pub idx: u32,
-    pub name: [::std::os::raw::c_char; 64usize],
-    pub stable_id: u32,
-    pub stable_id_new: u32,
-}
-#[test]
-fn bindgen_test_layout_cras_iodev_info() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_iodev_info>(),
-        76usize,
-        concat!("Size of: ", stringify!(cras_iodev_info))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_iodev_info>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_iodev_info))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_iodev_info>())).idx as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_iodev_info),
-            "::",
-            stringify!(idx)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_iodev_info>())).name as *const _ as usize },
-        4usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_iodev_info),
-            "::",
-            stringify!(name)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_iodev_info>())).stable_id as *const _ as usize },
-        68usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_iodev_info),
-            "::",
-            stringify!(stable_id)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_iodev_info>())).stable_id_new as *const _ as usize },
-        72usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_iodev_info),
-            "::",
-            stringify!(stable_id_new)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Copy, Clone)]
-pub struct cras_ionode_info {
-    pub iodev_idx: u32,
-    pub ionode_idx: u32,
-    pub plugged: i32,
-    pub active: i32,
-    pub plugged_time: cras_ionode_info__bindgen_ty_1,
-    pub volume: u32,
-    pub capture_gain: i32,
-    pub left_right_swapped: i32,
-    pub type_enum: u32,
-    pub stable_id: u32,
-    pub stable_id_new: u32,
-    pub mic_positions: [::std::os::raw::c_char; 128usize],
-    pub type_: [::std::os::raw::c_char; 32usize],
-    pub name: [::std::os::raw::c_char; 64usize],
-    pub active_hotword_model: [::std::os::raw::c_char; 16usize],
-}
-#[repr(C)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_ionode_info__bindgen_ty_1 {
-    pub tv_sec: i64,
-    pub tv_usec: i64,
-}
-#[test]
-fn bindgen_test_layout_cras_ionode_info__bindgen_ty_1() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_ionode_info__bindgen_ty_1>(),
-        16usize,
-        concat!("Size of: ", stringify!(cras_ionode_info__bindgen_ty_1))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_ionode_info__bindgen_ty_1>(),
-        8usize,
-        concat!("Alignment of ", stringify!(cras_ionode_info__bindgen_ty_1))
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_ionode_info__bindgen_ty_1>())).tv_sec as *const _ as usize
-        },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_ionode_info__bindgen_ty_1),
-            "::",
-            stringify!(tv_sec)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_ionode_info__bindgen_ty_1>())).tv_usec as *const _ as usize
-        },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_ionode_info__bindgen_ty_1),
-            "::",
-            stringify!(tv_usec)
-        )
-    );
-}
-#[test]
-fn bindgen_test_layout_cras_ionode_info() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_ionode_info>(),
-        296usize,
-        concat!("Size of: ", stringify!(cras_ionode_info))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_ionode_info>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_ionode_info))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_ionode_info>())).iodev_idx as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_ionode_info),
-            "::",
-            stringify!(iodev_idx)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_ionode_info>())).ionode_idx as *const _ as usize },
-        4usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_ionode_info),
-            "::",
-            stringify!(ionode_idx)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_ionode_info>())).plugged as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_ionode_info),
-            "::",
-            stringify!(plugged)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_ionode_info>())).active as *const _ as usize },
-        12usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_ionode_info),
-            "::",
-            stringify!(active)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_ionode_info>())).plugged_time as *const _ as usize },
-        16usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_ionode_info),
-            "::",
-            stringify!(plugged_time)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_ionode_info>())).volume as *const _ as usize },
-        32usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_ionode_info),
-            "::",
-            stringify!(volume)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_ionode_info>())).capture_gain as *const _ as usize },
-        36usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_ionode_info),
-            "::",
-            stringify!(capture_gain)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_ionode_info>())).left_right_swapped as *const _ as usize
-        },
-        40usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_ionode_info),
-            "::",
-            stringify!(left_right_swapped)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_ionode_info>())).type_enum as *const _ as usize },
-        44usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_ionode_info),
-            "::",
-            stringify!(type_enum)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_ionode_info>())).stable_id as *const _ as usize },
-        48usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_ionode_info),
-            "::",
-            stringify!(stable_id)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_ionode_info>())).stable_id_new as *const _ as usize },
-        52usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_ionode_info),
-            "::",
-            stringify!(stable_id_new)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_ionode_info>())).mic_positions as *const _ as usize },
-        56usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_ionode_info),
-            "::",
-            stringify!(mic_positions)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_ionode_info>())).type_ as *const _ as usize },
-        184usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_ionode_info),
-            "::",
-            stringify!(type_)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_ionode_info>())).name as *const _ as usize },
-        216usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_ionode_info),
-            "::",
-            stringify!(name)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_ionode_info>())).active_hotword_model as *const _ as usize
-        },
-        280usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_ionode_info),
-            "::",
-            stringify!(active_hotword_model)
-        )
-    );
-}
-pub const ionode_attr_IONODE_ATTR_PLUGGED: ionode_attr = 0;
-pub const ionode_attr_IONODE_ATTR_VOLUME: ionode_attr = 1;
-pub const ionode_attr_IONODE_ATTR_CAPTURE_GAIN: ionode_attr = 2;
-pub const ionode_attr_IONODE_ATTR_SWAP_LEFT_RIGHT: ionode_attr = 3;
-pub type ionode_attr = u32;
-#[repr(C)]
-#[derive(Debug, Copy, Clone)]
-pub struct timespec {
-    pub tv_sec: __time_t,
-    pub tv_nsec: __syscall_slong_t,
-}
-#[test]
-fn bindgen_test_layout_timespec() {
-    assert_eq!(
-        ::std::mem::size_of::<timespec>(),
-        16usize,
-        concat!("Size of: ", stringify!(timespec))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<timespec>(),
-        8usize,
-        concat!("Alignment of ", stringify!(timespec))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<timespec>())).tv_sec as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(timespec),
-            "::",
-            stringify!(tv_sec)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<timespec>())).tv_nsec as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(timespec),
-            "::",
-            stringify!(tv_nsec)
-        )
-    );
-}
-impl _snd_pcm_format {
-    pub const SND_PCM_FORMAT_LAST: _snd_pcm_format = _snd_pcm_format::SND_PCM_FORMAT_DSD_U32_BE;
-}
-impl _snd_pcm_format {
-    pub const SND_PCM_FORMAT_S16: _snd_pcm_format = _snd_pcm_format::SND_PCM_FORMAT_S16_LE;
-}
-impl _snd_pcm_format {
-    pub const SND_PCM_FORMAT_U16: _snd_pcm_format = _snd_pcm_format::SND_PCM_FORMAT_U16_LE;
-}
-impl _snd_pcm_format {
-    pub const SND_PCM_FORMAT_S24: _snd_pcm_format = _snd_pcm_format::SND_PCM_FORMAT_S24_LE;
-}
-impl _snd_pcm_format {
-    pub const SND_PCM_FORMAT_U24: _snd_pcm_format = _snd_pcm_format::SND_PCM_FORMAT_U24_LE;
-}
-impl _snd_pcm_format {
-    pub const SND_PCM_FORMAT_S32: _snd_pcm_format = _snd_pcm_format::SND_PCM_FORMAT_S32_LE;
-}
-impl _snd_pcm_format {
-    pub const SND_PCM_FORMAT_U32: _snd_pcm_format = _snd_pcm_format::SND_PCM_FORMAT_U32_LE;
-}
-impl _snd_pcm_format {
-    pub const SND_PCM_FORMAT_FLOAT: _snd_pcm_format = _snd_pcm_format::SND_PCM_FORMAT_FLOAT_LE;
-}
-impl _snd_pcm_format {
-    pub const SND_PCM_FORMAT_FLOAT64: _snd_pcm_format = _snd_pcm_format::SND_PCM_FORMAT_FLOAT64_LE;
-}
-impl _snd_pcm_format {
-    pub const SND_PCM_FORMAT_IEC958_SUBFRAME: _snd_pcm_format =
-        _snd_pcm_format::SND_PCM_FORMAT_IEC958_SUBFRAME_LE;
-}
-impl _snd_pcm_format {
-    pub const SND_PCM_FORMAT_S20: _snd_pcm_format = _snd_pcm_format::SND_PCM_FORMAT_S20_LE;
-}
-impl _snd_pcm_format {
-    pub const SND_PCM_FORMAT_U20: _snd_pcm_format = _snd_pcm_format::SND_PCM_FORMAT_U20_LE;
-}
-#[repr(i32)]
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum _snd_pcm_format {
-    SND_PCM_FORMAT_UNKNOWN = -1,
-    SND_PCM_FORMAT_S8 = 0,
-    SND_PCM_FORMAT_U8 = 1,
-    SND_PCM_FORMAT_S16_LE = 2,
-    SND_PCM_FORMAT_S16_BE = 3,
-    SND_PCM_FORMAT_U16_LE = 4,
-    SND_PCM_FORMAT_U16_BE = 5,
-    SND_PCM_FORMAT_S24_LE = 6,
-    SND_PCM_FORMAT_S24_BE = 7,
-    SND_PCM_FORMAT_U24_LE = 8,
-    SND_PCM_FORMAT_U24_BE = 9,
-    SND_PCM_FORMAT_S32_LE = 10,
-    SND_PCM_FORMAT_S32_BE = 11,
-    SND_PCM_FORMAT_U32_LE = 12,
-    SND_PCM_FORMAT_U32_BE = 13,
-    SND_PCM_FORMAT_FLOAT_LE = 14,
-    SND_PCM_FORMAT_FLOAT_BE = 15,
-    SND_PCM_FORMAT_FLOAT64_LE = 16,
-    SND_PCM_FORMAT_FLOAT64_BE = 17,
-    SND_PCM_FORMAT_IEC958_SUBFRAME_LE = 18,
-    SND_PCM_FORMAT_IEC958_SUBFRAME_BE = 19,
-    SND_PCM_FORMAT_MU_LAW = 20,
-    SND_PCM_FORMAT_A_LAW = 21,
-    SND_PCM_FORMAT_IMA_ADPCM = 22,
-    SND_PCM_FORMAT_MPEG = 23,
-    SND_PCM_FORMAT_GSM = 24,
-    SND_PCM_FORMAT_S20_LE = 25,
-    SND_PCM_FORMAT_S20_BE = 26,
-    SND_PCM_FORMAT_U20_LE = 27,
-    SND_PCM_FORMAT_U20_BE = 28,
-    SND_PCM_FORMAT_SPECIAL = 31,
-    SND_PCM_FORMAT_S24_3LE = 32,
-    SND_PCM_FORMAT_S24_3BE = 33,
-    SND_PCM_FORMAT_U24_3LE = 34,
-    SND_PCM_FORMAT_U24_3BE = 35,
-    SND_PCM_FORMAT_S20_3LE = 36,
-    SND_PCM_FORMAT_S20_3BE = 37,
-    SND_PCM_FORMAT_U20_3LE = 38,
-    SND_PCM_FORMAT_U20_3BE = 39,
-    SND_PCM_FORMAT_S18_3LE = 40,
-    SND_PCM_FORMAT_S18_3BE = 41,
-    SND_PCM_FORMAT_U18_3LE = 42,
-    SND_PCM_FORMAT_U18_3BE = 43,
-    SND_PCM_FORMAT_G723_24 = 44,
-    SND_PCM_FORMAT_G723_24_1B = 45,
-    SND_PCM_FORMAT_G723_40 = 46,
-    SND_PCM_FORMAT_G723_40_1B = 47,
-    SND_PCM_FORMAT_DSD_U8 = 48,
-    SND_PCM_FORMAT_DSD_U16_LE = 49,
-    SND_PCM_FORMAT_DSD_U32_LE = 50,
-    SND_PCM_FORMAT_DSD_U16_BE = 51,
-    SND_PCM_FORMAT_DSD_U32_BE = 52,
-}
-pub use self::_snd_pcm_format as snd_pcm_format_t;
-#[repr(u32)]
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum CRAS_CHANNEL {
-    CRAS_CH_FL = 0,
-    CRAS_CH_FR = 1,
-    CRAS_CH_RL = 2,
-    CRAS_CH_RR = 3,
-    CRAS_CH_FC = 4,
-    CRAS_CH_LFE = 5,
-    CRAS_CH_SL = 6,
-    CRAS_CH_SR = 7,
-    CRAS_CH_RC = 8,
-    CRAS_CH_FLC = 9,
-    CRAS_CH_FRC = 10,
-    CRAS_CH_MAX = 11,
-}
-#[repr(C)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_audio_format {
-    pub format: snd_pcm_format_t,
-    pub frame_rate: usize,
-    pub num_channels: usize,
-    pub channel_layout: [i8; 11usize],
-}
-#[test]
-fn bindgen_test_layout_cras_audio_format() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_audio_format>(),
-        40usize,
-        concat!("Size of: ", stringify!(cras_audio_format))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_audio_format>(),
-        8usize,
-        concat!("Alignment of ", stringify!(cras_audio_format))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_audio_format>())).format as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_audio_format),
-            "::",
-            stringify!(format)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_audio_format>())).frame_rate as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_audio_format),
-            "::",
-            stringify!(frame_rate)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_audio_format>())).num_channels as *const _ as usize },
-        16usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_audio_format),
-            "::",
-            stringify!(num_channels)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_audio_format>())).channel_layout as *const _ as usize
-        },
-        24usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_audio_format),
-            "::",
-            stringify!(channel_layout)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_audio_format_packed {
-    pub format: i32,
-    pub frame_rate: u32,
-    pub num_channels: u32,
-    pub channel_layout: [i8; 11usize],
-}
-#[test]
-fn bindgen_test_layout_cras_audio_format_packed() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_audio_format_packed>(),
-        23usize,
-        concat!("Size of: ", stringify!(cras_audio_format_packed))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_audio_format_packed>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_audio_format_packed))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_audio_format_packed>())).format as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_audio_format_packed),
-            "::",
-            stringify!(format)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_audio_format_packed>())).frame_rate as *const _ as usize
-        },
-        4usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_audio_format_packed),
-            "::",
-            stringify!(frame_rate)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_audio_format_packed>())).num_channels as *const _ as usize
-        },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_audio_format_packed),
-            "::",
-            stringify!(num_channels)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_audio_format_packed>())).channel_layout as *const _ as usize
-        },
-        12usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_audio_format_packed),
-            "::",
-            stringify!(channel_layout)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_timespec {
-    pub tv_sec: i64,
-    pub tv_nsec: i64,
-}
-#[test]
-fn bindgen_test_layout_cras_timespec() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_timespec>(),
-        16usize,
-        concat!("Size of: ", stringify!(cras_timespec))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_timespec>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_timespec))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_timespec>())).tv_sec as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_timespec),
-            "::",
-            stringify!(tv_sec)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_timespec>())).tv_nsec as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_timespec),
-            "::",
-            stringify!(tv_nsec)
-        )
-    );
-}
-#[repr(u32)]
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum CRAS_SPECIAL_DEVICE {
-    NO_DEVICE = 0,
-    SILENT_RECORD_DEVICE = 1,
-    SILENT_PLAYBACK_DEVICE = 2,
-    SILENT_HOTWORD_DEVICE = 3,
-    MAX_SPECIAL_DEVICE_IDX = 4,
-}
-pub const TEST_IODEV_TYPE_TEST_IODEV_HOTWORD: TEST_IODEV_TYPE = 0;
-pub type TEST_IODEV_TYPE = u32;
-#[repr(u32)]
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum CRAS_TEST_IODEV_CMD {
-    TEST_IODEV_CMD_HOTWORD_TRIGGER = 0,
-}
-#[repr(u32)]
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum CRAS_STREAM_DIRECTION {
-    CRAS_STREAM_OUTPUT = 0,
-    CRAS_STREAM_INPUT = 1,
-    CRAS_STREAM_UNDEFINED = 2,
-    CRAS_STREAM_POST_MIX_PRE_DSP = 3,
-    CRAS_NUM_DIRECTIONS = 4,
-}
-#[repr(u32)]
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum CRAS_INPUT_STREAM_FLAG {
-    BULK_AUDIO_OK = 1,
-    USE_DEV_TIMING = 2,
-    HOTWORD_STREAM = 3,
-    TRIGGER_ONLY = 4,
-    SERVER_ONLY = 8,
-}
-#[repr(u32)]
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum CRAS_LOOPBACK_TYPE {
-    LOOPBACK_POST_MIX_PRE_DSP = 0,
-    LOOPBACK_POST_DSP = 1,
-    LOOPBACK_NUM_TYPES = 2,
-}
-#[repr(u32)]
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum CRAS_STREAM_TYPE {
-    CRAS_STREAM_TYPE_DEFAULT = 0,
-    CRAS_STREAM_TYPE_MULTIMEDIA = 1,
-    CRAS_STREAM_TYPE_VOICE_COMMUNICATION = 2,
-    CRAS_STREAM_TYPE_SPEECH_RECOGNITION = 3,
-    CRAS_STREAM_TYPE_PRO_AUDIO = 4,
-    CRAS_STREAM_TYPE_ACCESSIBILITY = 5,
-    CRAS_STREAM_NUM_TYPES = 6,
-}
-#[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,
-    APM_GAIN_CONTROL = 4,
-    APM_VOICE_DETECTION = 8,
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_attached_client_info {
-    pub id: u32,
-    pub pid: i32,
-    pub uid: u32,
-    pub gid: u32,
-}
-#[test]
-fn bindgen_test_layout_cras_attached_client_info() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_attached_client_info>(),
-        16usize,
-        concat!("Size of: ", stringify!(cras_attached_client_info))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_attached_client_info>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_attached_client_info))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_attached_client_info>())).id as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_attached_client_info),
-            "::",
-            stringify!(id)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_attached_client_info>())).pid as *const _ as usize },
-        4usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_attached_client_info),
-            "::",
-            stringify!(pid)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_attached_client_info>())).uid as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_attached_client_info),
-            "::",
-            stringify!(uid)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_attached_client_info>())).gid as *const _ as usize },
-        12usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_attached_client_info),
-            "::",
-            stringify!(gid)
-        )
-    );
-}
-pub type cras_node_id_t = u64;
-#[repr(u32)]
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum CRAS_BT_LOG_EVENTS {
-    BT_ADAPTER_ADDED = 0,
-    BT_ADAPTER_REMOVED = 1,
-    BT_AUDIO_GATEWAY_INIT = 2,
-    BT_AUDIO_GATEWAY_START = 3,
-    BT_AVAILABLE_CODECS = 4,
-    BT_A2DP_CONFIGURED = 5,
-    BT_A2DP_START = 6,
-    BT_A2DP_SUSPENDED = 7,
-    BT_CODEC_SELECTION = 8,
-    BT_DEV_CONNECTED_CHANGE = 9,
-    BT_DEV_CONN_WATCH_CB = 10,
-    BT_DEV_SUSPEND_CB = 11,
-    BT_HFP_NEW_CONNECTION = 12,
-    BT_HFP_REQUEST_DISCONNECT = 13,
-    BT_HFP_SUPPORTED_FEATURES = 14,
-    BT_HSP_NEW_CONNECTION = 15,
-    BT_HSP_REQUEST_DISCONNECT = 16,
-    BT_NEW_AUDIO_PROFILE_AFTER_CONNECT = 17,
-    BT_RESET = 18,
-    BT_SCO_CONNECT = 19,
-    BT_TRANSPORT_ACQUIRE = 20,
-    BT_TRANSPORT_RELEASE = 21,
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct audio_thread_event {
-    pub tag_sec: u32,
-    pub nsec: u32,
-    pub data1: u32,
-    pub data2: u32,
-    pub data3: u32,
-}
-#[test]
-fn bindgen_test_layout_audio_thread_event() {
-    assert_eq!(
-        ::std::mem::size_of::<audio_thread_event>(),
-        20usize,
-        concat!("Size of: ", stringify!(audio_thread_event))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<audio_thread_event>(),
-        1usize,
-        concat!("Alignment of ", stringify!(audio_thread_event))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<audio_thread_event>())).tag_sec as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_thread_event),
-            "::",
-            stringify!(tag_sec)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<audio_thread_event>())).nsec as *const _ as usize },
-        4usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_thread_event),
-            "::",
-            stringify!(nsec)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<audio_thread_event>())).data1 as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_thread_event),
-            "::",
-            stringify!(data1)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<audio_thread_event>())).data2 as *const _ as usize },
-        12usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_thread_event),
-            "::",
-            stringify!(data2)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<audio_thread_event>())).data3 as *const _ as usize },
-        16usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_thread_event),
-            "::",
-            stringify!(data3)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Copy, Clone)]
-pub struct audio_thread_event_log {
-    pub write_pos: u32,
-    pub len: u32,
-    pub log: [audio_thread_event; 6144usize],
-}
-#[test]
-fn bindgen_test_layout_audio_thread_event_log() {
-    assert_eq!(
-        ::std::mem::size_of::<audio_thread_event_log>(),
-        122888usize,
-        concat!("Size of: ", stringify!(audio_thread_event_log))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<audio_thread_event_log>(),
-        1usize,
-        concat!("Alignment of ", stringify!(audio_thread_event_log))
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_thread_event_log>())).write_pos as *const _ as usize
-        },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_thread_event_log),
-            "::",
-            stringify!(write_pos)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<audio_thread_event_log>())).len as *const _ as usize },
-        4usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_thread_event_log),
-            "::",
-            stringify!(len)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<audio_thread_event_log>())).log as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_thread_event_log),
-            "::",
-            stringify!(log)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Copy, Clone)]
-pub struct audio_dev_debug_info {
-    pub dev_name: [::std::os::raw::c_char; 64usize],
-    pub buffer_size: u32,
-    pub min_buffer_level: u32,
-    pub min_cb_level: u32,
-    pub max_cb_level: u32,
-    pub frame_rate: u32,
-    pub num_channels: u32,
-    pub est_rate_ratio: f64,
-    pub direction: u8,
-    pub num_underruns: u32,
-    pub num_severe_underruns: u32,
-    pub highest_hw_level: u32,
-    pub runtime_sec: u32,
-    pub runtime_nsec: u32,
-    pub software_gain_scaler: f64,
-}
-#[test]
-fn bindgen_test_layout_audio_dev_debug_info() {
-    assert_eq!(
-        ::std::mem::size_of::<audio_dev_debug_info>(),
-        125usize,
-        concat!("Size of: ", stringify!(audio_dev_debug_info))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<audio_dev_debug_info>(),
-        1usize,
-        concat!("Alignment of ", stringify!(audio_dev_debug_info))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<audio_dev_debug_info>())).dev_name as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_dev_debug_info),
-            "::",
-            stringify!(dev_name)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_dev_debug_info>())).buffer_size as *const _ as usize
-        },
-        64usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_dev_debug_info),
-            "::",
-            stringify!(buffer_size)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_dev_debug_info>())).min_buffer_level as *const _ as usize
-        },
-        68usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_dev_debug_info),
-            "::",
-            stringify!(min_buffer_level)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_dev_debug_info>())).min_cb_level as *const _ as usize
-        },
-        72usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_dev_debug_info),
-            "::",
-            stringify!(min_cb_level)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_dev_debug_info>())).max_cb_level as *const _ as usize
-        },
-        76usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_dev_debug_info),
-            "::",
-            stringify!(max_cb_level)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<audio_dev_debug_info>())).frame_rate as *const _ as usize },
-        80usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_dev_debug_info),
-            "::",
-            stringify!(frame_rate)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_dev_debug_info>())).num_channels as *const _ as usize
-        },
-        84usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_dev_debug_info),
-            "::",
-            stringify!(num_channels)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_dev_debug_info>())).est_rate_ratio as *const _ as usize
-        },
-        88usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_dev_debug_info),
-            "::",
-            stringify!(est_rate_ratio)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<audio_dev_debug_info>())).direction as *const _ as usize },
-        96usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_dev_debug_info),
-            "::",
-            stringify!(direction)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_dev_debug_info>())).num_underruns as *const _ as usize
-        },
-        97usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_dev_debug_info),
-            "::",
-            stringify!(num_underruns)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_dev_debug_info>())).num_severe_underruns as *const _
-                as usize
-        },
-        101usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_dev_debug_info),
-            "::",
-            stringify!(num_severe_underruns)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_dev_debug_info>())).highest_hw_level as *const _ as usize
-        },
-        105usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_dev_debug_info),
-            "::",
-            stringify!(highest_hw_level)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_dev_debug_info>())).runtime_sec as *const _ as usize
-        },
-        109usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_dev_debug_info),
-            "::",
-            stringify!(runtime_sec)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_dev_debug_info>())).runtime_nsec as *const _ as usize
-        },
-        113usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_dev_debug_info),
-            "::",
-            stringify!(runtime_nsec)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_dev_debug_info>())).software_gain_scaler as *const _
-                as usize
-        },
-        117usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_dev_debug_info),
-            "::",
-            stringify!(software_gain_scaler)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct audio_stream_debug_info {
-    pub stream_id: u64,
-    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,
-    pub flags: u32,
-    pub frame_rate: u32,
-    pub num_channels: u32,
-    pub longest_fetch_sec: u32,
-    pub longest_fetch_nsec: u32,
-    pub num_missed_cb: u32,
-    pub num_overruns: u32,
-    pub is_pinned: u32,
-    pub pinned_dev_idx: u32,
-    pub runtime_sec: u32,
-    pub runtime_nsec: u32,
-    pub stream_volume: f64,
-    pub channel_layout: [i8; 11usize],
-}
-#[test]
-fn bindgen_test_layout_audio_stream_debug_info() {
-    assert_eq!(
-        ::std::mem::size_of::<audio_stream_debug_info>(),
-        103usize,
-        concat!("Size of: ", stringify!(audio_stream_debug_info))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<audio_stream_debug_info>(),
-        1usize,
-        concat!("Alignment of ", stringify!(audio_stream_debug_info))
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_stream_debug_info>())).stream_id as *const _ as usize
-        },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_stream_debug_info),
-            "::",
-            stringify!(stream_id)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<audio_stream_debug_info>())).dev_idx as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_stream_debug_info),
-            "::",
-            stringify!(dev_idx)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_stream_debug_info>())).direction as *const _ as usize
-        },
-        12usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_stream_debug_info),
-            "::",
-            stringify!(direction)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_stream_debug_info>())).stream_type as *const _ as usize
-        },
-        16usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_stream_debug_info),
-            "::",
-            stringify!(stream_type)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::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)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_stream_debug_info>())).cb_threshold as *const _ as usize
-        },
-        28usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_stream_debug_info),
-            "::",
-            stringify!(cb_threshold)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<audio_stream_debug_info>())).effects as *const _ as usize },
-        32usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_stream_debug_info),
-            "::",
-            stringify!(effects)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<audio_stream_debug_info>())).flags as *const _ as usize },
-        40usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_stream_debug_info),
-            "::",
-            stringify!(flags)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_stream_debug_info>())).frame_rate as *const _ as usize
-        },
-        44usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_stream_debug_info),
-            "::",
-            stringify!(frame_rate)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_stream_debug_info>())).num_channels as *const _ as usize
-        },
-        48usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_stream_debug_info),
-            "::",
-            stringify!(num_channels)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_stream_debug_info>())).longest_fetch_sec as *const _
-                as usize
-        },
-        52usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_stream_debug_info),
-            "::",
-            stringify!(longest_fetch_sec)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_stream_debug_info>())).longest_fetch_nsec as *const _
-                as usize
-        },
-        56usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_stream_debug_info),
-            "::",
-            stringify!(longest_fetch_nsec)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_stream_debug_info>())).num_missed_cb as *const _ as usize
-        },
-        60usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_stream_debug_info),
-            "::",
-            stringify!(num_missed_cb)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_stream_debug_info>())).num_overruns as *const _ as usize
-        },
-        64usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_stream_debug_info),
-            "::",
-            stringify!(num_overruns)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_stream_debug_info>())).is_pinned as *const _ as usize
-        },
-        68usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_stream_debug_info),
-            "::",
-            stringify!(is_pinned)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_stream_debug_info>())).pinned_dev_idx as *const _ as usize
-        },
-        72usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_stream_debug_info),
-            "::",
-            stringify!(pinned_dev_idx)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_stream_debug_info>())).runtime_sec as *const _ as usize
-        },
-        76usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_stream_debug_info),
-            "::",
-            stringify!(runtime_sec)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_stream_debug_info>())).runtime_nsec as *const _ as usize
-        },
-        80usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_stream_debug_info),
-            "::",
-            stringify!(runtime_nsec)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_stream_debug_info>())).stream_volume as *const _ as usize
-        },
-        84usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_stream_debug_info),
-            "::",
-            stringify!(stream_volume)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<audio_stream_debug_info>())).channel_layout as *const _ as usize
-        },
-        92usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_stream_debug_info),
-            "::",
-            stringify!(channel_layout)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Copy, Clone)]
-pub struct audio_debug_info {
-    pub num_streams: u32,
-    pub num_devs: u32,
-    pub devs: [audio_dev_debug_info; 4usize],
-    pub streams: [audio_stream_debug_info; 8usize],
-    pub log: audio_thread_event_log,
-}
-#[test]
-fn bindgen_test_layout_audio_debug_info() {
-    assert_eq!(
-        ::std::mem::size_of::<audio_debug_info>(),
-        124220usize,
-        concat!("Size of: ", stringify!(audio_debug_info))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<audio_debug_info>(),
-        1usize,
-        concat!("Alignment of ", stringify!(audio_debug_info))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<audio_debug_info>())).num_streams as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_debug_info),
-            "::",
-            stringify!(num_streams)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<audio_debug_info>())).num_devs as *const _ as usize },
-        4usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_debug_info),
-            "::",
-            stringify!(num_devs)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<audio_debug_info>())).devs as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_debug_info),
-            "::",
-            stringify!(devs)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<audio_debug_info>())).streams as *const _ as usize },
-        508usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_debug_info),
-            "::",
-            stringify!(streams)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<audio_debug_info>())).log as *const _ as usize },
-        1332usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_debug_info),
-            "::",
-            stringify!(log)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_bt_event {
-    pub tag_sec: u32,
-    pub nsec: u32,
-    pub data1: u32,
-    pub data2: u32,
-}
-#[test]
-fn bindgen_test_layout_cras_bt_event() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_bt_event>(),
-        16usize,
-        concat!("Size of: ", stringify!(cras_bt_event))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_bt_event>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_bt_event))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_bt_event>())).tag_sec as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_bt_event),
-            "::",
-            stringify!(tag_sec)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_bt_event>())).nsec as *const _ as usize },
-        4usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_bt_event),
-            "::",
-            stringify!(nsec)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_bt_event>())).data1 as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_bt_event),
-            "::",
-            stringify!(data1)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_bt_event>())).data2 as *const _ as usize },
-        12usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_bt_event),
-            "::",
-            stringify!(data2)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Copy, Clone)]
-pub struct cras_bt_event_log {
-    pub write_pos: u32,
-    pub len: u32,
-    pub log: [cras_bt_event; 1024usize],
-}
-#[test]
-fn bindgen_test_layout_cras_bt_event_log() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_bt_event_log>(),
-        16392usize,
-        concat!("Size of: ", stringify!(cras_bt_event_log))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_bt_event_log>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_bt_event_log))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_bt_event_log>())).write_pos as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_bt_event_log),
-            "::",
-            stringify!(write_pos)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_bt_event_log>())).len as *const _ as usize },
-        4usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_bt_event_log),
-            "::",
-            stringify!(len)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_bt_event_log>())).log as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_bt_event_log),
-            "::",
-            stringify!(log)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Copy, Clone)]
-pub struct cras_bt_debug_info {
-    pub bt_log: cras_bt_event_log,
-}
-#[test]
-fn bindgen_test_layout_cras_bt_debug_info() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_bt_debug_info>(),
-        16392usize,
-        concat!("Size of: ", stringify!(cras_bt_debug_info))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_bt_debug_info>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_bt_debug_info))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_bt_debug_info>())).bt_log as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_bt_debug_info),
-            "::",
-            stringify!(bt_log)
-        )
-    );
-}
-#[repr(u32)]
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum CRAS_AUDIO_THREAD_EVENT_TYPE {
-    AUDIO_THREAD_EVENT_BUSYLOOP = 0,
-    AUDIO_THREAD_EVENT_DEBUG = 1,
-    AUDIO_THREAD_EVENT_SEVERE_UNDERRUN = 2,
-    AUDIO_THREAD_EVENT_UNDERRUN = 3,
-    AUDIO_THREAD_EVENT_TYPE_COUNT = 4,
-}
-#[repr(C, packed)]
-#[derive(Copy, Clone)]
-pub struct cras_audio_thread_snapshot {
-    pub timestamp: timespec,
-    pub event_type: CRAS_AUDIO_THREAD_EVENT_TYPE,
-    pub audio_debug_info: audio_debug_info,
-}
-#[test]
-fn bindgen_test_layout_cras_audio_thread_snapshot() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_audio_thread_snapshot>(),
-        124240usize,
-        concat!("Size of: ", stringify!(cras_audio_thread_snapshot))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_audio_thread_snapshot>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_audio_thread_snapshot))
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_audio_thread_snapshot>())).timestamp as *const _ as usize
-        },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_audio_thread_snapshot),
-            "::",
-            stringify!(timestamp)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_audio_thread_snapshot>())).event_type as *const _ as usize
-        },
-        16usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_audio_thread_snapshot),
-            "::",
-            stringify!(event_type)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_audio_thread_snapshot>())).audio_debug_info as *const _
-                as usize
-        },
-        20usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_audio_thread_snapshot),
-            "::",
-            stringify!(audio_debug_info)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Copy, Clone)]
-pub struct cras_audio_thread_snapshot_buffer {
-    pub snapshots: [cras_audio_thread_snapshot; 10usize],
-    pub pos: ::std::os::raw::c_int,
-}
-#[test]
-fn bindgen_test_layout_cras_audio_thread_snapshot_buffer() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_audio_thread_snapshot_buffer>(),
-        1242404usize,
-        concat!("Size of: ", stringify!(cras_audio_thread_snapshot_buffer))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_audio_thread_snapshot_buffer>(),
-        1usize,
-        concat!(
-            "Alignment of ",
-            stringify!(cras_audio_thread_snapshot_buffer)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_audio_thread_snapshot_buffer>())).snapshots as *const _
-                as usize
-        },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_audio_thread_snapshot_buffer),
-            "::",
-            stringify!(snapshots)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_audio_thread_snapshot_buffer>())).pos as *const _ as usize
-        },
-        1242400usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_audio_thread_snapshot_buffer),
-            "::",
-            stringify!(pos)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Copy, Clone)]
-pub struct cras_server_state {
-    pub state_version: u32,
-    pub volume: u32,
-    pub min_volume_dBFS: i32,
-    pub max_volume_dBFS: i32,
-    pub mute: i32,
-    pub user_mute: i32,
-    pub mute_locked: i32,
-    pub suspended: i32,
-    pub capture_gain: i32,
-    pub capture_gain_target: i32,
-    pub capture_mute: i32,
-    pub capture_mute_locked: i32,
-    pub min_capture_gain: i32,
-    pub max_capture_gain: i32,
-    pub num_streams_attached: u32,
-    pub num_output_devs: u32,
-    pub num_input_devs: u32,
-    pub output_devs: [cras_iodev_info; 20usize],
-    pub input_devs: [cras_iodev_info; 20usize],
-    pub num_output_nodes: u32,
-    pub num_input_nodes: u32,
-    pub output_nodes: [cras_ionode_info; 20usize],
-    pub input_nodes: [cras_ionode_info; 20usize],
-    pub num_attached_clients: u32,
-    pub client_info: [cras_attached_client_info; 20usize],
-    pub update_count: u32,
-    pub num_active_streams: [u32; 4usize],
-    pub last_active_stream_time: cras_timespec,
-    pub audio_debug_info: audio_debug_info,
-    pub default_output_buffer_size: i32,
-    pub non_empty_status: i32,
-    pub aec_supported: i32,
-    pub aec_group_id: i32,
-    pub snapshot_buffer: cras_audio_thread_snapshot_buffer,
-    pub bt_debug_info: cras_bt_debug_info,
-    pub bt_wbs_enabled: i32,
-}
-#[test]
-fn bindgen_test_layout_cras_server_state() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_server_state>(),
-        1398352usize,
-        concat!("Size of: ", stringify!(cras_server_state))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_server_state>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_server_state))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_server_state>())).state_version as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(state_version)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_server_state>())).volume as *const _ as usize },
-        4usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(volume)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_server_state>())).min_volume_dBFS as *const _ as usize
-        },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(min_volume_dBFS)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_server_state>())).max_volume_dBFS as *const _ as usize
-        },
-        12usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(max_volume_dBFS)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_server_state>())).mute as *const _ as usize },
-        16usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(mute)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_server_state>())).user_mute as *const _ as usize },
-        20usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(user_mute)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_server_state>())).mute_locked as *const _ as usize },
-        24usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(mute_locked)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_server_state>())).suspended as *const _ as usize },
-        28usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(suspended)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_server_state>())).capture_gain as *const _ as usize },
-        32usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(capture_gain)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_server_state>())).capture_gain_target as *const _ as usize
-        },
-        36usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(capture_gain_target)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_server_state>())).capture_mute as *const _ as usize },
-        40usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(capture_mute)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_server_state>())).capture_mute_locked as *const _ as usize
-        },
-        44usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(capture_mute_locked)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_server_state>())).min_capture_gain as *const _ as usize
-        },
-        48usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(min_capture_gain)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_server_state>())).max_capture_gain as *const _ as usize
-        },
-        52usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(max_capture_gain)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_server_state>())).num_streams_attached as *const _ as usize
-        },
-        56usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(num_streams_attached)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_server_state>())).num_output_devs as *const _ as usize
-        },
-        60usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(num_output_devs)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_server_state>())).num_input_devs as *const _ as usize
-        },
-        64usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(num_input_devs)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_server_state>())).output_devs as *const _ as usize },
-        68usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(output_devs)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_server_state>())).input_devs as *const _ as usize },
-        1588usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(input_devs)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_server_state>())).num_output_nodes as *const _ as usize
-        },
-        3108usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(num_output_nodes)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_server_state>())).num_input_nodes as *const _ as usize
-        },
-        3112usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(num_input_nodes)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_server_state>())).output_nodes as *const _ as usize },
-        3116usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(output_nodes)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_server_state>())).input_nodes as *const _ as usize },
-        9036usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(input_nodes)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_server_state>())).num_attached_clients as *const _ as usize
-        },
-        14956usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(num_attached_clients)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_server_state>())).client_info as *const _ as usize },
-        14960usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(client_info)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_server_state>())).update_count as *const _ as usize },
-        15280usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(update_count)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_server_state>())).num_active_streams as *const _ as usize
-        },
-        15284usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(num_active_streams)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_server_state>())).last_active_stream_time as *const _
-                as usize
-        },
-        15300usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(last_active_stream_time)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_server_state>())).audio_debug_info as *const _ as usize
-        },
-        15316usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(audio_debug_info)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_server_state>())).default_output_buffer_size as *const _
-                as usize
-        },
-        139536usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(default_output_buffer_size)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_server_state>())).non_empty_status as *const _ as usize
-        },
-        139540usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(non_empty_status)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_server_state>())).aec_supported as *const _ as usize },
-        139544usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(aec_supported)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_server_state>())).aec_group_id as *const _ as usize },
-        139548usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(aec_group_id)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_server_state>())).snapshot_buffer as *const _ as usize
-        },
-        139552usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(snapshot_buffer)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_server_state>())).bt_debug_info as *const _ as usize },
-        1381956usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(bt_debug_info)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_server_state>())).bt_wbs_enabled as *const _ as usize
-        },
-        1398348usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_state),
-            "::",
-            stringify!(bt_wbs_enabled)
-        )
-    );
-}
-pub const cras_notify_device_action_CRAS_DEVICE_ACTION_ADD: cras_notify_device_action = 0;
-pub const cras_notify_device_action_CRAS_DEVICE_ACTION_REMOVE: cras_notify_device_action = 1;
-pub const cras_notify_device_action_CRAS_DEVICE_ACTION_CHANGE: cras_notify_device_action = 2;
-pub type cras_notify_device_action = u32;
-#[repr(u32)]
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum CRAS_ALSA_CARD_TYPE {
-    ALSA_CARD_TYPE_INTERNAL = 0,
-    ALSA_CARD_TYPE_USB = 1,
-}
-#[repr(C, packed)]
-#[derive(Copy, Clone)]
-pub struct cras_alsa_card_info {
-    pub card_type: CRAS_ALSA_CARD_TYPE,
-    pub card_index: u32,
-    pub usb_vendor_id: u32,
-    pub usb_product_id: u32,
-    pub usb_serial_number: [::std::os::raw::c_char; 64usize],
-    pub usb_desc_checksum: u32,
-}
-#[test]
-fn bindgen_test_layout_cras_alsa_card_info() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_alsa_card_info>(),
-        84usize,
-        concat!("Size of: ", stringify!(cras_alsa_card_info))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_alsa_card_info>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_alsa_card_info))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_alsa_card_info>())).card_type as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_alsa_card_info),
-            "::",
-            stringify!(card_type)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_alsa_card_info>())).card_index as *const _ as usize },
-        4usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_alsa_card_info),
-            "::",
-            stringify!(card_index)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_alsa_card_info>())).usb_vendor_id as *const _ as usize
-        },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_alsa_card_info),
-            "::",
-            stringify!(usb_vendor_id)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_alsa_card_info>())).usb_product_id as *const _ as usize
-        },
-        12usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_alsa_card_info),
-            "::",
-            stringify!(usb_product_id)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_alsa_card_info>())).usb_serial_number as *const _ as usize
-        },
-        16usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_alsa_card_info),
-            "::",
-            stringify!(usb_serial_number)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_alsa_card_info>())).usb_desc_checksum as *const _ as usize
-        },
-        80usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_alsa_card_info),
-            "::",
-            stringify!(usb_desc_checksum)
-        )
-    );
-}
-pub type cras_stream_id_t = u32;
-#[repr(u32)]
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum CRAS_NODE_TYPE {
-    CRAS_NODE_TYPE_INTERNAL_SPEAKER = 0,
-    CRAS_NODE_TYPE_HEADPHONE = 1,
-    CRAS_NODE_TYPE_HDMI = 2,
-    CRAS_NODE_TYPE_HAPTIC = 3,
-    CRAS_NODE_TYPE_LINEOUT = 4,
-    CRAS_NODE_TYPE_MIC = 5,
-    CRAS_NODE_TYPE_HOTWORD = 6,
-    CRAS_NODE_TYPE_POST_MIX_PRE_DSP = 7,
-    CRAS_NODE_TYPE_POST_DSP = 8,
-    CRAS_NODE_TYPE_USB = 9,
-    CRAS_NODE_TYPE_BLUETOOTH = 10,
-    CRAS_NODE_TYPE_UNKNOWN = 11,
-}
-#[repr(u32)]
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum CRAS_NODE_POSITION {
-    NODE_POSITION_EXTERNAL = 0,
-    NODE_POSITION_INTERNAL = 1,
-    NODE_POSITION_FRONT = 2,
-    NODE_POSITION_REAR = 3,
-    NODE_POSITION_KEYBOARD = 4,
-}
-#[repr(u32)]
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum CRAS_SERVER_MESSAGE_ID {
-    CRAS_SERVER_CONNECT_STREAM = 0,
-    CRAS_SERVER_DISCONNECT_STREAM = 1,
-    CRAS_SERVER_SWITCH_STREAM_TYPE_IODEV = 2,
-    CRAS_SERVER_SET_SYSTEM_VOLUME = 3,
-    CRAS_SERVER_SET_SYSTEM_MUTE = 4,
-    CRAS_SERVER_SET_USER_MUTE = 5,
-    CRAS_SERVER_SET_SYSTEM_MUTE_LOCKED = 6,
-    CRAS_SERVER_SET_SYSTEM_CAPTURE_GAIN = 7,
-    CRAS_SERVER_SET_SYSTEM_CAPTURE_MUTE = 8,
-    CRAS_SERVER_SET_SYSTEM_CAPTURE_MUTE_LOCKED = 9,
-    CRAS_SERVER_SET_NODE_ATTR = 10,
-    CRAS_SERVER_SELECT_NODE = 11,
-    CRAS_SERVER_RELOAD_DSP = 12,
-    CRAS_SERVER_DUMP_DSP_INFO = 13,
-    CRAS_SERVER_DUMP_AUDIO_THREAD = 14,
-    CRAS_SERVER_DUMP_SNAPSHOTS = 15,
-    CRAS_SERVER_ADD_ACTIVE_NODE = 16,
-    CRAS_SERVER_RM_ACTIVE_NODE = 17,
-    CRAS_SERVER_ADD_TEST_DEV = 18,
-    CRAS_SERVER_TEST_DEV_COMMAND = 19,
-    CRAS_SERVER_SUSPEND = 20,
-    CRAS_SERVER_RESUME = 21,
-    CRAS_CONFIG_GLOBAL_REMIX = 22,
-    CRAS_SERVER_GET_HOTWORD_MODELS = 23,
-    CRAS_SERVER_SET_HOTWORD_MODEL = 24,
-    CRAS_SERVER_REGISTER_NOTIFICATION = 25,
-    CRAS_SERVER_SET_AEC_DUMP = 26,
-    CRAS_SERVER_RELOAD_AEC_CONFIG = 27,
-    CRAS_SERVER_DUMP_BT = 28,
-    CRAS_SERVER_SET_BT_WBS_ENABLED = 29,
-}
-#[repr(u32)]
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum CRAS_CLIENT_MESSAGE_ID {
-    CRAS_CLIENT_CONNECTED = 0,
-    CRAS_CLIENT_STREAM_CONNECTED = 1,
-    CRAS_CLIENT_AUDIO_DEBUG_INFO_READY = 2,
-    CRAS_CLIENT_GET_HOTWORD_MODELS_READY = 3,
-    CRAS_CLIENT_OUTPUT_VOLUME_CHANGED = 4,
-    CRAS_CLIENT_OUTPUT_MUTE_CHANGED = 5,
-    CRAS_CLIENT_CAPTURE_GAIN_CHANGED = 6,
-    CRAS_CLIENT_CAPTURE_MUTE_CHANGED = 7,
-    CRAS_CLIENT_NODES_CHANGED = 8,
-    CRAS_CLIENT_ACTIVE_NODE_CHANGED = 9,
-    CRAS_CLIENT_OUTPUT_NODE_VOLUME_CHANGED = 10,
-    CRAS_CLIENT_NODE_LEFT_RIGHT_SWAPPED_CHANGED = 11,
-    CRAS_CLIENT_INPUT_NODE_GAIN_CHANGED = 12,
-    CRAS_CLIENT_NUM_ACTIVE_STREAMS_CHANGED = 13,
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_server_message {
-    pub length: u32,
-    pub id: CRAS_SERVER_MESSAGE_ID,
-}
-#[test]
-fn bindgen_test_layout_cras_server_message() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_server_message>(),
-        8usize,
-        concat!("Size of: ", stringify!(cras_server_message))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_server_message>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_server_message))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_server_message>())).length as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_message),
-            "::",
-            stringify!(length)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_server_message>())).id as *const _ as usize },
-        4usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_server_message),
-            "::",
-            stringify!(id)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_client_message {
-    pub length: u32,
-    pub id: CRAS_CLIENT_MESSAGE_ID,
-}
-#[test]
-fn bindgen_test_layout_cras_client_message() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_client_message>(),
-        8usize,
-        concat!("Size of: ", stringify!(cras_client_message))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_client_message>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_client_message))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_client_message>())).length as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_message),
-            "::",
-            stringify!(length)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_client_message>())).id as *const _ as usize },
-        4usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_message),
-            "::",
-            stringify!(id)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_connect_message {
-    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,
-    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>(),
-        79usize,
-        concat!("Size of: ", stringify!(cras_connect_message))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_connect_message>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_connect_message))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_connect_message>())).header as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_connect_message),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_connect_message>())).proto_version as *const _ as usize
-        },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_connect_message),
-            "::",
-            stringify!(proto_version)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_connect_message>())).direction as *const _ as usize },
-        12usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_connect_message),
-            "::",
-            stringify!(direction)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_connect_message>())).stream_id as *const _ as usize },
-        16usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_connect_message),
-            "::",
-            stringify!(stream_id)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_connect_message>())).stream_type as *const _ as usize
-        },
-        20usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_connect_message),
-            "::",
-            stringify!(stream_type)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_connect_message>())).buffer_frames as *const _ as usize
-        },
-        24usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_connect_message),
-            "::",
-            stringify!(buffer_frames)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_connect_message>())).cb_threshold as *const _ as usize
-        },
-        28usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_connect_message),
-            "::",
-            stringify!(cb_threshold)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_connect_message>())).flags as *const _ as usize },
-        32usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_connect_message),
-            "::",
-            stringify!(flags)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_connect_message>())).format as *const _ as usize },
-        36usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_connect_message),
-            "::",
-            stringify!(format)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_connect_message>())).dev_idx as *const _ as usize },
-        59usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_connect_message),
-            "::",
-            stringify!(dev_idx)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_connect_message>())).effects as *const _ as usize },
-        63usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(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)]
-pub struct cras_disconnect_stream_message {
-    pub header: cras_server_message,
-    pub stream_id: cras_stream_id_t,
-}
-#[test]
-fn bindgen_test_layout_cras_disconnect_stream_message() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_disconnect_stream_message>(),
-        12usize,
-        concat!("Size of: ", stringify!(cras_disconnect_stream_message))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_disconnect_stream_message>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_disconnect_stream_message))
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_disconnect_stream_message>())).header as *const _ as usize
-        },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_disconnect_stream_message),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_disconnect_stream_message>())).stream_id as *const _
-                as usize
-        },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_disconnect_stream_message),
-            "::",
-            stringify!(stream_id)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_switch_stream_type_iodev {
-    pub header: cras_server_message,
-    pub stream_type: CRAS_STREAM_TYPE,
-    pub iodev_idx: u32,
-}
-#[test]
-fn bindgen_test_layout_cras_switch_stream_type_iodev() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_switch_stream_type_iodev>(),
-        16usize,
-        concat!("Size of: ", stringify!(cras_switch_stream_type_iodev))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_switch_stream_type_iodev>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_switch_stream_type_iodev))
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_switch_stream_type_iodev>())).header as *const _ as usize
-        },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_switch_stream_type_iodev),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_switch_stream_type_iodev>())).stream_type as *const _
-                as usize
-        },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_switch_stream_type_iodev),
-            "::",
-            stringify!(stream_type)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_switch_stream_type_iodev>())).iodev_idx as *const _ as usize
-        },
-        12usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_switch_stream_type_iodev),
-            "::",
-            stringify!(iodev_idx)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_set_system_volume {
-    pub header: cras_server_message,
-    pub volume: u32,
-}
-#[test]
-fn bindgen_test_layout_cras_set_system_volume() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_set_system_volume>(),
-        12usize,
-        concat!("Size of: ", stringify!(cras_set_system_volume))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_set_system_volume>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_set_system_volume))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_set_system_volume>())).header as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_set_system_volume),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_set_system_volume>())).volume as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_set_system_volume),
-            "::",
-            stringify!(volume)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_set_system_capture_gain {
-    pub header: cras_server_message,
-    pub gain: i32,
-}
-#[test]
-fn bindgen_test_layout_cras_set_system_capture_gain() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_set_system_capture_gain>(),
-        12usize,
-        concat!("Size of: ", stringify!(cras_set_system_capture_gain))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_set_system_capture_gain>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_set_system_capture_gain))
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_set_system_capture_gain>())).header as *const _ as usize
-        },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_set_system_capture_gain),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_set_system_capture_gain>())).gain as *const _ as usize
-        },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_set_system_capture_gain),
-            "::",
-            stringify!(gain)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_set_system_mute {
-    pub header: cras_server_message,
-    pub mute: i32,
-}
-#[test]
-fn bindgen_test_layout_cras_set_system_mute() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_set_system_mute>(),
-        12usize,
-        concat!("Size of: ", stringify!(cras_set_system_mute))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_set_system_mute>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_set_system_mute))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_set_system_mute>())).header as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_set_system_mute),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_set_system_mute>())).mute as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_set_system_mute),
-            "::",
-            stringify!(mute)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_set_node_attr {
-    pub header: cras_server_message,
-    pub node_id: cras_node_id_t,
-    pub attr: ionode_attr,
-    pub value: i32,
-}
-#[test]
-fn bindgen_test_layout_cras_set_node_attr() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_set_node_attr>(),
-        24usize,
-        concat!("Size of: ", stringify!(cras_set_node_attr))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_set_node_attr>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_set_node_attr))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_set_node_attr>())).header as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_set_node_attr),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_set_node_attr>())).node_id as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_set_node_attr),
-            "::",
-            stringify!(node_id)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_set_node_attr>())).attr as *const _ as usize },
-        16usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_set_node_attr),
-            "::",
-            stringify!(attr)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_set_node_attr>())).value as *const _ as usize },
-        20usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_set_node_attr),
-            "::",
-            stringify!(value)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_select_node {
-    pub header: cras_server_message,
-    pub direction: CRAS_STREAM_DIRECTION,
-    pub node_id: cras_node_id_t,
-}
-#[test]
-fn bindgen_test_layout_cras_select_node() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_select_node>(),
-        20usize,
-        concat!("Size of: ", stringify!(cras_select_node))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_select_node>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_select_node))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_select_node>())).header as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_select_node),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_select_node>())).direction as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_select_node),
-            "::",
-            stringify!(direction)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_select_node>())).node_id as *const _ as usize },
-        12usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_select_node),
-            "::",
-            stringify!(node_id)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_add_active_node {
-    pub header: cras_server_message,
-    pub direction: CRAS_STREAM_DIRECTION,
-    pub node_id: cras_node_id_t,
-}
-#[test]
-fn bindgen_test_layout_cras_add_active_node() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_add_active_node>(),
-        20usize,
-        concat!("Size of: ", stringify!(cras_add_active_node))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_add_active_node>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_add_active_node))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_add_active_node>())).header as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_add_active_node),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_add_active_node>())).direction as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_add_active_node),
-            "::",
-            stringify!(direction)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_add_active_node>())).node_id as *const _ as usize },
-        12usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_add_active_node),
-            "::",
-            stringify!(node_id)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_rm_active_node {
-    pub header: cras_server_message,
-    pub direction: CRAS_STREAM_DIRECTION,
-    pub node_id: cras_node_id_t,
-}
-#[test]
-fn bindgen_test_layout_cras_rm_active_node() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_rm_active_node>(),
-        20usize,
-        concat!("Size of: ", stringify!(cras_rm_active_node))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_rm_active_node>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_rm_active_node))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_rm_active_node>())).header as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_rm_active_node),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_rm_active_node>())).direction as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_rm_active_node),
-            "::",
-            stringify!(direction)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_rm_active_node>())).node_id as *const _ as usize },
-        12usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_rm_active_node),
-            "::",
-            stringify!(node_id)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_reload_dsp {
-    pub header: cras_server_message,
-}
-#[test]
-fn bindgen_test_layout_cras_reload_dsp() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_reload_dsp>(),
-        8usize,
-        concat!("Size of: ", stringify!(cras_reload_dsp))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_reload_dsp>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_reload_dsp))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_reload_dsp>())).header as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_reload_dsp),
-            "::",
-            stringify!(header)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_dump_dsp_info {
-    pub header: cras_server_message,
-}
-#[test]
-fn bindgen_test_layout_cras_dump_dsp_info() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_dump_dsp_info>(),
-        8usize,
-        concat!("Size of: ", stringify!(cras_dump_dsp_info))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_dump_dsp_info>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_dump_dsp_info))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_dump_dsp_info>())).header as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_dump_dsp_info),
-            "::",
-            stringify!(header)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_dump_audio_thread {
-    pub header: cras_server_message,
-}
-#[test]
-fn bindgen_test_layout_cras_dump_audio_thread() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_dump_audio_thread>(),
-        8usize,
-        concat!("Size of: ", stringify!(cras_dump_audio_thread))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_dump_audio_thread>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_dump_audio_thread))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_dump_audio_thread>())).header as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_dump_audio_thread),
-            "::",
-            stringify!(header)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_dump_bt {
-    pub header: cras_server_message,
-}
-#[test]
-fn bindgen_test_layout_cras_dump_bt() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_dump_bt>(),
-        8usize,
-        concat!("Size of: ", stringify!(cras_dump_bt))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_dump_bt>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_dump_bt))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_dump_bt>())).header as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_dump_bt),
-            "::",
-            stringify!(header)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_dump_snapshots {
-    pub header: cras_server_message,
-}
-#[test]
-fn bindgen_test_layout_cras_dump_snapshots() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_dump_snapshots>(),
-        8usize,
-        concat!("Size of: ", stringify!(cras_dump_snapshots))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_dump_snapshots>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_dump_snapshots))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_dump_snapshots>())).header as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_dump_snapshots),
-            "::",
-            stringify!(header)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_add_test_dev {
-    pub header: cras_server_message,
-    pub type_: TEST_IODEV_TYPE,
-}
-#[test]
-fn bindgen_test_layout_cras_add_test_dev() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_add_test_dev>(),
-        12usize,
-        concat!("Size of: ", stringify!(cras_add_test_dev))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_add_test_dev>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_add_test_dev))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_add_test_dev>())).header as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_add_test_dev),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_add_test_dev>())).type_ as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_add_test_dev),
-            "::",
-            stringify!(type_)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Copy, Clone)]
-pub struct cras_test_dev_command {
-    pub header: cras_server_message,
-    pub command: ::std::os::raw::c_uint,
-    pub iodev_idx: ::std::os::raw::c_uint,
-    pub data_len: ::std::os::raw::c_uint,
-    pub data: [u8; 224usize],
-}
-#[test]
-fn bindgen_test_layout_cras_test_dev_command() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_test_dev_command>(),
-        244usize,
-        concat!("Size of: ", stringify!(cras_test_dev_command))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_test_dev_command>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_test_dev_command))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_test_dev_command>())).header as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_test_dev_command),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_test_dev_command>())).command as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_test_dev_command),
-            "::",
-            stringify!(command)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_test_dev_command>())).iodev_idx as *const _ as usize },
-        12usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_test_dev_command),
-            "::",
-            stringify!(iodev_idx)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_test_dev_command>())).data_len as *const _ as usize },
-        16usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_test_dev_command),
-            "::",
-            stringify!(data_len)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_test_dev_command>())).data as *const _ as usize },
-        20usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_test_dev_command),
-            "::",
-            stringify!(data)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_config_global_remix {
-    pub header: cras_server_message,
-    pub num_channels: ::std::os::raw::c_uint,
-    pub coefficient: [f32; 32usize],
-}
-#[test]
-fn bindgen_test_layout_cras_config_global_remix() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_config_global_remix>(),
-        140usize,
-        concat!("Size of: ", stringify!(cras_config_global_remix))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_config_global_remix>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_config_global_remix))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_config_global_remix>())).header as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_config_global_remix),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_config_global_remix>())).num_channels as *const _ as usize
-        },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_config_global_remix),
-            "::",
-            stringify!(num_channels)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_config_global_remix>())).coefficient as *const _ as usize
-        },
-        12usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_config_global_remix),
-            "::",
-            stringify!(coefficient)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_get_hotword_models {
-    pub header: cras_server_message,
-    pub node_id: cras_node_id_t,
-}
-#[test]
-fn bindgen_test_layout_cras_get_hotword_models() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_get_hotword_models>(),
-        16usize,
-        concat!("Size of: ", stringify!(cras_get_hotword_models))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_get_hotword_models>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_get_hotword_models))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_get_hotword_models>())).header as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_get_hotword_models),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_get_hotword_models>())).node_id as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_get_hotword_models),
-            "::",
-            stringify!(node_id)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-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; 12usize],
-}
-#[test]
-fn bindgen_test_layout_cras_set_hotword_model() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_set_hotword_model>(),
-        28usize,
-        concat!("Size of: ", stringify!(cras_set_hotword_model))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_set_hotword_model>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_set_hotword_model))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_set_hotword_model>())).header as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_set_hotword_model),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_set_hotword_model>())).node_id as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_set_hotword_model),
-            "::",
-            stringify!(node_id)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_set_hotword_model>())).model_name as *const _ as usize
-        },
-        16usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_set_hotword_model),
-            "::",
-            stringify!(model_name)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_set_aec_dump {
-    pub header: cras_server_message,
-    pub stream_id: cras_stream_id_t,
-    pub start: ::std::os::raw::c_uint,
-}
-#[test]
-fn bindgen_test_layout_cras_set_aec_dump() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_set_aec_dump>(),
-        16usize,
-        concat!("Size of: ", stringify!(cras_set_aec_dump))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_set_aec_dump>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_set_aec_dump))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_set_aec_dump>())).header as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_set_aec_dump),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_set_aec_dump>())).stream_id as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_set_aec_dump),
-            "::",
-            stringify!(stream_id)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_set_aec_dump>())).start as *const _ as usize },
-        12usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_set_aec_dump),
-            "::",
-            stringify!(start)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_reload_aec_config {
-    pub header: cras_server_message,
-}
-#[test]
-fn bindgen_test_layout_cras_reload_aec_config() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_reload_aec_config>(),
-        8usize,
-        concat!("Size of: ", stringify!(cras_reload_aec_config))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_reload_aec_config>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_reload_aec_config))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_reload_aec_config>())).header as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_reload_aec_config),
-            "::",
-            stringify!(header)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_set_bt_wbs_enabled {
-    pub header: cras_server_message,
-    pub enabled: ::std::os::raw::c_uint,
-}
-#[test]
-fn bindgen_test_layout_cras_set_bt_wbs_enabled() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_set_bt_wbs_enabled>(),
-        12usize,
-        concat!("Size of: ", stringify!(cras_set_bt_wbs_enabled))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_set_bt_wbs_enabled>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_set_bt_wbs_enabled))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_set_bt_wbs_enabled>())).header as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_set_bt_wbs_enabled),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_set_bt_wbs_enabled>())).enabled as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_set_bt_wbs_enabled),
-            "::",
-            stringify!(enabled)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_register_notification {
-    pub header: cras_server_message,
-    pub msg_id: u32,
-    pub do_register: ::std::os::raw::c_int,
-}
-#[test]
-fn bindgen_test_layout_cras_register_notification() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_register_notification>(),
-        16usize,
-        concat!("Size of: ", stringify!(cras_register_notification))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_register_notification>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_register_notification))
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_register_notification>())).header as *const _ as usize
-        },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_register_notification),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_register_notification>())).msg_id as *const _ as usize
-        },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_register_notification),
-            "::",
-            stringify!(msg_id)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_register_notification>())).do_register as *const _ as usize
-        },
-        12usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_register_notification),
-            "::",
-            stringify!(do_register)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_client_connected {
-    pub header: cras_client_message,
-    pub client_id: u32,
-}
-#[test]
-fn bindgen_test_layout_cras_client_connected() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_client_connected>(),
-        12usize,
-        concat!("Size of: ", stringify!(cras_client_connected))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_client_connected>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_client_connected))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_client_connected>())).header as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_connected),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_client_connected>())).client_id as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_connected),
-            "::",
-            stringify!(client_id)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_client_stream_connected {
-    pub header: cras_client_message,
-    pub err: i32,
-    pub stream_id: cras_stream_id_t,
-    pub format: cras_audio_format_packed,
-    pub samples_shm_size: u32,
-    pub effects: u64,
-}
-#[test]
-fn bindgen_test_layout_cras_client_stream_connected() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_client_stream_connected>(),
-        51usize,
-        concat!("Size of: ", stringify!(cras_client_stream_connected))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_client_stream_connected>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_client_stream_connected))
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_client_stream_connected>())).header as *const _ as usize
-        },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_stream_connected),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_client_stream_connected>())).err as *const _ as usize
-        },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_stream_connected),
-            "::",
-            stringify!(err)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_client_stream_connected>())).stream_id as *const _ as usize
-        },
-        12usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_stream_connected),
-            "::",
-            stringify!(stream_id)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_client_stream_connected>())).format as *const _ as usize
-        },
-        16usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_stream_connected),
-            "::",
-            stringify!(format)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_client_stream_connected>())).samples_shm_size as *const _
-                as usize
-        },
-        39usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_stream_connected),
-            "::",
-            stringify!(samples_shm_size)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_client_stream_connected>())).effects as *const _ as usize
-        },
-        43usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_stream_connected),
-            "::",
-            stringify!(effects)
-        )
-    );
-}
-#[repr(C)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_client_audio_debug_info_ready {
-    pub header: cras_client_message,
-}
-#[test]
-fn bindgen_test_layout_cras_client_audio_debug_info_ready() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_client_audio_debug_info_ready>(),
-        8usize,
-        concat!("Size of: ", stringify!(cras_client_audio_debug_info_ready))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_client_audio_debug_info_ready>(),
-        1usize,
-        concat!(
-            "Alignment of ",
-            stringify!(cras_client_audio_debug_info_ready)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_client_audio_debug_info_ready>())).header as *const _
-                as usize
-        },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_audio_debug_info_ready),
-            "::",
-            stringify!(header)
-        )
-    );
-}
-#[repr(C)]
-#[derive(Copy, Clone)]
-pub struct cras_client_get_hotword_models_ready {
-    pub header: cras_client_message,
-    pub hotword_models_size: i32,
-    pub hotword_models: [u8; 244usize],
-}
-#[test]
-fn bindgen_test_layout_cras_client_get_hotword_models_ready() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_client_get_hotword_models_ready>(),
-        256usize,
-        concat!(
-            "Size of: ",
-            stringify!(cras_client_get_hotword_models_ready)
-        )
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_client_get_hotword_models_ready>(),
-        4usize,
-        concat!(
-            "Alignment of ",
-            stringify!(cras_client_get_hotword_models_ready)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_client_get_hotword_models_ready>())).header as *const _
-                as usize
-        },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_get_hotword_models_ready),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_client_get_hotword_models_ready>())).hotword_models_size
-                as *const _ as usize
-        },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_get_hotword_models_ready),
-            "::",
-            stringify!(hotword_models_size)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_client_get_hotword_models_ready>())).hotword_models
-                as *const _ as usize
-        },
-        12usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_get_hotword_models_ready),
-            "::",
-            stringify!(hotword_models)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_client_volume_changed {
-    pub header: cras_client_message,
-    pub volume: i32,
-}
-#[test]
-fn bindgen_test_layout_cras_client_volume_changed() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_client_volume_changed>(),
-        12usize,
-        concat!("Size of: ", stringify!(cras_client_volume_changed))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_client_volume_changed>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_client_volume_changed))
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_client_volume_changed>())).header as *const _ as usize
-        },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_volume_changed),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_client_volume_changed>())).volume as *const _ as usize
-        },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_volume_changed),
-            "::",
-            stringify!(volume)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_client_mute_changed {
-    pub header: cras_client_message,
-    pub muted: i32,
-    pub user_muted: i32,
-    pub mute_locked: i32,
-}
-#[test]
-fn bindgen_test_layout_cras_client_mute_changed() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_client_mute_changed>(),
-        20usize,
-        concat!("Size of: ", stringify!(cras_client_mute_changed))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_client_mute_changed>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_client_mute_changed))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_client_mute_changed>())).header as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_mute_changed),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_client_mute_changed>())).muted as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_mute_changed),
-            "::",
-            stringify!(muted)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_client_mute_changed>())).user_muted as *const _ as usize
-        },
-        12usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_mute_changed),
-            "::",
-            stringify!(user_muted)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_client_mute_changed>())).mute_locked as *const _ as usize
-        },
-        16usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_mute_changed),
-            "::",
-            stringify!(mute_locked)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_client_nodes_changed {
-    pub header: cras_client_message,
-}
-#[test]
-fn bindgen_test_layout_cras_client_nodes_changed() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_client_nodes_changed>(),
-        8usize,
-        concat!("Size of: ", stringify!(cras_client_nodes_changed))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_client_nodes_changed>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_client_nodes_changed))
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_client_nodes_changed>())).header as *const _ as usize
-        },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_nodes_changed),
-            "::",
-            stringify!(header)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_client_active_node_changed {
-    pub header: cras_client_message,
-    pub direction: u32,
-    pub node_id: cras_node_id_t,
-}
-#[test]
-fn bindgen_test_layout_cras_client_active_node_changed() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_client_active_node_changed>(),
-        20usize,
-        concat!("Size of: ", stringify!(cras_client_active_node_changed))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_client_active_node_changed>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_client_active_node_changed))
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_client_active_node_changed>())).header as *const _ as usize
-        },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_active_node_changed),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_client_active_node_changed>())).direction as *const _
-                as usize
-        },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_active_node_changed),
-            "::",
-            stringify!(direction)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_client_active_node_changed>())).node_id as *const _ as usize
-        },
-        12usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_active_node_changed),
-            "::",
-            stringify!(node_id)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_client_node_value_changed {
-    pub header: cras_client_message,
-    pub node_id: cras_node_id_t,
-    pub value: i32,
-}
-#[test]
-fn bindgen_test_layout_cras_client_node_value_changed() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_client_node_value_changed>(),
-        20usize,
-        concat!("Size of: ", stringify!(cras_client_node_value_changed))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_client_node_value_changed>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_client_node_value_changed))
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_client_node_value_changed>())).header as *const _ as usize
-        },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_node_value_changed),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_client_node_value_changed>())).node_id as *const _ as usize
-        },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_node_value_changed),
-            "::",
-            stringify!(node_id)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_client_node_value_changed>())).value as *const _ as usize
-        },
-        16usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_node_value_changed),
-            "::",
-            stringify!(value)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_client_num_active_streams_changed {
-    pub header: cras_client_message,
-    pub direction: u32,
-    pub num_active_streams: u32,
-}
-#[test]
-fn bindgen_test_layout_cras_client_num_active_streams_changed() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_client_num_active_streams_changed>(),
-        16usize,
-        concat!(
-            "Size of: ",
-            stringify!(cras_client_num_active_streams_changed)
-        )
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_client_num_active_streams_changed>(),
-        1usize,
-        concat!(
-            "Alignment of ",
-            stringify!(cras_client_num_active_streams_changed)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_client_num_active_streams_changed>())).header as *const _
-                as usize
-        },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_num_active_streams_changed),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_client_num_active_streams_changed>())).direction as *const _
-                as usize
-        },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_num_active_streams_changed),
-            "::",
-            stringify!(direction)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_client_num_active_streams_changed>())).num_active_streams
-                as *const _ as usize
-        },
-        12usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_client_num_active_streams_changed),
-            "::",
-            stringify!(num_active_streams)
-        )
-    );
-}
-#[repr(u32)]
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum CRAS_AUDIO_MESSAGE_ID {
-    AUDIO_MESSAGE_REQUEST_DATA = 0,
-    AUDIO_MESSAGE_DATA_READY = 1,
-    AUDIO_MESSAGE_DATA_CAPTURED = 2,
-    NUM_AUDIO_MESSAGES = 3,
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct audio_message {
-    pub id: CRAS_AUDIO_MESSAGE_ID,
-    pub error: i32,
-    pub frames: u32,
-}
-#[test]
-fn bindgen_test_layout_audio_message() {
-    assert_eq!(
-        ::std::mem::size_of::<audio_message>(),
-        12usize,
-        concat!("Size of: ", stringify!(audio_message))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<audio_message>(),
-        1usize,
-        concat!("Alignment of ", stringify!(audio_message))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<audio_message>())).id as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_message),
-            "::",
-            stringify!(id)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<audio_message>())).error as *const _ as usize },
-        4usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_message),
-            "::",
-            stringify!(error)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<audio_message>())).frames as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(audio_message),
-            "::",
-            stringify!(frames)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_audio_shm_config {
-    pub used_size: u32,
-    pub frame_bytes: u32,
-}
-#[test]
-fn bindgen_test_layout_cras_audio_shm_config() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_audio_shm_config>(),
-        8usize,
-        concat!("Size of: ", stringify!(cras_audio_shm_config))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_audio_shm_config>(),
-        1usize,
-        concat!("Alignment of ", stringify!(cras_audio_shm_config))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_audio_shm_config>())).used_size as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_audio_shm_config),
-            "::",
-            stringify!(used_size)
-        )
-    );
-    assert_eq!(
-        unsafe {
-            &(*(::std::ptr::null::<cras_audio_shm_config>())).frame_bytes as *const _ as usize
-        },
-        4usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_audio_shm_config),
-            "::",
-            stringify!(frame_bytes)
-        )
-    );
-}
-#[repr(C, packed)]
-#[derive(Debug, Copy, Clone)]
-pub struct cras_audio_shm_header {
-    pub config: cras_audio_shm_config,
-    pub read_buf_idx: u32,
-    pub write_buf_idx: u32,
-    pub read_offset: [u32; 2usize],
-    pub write_offset: [u32; 2usize],
-    pub write_in_progress: [i32; 2usize],
-    pub volume_scaler: f32,
-    pub mute: i32,
-    pub callback_pending: i32,
-    pub num_overruns: u32,
-    pub ts: cras_timespec,
-    pub buffer_offset: [u32; 2usize],
-}
-#[test]
-fn bindgen_test_layout_cras_audio_shm_header() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_audio_shm_header>(),
-        80usize,
-        concat!("Size of: ", stringify!(cras_audio_shm_header))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<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)]
-pub struct cras_shm_info {
-    pub fd: ::std::os::raw::c_int,
-    pub name: [::std::os::raw::c_char; 255usize],
-    pub length: usize,
-}
-#[test]
-fn bindgen_test_layout_cras_shm_info() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_shm_info>(),
-        272usize,
-        concat!("Size of: ", stringify!(cras_shm_info))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_shm_info>(),
-        8usize,
-        concat!("Alignment of ", stringify!(cras_shm_info))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_shm_info>())).fd as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_shm_info),
-            "::",
-            stringify!(fd)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_shm_info>())).name as *const _ as usize },
-        4usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_shm_info),
-            "::",
-            stringify!(name)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_shm_info>())).length as *const _ as usize },
-        264usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_shm_info),
-            "::",
-            stringify!(length)
-        )
-    );
-}
-#[repr(C)]
-#[derive(Copy, Clone)]
-pub struct cras_audio_shm {
-    pub config: cras_audio_shm_config,
-    pub header_info: cras_shm_info,
-    pub header: *mut cras_audio_shm_header,
-    pub samples_info: cras_shm_info,
-    pub samples: *mut u8,
-}
-#[test]
-fn bindgen_test_layout_cras_audio_shm() {
-    assert_eq!(
-        ::std::mem::size_of::<cras_audio_shm>(),
-        568usize,
-        concat!("Size of: ", stringify!(cras_audio_shm))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<cras_audio_shm>(),
-        8usize,
-        concat!("Alignment of ", stringify!(cras_audio_shm))
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_audio_shm>())).config as *const _ as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_audio_shm),
-            "::",
-            stringify!(config)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_audio_shm>())).header_info as *const _ as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_audio_shm),
-            "::",
-            stringify!(header_info)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_audio_shm>())).header as *const _ as usize },
-        280usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_audio_shm),
-            "::",
-            stringify!(header)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_audio_shm>())).samples_info as *const _ as usize },
-        288usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_audio_shm),
-            "::",
-            stringify!(samples_info)
-        )
-    );
-    assert_eq!(
-        unsafe { &(*(::std::ptr::null::<cras_audio_shm>())).samples as *const _ as usize },
-        560usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(cras_audio_shm),
-            "::",
-            stringify!(samples)
-        )
-    );
-}
diff --git a/cras/client/cras-sys/src/lib.rs b/cras/client/cras-sys/src/lib.rs
deleted file mode 100644
index 4056162..0000000
--- a/cras/client/cras-sys/src/lib.rs
+++ /dev/null
@@ -1,58 +0,0 @@
-// 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.
-extern crate data_model;
-
-#[allow(dead_code)]
-#[allow(non_upper_case_globals)]
-#[allow(non_camel_case_types)]
-#[allow(non_snake_case)]
-pub mod gen;
-use gen::{
-    _snd_pcm_format, audio_message, cras_audio_format_packed, CRAS_AUDIO_MESSAGE_ID, CRAS_CHANNEL,
-};
-
-unsafe impl data_model::DataInit for gen::audio_message {}
-unsafe impl data_model::DataInit for gen::cras_client_connected {}
-unsafe impl data_model::DataInit for gen::cras_client_stream_connected {}
-unsafe impl data_model::DataInit for gen::cras_connect_message {}
-unsafe impl data_model::DataInit for gen::cras_disconnect_stream_message {}
-unsafe impl data_model::DataInit for gen::cras_server_state {}
-
-impl cras_audio_format_packed {
-    /// Initializes `cras_audio_format_packed` from input parameters.
-    ///
-    /// # Arguments
-    /// * `format` - Format in used.
-    /// * `rate` - Rate in used.
-    /// * `num_channels` - Number of channels in used.
-    ///
-    /// # Returns
-    /// Structure `cras_audio_format_packed`
-    pub fn new(format: _snd_pcm_format, rate: usize, num_channels: usize) -> Self {
-        let mut audio_format = Self {
-            format: format as i32,
-            frame_rate: rate as u32,
-            num_channels: num_channels as u32,
-            channel_layout: [-1; CRAS_CHANNEL::CRAS_CH_MAX as usize],
-        };
-        for i in 0..CRAS_CHANNEL::CRAS_CH_MAX as usize {
-            if i < num_channels {
-                audio_format.channel_layout[i] = i as i8;
-            } else {
-                break;
-            }
-        }
-        audio_format
-    }
-}
-
-impl Default for audio_message {
-    fn default() -> Self {
-        Self {
-            error: 0,
-            frames: 0,
-            id: CRAS_AUDIO_MESSAGE_ID::NUM_AUDIO_MESSAGES,
-        }
-    }
-}
diff --git a/cras/client/cras_tests/.gitignore b/cras/client/cras_tests/.gitignore
deleted file mode 100644
index 302b31d..0000000
--- a/cras/client/cras_tests/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-target/
-.*.rustfmt
diff --git a/cras/client/cras_tests/.rustfmt.toml b/cras/client/cras_tests/.rustfmt.toml
deleted file mode 100644
index a2db301..0000000
--- a/cras/client/cras_tests/.rustfmt.toml
+++ /dev/null
@@ -1,2 +0,0 @@
-use_field_init_shorthand = true
-use_try_shorthand = true
diff --git a/cras/client/cras_tests/Cargo.toml b/cras/client/cras_tests/Cargo.toml
deleted file mode 100644
index 94453dd..0000000
--- a/cras/client/cras_tests/Cargo.toml
+++ /dev/null
@@ -1,11 +0,0 @@
-[package]
-name = "cras_tests"
-version = "0.1.0"
-authors = ["The Chromium OS Authors"]
-edition = "2018"
-
-[dependencies]
-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
deleted file mode 100644
index d71aac5..0000000
--- a/cras/client/cras_tests/src/audio_options.rs
+++ /dev/null
@@ -1,194 +0,0 @@
-// 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
deleted file mode 100644
index 9709404..0000000
--- a/cras/client/cras_tests/src/main.rs
+++ /dev/null
@@ -1,131 +0,0 @@
-// 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::{self, BufRead, BufReader, Write};
-use std::thread::spawn;
-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;
-
-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 channel_string(num_channels: usize) -> String {
-    match num_channels {
-        1 => "Mono".to_string(),
-        2 => "Stereo".to_string(),
-        _ => format!("{} Channels", num_channels),
-    }
-}
-
-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 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 || {
-        set_priority_to_realtime();
-        loop {
-            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
-            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)
-                .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");
-    // Stream and client should gracefully be closed out of this scope
-
-    Ok(())
-}
-
-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,
-        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) => {
-                let written = io::copy(&mut buf, &mut file)?;
-                written
-            }
-        };
-    }
-}
-
-fn main() -> Result<()> {
-    let args: Vec<String> = std::env::args().collect();
-    let opts = match AudioOptions::parse_from_args(&args)? {
-        None => return Ok(()),
-        Some(v) => v,
-    };
-
-    match opts.subcommand {
-        Subcommand::Capture => capture(opts)?,
-        Subcommand::Playback => playback(opts)?,
-    };
-    Ok(())
-}
diff --git a/cras/client/libcras/.gitignore b/cras/client/libcras/.gitignore
deleted file mode 100644
index 41cebfd..0000000
--- a/cras/client/libcras/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-target/
-.rustfmt.toml
-.*.rustfmt.toml
diff --git a/cras/client/libcras/.rustfmt.toml b/cras/client/libcras/.rustfmt.toml
deleted file mode 100644
index a2db301..0000000
--- a/cras/client/libcras/.rustfmt.toml
+++ /dev/null
@@ -1,2 +0,0 @@
-use_field_init_shorthand = true
-use_try_shorthand = true
diff --git a/cras/client/libcras/Android.bp b/cras/client/libcras/Android.bp
deleted file mode 100644
index 3c0b3ed..0000000
--- a/cras/client/libcras/Android.bp
+++ /dev/null
@@ -1,14 +0,0 @@
-rust_library_host_rlib {
-    name: "liblibcras",
-    deny_warnings: false,
-    crate_name: "libcras",
-    edition: "2018",
-    srcs: ["src/libcras.rs"],
-    rlibs: [
-        "liblibc",
-        "libaudio_streams",
-        "libcras_sys",
-        "libdata_model",
-        "libsys_util",
-    ],
-}
diff --git a/cras/client/libcras/Cargo.toml b/cras/client/libcras/Cargo.toml
deleted file mode 100644
index cc2a3e1..0000000
--- a/cras/client/libcras/Cargo.toml
+++ /dev/null
@@ -1,15 +0,0 @@
-[package]
-name = "libcras"
-version = "0.1.0"
-authors = ["The Chromium OS Authors"]
-edition = "2018"
-
-[lib]
-path = "src/libcras.rs"
-
-[dependencies]
-audio_streams = { path = "../../../audio_streams" } # provided by ebuild
-libc = "*"
-cras-sys = { path = "../cras-sys" } # provided by ebuild
-data_model = { path = "../../../../../platform/crosvm/data_model" } # provided by ebuild
-sys_util = { path = "../../../../../platform/crosvm/sys_util" } # provided by ebuild
diff --git a/cras/client/libcras/src/audio_socket.rs b/cras/client/libcras/src/audio_socket.rs
deleted file mode 100644
index ac56144..0000000
--- a/cras/client/libcras/src/audio_socket.rs
+++ /dev/null
@@ -1,316 +0,0 @@
-// 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::io;
-use std::io::{Read, Write};
-use std::mem;
-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;
-use sys_util::{PollContext, PollToken};
-
-/// A structure for interacting with the CRAS server audio thread through a `UnixStream::pair`.
-pub struct AudioSocket {
-    socket: UnixStream,
-}
-
-/// Audio message results which are exchanged by `CrasStream` and CRAS audio server.
-/// through an audio socket.
-#[allow(dead_code)]
-#[derive(Debug)]
-pub enum AudioMessage {
-    /// * `id` - Audio message id, which is a `enum CRAS_AUDIO_MESSAGE_ID`.
-    /// * `frames` - A `u32` indicating the read or written frame count.
-    Success {
-        id: CRAS_AUDIO_MESSAGE_ID,
-        frames: u32,
-    },
-    /// * `error` - Error code when a error occurs.
-    Error(i32),
-}
-
-/// Converts AudioMessage to raw audio_message for CRAS audio server.
-impl Into<audio_message> for AudioMessage {
-    fn into(self) -> audio_message {
-        match self {
-            AudioMessage::Success { id, frames } => audio_message {
-                id,
-                error: 0,
-                frames,
-            },
-            AudioMessage::Error(error) => audio_message {
-                id: CRAS_AUDIO_MESSAGE_ID::AUDIO_MESSAGE_REQUEST_DATA,
-                error,
-                frames: 0,
-            },
-        }
-    }
-}
-
-/// Converts AudioMessage from raw audio_message from CRAS audio server.
-impl From<audio_message> for AudioMessage {
-    fn from(message: audio_message) -> Self {
-        match message.error {
-            0 => AudioMessage::Success {
-                id: message.id as CRAS_AUDIO_MESSAGE_ID,
-                frames: message.frames,
-            },
-            error => AudioMessage::Error(error),
-        }
-    }
-}
-
-impl AudioSocket {
-    /// Creates `AudioSocket` from a `UnixStream`.
-    ///
-    /// # Arguments
-    /// `socket` - A `UnixStream`.
-    pub fn new(socket: UnixStream) -> Self {
-        AudioSocket { socket }
-    }
-
-    fn read_from_socket<T>(&mut self) -> io::Result<T>
-    where
-        T: Sized + DataInit + Default,
-    {
-        let mut message: T = Default::default();
-        let rc = self.socket.read(message.as_mut_slice())?;
-        if rc == mem::size_of::<T>() {
-            Ok(message)
-        } else {
-            Err(io::Error::new(io::ErrorKind::Other, "Read truncated data."))
-        }
-    }
-
-    /// Blocks reading an `audio message`.
-    ///
-    /// # Returns
-    /// `AudioMessage` - AudioMessage enum.
-    ///
-    /// # 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,
-        }
-        let poll_ctx: PollContext<Token> =
-            match PollContext::new().and_then(|pc| pc.add(self, Token::AudioMsg).and(Ok(pc))) {
-                Ok(pc) => pc,
-                Err(e) => {
-                    return Err(io::Error::new(
-                        io::ErrorKind::Other,
-                        format!("Failed to create PollContext: {}", e),
-                    ));
-                }
-            };
-        let events = {
-            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(
-                        io::ErrorKind::Other,
-                        format!("Failed to poll: {:?}", e),
-                    ));
-                }
-            }
-        };
-
-        // Check the first readable message
-        let tokens: Vec<Token> = events.iter_readable().map(|e| e.token()).collect();
-        match tokens.get(0) {
-            None => Ok(None),
-            Some(&Token::AudioMsg) => {
-                let raw_msg: audio_message = self.read_from_socket()?;
-                Ok(Some(AudioMessage::from(raw_msg)))
-            }
-        }
-    }
-
-    /// Sends raw audio message with given AudioMessage enum.
-    ///
-    /// # Arguments
-    /// * `msg` - enum AudioMessage, which could be `Success` with message id
-    /// and frames or `Error` with error code.
-    ///
-    /// # Errors
-    /// Returns error if `libc::write` fails.
-    fn send_audio_message(&mut self, msg: AudioMessage) -> io::Result<()> {
-        let msg: audio_message = msg.into();
-        let rc = self.socket.write(msg.as_slice())?;
-        if rc < mem::size_of::<audio_message>() {
-            Err(io::Error::new(io::ErrorKind::Other, "Sent truncated data."))
-        } else {
-            Ok(())
-        }
-    }
-
-    /// Sends the data ready message with written frame count.
-    ///
-    /// # Arguments
-    /// * `frames` - An `u32` indicating the written frame count.
-    pub fn data_ready(&mut self, frames: u32) -> io::Result<()> {
-        self.send_audio_message(AudioMessage::Success {
-            id: CRAS_AUDIO_MESSAGE_ID::AUDIO_MESSAGE_DATA_READY,
-            frames,
-        })
-    }
-
-    /// Sends the capture ready message with read frame count.
-    ///
-    /// # Arguments
-    ///
-    /// * `frames` - An `u32` indicating the number of read frames.
-    pub fn capture_ready(&mut self, frames: u32) -> io::Result<()> {
-        self.send_audio_message(AudioMessage::Success {
-            id: CRAS_AUDIO_MESSAGE_ID::AUDIO_MESSAGE_DATA_CAPTURED,
-            frames,
-        })
-    }
-}
-
-impl AsRawFd for AudioSocket {
-    fn as_raw_fd(&self) -> RawFd {
-        self.socket.as_raw_fd()
-    }
-}
-
-#[cfg(test)]
-mod tests {
-    use super::*;
-
-    // PartialEq for comparing AudioMessage in tests
-    impl PartialEq for AudioMessage {
-        fn eq(&self, other: &Self) -> bool {
-            match (self, other) {
-                (
-                    AudioMessage::Success { id, frames },
-                    AudioMessage::Success {
-                        id: other_id,
-                        frames: other_frames,
-                    },
-                ) => id == other_id && frames == other_frames,
-                (AudioMessage::Error(err), AudioMessage::Error(other_err)) => err == other_err,
-                _ => false,
-            }
-        }
-    }
-
-    fn init_audio_socket_pair() -> (AudioSocket, AudioSocket) {
-        let (sock1, sock2) = UnixStream::pair().unwrap();
-        let sender = AudioSocket::new(sock1);
-        let receiver = AudioSocket::new(sock2);
-        (sender, receiver)
-    }
-
-    #[test]
-    fn audio_socket_send_and_recv_audio_message() {
-        let (mut sender, mut receiver) = init_audio_socket_pair();
-        let message_succ = AudioMessage::Success {
-            id: CRAS_AUDIO_MESSAGE_ID::AUDIO_MESSAGE_REQUEST_DATA,
-            frames: 0,
-        };
-        sender.send_audio_message(message_succ).unwrap();
-        let res = receiver.read_audio_message().unwrap();
-        assert_eq!(
-            res,
-            AudioMessage::Success {
-                id: CRAS_AUDIO_MESSAGE_ID::AUDIO_MESSAGE_REQUEST_DATA,
-                frames: 0
-            }
-        );
-
-        let message_err = AudioMessage::Error(123);
-        sender.send_audio_message(message_err).unwrap();
-        let res = receiver.read_audio_message().unwrap();
-        assert_eq!(res, AudioMessage::Error(123));
-    }
-
-    #[test]
-    fn audio_socket_data_ready_send_and_recv() {
-        let (sock1, sock2) = UnixStream::pair().unwrap();
-        let mut audio_socket_send = AudioSocket::new(sock1);
-        let mut audio_socket_recv = AudioSocket::new(sock2);
-        audio_socket_send.data_ready(256).unwrap();
-
-        // Test receiving by using raw audio_message since CRAS audio server use this.
-        let audio_msg: audio_message = audio_socket_recv.read_from_socket().unwrap();
-        let ref_audio_msg = audio_message {
-            id: CRAS_AUDIO_MESSAGE_ID::AUDIO_MESSAGE_DATA_READY,
-            error: 0,
-            frames: 256,
-        };
-        // Use brace to copy unaligned data locally
-        assert_eq!({ audio_msg.id }, { ref_audio_msg.id });
-        assert_eq!({ audio_msg.error }, { ref_audio_msg.error });
-        assert_eq!({ audio_msg.frames }, { ref_audio_msg.frames });
-    }
-
-    #[test]
-    fn audio_socket_capture_ready() {
-        let (sock1, sock2) = UnixStream::pair().unwrap();
-        let mut audio_socket_send = AudioSocket::new(sock1);
-        let mut audio_socket_recv = AudioSocket::new(sock2);
-        audio_socket_send
-            .capture_ready(256)
-            .expect("Failed to send capture ready message.");
-
-        // Test receiving by using raw audio_message since CRAS audio server use this.
-        let audio_msg: audio_message = audio_socket_recv
-            .read_from_socket()
-            .expect("Failed to read audio message from AudioSocket.");
-        let ref_audio_msg = audio_message {
-            id: CRAS_AUDIO_MESSAGE_ID::AUDIO_MESSAGE_DATA_CAPTURED,
-            error: 0,
-            frames: 256,
-        };
-        // Use brace to copy unaligned data locally
-        assert_eq!({ audio_msg.id }, { ref_audio_msg.id });
-        assert_eq!({ audio_msg.error }, { ref_audio_msg.error });
-        assert_eq!({ audio_msg.frames }, { ref_audio_msg.frames });
-    }
-
-    #[test]
-    fn audio_socket_send_when_broken_pipe() {
-        let sock1 = {
-            let (sock1, _) = UnixStream::pair().unwrap();
-            sock1
-        };
-        let mut audio_socket = AudioSocket::new(sock1);
-        let res = audio_socket.data_ready(256);
-        //Broken pipe
-        assert_eq!(
-            res.expect_err("Result should be an error.").kind(),
-            io::Error::from_raw_os_error(32).kind(),
-            "Error should be broken pipe.",
-        );
-    }
-}
diff --git a/cras/client/libcras/src/cras_client_message.rs b/cras/client/libcras/src/cras_client_message.rs
deleted file mode 100644
index 0921c5f..0000000
--- a/cras/client/libcras/src/cras_client_message.rs
+++ /dev/null
@@ -1,201 +0,0 @@
-// 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::{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,
-    CRAS_CLIENT_MAX_MSG_SIZE,
-    CRAS_CLIENT_MESSAGE_ID::{self, *},
-};
-use data_model::DataInit;
-use sys_util::ScmSocket;
-
-use crate::cras_server_socket::CrasServerSocket;
-use crate::cras_shm::*;
-use crate::cras_stream;
-
-#[derive(Debug)]
-enum ErrorType {
-    IoError(io::Error),
-    SysUtilError(sys_util::Error),
-    CrasStreamError(cras_stream::Error),
-    ArrayTryFromSliceError(TryFromSliceError),
-    InvalidSize,
-    MessageTypeError,
-    MessageNumFdError,
-    MessageTruncated,
-    MessageIdError,
-    MessageFromSliceError,
-}
-
-#[derive(Debug)]
-pub struct Error {
-    error_type: ErrorType,
-}
-
-impl Error {
-    fn new(error_type: ErrorType) -> Error {
-        Error { error_type }
-    }
-}
-
-impl error::Error for Error {}
-
-impl fmt::Display for Error {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        match self.error_type {
-            ErrorType::IoError(ref err) => err.fmt(f),
-            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"),
-            ErrorType::MessageFromSliceError => write!(f, "Message from slice error"),
-            ErrorType::InvalidSize => write!(f, "Invalid data size"),
-        }
-    }
-}
-
-type Result<T> = std::result::Result<T, Error>;
-
-impl From<io::Error> for Error {
-    fn from(io_err: io::Error) -> Self {
-        Self::new(ErrorType::IoError(io_err))
-    }
-}
-
-impl From<sys_util::Error> for Error {
-    fn from(sys_util_err: sys_util::Error) -> Self {
-        Self::new(ErrorType::SysUtilError(sys_util_err))
-    }
-}
-
-impl From<cras_stream::Error> for Error {
-    fn from(err: cras_stream::Error) -> Self {
-        Self::new(ErrorType::CrasStreamError(err))
-    }
-}
-
-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
-    Connected(u32, CrasServerStateShmFd),
-    /// stream_id, header_fd, samples_fd
-    StreamConnected(u32, CrasAudioShmHeaderFd, CrasShmFd),
-}
-
-impl ServerResult {
-    /// Reads and handles one server message and converts `CrasClientMessage` into `ServerResult`
-    /// with error handling.
-    ///
-    /// # Arguments
-    /// * `server_socket`: A reference to `CrasServerSocket`.
-    pub fn handle_server_message(server_socket: &CrasServerSocket) -> Result<ServerResult> {
-        let message = CrasClientMessage::try_new(&server_socket)?;
-        match message.get_id()? {
-            CRAS_CLIENT_MESSAGE_ID::CRAS_CLIENT_CONNECTED => {
-                let cmsg: &cras_client_connected = message.get_message()?;
-                // CRAS server should return a shared memory area which contains
-                // `cras_server_state`.
-                let server_state_fd = unsafe { CrasServerStateShmFd::new(message.fds[0]) };
-                Ok(ServerResult::Connected(cmsg.client_id, server_state_fd))
-            }
-            CRAS_CLIENT_MESSAGE_ID::CRAS_CLIENT_STREAM_CONNECTED => {
-                let cmsg: &cras_client_stream_connected = message.get_message()?;
-                // 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.
-                Ok(ServerResult::StreamConnected(
-                    cmsg.stream_id,
-                    // Safe because CRAS ensures that the first fd contains a cras_audio_shm_header
-                    unsafe { CrasAudioShmHeaderFd::new(message.fds[0]) },
-                    // Safe because CRAS ensures that the second fd has length 'samples_shm_size'
-                    unsafe { CrasShmFd::new(message.fds[1], cmsg.samples_shm_size as usize) },
-                ))
-            }
-            _ => Err(Error::new(ErrorType::MessageTypeError)),
-        }
-    }
-}
-
-// A structure for raw message with fds from CRAS server.
-struct CrasClientMessage {
-    fds: [RawFd; 2],
-    data: [u8; CRAS_CLIENT_MAX_MSG_SIZE as usize],
-    len: usize,
-}
-
-/// The default constructor won't be used outside of this file and it's an optimization to prevent
-/// having to copy the message data from a temp buffer.
-impl Default for CrasClientMessage {
-    // Initializes fields with default values.
-    fn default() -> Self {
-        Self {
-            fds: [-1; 2],
-            data: [0; CRAS_CLIENT_MAX_MSG_SIZE as usize],
-            len: 0,
-        }
-    }
-}
-
-impl CrasClientMessage {
-    // Reads a message from server_socket and checks validity of the read result
-    fn try_new(server_socket: &CrasServerSocket) -> Result<CrasClientMessage> {
-        let mut message: Self = Default::default();
-        let (len, fd_nums) = server_socket.recv_with_fds(&mut message.data, &mut message.fds)?;
-
-        if len < mem::size_of::<cras_client_message>() {
-            Err(Error::new(ErrorType::MessageTruncated))
-        } else {
-            message.len = len;
-            message.check_fd_nums(fd_nums)?;
-            Ok(message)
-        }
-    }
-
-    // Check if `fd nums` of a read result is valid
-    fn check_fd_nums(&self, fd_nums: usize) -> Result<()> {
-        match self.get_id()? {
-            CRAS_CLIENT_CONNECTED => match fd_nums {
-                1 => Ok(()),
-                _ => Err(Error::new(ErrorType::MessageNumFdError)),
-            },
-            CRAS_CLIENT_STREAM_CONNECTED => match fd_nums {
-                // 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)),
-            },
-            _ => Err(Error::new(ErrorType::MessageTypeError)),
-        }
-    }
-
-    // Gets the message id
-    fn get_id(&self) -> Result<CRAS_CLIENT_MESSAGE_ID> {
-        let offset = mem::size_of::<u32>();
-        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)),
-        }
-    }
-
-    // Gets a reference to the message content
-    fn get_message<T: DataInit>(&self) -> Result<&T> {
-        if self.len != mem::size_of::<T>() {
-            return Err(Error::new(ErrorType::InvalidSize));
-        }
-        T::from_slice(&self.data[..mem::size_of::<T>()])
-            .ok_or_else(|| Error::new(ErrorType::MessageFromSliceError))
-    }
-}
diff --git a/cras/client/libcras/src/cras_server_socket.rs b/cras/client/libcras/src/cras_server_socket.rs
deleted file mode 100644
index 139382a..0000000
--- a/cras/client/libcras/src/cras_server_socket.rs
+++ /dev/null
@@ -1,68 +0,0 @@
-// 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::io;
-use std::os::unix::io::{AsRawFd, RawFd};
-
-use sys_util::{net::UnixSeqpacket, ScmSocket};
-
-use data_model::DataInit;
-
-const CRAS_SERVER_SOCKET_PATH: &str = "/run/cras/.cras_socket";
-/// A socket connecting to the CRAS audio server.
-pub struct CrasServerSocket {
-    socket: UnixSeqpacket,
-}
-
-impl CrasServerSocket {
-    pub fn new() -> io::Result<CrasServerSocket> {
-        let socket = UnixSeqpacket::connect(CRAS_SERVER_SOCKET_PATH)?;
-        Ok(CrasServerSocket { socket })
-    }
-
-    /// Sends a sized and packed server messge to the server socket. The message
-    /// must implement `Sized` and `DataInit`.
-    /// # Arguments
-    /// * `message` - A sized and packed message.
-    /// * `fds` - A slice of fds to send.
-    ///
-    /// # Returns
-    /// * Length of written bytes in `usize`.
-    ///
-    /// # Errors
-    /// Return error if the socket fails to write message to server.
-    pub fn send_server_message_with_fds<M: Sized + DataInit>(
-        &self,
-        message: &M,
-        fds: &[RawFd],
-    ) -> io::Result<usize> {
-        match fds.len() {
-            0 => self.socket.send(message.as_slice()),
-            _ => match self.send_with_fds(message.as_slice(), fds) {
-                Ok(len) => Ok(len),
-                Err(err) => Err(io::Error::new(io::ErrorKind::Other, format!("{}", err))),
-            },
-        }
-    }
-
-    /// Creates a clone of the underlying socket. The returned clone can also be
-    /// used to communicate with the cras server.
-    pub fn try_clone(&self) -> io::Result<CrasServerSocket> {
-        let new_sock = self.socket.try_clone()?;
-        Ok(CrasServerSocket { socket: new_sock })
-    }
-}
-
-// For using `recv_with_fds` and `send_with_fds`.
-impl ScmSocket for CrasServerSocket {
-    fn socket_fd(&self) -> RawFd {
-        self.socket.as_raw_fd()
-    }
-}
-
-// For using `PollContex`.
-impl AsRawFd for CrasServerSocket {
-    fn as_raw_fd(&self) -> RawFd {
-        self.socket.as_raw_fd()
-    }
-}
diff --git a/cras/client/libcras/src/cras_shm.rs b/cras/client/libcras/src/cras_shm.rs
deleted file mode 100644
index 5547497..0000000
--- a/cras/client/libcras/src/cras_shm.rs
+++ /dev/null
@@ -1,969 +0,0 @@
-// 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::io;
-use std::mem;
-use std::os::unix::io::{AsRawFd, RawFd};
-use std::ptr;
-use std::ptr::NonNull;
-use std::slice;
-
-use libc;
-
-use cras_sys::gen::{
-    cras_audio_shm_header, cras_server_state, CRAS_NUM_SHM_BUFFERS, CRAS_SHM_BUFFERS_MASK,
-};
-use data_model::VolatileRef;
-
-/// A structure wrapping a fd which contains a shared `cras_audio_shm_header`.
-/// * `shm_fd` - A shared memory fd contains a `cras_audio_shm_header`
-pub struct CrasAudioShmHeaderFd {
-    fd: CrasShmFd,
-}
-
-impl CrasAudioShmHeaderFd {
-    /// Creates a `CrasAudioShmHeaderFd` by shared memory fd
-    /// # Arguments
-    /// * `fd` - A shared memory file descriptor, which will be owned by the resulting structure and
-    /// the fd will be closed on drop.
-    ///
-    /// # Returns
-    /// A structure wrapping a `CrasShmFd` with the input fd and `size` which equals to
-    /// the size of `cras_audio_shm_header`.
-    ///
-    /// To use this function safely, we need to make sure
-    /// - The input fd is a valid shared memory fd.
-    /// - The input shared memory fd won't be used by others.
-    /// - The shared memory area in the input fd contains a `cras_audio_shm_header`.
-    pub unsafe fn new(fd: libc::c_int) -> Self {
-        Self {
-            fd: CrasShmFd::new(fd, mem::size_of::<cras_audio_shm_header>()),
-        }
-    }
-}
-
-/// A wrapper for the raw structure `cras_audio_shm_header` with
-/// size information for the separate audio samples shm area and several
-/// `VolatileRef` to sub fields for safe access to the header.
-#[allow(dead_code)]
-pub struct CrasAudioHeader<'a> {
-    addr: *mut libc::c_void,
-    /// Size of the buffer for samples in CrasAudioBuffer
-    samples_len: usize,
-    used_size: VolatileRef<'a, u32>,
-    frame_size: VolatileRef<'a, u32>,
-    read_buf_idx: VolatileRef<'a, u32>,
-    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
-// pointers contained in it.
-unsafe impl<'a> Send for CrasAudioHeader<'a> {}
-
-/// An unsafe macro for getting `VolatileRef` for a field from a given NonNull pointer.
-/// It Supports
-/// - Nested sub-field
-/// - Element of an array field
-///
-/// To use this macro safely, we need to
-/// - Make sure the pointer address is readable and writable for its structure.
-/// - Make sure all `VolatileRef`s generated from this macro have exclusive ownership for the same
-/// pointer.
-#[macro_export]
-macro_rules! vref_from_addr {
-    ($addr:ident, $($field:ident).*) => {
-        VolatileRef::new(&mut $addr.as_mut().$($field).* as *mut _)
-    };
-
-    ($addr:ident, $field:ident[$idx:tt]) => {
-        VolatileRef::new(&mut $addr.as_mut().$field[$idx] as *mut _)
-    };
-}
-
-// Generates error when an index is out of range.
-fn index_out_of_range() -> io::Error {
-    io::Error::new(io::ErrorKind::InvalidInput, "Index out of range.")
-}
-
-impl<'a> CrasAudioHeader<'a> {
-    // Creates a `CrasAudioHeader` with given `CrasAudioShmHeaderFd` and `samples_len`
-    fn new(header_fd: CrasAudioShmHeaderFd, samples_len: usize) -> io::Result<Self> {
-        // Safe because the creator of CrasAudioShmHeaderFd already
-        // ensured that header_fd contains a cras_audio_shm_header.
-        let mmap_addr = unsafe {
-            cras_mmap(
-                header_fd.fd.size,
-                libc::PROT_READ | libc::PROT_WRITE,
-                header_fd.fd.as_raw_fd(),
-            )?
-        };
-
-        let mut addr = NonNull::new(mmap_addr as *mut cras_audio_shm_header)
-            .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "Failed to create header."))?;
-
-        // Safe because we know that mmap_addr (contained in addr) contains a
-        // cras_audio_shm_header, and the mapped area will be exclusively
-        // owned by this struct.
-        unsafe {
-            Ok(CrasAudioHeader {
-                addr: addr.as_ptr() as *mut libc::c_void,
-                samples_len,
-                used_size: vref_from_addr!(addr, config.used_size),
-                frame_size: vref_from_addr!(addr, config.frame_bytes),
-                read_buf_idx: vref_from_addr!(addr, read_buf_idx),
-                write_buf_idx: vref_from_addr!(addr, write_buf_idx),
-                read_offset: [
-                    vref_from_addr!(addr, read_offset[0]),
-                    vref_from_addr!(addr, read_offset[1]),
-                ],
-                write_offset: [
-                    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]),
-                ],
-            })
-        }
-    }
-
-    /// 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 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 buffer offset of the read buffer.
-    ///
-    ///  # Returns
-    ///
-    ///  * `usize` - read offset in bytes
-    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.
-    ///
-    /// # Returns
-    ///
-    /// * `usize` - Number of bytes per frame
-    pub fn get_frame_size(&self) -> usize {
-        self.frame_size.load() as usize
-    }
-
-    /// Gets the size in bytes of the shared memory buffer.
-    fn get_used_size(&self) -> usize {
-        self.used_size.load() as usize
-    }
-
-    /// Gets the index of the current written buffer.
-    ///
-    /// # Returns
-    /// `u32` - the returned index is less than `CRAS_NUM_SHM_BUFFERS`.
-    fn get_write_buf_idx(&self) -> u32 {
-        self.write_buf_idx.load() & CRAS_SHM_BUFFERS_MASK
-    }
-
-    fn get_read_buf_idx(&self) -> u32 {
-        self.read_buf_idx.load() & CRAS_SHM_BUFFERS_MASK
-    }
-
-    /// Switches the written buffer.
-    fn switch_write_buf_idx(&mut self) {
-        self.write_buf_idx
-            .store(self.get_write_buf_idx() as u32 ^ 1u32)
-    }
-
-    /// Switches the buffer to read.
-    fn switch_read_buf_idx(&mut self) {
-        self.read_buf_idx
-            .store(self.get_read_buf_idx() as u32 ^ 1u32)
-    }
-
-    /// Checks if the offset value for setting write_offset or read_offset is
-    /// out of range or not.
-    ///
-    /// # Arguments
-    /// `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 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,
-                format!(
-                    "Offset {} is larger than buffer size {}.",
-                    offset, buffer_len
-                ),
-            ));
-        }
-
-        Ok(())
-    }
-
-    /// Sets `write_offset[idx]` to the count of written bytes.
-    ///
-    /// # Arguments
-    /// `idx` - 0 <= `idx` < `CRAS_NUM_SHM_BUFFERS`
-    /// `offset` - 0 <= `offset` <= `used_size` && `offset` + `used_size` <=
-    /// `samples_len`. Writable size equals to 0 when offset equals to
-    /// `used_size`.
-    ///
-    /// # Errors
-    /// Returns an error if `offset` is out of range.
-    fn set_write_offset(&mut self, idx: usize, offset: u32) -> io::Result<()> {
-        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(())
-    }
-
-    /// Sets `read_offset[idx]` of to count of written bytes.
-    ///
-    /// # Arguments
-    /// `idx` - 0 <= `idx` < `CRAS_NUM_SHM_BUFFERS`
-    /// `offset` - 0 <= `offset` <= `used_size` && `offset` + `used_size` <=
-    /// `samples_len`. Readable size equals to 0 when offset equals to
-    /// `used_size`.
-    ///
-    /// # Errors
-    /// Returns error if index out of range.
-    fn set_read_offset(&mut self, idx: usize, offset: u32) -> io::Result<()> {
-        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`
-    /// - Sets `read_offset` of current buffer to `0`.
-    ///
-    /// # Arguments
-    ///
-    /// * `frame_count` - Number of frames written to the current buffer
-    ///
-    /// # Errors
-    ///
-    /// * Returns error if `frame_count` is larger than buffer size
-    ///
-    /// This function is safe because we switch `write_buf_idx` after letting
-    /// `write_offset` and `read_offset` ready and we read / write shared memory
-    /// variables with volatile operations.
-    pub fn commit_written_frames(&mut self, frame_count: u32) -> io::Result<()> {
-        // Uses `u64` to prevent possible overflow
-        let byte_count = frame_count as u64 * self.get_frame_size() as u64;
-        if byte_count > self.get_used_size() as u64 {
-            Err(io::Error::new(
-                io::ErrorKind::InvalidInput,
-                "frame_count * frame_size is larger than used_size",
-            ))
-        } else {
-            let idx = self.get_write_buf_idx() as usize;
-            // Sets `write_offset` of current buffer to frame_count * frame_size
-            self.set_write_offset(idx, byte_count as u32)?;
-            // Sets `read_offset` of current buffer to `0`.
-            self.set_read_offset(idx, 0)?;
-            // Switch to the other buffer
-            self.switch_write_buf_idx();
-            Ok(())
-        }
-    }
-
-    /// Get readable frames in current buffer.
-    ///
-    /// # Returns
-    ///
-    /// * `usize` - number of readable frames.
-    ///
-    /// # Errors
-    ///
-    /// Returns error if index out of range.
-    pub fn get_readable_frames(&self) -> io::Result<usize> {
-        let idx = self.get_read_buf_idx() as usize;
-        let read_offset = self.read_offset.get(idx).ok_or_else(index_out_of_range)?;
-        let write_offset = self.write_offset.get(idx).ok_or_else(index_out_of_range)?;
-        let nframes =
-            (write_offset.load() as i32 - read_offset.load() as i32) / self.get_frame_size() as i32;
-        if nframes < 0 {
-            Ok(0)
-        } else {
-            Ok(nframes as usize)
-        }
-    }
-
-    /// Commit read frames from reader, .
-    /// - Sets `read_offset` of current buffer to `read_offset + frame_count * frame_size`.
-    /// If `read_offset` is larger than or equal to `write_offset`, then
-    /// - Sets `read_offset` and `write_offset` to `0` and switch `read_buf_idx`.
-    ///
-    /// # Arguments
-    ///
-    /// * `frame_count` - Read frames in current read buffer.
-    ///
-    /// # Errors
-    ///
-    /// Returns error if index out of range.
-    pub fn commit_read_frames(&mut self, frame_count: u32) -> io::Result<()> {
-        let idx = self.get_read_buf_idx() as usize;
-        let read_offset = self.read_offset.get(idx).ok_or_else(index_out_of_range)?;
-        let write_offset = self.write_offset.get(idx).ok_or_else(index_out_of_range)?;
-        read_offset.store(read_offset.load() + frame_count * self.get_frame_size() as u32);
-        if read_offset.load() >= write_offset.load() {
-            read_offset.store(0);
-            write_offset.store(0);
-            self.switch_read_buf_idx();
-        }
-        Ok(())
-    }
-}
-
-impl<'a> Drop for CrasAudioHeader<'a> {
-    fn drop(&mut self) {
-        // Safe because all references must be gone by the time drop is called.
-        unsafe {
-            libc::munmap(self.addr as *mut _, mem::size_of::<cras_audio_shm_header>());
-        }
-    }
-}
-
-// To use this safely, we need to make sure
-// - The given fd contains valid space which is larger than `len` + `offset`
-unsafe fn cras_mmap_offset(
-    len: usize,
-    prot: libc::c_int,
-    fd: libc::c_int,
-    offset: usize,
-) -> io::Result<*mut libc::c_void> {
-    if offset > libc::off_t::max_value() as usize {
-        return Err(io::Error::new(
-            io::ErrorKind::InvalidInput,
-            "Requested offset is out of range of `libc::off_t`.",
-        ));
-    }
-    // It's safe because we handle its returned results.
-    match libc::mmap(
-        ptr::null_mut(),
-        len,
-        prot,
-        libc::MAP_SHARED,
-        fd,
-        offset as libc::off_t,
-    ) {
-        libc::MAP_FAILED => Err(io::Error::last_os_error()),
-        shm_ptr => Ok(shm_ptr),
-    }
-}
-
-// To use this safely, we need to make sure
-// - The given fd contains valid space which is larger than `len`
-unsafe fn cras_mmap(
-    len: usize,
-    prot: libc::c_int,
-    fd: libc::c_int,
-) -> io::Result<*mut libc::c_void> {
-    cras_mmap_offset(len, prot, fd, 0)
-}
-
-/// A structure that points to RO shared memory area - `cras_server_state`
-/// The structure is created from a shared memory fd which contains the structure.
-#[allow(dead_code)]
-pub struct CrasServerState {
-    addr: *mut libc::c_void,
-    size: usize,
-}
-
-impl CrasServerState {
-    /// An unsafe function for creating `CrasServerState`. To use this function safely, we need to
-    /// - Make sure that the `shm_fd` must come from the server's message that provides the shared
-    /// memory region. The Id for the message is `CRAS_CLIENT_MESSAGE_ID::CRAS_CLIENT_CONNECTED`.
-    #[allow(dead_code)]
-    pub unsafe fn new(shm_fd: CrasShmFd) -> io::Result<Self> {
-        let size = mem::size_of::<cras_server_state>();
-        if size > shm_fd.size {
-            Err(io::Error::new(
-                io::ErrorKind::InvalidInput,
-                "Invalid shared memory size.",
-            ))
-        } else {
-            let addr = cras_mmap(size, libc::PROT_READ, shm_fd.as_raw_fd())?;
-            Ok(CrasServerState { addr, size })
-        }
-    }
-
-    // Gets `cras_server_state` reference from the structure.
-    #[allow(dead_code)]
-    fn get_ref(&self) -> VolatileRef<cras_server_state> {
-        unsafe { VolatileRef::new(self.addr as *mut _) }
-    }
-}
-
-impl Drop for CrasServerState {
-    /// Call `munmap` for `addr`.
-    fn drop(&mut self) {
-        unsafe {
-            // Safe because all references must be gone by the time drop is called.
-            libc::munmap(self.addr, self.size);
-        }
-    }
-}
-
-/// A structure holding the mapped shared memory area used to exchange
-/// samples with CRAS. The shared memory is owned exclusively by this structure,
-/// and will be cleaned up on drop.
-/// * `addr` - The address of the mapped shared memory.
-/// * `len` - Length of the mapped shared memory in bytes.
-pub struct CrasAudioBuffer {
-    addr: *mut u8,
-    len: usize,
-}
-
-// It is safe to send audio buffers between threads as this struct has exclusive ownership of the
-// shared memory area contained in it.
-unsafe impl Send for CrasAudioBuffer {}
-
-impl CrasAudioBuffer {
-    fn new(samples_fd: CrasShmFd) -> io::Result<Self> {
-        // This is safe because we checked that the size of the shm in samples_fd
-        // was at least samples_fd.size when it was created.
-        let addr = unsafe {
-            cras_mmap(
-                samples_fd.size,
-                libc::PROT_READ | libc::PROT_WRITE,
-                samples_fd.as_raw_fd(),
-            )? as *mut u8
-        };
-        Ok(Self {
-            addr,
-            len: samples_fd.size,
-        })
-    }
-
-    /// Provides a mutable slice to be filled with audio samples.
-    pub fn get_buffer(&mut self) -> &mut [u8] {
-        // This is safe because it takes a mutable reference to self, and there can only be one
-        // taken at a time. Although this is shared memory, the reader side must have it mapped as
-        // read only.
-        unsafe { slice::from_raw_parts_mut(self.addr, self.len) }
-    }
-}
-
-impl Drop for CrasAudioBuffer {
-    fn drop(&mut self) {
-        // Safe because all references must be gone by the time drop is called.
-        unsafe {
-            libc::munmap(self.addr as *mut _, self.len);
-        }
-    }
-}
-
-/// Creates header and buffer from given shared memory fds.
-pub fn create_header_and_buffers<'a>(
-    header_fd: CrasAudioShmHeaderFd,
-    samples_fd: CrasShmFd,
-) -> io::Result<(CrasAudioHeader<'a>, CrasAudioBuffer)> {
-    let header = CrasAudioHeader::new(header_fd, samples_fd.size)?;
-    let buffer = CrasAudioBuffer::new(samples_fd)?;
-
-    Ok((header, buffer))
-}
-
-/// A structure wrapping a fd which contains a shared memory area and its size.
-/// * `fd` - The shared memory file descriptor, a `libc::c_int`.
-/// * `size` - Size of the shared memory area.
-pub struct CrasShmFd {
-    fd: libc::c_int,
-    size: usize,
-}
-
-impl CrasShmFd {
-    /// Creates a `CrasShmFd` by shared memory fd and size
-    /// # Arguments
-    /// * `fd` - A shared memory file descriptor, which will be owned by the resulting structure and
-    /// the fd will be closed on drop.
-    /// * `size` - Size of the shared memory.
-    ///
-    /// # Returns
-    /// * `CrasShmFd` - Wrap the input arguments without doing anything.
-    ///
-    /// To use this function safely, we need to make sure
-    /// - The input fd is a valid shared memory fd.
-    /// - The input shared memory fd won't be used by others.
-    /// - The input fd contains memory size larger than `size`.
-    pub unsafe fn new(fd: libc::c_int, size: usize) -> CrasShmFd {
-        CrasShmFd { fd, size }
-    }
-}
-
-impl AsRawFd for CrasShmFd {
-    fn as_raw_fd(&self) -> RawFd {
-        self.fd
-    }
-}
-
-impl Drop for CrasShmFd {
-    fn drop(&mut self) {
-        // It's safe here if we make sure
-        // - the input fd is valid and
-        // - `CrasShmFd` is the only owner
-        // in `new` function
-        unsafe {
-            libc::close(self.fd);
-        }
-    }
-}
-
-/// A structure wrapping a fd which contains a shared `cras_server_state`.
-/// * `shm_fd` - A shared memory fd contains a `cras_server_state`
-pub struct CrasServerStateShmFd {
-    #[allow(dead_code)]
-    shm_fd: CrasShmFd,
-}
-
-impl CrasServerStateShmFd {
-    /// Creates a `CrasServerStateShmFd` by shared memory fd
-    /// # Arguments
-    /// * `fd` - A shared memory file descriptor, which will be owned by the resulting structure and
-    /// the fd will be closed on drop.
-    ///
-    /// # Returns
-    /// A structure wrapping a `CrasShmFd` with the input fd and `size` which equals to
-    /// the size of `cras_server_sate`.
-    ///
-    /// To use this function safely, we need to make sure
-    /// - The input fd is a valid shared memory fd.
-    /// - The input shared memory fd won't be used by others.
-    /// - The shared memory area in the input fd contains a `cras_server_state`.
-    pub unsafe fn new(fd: libc::c_int) -> Self {
-        Self {
-            shm_fd: CrasShmFd::new(fd, mem::size_of::<cras_server_state>()),
-        }
-    }
-}
-
-#[cfg(test)]
-mod tests {
-    use super::*;
-    use std::fs::File;
-    use std::os::unix::io::IntoRawFd;
-    use sys_util::{kernel_has_memfd, SharedMemory};
-
-    #[test]
-    fn cras_audio_header_switch_test() {
-        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());
-    }
-
-    #[test]
-    fn cras_audio_header_write_offset_test() {
-        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_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() {
-        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());
-        // 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_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() {
-        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);
-        assert_eq!(header.write_buf_idx.load(), 1);
-    }
-
-    #[test]
-    fn cras_audio_header_get_readable_frames_test() {
-        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);
-        header.write_offset[0].store(10);
-        let frames = header
-            .get_readable_frames()
-            .expect("Failed to get readable frames.");
-        assert_eq!(frames, 4);
-    }
-
-    #[test]
-    fn cras_audio_header_commit_read_frames_test() {
-        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);
-        header.write_offset[0].store(10);
-        header
-            .commit_read_frames(3)
-            .expect("Failed to commit read frames.");
-        assert_eq!(header.get_read_buf_idx(), 0);
-        assert_eq!(header.read_offset[0].load(), 8);
-
-        header
-            .commit_read_frames(1)
-            .expect("Failed to commit read frames.");
-        // Read buffer should be switched
-        assert_eq!(header.get_read_buf_idx(), 1);
-        assert_eq!(header.read_offset[0].load(), 0);
-        assert_eq!(header.read_offset[0].load(), 0);
-    }
-
-    #[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() {
-        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_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 create_cras_audio_header<'a>(samples_len: usize) -> CrasAudioHeader<'a> {
-        CrasAudioHeader::new(cras_audio_header_fd(), samples_len).unwrap()
-    }
-
-    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_audio_samples_fd(size: usize) -> CrasShmFd {
-        let shm = create_shm(size);
-        unsafe { CrasShmFd::new(shm.into_raw_fd(), size) }
-    }
-
-    #[test]
-    fn cras_mmap_pass() {
-        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
deleted file mode 100644
index bd9520a..0000000
--- a/cras/client/libcras/src/cras_stream.rs
+++ /dev/null
@@ -1,288 +0,0 @@
-// 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::cmp::min;
-use std::io;
-use std::marker::PhantomData;
-use std::mem;
-use std::{error, fmt};
-
-use audio_streams::{
-    capture::{CaptureBuffer, CaptureBufferStream},
-    BufferDrop, PlaybackBuffer, PlaybackBufferStream,
-};
-use cras_sys::gen::{
-    cras_disconnect_stream_message, cras_server_message, snd_pcm_format_t, CRAS_AUDIO_MESSAGE_ID,
-    CRAS_SERVER_MESSAGE_ID, CRAS_STREAM_DIRECTION,
-};
-use sys_util::error;
-
-use crate::audio_socket::{AudioMessage, AudioSocket};
-use crate::cras_server_socket::CrasServerSocket;
-use crate::cras_shm::*;
-
-#[derive(Debug)]
-pub enum ErrorType {
-    IoError(io::Error),
-    MessageTypeError,
-    NoShmError,
-}
-
-#[derive(Debug)]
-pub struct Error {
-    error_type: ErrorType,
-}
-
-impl Error {
-    fn new(error_type: ErrorType) -> Error {
-        Error { error_type }
-    }
-}
-
-impl error::Error for Error {}
-
-impl fmt::Display for Error {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        match self.error_type {
-            ErrorType::IoError(ref err) => err.fmt(f),
-            ErrorType::MessageTypeError => write!(f, "Message type error"),
-            ErrorType::NoShmError => write!(f, "Shared memory area is not created"),
-        }
-    }
-}
-
-impl From<io::Error> for Error {
-    fn from(io_err: io::Error) -> Error {
-        Error::new(ErrorType::IoError(io_err))
-    }
-}
-
-/// A trait controls the state of `CrasAudioHeader` and
-/// interacts with server's audio thread through `AudioSocket`.
-pub trait CrasStreamData<'a>: Send {
-    // Creates `CrasStreamData` with only `AudioSocket`.
-    fn new(audio_sock: AudioSocket) -> Self;
-    fn set_header(&mut self, header: CrasAudioHeader<'a>);
-    fn header_mut(&mut self) -> &mut Option<CrasAudioHeader<'a>>;
-    fn audio_sock_mut(&mut self) -> &mut AudioSocket;
-}
-
-/// `CrasStreamData` implementation for `PlaybackBufferStream`.
-pub struct CrasPlaybackData<'a> {
-    audio_sock: AudioSocket,
-    header: Option<CrasAudioHeader<'a>>,
-}
-
-impl<'a> CrasStreamData<'a> for CrasPlaybackData<'a> {
-    fn new(audio_sock: AudioSocket) -> Self {
-        Self {
-            audio_sock,
-            header: None,
-        }
-    }
-
-    fn set_header(&mut self, header: CrasAudioHeader<'a>) {
-        self.header = Some(header);
-    }
-
-    fn header_mut(&mut self) -> &mut Option<CrasAudioHeader<'a>> {
-        &mut self.header
-    }
-
-    fn audio_sock_mut(&mut self) -> &mut AudioSocket {
-        &mut self.audio_sock
-    }
-}
-
-impl<'a> BufferDrop for CrasPlaybackData<'a> {
-    fn trigger(&mut self, nframes: usize) {
-        let log_err = |e| error!("BufferDrop error: {}", e);
-        if let Some(header) = &mut self.header {
-            if let Err(e) = header.commit_written_frames(nframes as u32) {
-                log_err(e);
-            }
-        }
-        if let Err(e) = self.audio_sock.data_ready(nframes as u32) {
-            log_err(e);
-        }
-    }
-}
-
-/// `CrasStreamData` implementation for `CaptureBufferStream`.
-pub struct CrasCaptureData<'a> {
-    audio_sock: AudioSocket,
-    header: Option<CrasAudioHeader<'a>>,
-}
-
-impl<'a> CrasStreamData<'a> for CrasCaptureData<'a> {
-    fn new(audio_sock: AudioSocket) -> Self {
-        Self {
-            audio_sock,
-            header: None,
-        }
-    }
-
-    fn set_header(&mut self, header: CrasAudioHeader<'a>) {
-        self.header = Some(header);
-    }
-
-    fn header_mut(&mut self) -> &mut Option<CrasAudioHeader<'a>> {
-        &mut self.header
-    }
-
-    fn audio_sock_mut(&mut self) -> &mut AudioSocket {
-        &mut self.audio_sock
-    }
-}
-
-impl<'a> BufferDrop for CrasCaptureData<'a> {
-    fn trigger(&mut self, nframes: usize) {
-        let log_err = |e| error!("BufferDrop error: {}", e);
-        if let Some(header) = &mut self.header {
-            if let Err(e) = header.commit_read_frames(nframes as u32) {
-                log_err(e);
-            }
-        }
-        if let Err(e) = self.audio_sock.capture_ready(nframes as u32) {
-            log_err(e);
-        }
-    }
-}
-
-#[allow(dead_code)]
-pub struct CrasStream<'a, T: CrasStreamData<'a> + BufferDrop> {
-    stream_id: u32,
-    server_socket: CrasServerSocket,
-    block_size: u32,
-    direction: CRAS_STREAM_DIRECTION,
-    rate: usize,
-    num_channels: usize,
-    format: snd_pcm_format_t,
-    /// A structure for stream to interact with server audio thread.
-    controls: T,
-    /// The `PhantomData` is used by `controls: T`
-    phantom: PhantomData<CrasAudioHeader<'a>>,
-    audio_buffer: Option<CrasAudioBuffer>,
-}
-
-impl<'a, T: CrasStreamData<'a> + BufferDrop> CrasStream<'a, T> {
-    /// Creates a CrasStream by given arguments.
-    ///
-    /// # Returns
-    /// `CrasStream` - CRAS client stream.
-    pub fn new(
-        stream_id: u32,
-        server_socket: CrasServerSocket,
-        block_size: u32,
-        direction: CRAS_STREAM_DIRECTION,
-        rate: usize,
-        num_channels: usize,
-        format: snd_pcm_format_t,
-        audio_sock: AudioSocket,
-    ) -> Self {
-        Self {
-            stream_id,
-            server_socket,
-            block_size,
-            direction,
-            rate,
-            num_channels,
-            format,
-            controls: T::new(audio_sock),
-            phantom: PhantomData,
-            audio_buffer: None,
-        }
-    }
-
-    /// Receives shared memory fd and initialize stream audio shared memory area
-    pub fn init_shm(
-        &mut self,
-        header_fd: CrasAudioShmHeaderFd,
-        samples_fd: CrasShmFd,
-    ) -> Result<(), Error> {
-        let (header, buffer) = create_header_and_buffers(header_fd, samples_fd)?;
-        self.controls.set_header(header);
-        self.audio_buffer = Some(buffer);
-        Ok(())
-    }
-
-    fn wait_request_data(&mut self) -> Result<(), Error> {
-        match self.controls.audio_sock_mut().read_audio_message()? {
-            AudioMessage::Success { id, .. } => match id {
-                CRAS_AUDIO_MESSAGE_ID::AUDIO_MESSAGE_REQUEST_DATA => Ok(()),
-                _ => Err(Error::new(ErrorType::MessageTypeError)),
-            },
-            _ => Err(Error::new(ErrorType::MessageTypeError)),
-        }
-    }
-
-    fn wait_data_ready(&mut self) -> Result<u32, Error> {
-        match self.controls.audio_sock_mut().read_audio_message()? {
-            AudioMessage::Success { id, frames } => match id {
-                CRAS_AUDIO_MESSAGE_ID::AUDIO_MESSAGE_DATA_READY => Ok(frames),
-                _ => Err(Error::new(ErrorType::MessageTypeError)),
-            },
-            _ => Err(Error::new(ErrorType::MessageTypeError)),
-        }
-    }
-}
-
-impl<'a, T: CrasStreamData<'a> + BufferDrop> Drop for CrasStream<'a, T> {
-    /// A blocking drop function, sends the disconnect message to `CrasClient` and waits for
-    /// the return message.
-    /// Logs an error message to stderr if the method fails.
-    fn drop(&mut self) {
-        // Send stream disconnect message
-        let msg_header = cras_server_message {
-            length: mem::size_of::<cras_disconnect_stream_message>() as u32,
-            id: CRAS_SERVER_MESSAGE_ID::CRAS_SERVER_DISCONNECT_STREAM,
-        };
-        let server_cmsg = cras_disconnect_stream_message {
-            header: msg_header,
-            stream_id: self.stream_id,
-        };
-        if let Err(e) = self
-            .server_socket
-            .send_server_message_with_fds(&server_cmsg, &[])
-        {
-            error!("CrasStream::Drop error: {}", e);
-        }
-    }
-}
-
-impl<'a, T: CrasStreamData<'a> + BufferDrop> PlaybackBufferStream for CrasStream<'a, T> {
-    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_write_offset_and_len()?),
-        };
-        let buf = match self.audio_buffer.as_mut() {
-            None => return Err(Error::new(ErrorType::NoShmError).into()),
-            Some(audio_buffer) => &mut audio_buffer.get_buffer()[offset..offset + len],
-        };
-        PlaybackBuffer::new(frame_size, buf, &mut self.controls).map_err(Box::from)
-    }
-}
-
-impl<'a, T: CrasStreamData<'a> + BufferDrop> CaptureBufferStream for CrasStream<'a, T> {
-    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() {
-            None => return Err(Error::new(ErrorType::NoShmError).into()),
-            Some(header) => (
-                header.get_frame_size(),
-                header.get_readable_frames()?,
-                header.get_read_buffer_offset()?,
-            ),
-        };
-        let len = min(shm_frames, frames as usize) * frame_size;
-        let buf = match self.audio_buffer.as_mut() {
-            None => return Err(Error::new(ErrorType::NoShmError).into()),
-            Some(audio_buffer) => &mut audio_buffer.get_buffer()[offset..offset + len],
-        };
-        CaptureBuffer::new(frame_size, buf, &mut self.controls).map_err(Box::from)
-    }
-}
diff --git a/cras/client/libcras/src/libcras.rs b/cras/client/libcras/src/libcras.rs
deleted file mode 100644
index c81e540..0000000
--- a/cras/client/libcras/src/libcras.rs
+++ /dev/null
@@ -1,416 +0,0 @@
-// 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.
-//! Provides an interface for playing and recording audio through CRAS server.
-//!
-//! `CrasClient` implements `StreamSource` trait and it can create playback or capture
-//! stream - `CrasStream` which can be a
-//! - `PlaybackBufferStream` for audio playback or
-//! - `CaptureBufferStream` for audio capture.
-//!
-//! # Example of file audio playback
-//!
-//! `PlaybackBuffer`s to be filled with audio samples are obtained by calling
-//! `next_playback_buffer` from `CrasStream`.
-//!
-//! Users playing audio fill the provided buffers with audio. When a `PlaybackBuffer` is dropped,
-//! the samples written to it are committed to the `CrasStream` it came from.
-//!
-//!
-//! ```
-//! // An example of playing raw audio data from a given file
-//! use std::env;
-//! use std::fs::File;
-//! use std::io::{Read, Write};
-//! use std::thread::{spawn, JoinHandle};
-//! type Result<T> = std::result::Result<T, Box<std::error::Error>>;
-//!
-//! use libcras::{CrasClient, CrasClientType};
-//! use audio_streams::StreamSource;
-//!
-//! const BUFFER_SIZE: usize = 256;
-//! const FRAME_RATE: usize = 44100;
-//! const NUM_CHANNELS: usize = 2;
-//!
-//! # fn main() -> Result<()> {
-//! #    let args: Vec<String> = env::args().collect();
-//! #    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)?;
-//!
-//!              // Plays 1000 * BUFFER_SIZE samples from the given file
-//!              let mut file = File::open(&args[1])?;
-//!              let mut local_buffer = [0u8; BUFFER_SIZE * NUM_CHANNELS * 2];
-//!              for _i in 0..1000 {
-//!                  // Reads data to local buffer
-//!                  let _read_count = file.read(&mut local_buffer)?;
-//!
-//!                  // Gets writable buffer from stream and
-//!                  let mut buffer = stream.next_playback_buffer()?;
-//!                  // Writes data to stream buffer
-//!                  let _write_frames = buffer.write(&local_buffer)?;
-//!              }
-//!              // Stream and client should gracefully be closed out of this scope
-//! #        }
-//! #        _ => {
-//! #            println!("{} /path/to/playback_file.raw", args[0]);
-//! #        }
-//! #    };
-//! #    Ok(())
-//! # }
-//! ```
-//!
-//! # Example of file audio capture
-//!
-//! `CaptureBuffer`s which contain audio samples are obtained by calling
-//! `next_capture_buffer` from `CrasStream`.
-//!
-//! Users get captured audio samples from the provided buffers. When a `CaptureBuffer` is dropped,
-//! the number of read samples will be committed to the `CrasStream` it came from.
-//! ```
-//! use std::env;
-//! use std::fs::File;
-//! use std::io::{Read, Write};
-//! use std::thread::{spawn, JoinHandle};
-//! type Result<T> = std::result::Result<T, Box<std::error::Error>>;
-//!
-//! use libcras::{CrasClient, CrasClientType};
-//! use audio_streams::StreamSource;
-//!
-//! const BUFFER_SIZE: usize = 256;
-//! const FRAME_RATE: usize = 44100;
-//! const NUM_CHANNELS: usize = 2;
-//!
-//! # fn main() -> Result<()> {
-//! #    let args: Vec<String> = env::args().collect();
-//! #    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)?;
-//!
-//!              // Capture 1000 * BUFFER_SIZE samples to the given file
-//!              let mut file = File::create(&args[1])?;
-//!              let mut local_buffer = [0u8; BUFFER_SIZE * NUM_CHANNELS * 2];
-//!              for _i in 0..1000 {
-//!
-//!                  // Gets readable buffer from stream and
-//!                  let mut buffer = stream.next_capture_buffer()?;
-//!                  // Reads data to local buffer
-//!                  let read_count = buffer.read(&mut local_buffer)?;
-//!                  // Writes data to file
-//!                  let _read_frames = file.write(&local_buffer[..read_count])?;
-//!              }
-//!              // Stream and client should gracefully be closed out of this scope
-//! #        }
-//! #        _ => {
-//! #            println!("{} /path/to/capture_file.raw", args[0]);
-//! #        }
-//! #    };
-//! #    Ok(())
-//! # }
-//! ```
-use std::io;
-use std::mem;
-use std::os::unix::{
-    io::{AsRawFd, RawFd},
-    net::UnixStream,
-};
-use std::{error, fmt};
-
-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};
-
-mod audio_socket;
-use crate::audio_socket::AudioSocket;
-mod cras_server_socket;
-use crate::cras_server_socket::CrasServerSocket;
-mod cras_shm;
-mod cras_stream;
-use crate::cras_stream::{CrasCaptureData, CrasPlaybackData, CrasStream, CrasStreamData};
-mod cras_client_message;
-use crate::cras_client_message::*;
-
-#[derive(Debug)]
-pub enum ErrorType {
-    CrasClientMessageError(cras_client_message::Error),
-    CrasStreamError(cras_stream::Error),
-    IoError(io::Error),
-    SysUtilError(sys_util::Error),
-    MessageTypeError,
-    UnexpectedExit,
-}
-
-#[derive(Debug)]
-pub struct Error {
-    error_type: ErrorType,
-}
-
-impl Error {
-    fn new(error_type: ErrorType) -> Self {
-        Self { error_type }
-    }
-}
-
-impl error::Error for Error {}
-
-impl fmt::Display for Error {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        match self.error_type {
-            ErrorType::CrasClientMessageError(ref err) => err.fmt(f),
-            ErrorType::CrasStreamError(ref err) => err.fmt(f),
-            ErrorType::IoError(ref err) => err.fmt(f),
-            ErrorType::SysUtilError(ref err) => err.fmt(f),
-            ErrorType::MessageTypeError => write!(f, "Message type error"),
-            ErrorType::UnexpectedExit => write!(f, "Unexpected exit"),
-        }
-    }
-}
-
-type Result<T> = std::result::Result<T, Error>;
-
-impl From<io::Error> for Error {
-    fn from(io_err: io::Error) -> Self {
-        Self::new(ErrorType::IoError(io_err))
-    }
-}
-
-impl From<sys_util::Error> for Error {
-    fn from(sys_util_err: sys_util::Error) -> Self {
-        Self::new(ErrorType::SysUtilError(sys_util_err))
-    }
-}
-
-impl From<cras_stream::Error> for Error {
-    fn from(err: cras_stream::Error) -> Self {
-        Self::new(ErrorType::CrasStreamError(err))
-    }
-}
-
-impl From<cras_client_message::Error> for Error {
-    fn from(err: cras_client_message::Error) -> Self {
-        Self::new(ErrorType::CrasClientMessageError(err))
-    }
-}
-
-/// A CRAS server client, which implements StreamSource. It can create audio streams connecting
-/// to CRAS server.
-pub struct CrasClient {
-    server_socket: CrasServerSocket,
-    client_id: u32,
-    next_stream_id: u32,
-    cras_capture: bool,
-    client_type: CRAS_CLIENT_TYPE,
-}
-
-impl CrasClient {
-    /// Blocks creating a `CrasClient` with registered `client_id`
-    ///
-    /// # Results
-    ///
-    /// * `CrasClient` - A client to interact with CRAS server
-    ///
-    /// # Errors
-    ///
-    /// Returns error if error occurs while handling server message or message
-    /// type is incorrect
-    pub fn new() -> Result<Self> {
-        // Create a connection to the server.
-        let mut server_socket = CrasServerSocket::new()?;
-
-        // Gets client ID from server
-        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(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.
-    pub fn enable_cras_capture(&mut self) {
-        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;
-        self.next_stream_id += 1;
-        self.server_stream_id(&res)
-    }
-
-    // Gets server_stream_id from given stream_id
-    fn server_stream_id(&self, stream_id: &u32) -> Result<u32> {
-        Ok((self.client_id << 16) | stream_id)
-    }
-
-    // Creates general stream with given parameters
-    fn create_stream<'a, T: BufferDrop + CrasStreamData<'a>>(
-        &mut self,
-        block_size: u32,
-        direction: CRAS_STREAM_DIRECTION,
-        rate: usize,
-        channel_num: usize,
-        format: snd_pcm_format_t,
-    ) -> Result<CrasStream<'a, T>> {
-        let stream_id = self.next_server_stream_id()?;
-
-        // Prepares server message
-        let audio_format = cras_audio_format_packed::new(format, rate, channel_num);
-        let msg_header = cras_server_message {
-            length: mem::size_of::<cras_connect_message>() as u32,
-            id: CRAS_SERVER_MESSAGE_ID::CRAS_SERVER_CONNECT_STREAM,
-        };
-        let server_cmsg = cras_connect_message {
-            header: msg_header,
-            proto_version: CRAS_PROTO_VER,
-            direction,
-            stream_id,
-            stream_type: CRAS_STREAM_TYPE::CRAS_STREAM_TYPE_DEFAULT,
-            buffer_frames: block_size,
-            cb_threshold: block_size,
-            flags: 0,
-            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
-        let (sock1, sock2) = UnixStream::pair()?;
-
-        // Sends `CRAS_SERVER_CONNECT_STREAM` message
-        let socks = [sock2.as_raw_fd()];
-        self.server_socket
-            .send_server_message_with_fds(&server_cmsg, &socks)?;
-
-        let audio_socket = AudioSocket::new(sock1);
-        let mut stream = CrasStream::new(
-            stream_id,
-            self.server_socket.try_clone()?,
-            block_size,
-            direction,
-            rate,
-            channel_num,
-            format,
-            audio_socket,
-        );
-
-        loop {
-            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;
-            }
-        }
-
-        Ok(stream)
-    }
-
-    // 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(socket, Token::ServerMsg).and(Ok(pc)))?;
-
-        let events = poll_ctx.wait()?;
-        // Check the first readable message
-        let tokens: Vec<Token> = events.iter_readable().map(|e| e.token()).collect();
-        tokens
-            .get(0)
-            .ok_or_else(|| Error::new(ErrorType::UnexpectedExit))
-            .and_then(|ref token| {
-                match token {
-                    Token::ServerMsg => ServerResult::handle_server_message(socket),
-                }
-                .map_err(Into::into)
-            })
-    }
-}
-
-impl StreamSource for CrasClient {
-    fn new_playback_stream(
-        &mut self,
-        num_channels: usize,
-        frame_rate: usize,
-        buffer_size: usize,
-    ) -> std::result::Result<
-        (Box<dyn StreamControl>, Box<dyn PlaybackBufferStream>),
-        Box<dyn error::Error>,
-    > {
-        Ok((
-            Box::new(DummyStreamControl::new()),
-            Box::new(self.create_stream::<CrasPlaybackData>(
-                buffer_size as u32,
-                CRAS_STREAM_DIRECTION::CRAS_STREAM_OUTPUT,
-                frame_rate,
-                num_channels,
-                _snd_pcm_format::SND_PCM_FORMAT_S16_LE,
-            )?),
-        ))
-    }
-
-    fn new_capture_stream(
-        &mut self,
-        num_channels: usize,
-        frame_rate: usize,
-        buffer_size: usize,
-    ) -> std::result::Result<
-        (Box<dyn StreamControl>, Box<dyn CaptureBufferStream>),
-        Box<dyn error::Error>,
-    > {
-        if self.cras_capture {
-            Ok((
-                Box::new(DummyStreamControl::new()),
-                Box::new(self.create_stream::<CrasCaptureData>(
-                    buffer_size as u32,
-                    CRAS_STREAM_DIRECTION::CRAS_STREAM_INPUT,
-                    frame_rate,
-                    num_channels,
-                    _snd_pcm_format::SND_PCM_FORMAT_S16_LE,
-                )?),
-            ))
-        } else {
-            Ok((
-                Box::new(DummyStreamControl::new()),
-                Box::new(DummyCaptureStream::new(
-                    num_channels,
-                    frame_rate,
-                    buffer_size,
-                )),
-            ))
-        }
-    }
-
-    fn keep_fds(&self) -> Option<Vec<RawFd>> {
-        Some(vec![self.server_socket.as_raw_fd()])
-    }
-}
diff --git a/cras/examples/cplay.c b/cras/examples/cplay.c
index eb6d8e6..8b78447 100644
--- a/cras/examples/cplay.c
+++ b/cras/examples/cplay.c
@@ -19,11 +19,14 @@
 };
 
 /* 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)
 {
 	struct stream_data *data = (struct stream_data *)user_arg;
 	int nread;
@@ -36,8 +39,10 @@
 }
 
 /* Run from callback thread. */
-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);
 	exit(err);
@@ -77,9 +82,8 @@
 	data->frame_bytes = 4;
 
 	rc = cras_helper_add_stream_simple(client, CRAS_STREAM_OUTPUT, data,
-					   put_samples, stream_error,
-					   SND_PCM_FORMAT_S16_LE, rate,
-					   num_channels, NO_DEVICE, &stream_id);
+			put_samples, stream_error, SND_PCM_FORMAT_S16_LE, rate,
+			num_channels, NO_DEVICE, &stream_id);
 	if (rc < 0) {
 		fprintf(stderr, "adding a stream %d\n", rc);
 		goto destroy_exit;
diff --git a/cras/examples/cplay_buffer.c b/cras/examples/cplay_buffer.c
index 07e5d0f..98c63c1 100644
--- a/cras/examples/cplay_buffer.c
+++ b/cras/examples/cplay_buffer.c
@@ -52,11 +52,10 @@
 	}
 
 	rc = cras_helper_play_buffer(client, buffer, nread / 4,
-				     SND_PCM_FORMAT_S16_LE, rate, num_channels,
-				     cras_client_get_first_dev_type_idx(
-					     client,
-					     CRAS_NODE_TYPE_INTERNAL_SPEAKER,
-					     CRAS_STREAM_OUTPUT));
+			SND_PCM_FORMAT_S16_LE, rate, num_channels,
+			cras_client_get_first_dev_type_idx(
+				client, CRAS_NODE_TYPE_INTERNAL_SPEAKER,
+				CRAS_STREAM_OUTPUT));
 	if (rc < 0) {
 		fprintf(stderr, "playing a buffer %d\n", rc);
 		goto destroy_exit;
diff --git a/cras/src/Android.bp b/cras/src/Android.bp
index 070e6ca..46c364f 100644
--- a/cras/src/Android.bp
+++ b/cras/src/Android.bp
@@ -5,17 +5,13 @@
         "common/cras_audio_format.c",
         "common/cras_config.c",
         "common/cras_file_wait.c",
-        "common/cras_shm.c",
         "common/cras_util.c",
         "common/edid_utils.c",
         "libcras/cras_client.c",
         "libcras/cras_helpers.c",
     ],
 
-    shared_libs: [
-        "libcutils",
-        "libtinyalsa",
-    ],
+    shared_libs: ["libtinyalsa"],
 
     export_include_dirs: [
         "common",
@@ -28,7 +24,6 @@
         "-Werror",
         "-Wno-error=missing-field-initializers",
         "-Wno-sign-compare",
-        "-Wno-unused-function",
         "-Wno-unused-parameter",
     ],
 }
diff --git a/cras/src/Makefile.am b/cras/src/Makefile.am
index acc62d4..ddb53fa 100644
--- a/cras/src/Makefile.am
+++ b/cras/src/Makefile.am
@@ -31,7 +31,9 @@
 
 if HAVE_WEBRTC_APM
 CRAS_WEBRTC_APM_SOURCES = \
-	server/cras_apm_list.c
+	server/cras_apm_list.c \
+	server/config/aec_config.c \
+	server/config/apm_config.c
 else
 CRAS_WEBRTC_APM_SOURCES =
 endif
@@ -58,7 +60,6 @@
 	server/cras_dbus_control.c \
 	server/cras_hfp_ag_profile.c \
 	server/cras_hfp_iodev.c \
-	server/cras_hfp_alsa_iodev.c \
 	server/cras_hfp_info.c \
 	server/cras_hfp_slc.c \
 	server/cras_a2dp_endpoint.c \
@@ -101,7 +102,6 @@
 	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 \
@@ -127,7 +127,6 @@
 	server/cras_empty_iodev.c \
 	server/cras_expr.c \
 	server/cras_fmt_conv.c \
-	server/cras_fmt_conv_ops.c \
 	server/cras_gpio_jack.c \
 	server/cras_hotword_handler.c \
 	server/cras_iodev.c \
@@ -139,10 +138,6 @@
 	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 \
@@ -164,7 +159,7 @@
 	$(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/plc \
+	-I$(top_srcdir)/src/server/config \
 	$(DBUS_CFLAGS) $(SBC_CFLAGS) $(SELINUX_CFLAGS)
 libcrasserver_la_LIBADD = \
 	libcrasmix.la \
@@ -183,7 +178,7 @@
 
 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/plc \
+	-I$(top_srcdir)/src/server/config \
 	$(DBUS_CFLAGS) $(SBC_CFLAGS)
 
 cras_LDADD = \
@@ -213,7 +208,7 @@
 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/plc \
+	-I$(top_srcdir)/src/server/config \
 	$(DBUS_CFLAGS) $(SBC_CFLAGS)
 
 libcrasmix_sse42_la_SOURCES = \
@@ -222,7 +217,7 @@
 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/plc \
+	-I$(top_srcdir)/src/server/config \
 	$(DBUS_CFLAGS) $(SSE42_CFLAGS)
 
 libcrasmix_avx_la_SOURCES = \
@@ -231,7 +226,7 @@
 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/plc \
+	-I$(top_srcdir)/src/server/config \
 	$(DBUS_CFLAGS) $(AVX_CFLAGS)
 
 libcrasmix_avx2_la_SOURCES = \
@@ -240,7 +235,7 @@
 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/plc \
+	-I$(top_srcdir)/src/server/config \
 	$(DBUS_CFLAGS) $(AVX2_CFLAGS)
 
 libcrasmix_fma_la_SOURCES = \
@@ -249,7 +244,7 @@
 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/plc \
+	-I$(top_srcdir)/src/server/config \
 	$(DBUS_CFLAGS) $(FMA_CFLAGS)
 
 lib_LTLIBRARIES = libcras.la
@@ -257,7 +252,6 @@
 	common/cras_audio_format.c \
 	common/cras_config.c \
 	common/cras_file_wait.c \
-	common/cras_shm.c \
 	common/cras_util.c \
 	common/edid_utils.c \
 	libcras/cras_client.c \
@@ -317,8 +311,6 @@
 	bt_device_unittest \
 	bt_io_unittest \
 	hfp_iodev_unittest \
-	hfp_alsa_iodev_unittest \
-	hfp_ag_profile_unittest \
 	hfp_slc_unittest
 else
 DBUS_TESTS =
@@ -345,7 +337,6 @@
 	alsa_mixer_unittest \
 	alsa_ucm_unittest \
 	array_unittest \
-	biquad_unittest \
 	byte_buffer_unittest \
 	card_config_unittest \
 	checksum_unittest \
@@ -361,15 +352,12 @@
 	dsp_unittest \
 	dumper_unittest \
 	edid_utils_unittest \
-	empty_iodev_unittest \
 	expr_unittest \
 	file_wait_unittest \
 	float_buffer_unittest \
 	fmt_conv_unittest \
-	fmt_conv_ops_unittest \
 	hfp_info_unittest \
 	buffer_share_unittest \
-	input_data_unittest \
 	iodev_list_unittest \
 	iodev_unittest \
 	loopback_iodev_unittest \
@@ -379,9 +367,7 @@
 	polled_interval_checker_unittest \
 	ramp_unittest \
 	rate_estimator_unittest \
-	control_rclient_unittest \
-	playback_rclient_unittest \
-	capture_rclient_unittest \
+	rclient_unittest \
 	rstream_unittest \
 	shm_unittest \
 	server_metrics_unittest \
@@ -395,27 +381,27 @@
 
 check_PROGRAMS = $(TESTS)
 
-cras_test_client_SOURCES = tools/cras_test_client/cras_test_client.c
+cras_test_client_SOURCES = tests/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
 
-tools/cras_test_client/cras_test_client.c: common/cras_version.h
+tests/cras_test_client.c: common/cras_version.h
 
-cras_monitor_SOURCES = tools/cras_monitor/cras_monitor.c
+cras_monitor_SOURCES = tests/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
 
-tools/cras_monitor/cras_monitor.c: common/cras_version.h
+tests/cras_monitor.c: common/cras_version.h
 
-cras_router_SOURCES = tools/cras_router/cras_router.c
+cras_router_SOURCES = tests/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
 
-tools/cras_router/cras_router.c: common/cras_version.h
+tests/cras_router.c: common/cras_version.h
 
 CLEANFILES = common/cras_version.h
 .PHONY: common/cras_version.h
@@ -483,14 +469,6 @@
 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
@@ -527,10 +505,8 @@
 audio_format_unittest_LDADD = -lgtest -lpthread
 
 if HAVE_DBUS
-a2dp_info_unittest_SOURCES =  \
-	server/cras_a2dp_info.c \
-	tests/a2dp_info_unittest.cc \
-	tests/sbc_codec_stub.cc
+a2dp_info_unittest_SOURCES = tests/a2dp_info_unittest.cc \
+	server/cras_a2dp_info.c
 a2dp_info_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/server \
 	-I$(top_srcdir)/src/common
 a2dp_info_unittest_LDADD = -lgtest -lpthread
@@ -586,7 +562,7 @@
 	-I$(top_srcdir)/src/server \
 	-I$(top_srcdir)/src/server/config \
 	$(WEBRTC_APM_CFLAGS)
-apm_list_unittest_LDADD = -lgtest -liniparser
+apm_list_unittest_LDADD = -lgtest
 endif
 
 array_unittest_SOURCES = tests/array_unittest.cc
@@ -594,8 +570,7 @@
 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 \
-	common/cras_shm.c
+	server/dev_io.c tests/empty_audio_stub.cc
 audio_thread_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) \
 	-I$(top_srcdir)/src/common -I$(top_srcdir)/src/server
 audio_thread_unittest_LDADD = -lgtest -lpthread -lrt
@@ -618,12 +593,6 @@
 bt_io_unittest_LDADD = -lgtest -lpthread $(DBUS_LIBS)
 endif
 
-biquad_unittest_SOURCES = tests/biquad_unittest.cc \
-	dsp/biquad.c
-biquad_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) $(DSP_INCLUDE_PATHS) \
-	-I$(top_srcdir)/src/server
-biquad_unittest_LDADD = -lgtest -lpthread -lm
-
 byte_buffer_unittest_SOURCES = tests/byte_buffer_unittest.cc
 byte_buffer_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/common
 byte_buffer_unittest_LDADD = -lgtest -lpthread
@@ -640,11 +609,10 @@
 checksum_unittest_LDADD = -lgtest -lpthread
 
 cras_client_unittest_SOURCES = tests/cras_client_unittest.cc \
-	common/cras_config.c common/cras_shm.c common/cras_util.c \
-	common/cras_file_wait.c
+	common/cras_config.c common/cras_util.c common/cras_file_wait.c
 cras_client_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/common \
 	-I$(top_srcdir)/src/libcras
-cras_client_unittest_LDADD = -lgtest -lpthread -lrt -lspeexdsp
+cras_client_unittest_LDADD = -lgtest -lpthread -lspeexdsp
 
 cras_tm_unittest_SOURCES = tests/cras_tm_unittest.cc server/cras_tm.c
 cras_tm_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/common \
@@ -654,11 +622,17 @@
 dev_io_unittest_SOURCES = \
 	$(CRAS_SELINUX_UNITTEST_SOURCES) \
 	common/cras_audio_format.c \
+	common/cras_shm.c \
+	server/cras_audio_area.c \
+	server/cras_fmt_conv.c \
+	server/cras_mix.c \
+	server/cras_mix_ops.c \
 	server/dev_io.c \
+	server/dev_stream.c \
+	server/linear_resampler.c \
 	tests/dev_io_stubs.cc \
 	tests/iodev_stub.cc \
 	tests/empty_audio_stub.cc \
-	tests/metrics_stub.cc \
 	tests/rstream_stub.cc \
 	tests/dev_io_unittest.cc
 dev_io_unittest_CXXFLAGS = \
@@ -679,10 +653,10 @@
 	-lgtest -lrt -lpthread -ldl -lm -lspeexdsp
 
 dev_stream_unittest_SOURCES = tests/dev_stream_unittest.cc \
-	server/dev_stream.c common/cras_shm.c
+	server/dev_stream.c
 dev_stream_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) \
 	-I$(top_srcdir)/src/common -I$(top_srcdir)/src/server
-dev_stream_unittest_LDADD = -lgtest -liniparser -lpthread -lrt
+dev_stream_unittest_LDADD = -lgtest -liniparser -lpthread
 
 device_blacklist_unittest_SOURCES = tests/device_blacklist_unittest.cc \
 	server/config/cras_device_blacklist.c
@@ -731,12 +705,6 @@
 edid_utils_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/common
 edid_utils_unittest_LDADD = -lgtest -lpthread
 
-empty_iodev_unittest_SOURCES = tests/empty_iodev_unittest.cc \
-	server/cras_empty_iodev.c
-empty_iodev_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/common \
-	-I$(top_srcdir)/src/server
-empty_iodev_unittest_LDADD = -lgtest -lpthread
-
 expr_unittest_SOURCES = tests/expr_unittest.cc server/cras_expr.c common/dumper.c
 expr_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/common \
 	-I$(top_srcdir)/src/server
@@ -754,22 +722,14 @@
 	-I$(top_srcdir)/src/server
 float_buffer_unittest_LDADD = -lgtest -lpthread
 
-fmt_conv_unittest_SOURCES = tests/fmt_conv_unittest.cc server/cras_fmt_conv.c \
-	server/cras_fmt_conv_ops.c
+fmt_conv_unittest_SOURCES = tests/fmt_conv_unittest.cc server/cras_fmt_conv.c
 fmt_conv_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/common \
 	 -I$(top_srcdir)/src/server
 fmt_conv_unittest_LDADD = -lasound -lspeexdsp -lgtest -lpthread
 
-fmt_conv_ops_unittest_SOURCES = tests/fmt_conv_ops_unittest.cc \
-	server/cras_fmt_conv_ops.c
-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 \
-	tests/metrics_stub.cc tests/sbc_codec_stub.cc
+hfp_info_unittest_SOURCES = tests/hfp_info_unittest.cc
 hfp_info_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/common \
-	-I$(top_srcdir)/src/server -I$(top_srcdir)/src/plc
+	-I$(top_srcdir)/src/server
 hfp_info_unittest_LDADD = -lgtest -lpthread
 
 if HAVE_DBUS
@@ -779,18 +739,6 @@
 	-I$(top_srcdir)/src/server $(DBUS_CFLAGS)
 hfp_iodev_unittest_LDADD = -lgtest -lpthread $(DBUS_LIBS)
 
-hfp_alsa_iodev_unittest_SOURCES = tests/hfp_alsa_iodev_unittest.cc \
-	server/cras_hfp_alsa_iodev.c common/sfh.c
-hfp_alsa_iodev_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) \
-	-I$(top_srcdir)/src/common -I$(top_srcdir)/src/server $(DBUS_CFLAGS)
-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 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)
-
 hfp_slc_unittest_SOURCES = tests/hfp_slc_unittest.cc \
 	server/cras_hfp_slc.c
 hfp_slc_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/common \
@@ -817,17 +765,11 @@
 	-I$(top_srcdir)/src/server
 loopback_iodev_unittest_LDADD = -lgtest -lpthread
 
-input_data_unittest_SOURCES = tests/input_data_unittest.cc \
-	server/input_data.c
-input_data_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/common \
-	 -I$(top_srcdir)/src/dsp -I$(top_srcdir)/src/server
-input_data_unittest_LDADD = -lgtest -lpthread
-
 iodev_unittest_SOURCES = tests/iodev_unittest.cc \
-	server/cras_iodev.c common/cras_shm.c
+	server/cras_iodev.c
 iodev_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/common \
 	 -I$(top_srcdir)/src/server
-iodev_unittest_LDADD = -lgtest -lpthread -lrt
+iodev_unittest_LDADD = -lgtest -lpthread
 
 mix_unittest_SOURCES = tests/mix_unittest.cc server/cras_mix.c
 mix_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/common \
@@ -867,23 +809,10 @@
 	 -I$(top_srcdir)/src/server
 rate_estimator_unittest_LDADD = -lgtest -lpthread
 
-control_rclient_unittest_SOURCES = tests/control_rclient_unittest.cc
-control_rclient_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) \
-	-I$(top_srcdir)/src/common \
-	-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
+rclient_unittest_SOURCES = tests/rclient_unittest.cc
+rclient_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/common \
+	 -I$(top_srcdir)/src/server $(CRAS_UT_TMPDIR_CFLAGS)
+rclient_unittest_LDADD = -lgtest -lpthread
 
 rstream_unittest_SOURCES = tests/rstream_unittest.cc server/cras_rstream.c \
 	common/cras_shm.c $(CRAS_SELINUX_UNITTEST_SOURCES)
@@ -927,7 +856,6 @@
 	common/cras_shm.c \
 	server/cras_audio_area.c \
 	server/cras_fmt_conv.c \
-	server/cras_fmt_conv_ops.c \
 	server/cras_mix.c \
 	server/cras_mix_ops.c \
 	server/dev_io.c \
@@ -936,7 +864,6 @@
 	tests/dev_io_stubs.cc \
 	tests/iodev_stub.cc \
 	tests/empty_audio_stub.cc \
-	tests/metrics_stub.cc \
 	tests/rstream_stub.cc \
 	tests/timing_unittest.cc
 timing_unittest_CXXFLAGS = \
diff --git a/cras/src/alsa_plugin/ctl_cras.c b/cras/src/alsa_plugin/ctl_cras.c
index 822b63a..a410bd3 100644
--- a/cras/src/alsa_plugin/ctl_cras.c
+++ b/cras/src/alsa_plugin/ctl_cras.c
@@ -29,14 +29,14 @@
 
 /* CRAS mixer elements. */
 static const struct cras_mixer_control cras_elems[NUM_CTL_CRAS_MIXER_ELEMS] = {
-	{ "Master Playback Switch", SND_CTL_ELEM_TYPE_BOOLEAN,
-	  SND_CTL_EXT_ACCESS_READWRITE, 1 },
-	{ "Master Playback Volume", SND_CTL_ELEM_TYPE_INTEGER,
-	  SND_CTL_EXT_ACCESS_READWRITE, 1 },
-	{ "Capture Switch", SND_CTL_ELEM_TYPE_BOOLEAN,
-	  SND_CTL_EXT_ACCESS_READWRITE, 1 },
-	{ "Capture Volume", SND_CTL_ELEM_TYPE_INTEGER,
-	  SND_CTL_EXT_ACCESS_READWRITE, 1 },
+	{"Master Playback Switch", SND_CTL_ELEM_TYPE_BOOLEAN,
+		SND_CTL_EXT_ACCESS_READWRITE, 1},
+	{"Master Playback Volume", SND_CTL_ELEM_TYPE_INTEGER,
+		SND_CTL_EXT_ACCESS_READWRITE, 1},
+	{"Capture Switch", SND_CTL_ELEM_TYPE_BOOLEAN,
+		SND_CTL_EXT_ACCESS_READWRITE, 1},
+	{"Capture Volume", SND_CTL_ELEM_TYPE_INTEGER,
+		SND_CTL_EXT_ACCESS_READWRITE, 1},
 };
 
 /* Holds the client and ctl plugin pointers. */
@@ -110,8 +110,8 @@
 /* Returns the range of the specified control.  The volume sliders always run
  * from 0 to 100 for CRAS. */
 static int ctl_cras_get_integer_info(snd_ctl_ext_t *ext_ctl,
-				     snd_ctl_ext_key_t key, long *imin,
-				     long *imax, long *istep)
+				     snd_ctl_ext_key_t key,
+				     long *imin, long *imax, long *istep)
 {
 	*istep = 0;
 	*imin = 0;
@@ -159,8 +159,10 @@
 	return (gain - min) / dB_step;
 }
 
-static int get_nodes(struct cras_client *client, enum CRAS_STREAM_DIRECTION dir,
-		     struct cras_ionode_info *nodes, size_t num_nodes)
+static int get_nodes(struct cras_client *client,
+		     enum CRAS_STREAM_DIRECTION dir,
+		     struct cras_ionode_info *nodes,
+		     size_t num_nodes)
 {
 	struct cras_iodev_info devs[MAX_IODEVS];
 	size_t num_devs;
@@ -190,8 +192,8 @@
 		*value = !cras_client_get_user_muted(cras->client);
 		break;
 	case CTL_CRAS_MIXER_PLAYBACK_VOLUME:
-		num_nodes = get_nodes(cras->client, CRAS_STREAM_OUTPUT, nodes,
-				      MAX_IONODES);
+		num_nodes = get_nodes(cras->client, CRAS_STREAM_OUTPUT,
+				      nodes, MAX_IONODES);
 		for (i = 0; i < num_nodes; i++) {
 			if (!nodes[i].active)
 				continue;
@@ -203,13 +205,14 @@
 		*value = !cras_client_get_system_capture_muted(cras->client);
 		break;
 	case CTL_CRAS_MIXER_CAPTURE_VOLUME:
-		num_nodes = get_nodes(cras->client, CRAS_STREAM_INPUT, nodes,
-				      MAX_IONODES);
+		num_nodes = get_nodes(cras->client, CRAS_STREAM_INPUT,
+				      nodes, MAX_IONODES);
 		for (i = 0; i < num_nodes; i++) {
 			if (!nodes[i].active)
 				continue;
-			*value = capture_gain_to_index(cras->client,
-						       nodes[i].capture_gain);
+			*value = capture_gain_to_index(
+					cras->client,
+					nodes[i].capture_gain);
 			break;
 		}
 		break;
@@ -222,7 +225,7 @@
 
 /* Writes the given values to CRAS. */
 static int ctl_cras_write_integer(snd_ctl_ext_t *ext_ctl, snd_ctl_ext_key_t key,
-				  long *value)
+				   long *value)
 {
 	struct ctl_cras *cras = (struct ctl_cras *)ext_ctl->private_data;
 	struct cras_ionode_info nodes[MAX_IONODES];
@@ -234,16 +237,15 @@
 		cras_client_set_user_mute(cras->client, !(*value));
 		break;
 	case CTL_CRAS_MIXER_PLAYBACK_VOLUME:
-		num_nodes = get_nodes(cras->client, CRAS_STREAM_OUTPUT, nodes,
-				      MAX_IONODES);
+		num_nodes = get_nodes(cras->client, CRAS_STREAM_OUTPUT,
+				      nodes, MAX_IONODES);
 		for (i = 0; i < num_nodes; i++) {
 			if (!nodes[i].active)
 				continue;
-			cras_client_set_node_volume(
-				cras->client,
-				cras_make_node_id(nodes[i].iodev_idx,
-						  nodes[i].ionode_idx),
-				*value);
+			cras_client_set_node_volume(cras->client,
+					cras_make_node_id(nodes[i].iodev_idx,
+							  nodes[i].ionode_idx),
+					*value);
 		}
 		break;
 	case CTL_CRAS_MIXER_CAPTURE_SWITCH:
@@ -251,16 +253,15 @@
 		break;
 	case CTL_CRAS_MIXER_CAPTURE_VOLUME:
 		gain = capture_index_to_gain(cras->client, *value);
-		num_nodes = get_nodes(cras->client, CRAS_STREAM_INPUT, nodes,
-				      MAX_IONODES);
+		num_nodes = get_nodes(cras->client, CRAS_STREAM_INPUT,
+				      nodes, MAX_IONODES);
 		for (i = 0; i < num_nodes; i++) {
 			if (!nodes[i].active)
 				continue;
-			cras_client_set_node_capture_gain(
-				cras->client,
-				cras_make_node_id(nodes[i].iodev_idx,
-						  nodes[i].ionode_idx),
-				gain);
+			cras_client_set_node_capture_gain(cras->client,
+					cras_make_node_id(nodes[i].iodev_idx,
+							  nodes[i].ionode_idx),
+					gain);
 		}
 		break;
 	default:
diff --git a/cras/src/alsa_plugin/pcm_cras.c b/cras/src/alsa_plugin/pcm_cras.c
index 715db2c..f30c7cd 100644
--- a/cras/src/alsa_plugin/pcm_cras.c
+++ b/cras/src/alsa_plugin/pcm_cras.c
@@ -82,8 +82,10 @@
 
 /* Poll callback used to wait for data ready (playback) or space available
  * (capture). */
-static int snd_pcm_cras_poll_revents(snd_pcm_ioplug_t *io, struct pollfd *pfds,
-				     unsigned int nfds, unsigned short *revents)
+static int snd_pcm_cras_poll_revents(snd_pcm_ioplug_t *io,
+				     struct pollfd *pfds,
+				     unsigned int nfds,
+				     unsigned short *revents)
 {
 	static char buf[1];
 	int rc;
@@ -97,8 +99,8 @@
 	}
 	*revents = pfds[0].revents & ~(POLLIN | POLLOUT);
 	if (pfds[0].revents & POLLIN)
-		*revents |= (io->stream == SND_PCM_STREAM_PLAYBACK) ? POLLOUT :
-								      POLLIN;
+		*revents |= (io->stream == SND_PCM_STREAM_PLAYBACK) ? POLLOUT
+								    : POLLIN;
 	return 0;
 }
 
@@ -116,9 +118,11 @@
 static int pcm_cras_process_cb(struct cras_client *client,
 			       cras_stream_id_t stream_id,
 			       uint8_t *capture_samples,
-			       uint8_t *playback_samples, unsigned int nframes,
+			       uint8_t *playback_samples,
+			       unsigned int nframes,
 			       const struct timespec *capture_ts,
-			       const struct timespec *playback_ts, void *arg)
+			       const struct timespec *playback_ts,
+			       void *arg)
 {
 	snd_pcm_ioplug_t *io;
 	struct snd_pcm_cras *pcm_cras;
@@ -130,8 +134,8 @@
 	uint8_t *samples;
 	const struct timespec *sample_time;
 
-	samples = capture_samples ?: playback_samples;
-	sample_time = capture_ts ?: playback_ts;
+	samples = capture_samples ? : playback_samples;
+	sample_time = capture_ts ? : playback_ts;
 
 	io = (snd_pcm_ioplug_t *)arg;
 	pcm_cras = (struct snd_pcm_cras *)io->private_data;
@@ -181,14 +185,17 @@
 		for (chan = 0; chan < io->channels; chan++)
 			if (io->stream == SND_PCM_STREAM_PLAYBACK)
 				snd_pcm_area_copy(&pcm_cras->areas[chan],
-						  copied_frames, &areas[chan],
-						  pcm_cras->hw_ptr, frames,
+						  copied_frames,
+						  &areas[chan],
+						  pcm_cras->hw_ptr,
+						  frames,
 						  io->format);
 			else
 				snd_pcm_area_copy(&areas[chan],
 						  pcm_cras->hw_ptr,
 						  &pcm_cras->areas[chan],
-						  copied_frames, frames,
+						  copied_frames,
+						  frames,
 						  io->format);
 
 		pcm_cras->hw_ptr += frames;
@@ -205,7 +212,9 @@
 
 /* Callback from CRAS for stream errors. */
 static int pcm_cras_error_cb(struct cras_client *client,
-			     cras_stream_id_t stream_id, int err, void *arg)
+			     cras_stream_id_t stream_id,
+			     int err,
+			     void *arg)
 {
 	fprintf(stderr, "Stream error %d\n", err);
 	return 0;
@@ -228,21 +237,25 @@
 	struct cras_audio_format *audio_format;
 	int rc;
 
-	audio_format =
-		cras_audio_format_create(io->format, io->rate, io->channels);
+	audio_format = cras_audio_format_create(io->format, io->rate,
+						io->channels);
 	if (audio_format == NULL)
 		return -ENOMEM;
 
 	params = cras_client_unified_params_create(
-		pcm_cras->direction, io->period_size, 0, 0, io,
-		pcm_cras_process_cb, pcm_cras_error_cb, audio_format);
+			pcm_cras->direction,
+			io->period_size,
+			0,
+			0,
+			io,
+			pcm_cras_process_cb,
+			pcm_cras_error_cb,
+			audio_format);
 	if (params == NULL) {
 		rc = -ENOMEM;
 		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;
@@ -250,7 +263,8 @@
 	pcm_cras->bytes_per_frame =
 		cras_client_format_bytes_per_frame(audio_format);
 
-	rc = cras_client_add_stream(pcm_cras->client, &pcm_cras->stream_id,
+	rc = cras_client_add_stream(pcm_cras->client,
+				    &pcm_cras->stream_id,
 				    params);
 	if (rc < 0) {
 		fprintf(stderr, "CRAS add failed\n");
@@ -278,7 +292,6 @@
  * snd_pcm_set_params(). */
 static int set_hw_constraints(struct snd_pcm_cras *pcm_cras)
 {
-	// clang-format off
 	static const unsigned int access_list[] = {
 		SND_PCM_ACCESS_MMAP_INTERLEAVED,
 		SND_PCM_ACCESS_MMAP_NONINTERLEAVED,
@@ -292,7 +305,6 @@
 		SND_PCM_FORMAT_S32_LE,
 		SND_PCM_FORMAT_S24_3LE,
 	};
-	// clang-format on
 	int rc;
 
 	rc = snd_pcm_ioplug_set_param_list(&pcm_cras->io,
@@ -308,26 +320,33 @@
 	if (rc < 0)
 		return rc;
 	rc = snd_pcm_ioplug_set_param_minmax(&pcm_cras->io,
-					     SND_PCM_IOPLUG_HW_CHANNELS, 1,
+					     SND_PCM_IOPLUG_HW_CHANNELS,
+					     1,
 					     pcm_cras->channels);
 	if (rc < 0)
 		return rc;
-	rc = snd_pcm_ioplug_set_param_minmax(
-		&pcm_cras->io, SND_PCM_IOPLUG_HW_RATE, 8000, 48000);
+	rc = snd_pcm_ioplug_set_param_minmax(&pcm_cras->io,
+					    SND_PCM_IOPLUG_HW_RATE,
+					    8000,
+					    48000);
 	if (rc < 0)
 		return rc;
 	rc = snd_pcm_ioplug_set_param_minmax(&pcm_cras->io,
-					     SND_PCM_IOPLUG_HW_BUFFER_BYTES, 64,
+					     SND_PCM_IOPLUG_HW_BUFFER_BYTES,
+					     64,
 					     2 * 1024 * 1024);
 	if (rc < 0)
 		return rc;
 	rc = snd_pcm_ioplug_set_param_minmax(&pcm_cras->io,
-					     SND_PCM_IOPLUG_HW_PERIOD_BYTES, 64,
+					     SND_PCM_IOPLUG_HW_PERIOD_BYTES,
+					     64,
 					     2 * 1024 * 1024);
 	if (rc < 0)
 		return rc;
-	rc = snd_pcm_ioplug_set_param_minmax(
-		&pcm_cras->io, SND_PCM_IOPLUG_HW_PERIODS, 1, 2048);
+	rc = snd_pcm_ioplug_set_param_minmax(&pcm_cras->io,
+					     SND_PCM_IOPLUG_HW_PERIODS,
+					     1,
+					     2048);
 	return rc;
 }
 
@@ -347,9 +366,8 @@
 	pcm_cras->fd = -1;
 	pcm_cras->io.poll_fd = -1;
 	pcm_cras->channels = 2;
-	pcm_cras->direction = (stream == SND_PCM_STREAM_PLAYBACK) ?
-				      CRAS_STREAM_OUTPUT :
-				      CRAS_STREAM_INPUT;
+	pcm_cras->direction = (stream == SND_PCM_STREAM_PLAYBACK)
+				? CRAS_STREAM_OUTPUT : CRAS_STREAM_INPUT;
 
 	rc = cras_client_create(&pcm_cras->client);
 	if (rc != 0 || pcm_cras->client == NULL) {
@@ -358,8 +376,8 @@
 		return rc;
 	}
 
-	pcm_cras->areas =
-		calloc(pcm_cras->channels, sizeof(snd_pcm_channel_area_t));
+	pcm_cras->areas = calloc(pcm_cras->channels,
+				 sizeof(snd_pcm_channel_area_t));
 	if (pcm_cras->areas == NULL) {
 		snd_pcm_cras_free(pcm_cras);
 		return -ENOMEM;
@@ -397,6 +415,7 @@
 	return 0;
 }
 
+
 SND_PCM_PLUGIN_DEFINE_FUNC(cras)
 {
 	return snd_pcm_cras_open(pcmp, name, stream, mode);
diff --git a/cras/src/common/a2dp-codecs.h b/cras/src/common/a2dp-codecs.h
index 006d9fe..3dc31cb 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_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_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_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_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 {
 	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 b21987e..716dab1 100644
--- a/cras/src/common/array.h
+++ b/cras/src/common/array.h
@@ -27,7 +27,7 @@
 	ARRAY_APPEND(&a, 1.0);
 	*ARRAY_APPEND_ZERO(&a) = 2.0;
 
-	ARRAY_ELEMENT_FOREACH(&a, i, p) {
+	FOR_ARRAY_ELEMENT(&a, i, p) {
 		printf("%f\n", *p);  // prints 1.0 2.0
 	}
 
@@ -37,44 +37,43 @@
 */
 
 /* 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_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_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 */
@@ -88,26 +87,28 @@
 
 /* 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 FOR_ARRAY_ELEMENT(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 155b5e0..215911d 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_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;
@@ -65,12 +65,3 @@
 struct sco_options {
 	uint16_t mtu;
 };
-
-#define SOL_BLUETOOTH 274
-
-#define BT_VOICE 11
-struct bt_voice {
-	uint16_t setting;
-};
-
-#define BT_VOICE_TRANSPARENT 0x0003
diff --git a/cras/src/common/byte_buffer.h b/cras/src/common/byte_buffer.h
index dd9cb2d..2470d26 100644
--- a/cras/src/common/byte_buffer.h
+++ b/cras/src/common/byte_buffer.h
@@ -23,8 +23,8 @@
 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;
@@ -66,15 +66,6 @@
 	return buf->used_size - buf->read_idx;
 }
 
-/* Adjust readable size to given value. Use with caution. */
-static inline unsigned int buf_adjust_readable(struct byte_buffer *buf,
-					       size_t readable)
-{
-	buf->level = MIN(readable, buf->used_size);
-	buf->write_idx = (buf->read_idx + buf->level) % buf->used_size;
-	return 0;
-}
-
 static inline unsigned int buf_queued(struct byte_buffer *buf)
 {
 	return buf->level;
diff --git a/cras/src/common/cras_audio_format.c b/cras/src/common/cras_audio_format.c
index f504dfc..e25c20c 100644
--- a/cras/src/common/cras_audio_format.c
+++ b/cras/src/common/cras_audio_format.c
@@ -10,22 +10,24 @@
 
 #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. */
@@ -77,7 +79,7 @@
 	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;
@@ -100,7 +102,7 @@
 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);
 }
@@ -127,9 +129,11 @@
 	 * 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
@@ -144,7 +148,7 @@
 				    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 47bb5c5..acef686 100644
--- a/cras/src/common/cras_audio_format.h
+++ b/cras/src/common/cras_audio_format.h
@@ -21,25 +21,25 @@
 
 /* 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,32 +88,31 @@
  * 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.
@@ -127,8 +126,8 @@
 
 /* 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++)
@@ -152,7 +151,7 @@
 					 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 33e9f60..96a2de0 100644
--- a/cras/src/common/cras_checksum.c
+++ b/cras/src/common/cras_checksum.c
@@ -13,49 +13,58 @@
 #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 335b784..29e9fa1 100644
--- a/cras/src/common/cras_config.c
+++ b/cras/src/common/cras_config.c
@@ -8,8 +8,6 @@
 #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
@@ -17,33 +15,3 @@
 	 * 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 8b1e613..c1731c7 100644
--- a/cras/src/common/cras_config.h
+++ b/cras/src/common/cras_config.h
@@ -6,21 +6,12 @@
 #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. */
@@ -28,15 +19,4 @@
 /* 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 9ad9448..5304f40 100644
--- a/cras/src/common/cras_file_wait.c
+++ b/cras/src/common/cras_file_wait.c
@@ -84,8 +84,7 @@
 {
 	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 : "");
@@ -106,9 +105,9 @@
 		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;
@@ -147,8 +146,8 @@
 			       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;
@@ -158,19 +157,16 @@
 		} 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) {
@@ -180,7 +176,7 @@
 
 	/* 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;
 	}
@@ -203,7 +199,7 @@
 		/* 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) {
@@ -229,9 +225,10 @@
 			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;
@@ -259,7 +256,7 @@
 
 		/* 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);
@@ -270,7 +267,8 @@
 	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)
@@ -285,8 +283,8 @@
 
 	/* 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;
@@ -300,8 +298,8 @@
 	 * 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);
@@ -309,11 +307,9 @@
 	/* 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);
-		return rc;
-	}
-
-	*file_wait_out = file_wait;
-	return 0;
+	else
+		*file_wait_out = file_wait;
+	return rc;
 }
diff --git a/cras/src/common/cras_file_wait.h b/cras/src/common/cras_file_wait.h
index e9ec3ad..2803582 100644
--- a/cras/src/common/cras_file_wait.h
+++ b/cras/src/common/cras_file_wait.h
@@ -17,7 +17,7 @@
 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,10 +73,11 @@
  *    - 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.
  *
@@ -104,7 +105,7 @@
  *                cras_file_wait_start().
  *
  * Returns:
- *    - 0 for success, negative on error.
+ *    - 0 for success, non-zero 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 5317dde..bc3c18c 100644
--- a/cras/src/common/cras_iodev_info.h
+++ b/cras/src/common/cras_iodev_info.h
@@ -19,11 +19,14 @@
  *    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.
@@ -36,25 +39,25 @@
  *    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 195965b..c08d2bb 100644
--- a/cras/src/common/cras_messages.h
+++ b/cras/src/common/cras_messages.h
@@ -16,10 +16,11 @@
 
 /* Rev when message format changes. If new messages are added, or message ID
  * values change. */
-#define CRAS_PROTO_VER 5
+#define CRAS_PROTO_VER 2
 #define CRAS_SERV_MAX_MSG_SIZE 256
 #define CRAS_CLIENT_MAX_MSG_SIZE 256
-#define CRAS_MAX_HOTWORD_MODELS 243
+#define CRAS_HOTWORD_NAME_MAX_SIZE 8
+#define CRAS_MAX_HOTWORD_MODELS 244
 #define CRAS_MAX_REMIX_CHANNELS 32
 #define CRAS_MAX_TEST_DATA_LEN 224
 #define CRAS_AEC_DUMP_FILE_NAME_LEN 128
@@ -55,9 +56,6 @@
 	CRAS_SERVER_REGISTER_NOTIFICATION,
 	CRAS_SERVER_SET_AEC_DUMP,
 	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,20 +75,18 @@
 	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;
 };
@@ -100,7 +96,7 @@
  */
 
 /* 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 */
@@ -112,18 +108,15 @@
 	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.
+ * Old version of connect message without 'effects' member 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.
+ * Expected to have proto_version set to 1.
+ * TODO(hychao): remove when all clients migrate to latest libcras.
  */
-struct __attribute__((__packed__)) cras_connect_message_old {
+struct __attribute__ ((__packed__)) cras_connect_message_old {
 	struct cras_server_message header;
 	uint32_t proto_version;
 	enum CRAS_STREAM_DIRECTION direction; /* input/output/loopback */
@@ -134,16 +127,18 @@
 	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. */
 };
 
-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)
+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)
 {
 	m->proto_version = CRAS_PROTO_VER;
 	m->direction = direction;
@@ -155,20 +150,18 @@
 	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;
@@ -176,19 +169,20 @@
 }
 
 /* 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;
@@ -196,13 +190,13 @@
 }
 
 /* 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;
@@ -210,41 +204,45 @@
 }
 
 /* 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;
@@ -252,15 +250,17 @@
 }
 
 /* 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;
@@ -270,14 +270,15 @@
 }
 
 /* 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;
@@ -286,15 +287,15 @@
 }
 
 /* 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;
@@ -303,15 +304,15 @@
 }
 
 /* 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;
@@ -320,71 +321,54 @@
 }
 
 /* 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 cras_server_message header;
-};
-
-static inline void cras_fill_dump_bt(struct cras_dump_bt *m)
-{
-	m->header.id = CRAS_SERVER_DUMP_BT;
-	m->header.length = sizeof(*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;
 };
@@ -398,7 +382,7 @@
 }
 
 /* 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;
@@ -431,16 +415,17 @@
  * 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);
@@ -449,14 +434,14 @@
 }
 
 /* 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);
@@ -464,33 +449,34 @@
 }
 
 /* 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_MAX_HOTWORD_MODEL_NAME_SIZE];
+	char model_name[CRAS_HOTWORD_NAME_MAX_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_MAX_HOTWORD_MODEL_NAME_SIZE);
+	memcpy(m->model_name, model_name, CRAS_HOTWORD_NAME_MAX_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);
@@ -499,38 +485,25 @@
 }
 
 /* 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 cras_server_message header;
-	unsigned int enabled;
+struct __attribute__ ((__packed__)) cras_register_notification {
+		struct cras_server_message header;
+		uint32_t msg_id;
+		int do_register;
 };
-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;
-};
-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);
@@ -543,12 +516,13 @@
  */
 
 /* 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;
@@ -558,109 +532,114 @@
 /*
  * Reply from server that a stream has been successfully added.
  * Two file descriptors are added, input shm followed by out shm.
- *
- * 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;
 	struct cras_audio_format_packed format;
-	uint32_t samples_shm_size;
+	uint32_t shm_max_size;
 	uint64_t effects;
 };
-
-static inline void
-cras_fill_client_stream_connected(struct cras_client_stream_connected *m,
-				  int err, cras_stream_id_t stream_id,
-				  struct cras_audio_format *format,
-				  size_t samples_shm_size, uint64_t effects)
+/*
+ * Old version of stream connected message without effects defined.
+ * TODO(hychao): remove when all clients migrate to latest libcras.
+ */
+struct __attribute__ ((__packed__)) cras_client_stream_connected_old {
+	struct cras_client_message header;
+	int32_t err;
+	cras_stream_id_t stream_id;
+	struct cras_audio_format_packed format;
+	uint32_t shm_max_size;
+};
+static inline void cras_fill_client_stream_connected(
+		struct cras_client_stream_connected *m,
+		int err,
+		cras_stream_id_t stream_id,
+		struct cras_audio_format *format,
+		size_t shm_max_size,
+		uint64_t effects)
 {
 	m->err = err;
 	m->stream_id = stream_id;
 	pack_cras_audio_format(&m->format, format);
-	m->samples_shm_size = samples_shm_size;
+	m->shm_max_size = shm_max_size;
 	m->effects = effects;
 	m->header.id = CRAS_CLIENT_STREAM_CONNECTED;
 	m->header.length = sizeof(struct cras_client_stream_connected);
 }
+static inline void cras_fill_client_stream_connected_old(
+		struct cras_client_stream_connected_old *m,
+		int err,
+		cras_stream_id_t stream_id,
+		struct cras_audio_format *format,
+		size_t shm_max_size)
+{
+	m->err = err;
+	m->stream_id = stream_id;
+	pack_cras_audio_format(&m->format, format);
+	m->shm_max_size = shm_max_size;
+	m->header.id = CRAS_CLIENT_STREAM_CONNECTED;
+	m->header.length = sizeof(struct cras_client_stream_connected_old);
+}
 
 /* Sent from server to client when audio debug information is requested. */
-struct __attribute__((__packed__)) cras_client_audio_debug_info_ready {
+struct 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 __attribute__((__packed__)) cras_client_get_hotword_models_ready {
+struct cras_client_get_hotword_models_ready {
 	struct cras_client_message header;
 	int32_t hotword_models_size;
-	uint8_t hotword_models[CRAS_MAX_HOTWORD_MODELS + 1];
+	uint8_t hotword_models[CRAS_MAX_HOTWORD_MODELS];
 };
 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);
+	m->header.length = sizeof(*m) + hotword_models_size;
 	m->hotword_models_size = 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';
-	}
+	memcpy(m->hotword_models, hotword_models, hotword_models_size);
 }
 
 /* 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);
@@ -668,9 +647,9 @@
 	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);
@@ -679,25 +658,25 @@
 	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);
@@ -705,32 +684,35 @@
 	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);
@@ -738,14 +720,15 @@
 	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);
@@ -763,7 +746,7 @@
 	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 b318fb4..dc5957a 100644
--- a/cras/src/common/cras_metrics.c
+++ b/cras/src/common/cras_metrics.c
@@ -16,17 +16,19 @@
 
 	syslog(LOG_DEBUG, "UMA event: %s", event);
 	handle = CMetricsLibraryNew();
+	CMetricsLibraryInit(handle);
 	CMetricsLibrarySendCrosEventToUMA(handle, 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;
 
 	syslog(LOG_DEBUG, "UMA name: %s", name);
 	handle = CMetricsLibraryNew();
+	CMetricsLibraryInit(handle);
 	CMetricsLibrarySendToUMA(handle, name, sample, min, max, nbuckets);
 	CMetricsLibraryDelete(handle);
 }
@@ -37,6 +39,7 @@
 
 	syslog(LOG_DEBUG, "UMA name: %s", name);
 	handle = CMetricsLibraryNew();
+	CMetricsLibraryInit(handle);
 	CMetricsLibrarySendSparseToUMA(handle, name, sample);
 	CMetricsLibraryDelete(handle);
 }
@@ -45,8 +48,8 @@
 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 814b3dd..82c1d21 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 70dd513..108f166 100644
--- a/cras/src/common/cras_observer_ops.h
+++ b/cras/src/common/cras_observer_ops.h
@@ -17,8 +17,8 @@
 	/* 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,17 +39,19 @@
 						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 df02b3e..4c61b57 100644
--- a/cras/src/common/cras_sbc_codec.c
+++ b/cras/src/common/cras_sbc_codec.c
@@ -22,51 +22,9 @@
 	unsigned int frame_length;
 };
 
-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)
-{
-	struct cras_sbc_data *data = (struct cras_sbc_data *)codec->priv_data;
-	size_t written = 0;
-	ssize_t decoded;
-
-	/*
-	 * Proceed decode when there is buffer left in input and room in
-	 * output.
-	 */
-	decoded = sbc_decode(&data->sbc, input, input_len, output, output_len,
-			     &written);
-
-	*count = written;
-	return decoded;
-}
-
-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)
-{
-	struct cras_sbc_data *data = (struct cras_sbc_data *)codec->priv_data;
-	ssize_t written = 0;
-	ssize_t encoded;
-
-	/*
-	 * Proceed encode when input buffer has at least one input block and
-	 * there is still room in output buffer.
-	 */
-	if (input_len < data->codesize)
-		return -EINVAL;
-
-	encoded = sbc_encode(&data->sbc, input, data->codesize, output,
-			     output_len, &written);
-
-	*count = written;
-	return encoded;
-}
-
 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;
@@ -77,9 +35,12 @@
 	 * 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;
 
@@ -92,8 +53,7 @@
 
 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;
@@ -102,10 +62,13 @@
 	 * 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)
@@ -130,8 +93,9 @@
 	return data->frame_length;
 }
 
-struct cras_audio_codec *cras_msbc_codec_create()
-{
+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;
 
@@ -139,36 +103,8 @@
 	if (!codec)
 		return NULL;
 
-	codec->priv_data =
-		(struct cras_sbc_data *)calloc(1, sizeof(struct cras_sbc_data));
-	if (!codec->priv_data) {
-		free(codec);
-		return NULL;
-	}
-
-	data = (struct cras_sbc_data *)codec->priv_data;
-	sbc_init_msbc(&data->sbc, 0L);
-	data->codesize = sbc_get_codesize(&data->sbc);
-	data->frame_length = sbc_get_frame_length(&data->sbc);
-
-	codec->decode = cras_msbc_decode;
-	codec->encode = cras_msbc_encode;
-	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 *codec;
-	struct cras_sbc_data *data;
-
-	codec = (struct cras_audio_codec *)calloc(1, sizeof(*codec));
-	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 322c45b..1c17f39 100644
--- a/cras/src/common/cras_sbc_codec.h
+++ b/cras/src/common/cras_sbc_codec.h
@@ -19,13 +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);
-
-/* Creates an mSBC codec, which is a version of SBC codec used for
- * wideband speech mode of HFP. */
-struct cras_audio_codec *cras_msbc_codec_create();
+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);
 
 /* Destroys an sbc codec.
  * Args:
diff --git a/cras/src/common/cras_selinux_helper.c b/cras/src/common/cras_selinux_helper.c
index ddacc6a..59717bb 100644
--- a/cras/src/common/cras_selinux_helper.c
+++ b/cras/src/common/cras_selinux_helper.c
@@ -6,7 +6,6 @@
 
 #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 3e6c2b7..bf42347 100644
--- a/cras/src/common/cras_shm.c
+++ b/cras/src/common/cras_shm.c
@@ -14,174 +14,16 @@
 #include <syslog.h>
 #include <stdio.h>
 #include <string.h>
-#include <unistd.h>
 
 #include "cras_shm.h"
 
-int cras_shm_info_init(const char *stream_name, uint32_t length,
-		       struct cras_shm_info *info_out)
-{
-	struct cras_shm_info info;
-
-	if (!info_out)
-		return -EINVAL;
-
-	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)
-		return info.fd;
-
-	*info_out = info;
-
-	return 0;
-}
-
-int cras_shm_info_init_with_fd(int fd, size_t length,
-			       struct cras_shm_info *info_out)
-{
-	struct cras_shm_info info;
-
-	if (!info_out)
-		return -EINVAL;
-
-	info.name[0] = '\0';
-	info.length = length;
-	info.fd = dup(fd);
-	if (info.fd < 0)
-		return info.fd;
-
-	*info_out = info;
-
-	return 0;
-}
-
-/* Move the resources from the cras_shm_info 'from' into the cras_shm_info 'to'.
- * The owner of 'to' will be responsible for cleaning up those resources with
- * cras_shm_info_cleanup.
- */
-static int cras_shm_info_move(struct cras_shm_info *from,
-			      struct cras_shm_info *to)
-{
-	if (!from || !to)
-		return -EINVAL;
-
-	*to = *from;
-	from->fd = -1;
-	from->name[0] = '\0';
-	return 0;
-}
-
-void cras_shm_info_cleanup(struct cras_shm_info *info)
-{
-	if (!info)
-		return;
-
-	if (info->name[0] != '\0')
-		cras_shm_close_unlink(info->name, info->fd);
-	else
-		close(info->fd);
-
-	info->fd = -1;
-	info->name[0] = '\0';
-}
-
-int cras_audio_shm_create(struct cras_shm_info *header_info,
-			  struct cras_shm_info *samples_info, int samples_prot,
-			  struct cras_audio_shm **shm_out)
-{
-	struct cras_audio_shm *shm;
-	int ret;
-
-	if (!header_info || !samples_info || !shm_out) {
-		ret = -EINVAL;
-		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;
-		goto cleanup_info;
-	}
-
-	/* Move the cras_shm_info params into the new cras_audio_shm object.
-	 * The parameters are cleared, and the owner of cras_audio_shm is now
-	 * responsible for closing the fds and unlinking any associated shm
-	 * files using cras_audio_shm_destroy.
-	 *
-	 * The source pointers are updated to point to the moved structs so that
-	 * they will be properly cleaned up in the error case.
-	 */
-	ret = cras_shm_info_move(header_info, &shm->header_info);
-	if (ret)
-		goto free_shm;
-	header_info = &shm->header_info;
-
-	ret = cras_shm_info_move(samples_info, &shm->samples_info);
-	if (ret)
-		goto free_shm;
-	samples_info = &shm->samples_info;
-
-	shm->header = mmap(NULL, header_info->length, PROT_READ | PROT_WRITE,
-			   MAP_SHARED, 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;
-	}
-
-	shm->samples = mmap(NULL, samples_info->length, samples_prot,
-			    MAP_SHARED, samples_info->fd, 0);
-	if (shm->samples == (uint8_t *)-1) {
-		ret = errno;
-		syslog(LOG_ERR,
-		       "cras_shm: mmap failed to map shm for samples.");
-		goto unmap_header;
-	}
-
-	cras_shm_set_volume_scaler(shm, 1.0);
-
-	*shm_out = shm;
-	return 0;
-
-unmap_header:
-	munmap(shm->header, shm->header_info.length);
-free_shm:
-	free(shm);
-cleanup_info:
-	cras_shm_info_cleanup(samples_info);
-	cras_shm_info_cleanup(header_info);
-	return ret;
-}
-
-void cras_audio_shm_destroy(struct cras_audio_shm *shm)
-{
-	if (!shm)
-		return;
-
-	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);
-}
-
 /* Set the correct SELinux label for SHM fds. */
 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;
@@ -196,8 +38,8 @@
 	}
 
 	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);
@@ -206,7 +48,7 @@
 
 #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;
 
@@ -216,32 +58,33 @@
 	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));
-	}
-	return 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_create_region %s: %s\n",
 		       name, strerror(-fd));
 	}
 	return fd;
 }
 
-void cras_shm_close_unlink(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",
+		       name, strerror(-fd));
+	}
+	return 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;
@@ -249,15 +92,15 @@
 	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;
 	}
 
@@ -266,7 +109,7 @@
 	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);
@@ -279,7 +122,7 @@
 	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);
@@ -287,7 +130,9 @@
 
 #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);
@@ -295,8 +140,9 @@
 		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 f9c9392..df5dfd8 100644
--- a/cras/src/common/cras_shm.h
+++ b/cras/src/common/cras_shm.h
@@ -8,7 +8,6 @@
 
 #include <assert.h>
 #include <stdint.h>
-#include <sys/mman.h>
 #include <sys/param.h>
 
 #include "cras_types.h"
@@ -22,12 +21,12 @@
  *  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;
 };
 
-/* Structure containing stream metadata shared between client and server.
+/* Structure that is shared as shm between client and server.
  *
  *  config - Size config data.  A copy of the config shared with clients.
  *  read_buf_idx - index of the current buffer to read from (0 or 1 if double
@@ -44,10 +43,10 @@
  *  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.
- *  buffer_offset - Offset of each buffer from start of samples area.
- *                  Valid range: 0 <= buffer_offset <= shm->samples_info.length
+ *  samples - Audio data - a double buffered area that is used to exchange
+ *    audio samples.
  */
-struct __attribute__((__packed__)) cras_audio_shm_header {
+struct __attribute__ ((__packed__)) cras_audio_shm_area {
 	struct cras_audio_shm_config config;
 	uint32_t read_buf_idx; /* use buffer A or B */
 	uint32_t write_buf_idx;
@@ -59,174 +58,65 @@
 	int32_t callback_pending;
 	uint32_t num_overruns;
 	struct cras_timespec ts;
-	uint32_t buffer_offset[CRAS_NUM_SHM_BUFFERS];
+	uint8_t samples[];
 };
 
-/* Returns the number of bytes needed to hold a cras_audio_shm_header. */
-static inline uint32_t cras_shm_header_size()
-{
-	return sizeof(struct cras_audio_shm_header);
-}
-
-/* Returns the number of bytes needed to hold the samples area for an audio
- * shm with the given used_size */
-static inline uint32_t cras_shm_calculate_samples_size(uint32_t used_size)
-{
-	return used_size * CRAS_NUM_SHM_BUFFERS;
-}
-
-/* Holds identifiers for a shm segment. All valid cras_shm_info objects will
- * have an fd and a length, and they may have the name of the shm file as well.
- *
- *  fd - File descriptor to access shm (shared between client/server).
- *  name - Name of the shm area. May be empty.
- *  length - Size of the shm region.
- */
-struct cras_shm_info {
-	int fd;
-	char name[NAME_MAX];
-	size_t length;
-};
-
-/* Initializes a cras_shm_info to be used as the backing shared memory for a
- * cras_audio_shm.
- *
- * shm_name - the name of the shm area to create.
- * length - the length of the shm area to create.
- * info_out - pointer where the created cras_shm_info will be stored.
- */
-int cras_shm_info_init(const char *shm_name, uint32_t length,
-		       struct cras_shm_info *info_out);
-
-/* Initializes a cras_shm_info to be used as the backing shared memory for a
- * cras_audio_shm.
- *
- * fd - file descriptor for the shm to be used. fd must be closed after
- *      calling this function.
- * length - the size of the shm referenced by fd.
- * info_out - pointer where the created cras_shm_info will be stored.
- */
-int cras_shm_info_init_with_fd(int fd, size_t length,
-			       struct cras_shm_info *info_out);
-
-/* Cleans up the resources for a cras_shm_info returned from cras_shm_info_init.
- *
- * info - the cras_shm_info to cleanup.
- */
-void cras_shm_info_cleanup(struct cras_shm_info *info);
-
-/* Structure that holds the config for and a pointer to the audio shm header and
- * samples area.
+/* Structure that holds the config for and a pointer to the audio shm area.
  *
  *  config - Size config data, kept separate so it can be checked.
- *  header_info - fd, name, and length of shm containing header.
- *  header - Shm region containing audio metadata
- *  samples_info - fd, name, and length of shm containing samples.
- *  samples - Shm region containing audio data.
+ *  area - Acutal shm region that is shared.
  */
 struct cras_audio_shm {
 	struct cras_audio_shm_config config;
-	struct cras_shm_info header_info;
-	struct cras_audio_shm_header *header;
-	struct cras_shm_info samples_info;
-	uint8_t *samples;
+	struct cras_audio_shm_area *area;
 };
 
-/* Sets up a cras_audio_shm given info about the shared memory to use
- *
- * header_info - the underlying shm area to use for the header. The shm
- *               will be managed by the created cras_audio_shm object.
- *               The header_info parameter will be returned to an uninitialized
- *               state, and the client need not call cras_shm_info_destroy.
- * samples_info - the underlying shm area to use for the samples. The shm
- *               will be managed by the created cras_audio_shm object.
- *               The samples_info parameter will be returned to an
- *               uninitialized state, and the client need not call
- *               cras_shm_info_destroy.
- * 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, int samples_prot,
-			  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)
 {
 	assert_on_compile_is_power_of_2(CRAS_NUM_SHM_BUFFERS);
 	idx = idx & CRAS_SHM_BUFFERS_MASK;
-
-	return shm->samples + cras_shm_get_checked_buffer_offset(shm, idx);
+	return shm->area->samples + shm->config.used_size * idx;
 }
 
 /* Limit a read offset to within the buffer size. */
-static inline unsigned
-cras_shm_get_checked_read_offset(const struct cras_audio_shm *shm,
-				 uint32_t buf_idx)
+static inline
+unsigned cras_shm_check_read_offset(const struct cras_audio_shm *shm,
+				    unsigned offset)
 {
-	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
+	/* The 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 (read_offset > shm->config.used_size)
+	if (offset > shm->config.used_size)
 		return 0;
-	if (buffer_offset + read_offset > shm->samples_info.length)
-		return 0;
-	return read_offset;
+	return offset;
 }
 
 /* Limit a write offset to within the buffer size. */
-static inline unsigned
-cras_shm_get_checked_write_offset(const struct cras_audio_shm *shm,
-				  uint32_t buf_idx)
+static inline
+unsigned cras_shm_check_write_offset(const struct cras_audio_shm *shm,
+				     unsigned 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;
+	/* 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;
 }
 
 /* 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 buf_idx = shm->header->read_buf_idx & CRAS_SHM_BUFFERS_MASK;
+	unsigned i = shm->area->read_buf_idx & CRAS_SHM_BUFFERS_MASK;
 	unsigned read_offset, write_offset;
 
-	read_offset = cras_shm_get_checked_read_offset(shm, buf_idx);
-	write_offset = cras_shm_get_checked_write_offset(shm, buf_idx);
+	read_offset =
+		cras_shm_check_read_offset(shm, shm->area->read_offset[i]);
+	write_offset =
+		cras_shm_check_write_offset(shm, shm->area->write_offset[i]);
 
 	if (read_offset > write_offset)
 		return 0;
@@ -235,33 +125,35 @@
 }
 
 /* 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;
+	unsigned i = shm->area->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;
+	unsigned i = shm->area->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
 
 	return cras_shm_buff_for_idx(shm, i);
 }
 
 /* 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 buf_idx = shm->header->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
+	unsigned i = shm->area->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
 	unsigned write_offset;
 	const unsigned frame_bytes = shm->config.frame_bytes;
 	unsigned written;
 
-	write_offset = cras_shm_get_checked_write_offset(shm, buf_idx);
+	write_offset = cras_shm_check_write_offset(shm,
+						   shm->area->write_offset[i]);
 	written = write_offset / frame_bytes;
 	if (frames) {
 		if (limit_frames >= written)
@@ -270,30 +162,36 @@
 			*frames = 0;
 	}
 
-	return cras_shm_buff_for_idx(shm, buf_idx) + write_offset;
+	return cras_shm_buff_for_idx(shm, i) + 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 buf_idx = shm->area->read_buf_idx & CRAS_SHM_BUFFERS_MASK;
 	unsigned read_offset, write_offset, final_offset;
 
 	assert(frames != NULL);
 
-	read_offset = cras_shm_get_checked_read_offset(shm, buf_idx);
-	write_offset = cras_shm_get_checked_write_offset(shm, buf_idx);
+	read_offset =
+		cras_shm_check_read_offset(shm,
+					   shm->area->read_offset[buf_idx]);
+	write_offset =
+		cras_shm_check_write_offset(shm,
+					    shm->area->write_offset[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_get_checked_write_offset(shm, buf_idx);
+		write_offset = cras_shm_check_write_offset(
+				shm, shm->area->write_offset[buf_idx]);
 	}
 	if (final_offset >= write_offset) {
 		/* Past end of samples. */
@@ -314,8 +212,8 @@
 	for (i = 0; i < CRAS_NUM_SHM_BUFFERS; i++) {
 		unsigned read_offset, write_offset;
 
-		read_offset = MIN(shm->header->read_offset[i], used_size);
-		write_offset = MIN(shm->header->write_offset[i], used_size);
+		read_offset = MIN(shm->area->read_offset[i], used_size);
+		write_offset = MIN(shm->area->write_offset[i], used_size);
 
 		if (write_offset > read_offset)
 			total += write_offset - read_offset;
@@ -335,15 +233,15 @@
 }
 
 /* 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;
+	size_t buf_idx = shm->area->read_buf_idx & CRAS_SHM_BUFFERS_MASK;
 	unsigned read_offset, write_offset;
 	const unsigned used_size = shm->config.used_size;
 
-	read_offset = MIN(shm->header->read_offset[buf_idx], used_size);
-	write_offset = MIN(shm->header->write_offset[buf_idx], used_size);
+	read_offset = MIN(shm->area->read_offset[buf_idx], used_size);
+	write_offset = MIN(shm->area->write_offset[buf_idx], used_size);
 
 	if (write_offset <= read_offset)
 		return 0;
@@ -354,14 +252,14 @@
 /* Return 1 if there is an empty buffer in the list. */
 static inline int cras_shm_is_buffer_available(const struct cras_audio_shm *shm)
 {
-	size_t buf_idx = shm->header->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
+	size_t buf_idx = shm->area->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
 
-	return (shm->header->write_offset[buf_idx] == 0);
+	return (shm->area->write_offset[buf_idx] == 0);
 }
 
 /* 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))
@@ -375,145 +273,144 @@
 static inline int cras_shm_check_write_overrun(struct cras_audio_shm *shm)
 {
 	int ret = 0;
-	size_t write_buf_idx =
-		shm->header->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
+	size_t write_buf_idx = shm->area->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
 
-	if (!shm->header->write_in_progress[write_buf_idx]) {
+	if (!shm->area->write_in_progress[write_buf_idx]) {
 		unsigned int used_size = shm->config.used_size;
 
-		if (shm->header->write_offset[write_buf_idx]) {
-			shm->header->num_overruns++; /* Will over-write unread */
+		if (shm->area->write_offset[write_buf_idx]) {
+			shm->area->num_overruns++; /* Will over-write unread */
 			ret = 1;
 		}
 
 		memset(cras_shm_buff_for_idx(shm, write_buf_idx), 0, used_size);
 
-		shm->header->write_in_progress[write_buf_idx] = 1;
-		shm->header->write_offset[write_buf_idx] = 0;
+		shm->area->write_in_progress[write_buf_idx] = 1;
+		shm->area->write_offset[write_buf_idx] = 0;
 	}
 	return ret;
 }
 
 /* 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;
+	size_t buf_idx = shm->area->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
 
 	if (frames == 0)
 		return;
 
-	shm->header->write_offset[buf_idx] += frames * shm->config.frame_bytes;
-	shm->header->read_offset[buf_idx] = 0;
+	shm->area->write_offset[buf_idx] += frames * shm->config.frame_bytes;
+	shm->area->read_offset[buf_idx] = 0;
 }
 
 /* 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;
+	size_t buf_idx = shm->area->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
 
-	return shm->header->write_offset[buf_idx] / shm->config.frame_bytes;
+	return shm->area->write_offset[buf_idx] / shm->config.frame_bytes;
 }
 
 /* Signals the writing to this buffer is complete and moves to the next one. */
 static inline void cras_shm_buffer_write_complete(struct cras_audio_shm *shm)
 {
-	size_t buf_idx = shm->header->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
+	size_t buf_idx = shm->area->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
 
-	shm->header->write_in_progress[buf_idx] = 0;
+	shm->area->write_in_progress[buf_idx] = 0;
 
 	assert_on_compile_is_power_of_2(CRAS_NUM_SHM_BUFFERS);
 	buf_idx = (buf_idx + 1) & CRAS_SHM_BUFFERS_MASK;
-	shm->header->write_buf_idx = buf_idx;
+	shm->area->write_buf_idx = buf_idx;
 }
 
 /* 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;
+	size_t buf_idx = shm->area->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
 
-	shm->header->write_offset[buf_idx] = frames * shm->config.frame_bytes;
-	shm->header->read_offset[buf_idx] = 0;
+	shm->area->write_offset[buf_idx] = frames * shm->config.frame_bytes;
+	shm->area->read_offset[buf_idx] = 0;
 	cras_shm_buffer_write_complete(shm);
 }
 
 /* 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 buf_idx = shm->area->read_buf_idx & CRAS_SHM_BUFFERS_MASK;
 	size_t remainder;
-	struct cras_audio_shm_header *header = shm->header;
+	struct cras_audio_shm_area *area = shm->area;
 	struct cras_audio_shm_config *config = &shm->config;
 
 	if (frames == 0)
 		return;
 
-	header->read_offset[buf_idx] += frames * config->frame_bytes;
-	if (header->read_offset[buf_idx] >= header->write_offset[buf_idx]) {
-		remainder = header->read_offset[buf_idx] -
-			    header->write_offset[buf_idx];
-		header->read_offset[buf_idx] = 0;
-		header->write_offset[buf_idx] = 0;
+	area->read_offset[buf_idx] += frames * config->frame_bytes;
+	if (area->read_offset[buf_idx] >= area->write_offset[buf_idx]) {
+		remainder = area->read_offset[buf_idx] -
+				area->write_offset[buf_idx];
+		area->read_offset[buf_idx] = 0;
+		area->write_offset[buf_idx] = 0;
 		assert_on_compile_is_power_of_2(CRAS_NUM_SHM_BUFFERS);
 		buf_idx = (buf_idx + 1) & CRAS_SHM_BUFFERS_MASK;
-		if (remainder < header->write_offset[buf_idx]) {
-			header->read_offset[buf_idx] = remainder;
+		if (remainder < area->write_offset[buf_idx]) {
+			area->read_offset[buf_idx] = remainder;
 		} else if (remainder) {
 			/* Read all of this buffer too. */
-			header->write_offset[buf_idx] = 0;
+			area->write_offset[buf_idx] = 0;
 			buf_idx = (buf_idx + 1) & CRAS_SHM_BUFFERS_MASK;
 		}
-		header->read_buf_idx = buf_idx;
+		area->read_buf_idx = buf_idx;
 	}
 }
 
 /* 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;
+	size_t buf_idx = shm->area->read_buf_idx & CRAS_SHM_BUFFERS_MASK;
+	struct cras_audio_shm_area *area = shm->area;
 	struct cras_audio_shm_config *config = &shm->config;
 
-	header->read_offset[buf_idx] += frames * config->frame_bytes;
-	if (header->read_offset[buf_idx] >= header->write_offset[buf_idx]) {
-		header->read_offset[buf_idx] = 0;
-		header->write_offset[buf_idx] = 0;
+	area->read_offset[buf_idx] += frames * config->frame_bytes;
+	if (area->read_offset[buf_idx] >= area->write_offset[buf_idx]) {
+		area->read_offset[buf_idx] = 0;
+		area->write_offset[buf_idx] = 0;
 		buf_idx = (buf_idx + 1) & CRAS_SHM_BUFFERS_MASK;
-		header->read_buf_idx = buf_idx;
+		area->read_buf_idx = buf_idx;
 	}
 }
 
 /* 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);
+	shm->area->volume_scaler = MIN(volume_scaler, 1.0);
 }
 
 /* Returns the volume of the stream(0.0-1.0). */
 static inline float cras_shm_get_volume_scaler(const struct cras_audio_shm *shm)
 {
-	return shm->header->volume_scaler;
+	return shm->area->volume_scaler;
 }
 
 /* Indicates that the stream should be muted/unmuted */
 static inline void cras_shm_set_mute(struct cras_audio_shm *shm, size_t mute)
 {
-	shm->header->mute = !!mute;
+	shm->area->mute = !!mute;
 }
 
 /* Returns the mute state of the stream.  0 if not muted, non-zero if muted. */
 static inline size_t cras_shm_get_mute(const struct cras_audio_shm *shm)
 {
-	return shm->header->mute;
+	return shm->area->mute;
 }
 
 /* Sets the size of a frame in bytes. */
@@ -521,8 +418,8 @@
 					    unsigned frame_bytes)
 {
 	shm->config.frame_bytes = frame_bytes;
-	if (shm->header)
-		shm->header->config.frame_bytes = frame_bytes;
+	if (shm->area)
+		shm->area->config.frame_bytes = frame_bytes;
 }
 
 /* Returns the size of a frame in bytes. */
@@ -532,41 +429,27 @@
 }
 
 /* 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;
+	shm->area->callback_pending = !!pending;
 }
 
 /* Returns non-zero if a callback is pending for this shm region. */
 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;
+	return shm->area->callback_pending;
 }
 
 /* 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);
+	if (shm->area)
+		shm->area->config.used_size = used_size;
 }
 
 /* Returns the used size of the shm region in bytes. */
@@ -581,16 +464,18 @@
 	return shm->config.used_size / shm->config.frame_bytes;
 }
 
-/* Returns the size of the samples shm region. */
-static inline unsigned cras_shm_samples_size(const struct cras_audio_shm *shm)
+/* Returns the total size of the shared memory region. */
+static inline unsigned cras_shm_total_size(const struct cras_audio_shm *shm)
 {
-	return shm->samples_info.length;
+	return cras_shm_used_size(shm) * CRAS_NUM_SHM_BUFFERS +
+			sizeof(*shm->area);
 }
 
 /* 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;
+	return shm->area->num_overruns;
 }
 
 /* Copy the config from the shm region to the local config.  Used by clients
@@ -598,7 +483,7 @@
  */
 static inline void cras_shm_copy_shared_config(struct cras_audio_shm *shm)
 {
-	memcpy(&shm->config, &shm->header->config, sizeof(shm->config));
+	memcpy(&shm->config, &shm->area->config, sizeof(shm->config));
 }
 
 /* Open a read/write shared memory area with the given name.
@@ -608,7 +493,7 @@
  * 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:
@@ -617,7 +502,7 @@
  * 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:
@@ -626,7 +511,7 @@
  * 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.
@@ -637,7 +522,9 @@
  *    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 3dd9413..d0463fa 100644
--- a/cras/src/common/cras_types.h
+++ b/cras/src/common/cras_types.h
@@ -9,7 +9,6 @@
 #ifndef CRAS_TYPES_H_
 #define CRAS_TYPES_H_
 
-#include <stdbool.h>
 #include <stdint.h>
 #include <stdlib.h>
 
@@ -17,7 +16,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;
 };
@@ -38,25 +37,12 @@
 	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.
  *
@@ -73,24 +59,6 @@
 	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
@@ -152,27 +120,12 @@
 	CRAS_STREAM_NUM_TYPES,
 };
 
-/* 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;
 
-#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)
 {
-	// clang-format off
-	switch (stream_type) {
+	switch(stream_type) {
 	ENUM_STR(CRAS_STREAM_TYPE_DEFAULT)
 	ENUM_STR(CRAS_STREAM_TYPE_MULTIMEDIA)
 	ENUM_STR(CRAS_STREAM_TYPE_VOICE_COMMUNICATION)
@@ -182,26 +135,6 @@
 	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. */
@@ -213,7 +146,7 @@
 };
 
 /* 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;
@@ -233,23 +166,22 @@
 
 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 12
+#define CRAS_HOTWORD_STRING_SIZE 256
 #define MAX_DEBUG_DEVS 4
 #define MAX_DEBUG_STREAMS 8
-#define AUDIO_THREAD_EVENT_LOG_SIZE (1024 * 6)
-#define CRAS_BT_EVENT_LOG_SIZE 1024
+#define AUDIO_THREAD_EVENT_LOG_SIZE (1024*6)
 
 /* There are 8 bits of space for events. */
 enum AUDIO_THREAD_LOG_EVENTS {
@@ -276,8 +208,6 @@
 	AUDIO_THREAD_CAPTURE_POST,
 	AUDIO_THREAD_CAPTURE_WRITE,
 	AUDIO_THREAD_CONV_COPY,
-	AUDIO_THREAD_STREAM_FETCH_PENDING,
-	AUDIO_THREAD_STREAM_RESCHEDULE,
 	AUDIO_THREAD_STREAM_SLEEP_TIME,
 	AUDIO_THREAD_STREAM_SLEEP_ADJUST,
 	AUDIO_THREAD_STREAM_SKIP_CB,
@@ -294,37 +224,9 @@
 	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. */
-enum CRAS_BT_LOG_EVENTS {
-	BT_ADAPTER_ADDED,
-	BT_ADAPTER_REMOVED,
-	BT_AUDIO_GATEWAY_INIT,
-	BT_AUDIO_GATEWAY_START,
-	BT_AVAILABLE_CODECS,
-	BT_A2DP_CONFIGURED,
-	BT_A2DP_START,
-	BT_A2DP_SUSPENDED,
-	BT_CODEC_SELECTION,
-	BT_DEV_CONNECTED_CHANGE,
-	BT_DEV_CONN_WATCH_CB,
-	BT_DEV_SUSPEND_CB,
-	BT_HFP_NEW_CONNECTION,
-	BT_HFP_REQUEST_DISCONNECT,
-	BT_HFP_SUPPORTED_FEATURES,
-	BT_HSP_NEW_CONNECTION,
-	BT_HSP_REQUEST_DISCONNECT,
-	BT_NEW_AUDIO_PROFILE_AFTER_CONNECT,
-	BT_RESET,
-	BT_SCO_CONNECT,
-	BT_TRANSPORT_ACQUIRE,
-	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;
@@ -333,14 +235,13 @@
 };
 
 /* Ring buffer of log events from the audio thread. */
-struct __attribute__((__packed__)) audio_thread_event_log {
-	uint64_t write_pos;
-	uint64_t sync_write_pos;
+struct __attribute__ ((__packed__)) audio_thread_event_log {
+	uint32_t 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;
@@ -353,19 +254,13 @@
 	uint32_t num_underruns;
 	uint32_t num_severe_underruns;
 	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;
@@ -374,18 +269,12 @@
 	uint32_t num_channels;
 	uint32_t longest_fetch_sec;
 	uint32_t longest_fetch_nsec;
-	uint32_t num_missed_cb;
 	uint32_t num_overruns;
-	uint32_t is_pinned;
-	uint32_t pinned_dev_idx;
-	uint32_t runtime_sec;
-	uint32_t runtime_nsec;
-	double stream_volume;
 	int8_t channel_layout[CRAS_CH_MAX];
 };
 
 /* 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];
@@ -393,23 +282,6 @@
 	struct audio_thread_event_log log;
 };
 
-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 {
-	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 cras_bt_event_log bt_log;
-};
-
 /*
  * All event enums should be less then AUDIO_THREAD_EVENT_TYPE_COUNT,
  * or they will be ignored by the handler.
@@ -419,14 +291,13 @@
 	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;
@@ -435,9 +306,9 @@
 /*
  * 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;
 };
 
@@ -485,14 +356,10 @@
  *    non_empty_status - Whether any non-empty audio is being
  *        played/captured.
  *    aec_supported - Flag to indicate if system aec is supported.
- *    aec_group_id  - Group ID for the system aec to use for separating aec
- *        tunings.
  *    snapshot_buffer - ring buffer for storing audio thread snapshots.
- *    bt_debug_info - ring buffer for storing bluetooth event logs.
- *    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;
@@ -525,16 +392,12 @@
 	int32_t default_output_buffer_size;
 	int32_t non_empty_status;
 	int32_t aec_supported;
-	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,
 };
@@ -556,7 +419,7 @@
 	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;
@@ -576,12 +439,6 @@
 	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. */
@@ -598,8 +455,6 @@
 	/* 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 28570bf..bcc513e 100644
--- a/cras/src/common/cras_util.c
+++ b/cras/src/common/cras_util.c
@@ -30,7 +30,7 @@
 
 	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,8 +48,7 @@
 	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;
 }
@@ -65,8 +64,8 @@
 	 */
 	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;
 }
@@ -98,7 +97,7 @@
 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;
@@ -122,8 +121,6 @@
 	memcpy(CMSG_DATA(cmsg), fd, sizeof(*fd) * num_fds);
 
 	rc = sendmsg(sockfd, &msg, 0);
-	if (rc == -1)
-		rc = -errno;
 	free(control);
 	return rc;
 }
@@ -131,7 +128,7 @@
 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;
@@ -159,17 +156,15 @@
 
 	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));
-			goto exit;
+			break;
 		}
 	}
 
-	// If we reach here, we did not find any file descriptors.
-	*num_fds = 0;
 exit:
 	free(control);
 	return rc;
@@ -204,7 +199,8 @@
 	rc = ppoll(fds, nfds, timeout, sigmask);
 	if (rc == 0 && timeout) {
 		rc = -ETIMEDOUT;
-	} else if (rc < 0) {
+	}
+	else if (rc < 0) {
 		rc = -errno;
 	}
 
@@ -233,12 +229,12 @@
 	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 0103424..237cff6 100644
--- a/cras/src/common/cras_util.h
+++ b/cras/src/common/cras_util.h
@@ -15,11 +15,11 @@
 
 #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,7 +36,8 @@
 }
 
 /* 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;
@@ -45,7 +46,8 @@
 }
 
 /* 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;
@@ -55,8 +57,8 @@
 }
 
 /* Converts a timespec duration to a frame count. */
-static inline uint64_t cras_time_to_frames(const struct timespec *t,
-					   unsigned int rate)
+static inline unsigned int cras_time_to_frames(const struct timespec *t,
+					       unsigned int rate)
 {
 	return t->tv_nsec * (uint64_t)rate / 1000000000 + rate * t->tv_sec;
 }
@@ -101,7 +103,8 @@
 	}
 }
 
-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;
@@ -136,7 +139,7 @@
 				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 */
@@ -144,7 +147,7 @@
 				 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.
@@ -161,21 +164,15 @@
 	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. */
-static inline uint64_t cras_frames_since_time(const struct timespec *beg,
-					      unsigned int rate)
+static inline unsigned int cras_frames_since_time(const struct timespec *beg,
+						  unsigned int rate)
 {
 	struct timespec now, time_since;
 
@@ -211,7 +208,7 @@
  *    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 a6a3227..7517564 100644
--- a/cras/src/common/dumper.h
+++ b/cras/src/common/dumper.h
@@ -15,7 +15,7 @@
 /* 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 d9361f0..2707b55 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,133 +26,180 @@
 	}
 }
 
+
 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;
 }
 
@@ -161,7 +208,7 @@
 	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;
 }
 
@@ -180,20 +227,20 @@
 /* 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] +
@@ -202,21 +249,23 @@
 		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;
 	}
 
@@ -224,48 +273,40 @@
 	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] = {
@@ -275,14 +316,16 @@
 	"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: ",
@@ -322,7 +365,8 @@
 	}
 }
 
-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) ||
@@ -339,7 +383,7 @@
 		"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 " : "",
@@ -349,7 +393,7 @@
 
 	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",
@@ -363,27 +407,31 @@
 			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)]);
@@ -393,7 +441,8 @@
 	}
 
 	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));
@@ -418,7 +467,7 @@
 		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);
@@ -441,7 +490,7 @@
 		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);
@@ -453,8 +502,7 @@
 				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;
@@ -464,7 +512,8 @@
 			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];
 
@@ -486,7 +535,7 @@
 		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;
 		}
@@ -497,14 +546,15 @@
 		/* 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) &&
@@ -548,8 +598,7 @@
 		/* 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;
@@ -565,6 +614,7 @@
 	return 0;
 }
 
+
 int edid_has_hdmi_info(const unsigned char *edid_data, int ext)
 {
 	const unsigned char *edid_ext = edid_data + EDID_SIZE;
@@ -621,26 +671,26 @@
 	}
 	/* 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",
@@ -685,7 +735,7 @@
 		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");
@@ -702,30 +752,31 @@
 		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;
@@ -766,17 +817,19 @@
 			}
 			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)
 {
@@ -813,7 +866,8 @@
 		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;
@@ -823,8 +877,8 @@
 		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 b43a6bc..8ee85d6 100644
--- a/cras/src/common/edid_utils.h
+++ b/cras/src/common/edid_utils.h
@@ -5,42 +5,40 @@
 #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_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_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
@@ -147,6 +145,7 @@
 #define DBCVHDMI_IVLAT 10
 #define DBCVHDMI_IALAT 11
 
+
 #define DBCSP_ALLOC 0
 #define DBCSP_SIZE 3
 
@@ -164,9 +163,9 @@
 #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
@@ -179,8 +178,8 @@
 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);
@@ -194,7 +193,8 @@
  *    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 d0fb14a..45fddcf 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 56ac755..32cb834 100644
--- a/cras/src/common/sfh.c
+++ b/cras/src/common/sfh.c
@@ -30,54 +30,48 @@
 #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 e3ee630..a9f19b5 100644
--- a/cras/src/common/utlist.h
+++ b/cras/src/common/utlist.h
@@ -62,36 +62,36 @@
  * 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,31 +107,32 @@
 		}                                                              \
 	} 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)
@@ -209,18 +210,19 @@
 		}                                                              \
 	} 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
@@ -228,3 +230,4 @@
 #define DL_SEARCH LL_SEARCH
 
 #endif /* UTLIST_H */
+
diff --git a/cras/src/dsp/biquad.c b/cras/src/dsp/biquad.c
index 337a439..b28256d 100644
--- a/cras/src/dsp/biquad.c
+++ b/cras/src/dsp/biquad.c
@@ -12,21 +12,15 @@
 #include "biquad.h"
 
 #ifndef max
-#define max(a, b)                                                              \
-	({                                                                     \
-		__typeof__(a) _a = (a);                                        \
-		__typeof__(b) _b = (b);                                        \
-		_a > _b ? _a : _b;                                             \
-	})
+#define max(a, b) ({ __typeof__(a) _a = (a);	\
+			__typeof__(b) _b = (b);	\
+			_a > _b ? _a : _b; })
 #endif
 
 #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
 
 #ifndef M_PI
@@ -49,33 +43,34 @@
 	/* Limit cutoff to 0 to 1. */
 	cutoff = max(0.0, min(cutoff, 1.0));
 
-	if (cutoff == 1 || cutoff == 0) {
-		/* When cutoff is 1, the z-transform is 1.
-		 * When cutoff is zero, nothing gets through the filter, so set
+	if (cutoff == 1) {
+		/* When cutoff is 1, the z-transform is 1. */
+		set_coefficient(bq, 1, 0, 0, 1, 0, 0);
+	} else if (cutoff > 0) {
+		/* Compute biquad coefficients for lowpass filter */
+		resonance = max(0.0, resonance); /* can't go negative */
+		double g = pow(10.0, 0.05 * resonance);
+		double d = sqrt((4 - sqrt(16 - 16 / (g * g))) / 2);
+
+		double theta = M_PI * cutoff;
+		double sn = 0.5 * d * sin(theta);
+		double beta = 0.5 * (1 - sn) / (1 + sn);
+		double gamma = (0.5 + beta) * cos(theta);
+		double alpha = 0.25 * (0.5 + beta - gamma);
+
+		double b0 = 2 * alpha;
+		double b1 = 2 * 2 * alpha;
+		double b2 = 2 * alpha;
+		double a1 = 2 * -gamma;
+		double a2 = 2 * beta;
+
+		set_coefficient(bq, b0, b1, b2, 1, a1, a2);
+	} else {
+		/* When cutoff is zero, nothing gets through the filter, so set
 		 * coefficients up correctly.
 		 */
-		set_coefficient(bq, cutoff, 0, 0, 1, 0, 0);
-		return;
+		set_coefficient(bq, 0, 0, 0, 1, 0, 0);
 	}
-
-	/* Compute biquad coefficients for lowpass filter */
-	resonance = max(0.0, resonance); /* can't go negative */
-	double g = pow(10.0, 0.05 * resonance);
-	double d = sqrt((4 - sqrt(16 - 16 / (g * g))) / 2);
-
-	double theta = M_PI * cutoff;
-	double sn = 0.5 * d * sin(theta);
-	double beta = 0.5 * (1 - sn) / (1 + sn);
-	double gamma = (0.5 + beta) * cos(theta);
-	double alpha = 0.25 * (0.5 + beta - gamma);
-
-	double b0 = 2 * alpha;
-	double b1 = 2 * 2 * alpha;
-	double b2 = 2 * alpha;
-	double a1 = 2 * -gamma;
-	double a2 = 2 * beta;
-
-	set_coefficient(bq, b0, b1, b2, 1, a1, a2);
 }
 
 static void biquad_highpass(struct biquad *bq, double cutoff, double resonance)
@@ -83,35 +78,36 @@
 	/* Limit cutoff to 0 to 1. */
 	cutoff = max(0.0, min(cutoff, 1.0));
 
-	if (cutoff == 1 || cutoff == 0) {
-		/* When cutoff is one, the z-transform is 0. */
+	if (cutoff == 1) {
+		/* The z-transform is 0. */
+		set_coefficient(bq, 0, 0, 0, 1, 0, 0);
+	} else if (cutoff > 0) {
+		/* Compute biquad coefficients for highpass filter */
+		resonance = max(0.0, resonance); /* can't go negative */
+		double g = pow(10.0, 0.05 * resonance);
+		double d = sqrt((4 - sqrt(16 - 16 / (g * g))) / 2);
+
+		double theta = M_PI * cutoff;
+		double sn = 0.5 * d * sin(theta);
+		double beta = 0.5 * (1 - sn) / (1 + sn);
+		double gamma = (0.5 + beta) * cos(theta);
+		double alpha = 0.25 * (0.5 + beta + gamma);
+
+		double b0 = 2 * alpha;
+		double b1 = 2 * -2 * alpha;
+		double b2 = 2 * alpha;
+		double a1 = 2 * -gamma;
+		double a2 = 2 * beta;
+
+		set_coefficient(bq, b0, b1, b2, 1, a1, a2);
+	} else {
 		/* When cutoff is zero, we need to be careful because the above
 		 * gives a quadratic divided by the same quadratic, with poles
 		 * and zeros on the unit circle in the same place. When cutoff
 		 * is zero, the z-transform is 1.
 		 */
-		set_coefficient(bq, 1 - cutoff, 0, 0, 1, 0, 0);
-		return;
+		set_coefficient(bq, 1, 0, 0, 1, 0, 0);
 	}
-
-	/* Compute biquad coefficients for highpass filter */
-	resonance = max(0.0, resonance); /* can't go negative */
-	double g = pow(10.0, 0.05 * resonance);
-	double d = sqrt((4 - sqrt(16 - 16 / (g * g))) / 2);
-
-	double theta = M_PI * cutoff;
-	double sn = 0.5 * d * sin(theta);
-	double beta = 0.5 * (1 - sn) / (1 + sn);
-	double gamma = (0.5 + beta) * cos(theta);
-	double alpha = 0.25 * (0.5 + beta + gamma);
-
-	double b0 = 2 * alpha;
-	double b1 = 2 * -2 * alpha;
-	double b2 = 2 * alpha;
-	double a1 = 2 * -gamma;
-	double a2 = 2 * beta;
-
-	set_coefficient(bq, b0, b1, b2, 1, a1, a2);
 }
 
 static void biquad_bandpass(struct biquad *bq, double frequency, double Q)
@@ -122,7 +118,28 @@
 	/* Don't let Q go negative, which causes an unstable filter. */
 	Q = max(0.0, Q);
 
-	if (frequency <= 0 || frequency >= 1) {
+	if (frequency > 0 && frequency < 1) {
+		double w0 = M_PI * frequency;
+		if (Q > 0) {
+			double alpha = sin(w0) / (2 * Q);
+			double k = cos(w0);
+
+			double b0 = alpha;
+			double b1 = 0;
+			double b2 = -alpha;
+			double a0 = 1 + alpha;
+			double a1 = -2 * k;
+			double a2 = 1 - alpha;
+
+			set_coefficient(bq, b0, b1, b2, a0, a1, a2);
+		} else {
+			/* When Q = 0, the above formulas have problems. If we
+			 * look at the z-transform, we can see that the limit
+			 * as Q->0 is 1, so set the filter that way.
+			 */
+			set_coefficient(bq, 1, 0, 0, 1, 0, 0);
+		}
+	} else {
 		/* When the cutoff is zero, the z-transform approaches 0, if Q
 		 * > 0. When both Q and cutoff are zero, the z-transform is
 		 * pretty much undefined. What should we do in this case?
@@ -130,29 +147,7 @@
 		 * z-transform also approaches 0.
 		 */
 		set_coefficient(bq, 0, 0, 0, 1, 0, 0);
-		return;
 	}
-	if (Q <= 0) {
-		/* When Q = 0, the above formulas have problems. If we
-		 * look at the z-transform, we can see that the limit
-		 * as Q->0 is 1, so set the filter that way.
-		 */
-		set_coefficient(bq, 1, 0, 0, 1, 0, 0);
-		return;
-	}
-
-	double w0 = M_PI * frequency;
-	double alpha = sin(w0) / (2 * Q);
-	double k = cos(w0);
-
-	double b0 = alpha;
-	double b1 = 0;
-	double b2 = -alpha;
-	double a0 = 1 + alpha;
-	double a1 = -2 * k;
-	double a2 = 1 - alpha;
-
-	set_coefficient(bq, b0, b1, b2, a0, a1, a2);
 }
 
 static void biquad_lowshelf(struct biquad *bq, double frequency, double db_gain)
@@ -165,30 +160,28 @@
 	if (frequency == 1) {
 		/* The z-transform is a constant gain. */
 		set_coefficient(bq, A * A, 0, 0, 1, 0, 0);
-		return;
-	}
-	if (frequency <= 0) {
+	} else if (frequency > 0) {
+		double w0 = M_PI * frequency;
+		double S = 1; /* filter slope (1 is max value) */
+		double alpha = 0.5 * sin(w0) *
+			sqrt((A + 1 / A) * (1 / S - 1) + 2);
+		double k = cos(w0);
+		double k2 = 2 * sqrt(A) * alpha;
+		double a_plus_one = A + 1;
+		double a_minus_one = A - 1;
+
+		double b0 = A * (a_plus_one - a_minus_one * k + k2);
+		double b1 = 2 * A * (a_minus_one - a_plus_one * k);
+		double b2 = A * (a_plus_one - a_minus_one * k - k2);
+		double a0 = a_plus_one + a_minus_one * k + k2;
+		double a1 = -2 * (a_minus_one + a_plus_one * k);
+		double a2 = a_plus_one + a_minus_one * k - k2;
+
+		set_coefficient(bq, b0, b1, b2, a0, a1, a2);
+	} else {
 		/* When frequency is 0, the z-transform is 1. */
 		set_coefficient(bq, 1, 0, 0, 1, 0, 0);
-		return;
 	}
-
-	double w0 = M_PI * frequency;
-	double S = 1; /* filter slope (1 is max value) */
-	double alpha = 0.5 * sin(w0) * sqrt((A + 1 / A) * (1 / S - 1) + 2);
-	double k = cos(w0);
-	double k2 = 2 * sqrt(A) * alpha;
-	double a_plus_one = A + 1;
-	double a_minus_one = A - 1;
-
-	double b0 = A * (a_plus_one - a_minus_one * k + k2);
-	double b1 = 2 * A * (a_minus_one - a_plus_one * k);
-	double b2 = A * (a_plus_one - a_minus_one * k - k2);
-	double a0 = a_plus_one + a_minus_one * k + k2;
-	double a1 = -2 * (a_minus_one + a_plus_one * k);
-	double a2 = a_plus_one + a_minus_one * k - k2;
-
-	set_coefficient(bq, b0, b1, b2, a0, a1, a2);
 }
 
 static void biquad_highshelf(struct biquad *bq, double frequency,
@@ -202,30 +195,28 @@
 	if (frequency == 1) {
 		/* The z-transform is 1. */
 		set_coefficient(bq, 1, 0, 0, 1, 0, 0);
-		return;
-	}
-	if (frequency <= 0) {
+	} else if (frequency > 0) {
+		double w0 = M_PI * frequency;
+		double S = 1; /* filter slope (1 is max value) */
+		double alpha = 0.5 * sin(w0) *
+			sqrt((A + 1 / A) * (1 / S - 1) + 2);
+		double k = cos(w0);
+		double k2 = 2 * sqrt(A) * alpha;
+		double a_plus_one = A + 1;
+		double a_minus_one = A - 1;
+
+		double b0 = A * (a_plus_one + a_minus_one * k + k2);
+		double b1 = -2 * A * (a_minus_one + a_plus_one * k);
+		double b2 = A * (a_plus_one + a_minus_one * k - k2);
+		double a0 = a_plus_one - a_minus_one * k + k2;
+		double a1 = 2 * (a_minus_one - a_plus_one * k);
+		double a2 = a_plus_one - a_minus_one * k - k2;
+
+		set_coefficient(bq, b0, b1, b2, a0, a1, a2);
+	} else {
 		/* When frequency = 0, the filter is just a gain, A^2. */
 		set_coefficient(bq, A * A, 0, 0, 1, 0, 0);
-		return;
 	}
-
-	double w0 = M_PI * frequency;
-	double S = 1; /* filter slope (1 is max value) */
-	double alpha = 0.5 * sin(w0) * sqrt((A + 1 / A) * (1 / S - 1) + 2);
-	double k = cos(w0);
-	double k2 = 2 * sqrt(A) * alpha;
-	double a_plus_one = A + 1;
-	double a_minus_one = A - 1;
-
-	double b0 = A * (a_plus_one + a_minus_one * k + k2);
-	double b1 = -2 * A * (a_minus_one + a_plus_one * k);
-	double b2 = A * (a_plus_one + a_minus_one * k - k2);
-	double a0 = a_plus_one - a_minus_one * k + k2;
-	double a1 = 2 * (a_minus_one - a_plus_one * k);
-	double a2 = a_plus_one - a_minus_one * k - k2;
-
-	set_coefficient(bq, b0, b1, b2, a0, a1, a2);
 }
 
 static void biquad_peaking(struct biquad *bq, double frequency, double Q,
@@ -239,32 +230,31 @@
 
 	double A = pow(10.0, db_gain / 40);
 
-	if (frequency <= 0 || frequency >= 1) {
+	if (frequency > 0 && frequency < 1) {
+		if (Q > 0) {
+			double w0 = M_PI * frequency;
+			double alpha = sin(w0) / (2 * Q);
+			double k = cos(w0);
+
+			double b0 = 1 + alpha * A;
+			double b1 = -2 * k;
+			double b2 = 1 - alpha * A;
+			double a0 = 1 + alpha / A;
+			double a1 = -2 * k;
+			double a2 = 1 - alpha / A;
+
+			set_coefficient(bq, b0, b1, b2, a0, a1, a2);
+		} else {
+			/* When Q = 0, the above formulas have problems. If we
+			 * look at the z-transform, we can see that the limit
+			 * as Q->0 is A^2, so set the filter that way.
+			 */
+			set_coefficient(bq, A * A, 0, 0, 1, 0, 0);
+		}
+	} else {
 		/* When frequency is 0 or 1, the z-transform is 1. */
 		set_coefficient(bq, 1, 0, 0, 1, 0, 0);
-		return;
 	}
-	if (Q <= 0) {
-		/* When Q = 0, the above formulas have problems. If we
-		 * look at the z-transform, we can see that the limit
-		 * as Q->0 is A^2, so set the filter that way.
-		 */
-		set_coefficient(bq, A * A, 0, 0, 1, 0, 0);
-		return;
-	}
-
-	double w0 = M_PI * frequency;
-	double alpha = sin(w0) / (2 * Q);
-	double k = cos(w0);
-
-	double b0 = 1 + alpha * A;
-	double b1 = -2 * k;
-	double b2 = 1 - alpha * A;
-	double a0 = 1 + alpha / A;
-	double a1 = -2 * k;
-	double a2 = 1 - alpha / A;
-
-	set_coefficient(bq, b0, b1, b2, a0, a1, a2);
 }
 
 static void biquad_notch(struct biquad *bq, double frequency, double Q)
@@ -275,32 +265,31 @@
 	/* Don't let Q go negative, which causes an unstable filter. */
 	Q = max(0.0, Q);
 
-	if (frequency <= 0 || frequency >= 1) {
+	if (frequency > 0 && frequency < 1) {
+		if (Q > 0) {
+			double w0 = M_PI * frequency;
+			double alpha = sin(w0) / (2 * Q);
+			double k = cos(w0);
+
+			double b0 = 1;
+			double b1 = -2 * k;
+			double b2 = 1;
+			double a0 = 1 + alpha;
+			double a1 = -2 * k;
+			double a2 = 1 - alpha;
+
+			set_coefficient(bq, b0, b1, b2, a0, a1, a2);
+		} else {
+			/* When Q = 0, the above formulas have problems. If we
+			 * look at the z-transform, we can see that the limit
+			 * as Q->0 is 0, so set the filter that way.
+			 */
+			set_coefficient(bq, 0, 0, 0, 1, 0, 0);
+		}
+	} else {
 		/* When frequency is 0 or 1, the z-transform is 1. */
 		set_coefficient(bq, 1, 0, 0, 1, 0, 0);
-		return;
 	}
-	if (Q <= 0) {
-		/* When Q = 0, the above formulas have problems. If we
-		 * look at the z-transform, we can see that the limit
-		 * as Q->0 is 0, so set the filter that way.
-		 */
-		set_coefficient(bq, 0, 0, 0, 1, 0, 0);
-		return;
-	}
-
-	double w0 = M_PI * frequency;
-	double alpha = sin(w0) / (2 * Q);
-	double k = cos(w0);
-
-	double b0 = 1;
-	double b1 = -2 * k;
-	double b2 = 1;
-	double a0 = 1 + alpha;
-	double a1 = -2 * k;
-	double a2 = 1 - alpha;
-
-	set_coefficient(bq, b0, b1, b2, a0, a1, a2);
 }
 
 static void biquad_allpass(struct biquad *bq, double frequency, double Q)
@@ -311,33 +300,31 @@
 	/* Don't let Q go negative, which causes an unstable filter. */
 	Q = max(0.0, Q);
 
-	if (frequency <= 0 || frequency >= 1) {
+	if (frequency > 0 && frequency < 1) {
+		if (Q > 0) {
+			double w0 = M_PI * frequency;
+			double alpha = sin(w0) / (2 * Q);
+			double k = cos(w0);
+
+			double b0 = 1 - alpha;
+			double b1 = -2 * k;
+			double b2 = 1 + alpha;
+			double a0 = 1 + alpha;
+			double a1 = -2 * k;
+			double a2 = 1 - alpha;
+
+			set_coefficient(bq, b0, b1, b2, a0, a1, a2);
+		} else {
+			/* When Q = 0, the above formulas have problems. If we
+			 * look at the z-transform, we can see that the limit
+			 * as Q->0 is -1, so set the filter that way.
+			 */
+			set_coefficient(bq, -1, 0, 0, 1, 0, 0);
+		}
+	} else {
 		/* When frequency is 0 or 1, the z-transform is 1. */
 		set_coefficient(bq, 1, 0, 0, 1, 0, 0);
-		return;
 	}
-
-	if (Q <= 0) {
-		/* When Q = 0, the above formulas have problems. If we
-		 * look at the z-transform, we can see that the limit
-		 * as Q->0 is -1, so set the filter that way.
-		 */
-		set_coefficient(bq, -1, 0, 0, 1, 0, 0);
-		return;
-	}
-
-	double w0 = M_PI * frequency;
-	double alpha = sin(w0) / (2 * Q);
-	double k = cos(w0);
-
-	double b0 = 1 - alpha;
-	double b1 = -2 * k;
-	double b2 = 1 + alpha;
-	double a0 = 1 + alpha;
-	double a1 = -2 * k;
-	double a2 = 1 - alpha;
-
-	set_coefficient(bq, b0, b1, b2, a0, a1, a2);
 }
 
 void biquad_set(struct biquad *bq, enum biquad_type type, double freq, double Q,
diff --git a/cras/src/dsp/crossover.c b/cras/src/dsp/crossover.c
index 48dce89..11a8c6e 100644
--- a/cras/src/dsp/crossover.c
+++ b/cras/src/dsp/crossover.c
@@ -61,8 +61,8 @@
 	for (i = 0; i < count; i++) {
 		float x, y, z;
 		x = data0[i];
-		y = lb0 * x + lb1 * lx1 + lb2 * lx2 - la1 * ly1 - la2 * ly2;
-		z = lb0 * y + lb1 * ly1 + lb2 * ly2 - la1 * lz1 - la2 * lz2;
+		y = lb0*x + lb1*lx1 + lb2*lx2 - la1*ly1 - la2*ly2;
+		z = lb0*y + lb1*ly1 + lb2*ly2 - la1*lz1 - la2*lz2;
 		lx2 = lx1;
 		lx1 = x;
 		ly2 = ly1;
@@ -71,8 +71,8 @@
 		lz1 = z;
 		data0[i] = z;
 
-		y = hb0 * x + hb1 * hx1 + hb2 * hx2 - ha1 * hy1 - ha2 * hy2;
-		z = hb0 * y + hb1 * hy1 + hb2 * hy2 - ha1 * hz1 - ha2 * hz2;
+		y = hb0*x + hb1*hx1 + hb2*hx2 - ha1*hy1 - ha2*hy2;
+		z = hb0*y + hb1*hy1 + hb2*hy2 - ha1*hz1 - ha2*hz2;
 		hx2 = hx1;
 		hx1 = x;
 		hy2 = hy1;
@@ -134,8 +134,8 @@
 	for (i = 0; i < count; i++) {
 		float x, y, z;
 		x = data[i];
-		y = lb0 * x + lb1 * lx1 + lb2 * lx2 - la1 * ly1 - la2 * ly2;
-		z = lb0 * y + lb1 * ly1 + lb2 * ly2 - la1 * lz1 - la2 * lz2;
+		y = lb0*x + lb1*lx1 + lb2*lx2 - la1*ly1 - la2*ly2;
+		z = lb0*y + lb1*ly1 + lb2*ly2 - la1*lz1 - la2*lz2;
 		lx2 = lx1;
 		lx1 = x;
 		ly2 = ly1;
@@ -143,8 +143,8 @@
 		lz2 = lz1;
 		lz1 = z;
 
-		y = hb0 * x + hb1 * hx1 + hb2 * hx2 - ha1 * hy1 - ha2 * hy2;
-		z = hb0 * y + hb1 * hy1 + hb2 * hy2 - ha1 * hz1 - ha2 * hz2;
+		y = hb0*x + hb1*hx1 + hb2*hx2 - ha1*hy1 - ha2*hy2;
+		z = hb0*y + hb1*hy1 + hb2*hy2 - ha1*hz1 - ha2*hz2;
 		hx2 = hx1;
 		hx1 = x;
 		hy2 = hy1;
diff --git a/cras/src/dsp/crossover2.c b/cras/src/dsp/crossover2.c
index 7d7e99c..a2ea9ad 100644
--- a/cras/src/dsp/crossover2.c
+++ b/cras/src/dsp/crossover2.c
@@ -29,22 +29,21 @@
 #if defined(__ARM_NEON__)
 #include <arm_neon.h>
 static void lr42_split(struct lr42 *lp, struct lr42 *hp, int count,
-		       float *data0L, float *data0R, float *data1L,
-		       float *data1R)
+		       float *data0L, float *data0R,
+		       float *data1L, float *data1R)
 {
-	float32x4_t x1 = { lp->x1L, hp->x1L, lp->x1R, hp->x1R };
-	float32x4_t x2 = { lp->x2L, hp->x2L, lp->x2R, hp->x2R };
-	float32x4_t y1 = { lp->y1L, hp->y1L, lp->y1R, hp->y1R };
-	float32x4_t y2 = { lp->y2L, hp->y2L, lp->y2R, hp->y2R };
-	float32x4_t z1 = { lp->z1L, hp->z1L, lp->z1R, hp->z1R };
-	float32x4_t z2 = { lp->z2L, hp->z2L, lp->z2R, hp->z2R };
-	float32x4_t b0 = { lp->b0, hp->b0, lp->b0, hp->b0 };
-	float32x4_t b1 = { lp->b1, hp->b1, lp->b1, hp->b1 };
-	float32x4_t b2 = { lp->b2, hp->b2, lp->b2, hp->b2 };
-	float32x4_t a1 = { lp->a1, hp->a1, lp->a1, hp->a1 };
-	float32x4_t a2 = { lp->a2, hp->a2, lp->a2, hp->a2 };
+	float32x4_t x1 = {lp->x1L, hp->x1L, lp->x1R, hp->x1R};
+	float32x4_t x2 = {lp->x2L, hp->x2L, lp->x2R, hp->x2R};
+	float32x4_t y1 = {lp->y1L, hp->y1L, lp->y1R, hp->y1R};
+	float32x4_t y2 = {lp->y2L, hp->y2L, lp->y2R, hp->y2R};
+	float32x4_t z1 = {lp->z1L, hp->z1L, lp->z1R, hp->z1R};
+	float32x4_t z2 = {lp->z2L, hp->z2L, lp->z2R, hp->z2R};
+	float32x4_t b0 = {lp->b0, hp->b0, lp->b0, hp->b0};
+	float32x4_t b1 = {lp->b1, hp->b1, lp->b1, hp->b1};
+	float32x4_t b2 = {lp->b2, hp->b2, lp->b2, hp->b2};
+	float32x4_t a1 = {lp->a1, hp->a1, lp->a1, hp->a1};
+	float32x4_t a2 = {lp->a2, hp->a2, lp->a2, hp->a2};
 
-	// clang-format off
 	__asm__ __volatile__(
 		/* q0 = x, q1 = y, q2 = z */
 		"1:                                     \n"
@@ -96,54 +95,41 @@
 		  [a1]"w"(a1),
 		  [a2]"w"(a2)
 		: /* clobber */
-		  "q0", "q1", "q2", "memory", "cc");
-	// clang-format on
+		  "q0", "q1", "q2", "memory", "cc"
+		);
 
-	lp->x1L = x1[0];
-	lp->x1R = x1[2];
-	lp->x2L = x2[0];
-	lp->x2R = x2[2];
-	lp->y1L = y1[0];
-	lp->y1R = y1[2];
-	lp->y2L = y2[0];
-	lp->y2R = y2[2];
-	lp->z1L = z1[0];
-	lp->z1R = z1[2];
-	lp->z2L = z2[0];
-	lp->z2R = z2[2];
+	lp->x1L = x1[0]; lp->x1R = x1[2];
+	lp->x2L = x2[0]; lp->x2R = x2[2];
+	lp->y1L = y1[0]; lp->y1R = y1[2];
+	lp->y2L = y2[0]; lp->y2R = y2[2];
+	lp->z1L = z1[0]; lp->z1R = z1[2];
+	lp->z2L = z2[0]; lp->z2R = z2[2];
 
-	hp->x1L = x1[1];
-	hp->x1R = x1[3];
-	hp->x2L = x2[1];
-	hp->x2R = x2[3];
-	hp->y1L = y1[1];
-	hp->y1R = y1[3];
-	hp->y2L = y2[1];
-	hp->y2R = y2[3];
-	hp->z1L = z1[1];
-	hp->z1R = z1[3];
-	hp->z2L = z2[1];
-	hp->z2R = z2[3];
+	hp->x1L = x1[1]; hp->x1R = x1[3];
+	hp->x2L = x2[1]; hp->x2R = x2[3];
+	hp->y1L = y1[1]; hp->y1R = y1[3];
+	hp->y2L = y2[1]; hp->y2R = y2[3];
+	hp->z1L = z1[1]; hp->z1R = z1[3];
+	hp->z2L = z2[1]; hp->z2R = z2[3];
 }
 #elif defined(__SSE3__) && defined(__x86_64__)
 #include <emmintrin.h>
 static void lr42_split(struct lr42 *lp, struct lr42 *hp, int count,
-		       float *data0L, float *data0R, float *data1L,
-		       float *data1R)
+		       float *data0L, float *data0R,
+		       float *data1L, float *data1R)
 {
-	__m128 x1 = { lp->x1L, hp->x1L, lp->x1R, hp->x1R };
-	__m128 x2 = { lp->x2L, hp->x2L, lp->x2R, hp->x2R };
-	__m128 y1 = { lp->y1L, hp->y1L, lp->y1R, hp->y1R };
-	__m128 y2 = { lp->y2L, hp->y2L, lp->y2R, hp->y2R };
-	__m128 z1 = { lp->z1L, hp->z1L, lp->z1R, hp->z1R };
-	__m128 z2 = { lp->z2L, hp->z2L, lp->z2R, hp->z2R };
-	__m128 b0 = { lp->b0, hp->b0, lp->b0, hp->b0 };
-	__m128 b1 = { lp->b1, hp->b1, lp->b1, hp->b1 };
-	__m128 b2 = { lp->b2, hp->b2, lp->b2, hp->b2 };
-	__m128 a1 = { lp->a1, hp->a1, lp->a1, hp->a1 };
-	__m128 a2 = { lp->a2, hp->a2, lp->a2, hp->a2 };
+	__m128 x1 = {lp->x1L, hp->x1L, lp->x1R, hp->x1R};
+	__m128 x2 = {lp->x2L, hp->x2L, lp->x2R, hp->x2R};
+	__m128 y1 = {lp->y1L, hp->y1L, lp->y1R, hp->y1R};
+	__m128 y2 = {lp->y2L, hp->y2L, lp->y2R, hp->y2R};
+	__m128 z1 = {lp->z1L, hp->z1L, lp->z1R, hp->z1R};
+	__m128 z2 = {lp->z2L, hp->z2L, lp->z2R, hp->z2R};
+	__m128 b0 = {lp->b0, hp->b0, lp->b0, hp->b0};
+	__m128 b1 = {lp->b1, hp->b1, lp->b1, hp->b1};
+	__m128 b2 = {lp->b2, hp->b2, lp->b2, hp->b2};
+	__m128 a1 = {lp->a1, hp->a1, lp->a1, hp->a1};
+	__m128 a2 = {lp->a2, hp->a2, lp->a2, hp->a2};
 
-	// clang-format off
 	__asm__ __volatile__(
 		"1:                                     \n"
 		"movss (%[data0L]), %%xmm2              \n"
@@ -212,39 +198,27 @@
 		  [a1]"x"(a1),
 		  [a2]"x"(a2)
 		: /* clobber */
-		  "xmm0", "xmm1", "xmm2", "memory", "cc");
-	// clang-format on
+		  "xmm0", "xmm1", "xmm2", "memory", "cc"
+		);
 
-	lp->x1L = x1[0];
-	lp->x1R = x1[2];
-	lp->x2L = x2[0];
-	lp->x2R = x2[2];
-	lp->y1L = y1[0];
-	lp->y1R = y1[2];
-	lp->y2L = y2[0];
-	lp->y2R = y2[2];
-	lp->z1L = z1[0];
-	lp->z1R = z1[2];
-	lp->z2L = z2[0];
-	lp->z2R = z2[2];
+	lp->x1L = x1[0]; lp->x1R = x1[2];
+	lp->x2L = x2[0]; lp->x2R = x2[2];
+	lp->y1L = y1[0]; lp->y1R = y1[2];
+	lp->y2L = y2[0]; lp->y2R = y2[2];
+	lp->z1L = z1[0]; lp->z1R = z1[2];
+	lp->z2L = z2[0]; lp->z2R = z2[2];
 
-	hp->x1L = x1[1];
-	hp->x1R = x1[3];
-	hp->x2L = x2[1];
-	hp->x2R = x2[3];
-	hp->y1L = y1[1];
-	hp->y1R = y1[3];
-	hp->y2L = y2[1];
-	hp->y2R = y2[3];
-	hp->z1L = z1[1];
-	hp->z1R = z1[3];
-	hp->z2L = z2[1];
-	hp->z2R = z2[3];
+	hp->x1L = x1[1]; hp->x1R = x1[3];
+	hp->x2L = x2[1]; hp->x2R = x2[3];
+	hp->y1L = y1[1]; hp->y1R = y1[3];
+	hp->y2L = y2[1]; hp->y2R = y2[3];
+	hp->z1L = z1[1]; hp->z1R = z1[3];
+	hp->z2L = z2[1]; hp->z2R = z2[3];
 }
 #else
 static void lr42_split(struct lr42 *lp, struct lr42 *hp, int count,
-		       float *data0L, float *data0R, float *data1L,
-		       float *data1R)
+		       float *data0L, float *data0R,
+		       float *data1L, float *data1R)
 {
 	float lx1L = lp->x1L, lx1R = lp->x1R;
 	float lx2L = lp->x2L, lx2R = lp->x2R;
@@ -275,14 +249,10 @@
 		float xL, yL, zL, xR, yR, zR;
 		xL = data0L[i];
 		xR = data0R[i];
-		yL = lb0 * xL + lb1 * lx1L + lb2 * lx2L - la1 * ly1L -
-		     la2 * ly2L;
-		yR = lb0 * xR + lb1 * lx1R + lb2 * lx2R - la1 * ly1R -
-		     la2 * ly2R;
-		zL = lb0 * yL + lb1 * ly1L + lb2 * ly2L - la1 * lz1L -
-		     la2 * lz2L;
-		zR = lb0 * yR + lb1 * ly1R + lb2 * ly2R - la1 * lz1R -
-		     la2 * lz2R;
+		yL = lb0*xL + lb1*lx1L + lb2*lx2L - la1*ly1L - la2*ly2L;
+		yR = lb0*xR + lb1*lx1R + lb2*lx2R - la1*ly1R - la2*ly2R;
+		zL = lb0*yL + lb1*ly1L + lb2*ly2L - la1*lz1L - la2*lz2L;
+		zR = lb0*yR + lb1*ly1R + lb2*ly2R - la1*lz1R - la2*lz2R;
 		lx2L = lx1L;
 		lx2R = lx1R;
 		lx1L = xL;
@@ -298,14 +268,10 @@
 		data0L[i] = zL;
 		data0R[i] = zR;
 
-		yL = hb0 * xL + hb1 * hx1L + hb2 * hx2L - ha1 * hy1L -
-		     ha2 * hy2L;
-		yR = hb0 * xR + hb1 * hx1R + hb2 * hx2R - ha1 * hy1R -
-		     ha2 * hy2R;
-		zL = hb0 * yL + hb1 * hy1L + hb2 * hy2L - ha1 * hz1L -
-		     ha2 * hz2L;
-		zR = hb0 * yR + hb1 * hy1R + hb2 * hy2R - ha1 * hz1R -
-		     ha2 * hz2R;
+		yL = hb0*xL + hb1*hx1L + hb2*hx2L - ha1*hy1L - ha2*hy2L;
+		yR = hb0*xR + hb1*hx1R + hb2*hx2R - ha1*hy1R - ha2*hy2R;
+		zL = hb0*yL + hb1*hy1L + hb2*hy2L - ha1*hz1L - ha2*hz2L;
+		zR = hb0*yR + hb1*hy1R + hb2*hy2R - ha1*hz1R - ha2*hz2R;
 		hx2L = hx1L;
 		hx2R = hx1R;
 		hx1L = xL;
@@ -322,31 +288,19 @@
 		data1R[i] = zR;
 	}
 
-	lp->x1L = lx1L;
-	lp->x1R = lx1R;
-	lp->x2L = lx2L;
-	lp->x2R = lx2R;
-	lp->y1L = ly1L;
-	lp->y1R = ly1R;
-	lp->y2L = ly2L;
-	lp->y2R = ly2R;
-	lp->z1L = lz1L;
-	lp->z1R = lz1R;
-	lp->z2L = lz2L;
-	lp->z2R = lz2R;
+	lp->x1L = lx1L; lp->x1R = lx1R;
+	lp->x2L = lx2L;	lp->x2R = lx2R;
+	lp->y1L = ly1L;	lp->y1R = ly1R;
+	lp->y2L = ly2L;	lp->y2R = ly2R;
+	lp->z1L = lz1L;	lp->z1R = lz1R;
+	lp->z2L = lz2L;	lp->z2R = lz2R;
 
-	hp->x1L = hx1L;
-	hp->x1R = hx1R;
-	hp->x2L = hx2L;
-	hp->x2R = hx2R;
-	hp->y1L = hy1L;
-	hp->y1R = hy1R;
-	hp->y2L = hy2L;
-	hp->y2R = hy2R;
-	hp->z1L = hz1L;
-	hp->z1R = hz1R;
-	hp->z2L = hz2L;
-	hp->z2R = hz2R;
+	hp->x1L = hx1L; hp->x1R = hx1R;
+	hp->x2L = hx2L;	hp->x2R = hx2R;
+	hp->y1L = hy1L;	hp->y1R = hy1R;
+	hp->y2L = hy2L;	hp->y2R = hy2R;
+	hp->z1L = hz1L;	hp->z1R = hz1R;
+	hp->z2L = hz2L;	hp->z2R = hz2R;
 }
 #endif
 
@@ -362,19 +316,18 @@
 static void lr42_merge(struct lr42 *lp, struct lr42 *hp, int count,
 		       float *dataL, float *dataR)
 {
-	float32x4_t x1 = { lp->x1L, hp->x1L, lp->x1R, hp->x1R };
-	float32x4_t x2 = { lp->x2L, hp->x2L, lp->x2R, hp->x2R };
-	float32x4_t y1 = { lp->y1L, hp->y1L, lp->y1R, hp->y1R };
-	float32x4_t y2 = { lp->y2L, hp->y2L, lp->y2R, hp->y2R };
-	float32x4_t z1 = { lp->z1L, hp->z1L, lp->z1R, hp->z1R };
-	float32x4_t z2 = { lp->z2L, hp->z2L, lp->z2R, hp->z2R };
-	float32x4_t b0 = { lp->b0, hp->b0, lp->b0, hp->b0 };
-	float32x4_t b1 = { lp->b1, hp->b1, lp->b1, hp->b1 };
-	float32x4_t b2 = { lp->b2, hp->b2, lp->b2, hp->b2 };
-	float32x4_t a1 = { lp->a1, hp->a1, lp->a1, hp->a1 };
-	float32x4_t a2 = { lp->a2, hp->a2, lp->a2, hp->a2 };
+	float32x4_t x1 = {lp->x1L, hp->x1L, lp->x1R, hp->x1R};
+	float32x4_t x2 = {lp->x2L, hp->x2L, lp->x2R, hp->x2R};
+	float32x4_t y1 = {lp->y1L, hp->y1L, lp->y1R, hp->y1R};
+	float32x4_t y2 = {lp->y2L, hp->y2L, lp->y2R, hp->y2R};
+	float32x4_t z1 = {lp->z1L, hp->z1L, lp->z1R, hp->z1R};
+	float32x4_t z2 = {lp->z2L, hp->z2L, lp->z2R, hp->z2R};
+	float32x4_t b0 = {lp->b0, hp->b0, lp->b0, hp->b0};
+	float32x4_t b1 = {lp->b1, hp->b1, lp->b1, hp->b1};
+	float32x4_t b2 = {lp->b2, hp->b2, lp->b2, hp->b2};
+	float32x4_t a1 = {lp->a1, hp->a1, lp->a1, hp->a1};
+	float32x4_t a2 = {lp->a2, hp->a2, lp->a2, hp->a2};
 
-	// clang-format off
 	__asm__ __volatile__(
 		/* q0 = x, q1 = y, q2 = z */
 		"1:                                     \n"
@@ -421,53 +374,40 @@
 		  [a1]"w"(a1),
 		  [a2]"w"(a2)
 		: /* clobber */
-		  "q0", "q1", "q2", "memory", "cc");
-	// clang-format on
+		  "q0", "q1", "q2", "memory", "cc"
+		);
 
-	lp->x1L = x1[0];
-	lp->x1R = x1[2];
-	lp->x2L = x2[0];
-	lp->x2R = x2[2];
-	lp->y1L = y1[0];
-	lp->y1R = y1[2];
-	lp->y2L = y2[0];
-	lp->y2R = y2[2];
-	lp->z1L = z1[0];
-	lp->z1R = z1[2];
-	lp->z2L = z2[0];
-	lp->z2R = z2[2];
+	lp->x1L = x1[0]; lp->x1R = x1[2];
+	lp->x2L = x2[0]; lp->x2R = x2[2];
+	lp->y1L = y1[0]; lp->y1R = y1[2];
+	lp->y2L = y2[0]; lp->y2R = y2[2];
+	lp->z1L = z1[0]; lp->z1R = z1[2];
+	lp->z2L = z2[0]; lp->z2R = z2[2];
 
-	hp->x1L = x1[1];
-	hp->x1R = x1[3];
-	hp->x2L = x2[1];
-	hp->x2R = x2[3];
-	hp->y1L = y1[1];
-	hp->y1R = y1[3];
-	hp->y2L = y2[1];
-	hp->y2R = y2[3];
-	hp->z1L = z1[1];
-	hp->z1R = z1[3];
-	hp->z2L = z2[1];
-	hp->z2R = z2[3];
+	hp->x1L = x1[1]; hp->x1R = x1[3];
+	hp->x2L = x2[1]; hp->x2R = x2[3];
+	hp->y1L = y1[1]; hp->y1R = y1[3];
+	hp->y2L = y2[1]; hp->y2R = y2[3];
+	hp->z1L = z1[1]; hp->z1R = z1[3];
+	hp->z2L = z2[1]; hp->z2R = z2[3];
 }
 #elif defined(__SSE3__) && defined(__x86_64__)
 #include <emmintrin.h>
 static void lr42_merge(struct lr42 *lp, struct lr42 *hp, int count,
 		       float *dataL, float *dataR)
 {
-	__m128 x1 = { lp->x1L, hp->x1L, lp->x1R, hp->x1R };
-	__m128 x2 = { lp->x2L, hp->x2L, lp->x2R, hp->x2R };
-	__m128 y1 = { lp->y1L, hp->y1L, lp->y1R, hp->y1R };
-	__m128 y2 = { lp->y2L, hp->y2L, lp->y2R, hp->y2R };
-	__m128 z1 = { lp->z1L, hp->z1L, lp->z1R, hp->z1R };
-	__m128 z2 = { lp->z2L, hp->z2L, lp->z2R, hp->z2R };
-	__m128 b0 = { lp->b0, hp->b0, lp->b0, hp->b0 };
-	__m128 b1 = { lp->b1, hp->b1, lp->b1, hp->b1 };
-	__m128 b2 = { lp->b2, hp->b2, lp->b2, hp->b2 };
-	__m128 a1 = { lp->a1, hp->a1, lp->a1, hp->a1 };
-	__m128 a2 = { lp->a2, hp->a2, lp->a2, hp->a2 };
+	__m128 x1 = {lp->x1L, hp->x1L, lp->x1R, hp->x1R};
+	__m128 x2 = {lp->x2L, hp->x2L, lp->x2R, hp->x2R};
+	__m128 y1 = {lp->y1L, hp->y1L, lp->y1R, hp->y1R};
+	__m128 y2 = {lp->y2L, hp->y2L, lp->y2R, hp->y2R};
+	__m128 z1 = {lp->z1L, hp->z1L, lp->z1R, hp->z1R};
+	__m128 z2 = {lp->z2L, hp->z2L, lp->z2R, hp->z2R};
+	__m128 b0 = {lp->b0, hp->b0, lp->b0, hp->b0};
+	__m128 b1 = {lp->b1, hp->b1, lp->b1, hp->b1};
+	__m128 b2 = {lp->b2, hp->b2, lp->b2, hp->b2};
+	__m128 a1 = {lp->a1, hp->a1, lp->a1, hp->a1};
+	__m128 a2 = {lp->a2, hp->a2, lp->a2, hp->a2};
 
-	// clang-format off
 	__asm__ __volatile__(
 		"1:                                     \n"
 		"movss (%[dataL]), %%xmm2               \n"
@@ -529,34 +469,22 @@
 		  [a1]"x"(a1),
 		  [a2]"x"(a2)
 		: /* clobber */
-		  "xmm0", "xmm1", "xmm2", "memory", "cc");
-	// clang-format on
+		  "xmm0", "xmm1", "xmm2", "memory", "cc"
+		);
 
-	lp->x1L = x1[0];
-	lp->x1R = x1[2];
-	lp->x2L = x2[0];
-	lp->x2R = x2[2];
-	lp->y1L = y1[0];
-	lp->y1R = y1[2];
-	lp->y2L = y2[0];
-	lp->y2R = y2[2];
-	lp->z1L = z1[0];
-	lp->z1R = z1[2];
-	lp->z2L = z2[0];
-	lp->z2R = z2[2];
+	lp->x1L = x1[0]; lp->x1R = x1[2];
+	lp->x2L = x2[0]; lp->x2R = x2[2];
+	lp->y1L = y1[0]; lp->y1R = y1[2];
+	lp->y2L = y2[0]; lp->y2R = y2[2];
+	lp->z1L = z1[0]; lp->z1R = z1[2];
+	lp->z2L = z2[0]; lp->z2R = z2[2];
 
-	hp->x1L = x1[1];
-	hp->x1R = x1[3];
-	hp->x2L = x2[1];
-	hp->x2R = x2[3];
-	hp->y1L = y1[1];
-	hp->y1R = y1[3];
-	hp->y2L = y2[1];
-	hp->y2R = y2[3];
-	hp->z1L = z1[1];
-	hp->z1R = z1[3];
-	hp->z2L = z2[1];
-	hp->z2R = z2[3];
+	hp->x1L = x1[1]; hp->x1R = x1[3];
+	hp->x2L = x2[1]; hp->x2R = x2[3];
+	hp->y1L = y1[1]; hp->y1R = y1[3];
+	hp->y2L = y2[1]; hp->y2R = y2[3];
+	hp->z1L = z1[1]; hp->z1R = z1[3];
+	hp->z2L = z2[1]; hp->z2R = z2[3];
 }
 #else
 static void lr42_merge(struct lr42 *lp, struct lr42 *hp, int count,
@@ -591,14 +519,10 @@
 		float xL, yL, zL, xR, yR, zR;
 		xL = dataL[i];
 		xR = dataR[i];
-		yL = lb0 * xL + lb1 * lx1L + lb2 * lx2L - la1 * ly1L -
-		     la2 * ly2L;
-		yR = lb0 * xR + lb1 * lx1R + lb2 * lx2R - la1 * ly1R -
-		     la2 * ly2R;
-		zL = lb0 * yL + lb1 * ly1L + lb2 * ly2L - la1 * lz1L -
-		     la2 * lz2L;
-		zR = lb0 * yR + lb1 * ly1R + lb2 * ly2R - la1 * lz1R -
-		     la2 * lz2R;
+		yL = lb0*xL + lb1*lx1L + lb2*lx2L - la1*ly1L - la2*ly2L;
+		yR = lb0*xR + lb1*lx1R + lb2*lx2R - la1*ly1R - la2*ly2R;
+		zL = lb0*yL + lb1*ly1L + lb2*ly2L - la1*lz1L - la2*lz2L;
+		zR = lb0*yR + lb1*ly1R + lb2*ly2R - la1*lz1R - la2*lz2R;
 		lx2L = lx1L;
 		lx2R = lx1R;
 		lx1L = xL;
@@ -612,14 +536,10 @@
 		lz1L = zL;
 		lz1R = zR;
 
-		yL = hb0 * xL + hb1 * hx1L + hb2 * hx2L - ha1 * hy1L -
-		     ha2 * hy2L;
-		yR = hb0 * xR + hb1 * hx1R + hb2 * hx2R - ha1 * hy1R -
-		     ha2 * hy2R;
-		zL = hb0 * yL + hb1 * hy1L + hb2 * hy2L - ha1 * hz1L -
-		     ha2 * hz2L;
-		zR = hb0 * yR + hb1 * hy1R + hb2 * hy2R - ha1 * hz1R -
-		     ha2 * hz2R;
+		yL = hb0*xL + hb1*hx1L + hb2*hx2L - ha1*hy1L - ha2*hy2L;
+		yR = hb0*xR + hb1*hx1R + hb2*hx2R - ha1*hy1R - ha2*hy2R;
+		zL = hb0*yL + hb1*hy1L + hb2*hy2L - ha1*hz1L - ha2*hz2L;
+		zR = hb0*yR + hb1*hy1R + hb2*hy2R - ha1*hz1R - ha2*hz2R;
 		hx2L = hx1L;
 		hx2R = hx1R;
 		hx1L = xL;
@@ -636,31 +556,19 @@
 		dataR[i] = zR + lz1R;
 	}
 
-	lp->x1L = lx1L;
-	lp->x1R = lx1R;
-	lp->x2L = lx2L;
-	lp->x2R = lx2R;
-	lp->y1L = ly1L;
-	lp->y1R = ly1R;
-	lp->y2L = ly2L;
-	lp->y2R = ly2R;
-	lp->z1L = lz1L;
-	lp->z1R = lz1R;
-	lp->z2L = lz2L;
-	lp->z2R = lz2R;
+	lp->x1L = lx1L; lp->x1R = lx1R;
+	lp->x2L = lx2L;	lp->x2R = lx2R;
+	lp->y1L = ly1L;	lp->y1R = ly1R;
+	lp->y2L = ly2L;	lp->y2R = ly2R;
+	lp->z1L = lz1L;	lp->z1R = lz1R;
+	lp->z2L = lz2L;	lp->z2R = lz2R;
 
-	hp->x1L = hx1L;
-	hp->x1R = hx1R;
-	hp->x2L = hx2L;
-	hp->x2R = hx2R;
-	hp->y1L = hy1L;
-	hp->y1R = hy1R;
-	hp->y2L = hy2L;
-	hp->y2R = hy2R;
-	hp->z1L = hz1L;
-	hp->z1R = hz1R;
-	hp->z2L = hz2L;
-	hp->z2R = hz2R;
+	hp->x1L = hx1L; hp->x1R = hx1R;
+	hp->x2L = hx2L;	hp->x2R = hx2R;
+	hp->y1L = hy1L;	hp->y1R = hy1R;
+	hp->y2L = hy2L;	hp->y2R = hy2R;
+	hp->z1L = hz1L;	hp->z1R = hz1R;
+	hp->z2L = hz2L;	hp->z2R = hz2R;
 }
 #endif
 
@@ -674,16 +582,17 @@
 	}
 }
 
-void crossover2_process(struct crossover2 *xo2, int count, float *data0L,
-			float *data0R, float *data1L, float *data1R,
+void crossover2_process(struct crossover2 *xo2, int count,
+			float *data0L, float *data0R,
+			float *data1L, float *data1R,
 			float *data2L, float *data2R)
 {
 	if (!count)
 		return;
 
-	lr42_split(&xo2->lp[0], &xo2->hp[0], count, data0L, data0R, data1L,
-		   data1R);
+	lr42_split(&xo2->lp[0], &xo2->hp[0], count, data0L, data0R,
+		   data1L, data1R);
 	lr42_merge(&xo2->lp[1], &xo2->hp[1], count, data0L, data0R);
-	lr42_split(&xo2->lp[2], &xo2->hp[2], count, data1L, data1R, data2L,
-		   data2R);
+	lr42_split(&xo2->lp[2], &xo2->hp[2], count, data1L, data1R,
+		   data2L, data2R);
 }
diff --git a/cras/src/dsp/crossover2.h b/cras/src/dsp/crossover2.h
index 9afa0e8..ffabc17 100644
--- a/cras/src/dsp/crossover2.h
+++ b/cras/src/dsp/crossover2.h
@@ -64,8 +64,9 @@
  *    data1L, data1R - The place to store mid band output.
  *    data2L, data2R - The place to store high band output.
  */
-void crossover2_process(struct crossover2 *xo2, int count, float *data0L,
-			float *data0R, float *data1L, float *data1R,
+void crossover2_process(struct crossover2 *xo2, int count,
+			float *data0L, float *data0R,
+			float *data1L, float *data1R,
 			float *data2L, float *data2R);
 
 #ifdef __cplusplus
diff --git a/cras/src/dsp/dcblock.c b/cras/src/dsp/dcblock.c
index 53ba941..87379e4 100644
--- a/cras/src/dsp/dcblock.c
+++ b/cras/src/dsp/dcblock.c
@@ -6,22 +6,16 @@
 #include <stdlib.h>
 #include "dcblock.h"
 
-#define RAMP_TIME_MS 20
-
 struct dcblock {
-	float R;
-	float x_prev;
-	float y_prev;
-	float ramp_factor;
-	float ramp_increment;
-	int initialized;
+        float R;
+        float x_prev;
+        float y_prev;
 };
 
-struct dcblock *dcblock_new(float R, unsigned long sample_rate)
+struct dcblock *dcblock_new(float R)
 {
 	struct dcblock *dcblock = (struct dcblock *)calloc(1, sizeof(*dcblock));
 	dcblock->R = R;
-	dcblock->ramp_increment = 1000. / (float)(RAMP_TIME_MS * sample_rate);
 	return dcblock;
 }
 
@@ -37,31 +31,11 @@
 	float x_prev = dcblock->x_prev;
 	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;
-
-		y_prev = d;
+		data[n] = x - x_prev + R * y_prev;
+		y_prev = data[n];
 		x_prev = x;
-
-		/*
-		 * It takes a while for this DC-block filter to completely
-		 * filter out a large DC-offset, so apply a mix-in ramp to
-		 * avoid any residual jump discontinuities that can lead to
-		 * "pop" during capture.
-		 */
-		if (dcblock->ramp_factor < 1.0) {
-			d *= dcblock->ramp_factor;
-			dcblock->ramp_factor += dcblock->ramp_increment;
-		}
-
-		data[n] = d;
 	}
 	dcblock->x_prev = x_prev;
 	dcblock->y_prev = y_prev;
diff --git a/cras/src/dsp/dcblock.h b/cras/src/dsp/dcblock.h
index a2ac427..b723470 100644
--- a/cras/src/dsp/dcblock.h
+++ b/cras/src/dsp/dcblock.h
@@ -18,11 +18,8 @@
  * Create a DC blocking filter.
  *
  * Transfer fn: (1 - z^-1) / (1 - R * z^-1)
- * Args:
- *    R - DC block filter coefficient.
- *    sample_rate - The sample rate, in Hz.
  */
-struct dcblock *dcblock_new(float R, unsigned long sample_rate);
+struct dcblock *dcblock_new(float R);
 
 /* Free a DC blocking filter. */
 void dcblock_free(struct dcblock *dcblock);
diff --git a/cras/src/dsp/drc.c b/cras/src/dsp/drc.c
index 1b2639a..9f35deb 100644
--- a/cras/src/dsp/drc.c
+++ b/cras/src/dsp/drc.c
@@ -176,14 +176,15 @@
 
 	float stage_gain = drc_get_param(drc, 0, PARAM_FILTER_STAGE_GAIN);
 	float stage_ratio = drc_get_param(drc, 0, PARAM_FILTER_STAGE_RATIO);
-	float anchor_freq = drc_get_param(drc, 0, PARAM_FILTER_ANCHOR);
+	float anchor_freq = drc_get_param(drc, 0,  PARAM_FILTER_ANCHOR);
 
 	drc->emphasis_eq = eq2_new();
 	drc->deemphasis_eq = eq2_new();
 
 	for (i = 0; i < 2; i++) {
 		emphasis_stage_pair_biquads(stage_gain, anchor_freq,
-					    anchor_freq / stage_ratio, &e, &d);
+					    anchor_freq / stage_ratio,
+					    &e, &d);
 		for (j = 0; j < 2; j++) {
 			eq2_append_biquad_direct(drc->emphasis_eq, j, &e);
 			eq2_append_biquad_direct(drc->deemphasis_eq, j, &d);
@@ -229,10 +230,19 @@
 		float db_post_gain = drc_get_param(drc, i, PARAM_POST_GAIN);
 		int enabled = drc_get_param(drc, i, PARAM_ENABLED);
 
-		dk_set_parameters(&drc->kernel[i], db_threshold, db_knee, ratio,
-				  attack_time, release_time, pre_delay_time,
-				  db_post_gain, releaseZone1, releaseZone2,
-				  releaseZone3, releaseZone4);
+		dk_set_parameters(&drc->kernel[i],
+				  db_threshold,
+				  db_knee,
+				  ratio,
+				  attack_time,
+				  release_time,
+				  pre_delay_time,
+				  db_post_gain,
+				  releaseZone1,
+				  releaseZone2,
+				  releaseZone3,
+				  releaseZone4
+			);
 
 		dk_set_enabled(&drc->kernel[i], enabled);
 	}
@@ -256,7 +266,6 @@
 	int i;
 
 	if (count) {
-		// clang-format off
 		__asm__ __volatile(
 			"1:                                         \n"
 			"ld1 {v0.4s}, [%[data1]], #16               \n"
@@ -274,8 +283,8 @@
 			  [count]"+r"(count)
 			: /* input */
 			: /* clobber */
-			  "v0", "v1", "v2", "memory", "cc");
-		// clang-format on
+			  "v0", "v1", "v2", "memory", "cc"
+			);
 	}
 
 	n &= 3;
@@ -289,7 +298,6 @@
 	int i;
 
 	if (count) {
-		// clang-format off
 		__asm__ __volatile(
 			"1:                                         \n"
 			"vld1.32 {q0}, [%[data1]]!                  \n"
@@ -307,8 +315,8 @@
 			  [count]"+r"(count)
 			: /* input */
 			: /* clobber */
-			  "q0", "q1", "q2", "memory", "cc");
-		// clang-format on
+			  "q0", "q1", "q2", "memory", "cc"
+			);
 	}
 
 	n &= 3;
@@ -324,7 +332,6 @@
 	int i;
 
 	if (count) {
-		// clang-format off
 		__asm__ __volatile(
 			"1:                                         \n"
 			"lddqu (%[data1]), %[x]                     \n"
@@ -348,8 +355,8 @@
 			  [z]"=x"(z)
 			: /* input */
 			: /* clobber */
-			  "memory", "cc");
-		// clang-format on
+			  "memory", "cc"
+			);
 	}
 
 	n &= 3;
@@ -376,8 +383,8 @@
 		eq2_process(drc->emphasis_eq, data[0], data[1], frames);
 
 	/* Crossover */
-	crossover2_process(&drc->xo2, frames, data[0], data[1], data1[0],
-			   data1[1], data2[0], data2[1]);
+	crossover2_process(&drc->xo2, frames, data[0], data[1],
+			   data1[0], data1[1], data2[0], data2[1]);
 
 	/* Apply compression to each band of the signal. The processing is
 	 * performed in place.
diff --git a/cras/src/dsp/drc.h b/cras/src/dsp/drc.h
index f61e851..f35b7df 100644
--- a/cras/src/dsp/drc.h
+++ b/cras/src/dsp/drc.h
@@ -77,23 +77,25 @@
  *     frequency (in [0, 1], relative to half of the sample rate).
  * PARAM_ENABLED - 1 to enable the compressor, 0 to disable it.
  */
-enum { PARAM_THRESHOLD,
-       PARAM_KNEE,
-       PARAM_RATIO,
-       PARAM_ATTACK,
-       PARAM_RELEASE,
-       PARAM_PRE_DELAY,
-       PARAM_RELEASE_ZONE1,
-       PARAM_RELEASE_ZONE2,
-       PARAM_RELEASE_ZONE3,
-       PARAM_RELEASE_ZONE4,
-       PARAM_POST_GAIN,
-       PARAM_FILTER_STAGE_GAIN,
-       PARAM_FILTER_STAGE_RATIO,
-       PARAM_FILTER_ANCHOR,
-       PARAM_CROSSOVER_LOWER_FREQ,
-       PARAM_ENABLED,
-       PARAM_LAST };
+enum {
+	PARAM_THRESHOLD,
+	PARAM_KNEE,
+	PARAM_RATIO,
+	PARAM_ATTACK,
+	PARAM_RELEASE,
+	PARAM_PRE_DELAY,
+	PARAM_RELEASE_ZONE1,
+	PARAM_RELEASE_ZONE2,
+	PARAM_RELEASE_ZONE3,
+	PARAM_RELEASE_ZONE4,
+	PARAM_POST_GAIN,
+	PARAM_FILTER_STAGE_GAIN,
+	PARAM_FILTER_STAGE_RATIO,
+	PARAM_FILTER_ANCHOR,
+	PARAM_CROSSOVER_LOWER_FREQ,
+	PARAM_ENABLED,
+	PARAM_LAST
+};
 
 /* The number of compressor kernels (also the number of bands). */
 #define DRC_NUM_KERNELS 3
diff --git a/cras/src/dsp/drc_kernel.c b/cras/src/dsp/drc_kernel.c
index c0eb100..bb922b6 100644
--- a/cras/src/dsp/drc_kernel.c
+++ b/cras/src/dsp/drc_kernel.c
@@ -22,8 +22,8 @@
 #define DIVISION_FRAMES_MASK (DIVISION_FRAMES - 1)
 
 #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))
 
 const float uninitialized_value = -1;
 static int drc_math_initialized;
@@ -117,7 +117,7 @@
 		return x;
 
 	return dk->linear_threshold +
-	       (1 - knee_expf(-k * (x - dk->linear_threshold))) / k;
+		(1 - knee_expf(-k * (x - dk->linear_threshold))) / k;
 }
 
 /* Approximate 1st derivative with input and output expressed in dB.  This slope
@@ -174,8 +174,8 @@
 }
 
 static void update_static_curve_parameters(struct drc_kernel *dk,
-					   float db_threshold, float db_knee,
-					   float ratio)
+					   float db_threshold,
+					   float db_knee, float ratio)
 {
 	if (db_threshold != dk->db_threshold || db_knee != dk->db_knee ||
 	    ratio != dk->ratio) {
@@ -240,11 +240,18 @@
 	return y;
 }
 
-void dk_set_parameters(struct drc_kernel *dk, float db_threshold, float db_knee,
-		       float ratio, float attack_time, float release_time,
-		       float pre_delay_time, float db_post_gain,
-		       float releaseZone1, float releaseZone2,
-		       float releaseZone3, float releaseZone4)
+void dk_set_parameters(struct drc_kernel *dk,
+		       float db_threshold,
+		       float db_knee,
+		       float ratio,
+		       float attack_time,
+		       float release_time,
+		       float pre_delay_time,
+		       float db_post_gain,
+		       float releaseZone1,
+		       float releaseZone2,
+		       float releaseZone3,
+		       float releaseZone4)
 {
 	float sample_rate = dk->sample_rate;
 
@@ -257,8 +264,8 @@
 	/* Empirical/perceptual tuning. */
 	full_range_makeup_gain = powf(full_range_makeup_gain, 0.6f);
 
-	dk->master_linear_gain =
-		decibels_to_linear(db_post_gain) * full_range_makeup_gain;
+	dk->master_linear_gain = decibels_to_linear(db_post_gain) *
+		full_range_makeup_gain;
 
 	/* Attack parameters. */
 	attack_time = max(0.001f, attack_time);
@@ -286,16 +293,16 @@
 	 * fitting where the y values match the evenly spaced x values as
 	 * follows: (y1 : x == 0, y2 : x == 1, y3 : x == 2, y4 : x == 3)
 	 */
-	dk->kA = 0.9999999999999998f * y1 + 1.8432219684323923e-16f * y2 -
-		 1.9373394351676423e-16f * y3 + 8.824516011816245e-18f * y4;
-	dk->kB = -1.5788320352845888f * y1 + 2.3305837032074286f * y2 -
-		 0.9141194204840429f * y3 + 0.1623677525612032f * y4;
-	dk->kC = 0.5334142869106424f * y1 - 1.272736789213631f * y2 +
-		 0.9258856042207512f * y3 - 0.18656310191776226f * y4;
-	dk->kD = 0.08783463138207234f * y1 - 0.1694162967925622f * y2 +
-		 0.08588057951595272f * y3 - 0.00429891410546283f * y4;
-	dk->kE = -0.042416883008123074f * y1 + 0.1115693827987602f * y2 -
-		 0.09764676325265872f * y3 + 0.028494263462021576f * y4;
+	dk->kA = 0.9999999999999998f*y1 + 1.8432219684323923e-16f*y2
+		- 1.9373394351676423e-16f*y3 + 8.824516011816245e-18f*y4;
+	dk->kB = -1.5788320352845888f*y1 + 2.3305837032074286f*y2
+		- 0.9141194204840429f*y3 + 0.1623677525612032f*y4;
+	dk->kC = 0.5334142869106424f*y1 - 1.272736789213631f*y2
+		+ 0.9258856042207512f*y3 - 0.18656310191776226f*y4;
+	dk->kD = 0.08783463138207234f*y1 - 0.1694162967925622f*y2
+		+ 0.08588057951595272f*y3 - 0.00429891410546283f*y4;
+	dk->kE = -0.042416883008123074f*y1 + 0.1115693827987602f*y2
+		- 0.09764676325265872f*y3 + 0.028494263462021576f*y4;
 
 	/* x ranges from 0 -> 3	      0	   1	2   3
 	 *			     -15  -10  -5   0db
@@ -339,8 +346,8 @@
 
 	/* compression_diff_db is the difference between current compression
 	 * level and the desired level. */
-	float compression_diff_db =
-		linear_to_decibels(dk->compressor_gain / scaled_desired_gain);
+	float compression_diff_db = linear_to_decibels(
+		dk->compressor_gain / scaled_desired_gain);
 
 	if (is_releasing) {
 		/* Release mode - compression_diff_db should be negative dB */
@@ -366,8 +373,8 @@
 		float x2 = x * x;
 		float x3 = x2 * x;
 		float x4 = x2 * x2;
-		float release_frames =
-			kA + kB * x + kC * x2 + kD * x3 + kE * x4;
+		float release_frames = kA + kB * x + kC * x2 + kD * x3 +
+			kE * x4;
 
 #define kSpacingDb 5
 		float db_per_frame = kSpacingDb / release_frames;
@@ -382,9 +389,9 @@
 		/* As long as we're still in attack mode, use a rate based off
 		 * the largest compression_diff_db we've encountered so far.
 		 */
-		dk->max_attack_compression_diff_db =
-			max(dk->max_attack_compression_diff_db,
-			    compression_diff_db);
+		dk->max_attack_compression_diff_db = max(
+			dk->max_attack_compression_diff_db,
+			compression_diff_db);
 
 		float eff_atten_diff_db =
 			max(0.5f, dk->max_attack_compression_diff_db);
@@ -400,12 +407,11 @@
 /* For a division of frames, take the absolute values of left channel and right
  * channel, store the maximum of them in output. */
 #if defined(__aarch64__)
-static inline void max_abs_division(float *output, const float *data0,
-				    const float *data1)
+static inline void max_abs_division(float *output,
+				    const float *data0, const float *data1)
 {
 	int count = DIVISION_FRAMES / 4;
 
-	// clang-format off
 	__asm__ __volatile__(
 		"1:                                     \n"
 		"ld1 {v0.4s}, [%[data0]], #16           \n"
@@ -423,16 +429,15 @@
 		  [count]"+r"(count)
 		: /* input */
 		: /* clobber */
-		  "v0", "v1", "memory", "cc");
-	// clang-format on
+		  "v0", "v1", "memory", "cc"
+		);
 }
 #elif defined(__ARM_NEON__)
-static inline void max_abs_division(float *output, const float *data0,
-				    const float *data1)
+static inline void max_abs_division(float *output,
+				    const float *data0, const float *data1)
 {
 	int count = DIVISION_FRAMES / 4;
 
-	// clang-format off
 	__asm__ __volatile__(
 		"1:                                     \n"
 		"vld1.32 {q0}, [%[data0]]!              \n"
@@ -450,17 +455,17 @@
 		  [count]"+r"(count)
 		: /* input */
 		: /* clobber */
-		  "q0", "q1", "memory", "cc");
-	// clang-format on
+		  "q0", "q1", "memory", "cc"
+		);
 }
 #elif defined(__SSE3__)
 #include <emmintrin.h>
-static inline void max_abs_division(float *output, const float *data0,
-				    const float *data1)
+static inline void max_abs_division(float *output,
+				    const float *data0, const float *data1)
 {
 	__m128 x, y;
 	int count = DIVISION_FRAMES / 4;
-	// clang-format off
+
 	__asm__ __volatile__(
 		"1:                                     \n"
 		"lddqu (%[data0]), %[x]                 \n"
@@ -484,12 +489,12 @@
 		: /* input */
 		  [mask]"x"(_mm_set1_epi32(0x7fffffff))
 		: /* clobber */
-		  "memory", "cc");
-	// clang-format on
+		  "memory", "cc"
+		);
 }
 #else
-static inline void max_abs_division(float *output, const float *data0,
-				    const float *data1)
+static inline void max_abs_division(float *output,
+				    const float *data0, const float *data1)
 {
 	int i;
 	for (i = 0; i < DIVISION_FRAMES; i++)
@@ -515,7 +520,8 @@
 	}
 
 	/* The max abs value across all channels for this frame */
-	max_abs_division(abs_input_array, &dk->pre_delay_buffers[0][div_start],
+	max_abs_division(abs_input_array,
+			 &dk->pre_delay_buffers[0][div_start],
 			 &dk->pre_delay_buffers[1][div_start]);
 
 	for (i = 0; i < DIVISION_FRAMES; i++) {
@@ -533,17 +539,16 @@
 		int is_release = (gain > detector_average);
 		if (is_release) {
 			if (gain > NEG_TWO_DB) {
-				detector_average +=
-					(gain - detector_average) *
+				detector_average += (gain - detector_average) *
 					sat_release_rate_at_neg_two_db;
 			} else {
 				float gain_db = linear_to_decibels(gain);
-				float db_per_frame =
-					gain_db * sat_release_frames_inv_neg;
+				float db_per_frame = gain_db *
+					sat_release_frames_inv_neg;
 				float sat_release_rate =
 					decibels_to_linear(db_per_frame) - 1;
 				detector_average += (gain - detector_average) *
-						    sat_release_rate;
+					sat_release_rate;
 			}
 		} else {
 			detector_average = gain;
@@ -585,11 +590,9 @@
 	if (envelope_rate < 1) {
 		float c = compressor_gain - scaled_desired_gain;
 		float r = 1 - envelope_rate;
-		float32x4_t x0 = { c * r, c * r * r, c * r * r * r,
-				   c * r * r * r * r };
+		float32x4_t x0 = {c*r, c*r*r, c*r*r*r, c*r*r*r*r};
 		float32x4_t x, x2, x4, left, right, tmp1, tmp2;
 
-		// clang-format off
 		__asm__ __volatile(
 			"b 2f                                               \n"
 			"1:                                                 \n"
@@ -640,17 +643,15 @@
 			  [r4]"w"(vdupq_n_f32(r*r*r*r)),
 			  [g]"w"(vdupq_n_f32(master_linear_gain))
 			: /* clobber */
-			  "memory", "cc");
-		// clang-format on
+			  "memory", "cc"
+			);
 		dk->compressor_gain = x[3];
 	} else {
 		float c = compressor_gain;
 		float r = envelope_rate;
-		float32x4_t x = { c * r, c * r * r, c * r * r * r,
-				  c * r * r * r * r };
+		float32x4_t x = {c*r, c*r*r, c*r*r*r, c*r*r*r*r};
 		float32x4_t x2, x4, left, right, tmp1, tmp2;
 
-		// clang-format off
 		__asm__ __volatile(
 			"b 2f                                               \n"
 			"1:                                                 \n"
@@ -700,8 +701,8 @@
 			  [r4]"w"(vdupq_n_f32(r*r*r*r)),
 			  [g]"w"(vdupq_n_f32(master_linear_gain))
 			: /* clobber */
-			  "memory", "cc");
-		// clang-format on
+			  "memory", "cc"
+			);
 		dk->compressor_gain = x[3];
 	}
 }
@@ -728,11 +729,9 @@
 	if (envelope_rate < 1) {
 		float c = compressor_gain - scaled_desired_gain;
 		float r = 1 - envelope_rate;
-		__m128 x0 = { c * r, c * r * r, c * r * r * r,
-			      c * r * r * r * r };
+		__m128 x0 = {c*r, c*r*r, c*r*r*r, c*r*r*r*r};
 		__m128 x, x2, x4, left, right, tmp1, tmp2;
 
-		// clang-format off
 		__asm__ __volatile(
 			"jmp 2f                                     \n"
 			"1:                                         \n"
@@ -791,8 +790,8 @@
 			  [r4]"x"(_mm_set1_ps(r*r*r*r)),
 			  [g]"x"(_mm_set1_ps(master_linear_gain))
 			: /* clobber */
-			  "memory", "cc");
-		// clang-format on
+			  "memory", "cc"
+			);
 		dk->compressor_gain = x[3];
 	} else {
 		/* See warp_sinf() for the details for the constants. */
@@ -803,11 +802,9 @@
 
 		float c = compressor_gain;
 		float r = envelope_rate;
-		__m128 x = { c * r, c * r * r, c * r * r * r,
-			     c * r * r * r * r };
+		__m128 x = {c*r, c*r*r, c*r*r*r, c*r*r*r*r};
 		__m128 x2, x4, left, right, tmp1, tmp2;
 
-		// clang-format off
 		__asm__ __volatile(
 			"jmp 2f                                     \n"
 			"1:                                         \n"
@@ -864,8 +861,8 @@
 			  [r4]"x"(_mm_set1_ps(r*r*r*r)),
 			  [g]"x"(_mm_set1_ps(master_linear_gain))
 			: /* clobber */
-			  "memory", "cc");
-		// clang-format on
+			  "memory", "cc"
+			);
 		dk->compressor_gain = x[3];
 	}
 }
@@ -889,9 +886,8 @@
 		float c = compressor_gain - scaled_desired_gain;
 		float base = scaled_desired_gain;
 		float r = 1 - envelope_rate;
-		float x[4] = { c * r, c * r * r, c * r * r * r,
-			       c * r * r * r * r };
-		float r4 = r * r * r * r;
+		float x[4] = {c*r, c*r*r, c*r*r*r, c*r*r*r*r};
+		float r4 = r*r*r*r;
 
 		i = 0;
 		while (1) {
@@ -904,7 +900,7 @@
 
 				/* Calculate total gain using master gain. */
 				float total_gain = master_linear_gain *
-						   post_warp_compressor_gain;
+					post_warp_compressor_gain;
 
 				/* Apply final gain. */
 				*ptr_left++ *= total_gain;
@@ -923,9 +919,8 @@
 		/* Release - exponentially increase gain to 1.0 */
 		float c = compressor_gain;
 		float r = envelope_rate;
-		float x[4] = { c * r, c * r * r, c * r * r * r,
-			       c * r * r * r * r };
-		float r4 = r * r * r * r;
+		float x[4] = {c*r, c*r*r, c*r*r*r, c*r*r*r*r};
+		float r4 = r*r*r*r;
 
 		i = 0;
 		while (1) {
@@ -938,7 +933,7 @@
 
 				/* Calculate total gain using master gain. */
 				float total_gain = master_linear_gain *
-						   post_warp_compressor_gain;
+					post_warp_compressor_gain;
 
 				/* Apply final gain. */
 				*ptr_left++ *= total_gain;
@@ -988,10 +983,10 @@
 		       frames_to_process * sizeof(float));
 	}
 
-	dk->pre_delay_write_index =
-		(write_index + frames_to_process) & MAX_PRE_DELAY_FRAMES_MASK;
-	dk->pre_delay_read_index =
-		(read_index + frames_to_process) & MAX_PRE_DELAY_FRAMES_MASK;
+	dk->pre_delay_write_index = (write_index + frames_to_process) &
+		MAX_PRE_DELAY_FRAMES_MASK;
+	dk->pre_delay_read_index = (read_index + frames_to_process) &
+		MAX_PRE_DELAY_FRAMES_MASK;
 }
 
 /* Delay the input sample only and don't do other processing. This is used when
@@ -1016,7 +1011,8 @@
 		chunk = min(chunk, count - i);
 		for (j = 0; j < DRC_NUM_CHANNELS; ++j) {
 			memcpy(&dk->pre_delay_buffers[j][write_index],
-			       &data_channels[j][i], chunk * sizeof(float));
+			       &data_channels[j][i],
+			       chunk * sizeof(float));
 			memcpy(&data_channels[j][i],
 			       &dk->pre_delay_buffers[j][read_index],
 			       chunk * sizeof(float));
diff --git a/cras/src/dsp/drc_kernel.h b/cras/src/dsp/drc_kernel.h
index 1157f22..a5ee86b 100644
--- a/cras/src/dsp/drc_kernel.h
+++ b/cras/src/dsp/drc_kernel.h
@@ -85,11 +85,19 @@
 void dk_free(struct drc_kernel *dk);
 
 /* Sets the parameters of a drc kernel. See drc.h for details */
-void dk_set_parameters(struct drc_kernel *dk, float db_threshold, float db_knee,
-		       float ratio, float attack_time, float release_time,
-		       float pre_delay_time, float db_post_gain,
-		       float releaseZone1, float releaseZone2,
-		       float releaseZone3, float releaseZone4);
+void dk_set_parameters(struct drc_kernel *dk,
+		       float db_threshold,
+		       float db_knee,
+		       float ratio,
+		       float attack_time,
+		       float release_time,
+		       float pre_delay_time,
+		       float db_post_gain,
+		       float releaseZone1,
+		       float releaseZone2,
+		       float releaseZone3,
+		       float releaseZone4
+		       );
 
 /* Enables or disables a drc kernel */
 void dk_set_enabled(struct drc_kernel *dk, int enabled);
diff --git a/cras/src/dsp/drc_math.c b/cras/src/dsp/drc_math.c
index 1ee5c81..35e6f4a 100644
--- a/cras/src/dsp/drc_math.c
+++ b/cras/src/dsp/drc_math.c
@@ -10,5 +10,5 @@
 {
 	int i;
 	for (i = -100; i <= 100; i++)
-		db_to_linear[i + 100] = pow(10, i / 20.0);
+		db_to_linear[i + 100] = pow(10, i/20.0);
 }
diff --git a/cras/src/dsp/drc_math.h b/cras/src/dsp/drc_math.h
index 970b729..eec2061 100644
--- a/cras/src/dsp/drc_math.h
+++ b/cras/src/dsp/drc_math.h
@@ -16,13 +16,15 @@
 #ifndef __BIONIC__
 #include <ieee754.h>
 #else
-union ieee754_float {
+union ieee754_float
+{
 	float f;
 	/* Little endian float fields */
-	struct {
-		unsigned int mantissa : 23;
-		unsigned int exponent : 8;
-		unsigned int negative : 1;
+	struct
+	{
+		unsigned int mantissa:23;
+		unsigned int exponent:8;
+		unsigned int negative:1;
 	} ieee;
 };
 #endif
@@ -40,28 +42,22 @@
 #define NEG_TWO_DB 0.7943282347242815f /* -2dB = 10^(-2/20) */
 
 #ifndef max
-#define max(a, b)                                                              \
-	({                                                                     \
-		__typeof__(a) _a = (a);                                        \
-		__typeof__(b) _b = (b);                                        \
-		_a > _b ? _a : _b;                                             \
-	})
+#define max(a, b) ({ __typeof__(a) _a = (a);	\
+			__typeof__(b) _b = (b);	\
+			_a > _b ? _a : _b; })
 #endif
 
 #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
 
 #ifndef M_PI
 #define M_PI 3.14159265358979323846
 #endif
 
-#define PURE __attribute__((pure))
+#define PURE __attribute__ ((pure))
 static inline float decibels_to_linear(float decibels) PURE;
 static inline float linear_to_decibels(float linear) PURE;
 static inline float warp_sinf(float x) PURE;
@@ -107,7 +103,7 @@
 	const float A0 = 1.0f;
 
 	float x2 = x * x;
-	return ((A3 * x + A2) * x2 + (A1 * x + A0)) * db_to_linear[i + 100];
+	return ((A3 * x + A2)*x2 + (A1 * x + A0)) * db_to_linear[i+100];
 #endif
 }
 
@@ -159,12 +155,12 @@
 
 	float x2 = x * x;
 	float x4 = x2 * x2;
-	return ((A5 * x + A4) * x4 + (A3 * x + A2) * x2 + (A1 * x + A0)) *
-		       20.0f +
-	       exp * 6.0205999132796239f;
+	return ((A5 * x + A4)*x4 + (A3 * x + A2)*x2 + (A1 * x + A0)) * 20.0f
+		+ exp * 6.0205999132796239f;
 #endif
 }
 
+
 static inline float warp_sinf(float x)
 {
 #ifdef SLOW_WARP_SIN
diff --git a/cras/src/dsp/dsp_util.c b/cras/src/dsp/dsp_util.c
index 86679e1..c95f0c5 100644
--- a/cras/src/dsp/dsp_util.c
+++ b/cras/src/dsp/dsp_util.c
@@ -9,21 +9,15 @@
 #include "dsp_util.h"
 
 #ifndef max
-#define max(a, b)                                                              \
-	({                                                                     \
-		__typeof__(a) _a = (a);                                        \
-		__typeof__(b) _b = (b);                                        \
-		_a > _b ? _a : _b;                                             \
-	})
+#define max(a, b) ({ __typeof__(a) _a = (a);	\
+			__typeof__(b) _b = (b);	\
+			_a > _b ? _a : _b; })
 #endif
 
 #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
 
 #undef deinterleave_stereo
@@ -35,16 +29,15 @@
  * shorts to int with sign extension.
  */
 #ifdef __aarch64__
-static void deinterleave_stereo(int16_t *input, float *output1, float *output2,
-				int frames)
+static void deinterleave_stereo(int16_t *input, float *output1,
+				float *output2, int frames)
 {
 	int chunk = frames >> 3;
 	frames &= 7;
 	/* Process 8 frames (16 samples) each loop. */
 	/* L0 R0 L1 R1 L2 R2 L3 R3... -> L0 L1 L2 L3... R0 R1 R2 R3... */
 	if (chunk) {
-		// clang-format off
-		__asm__ __volatile__(
+		__asm__ __volatile__ (
 			"1:                                         \n"
 			"ld2  {v2.8h, v3.8h}, [%[input]], #32       \n"
 			"subs %w[chunk], %w[chunk], #1              \n"
@@ -66,8 +59,8 @@
 			  [output2]"+r"(output2)
 			: /* input */
 			: /* clobber */
-			  "v0", "v1", "v2", "v3", "memory", "cc");
-		// clang-format on
+			  "v0", "v1", "v2", "v3", "memory", "cc"
+			);
 	}
 
 	/* The remaining samples. */
@@ -90,8 +83,8 @@
  * to the min or max value that fits an int.
  * For other values, sqxtn clamps the output to -32768 to 32767 range.
  */
-static void interleave_stereo(float *input1, float *input2, int16_t *output,
-			      int frames)
+static void interleave_stereo(float *input1, float *input2,
+			      int16_t *output, int frames)
 {
 	/* Process 4 frames (8 samples) each loop. */
 	/* L0 L1 L2 L3, R0 R1 R2 R3 -> L0 R0 L1 R1, L2 R2 L3 R3 */
@@ -99,8 +92,7 @@
 	frames &= 3;
 
 	if (chunk) {
-		// clang-format off
-		__asm__ __volatile__(
+		__asm__ __volatile__ (
 			"dup    v2.4s, %w[scale]                    \n"
 			"1:                                         \n"
 			"ld1    {v0.4s}, [%[input1]], #16           \n"
@@ -122,8 +114,8 @@
 			: /* input */
 			  [scale]"r"(15 << 23)
 			: /* clobber */
-			  "v0", "v1", "v2", "memory", "cc");
-		// clang-format on
+			  "v0", "v1", "v2", "memory", "cc"
+			);
 	}
 
 	/* The remaining samples */
@@ -143,16 +135,15 @@
 #ifdef __ARM_NEON__
 #include <arm_neon.h>
 
-static void deinterleave_stereo(int16_t *input, float *output1, float *output2,
-				int frames)
+static void deinterleave_stereo(int16_t *input, float *output1,
+				float *output2, int frames)
 {
 	/* Process 8 frames (16 samples) each loop. */
 	/* L0 R0 L1 R1 L2 R2 L3 R3... -> L0 L1 L2 L3... R0 R1 R2 R3... */
 	int chunk = frames >> 3;
 	frames &= 7;
 	if (chunk) {
-		// clang-format off
-		__asm__ __volatile__(
+		__asm__ __volatile__ (
 			"1:					    \n"
 			"vld2.16 {d0-d3}, [%[input]]!		    \n"
 			"subs %[chunk], #1			    \n"
@@ -174,8 +165,8 @@
 			  [output2]"+r"(output2)
 			: /* input */
 			: /* clobber */
-			  "q0", "q1", "q2", "q3", "memory", "cc");
-		// clang-format on
+			  "q0", "q1", "q2", "q3", "memory", "cc"
+			);
 	}
 
 	/* The remaining samples. */
@@ -196,8 +187,8 @@
  * to the min or max value that fits an int.
  * For other values, vqmovn clamps the output to -32768 to 32767 range.
  */
-static void interleave_stereo(float *input1, float *input2, int16_t *output,
-			      int frames)
+static void interleave_stereo(float *input1, float *input2,
+			      int16_t *output, int frames)
 {
 	/* Process 4 frames (8 samples) each loop. */
 	/* L0 L1 L2 L3, R0 R1 R2 R3 -> L0 R0 L1 R1, L2 R2 L3 R3 */
@@ -207,8 +198,7 @@
 	frames &= 3;
 
 	if (chunk) {
-		// clang-format off
-		__asm__ __volatile__(
+		__asm__ __volatile__ (
 			"veor q0, q0, q0			    \n"
 			"1:					    \n"
 			"vld1.32 {d2-d3}, [%[input1]]!		    \n"
@@ -239,8 +229,8 @@
 			  [pos]"w"(pos),
 			  [neg]"w"(neg)
 			: /* clobber */
-			  "q0", "q1", "q2", "q3", "q4", "memory", "cc");
-		// clang-format on
+			  "q0", "q1", "q2", "q3", "q4", "memory", "cc"
+			);
 	}
 
 	/* The remaining samples */
@@ -270,16 +260,15 @@
  * mulps is used to normalize the range of the low and high words, adjusting
  * for high and low words being in different range.
  */
-static void deinterleave_stereo(int16_t *input, float *output1, float *output2,
-				int frames)
+static void deinterleave_stereo(int16_t *input, float *output1,
+				float *output2, int frames)
 {
 	/* Process 8 frames (16 samples) each loop. */
 	/* L0 R0 L1 R1 L2 R2 L3 R3... -> L0 L1 L2 L3... R0 R1 R2 R3... */
 	int chunk = frames >> 3;
 	frames &= 7;
 	if (chunk) {
-		// clang-format off
-		__asm__ __volatile__(
+		__asm__ __volatile__ (
 			"1:                                         \n"
 			"lddqu (%[input]), %%xmm0                   \n"
 			"lddqu 16(%[input]), %%xmm1                 \n"
@@ -315,8 +304,8 @@
 			  [scale_2_n31]"x"(_mm_set1_ps(1.0f/(1<<15)/(1<<16))),
 			  [scale_2_n15]"x"(_mm_set1_ps(1.0f/(1<<15)))
 			: /* clobber */
-			  "xmm0", "xmm1", "xmm2", "xmm3", "memory", "cc");
-		// clang-format on
+			  "xmm0", "xmm1", "xmm2", "xmm3", "memory", "cc"
+			);
 	}
 
 	/* The remaining samples. */
@@ -333,8 +322,8 @@
  * For very large values, beyond +/- 2 billion, cvtps2dq will produce
  * 0x80000000 and packssdw will clamp -32768.
  */
-static void interleave_stereo(float *input1, float *input2, int16_t *output,
-			      int frames)
+static void interleave_stereo(float *input1, float *input2,
+			      int16_t *output, int frames)
 {
 	/* Process 4 frames (8 samples) each loop. */
 	/* L0 L1 L2 L3, R0 R1 R2 R3 -> L0 R0 L1 R1, L2 R2 L3 R3 */
@@ -342,8 +331,7 @@
 	frames &= 3;
 
 	if (chunk) {
-		// clang-format off
-		__asm__ __volatile__(
+		__asm__ __volatile__ (
 			"1:                                         \n"
 			"lddqu (%[input1]), %%xmm0                  \n"
 			"lddqu (%[input2]), %%xmm2                  \n"
@@ -370,8 +358,8 @@
 			  [scale_2_15]"x"(_mm_set1_epi32(15 << 23)),
 			  [clamp_large]"x"(_mm_set1_ps(32767.0f))
 			: /* clobber */
-			  "xmm0", "xmm1", "xmm2", "memory", "cc");
-		// clang-format on
+			  "xmm0", "xmm1", "xmm2", "memory", "cc"
+			);
 	}
 
 	/* The remaining samples */
@@ -389,7 +377,7 @@
 #endif
 
 static void dsp_util_deinterleave_s16le(int16_t *input, float *const *output,
-					int channels, int frames)
+				 int channels, int frames)
 {
 	float *output_ptr[channels];
 	int i, j;
@@ -409,6 +397,7 @@
 			*(output_ptr[j]++) = *input++ / 32768.0f;
 }
 
+
 static void dsp_util_deinterleave_s24le(int32_t *input, float *const *output,
 					int channels, int frames)
 {
@@ -420,7 +409,8 @@
 
 	for (i = 0; i < frames; i++)
 		for (j = 0; j < channels; j++, input++)
-			*(output_ptr[j]++) = (*input << 8) / 2147483648.0f;
+			*(output_ptr[j]++) =
+				(*input << 8) / 2147483648.0f;
 }
 
 static void dsp_util_deinterleave_s243le(uint8_t *input, float *const *output,
@@ -460,19 +450,20 @@
 {
 	switch (format) {
 	case SND_PCM_FORMAT_S16_LE:
-		dsp_util_deinterleave_s16le((int16_t *)input, output, channels,
-					    frames);
+		dsp_util_deinterleave_s16le((int16_t *)input, output,
+					    channels, frames);
 		break;
 	case SND_PCM_FORMAT_S24_LE:
-		dsp_util_deinterleave_s24le((int32_t *)input, output, channels,
-					    frames);
+		dsp_util_deinterleave_s24le((int32_t *)input, output,
+					  channels, frames);
 		break;
 	case SND_PCM_FORMAT_S24_3LE:
-		dsp_util_deinterleave_s243le(input, output, channels, frames);
+		dsp_util_deinterleave_s243le(input, output,
+					     channels, frames);
 		break;
 	case SND_PCM_FORMAT_S32_LE:
-		dsp_util_deinterleave_s32le((int32_t *)input, output, channels,
-					    frames);
+		dsp_util_deinterleave_s32le((int32_t *)input, output,
+					     channels, frames);
 		break;
 	default:
 		syslog(LOG_ERR, "Invalid format to deinterleave");
@@ -519,7 +510,7 @@
 			float f = *(input_ptr[j]++) * 2147483648.0f;
 			f += (f >= 0) ? 0.5f : -0.5f;
 			*output = max((float)INT_MIN, min((float)INT_MAX, f));
-			*output = (*output >> 8) & 0x00ffffff;
+			*output >>= 8;
 		}
 }
 
@@ -565,19 +556,19 @@
 {
 	switch (format) {
 	case SND_PCM_FORMAT_S16_LE:
-		dsp_util_interleave_s16le(input, (int16_t *)output, channels,
-					  frames);
+		dsp_util_interleave_s16le(input, (int16_t *)output,
+					  channels, frames);
 		break;
 	case SND_PCM_FORMAT_S24_LE:
-		dsp_util_interleave_s24le(input, (int32_t *)output, channels,
-					  frames);
+		dsp_util_interleave_s24le(input, (int32_t *)output,
+					  channels, frames);
 		break;
 	case SND_PCM_FORMAT_S24_3LE:
 		dsp_util_interleave_s243le(input, output, channels, frames);
 		break;
 	case SND_PCM_FORMAT_S32_LE:
-		dsp_util_interleave_s32le(input, (int32_t *)output, channels,
-					  frames);
+		dsp_util_interleave_s32le(input, (int32_t *)output,
+					  channels, frames);
 		break;
 	default:
 		syslog(LOG_ERR, "Invalid format to interleave");
@@ -594,17 +585,19 @@
 	__builtin_ia32_ldmxcsr(mxcsr | 0x8040);
 #elif defined(__aarch64__)
 	uint64_t cw;
-	__asm__ __volatile__("mrs    %0, fpcr			    \n"
-			     "orr    %0, %0, #0x1000000		    \n"
-			     "msr    fpcr, %0			    \n"
-			     "isb					    \n"
-			     : "=r"(cw)::"memory");
+	__asm__ __volatile__ (
+		"mrs    %0, fpcr			    \n"
+		"orr    %0, %0, #0x1000000		    \n"
+		"msr    fpcr, %0			    \n"
+		"isb					    \n"
+		: "=r"(cw) :: "memory");
 #elif defined(__arm__)
 	uint32_t cw;
-	__asm__ __volatile__("vmrs   %0, fpscr			    \n"
-			     "orr    %0, %0, #0x1000000		    \n"
-			     "vmsr   fpscr, %0			    \n"
-			     : "=r"(cw)::"memory");
+	__asm__ __volatile__ (
+		"vmrs   %0, fpscr			    \n"
+		"orr    %0, %0, #0x1000000		    \n"
+		"vmsr   fpscr, %0			    \n"
+		: "=r"(cw) :: "memory");
 #else
 #warning "Don't know how to disable denorms. Performace may suffer."
 #endif
diff --git a/cras/src/dsp/eq.c b/cras/src/dsp/eq.c
index 9f3197f..89c396d 100644
--- a/cras/src/dsp/eq.c
+++ b/cras/src/dsp/eq.c
@@ -23,7 +23,7 @@
 }
 
 int eq_append_biquad(struct eq *eq, enum biquad_type type, float freq, float Q,
-		     float gain)
+		      float gain)
 {
 	if (eq->n >= MAX_BIQUADS_PER_EQ)
 		return -1;
@@ -56,8 +56,9 @@
 		float a2 = q->a2;
 		for (j = 0; j < count; j++) {
 			float x = data[j];
-			float y =
-				b0 * x + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2;
+			float y = b0*x
+				+ b1*x1 + b2*x2
+				- a1*y1 - a2*y2;
 			data[j] = y;
 			x2 = x1;
 			x1 = x;
@@ -90,8 +91,9 @@
 			float a2 = q->a2;
 			for (j = 0; j < count; j++) {
 				float x = data[j];
-				float y = b0 * x + b1 * x1 + b2 * x2 - a1 * y1 -
-					  a2 * y2;
+				float y = b0*x
+					+ b1*x1 + b2*x2
+					- a1*y1 - a2*y2;
 				data[j] = y;
 				x2 = x1;
 				x1 = x;
@@ -104,7 +106,7 @@
 			q->y2 = y2;
 		} else {
 			struct biquad *q = &eq->biquad[i];
-			struct biquad *r = &eq->biquad[i + 1];
+			struct biquad *r = &eq->biquad[i+1];
 			float x1 = q->x1;
 			float x2 = q->x2;
 			float y1 = q->y1;
@@ -125,10 +127,12 @@
 
 			for (j = 0; j < count; j++) {
 				float x = data[j];
-				float y = qb0 * x + qb1 * x1 + qb2 * x2 -
-					  qa1 * y1 - qa2 * y2;
-				float z = rb0 * y + rb1 * y1 + rb2 * y2 -
-					  ra1 * z1 - ra2 * z2;
+				float y = qb0*x
+					+ qb1*x1 + qb2*x2
+					- qa1*y1 - qa2*y2;
+				float z = rb0*y
+					+ rb1*y1 + rb2*y2
+					- ra1*z1 - ra2*z2;
 				data[j] = z;
 				x2 = x1;
 				x1 = x;
diff --git a/cras/src/dsp/eq.h b/cras/src/dsp/eq.h
index 212f653..c583632 100644
--- a/cras/src/dsp/eq.h
+++ b/cras/src/dsp/eq.h
@@ -39,7 +39,7 @@
  *    0 if success. -1 if the eq has no room for more biquads.
  */
 int eq_append_biquad(struct eq *eq, enum biquad_type type, float freq, float Q,
-		     float gain);
+		      float gain);
 
 /* Append a biquad filter to an EQ. An EQ can have at most MAX_BIQUADS_PER_EQ
  * biquad filters. This is similar to eq_append_biquad(), but it specifies the
diff --git a/cras/src/dsp/eq2.c b/cras/src/dsp/eq2.c
index f4f4185..07b0050 100644
--- a/cras/src/dsp/eq2.c
+++ b/cras/src/dsp/eq2.c
@@ -30,8 +30,8 @@
 	free(eq2);
 }
 
-int eq2_append_biquad(struct eq2 *eq2, int channel, enum biquad_type type,
-		      float freq, float Q, float gain)
+int eq2_append_biquad(struct eq2 *eq2, int channel,
+		      enum biquad_type type, float freq, float Q, float gain)
 {
 	if (eq2->n[channel] >= MAX_BIQUADS_PER_EQ2)
 		return -1;
@@ -49,8 +49,8 @@
 	return 0;
 }
 
-static inline void eq2_process_one(struct biquad (*bq)[2], float *data0,
-				   float *data1, int count)
+static inline void eq2_process_one(struct biquad (*bq)[2],
+				   float *data0, float *data1, int count)
 {
 	struct biquad *qL = &bq[0][0];
 	struct biquad *qR = &bq[0][1];
@@ -80,15 +80,17 @@
 		float xL = data0[j];
 		float xR = data1[j];
 
-		float yL = b0L * xL + b1L * x1L + b2L * x2L - a1L * y1L -
-			   a2L * y2L;
+		float yL = b0L*xL
+			+ b1L*x1L + b2L*x2L
+			- a1L*y1L - a2L*y2L;
 		x2L = x1L;
 		x1L = xL;
 		y2L = y1L;
 		y1L = yL;
 
-		float yR = b0R * xR + b1R * x1R + b2R * x2R - a1R * y1R -
-			   a2R * y2R;
+		float yR = b0R*xR
+			+ b1R*x1R + b2R*x2R
+			- a1R*y1R - a2R*y2R;
 		x2R = x1R;
 		x1R = xR;
 		y2R = y1R;
@@ -110,33 +112,32 @@
 
 #ifdef __ARM_NEON__
 #include <arm_neon.h>
-static inline void eq2_process_two_neon(struct biquad (*bq)[2], float *data0,
-					float *data1, int count)
+static inline void eq2_process_two_neon(struct biquad (*bq)[2],
+					float *data0, float *data1, int count)
 {
 	struct biquad *qL = &bq[0][0];
 	struct biquad *rL = &bq[1][0];
 	struct biquad *qR = &bq[0][1];
 	struct biquad *rR = &bq[1][1];
 
-	float32x2_t x1 = { qL->x1, qR->x1 };
-	float32x2_t x2 = { qL->x2, qR->x2 };
-	float32x2_t y1 = { qL->y1, qR->y1 };
-	float32x2_t y2 = { qL->y2, qR->y2 };
-	float32x2_t qb0 = { qL->b0, qR->b0 };
-	float32x2_t qb1 = { qL->b1, qR->b1 };
-	float32x2_t qb2 = { qL->b2, qR->b2 };
-	float32x2_t qa1 = { qL->a1, qR->a1 };
-	float32x2_t qa2 = { qL->a2, qR->a2 };
+	float32x2_t x1 = {qL->x1, qR->x1};
+	float32x2_t x2 = {qL->x2, qR->x2};
+	float32x2_t y1 = {qL->y1, qR->y1};
+	float32x2_t y2 = {qL->y2, qR->y2};
+	float32x2_t qb0 = {qL->b0, qR->b0};
+	float32x2_t qb1 = {qL->b1, qR->b1};
+	float32x2_t qb2 = {qL->b2, qR->b2};
+	float32x2_t qa1 = {qL->a1, qR->a1};
+	float32x2_t qa2 = {qL->a2, qR->a2};
 
-	float32x2_t z1 = { rL->y1, rR->y1 };
-	float32x2_t z2 = { rL->y2, rR->y2 };
-	float32x2_t rb0 = { rL->b0, rR->b0 };
-	float32x2_t rb1 = { rL->b1, rR->b1 };
-	float32x2_t rb2 = { rL->b2, rR->b2 };
-	float32x2_t ra1 = { rL->a1, rR->a1 };
-	float32x2_t ra2 = { rL->a2, rR->a2 };
+	float32x2_t z1 = {rL->y1, rR->y1};
+	float32x2_t z2 = {rL->y2, rR->y2};
+	float32x2_t rb0 = {rL->b0, rR->b0};
+	float32x2_t rb1 = {rL->b1, rR->b1};
+	float32x2_t rb2 = {rL->b2, rR->b2};
+	float32x2_t ra1 = {rL->a1, rR->a1};
+	float32x2_t ra2 = {rL->a2, rR->a2};
 
-	// clang-format off
 	__asm__ __volatile__(
 		/* d0 = x, d1 = y, d2 = z */
 		"1:                                     \n"
@@ -184,8 +185,8 @@
 		  [ra1]"w"(ra1),
 		  [ra2]"w"(ra2)
 		: /* clobber */
-		  "d0", "d1", "d2", "memory", "cc");
-	// clang-format on
+		  "d0", "d1", "d2", "memory", "cc"
+		);
 
 	qL->x1 = x1[0];
 	qL->x2 = x2[0];
@@ -204,33 +205,32 @@
 
 #if defined(__SSE3__) && defined(__x86_64__)
 #include <emmintrin.h>
-static inline void eq2_process_two_sse3(struct biquad (*bq)[2], float *data0,
-					float *data1, int count)
+static inline void eq2_process_two_sse3(struct biquad (*bq)[2],
+					float *data0, float *data1, int count)
 {
 	struct biquad *qL = &bq[0][0];
 	struct biquad *rL = &bq[1][0];
 	struct biquad *qR = &bq[0][1];
 	struct biquad *rR = &bq[1][1];
 
-	__m128 x1 = { qL->x1, qR->x1 };
-	__m128 x2 = { qL->x2, qR->x2 };
-	__m128 y1 = { qL->y1, qR->y1 };
-	__m128 y2 = { qL->y2, qR->y2 };
-	__m128 qb0 = { qL->b0, qR->b0 };
-	__m128 qb1 = { qL->b1, qR->b1 };
-	__m128 qb2 = { qL->b2, qR->b2 };
-	__m128 qa1 = { qL->a1, qR->a1 };
-	__m128 qa2 = { qL->a2, qR->a2 };
+	__m128 x1 = {qL->x1, qR->x1};
+	__m128 x2 = {qL->x2, qR->x2};
+	__m128 y1 = {qL->y1, qR->y1};
+	__m128 y2 = {qL->y2, qR->y2};
+	__m128 qb0 = {qL->b0, qR->b0};
+	__m128 qb1 = {qL->b1, qR->b1};
+	__m128 qb2 = {qL->b2, qR->b2};
+	__m128 qa1 = {qL->a1, qR->a1};
+	__m128 qa2 = {qL->a2, qR->a2};
 
-	__m128 z1 = { rL->y1, rR->y1 };
-	__m128 z2 = { rL->y2, rR->y2 };
-	__m128 rb0 = { rL->b0, rR->b0 };
-	__m128 rb1 = { rL->b1, rR->b1 };
-	__m128 rb2 = { rL->b2, rR->b2 };
-	__m128 ra1 = { rL->a1, rR->a1 };
-	__m128 ra2 = { rL->a2, rR->a2 };
+	__m128 z1 = {rL->y1, rR->y1};
+	__m128 z2 = {rL->y2, rR->y2};
+	__m128 rb0 = {rL->b0, rR->b0};
+	__m128 rb1 = {rL->b1, rR->b1};
+	__m128 rb2 = {rL->b2, rR->b2};
+	__m128 ra1 = {rL->a1, rR->a1};
+	__m128 ra2 = {rL->a2, rR->a2};
 
-	// clang-format off
 	__asm__ __volatile__(
 		"1:                                     \n"
 		"movss (%[data0]), %%xmm2               \n"
@@ -296,8 +296,8 @@
 		  [ra1]"x"(ra1),
 		  [ra2]"x"(ra2)
 		: /* clobber */
-		  "xmm0", "xmm1", "xmm2", "memory", "cc");
-	// clang-format on
+		  "xmm0", "xmm1", "xmm2", "memory", "cc"
+		);
 
 	qL->x1 = x1[0];
 	qL->x2 = x2[0];
@@ -335,8 +335,7 @@
 					     count);
 #else
 			eq2_process_one(&eq2->biquad[i], data0, data1, count);
-			eq2_process_one(&eq2->biquad[i + 1], data0, data1,
-					count);
+			eq2_process_one(&eq2->biquad[i+1], data0, data1, count);
 #endif
 		}
 	}
diff --git a/cras/src/dsp/eq2.h b/cras/src/dsp/eq2.h
index dfa9a1d..9a9eed6 100644
--- a/cras/src/dsp/eq2.h
+++ b/cras/src/dsp/eq2.h
@@ -39,8 +39,8 @@
  * Returns:
  *    0 if success. -1 if the eq has no room for more biquads.
  */
-int eq2_append_biquad(struct eq2 *eq2, int channel, enum biquad_type type,
-		      float freq, float Q, float gain);
+int eq2_append_biquad(struct eq2 *eq2, int channel,
+		      enum biquad_type type, float freq, float Q, float gain);
 
 /* Append a biquad filter to an EQ2. An EQ2 can have at most MAX_BIQUADS_PER_EQ2
  * biquad filters. This is similar to eq2_append_biquad(), but it specifies the
diff --git a/cras/src/dsp/tests/cmpraw.c b/cras/src/dsp/tests/cmpraw.c
index 911f19d..f500453 100644
--- a/cras/src/dsp/tests/cmpraw.c
+++ b/cras/src/dsp/tests/cmpraw.c
@@ -49,8 +49,8 @@
 			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 f313d38..c81a181 100644
--- a/cras/src/dsp/tests/crossover2_test.c
+++ b/cras/src/dsp/tests/crossover2_test.c
@@ -15,18 +15,15 @@
 #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 267438d..5207cca 100644
--- a/cras/src/dsp/tests/crossover_test.c
+++ b/cras/src/dsp/tests/crossover_test.c
@@ -15,18 +15,15 @@
 #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,
@@ -34,8 +31,8 @@
 {
 	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)
@@ -68,7 +65,8 @@
 
 	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 7beaa9f..2093a5d 100644
--- a/cras/src/dsp/tests/dcblock_test.c
+++ b/cras/src/dsp/tests/dcblock_test.c
@@ -13,18 +13,15 @@
 #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 */
@@ -32,7 +29,9 @@
 {
 	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 */
@@ -45,11 +44,11 @@
 
 	float *data = read_raw(input_filename, &frames);
 
-	dcblockl = dcblock_new(0.995, 48000);
-	dcblockr = dcblock_new(0.995, 48000);
+	dcblockl = dcblock_new(0.995);
+	dcblockr = dcblock_new(0.995);
 	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 17ccbcd..800dd79 100644
--- a/cras/src/dsp/tests/drc_test.c
+++ b/cras/src/dsp/tests/drc_test.c
@@ -12,18 +12,15 @@
 #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 44f7257..f545fc8 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,25 +13,24 @@
 #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)));
 }
@@ -79,13 +78,13 @@
 	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);
@@ -126,12 +125,10 @@
 		}
 	}
 	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,
@@ -142,13 +139,11 @@
 			      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);
@@ -198,11 +193,11 @@
 	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);
@@ -218,10 +213,10 @@
 
 	/* 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
 
@@ -254,14 +249,14 @@
 #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 */
@@ -270,13 +265,13 @@
 	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);
@@ -296,18 +291,19 @@
 
 	/* 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 */
@@ -317,36 +313,35 @@
 					    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 */
@@ -356,25 +351,20 @@
 					      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 36ce80b..dbcee95 100644
--- a/cras/src/dsp/tests/eq2_test.c
+++ b/cras/src/dsp/tests/eq2_test.c
@@ -13,18 +13,15 @@
 #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 */
@@ -53,18 +50,18 @@
 
 	/* 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 4adcecf..d799101 100644
--- a/cras/src/dsp/tests/eq_test.c
+++ b/cras/src/dsp/tests/eq_test.c
@@ -13,18 +13,15 @@
 #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 */
@@ -42,12 +39,12 @@
 	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);
@@ -87,12 +84,12 @@
 
 	/* 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);
@@ -102,12 +99,12 @@
 
 	/* 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 d75e28f..65c1d92 100644
--- a/cras/src/dsp/tests/raw.c
+++ b/cras/src/dsp/tests/raw.c
@@ -43,8 +43,8 @@
 	/* 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 @@
 
 	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/.clang-format b/cras/src/fuzz/.clang-format
deleted file mode 100644
index 3f19e61..0000000
--- a/cras/src/fuzz/.clang-format
+++ /dev/null
@@ -1 +0,0 @@
-BasedOnStyle: Chromium
diff --git a/cras/src/fuzz/README b/cras/src/fuzz/README
new file mode 100644
index 0000000..96e9076
--- /dev/null
+++ b/cras/src/fuzz/README
@@ -0,0 +1,23 @@
+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
deleted file mode 100644
index 7271602..0000000
--- a/cras/src/fuzz/README.md
+++ /dev/null
@@ -1,40 +0,0 @@
-# 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 a2a5650..9ae5fb1 100644
--- a/cras/src/fuzz/rclient_message.cc
+++ b/cras/src/fuzz/rclient_message.cc
@@ -1,4 +1,4 @@
-/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+/* Copyright 2017 The Chromium Authors. All rights reserved.
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
@@ -16,25 +16,29 @@
 #include "cras_system_state.h"
 }
 
-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);
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+  cras_rclient *client = cras_rclient_create(0, 0);
+  cras_rclient_buffer_from_client(client, data, size, -1);
   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 fe54e0e..4f9f131 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 receiving audio events from aud_fd. This message
+ *    the client should start receving 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
@@ -61,12 +61,13 @@
 static const size_t HOTWORD_BLOCK_SIZE = 320;
 
 /* Commands sent from the user to the running client. */
-enum { CLIENT_STOP,
-       CLIENT_ADD_STREAM,
-       CLIENT_REMOVE_STREAM,
-       CLIENT_SET_STREAM_VOLUME_SCALER,
-       CLIENT_SERVER_CONNECT,
-       CLIENT_SERVER_CONNECT_ASYNC,
+enum {
+	CLIENT_STOP,
+	CLIENT_ADD_STREAM,
+	CLIENT_REMOVE_STREAM,
+	CLIENT_SET_STREAM_VOLUME_SCALER,
+	CLIENT_SERVER_CONNECT,
+	CLIENT_SERVER_CONNECT_ASYNC,
 };
 
 struct command_msg {
@@ -94,7 +95,8 @@
 };
 
 /* Commands send from a running stream to the client. */
-enum { CLIENT_STREAM_EOF,
+enum {
+	CLIENT_STREAM_EOF,
 };
 
 struct stream_msg {
@@ -103,13 +105,10 @@
 };
 
 enum CRAS_THREAD_STATE {
-	CRAS_THREAD_STOP,
-	/* Isn't (shouldn't be) running. */
-	CRAS_THREAD_WARMUP,
-	/* Is started, but not fully functional: waiting
-	 * for resources to be ready for example. */
-	CRAS_THREAD_RUNNING,
-	/* Is running and fully functional. */
+	CRAS_THREAD_STOP,	/* Isn't (shouldn't be) running. */
+	CRAS_THREAD_WARMUP,	/* Is started, but not fully functional: waiting
+				 * for resources to be ready for example. */
+	CRAS_THREAD_RUNNING,	/* Is running and fully functional. */
 };
 
 /* Manage information for a thread. */
@@ -125,7 +124,6 @@
 	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;
@@ -133,24 +131,21 @@
 	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.
  * id - Unique stream identifier.
  * aud_fd - After server connects audio messages come in here.
- * direction - playback, capture, or loopback (see CRAS_STREAM_DIRECTION).
+ * direction - playback, capture, both, or loopback (see CRAS_STREAM_DIRECTION).
  * flags - Currently not used.
- * volume_scaler - Amount to scale the stream by, 0.0 to 1.0. Client could
- *    change this scaler value before stream actually connected, so we need
- *    to cache it until shm is prepared and apply it.
+ * volume_scaler - Amount to scale the stream by, 0.0 to 1.0.
  * tid - Thread id of the audio thread spawned for this stream.
  * running - Audio thread runs while this is non-zero.
  * wake_fds - Pipe to wake the audio thread.
  * client - The client this stream is attached to.
  * config - Audio stream configuration.
- * shm - Shared memory used to exchange audio samples with the server.
+ * capture_shm - Shared memory used to exchange audio samples with the server.
+ * play_shm - Shared memory used to exchange audio samples with the server.
  * prev, next - Form a linked list of streams attached to a client.
  */
 struct client_stream {
@@ -163,30 +158,33 @@
 	int wake_fds[2]; /* Pipe to wake the thread */
 	struct cras_client *client;
 	struct cras_stream_params *config;
-	struct cras_audio_shm *shm;
+	struct cras_audio_shm capture_shm;
+	int capture_shm_size;
+	struct cras_audio_shm play_shm;
+	int play_shm_size;
 	struct client_stream *prev, *next;
 };
 
 /* State of the socket. */
 typedef enum cras_socket_state {
 	CRAS_SOCKET_STATE_DISCONNECTED,
-	/* Not connected. Also used to cleanup the current connection
-	 * before restarting the connection attempt. */
+		/* Not connected. Also used to cleanup the current connection
+		 * before restarting the connection attempt. */
 	CRAS_SOCKET_STATE_WAIT_FOR_SOCKET,
-	/* Waiting for the socket file to exist. Socket file existence
-	 * is monitored using cras_file_wait. */
+		/* Waiting for the socket file to exist. Socket file existence
+		 * is monitored using cras_file_wait. */
 	CRAS_SOCKET_STATE_WAIT_FOR_WRITABLE,
-	/* Waiting for the socket to have something at the other end. */
+		/* Waiting for the socket to have something at the other end. */
 	CRAS_SOCKET_STATE_FIRST_MESSAGE,
-	/* Waiting for the first messages from the server and set our
-	 * client ID. */
+		/* Waiting for the first messages from the server and set our
+		 * client ID. */
 	CRAS_SOCKET_STATE_CONNECTED,
-	/* The socket is connected and working. */
+		/* The socket is connected and working. */
 	CRAS_SOCKET_STATE_ERROR_DELAY,
-	/* There was an error during one of the above states. Sleep for
-	 * a bit before continuing. If this state could not be initiated
-	 * then we move to the DISCONNECTED state and notify via the
-	 * connection callback. */
+		/* There was an error during one of the above states. Sleep for
+		 * a bit before continuing. If this state could not be initiated
+		 * then we move to the DISCONNECTED state and notify via the
+		 * connection callback. */
 } cras_socket_state_t;
 
 /* Represents a client used to communicate with the audio server.
@@ -208,10 +206,10 @@
  * 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.
@@ -236,10 +234,9 @@
 	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;
@@ -258,9 +255,8 @@
 	pthread_rwlock_t server_state_rwlock;
 };
 
-#define to_client_int(cptr)                                                    \
-	((struct client_int *)((char *)cptr -                                  \
-			       offsetof(struct client_int, client)))
+#define to_client_int(cptr) \
+((struct client_int *)((char *)cptr - offsetof(struct client_int, client)))
 
 /*
  * Holds the hotword stream format, params, and ID used when waiting for a
@@ -293,7 +289,8 @@
  *    lock_rc - The result of server_state_rdlock or
  *              server_state_wrlock.
  */
-static void server_state_unlock(const struct cras_client *client, int lock_rc)
+static void server_state_unlock(const struct cras_client *client,
+				int lock_rc)
 {
 	struct client_int *client_int;
 
@@ -410,14 +407,16 @@
  * that the timer has expired, and restart the connection by moving to
  * WAIT_FOR_SOCKET state.
  */
-static int error_delay_next_action(struct cras_client *client, int poll_revents)
+static int error_delay_next_action(struct cras_client *client,
+				   int poll_revents)
 {
 	int rc;
 	struct itimerspec timeout;
 
 	if (client->server_fd == -1) {
-		client->server_fd = timerfd_create(CLOCK_MONOTONIC,
-						   TFD_NONBLOCK | TFD_CLOEXEC);
+		client->server_fd = timerfd_create(
+					CLOCK_MONOTONIC,
+					TFD_NONBLOCK|TFD_CLOEXEC);
 		if (client->server_fd == -1) {
 			rc = -errno;
 			syslog(LOG_ERR,
@@ -462,8 +461,8 @@
 static void wait_for_socket_next_action(struct cras_client *client)
 {
 	if (client->sock_file_exists)
-		server_fd_move_to_state(client,
-					CRAS_SOCKET_STATE_WAIT_FOR_WRITABLE);
+		server_fd_move_to_state(
+			client, CRAS_SOCKET_STATE_WAIT_FOR_WRITABLE);
 }
 
 /*
@@ -491,7 +490,8 @@
 			       strerror(-rc));
 			return rc;
 		}
-	} else if ((poll_revents & POLLOUT) == 0) {
+	}
+	else if ((poll_revents & POLLOUT) == 0) {
 		return 0;
 	}
 
@@ -516,7 +516,8 @@
 			 * to move the state machine. */
 			close(client->server_fd);
 			client->server_fd = -1;
-		} else if (rc != -EINPROGRESS) {
+		}
+		else if (rc != -EINPROGRESS) {
 			syslog(LOG_ERR,
 			       "cras_client: server connect failed: %s",
 			       strerror(-rc));
@@ -549,8 +550,8 @@
 	eventfd_write(client->server_event_fd, 1);
 	if (client->server_connection_cb)
 		client->server_connection_cb(
-			client, CRAS_CONN_STATUS_CONNECTED,
-			client->server_connection_user_arg);
+				client, CRAS_CONN_STATUS_CONNECTED,
+				client->server_connection_user_arg);
 	return 0;
 }
 
@@ -623,7 +624,7 @@
 
 	/* Stop all playing streams.
 	 * TODO(muirj): Pause and resume streams. */
-	DL_FOREACH (client->streams, s) {
+	DL_FOREACH(client->streams, s) {
 		s->config->err_cb(client, s->id, -ENOTCONN,
 				  s->config->user_data);
 		client_thread_rm_stream(client, s->id);
@@ -662,11 +663,15 @@
 		/* We're disconnected and there was a failure to setup
 		 * automatic reconnection, so call the server error
 		 * callback now. */
-		server_fd_move_to_state(client, CRAS_SOCKET_STATE_DISCONNECTED);
+		server_fd_move_to_state(
+			client, CRAS_SOCKET_STATE_DISCONNECTED);
 		if (client->server_connection_cb)
 			client->server_connection_cb(
-				client, CRAS_CONN_STATUS_FAILED,
-				client->server_connection_user_arg);
+					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:
@@ -674,18 +679,19 @@
 		/* We are running this state transition while a connection is
 		 * in progress for an error case. When there is no error, we
 		 * come into this function in the DISCONNECTED state. */
-		server_fd_move_to_state(client, CRAS_SOCKET_STATE_ERROR_DELAY);
+		server_fd_move_to_state(
+			client, CRAS_SOCKET_STATE_ERROR_DELAY);
 		break;
 	case CRAS_SOCKET_STATE_CONNECTED:
 		/* Disconnected from CRAS (for an error), wait for the socket
 		 * file to be (re)created. */
-		server_fd_move_to_state(client,
-					CRAS_SOCKET_STATE_WAIT_FOR_SOCKET);
+		server_fd_move_to_state(
+			client, CRAS_SOCKET_STATE_WAIT_FOR_SOCKET);
 		/* Notify the caller that we aren't connected anymore. */
 		if (client->server_connection_cb)
 			client->server_connection_cb(
-				client, CRAS_CONN_STATUS_DISCONNECTED,
-				client->server_connection_user_arg);
+					client, CRAS_CONN_STATUS_DISCONNECTED,
+					client->server_connection_user_arg);
 		break;
 	}
 }
@@ -809,7 +815,8 @@
  * If the socket file is deleted, then cause a disconnect from the server.
  * Otherwise, start a reconnect depending on the server_fd_state.
  */
-static int sock_file_wait_dispatch(struct cras_client *client, int poll_revents)
+static int sock_file_wait_dispatch(struct cras_client *client,
+				   int poll_revents)
 {
 	int rc;
 
@@ -868,7 +875,8 @@
  *    0 for success, negative error code on failure.
  */
 static int connect_to_server(struct cras_client *client,
-			     struct timespec *timeout, bool use_command_thread)
+			     struct timespec *timeout,
+			     bool use_command_thread)
 {
 	int rc;
 	struct pollfd poll_fd[2];
@@ -894,7 +902,7 @@
 	poll_fd[0].events = POLLIN;
 
 	rc = server_connect(client);
-	while (rc == 0) {
+	while(rc == 0) {
 		// Wait until we've connected or until there is a timeout.
 		// Meanwhile handle incoming actions on our fds.
 
@@ -904,15 +912,16 @@
 			continue;
 
 		if (poll_fd[0].revents) {
-			rc = sock_file_wait_dispatch(client,
-						     poll_fd[0].revents);
+			rc = sock_file_wait_dispatch(
+					client, poll_fd[0].revents);
 			continue;
 		}
 
 		if (poll_fd[1].revents) {
 			rc = server_fd_dispatch(client, poll_fd[1].revents);
-			if (rc == 0 && client->server_fd_state ==
-					       CRAS_SOCKET_STATE_CONNECTED)
+			if (rc == 0 &&
+			    client->server_fd_state ==
+					CRAS_SOCKET_STATE_CONNECTED)
 				break;
 		}
 	}
@@ -925,7 +934,8 @@
 }
 
 static int connect_to_server_wait_retry(struct cras_client *client,
-					int timeout_ms, bool use_command_thread)
+					int timeout_ms,
+					bool use_command_thread)
 {
 	struct timespec timeout_value;
 	struct timespec *timeout;
@@ -950,8 +960,8 @@
 static int connect_to_server_wait(struct cras_client *client,
 				  bool use_command_thread)
 {
-	return connect_to_server_wait_retry(client, SERVER_CONNECT_TIMEOUT_MS,
-					    use_command_thread);
+	return connect_to_server_wait_retry(
+			client, SERVER_CONNECT_TIMEOUT_MS, use_command_thread);
 }
 
 /*
@@ -1026,7 +1036,7 @@
 {
 	/* Always return the beginning of the read buffer because Chrome expects
 	 * so. */
-	*captured_frames = cras_shm_get_read_buffer_base(stream->shm);
+	*captured_frames = cras_shm_get_read_buffer_base(&stream->capture_shm);
 
 	/* Don't ask for more frames than the client desires. */
 	if (stream->flags & BULK_AUDIO_OK)
@@ -1037,7 +1047,7 @@
 	/* If shm readable frames is less than client requests, that means
 	 * overrun has happened in server side. Don't send partial corrupted
 	 * buffer to client. */
-	if (cras_shm_get_curr_read_frames(stream->shm) < num_frames)
+	if (cras_shm_get_curr_read_frames(&stream->capture_shm) < num_frames)
 		return 0;
 
 	return num_frames;
@@ -1046,10 +1056,11 @@
 static void complete_capture_read_current(struct client_stream *stream,
 					  unsigned int num_frames)
 {
-	cras_shm_buffer_read_current(stream->shm, num_frames);
+	cras_shm_buffer_read_current(&stream->capture_shm, num_frames);
 }
 
-static int send_capture_reply(struct client_stream *stream, unsigned int frames,
+static int send_capture_reply(struct client_stream *stream,
+			      unsigned int frames,
 			      int err)
 {
 	struct audio_message aud_msg;
@@ -1098,15 +1109,23 @@
 	if (num_frames == 0)
 		return 0;
 
-	cras_timespec_to_timespec(&ts, &stream->shm->header->ts);
+	cras_timespec_to_timespec(&ts, &stream->capture_shm.area->ts);
 
 	if (config->unified_cb)
-		frames = config->unified_cb(stream->client, stream->id,
-					    captured_frames, NULL, num_frames,
-					    &ts, NULL, config->user_data);
+		frames = config->unified_cb(stream->client,
+					    stream->id,
+					    captured_frames,
+					    NULL,
+					    num_frames,
+					    &ts,
+					    NULL,
+					    config->user_data);
 	else
-		frames = config->aud_cb(stream->client, stream->id,
-					captured_frames, num_frames, &ts,
+		frames = config->aud_cb(stream->client,
+					stream->id,
+					captured_frames,
+					num_frames,
+					&ts,
 					config->user_data);
 	if (frames < 0) {
 		send_stream_message(stream, CLIENT_STREAM_EOF);
@@ -1123,7 +1142,8 @@
 
 /* Notifies the server that "frames" samples have been written. */
 static int send_playback_reply(struct client_stream *stream,
-			       unsigned int frames, int error)
+			       unsigned int frames,
+			       int error)
 {
 	struct audio_message aud_msg;
 	int rc;
@@ -1152,7 +1172,7 @@
 	int frames;
 	int rc = 0;
 	struct cras_stream_params *config;
-	struct cras_audio_shm *shm = stream->shm;
+	struct cras_audio_shm *shm = &stream->play_shm;
 	struct timespec ts;
 
 	config = stream->config;
@@ -1163,21 +1183,30 @@
 		return 0;
 	}
 
-	buf = cras_shm_get_write_buffer_base(shm);
+	buf = cras_shm_get_write_buffer_base(&stream->play_shm);
 
 	/* Limit the amount of frames to the configured amount. */
 	num_frames = MIN(num_frames, config->cb_threshold);
 
-	cras_timespec_to_timespec(&ts, &shm->header->ts);
+	cras_timespec_to_timespec(&ts, &shm->area->ts);
 
 	/* Get samples from the user */
 	if (config->unified_cb)
-		frames = config->unified_cb(stream->client, stream->id, NULL,
-					    buf, num_frames, NULL, &ts,
-					    config->user_data);
+		frames = config->unified_cb(stream->client,
+				stream->id,
+				NULL,
+				buf,
+				num_frames,
+				NULL,
+				&ts,
+				config->user_data);
 	else
-		frames = config->aud_cb(stream->client, stream->id, buf,
-					num_frames, &ts, config->user_data);
+		frames = config->aud_cb(stream->client,
+				stream->id,
+				buf,
+				num_frames,
+				&ts,
+				config->user_data);
 	if (frames < 0) {
 		send_stream_message(stream, CLIENT_STREAM_EOF);
 		rc = frames;
@@ -1230,11 +1259,11 @@
 		/* While we are warming up, aud_fd may not be valid and some
 		 * shared memory resources may not yet be available. */
 		aud_fd = (stream->thread.state == CRAS_THREAD_WARMUP) ?
-				 -1 :
-				 stream->aud_fd;
-		num_read =
-			read_with_wake_fd(stream->wake_fds[0], aud_fd,
-					  (uint8_t *)&aud_msg, sizeof(aud_msg));
+			 -1 : stream->aud_fd;
+		num_read = read_with_wake_fd(stream->wake_fds[0],
+					     aud_fd,
+					     (uint8_t *)&aud_msg,
+					     sizeof(aud_msg));
 		if (num_read < 0)
 			return (void *)-EIO;
 		if (num_read == 0)
@@ -1243,11 +1272,13 @@
 		switch (aud_msg.id) {
 		case AUDIO_MESSAGE_DATA_READY:
 			thread_terminated = handle_capture_data_ready(
-				stream, aud_msg.frames);
+					stream,
+					aud_msg.frames);
 			break;
 		case AUDIO_MESSAGE_REQUEST_DATA:
-			thread_terminated =
-				handle_playback_request(stream, aud_msg.frames);
+			thread_terminated = handle_playback_request(
+					stream,
+					aud_msg.frames);
 			break;
 		default:
 			break;
@@ -1315,7 +1346,8 @@
 	rc = pthread_create(&stream->thread.tid, NULL, audio_thread, stream);
 	if (rc) {
 		pthread_mutex_unlock(&stream->client->stream_start_lock);
-		syslog(LOG_ERR, "cras_client: Couldn't create audio stream: %s",
+		syslog(LOG_ERR,
+		       "cras_client: Couldn't create audio stream: %s",
 		       strerror(rc));
 		stream->thread.state = CRAS_THREAD_STOP;
 		stop_aud_thread(stream, 0);
@@ -1325,8 +1357,7 @@
 	clock_gettime(CLOCK_REALTIME, &future);
 	future.tv_sec += 2; /* Wait up to two seconds. */
 	rc = pthread_cond_timedwait(&stream->client->stream_start_cond,
-				    &stream->client->stream_start_lock,
-				    &future);
+				    &stream->client->stream_start_lock, &future);
 	pthread_mutex_unlock(&stream->client->stream_start_lock);
 	if (rc != 0) {
 		/* Something is very wrong: try to cancel the thread and don't
@@ -1344,8 +1375,8 @@
  */
 
 /* Gets the update_count of the server state shm region. */
-static inline unsigned
-begin_server_state_read(const struct cras_server_state *state)
+static inline
+unsigned begin_server_state_read(const struct cras_server_state *state)
 {
 	unsigned count;
 
@@ -1359,20 +1390,44 @@
 /* Checks if the update count of the server state shm region has changed from
  * count.  Returns 0 if the count still matches.
  */
-static inline int end_server_state_read(const struct cras_server_state *state,
-					unsigned count)
+static inline
+int end_server_state_read(const struct cras_server_state *state, unsigned count)
 {
 	__sync_synchronize();
 	if (count != *(volatile unsigned *)&state->update_count)
 		return -EAGAIN;
 	return 0;
+
+}
+
+/* Gets the shared memory region used to share audio data with the server. */
+static int config_shm(struct cras_audio_shm *shm, int shm_fd, size_t size)
+{
+	shm->area = (struct cras_audio_shm_area *)mmap(
+			NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED,
+			shm_fd, 0);
+	if (shm->area == (struct cras_audio_shm_area *)-1) {
+		syslog(LOG_ERR,
+		       "cras_client: mmap failed to map shm for stream.");
+		return errno;
+	}
+	/* Copy server shm config locally. */
+	cras_shm_copy_shared_config(shm);
+
+	return 0;
 }
 
 /* Release shm areas if references to them are held. */
 static void free_shm(struct client_stream *stream)
 {
-	cras_audio_shm_destroy(stream->shm);
-	stream->shm = NULL;
+	if (stream->capture_shm.area) {
+		munmap(stream->capture_shm.area, stream->capture_shm_size);
+	}
+	if (stream->play_shm.area) {
+		munmap(stream->play_shm.area, stream->play_shm_size);
+	}
+	stream->capture_shm.area = NULL;
+	stream->play_shm.area = NULL;
 }
 
 /* Handles the stream connected message from the server.  Check if we need a
@@ -1382,13 +1437,11 @@
 			    const struct cras_client_stream_connected *msg,
 			    const int stream_fds[2], const unsigned int num_fds)
 {
-	int rc, samples_prot;
-	unsigned int i;
+	int rc;
 	struct cras_audio_format mfmt;
-	struct cras_shm_info header_info, samples_info;
 
 	if (msg->err || num_fds != 2) {
-		syslog(LOG_ERR, "cras_client: Error setting up stream %d\n",
+		syslog(LOG_ERR, "cras_client: Error Setting up stream %d\n",
 		       msg->err);
 		rc = msg->err;
 		goto err_ret;
@@ -1396,32 +1449,32 @@
 
 	unpack_cras_audio_format(&mfmt, &msg->format);
 
-	rc = cras_shm_info_init_with_fd(stream_fds[0], cras_shm_header_size(),
-					&header_info);
-	if (rc < 0)
-		goto err_ret;
-
-	rc = cras_shm_info_init_with_fd(stream_fds[1], msg->samples_shm_size,
-					&samples_info);
-	if (rc < 0) {
-		cras_shm_info_cleanup(&header_info);
-		goto err_ret;
+	if (cras_stream_has_input(stream->direction)) {
+		rc = config_shm(&stream->capture_shm,
+				stream_fds[0],
+				msg->shm_max_size);
+		if (rc < 0) {
+			syslog(LOG_ERR,
+			       "cras_client: Error configuring capture shm");
+			goto err_ret;
+		}
+		stream->capture_shm_size = msg->shm_max_size;
 	}
 
-	samples_prot = 0;
-	if (stream->direction == CRAS_STREAM_OUTPUT)
-		samples_prot = PROT_WRITE;
-	else
-		samples_prot = PROT_READ;
+	if (cras_stream_uses_output_hw(stream->direction)) {
+		rc = config_shm(&stream->play_shm,
+				stream_fds[1],
+				msg->shm_max_size);
+		if (rc < 0) {
+			syslog(LOG_ERR,
+			       "cras_client: Error configuring playback shm");
+			goto err_ret;
+		}
+		stream->play_shm_size = msg->shm_max_size;
 
-	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;
+		cras_shm_set_volume_scaler(&stream->play_shm,
+					   stream->volume_scaler);
 	}
-	cras_shm_copy_shared_config(stream->shm);
-	cras_shm_set_volume_scaler(stream->shm, stream->volume_scaler);
 
 	stream->thread.state = CRAS_THREAD_RUNNING;
 	wake_aud_thread(stream);
@@ -1431,20 +1484,19 @@
 	return 0;
 err_ret:
 	stop_aud_thread(stream, 1);
-	for (i = 0; i < num_fds; i++)
-		close(stream_fds[i]);
+	close(stream_fds[0]);
+	close(stream_fds[1]);
 	free_shm(stream);
 	return rc;
 }
 
 static int send_connect_message(struct cras_client *client,
-				struct client_stream *stream, uint32_t dev_idx)
+				struct client_stream *stream,
+				uint32_t dev_idx)
 {
 	int rc;
 	struct cras_connect_message serv_msg;
-	int sock[2] = { -1, -1 };
-	int fds[2] = { -1, -1 };
-	unsigned int num_fds;
+	int sock[2] = {-1, -1};
 
 	/* Create a socket pair for the server to notify of audio events. */
 	rc = socketpair(AF_UNIX, SOCK_STREAM, 0, sock);
@@ -1454,21 +1506,18 @@
 		goto fail;
 	}
 
-	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++;
-	}
+	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);
 	rc = cras_send_with_fds(client->server_fd, &serv_msg, sizeof(serv_msg),
-				fds, num_fds);
+			       &sock[1], 1);
 	if (rc != sizeof(serv_msg)) {
 		rc = EIO;
 		syslog(LOG_ERR,
@@ -1478,8 +1527,6 @@
 
 	stream->aud_fd = sock[0];
 	close(sock[1]);
-	if (stream->config->client_shm_fd != -1)
-		close(stream->config->client_shm_fd);
 	return 0;
 
 fail:
@@ -1487,8 +1534,6 @@
 		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;
 }
 
@@ -1506,10 +1551,10 @@
 
 	/* Find the hotword device index. */
 	if ((stream->flags & HOTWORD_STREAM) == HOTWORD_STREAM &&
-	    dev_idx == NO_DEVICE) {
+			dev_idx == NO_DEVICE) {
 		int hotword_idx;
-		hotword_idx = cras_client_get_first_dev_type_idx(
-			client, CRAS_NODE_TYPE_HOTWORD, CRAS_STREAM_INPUT);
+		hotword_idx = cras_client_get_first_dev_type_idx(client,
+				CRAS_NODE_TYPE_HOTWORD, CRAS_STREAM_INPUT);
 		if (hotword_idx < 0) {
 			syslog(LOG_ERR,
 			       "cras_client: add_stream: Finding hotword dev");
@@ -1554,7 +1599,8 @@
 				   cras_stream_id_t stream_id)
 {
 	struct cras_disconnect_stream_message msg;
-	struct client_stream *stream = stream_from_id(client, stream_id);
+	struct client_stream *stream =
+		stream_from_id(client, stream_id);
 	int rc;
 
 	if (stream == NULL)
@@ -1584,7 +1630,7 @@
 	return 0;
 }
 
-/* Sets the volume scaling factor for a playback or capture stream. */
+/* Sets the volume scaling factor for a playing stream. */
 static int client_thread_set_stream_volume(struct cras_client *client,
 					   cras_stream_id_t stream_id,
 					   float volume_scaler)
@@ -1596,20 +1642,12 @@
 		return -EINVAL;
 
 	stream->volume_scaler = volume_scaler;
-	if (stream->shm)
-		cras_shm_set_volume_scaler(stream->shm, volume_scaler);
+	if (stream->play_shm.area != NULL)
+		cras_shm_set_volume_scaler(&stream->play_shm, volume_scaler);
 
 	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)
 {
@@ -1623,8 +1661,8 @@
 	}
 
 	client->server_state = (struct cras_server_state *)mmap(
-		NULL, sizeof(*client->server_state), PROT_READ, MAP_SHARED,
-		shm_fd, 0);
+			NULL, sizeof(*client->server_state),
+			PROT_READ, MAP_SHARED, shm_fd, 0);
 	rc = -errno;
 	close(shm_fd);
 	if (client->server_state == (struct cras_server_state *)-1) {
@@ -1649,8 +1687,9 @@
 	return rc;
 }
 
-static void cras_client_get_hotword_models_ready(struct cras_client *client,
-						 const char *hotword_models)
+static void cras_client_get_hotword_models_ready(
+		struct cras_client *client,
+		const char *hotword_models)
 {
 	if (!client->get_hotword_models_cb)
 		return;
@@ -1694,8 +1733,7 @@
 			stream_from_id(client, cmsg->stream_id);
 		if (stream == NULL) {
 			if (num_fds != 2) {
-				syslog(LOG_ERR,
-				       "cras_client: Error receiving "
+				syslog(LOG_ERR, "cras_client: Error receiving "
 				       "stream 0x%x connected message",
 				       cmsg->stream_id);
 				return -EINVAL;
@@ -1712,7 +1750,9 @@
 		}
 		rc = stream_connected(stream, cmsg, server_fds, num_fds);
 		if (rc < 0)
-			stream->config->err_cb(stream->client, stream->id, rc,
+			stream->config->err_cb(stream->client,
+					       stream->id,
+					       rc,
 					       stream->config->user_data);
 		break;
 	}
@@ -1721,19 +1761,11 @@
 			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;
-		cras_client_get_hotword_models_ready(
-			client, (const char *)cmsg->hotword_models);
+		cras_client_get_hotword_models_ready(client,
+				(const char *)cmsg->hotword_models);
 		break;
 	}
 	case CRAS_CLIENT_OUTPUT_VOLUME_CHANGED: {
@@ -1741,7 +1773,8 @@
 			(struct cras_client_volume_changed *)msg;
 		if (client->observer_ops.output_volume_changed)
 			client->observer_ops.output_volume_changed(
-				client->observer_context, cmsg->volume);
+					client->observer_context,
+					cmsg->volume);
 		break;
 	}
 	case CRAS_CLIENT_OUTPUT_MUTE_CHANGED: {
@@ -1749,8 +1782,10 @@
 			(struct cras_client_mute_changed *)msg;
 		if (client->observer_ops.output_mute_changed)
 			client->observer_ops.output_mute_changed(
-				client->observer_context, cmsg->muted,
-				cmsg->user_muted, cmsg->mute_locked);
+					client->observer_context,
+					cmsg->muted,
+					cmsg->user_muted,
+					cmsg->mute_locked);
 		break;
 	}
 	case CRAS_CLIENT_CAPTURE_GAIN_CHANGED: {
@@ -1758,7 +1793,8 @@
 			(struct cras_client_volume_changed *)msg;
 		if (client->observer_ops.capture_gain_changed)
 			client->observer_ops.capture_gain_changed(
-				client->observer_context, cmsg->volume);
+					client->observer_context,
+					cmsg->volume);
 		break;
 	}
 	case CRAS_CLIENT_CAPTURE_MUTE_CHANGED: {
@@ -1766,14 +1802,15 @@
 			(struct cras_client_mute_changed *)msg;
 		if (client->observer_ops.capture_mute_changed)
 			client->observer_ops.capture_mute_changed(
-				client->observer_context, cmsg->muted,
-				cmsg->mute_locked);
+					client->observer_context,
+					cmsg->muted,
+					cmsg->mute_locked);
 		break;
 	}
 	case CRAS_CLIENT_NODES_CHANGED: {
 		if (client->observer_ops.nodes_changed)
 			client->observer_ops.nodes_changed(
-				client->observer_context);
+					client->observer_context);
 		break;
 	}
 	case CRAS_CLIENT_ACTIVE_NODE_CHANGED: {
@@ -1783,8 +1820,8 @@
 			(enum CRAS_STREAM_DIRECTION)cmsg->direction;
 		if (client->observer_ops.active_node_changed)
 			client->observer_ops.active_node_changed(
-				client->observer_context, direction,
-				cmsg->node_id);
+					client->observer_context,
+					direction, cmsg->node_id);
 		break;
 	}
 	case CRAS_CLIENT_OUTPUT_NODE_VOLUME_CHANGED: {
@@ -1792,8 +1829,9 @@
 			(struct cras_client_node_value_changed *)msg;
 		if (client->observer_ops.output_node_volume_changed)
 			client->observer_ops.output_node_volume_changed(
-				client->observer_context, cmsg->node_id,
-				cmsg->value);
+					client->observer_context,
+					cmsg->node_id,
+					cmsg->value);
 		break;
 	}
 	case CRAS_CLIENT_NODE_LEFT_RIGHT_SWAPPED_CHANGED: {
@@ -1801,8 +1839,9 @@
 			(struct cras_client_node_value_changed *)msg;
 		if (client->observer_ops.node_left_right_swapped_changed)
 			client->observer_ops.node_left_right_swapped_changed(
-				client->observer_context, cmsg->node_id,
-				cmsg->value);
+					client->observer_context,
+					cmsg->node_id,
+					cmsg->value);
 		break;
 	}
 	case CRAS_CLIENT_INPUT_NODE_GAIN_CHANGED: {
@@ -1810,19 +1849,20 @@
 			(struct cras_client_node_value_changed *)msg;
 		if (client->observer_ops.input_node_gain_changed)
 			client->observer_ops.input_node_gain_changed(
-				client->observer_context, cmsg->node_id,
-				cmsg->value);
+					client->observer_context,
+					cmsg->node_id,
+					cmsg->value);
 		break;
 	}
 	case CRAS_CLIENT_NUM_ACTIVE_STREAMS_CHANGED: {
 		struct cras_client_num_active_streams_changed *cmsg =
-			(struct cras_client_num_active_streams_changed *)msg;
+		    (struct cras_client_num_active_streams_changed *)msg;
 		enum CRAS_STREAM_DIRECTION direction =
 			(enum CRAS_STREAM_DIRECTION)cmsg->direction;
 		if (client->observer_ops.num_active_streams_changed)
 			client->observer_ops.num_active_streams_changed(
-				client->observer_context, direction,
-				cmsg->num_active_streams);
+					client->observer_context,
+					direction, cmsg->num_active_streams);
 		break;
 	}
 	default:
@@ -1833,7 +1873,8 @@
 }
 
 /* Handles messages from streams to this client. */
-static int handle_stream_message(struct cras_client *client, int poll_revents)
+static int handle_stream_message(struct cras_client *client,
+				 int poll_revents)
 {
 	struct stream_msg msg;
 	int rc;
@@ -1852,7 +1893,8 @@
 }
 
 /* Handles messages from users to this client. */
-static int handle_command_message(struct cras_client *client, int poll_revents)
+static int handle_command_message(struct cras_client *client,
+				  int poll_revents)
 {
 	uint8_t buf[MAX_CMD_MSG_LEN];
 	struct command_msg *msg = (struct command_msg *)buf;
@@ -1878,7 +1920,7 @@
 		struct client_stream *s;
 
 		/* Stop all playing streams */
-		DL_FOREACH (client->streams, s)
+		DL_FOREACH(client->streams, s)
 			client_thread_rm_stream(client, s->id);
 
 		/* And stop this client */
@@ -1889,7 +1931,8 @@
 	case CLIENT_ADD_STREAM: {
 		struct add_stream_command_message *add_msg =
 			(struct add_stream_command_message *)msg;
-		rc = client_thread_add_stream(client, add_msg->stream,
+		rc = client_thread_add_stream(client,
+					      add_msg->stream,
 					      add_msg->stream_id_out,
 					      add_msg->dev_idx);
 		break;
@@ -1931,7 +1974,7 @@
 {
 	struct cras_client *client = (struct cras_client *)arg;
 	struct pollfd pollfds[4];
-	int (*cbs[4])(struct cras_client * client, int poll_revents);
+	int (*cbs[4])(struct cras_client *client, int poll_revents);
 	unsigned int num_pollfds, i;
 	int rc;
 
@@ -1948,7 +1991,8 @@
 			pollfds[num_pollfds].events = POLLIN;
 			pollfds[num_pollfds].revents = 0;
 			num_pollfds++;
-		} else
+		}
+		else
 			syslog(LOG_ERR, "file wait fd: %d", rc);
 		if (client->server_fd >= 0) {
 			cbs[num_pollfds] = server_fd_dispatch;
@@ -2013,7 +2057,8 @@
 
 /* Send a simple message to the client thread that holds no data. */
 static int send_simple_cmd_msg(struct cras_client *client,
-			       cras_stream_id_t stream_id, unsigned msg_id)
+			       cras_stream_id_t stream_id,
+			       unsigned msg_id)
 {
 	struct command_msg msg;
 
@@ -2064,44 +2109,25 @@
 		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_with_type(struct cras_client **client,
-				 enum CRAS_CONNECTION_TYPE conn_type)
+int cras_client_create(struct cras_client **client)
 {
+	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;
@@ -2133,26 +2159,29 @@
 		goto free_lock;
 	}
 
-	(*client)->server_event_fd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
+	(*client)->server_event_fd = eventfd(0, EFD_CLOEXEC|EFD_NONBLOCK);
 	if ((*client)->server_event_fd < 0) {
 		syslog(LOG_ERR, "cras_client: Could not setup server eventfd.");
 		rc = -errno;
 		goto free_cond;
 	}
 
-	rc = fill_socket_file((*client), conn_type);
-	if (rc < 0) {
+	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;
 		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': %s",
-		       (*client)->sock_file, strerror(-rc));
+	if (rc != 0 && rc != -ENOENT) {
+		syslog(LOG_ERR, "cras_client: Could not setup watch for '%s'.",
+		       (*client)->sock_file);
 		goto free_error;
 	}
 	(*client)->sock_file_exists = (rc == 0);
@@ -2191,11 +2220,6 @@
 	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;
@@ -2203,6 +2227,7 @@
 		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);
@@ -2238,10 +2263,16 @@
 }
 
 struct cras_stream_params *cras_client_stream_params_create(
-	enum CRAS_STREAM_DIRECTION direction, size_t buffer_frames,
-	size_t cb_threshold, size_t unused, enum CRAS_STREAM_TYPE stream_type,
-	uint32_t flags, void *user_data, cras_playback_cb_t aud_cb,
-	cras_error_cb_t err_cb, struct cras_audio_format *format)
+		enum CRAS_STREAM_DIRECTION direction,
+		size_t buffer_frames,
+		size_t cb_threshold,
+		size_t unused,
+		enum CRAS_STREAM_TYPE stream_type,
+		uint32_t flags,
+		void *user_data,
+		cras_playback_cb_t aud_cb,
+		cras_error_cb_t err_cb,
+		struct cras_audio_format *format)
 {
 	struct cras_stream_params *params;
 
@@ -2254,24 +2285,15 @@
 	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;
@@ -2312,19 +2334,15 @@
 	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,
-	cras_unified_cb_t unified_cb, cras_error_cb_t err_cb,
-	struct cras_audio_format *format)
+		enum CRAS_STREAM_DIRECTION direction,
+		unsigned int block_size,
+		enum CRAS_STREAM_TYPE stream_type,
+		uint32_t flags,
+		void *user_data,
+		cras_unified_cb_t unified_cb,
+		cras_error_cb_t err_cb,
+		struct cras_audio_format *format)
 {
 	struct cras_stream_params *params;
 
@@ -2336,15 +2354,12 @@
 	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;
@@ -2356,8 +2371,10 @@
 }
 
 static inline int cras_client_send_add_stream_command_message(
-	struct cras_client *client, uint32_t dev_idx,
-	cras_stream_id_t *stream_id_out, struct cras_stream_params *config)
+		struct cras_client *client,
+		uint32_t dev_idx,
+		cras_stream_id_t *stream_id_out,
+		struct cras_stream_params *config)
 {
 	struct add_stream_command_message cmd_msg;
 	struct client_stream *stream;
@@ -2377,8 +2394,8 @@
 		rc = -ENOMEM;
 		goto add_failed;
 	}
-	stream->config =
-		(struct cras_stream_params *)malloc(sizeof(*(stream->config)));
+	stream->config = (struct cras_stream_params *)
+			malloc(sizeof(*(stream->config)));
 	if (stream->config == NULL) {
 		rc = -ENOMEM;
 		goto add_failed;
@@ -2388,12 +2405,9 @@
 	stream->wake_fds[0] = -1;
 	stream->wake_fds[1] = -1;
 	stream->direction = config->direction;
+	stream->volume_scaler = 1.0;
 	stream->flags = config->flags;
 
-	/* Caller might not set this volume scaler after stream created,
-	 * so always initialize it to 1.0f */
-	stream->volume_scaler = 1.0f;
-
 	cmd_msg.header.len = sizeof(cmd_msg);
 	cmd_msg.header.msg_id = CLIENT_ADD_STREAM;
 	cmd_msg.header.stream_id = stream->id;
@@ -2423,15 +2437,22 @@
 			   struct cras_stream_params *config)
 {
 	return cras_client_send_add_stream_command_message(
-		client, NO_DEVICE, stream_id_out, config);
+			client,
+			NO_DEVICE,
+			stream_id_out,
+			config);
 }
 
-int cras_client_add_pinned_stream(struct cras_client *client, uint32_t dev_idx,
+int cras_client_add_pinned_stream(struct cras_client *client,
+				  uint32_t dev_idx,
 				  cras_stream_id_t *stream_id_out,
 				  struct cras_stream_params *config)
 {
 	return cras_client_send_add_stream_command_message(
-		client, dev_idx, stream_id_out, config);
+			client,
+			dev_idx,
+			stream_id_out,
+			config);
 }
 
 int cras_client_rm_stream(struct cras_client *client,
@@ -2657,8 +2678,8 @@
 	return max_gain;
 }
 
-const struct audio_debug_info *
-cras_client_get_audio_debug_info(const struct cras_client *client)
+const struct audio_debug_info *cras_client_get_audio_debug_info(
+		const struct cras_client *client)
 {
 	const struct audio_debug_info *debug_info;
 	int lock_rc;
@@ -2672,23 +2693,9 @@
 	return debug_info;
 }
 
-const struct cras_bt_debug_info *
-cras_client_get_bt_debug_info(const struct cras_client *client)
-{
-	const struct cras_bt_debug_info *debug_info;
-	int lock_rc;
-
-	lock_rc = server_state_rdlock(client);
-	if (lock_rc)
-		return 0;
-
-	debug_info = &client->server_state->bt_debug_info;
-	server_state_unlock(client, lock_rc);
-	return debug_info;
-}
-
-const struct cras_audio_thread_snapshot_buffer *
-cras_client_get_audio_thread_snapshot_buffer(const struct cras_client *client)
+const struct cras_audio_thread_snapshot_buffer*
+	cras_client_get_audio_thread_snapshot_buffer(
+		const struct cras_client *client)
 {
 	const struct cras_audio_thread_snapshot_buffer *snapshot_buffer;
 	int lock_rc;
@@ -2721,8 +2728,7 @@
 		if (num_streams)
 			clock_gettime(CLOCK_MONOTONIC_RAW, ts);
 		else
-			cras_timespec_to_timespec(
-				ts,
+			cras_timespec_to_timespec(ts,
 				&client->server_state->last_active_stream_time);
 	}
 	if (end_server_state_read(client->server_state, version))
@@ -2774,9 +2780,18 @@
 	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)
+		struct cras_client *client,
+		cras_connection_status_cb_t connection_cb,
+		void *user_arg)
 {
 	client->server_connection_cb = connection_cb;
 	client->server_connection_user_arg = user_arg;
@@ -2897,13 +2912,13 @@
 	if (!client || !dev_name || !node_name)
 		goto quit;
 
-	devs = (struct cras_iodev_info *)malloc(CRAS_MAX_IODEVS *
-						sizeof(*devs));
+	devs = (struct cras_iodev_info *)
+			malloc(CRAS_MAX_IODEVS * sizeof(*devs));
 	if (!devs)
 		goto quit;
 
-	nodes = (struct cras_ionode_info *)malloc(CRAS_MAX_IONODES *
-						  sizeof(*nodes));
+	nodes = (struct cras_ionode_info *)
+			malloc(CRAS_MAX_IONODES * sizeof(*nodes));
 	if (!nodes)
 		goto quit;
 
@@ -2939,9 +2954,10 @@
 	return rc;
 }
 
-int cras_client_get_node_by_id(const struct cras_client *client, int input,
+int cras_client_get_node_by_id(const struct cras_client *client,
+			       int input,
 			       const cras_node_id_t node_id,
-			       struct cras_ionode_info *node_info)
+			       struct cras_ionode_info* node_info)
 {
 	size_t ndevs, nnodes;
 	struct cras_iodev_info *devs = NULL;
@@ -2954,15 +2970,15 @@
 		goto quit;
 	}
 
-	devs = (struct cras_iodev_info *)malloc(CRAS_MAX_IODEVS *
-						sizeof(*devs));
+	devs = (struct cras_iodev_info *)
+			malloc(CRAS_MAX_IODEVS * sizeof(*devs));
 	if (!devs) {
 		rc = -ENOMEM;
 		goto quit;
 	}
 
-	nodes = (struct cras_ionode_info *)malloc(CRAS_MAX_IONODES *
-						  sizeof(*nodes));
+	nodes = (struct cras_ionode_info *)
+			malloc(CRAS_MAX_IONODES * sizeof(*nodes));
 	if (!nodes) {
 		rc = -ENOMEM;
 		goto quit;
@@ -2971,11 +2987,11 @@
 	ndevs = CRAS_MAX_IODEVS;
 	nnodes = CRAS_MAX_IONODES;
 	if (input)
-		rc = cras_client_get_input_devices(client, devs, nodes, &ndevs,
-						   &nnodes);
+		rc = cras_client_get_input_devices(client, devs, nodes,
+						&ndevs, &nnodes);
 	else
-		rc = cras_client_get_output_devices(client, devs, nodes, &ndevs,
-						    &nnodes);
+		rc = cras_client_get_output_devices(client, devs, nodes,
+						&ndevs, &nnodes);
 	if (rc < 0)
 		goto quit;
 
@@ -3009,8 +3025,8 @@
 }
 
 int cras_client_set_node_attr(struct cras_client *client,
-			      cras_node_id_t node_id, enum ionode_attr attr,
-			      int value)
+			      cras_node_id_t node_id,
+			      enum ionode_attr attr, int value)
 {
 	struct cras_set_node_attr msg;
 
@@ -3121,7 +3137,8 @@
 }
 
 int cras_client_update_audio_debug_info(
-	struct cras_client *client, void (*debug_info_cb)(struct cras_client *))
+	struct cras_client *client,
+	void (*debug_info_cb)(struct cras_client *))
 {
 	struct cras_dump_audio_thread msg;
 
@@ -3136,96 +3153,9 @@
 	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(&timestamp, &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 *))
-{
-	struct cras_dump_bt msg;
-
-	if (client == NULL)
-		return -EINVAL;
-
-	if (client->debug_info_callback != NULL)
-		return -EINVAL;
-	client->debug_info_callback = debug_info_cb;
-
-	cras_fill_dump_bt(&msg);
-	return write_message_to_server(client, &msg.header);
-}
-
 int cras_client_update_audio_thread_snapshots(
-	struct cras_client *client, void (*debug_info_cb)(struct cras_client *))
+	struct cras_client *client,
+	void (*debug_info_cb)(struct cras_client *))
 {
 	struct cras_dump_snapshots msg;
 
@@ -3241,7 +3171,8 @@
 }
 
 int cras_client_set_node_volume(struct cras_client *client,
-				cras_node_id_t node_id, uint8_t volume)
+				cras_node_id_t node_id,
+				uint8_t volume)
 {
 	struct cras_set_node_attr msg;
 
@@ -3253,7 +3184,7 @@
 }
 
 int cras_client_swap_node_left_right(struct cras_client *client,
-				     cras_node_id_t node_id, int enable)
+					cras_node_id_t node_id, int enable)
 {
 	struct cras_set_node_attr msg;
 
@@ -3266,7 +3197,8 @@
 }
 
 int cras_client_set_node_capture_gain(struct cras_client *client,
-				      cras_node_id_t node_id, long gain)
+				      cras_node_id_t node_id,
+				      long gain)
 {
 	struct cras_set_node_attr msg;
 
@@ -3291,7 +3223,8 @@
 int cras_client_test_iodev_command(struct cras_client *client,
 				   unsigned int iodev_idx,
 				   enum CRAS_TEST_IODEV_CMD command,
-				   unsigned int data_len, const uint8_t *data)
+				   unsigned int data_len,
+				   const uint8_t *data)
 {
 	struct cras_test_dev_command *msg;
 	int rc;
@@ -3304,15 +3237,16 @@
 }
 
 int cras_client_config_global_remix(struct cras_client *client,
-				    unsigned num_channels, float *coefficient)
+				    unsigned num_channels,
+				    float *coefficient)
 {
 	struct cras_config_global_remix *msg;
 	int rc;
 
-	msg = (struct cras_config_global_remix *)malloc(
-		sizeof(*msg) +
-		num_channels * num_channels * sizeof(*coefficient));
-	cras_fill_config_global_remix_command(msg, num_channels, coefficient,
+	msg = (struct cras_config_global_remix *)malloc(sizeof(*msg) +
+			num_channels * num_channels * sizeof(*coefficient));
+	cras_fill_config_global_remix_command(msg, num_channels,
+					      coefficient,
 					      num_channels * num_channels);
 	rc = write_message_to_server(client, &msg->header);
 	free(msg);
@@ -3384,8 +3318,8 @@
 }
 
 int cras_client_get_hotword_models(struct cras_client *client,
-				   cras_node_id_t node_id,
-				   get_hotword_models_cb_t cb)
+				     cras_node_id_t node_id,
+				     get_hotword_models_cb_t cb)
 {
 	struct cras_get_hotword_models msg;
 
@@ -3408,15 +3342,17 @@
 }
 
 int cras_client_set_aec_dump(struct cras_client *client,
-			     cras_stream_id_t stream_id, int start, int fd)
+			      cras_stream_id_t stream_id,
+			      int start,
+			      int fd)
 {
 	struct cras_set_aec_dump msg;
 
 	cras_fill_set_aec_dump_message(&msg, stream_id, start);
 
 	if (fd != -1)
-		return cras_send_with_fds(client->server_fd, &msg, sizeof(msg),
-					  &fd, 1);
+		return cras_send_with_fds(client->server_fd, &msg,
+					  sizeof(msg), &fd, 1);
 	else
 		return write_message_to_server(client, &msg.header);
 }
@@ -3443,30 +3379,8 @@
 	return aec_supported;
 }
 
-int cras_client_get_aec_group_id(struct cras_client *client)
-{
-	int aec_group_id;
-	int lock_rc;
-
-	lock_rc = server_state_rdlock(client);
-	if (lock_rc)
-		return -1;
-
-	aec_group_id = client->server_state->aec_group_id;
-	server_state_unlock(client, lock_rc);
-	return aec_group_id;
-}
-
-int cras_client_set_bt_wbs_enabled(struct cras_client *client, bool enabled)
-{
-	struct cras_set_bt_wbs_enabled msg;
-
-	cras_fill_set_bt_wbs_enabled(&msg, enabled);
-	return write_message_to_server(client, &msg.header);
-}
-
-void cras_client_set_state_change_callback_context(struct cras_client *client,
-						   void *context)
+void cras_client_set_state_change_callback_context(
+		struct cras_client *client, void *context)
 {
 	if (!client)
 		return;
@@ -3491,111 +3405,113 @@
 }
 
 int cras_client_set_output_volume_changed_callback(
-	struct cras_client *client,
-	cras_client_output_volume_changed_callback cb)
+		struct cras_client *client,
+		cras_client_output_volume_changed_callback cb)
 {
 	if (!client)
 		return -EINVAL;
 	client->observer_ops.output_volume_changed = cb;
 	return cras_send_register_notification(
-		client, CRAS_CLIENT_OUTPUT_VOLUME_CHANGED, cb != NULL);
+			client, CRAS_CLIENT_OUTPUT_VOLUME_CHANGED, cb != NULL);
 }
 
 int cras_client_set_output_mute_changed_callback(
-	struct cras_client *client, cras_client_output_mute_changed_callback cb)
+		struct cras_client *client,
+		cras_client_output_mute_changed_callback cb)
 {
 	if (!client)
 		return -EINVAL;
 	client->observer_ops.output_mute_changed = cb;
 	return cras_send_register_notification(
-		client, CRAS_CLIENT_OUTPUT_MUTE_CHANGED, cb != NULL);
+			client, CRAS_CLIENT_OUTPUT_MUTE_CHANGED, cb != NULL);
 }
 
 int cras_client_set_capture_gain_changed_callback(
-	struct cras_client *client,
-	cras_client_capture_gain_changed_callback cb)
+		struct cras_client *client,
+		cras_client_capture_gain_changed_callback cb)
 {
 	if (!client)
 		return -EINVAL;
 	client->observer_ops.capture_gain_changed = cb;
 	return cras_send_register_notification(
-		client, CRAS_CLIENT_CAPTURE_GAIN_CHANGED, cb != NULL);
+			client, CRAS_CLIENT_CAPTURE_GAIN_CHANGED, cb != NULL);
 }
 
 int cras_client_set_capture_mute_changed_callback(
-	struct cras_client *client,
-	cras_client_capture_mute_changed_callback cb)
+		struct cras_client *client,
+		cras_client_capture_mute_changed_callback cb)
 {
 	if (!client)
 		return -EINVAL;
 	client->observer_ops.capture_mute_changed = cb;
 	return cras_send_register_notification(
-		client, CRAS_CLIENT_CAPTURE_MUTE_CHANGED, cb != NULL);
+			client, CRAS_CLIENT_CAPTURE_MUTE_CHANGED, cb != NULL);
 }
 
 int cras_client_set_nodes_changed_callback(
-	struct cras_client *client, cras_client_nodes_changed_callback cb)
+		struct cras_client *client,
+		cras_client_nodes_changed_callback cb)
 {
 	if (!client)
 		return -EINVAL;
 	client->observer_ops.nodes_changed = cb;
 	return cras_send_register_notification(
-		client, CRAS_CLIENT_NODES_CHANGED, cb != NULL);
+			client, CRAS_CLIENT_NODES_CHANGED, cb != NULL);
 }
 
 int cras_client_set_active_node_changed_callback(
-	struct cras_client *client, cras_client_active_node_changed_callback cb)
+		struct cras_client *client,
+		cras_client_active_node_changed_callback cb)
 {
 	if (!client)
 		return -EINVAL;
 	client->observer_ops.active_node_changed = cb;
 	return cras_send_register_notification(
-		client, CRAS_CLIENT_ACTIVE_NODE_CHANGED, cb != NULL);
+		   client, CRAS_CLIENT_ACTIVE_NODE_CHANGED, cb != NULL);
 }
 
 int cras_client_set_output_node_volume_changed_callback(
-	struct cras_client *client,
-	cras_client_output_node_volume_changed_callback cb)
+		struct cras_client *client,
+		cras_client_output_node_volume_changed_callback cb)
 {
 	if (!client)
 		return -EINVAL;
 	client->observer_ops.output_node_volume_changed = cb;
 	return cras_send_register_notification(
-		client, CRAS_CLIENT_OUTPUT_NODE_VOLUME_CHANGED, cb != NULL);
+		    client, CRAS_CLIENT_OUTPUT_NODE_VOLUME_CHANGED, cb != NULL);
 }
 
 int cras_client_set_node_left_right_swapped_changed_callback(
-	struct cras_client *client,
-	cras_client_node_left_right_swapped_changed_callback cb)
+		struct cras_client *client,
+		cras_client_node_left_right_swapped_changed_callback cb)
 {
 	if (!client)
 		return -EINVAL;
 	client->observer_ops.node_left_right_swapped_changed = cb;
 	return cras_send_register_notification(
-		client, CRAS_CLIENT_NODE_LEFT_RIGHT_SWAPPED_CHANGED,
-		cb != NULL);
+	       client, CRAS_CLIENT_NODE_LEFT_RIGHT_SWAPPED_CHANGED, cb != NULL);
 }
 
 int cras_client_set_input_node_gain_changed_callback(
-	struct cras_client *client,
-	cras_client_input_node_gain_changed_callback cb)
+		struct cras_client *client,
+		cras_client_input_node_gain_changed_callback cb)
 {
 	if (!client)
 		return -EINVAL;
 	client->observer_ops.input_node_gain_changed = cb;
 	return cras_send_register_notification(
-		client, CRAS_CLIENT_INPUT_NODE_GAIN_CHANGED, cb != NULL);
+		       client, CRAS_CLIENT_INPUT_NODE_GAIN_CHANGED, cb != NULL);
 }
 
 int cras_client_set_num_active_streams_changed_callback(
-	struct cras_client *client,
-	cras_client_num_active_streams_changed_callback cb)
+		struct cras_client *client,
+		cras_client_num_active_streams_changed_callback cb)
 {
 	if (!client)
 		return -EINVAL;
 	client->observer_ops.num_active_streams_changed = cb;
 	return cras_send_register_notification(
-		client, CRAS_CLIENT_NUM_ACTIVE_STREAMS_CHANGED, cb != NULL);
+	      client, CRAS_CLIENT_NUM_ACTIVE_STREAMS_CHANGED, cb != NULL);
 }
 
 static int reregister_notifications(struct cras_client *client)
@@ -3604,64 +3520,70 @@
 
 	if (client->observer_ops.output_volume_changed) {
 		rc = cras_client_set_output_volume_changed_callback(
-			client, client->observer_ops.output_volume_changed);
+				client,
+				client->observer_ops.output_volume_changed);
 		if (rc != 0)
 			return rc;
 	}
 	if (client->observer_ops.output_mute_changed) {
 		rc = cras_client_set_output_mute_changed_callback(
-			client, client->observer_ops.output_mute_changed);
+				client,
+				client->observer_ops.output_mute_changed);
 		if (rc != 0)
 			return rc;
 	}
 	if (client->observer_ops.capture_gain_changed) {
 		rc = cras_client_set_capture_gain_changed_callback(
-			client, client->observer_ops.capture_gain_changed);
+				client,
+				client->observer_ops.capture_gain_changed);
 		if (rc != 0)
 			return rc;
 	}
 	if (client->observer_ops.capture_mute_changed) {
 		rc = cras_client_set_capture_mute_changed_callback(
-			client, client->observer_ops.capture_mute_changed);
+				client,
+				client->observer_ops.capture_mute_changed);
 		if (rc != 0)
 			return rc;
 	}
 	if (client->observer_ops.nodes_changed) {
 		rc = cras_client_set_nodes_changed_callback(
-			client, client->observer_ops.nodes_changed);
+				client, client->observer_ops.nodes_changed);
 		if (rc != 0)
 			return rc;
 	}
 	if (client->observer_ops.active_node_changed) {
 		rc = cras_client_set_active_node_changed_callback(
-			client, client->observer_ops.active_node_changed);
+				client,
+				client->observer_ops.active_node_changed);
 		if (rc != 0)
 			return rc;
 	}
 	if (client->observer_ops.output_node_volume_changed) {
 		rc = cras_client_set_output_node_volume_changed_callback(
-			client,
-			client->observer_ops.output_node_volume_changed);
+			    client,
+			    client->observer_ops.output_node_volume_changed);
 		if (rc != 0)
 			return rc;
 	}
 	if (client->observer_ops.node_left_right_swapped_changed) {
 		rc = cras_client_set_node_left_right_swapped_changed_callback(
-			client,
-			client->observer_ops.node_left_right_swapped_changed);
+			  client,
+			  client->observer_ops.node_left_right_swapped_changed);
 		if (rc != 0)
 			return rc;
 	}
 	if (client->observer_ops.input_node_gain_changed) {
 		rc = cras_client_set_input_node_gain_changed_callback(
-			client, client->observer_ops.input_node_gain_changed);
+				client,
+				client->observer_ops.input_node_gain_changed);
 		if (rc != 0)
 			return rc;
 	}
 	if (client->observer_ops.num_active_streams_changed) {
 		rc = cras_client_set_num_active_streams_changed_callback(
-			client,
-			client->observer_ops.num_active_streams_changed);
+			       client,
+			       client->observer_ops.num_active_streams_changed);
 		if (rc != 0)
 			return rc;
 	}
@@ -3670,10 +3592,12 @@
 
 static int hotword_read_cb(struct cras_client *client,
 			   cras_stream_id_t stream_id,
-			   uint8_t *captured_samples, uint8_t *playback_samples,
+			   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)
 {
 	struct cras_hotword_handle *handle;
 
@@ -3685,7 +3609,9 @@
 }
 
 static int hotword_err_cb(struct cras_client *client,
-			  cras_stream_id_t stream_id, int error, void *user_arg)
+			  cras_stream_id_t stream_id,
+			  int error,
+			  void *user_arg)
 {
 	struct cras_hotword_handle *handle;
 
@@ -3720,9 +3646,14 @@
 	}
 
 	handle->params = cras_client_unified_params_create(
-		CRAS_STREAM_INPUT, HOTWORD_BLOCK_SIZE, CRAS_STREAM_TYPE_DEFAULT,
-		HOTWORD_STREAM | TRIGGER_ONLY, (void *)handle, hotword_read_cb,
-		hotword_err_cb, handle->format);
+		CRAS_STREAM_INPUT,
+		HOTWORD_BLOCK_SIZE,
+		CRAS_STREAM_TYPE_DEFAULT,
+		HOTWORD_STREAM | TRIGGER_ONLY,
+		(void *)handle,
+		hotword_read_cb,
+		hotword_err_cb,
+		handle->format);
 	if (!handle->params) {
 		ret = -ENOMEM;
 		goto cleanup_format;
diff --git a/cras/src/libcras/cras_client.h b/cras/src/libcras/cras_client.h
index 7012e2d..1817a73 100644
--- a/cras/src/libcras/cras_client.h
+++ b/cras/src/libcras/cras_client.h
@@ -76,7 +76,8 @@
  *    stream is reached.
  */
 typedef int (*cras_playback_cb_t)(struct cras_client *client,
-				  cras_stream_id_t stream_id, uint8_t *samples,
+				  cras_stream_id_t stream_id,
+				  uint8_t *samples,
 				  size_t frames,
 				  const struct timespec *sample_time,
 				  void *user_arg);
@@ -99,7 +100,8 @@
 typedef int (*cras_unified_cb_t)(struct cras_client *client,
 				 cras_stream_id_t stream_id,
 				 uint8_t *captured_samples,
-				 uint8_t *playback_samples, unsigned int frames,
+				 uint8_t *playback_samples,
+				 unsigned int frames,
 				 const struct timespec *captured_time,
 				 const struct timespec *playback_time,
 				 void *user_arg);
@@ -112,26 +114,45 @@
  *    user_arg - The argument defined in cras_client_*_params_create().
  */
 typedef int (*cras_error_cb_t)(struct cras_client *client,
-			       cras_stream_id_t stream_id, int error,
+			       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,
-	/* Resource allocation problem. Free resources, and retry the
-	 * connection with cras_client_connect_async(), or (blocking)
-	 * cras_client_connect(). Do not call cras_client_connect(),
-	 * cras_client_connect_timeout(), or cras_client_destroy()
-	 * from the callback. */
+		/* Resource allocation problem. Free resources, and retry the
+		 * connection with cras_client_connect_async(), or (blocking)
+		 * cras_client_connect(). Do not call cras_client_connect(),
+		 * cras_client_connect_timeout(), or cras_client_destroy()
+		 * from the callback. */
 	CRAS_CONN_STATUS_DISCONNECTED,
-	/* The control thread is attempting to reconnect to the
-	 * server in the background. Any attempt to access the
-	 * server will fail or block (see
-	 * cras_client_set_server_message_blocking(). */
+		/* The control thread is attempting to reconnect to the
+		 * server in the background. Any attempt to access the
+		 * server will fail or block (see
+		 * cras_client_set_server_message_blocking(). */
 	CRAS_CONN_STATUS_CONNECTED,
-	/* Connection is established. All state change callbacks
-	 * have been re-registered, but audio streams must be
-	 * restarted, and node state data must be updated. */
+		/* Connection is established. All state change callbacks
+		 * have been re-registered, but audio streams must be
+		 * restarted, and node state data must be updated. */
 } cras_connection_status_t;
 
 /* Callback for handling server connection status.
@@ -165,7 +186,8 @@
 /* Callback for handling hotword errors. */
 typedef int (*cras_hotword_error_cb_t)(struct cras_client *client,
 				       struct cras_hotword_handle *handle,
-				       int error, void *user_data);
+				       int error,
+				       void *user_data);
 
 /*
  * Client handling.
@@ -180,18 +202,6 @@
  */
 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".
@@ -270,6 +280,19 @@
  */
 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
@@ -281,8 +304,9 @@
  *    user_arg - Pointer that will be passed to the callback.
  */
 void cras_client_set_connection_status_cb(
-	struct cras_client *client, cras_connection_status_cb_t connection_cb,
-	void *user_arg);
+		struct cras_client *client,
+		cras_connection_status_cb_t connection_cb,
+		void *user_arg);
 
 /* Sets callback for setting thread priority.
  * Args:
@@ -373,9 +397,10 @@
  * Returns:
  *    0 if successful, negative on error; -ENOENT if the node cannot be found.
  */
-int cras_client_get_node_by_id(const struct cras_client *client, int input,
+int cras_client_get_node_by_id(const struct cras_client *client,
+			       int input,
 			       const cras_node_id_t node_id,
-			       struct cras_ionode_info *node_info);
+			       struct cras_ionode_info* node_info);
 
 /* Checks if the output device with the given name is currently plugged in.
  *
@@ -409,7 +434,8 @@
  *    Returns 0 for success, negative on error (from errno.h).
  */
 int cras_client_set_node_attr(struct cras_client *client,
-			      cras_node_id_t node_id, enum ionode_attr attr,
+			      cras_node_id_t node_id,
+			      enum ionode_attr attr,
 			      int value);
 
 /* Select the preferred node for playback/capture.
@@ -448,6 +474,7 @@
 			       enum CRAS_STREAM_DIRECTION direction,
 			       cras_node_id_t node_id);
 
+
 /* Asks the server to reload dsp plugin configuration from the ini file.
  *
  * Args:
@@ -474,45 +501,8 @@
  * Returns:
  *    0 on success, -EINVAL if the client isn't valid or isn't running.
  */
-int cras_client_update_audio_debug_info(struct cras_client *client,
-					void (*cb)(struct cras_client *));
-
-/* Asks the server to dump bluetooth debug information.
- * Args:
- *    client - The client from cras_client_create.
- *    cb - Function to call when debug info is ready.
- * Returns:
- *    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);
+int cras_client_update_audio_debug_info(
+	struct cras_client *client, void (*cb)(struct cras_client *));
 
 /* Asks the server to dump current audio thread snapshots.
  *
@@ -522,8 +512,8 @@
  * Returns:
  *    0 on success, -EINVAL if the client isn't valid or isn't running.
  */
-int cras_client_update_audio_thread_snapshots(struct cras_client *client,
-					      void (*cb)(struct cras_client *));
+int cras_client_update_audio_thread_snapshots(
+	struct cras_client *client, void (*cb)(struct cras_client *));
 
 /*
  * Stream handling.
@@ -547,18 +537,16 @@
  *        number of channels, and sample rate.
  */
 struct cras_stream_params *cras_client_stream_params_create(
-	enum CRAS_STREAM_DIRECTION direction, size_t buffer_frames,
-	size_t cb_threshold, size_t unused, enum CRAS_STREAM_TYPE stream_type,
-	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);
+		enum CRAS_STREAM_DIRECTION direction,
+		size_t buffer_frames,
+		size_t cb_threshold,
+		size_t unused,
+		enum CRAS_STREAM_TYPE stream_type,
+		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 enable or disable specific effect on given stream parameter.
  * Args:
@@ -573,19 +561,7 @@
 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.
+/* Setup stream configuration parameters.
  * Args:
  *    direction - playback(CRAS_STREAM_OUTPUT) or capture(CRAS_STREAM_INPUT) or
  *        loopback(CRAS_STREAM_POST_MIX_PRE_DSP).
@@ -593,19 +569,20 @@
  *    stream_type - media or talk (currently only support "default").
  *    flags - None currently used.
  *    user_data - Pointer that will be passed to the callback.
- *    unified_cb - Called to request audio data or to notify the client when
- *                 captured audio is available. Though this is a unified_cb,
- *                 only one direction will be used for a stream, depending
- *                 on the 'direction' parameter.
+ *    unified_cb - Called for streams that do simultaneous input/output.
  *    err_cb - Called when there is an error with the stream.
  *    format - The format of the audio stream.  Specifies bits per sample,
  *        number of channels, and sample rate.
  */
 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,
-	cras_unified_cb_t unified_cb, cras_error_cb_t err_cb,
-	struct cras_audio_format *format);
+		enum CRAS_STREAM_DIRECTION direction,
+		unsigned int block_size,
+		enum CRAS_STREAM_TYPE stream_type,
+		uint32_t flags,
+		void *user_data,
+		cras_unified_cb_t unified_cb,
+		cras_error_cb_t err_cb,
+		struct cras_audio_format *format);
 
 /* Destroy stream params created with cras_client_stream_params_create. */
 void cras_client_stream_params_destroy(struct cras_stream_params *params);
@@ -643,7 +620,8 @@
  * Returns:
  *    0 on success, negative error code on failure (from errno.h).
  */
-int cras_client_add_pinned_stream(struct cras_client *client, uint32_t dev_idx,
+int cras_client_add_pinned_stream(struct cras_client *client,
+				  uint32_t dev_idx,
 				  cras_stream_id_t *stream_id_out,
 				  struct cras_stream_params *config);
 
@@ -876,21 +854,8 @@
  *    A pointer to the debug info.  This info is only updated when requested by
  *    calling cras_client_update_audio_debug_info.
  */
-const struct audio_debug_info *
-cras_client_get_audio_debug_info(const struct cras_client *client);
-
-/* Gets bluetooth debug info.
- *
- * Requires that the connection to the server has been established.
- *
- * Args:
- *    client - The client from cras_client_create.
- * Returns:
- *    A pointer to the debug info. This info is updated and requested by
- *    calling cras_client_update_bt_debug_info.
- */
-const struct cras_bt_debug_info *
-cras_client_get_bt_debug_info(const struct cras_client *client);
+const struct audio_debug_info *cras_client_get_audio_debug_info(
+		const struct cras_client *client);
 
 /* Gets audio thread snapshot buffer.
  *
@@ -904,7 +869,8 @@
  *    requested by calling cras_client_update_audio_thread_snapshots.
  */
 const struct cras_audio_thread_snapshot_buffer *
-cras_client_get_audio_thread_snapshot_buffer(const struct cras_client *client);
+	cras_client_get_audio_thread_snapshot_buffer(
+		const struct cras_client *client);
 
 /* Gets the number of streams currently attached to the server.
  *
@@ -924,6 +890,7 @@
 unsigned cras_client_get_num_active_streams(const struct cras_client *client,
 					    struct timespec *ts);
 
+
 /*
  * Utility functions.
  */
@@ -970,7 +937,8 @@
  *    volume - New value for node volume.
  */
 int cras_client_set_node_volume(struct cras_client *client,
-				cras_node_id_t node_id, uint8_t volume);
+				cras_node_id_t node_id,
+				uint8_t volume);
 
 /* Swap the left and right channel of the given node.
  *
@@ -980,7 +948,7 @@
  *    enable - 1 to enable swap mode, 0 to disable.
  */
 int cras_client_swap_node_left_right(struct cras_client *client,
-				     cras_node_id_t node_id, int enable);
+					cras_node_id_t node_id, int enable);
 
 /* Set the capture gain of the given input node.  Only for input nodes.
  *
@@ -990,7 +958,8 @@
  *    gain - New capture gain for the node.
  */
 int cras_client_set_node_capture_gain(struct cras_client *client,
-				      cras_node_id_t node_id, long gain);
+				      cras_node_id_t node_id,
+				      long gain);
 
 /* Add a test iodev to the iodev list.
  *
@@ -1013,7 +982,8 @@
 int cras_client_test_iodev_command(struct cras_client *client,
 				   unsigned int iodev_idx,
 				   enum CRAS_TEST_IODEV_CMD command,
-				   unsigned int data_len, const uint8_t *data);
+				   unsigned int data_len,
+				   const uint8_t *data);
 
 /* Finds the first node of the given type.
  *
@@ -1070,7 +1040,8 @@
  *        multiplying this matrix.
  */
 int cras_client_config_global_remix(struct cras_client *client,
-				    unsigned num_channels, float *coefficient);
+				    unsigned num_channels,
+				    float *coefficient);
 
 /* Gets the set of supported hotword language models on a node. The supported
  * models may differ on different nodes.
@@ -1083,8 +1054,8 @@
  *    0 on success.
  */
 int cras_client_get_hotword_models(struct cras_client *client,
-				   cras_node_id_t node_id,
-				   get_hotword_models_cb_t cb);
+				     cras_node_id_t node_id,
+				     get_hotword_models_cb_t cb);
 
 /* Sets the hotword language model on a node. If there are existing streams on
  * the hotword input node when this function is called, they need to be closed
@@ -1115,9 +1086,11 @@
  *    0 on success, negative error code on failure (from errno.h).
  */
 int cras_client_enable_hotword_callback(
-	struct cras_client *client, void *user_data,
-	cras_hotword_trigger_cb_t trigger_cb, cras_hotword_error_cb_t err_cb,
-	struct cras_hotword_handle **handle_out);
+		struct cras_client *client,
+		void *user_data,
+		cras_hotword_trigger_cb_t trigger_cb,
+		cras_hotword_error_cb_t err_cb,
+		struct cras_hotword_handle **handle_out);
 
 /*
  * Closes a hotword stream that was created by cras_client_wait_for_hotword.
@@ -1139,7 +1112,9 @@
  *    fd - File descriptor of the file to store aec dump result.
  */
 int cras_client_set_aec_dump(struct cras_client *client,
-			     cras_stream_id_t stream_id, int start, int fd);
+			     cras_stream_id_t stream_id,
+			     int start,
+			     int fd);
 /*
  * Reloads the aec.ini config file on server side.
  */
@@ -1150,23 +1125,13 @@
  */
 int cras_client_get_aec_supported(struct cras_client *client);
 
-/*
- * Returns the AEC group ID if available.
- */
-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);
-
 /* Set the context pointer for system state change callbacks.
  * Args:
  *    client - The client from cras_client_create.
  *    context - The context pointer passed to all callbacks.
  */
-void cras_client_set_state_change_callback_context(struct cras_client *client,
-						   void *context);
+void cras_client_set_state_change_callback_context(
+		struct cras_client *client, void *context);
 
 /* Output volume change callback.
  *
@@ -1175,8 +1140,8 @@
  *              cras_client_set_state_change_callback_context().
  *    volume - The system output volume, ranging from 0 to 100.
  */
-typedef void (*cras_client_output_volume_changed_callback)(void *context,
-							   int32_t volume);
+typedef void (*cras_client_output_volume_changed_callback)(
+		void* context, int32_t volume);
 
 /* Output mute change callback.
  *
@@ -1189,10 +1154,8 @@
  *    mute_locked - Non-zero when the mute funcion is locked,
  *                  zero otherwise.
  */
-typedef void (*cras_client_output_mute_changed_callback)(void *context,
-							 int muted,
-							 int user_muted,
-							 int mute_locked);
+typedef void (*cras_client_output_mute_changed_callback)(
+		void* context, int muted, int user_muted, int mute_locked);
 
 /* Capture gain change callback.
  *
@@ -1201,8 +1164,8 @@
  *              cras_client_set_state_change_callback_context().
  *    gain - The system capture gain, in centi-decibels.
  */
-typedef void (*cras_client_capture_gain_changed_callback)(void *context,
-							  int32_t gain);
+typedef void (*cras_client_capture_gain_changed_callback)(
+		void* context, int32_t gain);
 
 /* Capture mute change callback.
  *
@@ -1213,9 +1176,8 @@
  *    mute_locked - Non-zero when the mute funcion is locked,
  *                  zero otherwise.
  */
-typedef void (*cras_client_capture_mute_changed_callback)(void *context,
-							  int muted,
-							  int mute_locked);
+typedef void (*cras_client_capture_mute_changed_callback)(
+		void* context, int muted, int mute_locked);
 
 /* Nodes change callback.
  *
@@ -1223,7 +1185,7 @@
  *    context - Context pointer set with
  *              cras_client_set_state_change_callback_context().
  */
-typedef void (*cras_client_nodes_changed_callback)(void *context);
+typedef void (*cras_client_nodes_changed_callback)(void* context);
 
 /* Active node change callback.
  *
@@ -1236,8 +1198,8 @@
  *              device or node is selected or between selections.
  */
 typedef void (*cras_client_active_node_changed_callback)(
-	void *context, enum CRAS_STREAM_DIRECTION direction,
-	cras_node_id_t node_id);
+    void* context, enum CRAS_STREAM_DIRECTION direction,
+    cras_node_id_t node_id);
 
 /* Output node volume change callback.
  *
@@ -1248,7 +1210,7 @@
  *    volume - The volume for this node with range 0 to 100.
  */
 typedef void (*cras_client_output_node_volume_changed_callback)(
-	void *context, cras_node_id_t node_id, int32_t volume);
+		void* context, cras_node_id_t node_id, int32_t volume);
 
 /* Node left right swapped change callback.
  *
@@ -1259,7 +1221,7 @@
  *    swapped - Non-zero if the node is left-right swapped, zero otherwise.
  */
 typedef void (*cras_client_node_left_right_swapped_changed_callback)(
-	void *context, cras_node_id_t node_id, int swapped);
+		void* context, cras_node_id_t node_id, int swapped);
 
 /* Input node gain change callback.
  * Args:
@@ -1269,7 +1231,7 @@
  *    gain - The gain for this node in centi-decibels.
  */
 typedef void (*cras_client_input_node_gain_changed_callback)(
-	void *context, cras_node_id_t node_id, int32_t gain);
+		void* context, cras_node_id_t node_id, int32_t gain);
 
 /* Number of active streams change callback.
  *
@@ -1280,8 +1242,8 @@
  *    num_active_streams - The number of active streams.
  */
 typedef void (*cras_client_num_active_streams_changed_callback)(
-	void *context, enum CRAS_STREAM_DIRECTION direction,
-	uint32_t num_active_streams);
+		void* context, enum CRAS_STREAM_DIRECTION direction,
+		uint32_t num_active_streams);
 
 /* Set system state information callbacks.
  * NOTE: These callbacks are executed from the client control thread.
@@ -1295,34 +1257,36 @@
  *    0 for success or negative errno error code on error.
  */
 int cras_client_set_output_volume_changed_callback(
-	struct cras_client *client,
-	cras_client_output_volume_changed_callback cb);
+		struct cras_client *client,
+		cras_client_output_volume_changed_callback cb);
 int cras_client_set_output_mute_changed_callback(
-	struct cras_client *client,
-	cras_client_output_mute_changed_callback cb);
+		struct cras_client *client,
+		cras_client_output_mute_changed_callback cb);
 int cras_client_set_capture_gain_changed_callback(
-	struct cras_client *client,
-	cras_client_capture_gain_changed_callback cb);
+		struct cras_client *client,
+		cras_client_capture_gain_changed_callback cb);
 int cras_client_set_capture_mute_changed_callback(
-	struct cras_client *client,
-	cras_client_capture_mute_changed_callback cb);
+		struct cras_client *client,
+		cras_client_capture_mute_changed_callback cb);
 int cras_client_set_nodes_changed_callback(
-	struct cras_client *client, cras_client_nodes_changed_callback cb);
+		struct cras_client *client,
+		cras_client_nodes_changed_callback cb);
 int cras_client_set_active_node_changed_callback(
-	struct cras_client *client,
-	cras_client_active_node_changed_callback cb);
+		struct cras_client *client,
+		cras_client_active_node_changed_callback cb);
 int cras_client_set_output_node_volume_changed_callback(
-	struct cras_client *client,
-	cras_client_output_node_volume_changed_callback cb);
+		struct cras_client *client,
+		cras_client_output_node_volume_changed_callback cb);
 int cras_client_set_node_left_right_swapped_changed_callback(
-	struct cras_client *client,
-	cras_client_node_left_right_swapped_changed_callback cb);
+		struct cras_client *client,
+		cras_client_node_left_right_swapped_changed_callback cb);
 int cras_client_set_input_node_gain_changed_callback(
-	struct cras_client *client,
-	cras_client_input_node_gain_changed_callback cb);
+		struct cras_client *client,
+		cras_client_input_node_gain_changed_callback cb);
 int cras_client_set_num_active_streams_changed_callback(
-	struct cras_client *client,
-	cras_client_num_active_streams_changed_callback cb);
+		struct cras_client *client,
+		cras_client_num_active_streams_changed_callback cb);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/cras/src/libcras/cras_helpers.c b/cras/src/libcras/cras_helpers.c
index a2120ea..3db8f6a 100644
--- a/cras/src/libcras/cras_helpers.c
+++ b/cras/src/libcras/cras_helpers.c
@@ -17,11 +17,14 @@
 	unsigned int len;
 };
 
-static int
-play_buffer_callback(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 play_buffer_callback(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)
 {
 	struct buffer_data *data = (struct buffer_data *)user_arg;
 	int to_copy = data->len - data->offset;
@@ -41,7 +44,8 @@
 }
 
 static int play_buffer_error(struct cras_client *client,
-			     cras_stream_id_t stream_id, int error,
+			     cras_stream_id_t stream_id,
+			     int error,
 			     void *user_arg)
 {
 	free(user_arg);
@@ -102,11 +106,16 @@
 	return rc;
 }
 
-int cras_helper_add_stream_simple(
-	struct cras_client *client, enum CRAS_STREAM_DIRECTION direction,
-	void *user_data, cras_unified_cb_t unified_cb, cras_error_cb_t err_cb,
-	snd_pcm_format_t format, unsigned int frame_rate,
-	unsigned int num_channels, int dev_idx, cras_stream_id_t *stream_id_out)
+int cras_helper_add_stream_simple(struct cras_client *client,
+				  enum CRAS_STREAM_DIRECTION direction,
+				  void *user_data,
+				  cras_unified_cb_t unified_cb,
+				  cras_error_cb_t err_cb,
+				  snd_pcm_format_t format,
+				  unsigned int frame_rate,
+				  unsigned int num_channels,
+				  int dev_idx,
+				  cras_stream_id_t *stream_id_out)
 {
 	struct cras_audio_format *aud_format;
 	struct cras_stream_params *params;
@@ -116,10 +125,9 @@
 	if (!aud_format)
 		return -ENOMEM;
 
-	params = cras_client_unified_params_create(CRAS_STREAM_OUTPUT, 2048,
-						   CRAS_STREAM_TYPE_DEFAULT, 0,
-						   user_data, unified_cb,
-						   err_cb, aud_format);
+	params = cras_client_unified_params_create(CRAS_STREAM_OUTPUT,
+			2048, CRAS_STREAM_TYPE_DEFAULT, 0, user_data,
+			unified_cb, err_cb, aud_format);
 	if (!params) {
 		rc = -ENOMEM;
 		goto done_add_stream;
@@ -136,9 +144,12 @@
 	return rc;
 }
 
-int cras_helper_play_buffer(struct cras_client *client, const void *buffer,
-			    unsigned int frames, snd_pcm_format_t format,
-			    unsigned int frame_rate, unsigned int num_channels,
+int cras_helper_play_buffer(struct cras_client *client,
+			    const void *buffer,
+			    unsigned int frames,
+			    snd_pcm_format_t format,
+			    unsigned int frame_rate,
+			    unsigned int num_channels,
 			    int dev_idx)
 {
 	struct buffer_data *data;
@@ -152,8 +163,6 @@
 	data->len = frames * data->frame_bytes;
 
 	return cras_helper_add_stream_simple(client, CRAS_STREAM_OUTPUT, data,
-					     play_buffer_callback,
-					     play_buffer_error, format,
-					     frame_rate, num_channels, dev_idx,
-					     &stream_id);
+			play_buffer_callback, play_buffer_error, format,
+			frame_rate, num_channels, dev_idx, &stream_id);
 }
diff --git a/cras/src/libcras/cras_helpers.h b/cras/src/libcras/cras_helpers.h
index 604b266..ad54c5c 100644
--- a/cras/src/libcras/cras_helpers.h
+++ b/cras/src/libcras/cras_helpers.h
@@ -38,17 +38,12 @@
 int cras_helper_create_connect(struct cras_client **client);
 
 /* Adds a stream with the given parameters, no flags and a buffer size of 2048
- * Note that the unified_cb parameter is being phased out.
- * TODO(crbug.com/972928): convert this from unified_cb.
  * Args:
  *    client - The client to add the stream to (from cras_client_create).
  *    direction - playback(CRAS_STREAM_OUTPUT) or capture(CRAS_STREAM_INPUT) or
  *        loopback(CRAS_STREAM_POST_MIX_PRE_DSP).
  *    user_data - Pointer that will be passed to the callback.
- *    unified_cb - Called to request audio data or to notify the client when
- *                 captured audio is available. Though this is a unified_cb,
- *                 only one direction will be used for a stream, depending
- *                 on the 'direction' parameter.
+ *    unified_cb - Called for streams that do simultaneous input/output.
  *    err_cb - Called when there is an error with the stream.
  *    format - The type of the samples, ex. S16_LE.
  *    frame_rate - Sample rate.
@@ -63,11 +58,13 @@
  */
 int cras_helper_add_stream_simple(struct cras_client *client,
 				  enum CRAS_STREAM_DIRECTION direction,
-				  void *user_data, cras_unified_cb_t unified_cb,
+				  void *user_data,
+				  cras_unified_cb_t unified_cb,
 				  cras_error_cb_t err_cb,
 				  snd_pcm_format_t format,
 				  unsigned int frame_rate,
-				  unsigned int num_channels, int dev_idx,
+				  unsigned int num_channels,
+				  int dev_idx,
 				  cras_stream_id_t *stream_id_out);
 
 /* Plays the given buffer at a default latency.
@@ -83,9 +80,12 @@
  * Returns:
  *    0 on success, negative error code on failure (from errno.h).
  */
-int cras_helper_play_buffer(struct cras_client *client, const void *buffer,
-			    unsigned int num_frames, snd_pcm_format_t format,
-			    unsigned int frame_rate, unsigned int num_channels,
+int cras_helper_play_buffer(struct cras_client *client,
+			    const void *buffer,
+			    unsigned int num_frames,
+			    snd_pcm_format_t format,
+			    unsigned int frame_rate,
+			    unsigned int num_channels,
 			    int dev_idx);
 
 #ifdef __cplusplus
diff --git a/cras/src/plc/cras_plc.c b/cras/src/plc/cras_plc.c
deleted file mode 100644
index ed42ae9..0000000
--- a/cras/src/plc/cras_plc.c
+++ /dev/null
@@ -1,220 +0,0 @@
-/* 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
deleted file mode 100644
index ccde8bb..0000000
--- a/cras/src/plc/cras_plc.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/* 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
deleted file mode 100644
index 458f125..0000000
--- a/cras/src/plc/cras_plc_test.c
+++ /dev/null
@@ -1,135 +0,0 @@
-/* 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 d7ef8bd..7d208d8 100644
--- a/cras/src/server/audio_thread.c
+++ b/cras/src/server/audio_thread.c
@@ -4,24 +4,21 @@
  */
 
 #ifndef _GNU_SOURCE
-#define _GNU_SOURCE /* for ppoll and asprintf*/
+#define _GNU_SOURCE /* for ppoll */
 #endif
 
 #include <pthread.h>
 #include <poll.h>
 #include <stdbool.h>
-#include <stdio.h>
 #include <sys/param.h>
 #include <syslog.h>
 
 #include "audio_thread_log.h"
 #include "cras_audio_thread_monitor.h"
 #include "cras_config.h"
-#include "cras_device_monitor.h"
 #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"
@@ -68,12 +65,6 @@
 	struct cras_iodev *dev;
 };
 
-struct audio_thread_rm_device_msg {
-	struct audio_thread_msg header;
-	enum CRAS_STREAM_DIRECTION dir;
-	unsigned dev_idx;
-};
-
 struct audio_thread_rm_callback_msg {
 	struct audio_thread_msg header;
 	int fd;
@@ -93,7 +84,7 @@
 
 struct audio_thread_dev_start_ramp_msg {
 	struct audio_thread_msg header;
-	unsigned int dev_idx;
+	struct cras_iodev *dev;
 	enum CRAS_IODEV_RAMP_REQUEST request;
 };
 
@@ -104,16 +95,11 @@
 	int fd;
 };
 
-/* 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.
- */
+/* Audio thread logging. */
 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;
@@ -125,13 +111,13 @@
 	struct iodev_callback_list *prev, *next;
 };
 
-static void _audio_thread_add_callback(int fd, thread_callback cb, void *data,
-				       int is_write)
+static void _audio_thread_add_callback(int fd, thread_callback cb,
+				       void *data, int is_write)
 {
 	struct iodev_callback_list *iodev_cb;
 
 	/* Don't add iodev_cb twice */
-	DL_FOREACH (iodev_callbacks, iodev_cb)
+	DL_FOREACH(iodev_callbacks, iodev_cb)
 		if (iodev_cb->fd == fd && iodev_cb->cb_data == data)
 			return;
 
@@ -145,12 +131,14 @@
 	DL_APPEND(iodev_callbacks, iodev_cb);
 }
 
-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_add_callback(fd, cb, data, 0);
 }
 
-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)
 {
 	_audio_thread_add_callback(fd, cb, data, 1);
 }
@@ -159,7 +147,7 @@
 {
 	struct iodev_callback_list *iodev_cb;
 
-	DL_FOREACH (iodev_callbacks, iodev_cb) {
+	DL_FOREACH(iodev_callbacks, iodev_cb) {
 		if (iodev_cb->fd == fd) {
 			DL_DELETE(iodev_callbacks, iodev_cb);
 			free(iodev_cb);
@@ -172,7 +160,7 @@
 {
 	struct iodev_callback_list *iodev_cb;
 
-	DL_FOREACH (iodev_callbacks, iodev_cb) {
+	DL_FOREACH(iodev_callbacks, iodev_cb) {
 		if (iodev_cb->fd == fd) {
 			iodev_cb->enabled = !!enabled;
 			return;
@@ -203,8 +191,7 @@
  * Returns:
  *    |count| on success, negative error code on failure.
  */
-static int read_until_finished(int fd, void *buf, size_t count)
-{
+static int read_until_finished(int fd, void *buf, size_t count) {
 	int nread, count_left = count;
 
 	while (count_left > 0) {
@@ -234,15 +221,16 @@
  * Returns:
  *    0 on success, negative error code on failure.
  */
-static int audio_thread_read_command(struct audio_thread *thread, uint8_t *buf,
+static int audio_thread_read_command(struct audio_thread *thread,
+				     uint8_t *buf,
 				     size_t max_len)
 {
 	int to_read, nread, rc;
 	struct audio_thread_msg *msg = (struct audio_thread_msg *)buf;
 
 	/* Get the length of the message first */
-	nread = read_until_finished(thread->to_thread_fds[0], buf,
-				    sizeof(msg->length));
+	nread = read_until_finished(
+			thread->to_thread_fds[0], buf, sizeof(msg->length));
 	if (nread < 0)
 		return nread;
 
@@ -251,7 +239,7 @@
 
 	to_read = msg->length - sizeof(msg->length);
 	rc = read_until_finished(thread->to_thread_fds[0],
-				 &buf[0] + sizeof(msg->length), to_read);
+			&buf[0] + sizeof(msg->length), to_read);
 	if (rc < 0)
 		return rc;
 	return 0;
@@ -263,13 +251,121 @@
 	cras_iodev_fill_odev_zeros(odev, odev->min_buffer_level);
 }
 
+/* Append a new stream to a specified set of iodevs. */
+static int append_stream(struct audio_thread *thread,
+			 struct cras_rstream *stream,
+			 struct cras_iodev **iodevs,
+			 unsigned int num_iodevs)
+{
+	struct open_dev *open_dev;
+	struct cras_iodev *dev;
+	struct dev_stream *out;
+	struct timespec init_cb_ts;
+	const struct timespec *stream_ts;
+	unsigned int i;
+	bool cb_ts_set = false;
+	int rc = 0;
+
+	for (i = 0; i < num_iodevs; i++) {
+		DL_SEARCH_SCALAR(thread->open_devs[stream->direction], open_dev,
+				dev, iodevs[i]);
+		if (!open_dev)
+			continue;
+
+		dev = iodevs[i];
+		DL_SEARCH_SCALAR(dev->streams, out, stream, stream);
+		if (out)
+			continue;
+
+		/* For output, if open device already has stream, get the earliest next
+		 * callback time from these streams to align with. Otherwise, use the
+		 * timestamp now as the initial callback time for new stream so dev_stream
+		 * can set its own schedule.
+		 * If next callback time is too far from now, it will block writing and
+		 * lower hardware level. Else if we fetch the new stream immediately, it
+		 * may cause device buffer level stack up.
+		 */
+		if (stream->direction == CRAS_STREAM_OUTPUT && dev->streams) {
+			DL_FOREACH(dev->streams, out) {
+				stream_ts =  dev_stream_next_cb_ts(out);
+				if (stream_ts &&
+				    (!cb_ts_set || timespec_after(&init_cb_ts, stream_ts))) {
+					init_cb_ts = *stream_ts;
+					cb_ts_set = true;
+				}
+			}
+		}
+
+		if (!cb_ts_set)
+			clock_gettime(CLOCK_MONOTONIC_RAW, &init_cb_ts);
+
+		out = dev_stream_create(stream, dev->info.idx,
+					dev->ext_format, dev, &init_cb_ts);
+		if (!out) {
+			rc = -EINVAL;
+			break;
+		}
+
+		/* 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.
+		 */
+		if ((stream->direction == CRAS_STREAM_INPUT) && !dev->streams) {
+			int num_flushed = dev->flush_buffer(dev);
+			if (num_flushed < 0) {
+				rc = num_flushed;
+				break;
+			}
+		}
+
+		cras_iodev_add_stream(dev, out);
+
+		/* For multiple inputs case, if the new stream is not the first
+		 * one to append, copy the 1st stream's offset to it so that
+		 * future read offsets can be aligned across all input streams
+		 * to avoid the deadlock scenario when multiple streams reading
+		 * from multiple devices.
+		 */
+		if ((stream->direction == CRAS_STREAM_INPUT) &&
+		    (dev->streams != out)) {
+			unsigned int offset =
+				cras_iodev_stream_offset(dev, dev->streams);
+			if (offset > stream->cb_threshold)
+				offset = stream->cb_threshold;
+			cras_iodev_stream_written(dev, out, offset);
+
+			offset = cras_rstream_dev_offset(dev->streams->stream,
+							 dev->info.idx);
+			if (offset > stream->cb_threshold)
+				offset = stream->cb_threshold;
+			cras_rstream_dev_offset_update(stream, offset,
+						       dev->info.idx);
+		}
+	}
+
+	if (rc) {
+		DL_FOREACH(thread->open_devs[stream->direction], open_dev) {
+			dev = open_dev->dev;
+			DL_SEARCH_SCALAR(dev->streams, out, stream, stream);
+			if (!out)
+				continue;
+
+			cras_iodev_rm_stream(dev, stream);
+			dev_stream_destroy(out);
+		}
+	}
+
+	return rc;
+}
+
 /* Handles messages from main thread to add a new active device. */
 static int thread_add_open_dev(struct audio_thread *thread,
 			       struct cras_iodev *iodev)
 {
 	struct open_dev *adev;
 
-	DL_SEARCH_SCALAR(thread->open_devs[iodev->direction], adev, dev, iodev);
+	DL_SEARCH_SCALAR(thread->open_devs[iodev->direction],
+			 adev, dev, iodev);
 	if (adev)
 		return -EEXIST;
 
@@ -292,15 +388,14 @@
 
 /* Handles messages from the main thread to remove an active device. */
 static int thread_rm_open_dev(struct audio_thread *thread,
-			      enum CRAS_STREAM_DIRECTION dir,
-			      unsigned int dev_idx)
+			      struct cras_iodev *iodev)
 {
-	struct open_dev *adev =
-		dev_io_find_open_dev(thread->open_devs[dir], dev_idx);
+	struct open_dev *adev = dev_io_find_open_dev(
+			thread->open_devs[iodev->direction], iodev);
 	if (!adev)
 		return -EINVAL;
 
-	dev_io_rm_open_dev(&thread->open_devs[dir], adev);
+	dev_io_rm_open_dev(&thread->open_devs[iodev->direction], adev);
 	return 0;
 }
 
@@ -312,55 +407,24 @@
 			      struct cras_iodev *iodev)
 {
 	struct open_dev *adev = dev_io_find_open_dev(
-		thread->open_devs[iodev->direction], iodev->info.idx);
+			thread->open_devs[iodev->direction], iodev);
 	return !!adev;
 }
 
-/*
- * Handles messages from the main thread to start ramping on a device.
- * Start ramping in audio thread and set mute/unmute
- * state on device. This should only be done when
- * device is running with valid streams.
- *
- * 1. Mute -> Unmute: Set device unmute state after
- *                    ramping is started.
- * 2. Unmute -> Mute: Set device mute state after
- *                    ramping is done.
- *
- * The above transition will be handled by cras_iodev_start_ramp.
- */
+/* Handles messages from the main thread to start ramping on a device. */
 static int thread_dev_start_ramp(struct audio_thread *thread,
-				 unsigned int dev_idx,
+				 struct cras_iodev *iodev,
 				 enum CRAS_IODEV_RAMP_REQUEST request)
 {
 	/* Do nothing if device wasn't already in the active dev list. */
-	struct cras_iodev *iodev;
 	struct open_dev *adev = dev_io_find_open_dev(
-		thread->open_devs[CRAS_STREAM_OUTPUT], dev_idx);
+			thread->open_devs[iodev->direction], iodev);
 	if (!adev)
 		return -EINVAL;
-	iodev = adev->dev;
-
-	/*
-	 * Checks if a device should start ramping for mute/unmute change.
-	 * Device must meet all the conditions:
-	 *
-	 * - Device has ramp support.
-	 * - Device is in normal run state, that is, it must be running with valid
-	 *   streams.
-	 * - Device volume, which considers both system volume and adjusted active
-	 *   node volume, is not zero. If device volume is zero, all the samples are
-	 *   suppressed to zero and there is no need to ramp.
-	 */
-	if (iodev->ramp &&
-	    cras_iodev_state(iodev) == CRAS_IODEV_STATE_NORMAL_RUN &&
-	    !cras_iodev_is_zero_volume(iodev))
-		return cras_iodev_start_ramp(iodev, request);
-	else
-		return cras_device_monitor_set_device_mute_state(
-			iodev->info.idx);
+	return cras_iodev_start_ramp(iodev, request);
 }
 
+
 /* Return non-zero if the stream is attached to any device. */
 static int thread_find_stream(struct audio_thread *thread,
 			      struct cras_rstream *rstream)
@@ -368,8 +432,8 @@
 	struct open_dev *open_dev;
 	struct dev_stream *s;
 
-	DL_FOREACH (thread->open_devs[rstream->direction], open_dev) {
-		DL_FOREACH (open_dev->dev->streams, s) {
+	DL_FOREACH(thread->open_devs[rstream->direction], open_dev) {
+		DL_FOREACH(open_dev->dev->streams, s) {
 			if (s->stream == rstream)
 				return 1;
 		}
@@ -378,8 +442,8 @@
 }
 
 /* Handles the disconnect_stream message from the main thread. */
-static int thread_disconnect_stream(struct audio_thread *thread,
-				    struct cras_rstream *stream,
+static int thread_disconnect_stream(struct audio_thread* thread,
+				    struct cras_rstream* stream,
 				    struct cras_iodev *dev)
 {
 	int rc;
@@ -387,8 +451,8 @@
 	if (!thread_find_stream(thread, stream))
 		return 0;
 
-	rc = dev_io_remove_stream(&thread->open_devs[stream->direction], stream,
-				  dev);
+	rc = dev_io_remove_stream(&thread->open_devs[stream->direction],
+				  stream, dev);
 
 	return rc;
 }
@@ -407,7 +471,7 @@
 	if (rstream->direction != CRAS_STREAM_OUTPUT)
 		return 0;
 
-	shm = cras_rstream_shm(rstream);
+	shm = cras_rstream_output_shm(rstream);
 	fr_in_buff = cras_shm_get_frames(shm);
 
 	if (fr_in_buff <= 0)
@@ -445,28 +509,30 @@
 {
 	int rc;
 
-	rc = dev_io_append_stream(&thread->open_devs[stream->direction], stream,
-				  iodevs, num_iodevs);
+	rc = append_stream(thread, stream, iodevs, num_iodevs);
 	if (rc < 0)
 		return rc;
 
+	ATLOG(atlog, AUDIO_THREAD_STREAM_ADDED, stream->stream_id,
+	      num_iodevs ? iodevs[0]->info.idx : 0, num_iodevs);
 	return 0;
 }
 
 /* Starts or stops aec dump task. */
 static int thread_set_aec_dump(struct audio_thread *thread,
-			       cras_stream_id_t stream_id, unsigned int start,
+			       cras_stream_id_t stream_id,
+			       unsigned int start,
 			       int fd)
 {
 	struct open_dev *idev_list = thread->open_devs[CRAS_STREAM_INPUT];
 	struct open_dev *adev;
 	struct dev_stream *stream;
 
-	DL_FOREACH (idev_list, adev) {
+	DL_FOREACH(idev_list, adev) {
 		if (!cras_iodev_is_open(adev->dev))
 			continue;
 
-		DL_FOREACH (adev->dev->streams, stream) {
+		DL_FOREACH(adev->dev->streams, stream) {
 			if ((stream->stream->apm_list == NULL) ||
 			    (stream->stream->stream_id != stream_id))
 				continue;
@@ -487,8 +553,7 @@
 static void append_dev_dump_info(struct audio_dev_debug_info *di,
 				 struct open_dev *adev)
 {
-	struct cras_audio_format *fmt = adev->dev->format;
-	struct timespec now, time_since;
+	struct cras_audio_format *fmt = adev->dev->ext_format;
 	strncpy(di->dev_name, adev->dev->info.name, sizeof(di->dev_name));
 	di->buffer_size = adev->dev->buffer_size;
 	di->min_buffer_level = adev->dev->min_buffer_level;
@@ -496,20 +561,9 @@
 	di->max_cb_level = adev->dev->max_cb_level;
 	di->direction = adev->dev->direction;
 	di->num_underruns = cras_iodev_get_num_underruns(adev->dev);
-	di->num_severe_underruns =
-		cras_iodev_get_num_severe_underruns(adev->dev);
+	di->num_severe_underruns = cras_iodev_get_num_severe_underruns(
+			adev->dev);
 	di->highest_hw_level = adev->dev->highest_hw_level;
-	di->software_gain_scaler = (adev->dev->direction == CRAS_STREAM_INPUT) ?
-					   adev->dev->software_gain_scaler :
-					   0.0f;
-
-	clock_gettime(CLOCK_MONOTONIC_RAW, &now);
-	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;
 		di->num_channels = fmt->num_channels;
@@ -524,10 +578,10 @@
 /* Put stream info for the given stream into the info struct. */
 static void append_stream_dump_info(struct audio_debug_info *info,
 				    struct dev_stream *stream,
-				    unsigned int dev_idx, int index)
+				    unsigned int dev_idx,
+				    int index)
 {
 	struct audio_stream_debug_info *si;
-	struct timespec now, time_since;
 
 	si = &info->streams[index];
 
@@ -535,7 +589,6 @@
 	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;
@@ -544,17 +597,11 @@
 	       sizeof(si->channel_layout));
 	si->longest_fetch_sec = stream->stream->longest_fetch_interval.tv_sec;
 	si->longest_fetch_nsec = stream->stream->longest_fetch_interval.tv_nsec;
-	si->num_overruns = cras_shm_num_overruns(stream->stream->shm);
+	si->num_overruns = cras_shm_num_overruns(&stream->stream->shm);
 	si->effects = cras_apm_list_get_effects(stream->stream->apm_list);
-	si->pinned_dev_idx = stream->stream->pinned_dev_idx;
-	si->is_pinned = stream->stream->is_pinned;
-	si->num_missed_cb = stream->stream->num_missed_cb;
-	si->stream_volume = cras_rstream_get_volume_scaler(stream->stream);
 
-	clock_gettime(CLOCK_MONOTONIC_RAW, &now);
-	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 */
@@ -578,7 +625,7 @@
 		ATLOG(atlog, AUDIO_THREAD_WRITE_STREAMS_WAIT,
 		      amsg->stream->stream_id, 0, 0);
 		ret = thread_add_stream(thread, amsg->stream, amsg->devs,
-					amsg->num_devs);
+				amsg->num_devs);
 		break;
 	}
 	case AUDIO_THREAD_DISCONNECT_STREAM: {
@@ -587,7 +634,7 @@
 		rmsg = (struct audio_thread_add_rm_stream_msg *)msg;
 
 		ret = thread_disconnect_stream(thread, rmsg->stream,
-					       rmsg->devs[0]);
+				rmsg->devs[0]);
 		break;
 	}
 	case AUDIO_THREAD_ADD_OPEN_DEV: {
@@ -598,10 +645,10 @@
 		break;
 	}
 	case AUDIO_THREAD_RM_OPEN_DEV: {
-		struct audio_thread_rm_device_msg *rmsg;
+		struct audio_thread_open_device_msg *rmsg;
 
-		rmsg = (struct audio_thread_rm_device_msg *)msg;
-		ret = thread_rm_open_dev(thread, rmsg->dir, rmsg->dev_idx);
+		rmsg = (struct audio_thread_open_device_msg *)msg;
+		ret = thread_rm_open_dev(thread, rmsg->dev);
 		break;
 	}
 	case AUDIO_THREAD_IS_DEV_OPEN: {
@@ -631,11 +678,11 @@
 		info = dmsg->info;
 
 		/* Go through all open devices. */
-		DL_FOREACH (thread->open_devs[CRAS_STREAM_OUTPUT], adev) {
+		DL_FOREACH(thread->open_devs[CRAS_STREAM_OUTPUT], adev) {
 			append_dev_dump_info(&info->devs[num_devs], adev);
 			if (++num_devs == MAX_DEBUG_DEVS)
 				break;
-			DL_FOREACH (adev->dev->streams, curr) {
+			DL_FOREACH(adev->dev->streams, curr) {
 				if (num_streams == MAX_DEBUG_STREAMS)
 					break;
 				append_stream_dump_info(info, curr,
@@ -643,11 +690,11 @@
 							num_streams++);
 			}
 		}
-		DL_FOREACH (thread->open_devs[CRAS_STREAM_INPUT], adev) {
+		DL_FOREACH(thread->open_devs[CRAS_STREAM_INPUT], adev) {
 			if (num_devs == MAX_DEBUG_DEVS)
 				break;
 			append_dev_dump_info(&info->devs[num_devs], adev);
-			DL_FOREACH (adev->dev->streams, curr) {
+			DL_FOREACH(adev->dev->streams, curr) {
 				if (num_streams == MAX_DEBUG_STREAMS)
 					break;
 				append_stream_dump_info(info, curr,
@@ -693,16 +740,15 @@
 	case AUDIO_THREAD_DEV_START_RAMP: {
 		struct audio_thread_dev_start_ramp_msg *rmsg;
 
-		rmsg = (struct audio_thread_dev_start_ramp_msg *)msg;
-		ret = thread_dev_start_ramp(thread, rmsg->dev_idx,
-					    rmsg->request);
+		rmsg = (struct audio_thread_dev_start_ramp_msg*)msg;
+		ret = thread_dev_start_ramp(thread, rmsg->dev, rmsg->request);
 		break;
 	}
 	case AUDIO_THREAD_AEC_DUMP: {
 		struct audio_thread_aec_dump_msg *rmsg;
 		rmsg = (struct audio_thread_aec_dump_msg *)msg;
-		ret = thread_set_aec_dump(thread, rmsg->stream_id, rmsg->start,
-					  rmsg->fd);
+		ret = thread_set_aec_dump(thread, rmsg->stream_id,
+					  rmsg->start, rmsg->fd);
 		break;
 	}
 	default:
@@ -716,6 +762,61 @@
 	return ret;
 }
 
+/* Fills the time that the next stream needs to be serviced. */
+static int get_next_stream_wake_from_list(struct dev_stream *streams,
+					  struct timespec *min_ts)
+{
+	struct dev_stream *dev_stream;
+	int ret = 0; /* The total number of streams to wait on. */
+
+	DL_FOREACH(streams, dev_stream) {
+		const struct timespec *next_cb_ts;
+
+		if (cras_rstream_get_is_draining(dev_stream->stream) &&
+		    dev_stream_playback_frames(dev_stream) <= 0)
+			continue;
+		if (!dev_stream_can_fetch(dev_stream))
+			continue;
+
+		next_cb_ts = dev_stream_next_cb_ts(dev_stream);
+		if (!next_cb_ts)
+			continue;
+
+		ATLOG(atlog, AUDIO_THREAD_STREAM_SLEEP_TIME,
+		      dev_stream->stream->stream_id, next_cb_ts->tv_sec,
+		      next_cb_ts->tv_nsec);
+		if (timespec_after(min_ts, next_cb_ts))
+			*min_ts = *next_cb_ts;
+		ret++;
+	}
+
+	return ret;
+}
+
+static int get_next_output_wake(struct open_dev **odevs,
+				struct timespec *min_ts,
+				const struct timespec *now)
+{
+	struct open_dev *adev;
+	int ret = 0;
+
+	DL_FOREACH(*odevs, adev)
+		ret += get_next_stream_wake_from_list(
+				adev->dev->streams,
+				min_ts);
+
+	DL_FOREACH(*odevs, adev) {
+		if (!cras_iodev_odev_should_wake(adev->dev))
+			continue;
+
+		ret++;
+		if (timespec_after(min_ts, &adev->wake_ts))
+			*min_ts = adev->wake_ts;
+	}
+
+	return ret;
+}
+
 /* Returns the number of active streams plus the number of active devices. */
 static int fill_next_sleep_interval(struct audio_thread *thread,
 				    struct timespec *ts)
@@ -731,8 +832,8 @@
 	min_ts.tv_nsec = 0;
 	clock_gettime(CLOCK_MONOTONIC_RAW, &now);
 	add_timespecs(&min_ts, &now);
-	ret = dev_io_next_output_wake(&thread->open_devs[CRAS_STREAM_OUTPUT],
-				      &min_ts, &now);
+	ret = get_next_output_wake(&thread->open_devs[CRAS_STREAM_OUTPUT],
+				   &min_ts, &now);
 	ret += dev_io_next_input_wake(&thread->open_devs[CRAS_STREAM_INPUT],
 				      &min_ts);
 	if (timespec_after(&min_ts, &now))
@@ -741,8 +842,8 @@
 	return ret;
 }
 
-static struct pollfd *add_pollfd(struct audio_thread *thread, int fd,
-				 int is_write)
+static struct pollfd *add_pollfd(struct audio_thread *thread,
+				 int fd, int is_write)
 {
 	thread->pollfds[thread->num_pollfds].fd = fd;
 	if (is_write)
@@ -752,9 +853,10 @@
 	thread->num_pollfds++;
 	if (thread->num_pollfds >= thread->pollfds_size) {
 		thread->pollfds_size *= 2;
-		thread->pollfds = (struct pollfd *)realloc(
-			thread->pollfds,
-			sizeof(*thread->pollfds) * thread->pollfds_size);
+		thread->pollfds =
+			(struct pollfd *)realloc(thread->pollfds,
+						 sizeof(*thread->pollfds) *
+						 thread->pollfds_size);
 		return NULL;
 	}
 
@@ -762,41 +864,17 @@
 }
 
 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 void check_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);
+	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();
 	}
-}
-
-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) {
-			busyloop_count++;
-			cras_audio_thread_event_busyloop();
-		}
-	} else {
+	else
+	{
 		continuous_zero_sleep_count = 0;
 	}
 }
@@ -813,7 +891,7 @@
 	struct audio_thread *thread = (struct audio_thread *)arg;
 	struct open_dev *adev;
 	struct dev_stream *curr;
-	struct timespec ts;
+	struct timespec ts, now, last_wake;
 	int msg_fd;
 	int rc;
 
@@ -823,6 +901,10 @@
 	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;
 
@@ -841,21 +923,21 @@
 		if (fill_next_sleep_interval(thread, &ts))
 			wait_ts = &ts;
 
-	restart_poll_loop:
+restart_poll_loop:
 		thread->num_pollfds = 1;
 
-		DL_FOREACH (iodev_callbacks, iodev_cb) {
+		DL_FOREACH(iodev_callbacks, iodev_cb) {
 			if (!iodev_cb->enabled)
 				continue;
 			iodev_cb->pollfd = add_pollfd(thread, iodev_cb->fd,
 						      iodev_cb->is_write);
 			if (!iodev_cb->pollfd)
-				goto restart_poll_loop;
+			    goto restart_poll_loop;
 		}
 
 		/* TODO(dgreid) - once per rstream not per dev_stream */
-		DL_FOREACH (thread->open_devs[CRAS_STREAM_OUTPUT], adev) {
-			DL_FOREACH (adev->dev->streams, curr) {
+		DL_FOREACH(thread->open_devs[CRAS_STREAM_OUTPUT], adev) {
+			DL_FOREACH(adev->dev->streams, curr) {
 				int fd = dev_stream_poll_stream_fd(curr);
 				if (fd < 0)
 					continue;
@@ -863,8 +945,8 @@
 					goto restart_poll_loop;
 			}
 		}
-		DL_FOREACH (thread->open_devs[CRAS_STREAM_INPUT], adev) {
-			DL_FOREACH (adev->dev->streams, curr) {
+		DL_FOREACH(thread->open_devs[CRAS_STREAM_INPUT], adev) {
+			DL_FOREACH(adev->dev->streams, curr) {
 				int fd = dev_stream_poll_stream_fd(curr);
 				if (fd < 0)
 					continue;
@@ -873,18 +955,20 @@
 			}
 		}
 
-		log_busyloop(wait_ts);
+		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;
+		}
 
 		ATLOG(atlog, AUDIO_THREAD_SLEEP, wait_ts ? wait_ts->tv_sec : 0,
-		      wait_ts ? wait_ts->tv_nsec : 0, 0);
-		if (wait_ts)
+		      wait_ts ? wait_ts->tv_nsec : 0, longest_wake.tv_nsec);
+		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;
@@ -892,10 +976,10 @@
 		if (thread->pollfds[0].revents & POLLIN) {
 			rc = handle_playback_thread_message(thread);
 			if (rc < 0)
-				syslog(LOG_ERR, "handle message %d", rc);
+				syslog(LOG_INFO, "handle message %d", rc);
 		}
 
-		DL_FOREACH (iodev_callbacks, iodev_cb) {
+		DL_FOREACH(iodev_callbacks, iodev_cb) {
 			if (iodev_cb->pollfd &&
 			    iodev_cb->pollfd->revents & (POLLIN | POLLOUT)) {
 				ATLOG(atlog, AUDIO_THREAD_IODEV_CB,
@@ -949,17 +1033,6 @@
 	msg->dev = dev;
 }
 
-static void init_rm_device_msg(struct audio_thread_rm_device_msg *msg,
-			       enum CRAS_STREAM_DIRECTION dir,
-			       unsigned int dev_idx)
-{
-	memset(msg, 0, sizeof(*msg));
-	msg->header.id = AUDIO_THREAD_RM_OPEN_DEV;
-	msg->header.length = sizeof(*msg);
-	msg->dir = dir;
-	msg->dev_idx = dev_idx;
-}
-
 static void init_add_rm_stream_msg(struct audio_thread_add_rm_stream_msg *msg,
 				   enum AUDIO_THREAD_COMMAND id,
 				   struct cras_rstream *stream,
@@ -974,9 +1047,9 @@
 	msg->num_devs = num_devs;
 }
 
-static void
-init_dump_debug_info_msg(struct audio_thread_dump_debug_info_msg *msg,
-			 struct audio_debug_info *info)
+static void init_dump_debug_info_msg(
+		struct audio_thread_dump_debug_info_msg *msg,
+		struct audio_debug_info *info)
 {
 	memset(msg, 0, sizeof(*msg));
 	msg->header.id = AUDIO_THREAD_DUMP_THREAD_INFO;
@@ -984,36 +1057,33 @@
 	msg->info = info;
 }
 
-static void
-init_config_global_remix_msg(struct audio_thread_config_global_remix *msg)
+static void init_config_global_remix_msg(
+		struct audio_thread_config_global_remix *msg)
 {
 	memset(msg, 0, sizeof(*msg));
 	msg->header.id = AUDIO_THREAD_CONFIG_GLOBAL_REMIX;
 	msg->header.length = sizeof(*msg);
 }
 
-static void
-init_device_start_ramp_msg(struct audio_thread_dev_start_ramp_msg *msg,
-			   enum AUDIO_THREAD_COMMAND id, unsigned int dev_idx,
-			   enum CRAS_IODEV_RAMP_REQUEST request)
+static void init_device_start_ramp_msg(
+		struct audio_thread_dev_start_ramp_msg *msg,
+		enum AUDIO_THREAD_COMMAND id,
+		struct cras_iodev *dev,
+		enum CRAS_IODEV_RAMP_REQUEST request)
 {
 	memset(msg, 0, sizeof(*msg));
 	msg->header.id = id;
 	msg->header.length = sizeof(*msg);
-	msg->dev_idx = dev_idx;
+	msg->dev = dev;
 	msg->request = request;
 }
 
 /* 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)
+			    struct cras_iodev **devs,
+			    unsigned int num_devs)
 {
 	struct audio_thread_add_rm_stream_msg msg;
 
@@ -1022,8 +1092,8 @@
 	if (!thread->started)
 		return -EINVAL;
 
-	init_add_rm_stream_msg(&msg, AUDIO_THREAD_ADD_STREAM, stream, devs,
-			       num_devs);
+	init_add_rm_stream_msg(&msg, AUDIO_THREAD_ADD_STREAM, stream,
+			       devs, num_devs);
 	return audio_thread_post_message(thread, &msg.header);
 }
 
@@ -1047,8 +1117,8 @@
 
 	assert(thread && stream);
 
-	init_add_rm_stream_msg(&msg, AUDIO_THREAD_DRAIN_STREAM, stream, NULL,
-			       0);
+	init_add_rm_stream_msg(&msg, AUDIO_THREAD_DRAIN_STREAM, stream,
+			       NULL, 0);
 	return audio_thread_post_message(thread, &msg.header);
 }
 
@@ -1062,8 +1132,9 @@
 }
 
 int audio_thread_set_aec_dump(struct audio_thread *thread,
-			      cras_stream_id_t stream_id, unsigned int start,
-			      int fd)
+			       cras_stream_id_t stream_id,
+			       unsigned int start,
+			       int fd)
 {
 	struct audio_thread_aec_dump_msg msg;
 
@@ -1076,8 +1147,7 @@
 	return audio_thread_post_message(thread, &msg.header);
 }
 
-int audio_thread_rm_callback_sync(struct audio_thread *thread, int fd)
-{
+int audio_thread_rm_callback_sync(struct audio_thread *thread, int fd) {
 	struct audio_thread_rm_callback_msg msg;
 
 	memset(&msg, 0, sizeof(msg));
@@ -1169,22 +1239,18 @@
 		return NULL;
 	}
 
-	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);
+	atlog = audio_thread_event_log_init();
 
 	thread->pollfds_size = 32;
-	thread->pollfds = (struct pollfd *)malloc(sizeof(*thread->pollfds) *
-						  thread->pollfds_size);
+	thread->pollfds =
+		(struct pollfd *)malloc(sizeof(*thread->pollfds)
+					* thread->pollfds_size);
 
 	return thread;
 }
 
 int audio_thread_add_open_dev(struct audio_thread *thread,
-			      struct cras_iodev *dev)
+				struct cras_iodev *dev)
 {
 	struct audio_thread_open_device_msg msg;
 
@@ -1198,16 +1264,15 @@
 }
 
 int audio_thread_rm_open_dev(struct audio_thread *thread,
-			     enum CRAS_STREAM_DIRECTION dir,
-			     unsigned int dev_idx)
+			     struct cras_iodev *dev)
 {
-	struct audio_thread_rm_device_msg msg;
+	struct audio_thread_open_device_msg msg;
 
-	assert(thread);
+	assert(thread && dev);
 	if (!thread->started)
 		return -EINVAL;
 
-	init_rm_device_msg(&msg, dir, dev_idx);
+	init_open_device_msg(&msg, AUDIO_THREAD_RM_OPEN_DEV, dev);
 	return audio_thread_post_message(thread, &msg.header);
 }
 
@@ -1224,18 +1289,18 @@
 }
 
 int audio_thread_dev_start_ramp(struct audio_thread *thread,
-				unsigned int dev_idx,
+				struct cras_iodev *dev,
 				enum CRAS_IODEV_RAMP_REQUEST request)
 {
 	struct audio_thread_dev_start_ramp_msg msg;
 
-	assert(thread);
+	assert(thread && dev);
 
 	if (!thread->started)
 		return -EINVAL;
 
-	init_device_start_ramp_msg(&msg, AUDIO_THREAD_DEV_START_RAMP, dev_idx,
-				   request);
+	init_device_start_ramp_msg(&msg, AUDIO_THREAD_DEV_START_RAMP,
+				   dev, request);
 	return audio_thread_post_message(thread, &msg.header);
 }
 
@@ -1267,8 +1332,7 @@
 
 	free(thread->pollfds);
 
-	audio_thread_event_log_deinit(atlog, atlog_name);
-	free(atlog_name);
+	audio_thread_event_log_deinit(atlog);
 
 	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 5e5e995..e2c0d72 100644
--- a/cras/src/server/audio_thread.h
+++ b/cras/src/server/audio_thread.h
@@ -72,8 +72,7 @@
  *    dev - The open device to remove.
  */
 int audio_thread_rm_open_dev(struct audio_thread *thread,
-			     enum CRAS_STREAM_DIRECTION dir,
-			     unsigned int dev_idx);
+			     struct cras_iodev *dev);
 
 /* Checks if dev is open and used by audio thread.
  * Args:
@@ -90,7 +89,8 @@
  *    cb - The callback function.
  *    data - The data for the callback function.
  */
-void audio_thread_add_callback(int fd, thread_callback cb, void *data);
+void audio_thread_add_callback(int fd, thread_callback cb,
+                               void *data);
 
 /* Adds an thread_callback to audio thread.
  * Args:
@@ -99,7 +99,8 @@
  *    cb - The callback function.
  *    data - The data for the callback function.
  */
-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);
 
 /* Removes an thread_callback from audio thread.
  * Args:
@@ -114,6 +115,7 @@
  */
 int audio_thread_rm_callback_sync(struct audio_thread *thread, int fd);
 
+
 /* Enables or Disabled the callback associated with fd. */
 void audio_thread_enable_callback(int fd, int enabled);
 
@@ -128,9 +130,6 @@
 /* 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.
@@ -145,7 +144,8 @@
  */
 int audio_thread_add_stream(struct audio_thread *thread,
 			    struct cras_rstream *stream,
-			    struct cras_iodev **devs, unsigned int num_devs);
+			    struct cras_iodev **devs,
+			    unsigned int num_devs);
 
 /* Begin draining a stream and check the draining status.
  * Args:
@@ -183,7 +183,8 @@
  *    fd - File to store aec dump result.
  */
 int audio_thread_set_aec_dump(struct audio_thread *thread,
-			      cras_stream_id_t stream_id, unsigned int start,
+			      cras_stream_id_t stream_id,
+			      unsigned int start,
 			      int fd);
 
 /* Configures the global converter for output remixing. Called by main
@@ -199,12 +200,12 @@
  *
  * Args:
  *   thread - a pointer to the audio thread.
- *   dev_idx - Index of the the device to start ramping.
+ *   dev - the device to start ramping.
  *   request - Check the docstrings of CRAS_IODEV_RAMP_REQUEST.
  * Returns:
  *    0 on success, negative if error.
  */
 int audio_thread_dev_start_ramp(struct audio_thread *thread,
-				unsigned int dev_idx,
+				struct cras_iodev *dev,
 				enum CRAS_IODEV_RAMP_REQUEST request);
 #endif /* AUDIO_THREAD_H_ */
diff --git a/cras/src/server/audio_thread_log.h b/cras/src/server/audio_thread_log.h
index ee5d159..122c5bd 100644
--- a/cras/src/server/audio_thread_log.h
+++ b/cras/src/server/audio_thread_log.h
@@ -8,86 +8,61 @@
 #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
+#define AUDIO_THREAD_LOGGING	1
 
 #if (AUDIO_THREAD_LOGGING)
-#define ATLOG(log, event, data1, data2, data3)                                 \
-	audio_thread_event_log_data(log, event, data1, data2, data3);
+#define ATLOG(log,event,data1,data2,data3) \
+	audio_thread_event_log_data(log,event,data1,data2,data3);
 #else
-#define ATLOG(log, event, data1, data2, data3)
+#define ATLOG(log,event,data1,data2,data3)
 #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(char *name)
+static inline
+struct audio_thread_event_log *audio_thread_event_log_init()
 {
 	struct audio_thread_event_log *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 = (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, char *name)
+static inline
+void audio_thread_event_log_deinit(struct audio_thread_event_log *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);
-	}
+	free(log);
 }
 
 /* Log a tag and the current time, Uses two words, the first is split
  * 8 bits for tag and 24 for seconds, second word is micro seconds.
  */
-static inline void
-audio_thread_event_log_data(struct audio_thread_event_log *log,
-			    enum AUDIO_THREAD_LOG_EVENTS event, uint32_t data1,
-			    uint32_t data2, uint32_t data3)
+static inline void audio_thread_event_log_data(
+		struct audio_thread_event_log *log,
+		enum AUDIO_THREAD_LOG_EVENTS event,
+		uint32_t data1,
+		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[pos_mod_len].tag_sec =
-		(event << 24) | (now.tv_sec & 0x00ffffff);
-	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;
+	clock_gettime(CLOCK_MONOTONIC_RAW, &now);
+	log->log[log->write_pos].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->write_pos++;
+	log->write_pos %= AUDIO_THREAD_EVENT_LOG_SIZE;
 }
 
 #endif /* AUDIO_THREAD_LOG_H_ */
diff --git a/cras/src/server/buffer_share.c b/cras/src/server/buffer_share.c
index 5d106f0..6fcee6f 100644
--- a/cras/src/server/buffer_share.c
+++ b/cras/src/server/buffer_share.c
@@ -21,6 +21,7 @@
 	return NULL;
 }
 
+
 static inline struct id_offset *find_id(const struct buffer_share *mix,
 					unsigned int id)
 {
@@ -39,8 +40,7 @@
 	unsigned int new_size = mix->id_sz * 2;
 	unsigned int i;
 
-	mix->wr_idx = (struct id_offset *)realloc(
-		mix->wr_idx, sizeof(mix->wr_idx[0]) * new_size);
+	mix->wr_idx = realloc(mix->wr_idx, sizeof(mix->wr_idx[0]) * new_size);
 
 	for (i = mix->id_sz; i < new_size; i++)
 		mix->wr_idx[i].used = 0;
@@ -52,10 +52,9 @@
 {
 	struct buffer_share *mix;
 
-	mix = (struct buffer_share *)calloc(1, sizeof(*mix));
+	mix = calloc(1, sizeof(*mix));
 	mix->id_sz = INITIAL_ID_SIZE;
-	mix->wr_idx =
-		(struct id_offset *)calloc(mix->id_sz, sizeof(mix->wr_idx[0]));
+	mix->wr_idx = calloc(mix->id_sz, sizeof(mix->wr_idx[0]));
 	mix->buf_sz = buf_sz;
 
 	return mix;
@@ -164,7 +163,8 @@
 	return o ? o->offset : 0;
 }
 
-void *buffer_share_get_data(const struct buffer_share *mix, unsigned int id)
+void *buffer_share_get_data(const struct buffer_share *mix,
+			    unsigned int id)
 {
 	struct id_offset *o = get_id_offset(mix, id);
 	return o ? o->data : NULL;
diff --git a/cras/src/server/buffer_share.h b/cras/src/server/buffer_share.h
index c61c7a0..1e6cae0 100644
--- a/cras/src/server/buffer_share.h
+++ b/cras/src/server/buffer_share.h
@@ -56,6 +56,7 @@
 /*
  * Gets the data pointer for given id.
  */
-void *buffer_share_get_data(const struct buffer_share *mix, unsigned int id);
+void *buffer_share_get_data(const struct buffer_share *mix,
+			    unsigned int id);
 
 #endif /* BUFFER_SHARE_H_ */
diff --git a/cras/src/server/config/aec_config.c b/cras/src/server/config/aec_config.c
new file mode 100644
index 0000000..d51d4b8
--- /dev/null
+++ b/cras/src/server/config/aec_config.c
@@ -0,0 +1,479 @@
+/* Copyright 2018 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 "aec_config.h"
+#include "iniparser_wrapper.h"
+
+static const unsigned int MAX_INI_NAME_LEN = 63;
+
+#define AEC_CONFIG_NAME "aec.ini"
+
+#define AEC_GET_INT(ini, category, key)			\
+	iniparser_getint(				\
+		ini, AEC_ ## category ## _ ## key,	\
+		AEC_ ## category ## _ ## key ## _VALUE)
+
+#define AEC_GET_FLOAT(ini, category, key)		\
+	iniparser_getdouble(				\
+		ini, AEC_ ## category ## _ ## key,	\
+		AEC_ ## category ## _ ## key ## _VALUE)
+
+struct aec_config *aec_config_get(const char *device_config_dir)
+{
+	struct aec_config *config;
+	char ini_name[MAX_INI_NAME_LEN + 1];
+	dictionary *ini;
+
+	snprintf(ini_name, MAX_INI_NAME_LEN, "%s/%s",
+		 device_config_dir, AEC_CONFIG_NAME);
+	ini_name[MAX_INI_NAME_LEN] = '\0';
+
+	ini = iniparser_load_wrapper(ini_name);
+	if (ini == NULL) {
+		syslog(LOG_DEBUG, "No ini file %s", ini_name);
+		return NULL;
+	}
+
+	config = (struct aec_config *)calloc(1, sizeof(*config));
+
+	config->delay.default_delay =
+		AEC_GET_INT(ini, DELAY, DEFAULT_DELAY);
+	config->delay.down_sampling_factor =
+		AEC_GET_INT(ini, DELAY, DOWN_SAMPLING_FACTOR);
+	config->delay.num_filters =
+		AEC_GET_INT(ini, DELAY, NUM_FILTERS);
+	config->delay.api_call_jitter_blocks =
+		AEC_GET_INT(ini, DELAY, API_CALL_JITTER_BLOCKS);
+	config->delay.min_echo_path_delay_blocks =
+		AEC_GET_INT(ini, DELAY, MIN_ECHO_PATH_DELAY_BLOCKS);
+	config->delay.delay_headroom_blocks =
+		AEC_GET_INT(ini, DELAY, DELAY_HEADROOM_BLOCKS);
+	config->delay.hysteresis_limit_1_blocks =
+		AEC_GET_INT(ini, DELAY, HYSTERESIS_LIMIT_1_BLOCKS);
+	config->delay.hysteresis_limit_2_blocks =
+		AEC_GET_INT(ini, DELAY, HYSTERESIS_LIMIT_2_BLOCKS);
+	config->delay.skew_hysteresis_blocks =
+		AEC_GET_INT(ini, DELAY, SKEW_HYSTERESIS_BLOCKS);
+	config->delay.fixed_capture_delay_samples =
+		AEC_GET_INT(ini, DELAY, FIXED_CAPTURE_DELAY_SAMPLES);
+
+	config->filter.main.length_blocks =
+		AEC_GET_INT(ini, FILTER_MAIN, LENGTH_BLOCKS);
+	config->filter.main.leakage_converged =
+		AEC_GET_FLOAT(ini, FILTER_MAIN, LEAKAGE_CONVERGED);
+	config->filter.main.leakage_diverged =
+		AEC_GET_FLOAT(ini, FILTER_MAIN, LEAKAGE_DIVERGED);
+	config->filter.main.error_floor =
+		AEC_GET_FLOAT(ini, FILTER_MAIN, ERROR_FLOOR);
+	config->filter.main.noise_gate =
+		AEC_GET_FLOAT(ini, FILTER_MAIN, NOISE_GATE);
+
+	config->filter.shadow.length_blocks =
+		AEC_GET_INT(ini, FILTER_SHADOW, LENGTH_BLOCKS);
+	config->filter.shadow.rate =
+		AEC_GET_FLOAT(ini, FILTER_SHADOW, RATE);
+	config->filter.shadow.noise_gate =
+		AEC_GET_FLOAT(ini, FILTER_SHADOW, NOISE_GATE);
+
+	config->filter.main_initial.length_blocks =
+		AEC_GET_INT(ini, FILTER_MAIN_INIT, LENGTH_BLOCKS);
+	config->filter.main_initial.leakage_converged =
+		AEC_GET_FLOAT(ini, FILTER_MAIN_INIT, LEAKAGE_CONVERGED);
+	config->filter.main_initial.leakage_diverged =
+		AEC_GET_FLOAT(ini, FILTER_MAIN_INIT, LEAKAGE_DIVERGED);
+	config->filter.main_initial.error_floor =
+		AEC_GET_FLOAT(ini, FILTER_MAIN_INIT, ERROR_FLOOR);
+	config->filter.main_initial.noise_gate =
+		AEC_GET_FLOAT(ini, FILTER_MAIN_INIT, NOISE_GATE);
+
+	config->filter.shadow_initial.length_blocks =
+		AEC_GET_INT(ini, FILTER_SHADOW_INIT, LENGTH_BLOCKS);
+	config->filter.shadow_initial.rate =
+		AEC_GET_FLOAT(ini, FILTER_SHADOW_INIT, RATE);
+	config->filter.shadow_initial.noise_gate =
+		AEC_GET_FLOAT(ini, FILTER_SHADOW_INIT, NOISE_GATE);
+
+	config->filter.config_change_duration_blocks =
+		AEC_GET_INT(ini, FILTER, CONFIG_CHANGE_DURATION_BLOCKS);
+	config->filter.initial_state_seconds =
+		AEC_GET_FLOAT(ini, FILTER, INITIAL_STATE_SECONDS);
+	config->filter.conservative_initial_phase =
+		AEC_GET_INT(ini, FILTER, CONSERVATIVE_INITIAL_PHASE);
+	config->filter.enable_shadow_filter_output_usage =
+		AEC_GET_INT(ini, FILTER, ENABLE_SHADOW_FILTER_OUTPUT_USAGE);
+
+	config->erle.min =
+		AEC_GET_FLOAT(ini, ERLE, MIN);
+	config->erle.max_l =
+		AEC_GET_FLOAT(ini, ERLE, MAX_L);
+	config->erle.max_h =
+		AEC_GET_FLOAT(ini, ERLE, MAX_H);
+	config->erle.onset_detection =
+		AEC_GET_INT(ini, ERLE, ONSET_DETECTION);
+
+	config->ep_strength.lf =
+		AEC_GET_FLOAT(ini, EP_STRENGTH, LF);
+	config->ep_strength.mf =
+		AEC_GET_FLOAT(ini, EP_STRENGTH, MF);
+	config->ep_strength.hf =
+		AEC_GET_FLOAT(ini, EP_STRENGTH, HF);
+	config->ep_strength.default_len =
+		AEC_GET_FLOAT(ini, EP_STRENGTH, DEFAULT_LEN);
+	config->ep_strength.reverb_based_on_render =
+		AEC_GET_INT(ini, EP_STRENGTH, REVERB_BASED_ON_RENDER);
+	config->ep_strength.bounded_erl =
+		AEC_GET_INT(ini, EP_STRENGTH, BOUNDED_ERL);
+	config->ep_strength.echo_can_saturate =
+		AEC_GET_INT(ini, EP_STRENGTH, ECHO_CAN_SATURATE);
+
+	config->gain_mask.m0 =
+		AEC_GET_FLOAT(ini, GAIN_MASK, M0);
+	config->gain_mask.m1 =
+		AEC_GET_FLOAT(ini, GAIN_MASK, M1);
+	config->gain_mask.m2 =
+		AEC_GET_FLOAT(ini, GAIN_MASK, M2);
+	config->gain_mask.m3 =
+		AEC_GET_FLOAT(ini, GAIN_MASK, M3);
+	config->gain_mask.m5 =
+		AEC_GET_FLOAT(ini, GAIN_MASK, M5);
+	config->gain_mask.m6 =
+		AEC_GET_FLOAT(ini, GAIN_MASK, M6);
+	config->gain_mask.m7 =
+		AEC_GET_FLOAT(ini, GAIN_MASK, M7);
+	config->gain_mask.m8 =
+		AEC_GET_FLOAT(ini, GAIN_MASK, M8);
+	config->gain_mask.m9 =
+		AEC_GET_FLOAT(ini, GAIN_MASK, M9);
+	config->gain_mask.gain_curve_offset =
+		AEC_GET_FLOAT(ini, GAIN_MASK, GAIN_CURVE_OFFSET);
+	config->gain_mask.gain_curve_slope =
+		AEC_GET_FLOAT(ini, GAIN_MASK, GAIN_CURVE_SLOPE);
+	config->gain_mask.temporal_masking_lf =
+		AEC_GET_FLOAT(ini, GAIN_MASK, TEMPORAL_MASKING_LF);
+	config->gain_mask.temporal_masking_hf =
+		AEC_GET_FLOAT(ini, GAIN_MASK, TEMPORAL_MASKING_HF);
+	config->gain_mask.temporal_masking_lf_bands =
+		AEC_GET_INT(ini, GAIN_MASK, TEMPORAL_MASKING_LF_BANDS);
+
+	config->echo_audibility.low_render_limit =
+		AEC_GET_FLOAT(ini, ECHO_AUDIBILITY, LOW_RENDER_LIMIT);
+	config->echo_audibility.normal_render_limit =
+		AEC_GET_FLOAT(ini, ECHO_AUDIBILITY, NORMAL_RENDER_LIMIT);
+	config->echo_audibility.floor_power =
+		AEC_GET_FLOAT(ini, ECHO_AUDIBILITY, FLOOR_POWER);
+	config->echo_audibility.audibility_threshold_lf =
+		AEC_GET_FLOAT(ini, ECHO_AUDIBILITY, AUDIBILITY_THRESHOLD_LF);
+	config->echo_audibility.audibility_threshold_mf =
+		AEC_GET_FLOAT(ini, ECHO_AUDIBILITY, AUDIBILITY_THRESHOLD_MF);
+	config->echo_audibility.audibility_threshold_hf =
+		AEC_GET_FLOAT(ini, ECHO_AUDIBILITY, AUDIBILITY_THRESHOLD_HF);
+	config->echo_audibility.use_stationary_properties =
+		AEC_GET_INT(ini, ECHO_AUDIBILITY, USE_STATIONARY_PROPERTIES);
+
+	config->render_levels.active_render_limit =
+		AEC_GET_FLOAT(ini, RENDER_LEVELS, ACTIVE_RENDER_LIMIT);
+	config->render_levels.poor_excitation_render_limit =
+		AEC_GET_FLOAT(ini, RENDER_LEVELS, POOR_EXCITATION_RENDER_LIMIT);
+	config->render_levels.poor_excitation_render_limit_ds8 =
+		AEC_GET_FLOAT(ini, RENDER_LEVELS, POOR_EXCITATION_RENDER_LIMIT_DS8);
+
+	config->echo_removal_control.gain_rampup.initial_gain =
+		AEC_GET_FLOAT(ini, ECHO_REMOVAL_CTL, INITIAL_GAIN);
+	config->echo_removal_control.gain_rampup.first_non_zero_gain =
+		AEC_GET_FLOAT(ini, ECHO_REMOVAL_CTL, FIRST_NON_ZERO_GAIN);
+	config->echo_removal_control.gain_rampup.non_zero_gain_blocks =
+		AEC_GET_INT(ini, ECHO_REMOVAL_CTL, NON_ZERO_GAIN_BLOCKS);
+	config->echo_removal_control.gain_rampup.full_gain_blocks =
+		AEC_GET_INT(ini, ECHO_REMOVAL_CTL, FULL_GAIN_BLOCKS);
+	config->echo_removal_control.has_clock_drift =
+		AEC_GET_INT(ini, ECHO_REMOVAL_CTL, HAS_CLOCK_DRIFT);
+	config->echo_removal_control.linear_and_stable_echo_path =
+		AEC_GET_INT(ini, ECHO_REMOVAL_CTL, LINEAR_AND_STABLE_ECHO_PATH);
+
+	config->echo_model.noise_floor_hold =
+		AEC_GET_INT(ini, ECHO_MODEL, NOISE_FLOOR_HOLD);
+	config->echo_model.min_noise_floor_power =
+		AEC_GET_FLOAT(ini, ECHO_MODEL, MIN_NOISE_FLOOR_POWER);
+	config->echo_model.stationary_gate_slope =
+		AEC_GET_FLOAT(ini, ECHO_MODEL, STATIONARY_GATE_SLOPE);
+	config->echo_model.noise_gate_power =
+		AEC_GET_FLOAT(ini, ECHO_MODEL, NOISE_GATE_POWER);
+	config->echo_model.noise_gate_slope =
+		AEC_GET_FLOAT(ini, ECHO_MODEL, NOISE_GATE_SLOPE);
+	config->echo_model.render_pre_window_size =
+		AEC_GET_INT(ini, ECHO_MODEL, RENDER_PRE_WINDOW_SIZE);
+	config->echo_model.render_post_window_size =
+		AEC_GET_INT(ini, ECHO_MODEL, RENDER_POST_WINDOW_SIZE);
+	config->echo_model.render_pre_window_size_init =
+		AEC_GET_INT(ini, ECHO_MODEL, RENDER_PRE_WINDOW_SIZE_INIT);
+	config->echo_model.render_post_window_size_init =
+		AEC_GET_INT(ini, ECHO_MODEL, RENDER_POST_WINDOW_SIZE_INIT);
+	config->echo_model.nonlinear_hold =
+		AEC_GET_FLOAT(ini, ECHO_MODEL, NONLINEAR_HOLD);
+	config->echo_model.nonlinear_release =
+		AEC_GET_FLOAT(ini, ECHO_MODEL, NONLINEAR_RELEASE);
+
+	config->suppressor.nearend_average_blocks =
+		AEC_GET_INT(ini, SUPPRESSOR, NEAREND_AVERAGE_BLOCKS);
+
+	config->suppressor.normal_tuning.mask_lf.enr_transparent =
+		AEC_GET_FLOAT(ini, SUPPRESSOR_NORMAL_TUNING,
+			      MASK_LF_ENR_TRANSPARENT);
+	config->suppressor.normal_tuning.mask_lf.enr_suppress =
+		AEC_GET_FLOAT(ini, SUPPRESSOR_NORMAL_TUNING,
+			      MASK_LF_ENR_SUPPRESS);
+	config->suppressor.normal_tuning.mask_lf.emr_transparent =
+		AEC_GET_FLOAT(ini, SUPPRESSOR_NORMAL_TUNING,
+			      MASK_LF_EMR_TRANSPARENT);
+	config->suppressor.normal_tuning.mask_hf.enr_transparent =
+		AEC_GET_FLOAT(ini, SUPPRESSOR_NORMAL_TUNING,
+			      MASK_HF_ENR_TRANSPARENT);
+	config->suppressor.normal_tuning.mask_hf.enr_suppress =
+		AEC_GET_FLOAT(ini, SUPPRESSOR_NORMAL_TUNING,
+			      MASK_HF_ENR_SUPPRESS);
+	config->suppressor.normal_tuning.mask_hf.emr_transparent =
+		AEC_GET_FLOAT(ini, SUPPRESSOR_NORMAL_TUNING,
+			      MASK_HF_EMR_TRANSPARENT);
+	config->suppressor.normal_tuning.max_inc_factor =
+		AEC_GET_FLOAT(ini, SUPPRESSOR_NORMAL_TUNING, MAX_INC_FACTOR);
+	config->suppressor.normal_tuning.max_dec_factor_lf =
+		AEC_GET_FLOAT(ini, SUPPRESSOR_NORMAL_TUNING, MAX_DEC_FACTOR_LF);
+
+	config->suppressor.nearend_tuning.mask_lf.enr_transparent =
+		AEC_GET_FLOAT(ini, SUPPRESSOR_NEAREND_TUNING,
+			      MASK_LF_ENR_TRANSPARENT);
+	config->suppressor.nearend_tuning.mask_lf.enr_suppress =
+		AEC_GET_FLOAT(ini, SUPPRESSOR_NEAREND_TUNING,
+			      MASK_LF_ENR_SUPPRESS);
+	config->suppressor.nearend_tuning.mask_lf.emr_transparent =
+		AEC_GET_FLOAT(ini, SUPPRESSOR_NEAREND_TUNING,
+			      MASK_LF_EMR_TRANSPARENT);
+	config->suppressor.nearend_tuning.mask_hf.enr_transparent =
+		AEC_GET_FLOAT(ini, SUPPRESSOR_NEAREND_TUNING,
+			      MASK_HF_ENR_TRANSPARENT);
+	config->suppressor.nearend_tuning.mask_hf.enr_suppress =
+		AEC_GET_FLOAT(ini, SUPPRESSOR_NEAREND_TUNING,
+			      MASK_HF_ENR_SUPPRESS);
+	config->suppressor.nearend_tuning.mask_hf.emr_transparent =
+		AEC_GET_FLOAT(ini, SUPPRESSOR_NEAREND_TUNING,
+			      MASK_HF_EMR_TRANSPARENT);
+	config->suppressor.nearend_tuning.max_inc_factor =
+		AEC_GET_FLOAT(ini, SUPPRESSOR_NEAREND_TUNING, MAX_INC_FACTOR);
+	config->suppressor.nearend_tuning.max_dec_factor_lf =
+		AEC_GET_FLOAT(ini, SUPPRESSOR_NEAREND_TUNING, MAX_DEC_FACTOR_LF);
+
+	config->suppressor.dominant_nearend_detection.enr_threshold =
+		AEC_GET_FLOAT(ini, SUPPRESSOR_DOMINANT_NEAREND_DETECTION,
+			ENR_THRESHOLD);
+	config->suppressor.dominant_nearend_detection.snr_threshold =
+		AEC_GET_FLOAT(ini, SUPPRESSOR_DOMINANT_NEAREND_DETECTION,
+			SNR_THRESHOLD);
+	config->suppressor.dominant_nearend_detection.hold_duration =
+		AEC_GET_INT(ini, SUPPRESSOR_DOMINANT_NEAREND_DETECTION,
+			HOLD_DURATION);
+	config->suppressor.dominant_nearend_detection.trigger_threshold =
+		AEC_GET_INT(ini, SUPPRESSOR_DOMINANT_NEAREND_DETECTION,
+			TRIGGER_THRESHOLD);
+
+	config->suppressor.high_bands_suppression.enr_threshold =
+		AEC_GET_FLOAT(ini, SUPPRESSOR_HIGH_BANDS_SUPPRESSION,
+			ENR_THRESHOLD);
+	config->suppressor.high_bands_suppression.max_gain_during_echo =
+		AEC_GET_FLOAT(ini, SUPPRESSOR_HIGH_BANDS_SUPPRESSION,
+			MAX_GAIN_DURING_ECHO);
+
+	config->suppressor.floor_first_increase =
+		AEC_GET_FLOAT(ini, SUPPRESSOR, FLOOR_FIRST_INCREASE);
+	config->suppressor.enforce_transparent =
+		AEC_GET_INT(ini, SUPPRESSOR, ENFORCE_TRANSPARENT);
+	config->suppressor.enforce_empty_higher_bands =
+		AEC_GET_INT(ini, SUPPRESSOR, ENFORCE_EMPTY_HIGHER_BANDS);
+
+	return config;
+}
+
+void aec_config_dump(struct aec_config *config)
+{
+	syslog(LOG_ERR, "---- aec config dump ----");
+	syslog(LOG_ERR, "Delay:");
+	syslog(LOG_ERR, "    default_delay %zu sampling_factor %zu num_filters %zu",
+			config->delay.default_delay,
+			config->delay.down_sampling_factor,
+			config->delay.num_filters);
+	syslog(LOG_ERR, "    api_call_jitter_blocks %zu, min_echo_path_delay_blocks %zu",
+			config->delay.api_call_jitter_blocks,
+			config->delay.min_echo_path_delay_blocks);
+	syslog(LOG_ERR, "    delay_headroom_blocks %zu, hysteresis_limit_1_blocks %zu",
+			config->delay.delay_headroom_blocks,
+			config->delay.hysteresis_limit_1_blocks);
+	syslog(LOG_ERR, "    hysteresis_limit_2_blocks %zu, skew_hysteresis_blocks %zu",
+			config->delay.hysteresis_limit_2_blocks,
+			config->delay.skew_hysteresis_blocks);
+	syslog(LOG_ERR, "    fixed_capture_delay_samples %zu",
+			config->delay.fixed_capture_delay_samples);
+
+	syslog(LOG_ERR, "Filter main configuration:");
+	syslog(LOG_ERR, "    length_blocks %zu, leakage_converged %f, leakage_diverged %f",
+			config->filter.main.length_blocks,
+			config->filter.main.leakage_converged,
+			config->filter.main.leakage_diverged);
+	syslog(LOG_ERR, "    error_floor %f, noise_gate %f",
+			config->filter.main.error_floor,
+			config->filter.main.noise_gate);
+	syslog(LOG_ERR, "Filter shadow configuration:");
+	syslog(LOG_ERR, "    length_blocks %zu, rate %f, noise_gate %f",
+			config->filter.shadow.length_blocks,
+			config->filter.shadow.rate,
+			config->filter.shadow.noise_gate);
+	syslog(LOG_ERR, "Filter main initial configuration:");
+	syslog(LOG_ERR, "    length_blocks %zu, leakage_converged %f",
+			config->filter.main_initial.length_blocks,
+			config->filter.main_initial.leakage_converged);
+	syslog(LOG_ERR, "    leakage_diverged %f, error_floor %f, noise_gate %f",
+			config->filter.main_initial.leakage_diverged,
+			config->filter.main_initial.error_floor,
+			config->filter.main_initial.noise_gate);
+	syslog(LOG_ERR, "Filter shadow initial configuration:");
+	syslog(LOG_ERR, "    length_blocks %zu, rate %f, noise_gate %f",
+			config->filter.shadow_initial.length_blocks,
+			config->filter.shadow_initial.rate,
+			config->filter.shadow_initial.noise_gate);
+	syslog(LOG_ERR, "Filter:    config_change_duration_blocks %d",
+			config->filter.config_change_duration_blocks);
+	syslog(LOG_ERR, "    initial_state_seconds %f",
+			config->filter.initial_state_seconds);
+	syslog(LOG_ERR, "    conservative_initial_phase %d",
+			config->filter.conservative_initial_phase);
+	syslog(LOG_ERR, "    enable_shadow_filter_output_usage %d",
+			config->filter.enable_shadow_filter_output_usage);
+	syslog(LOG_ERR, "Erle: min %f max_l %f max_h %f onset_detection %d",
+			config->erle.min, config->erle.max_l,
+			config->erle.max_h, config->erle.onset_detection);
+	syslog(LOG_ERR, "Ep strength: lf %f mf %f hf %f default_len %f",
+			config->ep_strength.lf,
+			config->ep_strength.mf,
+			config->ep_strength.hf,
+			config->ep_strength.default_len);
+	syslog(LOG_ERR, "    echo_can_saturate %d, bounded_erl %d,"
+			"    ep_strength.reverb_based_on_render %d",
+			config->ep_strength.echo_can_saturate,
+			config->ep_strength.bounded_erl,
+			config->ep_strength.reverb_based_on_render);
+	syslog(LOG_ERR, "Gain mask: m0 %f m1 %f m2 %f m3 %f m5 %f",
+			config->gain_mask.m0,
+			config->gain_mask.m1,
+			config->gain_mask.m2,
+			config->gain_mask.m3,
+			config->gain_mask.m5);
+	syslog(LOG_ERR, "    m6 %f m7 %f m8 %f m9 %f",
+			config->gain_mask.m6,
+			config->gain_mask.m7,
+			config->gain_mask.m8,
+			config->gain_mask.m9);
+	syslog(LOG_ERR, "    gain_curve offset %f, gain_curve_slope %f",
+			config->gain_mask.gain_curve_offset,
+			config->gain_mask.gain_curve_slope);
+	syslog(LOG_ERR, "    temporal_masking_lf %f, temporal_masking_hf %f",
+			config->gain_mask.temporal_masking_lf,
+			config->gain_mask.temporal_masking_hf);
+	syslog(LOG_ERR, "    temporal_masking_lf_bands %zu",
+			config->gain_mask.temporal_masking_lf_bands);
+	syslog(LOG_ERR, "Echo audibility:");
+	syslog(LOG_ERR, "    low_render_limit %f, normal_render_limit %f",
+			config->echo_audibility.low_render_limit,
+			config->echo_audibility.normal_render_limit);
+	syslog(LOG_ERR, "    floor_power %f, audibility_threshold_lf %f",
+			config->echo_audibility.floor_power,
+			config->echo_audibility.audibility_threshold_lf);
+	syslog(LOG_ERR, "    audibility_threshold_mf %f",
+			config->echo_audibility.audibility_threshold_mf);
+	syslog(LOG_ERR, "    audibility_threshold_hf %f",
+			config->echo_audibility.audibility_threshold_hf);
+	syslog(LOG_ERR, "    use_stationary_properties %d",
+			config->echo_audibility.use_stationary_properties);
+	syslog(LOG_ERR, "Render levels:");
+	syslog(LOG_ERR, "    active_render_limit %f",
+			config->render_levels.active_render_limit);
+	syslog(LOG_ERR, "    poor_excitation_render_limit %f",
+			config->render_levels.poor_excitation_render_limit);
+	syslog(LOG_ERR, "    poor_excitation_render_limit_ds8 %f",
+			config->render_levels.poor_excitation_render_limit_ds8);
+	syslog(LOG_ERR, "Echo removal control:");
+	syslog(LOG_ERR, "    gain rampup:");
+	syslog(LOG_ERR, "        initial_gain %f, first_non_zero_gain %f",
+			config->echo_removal_control.gain_rampup.initial_gain,
+			config->echo_removal_control.gain_rampup.first_non_zero_gain);
+	syslog(LOG_ERR, "        non_zero_gain_blocks %d, full_gain_blocks %d",
+			config->echo_removal_control.gain_rampup.non_zero_gain_blocks,
+			config->echo_removal_control.gain_rampup.full_gain_blocks);
+	syslog(LOG_ERR, "    has_clock_drift %d",
+			config->echo_removal_control.has_clock_drift);
+	syslog(LOG_ERR, "    linear_and_stable_echo_path %d",
+			config->echo_removal_control.linear_and_stable_echo_path);
+	syslog(LOG_ERR, "Echo model:");
+	syslog(LOG_ERR, "    noise_floor_hold %zu, min_noise_floor_power %f",
+			config->echo_model.noise_floor_hold,
+			config->echo_model.min_noise_floor_power);
+	syslog(LOG_ERR, "    stationary_gate_slope %f, noise_gate_power %f",
+			config->echo_model.stationary_gate_slope,
+			config->echo_model.noise_gate_power);
+	syslog(LOG_ERR, "    noise_gate_slope %f, render_pre_window_size %zu",
+			config->echo_model.noise_gate_slope,
+			config->echo_model.render_pre_window_size);
+	syslog(LOG_ERR, "    render_post_window_size %zu nonlinear_hold %f",
+			config->echo_model.render_post_window_size,
+			config->echo_model.nonlinear_hold);
+	syslog(LOG_ERR, "    render_pre_window_size_init %u, "
+			"render_post_window_size_init %u",
+			config->echo_model.render_pre_window_size_init,
+			config->echo_model.render_post_window_size_init);
+	syslog(LOG_ERR, "    nonlinear_release %f",
+			config->echo_model.nonlinear_release);
+	syslog(LOG_ERR, "Suppressor:");
+	syslog(LOG_ERR, "    nearend_average_blocks %u",
+			config->suppressor.nearend_average_blocks);
+	syslog(LOG_ERR, "    Normal tuning, mask_lf %f %f %f",
+			config->suppressor.normal_tuning.mask_lf.enr_transparent,
+			config->suppressor.normal_tuning.mask_lf.enr_suppress,
+			config->suppressor.normal_tuning.mask_lf.emr_transparent);
+	syslog(LOG_ERR, "                   mask_hf %f %f %f",
+			config->suppressor.normal_tuning.mask_hf.enr_transparent,
+			config->suppressor.normal_tuning.mask_hf.enr_suppress,
+			config->suppressor.normal_tuning.mask_hf.emr_transparent);
+	syslog(LOG_ERR, "                   max_inc_factor %f max_dec_factor_lf %f",
+			config->suppressor.normal_tuning.max_inc_factor,
+			config->suppressor.normal_tuning.max_dec_factor_lf);
+	syslog(LOG_ERR, "    Nearend tuning, mask_lf %f %f %f",
+			config->suppressor.nearend_tuning.mask_lf.enr_transparent,
+			config->suppressor.nearend_tuning.mask_lf.enr_suppress,
+			config->suppressor.nearend_tuning.mask_lf.emr_transparent);
+	syslog(LOG_ERR, "                   mask_hf %f %f %f",
+			config->suppressor.nearend_tuning.mask_hf.enr_transparent,
+			config->suppressor.nearend_tuning.mask_hf.enr_suppress,
+			config->suppressor.nearend_tuning.mask_hf.emr_transparent);
+	syslog(LOG_ERR, "                   max_inc_factor %f max_dec_factor_lf %f",
+			config->suppressor.nearend_tuning.max_inc_factor,
+			config->suppressor.nearend_tuning.max_dec_factor_lf);
+	syslog(LOG_ERR, "    Dominant nearend detection:");
+	syslog(LOG_ERR, "        enr_threshold %f",
+			config->suppressor.dominant_nearend_detection.enr_threshold);
+	syslog(LOG_ERR, "        snr_threshold %f",
+			config->suppressor.dominant_nearend_detection.snr_threshold);
+	syslog(LOG_ERR, "        hold_duration %d",
+			config->suppressor.dominant_nearend_detection.hold_duration);
+	syslog(LOG_ERR, "        trigger_threshold %d",
+			config->suppressor.dominant_nearend_detection.trigger_threshold);
+	syslog(LOG_ERR, "    High bands suppression:");
+	syslog(LOG_ERR, "        enr_threshold %f max_gain_during_echo %f",
+			config->suppressor.high_bands_suppression.enr_threshold,
+			config->suppressor.high_bands_suppression.max_gain_during_echo);
+	syslog(LOG_ERR, "    floor_first_increase %f, enforce_transparent %d",
+			config->suppressor.floor_first_increase,
+			config->suppressor.enforce_transparent);
+	syslog(LOG_ERR, "    enforce_empty_higher_bands %f",
+			config->suppressor.enforce_empty_higher_bands);
+}
diff --git a/cras/src/server/config/aec_config.h b/cras/src/server/config/aec_config.h
new file mode 100644
index 0000000..015ca76
--- /dev/null
+++ b/cras/src/server/config/aec_config.h
@@ -0,0 +1,318 @@
+/* Copyright 2018 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 AEC_CONFIG_H_
+#define AEC_CONFIG_H_
+
+#include <webrtc-apm/webrtc_apm.h>
+
+#define AEC_DELAY_DEFAULT_DELAY "delay:default_delay"
+#define AEC_DELAY_DEFAULT_DELAY_VALUE 5
+#define AEC_DELAY_DOWN_SAMPLING_FACTOR "delay:down_sampling_factor"
+#define AEC_DELAY_DOWN_SAMPLING_FACTOR_VALUE 4
+#define AEC_DELAY_NUM_FILTERS "delay:num_filters"
+#define AEC_DELAY_NUM_FILTERS_VALUE 6
+#define AEC_DELAY_API_CALL_JITTER_BLOCKS "delay:api_call_jitter_blocks"
+#define AEC_DELAY_API_CALL_JITTER_BLOCKS_VALUE 26
+#define AEC_DELAY_MIN_ECHO_PATH_DELAY_BLOCKS "delay:min_echo_path_delay_blocks"
+#define AEC_DELAY_MIN_ECHO_PATH_DELAY_BLOCKS_VALUE 0
+#define AEC_DELAY_DELAY_HEADROOM_BLOCKS "delay:delay_headroom_blocks"
+#define AEC_DELAY_DELAY_HEADROOM_BLOCKS_VALUE 2
+#define AEC_DELAY_HYSTERESIS_LIMIT_1_BLOCKS "delay:hysteresis_limit_1_blocks"
+#define AEC_DELAY_HYSTERESIS_LIMIT_1_BLOCKS_VALUE 1
+#define AEC_DELAY_HYSTERESIS_LIMIT_2_BLOCKS "delay:hysteresis_limit_2_blocks"
+#define AEC_DELAY_HYSTERESIS_LIMIT_2_BLOCKS_VALUE 1
+#define AEC_DELAY_SKEW_HYSTERESIS_BLOCKS "delay:skew_hysteresis_blocks"
+#define AEC_DELAY_SKEW_HYSTERESIS_BLOCKS_VALUE 3
+#define AEC_DELAY_FIXED_CAPTURE_DELAY_SAMPLES \
+	"delay:fixed_capture_delay_samples"
+#define AEC_DELAY_FIXED_CAPTURE_DELAY_SAMPLES_VALUE 0
+
+// Filter Main configuration
+#define AEC_FILTER_MAIN_LENGTH_BLOCKS "filter.main:length_blocks"
+#define AEC_FILTER_MAIN_LENGTH_BLOCKS_VALUE 13
+#define AEC_FILTER_MAIN_LEAKAGE_CONVERGED "filter.main:leakage_converged"
+#define AEC_FILTER_MAIN_LEAKAGE_CONVERGED_VALUE 0.00005f
+#define AEC_FILTER_MAIN_LEAKAGE_DIVERGED "filter.main:leakage_diverged"
+#define AEC_FILTER_MAIN_LEAKAGE_DIVERGED_VALUE 0.01f
+#define AEC_FILTER_MAIN_ERROR_FLOOR "filter.main:error_floor"
+#define AEC_FILTER_MAIN_ERROR_FLOOR_VALUE 0.1f
+#define AEC_FILTER_MAIN_NOISE_GATE "filter.main:noise_gate"
+#define AEC_FILTER_MAIN_NOISE_GATE_VALUE 20075344.f
+
+// Filter Shadow configuration
+#define AEC_FILTER_SHADOW_LENGTH_BLOCKS "filter.shadow:length_blocks"
+#define AEC_FILTER_SHADOW_LENGTH_BLOCKS_VALUE 13
+#define AEC_FILTER_SHADOW_RATE "filter.shadow:rate"
+#define AEC_FILTER_SHADOW_RATE_VALUE 0.7f
+#define AEC_FILTER_SHADOW_NOISE_GATE "filter.shadow:noise_gate"
+#define AEC_FILTER_SHADOW_NOISE_GATE_VALUE 20075344.f
+
+// Filter Main initial configuration
+#define AEC_FILTER_MAIN_INIT_LENGTH_BLOCKS "filter.main_initial:length_blocks"
+#define AEC_FILTER_MAIN_INIT_LENGTH_BLOCKS_VALUE 12
+#define AEC_FILTER_MAIN_INIT_LEAKAGE_CONVERGED \
+	"filter.main_initial:leakage_converged"
+#define AEC_FILTER_MAIN_INIT_LEAKAGE_CONVERGED_VALUE 0.005f
+#define AEC_FILTER_MAIN_INIT_LEAKAGE_DIVERGED \
+	"filter.main_initial:leakage_diverged"
+#define AEC_FILTER_MAIN_INIT_LEAKAGE_DIVERGED_VALUE 0.5f
+#define AEC_FILTER_MAIN_INIT_ERROR_FLOOR "filter.main_initial:error_floor"
+#define AEC_FILTER_MAIN_INIT_ERROR_FLOOR_VALUE 0.001f
+#define AEC_FILTER_MAIN_INIT_NOISE_GATE "filter.main_initial:noise_gate"
+#define AEC_FILTER_MAIN_INIT_NOISE_GATE_VALUE 20075344.f
+
+// Filter Shadow initial configuration
+#define AEC_FILTER_SHADOW_INIT_LENGTH_BLOCKS \
+	"filter.shadow_initial:length_blocks"
+#define AEC_FILTER_SHADOW_INIT_LENGTH_BLOCKS_VALUE 12
+#define AEC_FILTER_SHADOW_INIT_RATE "filter.shadow_initial:rate"
+#define AEC_FILTER_SHADOW_INIT_RATE_VALUE 0.9f
+#define AEC_FILTER_SHADOW_INIT_NOISE_GATE "filter.shadow_initial:noise_gate"
+#define AEC_FILTER_SHADOW_INIT_NOISE_GATE_VALUE 20075344.f
+
+#define AEC_FILTER_CONFIG_CHANGE_DURATION_BLOCKS \
+	"filter:config_change_duration_blocks"
+#define AEC_FILTER_CONFIG_CHANGE_DURATION_BLOCKS_VALUE 250
+#define AEC_FILTER_INITIAL_STATE_SECONDS "filter:initial_state_seconds"
+#define AEC_FILTER_INITIAL_STATE_SECONDS_VALUE 2.5f
+#define AEC_FILTER_CONSERVATIVE_INITIAL_PHASE \
+	"filter:conservative_initial_phase"
+#define AEC_FILTER_CONSERVATIVE_INITIAL_PHASE_VALUE 0
+#define AEC_FILTER_ENABLE_SHADOW_FILTER_OUTPUT_USAGE \
+	"filter:enable_shadow_filter_output_usage"
+#define AEC_FILTER_ENABLE_SHADOW_FILTER_OUTPUT_USAGE_VALUE 1
+
+// Erle
+#define AEC_ERLE_MIN "erle:min"
+#define AEC_ERLE_MIN_VALUE 1.f
+#define AEC_ERLE_MAX_L "erle:max_l"
+#define AEC_ERLE_MAX_L_VALUE 4.f
+#define AEC_ERLE_MAX_H "erle:max_h"
+#define AEC_ERLE_MAX_H_VALUE 1.5f
+#define AEC_ERLE_ONSET_DETECTION "erle:onset_detection"
+#define AEC_ERLE_ONSET_DETECTION_VALUE 1
+
+// EpStrength
+#define AEC_EP_STRENGTH_LF "ep_strength:lf"
+#define AEC_EP_STRENGTH_LF_VALUE 1.f
+#define AEC_EP_STRENGTH_MF "ep_strength:mf"
+#define AEC_EP_STRENGTH_MF_VALUE 1.f
+#define AEC_EP_STRENGTH_HF "ep_strength:hf"
+#define AEC_EP_STRENGTH_HF_VALUE 1.f
+#define AEC_EP_STRENGTH_DEFAULT_LEN "ep_strength:default_len"
+#define AEC_EP_STRENGTH_DEFAULT_LEN_VALUE 0.88f
+#define AEC_EP_STRENGTH_REVERB_BASED_ON_RENDER \
+	"ep_strength:reverb_based_on_render"
+#define AEC_EP_STRENGTH_REVERB_BASED_ON_RENDER_VALUE 1
+#define AEC_EP_STRENGTH_ECHO_CAN_SATURATE "ep_strength:echo_can_saturate"
+#define AEC_EP_STRENGTH_ECHO_CAN_SATURATE_VALUE 1
+#define AEC_EP_STRENGTH_BOUNDED_ERL "ep_strength:bounded_erl"
+#define AEC_EP_STRENGTH_BOUNDED_ERL_VALUE 0
+
+// Gain mask
+#define AEC_GAIN_MASK_M0 "gain_mask:m0"
+#define AEC_GAIN_MASK_M0_VALUE 0.1f
+#define AEC_GAIN_MASK_M1 "gain_mask:m1"
+#define AEC_GAIN_MASK_M1_VALUE 0.01f
+#define AEC_GAIN_MASK_M2 "gain_mask:m2"
+#define AEC_GAIN_MASK_M2_VALUE 0.0001f
+#define AEC_GAIN_MASK_M3 "gain_mask:m3"
+#define AEC_GAIN_MASK_M3_VALUE 0.01f
+// m4 was removed intentionally.
+// https://webrtc-review.googlesource.com/c/src/+/70421
+#define AEC_GAIN_MASK_M5 "gain_mask:m5"
+#define AEC_GAIN_MASK_M5_VALUE 0.01f
+#define AEC_GAIN_MASK_M6 "gain_mask:m6"
+#define AEC_GAIN_MASK_M6_VALUE 0.0001f
+#define AEC_GAIN_MASK_M7 "gain_mask:m7"
+#define AEC_GAIN_MASK_M7_VALUE 0.01f
+#define AEC_GAIN_MASK_M8 "gain_mask:m8"
+#define AEC_GAIN_MASK_M8_VALUE 0.0001f
+#define AEC_GAIN_MASK_M9 "gain_mask:m9"
+#define AEC_GAIN_MASK_M9_VALUE 0.1f
+#define AEC_GAIN_MASK_GAIN_CURVE_OFFSET "gain_mask:gain_curve_offset"
+#define AEC_GAIN_MASK_GAIN_CURVE_OFFSET_VALUE 1.45f
+#define AEC_GAIN_MASK_GAIN_CURVE_SLOPE "gain_mask:gain_curve_slope"
+#define AEC_GAIN_MASK_GAIN_CURVE_SLOPE_VALUE 5.f
+#define AEC_GAIN_MASK_TEMPORAL_MASKING_LF "gain_mask:temporal_masking_lf"
+#define AEC_GAIN_MASK_TEMPORAL_MASKING_LF_VALUE 0.9f
+#define AEC_GAIN_MASK_TEMPORAL_MASKING_HF "gain_mask:temporal_masking_hf"
+#define AEC_GAIN_MASK_TEMPORAL_MASKING_HF_VALUE 0.6f
+#define AEC_GAIN_MASK_TEMPORAL_MASKING_LF_BANDS \
+	"gain_mask:temporal_masking_lf_bands"
+#define AEC_GAIN_MASK_TEMPORAL_MASKING_LF_BANDS_VALUE 3
+
+#define AEC_ECHO_AUDIBILITY_LOW_RENDER_LIMIT "echo_audibility:low_render_limit"
+#define AEC_ECHO_AUDIBILITY_LOW_RENDER_LIMIT_VALUE 4 * 64.f
+#define AEC_ECHO_AUDIBILITY_NORMAL_RENDER_LIMIT \
+	"echo_audibility:normal_render_limit"
+#define AEC_ECHO_AUDIBILITY_NORMAL_RENDER_LIMIT_VALUE 64.f
+#define AEC_ECHO_AUDIBILITY_FLOOR_POWER "echo_audibility:floor_power"
+#define AEC_ECHO_AUDIBILITY_FLOOR_POWER_VALUE 2 * 64.f
+#define AEC_ECHO_AUDIBILITY_AUDIBILITY_THRESHOLD_LF \
+	"echo_audibility:audibility_threshold_lf"
+#define AEC_ECHO_AUDIBILITY_AUDIBILITY_THRESHOLD_LF_VALUE 10
+#define AEC_ECHO_AUDIBILITY_AUDIBILITY_THRESHOLD_MF \
+	"echo_audibility:audibility_threshold_mf"
+#define AEC_ECHO_AUDIBILITY_AUDIBILITY_THRESHOLD_MF_VALUE 10
+#define AEC_ECHO_AUDIBILITY_AUDIBILITY_THRESHOLD_HF \
+	"echo_audibility:audibility_threshold_hf"
+#define AEC_ECHO_AUDIBILITY_AUDIBILITY_THRESHOLD_HF_VALUE 10
+#define AEC_ECHO_AUDIBILITY_USE_STATIONARY_PROPERTIES \
+	"echo_audibility:use_stationary_properties"
+#define AEC_ECHO_AUDIBILITY_USE_STATIONARY_PROPERTIES_VALUE 1
+
+// Rendering levels
+#define AEC_RENDER_LEVELS_ACTIVE_RENDER_LIMIT \
+	"render_levels:active_render_limit"
+#define AEC_RENDER_LEVELS_ACTIVE_RENDER_LIMIT_VALUE 100.f
+#define AEC_RENDER_LEVELS_POOR_EXCITATION_RENDER_LIMIT \
+	"render_levels:poor_excitation_render_limit"
+#define AEC_RENDER_LEVELS_POOR_EXCITATION_RENDER_LIMIT_VALUE 150.f
+#define AEC_RENDER_LEVELS_POOR_EXCITATION_RENDER_LIMIT_DS8 \
+	"render_levels:poor_excitation_render_limit_ds8"
+#define AEC_RENDER_LEVELS_POOR_EXCITATION_RENDER_LIMIT_DS8_VALUE 20.f
+
+// Echo removal controls
+#define AEC_ECHO_REMOVAL_CTL_INITIAL_GAIN "echo_removal_control:initial_gain"
+#define AEC_ECHO_REMOVAL_CTL_INITIAL_GAIN_VALUE 0.0f
+#define AEC_ECHO_REMOVAL_CTL_FIRST_NON_ZERO_GAIN \
+	"echo_removal_control:first_non_zero_gain"
+#define AEC_ECHO_REMOVAL_CTL_FIRST_NON_ZERO_GAIN_VALUE 0.001f
+#define AEC_ECHO_REMOVAL_CTL_NON_ZERO_GAIN_BLOCKS \
+	"echo_removal_control:non_zero_gain_blocks"
+#define AEC_ECHO_REMOVAL_CTL_NON_ZERO_GAIN_BLOCKS_VALUE 187
+#define AEC_ECHO_REMOVAL_CTL_FULL_GAIN_BLOCKS \
+	"echo_removal_control:full_gain_blocks"
+#define AEC_ECHO_REMOVAL_CTL_FULL_GAIN_BLOCKS_VALUE 312
+#define AEC_ECHO_REMOVAL_CTL_HAS_CLOCK_DRIFT \
+	"echo_removal_control:has_clock_drift"
+#define AEC_ECHO_REMOVAL_CTL_HAS_CLOCK_DRIFT_VALUE 0
+#define AEC_ECHO_REMOVAL_CTL_LINEAR_AND_STABLE_ECHO_PATH \
+	"echo_removal_control:linear_and_stable_echo_path"
+#define AEC_ECHO_REMOVAL_CTL_LINEAR_AND_STABLE_ECHO_PATH_VALUE 0
+
+// EchoModel
+#define AEC_ECHO_MODEL_NOISE_FLOOR_HOLD "echo_model:noise_floor_hold"
+#define AEC_ECHO_MODEL_NOISE_FLOOR_HOLD_VALUE 50
+#define AEC_ECHO_MODEL_MIN_NOISE_FLOOR_POWER "echo_model:min_noise_floor_power"
+#define AEC_ECHO_MODEL_MIN_NOISE_FLOOR_POWER_VALUE 1638400.f
+#define AEC_ECHO_MODEL_STATIONARY_GATE_SLOPE "echo_model:stationary_gate_slope"
+#define AEC_ECHO_MODEL_STATIONARY_GATE_SLOPE_VALUE 10.f
+#define AEC_ECHO_MODEL_NOISE_GATE_POWER "echo_model:noise_gate_power"
+#define AEC_ECHO_MODEL_NOISE_GATE_POWER_VALUE 27509.42f
+#define AEC_ECHO_MODEL_NOISE_GATE_SLOPE "echo_model:noise_gate_slope"
+#define AEC_ECHO_MODEL_NOISE_GATE_SLOPE_VALUE 0.3f
+#define AEC_ECHO_MODEL_RENDER_PRE_WINDOW_SIZE \
+	"echo_model:render_pre_window_size"
+#define AEC_ECHO_MODEL_RENDER_PRE_WINDOW_SIZE_VALUE 1
+#define AEC_ECHO_MODEL_RENDER_POST_WINDOW_SIZE \
+	"echo_model:render_post_window_size"
+#define AEC_ECHO_MODEL_RENDER_POST_WINDOW_SIZE_VALUE 1
+#define AEC_ECHO_MODEL_RENDER_PRE_WINDOW_SIZE_INIT \
+	"echo_model:render_pre_window_size_init"
+#define AEC_ECHO_MODEL_RENDER_PRE_WINDOW_SIZE_INIT_VALUE 10
+#define AEC_ECHO_MODEL_RENDER_POST_WINDOW_SIZE_INIT \
+	"echo_model:render_post_window_size_init"
+#define AEC_ECHO_MODEL_RENDER_POST_WINDOW_SIZE_INIT_VALUE 10
+#define AEC_ECHO_MODEL_NONLINEAR_HOLD "echo_model:nonlinear_hold"
+#define AEC_ECHO_MODEL_NONLINEAR_HOLD_VALUE 1
+#define AEC_ECHO_MODEL_NONLINEAR_RELEASE "echo_model:nonlinear_release"
+#define AEC_ECHO_MODEL_NONLINEAR_RELEASE_VALUE 0.001f
+
+#define AEC_SUPPRESSOR_NEAREND_AVERAGE_BLOCKS \
+	"suppressor:nearend_average_blocks"
+#define AEC_SUPPRESSOR_NEAREND_AVERAGE_BLOCKS_VALUE 4
+
+#define AEC_SUPPRESSOR_NORMAL_TUNING_MASK_LF_ENR_TRANSPARENT \
+	"suppressor.normal_tuning:mask_lf_enr_transparent"
+#define AEC_SUPPRESSOR_NORMAL_TUNING_MASK_LF_ENR_TRANSPARENT_VALUE .2f
+#define AEC_SUPPRESSOR_NORMAL_TUNING_MASK_LF_ENR_SUPPRESS \
+	"suppressor.normal_tuning:mask_lf_enr_suppress"
+#define AEC_SUPPRESSOR_NORMAL_TUNING_MASK_LF_ENR_SUPPRESS_VALUE .3f
+#define AEC_SUPPRESSOR_NORMAL_TUNING_MASK_LF_EMR_TRANSPARENT \
+	"suppressor.normal_tuning:mask_lf_emr_transparent"
+#define AEC_SUPPRESSOR_NORMAL_TUNING_MASK_LF_EMR_TRANSPARENT_VALUE .3f
+
+#define AEC_SUPPRESSOR_NORMAL_TUNING_MASK_HF_ENR_TRANSPARENT \
+	"suppressor.normal_tuning:mask_hf_enr_transparent"
+#define AEC_SUPPRESSOR_NORMAL_TUNING_MASK_HF_ENR_TRANSPARENT_VALUE .07f
+#define AEC_SUPPRESSOR_NORMAL_TUNING_MASK_HF_ENR_SUPPRESS \
+	"suppressor.normal_tuning:mask_hf_enr_suppress"
+#define AEC_SUPPRESSOR_NORMAL_TUNING_MASK_HF_ENR_SUPPRESS_VALUE .1f
+#define AEC_SUPPRESSOR_NORMAL_TUNING_MASK_HF_EMR_TRANSPARENT \
+	"suppressor.normal_tuning:mask_hf_emr_transparent"
+#define AEC_SUPPRESSOR_NORMAL_TUNING_MASK_HF_EMR_TRANSPARENT_VALUE .3f
+
+#define AEC_SUPPRESSOR_NORMAL_TUNING_MAX_INC_FACTOR \
+	"suppressor.normal_tuning:max_inc_factor"
+#define AEC_SUPPRESSOR_NORMAL_TUNING_MAX_INC_FACTOR_VALUE 2.0f
+#define AEC_SUPPRESSOR_NORMAL_TUNING_MAX_DEC_FACTOR_LF \
+	"suppressor.normal_tuning:max_dec_factor_lf"
+#define AEC_SUPPRESSOR_NORMAL_TUNING_MAX_DEC_FACTOR_LF_VALUE 0.25f
+
+#define AEC_SUPPRESSOR_NEAREND_TUNING_MASK_LF_ENR_TRANSPARENT \
+	"suppressor.nearend_tuning:mask_lf_enr_transparent"
+#define AEC_SUPPRESSOR_NEAREND_TUNING_MASK_LF_ENR_TRANSPARENT_VALUE .2f
+#define AEC_SUPPRESSOR_NEAREND_TUNING_MASK_LF_ENR_SUPPRESS \
+	"suppressor.nearend_tuning:mask_lf_enr_suppress"
+#define AEC_SUPPRESSOR_NEAREND_TUNING_MASK_LF_ENR_SUPPRESS_VALUE .3f
+#define AEC_SUPPRESSOR_NEAREND_TUNING_MASK_LF_EMR_TRANSPARENT \
+	"suppressor.nearend_tuning:mask_lf_emr_transparent"
+#define AEC_SUPPRESSOR_NEAREND_TUNING_MASK_LF_EMR_TRANSPARENT_VALUE .3f
+
+#define AEC_SUPPRESSOR_NEAREND_TUNING_MASK_HF_ENR_TRANSPARENT \
+	"suppressor.nearend_tuning:mask_hf_enr_transparent"
+#define AEC_SUPPRESSOR_NEAREND_TUNING_MASK_HF_ENR_TRANSPARENT_VALUE .07f
+#define AEC_SUPPRESSOR_NEAREND_TUNING_MASK_HF_ENR_SUPPRESS \
+	"suppressor.nearend_tuning:mask_hf_enr_suppress"
+#define AEC_SUPPRESSOR_NEAREND_TUNING_MASK_HF_ENR_SUPPRESS_VALUE .1f
+#define AEC_SUPPRESSOR_NEAREND_TUNING_MASK_HF_EMR_TRANSPARENT \
+	"suppressor.nearend_tuning:mask_hf_emr_transparent"
+#define AEC_SUPPRESSOR_NEAREND_TUNING_MASK_HF_EMR_TRANSPARENT_VALUE .3f
+
+#define AEC_SUPPRESSOR_NEAREND_TUNING_MAX_INC_FACTOR \
+	"suppressor.nearend_tuning:max_inc_factor"
+#define AEC_SUPPRESSOR_NEAREND_TUNING_MAX_INC_FACTOR_VALUE 2.0f
+#define AEC_SUPPRESSOR_NEAREND_TUNING_MAX_DEC_FACTOR_LF \
+	"suppressor.nearend_tuning:max_dec_factor_lf"
+#define AEC_SUPPRESSOR_NEAREND_TUNING_MAX_DEC_FACTOR_LF_VALUE 0.25f
+
+#define AEC_SUPPRESSOR_DOMINANT_NEAREND_DETECTION_ENR_THRESHOLD \
+	"suppressor.dominant_nearend_detection:enr_threshold"
+#define AEC_SUPPRESSOR_DOMINANT_NEAREND_DETECTION_ENR_THRESHOLD_VALUE 10.f
+#define AEC_SUPPRESSOR_DOMINANT_NEAREND_DETECTION_SNR_THRESHOLD \
+	"suppressor.dominant_nearend_detection:snr_threshold"
+#define AEC_SUPPRESSOR_DOMINANT_NEAREND_DETECTION_SNR_THRESHOLD_VALUE 10.f
+#define AEC_SUPPRESSOR_DOMINANT_NEAREND_DETECTION_HOLD_DURATION \
+	"suppressor.dominant_nearend_detection:hold_duration"
+#define AEC_SUPPRESSOR_DOMINANT_NEAREND_DETECTION_HOLD_DURATION_VALUE 25
+#define AEC_SUPPRESSOR_DOMINANT_NEAREND_DETECTION_TRIGGER_THRESHOLD \
+	"suppressor.dominant_nearend_detection:trigger_threshold"
+#define AEC_SUPPRESSOR_DOMINANT_NEAREND_DETECTION_TRIGGER_THRESHOLD_VALUE 15
+
+#define AEC_SUPPRESSOR_HIGH_BANDS_SUPPRESSION_ENR_THRESHOLD \
+	"suppressor.high_bands_suppression:enr_threshold"
+#define AEC_SUPPRESSOR_HIGH_BANDS_SUPPRESSION_ENR_THRESHOLD_VALUE 1.f
+#define AEC_SUPPRESSOR_HIGH_BANDS_SUPPRESSION_MAX_GAIN_DURING_ECHO \
+	"suppressor.high_bands_suppression:max_gain_during_echo"
+#define AEC_SUPPRESSOR_HIGH_BANDS_SUPPRESSION_MAX_GAIN_DURING_ECHO_VALUE 1.f
+
+#define AEC_SUPPRESSOR_FLOOR_FIRST_INCREASE "suppressor:floor_first_increase"
+#define AEC_SUPPRESSOR_FLOOR_FIRST_INCREASE_VALUE 0.00001f
+#define AEC_SUPPRESSOR_ENFORCE_TRANSPARENT "suppressor:enforce_transparent"
+#define AEC_SUPPRESSOR_ENFORCE_TRANSPARENT_VALUE 0
+#define AEC_SUPPRESSOR_ENFORCE_EMPTY_HIGHER_BANDS \
+	"suppressor:enforce_empty_higher_bands"
+#define AEC_SUPPRESSOR_ENFORCE_EMPTY_HIGHER_BANDS_VALUE 0
+
+/* Gets the aec config from given config directory. */
+struct aec_config *aec_config_get(const char *device_config_dir);
+
+/* Prints the config content to syslog. */
+void aec_config_dump(struct aec_config *config);
+
+#endif /* AEC_CONFIG_H_ */
diff --git a/cras/src/server/config/apm_config.c b/cras/src/server/config/apm_config.c
new file mode 100644
index 0000000..ae5df69
--- /dev/null
+++ b/cras/src/server/config/apm_config.c
@@ -0,0 +1,94 @@
+/* Copyright 2018 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 "apm_config.h"
+#include "iniparser_wrapper.h"
+
+static const unsigned int MAX_INI_NAME_LEN = 63;
+
+#define APM_CONFIG_NAME "apm.ini"
+
+#define APM_GET_INT(ini, key)	\
+	iniparser_getint(	\
+		ini, key,	\
+		key ## _VALUE)
+#define APM_GET_FLOAT(ini, key)	\
+	iniparser_getdouble(	\
+		ini, key,	\
+		key ## _VALUE)
+
+struct apm_config *apm_config_get(const char *device_config_dir)
+{
+	struct apm_config *config;
+	char ini_name[MAX_INI_NAME_LEN + 1];
+	dictionary *ini;
+
+	snprintf(ini_name, MAX_INI_NAME_LEN, "%s/%s",
+		 device_config_dir, APM_CONFIG_NAME);
+	ini_name[MAX_INI_NAME_LEN] = '\0';
+
+	ini = iniparser_load_wrapper(ini_name);
+	if (ini == NULL) {
+		syslog(LOG_DEBUG, "No ini file %s", ini_name);
+		return NULL;
+	}
+
+	config = (struct apm_config *)calloc(1, sizeof(*config));
+	config->residual_echo_detector_enabled =
+			APM_GET_INT(ini, APM_RESIDUAL_ECHO_DETECTOR_ENABLED);
+	config->high_pass_filter_enabled =
+			APM_GET_INT(ini, APM_HIGH_PASS_FILTER_ENABLED);
+	config->pre_amplifier_enabled =
+			APM_GET_INT(ini, APM_PRE_AMPLIFIER_ENABLED);
+	config->pre_amplifier_fixed_gain_factor =
+			APM_GET_FLOAT(ini, APM_PRE_AMPLIFIER_FIXED_GAIN_FACTOR);
+	config->gain_controller2_enabled =
+			APM_GET_INT(ini, APM_GAIN_CONTROLLER2_ENABLED);
+	config->gain_controller2_fixed_gain_db =
+			APM_GET_FLOAT(ini, APM_GAIN_CONTROLLER2_FIXED_GAIN_DB);
+	config->gain_controller2_adaptive_digital_mode =
+			APM_GET_INT(ini, APM_GAIN_CONTROLLER2_ADAPTIVE_DIGITAL_MODE);
+	config->gain_control_compression_gain_db =
+			APM_GET_INT(ini, APM_GAIN_CONTROL_COMPRESSION_GAIN_DB);
+	config->agc_mode = (enum gain_control_mode)
+			APM_GET_INT(ini, APM_GAIN_CONTROL_MODE);
+	config->gain_control_enabled =
+			APM_GET_INT(ini, APM_GAIN_CONTROL_ENABLED);
+	config->ns_level = (enum noise_suppression_level)
+			APM_GET_INT(ini, APM_NOISE_SUPPRESSION_LEVEL);
+	config->noise_suppression_enabled =
+			APM_GET_INT(ini, APM_NOISE_SUPPRESSION_ENABLED);
+
+	return config;
+}
+
+void apm_config_dump(struct apm_config *config)
+{
+	syslog(LOG_ERR, "---- apm config dump ----");
+	syslog(LOG_ERR, "residual_echo_detector_enabled %u",
+		config->residual_echo_detector_enabled);
+	syslog(LOG_ERR, "high_pass_filter_enabled %u",
+		config->high_pass_filter_enabled);
+	syslog(LOG_ERR, "pre_amplifier_enabled %u",
+		config->pre_amplifier_enabled);
+	syslog(LOG_ERR, "pre_amplifier_fixed_gain_factor %f",
+		config->pre_amplifier_fixed_gain_factor);
+	syslog(LOG_ERR, "gain_controller2_enabled %u",
+		config->gain_controller2_enabled);
+	syslog(LOG_ERR, "gain_controller2_fixed_gain_db %f",
+		config->gain_controller2_fixed_gain_db);
+	syslog(LOG_ERR, "gain_controller2_adaptive_digital_mode %d",
+		config->gain_controller2_adaptive_digital_mode);
+	syslog(LOG_ERR, "gain_control_compression_gain_db %u",
+		config->gain_control_compression_gain_db);
+	syslog(LOG_ERR, "gain_control_mode %u", config->agc_mode);
+	syslog(LOG_ERR, "gain_control_enabled %u",
+		config->gain_control_enabled);
+	syslog(LOG_ERR, "noise_suppression_level %u", config->ns_level);
+	syslog(LOG_ERR, "noise_suppression_enabled %u",
+		config->noise_suppression_enabled);
+}
diff --git a/cras/src/server/config/apm_config.h b/cras/src/server/config/apm_config.h
new file mode 100644
index 0000000..b0e39be
--- /dev/null
+++ b/cras/src/server/config/apm_config.h
@@ -0,0 +1,45 @@
+/* Copyright 2018 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 APM_CONFIG_H_
+#define APM_CONFIG_H_
+
+#include <webrtc-apm/webrtc_apm.h>
+#include <webrtc-apm/webrtc_apm.h>
+
+#define APM_RESIDUAL_ECHO_DETECTOR_ENABLED "apm:residual_echo_detector_enabled"
+#define APM_RESIDUAL_ECHO_DETECTOR_ENABLED_VALUE 1
+#define APM_HIGH_PASS_FILTER_ENABLED "apm:high_pass_filter_enabled"
+#define APM_HIGH_PASS_FILTER_ENABLED_VALUE 0
+#define APM_PRE_AMPLIFIER_ENABLED "apm:pre_amplifier_enabled"
+#define APM_PRE_AMPLIFIER_ENABLED_VALUE 0
+#define APM_PRE_AMPLIFIER_FIXED_GAIN_FACTOR "apm:pre_amplifier_fixed_gain_factor"
+#define APM_PRE_AMPLIFIER_FIXED_GAIN_FACTOR_VALUE 1.f
+#define APM_GAIN_CONTROLLER2_ENABLED "apm:gain_controller2_enabled"
+#define APM_GAIN_CONTROLLER2_ENABLED_VALUE 0
+#define APM_GAIN_CONTROLLER2_FIXED_GAIN_DB "apm:gain_controller2_fixed_gain_db"
+#define APM_GAIN_CONTROLLER2_FIXED_GAIN_DB_VALUE 0.f
+#define APM_GAIN_CONTROLLER2_ADAPTIVE_DIGITAL_MODE "apm:gain_controller2_adaptive_digital_mode"
+#define APM_GAIN_CONTROLLER2_ADAPTIVE_DIGITAL_MODE_VALUE 1
+#define APM_GAIN_CONTROL_COMPRESSION_GAIN_DB "apm:gain_control_compression_gain_db"
+#define APM_GAIN_CONTROL_COMPRESSION_GAIN_DB_VALUE 9
+/* 0: adaptive analog, 1: adaptive digital, 2: fixed digital */
+#define APM_GAIN_CONTROL_MODE "apm:gain_control_mode"
+#define APM_GAIN_CONTROL_MODE_VALUE 0
+#define APM_GAIN_CONTROL_ENABLED "apm:gain_control_enabled"
+#define APM_GAIN_CONTROL_ENABLED_VALUE 0
+/* 0: low, 1: moderate, 2: high, 3: very high*/
+#define APM_NOISE_SUPPRESSION_LEVEL "apm:noise_suppression_level"
+#define APM_NOISE_SUPPRESSION_LEVEL_VALUE 0
+#define APM_NOISE_SUPPRESSION_ENABLED "apm:noise_suppression_enabled"
+#define APM_NOISE_SUPPRESSION_ENABLED_VALUE 0
+
+/* Gets apm config from given config directory. */
+struct apm_config *apm_config_get(const char *device_config_dir);
+
+/* Prints config content to syslog. */
+void apm_config_dump(struct apm_config *config);
+
+#endif /* APM_CONFIG_H_ */
diff --git a/cras/src/server/config/cras_board_config.c b/cras/src/server/config/cras_board_config.c
index 9acdf82..a920b63 100644
--- a/cras/src/server/config/cras_board_config.c
+++ b/cras/src/server/config/cras_board_config.c
@@ -13,15 +13,14 @@
 static const unsigned int MAX_KEY_LEN = 63;
 static const int32_t DEFAULT_OUTPUT_BUFFER_SIZE = 512;
 static const int32_t AEC_SUPPORTED_DEFAULT = 0;
-static const int32_t AEC_GROUP_ID_DEFAULT = -1;
 
 #define CONFIG_NAME "board.ini"
 #define DEFAULT_OUTPUT_BUF_SIZE_INI_KEY "output:default_output_buffer_size"
 #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];
@@ -29,11 +28,11 @@
 
 	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;
 	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) {
@@ -51,11 +50,7 @@
 	board_config->aec_supported =
 		iniparser_getint(ini, ini_key, AEC_SUPPORTED_DEFAULT);
 
-	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);
-
 	iniparser_freedict(ini);
 	syslog(LOG_DEBUG, "Loaded ini file %s", ini_name);
 }
+
diff --git a/cras/src/server/config/cras_board_config.h b/cras/src/server/config/cras_board_config.h
index 92ef971..f06f92b 100644
--- a/cras/src/server/config/cras_board_config.h
+++ b/cras/src/server/config/cras_board_config.h
@@ -11,7 +11,6 @@
 struct cras_board_config {
 	int32_t default_output_buffer_size;
 	int32_t aec_supported;
-	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 f19d085..c6f5edd 100644
--- a/cras/src/server/config/cras_card_config.c
+++ b/cras/src/server/config/cras_card_config.c
@@ -18,9 +18,9 @@
 	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 @@
 	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,7 +91,8 @@
 }
 
 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 22ddc39..6ec9ad1 100644
--- a/cras/src/server/config/cras_card_config.h
+++ b/cras/src/server/config/cras_card_config.h
@@ -32,6 +32,7 @@
  *    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 1d18eb0..f3000a8 100644
--- a/cras/src/server/config/cras_device_blacklist.c
+++ b/cras/src/server/config/cras_device_blacklist.c
@@ -19,8 +19,8 @@
  * 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 @@
 	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,8 +45,10 @@
 }
 
 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 ac7cfe2..d43f540 100644
--- a/cras/src/server/config/cras_device_blacklist.h
+++ b/cras/src/server/config/cras_device_blacklist.h
@@ -23,8 +23,8 @@
  * 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,7 +42,9 @@
  *  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.c b/cras/src/server/cras.c
index 32953ef..cc213ab 100644
--- a/cras/src/server/cras.c
+++ b/cras/src/server/cras.c
@@ -18,12 +18,12 @@
 #include "cras_dsp.h"
 
 static struct option long_options[] = {
-	{ "dsp_config", required_argument, 0, 'd' },
-	{ "syslog_mask", required_argument, 0, 'l' },
-	{ "device_config_dir", required_argument, 0, 'c' },
-	{ "disable_profile", required_argument, 0, 'D' },
-	{ "internal_ucm_suffix", required_argument, 0, 'u' },
-	{ 0, 0, 0, 0 }
+	{"dsp_config", required_argument, 0, 'd'},
+	{"syslog_mask", required_argument, 0, 'l'},
+	{"device_config_dir", required_argument, 0, 'c'},
+	{"disable_profile", required_argument, 0, 'D'},
+	{"internal_ucm_suffix", required_argument, 0, 'u'},
+	{0, 0, 0, 0}
 };
 
 /* Ignores sigpipe, we'll notice when a read/write fails. */
@@ -73,16 +73,13 @@
 		case 'D':
 			while ((optarg != NULL) && (*optarg != 0)) {
 				if (strncmp(optarg, "hfp", 3) == 0) {
-					profile_disable_mask |=
-						CRAS_SERVER_PROFILE_MASK_HFP;
+					profile_disable_mask |= CRAS_SERVER_PROFILE_MASK_HFP;
 				}
 				if (strncmp(optarg, "hsp", 3) == 0) {
-					profile_disable_mask |=
-						CRAS_SERVER_PROFILE_MASK_HSP;
+					profile_disable_mask |= CRAS_SERVER_PROFILE_MASK_HSP;
 				}
 				if (strncmp(optarg, "a2dp", 4) == 0) {
-					profile_disable_mask |=
-						CRAS_SERVER_PROFILE_MASK_A2DP;
+					profile_disable_mask |= CRAS_SERVER_PROFILE_MASK_A2DP;
 				}
 				optarg = strchr(optarg, ',');
 				if (optarg != NULL) {
@@ -100,39 +97,40 @@
 	}
 
 	switch (log_mask) {
-	case LOG_EMERG:
-	case LOG_ALERT:
-	case LOG_CRIT:
-	case LOG_ERR:
-	case LOG_WARNING:
-	case LOG_NOTICE:
-	case LOG_INFO:
-	case LOG_DEBUG:
-		break;
-	default:
-		fprintf(stderr,
-			"Unsupported syslog priority value: %d; using LOG_ERR=%d\n",
-			log_mask, LOG_ERR);
-		log_mask = LOG_ERR;
-		break;
+		case LOG_EMERG: case LOG_ALERT: case LOG_CRIT: case LOG_ERR:
+		case LOG_WARNING: case LOG_NOTICE: case LOG_INFO:
+		case LOG_DEBUG:
+			break;
+		default:
+			fprintf(stderr,
+				"Unsupported syslog priority value: %d; using LOG_ERR=%d\n",
+				log_mask, LOG_ERR);
+			log_mask = LOG_ERR;
+			break;
 	}
 	setlogmask(LOG_UPTO(log_mask));
 
 	/* Initialize system. */
 	cras_server_init();
-	char *shm_name;
-	if (asprintf(&shm_name, "/cras-%d", getpid()) < 0)
+        char *shm_name;
+        if (asprintf(&shm_name, "/cras-%d", getpid()) < 0)
 		exit(-1);
 	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));
-	free(shm_name);
+	cras_system_state_init(device_config_dir,
+			       shm_name,
+			       rw_shm_fd,
+			       ro_shm_fd,
+			       exp_state,
+			       sizeof(*exp_state));
+        free(shm_name);
 	if (internal_ucm_suffix)
 		cras_system_state_set_internal_ucm_suffix(internal_ucm_suffix);
 	cras_dsp_init(dsp_config);
diff --git a/cras/src/server/cras_a2dp_endpoint.c b/cras/src/server/cras_a2dp_endpoint.c
index 4cda169..3afe8b9 100644
--- a/cras/src/server/cras_a2dp_endpoint.c
+++ b/cras/src/server/cras_a2dp_endpoint.c
@@ -13,12 +13,12 @@
 #include "cras_iodev.h"
 #include "cras_bt_constants.h"
 #include "cras_bt_endpoint.h"
-#include "cras_bt_log.h"
 #include "cras_system_state.h"
 #include "cras_util.h"
 
 #define A2DP_SOURCE_ENDPOINT_PATH "/org/chromium/Cras/Bluetooth/A2DPSource"
-#define A2DP_SINK_ENDPOINT_PATH "/org/chromium/Cras/Bluetooth/A2DPSink"
+#define A2DP_SINK_ENDPOINT_PATH   "/org/chromium/Cras/Bluetooth/A2DPSink"
+
 
 /* Pointers for the only connected a2dp device. */
 static struct a2dp {
@@ -37,17 +37,21 @@
 	*len = sizeof(*sbc_caps);
 
 	/* Return all capabilities. */
-	sbc_caps->channel_mode =
-		SBC_CHANNEL_MODE_MONO | SBC_CHANNEL_MODE_DUAL_CHANNEL |
-		SBC_CHANNEL_MODE_STEREO | SBC_CHANNEL_MODE_JOINT_STEREO;
+	sbc_caps->channel_mode = SBC_CHANNEL_MODE_MONO |
+			SBC_CHANNEL_MODE_DUAL_CHANNEL |
+			SBC_CHANNEL_MODE_STEREO |
+			SBC_CHANNEL_MODE_JOINT_STEREO;
 	sbc_caps->frequency = SBC_SAMPLING_FREQ_16000 |
-			      SBC_SAMPLING_FREQ_32000 |
-			      SBC_SAMPLING_FREQ_44100 | SBC_SAMPLING_FREQ_48000;
-	sbc_caps->allocation_method =
-		SBC_ALLOCATION_SNR | SBC_ALLOCATION_LOUDNESS;
+			SBC_SAMPLING_FREQ_32000 |
+			SBC_SAMPLING_FREQ_44100 |
+			SBC_SAMPLING_FREQ_48000;
+	sbc_caps->allocation_method = SBC_ALLOCATION_SNR |
+			SBC_ALLOCATION_LOUDNESS;
 	sbc_caps->subbands = SBC_SUBBANDS_4 | SBC_SUBBANDS_8;
-	sbc_caps->block_length = SBC_BLOCK_LENGTH_4 | SBC_BLOCK_LENGTH_8 |
-				 SBC_BLOCK_LENGTH_12 | SBC_BLOCK_LENGTH_16;
+	sbc_caps->block_length = SBC_BLOCK_LENGTH_4 |
+			SBC_BLOCK_LENGTH_8 |
+			SBC_BLOCK_LENGTH_12 |
+			SBC_BLOCK_LENGTH_16;
 	sbc_caps->min_bitpool = MIN_BITPOOL;
 	sbc_caps->max_bitpool = MAX_BITPOOL;
 
@@ -119,18 +123,16 @@
 		return -ENOSYS;
 	}
 
-	sbc_config->min_bitpool =
-		(sbc_caps->min_bitpool > MIN_BITPOOL ? sbc_caps->min_bitpool :
-						       MIN_BITPOOL);
-	sbc_config->max_bitpool =
-		(sbc_caps->max_bitpool < MAX_BITPOOL ? sbc_caps->max_bitpool :
-						       MAX_BITPOOL);
+	sbc_config->min_bitpool = (sbc_caps->min_bitpool > MIN_BITPOOL
+				   ? sbc_caps->min_bitpool : MIN_BITPOOL);
+	sbc_config->max_bitpool = (sbc_caps->max_bitpool < MAX_BITPOOL
+				   ? sbc_caps->max_bitpool : MAX_BITPOOL);
 
 	return 0;
 }
 
 static void cras_a2dp_set_configuration(struct cras_bt_endpoint *endpoint,
-					struct cras_bt_transport *transport)
+			    struct cras_bt_transport *transport)
 {
 	struct cras_bt_device *device;
 
@@ -142,11 +144,7 @@
 			      struct cras_bt_transport *transport)
 {
 	struct cras_bt_device *device = cras_bt_transport_device(transport);
-
-	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,
@@ -157,7 +155,7 @@
 		 * the transport. */
 		if (cras_bt_transport_fd(transport) != -1 &&
 		    cras_bt_transport_state(transport) ==
-			    CRAS_BT_TRANSPORT_STATE_PENDING)
+				CRAS_BT_TRANSPORT_STATE_PENDING)
 			cras_bt_transport_try_acquire(transport);
 	}
 }
@@ -187,8 +185,6 @@
 {
 	struct cras_bt_transport *transport = cras_a2dp_endpoint.transport;
 
-	BTLOG(btlog, BT_A2DP_START, 0, 0);
-
 	if (!transport || device != cras_bt_transport_device(transport)) {
 		syslog(LOG_ERR, "Device and active transport not match.");
 		return;
diff --git a/cras/src/server/cras_a2dp_info.c b/cras/src/server/cras_a2dp_info.c
index ffddb25..80a498c 100644
--- a/cras/src/server/cras_a2dp_info.c
+++ b/cras/src/server/cras_a2dp_info.c
@@ -75,8 +75,8 @@
 	a2dp->codesize = cras_sbc_get_codesize(a2dp->codec);
 	a2dp->frame_length = cras_sbc_get_frame_length(a2dp->codec);
 
-	a2dp->a2dp_buf_used =
-		sizeof(struct rtp_header) + sizeof(struct rtp_payload);
+	a2dp->a2dp_buf_used = sizeof(struct rtp_header)
+			+ sizeof(struct rtp_payload);
 	a2dp->frame_count = 0;
 	a2dp->seq_num = 0;
 	a2dp->samples = 0;
@@ -106,8 +106,8 @@
 
 void a2dp_drain(struct a2dp_info *a2dp)
 {
-	a2dp->a2dp_buf_used =
-		sizeof(struct rtp_header) + sizeof(struct rtp_payload);
+	a2dp->a2dp_buf_used = sizeof(struct rtp_header)
+			+ sizeof(struct rtp_payload);
 	a2dp->samples = 0;
 	a2dp->seq_num = 0;
 	a2dp->frame_count = 0;
diff --git a/cras/src/server/cras_a2dp_iodev.c b/cras/src/server/cras_a2dp_iodev.c
index f6351ab..ec8c345 100644
--- a/cras/src/server/cras_a2dp_iodev.c
+++ b/cras/src/server/cras_a2dp_iodev.c
@@ -27,14 +27,9 @@
 #include "rtp.h"
 #include "utlist.h"
 
-#define PCM_BUF_MAX_SIZE_FRAMES (4096 * 4)
+#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"
@@ -43,14 +38,11 @@
  *    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.
  *    dev_open_time - The last time a2dp_ios is opened.
- *    drain_complete - Flag to indicate if valid frames have all been drained
- *        in no stream state.
- *    filled_zeros_bytes - Number of zero data in bytes that have been filled
- *        in no stream state.
  */
 struct a2dp_io {
 	struct cras_iodev base;
@@ -59,10 +51,9 @@
 	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;
-	int filled_zeros_bytes;
 };
 
 static int flush_data(void *arg);
@@ -74,7 +65,8 @@
 	size_t channel;
 	a2dp_sbc_t a2dp;
 
-	cras_bt_transport_configuration(a2dpio->transport, &a2dp, sizeof(a2dp));
+	cras_bt_transport_configuration(a2dpio->transport, &a2dp,
+					sizeof(a2dp));
 
 	iodev->format->format = SND_PCM_FORMAT_S16_LE;
 	channel = (a2dp.channel_mode == SBC_CHANNEL_MODE_MONO) ? 1 : 2;
@@ -129,70 +121,26 @@
 		return 0;
 }
 
+
 static int frames_queued(const struct cras_iodev *iodev,
 			 struct timespec *tstamp)
 {
 	struct a2dp_io *a2dpio = (struct a2dp_io *)iodev;
 	int estimate_queued_frames = bt_queued_frames(iodev, 0);
-	int local_queued_frames = a2dp_queued_frames(&a2dpio->a2dp) +
-				  buf_queued(a2dpio->pcm_buf) /
-					  cras_get_format_bytes(iodev->format);
+	int local_queued_frames =
+			a2dp_queued_frames(&a2dpio->a2dp) +
+			buf_queued(a2dpio->pcm_buf) /
+				cras_get_format_bytes(iodev->format);
 	clock_gettime(CLOCK_MONOTONIC_RAW, tstamp);
 	return MIN(iodev->buffer_size,
 		   MAX(estimate_queued_frames, local_queued_frames));
 }
 
-static int no_stream(struct cras_iodev *iodev, int enable)
-{
-	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);
-
-	if (enable) {
-		/* 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 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 || target_total_bytes == 0)
-				break;
-			target_bytes = MIN(buf_avail, target_total_bytes);
-			memset(buf, 0, target_bytes);
-			buf_increment_write(a2dpio->pcm_buf, target_bytes);
-			bt_queued_frames(iodev, target_bytes / format_bytes);
-			target_total_bytes -= target_bytes;
-		}
-		flush_data(iodev);
-		return 0;
-	}
-	return 0;
-}
-
 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) {
@@ -221,19 +169,16 @@
 	 * EAGAIN.  This will allow the write to be throttled when a reasonable
 	 * amount of data is queued. */
 	sock_depth = 2 * cras_bt_transport_write_mtu(a2dpio->transport);
-	setsockopt(cras_bt_transport_fd(a2dpio->transport), SOL_SOCKET,
-		   SO_SNDBUF, &sock_depth, sizeof(sock_depth));
+	setsockopt(cras_bt_transport_fd(a2dpio->transport),
+		   SOL_SOCKET, SO_SNDBUF, &sock_depth, sizeof(sock_depth));
 
-	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);
-
+	a2dpio->sock_depth_frames =
+		a2dp_block_size(&a2dpio->a2dp,
+				cras_bt_transport_write_mtu(a2dpio->transport))
+			/ cras_get_format_bytes(iodev->format) * 2;
 	iodev->min_buffer_level = a2dpio->sock_depth_frames;
 
-	a2dpio->drain_complete = 0;
-	a2dpio->filled_zeros_bytes = 0;
+	a2dpio->pre_fill_complete = 0;
 
 	/* Initialize variables for bt_queued_frames() */
 	a2dpio->bt_written_frames = 0;
@@ -257,10 +202,12 @@
 
 	/* Remove audio thread callback and sync before releasing
 	 * the transport. */
-	audio_thread_rm_callback_sync(cras_iodev_list_get_audio_thread(),
-				      cras_bt_transport_fd(a2dpio->transport));
+	audio_thread_rm_callback_sync(
+			cras_iodev_list_get_audio_thread(),
+			cras_bt_transport_fd(a2dpio->transport));
 
-	err = cras_bt_transport_release(a2dpio->transport, !a2dpio->destroyed);
+	err = cras_bt_transport_release(a2dpio->transport,
+					!a2dpio->destroyed);
 	if (err < 0)
 		syslog(LOG_ERR, "transport_release failed");
 
@@ -274,6 +221,41 @@
 	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.
@@ -300,12 +282,16 @@
 encode_more:
 	while (buf_queued(a2dpio->pcm_buf)) {
 		processed = a2dp_encode(
-			&a2dpio->a2dp, buf_read_pointer(a2dpio->pcm_buf),
-			buf_readable(a2dpio->pcm_buf), format_bytes,
-			cras_bt_transport_write_mtu(a2dpio->transport));
-		ATLOG(atlog, AUDIO_THREAD_A2DP_ENCODE, processed,
-		      buf_queued(a2dpio->pcm_buf),
-		      buf_readable(a2dpio->pcm_buf));
+				&a2dpio->a2dp,
+				buf_read_pointer(a2dpio->pcm_buf),
+				buf_readable(a2dpio->pcm_buf),
+				format_bytes,
+				cras_bt_transport_write_mtu(a2dpio->transport));
+		ATLOG(atlog, AUDIO_THREAD_A2DP_ENCODE,
+					    processed,
+					    buf_queued(a2dpio->pcm_buf),
+					    buf_readable(a2dpio->pcm_buf)
+					    );
 		if (processed == -ENOSPC || processed == 0)
 			break;
 		if (processed < 0)
@@ -317,14 +303,15 @@
 	written = a2dp_write(&a2dpio->a2dp,
 			     cras_bt_transport_fd(a2dpio->transport),
 			     cras_bt_transport_write_mtu(a2dpio->transport));
-	ATLOG(atlog, AUDIO_THREAD_A2DP_WRITE, written,
-	      a2dp_queued_frames(&a2dpio->a2dp), 0);
+	ATLOG(atlog, AUDIO_THREAD_A2DP_WRITE,
+				    written,
+				    a2dp_queued_frames(&a2dpio->a2dp), 0);
 	if (written == -EAGAIN) {
 		/* If EAGAIN error lasts longer than 5 seconds, suspend the
 		 * a2dp connection. */
 		cras_bt_device_schedule_suspend(device, 5000);
 		audio_thread_enable_callback(
-			cras_bt_transport_fd(a2dpio->transport), 1);
+				cras_bt_transport_fd(a2dpio->transport), 1);
 		return 0;
 	} else if (written < 0) {
 		/* Suspend a2dp immediately when receives error other than
@@ -347,8 +334,8 @@
 		goto encode_more;
 
 	/* everything written. */
-	audio_thread_enable_callback(cras_bt_transport_fd(a2dpio->transport),
-				     0);
+	audio_thread_enable_callback(
+			cras_bt_transport_fd(a2dpio->transport), 0);
 
 	return 0;
 }
@@ -362,7 +349,8 @@
 	return frames_queued(iodev, &tstamp) + a2dpio->sock_depth_frames;
 }
 
-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)
 {
 	size_t format_bytes;
@@ -375,10 +363,12 @@
 	if (iodev->direction != CRAS_STREAM_OUTPUT)
 		return 0;
 
-	*frames = MIN(*frames, buf_writable(a2dpio->pcm_buf) / format_bytes);
+	*frames = MIN(*frames, buf_writable(a2dpio->pcm_buf) /
+					format_bytes);
 	iodev->area->frames = *frames;
-	cras_audio_area_config_buf_pointers(iodev->area, iodev->format,
-					    buf_write_pointer(a2dpio->pcm_buf));
+	cras_audio_area_config_buf_pointers(
+			iodev->area, iodev->format,
+			buf_write_pointer(a2dpio->pcm_buf));
 	*area = iodev->area;
 	return 0;
 }
@@ -397,12 +387,17 @@
 
 	buf_increment_write(a2dpio->pcm_buf, written_bytes);
 
-	/* 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);
 
+	/* 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. */
+		clock_gettime(CLOCK_MONOTONIC_RAW, &a2dpio->dev_open_time);
+	}
+
 	return flush_data(iodev);
 }
 
@@ -416,7 +411,7 @@
 	size_t volume;
 	struct a2dp_io *a2dpio = (struct a2dp_io *)iodev;
 	struct cras_bt_device *device =
-		cras_bt_transport_device(a2dpio->transport);
+			cras_bt_transport_device(a2dpio->transport);
 
 	if (!cras_bt_device_get_use_hardware_volume(device))
 		return;
@@ -462,7 +457,8 @@
 		goto error;
 
 	a2dpio->transport = transport;
-	cras_bt_transport_configuration(a2dpio->transport, &a2dp, sizeof(a2dp));
+	cras_bt_transport_configuration(a2dpio->transport, &a2dp,
+					sizeof(a2dp));
 	err = init_a2dp(&a2dpio->a2dp, &a2dp);
 	if (err) {
 		syslog(LOG_ERR, "Fail to init a2dp");
@@ -484,10 +480,11 @@
 
 	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 = 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;
@@ -495,7 +492,6 @@
 	iodev->get_buffer = get_buffer;
 	iodev->put_buffer = put_buffer;
 	iodev->flush_buffer = flush_buffer;
-	iodev->no_stream = no_stream;
 	iodev->close_dev = close_dev;
 	iodev->update_supported_formats = update_supported_formats;
 	iodev->update_active_node = update_active_node;
@@ -511,8 +507,8 @@
 	gettimeofday(&node->plugged_time, NULL);
 
 	/* A2DP does output only */
-	cras_bt_device_append_iodev(
-		device, iodev, cras_bt_transport_profile(a2dpio->transport));
+	cras_bt_device_append_iodev(device, iodev,
+			cras_bt_transport_profile(a2dpio->transport));
 	cras_iodev_add_node(iodev, node);
 	cras_iodev_set_active_node(iodev, node);
 
diff --git a/cras/src/server/cras_a2dp_iodev.h b/cras/src/server/cras_a2dp_iodev.h
index d4e489d..e33af6c 100644
--- a/cras/src/server/cras_a2dp_iodev.h
+++ b/cras/src/server/cras_a2dp_iodev.h
@@ -15,7 +15,8 @@
  * Args:
  *    transport - The transport to create a2dp iodev for
  */
-struct cras_iodev *a2dp_iodev_create(struct cras_bt_transport *transport);
+struct cras_iodev *a2dp_iodev_create(
+		struct cras_bt_transport *transport);
 
 /*
  * Destroys a2dp iodev.
diff --git a/cras/src/server/cras_alert.c b/cras/src/server/cras_alert.c
index 9950ec1..6c97592 100644
--- a/cras/src/server/cras_alert.c
+++ b/cras/src/server/cras_alert.c
@@ -60,7 +60,7 @@
 	if (cb == NULL)
 		return -EINVAL;
 
-	DL_FOREACH (alert->callbacks, alert_cb)
+	DL_FOREACH(alert->callbacks, alert_cb)
 		if (alert_cb->callback == cb && alert_cb->arg == arg)
 			return -EEXIST;
 
@@ -78,7 +78,7 @@
 {
 	struct cras_alert_cb_list *alert_cb;
 
-	DL_FOREACH (alert->callbacks, alert_cb)
+	DL_FOREACH(alert->callbacks, alert_cb)
 		if (alert_cb->callback == cb && alert_cb->arg == arg) {
 			DL_DELETE(alert->callbacks, alert_cb);
 			free(alert_cb);
@@ -102,13 +102,13 @@
 		alert->prepare(alert);
 
 	if (!alert->data) {
-		DL_FOREACH (alert->callbacks, cb)
+		DL_FOREACH(alert->callbacks, cb)
 			cb->callback(cb->arg, NULL);
 	}
 
 	/* Have data arguments, pass each to the callbacks. */
-	DL_FOREACH (alert->data, data) {
-		DL_FOREACH (alert->callbacks, cb)
+	DL_FOREACH(alert->data, data) {
+		DL_FOREACH(alert->callbacks, cb)
 			cb->callback(cb->arg, (void *)data->buf);
 		DL_DELETE(alert->data, data);
 		free(data);
@@ -121,8 +121,8 @@
 	has_alert_pending = 1;
 }
 
-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)
 {
 	struct cras_alert_data *d;
 
@@ -148,7 +148,7 @@
 
 	while (has_alert_pending) {
 		has_alert_pending = 0;
-		DL_FOREACH (all_alerts, alert)
+		DL_FOREACH(all_alerts, alert)
 			cras_alert_process(alert);
 	}
 }
@@ -161,12 +161,12 @@
 	if (!alert)
 		return;
 
-	DL_FOREACH (alert->callbacks, cb) {
+	DL_FOREACH(alert->callbacks, cb) {
 		DL_DELETE(alert->callbacks, cb);
 		free(cb);
 	}
 
-	DL_FOREACH (alert->data, data) {
+	DL_FOREACH(alert->data, data) {
 		DL_DELETE(alert->data, data);
 		free(data);
 	}
@@ -179,6 +179,6 @@
 void cras_alert_destroy_all()
 {
 	struct cras_alert *alert;
-	DL_FOREACH (all_alerts, alert)
+	DL_FOREACH(all_alerts, alert)
 		cras_alert_destroy(alert);
 }
diff --git a/cras/src/server/cras_alert.h b/cras/src/server/cras_alert.h
index 7149a0b..3fee90b 100644
--- a/cras/src/server/cras_alert.h
+++ b/cras/src/server/cras_alert.h
@@ -102,8 +102,8 @@
  *    data - A pointer to data that is copied and passed to the callback.
  *    data_size - Size of the data.
  */
-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);
 
 /* Processes all alerts that are pending.
  *
diff --git a/cras/src/server/cras_alsa_card.c b/cras/src/server/cras_alsa_card.c
index 709cc1d..7f7a620 100644
--- a/cras/src/server/cras_alsa_card.c
+++ b/cras/src/server/cras_alsa_card.c
@@ -77,9 +77,13 @@
  *    other negative error code otherwise.
  */
 struct cras_iodev *create_iodev_for_device(
-	struct cras_alsa_card *alsa_card, struct cras_alsa_card_info *info,
-	const char *card_name, const char *dev_name, const char *dev_id,
-	unsigned device_index, enum CRAS_STREAM_DIRECTION direction)
+		struct cras_alsa_card *alsa_card,
+		struct cras_alsa_card_info *info,
+		const char *card_name,
+		const char *dev_name,
+		const char *dev_id,
+		unsigned device_index,
+		enum CRAS_STREAM_DIRECTION direction)
 {
 	struct iodev_list_node *new_dev;
 	struct iodev_list_node *node;
@@ -87,7 +91,7 @@
 
 	/* Find whether this is the first device in this direction, and
 	 * avoid duplicate device indexes. */
-	DL_FOREACH (alsa_card->iodevs, node) {
+	DL_FOREACH(alsa_card->iodevs, node) {
 		if (node->direction != direction)
 			continue;
 		first = 0;
@@ -104,11 +108,21 @@
 		return NULL;
 
 	new_dev->direction = direction;
-	new_dev->iodev = alsa_iodev_create(
-		info->card_index, card_name, device_index, dev_name, dev_id,
-		info->card_type, first, alsa_card->mixer, alsa_card->config,
-		alsa_card->ucm, alsa_card->hctl, direction, info->usb_vendor_id,
-		info->usb_product_id, info->usb_serial_number);
+	new_dev->iodev = alsa_iodev_create(info->card_index,
+					   card_name,
+					   device_index,
+					   dev_name,
+					   dev_id,
+					   info->card_type,
+					   first,
+					   alsa_card->mixer,
+					   alsa_card->config,
+					   alsa_card->ucm,
+					   alsa_card->hctl,
+					   direction,
+					   info->usb_vendor_id,
+					   info->usb_product_id,
+					   info->usb_serial_number);
 	if (new_dev->iodev == NULL) {
 		syslog(LOG_ERR, "Couldn't create alsa_iodev for %u:%u\n",
 		       info->card_index, device_index);
@@ -118,7 +132,8 @@
 
 	syslog(LOG_DEBUG, "New %s device %u:%d",
 	       direction == CRAS_STREAM_OUTPUT ? "playback" : "capture",
-	       info->card_index, device_index);
+	       info->card_index,
+	       device_index);
 
 	DL_APPEND(alsa_card->iodevs, new_dev);
 	return new_dev->iodev;
@@ -131,7 +146,7 @@
 	struct iodev_list_node *node;
 
 	/* Find the first device that has an hctl jack. */
-	DL_FOREACH (alsa_card->iodevs, node) {
+	DL_FOREACH(alsa_card->iodevs, node) {
 		if (alsa_iodev_has_hctl_jacks(node->iodev))
 			return 1;
 	}
@@ -146,9 +161,11 @@
 			     size_t device_index)
 {
 	if (info->card_type == ALSA_CARD_TYPE_USB)
-		return cras_device_blacklist_check(
-			blacklist, info->usb_vendor_id, info->usb_product_id,
-			info->usb_desc_checksum, device_index);
+		return cras_device_blacklist_check(blacklist,
+						   info->usb_vendor_id,
+						   info->usb_product_id,
+						   info->usb_desc_checksum,
+						   device_index);
 	return 0;
 }
 
@@ -158,7 +175,7 @@
 					  struct mixer_name *controls)
 {
 	struct mixer_name *control;
-	DL_FOREACH (controls, control) {
+	DL_FOREACH(controls, control) {
 		char *dev = ucm_get_dev_for_mixer(ucm, control->name,
 						  CRAS_STREAM_OUTPUT);
 		if (!dev)
@@ -186,11 +203,12 @@
 	snd_hctl_handle_events(card->hctl);
 }
 
-static int
-add_controls_and_iodevs_by_matching(struct cras_alsa_card_info *info,
-				    struct cras_device_blacklist *blacklist,
-				    struct cras_alsa_card *alsa_card,
-				    const char *card_name, snd_ctl_t *handle)
+static int add_controls_and_iodevs_by_matching(
+		struct cras_alsa_card_info *info,
+		struct cras_device_blacklist *blacklist,
+		struct cras_alsa_card *alsa_card,
+		const char *card_name,
+		snd_ctl_t *handle)
 {
 	struct mixer_name *coupled_controls = NULL;
 	int dev_idx;
@@ -204,32 +222,36 @@
 		char *extra_main_volume;
 
 		/* Filter the extra output mixer names */
-		extra_controls = filter_controls(
-			alsa_card->ucm,
-			mixer_name_add(extra_controls, "IEC958",
-				       CRAS_STREAM_OUTPUT, MIXER_NAME_VOLUME));
+		extra_controls =
+			filter_controls(alsa_card->ucm,
+				mixer_name_add(extra_controls, "IEC958",
+					       CRAS_STREAM_OUTPUT,
+					       MIXER_NAME_VOLUME));
 
 		/* Get the extra main volume control. */
-		extra_main_volume =
-			ucm_get_flag(alsa_card->ucm, "ExtraMainVolume");
+		extra_main_volume = ucm_get_flag(alsa_card->ucm,
+						 "ExtraMainVolume");
 		if (extra_main_volume) {
-			extra_controls = mixer_name_add(extra_controls,
-							extra_main_volume,
-							CRAS_STREAM_OUTPUT,
-							MIXER_NAME_MAIN_VOLUME);
+			extra_controls =
+				mixer_name_add(extra_controls,
+					       extra_main_volume,
+					       CRAS_STREAM_OUTPUT,
+					       MIXER_NAME_MAIN_VOLUME);
 			free(extra_main_volume);
 		}
 		mixer_name_dump(extra_controls, "extra controls");
 
 		/* Check if coupled controls has been specified for speaker. */
-		coupled_controls =
-			ucm_get_coupled_mixer_names(alsa_card->ucm, "Speaker");
+		coupled_controls = ucm_get_coupled_mixer_names(
+					alsa_card->ucm, "Speaker");
 		mixer_name_dump(coupled_controls, "coupled controls");
 	}
 
 	/* Add controls to mixer by name matching. */
 	rc = cras_alsa_mixer_add_controls_by_name_matching(
-		alsa_card->mixer, extra_controls, coupled_controls);
+			alsa_card->mixer,
+			extra_controls,
+			coupled_controls);
 	if (rc) {
 		syslog(LOG_ERR, "Fail adding controls to mixer for %s.",
 		       alsa_card->name);
@@ -249,31 +271,43 @@
 		snd_pcm_info_set_subdevice(dev_info, 0);
 
 		/* Check for playback devices. */
-		snd_pcm_info_set_stream(dev_info, SND_PCM_STREAM_PLAYBACK);
+		snd_pcm_info_set_stream(
+			dev_info, SND_PCM_STREAM_PLAYBACK);
 		if (snd_ctl_pcm_info(handle, dev_info) == 0 &&
 		    !should_ignore_dev(info, blacklist, dev_idx)) {
-			struct cras_iodev *iodev = create_iodev_for_device(
-				alsa_card, info, card_name,
-				snd_pcm_info_get_name(dev_info),
-				snd_pcm_info_get_id(dev_info), dev_idx,
-				CRAS_STREAM_OUTPUT);
+			struct cras_iodev *iodev =
+				create_iodev_for_device(
+					alsa_card,
+					info,
+					card_name,
+					snd_pcm_info_get_name(dev_info),
+					snd_pcm_info_get_id(dev_info),
+					dev_idx,
+					CRAS_STREAM_OUTPUT);
 			if (iodev) {
-				rc = alsa_iodev_legacy_complete_init(iodev);
+				rc = alsa_iodev_legacy_complete_init(
+					iodev);
 				if (rc < 0)
 					goto error;
 			}
 		}
 
 		/* Check for capture devices. */
-		snd_pcm_info_set_stream(dev_info, SND_PCM_STREAM_CAPTURE);
+		snd_pcm_info_set_stream(
+			dev_info, SND_PCM_STREAM_CAPTURE);
 		if (snd_ctl_pcm_info(handle, dev_info) == 0) {
-			struct cras_iodev *iodev = create_iodev_for_device(
-				alsa_card, info, card_name,
-				snd_pcm_info_get_name(dev_info),
-				snd_pcm_info_get_id(dev_info), dev_idx,
-				CRAS_STREAM_INPUT);
+			struct cras_iodev *iodev =
+				create_iodev_for_device(
+					alsa_card,
+					info,
+					card_name,
+					snd_pcm_info_get_name(dev_info),
+					snd_pcm_info_get_id(dev_info),
+					dev_idx,
+					CRAS_STREAM_INPUT);
 			if (iodev) {
-				rc = alsa_iodev_legacy_complete_init(iodev);
+				rc = alsa_iodev_legacy_complete_init(
+					iodev);
 				if (rc < 0)
 					goto error;
 			}
@@ -285,13 +319,13 @@
 	return rc;
 }
 
-static int add_controls_and_iodevs_with_ucm(struct cras_alsa_card_info *info,
-					    struct cras_alsa_card *alsa_card,
-					    const char *card_name,
-					    snd_ctl_t *handle)
+static int add_controls_and_iodevs_with_ucm(
+		struct cras_alsa_card_info *info,
+		struct cras_alsa_card *alsa_card,
+		const char *card_name,
+		snd_ctl_t *handle)
 {
 	snd_pcm_info_t *dev_info;
-	struct mixer_name *main_volume_control_names;
 	struct iodev_list_node *node;
 	int rc = 0;
 	struct ucm_section *section;
@@ -299,95 +333,82 @@
 
 	snd_pcm_info_alloca(&dev_info);
 
-	main_volume_control_names = ucm_get_main_volume_names(alsa_card->ucm);
-	if (main_volume_control_names) {
-		rc = cras_alsa_mixer_add_main_volume_control_by_name(
-			alsa_card->mixer, main_volume_control_names);
-		if (rc) {
-			syslog(LOG_ERR,
-			       "Failed adding main volume controls to"
-			       " mixer for '%s'.'",
-			       card_name);
-			goto cleanup_names;
-		}
-	}
-
 	/* Get info on the devices specified in the UCM config. */
 	ucm_sections = ucm_get_sections(alsa_card->ucm);
 	if (!ucm_sections) {
 		syslog(LOG_ERR,
 		       "Could not retrieve any UCM SectionDevice"
-		       " info for '%s'.",
-		       card_name);
+		       " info for '%s'.", card_name);
 		rc = -ENOENT;
-		goto cleanup_names;
+		goto error;
 	}
 
 	/* Create all of the controls first. */
-	DL_FOREACH (ucm_sections, section) {
-		rc = cras_alsa_mixer_add_controls_in_section(alsa_card->mixer,
-							     section);
+	DL_FOREACH(ucm_sections, section) {
+		rc = cras_alsa_mixer_add_controls_in_section(
+				alsa_card->mixer, section);
 		if (rc) {
-			syslog(LOG_ERR,
-			       "Failed adding controls to"
-			       " mixer for '%s:%s'",
-			       card_name, section->name);
-			goto cleanup;
+			syslog(LOG_ERR, "Failed adding controls to"
+					" mixer for '%s:%s'",
+					card_name,
+					section->name);
+			goto error;
 		}
 	}
 
 	/* Create all of the devices. */
-	DL_FOREACH (ucm_sections, section) {
+	DL_FOREACH(ucm_sections, section) {
 		snd_pcm_info_set_device(dev_info, section->dev_idx);
 		snd_pcm_info_set_subdevice(dev_info, 0);
 		if (section->dir == CRAS_STREAM_OUTPUT)
-			snd_pcm_info_set_stream(dev_info,
-						SND_PCM_STREAM_PLAYBACK);
+			snd_pcm_info_set_stream(
+				dev_info, SND_PCM_STREAM_PLAYBACK);
 		else if (section->dir == CRAS_STREAM_INPUT)
-			snd_pcm_info_set_stream(dev_info,
-						SND_PCM_STREAM_CAPTURE);
+			snd_pcm_info_set_stream(
+				dev_info, SND_PCM_STREAM_CAPTURE);
 		else {
 			syslog(LOG_ERR, "Unexpected direction: %d",
 			       section->dir);
 			rc = -EINVAL;
-			goto cleanup;
+			goto error;
 		}
 
 		if (snd_ctl_pcm_info(handle, dev_info)) {
-			syslog(LOG_ERR, "Could not get info for device: %s",
+			syslog(LOG_ERR,
+			       "Could not get info for device: %s",
 			       section->name);
 			continue;
 		}
 
-		create_iodev_for_device(alsa_card, info, card_name,
-					snd_pcm_info_get_name(dev_info),
-					snd_pcm_info_get_id(dev_info),
-					section->dev_idx, section->dir);
+		create_iodev_for_device(
+			alsa_card, info, card_name,
+			snd_pcm_info_get_name(dev_info),
+			snd_pcm_info_get_id(dev_info),
+			section->dev_idx, section->dir);
 	}
 
 	/* Setup jacks and controls for the devices. */
-	DL_FOREACH (ucm_sections, section) {
-		DL_FOREACH (alsa_card->iodevs, node) {
+	DL_FOREACH(ucm_sections, section) {
+		DL_FOREACH(alsa_card->iodevs, node) {
 			if (node->direction == section->dir &&
-			    alsa_iodev_index(node->iodev) == section->dev_idx)
+			    alsa_iodev_index(node->iodev) ==
+			    section->dev_idx)
 				break;
 		}
 		if (node) {
-			rc = alsa_iodev_ucm_add_nodes_and_jacks(node->iodev,
-								section);
+			rc = alsa_iodev_ucm_add_nodes_and_jacks(
+				node->iodev, section);
 			if (rc < 0)
-				goto cleanup;
+				goto error;
 		}
 	}
 
-	DL_FOREACH (alsa_card->iodevs, node) {
+	DL_FOREACH(alsa_card->iodevs, node) {
 		alsa_iodev_ucm_complete_init(node->iodev);
 	}
 
-cleanup:
+error:
 	ucm_section_free_list(ucm_sections);
-cleanup_names:
-	mixer_name_free(main_volume_control_names);
 	return rc;
 }
 
@@ -399,15 +420,16 @@
 	if (!alsa_card->ucm)
 		return;
 
-	DL_FOREACH (alsa_card->iodevs, dev_node) {
+	DL_FOREACH(alsa_card->iodevs, dev_node) {
 		if (!dev_node->iodev->nodes)
 			continue;
 
 		echo_ref_name = ucm_get_echo_reference_dev_name_for_dev(
-			alsa_card->ucm, dev_node->iodev->nodes->name);
+				alsa_card->ucm,
+				dev_node->iodev->nodes->name);
 		if (!echo_ref_name)
 			continue;
-		DL_FOREACH (alsa_card->iodevs, echo_ref_node) {
+		DL_FOREACH(alsa_card->iodevs, echo_ref_node) {
 			if (echo_ref_node->iodev->nodes == NULL)
 				continue;
 			if (!strcmp(echo_ref_name,
@@ -416,7 +438,7 @@
 		}
 		if (echo_ref_node)
 			dev_node->iodev->echo_reference_dev =
-				echo_ref_node->iodev;
+					echo_ref_node->iodev;
 		else
 			syslog(LOG_ERR,
 			       "Echo ref dev %s doesn't exist on card %s",
@@ -430,8 +452,10 @@
  */
 
 struct cras_alsa_card *cras_alsa_card_create(
-	struct cras_alsa_card_info *info, const char *device_config_dir,
-	struct cras_device_blacklist *blacklist, const char *ucm_suffix)
+		struct cras_alsa_card_info *info,
+		const char *device_config_dir,
+		struct cras_device_blacklist *blacklist,
+		const char *ucm_suffix)
 {
 	snd_ctl_t *handle = NULL;
 	int rc, n;
@@ -440,7 +464,9 @@
 	struct cras_alsa_card *alsa_card;
 
 	if (info->card_index >= MAX_ALSA_CARDS) {
-		syslog(LOG_ERR, "Invalid alsa card index %u", info->card_index);
+		syslog(LOG_ERR,
+		       "Invalid alsa card index %u",
+		       info->card_index);
 		return NULL;
 	}
 
@@ -451,7 +477,9 @@
 		return NULL;
 	alsa_card->card_index = info->card_index;
 
-	snprintf(alsa_card->name, MAX_ALSA_PCM_NAME_LENGTH, "hw:%u",
+	snprintf(alsa_card->name,
+		 MAX_ALSA_PCM_NAME_LENGTH,
+		 "hw:%u",
 		 info->card_index);
 
 	rc = snd_ctl_open(&handle, alsa_card->name, 0);
@@ -473,8 +501,8 @@
 	}
 
 	/* Read config file for this card if it exists. */
-	alsa_card->config =
-		cras_card_config_create(device_config_dir, card_name);
+	alsa_card->config = cras_card_config_create(device_config_dir,
+						    card_name);
 	if (alsa_card->config == NULL)
 		syslog(LOG_DEBUG, "No config file for %s", alsa_card->name);
 
@@ -486,31 +514,36 @@
 			goto error_bail;
 		}
 		alsa_card->ucm = ucm_create(ucm_name);
-		syslog(LOG_INFO, "Card %s (%s) has UCM: %s", alsa_card->name,
-		       ucm_name, alsa_card->ucm ? "yes" : "no");
+		syslog(LOG_INFO, "Card %s (%s) has UCM: %s",
+		       alsa_card->name, ucm_name,
+		       alsa_card->ucm ? "yes" : "no");
 		free(ucm_name);
 	} else {
 		alsa_card->ucm = ucm_create(card_name);
-		syslog(LOG_INFO, "Card %s (%s) has UCM: %s", alsa_card->name,
-		       card_name, alsa_card->ucm ? "yes" : "no");
+		syslog(LOG_INFO, "Card %s (%s) has UCM: %s",
+		       alsa_card->name, card_name,
+		       alsa_card->ucm ? "yes" : "no");
 	}
 
-	rc = snd_hctl_open(&alsa_card->hctl, alsa_card->name, SND_CTL_NONBLOCK);
+	rc = snd_hctl_open(&alsa_card->hctl,
+			   alsa_card->name,
+			   SND_CTL_NONBLOCK);
 	if (rc < 0) {
-		syslog(LOG_DEBUG, "failed to get hctl for %s", alsa_card->name);
+		syslog(LOG_DEBUG,
+		       "failed to get hctl for %s", alsa_card->name);
 		alsa_card->hctl = NULL;
 	} else {
 		rc = snd_hctl_nonblock(alsa_card->hctl, 1);
 		if (rc < 0) {
-			syslog(LOG_ERR, "failed to nonblock hctl for %s",
-			       alsa_card->name);
+			syslog(LOG_ERR,
+			    "failed to nonblock hctl for %s", alsa_card->name);
 			goto error_bail;
 		}
 
 		rc = snd_hctl_load(alsa_card->hctl);
 		if (rc < 0) {
-			syslog(LOG_ERR, "failed to load hctl for %s",
-			       alsa_card->name);
+			syslog(LOG_ERR,
+			       "failed to load hctl for %s", alsa_card->name);
 			goto error_bail;
 		}
 	}
@@ -524,18 +557,18 @@
 	}
 
 	if (alsa_card->ucm && ucm_has_fully_specified_ucm_flag(alsa_card->ucm))
-		rc = add_controls_and_iodevs_with_ucm(info, alsa_card,
-						      card_name, handle);
+		rc = add_controls_and_iodevs_with_ucm(
+				info, alsa_card, card_name, handle);
 	else
 		rc = add_controls_and_iodevs_by_matching(
-			info, blacklist, alsa_card, card_name, handle);
+				info, blacklist, alsa_card, card_name, handle);
 	if (rc)
 		goto error_bail;
 
 	configure_echo_reference_dev(alsa_card);
 
-	n = alsa_card->hctl ? snd_hctl_poll_descriptors_count(alsa_card->hctl) :
-			      0;
+	n = alsa_card->hctl ?
+		snd_hctl_poll_descriptors_count(alsa_card->hctl) : 0;
 	if (n != 0 && card_has_hctl_jack(alsa_card)) {
 		struct hctl_poll_fd *registered_fd;
 		struct pollfd *pollfds;
@@ -558,8 +591,9 @@
 			registered_fd->fd = pollfds[i].fd;
 			DL_APPEND(alsa_card->hctl_poll_fds, registered_fd);
 			rc = cras_system_add_select_fd(
-				registered_fd->fd, alsa_control_event_pending,
-				alsa_card);
+					registered_fd->fd,
+					alsa_control_event_pending,
+					alsa_card);
 			if (rc < 0) {
 				DL_DELETE(alsa_card->hctl_poll_fds,
 					  registered_fd);
@@ -588,12 +622,12 @@
 	if (alsa_card == NULL)
 		return;
 
-	DL_FOREACH (alsa_card->iodevs, curr) {
+	DL_FOREACH(alsa_card->iodevs, curr) {
 		alsa_iodev_destroy(curr->iodev);
 		DL_DELETE(alsa_card->iodevs, curr);
 		free(curr);
 	}
-	DL_FOREACH (alsa_card->hctl_poll_fds, poll_fd) {
+	DL_FOREACH(alsa_card->hctl_poll_fds, poll_fd) {
 		cras_system_rm_select_fd(poll_fd->fd);
 		DL_DELETE(alsa_card->hctl_poll_fds, poll_fd);
 		free(poll_fd);
diff --git a/cras/src/server/cras_alsa_card.h b/cras/src/server/cras_alsa_card.h
index 749a17f..705b8e7 100644
--- a/cras/src/server/cras_alsa_card.h
+++ b/cras/src/server/cras_alsa_card.h
@@ -31,8 +31,10 @@
  *    by calling cras_alsa_card_destroy or NULL on error.
  */
 struct cras_alsa_card *cras_alsa_card_create(
-	struct cras_alsa_card_info *info, const char *device_config_dir,
-	struct cras_device_blacklist *blacklist, const char *ucm_suffix);
+		struct cras_alsa_card_info *info,
+		const char *device_config_dir,
+		struct cras_device_blacklist *blacklist,
+		const char *ucm_suffix);
 
 /* Destroys a cras_alsa_card that was returned from cras_alsa_card_create.
  * Args:
diff --git a/cras/src/server/cras_alsa_helpers.c b/cras/src/server/cras_alsa_helpers.c
index b0729fd..d2520e7 100644
--- a/cras/src/server/cras_alsa_helpers.c
+++ b/cras/src/server/cras_alsa_helpers.c
@@ -16,8 +16,8 @@
  * alsa-lib since 1.0.27) and CRAS_CHANNEL, values of which are
  * of the same order but shifted by 3.
  */
-#define CH_TO_ALSA(ch) ((ch) + (3))
-#define CH_TO_CRAS(ch) ((ch) - (3))
+#define CH_TO_ALSA(ch) ((ch) + 3)
+#define CH_TO_CRAS(ch) ((ch) - 3)
 
 /* Assert the channel is defined in CRAS_CHANNELS. */
 #define ALSA_CH_VALID(ch) ((ch >= SND_CHMAP_FL) && (ch <= SND_CHMAP_FRC))
@@ -33,24 +33,44 @@
 /* What rates should we check for on this dev?
  * Listed in order of preference. 0 terminalted. */
 static const size_t test_sample_rates[] = {
-	44100, 48000, 32000, 96000, 22050, 16000, 8000, 4000, 192000, 0,
+	44100,
+	48000,
+	32000,
+	96000,
+	22050,
+	16000,
+	8000,
+	4000,
+	192000,
+	0
 };
 
 /* What channel counts shoud be checked on this dev?
  * Listed in order of preference. 0 terminalted. */
-static const size_t test_channel_counts[] = { 10, 6, 4, 2, 1, 8, 0 };
+static const size_t test_channel_counts[] = {
+	10,
+	6,
+	4,
+	2,
+	1,
+	8,
+	0
+};
 
 static const snd_pcm_format_t test_formats[] = {
-	SND_PCM_FORMAT_S16_LE, SND_PCM_FORMAT_S24_LE, SND_PCM_FORMAT_S32_LE,
-	SND_PCM_FORMAT_S24_3LE, (snd_pcm_format_t)0
+	SND_PCM_FORMAT_S16_LE,
+	SND_PCM_FORMAT_S24_LE,
+	SND_PCM_FORMAT_S32_LE,
+	SND_PCM_FORMAT_S24_3LE,
+	(snd_pcm_format_t)0
 };
 
 /* Looks up the list of channel map for the one can exactly matches
  * the layout specified in fmt.
  */
-static snd_pcm_chmap_query_t *
-cras_chmap_caps_match(snd_pcm_chmap_query_t **chmaps,
-		      struct cras_audio_format *fmt)
+static snd_pcm_chmap_query_t *cras_chmap_caps_match(
+		snd_pcm_chmap_query_t **chmaps,
+		struct cras_audio_format *fmt)
 {
 	size_t ch, i;
 	int idx, matches;
@@ -115,7 +135,7 @@
 
 			if (fmt->channel_layout[ch] + 1 !=
 			    fmt->channel_layout[CH_TO_CRAS(
-				    (*chmap)->map.pos[i + 1])]) {
+					    (*chmap)->map.pos[i + 1])]) {
 				matches = 0;
 				break;
 			}
@@ -131,17 +151,17 @@
  * channel map which can be supported by means of channel conversion
  * matrix.
  */
-static snd_pcm_chmap_query_t *
-cras_chmap_caps_conv_matrix(snd_pcm_chmap_query_t **chmaps,
-			    struct cras_audio_format *fmt)
+static snd_pcm_chmap_query_t *cras_chmap_caps_conv_matrix(
+		snd_pcm_chmap_query_t **chmaps,
+		struct cras_audio_format *fmt)
 {
 	float **conv_mtx;
 	size_t i;
 	snd_pcm_chmap_query_t **chmap;
 	struct cras_audio_format *conv_fmt;
 
-	conv_fmt = cras_audio_format_create(fmt->format, fmt->frame_rate,
-					    fmt->num_channels);
+	conv_fmt = cras_audio_format_create(fmt->format,
+			fmt->frame_rate, fmt->num_channels);
 
 	for (chmap = chmaps; *chmap; chmap++) {
 		if ((*chmap)->map.channels != fmt->num_channels)
@@ -152,7 +172,7 @@
 			if (!ALSA_CH_VALID((*chmap)->map.pos[i]))
 				continue;
 			conv_fmt->channel_layout[CH_TO_CRAS(
-				(*chmap)->map.pos[i])] = i;
+					(*chmap)->map.pos[i])] = i;
 		}
 
 		/* Examine channel map by test creating a conversion matrix
@@ -162,8 +182,8 @@
 		 */
 		conv_mtx = cras_channel_conv_matrix_create(fmt, conv_fmt);
 		if (conv_mtx) {
-			cras_channel_conv_matrix_destroy(
-				conv_mtx, conv_fmt->num_channels);
+			cras_channel_conv_matrix_destroy(conv_mtx,
+						 conv_fmt->num_channels);
 			cras_audio_format_destroy(conv_fmt);
 			return *chmap;
 		}
@@ -176,9 +196,10 @@
 /* Finds the best channel map for given format and list of channel
  * map capability.
  */
-static snd_pcm_chmap_query_t *
-cras_chmap_caps_best(snd_pcm_t *handle, snd_pcm_chmap_query_t **chmaps,
-		     struct cras_audio_format *fmt)
+static snd_pcm_chmap_query_t *cras_chmap_caps_best(
+		snd_pcm_t *handle,
+		snd_pcm_chmap_query_t **chmaps,
+		struct cras_audio_format *fmt)
 {
 	snd_pcm_chmap_query_t **chmap;
 	snd_pcm_chmap_query_t *match;
@@ -210,10 +231,13 @@
 	static const unsigned int OPEN_RETRY_DELAY_US = 100000;
 
 retry_open:
-	rc = snd_pcm_open(handle, dev, stream,
-			  SND_PCM_NONBLOCK | SND_PCM_NO_AUTO_RESAMPLE |
-				  SND_PCM_NO_AUTO_CHANNELS |
-				  SND_PCM_NO_AUTO_FORMAT);
+	rc = snd_pcm_open(handle,
+			  dev,
+			  stream,
+			  SND_PCM_NONBLOCK |
+			  SND_PCM_NO_AUTO_RESAMPLE |
+			  SND_PCM_NO_AUTO_CHANNELS |
+			  SND_PCM_NO_AUTO_FORMAT);
 	if (rc == -EBUSY && --retries) {
 		usleep(OPEN_RETRY_DELAY_US);
 		goto retry_open;
@@ -278,7 +302,8 @@
 	return 0;
 }
 
-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)
 {
 	size_t i, ch;
 	snd_pcm_chmap_query_t **chmaps;
@@ -318,7 +343,8 @@
 	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)
 {
 	snd_pcm_chmap_query_t **chmaps;
 	snd_pcm_chmap_query_t *match;
@@ -357,8 +383,8 @@
 	return rc;
 }
 
-int cras_alsa_fill_properties(snd_pcm_t *handle, size_t **rates,
-			      size_t **channel_counts,
+int cras_alsa_fill_properties(snd_pcm_t *handle,
+			      size_t **rates, size_t **channel_counts,
 			      snd_pcm_format_t **formats)
 {
 	int rc;
@@ -475,7 +501,7 @@
 		unsigned int original = dma_period_time;
 
 		err = snd_pcm_hw_params_set_period_time_near(
-			handle, hwparams, &dma_period_time, &dir);
+				handle, hwparams, &dma_period_time, &dir);
 		if (err < 0) {
 			syslog(LOG_ERR, "could not set period time: %s",
 			       snd_strerror(err));
@@ -486,7 +512,8 @@
 		}
 	}
 	/* Set the sample format. */
-	err = snd_pcm_hw_params_set_format(handle, hwparams, format->format);
+	err = snd_pcm_hw_params_set_format(handle, hwparams,
+					   format->format);
 	if (err < 0) {
 		syslog(LOG_ERR, "set format %s\n", snd_strerror(err));
 		return err;
@@ -514,7 +541,8 @@
 
 	/* Make sure buffer frames is even, or snd_pcm_hw_params will
 	 * return invalid argument error. */
-	err = snd_pcm_hw_params_get_buffer_size_max(hwparams, buffer_frames);
+	err = snd_pcm_hw_params_get_buffer_size_max(hwparams,
+						    buffer_frames);
 	if (err < 0)
 		syslog(LOG_WARNING, "get buffer max %s\n", snd_strerror(err));
 
@@ -532,11 +560,9 @@
 	/* Finally, write the parameters to the device. */
 	err = snd_pcm_hw_params(handle, hwparams);
 	if (err < 0) {
-		syslog(LOG_ERR,
-		       "hw_params: %s: rate: %u, ret_rate: %u, "
-		       "channel: %zu, format: %u\n",
-		       snd_strerror(err), rate, ret_rate, format->num_channels,
-		       format->format);
+		syslog(LOG_ERR, "hw_params: %s: rate: %u, ret_rate: %u, "
+		       "channel: %zu, format: %u\n", snd_strerror(err), rate,
+		       ret_rate, format->num_channels, format->format);
 		return err;
 	}
 	return 0;
@@ -582,14 +608,15 @@
 	if (*enable_htimestamp) {
 		/* Use MONOTONIC_RAW time-stamps. */
 		err = snd_pcm_sw_params_set_tstamp_type(
-			handle, swparams, SND_PCM_TSTAMP_TYPE_MONOTONIC_RAW);
+				handle, swparams,
+				SND_PCM_TSTAMP_TYPE_MONOTONIC_RAW);
 		if (err < 0) {
 			syslog(LOG_ERR, "set_tstamp_type: %s\n",
 			       snd_strerror(err));
 			return err;
 		}
-		err = snd_pcm_sw_params_set_tstamp_mode(handle, swparams,
-							SND_PCM_TSTAMP_ENABLE);
+		err = snd_pcm_sw_params_set_tstamp_mode(
+				handle, swparams, SND_PCM_TSTAMP_ENABLE);
 		if (err < 0) {
 			syslog(LOG_ERR, "set_tstamp_mode: %s\n",
 			       snd_strerror(err));
@@ -607,14 +634,15 @@
 		       "MONOTONIC_RAW timestamps are not supported.");
 
 		err = snd_pcm_sw_params_set_tstamp_type(
-			handle, swparams, SND_PCM_TSTAMP_TYPE_GETTIMEOFDAY);
+				handle, swparams,
+				SND_PCM_TSTAMP_TYPE_GETTIMEOFDAY);
 		if (err < 0) {
 			syslog(LOG_ERR, "set_tstamp_type: %s\n",
 			       snd_strerror(err));
 			return err;
 		}
-		err = snd_pcm_sw_params_set_tstamp_mode(handle, swparams,
-							SND_PCM_TSTAMP_NONE);
+		err = snd_pcm_sw_params_set_tstamp_mode(
+				handle, swparams, SND_PCM_TSTAMP_NONE);
 		if (err < 0) {
 			syslog(LOG_ERR, "set_tstamp_mode: %s\n",
 			       snd_strerror(err));
@@ -633,13 +661,14 @@
 
 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 *avail,
+			       const char *dev_name,
+			       snd_pcm_uframes_t *avail,
 			       struct timespec *tstamp)
 {
 	snd_pcm_sframes_t frames;
 	int rc = 0;
-	static struct timespec tstamp_last_underrun_log = { .tv_sec = 0,
-							    .tv_nsec = 0 };
+	static struct timespec tstamp_last_underrun_log =
+			{.tv_sec = 0, .tv_nsec = 0};
 
 	/* Use snd_pcm_avail still to ensure that the hardware pointer is
 	 * up to date. Otherwise, we could use the deprecated snd_pcm_hwsync().
@@ -655,8 +684,8 @@
 		rc = 0;
 		goto error;
 	} else if (rc < 0) {
-		syslog(LOG_ERR, "pcm_avail error %s, %s\n", dev_name,
-		       snd_strerror(rc));
+		syslog(LOG_ERR, "pcm_avail error %s, %s\n",
+		       dev_name, snd_strerror(rc));
 		goto error;
 	} else if (frames > (snd_pcm_sframes_t)buf_size) {
 		struct timespec tstamp_now;
@@ -789,7 +818,7 @@
 		 * case.
 		 */
 		if (snd_pcm_stream(handle) == SND_PCM_STREAM_PLAYBACK &&
-		    *frames == 0) {
+				*frames == 0) {
 			syslog(LOG_INFO, "mmap_begin set frames to 0.");
 			return -EIO;
 		}
diff --git a/cras/src/server/cras_alsa_helpers.h b/cras/src/server/cras_alsa_helpers.h
index 3897674..81ed645 100644
--- a/cras/src/server/cras_alsa_helpers.h
+++ b/cras/src/server/cras_alsa_helpers.h
@@ -16,6 +16,7 @@
 
 struct cras_audio_format;
 
+
 /* Sets the channel layout from given format to the pcm handle.
  * Args:
  *    handle - Pointer to the opened pcm to set channel map to.
@@ -23,7 +24,8 @@
  * Returns:
  *    0 if a matched channel map is set to HW, -1 otherwise.
  */
-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);
 
 /*  Gets the supported channel mapping of the pcm handle which matches
  *  the channel layout in the format.
@@ -33,7 +35,8 @@
  *  Returns:
  *     0 if an exactly matched channel map is found, -1 otherwise.
  */
-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);
 
 /* Opens an alsa device, thin wrapper to snd_pcm_open.
  * Args:
@@ -112,8 +115,8 @@
  * Returns:
  *   0 on success.  On failure an error code from alsa or -ENOMEM.
  */
-int cras_alsa_fill_properties(snd_pcm_t *handle, size_t **rates,
-			      size_t **channel_counts,
+int cras_alsa_fill_properties(snd_pcm_t *handle,
+			      size_t **rates, size_t **channel_counts,
 			      snd_pcm_format_t **formats);
 
 /* Sets up the hwparams to alsa.
@@ -164,7 +167,8 @@
  */
 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 *avail,
+			       const char *dev_name,
+			       snd_pcm_uframes_t *avail,
 			       struct timespec *tstamp);
 
 /* Get the current alsa delay, make sure it's no bigger than the buffer size.
diff --git a/cras/src/server/cras_alsa_io.c b/cras/src/server/cras_alsa_io.c
index 4aec9d6..d9169f1 100644
--- a/cras/src/server/cras_alsa_io.c
+++ b/cras/src/server/cras_alsa_io.c
@@ -67,15 +67,6 @@
 #define SEVERE_UNDERRUN_MS 5000
 
 /*
- * When entering no stream state, audio thread needs to fill extra zeros in
- * order to play remaining valid frames. The value indicates how many
- * time will be filled.
- */
-static const struct timespec no_stream_fill_zeros_duration = {
-	0, 50 * 1000 * 1000 /* 50 msec. */
-};
-
-/*
  * This extends cras_ionode to include alsa-specific information.
  * Members:
  *    mixer_output - From cras_alsa_mixer.
@@ -91,7 +82,7 @@
 
 struct alsa_input_node {
 	struct cras_ionode base;
-	struct mixer_control *mixer_input;
+	struct mixer_control* mixer_input;
 	const struct cras_alsa_jack *jack;
 	int8_t *channel_layout;
 };
@@ -109,7 +100,6 @@
  * is_first - true if this is the first iodev on the card.
  * fully_specified - true if this device and it's nodes were fully specified.
  *     That is, don't automatically create nodes for it.
- * jack_always_plugged - true if this node is always plugged even without jack.
  * enable_htimestamp - True when the device's htimestamp is used.
  * handle - Handle to the opened ALSA device.
  * num_underruns - Number of times we have run out of data (playback only).
@@ -128,10 +118,10 @@
  *     by the jack specific dsp name.
  * poll_fd - Descriptor used to block until data is ready.
  * dma_period_set_microsecs - If non-zero, the value to apply to the dma_period.
- * free_running - true if device is playing zeros in the buffer without
- *                user filling meaningful data. The device buffer is filled
- *                with zeros. In this state, appl_ptr remains the same
- *                while hw_ptr keeps running ahead.
+ * is_free_running - true if device is playing zeros in the buffer without
+ *                   user filling meaningful data. The device buffer is filled
+ *                   with zeros. In this state, appl_ptr remains the same
+ *                   while hw_ptr keeps running ahead.
  * filled_zeros_for_draining - The number of zeros filled for draining.
  * severe_underrun_frames - The threshold for severe underrun.
  * default_volume_curve - Default volume curve that converts from an index
@@ -147,7 +137,6 @@
 	enum CRAS_ALSA_CARD_TYPE card_type;
 	int is_first;
 	int fully_specified;
-	int jack_always_plugged;
 	int enable_htimestamp;
 	snd_pcm_t *handle;
 	unsigned int num_underruns;
@@ -161,7 +150,7 @@
 	const char *dsp_name_default;
 	int poll_fd;
 	unsigned int dma_period_set_microsecs;
-	int free_running;
+	int is_free_running;
 	unsigned int filled_zeros_for_draining;
 	snd_pcm_uframes_t severe_underrun_frames;
 	struct cras_volume_curve *default_volume_curve;
@@ -257,16 +246,6 @@
 		.type = CRAS_NODE_TYPE_LINEOUT,
 		.position = NODE_POSITION_EXTERNAL,
 	},
-	{
-		.name = "SCO Line In",
-		.type = CRAS_NODE_TYPE_BLUETOOTH,
-		.position = NODE_POSITION_EXTERNAL,
-	},
-	{
-		.name = "SCO Line Out",
-		.type = CRAS_NODE_TYPE_BLUETOOTH,
-		.position = NODE_POSITION_EXTERNAL,
-	},
 };
 
 static int set_hwparams(struct cras_iodev *iodev)
@@ -305,9 +284,11 @@
 	int rc;
 	snd_pcm_uframes_t frames;
 
-	rc = cras_alsa_get_avail_frames(aio->handle, aio->base.buffer_size,
+	rc = cras_alsa_get_avail_frames(aio->handle,
+					aio->base.buffer_size,
 					aio->severe_underrun_frames,
-					iodev->info.name, &frames, tstamp);
+					iodev->info.name,
+					&frames, tstamp);
 	if (rc < 0) {
 		if (rc == -EPIPE)
 			aio->num_severe_underruns++;
@@ -328,7 +309,8 @@
 	snd_pcm_sframes_t delay;
 	int rc;
 
-	rc = cras_alsa_get_delay_frames(aio->handle, iodev->buffer_size,
+	rc = cras_alsa_get_delay_frames(aio->handle,
+					iodev->buffer_size,
 					&delay);
 	if (rc < 0)
 		return rc;
@@ -343,12 +325,13 @@
 	/* Removes audio thread callback from main thread. */
 	if (aio->poll_fd >= 0)
 		audio_thread_rm_callback_sync(
-			cras_iodev_list_get_audio_thread(), aio->poll_fd);
+				cras_iodev_list_get_audio_thread(),
+				aio->poll_fd);
 	if (!aio->handle)
 		return 0;
 	cras_alsa_pcm_close(aio->handle);
 	aio->handle = NULL;
-	aio->free_running = 0;
+	aio->is_free_running = 0;
 	aio->filled_zeros_for_draining = 0;
 	aio->hwparams_set = 0;
 	cras_iodev_free_format(&aio->base);
@@ -396,10 +379,10 @@
 	if (iodev->format == NULL)
 		return -EINVAL;
 	aio->num_underruns = 0;
-	aio->free_running = 0;
+	aio->is_free_running = 0;
 	aio->filled_zeros_for_draining = 0;
 	aio->severe_underrun_frames =
-		SEVERE_UNDERRUN_MS * iodev->format->frame_rate / 1000;
+			SEVERE_UNDERRUN_MS * iodev->format->frame_rate / 1000;
 
 	cras_iodev_init_audio_area(iodev, iodev->format->num_channels);
 
@@ -412,7 +395,8 @@
 		return rc;
 
 	/* Set channel map to device */
-	rc = cras_alsa_set_channel_map(aio->handle, iodev->format);
+	rc = cras_alsa_set_channel_map(aio->handle,
+				       iodev->format);
 	if (rc < 0)
 		return rc;
 
@@ -458,7 +442,8 @@
 
 		if (aio->poll_fd >= 0)
 			audio_thread_add_callback(aio->poll_fd,
-						  dummy_hotword_cb, aio);
+						  dummy_hotword_cb,
+						  aio);
 	}
 
 	/* Capture starts right away, playback will wait for samples. */
@@ -509,7 +494,8 @@
 	return 0;
 }
 
-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 alsa_io *aio = (struct alsa_io *)iodev;
@@ -521,8 +507,11 @@
 	aio->mmap_offset = 0;
 	format_bytes = cras_get_format_bytes(iodev->format);
 
-	rc = cras_alsa_mmap_begin(aio->handle, format_bytes, &dst,
-				  &aio->mmap_offset, &nframes);
+	rc = cras_alsa_mmap_begin(aio->handle,
+				  format_bytes,
+				  &dst,
+				  &aio->mmap_offset,
+				  &nframes);
 
 	iodev->area->frames = nframes;
 	cras_audio_area_config_buf_pointers(iodev->area, iodev->format, dst);
@@ -537,7 +526,9 @@
 {
 	struct alsa_io *aio = (struct alsa_io *)iodev;
 
-	return cras_alsa_mmap_commit(aio->handle, aio->mmap_offset, nwritten);
+	return cras_alsa_mmap_commit(aio->handle,
+				     aio->mmap_offset,
+				     nwritten);
 }
 
 static int flush_buffer(struct cras_iodev *iodev)
@@ -564,7 +555,7 @@
 	/* When this is called at iodev creation, none of the nodes
 	 * are selected. Just pick the first plugged one and let Chrome
 	 * choose it later. */
-	DL_FOREACH (iodev->nodes, n) {
+	DL_FOREACH(iodev->nodes, n) {
 		if (n->plugged)
 			return n;
 	}
@@ -577,7 +568,7 @@
 	struct cras_ionode *n;
 
 	/* If a node exists for node_idx, set it as active. */
-	DL_FOREACH (iodev->nodes, n) {
+	DL_FOREACH(iodev->nodes, n) {
 		if (n->idx == node_idx) {
 			alsa_iodev_set_active_node(iodev, n, dev_enabled);
 			return;
@@ -650,9 +641,9 @@
  * Gets the curve for the active output node. If the node doesn't have volume
  * curve specified, return the default volume curve of the parent iodev.
  */
-static const struct cras_volume_curve *
-get_curve_for_output_node(const struct alsa_io *aio,
-			  const struct alsa_output_node *node)
+static const struct cras_volume_curve *get_curve_for_output_node(
+		const struct alsa_io *aio,
+		const struct alsa_output_node *node)
 {
 	if (node && node->volume_curve)
 		return node->volume_curve;
@@ -662,8 +653,8 @@
 /*
  * Gets the curve for the active output.
  */
-static const struct cras_volume_curve *
-get_curve_for_active_output(const struct alsa_io *aio)
+static const struct cras_volume_curve *get_curve_for_active_output(
+		const struct alsa_io *aio)
 {
 	struct alsa_output_node *node = get_active_output(aio);
 	return get_curve_for_output_node(aio, node);
@@ -681,9 +672,26 @@
 		return;
 
 	curve = get_curve_for_active_output(aio);
-	cras_system_set_volume_limits(curve->get_dBFS(curve, 1), /* min */
-				      curve->get_dBFS(curve,
-						      CRAS_MAX_SYSTEM_VOLUME));
+	cras_system_set_volume_limits(
+			curve->get_dBFS(curve, 1), /* min */
+			curve->get_dBFS(curve, CRAS_MAX_SYSTEM_VOLUME));
+}
+
+/*
+ * Sets the alsa mute control for this iodev.
+ */
+static void set_alsa_mute_control(const struct alsa_io *aio, int muted)
+{
+	struct alsa_output_node *aout;
+
+	if (!has_handle(aio))
+		return;
+
+	aout = get_active_output(aio);
+	cras_alsa_mixer_set_mute(
+		aio->mixer,
+		muted,
+		aout ? aout->mixer_output : NULL);
 }
 
 /*
@@ -719,24 +727,17 @@
 	if (cras_iodev_software_volume_needed(iodev))
 		volume = 100;
 
-	cras_alsa_mixer_set_dBFS(aio->mixer, curve->get_dBFS(curve, volume),
-				 aout ? aout->mixer_output : NULL);
+	cras_alsa_mixer_set_dBFS(
+		aio->mixer,
+		curve->get_dBFS(curve, volume),
+		aout ? aout->mixer_output : NULL);
 }
 
-/*
- * Sets the alsa mute control for this iodev.
- */
 static void set_alsa_mute(struct cras_iodev *iodev)
 {
+	/* Mute for zero. */
 	const struct alsa_io *aio = (const struct alsa_io *)iodev;
-	struct alsa_output_node *aout;
-
-	if (!has_handle(aio))
-		return;
-
-	aout = get_active_output(aio);
-	cras_alsa_mixer_set_mute(aio->mixer, cras_system_get_mute(),
-				 aout ? aout->mixer_output : NULL);
+	set_alsa_mute_control(aio, cras_system_get_mute());
 }
 
 /*
@@ -758,7 +759,7 @@
 	if (!has_handle(aio))
 		return;
 	gain = cras_iodev_adjust_active_node_gain(
-		iodev, cras_system_get_capture_gain());
+				iodev, cras_system_get_capture_gain());
 
 	/* Set hardware gain to 0dB if software gain is needed. */
 	if (cras_iodev_software_volume_needed(iodev))
@@ -766,8 +767,10 @@
 
 	ain = get_active_input(aio);
 
-	cras_alsa_mixer_set_capture_dBFS(aio->mixer, gain,
-					 ain ? ain->mixer_input : NULL);
+	cras_alsa_mixer_set_capture_dBFS(
+			aio->mixer,
+			gain,
+			ain ? ain->mixer_input : NULL);
 	cras_alsa_mixer_set_capture_mute(aio->mixer,
 					 cras_system_get_capture_mute(),
 					 ain ? ain->mixer_input : NULL);
@@ -806,17 +809,17 @@
 			mixer_input = ain->mixer_input;
 
 		if (cras_iodev_software_volume_needed(&aio->base)) {
-			min_capture_gain =
-				cras_iodev_minimum_software_gain(&aio->base);
-			max_capture_gain =
-				cras_iodev_maximum_software_gain(&aio->base);
+			min_capture_gain = cras_iodev_minimum_software_gain(
+					&aio->base);
+			max_capture_gain = cras_iodev_maximum_software_gain(
+					&aio->base);
 		} else {
 			min_capture_gain =
 				cras_alsa_mixer_get_minimum_capture_gain(
-					aio->mixer, mixer_input);
+						aio->mixer, mixer_input);
 			max_capture_gain =
 				cras_alsa_mixer_get_maximum_capture_gain(
-					aio->mixer, mixer_input);
+						aio->mixer, mixer_input);
 		}
 		cras_system_set_capture_gain_limits(min_capture_gain,
 						    max_capture_gain);
@@ -842,14 +845,13 @@
 	free(aio->base.supported_channel_counts);
 	free(aio->base.supported_formats);
 
-	DL_FOREACH (aio->base.nodes, node) {
+	DL_FOREACH(aio->base.nodes, node) {
 		if (aio->base.direction == CRAS_STREAM_OUTPUT) {
 			aout = (struct alsa_output_node *)node;
 			cras_volume_curve_destroy(aout->volume_curve);
 		}
 		cras_iodev_rm_node(&aio->base, node);
 		free(node->softvol_scalers);
-		free((void *)node->dsp_name);
 		free(node);
 	}
 
@@ -877,7 +879,7 @@
 {
 	struct cras_ionode *node;
 
-	DL_FOREACH (aio->base.nodes, node)
+	DL_FOREACH(aio->base.nodes, node)
 		if (!strcmp(node->name, name))
 			return 1;
 
@@ -906,10 +908,8 @@
 		strcpy(node->name, HDMI);
 	else {
 		/* Only HDMI or USB node might have invalid name to drop */
-		syslog(LOG_ERR,
-		       "Unexpectedly drop node name for "
-		       "node: %s, type: %d",
-		       node->name, node->type);
+		syslog(LOG_ERR, "Unexpectedly drop node name for "
+		       "node: %s, type: %d", node->name, node->type);
 		strcpy(node->name, DEFAULT);
 	}
 }
@@ -922,6 +922,7 @@
 static void set_node_initial_state(struct cras_ionode *node,
 				   enum CRAS_ALSA_CARD_TYPE card_type)
 {
+
 	unsigned i;
 
 	node->volume = 100;
@@ -931,8 +932,8 @@
 		if (!strncmp(node->name, node_defaults[i].name,
 			     strlen(node_defaults[i].name))) {
 			node->position = node_defaults[i].position;
-			node->plugged =
-				(node->position != NODE_POSITION_EXTERNAL);
+			node->plugged = (node->position
+					!= NODE_POSITION_EXTERNAL);
 			node->type = node_defaults[i].type;
 			if (node->plugged)
 				gettimeofday(&node->plugged_time, NULL);
@@ -954,12 +955,11 @@
 		if (endswith(node->name, "Jack") && !strstr(node->name, HDMI)) {
 			if (node->dev->direction == CRAS_STREAM_OUTPUT) {
 				node->type = CRAS_NODE_TYPE_HEADPHONE;
-				strncpy(node->name, HEADPHONE,
-					sizeof(node->name) - 1);
-			} else {
+				strncpy(node->name, HEADPHONE, sizeof(node->name) - 1);
+			}
+			else {
 				node->type = CRAS_NODE_TYPE_MIC;
-				strncpy(node->name, MIC,
-					sizeof(node->name) - 1);
+				strncpy(node->name, MIC, sizeof(node->name) - 1);
 			}
 		}
 		if (strstr(node->name, HDMI) &&
@@ -981,7 +981,8 @@
 #endif
 }
 
-static int get_ucm_flag_integer(struct alsa_io *aio, const char *flag_name,
+static int get_ucm_flag_integer(struct alsa_io *aio,
+				const char *flag_name,
 				int *result)
 {
 	char *value;
@@ -1032,10 +1033,10 @@
 	return result;
 }
 
-static void
-set_output_node_software_volume_needed(struct alsa_output_node *output,
-				       struct alsa_io *aio)
+static void set_output_node_software_volume_needed(
+	struct alsa_output_node *output, struct alsa_io *aio)
 {
+
 	struct cras_alsa_mixer *mixer = aio->mixer;
 	long range = 0;
 
@@ -1058,7 +1059,7 @@
 	if (output->base.type == CRAS_NODE_TYPE_USB) {
 		range += cras_alsa_mixer_get_dB_range(mixer);
 		range += cras_alsa_mixer_get_output_dB_range(
-			output->mixer_output);
+				output->mixer_output);
 		if (range < 4000)
 			output->base.software_volume_needed = 1;
 	}
@@ -1067,8 +1068,8 @@
 		       output->base.name);
 }
 
-static void set_input_node_software_volume_needed(struct alsa_input_node *input,
-						  struct alsa_io *aio)
+static void set_input_node_software_volume_needed(
+	struct alsa_input_node *input, struct alsa_io *aio)
 {
 	long min_software_gain;
 	long max_software_gain;
@@ -1083,7 +1084,7 @@
 		return;
 
 	rc = ucm_get_max_software_gain(aio->ucm, input->base.name,
-				       &max_software_gain);
+	                               &max_software_gain);
 
 	/* If max software gain doesn't exist, skip min software gain setting. */
 	if (rc)
@@ -1093,27 +1094,24 @@
 	input->base.max_software_gain = max_software_gain;
 	syslog(LOG_INFO,
 	       "Use software gain for %s with max %ld because it is specified"
-	       " in UCM",
-	       input->base.name, max_software_gain);
+	       " in UCM", input->base.name, max_software_gain);
 
 	/* Enable min software gain if it is specified in UCM. */
 	rc = ucm_get_min_software_gain(aio->ucm, input->base.name,
-				       &min_software_gain);
+	                               &min_software_gain);
 	if (rc)
 		return;
 
 	if (min_software_gain > max_software_gain) {
 		syslog(LOG_ERR,
 		       "Ignore MinSoftwareGain %ld because it is larger than "
-		       "MaxSoftwareGain %ld",
-		       min_software_gain, max_software_gain);
+		       "MaxSoftwareGain %ld", min_software_gain, max_software_gain);
 		return;
 	}
 
 	syslog(LOG_INFO,
 	       "Use software gain for %s with min %ld because it is specified"
-	       " in UCM",
-	       input->base.name, min_software_gain);
+	       " in UCM", input->base.name, min_software_gain);
 	input->base.min_software_gain = min_software_gain;
 }
 
@@ -1127,7 +1125,7 @@
 		return;
 
 	rc = ucm_get_default_node_gain(aio->ucm, input->base.name,
-				       &default_node_gain);
+					 &default_node_gain);
 	if (rc)
 		return;
 
@@ -1135,7 +1133,8 @@
 }
 
 static void check_auto_unplug_output_node(struct alsa_io *aio,
-					  struct cras_ionode *node, int plugged)
+					  struct cras_ionode *node,
+					  int plugged)
 {
 	struct cras_ionode *tmp;
 
@@ -1144,13 +1143,17 @@
 
 	/* Auto unplug internal speaker if any output node has been created */
 	if (!strcmp(node->name, INTERNAL_SPEAKER) && plugged) {
-		DL_FOREACH (aio->base.nodes, tmp)
+		DL_FOREACH(aio->base.nodes, tmp)
 			if (tmp->plugged && (tmp != node))
-				cras_iodev_set_node_plugged(node, 0);
+				cras_iodev_set_node_attr(node,
+							 IONODE_ATTR_PLUGGED,
+							 0);
 	} else {
-		DL_FOREACH (aio->base.nodes, tmp) {
+		DL_FOREACH(aio->base.nodes, tmp) {
 			if (!strcmp(tmp->name, INTERNAL_SPEAKER))
-				cras_iodev_set_node_plugged(tmp, !plugged);
+				cras_iodev_set_node_attr(tmp,
+							 IONODE_ATTR_PLUGGED,
+							 !plugged);
 		}
 	}
 }
@@ -1177,20 +1180,20 @@
 	}
 	output->base.dev = &aio->base;
 	output->base.idx = aio->next_ionode_index++;
-	output->base.stable_id =
-		SuperFastHash(name, strlen(name), aio->base.info.stable_id);
-	if (aio->ucm)
-		output->base.dsp_name =
-			ucm_get_dsp_name_for_dev(aio->ucm, name);
-
-	if (strcmp(name, "SCO Line Out") == 0)
-		output->base.is_sco_pcm = 1;
+	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
+						   );
 	output->mixer_output = cras_output;
 
 	/* Volume curve. */
 	output->volume_curve = cras_card_config_get_volume_curve_for_control(
-		aio->config,
-		name ? name : cras_alsa_mixer_get_control_name(cras_output));
+			aio->config,
+			name ? name
+			     : cras_alsa_mixer_get_control_name(cras_output));
 
 	strncpy(output->base.name, name, sizeof(output->base.name) - 1);
 	set_node_initial_state(&output->base, aio->card_type);
@@ -1203,7 +1206,7 @@
 }
 
 static void new_output_by_mixer_control(struct mixer_control *cras_output,
-					void *callback_arg)
+				        void *callback_arg)
 {
 	struct alsa_io *aio = (struct alsa_io *)callback_arg;
 	char node_name[CRAS_IODEV_NAME_BUFFER_SIZE];
@@ -1211,7 +1214,7 @@
 
 	ctl_name = cras_alsa_mixer_get_control_name(cras_output);
 	if (!ctl_name)
-		return;
+	        return;
 
 	if (aio->card_type == ALSA_CARD_TYPE_USB) {
 		if (snprintf(node_name, sizeof(node_name), "%s: %s",
@@ -1224,7 +1227,8 @@
 }
 
 static void check_auto_unplug_input_node(struct alsa_io *aio,
-					 struct cras_ionode *node, int plugged)
+					 struct cras_ionode *node,
+					 int plugged)
 {
 	struct cras_ionode *tmp;
 	if (!auto_unplug_input_node(aio))
@@ -1233,19 +1237,22 @@
 	/* Auto unplug internal mic if any input node has already
 	 * been created */
 	if (!strcmp(node->name, INTERNAL_MICROPHONE) && plugged) {
-		DL_FOREACH (aio->base.nodes, tmp)
+		DL_FOREACH(aio->base.nodes, tmp)
 			if (tmp->plugged && (tmp != node))
-				cras_iodev_set_node_plugged(node, 0);
+				cras_iodev_set_node_attr(node,
+							 IONODE_ATTR_PLUGGED,
+							 0);
 	} else {
-		DL_FOREACH (aio->base.nodes, tmp)
+		DL_FOREACH(aio->base.nodes, tmp)
 			if (!strcmp(tmp->name, INTERNAL_MICROPHONE))
-				cras_iodev_set_node_plugged(tmp, !plugged);
+				cras_iodev_set_node_attr(tmp,
+							 IONODE_ATTR_PLUGGED,
+							 !plugged);
 	}
 }
 
 static struct alsa_input_node *new_input(struct alsa_io *aio,
-					 struct mixer_control *cras_input,
-					 const char *name)
+		struct mixer_control *cras_input, const char *name)
 {
 	struct cras_iodev *iodev = &aio->base;
 	struct alsa_input_node *input;
@@ -1259,10 +1266,12 @@
 	}
 	input->base.dev = &aio->base;
 	input->base.idx = aio->next_ionode_index++;
-	input->base.stable_id =
-		SuperFastHash(name, strlen(name), aio->base.info.stable_id);
-	if (strcmp(name, "SCO Line In") == 0)
-		input->base.is_sco_pcm = 1;
+	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);
 	input->mixer_input = cras_input;
 	strncpy(input->base.name, name, sizeof(input->base.name) - 1);
 	set_node_initial_state(&input->base, aio->card_type);
@@ -1284,7 +1293,7 @@
 
 		/* Check if channel map is specified in UCM. */
 		input->channel_layout = (int8_t *)malloc(
-			CRAS_CH_MAX * sizeof(*input->channel_layout));
+				CRAS_CH_MAX * sizeof(*input->channel_layout));
 		err = ucm_get_capture_chmap_for_dev(aio->ucm, name,
 						    input->channel_layout);
 		if (err) {
@@ -1297,12 +1306,11 @@
 			iodev->post_close_iodev_hook =
 				cras_iodev_list_resume_hotword_stream;
 		}
-
-		input->base.dsp_name = ucm_get_dsp_name_for_dev(aio->ucm, name);
 	}
 
 	cras_iodev_add_node(&aio->base, &input->base);
-	check_auto_unplug_input_node(aio, &input->base, input->base.plugged);
+	check_auto_unplug_input_node(aio, &input->base,
+				     input->base.plugged);
 	return input;
 }
 
@@ -1314,7 +1322,7 @@
 	const char *ctl_name = cras_alsa_mixer_get_control_name(cras_input);
 
 	if (aio->card_type == ALSA_CARD_TYPE_USB) {
-		int ret = snprintf(node_name, sizeof(node_name), "%s: %s",
+		int ret = snprintf(node_name , sizeof(node_name), "%s: %s",
 				   aio->base.info.name, ctl_name);
 		// Truncation is OK, but add a check to make the compiler happy.
 		if (ret == sizeof(node_name))
@@ -1328,16 +1336,16 @@
 /*
  * Finds the output node associated with the jack. Returns NULL if not found.
  */
-static struct alsa_output_node *
-get_output_node_from_jack(struct alsa_io *aio,
-			  const struct cras_alsa_jack *jack)
+static struct alsa_output_node *get_output_node_from_jack(
+		struct alsa_io *aio, const struct cras_alsa_jack *jack)
 {
 	struct mixer_control *mixer_output;
 	struct cras_ionode *node = NULL;
 	struct alsa_output_node *aout = NULL;
 
 	/* Search by jack first. */
-	DL_SEARCH_SCALAR_WITH_CAST(aio->base.nodes, node, aout, jack, jack);
+	DL_SEARCH_SCALAR_WITH_CAST(aio->base.nodes, node, aout,
+				   jack, jack);
 	if (aout)
 		return aout;
 
@@ -1346,13 +1354,13 @@
 	if (mixer_output == NULL)
 		return NULL;
 
-	DL_SEARCH_SCALAR_WITH_CAST(aio->base.nodes, node, aout, mixer_output,
-				   mixer_output);
+	DL_SEARCH_SCALAR_WITH_CAST(aio->base.nodes, node, aout,
+				   mixer_output, mixer_output);
 	return aout;
 }
 
-static struct alsa_input_node *
-get_input_node_from_jack(struct alsa_io *aio, const struct cras_alsa_jack *jack)
+static struct alsa_input_node *get_input_node_from_jack(
+		struct alsa_io *aio, const struct cras_alsa_jack *jack)
 {
 	struct mixer_control *mixer_input;
 	struct cras_ionode *node = NULL;
@@ -1360,13 +1368,13 @@
 
 	mixer_input = cras_alsa_jack_get_mixer_input(jack);
 	if (mixer_input == NULL) {
-		DL_SEARCH_SCALAR_WITH_CAST(aio->base.nodes, node, ain, jack,
-					   jack);
+		DL_SEARCH_SCALAR_WITH_CAST(aio->base.nodes, node, ain,
+					   jack, jack);
 		return ain;
 	}
 
-	DL_SEARCH_SCALAR_WITH_CAST(aio->base.nodes, node, ain, mixer_input,
-				   mixer_input);
+	DL_SEARCH_SCALAR_WITH_CAST(aio->base.nodes, node, ain,
+				   mixer_input, mixer_input);
 	return ain;
 }
 
@@ -1386,26 +1394,32 @@
 }
 
 /*
- * Returns the dsp name specified in the ucm config. If there is a dsp name
- * specified for the active node, use that. Otherwise use the default dsp name
- * for the alsa_io device.
+ * Returns the dsp name specified in the ucm config. If there is a dsp
+ * name specified for the jack of the active node, use that. Otherwise
+ * use the default dsp name for the alsa_io device.
  */
 static const char *get_active_dsp_name(struct alsa_io *aio)
 {
 	struct cras_ionode *node = aio->base.active_node;
+	const struct cras_alsa_jack *jack;
 
 	if (node == NULL)
 		return NULL;
 
-	return node->dsp_name ?: aio->dsp_name_default;
+	if (aio->base.direction == CRAS_STREAM_OUTPUT)
+		jack = ((struct alsa_output_node *) node)->jack;
+	else
+		jack = ((struct alsa_input_node *) node)->jack;
+
+	return cras_alsa_jack_get_dsp_name(jack) ? : aio->dsp_name_default;
 }
 
 /*
  * Creates volume curve for the node associated with given jack.
  */
-static struct cras_volume_curve *
-create_volume_curve_for_jack(const struct cras_card_config *config,
-			     const struct cras_alsa_jack *jack)
+static struct cras_volume_curve *create_volume_curve_for_jack(
+		const struct cras_card_config *config,
+		const struct cras_alsa_jack *jack)
 {
 	struct cras_volume_curve *curve;
 	const char *name;
@@ -1429,7 +1443,8 @@
  * Callback that is called when an output jack is plugged or unplugged.
  */
 static void jack_output_plug_event(const struct cras_alsa_jack *jack,
-				   int plugged, void *arg)
+				    int plugged,
+				    void *arg)
 {
 	struct alsa_io *aio;
 	struct alsa_output_node *node;
@@ -1469,8 +1484,8 @@
 		/* If we already have the node, associate with the jack. */
 		node->jack = jack;
 		if (node->volume_curve == NULL)
-			node->volume_curve =
-				create_volume_curve_for_jack(aio->config, jack);
+			node->volume_curve = create_volume_curve_for_jack(
+					aio->config, jack);
 	}
 
 	syslog(LOG_DEBUG, "%s plugged: %d, %s", jack_name, plugged,
@@ -1485,7 +1500,7 @@
 		drop_node_name(&node->base);
 #endif
 
-	cras_iodev_set_node_plugged(&node->base, plugged);
+	cras_iodev_set_node_attr(&node->base, IONODE_ATTR_PLUGGED, plugged);
 
 	check_auto_unplug_output_node(aio, &node->base, plugged);
 }
@@ -1494,7 +1509,8 @@
  * Callback that is called when an input jack is plugged or unplugged.
  */
 static void jack_input_plug_event(const struct cras_alsa_jack *jack,
-				  int plugged, void *arg)
+				  int plugged,
+				  void *arg)
 {
 	struct alsa_io *aio;
 	struct alsa_input_node *node;
@@ -1534,7 +1550,7 @@
 		node->jack = jack;
 	}
 
-	cras_iodev_set_node_plugged(&node->base, plugged);
+	cras_iodev_set_node_attr(&node->base, IONODE_ATTR_PLUGGED, plugged);
 
 	check_auto_unplug_input_node(aio, &node->base, plugged);
 }
@@ -1543,43 +1559,58 @@
  * Sets the name of the given iodev, using the name and index of the card
  * combined with the device index and direction.
  */
-static void set_iodev_name(struct cras_iodev *dev, const char *card_name,
-			   const char *dev_name, size_t card_index,
+static void set_iodev_name(struct cras_iodev *dev,
+			   const char *card_name,
+			   const char *dev_name,
+			   size_t card_index,
 			   size_t device_index,
-			   enum CRAS_ALSA_CARD_TYPE card_type, size_t usb_vid,
-			   size_t usb_pid, char *usb_serial_number)
+			   enum CRAS_ALSA_CARD_TYPE card_type,
+			   size_t usb_vid,
+			   size_t usb_pid,
+			   char *usb_serial_number)
 {
-	snprintf(dev->info.name, sizeof(dev->info.name), "%s: %s:%zu,%zu",
-		 card_name, dev_name, card_index, device_index);
+	snprintf(dev->info.name,
+		 sizeof(dev->info.name),
+		 "%s: %s:%zu,%zu",
+		 card_name,
+		 dev_name,
+		 card_index,
+		 device_index);
 	dev->info.name[ARRAY_SIZE(dev->info.name) - 1] = '\0';
 	syslog(LOG_DEBUG, "Add device name=%s", dev->info.name);
 
-	dev->info.stable_id =
-		SuperFastHash(card_name, strlen(card_name), strlen(card_name));
-	dev->info.stable_id =
-		SuperFastHash(dev_name, strlen(dev_name), dev->info.stable_id);
+	dev->info.stable_id = SuperFastHash(card_name,
+					    strlen(card_name),
+					    strlen(card_name));
+	dev->info.stable_id = SuperFastHash(dev_name,
+					    strlen(dev_name),
+					    dev->info.stable_id);
 
 	switch (card_type) {
 	case ALSA_CARD_TYPE_INTERNAL:
 		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 =
-			SuperFastHash((const char *)&usb_vid, sizeof(usb_vid),
-				      dev->info.stable_id);
-		dev->info.stable_id =
-			SuperFastHash((const char *)&usb_pid, sizeof(usb_pid),
-				      dev->info.stable_id);
-		dev->info.stable_id = SuperFastHash(usb_serial_number,
-						    strlen(usb_serial_number),
+		dev->info.stable_id = SuperFastHash((const char *)&usb_vid,
+						    sizeof(usb_vid),
 						    dev->info.stable_id);
+		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);
 		break;
 	default:
+		dev->info.stable_id_new = dev->info.stable_id;
 		break;
 	}
-	syslog(LOG_DEBUG, "Stable ID=%08x", dev->info.stable_id);
+	syslog(LOG_DEBUG, "Stable ID=%08x, New Stable ID=%08x",
+	       dev->info.stable_id, dev->info.stable_id_new);
 }
 
 static int get_fixed_rate(struct alsa_io *aio)
@@ -1617,7 +1648,8 @@
 	free(iodev->supported_formats);
 	iodev->supported_formats = NULL;
 
-	err = cras_alsa_fill_properties(aio->handle, &iodev->supported_rates,
+	err = cras_alsa_fill_properties(aio->handle,
+					&iodev->supported_rates,
 					&iodev->supported_channel_counts,
 					&iodev->supported_formats);
 	if (err)
@@ -1628,8 +1660,8 @@
 		fixed_rate = get_fixed_rate(aio);
 		if (fixed_rate > 0) {
 			free(iodev->supported_rates);
-			iodev->supported_rates = (size_t *)malloc(
-				2 * sizeof(iodev->supported_rates[0]));
+			iodev->supported_rates = (size_t*)malloc(
+					2 * sizeof(iodev->supported_rates[0]));
 			iodev->supported_rates[0] = fixed_rate;
 			iodev->supported_rates[1] = 0;
 		}
@@ -1644,7 +1676,7 @@
 {
 	struct cras_ionode *ionode;
 
-	DL_FOREACH (aio->base.nodes, ionode) {
+	DL_FOREACH(aio->base.nodes, ionode) {
 		struct alsa_output_node *aout;
 		const struct cras_volume_curve *curve;
 
@@ -1702,31 +1734,16 @@
 	return 0;
 }
 
-/*
- * Move appl_ptr to min_buffer_level + min_cb_level frames ahead of hw_ptr
- * when resuming from free run.
- */
-static int adjust_appl_ptr_for_leaving_free_run(struct cras_iodev *odev)
+static int adjust_appl_ptr(struct cras_iodev *odev)
 {
 	struct alsa_io *aio = (struct alsa_io *)odev;
-	snd_pcm_uframes_t ahead;
 
-	ahead = odev->min_buffer_level + odev->min_cb_level;
-	return cras_alsa_resume_appl_ptr(aio->handle, ahead);
-}
-
-/*
- * Move appl_ptr to min_buffer_level + min_cb_level * 1.5 frames ahead of
- * hw_ptr when adjusting appl_ptr from underrun.
- */
-static int adjust_appl_ptr_for_underrun(struct cras_iodev *odev)
-{
-	struct alsa_io *aio = (struct alsa_io *)odev;
-	snd_pcm_uframes_t ahead;
-
-	ahead = odev->min_buffer_level + odev->min_cb_level +
-		odev->min_cb_level / 2;
-	return cras_alsa_resume_appl_ptr(aio->handle, ahead);
+	/* Move appl_ptr to min_buffer_level + min_cb_level frames ahead of
+	 * hw_ptr when resuming from free run or adjusting appl_ptr from
+	 * underrun. */
+	return cras_alsa_resume_appl_ptr(
+			aio->handle,
+			odev->min_buffer_level + odev->min_cb_level);
 }
 
 /* This function is for leaving no-stream state but still not in free run yet.
@@ -1745,7 +1762,7 @@
 	 * subtract min_buffer_level. */
 	valid_sample = 0;
 	rc = odev->frames_queued(odev, &hw_tstamp);
-	if (rc < 0)
+	if(rc < 0)
 		return rc;
 	real_hw_level = rc;
 
@@ -1784,7 +1801,7 @@
 	if (rc)
 		return rc;
 	/* Adjust appl_ptr to leave underrun. */
-	return adjust_appl_ptr_for_underrun(odev);
+	return adjust_appl_ptr(odev);
 }
 
 static int possibly_enter_free_run(struct cras_iodev *odev)
@@ -1792,16 +1809,17 @@
 	struct alsa_io *aio = (struct alsa_io *)odev;
 	int rc;
 	unsigned int real_hw_level, fr_to_write;
+	unsigned int target_hw_level = odev->min_cb_level * 2 + odev->min_buffer_level;
 	struct timespec hw_tstamp;
 
-	if (aio->free_running)
+	if (aio->is_free_running)
 		return 0;
 
 	/* Check if all valid samples are played. If all valid samples are played,
 	 * fill whole buffer with zeros. The real_hw_level is the real hw_level in
 	 * device buffer. It doesn't subtract min_buffer_level.*/
 	rc = odev->frames_queued(odev, &hw_tstamp);
-	if (rc < 0)
+	if(rc < 0)
 		return rc;
 	real_hw_level = rc;
 
@@ -1810,27 +1828,27 @@
 		rc = odev->output_underrun(odev);
 		if (rc < 0)
 			return rc;
-		aio->free_running = 1;
+		aio->is_free_running = 1;
 		return 0;
 	}
 
-	if (real_hw_level <= aio->filled_zeros_for_draining ||
-	    real_hw_level == 0) {
+	if (real_hw_level <= aio->filled_zeros_for_draining || real_hw_level == 0) {
 		rc = fill_whole_buffer_with_zeros(odev);
 		if (rc < 0)
 			return rc;
-		aio->free_running = 1;
+		aio->is_free_running = 1;
 		return 0;
 	}
 
-	/* Fill zeros to drain valid samples. */
-	fr_to_write = MIN(cras_time_to_frames(&no_stream_fill_zeros_duration,
-					      odev->format->frame_rate),
-			  odev->buffer_size - real_hw_level);
-	rc = cras_iodev_fill_odev_zeros(odev, fr_to_write);
-	if (rc)
-		return rc;
-	aio->filled_zeros_for_draining += fr_to_write;
+	/* Fill some zeros to drain valid samples. */
+	fr_to_write = odev->buffer_size - real_hw_level;
+	if (real_hw_level < target_hw_level) {
+		fr_to_write = MIN(target_hw_level - real_hw_level, fr_to_write);
+		rc = cras_iodev_fill_odev_zeros(odev, fr_to_write);
+		if (rc)
+			return rc;
+		aio->filled_zeros_for_draining += fr_to_write;
+	}
 
 	return 0;
 }
@@ -1840,8 +1858,8 @@
 	struct alsa_io *aio = (struct alsa_io *)odev;
 	int rc;
 
-	if (aio->free_running)
-		rc = adjust_appl_ptr_for_leaving_free_run(odev);
+	if (aio->is_free_running)
+		rc = adjust_appl_ptr(odev);
 	else
 		rc = adjust_appl_ptr_samples_remaining(odev);
 	if (rc) {
@@ -1849,7 +1867,7 @@
 		       odev->info.name, rc);
 		return rc;
 	}
-	aio->free_running = 0;
+	aio->is_free_running = 0;
 	aio->filled_zeros_for_draining = 0;
 
 	return 0;
@@ -1869,11 +1887,16 @@
 		return leave_free_run(odev);
 }
 
-static int is_free_running(const struct cras_iodev *odev)
+static int output_should_wake(const struct cras_iodev *odev)
 {
 	struct alsa_io *aio = (struct alsa_io *)odev;
-
-	return aio->free_running;
+	if (aio->is_free_running)
+		return 0;
+	else
+		return ((cras_iodev_state(odev) ==
+					CRAS_IODEV_STATE_NO_STREAM_RUN) ||
+		        (cras_iodev_state(odev) ==
+					CRAS_IODEV_STATE_NORMAL_RUN));
 }
 
 static unsigned int get_num_underruns(const struct cras_iodev *iodev)
@@ -1890,63 +1913,37 @@
 
 static void set_default_hotword_model(struct cras_iodev *iodev)
 {
-	const char *default_models[] = { "en_all", "en_us" };
+	const char *default_model = "en_us";
 	cras_node_id_t node_id;
-	unsigned i;
 
 	if (!iodev->active_node ||
-	    iodev->active_node->type != CRAS_NODE_TYPE_HOTWORD)
+	     iodev->active_node->type != CRAS_NODE_TYPE_HOTWORD)
 		return;
 
 	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 */
-	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,
-			    struct timespec *tstamp)
-{
-	struct alsa_io *aio = (struct alsa_io *)odev;
-	int rc;
-	unsigned int real_hw_level;
-
-	/*
-	 * Get the amount of valid frames which haven't been played yet.
-	 * The real_hw_level is the real hw_level in device buffer. It doesn't
-	 * subtract min_buffer_level.
-	 */
-	if (aio->free_running) {
-		clock_gettime(CLOCK_MONOTONIC_RAW, tstamp);
-		return 0;
-	}
-
-	rc = odev->frames_queued(odev, tstamp);
-	if (rc < 0)
-		return rc;
-	real_hw_level = rc;
-
-	if (real_hw_level > aio->filled_zeros_for_draining)
-		return real_hw_level - aio->filled_zeros_for_draining;
-
-	return 0;
+	cras_iodev_list_set_hotword_model(node_id, default_model);
 }
 
 /*
  * Exported Interface.
  */
 
-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 *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 alsa_io *aio;
 	struct cras_iodev *iodev;
@@ -1965,7 +1962,6 @@
 	aio->is_first = is_first;
 	aio->handle = NULL;
 	aio->num_severe_underruns = 0;
-	aio->jack_always_plugged = 0;
 	if (dev_name) {
 		aio->dev_name = strdup(dev_name);
 		if (!aio->dev_name)
@@ -1976,12 +1972,15 @@
 		if (!aio->dev_id)
 			goto cleanup_iodev;
 	}
-	aio->free_running = 0;
+	aio->is_free_running = 0;
 	aio->filled_zeros_for_draining = 0;
 	aio->dev = (char *)malloc(MAX_ALSA_DEV_NAME_LENGTH);
 	if (aio->dev == NULL)
 		goto cleanup_iodev;
-	snprintf(aio->dev, MAX_ALSA_DEV_NAME_LENGTH, "hw:%zu,%zu", card_index,
+	snprintf(aio->dev,
+		 MAX_ALSA_DEV_NAME_LENGTH,
+		 "hw:%zu,%zu",
+		 card_index,
 		 device_index);
 
 	if (direction == CRAS_STREAM_INPUT) {
@@ -2009,10 +2008,9 @@
 	iodev->set_hotword_model = set_hotword_model;
 	iodev->get_hotword_models = get_hotword_models;
 	iodev->no_stream = no_stream;
-	iodev->is_free_running = is_free_running;
+	iodev->output_should_wake = output_should_wake;
 	iodev->get_num_underruns = get_num_underruns;
 	iodev->get_num_severe_underruns = get_num_severe_underruns;
-	iodev->get_valid_frames = get_valid_frames;
 	iodev->set_swap_mode_for_node = cras_iodev_dsp_set_swap_mode_for_node;
 
 	if (card_type == ALSA_CARD_TYPE_USB)
@@ -2026,19 +2024,19 @@
 	aio->config = config;
 	if (direction == CRAS_STREAM_OUTPUT) {
 		aio->default_volume_curve =
-			cras_card_config_get_volume_curve_for_control(
-				config, "Default");
+				cras_card_config_get_volume_curve_for_control(
+						config, "Default");
 		if (aio->default_volume_curve == NULL)
 			aio->default_volume_curve =
-				cras_volume_curve_create_default();
+					cras_volume_curve_create_default();
 	}
 	aio->ucm = ucm;
 	if (ucm) {
 		unsigned int level;
 		int rc;
 
-		aio->dsp_name_default =
-			ucm_get_dsp_name_default(ucm, direction);
+		aio->dsp_name_default = ucm_get_dsp_name_default(ucm,
+								 direction);
 		/* Set callback for swap mode if it is supported
 		 * in ucm modifier. */
 		if (ucm_swap_mode_exists(ucm))
@@ -2049,18 +2047,27 @@
 		if (!rc && direction == CRAS_STREAM_OUTPUT)
 			iodev->min_buffer_level = level;
 
-		aio->enable_htimestamp = ucm_get_enable_htimestamp_flag(ucm);
+		aio->enable_htimestamp =
+			ucm_get_enable_htimestamp_flag(ucm);
 	}
 
 	set_iodev_name(iodev, card_name, dev_name, card_index, device_index,
 		       card_type, usb_vid, usb_pid, usb_serial_number);
 
-	aio->jack_list = cras_alsa_jack_list_create(
-		card_index, card_name, device_index, is_first, mixer, ucm, hctl,
-		direction,
-		direction == CRAS_STREAM_OUTPUT ? jack_output_plug_event :
-						  jack_input_plug_event,
-		aio);
+	aio->jack_list =
+		cras_alsa_jack_list_create(
+			card_index,
+			card_name,
+			device_index,
+			is_first,
+			mixer,
+			ucm,
+			hctl,
+			direction,
+			direction == CRAS_STREAM_OUTPUT ?
+				     jack_output_plug_event :
+				     jack_input_plug_event,
+			aio);
 	if (!aio->jack_list)
 		goto cleanup_iodev;
 
@@ -2103,11 +2110,11 @@
 	/* Create output nodes for mixer controls, such as Headphone
 	 * and Speaker, only for the first device. */
 	if (direction == CRAS_STREAM_OUTPUT && is_first)
-		cras_alsa_mixer_list_outputs(mixer, new_output_by_mixer_control,
-					     aio);
+		cras_alsa_mixer_list_outputs(mixer,
+				new_output_by_mixer_control, aio);
 	else if (direction == CRAS_STREAM_INPUT && is_first)
-		cras_alsa_mixer_list_inputs(mixer, new_input_by_mixer_control,
-					    aio);
+		cras_alsa_mixer_list_inputs(mixer,
+				new_input_by_mixer_control, aio);
 
 	err = cras_alsa_jack_list_find_jacks_by_name_matching(aio->jack_list);
 	if (err)
@@ -2124,9 +2131,10 @@
 	 * node creation can be supressed by UCM flags for platforms
 	 * which really don't have an internal device. */
 	if ((direction == CRAS_STREAM_OUTPUT) &&
-	    !no_create_default_output_node(aio)) {
+			!no_create_default_output_node(aio)) {
 		if (first_internal_device(aio) &&
-		    !has_node(aio, INTERNAL_SPEAKER) && !has_node(aio, HDMI)) {
+		    !has_node(aio, INTERNAL_SPEAKER) &&
+		    !has_node(aio, HDMI)) {
 			if (strstr(aio->base.info.name, HDMI))
 				new_output(aio, NULL, HDMI);
 			else
@@ -2135,7 +2143,7 @@
 			new_output(aio, NULL, DEFAULT);
 		}
 	} else if ((direction == CRAS_STREAM_INPUT) &&
-		   !no_create_default_input_node(aio)) {
+			!no_create_default_input_node(aio)) {
 		if (first_internal_device(aio) &&
 		    !has_node(aio, INTERNAL_MICROPHONE))
 			new_input(aio, NULL, INTERNAL_MICROPHONE);
@@ -2152,14 +2160,16 @@
 		build_softvol_scalers(aio);
 
 	/* Set the active node as the best node we have now. */
-	alsa_iodev_set_active_node(&aio->base, first_plugged_node(&aio->base),
+	alsa_iodev_set_active_node(&aio->base,
+				   first_plugged_node(&aio->base),
 				   0);
 
 	/* Set plugged for the first USB device per card when it appears if
 	 * there is no jack reporting plug status. */
 	if (aio->card_type == ALSA_CARD_TYPE_USB && is_first &&
-	    !get_jack_from_node(iodev->active_node))
-		cras_iodev_set_node_plugged(iodev->active_node, 1);
+			!get_jack_from_node(iodev->active_node))
+		cras_iodev_set_node_attr(iodev->active_node,
+					 IONODE_ATTR_PLUGGED, 1);
 
 	set_default_hotword_model(iodev);
 
@@ -2203,12 +2213,9 @@
 			return -ENOMEM;
 	}
 
-	if (section->jack_type && !strcmp(section->jack_type, "always"))
-		aio->jack_always_plugged = 1;
-
 	/* Find any jack controls for this device. */
-	rc = cras_alsa_jack_list_add_jack_for_section(aio->jack_list, section,
-						      &jack);
+	rc = cras_alsa_jack_list_add_jack_for_section(
+					aio->jack_list, section, &jack);
 	if (rc)
 		return rc;
 
@@ -2242,18 +2249,16 @@
 		build_softvol_scalers(aio);
 
 	/* Set the active node as the best node we have now. */
-	alsa_iodev_set_active_node(&aio->base, first_plugged_node(&aio->base),
+	alsa_iodev_set_active_node(&aio->base,
+				   first_plugged_node(&aio->base),
 				   0);
 
-	/*
-	 * Set plugged for the USB device per card when it appears if
-	 * there is no jack reporting plug status and the jack is set
-	 * to be always plugged.
-	 */
-	if (aio->card_type == ALSA_CARD_TYPE_USB && aio->jack_always_plugged &&
-	    !get_jack_from_node(iodev->active_node)) {
-		cras_iodev_set_node_plugged(iodev->active_node, 1);
-	}
+	/* Set plugged for the first USB device per card when it appears if
+	 * there is no jack reporting plug status. */
+	if (aio->card_type == ALSA_CARD_TYPE_USB && aio->is_first &&
+			!get_jack_from_node(iodev->active_node))
+		cras_iodev_set_node_attr(iodev->active_node,
+					 IONODE_ATTR_PLUGGED, 1);
 
 	set_default_hotword_model(iodev);
 }
@@ -2263,6 +2268,7 @@
 	struct alsa_io *aio = (struct alsa_io *)iodev;
 	int rc;
 
+	cras_alsa_jack_list_destroy(aio->jack_list);
 	if (iodev->direction == CRAS_STREAM_INPUT)
 		rc = cras_iodev_list_rm_input(iodev);
 	else
@@ -2274,7 +2280,6 @@
 	}
 
 	/* Free resources when device successfully removed. */
-	cras_alsa_jack_list_destroy(aio->jack_list);
 	free_alsa_iodev_resources(aio);
 	cras_volume_curve_destroy(aio->default_volume_curve);
 	free(iodev);
@@ -2304,8 +2309,9 @@
 	 * active mixer output and mute all others, otherwise just set
 	 * the node as active and set the volume curve. */
 	if (mixer) {
+		set_alsa_mute_control(aio, 1);
 		/* Unmute the active mixer output, mute all others. */
-		DL_FOREACH (aio->base.nodes, node) {
+		DL_FOREACH(aio->base.nodes, node) {
 			output = (struct alsa_output_node *)node;
 			if (output->mixer_output)
 				cras_alsa_mixer_set_output_active_state(
diff --git a/cras/src/server/cras_alsa_io.h b/cras/src/server/cras_alsa_io.h
index 9bc0c1f..0b3e548 100644
--- a/cras/src/server/cras_alsa_io.h
+++ b/cras/src/server/cras_alsa_io.h
@@ -36,15 +36,21 @@
  * Returns:
  *    A pointer to the newly created iodev if successful, NULL otherwise.
  */
-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 *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);
 
 /* Complete initializeation of this iodev with the legacy method.
  * Add IO nodes and find jacks for this iodev with magic sauce, then choose
diff --git a/cras/src/server/cras_alsa_jack.c b/cras/src/server/cras_alsa_jack.c
index a16e94e..b74af25 100644
--- a/cras/src/server/cras_alsa_jack.c
+++ b/cras/src/server/cras_alsa_jack.c
@@ -82,9 +82,9 @@
  *    has the same mixer_control as the jack.
  */
 struct cras_alsa_jack {
-	unsigned is_gpio; /* !0 -> 'gpio' valid
-			   *  0 -> 'elem' valid
-			   */
+	unsigned is_gpio;	/* !0 -> 'gpio' valid
+				 *  0 -> 'elem' valid
+				 */
 	union {
 		snd_hctl_elem_t *elem;
 		struct cras_gpio_jack gpio;
@@ -95,7 +95,8 @@
 	struct mixer_control *mixer_output;
 	struct mixer_control *mixer_input;
 	char *ucm_device;
-	const char *override_type_name;
+	const char *dsp_name;
+	const char* override_type_name;
 	const char *edid_file;
 	struct cras_timer *display_info_timer;
 	unsigned int display_info_retries;
@@ -147,13 +148,13 @@
  * Local Helpers.
  */
 
-#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 sys_input_get_switch_state(int fd, unsigned sw, unsigned *state)
 {
@@ -183,7 +184,8 @@
 	return jack;
 }
 
-static void cras_free_jack(struct cras_alsa_jack *jack, int rm_select_fd)
+static void cras_free_jack(struct cras_alsa_jack *jack,
+			   int rm_select_fd)
 {
 	if (!jack)
 		return;
@@ -211,6 +213,7 @@
 		snd_hctl_elem_set_callback(jack->elem, NULL);
 
 	free((void *)jack->override_type_name);
+	free((void *)jack->dsp_name);
 	free(jack);
 }
 
@@ -260,7 +263,8 @@
 }
 
 static int get_jack_edid_monitor_name(const struct cras_alsa_jack *jack,
-				      char *buf, unsigned int buf_size)
+				      char *buf,
+				      unsigned int buf_size)
 {
 	uint8_t edid[EEDID_SIZE];
 
@@ -308,8 +312,8 @@
 	}
 	if (retry) {
 		jack->display_info_retries =
-			jack->is_gpio ? DISPLAY_INFO_GPIO_MAX_RETRIES :
-					DISPLAY_INFO_MAX_RETRIES;
+				jack->is_gpio ? DISPLAY_INFO_GPIO_MAX_RETRIES
+					      : DISPLAY_INFO_MAX_RETRIES;
 	}
 
 	if (!get_jack_current_state(jack))
@@ -335,12 +339,14 @@
 		goto report_jack_state;
 	}
 
-	jack->display_info_timer = cras_tm_create_timer(
-		tm, DISPLAY_INFO_RETRY_DELAY_MS, display_info_delay_cb, jack);
+	jack->display_info_timer = cras_tm_create_timer(tm,
+						DISPLAY_INFO_RETRY_DELAY_MS,
+						display_info_delay_cb, jack);
 	return;
 
 report_jack_state:
-	jack->jack_list->change_callback(jack, get_jack_current_state(jack),
+	jack->jack_list->change_callback(jack,
+					 get_jack_current_state(jack),
 					 jack->jack_list->callback_data);
 }
 
@@ -405,13 +411,12 @@
  * assume it should be associated with the first input device or the first
  * output device on the card.
  */
-static unsigned int
-gpio_jack_match_device(const struct cras_alsa_jack *jack,
-		       struct cras_alsa_jack_list *jack_list,
-		       const char *card_name,
-		       enum CRAS_STREAM_DIRECTION direction)
+static unsigned int gpio_jack_match_device(const struct cras_alsa_jack *jack,
+			struct cras_alsa_jack_list* jack_list,
+			const char *card_name,
+			enum CRAS_STREAM_DIRECTION direction)
 {
-	const char *target_device_name = NULL;
+	const char* target_device_name = NULL;
 	char current_device_name[CRAS_IODEV_NAME_BUFFER_SIZE];
 	unsigned int rc;
 
@@ -422,28 +427,31 @@
 
 	/* Look for device name specified in a device section of UCM. */
 	target_device_name = ucm_get_device_name_for_dev(
-		jack_list->ucm, jack->ucm_device, direction);
+				jack_list->ucm, jack->ucm_device, direction);
 
 	if (!target_device_name)
 		return jack_list->is_first_device;
 
-	syslog(LOG_DEBUG,
-	       "Matching GPIO jack, target device name: %s, "
+	syslog(LOG_DEBUG, "Matching GPIO jack, target device name: %s, "
 	       "current card name: %s, device index: %zu\n",
-	       target_device_name, card_name, jack_list->device_index);
+		target_device_name, card_name, jack_list->device_index);
 
 	/* Device name of format "hw:<card_name>,<device_index>", should fit
 	 * in the string of size CRAS_IODEV_NAME_BUFFER_SIZE.*/
-	snprintf(current_device_name, sizeof(current_device_name), "hw:%s,%zu",
-		 card_name, jack_list->device_index);
+	snprintf(current_device_name,
+		 sizeof(current_device_name),
+		 "hw:%s,%zu",
+		 card_name,
+		 jack_list->device_index);
 
 	rc = !strcmp(current_device_name, target_device_name);
-	free((void *)target_device_name);
+	free((void*)target_device_name);
 	return rc;
 }
 
 static int create_jack_for_gpio(struct cras_alsa_jack_list *jack_list,
-				const char *pathname, const char *dev_name,
+				const char *pathname,
+				const char *dev_name,
 				unsigned switch_event,
 				struct cras_alsa_jack **out_jack)
 {
@@ -498,11 +506,14 @@
 				   unsigned switch_event)
 {
 	struct cras_alsa_jack_list *jack_list = data->jack_list;
+	enum CRAS_STREAM_DIRECTION direction = jack_list->direction;
 	int r;
 
 	if (jack->ucm_device) {
 		jack->edid_file = ucm_get_edid_file_for_dev(jack_list->ucm,
 							    jack->ucm_device);
+		jack->dsp_name = ucm_get_dsp_name(
+			jack->jack_list->ucm, jack->ucm_device, direction);
 	}
 
 	r = sys_input_get_switch_state(jack->gpio.fd, switch_event,
@@ -511,8 +522,8 @@
 		cras_free_jack(jack, 0);
 		return -EIO;
 	}
-	r = cras_system_add_select_fd(jack->gpio.fd, gpio_switch_callback,
-				      jack);
+	r = cras_system_add_select_fd(jack->gpio.fd,
+				      gpio_switch_callback, jack);
 	if (r < 0) {
 		/* Not yet registered with system select. */
 		cras_free_jack(jack, 0);
@@ -523,7 +534,8 @@
 	if (!data->result_jack)
 		data->result_jack = jack;
 	else if (data->section)
-		syslog(LOG_ERR, "More than one jack for SectionDevice '%s'.",
+		syslog(LOG_ERR,
+		       "More than one jack for SectionDevice '%s'.",
 		       data->section->name);
 	return 0;
 }
@@ -535,7 +547,8 @@
  *   Returns 0 when a jack has been successfully added.
  */
 static int open_and_monitor_gpio(struct gpio_switch_list_data *data,
-				 const char *pathname, const char *dev_name,
+				 const char *pathname,
+				 const char *dev_name,
 				 unsigned switch_event)
 {
 	struct cras_alsa_jack *jack;
@@ -544,14 +557,16 @@
 	enum CRAS_STREAM_DIRECTION direction = jack_list->direction;
 	int r;
 
-	r = create_jack_for_gpio(jack_list, pathname, dev_name, switch_event,
-				 &jack);
+	r = create_jack_for_gpio(jack_list, pathname, dev_name,
+				 switch_event, &jack);
 	if (r != 0)
 		return r;
 
 	if (jack_list->ucm)
-		jack->ucm_device = ucm_get_dev_for_jack(
-			jack_list->ucm, jack->gpio.device_name, direction);
+		jack->ucm_device =
+			ucm_get_dev_for_jack(jack_list->ucm,
+					     jack->gpio.device_name,
+					     direction);
 
 	if (!gpio_jack_match_device(jack, jack_list, card_name, direction)) {
 		cras_free_jack(jack, 0);
@@ -562,11 +577,13 @@
 	    (strstr(jack->gpio.device_name, "Headphone") ||
 	     strstr(jack->gpio.device_name, "Headset")))
 		jack->mixer_output = cras_alsa_mixer_get_output_matching_name(
-			jack_list->mixer, "Headphone");
+			jack_list->mixer,
+			"Headphone");
 	else if (direction == CRAS_STREAM_OUTPUT &&
 		 strstr(jack->gpio.device_name, "HDMI"))
 		jack->mixer_output = cras_alsa_mixer_get_output_matching_name(
-			jack_list->mixer, "HDMI");
+			jack_list->mixer,
+			"HDMI");
 
 	if (jack->ucm_device && direction == CRAS_STREAM_INPUT) {
 		char *control_name;
@@ -575,15 +592,17 @@
 		if (control_name)
 			jack->mixer_input =
 				cras_alsa_mixer_get_input_matching_name(
-					jack_list->mixer, control_name);
+					jack_list->mixer,
+					control_name);
 	}
 
 	return cras_complete_gpio_jack(data, jack, switch_event);
 }
 
-static int
-open_and_monitor_gpio_with_section(struct gpio_switch_list_data *data,
-				   const char *pathname, unsigned switch_event)
+static int open_and_monitor_gpio_with_section(
+			struct gpio_switch_list_data *data,
+			const char *pathname,
+			unsigned switch_event)
 {
 	struct cras_alsa_jack *jack;
 	struct cras_alsa_jack_list *jack_list = data->jack_list;
@@ -604,10 +623,10 @@
 
 	if (direction == CRAS_STREAM_OUTPUT)
 		jack->mixer_output = cras_alsa_mixer_get_control_for_section(
-			jack_list->mixer, section);
+						jack_list->mixer, section);
 	else if (direction == CRAS_STREAM_INPUT)
 		jack->mixer_input = cras_alsa_mixer_get_control_for_section(
-			jack_list->mixer, section);
+						jack_list->mixer, section);
 
 	return cras_complete_gpio_jack(data, jack, switch_event);
 }
@@ -625,9 +644,9 @@
 					const char *dev_path,
 					const char *dev_name)
 {
-	static const int out_switches[] = { SW_HEADPHONE_INSERT,
-					    SW_LINEOUT_INSERT };
-	static const int in_switches[] = { SW_MICROPHONE_INSERT };
+	static const int out_switches[] = {SW_HEADPHONE_INSERT,
+					   SW_LINEOUT_INSERT};
+	static const int in_switches[] = {SW_MICROPHONE_INSERT};
 	int sw;
 	const int *switches = out_switches;
 	int num_switches = ARRAY_SIZE(out_switches);
@@ -637,7 +656,8 @@
 	if (data->section && data->section->jack_switch >= 0) {
 		switches = &data->section->jack_switch;
 		num_switches = 1;
-	} else if (data->jack_list->direction == CRAS_STREAM_INPUT) {
+	}
+	else if (data->jack_list->direction == CRAS_STREAM_INPUT) {
 		switches = in_switches;
 		num_switches = ARRAY_SIZE(in_switches);
 	}
@@ -646,13 +666,14 @@
 	 * be looking at, but stop trying if we run into another
 	 * type of error.
 	 */
-	for (sw = 0; (rc == 0 || rc == -EIO) && sw < num_switches; sw++) {
+	for (sw = 0; (rc == 0 || rc == -EIO)
+		     && sw < num_switches; sw++) {
 		if (data->section)
-			rc = open_and_monitor_gpio_with_section(data, dev_path,
-								switches[sw]);
+			rc = open_and_monitor_gpio_with_section(
+				data, dev_path, switches[sw]);
 		else
-			rc = open_and_monitor_gpio(data, dev_path, dev_name,
-						   switches[sw]);
+			rc = open_and_monitor_gpio(
+				data, dev_path, dev_name, switches[sw]);
 		if (rc != 0 && rc != -EIO)
 			success = 0;
 	}
@@ -663,7 +684,8 @@
 }
 
 static int gpio_switch_list_with_section(const char *dev_path,
-					 const char *dev_name, void *arg)
+					 const char *dev_name,
+					 void *arg)
 {
 	struct gpio_switch_list_data *data =
 		(struct gpio_switch_list_data *)arg;
@@ -703,7 +725,8 @@
 }
 
 static int gpio_switch_list_by_matching(const char *dev_path,
-					const char *dev_name, void *arg)
+					const char *dev_name,
+					void *arg)
 {
 	struct gpio_switch_list_data *data =
 		(struct gpio_switch_list_data *)arg;
@@ -714,7 +737,8 @@
 			/* Continue searching. */
 			return 0;
 		}
-	} else if (data->jack_list->direction == CRAS_STREAM_OUTPUT) {
+	}
+	else if (data->jack_list->direction == CRAS_STREAM_OUTPUT) {
 		if (!jack_matches_regex(dev_name, "^.*Headphone Jack$") &&
 		    !jack_matches_regex(dev_name, "^.*Headset Jack$") &&
 		    !jack_matches_regex(dev_name, "^.*HDMI Jack$")) {
@@ -760,9 +784,11 @@
 	data.rc = 0;
 
 	if (section)
-		gpio_switch_list_for_each(gpio_switch_list_with_section, &data);
+		gpio_switch_list_for_each(
+			gpio_switch_list_with_section, &data);
 	else
-		gpio_switch_list_for_each(gpio_switch_list_by_matching, &data);
+		gpio_switch_list_for_each(
+			gpio_switch_list_by_matching, &data);
 	if (result_jack)
 		*result_jack = data.result_jack;
 	return data.rc;
@@ -791,9 +817,11 @@
 	snd_hctl_elem_read(elem, elem_value);
 	name = snd_hctl_elem_get_name(elem);
 
-	syslog(LOG_DEBUG, "Jack %s %s", name,
-	       snd_ctl_elem_value_get_boolean(elem_value, 0) ? "plugged" :
-							       "unplugged");
+	syslog(LOG_DEBUG,
+	       "Jack %s %s",
+	       name,
+	       snd_ctl_elem_value_get_boolean(elem_value, 0) ? "plugged"
+							     : "unplugged");
 	jack_state_change_cb(jack, 1);
 	return 0;
 }
@@ -829,7 +857,7 @@
 
 /* Checks if the given control name is in the supplied list of possible jack
  * control base names. */
-static int is_jack_control_in_list(const char *const *list,
+static int is_jack_control_in_list(const char * const *list,
 				   unsigned int list_length,
 				   const char *control_name)
 {
@@ -847,8 +875,7 @@
 			enum CRAS_STREAM_DIRECTION direction)
 {
 	return jack_matches_regex(jack_name, direction == CRAS_STREAM_OUTPUT ?
-						     "^.* - Output Jack$" :
-						     "^.* - Input Jack$");
+				  "^.* - Output Jack$" : "^.* - Input Jack$");
 }
 
 /* Looks for any JACK controls.  Monitors any found controls for changes and
@@ -858,17 +885,17 @@
 	snd_hctl_elem_t *elem;
 	struct cras_alsa_jack *jack;
 	const char *name;
-	static const char *const output_jack_base_names[] = {
+	static const char * const output_jack_base_names[] = {
 		"Headphone Jack",
 		"Front Headphone Jack",
 		"HDMI/DP",
 		"Speaker Phantom Jack",
 	};
-	static const char *const input_jack_base_names[] = {
+	static const char * const input_jack_base_names[] = {
 		"Mic Jack",
 	};
 	static const char eld_control_name[] = "ELD";
-	const char *const *jack_names;
+	const char * const *jack_names;
 	unsigned int num_jack_names;
 
 	if (!jack_list->hctl) {
@@ -885,15 +912,14 @@
 	}
 
 	for (elem = snd_hctl_first_elem(jack_list->hctl); elem != NULL;
-	     elem = snd_hctl_elem_next(elem)) {
+			elem = snd_hctl_elem_next(elem)) {
 		snd_ctl_elem_iface_t iface;
 
 		iface = snd_hctl_elem_get_interface(elem);
 		if (iface != SND_CTL_ELEM_IFACE_CARD)
 			continue;
 		name = snd_hctl_elem_get_name(elem);
-		if (!is_jack_control_in_list(jack_names, num_jack_names,
-					     name) &&
+		if (!is_jack_control_in_list(jack_names, num_jack_names, name) &&
 		    !is_jack_uac2(name, jack_list->direction))
 			continue;
 		if (hctl_jack_device_index(name) != jack_list->device_index)
@@ -912,30 +938,35 @@
 		if (jack_list->direction == CRAS_STREAM_OUTPUT)
 			jack->mixer_output =
 				cras_alsa_mixer_get_output_matching_name(
-					jack_list->mixer, name);
+					jack_list->mixer,
+					name);
 		if (jack_list->ucm)
-			jack->ucm_device = ucm_get_dev_for_jack(
-				jack_list->ucm, name, jack_list->direction);
+			jack->ucm_device =
+				ucm_get_dev_for_jack(jack_list->ucm, name,
+						     jack_list->direction);
 
-		if (jack->ucm_device &&
-		    jack_list->direction == CRAS_STREAM_INPUT) {
+		if (jack->ucm_device && jack_list->direction == CRAS_STREAM_INPUT) {
 			char *control_name;
 			control_name = ucm_get_cap_control(jack->jack_list->ucm,
-							   jack->ucm_device);
+						       jack->ucm_device);
 			if (control_name)
 				jack->mixer_input =
 					cras_alsa_mixer_get_input_matching_name(
-						jack_list->mixer, control_name);
+						jack_list->mixer,
+						control_name);
 		}
 
 		if (jack->ucm_device) {
+			jack->dsp_name = ucm_get_dsp_name(
+				jack->jack_list->ucm, jack->ucm_device,
+				jack_list->direction);
 			jack->override_type_name = ucm_get_override_type_name(
 				jack->jack_list->ucm, jack->ucm_device);
 		}
 	}
 
 	/* Look up ELD controls */
-	DL_FOREACH (jack_list->jacks, jack) {
+	DL_FOREACH(jack_list->jacks, jack) {
 		if (jack->is_gpio || jack->eld_control)
 			continue;
 		name = snd_hctl_elem_get_name(jack->elem);
@@ -946,8 +977,8 @@
 			if (strcmp(snd_hctl_elem_get_name(elem),
 				   eld_control_name))
 				continue;
-			if (snd_hctl_elem_get_device(elem) !=
-			    jack_list->device_index)
+			if (snd_hctl_elem_get_device(elem)
+			    != jack_list->device_index)
 				continue;
 			jack->eld_control = elem;
 			break;
@@ -973,9 +1004,10 @@
 	return find_gpio_jacks(jack_list, NULL, NULL);
 }
 
-static int find_hctl_jack_for_section(struct cras_alsa_jack_list *jack_list,
-				      struct ucm_section *section,
-				      struct cras_alsa_jack **result_jack)
+static int find_hctl_jack_for_section(
+		struct cras_alsa_jack_list *jack_list,
+		struct ucm_section *section,
+		struct cras_alsa_jack **result_jack)
 {
 	static const char eld_control_name[] = "ELD";
 	snd_hctl_elem_t *elem;
@@ -996,8 +1028,8 @@
 	if (!elem)
 		return -ENOENT;
 
-	syslog(LOG_DEBUG, "Found Jack: %s for %s", section->jack_name,
-	       section->name);
+	syslog(LOG_DEBUG, "Found Jack: %s for %s",
+	       section->jack_name, section->name);
 
 	jack = cras_alloc_jack(0);
 	if (jack == NULL)
@@ -1012,10 +1044,14 @@
 	}
 	if (jack_list->direction == CRAS_STREAM_OUTPUT)
 		jack->mixer_output = cras_alsa_mixer_get_control_for_section(
-			jack_list->mixer, section);
+					jack_list->mixer, section);
 	else if (jack_list->direction == CRAS_STREAM_INPUT)
 		jack->mixer_input = cras_alsa_mixer_get_control_for_section(
-			jack_list->mixer, section);
+					jack_list->mixer, section);
+
+	jack->dsp_name = ucm_get_dsp_name(
+		jack->jack_list->ucm, jack->ucm_device,
+		jack_list->direction);
 
 	snd_hctl_elem_set_callback(elem, hctl_jack_cb);
 	snd_hctl_elem_set_callback_private(elem, jack);
@@ -1040,7 +1076,8 @@
  */
 
 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_list *jack_list,
+	struct ucm_section *ucm_section,
 	struct cras_alsa_jack **result_jack)
 {
 	if (result_jack)
@@ -1061,24 +1098,29 @@
 	}
 
 	if (!strcmp(ucm_section->jack_type, "hctl")) {
-		return find_hctl_jack_for_section(jack_list, ucm_section,
-						  result_jack);
+		return find_hctl_jack_for_section(
+				jack_list, ucm_section, result_jack);
 	} else if (!strcmp(ucm_section->jack_type, "gpio")) {
 		return find_gpio_jacks(jack_list, ucm_section, result_jack);
 	} else {
-		syslog(LOG_ERR, "Invalid JackType '%s' in '%s'.",
+		syslog(LOG_ERR,
+		       "Invalid JackType '%s' in '%s'.",
 		       ucm_section->jack_type, ucm_section->name);
 		return -EINVAL;
 	}
 }
 
-struct cras_alsa_jack_list *
-cras_alsa_jack_list_create(unsigned int card_index, const char *card_name,
-			   unsigned int device_index, int is_first_device,
-			   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 is_first_device,
+		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 *jack_list;
 
@@ -1109,7 +1151,7 @@
 
 	if (jack_list == NULL)
 		return;
-	DL_FOREACH (jack_list->jacks, jack) {
+	DL_FOREACH(jack_list->jacks, jack) {
 		DL_DELETE(jack_list->jacks, jack);
 		cras_free_jack(jack, 1);
 	}
@@ -1122,23 +1164,23 @@
 
 	if (!jack_list)
 		return 0;
-	DL_FOREACH (jack_list->jacks, jack) {
+	DL_FOREACH(jack_list->jacks, jack) {
 		if (!jack->is_gpio)
 			return 1;
 	}
 	return 0;
 }
 
-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)
 {
 	if (jack == NULL)
 		return NULL;
 	return jack->mixer_output;
 }
 
-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 jack ? jack->mixer_input : NULL;
 }
@@ -1150,7 +1192,7 @@
 	if (jack_list == NULL)
 		return;
 
-	DL_FOREACH (jack_list->jacks, jack)
+	DL_FOREACH(jack_list->jacks, jack)
 		if (jack->is_gpio)
 			gpio_switch_initial_state(jack);
 		else
@@ -1172,7 +1214,8 @@
 }
 
 void cras_alsa_jack_update_monitor_name(const struct cras_alsa_jack *jack,
-					char *name_buf, unsigned int buf_size)
+					char *name_buf,
+					unsigned int buf_size)
 {
 	snd_ctl_elem_value_t *elem_value;
 	snd_ctl_elem_info_t *elem_info;
@@ -1231,6 +1274,13 @@
 	return;
 }
 
+const char *cras_alsa_jack_get_dsp_name(const struct cras_alsa_jack *jack)
+{
+	if (jack == NULL)
+		return NULL;
+	return jack->dsp_name;
+}
+
 void cras_alsa_jack_enable_ucm(const struct cras_alsa_jack *jack, int enable)
 {
 	if (jack && jack->ucm_device)
diff --git a/cras/src/server/cras_alsa_jack.h b/cras/src/server/cras_alsa_jack.h
index 9f35459..b944898 100644
--- a/cras/src/server/cras_alsa_jack.h
+++ b/cras/src/server/cras_alsa_jack.h
@@ -23,8 +23,9 @@
  *    plugged - non-zero if the jack is attached.
  *    data - User defined pointer passed to cras_alsa_jack_create.
  */
-typedef void(jack_state_change_callback)(const struct cras_alsa_jack *jack,
-					 int plugged, void *data);
+typedef void (jack_state_change_callback)(const struct cras_alsa_jack *jack,
+					  int plugged,
+					  void *data);
 
 /* Creates a jack list. The jacks can be added later by name matching or
  * fully specified UCM.
@@ -44,13 +45,17 @@
  * Returns:
  *    A pointer to a new jack list on success, NULL if there is a failure.
  */
-struct cras_alsa_jack_list *
-cras_alsa_jack_list_create(unsigned int card_index, const char *card_name,
-			   unsigned int device_index, int is_first_device,
-			   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 is_first_device,
+		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);
 
 /* Finds jacks by name matching.
  * The list holds all the interesting ALSA jacks for this
@@ -72,7 +77,8 @@
  *   0 on success. Error code if there is a failure.
  */
 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_list *jack_list,
+	struct ucm_section *ucm_section,
 	struct cras_alsa_jack **result_jack);
 
 /* Destroys a jack list created with cras_alsa_jack_list_create.
@@ -93,8 +99,8 @@
  * Returns:
  *    A pointer to the mixer output if it exists, otherwise NULL.
  */
-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);
 
 /* Gets the mixer input associated with given jack.
  * Args:
@@ -102,8 +108,8 @@
  * Returns:
  *    A pointer to the mixer input if it exists, otherwise NULL.
  */
-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);
 
 /* Query all jacks in the list and report the state to the callback.
  * Args:
@@ -123,8 +129,10 @@
  */
 const char *cras_alsa_jack_get_ucm_device(const struct cras_alsa_jack *jack);
 
+
 void cras_alsa_jack_update_monitor_name(const struct cras_alsa_jack *jack,
-					char *name_buf, unsigned int buf_size);
+					char *name_buf,
+					unsigned int buf_size);
 
 /* Updates the node type according to override_type_name in jack.
  * Currently this method only supports updating the node type to
@@ -139,12 +147,19 @@
 void cras_alsa_jack_update_node_type(const struct cras_alsa_jack *jack,
 				     enum CRAS_NODE_TYPE *type);
 
+/* Gets the dsp name of a jack.
+ * Args:
+ *    jack_list - The jack list to query.
+ */
+const char *cras_alsa_jack_get_dsp_name(const struct cras_alsa_jack *jack);
+
 /* Enables the ucm device for this jack if any.
  * Args:
  *    jack - The jack to query for a mixer output.
  */
 void cras_alsa_jack_enable_ucm(const struct cras_alsa_jack *jack, int enable);
 
+
 /* Find out whether the specified card has a jack with the given name.
  * Args:
  *    card_index - Index ALSA uses to refer to the card.  The X in "hw:X".
diff --git a/cras/src/server/cras_alsa_mixer.c b/cras/src/server/cras_alsa_mixer.c
index 99f4d61..27ea4a6 100644
--- a/cras/src/server/cras_alsa_mixer.c
+++ b/cras/src/server/cras_alsa_mixer.c
@@ -94,7 +94,8 @@
  *    mixdev - Name of the device to open the mixer for.
  *    mixer - Pointer filled with the opened mixer on success, NULL on failure.
  */
-static void alsa_mixer_open(const char *mixdev, snd_mixer_t **mixer)
+static void alsa_mixer_open(const char *mixdev,
+			    snd_mixer_t **mixer)
 {
 	int rc;
 
@@ -111,8 +112,7 @@
 	}
 	rc = snd_mixer_selem_register(*mixer, NULL, NULL);
 	if (rc < 0) {
-		syslog(LOG_ERR, "snd_mixer_selem_register: %d: %s", rc,
-		       strerror(-rc));
+		syslog(LOG_ERR, "snd_mixer_selem_register: %d: %s", rc, strerror(-rc));
 		goto fail_after_open;
 	}
 	rc = snd_mixer_load(*mixer);
@@ -127,9 +127,9 @@
 	*mixer = NULL;
 }
 
-static struct mixer_control_element *
-mixer_control_element_create(snd_mixer_elem_t *elem,
-			     enum CRAS_STREAM_DIRECTION dir)
+static struct mixer_control_element *mixer_control_element_create(
+					snd_mixer_elem_t *elem,
+					enum CRAS_STREAM_DIRECTION dir)
 {
 	struct mixer_control_element *c;
 	long min, max;
@@ -151,18 +151,19 @@
 		c->has_mute = snd_mixer_selem_has_playback_switch(elem);
 
 		if (snd_mixer_selem_has_playback_volume(elem) &&
-		    snd_mixer_selem_get_playback_dB_range(elem, &min, &max) ==
-			    0) {
+		    snd_mixer_selem_get_playback_dB_range(
+						elem, &min, &max) == 0) {
 			c->max_volume_dB = max;
 			c->min_volume_dB = min;
 			c->has_volume = 1;
 		}
-	} else if (dir == CRAS_STREAM_INPUT) {
+	}
+	else if (dir == CRAS_STREAM_INPUT) {
 		c->has_mute = snd_mixer_selem_has_capture_switch(elem);
 
 		if (snd_mixer_selem_has_capture_volume(elem) &&
-		    snd_mixer_selem_get_capture_dB_range(elem, &min, &max) ==
-			    0) {
+		    snd_mixer_selem_get_capture_dB_range(
+						elem, &min, &max) == 0) {
 			c->max_volume_dB = max;
 			c->min_volume_dB = min;
 			c->has_volume = 1;
@@ -172,14 +173,13 @@
 	return c;
 }
 
-static void mixer_control_destroy(struct mixer_control *control)
-{
+static void mixer_control_destroy(struct mixer_control *control) {
 	struct mixer_control_element *elem;
 
 	if (!control)
 		return;
 
-	DL_FOREACH (control->elements, elem) {
+	DL_FOREACH(control->elements, elem) {
 		DL_DELETE(control->elements, elem);
 		free(elem);
 	}
@@ -193,7 +193,7 @@
 	struct mixer_control *control;
 	if (!control_list)
 		return;
-	DL_FOREACH (control_list, control) {
+	DL_FOREACH(control_list, control) {
 		DL_DELETE(control_list, control);
 		mixer_control_destroy(control);
 	}
@@ -220,18 +220,19 @@
 		/* Assume that all elements have a common volume range, and
 		 * that both min and max values are valid if one of the two
 		 * is valid. */
-		if (control->min_volume_dB == MIXER_CONTROL_VOLUME_DB_INVALID) {
+		if (control->min_volume_dB ==
+		    MIXER_CONTROL_VOLUME_DB_INVALID) {
 			control->min_volume_dB = elem->min_volume_dB;
 			control->max_volume_dB = elem->max_volume_dB;
 		} else if (control->min_volume_dB != elem->min_volume_dB ||
 			   control->max_volume_dB != elem->max_volume_dB) {
 			syslog(LOG_WARNING,
-			       "Element '%s' of control '%s' has different"
-			       "volume range: [%ld:%ld] ctrl: [%ld:%ld]",
-			       snd_mixer_selem_get_name(elem->elem),
-			       control->name, elem->min_volume_dB,
-			       elem->max_volume_dB, control->min_volume_dB,
-			       control->max_volume_dB);
+			    "Element '%s' of control '%s' has different"
+			    "volume range: [%ld:%ld] ctrl: [%ld:%ld]",
+			    snd_mixer_selem_get_name(elem->elem),
+			    control->name,
+			    elem->min_volume_dB, elem->max_volume_dB,
+			    control->min_volume_dB, control->max_volume_dB);
 		}
 	}
 
@@ -241,7 +242,8 @@
 }
 
 static int mixer_control_create(struct mixer_control **control,
-				const char *name, snd_mixer_elem_t *elem,
+				const char *name,
+				snd_mixer_elem_t *elem,
 				enum CRAS_STREAM_DIRECTION dir)
 {
 	struct mixer_control *c;
@@ -302,11 +304,12 @@
  *    Returns 0 for success, negative error code otherwise. *control is
  *    initialized to NULL on error, or has a valid pointer for success.
  */
-static int mixer_control_create_by_name(struct mixer_control **control,
-					struct cras_alsa_mixer *cmix,
-					const char *name,
-					struct mixer_name *mixer_names,
-					enum CRAS_STREAM_DIRECTION dir)
+static int mixer_control_create_by_name(
+		struct mixer_control **control,
+		struct cras_alsa_mixer *cmix,
+		const char *name,
+		struct mixer_name *mixer_names,
+		enum CRAS_STREAM_DIRECTION dir)
 {
 	snd_mixer_selem_id_t *sid;
 	snd_mixer_elem_t *elem;
@@ -331,7 +334,7 @@
 
 	snd_mixer_selem_id_malloc(&sid);
 
-	DL_FOREACH (mixer_names, m_name) {
+	DL_FOREACH(mixer_names, m_name) {
 		snd_mixer_selem_id_set_index(sid, 0);
 		snd_mixer_selem_id_set_name(sid, m_name->name);
 		elem = snd_mixer_find_selem(cmix->mixer, sid);
@@ -355,52 +358,56 @@
 	return 0;
 }
 
-static int mixer_control_set_dBFS(const struct mixer_control *control,
-				  long to_set)
+static int mixer_control_set_dBFS(
+		const struct mixer_control *control, long to_set)
 {
 	const struct mixer_control_element *elem = NULL;
 	int rc = -EINVAL;
 	if (!control)
 		return rc;
-	DL_FOREACH (control->elements, elem) {
-		if (elem->has_volume) {
+	DL_FOREACH(control->elements, elem) {
+		if(elem->has_volume) {
 			if (control->dir == CRAS_STREAM_OUTPUT)
 				rc = snd_mixer_selem_set_playback_dB_all(
-					elem->elem, to_set, 1);
+						elem->elem, to_set, 1);
 			else if (control->dir == CRAS_STREAM_INPUT)
 				rc = snd_mixer_selem_set_capture_dB_all(
-					elem->elem, to_set, 1);
+						elem->elem, to_set, 1);
 			if (rc)
 				break;
 			syslog(LOG_DEBUG, "%s:%s volume set to %ld",
 			       control->name,
-			       snd_mixer_selem_get_name(elem->elem), to_set);
+			       snd_mixer_selem_get_name(elem->elem),
+			       to_set);
 		}
 	}
 	if (rc && elem) {
 		syslog(LOG_ERR, "Failed to set volume of '%s:%s': %d",
-		       control->name, snd_mixer_selem_get_name(elem->elem), rc);
+		       control->name,
+		       snd_mixer_selem_get_name(elem->elem), rc);
 	}
 	return rc;
 }
 
-static int mixer_control_get_dBFS(const struct mixer_control *control,
-				  long *to_get)
+static int mixer_control_get_dBFS(
+		const struct mixer_control *control, long *to_get)
 {
 	const struct mixer_control_element *elem = NULL;
 	int rc = -EINVAL;
 	if (!control || !to_get)
 		return -EINVAL;
-	DL_FOREACH (control->elements, elem) {
+	DL_FOREACH(control->elements, elem) {
 		if (elem->has_volume) {
 			if (control->dir == CRAS_STREAM_OUTPUT)
 				rc = snd_mixer_selem_get_playback_dB(
-					elem->elem, SND_MIXER_SCHN_FRONT_LEFT,
-					to_get);
+						elem->elem,
+						SND_MIXER_SCHN_FRONT_LEFT,
+						to_get);
 			else if (control->dir == CRAS_STREAM_INPUT)
 				rc = snd_mixer_selem_get_capture_dB(
-					elem->elem, SND_MIXER_SCHN_FRONT_LEFT,
-					to_get);
+						elem->elem,
+						SND_MIXER_SCHN_FRONT_LEFT,
+						to_get);
 			/* Assume all of the elements of this control have
 			 * the same value. */
 			break;
@@ -408,20 +415,21 @@
 	}
 	if (rc && elem) {
 		syslog(LOG_ERR, "Failed to get volume of '%s:%s': %d",
-		       control->name, snd_mixer_selem_get_name(elem->elem), rc);
+		       control->name,
+		       snd_mixer_selem_get_name(elem->elem), rc);
 	}
 	return rc;
 }
 
-static int mixer_control_set_mute(const struct mixer_control *control,
-				  int muted)
+static int mixer_control_set_mute(
+		const struct mixer_control *control, int muted)
 {
 	const struct mixer_control_element *elem = NULL;
 	int rc;
 	if (!control)
 		return -EINVAL;
-	DL_FOREACH (control->elements, elem) {
-		if (elem->has_mute) {
+	DL_FOREACH(control->elements, elem) {
+		if(elem->has_mute) {
 			if (control->dir == CRAS_STREAM_OUTPUT)
 				rc = snd_mixer_selem_set_playback_switch_all(
 					elem->elem, !muted);
@@ -433,7 +441,8 @@
 		}
 	}
 	if (rc && elem) {
-		syslog(LOG_ERR, "Failed to mute '%s:%s': %d", control->name,
+		syslog(LOG_ERR, "Failed to mute '%s:%s': %d",
+		       control->name,
 		       snd_mixer_selem_get_name(elem->elem), rc);
 	}
 	return rc;
@@ -447,8 +456,7 @@
 	if (snd_mixer_selem_has_playback_volume(elem)) {
 		long range;
 		struct mixer_control *c, *next;
-		int rc = mixer_control_create(&c, NULL, elem,
-					      CRAS_STREAM_OUTPUT);
+		int rc = mixer_control_create(&c, NULL, elem, CRAS_STREAM_OUTPUT);
 		if (rc)
 			return rc;
 
@@ -458,7 +466,7 @@
 		}
 
 		range = c->max_volume_dB - c->min_volume_dB;
-		DL_FOREACH (cmix->main_volume_controls, next) {
+		DL_FOREACH(cmix->main_volume_controls, next) {
 			if (range > next->max_volume_dB - next->min_volume_dB)
 				break;
 		}
@@ -470,7 +478,7 @@
 	/* If cmix doesn't yet have a playback switch and this is a playback
 	 * switch, use it. */
 	if (cmix->playback_switch == NULL &&
-	    snd_mixer_selem_has_playback_switch(elem)) {
+			snd_mixer_selem_has_playback_switch(elem)) {
 		syslog(LOG_DEBUG, "Using '%s' as playback switch.",
 		       snd_mixer_selem_get_name(elem));
 		cmix->playback_switch = elem;
@@ -490,8 +498,7 @@
 
 	if (snd_mixer_selem_has_capture_volume(elem)) {
 		struct mixer_control *c;
-		int rc =
-			mixer_control_create(&c, NULL, elem, CRAS_STREAM_INPUT);
+		int rc = mixer_control_create(&c, NULL, elem, CRAS_STREAM_INPUT);
 		if (rc)
 			return rc;
 
@@ -514,7 +521,8 @@
 /* Adds a control to the list. */
 static int add_control_with_name(struct cras_alsa_mixer *cmix,
 				 enum CRAS_STREAM_DIRECTION dir,
-				 snd_mixer_elem_t *elem, const char *name)
+				 snd_mixer_elem_t *elem,
+				 const char *name)
 {
 	int index; /* Index part of mixer simple element */
 	struct mixer_control *c;
@@ -522,7 +530,8 @@
 
 	index = snd_mixer_selem_get_index(elem);
 	syslog(LOG_DEBUG, "Add %s control: %s,%d\n",
-	       dir == CRAS_STREAM_OUTPUT ? "output" : "input", name, index);
+	       dir == CRAS_STREAM_OUTPUT ? "output" : "input",
+	       name, index);
 
 	rc = mixer_control_create(&c, name, elem, dir);
 	if (rc)
@@ -540,27 +549,30 @@
 }
 
 static int add_control(struct cras_alsa_mixer *cmix,
-		       enum CRAS_STREAM_DIRECTION dir, snd_mixer_elem_t *elem)
+		       enum CRAS_STREAM_DIRECTION dir,
+		       snd_mixer_elem_t *elem)
 {
 	return add_control_with_name(cmix, dir, elem,
 				     snd_mixer_selem_get_name(elem));
 }
 
 static void list_controls(struct mixer_control *control_list,
-			  cras_alsa_mixer_control_callback cb, void *cb_arg)
+			  cras_alsa_mixer_control_callback cb,
+			  void *cb_arg)
 {
 	struct mixer_control *control;
 
-	DL_FOREACH (control_list, control)
+	DL_FOREACH(control_list, control)
 		cb(control, cb_arg);
 }
 
-static struct mixer_control *
-get_control_matching_name(struct mixer_control *control_list, const char *name)
+static struct mixer_control *get_control_matching_name(
+		struct mixer_control *control_list,
+		const char *name)
 {
 	struct mixer_control *c;
 
-	DL_FOREACH (control_list, c) {
+	DL_FOREACH(control_list, c) {
 		if (strstr(name, c->name))
 			return c;
 	}
@@ -568,20 +580,22 @@
 }
 
 /* Creates a mixer_control with multiple control elements. */
-static int add_control_with_coupled_mixers(struct cras_alsa_mixer *cmix,
-					   enum CRAS_STREAM_DIRECTION dir,
-					   const char *name,
-					   struct mixer_name *coupled_controls)
+static int add_control_with_coupled_mixers(
+				struct cras_alsa_mixer *cmix,
+				enum CRAS_STREAM_DIRECTION dir,
+				const char *name,
+				struct mixer_name *coupled_controls)
 {
 	struct mixer_control *c;
 	int rc;
 
-	rc = mixer_control_create_by_name(&c, cmix, name, coupled_controls,
-					  dir);
+	rc = mixer_control_create_by_name(
+		 &c, cmix, name, coupled_controls, dir);
 	if (rc)
 		return rc;
 	syslog(LOG_DEBUG, "Add %s control: %s\n",
-	       dir == CRAS_STREAM_OUTPUT ? "output" : "input", c->name);
+	       dir == CRAS_STREAM_OUTPUT ? "output" : "input",
+	       c->name);
 	mixer_name_dump(coupled_controls, "  elements");
 
 	if (c->has_volume)
@@ -596,7 +610,8 @@
 }
 
 static int add_control_by_name(struct cras_alsa_mixer *cmix,
-			       enum CRAS_STREAM_DIRECTION dir, const char *name)
+			       enum CRAS_STREAM_DIRECTION dir,
+			       const char *name)
 {
 	struct mixer_control *c;
 	struct mixer_name *m_name;
@@ -611,7 +626,8 @@
 	if (rc)
 		return rc;
 	syslog(LOG_DEBUG, "Add %s control: %s\n",
-	       dir == CRAS_STREAM_OUTPUT ? "output" : "input", c->name);
+	       dir == CRAS_STREAM_OUTPUT ? "output" : "input",
+	       c->name);
 
 	if (c->has_volume)
 		syslog(LOG_DEBUG, "Control '%s' volume range: [%ld:%ld]",
@@ -644,29 +660,30 @@
 }
 
 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 cras_alsa_mixer *cmix,
+		struct mixer_name *extra_controls,
+		struct mixer_name *coupled_controls)
 {
 	/* Names of controls for main system volume. */
-	static const char *const main_volume_names[] = {
+	static const char * const main_volume_names[] = {
 		"Master",
 		"Digital",
 		"PCM",
 	};
 	/* Names of controls for individual outputs. */
-	static const char *const output_names[] = {
+	static const char * const output_names[] = {
 		"Headphone",
 		"Headset",
 		"HDMI",
 		"Speaker",
 	};
 	/* Names of controls for capture gain/attenuation and mute. */
-	static const char *const main_capture_names[] = {
+	static const char * const main_capture_names[] = {
 		"Capture",
 		"Digital Capture",
 	};
 	/* Names of controls for individual inputs. */
-	static const char *const input_names[] = {
+	static const char * const input_names[] = {
 		"Mic",
 		"Microphone",
 	};
@@ -684,30 +701,28 @@
 		return 0;
 	}
 
+	default_controls = mixer_name_add_array(default_controls,
+				output_names, ARRAY_SIZE(output_names),
+				CRAS_STREAM_OUTPUT, MIXER_NAME_VOLUME);
+	default_controls = mixer_name_add_array(default_controls,
+				input_names, ARRAY_SIZE(input_names),
+				CRAS_STREAM_INPUT, MIXER_NAME_VOLUME);
 	default_controls =
-		mixer_name_add_array(default_controls, output_names,
-				     ARRAY_SIZE(output_names),
-				     CRAS_STREAM_OUTPUT, MIXER_NAME_VOLUME);
+		mixer_name_add_array(default_controls,
+			main_volume_names, ARRAY_SIZE(main_volume_names),
+			CRAS_STREAM_OUTPUT, MIXER_NAME_MAIN_VOLUME);
 	default_controls =
-		mixer_name_add_array(default_controls, input_names,
-				     ARRAY_SIZE(input_names), CRAS_STREAM_INPUT,
-				     MIXER_NAME_VOLUME);
-	default_controls =
-		mixer_name_add_array(default_controls, main_volume_names,
-				     ARRAY_SIZE(main_volume_names),
-				     CRAS_STREAM_OUTPUT,
-				     MIXER_NAME_MAIN_VOLUME);
-	default_controls =
-		mixer_name_add_array(default_controls, main_capture_names,
-				     ARRAY_SIZE(main_capture_names),
-				     CRAS_STREAM_INPUT, MIXER_NAME_MAIN_VOLUME);
+		mixer_name_add_array(default_controls,
+			main_capture_names, ARRAY_SIZE(main_capture_names),
+			CRAS_STREAM_INPUT, MIXER_NAME_MAIN_VOLUME);
 	extra_main_volume =
-		mixer_name_find(extra_controls, NULL, CRAS_STREAM_OUTPUT,
+		mixer_name_find(extra_controls, NULL,
+				CRAS_STREAM_OUTPUT,
 				MIXER_NAME_MAIN_VOLUME) != NULL;
 
 	/* Find volume and mute controls. */
-	for (elem = snd_mixer_first_elem(cmix->mixer); elem != NULL;
-	     elem = snd_mixer_elem_next(elem)) {
+	for(elem = snd_mixer_first_elem(cmix->mixer);
+			elem != NULL; elem = snd_mixer_elem_next(elem)) {
 		const char *name;
 		struct mixer_name *control;
 		int found = 0;
@@ -724,27 +739,27 @@
 		/* If our extra controls contain a main volume
 		 * entry, and we found a main volume entry, then
 		 * skip it. */
-		if (extra_main_volume && control &&
-		    control->type == MIXER_NAME_MAIN_VOLUME)
+		if (extra_main_volume &&
+		    control && control->type == MIXER_NAME_MAIN_VOLUME)
 			control = NULL;
 
 		/* If we didn't match any of the defaults, match
 		 * the extras list. */
 		if (!control)
 			control = mixer_name_find(extra_controls, name,
-						  CRAS_STREAM_OUTPUT,
-						  MIXER_NAME_UNDEFINED);
+					  CRAS_STREAM_OUTPUT,
+					  MIXER_NAME_UNDEFINED);
 
 		if (control) {
 			int rc = -1;
-			switch (control->type) {
+			switch(control->type) {
 			case MIXER_NAME_MAIN_VOLUME:
 				rc = add_main_volume_control(cmix, elem);
 				break;
 			case MIXER_NAME_VOLUME:
 				/* TODO(dgreid) - determine device index. */
-				rc = add_control(cmix, CRAS_STREAM_OUTPUT,
-						 elem);
+				rc = add_control(
+					cmix, CRAS_STREAM_OUTPUT, elem);
 				break;
 			case MIXER_NAME_UNDEFINED:
 				rc = -EINVAL;
@@ -769,17 +784,18 @@
 		   the extras list */
 		if (!control)
 			control = mixer_name_find(extra_controls, name,
-						  CRAS_STREAM_INPUT,
-						  MIXER_NAME_UNDEFINED);
+					  CRAS_STREAM_INPUT,
+					  MIXER_NAME_UNDEFINED);
 
 		if (control) {
 			int rc = -1;
-			switch (control->type) {
+			switch(control->type) {
 			case MIXER_NAME_MAIN_VOLUME:
 				rc = add_main_capture_control(cmix, elem);
 				break;
 			case MIXER_NAME_VOLUME:
-				rc = add_control(cmix, CRAS_STREAM_INPUT, elem);
+				rc = add_control(
+					cmix, CRAS_STREAM_INPUT, elem);
 				break;
 			case MIXER_NAME_UNDEFINED:
 				rc = -EINVAL;
@@ -800,7 +816,8 @@
 			 * in the list above, but has a playback volume
 			 * control and the largest volume range. */
 			long min, max, range;
-			if (snd_mixer_selem_get_playback_dB_range(elem, &min,
+			if (snd_mixer_selem_get_playback_dB_range(elem,
+								  &min,
 								  &max) != 0)
 				continue;
 
@@ -815,7 +832,8 @@
 	/* Handle coupled output names for speaker */
 	if (coupled_controls) {
 		rc = add_control_with_coupled_mixers(
-			cmix, CRAS_STREAM_OUTPUT, "Speaker", coupled_controls);
+				cmix, CRAS_STREAM_OUTPUT,
+				"Speaker", coupled_controls);
 		if (rc) {
 			syslog(LOG_ERR, "Could not add coupled output");
 			goto out;
@@ -839,40 +857,9 @@
 	return rc;
 }
 
-int cras_alsa_mixer_add_main_volume_control_by_name(
-	struct cras_alsa_mixer *cmix, struct mixer_name *mixer_names)
-{
-	snd_mixer_elem_t *elem;
-	struct mixer_name *m_name;
-	int rc = 0;
-	snd_mixer_selem_id_t *sid;
-
-	if (!mixer_names)
-		return -EINVAL;
-
-	snd_mixer_selem_id_malloc(&sid);
-
-	DL_FOREACH (mixer_names, m_name) {
-		snd_mixer_selem_id_set_index(sid, 0);
-		snd_mixer_selem_id_set_name(sid, m_name->name);
-		elem = snd_mixer_find_selem(cmix->mixer, sid);
-		if (!elem) {
-			rc = -ENOENT;
-			syslog(LOG_ERR, "Unable to find simple control %s, 0",
-			       m_name->name);
-			break;
-		}
-		rc = add_main_volume_control(cmix, elem);
-		if (rc)
-			break;
-	}
-
-	snd_mixer_selem_id_free(sid);
-	return rc;
-}
-
-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)
 {
 	int rc;
 
@@ -890,8 +877,8 @@
 	/* TODO(muirj) - Extra main volume controls when fully-specified. */
 
 	if (section->mixer_name) {
-		rc = add_control_by_name(cmix, section->dir,
-					 section->mixer_name);
+		rc = add_control_by_name(
+				cmix, section->dir, section->mixer_name);
 		if (rc) {
 			syslog(LOG_ERR, "Could not add mixer control '%s': %s",
 			       section->mixer_name, strerror(-rc));
@@ -901,7 +888,8 @@
 
 	if (section->coupled) {
 		rc = add_control_with_coupled_mixers(
-			cmix, section->dir, section->name, section->coupled);
+				cmix, section->dir,
+				section->name, section->coupled);
 		if (rc) {
 			syslog(LOG_ERR, "Could not add coupled control: %s",
 			       strerror(-rc));
@@ -924,7 +912,8 @@
 	free(cras_mixer);
 }
 
-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 !!cras_mixer->main_volume_controls;
 }
@@ -934,7 +923,8 @@
 	return mixer_control && mixer_control->has_volume;
 }
 
-void cras_alsa_mixer_set_dBFS(struct cras_alsa_mixer *cras_mixer, long dBFS,
+void cras_alsa_mixer_set_dBFS(struct cras_alsa_mixer *cras_mixer,
+			      long dBFS,
 			      struct mixer_control *mixer_output)
 {
 	struct mixer_control *c;
@@ -954,7 +944,7 @@
 	 * next one until we have the exact volume, or gotten as close as we
 	 * can. Once all of the volume is set the rest of the controls should be
 	 * set to 0dB. */
-	DL_FOREACH (cras_mixer->main_volume_controls, c) {
+	DL_FOREACH(cras_mixer->main_volume_controls, c) {
 		long actual_dB;
 
 		if (!c->has_volume)
@@ -975,7 +965,8 @@
 	return cras_mixer->max_volume_dB - cras_mixer->min_volume_dB;
 }
 
-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)
 {
 	if (!cras_alsa_mixer_has_volume(mixer_output))
 		return 0;
@@ -997,7 +988,7 @@
 	 * be set on the current control, move on to the next one until we have
 	 * the exact gain, or gotten as close as we can. Once all of the gain is
 	 * set the rest of the controls should be set to 0dB. */
-	DL_FOREACH (cras_mixer->main_capture_controls, c) {
+	DL_FOREACH(cras_mixer->main_capture_controls, c) {
 		long actual_dB;
 
 		if (!c->has_volume)
@@ -1012,47 +1003,52 @@
 		mixer_control_set_dBFS(mixer_input, to_set);
 }
 
-long cras_alsa_mixer_get_minimum_capture_gain(struct cras_alsa_mixer *cmix,
-					      struct mixer_control *mixer_input)
+long cras_alsa_mixer_get_minimum_capture_gain(
+                struct cras_alsa_mixer *cmix,
+		struct mixer_control *mixer_input)
 {
 	struct mixer_control *c;
 	long total_min = 0;
 
 	assert(cmix);
-	DL_FOREACH (cmix->main_capture_controls, c)
+	DL_FOREACH(cmix->main_capture_controls, c)
 		if (c->has_volume)
 			total_min += c->min_volume_dB;
-	if (mixer_input && mixer_input->has_volume)
+	if (mixer_input &&
+	    mixer_input->has_volume)
 		total_min += mixer_input->min_volume_dB;
 
 	return total_min;
 }
 
-long cras_alsa_mixer_get_maximum_capture_gain(struct cras_alsa_mixer *cmix,
-					      struct mixer_control *mixer_input)
+long cras_alsa_mixer_get_maximum_capture_gain(
+		struct cras_alsa_mixer *cmix,
+		struct mixer_control *mixer_input)
 {
 	struct mixer_control *c;
 	long total_max = 0;
 
 	assert(cmix);
-	DL_FOREACH (cmix->main_capture_controls, c)
+	DL_FOREACH(cmix->main_capture_controls, c)
 		if (c->has_volume)
 			total_max += c->max_volume_dB;
 
-	if (mixer_input && mixer_input->has_volume)
+	if (mixer_input &&
+	    mixer_input->has_volume)
 		total_max += mixer_input->max_volume_dB;
 
 	return total_max;
 }
 
-void cras_alsa_mixer_set_mute(struct cras_alsa_mixer *cras_mixer, int muted,
+void cras_alsa_mixer_set_mute(struct cras_alsa_mixer *cras_mixer,
+			      int muted,
 			      struct mixer_control *mixer_output)
 {
 	assert(cras_mixer);
 
 	if (cras_mixer->playback_switch) {
 		snd_mixer_selem_set_playback_switch_all(
-			cras_mixer->playback_switch, !muted);
+				cras_mixer->playback_switch, !muted);
 	}
 	if (mixer_output && mixer_output->has_mute) {
 		mixer_control_set_mute(mixer_output, muted);
@@ -1066,7 +1062,7 @@
 	assert(cras_mixer);
 	if (cras_mixer->capture_switch) {
 		snd_mixer_selem_set_capture_switch_all(
-			cras_mixer->capture_switch, !muted);
+				cras_mixer->capture_switch, !muted);
 		return;
 	}
 	if (mixer_input && mixer_input->has_mute)
@@ -1089,18 +1085,18 @@
 	list_controls(cras_mixer->input_controls, cb, cb_arg);
 }
 
-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)
 {
 	if (!control)
 		return NULL;
 	return control->name;
 }
 
-struct mixer_control *
-cras_alsa_mixer_get_control_matching_name(struct cras_alsa_mixer *cras_mixer,
-					  enum CRAS_STREAM_DIRECTION dir,
-					  const char *name, int create_missing)
+struct mixer_control *cras_alsa_mixer_get_control_matching_name(
+		struct cras_alsa_mixer *cras_mixer,
+		enum CRAS_STREAM_DIRECTION dir, const char *name,
+		int create_missing)
 {
 	struct mixer_control *c;
 
@@ -1109,13 +1105,14 @@
 		return NULL;
 
 	if (dir == CRAS_STREAM_OUTPUT) {
-		c = get_control_matching_name(cras_mixer->output_controls,
-					      name);
+		c = get_control_matching_name(
+				cras_mixer->output_controls, name);
 	} else if (dir == CRAS_STREAM_INPUT) {
-		c = get_control_matching_name(cras_mixer->input_controls, name);
+		c = get_control_matching_name(
+				cras_mixer->input_controls, name);
 	} else {
 		return NULL;
-	}
+        }
 
 	/* TODO: Allowing creation of a new control is a workaround: we
 	 * should pass the input names in ucm config to
@@ -1124,48 +1121,49 @@
 		int rc = add_control_by_name(cras_mixer, dir, name);
 		if (rc)
 			return NULL;
-		c = cras_alsa_mixer_get_control_matching_name(cras_mixer, dir,
-							      name, 0);
+		c = cras_alsa_mixer_get_control_matching_name(
+				cras_mixer, dir, name, 0);
 	}
 	return c;
 }
 
-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)
 {
 	assert(cras_mixer && section);
 	if (section->mixer_name) {
 		return cras_alsa_mixer_get_control_matching_name(
-			cras_mixer, section->dir, section->mixer_name, 0);
+			   cras_mixer, section->dir, section->mixer_name, 0);
 	} else if (section->coupled) {
 		return cras_alsa_mixer_get_control_matching_name(
-			cras_mixer, section->dir, section->name, 0);
+			   cras_mixer, section->dir, section->name, 0);
 	}
 	return NULL;
 }
 
-struct mixer_control *
-cras_alsa_mixer_get_output_matching_name(struct cras_alsa_mixer *cras_mixer,
-					 const char *const name)
+struct mixer_control *cras_alsa_mixer_get_output_matching_name(
+		struct cras_alsa_mixer *cras_mixer,
+		const char * const name)
 {
 	return cras_alsa_mixer_get_control_matching_name(
-		cras_mixer, CRAS_STREAM_OUTPUT, name, 0);
+			cras_mixer, CRAS_STREAM_OUTPUT, name, 0);
 }
 
-struct mixer_control *
-cras_alsa_mixer_get_input_matching_name(struct cras_alsa_mixer *cras_mixer,
-					const char *name)
+struct mixer_control *cras_alsa_mixer_get_input_matching_name(
+		struct cras_alsa_mixer *cras_mixer,
+		const char *name)
 {
 	/* TODO: Allowing creation of a new control is a workaround: we
 	 * should pass the input names in ucm config to
 	 * cras_alsa_mixer_create. */
 	return cras_alsa_mixer_get_control_matching_name(
-		cras_mixer, CRAS_STREAM_INPUT, name, 1);
+			cras_mixer, CRAS_STREAM_INPUT, name, 1);
 }
 
-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)
 {
 	assert(output);
 	if (!output->has_mute)
diff --git a/cras/src/server/cras_alsa_mixer.h b/cras/src/server/cras_alsa_mixer.h
index 6b30603..4e0ca1b 100644
--- a/cras/src/server/cras_alsa_mixer.h
+++ b/cras/src/server/cras_alsa_mixer.h
@@ -41,19 +41,9 @@
  * Returns:
  *    0 on success. Negative error code otherwise.
  */
-int cras_alsa_mixer_add_controls_in_section(struct cras_alsa_mixer *cmix,
-					    struct ucm_section *section);
-
-/* Adds main volume controls to a cras_alsa_mixer from the given list of mixer
- * names of main volume controls.
- * Args:
- *    cmix - A pointer to cras_alsa_mixer.
- *    mixer_names - A list of mixer names from the given UCM MainVolumeNames.
- * Returns:
- *    0 on success. Negative error code otherwise.
- */
-int cras_alsa_mixer_add_main_volume_control_by_name(
-	struct cras_alsa_mixer *cmix, struct mixer_name *mixer_names);
+int cras_alsa_mixer_add_controls_in_section(
+		struct cras_alsa_mixer *cmix,
+		struct ucm_section *section);
 
 /* Adds controls to a cras_alsa_mixer instance by name matching.
  * Args:
@@ -64,8 +54,9 @@
  *    0 on success. Other error code if error happens.
  */
 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 cras_alsa_mixer *cmix,
+		struct mixer_name *extra_controls,
+		struct mixer_name *coupled_controls);
 
 /* Destroys a cras_alsa_mixer that was returned from cras_alsa_mixer_create.
  * Args:
@@ -88,7 +79,8 @@
  *    mixer_output - The mixer output to set if not all attenuation can be
  *      obtained from the main controls.  Can be null.
  */
-void cras_alsa_mixer_set_dBFS(struct cras_alsa_mixer *cras_mixer, long dBFS,
+void cras_alsa_mixer_set_dBFS(struct cras_alsa_mixer *cras_mixer,
+			      long dBFS,
 			      struct mixer_control *mixer_output);
 
 /* Gets the volume range of the mixer in dB.
@@ -101,7 +93,8 @@
  * Args:
  *    mixer_output - The mixer output to get the volume range.
  */
-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);
 
 /* Sets the capture gain for the device associated with this mixer.
  * Args:
@@ -112,7 +105,7 @@
  */
 void cras_alsa_mixer_set_capture_dBFS(struct cras_alsa_mixer *cras_mixer,
 				      long dBFS,
-				      struct mixer_control *mixer_input);
+				      struct mixer_control* mixer_input);
 
 /* Gets the minimum allowed setting for capture gain.
  * Args:
@@ -123,7 +116,8 @@
  *    The minimum allowed capture gain in dBFS * 100.
  */
 long cras_alsa_mixer_get_minimum_capture_gain(
-	struct cras_alsa_mixer *cmix, struct mixer_control *mixer_input);
+                struct cras_alsa_mixer *cmix,
+		struct mixer_control *mixer_input);
 
 /* Gets the maximum allowed setting for capture gain.
  * Args:
@@ -134,7 +128,8 @@
  *    The maximum allowed capture gain in dBFS * 100.
  */
 long cras_alsa_mixer_get_maximum_capture_gain(
-	struct cras_alsa_mixer *cmix, struct mixer_control *mixer_input);
+		struct cras_alsa_mixer *cmix,
+		struct mixer_control *mixer_input);
 
 /* Sets the playback switch for the device.
  * Args:
@@ -143,7 +138,8 @@
  *    mixer_output - The output specific mixer control to mute/unmute. Pass NULL
  *                   to skip it.
  */
-void cras_alsa_mixer_set_mute(struct cras_alsa_mixer *cras_mixer, int muted,
+void cras_alsa_mixer_set_mute(struct cras_alsa_mixer *cras_mixer,
+			      int muted,
 			      struct mixer_control *mixer_output);
 
 /* Sets the capture switch for the device.
@@ -164,8 +160,8 @@
  *    cb - Function to call for each output (input).
  *    cb_arg - Argument to pass to cb.
  */
-typedef void (*cras_alsa_mixer_control_callback)(struct mixer_control *control,
-						 void *arg);
+typedef void (*cras_alsa_mixer_control_callback)(
+		struct mixer_control *control, void *arg);
 void cras_alsa_mixer_list_outputs(struct cras_alsa_mixer *cras_mixer,
 				  cras_alsa_mixer_control_callback cb,
 				  void *cb_arg);
@@ -175,8 +171,8 @@
 				 void *cb_arg);
 
 /* Gets the name of a given control. */
-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);
 
 /* Returns the mixer control matching the given direction and name.
  * Args:
@@ -188,10 +184,10 @@
  * Returns:
  *    A pointer to the matching mixer control, or NULL if none found.
  */
-struct mixer_control *
-cras_alsa_mixer_get_control_matching_name(struct cras_alsa_mixer *cras_mixer,
-					  enum CRAS_STREAM_DIRECTION dir,
-					  const char *name, int create_missing);
+struct mixer_control *cras_alsa_mixer_get_control_matching_name(
+		struct cras_alsa_mixer *cras_mixer,
+		enum CRAS_STREAM_DIRECTION dir, const char *name,
+		int create_missing);
 
 /* Returns the mixer control associated with the given section.
  * The control is the one that matches 'mixer_name', or if that is not defined
@@ -203,9 +199,9 @@
  * Returns:
  *    A pointer to the associated mixer control, or NULL if none found.
  */
-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);
 
 /* Finds the output that matches the given string.  Used to match Jacks to Mixer
  * elements.
@@ -215,9 +211,9 @@
  * Returns:
  *    A pointer to the output with a mixer control that matches "name".
  */
-struct mixer_control *
-cras_alsa_mixer_get_output_matching_name(struct cras_alsa_mixer *cras_mixer,
-					 const char *name);
+struct mixer_control *cras_alsa_mixer_get_output_matching_name(
+		struct cras_alsa_mixer *cras_mixer,
+		const char *name);
 
 /* Finds the mixer control for that matches the control name of input control
  * name specified in ucm config.
@@ -227,12 +223,13 @@
  * Returns:
  *    A pointer to the input with a mixer control that matches "name".
  */
-struct mixer_control *
-cras_alsa_mixer_get_input_matching_name(struct cras_alsa_mixer *cras_mixer,
-					const char *name);
+struct mixer_control *cras_alsa_mixer_get_input_matching_name(
+		struct cras_alsa_mixer *cras_mixer,
+		const char *name);
 
 /* Sets the given output active or inactive. */
-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);
 
 #endif /* _CRAS_ALSA_MIXER_H */
diff --git a/cras/src/server/cras_alsa_mixer_name.c b/cras/src/server/cras_alsa_mixer_name.c
index 45ef2c5..7f887b9 100644
--- a/cras/src/server/cras_alsa_mixer_name.c
+++ b/cras/src/server/cras_alsa_mixer_name.c
@@ -10,7 +10,8 @@
 #include "cras_alsa_mixer_name.h"
 #include "utlist.h"
 
-struct mixer_name *mixer_name_add(struct mixer_name *names, const char *name,
+struct mixer_name *mixer_name_add(struct mixer_name *names,
+				  const char *name,
 				  enum CRAS_STREAM_DIRECTION dir,
 				  mixer_name_type type)
 {
@@ -36,7 +37,7 @@
 }
 
 struct mixer_name *mixer_name_add_array(struct mixer_name *names,
-					const char *const *name_array,
+					const char * const *name_array,
 					size_t name_array_size,
 					enum CRAS_STREAM_DIRECTION dir,
 					mixer_name_type type)
@@ -50,14 +51,15 @@
 void mixer_name_free(struct mixer_name *names)
 {
 	struct mixer_name *m_name;
-	DL_FOREACH (names, m_name) {
+	DL_FOREACH(names, m_name) {
 		DL_DELETE(names, m_name);
-		free((void *)m_name->name);
+		free((void*)m_name->name);
 		free(m_name);
 	}
 }
 
-struct mixer_name *mixer_name_find(struct mixer_name *names, const char *name,
+struct mixer_name *mixer_name_find(struct mixer_name *names,
+				   const char *name,
 				   enum CRAS_STREAM_DIRECTION dir,
 				   mixer_name_type type)
 {
@@ -65,12 +67,13 @@
 		return NULL;
 
 	struct mixer_name *m_name;
-	DL_FOREACH (names, m_name) {
+	DL_FOREACH(names, m_name) {
 		/* Match the direction. */
 		if (dir != m_name->dir)
 			continue;
 		/* Match the type unless the type is UNDEFINED. */
-		if (type != MIXER_NAME_UNDEFINED && type != m_name->type)
+		if (type != MIXER_NAME_UNDEFINED &&
+		    type != m_name->type)
 			continue;
 		/* Match the name if it is non-NULL, or return the first
 		 * item with the correct type when the name is not defined. */
@@ -123,7 +126,7 @@
 	}
 
 	syslog(LOG_DEBUG, "%s:", message);
-	DL_FOREACH (names, m_name) {
+	DL_FOREACH(names, m_name) {
 		const char *type_str =
 			mixer_name_type_str(m_name->dir, m_name->type);
 		syslog(LOG_DEBUG, "    %s %s", m_name->name, type_str);
diff --git a/cras/src/server/cras_alsa_mixer_name.h b/cras/src/server/cras_alsa_mixer_name.h
index 67f8e9e..0a91454 100644
--- a/cras/src/server/cras_alsa_mixer_name.h
+++ b/cras/src/server/cras_alsa_mixer_name.h
@@ -21,7 +21,7 @@
 
 /* Represents a list of mixer names found in ALSA. */
 struct mixer_name {
-	const char *name;
+	const char* name;
 	enum CRAS_STREAM_DIRECTION dir;
 	mixer_name_type type;
 	struct mixer_name *prev, *next;
@@ -39,7 +39,8 @@
  *    Returns the new head of the list (which changes only
  *    when names is NULL).
  */
-struct mixer_name *mixer_name_add(struct mixer_name *names, const char *name,
+struct mixer_name *mixer_name_add(struct mixer_name *names,
+				  const char *name,
 				  enum CRAS_STREAM_DIRECTION dir,
 				  mixer_name_type type);
 
@@ -57,7 +58,7 @@
  *    when names is NULL).
  */
 struct mixer_name *mixer_name_add_array(struct mixer_name *names,
-					const char *const *name_array,
+					const char * const *name_array,
 					size_t name_array_size,
 					enum CRAS_STREAM_DIRECTION dir,
 					mixer_name_type type);
@@ -83,7 +84,8 @@
  *    Returns a pointer to the matching struct mixer_name or NULL if
  *    not found.
  */
-struct mixer_name *mixer_name_find(struct mixer_name *names, const char *name,
+struct mixer_name *mixer_name_find(struct mixer_name *names,
+				   const char *name,
 				   enum CRAS_STREAM_DIRECTION dir,
 				   mixer_name_type type);
 
diff --git a/cras/src/server/cras_alsa_ucm.c b/cras/src/server/cras_alsa_ucm.c
index 12ee81e..2508b8b 100644
--- a/cras/src/server/cras_alsa_ucm.c
+++ b/cras/src/server/cras_alsa_ucm.c
@@ -22,7 +22,6 @@
 static const char override_type_name_var[] = "OverrideNodeType";
 static const char output_dsp_name_var[] = "OutputDspName";
 static const char input_dsp_name_var[] = "InputDspName";
-static const char dsp_name_var[] = "DspName";
 static const char mixer_var[] = "MixerName";
 static const char swap_mode_suffix[] = "Swap Mode";
 static const char min_buffer_level_var[] = "MinBufferLevel";
@@ -59,14 +58,18 @@
 
 /* Use case verbs corresponding to CRAS_STREAM_TYPE. */
 static const char *use_case_verbs[] = {
-	"HiFi",	  "Multimedia", "Voice Call",
-	"Speech", "Pro Audio",	"Accessibility",
+	"HiFi",
+	"Multimedia",
+	"Voice Call",
+	"Speech",
+	"Pro Audio",
+	"Accessibility",
 };
 
 /* Represents a list of section names found in UCM. */
 struct section_name {
-	const char *name;
-	struct section_name *prev, *next;
+	const char* name;
+	struct section_name  *prev, *next;
 };
 
 struct cras_use_case_mgr {
@@ -171,8 +174,7 @@
 }
 
 static int ucm_section_exists_with_name(struct cras_use_case_mgr *mgr,
-					const char *name,
-					const char *identifier)
+		const char *name, const char *identifier)
 {
 	const char **list;
 	unsigned int i;
@@ -183,7 +185,8 @@
 	if (num_entries <= 0)
 		return 0;
 
-	for (i = 0; i < (unsigned int)num_entries; i += 2) {
+	for (i = 0; i < (unsigned int)num_entries; i+=2) {
+
 		if (!list[i])
 			continue;
 
@@ -197,8 +200,7 @@
 }
 
 static int ucm_section_exists_with_suffix(struct cras_use_case_mgr *mgr,
-					  const char *suffix,
-					  const char *identifier)
+		const char *suffix, const char *identifier)
 {
 	const char **list;
 	unsigned int i;
@@ -209,7 +211,8 @@
 	if (num_entries <= 0)
 		return 0;
 
-	for (i = 0; i < (unsigned int)num_entries; i += 2) {
+	for (i = 0; i < (unsigned int)num_entries; i+=2) {
+
 		if (!list[i])
 			continue;
 
@@ -247,10 +250,11 @@
 }
 
 /* Get a list of section names whose variable is the matched value. */
-static struct section_name *
-ucm_get_sections_for_var(struct cras_use_case_mgr *mgr, const char *var,
-			 const char *value, const char *identifier,
-			 enum CRAS_STREAM_DIRECTION direction)
+static struct section_name * ucm_get_sections_for_var(
+		struct cras_use_case_mgr *mgr,
+		const char *var, const char *value,
+		const char *identifier,
+		enum CRAS_STREAM_DIRECTION direction)
 {
 	const char **list;
 	struct section_name *section_names = NULL, *s_name;
@@ -264,7 +268,7 @@
 
 	/* snd_use_case_get_list fills list with pairs of device name and
 	 * comment, so device names are in even-indexed elements. */
-	for (i = 0; i < (unsigned int)num_entries; i += 2) {
+	for (i = 0; i < (unsigned int)num_entries; i+=2) {
 		const char *this_value;
 
 		if (!list[i])
@@ -276,7 +280,7 @@
 
 		if (!strcmp(value, this_value)) {
 			s_name = (struct section_name *)malloc(
-				sizeof(struct section_name));
+					sizeof(struct section_name));
 
 			if (!s_name) {
 				syslog(LOG_ERR, "Failed to allocate memory");
@@ -294,23 +298,23 @@
 	return section_names;
 }
 
-static struct section_name *
-ucm_get_devices_for_var(struct cras_use_case_mgr *mgr, const char *var,
-			const char *value, enum CRAS_STREAM_DIRECTION dir)
+static struct section_name *ucm_get_devices_for_var(
+		struct cras_use_case_mgr *mgr,
+		const char *var, const char *value,
+		enum CRAS_STREAM_DIRECTION dir)
 {
 	char *identifier;
 	struct section_name *section_names;
 
 	identifier = snd_use_case_identifier("_devices/%s", uc_verb(mgr));
-	section_names =
-		ucm_get_sections_for_var(mgr, var, value, identifier, dir);
+	section_names = ucm_get_sections_for_var(mgr, var, value, identifier,
+						 dir);
 	free(identifier);
 	return section_names;
 }
 
-static const char *
-ucm_get_playback_device_name_for_dev(struct cras_use_case_mgr *mgr,
-				     const char *dev)
+static const char *ucm_get_playback_device_name_for_dev(
+		struct cras_use_case_mgr *mgr, const char *dev)
 {
 	const char *name = NULL;
 	int rc;
@@ -322,9 +326,8 @@
 	return name;
 }
 
-static const char *
-ucm_get_capture_device_name_for_dev(struct cras_use_case_mgr *mgr,
-				    const char *dev)
+static const char *ucm_get_capture_device_name_for_dev(
+		struct cras_use_case_mgr *mgr, const char *dev)
 {
 	const char *name = NULL;
 	int rc;
@@ -340,9 +343,9 @@
  * E.g. "Left Playback,Right Playback".
  */
 static struct mixer_name *ucm_get_mixer_names(struct cras_use_case_mgr *mgr,
-					      const char *dev, const char *var,
-					      enum CRAS_STREAM_DIRECTION dir,
-					      mixer_name_type type)
+				const char *dev, const char* var,
+				enum CRAS_STREAM_DIRECTION dir,
+				mixer_name_type type)
 {
 	const char *names_in_string = NULL;
 	int rc;
@@ -360,7 +363,7 @@
 		names = mixer_name_add(names, name, dir, type);
 		name = strtok_r(NULL, ",", &laststr);
 	}
-	free((void *)names_in_string);
+	free((void*)names_in_string);
 	free(tokens);
 	return names;
 }
@@ -431,8 +434,8 @@
 	if (mgr->avail_use_cases & (1 << use_case)) {
 		mgr->use_case = use_case;
 	} else {
-		syslog(LOG_ERR, "Unavailable use case %d for card %s", use_case,
-		       mgr->name);
+		syslog(LOG_ERR, "Unavailable use case %d for card %s",
+		       use_case, mgr->name);
 		return -1;
 	}
 
@@ -462,8 +465,7 @@
 		return -ENOMEM;
 	snprintf(swap_mod, len, "%s %s", node_name, swap_mode_suffix);
 	if (!ucm_mod_exists_with_name(mgr, swap_mod)) {
-		syslog(LOG_ERR, "Can not find swap mode modifier %s.",
-		       swap_mod);
+		syslog(LOG_ERR, "Can not find swap mode modifier %s.", swap_mod);
 		free((void *)swap_mod);
 		return -EPERM;
 	}
@@ -552,7 +554,7 @@
 
 	section_names = ucm_get_devices_for_var(mgr, jack_var, jack, direction);
 
-	DL_FOREACH (section_names, c) {
+	DL_FOREACH(section_names, c) {
 		if (!strcmp(c->name, "Mic")) {
 			/* Skip mic section for output */
 			if (direction == CRAS_STREAM_OUTPUT)
@@ -566,9 +568,9 @@
 		break;
 	}
 
-	DL_FOREACH (section_names, c) {
+	DL_FOREACH(section_names, c) {
 		DL_DELETE(section_names, c);
-		free((void *)c->name);
+		free((void*)c->name);
 		free(c);
 	}
 
@@ -586,9 +588,9 @@
 	if (section_names)
 		ret = strdup(section_names->name);
 
-	DL_FOREACH (section_names, c) {
+	DL_FOREACH(section_names, c) {
 		DL_DELETE(section_names, c);
-		free((void *)c->name);
+		free((void*)c->name);
 		free(c);
 	}
 
@@ -608,36 +610,30 @@
 	return file_name;
 }
 
+const char *ucm_get_dsp_name(struct cras_use_case_mgr *mgr, const char *ucm_dev,
+			     int direction)
+{
+	const char *var = (direction == CRAS_STREAM_OUTPUT)
+		? output_dsp_name_var
+		: input_dsp_name_var;
+	const char *dsp_name = NULL;
+	int rc;
+
+	rc = get_var(mgr, var, ucm_dev, uc_verb(mgr), &dsp_name);
+	if (rc)
+		return NULL;
+
+	return dsp_name;
+}
+
 const char *ucm_get_dsp_name_default(struct cras_use_case_mgr *mgr,
 				     int direction)
 {
-	const char *var = (direction == CRAS_STREAM_OUTPUT) ?
-				  output_dsp_name_var :
-				  input_dsp_name_var;
-	const char *dsp_name = NULL;
-	int rc;
-
-	rc = get_var(mgr, var, "", uc_verb(mgr), &dsp_name);
-	if (rc)
-		return NULL;
-
-	return dsp_name;
+	return ucm_get_dsp_name(mgr, "", direction);
 }
 
-const char *ucm_get_dsp_name_for_dev(struct cras_use_case_mgr *mgr,
-				     const char *dev)
-{
-	const char *dsp_name = NULL;
-	int rc;
-
-	rc = get_var(mgr, dsp_name_var, dev, uc_verb(mgr), &dsp_name);
-	if (rc)
-		return NULL;
-
-	return dsp_name;
-}
-
-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)
 {
 	int value;
 	int rc;
@@ -712,9 +708,9 @@
 	return value;
 }
 
-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)
 {
 	if (direction == CRAS_STREAM_OUTPUT)
 		return ucm_get_playback_device_name_for_dev(mgr, dev);
@@ -723,15 +719,14 @@
 	return NULL;
 }
 
-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)
 {
 	const char *name = NULL;
 	int rc;
 
-	rc = get_var(mgr, echo_reference_dev_name_var, dev, uc_verb(mgr),
-		     &name);
+	rc = get_var(mgr, echo_reference_dev_name_var, dev,
+		     uc_verb(mgr), &name);
 	if (rc)
 		return NULL;
 	return name;
@@ -759,7 +754,8 @@
 }
 
 int ucm_get_capture_chmap_for_dev(struct cras_use_case_mgr *mgr,
-				  const char *dev, int8_t *channel_layout)
+				  const char *dev,
+				  int8_t *channel_layout)
 {
 	const char *var_str;
 	char *tokens, *token;
@@ -781,10 +777,11 @@
 	return (i == CRAS_CH_MAX) ? 0 : -EINVAL;
 }
 
-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_mixer_names(mgr, dev, coupled_mixers, CRAS_STREAM_OUTPUT,
+	return ucm_get_mixer_names(mgr, dev, coupled_mixers,
+				   CRAS_STREAM_OUTPUT,
 				   MIXER_NAME_VOLUME);
 }
 
@@ -841,14 +838,14 @@
 			dir = CRAS_STREAM_OUTPUT;
 		else {
 			target_device_name =
-				ucm_get_capture_device_name_for_dev(mgr,
-								    dev_name);
+				ucm_get_capture_device_name_for_dev(
+					mgr, dev_name);
 			if (target_device_name)
 				dir = CRAS_STREAM_INPUT;
 		}
 		if (target_device_name) {
 			dev_idx = get_device_index_from_target(
-				target_device_name);
+					target_device_name);
 			free((void *)target_device_name);
 		}
 
@@ -863,8 +860,7 @@
 		if (dev_idx == -1) {
 			syslog(LOG_ERR,
 			       "PlaybackPCM or CapturePCM for '%s' must be in"
-			       " the form 'hw:<card>,<number>'",
-			       dev_name);
+			       " the form 'hw:<card>,<number>'", dev_name);
 			goto error_cleanup;
 		}
 
@@ -872,8 +868,8 @@
 		jack_type = ucm_get_jack_type_for_dev(mgr, dev_name);
 		mixer_name = ucm_get_mixer_name_for_dev(mgr, dev_name);
 
-		dev_sec = ucm_section_create(dev_name, dev_idx, dir, jack_name,
-					     jack_type);
+		dev_sec = ucm_section_create(dev_name, dev_idx, dir,
+					     jack_name, jack_type);
 		if (jack_name)
 			free((void *)jack_name);
 		if (jack_type)
@@ -896,8 +892,8 @@
 				goto error_cleanup;
 		}
 
-		m_name = ucm_get_mixer_names(mgr, dev_name, coupled_mixers, dir,
-					     MIXER_NAME_VOLUME);
+		m_name = ucm_get_mixer_names(mgr, dev_name, coupled_mixers,
+					     dir, MIXER_NAME_VOLUME);
 		ucm_section_concat_coupled(dev_sec, m_name);
 
 		DL_APPEND(sections, dev_sec);
@@ -923,46 +919,31 @@
 	int i, num_entries;
 	int models_len = 0;
 	char *models = NULL;
-	const char *model_name;
+	const char *tmp;
 	char *identifier;
 
 	identifier = snd_use_case_identifier("_modifiers/%s", uc_verb(mgr));
 	num_entries = snd_use_case_get_list(mgr->mgr, identifier, &list);
 	free(identifier);
-
 	if (num_entries <= 0)
 		return 0;
-
-	models = (char *)malloc(num_entries *
-				(CRAS_MAX_HOTWORD_MODEL_NAME_SIZE + 1));
-
-	for (i = 0; i < num_entries; i += 2) {
+	models = (char *)malloc(num_entries * 8);
+	for (i = 0; i < num_entries; i+=2) {
 		if (!list[i])
 			continue;
-
-		if (strncmp(list[i], hotword_model_prefix,
-			    strlen(hotword_model_prefix)))
-			continue;
-
-		model_name = list[i] + strlen(hotword_model_prefix);
-		while (isspace(*model_name))
-			model_name++;
-
-		if (strlen(model_name) > CRAS_MAX_HOTWORD_MODEL_NAME_SIZE) {
-			syslog(LOG_ERR,
-			       "Ignore hotword model %s because the it is"
-			       "too long.",
-			       list[i]);
-			continue;
+		if (0 == strncmp(list[i], hotword_model_prefix,
+				 strlen(hotword_model_prefix))) {
+			tmp = list[i] + strlen(hotword_model_prefix);
+			while (isspace(*tmp))
+				tmp++;
+			strcpy(models + models_len, tmp);
+			models_len += strlen(tmp);
+			if (i + 2 >= num_entries)
+				models[models_len] = '\0';
+			else
+				models[models_len++] = ',';
 		}
-
-		if (models_len != 0)
-			models[models_len++] = ',';
-
-		strcpy(models + models_len, model_name);
-		models_len += strlen(model_name);
 	}
-	models[models_len++] = 0;
 	snd_use_case_free_list(list, num_entries);
 
 	return models;
@@ -973,13 +954,13 @@
 	const char **list;
 	int num_enmods, mod_idx;
 	char *model_mod = NULL;
-	size_t model_mod_size =
-		strlen(model) + 1 + strlen(hotword_model_prefix) + 1;
+	size_t model_mod_size = strlen(model) + 1 +
+				strlen(hotword_model_prefix) + 1;
 	model_mod = (char *)malloc(model_mod_size);
 	if (!model_mod)
 		return -ENOMEM;
-	snprintf(model_mod, model_mod_size, "%s %s", hotword_model_prefix,
-		 model);
+	snprintf(model_mod, model_mod_size,
+		 "%s %s", hotword_model_prefix, model);
 	if (!ucm_mod_exists_with_name(mgr, model_mod)) {
 		free((void *)model_mod);
 		return -EINVAL;
@@ -1015,8 +996,7 @@
 	return ret;
 }
 
-const char *ucm_get_mixer_name_for_dev(struct cras_use_case_mgr *mgr,
-				       const char *dev)
+const char *ucm_get_mixer_name_for_dev(struct cras_use_case_mgr *mgr, const char *dev)
 {
 	const char *name = NULL;
 	int rc;
@@ -1035,13 +1015,15 @@
 }
 
 int ucm_list_section_devices_by_device_name(
-	struct cras_use_case_mgr *mgr, enum CRAS_STREAM_DIRECTION direction,
-	const char *device_name, ucm_list_section_devices_callback cb,
-	void *cb_arg)
+		struct cras_use_case_mgr *mgr,
+		enum CRAS_STREAM_DIRECTION direction,
+		const char *device_name,
+		ucm_list_section_devices_callback cb,
+		void *cb_arg)
 {
-	int listed = 0;
+	int listed= 0;
 	struct section_name *section_names, *c;
-	const char *var;
+	const char* var;
 	char *identifier;
 
 	if (direction == CRAS_STREAM_OUTPUT)
@@ -1052,20 +1034,20 @@
 		return 0;
 
 	identifier = snd_use_case_identifier("_devices/%s", uc_verb(mgr));
-	section_names = ucm_get_sections_for_var(mgr, var, device_name,
-						 identifier, direction);
+	section_names = ucm_get_sections_for_var(
+		mgr, var, device_name, identifier, direction);
 	free(identifier);
 	if (!section_names)
 		return 0;
 
-	DL_FOREACH (section_names, c) {
+	DL_FOREACH(section_names, c) {
 		cb(c->name, cb_arg);
 		listed++;
 	}
 
-	DL_FOREACH (section_names, c) {
+	DL_FOREACH(section_names, c) {
 		DL_DELETE(section_names, c);
-		free((void *)c->name);
+		free((void*)c->name);
 		free(c);
 	}
 	return listed;
@@ -1094,10 +1076,9 @@
 	if (rc)
 		return NULL;
 
-	if (strcmp(name, "hctl") && strcmp(name, "gpio") &&
-	    strcmp(name, "always")) {
+	if (strcmp(name, "hctl") && strcmp(name, "gpio")) {
 		syslog(LOG_ERR, "Unknown jack type: %s", name);
-		if (name)
+		if(name)
 			free((void *)name);
 		return NULL;
 	}
diff --git a/cras/src/server/cras_alsa_ucm.h b/cras/src/server/cras_alsa_ucm.h
index 36f68a0..38377a0 100644
--- a/cras/src/server/cras_alsa_ucm.h
+++ b/cras/src/server/cras_alsa_ucm.h
@@ -31,6 +31,7 @@
  */
 struct cras_use_case_mgr *ucm_create(const char *name);
 
+
 /* Destroys a cras_use_case_mgr that was returned from ucm_create.
  * Args:
  *    mgr - The cras_use_case_mgr pointer returned from alsa_ucm_create.
@@ -155,6 +156,18 @@
 const char *ucm_get_edid_file_for_dev(struct cras_use_case_mgr *mgr,
 				      const char *dev);
 
+/* Gets the dsp name which is associated with the given ucm device.
+ * Args:
+ *    mgr - The cras_use_case_mgr pointer returned from alsa_ucm_create.
+ *    ucm_dev - The ucm device to get dsp name for.
+ *    direction - playback(CRAS_STREAM_OUTPUT) or capture(CRAS_STREAM_INPUT).
+ * Returns:
+ *    A pointer to the allocated string containing the dsp name, or NULL if no
+ *    dsp name is found.
+ */
+const char *ucm_get_dsp_name(struct cras_use_case_mgr *mgr, const char *ucm_dev,
+			     int direction);
+
 /* Gets the default dsp name.
  * Args:
  *    mgr - The cras_use_case_mgr pointer returned from alsa_ucm_create.
@@ -166,17 +179,6 @@
 const char *ucm_get_dsp_name_default(struct cras_use_case_mgr *mgr,
 				     int direction);
 
-/* Gets the dsp name which is associated with the given ucm device.
- * Args:
- *    mgr - The cras_use_case_mgr pointer returned from alsa_ucm_create.
- *    dev - The device to get dsp name for.
- * Returns:
- *    A pointer to the allocated string containing the dsp name, or NULL if no
- *    dsp name is found.
- */
-const char *ucm_get_dsp_name_for_dev(struct cras_use_case_mgr *mgr,
-				     const char *dev);
-
 /* Gets the minimum buffer level for an output.  This level will add latency to
  * all streams playing on the output, but can be used to work around an
  * unreliable dma residue.
@@ -250,9 +252,9 @@
  *    if no device name is found. The device name is of format
  *    "card_name:device_index".
  */
-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);
 
 /* Gets the node name of the echo reference device on the card.
  * Args:
@@ -263,9 +265,8 @@
  *    dev, caller is responsible to free it later. NULL if echo reference
  *    doesn't exist.
  */
-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);
 
 /* Gets the sample rate at which to run this device.
  *
@@ -286,7 +287,8 @@
  *    channel_layout - The channel layout to fill.
  */
 int ucm_get_capture_chmap_for_dev(struct cras_use_case_mgr *mgr,
-				  const char *dev, int8_t *channel_layout);
+				  const char *dev,
+				  int8_t *channel_layout);
 
 /* Gets the mixer names for the coupled mixer controls of this device
  * on the card.
@@ -297,8 +299,8 @@
  * Returns:
  *    A list of cras_alsa_control.
  */
-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);
 
 /* Gets a list of UCM sections
  *
@@ -372,8 +374,8 @@
  *    section_name: The name of a SectionDevice in UCM.
  *    arg - Argument to pass to this callback.
  */
-typedef void (*ucm_list_section_devices_callback)(const char *section_name,
-						  void *arg);
+typedef void (*ucm_list_section_devices_callback)(
+		const char *section_name, void *arg);
 
 /* Invokes the provided callback once for each section with matched device name.
  *
@@ -390,9 +392,11 @@
  *    Number of sections listed.
  */
 int ucm_list_section_devices_by_device_name(
-	struct cras_use_case_mgr *mgr, enum CRAS_STREAM_DIRECTION direction,
-	const char *device_name, ucm_list_section_devices_callback cb,
-	void *cb_arg);
+		struct cras_use_case_mgr *mgr,
+		enum CRAS_STREAM_DIRECTION direction,
+		const char *device_name,
+		ucm_list_section_devices_callback cb,
+		void *cb_arg);
 
 /* Gets the jack name of this device on the card.
  *
diff --git a/cras/src/server/cras_alsa_ucm_section.c b/cras/src/server/cras_alsa_ucm_section.c
index 36d4422..179706d 100644
--- a/cras/src/server/cras_alsa_ucm_section.c
+++ b/cras/src/server/cras_alsa_ucm_section.c
@@ -11,8 +11,7 @@
 #include "cras_alsa_mixer_name.h"
 #include "utlist.h"
 
-static void ucm_section_free(struct ucm_section *section)
-{
+static void ucm_section_free(struct ucm_section *section) {
 	if (section->name)
 		free((void *)section->name);
 	if (section->jack_name)
@@ -28,13 +27,14 @@
 void ucm_section_free_list(struct ucm_section *sections)
 {
 	struct ucm_section *section;
-	DL_FOREACH (sections, section) {
+	DL_FOREACH(sections, section) {
 		DL_DELETE(sections, section);
 		ucm_section_free(section);
 	}
 }
 
-struct ucm_section *ucm_section_create(const char *name, int dev_idx,
+struct ucm_section *ucm_section_create(const char *name,
+				       int dev_idx,
 				       enum CRAS_STREAM_DIRECTION dir,
 				       const char *jack_name,
 				       const char *jack_type)
@@ -45,7 +45,8 @@
 	if (!name)
 		return NULL;
 
-	section = (struct ucm_section *)calloc(1, sizeof(struct ucm_section));
+	section = (struct ucm_section *)
+		  calloc(1, sizeof(struct ucm_section));
 	if (!section)
 		return NULL;
 
@@ -77,7 +78,8 @@
 	return NULL;
 }
 
-int ucm_section_set_mixer_name(struct ucm_section *section, const char *name)
+int ucm_section_set_mixer_name(struct ucm_section *section,
+			       const char *name)
 {
 	if (!section || !name)
 		return -EINVAL;
@@ -90,7 +92,8 @@
 	return 0;
 }
 
-int ucm_section_add_coupled(struct ucm_section *section, const char *name,
+int ucm_section_add_coupled(struct ucm_section *section,
+			    const char *name,
 			    mixer_name_type type)
 {
 	struct mixer_name *m_name;
@@ -116,11 +119,11 @@
 
 void ucm_section_dump(struct ucm_section *section)
 {
-	syslog(LOG_DEBUG, "section: %s [%d] (%s)", section->name,
-	       section->dev_idx,
-	       section->dir == CRAS_STREAM_OUTPUT ? "output" : "input");
-	syslog(LOG_DEBUG, "  jack: %s %s", section->jack_name,
-	       section->jack_type);
+	syslog(LOG_DEBUG, "section: %s [%d] (%s)",
+		section->name, section->dev_idx,
+		section->dir == CRAS_STREAM_OUTPUT ? "output" : "input");
+	syslog(LOG_DEBUG, "  jack: %s %s",
+		section->jack_name, section->jack_type);
 	syslog(LOG_DEBUG, "  mixer_name: %s", section->mixer_name);
 	mixer_name_dump(section->coupled, "  coupled");
 }
diff --git a/cras/src/server/cras_alsa_ucm_section.h b/cras/src/server/cras_alsa_ucm_section.h
index 0ffa5ab..bd0c2ef 100644
--- a/cras/src/server/cras_alsa_ucm_section.h
+++ b/cras/src/server/cras_alsa_ucm_section.h
@@ -15,22 +15,15 @@
 
 /* Represents an ALSA UCM section. */
 struct ucm_section {
-	/* Section name. */
-	const char *name;
-	/* Device PCM index. */
-	int dev_idx;
-	/* Output or Input. */
-	enum CRAS_STREAM_DIRECTION dir;
-	/* Associated jack's name. */
-	const char *jack_name;
-	/* Associated jack's type. */
-	const char *jack_type;
-	/* Switch number for jack from linux/input.h, or -1. */
-	int jack_switch;
-	/* MixerName value. */
-	const char *mixer_name;
-	/* CoupledMixers value. */
-	struct mixer_name *coupled;
+	const char *name;                /* Section name. */
+	int dev_idx;                     /* Device PCM index. */
+	enum CRAS_STREAM_DIRECTION dir;  /* Output or Input. */
+	const char *jack_name;           /* Associated jack's name. */
+	const char *jack_type;           /* Associated jack's type. */
+	int jack_switch;                 /* Switch number for jack from
+	                                  * linux/input.h, or -1. */
+	const char *mixer_name;          /* MixerName value. */
+	struct mixer_name *coupled;      /* CoupledMixers value. */
 	struct ucm_section *prev, *next;
 };
 
@@ -46,7 +39,8 @@
  * Returns:
  *    A valid pointer on success, NULL for memory allocation error.
  */
-struct ucm_section *ucm_section_create(const char *name, int dev_idx,
+struct ucm_section *ucm_section_create(const char *name,
+				       int dev_idx,
 				       enum CRAS_STREAM_DIRECTION dir,
 				       const char *jack_name,
 				       const char *jack_type);
@@ -60,7 +54,8 @@
  * Returns:
  *    0 for success, -EINVAL for invalid arguments, or -ENOMEM.
  */
-int ucm_section_set_mixer_name(struct ucm_section *section, const char *name);
+int ucm_section_set_mixer_name(struct ucm_section *section,
+			       const char *name);
 
 /* Add a single coupled control to this section.
  * Control has the same direction as the section.
@@ -73,7 +68,8 @@
  * Returns:
  *    0 for success, -EINVAL for invalid arguments, or -ENOMEM.
  */
-int ucm_section_add_coupled(struct ucm_section *section, const char *name,
+int ucm_section_add_coupled(struct ucm_section *section,
+			    const char *name,
 			    mixer_name_type type);
 
 /* Concatenate a list of coupled controls to this section.
diff --git a/cras/src/server/cras_apm_list.c b/cras/src/server/cras_apm_list.c
index d0ea9a9..ac0935e 100644
--- a/cras/src/server/cras_apm_list.c
+++ b/cras/src/server/cras_apm_list.c
@@ -3,12 +3,13 @@
  * found in the LICENSE file.
  */
 
-#include <inttypes.h>
 #include <string.h>
 #include <syslog.h>
 
 #include <webrtc-apm/webrtc_apm.h>
 
+#include "aec_config.h"
+#include "apm_config.h"
 #include "byte_buffer.h"
 #include "cras_apm_list.h"
 #include "cras_audio_area.h"
@@ -19,13 +20,8 @@
 #include "dsp_util.h"
 #include "dumper.h"
 #include "float_buffer.h"
-#include "iniparser_wrapper.h"
 #include "utlist.h"
 
-static const unsigned int MAX_INI_NAME_LEN = 63;
-
-#define AEC_CONFIG_NAME "aec.ini"
-#define APM_CONFIG_NAME "apm.ini"
 
 /*
  * Structure holding a WebRTC audio processing module and necessary
@@ -113,10 +109,9 @@
 
 static struct cras_apm_reverse_module *rmodule = NULL;
 static struct cras_apm_list *apm_list = NULL;
+static struct aec_config *aec_config = NULL;
+static struct apm_config *apm_config = NULL;
 static const char *aec_config_dir = NULL;
-static char ini_name[MAX_INI_NAME_LEN + 1];
-static dictionary *aec_ini = NULL;
-static dictionary *apm_ini = NULL;
 
 /* Update the global process reverse flag. Should be called when apms are added
  * or removed. */
@@ -127,7 +122,7 @@
 	if (!rmodule)
 		return;
 	rmodule->process_reverse = 0;
-	DL_FOREACH (apm_list, list) {
+	DL_FOREACH(apm_list, list) {
 		rmodule->process_reverse |=
 			!!(list->effects & APM_ECHO_CANCELLATION);
 	}
@@ -147,7 +142,8 @@
 	*apm = NULL;
 }
 
-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)
 {
 	struct cras_apm_list *list;
 
@@ -174,7 +170,7 @@
 	if (list == NULL)
 		return NULL;
 
-	DL_FOREACH (list->apms, apm) {
+	DL_FOREACH(list->apms, apm) {
 		if (apm->dev_ptr == dev_ptr)
 			return apm;
 	}
@@ -193,8 +189,8 @@
 {
 	struct cras_apm *apm;
 
-	DL_FOREACH (list->apms, apm) {
-		if (apm->dev_ptr == dev_ptr) {
+	DL_FOREACH(list->apms, apm) {
+		if (apm->dev_ptr == dev_ptr ) {
 			DL_DELETE(list->apms, apm);
 			apm_destroy(&apm);
 		}
@@ -225,7 +221,7 @@
 	 * TODO(hychao): extend the logic when we have a stream that wants
 	 * to record channels like RR(rear right).
 	 */
-	for (ch = 0; ch < CRAS_CH_MAX; ch++)
+	for (ch = 0 ; ch < CRAS_CH_MAX; ch++)
 		layout[ch] = -1;
 
 	apm_fmt->num_channels = 0;
@@ -236,18 +232,22 @@
 	if (apm_fmt->channel_layout[CRAS_CH_FC] != -1)
 		layout[CRAS_CH_FC] = apm_fmt->num_channels++;
 
-	for (ch = 0; ch < CRAS_CH_MAX; ch++)
+	for (ch = 0 ; ch < CRAS_CH_MAX; ch++)
 		apm_fmt->channel_layout[ch] = layout[ch];
 }
 
-struct cras_apm *cras_apm_list_add(struct cras_apm_list *list, void *dev_ptr,
+struct cras_apm *cras_apm_list_add(struct cras_apm_list *list,
+				   void *dev_ptr,
 				   const struct cras_audio_format *dev_fmt)
 {
 	struct cras_apm *apm;
 
-	DL_FOREACH (list->apms, apm)
-		if (apm->dev_ptr == dev_ptr)
-			return apm;
+	DL_FOREACH(list->apms, apm) {
+		if (apm->dev_ptr == dev_ptr) {
+			DL_DELETE(list->apms, apm);
+			apm_destroy(&apm);
+		}
+	}
 
 	// TODO(hychao): Remove the check when we enable more effects.
 	if (!(list->effects & APM_ECHO_CANCELLATION))
@@ -262,14 +262,17 @@
 	apm->fmt = *dev_fmt;
 	get_best_channels(&apm->fmt);
 
-	apm->apm_ptr = webrtc_apm_create(apm->fmt.num_channels,
-					 apm->fmt.frame_rate, aec_ini, apm_ini);
+	apm->apm_ptr = webrtc_apm_create(
+			apm->fmt.num_channels,
+			apm->fmt.frame_rate,
+			aec_config,
+			apm_config);
 	if (apm->apm_ptr == NULL) {
-		syslog(LOG_ERR,
-		       "Fail to create webrtc apm for ch %zu"
-		       " rate %zu effect %" PRIu64,
-		       dev_fmt->num_channels, dev_fmt->frame_rate,
-		       list->effects);
+		syslog(LOG_ERR, "Fail to create webrtc apm for ch %zu"
+				" rate %zu effect %lu",
+				dev_fmt->num_channels,
+				dev_fmt->frame_rate,
+				list->effects);
 		free(apm);
 		return NULL;
 	}
@@ -296,7 +299,7 @@
 	struct cras_apm_list *tmp;
 	struct cras_apm *apm;
 
-	DL_FOREACH (apm_list, tmp) {
+	DL_FOREACH(apm_list, tmp) {
 		if (tmp == list) {
 			DL_DELETE(apm_list, tmp);
 			break;
@@ -306,7 +309,7 @@
 	if (tmp == NULL)
 		return 0;
 
-	DL_FOREACH (list->apms, apm) {
+	DL_FOREACH(list->apms, apm) {
 		DL_DELETE(list->apms, apm);
 		apm_destroy(&apm);
 	}
@@ -324,7 +327,9 @@
  */
 static struct cras_iodev *get_echo_reference_target(struct cras_iodev *iodev)
 {
-	return iodev->echo_reference_dev ? iodev->echo_reference_dev : iodev;
+	return iodev->echo_reference_dev
+			? iodev->echo_reference_dev
+			: iodev;
 }
 
 /*
@@ -339,23 +344,13 @@
 {
 	struct cras_iodev *echo_ref;
 	struct cras_iodev *iodev =
-		cras_iodev_list_get_first_enabled_iodev(CRAS_STREAM_OUTPUT);
+			cras_iodev_list_get_first_enabled_iodev(
+				CRAS_STREAM_OUTPUT);
 
 	if (iodev == NULL)
 		return;
 
 	echo_ref = get_echo_reference_target(iodev);
-
-	/* If rmodule is already tracking echo_ref, do nothing. */
-	if (rmodule->odev == echo_ref)
-		return;
-
-	/* Detach from the old iodev that rmodule was tracking. */
-	if (rmodule->odev) {
-		cras_iodev_set_ext_dsp_module(rmodule->odev, NULL);
-		rmodule->odev = NULL;
-	}
-
 	rmodule->odev = echo_ref;
 	cras_iodev_set_ext_dsp_module(echo_ref, &rmodule->ext);
 }
@@ -399,16 +394,19 @@
 
 	wp = float_buffer_write_pointer(fbuf);
 
-	DL_FOREACH (apm_list, list) {
+	DL_FOREACH(apm_list, list) {
 		if (!(list->effects & APM_ECHO_CANCELLATION))
 			continue;
 
-		DL_FOREACH (list->apms, apm) {
+		DL_FOREACH(list->apms, apm) {
 			ret = webrtc_apm_process_reverse_stream_f(
-				apm->apm_ptr, fbuf->num_channels, frame_rate,
-				wp);
+					apm->apm_ptr,
+					fbuf->num_channels,
+					frame_rate,
+					wp);
 			if (ret) {
-				syslog(LOG_ERR, "APM process reverse err");
+				syslog(LOG_ERR,
+				       "APM process reverse err");
 				return ret;
 			}
 		}
@@ -417,10 +415,11 @@
 	return 0;
 }
 
-void reverse_data_run(struct ext_dsp_module *ext, unsigned int nframes)
+void reverse_data_run(struct ext_dsp_module *ext,
+		      unsigned int nframes)
 {
 	struct cras_apm_reverse_module *rmod =
-		(struct cras_apm_reverse_module *)ext;
+			(struct cras_apm_reverse_module *)ext;
 	unsigned int writable;
 	int i, offset = 0;
 	float *const *wp;
@@ -444,63 +443,41 @@
 }
 
 void reverse_data_configure(struct ext_dsp_module *ext,
-			    unsigned int buffer_size, unsigned int num_channels,
+			    unsigned int buffer_size,
+			    unsigned int num_channels,
 			    unsigned int rate)
 {
 	struct cras_apm_reverse_module *rmod =
-		(struct cras_apm_reverse_module *)ext;
+			(struct cras_apm_reverse_module *)ext;
 	if (rmod->fbuf)
 		float_buffer_destroy(&rmod->fbuf);
-	rmod->fbuf = float_buffer_create(rate / 100, num_channels);
+	rmod->fbuf = float_buffer_create(rate / 100,
+					 num_channels);
 	rmod->dev_rate = rate;
 }
 
-static void get_aec_ini(const char *config_dir)
-{
-	snprintf(ini_name, MAX_INI_NAME_LEN, "%s/%s", config_dir,
-		 AEC_CONFIG_NAME);
-	ini_name[MAX_INI_NAME_LEN] = '\0';
-
-	if (aec_ini) {
-		iniparser_freedict(aec_ini);
-		aec_ini = NULL;
-	}
-	aec_ini = iniparser_load_wrapper(ini_name);
-	if (aec_ini == NULL)
-		syslog(LOG_INFO, "No aec ini file %s", ini_name);
-}
-
-static void get_apm_ini(const char *config_dir)
-{
-	snprintf(ini_name, MAX_INI_NAME_LEN, "%s/%s", config_dir,
-		 APM_CONFIG_NAME);
-	ini_name[MAX_INI_NAME_LEN] = '\0';
-
-	if (apm_ini) {
-		iniparser_freedict(apm_ini);
-		apm_ini = NULL;
-	}
-	apm_ini = iniparser_load_wrapper(ini_name);
-	if (apm_ini == NULL)
-		syslog(LOG_INFO, "No apm ini file %s", ini_name);
-}
-
 int cras_apm_list_init(const char *device_config_dir)
 {
 	if (rmodule == NULL) {
-		rmodule = (struct cras_apm_reverse_module *)calloc(
-			1, sizeof(*rmodule));
+		rmodule = (struct cras_apm_reverse_module *)
+				calloc(1, sizeof(*rmodule));
 		rmodule->ext.run = reverse_data_run;
 		rmodule->ext.configure = reverse_data_configure;
 	}
 
 	aec_config_dir = device_config_dir;
-	get_aec_ini(aec_config_dir);
-	get_apm_ini(aec_config_dir);
+	if (aec_config)
+		free(aec_config);
+	aec_config = aec_config_get(device_config_dir);
+	if (apm_config)
+		free(apm_config);
+	apm_config = apm_config_get(device_config_dir);
 
 	update_first_output_dev_to_process();
 	cras_iodev_list_set_device_enabled_callback(
-		handle_device_enabled, handle_device_disabled, rmodule);
+			handle_device_enabled,
+			handle_device_disabled,
+			rmodule);
 
 	return 0;
 }
@@ -510,11 +487,21 @@
 	if (NULL == aec_config_dir)
 		return;
 
-	get_aec_ini(aec_config_dir);
-	get_apm_ini(aec_config_dir);
+	if (aec_config)
+		free(aec_config);
+	aec_config = aec_config_get(aec_config_dir);
 
 	/* Dump the config content at reload only, for debug. */
-	webrtc_apm_dump_configs(apm_ini, aec_ini);
+	if (aec_config)
+		aec_config_dump(aec_config);
+
+	if (apm_config)
+		free(apm_config);
+	apm_config = apm_config_get(aec_config_dir);
+
+	/* Dump the config content at reload only, for debug. */
+	if (apm_config)
+		apm_config_dump(apm_config);
 }
 
 int cras_apm_list_deinit()
@@ -523,12 +510,12 @@
 		if (rmodule->fbuf)
 			float_buffer_destroy(&rmodule->fbuf);
 		free(rmodule);
-		rmodule = NULL;
 	}
 	return 0;
 }
 
-int cras_apm_list_process(struct cras_apm *apm, struct float_buffer *input,
+int cras_apm_list_process(struct cras_apm *apm,
+			  struct float_buffer *input,
 			  unsigned int offset)
 {
 	unsigned int writable, nframes, nread;
@@ -576,19 +563,22 @@
 
 	/* process and move to int buffer */
 	if ((float_buffer_writable(apm->fbuffer) == 0) &&
-	    (buf_queued(apm->buffer) == 0)) {
+            (buf_queued(apm->buffer) == 0)) {
 		nread = float_buffer_level(apm->fbuffer);
 		rp = float_buffer_read_pointer(apm->fbuffer, 0, &nread);
 		ret = webrtc_apm_process_stream_f(apm->apm_ptr,
 						  apm->fmt.num_channels,
-						  apm->fmt.frame_rate, rp);
+						  apm->fmt.frame_rate,
+						  rp);
 		if (ret) {
 			syslog(LOG_ERR, "APM process stream f err");
 			return ret;
 		}
 
-		dsp_util_interleave(rp, buf_write_pointer(apm->buffer),
-				    apm->fbuffer->num_channels, apm->fmt.format,
+		dsp_util_interleave(rp,
+				    buf_write_pointer(apm->buffer),
+				    apm->fbuffer->num_channels,
+				    apm->fmt.format,
 				    nread);
 		buf_increment_write(apm->buffer,
 				    nread * cras_get_format_bytes(&apm->fmt));
@@ -636,7 +626,7 @@
 		if (handle == NULL) {
 			syslog(LOG_ERR, "Create dump handle fail, errno %d",
 			       errno);
-			return;
+			return ;
 		}
 		/* webrtc apm will own the FILE handle and close it. */
 		rc = webrtc_apm_aec_dump(apm->apm_ptr, &apm->work_queue, start,
diff --git a/cras/src/server/cras_apm_list.h b/cras/src/server/cras_apm_list.h
index 486b943..c7450d3 100644
--- a/cras/src/server/cras_apm_list.h
+++ b/cras/src/server/cras_apm_list.h
@@ -32,18 +32,18 @@
  *    stream_ptr - Pointer to the stream.
  *    effects - Bit map specifying the enabled effects on this stream.
  */
-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);
 
 /*
- * Creates a cras_apm associated to given dev_ptr and adds it to the list.
- * If there already exists an APM instance linked to dev_ptr, we assume
- * the open format is unchanged so just return it.
+ * Creates a cras_apm and adds it to the list.
  * Args:
  *    list - The list holding APM instances.
  *    dev_ptr - Pointer to the iodev to add new APM for.
  *    fmt - Format of the audio data used for this cras_apm.
  */
-struct cras_apm *cras_apm_list_add(struct cras_apm_list *list, void *dev_ptr,
+struct cras_apm *cras_apm_list_add(struct cras_apm_list *list,
+				   void *dev_ptr,
 				   const struct cras_audio_format *fmt);
 
 /*
@@ -52,7 +52,8 @@
  *    list - The list holding APM instances.
  *    dev_ptr - The iodev as key to look up associated APM.
  */
-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);
 
 /*
  * Gets the effects bit map of the APM list.
@@ -80,7 +81,8 @@
  *    offset - Offset in |input| to note the data position to start
  *        reading.
  */
-int cras_apm_list_process(struct cras_apm *apm, struct float_buffer *input,
+int cras_apm_list_process(struct cras_apm *apm,
+			  struct float_buffer *input,
 			  unsigned int offset);
 
 /* Gets the APM processed data in the form of audio area.
@@ -114,8 +116,10 @@
  *    start - True to set debug recording start, otherwise stop.
  *    fd - File descriptor to aec dump destination.
  */
-void cras_apm_list_set_aec_dump(struct cras_apm_list *list, void *dev_ptr,
-				int start, int fd);
+void cras_apm_list_set_aec_dump(struct cras_apm_list *list,
+				void *dev_ptr,
+			        int start,
+			        int fd);
 
 #else
 
@@ -136,9 +140,10 @@
 {
 	return NULL;
 }
-static inline struct cras_apm *
-cras_apm_list_add(struct cras_apm_list *list, void *dev_ptr,
-		  const struct cras_audio_format *fmt)
+static inline struct cras_apm *cras_apm_list_add(
+		struct cras_apm_list *list,
+		void *dev_ptr,
+		const struct cras_audio_format *fmt)
 {
 	return NULL;
 }
@@ -167,8 +172,8 @@
 	return 0;
 }
 
-static inline struct cras_audio_area *
-cras_apm_list_get_processed(struct cras_apm *apm)
+static inline struct cras_audio_area *cras_apm_list_get_processed(
+		struct cras_apm *apm)
 {
 	return NULL;
 }
@@ -178,14 +183,16 @@
 {
 }
 
-static inline struct cras_audio_format *
-cras_apm_list_get_format(struct cras_apm *apm)
+static inline struct cras_audio_format *cras_apm_list_get_format(
+		struct cras_apm *apm)
 {
 	return NULL;
 }
 
 static inline void cras_apm_list_set_aec_dump(struct cras_apm_list *list,
-					      void *dev_ptr, int start, int fd)
+					      void *dev_ptr,
+					      int start,
+					      int fd)
 {
 }
 
diff --git a/cras/src/server/cras_audio_area.c b/cras/src/server/cras_audio_area.c
index 1861573..5def7ea 100644
--- a/cras/src/server/cras_audio_area.c
+++ b/cras/src/server/cras_audio_area.c
@@ -37,6 +37,7 @@
 
 	/* 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))
@@ -47,11 +48,11 @@
 			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);
 		}
 	}
 
@@ -85,9 +86,9 @@
 		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,
@@ -98,7 +99,7 @@
 	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 fe04232..1111ee4 100644
--- a/cras/src/server/cras_audio_area.h
+++ b/cras/src/server/cras_audio_area.h
@@ -42,8 +42,9 @@
  *    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 5921245..9a23b00 100644
--- a/cras/src/server/cras_audio_thread_monitor.c
+++ b/cras/src/server/cras_audio_thread_monitor.c
@@ -23,8 +23,8 @@
 {
 	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 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,33 +46,36 @@
 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);
-	return cras_main_message_send(&msg.header);
+	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;
 }
 
-int cras_audio_thread_event_debug()
+int cras_audio_thread_debug()
 {
 	return cras_audio_thread_event_send(AUDIO_THREAD_EVENT_DEBUG);
 }
 
-int cras_audio_thread_event_busyloop()
+int cras_audio_thread_busyloop()
 {
 	return cras_audio_thread_event_send(AUDIO_THREAD_EVENT_BUSYLOOP);
 }
 
-int cras_audio_thread_event_underrun()
+int cras_audio_thread_underrun()
 {
 	return cras_audio_thread_event_send(AUDIO_THREAD_EVENT_UNDERRUN);
 }
 
-int cras_audio_thread_event_severe_underrun()
+int cras_audio_thread_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_DROP_SAMPLES);
+	return cras_audio_thread_event_send(
+		AUDIO_THREAD_EVENT_SEVERE_UNDERRUN);
 }
 
 static struct timespec last_event_snapshot_time[AUDIO_THREAD_EVENT_TYPE_COUNT];
@@ -83,9 +86,9 @@
  * 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;
@@ -93,7 +96,7 @@
 	/*
 	 * 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 =
@@ -106,9 +109,10 @@
 	 */
 	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;
 	}
@@ -116,8 +120,8 @@
 
 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 b7355ca..f2044bf 100644
--- a/cras/src/server/cras_audio_thread_monitor.h
+++ b/cras/src/server/cras_audio_thread_monitor.h
@@ -9,27 +9,22 @@
 /*
  * Sends a debug event to the audio thread for debugging.
  */
-int cras_audio_thread_event_debug();
+int cras_audio_thread_debug();
 
 /*
  * Notifies the main thread when a busyloop event happens.
  */
-int cras_audio_thread_event_busyloop();
+int cras_audio_thread_busyloop();
 
 /*
  * Notifies the main thread when a underrun event happens.
  */
-int cras_audio_thread_event_underrun();
+int cras_audio_thread_underrun();
 
 /*
  * Notifies the main thread when a severe underrun event happens.
  */
-int cras_audio_thread_event_severe_underrun();
-
-/*
- * Notifies the main thread when a drop samples event happens.
- */
-int cras_audio_thread_event_drop_samples();
+int cras_audio_thread_severe_underrun();
 
 /*
  * 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 bcdecef..f84e01e 100644
--- a/cras/src/server/cras_bt_adapter.c
+++ b/cras/src/server/cras_bt_adapter.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
@@ -18,28 +18,13 @@
 #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;
 };
@@ -80,8 +65,7 @@
 	return 0;
 }
 
-struct cras_bt_adapter *cras_bt_adapter_create(DBusConnection *conn,
-					       const char *object_path)
+struct cras_bt_adapter *cras_bt_adapter_create(const char *object_path)
 {
 	struct cras_bt_adapter *adapter;
 
@@ -89,7 +73,6 @@
 	if (adapter == NULL)
 		return NULL;
 
-	adapter->conn = conn;
 	adapter->object_path = strdup(object_path);
 	if (adapter->object_path == NULL) {
 		free(adapter);
@@ -124,6 +107,7 @@
 	}
 }
 
+
 struct cras_bt_adapter *cras_bt_adapter_get(const char *object_path)
 {
 	struct cras_bt_adapter *adapter;
@@ -131,7 +115,7 @@
 	if (object_path == NULL)
 		return NULL;
 
-	DL_FOREACH (adapters, adapter) {
+	DL_FOREACH(adapters, adapter) {
 		if (strcmp(adapter->object_path, object_path) == 0)
 			return adapter;
 	}
@@ -145,7 +129,7 @@
 	struct cras_bt_adapter **adapter_list = NULL;
 	size_t num_adapters = 0;
 
-	DL_FOREACH (adapters, adapter) {
+	DL_FOREACH(adapters, adapter) {
 		struct cras_bt_adapter **tmp;
 
 		tmp = realloc(adapter_list,
@@ -183,17 +167,6 @@
 	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,
@@ -226,6 +199,7 @@
 			} else if (strcmp(key, "Alias") == 0) {
 				free(adapter->name);
 				adapter->name = strdup(value);
+
 			}
 
 		} else if (type == DBUS_TYPE_UINT32) {
@@ -242,7 +216,8 @@
 			dbus_message_iter_get_basic(&variant_iter, &value);
 
 			if (strcmp(key, "Powered") == 0)
-				bt_adapter_set_powered(adapter, value);
+				adapter->powered = value;
+
 		}
 
 		dbus_message_iter_next(properties_array_iter);
@@ -250,7 +225,7 @@
 
 	while (invalidated_array_iter &&
 	       dbus_message_iter_get_arg_type(invalidated_array_iter) !=
-		       DBUS_TYPE_INVALID) {
+	       DBUS_TYPE_INVALID) {
 		const char *key;
 
 		dbus_message_iter_get_basic(invalidated_array_iter, &key);
@@ -274,110 +249,4 @@
 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;
-}
+}
\ No newline at end of file
diff --git a/cras/src/server/cras_bt_adapter.h b/cras/src/server/cras_bt_adapter.h
index dc07b68..8add361 100644
--- a/cras/src/server/cras_bt_adapter.h
+++ b/cras/src/server/cras_bt_adapter.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
@@ -10,14 +10,7 @@
 
 struct cras_bt_adapter;
 
-/* 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);
+struct cras_bt_adapter *cras_bt_adapter_create(const char *object_path);
 void cras_bt_adapter_destroy(struct cras_bt_adapter *adapter);
 void cras_bt_adapter_reset();
 
@@ -30,10 +23,6 @@
 
 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,
@@ -41,10 +30,4 @@
 
 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 8d9ad5d..13a1737 100644
--- a/cras/src/server/cras_bt_constants.h
+++ b/cras/src/server/cras_bt_constants.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
@@ -6,7 +6,7 @@
 #ifndef CRAS_BT_CONSTANTS_H_
 #define CRAS_BT_CONSTANTS_H_
 
-#define BLUEZ_SERVICE "org.chromium.Bluetooth"
+#define BLUEZ_SERVICE "org.bluez"
 
 #define BLUEZ_INTERFACE_ADAPTER "org.bluez.Adapter1"
 #define BLUEZ_INTERFACE_DEVICE "org.bluez.Device1"
@@ -22,18 +22,18 @@
 #endif
 
 /* UUIDs taken from lib/uuid.h in the BlueZ source */
-#define HSP_HS_UUID "00001108-0000-1000-8000-00805f9b34fb"
-#define HSP_AG_UUID "00001112-0000-1000-8000-00805f9b34fb"
+#define HSP_HS_UUID             "00001108-0000-1000-8000-00805f9b34fb"
+#define HSP_AG_UUID             "00001112-0000-1000-8000-00805f9b34fb"
 
-#define HFP_HF_UUID "0000111e-0000-1000-8000-00805f9b34fb"
-#define HFP_AG_UUID "0000111f-0000-1000-8000-00805f9b34fb"
+#define HFP_HF_UUID             "0000111e-0000-1000-8000-00805f9b34fb"
+#define HFP_AG_UUID             "0000111f-0000-1000-8000-00805f9b34fb"
 
-#define A2DP_SOURCE_UUID "0000110a-0000-1000-8000-00805f9b34fb"
-#define A2DP_SINK_UUID "0000110b-0000-1000-8000-00805f9b34fb"
+#define A2DP_SOURCE_UUID        "0000110a-0000-1000-8000-00805f9b34fb"
+#define A2DP_SINK_UUID          "0000110b-0000-1000-8000-00805f9b34fb"
 
-#define AVRCP_REMOTE_UUID "0000110e-0000-1000-8000-00805f9b34fb"
-#define AVRCP_TARGET_UUID "0000110c-0000-1000-8000-00805f9b34fb"
+#define AVRCP_REMOTE_UUID       "0000110e-0000-1000-8000-00805f9b34fb"
+#define AVRCP_TARGET_UUID       "0000110c-0000-1000-8000-00805f9b34fb"
 
-#define GENERIC_AUDIO_UUID "00001203-0000-1000-8000-00805f9b34fb"
+#define GENERIC_AUDIO_UUID	"00001203-0000-1000-8000-00805f9b34fb"
 
 #endif /* CRAS_BT_CONSTANTS_H_ */
diff --git a/cras/src/server/cras_bt_device.c b/cras/src/server/cras_bt_device.c
index bc6b43d..f993626 100644
--- a/cras/src/server/cras_bt_device.c
+++ b/cras/src/server/cras_bt_device.c
@@ -23,7 +23,6 @@
 #include "cras_bt_adapter.h"
 #include "cras_bt_device.h"
 #include "cras_bt_constants.h"
-#include "cras_bt_log.h"
 #include "cras_bt_io.h"
 #include "cras_bt_profile.h"
 #include "cras_hfp_ag_profile.h"
@@ -35,17 +34,10 @@
 #include "cras_tm.h"
 #include "utlist.h"
 
-/*
- * Bluetooth Core 5.0 spec, vol 4, part B, section 2 describes
- * the recommended HCI packet size in one USB transfer for CVSD
- * and MSBC codec.
- */
-#define USB_MSBC_PKT_SIZE 60
-#define USB_CVSD_PKT_SIZE 48
-#define DEFAULT_SCO_PKT_SIZE USB_CVSD_PKT_SIZE
+#define DEFAULT_HFP_MTU_BYTES 48
+
 
 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.
@@ -54,11 +46,6 @@
 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:
@@ -82,8 +69,7 @@
  *    suspend_timer - The timer used to suspend device.
  *    switch_profile_timer - The timer used to delay enabling iodev after
  *        profile switch.
- *    sco_fd - The file descriptor of the SCO connection.
- *    sco_ref_count - The reference counts of the SCO connection.
+ *    append_iodev_cb - The callback to trigger when an iodev is appended.
  */
 struct cras_bt_device {
 	DBusConnection *conn;
@@ -104,8 +90,7 @@
 	struct cras_timer *conn_watch_timer;
 	struct cras_timer *suspend_timer;
 	struct cras_timer *switch_profile_timer;
-	int sco_fd;
-	size_t sco_ref_count;
+	void (*append_iodev_cb)(void *data);
 
 	struct cras_bt_device *prev, *next;
 };
@@ -127,6 +112,12 @@
 
 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)
@@ -179,7 +170,7 @@
 
 	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR)
 		syslog(LOG_ERR, "Connect profile message replied error: %s",
-		       dbus_message_get_error_name(reply));
+			dbus_message_get_error_name(reply));
 
 	dbus_message_unref(reply);
 }
@@ -205,21 +196,26 @@
 	DBusError dbus_error;
 	DBusPendingCall *pending_call;
 
-	method_call =
-		dbus_message_new_method_call(BLUEZ_SERVICE, device->object_path,
-					     BLUEZ_INTERFACE_DEVICE,
-					     "ConnectProfile");
+	method_call = dbus_message_new_method_call(
+			BLUEZ_SERVICE,
+			device->object_path,
+			BLUEZ_INTERFACE_DEVICE,
+			"ConnectProfile");
 	if (!method_call)
 		return -ENOMEM;
 
-	if (!dbus_message_append_args(method_call, DBUS_TYPE_STRING, &uuid,
+	if (!dbus_message_append_args(method_call,
+				      DBUS_TYPE_STRING,
+				      &uuid,
 				      DBUS_TYPE_INVALID))
 		return -ENOMEM;
 
 	dbus_error_init(&dbus_error);
 
 	pending_call = NULL;
-	if (!dbus_connection_send_with_reply(conn, method_call, &pending_call,
+	if (!dbus_connection_send_with_reply(conn,
+					     method_call,
+					     &pending_call,
 					     DBUS_TIMEOUT_USE_DEFAULT)) {
 		dbus_message_unref(method_call);
 		syslog(LOG_ERR, "Failed to send Disconnect message");
@@ -227,8 +223,9 @@
 	}
 
 	dbus_message_unref(method_call);
-	if (!dbus_pending_call_set_notify(
-		    pending_call, on_connect_profile_reply, conn, NULL)) {
+	if (!dbus_pending_call_set_notify(pending_call,
+					  on_connect_profile_reply,
+					  conn, NULL)) {
 		dbus_pending_call_cancel(pending_call);
 		dbus_pending_call_unref(pending_call);
 		return -EIO;
@@ -243,17 +240,20 @@
 	DBusError dbus_error;
 	DBusPendingCall *pending_call;
 
-	method_call =
-		dbus_message_new_method_call(BLUEZ_SERVICE, device->object_path,
-					     BLUEZ_INTERFACE_DEVICE,
-					     "Disconnect");
+	method_call = dbus_message_new_method_call(
+			BLUEZ_SERVICE,
+			device->object_path,
+			BLUEZ_INTERFACE_DEVICE,
+			"Disconnect");
 	if (!method_call)
 		return -ENOMEM;
 
 	dbus_error_init(&dbus_error);
 
 	pending_call = NULL;
-	if (!dbus_connection_send_with_reply(conn, method_call, &pending_call,
+	if (!dbus_connection_send_with_reply(conn,
+					     method_call,
+					     &pending_call,
 					     DBUS_TIMEOUT_USE_DEFAULT)) {
 		dbus_message_unref(method_call);
 		syslog(LOG_ERR, "Failed to send Disconnect message");
@@ -261,7 +261,8 @@
 	}
 
 	dbus_message_unref(method_call);
-	if (!dbus_pending_call_set_notify(pending_call, on_disconnect_reply,
+	if (!dbus_pending_call_set_notify(pending_call,
+					  on_disconnect_reply,
 					  conn, NULL)) {
 		dbus_pending_call_cancel(pending_call);
 		dbus_pending_call_unref(pending_call);
@@ -270,7 +271,7 @@
 	return 0;
 }
 
-static void cras_bt_device_destroy(struct cras_bt_device *device)
+void cras_bt_device_destroy(struct cras_bt_device *device)
 {
 	struct cras_tm *tm = cras_system_state_get_tm();
 	DL_DELETE(devices, device);
@@ -281,32 +282,12 @@
 		cras_tm_cancel_timer(tm, device->switch_profile_timer);
 	if (device->suspend_timer)
 		cras_tm_cancel_timer(tm, device->suspend_timer);
-	free(device->adapter_obj_path);
 	free(device->object_path);
 	free(device->address);
 	free(device->name);
 	free(device);
 }
 
-void cras_bt_device_remove(struct cras_bt_device *device)
-{
-	/*
-	 * We expect BT stack to disconnect this device before removing it,
-	 * but it may not the case if there's issue at BT side. Print error
-	 * log whenever this happens.
-	 */
-	if (device->connected)
-		syslog(LOG_ERR, "Removing dev with connected profiles %u",
-		       device->connected_profiles);
-	/*
-	 * Possibly clean up the associated A2DP and HFP AG iodevs that are
-	 * still accessing this device.
-	 */
-	cras_a2dp_suspend_connected_device(device);
-	cras_hfp_ag_suspend_connected_device(device);
-	cras_bt_device_destroy(device);
-}
-
 void cras_bt_device_reset()
 {
 	while (devices) {
@@ -316,11 +297,12 @@
 	}
 }
 
+
 struct cras_bt_device *cras_bt_device_get(const char *object_path)
 {
 	struct cras_bt_device *device;
 
-	DL_FOREACH (devices, device) {
+	DL_FOREACH(devices, device) {
 		if (strcmp(device->object_path, object_path) == 0)
 			return device;
 	}
@@ -328,13 +310,37 @@
 	return NULL;
 }
 
+size_t cras_bt_device_get_list(struct cras_bt_device ***device_list_out)
+{
+	struct cras_bt_device *device;
+	struct cras_bt_device **device_list = NULL;
+	size_t num_devices = 0;
+
+	DL_FOREACH(devices, device) {
+		struct cras_bt_device **tmp;
+
+		tmp = realloc(device_list,
+			      sizeof(device_list[0]) * (num_devices + 1));
+		if (!tmp) {
+			free(device_list);
+			return -ENOMEM;
+		}
+
+		device_list = tmp;
+		device_list[num_devices++] = device;
+	}
+
+	*device_list_out = device_list;
+	return num_devices;
+}
+
 const char *cras_bt_device_object_path(const struct cras_bt_device *device)
 {
 	return device->object_path;
 }
 
-struct cras_bt_adapter *
-cras_bt_device_adapter(const struct cras_bt_device *device)
+struct cras_bt_adapter *cras_bt_device_adapter(
+	const struct cras_bt_device *device)
 {
 	return cras_bt_adapter_get(device->adapter_obj_path);
 }
@@ -381,8 +387,12 @@
 	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);
+				cras_bt_io_create(device, iodev, profile);
 	}
 }
 
@@ -433,7 +443,6 @@
 
 void cras_bt_device_a2dp_configured(struct cras_bt_device *device)
 {
-	BTLOG(btlog, BT_A2DP_CONFIGURED, device->connected_profiles, 0);
 	device->connected_profiles |= CRAS_BT_DEVICE_PROFILE_A2DP_SINK;
 }
 
@@ -442,8 +451,8 @@
 	struct cras_iodev *odev = device->bt_iodevs[CRAS_STREAM_OUTPUT];
 
 	/* Check if there is an output iodev with A2DP node attached. */
-	return odev &&
-	       cras_bt_io_get_profile(odev, CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE);
+	return odev && cras_bt_io_get_profile(
+			odev, CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE);
 }
 
 int cras_bt_device_can_switch_to_a2dp(struct cras_bt_device *device)
@@ -451,31 +460,43 @@
 	struct cras_iodev *idev = device->bt_iodevs[CRAS_STREAM_INPUT];
 
 	return cras_bt_device_has_a2dp(device) &&
-	       (!idev || !cras_iodev_is_open(idev));
-}
-
-static void bt_device_remove_conflict(struct cras_bt_device *device)
-{
-	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);
+		(!idev || !cras_iodev_is_open(idev));
 }
 
 int cras_bt_device_audio_gateway_initialized(struct cras_bt_device *device)
 {
-	BTLOG(btlog, BT_AUDIO_GATEWAY_INIT, device->profiles, 0);
+	int rc = 0;
+	struct cras_tm *tm;
+
 	/* 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);
+	device->connected_profiles |=
+			(CRAS_BT_DEVICE_PROFILE_HFP_HANDSFREE |
+			 CRAS_BT_DEVICE_PROFILE_HSP_HEADSET);
 
-	return 0;
+	/* 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;
 }
 
 int cras_bt_device_get_active_profile(const struct cras_bt_device *device)
@@ -528,9 +549,9 @@
 	}
 }
 
-static int
-cras_bt_device_is_profile_connected(const struct cras_bt_device *device,
-				    enum cras_bt_device_profile profile)
+static int cras_bt_device_is_profile_connected(
+		const struct cras_bt_device *device,
+		enum cras_bt_device_profile profile)
 {
 	return !!(device->connected_profiles & profile);
 }
@@ -543,59 +564,46 @@
 {
 	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) &&
+	if (cras_bt_device_supports_profile(
+			device, CRAS_BT_DEVICE_PROFILE_A2DP_SINK) &&
 	    !cras_bt_device_is_profile_connected(
-		    device, CRAS_BT_DEVICE_PROFILE_A2DP_SINK)) {
+			device, CRAS_BT_DEVICE_PROFILE_A2DP_SINK)) {
 		if (0 == device->conn_watch_retries % PROFILE_CONN_RETRIES)
-			cras_bt_device_connect_profile(device->conn, device,
-						       A2DP_SINK_UUID);
+			cras_bt_device_connect_profile(
+					device->conn, device, A2DP_SINK_UUID);
 		goto arm_retry_timer;
 	}
 
 	/* If HFP is not ready, try connect it after a while. */
 	if (cras_bt_device_supports_profile(
-		    device, CRAS_BT_DEVICE_PROFILE_HFP_HANDSFREE) &&
+			device, CRAS_BT_DEVICE_PROFILE_HFP_HANDSFREE) &&
 	    !cras_bt_device_is_profile_connected(
-		    device, CRAS_BT_DEVICE_PROFILE_HFP_HANDSFREE)) {
+			device, CRAS_BT_DEVICE_PROFILE_HFP_HANDSFREE)) {
 		if (0 == device->conn_watch_retries % PROFILE_CONN_RETRIES)
-			cras_bt_device_connect_profile(device->conn, device,
-						       HFP_HF_UUID);
+			cras_bt_device_connect_profile(
+					device->conn, device, HFP_HF_UUID);
 		goto arm_retry_timer;
 	}
 
-	/* 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))
+			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();
+
 		cras_a2dp_start(device);
+	}
 
 	if (cras_bt_device_is_profile_connected(
-		    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);
-		}
-	}
+			device, CRAS_BT_DEVICE_PROFILE_HFP_HANDSFREE))
+		cras_hfp_ag_start(device);
 	return;
 
 arm_retry_timer:
@@ -604,17 +612,17 @@
 
 	if (--device->conn_watch_retries) {
 		tm = cras_system_state_get_tm();
-		device->conn_watch_timer =
-			cras_tm_create_timer(tm, CONN_WATCH_PERIOD_MS,
-					     bt_device_conn_watch_cb, device);
+		device->conn_watch_timer = cras_tm_create_timer(tm,
+				CONN_WATCH_PERIOD_MS,
+				bt_device_conn_watch_cb, device);
 	} else {
 		syslog(LOG_ERR, "Connection watch timeout.");
 		bt_device_schedule_suspend(device, 0);
 	}
 }
 
-static void
-cras_bt_device_start_new_conn_watch_timer(struct cras_bt_device *device)
+static void cras_bt_device_start_new_conn_watch_timer(
+		struct cras_bt_device *device)
 {
 	struct cras_tm *tm = cras_system_state_get_tm();
 
@@ -622,15 +630,15 @@
 		cras_tm_cancel_timer(tm, device->conn_watch_timer);
 	}
 	device->conn_watch_retries = CONN_WATCH_MAX_RETRIES;
-	device->conn_watch_timer = cras_tm_create_timer(
-		tm, CONN_WATCH_PERIOD_MS, bt_device_conn_watch_cb, device);
+	device->conn_watch_timer = cras_tm_create_timer(tm,
+			CONN_WATCH_PERIOD_MS,
+			bt_device_conn_watch_cb, device);
 }
 
-void cras_bt_device_set_connected(struct cras_bt_device *device, int value)
+static 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);
 
 	if (device->connected && !value) {
 		cras_bt_profile_on_device_disconnected(device);
@@ -640,63 +648,21 @@
 
 	device->connected = value;
 
-	if (!device->connected && device->conn_watch_timer) {
+	if (device->connected) {
+		cras_bt_device_start_new_conn_watch_timer(device);
+	} else if (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.
- * Args:
- *    device - The BT device holding supported profiles bitmap.
- *    uuid - UUID string from the device properties notified by BlueZ.
- * Returns:
- *    True if uuid is a new audio profiles not already supported by device.
- */
-int cras_bt_device_add_supported_profiles(struct cras_bt_device *device,
-					  const char *uuid)
-{
-	enum cras_bt_device_profile profile =
-		cras_bt_device_profile_from_uuid(uuid);
-
-	if (profile == 0)
-		return 0;
-
-	/* Do nothing if this profile is not new. */
-	if (device->profiles & profile)
-		return 0;
-
-	/* 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 & 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 & CRAS_SUPPORTED_PROFILES);
-}
-
 void cras_bt_device_update_properties(struct cras_bt_device *device,
 				      DBusMessageIter *properties_array_iter,
 				      DBusMessageIter *invalidated_array_iter)
 {
-	int watch_needed = 0;
+
+	int get_profile = 0;
+
 	while (dbus_message_iter_get_arg_type(properties_array_iter) !=
 	       DBUS_TYPE_INVALID) {
 		DBusMessageIter properties_dict_iter, variant_iter;
@@ -747,14 +713,11 @@
 				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),
-				  "as") == 0 &&
+		} else if (strcmp(
+				dbus_message_iter_get_signature(&variant_iter),
+				"as") == 0 &&
 			   strcmp(key, "UUIDs") == 0) {
 			DBusMessageIter uuid_array_iter;
 
@@ -763,22 +726,17 @@
 			while (dbus_message_iter_get_arg_type(
 				       &uuid_array_iter) != DBUS_TYPE_INVALID) {
 				const char *uuid;
+				enum cras_bt_device_profile profile;
+
+				get_profile = 1;
 
 				dbus_message_iter_get_basic(&uuid_array_iter,
 							    &uuid);
+				profile = cras_bt_device_profile_from_uuid(
+					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;
+				device->profiles |= profile;
+				cras_bt_device_log_profile(device, profile);
 
 				dbus_message_iter_next(&uuid_array_iter);
 			}
@@ -789,7 +747,7 @@
 
 	while (invalidated_array_iter &&
 	       dbus_message_iter_get_arg_type(invalidated_array_iter) !=
-		       DBUS_TYPE_INVALID) {
+	       DBUS_TYPE_INVALID) {
 		const char *key;
 
 		dbus_message_iter_get_basic(invalidated_array_iter, &key);
@@ -818,8 +776,14 @@
 		dbus_message_iter_next(invalidated_array_iter);
 	}
 
-	if (watch_needed)
+	/* If updated properties includes 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 (get_profile && device->connected) {
 		cras_bt_device_start_new_conn_watch_timer(device);
+	}
 }
 
 /* Converts bluetooth address string into sockaddr structure. The address
@@ -848,31 +812,7 @@
 	return 0;
 }
 
-/* Apply codec specific settings to the socket fd. */
-static int apply_codec_settings(int fd, uint8_t codec)
-{
-	struct bt_voice voice;
-
-	memset(&voice, 0, sizeof(voice));
-	if (codec == HFP_CODEC_ID_CVSD)
-		return 0;
-
-	if (codec != HFP_CODEC_ID_MSBC) {
-		syslog(LOG_ERR, "Unsupported codec %d", codec);
-		return -1;
-	}
-
-	voice.setting = BT_VOICE_TRANSPARENT;
-
-	if (setsockopt(fd, SOL_BLUETOOTH, BT_VOICE, &voice, sizeof(voice)) <
-	    0) {
-		syslog(LOG_ERR, "Failed to apply voice setting");
-		return -1;
-	}
-	return 0;
-}
-
-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 sk = 0, err;
 	struct sockaddr addr;
@@ -887,11 +827,10 @@
 		goto error;
 	}
 
-	sk = socket(PF_BLUETOOTH, SOCK_SEQPACKET | O_NONBLOCK | SOCK_CLOEXEC,
-		    BTPROTO_SCO);
+	sk = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_SCO);
 	if (sk < 0) {
 		syslog(LOG_ERR, "Failed to create socket: %s (%d)",
-		       strerror(errno), errno);
+				strerror(errno), errno);
 		return -errno;
 	}
 
@@ -900,7 +839,7 @@
 		goto error;
 	if (bind(sk, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
 		syslog(LOG_ERR, "Failed to bind socket: %s (%d)",
-		       strerror(errno), errno);
+				strerror(errno), errno);
 		goto error;
 	}
 
@@ -912,15 +851,10 @@
 
 	if (bt_address(cras_bt_device_address(device), &addr))
 		goto error;
-
-	err = apply_codec_settings(sk, codec);
-	if (err)
-		goto error;
-
-	err = connect(sk, (struct sockaddr *)&addr, sizeof(addr));
+	err = connect(sk, (struct sockaddr *) &addr, sizeof(addr));
 	if (err && errno != EINPROGRESS) {
-		syslog(LOG_ERR, "Failed to connect: %s (%d)", strerror(errno),
-		       errno);
+		syslog(LOG_ERR, "Failed to connect: %s (%d)",
+				strerror(errno), errno);
 		goto error;
 	}
 
@@ -937,34 +871,27 @@
 		goto error;
 	}
 
-	BTLOG(btlog, BT_SCO_CONNECT, 1, sk);
 	return sk;
 
 error:
-	BTLOG(btlog, BT_SCO_CONNECT, 0, sk);
 	if (sk)
 		close(sk);
 	return -1;
 }
 
-int cras_bt_device_sco_packet_size(struct cras_bt_device *device,
-				   int sco_socket, int codec)
+int cras_bt_device_sco_mtu(struct cras_bt_device *device, int sco_socket)
 {
 	struct sco_options so;
 	socklen_t len = sizeof(so);
 	struct cras_bt_adapter *adapter;
 
 	adapter = cras_bt_adapter_get(device->adapter_obj_path);
+	if (cras_bt_adapter_on_usb(adapter))
+		return DEFAULT_HFP_MTU_BYTES;
 
-	if (cras_bt_adapter_on_usb(adapter)) {
-		return (codec == HFP_CODEC_ID_MSBC) ? USB_MSBC_PKT_SIZE :
-						      USB_CVSD_PKT_SIZE;
-	}
-
-	/* For non-USB cases, query the SCO MTU from driver. */
 	if (getsockopt(sco_socket, SOL_SCO, SCO_OPTIONS, &so, &len) < 0) {
 		syslog(LOG_ERR, "Get SCO options error: %s", strerror(errno));
-		return DEFAULT_SCO_PKT_SIZE;
+		return DEFAULT_HFP_MTU_BYTES;
 	}
 	return so.mtu;
 }
@@ -988,7 +915,8 @@
 static void init_bt_device_msg(struct bt_device_msg *msg,
 			       enum BT_DEVICE_COMMAND cmd,
 			       struct cras_bt_device *device,
-			       struct cras_iodev *dev, unsigned int arg)
+			       struct cras_iodev *dev,
+			       unsigned int arg)
 {
 	memset(msg, 0, sizeof(*msg));
 	msg->header.type = CRAS_MAIN_BT;
@@ -1015,8 +943,8 @@
 	struct bt_device_msg msg;
 	int rc;
 
-	init_bt_device_msg(&msg, BT_DEVICE_SCHEDULE_SUSPEND, device, NULL,
-			   msec);
+	init_bt_device_msg(&msg, BT_DEVICE_SCHEDULE_SUSPEND, device,
+			   NULL, msec);
 	rc = cras_main_message_send((struct cras_main_message *)&msg);
 	return rc;
 }
@@ -1049,8 +977,8 @@
 	struct bt_device_msg msg;
 	int rc;
 
-	init_bt_device_msg(&msg, BT_DEVICE_SWITCH_PROFILE_ENABLE_DEV, device,
-			   bt_iodev, 0);
+	init_bt_device_msg(&msg, BT_DEVICE_SWITCH_PROFILE_ENABLE_DEV,
+			   device, bt_iodev, 0);
 	rc = cras_main_message_send((struct cras_main_message *)&msg);
 	return rc;
 }
@@ -1061,11 +989,24 @@
 	struct bt_device_msg msg;
 	int rc;
 
-	init_bt_device_msg(&msg, BT_DEVICE_SWITCH_PROFILE, device, bt_iodev, 0);
+	init_bt_device_msg(&msg, BT_DEVICE_SWITCH_PROFILE,
+			   device, bt_iodev, 0);
 	rc = cras_main_message_send((struct cras_main_message *)&msg);
 	return rc;
 }
 
+void cras_bt_device_iodev_buffer_size_changed(struct cras_bt_device *device)
+{
+	struct cras_iodev *iodev;
+
+	iodev = device->bt_iodevs[CRAS_STREAM_INPUT];
+	if (iodev && cras_iodev_is_open(iodev))
+		cras_bt_io_update_buffer_size(iodev);
+	iodev = device->bt_iodevs[CRAS_STREAM_OUTPUT];
+	if (iodev && cras_iodev_is_open(iodev))
+		cras_bt_io_update_buffer_size(iodev);
+}
+
 static void profile_switch_delay_cb(struct cras_timer *timer, void *arg)
 {
 	struct cras_bt_device *device = (struct cras_bt_device *)arg;
@@ -1084,8 +1025,11 @@
 	 * We should NOT call into update_active_node from main thread
 	 * because that may mess up the active node content.
 	 */
+	if (cras_iodev_list_dev_is_enabled(iodev))
+		return;
+
 	iodev->update_active_node(iodev, 0, 1);
-	cras_iodev_list_resume_dev(iodev->info.idx);
+	cras_iodev_list_enable_dev(iodev);
 }
 
 static void bt_device_switch_profile_with_delay(struct cras_bt_device *device,
@@ -1098,7 +1042,7 @@
 		device->switch_profile_timer = NULL;
 	}
 	device->switch_profile_timer = cras_tm_create_timer(
-		tm, delay_ms, profile_switch_delay_cb, device);
+			tm, delay_ms, profile_switch_delay_cb, device);
 }
 
 /* Switches associated bt iodevs to use the active profile. This is
@@ -1109,17 +1053,20 @@
 				     int enable_dev)
 {
 	struct cras_iodev *iodev;
+	int was_enabled[CRAS_NUM_DIRECTIONS] = {0};
 	int dir;
 
-	/* If a bt iodev is active, temporarily force close it.
-	 * Note that we need to check all bt_iodevs for the situation that both
-	 * input and output are active while switches from HFP/HSP to A2DP.
+	/* If a bt iodev is active, temporarily remove it from the active
+	 * device list. Note that we need to check all bt_iodevs for the
+	 * situation that both input and output are active while switches
+	 * from HFP/HSP to A2DP.
 	 */
 	for (dir = 0; dir < CRAS_NUM_DIRECTIONS; dir++) {
 		iodev = device->bt_iodevs[dir];
 		if (!iodev)
 			continue;
-		cras_iodev_list_suspend_dev(iodev->info.idx);
+		was_enabled[dir] = cras_iodev_list_dev_is_enabled(iodev);
+		cras_iodev_list_disable_dev(iodev, false);
 	}
 
 	for (dir = 0; dir < CRAS_NUM_DIRECTIONS; dir++) {
@@ -1135,12 +1082,16 @@
 		 * would fail to playback afterwards when the switching happens
 		 * too soon, so put this task in a delayed callback.
 		 */
-		if (dir == CRAS_STREAM_INPUT) {
-			iodev->update_active_node(iodev, 0, 1);
-			cras_iodev_list_resume_dev(iodev->info.idx);
-		} else {
-			bt_device_switch_profile_with_delay(
-				device, PROFILE_SWITCH_DELAY_MS);
+		if (was_enabled[dir] ||
+		    (enable_dev && iodev == bt_iodev)) {
+			if (dir == CRAS_STREAM_INPUT) {
+				iodev->update_active_node(iodev, 0, 1);
+				cras_iodev_list_enable_dev(iodev);
+			} else {
+				bt_device_switch_profile_with_delay(
+						device,
+						PROFILE_SWITCH_DELAY_MS);
+			}
 		}
 	}
 }
@@ -1149,13 +1100,10 @@
 {
 	struct cras_bt_device *device = (struct cras_bt_device *)arg;
 
-	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,
@@ -1165,8 +1113,8 @@
 
 	if (device->suspend_timer)
 		return;
-	device->suspend_timer =
-		cras_tm_create_timer(tm, msec, bt_device_suspend_cb, device);
+	device->suspend_timer = cras_tm_create_timer(tm, msec,
+			bt_device_suspend_cb, device);
 }
 
 static void bt_device_cancel_suspend(struct cras_bt_device *device)
@@ -1183,7 +1131,7 @@
 	struct bt_device_msg *bt_msg = (struct bt_device_msg *)msg;
 	struct cras_bt_device *device = NULL;
 
-	DL_FOREACH (devices, device) {
+	DL_FOREACH(devices, device) {
 		if (device == bt_msg->device)
 			break;
 	}
@@ -1212,8 +1160,8 @@
 
 void cras_bt_device_start_monitor()
 {
-	cras_main_message_add_handler(CRAS_MAIN_BT, bt_device_process_msg,
-				      NULL);
+	cras_main_message_add_handler(CRAS_MAIN_BT,
+				      bt_device_process_msg, NULL);
 }
 
 void cras_bt_device_update_hardware_volume(struct cras_bt_device *device,
@@ -1234,24 +1182,3 @@
 	iodev->active_node->volume = volume;
 	cras_iodev_list_notify_node_volume(iodev->active_node);
 }
-
-int cras_bt_device_get_sco(struct cras_bt_device *device, int codec)
-{
-	if (device->sco_ref_count == 0) {
-		device->sco_fd = cras_bt_device_sco_connect(device, codec);
-		if (device->sco_fd < 0)
-			return device->sco_fd;
-	}
-
-	++device->sco_ref_count;
-	return 0;
-}
-
-void cras_bt_device_put_sco(struct cras_bt_device *device)
-{
-	if (device->sco_ref_count == 0)
-		return;
-
-	if (--device->sco_ref_count == 0)
-		close(device->sco_fd);
-}
diff --git a/cras/src/server/cras_bt_device.h b/cras/src/server/cras_bt_device.h
index 904a5f4..50468ab 100644
--- a/cras/src/server/cras_bt_device.h
+++ b/cras/src/server/cras_bt_device.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
@@ -14,13 +14,13 @@
 struct cras_timer;
 
 enum cras_bt_device_profile {
-	CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE = (1 << 0),
-	CRAS_BT_DEVICE_PROFILE_A2DP_SINK = (1 << 1),
-	CRAS_BT_DEVICE_PROFILE_AVRCP_REMOTE = (1 << 2),
-	CRAS_BT_DEVICE_PROFILE_AVRCP_TARGET = (1 << 3),
-	CRAS_BT_DEVICE_PROFILE_HFP_HANDSFREE = (1 << 4),
-	CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY = (1 << 5),
-	CRAS_BT_DEVICE_PROFILE_HSP_HEADSET = (1 << 6),
+	CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE	= (1 << 0),
+	CRAS_BT_DEVICE_PROFILE_A2DP_SINK	= (1 << 1),
+	CRAS_BT_DEVICE_PROFILE_AVRCP_REMOTE	= (1 << 2),
+	CRAS_BT_DEVICE_PROFILE_AVRCP_TARGET	= (1 << 3),
+	CRAS_BT_DEVICE_PROFILE_HFP_HANDSFREE	= (1 << 4),
+	CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY	= (1 << 5),
+	CRAS_BT_DEVICE_PROFILE_HSP_HEADSET	= (1 << 6),
 	CRAS_BT_DEVICE_PROFILE_HSP_AUDIOGATEWAY = (1 << 7)
 };
 
@@ -28,20 +28,15 @@
 
 struct cras_bt_device *cras_bt_device_create(DBusConnection *conn,
 					     const char *object_path);
-
-/*
- * Removes a BT device from record. If this device is connected state,
- * ensure the associated A2DP and HFP AG be removed cleanly.
- */
-void cras_bt_device_remove(struct cras_bt_device *device);
-
+void cras_bt_device_destroy(struct cras_bt_device *device);
 void cras_bt_device_reset();
 
 struct cras_bt_device *cras_bt_device_get(const char *object_path);
+size_t cras_bt_device_get_list(struct cras_bt_device ***device_list_out);
 
 const char *cras_bt_device_object_path(const struct cras_bt_device *device);
-struct cras_bt_adapter *
-cras_bt_device_adapter(const struct cras_bt_device *device);
+struct cras_bt_adapter *cras_bt_device_adapter(
+	const struct cras_bt_device *device);
 const char *cras_bt_device_address(const struct cras_bt_device *device);
 const char *cras_bt_device_name(const struct cras_bt_device *device);
 int cras_bt_device_paired(const struct cras_bt_device *device);
@@ -52,9 +47,9 @@
 				      DBusMessageIter *properties_array_iter,
 				      DBusMessageIter *invalidated_array_iter);
 
-/* 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);
+/* 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));
 
 /* Checks if profile is claimed supported by the device. */
 int cras_bt_device_supports_profile(const struct cras_bt_device *device,
@@ -72,9 +67,6 @@
 /* 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.
@@ -88,21 +80,11 @@
 /* Gets the SCO socket for the device.
  * Args:
  *     device - The device object to get SCO socket for.
- *     codec - 1 for CVSD, 2 for mSBC
  */
-int cras_bt_device_sco_connect(struct cras_bt_device *device, int codec);
+int cras_bt_device_sco_connect(struct cras_bt_device *device);
 
-/* Gets the SCO packet size in bytes, used by HFP iodev for audio I/O.
- * The logic is built base on experience: for USB bus, respect BT Core spec
- * that has clear recommendation of packet size of codecs (CVSD, mSBC).
- * As for other buses, use the MTU value of SCO socket filled by driver.
- * Args:
- *    device - The bt device to query mtu.
- *    sco_socket - The SCO socket.
- *    codec - 1 for CVSD, 2 for mSBC per HFP 1.7 specification.
- */
-int cras_bt_device_sco_packet_size(struct cras_bt_device *device,
-				   int sco_socket, int codec);
+/* Queries the preffered mtu value for SCO socket. */
+int cras_bt_device_sco_mtu(struct cras_bt_device *device, int sco_socket);
 
 /* Appends an iodev to bt device.
  * Args:
@@ -149,6 +131,10 @@
 int cras_bt_device_switch_profile(struct cras_bt_device *device,
 				  struct cras_iodev *bt_iodev);
 
+/* Calls this function when the buffer size of an underlying profile iodev
+ * has changed and update it for the virtual bt iodev. */
+void cras_bt_device_iodev_buffer_size_changed(struct cras_bt_device *device);
+
 void cras_bt_device_start_monitor();
 
 /* Checks if the device has an iodev for A2DP. */
@@ -181,34 +167,4 @@
  */
 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:
- *    device - The bluetooth device.
- *    codec - 1 for CVSD, 2 for mSBC
- * Returns:
- *   0 on success, error code otherwise.
- */
-int cras_bt_device_get_sco(struct cras_bt_device *device, int codec);
-
-/*
- * Closes SCO connection if the caller is the last user for the connection on
- * the BT device.
- * Note: this function should be only used for hfp_alsa_io.
- * Args:
- *   device - The bluetooth device.
- */
-void cras_bt_device_put_sco(struct cras_bt_device *device);
-
 #endif /* CRAS_BT_DEVICE_H_ */
diff --git a/cras/src/server/cras_bt_endpoint.c b/cras/src/server/cras_bt_endpoint.c
index 5b2b6e0..52cc362 100644
--- a/cras/src/server/cras_bt_endpoint.c
+++ b/cras/src/server/cras_bt_endpoint.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
@@ -16,55 +16,46 @@
 #include "utlist.h"
 
 /* Defined by doc/media-api.txt in the BlueZ source */
-#define ENDPOINT_INTROSPECT_XML                                                 \
-	DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE                               \
-	"<node>\n"                                                              \
-	"  <interface name=\"org.bluez.MediaEndpoint\">\n"                      \
-	"    <method name=\"SetConfiguration\">\n"                              \
-	"      <arg name=\"transport\" type=\"o\" direction=\"in\"/>\n"         \
-	"      <arg name=\"configuration\" type=\"a{sv}\" direction=\"in\"/>\n" \
-	"    </method>\n"                                                       \
-	"    <method name=\"SelectConfiguration\">\n"                           \
-	"      <arg name=\"capabilities\" type=\"ay\" direction=\"in\"/>\n"     \
-	"      <arg name=\"configuration\" type=\"ay\" direction=\"out\"/>\n"   \
-	"    </method>\n"                                                       \
-	"    <method name=\"ClearConfiguration\">\n"                            \
-	"    </method>\n"                                                       \
-	"    <method name=\"Release\">\n"                                       \
-	"    </method>\n"                                                       \
-	"  </interface>\n"                                                      \
-	"  <interface name=\"" DBUS_INTERFACE_INTROSPECTABLE "\">\n"            \
-	"    <method name=\"Introspect\">\n"                                    \
-	"      <arg name=\"data\" type=\"s\" direction=\"out\"/>\n"             \
-	"    </method>\n"                                                       \
-	"  </interface>\n"                                                      \
+#define ENDPOINT_INTROSPECT_XML						\
+	DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE			\
+	"<node>\n"							\
+	"  <interface name=\"org.bluez.MediaEndpoint\">\n"		\
+	"    <method name=\"SetConfiguration\">\n"			\
+	"      <arg name=\"transport\" type=\"o\" direction=\"in\"/>\n"	\
+	"      <arg name=\"configuration\" type=\"a{sv}\" direction=\"in\"/>\n"\
+	"    </method>\n"						\
+	"    <method name=\"SelectConfiguration\">\n"			\
+	"      <arg name=\"capabilities\" type=\"ay\" direction=\"in\"/>\n"\
+	"      <arg name=\"configuration\" type=\"ay\" direction=\"out\"/>\n"\
+	"    </method>\n"						\
+	"    <method name=\"ClearConfiguration\">\n"			\
+	"    </method>\n"						\
+	"    <method name=\"Release\">\n"				\
+	"    </method>\n"						\
+	"  </interface>\n"						\
+	"  <interface name=\"" DBUS_INTERFACE_INTROSPECTABLE "\">\n"	\
+	"    <method name=\"Introspect\">\n"				\
+	"      <arg name=\"data\" type=\"s\" direction=\"out\"/>\n"	\
+	"    </method>\n"						\
+	"  </interface>\n"						\
 	"</node>\n"
 
+
 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);
 
-	transport = endpoint->transport;
-	cras_bt_transport_set_endpoint(transport, NULL);
+	cras_bt_transport_set_endpoint(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
-cras_bt_endpoint_set_configuration(DBusConnection *conn, DBusMessage *message,
-				   void *arg)
+static DBusHandlerResult cras_bt_endpoint_set_configuration(
+	DBusConnection *conn,
+	DBusMessage *message,
+	void *arg)
 {
 	DBusMessageIter message_iter, properties_array_iter;
 	const char *endpoint_path, *transport_path;
@@ -94,13 +85,16 @@
 
 	transport = cras_bt_transport_get(transport_path);
 	if (transport) {
-		cras_bt_transport_update_properties(
-			transport, &properties_array_iter, NULL);
+		cras_bt_transport_update_properties(transport,
+						    &properties_array_iter,
+						    NULL);
 	} else {
 		transport = cras_bt_transport_create(conn, transport_path);
 		if (transport) {
 			cras_bt_transport_update_properties(
-				transport, &properties_array_iter, NULL);
+				transport,
+				&properties_array_iter,
+				NULL);
 			syslog(LOG_INFO, "Bluetooth Transport: %s added",
 			       cras_bt_transport_object_path(transport));
 		}
@@ -126,9 +120,10 @@
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-static DBusHandlerResult
-cras_bt_endpoint_select_configuration(DBusConnection *conn,
-				      DBusMessage *message, void *arg)
+static DBusHandlerResult cras_bt_endpoint_select_configuration(
+	DBusConnection *conn,
+	DBusMessage *message,
+	void *arg)
 {
 	DBusError dbus_error;
 	const char *endpoint_path;
@@ -148,8 +143,9 @@
 
 	dbus_error_init(&dbus_error);
 
-	if (!dbus_message_get_args(message, &dbus_error, DBUS_TYPE_ARRAY,
-				   DBUS_TYPE_BYTE, &capabilities, &len,
+	if (!dbus_message_get_args(message, &dbus_error,
+				   DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
+				   &capabilities, &len,
 				   DBUS_TYPE_INVALID)) {
 		syslog(LOG_WARNING, "Bad SelectConfiguration method call: %s",
 		       dbus_error.message);
@@ -175,8 +171,10 @@
 	reply = dbus_message_new_method_return(message);
 	if (!reply)
 		return DBUS_HANDLER_RESULT_NEED_MEMORY;
-	if (!dbus_message_append_args(reply, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
-				      &configuration, len, DBUS_TYPE_INVALID))
+	if (!dbus_message_append_args(reply,
+				      DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
+				      &configuration, len,
+				      DBUS_TYPE_INVALID))
 		return DBUS_HANDLER_RESULT_NEED_MEMORY;
 	if (!dbus_connection_send(conn, reply, NULL))
 		return DBUS_HANDLER_RESULT_NEED_MEMORY;
@@ -185,9 +183,10 @@
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-static DBusHandlerResult
-cras_bt_endpoint_clear_configuration(DBusConnection *conn, DBusMessage *message,
-				     void *arg)
+static DBusHandlerResult cras_bt_endpoint_clear_configuration(
+	DBusConnection *conn,
+	DBusMessage *message,
+	void *arg)
 {
 	DBusError dbus_error;
 	const char *endpoint_path, *transport_path;
@@ -205,8 +204,9 @@
 
 	dbus_error_init(&dbus_error);
 
-	if (!dbus_message_get_args(message, &dbus_error, DBUS_TYPE_OBJECT_PATH,
-				   &transport_path, DBUS_TYPE_INVALID)) {
+	if (!dbus_message_get_args(message, &dbus_error,
+				   DBUS_TYPE_OBJECT_PATH, &transport_path,
+				   DBUS_TYPE_INVALID)) {
 		syslog(LOG_WARNING, "Bad ClearConfiguration method call: %s",
 		       dbus_error.message);
 		dbus_error_free(&dbus_error);
@@ -228,14 +228,16 @@
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-static DBusHandlerResult
-cras_bt_endpoint_release(DBusConnection *conn, DBusMessage *message, void *arg)
+static DBusHandlerResult cras_bt_endpoint_release(DBusConnection *conn,
+						  DBusMessage *message,
+						  void *arg)
 {
 	const char *endpoint_path;
 	struct cras_bt_endpoint *endpoint;
 	DBusMessage *reply;
 
-	syslog(LOG_DEBUG, "Release: %s", dbus_message_get_path(message));
+	syslog(LOG_DEBUG, "Release: %s",
+	       dbus_message_get_path(message));
 
 	endpoint_path = dbus_message_get_path(message);
 	endpoint = cras_bt_endpoint_get(endpoint_path);
@@ -263,7 +265,8 @@
 	       dbus_message_get_interface(message),
 	       dbus_message_get_member(message));
 
-	if (dbus_message_is_method_call(message, DBUS_INTERFACE_INTROSPECTABLE,
+	if (dbus_message_is_method_call(message,
+					DBUS_INTERFACE_INTROSPECTABLE,
 					"Introspect")) {
 		DBusMessage *reply;
 		const char *xml = ENDPOINT_INTROSPECT_XML;
@@ -271,7 +274,8 @@
 		reply = dbus_message_new_method_return(message);
 		if (!reply)
 			return DBUS_HANDLER_RESULT_NEED_MEMORY;
-		if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &xml,
+		if (!dbus_message_append_args(reply,
+					      DBUS_TYPE_STRING, &xml,
 					      DBUS_TYPE_INVALID))
 			return DBUS_HANDLER_RESULT_NEED_MEMORY;
 		if (!dbus_connection_send(conn, reply, NULL))
@@ -288,8 +292,8 @@
 	} else if (dbus_message_is_method_call(message,
 					       BLUEZ_INTERFACE_MEDIA_ENDPOINT,
 					       "SelectConfiguration")) {
-		return cras_bt_endpoint_select_configuration(conn, message,
-							     arg);
+		return cras_bt_endpoint_select_configuration(
+			conn, message, arg);
 
 	} else if (dbus_message_is_method_call(message,
 					       BLUEZ_INTERFACE_MEDIA_ENDPOINT,
@@ -310,6 +314,7 @@
 	}
 }
 
+
 static void cras_bt_on_register_endpoint(DBusPendingCall *pending_call,
 					 void *data)
 {
@@ -349,29 +354,32 @@
 
 	adapter_path = cras_bt_adapter_object_path(adapter);
 
-	method_call = dbus_message_new_method_call(BLUEZ_SERVICE, adapter_path,
+	method_call = dbus_message_new_method_call(BLUEZ_SERVICE,
+						   adapter_path,
 						   BLUEZ_INTERFACE_MEDIA,
 						   "RegisterEndpoint");
 	if (!method_call)
 		return -ENOMEM;
 
 	dbus_message_iter_init_append(method_call, &message_iter);
-	dbus_message_iter_append_basic(&message_iter, DBUS_TYPE_OBJECT_PATH,
+	dbus_message_iter_append_basic(&message_iter,
+				       DBUS_TYPE_OBJECT_PATH,
 				       &endpoint->object_path);
 
-	dbus_message_iter_open_container(
-		&message_iter, DBUS_TYPE_ARRAY,
-		DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING
-			DBUS_TYPE_VARIANT_AS_STRING
-				DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
-		&properties_array_iter);
+	dbus_message_iter_open_container(&message_iter,
+					 DBUS_TYPE_ARRAY,
+					 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+					 DBUS_TYPE_STRING_AS_STRING
+					 DBUS_TYPE_VARIANT_AS_STRING
+					 DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+					 &properties_array_iter);
 
 	key = "UUID";
 	dbus_message_iter_open_container(&properties_array_iter,
 					 DBUS_TYPE_DICT_ENTRY, NULL,
 					 &properties_dict_iter);
-	dbus_message_iter_append_basic(&properties_dict_iter, DBUS_TYPE_STRING,
-				       &key);
+	dbus_message_iter_append_basic(&properties_dict_iter,
+				       DBUS_TYPE_STRING, &key);
 	dbus_message_iter_open_container(&properties_dict_iter,
 					 DBUS_TYPE_VARIANT,
 					 DBUS_TYPE_STRING_AS_STRING,
@@ -386,8 +394,8 @@
 	dbus_message_iter_open_container(&properties_array_iter,
 					 DBUS_TYPE_DICT_ENTRY, NULL,
 					 &properties_dict_iter);
-	dbus_message_iter_append_basic(&properties_dict_iter, DBUS_TYPE_STRING,
-				       &key);
+	dbus_message_iter_append_basic(&properties_dict_iter,
+				       DBUS_TYPE_STRING, &key);
 	dbus_message_iter_open_container(&properties_dict_iter,
 					 DBUS_TYPE_VARIANT,
 					 DBUS_TYPE_BYTE_AS_STRING,
@@ -402,14 +410,16 @@
 	dbus_message_iter_open_container(&properties_array_iter,
 					 DBUS_TYPE_DICT_ENTRY, NULL,
 					 &properties_dict_iter);
-	dbus_message_iter_append_basic(&properties_dict_iter, DBUS_TYPE_STRING,
-				       &key);
-	dbus_message_iter_open_container(
-		&properties_dict_iter, DBUS_TYPE_VARIANT,
-		DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING,
-		&variant_iter);
+	dbus_message_iter_append_basic(&properties_dict_iter,
+				       DBUS_TYPE_STRING, &key);
+	dbus_message_iter_open_container(&properties_dict_iter,
+					 DBUS_TYPE_VARIANT,
+					 DBUS_TYPE_ARRAY_AS_STRING
+					 DBUS_TYPE_BYTE_AS_STRING,
+					 &variant_iter);
 	dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
-					 DBUS_TYPE_BYTE_AS_STRING, &bytes_iter);
+					 DBUS_TYPE_BYTE_AS_STRING,
+					 &bytes_iter);
 	dbus_message_iter_append_fixed_array(&bytes_iter, DBUS_TYPE_BYTE,
 					     &capabilities, len);
 	dbus_message_iter_close_container(&variant_iter, &bytes_iter);
@@ -430,8 +440,9 @@
 	if (!pending_call)
 		return -EIO;
 
-	if (!dbus_pending_call_set_notify(
-		    pending_call, cras_bt_on_register_endpoint, NULL, NULL)) {
+	if (!dbus_pending_call_set_notify(pending_call,
+					  cras_bt_on_register_endpoint,
+					  NULL, NULL)) {
 		dbus_pending_call_cancel(pending_call);
 		dbus_pending_call_unref(pending_call);
 		return -ENOMEM;
@@ -468,13 +479,15 @@
 
 	adapter_path = cras_bt_adapter_object_path(adapter);
 
-	method_call = dbus_message_new_method_call(BLUEZ_SERVICE, adapter_path,
+	method_call = dbus_message_new_method_call(BLUEZ_SERVICE,
+						   adapter_path,
 						   BLUEZ_INTERFACE_MEDIA,
 						   "UnregisterEndpoint");
 	if (!method_call)
 		return -ENOMEM;
 
-	if (!dbus_message_append_args(method_call, DBUS_TYPE_OBJECT_PATH,
+	if (!dbus_message_append_args(method_call,
+				      DBUS_TYPE_OBJECT_PATH,
 				      &endpoint->object_path,
 				      DBUS_TYPE_INVALID))
 		return -ENOMEM;
@@ -489,8 +502,9 @@
 	if (!pending_call)
 		return -EIO;
 
-	if (!dbus_pending_call_set_notify(
-		    pending_call, cras_bt_on_unregister_endpoint, NULL, NULL)) {
+	if (!dbus_pending_call_set_notify(pending_call,
+					  cras_bt_on_unregister_endpoint,
+					  NULL, NULL)) {
 		dbus_pending_call_cancel(pending_call);
 		dbus_pending_call_unref(pending_call);
 		return -ENOMEM;
@@ -499,6 +513,7 @@
 	return 0;
 }
 
+
 /* Available endpoints */
 static struct cras_bt_endpoint *endpoints;
 
@@ -507,7 +522,7 @@
 {
 	struct cras_bt_endpoint *endpoint;
 
-	DL_FOREACH (endpoints, endpoint)
+	DL_FOREACH(endpoints, endpoint)
 		cras_bt_register_endpoint(conn, adapter, endpoint);
 
 	return 0;
@@ -528,7 +543,8 @@
 
 	dbus_error_init(&dbus_error);
 
-	if (!dbus_connection_register_object_path(conn, endpoint->object_path,
+	if (!dbus_connection_register_object_path(conn,
+						  endpoint->object_path,
 						  &endpoint_vtable,
 						  &dbus_error)) {
 		syslog(LOG_WARNING,
@@ -566,7 +582,7 @@
 {
 	struct cras_bt_endpoint *endpoint;
 
-	DL_FOREACH (endpoints, endpoint)
+	DL_FOREACH(endpoints, endpoint)
 		cras_bt_endpoint_suspend(endpoint);
 }
 
@@ -574,7 +590,7 @@
 {
 	struct cras_bt_endpoint *endpoint;
 
-	DL_FOREACH (endpoints, endpoint) {
+	DL_FOREACH(endpoints, endpoint) {
 		if (strcmp(endpoint->object_path, object_path) == 0)
 			return endpoint;
 	}
diff --git a/cras/src/server/cras_bt_endpoint.h b/cras/src/server/cras_bt_endpoint.h
index 963071c..be56070 100644
--- a/cras/src/server/cras_bt_endpoint.h
+++ b/cras/src/server/cras_bt_endpoint.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
@@ -19,7 +19,7 @@
 	uint8_t codec;
 
 	int (*get_capabilities)(struct cras_bt_endpoint *endpoint,
-				void *capabilities, int *len);
+				 void *capabilities, int *len);
 	int (*select_configuration)(struct cras_bt_endpoint *endpoint,
 				    void *capabilities, int len,
 				    void *configuration);
diff --git a/cras/src/server/cras_bt_io.c b/cras/src/server/cras_bt_io.c
index 637f0a7..84ac5ca 100644
--- a/cras/src/server/cras_bt_io.c
+++ b/cras/src/server/cras_bt_io.c
@@ -69,6 +69,7 @@
 	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);
 
@@ -90,14 +91,13 @@
 	switch (profile) {
 	case CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY:
 	case CRAS_BT_DEVICE_PROFILE_HSP_AUDIOGATEWAY:
-		cras_bt_device_set_active_profile(
-			device,
-			CRAS_BT_DEVICE_PROFILE_HSP_AUDIOGATEWAY |
+		cras_bt_device_set_active_profile(device,
+				CRAS_BT_DEVICE_PROFILE_HSP_AUDIOGATEWAY |
 				CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY);
 		break;
 	case CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE:
-		cras_bt_device_set_active_profile(
-			device, CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE);
+		cras_bt_device_set_active_profile(device,
+				CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE);
 		break;
 	default:
 		syslog(LOG_ERR, "Unexpect profile %u", profile);
@@ -124,7 +124,6 @@
 static int open_dev(struct cras_iodev *iodev)
 {
 	struct bt_io *btio = (struct bt_io *)iodev;
-	struct cras_iodev *dev = active_profile_dev(iodev);
 
 	/* Force to use HFP if opening input dev. */
 	if (device_using_profile(btio->device,
@@ -136,9 +135,6 @@
 		return -EAGAIN;
 	}
 
-	if (dev && dev->open_dev)
-		return dev->open_dev(dev);
-
 	return 0;
 }
 
@@ -147,12 +143,9 @@
 	struct cras_iodev *dev = active_profile_dev(iodev);
 	int rc, length, i;
 
-	if (!dev)
-		return -EINVAL;
-
 	if (dev->format == NULL) {
-		dev->format = (struct cras_audio_format *)malloc(
-			sizeof(*dev->format));
+		dev->format = (struct cras_audio_format *)
+				malloc(sizeof(*dev->format));
 		*dev->format = *iodev->format;
 	}
 
@@ -163,29 +156,26 @@
 	}
 
 	/* Fill in the supported rates and channel counts. */
-	for (length = 0; dev->supported_rates[length]; length++)
-		;
+	for (length = 0; dev->supported_rates[length]; length++);
 	free(iodev->supported_rates);
 	iodev->supported_rates = (size_t *)malloc(
-		(length + 1) * sizeof(*iodev->supported_rates));
+			(length + 1) * sizeof(*iodev->supported_rates));
 	for (i = 0; i < length + 1; i++)
 		iodev->supported_rates[i] = dev->supported_rates[i];
 
-	for (length = 0; dev->supported_channel_counts[length]; length++)
-		;
+	for (length = 0; dev->supported_channel_counts[length]; length++);
 	iodev->supported_channel_counts = (size_t *)malloc(
 		(length + 1) * sizeof(*iodev->supported_channel_counts));
 	for (i = 0; i < length + 1; i++)
 		iodev->supported_channel_counts[i] =
 			dev->supported_channel_counts[i];
 
-	for (length = 0; dev->supported_formats[length]; length++)
-		;
-
+	for (length = 0; dev->supported_formats[length]; length++);
 	iodev->supported_formats = (snd_pcm_format_t *)malloc(
 		(length + 1) * sizeof(*iodev->supported_formats));
 	for (i = 0; i < length + 1; i++)
-		iodev->supported_formats[i] = dev->supported_formats[i];
+		iodev->supported_formats[i] =
+			dev->supported_formats[i];
 	return 0;
 }
 
@@ -200,8 +190,12 @@
 	*dev->format = *iodev->format;
 
 	rc = dev->configure_dev(dev);
-	if (rc)
+	if (rc) {
+		/* Free format here to assure the update_supported_format
+		 * callback will be called before any future open_dev call. */
+		cras_iodev_free_format(iodev);
 		return rc;
+	}
 
 	iodev->buffer_size = dev->buffer_size;
 	iodev->min_buffer_level = dev->min_buffer_level;
@@ -213,18 +207,15 @@
 	struct bt_io *btio = (struct bt_io *)iodev;
 	int rc;
 	struct cras_iodev *dev = active_profile_dev(iodev);
-	if (!dev)
-		return -EINVAL;
 
 	/* Force back to A2DP if closing HFP. */
-	if (device_using_profile(
-		    btio->device,
-		    CRAS_BT_DEVICE_PROFILE_HSP_AUDIOGATEWAY |
-			    CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY) &&
+	if (device_using_profile(btio->device,
+			CRAS_BT_DEVICE_PROFILE_HSP_AUDIOGATEWAY |
+			CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY) &&
 	    iodev->direction == CRAS_STREAM_INPUT &&
 	    cras_bt_device_has_a2dp(btio->device)) {
-		cras_bt_device_set_active_profile(
-			btio->device, CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE);
+		cras_bt_device_set_active_profile(btio->device,
+				CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE);
 		cras_bt_device_switch_profile(btio->device, iodev);
 	}
 
@@ -238,8 +229,6 @@
 static void set_bt_volume(struct cras_iodev *iodev)
 {
 	struct cras_iodev *dev = active_profile_dev(iodev);
-	if (!dev)
-		return;
 
 	if (dev->active_node)
 		dev->active_node->volume = iodev->active_node->volume;
@@ -269,7 +258,8 @@
 	return dev->delay_frames(dev);
 }
 
-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 cras_iodev *dev = active_profile_dev(iodev);
@@ -303,13 +293,12 @@
 	struct bt_io *btio = (struct bt_io *)iodev;
 	struct cras_ionode *node;
 	struct bt_node *active = (struct bt_node *)iodev->active_node;
-	struct cras_iodev *dev;
 
 	if (device_using_profile(btio->device, active->profile))
-		goto leave;
+		return;
 
 	/* Switch to the correct dev using active_profile. */
-	DL_FOREACH (iodev->nodes, node) {
+	DL_FOREACH(iodev->nodes, node) {
 		struct bt_node *n = (struct bt_node *)node;
 		if (n == active)
 			continue;
@@ -322,56 +311,6 @@
 			set_bt_volume(iodev);
 		}
 	}
-
-leave:
-	dev = active_profile_dev(iodev);
-	if (dev && dev->update_active_node)
-		dev->update_active_node(dev, node_idx, dev_enabled);
-}
-
-static int no_stream(struct cras_iodev *iodev, int enable)
-{
-	struct cras_iodev *dev = active_profile_dev(iodev);
-	if (!dev)
-		return -EINVAL;
-
-	if (dev->no_stream) {
-		/*
-		 * Copy iodev->min_cb_level and iodev->max_cb_level from the
-		 * parent (i.e. bt_io).  no_stream() of hfp_alsa_iodev will
-		 * use them.
-		 * A2DP and HFP dev will use buffer and callback sizes to fill
-		 * zeros in no stream state.
-		 */
-		dev->min_cb_level = iodev->min_cb_level;
-		dev->max_cb_level = iodev->max_cb_level;
-		dev->buffer_size = iodev->buffer_size;
-		return dev->no_stream(dev, enable);
-	}
-	return 0;
-}
-
-static int is_free_running(const struct cras_iodev *iodev)
-{
-	struct cras_iodev *dev = active_profile_dev(iodev);
-	if (!dev)
-		return -EINVAL;
-
-	if (dev->is_free_running)
-		return dev->is_free_running(dev);
-
-	return 0;
-}
-
-static int start(const struct cras_iodev *iodev)
-{
-	struct cras_iodev *dev = active_profile_dev(iodev);
-	if (!dev)
-		return -EINVAL;
-
-	if (dev->start)
-		return dev->start(dev);
-	return 0;
 }
 
 struct cras_iodev *cras_bt_io_create(struct cras_bt_device *device,
@@ -396,6 +335,7 @@
 	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;
@@ -407,9 +347,7 @@
 	iodev->close_dev = close_dev;
 	iodev->update_supported_formats = update_supported_formats;
 	iodev->update_active_node = update_active_node;
-	iodev->no_stream = no_stream;
-	iodev->is_free_running = is_free_running;
-	iodev->start = start;
+	iodev->no_stream = cras_iodev_default_no_stream_playback;
 
 	/* Input also checks |software_volume_needed| flag for using software
 	 * gain. Keep it as false for BT input.
@@ -418,7 +356,7 @@
 	 */
 	if (dev->direction == CRAS_STREAM_OUTPUT) {
 		iodev->software_volume_needed =
-			!cras_bt_device_get_use_hardware_volume(device);
+				!cras_bt_device_get_use_hardware_volume(device);
 		iodev->set_volume = set_bt_volume;
 	}
 
@@ -432,10 +370,11 @@
 	active->base.type = CRAS_NODE_TYPE_BLUETOOTH;
 	active->base.volume = 100;
 	active->base.plugged = 1;
-	active->base.stable_id =
-		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 = 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);
@@ -480,7 +419,7 @@
 	free(bt_iodev->supported_channel_counts);
 	free(bt_iodev->supported_formats);
 
-	DL_FOREACH (bt_iodev->nodes, node) {
+	DL_FOREACH(bt_iodev->nodes, node) {
 		n = (struct bt_node *)node;
 		cras_iodev_rm_node(bt_iodev, node);
 		free(n);
@@ -509,7 +448,7 @@
 					   enum cras_bt_device_profile profile)
 {
 	struct cras_ionode *node;
-	DL_FOREACH (bt_iodev->nodes, node) {
+	DL_FOREACH(bt_iodev->nodes, node) {
 		struct bt_node *n = (struct bt_node *)node;
 		if (n->profile & profile)
 			return node;
@@ -517,7 +456,8 @@
 	return NULL;
 }
 
-int cras_bt_io_append(struct cras_iodev *bt_iodev, struct cras_iodev *dev,
+int cras_bt_io_append(struct cras_iodev *bt_iodev,
+		      struct cras_iodev *dev,
 		      enum cras_bt_device_profile profile)
 {
 	struct cras_ionode *node;
@@ -547,6 +487,16 @@
 	return !!(profile & btnode->profile);
 }
 
+int cras_bt_io_update_buffer_size(struct cras_iodev *bt_iodev)
+{
+	struct cras_iodev *dev = active_profile_dev(bt_iodev);
+	if (!dev)
+		return -EINVAL;
+
+	bt_iodev->buffer_size = dev->buffer_size;
+	return 0;
+}
+
 unsigned int cras_bt_io_try_remove(struct cras_iodev *bt_iodev,
 				   struct cras_iodev *dev)
 {
@@ -557,7 +507,7 @@
 	active = (struct bt_node *)bt_iodev->active_node;
 
 	if (active->profile_dev == dev) {
-		DL_FOREACH (bt_iodev->nodes, node) {
+		DL_FOREACH(bt_iodev->nodes, node) {
 			btnode = (struct bt_node *)node;
 			/* Skip the active node and the node we're trying
 			 * to remove. */
@@ -572,12 +522,13 @@
 	return try_profile;
 }
 
-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)
 {
 	struct cras_ionode *node;
 	struct bt_node *btnode;
 
-	DL_FOREACH (bt_iodev->nodes, node) {
+	DL_FOREACH(bt_iodev->nodes, node) {
 		btnode = (struct bt_node *)node;
 		if (btnode->profile_dev != dev)
 			continue;
diff --git a/cras/src/server/cras_bt_io.h b/cras/src/server/cras_bt_io.h
index b833cd9..8556be3 100644
--- a/cras/src/server/cras_bt_io.h
+++ b/cras/src/server/cras_bt_io.h
@@ -19,17 +19,22 @@
 void cras_bt_io_destroy(struct cras_iodev *bt_iodev);
 
 /* Looks up for the node of given profile, returns NULL if doesn't exist. */
-struct cras_ionode *cras_bt_io_get_profile(struct cras_iodev *bt_iodev,
-					   enum cras_bt_device_profile profile);
+struct cras_ionode *cras_bt_io_get_profile(
+		struct cras_iodev *bt_iodev,
+		enum cras_bt_device_profile profile);
 
 /* Appends a profile specific iodev to bt_iodev. */
-int cras_bt_io_append(struct cras_iodev *bt_iodev, struct cras_iodev *dev,
+int cras_bt_io_append(struct cras_iodev *bt_iodev,
+		      struct cras_iodev *dev,
 		      enum cras_bt_device_profile profile);
 
 /* Checks if the active node of bt_io matches a profile. */
 int cras_bt_io_on_profile(struct cras_iodev *bt_iodev,
 			  enum cras_bt_device_profile profile);
 
+/* Updates the buffer size to the profile specific iodev. */
+int cras_bt_io_update_buffer_size(struct cras_iodev *bt_iodev);
+
 /* Dry-run the profile device removal from bt_iodev.
  * Returns:
  *    0 if the bt_iodev will be empty and should to be destroied
diff --git a/cras/src/server/cras_bt_log.h b/cras/src/server/cras_bt_log.h
deleted file mode 100644
index 26c559a..0000000
--- a/cras/src/server/cras_bt_log.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/* 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_BT_LOG_H_
-#define CRAS_BT_LOG_H_
-
-#include <stdint.h>
-
-#include "cras_types.h"
-
-#define CRAS_BT_LOGGING 1
-
-#if (CRAS_BT_LOGGING)
-#define BTLOG(log, event, data1, data2)                                        \
-	cras_bt_event_log_data(log, event, data1, data2);
-#else
-#define BTLOG(log, event, data1, data2)
-#endif
-
-extern struct cras_bt_event_log *btlog;
-
-static inline struct cras_bt_event_log *cras_bt_event_log_init()
-{
-	struct cras_bt_event_log *log;
-	log = (struct cras_bt_event_log *)calloc(
-		1, sizeof(struct cras_bt_event_log));
-	log->len = CRAS_BT_EVENT_LOG_SIZE;
-
-	return log;
-}
-
-static inline void cras_bt_event_log_deinit(struct cras_bt_event_log *log)
-{
-	free(log);
-}
-
-static inline void cras_bt_event_log_data(struct cras_bt_event_log *log,
-					  enum CRAS_BT_LOG_EVENTS event,
-					  uint32_t data1, uint32_t data2)
-{
-	struct timespec now;
-
-	clock_gettime(CLOCK_MONOTONIC_RAW, &now);
-	log->log[log->write_pos].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->write_pos++;
-	log->write_pos %= CRAS_BT_EVENT_LOG_SIZE;
-}
-
-#endif /* CRAS_BT_LOG_H_ */
\ No newline at end of file
diff --git a/cras/src/server/cras_bt_manager.c b/cras/src/server/cras_bt_manager.c
index 3a3ea4a..8d6c97a 100644
--- a/cras/src/server/cras_bt_manager.c
+++ b/cras/src/server/cras_bt_manager.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
@@ -15,13 +15,11 @@
 #include "cras_bt_adapter.h"
 #include "cras_bt_device.h"
 #include "cras_bt_endpoint.h"
-#include "cras_bt_log.h"
 #include "cras_bt_player.h"
 #include "cras_bt_profile.h"
 #include "cras_bt_transport.h"
 #include "utlist.h"
 
-struct cras_bt_event_log *btlog;
 
 static void cras_bt_interface_added(DBusConnection *conn,
 				    const char *object_path,
@@ -36,8 +34,7 @@
 			cras_bt_adapter_update_properties(
 				adapter, properties_array_iter, NULL);
 		} else {
-			BTLOG(btlog, BT_ADAPTER_ADDED, 0, 0);
-			adapter = cras_bt_adapter_create(conn, object_path);
+			adapter = cras_bt_adapter_create(object_path);
 			if (adapter) {
 				cras_bt_adapter_update_properties(
 					adapter, properties_array_iter, NULL);
@@ -76,8 +73,8 @@
 			}
 		}
 
-	} else if (strcmp(interface_name, BLUEZ_INTERFACE_MEDIA_TRANSPORT) ==
-		   0) {
+	} else if (strcmp(interface_name,
+			  BLUEZ_INTERFACE_MEDIA_TRANSPORT) == 0) {
 		struct cras_bt_transport *transport;
 
 		transport = cras_bt_transport_get(object_path);
@@ -91,9 +88,8 @@
 					transport, properties_array_iter, NULL);
 
 				syslog(LOG_INFO,
-				       "Bluetooth Transport: %s added",
-				       cras_bt_transport_object_path(
-					       transport));
+				      "Bluetooth Transport: %s added",
+				      cras_bt_transport_object_path(transport));
 			} else {
 				syslog(LOG_WARNING,
 				       "Failed to create Bluetooth Transport: "
@@ -101,6 +97,7 @@
 				       object_path);
 			}
 		}
+
 	}
 }
 
@@ -111,7 +108,6 @@
 	if (strcmp(interface_name, BLUEZ_INTERFACE_ADAPTER) == 0) {
 		struct cras_bt_adapter *adapter;
 
-		BTLOG(btlog, BT_ADAPTER_REMOVED, 0, 0);
 		adapter = cras_bt_adapter_get(object_path);
 		if (adapter) {
 			syslog(LOG_INFO, "Bluetooth Adapter: %s removed",
@@ -126,19 +122,20 @@
 		if (device) {
 			syslog(LOG_INFO, "Bluetooth Device: %s removed",
 			       cras_bt_device_address(device));
-			cras_bt_device_remove(device);
+			cras_bt_device_destroy(device);
 		}
 
-	} else if (strcmp(interface_name, BLUEZ_INTERFACE_MEDIA_TRANSPORT) ==
-		   0) {
+	} else if (strcmp(interface_name,
+			  BLUEZ_INTERFACE_MEDIA_TRANSPORT) == 0) {
 		struct cras_bt_transport *transport;
 
 		transport = cras_bt_transport_get(object_path);
 		if (transport) {
 			syslog(LOG_INFO, "Bluetooth Transport: %s removed",
 			       cras_bt_transport_object_path(transport));
-			cras_bt_transport_remove(transport);
+			cras_bt_transport_destroy(transport);
 		}
+
 	}
 }
 
@@ -168,8 +165,8 @@
 				invalidated_array_iter);
 		}
 
-	} else if (strcmp(interface_name, BLUEZ_INTERFACE_MEDIA_TRANSPORT) ==
-		   0) {
+	} else if (strcmp(interface_name,
+			  BLUEZ_INTERFACE_MEDIA_TRANSPORT) == 0) {
 		struct cras_bt_transport *transport;
 
 		transport = cras_bt_transport_get(object_path);
@@ -178,6 +175,7 @@
 				transport, properties_array_iter,
 				invalidated_array_iter);
 		}
+
 	}
 }
 
@@ -186,7 +184,6 @@
  */
 static void cras_bt_reset()
 {
-	BTLOG(btlog, BT_RESET, 0, 0);
 	cras_bt_endpoint_reset();
 	cras_bt_transport_reset();
 	cras_bt_profile_reset();
@@ -194,6 +191,7 @@
 	cras_bt_adapter_reset();
 }
 
+
 static void cras_bt_on_get_managed_objects(DBusPendingCall *pending_call,
 					   void *data)
 {
@@ -221,7 +219,7 @@
 	dbus_message_iter_recurse(&message_iter, &object_array_iter);
 
 	while (dbus_message_iter_get_arg_type(&object_array_iter) !=
-	       DBUS_TYPE_INVALID) {
+		       DBUS_TYPE_INVALID) {
 		DBusMessageIter object_dict_iter, interface_array_iter;
 		const char *object_path;
 
@@ -235,7 +233,7 @@
 					  &interface_array_iter);
 
 		while (dbus_message_iter_get_arg_type(&interface_array_iter) !=
-		       DBUS_TYPE_INVALID) {
+			       DBUS_TYPE_INVALID) {
 			DBusMessageIter interface_dict_iter;
 			DBusMessageIter properties_array_iter;
 			const char *interface_name;
@@ -250,8 +248,8 @@
 			dbus_message_iter_recurse(&interface_dict_iter,
 						  &properties_array_iter);
 
-			cras_bt_interface_added(conn, object_path,
-						interface_name,
+			cras_bt_interface_added(conn,
+						object_path, interface_name,
 						&properties_array_iter);
 
 			dbus_message_iter_next(&interface_array_iter);
@@ -268,15 +266,17 @@
 	DBusMessage *method_call;
 	DBusPendingCall *pending_call;
 
-	method_call =
-		dbus_message_new_method_call(BLUEZ_SERVICE, "/",
-					     DBUS_INTERFACE_OBJECT_MANAGER,
-					     "GetManagedObjects");
+	method_call = dbus_message_new_method_call(
+		BLUEZ_SERVICE,
+		"/",
+		DBUS_INTERFACE_OBJECT_MANAGER,
+		"GetManagedObjects");
 	if (!method_call)
 		return -ENOMEM;
 
 	pending_call = NULL;
-	if (!dbus_connection_send_with_reply(conn, method_call, &pending_call,
+	if (!dbus_connection_send_with_reply(conn, method_call,
+					     &pending_call,
 					     DBUS_TIMEOUT_USE_DEFAULT)) {
 		dbus_message_unref(method_call);
 		return -ENOMEM;
@@ -286,8 +286,9 @@
 	if (!pending_call)
 		return -EIO;
 
-	if (!dbus_pending_call_set_notify(
-		    pending_call, cras_bt_on_get_managed_objects, conn, NULL)) {
+	if (!dbus_pending_call_set_notify(pending_call,
+					  cras_bt_on_get_managed_objects,
+					  conn, NULL)) {
 		dbus_pending_call_cancel(pending_call);
 		dbus_pending_call_unref(pending_call);
 		return -ENOMEM;
@@ -296,6 +297,7 @@
 	return 0;
 }
 
+
 static DBusHandlerResult cras_bt_handle_name_owner_changed(DBusConnection *conn,
 							   DBusMessage *message,
 							   void *arg)
@@ -304,12 +306,13 @@
 	const char *service_name, *old_owner, *new_owner;
 
 	if (!dbus_message_is_signal(message, DBUS_INTERFACE_DBUS,
-				    "NameOwnerChanged"))
+		    "NameOwnerChanged"))
 		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 
 	dbus_error_init(&dbus_error);
-	if (!dbus_message_get_args(message, &dbus_error, DBUS_TYPE_STRING,
-				   &service_name, DBUS_TYPE_STRING, &old_owner,
+	if (!dbus_message_get_args(message, &dbus_error,
+				   DBUS_TYPE_STRING, &service_name,
+				   DBUS_TYPE_STRING, &old_owner,
 				   DBUS_TYPE_STRING, &new_owner,
 				   DBUS_TYPE_INVALID)) {
 		syslog(LOG_WARNING, "Bad NameOwnerChanged signal received: %s",
@@ -335,7 +338,7 @@
 	const char *object_path;
 
 	if (!dbus_message_is_signal(message, DBUS_INTERFACE_OBJECT_MANAGER,
-				    "InterfacesAdded"))
+			    "InterfacesAdded"))
 		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 
 	if (!dbus_message_has_signature(message, "oa{sa{sv}}")) {
@@ -351,7 +354,7 @@
 	dbus_message_iter_recurse(&message_iter, &interface_array_iter);
 
 	while (dbus_message_iter_get_arg_type(&interface_array_iter) !=
-	       DBUS_TYPE_INVALID) {
+		       DBUS_TYPE_INVALID) {
 		DBusMessageIter interface_dict_iter, properties_array_iter;
 		const char *interface_name;
 
@@ -382,7 +385,7 @@
 	const char *object_path;
 
 	if (!dbus_message_is_signal(message, DBUS_INTERFACE_OBJECT_MANAGER,
-				    "InterfacesRemoved"))
+			    "InterfacesRemoved"))
 		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 
 	if (!dbus_message_has_signature(message, "oas")) {
@@ -448,12 +451,11 @@
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
+
 void cras_bt_start(DBusConnection *conn)
 {
 	DBusError dbus_error;
 
-	btlog = cras_bt_event_log_init();
-
 	dbus_error_init(&dbus_error);
 
 	/* Inform the bus daemon which signals we wish to receive. */
diff --git a/cras/src/server/cras_bt_player.c b/cras/src/server/cras_bt_player.c
index 13343a6..3821721 100644
--- a/cras/src/server/cras_bt_player.c
+++ b/cras/src/server/cras_bt_player.c
@@ -1,4 +1,4 @@
-/* Copyright 2016 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2016 The Chromium Authors. All rights reserved.
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
@@ -15,6 +15,7 @@
 
 #define CRAS_DEFAULT_PLAYER "/org/chromium/Cras/Bluetooth/DefaultPlayer"
 
+
 static void cras_bt_on_player_registered(DBusPendingCall *pending_call,
 					 void *data)
 {
@@ -43,29 +44,35 @@
 	DBusPendingCall *pending_call;
 
 	adapter_path = cras_bt_adapter_object_path(adapter);
-	method_call = dbus_message_new_method_call(BLUEZ_SERVICE, adapter_path,
+	method_call = dbus_message_new_method_call(BLUEZ_SERVICE,
+						   adapter_path,
 						   BLUEZ_INTERFACE_MEDIA,
 						   "RegisterPlayer");
 	if (!method_call)
 		return -ENOMEM;
 
 	dbus_message_iter_init_append(method_call, &message_iter);
-	dbus_message_iter_append_basic(&message_iter, DBUS_TYPE_OBJECT_PATH,
+	dbus_message_iter_append_basic(&message_iter,
+				       DBUS_TYPE_OBJECT_PATH,
 				       &player->object_path);
 
-	dbus_message_iter_open_container(
-		&message_iter, DBUS_TYPE_ARRAY,
-		DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING
-			DBUS_TYPE_VARIANT_AS_STRING
-				DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
-		&dict);
+	dbus_message_iter_open_container(&message_iter,
+					 DBUS_TYPE_ARRAY,
+					 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+					 DBUS_TYPE_STRING_AS_STRING
+					 DBUS_TYPE_VARIANT_AS_STRING
+					 DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+					 &dict);
 
 	append_key_value(&dict, "PlaybackStatus", DBUS_TYPE_STRING,
-			 DBUS_TYPE_STRING_AS_STRING, &player->playback_status);
+			 DBUS_TYPE_STRING_AS_STRING,
+			 &player->playback_status);
 	append_key_value(&dict, "Identity", DBUS_TYPE_STRING,
-			 DBUS_TYPE_STRING_AS_STRING, &player->identity);
+			 DBUS_TYPE_STRING_AS_STRING,
+			 &player->identity);
 	append_key_value(&dict, "LoopStatus", DBUS_TYPE_STRING,
-			 DBUS_TYPE_STRING_AS_STRING, &player->loop_status);
+			 DBUS_TYPE_STRING_AS_STRING,
+			 &player->loop_status);
 	append_key_value(&dict, "Position", DBUS_TYPE_INT64,
 			 DBUS_TYPE_INT64_AS_STRING, &player->position);
 	append_key_value(&dict, "Shuffle", DBUS_TYPE_BOOLEAN,
@@ -93,8 +100,9 @@
 	if (!pending_call)
 		return -EIO;
 
-	if (!dbus_pending_call_set_notify(
-		    pending_call, cras_bt_on_player_registered, player, NULL)) {
+	if (!dbus_pending_call_set_notify(pending_call,
+					  cras_bt_on_player_registered,
+					  player, NULL)) {
 		dbus_pending_call_cancel(pending_call);
 		dbus_pending_call_unref(pending_call);
 		return -ENOMEM;
@@ -102,6 +110,7 @@
 	return 0;
 }
 
+
 /* Note that player properties will be used mostly for AVRCP qualification and
  * not for normal use cases. The corresponding media events won't be routed by
  * CRAS until we have a plan to provide general system API to handle media
@@ -137,7 +146,7 @@
 int cras_bt_player_create(DBusConnection *conn)
 {
 	static const DBusObjectPathVTable player_vtable = {
-		.message_function = cras_bt_player_handle_message
+	        .message_function = cras_bt_player_handle_message
 	};
 
 	DBusError dbus_error;
@@ -146,8 +155,10 @@
 
 	dbus_error_init(&dbus_error);
 
-	if (!dbus_connection_register_object_path(
-		    conn, player.object_path, &player_vtable, &dbus_error)) {
+	if (!dbus_connection_register_object_path(conn,
+						  player.object_path,
+						  &player_vtable,
+						  &dbus_error)) {
 		syslog(LOG_ERR, "Cannot register player %s",
 		       player.object_path);
 		dbus_error_free(&dbus_error);
diff --git a/cras/src/server/cras_bt_player.h b/cras/src/server/cras_bt_player.h
index 9b66d70..cce3710 100644
--- a/cras/src/server/cras_bt_player.h
+++ b/cras/src/server/cras_bt_player.h
@@ -1,4 +1,4 @@
-/* Copyright 2016 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2016 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.
  */
@@ -11,6 +11,7 @@
 
 #include "cras_bt_adapter.h"
 
+
 /* Object to register as media player so that bluetoothd will report hardware
  * volume from device through bt_transport. Properties of the player are defined
  * in BlueZ's media API.
@@ -45,4 +46,4 @@
 int cras_bt_register_player(DBusConnection *conn,
 			    const struct cras_bt_adapter *adapter);
 
-#endif /* CRAS_BT_PLAYER_H_ */
+#endif /* CRAS_BT_PLAYER_H_ */
\ No newline at end of file
diff --git a/cras/src/server/cras_bt_profile.c b/cras/src/server/cras_bt_profile.c
index d180a1b..9f898aa 100644
--- a/cras/src/server/cras_bt_profile.c
+++ b/cras/src/server/cras_bt_profile.c
@@ -16,35 +16,37 @@
 #include "cras_dbus_util.h"
 #include "utlist.h"
 
-#define PROFILE_INTROSPECT_XML                                                 \
-	DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE                              \
-	"<node>\n"                                                             \
-	"  <interface name=\"org.bluez.Profile1\">\n"                          \
-	"    <method name=\"Release\">\n"                                      \
-	"    </method>\n"                                                      \
-	"    <method name=\"NewConnection\">\n"                                \
-	"      <arg name=\"device\" type=\"o\" direction=\"in\">\n"            \
-	"      <arg name=\"fd\" type=\"h\" direction=\"in\">\n"                \
-	"      <arg name=\"fd_properties\" type=\"a{sv}\" direction=\"in\">\n" \
-	"    </method>\n"                                                      \
-	"    <method name=\"RequestDisconnection\">\n"                         \
-	"      <arg name=\"device\" type=\"o\" direction=\"in\">\n"            \
-	"    </method>\n"                                                      \
-	"    <method name=\"Cancel\">\n"                                       \
-	"    </method>\n"                                                      \
-	"  <interface name=\"" DBUS_INTERFACE_INTROSPECTABLE "\">\n"           \
-	"    <method name=\"Introspect\">\n"                                   \
-	"      <arg name=\"data\" type=\"s\" direction=\"out\"/>\n"            \
-	"    </method>\n"                                                      \
-	"  </interface>\n"                                                     \
+#define PROFILE_INTROSPECT_XML						\
+	DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE			\
+	"<node>\n"							\
+	"  <interface name=\"org.bluez.Profile1\">\n"			\
+	"    <method name=\"Release\">\n"				\
+	"    </method>\n"						\
+	"    <method name=\"NewConnection\">\n"				\
+	"      <arg name=\"device\" type=\"o\" direction=\"in\">\n"	\
+	"      <arg name=\"fd\" type=\"h\" direction=\"in\">\n"		\
+	"      <arg name=\"fd_properties\" type=\"a{sv}\" direction=\"in\">\n"\
+	"    </method>\n"						\
+	"    <method name=\"RequestDisconnection\">\n"			\
+	"      <arg name=\"device\" type=\"o\" direction=\"in\">\n"	\
+	"    </method>\n"						\
+	"    <method name=\"Cancel\">\n"				\
+	"    </method>\n"						\
+	"  <interface name=\"" DBUS_INTERFACE_INTROSPECTABLE "\">\n"	\
+	"    <method name=\"Introspect\">\n"				\
+	"      <arg name=\"data\" type=\"s\" direction=\"out\"/>\n"	\
+	"    </method>\n"						\
+	"  </interface>\n"						\
 	"</node>\n"
 
+
 /* Profiles */
 static struct cras_bt_profile *profiles;
 
-static DBusHandlerResult cras_bt_profile_handle_release(DBusConnection *conn,
-							DBusMessage *message,
-							void *arg)
+static DBusHandlerResult cras_bt_profile_handle_release(
+		DBusConnection *conn,
+		DBusMessage *message,
+		void *arg)
 {
 	DBusMessage *reply;
 	const char *profile_path;
@@ -56,7 +58,6 @@
 	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);
@@ -72,9 +73,10 @@
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-static DBusHandlerResult
-cras_bt_profile_handle_new_connection(DBusConnection *conn,
-				      DBusMessage *message, void *arg)
+static DBusHandlerResult cras_bt_profile_handle_new_connection(
+		DBusConnection *conn,
+		DBusMessage *message,
+		void *arg)
 {
 	DBusMessageIter message_iter;
 	DBusMessage *reply;
@@ -90,8 +92,8 @@
 	dbus_message_iter_get_basic(&message_iter, &object_path);
 	dbus_message_iter_next(&message_iter);
 
-	if (dbus_message_iter_get_arg_type(&message_iter) !=
-	    DBUS_TYPE_UNIX_FD) {
+	if (dbus_message_iter_get_arg_type(&message_iter)
+			!= DBUS_TYPE_UNIX_FD) {
 		syslog(LOG_ERR, "Argument not a valid unix file descriptor");
 		goto invalid;
 	}
@@ -116,9 +118,9 @@
 	if (err) {
 		syslog(LOG_INFO, "%s new connection rejected", profile->name);
 		close(fd);
-		reply = dbus_message_new_error(
-			message, "org.chromium.Cras.Error.RejectNewConnection",
-			"Possibly another headset already in use");
+		reply = dbus_message_new_error(message,
+				"org.chromium.Cras.Error.RejectNewConnection",
+				"Possibly another headset already in use");
 		if (!dbus_connection_send(conn, reply, NULL))
 			return DBUS_HANDLER_RESULT_NEED_MEMORY;
 
@@ -143,9 +145,10 @@
 	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
 
-static DBusHandlerResult
-cras_bt_profile_handle_request_disconnection(DBusConnection *conn,
-					     DBusMessage *message, void *arg)
+static DBusHandlerResult cras_bt_profile_handle_request_disconnection(
+		DBusConnection *conn,
+		DBusMessage *message,
+		void *arg)
 {
 	DBusMessageIter message_iter;
 	DBusMessage *reply;
@@ -185,9 +188,10 @@
 	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
 
-static DBusHandlerResult cras_bt_profile_handle_cancel(DBusConnection *conn,
-						       DBusMessage *message,
-						       void *arg)
+static DBusHandlerResult cras_bt_profile_handle_cancel(
+		DBusConnection *conn,
+		DBusMessage *message,
+		void *arg)
 {
 	DBusMessage *reply;
 	const char *profile_path;
@@ -215,10 +219,11 @@
 }
 
 static DBusHandlerResult cras_bt_handle_profile_messages(DBusConnection *conn,
-							 DBusMessage *message,
-							 void *arg)
+							DBusMessage *message,
+							void *arg)
 {
-	if (dbus_message_is_method_call(message, DBUS_INTERFACE_INTROSPECTABLE,
+	if (dbus_message_is_method_call(message,
+					DBUS_INTERFACE_INTROSPECTABLE,
 					"Introspect")) {
 		DBusMessage *reply;
 		const char *xml = PROFILE_INTROSPECT_XML;
@@ -226,7 +231,9 @@
 		reply = dbus_message_new_method_return(message);
 		if (!reply)
 			return DBUS_HANDLER_RESULT_NEED_MEMORY;
-		if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &xml,
+		if (!dbus_message_append_args(reply,
+					      DBUS_TYPE_STRING,
+					      &xml,
 					      DBUS_TYPE_INVALID)) {
 			dbus_message_unref(reply);
 			return DBUS_HANDLER_RESULT_NEED_MEMORY;
@@ -238,18 +245,22 @@
 
 		dbus_message_unref(reply);
 		return DBUS_HANDLER_RESULT_HANDLED;
-	} else if (dbus_message_is_method_call(message, BLUEZ_INTERFACE_PROFILE,
+	} else if (dbus_message_is_method_call(message,
+					       BLUEZ_INTERFACE_PROFILE,
 					       "Release")) {
 		return cras_bt_profile_handle_release(conn, message, arg);
-	} else if (dbus_message_is_method_call(message, BLUEZ_INTERFACE_PROFILE,
+	} else if (dbus_message_is_method_call(message,
+					       BLUEZ_INTERFACE_PROFILE,
 					       "NewConnection")) {
-		return cras_bt_profile_handle_new_connection(conn, message,
-							     arg);
-	} else if (dbus_message_is_method_call(message, BLUEZ_INTERFACE_PROFILE,
+		return cras_bt_profile_handle_new_connection(conn, message, arg);
+	} else if (dbus_message_is_method_call(message,
+					       BLUEZ_INTERFACE_PROFILE,
 					       "RequestDisconnection")) {
-		return cras_bt_profile_handle_request_disconnection(
-			conn, message, arg);
-	} else if (dbus_message_is_method_call(message, BLUEZ_INTERFACE_PROFILE,
+		return cras_bt_profile_handle_request_disconnection(conn,
+								    message,
+								    arg);
+	} else if (dbus_message_is_method_call(message,
+					       BLUEZ_INTERFACE_PROFILE,
 					       "Cancel")) {
 		return cras_bt_profile_handle_cancel(conn, message, arg);
 	} else {
@@ -293,14 +304,15 @@
 	dbus_message_iter_append_basic(&message_iter, DBUS_TYPE_OBJECT_PATH,
 				       &profile->object_path);
 	dbus_message_iter_append_basic(&message_iter, DBUS_TYPE_STRING,
-				       &profile->uuid);
+					       &profile->uuid);
 
-	dbus_message_iter_open_container(
-		&message_iter, DBUS_TYPE_ARRAY,
-		DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING
-			DBUS_TYPE_VARIANT_AS_STRING
-				DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
-		&properties_array_iter);
+	dbus_message_iter_open_container(&message_iter,
+					 DBUS_TYPE_ARRAY,
+					 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+					 DBUS_TYPE_STRING_AS_STRING
+					 DBUS_TYPE_VARIANT_AS_STRING
+					 DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+					 &properties_array_iter);
 
 	if (!append_key_value(&properties_array_iter, "Name", DBUS_TYPE_STRING,
 			      DBUS_TYPE_STRING_AS_STRING, &profile->name)) {
@@ -317,23 +329,25 @@
 	}
 
 	if (!append_key_value(&properties_array_iter, "Version",
-			      DBUS_TYPE_UINT16, DBUS_TYPE_UINT16_AS_STRING,
-			      &profile->version)) {
+			      DBUS_TYPE_UINT16,
+			      DBUS_TYPE_UINT16_AS_STRING, &profile->version)) {
 		dbus_message_unref(method_call);
 		return -ENOMEM;
 	}
 
-	if (profile->role &&
-	    !append_key_value(&properties_array_iter, "Role", DBUS_TYPE_STRING,
-			      DBUS_TYPE_STRING_AS_STRING, &profile->role)) {
+	if (profile->role && !append_key_value(&properties_array_iter, "Role",
+					       DBUS_TYPE_STRING,
+					       DBUS_TYPE_STRING_AS_STRING,
+					       &profile->role)) {
 		dbus_message_unref(method_call);
 		return -ENOMEM;
 	}
 
-	if (profile->features &&
-	    !append_key_value(&properties_array_iter, "Features",
-			      DBUS_TYPE_UINT16, DBUS_TYPE_UINT16_AS_STRING,
-			      &profile->features)) {
+	if (profile->features && !append_key_value(&properties_array_iter,
+						   "Features",
+						   DBUS_TYPE_UINT16,
+						   DBUS_TYPE_UINT16_AS_STRING,
+						   &profile->features)) {
 		dbus_message_unref(method_call);
 		return -ENOMEM;
 	}
@@ -351,8 +365,9 @@
 	if (!pending_call)
 		return -EIO;
 
-	if (!dbus_pending_call_set_notify(
-		    pending_call, cras_bt_on_register_profile, NULL, NULL)) {
+	if (!dbus_pending_call_set_notify(pending_call,
+					  cras_bt_on_register_profile,
+					  NULL, NULL)) {
 		dbus_pending_call_cancel(pending_call);
 		dbus_pending_call_unref(pending_call);
 		syslog(LOG_ERR, "register profile fail on set notify");
@@ -367,7 +382,7 @@
 	struct cras_bt_profile *profile;
 	int err;
 
-	DL_FOREACH (profiles, profile) {
+	DL_FOREACH(profiles, profile) {
 		err = cras_bt_register_profile(conn, profile);
 		if (err)
 			return err;
@@ -376,18 +391,23 @@
 	return 0;
 }
 
-int cras_bt_add_profile(DBusConnection *conn, struct cras_bt_profile *profile)
+int cras_bt_add_profile(DBusConnection *conn,
+			struct cras_bt_profile *profile)
 {
 	static const DBusObjectPathVTable profile_vtable = {
-		NULL, cras_bt_handle_profile_messages, NULL, NULL, NULL, NULL
+		NULL,
+		cras_bt_handle_profile_messages,
+		NULL, NULL, NULL, NULL
 	};
 
 	DBusError dbus_error;
 
 	dbus_error_init(&dbus_error);
 
-	if (!dbus_connection_register_object_path(
-		    conn, profile->object_path, &profile_vtable, &dbus_error)) {
+	if (!dbus_connection_register_object_path(conn,
+						  profile->object_path,
+						  &profile_vtable,
+						  &dbus_error)) {
 		syslog(LOG_ERR, "Could not register BT profile %s: %s",
 		       profile->object_path, dbus_error.message);
 		dbus_error_free(&dbus_error);
@@ -403,14 +423,14 @@
 {
 	struct cras_bt_profile *profile;
 
-	DL_FOREACH (profiles, profile)
+	DL_FOREACH(profiles, profile)
 		profile->release(profile);
 }
 
 struct cras_bt_profile *cras_bt_profile_get(const char *path)
 {
 	struct cras_bt_profile *profile;
-	DL_FOREACH (profiles, profile) {
+	DL_FOREACH(profiles, profile) {
 		if (strcmp(profile->object_path, path) == 0)
 			return profile;
 	}
@@ -421,6 +441,6 @@
 void cras_bt_profile_on_device_disconnected(struct cras_bt_device *device)
 {
 	struct cras_bt_profile *profile;
-	DL_FOREACH (profiles, profile)
+	DL_FOREACH(profiles, profile)
 		profile->request_disconnection(profile, device);
 }
diff --git a/cras/src/server/cras_bt_profile.h b/cras/src/server/cras_bt_profile.h
index ed42660..c628bf6 100644
--- a/cras/src/server/cras_bt_profile.h
+++ b/cras/src/server/cras_bt_profile.h
@@ -27,7 +27,8 @@
 	void (*release)(struct cras_bt_profile *profile);
 	int (*new_connection)(DBusConnection *conn,
 			      struct cras_bt_profile *profile,
-			      struct cras_bt_device *device, int rfcomm_fd);
+			      struct cras_bt_device *device,
+			      int rfcomm_fd);
 	void (*request_disconnection)(struct cras_bt_profile *profile,
 				      struct cras_bt_device *device);
 	void (*cancel)(struct cras_bt_profile *profile);
@@ -39,7 +40,8 @@
  *    conn - The dbus connection.
  *    profile - Pointer to the profile structure to be add.
  */
-int cras_bt_add_profile(DBusConnection *conn, struct cras_bt_profile *profile);
+int cras_bt_add_profile(DBusConnection *conn,
+			struct cras_bt_profile *profile);
 
 /* Gets the profile by object path.
  * Args:
diff --git a/cras/src/server/cras_bt_transport.c b/cras/src/server/cras_bt_transport.c
index 9e06dac..4037cfd 100644
--- a/cras/src/server/cras_bt_transport.c
+++ b/cras/src/server/cras_bt_transport.c
@@ -14,11 +14,11 @@
 
 #include "cras_bt_device.h"
 #include "cras_bt_endpoint.h"
-#include "cras_bt_log.h"
 #include "cras_bt_transport.h"
 #include "cras_bt_constants.h"
 #include "utlist.h"
 
+
 struct cras_bt_transport {
 	DBusConnection *conn;
 	char *object_path;
@@ -32,7 +32,6 @@
 	uint16_t read_mtu;
 	uint16_t write_mtu;
 	int volume;
-	int removed;
 
 	struct cras_bt_endpoint *endpoint;
 	struct cras_bt_transport *prev, *next;
@@ -67,30 +66,10 @@
 }
 
 void cras_bt_transport_set_endpoint(struct cras_bt_transport *transport,
-				    struct cras_bt_endpoint *endpoint)
-{
+				    struct cras_bt_endpoint *endpoint) {
 	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);
@@ -114,11 +93,12 @@
 	}
 }
 
+
 struct cras_bt_transport *cras_bt_transport_get(const char *object_path)
 {
 	struct cras_bt_transport *transport;
 
-	DL_FOREACH (transports, transport) {
+	DL_FOREACH(transports, transport) {
 		if (strcmp(transport->object_path, object_path) == 0)
 			return transport;
 	}
@@ -126,14 +106,14 @@
 	return NULL;
 }
 
-size_t
-cras_bt_transport_get_list(struct cras_bt_transport ***transport_list_out)
+size_t cras_bt_transport_get_list(
+	struct cras_bt_transport ***transport_list_out)
 {
 	struct cras_bt_transport *transport;
 	struct cras_bt_transport **transport_list = NULL;
 	size_t num_transports = 0;
 
-	DL_FOREACH (transports, transport) {
+	DL_FOREACH(transports, transport) {
 		struct cras_bt_transport **tmp;
 
 		tmp = realloc(transport_list,
@@ -151,20 +131,20 @@
 	return num_transports;
 }
 
-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 transport->object_path;
 }
 
-struct cras_bt_device *
-cras_bt_transport_device(const struct cras_bt_transport *transport)
+struct cras_bt_device *cras_bt_transport_device(
+	const struct cras_bt_transport *transport)
 {
 	return transport->device;
 }
 
-enum cras_bt_device_profile
-cras_bt_transport_profile(const struct cras_bt_transport *transport)
+enum cras_bt_device_profile cras_bt_transport_profile(
+	const struct cras_bt_transport *transport)
 {
 	return transport->profile;
 }
@@ -181,8 +161,8 @@
 	return 0;
 }
 
-enum cras_bt_transport_state
-cras_bt_transport_state(const struct cras_bt_transport *transport)
+enum cras_bt_transport_state cras_bt_transport_state(
+	const struct cras_bt_transport *transport)
 {
 	return transport->state;
 }
@@ -197,8 +177,8 @@
 	return transport->write_mtu;
 }
 
-static enum cras_bt_transport_state
-cras_bt_transport_state_from_string(const char *value)
+static enum cras_bt_transport_state cras_bt_transport_state_from_string(
+	const char *value)
 {
 	if (strcmp("idle", value) == 0)
 		return CRAS_BT_TRANSPORT_STATE_IDLE;
@@ -212,9 +192,11 @@
 
 static void cras_bt_transport_state_changed(struct cras_bt_transport *transport)
 {
-	if (transport->endpoint && transport->endpoint->transport_state_changed)
+	if (transport->endpoint &&
+	    transport->endpoint->transport_state_changed)
 		transport->endpoint->transport_state_changed(
-			transport->endpoint, transport);
+				transport->endpoint,
+				transport);
 }
 
 /* Updates bt_device when certain transport property has changed. */
@@ -231,13 +213,15 @@
 	if (transport->volume != -1) {
 		cras_bt_device_set_use_hardware_volume(transport->device, 1);
 		cras_bt_device_update_hardware_volume(
-			transport->device, transport->volume * 100 / 127);
+				transport->device,
+				transport->volume * 100 / 127);
 	}
 }
 
-void cras_bt_transport_update_properties(struct cras_bt_transport *transport,
-					 DBusMessageIter *properties_array_iter,
-					 DBusMessageIter *invalidated_array_iter)
+void cras_bt_transport_update_properties(
+	struct cras_bt_transport *transport,
+	DBusMessageIter *properties_array_iter,
+	DBusMessageIter *invalidated_array_iter)
 {
 	while (dbus_message_iter_get_arg_type(properties_array_iter) !=
 	       DBUS_TYPE_INVALID) {
@@ -288,24 +272,25 @@
 			dbus_message_iter_get_basic(&variant_iter, &obj_path);
 			transport->device = cras_bt_device_get(obj_path);
 			if (!transport->device) {
-				syslog(LOG_ERR,
-				       "Device %s not found at update"
+				syslog(LOG_ERR, "Device %s not found at update"
 				       "transport properties",
 				       obj_path);
-				transport->device = cras_bt_device_create(
-					transport->conn, obj_path);
+				transport->device =
+					cras_bt_device_create(transport->conn,
+							      obj_path);
 				cras_bt_transport_update_device(transport);
 			}
-		} else if (strcmp(dbus_message_iter_get_signature(&variant_iter),
-				  "ay") == 0 &&
+		} else if (strcmp(
+				dbus_message_iter_get_signature(&variant_iter),
+				"ay") == 0 &&
 			   strcmp(key, "Configuration") == 0) {
 			DBusMessageIter value_iter;
 			char *value;
 			int len;
 
 			dbus_message_iter_recurse(&variant_iter, &value_iter);
-			dbus_message_iter_get_fixed_array(&value_iter, &value,
-							  &len);
+			dbus_message_iter_get_fixed_array(&value_iter,
+							  &value, &len);
 
 			free(transport->configuration);
 			transport->configuration_len = 0;
@@ -329,7 +314,7 @@
 
 	while (invalidated_array_iter &&
 	       dbus_message_iter_get_arg_type(invalidated_array_iter) !=
-		       DBUS_TYPE_INVALID) {
+	       DBUS_TYPE_INVALID) {
 		const char *key;
 
 		dbus_message_iter_get_basic(invalidated_array_iter, &key);
@@ -374,10 +359,11 @@
 	DBusMessageIter message_iter, variant;
 	DBusPendingCall *pending_call;
 
-	method_call =
-		dbus_message_new_method_call(BLUEZ_SERVICE,
-					     transport->object_path,
-					     DBUS_INTERFACE_PROPERTIES, "Set");
+	method_call = dbus_message_new_method_call(
+		BLUEZ_SERVICE,
+		transport->object_path,
+		DBUS_INTERFACE_PROPERTIES,
+		"Set");
 	if (!method_call)
 		return -ENOMEM;
 
@@ -403,7 +389,8 @@
 	if (!pending_call)
 		return -EIO;
 
-	if (!dbus_pending_call_set_notify(pending_call, on_transport_volume_set,
+	if (!dbus_pending_call_set_notify(pending_call,
+					  on_transport_volume_set,
 					  NULL, NULL)) {
 		dbus_pending_call_cancel(pending_call);
 		dbus_pending_call_unref(pending_call);
@@ -417,29 +404,31 @@
 {
 	DBusMessage *method_call, *reply;
 	DBusError dbus_error;
-	int rc = 0;
 
 	if (transport->fd >= 0)
 		return 0;
 
 	method_call = dbus_message_new_method_call(
-		BLUEZ_SERVICE, transport->object_path,
-		BLUEZ_INTERFACE_MEDIA_TRANSPORT, "Acquire");
+		BLUEZ_SERVICE,
+		transport->object_path,
+		BLUEZ_INTERFACE_MEDIA_TRANSPORT,
+		"Acquire");
 	if (!method_call)
 		return -ENOMEM;
 
 	dbus_error_init(&dbus_error);
 
 	reply = dbus_connection_send_with_reply_and_block(
-		transport->conn, method_call, DBUS_TIMEOUT_USE_DEFAULT,
+		transport->conn,
+		method_call,
+		DBUS_TIMEOUT_USE_DEFAULT,
 		&dbus_error);
 	if (!reply) {
 		syslog(LOG_ERR, "Failed to acquire transport %s: %s",
 		       transport->object_path, dbus_error.message);
 		dbus_error_free(&dbus_error);
 		dbus_message_unref(method_call);
-		rc = -EIO;
-		goto acquire_fail;
+		return -EIO;
 	}
 
 	dbus_message_unref(method_call);
@@ -448,29 +437,23 @@
 		syslog(LOG_ERR, "Acquire returned error: %s",
 		       dbus_message_get_error_name(reply));
 		dbus_message_unref(reply);
-		rc = -EIO;
-		goto acquire_fail;
+		return -EIO;
 	}
 
-	if (!dbus_message_get_args(
-		    reply, &dbus_error, DBUS_TYPE_UNIX_FD, &(transport->fd),
-		    DBUS_TYPE_UINT16, &(transport->read_mtu), DBUS_TYPE_UINT16,
-		    &(transport->write_mtu), DBUS_TYPE_INVALID)) {
+	if (!dbus_message_get_args(reply, &dbus_error,
+				   DBUS_TYPE_UNIX_FD, &(transport->fd),
+				   DBUS_TYPE_UINT16, &(transport->read_mtu),
+				   DBUS_TYPE_UINT16, &(transport->write_mtu),
+				   DBUS_TYPE_INVALID)) {
 		syslog(LOG_ERR, "Bad Acquire reply received: %s",
 		       dbus_error.message);
 		dbus_error_free(&dbus_error);
 		dbus_message_unref(reply);
-		rc = -EINVAL;
-		goto acquire_fail;
+		return -EINVAL;
 	}
 
-	BTLOG(btlog, BT_TRANSPORT_ACQUIRE, 1, transport->fd);
 	dbus_message_unref(reply);
 	return 0;
-
-acquire_fail:
-	BTLOG(btlog, BT_TRANSPORT_ACQUIRE, 0, 0);
-	return rc;
 }
 
 int cras_bt_transport_try_acquire(struct cras_bt_transport *transport)
@@ -480,15 +463,19 @@
 	int fd, read_mtu, write_mtu;
 
 	method_call = dbus_message_new_method_call(
-		BLUEZ_SERVICE, transport->object_path,
-		BLUEZ_INTERFACE_MEDIA_TRANSPORT, "TryAcquire");
+			BLUEZ_SERVICE,
+			transport->object_path,
+			BLUEZ_INTERFACE_MEDIA_TRANSPORT,
+			"TryAcquire");
 	if (!method_call)
 		return -ENOMEM;
 
 	dbus_error_init(&dbus_error);
 
 	reply = dbus_connection_send_with_reply_and_block(
-		transport->conn, method_call, DBUS_TIMEOUT_USE_DEFAULT,
+		transport->conn,
+		method_call,
+		DBUS_TIMEOUT_USE_DEFAULT,
 		&dbus_error);
 	if (!reply) {
 		syslog(LOG_ERR, "Failed to try acquire transport %s: %s",
@@ -507,7 +494,8 @@
 		return -EIO;
 	}
 
-	if (!dbus_message_get_args(reply, &dbus_error, DBUS_TYPE_UNIX_FD, &fd,
+	if (!dbus_message_get_args(reply, &dbus_error,
+				   DBUS_TYPE_UNIX_FD, &fd,
 				   DBUS_TYPE_UINT16, &read_mtu,
 				   DBUS_TYPE_UINT16, &write_mtu,
 				   DBUS_TYPE_INVALID)) {
@@ -556,8 +544,6 @@
 	if (transport->fd < 0)
 		return 0;
 
-	BTLOG(btlog, BT_TRANSPORT_RELEASE, transport->fd, 0);
-
 	/* Close the transport on our end no matter whether or not the server
 	 * gives us an error.
 	 */
@@ -565,8 +551,10 @@
 	transport->fd = -1;
 
 	method_call = dbus_message_new_method_call(
-		BLUEZ_SERVICE, transport->object_path,
-		BLUEZ_INTERFACE_MEDIA_TRANSPORT, "Release");
+		BLUEZ_SERVICE,
+		transport->object_path,
+		BLUEZ_INTERFACE_MEDIA_TRANSPORT,
+		"Release");
 	if (!method_call)
 		return -ENOMEM;
 
@@ -574,7 +562,9 @@
 		dbus_error_init(&dbus_error);
 
 		reply = dbus_connection_send_with_reply_and_block(
-			transport->conn, method_call, DBUS_TIMEOUT_USE_DEFAULT,
+			transport->conn,
+			method_call,
+			DBUS_TIMEOUT_USE_DEFAULT,
 			&dbus_error);
 		if (!reply) {
 			syslog(LOG_ERR, "Failed to release transport %s: %s",
@@ -596,8 +586,10 @@
 		dbus_message_unref(reply);
 	} else {
 		if (!dbus_connection_send_with_reply(
-			    transport->conn, method_call, &pending_call,
-			    DBUS_TIMEOUT_USE_DEFAULT)) {
+				transport->conn,
+				method_call,
+				&pending_call,
+				DBUS_TIMEOUT_USE_DEFAULT)) {
 			dbus_message_unref(method_call);
 			return -ENOMEM;
 		}
diff --git a/cras/src/server/cras_bt_transport.h b/cras/src/server/cras_bt_transport.h
index 6722fb0..bafd9d2 100644
--- a/cras/src/server/cras_bt_transport.h
+++ b/cras/src/server/cras_bt_transport.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
@@ -20,40 +20,28 @@
 	CRAS_BT_TRANSPORT_STATE_ACTIVE
 };
 
+
 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();
 
 struct cras_bt_transport *cras_bt_transport_get(const char *object_path);
-size_t
-cras_bt_transport_get_list(struct cras_bt_transport ***transport_list_out);
+size_t cras_bt_transport_get_list(
+	struct cras_bt_transport ***transport_list_out);
 
-const char *
-cras_bt_transport_object_path(const struct cras_bt_transport *transport);
-struct cras_bt_device *
-cras_bt_transport_device(const struct cras_bt_transport *transport);
-enum cras_bt_device_profile
-cras_bt_transport_profile(const struct cras_bt_transport *transport);
+const char *cras_bt_transport_object_path(
+	const struct cras_bt_transport *transport);
+struct cras_bt_device *cras_bt_transport_device(
+	const struct cras_bt_transport *transport);
+enum cras_bt_device_profile cras_bt_transport_profile(
+	const struct cras_bt_transport *transport);
 int cras_bt_transport_configuration(const struct cras_bt_transport *transport,
 				    void *configuration, int len);
-enum cras_bt_transport_state
-cras_bt_transport_state(const struct cras_bt_transport *transport);
+enum cras_bt_transport_state cras_bt_transport_state(
+	const struct cras_bt_transport *transport);
 
 int cras_bt_transport_fd(const struct cras_bt_transport *transport);
 uint16_t cras_bt_transport_write_mtu(const struct cras_bt_transport *transport);
diff --git a/cras/src/server/cras_capture_rclient.c b/cras/src/server/cras_capture_rclient.c
deleted file mode 100644
index c13792c..0000000
--- a/cras/src/server/cras_capture_rclient.c
+++ /dev/null
@@ -1,103 +0,0 @@
-/* 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
deleted file mode 100644
index 129e559..0000000
--- a/cras/src/server/cras_capture_rclient.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/* 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
deleted file mode 100644
index c0eea5d..0000000
--- a/cras/src/server/cras_control_rclient.c
+++ /dev/null
@@ -1,555 +0,0 @@
-/* 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 <assert.h>
-#include <stdlib.h>
-#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"
-#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_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"
-#include "utlist.h"
-
-/* Handles dumping audio thread debug info back to the client. */
-static void dump_audio_thread_info(struct cras_rclient *client)
-{
-	struct cras_client_audio_debug_info_ready msg;
-	struct cras_server_state *state;
-
-	cras_fill_client_audio_debug_info_ready(&msg);
-	state = cras_system_state_get_no_lock();
-	audio_thread_dump_thread_info(cras_iodev_list_get_audio_thread(),
-				      &state->audio_debug_info);
-	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)
-{
-	struct cras_client_audio_debug_info_ready msg;
-
-	cras_fill_client_audio_debug_info_ready(&msg);
-	cras_system_state_dump_snapshots();
-	client->ops->send_message_to_client(client, &msg.header, NULL, 0);
-}
-
-static void handle_get_hotword_models(struct cras_rclient *client,
-				      cras_node_id_t node_id)
-{
-	struct cras_client_get_hotword_models_ready *msg;
-	char *hotword_models;
-	unsigned hotword_models_size;
-	uint8_t buf[CRAS_CLIENT_MAX_MSG_SIZE];
-
-	msg = (struct cras_client_get_hotword_models_ready *)buf;
-	hotword_models = cras_iodev_list_get_hotword_models(node_id);
-	if (!hotword_models)
-		goto empty_reply;
-	hotword_models_size = strlen(hotword_models);
-	if (hotword_models_size > CRAS_MAX_HOTWORD_MODELS) {
-		free(hotword_models);
-		goto empty_reply;
-	}
-
-	cras_fill_client_get_hotword_models_ready(msg, hotword_models,
-						  hotword_models_size);
-	client->ops->send_message_to_client(client, &msg->header, NULL, 0);
-	free(hotword_models);
-	return;
-
-empty_reply:
-	cras_fill_client_get_hotword_models_ready(msg, NULL, 0);
-	client->ops->send_message_to_client(client, &msg->header, NULL, 0);
-}
-
-/* Client notification callback functions. */
-
-static void send_output_volume_changed(void *context, int32_t volume)
-{
-	struct cras_client_volume_changed msg;
-	struct cras_rclient *client = (struct cras_rclient *)context;
-
-	cras_fill_client_output_volume_changed(&msg, volume);
-	client->ops->send_message_to_client(client, &msg.header, NULL, 0);
-}
-
-static void send_output_mute_changed(void *context, int muted, int user_muted,
-				     int mute_locked)
-{
-	struct cras_client_mute_changed msg;
-	struct cras_rclient *client = (struct cras_rclient *)context;
-
-	cras_fill_client_output_mute_changed(&msg, muted, user_muted,
-					     mute_locked);
-	client->ops->send_message_to_client(client, &msg.header, NULL, 0);
-}
-
-static void send_capture_gain_changed(void *context, int32_t gain)
-{
-	struct cras_client_volume_changed msg;
-	struct cras_rclient *client = (struct cras_rclient *)context;
-
-	cras_fill_client_capture_gain_changed(&msg, gain);
-	client->ops->send_message_to_client(client, &msg.header, NULL, 0);
-}
-
-static void send_capture_mute_changed(void *context, int muted, int mute_locked)
-{
-	struct cras_client_mute_changed msg;
-	struct cras_rclient *client = (struct cras_rclient *)context;
-
-	cras_fill_client_capture_mute_changed(&msg, muted, mute_locked);
-	client->ops->send_message_to_client(client, &msg.header, NULL, 0);
-}
-
-static void send_nodes_changed(void *context)
-{
-	struct cras_client_nodes_changed msg;
-	struct cras_rclient *client = (struct cras_rclient *)context;
-
-	cras_fill_client_nodes_changed(&msg);
-	client->ops->send_message_to_client(client, &msg.header, NULL, 0);
-}
-
-static void send_active_node_changed(void *context,
-				     enum CRAS_STREAM_DIRECTION dir,
-				     cras_node_id_t node_id)
-{
-	struct cras_client_active_node_changed msg;
-	struct cras_rclient *client = (struct cras_rclient *)context;
-
-	cras_fill_client_active_node_changed(&msg, dir, node_id);
-	client->ops->send_message_to_client(client, &msg.header, NULL, 0);
-}
-
-static void send_output_node_volume_changed(void *context,
-					    cras_node_id_t node_id,
-					    int32_t volume)
-{
-	struct cras_client_node_value_changed msg;
-	struct cras_rclient *client = (struct cras_rclient *)context;
-
-	cras_fill_client_output_node_volume_changed(&msg, node_id, volume);
-	client->ops->send_message_to_client(client, &msg.header, NULL, 0);
-}
-
-static void send_node_left_right_swapped_changed(void *context,
-						 cras_node_id_t node_id,
-						 int swapped)
-{
-	struct cras_client_node_value_changed msg;
-	struct cras_rclient *client = (struct cras_rclient *)context;
-
-	cras_fill_client_node_left_right_swapped_changed(&msg, node_id,
-							 swapped);
-	client->ops->send_message_to_client(client, &msg.header, NULL, 0);
-}
-
-static void send_input_node_gain_changed(void *context, cras_node_id_t node_id,
-					 int32_t gain)
-{
-	struct cras_client_node_value_changed msg;
-	struct cras_rclient *client = (struct cras_rclient *)context;
-
-	cras_fill_client_input_node_gain_changed(&msg, node_id, gain);
-	client->ops->send_message_to_client(client, &msg.header, NULL, 0);
-}
-
-static void send_num_active_streams_changed(void *context,
-					    enum CRAS_STREAM_DIRECTION dir,
-					    uint32_t num_active_streams)
-{
-	struct cras_client_num_active_streams_changed msg;
-	struct cras_rclient *client = (struct cras_rclient *)context;
-
-	cras_fill_client_num_active_streams_changed(&msg, dir,
-						    num_active_streams);
-	client->ops->send_message_to_client(client, &msg.header, NULL, 0);
-}
-
-static void register_for_notification(struct cras_rclient *client,
-				      enum CRAS_CLIENT_MESSAGE_ID msg_id,
-				      int do_register)
-{
-	struct cras_observer_ops observer_ops;
-	int empty;
-
-	cras_observer_get_ops(client->observer, &observer_ops);
-
-	switch (msg_id) {
-	case CRAS_CLIENT_OUTPUT_VOLUME_CHANGED:
-		observer_ops.output_volume_changed =
-			do_register ? send_output_volume_changed : NULL;
-		break;
-	case CRAS_CLIENT_OUTPUT_MUTE_CHANGED:
-		observer_ops.output_mute_changed =
-			do_register ? send_output_mute_changed : NULL;
-		break;
-	case CRAS_CLIENT_CAPTURE_GAIN_CHANGED:
-		observer_ops.capture_gain_changed =
-			do_register ? send_capture_gain_changed : NULL;
-		break;
-	case CRAS_CLIENT_CAPTURE_MUTE_CHANGED:
-		observer_ops.capture_mute_changed =
-			do_register ? send_capture_mute_changed : NULL;
-		break;
-	case CRAS_CLIENT_NODES_CHANGED:
-		observer_ops.nodes_changed =
-			do_register ? send_nodes_changed : NULL;
-		break;
-	case CRAS_CLIENT_ACTIVE_NODE_CHANGED:
-		observer_ops.active_node_changed =
-			do_register ? send_active_node_changed : NULL;
-		break;
-	case CRAS_CLIENT_OUTPUT_NODE_VOLUME_CHANGED:
-		observer_ops.output_node_volume_changed =
-			do_register ? send_output_node_volume_changed : NULL;
-		break;
-	case CRAS_CLIENT_NODE_LEFT_RIGHT_SWAPPED_CHANGED:
-		observer_ops.node_left_right_swapped_changed =
-			do_register ? send_node_left_right_swapped_changed :
-				      NULL;
-		break;
-	case CRAS_CLIENT_INPUT_NODE_GAIN_CHANGED:
-		observer_ops.input_node_gain_changed =
-			do_register ? send_input_node_gain_changed : NULL;
-		break;
-	case CRAS_CLIENT_NUM_ACTIVE_STREAMS_CHANGED:
-		observer_ops.num_active_streams_changed =
-			do_register ? send_num_active_streams_changed : NULL;
-		break;
-	default:
-		syslog(LOG_ERR, "Invalid client notification message ID: %u",
-		       msg_id);
-		break;
-	}
-
-	empty = cras_observer_ops_are_empty(&observer_ops);
-	if (client->observer) {
-		if (empty) {
-			cras_observer_remove(client->observer);
-			client->observer = NULL;
-		} else {
-			cras_observer_set_ops(client->observer, &observer_ops);
-		}
-	} else if (!empty) {
-		client->observer = cras_observer_add(&observer_ops, client);
-	}
-}
-
-static int direction_valid(enum CRAS_STREAM_DIRECTION direction)
-{
-	return direction < CRAS_NUM_DIRECTIONS &&
-	       direction != CRAS_STREAM_UNDEFINED;
-}
-
-/* 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)) {
-			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;
-		}
-	}
-	case CRAS_SERVER_DISCONNECT_STREAM:
-		if (!MSG_LEN_VALID(msg, struct cras_disconnect_stream_message))
-			return -EINVAL;
-		rclient_handle_client_stream_disconnect(
-			client,
-			(const struct cras_disconnect_stream_message *)msg);
-		break;
-	case CRAS_SERVER_SET_SYSTEM_VOLUME:
-		if (!MSG_LEN_VALID(msg, struct cras_set_system_volume))
-			return -EINVAL;
-		cras_system_set_volume(
-			((const struct cras_set_system_volume *)msg)->volume);
-		break;
-	case CRAS_SERVER_SET_SYSTEM_MUTE:
-		if (!MSG_LEN_VALID(msg, struct cras_set_system_mute))
-			return -EINVAL;
-		cras_system_set_mute(
-			((const struct cras_set_system_mute *)msg)->mute);
-		break;
-	case CRAS_SERVER_SET_USER_MUTE:
-		if (!MSG_LEN_VALID(msg, struct cras_set_system_mute))
-			return -EINVAL;
-		cras_system_set_user_mute(
-			((const struct cras_set_system_mute *)msg)->mute);
-		break;
-	case CRAS_SERVER_SET_SYSTEM_MUTE_LOCKED:
-		if (!MSG_LEN_VALID(msg, struct cras_set_system_mute))
-			return -EINVAL;
-		cras_system_set_mute_locked(
-			((const struct cras_set_system_mute *)msg)->mute);
-		break;
-	case CRAS_SERVER_SET_SYSTEM_CAPTURE_GAIN: {
-		const struct cras_set_system_capture_gain *m =
-			(const struct cras_set_system_capture_gain *)msg;
-		if (!MSG_LEN_VALID(msg, struct cras_set_system_capture_gain))
-			return -EINVAL;
-		cras_system_set_capture_gain(m->gain);
-		break;
-	}
-	case CRAS_SERVER_SET_SYSTEM_CAPTURE_MUTE:
-		if (!MSG_LEN_VALID(msg, struct cras_set_system_mute))
-			return -EINVAL;
-		cras_system_set_capture_mute(
-			((const struct cras_set_system_mute *)msg)->mute);
-		break;
-	case CRAS_SERVER_SET_SYSTEM_CAPTURE_MUTE_LOCKED:
-		if (!MSG_LEN_VALID(msg, struct cras_set_system_mute))
-			return -EINVAL;
-		cras_system_set_capture_mute_locked(
-			((const struct cras_set_system_mute *)msg)->mute);
-		break;
-	case CRAS_SERVER_SET_NODE_ATTR: {
-		const struct cras_set_node_attr *m =
-			(const struct cras_set_node_attr *)msg;
-		if (!MSG_LEN_VALID(msg, struct cras_set_node_attr))
-			return -EINVAL;
-		cras_iodev_list_set_node_attr(m->node_id, m->attr, m->value);
-		break;
-	}
-	case CRAS_SERVER_SELECT_NODE: {
-		const struct cras_select_node *m =
-			(const struct cras_select_node *)msg;
-		if (!MSG_LEN_VALID(msg, struct cras_select_node) ||
-		    !direction_valid(m->direction))
-			return -EINVAL;
-		cras_iodev_list_select_node(m->direction, m->node_id);
-		break;
-	}
-	case CRAS_SERVER_ADD_ACTIVE_NODE: {
-		const struct cras_add_active_node *m =
-			(const struct cras_add_active_node *)msg;
-		if (!MSG_LEN_VALID(msg, struct cras_add_active_node) ||
-		    !direction_valid(m->direction))
-			return -EINVAL;
-		cras_iodev_list_add_active_node(m->direction, m->node_id);
-		break;
-	}
-	case CRAS_SERVER_RM_ACTIVE_NODE: {
-		const struct cras_rm_active_node *m =
-			(const struct cras_rm_active_node *)msg;
-		if (!MSG_LEN_VALID(msg, struct cras_rm_active_node) ||
-		    !direction_valid(m->direction))
-			return -EINVAL;
-		cras_iodev_list_rm_active_node(m->direction, m->node_id);
-		break;
-	}
-	case CRAS_SERVER_RELOAD_DSP:
-		cras_dsp_reload_ini();
-		break;
-	case CRAS_SERVER_DUMP_DSP_INFO:
-		cras_dsp_dump_info();
-		break;
-	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;
-
-		state = cras_system_state_get_no_lock();
-#ifdef CRAS_DBUS
-		memcpy(&state->bt_debug_info.bt_log, btlog,
-		       sizeof(struct cras_bt_debug_info));
-#else
-		memset(&state->bt_debug_info.bt_log, 0,
-		       sizeof(struct cras_bt_debug_info));
-#endif
-
-		cras_fill_client_audio_debug_info_ready(&msg);
-		client->ops->send_message_to_client(client, &msg.header, NULL,
-						    0);
-		break;
-	}
-	case CRAS_SERVER_SET_BT_WBS_ENABLED: {
-		const struct cras_set_bt_wbs_enabled *m =
-			(const struct cras_set_bt_wbs_enabled *)msg;
-		if (!MSG_LEN_VALID(msg, struct cras_set_bt_wbs_enabled))
-			return -EINVAL;
-		cras_system_set_bt_wbs_enabled(m->enabled);
-		break;
-	}
-	case CRAS_SERVER_DUMP_SNAPSHOTS:
-		dump_audio_thread_snapshots(client);
-		break;
-	case CRAS_SERVER_ADD_TEST_DEV: {
-		const struct cras_add_test_dev *m =
-			(const struct cras_add_test_dev *)msg;
-		if (!MSG_LEN_VALID(msg, struct cras_add_test_dev))
-			return -EINVAL;
-		cras_iodev_list_add_test_dev(m->type);
-		break;
-	}
-	case CRAS_SERVER_TEST_DEV_COMMAND: {
-		const struct cras_test_dev_command *m =
-			(const struct cras_test_dev_command *)msg;
-		if (!MSG_LEN_VALID(msg, struct cras_test_dev_command))
-			return -EINVAL;
-		cras_iodev_list_test_dev_command(
-			m->iodev_idx, (enum CRAS_TEST_IODEV_CMD)m->command,
-			m->data_len, m->data);
-		break;
-	}
-	case CRAS_SERVER_SUSPEND:
-		cras_system_set_suspended(1);
-		break;
-	case CRAS_SERVER_RESUME:
-		cras_system_set_suspended(0);
-		break;
-	case CRAS_CONFIG_GLOBAL_REMIX: {
-		const struct cras_config_global_remix *m =
-			(const struct cras_config_global_remix *)msg;
-		if (!MSG_LEN_VALID(msg, struct cras_config_global_remix) ||
-		    m->num_channels > CRAS_MAX_REMIX_CHANNELS)
-			return -EINVAL;
-		size_t size_with_coefficients =
-			sizeof(*m) + m->num_channels * m->num_channels *
-					     sizeof(m->coefficient[0]);
-		if (size_with_coefficients != msg->length)
-			return -EINVAL;
-		audio_thread_config_global_remix(
-			cras_iodev_list_get_audio_thread(), m->num_channels,
-			m->coefficient);
-		break;
-	}
-	case CRAS_SERVER_GET_HOTWORD_MODELS: {
-		if (!MSG_LEN_VALID(msg, struct cras_get_hotword_models))
-			return -EINVAL;
-		handle_get_hotword_models(
-			client,
-			((const struct cras_get_hotword_models *)msg)->node_id);
-		break;
-	}
-	case CRAS_SERVER_SET_HOTWORD_MODEL: {
-		const struct cras_set_hotword_model *m =
-			(const struct cras_set_hotword_model *)msg;
-		if (!MSG_LEN_VALID(msg, struct cras_set_hotword_model))
-			return -EINVAL;
-		cras_iodev_list_set_hotword_model(m->node_id, m->model_name);
-		break;
-	}
-	case CRAS_SERVER_REGISTER_NOTIFICATION: {
-		const struct cras_register_notification *m =
-			(struct cras_register_notification *)msg;
-		if (!MSG_LEN_VALID(msg, struct cras_register_notification))
-			return -EINVAL;
-		register_for_notification(
-			client, (enum CRAS_CLIENT_MESSAGE_ID)m->msg_id,
-			m->do_register);
-		break;
-	}
-	case CRAS_SERVER_SET_AEC_DUMP: {
-		const struct cras_set_aec_dump *m =
-			(const struct cras_set_aec_dump *)msg;
-		if (!MSG_LEN_VALID(msg, struct cras_set_aec_dump))
-			return -EINVAL;
-		audio_thread_set_aec_dump(cras_iodev_list_get_audio_thread(),
-					  m->stream_id, m->start, fd);
-		break;
-	}
-	case CRAS_SERVER_RELOAD_AEC_CONFIG:
-		cras_apm_list_reload_aec_config();
-		break;
-	default:
-		break;
-	}
-
-	return 0;
-}
-
-/* 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 = rclient_send_message_to_client,
-	.destroy = rclient_destroy,
-};
-
-/*
- * Exported Functions.
- */
-
-/* Creates a client structure and sends a message back informing the client that
- * the conneciton has succeeded. */
-struct cras_rclient *cras_control_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_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();
-	client->ops->send_message_to_client(client, &msg.header, &state_fd, 1);
-
-	return client;
-}
diff --git a/cras/src/server/cras_control_rclient.h b/cras/src/server/cras_control_rclient.h
deleted file mode 100644
index d654df5..0000000
--- a/cras/src/server/cras_control_rclient.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/* 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_CONTROL_RCLIENT_H_
-#define CRAS_CONTROL_RCLIENT_H_
-
-struct cras_rclient;
-
-/* Creates a control 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_control_rclient_create(int fd, size_t id);
-
-#endif /* CRAS_CONTROL_RCLIENT_H_ */
diff --git a/cras/src/server/cras_dbus.c b/cras/src/server/cras_dbus.c
index d127485..27192e8 100644
--- a/cras/src/server/cras_dbus.c
+++ b/cras/src/server/cras_dbus.c
@@ -48,7 +48,8 @@
 	 */
 	if ((flags & DBUS_WATCH_READABLE) && dbus_watch_get_enabled(watch)) {
 		r = cras_system_add_select_fd(dbus_watch_get_unix_fd(watch),
-					      dbus_watch_callback, watch);
+					      dbus_watch_callback,
+					      watch);
 		if (r != 0)
 			return FALSE;
 	}
@@ -74,14 +75,17 @@
 	}
 }
 
+
 static void dbus_timeout_callback(struct cras_timer *t, void *data)
 {
 	struct cras_tm *tm = cras_system_state_get_tm();
 	struct DBusTimeout *timeout = data;
 
+
 	/* Timer is automatically removed after it fires.  Add a new one so this
 	 * fires until it is removed by dbus. */
-	t = cras_tm_create_timer(tm, dbus_timeout_get_interval(timeout),
+	t = cras_tm_create_timer(tm,
+				 dbus_timeout_get_interval(timeout),
 				 dbus_timeout_callback, timeout);
 	dbus_timeout_set_data(timeout, t, NULL);
 
@@ -100,11 +104,13 @@
 	}
 
 	if (dbus_timeout_get_enabled(timeout)) {
-		t = cras_tm_create_timer(tm, dbus_timeout_get_interval(timeout),
+		t = cras_tm_create_timer(tm,
+					 dbus_timeout_get_interval(timeout),
 					 dbus_timeout_callback, timeout);
 		dbus_timeout_set_data(timeout, t, NULL);
 		if (t == NULL)
 			return FALSE;
+
 	}
 
 	return TRUE;
@@ -154,13 +160,19 @@
 	if (rc != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
 		syslog(LOG_ERR, "Not primary owner of dbus name.");
 
-	if (!dbus_connection_set_watch_functions(
-		    conn, dbus_watch_add, dbus_watch_remove, dbus_watch_toggled,
-		    NULL, NULL))
+	if (!dbus_connection_set_watch_functions(conn,
+						 dbus_watch_add,
+						 dbus_watch_remove,
+						 dbus_watch_toggled,
+						 NULL,
+						 NULL))
 		goto error;
-	if (!dbus_connection_set_timeout_functions(
-		    conn, dbus_timeout_add, dbus_timeout_remove,
-		    dbus_timeout_toggled, NULL, NULL))
+	if (!dbus_connection_set_timeout_functions(conn,
+						   dbus_timeout_add,
+						   dbus_timeout_remove,
+						   dbus_timeout_toggled,
+						   NULL,
+						   NULL))
 		goto error;
 
 	return conn;
@@ -173,7 +185,8 @@
 
 void cras_dbus_dispatch(DBusConnection *conn)
 {
-	while (dbus_connection_dispatch(conn) == DBUS_DISPATCH_DATA_REMAINS)
+	while (dbus_connection_dispatch(conn)
+		== DBUS_DISPATCH_DATA_REMAINS)
 		;
 }
 
diff --git a/cras/src/server/cras_dbus_control.c b/cras/src/server/cras_dbus_control.c
index 978c64a..56effce 100644
--- a/cras/src/server/cras_dbus_control.c
+++ b/cras/src/server/cras_dbus_control.c
@@ -22,107 +22,101 @@
 
 #define CRAS_CONTROL_INTERFACE "org.chromium.cras.Control"
 #define CRAS_ROOT_OBJECT_PATH "/org/chromium/cras"
-#define CONTROL_INTROSPECT_XML                                                  \
-	DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE                               \
-	"<node>\n"                                                              \
-	"  <interface name=\"" CRAS_CONTROL_INTERFACE "\">\n"                   \
-	"    <method name=\"SetOutputVolume\">\n"                               \
-	"      <arg name=\"volume\" type=\"i\" direction=\"in\"/>\n"            \
-	"    </method>\n"                                                       \
-	"    <method name=\"SetOutputNodeVolume\">\n"                           \
-	"      <arg name=\"node_id\" type=\"t\" direction=\"in\"/>\n"           \
-	"      <arg name=\"volume\" type=\"i\" direction=\"in\"/>\n"            \
-	"    </method>\n"                                                       \
-	"    <method name=\"SwapLeftRight\">\n"                                 \
-	"      <arg name=\"node_id\" type=\"t\" direction=\"in\"/>\n"           \
-	"      <arg name=\"swap\" type=\"b\" direction=\"in\"/>\n"              \
-	"    </method>\n"                                                       \
-	"    <method name=\"SetOutputMute\">\n"                                 \
-	"      <arg name=\"mute_on\" type=\"b\" direction=\"in\"/>\n"           \
-	"    </method>\n"                                                       \
-	"    <method name=\"SetOutputUserMute\">\n"                             \
-	"      <arg name=\"mute_on\" type=\"b\" direction=\"in\"/>\n"           \
-	"    </method>\n"                                                       \
-	"    <method name=\"SetSuspendAudio\">\n"                               \
-	"      <arg name=\"suspend\" type=\"b\" direction=\"in\"/>\n"           \
-	"    </method>\n"                                                       \
-	"    <method name=\"SetInputGain\">\n"                                  \
-	"      <arg name=\"gain\" type=\"i\" direction=\"in\"/>\n"              \
-	"    </method>\n"                                                       \
-	"    <method name=\"SetInputNodeGain\">\n"                              \
-	"      <arg name=\"node_id\" type=\"t\" direction=\"in\"/>\n"           \
-	"      <arg name=\"gain\" type=\"i\" direction=\"in\"/>\n"              \
-	"    </method>\n"                                                       \
-	"    <method name=\"SetInputMute\">\n"                                  \
-	"      <arg name=\"mute_on\" type=\"b\" direction=\"in\"/>\n"           \
-	"    </method>\n"                                                       \
-	"    <method name=\"GetVolumeState\">\n"                                \
-	"      <arg name=\"output_volume\" type=\"i\" direction=\"out\"/>\n"    \
-	"      <arg name=\"output_mute\" type=\"b\" direction=\"out\"/>\n"      \
-	"      <arg name=\"input_gain\" type=\"i\" direction=\"out\"/>\n"       \
-	"      <arg name=\"input_mute\" type=\"b\" direction=\"out\"/>\n"       \
-	"      <arg name=\"output_user_mute\" type=\"b\" direction=\"out\"/>\n" \
-	"    </method>\n"                                                       \
-	"    <method name=\"GetDefaultOutputBufferSize\">\n"                    \
-	"      <arg name=\"buffer_size\" type=\"i\" direction=\"out\"/>\n"      \
-	"    </method>\n"                                                       \
-	"    <method name=\"GetNodes\">\n"                                      \
-	"      <arg name=\"nodes\" type=\"a{sv}\" direction=\"out\"/>\n"        \
-	"    </method>\n"                                                       \
-	"    <method name=\"GetSystemAecSupported\">\n"                         \
-	"      <arg name=\"supported\" type=\"b\" direction=\"out\"/>\n"        \
-	"    </method>\n"                                                       \
-	"    <method name=\"GetSystemAecGroupId\">\n"                           \
-	"      <arg name=\"group_id\" type=\"i\" direction=\"out\"/>\n"         \
-	"    </method>\n"                                                       \
-	"    <method name=\"SetActiveOutputNode\">\n"                           \
-	"      <arg name=\"node_id\" type=\"t\" direction=\"in\"/>\n"           \
-	"    </method>\n"                                                       \
-	"    <method name=\"SetActiveInputNode\">\n"                            \
-	"      <arg name=\"node_id\" type=\"t\" direction=\"in\"/>\n"           \
-	"    </method>\n"                                                       \
-	"    <method name=\"AddActiveInputNode\">\n"                            \
-	"      <arg name=\"node_id\" type=\"t\" direction=\"in\"/>\n"           \
-	"    </method>\n"                                                       \
-	"    <method name=\"AddActiveOutputNode\">\n"                           \
-	"      <arg name=\"node_id\" type=\"t\" direction=\"in\"/>\n"           \
-	"    </method>\n"                                                       \
-	"    <method name=\"RemoveActiveInputNode\">\n"                         \
-	"      <arg name=\"node_id\" type=\"t\" direction=\"in\"/>\n"           \
-	"    </method>\n"                                                       \
-	"    <method name=\"RemoveActiveOutputNode\">\n"                        \
-	"      <arg name=\"node_id\" type=\"t\" direction=\"in\"/>\n"           \
-	"    </method>\n"                                                       \
-	"    <method name=\"GetNumberOfActiveStreams\">\n"                      \
-	"      <arg name=\"num\" type=\"i\" direction=\"out\"/>\n"              \
-	"    </method>\n"                                                       \
-	"    <method name=\"GetNumberOfActiveOutputStreams\">\n"                \
-	"      <arg name=\"num\" type=\"i\" direction=\"out\"/>\n"              \
-	"    </method>\n"                                                       \
-	"    <method name=\"GetNumberOfActiveInputStreams\">\n"                 \
-	"      <arg name=\"num\" type=\"i\" direction=\"out\"/>\n"              \
-	"    </method>\n"                                                       \
-	"    <method name=\"SetGlobalOutputChannelRemix\">\n"                   \
-	"      <arg name=\"num_channels\" type=\"i\" direction=\"in\"/>\n"      \
-	"      <arg name=\"coefficient\" type=\"ad\" direction=\"in\"/>\n"      \
-	"    </method>\n"                                                       \
-	"    <method name=\"SetHotwordModel\">\n"                               \
-	"      <arg name=\"node_id\" type=\"t\" direction=\"in\"/>\n"           \
-	"      <arg name=\"model_name\" type=\"s\" direction=\"in\"/>\n"        \
-	"    </method>\n"                                                       \
-	"    <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"                                    \
-	"      <arg name=\"data\" type=\"s\" direction=\"out\"/>\n"             \
-	"    </method>\n"                                                       \
-	"  </interface>\n"                                                      \
-	"</node>\n"
+#define CONTROL_INTROSPECT_XML                                          \
+    DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE                           \
+    "<node>\n"                                                          \
+    "  <interface name=\""CRAS_CONTROL_INTERFACE"\">\n"                 \
+    "    <method name=\"SetOutputVolume\">\n"                           \
+    "      <arg name=\"volume\" type=\"i\" direction=\"in\"/>\n"        \
+    "    </method>\n"                                                   \
+    "    <method name=\"SetOutputNodeVolume\">\n"                       \
+    "      <arg name=\"node_id\" type=\"t\" direction=\"in\"/>\n"       \
+    "      <arg name=\"volume\" type=\"i\" direction=\"in\"/>\n"        \
+    "    </method>\n"                                                   \
+    "    <method name=\"SwapLeftRight\">\n"                             \
+    "      <arg name=\"node_id\" type=\"t\" direction=\"in\"/>\n"       \
+    "      <arg name=\"swap\" type=\"b\" direction=\"in\"/>\n"          \
+    "    </method>\n"                                                   \
+    "    <method name=\"SetOutputMute\">\n"                             \
+    "      <arg name=\"mute_on\" type=\"b\" direction=\"in\"/>\n"       \
+    "    </method>\n"                                                   \
+    "    <method name=\"SetOutputUserMute\">\n"                         \
+    "      <arg name=\"mute_on\" type=\"b\" direction=\"in\"/>\n"       \
+    "    </method>\n"                                                   \
+    "    <method name=\"SetSuspendAudio\">\n"                           \
+    "      <arg name=\"suspend\" type=\"b\" direction=\"in\"/>\n"       \
+    "    </method>\n"                                                   \
+    "    <method name=\"SetInputGain\">\n"                              \
+    "      <arg name=\"gain\" type=\"i\" direction=\"in\"/>\n"          \
+    "    </method>\n"                                                   \
+    "    <method name=\"SetInputNodeGain\">\n"                          \
+    "      <arg name=\"node_id\" type=\"t\" direction=\"in\"/>\n"       \
+    "      <arg name=\"gain\" type=\"i\" direction=\"in\"/>\n"          \
+    "    </method>\n"                                                   \
+    "    <method name=\"SetInputMute\">\n"                              \
+    "      <arg name=\"mute_on\" type=\"b\" direction=\"in\"/>\n"       \
+    "    </method>\n"                                                   \
+    "    <method name=\"GetVolumeState\">\n"                            \
+    "      <arg name=\"output_volume\" type=\"i\" direction=\"out\"/>\n"\
+    "      <arg name=\"output_mute\" type=\"b\" direction=\"out\"/>\n"  \
+    "      <arg name=\"input_gain\" type=\"i\" direction=\"out\"/>\n"   \
+    "      <arg name=\"input_mute\" type=\"b\" direction=\"out\"/>\n"   \
+    "      <arg name=\"output_user_mute\" type=\"b\" direction=\"out\"/>\n"\
+    "    </method>\n"                                                   \
+    "    <method name=\"GetDefaultOutputBufferSize\">\n"                    \
+    "      <arg name=\"buffer_size\" type=\"i\" direction=\"out\"/>\n"  \
+    "    </method>\n"                                                   \
+    "    <method name=\"GetNodes\">\n"                                  \
+    "      <arg name=\"nodes\" type=\"a{sv}\" direction=\"out\"/>\n"    \
+    "    </method>\n"                                                   \
+    "    <method name=\"GetSystemAecSupported\">\n"                     \
+    "      <arg name=\"supported\" type=\"b\" direction=\"out\"/>\n"    \
+    "    </method>\n"                                                   \
+    "    <method name=\"SetActiveOutputNode\">\n"                       \
+    "      <arg name=\"node_id\" type=\"t\" direction=\"in\"/>\n"       \
+    "    </method>\n"                                                   \
+    "    <method name=\"SetActiveInputNode\">\n"                        \
+    "      <arg name=\"node_id\" type=\"t\" direction=\"in\"/>\n"       \
+    "    </method>\n"                                                   \
+    "    <method name=\"AddActiveInputNode\">\n"                        \
+    "      <arg name=\"node_id\" type=\"t\" direction=\"in\"/>\n"       \
+    "    </method>\n"                                                   \
+    "    <method name=\"AddActiveOutputNode\">\n"                       \
+    "      <arg name=\"node_id\" type=\"t\" direction=\"in\"/>\n"       \
+    "    </method>\n"                                                   \
+    "    <method name=\"RemoveActiveInputNode\">\n"                     \
+    "      <arg name=\"node_id\" type=\"t\" direction=\"in\"/>\n"       \
+    "    </method>\n"                                                   \
+    "    <method name=\"RemoveActiveOutputNode\">\n"                    \
+    "      <arg name=\"node_id\" type=\"t\" direction=\"in\"/>\n"       \
+    "    </method>\n"                                                   \
+    "    <method name=\"GetNumberOfActiveStreams\">\n"                  \
+    "      <arg name=\"num\" type=\"i\" direction=\"out\"/>\n"          \
+    "    </method>\n"                                                   \
+    "    <method name=\"GetNumberOfActiveOutputStreams\">\n"            \
+    "      <arg name=\"num\" type=\"i\" direction=\"out\"/>\n"          \
+    "    </method>\n"                                                   \
+    "    <method name=\"GetNumberOfActiveInputStreams\">\n"             \
+    "      <arg name=\"num\" type=\"i\" direction=\"out\"/>\n"          \
+    "    </method>\n"                                                   \
+    "    <method name=\"SetGlobalOutputChannelRemix\">\n"               \
+    "      <arg name=\"num_channels\" type=\"i\" direction=\"in\"/>\n"  \
+    "      <arg name=\"coefficient\" type=\"ad\" direction=\"in\"/>\n"  \
+    "    </method>\n"                                                   \
+    "    <method name=\"SetHotwordModel\">\n"                           \
+    "      <arg name=\"node_id\" type=\"t\" direction=\"in\"/>\n"       \
+    "      <arg name=\"model_name\" type=\"s\" direction=\"in\"/>\n"    \
+    "    </method>\n"                                                   \
+    "    <method name=\"IsAudioOutputActive\">\n"                       \
+    "      <arg name=\"active\" type=\"b\" direction=\"out\"/>\n"       \
+    "    </method>\n"                                                   \
+    "  </interface>\n"                                                  \
+    "  <interface name=\"" DBUS_INTERFACE_INTROSPECTABLE "\">\n"        \
+    "    <method name=\"Introspect\">\n"                                \
+    "      <arg name=\"data\" type=\"s\" direction=\"out\"/>\n"         \
+    "    </method>\n"                                                   \
+    "  </interface>\n"                                                  \
+    "</node>\n"
 
 struct cras_dbus_control {
 	DBusConnection *conn;
@@ -137,9 +131,11 @@
 
 	dbus_error_init(&dbus_error);
 
-	if (!dbus_message_get_args(message, &dbus_error, dbus_type, arg,
+	if (!dbus_message_get_args(message, &dbus_error,
+				   dbus_type, arg,
 				   DBUS_TYPE_INVALID)) {
-		syslog(LOG_WARNING, "Bad method received: %s",
+		syslog(LOG_WARNING,
+		       "Bad method received: %s",
 		       dbus_error.message);
 		dbus_error_free(&dbus_error);
 		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
@@ -164,7 +160,8 @@
 }
 
 /* Helper to send an int32 reply. */
-static void send_int32_reply(DBusConnection *conn, DBusMessage *message,
+static void send_int32_reply(DBusConnection *conn,
+			     DBusMessage *message,
 			     dbus_int32_t value)
 {
 	DBusMessage *reply;
@@ -174,7 +171,8 @@
 	if (!reply)
 		return;
 
-	dbus_message_append_args(reply, DBUS_TYPE_INT32, &value,
+	dbus_message_append_args(reply,
+				 DBUS_TYPE_INT32, &value,
 				 DBUS_TYPE_INVALID);
 	dbus_connection_send(conn, reply, &serial);
 
@@ -182,8 +180,10 @@
 }
 
 /* Handlers for exported DBus method calls. */
-static DBusHandlerResult
-handle_set_output_volume(DBusConnection *conn, DBusMessage *message, void *arg)
+static DBusHandlerResult handle_set_output_volume(
+	DBusConnection *conn,
+	DBusMessage *message,
+	void *arg)
 {
 	int rc;
 	dbus_int32_t new_vol;
@@ -199,9 +199,10 @@
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-static DBusHandlerResult handle_set_output_node_volume(DBusConnection *conn,
-						       DBusMessage *message,
-						       void *arg)
+static DBusHandlerResult handle_set_output_node_volume(
+	DBusConnection *conn,
+	DBusMessage *message,
+	void *arg)
 {
 	dbus_int32_t new_vol;
 	cras_node_id_t id;
@@ -209,10 +210,12 @@
 
 	dbus_error_init(&dbus_error);
 
-	if (!dbus_message_get_args(message, &dbus_error, DBUS_TYPE_UINT64, &id,
+	if (!dbus_message_get_args(message, &dbus_error,
+				   DBUS_TYPE_UINT64, &id,
 				   DBUS_TYPE_INT32, &new_vol,
 				   DBUS_TYPE_INVALID)) {
-		syslog(LOG_WARNING, "Bad method received: %s",
+		syslog(LOG_WARNING,
+		       "Bad method received: %s",
 		       dbus_error.message);
 		dbus_error_free(&dbus_error);
 		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
@@ -225,8 +228,10 @@
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-static DBusHandlerResult handle_swap_left_right(DBusConnection *conn,
-						DBusMessage *message, void *arg)
+static DBusHandlerResult handle_swap_left_right(
+	DBusConnection *conn,
+	DBusMessage *message,
+	void *arg)
 {
 	cras_node_id_t id;
 	dbus_bool_t swap;
@@ -234,24 +239,29 @@
 
 	dbus_error_init(&dbus_error);
 
-	if (!dbus_message_get_args(message, &dbus_error, DBUS_TYPE_UINT64, &id,
+	if (!dbus_message_get_args(message, &dbus_error,
+				   DBUS_TYPE_UINT64, &id,
 				   DBUS_TYPE_BOOLEAN, &swap,
 				   DBUS_TYPE_INVALID)) {
-		syslog(LOG_WARNING, "Bad method received: %s",
+		syslog(LOG_WARNING,
+		       "Bad method received: %s",
 		       dbus_error.message);
 		dbus_error_free(&dbus_error);
 		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 	}
 
-	cras_iodev_list_set_node_attr(id, IONODE_ATTR_SWAP_LEFT_RIGHT, swap);
+	cras_iodev_list_set_node_attr(id, IONODE_ATTR_SWAP_LEFT_RIGHT,
+				      swap);
 
 	send_empty_reply(conn, message);
 
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-static DBusHandlerResult handle_set_output_mute(DBusConnection *conn,
-						DBusMessage *message, void *arg)
+static DBusHandlerResult handle_set_output_mute(
+	DBusConnection *conn,
+	DBusMessage *message,
+	void *arg)
 {
 	int rc;
 	dbus_bool_t new_mute;
@@ -267,9 +277,10 @@
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-static DBusHandlerResult handle_set_output_user_mute(DBusConnection *conn,
-						     DBusMessage *message,
-						     void *arg)
+static DBusHandlerResult handle_set_output_user_mute(
+	DBusConnection *conn,
+	DBusMessage *message,
+	void *arg)
 {
 	int rc;
 	dbus_bool_t new_mute;
@@ -285,8 +296,10 @@
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-static DBusHandlerResult
-handle_set_suspend_audio(DBusConnection *conn, DBusMessage *message, void *arg)
+static DBusHandlerResult handle_set_suspend_audio(
+	DBusConnection *conn,
+	DBusMessage *message,
+	void *arg)
 {
 	int rc;
 	dbus_bool_t suspend;
@@ -301,8 +314,10 @@
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-static DBusHandlerResult handle_set_input_gain(DBusConnection *conn,
-					       DBusMessage *message, void *arg)
+static DBusHandlerResult handle_set_input_gain(
+	DBusConnection *conn,
+	DBusMessage *message,
+	void *arg)
 {
 	int rc;
 	dbus_int32_t new_gain;
@@ -318,9 +333,10 @@
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-static DBusHandlerResult handle_set_input_node_gain(DBusConnection *conn,
-						    DBusMessage *message,
-						    void *arg)
+static DBusHandlerResult handle_set_input_node_gain(
+	DBusConnection *conn,
+	DBusMessage *message,
+	void *arg)
 {
 	dbus_int32_t new_gain;
 	cras_node_id_t id;
@@ -328,10 +344,12 @@
 
 	dbus_error_init(&dbus_error);
 
-	if (!dbus_message_get_args(message, &dbus_error, DBUS_TYPE_UINT64, &id,
+	if (!dbus_message_get_args(message, &dbus_error,
+				   DBUS_TYPE_UINT64, &id,
 				   DBUS_TYPE_INT32, &new_gain,
 				   DBUS_TYPE_INVALID)) {
-		syslog(LOG_WARNING, "Bad method received: %s",
+		syslog(LOG_WARNING,
+		       "Bad method received: %s",
 		       dbus_error.message);
 		dbus_error_free(&dbus_error);
 		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
@@ -344,8 +362,10 @@
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-static DBusHandlerResult handle_set_input_mute(DBusConnection *conn,
-					       DBusMessage *message, void *arg)
+static DBusHandlerResult handle_set_input_mute(
+	DBusConnection *conn,
+	DBusMessage *message,
+	void *arg)
 {
 	int rc;
 	dbus_bool_t new_mute;
@@ -361,8 +381,10 @@
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-static DBusHandlerResult
-handle_get_volume_state(DBusConnection *conn, DBusMessage *message, void *arg)
+static DBusHandlerResult handle_get_volume_state(
+	DBusConnection *conn,
+	DBusMessage *message,
+	void *arg)
 {
 	DBusMessage *reply;
 	dbus_uint32_t serial = 0;
@@ -380,7 +402,8 @@
 	capture_gain = cras_system_get_capture_gain();
 	capture_muted = cras_system_get_capture_mute();
 
-	dbus_message_append_args(reply, DBUS_TYPE_INT32, &volume,
+	dbus_message_append_args(reply,
+				 DBUS_TYPE_INT32, &volume,
 				 DBUS_TYPE_BOOLEAN, &system_muted,
 				 DBUS_TYPE_INT32, &capture_gain,
 				 DBUS_TYPE_BOOLEAN, &capture_muted,
@@ -394,9 +417,10 @@
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-static DBusHandlerResult
-handle_get_default_output_buffer_size(DBusConnection *conn,
-				      DBusMessage *message, void *arg)
+static DBusHandlerResult handle_get_default_output_buffer_size(
+	DBusConnection *conn,
+	DBusMessage *message,
+	void *arg)
 {
 	DBusMessage *reply;
 	dbus_uint32_t serial = 0;
@@ -405,7 +429,8 @@
 	reply = dbus_message_new_method_return(message);
 
 	buffer_size = cras_system_get_default_output_buffer_size();
-	dbus_message_append_args(reply, DBUS_TYPE_INT32, &buffer_size,
+	dbus_message_append_args(reply,
+				 DBUS_TYPE_INT32, &buffer_size,
 				 DBUS_TYPE_INVALID);
 
 	dbus_connection_send(conn, reply, &serial);
@@ -427,12 +452,13 @@
 	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;
 	dbus_bool_t active;
 	dbus_uint64_t plugged_time = node->plugged_time.tv_sec * 1000000ULL +
-				     node->plugged_time.tv_usec;
+		node->plugged_time.tv_usec;
 	dbus_uint64_t node_volume = node->volume;
 	dbus_int64_t node_capture_gain = node->capture_gain;
 	char *models, *empty_models = "";
@@ -454,13 +480,12 @@
 	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;
@@ -535,7 +560,8 @@
 }
 
 static DBusHandlerResult handle_get_nodes(DBusConnection *conn,
-					  DBusMessage *message, void *arg)
+					  DBusMessage *message,
+					  void *arg)
 {
 	DBusMessage *reply;
 	DBusMessageIter array;
@@ -553,9 +579,10 @@
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-static DBusHandlerResult handle_get_system_aec_supported(DBusConnection *conn,
-							 DBusMessage *message,
-							 void *arg)
+static DBusHandlerResult handle_get_system_aec_supported(
+	DBusConnection *conn,
+	DBusMessage *message,
+	void *arg)
 {
 	DBusMessage *reply;
 	dbus_uint32_t serial = 0;
@@ -564,28 +591,8 @@
 	reply = dbus_message_new_method_return(message);
 
 	system_aec_supported = cras_system_get_aec_supported();
-	dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN,
-				 &system_aec_supported, DBUS_TYPE_INVALID);
-
-	dbus_connection_send(conn, reply, &serial);
-
-	dbus_message_unref(reply);
-
-	return DBUS_HANDLER_RESULT_HANDLED;
-}
-
-static DBusHandlerResult handle_get_system_aec_group_id(DBusConnection *conn,
-							DBusMessage *message,
-							void *arg)
-{
-	DBusMessage *reply;
-	dbus_uint32_t serial = 0;
-	dbus_int32_t system_aec_group_id;
-
-	reply = dbus_message_new_method_return(message);
-
-	system_aec_group_id = cras_system_get_aec_group_id();
-	dbus_message_append_args(reply, DBUS_TYPE_INT32, &system_aec_group_id,
+	dbus_message_append_args(reply,
+				 DBUS_TYPE_BOOLEAN, &system_aec_supported,
 				 DBUS_TYPE_INVALID);
 
 	dbus_connection_send(conn, reply, &serial);
@@ -596,7 +603,9 @@
 }
 
 static DBusHandlerResult
-handle_set_active_node(DBusConnection *conn, DBusMessage *message, void *arg,
+handle_set_active_node(DBusConnection *conn,
+		       DBusMessage *message,
+		       void *arg,
 		       enum CRAS_STREAM_DIRECTION direction)
 {
 	int rc;
@@ -614,8 +623,10 @@
 }
 
 static DBusHandlerResult
-handle_add_active_node(DBusConnection *conn, DBusMessage *message, void *arg,
-		       enum CRAS_STREAM_DIRECTION direction)
+handle_add_active_node(DBusConnection *conn,
+		       DBusMessage *message,
+		       void *arg,
+                       enum CRAS_STREAM_DIRECTION direction)
 {
 	int rc;
 	cras_node_id_t id;
@@ -632,68 +643,72 @@
 }
 
 static DBusHandlerResult
-handle_rm_active_node(DBusConnection *conn, DBusMessage *message, void *arg,
-		      enum CRAS_STREAM_DIRECTION direction)
+handle_rm_active_node(DBusConnection *conn,
+                      DBusMessage *message,
+                      void *arg,
+                      enum CRAS_STREAM_DIRECTION direction)
 {
-	int rc;
-	cras_node_id_t id;
+        int rc;
+        cras_node_id_t id;
 
-	rc = get_single_arg(message, DBUS_TYPE_UINT64, &id);
-	if (rc)
-		return rc;
+        rc = get_single_arg(message, DBUS_TYPE_UINT64, &id);
+        if (rc)
+                return rc;
 
-	cras_iodev_list_rm_active_node(direction, id);
+        cras_iodev_list_rm_active_node(direction, id);
 
-	send_empty_reply(conn, message);
+        send_empty_reply(conn, message);
 
-	return DBUS_HANDLER_RESULT_HANDLED;
+        return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-static DBusHandlerResult handle_get_num_active_streams(DBusConnection *conn,
-						       DBusMessage *message,
-						       void *arg)
+static DBusHandlerResult handle_get_num_active_streams(
+	DBusConnection *conn,
+	DBusMessage *message,
+	void *arg)
 {
 	send_int32_reply(conn, message, cras_system_state_get_active_streams());
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-static DBusHandlerResult
-handle_get_num_active_streams_use_input_hw(DBusConnection *conn,
-					   DBusMessage *message, void *arg)
+static DBusHandlerResult handle_get_num_active_streams_use_input_hw(
+	DBusConnection *conn,
+	DBusMessage *message,
+	void *arg)
 {
 	dbus_int32_t num = 0;
 	unsigned i;
 
 	for (i = 0; i < CRAS_NUM_DIRECTIONS; i++) {
 		if (cras_stream_uses_input_hw(i))
-			num += cras_system_state_get_active_streams_by_direction(
-				i);
+			num += cras_system_state_get_active_streams_by_direction(i);
 	}
 	send_int32_reply(conn, message, num);
 
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-static DBusHandlerResult
-handle_get_num_active_streams_use_output_hw(DBusConnection *conn,
-					    DBusMessage *message, void *arg)
+static DBusHandlerResult handle_get_num_active_streams_use_output_hw(
+	DBusConnection *conn,
+	DBusMessage *message,
+	void *arg)
 {
 	dbus_int32_t num = 0;
 	unsigned i;
 
 	for (i = 0; i < CRAS_NUM_DIRECTIONS; i++) {
 		if (cras_stream_uses_output_hw(i))
-			num += cras_system_state_get_active_streams_by_direction(
-				i);
+			num += cras_system_state_get_active_streams_by_direction(i);
 	}
 	send_int32_reply(conn, message, num);
 
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-static DBusHandlerResult
-handle_set_global_output_channel_remix(DBusConnection *conn,
-				       DBusMessage *message, void *arg)
+static DBusHandlerResult handle_set_global_output_channel_remix(
+	DBusConnection *conn,
+	DBusMessage *message,
+	void *arg)
 {
 	dbus_int32_t num_channels;
 	double *coeff_array;
@@ -704,12 +719,13 @@
 
 	dbus_error_init(&dbus_error);
 
-	if (!dbus_message_get_args(message, &dbus_error, DBUS_TYPE_INT32,
-				   &num_channels, DBUS_TYPE_ARRAY,
-				   DBUS_TYPE_DOUBLE, &coeff_array, &count,
-				   DBUS_TYPE_INVALID)) {
+	if (!dbus_message_get_args(message, &dbus_error,
+			DBUS_TYPE_INT32, &num_channels,
+			DBUS_TYPE_ARRAY,
+			      DBUS_TYPE_DOUBLE, &coeff_array, &count,
+			      DBUS_TYPE_INVALID)) {
 		syslog(LOG_WARNING, "Set global output channel remix error: %s",
-		       dbus_error.message);
+			dbus_error.message);
 		dbus_error_free(&dbus_error);
 		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 	}
@@ -721,16 +737,20 @@
 	for (i = 0; i < count; i++)
 		coefficient[i] = coeff_array[i];
 
-	audio_thread_config_global_remix(cras_iodev_list_get_audio_thread(),
-					 num_channels, coefficient);
+	audio_thread_config_global_remix(
+			cras_iodev_list_get_audio_thread(),
+			num_channels,
+			coefficient);
 
 	send_empty_reply(conn, message);
 	free(coefficient);
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-static DBusHandlerResult
-handle_set_hotword_model(DBusConnection *conn, DBusMessage *message, void *arg)
+static DBusHandlerResult handle_set_hotword_model(
+	DBusConnection *conn,
+	DBusMessage *message,
+	void *arg)
 {
 	cras_node_id_t id;
 	const char *model_name;
@@ -739,10 +759,12 @@
 
 	dbus_error_init(&dbus_error);
 
-	if (!dbus_message_get_args(message, &dbus_error, DBUS_TYPE_UINT64, &id,
+	if (!dbus_message_get_args(message, &dbus_error,
+				   DBUS_TYPE_UINT64, &id,
 				   DBUS_TYPE_STRING, &model_name,
 				   DBUS_TYPE_INVALID)) {
-		syslog(LOG_WARNING, "Bad method received: %s",
+		syslog(LOG_WARNING,
+		       "Bad method received: %s",
 		       dbus_error.message);
 		dbus_error_free(&dbus_error);
 		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
@@ -754,8 +776,10 @@
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-static DBusHandlerResult handle_is_audio_active(DBusConnection *conn,
-						DBusMessage *message, void *arg)
+static DBusHandlerResult handle_is_audio_active(
+		DBusConnection *conn,
+		DBusMessage *message,
+		void* arg)
 {
 	dbus_int32_t active = cras_system_state_get_non_empty_status();
 
@@ -764,33 +788,18 @@
 	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)
+						DBusMessage *message,
+						void *arg)
 {
 	syslog(LOG_DEBUG, "Control message: %s %s %s",
 	       dbus_message_get_path(message),
 	       dbus_message_get_interface(message),
 	       dbus_message_get_member(message));
 
-	if (dbus_message_is_method_call(message, DBUS_INTERFACE_INTROSPECTABLE,
+	if (dbus_message_is_method_call(message,
+					DBUS_INTERFACE_INTROSPECTABLE,
 					"Introspect")) {
 		DBusMessage *reply;
 		const char *xml = CONTROL_INTROSPECT_XML;
@@ -798,7 +807,8 @@
 		reply = dbus_message_new_method_return(message);
 		if (!reply)
 			return DBUS_HANDLER_RESULT_NEED_MEMORY;
-		if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &xml,
+		if (!dbus_message_append_args(reply,
+					      DBUS_TYPE_STRING, &xml,
 					      DBUS_TYPE_INVALID))
 			return DBUS_HANDLER_RESULT_NEED_MEMORY;
 		if (!dbus_connection_send(conn, reply, NULL))
@@ -807,99 +817,115 @@
 		dbus_message_unref(reply);
 		return DBUS_HANDLER_RESULT_HANDLED;
 
-	} else if (dbus_message_is_method_call(message, CRAS_CONTROL_INTERFACE,
+	} else if (dbus_message_is_method_call(message,
+					       CRAS_CONTROL_INTERFACE,
 					       "SetOutputVolume")) {
 		return handle_set_output_volume(conn, message, arg);
-	} else if (dbus_message_is_method_call(message, CRAS_CONTROL_INTERFACE,
+	} else if (dbus_message_is_method_call(message,
+					       CRAS_CONTROL_INTERFACE,
 					       "SetOutputNodeVolume")) {
 		return handle_set_output_node_volume(conn, message, arg);
-	} else if (dbus_message_is_method_call(message, CRAS_CONTROL_INTERFACE,
+	} else if (dbus_message_is_method_call(message,
+					       CRAS_CONTROL_INTERFACE,
 					       "SwapLeftRight")) {
 		return handle_swap_left_right(conn, message, arg);
-	} else if (dbus_message_is_method_call(message, CRAS_CONTROL_INTERFACE,
+	} else if (dbus_message_is_method_call(message,
+					       CRAS_CONTROL_INTERFACE,
 					       "SetOutputMute")) {
 		return handle_set_output_mute(conn, message, arg);
-	} else if (dbus_message_is_method_call(message, CRAS_CONTROL_INTERFACE,
+	} else if (dbus_message_is_method_call(message,
+					       CRAS_CONTROL_INTERFACE,
 					       "SetOutputUserMute")) {
 		return handle_set_output_user_mute(conn, message, arg);
-	} else if (dbus_message_is_method_call(message, CRAS_CONTROL_INTERFACE,
+	} else if (dbus_message_is_method_call(message,
+					       CRAS_CONTROL_INTERFACE,
 					       "SetSuspendAudio")) {
 		return handle_set_suspend_audio(conn, message, arg);
-	} else if (dbus_message_is_method_call(message, CRAS_CONTROL_INTERFACE,
+	} else if (dbus_message_is_method_call(message,
+					       CRAS_CONTROL_INTERFACE,
 					       "SetInputGain")) {
 		return handle_set_input_gain(conn, message, arg);
-	} else if (dbus_message_is_method_call(message, CRAS_CONTROL_INTERFACE,
+	} else if (dbus_message_is_method_call(message,
+					       CRAS_CONTROL_INTERFACE,
 					       "SetInputNodeGain")) {
 		return handle_set_input_node_gain(conn, message, arg);
-	} else if (dbus_message_is_method_call(message, CRAS_CONTROL_INTERFACE,
+	} else if (dbus_message_is_method_call(message,
+					       CRAS_CONTROL_INTERFACE,
 					       "SetInputMute")) {
 		return handle_set_input_mute(conn, message, arg);
-	} else if (dbus_message_is_method_call(message, CRAS_CONTROL_INTERFACE,
+	} else if (dbus_message_is_method_call(message,
+					       CRAS_CONTROL_INTERFACE,
 					       "GetVolumeState")) {
 		return handle_get_volume_state(conn, message, arg);
-	} else if (dbus_message_is_method_call(message, CRAS_CONTROL_INTERFACE,
+	} else if (dbus_message_is_method_call(message,
+					       CRAS_CONTROL_INTERFACE,
 					       "GetDefaultOutputBufferSize")) {
-		return handle_get_default_output_buffer_size(conn, message,
-							     arg);
-	} else if (dbus_message_is_method_call(message, CRAS_CONTROL_INTERFACE,
+		return handle_get_default_output_buffer_size(conn, message, arg);
+	} else if (dbus_message_is_method_call(message,
+					       CRAS_CONTROL_INTERFACE,
 					       "GetNodes")) {
 		return handle_get_nodes(conn, message, arg);
-	} else if (dbus_message_is_method_call(message, CRAS_CONTROL_INTERFACE,
+	} else if (dbus_message_is_method_call(message,
+					       CRAS_CONTROL_INTERFACE,
 					       "GetSystemAecSupported")) {
 		return handle_get_system_aec_supported(conn, message, arg);
-	} else if (dbus_message_is_method_call(message, CRAS_CONTROL_INTERFACE,
-					       "GetSystemAecGroupId")) {
-		return handle_get_system_aec_group_id(conn, message, arg);
-	} else if (dbus_message_is_method_call(message, CRAS_CONTROL_INTERFACE,
+	} else if (dbus_message_is_method_call(message,
+					       CRAS_CONTROL_INTERFACE,
 					       "SetActiveOutputNode")) {
 		return handle_set_active_node(conn, message, arg,
 					      CRAS_STREAM_OUTPUT);
-	} else if (dbus_message_is_method_call(message, CRAS_CONTROL_INTERFACE,
+	} else if (dbus_message_is_method_call(message,
+					       CRAS_CONTROL_INTERFACE,
 					       "SetActiveInputNode")) {
 		return handle_set_active_node(conn, message, arg,
 					      CRAS_STREAM_INPUT);
-	} else if (dbus_message_is_method_call(message, CRAS_CONTROL_INTERFACE,
+	} else if (dbus_message_is_method_call(message,
+					       CRAS_CONTROL_INTERFACE,
 					       "AddActiveInputNode")) {
 		return handle_add_active_node(conn, message, arg,
-					      CRAS_STREAM_INPUT);
-	} else if (dbus_message_is_method_call(message, CRAS_CONTROL_INTERFACE,
-					       "AddActiveOutputNode")) {
-		return handle_add_active_node(conn, message, arg,
-					      CRAS_STREAM_OUTPUT);
-	} else if (dbus_message_is_method_call(message, CRAS_CONTROL_INTERFACE,
-					       "RemoveActiveInputNode")) {
-		return handle_rm_active_node(conn, message, arg,
-					     CRAS_STREAM_INPUT);
-	} else if (dbus_message_is_method_call(message, CRAS_CONTROL_INTERFACE,
-					       "RemoveActiveOutputNode")) {
-		return handle_rm_active_node(conn, message, arg,
-					     CRAS_STREAM_OUTPUT);
-	} else if (dbus_message_is_method_call(message, CRAS_CONTROL_INTERFACE,
+                                              CRAS_STREAM_INPUT);
+        } else if (dbus_message_is_method_call(message,
+                                               CRAS_CONTROL_INTERFACE,
+                                               "AddActiveOutputNode")) {
+                return handle_add_active_node(conn, message, arg,
+                                              CRAS_STREAM_OUTPUT);
+        } else if (dbus_message_is_method_call(message,
+                                               CRAS_CONTROL_INTERFACE,
+                                               "RemoveActiveInputNode")) {
+                return handle_rm_active_node(conn, message, arg,
+                                             CRAS_STREAM_INPUT);
+        } else if (dbus_message_is_method_call(message,
+                                               CRAS_CONTROL_INTERFACE,
+                                               "RemoveActiveOutputNode")) {
+                return handle_rm_active_node(conn, message, arg,
+                                             CRAS_STREAM_OUTPUT);
+	} else if (dbus_message_is_method_call(message,
+					       CRAS_CONTROL_INTERFACE,
 					       "GetNumberOfActiveStreams")) {
 		return handle_get_num_active_streams(conn, message, arg);
-	} else if (dbus_message_is_method_call(
-			   message, CRAS_CONTROL_INTERFACE,
-			   "GetNumberOfActiveInputStreams")) {
-		return handle_get_num_active_streams_use_input_hw(conn, message,
-								  arg);
-	} else if (dbus_message_is_method_call(
-			   message, CRAS_CONTROL_INTERFACE,
-			   "GetNumberOfActiveOutputStreams")) {
+	} else if (dbus_message_is_method_call(message,
+						   CRAS_CONTROL_INTERFACE,
+						   "GetNumberOfActiveInputStreams")) {
+		return handle_get_num_active_streams_use_input_hw(
+				conn, message, arg);
+	} else if (dbus_message_is_method_call(message,
+						   CRAS_CONTROL_INTERFACE,
+						   "GetNumberOfActiveOutputStreams")) {
 		return handle_get_num_active_streams_use_output_hw(
-			conn, message, arg);
-	} else if (dbus_message_is_method_call(message, CRAS_CONTROL_INTERFACE,
+				conn, message, arg);
+	} else if (dbus_message_is_method_call(message,
+					       CRAS_CONTROL_INTERFACE,
 					       "SetGlobalOutputChannelRemix")) {
-		return handle_set_global_output_channel_remix(conn, message,
-							      arg);
-	} else if (dbus_message_is_method_call(message, CRAS_CONTROL_INTERFACE,
+		return handle_set_global_output_channel_remix(
+				conn, message, arg);
+	} else if (dbus_message_is_method_call(message,
+					       CRAS_CONTROL_INTERFACE,
 					       "SetHotwordModel")) {
 		return handle_set_hotword_model(conn, message, arg);
-	} else if (dbus_message_is_method_call(message, CRAS_CONTROL_INTERFACE,
+	} 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;
@@ -910,7 +936,8 @@
 {
 	DBusMessage *msg;
 	msg = dbus_message_new_signal(CRAS_ROOT_OBJECT_PATH,
-				      CRAS_CONTROL_INTERFACE, name);
+				      CRAS_CONTROL_INTERFACE,
+				      name);
 	if (!msg)
 		syslog(LOG_ERR, "Failed to create signal");
 
@@ -930,7 +957,8 @@
 		return;
 
 	volume = cras_system_get_volume();
-	dbus_message_append_args(msg, DBUS_TYPE_INT32, &volume,
+	dbus_message_append_args(msg,
+				 DBUS_TYPE_INT32, &volume,
 				 DBUS_TYPE_INVALID);
 	dbus_connection_send(control->conn, msg, &serial);
 	dbus_message_unref(msg);
@@ -949,7 +977,8 @@
 
 	muted = cras_system_get_system_mute();
 	user_muted = cras_system_get_user_mute();
-	dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &muted,
+	dbus_message_append_args(msg,
+				 DBUS_TYPE_BOOLEAN, &muted,
 				 DBUS_TYPE_BOOLEAN, &user_muted,
 				 DBUS_TYPE_INVALID);
 	dbus_connection_send(control->conn, msg, &serial);
@@ -966,7 +995,8 @@
 	if (!msg)
 		return;
 
-	dbus_message_append_args(msg, DBUS_TYPE_INT32, &gain,
+	dbus_message_append_args(msg,
+				 DBUS_TYPE_INT32, &gain,
 				 DBUS_TYPE_INVALID);
 	dbus_connection_send(control->conn, msg, &serial);
 	dbus_message_unref(msg);
@@ -982,7 +1012,8 @@
 	if (!msg)
 		return;
 
-	dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &muted,
+	dbus_message_append_args(msg,
+				 DBUS_TYPE_BOOLEAN, &muted,
 				 DBUS_TYPE_INVALID);
 	dbus_connection_send(control->conn, msg, &serial);
 	dbus_message_unref(msg);
@@ -1010,19 +1041,21 @@
 	DBusMessage *msg;
 	dbus_uint32_t serial = 0;
 
-	msg = create_dbus_message((dir == CRAS_STREAM_OUTPUT) ?
-					  "ActiveOutputNodeChanged" :
-					  "ActiveInputNodeChanged");
+	msg = create_dbus_message((dir == CRAS_STREAM_OUTPUT)
+			? "ActiveOutputNodeChanged"
+			: "ActiveInputNodeChanged");
 	if (!msg)
 		return;
-	dbus_message_append_args(msg, DBUS_TYPE_UINT64, &node_id,
+	dbus_message_append_args(msg,
+				 DBUS_TYPE_UINT64, &node_id,
 				 DBUS_TYPE_INVALID);
 	dbus_connection_send(control->conn, msg, &serial);
 	dbus_message_unref(msg);
 }
 
 /* Called by iodev_list when a node volume changes. */
-static void signal_node_volume_changed(void *context, cras_node_id_t node_id,
+static void signal_node_volume_changed(void *context,
+				       cras_node_id_t node_id,
 				       int32_t volume)
 {
 	struct cras_dbus_control *control = (struct cras_dbus_control *)context;
@@ -1033,8 +1066,10 @@
 	if (!msg)
 		return;
 
-	dbus_message_append_args(msg, DBUS_TYPE_UINT64, &node_id,
-				 DBUS_TYPE_INT32, &volume, DBUS_TYPE_INVALID);
+	dbus_message_append_args(msg,
+				 DBUS_TYPE_UINT64, &node_id,
+				 DBUS_TYPE_INT32, &volume,
+				 DBUS_TYPE_INVALID);
 	dbus_connection_send(control->conn, msg, &serial);
 	dbus_message_unref(msg);
 }
@@ -1051,7 +1086,8 @@
 	if (!msg)
 		return;
 
-	dbus_message_append_args(msg, DBUS_TYPE_UINT64, &node_id,
+	dbus_message_append_args(msg,
+				 DBUS_TYPE_UINT64, &node_id,
 				 DBUS_TYPE_INT32, &capture_gain,
 				 DBUS_TYPE_INVALID);
 	dbus_connection_send(control->conn, msg, &serial);
@@ -1070,7 +1106,8 @@
 	if (!msg)
 		return;
 
-	dbus_message_append_args(msg, DBUS_TYPE_UINT64, &node_id,
+	dbus_message_append_args(msg,
+				 DBUS_TYPE_UINT64, &node_id,
 				 DBUS_TYPE_BOOLEAN, &swapped,
 				 DBUS_TYPE_INVALID);
 	dbus_connection_send(control->conn, msg, &serial);
@@ -1091,12 +1128,15 @@
 		return;
 
 	num = cras_system_state_get_active_streams();
-	dbus_message_append_args(msg, DBUS_TYPE_INT32, &num, DBUS_TYPE_INVALID);
+	dbus_message_append_args(msg,
+				 DBUS_TYPE_INT32, &num,
+				 DBUS_TYPE_INVALID);
 	dbus_connection_send(control->conn, msg, &serial);
 	dbus_message_unref(msg);
 }
 
-static void signal_hotword_triggered(void *context, int64_t tv_sec,
+static void signal_hotword_triggered(void *context,
+				     int64_t tv_sec,
 				     int64_t tv_nsec)
 {
 	struct cras_dbus_control *control = (struct cras_dbus_control *)context;
@@ -1107,8 +1147,10 @@
 	if (!msg)
 		return;
 
-	dbus_message_append_args(msg, DBUS_TYPE_INT64, &tv_sec, DBUS_TYPE_INT64,
-				 &tv_nsec, DBUS_TYPE_INVALID);
+	dbus_message_append_args(msg,
+				 DBUS_TYPE_INT64, &tv_sec,
+				 DBUS_TYPE_INT64, &tv_nsec,
+				 DBUS_TYPE_INVALID);
 	dbus_connection_send(control->conn, msg, &serial);
 	dbus_message_unref(msg);
 }
@@ -1124,7 +1166,8 @@
 	if (!msg)
 		return;
 
-	dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &non_empty,
+	dbus_message_append_args(msg,
+				 DBUS_TYPE_BOOLEAN, &non_empty,
 				 DBUS_TYPE_INVALID);
 
 	dbus_connection_send(control->conn, msg, &serial);
@@ -1145,10 +1188,12 @@
 	dbus_control.conn = conn;
 	dbus_connection_ref(dbus_control.conn);
 
-	if (!dbus_connection_register_object_path(conn, CRAS_ROOT_OBJECT_PATH,
+	if (!dbus_connection_register_object_path(conn,
+						  CRAS_ROOT_OBJECT_PATH,
 						  &control_vtable,
 						  &dbus_error)) {
-		syslog(LOG_WARNING, "Couldn't register CRAS control: %s: %s",
+		syslog(LOG_WARNING,
+		       "Couldn't register CRAS control: %s: %s",
 		       CRAS_ROOT_OBJECT_PATH, dbus_error.message);
 		dbus_error_free(&dbus_error);
 		return;
@@ -1160,16 +1205,16 @@
 	observer_ops.capture_gain_changed = signal_capture_gain;
 	observer_ops.capture_mute_changed = signal_capture_mute;
 	observer_ops.num_active_streams_changed =
-		signal_num_active_streams_changed;
+			signal_num_active_streams_changed;
 	observer_ops.nodes_changed = signal_nodes_changed;
 	observer_ops.active_node_changed = signal_active_node_changed;
 	observer_ops.input_node_gain_changed = signal_node_capture_gain_changed;
 	observer_ops.output_node_volume_changed = signal_node_volume_changed;
 	observer_ops.node_left_right_swapped_changed =
-		signal_node_left_right_swapped_changed;
+			signal_node_left_right_swapped_changed;
 	observer_ops.hotword_triggered = signal_hotword_triggered;
 	observer_ops.non_empty_audio_state_changed =
-		signal_non_empty_audio_state_changed;
+			signal_non_empty_audio_state_changed;
 
 	dbus_control.observer = cras_observer_add(&observer_ops, &dbus_control);
 }
diff --git a/cras/src/server/cras_dbus_util.c b/cras/src/server/cras_dbus_util.c
index 79e4834..b204279 100644
--- a/cras/src/server/cras_dbus_util.c
+++ b/cras/src/server/cras_dbus_util.c
@@ -5,25 +5,26 @@
 
 #include "cras_dbus_util.h"
 
-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)
 {
-	DBusMessageIter entry, variant;
+       DBusMessageIter entry, variant;
 
-	if (!dbus_message_iter_open_container(iter, DBUS_TYPE_DICT_ENTRY, NULL,
-					      &entry))
-		return FALSE;
-	if (!dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key))
-		return FALSE;
-	if (!dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
-					      type_string, &variant))
-		return FALSE;
-	if (!dbus_message_iter_append_basic(&variant, type, value))
-		return FALSE;
-	if (!dbus_message_iter_close_container(&entry, &variant))
-		return FALSE;
-	if (!dbus_message_iter_close_container(iter, &entry))
-		return FALSE;
+       if (!dbus_message_iter_open_container(iter, DBUS_TYPE_DICT_ENTRY, NULL,
+                                             &entry))
+               return FALSE;
+       if (!dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key))
+               return FALSE;
+       if (!dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
+                                             type_string, &variant))
+               return FALSE;
+       if (!dbus_message_iter_append_basic(&variant, type, value))
+               return FALSE;
+       if (!dbus_message_iter_close_container(&entry, &variant))
+               return FALSE;
+       if (!dbus_message_iter_close_container(iter, &entry))
+               return FALSE;
 
-	return TRUE;
+       return TRUE;
 }
diff --git a/cras/src/server/cras_dbus_util.h b/cras/src/server/cras_dbus_util.h
index 94d5320..6e9215a 100644
--- a/cras/src/server/cras_dbus_util.h
+++ b/cras/src/server/cras_dbus_util.h
@@ -5,6 +5,7 @@
 
 #include <dbus/dbus.h>
 
+
 /* Appends a key-value pair to the dbus message.
  * Args:
  *    key - the key (a string)
@@ -14,5 +15,6 @@
  * Returns:
  *    false if not enough memory.
 */
-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);
diff --git a/cras/src/server/cras_device_monitor.c b/cras/src/server/cras_device_monitor.c
index 7dd0f5d..7dd8f27 100644
--- a/cras/src/server/cras_device_monitor.c
+++ b/cras/src/server/cras_device_monitor.c
@@ -18,26 +18,27 @@
 struct cras_device_monitor_message {
 	struct cras_main_message header;
 	enum CRAS_DEVICE_MONITOR_MSG_TYPE message_type;
-	unsigned int dev_idx;
+	struct cras_iodev *iodev;
 };
 
-static void init_device_msg(struct cras_device_monitor_message *msg,
-			    enum CRAS_DEVICE_MONITOR_MSG_TYPE type,
-			    unsigned int dev_idx)
+static void init_device_msg(
+		struct cras_device_monitor_message *msg,
+		enum CRAS_DEVICE_MONITOR_MSG_TYPE type,
+		struct cras_iodev *iodev)
 {
 	memset(msg, 0, sizeof(*msg));
 	msg->header.type = CRAS_MAIN_MONITOR_DEVICE;
 	msg->header.length = sizeof(*msg);
 	msg->message_type = type;
-	msg->dev_idx = dev_idx;
+	msg->iodev = iodev;
 }
 
-int cras_device_monitor_reset_device(unsigned int dev_idx)
+int cras_device_monitor_reset_device(struct cras_iodev *iodev)
 {
 	struct cras_device_monitor_message msg;
 	int err;
 
-	init_device_msg(&msg, RESET_DEVICE, dev_idx);
+	init_device_msg(&msg, RESET_DEVICE, iodev);
 	err = cras_main_message_send((struct cras_main_message *)&msg);
 	if (err < 0) {
 		syslog(LOG_ERR, "Failed to send device message %d",
@@ -47,12 +48,12 @@
 	return 0;
 }
 
-int cras_device_monitor_set_device_mute_state(unsigned int dev_idx)
+int cras_device_monitor_set_device_mute_state(struct cras_iodev *iodev)
 {
 	struct cras_device_monitor_message msg;
 	int err;
 
-	init_device_msg(&msg, SET_MUTE_STATE, dev_idx);
+	init_device_msg(&msg, SET_MUTE_STATE, iodev);
 	err = cras_main_message_send((struct cras_main_message *)&msg);
 	if (err < 0) {
 		syslog(LOG_ERR, "Failed to send device message %d",
@@ -62,27 +63,29 @@
 	return 0;
 }
 
+
 /* When device is in a bad state, e.g. severe underrun,
  * it might break how audio thread works and cause busy wake up loop.
  * Resetting the device can bring device back to normal state.
  * Let main thread follow the disable/enable sequence in iodev_list
-  * to properly close/open the device while enabling/disabling fallback
+ * to properly close/open the device while enabling/disabling fallback
  * device.
  */
 static void handle_device_message(struct cras_main_message *msg, void *arg)
 {
 	struct cras_device_monitor_message *device_msg =
-		(struct cras_device_monitor_message *)msg;
+			(struct cras_device_monitor_message *)msg;
+	struct cras_iodev *iodev = device_msg->iodev;
 
 	switch (device_msg->message_type) {
 	case RESET_DEVICE:
 		syslog(LOG_ERR, "trying to recover device 0x%x by resetting it",
-		       device_msg->dev_idx);
-		cras_iodev_list_suspend_dev(device_msg->dev_idx);
-		cras_iodev_list_resume_dev(device_msg->dev_idx);
+		       iodev->info.idx);
+		cras_iodev_list_disable_dev(iodev, true);
+		cras_iodev_list_enable_dev(iodev);
 		break;
 	case SET_MUTE_STATE:
-		cras_iodev_list_set_dev_mute(device_msg->dev_idx);
+		cras_iodev_set_mute(iodev);
 		break;
 	default:
 		syslog(LOG_ERR, "Unknown device message type %u",
diff --git a/cras/src/server/cras_device_monitor.h b/cras/src/server/cras_device_monitor.h
index ac31adb..21aa9f6 100644
--- a/cras/src/server/cras_device_monitor.h
+++ b/cras/src/server/cras_device_monitor.h
@@ -6,11 +6,13 @@
 #ifndef CRAS_DEVICE_MONITOR_H_
 #define CRAS_DEVICE_MONITOR_H_
 
+#include "cras_iodev.h"
+
 /* Asks main thread to reset a device */
-int cras_device_monitor_reset_device(unsigned int dev_idx);
+int cras_device_monitor_reset_device(struct cras_iodev *iodev);
 
 /* Asks main thread to set mute/unmute state on a device. */
-int cras_device_monitor_set_device_mute_state(unsigned int dev_idx);
+int cras_device_monitor_set_device_mute_state(struct cras_iodev *iodev);
 
 /* Initializes device monitor and sets main thread callback. */
 int cras_device_monitor_init();
diff --git a/cras/src/server/cras_dsp.c b/cras/src/server/cras_dsp.c
index 1a2707d..97e3a85 100644
--- a/cras/src/server/cras_dsp.c
+++ b/cras/src/server/cras_dsp.c
@@ -48,24 +48,9 @@
 	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)
+static struct pipeline *prepare_pipeline(
+		struct cras_dsp_context *ctx,
+		struct ini *target_ini)
 {
 	struct pipeline *pipeline;
 	const char *purpose = ctx->purpose;
@@ -100,7 +85,7 @@
 
 bail:
 	if (pipeline)
-		destroy_pipeline(pipeline);
+		cras_dsp_pipeline_free(pipeline);
 	return NULL;
 }
 
@@ -118,7 +103,7 @@
 	pthread_mutex_unlock(&ctx->mutex);
 
 	if (old_pipeline)
-		destroy_pipeline(old_pipeline);
+		cras_dsp_pipeline_free(old_pipeline);
 }
 
 static void cmd_reload_ini()
@@ -128,11 +113,12 @@
 
 	ini = cras_dsp_ini_create(ini_filename);
 	if (!ini) {
-		syslog(LOG_DEBUG, "cannot create dsp ini");
+		syslog(LOG_ERR, "cannot create dsp ini");
 		return;
 	}
 
-	DL_FOREACH (context_list, ctx) {
+
+	DL_FOREACH(context_list, ctx) {
 		cmd_load_pipeline(ctx, ini);
 	}
 
@@ -180,7 +166,7 @@
 
 	pthread_mutex_destroy(&ctx->mutex);
 	if (ctx->pipeline) {
-		destroy_pipeline(ctx->pipeline);
+		cras_dsp_pipeline_free(ctx->pipeline);
 		ctx->pipeline = NULL;
 	}
 	cras_expr_env_free(&ctx->env);
@@ -189,13 +175,14 @@
 }
 
 void cras_dsp_set_variable_string(struct cras_dsp_context *ctx, const char *key,
-				  const char *value)
+			   const char *value)
 {
 	cras_expr_env_set_variable_string(&ctx->env, key, value);
 }
 
 void cras_dsp_set_variable_boolean(struct cras_dsp_context *ctx,
-				   const char *key, char value)
+				   const char *key,
+				   char value)
 {
 	cras_expr_env_set_variable_boolean(&ctx->env, key, value);
 }
@@ -210,10 +197,8 @@
 {
 	struct ini *dummy_ini;
 	dummy_ini = create_dummy_ini(ctx->purpose, num_channels);
-	if (dummy_ini == NULL)
-		syslog(LOG_ERR, "Failed to create dummy ini");
-	else
-		cmd_load_pipeline(ctx, dummy_ini);
+	cmd_load_pipeline(ctx, dummy_ini);
+	cras_dsp_ini_free((dummy_ini));
 }
 
 struct pipeline *cras_dsp_get_pipeline(struct cras_dsp_context *ctx)
@@ -243,7 +228,7 @@
 
 	if (ini)
 		cras_dsp_ini_dump(syslog_dumper, ini);
-	DL_FOREACH (context_list, ctx) {
+	DL_FOREACH(context_list, ctx) {
 		cras_expr_env_dump(syslog_dumper, &ctx->env);
 		pipeline = ctx->pipeline;
 		if (pipeline)
diff --git a/cras/src/server/cras_dsp.h b/cras/src/server/cras_dsp.h
index 9a72f42..6c7af18 100644
--- a/cras/src/server/cras_dsp.h
+++ b/cras/src/server/cras_dsp.h
@@ -45,8 +45,8 @@
 				  const char *value);
 
 /* Sets a configuration boolean variable in the context. */
-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);
 
 /* Loads the pipeline to the context. This should be called again when
  * new values of configuration variables may change the plugin
diff --git a/cras/src/server/cras_dsp_ini.c b/cras/src/server/cras_dsp_ini.c
index 966c6b0..a8b3a9c 100644
--- a/cras/src/server/cras_dsp_ini.c
+++ b/cras/src/server/cras_dsp_ini.c
@@ -9,8 +9,8 @@
 #include "cras_dsp_ini.h"
 #include "iniparser_wrapper.h"
 
-#define MAX_INI_KEY_LENGTH 64 /* names like "output_source:output_0" */
-#define MAX_NR_PORT 128 /* the max number of ports for a plugin */
+#define MAX_INI_KEY_LENGTH 64  /* names like "output_source:output_0" */
+#define MAX_NR_PORT 128	/* the max number of ports for a plugin */
 #define MAX_PORT_NAME_LENGTH 20 /* names like "output_32" */
 #define MAX_DUMMY_INI_CH 8 /* Max number of channels to create dummy ini */
 
@@ -73,7 +73,7 @@
 	int i;
 	const struct flow *flow;
 
-	ARRAY_ELEMENT_FOREACH (&ini->flows, i, flow) {
+	FOR_ARRAY_ELEMENT(&ini->flows, i, flow) {
 		if (strcmp(flow->name, name) == 0)
 			return i;
 	}
@@ -106,7 +106,7 @@
 		direction = PORT_INPUT;
 		snprintf(key, sizeof(key), "input_%d", i);
 		str = getstring(ini, sec_name, key);
-		if (str == NULL) {
+		if (str == NULL)  {
 			direction = PORT_OUTPUT;
 			snprintf(key, sizeof(key), "output_%d", i);
 			str = getstring(ini, sec_name, key);
@@ -149,8 +149,8 @@
 	p->library = getstring(ini, sec_name, "library");
 	p->label = getstring(ini, sec_name, "label");
 	p->purpose = getstring(ini, sec_name, "purpose");
-	p->disable_expr =
-		cras_expr_expression_parse(getstring(ini, sec_name, "disable"));
+	p->disable_expr = cras_expr_expression_parse(
+		getstring(ini, sec_name, "disable"));
 
 	if (p->library == NULL || p->label == NULL) {
 		syslog(LOG_ERR, "A plugin must have library and label: %s",
@@ -175,8 +175,8 @@
 	struct plugin **pplugin;
 	int *pport;
 
-	ARRAY_ELEMENT_FOREACH (&ini->plugins, i, plugin) {
-		ARRAY_ELEMENT_FOREACH (&plugin->ports, j, port) {
+	FOR_ARRAY_ELEMENT(&ini->plugins, i, plugin) {
+		FOR_ARRAY_ELEMENT(&plugin->ports, j, port) {
 			int flow_id = port->flow_id;
 			if (flow_id == INVALID_FLOW_ID)
 				continue;
@@ -196,7 +196,9 @@
 }
 
 /* Adds a port to a plugin with specified flow id and direction. */
-static void add_audio_port(struct ini *ini, struct plugin *plugin, int flow_id,
+static void add_audio_port(struct ini *ini,
+			   struct plugin *plugin,
+			   int flow_id,
 			   enum port_direction port_direction)
 {
 	struct port *p;
@@ -208,9 +210,12 @@
 }
 
 /* Fills fields for a swap_lr plugin.*/
-static void fill_swap_lr_plugin(struct ini *ini, struct plugin *plugin,
-				int input_flowid_0, int input_flowid_1,
-				int output_flowid_0, int output_flowid_1)
+static void fill_swap_lr_plugin(struct ini *ini,
+				struct plugin *plugin,
+				int input_flowid_0,
+				int input_flowid_1,
+				int output_flowid_0,
+				int output_flowid_1)
 {
 	plugin->title = "swap_lr";
 	plugin->library = "builtin";
@@ -245,7 +250,7 @@
 	int i;
 	struct plugin *plugin;
 
-	ARRAY_ELEMENT_FOREACH (&ini->plugins, i, plugin) {
+	FOR_ARRAY_ELEMENT(&ini->plugins, i, plugin) {
 		if (strcmp(plugin->library, "builtin") != 0)
 			continue;
 		if (strcmp(plugin->label, "sink") != 0)
@@ -291,8 +296,11 @@
 
 	/* Creates a swap_lr plugin and sets the input and output ports. */
 	swap_lr = ARRAY_APPEND_ZERO(&ini->plugins);
-	fill_swap_lr_plugin(ini, swap_lr, sink_input_flowid_0,
-			    sink_input_flowid_1, swap_lr_output_flowid_0,
+	fill_swap_lr_plugin(ini,
+			    swap_lr,
+			    sink_input_flowid_0,
+			    sink_input_flowid_1,
+			    swap_lr_output_flowid_0,
 			    swap_lr_output_flowid_1);
 
 	/* Look up first sink again because ini->plugins could be realloc'ed */
@@ -372,7 +380,7 @@
 
 	dict = iniparser_load_wrapper((char *)ini_filename);
 	if (!dict) {
-		syslog(LOG_DEBUG, "no ini file %s", ini_filename);
+		syslog(LOG_ERR, "no ini file %s", ini_filename);
 		goto bail;
 	}
 	ini->dict = dict;
@@ -408,7 +416,7 @@
 	int i;
 
 	/* free plugins */
-	ARRAY_ELEMENT_FOREACH (&ini->plugins, i, p) {
+	FOR_ARRAY_ELEMENT(&ini->plugins, i, p) {
 		cras_expr_expression_free(p->disable_expr);
 		ARRAY_FREE(&p->ports);
 	}
@@ -426,24 +434,18 @@
 static const char *port_direction_str(enum port_direction port_direction)
 {
 	switch (port_direction) {
-	case PORT_INPUT:
-		return "input";
-	case PORT_OUTPUT:
-		return "output";
-	default:
-		return "unknown";
+	case PORT_INPUT: return "input";
+	case PORT_OUTPUT: return "output";
+	default: return "unknown";
 	}
 }
 
 static const char *port_type_str(enum port_type port_type)
 {
 	switch (port_type) {
-	case PORT_CONTROL:
-		return "control";
-	case PORT_AUDIO:
-		return "audio";
-	default:
-		return "unknown";
+	case PORT_CONTROL: return "control";
+	case PORT_AUDIO: return "audio";
+	default: return "unknown";
 	}
 }
 
@@ -465,13 +467,13 @@
 	dumpf(d, "ini->dict = %p\n", ini->dict);
 
 	dumpf(d, "number of plugins = %d\n", ARRAY_COUNT(&ini->plugins));
-	ARRAY_ELEMENT_FOREACH (&ini->plugins, i, plugin) {
+	FOR_ARRAY_ELEMENT(&ini->plugins, i, plugin) {
 		dumpf(d, "[plugin %d: %s]\n", i, plugin->title);
 		dumpf(d, "library=%s\n", plugin->library);
 		dumpf(d, "label=%s\n", plugin->label);
 		dumpf(d, "purpose=%s\n", plugin->purpose);
 		dumpf(d, "disable=%p\n", plugin->disable_expr);
-		ARRAY_ELEMENT_FOREACH (&plugin->ports, j, port) {
+		FOR_ARRAY_ELEMENT(&plugin->ports, j, port) {
 			dumpf(d,
 			      "  [%s port %d] type=%s, flow_id=%d, value=%g\n",
 			      port_direction_str(port->direction), j,
@@ -481,10 +483,11 @@
 	}
 
 	dumpf(d, "number of flows = %d\n", ARRAY_COUNT(&ini->flows));
-	ARRAY_ELEMENT_FOREACH (&ini->flows, i, flow) {
-		dumpf(d, "  [flow %d] %s, %s, %s:%d -> %s:%d\n", i, flow->name,
-		      port_type_str(flow->type), plugin_title(flow->from),
-		      flow->from_port, plugin_title(flow->to), flow->to_port);
+	FOR_ARRAY_ELEMENT(&ini->flows, i, flow) {
+		dumpf(d, "  [flow %d] %s, %s, %s:%d -> %s:%d\n",
+		      i, flow->name, port_type_str(flow->type),
+		      plugin_title(flow->from), flow->from_port,
+		      plugin_title(flow->to), flow->to_port);
 	}
 
 	dumpf(d, "---- ini dump end ----\n");
diff --git a/cras/src/server/cras_dsp_ini.h b/cras/src/server/cras_dsp_ini.h
index 117cfd2..0fdd69f 100644
--- a/cras/src/server/cras_dsp_ini.h
+++ b/cras/src/server/cras_dsp_ini.h
@@ -44,16 +44,16 @@
 
 struct plugin {
 	const char *title;
-	const char *library; /* file name like "plugin.so" */
-	const char *label; /* label like "Eq" */
-	const char *purpose; /* like "playback" or "capture" */
-	struct cras_expr_expression *disable_expr; /* the disable expression of
+	const char *library;  /* file name like "plugin.so" */
+	const char *label;    /* label like "Eq" */
+	const char *purpose;  /* like "playback" or "capture" */
+	struct cras_expr_expression *disable_expr;  /* the disable expression of
 					     this plugin */
 	port_array ports;
 };
 
 struct flow {
-	enum port_type type; /* the type of the ports this flow connects to */
+	enum port_type type;  /* the type of the ports this flow connects to */
 	const char *name;
 	struct plugin *from;
 	struct plugin *to;
diff --git a/cras/src/server/cras_dsp_mod_builtin.c b/cras/src/server/cras_dsp_mod_builtin.c
index 296c0eb..25106de 100644
--- a/cras/src/server/cras_dsp_mod_builtin.c
+++ b/cras/src/server/cras_dsp_mod_builtin.c
@@ -21,32 +21,23 @@
 }
 
 static void empty_connect_port(struct dsp_module *module, unsigned long port,
-			       float *data_location)
-{
-}
+			       float *data_location) {}
 
 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)
 {
 	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)
 {
@@ -71,19 +62,20 @@
 static int swap_lr_instantiate(struct dsp_module *module,
 			       unsigned long sample_rate)
 {
-	module->data = calloc(4, sizeof(float *));
+	module->data = calloc(4, sizeof(float*));
 	return 0;
 }
 
-static void swap_lr_connect_port(struct dsp_module *module, unsigned long port,
-				 float *data_location)
+static void swap_lr_connect_port(struct dsp_module *module,
+				 unsigned long port, float *data_location)
 {
 	float **ports;
 	ports = (float **)module->data;
 	ports[port] = data_location;
 }
 
-static void swap_lr_run(struct dsp_module *module, unsigned long sample_count)
+static void swap_lr_run(struct dsp_module *module,
+			unsigned long sample_count)
 {
 	size_t i;
 	float **ports = (float **)module->data;
@@ -120,7 +112,7 @@
 static int invert_lr_instantiate(struct dsp_module *module,
 				 unsigned long sample_rate)
 {
-	module->data = calloc(4, sizeof(float *));
+	module->data = calloc(4, sizeof(float*));
 	return 0;
 }
 
@@ -132,7 +124,8 @@
 	ports[port] = data_location;
 }
 
-static void invert_lr_run(struct dsp_module *module, unsigned long sample_count)
+static void invert_lr_run(struct dsp_module *module,
+			  unsigned long sample_count)
 {
 	size_t i;
 	float **ports = (float **)module->data;
@@ -165,7 +158,7 @@
 static int mix_stereo_instantiate(struct dsp_module *module,
 				  unsigned long sample_rate)
 {
-	module->data = calloc(4, sizeof(float *));
+	module->data = calloc(4, sizeof(float*));
 	return 0;
 }
 
@@ -214,7 +207,6 @@
 struct dcblock_data {
 	struct dcblock *dcblockl;
 	struct dcblock *dcblockr;
-	unsigned long sample_rate;
 
 	/* One port for input, one for output, and 1 parameter */
 	float *ports[5];
@@ -223,31 +215,24 @@
 static int dcblock_instantiate(struct dsp_module *module,
 			       unsigned long sample_rate)
 {
-	struct dcblock_data *data;
-
 	module->data = calloc(1, sizeof(struct dcblock_data));
-	data = (struct dcblock_data *)module->data;
-	data->sample_rate = sample_rate;
-
 	return 0;
 }
 
-static void dcblock_connect_port(struct dsp_module *module, unsigned long port,
-				 float *data_location)
+static void dcblock_connect_port(struct dsp_module *module,
+				 unsigned long port, float *data_location)
 {
-	struct dcblock_data *data = (struct dcblock_data *)module->data;
+	struct dcblock_data *data = (struct dcblock_data *) module->data;
 	data->ports[port] = data_location;
 }
 
 static void dcblock_run(struct dsp_module *module, unsigned long sample_count)
 {
-	struct dcblock_data *data = (struct dcblock_data *)module->data;
+	struct dcblock_data *data = (struct dcblock_data *) module->data;
 	if (!data->dcblockl)
-		data->dcblockl =
-			dcblock_new(*data->ports[4], data->sample_rate);
+		data->dcblockl = dcblock_new(*data->ports[4]);
 	if (!data->dcblockr)
-		data->dcblockr =
-			dcblock_new(*data->ports[4], data->sample_rate);
+		data->dcblockr = dcblock_new(*data->ports[4]);
 	if (data->ports[0] != data->ports[2])
 		memcpy(data->ports[2], data->ports[0],
 		       sizeof(float) * sample_count);
@@ -255,13 +240,13 @@
 		memcpy(data->ports[3], data->ports[1],
 		       sizeof(float) * sample_count);
 
-	dcblock_process(data->dcblockl, data->ports[2], (int)sample_count);
-	dcblock_process(data->dcblockr, data->ports[3], (int)sample_count);
+	dcblock_process(data->dcblockl, data->ports[2], (int) sample_count);
+	dcblock_process(data->dcblockr, data->ports[3], (int) sample_count);
 }
 
 static void dcblock_deinstantiate(struct dsp_module *module)
 {
-	struct dcblock_data *data = (struct dcblock_data *)module->data;
+	struct dcblock_data *data = (struct dcblock_data *) module->data;
 	if (data->dcblockl)
 		dcblock_free(data->dcblockl);
 	if (data->dcblockr)
@@ -286,7 +271,7 @@
  */
 struct eq_data {
 	int sample_rate;
-	struct eq *eq; /* Initialized in the first call of eq_run() */
+	struct eq *eq;  /* Initialized in the first call of eq_run() */
 
 	/* One port for input, one for output, and 4 parameters per eq */
 	float *ports[2 + MAX_BIQUADS_PER_EQ * 4];
@@ -297,21 +282,21 @@
 	struct eq_data *data;
 
 	module->data = calloc(1, sizeof(struct eq_data));
-	data = (struct eq_data *)module->data;
-	data->sample_rate = (int)sample_rate;
+	data = (struct eq_data *) module->data;
+	data->sample_rate = (int) sample_rate;
 	return 0;
 }
 
-static void eq_connect_port(struct dsp_module *module, unsigned long port,
-			    float *data_location)
+static void eq_connect_port(struct dsp_module *module,
+			    unsigned long port, float *data_location)
 {
-	struct eq_data *data = (struct eq_data *)module->data;
+	struct eq_data *data = (struct eq_data *) module->data;
 	data->ports[port] = data_location;
 }
 
 static void eq_run(struct dsp_module *module, unsigned long sample_count)
 {
-	struct eq_data *data = (struct eq_data *)module->data;
+	struct eq_data *data = (struct eq_data *) module->data;
 	if (!data->eq) {
 		float nyquist = data->sample_rate / 2;
 		int i;
@@ -320,10 +305,10 @@
 		for (i = 2; i < 2 + MAX_BIQUADS_PER_EQ * 4; i += 4) {
 			if (!data->ports[i])
 				break;
-			int type = (int)*data->ports[i];
-			float freq = *data->ports[i + 1];
-			float Q = *data->ports[i + 2];
-			float gain = *data->ports[i + 3];
+			int type = (int) *data->ports[i];
+			float freq = *data->ports[i+1];
+			float Q = *data->ports[i+2];
+			float gain = *data->ports[i+3];
 			eq_append_biquad(data->eq, type, freq / nyquist, Q,
 					 gain);
 		}
@@ -331,12 +316,12 @@
 	if (data->ports[0] != data->ports[1])
 		memcpy(data->ports[1], data->ports[0],
 		       sizeof(float) * sample_count);
-	eq_process(data->eq, data->ports[1], (int)sample_count);
+	eq_process(data->eq, data->ports[1], (int) sample_count);
 }
 
 static void eq_deinstantiate(struct dsp_module *module)
 {
-	struct eq_data *data = (struct eq_data *)module->data;
+	struct eq_data *data = (struct eq_data *) module->data;
 	if (data->eq)
 		eq_free(data->eq);
 	free(data);
@@ -359,7 +344,7 @@
  */
 struct eq2_data {
 	int sample_rate;
-	struct eq2 *eq2; /* Initialized in the first call of eq2_run() */
+	struct eq2 *eq2;  /* Initialized in the first call of eq2_run() */
 
 	/* Two ports for input, two for output, and 8 parameters per eq pair */
 	float *ports[4 + MAX_BIQUADS_PER_EQ2 * 8];
@@ -370,21 +355,21 @@
 	struct eq2_data *data;
 
 	module->data = calloc(1, sizeof(struct eq2_data));
-	data = (struct eq2_data *)module->data;
-	data->sample_rate = (int)sample_rate;
+	data = (struct eq2_data *) module->data;
+	data->sample_rate = (int) sample_rate;
 	return 0;
 }
 
-static void eq2_connect_port(struct dsp_module *module, unsigned long port,
-			     float *data_location)
+static void eq2_connect_port(struct dsp_module *module,
+			     unsigned long port, float *data_location)
 {
-	struct eq2_data *data = (struct eq2_data *)module->data;
+	struct eq2_data *data = (struct eq2_data *) module->data;
 	data->ports[port] = data_location;
 }
 
 static void eq2_run(struct dsp_module *module, unsigned long sample_count)
 {
-	struct eq2_data *data = (struct eq2_data *)module->data;
+	struct eq2_data *data = (struct eq2_data *) module->data;
 	if (!data->eq2) {
 		float nyquist = data->sample_rate / 2;
 		int i, channel;
@@ -395,16 +380,17 @@
 				break;
 			for (channel = 0; channel < 2; channel++) {
 				int k = i + channel * 4;
-				int type = (int)*data->ports[k];
-				float freq = *data->ports[k + 1];
-				float Q = *data->ports[k + 2];
-				float gain = *data->ports[k + 3];
+				int type = (int) *data->ports[k];
+				float freq = *data->ports[k+1];
+				float Q = *data->ports[k+2];
+				float gain = *data->ports[k+3];
 				eq2_append_biquad(data->eq2, channel, type,
 						  freq / nyquist, Q, gain);
 			}
 		}
 	}
 
+
 	if (data->ports[0] != data->ports[2])
 		memcpy(data->ports[2], data->ports[0],
 		       sizeof(float) * sample_count);
@@ -413,12 +399,12 @@
 		       sizeof(float) * sample_count);
 
 	eq2_process(data->eq2, data->ports[2], data->ports[3],
-		    (int)sample_count);
+		    (int) sample_count);
 }
 
 static void eq2_deinstantiate(struct dsp_module *module)
 {
-	struct eq2_data *data = (struct eq2_data *)module->data;
+	struct eq2_data *data = (struct eq2_data *) module->data;
 	if (data->eq2)
 		eq2_free(data->eq2);
 	free(data);
@@ -441,7 +427,7 @@
  */
 struct drc_data {
 	int sample_rate;
-	struct drc *drc; /* Initialized in the first call of drc_run() */
+	struct drc *drc;  /* Initialized in the first call of drc_run() */
 
 	/* Two ports for input, two for output, one for disable_emphasis,
 	 * and 8 parameters each band */
@@ -453,44 +439,44 @@
 	struct drc_data *data;
 
 	module->data = calloc(1, sizeof(struct drc_data));
-	data = (struct drc_data *)module->data;
-	data->sample_rate = (int)sample_rate;
+	data = (struct drc_data *) module->data;
+	data->sample_rate = (int) sample_rate;
 	return 0;
 }
 
-static void drc_connect_port(struct dsp_module *module, unsigned long port,
-			     float *data_location)
+static void drc_connect_port(struct dsp_module *module,
+			    unsigned long port, float *data_location)
 {
-	struct drc_data *data = (struct drc_data *)module->data;
+	struct drc_data *data = (struct drc_data *) module->data;
 	data->ports[port] = data_location;
 }
 
 static int drc_get_delay(struct dsp_module *module)
 {
-	struct drc_data *data = (struct drc_data *)module->data;
+	struct drc_data *data = (struct drc_data *) module->data;
 	return DRC_DEFAULT_PRE_DELAY * data->sample_rate;
 }
 
 static void drc_run(struct dsp_module *module, unsigned long sample_count)
 {
-	struct drc_data *data = (struct drc_data *)module->data;
+	struct drc_data *data = (struct drc_data *) module->data;
 	if (!data->drc) {
 		int i;
 		float nyquist = data->sample_rate / 2;
 		struct drc *drc = drc_new(data->sample_rate);
 
 		data->drc = drc;
-		drc->emphasis_disabled = (int)*data->ports[4];
+		drc->emphasis_disabled = (int) *data->ports[4];
 		for (i = 0; i < 3; i++) {
 			int k = 5 + i * 8;
 			float f = *data->ports[k];
-			float enable = *data->ports[k + 1];
-			float threshold = *data->ports[k + 2];
-			float knee = *data->ports[k + 3];
-			float ratio = *data->ports[k + 4];
-			float attack = *data->ports[k + 5];
-			float release = *data->ports[k + 6];
-			float boost = *data->ports[k + 7];
+			float enable = *data->ports[k+1];
+			float threshold = *data->ports[k+2];
+			float knee = *data->ports[k+3];
+			float ratio = *data->ports[k+4];
+			float attack = *data->ports[k+5];
+			float release = *data->ports[k+6];
+			float boost = *data->ports[k+7];
 			drc_set_param(drc, i, PARAM_CROSSOVER_LOWER_FREQ,
 				      f / nyquist);
 			drc_set_param(drc, i, PARAM_ENABLED, enable);
@@ -510,12 +496,12 @@
 		memcpy(data->ports[3], data->ports[1],
 		       sizeof(float) * sample_count);
 
-	drc_process(data->drc, &data->ports[2], (int)sample_count);
+	drc_process(data->drc, &data->ports[2], (int) sample_count);
 }
 
 static void drc_deinstantiate(struct dsp_module *module)
 {
-	struct drc_data *data = (struct drc_data *)module->data;
+	struct drc_data *data = (struct drc_data *) module->data;
 	if (data->drc)
 		drc_free(data->drc);
 	free(data);
@@ -555,7 +541,7 @@
 }
 
 static void sink_connect_port(struct dsp_module *module, unsigned long port,
-			      float *data_location)
+				  float *data_location)
 {
 	struct sink_data *data = (struct sink_data *)module->data;
 	data->ports[port] = data_location;
@@ -589,9 +575,6 @@
 	int i;
 	data->ext_module = ext_module;
 
-	if (data->ext_module == NULL)
-		return;
-
 	for (i = 0; i < MAX_EXT_DSP_PORTS; i++)
 		ext_module->ports[i] = data->ports[i];
 }
diff --git a/cras/src/server/cras_dsp_mod_ladspa.c b/cras/src/server/cras_dsp_mod_ladspa.c
index 2ee1539..9110ad4 100644
--- a/cras/src/server/cras_dsp_mod_ladspa.c
+++ b/cras/src/server/cras_dsp_mod_ladspa.c
@@ -13,9 +13,9 @@
 #define PLUGIN_PATH_MAX 256
 
 struct ladspa_data {
-	void *dlopen_handle; /* the handle returned by dlopen() */
+	void *dlopen_handle;  /* the handle returned by dlopen() */
 	const LADSPA_Descriptor *descriptor;
-	LADSPA_Handle *handle; /* returned by instantiate() */
+	LADSPA_Handle *handle;	/* returned by instantiate() */
 	int activated;
 };
 
@@ -65,7 +65,7 @@
 }
 
 static void connect_port(struct dsp_module *module, unsigned long port,
-			 float *data_location)
+			     float *data_location)
 {
 	struct ladspa_data *data = module->data;
 	const LADSPA_Descriptor *desc = data->descriptor;
@@ -134,7 +134,7 @@
 		return -1;
 	}
 
-	ARRAY_ELEMENT_FOREACH (&plugin->ports, i, port) {
+	FOR_ARRAY_ELEMENT(&plugin->ports, i, port) {
 		LADSPA_PortDescriptor port_desc = desc->PortDescriptors[i];
 		if ((port->direction == PORT_INPUT) !=
 		    !!(port_desc & LADSPA_PORT_INPUT)) {
@@ -181,7 +181,7 @@
 		goto bail;
 	}
 
-	for (index = 0;; index++) {
+	for (index = 0; ; index++) {
 		const LADSPA_Descriptor *desc = desc_func(index);
 		if (desc == NULL) {
 			syslog(LOG_ERR, "cannot find label %s from %s",
diff --git a/cras/src/server/cras_dsp_module.h b/cras/src/server/cras_dsp_module.h
index 53b9dca..728418c 100644
--- a/cras/src/server/cras_dsp_module.h
+++ b/cras/src/server/cras_dsp_module.h
@@ -72,6 +72,7 @@
 	void (*dump)(struct dsp_module *mod, struct dumper *d);
 };
 
+
 /* An external module interface working with existing dsp pipeline.
  * __________  ___________        ____________      __________
  * |        |  |         |        |          |      |        |
@@ -97,12 +98,18 @@
  */
 struct ext_dsp_module {
 	float *ports[MAX_EXT_DSP_PORTS];
-	void (*run)(struct ext_dsp_module *ext, unsigned int nframes);
-	void (*configure)(struct ext_dsp_module *ext, unsigned int buffer_size,
-			  unsigned int num_channels, unsigned int rate);
+	void (*run)(struct ext_dsp_module *ext,
+		    unsigned int nframes);
+	void (*configure)(struct ext_dsp_module *ext,
+			  unsigned int buffer_size,
+			  unsigned int num_channels,
+			  unsigned int rate);
 };
 
-enum { MODULE_INPLACE_BROKEN = 1 }; /* See ladspa.h for explanation */
+
+enum {
+	MODULE_INPLACE_BROKEN = 1  /* See ladspa.h for explanation */
+};
 
 /* Connects an external dsp module to a builtin sink module. */
 void cras_dsp_module_set_sink_ext_module(struct dsp_module *module,
diff --git a/cras/src/server/cras_dsp_pipeline.c b/cras/src/server/cras_dsp_pipeline.c
index 945e5c3..699c86b 100644
--- a/cras/src/server/cras_dsp_pipeline.c
+++ b/cras/src/server/cras_dsp_pipeline.c
@@ -45,18 +45,18 @@
 
 /* This represents an audio port on an instance. */
 struct audio_port {
-	struct audio_port *peer; /* the audio port this port connects to */
-	struct plugin *plugin; /* the plugin corresponds to the instance */
-	int original_index; /* the port index in the plugin */
+	struct audio_port *peer;  /* the audio port this port connects to */
+	struct plugin *plugin;  /* the plugin corresponds to the instance */
+	int original_index;  /* the port index in the plugin */
 	int buf_index; /* the buffer index in the pipeline */
 };
 
 /* This represents a control port on an instance. */
 struct control_port {
-	struct control_port *peer; /* the control port this port connects to */
-	struct plugin *plugin; /* the plugin corresponds to the instance */
-	int original_index; /* the port index in the plugin */
-	float value; /* the value of the control port */
+	struct control_port *peer;  /* the control port this port connects to */
+	struct plugin *plugin;  /* the plugin corresponds to the instance */
+	int original_index;  /* the port index in the plugin */
+	float value;  /* the value of the control port */
 };
 
 DECLARE_ARRAY_TYPE(struct audio_port, audio_port_array);
@@ -150,7 +150,7 @@
 	int i;
 	struct instance *instance;
 
-	ARRAY_ELEMENT_FOREACH (instances, i, instance) {
+	FOR_ARRAY_ELEMENT(instances, i, instance) {
 		if (instance->plugin == plugin)
 			return instance;
 	}
@@ -197,7 +197,7 @@
 
 	k = 0;
 	found = 0;
-	ARRAY_ELEMENT_FOREACH (&plugin->ports, i, port) {
+	FOR_ARRAY_ELEMENT(&plugin->ports, i, port) {
 		if (index == i) {
 			found = 1;
 			break;
@@ -209,7 +209,7 @@
 		return -1;
 
 	found = 0;
-	ARRAY_ELEMENT_FOREACH (&plugin->ports, i, port) {
+	FOR_ARRAY_ELEMENT(&plugin->ports, i, port) {
 		if (port->direction == PORT_INPUT && port->type == type) {
 			if (k-- == 0) {
 				index = i;
@@ -237,7 +237,7 @@
 	if (!instance)
 		return NULL;
 
-	ARRAY_ELEMENT_FOREACH (&instance->output_audio_ports, i, audio_port) {
+	FOR_ARRAY_ELEMENT(&instance->output_audio_ports, i, audio_port) {
 		if (audio_port->original_index == index)
 			return audio_port;
 	}
@@ -257,8 +257,7 @@
 	if (!instance)
 		return NULL;
 
-	ARRAY_ELEMENT_FOREACH (&instance->output_control_ports, i,
-			       control_port) {
+	FOR_ARRAY_ELEMENT(&instance->output_control_ports, i, control_port) {
 		if (control_port->original_index == index)
 			return control_port;
 	}
@@ -270,14 +269,14 @@
 {
 	char disabled;
 	return (plugin->disable_expr &&
-		cras_expr_expression_eval_boolean(plugin->disable_expr, env,
-						  &disabled) == 0 &&
+		cras_expr_expression_eval_boolean(
+			plugin->disable_expr, env, &disabled) == 0 &&
 		disabled == 1);
 }
 
 static int topological_sort(struct pipeline *pipeline,
-			    struct cras_expr_env *env, struct plugin *plugin,
-			    char *visited)
+			    struct cras_expr_env *env,
+			    struct plugin *plugin, char* visited)
 {
 	struct port *port;
 	struct flow *flow;
@@ -292,7 +291,7 @@
 		return 0;
 	visited[index] = 1;
 
-	ARRAY_ELEMENT_FOREACH (&plugin->ports, i, port) {
+	FOR_ARRAY_ELEMENT(&plugin->ports, i, port) {
 		if (port->flow_id == INVALID_FLOW_ID)
 			continue;
 		flow_id = port->flow_id;
@@ -314,10 +313,10 @@
 	instance->plugin = plugin;
 
 	/* constructs audio and control ports for the instance */
-	ARRAY_ELEMENT_FOREACH (&plugin->ports, i, port) {
+	FOR_ARRAY_ELEMENT(&plugin->ports, i, port) {
 		int need_connect = (port->flow_id != INVALID_FLOW_ID &&
 				    port->direction == PORT_INPUT);
-		struct plugin *origin = NULL;
+                struct plugin *origin = NULL;
 		int origin_index = 0;
 
 		if (need_connect) {
@@ -329,8 +328,8 @@
 		if (port->type == PORT_AUDIO) {
 			audio_port_array *audio_port_array =
 				(port->direction == PORT_INPUT) ?
-					&instance->input_audio_ports :
-					&instance->output_audio_ports;
+				&instance->input_audio_ports :
+				&instance->output_audio_ports;
 			struct audio_port *audio_port =
 				ARRAY_APPEND_ZERO(audio_port_array);
 			audio_port->plugin = plugin;
@@ -348,8 +347,8 @@
 		} else if (port->type == PORT_CONTROL) {
 			control_port_array *control_port_array =
 				(port->direction == PORT_INPUT) ?
-					&instance->input_control_ports :
-					&instance->output_control_ports;
+				&instance->input_control_ports :
+				&instance->output_control_ports;
 			struct control_port *control_port =
 				ARRAY_APPEND_ZERO(control_port_array);
 			control_port->plugin = plugin;
@@ -379,7 +378,7 @@
 	int i;
 	struct plugin *plugin, *found = NULL;
 
-	ARRAY_ELEMENT_FOREACH (&ini->plugins, i, plugin) {
+	FOR_ARRAY_ELEMENT(&ini->plugins, i, plugin) {
 		if (strcmp(plugin->library, "builtin") != 0)
 			continue;
 		if (strcmp(plugin->label, label) != 0)
@@ -407,15 +406,15 @@
 	int n;
 	char *visited;
 	int rc;
-	struct plugin *source =
-		find_enabled_builtin_plugin(ini, "source", purpose, env);
-	struct plugin *sink =
-		find_enabled_builtin_plugin(ini, "sink", purpose, env);
+	struct plugin *source = find_enabled_builtin_plugin(
+		ini, "source", purpose, env);
+	struct plugin *sink = find_enabled_builtin_plugin(
+		ini, "sink", purpose, env);
 
 	if (!source || !sink) {
 		syslog(LOG_DEBUG,
-		       "no enabled source or sink found %p/%p for %s", source,
-		       sink, purpose);
+		       "no enabled source or sink found %p/%p for %s",
+		       source, sink, purpose);
 		return NULL;
 	}
 
@@ -438,10 +437,10 @@
 		return NULL;
 	}
 
-	pipeline->source_instance =
-		find_instance_by_plugin(&pipeline->instances, source);
-	pipeline->sink_instance =
-		find_instance_by_plugin(&pipeline->instances, sink);
+	pipeline->source_instance = find_instance_by_plugin(
+		&pipeline->instances, source);
+	pipeline->sink_instance = find_instance_by_plugin(
+		&pipeline->instances, sink);
 
 	if (!pipeline->source_instance || !pipeline->sink_instance) {
 		syslog(LOG_ERR, "source(%p) or sink(%p) missing/disabled?",
@@ -450,10 +449,10 @@
 		return NULL;
 	}
 
-	pipeline->input_channels =
-		ARRAY_COUNT(&pipeline->source_instance->output_audio_ports);
-	pipeline->output_channels =
-		ARRAY_COUNT(&pipeline->sink_instance->input_audio_ports);
+	pipeline->input_channels = ARRAY_COUNT(
+		&pipeline->source_instance->output_audio_ports);
+	pipeline->output_channels = ARRAY_COUNT(
+		&pipeline->sink_instance->input_audio_ports);
 	if (pipeline->output_channels > pipeline->input_channels) {
 		/* Can't increase channel count, no where to put them. */
 		syslog(LOG_ERR, "DSP output more channels than input\n");
@@ -482,7 +481,7 @@
 	int i, k = 0;
 	struct audio_port *audio_port;
 
-	ARRAY_ELEMENT_FOREACH (audio_ports, i, audio_port) {
+	FOR_ARRAY_ELEMENT(audio_ports, i, audio_port) {
 		while (busy[k])
 			k++;
 		audio_port->buf_index = k;
@@ -495,7 +494,7 @@
 	int i;
 	struct audio_port *audio_port;
 
-	ARRAY_ELEMENT_FOREACH (audio_ports, i, audio_port) {
+	FOR_ARRAY_ELEMENT(audio_ports, i, audio_port) {
 		busy[audio_port->buf_index] = 0;
 	}
 }
@@ -509,7 +508,7 @@
 	char *busy;
 
 	/* first figure out how many buffers do we need */
-	ARRAY_ELEMENT_FOREACH (&pipeline->instances, i, instance) {
+	FOR_ARRAY_ELEMENT(&pipeline->instances, i, instance) {
 		int in = ARRAY_COUNT(&instance->input_audio_ports);
 		int out = ARRAY_COUNT(&instance->output_audio_ports);
 
@@ -546,13 +545,12 @@
 
 	/* Now assign buffer index for each instance's input/output ports */
 	busy = calloc(peak_buf, sizeof(*busy));
-	ARRAY_ELEMENT_FOREACH (&pipeline->instances, i, instance) {
+	FOR_ARRAY_ELEMENT(&pipeline->instances, i, instance) {
 		int j;
 		struct audio_port *audio_port;
 
 		/* Collect input buffers from upstream */
-		ARRAY_ELEMENT_FOREACH (&instance->input_audio_ports, j,
-				       audio_port) {
+		FOR_ARRAY_ELEMENT(&instance->input_audio_ports, j, audio_port) {
 			audio_port->buf_index = audio_port->peer->buf_index;
 		}
 
@@ -600,7 +598,7 @@
 	int i;
 	struct instance *instance;
 
-	ARRAY_ELEMENT_FOREACH (&pipeline->instances, i, instance) {
+	FOR_ARRAY_ELEMENT(&pipeline->instances, i, instance) {
 		struct plugin *plugin = instance->plugin;
 		if (load_module(plugin, instance) != 0)
 			return -1;
@@ -618,7 +616,7 @@
 	int i;
 	struct instance *instance;
 
-	ARRAY_ELEMENT_FOREACH (&pipeline->instances, i, instance) {
+	FOR_ARRAY_ELEMENT(&pipeline->instances, i, instance) {
 		struct dsp_module *module = instance->module;
 		audio_port_array *audio_in = &instance->input_audio_ports;
 		struct audio_port *audio_port;
@@ -627,7 +625,7 @@
 
 		/* Finds the max delay of all modules that provide input to this
 		 * instance. */
-		ARRAY_ELEMENT_FOREACH (audio_in, j, audio_port) {
+		FOR_ARRAY_ELEMENT(audio_in, j, audio_port) {
 			struct instance *upstream = find_instance_by_plugin(
 				&pipeline->instances, audio_port->peer->plugin);
 			delay = MAX(upstream->total_delay, delay);
@@ -642,7 +640,7 @@
 	int i;
 	struct instance *instance;
 
-	ARRAY_ELEMENT_FOREACH (&pipeline->instances, i, instance) {
+	FOR_ARRAY_ELEMENT(&pipeline->instances, i, instance) {
 		struct dsp_module *module = instance->module;
 		if (module->instantiate(module, sample_rate) != 0)
 			return -1;
@@ -651,7 +649,7 @@
 	}
 	pipeline->sample_rate = sample_rate;
 
-	ARRAY_ELEMENT_FOREACH (&pipeline->instances, i, instance) {
+	FOR_ARRAY_ELEMENT(&pipeline->instances, i, instance) {
 		audio_port_array *audio_in = &instance->input_audio_ports;
 		audio_port_array *audio_out = &instance->output_audio_ports;
 		control_port_array *control_in = &instance->input_control_ports;
@@ -663,17 +661,19 @@
 		struct dsp_module *module = instance->module;
 
 		/* connect audio ports */
-		ARRAY_ELEMENT_FOREACH (audio_in, j, audio_port) {
+		FOR_ARRAY_ELEMENT(audio_in, j, audio_port) {
 			float *buf = pipeline->buffers[audio_port->buf_index];
-			module->connect_port(module, audio_port->original_index,
+			module->connect_port(module,
+					     audio_port->original_index,
 					     buf);
 			syslog(LOG_DEBUG, "connect audio buf %d to %s:%d (in)",
 			       audio_port->buf_index, instance->plugin->title,
 			       audio_port->original_index);
 		}
-		ARRAY_ELEMENT_FOREACH (audio_out, j, audio_port) {
+		FOR_ARRAY_ELEMENT(audio_out, j, audio_port) {
 			float *buf = pipeline->buffers[audio_port->buf_index];
-			module->connect_port(module, audio_port->original_index,
+			module->connect_port(module,
+					     audio_port->original_index,
 					     buf);
 			syslog(LOG_DEBUG, "connect audio buf %d to %s:%d (out)",
 			       audio_port->buf_index, instance->plugin->title,
@@ -681,22 +681,23 @@
 		}
 
 		/* connect control ports */
-		ARRAY_ELEMENT_FOREACH (control_in, j, control_port) {
+		FOR_ARRAY_ELEMENT(control_in, j, control_port) {
 			/* Note for input control ports which has a
 			 * peer, we use &control_port->peer->value, so
 			 * we can get the peer port's output value
 			 * directly */
 			float *value = control_port->peer ?
-					       &control_port->peer->value :
-					       &control_port->value;
-			module->connect_port(
-				module, control_port->original_index, value);
+				&control_port->peer->value :
+				&control_port->value;
+			module->connect_port(module,
+					     control_port->original_index,
+					     value);
 			syslog(LOG_DEBUG,
 			       "connect control (val=%g) to %s:%d (in)",
 			       control_port->value, instance->plugin->title,
 			       control_port->original_index);
 		}
-		ARRAY_ELEMENT_FOREACH (control_out, j, control_port) {
+		FOR_ARRAY_ELEMENT(control_out, j, control_port) {
 			module->connect_port(module,
 					     control_port->original_index,
 					     &control_port->value);
@@ -716,7 +717,7 @@
 	int i;
 	struct instance *instance;
 
-	ARRAY_ELEMENT_FOREACH (&pipeline->instances, i, instance) {
+	FOR_ARRAY_ELEMENT(&pipeline->instances, i, instance) {
 		struct dsp_module *module = instance->module;
 		if (instance->instantiated) {
 			module->deinstantiate(module);
@@ -752,12 +753,13 @@
 }
 
 static float *find_buffer(struct pipeline *pipeline,
-			  audio_port_array *audio_ports, int index)
+			  audio_port_array *audio_ports,
+			  int index)
 {
 	int i;
 	struct audio_port *audio_port;
 
-	ARRAY_ELEMENT_FOREACH (audio_ports, i, audio_port) {
+	FOR_ARRAY_ELEMENT(audio_ports, i, audio_port) {
 		if (audio_port->original_index == index)
 			return pipeline->buffers[audio_port->buf_index];
 	}
@@ -774,19 +776,16 @@
 float *cras_dsp_pipeline_get_sink_buffer(struct pipeline *pipeline, int index)
 {
 	return find_buffer(pipeline,
-			   &pipeline->sink_instance->input_audio_ports, index);
+			   &pipeline->sink_instance->input_audio_ports,
+			   index);
 }
 
 void cras_dsp_pipeline_set_sink_ext_module(struct pipeline *pipeline,
 					   struct ext_dsp_module *ext_module)
 {
-	cras_dsp_module_set_sink_ext_module(pipeline->sink_instance->module,
-					    ext_module);
-}
-
-struct ini *cras_dsp_pipeline_get_ini(struct pipeline *pipeline)
-{
-	return pipeline->ini;
+	cras_dsp_module_set_sink_ext_module(
+			pipeline->sink_instance->module,
+			ext_module);
 }
 
 void cras_dsp_pipeline_run(struct pipeline *pipeline, int sample_count)
@@ -794,7 +793,7 @@
 	int i;
 	struct instance *instance;
 
-	ARRAY_ELEMENT_FOREACH (&pipeline->instances, i, instance) {
+	FOR_ARRAY_ELEMENT(&pipeline->instances, i, instance) {
 		struct dsp_module *module = instance->module;
 		module->run(module, sample_count);
 	}
@@ -854,8 +853,8 @@
 		chunk = MIN(remaining, (size_t)DSP_BUFFER_SIZE);
 
 		/* deinterleave and convert to float */
-		rc = dsp_util_deinterleave(buf, source, input_channels, format,
-					   chunk);
+		rc = dsp_util_deinterleave(buf, source, input_channels,
+					   format, chunk);
 		if (rc)
 			return rc;
 
@@ -863,8 +862,8 @@
 		cras_dsp_pipeline_run(pipeline, chunk);
 
 		/* interleave and convert back to int16_t */
-		rc = dsp_util_interleave(sink, buf, output_channels, format,
-					 chunk);
+		rc = dsp_util_interleave(sink, buf, output_channels,
+					 format, chunk);
 		if (rc)
 			return rc;
 
@@ -883,7 +882,7 @@
 	int i;
 	struct instance *instance;
 
-	ARRAY_ELEMENT_FOREACH (&pipeline->instances, i, instance) {
+	FOR_ARRAY_ELEMENT(&pipeline->instances, i, instance) {
 		struct dsp_module *module = instance->module;
 		instance->plugin = NULL;
 		ARRAY_FREE(&instance->input_audio_ports);
@@ -921,10 +920,10 @@
 		return;
 	dumpf(d, "   %s (%d) =\n", name, n);
 
-	ARRAY_ELEMENT_FOREACH (audio_ports, i, audio_port) {
-		dumpf(d, "   %p, peer %p, orig=%d, buf=%d\n", audio_port,
-		      audio_port->peer, audio_port->original_index,
-		      audio_port->buf_index);
+	FOR_ARRAY_ELEMENT(audio_ports, i, audio_port) {
+		dumpf(d, "   %p, peer %p, orig=%d, buf=%d\n",
+		      audio_port, audio_port->peer,
+		      audio_port->original_index, audio_port->buf_index);
 	}
 }
 
@@ -939,10 +938,10 @@
 		return;
 	dumpf(d, "   %s (%d) =\n", name, ARRAY_COUNT(control_ports));
 
-	ARRAY_ELEMENT_FOREACH (control_ports, i, control_port) {
-		dumpf(d, "   %p, peer %p, orig=%d, value=%g\n", control_port,
-		      control_port->peer, control_port->original_index,
-		      control_port->value);
+	FOR_ARRAY_ELEMENT(control_ports, i, control_port) {
+		dumpf(d, "   %p, peer %p, orig=%d, value=%g\n",
+		      control_port, control_port->peer,
+		      control_port->original_index, control_port->value);
 	}
 }
 
@@ -970,14 +969,15 @@
 	      pipeline->min_time);
 	dumpf(d, " max processing time per block: %" PRId64 "ns\n",
 	      pipeline->max_time);
-	dumpf(d, " cpu load: %g%%\n",
-	      pipeline->total_time * 1e-9 / pipeline->total_samples *
-		      pipeline->sample_rate * 100);
-	dumpf(d, " instances (%d):\n", ARRAY_COUNT(&pipeline->instances));
-	ARRAY_ELEMENT_FOREACH (&pipeline->instances, i, instance) {
+	dumpf(d, " cpu load: %g%%\n", pipeline->total_time * 1e-9
+	      / pipeline->total_samples * pipeline->sample_rate * 100);
+	dumpf(d, " instances (%d):\n",
+	      ARRAY_COUNT(&pipeline->instances));
+	FOR_ARRAY_ELEMENT(&pipeline->instances, i, instance) {
 		struct dsp_module *module = instance->module;
-		dumpf(d, "  [%d]%s mod=%p, total delay=%d\n", i,
-		      instance->plugin->title, module, instance->total_delay);
+		dumpf(d, "  [%d]%s mod=%p, total delay=%d\n",
+		      i, instance->plugin->title, module,
+		      instance->total_delay);
 		if (module)
 			module->dump(module, d);
 		dump_audio_ports(d, "input_audio_ports",
diff --git a/cras/src/server/cras_dsp_pipeline.h b/cras/src/server/cras_dsp_pipeline.h
index 1a5a85a..c299f3a 100644
--- a/cras/src/server/cras_dsp_pipeline.h
+++ b/cras/src/server/cras_dsp_pipeline.h
@@ -42,7 +42,7 @@
  * Returns:
  *    A pointer to the pipeline, or NULL if the creation fails.
  */
-struct pipeline *cras_dsp_pipeline_create(struct ini *ini,
+struct pipeline *cras_dsp_pipeline_create(struct ini* ini,
 					  struct cras_expr_env *env,
 					  const char *purpose);
 
@@ -119,9 +119,6 @@
  * 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_empty_iodev.c b/cras/src/server/cras_empty_iodev.c
index 574f536..09defa0 100644
--- a/cras/src/server/cras_empty_iodev.c
+++ b/cras/src/server/cras_empty_iodev.c
@@ -19,47 +19,54 @@
 #define EMPTY_FRAME_SIZE 4
 #define EMPTY_FRAMES (EMPTY_BUFFER_SIZE / EMPTY_FRAME_SIZE)
 
-static size_t empty_supported_rates[] = { 44100, 48000, 0 };
+static size_t empty_supported_rates[] = {
+	44100, 48000, 0
+};
 
-static size_t empty_supported_channel_counts[] = { 1, 2, 0 };
+static size_t empty_supported_channel_counts[] = {
+	1, 2, 0
+};
 
 static snd_pcm_format_t empty_supported_formats[] = {
-	SND_PCM_FORMAT_S16_LE, SND_PCM_FORMAT_S24_LE, SND_PCM_FORMAT_S32_LE,
-	SND_PCM_FORMAT_S24_3LE, 0
+	SND_PCM_FORMAT_S16_LE,
+	SND_PCM_FORMAT_S24_LE,
+	SND_PCM_FORMAT_S32_LE,
+	SND_PCM_FORMAT_S24_3LE,
+	0
 };
 
 struct empty_iodev {
 	struct cras_iodev base;
+	int open;
 	uint8_t *audio_buffer;
-	uint64_t read_frames, written_frames;
-	struct timespec dev_start_time;
+	unsigned int buffer_level;
+	struct timespec last_buffer_access;
 };
 
-/*
- * Current level of the audio buffer.  This is made up based on what has been
- * read/written and how long it has been since the start. Simulates audio
- * hardware running at the given sample rate.
+/* Current level of the audio buffer.  This is made up based on what has been
+ * read/written and how long it has been since then.  Simulates audio hardware
+ * running at the given sample rate.
  */
 static unsigned int current_level(const struct cras_iodev *iodev)
 {
 	struct empty_iodev *empty_iodev = (struct empty_iodev *)iodev;
-	uint64_t frames_since_start, nframes;
+	unsigned int frames, frames_since_last;
 
 	if (iodev->active_node->type == CRAS_NODE_TYPE_HOTWORD)
 		return 0;
 
-	frames_since_start = cras_frames_since_time(
-		&empty_iodev->dev_start_time, iodev->format->frame_rate);
+	frames = empty_iodev->buffer_level;
+	frames_since_last = cras_frames_since_time(
+			&empty_iodev->last_buffer_access,
+			iodev->format->frame_rate);
 
-	if (iodev->direction == CRAS_STREAM_INPUT) {
-		nframes = frames_since_start - empty_iodev->read_frames;
-		return MIN(nframes, EMPTY_FRAMES);
-	}
+	if (iodev->direction == CRAS_STREAM_INPUT)
+		return (frames + frames_since_last) % EMPTY_FRAMES;
 
 	/* output */
-	if (empty_iodev->written_frames <= frames_since_start)
+	if (frames <= frames_since_last)
 		return 0;
-	return empty_iodev->written_frames - frames_since_start;
+	return frames - frames_since_last;
 }
 
 /*
@@ -82,6 +89,7 @@
 {
 	struct empty_iodev *empty_iodev = (struct empty_iodev *)iodev;
 
+	empty_iodev->open = 0;
 	free(empty_iodev->audio_buffer);
 	empty_iodev->audio_buffer = NULL;
 	cras_iodev_free_audio_area(iodev);
@@ -96,16 +104,17 @@
 		return -EINVAL;
 
 	cras_iodev_init_audio_area(iodev, iodev->format->num_channels);
+	empty_iodev->open = 1;
 	empty_iodev->audio_buffer = calloc(1, EMPTY_BUFFER_SIZE);
-	empty_iodev->read_frames = 0;
-	empty_iodev->written_frames = 0;
+	empty_iodev->buffer_level = 0;
 
-	clock_gettime(CLOCK_MONOTONIC_RAW, &empty_iodev->dev_start_time);
+	clock_gettime(CLOCK_MONOTONIC_RAW, &empty_iodev->last_buffer_access);
 
 	return 0;
 }
 
-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 empty_iodev *empty_iodev = (struct empty_iodev *)iodev;
@@ -121,28 +130,30 @@
 
 	iodev->area->frames = *frames;
 	cras_audio_area_config_buf_pointers(iodev->area, iodev->format,
-					    empty_iodev->audio_buffer);
+			empty_iodev->audio_buffer);
 	*area = iodev->area;
 	return 0;
 }
 
-/*
- * Returns -EPIPE if there are not enough frames or spaces in device buffer.
- * It matches other alsa-based devices.
- */
 static int put_buffer(struct cras_iodev *iodev, unsigned frames)
 {
 	struct empty_iodev *empty_iodev = (struct empty_iodev *)iodev;
 
-	if (iodev->direction == CRAS_STREAM_INPUT) {
-		if (current_level(iodev) < frames)
-			return -EPIPE;
-		empty_iodev->read_frames += frames;
+	empty_iodev->buffer_level = current_level(iodev);
+
+	clock_gettime(CLOCK_MONOTONIC_RAW, &empty_iodev->last_buffer_access);
+
+	if (iodev->direction == CRAS_STREAM_OUTPUT) {
+		empty_iodev->buffer_level += frames;
+		empty_iodev->buffer_level %= EMPTY_FRAMES;
 	} else {
-		if (EMPTY_FRAMES - current_level(iodev) < frames)
-			return -EPIPE;
-		empty_iodev->written_frames += frames;
+		/* Input */
+		if (empty_iodev->buffer_level > frames)
+			empty_iodev->buffer_level -= frames;
+		else
+			empty_iodev->buffer_level = 0;
 	}
+
 	return 0;
 }
 
@@ -150,12 +161,12 @@
 {
 	struct empty_iodev *empty_iodev = (struct empty_iodev *)iodev;
 
-	if (iodev->direction == CRAS_STREAM_INPUT)
-		empty_iodev->read_frames = 0;
-	else
-		empty_iodev->written_frames = 0;
-
-	clock_gettime(CLOCK_MONOTONIC_RAW, &empty_iodev->dev_start_time);
+	empty_iodev->buffer_level = current_level(iodev);
+	if (iodev->direction == CRAS_STREAM_INPUT) {
+		empty_iodev->buffer_level = 0;
+		clock_gettime(CLOCK_MONOTONIC_RAW,
+			      &empty_iodev->last_buffer_access);
+	}
 	return 0;
 }
 
@@ -211,20 +222,23 @@
 	/* Finally add it to the appropriate iodev list. */
 	if (direction == CRAS_STREAM_INPUT) {
 		if (node->type == CRAS_NODE_TYPE_HOTWORD) {
-			snprintf(iodev->info.name, ARRAY_SIZE(iodev->info.name),
+			snprintf(iodev->info.name,
+				 ARRAY_SIZE(iodev->info.name),
 				 "Silent hotword device.");
 			iodev->info.name[ARRAY_SIZE(iodev->info.name) - 1] =
 				'\0';
 			iodev->info.idx = SILENT_HOTWORD_DEVICE;
 		} else {
-			snprintf(iodev->info.name, ARRAY_SIZE(iodev->info.name),
+			snprintf(iodev->info.name,
+				 ARRAY_SIZE(iodev->info.name),
 				 "Silent record device.");
 			iodev->info.name[ARRAY_SIZE(iodev->info.name) - 1] =
 				'\0';
 			iodev->info.idx = SILENT_RECORD_DEVICE;
 		}
 	} else {
-		snprintf(iodev->info.name, ARRAY_SIZE(iodev->info.name),
+		snprintf(iodev->info.name,
+			 ARRAY_SIZE(iodev->info.name),
 			 "Silent playback device.");
 		iodev->info.name[ARRAY_SIZE(iodev->info.name) - 1] = '\0';
 		iodev->info.idx = SILENT_PLAYBACK_DEVICE;
diff --git a/cras/src/server/cras_expr.c b/cras/src/server/cras_expr.c
index f7fab0d..5d8767f 100644
--- a/cras/src/server/cras_expr.c
+++ b/cras/src/server/cras_expr.c
@@ -56,7 +56,7 @@
 static void copy_value(struct cras_expr_value *value,
 		       struct cras_expr_value *original)
 {
-	cras_expr_value_free(value); /* free the original value first */
+	cras_expr_value_free(value);  /* free the original value first */
 	value->type = original->type;
 	switch (value->type) {
 	case CRAS_EXPR_VALUE_TYPE_NONE:
@@ -99,7 +99,8 @@
 		dumpf(d, "none");
 		break;
 	case CRAS_EXPR_VALUE_TYPE_BOOLEAN:
-		dumpf(d, "boolean(%s)", value->u.boolean ? "true" : "false");
+		dumpf(d, "boolean(%s)",
+		      value->u.boolean ? "true" : "false");
 		break;
 	case CRAS_EXPR_VALUE_TYPE_INT:
 		dumpf(d, "integer(%d)", value->u.integer);
@@ -119,7 +120,7 @@
 	int i;
 	const char **key;
 
-	ARRAY_ELEMENT_FOREACH (&env->keys, i, key) {
+	FOR_ARRAY_ELEMENT(&env->keys, i, key) {
 		if (strcmp(*key, name) == 0)
 			return ARRAY_ELEMENT(&env->values, i);
 	}
@@ -177,9 +178,9 @@
 	}
 
 	/* if there is any #f, return it */
-	ARRAY_ELEMENT_FOREACH (operands, i, value) {
+	FOR_ARRAY_ELEMENT(operands, i, value) {
 		if (i == 0)
-			continue; /* ignore "and" itself */
+			continue;  /* ignore "and" itself */
 		if (value->type == CRAS_EXPR_VALUE_TYPE_BOOLEAN &&
 		    !value->u.boolean) {
 			value_set_boolean(result, 0);
@@ -197,9 +198,9 @@
 	int i;
 	struct cras_expr_value *value;
 
-	ARRAY_ELEMENT_FOREACH (operands, i, value) {
+	FOR_ARRAY_ELEMENT(operands, i, value) {
 		if (i == 0)
-			continue; /* ignore "or" itself */
+			continue;  /* ignore "or" itself */
 		if (value->type != CRAS_EXPR_VALUE_TYPE_BOOLEAN ||
 		    value->u.boolean) {
 			copy_value(result, value);
@@ -215,9 +216,9 @@
 	int i;
 	struct cras_expr_value *value, *prev;
 
-	ARRAY_ELEMENT_FOREACH (operands, i, value) {
+	FOR_ARRAY_ELEMENT(operands, i, value) {
 		if (i <= 1)
-			continue; /* ignore equal? and first operand */
+			continue;  /* ignore equal? and first operand */
 		/* compare with the previous operand */
 
 		prev = ARRAY_ELEMENT(operands, i - 1);
@@ -310,11 +311,11 @@
 	const char **key;
 	struct cras_expr_value *value;
 
-	ARRAY_ELEMENT_FOREACH (&env->keys, i, key) {
+	FOR_ARRAY_ELEMENT(&env->keys, i, key) {
 		free((char *)*key);
 	}
 
-	ARRAY_ELEMENT_FOREACH (&env->values, i, value) {
+	FOR_ARRAY_ELEMENT(&env->values, i, value) {
 		cras_expr_value_free(value);
 	}
 
@@ -329,7 +330,7 @@
 	struct cras_expr_value *value;
 
 	dumpf(d, "--- environment ---\n");
-	ARRAY_ELEMENT_FOREACH (&env->keys, i, key) {
+	FOR_ARRAY_ELEMENT(&env->keys, i, key) {
 		dumpf(d, " key=%s,", *key);
 		dumpf(d, " value=");
 		value = ARRAY_ELEMENT(&env->values, i);
@@ -420,7 +421,8 @@
 			(*str)++;
 			return new_boolean_literal(c == 't');
 		} else {
-			syslog(LOG_ERR, "unexpected char after #: '%c'", c);
+			syslog(LOG_ERR, "unexpected char after #: '%c'",
+			       c);
 		}
 		return NULL;
 	}
@@ -489,7 +491,8 @@
 		dumpf(d, "%*s(none)", indent, "");
 		break;
 	case CRAS_EXPR_VALUE_TYPE_BOOLEAN:
-		dumpf(d, "%*s%s", indent, "", value->u.boolean ? "#t" : "#f");
+		dumpf(d, "%*s%s", indent, "",
+		      value->u.boolean ? "#t" : "#f");
 		break;
 	case CRAS_EXPR_VALUE_TYPE_INT:
 		dumpf(d, "%*s%d", indent, "", value->u.integer);
@@ -519,11 +522,12 @@
 		dump_value(d, &expr->u.literal, indent + 2);
 		break;
 	case EXPR_TYPE_VARIABLE:
-		dumpf(d, "%*svariable (%s)", indent, "", expr->u.variable);
+		dumpf(d, "%*svariable (%s)", indent, "",
+		      expr->u.variable);
 		break;
 	case EXPR_TYPE_COMPOUND:
 		dumpf(d, "%*scompound", indent, "");
-		ARRAY_ELEMENT_FOREACH (&expr->u.children, i, sub) {
+		FOR_ARRAY_ELEMENT(&expr->u.children, i, sub) {
 			dump_one_expression(d, *sub, indent + 2);
 		}
 		break;
@@ -550,10 +554,11 @@
 	case EXPR_TYPE_VARIABLE:
 		free((char *)expr->u.variable);
 		break;
-	case EXPR_TYPE_COMPOUND: {
+	case EXPR_TYPE_COMPOUND:
+	{
 		int i;
 		struct cras_expr_expression **psub;
-		ARRAY_ELEMENT_FOREACH (&expr->u.children, i, psub) {
+		FOR_ARRAY_ELEMENT(&expr->u.children, i, psub) {
 			cras_expr_expression_free(*psub);
 		}
 		ARRAY_FREE(&expr->u.children);
@@ -575,9 +580,10 @@
 	case EXPR_TYPE_LITERAL:
 		copy_value(result, &expr->u.literal);
 		break;
-	case EXPR_TYPE_VARIABLE: {
-		struct cras_expr_value *value =
-			find_value(env, expr->u.variable);
+	case EXPR_TYPE_VARIABLE:
+	{
+		struct cras_expr_value *value = find_value(env,
+							   expr->u.variable);
 		if (value == NULL) {
 			syslog(LOG_ERR, "cannot find value for %s",
 			       expr->u.variable);
@@ -586,13 +592,14 @@
 		}
 		break;
 	}
-	case EXPR_TYPE_COMPOUND: {
+	case EXPR_TYPE_COMPOUND:
+	{
 		int i;
 		struct cras_expr_expression **psub;
 		cras_expr_value_array values = ARRAY_INIT;
 		struct cras_expr_value *value;
 
-		ARRAY_ELEMENT_FOREACH (&expr->u.children, i, psub) {
+		FOR_ARRAY_ELEMENT(&expr->u.children, i, psub) {
 			value = ARRAY_APPEND_ZERO(&values);
 			cras_expr_expression_eval(*psub, env, value);
 		}
@@ -608,7 +615,7 @@
 			syslog(LOG_ERR, "empty compound expression?");
 		}
 
-		ARRAY_ELEMENT_FOREACH (&values, i, value) {
+		FOR_ARRAY_ELEMENT(&values, i, value) {
 			cras_expr_value_free(value);
 		}
 
@@ -619,7 +626,8 @@
 }
 
 int cras_expr_expression_eval_int(struct cras_expr_expression *expr,
-				  struct cras_expr_env *env, int *integer)
+				  struct cras_expr_env *env,
+				  int *integer)
 {
 	int rc = 0;
 	struct cras_expr_value value = CRAS_EXPR_VALUE_INIT;
@@ -636,7 +644,8 @@
 }
 
 int cras_expr_expression_eval_boolean(struct cras_expr_expression *expr,
-				      struct cras_expr_env *env, char *boolean)
+				      struct cras_expr_env *env,
+				      char *boolean)
 {
 	int rc = 0;
 	struct cras_expr_value value = CRAS_EXPR_VALUE_INIT;
diff --git a/cras/src/server/cras_expr.h b/cras/src/server/cras_expr.h
index a26e98d..49eeb3b 100644
--- a/cras/src/server/cras_expr.h
+++ b/cras/src/server/cras_expr.h
@@ -38,9 +38,7 @@
 };
 
 /* initial value for the value type is zero */
-// clang-format off
 #define CRAS_EXPR_VALUE_INIT {}
-// clang-format on
 
 /* Expression */
 
@@ -72,9 +70,7 @@
 };
 
 /* initial value for the environment type is zero */
-// clang-format off
 #define CRAS_EXPR_ENV_INIT {}
-// clang-format on
 
 void cras_expr_env_install_builtins(struct cras_expr_env *env);
 void cras_expr_env_set_variable_boolean(struct cras_expr_env *env,
diff --git a/cras/src/server/cras_fmt_conv.c b/cras/src/server/cras_fmt_conv.c
index 35ab8ec..5b4bbeb 100644
--- a/cras/src/server/cras_fmt_conv.c
+++ b/cras/src/server/cras_fmt_conv.c
@@ -7,11 +7,8 @@
 #include <speex/speex_resampler.h>
 #include <sys/param.h>
 #include <syslog.h>
-#include <endian.h>
-#include <limits.h>
 
 #include "cras_fmt_conv.h"
-#include "cras_fmt_conv_ops.h"
 #include "cras_audio_format.h"
 #include "cras_util.h"
 #include "linear_resampler.h"
@@ -25,11 +22,13 @@
 #define STEREO_L 0
 #define STEREO_R 1
 
-typedef void (*sample_format_converter_t)(const uint8_t *in, size_t in_samples,
+typedef void (*sample_format_converter_t)(const uint8_t *in,
+					  size_t in_samples,
 					  uint8_t *out);
 typedef size_t (*channel_converter_t)(struct cras_fmt_conv *conv,
-				      const uint8_t *in, size_t in_frames,
-				      uint8_t *out);
+				      const int16_t *in,
+				      size_t in_frames,
+				      int16_t *out);
 
 /* Member data for the resampler. */
 struct cras_fmt_conv {
@@ -47,6 +46,345 @@
 	size_t num_converters; /* Incremented once for SRC, channel, format. */
 };
 
+/* Add and clip two s16 samples. */
+static int16_t s16_add_and_clip(int16_t a, int16_t b)
+{
+	int32_t sum;
+
+	sum = a + b;
+	sum = MAX(sum, -0x8000);
+	sum = MIN(sum, 0x7fff);
+	return (int16_t)sum;
+}
+
+/*
+ * Convert between different sample formats.
+ */
+
+/* Converts from U8 to S16. */
+static void convert_u8_to_s16le(const uint8_t *in, size_t in_samples,
+				uint8_t *out)
+{
+	size_t i;
+	uint16_t *_out = (uint16_t *)out;
+
+	for (i = 0; i < in_samples; i++, in++, _out++)
+		*_out = (uint16_t)((int16_t)*in - 0x80) << 8;
+}
+
+/* Converts from S24 to S16. */
+static void convert_s24le_to_s16le(const uint8_t *in, size_t in_samples,
+				   uint8_t *out)
+{
+	size_t i;
+	int32_t *_in = (int32_t *)in;
+	uint16_t *_out = (uint16_t *)out;
+
+	for (i = 0; i < in_samples; i++, _in++, _out++)
+		*_out = (int16_t)((*_in & 0x00ffffff) >> 8);
+}
+
+/* Converts from S32 to S16. */
+static void convert_s32le_to_s16le(const uint8_t *in, size_t in_samples,
+				   uint8_t *out)
+{
+	size_t i;
+	int32_t *_in = (int32_t *)in;
+	uint16_t *_out = (uint16_t *)out;
+
+	for (i = 0; i < in_samples; i++, _in++, _out++)
+		*_out = (int16_t)(*_in >> 16);
+}
+
+/* Converts from S24_3LE to S16. */
+static void convert_s243le_to_s16le(const uint8_t *in, size_t in_samples,
+				   uint8_t *out)
+{
+	/* find how to calculate in and out size, implement the conversion
+	 * between S24_3LE and S16 */
+
+	size_t i;
+	int8_t *_in = (int8_t *)in;
+	uint16_t *_out = (uint16_t *)out;
+
+	for (i = 0; i < in_samples; i++, _in += 3, _out++)
+		memcpy(_out, _in + 1, 2);
+}
+
+/* Converts from S16 to U8. */
+static void convert_s16le_to_u8(const uint8_t *in, size_t in_samples,
+				uint8_t *out)
+{
+	size_t i;
+	int16_t *_in = (int16_t *)in;
+
+	for (i = 0; i < in_samples; i++, _in++, out++)
+		*out = (uint8_t)(*_in >> 8) + 128;
+}
+
+/* Converts from S16 to S24. */
+static void convert_s16le_to_s24le(const uint8_t *in, size_t in_samples,
+				   uint8_t *out)
+{
+	size_t i;
+	int16_t *_in = (int16_t *)in;
+	uint32_t *_out = (uint32_t *)out;
+
+	for (i = 0; i < in_samples; i++, _in++, _out++)
+		*_out = ((uint32_t)(int32_t)*_in << 8);
+}
+
+/* Converts from S16 to S32. */
+static void convert_s16le_to_s32le(const uint8_t *in, size_t in_samples,
+				   uint8_t *out)
+{
+	size_t i;
+	int16_t *_in = (int16_t *)in;
+	uint32_t *_out = (uint32_t *)out;
+
+	for (i = 0; i < in_samples; i++, _in++, _out++)
+		*_out = ((uint32_t)(int32_t)*_in << 16);
+}
+
+/* Converts from S16 to S24_3LE. */
+static void convert_s16le_to_s243le(const uint8_t *in, size_t in_samples,
+				   uint8_t *out)
+{
+	size_t i;
+	int16_t *_in = (int16_t *)in;
+	uint8_t *_out = (uint8_t *)out;
+
+	for (i = 0; i < in_samples; i++, _in++, _out += 3) {
+		*_out = 0;
+		memcpy(_out + 1, _in, 2);
+	}
+}
+
+/*
+ * Convert between different channel numbers.
+ */
+
+/* Converts S16 mono to S16 stereo. The out buffer must be double the size of
+ * the input buffer. */
+static size_t s16_mono_to_stereo(struct cras_fmt_conv *conv,
+				const int16_t *in, size_t in_frames,
+				int16_t *out)
+{
+	size_t i;
+
+	for (i = 0; i < in_frames; i++) {
+		out[2 * i] = in[i];
+		out[2 * i + 1] = in[i];
+	}
+	return in_frames;
+}
+
+/* Converts S16 Stereo to S16 mono.  The output buffer only need be big enough
+ * for mono samples. */
+static size_t s16_stereo_to_mono(struct cras_fmt_conv *conv,
+				const int16_t *in, size_t in_frames,
+				int16_t *out)
+{
+	size_t i;
+
+	for (i = 0; i < in_frames; i++)
+		out[i] = s16_add_and_clip(in[2 * i], in[2 * i + 1]);
+	return in_frames;
+}
+
+/* Converts S16 mono to 5.1 surround. Fit mono to front center of the
+ * output, or split to front left/right if front center is missing
+ * from the output channel layout.
+ */
+static size_t s16_mono_to_51(struct cras_fmt_conv *conv,
+			     const int16_t *in, size_t in_frames,
+			     int16_t *out)
+{
+	size_t i, left, right, center;
+
+	memset(out, 0, sizeof(*out) * 6 * in_frames);
+	left = conv->out_fmt.channel_layout[CRAS_CH_FL];
+	right = conv->out_fmt.channel_layout[CRAS_CH_FR];
+	center = conv->out_fmt.channel_layout[CRAS_CH_FC];
+
+	if (center != -1)
+		for (i = 0; i < in_frames; i++)
+			out[6 * i + center] = in[i];
+	else if (left != -1 && right != -1)
+		for (i = 0; i < in_frames; i++) {
+			out[6 * i + right] = in[i] / 2;
+			out[6 * 1 + left] = in[i] / 2;
+		}
+	else
+		/* Select the first channel to convert to as the
+		 * default behavior.
+		 */
+		for (i = 0; i < in_frames; i++)
+			out[6 * i] = in[i];
+
+	return in_frames;
+}
+
+/* Converts S16 stereo to 5.1 surround. Fit the left/right of input
+ * to the front left/right of output respectively and fill others
+ * with zero. If any of the front left/right is missed from the output
+ * channel layout, mix to front center.
+ */
+static size_t s16_stereo_to_51(struct cras_fmt_conv *conv,
+			       const int16_t *in, size_t in_frames,
+			       int16_t *out)
+{
+	size_t i, left, right, center;
+
+	memset(out, 0, sizeof(*out) * 6 * in_frames);
+	left = conv->out_fmt.channel_layout[CRAS_CH_FL];
+	right = conv->out_fmt.channel_layout[CRAS_CH_FR];
+	center = conv->out_fmt.channel_layout[CRAS_CH_FC];
+
+	if (left != -1 && right != -1)
+		for (i = 0; i < in_frames; i++) {
+			out[6 * i + left] = in[2 * i];
+			out[6 * i + right] = in[2 * i + 1];
+		}
+	else if (center != -1)
+		for (i = 0; i < in_frames; i++)
+			out[6 * i + center] = s16_add_and_clip(
+					in[2 * i], in[2 * i + 1]);
+	else
+		/* Select the first two channels to convert to as the
+		 * default behavior.
+		 */
+		for (i = 0; i < in_frames; i++) {
+			out[6 * i] = in[2 * i];
+			out[6 * i + 1] = in[2 * i + 1];
+		}
+
+	return in_frames;
+}
+
+/* Converts S16 5.1 to S16 stereo. The out buffer can have room for just
+ * stereo samples. This convert function is used as the default behavior
+ * when channel layout is not set from the client side. */
+static size_t s16_51_to_stereo(struct cras_fmt_conv *conv,
+			       const int16_t *in, size_t in_frames,
+			       int16_t *out)
+{
+	static const unsigned int left_idx = 0;
+	static const unsigned int right_idx = 1;
+	/* static const unsigned int left_surround_idx = 2; */
+	/* static const unsigned int right_surround_idx = 3; */
+	static const unsigned int center_idx = 4;
+	/* static const unsigned int lfe_idx = 5; */
+	size_t i;
+
+	for (i = 0; i < in_frames; i++) {
+		unsigned int half_center;
+
+		half_center = in[6 * i + center_idx] / 2;
+		out[2 * i + left_idx] = s16_add_and_clip(in[6 * i + left_idx],
+							 half_center);
+		out[2 * i + right_idx] = s16_add_and_clip(in[6 * i + right_idx],
+							  half_center);
+	}
+	return in_frames;
+}
+
+/* Converts S16 stereo to quad (front L/R, rear L/R). Fit left/right of input
+ * to the front left/right of output respectively and fill others
+ * with zero.
+ */
+static size_t s16_stereo_to_quad(struct cras_fmt_conv *conv,
+				 const int16_t *in, size_t in_frames,
+				 int16_t *out)
+{
+	size_t i, front_left, front_right, rear_left, rear_right;
+
+	front_left = conv->out_fmt.channel_layout[CRAS_CH_FL];
+	front_right = conv->out_fmt.channel_layout[CRAS_CH_FR];
+	rear_left = conv->out_fmt.channel_layout[CRAS_CH_RL];
+	rear_right = conv->out_fmt.channel_layout[CRAS_CH_RR];
+
+	if (front_left != -1 && front_right != -1 &&
+	    rear_left != -1 && rear_right != -1)
+		for (i = 0; i < in_frames; i++) {
+			out[4 * i + front_left] = in[2 * i];
+			out[4 * i + front_right] = in[2 * i + 1];
+			out[4 * i + rear_left] = in[2 * i];
+			out[4 * i + rear_right] = in[2 * i + 1];
+		}
+	else
+		/* Select the first four channels to convert to as the
+		 * default behavior.
+		 */
+		for (i = 0; i < in_frames; i++) {
+			out[4 * i] = in[2 * i];
+			out[4 * i + 1] = in[2 * i + 1];
+			out[4 * i + 2] = in[2 * i];
+			out[4 * i + 3] = in[2 * i + 1];
+		}
+
+	return in_frames;
+}
+
+/* Converts S16 quad (front L/R, rear L/R) to S16 stereo. The out buffer
+ * can have room for just stereo samples.
+ */
+static size_t s16_quad_to_stereo(struct cras_fmt_conv *conv,
+			       const int16_t *in, size_t in_frames,
+			       int16_t *out)
+{
+	size_t i;
+	unsigned int left_idx =
+			conv->in_fmt.channel_layout[CRAS_CH_FL];
+	unsigned int right_idx =
+			conv->in_fmt.channel_layout[CRAS_CH_FR];
+	unsigned int left_rear_idx =
+			conv->in_fmt.channel_layout[CRAS_CH_RL];
+	unsigned int right_rear_idx =
+			conv->in_fmt.channel_layout[CRAS_CH_RR];
+
+	if (left_idx == -1 || right_idx == -1 ||
+	    left_rear_idx == -1 || right_rear_idx == -1) {
+		left_idx = 0;
+		right_idx = 1;
+		left_rear_idx = 2;
+		right_rear_idx = 3;
+	}
+
+	for (i = 0; i < in_frames; i++) {
+		out[2 * i] = s16_add_and_clip(
+		    in[4 * i + left_idx],
+		    in[4 * i + left_rear_idx] / 4);
+		out[2 * i + 1] = s16_add_and_clip(
+		    in[4 * i + right_idx],
+		    in[4 * i + right_rear_idx] / 4);
+	}
+	return in_frames;
+}
+
+/* Converts S16 N channels to S16 M channels.  The out buffer must have room for
+ * M channel. This convert function is used as the default behavior when channel
+ * layout is not set from the client side. */
+static size_t s16_default_all_to_all(struct cras_fmt_conv *conv,
+				     const int16_t *in, size_t in_frames,
+				     int16_t *out)
+{
+	unsigned int num_in_ch = conv->in_fmt.num_channels;
+	unsigned int num_out_ch = conv->out_fmt.num_channels;
+	unsigned int in_ch, out_ch, i;
+
+	memset(out, 0, in_frames * cras_get_format_bytes(&conv->out_fmt));
+	for (out_ch = 0; out_ch < num_out_ch; out_ch++) {
+		for (in_ch = 0; in_ch < num_in_ch; in_ch++) {
+			for (i = 0; i < in_frames; i++) {
+				out[out_ch + i * num_out_ch] +=
+					in[in_ch + i * num_in_ch] / num_in_ch;
+			}
+		}
+	}
+	return in_frames;
+}
+
 static int is_channel_layout_equal(const struct cras_audio_format *a,
 				   const struct cras_audio_format *b)
 {
@@ -58,16 +396,56 @@
 	return 1;
 }
 
+/* Multiplies buffer vector with coefficient vector. */
+static int16_t multiply_buf_with_coef(float *coef,
+				      const int16_t *buf,
+				      size_t size)
+{
+	int32_t sum = 0;
+	int i;
+
+	for (i = 0; i < size; i++)
+		sum += coef[i] * buf[i];
+	sum = MAX(sum, -0x8000);
+	sum = MIN(sum, 0x7fff);
+	return (int16_t)sum;
+}
+
 static void normalize_buf(float *buf, size_t size)
 {
 	int i;
 	float squre_sum = 0.0;
 	for (i = 0; i < size; i++)
 		squre_sum += buf[i] * buf[i];
-	for (i = 0; i < size; i++)
+	for (i = 0; i < size; i ++)
 		buf[i] /= squre_sum;
 }
 
+/* Converts channels based on the channel conversion
+ * coefficient matrix.
+ */
+static size_t convert_channels(struct cras_fmt_conv *conv,
+			       const int16_t *in,
+			       size_t in_frames,
+			       int16_t *out)
+{
+	unsigned i, fr;
+	unsigned in_idx = 0;
+	unsigned out_idx = 0;
+
+	for (fr = 0; fr < in_frames; fr++) {
+		for (i = 0; i < conv->out_fmt.num_channels; i++)
+			out[out_idx + i] = multiply_buf_with_coef(
+					conv->ch_conv_mtx[i],
+					&in[in_idx],
+					conv->in_fmt.num_channels);
+		in_idx += conv->in_fmt.num_channels;
+		out_idx += conv->out_fmt.num_channels;
+	}
+
+	return in_frames;
+}
+
 /* Populates the down mix matrix by rules:
  * 1. Front/side left(right) channel will mix to left(right) of
  *    full scale.
@@ -107,119 +485,6 @@
 	normalize_buf(mtx[STEREO_R], 6);
 }
 
-static int is_supported_format(const struct cras_audio_format *fmt)
-{
-	if (!fmt)
-		return 0;
-
-	switch (fmt->format) {
-	case SND_PCM_FORMAT_U8:
-	case SND_PCM_FORMAT_S16_LE:
-	case SND_PCM_FORMAT_S24_3LE:
-	case SND_PCM_FORMAT_S24_LE:
-	case SND_PCM_FORMAT_S32_LE:
-		return 1;
-	default:
-		return 0;
-	}
-}
-
-static size_t mono_to_stereo(struct cras_fmt_conv *conv, const uint8_t *in,
-			     size_t in_frames, uint8_t *out)
-{
-	return s16_mono_to_stereo(in, in_frames, out);
-}
-
-static size_t stereo_to_mono(struct cras_fmt_conv *conv, const uint8_t *in,
-			     size_t in_frames, uint8_t *out)
-{
-	return s16_stereo_to_mono(in, in_frames, out);
-}
-
-static size_t mono_to_51(struct cras_fmt_conv *conv, const uint8_t *in,
-			 size_t in_frames, uint8_t *out)
-{
-	size_t left, right, center;
-
-	left = conv->out_fmt.channel_layout[CRAS_CH_FL];
-	right = conv->out_fmt.channel_layout[CRAS_CH_FR];
-	center = conv->out_fmt.channel_layout[CRAS_CH_FC];
-
-	return s16_mono_to_51(left, right, center, in, in_frames, out);
-}
-
-static size_t stereo_to_51(struct cras_fmt_conv *conv, const uint8_t *in,
-			   size_t in_frames, uint8_t *out)
-{
-	size_t left, right, center;
-
-	left = conv->out_fmt.channel_layout[CRAS_CH_FL];
-	right = conv->out_fmt.channel_layout[CRAS_CH_FR];
-	center = conv->out_fmt.channel_layout[CRAS_CH_FC];
-
-	return s16_stereo_to_51(left, right, center, in, in_frames, out);
-}
-
-static size_t _51_to_stereo(struct cras_fmt_conv *conv, const uint8_t *in,
-			    size_t in_frames, uint8_t *out)
-{
-	return s16_51_to_stereo(in, in_frames, out);
-}
-
-static size_t stereo_to_quad(struct cras_fmt_conv *conv, const uint8_t *in,
-			     size_t in_frames, uint8_t *out)
-{
-	size_t front_left, front_right, rear_left, rear_right;
-
-	front_left = conv->out_fmt.channel_layout[CRAS_CH_FL];
-	front_right = conv->out_fmt.channel_layout[CRAS_CH_FR];
-	rear_left = conv->out_fmt.channel_layout[CRAS_CH_RL];
-	rear_right = conv->out_fmt.channel_layout[CRAS_CH_RR];
-
-	return s16_stereo_to_quad(front_left, front_right, rear_left,
-				  rear_right, in, in_frames, out);
-}
-
-static size_t quad_to_stereo(struct cras_fmt_conv *conv, const uint8_t *in,
-			     size_t in_frames, uint8_t *out)
-{
-	size_t front_left, front_right, rear_left, rear_right;
-
-	front_left = conv->in_fmt.channel_layout[CRAS_CH_FL];
-	front_right = conv->in_fmt.channel_layout[CRAS_CH_FR];
-	rear_left = conv->in_fmt.channel_layout[CRAS_CH_RL];
-	rear_right = conv->in_fmt.channel_layout[CRAS_CH_RR];
-
-	return s16_quad_to_stereo(front_left, front_right, rear_left,
-				  rear_right, in, in_frames, out);
-}
-
-static size_t default_all_to_all(struct cras_fmt_conv *conv, const uint8_t *in,
-				 size_t in_frames, uint8_t *out)
-{
-	size_t num_in_ch, num_out_ch;
-
-	num_in_ch = conv->in_fmt.num_channels;
-	num_out_ch = conv->out_fmt.num_channels;
-
-	return s16_default_all_to_all(&conv->out_fmt, num_in_ch, num_out_ch, in,
-				      in_frames, out);
-}
-
-static size_t convert_channels(struct cras_fmt_conv *conv, const uint8_t *in,
-			       size_t in_frames, uint8_t *out)
-{
-	float **ch_conv_mtx;
-	size_t num_in_ch, num_out_ch;
-
-	ch_conv_mtx = conv->ch_conv_mtx;
-	num_in_ch = conv->in_fmt.num_channels;
-	num_out_ch = conv->out_fmt.num_channels;
-
-	return s16_convert_channels(ch_conv_mtx, num_in_ch, num_out_ch, in,
-				    in_frames, out);
-}
-
 /*
  * Exported interface
  */
@@ -241,26 +506,14 @@
 	conv->tmp_buf_frames = max_frames;
 	conv->pre_linear_resample = pre_linear_resample;
 
-	if (!is_supported_format(in)) {
-		syslog(LOG_ERR, "Invalid input format %d", in->format);
-		cras_fmt_conv_destroy(&conv);
-		return NULL;
-	}
-
-	if (!is_supported_format(out)) {
-		syslog(LOG_ERR, "Invalid output format %d", out->format);
-		cras_fmt_conv_destroy(&conv);
-		return NULL;
-	}
-
 	/* Set up sample format conversion. */
 	/* TODO(dgreid) - modify channel and sample rate conversion so
 	 * converting to s16 isnt necessary. */
 	if (in->format != SND_PCM_FORMAT_S16_LE) {
 		conv->num_converters++;
-		syslog(LOG_DEBUG, "Convert from format %d to %d.", in->format,
-		       out->format);
-		switch (in->format) {
+		syslog(LOG_DEBUG, "Convert from format %d to %d.",
+		       in->format, out->format);
+		switch(in->format) {
 		case SND_PCM_FORMAT_U8:
 			conv->in_format_converter = convert_u8_to_s16le;
 			break;
@@ -274,14 +527,15 @@
 			conv->in_format_converter = convert_s243le_to_s16le;
 			break;
 		default:
-			syslog(LOG_ERR, "Should never reachable");
-			break;
+			syslog(LOG_WARNING, "Invalid format %d", in->format);
+			cras_fmt_conv_destroy(&conv);
+			return NULL;
 		}
 	}
 	if (out->format != SND_PCM_FORMAT_S16_LE) {
 		conv->num_converters++;
-		syslog(LOG_DEBUG, "Convert from format %d to %d.", in->format,
-		       out->format);
+		syslog(LOG_DEBUG, "Convert from format %d to %d.",
+		       in->format, out->format);
 		switch (out->format) {
 		case SND_PCM_FORMAT_U8:
 			conv->out_format_converter = convert_s16le_to_u8;
@@ -296,8 +550,9 @@
 			conv->out_format_converter = convert_s16le_to_s243le;
 			break;
 		default:
-			syslog(LOG_ERR, "Should never reachable");
-			break;
+			syslog(LOG_WARNING, "Invalid format %d", out->format);
+			cras_fmt_conv_destroy(&conv);
+			return NULL;
 		}
 	}
 
@@ -310,17 +565,17 @@
 		/* Populate the conversion matrix base on in/out channel count
 		 * and layout. */
 		if (in->num_channels == 1 && out->num_channels == 2) {
-			conv->channel_converter = mono_to_stereo;
+			conv->channel_converter = s16_mono_to_stereo;
 		} else if (in->num_channels == 1 && out->num_channels == 6) {
-			conv->channel_converter = mono_to_51;
+			conv->channel_converter = s16_mono_to_51;
 		} else if (in->num_channels == 2 && out->num_channels == 1) {
-			conv->channel_converter = stereo_to_mono;
+			conv->channel_converter = s16_stereo_to_mono;
 		} else if (in->num_channels == 2 && out->num_channels == 4) {
-			conv->channel_converter = stereo_to_quad;
+			conv->channel_converter = s16_stereo_to_quad;
 		} else if (in->num_channels == 4 && out->num_channels == 2) {
-			conv->channel_converter = quad_to_stereo;
+			conv->channel_converter = s16_quad_to_stereo;
 		} else if (in->num_channels == 2 && out->num_channels == 6) {
-			conv->channel_converter = stereo_to_51;
+			conv->channel_converter = s16_stereo_to_51;
 		} else if (in->num_channels == 6 && out->num_channels == 2) {
 			int in_channel_layout_set = 0;
 
@@ -333,8 +588,7 @@
 			 * channel layout is set, or default to use existing
 			 * converter to downmix to stereo */
 			if (in_channel_layout_set) {
-				conv->ch_conv_mtx =
-					cras_channel_conv_matrix_alloc(
+				conv->ch_conv_mtx = cras_channel_conv_matrix_alloc(
 						in->num_channels,
 						out->num_channels);
 				if (conv->ch_conv_mtx == NULL) {
@@ -343,23 +597,23 @@
 				}
 				conv->channel_converter = convert_channels;
 				surround51_to_stereo_downmix_mtx(
-					conv->ch_conv_mtx,
-					conv->in_fmt.channel_layout);
+						conv->ch_conv_mtx,
+						conv->in_fmt.channel_layout);
 			} else {
-				conv->channel_converter = _51_to_stereo;
+				conv->channel_converter = s16_51_to_stereo;
 			}
 		} else {
 			syslog(LOG_WARNING,
 			       "Using default channel map for %zu to %zu",
 			       in->num_channels, out->num_channels);
-			conv->channel_converter = default_all_to_all;
+			conv->channel_converter = s16_default_all_to_all;
 		}
-	} else if (in->num_channels > 2 && !is_channel_layout_equal(in, out)) {
+	} else if (in->num_channels > 2 &&
+		   !is_channel_layout_equal(in, out)){
 		conv->num_converters++;
 		conv->ch_conv_mtx = cras_channel_conv_matrix_create(in, out);
 		if (conv->ch_conv_mtx == NULL) {
-			syslog(LOG_ERR,
-			       "Failed to create channel conversion matrix");
+			syslog(LOG_ERR, "Failed to create channel conversion matrix");
 			cras_fmt_conv_destroy(&conv);
 			return NULL;
 		}
@@ -368,34 +622,31 @@
 	/* Set up sample rate conversion. */
 	if (in->frame_rate != out->frame_rate) {
 		conv->num_converters++;
-		syslog(LOG_DEBUG, "Convert from %zu to %zu Hz.", in->frame_rate,
-		       out->frame_rate);
-		conv->speex_state =
-			speex_resampler_init(out->num_channels, in->frame_rate,
-					     out->frame_rate,
-					     SPEEX_QUALITY_LEVEL, &rc);
+		syslog(LOG_DEBUG, "Convert from %zu to %zu Hz.",
+		       in->frame_rate, out->frame_rate);
+		conv->speex_state = speex_resampler_init(out->num_channels,
+							 in->frame_rate,
+							 out->frame_rate,
+							 SPEEX_QUALITY_LEVEL,
+							 &rc);
 		if (conv->speex_state == NULL) {
 			syslog(LOG_ERR, "Fail to create speex:%zu %zu %zu %d",
-			       out->num_channels, in->frame_rate,
-			       out->frame_rate, rc);
+			       out->num_channels,
+			       in->frame_rate,
+			       out->frame_rate,
+			       rc);
 			cras_fmt_conv_destroy(&conv);
 			return NULL;
 		}
 	}
 
-	/*
-	 * Set up linear resampler.
-	 *
-	 * Note: intended to give both src_rate and dst_rate the same value
-	 * (i.e. out->frame_rate).  They will be updated in runtime in
-	 * update_estimated_rate() when the audio thread wants to adjust the
-	 * rate for inaccurate device consumption rate.
-	 */
+	/* Set up linear resampler. */
 	conv->num_converters++;
-	conv->resampler =
-		linear_resampler_create(out->num_channels,
-					cras_get_format_bytes(out),
-					out->frame_rate, out->frame_rate);
+	conv->resampler = linear_resampler_create(
+			out->num_channels,
+			cras_get_format_bytes(out),
+			out->frame_rate,
+			out->frame_rate);
 	if (conv->resampler == NULL) {
 		syslog(LOG_ERR, "Fail to create linear resampler");
 		cras_fmt_conv_destroy(&conv);
@@ -406,7 +657,8 @@
 	 * directly into the output. */
 	for (i = 0; i < conv->num_converters - 1; i++) {
 		conv->tmp_bufs[i] = malloc(
-			max_frames * 4 * /* width in bytes largest format. */
+			max_frames *
+			4 * /* width in bytes largest format. */
 			MAX(in->num_channels, out->num_channels));
 		if (conv->tmp_bufs[i] == NULL) {
 			cras_fmt_conv_destroy(&conv);
@@ -437,8 +689,9 @@
 	*convp = NULL;
 }
 
-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)
 {
 	struct cras_fmt_conv *conv;
 	unsigned out_ch, in_ch;
@@ -449,8 +702,8 @@
 	conv->in_fmt.num_channels = num_channels;
 	conv->out_fmt.num_channels = num_channels;
 
-	conv->ch_conv_mtx =
-		cras_channel_conv_matrix_alloc(num_channels, num_channels);
+	conv->ch_conv_mtx = cras_channel_conv_matrix_alloc(num_channels,
+							   num_channels);
 	/* Convert the coeffiencnt array to conversion matrix. */
 	for (out_ch = 0; out_ch < num_channels; out_ch++)
 		for (in_ch = 0; in_ch < num_channels; in_ch++)
@@ -465,27 +718,22 @@
 
 void cras_channel_remix_convert(struct cras_fmt_conv *conv,
 				const struct cras_audio_format *fmt,
-				uint8_t *in_buf, size_t nframes)
+				uint8_t *in_buf,
+				size_t nframes)
 {
 	unsigned ch, fr;
 	int16_t *tmp = (int16_t *)conv->tmp_bufs[0];
 	int16_t *buf = (int16_t *)in_buf;
 
-	/*
-	 * Skip remix for non S16_LE format.
-	 * TODO(tzungbi): support 24 bits remix convert.
-	 */
-	if (fmt->format != SND_PCM_FORMAT_S16_LE)
-		return;
-
 	/* Do remix only when input buffer has the same number of channels. */
 	if (fmt->num_channels != conv->in_fmt.num_channels)
 		return;
 
 	for (fr = 0; fr < nframes; fr++) {
 		for (ch = 0; ch < conv->in_fmt.num_channels; ch++)
-			tmp[ch] = s16_multiply_buf_with_coef(
-				conv->ch_conv_mtx[ch], buf,
+			tmp[ch] = multiply_buf_with_coef(
+				conv->ch_conv_mtx[ch],
+				buf,
 				conv->in_fmt.num_channels);
 		for (ch = 0; ch < conv->in_fmt.num_channels; ch++)
 			buf[ch] = tmp[ch];
@@ -493,14 +741,14 @@
 	}
 }
 
-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 &conv->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 &conv->out_fmt;
 }
@@ -512,13 +760,16 @@
 		return in_frames;
 
 	if (conv->pre_linear_resample)
-		in_frames = linear_resampler_in_frames_to_out(conv->resampler,
-							      in_frames);
-	in_frames = cras_frames_at_rate(conv->in_fmt.frame_rate, in_frames,
-					conv->out_fmt.frame_rate);
+		in_frames = linear_resampler_in_frames_to_out(
+				conv->resampler,
+				in_frames);
+	in_frames = cras_frames_at_rate(conv->in_fmt.frame_rate,
+				   in_frames,
+				   conv->out_fmt.frame_rate);
 	if (!conv->pre_linear_resample)
-		in_frames = linear_resampler_in_frames_to_out(conv->resampler,
-							      in_frames);
+		in_frames = linear_resampler_in_frames_to_out(
+				conv->resampler,
+				in_frames);
 	return in_frames;
 }
 
@@ -528,25 +779,31 @@
 	if (!conv)
 		return out_frames;
 	if (!conv->pre_linear_resample)
-		out_frames = linear_resampler_out_frames_to_in(conv->resampler,
-							       out_frames);
-	out_frames = cras_frames_at_rate(conv->out_fmt.frame_rate, out_frames,
-					 conv->in_fmt.frame_rate);
+		out_frames = linear_resampler_out_frames_to_in(
+				conv->resampler,
+				out_frames);
+	out_frames = cras_frames_at_rate(conv->out_fmt.frame_rate,
+				   out_frames,
+				   conv->in_fmt.frame_rate);
 	if (conv->pre_linear_resample)
-		out_frames = linear_resampler_out_frames_to_in(conv->resampler,
-							       out_frames);
+		out_frames = linear_resampler_out_frames_to_in(
+				conv->resampler,
+				out_frames);
 	return out_frames;
 }
 
 void cras_fmt_conv_set_linear_resample_rates(struct cras_fmt_conv *conv,
-					     float from, float to)
+					     float from,
+					     float to)
 {
 	linear_resampler_set_rates(conv->resampler, from, to);
 }
 
 size_t cras_fmt_conv_convert_frames(struct cras_fmt_conv *conv,
-				    const uint8_t *in_buf, uint8_t *out_buf,
-				    unsigned int *in_frames, size_t out_frames)
+				    const uint8_t *in_buf,
+				    uint8_t *out_buf,
+				    unsigned int *in_frames,
+				    size_t out_frames)
 {
 	uint32_t fr_in, fr_out;
 	uint8_t *buffers[MAX_NUM_CONVERTERS + 1]; /* converters + out buffer. */
@@ -569,8 +826,10 @@
 	if (conv->speex_state == NULL) {
 		fr_in = MIN(*in_frames, out_frames);
 		if (out_frames < *in_frames && !logged_frames_dont_fit) {
-			syslog(LOG_INFO, "fmt_conv: %u to %zu no SRC.",
-			       *in_frames, out_frames);
+			syslog(LOG_INFO,
+			       "fmt_conv: %u to %zu no SRC.",
+			       *in_frames,
+			       out_frames);
 			logged_frames_dont_fit = 1;
 		}
 	} else {
@@ -601,8 +860,8 @@
 		 */
 		if (conv->speex_state != NULL) {
 			resample_limit = resample_limit *
-					 conv->in_fmt.frame_rate /
-					 conv->out_fmt.frame_rate;
+					conv->in_fmt.frame_rate /
+					conv->out_fmt.frame_rate;
 			/*
 			 * However if the limit frames count is less than
 			 * |out_rate / in_rate|, the final limit value could be
@@ -615,8 +874,11 @@
 
 		resample_limit = MIN(resample_limit, conv->tmp_buf_frames);
 		fr_in = linear_resampler_resample(
-			conv->resampler, buffers[buf_idx], &linear_resample_fr,
-			buffers[buf_idx + 1], resample_limit);
+				conv->resampler,
+				buffers[buf_idx],
+				&linear_resample_fr,
+				buffers[buf_idx + 1],
+				resample_limit);
 		buf_idx++;
 	}
 
@@ -630,8 +892,10 @@
 
 	/* Then channel conversion. */
 	if (conv->channel_converter != NULL) {
-		conv->channel_converter(conv, buffers[buf_idx], fr_in,
-					buffers[buf_idx + 1]);
+		conv->channel_converter(conv,
+					(int16_t *)buffers[buf_idx],
+					fr_in,
+					(int16_t *)buffers[buf_idx + 1]);
 		buf_idx++;
 	}
 
@@ -641,20 +905,25 @@
 
 		if (post_linear_resample)
 			out_limit = linear_resampler_out_frames_to_in(
-				conv->resampler, out_limit);
-		fr_out = cras_frames_at_rate(conv->in_fmt.frame_rate, fr_in,
+					conv->resampler, out_limit);
+		fr_out = cras_frames_at_rate(conv->in_fmt.frame_rate,
+					     fr_in,
 					     conv->out_fmt.frame_rate);
 		if (fr_out > out_frames + 1 && !logged_frames_dont_fit) {
 			syslog(LOG_INFO,
 			       "fmt_conv: put %u frames in %zu sized buffer",
-			       fr_out, out_frames);
+			       fr_out,
+			       out_frames);
 			logged_frames_dont_fit = 1;
 		}
 		/* limit frames to the output size. */
 		fr_out = MIN(fr_out, out_limit);
 		speex_resampler_process_interleaved_int(
-			conv->speex_state, (int16_t *)buffers[buf_idx], &fr_in,
-			(int16_t *)buffers[buf_idx + 1], &fr_out);
+				conv->speex_state,
+				(int16_t *)buffers[buf_idx],
+				&fr_in,
+				(int16_t *)buffers[buf_idx + 1],
+				&fr_out);
 		buf_idx++;
 	}
 
@@ -662,8 +931,11 @@
 		linear_resample_fr = fr_out;
 		unsigned resample_limit = MIN(conv->tmp_buf_frames, out_frames);
 		fr_out = linear_resampler_resample(
-			conv->resampler, buffers[buf_idx], &linear_resample_fr,
-			buffers[buf_idx + 1], resample_limit);
+				conv->resampler,
+				buffers[buf_idx],
+				&linear_resample_fr,
+				buffers[buf_idx + 1],
+				resample_limit);
 		buf_idx++;
 	}
 
@@ -726,7 +998,8 @@
 	       "format convert: from:%d %zu %zu target: %d %zu %zu "
 	       "frames = %u",
 	       from->format, from->frame_rate, from->num_channels,
-	       target.format, target.frame_rate, target.num_channels, frames);
+	       target.format, target.frame_rate, target.num_channels,
+	       frames);
 	*conv = cras_fmt_conv_create(from, &target, frames,
 				     (dir == CRAS_STREAM_INPUT));
 	if (!*conv) {
diff --git a/cras/src/server/cras_fmt_conv.h b/cras/src/server/cras_fmt_conv.h
index 12c0c16..0f6042a 100644
--- a/cras/src/server/cras_fmt_conv.h
+++ b/cras/src/server/cras_fmt_conv.h
@@ -32,8 +32,9 @@
  *    coefficient - Float array of length N * N representing the conversion
  *        matrix, where matrix[i][j] corresponds to coefficient[i * N + j]
  */
-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);
 
 /* Converts nframes of sample from in_buf, using given remix converter.
  * Args:
@@ -44,15 +45,16 @@
  */
 void cras_channel_remix_convert(struct cras_fmt_conv *conv,
 				const struct cras_audio_format *fmt,
-				uint8_t *in_buf, size_t nframes);
+				uint8_t *in_buf,
+				size_t nframes);
 
 /* Get the input format of the converter. */
-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);
 
 /* Get the output format of the converter. */
-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);
 
 /* Get the number of output frames that will result from converting in_frames */
 size_t cras_fmt_conv_in_frames_to_out(struct cras_fmt_conv *conv,
@@ -62,7 +64,8 @@
 				      size_t out_frames);
 /* Sets the input and output rate to the linear resampler. */
 void cras_fmt_conv_set_linear_resample_rates(struct cras_fmt_conv *conv,
-					     float from, float to);
+					     float from,
+					     float to);
 /* Converts in_frames samples from in_buf, storing the results in out_buf.
  * Args:
  *    conv - The format converter returned from cras_fmt_conv_create().
@@ -75,8 +78,10 @@
  *      frames, this can be checked with cras_fmt_conv_in_frames_to_out().
  * Return number of frames put in out_buf. */
 size_t cras_fmt_conv_convert_frames(struct cras_fmt_conv *conv,
-				    const uint8_t *in_buf, uint8_t *out_buf,
-				    unsigned int *in_frames, size_t out_frames);
+				    const uint8_t *in_buf,
+				    uint8_t *out_buf,
+				    unsigned int *in_frames,
+				    size_t out_frames);
 
 /* Checks if format conversion is needed for a fmt converter.
  * Args:
diff --git a/cras/src/server/cras_fmt_conv_ops.c b/cras/src/server/cras_fmt_conv_ops.c
deleted file mode 100644
index bf479c9..0000000
--- a/cras/src/server/cras_fmt_conv_ops.c
+++ /dev/null
@@ -1,386 +0,0 @@
-/* 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 <limits.h>
-#include <string.h>
-
-#include "cras_fmt_conv_ops.h"
-
-#define MAX(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;                                             \
-	})
-
-/*
- * Add and clip.
- */
-static int16_t s16_add_and_clip(int16_t a, int16_t b)
-{
-	int32_t sum;
-
-	a = htole16(a);
-	b = htole16(b);
-	sum = (int32_t)a + (int32_t)b;
-	sum = MAX(sum, SHRT_MIN);
-	sum = MIN(sum, SHRT_MAX);
-	return (int16_t)le16toh(sum);
-}
-
-/*
- * Format converter.
- */
-void convert_u8_to_s16le(const uint8_t *in, size_t in_samples, uint8_t *out)
-{
-	size_t i;
-	uint16_t *_out = (uint16_t *)out;
-
-	for (i = 0; i < in_samples; i++, in++, _out++)
-		*_out = (uint16_t)((int16_t)*in - 0x80) << 8;
-}
-
-void convert_s243le_to_s16le(const uint8_t *in, size_t in_samples, uint8_t *out)
-{
-	/* find how to calculate in and out size, implement the conversion
-	 * between S24_3LE and S16 */
-
-	size_t i;
-	int8_t *_in = (int8_t *)in;
-	uint16_t *_out = (uint16_t *)out;
-
-	for (i = 0; i < in_samples; i++, _in += 3, _out++)
-		memcpy(_out, _in + 1, 2);
-}
-
-void convert_s24le_to_s16le(const uint8_t *in, size_t in_samples, uint8_t *out)
-{
-	size_t i;
-	int32_t *_in = (int32_t *)in;
-	uint16_t *_out = (uint16_t *)out;
-
-	for (i = 0; i < in_samples; i++, _in++, _out++)
-		*_out = (int16_t)((*_in & 0x00ffffff) >> 8);
-}
-
-void convert_s32le_to_s16le(const uint8_t *in, size_t in_samples, uint8_t *out)
-{
-	size_t i;
-	int32_t *_in = (int32_t *)in;
-	uint16_t *_out = (uint16_t *)out;
-
-	for (i = 0; i < in_samples; i++, _in++, _out++)
-		*_out = (int16_t)(*_in >> 16);
-}
-
-void convert_s16le_to_u8(const uint8_t *in, size_t in_samples, uint8_t *out)
-{
-	size_t i;
-	int16_t *_in = (int16_t *)in;
-
-	for (i = 0; i < in_samples; i++, _in++, out++)
-		*out = (uint8_t)(*_in >> 8) + 128;
-}
-
-void convert_s16le_to_s243le(const uint8_t *in, size_t in_samples, uint8_t *out)
-{
-	size_t i;
-	int16_t *_in = (int16_t *)in;
-	uint8_t *_out = (uint8_t *)out;
-
-	for (i = 0; i < in_samples; i++, _in++, _out += 3) {
-		*_out = 0;
-		memcpy(_out + 1, _in, 2);
-	}
-}
-
-void convert_s16le_to_s24le(const uint8_t *in, size_t in_samples, uint8_t *out)
-{
-	size_t i;
-	int16_t *_in = (int16_t *)in;
-	uint32_t *_out = (uint32_t *)out;
-
-	for (i = 0; i < in_samples; i++, _in++, _out++)
-		*_out = ((uint32_t)(int32_t)*_in << 8);
-}
-
-void convert_s16le_to_s32le(const uint8_t *in, size_t in_samples, uint8_t *out)
-{
-	size_t i;
-	int16_t *_in = (int16_t *)in;
-	uint32_t *_out = (uint32_t *)out;
-
-	for (i = 0; i < in_samples; i++, _in++, _out++)
-		*_out = ((uint32_t)(int32_t)*_in << 16);
-}
-
-/*
- * Channel converter: mono to stereo.
- */
-size_t s16_mono_to_stereo(const uint8_t *_in, size_t in_frames, uint8_t *_out)
-{
-	size_t i;
-	const int16_t *in = (const int16_t *)_in;
-	int16_t *out = (int16_t *)_out;
-
-	for (i = 0; i < in_frames; i++) {
-		out[2 * i] = in[i];
-		out[2 * i + 1] = in[i];
-	}
-	return in_frames;
-}
-
-/*
- * Channel converter: stereo to mono.
- */
-size_t s16_stereo_to_mono(const uint8_t *_in, size_t in_frames, uint8_t *_out)
-{
-	size_t i;
-	const int16_t *in = (const int16_t *)_in;
-	int16_t *out = (int16_t *)_out;
-
-	for (i = 0; i < in_frames; i++)
-		out[i] = s16_add_and_clip(in[2 * i], in[2 * i + 1]);
-	return in_frames;
-}
-
-/*
- * Channel converter: mono to 5.1 surround.
- *
- * Fit mono to front center of the output, or split to front left/right
- * if front center is missing from the output channel layout.
- */
-size_t s16_mono_to_51(size_t left, size_t right, size_t center,
-		      const uint8_t *_in, size_t in_frames, uint8_t *_out)
-{
-	size_t i;
-	const int16_t *in = (const int16_t *)_in;
-	int16_t *out = (int16_t *)_out;
-
-	memset(out, 0, sizeof(*out) * 6 * in_frames);
-
-	if (center != -1)
-		for (i = 0; i < in_frames; i++)
-			out[6 * i + center] = in[i];
-	else if (left != -1 && right != -1)
-		for (i = 0; i < in_frames; i++) {
-			out[6 * i + right] = in[i] / 2;
-			out[6 * i + left] = in[i] / 2;
-		}
-	else
-		/* Select the first channel to convert to as the
-		 * default behavior.
-		 */
-		for (i = 0; i < in_frames; i++)
-			out[6 * i] = in[i];
-
-	return in_frames;
-}
-
-/*
- * Channel converter: stereo to 5.1 surround.
- *
- * Fit the left/right of input to the front left/right of output respectively
- * and fill others with zero. If any of the front left/right is missed from
- * the output channel layout, mix to front center.
- */
-size_t s16_stereo_to_51(size_t left, size_t right, size_t center,
-			const uint8_t *_in, size_t in_frames, uint8_t *_out)
-{
-	size_t i;
-	const int16_t *in = (const int16_t *)_in;
-	int16_t *out = (int16_t *)_out;
-
-	memset(out, 0, sizeof(*out) * 6 * in_frames);
-
-	if (left != -1 && right != -1)
-		for (i = 0; i < in_frames; i++) {
-			out[6 * i + left] = in[2 * i];
-			out[6 * i + right] = in[2 * i + 1];
-		}
-	else if (center != -1)
-		for (i = 0; i < in_frames; i++)
-			out[6 * i + center] =
-				s16_add_and_clip(in[2 * i], in[2 * i + 1]);
-	else
-		/* Select the first two channels to convert to as the
-		 * default behavior.
-		 */
-		for (i = 0; i < in_frames; i++) {
-			out[6 * i] = in[2 * i];
-			out[6 * i + 1] = in[2 * i + 1];
-		}
-
-	return in_frames;
-}
-
-/*
- * Channel converter: 5.1 surround to stereo.
- *
- * The out buffer can have room for just stereo samples. This convert function
- * is used as the default behavior when channel layout is not set from the
- * client side.
- */
-size_t s16_51_to_stereo(const uint8_t *_in, size_t in_frames, uint8_t *_out)
-{
-	const int16_t *in = (const int16_t *)_in;
-	int16_t *out = (int16_t *)_out;
-	static const unsigned int left_idx = 0;
-	static const unsigned int right_idx = 1;
-	/* static const unsigned int left_surround_idx = 2; */
-	/* static const unsigned int right_surround_idx = 3; */
-	static const unsigned int center_idx = 4;
-	/* static const unsigned int lfe_idx = 5; */
-	size_t i;
-
-	for (i = 0; i < in_frames; i++) {
-		unsigned int half_center;
-
-		half_center = in[6 * i + center_idx] / 2;
-		out[2 * i + left_idx] =
-			s16_add_and_clip(in[6 * i + left_idx], half_center);
-		out[2 * i + right_idx] =
-			s16_add_and_clip(in[6 * i + right_idx], half_center);
-	}
-	return in_frames;
-}
-
-/*
- * Channel converter: stereo to quad (front L/R, rear L/R).
- *
- * Fit left/right of input to the front left/right of output respectively
- * and fill others with zero.
- */
-size_t s16_stereo_to_quad(size_t front_left, size_t front_right,
-			  size_t rear_left, size_t rear_right,
-			  const uint8_t *_in, size_t in_frames, uint8_t *_out)
-{
-	size_t i;
-	const int16_t *in = (const int16_t *)_in;
-	int16_t *out = (int16_t *)_out;
-
-	if (front_left != -1 && front_right != -1 && rear_left != -1 &&
-	    rear_right != -1)
-		for (i = 0; i < in_frames; i++) {
-			out[4 * i + front_left] = in[2 * i];
-			out[4 * i + front_right] = in[2 * i + 1];
-			out[4 * i + rear_left] = in[2 * i];
-			out[4 * i + rear_right] = in[2 * i + 1];
-		}
-	else
-		/* Select the first four channels to convert to as the
-		 * default behavior.
-		 */
-		for (i = 0; i < in_frames; i++) {
-			out[4 * i] = in[2 * i];
-			out[4 * i + 1] = in[2 * i + 1];
-			out[4 * i + 2] = in[2 * i];
-			out[4 * i + 3] = in[2 * i + 1];
-		}
-
-	return in_frames;
-}
-
-/*
- * Channel converter: quad (front L/R, rear L/R) to stereo.
- */
-size_t s16_quad_to_stereo(size_t front_left, size_t front_right,
-			  size_t rear_left, size_t rear_right,
-			  const uint8_t *_in, size_t in_frames, uint8_t *_out)
-{
-	size_t i;
-	const int16_t *in = (const int16_t *)_in;
-	int16_t *out = (int16_t *)_out;
-
-	if (front_left == -1 || front_right == -1 || rear_left == -1 ||
-	    rear_right == -1) {
-		front_left = 0;
-		front_right = 1;
-		rear_left = 2;
-		rear_right = 3;
-	}
-
-	for (i = 0; i < in_frames; i++) {
-		out[2 * i] = s16_add_and_clip(in[4 * i + front_left],
-					      in[4 * i + rear_left] / 4);
-		out[2 * i + 1] = s16_add_and_clip(in[4 * i + front_right],
-						  in[4 * i + rear_right] / 4);
-	}
-	return in_frames;
-}
-
-/*
- * Channel converter: N channels to M channels.
- *
- * The out buffer must have room for M channel. This convert function is used
- * as the default behavior when channel layout is not set from the client side.
- */
-size_t s16_default_all_to_all(struct cras_audio_format *out_fmt,
-			      size_t num_in_ch, size_t num_out_ch,
-			      const uint8_t *_in, size_t in_frames,
-			      uint8_t *_out)
-{
-	unsigned int in_ch, out_ch, i;
-	const int16_t *in = (const int16_t *)_in;
-	int16_t *out = (int16_t *)_out;
-
-	memset(out, 0, in_frames * cras_get_format_bytes(out_fmt));
-	for (out_ch = 0; out_ch < num_out_ch; out_ch++) {
-		for (in_ch = 0; in_ch < num_in_ch; in_ch++) {
-			for (i = 0; i < in_frames; i++) {
-				out[out_ch + i * num_out_ch] +=
-					in[in_ch + i * num_in_ch] / num_in_ch;
-			}
-		}
-	}
-	return in_frames;
-}
-
-/*
- * Multiplies buffer vector with coefficient vector.
- */
-int16_t s16_multiply_buf_with_coef(float *coef, const int16_t *buf, size_t size)
-{
-	int32_t sum = 0;
-	int i;
-
-	for (i = 0; i < size; i++)
-		sum += coef[i] * buf[i];
-	sum = MAX(sum, -0x8000);
-	sum = MIN(sum, 0x7fff);
-	return (int16_t)sum;
-}
-
-/*
- * Channel layout converter.
- *
- * Converts channels based on the channel conversion coefficient matrix.
- */
-size_t s16_convert_channels(float **ch_conv_mtx, size_t num_in_ch,
-			    size_t num_out_ch, const uint8_t *_in,
-			    size_t in_frames, uint8_t *_out)
-{
-	unsigned i, fr;
-	unsigned in_idx = 0;
-	unsigned out_idx = 0;
-	const int16_t *in = (const int16_t *)_in;
-	int16_t *out = (int16_t *)_out;
-
-	for (fr = 0; fr < in_frames; fr++) {
-		for (i = 0; i < num_out_ch; i++)
-			out[out_idx + i] = s16_multiply_buf_with_coef(
-				ch_conv_mtx[i], &in[in_idx], num_in_ch);
-		in_idx += num_in_ch;
-		out_idx += num_out_ch;
-	}
-
-	return in_frames;
-}
diff --git a/cras/src/server/cras_fmt_conv_ops.h b/cras/src/server/cras_fmt_conv_ops.h
deleted file mode 100644
index 6943f23..0000000
--- a/cras/src/server/cras_fmt_conv_ops.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/* 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_FMT_CONV_OPS_H_
-#define CRAS_FMT_CONV_OPS_H_
-
-#include <sys/types.h>
-#include "cras_audio_format.h"
-
-/*
- * Format converter.
- */
-void convert_u8_to_s16le(const uint8_t *in, size_t in_samples, uint8_t *out);
-void convert_s243le_to_s16le(const uint8_t *in, size_t in_samples,
-			     uint8_t *out);
-void convert_s24le_to_s16le(const uint8_t *in, size_t in_samples, uint8_t *out);
-void convert_s32le_to_s16le(const uint8_t *in, size_t in_samples, uint8_t *out);
-void convert_s16le_to_u8(const uint8_t *in, size_t in_samples, uint8_t *out);
-void convert_s16le_to_s243le(const uint8_t *in, size_t in_samples,
-			     uint8_t *out);
-void convert_s16le_to_s24le(const uint8_t *in, size_t in_samples, uint8_t *out);
-void convert_s16le_to_s32le(const uint8_t *in, size_t in_samples, uint8_t *out);
-
-/*
- * Channel converter: mono to stereo.
- */
-size_t s16_mono_to_stereo(const uint8_t *in, size_t in_frames, uint8_t *out);
-
-/*
- * Channel converter: stereo to mono.
- */
-size_t s16_stereo_to_mono(const uint8_t *in, size_t in_frames, uint8_t *out);
-
-/*
- * Channel converter: mono to 5.1 surround.
- */
-size_t s16_mono_to_51(size_t left, size_t right, size_t center,
-		      const uint8_t *in, size_t in_frames, uint8_t *out);
-
-/*
- * Channel converter: stereo to 5.1 surround.
- */
-size_t s16_stereo_to_51(size_t left, size_t right, size_t center,
-			const uint8_t *in, size_t in_frames, uint8_t *out);
-
-/*
- * Channel converter: 5.1 surround to stereo.
- */
-size_t s16_51_to_stereo(const uint8_t *in, size_t in_frames, uint8_t *out);
-
-/*
- * Channel converter: stereo to quad (front L/R, rear L/R).
- */
-size_t s16_stereo_to_quad(size_t front_left, size_t front_right,
-			  size_t rear_left, size_t rear_right,
-			  const uint8_t *in, size_t in_frames, uint8_t *out);
-
-/*
- * Channel converter: quad (front L/R, rear L/R) to stereo.
- */
-size_t s16_quad_to_stereo(size_t front_left, size_t front_right,
-			  size_t rear_left, size_t rear_right,
-			  const uint8_t *in, size_t in_frames, uint8_t *out);
-
-/*
- * Channel converter: N channels to M channels.
- */
-size_t s16_default_all_to_all(struct cras_audio_format *out_fmt,
-			      size_t num_in_ch, size_t num_out_ch,
-			      const uint8_t *in, size_t in_frames,
-			      uint8_t *out);
-
-/*
- * Multiplies buffer vector with coefficient vector.
- */
-int16_t s16_multiply_buf_with_coef(float *coef, const int16_t *buf,
-				   size_t size);
-
-/*
- * Channel layout converter.
- */
-size_t s16_convert_channels(float **ch_conv_mtx, size_t num_in_ch,
-			    size_t num_out_ch, const uint8_t *in,
-			    size_t in_frames, uint8_t *out);
-
-#endif /* CRAS_FMT_CONV_OPS_H_ */
diff --git a/cras/src/server/cras_gpio_jack.c b/cras/src/server/cras_gpio_jack.c
index 7021908..29784c4 100644
--- a/cras/src/server/cras_gpio_jack.c
+++ b/cras/src/server/cras_gpio_jack.c
@@ -44,15 +44,15 @@
 char *sys_input_get_device_name(const char *path)
 {
 	char name[256];
-	int fd = open(path, O_RDONLY);
+	int  fd = open(path, O_RDONLY);
 
 	if (fd >= 0) {
 		gpio_switch_eviocgname(fd, name, sizeof(name));
 		close(fd);
 		return strdup(name);
 	} else {
-		syslog(LOG_WARNING, "Could not open '%s': %s", path,
-		       strerror(errno));
+		syslog(LOG_WARNING, "Could not open '%s': %s",
+		       path, strerror(errno));
 		return NULL;
 	}
 }
@@ -74,11 +74,10 @@
 	udev_enumerate_scan_devices(enumerate);
 	dl = udev_enumerate_get_list_entry(enumerate);
 
-	udev_list_entry_foreach(dev_list_entry, dl)
-	{
+	udev_list_entry_foreach(dev_list_entry, dl) {
 		const char *path = udev_list_entry_get_name(dev_list_entry);
-		struct udev_device *dev =
-			udev_device_new_from_syspath(udev, path);
+		struct udev_device *dev = udev_device_new_from_syspath(udev,
+								       path);
 		const char *devnode = udev_device_get_devnode(dev);
 		char *ioctl_name;
 
diff --git a/cras/src/server/cras_gpio_jack.h b/cras/src/server/cras_gpio_jack.h
index e6dd8aa..1c1a2a8 100644
--- a/cras/src/server/cras_gpio_jack.h
+++ b/cras/src/server/cras_gpio_jack.h
@@ -34,7 +34,8 @@
  *    0 to continue searching, non-zero otherwise.
  */
 typedef int (*gpio_switch_list_callback)(const char *dev_path,
-					 const char *dev_name, void *arg);
+				         const char *dev_name,
+				         void *arg);
 
 /* Execute the given callback on each GPIO device.
  *
diff --git a/cras/src/server/cras_hfp_ag_profile.c b/cras/src/server/cras_hfp_ag_profile.c
index 6320191..29c3e0d 100644
--- a/cras/src/server/cras_hfp_ag_profile.c
+++ b/cras/src/server/cras_hfp_ag_profile.c
@@ -11,66 +11,66 @@
 #include "cras_a2dp_endpoint.h"
 #include "cras_bt_adapter.h"
 #include "cras_bt_constants.h"
-#include "cras_bt_log.h"
 #include "cras_bt_profile.h"
 #include "cras_hfp_ag_profile.h"
 #include "cras_hfp_info.h"
 #include "cras_hfp_iodev.h"
-#include "cras_hfp_alsa_iodev.h"
-#include "cras_server_metrics.h"
+#include "cras_hfp_slc.h"
 #include "cras_system_state.h"
-#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_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>"                                                       \
+#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>"						\
 	"</record>"
 
+
 /* Object representing the audio gateway role for HFP/HSP.
  * Members:
  *    idev - The input iodev for HFP/HSP.
@@ -97,28 +97,14 @@
 
 static struct audio_gateway *connected_ags;
 
-static int need_go_sco_pcm(struct cras_bt_device *device)
-{
-	return cras_iodev_list_get_sco_pcm_iodev(CRAS_STREAM_INPUT) ||
-	       cras_iodev_list_get_sco_pcm_iodev(CRAS_STREAM_OUTPUT);
-}
-
 static void destroy_audio_gateway(struct audio_gateway *ag)
 {
 	DL_DELETE(connected_ags, ag);
 
-	if (need_go_sco_pcm(ag->device)) {
-		if (ag->idev)
-			hfp_alsa_iodev_destroy(ag->idev);
-		if (ag->odev)
-			hfp_alsa_iodev_destroy(ag->odev);
-	} else {
-		if (ag->idev)
-			hfp_iodev_destroy(ag->idev);
-		if (ag->odev)
-			hfp_iodev_destroy(ag->odev);
-	}
-
+	if (ag->idev)
+		hfp_iodev_destroy(ag->idev);
+	if (ag->odev)
+		hfp_iodev_destroy(ag->odev);
 	if (ag->info) {
 		if (hfp_info_running(ag->info))
 			hfp_info_stop(ag->info);
@@ -127,6 +113,11 @@
 	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);
 }
 
@@ -134,7 +125,7 @@
 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;
 	}
@@ -143,10 +134,7 @@
 
 static void cras_hfp_ag_release(struct cras_bt_profile *profile)
 {
-	struct audio_gateway *ag;
-
-	DL_FOREACH (connected_ags, ag)
-		destroy_audio_gateway(ag);
+	cras_hfp_ag_suspend();
 }
 
 /* Callback triggered when SLC is initialized.  */
@@ -158,12 +146,6 @@
 	if (!ag)
 		return -EINVAL;
 
-	/* Log if the hands-free device supports WBS or not. Assuming the
-	 * codec negotiation feature means the WBS capability on headset.
-	 */
-	cras_server_metrics_hfp_wideband_support(
-		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);
 }
@@ -177,8 +159,6 @@
 		return -EINVAL;
 
 	destroy_audio_gateway(ag);
-	cras_bt_device_notify_profile_dropped(
-		ag->device, CRAS_BT_DEVICE_PROFILE_HFP_HANDSFREE);
 	return 0;
 }
 
@@ -187,49 +167,59 @@
 	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;
 }
 
-int cras_hfp_ag_remove_conflict(struct cras_bt_device *device)
+static void possibly_remove_conflict_dev(void *data)
 {
-	struct audio_gateway *ag;
+	struct cras_bt_device *device = (struct cras_bt_device *)data;
+	struct audio_gateway *ag, *new_ag = NULL;
+	struct cras_bt_device *a2dp_device;
 
-	DL_FOREACH (connected_ags, ag) {
+	/* Check if the device is still connected. */
+	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);
 	}
-	return 0;
+
+	/* 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);
+	}
 }
 
 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;
 	}
@@ -237,24 +227,14 @@
 	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 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() &&
-	    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,
+					device,
 					cras_hfp_ag_slc_initialized,
 					cras_hfp_ag_slc_disconnected);
 	DL_APPEND(connected_ags, ag);
@@ -265,16 +245,9 @@
 					      struct cras_bt_device *device)
 {
 	struct audio_gateway *ag;
-
-	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);
-		}
 	}
 }
 
@@ -288,7 +261,7 @@
 	.uuid = HFP_AG_UUID,
 	.version = HFP_VERSION_1_5,
 	.role = NULL,
-	.features = CRAS_AG_SUPPORTED_FEATURES & 0x1F,
+	.features = HFP_SUPPORTED_FEATURE & 0x1F,
 	.record = NULL,
 	.release = cras_hfp_ag_release,
 	.new_connection = cras_hfp_ag_new_connection,
@@ -302,18 +275,15 @@
 }
 
 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;
 	}
@@ -321,33 +291,18 @@
 	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, device, NULL,
+					cras_hfp_ag_slc_disconnected);
 	DL_APPEND(connected_ags, ag);
 	cras_hfp_ag_slc_initialized(ag->slc_handle);
 	return 0;
 }
 
-static void cras_hsp_ag_request_disconnection(struct cras_bt_profile *profile,
-					      struct cras_bt_device *device)
-{
-	struct audio_gateway *ag;
-
-	BTLOG(btlog, BT_HSP_REQUEST_DISCONNECT, 0, 0);
-
-	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);
-		}
-	}
-}
-
 static struct cras_bt_profile cras_hsp_ag_profile = {
 	.name = HSP_AG_PROFILE_NAME,
 	.object_path = HSP_AG_PROFILE_PATH,
@@ -357,7 +312,7 @@
 	.record = HSP_AG_RECORD,
 	.release = cras_hfp_ag_release,
 	.new_connection = cras_hsp_ag_new_connection,
-	.request_disconnection = cras_hsp_ag_request_disconnection,
+	.request_disconnection = cras_hfp_ag_request_disconnection,
 	.cancel = cras_hfp_ag_cancel
 };
 
@@ -365,41 +320,17 @@
 {
 	struct audio_gateway *ag;
 
-	BTLOG(btlog, BT_AUDIO_GATEWAY_START, 0, 0);
-
 	DL_SEARCH_SCALAR(connected_ags, ag, device, device);
 	if (ag == NULL)
 		return -EEXIST;
 
-	/*
-	 * There is chance that bluetooth stack notifies us about remote
-	 * device's capability incrementally in multiple events. That could
-	 * cause hfp_ag_start be called more than once. Check if the input
-	 * HFP iodev is already created so we don't re-create HFP resources.
-	 */
-	if (ag->idev)
-		return 0;
-
-	if (need_go_sco_pcm(device)) {
-		struct cras_iodev *in_aio, *out_aio;
-
-		in_aio = cras_iodev_list_get_sco_pcm_iodev(CRAS_STREAM_INPUT);
-		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->odev = hfp_alsa_iodev_create(out_aio, ag->device,
-						 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);
-	}
+	ag->info = hfp_info_create();
+	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) {
 		destroy_audio_gateway(ag);
@@ -409,6 +340,13 @@
 	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;
@@ -428,7 +366,7 @@
 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 4c1d49d..bc3e042 100644
--- a/cras/src/server/cras_hfp_ag_profile.h
+++ b/cras/src/server/cras_hfp_ag_profile.h
@@ -9,30 +9,48 @@
 #include <dbus/dbus.h>
 
 #include "cras_bt_device.h"
-#include "cras_hfp_slc.h"
 
-/* The bitmap of HFP AG feature supported by CRAS */
-#define CRAS_AG_SUPPORTED_FEATURES (AG_ENHANCED_CALL_STATUS)
+/* Hands-free Audio Gateway feature bits, listed in according
+ * to their order in the bitmap defined in HFP spec.
+ */
+/* Call waiting and 3-way calling */
+#define HFP_THREE_WAY_CALLING           0x0001
+/* EC and/or NR function */
+#define HFP_EC_ANDOR_NR                 0x0002
+/* Voice recognition activation */
+#define HFP_VOICE_RECOGNITION           0x0004
+/* Inband ringtone */
+#define HFP_INBAND_RINGTONE             0x0008
+/* Attach a number to voice tag */
+#define HFP_ATTACH_NUMBER_TO_VOICETAG   0x0010
+/* Ability to reject a call */
+#define HFP_REJECT_A_CALL               0x0020
+/* Enhanced call status */
+#define HFP_ENHANCED_CALL_STATUS        0x0040
+/* Enhanced call control */
+#define HFP_ENHANCED_CALL_CONTRO        0x0080
+/* Extended error result codes */
+#define HFP_EXTENDED_ERROR_RESULT_CODES 0x0100
+/* Codec negotiation */
+#define HFP_CODEC_NEGOTIATION           0x0200
+
+#define HFP_SUPPORTED_FEATURE           (HFP_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 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 all connected audio gateways, used to stop HFP/HSP audio when
+ * an A2DP only device is connected. */
+void cras_hfp_ag_suspend();
 
 /* 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
deleted file mode 100644
index aecc47b..0000000
--- a/cras/src/server/cras_hfp_alsa_iodev.c
+++ /dev/null
@@ -1,324 +0,0 @@
-/* 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 <sys/socket.h>
-#include <sys/time.h>
-#include <syslog.h>
-
-#include "cras_audio_area.h"
-#include "cras_hfp_slc.h"
-#include "cras_iodev.h"
-#include "cras_system_state.h"
-#include "cras_util.h"
-#include "sfh.h"
-#include "utlist.h"
-#include "cras_bt_device.h"
-
-#include "cras_hfp_alsa_iodev.h"
-
-/* Object to represent a special HFP iodev which would be managed by bt_io but
- * playback/capture via an inner ALSA iodev.
- * Members:
- *    base - The base class cras_iodev.
- *    device - The corresponding remote BT device.
- *    slc - The service level connection.
- *    aio - The effective iodev for playback/capture.
- */
-struct hfp_alsa_io {
-	struct cras_iodev base;
-	struct cras_bt_device *device;
-	struct hfp_slc_handle *slc;
-	struct cras_iodev *aio;
-};
-
-static int hfp_alsa_open_dev(struct cras_iodev *iodev)
-{
-	struct hfp_alsa_io *hfp_alsa_io = (struct hfp_alsa_io *)iodev;
-	struct cras_iodev *aio = hfp_alsa_io->aio;
-
-	return aio->open_dev(aio);
-}
-
-static int hfp_alsa_update_supported_formats(struct cras_iodev *iodev)
-{
-	struct hfp_alsa_io *hfp_alsa_io = (struct hfp_alsa_io *)iodev;
-	struct cras_iodev *aio = hfp_alsa_io->aio;
-	int rc, i;
-
-	/* 16 bit, mono, 8kHz (narrow band speech); */
-	rc = aio->update_supported_formats(aio);
-	if (rc)
-		return rc;
-
-	for (i = 0; aio->supported_rates[i]; ++i)
-		if (aio->supported_rates[i] == 8000)
-			break;
-	if (aio->supported_rates[i] != 8000)
-		return -EINVAL;
-
-	for (i = 0; aio->supported_channel_counts[i]; ++i)
-		if (aio->supported_channel_counts[i] == 1)
-			break;
-	if (aio->supported_channel_counts[i] != 1)
-		return -EINVAL;
-
-	for (i = 0; aio->supported_formats[i]; ++i)
-		if (aio->supported_formats[i] == SND_PCM_FORMAT_S16_LE)
-			break;
-	if (aio->supported_formats[i] != SND_PCM_FORMAT_S16_LE)
-		return -EINVAL;
-
-	free(aio->format);
-	aio->format = malloc(sizeof(struct cras_audio_format));
-	if (!aio->format)
-		return -ENOMEM;
-	aio->format->format = SND_PCM_FORMAT_S16_LE;
-	aio->format->frame_rate = 8000;
-	aio->format->num_channels = 1;
-
-	free(iodev->supported_rates);
-	iodev->supported_rates = malloc(2 * sizeof(*iodev->supported_rates));
-	if (!iodev->supported_rates)
-		return -ENOMEM;
-	iodev->supported_rates[0] = 8000;
-	iodev->supported_rates[1] = 0;
-
-	free(iodev->supported_channel_counts);
-	iodev->supported_channel_counts =
-		malloc(2 * sizeof(*iodev->supported_channel_counts));
-	if (!iodev->supported_channel_counts)
-		return -ENOMEM;
-	iodev->supported_channel_counts[0] = 1;
-	iodev->supported_channel_counts[1] = 0;
-
-	free(iodev->supported_formats);
-	iodev->supported_formats =
-		malloc(2 * sizeof(*iodev->supported_formats));
-	if (!iodev->supported_formats)
-		return -ENOMEM;
-	iodev->supported_formats[0] = SND_PCM_FORMAT_S16_LE;
-	iodev->supported_formats[1] = 0;
-
-	return 0;
-}
-
-static int hfp_alsa_configure_dev(struct cras_iodev *iodev)
-{
-	struct hfp_alsa_io *hfp_alsa_io = (struct hfp_alsa_io *)iodev;
-	struct cras_iodev *aio = hfp_alsa_io->aio;
-	int rc;
-
-	rc = aio->configure_dev(aio);
-	if (rc) {
-		syslog(LOG_ERR, "Failed to configure aio: %d\n", rc);
-		return rc;
-	}
-
-	rc = cras_bt_device_get_sco(
-		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;
-	}
-
-	hfp_set_call_status(hfp_alsa_io->slc, 1);
-	iodev->buffer_size = aio->buffer_size;
-
-	return 0;
-}
-
-static int hfp_alsa_close_dev(struct cras_iodev *iodev)
-{
-	struct hfp_alsa_io *hfp_alsa_io = (struct hfp_alsa_io *)iodev;
-	struct cras_iodev *aio = hfp_alsa_io->aio;
-
-	cras_bt_device_put_sco(hfp_alsa_io->device);
-	cras_iodev_free_format(iodev);
-	return aio->close_dev(aio);
-}
-
-static int hfp_alsa_frames_queued(const struct cras_iodev *iodev,
-				  struct timespec *tstamp)
-{
-	struct hfp_alsa_io *hfp_alsa_io = (struct hfp_alsa_io *)iodev;
-	struct cras_iodev *aio = hfp_alsa_io->aio;
-
-	return aio->frames_queued(aio, tstamp);
-}
-
-static int hfp_alsa_delay_frames(const struct cras_iodev *iodev)
-{
-	struct hfp_alsa_io *hfp_alsa_io = (struct hfp_alsa_io *)iodev;
-	struct cras_iodev *aio = hfp_alsa_io->aio;
-
-	return aio->delay_frames(aio);
-}
-
-static int hfp_alsa_get_buffer(struct cras_iodev *iodev,
-			       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;
-
-	return aio->get_buffer(aio, area, frames);
-}
-
-static int hfp_alsa_put_buffer(struct cras_iodev *iodev, unsigned nwritten)
-{
-	struct hfp_alsa_io *hfp_alsa_io = (struct hfp_alsa_io *)iodev;
-	struct cras_iodev *aio = hfp_alsa_io->aio;
-
-	return aio->put_buffer(aio, nwritten);
-}
-
-static int hfp_alsa_flush_buffer(struct cras_iodev *iodev)
-{
-	struct hfp_alsa_io *hfp_alsa_io = (struct hfp_alsa_io *)iodev;
-	struct cras_iodev *aio = hfp_alsa_io->aio;
-
-	return aio->flush_buffer(aio);
-}
-
-static void hfp_alsa_update_active_node(struct cras_iodev *iodev,
-					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;
-
-	aio->update_active_node(aio, node_idx, dev_enabled);
-}
-
-static int hfp_alsa_start(const struct cras_iodev *iodev)
-{
-	struct hfp_alsa_io *hfp_alsa_io = (struct hfp_alsa_io *)iodev;
-	struct cras_iodev *aio = hfp_alsa_io->aio;
-
-	return aio->start(aio);
-}
-
-static void hfp_alsa_set_volume(struct cras_iodev *iodev)
-{
-	size_t volume;
-	struct hfp_alsa_io *hfp_alsa_io = (struct hfp_alsa_io *)iodev;
-
-	volume = cras_system_get_volume();
-	if (iodev->active_node)
-		volume = cras_iodev_adjust_node_volume(iodev->active_node,
-						       volume);
-
-	hfp_event_speaker_gain(hfp_alsa_io->slc, volume);
-}
-
-static int hfp_alsa_no_stream(struct cras_iodev *iodev, int enable)
-{
-	struct hfp_alsa_io *hfp_alsa_io = (struct hfp_alsa_io *)iodev;
-	struct cras_iodev *aio = hfp_alsa_io->aio;
-
-	/*
-	 * Copy iodev->min_cb_level and iodev->max_cb_level from the parent
-	 * (i.e. hfp_alsa_iodev).  no_stream() of alsa_io will use them.
-	 */
-	aio->min_cb_level = iodev->min_cb_level;
-	aio->max_cb_level = iodev->max_cb_level;
-	return aio->no_stream(aio, enable);
-}
-
-static int hfp_alsa_is_free_running(const struct cras_iodev *iodev)
-{
-	struct hfp_alsa_io *hfp_alsa_io = (struct hfp_alsa_io *)iodev;
-	struct cras_iodev *aio = hfp_alsa_io->aio;
-
-	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 hfp_alsa_io *hfp_alsa_io;
-	struct cras_iodev *iodev;
-	struct cras_ionode *node;
-	const char *name;
-
-	hfp_alsa_io = calloc(1, sizeof(*hfp_alsa_io));
-	if (!hfp_alsa_io)
-		return NULL;
-
-	iodev = &hfp_alsa_io->base;
-	iodev->direction = aio->direction;
-
-	hfp_alsa_io->device = device;
-	hfp_alsa_io->slc = slc;
-	hfp_alsa_io->aio = aio;
-
-	/* Set iodev's name to device readable name or the address. */
-	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);
-	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->open_dev = hfp_alsa_open_dev;
-	iodev->update_supported_formats = hfp_alsa_update_supported_formats;
-	iodev->configure_dev = hfp_alsa_configure_dev;
-	iodev->close_dev = hfp_alsa_close_dev;
-
-	iodev->frames_queued = hfp_alsa_frames_queued;
-	iodev->delay_frames = hfp_alsa_delay_frames;
-	iodev->get_buffer = hfp_alsa_get_buffer;
-	iodev->put_buffer = hfp_alsa_put_buffer;
-	iodev->flush_buffer = hfp_alsa_flush_buffer;
-
-	iodev->update_active_node = hfp_alsa_update_active_node;
-	iodev->start = hfp_alsa_start;
-	iodev->set_volume = hfp_alsa_set_volume;
-	iodev->no_stream = hfp_alsa_no_stream;
-	iodev->is_free_running = hfp_alsa_is_free_running;
-
-	iodev->min_buffer_level = aio->min_buffer_level;
-
-	node = calloc(1, sizeof(*node));
-	node->dev = iodev;
-	strcpy(node->name, iodev->info.name);
-
-	node->plugged = 1;
-	node->type = CRAS_NODE_TYPE_BLUETOOTH;
-	node->volume = 100;
-	gettimeofday(&node->plugged_time, NULL);
-
-	cras_bt_device_append_iodev(device, iodev, profile);
-	cras_iodev_add_node(iodev, node);
-	cras_iodev_set_active_node(iodev, node);
-
-	return iodev;
-}
-
-void hfp_alsa_iodev_destroy(struct cras_iodev *iodev)
-{
-	struct hfp_alsa_io *hfp_alsa_io = (struct hfp_alsa_io *)iodev;
-	struct cras_ionode *node;
-
-	cras_bt_device_rm_iodev(hfp_alsa_io->device, iodev);
-
-	node = iodev->active_node;
-	if (node) {
-		cras_iodev_rm_node(iodev, node);
-		free(node);
-	}
-
-	free(iodev->supported_channel_counts);
-	free(iodev->supported_rates);
-	free(iodev->supported_formats);
-	cras_iodev_free_resources(iodev);
-
-	free(hfp_alsa_io);
-}
diff --git a/cras/src/server/cras_hfp_alsa_iodev.h b/cras/src/server/cras_hfp_alsa_iodev.h
deleted file mode 100644
index e05af68..0000000
--- a/cras/src/server/cras_hfp_alsa_iodev.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/* 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_HFP_ALSA_IODEV_H_
-#define CRAS_HFP_ALSA_IODEV_H_
-
-#include "cras_bt_device.h"
-#include "cras_hfp_info.h"
-#include "cras_types.h"
-
-struct hfp_slc_handle;
-
-/*
- * Creates a hfp alsa iodev.
- *
- * hfp_alsa_iodev is a special HFP iodev which would be managed by bt_io but
- * playback/capture via an inner ALSA iodev.
- *
- * 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);
-
-void hfp_alsa_iodev_destroy(struct cras_iodev *iodev);
-
-#endif /* CRAS_HFP_ALSA_IODEV_H_ */
diff --git a/cras/src/server/cras_hfp_info.c b/cras/src/server/cras_hfp_info.c
index 02bc8b4..4127a00 100644
--- a/cras/src/server/cras_hfp_info.c
+++ b/cras/src/server/cras_hfp_info.c
@@ -11,44 +11,19 @@
 
 #include "audio_thread.h"
 #include "byte_buffer.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 "cras_hfp_info.h"
 #include "utlist.h"
 
 /* The max buffer size. Note that the actual used size must set to multiple
  * of SCO packet size, and the packet size does not necessarily be equal to
- * MTU. We should keep this as common multiple of possible packet sizes, for
- * example: 48, 60, 64, 128.
+ * MTU.
  */
-#define MAX_HFP_BUF_SIZE_BYTES 28800
+#define MAX_HFP_BUF_SIZE_BYTES 16384
 
 /* rate(8kHz) * sample_size(2 bytes) * channels(1) */
 #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
-
-/* 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 HCI_SCO_HDR_SIZE_BYTES 3
-#define HCI_SCO_PKT_SIZE (MSBC_PKT_SIZE + HCI_SCO_HDR_SIZE_BYTES)
-
-#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 };
-
 /* Structure to hold variables for a HFP connection. Since HFP supports
  * bi-direction audio, two iodevs should share one hfp_info if they
  * represent two directions of the same HFP headset
@@ -60,21 +35,10 @@
  *         adapter, could be different than mtu.
  *     capture_buf - The buffer to hold samples read from SCO socket.
  *     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.
- *     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.
- *     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.
+ *     idev - The input iodev using this hfp_info.
+ *     odev - The output iodev using this hfp_info.
+ *     packet_size_changed_cbs - The callbacks to trigger when SCO packet
+ *         size changed.
  */
 struct hfp_info {
 	int fd;
@@ -83,34 +47,24 @@
 	unsigned int packet_size;
 	struct byte_buffer *capture_buf;
 	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 hci_sco_buf[HCI_SCO_PKT_SIZE];
-	size_t input_format_bytes;
-	size_t output_format_bytes;
+
+	struct cras_iodev *idev;
+	struct cras_iodev *odev;
+	struct hfp_packet_size_changed_callback *packet_size_changed_cbs;
 };
 
-int hfp_info_add_iodev(struct hfp_info *info,
-		       enum CRAS_STREAM_DIRECTION direction,
-		       struct cras_audio_format *format)
+int hfp_info_add_iodev(struct hfp_info *info, struct cras_iodev *dev)
 {
-	if (direction == CRAS_STREAM_OUTPUT) {
-		if (info->output_format_bytes)
+	if (dev->direction == CRAS_STREAM_OUTPUT) {
+		if (info->odev)
 			goto invalid;
-		info->output_format_bytes = cras_get_format_bytes(format);
+		info->odev = dev;
 
 		buf_reset(info->playback_buf);
-	} else if (direction == CRAS_STREAM_INPUT) {
-		if (info->input_format_bytes)
+	} else if (dev->direction == CRAS_STREAM_INPUT) {
+		if (info->idev)
 			goto invalid;
-		info->input_format_bytes = cras_get_format_bytes(format);
+		info->idev = dev;
 
 		buf_reset(info->capture_buf);
 	}
@@ -121,163 +75,70 @@
 	return -EINVAL;
 }
 
-int hfp_info_rm_iodev(struct hfp_info *info,
-		      enum CRAS_STREAM_DIRECTION direction)
+int hfp_info_rm_iodev(struct hfp_info *info, struct cras_iodev *dev)
 {
-	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 {
+	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
 		return -EINVAL;
-	}
 
 	return 0;
 }
 
 int hfp_info_has_iodev(struct hfp_info *info)
 {
-	return info->output_format_bytes || info->input_format_bytes;
+	return info->odev || info->idev;
 }
 
-void hfp_buf_acquire(struct hfp_info *info,
-		     enum CRAS_STREAM_DIRECTION direction, uint8_t **buf,
-		     unsigned *count)
+void hfp_buf_acquire(struct hfp_info *info, struct cras_iodev *dev,
+		     uint8_t **buf, unsigned *count)
 {
 	size_t format_bytes;
 	unsigned int buf_avail;
+	format_bytes = cras_get_format_bytes(dev->format);
 
-	if (direction == CRAS_STREAM_OUTPUT && info->output_format_bytes) {
+	*count *= format_bytes;
+
+	if (dev->direction == CRAS_STREAM_OUTPUT)
 		*buf = buf_write_pointer_size(info->playback_buf, &buf_avail);
-		format_bytes = info->output_format_bytes;
-	} else if (direction == CRAS_STREAM_INPUT && info->input_format_bytes) {
+	else
 		*buf = buf_read_pointer_size(info->capture_buf, &buf_avail);
-		format_bytes = info->input_format_bytes;
-	} else {
-		*count = 0;
-		return;
-	}
 
-	if (*count * format_bytes > buf_avail)
-		*count = buf_avail / format_bytes;
+	if (*count > buf_avail)
+		*count = buf_avail;
+	*count /= format_bytes;
 }
 
-int hfp_buf_size(struct hfp_info *info, enum CRAS_STREAM_DIRECTION direction)
+int hfp_buf_size(struct hfp_info *info, struct cras_iodev *dev)
 {
-	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;
+	return info->playback_buf->used_size / cras_get_format_bytes(dev->format);
 }
 
-void hfp_buf_release(struct hfp_info *info,
-		     enum CRAS_STREAM_DIRECTION direction,
+void hfp_buf_release(struct hfp_info *info, struct cras_iodev *dev,
 		     unsigned 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);
+	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);
 	else
-		written_frames = 0;
+		buf_increment_read(info->capture_buf, written_frames);
 }
 
-int hfp_buf_queued(struct hfp_info *info, enum CRAS_STREAM_DIRECTION direction)
+int hfp_buf_queued(struct hfp_info *info, const struct cras_iodev *dev)
 {
-	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;
+	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;
 	else
-		return 0;
-}
-
-int hfp_fill_output_with_zeros(struct hfp_info *info, unsigned int nframes)
-{
-	unsigned int buf_avail;
-	unsigned int nbytes;
-	uint8_t *buf;
-	int i;
-	int ret = 0;
-
-	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;
-}
-
-void hfp_force_output_level(struct hfp_info *info, unsigned int level)
-{
-	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)
-{
-	size_t encoded;
-	int err;
-	int pcm_encoded;
-	unsigned int pcm_avail;
-	uint8_t *samples;
-	uint8_t *wp;
-
-	samples = buf_read_pointer_size(info->playback_buf, &pcm_avail);
-	wp = info->write_buf;
-	if (pcm_avail >= MSBC_CODE_SIZE) {
-		/* Encode more */
-		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);
-		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);
-	}
-
-msbc_send_again:
-	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 != MSBC_PKT_SIZE) {
-		syslog(LOG_ERR, "Partially write %d bytes for mSBC", err);
-		return -1;
-	}
-	info->msbc_num_out_frames++;
-
-	return err;
+		return buf_queued(info->capture_buf) / format_bytes;
 }
 
 int hfp_write(struct hfp_info *info)
@@ -303,8 +164,8 @@
 
 	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;
 	}
 
@@ -313,170 +174,43 @@
 	return err;
 }
 
-static int h2_header_get_seq(const uint8_t *p)
+
+static void hfp_info_set_packet_size(struct hfp_info *info,
+				     unsigned int packet_size)
 {
-	int i;
-	for (i = 0; i < 4; i++) {
-		if (*p == h2_header_frames_count[i])
-			return i;
-	}
-	return -1;
+	struct hfp_packet_size_changed_callback *callback;
+	unsigned int used_size =
+		MAX_HFP_BUF_SIZE_BYTES / packet_size * packet_size;
+	info->packet_size = packet_size;
+	byte_buffer_set_used_size(info->playback_buf, used_size);
+	byte_buffer_set_used_size(info->capture_buf, used_size);
+
+	DL_FOREACH(info->packet_size_changed_cbs, callback)
+		callback->cb(callback->data);
 }
 
-/*
- * Extract mSBC frame from SCO socket input bytes, given that the mSBC frame
- * could be lost or corrupted.
- * Args:
- *    input - Pointer to input bytes read from SCO socket.
- *    len - Length of input bytes.
- *    seq_out - To be filled by the sequence number of mSBC packet.
- * Returns:
- *    The starting position of mSBC frame if found.
- */
-static const uint8_t *extract_msbc_frame(const uint8_t *input, int len,
-					 unsigned int *seq_out)
+void hfp_register_packet_size_changed_callback(struct hfp_info *info,
+					       void (*cb)(void *data),
+					       void *data)
 {
-	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;
+	struct hfp_packet_size_changed_callback *callback =
+		(struct hfp_packet_size_changed_callback *)calloc(1,
+			sizeof(struct hfp_packet_size_changed_callback));
+	callback->data = data;
+	callback->cb = cb;
+	DL_APPEND(info->packet_size_changed_cbs, callback);
+}
+
+void hfp_unregister_packet_size_changed_callback(struct hfp_info *info,
+						 void *data)
+{
+	struct hfp_packet_size_changed_callback *callback;
+	DL_FOREACH(info->packet_size_changed_cbs, callback) {
+		if (data == callback->data) {
+			DL_DELETE(info->packet_size_changed_cbs, callback);
+			free(callback);
 		}
-		seq = h2_header_get_seq(input + rp + 1);
-		if (seq < 0) {
-			rp++;
-			continue;
-		}
-		// `seq` is guaranteed to be positive now.
-		*seq_out = (unsigned int)seq;
-		return input + rp;
 	}
-	return NULL;
-}
-
-/*
- * Handle the case when mSBC frame is considered lost.
- * Args:
- *    info - The hfp_info instance holding mSBC codec and PLC objects.
- */
-static int handle_packet_loss(struct hfp_info *info)
-{
-	int decoded;
-	unsigned int pcm_avail;
-	uint8_t *in_bytes;
-
-	/* 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;
-
-	buf_increment_write(info->capture_buf, decoded);
-
-	return decoded;
-}
-
-int hfp_read_msbc(struct hfp_info *info)
-{
-	int err = 0;
-	unsigned int pcm_avail = 0;
-	int decoded;
-	size_t pcm_decoded = 0;
-	size_t pcm_read = 0;
-	uint8_t *capture_buf;
-	const uint8_t *frame_head = NULL;
-	unsigned int seq;
-
-recv_msbc_bytes:
-	err = recv(info->fd, info->hci_sco_buf, HCI_SCO_PKT_SIZE, 0);
-	if (err < 0) {
-		syslog(LOG_ERR, "HCI SCO packet read err %s", strerror(errno));
-		if (errno == EINTR)
-			goto recv_msbc_bytes;
-		return err;
-	}
-	/*
-	 * Treat return code 0 (socket shutdown) as error here. BT stack
-	 * shall send signal to main thread for device disconnection.
-	 */
-	if (err != HCI_SCO_PKT_SIZE) {
-		syslog(LOG_ERR, "Partially read %d bytes for mSBC packet", err);
-		return -1;
-	}
-
-	/*
-	 * 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) {
-		syslog(LOG_ERR, "Failed to extract msbc frame");
-		return handle_packet_loss(info);
-	}
-
-	/*
-	 * Consider packet loss when found discontinuity in sequence number.
-	 */
-	while (seq != (info->msbc_num_in_frames % 4)) {
-		syslog(LOG_ERR, "SCO packet seq unmatch");
-		err = handle_packet_loss(info);
-		if (err < 0)
-			return err;
-		pcm_read += err;
-	}
-
-	/* 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.
-		 */
-		syslog(LOG_ERR, "mSBC decode failed");
-		err = handle_packet_loss(info);
-		if (err < 0)
-			return 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;
-	}
-	return pcm_read;
 }
 
 int hfp_read(struct hfp_info *info)
@@ -508,10 +242,9 @@
 		 * transmitting SCO packet.
 		 */
 		if (err && (info->packet_size == info->mtu)) {
-			info->packet_size = err;
+			hfp_info_set_packet_size(info, 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;
 		}
@@ -537,48 +270,35 @@
 	int err;
 
 	if (!info->started)
-		return 0;
+		goto read_write_error;
 
-	err = info->read_cb(info);
+	err = hfp_read(info);
 	if (err < 0) {
 		syslog(LOG_ERR, "Read error");
 		goto read_write_error;
 	}
 
-	/* Ignore the bytes just read if input dev not in present */
-	if (!info->input_format_bytes)
-		buf_increment_read(info->capture_buf, err);
+	/* Ignore the MTU bytes just read if input dev not in present */
+	if (!info->idev)
+		buf_increment_read(info->capture_buf, info->packet_size);
 
-	/* 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;
+	if (info->odev) {
+		err = hfp_write(info);
+		if (err < 0) {
+			syslog(LOG_ERR, "Write error");
+			goto read_write_error;
+		}
 	}
 
 	return 0;
 
 read_write_error:
-	/*
-	 * This callback is executing in audio thread, so it's safe to
-	 * unregister itself by audio_thread_rm_callback().
-	 */
-	audio_thread_rm_callback(info->fd);
-	close(info->fd);
-	info->fd = 0;
-	info->started = 0;
+	hfp_info_stop(info);
 
 	return 0;
 }
 
-struct hfp_info *hfp_info_create(int codec)
+struct hfp_info *hfp_info_create()
 {
 	struct hfp_info *info;
 	info = (struct hfp_info *)calloc(1, sizeof(*info));
@@ -593,17 +313,6 @@
 	if (!info->playback_buf)
 		goto error;
 
-	if (codec == HFP_CODEC_ID_MSBC) {
-		info->write_cb = hfp_write_msbc;
-		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;
-	}
-
 	return info;
 
 error:
@@ -627,17 +336,15 @@
 	info->fd = fd;
 	info->mtu = mtu;
 
-	/* Initialize to MTU, it may change when actually read the socket. */
-	info->packet_size = mtu;
+	/* Make sure buffer size is multiple of packet size, which initially
+	 * set to MTU. */
+	hfp_info_set_packet_size(info, mtu);
 	buf_reset(info->playback_buf);
 	buf_reset(info->capture_buf);
 
 	audio_thread_add_callback(info->fd, hfp_info_callback, info);
 
 	info->started = 1;
-	info->msbc_num_out_frames = 0;
-	info->msbc_num_in_frames = 0;
-	info->msbc_num_lost_frames = 0;
 
 	return 0;
 }
@@ -647,19 +354,14 @@
 	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;
 }
 
@@ -671,12 +373,5 @@
 	if (info->playback_buf)
 		byte_buffer_destroy(&info->playback_buf);
 
-	if (info->msbc_read)
-		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 334278e..6d980a9 100644
--- a/cras/src/server/cras_hfp_info.h
+++ b/cras/src/server/cras_hfp_info.h
@@ -6,9 +6,10 @@
 #ifndef CRAS_HFP_INFO_H_
 #define CRAS_HFP_INFO_H_
 
-#include "cras_audio_format.h"
+#include "cras_iodev.h"
 #include "cras_types.h"
 
+
 /* Linked list to hold the information of callbacks to trigger
  * when the size of SCO packet has changed.
  */
@@ -23,11 +24,8 @@
  */
 struct hfp_info;
 
-/* Creates an hfp_info instance.
- * Args:
- *    codec - 1 for CVSD, 2 for mSBC per HFP 1.7 specification.
- */
-struct hfp_info *hfp_info_create(int codec);
+/* Creates an hfp_info instance. */
+struct hfp_info *hfp_info_create();
 
 /* Destroys given hfp_info instance. */
 void hfp_info_destroy(struct hfp_info *info);
@@ -36,88 +34,84 @@
 int hfp_info_running(struct hfp_info *info);
 
 /* Starts the hfp_info to transmit and reveice samples to and from the file
- * descriptor of a SCO socket. This should be called from main thread.
+ * descriptor of a SCO socket.
  */
 int hfp_info_start(int fd, unsigned int mtu, struct hfp_info *info);
 
 /* Stops given hfp_info. This implies sample transmission will
- * stop and socket be closed. This should be called from main thread.
+ * stop and socket be closed.
  */
 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.
- *    direction - The direction to indicate which buffer to query, playback
- *          or capture.
+ *    dev - The iodev to indicate which buffer to query, playback
+ *          or capture, depending on its direction.
  */
-int hfp_buf_queued(struct hfp_info *info, enum CRAS_STREAM_DIRECTION direction);
+int hfp_buf_queued(struct hfp_info *info, const struct cras_iodev *dev);
 
-/* Fill output buffer with zero frames.
- * Args:
- *    info - The hfp_info holding the output buffer.
- *    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, 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.
- *    level - Value of the target output level.
- */
-void hfp_force_output_level(struct hfp_info *info, unsigned int level);
-
-/* Gets how many frames of the buffer are used.
+/* Gets how many bytes of the buffer are used.
  * Args:
  *    info - The hfp_info holding buffer.
- *    direction - The direction of the buffer.
+ *    dev - The iodev which uses the buffer.
  */
-int hfp_buf_size(struct hfp_info *info, enum CRAS_STREAM_DIRECTION direction);
+int hfp_buf_size(struct hfp_info *info, struct cras_iodev *dev);
 
 /* Acquire buffer of count frames for dev to write(or read,
  * depend on dev's direction).
  * Args:
  *    info - The hfp_info holding buffer.
- *    direction - The direction of dev to acquire buffer for.
+ *    dev - The iodev 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,
-		     enum CRAS_STREAM_DIRECTION direction, uint8_t **buf,
-		     unsigned *count);
+void hfp_buf_acquire(struct hfp_info *info,  struct cras_iodev *dev,
+		     uint8_t **buf, unsigned *count);
 
 /* Releases the previously acquired buffer.
  * Args:
  *    info - The hfp_info holding the buffer.
- *    direction - The direction of dev to release buffer for.
+ *    dev - The iodev who releases buffer.
  *    written_frames - The size of the previously acquired buffer in frames
  *    which's been used.
  */
-void hfp_buf_release(struct hfp_info *info,
-		     enum CRAS_STREAM_DIRECTION direction,
+void hfp_buf_release(struct hfp_info *info, struct cras_iodev *dev,
 		     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,
-		       enum CRAS_STREAM_DIRECTION direction,
-		       struct cras_audio_format *format);
+int hfp_info_add_iodev(struct hfp_info *info, struct cras_iodev *dev);
 
 /* 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,
-		      enum CRAS_STREAM_DIRECTION direction);
+int hfp_info_rm_iodev(struct hfp_info *info, struct cras_iodev *dev);
 
 /* Checks if there's any iodev added to the given hfp_info. */
 int hfp_info_has_iodev(struct hfp_info *info);
 
+/* Registers a callback function for the SCO packet size changed event.
+ * Args:
+ *    info - The hfp_info to register callback to.
+ *    cb - The callback function to call.
+ *    data - The data which will be passed to callback function.
+ */
+void hfp_register_packet_size_changed_callback(struct hfp_info *info,
+					       void (*cb)(void *data),
+					       void *data);
+
+/* Unregisters a callback function for the SCO packet size changed event.
+ * Args:
+ *    info - The hfp_info to unregister callback from.
+ *    data - The data used as key to unregister callback.
+ */
+void hfp_unregister_packet_size_changed_callback(struct hfp_info *info,
+						 void *data);
+
 #endif /* CRAS_HFP_INFO_H_ */
diff --git a/cras/src/server/cras_hfp_iodev.c b/cras/src/server/cras_hfp_iodev.c
index 08e26d6..dd8296e 100644
--- a/cras/src/server/cras_hfp_iodev.c
+++ b/cras/src/server/cras_hfp_iodev.c
@@ -3,14 +3,11 @@
  * found in the LICENSE file.
  */
 
-#include <stdbool.h>
-#include <sys/param.h>
 #include <sys/socket.h>
 #include <sys/time.h>
 #include <syslog.h>
 
 #include "cras_audio_area.h"
-#include "cras_hfp_ag_profile.h"
 #include "cras_hfp_iodev.h"
 #include "cras_hfp_info.h"
 #include "cras_hfp_slc.h"
@@ -20,40 +17,22 @@
 #include "sfh.h"
 #include "utlist.h"
 
-/* Implementation of bluetooth hands-free profile iodev.
- * Members:
- *    base - The cras_iodev structure base class.
- *    device - The assciated bt_device.
- *    slc - Handle to the HFP service level connection.
- *    info - hfp_info taking care of SCO data read/write.
- *    drain_complete - Flag to indicate if valid samples are drained
- *        in no stream state. Only used for output.
- *    filled_zeros - Number of zero data in frames have been filled
- *        to buffer of hfp_info in no stream state. Only used for output
- */
+
 struct hfp_io {
 	struct cras_iodev base;
 	struct cras_bt_device *device;
 	struct hfp_slc_handle *slc;
 	struct hfp_info *info;
-	bool drain_complete;
-	unsigned int filled_zeros;
 };
 
 static int update_supported_formats(struct cras_iodev *iodev)
 {
-	struct hfp_io *hfpio = (struct hfp_io *)iodev;
-
-	/* 16 bit, mono, 8kHz for narrowband and 16KHz for wideband */
+	// 16 bit, mono, 8kHz
 	iodev->format->format = SND_PCM_FORMAT_S16_LE;
 
 	free(iodev->supported_rates);
 	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;
+	iodev->supported_rates[0] = 8000;
 	iodev->supported_rates[1] = 0;
 
 	free(iodev->supported_channel_counts);
@@ -70,47 +49,6 @@
 	return 0;
 }
 
-static int no_stream(struct cras_iodev *iodev, int enable)
-{
-	struct hfp_io *hfpio = (struct hfp_io *)iodev;
-	struct timespec hw_tstamp;
-	unsigned int hw_level;
-	unsigned int level_target;
-
-	if (iodev->direction != CRAS_STREAM_OUTPUT)
-		return 0;
-
-	hw_level = iodev->frames_queued(iodev, &hw_tstamp);
-	if (enable) {
-		if (!hfpio->drain_complete && (hw_level <= hfpio->filled_zeros))
-			hfpio->drain_complete = 1;
-		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, level_target);
-	} else {
-		unsigned int valid_samples = 0;
-		if (hw_level > hfpio->filled_zeros)
-			valid_samples = hw_level - hfpio->filled_zeros;
-		level_target = MAX(level_target, valid_samples);
-
-		if (level_target > hw_level)
-			hfp_fill_output_with_zeros(hfpio->info,
-						   level_target - hw_level);
-		else
-			hfp_force_output_level(hfpio->info, level_target);
-	}
-	hfpio->drain_complete = 0;
-	hfpio->filled_zeros = 0;
-
-	return 0;
-}
-
 static int frames_queued(const struct cras_iodev *iodev,
 			 struct timespec *tstamp)
 {
@@ -122,7 +60,19 @@
 	/* 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->direction);
+	return hfp_buf_queued(hfpio->info, iodev);
+}
+
+/* Modify the hfpio's buffer_size when the SCO packet size has changed. */
+static void hfp_packet_size_changed(void *data)
+{
+	struct hfp_io *hfpio = (struct hfp_io *)data;
+	struct cras_iodev *iodev = &hfpio->base;
+
+	if (!cras_iodev_is_open(iodev))
+		return;
+	iodev->buffer_size = hfp_buf_size(hfpio->info, iodev);
+	cras_bt_device_iodev_buffer_size_changed(hfpio->device);
 }
 
 static int configure_dev(struct cras_iodev *iodev)
@@ -139,26 +89,22 @@
 	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);
 	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_mtu(hfpio->device, sk);
 
 	/* Start hfp_info */
 	err = hfp_info_start(sk, mtu, hfpio->info);
 	if (err)
 		goto error;
 
-	hfpio->drain_complete = 0;
-	hfpio->filled_zeros = 0;
 add_dev:
-	hfp_info_add_iodev(hfpio->info, iodev->direction, iodev->format);
+	hfp_info_add_iodev(hfpio->info, iodev);
 	hfp_set_call_status(hfpio->slc, 1);
 
-	iodev->buffer_size = hfp_buf_size(hfpio->info, iodev->direction);
+	iodev->buffer_size = hfp_buf_size(hfpio->info, iodev);
 
 	return 0;
 error:
@@ -170,7 +116,7 @@
 {
 	struct hfp_io *hfpio = (struct hfp_io *)iodev;
 
-	hfp_info_rm_iodev(hfpio->info, iodev->direction);
+	hfp_info_rm_iodev(hfpio->info, iodev);
 	if (hfp_info_running(hfpio->info) && !hfp_info_has_iodev(hfpio->info)) {
 		hfp_info_stop(hfpio->info);
 		hfp_set_call_status(hfpio->slc, 0);
@@ -188,8 +134,7 @@
 
 	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);
 }
@@ -201,7 +146,8 @@
 	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;
@@ -210,7 +156,7 @@
 	if (!hfp_info_running(hfpio->info))
 		return -1;
 
-	hfp_buf_acquire(hfpio->info, iodev->direction, &dst, frames);
+	hfp_buf_acquire(hfpio->info, iodev, &dst, frames);
 
 	iodev->area->frames = *frames;
 	/* HFP is mono only. */
@@ -229,7 +175,7 @@
 	if (!hfp_info_running(hfpio->info))
 		return -1;
 
-	hfp_buf_release(hfpio->info, iodev->direction, nwritten);
+	hfp_buf_release(hfpio->info, iodev, nwritten);
 	return 0;
 }
 
@@ -239,8 +185,8 @@
 	unsigned nframes;
 
 	if (iodev->direction == CRAS_STREAM_INPUT) {
-		nframes = hfp_buf_queued(hfpio->info, iodev->direction);
-		hfp_buf_release(hfpio->info, iodev->direction, nframes);
+		nframes = hfp_buf_queued(hfpio->info, iodev);
+		hfp_buf_release(hfpio->info, iodev, nframes);
 	}
 	return 0;
 }
@@ -264,11 +210,12 @@
 	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;
@@ -292,18 +239,18 @@
 
 	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 = 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->configure_dev= configure_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->no_stream = no_stream;
 	iodev->close_dev = close_dev;
 	iodev->update_supported_formats = update_supported_formats;
 	iodev->update_active_node = update_active_node;
@@ -323,6 +270,9 @@
 	cras_iodev_set_active_node(iodev, node);
 
 	hfpio->info = info;
+	hfp_register_packet_size_changed_callback(info,
+						  hfp_packet_size_changed,
+						  hfpio);
 
 	return iodev;
 
@@ -339,6 +289,7 @@
 	struct hfp_io *hfpio = (struct hfp_io *)iodev;
 
 	cras_bt_device_rm_iodev(hfpio->device, iodev);
+	hfp_unregister_packet_size_changed_callback(hfpio->info, hfpio);
 	hfp_free_resources(hfpio);
 	free(hfpio);
 }
diff --git a/cras/src/server/cras_hfp_iodev.h b/cras/src/server/cras_hfp_iodev.h
index b2762be..3a073d0 100644
--- a/cras/src/server/cras_hfp_iodev.h
+++ b/cras/src/server/cras_hfp_iodev.h
@@ -15,11 +15,12 @@
 /*
  * 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 6b30a0b..cc51055 100644
--- a/cras/src/server/cras_hfp_slc.c
+++ b/cras/src/server/cras_hfp_slc.c
@@ -6,45 +6,36 @@
 #include <sys/socket.h>
 #include <syslog.h>
 
-#include "stdbool.h"
-
 #include "cras_bt_device.h"
-#include "cras_bt_log.h"
 #include "cras_telephony.h"
+#include "cras_hfp_ag_profile.h"
 #include "cras_hfp_slc.h"
 #include "cras_system_state.h"
-#include "cras_tm.h"
 
-/* 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.
@@ -54,24 +45,13 @@
  *    buf_write_idx - Write index for buf.
  *    rfcomm_fd - File descriptor for the established RFCOMM connection.
  *    init_cb - Callback to be triggered when an SLC is initialized.
+ *    initialized - The service level connection is fully initilized of not.
  *    cli_active - Calling line identification notification is enabled or not.
  *    battery - Current battery level of AG stored in SLC.
  *    signal - Current signal strength of AG stored in SLC.
  *    service - Current service availability of AG stored in SLC.
  *    callheld - Current callheld status of AG stored in SLC.
  *    ind_event_report - Activate status of indicator events reporting.
- *    ag_supported_features - Supported AG features bitmap.
- *    hf_codec_supported - Flags to indicate if codec is supported in HF.
- *    hf_supports_codec_negotiation - If the connected HF supports codec
- *        negotiation.
- *    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.
  */
@@ -79,24 +59,19 @@
 	char buf[SLC_BUF_SIZE_BYTES];
 	int buf_read_idx;
 	int buf_write_idx;
+
 	int is_hsp;
 	int rfcomm_fd;
 	hfp_slc_init_cb init_cb;
 	hfp_slc_disconnect_cb disconnect_cb;
+	int initialized;
 	int cli_active;
 	int battery;
 	int signal;
 	int service;
 	int callheld;
 	int ind_event_report;
-	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;
 
 	struct cras_telephony_handle *telephony;
 };
@@ -104,7 +79,7 @@
 /* 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 */
@@ -115,35 +90,47 @@
 	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, AT_CMD("+CIEV: %d,%d"), ind_index, value);
+	snprintf(cmd, 64, "+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 +138,9 @@
 		return 0;
 
 	if (handle->telephony->call) {
-		snprintf(cmd, 64, AT_CMD("+CCWA: \"%s\",%d"), number, type);
+		snprintf(cmd, 64, "+CCWA: \"%s\",%d", number, type);
 	} else {
-		snprintf(cmd, 64, AT_CMD("+CLIP: \"%s\",%d"), number, type);
+		snprintf(cmd, 64, "+CLIP: \"%s\",%d", number, type);
 	}
 	return hfp_send(handle, cmd);
 }
@@ -162,7 +149,7 @@
 static int answer_call(struct hfp_slc_handle *handle, const char *cmd)
 {
 	int rc;
-	rc = hfp_send(handle, AT_CMD("OK"));
+	rc = hfp_send(handle, "OK");
 	if (rc)
 		return rc;
 
@@ -173,7 +160,7 @@
  * Mandatory support per spec 4.21. */
 static int call_waiting_notify(struct hfp_slc_handle *handle, const char *buf)
 {
-	return hfp_send(handle, AT_CMD("OK"));
+	return hfp_send(handle, "OK");
 }
 
 /* AT+CLIP command to enable the "Calling Line Identification notification"
@@ -182,7 +169,7 @@
 static int cli_notification(struct hfp_slc_handle *handle, const char *cmd)
 {
 	handle->cli_active = (cmd[8] == '1');
-	return hfp_send(handle, AT_CMD("OK"));
+	return hfp_send(handle, "OK");
 }
 
 /* ATDdd...dd command to place call with supplied number, or ATD>nnn...
@@ -200,15 +187,15 @@
 		 * 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, AT_CMD("ERROR"));
-	} else {
+		if (handle->telephony->dial_number == NULL || memory_location != 1)
+			return hfp_send(handle, "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, AT_CMD("OK"));
+	rc = hfp_send(handle, "OK");
 	if (rc)
 		return rc;
 
@@ -219,130 +206,7 @@
 /* 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, 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. */
-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, ",");
-
-	if (codec) {
-		BTLOG(btlog, BT_CODEC_SELECTION, 1, atoi(codec));
-		handle->selected_codec = atoi(codec);
-	}
-
-	err = hfp_send(handle, AT_CMD("OK"));
-	initialize_slc_handle(NULL, (void *)handle);
-	free(tokens);
-	return err;
-}
-
-/*
- * Possibly choose mSBC code from the supported codecs. Otherwise just
- * initialize the SLC so the default CVSD codec is used.
- */
-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]) {
-		/* 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(),
-					     CODEC_NEGOTIATION_TIMEOUT_MS,
-					     initialize_slc_handle, handle);
-	} else {
-		initialize_slc_handle(NULL, (void *)handle);
-	}
-}
-
-/* Handles the event when headset reports its available codecs list. */
-static int available_codecs(struct hfp_slc_handle *handle, const char *cmd)
-{
-	char *tokens, *id_str;
-	int id;
-
-	for (id = 0; id < HFP_MAX_CODECS; id++)
-		handle->hf_codec_supported[id] = false;
-
-	tokens = strdup(cmd);
-	strtok(tokens, "=");
-	id_str = strtok(NULL, ",");
-	while (id_str) {
-		id = atoi(id_str);
-		if ((id > HFP_CODEC_UNUSED) && (id < HFP_MAX_CODECS)) {
-			handle->hf_codec_supported[id] = true;
-			BTLOG(btlog, BT_AVAILABLE_CODECS, 0, id);
-		}
-		id_str = strtok(NULL, ",");
-	}
-
-	free(tokens);
-	return hfp_send(handle, AT_CMD("OK"));
+	return hfp_send(handle, "OK");
 }
 
 /* AT+CMER command enables the registration status update function in AG.
@@ -374,27 +238,27 @@
 	if (!mode || !tmp) {
 		syslog(LOG_ERR, "Invalid event reporting” cmd %s", cmd);
 		err = -EINVAL;
-		goto event_reporting_done;
+		goto event_reporting_err;
 	}
 	if (atoi(mode) == FORWARD_UNSOLICIT_RESULT_CODE)
 		handle->ind_event_report = atoi(tmp);
 
-	err = hfp_send(handle, AT_CMD("OK"));
+	err = hfp_send(handle, "OK");
 	if (err) {
 		syslog(LOG_ERR, "Error sending response for command %s", cmd);
-		goto event_reporting_done;
+		goto event_reporting_err;
 	}
 
-	/*
-	 * Consider the Service Level Connection to be fully initialized,
+	/* Consider the Service Level Connection to be fully initialized,
 	 * and thereby established, after successfully responded with OK.
-	 * However we should postpone the initialize call after codec selection,
-	 * otherwise iodev could be open immediately while the headset is still
-	 * communicating about which of CVSD or mSBC codec to use.
 	 */
-	choose_codec_and_init_slc(handle);
+	if (!handle->initialized) {
+		handle->initialized = 1;
+		if (handle->init_cb)
+			handle->init_cb(handle);
+	}
 
-event_reporting_done:
+event_reporting_err:
 	free(tokens);
 	return err;
 }
@@ -404,7 +268,7 @@
  */
 static int extended_errors(struct hfp_slc_handle *handle, const char *buf)
 {
-	return hfp_send(handle, AT_CMD("OK"));
+	return hfp_send(handle, "OK");
 }
 
 /* AT+CKPD command to handle the user initiated action from headset profile
@@ -412,7 +276,7 @@
  */
 static int key_press(struct hfp_slc_handle *handle, const char *buf)
 {
-	hfp_send(handle, AT_CMD("OK"));
+	hfp_send(handle, "OK");
 
 	/* Release the call and connection. */
 	if (handle->telephony->call || handle->telephony->callsetup) {
@@ -431,9 +295,9 @@
 	int rc;
 
 	if (!handle->telephony->dial_number)
-		return hfp_send(handle, AT_CMD("ERROR"));
+		return hfp_send(handle, "ERROR");
 
-	rc = hfp_send(handle, AT_CMD("OK"));
+	rc = hfp_send(handle, "OK");
 	if (rc)
 		return rc;
 
@@ -457,21 +321,23 @@
 	 * 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, AT_CMD("+CLCC: %d,1,1,0,0"), idx++);
+	if (handle->telephony->callheld)
+	{
+		snprintf(buf, 64, "+CLCC: %d,1,1,0,0", idx++);
 		rc = hfp_send(handle, buf);
 		if (rc)
 			return rc;
 	}
 
-	if (handle->telephony->call) {
-		snprintf(buf, 64, AT_CMD("+CLCC: %d,1,0,0,0"), idx++);
+	if (handle->telephony->call)
+	{
+		snprintf(buf, 64, "+CLCC: %d,1,0,0,0", idx++);
 		rc = hfp_send(handle, buf);
 		if (rc)
 			return rc;
 	}
 
-	return hfp_send(handle, AT_CMD("OK"));
+	return hfp_send(handle, "OK");
 }
 
 /* AT+COPS command to query currently selected operator or set name format.
@@ -480,17 +346,18 @@
 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, AT_CMD("+COPS: 0"));
+		rc = hfp_send(handle, "+COPS: 0");
 		if (rc)
 			return rc;
 	}
-	return hfp_send(handle, AT_CMD("OK"));
+	return hfp_send(handle, "OK");
 }
 
 /* AT+CIND command retrieves the supported indicator and its corresponding
@@ -504,7 +371,7 @@
 
 	if (cmd[7] == '=') {
 		/* Indicator update test command "AT+CIND=?" */
-		err = hfp_send(handle, AT_CMD(INDICATOR_UPDATE_RSP));
+		err = hfp_send(handle, INDICATOR_UPDATE_RSP);
 	} else {
 		/* Indicator update read command "AT+CIND?".
 		 * Respond with current status of AG indicators,
@@ -513,17 +380,21 @@
 		 * +CIND: <signal>,<service>,<call>,
 		 *        <callsetup>,<callheld>,<roam>
 		 */
-		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);
+		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
+			);
 		err = hfp_send(handle, buf);
 	}
 
 	if (err < 0)
 		return err;
 
-	return hfp_send(handle, AT_CMD("OK"));
+	return hfp_send(handle, "OK");
 }
 
 /* AT+BIA command to change the subset of indicators that shall be
@@ -534,13 +405,14 @@
 {
 	/* AT+BIA=[[<indrep 1>][,[<indrep 2>][,...[,[<indrep n>]]]]] */
 	syslog(LOG_ERR, "Bluetooth indicator activation command %s", cmd);
-	return hfp_send(handle, AT_CMD("OK"));
+	return hfp_send(handle, "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;
 
@@ -557,7 +429,7 @@
 						      (gain + 1) * 100 / 16);
 	}
 
-	return hfp_send(handle, AT_CMD("OK"));
+	return hfp_send(handle, "OK");
 }
 
 /* AT+CNUM command to query the subscriber number. Mandatory support
@@ -565,7 +437,7 @@
  */
 static int subscriber_number(struct hfp_slc_handle *handle, const char *buf)
 {
-	return hfp_send(handle, AT_CMD("OK"));
+	return hfp_send(handle, "OK");
 }
 
 /* AT+BRSF command notifies the HF(Hands-free device) supported features
@@ -574,38 +446,21 @@
  */
 static int supported_features(struct hfp_slc_handle *handle, const char *cmd)
 {
-	int err, hf_features;
+	int err;
 	char response[128];
-	char *tokens, *features;
-
 	if (strlen(cmd) < 9)
 		return -EINVAL;
 
-	handle->hf_supports_codec_negotiation = 0;
-
-	tokens = strdup(cmd);
-	strtok(tokens, "=");
-	features = strtok(NULL, ",");
-
-	hf_features = atoi(features);
-	BTLOG(btlog, BT_HFP_SUPPORTED_FEATURES, 0, hf_features);
-	if (hf_features & HF_CODEC_NEGOTIATION)
-		handle->hf_supports_codec_negotiation = 1;
-	free(tokens);
-
 	/* AT+BRSF=<feature> command received, ignore the HF supported feature
 	 * for now. Respond with +BRSF:<feature> to notify mandatory supported
 	 * features in AG(audio gateway).
 	 */
-	BTLOG(btlog, BT_HFP_SUPPORTED_FEATURES, 1,
-	      handle->ag_supported_features);
-	snprintf(response, 128, AT_CMD("+BRSF: %u"),
-		 handle->ag_supported_features);
+	snprintf(response, 128, "+BRSF: %u", HFP_SUPPORTED_FEATURE);
 	err = hfp_send(handle, response);
 	if (err < 0)
 		return err;
 
-	return hfp_send(handle, AT_CMD("OK"));
+	return hfp_send(handle, "OK");
 }
 
 int hfp_event_speaker_gain(struct hfp_slc_handle *handle, int gain)
@@ -614,7 +469,7 @@
 
 	/* Normailize gain value to 0-15 */
 	gain = gain * 15 / 100;
-	snprintf(command, 128, AT_CMD("+VGS=%d"), gain);
+	snprintf(command, 128, "+VGS=%d", gain);
 
 	return hfp_send(handle, command);
 }
@@ -625,7 +480,7 @@
 static int terminate_call(struct hfp_slc_handle *handle, const char *cmd)
 {
 	int rc;
-	rc = hfp_send(handle, AT_CMD("OK"));
+	rc = hfp_send(handle, "OK");
 	if (rc)
 		return rc;
 
@@ -668,38 +523,37 @@
  *                     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 struct at_command at_commands[] = {
+	{ "ATA", answer_call },
+	{ "ATD", dial_number },
+	{ "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 int handle_at_command(struct hfp_slc_handle *slc_handle,
+			     const char *cmd) {
 	struct at_command *atc;
 
 	for (atc = at_commands; atc->cmd; atc++)
 		if (!strncmp(cmd, atc->cmd, strlen(atc->cmd)))
 			return atc->callback(slc_handle, cmd);
 
-	syslog(LOG_DEBUG, "AT command %s not supported", cmd);
-	return hfp_send(slc_handle, AT_CMD("ERROR"));
+	syslog(LOG_ERR, "AT command %s not supported", cmd);
+	return hfp_send(slc_handle, "ERROR");
 }
 
 static void slc_watch_callback(void *arg)
@@ -708,9 +562,9 @@
 	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));
@@ -743,7 +597,8 @@
 	/* 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;
@@ -754,28 +609,25 @@
 		}
 	}
 
-	post_at_command_tasks(handle);
-
 	return;
 }
 
 /* Exported interfaces */
 
-struct hfp_slc_handle *hfp_slc_create(int fd, int is_hsp,
-				      int ag_supported_features,
+struct hfp_slc_handle *hfp_slc_create(int fd,
+				      int is_hsp,
 				      struct cras_bt_device *device,
 				      hfp_slc_init_cb init_cb,
 				      hfp_slc_disconnect_cb disconnect_cb)
 {
 	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;
 
 	handle->rfcomm_fd = fd;
 	handle->is_hsp = is_hsp;
-	handle->ag_supported_features = ag_supported_features;
 	handle->device = device;
 	handle->init_cb = init_cb;
 	handle->disconnect_cb = disconnect_cb;
@@ -785,11 +637,9 @@
 	handle->service = 1;
 	handle->ind_event_report = 0;
 	handle->telephony = cras_telephony_get();
-	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;
 }
@@ -797,23 +647,10 @@
 void hfp_slc_destroy(struct hfp_slc_handle *slc_handle)
 {
 	cras_system_rm_select_fd(slc_handle->rfcomm_fd);
-	if (slc_handle->timer)
-		cras_tm_cancel_timer(cras_system_state_get_tm(),
-				     slc_handle->timer);
 	close(slc_handle->rfcomm_fd);
 	free(slc_handle);
 }
 
-int hfp_slc_get_selected_codec(struct hfp_slc_handle *handle)
-{
-	/* 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)
 {
 	int old_call = handle->telephony->call;
@@ -832,7 +669,8 @@
  *                 <-- +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;
@@ -849,7 +687,7 @@
 	if (handle->telephony->call)
 		return 0;
 	else
-		return hfp_send(handle, AT_CMD("RING"));
+		return hfp_send(handle, "RING");
 }
 
 int hfp_event_update_call(struct hfp_slc_handle *handle)
@@ -889,8 +727,3 @@
 	handle->service = !!avail;
 	return hfp_send_ind_event_report(handle, SERVICE_IND_INDEX, avail);
 }
-
-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 fd3ee55..dd0d05f 100644
--- a/cras/src/server/cras_hfp_slc.h
+++ b/cras/src/server/cras_hfp_slc.h
@@ -7,42 +7,6 @@
 #define CRAS_HFP_SLC_H_
 
 struct hfp_slc_handle;
-struct cras_bt_device;
-
-/*
- * Hands-free HFP and AG supported features bits definition.
- * 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
-
-/* 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
 
 /* Callback to call when service level connection initialized. */
 typedef int (*hfp_slc_init_cb)(struct hfp_slc_handle *handle);
@@ -55,7 +19,6 @@
  * Args:
  *    fd - the rfcomm fd used to initialize service level connection
  *    is_hsp - if the slc handle is created for headset profile
- *    ag_supported_features - Supported AG features bitmap.
  *    device - The bt device associated with the created slc object
  *    init_cb - the callback function to be triggered when a service level
  *        connection is initialized.
@@ -63,7 +26,6 @@
  *        level connection is disconnected.
  */
 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);
@@ -75,7 +37,8 @@
 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.
@@ -102,10 +65,4 @@
 /* Sets speaker gain value to headsfree device. */
 int hfp_event_speaker_gain(struct hfp_slc_handle *handle, int gain);
 
-/* Gets the selected codec for HFP, mSBC or CVSD. */
-int hfp_slc_get_selected_codec(struct hfp_slc_handle *handle);
-
-/* Gets if the remote HF supports codec negotiation. */
-int hfp_slc_get_hf_codec_negotiation_supported(struct hfp_slc_handle *handle);
-
 #endif /* CRAS_HFP_SLC_H_ */
diff --git a/cras/src/server/cras_iodev.c b/cras/src/server/cras_iodev.c
index cf6b71e..3130b30 100644
--- a/cras/src/server/cras_iodev.c
+++ b/cras/src/server/cras_iodev.c
@@ -25,7 +25,6 @@
 #include "cras_mix.h"
 #include "cras_ramp.h"
 #include "cras_rstream.h"
-#include "cras_server_metrics.h"
 #include "cras_system_state.h"
 #include "cras_util.h"
 #include "dev_stream.h"
@@ -37,23 +36,6 @@
 static const float RAMP_UNMUTE_DURATION_SECS = 0.5;
 static const float RAMP_NEW_STREAM_DURATION_SECS = 0.01;
 static const float RAMP_MUTE_DURATION_SECS = 0.1;
-static const float RAMP_VOLUME_CHANGE_DURATION_SECS = 0.1;
-
-/*
- * It is the lastest time for the device to wake up when it is in the normal
- * run state. It represents how many remaining frames in the device buffer.
- */
-static const struct timespec dev_normal_run_wake_up_time = {
-	0, 1 * 1000 * 1000 /* 1 msec. */
-};
-
-/*
- * It is the lastest time for the device to wake up when it is in the no stream
- * state. It represents how many remaining frames in the device buffer.
- */
-static const struct timespec dev_no_stream_wake_up_time = {
-	0, 5 * 1000 * 1000 /* 5 msec. */
-};
 
 /*
  * Check issu b/72496547 and commit message for the history of
@@ -91,8 +73,8 @@
 		hw_level = rc;
 	}
 
-	ATLOG(atlog, AUDIO_THREAD_ODEV_DEFAULT_NO_STREAMS, odev->info.idx,
-	      hw_level, target_hw_level);
+	ATLOG(atlog, AUDIO_THREAD_ODEV_DEFAULT_NO_STREAMS,
+	      odev->info.idx, hw_level, target_hw_level);
 
 	fr_to_write = cras_iodev_buffer_avail(odev, hw_level);
 	if (hw_level <= target_hw_level) {
@@ -123,18 +105,14 @@
 /* Gets the number of frames ready for this device to play.
  * It is the minimum number of available samples in dev_streams.
  */
-static unsigned int dev_playback_frames(struct cras_iodev *odev)
+static unsigned int dev_playback_frames(struct cras_iodev* odev)
 {
 	struct dev_stream *curr;
 	int frames = 0;
 
-	DL_FOREACH (odev->streams, curr) {
+	DL_FOREACH(odev->streams, curr) {
 		int dev_frames;
 
-		/* Skip stream which hasn't started running yet. */
-		if (!dev_stream_is_running(curr))
-			continue;
-
 		/* If this is a single output dev stream, updates the latest
 		 * number of frames for playback. */
 		if (dev_stream_attached_devs(curr) == 1)
@@ -146,7 +124,7 @@
 		if (dev_frames < 0)
 			continue;
 		if (!dev_frames) {
-			if (cras_rstream_get_is_draining(curr->stream))
+			if(cras_rstream_get_is_draining(curr->stream))
 				continue;
 			else
 				return 0;
@@ -182,11 +160,11 @@
 		return -EINVAL;
 
 	if (enable) {
-		ATLOG(atlog, AUDIO_THREAD_ODEV_NO_STREAMS, odev->info.idx, 0,
-		      0);
+		ATLOG(atlog, AUDIO_THREAD_ODEV_NO_STREAMS,
+		      odev->info.idx, 0, 0);
 	} else {
-		ATLOG(atlog, AUDIO_THREAD_ODEV_LEAVE_NO_STREAMS, odev->info.idx,
-		      0, 0);
+		ATLOG(atlog, AUDIO_THREAD_ODEV_LEAVE_NO_STREAMS,
+		      odev->info.idx, 0, 0);
 	}
 
 	rc = odev->no_stream(odev, enable);
@@ -219,7 +197,7 @@
 	system_volume = cras_system_get_volume();
 	if (odev->active_node) {
 		adjusted_node_volume = cras_iodev_adjust_node_volume(
-			odev->active_node, system_volume);
+				odev->active_node, system_volume);
 		return (adjusted_node_volume == 0);
 	}
 	return (system_volume == 0);
@@ -274,8 +252,8 @@
 		 * from stream later.
 		 * Starts the device here to finish state transition. */
 		cras_iodev_fill_odev_zeros(odev, odev->min_cb_level);
-		ATLOG(atlog, AUDIO_THREAD_ODEV_START, odev->info.idx,
-		      odev->min_cb_level, 0);
+		ATLOG(atlog, AUDIO_THREAD_ODEV_START,
+				odev->info.idx, odev->min_cb_level, 0);
 		return cras_iodev_start(odev);
 	} else if (odev->state == CRAS_IODEV_STATE_NO_STREAM_RUN) {
 		/* S3 => S2:
@@ -307,7 +285,8 @@
 		return 0;
 
 	for (i = 0, best = 0; iodev->supported_rates[i] != 0; i++) {
-		if (rrate == iodev->supported_rates[i] && rrate >= 44100)
+		if (rrate == iodev->supported_rates[i] &&
+		    rrate >= 44100)
 			return rrate;
 		if (best == 0 && (rrate % iodev->supported_rates[i] == 0 ||
 				  iodev->supported_rates[i] % rrate == 0))
@@ -342,7 +321,7 @@
 	 */
 	for (i = 0; iodev->supported_channel_counts[i] != 0; i++) {
 		if (iodev->supported_channel_counts[i] ==
-		    preferred_channel_count)
+				preferred_channel_count)
 			return preferred_channel_count;
 	}
 
@@ -379,7 +358,9 @@
 	if (!pipeline)
 		return 0;
 
-	rc = cras_dsp_pipeline_apply(pipeline, buf, iodev->format->format,
+	rc = cras_dsp_pipeline_apply(pipeline,
+				     buf,
+				     iodev->format->format,
 				     frames);
 
 	cras_dsp_put_pipeline(ctx);
@@ -403,17 +384,25 @@
 	if (!ctx || !cras_dsp_get_pipeline(ctx))
 		return;
 
-	if (iodev->direction == CRAS_STREAM_OUTPUT)
-		iodev->format->num_channels = cras_dsp_num_output_channels(ctx);
-	else
-		iodev->format->num_channels = cras_dsp_num_input_channels(ctx);
+	if (iodev->direction == CRAS_STREAM_OUTPUT) {
+		iodev->format->num_channels =
+			cras_dsp_num_output_channels(ctx);
+		iodev->ext_format->num_channels =
+			cras_dsp_num_input_channels(ctx);
+	} else {
+		iodev->format->num_channels =
+			cras_dsp_num_input_channels(ctx);
+		iodev->ext_format->num_channels =
+			cras_dsp_num_output_channels(ctx);
+	}
 
 	cras_dsp_put_pipeline(ctx);
 }
 
 /* Updates channel layout based on the number of channels set by a
- * client stream. Set a default value to format if the update call
- * fails.
+ * client stream. When successful we need to update the new channel
+ * layout to ext_format, otherwise we should set a default value
+ * to both format and ext_format.
  */
 static void update_channel_layout(struct cras_iodev *iodev)
 {
@@ -423,8 +412,14 @@
 		return;
 
 	rc = iodev->update_channel_layout(iodev);
-	if (rc < 0)
+	if (rc < 0) {
 		cras_audio_format_set_default_channel_layout(iodev->format);
+		cras_audio_format_set_default_channel_layout(iodev->ext_format);
+	} else {
+		cras_audio_format_set_channel_layout(
+				iodev->ext_format,
+				iodev->format->channel_layout);
+	}
 }
 
 /*
@@ -432,8 +427,7 @@
  * are higher than the supported number of channels. Should be used when the
  * number of channels of the format been reduced.
  */
-static void trim_channel_layout(struct cras_audio_format *fmt)
-{
+static void trim_channel_layout(struct cras_audio_format *fmt) {
 	int i;
 	for (i = 0; i < CRAS_CH_MAX; i++)
 		if (fmt->channel_layout[i] >= fmt->num_channels)
@@ -451,9 +445,11 @@
 	 * requested in "fmt". */
 	if (iodev->format == NULL) {
 		iodev->format = malloc(sizeof(struct cras_audio_format));
-		if (!iodev->format)
+		iodev->ext_format = malloc(sizeof(struct cras_audio_format));
+		if (!iodev->format || !iodev->ext_format)
 			return -ENOMEM;
 		*iodev->format = *fmt;
+		*iodev->ext_format = *fmt;
 
 		if (iodev->update_supported_formats) {
 			rc = iodev->update_supported_formats(iodev);
@@ -468,14 +464,15 @@
 		 * stream. */
 		actual_rate = get_best_rate(iodev, fmt->frame_rate);
 		iodev->format->frame_rate = actual_rate;
+		iodev->ext_format->frame_rate = actual_rate;
 
 		cras_iodev_alloc_dsp(iodev);
 		cras_iodev_update_dsp(iodev);
 		if (iodev->dsp_context)
 			adjust_dev_channel_for_dsp(iodev);
 
-		actual_num_channels = get_best_channel_count(
-			iodev, iodev->format->num_channels);
+		actual_num_channels = get_best_channel_count(iodev,
+					iodev->format->num_channels);
 		actual_format = get_best_pcm_format(iodev, fmt->format);
 		if (actual_rate == 0 || actual_num_channels == 0 ||
 		    actual_format == 0) {
@@ -484,10 +481,13 @@
 			goto error;
 		}
 		iodev->format->format = actual_format;
+		iodev->ext_format->format = actual_format;
 		if (iodev->format->num_channels != actual_num_channels) {
 			/* If the DSP for this device doesn't match, drop it. */
 			iodev->format->num_channels = actual_num_channels;
 			trim_channel_layout(iodev->format);
+			iodev->ext_format->num_channels = actual_num_channels;
+			trim_channel_layout(iodev->ext_format);
 			cras_iodev_free_dsp(iodev);
 		}
 
@@ -495,8 +495,9 @@
 
 		if (!iodev->rate_est)
 			iodev->rate_est = rate_estimator_create(
-				actual_rate, &rate_estimation_window_sz,
-				rate_estimation_smooth_factor);
+						actual_rate,
+						&rate_estimation_window_sz,
+						rate_estimation_smooth_factor);
 		else
 			rate_estimator_reset_rate(iodev->rate_est, actual_rate);
 	}
@@ -505,7 +506,9 @@
 
 error:
 	free(iodev->format);
+	free(iodev->ext_format);
 	iodev->format = NULL;
+	iodev->ext_format = NULL;
 	return rc;
 }
 
@@ -516,49 +519,31 @@
 {
 	struct pipeline *pipeline;
 
-	pipeline = iodev->dsp_context ?
-			   cras_dsp_get_pipeline(iodev->dsp_context) :
-			   NULL;
+	if (!iodev->ext_dsp_module)
+		return;
+
+	iodev->ext_dsp_module->configure(
+			iodev->ext_dsp_module,
+			iodev->buffer_size,
+			iodev->ext_format->num_channels,
+			iodev->ext_format->frame_rate);
+
+	pipeline = iodev->dsp_context
+			? cras_dsp_get_pipeline(iodev->dsp_context)
+			: NULL;
 
 	if (!pipeline) {
 		cras_iodev_alloc_dsp(iodev);
-		cras_dsp_load_dummy_pipeline(iodev->dsp_context,
-					     iodev->format->num_channels);
+		cras_dsp_load_dummy_pipeline(
+			iodev->dsp_context,
+			iodev->format->num_channels);
 		pipeline = cras_dsp_get_pipeline(iodev->dsp_context);
 	}
-	/* dsp_context mutex locked. Now it's safe to modify dsp
-	 * pipeline resources. */
 
-	if (iodev->ext_dsp_module)
-		iodev->ext_dsp_module->configure(iodev->ext_dsp_module,
-						 iodev->buffer_size,
-						 iodev->format->num_channels,
-						 iodev->format->frame_rate);
+	cras_dsp_pipeline_set_sink_ext_module(
+			pipeline,
+			iodev->ext_dsp_module);
 
-	cras_dsp_pipeline_set_sink_ext_module(pipeline, iodev->ext_dsp_module);
-
-	/* Unlock dsp_context mutex. */
-	cras_dsp_put_pipeline(iodev->dsp_context);
-}
-
-/*
- * Releases the ext_dsp_module if it ever added to iodev's dsp pipeline.
- */
-static void release_ext_dsp_module_from_pipeline(struct cras_iodev *iodev)
-{
-	struct pipeline *pipeline;
-
-	if (iodev->dsp_context == NULL)
-		return;
-
-	pipeline = cras_dsp_get_pipeline(iodev->dsp_context);
-	if (pipeline == NULL)
-		return;
-	/* dsp_context mutex locked. */
-
-	cras_dsp_pipeline_set_sink_ext_module(pipeline, NULL);
-
-	/* Unlock dsp_context mutex. */
 	cras_dsp_put_pipeline(iodev->dsp_context);
 }
 
@@ -567,13 +552,9 @@
 {
 	iodev->ext_dsp_module = ext;
 
-	if (!cras_iodev_is_open(iodev))
+	if (!ext || !cras_iodev_is_open(iodev))
 		return;
-
-	if (iodev->ext_dsp_module)
-		add_ext_dsp_module_to_pipeline(iodev);
-	else
-		release_ext_dsp_module_from_pipeline(iodev);
+	add_ext_dsp_module_to_pipeline(iodev);
 }
 
 void cras_iodev_update_dsp(struct cras_iodev *iodev)
@@ -584,7 +565,7 @@
 		return;
 
 	cras_dsp_set_variable_string(iodev->dsp_context, "dsp_name",
-				     iodev->dsp_name ?: "");
+				     iodev->dsp_name ? : "");
 
 	if (iodev->active_node && iodev->active_node->left_right_swapped)
 		swap_lr_disabled = 0;
@@ -595,8 +576,9 @@
 	cras_dsp_load_pipeline(iodev->dsp_context);
 }
 
+
 int cras_iodev_dsp_set_swap_mode_for_node(struct cras_iodev *iodev,
-					  struct cras_ionode *node, int enable)
+					   struct cras_ionode *node, int enable)
 {
 	if (node->left_right_swapped == enable)
 		return 0;
@@ -616,10 +598,14 @@
 void cras_iodev_free_format(struct cras_iodev *iodev)
 {
 	free(iodev->format);
+	free(iodev->ext_format);
 	iodev->format = NULL;
+	iodev->ext_format = NULL;
 }
 
-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)
 {
 	if (iodev->area)
 		cras_iodev_free_audio_area(iodev);
@@ -655,11 +641,12 @@
 		purpose = "capture";
 
 	cras_iodev_free_dsp(iodev);
-	iodev->dsp_context =
-		cras_dsp_context_new(iodev->format->frame_rate, purpose);
+	iodev->dsp_context = cras_dsp_context_new(iodev->format->frame_rate,
+						  purpose);
 }
 
-void cras_iodev_fill_time_from_frames(size_t frames, size_t frame_rate,
+void cras_iodev_fill_time_from_frames(size_t frames,
+				      size_t frame_rate,
 				      struct timespec *ts)
 {
 	uint64_t to_play_usec;
@@ -676,7 +663,7 @@
 }
 
 /* This is called when a node is plugged/unplugged */
-void cras_iodev_set_node_plugged(struct cras_ionode *node, int plugged)
+static void plug_node(struct cras_ionode *node, int plugged)
 {
 	if (node->plugged == plugged)
 		return;
@@ -689,6 +676,78 @@
 	cras_iodev_list_notify_nodes_changed();
 }
 
+static void set_node_volume(struct cras_ionode *node, int value)
+{
+	struct cras_iodev *dev = node->dev;
+	unsigned int volume;
+
+	if (dev->direction != CRAS_STREAM_OUTPUT)
+		return;
+
+	volume = (unsigned int)MIN(value, 100);
+	node->volume = volume;
+	if (dev->set_volume)
+		dev->set_volume(dev);
+
+	cras_iodev_list_notify_node_volume(node);
+}
+
+static void set_node_capture_gain(struct cras_ionode *node, int value)
+{
+	struct cras_iodev *dev = node->dev;
+
+	if (dev->direction != CRAS_STREAM_INPUT)
+		return;
+
+	node->capture_gain = (long)value;
+	if (dev->set_capture_gain)
+		dev->set_capture_gain(dev);
+
+	cras_iodev_list_notify_node_capture_gain(node);
+}
+
+static void set_node_left_right_swapped(struct cras_ionode *node, int value)
+{
+	struct cras_iodev *dev = node->dev;
+	int rc;
+
+	if (!dev->set_swap_mode_for_node)
+		return;
+	rc = dev->set_swap_mode_for_node(dev, node, value);
+	if (rc) {
+		syslog(LOG_ERR,
+		       "Failed to set swap mode on node %s to %d; error %d",
+		       node->name, value, rc);
+		return;
+	}
+	node->left_right_swapped = value;
+	cras_iodev_list_notify_node_left_right_swapped(node);
+	return;
+}
+
+int cras_iodev_set_node_attr(struct cras_ionode *ionode,
+			     enum ionode_attr attr, int value)
+{
+	switch (attr) {
+	case IONODE_ATTR_PLUGGED:
+		plug_node(ionode, value);
+		break;
+	case IONODE_ATTR_VOLUME:
+		set_node_volume(ionode, value);
+		break;
+	case IONODE_ATTR_CAPTURE_GAIN:
+		set_node_capture_gain(ionode, value);
+		break;
+	case IONODE_ATTR_SWAP_LEFT_RIGHT:
+		set_node_left_right_swapped(ionode, value);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 void cras_iodev_add_node(struct cras_iodev *iodev, struct cras_ionode *node)
 {
 	DL_APPEND(iodev->nodes, node);
@@ -712,69 +771,32 @@
 {
 	unsigned int volume;
 
-	volume = cras_iodev_adjust_active_node_volume(iodev,
-						      cras_system_get_volume());
+	volume = cras_iodev_adjust_active_node_volume(
+			iodev, cras_system_get_volume());
 
 	if (iodev->active_node && iodev->active_node->softvol_scalers)
 		return iodev->active_node->softvol_scalers[volume];
 	return softvol_get_scaler(volume);
 }
 
-float cras_iodev_get_software_gain_scaler(const struct cras_iodev *iodev)
-{
+float cras_iodev_get_software_gain_scaler(const struct cras_iodev *iodev) {
 	float scaler = 1.0f;
 	if (cras_iodev_software_volume_needed(iodev)) {
 		long gain = cras_iodev_adjust_active_node_gain(
-			iodev, cras_system_get_capture_gain());
+				iodev, cras_system_get_capture_gain());
 		scaler = convert_softvol_scaler_from_dB(gain);
 	}
 	return scaler;
 }
 
-int cras_iodev_get_valid_frames(struct cras_iodev *odev,
-				struct timespec *hw_tstamp)
-{
-	int rc;
-
-	if (odev->direction != CRAS_STREAM_OUTPUT)
-		return -EINVAL;
-
-	if (odev->get_valid_frames) {
-		rc = odev->get_valid_frames(odev, hw_tstamp);
-		if (rc < 0)
-			return rc;
-
-		if (rc < odev->min_buffer_level)
-			return 0;
-
-		return rc - odev->min_buffer_level;
-	} else {
-		return cras_iodev_frames_queued(odev, hw_tstamp);
-	}
-}
-
-int cras_iodev_add_stream(struct cras_iodev *iodev, struct dev_stream *stream)
-{
-	/*
-	 * For input stream, start stream right after adding stream.
-	 * For output stream, start stream after its first fetch such that it does not
-	 * block other existing streams.
-	 */
-	DL_APPEND(iodev->streams, stream);
-	if (!iodev->buf_state)
-		iodev->buf_state = buffer_share_create(iodev->buffer_size);
-	if (stream->stream->direction == CRAS_STREAM_INPUT)
-		cras_iodev_start_stream(iodev, stream);
-	return 0;
-}
-
-void cras_iodev_start_stream(struct cras_iodev *iodev,
-			     struct dev_stream *stream)
+int cras_iodev_add_stream(struct cras_iodev *iodev,
+			  struct dev_stream *stream)
 {
 	unsigned int cb_threshold = dev_stream_cb_threshold(stream);
+	DL_APPEND(iodev->streams, stream);
 
-	if (dev_stream_is_running(stream))
-		return;
+	if (!iodev->buf_state)
+		iodev->buf_state = buffer_share_create(iodev->buffer_size);
 	/*
 	 * TRIGGER_ONLY streams do not want to receive data, so do not add them
 	 * to buffer_share, otherwise they'll affect other streams to receive.
@@ -782,10 +804,10 @@
 	if (!(stream->stream->flags & TRIGGER_ONLY))
 		buffer_share_add_id(iodev->buf_state, stream->stream->stream_id,
 				    NULL);
+
 	iodev->min_cb_level = MIN(iodev->min_cb_level, cb_threshold);
 	iodev->max_cb_level = MAX(iodev->max_cb_level, cb_threshold);
-	iodev->largest_cb_level = MAX(iodev->largest_cb_level, cb_threshold);
-	dev_stream_set_running(stream);
+	return 0;
 }
 
 struct dev_stream *cras_iodev_rm_stream(struct cras_iodev *iodev,
@@ -794,12 +816,10 @@
 	struct dev_stream *out;
 	struct dev_stream *ret = NULL;
 	unsigned int cb_threshold;
-	struct timespec earliest_next_cb_ts;
-	int set_earliest = 0;
 
 	iodev->min_cb_level = iodev->buffer_size / 2;
 	iodev->max_cb_level = 0;
-	DL_FOREACH (iodev->streams, out) {
+	DL_FOREACH(iodev->streams, out) {
 		if (out->stream == rstream) {
 			buffer_share_rm_id(iodev->buf_state,
 					   rstream->stream_id);
@@ -807,18 +827,9 @@
 			DL_DELETE(iodev->streams, out);
 			continue;
 		}
-		if (!dev_stream_is_running(out))
-			continue;
 		cb_threshold = dev_stream_cb_threshold(out);
 		iodev->min_cb_level = MIN(iodev->min_cb_level, cb_threshold);
 		iodev->max_cb_level = MAX(iodev->max_cb_level, cb_threshold);
-		if (!set_earliest) {
-			set_earliest = 1;
-			earliest_next_cb_ts = out->stream->next_cb_ts;
-		}
-		if (timespec_after(&earliest_next_cb_ts,
-				   &out->stream->next_cb_ts))
-			earliest_next_cb_ts = out->stream->next_cb_ts;
 	}
 
 	if (!iodev->streams) {
@@ -832,15 +843,6 @@
 		    (iodev->state == CRAS_IODEV_STATE_NORMAL_RUN))
 			cras_iodev_no_stream_playback_transition(iodev, 1);
 	}
-
-	if (!set_earliest)
-		return ret;
-
-	DL_FOREACH (iodev->streams, out) {
-		if (!dev_stream_is_running(out))
-			out->stream->next_cb_ts = earliest_next_cb_ts;
-	}
-
 	return ret;
 }
 
@@ -852,10 +854,11 @@
 }
 
 void cras_iodev_stream_written(struct cras_iodev *iodev,
-			       struct dev_stream *stream, unsigned int nwritten)
+			       struct dev_stream *stream,
+			       unsigned int nwritten)
 {
-	buffer_share_offset_update(iodev->buf_state, stream->stream->stream_id,
-				   nwritten);
+	buffer_share_offset_update(iodev->buf_state,
+				   stream->stream->stream_id, nwritten);
 }
 
 unsigned int cras_iodev_all_streams_written(struct cras_iodev *iodev)
@@ -870,13 +873,10 @@
 	unsigned int max = 0;
 	struct dev_stream *curr;
 
-	DL_FOREACH (iodev->streams, curr) {
-		/* Skip stream which hasn't started running yet. */
-		if (!dev_stream_is_running(curr))
-			continue;
-
-		max = MAX(max, buffer_share_id_offset(iodev->buf_state,
-						      curr->stream->stream_id));
+	DL_FOREACH(iodev->streams, curr) {
+		max = MAX(max,
+			  buffer_share_id_offset(iodev->buf_state,
+						 curr->stream->stream_id));
 	}
 
 	return max;
@@ -885,24 +885,18 @@
 int cras_iodev_open(struct cras_iodev *iodev, unsigned int cb_level,
 		    const struct cras_audio_format *fmt)
 {
-	struct cras_loopback *loopback;
 	int rc;
 
 	if (iodev->pre_open_iodev_hook)
 		iodev->pre_open_iodev_hook();
 
-	DL_FOREACH (iodev->loopbacks, loopback) {
-		if (loopback->hook_control)
-			loopback->hook_control(true, loopback->cb_data);
-	}
-
 	if (iodev->open_dev) {
 		rc = iodev->open_dev(iodev);
 		if (rc)
 			return rc;
 	}
 
-	if (iodev->format == NULL) {
+	if (iodev->ext_format == NULL) {
 		rc = cras_iodev_set_format(iodev, fmt);
 		if (rc) {
 			iodev->close_dev(iodev);
@@ -919,17 +913,16 @@
 	/*
 	 * Convert cb_level from input format to device format
 	 */
-	cb_level = cras_frames_at_rate(fmt->frame_rate, cb_level,
-				       iodev->format->frame_rate);
+	cb_level = cras_frames_at_rate(fmt->frame_rate,
+				       cb_level,
+				       iodev->ext_format->frame_rate);
 	/* Make sure the min_cb_level doesn't get too large. */
 	iodev->min_cb_level = MIN(iodev->buffer_size / 2, cb_level);
 	iodev->max_cb_level = 0;
-	iodev->largest_cb_level = 0;
 
 	iodev->reset_request_pending = 0;
 	iodev->state = CRAS_IODEV_STATE_OPEN;
 	iodev->highest_hw_level = 0;
-	iodev->input_dsp_offset = 0;
 
 	if (iodev->direction == CRAS_STREAM_OUTPUT) {
 		/* If device supports start ops, device can be in open state.
@@ -952,19 +945,9 @@
 		iodev->state = CRAS_IODEV_STATE_NORMAL_RUN;
 		/* Initialize the input_streaming flag to zero.*/
 		iodev->input_streaming = 0;
-
-		/*
-		 * The device specific gain scaler to be used in audio thread.
-		 * It's expected to stick to 1.0f if device has hardware gain
-		 * control. For alsa device, this gain value can be configured
-		 * through UCM labels DefaultNodeGain.
-		 */
-		iodev->software_gain_scaler =
-			cras_iodev_get_software_gain_scaler(iodev);
 	}
 
 	add_ext_dsp_module_to_pipeline(iodev);
-	clock_gettime(CLOCK_MONOTONIC_RAW, &iodev->open_ts);
 
 	return 0;
 }
@@ -976,14 +959,11 @@
 
 int cras_iodev_close(struct cras_iodev *iodev)
 {
-	struct cras_loopback *loopback;
 	int rc;
 
 	if (!cras_iodev_is_open(iodev))
 		return 0;
 
-	cras_server_metrics_device_runtime(iodev);
-
 	if (iodev->input_data) {
 		if (iodev->ext_dsp_module == &iodev->input_data->ext)
 			iodev->ext_dsp_module = NULL;
@@ -999,12 +979,6 @@
 
 	if (iodev->post_close_iodev_hook)
 		iodev->post_close_iodev_hook();
-
-	DL_FOREACH (iodev->loopbacks, loopback) {
-		if (loopback->hook_control)
-			loopback->hook_control(false, loopback->cb_data);
-	}
-
 	return 0;
 }
 
@@ -1013,7 +987,6 @@
 	unsigned int min_frames;
 	unsigned int dsp_frames;
 	struct input_data *data = iodev->input_data;
-	int rc;
 
 	if (iodev->streams)
 		min_frames = buffer_share_get_new_write_point(iodev->buf_state);
@@ -1026,10 +999,7 @@
 
 	input_data_set_all_streams_read(data, min_frames);
 	rate_estimator_add_frames(iodev->rate_est, -min_frames);
-	rc = iodev->put_buffer(iodev, min_frames);
-	if (rc < 0)
-		return rc;
-	return min_frames;
+	return iodev->put_buffer(iodev, min_frames);
 }
 
 int cras_iodev_put_output_buffer(struct cras_iodev *iodev, uint8_t *frames,
@@ -1041,43 +1011,26 @@
 		.type = CRAS_RAMP_ACTION_NONE,
 		.scaler = 0.0f,
 		.increment = 0.0f,
-		.target = 1.0f,
 	};
 	float software_volume_scaler = 1.0;
 	int software_volume_needed = cras_iodev_software_volume_needed(iodev);
 	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;
-			}
-		}
-	}
+	if (iodev->pre_dsp_hook)
+		iodev->pre_dsp_hook(frames, nframes, iodev->ext_format,
+				    iodev->pre_dsp_hook_cb_data);
 
-	DL_FOREACH (iodev->loopbacks, loopback) {
-		if (loopback->type == LOOPBACK_POST_MIX_PRE_DSP)
-			loopback->hook_data(frames, nframes, iodev->format,
-					    loopback->cb_data);
+	if (iodev->ramp) {
+		ramp_action = cras_ramp_get_current_action(iodev->ramp);
 	}
 
 	rc = apply_dsp(iodev, frames, nframes);
 	if (rc)
 		return rc;
 
-	DL_FOREACH (iodev->loopbacks, loopback) {
-		if (loopback->type == LOOPBACK_POST_DSP)
-			loopback->hook_data(frames, nframes, iodev->format,
-					    loopback->cb_data);
-	}
-
-	if (iodev->ramp) {
-		ramp_action = cras_ramp_get_current_action(iodev->ramp);
-	}
+	if (iodev->post_dsp_hook)
+		iodev->post_dsp_hook(frames, nframes, fmt,
+				     iodev->post_dsp_hook_cb_data);
 
 	/* Mute samples if adjusted volume is 0 or system is muted, plus
 	 * that this device is not ramping. */
@@ -1085,6 +1038,9 @@
 	    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. */
@@ -1098,31 +1054,42 @@
 		 * software volume using cras_scale_buffer_increment.*/
 		float starting_scaler = ramp_action.scaler;
 		float increment = ramp_action.increment;
-		float target = ramp_action.target;
 
 		if (software_volume_needed) {
 			starting_scaler *= software_volume_scaler;
 			increment *= software_volume_scaler;
-			target *= software_volume_scaler;
 		}
 
-		cras_scale_buffer_increment(fmt->format, frames, nframes,
-					    starting_scaler, increment, target,
-					    fmt->num_channels);
+		cras_scale_buffer_increment(
+				fmt->format, frames, nframes,
+				starting_scaler, increment,
+				fmt->num_channels);
 		cras_ramp_update_ramped_frames(iodev->ramp, nframes);
 	} else if (!output_should_mute(iodev) && software_volume_needed) {
 		/* Just scale for software volume using
 		 * cras_scale_buffer. */
 		unsigned int nsamples = nframes * fmt->num_channels;
-		cras_scale_buffer(fmt->format, frames, nsamples,
-				  software_volume_scaler);
+		cras_scale_buffer(fmt->format, frames,
+				  nsamples, software_volume_scaler);
 	}
 
 	if (remix_converter)
-		cras_channel_remix_convert(remix_converter, iodev->format,
-					   frames, nframes);
-	if (iodev->rate_est)
-		rate_estimator_add_frames(iodev->rate_est, nframes);
+		cras_channel_remix_convert(remix_converter,
+				   iodev->format,
+				   frames,
+				   nframes);
+	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);
 }
@@ -1142,8 +1109,7 @@
 	if (*frames > frame_requested) {
 		syslog(LOG_ERR,
 		       "frames returned from get_buffer is greater than "
-		       "requested: %u > %u",
-		       *frames, frame_requested);
+		       "requested: %u > %u", *frames, frame_requested);
 		return -EINVAL;
 	}
 
@@ -1152,6 +1118,7 @@
 	/* TODO(hychao) - This assumes interleaved audio. */
 	hw_buffer = data->area->channels[0].buf;
 
+
 	/*
 	 * input_dsp_offset records the position where input dsp has applied to
 	 * last time. It's possible the requested |frames| count is smaller
@@ -1162,9 +1129,8 @@
 	 * already applied dsp.
 	 */
 	if (*frames > iodev->input_dsp_offset) {
-		rc = apply_dsp(iodev,
-			       hw_buffer +
-				       iodev->input_dsp_offset * frame_bytes,
+		rc = apply_dsp(iodev, hw_buffer +
+			       iodev->input_dsp_offset * frame_bytes,
 			       *frames - iodev->input_dsp_offset);
 		if (rc)
 			return rc;
@@ -1187,8 +1153,7 @@
 	if (*frames > frame_requested) {
 		syslog(LOG_ERR,
 		       "frames returned from get_buffer is greater than "
-		       "requested: %u > %u",
-		       *frames, frame_requested);
+		       "requested: %u > %u", *frames, frame_requested);
 		return -EINVAL;
 	}
 	return rc;
@@ -1200,21 +1165,22 @@
 	/* If output underruns, reset to avoid incorrect estimated rate. */
 	if ((iodev->direction == CRAS_STREAM_OUTPUT) && !level)
 		rate_estimator_reset_rate(iodev->rate_est,
-					  iodev->format->frame_rate);
+					  iodev->ext_format->frame_rate);
 
 	return rate_estimator_check(iodev->rate_est, level, level_tstamp);
 }
 
 int cras_iodev_reset_rate_estimator(const struct cras_iodev *iodev)
 {
-	rate_estimator_reset_rate(iodev->rate_est, iodev->format->frame_rate);
+	rate_estimator_reset_rate(iodev->rate_est,
+				  iodev->ext_format->frame_rate);
 	return 0;
 }
 
 double cras_iodev_get_est_rate_ratio(const struct cras_iodev *iodev)
 {
 	return rate_estimator_get_rate(iodev->rate_est) /
-	       iodev->format->frame_rate;
+			iodev->ext_format->frame_rate;
 }
 
 int cras_iodev_get_dsp_delay(const struct cras_iodev *iodev)
@@ -1243,8 +1209,8 @@
 	int rc;
 
 	rc = iodev->frames_queued(iodev, hw_tstamp);
-	if (rc == -EPIPE)
-		cras_audio_thread_event_severe_underrun();
+	if(rc == -EPIPE)
+		cras_audio_thread_severe_underrun();
 
 	if (rc < 0)
 		return rc;
@@ -1272,6 +1238,22 @@
 	return iodev->buffer_size - iodev->min_buffer_level - hw_level;
 }
 
+void cras_iodev_register_pre_dsp_hook(struct cras_iodev *iodev,
+				      loopback_hook_t loop_cb,
+				      void *cb_data)
+{
+	iodev->pre_dsp_hook = loop_cb;
+	iodev->pre_dsp_hook_cb_data = cb_data;
+}
+
+void cras_iodev_register_post_dsp_hook(struct cras_iodev *iodev,
+				       loopback_hook_t loop_cb,
+				       void *cb_data)
+{
+	iodev->post_dsp_hook = loop_cb;
+	iodev->post_dsp_hook_cb_data = cb_data;
+}
+
 int cras_iodev_fill_odev_zeros(struct cras_iodev *odev, unsigned int frames)
 {
 	struct cras_audio_area *area = NULL;
@@ -1284,7 +1266,7 @@
 
 	ATLOG(atlog, AUDIO_THREAD_FILL_ODEV_ZEROS, odev->info.idx, frames, 0);
 
-	frame_bytes = cras_get_format_bytes(odev->format);
+	frame_bytes = cras_get_format_bytes(odev->ext_format);
 	while (frames > 0) {
 		frames_written = frames;
 		rc = cras_iodev_get_output_buffer(odev, &area, &frames_written);
@@ -1296,17 +1278,16 @@
 		/* This assumes consecutive channel areas. */
 		buf = area->channels[0].buf;
 		memset(buf, 0, frames_written * frame_bytes);
-		cras_iodev_put_output_buffer(odev, buf, frames_written, NULL,
-					     NULL);
+		cras_iodev_put_output_buffer(odev, buf, frames_written,
+					     NULL, NULL);
 		frames -= frames_written;
 	}
 
 	return 0;
 }
 
-int cras_iodev_output_underrun(struct cras_iodev *odev)
-{
-	cras_audio_thread_event_underrun();
+int cras_iodev_output_underrun(struct cras_iodev *odev) {
+	cras_audio_thread_underrun();
 	if (odev->output_underrun)
 		return odev->output_underrun(odev);
 	else
@@ -1318,12 +1299,12 @@
 	if (odev->direction != CRAS_STREAM_OUTPUT)
 		return 0;
 
-	if (odev->is_free_running && odev->is_free_running(odev))
-		return 0;
+	if (odev->output_should_wake)
+		return odev->output_should_wake(odev);
 
 	/* Do not wake up for device not started yet. */
 	return (odev->state == CRAS_IODEV_STATE_NORMAL_RUN ||
-		odev->state == CRAS_IODEV_STATE_NO_STREAM_RUN);
+	        odev->state == CRAS_IODEV_STATE_NO_STREAM_RUN);
 }
 
 unsigned int cras_iodev_frames_to_play_in_sleep(struct cras_iodev *odev,
@@ -1332,41 +1313,25 @@
 {
 	int rc = cras_iodev_frames_queued(odev, hw_tstamp);
 	unsigned int level = (rc < 0) ? 0 : rc;
-	unsigned int wakeup_frames;
 	*hw_level = level;
 
 	if (odev->streams) {
-		/*
-		 * We have two cases in this scope. The first one is if there are frames
-		 * waiting to be played, audio thread will wake up when hw_level drops
-		 * to min_cb_level. This situation only happens when hardware buffer is
-		 * smaller than the client stream buffer. The second one is waking up
-		 * when hw_level drops to dev_normal_run_wake_up_time. It is a default
-		 * behavior. This wake up time is the bottom line to avoid underrun.
-		 * Normally, the audio thread does not wake up at that time because the
-		 * streams should wake it up before then.
-		 */
-		if (*hw_level > odev->min_cb_level && dev_playback_frames(odev))
-			return *hw_level - odev->min_cb_level;
-
-		wakeup_frames = cras_time_to_frames(
-			&dev_normal_run_wake_up_time, odev->format->frame_rate);
-		if (level > wakeup_frames)
-			return level - wakeup_frames;
+		/* Schedule that audio thread will wake up when hw_level drops to
+		 * 1ms. Normally, this isn't hit because the client will wake us
+		 * up before then. This helps with cases where the hardware
+		 * buffer is smaller than the client stream buffer. */
+		unsigned int one_ms_frames = odev->format->frame_rate / 1000;
+		if (level > one_ms_frames)
+			return level - one_ms_frames;
 		else
 			return level;
 	}
 
-	/*
-	 * When this device has no stream, schedule audio thread to wake up when
-	 * hw_level drops to dev_no_stream_wake_up_time so audio thread can
-	 * fill zeros to it. We also need to consider min_cb_level in order to avoid
-	 * busyloop when device buffer size is smaller than wake up time.
-	 */
-	wakeup_frames = cras_time_to_frames(&dev_no_stream_wake_up_time,
-					    odev->format->frame_rate);
-	if (level > MIN(odev->min_cb_level, wakeup_frames))
-		return level - MIN(odev->min_cb_level, wakeup_frames);
+	/* When this device has no stream, schedule audio thread to wake up
+	 * when hw_level drops to min_cb_level so audio thread can fill
+	 * zeros to it. */
+	if (*hw_level > odev->min_cb_level)
+		return *hw_level - odev->min_cb_level;
 	else
 		return 0;
 }
@@ -1389,7 +1354,7 @@
 	state = cras_iodev_state(odev);
 
 	may_enter_normal_run = (state == CRAS_IODEV_STATE_OPEN ||
-				state == CRAS_IODEV_STATE_NO_STREAM_RUN);
+		                state == CRAS_IODEV_STATE_NO_STREAM_RUN);
 
 	if (may_enter_normal_run && dev_playback_frames(odev))
 		return cras_iodev_output_event_sample_ready(odev);
@@ -1415,7 +1380,7 @@
 	return 0;
 }
 
-int cras_iodev_reset_request(struct cras_iodev *iodev)
+int cras_iodev_reset_request(struct cras_iodev* iodev)
 {
 	/* Ignore requests if there is a pending request.
 	 * This function sends the request from audio thread to main
@@ -1430,13 +1395,13 @@
 	if (iodev->reset_request_pending)
 		return 0;
 	iodev->reset_request_pending = 1;
-	return cras_device_monitor_reset_device(iodev->info.idx);
+	return cras_device_monitor_reset_device(iodev);
 }
 
 static void ramp_mute_callback(void *data)
 {
 	struct cras_iodev *odev = (struct cras_iodev *)data;
-	cras_device_monitor_set_device_mute_state(odev->info.idx);
+	cras_device_monitor_set_device_mute_state(odev);
 }
 
 /* Used in audio thread. Check the docstrings of CRAS_IODEV_RAMP_REQUEST. */
@@ -1445,8 +1410,8 @@
 {
 	cras_ramp_cb cb = NULL;
 	void *cb_data = NULL;
-	int rc;
-	float from, to, duration_secs;
+	int rc, up;
+	float duration_secs;
 
 	/* Ignores request if device is closed. */
 	if (!cras_iodev_is_open(odev))
@@ -1454,32 +1419,30 @@
 
 	switch (request) {
 	case CRAS_IODEV_RAMP_REQUEST_UP_UNMUTE:
-		from = 0.0;
-		to = 1.0;
+		up = 1;
 		duration_secs = RAMP_UNMUTE_DURATION_SECS;
 		break;
 	case CRAS_IODEV_RAMP_REQUEST_UP_START_PLAYBACK:
-		from = 0.0;
-		to = 1.0;
+		up = 1;
 		duration_secs = RAMP_NEW_STREAM_DURATION_SECS;
 		break;
 	/* Unmute -> mute. Callback to set mute state should be called after
 	 * ramping is done. */
 	case CRAS_IODEV_RAMP_REQUEST_DOWN_MUTE:
-		from = 1.0;
-		to = 0.0;
+		up = 0;
 		duration_secs = RAMP_MUTE_DURATION_SECS;
 		cb = ramp_mute_callback;
-		cb_data = (void *)odev;
+		cb_data = (void*)odev;
 		break;
 	default:
 		return -EINVAL;
 	}
 
 	/* Starts ramping. */
-	rc = cras_mute_ramp_start(odev->ramp, from, to,
-				  duration_secs * odev->format->frame_rate, cb,
-				  cb_data);
+	rc = cras_ramp_start(
+			odev->ramp, up,
+			duration_secs * odev->format->frame_rate,
+			cb, cb_data);
 
 	if (rc)
 		return rc;
@@ -1487,48 +1450,12 @@
 	/* Mute -> unmute case, unmute state should be set after ramping is
 	 * started so device can start playing with samples close to 0. */
 	if (request == CRAS_IODEV_RAMP_REQUEST_UP_UNMUTE)
-		cras_device_monitor_set_device_mute_state(odev->info.idx);
+		cras_device_monitor_set_device_mute_state(odev);
 
 	return 0;
 }
 
-int cras_iodev_start_volume_ramp(struct cras_iodev *odev,
-				 unsigned int old_volume,
-				 unsigned int new_volume)
-{
-	float old_scaler, new_scaler;
-	float from, to;
-
-	if (old_volume == new_volume)
-		return 0;
-	if (!cras_iodev_is_open(odev))
-		return 0;
-	if (!odev->format)
-		return -EINVAL;
-	if (odev->active_node && odev->active_node->softvol_scalers) {
-		old_scaler = odev->active_node->softvol_scalers[old_volume];
-		new_scaler = odev->active_node->softvol_scalers[new_volume];
-	} else {
-		old_scaler = softvol_get_scaler(old_volume);
-		new_scaler = softvol_get_scaler(new_volume);
-	}
-	if (new_scaler == 0.0) {
-		return -EINVAL;
-	}
-	/* We will soon set odev's volume to new_volume from old_volume.
-	 * Because we're using softvol, we were previously scaling our volume by
-	 * old_scaler. If we want to avoid a jump in volume, we need to start
-	 * our ramp so that (from * new_scaler) = old_scaler. */
-	from = old_scaler / new_scaler;
-	to = 1.0;
-
-	return cras_volume_ramp_start(odev->ramp, from, to,
-				      RAMP_VOLUME_CHANGE_DURATION_SECS *
-					      odev->format->frame_rate,
-				      NULL, NULL);
-}
-
-int cras_iodev_set_mute(struct cras_iodev *iodev)
+int cras_iodev_set_mute(struct cras_iodev* iodev)
 {
 	if (!cras_iodev_is_open(iodev))
 		return 0;
@@ -1538,64 +1465,19 @@
 	return 0;
 }
 
+int cras_iodev_has_pinned_stream(const struct cras_iodev *dev)
+{
+	const struct dev_stream *out;
+	DL_FOREACH(dev->streams, out) {
+		if (out->stream->is_pinned)
+			return 1;
+	}
+	return 0;
+}
+
 void cras_iodev_update_highest_hw_level(struct cras_iodev *iodev,
-					unsigned int hw_level)
+		unsigned int hw_level)
 {
 	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 f699933..d40af91 100644
--- a/cras/src/server/cras_iodev.h
+++ b/cras/src/server/cras_iodev.h
@@ -14,8 +14,6 @@
 #ifndef CRAS_IODEV_H_
 #define CRAS_IODEV_H_
 
-#include <stdbool.h>
-
 #include "cras_dsp.h"
 #include "cras_iodev_info.h"
 #include "cras_messages.h"
@@ -30,53 +28,16 @@
 struct cras_iodev;
 struct rate_estimator;
 
-/*
- * Type of callback function to execute when loopback sender transfers audio
- * to the receiver. For example, this is called in audio thread when playback
- * samples are mixed and about to write to hardware.
- * Args:
- *    frames - Loopback audio data from sender.
- *    nframes - Number loopback audio data in frames.
- *    fmt - Format of the loopback audio data.
- *    cb_data - Pointer to the loopback receiver.
+/* Callback type for loopback listeners.  When enabled, this is called from the
+ * playback path of an iodev with the samples that are being played back.
  */
-typedef int (*loopback_hook_data_t)(const uint8_t *frames, unsigned int nframes,
-				    const struct cras_audio_format *fmt,
-				    void *cb_data);
-
-/*
- * Type of callback function to notify loopback receiver that the loopback path
- * starts or stops.
- * Args:
- *    start - True to notify receiver that loopback starts. False to notify
- *        loopback stops.
- *    cb_data - Pointer to the loopback receiver.
- */
-typedef int (*loopback_hook_control_t)(bool start, void *cb_data);
+typedef int (*loopback_hook_t)(const uint8_t *frames, unsigned int nframes,
+			       const struct cras_audio_format *fmt,
+			       void *cb_data);
 
 /* Callback type for an iodev event. */
 typedef int (*iodev_hook_t)();
 
-/*
- * Holds the information of a receiver of loopback audio, used to register
- * with the sender of loopback audio. A sender keeps a list of cras_loopback
- * objects representing all the receivers.
- * Members:
- *    type - Pre-dsp loopback can be used for system loopback. Post-dsp
- *        loopback can be used for echo reference.
- *    hook_data - Callback used for playback samples after mixing, before or
- *        after applying DSP depends on the value of |type|.
- *    hook_control - Callback to notify receiver that loopback starts or stops.
- *    cb_data - Pointer to the loopback receiver, will be passing to hook functions.
- */
-struct cras_loopback {
-	enum CRAS_LOOPBACK_TYPE type;
-	loopback_hook_data_t hook_data;
-	loopback_hook_control_t hook_control;
-	void *cb_data;
-	struct cras_loopback *prev, *next;
-};
-
 /* State of an iodev.
  * no_stream state is only supported on output device.
  * Open state is only supported for device supporting start ops.
@@ -104,7 +65,6 @@
  *      coordinates in meters with ordering x, y, z. The string is formatted as:
  *      "x1 y1 z1 ... xn yn zn" for an n-microphone array.
  *    name - Name displayed to the user.
- *    dsp_name - The "DspName" variable specified in the ucm config.
  *    active_hotword_model - name of the currently selected hotword model.
  *    softvol_scalers - pointer to software volume scalers.
  *    software_volume_needed - For output: True if the volume range of the node
@@ -113,7 +73,8 @@
  *    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.
- *    is_sco_pcm - Bool to indicate whether the ionode is for SCO over PCM.
+ *    stable_id_new - New stable_id, it will be deprecated and be put on
+ *      stable_id.
  */
 struct cras_ionode {
 	struct cras_iodev *dev;
@@ -127,14 +88,13 @@
 	enum CRAS_NODE_POSITION position;
 	char mic_positions[CRAS_NODE_MIC_POS_BUFFER_SIZE];
 	char name[CRAS_NODE_NAME_BUFFER_SIZE];
-	const char *dsp_name;
 	char active_hotword_model[CRAS_NODE_HOTWORD_MODEL_BUFFER_SIZE];
 	float *softvol_scalers;
 	int software_volume_needed;
 	long min_software_gain;
 	long max_software_gain;
 	unsigned int stable_id;
-	int is_sco_pcm;
+	unsigned int stable_id_new;
 	struct cras_ionode *prev, *next;
 };
 
@@ -166,7 +126,10 @@
  *             The default action of no stream state is to fill zeros
  *             periodically. Device can implement this function to define
  *             its own optimization of entering/exiting no stream state.
- * is_free_running - (Optional) Checks if the device is in free running state.
+ * output_should_wake - (Optional) Checks if audio thread should schedule a
+ *                      wake for this output device. The default condition is
+ *                      whether the device is running. Device can implement this
+ *                      function to use its own condition.
  * output_underrun - (Optional) Handle output device underrun.
  * update_active_node - Update the active node when the selected device/node has
  *     changed.
@@ -178,10 +141,9 @@
  * get_num_underruns - Gets number of underrun recorded so far.
  * get_num_severe_underruns - Gets number of severe underrun recorded since
  *                            iodev was created.
- * get_valid_frames - Gets number of valid frames in device which have not
- *                    played yet. Valid frames does not include zero samples
- *                    we filled under no streams state.
  * format - The audio format being rendered or captured to hardware.
+ * ext_format - The audio format that is visible to the rest of the system.
+ *     This can be different than the hardware if the device dsp changes it.
  * rate_est - Rate estimator to estimate the actual device rate.
  * area - Information about how the samples are stored.
  * info - Unique identifier for this device (index and name).
@@ -200,24 +162,20 @@
  *        iodev. This will be used as the echo reference for echo cancellation.
  * is_enabled - True if this iodev is enabled, false otherwise.
  * software_volume_needed - True if volume control is not supported by hardware.
- * software_gain_scaler - Scaler value to apply to captured data. This can
- *     be different when active node changes. Configured when there's no
- *     hardware gain control.
  * streams - List of audio streams serviced by dev.
  * state - Device is in one of close, open, normal, or no_stream state defined
  *         in enum CRAS_IODEV_STATE.
  * min_cb_level - min callback level of any stream attached.
  * max_cb_level - max callback level of any stream attached.
- * highest_hw_level - The highest hardware level of the device.
- * largest_cb_level - The largest callback level of streams attached to this
- *                    device. The difference with max_cb_level is it takes all
- *                    streams into account even if they have been removed.
  * buf_state - If multiple streams are writing to this device, then this
  *     keeps track of how much each stream has written.
  * idle_timeout - The timestamp when to close the dev after being idle.
- * open_ts - The time when the device opened.
- * loopbacks - List of registered cras_loopback objects representing the
- *    receivers who wants a copy of the audio sending through this iodev.
+ * pre_dsp_hook - Hook called before applying DSP, but after mixing.  Used for
+ *     system loopback.
+ * post_dsp_hook - Hook called after applying DSP.  Can be used for echo
+ *     reference.
+ * pre_dsp_hook_cb_data - Callback data that will be passing to pre_dsp_hook.
+ * post_dsp_hook_cb_data - Callback data that will be passing to post_dsp_hook.
  * pre_open_iodev_hook - Optional callback to call before iodev open.
  * post_close_iodev_hook - Optional callback to call after iodev close.
  * ext_dsp_module - External dsp module to process audio data in stream level
@@ -239,7 +197,8 @@
 	void (*set_capture_gain)(struct cras_iodev *iodev);
 	void (*set_capture_mute)(struct cras_iodev *iodev);
 	int (*set_swap_mode_for_node)(struct cras_iodev *iodev,
-				      struct cras_ionode *node, int enable);
+				      struct cras_ionode *node,
+				      int enable);
 	int (*open_dev)(struct cras_iodev *iodev);
 	int (*configure_dev)(struct cras_iodev *iodev);
 	int (*close_dev)(struct cras_iodev *iodev);
@@ -248,24 +207,24 @@
 			     struct timespec *tstamp);
 	int (*delay_frames)(const struct cras_iodev *iodev);
 	int (*get_buffer)(struct cras_iodev *iodev,
-			  struct cras_audio_area **area, unsigned *frames);
+			  struct cras_audio_area **area,
+			  unsigned *frames);
 	int (*put_buffer)(struct cras_iodev *iodev, unsigned nwritten);
 	int (*flush_buffer)(struct cras_iodev *iodev);
 	int (*start)(const struct cras_iodev *iodev);
-	int (*is_free_running)(const struct cras_iodev *iodev);
+	int (*output_should_wake)(const struct cras_iodev *iodev);
 	int (*output_underrun)(struct cras_iodev *iodev);
 	int (*no_stream)(struct cras_iodev *iodev, int enable);
-	void (*update_active_node)(struct cras_iodev *iodev, unsigned node_idx,
-				   unsigned dev_enabled);
+	void (*update_active_node)(struct cras_iodev *iodev,
+				   unsigned node_idx, unsigned dev_enabled);
 	int (*update_channel_layout)(struct cras_iodev *iodev);
 	int (*set_hotword_model)(struct cras_iodev *iodev,
 				 const char *model_name);
 	char *(*get_hotword_models)(struct cras_iodev *iodev);
 	unsigned int (*get_num_underruns)(const struct cras_iodev *iodev);
 	unsigned int (*get_num_severe_underruns)(const struct cras_iodev *iodev);
-	int (*get_valid_frames)(const struct cras_iodev *odev,
-				struct timespec *tstamp);
 	struct cras_audio_format *format;
+	struct cras_audio_format *ext_format;
 	struct rate_estimator *rate_est;
 	struct cras_audio_area *area;
 	struct cras_iodev_info info;
@@ -282,25 +241,25 @@
 	struct cras_iodev *echo_reference_dev;
 	int is_enabled;
 	int software_volume_needed;
-	float software_gain_scaler;
 	struct dev_stream *streams;
 	enum CRAS_IODEV_STATE state;
 	unsigned int min_cb_level;
 	unsigned int max_cb_level;
-	unsigned int highest_hw_level;
-	unsigned int largest_cb_level;
 	struct buffer_share *buf_state;
 	struct timespec idle_timeout;
-	struct timespec open_ts;
-	struct cras_loopback *loopbacks;
+	loopback_hook_t pre_dsp_hook;
+	loopback_hook_t post_dsp_hook;
+	void *pre_dsp_hook_cb_data;
+	void *post_dsp_hook_cb_data;
 	iodev_hook_t pre_open_iodev_hook;
 	iodev_hook_t post_close_iodev_hook;
 	struct ext_dsp_module *ext_dsp_module;
 	int reset_request_pending;
-	struct cras_ramp *ramp;
+	struct cras_ramp* ramp;
 	int input_streaming;
 	unsigned int input_frames_read;
 	unsigned int input_dsp_offset;
+	unsigned int highest_hw_level;
 	struct input_data *input_data;
 	struct cras_iodev *prev, *next;
 };
@@ -333,7 +292,7 @@
 
 enum CRAS_IODEV_RAMP_REQUEST {
 	CRAS_IODEV_RAMP_REQUEST_UP_UNMUTE = 0,
-	CRAS_IODEV_RAMP_REQUEST_DOWN_MUTE = 1,
+	CRAS_IODEV_RAMP_REQUEST_DOWN_MUTE  = 1,
 	CRAS_IODEV_RAMP_REQUEST_UP_START_PLAYBACK = 2,
 };
 
@@ -363,7 +322,8 @@
  *    iodev - the iodev to init audio area
  *    num_channels - the total number of channels
  */
-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);
 
 /* Frees the audio area for this iodev.
  * Args:
@@ -385,7 +345,8 @@
  *    frame_rate - 44100, 48000, etc.
  *    ts - Filled with the time to sleep for.
  */
-void cras_iodev_fill_time_from_frames(size_t frames, size_t frame_rate,
+void cras_iodev_fill_time_from_frames(size_t frames,
+				      size_t frame_rate,
 				      struct timespec *ts);
 
 /* Update the "dsp_name" dsp variable. This may cause the dsp pipeline to be
@@ -395,6 +356,7 @@
  */
 void cras_iodev_update_dsp(struct cras_iodev *iodev);
 
+
 /* Sets swap mode on a node using dsp. This function can be called when
  * dsp pipline is not created yet. It will take effect when dsp pipeline
  * is created later. If there is dsp pipeline, this function causes the dsp
@@ -407,7 +369,8 @@
  *    0 on success, error code on failure.
  */
 int cras_iodev_dsp_set_swap_mode_for_node(struct cras_iodev *iodev,
-					  struct cras_ionode *node, int enable);
+					   struct cras_ionode *node,
+					   int enable);
 
 /* Handles a plug event happening on this node.
  * Args:
@@ -419,8 +382,14 @@
 /* Returns true if node a is preferred over node b. */
 int cras_ionode_better(struct cras_ionode *a, struct cras_ionode *b);
 
-/* Sets the plugged state of a node. */
-void cras_iodev_set_node_plugged(struct cras_ionode *node, int plugged);
+/* Sets an attribute of an ionode on a device.
+ * Args:
+ *    ionode - ionode whose attribute we want to change.
+ *    attr - the attribute we want to change.
+ *    value - the value we want to set.
+ */
+int cras_iodev_set_node_attr(struct cras_ionode *ionode,
+			     enum ionode_attr attr, int value);
 
 /* Adds a node to the iodev's node list. */
 void cras_iodev_add_node(struct cras_iodev *iodev, struct cras_ionode *node);
@@ -433,9 +402,9 @@
 				struct cras_ionode *node);
 
 /* Adjust the system volume based on the volume of the given node. */
-static inline unsigned int
-cras_iodev_adjust_node_volume(const struct cras_ionode *node,
-			      unsigned int system_volume)
+static inline unsigned int cras_iodev_adjust_node_volume(
+		const struct cras_ionode *node,
+		unsigned int system_volume)
 {
 	unsigned int node_vol_offset = 100 - node->volume;
 
@@ -446,9 +415,8 @@
 }
 
 /* Get the volume scaler for the active node. */
-static inline unsigned int
-cras_iodev_adjust_active_node_volume(struct cras_iodev *iodev,
-				     unsigned int system_volume)
+static inline unsigned int cras_iodev_adjust_active_node_volume(
+		struct cras_iodev *iodev, unsigned int system_volume)
 {
 	if (!iodev->active_node)
 		return system_volume;
@@ -457,9 +425,8 @@
 }
 
 /* Get the gain adjusted based on system for the active node. */
-static inline long
-cras_iodev_adjust_active_node_gain(const struct cras_iodev *iodev,
-				   long system_gain)
+static inline long cras_iodev_adjust_active_node_gain(
+		const struct cras_iodev *iodev, long system_gain)
 {
 	if (!iodev->active_node)
 		return system_gain;
@@ -468,8 +435,8 @@
 }
 
 /* Returns true if the active node of the iodev needs software volume. */
-static inline int
-cras_iodev_software_volume_needed(const struct cras_iodev *iodev)
+static inline int cras_iodev_software_volume_needed(
+		const struct cras_iodev *iodev)
 {
 	if (iodev->software_volume_needed)
 		return 1;
@@ -486,8 +453,8 @@
  * Returs:
  *    0 if software gain is not needed, or if there is no active node.
  *    Returns min_software_gain on active node if there is one. */
-static inline long
-cras_iodev_minimum_software_gain(const struct cras_iodev *iodev)
+static inline long cras_iodev_minimum_software_gain(
+		const struct cras_iodev *iodev)
 {
 	if (!cras_iodev_software_volume_needed(iodev))
 		return 0;
@@ -502,8 +469,8 @@
  * Returs:
  *    0 if software gain is not needed, or if there is no active node.
  *    Returns max_software_gain on active node if there is one. */
-static inline long
-cras_iodev_maximum_software_gain(const struct cras_iodev *iodev)
+static inline long cras_iodev_maximum_software_gain(
+		const struct cras_iodev *iodev)
 {
 	if (!cras_iodev_software_volume_needed(iodev))
 		return 0;
@@ -525,13 +492,8 @@
 float cras_iodev_get_software_volume_scaler(struct cras_iodev *iodev);
 
 /* Indicate that a stream has been added from the device. */
-int cras_iodev_add_stream(struct cras_iodev *iodev, struct dev_stream *stream);
-
-/* Indicate that a stream is taken into consideration of device's I/O. This
- * function is for output stream only. For input stream, it is already included
- * by add_stream function. */
-void cras_iodev_start_stream(struct cras_iodev *iodev,
-			     struct dev_stream *stream);
+int cras_iodev_add_stream(struct cras_iodev *iodev,
+			  struct dev_stream *stream);
 
 /* Indicate that a stream has been removed from the device. */
 struct dev_stream *cras_iodev_rm_stream(struct cras_iodev *iodev,
@@ -568,12 +530,7 @@
 /* Gets the available buffer to write/read audio.*/
 int cras_iodev_buffer_avail(struct cras_iodev *iodev, unsigned hw_level);
 
-/* Marks a buffer from get_buffer as read.
- * Args:
- *    iodev - The input device.
- * Returns:
- *    Number of frames to put sucessfully. Negative error code on failure.
- */
+/* Marks a buffer from get_buffer as read. */
 int cras_iodev_put_input_buffer(struct cras_iodev *iodev);
 
 /* Marks a buffer from get_buffer as written. */
@@ -620,7 +577,8 @@
  *    Number of frames in the hardware buffer.
  *    Returns -EPIPE if there is severe underrun.
  */
-int cras_iodev_frames_queued(struct cras_iodev *iodev, struct timespec *tstamp);
+int cras_iodev_frames_queued(struct cras_iodev *iodev,
+			     struct timespec *tstamp);
 
 /* Get the delay for input/output in frames. */
 static inline int cras_iodev_delay_frames(const struct cras_iodev *iodev)
@@ -642,11 +600,15 @@
 	return 0;
 }
 
-/* Configure iodev to exit idle mode. */
-static inline void cras_iodev_exit_idle(struct cras_iodev *iodev)
-{
-	iodev->idle_timeout.tv_sec = 0;
-}
+/* Register a pre-dsp loopback hook.  Pass NULL to clear. */
+void cras_iodev_register_pre_dsp_hook(struct cras_iodev *iodev,
+				      loopback_hook_t loop_cb,
+				      void *cb_data);
+
+/* Register a post-dsp loopback hook.  Pass NULL to clear. */
+void cras_iodev_register_post_dsp_hook(struct cras_iodev *iodev,
+				       loopback_hook_t loop_cb,
+				       void *cb_data);
 
 /*
  * Sets the external dsp module for |iodev| and configures the module
@@ -654,8 +616,7 @@
  * in main thread.
  * Args:
  *    iodev - The iodev to hold the dsp module.
- *    ext - External dsp module to set to iodev. Pass NULL to release
- *        the ext_dsp_module already added to dsp pipeline.
+ *    ext - External dsp module to set to iodev.
  */
 void cras_iodev_set_ext_dsp_module(struct cras_iodev *iodev,
 				   struct ext_dsp_module *ext);
@@ -696,6 +657,7 @@
  * */
 int cras_iodev_default_no_stream_playback(struct cras_iodev *odev, int enable);
 
+
 /* Get current state of iodev.
  * Args:
  *    iodev[in] - The device.
@@ -730,20 +692,8 @@
  *    An unsigned int for number of severe underruns recorded since iodev
  *    was created.
  */
-unsigned int
-cras_iodev_get_num_severe_underruns(const struct cras_iodev *iodev);
-
-/* Get number of valid frames in the hardware buffer. The valid frames does
- * not include zero samples we filled with before.
- * Args:
- *    iodev[in] - The device.
- *    hw_tstamp[out] - Pointer to the timestamp for hw_level.
- * Returns:
- *    Number of valid frames in the hardware buffer.
- *    Negative error code on failure.
- */
-int cras_iodev_get_valid_frames(struct cras_iodev *iodev,
-				struct timespec *hw_tstamp);
+unsigned int cras_iodev_get_num_severe_underruns(
+		const struct cras_iodev *iodev);
 
 /* Request main thread to re-open device. This should be used in audio thread
  * when it finds device is in a bad state. The request will be ignored if
@@ -753,7 +703,7 @@
  * Returns:
  *    0 on success. Negative error code on failure.
  */
-int cras_iodev_reset_request(struct cras_iodev *iodev);
+int cras_iodev_reset_request(struct cras_iodev* iodev);
 
 /* Handle output underrun.
  * Args:
@@ -774,25 +724,13 @@
 int cras_iodev_start_ramp(struct cras_iodev *odev,
 			  enum CRAS_IODEV_RAMP_REQUEST request);
 
-/* Start ramping samples up/down on a device after a volume change.
- * Args:
- *    iodev[in] - The device.
- *    old_volume[in] - The previous volume percentage of the device.
- *    new_volume[in] - The new volume percentage of the device.
- * Returns:
- *    0 on success. Negative error code on failure.
- */
-int cras_iodev_start_volume_ramp(struct cras_iodev *odev,
-				 unsigned int old_volume,
-				 unsigned int new_volume);
-
 /* Set iodev to mute/unmute state.
  * Args:
  *    iodev[in] - The device.
  * Returns:
  *    0 on success. Negative error code on failure.
  */
-int cras_iodev_set_mute(struct cras_iodev *iodev);
+int cras_iodev_set_mute(struct cras_iodev* iodev);
 
 /*
  * Checks if an output iodev's volume is zero.
@@ -806,22 +744,20 @@
 int cras_iodev_is_zero_volume(const struct cras_iodev *odev);
 
 /*
+ * Checks if a iodev has pinned stream attached to it.
+ * Args:
+ *    dev[in] - The device.
+ * Returns:
+ *    1 if device has pinned stream. 0 otherwise.
+ */
+int cras_iodev_has_pinned_stream(const struct cras_iodev *dev);
+
+/*
  * Updates the highest hardware level of the device.
  * Args:
  *    iodev - The device.
  */
 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);
+		unsigned int hw_level);
 
 #endif /* CRAS_IODEV_H_ */
diff --git a/cras/src/server/cras_iodev_list.c b/cras/src/server/cras_iodev_list.c
index c581acd..5328af4 100644
--- a/cras/src/server/cras_iodev_list.c
+++ b/cras/src/server/cras_iodev_list.c
@@ -22,7 +22,10 @@
 #include "test_iodev.h"
 #include "utlist.h"
 
-const struct timespec idle_timeout_interval = { .tv_sec = 10, .tv_nsec = 0 };
+const struct timespec idle_timeout_interval = {
+	.tv_sec = 10,
+	.tv_nsec = 0
+};
 
 /* Linked list of available devices. */
 struct iodev_list {
@@ -94,23 +97,35 @@
 {
 	struct cras_iodev *dev;
 
-	DL_FOREACH (devs[CRAS_STREAM_OUTPUT].iodevs, dev)
+	DL_FOREACH(devs[CRAS_STREAM_OUTPUT].iodevs, dev)
 		if (dev->info.idx == dev_index)
 			return dev;
 
-	DL_FOREACH (devs[CRAS_STREAM_INPUT].iodevs, dev)
+	DL_FOREACH(devs[CRAS_STREAM_INPUT].iodevs, dev)
 		if (dev->info.idx == dev_index)
 			return dev;
 
 	return NULL;
 }
 
-static struct cras_ionode *find_node(struct cras_iodev *iodev,
-				     unsigned int node_idx)
+static struct cras_ionode *find_node(cras_node_id_t id)
 {
+	struct cras_iodev *dev;
 	struct cras_ionode *node;
-	DL_SEARCH_SCALAR(iodev->nodes, node, idx, node_idx);
-	return node;
+	uint32_t dev_index, node_index;
+
+	dev_index = dev_index_of(id);
+	node_index = node_index_of(id);
+
+	dev = find_dev(dev_index);
+	if (!dev)
+		return NULL;
+
+	DL_FOREACH(dev->nodes, node)
+		if (node->idx == node_index)
+			return node;
+
+	return NULL;
 }
 
 /* Adds a device to the list.  Used from add_input and add_output. */
@@ -120,12 +135,12 @@
 	uint32_t new_idx;
 	struct iodev_list *list = &devs[dev->direction];
 
-	DL_FOREACH (list->iodevs, tmp)
+	DL_FOREACH(list->iodevs, tmp)
 		if (tmp == dev)
 			return -EEXIST;
 
 	dev->format = NULL;
-	dev->format = NULL;
+	dev->ext_format = NULL;
 	dev->prev = dev->next = NULL;
 
 	/* Move to the next index and make sure it isn't taken. */
@@ -156,7 +171,7 @@
 {
 	struct cras_iodev *tmp;
 
-	DL_FOREACH (devs[dev->direction].iodevs, tmp)
+	DL_FOREACH(devs[dev->direction].iodevs, tmp)
 		if (tmp == dev) {
 			if (cras_iodev_is_open(dev))
 				return -EBUSY;
@@ -171,11 +186,12 @@
 
 /* Fills a dev_info array from the iodev_list. */
 static void fill_dev_list(struct iodev_list *list,
-			  struct cras_iodev_info *dev_info, size_t out_size)
+			  struct cras_iodev_info *dev_info,
+			  size_t out_size)
 {
 	int i = 0;
 	struct cras_iodev *tmp;
-	DL_FOREACH (list->iodevs, tmp) {
+	DL_FOREACH(list->iodevs, tmp) {
 		memcpy(&dev_info[i], &tmp->info, sizeof(dev_info[0]));
 		i++;
 		if (i == out_size)
@@ -220,10 +236,6 @@
 		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";
@@ -232,13 +244,14 @@
 
 /* Fills an ionode_info array from the iodev_list. */
 static int fill_node_list(struct iodev_list *list,
-			  struct cras_ionode_info *node_info, size_t out_size)
+			  struct cras_ionode_info *node_info,
+			  size_t out_size)
 {
 	int i = 0;
 	struct cras_iodev *dev;
 	struct cras_ionode *node;
-	DL_FOREACH (list->iodevs, dev) {
-		DL_FOREACH (dev->nodes, node) {
+	DL_FOREACH(list->iodevs, dev) {
+		DL_FOREACH(dev->nodes, node) {
 			node_info->iodev_idx = dev->info.idx;
 			node_info->ionode_idx = node->idx;
 			node_info->plugged = node->plugged;
@@ -246,19 +259,19 @@
 				node->plugged_time.tv_sec;
 			node_info->plugged_time.tv_usec =
 				node->plugged_time.tv_usec;
-			node_info->active =
-				dev->is_enabled && (dev->active_node == node);
+			node_info->active = dev->is_enabled &&
+					    (dev->active_node == node);
 			node_info->volume = node->volume;
 			node_info->capture_gain = node->capture_gain;
-			node_info->left_right_swapped =
-				node->left_right_swapped;
+			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,
-			       node->active_hotword_model);
+				node->active_hotword_model);
 			snprintf(node_info->type, sizeof(node_info->type), "%s",
-				 node_type_to_str(node));
+				node_type_to_str(node));
 			node_info->type_enum = node->type;
 			node_info++;
 			i++;
@@ -298,12 +311,31 @@
 {
 	struct cras_iodev *dev;
 
-	DL_FOREACH (devs[CRAS_STREAM_OUTPUT].iodevs, dev) {
+	DL_FOREACH(devs[CRAS_STREAM_OUTPUT].iodevs, dev) {
 		if (dev->set_volume && cras_iodev_is_open(dev))
 			dev->set_volume(dev);
 	}
 }
 
+/*
+ * Checks if a device should start ramping for mute/unmute change.
+ * Device must meet all the conditions:
+ *
+ * - Device is enabled in iodev_list.
+ * - Device has ramp support.
+ * - Device is in normal run state, that is, it must be running with valid
+ *   streams.
+ * - Device volume, which considers both system volume and adjusted active
+ *   node volume, is not zero. If device volume is zero, all the samples are
+ *   suppressed to zero and there is no need to ramp.
+ */
+static int device_should_start_ramp_for_mute(const struct cras_iodev *dev)
+{
+	return (cras_iodev_list_dev_is_enabled(dev) && dev->ramp &&
+		cras_iodev_state(dev) == CRAS_IODEV_STATE_NORMAL_RUN &&
+		!cras_iodev_is_zero_volume(dev));
+}
+
 /* Called when the system mute state changes.  Pass the current mute setting
  * to the default output if it is active. */
 static void sys_mute_change(void *context, int muted, int user_muted,
@@ -312,16 +344,31 @@
 	struct cras_iodev *dev;
 	int should_mute = muted || user_muted;
 
-	DL_FOREACH (devs[CRAS_STREAM_OUTPUT].iodevs, dev) {
-		if (!cras_iodev_is_open(dev)) {
-			/* For closed devices, just set its mute state. */
-			cras_iodev_set_mute(dev);
-		} else {
+	DL_FOREACH(devs[CRAS_STREAM_OUTPUT].iodevs, dev) {
+		if (device_should_start_ramp_for_mute(dev)) {
+			/*
+			 * Start ramping in audio thread and set mute/unmute
+			 * state on device. This should only be done when
+			 * device is running with valid streams.
+			 *
+			 * 1. Mute -> Unmute: Set device unmute state after
+			 *                    ramping is started.
+			 * 2. Unmute -> Mute: Set device mute state after
+			 *                    ramping is done.
+			 *
+			 * The above transition will be handled by
+			 * cras_iodev_ramp_start.
+			 */
 			audio_thread_dev_start_ramp(
-				audio_thread, dev->info.idx,
-				(should_mute ?
+					audio_thread,
+					dev,
+					(should_mute ?
 					 CRAS_IODEV_RAMP_REQUEST_DOWN_MUTE :
 					 CRAS_IODEV_RAMP_REQUEST_UP_UNMUTE));
+
+		} else {
+			/* For device without ramp, just set its mute state. */
+			cras_iodev_set_mute(dev);
 		}
 	}
 }
@@ -330,9 +377,9 @@
 {
 	struct cras_rstream *rstream;
 
-	audio_thread_rm_open_dev(audio_thread, dev->direction, dev->info.idx);
+	audio_thread_rm_open_dev(audio_thread, dev);
 
-	DL_FOREACH (stream_list_get(stream_list), rstream) {
+	DL_FOREACH(stream_list_get(stream_list), rstream) {
 		if (rstream->apm_list == NULL)
 			continue;
 		cras_apm_list_remove(rstream->apm_list, dev);
@@ -377,7 +424,9 @@
 static int close_dev_without_idle_check(struct cras_iodev *dev)
 {
 	if (!cras_iodev_is_open(dev))
-		return -EINVAL;
+	       return -EINVAL;
+	if (cras_iodev_has_pinned_stream(dev))
+		syslog(LOG_ERR, "Closing device with pinned streams.");
 
 	remove_all_streams_from_dev(dev);
 	dev->idle_timeout.tv_sec = 0;
@@ -408,7 +457,7 @@
 	min_idle_expiration.tv_sec = 0;
 	min_idle_expiration.tv_nsec = 0;
 
-	DL_FOREACH (enabled_devs[CRAS_STREAM_OUTPUT], edev) {
+	DL_FOREACH(enabled_devs[CRAS_STREAM_OUTPUT], edev) {
 		if (edev->dev->idle_timeout.tv_sec == 0)
 			continue;
 		if (timespec_after(&now, &edev->dev->idle_timeout)) {
@@ -447,7 +496,7 @@
 {
 	struct dev_init_retry *retry;
 
-	DL_FOREACH (init_retries, retry) {
+	DL_FOREACH(init_retries, retry) {
 		if (retry->dev_idx != dev_idx)
 			continue;
 		cras_tm_cancel_timer(cras_system_state_get_tm(),
@@ -458,11 +507,12 @@
 }
 
 /* Open the device potentially filling the output with a pre buffer. */
-static int init_device(struct cras_iodev *dev, struct cras_rstream *rstream)
+static int init_device(struct cras_iodev *dev,
+		       struct cras_rstream *rstream)
 {
 	int rc;
 
-	cras_iodev_exit_idle(dev);
+	dev->idle_timeout.tv_sec = 0;
 
 	if (cras_iodev_is_open(dev))
 		return 0;
@@ -486,7 +536,7 @@
 	struct enabled_dev *edev;
 	struct cras_rstream *rstream;
 
-	DL_FOREACH (stream_list_get(stream_list), rstream) {
+	DL_FOREACH(stream_list_get(stream_list), rstream) {
 		if (rstream->is_pinned) {
 			struct cras_iodev *dev;
 
@@ -507,10 +557,10 @@
 	}
 	stream_list_suspended = 1;
 
-	DL_FOREACH (enabled_devs[CRAS_STREAM_OUTPUT], edev) {
+	DL_FOREACH(enabled_devs[CRAS_STREAM_OUTPUT], edev) {
 		close_dev(edev->dev);
 	}
-	DL_FOREACH (enabled_devs[CRAS_STREAM_INPUT], edev) {
+	DL_FOREACH(enabled_devs[CRAS_STREAM_INPUT], edev) {
 		close_dev(edev->dev);
 	}
 }
@@ -522,7 +572,7 @@
 	struct cras_rstream *rstream;
 
 	stream_list_suspended = 0;
-	DL_FOREACH (stream_list_get(stream_list), rstream) {
+	DL_FOREACH(stream_list_get(stream_list), rstream) {
 		if ((rstream->flags & HOTWORD_STREAM) == HOTWORD_STREAM)
 			continue;
 		stream_added_cb(rstream);
@@ -544,7 +594,7 @@
 {
 	struct cras_iodev *dev;
 
-	DL_FOREACH (devs[CRAS_STREAM_INPUT].iodevs, dev) {
+	DL_FOREACH(devs[CRAS_STREAM_INPUT].iodevs, dev) {
 		if (dev->set_capture_gain && cras_iodev_is_open(dev))
 			dev->set_capture_gain(dev);
 	}
@@ -556,7 +606,7 @@
 {
 	struct cras_iodev *dev;
 
-	DL_FOREACH (devs[CRAS_STREAM_INPUT].iodevs, dev) {
+	DL_FOREACH(devs[CRAS_STREAM_INPUT].iodevs, dev) {
 		if (dev->set_capture_mute && cras_iodev_is_open(dev))
 			dev->set_capture_mute(dev);
 	}
@@ -569,37 +619,16 @@
 {
 	struct enabled_dev *edev;
 
-	DL_FOREACH (enabled_devs[dir], edev) {
+	DL_FOREACH(enabled_devs[dir], edev) {
 		if (edev->dev == fallback_devs[dir])
 			disable_device(edev, false);
 	}
 }
 
-/*
- * 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)
+static void possibly_enable_fallback(enum CRAS_STREAM_DIRECTION dir)
 {
 	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]);
 }
@@ -610,17 +639,18 @@
  * time consuming APM creation happens in main thread.
  */
 static int add_stream_to_open_devs(struct cras_rstream *stream,
-				   struct cras_iodev **iodevs,
-				   unsigned int num_iodevs)
+				    struct cras_iodev **iodevs,
+				    unsigned int num_iodevs)
 {
 	int i;
 	if (stream->apm_list) {
 		for (i = 0; i < num_iodevs; i++)
-			cras_apm_list_add(stream->apm_list, iodevs[i],
-					  iodevs[i]->format);
+			cras_apm_list_add(stream->apm_list,
+					  iodevs[i],
+					  iodevs[i]->ext_format);
 	}
-	return audio_thread_add_stream(audio_thread, stream, iodevs,
-				       num_iodevs);
+	return audio_thread_add_stream(audio_thread,
+				       stream, iodevs, num_iodevs);
 }
 
 static int init_and_attach_streams(struct cras_iodev *dev)
@@ -637,7 +667,7 @@
 
 	/* If there are active streams to attach to this device,
 	 * open it. */
-	DL_FOREACH (stream_list_get(stream_list), stream) {
+	DL_FOREACH(stream_list_get(stream_list), stream) {
 		if (stream->direction != dir)
 			continue;
 		/*
@@ -645,9 +675,9 @@
 		 * different device, or (2) this is a normal stream, but
 		 * device is not enabled.
 		 */
-		if (stream->is_pinned) {
-			if (stream->pinned_dev_idx != dev->info.idx)
-				continue;
+		if(stream->is_pinned) {
+		   if (stream->pinned_dev_idx != dev->info.idx)
+			continue;
 		} else if (!dev_enabled) {
 			continue;
 		}
@@ -676,7 +706,7 @@
 	DL_DELETE(init_retries, retry);
 	free(retry);
 
-	if (!dev || cras_iodev_is_open(dev))
+	if (cras_iodev_is_open(dev))
 		return;
 
 	rc = init_and_attach_streams(dev);
@@ -696,8 +726,8 @@
 		return -ENOMEM;
 
 	retry->dev_idx = dev->info.idx;
-	retry->init_timer = cras_tm_create_timer(tm, INIT_DEV_DELAY_MS,
-						 init_device_cb, retry);
+	retry->init_timer = cras_tm_create_timer(
+			tm, INIT_DEV_DELAY_MS, init_device_cb, retry);
 	DL_APPEND(init_retries, retry);
 	return 0;
 }
@@ -707,8 +737,6 @@
 {
 	int rc;
 
-	cras_iodev_exit_idle(dev);
-
 	if (audio_thread_is_dev_open(audio_thread, dev))
 		return 0;
 
@@ -718,7 +746,7 @@
 
 	/* Negative EAGAIN code indicates dev will be opened later. */
 	rc = init_device(dev, rstream);
-	if (rc)
+	if (rc && (rc != -EAGAIN))
 		return rc;
 	return 0;
 }
@@ -786,7 +814,7 @@
 	/* Add the new stream to all enabled iodevs at once to avoid offset
 	 * in shm level between different ouput iodevs. */
 	num_iodevs = 0;
-	DL_FOREACH (enabled_devs[rstream->direction], edev) {
+	DL_FOREACH(enabled_devs[rstream->direction], edev) {
 		if (num_iodevs >= ARRAY_SIZE(iodevs)) {
 			syslog(LOG_ERR, "too many enabled devices");
 			break;
@@ -822,7 +850,7 @@
 		 * cras_iodev_list_select_node() is called to re-select the
 		 * active node.
 		 */
-		possibly_enable_fallback(rstream->direction, true);
+		possibly_enable_fallback(rstream->direction);
 	}
 	return 0;
 }
@@ -833,16 +861,15 @@
 	const struct cras_rstream *s;
 
 	/* Check if there are still default streams attached. */
-	DL_FOREACH (stream_list_get(stream_list), s) {
+	DL_FOREACH(stream_list_get(stream_list), s) {
 		if (s->direction == dir && !s->is_pinned)
 			return 0;
 	}
 
 	/* No more default streams, close any device that doesn't have a stream
 	 * pinned to it. */
-	DL_FOREACH (enabled_devs[dir], edev) {
-		if (stream_list_has_pinned_stream(stream_list,
-						  edev->dev->info.idx))
+	DL_FOREACH(enabled_devs[dir], edev) {
+		if (cras_iodev_has_pinned_stream(edev->dev))
 			continue;
 		if (dir == CRAS_STREAM_INPUT) {
 			close_dev(edev->dev);
@@ -865,7 +892,7 @@
 	if (!dev)
 		return;
 	if (!cras_iodev_list_dev_is_enabled(dev) &&
-	    !stream_list_has_pinned_stream(stream_list, dev->info.idx))
+	    !cras_iodev_has_pinned_stream(dev))
 		close_pinned_device(dev);
 }
 
@@ -895,7 +922,7 @@
 	enum CRAS_STREAM_DIRECTION dir = dev->direction;
 	struct device_enabled_cb *callback;
 
-	DL_FOREACH (enabled_devs[dir], edev) {
+	DL_FOREACH(enabled_devs[dir], edev) {
 		if (edev->dev == dev)
 			return -EEXIST;
 	}
@@ -912,7 +939,7 @@
 		return rc;
 	}
 
-	DL_FOREACH (device_enable_cbs, callback)
+	DL_FOREACH(device_enable_cbs, callback)
 		callback->enabled_cb(dev, callback->cb_data);
 
 	return 0;
@@ -940,20 +967,16 @@
 	 * Pull all default streams off this device.
 	 * Pull all pinned streams off as well if force is true.
 	 */
-	DL_FOREACH (stream_list_get(stream_list), stream) {
+	DL_FOREACH(stream_list_get(stream_list), stream) {
 		if (stream->direction != dev->direction)
 			continue;
 		if (stream->is_pinned && !force)
 			continue;
 		audio_thread_disconnect_stream(audio_thread, stream, dev);
 	}
-	/* If this is a force disable call, that guarantees pinned streams have
-	 * all been detached. Otherwise check with stream_list to see if
-	 * there's still a pinned stream using this device.
-	 */
-	if (!force && stream_list_has_pinned_stream(stream_list, dev->info.idx))
+	if (cras_iodev_has_pinned_stream(dev))
 		return 0;
-	DL_FOREACH (device_enable_cbs, callback)
+	DL_FOREACH(device_enable_cbs, callback)
 		callback->disabled_cb(dev, callback->cb_data);
 	close_dev(dev);
 	dev->update_active_node(dev, dev->active_node->idx, 0);
@@ -972,11 +995,8 @@
 {
 	struct cras_rstream *rstream;
 
-	/* Pull pinned streams off this device. Note that this is initiated
-	 * from server side, so the pin stream still exist in stream_list
-	 * pending client side to actually remove it.
-	 */
-	DL_FOREACH (stream_list_get(stream_list), rstream) {
+	/* Pull pinned streams off this device. */
+	DL_FOREACH(stream_list_get(stream_list), rstream) {
 		if (rstream->direction != dev->direction)
 			continue;
 		if (!rstream->is_pinned)
@@ -985,7 +1005,8 @@
 			continue;
 		audio_thread_disconnect_stream(audio_thread, rstream, dev);
 	}
-
+	if (cras_iodev_has_pinned_stream(dev))
+		return -EEXIST;
 	close_dev(dev);
 	dev->update_active_node(dev, dev->active_node->idx, 0);
 	return 0;
@@ -1009,22 +1030,25 @@
 	idle_timer = NULL;
 
 	/* Create the audio stream list for the system. */
-	stream_list =
-		stream_list_create(stream_added_cb, stream_removed_cb,
-				   cras_rstream_create, cras_rstream_destroy,
-				   cras_system_state_get_tm());
+	stream_list = stream_list_create(stream_added_cb, stream_removed_cb,
+					 cras_rstream_create,
+					 cras_rstream_destroy,
+					 cras_system_state_get_tm());
 
 	/* 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_FALLBACK_NORMAL);
+			CRAS_STREAM_OUTPUT,
+			CRAS_NODE_TYPE_UNKNOWN);
 	fallback_devs[CRAS_STREAM_INPUT] = empty_iodev_create(
-		CRAS_STREAM_INPUT, CRAS_NODE_TYPE_FALLBACK_NORMAL);
+			CRAS_STREAM_INPUT,
+			CRAS_NODE_TYPE_UNKNOWN);
 	enable_device(fallback_devs[CRAS_STREAM_OUTPUT]);
 	enable_device(fallback_devs[CRAS_STREAM_INPUT]);
 
-	empty_hotword_dev =
-		empty_iodev_create(CRAS_STREAM_INPUT, CRAS_NODE_TYPE_HOTWORD);
+	empty_hotword_dev = empty_iodev_create(
+			CRAS_STREAM_INPUT,
+			CRAS_NODE_TYPE_HOTWORD);
 
 	/* Create loopback devices. */
 	loopdev_post_mix = loopback_iodev_create(LOOPBACK_POST_MIX_PRE_DSP);
@@ -1059,7 +1083,7 @@
 {
 	struct enabled_dev *edev;
 
-	DL_FOREACH (enabled_devs[dev->direction], edev) {
+	DL_FOREACH(enabled_devs[dev->direction], edev) {
 		if (edev->dev == dev)
 			return 1;
 	}
@@ -1108,7 +1132,7 @@
 
 	int is_the_only_enabled_device = 1;
 
-	DL_FOREACH (enabled_devs[dev->direction], edev) {
+	DL_FOREACH(enabled_devs[dev->direction], edev) {
 		if (edev->dev == dev)
 			edev_to_disable = edev;
 		else
@@ -1139,64 +1163,6 @@
 	return;
 }
 
-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;
-		/* Disconnect all streams that are either:
-		 * (1) normal stream while dev is enabled by UI, or
-		 * (2) stream specifically pins to this dev.
-		 */
-		if ((dev->is_enabled && !rstream->is_pinned) ||
-		    (rstream->is_pinned &&
-		     (dev->info.idx != rstream->pinned_dev_idx)))
-			audio_thread_disconnect_stream(audio_thread, rstream,
-						       dev);
-	}
-	close_dev(dev);
-	dev->update_active_node(dev, dev->active_node->idx, 0);
-}
-
-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 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);
-	}
-}
-
-void cras_iodev_list_set_dev_mute(unsigned int dev_idx)
-{
-	struct cras_iodev *dev;
-
-	dev = find_dev(dev_idx);
-	if (!dev)
-		return;
-
-	cras_iodev_set_mute(dev);
-}
-
 void cras_iodev_list_rm_active_node(enum CRAS_STREAM_DIRECTION dir,
 				    cras_node_id_t node_id)
 {
@@ -1275,32 +1241,16 @@
 	return get_dev_list(&devs[CRAS_STREAM_INPUT], list_out);
 }
 
-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)
 {
 	struct enabled_dev *edev = enabled_devs[direction];
 
 	return edev ? edev->dev : NULL;
 }
 
-struct cras_iodev *
-cras_iodev_list_get_sco_pcm_iodev(enum CRAS_STREAM_DIRECTION direction)
-{
-	struct cras_iodev *dev;
-	struct cras_ionode *node;
-
-	DL_FOREACH (devs[direction].iodevs, dev) {
-		DL_FOREACH (dev->nodes, node) {
-			if (node->is_sco_pcm)
-				return dev;
-		}
-	}
-
-	return NULL;
-}
-
-cras_node_id_t
-cras_iodev_list_get_active_node_id(enum CRAS_STREAM_DIRECTION direction)
+cras_node_id_t cras_iodev_list_get_active_node_id(
+	enum CRAS_STREAM_DIRECTION direction)
 {
 	struct enabled_dev *edev = enabled_devs[direction];
 
@@ -1326,12 +1276,12 @@
 	fill_dev_list(&devs[CRAS_STREAM_INPUT], &state->input_devs[0],
 		      CRAS_MAX_IODEVS);
 
-	state->num_output_nodes =
-		fill_node_list(&devs[CRAS_STREAM_OUTPUT],
-			       &state->output_nodes[0], CRAS_MAX_IONODES);
-	state->num_input_nodes =
-		fill_node_list(&devs[CRAS_STREAM_INPUT], &state->input_nodes[0],
-			       CRAS_MAX_IONODES);
+	state->num_output_nodes = fill_node_list(&devs[CRAS_STREAM_OUTPUT],
+						 &state->output_nodes[0],
+						 CRAS_MAX_IONODES);
+	state->num_input_nodes = fill_node_list(&devs[CRAS_STREAM_INPUT],
+						&state->input_nodes[0],
+						CRAS_MAX_IONODES);
 
 	cras_system_state_update_complete();
 }
@@ -1340,7 +1290,7 @@
 int find_hotword_stream_dev(struct cras_iodev **dev,
 			    struct cras_rstream **stream)
 {
-	DL_FOREACH (stream_list_get(stream_list), *stream) {
+	DL_FOREACH(stream_list_get(stream_list), *stream) {
 		if (((*stream)->flags & HOTWORD_STREAM) != HOTWORD_STREAM)
 			continue;
 
@@ -1375,20 +1325,18 @@
 	}
 	/* Move all existing hotword streams to the empty hotword iodev. */
 	init_pinned_device(empty_hotword_dev, stream);
-	DL_FOREACH (stream_list_get(stream_list), stream) {
+	DL_FOREACH(stream_list_get(stream_list), stream) {
 		if ((stream->flags & HOTWORD_STREAM) != HOTWORD_STREAM)
 			continue;
 		if (stream->pinned_dev_idx != hotword_dev->info.idx) {
 			syslog(LOG_ERR,
 			       "Failed to suspend hotword stream on dev %u",
-			       stream->pinned_dev_idx);
+				stream->pinned_dev_idx);
 			continue;
 		}
 
-		audio_thread_disconnect_stream(audio_thread, stream,
-					       hotword_dev);
-		audio_thread_add_stream(audio_thread, stream,
-					&empty_hotword_dev, 1);
+		audio_thread_disconnect_stream(audio_thread, stream, hotword_dev);
+		audio_thread_add_stream(audio_thread, stream, &empty_hotword_dev, 1);
 	}
 	close_pinned_device(hotword_dev);
 	hotword_suspended = 1;
@@ -1411,7 +1359,7 @@
 	}
 	/* Move all existing hotword streams to the real hotword iodev. */
 	init_pinned_device(hotword_dev, stream);
-	DL_FOREACH (stream_list_get(stream_list), stream) {
+	DL_FOREACH(stream_list_get(stream_list), stream) {
 		if ((stream->flags & HOTWORD_STREAM) != HOTWORD_STREAM)
 			continue;
 		if (stream->pinned_dev_idx != hotword_dev->info.idx) {
@@ -1421,8 +1369,7 @@
 			continue;
 		}
 
-		audio_thread_disconnect_stream(audio_thread, stream,
-					       empty_hotword_dev);
+		audio_thread_disconnect_stream(audio_thread, stream, empty_hotword_dev);
 		audio_thread_add_stream(audio_thread, stream, &hotword_dev, 1);
 	}
 	close_pinned_device(empty_hotword_dev);
@@ -1446,7 +1393,8 @@
 				      const char *model_name)
 {
 	int ret;
-	struct cras_iodev *dev = find_dev(dev_index_of(node_id));
+	struct cras_iodev *dev =
+			 find_dev(dev_index_of(node_id));
 	if (!dev || !dev->get_hotword_models ||
 	    (dev->active_node->type != CRAS_NODE_TYPE_HOTWORD))
 		return -EINVAL;
@@ -1464,10 +1412,10 @@
 }
 
 void cras_iodev_list_notify_active_node_changed(
-	enum CRAS_STREAM_DIRECTION direction)
+		enum CRAS_STREAM_DIRECTION direction)
 {
-	cras_observer_notify_active_node(
-		direction, cras_iodev_list_get_active_node_id(direction));
+	cras_observer_notify_active_node(direction,
+			cras_iodev_list_get_active_node_id(direction));
 }
 
 void cras_iodev_list_select_node(enum CRAS_STREAM_DIRECTION direction,
@@ -1475,7 +1423,7 @@
 {
 	struct cras_iodev *new_dev = NULL;
 	struct enabled_dev *edev;
-	int new_node_already_enabled = 0;
+        int new_node_already_enabled = 0;
 	int rc;
 
 	/* find the devices for the id. */
@@ -1492,7 +1440,7 @@
 	/* Determine whether the new device and node are already enabled - if
 	 * they are, the selection algorithm should avoid disabling the new
 	 * device. */
-	DL_FOREACH (enabled_devs[direction], edev) {
+	DL_FOREACH(enabled_devs[direction], edev) {
 		if (edev->dev == new_dev &&
 		    edev->dev->active_node->idx == node_index_of(node_id)) {
 			new_node_already_enabled = 1;
@@ -1506,11 +1454,11 @@
 	 * 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, false);
+		possibly_enable_fallback(direction);
 
 	/* Disable all devices except for fallback device, and the new device,
 	 * provided it is already enabled. */
-	DL_FOREACH (enabled_devs[direction], edev) {
+	DL_FOREACH(enabled_devs[direction], edev) {
 		if (edev->dev != fallback_devs[direction] &&
 		    !(new_node_already_enabled && edev->dev == new_dev)) {
 			disable_device(edev, false);
@@ -1531,107 +1479,17 @@
 	cras_iodev_list_notify_active_node_changed(direction);
 }
 
-static int set_node_plugged(struct cras_iodev *iodev, unsigned int node_idx,
-			    int plugged)
-{
-	struct cras_ionode *node;
-
-	node = find_node(iodev, node_idx);
-	if (!node)
-		return -EINVAL;
-	cras_iodev_set_node_plugged(node, plugged);
-	return 0;
-}
-
-static int set_node_volume(struct cras_iodev *iodev, unsigned int node_idx,
-			   int volume)
-{
-	struct cras_ionode *node;
-
-	node = find_node(iodev, node_idx);
-	if (!node)
-		return -EINVAL;
-
-	if (iodev->ramp && cras_iodev_software_volume_needed(iodev) &&
-	    !cras_system_get_mute())
-		cras_iodev_start_volume_ramp(iodev, node->volume, volume);
-
-	node->volume = volume;
-	if (iodev->set_volume)
-		iodev->set_volume(iodev);
-	cras_iodev_list_notify_node_volume(node);
-	return 0;
-}
-
-static int set_node_capture_gain(struct cras_iodev *iodev,
-				 unsigned int node_idx, int capture_gain)
-{
-	struct cras_ionode *node;
-
-	node = find_node(iodev, node_idx);
-	if (!node)
-		return -EINVAL;
-
-	node->capture_gain = capture_gain;
-	if (iodev->set_capture_gain)
-		iodev->set_capture_gain(iodev);
-	cras_iodev_list_notify_node_capture_gain(node);
-	return 0;
-}
-
-static int set_node_left_right_swapped(struct cras_iodev *iodev,
-				       unsigned int node_idx,
-				       int left_right_swapped)
+int cras_iodev_list_set_node_attr(cras_node_id_t node_id,
+				  enum ionode_attr attr, int value)
 {
 	struct cras_ionode *node;
 	int rc;
 
-	if (!iodev->set_swap_mode_for_node)
-		return -EINVAL;
-	node = find_node(iodev, node_idx);
+	node = find_node(node_id);
 	if (!node)
 		return -EINVAL;
 
-	rc = iodev->set_swap_mode_for_node(iodev, node, left_right_swapped);
-	if (rc) {
-		syslog(LOG_ERR, "Failed to set swap mode on node %s to %d",
-		       node->name, left_right_swapped);
-		return rc;
-	}
-	node->left_right_swapped = left_right_swapped;
-	cras_iodev_list_notify_node_left_right_swapped(node);
-	return 0;
-}
-
-int cras_iodev_list_set_node_attr(cras_node_id_t node_id, enum ionode_attr attr,
-				  int value)
-{
-	struct cras_iodev *iodev;
-	int rc = 0;
-
-	iodev = find_dev(dev_index_of(node_id));
-	if (!iodev)
-		return -EINVAL;
-
-	switch (attr) {
-	case IONODE_ATTR_PLUGGED:
-		rc = set_node_plugged(iodev, node_index_of(node_id), value);
-		break;
-	case IONODE_ATTR_VOLUME:
-		rc = set_node_volume(iodev, node_index_of(node_id), value);
-		break;
-	case IONODE_ATTR_CAPTURE_GAIN:
-		rc = set_node_capture_gain(iodev, node_index_of(node_id),
-					   value);
-		break;
-	case IONODE_ATTR_SWAP_LEFT_RIGHT:
-		rc = set_node_left_right_swapped(iodev, node_index_of(node_id),
-						 value);
-		break;
-	default:
-		return -EINVAL;
-	}
-
+	rc = cras_iodev_set_node_attr(node, attr, value);
 	return rc;
 }
 
@@ -1688,12 +1546,13 @@
 }
 
 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)
 {
 	struct device_enabled_cb *callback;
 
-	DL_FOREACH (device_enable_cbs, callback) {
+	DL_FOREACH(device_enable_cbs, callback) {
 		if (callback->cb_data != cb_data)
 			continue;
 
@@ -1702,8 +1561,8 @@
 	}
 
 	if (enabled_cb && disabled_cb) {
-		callback = (struct device_enabled_cb *)calloc(
-			1, sizeof(*callback));
+		callback = (struct device_enabled_cb *)
+				calloc(1, sizeof(*callback));
 		callback->enabled_cb = enabled_cb;
 		callback->disabled_cb = disabled_cb;
 		callback->cb_data = cb_data;
@@ -1713,81 +1572,16 @@
 	return 0;
 }
 
-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_control,
-				       unsigned int loopback_dev_idx)
-{
-	struct cras_iodev *iodev = find_dev(output_dev_idx);
-	struct cras_iodev *loopback_dev;
-	struct cras_loopback *loopback;
-	bool dev_open;
-
-	if (iodev == NULL) {
-		syslog(LOG_ERR, "Output dev %u not found for loopback",
-		       output_dev_idx);
-		return;
-	}
-
-	loopback_dev = find_dev(loopback_dev_idx);
-	if (loopback_dev == NULL) {
-		syslog(LOG_ERR, "Loopback dev %u not found", loopback_dev_idx);
-		return;
-	}
-
-	dev_open = cras_iodev_is_open(iodev);
-
-	loopback = (struct cras_loopback *)calloc(1, sizeof(*loopback));
-	if (NULL == loopback) {
-		syslog(LOG_ERR, "Not enough memory for loopback");
-		return;
-	}
-
-	loopback->type = loopback_type;
-	loopback->hook_data = hook_data;
-	loopback->hook_control = hook_control;
-	loopback->cb_data = loopback_dev;
-	if (loopback->hook_control && dev_open)
-		loopback->hook_control(true, loopback->cb_data);
-
-	DL_APPEND(iodev->loopbacks, loopback);
-}
-
-void cras_iodev_list_unregister_loopback(enum CRAS_LOOPBACK_TYPE type,
-					 unsigned int output_dev_idx,
-					 unsigned int loopback_dev_idx)
-{
-	struct cras_iodev *iodev = find_dev(output_dev_idx);
-	struct cras_iodev *loopback_dev;
-	struct cras_loopback *loopback;
-
-	if (iodev == NULL)
-		return;
-
-	loopback_dev = find_dev(loopback_dev_idx);
-	if (loopback_dev == NULL)
-		return;
-
-	DL_FOREACH (iodev->loopbacks, loopback) {
-		if ((loopback->cb_data == loopback_dev) &&
-		    (loopback->type == type)) {
-			DL_DELETE(iodev->loopbacks, loopback);
-			free(loopback);
-		}
-	}
-}
-
 void cras_iodev_list_reset()
 {
 	struct enabled_dev *edev;
 
-	DL_FOREACH (enabled_devs[CRAS_STREAM_OUTPUT], edev) {
+	DL_FOREACH(enabled_devs[CRAS_STREAM_OUTPUT], edev) {
 		DL_DELETE(enabled_devs[CRAS_STREAM_OUTPUT], edev);
 		free(edev);
 	}
 	enabled_devs[CRAS_STREAM_OUTPUT] = NULL;
-	DL_FOREACH (enabled_devs[CRAS_STREAM_INPUT], edev) {
+	DL_FOREACH(enabled_devs[CRAS_STREAM_INPUT], edev) {
 		DL_DELETE(enabled_devs[CRAS_STREAM_INPUT], edev);
 		free(edev);
 	}
diff --git a/cras/src/server/cras_iodev_list.h b/cras/src/server/cras_iodev_list.h
index 61c3a18..96c7306 100644
--- a/cras/src/server/cras_iodev_list.h
+++ b/cras/src/server/cras_iodev_list.h
@@ -12,17 +12,19 @@
 #include <stdbool.h>
 #include <stdint.h>
 
-#include "cras_iodev.h"
 #include "cras_types.h"
 
+struct cras_iodev;
+struct cras_iodev_info;
+struct cras_ionode;
 struct cras_rclient;
+struct cras_rstream;
+struct cras_audio_format;
 struct stream_list;
 
 /* Device enabled/disabled callback. */
-typedef void (*device_enabled_callback_t)(struct cras_iodev *dev,
-					  void *cb_data);
-typedef void (*device_disabled_callback_t)(struct cras_iodev *dev,
-					   void *cb_data);
+typedef void (*device_enabled_callback_t)(struct cras_iodev *dev, void *cb_data);
+typedef void (*device_disabled_callback_t)(struct cras_iodev *dev, void *cb_data);
 
 /* Initialize the list of iodevs. */
 void cras_iodev_list_init();
@@ -88,17 +90,8 @@
  * Returns:
  *    Pointer to the first enabled device of direction.
  */
-struct cras_iodev *
-cras_iodev_list_get_first_enabled_iodev(enum CRAS_STREAM_DIRECTION direction);
-
-/* Returns SCO PCM device.
- * Args:
- *    direction - Playback or capture.
- * Returns:
- *    Pointer to the SCO PCM device of direction.
- */
-struct cras_iodev *
-cras_iodev_list_get_sco_pcm_iodev(enum CRAS_STREAM_DIRECTION direction);
+struct cras_iodev *cras_iodev_list_get_first_enabled_iodev(
+	enum CRAS_STREAM_DIRECTION direction);
 
 /* Returns the active node id.
  * Args:
@@ -106,8 +99,8 @@
  * Returns:
  *    The id of the active node.
  */
-cras_node_id_t
-cras_iodev_list_get_active_node_id(enum CRAS_STREAM_DIRECTION direction);
+cras_node_id_t cras_iodev_list_get_active_node_id(
+	enum CRAS_STREAM_DIRECTION direction);
 
 /* Stores the following data to the shared memory server state region:
  * (1) device list
@@ -135,7 +128,7 @@
  *    direction - Direction of the node.
  */
 void cras_iodev_list_notify_active_node_changed(
-	enum CRAS_STREAM_DIRECTION direction);
+		enum CRAS_STREAM_DIRECTION direction);
 
 /* Sets an attribute of an ionode on a device.
  * Args:
@@ -144,8 +137,8 @@
  *    attr - the attribute we want to change.
  *    value - the value we want to set.
  */
-int cras_iodev_list_set_node_attr(cras_node_id_t id, enum ionode_attr attr,
-				  int value);
+int cras_iodev_list_set_node_attr(cras_node_id_t id,
+				  enum ionode_attr attr, int value);
 
 /* Select a node as the preferred node.
  * Args:
@@ -156,10 +149,7 @@
 void cras_iodev_list_select_node(enum CRAS_STREAM_DIRECTION direction,
 				 cras_node_id_t node_id);
 
-/*
- * Checks if an iodev is enabled. By enabled we mean all default streams will
- * be routed to this iodev.
- */
+/* Checks if an iodev is enabled. */
 int cras_iodev_list_dev_is_enabled(const struct cras_iodev *dev);
 
 /* Enables an iodev. If the fallback device was already enabled, this
@@ -167,25 +157,6 @@
 void cras_iodev_list_enable_dev(struct cras_iodev *dev);
 
 /*
- * Suspends the connection of all types of stream attached to given iodev.
- * This call doesn't disable the given iodev.
- */
-void cras_iodev_list_suspend_dev(unsigned int dev_idx);
-
-/*
- * Resumes the connection of all types of stream attached to given iodev.
- * This call doesn't enable the given dev.
- */
-void cras_iodev_list_resume_dev(unsigned int dev_idx);
-
-/*
- * Sets mute state to device of given index.
- * Args:
- *    dev_idx - Index of the device to set mute state.
- */
-void cras_iodev_list_set_dev_mute(unsigned int dev_idx);
-
-/*
  * Disables an iodev. If this is the last device to disable, the
  * fallback devices will be enabled accordingly.
  * Set `foce_close` to true if the device must be closed regardless of having
@@ -238,35 +209,9 @@
 
 /* Sets the function to call when a device is enabled or disabled. */
 int cras_iodev_list_set_device_enabled_callback(
-	device_enabled_callback_t enabled_cb,
-	device_disabled_callback_t disabled_cb, void *cb_data);
-
-/* Registers loopback to an output device.
- * Args:
- *    loopback_type - Pre or post software DSP.
- *    output_dev_idx - Index of the target output device.
- *    hook_data - Callback function to process loopback data.
- *    hook_start - Callback for starting or stopping loopback.
- *    loopback_dev_idx - Index of the loopback device that
- *        listens for output data.
- */
-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);
-
-/* Unregisters loopback from an output device by matching
- * loopback type and loopback device index.
- * Args:
- *    loopback_type - Pre or post software DSP.
- *    output_dev_idx - Index of the target output device.
- *    loopback_dev_idx - Index of the loopback device that
- *        listens for output data.
- */
-void cras_iodev_list_unregister_loopback(enum CRAS_LOOPBACK_TYPE loopback_type,
-					 unsigned int output_dev_idx,
-					 unsigned int loopback_dev_idx);
+		device_enabled_callback_t enabled_cb,
+		device_disabled_callback_t disabled_cb,
+		void *cb_data);
 
 /* Suspends all hotwording streams. */
 int cras_iodev_list_suspend_hotword_streams();
diff --git a/cras/src/server/cras_loopback_iodev.c b/cras/src/server/cras_loopback_iodev.c
index dea9616..2598089 100644
--- a/cras/src/server/cras_loopback_iodev.c
+++ b/cras/src/server/cras_loopback_iodev.c
@@ -24,50 +24,45 @@
 	"Post DSP Loopback",
 };
 
-static size_t loopback_supported_rates[] = { 48000, 0 };
+static size_t loopback_supported_rates[] = {
+	48000, 0
+};
 
-static size_t loopback_supported_channel_counts[] = { 2, 0 };
+static size_t loopback_supported_channel_counts[] = {
+	2, 0
+};
 
 static snd_pcm_format_t loopback_supported_formats[] = {
 	SND_PCM_FORMAT_S16_LE,
-	0,
+	0
 };
 
 /* loopack iodev.  Keep state of a loopback device.
- *    loopback_type - Pre-dsp or post-dsp.
- *    read_frames - Frames of audio data read since last dev start.
- *    started - True to indicate the target device is running, otherwise false.
- *    dev_start_time - The timestamp of the last call to configure_dev.
  *    sample_buffer - Pointer to sample buffer.
- *    sender_idx - Index of the output device to read loopback audio.
  */
 struct loopback_iodev {
 	struct cras_iodev base;
 	enum CRAS_LOOPBACK_TYPE loopback_type;
-	uint64_t read_frames;
-	bool started;
-	struct timespec dev_start_time;
+	struct timespec last_filled;
 	struct byte_buffer *sample_buffer;
-	unsigned int sender_idx;
 };
 
-static int sample_hook_start(bool start, void *cb_data)
-{
-	struct loopback_iodev *loopdev = (struct loopback_iodev *)cb_data;
-	loopdev->started = start;
-	return 0;
-}
-
-/*
- * Called in the put buffer function of the sender that hooked to.
- */
 static int sample_hook(const uint8_t *frames, unsigned int nframes,
-		       const struct cras_audio_format *fmt, void *cb_data)
+		       const struct cras_audio_format *fmt,
+		       void *cb_data)
 {
 	struct loopback_iodev *loopdev = (struct loopback_iodev *)cb_data;
 	struct byte_buffer *sbuf = loopdev->sample_buffer;
 	unsigned int frame_bytes = cras_get_format_bytes(fmt);
 	unsigned int frames_to_copy, bytes_to_copy;
+	struct cras_iodev *edev = cras_iodev_list_get_first_enabled_iodev(
+			CRAS_STREAM_OUTPUT);
+
+	/* If there's no active streams, the logic in frames_queued will fill
+	 * zeros for loopback capture, do not accept zeros for draining device.
+	 */
+	if (!edev || !edev->streams)
+		return 0;
 
 	frames_to_copy = MIN(buf_writable(sbuf) / frame_bytes, nframes);
 	if (!frames_to_copy)
@@ -76,46 +71,51 @@
 	bytes_to_copy = frames_to_copy * frame_bytes;
 	memcpy(buf_write_pointer(sbuf), frames, bytes_to_copy);
 	buf_increment_write(sbuf, bytes_to_copy);
+	clock_gettime(CLOCK_MONOTONIC_RAW, &loopdev->last_filled);
 
 	return frames_to_copy;
 }
 
-static void update_first_output_to_loopback(struct loopback_iodev *loopdev)
+static void register_loopback_hook(enum CRAS_LOOPBACK_TYPE loopback_type,
+				   struct cras_iodev *iodev,
+				   loopback_hook_t hook, void *cb_data)
 {
-	struct cras_iodev *edev;
-
-	/* Register loopback hook onto first enabled iodev. */
-	edev = cras_iodev_list_get_first_enabled_iodev(CRAS_STREAM_OUTPUT);
-	if (edev) {
-		loopdev->sender_idx = edev->info.idx;
-		cras_iodev_list_register_loopback(
-			loopdev->loopback_type, loopdev->sender_idx,
-			sample_hook, sample_hook_start, loopdev->base.info.idx);
+	if (!iodev) {
+		syslog(LOG_ERR, "Failed to register loopback hook.");
+		return;
 	}
+
+	if (loopback_type == LOOPBACK_POST_MIX_PRE_DSP)
+		cras_iodev_register_pre_dsp_hook(iodev, hook, cb_data);
+	else if (loopback_type == LOOPBACK_POST_DSP)
+		cras_iodev_register_post_dsp_hook(iodev, hook, cb_data);
 }
 
 static void device_enabled_hook(struct cras_iodev *iodev, void *cb_data)
 {
 	struct loopback_iodev *loopdev = (struct loopback_iodev *)cb_data;
+	struct cras_iodev *edev;
 
 	if (iodev->direction != CRAS_STREAM_OUTPUT)
 		return;
 
-	update_first_output_to_loopback(loopdev);
+	/* Register loopback hook onto first enabled iodev. */
+	edev = cras_iodev_list_get_first_enabled_iodev(
+			CRAS_STREAM_OUTPUT);
+	register_loopback_hook(loopdev->loopback_type, edev,
+			       sample_hook, cb_data);
 }
 
 static void device_disabled_hook(struct cras_iodev *iodev, void *cb_data)
 {
 	struct loopback_iodev *loopdev = (struct loopback_iodev *)cb_data;
 
-	if (loopdev->sender_idx != iodev->info.idx)
+	if (iodev->direction != CRAS_STREAM_OUTPUT)
 		return;
 
 	/* Unregister loopback hook from disabled iodev. */
-	cras_iodev_list_unregister_loopback(loopdev->loopback_type,
-					    loopdev->sender_idx,
-					    loopdev->base.info.idx);
-	update_first_output_to_loopback(loopdev);
+	register_loopback_hook(loopdev->loopback_type, iodev, NULL,
+			       NULL);
 }
 
 /*
@@ -128,25 +128,26 @@
 	struct loopback_iodev *loopdev = (struct loopback_iodev *)iodev;
 	struct byte_buffer *sbuf = loopdev->sample_buffer;
 	unsigned int frame_bytes = cras_get_format_bytes(iodev->format);
+	struct cras_iodev *edev = cras_iodev_list_get_first_enabled_iodev(
+			CRAS_STREAM_OUTPUT);
 
-	if (!loopdev->started) {
-		unsigned int frames_since_start, frames_to_fill, bytes_to_fill;
+	if (!edev || !edev->streams) {
+		unsigned int frames_since_last, frames_to_fill, bytes_to_fill;
 
-		frames_since_start = cras_frames_since_time(
-			&loopdev->dev_start_time, iodev->format->frame_rate);
-		frames_to_fill =
-			frames_since_start > loopdev->read_frames ?
-				frames_since_start - loopdev->read_frames :
-				0;
-		frames_to_fill =
-			MIN(buf_writable(sbuf) / frame_bytes, frames_to_fill);
+		frames_since_last = cras_frames_since_time(
+				&loopdev->last_filled,
+				iodev->format->frame_rate);
+		frames_to_fill = MIN(buf_writable(sbuf) / frame_bytes,
+				     frames_since_last);
 		if (frames_to_fill > 0) {
 			bytes_to_fill = frames_to_fill * frame_bytes;
 			memset(buf_write_pointer(sbuf), 0, bytes_to_fill);
 			buf_increment_write(sbuf, bytes_to_fill);
+			clock_gettime(CLOCK_MONOTONIC_RAW,
+				      &loopdev->last_filled);
 		}
 	}
-	clock_gettime(CLOCK_MONOTONIC_RAW, hw_tstamp);
+	*hw_tstamp = loopdev->last_filled;
 	return buf_queued(sbuf) / frame_bytes;
 }
 
@@ -161,15 +162,14 @@
 {
 	struct loopback_iodev *loopdev = (struct loopback_iodev *)iodev;
 	struct byte_buffer *sbuf = loopdev->sample_buffer;
+	struct cras_iodev *edev;
 
 	cras_iodev_free_format(iodev);
 	cras_iodev_free_audio_area(iodev);
 	buf_reset(sbuf);
 
-	cras_iodev_list_unregister_loopback(loopdev->loopback_type,
-					    loopdev->sender_idx,
-					    loopdev->base.info.idx);
-	loopdev->sender_idx = NO_DEVICE;
+	edev = cras_iodev_list_get_first_enabled_iodev(CRAS_STREAM_OUTPUT);
+	register_loopback_hook(loopdev->loopback_type, edev, NULL, NULL);
 	cras_iodev_list_set_device_enabled_callback(NULL, NULL, (void *)iodev);
 
 	return 0;
@@ -181,25 +181,21 @@
 	struct cras_iodev *edev;
 
 	cras_iodev_init_audio_area(iodev, iodev->format->num_channels);
-	clock_gettime(CLOCK_MONOTONIC_RAW, &loopdev->dev_start_time);
-	loopdev->read_frames = 0;
-	loopdev->started = 0;
+	clock_gettime(CLOCK_MONOTONIC_RAW, &loopdev->last_filled);
 
 	edev = cras_iodev_list_get_first_enabled_iodev(CRAS_STREAM_OUTPUT);
-	if (edev) {
-		loopdev->sender_idx = edev->info.idx;
-		cras_iodev_list_register_loopback(
-			loopdev->loopback_type, loopdev->sender_idx,
-			sample_hook, sample_hook_start, iodev->info.idx);
-	}
-	cras_iodev_list_set_device_enabled_callback(
-		device_enabled_hook, device_disabled_hook, (void *)iodev);
+	register_loopback_hook(loopdev->loopback_type, edev, sample_hook,
+			       (void *)iodev);
+	cras_iodev_list_set_device_enabled_callback(device_enabled_hook,
+						    device_disabled_hook,
+						    (void *)iodev);
 
 	return 0;
 }
 
 static int get_record_buffer(struct cras_iodev *iodev,
-			     struct cras_audio_area **area, unsigned *frames)
+		      struct cras_audio_area **area,
+		      unsigned *frames)
 {
 	struct loopback_iodev *loopdev = (struct loopback_iodev *)iodev;
 	struct byte_buffer *sbuf = loopdev->sample_buffer;
@@ -222,7 +218,7 @@
 	unsigned int frame_bytes = cras_get_format_bytes(iodev->format);
 
 	buf_increment_read(sbuf, nframes * frame_bytes);
-	loopdev->read_frames += nframes;
+
 	return 0;
 }
 
@@ -232,7 +228,6 @@
 	struct byte_buffer *sbuf = loopdev->sample_buffer;
 	unsigned int queued_bytes = buf_queued(sbuf);
 	buf_increment_read(sbuf, queued_bytes);
-	loopdev->read_frames = 0;
 	return 0;
 }
 
@@ -250,7 +245,7 @@
 	if (loopback_iodev == NULL)
 		return NULL;
 
-	loopback_iodev->sample_buffer = byte_buffer_create(1024 * 16 * 4);
+	loopback_iodev->sample_buffer = byte_buffer_create(1024*16*4);
 	if (loopback_iodev->sample_buffer == NULL) {
 		free(loopback_iodev);
 		return NULL;
@@ -263,9 +258,10 @@
 	snprintf(iodev->info.name, ARRAY_SIZE(iodev->info.name), "%s",
 		 loopdev_names[type]);
 	iodev->info.name[ARRAY_SIZE(iodev->info.name) - 1] = '\0';
-	iodev->info.stable_id =
-		SuperFastHash(iodev->info.name, strlen(iodev->info.name),
-			      strlen(iodev->info.name));
+	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;
@@ -316,6 +312,7 @@
 	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]);
@@ -333,7 +330,7 @@
 	struct byte_buffer *sbuf = loopdev->sample_buffer;
 
 	cras_iodev_list_rm_input(iodev);
-	free(iodev->nodes);
+        free(iodev->nodes);
 
 	byte_buffer_destroy(&sbuf);
 	free(loopdev);
diff --git a/cras/src/server/cras_main_message.c b/cras/src/server/cras_main_message.c
index 9fe62af..1187102 100644
--- a/cras/src/server/cras_main_message.c
+++ b/cras/src/server/cras_main_message.c
@@ -1,4 +1,4 @@
-/* Copyright 2015 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2015 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.
  */
@@ -12,6 +12,7 @@
 #include "cras_system_state.h"
 #include "cras_util.h"
 
+
 /* Callback to handle specific type of main thread message. */
 struct cras_main_msg_callback {
 	enum CRAS_MAIN_MESSAGE_TYPE type;
@@ -29,7 +30,7 @@
 {
 	struct cras_main_msg_callback *msg_cb;
 
-	DL_FOREACH (main_msg_callbacks, msg_cb) {
+	DL_FOREACH(main_msg_callbacks, msg_cb) {
 		if (msg_cb->type == type) {
 			syslog(LOG_ERR, "Main message type %u already exists",
 			       type);
@@ -59,8 +60,7 @@
 	return 0;
 }
 
-static int read_main_message(int msg_fd, uint8_t *buf, size_t max_len)
-{
+static int read_main_message(int msg_fd, uint8_t *buf, size_t max_len) {
 	int to_read, nread, rc;
 	struct cras_main_message *msg = (struct cras_main_message *)buf;
 
@@ -90,7 +90,7 @@
 		return;
 	}
 
-	DL_FOREACH (main_msg_callbacks, main_msg_cb) {
+	DL_FOREACH(main_msg_callbacks, main_msg_cb) {
 		if (main_msg_cb->type == msg->type) {
 			main_msg_cb->callback(msg, main_msg_cb->callback_data);
 			break;
@@ -98,8 +98,7 @@
 	}
 }
 
-void cras_main_message_init()
-{
+void cras_main_message_init() {
 	int rc;
 
 	rc = pipe(main_msg_fds);
@@ -112,5 +111,7 @@
 	cras_make_fd_nonblocking(main_msg_fds[0]);
 	cras_make_fd_nonblocking(main_msg_fds[1]);
 
-	cras_system_add_select_fd(main_msg_fds[0], handle_main_messages, NULL);
+	cras_system_add_select_fd(main_msg_fds[0],
+				  handle_main_messages,
+				  NULL);
 }
diff --git a/cras/src/server/cras_main_message.h b/cras/src/server/cras_main_message.h
index fd63488..5a2bb28 100644
--- a/cras/src/server/cras_main_message.h
+++ b/cras/src/server/cras_main_message.h
@@ -33,7 +33,8 @@
 };
 
 /* Callback function to handle main thread message. */
-typedef void (*cras_message_callback)(struct cras_main_message *msg, void *arg);
+typedef void (*cras_message_callback)(struct cras_main_message *msg,
+				      void *arg);
 
 /* Sends a message to main thread. */
 int cras_main_message_send(struct cras_main_message *msg);
diff --git a/cras/src/server/cras_mix.c b/cras/src/server/cras_mix.c
index ffe556b..b0694fd 100644
--- a/cras/src/server/cras_mix.c
+++ b/cras/src/server/cras_mix.c
@@ -11,7 +11,7 @@
 
 static const struct cras_mix_ops *ops = &mixer_ops;
 
-static const struct cras_mix_ops *get_mixer_ops(unsigned int cpu_flags)
+static const struct cras_mix_ops* get_mixer_ops(unsigned int cpu_flags)
 {
 #if defined HAVE_FMA
 	if (cpu_flags & CPU_X86_FMA)
@@ -45,10 +45,10 @@
 
 void cras_scale_buffer_increment(snd_pcm_format_t fmt, uint8_t *buff,
 				 unsigned int frame, float scaler,
-				 float increment, float target, int channel)
+				 float increment, int channel)
 {
 	ops->scale_buffer_increment(fmt, buff, frame * channel, scaler,
-				    increment, target, channel);
+				    increment, channel);
 }
 
 void cras_scale_buffer(snd_pcm_format_t fmt, uint8_t *buff, unsigned int count,
@@ -58,21 +58,23 @@
 }
 
 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)
+		  unsigned int count, unsigned int index,
+		  int mute, float mix_vol)
 {
 	ops->add(fmt, dst, src, count, index, mute, mix_vol);
 }
 
 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 count, unsigned int dst_stride,
+			 unsigned int src_stride, float scaler)
 {
 	ops->add_scale_stride(fmt, dst, src, count, dst_stride, src_stride,
 			      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)
 {
 	return ops->mute_buffer(dst, frame_bytes, count);
 }
diff --git a/cras/src/server/cras_mix.h b/cras/src/server/cras_mix.h
index 5c21df9..c16614a 100644
--- a/cras/src/server/cras_mix.h
+++ b/cras/src/server/cras_mix.h
@@ -6,15 +6,13 @@
 #ifndef _CRAS_MIX_H
 #define _CRAS_MIX_H
 
-#include "cras_types.h"
-
 struct cras_audio_shm;
 
 /* SIMD optimisation flags */
-#define CPU_X86_SSE4_2 1
-#define CPU_X86_AVX 2
-#define CPU_X86_AVX2 4
-#define CPU_X86_FMA 8
+#define CPU_X86_SSE4_2		1
+#define CPU_X86_AVX			2
+#define CPU_X86_AVX2			4
+#define CPU_X86_FMA			8
 
 void cras_mix_init(unsigned int flags);
 
@@ -25,13 +23,12 @@
  *    frame - The number of frames to render.
  *    scaler - Amount to scale samples (0.0 - 1.0).
  *    increment - The increment(+/-) of scaler at each frame. The scaler after
- *                increasing/decreasing will be clipped at target.
- *    target - The value at which to clip the scaler.
+ *                increasing/descreasing will be clipped to (0.0 - 1.0).
  *    channel - Number of samples in a frame.
  */
 void cras_scale_buffer_increment(snd_pcm_format_t fmt, uint8_t *buff,
 				 unsigned int frame, float scaler,
-				 float increment, float target, int channel);
+				 float increment, int channel);
 
 /* Scale the given buffer with the provided scaler.
  * Args:
@@ -55,8 +52,8 @@
  *    mix_vol - Scaler for the buffer to be mixed.
  */
 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);
+		  unsigned int count, unsigned int index,
+		  int mute, float mix_vol);
 
 /* Add src buffer to dst with independent channel strides.
  * Args:
@@ -69,8 +66,8 @@
  *    scaler - Amount to scale samples.
  */
 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 count, unsigned int dst_stride,
+			 unsigned int src_stride, float scaler);
 
 /* Mutes the given buffer.
  * Args:
@@ -78,6 +75,8 @@
  *    frame_bytes - number of bytes in a frame.
  *    count - The number of frames to render.
  */
-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);
 
 #endif /* _CRAS_MIX_H */
diff --git a/cras/src/server/cras_mix_ops.c b/cras/src/server/cras_mix_ops.c
index 2425f09..f12f783 100644
--- a/cras/src/server/cras_mix_ops.c
+++ b/cras/src/server/cras_mix_ops.c
@@ -13,23 +13,22 @@
 
 /* function suffixes for SIMD ops */
 #ifdef OPS_SSE42
-#define OPS(a) a##_sse42
+	#define OPS(a) a ## _sse42
 #elif OPS_AVX
-#define OPS(a) a##_avx
+	#define OPS(a) a ## _avx
 #elif OPS_AVX2
-#define OPS(a) a##_avx2
+	#define OPS(a) a ## _avx2
 #elif OPS_FMA
-#define OPS(a) a##_fma
+	#define OPS(a) a ## _fma
 #else
-#define OPS(a) a
+	#define OPS(a) a
 #endif
 
 /* Checks if the scaler needs a scaling operation.
  * We skip scaling for scaler too close to 1.0.
  * Note that this is not subjected to MAX_VOLUME_TO_SCALE
  * and MIN_VOLUME_TO_SCALE. */
-static inline int need_to_scale(float scaler)
-{
+static inline int need_to_scale(float scaler) {
 	return (scaler < 0.99 || scaler > 1.01);
 }
 
@@ -37,7 +36,8 @@
  * Signed 16 bit little endian functions.
  */
 
-static void cras_mix_add_clip_s16_le(int16_t *dst, const int16_t *src,
+static void cras_mix_add_clip_s16_le(int16_t *dst,
+				     const int16_t *src,
 				     size_t count)
 {
 	int32_t sum;
@@ -55,8 +55,10 @@
 
 /* Adds src into dst, after scaling by vol.
  * Just hard limits to the min and max S16 value, can be improved later. */
-static void scale_add_clip_s16_le(int16_t *dst, const int16_t *src,
-				  size_t count, float vol)
+static void scale_add_clip_s16_le(int16_t *dst,
+				  const int16_t *src,
+				  size_t count,
+				  float vol)
 {
 	int32_t sum;
 	size_t i;
@@ -76,7 +78,9 @@
 
 /* Adds the first stream to the mix.  Don't need to mix, just setup to the new
  * values. If volume is 1.0, just memcpy. */
-static void copy_scaled_s16_le(int16_t *dst, const int16_t *src, size_t count,
+static void copy_scaled_s16_le(int16_t *dst,
+			       const int16_t *src,
+			       size_t count,
 			       float volume_scaler)
 {
 	int i;
@@ -91,12 +95,14 @@
 }
 
 static void cras_scale_buffer_inc_s16_le(uint8_t *buffer, unsigned int count,
-					 float scaler, float increment,
-					 float target, int step)
+					 float scaler, float increment, int step)
 {
 	int i = 0, j;
 	int16_t *out = (int16_t *)buffer;
 
+	if (scaler > MAX_VOLUME_TO_SCALE && increment > 0)
+		return;
+
 	if (scaler < MIN_VOLUME_TO_SCALE && increment < 0) {
 		memset(out, 0, count * sizeof(*out));
 		return;
@@ -104,17 +110,11 @@
 
 	while (i + step <= count) {
 		for (j = 0; j < step; j++) {
-			float applied_scaler = scaler;
-
-			if ((applied_scaler > target && increment > 0) ||
-			    (applied_scaler < target && increment < 0))
-				applied_scaler = target;
-
-			if (applied_scaler > MAX_VOLUME_TO_SCALE) {
-			} else if (applied_scaler < MIN_VOLUME_TO_SCALE) {
+			if (scaler > MAX_VOLUME_TO_SCALE) {
+			} else if (scaler < MIN_VOLUME_TO_SCALE) {
 				out[i] = 0;
 			} else {
-				out[i] *= applied_scaler;
+				out[i] *= scaler;
 			}
 			i++;
 		}
@@ -140,8 +140,9 @@
 		out[i] *= scaler;
 }
 
-static void cras_mix_add_s16_le(uint8_t *dst, uint8_t *src, unsigned int count,
-				unsigned int index, int mute, float mix_vol)
+static void cras_mix_add_s16_le(uint8_t *dst, uint8_t *src,
+				unsigned int count, unsigned int index,
+				int mute, float mix_vol)
 {
 	int16_t *out = (int16_t *)dst;
 	int16_t *in = (int16_t *)src;
@@ -159,42 +160,45 @@
 }
 
 static void cras_mix_add_scale_stride_s16_le(uint8_t *dst, uint8_t *src,
-					     unsigned int dst_stride,
-					     unsigned int src_stride,
-					     unsigned int count, float scaler)
+				unsigned int dst_stride,
+				unsigned int src_stride,
+				unsigned int count,
+				float scaler)
 {
 	unsigned int i;
 
 	/* optimise the loops for vectorization */
 	if (dst_stride == src_stride && dst_stride == 2) {
+
 		for (i = 0; i < count; i++) {
 			int32_t sum;
 			if (need_to_scale(scaler))
 				sum = *(int16_t *)dst +
-				      *(int16_t *)src * scaler;
+						*(int16_t *)src * scaler;
 			else
 				sum = *(int16_t *)dst + *(int16_t *)src;
 			if (sum > INT16_MAX)
 				sum = INT16_MAX;
 			else if (sum < INT16_MIN)
 				sum = INT16_MIN;
-			*(int16_t *)dst = sum;
+			*(int16_t*)dst = sum;
 			dst += 2;
 			src += 2;
 		}
 	} else if (dst_stride == src_stride && dst_stride == 4) {
+
 		for (i = 0; i < count; i++) {
 			int32_t sum;
 			if (need_to_scale(scaler))
 				sum = *(int16_t *)dst +
-				      *(int16_t *)src * scaler;
+						*(int16_t *)src * scaler;
 			else
 				sum = *(int16_t *)dst + *(int16_t *)src;
 			if (sum > INT16_MAX)
 				sum = INT16_MAX;
 			else if (sum < INT16_MIN)
 				sum = INT16_MIN;
-			*(int16_t *)dst = sum;
+			*(int16_t*)dst = sum;
 			dst += 4;
 			src += 4;
 		}
@@ -203,14 +207,14 @@
 			int32_t sum;
 			if (need_to_scale(scaler))
 				sum = *(int16_t *)dst +
-				      *(int16_t *)src * scaler;
+						*(int16_t *)src * scaler;
 			else
 				sum = *(int16_t *)dst + *(int16_t *)src;
 			if (sum > INT16_MAX)
 				sum = INT16_MAX;
 			else if (sum < INT16_MIN)
 				sum = INT16_MIN;
-			*(int16_t *)dst = sum;
+			*(int16_t*)dst = sum;
 			dst += dst_stride;
 			src += src_stride;
 		}
@@ -221,14 +225,8 @@
  * Signed 24 bit little endian functions.
  */
 
-static int32_t scale_s24_le(int32_t value, float scaler)
-{
-	value = ((uint32_t)(value & 0x00ffffff)) << 8;
-	value *= scaler;
-	return (value >> 8) & 0x00ffffff;
-}
-
-static void cras_mix_add_clip_s24_le(int32_t *dst, const int32_t *src,
+static void cras_mix_add_clip_s24_le(int32_t *dst,
+				     const int32_t *src,
 				     size_t count)
 {
 	int32_t sum;
@@ -246,8 +244,10 @@
 
 /* Adds src into dst, after scaling by vol.
  * Just hard limits to the min and max S24 value, can be improved later. */
-static void scale_add_clip_s24_le(int32_t *dst, const int32_t *src,
-				  size_t count, float vol)
+static void scale_add_clip_s24_le(int32_t *dst,
+				  const int32_t *src,
+				  size_t count,
+				  float vol)
 {
 	int32_t sum;
 	size_t i;
@@ -267,7 +267,9 @@
 
 /* Adds the first stream to the mix.  Don't need to mix, just setup to the new
  * values. If volume is 1.0, just memcpy. */
-static void copy_scaled_s24_le(int32_t *dst, const int32_t *src, size_t count,
+static void copy_scaled_s24_le(int32_t *dst,
+			       const int32_t *src,
+			       size_t count,
 			       float volume_scaler)
 {
 	int i;
@@ -278,16 +280,18 @@
 	}
 
 	for (i = 0; i < count; i++)
-		dst[i] = scale_s24_le(src[i], volume_scaler);
+		dst[i] = src[i] * volume_scaler;
 }
 
 static void cras_scale_buffer_inc_s24_le(uint8_t *buffer, unsigned int count,
-					 float scaler, float increment,
-					 float target, int step)
+					 float scaler, float increment, int step)
 {
 	int i = 0, j;
 	int32_t *out = (int32_t *)buffer;
 
+	if (scaler > MAX_VOLUME_TO_SCALE && increment > 0)
+		return;
+
 	if (scaler < MIN_VOLUME_TO_SCALE && increment < 0) {
 		memset(out, 0, count * sizeof(*out));
 		return;
@@ -295,17 +299,11 @@
 
 	while (i + step <= count) {
 		for (j = 0; j < step; j++) {
-			float applied_scaler = scaler;
-
-			if ((applied_scaler > target && increment > 0) ||
-			    (applied_scaler < target && increment < 0))
-				applied_scaler = target;
-
-			if (applied_scaler > MAX_VOLUME_TO_SCALE) {
-			} else if (applied_scaler < MIN_VOLUME_TO_SCALE) {
+			if (scaler > MAX_VOLUME_TO_SCALE) {
+			} else if (scaler < MIN_VOLUME_TO_SCALE) {
 				out[i] = 0;
 			} else {
-				out[i] = scale_s24_le(out[i], applied_scaler);
+				out[i] *= scaler;
 			}
 			i++;
 		}
@@ -328,11 +326,12 @@
 	}
 
 	for (i = 0; i < count; i++)
-		out[i] = scale_s24_le(out[i], scaler);
+		out[i] *= scaler;
 }
 
-static void cras_mix_add_s24_le(uint8_t *dst, uint8_t *src, unsigned int count,
-				unsigned int index, int mute, float mix_vol)
+static void cras_mix_add_s24_le(uint8_t *dst, uint8_t *src,
+				unsigned int count, unsigned int index,
+				int mute, float mix_vol)
 {
 	int32_t *out = (int32_t *)dst;
 	int32_t *in = (int32_t *)src;
@@ -350,42 +349,45 @@
 }
 
 static void cras_mix_add_scale_stride_s24_le(uint8_t *dst, uint8_t *src,
-					     unsigned int dst_stride,
-					     unsigned int src_stride,
-					     unsigned int count, float scaler)
+				unsigned int dst_stride,
+				unsigned int src_stride,
+				unsigned int count,
+				float scaler)
 {
 	unsigned int i;
 
 	/* optimise the loops for vectorization */
 	if (dst_stride == src_stride && dst_stride == 4) {
+
 		for (i = 0; i < count; i++) {
 			int32_t sum;
 			if (need_to_scale(scaler))
 				sum = *(int32_t *)dst +
-				      scale_s24_le(*(int32_t *)src, scaler);
+						*(int32_t *)src * scaler;
 			else
 				sum = *(int32_t *)dst + *(int32_t *)src;
 			if (sum > 0x007fffff)
 				sum = 0x007fffff;
 			else if (sum < (int32_t)0xff800000)
 				sum = (int32_t)0xff800000;
-			*(int32_t *)dst = sum;
+			*(int32_t*)dst = sum;
 			dst += 4;
 			src += 4;
 		}
 	} else {
+
 		for (i = 0; i < count; i++) {
 			int32_t sum;
 			if (need_to_scale(scaler))
 				sum = *(int32_t *)dst +
-				      scale_s24_le(*(int32_t *)src, scaler);
+						*(int32_t *)src * scaler;
 			else
 				sum = *(int32_t *)dst + *(int32_t *)src;
 			if (sum > 0x007fffff)
 				sum = 0x007fffff;
 			else if (sum < (int32_t)0xff800000)
 				sum = (int32_t)0xff800000;
-			*(int32_t *)dst = sum;
+			*(int32_t*)dst = sum;
 			dst += dst_stride;
 			src += src_stride;
 		}
@@ -396,7 +398,8 @@
  * Signed 32 bit little endian functions.
  */
 
-static void cras_mix_add_clip_s32_le(int32_t *dst, const int32_t *src,
+static void cras_mix_add_clip_s32_le(int32_t *dst,
+				     const int32_t *src,
 				     size_t count)
 {
 	int64_t sum;
@@ -414,8 +417,10 @@
 
 /* Adds src into dst, after scaling by vol.
  * Just hard limits to the min and max S32 value, can be improved later. */
-static void scale_add_clip_s32_le(int32_t *dst, const int32_t *src,
-				  size_t count, float vol)
+static void scale_add_clip_s32_le(int32_t *dst,
+				  const int32_t *src,
+				  size_t count,
+				  float vol)
 {
 	int64_t sum;
 	size_t i;
@@ -435,7 +440,9 @@
 
 /* Adds the first stream to the mix.  Don't need to mix, just setup to the new
  * values. If volume is 1.0, just memcpy. */
-static void copy_scaled_s32_le(int32_t *dst, const int32_t *src, size_t count,
+static void copy_scaled_s32_le(int32_t *dst,
+			       const int32_t *src,
+			       size_t count,
 			       float volume_scaler)
 {
 	int i;
@@ -450,12 +457,14 @@
 }
 
 static void cras_scale_buffer_inc_s32_le(uint8_t *buffer, unsigned int count,
-					 float scaler, float increment,
-					 float target, int step)
+					 float scaler, float increment, int step)
 {
 	int i = 0, j;
 	int32_t *out = (int32_t *)buffer;
 
+	if (scaler > MAX_VOLUME_TO_SCALE && increment > 0)
+		return;
+
 	if (scaler < MIN_VOLUME_TO_SCALE && increment < 0) {
 		memset(out, 0, count * sizeof(*out));
 		return;
@@ -463,17 +472,11 @@
 
 	while (i + step <= count) {
 		for (j = 0; j < step; j++) {
-			float applied_scaler = scaler;
-
-			if ((applied_scaler > target && increment > 0) ||
-			    (applied_scaler < target && increment < 0))
-				applied_scaler = target;
-
-			if (applied_scaler > MAX_VOLUME_TO_SCALE) {
-			} else if (applied_scaler < MIN_VOLUME_TO_SCALE) {
+			if (scaler > MAX_VOLUME_TO_SCALE) {
+			} else if (scaler < MIN_VOLUME_TO_SCALE) {
 				out[i] = 0;
 			} else {
-				out[i] *= applied_scaler;
+				out[i] *= scaler;
 			}
 			i++;
 		}
@@ -499,8 +502,9 @@
 		out[i] *= scaler;
 }
 
-static void cras_mix_add_s32_le(uint8_t *dst, uint8_t *src, unsigned int count,
-				unsigned int index, int mute, float mix_vol)
+static void cras_mix_add_s32_le(uint8_t *dst, uint8_t *src,
+				unsigned int count, unsigned int index,
+				int mute, float mix_vol)
 {
 	int32_t *out = (int32_t *)dst;
 	int32_t *in = (int32_t *)src;
@@ -518,42 +522,45 @@
 }
 
 static void cras_mix_add_scale_stride_s32_le(uint8_t *dst, uint8_t *src,
-					     unsigned int dst_stride,
-					     unsigned int src_stride,
-					     unsigned int count, float scaler)
+				unsigned int dst_stride,
+				unsigned int src_stride,
+				unsigned int count,
+				float scaler)
 {
 	unsigned int i;
 
 	/* optimise the loops for vectorization */
 	if (dst_stride == src_stride && dst_stride == 4) {
+
 		for (i = 0; i < count; i++) {
 			int64_t sum;
 			if (need_to_scale(scaler))
 				sum = *(int32_t *)dst +
-				      *(int32_t *)src * scaler;
+						*(int32_t *)src * scaler;
 			else
 				sum = *(int32_t *)dst + *(int32_t *)src;
 			if (sum > INT32_MAX)
 				sum = INT32_MAX;
 			else if (sum < INT32_MIN)
 				sum = INT32_MIN;
-			*(int32_t *)dst = sum;
+			*(int32_t*)dst = sum;
 			dst += 4;
 			src += 4;
 		}
 	} else {
+
 		for (i = 0; i < count; i++) {
 			int64_t sum;
 			if (need_to_scale(scaler))
 				sum = *(int32_t *)dst +
-				      *(int32_t *)src * scaler;
+						*(int32_t *)src * scaler;
 			else
 				sum = *(int32_t *)dst + *(int32_t *)src;
 			if (sum > INT32_MAX)
 				sum = INT32_MAX;
 			else if (sum < INT32_MIN)
 				sum = INT32_MIN;
-			*(int32_t *)dst = sum;
+			*(int32_t*)dst = sum;
 			dst += dst_stride;
 			src += src_stride;
 		}
@@ -579,7 +586,8 @@
 	memcpy(dst, (uint8_t *)src + 1, 3);
 }
 
-static void cras_mix_add_clip_s24_3le(uint8_t *dst, const uint8_t *src,
+static void cras_mix_add_clip_s24_3le(uint8_t *dst,
+				      const uint8_t *src,
 				      size_t count)
 {
 	int64_t sum;
@@ -602,8 +610,10 @@
 
 /* Adds src into dst, after scaling by vol.
  * Just hard limits to the min and max S24 value, can be improved later. */
-static void scale_add_clip_s24_3le(uint8_t *dst, const uint8_t *src,
-				   size_t count, float vol)
+static void scale_add_clip_s24_3le(uint8_t *dst,
+				   const uint8_t *src,
+				   size_t count,
+				   float vol)
 {
 	int64_t sum;
 	int32_t dst_frame;
@@ -628,8 +638,10 @@
 
 /* Adds the first stream to the mix.  Don't need to mix, just setup to the new
  * values. If volume is 1.0, just memcpy. */
-static void copy_scaled_s24_3le(uint8_t *dst, const uint8_t *src, size_t count,
-				float volume_scaler)
+static void copy_scaled_s24_3le(uint8_t *dst,
+			        const uint8_t *src,
+			        size_t count,
+			        float volume_scaler)
 {
 	int32_t frame;
 	size_t i;
@@ -647,12 +659,14 @@
 }
 
 static void cras_scale_buffer_inc_s24_3le(uint8_t *buffer, unsigned int count,
-					  float scaler, float increment,
-					  float target, int step)
+					  float scaler, float increment, int step)
 {
 	int32_t frame;
 	int i = 0, j;
 
+	if (scaler > MAX_VOLUME_TO_SCALE && increment > 0)
+		return;
+
 	if (scaler < MIN_VOLUME_TO_SCALE && increment < 0) {
 		memset(buffer, 0, 3 * count * sizeof(*buffer));
 		return;
@@ -660,19 +674,13 @@
 
 	while (i + step <= count) {
 		for (j = 0; j < step; j++) {
-			float applied_scaler = scaler;
-
-			if ((applied_scaler > target && increment > 0) ||
-			    (applied_scaler < target && increment < 0))
-				applied_scaler = target;
-
 			convert_single_s243le_to_s32le(&frame, buffer);
 
-			if (applied_scaler > MAX_VOLUME_TO_SCALE) {
-			} else if (applied_scaler < MIN_VOLUME_TO_SCALE) {
+			if (scaler > MAX_VOLUME_TO_SCALE) {
+			} else if (scaler < MIN_VOLUME_TO_SCALE) {
 				frame = 0;
 			} else {
-				frame *= applied_scaler;
+				frame *= scaler;
 			}
 
 			convert_single_s32le_to_s243le(buffer, &frame);
@@ -705,8 +713,9 @@
 	}
 }
 
-static void cras_mix_add_s24_3le(uint8_t *dst, uint8_t *src, unsigned int count,
-				 unsigned int index, int mute, float mix_vol)
+static void cras_mix_add_s24_3le(uint8_t *dst, uint8_t *src,
+				 unsigned int count, unsigned int index,
+				 int mute, float mix_vol)
 {
 	uint8_t *out = dst;
 	uint8_t *in = src;
@@ -724,9 +733,10 @@
 }
 
 static void cras_mix_add_scale_stride_s24_3le(uint8_t *dst, uint8_t *src,
-					      unsigned int dst_stride,
-					      unsigned int src_stride,
-					      unsigned int count, float scaler)
+				 unsigned int dst_stride,
+				 unsigned int src_stride,
+				 unsigned int count,
+				 float scaler)
 {
 	unsigned int i;
 	int64_t sum;
@@ -753,28 +763,28 @@
 
 static void scale_buffer_increment(snd_pcm_format_t fmt, uint8_t *buff,
 				   unsigned int count, float scaler,
-				   float increment, float target, int step)
+				   float increment, int step)
 {
 	switch (fmt) {
 	case SND_PCM_FORMAT_S16_LE:
 		return cras_scale_buffer_inc_s16_le(buff, count, scaler,
-						    increment, target, step);
+						    increment, step);
 	case SND_PCM_FORMAT_S24_LE:
 		return cras_scale_buffer_inc_s24_le(buff, count, scaler,
-						    increment, target, step);
+						    increment, step);
 	case SND_PCM_FORMAT_S32_LE:
 		return cras_scale_buffer_inc_s32_le(buff, count, scaler,
-						    increment, target, step);
+						    increment, step);
 	case SND_PCM_FORMAT_S24_3LE:
 		return cras_scale_buffer_inc_s24_3le(buff, count, scaler,
-						     increment, target, step);
+						     increment, step);
 	default:
 		break;
 	}
 }
 
-static void scale_buffer(snd_pcm_format_t fmt, uint8_t *buff,
-			 unsigned int count, float scaler)
+static void scale_buffer(snd_pcm_format_t fmt, uint8_t *buff, unsigned int count,
+		       float scaler)
 {
 	switch (fmt) {
 	case SND_PCM_FORMAT_S16_LE:
@@ -791,8 +801,8 @@
 }
 
 static void mix_add(snd_pcm_format_t fmt, uint8_t *dst, uint8_t *src,
-		    unsigned int count, unsigned int index, int mute,
-		    float mix_vol)
+		  unsigned int count, unsigned int index,
+		  int mute, float mix_vol)
 {
 	switch (fmt) {
 	case SND_PCM_FORMAT_S16_LE:
@@ -813,29 +823,31 @@
 }
 
 static void 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)
+			uint8_t *src, unsigned int count,
+			unsigned int dst_stride, unsigned int src_stride,
+			float scaler)
 {
 	switch (fmt) {
 	case SND_PCM_FORMAT_S16_LE:
-		return cras_mix_add_scale_stride_s16_le(
-			dst, src, dst_stride, src_stride, count, scaler);
+		return cras_mix_add_scale_stride_s16_le(dst, src, dst_stride,
+						  src_stride, count, scaler);
 	case SND_PCM_FORMAT_S24_LE:
-		return cras_mix_add_scale_stride_s24_le(
-			dst, src, dst_stride, src_stride, count, scaler);
+		return cras_mix_add_scale_stride_s24_le(dst, src, dst_stride,
+						  src_stride, count, scaler);
 	case SND_PCM_FORMAT_S32_LE:
-		return cras_mix_add_scale_stride_s32_le(
-			dst, src, dst_stride, src_stride, count, scaler);
+		return cras_mix_add_scale_stride_s32_le(dst, src, dst_stride,
+						  src_stride, count, scaler);
 	case SND_PCM_FORMAT_S24_3LE:
-		return cras_mix_add_scale_stride_s24_3le(
-			dst, src, dst_stride, src_stride, count, scaler);
+		return cras_mix_add_scale_stride_s24_3le(dst, src, dst_stride,
+						   src_stride, count, scaler);
 	default:
 		break;
 	}
 }
 
-static size_t mix_mute_buffer(uint8_t *dst, size_t frame_bytes, size_t count)
+static size_t mix_mute_buffer(uint8_t *dst,
+			    size_t frame_bytes,
+			    size_t count)
 {
 	memset(dst, 0, count * frame_bytes);
 	return count;
diff --git a/cras/src/server/cras_mix_ops.h b/cras/src/server/cras_mix_ops.h
index 1fac6f3..8246a07 100644
--- a/cras/src/server/cras_mix_ops.h
+++ b/cras/src/server/cras_mix_ops.h
@@ -32,16 +32,18 @@
 struct cras_mix_ops {
 	void (*scale_buffer_increment)(snd_pcm_format_t fmt, uint8_t *buff,
 				       unsigned int count, float scaler,
-				       float increment, float target, int step);
+				       float increment, int step);
 	void (*scale_buffer)(snd_pcm_format_t fmt, uint8_t *buff,
-			     unsigned int count, float scaler);
+			unsigned int count, float scaler);
 	void (*add)(snd_pcm_format_t fmt, uint8_t *dst, uint8_t *src,
-		    unsigned int count, unsigned int index, int mute,
-		    float mix_vol);
+		  unsigned int count, unsigned int index,
+		  int mute, float mix_vol);
 	void (*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);
-	size_t (*mute_buffer)(uint8_t *dst, size_t frame_bytes, size_t count);
+			uint8_t *src, unsigned int count,
+			unsigned int dst_stride, unsigned int src_stride,
+			float scaler);
+	size_t (*mute_buffer)(uint8_t *dst,
+			    size_t frame_bytes,
+			    size_t count);
 };
 #endif
diff --git a/cras/src/server/cras_non_empty_audio_handler.c b/cras/src/server/cras_non_empty_audio_handler.c
index 313149f..9482453 100644
--- a/cras/src/server/cras_non_empty_audio_handler.c
+++ b/cras/src/server/cras_non_empty_audio_handler.c
@@ -46,11 +46,10 @@
 					   void *arg)
 {
 	struct non_empty_audio_msg *audio_msg =
-		(struct non_empty_audio_msg *)msg;
+			(struct non_empty_audio_msg *)msg;
 
 	cras_system_state_set_non_empty_status(audio_msg->non_empty);
-	cras_observer_notify_non_empty_audio_state_changed(
-		audio_msg->non_empty);
+	cras_observer_notify_non_empty_audio_state_changed(audio_msg->non_empty);
 }
 
 int cras_non_empty_audio_handler_init()
diff --git a/cras/src/server/cras_observer.c b/cras/src/server/cras_observer.c
index 0f6ab96..caff00d 100644
--- a/cras/src/server/cras_observer.c
+++ b/cras/src/server/cras_observer.c
@@ -100,10 +100,11 @@
 	struct cras_observer_alert_data_volume *volume_data =
 		(struct cras_observer_alert_data_volume *)data;
 
-	DL_FOREACH (g_observer->clients, client) {
+	DL_FOREACH(g_observer->clients, client) {
 		if (client->ops.output_volume_changed)
-			client->ops.output_volume_changed(client->context,
-							  volume_data->volume);
+			client->ops.output_volume_changed(
+					client->context,
+					volume_data->volume);
 	}
 }
 
@@ -113,12 +114,13 @@
 	struct cras_observer_alert_data_mute *mute_data =
 		(struct cras_observer_alert_data_mute *)data;
 
-	DL_FOREACH (g_observer->clients, client) {
+	DL_FOREACH(g_observer->clients, client) {
 		if (client->ops.output_mute_changed)
-			client->ops.output_mute_changed(client->context,
-							mute_data->muted,
-							mute_data->user_muted,
-							mute_data->mute_locked);
+			client->ops.output_mute_changed(
+					client->context,
+					mute_data->muted,
+					mute_data->user_muted,
+					mute_data->mute_locked);
 	}
 }
 
@@ -128,10 +130,11 @@
 	struct cras_observer_alert_data_volume *volume_data =
 		(struct cras_observer_alert_data_volume *)data;
 
-	DL_FOREACH (g_observer->clients, client) {
+	DL_FOREACH(g_observer->clients, client) {
 		if (client->ops.capture_gain_changed)
-			client->ops.capture_gain_changed(client->context,
-							 volume_data->volume);
+			client->ops.capture_gain_changed(
+					client->context,
+					volume_data->volume);
 	}
 }
 
@@ -141,11 +144,12 @@
 	struct cras_observer_alert_data_mute *mute_data =
 		(struct cras_observer_alert_data_mute *)data;
 
-	DL_FOREACH (g_observer->clients, client) {
+	DL_FOREACH(g_observer->clients, client) {
 		if (client->ops.capture_mute_changed)
 			client->ops.capture_mute_changed(
-				client->context, mute_data->muted,
-				mute_data->mute_locked);
+					client->context,
+					mute_data->muted,
+					mute_data->mute_locked);
 	}
 }
 
@@ -158,7 +162,7 @@
 {
 	struct cras_observer_client *client;
 
-	DL_FOREACH (g_observer->clients, client) {
+	DL_FOREACH(g_observer->clients, client) {
 		if (client->ops.nodes_changed)
 			client->ops.nodes_changed(client->context);
 	}
@@ -170,11 +174,12 @@
 	struct cras_observer_alert_data_active_node *node_data =
 		(struct cras_observer_alert_data_active_node *)data;
 
-	DL_FOREACH (g_observer->clients, client) {
+	DL_FOREACH(g_observer->clients, client) {
 		if (client->ops.active_node_changed)
-			client->ops.active_node_changed(client->context,
-							node_data->direction,
-							node_data->node_id);
+			client->ops.active_node_changed(
+					client->context,
+					node_data->direction,
+					node_data->node_id);
 	}
 }
 
@@ -184,11 +189,12 @@
 	struct cras_observer_alert_data_node_volume *node_data =
 		(struct cras_observer_alert_data_node_volume *)data;
 
-	DL_FOREACH (g_observer->clients, client) {
+	DL_FOREACH(g_observer->clients, client) {
 		if (client->ops.output_node_volume_changed)
 			client->ops.output_node_volume_changed(
-				client->context, node_data->node_id,
-				node_data->volume);
+					client->context,
+					node_data->node_id,
+					node_data->volume);
 	}
 }
 
@@ -198,11 +204,12 @@
 	struct cras_observer_alert_data_node_lr_swapped *node_data =
 		(struct cras_observer_alert_data_node_lr_swapped *)data;
 
-	DL_FOREACH (g_observer->clients, client) {
+	DL_FOREACH(g_observer->clients, client) {
 		if (client->ops.node_left_right_swapped_changed)
 			client->ops.node_left_right_swapped_changed(
-				client->context, node_data->node_id,
-				node_data->swapped);
+					client->context,
+					node_data->node_id,
+					node_data->swapped);
 	}
 }
 
@@ -212,11 +219,12 @@
 	struct cras_observer_alert_data_node_volume *node_data =
 		(struct cras_observer_alert_data_node_volume *)data;
 
-	DL_FOREACH (g_observer->clients, client) {
+	DL_FOREACH(g_observer->clients, client) {
 		if (client->ops.input_node_gain_changed)
-			client->ops.input_node_gain_changed(client->context,
-							    node_data->node_id,
-							    node_data->volume);
+			client->ops.input_node_gain_changed(
+					client->context,
+					node_data->node_id,
+					node_data->volume);
 	}
 }
 
@@ -226,10 +234,11 @@
 	struct cras_observer_alert_data_suspend *suspend_data =
 		(struct cras_observer_alert_data_suspend *)data;
 
-	DL_FOREACH (g_observer->clients, client) {
+	DL_FOREACH(g_observer->clients, client) {
 		if (client->ops.suspend_changed)
-			client->ops.suspend_changed(client->context,
-						    suspend_data->suspended);
+			client->ops.suspend_changed(
+					client->context,
+					suspend_data->suspended);
 	}
 }
 
@@ -239,11 +248,12 @@
 	struct cras_observer_alert_data_streams *streams_data =
 		(struct cras_observer_alert_data_streams *)data;
 
-	DL_FOREACH (g_observer->clients, client) {
+	DL_FOREACH(g_observer->clients, client) {
 		if (client->ops.num_active_streams_changed)
 			client->ops.num_active_streams_changed(
-				client->context, streams_data->direction,
-				streams_data->num_active_streams);
+					client->context,
+					streams_data->direction,
+					streams_data->num_active_streams);
 	}
 }
 
@@ -253,11 +263,12 @@
 	struct cras_observer_alert_data_hotword_triggered *triggered_data =
 		(struct cras_observer_alert_data_hotword_triggered *)data;
 
-	DL_FOREACH (g_observer->clients, client) {
+	DL_FOREACH(g_observer->clients, client) {
 		if (client->ops.hotword_triggered)
-			client->ops.hotword_triggered(client->context,
-						      triggered_data->tv_sec,
-						      triggered_data->tv_nsec);
+			client->ops.hotword_triggered(
+					client->context,
+					triggered_data->tv_sec,
+					triggered_data->tv_nsec);
 	}
 }
 
@@ -265,13 +276,13 @@
 {
 	struct cras_observer_client *client;
 	struct cras_observer_non_empty_audio_state *non_empty_audio_data =
-		(struct cras_observer_non_empty_audio_state *)data;
+			(struct cras_observer_non_empty_audio_state *)data;
 
-	DL_FOREACH (g_observer->clients, client) {
+	DL_FOREACH(g_observer->clients, client) {
 		if (client->ops.non_empty_audio_state_changed) {
 			client->ops.non_empty_audio_state_changed(
-				client->context,
-				non_empty_audio_data->non_empty);
+					client->context,
+					non_empty_audio_data->non_empty);
 		}
 	}
 }
@@ -287,23 +298,23 @@
 	return cras_alert_add_callback(*alert, cb, NULL);
 }
 
-#define CRAS_OBSERVER_SET_ALERT(alert, prepare, flags)                         \
-	do {                                                                   \
-		rc = cras_observer_server_set_alert(&g_observer->alerts.alert, \
-						    alert##_alert, prepare,    \
-						    flags);                    \
-		if (rc)                                                        \
-			goto error;                                            \
-	} while (0)
+#define CRAS_OBSERVER_SET_ALERT(alert,prepare,flags) \
+	do { \
+		rc = cras_observer_server_set_alert( \
+			&g_observer->alerts.alert, alert##_alert, \
+			prepare, flags); \
+		if (rc) \
+			goto error; \
+	} while(0)
 
-#define CRAS_OBSERVER_SET_ALERT_WITH_DIRECTION(alert, direction)               \
-	do {                                                                   \
-		rc = cras_observer_server_set_alert(                           \
-			&g_observer->alerts.alert[direction], alert##_alert,   \
-			NULL, 0);                                              \
-		if (rc)                                                        \
-			goto error;                                            \
-	} while (0)
+#define CRAS_OBSERVER_SET_ALERT_WITH_DIRECTION(alert,direction) \
+	do { \
+		rc = cras_observer_server_set_alert( \
+			&g_observer->alerts.alert[direction], \
+			alert##_alert, NULL, 0); \
+		if (rc) \
+			goto error; \
+	} while(0)
 
 /*
  * Public interface
@@ -314,8 +325,8 @@
 	int rc;
 
 	memset(&g_empty_ops, 0, sizeof(g_empty_ops));
-	g_observer = (struct cras_observer_server *)calloc(
-		1, sizeof(struct cras_observer_server));
+	g_observer = (struct cras_observer_server *)
+			calloc(1, sizeof(struct cras_observer_server));
 	if (!g_observer)
 		return -ENOMEM;
 
@@ -333,12 +344,12 @@
 	CRAS_OBSERVER_SET_ALERT(hotword_triggered, NULL, 0);
 	CRAS_OBSERVER_SET_ALERT(non_empty_audio_state_changed, NULL, 0);
 
-	CRAS_OBSERVER_SET_ALERT_WITH_DIRECTION(num_active_streams,
-					       CRAS_STREAM_OUTPUT);
-	CRAS_OBSERVER_SET_ALERT_WITH_DIRECTION(num_active_streams,
-					       CRAS_STREAM_INPUT);
-	CRAS_OBSERVER_SET_ALERT_WITH_DIRECTION(num_active_streams,
-					       CRAS_STREAM_POST_MIX_PRE_DSP);
+	CRAS_OBSERVER_SET_ALERT_WITH_DIRECTION(
+		num_active_streams, CRAS_STREAM_OUTPUT);
+	CRAS_OBSERVER_SET_ALERT_WITH_DIRECTION(
+		num_active_streams, CRAS_STREAM_INPUT);
+	CRAS_OBSERVER_SET_ALERT_WITH_DIRECTION(
+		num_active_streams, CRAS_STREAM_POST_MIX_PRE_DSP);
 
 	return 0;
 
@@ -363,13 +374,12 @@
 	cras_alert_destroy(g_observer->alerts.suspend_changed);
 	cras_alert_destroy(g_observer->alerts.hotword_triggered);
 	cras_alert_destroy(g_observer->alerts.non_empty_audio_state_changed);
-	cras_alert_destroy(
-		g_observer->alerts.num_active_streams[CRAS_STREAM_OUTPUT]);
-	cras_alert_destroy(
-		g_observer->alerts.num_active_streams[CRAS_STREAM_INPUT]);
-	cras_alert_destroy(
-		g_observer->alerts
-			.num_active_streams[CRAS_STREAM_POST_MIX_PRE_DSP]);
+	cras_alert_destroy(g_observer->alerts.num_active_streams[
+							CRAS_STREAM_OUTPUT]);
+	cras_alert_destroy(g_observer->alerts.num_active_streams[
+							CRAS_STREAM_INPUT]);
+	cras_alert_destroy(g_observer->alerts.num_active_streams[
+						CRAS_STREAM_POST_MIX_PRE_DSP]);
 	free(g_observer);
 	g_observer = NULL;
 }
@@ -401,8 +411,9 @@
 		memcpy(&client->ops, ops, sizeof(client->ops));
 }
 
-struct cras_observer_client *
-cras_observer_add(const struct cras_observer_ops *ops, void *context)
+struct cras_observer_client *cras_observer_add(
+			const struct cras_observer_ops *ops,
+			void *context)
 {
 	struct cras_observer_client *client;
 
@@ -432,8 +443,8 @@
 	struct cras_observer_alert_data_volume data;
 
 	data.volume = volume;
-	cras_alert_pending_data(g_observer->alerts.output_volume, &data,
-				sizeof(data));
+	cras_alert_pending_data(g_observer->alerts.output_volume,
+				&data, sizeof(data));
 }
 
 void cras_observer_notify_output_mute(int muted, int user_muted,
@@ -444,8 +455,8 @@
 	data.muted = muted;
 	data.user_muted = user_muted;
 	data.mute_locked = mute_locked;
-	cras_alert_pending_data(g_observer->alerts.output_mute, &data,
-				sizeof(data));
+	cras_alert_pending_data(g_observer->alerts.output_mute,
+				&data, sizeof(data));
 }
 
 void cras_observer_notify_capture_gain(int32_t gain)
@@ -453,8 +464,8 @@
 	struct cras_observer_alert_data_volume data;
 
 	data.volume = gain;
-	cras_alert_pending_data(g_observer->alerts.capture_gain, &data,
-				sizeof(data));
+	cras_alert_pending_data(g_observer->alerts.capture_gain,
+				&data, sizeof(data));
 }
 
 void cras_observer_notify_capture_mute(int muted, int mute_locked)
@@ -464,8 +475,8 @@
 	data.muted = muted;
 	data.user_muted = 0;
 	data.mute_locked = mute_locked;
-	cras_alert_pending_data(g_observer->alerts.capture_mute, &data,
-				sizeof(data));
+	cras_alert_pending_data(g_observer->alerts.capture_mute,
+				&data, sizeof(data));
 }
 
 void cras_observer_notify_nodes(void)
@@ -480,8 +491,8 @@
 
 	data.direction = dir;
 	data.node_id = node_id;
-	cras_alert_pending_data(g_observer->alerts.active_node, &data,
-				sizeof(data));
+	cras_alert_pending_data(g_observer->alerts.active_node,
+				&data, sizeof(data));
 }
 
 void cras_observer_notify_output_node_volume(cras_node_id_t node_id,
@@ -491,8 +502,8 @@
 
 	data.node_id = node_id;
 	data.volume = volume;
-	cras_alert_pending_data(g_observer->alerts.output_node_volume, &data,
-				sizeof(data));
+	cras_alert_pending_data(g_observer->alerts.output_node_volume,
+				&data, sizeof(data));
 }
 
 void cras_observer_notify_node_left_right_swapped(cras_node_id_t node_id,
@@ -506,14 +517,15 @@
 				&data, sizeof(data));
 }
 
-void cras_observer_notify_input_node_gain(cras_node_id_t node_id, int32_t gain)
+void cras_observer_notify_input_node_gain(cras_node_id_t node_id,
+					  int32_t gain)
 {
 	struct cras_observer_alert_data_node_volume data;
 
 	data.node_id = node_id;
 	data.volume = gain;
-	cras_alert_pending_data(g_observer->alerts.input_node_gain, &data,
-				sizeof(data));
+	cras_alert_pending_data(g_observer->alerts.input_node_gain,
+				&data, sizeof(data));
 }
 
 void cras_observer_notify_suspend_changed(int suspended)
@@ -521,8 +533,8 @@
 	struct cras_observer_alert_data_suspend data;
 
 	data.suspended = suspended;
-	cras_alert_pending_data(g_observer->alerts.suspend_changed, &data,
-				sizeof(data));
+	cras_alert_pending_data(g_observer->alerts.suspend_changed,
+				&data, sizeof(data));
 }
 
 void cras_observer_notify_num_active_streams(enum CRAS_STREAM_DIRECTION dir,
@@ -546,8 +558,8 @@
 
 	data.tv_sec = tv_sec;
 	data.tv_nsec = tv_nsec;
-	cras_alert_pending_data(g_observer->alerts.hotword_triggered, &data,
-				sizeof(data));
+	cras_alert_pending_data(g_observer->alerts.hotword_triggered,
+				&data, sizeof(data));
 }
 
 void cras_observer_notify_non_empty_audio_state_changed(int non_empty)
@@ -556,7 +568,6 @@
 
 	data.non_empty = non_empty;
 
-	cras_alert_pending_data(
-		g_observer->alerts.non_empty_audio_state_changed, &data,
-		sizeof(data));
+	cras_alert_pending_data(g_observer->alerts.non_empty_audio_state_changed,
+				&data, sizeof(data));
 }
\ No newline at end of file
diff --git a/cras/src/server/cras_observer.h b/cras/src/server/cras_observer.h
index 109bd60..440a8ce 100644
--- a/cras/src/server/cras_observer.h
+++ b/cras/src/server/cras_observer.h
@@ -19,8 +19,9 @@
  *    Valid pointer to the client reference, or NULL on memory allocation
  *    error.
  */
-struct cras_observer_client *
-cras_observer_add(const struct cras_observer_ops *ops, void *context);
+struct cras_observer_client *cras_observer_add(
+			const struct cras_observer_ops *ops,
+			void *context);
 
 /* Retrieve the observed state changes.
  * Args:
@@ -83,7 +84,8 @@
 						  int swapped);
 
 /* Notify observers of input node gain change. */
-void cras_observer_notify_input_node_gain(cras_node_id_t node_id, int32_t gain);
+void cras_observer_notify_input_node_gain(cras_node_id_t node_id,
+					  int32_t gain);
 
 /* Notify observers of suspend state changed. */
 void cras_observer_notify_suspend_changed(int suspended);
diff --git a/cras/src/server/cras_playback_rclient.c b/cras/src/server/cras_playback_rclient.c
deleted file mode 100644
index a282e8b..0000000
--- a/cras/src/server/cras_playback_rclient.c
+++ /dev/null
@@ -1,103 +0,0 @@
-/* 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
deleted file mode 100644
index 37f03cf..0000000
--- a/cras/src/server/cras_playback_rclient.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/* 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_ramp.c b/cras/src/server/cras_ramp.c
index 5f40a77..e83dc51 100644
--- a/cras/src/server/cras_ramp.c
+++ b/cras/src/server/cras_ramp.c
@@ -7,6 +7,19 @@
 
 #include "cras_ramp.h"
 
+
+/*
+ * State of cras_ramp:
+ *   CRAS_RAMP_STATE_IDLE: No ramping is started, or a ramping is already done.
+ *   CRAS_RAMP_STATE_UP: Ramping up from 0 to 1.
+ *   CRAS_RAMP_STATE_DOWN: Ramping down from certain scaler to 0.
+ */
+enum CRAS_RAMP_STATE {
+	CRAS_RAMP_STATE_IDLE,
+	CRAS_RAMP_STATE_UP,
+	CRAS_RAMP_STATE_DOWN,
+};
+
 /*
  * Struct to hold ramping information.
  * Members:
@@ -20,25 +33,24 @@
  *   cb_data: Data passed to cb.
  */
 struct cras_ramp {
-	int active;
+	enum CRAS_RAMP_STATE state;
 	int ramped_frames;
 	int duration_frames;
 	float increment;
 	float start_scaler;
-	float target;
 	void (*cb)(void *data);
 	void *cb_data;
 };
 
-void cras_ramp_destroy(struct cras_ramp *ramp)
+void cras_ramp_destroy(struct cras_ramp* ramp)
 {
 	free(ramp);
 }
 
-struct cras_ramp *cras_ramp_create()
+struct cras_ramp* cras_ramp_create()
 {
-	struct cras_ramp *ramp;
-	ramp = (struct cras_ramp *)malloc(sizeof(*ramp));
+	struct cras_ramp* ramp;
+	ramp = (struct cras_ramp*)malloc(sizeof(*ramp));
 	if (ramp == NULL) {
 		return NULL;
 	}
@@ -46,46 +58,43 @@
 	return ramp;
 }
 
-int cras_ramp_reset(struct cras_ramp *ramp)
-{
-	ramp->active = 0;
+int cras_ramp_reset(struct cras_ramp *ramp) {
+	ramp->state = CRAS_RAMP_STATE_IDLE;
 	ramp->ramped_frames = 0;
 	ramp->duration_frames = 0;
 	ramp->increment = 0;
 	ramp->start_scaler = 1.0;
-	ramp->target = 1.0;
 	return 0;
 }
 
-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 is_up, int duration_frames,
+		    cras_ramp_cb cb, void *cb_data)
 {
 	struct cras_ramp_action action;
 
-	if (from == to)
-		return 0;
-
 	/* Get current scaler position so it can serve as new start scaler. */
 	action = cras_ramp_get_current_action(ramp);
 	if (action.type == CRAS_RAMP_ACTION_INVALID)
 		return -EINVAL;
 
-	/* Set initial scaler to current scaler so ramping up/down can be
+        /* Set initial scaler to current scaler so ramping up/down can be
          * smoothly switched. */
-	ramp->active = 1;
-	if (action.type == CRAS_RAMP_ACTION_NONE) {
-		ramp->start_scaler = from;
+	if (is_up) {
+		ramp->state = CRAS_RAMP_STATE_UP;
+		if (action.type == CRAS_RAMP_ACTION_NONE)
+			ramp->start_scaler = 0;
+		else
+			ramp->start_scaler = action.scaler;
+		ramp->increment = (1 - ramp->start_scaler) / duration_frames;
 	} else {
-		/* If this a mute ramp, we want to match the previous multiplier
-		 * so that there is not a jump in the audio. Otherwise, we are
-		 * applying a volume ramp so we need to multiply |from| by the
-		 * previous scaler so that we can stack volume ramps. */
-		ramp->start_scaler = action.scaler;
-		if (!mute_ramp)
-			ramp->start_scaler *= from;
+		ramp->state = CRAS_RAMP_STATE_DOWN;
+		if (action.type == CRAS_RAMP_ACTION_NONE)
+			ramp->start_scaler = 1;
+		else
+			ramp->start_scaler = action.scaler;
+
+		ramp->increment = -ramp->start_scaler / duration_frames;
 	}
-	ramp->increment = (to - ramp->start_scaler) / duration_frames;
-	ramp->target = to;
 	ramp->ramped_frames = 0;
 	ramp->duration_frames = duration_frames;
 	ramp->cb = cb;
@@ -93,8 +102,7 @@
 	return 0;
 }
 
-struct cras_ramp_action
-cras_ramp_get_current_action(const struct cras_ramp *ramp)
+struct cras_ramp_action cras_ramp_get_current_action(const struct cras_ramp *ramp)
 {
 	struct cras_ramp_action action;
 
@@ -102,29 +110,39 @@
 		action.type = CRAS_RAMP_ACTION_INVALID;
 		action.scaler = 1.0;
 		action.increment = 0.0;
-		action.target = 1.0;
-	} else if (ramp->active) {
+		return action;
+	}
+
+	switch (ramp->state) {
+	case CRAS_RAMP_STATE_IDLE:
+		action.type = CRAS_RAMP_ACTION_NONE;
+		action.scaler = 1.0;
+		action.increment = 0.0;
+		break;
+	case CRAS_RAMP_STATE_DOWN:
 		action.type = CRAS_RAMP_ACTION_PARTIAL;
 		action.scaler = ramp->start_scaler +
 				ramp->ramped_frames * ramp->increment;
 		action.increment = ramp->increment;
-		action.target = ramp->target;
-	} else {
-		action.type = CRAS_RAMP_ACTION_NONE;
-		action.scaler = 1.0;
-		action.increment = 0.0;
-		action.target = 1.0;
+		break;
+	case CRAS_RAMP_STATE_UP:
+		action.type = CRAS_RAMP_ACTION_PARTIAL;
+		action.scaler = ramp->start_scaler +
+				ramp->ramped_frames * ramp->increment;
+		action.increment = ramp->increment;
+		break;
 	}
 	return action;
 }
 
-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)
 {
-	if (!ramp->active)
+	if (ramp->state == CRAS_RAMP_STATE_IDLE)
 		return -EINVAL;
 	ramp->ramped_frames += num_frames;
 	if (ramp->ramped_frames >= ramp->duration_frames) {
-		ramp->active = 0;
+		ramp->state = CRAS_RAMP_STATE_IDLE;
 		if (ramp->cb)
 			ramp->cb(ramp->cb_data);
 	}
diff --git a/cras/src/server/cras_ramp.h b/cras/src/server/cras_ramp.h
index 077e9be..5b1acfb 100644
--- a/cras/src/server/cras_ramp.h
+++ b/cras/src/server/cras_ramp.h
@@ -35,23 +35,20 @@
 	enum CRAS_RAMP_ACTION_TYPE type;
 	float scaler;
 	float increment;
-	float target;
 };
 
 typedef void (*cras_ramp_cb)(void *arg);
 
 /* Creates a ramp. */
-struct cras_ramp *cras_ramp_create();
+struct cras_ramp* cras_ramp_create();
 
 /* Destroys a ramp. */
-void cras_ramp_destroy(struct cras_ramp *ramp);
+void cras_ramp_destroy(struct cras_ramp* ramp);
 
-/* Ramps the scaler between from and to for duration_frames frames.
+/* Starts ramping up from 0 to 1 or from 1 to 0 for duration_frames frames.
  * Args:
  *   ramp[in]: The ramp struct to start.
- *   mute_ramp[in]: Is this ramp a mute->unmute or unmute->mute ramp.
- *   from[in]: The scaler value to ramp from.
- *   to[in]: The scaler value to ramp to.
+ *   is_up[in]: 1 to ramp up and 0 to ramp down.
  *   duration_frames[in]: Ramp duration in frames.
  *   cb[in]: The callback function to call after ramping is done. User can set
  *           cb to turn off speaker/headphone switch after ramping down
@@ -60,32 +57,18 @@
  * Returns:
  *   0 on success; negative error code on failure.
  */
-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);
-
-/* Convenience wrappers for cras_ramp_start */
-static inline int cras_mute_ramp_start(struct cras_ramp *ramp, float from,
-				       float to, int duration_frames,
-				       cras_ramp_cb cb, void *cb_data)
-{
-	return cras_ramp_start(ramp, 1, from, to, duration_frames, cb, cb_data);
-}
-
-static inline int cras_volume_ramp_start(struct cras_ramp *ramp, float from,
-					 float to, int duration_frames,
-					 cras_ramp_cb cb, void *cb_data)
-{
-	return cras_ramp_start(ramp, 0, from, to, duration_frames, cb, cb_data);
-}
+int cras_ramp_start(struct cras_ramp *ramp, int is_up, int duration_frames,
+		    cras_ramp_cb cb, void *cb_data);
 
 /* Resets ramp and cancels current ramping. */
 int cras_ramp_reset(struct cras_ramp *ramp);
 
 /* Gets current ramp action. */
-struct cras_ramp_action
-cras_ramp_get_current_action(const struct cras_ramp *ramp);
+struct cras_ramp_action cras_ramp_get_current_action(
+		const struct cras_ramp *ramp);
 
 /* Updates number of samples that went through ramping. */
-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);
 
 #endif /* CRAS_RAMP_H_ */
diff --git a/cras/src/server/cras_rclient.c b/cras/src/server/cras_rclient.c
index 38ba5c2..3131725 100644
--- a/cras/src/server/cras_rclient.c
+++ b/cras/src/server/cras_rclient.c
@@ -9,16 +9,12 @@
 
 #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"
@@ -28,54 +24,666 @@
 #include "stream_list.h"
 #include "utlist.h"
 
+/* An attached client.
+ *  id - The id of the client.
+ *  fd - Connection for client communication.
+ */
+struct cras_rclient {
+	struct cras_observer_client *observer;
+	size_t id;
+	int fd;
+};
+
+/* 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_stream_connected_old stream_connected_old;
+	struct cras_client_message *reply;
+	struct cras_audio_format remote_fmt;
+	struct cras_rstream_config stream_config;
+	int rc;
+	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;
+	rc = stream_list_add(cras_iodev_list_get_stream_list(),
+			     &stream_config, &stream);
+	if (rc) {
+		rc = -ENOMEM;
+		goto reply_err;
+	}
+
+	/* Tell client about the stream setup. */
+	syslog(LOG_DEBUG, "Send connected for stream %x\n", msg->stream_id);
+	if (msg->proto_version == CRAS_PROTO_VER) {
+		cras_fill_client_stream_connected(
+				&stream_connected,
+				0, /* No error. */
+				msg->stream_id,
+				&remote_fmt,
+				cras_rstream_get_total_shm_size(stream),
+				cras_rstream_get_effects(stream));
+		reply = &stream_connected.header;
+	} else {
+		cras_fill_client_stream_connected_old(
+				&stream_connected_old,
+				0, /* No error. */
+				msg->stream_id,
+				&remote_fmt,
+				cras_rstream_get_total_shm_size(stream));
+		reply = &stream_connected_old.header;
+	}
+	stream_fds[0] = cras_rstream_input_shm_fd(stream);
+	stream_fds[1] = cras_rstream_output_shm_fd(stream);
+	rc = cras_rclient_send_message(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. */
+	if (msg->proto_version == CRAS_PROTO_VER) {
+		cras_fill_client_stream_connected(
+				&stream_connected, rc, msg->stream_id,
+				&remote_fmt, 0, msg->effects);
+		reply = &stream_connected.header;
+	} else {
+		cras_fill_client_stream_connected_old(
+				&stream_connected_old, rc, msg->stream_id,
+				&remote_fmt, 0);
+		reply = &stream_connected_old.header;
+	}
+	cras_rclient_send_message(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)
+{
+	struct cras_client_audio_debug_info_ready msg;
+	struct cras_server_state *state;
+
+	cras_fill_client_audio_debug_info_ready(&msg);
+	state = cras_system_state_get_no_lock();
+	audio_thread_dump_thread_info(cras_iodev_list_get_audio_thread(),
+				      &state->audio_debug_info);
+	cras_rclient_send_message(client, &msg.header, NULL, 0);
+}
+
+/* Handles dumping audio snapshots to shared memory for the client. */
+static void dump_audio_thread_snapshots(struct cras_rclient *client)
+{
+	struct cras_client_audio_debug_info_ready msg;
+
+	cras_fill_client_audio_debug_info_ready(&msg);
+	cras_system_state_dump_snapshots();
+	cras_rclient_send_message(client, &msg.header, NULL, 0);
+}
+
+static void handle_get_hotword_models(struct cras_rclient *client,
+				      cras_node_id_t node_id)
+{
+	struct cras_client_get_hotword_models_ready *msg;
+	char *hotword_models;
+	unsigned hotword_models_size;
+	uint8_t buf[CRAS_CLIENT_MAX_MSG_SIZE];
+
+	msg = (struct cras_client_get_hotword_models_ready *)buf;
+	hotword_models = cras_iodev_list_get_hotword_models(node_id);
+	if (!hotword_models)
+		goto empty_reply;
+	hotword_models_size = strlen(hotword_models);
+	if (hotword_models_size + sizeof(*msg) > CRAS_CLIENT_MAX_MSG_SIZE) {
+		free(hotword_models);
+		goto empty_reply;
+	}
+
+	cras_fill_client_get_hotword_models_ready(msg, hotword_models,
+						  hotword_models_size);
+	cras_rclient_send_message(client, &msg->header, NULL, 0);
+	free(hotword_models);
+	return;
+
+empty_reply:
+	cras_fill_client_get_hotword_models_ready(msg, NULL, 0);
+	cras_rclient_send_message(client, &msg->header, NULL, 0);
+}
+
+/* Client notification callback functions. */
+
+static void send_output_volume_changed(void *context, int32_t volume)
+{
+	struct cras_client_volume_changed msg;
+	struct cras_rclient *client = (struct cras_rclient *)context;
+
+	cras_fill_client_output_volume_changed(&msg, volume);
+	cras_rclient_send_message(client, &msg.header, NULL, 0);
+}
+
+static void send_output_mute_changed(void *context, int muted,
+				     int user_muted, int mute_locked)
+{
+	struct cras_client_mute_changed msg;
+	struct cras_rclient *client = (struct cras_rclient *)context;
+
+	cras_fill_client_output_mute_changed(&msg, muted,
+					     user_muted, mute_locked);
+	cras_rclient_send_message(client, &msg.header, NULL, 0);
+}
+
+static void send_capture_gain_changed(void *context, int32_t gain)
+{
+	struct cras_client_volume_changed msg;
+	struct cras_rclient *client = (struct cras_rclient *)context;
+
+	cras_fill_client_capture_gain_changed(&msg, gain);
+	cras_rclient_send_message(client, &msg.header, NULL, 0);
+}
+
+static void send_capture_mute_changed(void *context, int muted, int mute_locked)
+{
+	struct cras_client_mute_changed msg;
+	struct cras_rclient *client = (struct cras_rclient *)context;
+
+	cras_fill_client_capture_mute_changed(&msg, muted, mute_locked);
+	cras_rclient_send_message(client, &msg.header, NULL, 0);
+}
+
+static void send_nodes_changed(void *context)
+{
+	struct cras_client_nodes_changed msg;
+	struct cras_rclient *client = (struct cras_rclient *)context;
+
+	cras_fill_client_nodes_changed(&msg);
+	cras_rclient_send_message(client, &msg.header, NULL, 0);
+}
+
+static void send_active_node_changed(void *context,
+				     enum CRAS_STREAM_DIRECTION dir,
+				     cras_node_id_t node_id)
+{
+	struct cras_client_active_node_changed msg;
+	struct cras_rclient *client = (struct cras_rclient *)context;
+
+	cras_fill_client_active_node_changed(&msg, dir, node_id);
+	cras_rclient_send_message(client, &msg.header, NULL, 0);
+}
+
+static void send_output_node_volume_changed(void *context,
+					    cras_node_id_t node_id,
+					    int32_t volume)
+{
+	struct cras_client_node_value_changed msg;
+	struct cras_rclient *client = (struct cras_rclient *)context;
+
+	cras_fill_client_output_node_volume_changed(&msg, node_id, volume);
+	cras_rclient_send_message(client, &msg.header, NULL, 0);
+}
+
+static void send_node_left_right_swapped_changed(void *context,
+						 cras_node_id_t node_id,
+						 int swapped)
+{
+	struct cras_client_node_value_changed msg;
+	struct cras_rclient *client = (struct cras_rclient *)context;
+
+	cras_fill_client_node_left_right_swapped_changed(
+						&msg, node_id, swapped);
+	cras_rclient_send_message(client, &msg.header, NULL, 0);
+}
+
+static void send_input_node_gain_changed(void *context,
+					 cras_node_id_t node_id,
+					 int32_t gain)
+{
+	struct cras_client_node_value_changed msg;
+	struct cras_rclient *client = (struct cras_rclient *)context;
+
+	cras_fill_client_input_node_gain_changed(&msg, node_id, gain);
+	cras_rclient_send_message(client, &msg.header, NULL, 0);
+}
+
+static void send_num_active_streams_changed(void *context,
+					    enum CRAS_STREAM_DIRECTION dir,
+					    uint32_t num_active_streams)
+{
+	struct cras_client_num_active_streams_changed msg;
+	struct cras_rclient *client = (struct cras_rclient *)context;
+
+	cras_fill_client_num_active_streams_changed(
+					&msg, dir, num_active_streams);
+	cras_rclient_send_message(client, &msg.header, NULL, 0);
+}
+
+static void register_for_notification(struct cras_rclient *client,
+				      enum CRAS_CLIENT_MESSAGE_ID msg_id,
+				      int do_register)
+{
+	struct cras_observer_ops observer_ops;
+	int empty;
+
+	cras_observer_get_ops(client->observer, &observer_ops);
+
+	switch (msg_id) {
+	case CRAS_CLIENT_OUTPUT_VOLUME_CHANGED:
+		observer_ops.output_volume_changed =
+			do_register ? send_output_volume_changed : NULL;
+		break;
+	case CRAS_CLIENT_OUTPUT_MUTE_CHANGED:
+		observer_ops.output_mute_changed =
+			do_register ? send_output_mute_changed : NULL;
+		break;
+	case CRAS_CLIENT_CAPTURE_GAIN_CHANGED:
+		observer_ops.capture_gain_changed =
+			do_register ? send_capture_gain_changed : NULL;
+		break;
+	case CRAS_CLIENT_CAPTURE_MUTE_CHANGED:
+		observer_ops.capture_mute_changed =
+			do_register ? send_capture_mute_changed : NULL;
+		break;
+	case CRAS_CLIENT_NODES_CHANGED:
+		observer_ops.nodes_changed =
+			do_register ? send_nodes_changed : NULL;
+		break;
+	case CRAS_CLIENT_ACTIVE_NODE_CHANGED:
+		observer_ops.active_node_changed =
+			do_register ? send_active_node_changed : NULL;
+		break;
+	case CRAS_CLIENT_OUTPUT_NODE_VOLUME_CHANGED:
+		observer_ops.output_node_volume_changed =
+			do_register ? send_output_node_volume_changed : NULL;
+		break;
+	case CRAS_CLIENT_NODE_LEFT_RIGHT_SWAPPED_CHANGED:
+		observer_ops.node_left_right_swapped_changed =
+		    do_register ? send_node_left_right_swapped_changed : NULL;
+		break;
+	case CRAS_CLIENT_INPUT_NODE_GAIN_CHANGED:
+		observer_ops.input_node_gain_changed =
+			do_register ? send_input_node_gain_changed : NULL;
+		break;
+	case CRAS_CLIENT_NUM_ACTIVE_STREAMS_CHANGED:
+		observer_ops.num_active_streams_changed =
+			do_register ? send_num_active_streams_changed : NULL;
+		break;
+	default:
+		syslog(LOG_ERR,
+		       "Invalid client notification message ID: %u", msg_id);
+		break;
+	}
+
+	empty = cras_observer_ops_are_empty(&observer_ops);
+	if (client->observer) {
+		if (empty) {
+			cras_observer_remove(client->observer);
+			client->observer = NULL;
+		} else {
+			cras_observer_set_ops(client->observer, &observer_ops);
+		}
+	} else if (!empty) {
+		client->observer = cras_observer_add(&observer_ops, client);
+	}
+}
+
+/*
+ * Exported Functions.
+ */
+
+/* Creates a client structure and sends a message back informing the client that
+ * the conneciton has succeeded. */
+struct cras_rclient *cras_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;
+
+	cras_fill_client_connected(&msg, client->id);
+	state_fd = cras_sys_state_shm_fd();
+	cras_rclient_send_message(client, &msg.header, &state_fd, 1);
+
+	return client;
+}
+
 /* Removes all streams that the client owns and destroys it. */
 void cras_rclient_destroy(struct cras_rclient *client)
 {
-	client->ops->destroy(client);
+	cras_observer_remove(client->observer);
+	stream_list_rm_all_client_streams(
+			cras_iodev_list_get_stream_list(), client);
+	free(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 *fds, int num_fds)
-{
+				    const uint8_t *buf,
+				    size_t buf_len,
+				    int fd) {
 	struct cras_server_message *msg = (struct cras_server_message *)buf;
 
 	if (buf_len < sizeof(*msg))
 		return -EINVAL;
 	if (msg->length != buf_len)
 		return -EINVAL;
-	return client->ops->handle_message_from_client(client, msg, fds,
-						       num_fds);
+	cras_rclient_message_from_client(client, msg, fd);
+	return 0;
+}
+
+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))
+
+/*
+ * Check if client is sending an old version of connect message
+ * and converts it to the correct cras_connect_message.
+ * Note that this is special check only for libcras transition in
+ * clients, from CRAS_PROTO_VER = 1 to 2.
+ * TODO(hychao): clean up the check once clients transition is done.
+ */
+static int is_connect_msg_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 0;
+
+	old = (struct cras_connect_message_old *)msg;
+	if (old->proto_version + 1 != CRAS_PROTO_VER)
+		return 0;
+
+	memcpy(cmsg, old, sizeof(*old));
+	cmsg->effects = 0;
+	return 1;
+}
+
+/* Entry point for handling a message from the client.  Called from the main
+ * server context. */
+int cras_rclient_message_from_client(struct cras_rclient *client,
+				     const struct cras_server_message *msg,
+				     int fd) {
+	struct cras_connect_message cmsg;
+
+	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;
+	}
+
+	switch (msg->id) {
+	case CRAS_SERVER_CONNECT_STREAM:
+		if (MSG_LEN_VALID(msg, struct cras_connect_message)) {
+			handle_client_stream_connect(client,
+				(const struct cras_connect_message *)msg, fd);
+		} else if (is_connect_msg_old(msg, &cmsg)) {
+			handle_client_stream_connect(client, &cmsg, fd);
+		} else {
+			return -EINVAL;
+		}
+		break;
+	case CRAS_SERVER_DISCONNECT_STREAM:
+		if (!MSG_LEN_VALID(msg, struct cras_disconnect_stream_message))
+			return -EINVAL;
+		handle_client_stream_disconnect(client,
+			(const struct cras_disconnect_stream_message *)msg);
+		break;
+	case CRAS_SERVER_SET_SYSTEM_VOLUME:
+		if (!MSG_LEN_VALID(msg, struct cras_set_system_volume))
+			return -EINVAL;
+		cras_system_set_volume(
+			((const struct cras_set_system_volume *)msg)->volume);
+		break;
+	case CRAS_SERVER_SET_SYSTEM_MUTE:
+		if (!MSG_LEN_VALID(msg, struct cras_set_system_mute))
+			return -EINVAL;
+		cras_system_set_mute(
+			((const struct cras_set_system_mute *)msg)->mute);
+		break;
+	case CRAS_SERVER_SET_USER_MUTE:
+		if (!MSG_LEN_VALID(msg, struct cras_set_system_mute))
+			return -EINVAL;
+		cras_system_set_user_mute(
+			((const struct cras_set_system_mute *)msg)->mute);
+		break;
+	case CRAS_SERVER_SET_SYSTEM_MUTE_LOCKED:
+		if (!MSG_LEN_VALID(msg, struct cras_set_system_mute))
+			return -EINVAL;
+		cras_system_set_mute_locked(
+			((const struct cras_set_system_mute *)msg)->mute);
+		break;
+	case CRAS_SERVER_SET_SYSTEM_CAPTURE_GAIN: {
+		const struct cras_set_system_capture_gain *m =
+			(const struct cras_set_system_capture_gain *)msg;
+		if (!MSG_LEN_VALID(msg, struct cras_set_system_capture_gain))
+			return -EINVAL;
+		cras_system_set_capture_gain(m->gain);
+		break;
+	}
+	case CRAS_SERVER_SET_SYSTEM_CAPTURE_MUTE:
+		if (!MSG_LEN_VALID(msg, struct cras_set_system_mute))
+			return -EINVAL;
+		cras_system_set_capture_mute(
+			((const struct cras_set_system_mute *)msg)->mute);
+		break;
+	case CRAS_SERVER_SET_SYSTEM_CAPTURE_MUTE_LOCKED:
+		if (!MSG_LEN_VALID(msg, struct cras_set_system_mute))
+			return -EINVAL;
+		cras_system_set_capture_mute_locked(
+			((const struct cras_set_system_mute *)msg)->mute);
+		break;
+	case CRAS_SERVER_SET_NODE_ATTR: {
+		const struct cras_set_node_attr *m =
+			(const struct cras_set_node_attr *)msg;
+		if (!MSG_LEN_VALID(msg, struct cras_set_node_attr))
+			return -EINVAL;
+		cras_iodev_list_set_node_attr(m->node_id, m->attr, m->value);
+		break;
+	}
+	case CRAS_SERVER_SELECT_NODE: {
+		const struct cras_select_node *m =
+			(const struct cras_select_node *)msg;
+		if (!MSG_LEN_VALID(msg, struct cras_select_node) ||
+		    !direction_valid(m->direction))
+			return -EINVAL;
+		cras_iodev_list_select_node(m->direction, m->node_id);
+		break;
+	}
+	case CRAS_SERVER_ADD_ACTIVE_NODE: {
+		const struct cras_add_active_node *m =
+			(const struct cras_add_active_node *)msg;
+		if (!MSG_LEN_VALID(msg, struct cras_add_active_node) ||
+		    !direction_valid(m->direction))
+			return -EINVAL;
+		cras_iodev_list_add_active_node(m->direction, m->node_id);
+		break;
+	}
+	case CRAS_SERVER_RM_ACTIVE_NODE: {
+		const struct cras_rm_active_node *m =
+			(const struct cras_rm_active_node *)msg;
+		if (!MSG_LEN_VALID(msg, struct cras_rm_active_node) ||
+		    !direction_valid(m->direction))
+			return -EINVAL;
+		cras_iodev_list_rm_active_node(m->direction, m->node_id);
+		break;
+	}
+	case CRAS_SERVER_RELOAD_DSP:
+		cras_dsp_reload_ini();
+		break;
+	case CRAS_SERVER_DUMP_DSP_INFO:
+		cras_dsp_dump_info();
+		break;
+	case CRAS_SERVER_DUMP_AUDIO_THREAD:
+		dump_audio_thread_info(client);
+		break;
+	case CRAS_SERVER_DUMP_SNAPSHOTS:
+		dump_audio_thread_snapshots(client);
+		break;
+	case CRAS_SERVER_ADD_TEST_DEV: {
+		const struct cras_add_test_dev *m =
+			(const struct cras_add_test_dev *)msg;
+		if (!MSG_LEN_VALID(msg, struct cras_add_test_dev))
+			return -EINVAL;
+		cras_iodev_list_add_test_dev(m->type);
+		break;
+	}
+	case CRAS_SERVER_TEST_DEV_COMMAND: {
+		const struct cras_test_dev_command *m =
+			(const struct cras_test_dev_command *)msg;
+		if (!MSG_LEN_VALID(msg, struct cras_test_dev_command))
+			return -EINVAL;
+		cras_iodev_list_test_dev_command(
+			m->iodev_idx, (enum CRAS_TEST_IODEV_CMD)m->command,
+			m->data_len, m->data);
+		break;
+	}
+	case CRAS_SERVER_SUSPEND:
+		cras_system_set_suspended(1);
+		break;
+	case CRAS_SERVER_RESUME:
+		cras_system_set_suspended(0);
+		break;
+	case CRAS_CONFIG_GLOBAL_REMIX: {
+		const struct cras_config_global_remix *m =
+			(const struct cras_config_global_remix *)msg;
+		if (!MSG_LEN_VALID(msg, struct cras_config_global_remix) ||
+		    m->num_channels > CRAS_MAX_REMIX_CHANNELS)
+			return -EINVAL;
+		size_t size_with_coefficients = sizeof(*m) +
+			m->num_channels * m->num_channels *
+			sizeof(m->coefficient[0]);
+		if (size_with_coefficients != msg->length)
+			return -EINVAL;
+		audio_thread_config_global_remix(
+				cras_iodev_list_get_audio_thread(),
+				m->num_channels,
+				m->coefficient);
+		break;
+	}
+	case CRAS_SERVER_GET_HOTWORD_MODELS: {
+		if (!MSG_LEN_VALID(msg, struct cras_get_hotword_models))
+			return -EINVAL;
+		handle_get_hotword_models(client,
+			((const struct cras_get_hotword_models *)msg)->node_id);
+		break;
+	}
+	case CRAS_SERVER_SET_HOTWORD_MODEL: {
+		const struct cras_set_hotword_model *m =
+			(const struct cras_set_hotword_model *)msg;
+		if (!MSG_LEN_VALID(msg, struct cras_set_hotword_model))
+			return -EINVAL;
+		cras_iodev_list_set_hotword_model(m->node_id,
+						  m->model_name);
+		break;
+	}
+	case CRAS_SERVER_REGISTER_NOTIFICATION: {
+		const struct cras_register_notification *m =
+			(struct cras_register_notification *)msg;
+		if (!MSG_LEN_VALID(msg, struct cras_register_notification))
+			return -EINVAL;
+		register_for_notification(
+			client, (enum CRAS_CLIENT_MESSAGE_ID)m->msg_id,
+			m->do_register);
+		break;
+	}
+	case CRAS_SERVER_SET_AEC_DUMP: {
+		const struct cras_set_aec_dump *m =
+			(const struct cras_set_aec_dump *)msg;
+		if (!MSG_LEN_VALID(msg, struct cras_set_aec_dump))
+			return -EINVAL;
+		audio_thread_set_aec_dump(
+				cras_iodev_list_get_audio_thread(),
+				m->stream_id,
+				m->start, fd);
+		break;
+	}
+	case CRAS_SERVER_RELOAD_AEC_CONFIG:
+		cras_apm_list_reload_aec_config();
+		break;
+	default:
+		break;
+	}
+
+	return 0;
 }
 
 /* Sends a message to the client. */
 int cras_rclient_send_message(const struct cras_rclient *client,
-			      const struct cras_client_message *msg, int *fds,
+			      const struct cras_client_message *msg,
+			      int *fds,
 			      unsigned int num_fds)
 {
-	return client->ops->send_message_to_client(client, msg, fds, num_fds);
+	return cras_send_with_fds(client->fd, (const void *)msg, msg->length,
+				  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 6cffb7d..af0457f 100644
--- a/cras/src/server/cras_rclient.h
+++ b/cras/src/server/cras_rclient.h
@@ -9,53 +9,19 @@
 #ifndef CRAS_RCLIENT_H_
 #define CRAS_RCLIENT_H_
 
-#include "cras_types.h"
-
 struct cras_client_message;
 struct cras_message;
+struct cras_rclient;
 struct cras_server_message;
 
-/* An attached client.
- *  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.
- * handle_message_from_client - Entry point for handling a message from the
- * corresponded client.
- * send_message_to_client - Method for sending message to the corresponded
- * client.
- * destroy - Method to destroy and free the cras_rclient.
- */
-struct cras_rclient_ops {
-	int (*handle_message_from_client)(struct cras_rclient *,
-					  const struct cras_server_message *,
-					  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);
-	void (*destroy)(struct cras_rclient *);
-};
-
 /* Creates an rclient structure.
  * 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,
-					 enum CRAS_CONNECTION_TYPE conn_type);
+struct cras_rclient *cras_rclient_create(int fd, size_t id);
 
 /* Destroys an rclient created with "cras_rclient_create".
  * Args:
@@ -63,20 +29,34 @@
  */
 void cras_rclient_destroy(struct cras_rclient *client);
 
+/* Handles a message from the client.
+ * Args:
+ *    client - The client that received this message.
+ *    msg - The message that was sent by the remote client.
+ *    fd - The file descriptor that was sent by the remote client (or -1 if no
+ *         file descriptor was sent).
+ * Returns:
+ *    0 on success, otherwise a negative error code.
+ */
+int cras_rclient_message_from_client(struct cras_rclient *client,
+				     const struct cras_server_message *msg,
+				     int fd);
+
 /* Handles a received buffer from the client.
  * Args:
  *    client - The client that received this message.
  *    buf - The raw byte buffer the client sent. It should contain a valid
  *      cras_server_message.
  *    buf_len - The length of |buf|.
- *    fds - Array of valid file descriptors sent by the remote client.
- *    num_fds - Length of |fds|.
+ *    fd - The file descriptor that was sent by the remote client (or -1 if no
+ *         file descriptor was sent).
  * 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 *fds, int num_fds);
+				    const uint8_t *buf,
+                                    size_t buf_len,
+                                    int fd);
 
 /* Sends a message to the client.
  * Args:
@@ -88,7 +68,8 @@
  *    number of bytes written on success, otherwise a negative error code.
  */
 int cras_rclient_send_message(const struct cras_rclient *client,
-			      const struct cras_client_message *msg, int *fds,
+			      const struct cras_client_message *msg,
+			      int *fds,
 			      unsigned int num_fds);
 
 #endif /* CRAS_RCLIENT_H_ */
diff --git a/cras/src/server/cras_rclient_util.c b/cras/src/server/cras_rclient_util.c
deleted file mode 100644
index c88df82..0000000
--- a/cras/src/server/cras_rclient_util.c
+++ /dev/null
@@ -1,222 +0,0 @@
-/* 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
deleted file mode 100644
index 4768a47..0000000
--- a/cras/src/server/cras_rclient_util.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/* 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 55beed2..d527dd7 100644
--- a/cras/src/server/cras_rstream.c
+++ b/cras/src/server/cras_rstream.c
@@ -14,122 +14,62 @@
 #include "cras_messages.h"
 #include "cras_rclient.h"
 #include "cras_rstream.h"
-#include "cras_server_metrics.h"
 #include "cras_shm.h"
 #include "cras_types.h"
 #include "buffer_share.h"
 #include "cras_system_state.h"
 
-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)
+/* Configure the shm area for the stream. */
+static int setup_shm(struct cras_rstream *stream,
+		     struct cras_audio_shm *shm,
+		     struct rstream_shm_info *shm_info)
 {
-	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)
-{
+	size_t used_size, samples_size, frame_bytes;
 	const struct cras_audio_format *fmt = &stream->format;
-	char header_name[NAME_MAX];
-	char samples_name[NAME_MAX];
-	struct cras_shm_info header_info, samples_info;
-	uint32_t frame_bytes, used_size;
-	int rc;
 
-	if (stream->shm) {
-		/* already setup */
+	if (shm->area != NULL) /* already setup */
 		return -EEXIST;
-	}
-
-	snprintf(header_name, sizeof(header_name),
-		 "/cras-%d-stream-%08x-header", getpid(), stream->stream_id);
-
-	rc = cras_shm_info_init(header_name, cras_shm_header_size(),
-				&header_info);
-	if (rc)
-		return rc;
 
 	frame_bytes = snd_pcm_format_physical_width(fmt->format) / 8 *
-		      fmt->num_channels;
+			fmt->num_channels;
 	used_size = stream->buffer_frames * frame_bytes;
+	samples_size = used_size * CRAS_NUM_SHM_BUFFERS;
+	shm_info->length = sizeof(struct cras_audio_shm_area) + samples_size;
 
-	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;
+	snprintf(shm_info->shm_name, sizeof(shm_info->shm_name),
+		 "/cras-%d-stream-%08x", getpid(), stream->stream_id);
+
+	shm_info->shm_fd = cras_shm_open_rw(shm_info->shm_name, shm_info->length);
+	if (shm_info->shm_fd < 0)
+		return shm_info->shm_fd;
+
+	/* mmap shm. */
+	shm->area = mmap(NULL, shm_info->length,
+			 PROT_READ | PROT_WRITE, MAP_SHARED,
+			 shm_info->shm_fd, 0);
+	if (shm->area == (struct cras_audio_shm_area *)-1) {
+		close(shm_info->shm_fd);
+		return errno;
 	}
 
-	int samples_prot = 0;
-	if (stream->direction == CRAS_STREAM_OUTPUT)
-		samples_prot = PROT_READ;
-	else
-		samples_prot = PROT_WRITE;
+	cras_shm_set_volume_scaler(shm, 1.0);
+	/* Set up config and copy to shared area. */
+	cras_shm_set_frame_bytes(shm, frame_bytes);
+	shm->config.frame_bytes = frame_bytes;
+	cras_shm_set_used_size(shm, used_size);
+	memcpy(&shm->area->config, &shm->config, sizeof(shm->config));
+	return 0;
+}
 
-	rc = cras_audio_shm_create(&header_info, &samples_info, samples_prot,
-				   &stream->shm);
+/* Setup the shared memory area used for audio samples. */
+static inline int setup_shm_area(struct cras_rstream *stream)
+{
+	int rc;
+
+	rc = setup_shm(stream, &stream->shm,
+			&stream->shm_info);
 	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);
@@ -146,8 +86,8 @@
 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,
+				     size_t buffer_frames,
+				     size_t cb_threshold,
 				     struct cras_rclient *client,
 				     struct cras_rstream **stream_out)
 {
@@ -185,11 +125,6 @@
 		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;
 }
 
@@ -198,7 +133,7 @@
  */
 static void set_pending_reply(struct cras_rstream *stream)
 {
-	cras_shm_set_callback_pending(stream->shm, 1);
+	cras_shm_set_callback_pending(&stream->shm, 1);
 }
 
 /*
@@ -206,7 +141,7 @@
  */
 static void clear_pending_reply(struct cras_rstream *stream)
 {
-	cras_shm_set_callback_pending(stream->shm, 0);
+	cras_shm_set_callback_pending(&stream->shm, 0);
 }
 
 /*
@@ -219,8 +154,8 @@
  *   A negative error code if read fails or the message from client
  *   has errors.
  */
-static int get_audio_request_reply(const struct cras_rstream *stream,
-				   struct audio_message *msg)
+static int get_audio_request_reply(
+	const struct cras_rstream *stream, struct audio_message *msg)
 {
 	int rc;
 
@@ -241,8 +176,8 @@
  *   A negative error code if read fails or the message from client
  *   has errors.
  */
-static int read_and_handle_client_message(struct cras_rstream *stream)
-{
+static int read_and_handle_client_message(struct cras_rstream *stream) {
+
 	struct audio_message msg;
 	int rc;
 
@@ -280,11 +215,11 @@
 	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_shm_fd, config->client_shm_size, config->client,
-		stream_out);
+	rc = verify_rstream_parameters(config->direction, config->format,
+				       config->stream_type,
+				       config->buffer_frames,
+				       config->cb_threshold, config->client,
+				       stream_out);
 	if (rc < 0)
 		return rc;
 
@@ -294,35 +229,30 @@
 
 	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;
 	stream->buffer_frames = config->buffer_frames;
 	stream->cb_threshold = config->cb_threshold;
 	stream->client = config->client;
-	stream->shm = NULL;
+	stream->shm.area = NULL;
 	stream->master_dev.dev_id = NO_DEVICE;
 	stream->master_dev.dev_ptr = NULL;
-	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;
 
-	rc = setup_shm_area(stream, config->client_shm_fd,
-			    config->client_shm_size);
+	rc = setup_shm_area(stream);
 	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) ?
-			cras_apm_list_create(stream, config->effects) :
-			NULL;
+	stream->apm_list = (stream->direction == CRAS_STREAM_INPUT)
+			? cras_apm_list_create(stream, config->effects)
+			: NULL;
 
 	syslog(LOG_DEBUG, "stream %x frames %zu, cb_thresh %zu",
 	       config->stream_id, config->buffer_frames, config->cb_threshold);
@@ -330,18 +260,19 @@
 
 	cras_system_state_stream_added(stream->direction);
 
-	clock_gettime(CLOCK_MONOTONIC_RAW, &stream->start_ts);
-
 	return 0;
 }
 
 void cras_rstream_destroy(struct cras_rstream *stream)
 {
-	cras_server_metrics_missed_cb_frequency(stream);
 	cras_system_state_stream_removed(stream->direction);
 	close(stream->fd);
-	cras_audio_shm_destroy(stream->shm);
-	cras_audio_area_destroy(stream->audio_area);
+	if (stream->shm.area != NULL) {
+		munmap(stream->shm.area, stream->shm_info.length);
+		cras_shm_close_unlink(stream->shm_info.shm_name,
+				      stream->shm_info.shm_fd);
+		cras_audio_area_destroy(stream->audio_area);
+	}
 	buffer_share_destroy(stream->buf_state);
 	if (stream->apm_list)
 		cras_apm_list_destroy(stream->apm_list);
@@ -350,13 +281,13 @@
 
 unsigned int cras_rstream_get_effects(const struct cras_rstream *stream)
 {
-	return stream->apm_list ? cras_apm_list_get_effects(stream->apm_list) :
-				  0;
+	return stream->apm_list
+			? cras_apm_list_get_effects(stream->apm_list)
+			: 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)
 {
 	struct cras_apm *apm;
 
@@ -382,7 +313,8 @@
 }
 
 static void init_audio_message(struct audio_message *msg,
-			       enum CRAS_AUDIO_MESSAGE_ID id, uint32_t frames)
+			       enum CRAS_AUDIO_MESSAGE_ID id,
+			       uint32_t frames)
 {
 	memset(msg, 0, sizeof(*msg));
 	msg->id = id;
@@ -417,11 +349,11 @@
 	struct audio_message msg;
 	int rc;
 
-	cras_shm_buffer_write_complete(stream->shm);
+	cras_shm_buffer_write_complete(&stream->shm);
 
 	/* Mark shm as used. */
 	if (stream_is_server_only(stream)) {
-		cras_shm_buffer_read_current(stream->shm, count);
+		cras_shm_buffer_read_current(&stream->shm, count);
 		return 0;
 	}
 
@@ -435,7 +367,8 @@
 	return rc;
 }
 
-void cras_rstream_dev_attach(struct cras_rstream *rstream, unsigned int dev_id,
+void cras_rstream_dev_attach(struct cras_rstream *rstream,
+			     unsigned int dev_id,
 			     void *dev_ptr)
 {
 	if (buffer_share_add_id(rstream->buf_state, dev_id, dev_ptr) == 0)
@@ -474,25 +407,28 @@
 }
 
 void cras_rstream_dev_offset_update(struct cras_rstream *rstream,
-				    unsigned int frames, unsigned int dev_id)
+				    unsigned int frames,
+				    unsigned int dev_id)
 {
 	buffer_share_offset_update(rstream->buf_state, dev_id, frames);
 }
 
 void cras_rstream_update_input_write_pointer(struct cras_rstream *rstream)
 {
-	unsigned int nwritten =
-		buffer_share_get_new_write_point(rstream->buf_state);
+	struct cras_audio_shm *shm = cras_rstream_input_shm(rstream);
+	unsigned int nwritten = buffer_share_get_new_write_point(
+					rstream->buf_state);
 
-	cras_shm_buffer_written(rstream->shm, nwritten);
+	cras_shm_buffer_written(shm, nwritten);
 }
 
 void cras_rstream_update_output_read_pointer(struct cras_rstream *rstream)
 {
-	unsigned int nwritten =
-		buffer_share_get_new_write_point(rstream->buf_state);
+	struct cras_audio_shm *shm = cras_rstream_input_shm(rstream);
+	unsigned int nwritten = buffer_share_get_new_write_point(
+					rstream->buf_state);
 
-	cras_shm_buffer_read(rstream->shm, nwritten);
+	cras_shm_buffer_read(shm, nwritten);
 }
 
 unsigned int cras_rstream_dev_offset(const struct cras_rstream *rstream,
@@ -503,36 +439,40 @@
 
 void cras_rstream_update_queued_frames(struct cras_rstream *rstream)
 {
-	rstream->queued_frames =
-		MIN(cras_shm_get_frames(rstream->shm), rstream->buffer_frames);
+	const struct cras_audio_shm *shm = cras_rstream_output_shm(rstream);
+	rstream->queued_frames = MIN(cras_shm_get_frames(shm),
+				     rstream->buffer_frames);
 }
 
 unsigned int cras_rstream_playable_frames(struct cras_rstream *rstream,
 					  unsigned int dev_id)
 {
 	return rstream->queued_frames -
-	       cras_rstream_dev_offset(rstream, dev_id);
+			cras_rstream_dev_offset(rstream, dev_id);
 }
 
 float cras_rstream_get_volume_scaler(struct cras_rstream *rstream)
 {
-	return cras_shm_get_volume_scaler(rstream->shm);
+	const struct cras_audio_shm *shm = cras_rstream_output_shm(rstream);
+
+	return cras_shm_get_volume_scaler(shm);
 }
 
 uint8_t *cras_rstream_get_readable_frames(struct cras_rstream *rstream,
-					  unsigned int offset, size_t *frames)
+					  unsigned int offset,
+					  size_t *frames)
 {
-	return cras_shm_get_readable_frames(rstream->shm, offset, frames);
+	return cras_shm_get_readable_frames(&rstream->shm, offset, frames);
 }
 
 int cras_rstream_get_mute(const struct cras_rstream *rstream)
 {
-	return cras_shm_get_mute(rstream->shm);
+	return cras_shm_get_mute(&rstream->shm);
 }
 
 int cras_rstream_is_pending_reply(const struct cras_rstream *stream)
 {
-	return cras_shm_callback_pending(stream->shm);
+	return cras_shm_callback_pending(&stream->shm);
 }
 
 int cras_rstream_flush_old_audio_messages(struct cras_rstream *stream)
diff --git a/cras/src/server/cras_rstream.h b/cras/src/server/cras_rstream.h
index 3329fe0..d19fc47 100644
--- a/cras/src/server/cras_rstream.h
+++ b/cras/src/server/cras_rstream.h
@@ -13,10 +13,20 @@
 #include "cras_shm.h"
 #include "cras_types.h"
 
-struct cras_connect_message;
 struct cras_rclient;
 struct dev_mix;
 
+/* Holds identifiers for an shm segment.
+ *  shm_fd - File descriptor shared with client to access shm.
+ *  shm_name - Name of the shm area.
+ *  length - Size of the shm region.
+ */
+struct rstream_shm_info {
+	int shm_fd;
+	char shm_name[NAME_MAX];
+	size_t length;
+};
+
 /* Holds informations about the master active device.
  * Members:
  *    dev_id - id of the master device.
@@ -33,7 +43,6 @@
  * 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.
@@ -42,6 +51,7 @@
  *    master_dev_info - The info of the master device this stream attaches to.
  *    is_draining - The stream is draining and waiting to be removed.
  *    client - The client who uses this stream.
+ *    shm_info - Configuration data for shared memory
  *    shm - shared memory
  *    audio_area - space for playback/capture audio
  *    format - format of the stream
@@ -49,12 +59,9 @@
  *    sleep_interval_ts - Time between audio callbacks.
  *    last_fetch_ts - The time of the last stream fetch.
  *    longest_fetch_interval_ts - Longest interval between two fetches.
- *    start_ts - The time when the stream started.
- *    first_missed_cb_ts - The time when the first missed callback happens.
  *    buf_state - State of the buffer from all devices for this stream.
  *    apm_list - List of audio processing module instances.
  *    num_attached_devs - Number of iodevs this stream has attached to.
- *    num_missed_cb - Number of callback schedules have been missed.
  *    queued_frames - Cached value of the number of queued frames in shm.
  *    is_pinned - True if the stream is a pinned stream, false otherwise.
  *    pinned_dev_idx - device the stream is pinned, 0 if none.
@@ -63,7 +70,6 @@
 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;
@@ -72,19 +78,17 @@
 	int is_draining;
 	struct master_dev_info master_dev;
 	struct cras_rclient *client;
-	struct cras_audio_shm *shm;
+	struct rstream_shm_info shm_info;
+	struct cras_audio_shm shm;
 	struct cras_audio_area *audio_area;
 	struct cras_audio_format format;
 	struct timespec next_cb_ts;
 	struct timespec sleep_interval_ts;
 	struct timespec last_fetch_ts;
 	struct timespec longest_fetch_interval;
-	struct timespec start_ts;
-	struct timespec first_missed_cb_ts;
 	struct buffer_share *buf_state;
 	struct cras_apm_list *apm_list;
 	int num_attached_devs;
-	int num_missed_cb;
 	int queued_frames;
 	int is_pinned;
 	uint32_t pinned_dev_idx;
@@ -94,7 +98,6 @@
 
 /* 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.
@@ -102,18 +105,12 @@
  *    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. 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.
+ *    audio_fd - The fd to read/write audio signals to.
  *    client - The client that owns this stream.
  */
 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;
@@ -122,59 +119,12 @@
 	size_t buffer_frames;
 	size_t cb_threshold;
 	int audio_fd;
-	int client_shm_fd;
-	size_t client_shm_size;
 	struct cras_rclient *client;
 };
 
-/* 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. It's a mutable
- *             borrow.
+ *    config - Params for configuration of the new rstream.
  *    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
@@ -187,29 +137,29 @@
 void cras_rstream_destroy(struct cras_rstream *stream);
 
 /* Gets the id of the stream */
-static inline cras_stream_id_t
-cras_rstream_id(const struct cras_rstream *stream)
+static inline cras_stream_id_t cras_rstream_id(
+		const struct cras_rstream *stream)
 {
 	return stream->stream_id;
 }
 
 /* Gets the total buffer size in frames for the given client stream. */
-static inline size_t
-cras_rstream_get_buffer_frames(const struct cras_rstream *stream)
+static inline size_t cras_rstream_get_buffer_frames(
+		const struct cras_rstream *stream)
 {
 	return stream->buffer_frames;
 }
 
 /* Gets the callback threshold in frames for the given client stream. */
-static inline size_t
-cras_rstream_get_cb_threshold(const struct cras_rstream *stream)
+static inline size_t cras_rstream_get_cb_threshold(
+		const struct cras_rstream *stream)
 {
 	return stream->cb_threshold;
 }
 
 /* Gets the max write size for the stream. */
-static inline size_t
-cras_rstream_get_max_write_frames(const struct cras_rstream *stream)
+static inline size_t cras_rstream_get_max_write_frames(
+		const struct cras_rstream *stream)
 {
 	if (stream->flags & BULK_AUDIO_OK)
 		return cras_rstream_get_buffer_frames(stream);
@@ -217,15 +167,15 @@
 }
 
 /* Gets the stream type of this stream. */
-static inline enum CRAS_STREAM_TYPE
-cras_rstream_get_type(const struct cras_rstream *stream)
+static inline enum CRAS_STREAM_TYPE cras_rstream_get_type(
+		const struct cras_rstream *stream)
 {
 	return stream->stream_type;
 }
 
 /* Gets the direction (input/output/loopback) of the stream. */
-static inline enum CRAS_STREAM_DIRECTION
-cras_rstream_get_direction(const struct cras_rstream *stream)
+static inline enum CRAS_STREAM_DIRECTION cras_rstream_get_direction(
+		const struct cras_rstream *stream)
 {
 	return stream->direction;
 }
@@ -252,44 +202,54 @@
 }
 
 /* Gets the is_draning flag. */
-static inline int
-cras_rstream_get_is_draining(const struct cras_rstream *stream)
+static inline
+int cras_rstream_get_is_draining(const struct cras_rstream *stream)
 {
 	return stream->is_draining;
 }
 
 /* Sets the is_draning flag. */
 static inline void cras_rstream_set_is_draining(struct cras_rstream *stream,
-						int is_draining)
+					    int is_draining)
 {
 	stream->is_draining = is_draining;
 }
 
-/* Gets the shm fds used for the stream shm */
-static inline int cras_rstream_get_shm_fds(const struct cras_rstream *stream,
-					   int *header_fd, int *samples_fd)
+/* Gets the shm key used to find the outputshm region. */
+static inline int cras_rstream_output_shm_fd(const struct cras_rstream *stream)
 {
-	if (!header_fd || !samples_fd)
-		return -EINVAL;
-
-	*header_fd = stream->shm->header_info.fd;
-	*samples_fd = stream->shm->samples_info.fd;
-
-	return 0;
+	return stream->shm_info.shm_fd;
 }
 
-/* Gets the size of the shm area used for samples for this stream. */
-static inline size_t
-cras_rstream_get_samples_shm_size(const struct cras_rstream *stream)
+/* Gets the shm key used to find the input shm region. */
+static inline int cras_rstream_input_shm_fd(const struct cras_rstream *stream)
 {
-	return cras_shm_samples_size(stream->shm);
+	return stream->shm_info.shm_fd;
+}
+
+/* Gets the total size of shm memory allocated. */
+static inline size_t cras_rstream_get_total_shm_size(
+		const struct cras_rstream *stream)
+{
+	if (stream->direction == CRAS_STREAM_OUTPUT)
+		return cras_shm_total_size(&stream->shm);
+
+	/* Use the shm size for loopback streams. */
+	return cras_shm_total_size(&stream->shm);
 }
 
 /* Gets shared memory region for this stream. */
-static inline struct cras_audio_shm *
-cras_rstream_shm(struct cras_rstream *stream)
+static inline
+struct cras_audio_shm *cras_rstream_input_shm(struct cras_rstream *stream)
 {
-	return stream->shm;
+	return &stream->shm;
+}
+
+/* Gets shared memory region for this stream. */
+static inline
+struct cras_audio_shm *cras_rstream_output_shm(struct cras_rstream *stream)
+{
+	return &stream->shm;
 }
 
 /* Checks if the stream uses an output device. */
@@ -313,9 +273,8 @@
 unsigned int cras_rstream_get_effects(const struct cras_rstream *stream);
 
 /* Gets the format of data after stream specific processing. */
-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);
 
 /* Checks how much time has passed since last stream fetch and records
  * the longest fetch interval. */
@@ -330,13 +289,15 @@
 int cras_rstream_audio_ready(struct cras_rstream *stream, size_t count);
 
 /* Let the rstream know when a device is added or removed. */
-void cras_rstream_dev_attach(struct cras_rstream *rstream, unsigned int dev_id,
+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);
 
 /* A device using this stream has read or written samples. */
 void cras_rstream_dev_offset_update(struct cras_rstream *rstream,
-				    unsigned int frames, unsigned int dev_id);
+				    unsigned int frames,
+				    unsigned int dev_id);
 
 void cras_rstream_update_input_write_pointer(struct cras_rstream *rstream);
 void cras_rstream_update_output_read_pointer(struct cras_rstream *rstream);
@@ -346,13 +307,13 @@
 
 static inline unsigned int cras_rstream_level(struct cras_rstream *rstream)
 {
-	const struct cras_audio_shm *shm = cras_rstream_shm(rstream);
+	const struct cras_audio_shm *shm = cras_rstream_input_shm(rstream);
 	return cras_shm_frames_written(shm);
 }
 
 static inline int cras_rstream_input_level_met(struct cras_rstream *rstream)
 {
-	const struct cras_audio_shm *shm = cras_rstream_shm(rstream);
+	const struct cras_audio_shm *shm = cras_rstream_input_shm(rstream);
 	return cras_shm_frames_written(shm) >= rstream->cb_threshold;
 }
 
@@ -371,7 +332,8 @@
 /* Returns a pointer to readable frames, fills frames with the number of frames
  * available. */
 uint8_t *cras_rstream_get_readable_frames(struct cras_rstream *rstream,
-					  unsigned int offset, size_t *frames);
+					  unsigned int offset,
+					  size_t *frames);
 
 /* Returns non-zero if the stream is muted. */
 int cras_rstream_get_mute(const struct cras_rstream *rstream);
diff --git a/cras/src/server/cras_server.c b/cras/src/server/cras_server.c
index 97c83df..51f3507 100644
--- a/cras/src/server/cras_server.c
+++ b/cras/src/server/cras_server.c
@@ -49,7 +49,6 @@
 #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,13 +98,6 @@
 	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;
@@ -114,19 +106,8 @@
 	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)
@@ -145,21 +126,19 @@
 {
 	uint8_t buf[CRAS_SERV_MAX_MSG_SIZE];
 	int nread;
-	unsigned int num_fds = 2;
-	int fds[num_fds];
+	int fd;
+	unsigned int num_fds = 1;
 
-	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, fds,
-					    num_fds) < 0)
+	nread = cras_recv_with_fds(client->fd, buf, sizeof(buf), &fd, &num_fds);
+        if (nread < 0)
+                goto read_error;
+        if (cras_rclient_buffer_from_client(client->client, buf, nread, fd) < 0)
 		goto read_error;
 	return;
 
 read_error:
-	for (int i = 0; i < num_fds; i++)
-		if (fds[i] >= 0)
-			close(fds[i]);
+	if (fd != -1)
+		close(fd);
 	switch (nread) {
 	case 0:
 		break;
@@ -177,8 +156,8 @@
 {
 	socklen_t ucred_length = sizeof(client->ucred);
 
-	if (getsockopt(client->fd, SOL_SOCKET, SO_PEERCRED, &client->ucred,
-		       &ucred_length))
+	if (getsockopt(client->fd, SOL_SOCKET, SO_PEERCRED,
+		       &client->ucred, &ucred_length))
 		syslog(LOG_INFO, "Failed to get client socket info\n");
 }
 
@@ -199,7 +178,7 @@
 
 	info = state->client_info;
 	i = 0;
-	DL_FOREACH (serv->clients_head, c) {
+	DL_FOREACH(serv->clients_head, c) {
 		info->id = c->id;
 		info->pid = c->ucred.pid;
 		info->uid = c->ucred.uid;
@@ -214,7 +193,7 @@
 
 /* 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 server_socket *server_socket)
+static void handle_new_connection(struct sockaddr_un *address, int fd)
 {
 	int connection_fd;
 	struct attached_client *poll_client;
@@ -227,8 +206,7 @@
 	}
 
 	memset(&address_length, 0, sizeof(address_length));
-	connection_fd = accept(server_socket->fd,
-			       (struct sockaddr *)&server_socket->addr,
+	connection_fd = accept(fd, (struct sockaddr *) address,
 			       &address_length);
 	if (connection_fd < 0) {
 		syslog(LOG_ERR, "connecting");
@@ -254,12 +232,13 @@
 	poll_client->next = NULL;
 	poll_client->pollfd = NULL;
 	fill_client_info(poll_client);
-
-	poll_client->client = cras_rclient_create(
-		connection_fd, poll_client->id, server_socket->type);
+	poll_client->client = cras_rclient_create(connection_fd,
+						  poll_client->id);
 	if (poll_client->client == NULL) {
 		syslog(LOG_ERR, "failed to create client");
-		goto error;
+		close(connection_fd);
+		free(poll_client);
+		return;
 	}
 
 	DL_APPEND(server_instance.clients_head, poll_client);
@@ -267,18 +246,13 @@
 	/* 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
  * registered with system state so that it is called when any client asks to
  * have a callback triggered based on an fd being readable. */
-static int add_select_fd(int fd, void (*cb)(void *data), void *callback_data,
-			 void *server_data)
+static int add_select_fd(int fd, void (*cb)(void *data),
+			 void *callback_data, void *server_data)
 {
 	struct client_callback *new_cb;
 	struct client_callback *client_cb;
@@ -289,11 +263,11 @@
 		return -EINVAL;
 
 	/* Check if fd already exists. */
-	DL_FOREACH (serv->client_callbacks, client_cb)
+	DL_FOREACH(serv->client_callbacks, client_cb)
 		if (client_cb->select_fd == fd && !client_cb->deleted)
 			return -EEXIST;
 
-	new_cb = (struct client_callback *)calloc(1, sizeof(*new_cb));
+	new_cb = (struct  client_callback *)calloc(1, sizeof(*new_cb));
 	if (new_cb == NULL)
 		return -ENOMEM;
 
@@ -320,7 +294,7 @@
 	if (serv == NULL)
 		return;
 
-	DL_FOREACH (serv->client_callbacks, client_cb)
+	DL_FOREACH(serv->client_callbacks, client_cb)
 		if (client_cb->select_fd == fd)
 			client_cb->deleted = 1;
 }
@@ -328,7 +302,8 @@
 /* Creates a new task entry and append to system_tasks list, which will be
  * executed in main loop later without wait time.
  */
-static int add_task(void (*cb)(void *data), void *callback_data,
+static int add_task(void (*cb)(void *data),
+		    void *callback_data,
 		    void *server_data)
 {
 	struct server_data *serv;
@@ -360,7 +335,7 @@
 	if (serv == NULL)
 		return;
 
-	DL_FOREACH (serv->client_callbacks, client_cb)
+	DL_FOREACH(serv->client_callbacks, client_cb)
 		if (client_cb->deleted) {
 			DL_DELETE(serv->client_callbacks, client_cb);
 			server_instance.num_client_callbacks--;
@@ -379,9 +354,8 @@
 #if defined(__amd64__)
 /* CPU detection - probaby best to move this elsewhere */
 static void cpuid(unsigned int *eax, unsigned int *ebx, unsigned int *ecx,
-		  unsigned int *edx, unsigned int op)
+	          unsigned int *edx, unsigned int op)
 {
-	// clang-format off
 	__asm__ __volatile__ (
 		"cpuid"
 		: "=a" (*eax),
@@ -389,8 +363,7 @@
 		  "=c" (*ecx),
 		  "=d" (*edx)
 		: "a" (op), "c" (0)
-	);
-	// clang-format on
+    );
 }
 
 static unsigned int cpu_x86_flags(void)
@@ -457,99 +430,19 @@
 	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 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 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(enum CRAS_CONNECTION_TYPE conn_type,
-					   struct server_socket *server_socket)
-{
-	int socket_fd = -1;
-	int rc = 0;
-	struct sockaddr_un *addr = &server_socket->addr;
-
-	socket_fd = socket(PF_UNIX, SOCK_SEQPACKET, 0);
-	if (socket_fd < 0) {
-		syslog(LOG_ERR, "Main server socket failed.");
-		rc = socket_fd;
-		goto error;
-	}
-
-	memset(addr, 0, sizeof(*addr));
-	addr->sun_family = AF_UNIX;
-	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
-	 * file created by bind, leaving no window for it to be modified. Start
-	 * with very restricted permissions. */
-	rc = fchmod(socket_fd, 0700);
-	if (rc < 0)
-		goto error;
-
-	rc = bind(socket_fd, (struct sockaddr *)addr,
-		  sizeof(struct sockaddr_un));
-	if (rc < 0) {
-		syslog(LOG_ERR, "Bind to server socket failed.");
-		rc = errno;
-		goto error;
-	}
-
-	/* Let other members in our group play audio through this socket. */
-	rc = chmod(addr->sun_path, 0770);
-	if (rc < 0)
-		goto error;
-
-	if (listen(socket_fd, 5) != 0) {
-		syslog(LOG_ERR, "Listen on server socket failed.");
-		rc = errno;
-		goto error;
-	}
-
-	server_socket->fd = socket_fd;
-	server_socket->type = conn_type;
-	return 0;
-error:
-	if (socket_fd >= 0) {
-		close(socket_fd);
-		unlink(addr->sun_path);
-	}
-	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 socket_fd = -1;
 	int rc = 0;
+	const char *sockdir;
+	struct sockaddr_un addr;
 	struct attached_client *elm;
 	struct client_callback *client_cb;
 	struct system_task *tasks;
@@ -595,11 +488,48 @@
 	}
 #endif
 
-	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;
+	socket_fd = socket(PF_UNIX, SOCK_SEQPACKET, 0);
+	if (socket_fd < 0) {
+		syslog(LOG_ERR, "Main server socket failed.");
+		rc = socket_fd;
+		goto bail;
+	}
+
+	sockdir = cras_config_get_system_socket_file_dir();
+	if (sockdir == NULL) {
+		rc = -ENOTDIR;
+		goto bail;
+	}
+
+	memset(&addr, 0, sizeof(addr));
+	addr.sun_family = AF_UNIX;
+	snprintf(addr.sun_path, sizeof(addr.sun_path),
+		 "%s/%s", sockdir, CRAS_SOCKET_FILE);
+	unlink(addr.sun_path);
+
+	/* Linux quirk: calling fchmod before bind, sets the permissions of the
+	 * file created by bind, leaving no window for it to be modified. Start
+	 * with very restricted permissions. */
+	rc = fchmod(socket_fd, 0700);
+	if (rc < 0)
+		goto bail;
+
+	if (bind(socket_fd, (struct sockaddr *) &addr,
+		 sizeof(struct sockaddr_un)) != 0) {
+		syslog(LOG_ERR, "Bind to server socket failed.");
+		rc = errno;
+		goto bail;
+	}
+
+	/* Let other members in our group play audio through this socket. */
+	rc = chmod(addr.sun_path, 0770);
+	if (rc < 0)
+		goto bail;
+
+	if (listen(socket_fd, 5) != 0) {
+		syslog(LOG_ERR, "Listen on server socket failed.");
+		rc = errno;
+		goto bail;
 	}
 
 	tm = cras_system_state_get_tm();
@@ -614,30 +544,25 @@
 
 	/* Main server loop - client callbacks are run from this context. */
 	while (1) {
-		poll_size_needed = CRAS_NUM_CONN_TYPE +
-				   server_instance.num_clients +
-				   server_instance.num_client_callbacks;
+		poll_size_needed = 1 + server_instance.num_clients +
+					server_instance.num_client_callbacks;
 		if (poll_size_needed > pollfds_size) {
 			pollfds_size = 2 * poll_size_needed;
 			pollfds = realloc(pollfds,
-					  sizeof(*pollfds) * pollfds_size);
+					sizeof(*pollfds) * pollfds_size);
 		}
 
-		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;
+		pollfds[0].fd = socket_fd;
+		pollfds[0].events = POLLIN;
+		num_pollfds = 1;
 
-		DL_FOREACH (server_instance.clients_head, elm) {
+		DL_FOREACH(server_instance.clients_head, elm) {
 			pollfds[num_pollfds].fd = elm->fd;
 			pollfds[num_pollfds].events = POLLIN;
 			elm->pollfd = &pollfds[num_pollfds];
 			num_pollfds++;
 		}
-		DL_FOREACH (server_instance.client_callbacks, client_cb) {
+		DL_FOREACH(server_instance.client_callbacks, client_cb) {
 			if (client_cb->deleted)
 				continue;
 			pollfds[num_pollfds].fd = client_cb->select_fd;
@@ -648,7 +573,7 @@
 
 		tasks = server_instance.system_tasks;
 		server_instance.system_tasks = NULL;
-		DL_FOREACH (tasks, system_task) {
+		DL_FOREACH(tasks, system_task) {
 			system_task->callback(system_task->callback_data);
 			DL_DELETE(tasks, system_task);
 			free(system_task);
@@ -666,27 +591,22 @@
 			poll_timeout = timers_active ? &ts : NULL;
 
 		rc = ppoll(pollfds, num_pollfds, poll_timeout, NULL);
-		if (rc < 0)
+		if  (rc < 0)
 			continue;
 
 		cras_tm_call_callbacks(tm);
 
 		/* Check for new connections. */
-		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]);
-		}
-
+		if (pollfds[0].revents & POLLIN)
+			handle_new_connection(&addr, socket_fd);
 		/* Check if there are messages pending for any clients. */
-		DL_FOREACH (server_instance.clients_head, elm)
+		DL_FOREACH(server_instance.clients_head, elm)
 			if (elm->pollfd && elm->pollfd->revents & POLLIN)
 				handle_message_from_client(elm);
 		/* Check any client-registered fd/callback pairs. */
-		DL_FOREACH (server_instance.client_callbacks, client_cb)
-			if (!client_cb->deleted && client_cb->pollfd &&
+		DL_FOREACH(server_instance.client_callbacks, client_cb)
+			if (!client_cb->deleted &&
+			    client_cb->pollfd &&
 			    (client_cb->pollfd->revents & POLLIN))
 				client_cb->callback(client_cb->callback_data);
 
@@ -701,7 +621,10 @@
 	}
 
 bail:
-	cleanup_server_sockets();
+	if (socket_fd >= 0) {
+		close(socket_fd);
+		unlink(addr.sun_path);
+	}
 	free(pollfds);
 	cras_observer_server_free();
 	return rc;
@@ -711,6 +634,6 @@
 {
 	struct attached_client *client;
 
-	DL_FOREACH (server_instance.clients_head, client)
+	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.h b/cras/src/server/cras_server.h
index a7dfa63..d17314b 100644
--- a/cras/src/server/cras_server.h
+++ b/cras/src/server/cras_server.h
@@ -12,9 +12,9 @@
 /*
  * Bitmask for cras_server_run() argument profile_disable_mask
  */
-#define CRAS_SERVER_PROFILE_MASK_HFP (1 << 0)
-#define CRAS_SERVER_PROFILE_MASK_HSP (1 << 1)
-#define CRAS_SERVER_PROFILE_MASK_A2DP (1 << 2)
+#define CRAS_SERVER_PROFILE_MASK_HFP	(1 << 0)
+#define CRAS_SERVER_PROFILE_MASK_HSP	(1 << 1)
+#define CRAS_SERVER_PROFILE_MASK_A2DP	(1 << 2)
 
 /* Reserver client id 0-15 for internal server usage. */
 #define RESERVED_CLIENT_IDS 16
diff --git a/cras/src/server/cras_server_metrics.c b/cras/src/server/cras_server_metrics.c
index 5f51e83..c78ad64 100644
--- a/cras/src/server/cras_server_metrics.c
+++ b/cras/src/server/cras_server_metrics.c
@@ -4,170 +4,55 @@
  */
 
 #include <errno.h>
-#include <math.h>
 #include <stdio.h>
 #include <string.h>
 #include <syslog.h>
 
-#ifdef CRAS_DBUS
-#include "cras_bt_io.h"
-#endif
-#include "cras_iodev.h"
 #include "cras_metrics.h"
 #include "cras_main_message.h"
 #include "cras_rstream.h"
-#include "cras_system_state.h"
 
-#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";
 const char kHighestOutputHardwareLevel[] = "Cras.HighestOutputHardwareLevel";
-const char kMissedCallbackFirstTimeInput[] =
-	"Cras.MissedCallbackFirstTimeInput";
-const char kMissedCallbackFirstTimeOutput[] =
-	"Cras.MissedCallbackFirstTimeOutput";
-const char kMissedCallbackFrequencyInput[] =
-	"Cras.MissedCallbackFrequencyInput";
-const char kMissedCallbackFrequencyOutput[] =
-	"Cras.MissedCallbackFrequencyOutput";
-const char kMissedCallbackFrequencyAfterReschedulingInput[] =
-	"Cras.MissedCallbackFrequencyAfterReschedulingInput";
-const char kMissedCallbackFrequencyAfterReschedulingOutput[] =
-	"Cras.MissedCallbackFrequencyAfterReschedulingOutput";
-const char kMissedCallbackSecondTimeInput[] =
-	"Cras.MissedCallbackSecondTimeInput";
-const char kMissedCallbackSecondTimeOutput[] =
-	"Cras.MissedCallbackSecondTimeOutput";
 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
- * than the threshold.
- */
-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,
 	HIGHEST_INPUT_HW_LEVEL,
 	HIGHEST_OUTPUT_HW_LEVEL,
 	LONGEST_FETCH_DELAY,
-	MISSED_CB_FIRST_TIME_INPUT,
-	MISSED_CB_FIRST_TIME_OUTPUT,
-	MISSED_CB_FREQUENCY_INPUT,
-	MISSED_CB_FREQUENCY_OUTPUT,
-	MISSED_CB_FREQUENCY_AFTER_RESCHEDULING_INPUT,
-	MISSED_CB_FREQUENCY_AFTER_RESCHEDULING_OUTPUT,
-	MISSED_CB_SECOND_TIME_INPUT,
-	MISSED_CB_SECOND_TIME_OUTPUT,
 	NUM_UNDERRUNS,
 	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 {
-	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;
 };
 
-/*
- * Make sure the size of message in the acceptable range. Otherwise, it may
- * be split into mutiple packets while sending.
- */
-static_assert(sizeof(union cras_server_metrics_data) <= 256,
-	      "The size is too large.");
-
 struct cras_server_metrics_message {
 	struct cras_main_message header;
 	enum CRAS_SERVER_METRICS_TYPE metrics_type;
 	union cras_server_metrics_data data;
 };
 
-static void init_server_metrics_msg(struct cras_server_metrics_message *msg,
-				    enum CRAS_SERVER_METRICS_TYPE type,
-				    union cras_server_metrics_data data)
+static void init_server_metrics_msg(
+		struct cras_server_metrics_message *msg,
+		enum CRAS_SERVER_METRICS_TYPE type,
+		union cras_server_metrics_data data)
 {
 	memset(msg, 0, sizeof(*msg));
 	msg->header.type = CRAS_MAIN_METRICS;
@@ -176,265 +61,8 @@
 	msg->data = data;
 }
 
-static void handle_metrics_message(struct cras_main_message *msg, void *arg);
-
-/* The wrapper function of cras_main_message_send. */
-static int cras_server_metrics_message_send(struct cras_main_message *msg)
-{
-	/* If current function is in the main thread, call handler directly. */
-	if (cras_system_state_in_main_thread()) {
-		handle_metrics_message(msg, NULL);
-		return 0;
-	}
-	return cras_main_message_send(msg);
-}
-
-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 CRAS_METRICS_DEVICE_INTERNAL_SPEAKER;
-	case CRAS_NODE_TYPE_HEADPHONE:
-		return CRAS_METRICS_DEVICE_HEADPHONE;
-	case CRAS_NODE_TYPE_HDMI:
-		return CRAS_METRICS_DEVICE_HDMI;
-	case CRAS_NODE_TYPE_HAPTIC:
-		return CRAS_METRICS_DEVICE_HAPTIC;
-	case CRAS_NODE_TYPE_LINEOUT:
-		return CRAS_METRICS_DEVICE_LINEOUT;
-	case CRAS_NODE_TYPE_MIC:
-		switch (iodev->active_node->position) {
-		case NODE_POSITION_INTERNAL:
-			return CRAS_METRICS_DEVICE_INTERNAL_MIC;
-		case NODE_POSITION_FRONT:
-			return CRAS_METRICS_DEVICE_FRONT_MIC;
-		case NODE_POSITION_REAR:
-			return CRAS_METRICS_DEVICE_REAR_MIC;
-		case NODE_POSITION_KEYBOARD:
-			return CRAS_METRICS_DEVICE_KEYBOARD_MIC;
-		case NODE_POSITION_EXTERNAL:
-		default:
-			return CRAS_METRICS_DEVICE_MIC;
-		}
-	case CRAS_NODE_TYPE_HOTWORD:
-		return CRAS_METRICS_DEVICE_HOTWORD;
-	case CRAS_NODE_TYPE_POST_MIX_PRE_DSP:
-		return CRAS_METRICS_DEVICE_POST_MIX_LOOPBACK;
-	case CRAS_NODE_TYPE_POST_DSP:
-		return CRAS_METRICS_DEVICE_POST_DSP_LOOPBACK;
-	case CRAS_NODE_TYPE_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 CRAS_METRICS_DEVICE_A2DP;
-		if (cras_bt_io_on_profile(
-			    iodev, CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY))
-			return CRAS_METRICS_DEVICE_HFP;
-		if (cras_bt_io_on_profile(
-			    iodev, CRAS_BT_DEVICE_PROFILE_HSP_AUDIOGATEWAY))
-			return CRAS_METRICS_DEVICE_HSP;
-#endif
-		return CRAS_METRICS_DEVICE_BLUETOOTH;
-	case CRAS_NODE_TYPE_UNKNOWN:
-	default:
-		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)
-{
-	struct cras_server_metrics_message msg;
-	union cras_server_metrics_data data;
-	int err;
-
-	data.value = supported;
-	init_server_metrics_msg(&msg, BT_WIDEBAND_SUPPORTED, 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_SUPPORTED");
-		return err;
-	}
-	return 0;
-}
-
-int cras_server_metrics_device_runtime(struct cras_iodev *iodev)
-{
-	struct cras_server_metrics_message msg;
-	union cras_server_metrics_data data;
-	struct timespec now;
-	int err;
-
-	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);
-
-	init_server_metrics_msg(&msg, DEVICE_RUNTIME, data);
-
-	err = cras_server_metrics_message_send(
-		(struct cras_main_message *)&msg);
-	if (err < 0) {
-		syslog(LOG_ERR,
-		       "Failed to send metrics message: DEVICE_RUNTIME");
-		return err;
-	}
-
-	return 0;
-}
-
-int cras_server_metrics_highest_device_delay(
-	unsigned int hw_level, unsigned int largest_cb_level,
-	enum CRAS_STREAM_DIRECTION direction)
-{
-	struct cras_server_metrics_message msg;
-	union cras_server_metrics_data data;
-	int err;
-
-	if (largest_cb_level == 0) {
-		syslog(LOG_ERR,
-		       "Failed to record device delay: devided by zero");
-		return -1;
-	}
-
-	/*
-	 * Because the latency depends on the callback threshold of streams, it
-	 * should be calculated as dividing the highest hardware level by largest
-	 * callback threshold of streams. For output device, this value should fall
-	 * around 2 because CRAS 's scheduling maintain device buffer level around
-	 * 1~2 minimum callback level. For input device, this value should be around
-	 * 1 because the device buffer level is around 0~1 minimum callback level.
-	 * Besides, UMA cannot record float so this ratio is multiplied by 1000.
-	 */
-	data.value = hw_level * 1000 / largest_cb_level;
-
-	switch (direction) {
-	case CRAS_STREAM_INPUT:
-		init_server_metrics_msg(&msg, HIGHEST_DEVICE_DELAY_INPUT, data);
-		break;
-	case CRAS_STREAM_OUTPUT:
-		init_server_metrics_msg(&msg, HIGHEST_DEVICE_DELAY_OUTPUT,
-					data);
-		break;
-	default:
-		return 0;
-	}
-
-	err = cras_server_metrics_message_send(
-		(struct cras_main_message *)&msg);
-	if (err < 0) {
-		syslog(LOG_ERR,
-		       "Failed to send metrics message: HIGHEST_DEVICE_DELAY");
-		return err;
-	}
-
-	return 0;
-}
-
 int cras_server_metrics_highest_hw_level(unsigned hw_level,
-					 enum CRAS_STREAM_DIRECTION direction)
+		enum CRAS_STREAM_DIRECTION direction)
 {
 	struct cras_server_metrics_message msg;
 	union cras_server_metrics_data data;
@@ -453,8 +81,7 @@
 		return 0;
 	}
 
-	err = cras_server_metrics_message_send(
-		(struct cras_main_message *)&msg);
+	err = cras_main_message_send((struct cras_main_message *)&msg);
 	if (err < 0) {
 		syslog(LOG_ERR,
 		       "Failed to send metrics message: HIGHEST_HW_LEVEL");
@@ -472,8 +99,7 @@
 
 	data.value = delay_msec;
 	init_server_metrics_msg(&msg, LONGEST_FETCH_DELAY, data);
-	err = cras_server_metrics_message_send(
-		(struct cras_main_message *)&msg);
+	err = cras_main_message_send((struct cras_main_message *)&msg);
 	if (err < 0) {
 		syslog(LOG_ERR,
 		       "Failed to send metrics message: LONGEST_FETCH_DELAY");
@@ -491,8 +117,7 @@
 
 	data.value = num_underruns;
 	init_server_metrics_msg(&msg, NUM_UNDERRUNS, data);
-	err = cras_server_metrics_message_send(
-		(struct cras_main_message *)&msg);
+	err = cras_main_message_send((struct cras_main_message *)&msg);
 	if (err < 0) {
 		syslog(LOG_ERR,
 		       "Failed to send metrics message: NUM_UNDERRUNS");
@@ -502,360 +127,82 @@
 	return 0;
 }
 
-int cras_server_metrics_missed_cb_frequency(const struct cras_rstream *stream)
-{
-	struct cras_server_metrics_message msg;
-	union cras_server_metrics_data data;
-	struct timespec now, time_since;
-	double seconds, frequency;
-	int err;
-
-	clock_gettime(CLOCK_MONOTONIC_RAW, &now);
-	subtract_timespecs(&now, &stream->start_ts, &time_since);
-	seconds = (double)time_since.tv_sec + time_since.tv_nsec / 1000000000.0;
-
-	/* Ignore streams which do not have enough runtime. */
-	if (seconds < MISSED_CB_FREQUENCY_SECONDS_MIN)
-		return 0;
-
-	/* Compute how many callbacks are missed in a day. */
-	frequency = (double)stream->num_missed_cb * 86400.0 / seconds;
-	data.value = (unsigned)(round(frequency) + 1e-9);
-
-	if (stream->direction == CRAS_STREAM_INPUT)
-		init_server_metrics_msg(&msg, MISSED_CB_FREQUENCY_INPUT, data);
-	else
-		init_server_metrics_msg(&msg, MISSED_CB_FREQUENCY_OUTPUT, data);
-
-	err = cras_server_metrics_message_send(
-		(struct cras_main_message *)&msg);
-	if (err < 0) {
-		syslog(LOG_ERR,
-		       "Failed to send metrics message: MISSED_CB_FREQUENCY");
-		return err;
-	}
-
-	/*
-	 * If missed callback happened at least once, also record frequncy after
-	 * rescheduling.
-	 */
-	if (!stream->num_missed_cb)
-		return 0;
-
-	subtract_timespecs(&now, &stream->first_missed_cb_ts, &time_since);
-	seconds = (double)time_since.tv_sec + time_since.tv_nsec / 1000000000.0;
-
-	/* Compute how many callbacks are missed in a day. */
-	frequency = (double)(stream->num_missed_cb - 1) * 86400.0 / seconds;
-	data.value = (unsigned)(round(frequency) + 1e-9);
-
-	if (stream->direction == CRAS_STREAM_INPUT) {
-		init_server_metrics_msg(
-			&msg, MISSED_CB_FREQUENCY_AFTER_RESCHEDULING_INPUT,
-			data);
-	} else {
-		init_server_metrics_msg(
-			&msg, MISSED_CB_FREQUENCY_AFTER_RESCHEDULING_OUTPUT,
-			data);
-	}
-
-	err = cras_server_metrics_message_send(
-		(struct cras_main_message *)&msg);
-	if (err < 0) {
-		syslog(LOG_ERR,
-		       "Failed to send metrics message: MISSED_CB_FREQUENCY");
-		return err;
-	}
-
-	return 0;
-}
-
-/*
- * Logs the duration between stream starting time and the first missed
- * callback.
- */
-static int
-cras_server_metrics_missed_cb_first_time(const struct cras_rstream *stream)
-{
-	struct cras_server_metrics_message msg;
-	union cras_server_metrics_data data;
-	struct timespec time_since;
-	int err;
-
-	subtract_timespecs(&stream->first_missed_cb_ts, &stream->start_ts,
-			   &time_since);
-	data.value = (unsigned)time_since.tv_sec;
-
-	if (stream->direction == CRAS_STREAM_INPUT) {
-		init_server_metrics_msg(&msg, MISSED_CB_FIRST_TIME_INPUT, data);
-	} else {
-		init_server_metrics_msg(&msg, MISSED_CB_FIRST_TIME_OUTPUT,
-					data);
-	}
-	err = cras_server_metrics_message_send(
-		(struct cras_main_message *)&msg);
-	if (err < 0) {
-		syslog(LOG_ERR, "Failed to send metrics message: "
-				"MISSED_CB_FIRST_TIME");
-		return err;
-	}
-
-	return 0;
-}
-
-/* Logs the duration between the first and the second missed callback events. */
-static int
-cras_server_metrics_missed_cb_second_time(const struct cras_rstream *stream)
-{
-	struct cras_server_metrics_message msg;
-	union cras_server_metrics_data data;
-	struct timespec now, time_since;
-	int err;
-
-	clock_gettime(CLOCK_MONOTONIC_RAW, &now);
-	subtract_timespecs(&now, &stream->first_missed_cb_ts, &time_since);
-	data.value = (unsigned)time_since.tv_sec;
-
-	if (stream->direction == CRAS_STREAM_INPUT) {
-		init_server_metrics_msg(&msg, MISSED_CB_SECOND_TIME_INPUT,
-					data);
-	} else {
-		init_server_metrics_msg(&msg, MISSED_CB_SECOND_TIME_OUTPUT,
-					data);
-	}
-	err = cras_server_metrics_message_send(
-		(struct cras_main_message *)&msg);
-	if (err < 0) {
-		syslog(LOG_ERR, "Failed to send metrics message: "
-				"MISSED_CB_SECOND_TIME");
-		return err;
-	}
-
-	return 0;
-}
-
-int cras_server_metrics_missed_cb_event(struct cras_rstream *stream)
-{
-	int rc = 0;
-
-	stream->num_missed_cb += 1;
-	if (stream->num_missed_cb == 1)
-		clock_gettime(CLOCK_MONOTONIC_RAW, &stream->first_missed_cb_ts);
-
-	/* Do not record missed cb if the stream has these flags. */
-	if (stream->flags & (BULK_AUDIO_OK | USE_DEV_TIMING | TRIGGER_ONLY))
-		return 0;
-
-	/* Only record the first and the second events. */
-	if (stream->num_missed_cb == 1)
-		rc = cras_server_metrics_missed_cb_first_time(stream);
-	else if (stream->num_missed_cb == 2)
-		rc = cras_server_metrics_missed_cb_second_time(stream);
-
-	return rc;
-}
-
 int cras_server_metrics_stream_config(struct cras_rstream_config *config)
 {
 	struct cras_server_metrics_message msg;
 	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(
-		(struct cras_main_message *)&msg);
+	err = cras_main_message_send((struct cras_main_message *)&msg);
 	if (err < 0) {
 		syslog(LOG_ERR,
-		       "Failed to send metrics message: STREAM_CONFIG");
+			"Failed to send metrics message: STREAM_CONFIG");
 		return err;
 	}
 
 	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];
-
-	snprintf(metrics_name, METRICS_NAME_BUFFER_SIZE,
-		 "Cras.%sDevice%sRuntime",
-		 data.direction == CRAS_STREAM_INPUT ? "Input" : "Output",
-		 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
-metrics_stream_config(struct cras_server_metrics_stream_config config)
+static void metrics_stream_config(
+		struct cras_server_metrics_stream_config config)
 {
 	/* Logs stream callback threshold. */
 	cras_metrics_log_sparse_histogram(kStreamCallbackThreshold,
 					  config.cb_threshold);
 
 	/* Logs stream flags. */
-	cras_metrics_log_sparse_histogram(kStreamFlags, config.flags);
+	cras_metrics_log_sparse_histogram(kStreamFlags,
+					  config.flags);
 
 	/* Logs stream sampling format. */
-	cras_metrics_log_sparse_histogram(kStreamSamplingFormat, config.format);
+	cras_metrics_log_sparse_histogram(kStreamSamplingFormat,
+					  config.format);
 
 	/* 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);
+	cras_metrics_log_sparse_histogram(kStreamSamplingRate,
+					  config.rate);
 }
 
 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;
+			(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);
-		break;
-	case DEVICE_RUNTIME:
-		metrics_device_runtime(metrics_msg->data.device_data);
-		break;
-	case HIGHEST_DEVICE_DELAY_INPUT:
-		cras_metrics_log_histogram(kHighestDeviceDelayInput,
-					   metrics_msg->data.value, 1, 10000,
-					   20);
-		break;
-	case HIGHEST_DEVICE_DELAY_OUTPUT:
-		cras_metrics_log_histogram(kHighestDeviceDelayOutput,
-					   metrics_msg->data.value, 1, 10000,
-					   20);
-		break;
 	case HIGHEST_INPUT_HW_LEVEL:
 		cras_metrics_log_histogram(kHighestInputHardwareLevel,
-					   metrics_msg->data.value, 1, 10000,
-					   20);
+				metrics_msg->data.value, 1, 10000, 20);
 		break;
 	case HIGHEST_OUTPUT_HW_LEVEL:
 		cras_metrics_log_histogram(kHighestOutputHardwareLevel,
-					   metrics_msg->data.value, 1, 10000,
-					   20);
+				metrics_msg->data.value, 1, 10000, 20);
 		break;
 	case LONGEST_FETCH_DELAY:
 		cras_metrics_log_histogram(kStreamTimeoutMilliSeconds,
-					   metrics_msg->data.value, 1, 20000,
-					   10);
-		break;
-	case MISSED_CB_FIRST_TIME_INPUT:
-		cras_metrics_log_histogram(kMissedCallbackFirstTimeInput,
-					   metrics_msg->data.value, 0, 90000,
-					   20);
-		break;
-	case MISSED_CB_FIRST_TIME_OUTPUT:
-		cras_metrics_log_histogram(kMissedCallbackFirstTimeOutput,
-					   metrics_msg->data.value, 0, 90000,
-					   20);
-		break;
-	case MISSED_CB_FREQUENCY_INPUT:
-		cras_metrics_log_histogram(kMissedCallbackFrequencyInput,
-					   metrics_msg->data.value, 0, 90000,
-					   20);
-		break;
-	case MISSED_CB_FREQUENCY_OUTPUT:
-		cras_metrics_log_histogram(kMissedCallbackFrequencyOutput,
-					   metrics_msg->data.value, 0, 90000,
-					   20);
-		break;
-	case MISSED_CB_FREQUENCY_AFTER_RESCHEDULING_INPUT:
-		cras_metrics_log_histogram(
-			kMissedCallbackFrequencyAfterReschedulingInput,
-			metrics_msg->data.value, 0, 90000, 20);
-		break;
-	case MISSED_CB_FREQUENCY_AFTER_RESCHEDULING_OUTPUT:
-		cras_metrics_log_histogram(
-			kMissedCallbackFrequencyAfterReschedulingOutput,
-			metrics_msg->data.value, 0, 90000, 20);
-		break;
-	case MISSED_CB_SECOND_TIME_INPUT:
-		cras_metrics_log_histogram(kMissedCallbackSecondTimeInput,
-					   metrics_msg->data.value, 0, 90000,
-					   20);
-		break;
-	case MISSED_CB_SECOND_TIME_OUTPUT:
-		cras_metrics_log_histogram(kMissedCallbackSecondTimeOutput,
-					   metrics_msg->data.value, 0, 90000,
-					   20);
+				metrics_msg->data.value, 1, 20000, 10);
 		break;
 	case NUM_UNDERRUNS:
 		cras_metrics_log_histogram(kUnderrunsPerDevice,
-					   metrics_msg->data.value, 0, 1000,
-					   10);
+				metrics_msg->data.value, 0, 1000, 10);
 		break;
 	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);
 		break;
 	}
+
 }
 
-int cras_server_metrics_init()
-{
-	cras_main_message_add_handler(CRAS_MAIN_METRICS, handle_metrics_message,
-				      NULL);
+int cras_server_metrics_init() {
+	cras_main_message_add_handler(CRAS_MAIN_METRICS,
+				      handle_metrics_message, NULL);
 	return 0;
 }
diff --git a/cras/src/server/cras_server_metrics.h b/cras/src/server/cras_server_metrics.h
index b9eb121..f2b206a 100644
--- a/cras/src/server/cras_server_metrics.h
+++ b/cras/src/server/cras_server_metrics.h
@@ -6,50 +6,33 @@
 #ifndef CRAS_SERVER_METRICS_H_
 #define CRAS_SERVER_METRICS_H_
 
-#include <stdbool.h>
-
-#include "cras_iodev.h"
 #include "cras_rstream.h"
 
 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);
-
-/* Logs the highest delay time of a device. */
-int cras_server_metrics_highest_device_delay(
-	unsigned int hw_level, unsigned int largest_cb_level,
-	enum CRAS_STREAM_DIRECTION direction);
+extern const char kHighestInputHardwareLevel[];
+extern const char kHighestOutputHardwareLevel[];
+extern const char kStreamTimeoutMilliSeconds[];
+extern const char kStreamCallbackThreshold[];
+extern const char kStreamFlags[];
+extern const char kStreamSamplingFormat[];
+extern const char kStreamSamplingRate[];
+extern const char kUnderrunsPerDevice[];
 
 /* Logs the highest hardware level of a device. */
 int cras_server_metrics_highest_hw_level(unsigned hw_level,
-					 enum CRAS_STREAM_DIRECTION direction);
+		enum CRAS_STREAM_DIRECTION direction);
 
 /* Logs the longest fetch delay of a stream in millisecond. */
-int cras_server_metrics_longest_fetch_delay(unsigned delay_msec);
+int cras_server_metrics_longest_fetch_delay(int delay_msec);
 
 /* Logs the number of underruns of a device. */
 int cras_server_metrics_num_underruns(unsigned num_underruns);
 
-/* Logs the frequency of missed callback. */
-int cras_server_metrics_missed_cb_frequency(const struct cras_rstream *stream);
-
-/* Logs the missed callback event. */
-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();
 
 #endif /* CRAS_SERVER_METRICS_H_ */
+
diff --git a/cras/src/server/cras_system_state.c b/cras/src/server/cras_system_state.c
index 7aa3367..1eaa5ec 100644
--- a/cras/src/server/cras_system_state.c
+++ b/cras/src/server/cras_system_state.c
@@ -47,7 +47,6 @@
  *    tm - The system-wide timer manager.
  *    add_task - Function to handle adding a task for main thread to execute.
  *    task_data - Data to be passed to add_task handler function.
- *    main_thread_tid - The thread id of the main thread.
  */
 static struct {
 	struct cras_server_state *exp_state;
@@ -62,34 +61,36 @@
 	pthread_mutex_t update_lock;
 	struct cras_tm *tm;
 	/* Select loop callback registration. */
-	int (*fd_add)(int fd, void (*cb)(void *data), void *cb_data,
-		      void *select_data);
+	int (*fd_add)(int fd, void (*cb)(void *data),
+		      void *cb_data, void *select_data);
 	void (*fd_rm)(int fd, void *select_data);
 	void *select_data;
-	int (*add_task)(void (*callback)(void *data), void *callback_data,
-			void *task_data);
+	int (*add_task)(void (*callback)(void *data),
+					 void *callback_data,
+					 void *task_data);
 	void *task_data;
 	struct cras_audio_thread_snapshot_buffer snapshot_buffer;
-	pthread_t main_thread_tid;
 } state;
 
 /*
  * Exported Interface.
  */
 
-void cras_system_state_init(const char *device_config_dir, const char *shm_name,
-			    int rw_shm_fd, int ro_shm_fd,
-			    struct cras_server_state *exp_state,
-			    size_t exp_state_size)
+void cras_system_state_init(const char *device_config_dir,
+                            const char *shm_name,
+                            int rw_shm_fd,
+                            int ro_shm_fd,
+                            struct cras_server_state *exp_state,
+                            size_t exp_state_size)
 {
 	struct cras_board_config board_config;
 	int rc;
 
-	assert(sizeof(*exp_state) == exp_state_size);
+        assert(sizeof(*exp_state) == exp_state_size);
 	state.shm_size = sizeof(*exp_state);
 
-	strncpy(state.shm_name, shm_name, sizeof(state.shm_name));
-	state.shm_name[sizeof(state.shm_name) - 1] = '\0';
+        strncpy(state.shm_name, shm_name, sizeof(state.shm_name));
+        state.shm_name[sizeof(state.shm_name) - 1] = '\0';
 	state.shm_fd = rw_shm_fd;
 	state.shm_fd_ro = ro_shm_fd;
 
@@ -114,9 +115,8 @@
 	exp_state->num_streams_attached = 0;
 	exp_state->default_output_buffer_size =
 		board_config.default_output_buffer_size;
-	exp_state->aec_supported = board_config.aec_supported;
-	exp_state->aec_group_id = board_config.aec_group_id;
-	exp_state->bt_wbs_enabled = 0;
+	exp_state->aec_supported =
+		board_config.aec_supported;
 
 	if ((rc = pthread_mutex_init(&state.update_lock, 0) != 0)) {
 		syslog(LOG_ERR, "Fatal: system state mutex init");
@@ -145,9 +145,6 @@
 	/* Initialize snapshot buffer memory */
 	memset(&state.snapshot_buffer, 0,
 	       sizeof(struct cras_audio_thread_snapshot_buffer));
-
-	/* Save thread id of the main thread. */
-	state.main_thread_tid = pthread_self();
 }
 
 void cras_system_state_set_internal_ucm_suffix(const char *internal_ucm_suffix)
@@ -356,21 +353,6 @@
 	return state.exp_state->aec_supported;
 }
 
-int cras_system_get_aec_group_id()
-{
-	return state.exp_state->aec_group_id;
-}
-
-void cras_system_set_bt_wbs_enabled(bool enabled)
-{
-	state.exp_state->bt_wbs_enabled = enabled;
-}
-
-bool cras_system_get_bt_wbs_enabled()
-{
-	return !!state.exp_state->bt_wbs_enabled;
-}
-
 int cras_system_add_alsa_card(struct cras_alsa_card_info *alsa_card_info)
 {
 	struct card_list *card;
@@ -382,15 +364,17 @@
 
 	card_index = alsa_card_info->card_index;
 
-	DL_FOREACH (state.cards, card) {
+	DL_FOREACH(state.cards, card) {
 		if (card_index == cras_alsa_card_get_index(card->card))
 			return -EEXIST;
 	}
 	alsa_card = cras_alsa_card_create(
-		alsa_card_info, state.device_config_dir, state.device_blacklist,
-		(alsa_card_info->card_type == ALSA_CARD_TYPE_INTERNAL) ?
-			state.internal_ucm_suffix :
-			NULL);
+			alsa_card_info,
+			state.device_config_dir,
+			state.device_blacklist,
+			(alsa_card_info->card_type == ALSA_CARD_TYPE_INTERNAL)
+				? state.internal_ucm_suffix
+				: NULL);
 	if (alsa_card == NULL)
 		return -ENOMEM;
 	card = calloc(1, sizeof(*card));
@@ -405,7 +389,7 @@
 {
 	struct card_list *card;
 
-	DL_FOREACH (state.cards, card) {
+	DL_FOREACH(state.cards, card) {
 		if (alsa_card_index == cras_alsa_card_get_index(card->card))
 			break;
 	}
@@ -421,16 +405,18 @@
 {
 	struct card_list *card;
 
-	DL_FOREACH (state.cards, card)
+	DL_FOREACH(state.cards, card)
 		if (alsa_card_index == cras_alsa_card_get_index(card->card))
 			return 1;
 	return 0;
 }
 
-int cras_system_set_select_handler(
-	int (*add)(int fd, void (*callback)(void *data), void *callback_data,
-		   void *select_data),
-	void (*rm)(int fd, void *select_data), void *select_data)
+int cras_system_set_select_handler(int (*add)(int fd,
+					      void (*callback)(void *data),
+					      void *callback_data,
+					      void *select_data),
+				   void (*rm)(int fd, void *select_data),
+				   void *select_data)
 {
 	if (state.fd_add != NULL || state.fd_rm != NULL)
 		return -EEXIST;
@@ -440,12 +426,14 @@
 	return 0;
 }
 
-int cras_system_add_select_fd(int fd, void (*callback)(void *data),
+int cras_system_add_select_fd(int fd,
+			      void (*callback)(void *data),
 			      void *callback_data)
 {
 	if (state.fd_add == NULL)
 		return -EINVAL;
-	return state.fd_add(fd, callback, callback_data, state.select_data);
+	return state.fd_add(fd, callback, callback_data,
+			    state.select_data);
 }
 
 int cras_system_set_add_task_handler(int (*add_task)(void (*cb)(void *data),
@@ -496,12 +484,13 @@
 	struct cras_server_state *s;
 	unsigned i, sum;
 
+
 	s = cras_system_state_update_begin();
 	if (!s)
 		return;
 
 	sum = 0;
-	for (i = 0; i < CRAS_NUM_DIRECTIONS; i++)
+	for (i=0; i < CRAS_NUM_DIRECTIONS; i++)
 		sum += s->num_active_streams[i];
 
 	/* Set the last active time when removing the final stream. */
@@ -519,7 +508,7 @@
 {
 	unsigned i, sum;
 	sum = 0;
-	for (i = 0; i < CRAS_NUM_DIRECTIONS; i++)
+	for (i=0; i < CRAS_NUM_DIRECTIONS; i++)
 		sum += state.exp_state->num_active_streams[i];
 	return sum;
 }
@@ -601,20 +590,18 @@
 	return state.tm;
 }
 
+
 void cras_system_state_dump_snapshots()
 {
 	memcpy(&state.exp_state->snapshot_buffer, &state.snapshot_buffer,
-	       sizeof(struct cras_audio_thread_snapshot_buffer));
+			sizeof(struct cras_audio_thread_snapshot_buffer));
 }
 
-void cras_system_state_add_snapshot(struct cras_audio_thread_snapshot *snapshot)
+void cras_system_state_add_snapshot(
+	struct cras_audio_thread_snapshot *snapshot)
 {
 	state.snapshot_buffer.snapshots[state.snapshot_buffer.pos++] =
-		(*snapshot);
-	state.snapshot_buffer.pos %= CRAS_MAX_AUDIO_THREAD_SNAPSHOTS;
-}
-
-int cras_system_state_in_main_thread()
-{
-	return pthread_self() == state.main_thread_tid;
+			(*snapshot);
+	state.snapshot_buffer.pos %=
+		CRAS_MAX_AUDIO_THREAD_SNAPSHOTS;
 }
diff --git a/cras/src/server/cras_system_state.h b/cras/src/server/cras_system_state.h
index 270e54c..e5c3980 100644
--- a/cras/src/server/cras_system_state.h
+++ b/cras/src/server/cras_system_state.h
@@ -13,7 +13,6 @@
 #ifndef CRAS_SYSTEM_STATE_H_
 #define CRAS_SYSTEM_STATE_H_
 
-#include <stdbool.h>
 #include <stddef.h>
 
 #include "cras_types.h"
@@ -38,10 +37,12 @@
  *    exp_state - Shared memory region for storing state.
  *    exp_state_size - Size of |exp_state|.
  */
-void cras_system_state_init(const char *device_config_dir, const char *shm_name,
-			    int rw_shm_fd, int ro_shm_fd,
-			    struct cras_server_state *exp_state,
-			    size_t exp_state_size);
+void cras_system_state_init(const char *device_config_dir,
+                            const char *shm_name,
+                            int rw_shm_fd,
+                            int ro_shm_fd,
+                            struct cras_server_state *exp_state,
+                            size_t exp_state_size);
 void cras_system_state_deinit();
 
 /* Sets the suffix string to control which UCM config fo load. */
@@ -122,15 +123,6 @@
 /* Returns if system aec is supported. */
 int cras_system_get_aec_supported();
 
-/* Returns the system aec group id is available. */
-int cras_system_get_aec_group_id();
-
-/* Sets the flag to enable or disable bluetooth wideband speech feature. */
-void cras_system_set_bt_wbs_enabled(bool enabled);
-
-/* Gets the elable flag of bluetooth wideband speech feature. */
-bool cras_system_get_bt_wbs_enabled();
-
 /* Adds a card at the given index to the system.  When a new card is found
  * (through a udev event notification) this will add the card to the system,
  * causing its devices to become available for playback/capture.
@@ -173,10 +165,12 @@
  * Returns:
  *    0 on success, or -EBUSY if there is already a registered handler.
  */
-int cras_system_set_select_handler(
-	int (*add)(int fd, void (*callback)(void *data), void *callback_data,
-		   void *select_data),
-	void (*rm)(int fd, void *select_data), void *select_data);
+int cras_system_set_select_handler(int (*add)(int fd,
+					      void (*callback)(void *data),
+					      void *callback_data,
+					      void *select_data),
+				  void (*rm)(int fd, void *select_data),
+				  void *select_data);
 
 /* Adds the fd and callback pair.  When select indicates that fd is readable,
  * the callback will be called.
@@ -187,7 +181,8 @@
  * Returns:
  *    0 on success or a negative error code on failure.
  */
-int cras_system_add_select_fd(int fd, void (*callback)(void *data),
+int cras_system_add_select_fd(int fd,
+			      void (*callback)(void *data),
 			      void *callback_data);
 
 /* Removes the fd from the list of fds that are passed to select.
@@ -324,9 +319,4 @@
  */
 void cras_system_state_dump_snapshots();
 
-/*
- * Returns true if in the main thread.
- */
-int cras_system_state_in_main_thread();
-
 #endif /* CRAS_SYSTEM_STATE_H_ */
diff --git a/cras/src/server/cras_telephony.c b/cras/src/server/cras_telephony.c
index ac95f7e..8f2deb7 100644
--- a/cras/src/server/cras_telephony.c
+++ b/cras/src/server/cras_telephony.c
@@ -15,53 +15,55 @@
 
 #define CRAS_TELEPHONY_INTERFACE "org.chromium.cras.Telephony"
 #define CRAS_TELEPHONY_OBJECT_PATH "/org/chromium/cras/telephony"
-#define TELEPHONY_INTROSPECT_XML                                               \
-	DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE                              \
-	"<node>\n"                                                             \
-	"  <interface name=\"" CRAS_TELEPHONY_INTERFACE "\">\n"                \
-	"    <method name=\"AnswerCall\">\n"                                   \
-	"    </method>\n"                                                      \
-	"    <method name=\"IncomingCall\">\n"                                 \
-	"      <arg name=\"value\" type=\"s\" direction=\"in\"/>\n"            \
-	"    </method>\n"                                                      \
-	"    <method name=\"TerminateCall\">\n"                                \
-	"    </method>\n"                                                      \
-	"    <method name=\"SetBatteryLevel\">\n"                              \
-	"      <arg name=\"value\" type=\"i\" direction=\"in\"/>\n"            \
-	"    </method>\n"                                                      \
-	"    <method name=\"SetSignalStrength\">\n"                            \
-	"      <arg name=\"value\" type=\"i\" direction=\"in\"/>\n"            \
-	"    </method>\n"                                                      \
-	"    <method name=\"SetServiceAvailability\">\n"                       \
-	"      <arg name=\"value\" type=\"i\" direction=\"in\"/>\n"            \
-	"    </method>\n"                                                      \
-	"    <method name=\"SetDialNumber\">\n"                                \
-	"      <arg name=\"value\" type=\"s\" direction=\"in\"/>\n"            \
-	"    </method>\n"                                                      \
-	"    <method name=\"SetCallheld\">\n"                                  \
-	"      <arg name=\"value\" type=\"i\" direction=\"in\"/>\n"            \
-	"    </method>\n"                                                      \
-	"  </interface>\n"                                                     \
-	"  <interface name=\"" DBUS_INTERFACE_INTROSPECTABLE "\">\n"           \
-	"    <method name=\"Introspect\">\n"                                   \
-	"      <arg name=\"data\" type=\"s\" direction=\"out\"/>\n"            \
-	"    </method>\n"                                                      \
-	"  </interface>\n"                                                     \
+#define TELEPHONY_INTROSPECT_XML					\
+	DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE			\
+	"<node>\n"							\
+	"  <interface name=\"" CRAS_TELEPHONY_INTERFACE "\">\n"		\
+	"    <method name=\"AnswerCall\">\n"				\
+	"    </method>\n"						\
+	"    <method name=\"IncomingCall\">\n"				\
+	"      <arg name=\"value\" type=\"s\" direction=\"in\"/>\n"	\
+	"    </method>\n"						\
+	"    <method name=\"TerminateCall\">\n"				\
+	"    </method>\n"						\
+	"    <method name=\"SetBatteryLevel\">\n"				\
+	"      <arg name=\"value\" type=\"i\" direction=\"in\"/>\n"	\
+	"    </method>\n"						\
+	"    <method name=\"SetSignalStrength\">\n"				\
+	"      <arg name=\"value\" type=\"i\" direction=\"in\"/>\n"	\
+	"    </method>\n"						\
+	"    <method name=\"SetServiceAvailability\">\n"				\
+	"      <arg name=\"value\" type=\"i\" direction=\"in\"/>\n"	\
+	"    </method>\n"						\
+	"    <method name=\"SetDialNumber\">\n"				\
+	"      <arg name=\"value\" type=\"s\" direction=\"in\"/>\n"	\
+	"    </method>\n"						\
+	"    <method name=\"SetCallheld\">\n"				\
+	"      <arg name=\"value\" type=\"i\" direction=\"in\"/>\n"	\
+	"    </method>\n"						\
+	"  </interface>\n"						\
+	"  <interface name=\"" DBUS_INTERFACE_INTROSPECTABLE "\">\n"	\
+	"    <method name=\"Introspect\">\n"				\
+	"      <arg name=\"data\" type=\"s\" direction=\"out\"/>\n"	\
+	"    </method>\n"						\
+	"  </interface>\n"						\
 	"</node>\n"
 
 static struct cras_telephony_handle telephony_handle;
 
 /* Helper to extract a single argument from a DBus message. */
-static DBusHandlerResult get_single_arg(DBusMessage *message, int dbus_type,
-					void *arg)
+static DBusHandlerResult get_single_arg(DBusMessage *message,
+					int dbus_type, void *arg)
 {
 	DBusError dbus_error;
 
 	dbus_error_init(&dbus_error);
 
-	if (!dbus_message_get_args(message, &dbus_error, dbus_type, arg,
+	if (!dbus_message_get_args(message, &dbus_error,
+				   dbus_type, arg,
 				   DBUS_TYPE_INVALID)) {
-		syslog(LOG_WARNING, "Bad method received: %s",
+		syslog(LOG_WARNING,
+		       "Bad method received: %s",
 		       dbus_error.message);
 		dbus_error_free(&dbus_error);
 		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
@@ -86,11 +88,12 @@
 }
 
 static DBusHandlerResult handle_incoming_call(DBusConnection *conn,
-					      DBusMessage *message, void *arg)
+					      DBusMessage *message,
+					      void *arg)
 {
 	struct hfp_slc_handle *handle;
 	DBusHandlerResult rc;
-	const char *number;
+	const char* number;
 
 	rc = get_single_arg(message, DBUS_TYPE_STRING, &number);
 	if (rc != DBUS_HANDLER_RESULT_HANDLED)
@@ -110,7 +113,8 @@
 }
 
 static DBusHandlerResult handle_terminate_call(DBusConnection *conn,
-					       DBusMessage *message, void *arg)
+					       DBusMessage *message,
+					       void *arg)
 {
 	cras_telephony_event_terminate_call();
 
@@ -119,7 +123,8 @@
 }
 
 static DBusHandlerResult handle_answer_call(DBusConnection *conn,
-					    DBusMessage *message, void *arg)
+					    DBusMessage *message,
+					    void *arg)
 {
 	cras_telephony_event_answer_call();
 
@@ -128,7 +133,8 @@
 }
 
 static DBusHandlerResult handle_set_dial_number(DBusConnection *conn,
-						DBusMessage *message, void *arg)
+						DBusMessage *message,
+						void *arg)
 {
 	DBusHandlerResult rc;
 	const char *number;
@@ -144,7 +150,8 @@
 }
 
 static DBusHandlerResult handle_set_battery(DBusConnection *conn,
-					    DBusMessage *message, void *arg)
+					    DBusMessage *message,
+					    void *arg)
 {
 	struct hfp_slc_handle *handle;
 	DBusHandlerResult rc;
@@ -163,7 +170,8 @@
 }
 
 static DBusHandlerResult handle_set_signal(DBusConnection *conn,
-					   DBusMessage *message, void *arg)
+					   DBusMessage *message,
+					   void *arg)
 {
 	struct hfp_slc_handle *handle;
 	DBusHandlerResult rc;
@@ -182,7 +190,8 @@
 }
 
 static DBusHandlerResult handle_set_service(DBusConnection *conn,
-					    DBusMessage *message, void *arg)
+					    DBusMessage *message,
+					    void *arg)
 {
 	struct hfp_slc_handle *handle;
 	DBusHandlerResult rc;
@@ -201,7 +210,8 @@
 }
 
 static DBusHandlerResult handle_set_callheld(DBusConnection *conn,
-					     DBusMessage *message, void *arg)
+					     DBusMessage *message,
+					     void *arg)
 {
 	struct hfp_slc_handle *handle;
 	DBusHandlerResult rc;
@@ -221,15 +231,17 @@
 }
 
 /* Handle incoming messages. */
-static DBusHandlerResult
-handle_telephony_message(DBusConnection *conn, DBusMessage *message, void *arg)
+static DBusHandlerResult handle_telephony_message(DBusConnection *conn,
+						  DBusMessage *message,
+						  void *arg)
 {
 	syslog(LOG_ERR, "Telephony message: %s %s %s",
-	       dbus_message_get_path(message),
-	       dbus_message_get_interface(message),
-	       dbus_message_get_member(message));
+			dbus_message_get_path(message),
+			dbus_message_get_interface(message),
+			dbus_message_get_member(message));
 
-	if (dbus_message_is_method_call(message, DBUS_INTERFACE_INTROSPECTABLE,
+	if (dbus_message_is_method_call(message,
+					DBUS_INTERFACE_INTROSPECTABLE,
 					"Introspect")) {
 		DBusMessage *reply;
 		const char *xml = TELEPHONY_INTROSPECT_XML;
@@ -237,7 +249,8 @@
 		reply = dbus_message_new_method_return(message);
 		if (!reply)
 			return DBUS_HANDLER_RESULT_NEED_MEMORY;
-		if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &xml,
+		if (!dbus_message_append_args(reply,
+					      DBUS_TYPE_STRING, &xml,
 					      DBUS_TYPE_INVALID))
 			return DBUS_HANDLER_RESULT_NEED_MEMORY;
 		if (!dbus_connection_send(conn, reply, NULL))
@@ -245,15 +258,17 @@
 
 		dbus_message_unref(reply);
 		return DBUS_HANDLER_RESULT_HANDLED;
-	} else if (dbus_message_is_method_call(
-			   message, CRAS_TELEPHONY_INTERFACE, "IncomingCall")) {
+	} else if (dbus_message_is_method_call(message,
+					       CRAS_TELEPHONY_INTERFACE,
+					       "IncomingCall")) {
 		return handle_incoming_call(conn, message, arg);
 	} else if (dbus_message_is_method_call(message,
 					       CRAS_TELEPHONY_INTERFACE,
 					       "TerminateCall")) {
 		return handle_terminate_call(conn, message, arg);
-	} else if (dbus_message_is_method_call(
-			   message, CRAS_TELEPHONY_INTERFACE, "AnswerCall")) {
+	} else if (dbus_message_is_method_call(message,
+					       CRAS_TELEPHONY_INTERFACE,
+					       "AnswerCall")) {
 		return handle_answer_call(conn, message, arg);
 	} else if (dbus_message_is_method_call(message,
 					       CRAS_TELEPHONY_INTERFACE,
@@ -271,8 +286,9 @@
 					       CRAS_TELEPHONY_INTERFACE,
 					       "SetServiceAvailability")) {
 		return handle_set_service(conn, message, arg);
-	} else if (dbus_message_is_method_call(
-			   message, CRAS_TELEPHONY_INTERFACE, "SetCallheld")) {
+	} else if (dbus_message_is_method_call(message,
+					       CRAS_TELEPHONY_INTERFACE,
+					       "SetCallheld")) {
 		return handle_set_callheld(conn, message, arg);
 	}
 
@@ -292,10 +308,12 @@
 	telephony_handle.dbus_conn = conn;
 	dbus_connection_ref(telephony_handle.dbus_conn);
 
-	if (!dbus_connection_register_object_path(
-		    conn, CRAS_TELEPHONY_OBJECT_PATH, &control_vtable,
-		    &dbus_error)) {
-		syslog(LOG_ERR, "Couldn't register telephony control: %s: %s",
+	if (!dbus_connection_register_object_path(conn,
+						  CRAS_TELEPHONY_OBJECT_PATH,
+						  &control_vtable,
+						  &dbus_error)) {
+		syslog(LOG_ERR,
+		       "Couldn't register telephony control: %s: %s",
 		       CRAS_TELEPHONY_OBJECT_PATH, dbus_error.message);
 		dbus_error_free(&dbus_error);
 		return;
@@ -313,7 +331,7 @@
 	telephony_handle.dbus_conn = NULL;
 }
 
-struct cras_telephony_handle *cras_telephony_get()
+struct cras_telephony_handle* cras_telephony_get()
 {
 	return &telephony_handle;
 }
@@ -384,7 +402,8 @@
 	return 0;
 }
 
-void cras_telephony_store_dial_number(int len, const char *number)
+void cras_telephony_store_dial_number(int len,
+				      const char *number)
 {
 	if (telephony_handle.dial_number != NULL) {
 		free(telephony_handle.dial_number);
@@ -392,12 +411,13 @@
 	}
 
 	if (len == 0)
-		return;
+		return ;
 
 	telephony_handle.dial_number =
-		(char *)calloc(len + 1, sizeof(*telephony_handle.dial_number));
+			(char *) calloc(len + 1,
+					sizeof(*telephony_handle.dial_number));
 	strncpy(telephony_handle.dial_number, number, len);
 
-	syslog(LOG_ERR, "store dial_number: \"%s\"",
-	       telephony_handle.dial_number);
+	syslog(LOG_ERR,
+	       "store dial_number: \"%s\"", telephony_handle.dial_number);
 }
diff --git a/cras/src/server/cras_telephony.h b/cras/src/server/cras_telephony.h
index 7c0a6c5..425cecf 100644
--- a/cras/src/server/cras_telephony.h
+++ b/cras/src/server/cras_telephony.h
@@ -36,14 +36,15 @@
 	DBusConnection *dbus_conn;
 };
 
+
 void cras_telephony_start(DBusConnection *conn);
 
 void cras_telephony_stop();
 
-struct cras_telephony_handle *cras_telephony_get();
+struct cras_telephony_handle* cras_telephony_get();
 
 /* Stores dial number in telephony module. */
-void cras_telephony_store_dial_number(int len, const char *num);
+void cras_telephony_store_dial_number(int len, const char* num);
 
 /* Handles answer call event from dbus or HF */
 int cras_telephony_event_answer_call();
diff --git a/cras/src/server/cras_tm.c b/cras/src/server/cras_tm.c
index c215fdc..2eb9fe1 100644
--- a/cras/src/server/cras_tm.c
+++ b/cras/src/server/cras_tm.c
@@ -53,10 +53,11 @@
 
 /* Exported Interface. */
 
-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)
 {
 	struct cras_timer *t;
 
@@ -90,7 +91,7 @@
 {
 	struct cras_timer *t;
 
-	DL_FOREACH (tm->timers, t) {
+	DL_FOREACH(tm->timers, t) {
 		DL_DELETE(tm->timers, t);
 		free(t);
 	}
@@ -107,7 +108,7 @@
 		return 0;
 
 	min = &tm->timers->ts;
-	DL_FOREACH (tm->timers, t)
+	DL_FOREACH(tm->timers, t)
 		if (timespec_sooner(&t->ts, min))
 			min = &t->ts;
 
diff --git a/cras/src/server/cras_tm.h b/cras/src/server/cras_tm.h
index 4cc37ac..2dfd8c2 100644
--- a/cras/src/server/cras_tm.h
+++ b/cras/src/server/cras_tm.h
@@ -24,10 +24,11 @@
  *    Pointer to a newly allocated timer, passed timer to cras_tm_cancel_timer
  *    to cancel before it fires.
  */
-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);
 
 /* Deletes a timer returned from cras_tm_create_timer. */
 void cras_tm_cancel_timer(struct cras_tm *tm, struct cras_timer *t);
diff --git a/cras/src/server/cras_udev.c b/cras/src/server/cras_udev.c
index dc4c2dd..2ba1fcd 100644
--- a/cras/src/server/cras_udev.c
+++ b/cras/src/server/cras_udev.c
@@ -25,8 +25,8 @@
 	int fd;
 };
 
-static unsigned is_action(const char *desired, const char *actual)
-	__attribute__((nonnull(1)));
+static unsigned is_action(const char *desired,
+			  const char *actual) __attribute__((nonnull(1)));
 
 /* Matches Alsa sound device entries generated by udev.  For
  * example:
@@ -77,7 +77,7 @@
 static const char card_regex_string[] = "^.*/card([0-9]+)";
 static regex_t card_regex;
 
-static char const *const subsystem = "sound";
+static char const * const  subsystem = "sound";
 static const unsigned int MAX_DESC_NAME_LEN = 256;
 
 static unsigned is_action(const char *desired, const char *actual)
@@ -98,7 +98,8 @@
 static unsigned is_internal_bus(const char *bus)
 {
 	return (bus != NULL &&
-		(strcmp(bus, "pci") == 0 || strcmp(bus, "platform") == 0));
+		(strcmp(bus, "pci") == 0 ||
+		 strcmp(bus, "platform") == 0));
 }
 
 static unsigned is_external_bus(const char *bus)
@@ -123,17 +124,19 @@
 	return 0;
 }
 
-static unsigned is_card_device(struct udev_device *dev, unsigned *internal,
-			       unsigned *card_number, const char **sysname)
+static unsigned is_card_device(struct udev_device  *dev,
+			       unsigned		   *internal,
+			       unsigned		   *card_number,
+			       const char	   **sysname)
 {
 	regmatch_t m[2];
 	const char *devpath = udev_device_get_devpath(dev);
 
 	if (devpath != NULL &&
 	    regexec(&card_regex, devpath, ARRAY_SIZE(m), m, 0) == 0) {
-		*sysname = udev_device_get_sysname(dev);
-		*internal = is_internal_device(dev);
-		*card_number = (unsigned)atoi(&devpath[m[1].rm_so]);
+		*sysname       = udev_device_get_sysname(dev);
+		*internal      = is_internal_device(dev);
+		*card_number   = (unsigned)atoi(&devpath[m[1].rm_so]);
 		return 1;
 	}
 
@@ -152,8 +155,8 @@
 		syslog(LOG_INFO, "%s: init card '%u' to factory default",
 		       __FUNCTION__, card_number);
 		r = snprintf(cmd_buf, ARRAY_SIZE(cmd_buf),
-			     "%s --file %s restore %u", alsactl, asound_state,
-			     card_number);
+			     "%s --file %s restore %u",
+			     alsactl, asound_state, card_number);
 		cmd_buf[ARRAY_SIZE(cmd_buf) - 1] = '\0';
 		r = system(cmd_buf);
 		if (r != 0)
@@ -175,7 +178,7 @@
 	 *
 	 * will be produced by cras_alsa_card_create().
 	 */
-	usleep(125000); /* 0.125 second */
+	usleep(125000);		/* 0.125 second */
 }
 
 /* Reads the "descriptors" file of the usb device and returns the
@@ -198,15 +201,15 @@
 	}
 
 	if (stat(path, &stat_buf) < 0) {
-		syslog(LOG_ERR, "failed to stat file %s: %s", path,
-		       strerror(errno));
+		syslog(LOG_ERR, "failed to stat file %s: %s",
+		       path, strerror(errno));
 		return 0;
 	}
 
 	fd = open(path, O_RDONLY);
 	if (fd < 0) {
-		syslog(LOG_ERR, "failed to open file %s: %s", path,
-		       strerror(errno));
+		syslog(LOG_ERR, "failed to open file %s: %s",
+		       path, strerror(errno));
 		return 0;
 	}
 
@@ -219,8 +222,8 @@
 				buf_size *= 2;
 			uint8_t *new_buf = realloc(buf, buf_size);
 			if (new_buf == NULL) {
-				syslog(LOG_ERR, "no memory to read file %s",
-				       path);
+				syslog(LOG_ERR,
+				       "no memory to read file %s", path);
 				goto bail;
 			}
 			buf = new_buf;
@@ -250,7 +253,8 @@
 {
 	const char *sysattr;
 	struct udev_device *parent_dev =
-		udev_device_get_parent_with_subsystem_devtype(dev, "usb",
+		udev_device_get_parent_with_subsystem_devtype(dev,
+							      "usb",
 							      "usb_device");
 	if (!parent_dev)
 		return;
@@ -265,21 +269,22 @@
 	if (sysattr) {
 		strncpy(card_info->usb_serial_number, sysattr,
 			USB_SERIAL_NUMBER_BUFFER_SIZE - 1);
-		card_info->usb_serial_number[USB_SERIAL_NUMBER_BUFFER_SIZE - 1] =
-			'\0';
+		card_info->usb_serial_number[USB_SERIAL_NUMBER_BUFFER_SIZE - 1]
+			= '\0';
 	}
 
 	card_info->usb_desc_checksum = calculate_desc_checksum(parent_dev);
 
-	syslog(LOG_ERR,
-	       "USB card: vendor:%04x, product:%04x, serial num:%s, "
+	syslog(LOG_ERR, "USB card: vendor:%04x, product:%04x, serial num:%s, "
 	       "checksum:%08x",
-	       card_info->usb_vendor_id, card_info->usb_product_id,
-	       card_info->usb_serial_number, card_info->usb_desc_checksum);
+		card_info->usb_vendor_id, card_info->usb_product_id,
+		card_info->usb_serial_number, card_info->usb_desc_checksum);
 }
 
-static void device_add_alsa(struct udev_device *dev, const char *sysname,
-			    unsigned card, unsigned internal)
+static void device_add_alsa(struct udev_device *dev,
+			    const char *sysname,
+			    unsigned card,
+			    unsigned internal)
 {
 	struct cras_alsa_card_info card_info;
 	memset(&card_info, 0, sizeof(card_info));
@@ -322,9 +327,9 @@
 	/* If the device, 'dev' is an alsa device, add it to the set of
 	 * devices available for I/O.  Mark it as the active device.
 	 */
-	unsigned internal;
-	unsigned card_number;
-	const char *sysname;
+	unsigned	internal;
+	unsigned	card_number;
+	const char     *sysname;
 
 	if (is_card_device(dev, &internal, &card_number, &sysname) &&
 	    udev_sound_initialized(dev) &&
@@ -337,9 +342,9 @@
 
 static void remove_device_if_card(struct udev_device *dev)
 {
-	unsigned internal;
-	unsigned card_number;
-	const char *sysname;
+	unsigned	internal;
+	unsigned	card_number;
+	const char     *sysname;
 
 	if (is_card_device(dev, &internal, &card_number, &sysname))
 		device_remove_alsa(sysname, card_number);
@@ -347,7 +352,7 @@
 
 static void enumerate_devices(struct udev_callback_data *data)
 {
-	struct udev_enumerate *enumerate = udev_enumerate_new(data->udev);
+	struct udev_enumerate  *enumerate = udev_enumerate_new(data->udev);
 	struct udev_list_entry *dl;
 	struct udev_list_entry *dev_list_entry;
 
@@ -355,8 +360,7 @@
 	udev_enumerate_scan_devices(enumerate);
 	dl = udev_enumerate_get_list_entry(enumerate);
 
-	udev_list_entry_foreach(dev_list_entry, dl)
-	{
+	udev_list_entry_foreach(dev_list_entry, dl) {
 		const char *path = udev_list_entry_get_name(dev_list_entry);
 		struct udev_device *dev =
 			udev_device_new_from_syspath(data->udev, path);
@@ -384,8 +388,7 @@
 	} else
 		syslog(LOG_WARNING,
 		       "%s (internal error): "
-		       "No device obtained",
-		       __FUNCTION__);
+		       "No device obtained", __FUNCTION__);
 }
 
 static void compile_regex(regex_t *regex, const char *str)
@@ -408,8 +411,9 @@
 	udev_monitor_enable_receiving(udev_data.mon);
 	udev_data.fd = udev_monitor_get_fd(udev_data.mon);
 
-	r = cras_system_add_select_fd(
-		udev_data.fd, udev_sound_subsystem_callback, &udev_data);
+	r = cras_system_add_select_fd(udev_data.fd,
+				      udev_sound_subsystem_callback,
+				      &udev_data);
 	assert(r == 0);
 	compile_regex(&pcm_regex, pcm_regex_string);
 	compile_regex(&card_regex, card_regex_string);
diff --git a/cras/src/server/cras_utf8.c b/cras/src/server/cras_utf8.c
index ebb8a89..d3780d3 100644
--- a/cras/src/server/cras_utf8.c
+++ b/cras/src/server/cras_utf8.c
@@ -24,62 +24,79 @@
 static const u8range_t kUTF8TwoByteSeq[] = {
 	{ 0xc2, 0xdf },
 	{ 0x80, 0xbf },
-	{ 0, 0 },
+	{ 0, 0 }
 };
 
 static const u8range_t kUTF8ByteSeqE0[] = {
 	{ 0xe0, 0xe0 },
 	{ 0xa0, 0xbf },
 	{ 0x80, 0xbf },
-	{ 0, 0 },
+	{ 0, 0 }
 };
 
 static const u8range_t kUTF8ByteSeqE1EC[] = {
 	{ 0xe1, 0xec },
 	{ 0x80, 0xbf },
 	{ 0x80, 0xbf },
-	{ 0, 0 },
+	{ 0, 0 }
 };
 
 static const u8range_t kUTF8ByteSeqED[] = {
 	{ 0xed, 0xed },
 	{ 0x80, 0x9f },
 	{ 0x80, 0xbf },
-	{ 0, 0 },
+	{ 0, 0 }
 };
 
 static const u8range_t kUTF8ByteSeqEEEF[] = {
 	{ 0xee, 0xef },
 	{ 0x80, 0xbf },
 	{ 0x80, 0xbf },
-	{ 0, 0 },
+	{ 0, 0 }
 };
 
 static const u8range_t kUTF8ByteSeqF0[] = {
-	{ 0xf0, 0xf0 }, { 0x90, 0xbf }, { 0x80, 0xbf },
-	{ 0x80, 0xbf }, { 0, 0 },
+	{ 0xf0, 0xf0 },
+	{ 0x90, 0xbf },
+	{ 0x80, 0xbf },
+	{ 0x80, 0xbf },
+	{ 0, 0 }
 };
 
 static const u8range_t kUTF8ByteSeqF1F3[] = {
-	{ 0xf1, 0xf3 }, { 0x80, 0xbf }, { 0x80, 0xbf },
-	{ 0x80, 0xbf }, { 0, 0 },
+	{ 0xf1, 0xf3 },
+	{ 0x80, 0xbf },
+	{ 0x80, 0xbf },
+	{ 0x80, 0xbf },
+	{ 0, 0 }
 };
 
 static const u8range_t kUTF8ByteSeqF4[] = {
-	{ 0xf4, 0xf4 }, { 0x80, 0x8f }, { 0x80, 0xbf },
-	{ 0x80, 0xbf }, { 0, 0 },
+	{ 0xf4, 0xf4 },
+	{ 0x80, 0x8f },
+	{ 0x80, 0xbf },
+	{ 0x80, 0xbf },
+	{ 0, 0 }
 };
 
-static const u8range_t kUTF8NullRange[] = { { 0, 0 } };
+static const u8range_t kUTF8NullRange[] = {
+	{ 0, 0 }
+};
 
 typedef struct utf8seq {
 	const u8range_t *ranges;
 } utf8seq_t;
 
 static const utf8seq_t kUTF8Sequences[] = {
-	{ kUTF8TwoByteSeq },  { kUTF8ByteSeqE0 },   { kUTF8ByteSeqE1EC },
-	{ kUTF8ByteSeqED },   { kUTF8ByteSeqEEEF }, { kUTF8ByteSeqF0 },
-	{ kUTF8ByteSeqF1F3 }, { kUTF8ByteSeqF4 },   { kUTF8NullRange }
+	{ kUTF8TwoByteSeq },
+	{ kUTF8ByteSeqE0 },
+	{ kUTF8ByteSeqE1EC },
+	{ kUTF8ByteSeqED },
+	{ kUTF8ByteSeqEEEF },
+	{ kUTF8ByteSeqF0 },
+	{ kUTF8ByteSeqF1F3 },
+	{ kUTF8ByteSeqF4 },
+	{ kUTF8NullRange }
 };
 
 int valid_utf8_string(const char *string, size_t *bad_pos)
@@ -96,7 +113,7 @@
 		goto error;
 	}
 
-	while ((byte = (uint8_t) * (pos++))) {
+	while ((byte = (uint8_t)*(pos++))) {
 		if (!range || range->min == 0) {
 			if (byte < 128) {
 				/* Ascii character. */
@@ -112,8 +129,8 @@
 					 * Rewind and assume that there is
 					 * no BOM. */
 					bom_chars =
-						ARRAY_SIZE(kUTF8ByteOrderMask);
-					pos = string;
+					        ARRAY_SIZE(kUTF8ByteOrderMask);
+                                        pos = string;
 					continue;
 				}
 			}
@@ -153,8 +170,8 @@
 	}
 
 	if (range && range->min != 0) {
-		/* Stopped in the middle of a sequence. */
-		ret = 0;
+	        /* Stopped in the middle of a sequence. */
+	        ret = 0;
 	}
 
 error:
@@ -174,8 +191,7 @@
 
 #else
 
-int is_utf8_string(const char *string)
-{
+int is_utf8_string (const char *string) {
 	return valid_utf8_string(string, NULL);
 }
 
diff --git a/cras/src/server/cras_utf8.h b/cras/src/server/cras_utf8.h
index b4625fb..ab0fda0 100644
--- a/cras/src/server/cras_utf8.h
+++ b/cras/src/server/cras_utf8.h
@@ -33,4 +33,4 @@
  * Returns:
  *    1 if it is a valid utf-8 string. 0 otherwise.
  */
-int is_utf8_string(const char *string);
+int is_utf8_string(const char* string);
diff --git a/cras/src/server/cras_volume_curve.c b/cras/src/server/cras_volume_curve.c
index a866122..47ac6bd 100644
--- a/cras/src/server/cras_volume_curve.c
+++ b/cras/src/server/cras_volume_curve.c
@@ -49,8 +49,9 @@
 	return cras_volume_curve_create_simple_step(0, 50);
 }
 
-struct cras_volume_curve *cras_volume_curve_create_simple_step(long max_volume,
-							       long volume_step)
+struct cras_volume_curve *cras_volume_curve_create_simple_step(
+		long max_volume,
+		long volume_step)
 {
 	struct stepped_curve *curve;
 	curve = (struct stepped_curve *)calloc(1, sizeof(*curve));
@@ -62,8 +63,8 @@
 	return &curve->curve;
 }
 
-struct cras_volume_curve *
-cras_volume_curve_create_explicit(long dB_values[NUM_VOLUME_STEPS])
+struct cras_volume_curve *cras_volume_curve_create_explicit(
+		long dB_values[NUM_VOLUME_STEPS])
 {
 	struct explicit_curve *curve;
 	curve = (struct explicit_curve *)calloc(1, sizeof(*curve));
diff --git a/cras/src/server/cras_volume_curve.h b/cras/src/server/cras_volume_curve.h
index c3b0ee6..02b1cfe 100644
--- a/cras/src/server/cras_volume_curve.h
+++ b/cras/src/server/cras_volume_curve.h
@@ -33,8 +33,9 @@
  *    max_volume - Maximum volume allowed in dBFS.
  *    volume_step - Number of dB to change for one volume tick.
  */
-struct cras_volume_curve *
-cras_volume_curve_create_simple_step(long max_volume, long volume_step);
+struct cras_volume_curve *cras_volume_curve_create_simple_step(
+		long max_volume,
+		long volume_step);
 
 /* Creates a volume curve with each step's dB value called out.
  * Args:
@@ -45,8 +46,8 @@
  *    cras_volume_curve_destroy() when it is no longer needed. If there is an
  *    error NULL will be returned.
  */
-struct cras_volume_curve *
-cras_volume_curve_create_explicit(long dB_values[101]);
+struct cras_volume_curve *cras_volume_curve_create_explicit(
+		long dB_values[101]);
 
 /* Destroys a curve created with cras_volume_curve_create_*.
  * Args:
diff --git a/cras/src/server/dev_io.c b/cras/src/server/dev_io.c
index 97c61f9..f51e58a 100644
--- a/cras/src/server/dev_io.c
+++ b/cras/src/server/dev_io.c
@@ -4,12 +4,10 @@
  */
 
 #include <poll.h>
-#include <stdbool.h>
 #include <syslog.h>
 
 #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"
@@ -17,7 +15,6 @@
 #include "dev_stream.h"
 #include "input_data.h"
 #include "polled_interval_checker.h"
-#include "rate_estimator.h"
 #include "utlist.h"
 
 #include "dev_io.h"
@@ -35,20 +32,12 @@
  */
 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;
 
 /* Gets the master device which the stream is attached to. */
-static inline struct cras_iodev *get_master_dev(const struct dev_stream *stream)
+static inline
+struct cras_iodev *get_master_dev(const struct dev_stream *stream)
 {
 	return (struct cras_iodev *)stream->stream->master_dev.dev_ptr;
 }
@@ -62,18 +51,18 @@
 	struct cras_iodev *dev = adev->dev;
 	struct dev_stream *dev_stream;
 
-	DL_FOREACH (dev->streams, dev_stream) {
+	DL_FOREACH(dev->streams, dev_stream) {
 		master_dev = get_master_dev(dev_stream);
 		if (master_dev == NULL) {
 			syslog(LOG_ERR, "Fail to find master open dev.");
 			continue;
 		}
 
-		dev_stream_set_dev_rate(
-			dev_stream, dev->format->frame_rate,
-			cras_iodev_get_est_rate_ratio(dev),
-			cras_iodev_get_est_rate_ratio(master_dev),
-			adev->coarse_rate_adjust);
+		dev_stream_set_dev_rate(dev_stream,
+				dev->ext_format->frame_rate,
+				cras_iodev_get_est_rate_ratio(dev),
+				cras_iodev_get_est_rate_ratio(master_dev),
+				adev->coarse_rate_adjust);
 	}
 }
 
@@ -81,50 +70,28 @@
  * Counts the number of devices which are currently playing/capturing non-empty
  * audio.
  */
-static inline int count_non_empty_dev(struct open_dev *adevs)
-{
+static inline int count_non_empty_dev(struct open_dev *adevs) {
 	int count = 0;
 	struct open_dev *adev;
-	DL_FOREACH (adevs, adev) {
+	DL_FOREACH(adevs, adev) {
 		if (!adev->empty_pi || !pic_interval_elapsed(adev->empty_pi))
 			count++;
 	}
 	return count;
 }
 
-static void check_non_empty_state_transition(struct open_dev *adevs)
-{
+static void check_non_empty_state_transition(struct open_dev *adevs) {
 	int new_non_empty_dev_count = count_non_empty_dev(adevs);
 
 	// If we have transitioned to or from a state with 0 non-empty devices,
 	// notify the main thread to update system state.
 	if ((non_empty_device_count == 0) != (new_non_empty_dev_count == 0))
-		cras_non_empty_audio_send_msg(new_non_empty_dev_count > 0 ? 1 :
-									    0);
+		cras_non_empty_audio_send_msg(
+			new_non_empty_dev_count > 0 ? 1 : 0);
 
 	non_empty_device_count = new_non_empty_dev_count;
 }
 
-/* Checks whether it is time to fetch. */
-static bool is_time_to_fetch(const struct dev_stream *dev_stream,
-			     struct timespec now)
-{
-	const struct timespec *next_cb_ts;
-	next_cb_ts = dev_stream_next_cb_ts(dev_stream);
-	if (!next_cb_ts)
-		return 0;
-
-	/*
-	 * Check if it's time to get more data from this stream.
-	 * Allow for waking up a little early.
-	 */
-	add_timespecs(&now, &playback_wake_fuzz_ts);
-	if (timespec_after(&now, next_cb_ts))
-		return 1;
-
-	return 0;
-}
-
 /* Asks any stream with room for more data. Sets the time stamp for all streams.
  * Args:
  *    adev - The output device streams are attached to.
@@ -143,9 +110,11 @@
 	if (delay < 0)
 		return delay;
 
-	DL_FOREACH (adev->dev->streams, dev_stream) {
+	DL_FOREACH(adev->dev->streams, dev_stream) {
 		struct cras_rstream *rstream = dev_stream->stream;
-		struct cras_audio_shm *shm = cras_rstream_shm(rstream);
+		struct cras_audio_shm *shm =
+			cras_rstream_output_shm(rstream);
+		const struct timespec *next_cb_ts;
 		struct timespec now;
 
 		clock_gettime(CLOCK_MONOTONIC_RAW, &now);
@@ -156,36 +125,27 @@
 							   &now);
 		}
 
-		if (!dev_stream_is_running(dev_stream))
-			continue;
-
-		if (!is_time_to_fetch(dev_stream, now))
-			continue;
-
 		if (cras_shm_get_frames(shm) < 0)
 			cras_rstream_set_is_draining(rstream, 1);
 
 		if (cras_rstream_get_is_draining(dev_stream->stream))
 			continue;
 
-		/*
-		 * Skip fetching if client still has not replied yet.
-		 */
-		if (cras_rstream_is_pending_reply(rstream)) {
-			ATLOG(atlog, AUDIO_THREAD_STREAM_FETCH_PENDING,
-			      cras_rstream_id(rstream), 0, 0);
+		next_cb_ts = dev_stream_next_cb_ts(dev_stream);
+		if (!next_cb_ts)
 			continue;
-		}
 
-		/*
-		 * Skip fetching if there are enough frames in shared memory.
-		 */
-		if (!cras_shm_is_buffer_available(shm)) {
+		/* Check if it's time to get more data from this stream.
+		 * Allow for waking up a little early. */
+		add_timespecs(&now, &playback_wake_fuzz_ts);
+		if (!timespec_after(&now, next_cb_ts))
+			continue;
+
+		if (!dev_stream_can_fetch(dev_stream)) {
 			ATLOG(atlog, AUDIO_THREAD_STREAM_SKIP_CB,
 			      cras_rstream_id(rstream),
-			      shm->header->write_offset[0],
-			      shm->header->write_offset[1]);
-			dev_stream_update_next_wake_time(dev_stream);
+			      shm->area->write_offset[0],
+			      shm->area->write_offset[1]);
 			continue;
 		}
 
@@ -196,8 +156,8 @@
 
 		rc = dev_stream_request_playback_samples(dev_stream, &now);
 		if (rc < 0) {
-			syslog(LOG_ERR, "fetch err: %d for %x", rc,
-			       cras_rstream_id(rstream));
+			syslog(LOG_ERR, "fetch err: %d for %x",
+			       rc, cras_rstream_id(rstream));
 			cras_rstream_set_is_draining(rstream, 1);
 		}
 	}
@@ -212,7 +172,7 @@
 	int delay;
 	int max_delay = 0;
 
-	DL_FOREACH (adevs, adev) {
+	DL_FOREACH(adevs, adev) {
 		if (!cras_iodev_is_open(adev->dev))
 			continue;
 		delay = cras_iodev_delay_frames(adev->dev);
@@ -236,7 +196,7 @@
 	/* TODO(dgreid) - Setting delay from last dev only. */
 	delay = input_delay_frames(adev);
 
-	DL_FOREACH (adev->dev->streams, stream) {
+	DL_FOREACH(adev->dev->streams, stream) {
 		if (stream->stream->flags & TRIGGER_ONLY)
 			continue;
 
@@ -255,9 +215,10 @@
  *                        Output NULL if there is no stream that causes
  *                        capture limit less than the initial limit.
  */
-static unsigned int get_stream_limit(struct open_dev *adev,
-				     unsigned int write_limit,
-				     struct dev_stream **limit_stream)
+static unsigned int get_stream_limit(
+		struct open_dev *adev,
+		unsigned int write_limit,
+		struct dev_stream **limit_stream)
 {
 	struct cras_rstream *rstream;
 	struct cras_audio_shm *shm;
@@ -266,16 +227,16 @@
 
 	*limit_stream = NULL;
 
-	DL_FOREACH (adev->dev->streams, stream) {
+	DL_FOREACH(adev->dev->streams, stream) {
 		rstream = stream->stream;
 		if (rstream->flags & TRIGGER_ONLY)
 			continue;
 
-		shm = cras_rstream_shm(rstream);
+		shm = cras_rstream_input_shm(rstream);
 		if (cras_shm_check_write_overrun(shm))
 			ATLOG(atlog, AUDIO_THREAD_READ_OVERRUN,
 			      adev->dev->info.idx, rstream->stream_id,
-			      shm->header->num_overruns);
+			      shm->area->num_overruns);
 		avail = dev_stream_capture_avail(stream);
 		if (avail < write_limit) {
 			write_limit = avail;
@@ -303,22 +264,23 @@
  *
  * Returns: 0 on success negative error on device failure.
  */
-static int get_input_dev_max_wake_ts(struct open_dev *adev,
-				     unsigned int curr_level,
-				     struct timespec *res_ts)
+static int get_input_dev_max_wake_ts(
+	struct open_dev *adev,
+	unsigned int curr_level,
+	struct timespec *res_ts)
 {
 	struct timespec dev_wake_ts, now;
 	unsigned int dev_rate, half_buffer_size, target_frames;
 
-	if (!adev || !adev->dev || !adev->dev->format ||
-	    !adev->dev->format->frame_rate || !adev->dev->buffer_size)
+	if(!adev || !adev->dev || !adev->dev->format ||
+	   !adev->dev->format->frame_rate || !adev->dev->buffer_size)
 		return -EINVAL;
 
 	*res_ts = min_input_dev_wake_ts;
 
 	dev_rate = adev->dev->format->frame_rate;
 	half_buffer_size = adev->dev->buffer_size / 2;
-	if (curr_level < half_buffer_size)
+	if(curr_level < half_buffer_size)
 		target_frames = half_buffer_size - curr_level;
 	else
 		target_frames = 0;
@@ -334,31 +296,11 @@
 	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.
+ * dev_streams.
  */
-static int set_input_dev_wake_ts(struct open_dev *adev, bool *need_to_drop)
+static int set_input_dev_wake_ts(struct open_dev *adev)
 {
 	int rc;
 	struct timespec level_tstamp, wake_time_out, min_ts, now, dev_wake_ts;
@@ -371,8 +313,6 @@
 	min_ts.tv_nsec = 0;
 	clock_gettime(CLOCK_MONOTONIC_RAW, &now);
 	add_timespecs(&min_ts, &now);
-	/* Set default value for device wake_ts. */
-	adev->wake_ts = min_ts;
 
 	rc = cras_iodev_frames_queued(adev->dev, &level_tstamp);
 	if (rc < 0)
@@ -381,15 +321,6 @@
 	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);
 
@@ -397,11 +328,15 @@
 	 * Loop through streams to find the earliest time audio thread
 	 * should wake up.
 	 */
-	DL_FOREACH (adev->dev->streams, stream) {
+	DL_FOREACH(adev->dev->streams, stream) {
 		wake_time_out = min_ts;
-		rc = dev_stream_wake_time(stream, curr_level, &level_tstamp,
-					  cap_limit, cap_limit_stream == stream,
-					  &wake_time_out);
+		rc = dev_stream_wake_time(
+			stream,
+			curr_level,
+			&level_tstamp,
+			cap_limit,
+			cap_limit_stream == stream,
+			&wake_time_out);
 
 		/*
 		 * rc > 0 means there is no need to set wake up time for this
@@ -418,18 +353,14 @@
 		}
 	}
 
-	/* 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 &&
-	    cap_limit) {
+	if(adev->dev->active_node &&
+	   adev->dev->active_node->type != CRAS_NODE_TYPE_HOTWORD) {
 		rc = get_input_dev_max_wake_ts(adev, curr_level, &dev_wake_ts);
-		if (rc < 0) {
+		if(rc < 0) {
 			syslog(LOG_ERR,
 			       "Failed to call get_input_dev_max_wake_ts."
-			       "rc = %d",
-			       rc);
-		} else if (timespec_after(&min_ts, &dev_wake_ts)) {
+			       "rc = %d", rc);
+		} else if(timespec_after(&min_ts, &dev_wake_ts)) {
 			min_ts = dev_wake_ts;
 		}
 	}
@@ -452,7 +383,7 @@
 	struct dev_stream *cap_limit_stream;
 	struct dev_stream *stream;
 
-	DL_FOREACH (adev->dev->streams, stream)
+	DL_FOREACH(adev->dev->streams, stream)
 		dev_stream_flush_old_audio_messages(stream);
 
 	rc = cras_iodev_frames_queued(idev, &hw_tstamp);
@@ -480,8 +411,8 @@
 
 	remainder = MIN(hw_level, cap_limit);
 
-	ATLOG(atlog, AUDIO_THREAD_READ_AUDIO, idev->info.idx, hw_level,
-	      remainder);
+	ATLOG(atlog, AUDIO_THREAD_READ_AUDIO, idev->info.idx,
+	      hw_level, remainder);
 
 	if (cras_iodev_state(idev) != CRAS_IODEV_STATE_NORMAL_RUN)
 		return 0;
@@ -496,7 +427,7 @@
 		if (rc < 0 || nread == 0)
 			return rc;
 
-		DL_FOREACH (adev->dev->streams, stream) {
+		DL_FOREACH(adev->dev->streams, stream) {
 			unsigned int this_read;
 			unsigned int area_offset;
 			float software_gain_scaler;
@@ -505,35 +436,23 @@
 			    stream->stream->triggered)
 				continue;
 
-			input_data_get_for_stream(idev->input_data,
-						  stream->stream,
-						  idev->buf_state, &area,
-						  &area_offset);
+			input_data_get_for_stream(idev->input_data, stream->stream,
+						  idev->buf_state,
+						  &area, &area_offset);
 			/*
-			 * The software gain scaler consist of two parts:
-			 * (1) The device gain scaler used when lack of hardware
-			 * gain control. Configured by the DefaultNodeGain label
-			 * in alsa UCM config.
-			 * (2) The gain scaler in cras_rstream set by app, for
-			 * example the AGC module in Chrome.
-			 *
-			 * APM has more advanced gain control mechanism, we shall
-			 * give APM total control of the captured samples without
-			 * additional gain scaler at all.
+			 * APM has more advanced gain control mechanism, so
+			 * don't apply the CRAS software gain to this stream
+			 * if APM is used.
 			 */
-			software_gain_scaler =
-				stream->stream->apm_list ?
-					1.0f :
-					idev->software_gain_scaler *
-						cras_rstream_get_volume_scaler(
-							stream->stream);
+			software_gain_scaler = stream->stream->apm_list
+				? 1.0f
+				: cras_iodev_get_software_gain_scaler(idev);
 
-			this_read =
-				dev_stream_capture(stream, area, area_offset,
-						   software_gain_scaler);
+			this_read = dev_stream_capture(
+					stream, area, area_offset,
+					software_gain_scaler);
 
-			input_data_put_for_stream(idev->input_data,
-						  stream->stream,
+			input_data_put_for_stream(idev->input_data, stream->stream,
 						  idev->buf_state, this_read);
 		}
 
@@ -566,27 +485,25 @@
  *    This number of frames is the minimum of the amount of frames each stream
  *    could provide which is the maximum that can currently be rendered.
  */
-static int write_streams(struct open_dev **odevs, struct open_dev *adev,
-			 uint8_t *dst, size_t write_limit)
+static int write_streams(struct open_dev **odevs,
+			 struct open_dev *adev,
+			 uint8_t *dst,
+			 size_t write_limit)
 {
 	struct cras_iodev *odev = adev->dev;
 	struct dev_stream *curr;
 	unsigned int max_offset = 0;
-	unsigned int frame_bytes = cras_get_format_bytes(odev->format);
+	unsigned int frame_bytes = cras_get_format_bytes(odev->ext_format);
 	unsigned int num_playing = 0;
 	unsigned int drain_limit = write_limit;
 
 	/* Mix as much as we can, the minimum fill level of any stream. */
 	max_offset = cras_iodev_max_stream_offset(odev);
 
-	/* Mix as much as we can, the minimum fill level of any stream. */
-	DL_FOREACH (adev->dev->streams, curr) {
+        /* Mix as much as we can, the minimum fill level of any stream. */
+	DL_FOREACH(adev->dev->streams, curr) {
 		int dev_frames;
 
-		/* Skip stream which hasn't started running yet. */
-		if (!dev_stream_is_running(curr))
-			continue;
-
 		/* If this is a single output dev stream, updates the latest
 		 * number of frames for playback. */
 		if (dev_stream_attached_devs(curr) == 1)
@@ -594,7 +511,9 @@
 
 		dev_frames = dev_stream_playback_frames(curr);
 		if (dev_frames < 0) {
-			dev_io_remove_stream(odevs, curr->stream, NULL);
+			dev_io_remove_stream(
+				odevs,
+				curr->stream, NULL);
 			continue;
 		}
 		ATLOG(atlog, AUDIO_THREAD_WRITE_STREAMS_STREAM,
@@ -603,7 +522,9 @@
 		if (cras_rstream_get_is_draining(curr->stream)) {
 			drain_limit = MIN((size_t)dev_frames, drain_limit);
 			if (!dev_frames)
-				dev_io_remove_stream(odevs, curr->stream, NULL);
+				dev_io_remove_stream(
+					odevs,
+					curr->stream, NULL);
 		} else {
 			write_limit = MIN((size_t)dev_frames, write_limit);
 			num_playing++;
@@ -617,20 +538,17 @@
 		memset(dst + max_offset * frame_bytes, 0,
 		       (write_limit - max_offset) * frame_bytes);
 
-	ATLOG(atlog, AUDIO_THREAD_WRITE_STREAMS_MIX, write_limit, max_offset,
-	      0);
+	ATLOG(atlog, AUDIO_THREAD_WRITE_STREAMS_MIX,
+	      write_limit, max_offset, 0);
 
-	DL_FOREACH (adev->dev->streams, curr) {
+	DL_FOREACH(adev->dev->streams, curr) {
 		unsigned int offset;
 		int nwritten;
 
-		if (!dev_stream_is_running(curr))
-			continue;
-
 		offset = cras_iodev_stream_offset(odev, curr);
 		if (offset >= write_limit)
 			continue;
-		nwritten = dev_stream_mix(curr, odev->format,
+		nwritten = dev_stream_mix(curr, odev->ext_format,
 					  dst + frame_bytes * offset,
 					  write_limit - offset);
 
@@ -664,21 +582,23 @@
 	clock_gettime(CLOCK_MONOTONIC_RAW, &now);
 
 	frames_to_play_in_sleep = cras_iodev_frames_to_play_in_sleep(
-		adev->dev, hw_level, &adev->wake_ts);
+			adev->dev, hw_level, &adev->wake_ts);
 	if (!timespec_is_nonzero(&adev->wake_ts))
 		adev->wake_ts = now;
 
 	if (cras_iodev_state(adev->dev) == CRAS_IODEV_STATE_NORMAL_RUN)
 		cras_iodev_update_highest_hw_level(adev->dev, *hw_level);
 
-	est_rate = adev->dev->format->frame_rate *
-		   cras_iodev_get_est_rate_ratio(adev->dev);
+	est_rate = adev->dev->ext_format->frame_rate *
+			cras_iodev_get_est_rate_ratio(adev->dev);
 
-	ATLOG(atlog, AUDIO_THREAD_SET_DEV_WAKE, adev->dev->info.idx, *hw_level,
-	      frames_to_play_in_sleep);
+	ATLOG(atlog, AUDIO_THREAD_SET_DEV_WAKE, adev->dev->info.idx,
+	      *hw_level, frames_to_play_in_sleep);
 
-	cras_frames_to_time_precise(frames_to_play_in_sleep, est_rate,
-				    &sleep_time);
+	cras_frames_to_time_precise(
+			frames_to_play_in_sleep,
+			est_rate,
+			&sleep_time);
 
 	add_timespecs(&adev->wake_ts, &sleep_time);
 
@@ -687,7 +607,8 @@
 }
 
 /* Returns 0 on success negative error on device failure. */
-int write_output_samples(struct open_dev **odevs, struct open_dev *adev,
+int write_output_samples(struct open_dev **odevs,
+			 struct open_dev *adev,
 			 struct cras_fmt_conv *output_converter)
 {
 	struct cras_iodev *odev = adev->dev;
@@ -769,13 +690,14 @@
 		// If we were empty last iteration, or the sampling interval
 		// has elapsed, check for emptiness.
 		if (adev->empty_pi ||
-		    pic_interval_elapsed(adev->non_empty_check_pi)) {
+			pic_interval_elapsed(adev->non_empty_check_pi)) {
 			non_empty_ptr = &non_empty;
 			pic_interval_reset(adev->non_empty_check_pi);
 		}
 
-		rc = cras_iodev_put_output_buffer(
-			odev, dst, written, non_empty_ptr, output_converter);
+		rc = cras_iodev_put_output_buffer(odev, dst, written,
+						  non_empty_ptr,
+						  output_converter);
 
 		if (rc < 0)
 			return rc;
@@ -794,136 +716,56 @@
 				MIN_EMPTY_PERIOD_SEC);
 	}
 
-	ATLOG(atlog, AUDIO_THREAD_FILL_AUDIO_DONE, hw_level, total_written,
-	      odev->min_cb_level);
+	ATLOG(atlog, AUDIO_THREAD_FILL_AUDIO_DONE, hw_level,
+	      total_written, odev->min_cb_level);
 
 	return total_written;
 }
 
 /*
- * 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.
-	DL_FOREACH (idev_list, adev) {
+	DL_FOREACH(idev_list, adev) {
 		struct dev_stream *stream;
 
 		if (!cras_iodev_is_open(adev->dev))
 			continue;
 
 		/* Post samples to rstream if there are enough samples. */
-		DL_FOREACH (adev->dev->streams, stream) {
+		DL_FOREACH(adev->dev->streams, stream) {
 			dev_stream_capture_update_rstream(stream);
 		}
 
 		/* Set wake_ts for this device. */
-		rc = set_input_dev_wake_ts(adev, &need_to_drop);
+		rc = set_input_dev_wake_ts(adev);
 		if (rc < 0)
 			return rc;
 	}
 
-	if (need_to_drop)
-		dev_io_drop_samples(idev_list);
-
 	return 0;
 }
 
-static void handle_dev_err(int err_rc, struct open_dev **odevs,
-			   struct open_dev *adev)
+static void handle_dev_err(
+		int err_rc,
+		struct open_dev **odevs,
+		struct open_dev *adev)
 {
 	if (err_rc == -EPIPE) {
 		/* Handle severe underrun. */
-		ATLOG(atlog, AUDIO_THREAD_SEVERE_UNDERRUN, adev->dev->info.idx,
-		      0, 0);
+		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)
@@ -932,7 +774,7 @@
 	struct open_dev *adev;
 	int rc;
 
-	DL_FOREACH (idev_list, adev) {
+	DL_FOREACH(idev_list, adev) {
 		if (!cras_iodev_is_open(adev->dev))
 			continue;
 		rc = capture_to_streams(adev);
@@ -943,33 +785,11 @@
 	return 0;
 }
 
-/* If it is the time to fetch, start dev_stream. */
-static void dev_io_check_dev_stream_start(struct open_dev *adev)
-{
-	struct dev_stream *dev_stream;
-	struct timespec now;
-	clock_gettime(CLOCK_MONOTONIC_RAW, &now);
-
-	DL_FOREACH (adev->dev->streams, dev_stream) {
-		if (!is_time_to_fetch(dev_stream, now))
-			continue;
-		if (!dev_stream_is_running(dev_stream))
-			cras_iodev_start_stream(adev->dev, dev_stream);
-	}
-}
-
 void dev_io_playback_fetch(struct open_dev *odev_list)
 {
 	struct open_dev *adev;
 
-	/* Check whether it is the time to start dev_stream before fetching. */
-	DL_FOREACH (odev_list, adev) {
-		if (!cras_iodev_is_open(adev->dev))
-			continue;
-		dev_io_check_dev_stream_start(adev);
-	}
-
-	DL_FOREACH (odev_list, adev) {
+	DL_FOREACH(odev_list, adev) {
 		if (!cras_iodev_is_open(adev->dev))
 			continue;
 		fetch_streams(adev);
@@ -988,13 +808,13 @@
 	 * of all streams before starting write output samples. */
 	adev = *odevs;
 	if (adev && adev->next) {
-		DL_FOREACH (*odevs, adev) {
-			DL_FOREACH (adev->dev->streams, curr)
+		DL_FOREACH(*odevs, adev) {
+			DL_FOREACH(adev->dev->streams, curr)
 				dev_stream_update_frames(curr);
 		}
 	}
 
-	DL_FOREACH (*odevs, adev) {
+	DL_FOREACH(*odevs, adev) {
 		if (!cras_iodev_is_open(adev->dev))
 			continue;
 
@@ -1029,10 +849,10 @@
 			 */
 			if (hw_level <= total_written) {
 				ATLOG(atlog, AUDIO_THREAD_UNDERRUN,
-				      adev->dev->info.idx, hw_level,
-				      total_written);
+				      adev->dev->info.idx,
+				      hw_level, total_written);
 				rc = cras_iodev_output_underrun(adev->dev);
-				if (rc < 0) {
+				if(rc < 0) {
 					handle_dev_err(rc, odevs, adev);
 				} else {
 					update_dev_wakeup_time(adev, &hw_level);
@@ -1042,11 +862,11 @@
 	}
 
 	/* TODO(dgreid) - once per rstream, not once per dev_stream. */
-	DL_FOREACH (*odevs, adev) {
+	DL_FOREACH(*odevs, adev) {
 		struct dev_stream *stream;
 		if (!cras_iodev_is_open(adev->dev))
 			continue;
-		DL_FOREACH (adev->dev->streams, stream) {
+		DL_FOREACH(adev->dev->streams, stream) {
 			dev_stream_playback_update_rstream(stream);
 		}
 	}
@@ -1054,38 +874,10 @@
 	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);
@@ -1115,7 +907,7 @@
 	struct open_dev *adev;
 	int ret = 0; /* The total number of devices to wait on. */
 
-	DL_FOREACH (*idevs, adev) {
+	DL_FOREACH(*idevs, adev) {
 		if (input_adev_ignore_wake(adev))
 			continue;
 		ret++;
@@ -1128,102 +920,43 @@
 	return ret;
 }
 
-/* Fills the time that the next stream needs to be serviced. */
-static int get_next_stream_wake_from_list(struct dev_stream *streams,
-					  struct timespec *min_ts)
-{
-	struct dev_stream *dev_stream;
-	int ret = 0; /* The total number of streams to wait on. */
-
-	DL_FOREACH (streams, dev_stream) {
-		const struct timespec *next_cb_ts;
-
-		if (cras_rstream_get_is_draining(dev_stream->stream))
-			continue;
-
-		if (cras_rstream_is_pending_reply(dev_stream->stream))
-			continue;
-
-		next_cb_ts = dev_stream_next_cb_ts(dev_stream);
-		if (!next_cb_ts)
-			continue;
-
-		ATLOG(atlog, AUDIO_THREAD_STREAM_SLEEP_TIME,
-		      dev_stream->stream->stream_id, next_cb_ts->tv_sec,
-		      next_cb_ts->tv_nsec);
-		if (timespec_after(min_ts, next_cb_ts))
-			*min_ts = *next_cb_ts;
-		ret++;
-	}
-
-	return ret;
-}
-
-int dev_io_next_output_wake(struct open_dev **odevs, struct timespec *min_ts,
-			    const struct timespec *now)
-{
-	struct open_dev *adev;
-	int ret = 0;
-
-	DL_FOREACH (*odevs, adev)
-		ret += get_next_stream_wake_from_list(adev->dev->streams,
-						      min_ts);
-
-	DL_FOREACH (*odevs, adev) {
-		if (!cras_iodev_odev_should_wake(adev->dev))
-			continue;
-
-		ret++;
-		if (timespec_after(min_ts, &adev->wake_ts))
-			*min_ts = adev->wake_ts;
-	}
-
-	return ret;
-}
-
 struct open_dev *dev_io_find_open_dev(struct open_dev *odev_list,
-				      unsigned int dev_idx)
+				      const struct cras_iodev *dev)
 {
 	struct open_dev *odev;
-	DL_FOREACH (odev_list, odev)
-		if (odev->dev->info.idx == dev_idx)
+	DL_FOREACH(odev_list, odev)
+		if (odev->dev == dev)
 			return odev;
 	return NULL;
 }
 
-void dev_io_rm_open_dev(struct open_dev **odev_list, struct open_dev *dev_to_rm)
+void dev_io_rm_open_dev(struct open_dev **odev_list,
+			struct open_dev *dev_to_rm)
 {
 	struct open_dev *odev;
 	struct dev_stream *dev_stream;
 
 	/* Do nothing if dev_to_rm wasn't already in the active dev list. */
-	DL_FOREACH (*odev_list, odev) {
-		if (odev == dev_to_rm)
-			break;
-	}
+	odev = dev_io_find_open_dev(*odev_list, dev_to_rm->dev);
 	if (!odev)
 		return;
 
+
 	DL_DELETE(*odev_list, dev_to_rm);
 
 	/* Metrics logs the number of underruns of this device. */
 	cras_server_metrics_num_underruns(
 		cras_iodev_get_num_underruns(dev_to_rm->dev));
 
-	/* Metrics logs the delay of this device. */
-	cras_server_metrics_highest_device_delay(
-		dev_to_rm->dev->highest_hw_level,
-		dev_to_rm->dev->largest_cb_level, dev_to_rm->dev->direction);
-
 	/* Metrics logs the highest_hw_level of this device. */
-	cras_server_metrics_highest_hw_level(dev_to_rm->dev->highest_hw_level,
-					     dev_to_rm->dev->direction);
+	cras_server_metrics_highest_hw_level(
+		dev_to_rm->dev->highest_hw_level, dev_to_rm->dev->direction);
 
 	check_non_empty_state_transition(*odev_list);
 
 	ATLOG(atlog, AUDIO_THREAD_DEV_REMOVED, dev_to_rm->dev->info.idx, 0, 0);
 
-	DL_FOREACH (dev_to_rm->dev->streams, dev_stream) {
+	DL_FOREACH(dev_to_rm->dev->streams, dev_stream) {
 		cras_iodev_rm_stream(dev_to_rm->dev, dev_stream->stream);
 		dev_stream_destroy(dev_stream);
 	}
@@ -1245,163 +978,9 @@
 		dev_stream_destroy(out);
 }
 
-int dev_io_append_stream(struct open_dev **dev_list,
-			 struct cras_rstream *stream,
-			 struct cras_iodev **iodevs, unsigned int num_iodevs)
-{
-	struct open_dev *open_dev;
-	struct cras_iodev *dev;
-	struct dev_stream *out;
-	struct timespec init_cb_ts;
-	struct timespec extra_sleep;
-	const struct timespec *stream_ts;
-	unsigned int i;
-	bool cb_ts_set = false;
-	int level;
-	int rc = 0;
-
-	for (i = 0; i < num_iodevs; i++) {
-		DL_SEARCH_SCALAR(*dev_list, open_dev, dev, iodevs[i]);
-		if (!open_dev)
-			continue;
-
-		dev = iodevs[i];
-		DL_SEARCH_SCALAR(dev->streams, out, stream, stream);
-		if (out)
-			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.
-		 */
-		if ((stream->direction == CRAS_STREAM_INPUT) && !dev->streams) {
-			int num_flushed = dev->flush_buffer(dev);
-			if (num_flushed < 0) {
-				rc = num_flushed;
-				break;
-			}
-		}
-
-		/*
-		 * For output, if open device already has stream, get the earliest next
-		 * callback time from these streams to align with. Otherwise, check whether
-		 * there are remaining frames in the device. Set the initial callback time to
-		 * the time when hw_level of device is close to min_cb_level.
-		 * If next callback time is too far from now, it will block writing and
-		 * lower hardware level. Else if we fetch the new stream immediately, it
-		 * may cause device buffer level stack up.
-		 */
-		if (stream->direction == CRAS_STREAM_OUTPUT) {
-			DL_FOREACH (dev->streams, out) {
-				stream_ts = dev_stream_next_cb_ts(out);
-				if (stream_ts &&
-				    (!cb_ts_set ||
-				     timespec_after(&init_cb_ts, stream_ts))) {
-					init_cb_ts = *stream_ts;
-					cb_ts_set = true;
-				}
-			}
-			if (!cb_ts_set) {
-				level = cras_iodev_get_valid_frames(
-					dev, &init_cb_ts);
-				if (level < 0) {
-					syslog(LOG_ERR,
-					       "Failed to set output init_cb_ts, rc = %d",
-					       level);
-					rc = -EINVAL;
-					break;
-				}
-				level -= cras_frames_at_rate(
-					stream->format.frame_rate,
-					cras_rstream_get_cb_threshold(stream),
-					dev->format->frame_rate);
-				if (level < 0)
-					level = 0;
-				cras_frames_to_time(level,
-						    dev->format->frame_rate,
-						    &extra_sleep);
-				add_timespecs(&init_cb_ts, &extra_sleep);
-			}
-		} else {
-			/*
-			 * For input streams, because audio thread can calculate wake up time
-			 * 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;
-		}
-
-		out = dev_stream_create(stream, dev->info.idx, dev->format, dev,
-					&init_cb_ts);
-		if (!out) {
-			rc = -EINVAL;
-			break;
-		}
-
-		cras_iodev_add_stream(dev, out);
-
-		/*
-		 * For multiple inputs case, if the new stream is not the first
-		 * one to append, copy the 1st stream's offset to it so that
-		 * future read offsets can be aligned across all input streams
-		 * to avoid the deadlock scenario when multiple streams reading
-		 * from multiple devices.
-		 */
-		if ((stream->direction == CRAS_STREAM_INPUT) &&
-		    (dev->streams != out)) {
-			unsigned int offset =
-				cras_iodev_stream_offset(dev, dev->streams);
-			if (offset > stream->cb_threshold)
-				offset = stream->cb_threshold;
-			cras_iodev_stream_written(dev, out, offset);
-
-			offset = cras_rstream_dev_offset(dev->streams->stream,
-							 dev->info.idx);
-			if (offset > stream->cb_threshold)
-				offset = stream->cb_threshold;
-			cras_rstream_dev_offset_update(stream, offset,
-						       dev->info.idx);
-		}
-		ATLOG(atlog, AUDIO_THREAD_STREAM_ADDED, stream->stream_id,
-		      dev->info.idx, 0);
-	}
-
-	if (rc) {
-		DL_FOREACH (*dev_list, open_dev) {
-			dev = open_dev->dev;
-			DL_SEARCH_SCALAR(dev->streams, out, stream, stream);
-			if (!out)
-				continue;
-
-			cras_iodev_rm_stream(dev, stream);
-			dev_stream_destroy(out);
-		}
-	}
-
-	return rc;
-}
-
 int dev_io_remove_stream(struct open_dev **dev_list,
-			 struct cras_rstream *stream, struct cras_iodev *dev)
+			 struct cras_rstream *stream,
+			 struct cras_iodev *dev)
 {
 	struct open_dev *open_dev;
 	struct timespec delay;
@@ -1411,18 +990,19 @@
 	if (timespec_after(&stream->longest_fetch_interval,
 			   &stream->sleep_interval_ts)) {
 		subtract_timespecs(&stream->longest_fetch_interval,
-				   &stream->sleep_interval_ts, &delay);
-		fetch_delay_msec =
-			delay.tv_sec * 1000 + delay.tv_nsec / 1000000;
+				   &stream->sleep_interval_ts,
+				   &delay);
+		fetch_delay_msec = delay.tv_sec * 1000 +
+				   delay.tv_nsec / 1000000;
 		if (fetch_delay_msec)
 			cras_server_metrics_longest_fetch_delay(
-				fetch_delay_msec);
+					fetch_delay_msec);
 	}
 
 	ATLOG(atlog, AUDIO_THREAD_STREAM_REMOVED, stream->stream_id, 0, 0);
 
 	if (dev == NULL) {
-		DL_FOREACH (*dev_list, open_dev) {
+		DL_FOREACH(*dev_list, open_dev) {
 			delete_stream_from_dev(open_dev->dev, stream);
 		}
 	} else {
diff --git a/cras/src/server/dev_io.h b/cras/src/server/dev_io.h
index 3184e4c..83e16e0 100644
--- a/cras/src/server/dev_io.h
+++ b/cras/src/server/dev_io.h
@@ -16,10 +16,6 @@
 /*
  * 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.
@@ -27,8 +23,6 @@
  */
 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;
@@ -51,7 +45,8 @@
 			  struct cras_fmt_conv *output_converter);
 
 /* Only public for testing. */
-int write_output_samples(struct open_dev **odevs, struct open_dev *adev,
+int write_output_samples(struct open_dev **odevs,
+			 struct open_dev *adev,
 			 struct cras_fmt_conv *output_converter);
 
 /*
@@ -77,13 +72,6 @@
 int dev_io_next_input_wake(struct open_dev **idevs, struct timespec *min_ts);
 
 /*
- * Fills min_ts with the next time the system should wake to service output.
- * Returns the number of devices waiting.
- */
-int dev_io_next_output_wake(struct open_dev **odevs, struct timespec *min_ts,
-			    const struct timespec *now);
-
-/*
  * Removes a device from a list of devices.
  *    odev_list - A pointer to the list to modify.
  *    dev_to_rm - Find this device in the list and remove it.
@@ -93,15 +81,11 @@
 
 /* Returns a pointer to an open_dev if it is in the list, otherwise NULL. */
 struct open_dev *dev_io_find_open_dev(struct open_dev *odev_list,
-				      unsigned int dev_idx);
-
-/* Append a new stream to a specified set of iodevs. */
-int dev_io_append_stream(struct open_dev **dev_list,
-			 struct cras_rstream *stream,
-			 struct cras_iodev **iodevs, unsigned int num_iodevs);
+                                      const struct cras_iodev *dev);
 
 /* Remove a stream from the provided list of devices. */
 int dev_io_remove_stream(struct open_dev **dev_list,
-			 struct cras_rstream *stream, struct cras_iodev *dev);
+			 struct cras_rstream *stream,
+			 struct cras_iodev *dev);
 
 #endif /* DEV_IO_H_ */
diff --git a/cras/src/server/dev_stream.c b/cras/src/server/dev_stream.c
index 878bb8a..a625d58 100644
--- a/cras/src/server/dev_stream.c
+++ b/cras/src/server/dev_stream.c
@@ -11,9 +11,13 @@
 #include "dev_stream.h"
 #include "cras_audio_area.h"
 #include "cras_mix.h"
-#include "cras_server_metrics.h"
 #include "cras_shm.h"
 
+/*
+ * Sleep this much time past the buffer size to be sure at least
+ * the buffer size is captured when the audio thread wakes up.
+ */
+static const unsigned int capture_extra_sleep_frames = 20;
 /* Adjust device's sample rate by this step faster or slower. Used
  * to make sure multiple active device has stable buffer level.
  */
@@ -36,8 +40,7 @@
  */
 unsigned int max_frames_for_conversion(unsigned int stream_frames,
 				       unsigned int stream_rate,
-				       unsigned int device_rate)
-{
+				       unsigned int device_rate) {
 	/*
 	 * There are multiple temp buffers in the format converter,
 	 * which are all the same size. Some of these contain audio
@@ -46,24 +49,26 @@
 	 * enough to hold either.
 	 */
 	return MAX(
-		       // Number of stream frames does not require conversion.
-		       stream_frames,
-		       // Calculate corresponding number of frames at device rate.
-		       cras_frames_at_rate(stream_rate, stream_frames,
-					   device_rate))
-	       /*
-	        * Add 1 because the linear resampler's frame rate
-	        * conversion does this, and is used to calculate
-	        * how many frames to read from the device.
-	        * See linear_resampler_{in,out}_frames_to_{out,in}(..)
-	        */
-	       + 1;
+	    // Number of stream frames does not require conversion.
+	    stream_frames,
+	    // Calculate corresponding number of frames at device rate.
+	    cras_frames_at_rate(stream_rate,
+				stream_frames,
+				device_rate))
+			/*
+			 * Add 1 because the linear resampler's frame rate
+			 * conversion does this, and is used to calculate
+			 * how many frames to read from the device.
+			 * See linear_resampler_{in,out}_frames_to_{out,in}(..)
+			 */
+			+ 1;
 }
 
 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)
+				     void *dev_ptr,
+				     struct timespec *cb_ts)
 {
 	struct dev_stream *out;
 	struct cras_audio_format *stream_fmt = &stream->format;
@@ -75,25 +80,30 @@
 	out->dev_id = dev_id;
 	out->stream = stream;
 	out->dev_rate = dev_fmt->frame_rate;
-	out->is_running = 0;
 
 	max_frames = max_frames_for_conversion(stream->buffer_frames,
 					       stream_fmt->frame_rate,
 					       dev_fmt->frame_rate);
 
 	if (stream->direction == CRAS_STREAM_OUTPUT) {
-		rc = config_format_converter(&out->conv, stream->direction,
-					     stream_fmt, dev_fmt, max_frames);
+		rc = config_format_converter(&out->conv,
+					     stream->direction,
+					     stream_fmt,
+					     dev_fmt,
+					     max_frames);
 	} else {
 		/*
 		 * For input, take into account the stream specific processing
 		 * like AEC. Use the post processing format to configure format
 		 * converter.
 		 */
-		ofmt = cras_rstream_post_processing_format(stream, dev_ptr) ?:
-			       dev_fmt,
-		rc = config_format_converter(&out->conv, stream->direction,
-					     ofmt, stream_fmt, max_frames);
+		ofmt = cras_rstream_post_processing_format(
+				stream, dev_ptr) ? : dev_fmt,
+		rc = config_format_converter(&out->conv,
+					     stream->direction,
+					     ofmt,
+					     stream_fmt,
+					     max_frames);
 	}
 	if (rc) {
 		free(out);
@@ -102,15 +112,14 @@
 
 	ofmt = cras_fmt_conv_out_format(out->conv);
 
-	dev_frames =
-		(stream->direction == CRAS_STREAM_OUTPUT) ?
-			cras_fmt_conv_in_frames_to_out(out->conv,
-						       stream->buffer_frames) :
-			cras_fmt_conv_out_frames_to_in(out->conv,
-						       stream->buffer_frames);
+	dev_frames = (stream->direction == CRAS_STREAM_OUTPUT)
+		? cras_fmt_conv_in_frames_to_out(out->conv,
+						 stream->buffer_frames)
+		: cras_fmt_conv_out_frames_to_in(out->conv,
+						 stream->buffer_frames);
 
-	out->conv_buffer_size_frames =
-		2 * MAX(dev_frames, stream->buffer_frames);
+	out->conv_buffer_size_frames = 2 * MAX(dev_frames,
+					       stream->buffer_frames);
 
 	/* Create conversion buffer and area using the output format
 	 * of the format converter. Note that this format might not be
@@ -120,9 +129,19 @@
 	out->conv_area = cras_audio_area_create(ofmt->num_channels);
 
 	cras_frames_to_time(cras_rstream_get_cb_threshold(stream),
-			    stream_fmt->frame_rate, &stream->sleep_interval_ts);
+			    stream_fmt->frame_rate,
+			    &stream->sleep_interval_ts);
 	stream->next_cb_ts = *cb_ts;
 
+	if (stream->direction != CRAS_STREAM_OUTPUT) {
+		struct timespec extra_sleep;
+
+		cras_frames_to_time(capture_extra_sleep_frames,
+				    stream->format.frame_rate, &extra_sleep);
+		add_timespecs(&stream->next_cb_ts, &stream->sleep_interval_ts);
+		add_timespecs(&stream->next_cb_ts, &extra_sleep);
+	}
+
 	cras_rstream_dev_attach(stream, dev_id, dev_ptr);
 
 	return out;
@@ -140,27 +159,35 @@
 }
 
 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)
+			     unsigned int dev_rate,
+			     double dev_rate_ratio,
+			     double master_rate_ratio,
+			     int coarse_rate_adjust)
 {
 	if (dev_stream->dev_id == dev_stream->stream->master_dev.dev_id) {
-		cras_fmt_conv_set_linear_resample_rates(dev_stream->conv,
-							dev_rate, dev_rate);
+		cras_fmt_conv_set_linear_resample_rates(
+				dev_stream->conv,
+				dev_rate,
+				dev_rate);
 		cras_frames_to_time_precise(
 			cras_rstream_get_cb_threshold(dev_stream->stream),
 			dev_stream->stream->format.frame_rate * dev_rate_ratio,
 			&dev_stream->stream->sleep_interval_ts);
 	} else {
-		double new_rate =
-			dev_rate * dev_rate_ratio / master_rate_ratio +
-			coarse_rate_adjust_step * coarse_rate_adjust;
-		cras_fmt_conv_set_linear_resample_rates(dev_stream->conv,
-							dev_rate, new_rate);
+		double new_rate = dev_rate * dev_rate_ratio /
+				master_rate_ratio +
+				coarse_rate_adjust_step * coarse_rate_adjust;
+		cras_fmt_conv_set_linear_resample_rates(
+				dev_stream->conv,
+				dev_rate,
+				new_rate);
 	}
+
 }
 
 int dev_stream_mix(struct dev_stream *dev_stream,
-		   const struct cras_audio_format *fmt, uint8_t *dst,
+		   const struct cras_audio_format *fmt,
+		   uint8_t *dst,
 		   unsigned int num_to_write)
 {
 	struct cras_rstream *rstream = dev_stream->stream;
@@ -190,15 +217,17 @@
 	while (fr_written < num_to_write) {
 		unsigned int read_frames;
 		src = cras_rstream_get_readable_frames(
-			rstream, buffer_offset + fr_read, &frames);
+				rstream, buffer_offset + fr_read, &frames);
 		if (frames == 0)
 			break;
 		if (cras_fmt_conversion_needed(dev_stream->conv)) {
 			read_frames = frames;
 			dev_frames = cras_fmt_conv_convert_frames(
-				dev_stream->conv, src,
-				dev_stream->conv_buffer->bytes, &read_frames,
-				num_to_write - fr_written);
+					dev_stream->conv,
+					src,
+					dev_stream->conv_buffer->bytes,
+					&read_frames,
+					num_to_write - fr_written);
 			src = dev_stream->conv_buffer->bytes;
 		} else {
 			dev_frames = MIN(frames, num_to_write - fr_written);
@@ -213,7 +242,8 @@
 	}
 
 	cras_rstream_dev_offset_update(rstream, fr_read, dev_stream->dev_id);
-	ATLOG(atlog, AUDIO_THREAD_DEV_STREAM_MIX, fr_written, fr_read, 0);
+	ATLOG(atlog, AUDIO_THREAD_DEV_STREAM_MIX,
+				    fr_written, fr_read, 0);
 
 	return fr_written;
 }
@@ -248,8 +278,11 @@
 
 		read_frames = num_frames - total_read;
 		write_frames = cras_fmt_conv_convert_frames(
-			dev_stream->conv, source_samples, buffer, &read_frames,
-			write_frames);
+				dev_stream->conv,
+				source_samples,
+				buffer,
+				&read_frames,
+				write_frames);
 		total_read += read_frames;
 		source_samples += read_frames * source_frame_bytes;
 		buf_increment_write(dev_stream->conv_buffer,
@@ -261,10 +294,10 @@
 
 /* Copy from the converted buffer to the stream shm.  These have the same format
  * at this point. */
-static unsigned int
-capture_copy_converted_to_stream(struct dev_stream *dev_stream,
-				 struct cras_rstream *rstream,
-				 float software_gain_scaler)
+static unsigned int capture_copy_converted_to_stream(
+		struct dev_stream *dev_stream,
+		struct cras_rstream *rstream,
+		float software_gain_scaler)
 {
 	struct cras_audio_shm *shm;
 	uint8_t *stream_samples;
@@ -276,7 +309,7 @@
 	unsigned int offset;
 	const struct cras_audio_format *fmt;
 
-	shm = cras_rstream_shm(rstream);
+	shm = cras_rstream_input_shm(rstream);
 
 	fmt = cras_fmt_conv_out_format(dev_stream->conv);
 	frame_bytes = cras_get_format_bytes(fmt);
@@ -284,30 +317,38 @@
 	offset = cras_rstream_dev_offset(rstream, dev_stream->dev_id);
 
 	stream_samples = cras_shm_get_writeable_frames(
-		shm, cras_rstream_get_cb_threshold(rstream),
-		&rstream->audio_area->frames);
+			shm,
+			cras_rstream_get_cb_threshold(rstream),
+			&rstream->audio_area->frames);
 	num_frames = MIN(rstream->audio_area->frames - offset,
-			 buf_queued(dev_stream->conv_buffer) / frame_bytes);
+			 buf_queued(dev_stream->conv_buffer) /
+							frame_bytes);
 
-	ATLOG(atlog, AUDIO_THREAD_CONV_COPY, shm->header->write_buf_idx,
-	      rstream->audio_area->frames, offset);
+	ATLOG(atlog, AUDIO_THREAD_CONV_COPY,
+				    shm->area->write_buf_idx,
+				    rstream->audio_area->frames,
+				    offset);
 
 	while (total_written < num_frames) {
-		converted_samples = buf_read_pointer_size(
-			dev_stream->conv_buffer, &write_frames);
+		converted_samples =
+			buf_read_pointer_size(dev_stream->conv_buffer,
+					      &write_frames);
 		write_frames /= frame_bytes;
 		write_frames = MIN(write_frames, num_frames - total_written);
 
-		cras_audio_area_config_buf_pointers(dev_stream->conv_area, fmt,
+		cras_audio_area_config_buf_pointers(dev_stream->conv_area,
+						    fmt,
 						    converted_samples);
 		cras_audio_area_config_channels(dev_stream->conv_area, fmt);
 		dev_stream->conv_area->frames = write_frames;
 
-		cras_audio_area_config_buf_pointers(
-			rstream->audio_area, &rstream->format, stream_samples);
+		cras_audio_area_config_buf_pointers(rstream->audio_area,
+						    &rstream->format,
+						    stream_samples);
 
 		cras_audio_area_copy(rstream->audio_area, offset,
-				     &rstream->format, dev_stream->conv_area, 0,
+				     &rstream->format,
+				     dev_stream->conv_area, 0,
 				     software_gain_scaler);
 
 		buf_increment_read(dev_stream->conv_buffer,
@@ -318,15 +359,17 @@
 		offset = cras_rstream_dev_offset(rstream, dev_stream->dev_id);
 	}
 
-	ATLOG(atlog, AUDIO_THREAD_CAPTURE_WRITE, rstream->stream_id,
-	      total_written, cras_shm_frames_written(shm));
+	ATLOG(atlog, AUDIO_THREAD_CAPTURE_WRITE,
+				    rstream->stream_id,
+				    total_written,
+				    cras_shm_frames_written(shm));
 	return total_written;
 }
 
 unsigned int dev_stream_capture(struct dev_stream *dev_stream,
-				const struct cras_audio_area *area,
-				unsigned int area_offset,
-				float software_gain_scaler)
+			const struct cras_audio_area *area,
+			unsigned int area_offset,
+			float software_gain_scaler)
 {
 	struct cras_rstream *rstream = dev_stream->stream;
 	struct cras_audio_shm *shm;
@@ -341,7 +384,7 @@
 		fr_to_capture = MIN(fr_to_capture, area->frames - area_offset);
 
 		format_bytes = cras_get_format_bytes(
-			cras_fmt_conv_in_format(dev_stream->conv));
+				cras_fmt_conv_in_format(dev_stream->conv));
 		nread = capture_with_fmt_conv(
 			dev_stream,
 			area->channels[0].buf + area_offset * format_bytes,
@@ -354,19 +397,24 @@
 			cras_rstream_dev_offset(rstream, dev_stream->dev_id);
 
 		/* Set up the shm area and copy to it. */
-		shm = cras_rstream_shm(rstream);
+		shm = cras_rstream_input_shm(rstream);
 		stream_samples = cras_shm_get_writeable_frames(
-			shm, cras_rstream_get_cb_threshold(rstream),
-			&rstream->audio_area->frames);
-		cras_audio_area_config_buf_pointers(
-			rstream->audio_area, &rstream->format, stream_samples);
+				shm,
+				cras_rstream_get_cb_threshold(rstream),
+				&rstream->audio_area->frames);
+		cras_audio_area_config_buf_pointers(rstream->audio_area,
+						    &rstream->format,
+						    stream_samples);
 
 		nread = cras_audio_area_copy(rstream->audio_area, offset,
 					     &rstream->format, area,
-					     area_offset, software_gain_scaler);
+					     area_offset,
+					     software_gain_scaler);
 
-		ATLOG(atlog, AUDIO_THREAD_CAPTURE_WRITE, rstream->stream_id,
-		      nread, cras_shm_frames_written(shm));
+		ATLOG(atlog, AUDIO_THREAD_CAPTURE_WRITE,
+					    rstream->stream_id,
+					    nread,
+					    cras_shm_frames_written(shm));
 		cras_rstream_dev_offset_update(rstream, nread,
 					       dev_stream->dev_id);
 	}
@@ -423,7 +471,7 @@
 	unsigned int dev_offset =
 		cras_rstream_dev_offset(rstream, dev_stream->dev_id);
 
-	shm = cras_rstream_shm(rstream);
+	shm = cras_rstream_input_shm(rstream);
 
 	wlimit = cras_rstream_get_max_write_frames(rstream);
 	wlimit -= dev_offset;
@@ -433,19 +481,20 @@
 		return frames_avail;
 
 	format_bytes = cras_get_format_bytes(
-		cras_fmt_conv_out_format(dev_stream->conv));
+			cras_fmt_conv_out_format(dev_stream->conv));
 
 	/* Sample rate conversion may cause some sample left in conv_buffer
 	 * take this buffer into account. */
-	conv_buf_level = buf_queued(dev_stream->conv_buffer) / format_bytes;
+	conv_buf_level = buf_queued(dev_stream->conv_buffer) /
+			format_bytes;
 	if (frames_avail <= conv_buf_level)
 		return 0;
 	else
 		frames_avail -= conv_buf_level;
 
-	frames_avail =
-		MIN(frames_avail,
-		    buf_available(dev_stream->conv_buffer) / format_bytes);
+	frames_avail = MIN(frames_avail,
+			   buf_available(dev_stream->conv_buffer) /
+					format_bytes);
 
 	return cras_fmt_conv_out_frames_to_in(dev_stream->conv, frames_avail);
 }
@@ -461,33 +510,9 @@
 		rstream->next_cb_ts = now;
 		add_timespecs(&rstream->next_cb_ts,
 			      &rstream->sleep_interval_ts);
-		ATLOG(atlog, AUDIO_THREAD_STREAM_RESCHEDULE, rstream->stream_id,
-		      rstream->next_cb_ts.tv_sec, rstream->next_cb_ts.tv_nsec);
-		cras_server_metrics_missed_cb_event(rstream);
 	}
 }
 
-void dev_stream_update_next_wake_time(struct dev_stream *dev_stream)
-{
-	struct cras_rstream *rstream = dev_stream->stream;
-
-	/*
-	 * The empty next_cb_ts means it is the first time update for input stream.
-	 * Initialize next_cb_ts without recording missed callback.
-	 */
-	if (rstream->direction == CRAS_STREAM_INPUT &&
-	    !timespec_is_nonzero(&rstream->next_cb_ts)) {
-		clock_gettime(CLOCK_MONOTONIC_RAW, &rstream->next_cb_ts);
-		add_timespecs(&rstream->next_cb_ts,
-			      &rstream->sleep_interval_ts);
-		return;
-	}
-	/* Update next callback time according to perfect schedule. */
-	add_timespecs(&rstream->next_cb_ts, &rstream->sleep_interval_ts);
-	/* Reset schedule if the schedule is missed. */
-	check_next_wake_time(dev_stream);
-}
-
 int dev_stream_playback_update_rstream(struct dev_stream *dev_stream)
 {
 	cras_rstream_update_output_read_pointer(dev_stream->stream);
@@ -530,8 +555,10 @@
 	if (rstream->flags & BULK_AUDIO_OK)
 		frames_ready = cras_rstream_level(rstream);
 
-	ATLOG(atlog, AUDIO_THREAD_CAPTURE_POST, rstream->stream_id,
-	      frames_ready, rstream->shm->header->read_buf_idx);
+	ATLOG(atlog, AUDIO_THREAD_CAPTURE_POST,
+				    rstream->stream_id,
+				    frames_ready,
+				    rstream->shm.area->read_buf_idx);
 
 	rc = cras_rstream_audio_ready(rstream, frames_ready);
 
@@ -541,12 +568,17 @@
 	if (rstream->flags & TRIGGER_ONLY)
 		rstream->triggered = 1;
 
-	dev_stream_update_next_wake_time(dev_stream);
+	/* Update next callback time according to perfect schedule. */
+	add_timespecs(&rstream->next_cb_ts,
+		      &rstream->sleep_interval_ts);
+	/* Reset schedule if the schedule is missed. */
+	check_next_wake_time(dev_stream);
 
 	return 0;
 }
 
-void cras_set_playback_timestamp(size_t frame_rate, size_t frames,
+void cras_set_playback_timestamp(size_t frame_rate,
+				 size_t frames,
 				 struct cras_timespec *ts)
 {
 	cras_clock_gettime(CLOCK_MONOTONIC_RAW, ts);
@@ -561,7 +593,8 @@
 	}
 }
 
-void cras_set_capture_timestamp(size_t frame_rate, size_t frames,
+void cras_set_capture_timestamp(size_t frame_rate,
+				size_t frames,
 				struct cras_timespec *ts)
 {
 	long tmp;
@@ -593,34 +626,50 @@
 	unsigned int stream_frames;
 
 	if (rstream->direction == CRAS_STREAM_OUTPUT) {
-		shm = cras_rstream_shm(rstream);
+		shm = cras_rstream_output_shm(rstream);
 		stream_frames = cras_fmt_conv_out_frames_to_in(dev_stream->conv,
 							       delay_frames);
 		cras_set_playback_timestamp(rstream->format.frame_rate,
 					    stream_frames +
-						    cras_shm_get_frames(shm),
-					    &shm->header->ts);
+						cras_shm_get_frames(shm),
+					    &shm->area->ts);
 	} else {
-		shm = cras_rstream_shm(rstream);
+		shm = cras_rstream_input_shm(rstream);
 		stream_frames = cras_fmt_conv_in_frames_to_out(dev_stream->conv,
 							       delay_frames);
 		if (cras_shm_frames_written(shm) == 0)
-			cras_set_capture_timestamp(rstream->format.frame_rate,
-						   stream_frames,
-						   &shm->header->ts);
+			cras_set_capture_timestamp(
+					rstream->format.frame_rate,
+					stream_frames,
+					&shm->area->ts);
 	}
 }
 
+int dev_stream_can_fetch(struct dev_stream *dev_stream)
+{
+	struct cras_rstream *rstream = dev_stream->stream;
+	struct cras_audio_shm *shm;
+
+	shm = cras_rstream_output_shm(rstream);
+
+	/* Don't fetch if the previous request hasn't got response. */
+	return !cras_rstream_is_pending_reply(rstream) &&
+	       cras_shm_is_buffer_available(shm);
+}
+
 int dev_stream_request_playback_samples(struct dev_stream *dev_stream,
 					const struct timespec *now)
 {
+	struct cras_rstream *rstream = dev_stream->stream;
 	int rc;
 
 	rc = cras_rstream_request_audio(dev_stream->stream, now);
 	if (rc < 0)
 		return rc;
 
-	dev_stream_update_next_wake_time(dev_stream);
+	add_timespecs(&rstream->next_cb_ts,
+		      &rstream->sleep_interval_ts);
+	check_next_wake_time(dev_stream);
 
 	return 0;
 }
@@ -653,7 +702,8 @@
 static int get_input_wake_time(struct dev_stream *dev_stream,
 			       unsigned int curr_level,
 			       struct timespec *level_tstamp,
-			       unsigned int cap_limit, int is_cap_limit_stream,
+			       unsigned int cap_limit,
+			       int is_cap_limit_stream,
 			       struct timespec *wake_time_out)
 {
 	struct cras_rstream *rstream = dev_stream->stream;
@@ -702,7 +752,7 @@
 	 *
 	 */
 	if ((rstream->flags & USE_DEV_TIMING) &&
-	    cras_rstream_is_pending_reply(rstream))
+	     cras_rstream_is_pending_reply(rstream))
 		return 1;
 
 	*wake_time_out = rstream->next_cb_ts;
@@ -716,7 +766,8 @@
 	else
 		needed_frames_from_device -= curr_level;
 
-	cras_frames_to_time(needed_frames_from_device, dev_stream->dev_rate,
+	cras_frames_to_time(needed_frames_from_device,
+			    dev_stream->dev_rate,
 			    &time_for_sample);
 
 	add_timespecs(&time_for_sample, level_tstamp);
@@ -724,20 +775,18 @@
 	/* Select the time that is later so both sample and time conditions
 	 * are met. */
 	if (timespec_after(&time_for_sample, &rstream->next_cb_ts))
-		*wake_time_out = time_for_sample;
+		*wake_time_out =  time_for_sample;
 	/* Using device timing means the stream neglects next callback time. */
 	if (rstream->flags & USE_DEV_TIMING)
-		*wake_time_out = time_for_sample;
-
-	ATLOG(atlog, AUDIO_THREAD_STREAM_SLEEP_TIME,
-	      dev_stream->stream->stream_id, wake_time_out->tv_sec,
-	      wake_time_out->tv_nsec);
+		*wake_time_out =  time_for_sample;
 
 	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 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)
 {
diff --git a/cras/src/server/dev_stream.h b/cras/src/server/dev_stream.h
index c39a801..52838f0 100644
--- a/cras/src/server/dev_stream.h
+++ b/cras/src/server/dev_stream.h
@@ -29,10 +29,6 @@
  *    conv_buffer_size_frames - Size of conv_buffer in frames.
  *    dev_rate - Sampling rate of device. This is set when dev_stream is
  *               created.
- *    is_running - For input stream, it should be set to true after it is added
- *                 into device. For output stream, it should be set to true
- *                 just before its first fetch to avoid affecting other existing
- *                 streams.
  */
 struct dev_stream {
 	unsigned int dev_id;
@@ -43,7 +39,6 @@
 	unsigned int conv_buffer_size_frames;
 	size_t dev_rate;
 	struct dev_stream *prev, *next;
-	int is_running;
 };
 
 struct dev_stream *dev_stream_create(struct cras_rstream *stream,
@@ -68,8 +63,10 @@
  *        sample rate should adjust to.
  */
 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);
+			     unsigned int dev_rate,
+			     double dev_rate_ratio,
+			     double master_rate_ratio,
+			     int coarse_rate_adjust);
 
 /*
  * Renders count frames from shm into dst.  Updates count if anything is
@@ -81,7 +78,8 @@
  *    num_to_write - The number of frames written.
  */
 int dev_stream_mix(struct dev_stream *dev_stream,
-		   const struct cras_audio_format *fmt, uint8_t *dst,
+		   const struct cras_audio_format *fmt,
+		   uint8_t *dst,
 		   unsigned int num_to_write);
 
 /*
@@ -93,9 +91,9 @@
  *    software_gain_scaler - The software gain scaler.
  */
 unsigned int dev_stream_capture(struct dev_stream *dev_stream,
-				const struct cras_audio_area *area,
-				unsigned int area_offset,
-				float software_gain_scaler);
+			const struct cras_audio_area *area,
+			unsigned int area_offset,
+			float software_gain_scaler);
 
 /* Returns the number of iodevs this stream has attached to. */
 int dev_stream_attached_devs(const struct dev_stream *dev_stream);
@@ -122,9 +120,6 @@
  */
 unsigned int dev_stream_cb_threshold(const struct dev_stream *dev_stream);
 
-/* Update next callback time for the stream. */
-void dev_stream_update_next_wake_time(struct dev_stream *dev_stream);
-
 /*
  * If enough samples have been captured, post them to the client.
  * TODO(dgreid) - see if this function can be eliminated.
@@ -135,11 +130,13 @@
 int dev_stream_playback_update_rstream(struct dev_stream *dev_stream);
 
 /* Fill ts with the time the playback sample will be played. */
-void cras_set_playback_timestamp(size_t frame_rate, size_t frames,
+void cras_set_playback_timestamp(size_t frame_rate,
+				 size_t frames,
 				 struct cras_timespec *ts);
 
 /* Fill ts with the time the capture sample was recorded. */
-void cras_set_capture_timestamp(size_t frame_rate, size_t frames,
+void cras_set_capture_timestamp(size_t frame_rate,
+				size_t frames,
 				struct cras_timespec *ts);
 
 /* Fill shm ts with the time the playback sample will be played or the capture
@@ -151,6 +148,9 @@
 void dev_stream_set_delay(const struct dev_stream *dev_stream,
 			  unsigned int delay_frames);
 
+/* Returns if it's okay to request playback samples for this stream. */
+int dev_stream_can_fetch(struct dev_stream *dev_stream);
+
 /* Ask the client for cb_threshold samples of audio to play. */
 int dev_stream_request_playback_samples(struct dev_stream *dev_stream,
 					const struct timespec *now);
@@ -171,8 +171,10 @@
  *   0 on success; negative error code on failure.
  *   A positive value if there is no need to set wake up time for this stream.
  */
-int dev_stream_wake_time(struct dev_stream *dev_stream, unsigned int curr_level,
-			 struct timespec *level_tstamp, unsigned int cap_limit,
+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);
 
@@ -182,18 +184,8 @@
  */
 int dev_stream_poll_stream_fd(const struct dev_stream *dev_stream);
 
-static inline int dev_stream_is_running(struct dev_stream *dev_stream)
-{
-	return dev_stream->is_running;
-}
-
-static inline void dev_stream_set_running(struct dev_stream *dev_stream)
-{
-	dev_stream->is_running = 1;
-}
-
 static inline const struct timespec *
-dev_stream_next_cb_ts(const struct dev_stream *dev_stream)
+dev_stream_next_cb_ts(struct dev_stream *dev_stream)
 {
 	if (dev_stream->stream->flags & USE_DEV_TIMING)
 		return NULL;
diff --git a/cras/src/server/float_buffer.h b/cras/src/server/float_buffer.h
index 39a0187..55e176e 100644
--- a/cras/src/server/float_buffer.h
+++ b/cras/src/server/float_buffer.h
@@ -26,8 +26,9 @@
  *    max_size - The max number of frames this buffer may store.
  *    num_channels - Number of channels of the deinterleaved data.
  */
-static inline struct float_buffer *
-float_buffer_create(unsigned int max_size, unsigned int num_channels)
+static inline struct float_buffer *float_buffer_create(
+		unsigned int max_size,
+		unsigned int num_channels)
 {
 	struct float_buffer *b;
 
@@ -35,9 +36,9 @@
 
 	b->num_channels = num_channels;
 	b->fp = (float **)malloc(num_channels * sizeof(float *));
-	b->buf = (struct byte_buffer *)calloc(
-		1, sizeof(struct byte_buffer) +
-			   max_size * num_channels * sizeof(float));
+	b->buf = (struct byte_buffer *)
+		calloc(1, sizeof(struct byte_buffer) +
+			max_size * num_channels * sizeof(float));
 	b->buf->max_size = max_size;
 	b->buf->used_size = max_size;
 	return b;
@@ -118,7 +119,8 @@
 }
 
 /* Marks |nread| frames as read in float_buffer. */
-static inline void float_buffer_read(struct float_buffer *b, unsigned int nread)
+static inline void float_buffer_read(struct float_buffer *b,
+				     unsigned int nread)
 {
 	buf_increment_read(b->buf, nread);
 }
diff --git a/cras/src/server/input_data.c b/cras/src/server/input_data.c
index b52c166..a790e11 100644
--- a/cras/src/server/input_data.c
+++ b/cras/src/server/input_data.c
@@ -15,7 +15,8 @@
 #include "input_data.h"
 #include "utlist.h"
 
-void input_data_run(struct ext_dsp_module *ext, unsigned int nframes)
+void input_data_run(struct ext_dsp_module *ext,
+		    unsigned int nframes)
 {
 	struct input_data *data = (struct input_data *)ext;
 	float *const *wp;
@@ -27,14 +28,12 @@
 		writable = float_buffer_writable(data->fbuffer);
 		writable = MIN(nframes, writable);
 		if (!writable) {
-			syslog(LOG_ERR,
-			       "Not enough space to process input data");
+			syslog(LOG_ERR, "Not enough space to process input data");
 			break;
 		}
 		wp = float_buffer_write_pointer(data->fbuffer);
 		for (i = 0; i < data->fbuffer->num_channels; i++)
-			memcpy(wp[i], ext->ports[i] + offset,
-			       writable * sizeof(float));
+			memcpy(wp[i], ext->ports[i] + offset, writable * sizeof(float));
 
 		float_buffer_written(data->fbuffer, writable);
 		nframes -= writable;
@@ -79,8 +78,7 @@
 		return;
 
 	if (float_buffer_level(data->fbuffer) < nframes) {
-		syslog(LOG_ERR,
-		       "All streams read %u frames exceeds %u"
+		syslog(LOG_ERR, "All streams read %u frames exceeds %u"
 		       " in input_data's buffer",
 		       nframes, float_buffer_level(data->fbuffer));
 		float_buffer_reset(data->fbuffer);
@@ -89,100 +87,48 @@
 	float_buffer_read(data->fbuffer, nframes);
 }
 
-/*
- * The logic is not trivial to return the cras_audio_area and offset for
- * a input stream to read. The buffer position and length of a bunch of
- * input member variables are described below.
- *
- *                          hw_ptr                 appl_ptr
- * a. buffer of input device: |------------------------|
- * b. fbuffer of input data:         |<--------------->|
- * c. stream offset of input data:         |<--------->|
- *    stream offset of input data:                |<-->|
- *    stream offset of input data:     |<------------->|
- * d. audio area of input data:          |<----------->|
- *
- * One thing to keep in mind is, the offset could exceed the size of
- * buffer to read. It's not intuitive though why the stream offset would
- * exceed buffer size. Check this example:
- *
- * Idev gets input buffer 500 frames. One stream read 400, while the other
- * stream read 100. We track stream offset [0, 300] after both stream
- * consumes 100 frames. In the next wake up, audio thread asks idev to
- * get 250 frames. Now the input data holds audio area containing 250 frames
- * of audio as queried, while its float buffer contains 400 frames of audio
- * deinterleaved from last wake up.
- *
- * Wake up at T0:
- *                        hw_ptr                        appl_ptr
- * Input audio area         |-------------------------------|
- * deinterleave float       |-------------------------------|
- * Stream 1 read                                     |------|
- * Stream 2 read                    |-----------------------|
- *
- * Wake up at T1:
-                          hw_ptr                 appl_ptr
- * Input audio area                     |------------|
- * deinterleave float       |------------------------|
- * Stream 1 offset                                   |
- * Stream 2 offset                  |----------------|
- *
- * Case 1:
- * A normal input stream, of read offset 0, about to read from device.
- * We shall return the exact audio area from idev, and set read offset to 0.
- *
- * Case 2:
- * A normal input stream, of read offset 300, about to read from device.
- * We shall return the exact audio area from idev but clip read offset to 250.
- *
- * Case 3:
- * An APM Stream of read offset 300, would like to read the deinterleaved
- * float buffer. We shall let APM process the float buffer from offset 300.
- * Don't bother clip read offset in this case, because fbuffer contains
- * the deepest deinterleaved audio data ever read from idev.
- */
 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 apm_processed;
+	unsigned int apm_processed;
 	struct cras_apm *apm;
-	int stream_offset = buffer_share_id_offset(offsets, stream->stream_id);
+
+	/*
+	 * It is possible that area buffer frames is smaller than the
+	 * offset of stream. In this case, just reset the offset value
+	 * to area->frames to prevent caller using these information get
+	 * bad access to data.
+	 */
+	*area = data->area;
+	*offset = MIN(buffer_share_id_offset(offsets, stream->stream_id),
+		      data->area->frames);
 
 	apm = cras_apm_list_get(stream->apm_list, data->dev_ptr);
-	if (apm == NULL) {
-		/*
-		 * Case 1 and 2 from above example.
-		 */
-		*area = data->area;
-		*offset = MIN(stream_offset, data->area->frames);
-	} else {
-		/*
-		 * Case 3 from above example.
-		 */
-		apm_processed = cras_apm_list_process(apm, data->fbuffer,
-						      stream_offset);
-		if (apm_processed < 0) {
-			cras_apm_list_remove(stream->apm_list, apm);
-			return 0;
-		}
-		buffer_share_offset_update(offsets, stream->stream_id,
-					   apm_processed);
-		*area = cras_apm_list_get_processed(apm);
-		*offset = 0;
+	if (apm == NULL)
+		return 0;
+
+	apm_processed = cras_apm_list_process(apm, data->fbuffer, *offset);
+	if (apm_processed < 0) {
+		cras_apm_list_remove(stream->apm_list, apm);
+		return 0;
 	}
+	buffer_share_offset_update(offsets, stream->stream_id, apm_processed);
+	*area = cras_apm_list_get_processed(apm);
+	*offset = 0;
 
 	return 0;
 }
 
 int input_data_put_for_stream(struct input_data *data,
 			      struct cras_rstream *stream,
-			      struct buffer_share *offsets, unsigned int frames)
+			      struct buffer_share *offsets,
+			      unsigned int frames)
 {
-	struct cras_apm *apm =
-		cras_apm_list_get(stream->apm_list, data->dev_ptr);
+	struct cras_apm *apm = cras_apm_list_get(
+			stream->apm_list, data->dev_ptr);
 
 	if (apm)
 		cras_apm_list_put_processed(apm, frames);
diff --git a/cras/src/server/input_data.h b/cras/src/server/input_data.h
index bb120b4..71ec1a6 100644
--- a/cras/src/server/input_data.h
+++ b/cras/src/server/input_data.h
@@ -55,11 +55,12 @@
  *    offset - To be filled with the samples offset in |area| that |stream|
  *        should start reading.
  */
-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);
 
 /*
  * Marks |frames| of audio data as read by |stream|.
@@ -71,8 +72,8 @@
  *    frames - Number of frames |stream| has read.
  */
 int input_data_put_for_stream(struct input_data *data,
-			      struct cras_rstream *stream,
-			      struct buffer_share *offsets,
-			      unsigned int frames);
+			   struct cras_rstream *stream,
+			   struct buffer_share *offsets,
+			   unsigned int frames);
 
 #endif /* INPUT_DATA_H_ */
diff --git a/cras/src/server/linear_resampler.c b/cras/src/server/linear_resampler.c
index ed2b6d6..e014e57 100644
--- a/cras/src/server/linear_resampler.c
+++ b/cras/src/server/linear_resampler.c
@@ -28,8 +28,9 @@
 };
 
 struct linear_resampler *linear_resampler_create(unsigned int num_channels,
-						 unsigned int format_bytes,
-						 float src_rate, float dst_rate)
+					     unsigned int format_bytes,
+					     float src_rate,
+					     float dst_rate)
 {
 	struct linear_resampler *lr;
 
@@ -50,8 +51,8 @@
 		free(lr);
 }
 
-void linear_resampler_set_rates(struct linear_resampler *lr, float from,
-				float to)
+void linear_resampler_set_rates(struct linear_resampler *lr,
+				float from, float to)
 {
 	lr->f = (float)to / from;
 	lr->to_times_100 = to * 100;
@@ -107,8 +108,10 @@
 }
 
 unsigned int linear_resampler_resample(struct linear_resampler *lr,
-				       uint8_t *src, unsigned int *src_frames,
-				       uint8_t *dst, unsigned dst_frames)
+			     uint8_t *src,
+			     unsigned int *src_frames,
+			     uint8_t *dst,
+			     unsigned dst_frames)
 {
 	int ch;
 	unsigned int src_idx = 0;
@@ -149,12 +152,11 @@
 				out[ch] = in[ch];
 		} else {
 			for (ch = 0; ch < lr->num_channels; ch++) {
-				out[ch] = in[ch] +
-					  (src_pos - src_idx) *
-						  (in[lr->num_channels + ch] -
-						   in[ch]);
+				out[ch] = in[ch] + (src_pos - src_idx) *
+					(in[lr->num_channels + ch] - in[ch]);
 			}
 		}
+
 	}
 
 	*src_frames = src_idx + 1;
diff --git a/cras/src/server/linear_resampler.h b/cras/src/server/linear_resampler.h
index 25eff2b..6e9720c 100644
--- a/cras/src/server/linear_resampler.h
+++ b/cras/src/server/linear_resampler.h
@@ -6,6 +6,7 @@
 #ifndef LINEAR_RESAMPLER_H_
 #define LINEAR_RESAMPLER_H_
 
+
 struct linear_resampler;
 
 /* Creates a linear resampler.
@@ -25,12 +26,13 @@
  *    from - The rate to resample from.
  *    to - The rate to resample to.
  */
-void linear_resampler_set_rates(struct linear_resampler *lr, float from,
+void linear_resampler_set_rates(struct linear_resampler *lr,
+				float from,
 				float to);
 
 /* Converts the frames count from output rate to input rate. */
 unsigned int linear_resampler_out_frames_to_in(struct linear_resampler *lr,
-					       unsigned int frames);
+                                               unsigned int frames);
 
 /* Converts the frames count from input rate to output rate. */
 unsigned int linear_resampler_in_frames_to_out(struct linear_resampler *lr,
@@ -48,8 +50,10 @@
  *    dst_frames - The number of frames of output buffer.
  */
 unsigned int linear_resampler_resample(struct linear_resampler *lr,
-				       uint8_t *src, unsigned int *src_frames,
-				       uint8_t *dst, unsigned dst_frames);
+			     uint8_t *src,
+			     unsigned int *src_frames,
+			     uint8_t *dst,
+			     unsigned dst_frames);
 
 /* Destroy a linear resampler. */
 void linear_resampler_destroy(struct linear_resampler *lr);
diff --git a/cras/src/server/polled_interval_checker.c b/cras/src/server/polled_interval_checker.c
index 37f9368..f647455 100644
--- a/cras/src/server/polled_interval_checker.c
+++ b/cras/src/server/polled_interval_checker.c
@@ -7,27 +7,24 @@
 #include "polled_interval_checker.h"
 
 struct polled_interval {
-	struct timespec last_interval_start_ts;
-	int interval_sec;
+    struct timespec last_interval_start_ts;
+    int interval_sec;
 };
 
 static struct timespec now;
 
-static inline int
-get_sec_since_last_active(const struct timespec *last_active_ts)
-{
+static inline int get_sec_since_last_active(
+	const struct timespec *last_active_ts) {
 	struct timespec diff;
 	subtract_timespecs(&now, last_active_ts, &diff);
 	return diff.tv_sec;
 }
 
-void pic_update_current_time()
-{
+void pic_update_current_time() {
 	clock_gettime(CLOCK_MONOTONIC_RAW, &now);
 }
 
-struct polled_interval *pic_polled_interval_create(int interval_sec)
-{
+struct polled_interval *pic_polled_interval_create(int interval_sec) {
 	struct polled_interval *pi;
 	pi = malloc(sizeof(*pi));
 	pi->last_interval_start_ts = now;
@@ -35,19 +32,16 @@
 	return pi;
 }
 
-void pic_polled_interval_destroy(struct polled_interval **interval)
-{
+void pic_polled_interval_destroy(struct polled_interval **interval) {
 	free(*interval);
 	*interval = NULL;
 }
 
-int pic_interval_elapsed(const struct polled_interval *pi)
-{
+int pic_interval_elapsed(const struct polled_interval *pi) {
 	return get_sec_since_last_active(&pi->last_interval_start_ts) >=
-	       pi->interval_sec;
+		pi->interval_sec;
 }
 
-void pic_interval_reset(struct polled_interval *pi)
-{
+void pic_interval_reset(struct polled_interval *pi) {
 	pi->last_interval_start_ts = now;
 }
\ No newline at end of file
diff --git a/cras/src/server/polled_interval_checker.h b/cras/src/server/polled_interval_checker.h
index 1b4619d..fc2fec5 100644
--- a/cras/src/server/polled_interval_checker.h
+++ b/cras/src/server/polled_interval_checker.h
@@ -46,4 +46,5 @@
  */
 void pic_update_current_time();
 
+
 #endif /* POLLED_ACTIVITY_CHECKER_H_ */
\ No newline at end of file
diff --git a/cras/src/server/rate_estimator.c b/cras/src/server/rate_estimator.c
index 4b1277e..e12c0b7 100644
--- a/cras/src/server/rate_estimator.c
+++ b/cras/src/server/rate_estimator.c
@@ -94,12 +94,12 @@
 	least_square_add_sample(&re->lsq,
 				td.tv_sec + (double)td.tv_nsec / 1000000000L,
 				re->window_frames);
-	if (timespec_after(&td, &re->window_size) && re->lsq.num_samples > 1) {
+	if (timespec_after(&td, &re->window_size) &&
+	    re->lsq.num_samples > 1) {
 		double rate = least_square_best_fit_slope(&re->lsq);
 		if (fabs(re->estimated_rate - rate) < MAX_RATE_SKEW)
-			re->estimated_rate =
-				rate * (1 - re->smooth_factor) +
-				re->smooth_factor * re->estimated_rate;
+			re->estimated_rate = rate * (1 - re->smooth_factor) +
+					re->smooth_factor * re->estimated_rate;
 		least_square_reset(&re->lsq);
 		re->window_start_ts = *now;
 		re->window_frames = 0;
diff --git a/cras/src/server/rate_estimator.h b/cras/src/server/rate_estimator.h
index c9a5aff..115c70c 100644
--- a/cras/src/server/rate_estimator.h
+++ b/cras/src/server/rate_estimator.h
@@ -8,6 +8,7 @@
 
 #include <time.h>
 
+
 /* Hold information to calculate linear least square from
  * several (x, y) samples.
  */
diff --git a/cras/src/server/server_stream.c b/cras/src/server/server_stream.c
index cc16cd8..242a34c 100644
--- a/cras/src/server/server_stream.c
+++ b/cras/src/server/server_stream.c
@@ -12,6 +12,7 @@
 #include "server_stream.h"
 #include "stream_list.h"
 
+
 /* Parameters used for server stream. */
 static unsigned int server_stream_block_size = 480;
 
@@ -21,7 +22,8 @@
  * make pinned device open and let data flow through its dsp
  * pipeline.
  */
-static struct cras_audio_format format = {
+static struct cras_audio_format format =
+{
 	SND_PCM_FORMAT_S16_LE,
 	48000,
 	2,
@@ -47,25 +49,24 @@
 
 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);
 		return;
 	}
 
-	stream_config =
-		(struct cras_rstream_config *)calloc(1, sizeof(*stream_config));
-	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);
+	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;
 
 	/* Schedule add stream in next main thread loop. */
 	cras_system_add_task(server_stream_add_cb, stream_list);
diff --git a/cras/src/server/softvol_curve.c b/cras/src/server/softvol_curve.c
index e4467ef..d98ca4c 100644
--- a/cras/src/server/softvol_curve.c
+++ b/cras/src/server/softvol_curve.c
@@ -12,21 +12,106 @@
 /* This is a ramp that increases 0.5dB per step, for a total range of 50dB. */
 const float softvol_scalers[101] = {
 	0.003162, /* volume 0 */
-	0.003350, 0.003548, 0.003758, 0.003981, 0.004217, 0.004467, 0.004732,
-	0.005012, 0.005309, 0.005623, 0.005957, 0.006310, 0.006683, 0.007079,
-	0.007499, 0.007943, 0.008414, 0.008913, 0.009441, 0.010000, 0.010593,
-	0.011220, 0.011885, 0.012589, 0.013335, 0.014125, 0.014962, 0.015849,
-	0.016788, 0.017783, 0.018836, 0.019953, 0.021135, 0.022387, 0.023714,
-	0.025119, 0.026607, 0.028184, 0.029854, 0.031623, 0.033497, 0.035481,
-	0.037584, 0.039811, 0.042170, 0.044668, 0.047315, 0.050119, 0.053088,
-	0.056234, 0.059566, 0.063096, 0.066834, 0.070795, 0.074989, 0.079433,
-	0.084140, 0.089125, 0.094406, 0.100000, 0.105925, 0.112202, 0.118850,
-	0.125893, 0.133352, 0.141254, 0.149624, 0.158489, 0.167880, 0.177828,
-	0.188365, 0.199526, 0.211349, 0.223872, 0.237137, 0.251189, 0.266073,
-	0.281838, 0.298538, 0.316228, 0.334965, 0.354813, 0.375837, 0.398107,
-	0.421697, 0.446684, 0.473151, 0.501187, 0.530884, 0.562341, 0.595662,
-	0.630957, 0.668344, 0.707946, 0.749894, 0.794328, 0.841395, 0.891251,
-	0.944061, 1.000000, /* volume 100 */
+	0.003350,
+	0.003548,
+	0.003758,
+	0.003981,
+	0.004217,
+	0.004467,
+	0.004732,
+	0.005012,
+	0.005309,
+	0.005623,
+	0.005957,
+	0.006310,
+	0.006683,
+	0.007079,
+	0.007499,
+	0.007943,
+	0.008414,
+	0.008913,
+	0.009441,
+	0.010000,
+	0.010593,
+	0.011220,
+	0.011885,
+	0.012589,
+	0.013335,
+	0.014125,
+	0.014962,
+	0.015849,
+	0.016788,
+	0.017783,
+	0.018836,
+	0.019953,
+	0.021135,
+	0.022387,
+	0.023714,
+	0.025119,
+	0.026607,
+	0.028184,
+	0.029854,
+	0.031623,
+	0.033497,
+	0.035481,
+	0.037584,
+	0.039811,
+	0.042170,
+	0.044668,
+	0.047315,
+	0.050119,
+	0.053088,
+	0.056234,
+	0.059566,
+	0.063096,
+	0.066834,
+	0.070795,
+	0.074989,
+	0.079433,
+	0.084140,
+	0.089125,
+	0.094406,
+	0.100000,
+	0.105925,
+	0.112202,
+	0.118850,
+	0.125893,
+	0.133352,
+	0.141254,
+	0.149624,
+	0.158489,
+	0.167880,
+	0.177828,
+	0.188365,
+	0.199526,
+	0.211349,
+	0.223872,
+	0.237137,
+	0.251189,
+	0.266073,
+	0.281838,
+	0.298538,
+	0.316228,
+	0.334965,
+	0.354813,
+	0.375837,
+	0.398107,
+	0.421697,
+	0.446684,
+	0.473151,
+	0.501187,
+	0.530884,
+	0.562341,
+	0.595662,
+	0.630957,
+	0.668344,
+	0.707946,
+	0.749894,
+	0.794328,
+	0.841395,
+	0.891251,
+	0.944061,
+	1.000000, /* volume 100 */
 };
 
 float *softvol_build_from_curve(const struct cras_volume_curve *curve)
@@ -48,14 +133,9 @@
 	 */
 	for (volume = 0; volume <= MAX_VOLUME; volume++) {
 		scalers[volume] = convert_softvol_scaler_from_dB(
-			curve->get_dBFS(curve, volume));
+				curve->get_dBFS(curve, volume));
 		if (scalers[volume] > 1.0)
 			scalers[volume] = 1.0;
-		/* Clip scalers so that all values are non-zero to make volume
-		 * ramping simpler. Because of how mix_ops treats small values,
-		 * this should be effectively the same as a 0 value. */
-		else if (scalers[volume] < 1e-7)
-			scalers[volume] = 1e-7;
 	}
 
 	return scalers;
diff --git a/cras/src/server/stream_list.c b/cras/src/server/stream_list.c
index d247ec8..bfca478 100644
--- a/cras/src/server/stream_list.c
+++ b/cras/src/server/stream_list.c
@@ -1,4 +1,4 @@
-/* Copyright 2015 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2015 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.
  */
@@ -26,7 +26,7 @@
 	struct stream_list *list = (struct stream_list *)data;
 	int max_drain_delay = 0;
 
-	DL_FOREACH (list->streams_to_delete, to_delete) {
+	DL_FOREACH(list->streams_to_delete, to_delete) {
 		int drain_delay;
 
 		drain_delay = list->stream_removed_cb(to_delete);
@@ -40,10 +40,8 @@
 
 	list->drain_timer = NULL;
 	if (max_drain_delay)
-		list->drain_timer =
-			cras_tm_create_timer(list->timer_manager,
-					     MAX(max_drain_delay, 10),
-					     delete_streams, list);
+		list->drain_timer = cras_tm_create_timer(list->timer_manager,
+				MAX(max_drain_delay, 10), delete_streams, list);
 }
 
 /*
@@ -120,7 +118,7 @@
 	struct cras_rstream *to_remove;
 	int rc = 0;
 
-	DL_FOREACH (list->streams, to_remove) {
+	DL_FOREACH(list->streams, to_remove) {
 		if (to_remove->client == rclient) {
 			DL_DELETE(list->streams, to_remove);
 			DL_APPEND(list->streams_to_delete, to_remove);
@@ -133,17 +131,6 @@
 	delete_streams(NULL, list);
 
 	return rc;
+
 }
 
-bool stream_list_has_pinned_stream(struct stream_list *list,
-				   unsigned int dev_idx)
-{
-	struct cras_rstream *rstream;
-	DL_FOREACH (list->streams, rstream) {
-		if (!rstream->is_pinned)
-			continue;
-		if (rstream->pinned_dev_idx == dev_idx)
-			return true;
-	}
-	return false;
-}
diff --git a/cras/src/server/stream_list.h b/cras/src/server/stream_list.h
index ae77a33..d12f2c6 100644
--- a/cras/src/server/stream_list.h
+++ b/cras/src/server/stream_list.h
@@ -1,10 +1,8 @@
-/* Copyright 2015 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2015 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 <stdbool.h>
-
 #include "cras_types.h"
 #include "utlist.h"
 
@@ -14,11 +12,10 @@
 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);
+typedef int (stream_callback)(struct cras_rstream *rstream);
+typedef int (stream_create_func)(struct cras_rstream_config *stream_config,
+				 struct cras_rstream **rstream);
+typedef void (stream_destroy_func)(struct cras_rstream *rstream);
 
 struct stream_list *stream_list_create(stream_callback *add_cb,
 				       stream_callback *rm_cb,
@@ -30,17 +27,6 @@
 
 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);
@@ -49,9 +35,3 @@
 
 int stream_list_rm_all_client_streams(struct stream_list *list,
 				      struct cras_rclient *rclient);
-
-/*
- * Checks if there is a stream pinned to the given device.
- */
-bool stream_list_has_pinned_stream(struct stream_list *list,
-				   unsigned int dev_idx);
diff --git a/cras/src/server/test_iodev.c b/cras/src/server/test_iodev.c
index 47ff336..37730d3 100644
--- a/cras/src/server/test_iodev.c
+++ b/cras/src/server/test_iodev.c
@@ -21,11 +21,18 @@
 
 #define TEST_BUFFER_SIZE (16 * 1024)
 
-static size_t test_supported_rates[] = { 16000, 0 };
+static size_t test_supported_rates[] = {
+	16000, 0
+};
 
-static size_t test_supported_channel_counts[] = { 1, 0 };
+static size_t test_supported_channel_counts[] = {
+	1, 0
+};
 
-static snd_pcm_format_t test_supported_formats[] = { SND_PCM_FORMAT_S16_LE, 0 };
+static snd_pcm_format_t test_supported_formats[] = {
+	SND_PCM_FORMAT_S16_LE,
+	0
+};
 
 struct test_iodev {
 	struct cras_iodev base;
@@ -75,13 +82,14 @@
 
 	cras_iodev_init_audio_area(iodev, iodev->format->num_channels);
 	testio->fmt_bytes = cras_get_format_bytes(iodev->format);
-	testio->audbuff =
-		byte_buffer_create(TEST_BUFFER_SIZE * testio->fmt_bytes);
+	testio->audbuff = byte_buffer_create(TEST_BUFFER_SIZE *
+						testio->fmt_bytes);
 
 	return 0;
 }
 
-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 test_iodev *testio = (struct test_iodev *)iodev;
@@ -108,7 +116,8 @@
 }
 
 static int get_buffer_fd_read(struct cras_iodev *iodev,
-			      struct cras_audio_area **area, unsigned *frames)
+			      struct cras_audio_area **area,
+			      unsigned *frames)
 {
 	struct test_iodev *testio = (struct test_iodev *)iodev;
 	int nread;
@@ -149,7 +158,8 @@
 	if (testio->fd >= 0) {
 		/* Remove audio thread callback from main thread. */
 		audio_thread_rm_callback_sync(
-			cras_iodev_list_get_audio_thread(), testio->fd);
+				cras_iodev_list_get_audio_thread(),
+				testio->fd);
 		close(testio->fd);
 	}
 
@@ -227,7 +237,8 @@
 	free(testio);
 }
 
-unsigned int test_iodev_add_samples(struct test_iodev *testio, uint8_t *samples,
+unsigned int test_iodev_add_samples(struct test_iodev *testio,
+				    uint8_t *samples,
 				    unsigned int count)
 {
 	unsigned int avail;
@@ -241,7 +252,8 @@
 }
 
 void test_iodev_command(struct cras_iodev *iodev,
-			enum CRAS_TEST_IODEV_CMD command, unsigned int data_len,
+			enum CRAS_TEST_IODEV_CMD command,
+			unsigned int data_len,
 			const uint8_t *data)
 {
 	struct test_iodev *testio = (struct test_iodev *)iodev;
diff --git a/cras/src/server/test_iodev.h b/cras/src/server/test_iodev.h
index 782bf5c..f1039f5 100644
--- a/cras/src/server/test_iodev.h
+++ b/cras/src/server/test_iodev.h
@@ -26,7 +26,8 @@
 
 /* Handle a test commdn to the given iodev. */
 void test_iodev_command(struct cras_iodev *iodev,
-			enum CRAS_TEST_IODEV_CMD command, unsigned int data_len,
+			enum CRAS_TEST_IODEV_CMD command,
+			unsigned int data_len,
 			const uint8_t *data);
 
 #endif /* TEST_IODEV_H_ */
diff --git a/cras/src/tests/.clang-format b/cras/src/tests/.clang-format
deleted file mode 100644
index a675ede..0000000
--- a/cras/src/tests/.clang-format
+++ /dev/null
@@ -1,14 +0,0 @@
-BasedOnStyle: Chromium
-
-# Taken from:
-#   git grep -h '^#define [^[:space:]]*FOREACH[^[:space:]]*(' cras/ \
-#   | sed "s,^#define \([^[:space:]]*FOREACH[^[:space:]]*\)(.*$,  - '\1'," \
-#   | sort | uniq
-
-ForEachMacros:
-  - 'ARRAY_ELEMENT_FOREACH'
-  - 'DL_FOREACH'
-  - 'DL_FOREACH_INTERNAL'
-  - 'LL_FOREACH'
-  - 'LL_FOREACH_SAFE'
-
diff --git a/cras/src/tests/a2dp_info_unittest.cc b/cras/src/tests/a2dp_info_unittest.cc
index 4858c46..3c70f87 100644
--- a/cras/src/tests/a2dp_info_unittest.cc
+++ b/cras/src/tests/a2dp_info_unittest.cc
@@ -2,28 +2,54 @@
 // 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_a2dp_info.h"
-#include "cras_sbc_codec.h"
-#include "sbc_codec_stub.h"
+  #include "cras_sbc_codec.h"
+  #include "cras_a2dp_info.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() {
-  sbc_codec_stub_reset();
+  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;
 
   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;
@@ -44,15 +70,15 @@
   ResetStubData();
   init_a2dp(&a2dp, &sbc);
 
-  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_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_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);
@@ -64,12 +90,12 @@
 TEST(A2dpInfoInit, InitA2dpFail) {
   ResetStubData();
   int err;
-  set_sbc_codec_create_fail(1);
+  cras_sbc_codec_create_fail = 1;
   err = init_a2dp(&a2dp, &sbc);
 
-  ASSERT_EQ(1, get_sbc_codec_create_called());
+  ASSERT_EQ(1, cras_sbc_codec_create_called);
   ASSERT_NE(0, err);
-  ASSERT_EQ(a2dp.codec, (void*)NULL);
+  ASSERT_EQ(a2dp.codec, (void *)NULL);
 }
 
 TEST(A2dpInfoInit, DestroyA2dp) {
@@ -77,7 +103,7 @@
   init_a2dp(&a2dp, &sbc);
   destroy_a2dp(&a2dp);
 
-  ASSERT_EQ(1, get_sbc_codec_destroy_called());
+  ASSERT_EQ(1, cras_sbc_codec_destroy_called);
 }
 
 TEST(A2dpInfoInit, DrainA2dp) {
@@ -104,7 +130,7 @@
   ResetStubData();
   init_a2dp(&a2dp, &sbc);
 
-  set_sbc_codec_encoded_out(4);
+  encode_out_encoded_return_val = 4;
   processed = a2dp_encode(&a2dp, NULL, 20, 4, (size_t)40);
 
   ASSERT_EQ(20, processed);
@@ -116,7 +142,7 @@
   ASSERT_EQ(5, a2dp.nsamples);
   ASSERT_EQ(0, a2dp.seq_num);
 
-  set_sbc_codec_encoded_out(15);
+  encode_out_encoded_return_val = 15;
   processed = a2dp_encode(&a2dp, NULL, 20, 4, (size_t)40);
 
   ASSERT_EQ(32, a2dp.a2dp_buf_used);
@@ -125,9 +151,61 @@
   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 c85b9d6..02d5068 100644
--- a/cras/src/tests/a2dp_iodev_unittest.cc
+++ b/cras/src/tests/a2dp_iodev_unittest.cc
@@ -2,19 +2,20 @@
 // 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 <stdint.h>
+#include <gtest/gtest.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"
@@ -22,12 +23,11 @@
 #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,18 +46,17 @@
 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;
@@ -77,17 +76,19 @@
   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;
@@ -98,27 +99,29 @@
 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));
-  }
+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);
-  }
+    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);
@@ -146,12 +149,12 @@
 }
 
 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);
@@ -161,7 +164,7 @@
 }
 
 TEST_F(A2dpIodev, OpenIodev) {
-  struct cras_iodev* iodev;
+  struct cras_iodev *iodev;
 
   iodev = a2dp_iodev_create(fake_transport);
 
@@ -179,16 +182,16 @@
 }
 
 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);
@@ -197,13 +200,16 @@
   area1_buf = area1->channels[0].buf;
 
   /* Test 100 frames(400 bytes) put and all processed. */
-  a2dp_encode_processed_bytes_val[0] = 400;
+  a2dp_encode_processed_bytes_val[0] = 4096 * 4;
+  a2dp_encode_processed_bytes_val[1] = 400;
   a2dp_write_index = 0;
-  a2dp_write_return_val[0] = 400;
+  a2dp_write_return_val[0] = -EAGAIN;
+  a2dp_write_return_val[1] = 400;
   iodev->put_buffer(iodev, 100);
   write_callback(write_callback_data);
   // Start with 4k frames.
-  EXPECT_EQ(400, pcm_buf_size_val[0]);
+  EXPECT_EQ(4096, pcm_buf_size_val[0]);
+  EXPECT_EQ(400, pcm_buf_size_val[1]);
 
   iodev->get_buffer(iodev, &area2, &frames);
   ASSERT_EQ(256, frames);
@@ -239,8 +245,8 @@
 }
 
 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;
 
@@ -250,7 +256,7 @@
   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);
@@ -261,13 +267,15 @@
    * Assume 200 bytes written out, queued 50 frames in a2dp buffer.
    */
   a2dp_encode_processed_bytes_val[0] = 400;
-  a2dp_write_return_val[0] = 50;
+  a2dp_encode_processed_bytes_val[1] = 0;
+  a2dp_write_return_val[0] = 200;
+  a2dp_write_return_val[1] = -EAGAIN;
   a2dp_queued_frames_val = 50;
   time_now.tv_sec = 0;
   time_now.tv_nsec = 1000000;
-  iodev->put_buffer(iodev, 200);
+  iodev->put_buffer(iodev, 300);
   write_callback(write_callback_data);
-  EXPECT_EQ(200, iodev->frames_queued(iodev, &tstamp));
+  EXPECT_EQ(350, iodev->frames_queued(iodev, &tstamp));
   EXPECT_EQ(tstamp.tv_sec, time_now.tv_sec);
   EXPECT_EQ(tstamp.tv_nsec, time_now.tv_nsec);
 
@@ -276,11 +284,12 @@
   time_now.tv_nsec = 2000000;
   a2dp_encode_index = 0;
   a2dp_write_index = 0;
-  a2dp_encode_processed_bytes_val[0] = 400;
+  a2dp_encode_processed_bytes_val[0] = 800;
   write_callback(write_callback_data);
   /* 1000000 nsec has passed, estimated queued frames adjusted by 44 */
-  EXPECT_EQ(156, iodev->frames_queued(iodev, &tstamp));
-  EXPECT_EQ(400, pcm_buf_size_val[0]);
+  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(tstamp.tv_sec, time_now.tv_sec);
   EXPECT_EQ(tstamp.tv_nsec, time_now.tv_nsec);
 
@@ -296,10 +305,9 @@
   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(800, pcm_buf_size_val[0]);
-  EXPECT_EQ(100, iodev->frames_queued(iodev, &tstamp));
+  EXPECT_EQ(1200, pcm_buf_size_val[0]);
+  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);
   iodev->close_dev(iodev);
@@ -307,8 +315,8 @@
 }
 
 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;
 
@@ -318,7 +326,7 @@
   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);
 
@@ -327,18 +335,22 @@
   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[0] = 800;
-  a2dp_encode_processed_bytes_val[1] = 0;
-  a2dp_write_return_val[0] = 200;
+  a2dp_encode_processed_bytes_val[1] = 800;
+  a2dp_encode_processed_bytes_val[2] = 0;
+  a2dp_write_return_val[1] = 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[2] = 800;
-  a2dp_encode_processed_bytes_val[3] = 0;
-  a2dp_write_return_val[1] = -EAGAIN;
+  a2dp_encode_processed_bytes_val[3] = 800;
+  a2dp_encode_processed_bytes_val[4] = 0;
+  a2dp_write_return_val[2] = -EAGAIN;
 
   time_now.tv_nsec = 10000000;
   iodev->put_buffer(iodev, 700);
@@ -351,190 +363,175 @@
   a2dp_iodev_destroy(iodev);
 }
 
-TEST_F(A2dpIodev, NoStreamState) {
-  struct cras_iodev* iodev;
-  struct cras_audio_area* area;
-  struct timespec tstamp;
-  unsigned frames;
+} // namespace
 
-  iodev = a2dp_iodev_create(fake_transport);
-  iodev_set_format(iodev, &format);
-  time_now.tv_sec = 0;
-  time_now.tv_nsec = 0;
-  iodev->configure_dev(iodev);
-  ASSERT_NE(write_callback, (void*)NULL);
-  ASSERT_EQ(400, iodev->min_buffer_level);
-
-  iodev->min_cb_level = 480;
-  frames = 200;
-  iodev->get_buffer(iodev, &area, &frames);
-  iodev->put_buffer(iodev, 200);
-
-  iodev->no_stream(iodev, 1);
-  EXPECT_EQ(1, cras_iodev_frames_queued_called);
-
-  /* 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(1082, frames);
-
-  /* After leaving no stream state, output buffer won't be adjusted */
-  iodev->no_stream(iodev, 0);
-  frames = iodev->frames_queued(iodev, &tstamp);
-  ASSERT_EQ(1082, frames);
-}
-
-}  // 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)
@@ -545,56 +542,47 @@
   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) {}
-
-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_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)
+{
   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 ec1efcc..5f547f5 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/socket.h>
 #include <sys/types.h>
+#include <sys/socket.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,15 +33,18 @@
   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);
@@ -52,7 +55,7 @@
 }
 
 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.
@@ -65,11 +68,11 @@
 }
 
 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);
@@ -78,14 +81,16 @@
 }
 
 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);
@@ -94,15 +99,15 @@
 }
 
 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);
@@ -111,7 +116,7 @@
 }
 
 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();
@@ -125,7 +130,7 @@
 }
 
 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);
@@ -135,8 +140,8 @@
 }
 
 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();
@@ -152,7 +157,7 @@
 }
 
 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);
@@ -164,8 +169,8 @@
 }
 
 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);
 
@@ -200,28 +205,31 @@
   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 dd75b1d..29c315b 100644
--- a/cras/src/tests/alsa_card_unittest.cc
+++ b/cras/src/tests/alsa_card_unittest.cc
@@ -4,11 +4,10 @@
 
 #include <gtest/gtest.h>
 #include <iniparser.h>
-#include <stdio.h>
-#include <sys/param.h>
-#include <syslog.h>
-
 #include <map>
+#include <stdio.h>
+#include <syslog.h>
+#include <sys/param.h>
 
 extern "C" {
 #include "cras_alsa_card.h"
@@ -24,25 +23,25 @@
 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;
@@ -50,11 +49,11 @@
 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;
@@ -63,10 +62,10 @@
 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;
@@ -76,31 +75,28 @@
 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[65];
+static char ucm_get_flag_name[64];
 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 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;
@@ -129,7 +125,7 @@
   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;
@@ -145,17 +141,16 @@
   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;
   mixer_name_free(coupled_output_names_value);
   coupled_output_names_value = NULL;
   ucm_has_fully_specified_ucm_flag_return_value = 0;
@@ -163,56 +158,50 @@
   ucm_get_sections_return_value = NULL;
   cras_alsa_mixer_add_controls_in_section_called = 0;
   cras_alsa_mixer_add_controls_in_section_return_value = 0;
-  cras_alsa_mixer_add_main_volume_control_by_name_called = 0;
-  cras_alsa_mixer_add_main_volume_control_by_name_return_value = 0;
   ucm_get_echo_reference_dev_name_for_dev_called = 0;
-  fake_dev1.nodes = NULL;
-  fake_dev2.nodes = NULL;
-  fake_dev3.nodes = NULL;
-  fake_dev4.nodes = NULL;
 }
 
 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);
@@ -220,7 +209,7 @@
 }
 
 TEST(AlsaCard, CreateFailHctlOpen) {
-  struct cras_alsa_card* c;
+  struct cras_alsa_card *c;
   cras_alsa_card_info card_info;
 
   ResetStubData();
@@ -229,9 +218,9 @@
   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);
@@ -243,7 +232,7 @@
 }
 
 TEST(AlsaCard, CreateFailHctlLoad) {
-  struct cras_alsa_card* c;
+  struct cras_alsa_card *c;
   cras_alsa_card_info card_info;
 
   ResetStubData();
@@ -251,9 +240,9 @@
   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);
@@ -265,10 +254,10 @@
 
 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();
@@ -277,9 +266,9 @@
   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);
@@ -294,12 +283,12 @@
 
 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();
@@ -312,9 +301,9 @@
   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);
@@ -337,16 +326,16 @@
 }
 
 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);
@@ -354,15 +343,15 @@
 }
 
 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);
@@ -378,23 +367,23 @@
 }
 
 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;
@@ -406,9 +395,9 @@
   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);
@@ -432,7 +421,7 @@
 }
 
 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;
@@ -446,9 +435,9 @@
   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);
@@ -464,7 +453,7 @@
 }
 
 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;
@@ -476,9 +465,9 @@
   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);
@@ -497,7 +486,7 @@
 }
 
 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;
@@ -509,9 +498,9 @@
   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);
@@ -530,7 +519,7 @@
 }
 
 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;
@@ -542,9 +531,9 @@
   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);
@@ -562,7 +551,7 @@
 }
 
 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;
@@ -574,9 +563,9 @@
   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);
@@ -594,7 +583,7 @@
 }
 
 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;
@@ -606,9 +595,9 @@
   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);
@@ -626,7 +615,7 @@
 }
 
 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;
@@ -657,10 +646,10 @@
   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);
@@ -677,7 +666,7 @@
 
   /* 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;
@@ -695,7 +684,7 @@
 }
 
 TEST(AlsaCard, CreateFullyUCMNoSections) {
-  struct cras_alsa_card* c;
+  struct cras_alsa_card *c;
   cras_alsa_card_info card_info;
 
   ResetStubData();
@@ -703,9 +692,9 @@
   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,54 +710,9 @@
   EXPECT_EQ(iniparser_load_called, iniparser_freedict_called);
 }
 
-TEST(AlsaCard, CreateFullyUCMTwoMainVolume) {
-  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;
-
-  ResetStubData();
-  card_info.card_type = ALSA_CARD_TYPE_INTERNAL;
-  card_info.card_index = 0;
-  ucm_has_fully_specified_ucm_flag_return_value = 1;
-
-  /* Creates a list of mixer names as return value of
-   * ucm_get_main_volume_names_return_value. */
-  mixer_name_1 = (struct mixer_name*)malloc(sizeof(*mixer_name_1));
-  mixer_name_2 = (struct mixer_name*)malloc(sizeof(*mixer_name_2));
-  mixer_name_1->name = name1;
-  mixer_name_2->name = name2;
-  mixer_name_1->dir = CRAS_STREAM_OUTPUT;
-  mixer_name_2->dir = CRAS_STREAM_OUTPUT;
-  mixer_name_1->type = MIXER_NAME_MAIN_VOLUME;
-  mixer_name_2->type = MIXER_NAME_MAIN_VOLUME;
-
-  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);
-
-  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);
-  EXPECT_EQ(1, snd_ctl_card_info_called);
-  EXPECT_EQ(1, cras_alsa_mixer_add_main_volume_control_by_name_called);
-  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);
-  EXPECT_EQ(NULL, cras_alsa_iodev_destroy_arg);
-  EXPECT_EQ(cras_alsa_mixer_create_called, cras_alsa_mixer_destroy_called);
-  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,13 +720,14 @@
   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);
@@ -793,7 +738,8 @@
   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);
 
@@ -801,7 +747,7 @@
 }
 
 TEST(AlsaCard, CreateFullyUCMFailureOnControls) {
-  struct cras_alsa_card* c;
+  struct cras_alsa_card *c;
   cras_alsa_card_info card_info;
 
   ResetStubData();
@@ -809,14 +755,14 @@
   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);
@@ -833,7 +779,7 @@
 }
 
 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};
 
@@ -848,12 +794,12 @@
   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);
@@ -872,11 +818,11 @@
 }
 
 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;
@@ -897,10 +843,10 @@
 
   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);
 }
@@ -908,76 +854,78 @@
 /* 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;
 }
 
@@ -987,7 +935,7 @@
 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);
@@ -995,11 +943,11 @@
     *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;
@@ -1015,165 +963,171 @@
   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) - 1);
+  strncpy(ucm_get_flag_name, flag_name, sizeof(ucm_get_flag_name));
   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) {
-  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) {
-  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);
@@ -1184,7 +1138,7 @@
 
 }  //  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 0e8112c..a613929 100644
--- a/cras/src/tests/alsa_helpers_unittest.cc
+++ b/cras/src/tests/alsa_helpers_unittest.cc
@@ -3,7 +3,6 @@
 // found in the LICENSE file.
 
 #include <gtest/gtest.h>
-
 #include <vector>
 
 extern "C" {
@@ -28,27 +27,28 @@
 
 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 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,16 +91,17 @@
 }
 
 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);
@@ -132,27 +133,27 @@
 
   /* 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]);
@@ -163,12 +164,12 @@
 }
 
 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();
@@ -206,27 +207,27 @@
 }
 
 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);
@@ -235,58 +236,57 @@
   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 @@
   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 2211f34..9a6b7f6 100644
--- a/cras/src/tests/alsa_io_unittest.cc
+++ b/cras/src/tests/alsa_io_unittest.cc
@@ -3,19 +3,18 @@
 // 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"
@@ -29,23 +28,23 @@
 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;
@@ -57,31 +56,31 @@
 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;
@@ -89,37 +88,37 @@
 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 size_t cras_iodev_set_node_plugged_called;
-static int cras_iodev_set_node_plugged_value;
+static struct cras_ionode *cras_iodev_set_node_attr_ionode;
+static size_t cras_iodev_set_node_attr_called;
+static enum ionode_attr cras_iodev_set_node_attr_attr;
+static int cras_iodev_set_node_attr_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;
-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;
+static const char *ucm_get_dsp_name_default_value;
+static size_t cras_alsa_jack_get_dsp_name_called;
+static const char *cras_alsa_jack_get_dsp_name_value;
 static size_t cras_iodev_free_resources_called;
 static size_t cras_alsa_jack_update_node_type_called;
 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;
@@ -134,11 +133,11 @@
 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;
@@ -148,13 +147,12 @@
 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;
 
 void ResetStubData() {
   cras_alsa_open_called = 0;
@@ -199,15 +197,15 @@
   cras_alsa_jack_list_destroy_called = 0;
   cras_alsa_jack_list_has_hctl_jacks_return_val = 1;
   cras_iodev_add_node_called = 0;
-  cras_iodev_set_node_plugged_called = 0;
+  cras_iodev_set_node_attr_called = 0;
   cras_alsa_jack_enable_ucm_called = 0;
   ucm_set_enabled_called = 0;
   cras_iodev_update_dsp_called = 0;
   cras_iodev_update_dsp_name = 0;
   ucm_get_dsp_name_default_called = 0;
   ucm_get_dsp_name_default_value = NULL;
-  ucm_get_dsp_name_for_dev_called = 0;
-  ucm_get_dsp_name_for_dev_values.clear();
+  cras_alsa_jack_get_dsp_name_called = 0;
+  cras_alsa_jack_get_dsp_name_value = NULL;
   cras_iodev_free_resources_called = 0;
   cras_alsa_jack_update_node_type_called = 0;
   ucm_swap_mode_exists_ret_value = 0;
@@ -246,162 +244,169 @@
   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_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 *)output_should_wake, (void *)aio->base.output_should_wake);
+  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_STREQ("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 *)output_should_wake, (void *)aio->base.output_should_wake);
+  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_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 *)output_should_wake, (void *)aio->base.output_should_wake);
+  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_STREQ("Internal Mic", 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 *)output_should_wake, (void *)aio->base.output_should_wake);
+  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_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);
+  EXPECT_EQ(1, cras_iodev_set_node_attr_called);
+  EXPECT_EQ(IONODE_ATTR_PLUGGED, cras_iodev_set_node_attr_attr);
+  EXPECT_EQ(1, cras_iodev_set_node_attr_value);
+  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_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);
+  EXPECT_EQ(2, cras_iodev_set_node_attr_called);
+  EXPECT_EQ(IONODE_ATTR_PLUGGED, cras_iodev_set_node_attr_attr);
+  EXPECT_EQ(1, cras_iodev_set_node_attr_value);
+  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);
 
   // Test that these flags are cleared after open_dev.
-  aio->free_running = 1;
+  aio->is_free_running = 1;
   aio->filled_zeros_for_draining = 512;
   iodev->open_dev(iodev);
   EXPECT_EQ(1, cras_alsa_open_called);
@@ -410,8 +415,8 @@
   EXPECT_EQ(1, sys_set_volume_limits_called);
   EXPECT_EQ(1, alsa_mixer_set_dBFS_called);
   EXPECT_EQ(0, cras_alsa_start_called);
-  EXPECT_EQ(0, cras_iodev_set_node_plugged_called);
-  EXPECT_EQ(0, aio->free_running);
+  EXPECT_EQ(0, cras_iodev_set_node_attr_called);
+  EXPECT_EQ(0, aio->is_free_running);
   EXPECT_EQ(0, aio->filled_zeros_for_draining);
   EXPECT_EQ(SEVERE_UNDERRUN_MS * format.frame_rate / 1000,
             aio->severe_underrun_frames);
@@ -421,15 +426,16 @@
 }
 
 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);
+  EXPECT_EQ(0, cras_iodev_set_node_attr_called);
   alsa_iodev_destroy(iodev);
 
   ResetStubData();
@@ -438,7 +444,7 @@
                                                     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);
+  EXPECT_EQ(0, cras_iodev_set_node_attr_called);
   alsa_iodev_destroy(iodev);
 
   ResetStubData();
@@ -448,13 +454,14 @@
   ASSERT_EQ(0, alsa_iodev_legacy_complete_init(iodev));
   EXPECT_EQ(2, cras_card_config_get_volume_curve_for_control_called);
   // Should assume USB devs are plugged when they appear.
-  EXPECT_EQ(1, cras_iodev_set_node_plugged_called);
-  EXPECT_EQ(1, iodev->active_node->plugged);
+  EXPECT_EQ(1, cras_iodev_set_node_attr_called);
+  EXPECT_EQ(IONODE_ATTR_PLUGGED, cras_iodev_set_node_attr_attr);
+  EXPECT_EQ(1, cras_iodev_set_node_attr_value);
   alsa_iodev_destroy(iodev);
 }
 
 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;
@@ -484,8 +491,8 @@
 }
 
 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();
@@ -493,9 +500,11 @@
   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);
@@ -503,7 +512,7 @@
   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);
@@ -514,9 +523,11 @@
   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);
@@ -534,9 +545,11 @@
   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);
@@ -544,7 +557,7 @@
   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);
@@ -555,9 +568,11 @@
   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);
@@ -570,8 +585,8 @@
 }
 
 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;
 
@@ -582,12 +597,14 @@
   ucm_get_max_software_gain_value = 2000;
 
   // Set default node gain to -1000 * 0.01 dB.
-  ucm_get_default_node_gain_values[INTERNAL_MICROPHONE] = default_node_gain;
+  ucm_get_default_node_gain_values["Internal Mic"] = 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.
@@ -602,15 +619,15 @@
 }
 
 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);
@@ -620,26 +637,28 @@
   EXPECT_EQ(0, cras_alsa_jack_list_add_jack_for_section_called);
 
   cras_alsa_jack_list_create_cb(NULL, 1, cras_alsa_jack_list_create_cb_data);
-  EXPECT_EQ(1, cras_iodev_set_node_plugged_called);
-  EXPECT_EQ(1, cras_iodev_set_node_plugged_value);
+  EXPECT_EQ(1, cras_iodev_set_node_attr_called);
+  EXPECT_EQ(IONODE_ATTR_PLUGGED, cras_iodev_set_node_attr_attr);
+  EXPECT_EQ(1, cras_iodev_set_node_attr_value);
   cras_alsa_jack_list_create_cb(NULL, 0, cras_alsa_jack_list_create_cb_data);
-  EXPECT_EQ(2, cras_iodev_set_node_plugged_called);
-  EXPECT_EQ(0, cras_iodev_set_node_plugged_value);
+  EXPECT_EQ(2, cras_iodev_set_node_attr_called);
+  EXPECT_EQ(IONODE_ATTR_PLUGGED, cras_iodev_set_node_attr_attr);
+  EXPECT_EQ(0, cras_iodev_set_node_attr_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);
@@ -648,44 +667,47 @@
   EXPECT_EQ(0, cras_alsa_jack_list_add_jack_for_section_called);
 
   cras_alsa_jack_list_create_cb(NULL, 1, cras_alsa_jack_list_create_cb_data);
-  EXPECT_EQ(1, cras_iodev_set_node_plugged_called);
-  EXPECT_EQ(1, cras_iodev_set_node_plugged_value);
+  EXPECT_EQ(1, cras_iodev_set_node_attr_called);
+  EXPECT_EQ(IONODE_ATTR_PLUGGED, cras_iodev_set_node_attr_attr);
+  EXPECT_EQ(1, cras_iodev_set_node_attr_value);
   cras_alsa_jack_list_create_cb(NULL, 0, cras_alsa_jack_list_create_cb_data);
-  EXPECT_EQ(2, cras_iodev_set_node_plugged_called);
-  EXPECT_EQ(0, cras_iodev_set_node_plugged_value);
+  EXPECT_EQ(2, cras_iodev_set_node_attr_called);
+  EXPECT_EQ(IONODE_ATTR_PLUGGED, cras_iodev_set_node_attr_attr);
+  EXPECT_EQ(0, cras_iodev_set_node_attr_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);
@@ -711,20 +733,22 @@
 }
 
 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;
 
   ResetStubData();
   // Set default node gain to -1000 * 0.01 dB.
-  ucm_get_default_node_gain_values[INTERNAL_MICROPHONE] = default_node_gain;
+  ucm_get_default_node_gain_values["Internal Mic"] = 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);
@@ -746,18 +770,20 @@
 }
 
 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;
@@ -788,13 +814,15 @@
 }
 
 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);
 
@@ -804,13 +832,14 @@
 }
 
 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);
 
@@ -830,13 +859,14 @@
 }
 
 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);
 
@@ -850,123 +880,98 @@
 }
 
 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_EQ(1, cras_alsa_jack_get_dsp_name_called);
   EXPECT_STREQ("hello", cras_iodev_update_dsp_name);
 
-  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;
-
-  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(
-      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));
-  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;
 
   ResetStubData();
   ucm_get_dsp_name_default_value = "default_dsp";
-  aio = (struct alsa_io*)alsa_iodev_create_with_default_parameters(
+  cras_alsa_jack_get_dsp_name_value = "override_dsp";
+  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);
+  EXPECT_EQ(1, cras_alsa_jack_get_dsp_name_called);
   EXPECT_EQ(1, cras_iodev_update_dsp_called);
   EXPECT_STREQ("default_dsp", cras_iodev_update_dsp_name);
 
-  cras_alsa_jack_get_name_ret_value = jack_name;
-  ucm_get_dsp_name_for_dev_values[jack_name] = "override_dsp";
   // Add the jack node.
   cras_alsa_jack_list_create_cb(jack, 1, cras_alsa_jack_list_create_cb_data);
-  EXPECT_EQ(2, cras_alsa_jack_get_name_called);
-  EXPECT_EQ(2, ucm_get_dsp_name_for_dev_called);
   EXPECT_EQ(1, ucm_get_dsp_name_default_called);
 
   // Mark the jack node as active.
   alsa_iodev_set_active_node(&aio->base, aio->base.nodes->next, 1);
-  EXPECT_EQ(2, ucm_get_dsp_name_for_dev_called);
+  EXPECT_EQ(2, cras_alsa_jack_get_dsp_name_called);
   EXPECT_EQ(2, cras_iodev_update_dsp_called);
   EXPECT_STREQ("override_dsp", cras_iodev_update_dsp_name);
 
   // Mark the default node as active.
   alsa_iodev_set_active_node(&aio->base, aio->base.nodes, 1);
   EXPECT_EQ(1, ucm_get_dsp_name_default_called);
-  EXPECT_EQ(2, ucm_get_dsp_name_for_dev_called);
+  EXPECT_EQ(3, cras_alsa_jack_get_dsp_name_called);
   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. */
@@ -974,12 +979,12 @@
 
   // 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);
 
@@ -987,33 +992,33 @@
   // 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);
@@ -1028,36 +1033,36 @@
   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);
+  EXPECT_EQ(2, alsa_mixer_set_mute_called);
   EXPECT_EQ(outputs[1], alsa_mixer_set_mute_output);
   EXPECT_EQ(1, alsa_mixer_set_dBFS_called);
   EXPECT_EQ(outputs[1], alsa_mixer_set_dBFS_output);
@@ -1071,46 +1076,46 @@
   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);
-  cras_alsa_mixer_get_control_name_values[output] = HEADPHONE;
+  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");
-  ucm_section_set_mixer_name(section, HEADPHONE);
+  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");
-  ucm_section_set_mixer_name(section, HEADPHONE);
+  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);
@@ -1119,56 +1124,58 @@
   // 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);
-  EXPECT_STREQ(cras_iodev_set_node_plugged_ionode->name, HEADPHONE);
+  jack_output_plug_event(reinterpret_cast<struct cras_alsa_jack *>(10), 0, aio);
+  EXPECT_STREQ(cras_iodev_set_node_attr_ionode->name, "Headphone");
 
-  jack_output_plug_event(reinterpret_cast<struct cras_alsa_jack*>(20), 0, aio);
-  EXPECT_STREQ(cras_iodev_set_node_plugged_ionode->name, "Line Out");
+  jack_output_plug_event(reinterpret_cast<struct cras_alsa_jack *>(20), 0, aio);
+  EXPECT_STREQ(cras_iodev_set_node_attr_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;
-  cras_alsa_mixer_get_control_name_values[outputs[1]] = HEADPHONE;
+  cras_alsa_mixer_get_control_name_values[outputs[1]] = "Headphone";
   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;
@@ -1182,8 +1189,8 @@
   // 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);
-  EXPECT_EQ(0, cras_iodev_set_node_plugged_called);
+  jack_output_plug_event(reinterpret_cast<struct cras_alsa_jack *>(4), 0, aio);
+  EXPECT_EQ(0, cras_iodev_set_node_attr_called);
 
   // Complete initialization, and make first node active.
   alsa_iodev_ucm_complete_init(iodev);
@@ -1193,12 +1200,12 @@
   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);
   EXPECT_EQ(0, rc);
-  EXPECT_EQ(1, alsa_mixer_set_mute_called);
+  EXPECT_EQ(2, alsa_mixer_set_mute_called);
   EXPECT_EQ(outputs[1], alsa_mixer_set_mute_output);
   EXPECT_EQ(1, alsa_mixer_set_dBFS_called);
   EXPECT_EQ(outputs[1], alsa_mixer_set_dBFS_output);
@@ -1214,31 +1221,33 @@
   // 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);
-  EXPECT_EQ(1, cras_iodev_set_node_plugged_called);
+  jack_output_plug_event(reinterpret_cast<struct cras_alsa_jack *>(4), 0, aio);
+  EXPECT_EQ(1, cras_iodev_set_node_attr_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;
@@ -1260,27 +1269,29 @@
 }
 
 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);
@@ -1300,35 +1311,37 @@
 }
 
 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;
+  cras_alsa_mixer_get_control_name_values[inputs[0]] = "Internal Mic";
+  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));
@@ -1339,24 +1352,24 @@
   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);
+  section = ucm_section_create("Mic", 0, CRAS_STREAM_INPUT, jack_name, "hctl");
+  ucm_section_set_mixer_name(section, "Mic");
   ASSERT_EQ(0, alsa_iodev_ucm_add_nodes_and_jacks(iodev, section));
   ucm_section_free_list(section);
 
   // 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);
-  EXPECT_EQ(0, cras_iodev_set_node_plugged_called);
+  jack_input_plug_event(reinterpret_cast<struct cras_alsa_jack *>(4), 0, aio);
+  EXPECT_EQ(0, cras_iodev_set_node_attr_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);
-  EXPECT_EQ(1, cras_iodev_set_node_plugged_called);
+  jack_input_plug_event(reinterpret_cast<struct cras_alsa_jack *>(4), 0, aio);
+  EXPECT_EQ(1, cras_iodev_set_node_attr_called);
 
   // Complete initialization, and make first node active.
   alsa_iodev_ucm_complete_init(iodev);
@@ -1369,7 +1382,7 @@
   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);
@@ -1389,23 +1402,25 @@
 }
 
 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;
@@ -1428,25 +1443,27 @@
 }
 
 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);
-  section = ucm_section_create(MIC, 0, CRAS_STREAM_INPUT, jack_name, "hctl");
+      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);
   EXPECT_EQ(1, cras_iodev_add_node_called);
@@ -1465,36 +1482,36 @@
 }
 
 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);
 
   cras_alsa_mixer_get_control_name_values[outputs[0]] = INTERNAL_SPEAKER;
-  cras_alsa_mixer_get_control_name_values[outputs[1]] = HEADPHONE;
+  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
@@ -1507,38 +1524,38 @@
   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);
 
   cras_alsa_mixer_get_control_name_values[inputs[0]] = INTERNAL_MICROPHONE;
-  cras_alsa_mixer_get_control_name_values[inputs[1]] = MIC;
+  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
@@ -1551,7 +1568,7 @@
   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) {
@@ -1571,7 +1588,7 @@
 
   memset(&node, 0, sizeof(node));
   node.dev = &dev;
-  strcpy(node.name, INTERNAL_SPEAKER);
+  strcpy(node.name, "Speaker");
   dev.direction = CRAS_STREAM_OUTPUT;
   set_node_initial_state(&node, ALSA_CARD_TYPE_INTERNAL);
   ASSERT_EQ(1, node.plugged);
@@ -1581,7 +1598,7 @@
 
   memset(&node, 0, sizeof(node));
   node.dev = &dev;
-  strcpy(node.name, INTERNAL_MICROPHONE);
+  strcpy(node.name, "Internal Mic");
   dev.direction = CRAS_STREAM_INPUT;
   set_node_initial_state(&node, ALSA_CARD_TYPE_INTERNAL);
   ASSERT_EQ(1, node.plugged);
@@ -1591,7 +1608,7 @@
 
   memset(&node, 0, sizeof(node));
   node.dev = &dev;
-  strcpy(node.name, HDMI);
+  strcpy(node.name, "HDMI");
   dev.direction = CRAS_STREAM_OUTPUT;
   set_node_initial_state(&node, ALSA_CARD_TYPE_INTERNAL);
   ASSERT_EQ(0, node.plugged);
@@ -1628,7 +1645,7 @@
 
   memset(&node, 0, sizeof(node));
   node.dev = &dev;
-  strcpy(node.name, HEADPHONE);
+  strcpy(node.name, "Headphone");
   dev.direction = CRAS_STREAM_OUTPUT;
   set_node_initial_state(&node, ALSA_CARD_TYPE_INTERNAL);
   ASSERT_EQ(0, node.plugged);
@@ -1646,7 +1663,7 @@
 
   memset(&node, 0, sizeof(node));
   node.dev = &dev;
-  strcpy(node.name, MIC);
+  strcpy(node.name, "Mic");
   dev.direction = CRAS_STREAM_INPUT;
   set_node_initial_state(&node, ALSA_CARD_TYPE_INTERNAL);
   ASSERT_EQ(0, node.plugged);
@@ -1697,8 +1714,8 @@
   ASSERT_EQ(0, node.plugged);
   ASSERT_EQ(CRAS_NODE_TYPE_MIC, node.type);
   ASSERT_EQ(NODE_POSITION_EXTERNAL, node.position);
-  // Node name is changed to "MIC".
-  ASSERT_EQ(0, strcmp(node.name, MIC));
+  // Node name is changed to "Mic".
+  ASSERT_EQ(0, strcmp(node.name, "Mic"));
 
   memset(&node, 0, sizeof(node));
   node.dev = &dev;
@@ -1709,11 +1726,11 @@
   ASSERT_EQ(CRAS_NODE_TYPE_HEADPHONE, node.type);
   ASSERT_EQ(NODE_POSITION_EXTERNAL, node.position);
   // Node name is changed to "Headphone".
-  ASSERT_EQ(0, strcmp(node.name, HEADPHONE));
+  ASSERT_EQ(0, strcmp(node.name, "Headphone"));
 
   memset(&node, 0, sizeof(node));
   node.dev = &dev;
-  strcpy(node.name, INTERNAL_SPEAKER);
+  strcpy(node.name, "Speaker");
   dev.direction = CRAS_STREAM_OUTPUT;
   set_node_initial_state(&node, ALSA_CARD_TYPE_USB);
   ASSERT_EQ(1, node.plugged);
@@ -1753,37 +1770,37 @@
   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;
   set_node_initial_state(&node, ALSA_CARD_TYPE_USB);
   ASSERT_EQ(CRAS_NODE_TYPE_USB, node.type);
-  ASSERT_STREQ(USB, node.name);
+  ASSERT_STREQ("USB", node.name);
 
   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;
   set_node_initial_state(&node, ALSA_CARD_TYPE_INTERNAL);
   ASSERT_EQ(CRAS_NODE_TYPE_HDMI, node.type);
-  ASSERT_STREQ(HDMI, node.name);
+  ASSERT_STREQ("HDMI", node.name);
 }
 
 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.
@@ -1798,56 +1815,60 @@
   EXPECT_EQ(2, cras_alsa_jack_get_name_called);
   ASSERT_EQ(CRAS_NODE_TYPE_HDMI, aio->base.nodes->next->type);
   // The node name should be "HDMI".
-  ASSERT_STREQ(HDMI, aio->base.nodes->next->name);
+  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);
+  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_] = "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;
-  }
+      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;
-  }
+    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 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);
@@ -1858,24 +1879,25 @@
   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;
-  cras_alsa_jack_get_name_ret_value = HEADPHONE;
-  cras_card_config_get_volume_curve_vals[HEADPHONE] = &hp_curve;
+  cras_alsa_jack_get_name_ret_value = "Headphone";
+  cras_card_config_get_volume_curve_vals["Headphone"] = &hp_curve;
   cras_alsa_jack_list_create_cb(jack, 1, cras_alsa_jack_list_create_cb_data);
   EXPECT_EQ(1, cras_alsa_jack_update_node_type_called);
   EXPECT_EQ(3, cras_card_config_get_volume_curve_for_control_called);
@@ -1895,16 +1917,16 @@
 
 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);
@@ -1938,7 +1960,7 @@
   // 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);
 }
@@ -1946,7 +1968,7 @@
 TEST_F(AlsaVolumeMuteSuite, SetMute) {
   int muted;
 
-  aio_output_->handle = (snd_pcm_t*)0x24;
+  aio_output_->handle = (snd_pcm_t *)0x24;
 
   // Test mute.
   ResetStubData();
@@ -1976,28 +1998,31 @@
 }
 
 //  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));
-  }
+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); }
+    virtual void TearDown() {
+      free(cras_alsa_mmap_begin_buffer);
+    }
 
   struct alsa_io aio;
   struct cras_audio_format fmt_;
@@ -2005,12 +2030,13 @@
 
 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);
@@ -2020,7 +2046,7 @@
   int rc;
 
   // Device is in free run state, no need to fill zeros or fill whole buffer.
-  aio.free_running = 1;
+  aio.is_free_running = 1;
 
   rc = no_stream(&aio.base, 1);
 
@@ -2033,9 +2059,10 @@
 TEST_F(AlsaFreeRunTestSuite, EnterFreeRunNotDrainedYetNeedToFillZeros) {
   int rc, real_hw_level;
   struct timespec hw_tstamp;
-  int fill_zeros_duration = 50;
   // Device is not in free run state. There are still valid samples to play.
-  // In cras_alsa_io.c, we defined there are 50ms zeros to be filled.
+  // The number of valid samples is less than min_cb_level * 2.
+  // Need to fill zeros targeting min_cb_level * 2 = 480.
+  // The number of zeros to be filled is 480 - 200 = 280.
   real_hw_level = 200;
   cras_alsa_get_avail_frames_avail = BUFFER_SIZE - real_hw_level;
 
@@ -2047,31 +2074,26 @@
   EXPECT_EQ(0, rc);
   EXPECT_EQ(0, cras_alsa_mmap_get_whole_buffer_called);
   EXPECT_EQ(1, cras_iodev_fill_odev_zeros_called);
-  EXPECT_EQ(fmt_.frame_rate / 1000 * fill_zeros_duration,
-            cras_iodev_fill_odev_zeros_frames);
-  EXPECT_EQ(fmt_.frame_rate / 1000 * fill_zeros_duration,
-            aio.filled_zeros_for_draining);
-  EXPECT_EQ(0, aio.free_running);
+  EXPECT_EQ(280, cras_iodev_fill_odev_zeros_frames);
+  EXPECT_EQ(280, aio.filled_zeros_for_draining);
+  EXPECT_EQ(0, aio.is_free_running);
 }
 
-TEST_F(AlsaFreeRunTestSuite, EnterFreeRunNotDrainedYetFillZerosExceedBuffer) {
+TEST_F(AlsaFreeRunTestSuite, EnterFreeRunNotDrainedYetNoNeedToFillZeros) {
   int rc, real_hw_level;
 
   // Device is not in free run state. There are still valid samples to play.
-  // If frames avail is smaller than 50ms(48 * 50 = 2400 zeros), only fill
-  // zeros until buffer size.
-  real_hw_level = 7000;
+  // The number of valid samples is more than min_cb_level * 2.
+  // No need to fill zeros.
+  real_hw_level = 500;
   cras_alsa_get_avail_frames_avail = BUFFER_SIZE - real_hw_level;
 
   rc = no_stream(&aio.base, 1);
 
   EXPECT_EQ(0, rc);
   EXPECT_EQ(0, cras_alsa_mmap_get_whole_buffer_called);
-  EXPECT_EQ(1, cras_iodev_fill_odev_zeros_called);
-  EXPECT_EQ(cras_alsa_get_avail_frames_avail,
-            cras_iodev_fill_odev_zeros_frames);
-  EXPECT_EQ(cras_alsa_get_avail_frames_avail, aio.filled_zeros_for_draining);
-  EXPECT_EQ(0, aio.free_running);
+  EXPECT_EQ(0, cras_iodev_fill_odev_zeros_called);
+  EXPECT_EQ(0, aio.is_free_running);
 }
 
 TEST_F(AlsaFreeRunTestSuite, EnterFreeRunDrained) {
@@ -2089,7 +2111,7 @@
   EXPECT_EQ(0, rc);
   EXPECT_EQ(1, cras_alsa_mmap_get_whole_buffer_called);
   EXPECT_EQ(0, cras_iodev_fill_odev_zeros_called);
-  EXPECT_EQ(1, aio.free_running);
+  EXPECT_EQ(1, aio.is_free_running);
 }
 
 TEST_F(AlsaFreeRunTestSuite, EnterFreeRunNoSamples) {
@@ -2105,15 +2127,24 @@
   EXPECT_EQ(0, rc);
   EXPECT_EQ(1, cras_alsa_mmap_get_whole_buffer_called);
   EXPECT_EQ(0, cras_iodev_fill_odev_zeros_called);
-  EXPECT_EQ(1, aio.free_running);
+  EXPECT_EQ(1, aio.is_free_running);
 }
 
-TEST_F(AlsaFreeRunTestSuite, IsFreeRunning) {
-  aio.free_running = 1;
-  EXPECT_EQ(1, is_free_running(&aio.base));
+TEST_F(AlsaFreeRunTestSuite, OutputShouldWake) {
 
-  aio.free_running = 0;
-  EXPECT_EQ(0, is_free_running(&aio.base));
+  aio.is_free_running = 1;
+
+  EXPECT_EQ(0, output_should_wake(&aio.base));
+
+  aio.is_free_running = 0;
+  aio.base.state = CRAS_IODEV_STATE_NO_STREAM_RUN;
+  EXPECT_EQ(1, output_should_wake(&aio.base));
+
+  aio.base.state = CRAS_IODEV_STATE_NORMAL_RUN;
+  EXPECT_EQ(1, output_should_wake(&aio.base));
+
+  aio.base.state = CRAS_IODEV_STATE_OPEN;
+  EXPECT_EQ(0, output_should_wake(&aio.base));
 }
 
 TEST_F(AlsaFreeRunTestSuite, LeaveFreeRunNotInFreeRunMoreRemain) {
@@ -2122,7 +2153,7 @@
   // Compare min_buffer_level + min_cb_level with valid samples left.
   // 240 + 512 < 900 - 100, so we will get 900 - 100 in appl_ptr_ahead.
 
-  aio.free_running = 0;
+  aio.is_free_running = 0;
   aio.filled_zeros_for_draining = 100;
   aio.base.min_buffer_level = 512;
   real_hw_level = 900;
@@ -2134,7 +2165,7 @@
   EXPECT_EQ(1, cras_alsa_resume_appl_ptr_called);
   EXPECT_EQ(800, cras_alsa_resume_appl_ptr_ahead);
   EXPECT_EQ(0, cras_iodev_fill_odev_zeros_frames);
-  EXPECT_EQ(0, aio.free_running);
+  EXPECT_EQ(0, aio.is_free_running);
   EXPECT_EQ(0, aio.filled_zeros_for_draining);
 }
 
@@ -2145,7 +2176,7 @@
   // 240 + 256 > 400 - 500, so we will get 240 + 256 in appl_ptr_ahead.
   // And it will fill 240 + 256 - 400 = 96 zeros frames into device.
 
-  aio.free_running = 0;
+  aio.is_free_running = 0;
   aio.filled_zeros_for_draining = 500;
   aio.base.min_buffer_level = 256;
   real_hw_level = 400;
@@ -2158,14 +2189,14 @@
   EXPECT_EQ(aio.base.min_buffer_level + aio.base.min_cb_level,
             cras_alsa_resume_appl_ptr_ahead);
   EXPECT_EQ(96, cras_iodev_fill_odev_zeros_frames);
-  EXPECT_EQ(0, aio.free_running);
+  EXPECT_EQ(0, aio.is_free_running);
   EXPECT_EQ(0, aio.filled_zeros_for_draining);
 }
 
 TEST_F(AlsaFreeRunTestSuite, LeaveFreeRunInFreeRun) {
   int rc;
 
-  aio.free_running = 1;
+  aio.is_free_running = 1;
   aio.filled_zeros_for_draining = 100;
   aio.base.min_buffer_level = 512;
 
@@ -2175,7 +2206,7 @@
   EXPECT_EQ(1, cras_alsa_resume_appl_ptr_called);
   EXPECT_EQ(aio.base.min_buffer_level + aio.base.min_cb_level,
             cras_alsa_resume_appl_ptr_ahead);
-  EXPECT_EQ(0, aio.free_running);
+  EXPECT_EQ(0, aio.is_free_running);
   EXPECT_EQ(0, aio.filled_zeros_for_draining);
 }
 
@@ -2183,8 +2214,7 @@
 // similar.
 TEST_F(AlsaFreeRunTestSuite, OutputUnderrun) {
   int rc;
-  int16_t* zeros;
-  snd_pcm_uframes_t offset;
+  int16_t *zeros;
 
   aio.num_underruns = 0;
 
@@ -2194,24 +2224,23 @@
   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
+  // appl_ptr should be moved to min_buffer_level + min_cb_level ahead of
   // hw_ptr.
-  offset = aio.base.min_buffer_level + aio.base.min_cb_level +
-           aio.base.min_cb_level / 2;
   EXPECT_EQ(1, cras_alsa_resume_appl_ptr_called);
-  EXPECT_EQ(offset, cras_alsa_resume_appl_ptr_ahead);
+  EXPECT_EQ(aio.base.min_buffer_level + aio.base.min_cb_level,
+            cras_alsa_resume_appl_ptr_ahead);
 
   free(zeros);
 }
 
 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();
@@ -2224,7 +2253,7 @@
 
   memset(&alsa_node, 0, sizeof(alsa_node));
   node->dev = iodev;
-  strcpy(node->name, HOTWORD_DEV);
+  strcpy(node->name, "Wake on Voice");
   set_node_initial_state(node, ALSA_CARD_TYPE_INTERNAL);
   EXPECT_EQ(CRAS_NODE_TYPE_HOTWORD, node->type);
 
@@ -2240,58 +2269,9 @@
   alsa_iodev_destroy(iodev);
 }
 
-TEST(AlsaGetValidFrames, GetValidFramesNormalState) {
-  struct cras_iodev* iodev;
-  struct alsa_io* aio;
-  struct timespec tstamp;
-  int rc;
-
-  ResetStubData();
-  iodev = alsa_iodev_create_with_default_parameters(
-      0, NULL, ALSA_CARD_TYPE_INTERNAL, 0, fake_mixer, fake_config, NULL,
-      CRAS_STREAM_OUTPUT);
-  aio = (struct alsa_io*)iodev;
-
-  aio->free_running = 0;
-  aio->filled_zeros_for_draining = 200;
-  cras_alsa_get_avail_frames_avail = iodev->buffer_size - 500;
-  cras_alsa_get_avail_frames_ret = 0;
-  clock_gettime_retspec.tv_sec = 123;
-  clock_gettime_retspec.tv_nsec = 321;
-  rc = iodev->get_valid_frames(iodev, &tstamp);
-  EXPECT_EQ(rc, 300);
-  EXPECT_EQ(tstamp.tv_sec, clock_gettime_retspec.tv_sec);
-  EXPECT_EQ(tstamp.tv_nsec, clock_gettime_retspec.tv_nsec);
-
-  alsa_iodev_destroy(iodev);
-}
-
-TEST(AlsaGetValidFrames, GetValidFramesFreeRunning) {
-  struct cras_iodev* iodev;
-  struct alsa_io* aio;
-  struct timespec tstamp;
-  int rc;
-
-  ResetStubData();
-  iodev = alsa_iodev_create_with_default_parameters(
-      0, NULL, ALSA_CARD_TYPE_INTERNAL, 0, fake_mixer, fake_config, NULL,
-      CRAS_STREAM_OUTPUT);
-  aio = (struct alsa_io*)iodev;
-
-  aio->free_running = 1;
-  clock_gettime_retspec.tv_sec = 123;
-  clock_gettime_retspec.tv_nsec = 321;
-  rc = iodev->get_valid_frames(iodev, &tstamp);
-  EXPECT_EQ(rc, 0);
-  EXPECT_EQ(tstamp.tv_sec, clock_gettime_retspec.tv_sec);
-  EXPECT_EQ(tstamp.tv_nsec, clock_gettime_retspec.tv_nsec);
-
-  alsa_iodev_destroy(iodev);
-}
-
 }  //  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();
@@ -2302,152 +2282,172 @@
 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) {
+				      const char *model_name)
+{
+	return 0;
+}
+
+int cras_iodev_list_suspend_hotword_streams()
+{
   return 0;
 }
 
-int cras_iodev_list_suspend_hotword_streams() {
+int cras_iodev_list_resume_hotword_stream()
+{
   return 0;
 }
 
-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);
@@ -2457,186 +2457,220 @@
 }
 
 //  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) {}
-
-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;
+void cras_volume_curve_destroy(struct cras_volume_curve *curve)
+{
 }
 
-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_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;
 }
 
-int cras_alsa_mixer_has_main_volume(const struct cras_alsa_mixer* cras_mixer) {
+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)
+{
   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 *cras_alsa_jack_get_dsp_name(const struct cras_alsa_jack *jack)
+{
+  cras_alsa_jack_get_dsp_name_called++;
+  return jack ? cras_alsa_jack_get_dsp_name_value : NULL;
+}
+
+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);
@@ -2644,41 +2678,30 @@
     return NULL;
 }
 
-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)
-    return NULL;
-  it = ucm_get_dsp_name_for_dev_values.find(dev);
-  if (it == ucm_get_dsp_name_for_dev_values.end())
-    return NULL;
-  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;
   }
@@ -2686,88 +2709,99 @@
   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)
@@ -2778,73 +2812,93 @@
   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) {
-  cras_iodev_set_node_plugged_called++;
-  cras_iodev_set_node_plugged_ionode = ionode;
-  cras_iodev_set_node_plugged_value = plugged;
-  if (ionode)
-    ionode->plugged = plugged;
+int cras_iodev_set_node_attr(struct cras_ionode *ionode,
+			     enum ionode_attr attr, int value)
+{
+  cras_iodev_set_node_attr_called++;
+  cras_iodev_set_node_attr_ionode = ionode;
+  cras_iodev_set_node_attr_attr = attr;
+  cras_iodev_set_node_attr_value = value;
+  if (ionode && (attr == IONODE_ATTR_PLUGGED))
+    ionode->plugged = value;
+  return 0;
 }
 
-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;
@@ -2853,57 +2907,70 @@
   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;
@@ -2911,34 +2978,40 @@
   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;
 }
@@ -2947,11 +3020,4 @@
   return (struct cras_ramp*)0x1;
 }
 
-//  From librt.
-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"
diff --git a/cras/src/tests/alsa_jack_unittest.cc b/cras/src/tests/alsa_jack_unittest.cc
index 24b43a3..a739c70 100644
--- a/cras/src/tests/alsa_jack_unittest.cc
+++ b/cras/src/tests/alsa_jack_unittest.cc
@@ -2,16 +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 <deque>
 #include <linux/input.h>
+#include <map>
 #include <poll.h>
 #include <stdio.h>
 #include <sys/param.h>
-#include <syslog.h>
-
-#include <deque>
-#include <map>
+#include <gtest/gtest.h>
 #include <string>
+#include <syslog.h>
 #include <vector>
 
 extern "C" {
@@ -25,51 +24,51 @@
 
 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;
@@ -79,15 +78,16 @@
 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 size_t ucm_get_dsp_name_called;
 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;
@@ -101,7 +101,7 @@
   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();
@@ -121,30 +121,32 @@
   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;
   ucm_get_dev_for_jack_return = false;
   edid_file_ret = NULL;
+  ucm_get_dsp_name_called = 0;
   ucm_get_override_type_name_called = 0;
   ucm_get_device_name_for_dev_value = NULL;
 
   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,12 +159,15 @@
 }
 
 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);
@@ -173,14 +178,17 @@
 }
 
 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);
@@ -192,25 +200,31 @@
   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]));
+        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(0, cras_alsa_jack_list_find_jacks_by_name_matching(jack_list));
@@ -235,17 +249,17 @@
   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;
@@ -253,21 +267,28 @@
         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_EQ(njacks, ucm_get_dsp_name_called);
+    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);
-    return NULL;
+  if (add_jack_rc != 0 || njacks != ucm_get_dsp_name_called) {
+      cras_alsa_jack_list_destroy(jack_list);
+      return NULL;
   }
   EXPECT_EQ(njacks, snd_hctl_elem_set_callback_called);
   EXPECT_EQ(njacks, cras_alsa_mixer_get_control_for_section_called);
@@ -281,23 +302,28 @@
 
 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");
@@ -305,10 +331,13 @@
   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);
@@ -320,7 +349,7 @@
 }
 
 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");
@@ -328,16 +357,23 @@
   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);
@@ -347,7 +383,7 @@
 }
 
 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");
@@ -355,10 +391,13 @@
   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);
 
@@ -375,14 +414,16 @@
   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;
@@ -394,10 +435,14 @@
   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);
@@ -419,8 +464,9 @@
   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) {
@@ -435,8 +481,9 @@
   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) {
@@ -451,8 +498,9 @@
   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) {
@@ -467,8 +515,9 @@
   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) {
@@ -483,8 +532,9 @@
   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) {
@@ -499,8 +549,9 @@
   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) {
@@ -515,8 +566,9 @@
   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) {
@@ -532,8 +584,9 @@
   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) {
@@ -549,8 +602,9 @@
   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) {
@@ -564,9 +618,16 @@
   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);
@@ -585,16 +646,19 @@
 }
 
 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);
@@ -606,30 +670,35 @@
 
 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;
@@ -645,15 +714,23 @@
 
 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);
@@ -666,16 +743,26 @@
 }
 
 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);
@@ -684,32 +771,36 @@
 
 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);
+  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_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;
@@ -722,11 +813,11 @@
 
 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");
@@ -735,19 +826,25 @@
   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);
+      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_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;
@@ -760,9 +857,9 @@
 }
 
 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");
@@ -773,12 +870,15 @@
   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);
@@ -800,11 +900,11 @@
 
 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");
@@ -813,20 +913,26 @@
   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);
@@ -835,9 +941,15 @@
   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);
 }
@@ -848,83 +960,87 @@
 
 // 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())
@@ -934,44 +1050,48 @@
 }
 
 // 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);
@@ -980,7 +1100,8 @@
   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
    */
@@ -989,7 +1110,8 @@
   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.
@@ -998,16 +1120,18 @@
   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;
@@ -1015,73 +1139,81 @@
   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_dsp_name(struct cras_use_case_mgr *mgr, const char *ucm_dev,
+                       int direction) {
+  ++ucm_get_dsp_name_called;
+  return NULL;
+}
+
+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;
 }
@@ -1096,7 +1228,7 @@
 
 }  //  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 d61ba3d..2deef7f 100644
--- a/cras/src/tests/alsa_mixer_unittest.cc
+++ b/cras/src/tests/alsa_mixer_unittest.cc
@@ -2,12 +2,11 @@
 // 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 <syslog.h>
-
+#include <gtest/gtest.h>
 #include <map>
 #include <string>
+#include <syslog.h>
 #include <vector>
 
 extern "C" {
@@ -30,60 +29,60 @@
 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;
@@ -96,88 +95,88 @@
   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"));
@@ -186,12 +185,12 @@
 }
 
 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"));
@@ -201,12 +200,12 @@
 }
 
 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"));
@@ -217,11 +216,12 @@
 }
 
 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,28 +241,29 @@
 }
 
 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"));
@@ -284,7 +285,7 @@
   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);
@@ -305,26 +306,26 @@
 }
 
 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);
@@ -333,8 +334,9 @@
   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"));
@@ -359,7 +361,7 @@
   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);
@@ -382,24 +384,27 @@
 }
 
 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,
+    1,
+    1,
   };
-  const char* element_names[] = {"Master", "Playback"};
-  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);
@@ -408,8 +413,9 @@
       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"));
@@ -428,7 +434,8 @@
 
   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);
@@ -438,7 +445,7 @@
   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);
@@ -458,26 +465,26 @@
 }
 
 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};
@@ -485,7 +492,7 @@
   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;
@@ -501,9 +508,11 @@
   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);
@@ -549,7 +558,7 @@
   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);
@@ -570,8 +579,8 @@
    * 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 =
@@ -584,8 +593,8 @@
   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);
@@ -593,30 +602,30 @@
 }
 
 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;
@@ -627,8 +636,9 @@
       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"));
@@ -646,15 +656,16 @@
    * 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);
@@ -663,14 +674,15 @@
   /* 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);
@@ -683,9 +695,9 @@
    * volume control */
 
   long get_dB_returns3[] = {
-      0,
-      0,
-      0,
+    0,
+    0,
+    0,
   };
   long set_dB_values3[3];
 
@@ -694,7 +706,8 @@
       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 =
@@ -709,7 +722,7 @@
   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);
@@ -736,59 +749,86 @@
   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 *element_names[] = {
+      "Master",
+      "PCM",
+      "Headphone",
+      "Speaker",
+      "HDMI",
+      "IEC958",
+      "Capture",
+      "Digital Capture",
     };
-    static const char* output_names_extra[] = {"IEC958"};
-    static char* iniparser_returns[] = {
-        NULL,
+    static const char *output_names_extra[] = {
+      "IEC958"
     };
-    struct mixer_name* extra_controls = mixer_name_add_array(
-        NULL, output_names_extra, ARRAY_SIZE(output_names_extra),
-        CRAS_STREAM_OUTPUT, MIXER_NAME_VOLUME);
+    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);
 
     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;
@@ -800,7 +840,7 @@
     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"));
@@ -820,57 +860,62 @@
     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;
 
@@ -881,8 +926,9 @@
   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. */
@@ -894,7 +940,8 @@
 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());
@@ -908,17 +955,19 @@
 
 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;
@@ -927,12 +976,12 @@
   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};
@@ -940,11 +989,15 @@
 
   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};
 
@@ -954,13 +1007,13 @@
   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 =
@@ -973,10 +1026,10 @@
   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"));
@@ -990,11 +1043,11 @@
   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);
@@ -1007,7 +1060,8 @@
   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);
 
@@ -1035,31 +1089,35 @@
 }
 
 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 =
@@ -1072,10 +1130,10 @@
   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"));
@@ -1089,11 +1147,11 @@
   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);
@@ -1112,31 +1170,35 @@
 }
 
 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 =
@@ -1149,10 +1211,10 @@
   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"));
@@ -1166,11 +1228,11 @@
   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);
@@ -1189,45 +1251,55 @@
 }
 
 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);
@@ -1238,45 +1310,67 @@
   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,
@@ -1284,7 +1378,8 @@
     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);
@@ -1292,29 +1387,33 @@
                                  "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;
@@ -1323,7 +1422,7 @@
         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"));
@@ -1332,21 +1431,21 @@
     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);
@@ -1368,99 +1467,103 @@
     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)
@@ -1468,7 +1571,7 @@
 
   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)
@@ -1476,7 +1579,7 @@
 
   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)
@@ -1484,7 +1587,7 @@
 
   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)
@@ -1492,24 +1595,24 @@
 
   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;
@@ -1518,9 +1621,9 @@
     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)
@@ -1529,12 +1632,12 @@
     *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;
@@ -1543,9 +1646,9 @@
     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)
@@ -1554,14 +1657,13 @@
     *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) {
@@ -1573,9 +1675,9 @@
   }
   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) {
@@ -1588,8 +1690,8 @@
   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++;
@@ -1602,30 +1704,34 @@
 }
 
 //  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;
@@ -1635,7 +1741,7 @@
 
 }  //  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 0773079..3199573 100644
--- a/cras/src/tests/alsa_ucm_unittest.cc
+++ b/cras/src/tests/alsa_ucm_unittest.cc
@@ -6,7 +6,6 @@
 #include <iniparser.h>
 #include <stdio.h>
 #include <syslog.h>
-
 #include <map>
 
 extern "C" {
@@ -14,6 +13,7 @@
 #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 @@
 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 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,16 +60,17 @@
   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";
@@ -113,7 +114,7 @@
 }
 
 TEST(AlsaUcm, CreateSuccess) {
-  struct cras_use_case_mgr* mgr;
+  struct cras_use_case_mgr *mgr;
 
   ResetStubData();
 
@@ -128,7 +129,7 @@
 }
 
 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;
@@ -144,8 +145,8 @@
 }
 
 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();
 
@@ -162,10 +163,10 @@
 }
 
 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();
 
@@ -181,8 +182,8 @@
 }
 
 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";
 
@@ -200,8 +201,8 @@
 }
 
 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";
 
@@ -219,14 +220,14 @@
 }
 
 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";
@@ -252,7 +253,7 @@
   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);
@@ -260,10 +261,10 @@
 }
 
 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();
 
@@ -287,10 +288,10 @@
 }
 
 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();
 
@@ -313,10 +314,10 @@
 }
 
 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();
 
@@ -339,10 +340,10 @@
 }
 
 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();
 
@@ -355,8 +356,8 @@
 
   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);
@@ -369,10 +370,10 @@
 }
 
 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();
 
@@ -386,8 +387,7 @@
   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 @@
   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 @@
   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, 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, 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,16 +473,22 @@
   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;
@@ -491,15 +497,18 @@
   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;
@@ -513,23 +522,23 @@
   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();
 
@@ -545,12 +554,13 @@
 }
 
 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();
 
@@ -576,12 +586,13 @@
 }
 
 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();
 
@@ -604,11 +615,12 @@
   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";
@@ -626,12 +638,12 @@
 }
 
 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;
 
@@ -644,7 +656,7 @@
 }
 
 TEST(AlsaUcm, SetModifierEnabled) {
-  struct cras_use_case_mgr* mgr = &cras_ucm_mgr;
+  struct cras_use_case_mgr *mgr = &cras_ucm_mgr;
 
   ResetStubData();
 
@@ -665,9 +677,9 @@
 }
 
 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();
 
@@ -679,12 +691,12 @@
 }
 
 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"));
@@ -693,7 +705,7 @@
 }
 
 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";
@@ -710,10 +722,10 @@
 }
 
 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();
 
@@ -736,7 +748,7 @@
 
   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);
@@ -744,9 +756,9 @@
 }
 
 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();
 
@@ -757,6 +769,7 @@
   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"));
@@ -768,7 +781,7 @@
 }
 
 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";
@@ -793,7 +806,7 @@
 }
 
 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";
@@ -818,7 +831,7 @@
 }
 
 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";
@@ -843,7 +856,7 @@
 }
 
 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";
@@ -865,7 +878,7 @@
 }
 
 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";
@@ -887,10 +900,10 @@
 }
 
 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();
 
@@ -908,12 +921,12 @@
 
   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();
@@ -935,7 +948,7 @@
   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);
@@ -945,7 +958,7 @@
 }
 
 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;
 
@@ -960,15 +973,17 @@
   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;
 
@@ -983,18 +998,20 @@
   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();
 
@@ -1010,16 +1027,17 @@
   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();
 
@@ -1047,18 +1065,18 @@
   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();
 
@@ -1083,18 +1101,21 @@
 }
 
 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);
@@ -1108,7 +1129,7 @@
   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));
@@ -1118,11 +1139,12 @@
   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(
@@ -1130,14 +1152,14 @@
 
   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++;
@@ -1149,62 +1171,64 @@
 }
 
 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",
+  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",
+    "=PlaybackPCM/Speaker/HiFi",
+    "=CoupledMixers/Speaker/HiFi",
 
-                       "=CapturePCM/Mic/HiFi",
-                       "=JackName/Mic/HiFi",
-                       "=JackType/Mic/HiFi",
-                       "=JackSwitch/Mic/HiFi",
-                       "=MixerName/Mic/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",
+    "=CapturePCM/Internal Mic/HiFi",
+    "=CoupledMixers/Internal Mic/HiFi",
+    "=JackSwitch/Internal Mic/HiFi",
 
-                       "=PlaybackPCM/HDMI/HiFi",
-                       "=MixerName/HDMI/HiFi",
+    "=PlaybackPCM/HDMI/HiFi",
+    "=MixerName/HDMI/HiFi",
 
-                       NULL};
+    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",
+    "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",
+    "SPK-L,SPK-R",
 
-      "hw:my-sound-card,0",
-      "my-sound-card Headset Jack",
-      "gpio",
-      "0",
-      "CAPTURE",
+    "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,0",
+    "MIC-L,MIC-R",
+    "-10",
 
-      "hw:my-sound-card,2",
-      "HDMI",
+    "hw:my-sound-card,2",
+    "HDMI",
   };
 
   ResetStubData();
@@ -1219,7 +1243,9 @@
 
   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
@@ -1262,7 +1288,7 @@
   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);
 
@@ -1289,7 +1315,7 @@
   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);
@@ -1297,15 +1323,18 @@
 }
 
 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();
@@ -1323,17 +1352,20 @@
 }
 
 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();
@@ -1351,7 +1383,7 @@
 }
 
 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;
@@ -1367,10 +1399,10 @@
 }
 
 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();
 
@@ -1383,10 +1415,10 @@
 }
 
 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();
@@ -1396,13 +1428,13 @@
 
   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);
@@ -1425,14 +1457,14 @@
   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()) {
@@ -1444,22 +1476,22 @@
 }
 
 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 2c91cf9..b7d01c5 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 <gtest/gtest.h>
 #include <stdio.h>
+#include <gtest/gtest.h>
 
 extern "C" {
 #include "cras_apm_list.h"
@@ -18,25 +18,25 @@
 
 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 @@
   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, 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 @@
   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,12 +152,13 @@
   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);
 
@@ -168,111 +169,103 @@
   EXPECT_EQ(1, webrtc_apm_process_reverse_stream_f_called);
 
   float_buffer_destroy(&buf);
-  cras_apm_list_destroy(list);
   cras_apm_list_deinit();
 }
 
-TEST(ApmList, StreamAddToAlreadyOpenedDev) {
-  struct cras_audio_format fmt;
-  struct cras_apm *apm1, *apm2;
-
-  fmt.num_channels = 2;
-  fmt.frame_rate = 48000;
-  fmt.format = SND_PCM_FORMAT_S16_LE;
-
-  webrtc_apm_create_called = 0;
-  list = cras_apm_list_create(stream_ptr, APM_ECHO_CANCELLATION);
-  EXPECT_NE((void*)NULL, list);
-
-  apm1 = cras_apm_list_add(list, dev_ptr, &fmt);
-  EXPECT_EQ(1, webrtc_apm_create_called);
-  EXPECT_NE((void*)NULL, apm1);
-
-  apm2 = cras_apm_list_add(list, dev_ptr, &fmt);
-  EXPECT_EQ(1, webrtc_apm_create_called);
-  EXPECT_EQ(apm1, apm2);
-
-  cras_apm_list_destroy(list);
-}
-
 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) {
-  webrtc_apm_create_called++;
+			     unsigned int frame_rate,
+			     struct aec_config *aec_config,
+                             struct apm_config *apm_config)
+{
   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_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 e95cd71..00bdf06 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 "array.h"
-
 #include <gtest/gtest.h>
 
+#include "array.h"
+
 namespace {
 
 struct point {
@@ -20,7 +20,7 @@
 
   /* 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, ForLoop) {
   int i;
-  double* p;
+  double *p;
   double_array a = ARRAY_INIT;
 
   for (i = 0; i < 100; i++) {
@@ -94,7 +94,7 @@
 
   int expectedIndex = 0;
   double expectedValue = 0;
-  ARRAY_ELEMENT_FOREACH (&a, i, p) {
+  FOR_ARRAY_ELEMENT(&a, i, p) {
     EXPECT_EQ(expectedIndex, i);
     EXPECT_EQ(expectedValue, *p);
     expectedIndex++;
@@ -110,7 +110,7 @@
 
 }  //  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 091d8de..7efe3a6 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 <gtest/gtest.h>
 #include <stdio.h>
+#include <gtest/gtest.h>
 
 extern "C" {
-#include "cras_audio_area.h"
 #include "cras_audio_format.h"
+#include "cras_audio_area.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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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,31 +310,28 @@
 
 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;
+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;
-  }
+	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 f03f687..662a878 100644
--- a/cras/src/tests/audio_format_unittest.cc
+++ b/cras/src/tests/audio_format_unittest.cc
@@ -12,27 +12,27 @@
 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);
-  }
+    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;
+    struct cras_audio_format *in_fmt;
+    struct cras_audio_format *out_fmt;
+    float **conv_mtx;
 };
 
 TEST_F(ChannelConvMtxTestSuite, MatrixCreateSuccess) {
@@ -51,7 +51,7 @@
   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 @@
   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 @@
   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 9e1de63..d62c572 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 <gtest/gtest.h>
 #include <stdio.h>
+#include <gtest/gtest.h>
 
 extern "C" {
 #include "cras_audio_thread_monitor.c"
@@ -21,17 +21,20 @@
 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) {
@@ -40,30 +43,25 @@
 }
 
 TEST_F(AudioThreadMonitorTestSuite, Busyloop) {
-  cras_audio_thread_event_busyloop();
+  cras_audio_thread_busyloop();
   EXPECT_EQ(message.event_type, AUDIO_THREAD_EVENT_BUSYLOOP);
 }
 
 TEST_F(AudioThreadMonitorTestSuite, Debug) {
-  cras_audio_thread_event_debug();
+  cras_audio_thread_debug();
   EXPECT_EQ(message.event_type, AUDIO_THREAD_EVENT_DEBUG);
 }
 
 TEST_F(AudioThreadMonitorTestSuite, Underrun) {
-  cras_audio_thread_event_underrun();
+  cras_audio_thread_underrun();
   EXPECT_EQ(message.event_type, AUDIO_THREAD_EVENT_UNDERRUN);
 }
 
 TEST_F(AudioThreadMonitorTestSuite, SevereUnderrun) {
-  cras_audio_thread_event_severe_underrun();
+  cras_audio_thread_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);
@@ -73,12 +71,12 @@
 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);
 }
@@ -86,7 +84,7 @@
 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);
 }
@@ -94,28 +92,28 @@
 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;
 }
@@ -123,7 +121,7 @@
 }  // 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 e06514e..083dab1 100644
--- a/cras/src/tests/audio_thread_unittest.cc
+++ b/cras/src/tests/audio_thread_unittest.cc
@@ -4,66 +4,48 @@
 
 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_event_busyloop_called;
+static int cras_audio_thread_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;
 static int dev_stream_playback_frames_ret;
-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 int cras_iodev_get_valid_frames_ret;
+static struct cras_iodev *cras_iodev_reset_request_iodev;
 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 int cras_device_monitor_set_device_mute_state_called;
-static int cras_iodev_is_zero_volume_ret;
+static std::map<const struct dev_stream*, struct timespec> dev_stream_wake_time_val;
 
 void ResetGlobalStubData() {
   cras_rstream_dev_offset_called = 0;
   cras_rstream_dev_offset_update_called = 0;
-  cras_rstream_is_pending_reply_ret = 0;
   for (int i = 0; i < MAX_CALLS; i++) {
     cras_rstream_dev_offset_ret[i] = 0;
     cras_rstream_dev_offset_rstream_val[i] = NULL;
@@ -83,164 +65,141 @@
   cras_iodev_fill_odev_zeros_frames = 0;
   cras_iodev_frames_to_play_in_sleep_called = 0;
   dev_stream_playback_frames_ret = 0;
-  dev_stream_mix_called = 0;
-  dev_stream_request_playback_samples_called = 0;
-  dev_stream_update_next_wake_time_called = 0;
   cras_iodev_prepare_output_before_write_samples_called = 0;
   cras_iodev_prepare_output_before_write_samples_state = CRAS_IODEV_STATE_OPEN;
   cras_iodev_get_output_buffer_called = 0;
   cras_iodev_prepare_output_before_write_samples_ret = 0;
   cras_iodev_reset_request_called = 0;
   cras_iodev_reset_request_iodev = NULL;
-  cras_iodev_get_valid_frames_ret = 0;
   cras_iodev_output_underrun_called = 0;
-  cras_iodev_start_stream_called = 0;
   cras_device_monitor_reset_device_called = 0;
   cras_device_monitor_reset_device_iodev = NULL;
   cras_iodev_start_ramp_odev = NULL;
   cras_iodev_start_ramp_request = CRAS_IODEV_RAMP_REQUEST_UP_START_PLAYBACK;
-  cras_device_monitor_set_device_mute_state_called = 0;
-  cras_iodev_is_zero_volume_ret = 0;
-  clock_gettime_retspec.tv_sec = 0;
-  clock_gettime_retspec.tv_nsec = 0;
   dev_stream_wake_time_val.clear();
 }
 
-void SetupRstream(struct cras_rstream* rstream,
-                  enum CRAS_STREAM_DIRECTION direction) {
-  uint32_t frame_bytes = 4;
-  uint32_t used_size = 4096 * frame_bytes;
-
-  memset(rstream, 0, sizeof(*rstream));
-  rstream->direction = direction;
-  rstream->cb_threshold = 480;
-  rstream->format.frame_rate = 48000;
-
-  rstream->shm = static_cast<cras_audio_shm*>(calloc(1, sizeof(*rstream->shm)));
-  rstream->shm->header = static_cast<cras_audio_shm_header*>(
-      calloc(1, sizeof(*rstream->shm->header)));
-
-  rstream->shm->samples = static_cast<uint8_t*>(
-      calloc(1, cras_shm_calculate_samples_size(used_size)));
-
-  cras_shm_set_frame_bytes(rstream->shm, frame_bytes);
-  cras_shm_set_used_size(rstream->shm, used_size);
-}
-
-void TearDownRstream(struct cras_rstream* rstream) {
-  free(rstream->shm->samples);
-  free(rstream->shm->header);
-  free(rstream->shm);
-}
-
 // 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->ext_format = &format_;
+      iodev->buffer_size = BUFFER_SIZE;
+      iodev->min_cb_level = FIRST_CB_LEVEL;
+    }
 
-  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;
+    }
 
-  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 SetupRstream(struct cras_rstream *rstream,
+                      enum CRAS_STREAM_DIRECTION direction) {
+      memset(rstream, 0, sizeof(*rstream));
+      rstream->direction = direction;
+      rstream->cb_threshold = 480;
+      rstream->shm.area = static_cast<cras_audio_shm_area*>(
+          calloc(1, sizeof(*rstream->shm.area)));
+    }
 
-  static int configure_dev(cras_iodev* iodev) {
-    open_dev_called_++;
-    return 0;
-  }
+    void TearDownRstream(struct cras_rstream *rstream) {
+      free(rstream->shm.area);
+    }
 
-  static int close_dev(cras_iodev* iodev) {
-    close_dev_called_++;
-    return 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;
+    }
 
-  static int frames_queued(const cras_iodev* iodev, struct timespec* tstamp) {
-    clock_gettime(CLOCK_MONOTONIC_RAW, tstamp);
-    return frames_queued_;
-  }
+    static int configure_dev(cras_iodev* iodev) {
+      open_dev_called_++;
+      return 0;
+    }
 
-  static int delay_frames(const cras_iodev* iodev) { return delay_frames_; }
+    static int close_dev(cras_iodev* iodev) {
+      close_dev_called_++;
+      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 frames_queued(const cras_iodev* iodev, struct timespec* tstamp) {
+      clock_gettime(CLOCK_MONOTONIC_RAW, tstamp);
+      return frames_queued_;
+    }
 
-    if (audio_buffer_size_ < *num)
-      *num = audio_buffer_size_;
+    static int delay_frames(const cras_iodev* iodev) {
+      return delay_frames_;
+    }
 
-    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 get_buffer(cras_iodev* iodev,
+                          struct cras_audio_area** area,
+                          unsigned int* num) {
+      size_t sz = sizeof(*area_) + sizeof(struct cras_channel_area) * 2;
 
-    *area = area_;
-    return 0;
-  }
+      if (audio_buffer_size_ < *num)
+        *num = audio_buffer_size_;
 
-  static int put_buffer(cras_iodev* iodev, unsigned int num) {
-    free(area_);
-    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 flush_buffer(cras_iodev* iodev) { return 0; }
+      *area = area_;
+      return 0;
+    }
 
-  int device_id_;
-  struct audio_thread* thread_;
+    static int put_buffer(cras_iodev* iodev, unsigned int num) {
+      free(area_);
+      return 0;
+    }
 
-  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_;
+    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_;
@@ -248,13 +207,13 @@
 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);
 
@@ -263,14 +222,14 @@
   adev = thread_->open_devs[CRAS_STREAM_OUTPUT];
   EXPECT_EQ(adev->dev, &iodev);
 
-  thread_rm_open_dev(thread_, CRAS_STREAM_OUTPUT, iodev.info.idx);
+  thread_rm_open_dev(thread_, &iodev);
   adev = thread_->open_devs[CRAS_STREAM_OUTPUT];
   EXPECT_EQ(NULL, adev);
 }
 
 TEST_F(StreamDeviceSuite, StartRamp) {
   struct cras_iodev iodev;
-  struct open_dev* adev;
+  struct open_dev *adev;
   int rc;
   enum CRAS_IODEV_RAMP_REQUEST req;
 
@@ -282,9 +241,8 @@
   EXPECT_EQ(adev->dev, &iodev);
 
   // Ramp up for unmute.
-  iodev.ramp = reinterpret_cast<cras_ramp*>(0x123);
   req = CRAS_IODEV_RAMP_REQUEST_UP_UNMUTE;
-  rc = thread_dev_start_ramp(thread_, iodev.info.idx, req);
+  rc = thread_dev_start_ramp(thread_, &iodev, req);
 
   EXPECT_EQ(0, rc);
   EXPECT_EQ(&iodev, cras_iodev_start_ramp_odev);
@@ -294,36 +252,17 @@
   ResetStubData();
   req = CRAS_IODEV_RAMP_REQUEST_DOWN_MUTE;
 
-  rc = thread_dev_start_ramp(thread_, iodev.info.idx, req);
+  rc = thread_dev_start_ramp(thread_, &iodev, req);
 
   EXPECT_EQ(0, rc);
   EXPECT_EQ(&iodev, cras_iodev_start_ramp_odev);
   EXPECT_EQ(req, cras_iodev_start_ramp_request);
-
-  // If device's volume percentage is zero, than ramp won't start.
-  ResetStubData();
-  cras_iodev_is_zero_volume_ret = 1;
-  rc = thread_dev_start_ramp(thread_, iodev.info.idx, req);
-
-  EXPECT_EQ(0, rc);
-  EXPECT_EQ(NULL, cras_iodev_start_ramp_odev);
-  EXPECT_EQ(1, cras_device_monitor_set_device_mute_state_called);
-
-  // Assume iodev changed to no_stream run state, it should not use ramp.
-  ResetStubData();
-  iodev.state = CRAS_IODEV_STATE_NO_STREAM_RUN;
-  rc = thread_dev_start_ramp(thread_, iodev.info.idx, req);
-
-  EXPECT_EQ(0, rc);
-  EXPECT_EQ(NULL, cras_iodev_start_ramp_odev);
-  EXPECT_EQ(2, cras_device_monitor_set_device_mute_state_called);
-
-  thread_rm_open_dev(thread_, CRAS_STREAM_OUTPUT, iodev.info.idx);
+  thread_rm_open_dev(thread_, &iodev);
 }
 
 TEST_F(StreamDeviceSuite, AddRemoveOpenInputDevice) {
   struct cras_iodev iodev;
-  struct open_dev* adev;
+  struct open_dev *adev;
 
   SetupDevice(&iodev, CRAS_STREAM_INPUT);
 
@@ -332,7 +271,7 @@
   adev = thread_->open_devs[CRAS_STREAM_INPUT];
   EXPECT_EQ(adev->dev, &iodev);
 
-  thread_rm_open_dev(thread_, CRAS_STREAM_INPUT, iodev.info.idx);
+  thread_rm_open_dev(thread_, &iodev);
   adev = thread_->open_devs[CRAS_STREAM_INPUT];
   EXPECT_EQ(NULL, adev);
 }
@@ -344,7 +283,7 @@
   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);
@@ -361,7 +300,7 @@
   EXPECT_EQ(adev->next->dev, &odev2);
 
   // Remove first open device and check the second one is still open.
-  thread_rm_open_dev(thread_, CRAS_STREAM_OUTPUT, odev.info.idx);
+  thread_rm_open_dev(thread_, &odev);
   adev = thread_->open_devs[CRAS_STREAM_OUTPUT];
   EXPECT_EQ(adev->dev, &odev2);
 
@@ -379,24 +318,24 @@
   EXPECT_EQ(adev->next->dev, &idev2);
 
   // Remove first open device and check the second one is still open.
-  thread_rm_open_dev(thread_, CRAS_STREAM_INPUT, idev.info.idx);
+  thread_rm_open_dev(thread_, &idev);
   adev = thread_->open_devs[CRAS_STREAM_INPUT];
   EXPECT_EQ(adev->dev, &idev2);
 
   // Add and remove another open device and check still open.
   thread_add_open_dev(thread_, &idev3);
-  thread_rm_open_dev(thread_, CRAS_STREAM_INPUT, idev3.info.idx);
+  thread_rm_open_dev(thread_, &idev3);
   adev = thread_->open_devs[CRAS_STREAM_INPUT];
   EXPECT_EQ(adev->dev, &idev2);
-  thread_rm_open_dev(thread_, CRAS_STREAM_INPUT, idev2.info.idx);
-  thread_rm_open_dev(thread_, CRAS_STREAM_OUTPUT, odev2.info.idx);
-  thread_rm_open_dev(thread_, CRAS_STREAM_OUTPUT, odev3.info.idx);
+  thread_rm_open_dev(thread_, &idev2);
+  thread_rm_open_dev(thread_, &odev2);
+  thread_rm_open_dev(thread_, &odev3);
 }
 
 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;
@@ -411,8 +350,8 @@
   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);
@@ -434,8 +373,8 @@
   EXPECT_EQ(&rstream2, cras_rstream_dev_offset_update_rstream_val[1]);
   EXPECT_EQ(0, cras_rstream_dev_offset_update_frames_val[1]);
 
-  thread_rm_open_dev(thread_, CRAS_STREAM_INPUT, iodev.info.idx);
-  thread_rm_open_dev(thread_, CRAS_STREAM_INPUT, iodev2.info.idx);
+  thread_rm_open_dev(thread_, &iodev);
+  thread_rm_open_dev(thread_, &iodev2);
   TearDownRstream(&rstream);
   TearDownRstream(&rstream2);
   TearDownRstream(&rstream3);
@@ -443,11 +382,11 @@
 
 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);
@@ -456,7 +395,7 @@
   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;
@@ -478,108 +417,7 @@
   EXPECT_EQ(ts_wake_1.tv_sec, adev->wake_ts.tv_sec);
   EXPECT_EQ(ts_wake_1.tv_nsec, adev->wake_ts.tv_nsec);
 
-  thread_rm_open_dev(thread_, CRAS_STREAM_INPUT, iodev.info.idx);
-  TearDownRstream(&rstream1);
-  TearDownRstream(&rstream2);
-}
-
-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;
-
-  ResetGlobalStubData();
-  SetupDevice(&iodev, CRAS_STREAM_OUTPUT);
-  SetupRstream(&rstream, CRAS_STREAM_OUTPUT);
-  shm_header = rstream.shm->header;
-
-  thread_add_open_dev(thread_, &iodev);
-  thread_add_stream(thread_, &rstream, &piodev, 1);
-  dev_stream = iodev.streams;
-  EXPECT_EQ(dev_stream->stream, &rstream);
-  /*
-   * When a output stream is added, the start_stream function will be called
-   * just before its first fetch.
-   */
-  EXPECT_EQ(cras_iodev_start_stream_called, 0);
-
-  adev = thread_->open_devs[CRAS_STREAM_OUTPUT];
-
-  shm_header->write_buf_idx = 0;
-  shm_header->write_offset[0] = 0;
-
-  /* Assume device is started. */
-  iodev.state = CRAS_IODEV_STATE_NORMAL_RUN;
-
-  /* Fetch stream. */
-  cras_rstream_is_pending_reply_ret = 0;
-  dev_io_playback_fetch(adev);
-  EXPECT_EQ(dev_stream_request_playback_samples_called, 1);
-  EXPECT_EQ(cras_iodev_start_stream_called, 1);
-
-  thread_rm_open_dev(thread_, CRAS_STREAM_OUTPUT, iodev.info.idx);
-  TearDownRstream(&rstream);
-}
-
-TEST_F(StreamDeviceSuite, OutputStreamFetchTime) {
-  struct cras_iodev iodev, *piodev = &iodev;
-  struct cras_rstream rstream1, rstream2;
-  struct dev_stream* dev_stream;
-  struct timespec expect_ts;
-
-  ResetGlobalStubData();
-  SetupDevice(&iodev, CRAS_STREAM_OUTPUT);
-  SetupRstream(&rstream1, CRAS_STREAM_OUTPUT);
-  SetupRstream(&rstream2, CRAS_STREAM_OUTPUT);
-
-  thread_add_open_dev(thread_, &iodev);
-
-  /* Add a new stream. init_cb_ts should be the time right now. */
-  clock_gettime_retspec.tv_sec = 1;
-  clock_gettime_retspec.tv_nsec = 500;
-  cras_iodev_get_valid_frames_ret = 0;
-  expect_ts = clock_gettime_retspec;
-  thread_add_stream(thread_, &rstream1, &piodev, 1);
-  dev_stream = iodev.streams;
-  EXPECT_EQ(dev_stream->stream, &rstream1);
-  EXPECT_EQ(init_cb_ts_.tv_sec, expect_ts.tv_sec);
-  EXPECT_EQ(init_cb_ts_.tv_nsec, expect_ts.tv_nsec);
-
-  thread_rm_open_dev(thread_, CRAS_STREAM_OUTPUT, iodev.info.idx);
-
-  thread_add_open_dev(thread_, &iodev);
-
-  /*
-   * Add a new stream when there are remaining frames in device buffer.
-   * init_cb_ts should be the time that hw_level drops to min_cb_level.
-   * In this case, we should wait 480 / 48000 = 0.01s.
-   */
-  clock_gettime_retspec.tv_sec = 1;
-  clock_gettime_retspec.tv_nsec = 500;
-  expect_ts = clock_gettime_retspec;
-  cras_iodev_get_valid_frames_ret = 960;
-  rstream1.cb_threshold = 480;
-  expect_ts.tv_nsec += 10 * 1000000;
-  thread_add_stream(thread_, &rstream1, &piodev, 1);
-  dev_stream = iodev.streams;
-  EXPECT_EQ(dev_stream->stream, &rstream1);
-  EXPECT_EQ(init_cb_ts_.tv_sec, expect_ts.tv_sec);
-  EXPECT_EQ(init_cb_ts_.tv_nsec, expect_ts.tv_nsec);
-
-  /*
-   * Add a new stream when there are other streams exist. init_cb_ts should
-   * be the earliest next callback time from other streams.
-   */
-  rstream1.next_cb_ts = expect_ts;
-  thread_add_stream(thread_, &rstream2, &piodev, 1);
-  dev_stream = iodev.streams->prev;
-  EXPECT_EQ(dev_stream->stream, &rstream2);
-  EXPECT_EQ(init_cb_ts_.tv_sec, expect_ts.tv_sec);
-  EXPECT_EQ(init_cb_ts_.tv_nsec, expect_ts.tv_nsec);
-
-  thread_rm_open_dev(thread_, CRAS_STREAM_OUTPUT, iodev.info.idx);
+  thread_rm_open_dev(thread_, &iodev);
   TearDownRstream(&rstream1);
   TearDownRstream(&rstream2);
 }
@@ -590,7 +428,7 @@
   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);
@@ -627,90 +465,36 @@
 
   // Remove first device from open and streams on second device remain
   // intact.
-  thread_rm_open_dev(thread_, CRAS_STREAM_OUTPUT, iodev.info.idx);
+  thread_rm_open_dev(thread_, &iodev);
   dev_stream = iodev2.streams;
   EXPECT_EQ(&rstream3, dev_stream->stream);
   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);
 
   // Remove open devices and check stream is on fallback device.
-  thread_rm_open_dev(thread_, CRAS_STREAM_OUTPUT, iodev2.info.idx);
+  thread_rm_open_dev(thread_, &iodev2);
 
   // Add open device, again check it is empty of streams.
   thread_add_open_dev(thread_, &iodev);
   dev_stream = iodev.streams;
   EXPECT_EQ(NULL, dev_stream);
 
-  thread_rm_open_dev(thread_, CRAS_STREAM_OUTPUT, iodev.info.idx);
+  thread_rm_open_dev(thread_, &iodev);
   TearDownRstream(&rstream);
   TearDownRstream(&rstream2);
   TearDownRstream(&rstream3);
 }
 
-TEST_F(StreamDeviceSuite, FetchStreams) {
-  struct cras_iodev iodev, *piodev = &iodev;
-  struct open_dev* adev;
-  struct cras_rstream rstream;
-  struct cras_audio_shm_header* shm_header;
-
-  SetupRstream(&rstream, CRAS_STREAM_OUTPUT);
-  shm_header = rstream.shm->header;
-  ResetGlobalStubData();
-
-  SetupDevice(&iodev, CRAS_STREAM_OUTPUT);
-
-  shm_header->write_buf_idx = 0;
-
-  /* Add the device and add the stream. */
-  thread_add_open_dev(thread_, &iodev);
-  thread_add_stream(thread_, &rstream, &piodev, 1);
-
-  adev = thread_->open_devs[CRAS_STREAM_OUTPUT];
-
-  /* Assume device is started. */
-  iodev.state = CRAS_IODEV_STATE_NORMAL_RUN;
-
-  /*
-   * If the stream is pending a reply and shm buffer for writing is empty,
-   * just skip it.
-   */
-  cras_rstream_is_pending_reply_ret = 1;
-  shm_header->write_offset[0] = 0;
-  dev_io_playback_fetch(adev);
-
-  EXPECT_EQ(dev_stream_request_playback_samples_called, 0);
-  EXPECT_EQ(dev_stream_update_next_wake_time_called, 0);
-
-  /*
-   * If the stream is not pending a reply and shm buffer for writing is full,
-   * update next wake up time and skip fetching.
-   */
-  cras_rstream_is_pending_reply_ret = 0;
-  shm_header->write_offset[0] = cras_shm_used_size(rstream.shm);
-  dev_io_playback_fetch(adev);
-  EXPECT_EQ(dev_stream_request_playback_samples_called, 0);
-  EXPECT_EQ(dev_stream_update_next_wake_time_called, 1);
-
-  /* If the stream can be fetched, fetch it. */
-  cras_rstream_is_pending_reply_ret = 0;
-  shm_header->write_offset[0] = 0;
-  dev_io_playback_fetch(adev);
-  EXPECT_EQ(dev_stream_request_playback_samples_called, 1);
-
-  thread_rm_open_dev(thread_, CRAS_STREAM_OUTPUT, iodev.info.idx);
-  TearDownRstream(&rstream);
-}
-
 TEST_F(StreamDeviceSuite, WriteOutputSamplesPrepareOutputFailed) {
   struct cras_iodev iodev;
-  struct open_dev* adev;
+  struct open_dev *adev;
 
   ResetGlobalStubData();
 
@@ -723,7 +507,7 @@
   // 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.
@@ -731,19 +515,19 @@
 
   // 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.
   EXPECT_EQ(0, cras_iodev_get_output_buffer_called);
 
-  thread_rm_open_dev(thread_, CRAS_STREAM_OUTPUT, iodev.info.idx);
+  thread_rm_open_dev(thread_, &iodev);
 }
 
 TEST_F(StreamDeviceSuite, WriteOutputSamplesNoStream) {
   struct cras_iodev iodev;
-  struct open_dev* adev;
+  struct open_dev *adev;
 
   ResetGlobalStubData();
 
@@ -756,7 +540,7 @@
   // 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.
@@ -766,12 +550,12 @@
   // called.
   EXPECT_EQ(0, cras_iodev_get_output_buffer_called);
 
-  thread_rm_open_dev(thread_, CRAS_STREAM_OUTPUT, iodev.info.idx);
+  thread_rm_open_dev(thread_, &iodev);
 }
 
 TEST_F(StreamDeviceSuite, WriteOutputSamplesLeaveNoStream) {
   struct cras_iodev iodev;
-  struct open_dev* adev;
+  struct open_dev *adev;
 
   ResetGlobalStubData();
 
@@ -788,7 +572,7 @@
   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;
@@ -799,7 +583,7 @@
   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.
@@ -807,74 +591,7 @@
   EXPECT_EQ(2, cras_iodev_prepare_output_before_write_samples_called);
   EXPECT_EQ(1, cras_iodev_get_output_buffer_called);
 
-  thread_rm_open_dev(thread_, CRAS_STREAM_OUTPUT, iodev.info.idx);
-}
-
-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;
-
-  ResetGlobalStubData();
-
-  SetupDevice(&iodev, CRAS_STREAM_OUTPUT);
-  SetupRstream(&rstream1, CRAS_STREAM_OUTPUT);
-  SetupRstream(&rstream2, CRAS_STREAM_OUTPUT);
-
-  // Setup the output buffer for device.
-  cras_iodev_get_output_buffer_area = cras_audio_area_create(2);
-
-  // Add the device and add the stream.
-  thread_add_open_dev(thread_, &iodev);
-  thread_add_stream(thread_, &rstream1, &piodev, 1);
-  adev = thread_->open_devs[CRAS_STREAM_OUTPUT];
-
-  // Assume device is running.
-  iodev.state = CRAS_IODEV_STATE_NORMAL_RUN;
-
-  // Assume device in normal run stream 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
-  // running.
-  frames_queued_ = 0;
-  dev_stream_playback_frames_ret = 100;
-  dev_stream = iodev.streams;
-  write_output_samples(&thread_->open_devs[CRAS_STREAM_OUTPUT], adev, nullptr);
-  EXPECT_EQ(1, cras_iodev_prepare_output_before_write_samples_called);
-  EXPECT_EQ(1, cras_iodev_get_output_buffer_called);
-  EXPECT_EQ(0, dev_stream_mix_called);
-
-  // Set rstream1 to be running. cras_iodev should mix samples from rstream1.
-  dev_stream_set_running(dev_stream);
-  write_output_samples(&thread_->open_devs[CRAS_STREAM_OUTPUT], adev, nullptr);
-  EXPECT_EQ(2, cras_iodev_prepare_output_before_write_samples_called);
-  EXPECT_EQ(2, cras_iodev_get_output_buffer_called);
-  EXPECT_EQ(1, dev_stream_mix_called);
-
-  // Add rstream2. cras_iodev should mix samples from rstream1 but not from
-  // rstream2.
-  thread_add_stream(thread_, &rstream2, &piodev, 1);
-  write_output_samples(&thread_->open_devs[CRAS_STREAM_OUTPUT], adev, nullptr);
-  EXPECT_EQ(3, cras_iodev_prepare_output_before_write_samples_called);
-  EXPECT_EQ(3, cras_iodev_get_output_buffer_called);
-  EXPECT_EQ(2, dev_stream_mix_called);
-
-  // Set rstream2 to be running. cras_iodev should mix samples from rstream1
-  // and rstream2.
-  dev_stream = iodev.streams->prev;
-  dev_stream_set_running(dev_stream);
-  write_output_samples(&thread_->open_devs[CRAS_STREAM_OUTPUT], adev, nullptr);
-  EXPECT_EQ(4, cras_iodev_prepare_output_before_write_samples_called);
-  EXPECT_EQ(4, cras_iodev_get_output_buffer_called);
-  EXPECT_EQ(4, dev_stream_mix_called);
-
-  thread_rm_open_dev(thread_, CRAS_STREAM_OUTPUT, iodev.info.idx);
-  TearDownRstream(&rstream1);
-  TearDownRstream(&rstream2);
+  thread_rm_open_dev(thread_, &iodev);
 }
 
 TEST_F(StreamDeviceSuite, DoPlaybackNoStream) {
@@ -890,7 +607,7 @@
   // 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;
@@ -907,7 +624,7 @@
   // update_dev_wakeup_time.
   EXPECT_EQ(1, cras_iodev_frames_to_play_in_sleep_called);
 
-  thread_rm_open_dev(thread_, CRAS_STREAM_OUTPUT, iodev.info.idx);
+  thread_rm_open_dev(thread_, &iodev);
 }
 
 TEST_F(StreamDeviceSuite, DoPlaybackUnderrun) {
@@ -935,14 +652,14 @@
   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);
   dev_io_playback_write(&thread_->open_devs[CRAS_STREAM_OUTPUT], nullptr);
   EXPECT_EQ(1, cras_iodev_output_underrun_called);
 
-  thread_rm_open_dev(thread_, CRAS_STREAM_OUTPUT, iodev.info.idx);
+  thread_rm_open_dev(thread_, &iodev);
   TearDownRstream(&rstream);
 }
 
@@ -967,7 +684,7 @@
   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);
@@ -976,103 +693,111 @@
   EXPECT_EQ(1, cras_iodev_reset_request_called);
   EXPECT_EQ(&iodev, cras_iodev_reset_request_iodev);
 
-  thread_rm_open_dev(thread_, CRAS_STREAM_OUTPUT, iodev.info.idx);
+  thread_rm_open_dev(thread_, &iodev);
   TearDownRstream(&rstream);
 }
 
-TEST(AudioThreadStreams, DrainStream) {
+TEST(AUdioThreadStreams, DrainStream) {
   struct cras_rstream rstream;
-  struct cras_audio_shm_header* shm_header;
+  struct cras_audio_shm_area shm_area;
   struct audio_thread thread;
 
-  SetupRstream(&rstream, CRAS_STREAM_OUTPUT);
-  shm_header = rstream.shm->header;
+  memset(&rstream, 0, sizeof(rstream));
+  memset(&shm_area, 0, sizeof(shm_area));
+  rstream.shm.config.frame_bytes = 4;
+  shm_area.config.frame_bytes = 4;
+  shm_area.config.used_size = 4096 * 4;
+  rstream.shm.config.used_size = 4096 * 4;
+  rstream.shm.area = &shm_area;
+  rstream.format.frame_rate = 48000;
+  rstream.direction = CRAS_STREAM_OUTPUT;
 
-  shm_header->write_offset[0] = 1 * 4;
+  shm_area.write_offset[0] = 1 * 4;
   EXPECT_EQ(1, thread_drain_stream_ms_remaining(&thread, &rstream));
 
-  shm_header->write_offset[0] = 479 * 4;
+  shm_area.write_offset[0] = 479 * 4;
   EXPECT_EQ(10, thread_drain_stream_ms_remaining(&thread, &rstream));
 
-  shm_header->write_offset[0] = 0;
+  shm_area.write_offset[0] = 0;
   EXPECT_EQ(0, thread_drain_stream_ms_remaining(&thread, &rstream));
 
   rstream.direction = CRAS_STREAM_INPUT;
-  shm_header->write_offset[0] = 479 * 4;
+  shm_area.write_offset[0] = 479 * 4;
   EXPECT_EQ(0, thread_drain_stream_ms_remaining(&thread, &rstream));
-  TearDownRstream(&rstream);
 }
 
 TEST(BusyloopDetectSuite, CheckerTest) {
   continuous_zero_sleep_count = 0;
-  cras_audio_thread_event_busyloop_called = 0;
+  cras_audio_thread_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_event_busyloop_called, 0);
+  EXPECT_EQ(cras_audio_thread_busyloop_called, 0);
   check_busyloop(&wait_ts);
   EXPECT_EQ(continuous_zero_sleep_count, 2);
-  EXPECT_EQ(cras_audio_thread_event_busyloop_called, 1);
+  EXPECT_EQ(cras_audio_thread_busyloop_called, 1);
   check_busyloop(&wait_ts);
   EXPECT_EQ(continuous_zero_sleep_count, 3);
-  EXPECT_EQ(cras_audio_thread_event_busyloop_called, 1);
+  EXPECT_EQ(cras_audio_thread_busyloop_called, 1);
 
   wait_ts.tv_sec = 1;
   check_busyloop(&wait_ts);
   EXPECT_EQ(continuous_zero_sleep_count, 0);
-  EXPECT_EQ(cras_audio_thread_event_busyloop_called, 1);
+  EXPECT_EQ(cras_audio_thread_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) {
-  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;
@@ -1081,85 +806,99 @@
   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) {
-  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;
@@ -1167,8 +906,9 @@
   }
 }
 
-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;
@@ -1179,107 +919,121 @@
   return 0;
 }
 
-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) {
-  return cras_rstream_is_pending_reply_ret;
+void cras_rstream_record_fetch_interval(struct cras_rstream *rstream,
+    const struct timespec *now)
+{
 }
 
-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) {
-  dev_stream_mix_called++;
+int dev_stream_mix(struct dev_stream *dev_stream,
+		   const struct cras_audio_format *fmt,
+                   uint8_t *dst,
+                   unsigned int num_to_write)
+{
   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) {
-  dev_stream_request_playback_samples_called++;
+int dev_stream_can_fetch(struct dev_stream *dev_stream)
+{
+  return 1;
+}
+
+int dev_stream_request_playback_samples(struct dev_stream *dev_stream,
+                                        const struct timespec *now)
+{
   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) {}
-
-void dev_stream_update_frames(const 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 coarse_rate_adjust)
+{
 }
 
-int dev_stream_wake_time(struct dev_stream* dev_stream,
+void dev_stream_update_frames(const 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;
@@ -1288,163 +1042,176 @@
   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) {
+int cras_server_metrics_highest_hw_level(unsigned hw_level,
+		enum CRAS_STREAM_DIRECTION direction)
+{
+  return 0;
+}
+
+int cras_server_metrics_longest_fetch_delay(int delay_msec)
+{
+  return 0;
+}
+
+int cras_server_metrics_num_underruns(unsigned num_underruns)
+{
+  return 0;
+}
+
+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) {
-  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) {
-  return 0;
-}
-
-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) {
-  *tp = clock_gettime_retspec;
+int input_data_put_for_stream(struct input_data *data,
+			   struct cras_rstream *stream,
+			   struct buffer_share *offsets,
+			   unsigned int frames)
+{
   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_event_busyloop() {
-  cras_audio_thread_event_busyloop_called++;
-  return 0;
-}
-
-int cras_audio_thread_event_drop_samples() {
+int cras_audio_thread_busyloop()
+{
+  cras_audio_thread_busyloop_called ++;
   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 0baeb38..14edc4d 100644
--- a/cras/src/tests/audio_thread_unittest_obsolete.cc
+++ b/cras/src/tests/audio_thread_unittest_obsolete.cc
@@ -6,21 +6,21 @@
 #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 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 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,135 +66,146 @@
 
 //  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;
+  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;
+      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;
+      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;
+      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_);
+      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;
+      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;
+      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;
-  }
+      cras_iodev_set_format_called = 0;
+      dev_stream_set_delay_called = 0;
+    }
 
-  virtual void TearDown() {
-    free(shm_->area);
-    free(rstream_);
-    free(shm2_->area);
-    free(rstream2_);
-    free(dummy_audio_area1);
-    free(dummy_audio_area2);
-  }
+    virtual void TearDown() {
+      free(shm_->area);
+      free(rstream_);
+      free(shm2_->area);
+      free(rstream2_);
+      free(dummy_audio_area1);
+      free(dummy_audio_area2);
+    }
 
-  void SetupRstream(struct cras_rstream** rstream, int fd) {
-    struct cras_audio_shm* shm;
+    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;
+      *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));
-  }
+      shm = cras_rstream_input_shm(*rstream);
+      shm->area = (struct cras_audio_shm_area *)calloc(1,
+          sizeof(*shm->area) + cb_threshold_ * 8);
+      cras_shm_set_frame_bytes(shm, 4);
+      cras_shm_set_used_size(
+          shm, cb_threshold_ * cras_shm_frame_bytes(shm));
+    }
 
-  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 frames_queued(const cras_iodev* iodev) { return frames_queued_; }
+    // Stub functions for the iodev structure.
+    static int frames_queued(const cras_iodev* iodev) {
+      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;
+    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_;
+      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_ = (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;
-  }
+      *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) { return is_open_; }
+    static int is_open(const cras_iodev* iodev) {
+      return is_open_;
+    }
 
-  static int open_dev(cras_iodev* iodev) { return 0; }
+    static int open_dev(cras_iodev* iodev) {
+      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 dev_running(const cras_iodev* iodev) {
-    dev_running_called_++;
-    return 1;
-  }
+    static int dev_running(const cras_iodev* iodev) {
+      dev_running_called_++;
+      return 1;
+    }
+
 
   struct cras_iodev iodev_;
   struct cras_iodev output_dev_;
@@ -203,14 +214,14 @@
   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;
@@ -221,12 +232,12 @@
 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);
@@ -251,7 +262,7 @@
   struct timespec ts;
   int rc;
   uint64_t nsec_expected;
-  struct audio_thread* thread;
+  struct audio_thread *thread;
 
   thread = audio_thread_create();
   ASSERT_TRUE(thread);
@@ -282,7 +293,7 @@
   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);
@@ -314,7 +325,7 @@
   struct timespec ts;
   int rc;
   uint64_t nsec_expected;
-  struct audio_thread* thread;
+  struct audio_thread *thread;
 
   thread = audio_thread_create();
   ASSERT_TRUE(thread);
@@ -327,7 +338,7 @@
   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 /
@@ -352,7 +363,7 @@
   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;
@@ -371,7 +382,7 @@
   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 /
@@ -393,7 +404,7 @@
   struct timespec ts;
   int rc;
   uint64_t nsec_expected;
-  struct audio_thread* thread;
+  struct audio_thread *thread;
 
   thread = audio_thread_create();
   ASSERT_TRUE(thread);
@@ -441,7 +452,7 @@
 TEST_F(ReadStreamSuite, PossiblyReadWriteThreeBuffers) {
   struct timespec ts;
   int rc;
-  struct audio_thread* thread;
+  struct audio_thread *thread;
 
   thread = audio_thread_create();
   ASSERT_TRUE(thread);
@@ -485,141 +496,147 @@
 
 //  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;
+  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;
+      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;
+      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_);
+      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_);
+      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_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;
+      dev_running_called_ = 0;
 
-    audio_buffer_size_ = 8196;
-    thread_add_stream(thread_, rstream_);
-    frames_written_ = 0;
-  }
+      audio_buffer_size_ = 8196;
+      thread_add_stream(thread_, rstream_);
+      frames_written_ = 0;
+    }
 
-  virtual void TearDown() {
-    free(shm_->area);
-    free(rstream_);
-    free(shm2_->area);
-    free(rstream2_);
-    audio_thread_destroy(thread_);
-  }
+    virtual void TearDown() {
+      free(shm_->area);
+      free(rstream_);
+      free(shm2_->area);
+      free(rstream2_);
+      audio_thread_destroy(thread_);
+    }
 
-  void SetupRstream(struct cras_rstream** rstream, int fd) {
-    struct cras_audio_shm* shm;
+    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;
+      *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));
-  }
+      shm = cras_rstream_output_shm(*rstream);
+      shm->area = (struct cras_audio_shm_area *)calloc(1,
+          sizeof(*shm->area) + cb_threshold_ * 8);
+      cras_shm_set_frame_bytes(shm, 4);
+      cras_shm_set_used_size(
+          shm, buffer_frames_ * cras_shm_frame_bytes(shm));
+    }
 
-  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;
-  }
+    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;
+    }
 
-  // Stub functions for the iodev structure.
-  static int frames_queued(const cras_iodev* iodev) {
-    return frames_queued_ + frames_written_;
-  }
+    // Stub functions for the iodev structure.
+    static int frames_queued(const cras_iodev* iodev) {
+      return frames_queued_ + frames_written_;
+    }
 
-  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;
+    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_;
+      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_ = (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;
-  }
+      *area = area_;
+      return 0;
+    }
 
-  static int put_buffer(cras_iodev* iodev, unsigned int num) {
-    free(area_);
-    frames_written_ += num;
-    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 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 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 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;
-  }
+    static int close_dev(cras_iodev* iodev) {
+      close_dev_called_++;
+      is_open_ = 0;
+      return 0;
+    }
 
   struct cras_iodev iodev_;
   static int is_open_;
@@ -634,13 +651,13 @@
   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;
@@ -655,7 +672,7 @@
 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;
@@ -694,8 +711,8 @@
   // 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;
@@ -741,8 +758,8 @@
   // 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);
@@ -818,8 +835,8 @@
   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);
@@ -843,7 +860,7 @@
   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;
@@ -858,7 +875,8 @@
   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);
 }
@@ -962,8 +980,8 @@
   //  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;
@@ -997,6 +1015,7 @@
   EXPECT_EQ(1, close_dev_called_);
 }
 
+
 TEST_F(WriteStreamSuite, DrainOutputBufferWaitForPlayback) {
   // Hardware buffer is full.
   frames_queued_ = buffer_frames_;
@@ -1082,179 +1101,179 @@
 
 //  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;
+  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;
+      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;
+      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;
+      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;
+      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() {}
-
-  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;
-  }
-
-  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 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;
-  }
-
-  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);
+      audio_buffer_size_ = 8196;
     }
 
-    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);
-  }
+    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;
+    }
+
+    // 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 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 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->area = (struct cras_audio_shm_area *)calloc(1, sizeof(*shm->area));
+
+      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->area = (struct cras_audio_shm_area *)calloc(1, sizeof(*shm->area));
+
+      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->area);
+      free(new_stream);
+      shm = cras_rstream_output_shm(second_stream);
+      free(shm->area);
+      free(second_stream);
+    }
 
   struct cras_iodev iodev_;
   static int is_open_;
@@ -1265,7 +1284,7 @@
   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_;
 };
@@ -1277,20 +1296,20 @@
 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;
@@ -1298,7 +1317,7 @@
          sizeof(cras_iodev_set_format_val));
 
   shm = cras_rstream_output_shm(new_stream);
-  shm->header = (struct cras_audio_shm_header*)calloc(1, sizeof(*shm->header));
+  shm->area = (struct cras_audio_shm_area *)calloc(1, sizeof(*shm->area));
 
   thread_set_active_dev(thread, &iodev_);
 
@@ -1321,15 +1340,16 @@
   rc = thread_disconnect_stream(thread, new_stream);
   EXPECT_EQ(1, cras_rstream_destroy_called);
 
-  free(shm->header);
+  free(shm->area);
   audio_thread_destroy(thread);
   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);
@@ -1337,7 +1357,7 @@
   printf("1\n");
 
   shm = cras_rstream_output_shm(&new_stream);
-  shm->header = (struct cras_audio_shm_header*)calloc(1, sizeof(*shm->header));
+  shm->area = (struct cras_audio_shm_area *)calloc(1, sizeof(*shm->area));
 
   open_dev_return_val_ = -1;
   new_stream.direction = CRAS_STREAM_OUTPUT;
@@ -1348,7 +1368,7 @@
   EXPECT_EQ(1, cras_iodev_set_format_called);
   audio_thread_destroy(thread);
   printf("3\n");
-  free(shm->header);
+  free(shm->area);
 }
 
 TEST_F(AddStreamSuite, AddRmTwoOutputStreams) {
@@ -1362,12 +1382,12 @@
 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;
@@ -1375,7 +1395,7 @@
          sizeof(cras_iodev_set_format_val));
 
   shm = cras_rstream_output_shm(new_stream);
-  shm->header = (struct cras_audio_shm_header*)calloc(1, sizeof(*shm->header));
+  shm->area = (struct cras_audio_shm_area *)calloc(1, sizeof(*shm->area));
 
   thread_set_active_dev(thread, &iodev_);
   rc = thread_add_stream(thread, new_stream);
@@ -1399,169 +1419,176 @@
   EXPECT_STREQ(kStreamTimeoutMilliSeconds, cras_metrics_log_histogram_name);
   EXPECT_EQ(90, cras_metrics_log_histogram_sample);
 
-  free(shm->header);
+  free(shm->area);
   free(new_stream);
   audio_thread_destroy(thread);
 }
 
 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;
+  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_);
+      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;
+      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;
+      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;
+      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->area);
+      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->area = (struct cras_audio_shm_area *)calloc(1,
+          sizeof(*shm->area) + 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->area = (struct cras_audio_shm_area *)calloc(1,
+	  sizeof(*shm->area) + 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;
+    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_];
+      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_ = (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_;
+      *area = area_;
 
-    get_buffer_val_idx_++;
-    return 0;
-  }
+      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 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];
@@ -1579,10 +1606,10 @@
   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];
 };
@@ -1603,10 +1630,10 @@
 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;
@@ -1615,7 +1642,7 @@
 
   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);
 
@@ -1632,7 +1659,7 @@
 }
 
 TEST_F(ActiveDevicesSuite, SetActiveDevAlreadyInList) {
-  struct active_dev* adevs;
+  struct active_dev *adevs;
   iodev_.direction = CRAS_STREAM_INPUT;
   iodev2_.direction = CRAS_STREAM_INPUT;
 
@@ -1651,30 +1678,30 @@
 }
 
 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);
 }
 
@@ -1684,12 +1711,12 @@
 
   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);
 }
@@ -1738,7 +1765,7 @@
   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) {
@@ -1756,7 +1783,7 @@
   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) {
@@ -1830,7 +1857,7 @@
   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;
   }
@@ -1852,64 +1879,66 @@
 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;
@@ -1934,7 +1963,8 @@
 
   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;
@@ -1948,14 +1978,17 @@
   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;
 
@@ -1970,15 +2003,14 @@
 }
 
 // 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;
@@ -1994,21 +2026,25 @@
 }
 
 //  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;
@@ -2022,63 +2058,65 @@
   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++;
@@ -2087,48 +2125,49 @@
 
 //  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);
@@ -2143,9 +2182,10 @@
   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;
 
@@ -2156,7 +2196,7 @@
   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;
@@ -2164,8 +2204,9 @@
   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++;
 
@@ -2173,19 +2214,21 @@
   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
deleted file mode 100644
index 30e67ea..0000000
--- a/cras/src/tests/biquad_unittest.cc
+++ /dev/null
@@ -1,216 +0,0 @@
-// 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 "biquad.h"
-
-#include <assert.h>
-#include <gtest/gtest.h>
-#include <math.h>
-
-namespace {
-
-TEST(InvalidFrequencyTest, All) {
-  struct biquad bq, test_bq;
-  float f_over = 1.5;
-  float f_under = -0.1;
-  double db_gain = 2;
-  double A = pow(10.0, db_gain / 40);
-
-  // check response to freq >= 1
-  biquad_set(&bq, BQ_LOWPASS, f_over, 0, db_gain);
-  test_bq = {0, 0, 0, 0, 0, 0, 0, 0, 0};
-  test_bq.b0 = 1;
-  EXPECT_EQ(bq.b0, test_bq.b0);
-  EXPECT_EQ(bq.b1, test_bq.b1);
-  EXPECT_EQ(bq.b2, test_bq.b2);
-  EXPECT_EQ(bq.a1, test_bq.a1);
-  EXPECT_EQ(bq.a2, test_bq.a2);
-
-  biquad_set(&bq, BQ_HIGHPASS, f_over, 0, db_gain);
-  test_bq = {0, 0, 0, 0, 0, 0, 0, 0, 0};
-  EXPECT_EQ(bq.b0, test_bq.b0);
-  EXPECT_EQ(bq.b1, test_bq.b1);
-  EXPECT_EQ(bq.b2, test_bq.b2);
-  EXPECT_EQ(bq.a1, test_bq.a1);
-  EXPECT_EQ(bq.a2, test_bq.a2);
-
-  biquad_set(&bq, BQ_BANDPASS, f_over, 0, db_gain);
-  test_bq = {0, 0, 0, 0, 0, 0, 0, 0, 0};
-  EXPECT_EQ(bq.b0, test_bq.b0);
-  EXPECT_EQ(bq.b1, test_bq.b1);
-  EXPECT_EQ(bq.b2, test_bq.b2);
-  EXPECT_EQ(bq.a1, test_bq.a1);
-  EXPECT_EQ(bq.a2, test_bq.a2);
-
-  biquad_set(&bq, BQ_LOWSHELF, f_over, 0, db_gain);
-  test_bq = {0, 0, 0, 0, 0, 0, 0, 0, 0};
-  test_bq.b0 = A * A;
-  EXPECT_EQ(bq.b0, test_bq.b0);
-  EXPECT_EQ(bq.b1, test_bq.b1);
-  EXPECT_EQ(bq.b2, test_bq.b2);
-  EXPECT_EQ(bq.a1, test_bq.a1);
-  EXPECT_EQ(bq.a2, test_bq.a2);
-
-  biquad_set(&bq, BQ_HIGHSHELF, f_over, 0, db_gain);
-  test_bq = {0, 0, 0, 0, 0, 0, 0, 0, 0};
-  test_bq.b0 = 1;
-  EXPECT_EQ(bq.b0, test_bq.b0);
-  EXPECT_EQ(bq.b1, test_bq.b1);
-  EXPECT_EQ(bq.b2, test_bq.b2);
-  EXPECT_EQ(bq.a1, test_bq.a1);
-  EXPECT_EQ(bq.a2, test_bq.a2);
-
-  biquad_set(&bq, BQ_PEAKING, f_over, 0, db_gain);
-  test_bq = {0, 0, 0, 0, 0, 0, 0, 0, 0};
-  test_bq.b0 = 1;
-  EXPECT_EQ(bq.b0, test_bq.b0);
-  EXPECT_EQ(bq.b1, test_bq.b1);
-  EXPECT_EQ(bq.b2, test_bq.b2);
-  EXPECT_EQ(bq.a1, test_bq.a1);
-  EXPECT_EQ(bq.a2, test_bq.a2);
-
-  biquad_set(&bq, BQ_NOTCH, f_over, 0, db_gain);
-  test_bq = {0, 0, 0, 0, 0, 0, 0, 0, 0};
-  test_bq.b0 = 1;
-  EXPECT_EQ(bq.b0, test_bq.b0);
-  EXPECT_EQ(bq.b1, test_bq.b1);
-  EXPECT_EQ(bq.b2, test_bq.b2);
-  EXPECT_EQ(bq.a1, test_bq.a1);
-  EXPECT_EQ(bq.a2, test_bq.a2);
-
-  biquad_set(&bq, BQ_ALLPASS, f_over, 0, db_gain);
-  test_bq = {0, 0, 0, 0, 0, 0, 0, 0, 0};
-  test_bq.b0 = 1;
-  EXPECT_EQ(bq.b0, test_bq.b0);
-  EXPECT_EQ(bq.b1, test_bq.b1);
-  EXPECT_EQ(bq.b2, test_bq.b2);
-  EXPECT_EQ(bq.a1, test_bq.a1);
-  EXPECT_EQ(bq.a2, test_bq.a2);
-
-  // check response to frew <= 0
-  biquad_set(&bq, BQ_LOWPASS, f_under, 0, db_gain);
-  test_bq = {0, 0, 0, 0, 0, 0, 0, 0, 0};
-  EXPECT_EQ(bq.b0, test_bq.b0);
-  EXPECT_EQ(bq.b1, test_bq.b1);
-  EXPECT_EQ(bq.b2, test_bq.b2);
-  EXPECT_EQ(bq.a1, test_bq.a1);
-  EXPECT_EQ(bq.a2, test_bq.a2);
-
-  biquad_set(&bq, BQ_HIGHPASS, f_under, 0, db_gain);
-  test_bq = {0, 0, 0, 0, 0, 0, 0, 0, 0};
-  test_bq.b0 = 1;
-  EXPECT_EQ(bq.b0, test_bq.b0);
-  EXPECT_EQ(bq.b1, test_bq.b1);
-  EXPECT_EQ(bq.b2, test_bq.b2);
-  EXPECT_EQ(bq.a1, test_bq.a1);
-  EXPECT_EQ(bq.a2, test_bq.a2);
-
-  biquad_set(&bq, BQ_BANDPASS, f_under, 0, db_gain);
-  test_bq = {0, 0, 0, 0, 0, 0, 0, 0, 0};
-  EXPECT_EQ(bq.b0, test_bq.b0);
-  EXPECT_EQ(bq.b1, test_bq.b1);
-  EXPECT_EQ(bq.b2, test_bq.b2);
-  EXPECT_EQ(bq.a1, test_bq.a1);
-  EXPECT_EQ(bq.a2, test_bq.a2);
-
-  biquad_set(&bq, BQ_LOWSHELF, f_under, 0, db_gain);
-  test_bq = {0, 0, 0, 0, 0, 0, 0, 0, 0};
-  test_bq.b0 = 1;
-  EXPECT_EQ(bq.b0, test_bq.b0);
-  EXPECT_EQ(bq.b1, test_bq.b1);
-  EXPECT_EQ(bq.b2, test_bq.b2);
-  EXPECT_EQ(bq.a1, test_bq.a1);
-  EXPECT_EQ(bq.a2, test_bq.a2);
-
-  biquad_set(&bq, BQ_HIGHSHELF, f_under, 0, db_gain);
-  test_bq = {0, 0, 0, 0, 0, 0, 0, 0, 0};
-  test_bq.b0 = A * A;
-  EXPECT_EQ(bq.b0, test_bq.b0);
-  EXPECT_EQ(bq.b1, test_bq.b1);
-  EXPECT_EQ(bq.b2, test_bq.b2);
-  EXPECT_EQ(bq.a1, test_bq.a1);
-  EXPECT_EQ(bq.a2, test_bq.a2);
-
-  biquad_set(&bq, BQ_PEAKING, f_under, 0, db_gain);
-  test_bq = {0, 0, 0, 0, 0, 0, 0, 0, 0};
-  test_bq.b0 = 1;
-  EXPECT_EQ(bq.b0, test_bq.b0);
-  EXPECT_EQ(bq.b1, test_bq.b1);
-  EXPECT_EQ(bq.b2, test_bq.b2);
-  EXPECT_EQ(bq.a1, test_bq.a1);
-  EXPECT_EQ(bq.a2, test_bq.a2);
-
-  biquad_set(&bq, BQ_NOTCH, f_under, 0, db_gain);
-  test_bq = {0, 0, 0, 0, 0, 0, 0, 0, 0};
-  test_bq.b0 = 1;
-  EXPECT_EQ(bq.b0, test_bq.b0);
-  EXPECT_EQ(bq.b1, test_bq.b1);
-  EXPECT_EQ(bq.b2, test_bq.b2);
-  EXPECT_EQ(bq.a1, test_bq.a1);
-  EXPECT_EQ(bq.a2, test_bq.a2);
-
-  biquad_set(&bq, BQ_ALLPASS, f_under, 0, db_gain);
-  test_bq = {0, 0, 0, 0, 0, 0, 0, 0, 0};
-  test_bq.b0 = 1;
-  EXPECT_EQ(bq.b0, test_bq.b0);
-  EXPECT_EQ(bq.b1, test_bq.b1);
-  EXPECT_EQ(bq.b2, test_bq.b2);
-  EXPECT_EQ(bq.a1, test_bq.a1);
-  EXPECT_EQ(bq.a2, test_bq.a2);
-}
-
-TEST(InvalidQTest, All) {
-  struct biquad bq, test_bq;
-  float f = 0.5;
-  float Q = -0.1;
-  double db_gain = 2;
-  double A = pow(10.0, db_gain / 40);
-
-  // check response to Q <= 0
-  // Low and High pass filters scope Q making the test mute
-
-  biquad_set(&bq, BQ_BANDPASS, f, Q, db_gain);
-  test_bq = {0, 0, 0, 0, 0, 0, 0, 0, 0};
-  test_bq.b0 = 1;
-  EXPECT_EQ(bq.b0, test_bq.b0);
-  EXPECT_EQ(bq.b1, test_bq.b1);
-  EXPECT_EQ(bq.b2, test_bq.b2);
-  EXPECT_EQ(bq.a1, test_bq.a1);
-  EXPECT_EQ(bq.a2, test_bq.a2);
-
-  // Low and high shelf do not compute resonance
-
-  biquad_set(&bq, BQ_PEAKING, f, Q, db_gain);
-  test_bq = {0, 0, 0, 0, 0, 0, 0, 0, 0};
-  test_bq.b0 = A * A;
-  EXPECT_EQ(bq.b0, test_bq.b0);
-  EXPECT_EQ(bq.b1, test_bq.b1);
-  EXPECT_EQ(bq.b2, test_bq.b2);
-  EXPECT_EQ(bq.a1, test_bq.a1);
-  EXPECT_EQ(bq.a2, test_bq.a2);
-
-  biquad_set(&bq, BQ_NOTCH, f, 0, db_gain);
-  test_bq = {0, 0, 0, 0, 0, 0, 0, 0, 0};
-  EXPECT_EQ(bq.b0, test_bq.b0);
-  EXPECT_EQ(bq.b1, test_bq.b1);
-  EXPECT_EQ(bq.b2, test_bq.b2);
-  EXPECT_EQ(bq.a1, test_bq.a1);
-  EXPECT_EQ(bq.a2, test_bq.a2);
-
-  biquad_set(&bq, BQ_ALLPASS, f, 0, db_gain);
-  test_bq = {0, 0, 0, 0, 0, 0, 0, 0, 0};
-  test_bq.b0 = -1;
-  EXPECT_EQ(bq.b0, test_bq.b0);
-  EXPECT_EQ(bq.b1, test_bq.b1);
-  EXPECT_EQ(bq.b2, test_bq.b2);
-  EXPECT_EQ(bq.a1, test_bq.a1);
-  EXPECT_EQ(bq.a2, test_bq.a2);
-}
-
-}  //  namespace
-
-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 d2e9a13..e0f340e 100644
--- a/cras/src/tests/bt_device_unittest.cc
+++ b/cras/src/tests/bt_device_unittest.cc
@@ -5,18 +5,16 @@
 #include <gtest/gtest.h>
 
 extern "C" {
-#include "cras_bt_constants.h"
-#include "cras_bt_device.h"
 #include "cras_bt_io.h"
-#include "cras_bt_log.h"
+#include "cras_bt_device.h"
 #include "cras_iodev.h"
 #include "cras_main_message.h"
 
 #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;
@@ -26,28 +24,9 @@
 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 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;
-};
+static void *cras_main_message_add_handler_callback_data;
 
 void ResetStubData() {
   cras_bt_io_get_profile_ret = NULL;
@@ -57,113 +36,84 @@
   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();
-  }
+  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;
+    }
 
-  virtual void TearDown() {
-    if (cras_main_message_send_msg)
-      free(cras_main_message_send_msg);
-    cras_bt_event_log_deinit(btlog);
-  }
+    virtual void TearDown() {
+      if(cras_main_message_send_msg)
+        free(cras_main_message_send_msg);
+    }
 
-  static void update_active_node(struct cras_iodev* iodev,
-                                 unsigned node_idx,
-                                 unsigned dev_enabled) {}
+    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_;
+    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);
+  cras_bt_device_destroy(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);
 
@@ -173,505 +123,225 @@
   EXPECT_EQ(1, cras_bt_io_remove_called);
   EXPECT_EQ(1, cras_bt_io_destroy_called);
   EXPECT_EQ(0, cras_bt_device_get_active_profile(device));
-  cras_bt_device_remove(device);
+  cras_bt_device_destroy(device);
 }
 
 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_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);
+      cras_main_message_send_msg,
+      cras_main_message_add_handler_callback_data);
+  cras_bt_device_destroy(device);
 }
 
 /* Stubs */
 extern "C" {
 
-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) {
+int cras_bt_io_update_buffer_size(struct cras_iodev *bt_iodev)
+{
+  return 0;
+}
+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) {
-  cras_hfp_ag_suspend_connected_device_called++;
+void cras_hfp_ag_suspend_connected_device(struct cras_bt_device *device)
+{
 }
 
-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_remove_conflict(struct cras_bt_device* device) {
-  cras_hfp_ag_remove_conflict_called++;
+int cras_hfp_ag_start(struct cras_bt_device *device)
+{
   return 0;
 }
 
-int cras_hfp_ag_start(struct cras_bt_device* device) {
-  cras_hfp_ag_start_called++;
-  return 0;
+void cras_hfp_ag_suspend()
+{
 }
 
-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_disable_dev(struct cras_iodev *dev)
+{
+}
 
-void cras_iodev_list_resume_dev(struct cras_iodev* dev) {}
+void cras_iodev_list_enable_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) {
-  cras_tm_create_timer_called++;
-  cras_tm_create_timer_cb = cb;
-  cras_tm_create_timer_cb_data = 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)
+{
   return NULL;
 }
 
-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 cras_tm_cancel_timer(struct cras_tm *tm, struct cras_timer *t)
+{
 }
 
-void dbus_message_unref(DBusMessage* message) {}
+} // extern "C"
+} // namespace
 
-dbus_bool_t dbus_message_append_args(DBusMessage* message,
-                                     int first_arg_type,
-                                     ...) {
-  return true;
-}
-
-dbus_bool_t dbus_connection_send_with_reply(DBusConnection* connection,
-                                            DBusMessage* message,
-                                            DBusPendingCall** pending_return,
-                                            int timeout_milliseconds) {
-  return true;
-}
-
-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) {
+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 97f4dae..aa37cc9 100644
--- a/cras/src/tests/bt_io_unittest.cc
+++ b/cras/src/tests/bt_io_unittest.cc
@@ -11,7 +11,7 @@
 #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 @@
   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,87 +54,93 @@
 namespace {
 
 class BtIoBasicSuite : public testing::Test {
- protected:
-  virtual void SetUp() {
-    ResetStubData();
-    SetUpIodev(&iodev_, CRAS_STREAM_OUTPUT);
-    SetUpIodev(&iodev2_, CRAS_STREAM_OUTPUT);
+  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;
-  }
+      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() {}
+    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;
-  }
+    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;
-  }
+    // 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);
+      free(iodev->ext_format);
+      iodev->format = NULL;
+      iodev->ext_format = NULL;
+      close_dev_called_++;
+      return 0;
+    }
 
-  static struct cras_iodev* bt_iodev;
+  static struct cras_iodev *bt_iodev;
   static struct cras_iodev iodev_;
   static struct cras_iodev iodev2_;
   static unsigned int update_supported_formats_called_;
@@ -146,7 +152,7 @@
   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_;
@@ -158,13 +164,13 @@
 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);
@@ -196,13 +202,13 @@
   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);
@@ -212,7 +218,7 @@
   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 =
@@ -227,7 +233,7 @@
   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 |
@@ -245,7 +251,7 @@
   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 |
@@ -260,10 +266,11 @@
 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);
@@ -275,11 +282,11 @@
 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);
@@ -291,11 +298,11 @@
       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);
 }
 
@@ -305,7 +312,7 @@
       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);
@@ -315,11 +322,12 @@
   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);
 }
 
@@ -329,15 +337,15 @@
   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();
 }
@@ -345,102 +353,121 @@
 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 0758b44..103d3ce 100644
--- a/cras/src/tests/bt_profile_unittest.cc
+++ b/cras/src/tests/bt_profile_unittest.cc
@@ -18,24 +18,24 @@
 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 @@
 };
 
 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, HandleMessage) {
   ExpectMethodCall(PROFILE_MANAGER_OBJ_PATH, BLUEZ_PROFILE_MGMT_INTERFACE,
-                   "RegisterProfile")
+		   "RegisterProfile")
       .WithObjectPath("/fake")
       .SendReply();
 
@@ -117,66 +117,75 @@
   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 f16456b..fd7634f 100644
--- a/cras/src/tests/buffer_share_unittest.cc
+++ b/cras/src/tests/buffer_share_unittest.cc
@@ -2,31 +2,34 @@
 // 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 <gtest/gtest.h>
 
 extern "C" {
-#include "buffer_share.h"
 #include "cras_types.h"
+#include "buffer_share.h"
 }
 
 namespace {
 
-class BufferShareTestSuite : public testing::Test {
- protected:
-  virtual void SetUp() {}
+class BufferShareTestSuite : public testing::Test{
+  protected:
+    virtual void SetUp() {
+    }
 
-  virtual void TearDown() {}
+    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);
@@ -43,7 +46,7 @@
 }
 
 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));
@@ -58,7 +61,7 @@
 }
 
 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);
@@ -80,7 +83,7 @@
 }
 
 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);
@@ -108,7 +111,7 @@
 
 }  //  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 7b28b0f..e0e7bbf 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 "byte_buffer.h"
-
 #include <gtest/gtest.h>
 
+#include "byte_buffer.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 @@
   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 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 @@
   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 @@
   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
deleted file mode 100644
index 5e0bc58..0000000
--- a/cras/src/tests/capture_rclient_unittest.cc
+++ /dev/null
@@ -1,331 +0,0 @@
-// 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 4616515..e4bed40 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 <gtest/gtest.h>
 #include <stdio.h>
+#include <gtest/gtest.h>
 
 extern "C" {
 #include "cras_card_config.h"
@@ -38,21 +38,21 @@
   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, 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, 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 @@
   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,11 +268,13 @@
   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 4d54b2c..5974034 100644
--- a/cras/src/tests/checksum_unittest.cc
+++ b/cras/src/tests/checksum_unittest.cc
@@ -10,28 +10,29 @@
 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
deleted file mode 100644
index 634bfe1..0000000
--- a/cras/src/tests/control_rclient_unittest.cc
+++ /dev/null
@@ -1,1029 +0,0 @@
-// Copyright (c) 2012 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_control_rclient.c"
-#include "cras_rclient_util.c"
-}
-
-//  Stub data.
-static int cras_rstream_create_return;
-static struct cras_rstream* cras_rstream_create_stream_out;
-static int cras_iodev_attach_stream_retval;
-static size_t cras_system_set_volume_value;
-static int cras_system_set_volume_called;
-static size_t cras_system_set_capture_gain_value;
-static int cras_system_set_capture_gain_called;
-static size_t cras_system_set_mute_value;
-static int cras_system_set_mute_called;
-static size_t cras_system_set_user_mute_value;
-static int cras_system_set_user_mute_called;
-static size_t cras_system_set_mute_locked_value;
-static int cras_system_set_mute_locked_called;
-static size_t cras_system_set_capture_mute_value;
-static int cras_system_set_capture_mute_called;
-static size_t cras_system_set_capture_mute_locked_value;
-static int cras_system_set_capture_mute_locked_called;
-static int cras_system_state_dump_snapshots_called;
-static size_t cras_make_fd_nonblocking_called;
-static audio_thread* iodev_get_thread_return;
-static int stream_list_add_stream_return;
-static unsigned int stream_list_add_stream_called;
-static unsigned int stream_list_disconnect_stream_called;
-static unsigned int cras_iodev_list_rm_input_called;
-static unsigned int cras_iodev_list_rm_output_called;
-static unsigned int cras_server_metrics_stream_config_called;
-static struct cras_audio_shm dummy_shm;
-static struct cras_rstream dummy_rstream;
-static size_t cras_observer_num_ops_registered;
-static size_t cras_observer_register_notify_called;
-static size_t cras_observer_add_called;
-static void* cras_observer_add_context_value;
-static struct cras_observer_client* cras_observer_add_return_value;
-static size_t cras_observer_get_ops_called;
-static struct cras_observer_ops cras_observer_ops_value;
-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;
-  cras_rstream_create_stream_out = (struct cras_rstream*)NULL;
-  cras_iodev_attach_stream_retval = 0;
-  cras_server_metrics_stream_config_called = 0;
-  cras_system_set_volume_value = 0;
-  cras_system_set_volume_called = 0;
-  cras_system_set_capture_gain_value = 0;
-  cras_system_set_capture_gain_called = 0;
-  cras_system_set_mute_value = 0;
-  cras_system_set_mute_called = 0;
-  cras_system_set_user_mute_value = 0;
-  cras_system_set_user_mute_called = 0;
-  cras_system_set_mute_locked_value = 0;
-  cras_system_set_mute_locked_called = 0;
-  cras_system_set_capture_mute_value = 0;
-  cras_system_set_capture_mute_called = 0;
-  cras_system_set_capture_mute_locked_value = 0;
-  cras_system_set_capture_mute_locked_called = 0;
-  cras_system_state_dump_snapshots_called = 0;
-  cras_make_fd_nonblocking_called = 0;
-  iodev_get_thread_return = reinterpret_cast<audio_thread*>(0xad);
-  stream_list_add_stream_return = 0;
-  stream_list_add_stream_called = 0;
-  stream_list_disconnect_stream_called = 0;
-  cras_iodev_list_rm_output_called = 0;
-  cras_iodev_list_rm_input_called = 0;
-  cras_observer_num_ops_registered = 0;
-  cras_observer_register_notify_called = 0;
-  cras_observer_add_called = 0;
-  cras_observer_add_return_value =
-      reinterpret_cast<struct cras_observer_client*>(1);
-  cras_observer_add_context_value = NULL;
-  cras_observer_get_ops_called = 0;
-  memset(&cras_observer_ops_value, 0, sizeof(cras_observer_ops_value));
-  cras_observer_set_ops_called = 0;
-  cras_observer_ops_are_empty_called = 0;
-  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 {
-
-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_control_rclient_create(pipe_fds[1], 800);
-  ASSERT_NE((void*)NULL, rclient);
-
-  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);
-  close(pipe_fds[0]);
-  close(pipe_fds[1]);
-}
-
-class RClientMessagesSuite : public testing::Test {
- protected:
-  virtual void SetUp() {
-    int rc;
-    struct cras_client_connected msg;
-
-    rc = pipe(pipe_fds_);
-    if (rc < 0)
-      return;
-    rclient_ = cras_control_rclient_create(pipe_fds_[1], 1);
-    rc = read(pipe_fds_[0], &msg, sizeof(msg));
-    if (rc < 0)
-      return;
-
-    rstream_ = (struct cras_rstream*)calloc(1, sizeof(*rstream_));
-
-    stream_id_ = 0x10002;
-    connect_msg_.header.id = CRAS_SERVER_CONNECT_STREAM;
-    connect_msg_.header.length = sizeof(connect_msg_);
-    connect_msg_.proto_version = CRAS_PROTO_VER;
-    connect_msg_.stream_type = CRAS_STREAM_TYPE_DEFAULT;
-    connect_msg_.direction = CRAS_STREAM_OUTPUT;
-    connect_msg_.stream_id = stream_id_;
-    connect_msg_.buffer_frames = 480;
-    connect_msg_.cb_threshold = 240;
-    connect_msg_.flags = 0;
-    connect_msg_.format.num_channels = 2;
-    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();
-  }
-
-  virtual void TearDown() {
-    rclient_->ops->destroy(rclient_);
-    free(rstream_);
-    close(pipe_fds_[0]);
-    close(pipe_fds_[1]);
-    cras_bt_event_log_deinit(btlog);
-  }
-
-  void RegisterNotification(enum CRAS_CLIENT_MESSAGE_ID msg_id,
-                            void* callback,
-                            void** ops_address);
-
-  struct cras_connect_message connect_msg_;
-  struct cras_rclient* rclient_;
-  struct cras_rstream* rstream_;
-  size_t stream_id_;
-  int pipe_fds_[2];
-  int fd_;
-};
-
-TEST_F(RClientMessagesSuite, AudThreadAttachFail) {
-  struct cras_client_stream_connected out_msg;
-  int rc;
-
-  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,
-                                                 &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);
-}
-
-TEST_F(RClientMessagesSuite, ConnectMsgWithBadFd) {
-  struct cras_client_stream_connected out_msg;
-  int rc;
-
-  rc = rclient_->ops->handle_message_from_client(rclient_, &connect_msg_.header,
-                                                 NULL, 0);
-  EXPECT_EQ(-EBADF, 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(stream_list_add_stream_called,
-            stream_list_disconnect_stream_called);
-  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;
-
-  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(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, SuccessCreateThreadReply) {
-  struct cras_client_stream_connected out_msg;
-  int rc;
-
-  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(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, SetVolume) {
-  struct cras_set_system_volume msg;
-  int rc;
-
-  msg.header.id = CRAS_SERVER_SET_SYSTEM_VOLUME;
-  msg.header.length = sizeof(msg);
-  msg.volume = 66;
-
-  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);
-}
-
-TEST_F(RClientMessagesSuite, SetCaptureVolume) {
-  struct cras_set_system_volume msg;
-  int rc;
-
-  msg.header.id = CRAS_SERVER_SET_SYSTEM_CAPTURE_GAIN;
-  msg.header.length = sizeof(msg);
-  msg.volume = 66;
-
-  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);
-}
-
-TEST_F(RClientMessagesSuite, SetMute) {
-  struct cras_set_system_mute msg;
-  int rc;
-
-  msg.header.id = CRAS_SERVER_SET_SYSTEM_MUTE;
-  msg.header.length = sizeof(msg);
-  msg.mute = 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, NULL, 0);
-  EXPECT_EQ(0, rc);
-  EXPECT_EQ(1, cras_system_set_mute_locked_called);
-  EXPECT_EQ(1, cras_system_set_mute_locked_value);
-}
-
-TEST_F(RClientMessagesSuite, SetUserMute) {
-  struct cras_set_system_mute msg;
-  int rc;
-
-  msg.header.id = CRAS_SERVER_SET_USER_MUTE;
-  msg.header.length = sizeof(msg);
-  msg.mute = 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);
-}
-
-TEST_F(RClientMessagesSuite, SetCaptureMute) {
-  struct cras_set_system_mute msg;
-  int rc;
-
-  msg.header.id = CRAS_SERVER_SET_SYSTEM_CAPTURE_MUTE;
-  msg.header.length = sizeof(msg);
-  msg.mute = 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, 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);
-}
-
-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, NULL, 0);
-  EXPECT_EQ(0, rc);
-  EXPECT_EQ(1, cras_system_state_dump_snapshots_called);
-}
-
-void RClientMessagesSuite::RegisterNotification(
-    enum CRAS_CLIENT_MESSAGE_ID msg_id,
-    void* callback,
-    void** ops_address) {
-  struct cras_register_notification msg;
-  int do_register = callback != NULL ? 1 : 0;
-  int rc;
-
-  cras_observer_register_notify_called++;
-
-  cras_fill_register_notification_message(&msg, msg_id, do_register);
-  EXPECT_EQ(msg.header.length, sizeof(msg));
-  EXPECT_EQ(msg.header.id, CRAS_SERVER_REGISTER_NOTIFICATION);
-  EXPECT_EQ(msg.do_register, do_register);
-  EXPECT_EQ(msg.msg_id, msg_id);
-
-  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,
-            cras_observer_ops_are_empty_called);
-  if (msg.do_register)
-    cras_observer_num_ops_registered++;
-  if (cras_observer_num_ops_registered == 1) {
-    if (msg.do_register) {
-      EXPECT_EQ(1, cras_observer_add_called);
-      EXPECT_EQ(rclient_, cras_observer_add_context_value);
-      EXPECT_EQ(rclient_->observer, cras_observer_add_return_value);
-    } else {
-      EXPECT_EQ(1, cras_observer_remove_called);
-      EXPECT_EQ(rclient_->observer, (struct cras_observer_client*)NULL);
-    }
-  } else {
-    EXPECT_EQ(cras_observer_register_notify_called - 1,
-              cras_observer_set_ops_called);
-  }
-  if (!msg.do_register)
-    cras_observer_num_ops_registered--;
-  if (cras_observer_num_ops_registered) {
-    EXPECT_EQ(callback, *ops_address);
-  }
-}
-
-TEST_F(RClientMessagesSuite, RegisterStatusNotification) {
-  /* First registration for this client. */
-  RegisterNotification(CRAS_CLIENT_OUTPUT_VOLUME_CHANGED,
-                       (void*)send_output_volume_changed,
-                       (void**)&cras_observer_ops_value.output_volume_changed);
-
-  /* Second registration for this client. */
-  RegisterNotification(CRAS_CLIENT_CAPTURE_GAIN_CHANGED,
-                       (void*)send_capture_gain_changed,
-                       (void**)&cras_observer_ops_value.capture_gain_changed);
-
-  /* Deregister output_volume. */
-  RegisterNotification(CRAS_CLIENT_OUTPUT_VOLUME_CHANGED, NULL,
-                       (void**)&cras_observer_ops_value.output_volume_changed);
-
-  /* Register/deregister all msg_ids. */
-
-  RegisterNotification(CRAS_CLIENT_OUTPUT_MUTE_CHANGED,
-                       (void*)send_output_mute_changed,
-                       (void**)&cras_observer_ops_value.output_mute_changed);
-  RegisterNotification(CRAS_CLIENT_OUTPUT_MUTE_CHANGED, NULL,
-                       (void**)&cras_observer_ops_value.output_mute_changed);
-
-  RegisterNotification(CRAS_CLIENT_CAPTURE_MUTE_CHANGED,
-                       (void*)send_capture_mute_changed,
-                       (void**)&cras_observer_ops_value.capture_mute_changed);
-  RegisterNotification(CRAS_CLIENT_CAPTURE_MUTE_CHANGED, NULL,
-                       (void**)&cras_observer_ops_value.capture_mute_changed);
-
-  RegisterNotification(CRAS_CLIENT_NODES_CHANGED, (void*)send_nodes_changed,
-                       (void**)&cras_observer_ops_value.nodes_changed);
-  RegisterNotification(CRAS_CLIENT_NODES_CHANGED, NULL,
-                       (void**)&cras_observer_ops_value.nodes_changed);
-
-  RegisterNotification(CRAS_CLIENT_ACTIVE_NODE_CHANGED,
-                       (void*)send_active_node_changed,
-                       (void**)&cras_observer_ops_value.active_node_changed);
-  RegisterNotification(CRAS_CLIENT_ACTIVE_NODE_CHANGED, NULL,
-                       (void**)&cras_observer_ops_value.active_node_changed);
-
-  RegisterNotification(
-      CRAS_CLIENT_OUTPUT_NODE_VOLUME_CHANGED,
-      (void*)send_output_node_volume_changed,
-      (void**)&cras_observer_ops_value.output_node_volume_changed);
-  RegisterNotification(
-      CRAS_CLIENT_OUTPUT_NODE_VOLUME_CHANGED, NULL,
-      (void**)&cras_observer_ops_value.output_node_volume_changed);
-
-  RegisterNotification(
-      CRAS_CLIENT_NODE_LEFT_RIGHT_SWAPPED_CHANGED,
-      (void*)send_node_left_right_swapped_changed,
-      (void**)&cras_observer_ops_value.node_left_right_swapped_changed);
-  RegisterNotification(
-      CRAS_CLIENT_NODE_LEFT_RIGHT_SWAPPED_CHANGED, NULL,
-      (void**)&cras_observer_ops_value.node_left_right_swapped_changed);
-
-  RegisterNotification(
-      CRAS_CLIENT_INPUT_NODE_GAIN_CHANGED, (void*)send_input_node_gain_changed,
-      (void**)&cras_observer_ops_value.input_node_gain_changed);
-  RegisterNotification(
-      CRAS_CLIENT_INPUT_NODE_GAIN_CHANGED, NULL,
-      (void**)&cras_observer_ops_value.input_node_gain_changed);
-
-  RegisterNotification(
-      CRAS_CLIENT_NUM_ACTIVE_STREAMS_CHANGED,
-      (void*)send_num_active_streams_changed,
-      (void**)&cras_observer_ops_value.num_active_streams_changed);
-  RegisterNotification(
-      CRAS_CLIENT_NUM_ACTIVE_STREAMS_CHANGED, NULL,
-      (void**)&cras_observer_ops_value.num_active_streams_changed);
-
-  /* Deregister last. */
-  RegisterNotification(CRAS_CLIENT_CAPTURE_GAIN_CHANGED, NULL,
-                       (void**)&cras_observer_ops_value.capture_gain_changed);
-}
-
-TEST_F(RClientMessagesSuite, SendOutputVolumeChanged) {
-  void* void_client = reinterpret_cast<void*>(rclient_);
-  char buf[1024];
-  ssize_t rc;
-  struct cras_client_volume_changed* msg =
-      (struct cras_client_volume_changed*)buf;
-  const int32_t volume = 90;
-
-  send_output_volume_changed(void_client, volume);
-  rc = read(pipe_fds_[0], buf, sizeof(buf));
-  ASSERT_EQ(rc, (ssize_t)sizeof(*msg));
-  EXPECT_EQ(msg->header.id, CRAS_CLIENT_OUTPUT_VOLUME_CHANGED);
-  EXPECT_EQ(msg->volume, volume);
-}
-
-TEST_F(RClientMessagesSuite, SendOutputMuteChanged) {
-  void* void_client = reinterpret_cast<void*>(rclient_);
-  char buf[1024];
-  ssize_t rc;
-  struct cras_client_mute_changed* msg = (struct cras_client_mute_changed*)buf;
-  const int muted = 1;
-  const int user_muted = 0;
-  const int mute_locked = 1;
-
-  send_output_mute_changed(void_client, muted, user_muted, mute_locked);
-  rc = read(pipe_fds_[0], buf, sizeof(buf));
-  ASSERT_EQ(rc, (ssize_t)sizeof(*msg));
-  EXPECT_EQ(msg->header.id, CRAS_CLIENT_OUTPUT_MUTE_CHANGED);
-  EXPECT_EQ(msg->muted, muted);
-  EXPECT_EQ(msg->user_muted, user_muted);
-  EXPECT_EQ(msg->mute_locked, mute_locked);
-}
-
-TEST_F(RClientMessagesSuite, SendCaptureGainChanged) {
-  void* void_client = reinterpret_cast<void*>(rclient_);
-  char buf[1024];
-  ssize_t rc;
-  struct cras_client_volume_changed* msg =
-      (struct cras_client_volume_changed*)buf;
-  const int32_t gain = 90;
-
-  send_capture_gain_changed(void_client, gain);
-  rc = read(pipe_fds_[0], buf, sizeof(buf));
-  ASSERT_EQ(rc, (ssize_t)sizeof(*msg));
-  EXPECT_EQ(msg->header.id, CRAS_CLIENT_CAPTURE_GAIN_CHANGED);
-  EXPECT_EQ(msg->volume, gain);
-}
-
-TEST_F(RClientMessagesSuite, SendCaptureMuteChanged) {
-  void* void_client = reinterpret_cast<void*>(rclient_);
-  char buf[1024];
-  ssize_t rc;
-  struct cras_client_mute_changed* msg = (struct cras_client_mute_changed*)buf;
-  const int muted = 1;
-  const int mute_locked = 0;
-
-  send_capture_mute_changed(void_client, muted, mute_locked);
-  rc = read(pipe_fds_[0], buf, sizeof(buf));
-  ASSERT_EQ(rc, (ssize_t)sizeof(*msg));
-  EXPECT_EQ(msg->header.id, CRAS_CLIENT_CAPTURE_MUTE_CHANGED);
-  EXPECT_EQ(msg->muted, muted);
-  EXPECT_EQ(msg->mute_locked, mute_locked);
-}
-
-TEST_F(RClientMessagesSuite, SendNodesChanged) {
-  void* void_client = reinterpret_cast<void*>(rclient_);
-  char buf[1024];
-  ssize_t rc;
-  struct cras_client_nodes_changed* msg =
-      (struct cras_client_nodes_changed*)buf;
-
-  send_nodes_changed(void_client);
-  rc = read(pipe_fds_[0], buf, sizeof(buf));
-  ASSERT_EQ(rc, (ssize_t)sizeof(*msg));
-  EXPECT_EQ(msg->header.id, CRAS_CLIENT_NODES_CHANGED);
-}
-
-TEST_F(RClientMessagesSuite, SendActiveNodeChanged) {
-  void* void_client = reinterpret_cast<void*>(rclient_);
-  char buf[1024];
-  ssize_t rc;
-  struct cras_client_active_node_changed* msg =
-      (struct cras_client_active_node_changed*)buf;
-  const enum CRAS_STREAM_DIRECTION dir = CRAS_STREAM_INPUT;
-  const cras_node_id_t node_id = 0x0001000200030004;
-
-  send_active_node_changed(void_client, dir, node_id);
-  rc = read(pipe_fds_[0], buf, sizeof(buf));
-  ASSERT_EQ(rc, (ssize_t)sizeof(*msg));
-  EXPECT_EQ(msg->header.id, CRAS_CLIENT_ACTIVE_NODE_CHANGED);
-  EXPECT_EQ(msg->direction, (int32_t)dir);
-  EXPECT_EQ((uint64_t)msg->node_id, node_id);
-}
-
-TEST_F(RClientMessagesSuite, SendOutputNodeVolumeChanged) {
-  void* void_client = reinterpret_cast<void*>(rclient_);
-  char buf[1024];
-  ssize_t rc;
-  struct cras_client_node_value_changed* msg =
-      (struct cras_client_node_value_changed*)buf;
-  const cras_node_id_t node_id = 0x0001000200030004;
-  const int32_t value = 90;
-
-  send_output_node_volume_changed(void_client, node_id, value);
-  rc = read(pipe_fds_[0], buf, sizeof(buf));
-  ASSERT_EQ(rc, (ssize_t)sizeof(*msg));
-  EXPECT_EQ(msg->header.id, CRAS_CLIENT_OUTPUT_NODE_VOLUME_CHANGED);
-  EXPECT_EQ(msg->node_id, node_id);
-  EXPECT_EQ(msg->value, value);
-}
-
-TEST_F(RClientMessagesSuite, SendNodeLeftRightSwappedChanged) {
-  void* void_client = reinterpret_cast<void*>(rclient_);
-  char buf[1024];
-  ssize_t rc;
-  struct cras_client_node_value_changed* msg =
-      (struct cras_client_node_value_changed*)buf;
-  const cras_node_id_t node_id = 0x0001000200030004;
-  const int32_t value = 0;
-
-  send_node_left_right_swapped_changed(void_client, node_id, value);
-  rc = read(pipe_fds_[0], buf, sizeof(buf));
-  ASSERT_EQ(rc, (ssize_t)sizeof(*msg));
-  EXPECT_EQ(msg->header.id, CRAS_CLIENT_NODE_LEFT_RIGHT_SWAPPED_CHANGED);
-  EXPECT_EQ(msg->node_id, node_id);
-  EXPECT_EQ(msg->value, value);
-}
-
-TEST_F(RClientMessagesSuite, SendNodeInputNodeGainChanged) {
-  void* void_client = reinterpret_cast<void*>(rclient_);
-  char buf[1024];
-  ssize_t rc;
-  struct cras_client_node_value_changed* msg =
-      (struct cras_client_node_value_changed*)buf;
-  const cras_node_id_t node_id = 0x0001000200030004;
-  const int32_t value = -19;
-
-  send_input_node_gain_changed(void_client, node_id, value);
-  rc = read(pipe_fds_[0], buf, sizeof(buf));
-  ASSERT_EQ(rc, (ssize_t)sizeof(*msg));
-  EXPECT_EQ(msg->header.id, CRAS_CLIENT_INPUT_NODE_GAIN_CHANGED);
-  EXPECT_EQ(msg->node_id, node_id);
-  EXPECT_EQ(msg->value, value);
-}
-
-TEST_F(RClientMessagesSuite, SendNumActiveStreamsChanged) {
-  void* void_client = reinterpret_cast<void*>(rclient_);
-  char buf[1024];
-  ssize_t rc;
-  struct cras_client_num_active_streams_changed* msg =
-      (struct cras_client_num_active_streams_changed*)buf;
-  const enum CRAS_STREAM_DIRECTION dir = CRAS_STREAM_INPUT;
-  const uint32_t num_active_streams = 3;
-
-  send_num_active_streams_changed(void_client, dir, num_active_streams);
-  rc = read(pipe_fds_[0], buf, sizeof(buf));
-  ASSERT_EQ(rc, (ssize_t)sizeof(*msg));
-  EXPECT_EQ(msg->header.id, CRAS_CLIENT_NUM_ACTIVE_STREAMS_CHANGED);
-  EXPECT_EQ(msg->direction, (int32_t)dir);
-  EXPECT_EQ(msg->num_active_streams, num_active_streams);
-}
-
-}  //  namespace
-
-int main(int argc, char** argv) {
-  ::testing::InitGoogleTest(&argc, argv);
-  return RUN_ALL_TESTS();
-}
-
-/* stubs */
-extern "C" {
-
-struct cras_bt_event_log* btlog;
-
-struct audio_thread* cras_iodev_list_get_audio_thread() {
-  return iodev_get_thread_return;
-}
-
-void cras_iodev_list_add_active_node(enum CRAS_STREAM_DIRECTION dir,
-                                     cras_node_id_t node_id) {}
-
-void cras_iodev_list_rm_active_node(enum CRAS_STREAM_DIRECTION dir,
-                                    cras_node_id_t node_id) {}
-
-int audio_thread_rm_stream(audio_thread* thread, cras_rstream* stream) {
-  return 0;
-}
-
-void audio_thread_add_output_dev(struct audio_thread* thread,
-                                 struct cras_iodev* odev) {}
-
-int audio_thread_dump_thread_info(struct audio_thread* thread,
-                                  struct audio_debug_info* info) {
-  return 0;
-}
-
-int audio_thread_suspend(struct audio_thread* thread) {
-  return 0;
-}
-
-int audio_thread_resume(struct audio_thread* thread) {
-  return 0;
-}
-
-int audio_thread_config_global_remix(struct audio_thread* thread,
-                                     unsigned int num_channels,
-                                     const float* coefficient) {
-  return 0;
-}
-
-int audio_thread_set_aec_dump(struct audio_thread* thread,
-                              cras_stream_id_t stream_id,
-                              unsigned int start,
-                              int fd) {
-  return 0;
-}
-
-int audio_thread_event_log_shm_fd() {
-  return -1;
-}
-
-#ifdef HAVE_WEBRTC_APM
-void cras_apm_list_reload_aec_config() {}
-#endif
-
-void cras_system_set_bt_wbs_enabled(bool enabled) {}
-
-const char* cras_config_get_socket_file_dir() {
-  return CRAS_UT_TMPDIR;
-}
-
-int cras_rstream_create(struct cras_rstream_config* stream_config,
-                        struct cras_rstream** stream_out) {
-  *stream_out = cras_rstream_create_stream_out;
-  return cras_rstream_create_return;
-}
-
-unsigned int cras_rstream_get_effects(const struct cras_rstream* stream) {
-  return 0;
-}
-
-int cras_iodev_move_stream_type(uint32_t type, uint32_t index) {
-  return 0;
-}
-
-int cras_iodev_list_rm_output(struct cras_iodev* output) {
-  cras_iodev_list_rm_output_called++;
-  return 0;
-}
-
-int cras_iodev_list_rm_input(struct cras_iodev* input) {
-  cras_iodev_list_rm_input_called++;
-  return 0;
-}
-
-int cras_server_disconnect_from_client_socket(int socket_fd) {
-  return 0;
-}
-
-int cras_make_fd_nonblocking(int fd) {
-  cras_make_fd_nonblocking_called++;
-  return 0;
-}
-
-void cras_system_state_dump_snapshots() {
-  cras_system_state_dump_snapshots_called++;
-}
-
-void cras_system_set_volume(size_t volume) {
-  cras_system_set_volume_value = volume;
-  cras_system_set_volume_called++;
-}
-
-void cras_system_set_capture_gain(long gain) {
-  cras_system_set_capture_gain_value = gain;
-  cras_system_set_capture_gain_called++;
-}
-
-//  From system_state.
-void cras_system_set_mute(int mute) {
-  cras_system_set_mute_value = mute;
-  cras_system_set_mute_called++;
-}
-void cras_system_set_user_mute(int mute) {
-  cras_system_set_user_mute_value = mute;
-  cras_system_set_user_mute_called++;
-}
-void cras_system_set_mute_locked(int mute) {
-  cras_system_set_mute_locked_value = mute;
-  cras_system_set_mute_locked_called++;
-}
-void cras_system_set_capture_mute(int mute) {
-  cras_system_set_capture_mute_value = mute;
-  cras_system_set_capture_mute_called++;
-}
-void cras_system_set_capture_mute_locked(int mute) {
-  cras_system_set_capture_mute_locked_value = mute;
-  cras_system_set_capture_mute_locked_called++;
-}
-
-int cras_system_remove_alsa_card(size_t alsa_card_index) {
-  return -1;
-}
-
-void cras_system_set_suspended(int suspended) {}
-
-struct cras_server_state* cras_system_state_get_no_lock() {
-  return NULL;
-}
-
-key_t cras_sys_state_shm_fd() {
-  return 1;
-}
-
-void cras_dsp_reload_ini() {}
-
-void cras_dsp_dump_info() {}
-
-int cras_iodev_list_set_node_attr(cras_node_id_t id,
-                                  enum ionode_attr attr,
-                                  int value) {
-  return 0;
-}
-
-void cras_iodev_list_select_node(enum CRAS_STREAM_DIRECTION direction,
-                                 cras_node_id_t node_id) {}
-
-void cras_iodev_list_add_test_dev(enum TEST_IODEV_TYPE type) {}
-
-struct stream_list* cras_iodev_list_get_stream_list() {
-  return NULL;
-}
-
-/* Handles sending a command to a test iodev. */
-void cras_iodev_list_test_dev_command(unsigned int iodev_idx,
-                                      enum CRAS_TEST_IODEV_CMD command,
-                                      unsigned int data_len,
-                                      const uint8_t* data) {}
-
-void cras_iodev_list_configure_global_remix_converter(
-    unsigned int num_channels,
-    const float* coefficient) {}
-
-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_stream_called++;
-  ret = stream_list_add_stream_return;
-  if (ret)
-    stream_list_add_stream_return = -EINVAL;
-
-  dummy_rstream.shm = &dummy_shm;
-  dummy_rstream.direction = config->direction;
-  dummy_rstream.stream_id = config->stream_id;
-
-  return ret;
-}
-
-int stream_list_rm(struct stream_list* list, cras_stream_id_t id) {
-  stream_list_disconnect_stream_called++;
-  return 0;
-}
-
-int stream_list_rm_all_client_streams(struct stream_list* list,
-                                      struct cras_rclient* rclient) {
-  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);
-}
-
-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 id,
-                                      const char* model_name) {
-  return 0;
-}
-
-struct cras_observer_client* cras_observer_add(
-    const struct cras_observer_ops* ops,
-    void* context) {
-  cras_observer_add_called++;
-  cras_observer_add_context_value = context;
-  memcpy(&cras_observer_ops_value, ops, sizeof(cras_observer_ops_value));
-  return cras_observer_add_return_value;
-}
-
-void cras_observer_get_ops(const struct cras_observer_client* client,
-                           struct cras_observer_ops* ops) {
-  cras_observer_get_ops_called++;
-  memcpy(ops, &cras_observer_ops_value, sizeof(*ops));
-}
-
-void cras_observer_set_ops(struct cras_observer_client* client,
-                           const struct cras_observer_ops* ops) {
-  cras_observer_set_ops_called++;
-  memcpy(&cras_observer_ops_value, ops, sizeof(cras_observer_ops_value));
-}
-
-int cras_observer_ops_are_empty(const struct cras_observer_ops* ops) {
-  cras_observer_ops_are_empty_called++;
-  return memcmp(&cras_observer_ops_are_empty_empty_ops, ops,
-                sizeof(cras_observer_ops_are_empty_empty_ops)) == 0;
-}
-
-void cras_observer_remove(struct cras_observer_client* client) {
-  cras_observer_remove_called++;
-}
-
-int cras_server_metrics_stream_config(struct cras_rstream_config* config) {
-  cras_server_metrics_stream_config_called++;
-  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 c1103af..4980609 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 <gtest/gtest.h>
 #include <stdio.h>
+#include <gtest/gtest.h>
 
 extern "C" {
 #include "cras_messages.h"
@@ -19,11 +19,13 @@
 static int pthread_cond_timedwait_called;
 static int pthread_cond_timedwait_retval;
 static int close_called;
+static int pipe_called;
 static int sendmsg_called;
-static void* mmap_return_value;
+static int write_called;
+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;
 
@@ -35,7 +37,9 @@
   pthread_cond_timedwait_called = 0;
   pthread_cond_timedwait_retval = 0;
   close_called = 0;
+  pipe_called = 0;
   sendmsg_called = 0;
+  write_called = 0;
   pthread_create_returned_value = 0;
   mmap_return_value = NULL;
   samples_ready_called = 0;
@@ -43,56 +47,53 @@
 }
 
 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);
-    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;
-  }
+  protected:
 
-  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;
+    void InitShm(struct cras_audio_shm* shm) {
+      shm->area = static_cast<cras_audio_shm_area*>(
+          calloc(1, sizeof(*shm->area)));
+      cras_shm_set_frame_bytes(shm, 4);
+      cras_shm_set_used_size(shm, shm_writable_frames_ * 4);
+      memcpy(&shm->area->config, &shm->config, sizeof(shm->config));
     }
 
-    if (stream_.shm) {
-      free(stream_.shm->header);
+    void FreeShm(struct cras_audio_shm* shm) {
+      if (shm->area) {
+        free(shm->area);
+        shm->area = NULL;
+      }
     }
-    free(stream_.shm);
-    stream_.shm = NULL;
-  }
 
-  void StreamConnected(CRAS_STREAM_DIRECTION direction);
+    virtual void SetUp() {
+      shm_writable_frames_ = 100;
+      InitStaticVariables();
 
-  void StreamConnectedFail(CRAS_STREAM_DIRECTION direction);
+      memset(&client_, 0, sizeof(client_));
+      client_.server_fd_state = CRAS_SOCKET_STATE_CONNECTED;
+      memset(&stream_, 0, sizeof(stream_));
+      stream_.id = FIRST_STREAM_ID;
 
-  struct client_stream stream_;
-  struct cras_client client_;
-  int shm_writable_frames_;
+      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;
+      }
+    }
+
+    void StreamConnected(CRAS_STREAM_DIRECTION direction);
+
+    void StreamConnectedFail(CRAS_STREAM_DIRECTION direction);
+
+    struct client_stream stream_;
+    struct cras_client client_;
+    int shm_writable_frames_;
 };
 
 void set_audio_format(struct cras_audio_format* format,
@@ -119,22 +120,21 @@
 }
 
 TEST_F(CrasClientTestSuite, HandleCaptureDataReady) {
-  struct cras_audio_shm* shm;
+  struct cras_audio_shm *shm = &stream_.capture_shm;
 
   stream_.direction = CRAS_STREAM_INPUT;
 
   shm_writable_frames_ = 480;
-  shm = InitShm();
-  stream_.shm = shm;
+  InitShm(shm);
   stream_.config->buffer_frames = 480;
   stream_.config->cb_threshold = 480;
   stream_.config->aud_cb = capture_samples_ready;
   stream_.config->unified_cb = 0;
 
-  shm->header->write_buf_idx = 0;
-  shm->header->read_buf_idx = 0;
-  shm->header->write_offset[0] = 480 * 4;
-  shm->header->read_offset[0] = 0;
+  shm->area->write_buf_idx = 0;
+  shm->area->read_buf_idx = 0;
+  shm->area->write_offset[0] = 480 * 4;
+  shm->area->read_offset[0] = 0;
 
   /* Normal scenario: read buffer has full of data written,
    * handle_capture_data_ready() should consume all 480 frames and move
@@ -143,27 +143,28 @@
   EXPECT_EQ(1, samples_ready_called);
   EXPECT_EQ(480, samples_ready_frames_value);
   EXPECT_EQ(cras_shm_buff_for_idx(shm, 0), samples_ready_samples_value);
-  EXPECT_EQ(1, shm->header->read_buf_idx);
-  EXPECT_EQ(0, shm->header->write_offset[0]);
-  EXPECT_EQ(0, shm->header->read_offset[0]);
+  EXPECT_EQ(1, shm->area->read_buf_idx);
+  EXPECT_EQ(0, shm->area->write_offset[0]);
+  EXPECT_EQ(0, shm->area->read_offset[0]);
 
   /* At the beginning of overrun: handle_capture_data_ready() should not
    * proceed to call audio_cb because there's no data captured. */
-  shm->header->read_buf_idx = 0;
-  shm->header->write_offset[0] = 0;
-  shm->header->read_offset[0] = 0;
+  shm->area->read_buf_idx = 0;
+  shm->area->write_offset[0] = 0;
+  shm->area->read_offset[0] = 0;
   handle_capture_data_ready(&stream_, 480);
   EXPECT_EQ(1, samples_ready_called);
-  EXPECT_EQ(0, shm->header->read_buf_idx);
+  EXPECT_EQ(0, shm->area->read_buf_idx);
 
   /* In the middle of overrun: partially written buffer should trigger
    * audio_cb, feed the full-sized read buffer to client. */
-  shm->header->read_buf_idx = 0;
-  shm->header->write_offset[0] = 123;
-  shm->header->read_offset[0] = 0;
+  shm->area->read_buf_idx = 0;
+  shm->area->write_offset[0] = 123;
+  shm->area->read_offset[0] = 0;
   handle_capture_data_ready(&stream_, 480);
   EXPECT_EQ(1, samples_ready_called);
-  EXPECT_EQ(0, shm->header->read_buf_idx);
+  EXPECT_EQ(0, shm->area->read_buf_idx);
+  FreeShm(shm);
 }
 
 void CrasClientTestSuite::StreamConnected(CRAS_STREAM_DIRECTION direction) {
@@ -172,7 +173,7 @@
   int shm_max_size = 600;
   size_t format_bytes;
   size_t effects = 123;
-  struct cras_audio_shm_header* header;
+  struct cras_audio_shm_area area;
 
   stream_.direction = direction;
   set_audio_format(&stream_.config->format, SND_PCM_FORMAT_S16_LE, 48000, 4);
@@ -182,19 +183,31 @@
 
   // Initialize shm area
   format_bytes = cras_get_format_bytes(&server_format);
-  header = (struct cras_audio_shm_header*)calloc(1, sizeof(*header));
-  header->config.frame_bytes = format_bytes;
-  header->config.used_size = shm_writable_frames_ * format_bytes;
+  memset(&area, 0, sizeof(area));
+  area.config.frame_bytes = format_bytes;
+  area.config.used_size = shm_writable_frames_ * format_bytes;
 
-  mmap_return_value = header;
+  mmap_return_value = &area;
 
-  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);
 
   EXPECT_EQ(CRAS_THREAD_RUNNING, stream_.thread.state);
-  EXPECT_EQ(header, stream_.shm->header);
+
+  if (direction == CRAS_STREAM_OUTPUT) {
+    EXPECT_EQ(NULL, stream_.capture_shm.area);
+    EXPECT_EQ(&area, stream_.play_shm.area);
+  } else {
+    EXPECT_EQ(NULL, stream_.play_shm.area);
+    EXPECT_EQ(&area, stream_.capture_shm.area);
+  }
 }
 
 TEST_F(CrasClientTestSuite, InputStreamConnected) {
@@ -205,13 +218,15 @@
   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;
   size_t format_bytes;
   size_t effects = 123;
-  struct cras_audio_shm_header header;
+  struct cras_audio_shm_area area;
   int rc;
 
   stream_.direction = direction;
@@ -227,20 +242,25 @@
 
   // Initialize shm area
   format_bytes = cras_get_format_bytes(&server_format);
-  memset(&header, 0, sizeof(header));
-  header.config.frame_bytes = format_bytes;
-  header.config.used_size = shm_writable_frames_ * format_bytes;
+  memset(&area, 0, sizeof(area));
+  area.config.frame_bytes = format_bytes;
+  area.config.used_size = shm_writable_frames_ * format_bytes;
 
-  mmap_return_value = &header;
+  mmap_return_value = &area;
 
   // 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) {
@@ -253,123 +273,46 @@
 
 TEST_F(CrasClientTestSuite, AddAndRemoveStream) {
   cras_stream_id_t stream_id;
-  struct cras_disconnect_stream_message msg;
-  int serv_fds[2];
-  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));
+  // Dynamically allocat the stream so that it can be freed later.
+  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(pipe_called, 1);
+  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;
 
-  rc = pipe(serv_fds);
-  EXPECT_EQ(0, rc);
-  client_.server_fd = serv_fds[1];
-  client_.server_fd_state = CRAS_SOCKET_STATE_CONNECTED;
   EXPECT_EQ(0, client_thread_rm_stream(&client_, stream_id));
 
-  rc = read(serv_fds[0], &msg, sizeof(msg));
-  EXPECT_EQ(sizeof(msg), rc);
-  EXPECT_EQ(stream_id, msg.stream_id);
+  // One for the disconnect message to server,
+  // the other is to wake_up the audio thread
+  EXPECT_EQ(2, write_called);
   EXPECT_EQ(1, pthread_join_called);
 
   EXPECT_EQ(NULL, stream_from_id(&client_, stream_id));
 }
 
-TEST_F(CrasClientTestSuite, SetOutputStreamVolume) {
-  cras_stream_id_t stream_id;
+} // namepsace
 
-  client_thread_add_stream(&client_, &stream_, &stream_id, NO_DEVICE);
-  EXPECT_EQ(&stream_, stream_from_id(&client_, stream_id));
-
-  /* Set volume before stream connected. */
-  client_thread_set_stream_volume(&client_, stream_id, 0.3f);
-  StreamConnected(CRAS_STREAM_OUTPUT);
-  EXPECT_EQ(0.3f, cras_shm_get_volume_scaler(stream_.shm));
-
-  /* Set volume after stream connected. */
-  client_thread_set_stream_volume(&client_, stream_id, 0.6f);
-  EXPECT_EQ(0.6f, cras_shm_get_volume_scaler(stream_.shm));
-}
-
-TEST_F(CrasClientTestSuite, SetInputStreamVolume) {
-  cras_stream_id_t stream_id;
-
-  client_thread_add_stream(&client_, &stream_, &stream_id, NO_DEVICE);
-  EXPECT_EQ(&stream_, stream_from_id(&client_, stream_id));
-
-  /* Set volume before stream connected. */
-  client_thread_set_stream_volume(&client_, stream_id, 0.3f);
-  StreamConnected(CRAS_STREAM_INPUT);
-  EXPECT_EQ(0.3f, cras_shm_get_volume_scaler(stream_.shm));
-
-  /* Set volume after stream connected. */
-  client_thread_set_stream_volume(&client_, stream_id, 0.6f);
-  EXPECT_EQ(0.6f, cras_shm_get_volume_scaler(stream_.shm));
-}
-
-TEST(CrasClientTest, InitStreamVolume) {
-  cras_stream_id_t stream_id;
-  struct cras_stream_params config;
-  struct add_stream_command_message cmd_msg;
-  int rc;
-  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);
-  config.err_cb = reinterpret_cast<cras_error_cb_t>(0x456);
-  client.thread.state = CRAS_THREAD_RUNNING;
-  rc = pipe(client.command_reply_fds);
-  EXPECT_EQ(0, rc);
-  rc = pipe(client.command_fds);
-  EXPECT_EQ(0, rc);
-
-  rc = write(client.command_reply_fds[1], &rc, sizeof(rc));
-  cras_client_add_stream(&client, &stream_id, &config);
-
-  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_EQ(1.0f, cmd_msg.stream->volume_scaler);
-
-  if (cmd_msg.stream->config)
-    free(cmd_msg.stream->config);
-  free(cmd_msg.stream);
-}
-
-}  // namespace
-
-int main(int argc, char** argv) {
+int main(int argc, char **argv) {
   ::testing::InitGoogleTest(&argc, argv);
   return RUN_ALL_TESTS();
 }
@@ -377,56 +320,68 @@
 /* stubs */
 extern "C" {
 
-ssize_t sendmsg(int sockfd, const struct msghdr* msg, int flags) {
+ssize_t write(int fd, const void *buf, size_t count) {
+  ++write_called;
+  return count;
+}
+
+ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags) {
   ++sendmsg_called;
   return msg->msg_iov->iov_len;
 }
 
+int pipe(int pipefd[2]) {
+  pipefd[0] = 1;
+  pipefd[1] = 2;
+  ++pipe_called;
+  return 0;
+}
+
 int close(int fd) {
   ++close_called;
   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 b6c733a..21cbc10 100644
--- a/cras/src/tests/cras_dsp_pipeline_unittest.cc
+++ b/cras/src/tests/cras_dsp_pipeline_unittest.cc
@@ -2,23 +2,24 @@
 // 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). */
@@ -31,7 +32,7 @@
 }
 
 struct data {
-  const char* title;
+  const char *title;
   int nr_ports;
   port_direction port_dir[MAX_MOCK_PORTS];
   int nr_in_audio;
@@ -48,7 +49,7 @@
   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];
@@ -62,23 +63,25 @@
   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. */
@@ -87,8 +90,9 @@
   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;
 
@@ -98,8 +102,7 @@
   }
 
   /* 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];
@@ -114,38 +117,43 @@
   }
 }
 
-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) {
@@ -179,12 +187,13 @@
   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];
   }
@@ -192,16 +201,19 @@
 }
 
 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;
 }
 }
@@ -212,7 +224,7 @@
  protected:
   virtual void SetUp() {
     num_modules = 0;
-    strcpy(filename, FILENAME_TEMPLATE);
+    strcpy(filename,  FILENAME_TEMPLATE);
     int fd = mkstemp(filename);
     fp = fdopen(fd, "w");
   }
@@ -230,12 +242,12 @@
   }
 
   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"
@@ -254,23 +266,23 @@
   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);
@@ -332,7 +344,8 @@
 
   /* 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);
@@ -360,7 +373,7 @@
    *                     --(g)-- 6 --(h)--
    */
 
-  const char* content =
+  const char *content =
       "[M6]\n"
       "library=builtin\n"
       "label=foo\n"
@@ -413,18 +426,18 @@
   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);
@@ -437,11 +450,11 @@
   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)-- \
@@ -463,7 +476,7 @@
   /* 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. */
@@ -479,7 +492,8 @@
 
   /* 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 */
@@ -512,7 +526,7 @@
 
 }  //  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/tools/cras_monitor/cras_monitor.c b/cras/src/tests/cras_monitor.c
similarity index 71%
rename from cras/src/tools/cras_monitor/cras_monitor.c
rename to cras/src/tests/cras_monitor.c
index d021669..f09b9f8 100644
--- a/cras/src/tools/cras_monitor/cras_monitor.c
+++ b/cras/src/tests/cras_monitor.c
@@ -24,8 +24,8 @@
 	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_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,22 +49,23 @@
 
 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);
@@ -101,10 +102,10 @@
 		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");
 	}
@@ -112,22 +113,24 @@
 	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;
@@ -136,8 +139,8 @@
 	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 =
@@ -156,8 +159,8 @@
 	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 =
@@ -170,8 +173,8 @@
 				       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,
@@ -180,27 +183,26 @@
 {
 	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);
 }
 
@@ -212,16 +214,16 @@
 	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) {
@@ -256,8 +258,8 @@
 		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);
@@ -267,25 +269,26 @@
 		}
 	}
 
-	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);
@@ -302,7 +305,7 @@
 		}
 	}
 
-	while (1) {
+	while(1) {
 		int rc;
 		char c;
 		rc = read(STDIN_FILENO, &c, 1);
diff --git a/cras/src/tools/cras_router/cras_router.c b/cras/src/tests/cras_router.c
similarity index 73%
rename from cras/src/tools/cras_router/cras_router.c
rename to cras/src/tests/cras_router.c
index b65b052..d813bc6 100644
--- a/cras/src/tools/cras_router/cras_router.c
+++ b/cras/src/tests/cras_router.c
@@ -42,11 +42,14 @@
 }
 
 /* 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;
@@ -62,11 +65,14 @@
 }
 
 /* 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;
@@ -83,16 +89,20 @@
 	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;
 
@@ -101,12 +111,17 @@
 		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;
@@ -125,9 +140,14 @@
 	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;
 
@@ -144,12 +164,17 @@
 
 	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;
 
@@ -169,9 +194,11 @@
 	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)
 {
@@ -207,7 +234,8 @@
 	}
 
 	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) {
@@ -218,7 +246,7 @@
 			rate = atoi(optarg);
 			break;
 		default:
-			break;
+		break;
 		}
 	}
 
diff --git a/cras/src/tests/cras_selinux_helper_unittest.c b/cras/src/tests/cras_selinux_helper_unittest.c
index 64fce14..0e7efad 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_test_client.c b/cras/src/tests/cras_test_client.c
new file mode 100644
index 0000000..c7c4565
--- /dev/null
+++ b/cras/src/tests/cras_test_client.c
@@ -0,0 +1,1645 @@
+/* Copyright (c) 2012 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 <fcntl.h>
+#include <getopt.h>
+#include <inttypes.h>
+#include <math.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <syslog.h>
+#include <sys/param.h>
+#include <sys/select.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "cras_client.h"
+#include "cras_types.h"
+#include "cras_util.h"
+#include "cras_version.h"
+
+#define NOT_ASSIGNED (0)
+#define PLAYBACK_BUFFERED_TIME_IN_US (5000)
+
+#define BUF_SIZE 32768
+
+static const size_t MAX_IODEVS = 10; /* Max devices to print out. */
+static const size_t MAX_IONODES = 20; /* Max ionodes to print out. */
+static const size_t MAX_ATTACHED_CLIENTS = 10; /* Max clients to print out. */
+
+static int pipefd[2];
+static struct timespec last_latency;
+static int show_latency;
+static float last_rms_sqr_sum;
+static int last_rms_size;
+static float total_rms_sqr_sum;
+static int total_rms_size;
+static int show_rms;
+static int show_total_rms;
+static int keep_looping = 1;
+static int exit_after_done_playing = 1;
+static size_t duration_frames;
+static int pause_client = 0;
+static int pause_a_reply = 0;
+static int pause_in_playback_reply = 1000;
+
+static char *channel_layout = NULL;
+static int pin_device_id;
+
+static int play_short_sound = 0;
+static int play_short_sound_periods = 0;
+static int play_short_sound_periods_left = 0;
+
+static int effect_aec = 0;
+static int effect_ns = 0;
+static int effect_agc = 0;
+static int effect_vad = 0;
+static char *aecdump_file = NULL;
+
+/* 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;
+
+struct cras_audio_format *aud_format;
+
+static int terminate_stream_loop()
+{
+	keep_looping = 0;
+	return write(pipefd[1], "1", 1);
+}
+
+static size_t get_block_size(uint64_t buffer_time_in_us, size_t rate)
+{
+	return (size_t)(buffer_time_in_us * rate / 1000000);
+}
+
+static void check_stream_terminate(size_t frames)
+{
+	if (duration_frames) {
+		if (duration_frames <= frames)
+			terminate_stream_loop();
+		else
+			duration_frames -= frames;
+	}
+}
+
+/* Compute square sum of samples (for calculation of RMS value). */
+float compute_sqr_sum_16(const int16_t *samples, int size)
+{
+	unsigned i;
+	float sqr_sum = 0;
+
+	for (i = 0; i < size; i++)
+		sqr_sum += samples[i] * samples[i];
+
+	return sqr_sum;
+}
+
+/* Update the RMS values with the given samples. */
+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_size = size / 2;
+		break;
+	}
+	default:
+		return -EINVAL;
+	}
+
+	total_rms_sqr_sum += last_rms_sqr_sum;
+	total_rms_size += last_rms_size;
+
+	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,
+		       unsigned int frames,
+		       const struct timespec *captured_time,
+		       const struct timespec *playback_time,
+		       void *user_arg)
+{
+	int *fd = (int *)user_arg;
+	int ret;
+	int write_size;
+	int frame_bytes;
+
+	while (pause_client)
+		usleep(10000);
+
+	cras_client_calc_capture_latency(captured_time, &last_latency);
+
+	frame_bytes = cras_client_format_bytes_per_frame(aud_format);
+	write_size = frames * frame_bytes;
+
+	/* Update RMS values with all available frames. */
+	if (keep_looping) {
+		update_rms(captured_samples,
+			   MIN(write_size, duration_frames * frame_bytes));
+	}
+
+	check_stream_terminate(frames);
+
+	ret = write(*fd, captured_samples, write_size);
+	if (ret != write_size)
+		printf("Error writing file\n");
+	return frames;
+}
+
+/* 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,
+		       unsigned int frames,
+		       const struct timespec *captured_time,
+		       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;
+	uint8_t buff[BUF_SIZE];
+	int nread;
+
+	while (pause_client)
+		usleep(10000);
+
+	if (pause_a_reply) {
+		usleep(pause_in_playback_reply);
+		pause_a_reply = 0;
+	}
+
+	check_stream_terminate(frames);
+
+	cras_client_calc_playback_latency(playback_time, &last_latency);
+
+	if (play_short_sound) {
+		if (play_short_sound_periods_left)
+			/* Play a period from file. */
+			play_short_sound_periods_left--;
+		else {
+			/* Fill zeros to play silence. */
+			memset(playback_samples, 0,
+			       MIN(frames * frame_bytes, BUF_SIZE));
+			return frames;
+		}
+	}
+
+	nread = read(fd, buff, MIN(frames * frame_bytes, BUF_SIZE));
+	if (nread <= 0) {
+		if (exit_after_done_playing)
+			terminate_stream_loop();
+		return nread;
+	}
+
+	memcpy(playback_samples, buff, nread);
+	return nread / frame_bytes;
+}
+
+/* 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)
+{
+	int rc = 0;
+	uint32_t frame_bytes = cras_client_format_bytes_per_frame(aud_format);
+
+	rc = read(0, playback_samples, frames * frame_bytes);
+	if (rc <= 0) {
+		terminate_stream_loop();
+		return -1;
+	}
+
+	return rc / frame_bytes;
+}
+
+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 void print_last_latency()
+{
+	if (last_latency.tv_sec > 0 || last_latency.tv_nsec > 0)
+		printf("%u.%09u\n", (unsigned)last_latency.tv_sec,
+		       (unsigned)last_latency.tv_nsec);
+	else {
+		printf("-%lld.%09lld\n", (long long)-last_latency.tv_sec,
+		       (long long)-last_latency.tv_nsec);
+	}
+}
+
+static void print_last_rms()
+{
+	if (last_rms_size != 0)
+		printf("%.9f\n", sqrt(last_rms_sqr_sum / last_rms_size));
+}
+
+static void print_total_rms()
+{
+	if (total_rms_size != 0)
+		printf("%.9f\n", sqrt(total_rms_sqr_sum / total_rms_size));
+}
+
+static void print_dev_info(const struct cras_iodev_info *devs, int num_devs)
+{
+	unsigned i;
+
+	printf("\tID\tName\n");
+	for (i = 0; i < num_devs; i++)
+		printf("\t%u\t%s\n", devs[i].idx, devs[i].name);
+}
+
+static void print_node_info(const struct cras_ionode_info *nodes, int num_nodes,
+			    int is_input)
+{
+	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");
+	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].ionode_idx,
+		       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);
+}
+
+static void print_device_lists(struct cras_client *client)
+{
+	struct cras_iodev_info devs[MAX_IODEVS];
+	struct cras_ionode_info nodes[MAX_IONODES];
+	size_t num_devs, num_nodes;
+	int rc;
+
+	num_devs = MAX_IODEVS;
+	num_nodes = MAX_IONODES;
+	rc = cras_client_get_output_devices(client, devs, nodes, &num_devs,
+					    &num_nodes);
+	if (rc < 0)
+		return;
+	printf("Output Devices:\n");
+	print_dev_info(devs, num_devs);
+	printf("Output Nodes:\n");
+	print_node_info(nodes, num_nodes, 0);
+
+	num_devs = MAX_IODEVS;
+	num_nodes = MAX_IONODES;
+	rc = cras_client_get_input_devices(client, devs, nodes, &num_devs,
+					   &num_nodes);
+	printf("Input Devices:\n");
+	print_dev_info(devs, num_devs);
+	printf("Input Nodes:\n");
+	print_node_info(nodes, num_nodes, 1);
+}
+
+static void print_attached_client_list(struct cras_client *client)
+{
+	struct cras_attached_client_info clients[MAX_ATTACHED_CLIENTS];
+	size_t i;
+	int num_clients;
+
+	num_clients = cras_client_get_attached_clients(client,
+						       clients,
+						       MAX_ATTACHED_CLIENTS);
+	if (num_clients < 0)
+		return;
+	num_clients = MIN(num_clients, MAX_ATTACHED_CLIENTS);
+	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,
+		       clients[i].gid);
+}
+
+static void print_active_stream_info(struct cras_client *client)
+{
+	struct timespec ts;
+	unsigned num_streams;
+
+	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);
+}
+
+static void print_system_volumes(struct cras_client *client)
+{
+	printf("System Volume (0-100): %zu %s\n"
+	       "Capture Gain (%.2f - %.2f): %.2fdB %s\n",
+	       cras_client_get_system_volume(client),
+	       cras_client_get_system_muted(client) ? "(Muted)" : "",
+	       cras_client_get_system_min_capture_gain(client) / 100.0,
+	       cras_client_get_system_max_capture_gain(client) / 100.0,
+	       cras_client_get_system_capture_gain(client) / 100.0,
+	       cras_client_get_system_capture_muted(client) ? "(Muted)" : "");
+}
+
+static void print_user_muted(struct cras_client *client)
+{
+	printf("User muted: %s\n",
+	       cras_client_get_user_muted(client) ? "Muted" : "Not muted");
+}
+
+static void show_alog_tag(const struct audio_thread_event_log *log,
+			  unsigned int tag_idx)
+{
+	unsigned int tag = (log->log[tag_idx].tag_sec >> 24) & 0xff;
+	unsigned int sec = log->log[tag_idx].tag_sec & 0x00ffffff;
+	unsigned int nsec = log->log[tag_idx].nsec;
+	unsigned int data1 = log->log[tag_idx].data1;
+	unsigned int data2 = log->log[tag_idx].data2;
+	unsigned int data3 = log->log[tag_idx].data3;
+
+	/* Skip unused log entries. */
+	if (log->log[tag_idx].tag_sec == 0 && log->log[tag_idx].nsec == 0)
+		return;
+
+	printf("%10u.%09u  ", sec, nsec);
+
+	switch (tag) {
+	case AUDIO_THREAD_WAKE:
+		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);
+		break;
+	case AUDIO_THREAD_READ_AUDIO:
+		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:%09d.%09d\n",
+		       "READ_AUDIO_TSTAMP", data1, (int)data2, (int)data3);
+		break;
+	case AUDIO_THREAD_READ_AUDIO_DONE:
+		printf("%-30s read_remainder:%u\n", "READ_AUDIO_DONE", data1);
+		break;
+	case AUDIO_THREAD_READ_OVERRUN:
+		printf("%-30s dev:%u stream:%x num_overruns:%u\n",
+		       "READ_AUDIO_OVERRUN", data1, data2, data3);
+		break;
+	case AUDIO_THREAD_FILL_AUDIO:
+		printf("%-30s dev:%u hw_level:%u\n",
+		       "FILL_AUDIO", data1, data2);
+		break;
+	case AUDIO_THREAD_FILL_AUDIO_TSTAMP:
+		printf("%-30s dev:%u tstamp:%09d.%09d\n",
+		       "FILL_AUDIO_TSTAMP", data1, (int)data2, (int)data3);
+		break;
+	case AUDIO_THREAD_FILL_AUDIO_DONE:
+		printf("%-30s hw_level:%u total_written:%u min_cb_level:%u\n",
+		       "FILL_AUDIO_DONE", data1, data2, data3);
+		break;
+	case AUDIO_THREAD_WRITE_STREAMS_WAIT:
+		printf("%-30s stream:%x\n", "WRITE_STREAMS_WAIT", data1);
+		break;
+	case AUDIO_THREAD_WRITE_STREAMS_WAIT_TO:
+		printf("%-30s\n", "WRITE_STREAMS_WAIT_TO");
+		break;
+	case AUDIO_THREAD_WRITE_STREAMS_MIX:
+		printf("%-30s write_limit:%u max_offset:%u\n",
+		       "WRITE_STREAMS_MIX", data1, data2);
+		break;
+	case AUDIO_THREAD_WRITE_STREAMS_MIXED:
+		printf("%-30s write_limit:%u\n", "WRITE_STREAMS_MIXED", data1);
+		break;
+	case AUDIO_THREAD_WRITE_STREAMS_STREAM:
+		printf("%-30s id:%x shm_frames:%u cb_pending:%u\n",
+		       "WRITE_STREAMS_STREAM", data1, data2, data3);
+		break;
+	case AUDIO_THREAD_FETCH_STREAM:
+		printf("%-30s id:%x cbth:%u delay:%u\n",
+		       "WRITE_STREAMS_FETCH_STREAM", data1, data2, data3);
+		break;
+	case AUDIO_THREAD_STREAM_ADDED:
+		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);
+		break;
+	case AUDIO_THREAD_A2DP_WRITE:
+		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);
+		break;
+	case AUDIO_THREAD_CAPTURE_POST:
+		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);
+		break;
+	case AUDIO_THREAD_CONV_COPY:
+		printf("%-30s wr_buf:%u shm_writable:%u offset:%u\n",
+		       "CONV_COPY", data1, data2, data3);
+		break;
+	case AUDIO_THREAD_STREAM_SLEEP_TIME:
+		printf("%-30s id:%x wake:%09u.%09d\n",
+		       "STREAM_SLEEP_TIME", data1, (int)data2, (int)data3);
+		break;
+	case AUDIO_THREAD_STREAM_SLEEP_ADJUST:
+		printf("%-30s id:%x from:%09u.%09d\n",
+		       "STREAM_SLEEP_ADJUST", data1, data2, data3);
+		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:%09u.%09d\n",
+		       "DEV_SLEEP_TIME", data1, data2, data3);
+		break;
+	case AUDIO_THREAD_SET_DEV_WAKE:
+		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);
+		break;
+	case AUDIO_THREAD_DEV_REMOVED:
+		printf("%-30s dev:%u\n", "DEV_REMOVED", data1);
+		break;
+	case AUDIO_THREAD_IODEV_CB:
+		printf("%-30s is_write:%u\n", "IODEV_CB", data1);
+		break;
+	case AUDIO_THREAD_PB_MSG:
+		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);
+		break;
+	case AUDIO_THREAD_ODEV_LEAVE_NO_STREAMS:
+		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);
+		break;
+	case AUDIO_THREAD_FILL_ODEV_ZEROS:
+		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",
+		       "DEFAULT_NO_STREAMS", data1, data2, data3);
+		break;
+	case AUDIO_THREAD_UNDERRUN:
+		printf("%-30s dev:%u hw_level:%u total_written:%u\n",
+		       "UNDERRUN", data1, data2, data3);
+		break;
+	case AUDIO_THREAD_SEVERE_UNDERRUN:
+		printf("%-30s dev:%u\n", "SEVERE_UNDERRUN", data1);
+		break;
+	default:
+		printf("%-30s tag:%u\n","UNKNOWN", tag);
+		break;
+	}
+}
+
+static void print_audio_debug_info(const struct audio_debug_info *info)
+{
+	int i, j;
+	printf("Audio Debug Stats:\n");
+	printf("-------------devices------------\n");
+	if (info->num_devs > MAX_DEBUG_DEVS)
+		return;
+
+	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].dev_name);
+		printf("buffer_size: %u\n"
+		       "min_buffer_level: %u\n"
+		       "min_cb_level: %u\n"
+		       "max_cb_level: %u\n"
+		       "frame_rate: %u\n"
+		       "num_channels: %u\n"
+		       "est_rate_ratio: %lf\n"
+		       "num_underruns: %u\n"
+		       "num_severe_underruns: %u\n"
+		       "highest_hw_level: %u\n",
+		       (unsigned int)info->devs[i].buffer_size,
+		       (unsigned int)info->devs[i].min_buffer_level,
+		       (unsigned int)info->devs[i].min_cb_level,
+		       (unsigned int)info->devs[i].max_cb_level,
+		       (unsigned int)info->devs[i].frame_rate,
+		       (unsigned int)info->devs[i].num_channels,
+		       info->devs[i].est_rate_ratio,
+		       (unsigned int)info->devs[i].num_underruns,
+		       (unsigned int)info->devs[i].num_severe_underruns,
+		       (unsigned int)info->devs[i].highest_hw_level);
+		printf("\n");
+	}
+
+	printf("-------------stream_dump------------\n");
+	if (info->num_streams > MAX_DEBUG_STREAMS)
+		return;
+
+	for (i = 0; i < info->num_streams; i++) {
+		int channel;
+		printf("stream: %llu dev: %u\n",
+		       (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");
+		printf("stream_type: %s\n",
+		       cras_stream_type_str(info->streams[i].stream_type));
+		printf("buffer_frames: %u\n"
+		       "cb_threshold: %u\n"
+		       "effects: 0x%.4x\n"
+		       "frame_rate: %u\n"
+		       "num_channels: %u\n"
+		       "longest_fetch_sec: %u.%09u\n"
+		       "num_overruns: %u\n",
+		       (unsigned int)info->streams[i].buffer_frames,
+		       (unsigned int)info->streams[i].cb_threshold,
+		       (unsigned int)info->streams[i].effects,
+		       (unsigned int)info->streams[i].frame_rate,
+		       (unsigned int)info->streams[i].num_channels,
+		       (unsigned int)info->streams[i].longest_fetch_sec,
+		       (unsigned int)info->streams[i].longest_fetch_nsec,
+		       (unsigned int)info->streams[i].num_overruns);
+		printf("channel map:");
+		for (channel = 0; channel < CRAS_CH_MAX; channel++)
+			printf("%d ", info->streams[i].channel_layout[channel]);
+		printf("\n\n");
+	}
+
+	printf("Audio Thread Event Log:\n");
+
+	j = info->log.write_pos;
+	i = 0;
+	printf("start at %d\n", j);
+	for (; i < info->log.len; i++) {
+		show_alog_tag(&info->log, j);
+		j++;
+		j %= info->log.len;
+	}
+}
+
+static void audio_debug_info(struct cras_client *client)
+{
+	const struct audio_debug_info *info;
+	info = cras_client_get_audio_debug_info(client);
+	if (!info)
+		return;
+	print_audio_debug_info(info);
+
+	/* Signal main thread we are done after the last chunk. */
+	pthread_mutex_lock(&done_mutex);
+	pthread_cond_signal(&done_cond);
+	pthread_mutex_unlock(&done_mutex);
+}
+
+static void print_cras_audio_thread_snapshot(
+	const struct cras_audio_thread_snapshot *snapshot)
+{
+	printf("-------------snapshot------------\n");
+	printf("Event time: %" PRId64 ".%ld\n",
+	       (int64_t)snapshot->timestamp.tv_sec,
+	       snapshot->timestamp.tv_nsec);
+
+	printf("Event type: ");
+	switch(snapshot->event_type) {
+	case AUDIO_THREAD_EVENT_BUSYLOOP:
+		printf("busyloop\n");
+		break;
+	case AUDIO_THREAD_EVENT_UNDERRUN:
+		printf("underrun\n");
+		break;
+	case AUDIO_THREAD_EVENT_SEVERE_UNDERRUN:
+		printf("severe underrun\n");
+		break;
+	case AUDIO_THREAD_EVENT_DEBUG:
+		printf("debug\n");
+		break;
+	default:
+		printf("no such type\n");
+	}
+	print_audio_debug_info(&snapshot->audio_debug_info);
+}
+
+static void audio_thread_snapshots(struct cras_client *client)
+{
+	const struct cras_audio_thread_snapshot_buffer *snapshot_buffer;
+	uint32_t i;
+	int j;
+	int count = 0;
+
+	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)
+		{
+			print_cras_audio_thread_snapshot(
+				&snapshot_buffer->snapshots[i]);
+			count++;
+		}
+		i++;
+		i %= CRAS_MAX_AUDIO_THREAD_SNAPSHOTS;
+	}
+	printf("There are %d, snapshots.\n", count);
+
+	/* Signal main thread we are done after the last chunk. */
+	pthread_mutex_lock(&done_mutex);
+	pthread_cond_signal(&done_cond);
+	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)
+{
+	int rc;
+
+	if (pin_device_id)
+		rc = cras_client_add_pinned_stream(client, pin_device_id,
+						   stream_id, params);
+	else
+		rc = cras_client_add_stream(client, stream_id, params);
+	if (rc < 0) {
+		fprintf(stderr, "adding a stream %d\n", rc);
+		return rc;
+	}
+	return cras_client_set_stream_volume(client, *stream_id, stream_volume);
+}
+
+static int parse_channel_layout(char *channel_layout_str,
+				int8_t channel_layout[CRAS_CH_MAX])
+{
+	int i = 0;
+	char *chp;
+
+	chp = strtok(channel_layout_str, ",");
+	while (chp && i < CRAS_CH_MAX) {
+		channel_layout[i++] = atoi(chp);
+		chp = strtok(NULL, ",");
+	}
+
+	return 0;
+}
+
+static void run_aecdump(struct cras_client *client, uint64_t stream_id,
+			int start)
+{
+	int aecdump_fd;
+	if (start) {
+		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;
+		}
+
+		printf("Dumping AEC info to %s, stream %" PRId64 ", fd %d\n",
+		       aecdump_file, stream_id, aecdump_fd);
+		cras_client_set_aec_dump(client, stream_id, 1, aecdump_fd);
+	} else {
+		cras_client_set_aec_dump(client, stream_id, 0, -1);
+		printf("Close AEC dump file %s\n", aecdump_file);
+	}
+}
+
+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,
+			      size_t num_channels,
+			      uint32_t flags,
+			      int is_loopback,
+			      int is_post_dsp)
+{
+	int rc, tty;
+	struct cras_stream_params *params;
+	cras_unified_cb_t aud_cb;
+	cras_stream_id_t stream_id = 0;
+	int stream_playing = 0;
+	int *pfd = malloc(sizeof(*pfd));
+	*pfd = fd;
+	fd_set poll_set;
+	struct timespec sleep_ts;
+	float volume_scaler = 1.0;
+	size_t sys_volume = 100;
+	long cap_gain = 0;
+	int mute = 0;
+	int8_t layout[CRAS_CH_MAX];
+
+	/* Set the sleep interval between latency/RMS prints. */
+	sleep_ts.tv_sec = 1;
+	sleep_ts.tv_nsec = 0;
+
+	/* Open the pipe file descriptor. */
+	rc = pipe(pipefd);
+	if (rc == -1) {
+		perror("failed to open pipe");
+		return -errno;
+	}
+
+	/* Reset the total RMS value. */
+	total_rms_sqr_sum = 0;
+	total_rms_size = 0;
+
+	if (direction == CRAS_STREAM_INPUT)
+		aud_cb = got_samples;
+	else
+		aud_cb = put_samples;
+
+	if (fd == 0) {
+		if (direction != CRAS_STREAM_OUTPUT)
+			return -EINVAL;
+		aud_cb = put_stdin_samples;
+	}
+
+	aud_format = cras_audio_format_create(SND_PCM_FORMAT_S16_LE, rate,
+					      num_channels);
+	if (aud_format == NULL)
+		return -ENOMEM;
+
+	if (channel_layout) {
+		/* Set channel layout to format */
+		parse_channel_layout(channel_layout, layout);
+		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,
+						   aud_format);
+	if (params == NULL)
+		return -ENOMEM;
+
+	if (effect_aec)
+		cras_client_stream_params_enable_aec(params);
+	if (effect_ns)
+		cras_client_stream_params_enable_ns(params);
+	if (effect_agc)
+		cras_client_stream_params_enable_agc(params);
+	if (effect_vad)
+		cras_client_stream_params_enable_vad(params);
+
+	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);
+
+		cras_client_connected_wait(client);
+		pin_device_id = cras_client_get_first_dev_type_idx(
+				client, type, CRAS_STREAM_INPUT);
+	}
+
+	stream_playing =
+		start_stream(client, &stream_id, params, volume_scaler) == 0;
+
+	tty = open("/dev/tty", O_RDONLY);
+
+	// There could be no terminal available when run in autotest.
+	if (tty == -1)
+		perror("warning: failed to open /dev/tty");
+
+	while (keep_looping) {
+		char input;
+		int nread;
+
+		FD_ZERO(&poll_set);
+		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);
+
+		if (stream_playing && show_latency)
+			print_last_latency();
+
+		if (stream_playing && show_rms)
+			print_last_rms();
+
+		if (tty < 0 || !FD_ISSET(tty, &poll_set))
+			continue;
+
+		nread = read(tty, &input, 1);
+		if (nread < 1) {
+			fprintf(stderr, "Error reading stdin\n");
+			return nread;
+		}
+		switch (input) {
+		case 'p':
+			pause_client = !pause_client;
+			break;
+		case 'i':
+			pause_a_reply = 1;
+			break;
+		case 'q':
+			terminate_stream_loop();
+			break;
+		case 's':
+			if (stream_playing)
+				break;
+
+			/* 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;
+			break;
+		case 'r':
+			if (!stream_playing)
+				break;
+			cras_client_rm_stream(client, stream_id);
+			stream_playing = 0;
+			break;
+		case 'u':
+			volume_scaler = MIN(volume_scaler + 0.1, 1.0);
+			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,
+						      volume_scaler);
+			break;
+		case 'k':
+			sys_volume = MIN(sys_volume + 1, 100);
+			cras_client_set_system_volume(client, sys_volume);
+			break;
+		case 'j':
+			sys_volume = sys_volume == 0 ? 0 : sys_volume - 1;
+			cras_client_set_system_volume(client, sys_volume);
+			break;
+		case 'K':
+			cap_gain = MIN(cap_gain + 100, 5000);
+			cras_client_set_system_capture_gain(client, cap_gain);
+			break;
+		case 'J':
+			cap_gain = cap_gain == -5000 ? -5000 : cap_gain - 100;
+			cras_client_set_system_capture_gain(client, cap_gain);
+			break;
+		case 'm':
+			mute = !mute;
+			cras_client_set_system_mute(client, mute);
+			break;
+		case '@':
+			print_device_lists(client);
+			break;
+		case '#':
+			print_attached_client_list(client);
+			break;
+		case 'v':
+			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_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)" : "",
+			       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;
+			break;
+		case '\n':
+			break;
+		default:
+			printf("Invalid key\n");
+			break;
+		}
+	}
+
+	if (show_total_rms)
+		print_total_rms();
+
+	cras_client_stop(client);
+
+	cras_audio_format_destroy(aud_format);
+	cras_client_stream_params_destroy(params);
+	free(pfd);
+
+	close(pipefd[0]);
+	close(pipefd[1]);
+
+	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,
+		       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);
+	if (fd == -1) {
+		perror("failed to open file");
+		return -errno;
+	}
+
+	run_file_io_stream(client, fd, CRAS_STREAM_INPUT, block_size,
+			   stream_type, rate, num_channels, flags, is_loopback,
+			   is_post_dsp);
+
+	close(fd);
+	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,
+			size_t num_channels)
+{
+	int fd;
+
+	fd = open(file, O_RDONLY);
+	if (fd == -1) {
+		perror("failed to open file");
+		return -errno;
+	}
+
+	run_file_io_stream(client, fd, CRAS_STREAM_OUTPUT, block_size,
+			   stream_type, rate, num_channels, 0, 0, 0);
+
+	close(fd);
+	return 0;
+}
+
+static void print_server_info(struct cras_client *client)
+{
+	cras_client_run_thread(client);
+	cras_client_connected_wait(client); /* To synchronize data. */
+	print_system_volumes(client);
+	print_user_muted(client);
+	print_device_lists(client);
+	print_attached_client_list(client);
+	print_active_stream_info(client);
+}
+
+static void show_audio_thread_snapshots(struct cras_client *client)
+{
+	struct timespec wait_time;
+
+	cras_client_run_thread(client);
+	cras_client_connected_wait(client); /* To synchronize data. */
+	cras_client_update_audio_thread_snapshots(client,
+						  audio_thread_snapshots);
+
+	clock_gettime(CLOCK_REALTIME, &wait_time);
+	wait_time.tv_sec += 2;
+
+	pthread_mutex_lock(&done_mutex);
+	pthread_cond_timedwait(&done_cond, &done_mutex, &wait_time);
+	pthread_mutex_unlock(&done_mutex);
+}
+
+static void show_audio_debug_info(struct cras_client *client)
+{
+	struct timespec wait_time;
+
+	cras_client_run_thread(client);
+	cras_client_connected_wait(client); /* To synchronize data. */
+	cras_client_update_audio_debug_info(client, audio_debug_info);
+
+	clock_gettime(CLOCK_REALTIME, &wait_time);
+	wait_time.tv_sec += 2;
+
+	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,
+			      const char *hotword_models)
+{
+	printf("Hotword models: %s\n", hotword_models);
+}
+
+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);
+
+	clock_gettime(CLOCK_REALTIME, &wait_time);
+	wait_time.tv_sec += 2;
+
+	pthread_mutex_lock(&done_mutex);
+	pthread_cond_timedwait(&done_cond, &done_mutex, &wait_time);
+	pthread_mutex_unlock(&done_mutex);
+}
+
+static void check_output_plugged(struct cras_client *client, const char *name)
+{
+	cras_client_run_thread(client);
+	cras_client_connected_wait(client); /* To synchronize data. */
+	printf("%s\n",
+	       cras_client_output_dev_plugged(client, name) ? "Yes" : "No");
+}
+
+/* Repeatedly mute and unmute the output until there is an error. */
+static void mute_loop_test(struct cras_client *client, int auto_reconnect)
+{
+	int mute = 0;
+	int rc;
+
+	if (auto_reconnect)
+		cras_client_run_thread(client);
+	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)
+			return;
+		mute = !mute;
+		sleep(2);
+	}
+}
+
+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},
+	{"select_input",        required_argument,      0, 'a'},
+	{"block_size",		required_argument,	0, 'b'},
+	{"capture_file",	required_argument,	0, 'c'},
+	{"duration_seconds",	required_argument,	0, 'd'},
+	{"dump_events",	        no_argument,            0, 'e'},
+	{"dump_dsp",            no_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_output",	required_argument,	0, 't'},
+	{"loopback_file",	required_argument,	0, 'l'},
+	{"dump_audio_thread",   no_argument,            0, 'm'},
+	{"num_channels",        required_argument,      0, 'n'},
+	{"channel_layout",      required_argument,      0, 'o'},
+	{"playback_file",	required_argument,	0, 'p'},
+	{"user_mute",           required_argument,      0, 'q'},
+	{"rate",		required_argument,	0, 'r'},
+	{"reload_dsp",          no_argument,            0, 's'},
+	{"mute",                required_argument,      0, 'u'},
+	{"volume",              required_argument,      0, 'v'},
+	{"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'},
+	{"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'},
+	{"aecdump",		required_argument,	0, 'C'},
+	{"reload_aec_config",	no_argument,		0, 'D'},
+	{"effects",		required_argument,	0, 'E'},
+	{"get_aec_supported",	no_argument,		0, 'F'},
+	{"syslog_mask",		required_argument,	0, 'L'},
+	{"mute_loop_test",	required_argument,	0, 'M'},
+	{"stream_type",		required_argument,	0, 'T'},
+	{0, 0, 0, 0}
+};
+
+static void show_usage()
+{
+	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_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("--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, "
+	       "\"-\" 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");
+}
+
+int main(int argc, char **argv)
+{
+	struct cras_client *client;
+	int c, option_index;
+	size_t block_size = NOT_ASSIGNED;
+	size_t rate = 48000;
+	size_t num_channels = 2;
+	float duration_seconds = 0;
+	const char *capture_file = NULL;
+	const char *playback_file = NULL;
+	const char *loopback_file = NULL;
+	int post_dsp = 0;
+	enum CRAS_STREAM_TYPE stream_type = CRAS_STREAM_TYPE_DEFAULT;
+	int rc = 0;
+	uint32_t stream_flags = 0;
+	cras_stream_id_t stream_id = 0;
+
+	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);
+	if (rc) {
+		fprintf(stderr, "Couldn't connect to server.\n");
+		goto destroy_exit;
+	}
+
+	while (1) {
+		c = getopt_long(argc, argv, "o:s:",
+				long_options, &option_index);
+		if (c == -1)
+			break;
+		switch (c) {
+		case 'c':
+			capture_file = optarg;
+			break;
+		case 'p':
+			playback_file = optarg;
+			break;
+		case 'l':
+			loopback_file = optarg;
+			break;
+		case 'A':
+			post_dsp = atoi(optarg);
+			break;
+		case 'b':
+			block_size = atoi(optarg);
+			break;
+		case 'r':
+			rate = atoi(optarg);
+			break;
+		case 'n':
+			num_channels = atoi(optarg);
+			break;
+		case 'd':
+			duration_seconds = atof(optarg);
+			break;
+		case 'u': {
+			int mute = atoi(optarg);
+			rc = cras_client_set_system_mute(client, mute);
+			if (rc < 0) {
+				fprintf(stderr, "problem setting mute\n");
+				goto destroy_exit;
+			}
+			break;
+		}
+		case 'q': {
+			int mute = atoi(optarg);
+			rc = cras_client_set_user_mute(client, mute);
+			if (rc < 0) {
+				fprintf(stderr, "problem setting mute\n");
+				goto destroy_exit;
+			}
+			break;
+		}
+		case 'v': {
+			int volume = atoi(optarg);
+			volume = MIN(100, MAX(0, volume));
+			rc = cras_client_set_system_volume(client, volume);
+			if (rc < 0) {
+				fprintf(stderr, "problem setting volume\n");
+				goto destroy_exit;
+			}
+			break;
+		}
+		case 'g': {
+			long gain = atol(optarg);
+			rc = cras_client_set_system_capture_gain(client, gain);
+			if (rc < 0) {
+				fprintf(stderr, "problem setting capture\n");
+				goto destroy_exit;
+			}
+			break;
+		}
+		case 'j':
+			check_output_plugged(client, optarg);
+			break;
+		case 's':
+			cras_client_reload_dsp(client);
+			break;
+		case 'f':
+			cras_client_dump_dsp_info(client);
+			break;
+		case 'i':
+			print_server_info(client);
+			break;
+		case 'h':
+			show_usage();
+			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);
+			enum ionode_attr attr = IONODE_ATTR_PLUGGED;
+			cras_client_set_node_attr(client, id, attr, value);
+			break;
+		}
+		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);
+
+			enum CRAS_STREAM_DIRECTION direction = (c == 'y') ?
+				CRAS_STREAM_OUTPUT : CRAS_STREAM_INPUT;
+			cras_client_select_node(client, direction, id);
+			break;
+		}
+		case 'z':
+			pause_in_playback_reply = atoi(optarg);
+			break;
+		case 'k':
+		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);
+
+			if (c == 't' || c == '2')
+				dir = CRAS_STREAM_OUTPUT;
+			else
+				dir = CRAS_STREAM_INPUT;
+
+			if (c == 'k' || c == 't')
+				cras_client_add_active_node(client, dir, id);
+			else
+				cras_client_rm_active_node(client, dir, id);
+			break;
+		}
+		case ':':
+		case 'w': {
+			const char *s;
+			int dev_index;
+			int node_index;
+			int value;
+
+			s = strtok(optarg, ":");
+			if (!s) {
+				show_usage();
+				return -EINVAL;
+			}
+			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);
+			break;
+		}
+		case '0': {
+			int mute = atoi(optarg);
+			rc = cras_client_set_system_capture_mute(client, mute);
+			if (rc < 0) {
+				fprintf(stderr, "problem setting mute\n");
+				goto destroy_exit;
+			}
+			break;
+		}
+		case 'e':
+			show_audio_thread_snapshots(client);
+			break;
+		case 'm':
+			show_audio_debug_info(client);
+			break;
+		case 'o':
+			channel_layout = optarg;
+			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_client_swap_node_left_right(client, id, value);
+			break;
+		}
+		case '4':
+			printf("%s\n", VCSID);
+			break;
+		case '5': {
+			cras_client_add_test_iodev(client, atoi(optarg));
+			break;
+		}
+		case '6': {
+			int dev_index = atoi(strtok(optarg, ":"));
+			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);
+			break;
+		}
+		case '7': {
+			stream_flags = HOTWORD_STREAM;
+			capture_file = optarg;
+			break;
+		}
+		case '8':
+			pin_device_id = atoi(optarg);
+			break;
+		case '9': {
+			int suspend = atoi(optarg);
+			cras_client_set_suspend(client, suspend);
+			break;
+		}
+		case '!': {
+			play_short_sound = 1;
+			play_short_sound_periods = atoi(optarg);
+			break;
+		}
+		case ';': {
+			char *s;
+			int nch;
+			int size = 0;
+			float *coeff;
+
+			s = strtok(optarg, ":");
+			nch = atoi(s);
+			coeff = (float *)calloc(nch * nch,
+						sizeof(*coeff));
+			for (size = 0; size < nch * nch; size++) {
+				s = strtok(NULL, ",");
+				if (NULL == s)
+					break;
+				coeff[size] = atof(s);
+			}
+			cras_client_config_global_remix(client, nch, coeff);
+			free(coeff);
+			break;
+		}
+		case '<':
+		case '>': {
+			char *s;
+			int dev_index;
+			int node_index;
+
+			s = strtok(optarg, ":");
+			if (!s) {
+				show_usage();
+				return -EINVAL;
+			}
+			dev_index = atoi(s);
+
+			s = strtok(NULL, ":");
+			if (!s) {
+				show_usage();
+				return -EINVAL;
+			}
+			node_index = atoi(s);
+
+			s = strtok(NULL, ":");
+			if (!s && c == ';') {
+				show_usage();
+				return -EINVAL;
+			}
+
+			cras_node_id_t id = cras_make_node_id(dev_index,
+							      node_index);
+			if (c == '<')
+				cras_client_set_hotword_model(client, id, s);
+			else
+				print_hotword_models(client, id);
+			break;
+		}
+		case 'L': {
+			int log_level = atoi(optarg);
+
+			setlogmask(LOG_UPTO(log_level));
+			break;
+		}
+		case 'M':
+			mute_loop_test(client, atoi(optarg));
+			break;
+		case 'T':
+			stream_type = atoi(optarg);
+			break;
+		case 'E': {
+			char *s;
+
+			s = strtok(optarg, ",");
+			while (s) {
+				if (strcmp("aec", s) == 0)
+					effect_aec = 1;
+				else if (strcmp("ns", s) == 0)
+					effect_ns = 1;
+				else if (strcmp("agc", s) == 0)
+					effect_agc = 1;
+				else if (strcmp("vad", s) == 0)
+					effect_vad = 1;
+				else
+					printf("Unknown effect %s\n", s);
+				s = strtok(NULL, ",");
+			}
+			break;
+		}
+		case 'B':
+			stream_id = atoi(optarg);
+			break;
+		case 'C':
+			aecdump_file = optarg;
+			break;
+		case 'D':
+			cras_client_reload_aec_config(client);
+			break;
+		case 'F':
+			printf("AEC supported %d\n",
+			       !!cras_client_get_aec_supported(client));
+		default:
+			break;
+		}
+	}
+
+	duration_frames = duration_seconds * rate;
+	if (block_size == NOT_ASSIGNED)
+		block_size = get_block_size(PLAYBACK_BUFFERED_TIME_IN_US, rate);
+
+	if (capture_file != NULL) {
+		if (strcmp(capture_file, "-") == 0)
+			rc = run_file_io_stream(client, 1, CRAS_STREAM_INPUT,
+					block_size, stream_type, rate,
+					num_channels, stream_flags, 0, 0);
+		else
+			rc = run_capture(client, capture_file, block_size,
+					 stream_type, rate, num_channels,
+					 stream_flags, 0, 0);
+	} 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,
+					num_channels, stream_flags, 0, 0);
+		else
+			rc = run_playback(client, playback_file, block_size,
+					  stream_type, rate, num_channels);
+	} else if (loopback_file != NULL) {
+		rc = run_capture(client, loopback_file, block_size,
+				 stream_type, rate, num_channels,
+				 stream_flags, 1, post_dsp);
+	} else if (aecdump_file != NULL) {
+		run_aecdump(client, stream_id, 1);
+		sleep(duration_seconds);
+		run_aecdump(client, stream_id, 0);
+	}
+
+destroy_exit:
+	cras_client_destroy(client);
+	return rc;
+}
diff --git a/cras/src/tests/cras_tm_unittest.cc b/cras/src/tests/cras_tm_unittest.cc
index 3f5521e..a2cc80a 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 <gtest/gtest.h>
 #include <stdio.h>
+#include <gtest/gtest.h>
 
 extern "C" {
 #include "cras_tm.h"
@@ -12,27 +12,29 @@
 
 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++;
 }
 
@@ -45,7 +47,7 @@
 }
 
 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);
@@ -53,7 +55,7 @@
 
 TEST_F(TimerTestSuite, AddLongTimer) {
   struct timespec ts;
-  struct cras_timer* t;
+  struct cras_timer *t;
   int timers_active;
 
   time_now.tv_sec = 0;
@@ -81,7 +83,7 @@
 
 TEST_F(TimerTestSuite, AddRemoveTimer) {
   struct timespec ts;
-  struct cras_timer* t;
+  struct cras_timer *t;
   int timers_active;
 
   time_now.tv_sec = 0;
@@ -183,7 +185,7 @@
 /* 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;
 }
@@ -192,7 +194,7 @@
 
 }  //  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 b435825..f3e5b17 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 "dbus_test.h"
+#include <algorithm>
 
-#include <stdlib.h>
 #include <sys/select.h>
+#include <stdlib.h>
 #include <unistd.h>
 
-#include <algorithm>
+#include "dbus_test.h"
 
 namespace {
 
@@ -22,7 +22,9 @@
       send_reply_(false),
       send_error_(false),
       expect_serial_(false),
-      matched_(false) {}
+      matched_(false) {
+
+}
 
 DBusMatch& DBusMatch::WithString(std::string value) {
   Arg arg;
@@ -102,6 +104,7 @@
   return *this;
 }
 
+
 DBusMatch& DBusMatch::SendReply() {
   send_reply_ = true;
   expect_serial_ = true;
@@ -123,14 +126,18 @@
   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;
 
@@ -142,6 +149,7 @@
   return *this;
 }
 
+
 void DBusMatch::ExpectMethodCall(std::string path,
                                  std::string interface,
                                  std::string method) {
@@ -151,7 +159,8 @@
   member_ = method;
 }
 
-void DBusMatch::CreateSignal(DBusConnection* conn,
+
+void DBusMatch::CreateSignal(DBusConnection *conn,
                              std::string path,
                              std::string interface,
                              std::string signal_name) {
@@ -165,7 +174,7 @@
   matched_ = true;
 }
 
-void DBusMatch::CreateMessageCall(DBusConnection* conn,
+void DBusMatch::CreateMessageCall(DBusConnection *conn,
                                   std::string path,
                                   std::string interface,
                                   std::string method_name) {
@@ -179,18 +188,22 @@
   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;
@@ -203,8 +216,9 @@
   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;
@@ -212,20 +226,22 @@
 
   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);
@@ -251,21 +267,24 @@
     }
 
     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);
         }
       }
@@ -273,8 +292,9 @@
 
       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);
@@ -292,7 +312,7 @@
     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);
@@ -301,16 +321,17 @@
     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.
@@ -326,11 +347,12 @@
   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_);
@@ -342,8 +364,8 @@
   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.
@@ -362,10 +384,17 @@
   return matched_ && expected_serials_.size() == 0;
 }
 
-DBusTest::DBusTest()
-    : conn_(NULL), server_(NULL), server_conn_(NULL), dispatch_(false) {}
 
-DBusTest::~DBusTest() {}
+DBusTest::DBusTest()
+    : conn_(NULL),
+      server_(NULL),
+      server_conn_(NULL),
+      dispatch_(false) {
+}
+
+DBusTest::~DBusTest() {
+}
+
 
 DBusMatch& DBusTest::ExpectMethodCall(std::string path,
                                       std::string interface,
@@ -374,11 +403,12 @@
   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) {
@@ -386,7 +416,7 @@
   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;
 }
@@ -398,18 +428,19 @@
   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;
     }
@@ -419,7 +450,7 @@
       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);
 
@@ -427,10 +458,10 @@
     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_);
 
@@ -444,6 +475,7 @@
   pthread_mutex_unlock(&mutex_);
 }
 
+
 void DBusTest::SetUp() {
   dbus_threads_init_default();
 
@@ -452,17 +484,22 @@
   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
@@ -518,100 +555,109 @@
   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;
@@ -620,7 +666,7 @@
   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_);
@@ -632,12 +678,13 @@
   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();
 
@@ -655,9 +702,9 @@
   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;
@@ -677,12 +724,12 @@
   // 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;
@@ -710,10 +757,10 @@
 
   // 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 d266037..1a738b6 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,34 +187,31 @@
 
   // 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();
@@ -227,7 +224,7 @@
   bool as_property_dictionary_;
   std::vector<Arg> args_;
 
-  DBusConnection* conn_;
+  DBusConnection *conn_;
 
   bool send_reply_;
   std::vector<Arg> reply_args_;
@@ -250,21 +247,18 @@
  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
@@ -277,11 +271,11 @@
   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_;
@@ -289,37 +283,36 @@
 
   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 b74162b..fc6c353 100644
--- a/cras/src/tests/dev_io_stubs.cc
+++ b/cras/src/tests/dev_io_stubs.cc
@@ -2,19 +2,18 @@
 // 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 "cras_iodev.h"
+#include "dev_stream.h"
 #include "cras_rstream.h"
+#include "cras_iodev.h"
 #include "cras_shm.h"
 #include "cras_types.h"
-#include "dev_stream.h"
 #include "utlist.h"
 }
 
@@ -23,34 +22,20 @@
 ShmPtr create_shm(size_t cb_threshold) {
   uint32_t frame_bytes = 4;
   uint32_t used_size = cb_threshold * 2 * frame_bytes;
-
-  ShmPtr shm(reinterpret_cast<struct cras_audio_shm*>(
-                 calloc(1, sizeof(struct cras_audio_shm))),
-             destroy_shm);
-
-  shm->header = reinterpret_cast<struct cras_audio_shm_header*>(
-      calloc(1, sizeof(struct cras_audio_shm_header)));
-  shm->header->config.used_size = used_size;
-  shm->header->config.frame_bytes = frame_bytes;
-  shm->config = shm->header->config;
-
-  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;
+  uint32_t shm_size = sizeof(cras_audio_shm_area) + used_size * 2;
+  ShmPtr shm(reinterpret_cast<cras_audio_shm_area*>(calloc(1, shm_size)),
+              free);
+  shm->config.used_size = used_size;
+  shm->config.frame_bytes = frame_bytes;
+  shm->volume_scaler = 1.0;
   return shm;
 }
 
-void destroy_shm(struct cras_audio_shm* shm) {
-  free(shm->header);
-  free(shm->samples);
-  free(shm);
-}
-
 RstreamPtr create_rstream(cras_stream_id_t id,
                           CRAS_STREAM_DIRECTION direction,
                           size_t cb_threshold,
                           const cras_audio_format* format,
-                          cras_audio_shm* shm) {
+                          cras_audio_shm_area* shm) {
   RstreamPtr rstream(
       reinterpret_cast<cras_rstream*>(calloc(1, sizeof(cras_rstream))), free);
   rstream->stream_id = id;
@@ -58,20 +43,22 @@
   rstream->fd = RSTREAM_FAKE_POLL_FD;
   rstream->buffer_frames = cb_threshold * 2;
   rstream->cb_threshold = cb_threshold;
-  rstream->shm = shm;
+  rstream->shm.area = shm;
+  rstream->shm.config = shm->config;
   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;
-  dstream->is_running = true;
   return dstream;
 }
 
@@ -81,17 +68,18 @@
                         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)));
+  StreamPtr s(new Stream(std::move(shm),
+                         std::move(rstream),
+                         std::move(dstream)));
   return s;
 }
 
 void AddFakeDataToStream(Stream* stream, unsigned int frames) {
-  cras_shm_check_write_overrun(stream->rstream->shm);
-  cras_shm_buffer_written(stream->rstream->shm, frames);
+  cras_shm_check_write_overrun(&stream->rstream->shm);
+  cras_shm_buffer_written(&stream->rstream->shm, frames);
 }
 
 int delay_frames_stub(const struct cras_iodev* iodev) {
@@ -105,16 +93,12 @@
   return ionode;
 }
 
-int fake_flush_buffer(struct cras_iodev* iodev) {
-  return 0;
-}
-
 IodevPtr create_open_iodev(CRAS_STREAM_DIRECTION direction,
                            size_t cb_threshold,
                            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,8 +108,6 @@
   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;
 }
 
@@ -135,8 +117,8 @@
                         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)));
@@ -149,8 +131,6 @@
                                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 9db193c..4c54ff8 100644
--- a/cras/src/tests/dev_io_stubs.h
+++ b/cras/src/tests/dev_io_stubs.h
@@ -2,19 +2,18 @@
 // 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 "cras_iodev.h"
-#include "cras_rstream.h"
-#include "cras_shm.h"
-#include "cras_types.h"
 #include "dev_io.h"
 #include "dev_stream.h"
+#include "cras_rstream.h"
+#include "cras_iodev.h"
+#include "cras_shm.h"
+#include "cras_types.h"
 #include "utlist.h"
 }
 
@@ -28,17 +27,15 @@
 using IonodePtr = std::unique_ptr<cras_ionode, decltype(free)*>;
 using OpendevPtr = std::unique_ptr<open_dev, decltype(free)*>;
 using RstreamPtr = std::unique_ptr<cras_rstream, decltype(free)*>;
-
-void destroy_shm(struct cras_audio_shm* shm);
-using ShmPtr = std::unique_ptr<cras_audio_shm, decltype(destroy_shm)*>;
-ShmPtr create_shm(size_t cb_threshold);
+using ShmPtr = std::unique_ptr<cras_audio_shm_area, decltype(free)*>;
 
 // Holds the rstream and devstream pointers for an attached stream.
 struct Stream {
-  Stream(ShmPtr shm, RstreamPtr rstream, DevStreamPtr dstream)
-      : shm(std::move(shm)),
-        rstream(std::move(rstream)),
-        dstream(std::move(dstream)) {}
+  Stream(ShmPtr shm, RstreamPtr rstream, DevStreamPtr dstream) :
+    shm(std::move(shm)),
+    rstream(std::move(rstream)),
+    dstream(std::move(dstream)) {
+  }
   ShmPtr shm;
   RstreamPtr rstream;
   DevStreamPtr dstream;
@@ -47,19 +44,23 @@
 
 // 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;
 };
 using DevicePtr = std::unique_ptr<Device>;
 
+ShmPtr create_shm(size_t cb_threshold);
 RstreamPtr create_rstream(cras_stream_id_t id,
                           CRAS_STREAM_DIRECTION direction,
                           size_t cb_threshold,
                           const cras_audio_format* format,
-                          cras_audio_shm* shm);
+                          cras_audio_shm_area* shm);
 DevStreamPtr create_dev_stream(unsigned int dev_id, cras_rstream* rstream);
 StreamPtr create_stream(cras_stream_id_t id,
                         unsigned int dev_id,
diff --git a/cras/src/tests/dev_io_unittest.cc b/cras/src/tests/dev_io_unittest.cc
index a18dd48..c49fb45 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 <gtest/gtest.h>
+#include <memory>
 #include <stdint.h>
 #include <stdio.h>
 #include <time.h>
 
-#include <memory>
+#include <gtest/gtest.h>
 
 extern "C" {
-#include "cras_iodev.h"    // stubbed
-#include "cras_rstream.h"  // stubbed
+#include "dev_io.h" // tested
+#include "dev_stream.h" // tested
+#include "cras_rstream.h" // stubbed
+#include "cras_iodev.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;
@@ -23,32 +23,32 @@
 
 #include "dev_io_stubs.h"
 #include "iodev_stub.h"
-#include "metrics_stub.h"
 #include "rstream_stub.h"
 
-static float dev_stream_capture_software_gain_scaler_val;
-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)));
     iodev_stub_reset();
     rstream_stub_reset();
-    fill_audio_format(&format, 48000);
-    stream = create_stream(1, 1, CRAS_STREAM_INPUT, cb_threshold, &format);
   }
 
-  virtual void TearDown() { free(atlog); }
-
-  size_t cb_threshold = 480;
-  cras_audio_format format;
-  StreamPtr stream;
+  virtual void TearDown() {
+    free(atlog);
+  }
 };
 
 TEST_F(DevIoSuite, SendCapturedFails) {
+  const size_t cb_threshold = 480;
+
+  cras_audio_format format;
+  fill_audio_format(&format, 48000);
+
+  StreamPtr stream =
+      create_stream(1, 1, CRAS_STREAM_INPUT, cb_threshold, &format);
   // rstream's next callback is now and there is enough data to fill.
   struct timespec start;
   clock_gettime(CLOCK_MONOTONIC_RAW, &start);
@@ -56,8 +56,8 @@
   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);
 
@@ -67,209 +67,46 @@
   EXPECT_EQ(-3, dev_io_send_captured_samples(dev_list));
 }
 
-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);
-
-  dev->dev->state = CRAS_IODEV_STATE_NORMAL_RUN;
-  dev->dev->software_gain_scaler = 0.99f;
-  iodev_stub_frames_queued(dev->dev.get(), 20, ts);
-  DL_APPEND(dev_list, dev->odev.get());
-  add_stream_to_dev(dev->dev, stream);
-
-  /* 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);
-  dev_io_capture(&dev_list);
-  EXPECT_EQ(1.0f, dev_stream_capture_software_gain_scaler_val);
-
-  stream->rstream->apm_list = 0x0;
-  dev_io_capture(&dev_list);
-  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 cras_server_metrics_highest_hw_level(unsigned hw_level,
+		enum CRAS_STREAM_DIRECTION direction)
+{
   return 0;
 }
 
-int input_data_put_for_stream(struct input_data* data,
-                              struct cras_rstream* stream,
-                              struct buffer_share* offsets,
-                              unsigned int frames) {
+int cras_server_metrics_longest_fetch_delay(unsigned delay_msec)
+{
   return 0;
 }
 
-int cras_audio_thread_event_drop_samples() {
+int cras_server_metrics_num_underruns(unsigned num_underruns)
+{
   return 0;
 }
 
-int dev_stream_attached_devs(const struct dev_stream* dev_stream) {
+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;
 }
-void dev_stream_update_frames(const struct dev_stream* dev_stream) {}
-int dev_stream_playback_frames(const struct dev_stream* dev_stream) {
+
+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_is_pending_reply(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) {
-  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) {
-  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) {
-  return 0;
-}
-int dev_stream_flush_old_audio_messages(struct dev_stream* dev_stream) {
-  return 0;
-}
-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) {
-  return 0;
-}
-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) {
-  return dev_stream_capture_avail_ret;
-}
-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) {
-  return 0;
+struct cras_audio_format *cras_rstream_post_processing_format(
+    const struct cras_rstream *stream, void *dev_ptr)
+{
+  return NULL;
 }
 }  // extern "C"
 
diff --git a/cras/src/tests/dev_stream_unittest.cc b/cras/src/tests/dev_stream_unittest.cc
index 39c16e4..450f5c7 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 <gtest/gtest.h>
 #include <stdio.h>
+#include <gtest/gtest.h>
 
 extern "C" {
 #include "audio_thread_log.h"
@@ -18,13 +18,11 @@
 namespace {
 
 extern "C" {
-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);
+struct audio_thread_event_log *atlog;
+unsigned int max_frames_for_conversion(
+    unsigned int stream_frames,
+    unsigned int stream_rate,
+    unsigned int device_rate);
 };
 
 static struct timespec clock_gettime_retspec;
@@ -32,46 +30,46 @@
 
 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;
@@ -79,15 +77,15 @@
 };
 
 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;
@@ -102,147 +100,124 @@
 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;
 
-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;
 
-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);
 
-    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_.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;
 
-    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_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(&copy_area_call, 0xff, sizeof(copy_area_call));
+      memset(&conv_frames_call, 0xff, sizeof(conv_frames_call));
 
-    memset(&copy_area_call, 0xff, sizeof(copy_area_call));
-    memset(&conv_frames_call, 0xff, sizeof(conv_frames_call));
+      atlog = audio_thread_event_log_init();
 
-    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;
 
-    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;
 
-    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.area->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);
+    }
 
-    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.area);
+      audio_thread_event_log_deinit(atlog);
+    }
 
-  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) {
+      int16_t *buf;
 
-  void SetupShm(struct cras_audio_shm** shm_out) {
-    int16_t* buf;
-    struct cras_audio_shm* shm;
-    uint32_t used_size;
+      shm->area = static_cast<struct cras_audio_shm_area *>(
+          calloc(1, kBufferFrames * 4 + sizeof(cras_audio_shm_area)));
+      cras_shm_set_frame_bytes(shm, 4);
+      cras_shm_set_used_size(shm,
+                             kBufferFrames * cras_shm_frame_bytes(shm));
 
-    shm = static_cast<struct cras_audio_shm*>(
-        calloc(1, sizeof(struct cras_audio_shm)));
+      buf = (int16_t *)shm->area->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->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);
+    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;
 
-    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);
+      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;
 
-    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);
-  }
+      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_;
 };
@@ -257,6 +232,7 @@
   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) {
@@ -268,12 +244,14 @@
   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);
@@ -301,12 +279,14 @@
 
   // 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|
@@ -327,44 +307,46 @@
 }
 
 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);
@@ -372,14 +354,14 @@
 }
 
 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.
@@ -389,15 +371,15 @@
 }
 
 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.
@@ -407,55 +389,57 @@
 }
 
 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.
@@ -465,15 +449,15 @@
 }
 
 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.
@@ -483,15 +467,15 @@
 }
 
 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.
@@ -504,19 +488,19 @@
 }
 
 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);
@@ -530,15 +514,16 @@
 }
 
 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);
@@ -558,16 +543,17 @@
 }
 
 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);
@@ -652,16 +638,16 @@
   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);
@@ -669,11 +655,11 @@
 }
 
 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,8 +671,33 @@
   dev_stream_destroy(dev_stream);
 }
 
+TEST_F(CreateSuite, StreamCanFetch) {
+  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);
+
+  /* Verify stream cannot fetch when it's still pending. */
+  cras_rstream_is_pending_reply_ret = 1;
+  EXPECT_EQ(0, dev_stream_can_fetch(dev_stream));
+
+  /* Verify stream can fetch when buffer available. */
+  cras_rstream_is_pending_reply_ret = 0;
+  rstream_.shm.area->write_offset[0] = 0;
+  rstream_.shm.area->write_offset[1] = 0;
+  EXPECT_EQ(1, dev_stream_can_fetch(dev_stream));
+
+  /* Verify stream cannot fetch when there's still buffer. */
+  cras_rstream_is_pending_reply_ret = 0;
+  rstream_.shm.area->write_offset[0] = kBufferFrames;
+  rstream_.shm.area->write_offset[1] = kBufferFrames;
+  EXPECT_EQ(0, dev_stream_can_fetch(dev_stream));
+  dev_stream_destroy(dev_stream);
+}
+
 TEST_F(CreateSuite, StreamCanSend) {
-  struct dev_stream* dev_stream;
+  struct dev_stream *dev_stream;
   unsigned int dev_id = 9;
   int written_frames;
   int rc;
@@ -694,7 +705,7 @@
 
   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;
@@ -706,7 +717,6 @@
   clock_gettime_retspec.tv_nsec = 0;
   rc = dev_stream_capture_update_rstream(dev_stream);
   EXPECT_EQ(0, cras_rstream_audio_ready_called);
-  EXPECT_EQ(0, cras_server_metrics_missed_cb_event_called);
   EXPECT_EQ(0, rc);
 
   // Case 2: Not enough samples. Time is late enough.
@@ -719,7 +729,6 @@
   // Stream still can not send samples to client.
   rc = dev_stream_capture_update_rstream(dev_stream);
   EXPECT_EQ(0, cras_rstream_audio_ready_called);
-  EXPECT_EQ(0, cras_server_metrics_missed_cb_event_called);
   EXPECT_EQ(0, rc);
 
   // Case 3: Enough samples. Time is not late enough.
@@ -730,11 +739,10 @@
   clock_gettime_retspec.tv_nsec = 0;
   // Enough samples are written.
   written_frames = rstream_.cb_threshold + 10;
-  cras_shm_buffer_written(rstream_.shm, written_frames);
+  cras_shm_buffer_written(&rstream_.shm, written_frames);
   // Stream still can not send samples to client.
   rc = dev_stream_capture_update_rstream(dev_stream);
   EXPECT_EQ(0, cras_rstream_audio_ready_called);
-  EXPECT_EQ(0, cras_server_metrics_missed_cb_event_called);
   EXPECT_EQ(0, rc);
 
   // Case 4: Enough samples. Time is late enough.
@@ -744,13 +752,13 @@
   rc = dev_stream_capture_update_rstream(dev_stream);
   EXPECT_EQ(1, cras_rstream_audio_ready_called);
   EXPECT_EQ(rstream_.cb_threshold, cras_rstream_audio_ready_count);
-  EXPECT_EQ(0, cras_server_metrics_missed_cb_event_called);
   EXPECT_EQ(0, rc);
 
   // 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);
 
@@ -768,13 +776,13 @@
   rc = dev_stream_capture_update_rstream(dev_stream);
   EXPECT_EQ(1, cras_rstream_audio_ready_called);
   EXPECT_EQ(rstream_.cb_threshold, cras_rstream_audio_ready_count);
-  EXPECT_EQ(1, cras_server_metrics_missed_cb_event_called);
   EXPECT_EQ(0, rc);
 
   // 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);
 
@@ -782,7 +790,7 @@
 }
 
 TEST_F(CreateSuite, StreamCanSendBulkAudio) {
-  struct dev_stream* dev_stream;
+  struct dev_stream *dev_stream;
   unsigned int dev_id = 9;
   int written_frames;
   int rc;
@@ -791,7 +799,7 @@
   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;
@@ -825,7 +833,7 @@
   clock_gettime_retspec.tv_nsec = 0;
   // Enough samples are written.
   written_frames = rstream_.cb_threshold + 10;
-  cras_shm_buffer_written(rstream_.shm, written_frames);
+  cras_shm_buffer_written(&rstream_.shm, written_frames);
   // Bulk audio stream can send all written samples to client.
   rc = dev_stream_capture_update_rstream(dev_stream);
   EXPECT_EQ(1, cras_rstream_audio_ready_called);
@@ -851,7 +859,8 @@
   // 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);
 
@@ -859,17 +868,17 @@
 }
 
 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;
 
   // Check first trigger callback called.
-  cras_shm_buffer_written(rstream_.shm, rstream_.cb_threshold);
+  cras_shm_buffer_written(&rstream_.shm, rstream_.cb_threshold);
   clock_gettime_retspec.tv_sec = 1;
   clock_gettime_retspec.tv_nsec = 0;
   dev_stream_capture_update_rstream(dev_stream);
@@ -877,7 +886,7 @@
   EXPECT_EQ(1, dev_stream->stream->triggered);
 
   // No future callback will be called for TRIGGER_ONLY streams.
-  cras_shm_buffer_written(rstream_.shm, rstream_.cb_threshold);
+  cras_shm_buffer_written(&rstream_.shm, rstream_.cb_threshold);
   clock_gettime_retspec.tv_sec = 2;
   clock_gettime_retspec.tv_nsec = 0;
   dev_stream_capture_update_rstream(dev_stream);
@@ -886,7 +895,7 @@
 }
 
 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;
@@ -896,7 +905,7 @@
 
   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;
@@ -904,10 +913,11 @@
 
   // Assume there are enough samples for stream.
   written_frames = rstream_.cb_threshold + 10;
-  cras_shm_buffer_written(rstream_.shm, written_frames);
+  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);
@@ -917,7 +927,7 @@
 }
 
 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;
@@ -929,16 +939,16 @@
   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;
-  cras_shm_buffer_written(rstream_.shm, written_frames);
+  cras_shm_buffer_written(&rstream_.shm, written_frames);
 
   // Compute wake up time for device level to reach enough samples
   // for one cb_threshold:
@@ -952,8 +962,8 @@
   // 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);
@@ -967,8 +977,9 @@
   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.
@@ -979,51 +990,15 @@
   // 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);
   dev_stream_destroy(dev_stream);
 }
 
-TEST_F(CreateSuite, UpdateNextWakeTime) {
-  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);
-
-  // Case 1: The new next_cb_ts is greater than now. Do not need to reschedule.
-  rstream_.next_cb_ts.tv_sec = 2;
-  rstream_.next_cb_ts.tv_nsec = 0;
-  clock_gettime_retspec.tv_sec = 2;
-  clock_gettime_retspec.tv_nsec = 500;
-  expected_next_cb_ts = rstream_.next_cb_ts;
-
-  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);
-  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);
-
-  // Case 2: The new next_cb_ts is less than now. Need to reset schedule.
-  rstream_.next_cb_ts.tv_sec = 2;
-  rstream_.next_cb_ts.tv_nsec = 0;
-  clock_gettime_retspec.tv_sec = 3;
-  clock_gettime_retspec.tv_nsec = 0;
-  expected_next_cb_ts = clock_gettime_retspec;
-
-  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);
-  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);
-}
-
 //  Test set_playback_timestamp.
 TEST(DevStreamTimimg, SetPlaybackTimeStampSimple) {
   struct cras_timespec ts;
@@ -1093,66 +1068,72 @@
 }
 
 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++;
@@ -1160,22 +1141,24 @@
   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;
@@ -1183,62 +1166,65 @@
   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;
@@ -1250,54 +1236,58 @@
   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;
 }
 
-int cras_server_metrics_missed_cb_event(const struct cras_rstream* stream) {
-  cras_server_metrics_missed_cb_event_called++;
-  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->tv_sec = clock_gettime_retspec.tv_sec;
   tp->tv_nsec = clock_gettime_retspec.tv_nsec;
   return 0;
@@ -1307,7 +1297,7 @@
 
 }  //  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 2c1edf0..812ac4c 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 <gtest/gtest.h>
 #include <stdio.h>
+#include <gtest/gtest.h>
 
 extern "C" {
 #include "cras_device_blacklist.h"
@@ -30,7 +30,7 @@
 
 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 @@
   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 @@
       "[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 @@
 
 }  //  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 31c2e8c..cc9e0d1 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 <gtest/gtest.h>
 #include <stdio.h>
+#include <gtest/gtest.h>
 
 extern "C" {
 #include "cras_device_monitor.c"
@@ -12,23 +12,22 @@
 }
 
 static enum CRAS_MAIN_MESSAGE_TYPE type_set;
-static struct cras_device_monitor_message* sent_msg;
-static int resume_dev_called;
-unsigned int resume_dev_idx;
-static int suspend_dev_called;
-unsigned int suspend_dev_idx;
+static struct cras_device_monitor_message *sent_msg;
+static int enable_dev_called;
+static cras_iodev *enable_dev;
+static int disable_dev_called;
+static cras_iodev *disable_dev;
 static int set_mute_called;
-unsigned int mute_dev_idx;
-unsigned int fake_dev_idx = 123;
+static cras_iodev *mute_dev;
 
 void ResetStubData() {
   type_set = (enum CRAS_MAIN_MESSAGE_TYPE)0;
-  resume_dev_called = 0;
-  resume_dev_idx = 0;
-  suspend_dev_called = 0;
-  suspend_dev_idx = 0;
+  enable_dev_called = 0;
+  enable_dev = NULL;
+  disable_dev_called = 0;
+  disable_dev = NULL;
   set_mute_called = 0;
-  mute_dev_idx = 0;
+  mute_dev = NULL;
 }
 
 namespace {
@@ -42,107 +41,112 @@
 }
 
 TEST(DeviceMonitorTestSuite, ResetDevice) {
+  struct cras_iodev dev;
   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);
+  cras_device_monitor_reset_device(&dev);
 
   EXPECT_EQ(sent_msg->header.type, CRAS_MAIN_MONITOR_DEVICE);
   EXPECT_EQ(sent_msg->header.length, sizeof(*sent_msg));
   EXPECT_EQ(sent_msg->message_type, RESET_DEVICE);
-  EXPECT_EQ(sent_msg->dev_idx, fake_dev_idx);
+  EXPECT_EQ(sent_msg->iodev, &dev);
 
   free(sent_msg);
 }
 
 TEST(DeviceMonitorTestSuite, HandleResetDevice) {
+  struct cras_iodev dev;
   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();
 
   // Filled msg with message content for resetting device.
-  init_device_msg(&msg, RESET_DEVICE, fake_dev_idx);
+  init_device_msg(&msg, RESET_DEVICE, &dev);
   // Assume the pipe works fine and main message handler receives the same
   // message.
   handle_device_message(main_message, NULL);
 
   // Verify that disable/enable functions are called with correct device.
-  EXPECT_EQ(resume_dev_called, 1);
-  EXPECT_EQ(resume_dev_idx, fake_dev_idx);
-  EXPECT_EQ(suspend_dev_called, 1);
-  EXPECT_EQ(suspend_dev_idx, fake_dev_idx);
+  EXPECT_EQ(enable_dev_called, 1);
+  EXPECT_EQ(enable_dev, &dev);
+  EXPECT_EQ(disable_dev_called, 1);
+  EXPECT_EQ(disable_dev, &dev);
 }
 
 TEST(DeviceMonitorTestSuite, MuteDevice) {
+  struct cras_iodev dev;
   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);
+  cras_device_monitor_set_device_mute_state(&dev);
 
   EXPECT_EQ(sent_msg->header.type, CRAS_MAIN_MONITOR_DEVICE);
   EXPECT_EQ(sent_msg->header.length, sizeof(*sent_msg));
   EXPECT_EQ(sent_msg->message_type, SET_MUTE_STATE);
-  EXPECT_EQ(sent_msg->dev_idx, fake_dev_idx);
+  EXPECT_EQ(sent_msg->iodev, &dev);
 
   free(sent_msg);
 }
 
 TEST(DeviceMonitorTestSuite, HandleMuteDevice) {
+  struct cras_iodev dev;
   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();
 
   // Filled msg with message content for device mute/unmute.
-  init_device_msg(&msg, SET_MUTE_STATE, fake_dev_idx);
+  init_device_msg(&msg, SET_MUTE_STATE, &dev);
   // Assume the pipe works fine and main message handler receives the same
   // message.
   handle_device_message(main_message, NULL);
 
   // Verify that cras_iodev_set_mute is called with correct device.
   EXPECT_EQ(set_mute_called, 1);
-  EXPECT_EQ(mute_dev_idx, fake_dev_idx);
+  EXPECT_EQ(mute_dev, &dev);
 }
 
 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;
 };
 
-void cras_iodev_list_resume_dev(unsigned int dev_idx) {
-  resume_dev_called++;
-  resume_dev_idx = dev_idx;
+void cras_iodev_list_enable_dev(struct cras_iodev *dev) {
+  enable_dev_called++;
+  enable_dev = dev;
 }
 
-void cras_iodev_list_suspend_dev(unsigned int dev_idx) {
-  suspend_dev_called++;
-  suspend_dev_idx = dev_idx;
+void cras_iodev_list_disable_dev(struct cras_iodev *dev, bool force) {
+  disable_dev_called++;
+  disable_dev = dev;
 }
 
-void cras_iodev_list_set_dev_mute(unsigned int dev_idx) {
+int cras_iodev_set_mute(struct cras_iodev *dev) {
   set_mute_called++;
-  mute_dev_idx = dev_idx;
+  mute_dev = dev;
+  return 0;
 }
 
 }  // 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 82c7957..0957795 100644
--- a/cras/src/tests/dsp_core_unittest.cc
+++ b/cras/src/tests/dsp_core_unittest.cc
@@ -4,7 +4,6 @@
 
 #include <gtest/gtest.h>
 #include <math.h>
-
 #include "crossover.h"
 #include "crossover2.h"
 #include "drc.h"
@@ -15,18 +14,17 @@
 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++) {
@@ -43,66 +41,49 @@
   /* 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};
+    -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 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 */
@@ -142,8 +123,7 @@
   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);
@@ -161,23 +141,23 @@
 }
 
 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 */
@@ -238,9 +218,9 @@
   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);
@@ -283,12 +263,12 @@
   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);
@@ -354,11 +334,11 @@
   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);
@@ -427,7 +407,7 @@
 
 }  //  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 ee18790..b7f488d 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 @@
 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 @@
   }
 
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
 
   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 @@
   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 @@
   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,6 +175,7 @@
 }
 
 TEST_F(DspIniTestSuite, TwoChannelWithSwap) {
+
   /*
    *  Stated in ini:
    *
@@ -186,7 +187,7 @@
    *
    */
 
-  const char* content =
+  const char *content =
       "[M0]\n"
       "library=builtin\n"
       "label=source\n"
@@ -210,33 +211,33 @@
   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
    * ------------------------------------------------------------
@@ -260,12 +261,12 @@
   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);
@@ -302,7 +303,7 @@
 
 }  //  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 b1f4c4e..2202990 100644
--- a/cras/src/tests/dsp_unittest.cc
+++ b/cras/src/tests/dsp_unittest.cc
@@ -12,7 +12,8 @@
 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;
 }
 }
@@ -20,7 +21,7 @@
 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");
   }
@@ -38,11 +39,11 @@
   }
 
   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"
@@ -60,12 +61,12 @@
 
   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);
@@ -76,7 +77,7 @@
   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);
 
@@ -96,36 +97,38 @@
   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;
@@ -138,18 +141,22 @@
 
 }  //  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 7bd1421..af19046 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 "dumper.h"
-
-#include <gtest/gtest.h>
 #include <syslog.h>
+#include <gtest/gtest.h>
+
+#include "dumper.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, 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 @@
 
 }  //  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 6b059af..291db71 100644
--- a/cras/src/tests/edid_utils_unittest.cc
+++ b/cras/src/tests/edid_utils_unittest.cc
@@ -2,35 +2,34 @@
 // 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];
 };
@@ -41,7 +40,7 @@
 
 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));
@@ -53,184 +52,256 @@
 // 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_edids[] = {
-    test_edid1,
-    test_edid2,
-    test_edid3,
-    test_edid4,
+static const uint8_t *test_no_aud_edids[] = {
+  test_no_aud_edid1,
+  test_no_aud_edid2,
+  test_no_aud_edid3,
 };
 
-static const char* monitor_names[] = {
-    "HDMI LLC",
-    "SAMSUNG",
-    "TX-SR605",
-    "M230A",
+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",
 };
 
 TEST_F(EDIDTestSuite, NoAudEDID) {
@@ -268,7 +339,7 @@
 
 }  //  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 00ede69..e15af00 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
deleted file mode 100644
index 585fba3..0000000
--- a/cras/src/tests/empty_iodev_unittest.cc
+++ /dev/null
@@ -1,100 +0,0 @@
-/* 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>
-
-extern "C" {
-#include "cras_audio_area.h"
-#include "cras_empty_iodev.h"
-#include "cras_iodev.h"
-}
-
-static struct timespec clock_gettime_retspec;
-static struct cras_audio_format fake_format;
-static cras_audio_area dummy_audio_area;
-
-namespace {
-
-TEST(EmptyIodev, GetInputBuffer) {
-  struct cras_iodev* iodev;
-  struct timespec ts;
-  cras_audio_area* area;
-  unsigned nframes;
-
-  iodev = empty_iodev_create(CRAS_STREAM_INPUT, CRAS_NODE_TYPE_FALLBACK_NORMAL);
-
-  clock_gettime_retspec.tv_sec = 0;
-  clock_gettime_retspec.tv_nsec = 10000000;
-  fake_format.frame_rate = 48000;
-  iodev->format = &fake_format;
-  iodev->configure_dev(iodev);
-
-  clock_gettime_retspec.tv_nsec = 20000000;
-  nframes = iodev->frames_queued(iodev, &ts);
-  ASSERT_EQ(480, nframes);
-
-  /* If client takes too long to get input data, number of frames
-   * returned shouldn't exceeds device's own buffer size. */
-  nframes = 5000;
-  clock_gettime_retspec.tv_sec = 1;
-  iodev->get_buffer(iodev, &area, &nframes);
-  ASSERT_EQ(4096, nframes);
-
-  iodev->close_dev(iodev);
-  empty_iodev_destroy(iodev);
-}
-
-}  // namespace
-
-extern "C" {
-
-void cras_iodev_free_format(struct cras_iodev* iodev) {}
-
-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) {
-  iodev->area = &dummy_audio_area;
-}
-
-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) {}
-
-int cras_iodev_list_rm_input(struct cras_iodev* input) {
-  return 0;
-}
-
-int cras_iodev_list_rm_output(struct cras_iodev* output) {
-  return 0;
-}
-
-void cras_iodev_free_resources(struct cras_iodev* iodev) {}
-
-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) {
-  iodev->active_node = node;
-}
-
-//  From librt.
-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"
-
-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 dbfdb46..2fec2df 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, 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, 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, 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,10 +173,9 @@
   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);
@@ -186,10 +185,10 @@
   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);
@@ -200,7 +199,7 @@
 }
 
 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;
 
@@ -242,7 +241,7 @@
 
 }  //  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 87cd53c..6bd76f3 100644
--- a/cras/src/tests/file_wait_unittest.cc
+++ b/cras/src/tests/file_wait_unittest.cc
@@ -2,18 +2,17 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include <fcntl.h>
 #include <gtest/gtest.h>
+#include <fcntl.h>
 #include <stdlib.h>
-
 #include <string>
 
-#include "cras_file_wait.h"
 #include "cras_util.h"
+#include "cras_file_wait.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 {
@@ -39,17 +38,18 @@
 };
 
 // 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 @@
   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 @@
 // 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,20 +112,21 @@
 
   // 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));
 
@@ -134,7 +135,7 @@
   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);
@@ -145,9 +146,10 @@
 
   // 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);
@@ -249,7 +251,7 @@
   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.
@@ -271,7 +273,7 @@
 
 }  //  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 eee523b..20d392e 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 "float_buffer.h"
-
 #include <gtest/gtest.h>
 
+#include "float_buffer.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 @@
   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
deleted file mode 100644
index d58d618..0000000
--- a/cras/src/tests/fmt_conv_ops_unittest.cc
+++ /dev/null
@@ -1,684 +0,0 @@
-// 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 <limits.h>
-#include <sys/param.h>
-
-#include <memory>
-
-extern "C" {
-#include "cras_fmt_conv_ops.h"
-#include "cras_types.h"
-}
-
-static uint8_t* AllocateRandomBytes(size_t size) {
-  uint8_t* buf = (uint8_t*)malloc(size);
-  while (size--)
-    buf[size] = rand() & 0xff;
-  return buf;
-}
-
-using U8Ptr = std::unique_ptr<uint8_t[], decltype(free)*>;
-using S16LEPtr = std::unique_ptr<int16_t[], decltype(free)*>;
-using S243LEPtr = std::unique_ptr<uint8_t[], decltype(free)*>;
-using S24LEPtr = std::unique_ptr<int32_t[], decltype(free)*>;
-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));
-  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);
-  return ret;
-}
-
-static S243LEPtr CreateS243LE(size_t size) {
-  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);
-  return ret;
-}
-
-static S32LEPtr CreateS32LE(size_t size) {
-  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));
-  while (size--)
-    buf[size] = (float)(rand() & 0xff) / 0xfff;
-  FloatPtr ret(buf, free);
-  return ret;
-}
-
-static int32_t ToS243LE(const uint8_t* in) {
-  int32_t ret = 0;
-
-  ret |= in[2];
-  ret <<= 8;
-  ret |= in[1];
-  ret <<= 8;
-  ret |= in[0];
-  return ret;
-}
-
-static int16_t S16AddAndClip(int16_t a, int16_t b) {
-  int32_t sum;
-
-  sum = (int32_t)a + (int32_t)b;
-  sum = MAX(sum, SHRT_MIN);
-  sum = MIN(sum, SHRT_MAX);
-  return sum;
-}
-
-// Test U8 to S16_LE conversion.
-TEST(FormatConverterOpsTest, ConvertU8ToS16LE) {
-  const size_t frames = 4096;
-  const size_t in_ch = 2;
-  const size_t out_ch = 2;
-
-  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());
-
-  for (size_t i = 0; i < frames * in_ch; ++i) {
-    EXPECT_EQ((int16_t)((uint16_t)((int16_t)(int8_t)src[i] - 0x80) << 8),
-              dst[i]);
-  }
-}
-
-// Test S24_3LE to S16_LE conversion.
-TEST(FormatConverterOpsTest, ConvertS243LEToS16LE) {
-  const size_t frames = 4096;
-  const size_t in_ch = 2;
-  const size_t out_ch = 2;
-
-  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());
-
-  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;
-  }
-}
-
-// Test S24_LE to S16_LE conversion.
-TEST(FormatConverterOpsTest, ConvertS24LEToS16LE) {
-  const size_t frames = 4096;
-  const size_t in_ch = 2;
-  const size_t out_ch = 2;
-
-  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());
-
-  for (size_t i = 0; i < frames * in_ch; ++i) {
-    EXPECT_EQ((int16_t)(src[i] >> 8), dst[i]);
-  }
-}
-
-// Test S32_LE to S16_LE conversion.
-TEST(FormatConverterOpsTest, ConvertS32LEToS16LE) {
-  const size_t frames = 4096;
-  const size_t in_ch = 2;
-  const size_t out_ch = 2;
-
-  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());
-
-  for (size_t i = 0; i < frames * in_ch; ++i) {
-    EXPECT_EQ((int16_t)(src[i] >> 16), dst[i]);
-  }
-}
-
-// Test S16_LE to U8 conversion.
-TEST(FormatConverterOpsTest, ConvertS16LEToU8) {
-  const size_t frames = 4096;
-  const size_t in_ch = 2;
-  const size_t out_ch = 2;
-
-  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());
-
-  for (size_t i = 0; i < frames * in_ch; ++i) {
-    EXPECT_EQ((uint8_t)(int8_t)((src[i] >> 8) + 0x80), dst[i]);
-  }
-}
-
-// Test S16_LE to S24_3LE conversion.
-TEST(FormatConverterOpsTest, ConvertS16LEToS243LE) {
-  const size_t frames = 4096;
-  const size_t in_ch = 2;
-  const size_t out_ch = 2;
-
-  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());
-
-  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);
-    p += 3;
-  }
-}
-
-// Test S16_LE to S24_LE conversion.
-TEST(FormatConverterOpsTest, ConvertS16LEToS24LE) {
-  const size_t frames = 4096;
-  const size_t in_ch = 2;
-  const size_t out_ch = 2;
-
-  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());
-
-  for (size_t i = 0; i < frames * in_ch; ++i) {
-    EXPECT_EQ((int32_t)((uint32_t)src[i] << 8) & 0x00ffffff,
-              dst[i] & 0x00ffffff);
-  }
-}
-
-// Test S16_LE to S32_LE conversion.
-TEST(FormatConverterOpsTest, ConvertS16LEToS32LE) {
-  const size_t frames = 4096;
-  const size_t in_ch = 2;
-  const size_t out_ch = 2;
-
-  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());
-
-  for (size_t i = 0; i < frames * in_ch; ++i) {
-    EXPECT_EQ((int32_t)((uint32_t)src[i] << 16) & 0xffffff00,
-              dst[i] & 0xffffff00);
-  }
-}
-
-// Test Mono to Stereo conversion.  S16_LE.
-TEST(FormatConverterOpsTest, MonoToStereoS16LE) {
-  const size_t frames = 4096;
-  const size_t in_ch = 1;
-  const size_t out_ch = 2;
-
-  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());
-  EXPECT_EQ(ret, frames);
-
-  for (size_t i = 0; i < frames; ++i) {
-    EXPECT_EQ(src[i], dst[i * 2 + 0]);
-    EXPECT_EQ(src[i], dst[i * 2 + 1]);
-  }
-}
-
-// Test Stereo to Mono conversion.  S16_LE.
-TEST(FormatConverterOpsTest, StereoToMonoS16LE) {
-  const size_t frames = 4096;
-  const size_t in_ch = 2;
-  const size_t out_ch = 1;
-
-  S16LEPtr src = CreateS16LE(frames * in_ch);
-  S16LEPtr dst = CreateS16LE(frames * out_ch);
-  for (size_t i = 0; i < frames; ++i) {
-    src[i * 2 + 0] = 13450;
-    src[i * 2 + 1] = -13449;
-  }
-
-  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) {
-    EXPECT_EQ(1, dst[i]);
-  }
-}
-
-// Test Stereo to Mono conversion.  S16_LE, Overflow.
-TEST(FormatConverterOpsTest, StereoToMonoS16LEOverflow) {
-  const size_t frames = 4096;
-  const size_t in_ch = 2;
-  const size_t out_ch = 1;
-
-  S16LEPtr src = CreateS16LE(frames * in_ch);
-  S16LEPtr dst = CreateS16LE(frames * out_ch);
-  for (size_t i = 0; i < frames; ++i) {
-    src[i * 2 + 0] = 0x7fff;
-    src[i * 2 + 1] = 1;
-  }
-
-  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) {
-    EXPECT_EQ(0x7fff, dst[i]);
-  }
-}
-
-// Test Stereo to Mono conversion.  S16_LE, Underflow.
-TEST(FormatConverterOpsTest, StereoToMonoS16LEUnderflow) {
-  const size_t frames = 4096;
-  const size_t in_ch = 2;
-  const size_t out_ch = 1;
-
-  S16LEPtr src = CreateS16LE(frames * in_ch);
-  S16LEPtr dst = CreateS16LE(frames * out_ch);
-  for (size_t i = 0; i < frames; ++i) {
-    src[i * 2 + 0] = -0x8000;
-    src[i * 2 + 1] = -0x1;
-  }
-
-  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) {
-    EXPECT_EQ(-0x8000, dst[i]);
-  }
-}
-
-// Test Mono to 5.1 conversion.  S16_LE, Center.
-TEST(FormatConverterOpsTest, MonoTo51S16LECenter) {
-  const size_t frames = 4096;
-  const size_t in_ch = 1;
-  const size_t out_ch = 6;
-  const size_t left = 0;
-  const size_t right = 1;
-  const size_t center = 4;
-
-  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());
-  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(src[i], dst[i * 6 + k]);
-      else
-        EXPECT_EQ(0, dst[i * 6 + k]);
-    }
-  }
-}
-
-// Test Mono to 5.1 conversion.  S16_LE, LeftRight.
-TEST(FormatConverterOpsTest, MonoTo51S16LELeftRight) {
-  const size_t frames = 4096;
-  const size_t in_ch = 1;
-  const size_t out_ch = 6;
-  const size_t left = 0;
-  const size_t right = 1;
-  const size_t center = -1;
-
-  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());
-  EXPECT_EQ(ret, frames);
-
-  for (size_t i = 0; i < frames; ++i) {
-    for (size_t k = 0; k < 6; ++k) {
-      if (k == left)
-        EXPECT_EQ(src[i] / 2, dst[i * 6 + k]);
-      else if (k == right)
-        EXPECT_EQ(src[i] / 2, dst[i * 6 + k]);
-      else
-        EXPECT_EQ(0, dst[i * 6 + k]);
-    }
-  }
-}
-
-// Test Mono to 5.1 conversion.  S16_LE, Unknown.
-TEST(FormatConverterOpsTest, MonoTo51S16LEUnknown) {
-  const size_t frames = 4096;
-  const size_t in_ch = 1;
-  const size_t out_ch = 6;
-  const size_t left = -1;
-  const size_t right = -1;
-  const size_t center = -1;
-
-  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());
-  EXPECT_EQ(ret, frames);
-
-  for (size_t i = 0; i < frames; ++i) {
-    for (size_t k = 0; k < 6; ++k) {
-      if (k == 0)
-        EXPECT_EQ(src[i], dst[i * 6 + k]);
-      else
-        EXPECT_EQ(0, dst[6 * i + k]);
-    }
-  }
-}
-
-// Test Stereo to 5.1 conversion.  S16_LE, Center.
-TEST(FormatConverterOpsTest, StereoTo51S16LECenter) {
-  const size_t frames = 4096;
-  const size_t in_ch = 2;
-  const size_t out_ch = 6;
-  const size_t left = -1;
-  const size_t right = 1;
-  const size_t center = 4;
-
-  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());
-  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]);
-      else
-        EXPECT_EQ(0, dst[i * 6 + k]);
-    }
-  }
-}
-
-// Test Stereo to 5.1 conversion.  S16_LE, LeftRight.
-TEST(FormatConverterOpsTest, StereoTo51S16LELeftRight) {
-  const size_t frames = 4096;
-  const size_t in_ch = 2;
-  const size_t out_ch = 6;
-  const size_t left = 0;
-  const size_t right = 1;
-  const size_t center = -1;
-
-  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());
-  EXPECT_EQ(ret, frames);
-
-  for (size_t i = 0; i < frames; ++i) {
-    for (size_t k = 0; k < 6; ++k) {
-      if (k == left)
-        EXPECT_EQ(src[i * 2 + 0], dst[i * 6 + k]);
-      else if (k == right)
-        EXPECT_EQ(src[i * 2 + 1], dst[i * 6 + k]);
-      else
-        EXPECT_EQ(0, dst[i * 6 + k]);
-    }
-  }
-}
-
-// Test Stereo to 5.1 conversion.  S16_LE, Unknown.
-TEST(FormatConverterOpsTest, StereoTo51S16LEUnknown) {
-  const size_t frames = 4096;
-  const size_t in_ch = 2;
-  const size_t out_ch = 6;
-  const size_t left = -1;
-  const size_t right = -1;
-  const size_t center = -1;
-
-  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());
-  EXPECT_EQ(ret, frames);
-
-  for (size_t i = 0; i < frames; ++i) {
-    for (size_t k = 0; k < 6; ++k) {
-      if (k == 0 || k == 1)
-        EXPECT_EQ(src[i * 2 + k], dst[i * 6 + k]);
-      else
-        EXPECT_EQ(0, dst[i * 6 + k]);
-    }
-  }
-}
-
-// Test 5.1 to Stereo conversion.  S16_LE.
-TEST(FormatConverterOpsTest, _51ToStereoS16LE) {
-  const size_t frames = 4096;
-  const size_t in_ch = 6;
-  const size_t out_ch = 2;
-  const size_t left = 0;
-  const size_t right = 1;
-  const size_t center = 4;
-
-  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());
-  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 + right], half_center),
-              dst[i * 2 + right]);
-  }
-}
-
-// Test Stereo to Quad conversion.  S16_LE, Specify.
-TEST(FormatConverterOpsTest, StereoToQuadS16LESpecify) {
-  const size_t frames = 4096;
-  const size_t in_ch = 2;
-  const size_t out_ch = 4;
-  const size_t front_left = 2;
-  const size_t front_right = 3;
-  const size_t rear_left = 0;
-  const size_t rear_right = 1;
-
-  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());
-  EXPECT_EQ(ret, frames);
-
-  for (size_t i = 0; i < frames; ++i) {
-    EXPECT_EQ(src[i * 2 + 0], dst[i * 4 + front_left]);
-    EXPECT_EQ(src[i * 2 + 0], dst[i * 4 + rear_left]);
-    EXPECT_EQ(src[i * 2 + 1], dst[i * 4 + front_right]);
-    EXPECT_EQ(src[i * 2 + 1], dst[i * 4 + rear_right]);
-  }
-}
-
-// Test Stereo to Quad conversion.  S16_LE, Default.
-TEST(FormatConverterOpsTest, StereoToQuadS16LEDefault) {
-  const size_t frames = 4096;
-  const size_t in_ch = 2;
-  const size_t out_ch = 4;
-  const size_t front_left = -1;
-  const size_t front_right = -1;
-  const size_t rear_left = -1;
-  const size_t rear_right = -1;
-
-  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());
-  EXPECT_EQ(ret, frames);
-
-  for (size_t i = 0; i < frames; ++i) {
-    EXPECT_EQ(src[i * 2 + 0], dst[i * 4 + 0]);
-    EXPECT_EQ(src[i * 2 + 0], dst[i * 4 + 2]);
-    EXPECT_EQ(src[i * 2 + 1], dst[i * 4 + 1]);
-    EXPECT_EQ(src[i * 2 + 1], dst[i * 4 + 3]);
-  }
-}
-
-// Test Quad to Stereo conversion.  S16_LE, Specify.
-TEST(FormatConverterOpsTest, QuadToStereoS16LESpecify) {
-  const size_t frames = 4096;
-  const size_t in_ch = 4;
-  const size_t out_ch = 2;
-  const size_t front_left = 2;
-  const size_t front_right = 3;
-  const size_t rear_left = 0;
-  const size_t rear_right = 1;
-
-  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());
-  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);
-    EXPECT_EQ(left, dst[i * 2 + 0]);
-    EXPECT_EQ(right, dst[i * 2 + 1]);
-  }
-}
-
-// Test Quad to Stereo conversion.  S16_LE, Default.
-TEST(FormatConverterOpsTest, QuadToStereoS16LEDefault) {
-  const size_t frames = 4096;
-  const size_t in_ch = 4;
-  const size_t out_ch = 2;
-  const size_t front_left = -1;
-  const size_t front_right = -1;
-  const size_t rear_left = -1;
-  const size_t rear_right = -1;
-
-  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());
-  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);
-    EXPECT_EQ(left, dst[i * 2 + 0]);
-    EXPECT_EQ(right, dst[i * 2 + 1]);
-  }
-}
-
-// Test Stereo to 3ch conversion.  S16_LE.
-TEST(FormatConverterOpsTest, StereoTo3chS16LE) {
-  const size_t frames = 4096;
-  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,
-  };
-
-  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());
-  EXPECT_EQ(ret, frames);
-
-  for (size_t i = 0; i < frames; ++i) {
-    for (size_t k = 0; k < in_ch; ++k)
-      src[i * in_ch + k] /= in_ch;
-    for (size_t k = 1; k < in_ch; ++k)
-      src[i * in_ch + 0] += src[i * in_ch + k];
-  }
-  for (size_t i = 0; i < frames; ++i) {
-    for (size_t k = 0; k < out_ch; ++k)
-      EXPECT_EQ(src[i * in_ch + 0], dst[i * out_ch + k]);
-  }
-}
-
-// Test Multiply with Coef.  S16_LE.
-TEST(FormatConverterOpsTest, MultiplyWithCoefS16LE) {
-  const size_t buf_size = 4096;
-
-  S16LEPtr buf = CreateS16LE(buf_size);
-  FloatPtr coef = CreateFloat(buf_size);
-
-  int16_t ret = s16_multiply_buf_with_coef(coef.get(), buf.get(), buf_size);
-
-  int32_t exp = 0;
-  for (size_t i = 0; i < buf_size; ++i)
-    exp += coef[i] * buf[i];
-  exp = MIN(MAX(exp, SHRT_MIN), SHRT_MAX);
-
-  EXPECT_EQ((int16_t)exp, ret);
-}
-
-// Test Convert Channels.  S16_LE.
-TEST(FormatConverterOpsTest, ConvertChannelsS16LE) {
-  const size_t frames = 4096;
-  const size_t in_ch = 2;
-  const size_t out_ch = 3;
-
-  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]);
-  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());
-  EXPECT_EQ(ret, frames);
-
-  for (size_t fr = 0; fr < frames; ++fr) {
-    for (size_t i = 0; i < out_ch; ++i) {
-      int16_t exp = 0;
-      for (size_t k = 0; k < in_ch; ++k)
-        exp += mtx[i][k] * src[fr * in_ch + k];
-      exp = MIN(MAX(exp, SHRT_MIN), SHRT_MAX);
-      EXPECT_EQ(exp, dst[fr * out_ch + i]);
-    }
-  }
-}
-
-extern "C" {}  // extern "C"
-
-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 5474f17..08bb243 100644
--- a/cras/src/tests/fmt_conv_unittest.cc
+++ b/cras/src/tests/fmt_conv_unittest.cc
@@ -10,24 +10,18 @@
 #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_layout[CRAS_CH_MAX] =
+	{0, 1, 2, 3, 4, 5, -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;
 static unsigned int linear_resampler_format_bytes;
-static int linear_resampler_src_rate;
-static int linear_resampler_dst_rate;
 
 void ResetStub() {
   linear_resampler_needed_val = 0;
@@ -35,27 +29,27 @@
 }
 
 // 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,13 +60,11 @@
   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_EQ(out_fmt.frame_rate, linear_resampler_src_rate);
-  EXPECT_EQ(out_fmt.frame_rate, linear_resampler_dst_rate);
+  EXPECT_NE((void *)NULL, c);
 
   /* When process on small buffers doing SRC 16KHz -> 48KHz,
    * speex does the work in two steps:
@@ -83,15 +75,19 @@
    * 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);
 
@@ -101,10 +97,10 @@
 }
 
 // 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;
@@ -115,13 +111,13 @@
 
 // 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;
 
@@ -134,7 +130,7 @@
   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);
@@ -142,13 +138,17 @@
   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;
     }
@@ -161,13 +161,13 @@
 
 // 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;
@@ -181,7 +181,7 @@
   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);
@@ -189,14 +189,17 @@
   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]);
@@ -207,111 +210,15 @@
   free(out_buff);
 }
 
-// Test Stereo to Mono mix.  Overflow.
-TEST(FormatConverterTest, StereoToMonoOverflow) {
-  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;
-  unsigned int i;
-  const size_t buf_size = 4096;
-  unsigned int in_buf_size = 4096;
-
-  ResetStub();
-  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 = 1;
-  in_fmt.frame_rate = 48000;
-  out_fmt.frame_rate = 48000;
-
-  c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0);
-  ASSERT_NE(c, (void*)NULL);
-
-  out_frames = cras_fmt_conv_out_frames_to_in(c, buf_size);
-  EXPECT_EQ(buf_size, out_frames);
-
-  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));
-  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);
-  EXPECT_EQ(buf_size, out_frames);
-  for (i = 0; i < buf_size; i++) {
-    EXPECT_EQ(0x7fff, out_buff[i]);
-  }
-
-  cras_fmt_conv_destroy(&c);
-  free(in_buff);
-  free(out_buff);
-}
-
-// Test Stereo to Mono mix.  Underflow.
-TEST(FormatConverterTest, StereoToMonoUnderflow) {
-  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;
-  unsigned int i;
-  const size_t buf_size = 4096;
-  unsigned int in_buf_size = 4096;
-
-  ResetStub();
-  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 = 1;
-  in_fmt.frame_rate = 48000;
-  out_fmt.frame_rate = 48000;
-
-  c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0);
-  ASSERT_NE(c, (void*)NULL);
-
-  out_frames = cras_fmt_conv_out_frames_to_in(c, buf_size);
-  EXPECT_EQ(buf_size, out_frames);
-
-  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));
-  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);
-  EXPECT_EQ(buf_size, out_frames);
-  for (i = 0; i < buf_size; i++) {
-    EXPECT_EQ(-0x8000, out_buff[i]);
-  }
-
-  cras_fmt_conv_destroy(&c);
-  free(in_buff);
-  free(out_buff);
-}
-
 // 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;
@@ -332,7 +239,7 @@
     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);
@@ -340,18 +247,21 @@
     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);
@@ -362,13 +272,13 @@
 
 // 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;
@@ -381,10 +291,10 @@
   in_fmt.frame_rate = 48000;
   out_fmt.frame_rate = 48000;
   for (i = 0; i < CRAS_CH_MAX; i++)
-    in_fmt.channel_layout[i] = surround_channel_center_layout[i];
+    in_fmt.channel_layout[i] = surround_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);
@@ -392,7 +302,7 @@
   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.
@@ -405,9 +315,12 @@
     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]);
@@ -419,8 +332,11 @@
   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]);
@@ -432,8 +348,11 @@
   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]);
@@ -446,8 +365,11 @@
   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]);
@@ -461,13 +383,13 @@
 
 // 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;
@@ -483,7 +405,7 @@
     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);
@@ -491,7 +413,7 @@
   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
@@ -503,10 +425,13 @@
     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]);
@@ -520,8 +445,11 @@
   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]);
@@ -535,8 +463,11 @@
   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]);
@@ -550,8 +481,11 @@
   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]);
@@ -564,14 +498,14 @@
 }
 
 // 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;
 
@@ -582,28 +516,31 @@
   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);
+  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);
 }
 
 // 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;
 
@@ -614,28 +551,31 @@
   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);
+  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);
 }
 
 // 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;
 
@@ -647,7 +587,7 @@
   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);
@@ -655,10 +595,13 @@
   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);
@@ -666,13 +609,13 @@
 
 // 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;
 
@@ -684,15 +627,18 @@
   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]);
@@ -704,13 +650,13 @@
 
 // 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;
 
@@ -722,15 +668,18 @@
   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]);
@@ -742,13 +691,13 @@
 
 // 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;
 
@@ -761,15 +710,18 @@
   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),
@@ -782,13 +734,13 @@
 
 // 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;
 
@@ -800,15 +752,18 @@
   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]);
@@ -820,13 +775,13 @@
 
 // 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;
 
@@ -838,15 +793,18 @@
   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]);
@@ -858,13 +816,13 @@
 
 // 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;
 
@@ -877,15 +835,18 @@
   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]);
@@ -897,13 +858,13 @@
 
 // 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;
@@ -916,18 +877,21 @@
   in_fmt.frame_rate = 48000;
   out_fmt.frame_rate = 48000;
   for (i = 0; i < CRAS_CH_MAX; i++)
-    in_fmt.channel_layout[i] = surround_channel_center_layout[i];
+    in_fmt.channel_layout[i] = surround_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 = (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);
@@ -937,13 +901,13 @@
 
 // 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;
@@ -956,18 +920,21 @@
   in_fmt.frame_rate = 48000;
   out_fmt.frame_rate = 48000;
   for (i = 0; i < CRAS_CH_MAX; i++)
-    out_fmt.channel_layout[i] = surround_channel_center_layout[i];
+    out_fmt.channel_layout[i] = surround_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*)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 */
@@ -984,15 +951,15 @@
   free(out_buff);
 }
 
-// Test 16 bit mono to 5.1 conversion.  Center.
-TEST(FormatConverterTest, ConvertS16LEToS16LEMonoTo51Center) {
-  struct cras_fmt_conv* c;
+// Test 16 bit mono to 5.1 conversion.
+TEST(FormatConverterTest, ConvertS16LEToS16LEMonoTo51) {
+  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;
@@ -1005,18 +972,21 @@
   in_fmt.frame_rate = 48000;
   out_fmt.frame_rate = 48000;
   for (i = 0; i < CRAS_CH_MAX; i++)
-    out_fmt.channel_layout[i] = surround_channel_center_layout[i];
+    out_fmt.channel_layout[i] = surround_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*)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 */
@@ -1033,117 +1003,16 @@
   free(out_buff);
 }
 
-// Test 16 bit mono to 5.1 conversion.  Left Right.
-TEST(FormatConverterTest, ConvertS16LEToS16LEMonoTo51LeftRight) {
-  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;
-  const size_t buf_size = 4096;
-  unsigned int in_buf_size = 4096;
-  unsigned int i, left, right;
-
-  ResetStub();
-  in_fmt.format = SND_PCM_FORMAT_S16_LE;
-  out_fmt.format = SND_PCM_FORMAT_S16_LE;
-  in_fmt.num_channels = 1;
-  out_fmt.num_channels = 6;
-  in_fmt.frame_rate = 48000;
-  out_fmt.frame_rate = 48000;
-  for (i = 0; i < CRAS_CH_MAX; i++)
-    out_fmt.channel_layout[i] = surround_channel_left_right_layout[i];
-  left = surround_channel_left_right_layout[CRAS_CH_FL];
-  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);
-
-  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);
-  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 */
-    for (unsigned int k = 0; k < 6; ++k) {
-      if (k == left)
-        EXPECT_EQ(in_buff[i] / 2, out_buff[6 * i + left]);
-      else if (k == right)
-        EXPECT_EQ(in_buff[i] / 2, out_buff[6 * i + right]);
-      else
-        EXPECT_EQ(0, out_buff[6 * i + k]);
-    }
-  }
-
-  cras_fmt_conv_destroy(&c);
-  free(in_buff);
-  free(out_buff);
-}
-
-// Test 16 bit mono to 5.1 conversion.  Unknown.
-TEST(FormatConverterTest, ConvertS16LEToS16LEMonoTo51Unknown) {
-  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;
-  const size_t buf_size = 4096;
-  unsigned int in_buf_size = 4096;
-  int i;
-
-  ResetStub();
-  in_fmt.format = SND_PCM_FORMAT_S16_LE;
-  out_fmt.format = SND_PCM_FORMAT_S16_LE;
-  in_fmt.num_channels = 1;
-  out_fmt.num_channels = 6;
-  in_fmt.frame_rate = 48000;
-  out_fmt.frame_rate = 48000;
-  for (i = 0; i < CRAS_CH_MAX; i++)
-    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);
-
-  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);
-  EXPECT_EQ(buf_size, out_frames);
-  for (unsigned int i = 0; i < buf_size; i++) {
-    /* Check mono be converted to CRAS_CH_FL */
-    EXPECT_EQ(in_buff[i], out_buff[6 * i + 0]);
-    EXPECT_EQ(0, out_buff[6 * i + 1]);
-    EXPECT_EQ(0, out_buff[6 * i + 2]);
-    EXPECT_EQ(0, out_buff[6 * i + 3]);
-    EXPECT_EQ(0, out_buff[6 * i + 4]);
-    EXPECT_EQ(0, out_buff[6 * i + 5]);
-  }
-
-  cras_fmt_conv_destroy(&c);
-  free(in_buff);
-  free(out_buff);
-}
 
 // 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;
 
@@ -1158,20 +1027,23 @@
     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]);
@@ -1185,8 +1057,11 @@
   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]);
@@ -1202,13 +1077,13 @@
 
 // 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;
@@ -1221,18 +1096,21 @@
   in_fmt.frame_rate = 48000;
   out_fmt.frame_rate = 96000;
   for (i = 0; i < CRAS_CH_MAX; i++)
-    in_fmt.channel_layout[i] = surround_channel_center_layout[i];
+    in_fmt.channel_layout[i] = surround_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 * 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);
@@ -1242,13 +1120,13 @@
 
 // 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;
@@ -1261,18 +1139,21 @@
   in_fmt.frame_rate = 96000;
   out_fmt.frame_rate = 48000;
   for (i = 0; i < CRAS_CH_MAX; i++)
-    in_fmt.channel_layout[i] = surround_channel_center_layout[i];
+    in_fmt.channel_layout[i] = surround_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 / 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);
@@ -1282,14 +1163,14 @@
 
 // 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;
@@ -1302,18 +1183,21 @@
   in_fmt.frame_rate = 48000;
   out_fmt.frame_rate = 44100;
   for (i = 0; i < CRAS_CH_MAX; i++)
-    in_fmt.channel_layout[i] = surround_channel_center_layout[i];
+    in_fmt.channel_layout[i] = surround_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_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);
@@ -1323,14 +1207,14 @@
 
 // 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;
@@ -1343,19 +1227,22 @@
   in_fmt.frame_rate = 44100;
   out_fmt.frame_rate = 48000;
   for (i = 0; i < CRAS_CH_MAX; i++)
-    in_fmt.channel_layout[i] = surround_channel_center_layout[i];
+    in_fmt.channel_layout[i] = surround_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_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);
@@ -1365,14 +1252,14 @@
 
 // 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;
@@ -1385,19 +1272,22 @@
   in_fmt.frame_rate = 96000;
   out_fmt.frame_rate = 48000;
   for (i = 0; i < CRAS_CH_MAX; i++)
-    in_fmt.channel_layout[i] = surround_channel_center_layout[i];
+    in_fmt.channel_layout[i] = surround_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 / 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);
@@ -1407,13 +1297,13 @@
 
 // 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;
@@ -1427,14 +1317,12 @@
   in_fmt.frame_rate = 96000;
   out_fmt.frame_rate = 48000;
   for (i = 0; i < CRAS_CH_MAX; i++) {
-    in_fmt.channel_layout[i] = surround_channel_center_layout[i];
-    out_fmt.channel_layout[i] = surround_channel_center_layout[i];
+    in_fmt.channel_layout[i] = surround_channel_layout[i];
+    out_fmt.channel_layout[i] = surround_channel_layout[i];
   }
 
   c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size * 2, 1);
-  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);
+  ASSERT_NE(c, (void *)NULL);
 
   linear_resampler_needed_val = 1;
   linear_resampler_ratio = 1.01;
@@ -1442,10 +1330,13 @@
   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);
@@ -1455,13 +1346,13 @@
 
 // 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;
@@ -1475,14 +1366,12 @@
   in_fmt.frame_rate = 96000;
   out_fmt.frame_rate = 48000;
   for (i = 0; i < CRAS_CH_MAX; i++) {
-    in_fmt.channel_layout[i] = surround_channel_center_layout[i];
-    out_fmt.channel_layout[i] = surround_channel_center_layout[i];
+    in_fmt.channel_layout[i] = surround_channel_layout[i];
+    out_fmt.channel_layout[i] = surround_channel_layout[i];
   }
 
   c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size * 2, 0);
-  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);
+  ASSERT_NE(c, (void *)NULL);
 
   linear_resampler_needed_val = 1;
   linear_resampler_ratio = 0.99;
@@ -1490,10 +1379,13 @@
   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);
@@ -1504,7 +1396,7 @@
 // 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;
 
@@ -1521,7 +1413,7 @@
   }
 
   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);
 }
@@ -1530,7 +1422,7 @@
 // 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;
 
@@ -1547,7 +1439,7 @@
   }
 
   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);
 }
@@ -1555,10 +1447,10 @@
 // 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;
 
@@ -1575,14 +1467,14 @@
   }
 
   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;
@@ -1590,16 +1482,8 @@
   fmt.num_channels = 2;
   conv = cras_channel_remix_conv_create(2, coeff);
 
-  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);
-  for (i = 0; i < 100; i++)
-    EXPECT_EQ(res[i], buf[i]);
+  buf = (int16_t *)ralloc(50 * 4);
+  res = (int16_t *)malloc(50 * 4);
 
   for (i = 0; i < 100; i += 2) {
     res[i] = coeff[0] * buf[i];
@@ -1608,85 +1492,89 @@
     res[i + 1] += coeff[3] * buf[i + 1];
   }
 
-  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) {
-  linear_resampler_src_rate = from;
-  linear_resampler_dst_rate = to;
+                                unsigned int 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) {
@@ -1695,11 +1583,13 @@
   }
   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
deleted file mode 100644
index 56c9908..0000000
--- a/cras/src/tests/hfp_ag_profile_unittest.cc
+++ /dev/null
@@ -1,264 +0,0 @@
-/* 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>
-
-extern "C" {
-#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 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();
-  }
-
-  virtual void TearDown() { cras_bt_event_log_deinit(btlog); }
-};
-
-TEST_F(HfpAgProfile, StartWithoutScoPCM) {
-  int ret;
-  struct cras_bt_profile* bt_profile;
-
-  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);
-
-  ret = cras_hfp_ag_start(fake_device);
-
-  EXPECT_EQ(0, ret);
-  EXPECT_EQ(2, hfp_iodev_create_called);
-
-  /* Start ag twice won't create more iodev. */
-  ret = cras_hfp_ag_start(fake_device);
-  EXPECT_EQ(0, ret);
-  EXPECT_EQ(2, hfp_iodev_create_called);
-
-  bt_profile->release(bt_profile);
-
-  EXPECT_EQ(2, hfp_iodev_destroy_called);
-}
-
-TEST_F(HfpAgProfile, StartWithScoPCM) {
-  int ret;
-  struct cras_bt_profile* bt_profile;
-
-  with_sco_pcm = 1;
-  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);
-
-  ret = cras_hfp_ag_start(fake_device);
-
-  EXPECT_EQ(0, ret);
-  EXPECT_EQ(2, hfp_alsa_iodev_create_called);
-
-  bt_profile->release(bt_profile);
-
-  EXPECT_EQ(2, hfp_alsa_iodev_destroy_called);
-}
-
-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_iodev* cras_iodev_list_get_sco_pcm_iodev(
-    enum CRAS_STREAM_DIRECTION direction) {
-  if (with_sco_pcm) {
-    if (direction == CRAS_STREAM_OUTPUT)
-      return &fake_sco_out;
-    else
-      return &fake_sco_in;
-  }
-
-  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) {
-  hfp_alsa_iodev_create_called++;
-  return (struct cras_iodev*)0xdeadbeef;
-}
-
-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) {
-  hfp_iodev_create_called++;
-  return (struct cras_iodev*)0xdeadbeef;
-}
-
-void hfp_iodev_destroy(struct cras_iodev* iodev) {
-  hfp_iodev_destroy_called++;
-}
-
-int cras_bt_add_profile(DBusConnection* conn, struct cras_bt_profile* profile) {
-  internal_bt_profile = profile;
-  return 0;
-}
-
-struct hfp_info* hfp_info_create() {
-  return NULL;
-}
-
-int hfp_info_running(struct hfp_info* info) {
-  return 0;
-}
-
-int hfp_info_stop(struct hfp_info* info) {
-  return 0;
-}
-
-void hfp_info_destroy(struct hfp_info* info) {}
-
-void hfp_slc_destroy(struct hfp_slc_handle* slc_handle) {}
-
-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) {
-  return 0;
-}
-
-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)) {}
-
-enum cras_bt_device_profile cras_bt_device_profile_from_uuid(const char* uuid) {
-  return CRAS_BT_DEVICE_PROFILE_HSP_AUDIOGATEWAY;
-}
-
-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) {
-  return HFP_CODEC_ID_CVSD;
-}
-
-int hfp_slc_get_hf_codec_negotiation_supported(struct hfp_slc_handle* handle) {
-  return 1;
-}
-
-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) {
-  return 0;
-}
-
-void cras_a2dp_suspend_connected_device(struct cras_bt_device* device) {}
-
-int cras_bt_device_audio_gateway_initialized(struct cras_bt_device* device) {
-  return 0;
-}
-
-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"
-
-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
deleted file mode 100644
index a4d5ba9..0000000
--- a/cras/src/tests/hfp_alsa_iodev_unittest.cc
+++ /dev/null
@@ -1,481 +0,0 @@
-/* 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>
-
-extern "C" {
-#include "cras_audio_format.h"
-#include "cras_hfp_alsa_iodev.h"
-#include "cras_hfp_slc.h"
-#include "cras_iodev.h"
-}
-
-struct hfp_alsa_io {
-  struct cras_iodev base;
-  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 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 size_t cras_iodev_rm_node_called;
-static size_t cras_iodev_set_active_node_called;
-static size_t cras_iodev_free_format_called;
-static size_t cras_iodev_free_resources_called;
-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)             \
-  static size_t fake_##name##_called; \
-  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_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);
-_FAKE_CALL1(update_supported_formats);
-_FAKE_CALL1(configure_dev);
-_FAKE_CALL1(close_dev);
-_FAKE_CALL2(frames_queued);
-_FAKE_CALL1(delay_frames);
-_FAKE_CALL3(get_buffer);
-_FAKE_CALL2(put_buffer);
-_FAKE_CALL1(flush_buffer);
-_FAKE_CALL3(update_active_node);
-_FAKE_CALL1(start);
-_FAKE_CALL2(no_stream);
-_FAKE_CALL1(is_free_running);
-
-static void ResetStubData() {
-  cras_bt_device_append_iodev_called = 0;
-  cras_bt_device_rm_iodev_called = 0;
-  cras_iodev_add_node_called = 0;
-  cras_iodev_rm_node_called = 0;
-  cras_iodev_set_active_node_called = 0;
-  cras_iodev_free_format_called = 0;
-  cras_iodev_free_resources_called = 0;
-  cras_iodev_set_format_called = 0;
-  hfp_set_call_status_called = 0;
-  hfp_event_speaker_gain_called = 0;
-
-  fake_sco_out.open_dev = fake_sco_in.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;
-  fake_update_supported_formats_called = 0;
-
-  fake_sco_out.configure_dev = fake_sco_in.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;
-  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;
-  fake_frames_queued_called = 0;
-
-  fake_sco_out.delay_frames = fake_sco_in.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_get_buffer_called = 0;
-
-  fake_sco_out.put_buffer = fake_sco_in.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;
-  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;
-  fake_update_active_node_called = 0;
-
-  fake_sco_out.start = fake_sco_in.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;
-  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;
-  fake_is_free_running_called = 0;
-}
-
-namespace {
-
-class HfpAlsaIodev : public testing::Test {
- protected:
-  virtual void SetUp() { ResetStubData(); }
-
-  virtual void TearDown() {}
-};
-
-TEST_F(HfpAlsaIodev, CreateHfpAlsaOutputIodev) {
-  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;
-
-  EXPECT_EQ(CRAS_STREAM_OUTPUT, iodev->direction);
-  EXPECT_EQ(1, cras_bt_device_append_iodev_called);
-  EXPECT_EQ(1, cras_iodev_add_node_called);
-  EXPECT_EQ(1, cras_iodev_set_active_node_called);
-  EXPECT_EQ(&fake_sco_out, hfp_alsa_io->aio);
-
-  hfp_alsa_iodev_destroy(iodev);
-
-  EXPECT_EQ(1, cras_bt_device_rm_iodev_called);
-  EXPECT_EQ(1, cras_iodev_rm_node_called);
-  EXPECT_EQ(1, cras_iodev_free_resources_called);
-}
-
-TEST_F(HfpAlsaIodev, CreateHfpAlsaInputIodev) {
-  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;
-
-  EXPECT_EQ(CRAS_STREAM_INPUT, iodev->direction);
-  EXPECT_EQ(1, cras_bt_device_append_iodev_called);
-  EXPECT_EQ(1, cras_iodev_add_node_called);
-  EXPECT_EQ(1, cras_iodev_set_active_node_called);
-  EXPECT_EQ(&fake_sco_in, hfp_alsa_io->aio);
-  /* Input device does not use software gain. */
-  EXPECT_EQ(0, iodev->software_volume_needed);
-
-  hfp_alsa_iodev_destroy(iodev);
-
-  EXPECT_EQ(1, cras_bt_device_rm_iodev_called);
-  EXPECT_EQ(1, cras_iodev_rm_node_called);
-  EXPECT_EQ(1, cras_iodev_free_resources_called);
-}
-
-TEST_F(HfpAlsaIodev, OpenDev) {
-  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->open_dev(iodev);
-
-  EXPECT_EQ(1, fake_open_dev_called);
-
-  hfp_alsa_iodev_destroy(iodev);
-}
-
-TEST_F(HfpAlsaIodev, UpdateSupportedFormat) {
-  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};
-
-  fake_sco_out.supported_rates = supported_rates;
-  fake_sco_out.supported_channel_counts = supported_channel_counts;
-  fake_sco_out.supported_formats = supported_formats;
-
-  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->update_supported_formats(iodev);
-
-  EXPECT_EQ(1, fake_update_supported_formats_called);
-  for (size_t i = 0; i < 2; ++i) {
-    EXPECT_EQ(supported_rates[i], iodev->supported_rates[i]);
-    EXPECT_EQ(supported_channel_counts[i], iodev->supported_channel_counts[i]);
-    EXPECT_EQ(supported_formats[i], iodev->supported_formats[i]);
-  }
-
-  hfp_alsa_iodev_destroy(iodev);
-}
-
-TEST_F(HfpAlsaIodev, ConfigureDev) {
-  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);
-  iodev->configure_dev(iodev);
-
-  EXPECT_EQ(1, fake_configure_dev_called);
-  EXPECT_EQ(1, hfp_set_call_status_called);
-  EXPECT_EQ(buf_size, iodev->buffer_size);
-
-  hfp_alsa_iodev_destroy(iodev);
-}
-
-TEST_F(HfpAlsaIodev, CloseDev) {
-  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->close_dev(iodev);
-
-  EXPECT_EQ(1, cras_iodev_free_format_called);
-  EXPECT_EQ(1, fake_close_dev_called);
-
-  hfp_alsa_iodev_destroy(iodev);
-}
-
-TEST_F(HfpAlsaIodev, FramesQueued) {
-  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);
-
-  EXPECT_EQ(1, fake_frames_queued_called);
-
-  hfp_alsa_iodev_destroy(iodev);
-}
-
-TEST_F(HfpAlsaIodev, DelayFrames) {
-  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->delay_frames(iodev);
-
-  EXPECT_EQ(1, fake_delay_frames_called);
-
-  hfp_alsa_iodev_destroy(iodev);
-}
-
-TEST_F(HfpAlsaIodev, GetBuffer) {
-  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);
-
-  EXPECT_EQ(1, fake_get_buffer_called);
-
-  hfp_alsa_iodev_destroy(iodev);
-}
-
-TEST_F(HfpAlsaIodev, PutBuffer) {
-  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->put_buffer(iodev, 0xdeadbeef);
-
-  EXPECT_EQ(1, fake_put_buffer_called);
-
-  hfp_alsa_iodev_destroy(iodev);
-}
-
-TEST_F(HfpAlsaIodev, FlushBuffer) {
-  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->flush_buffer(iodev);
-
-  EXPECT_EQ(1, fake_flush_buffer_called);
-
-  hfp_alsa_iodev_destroy(iodev);
-}
-
-TEST_F(HfpAlsaIodev, UpdateActiveNode) {
-  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->update_active_node(iodev, 0xdeadbeef, 0xdeadbeef);
-
-  EXPECT_EQ(1, fake_update_active_node_called);
-
-  hfp_alsa_iodev_destroy(iodev);
-}
-
-TEST_F(HfpAlsaIodev, Start) {
-  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->start(iodev);
-
-  EXPECT_EQ(1, fake_start_called);
-
-  hfp_alsa_iodev_destroy(iodev);
-}
-
-TEST_F(HfpAlsaIodev, SetVolume) {
-  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->set_volume(iodev);
-
-  EXPECT_EQ(1, hfp_event_speaker_gain_called);
-
-  hfp_alsa_iodev_destroy(iodev);
-}
-
-TEST_F(HfpAlsaIodev, NoStream) {
-  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->min_cb_level = 0xab;
-  iodev->max_cb_level = 0xcd;
-
-  iodev->no_stream(iodev, 1);
-
-  EXPECT_EQ(0xab, fake_sco_out.min_cb_level);
-  EXPECT_EQ(0xcd, fake_sco_out.max_cb_level);
-  EXPECT_EQ(1, fake_no_stream_called);
-
-  hfp_alsa_iodev_destroy(iodev);
-}
-
-TEST_F(HfpAlsaIodev, IsFreeRunning) {
-  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->is_free_running(iodev);
-
-  EXPECT_EQ(1, fake_is_free_running_called);
-
-  hfp_alsa_iodev_destroy(iodev);
-}
-
-}  // namespace
-
-extern "C" {
-
-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) {
-  cras_iodev_free_format_called++;
-}
-
-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) {
-  cras_iodev_rm_node_called++;
-  iodev->nodes = NULL;
-}
-
-void cras_iodev_set_active_node(struct cras_iodev* iodev,
-                                struct cras_ionode* node) {
-  cras_iodev_set_active_node_called++;
-  iodev->active_node = node;
-}
-
-size_t cras_system_get_volume() {
-  return 0;
-}
-
-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) {
-  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) {
-  cras_bt_device_append_iodev_called++;
-}
-
-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) {
-  return "/fake/object/path";
-}
-
-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) {
-  hfp_set_call_status_called++;
-  return 0;
-}
-
-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) {
-  return 0;
-}
-
-void cras_bt_device_put_sco(struct cras_bt_device* device) {}
-
-int hfp_slc_get_selected_codec(struct hfp_slc_handle* handle) {
-  return HFP_CODEC_ID_CVSD;
-}
-
-}  // extern "C"
-
-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 482c3a9..82b9393 100644
--- a/cras/src/tests/hfp_info_unittest.cc
+++ b/cras/src/tests/hfp_info_unittest.cc
@@ -8,25 +8,18 @@
 #include <time.h>
 
 extern "C" {
-#include "cras_hfp_info.c"
-#include "sbc_codec_stub.h"
+  #include "cras_hfp_info.c"
 }
-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;
@@ -36,83 +29,79 @@
 namespace {
 
 TEST(HfpInfo, AddRmDev) {
-  ResetStubData();
-
-  info = hfp_info_create(HFP_CODEC_ID_CVSD);
-  ASSERT_NE(info, (void*)NULL);
+  info = hfp_info_create();
+  ASSERT_NE(info, (void *)NULL);
   dev.direction = CRAS_STREAM_OUTPUT;
 
   /* Test add dev */
-  ASSERT_EQ(0, hfp_info_add_iodev(info, dev.direction, dev.format));
+  ASSERT_EQ(0, hfp_info_add_iodev(info, &dev));
   ASSERT_TRUE(hfp_info_has_iodev(info));
 
   /* Test remove dev */
-  ASSERT_EQ(0, hfp_info_rm_iodev(info, dev.direction));
+  ASSERT_EQ(0, hfp_info_rm_iodev(info, &dev));
   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);
+  info = hfp_info_create();
+  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.direction));
+  ASSERT_NE(0, hfp_info_rm_iodev(info, &dev));
 
   /* Adding an iodev twice returns error code */
-  ASSERT_EQ(0, hfp_info_add_iodev(info, dev.direction, dev.format));
-  ASSERT_NE(0, hfp_info_add_iodev(info, dev.direction, dev.format));
+  ASSERT_EQ(0, hfp_info_add_iodev(info, &dev));
+  ASSERT_NE(0, hfp_info_add_iodev(info, &dev));
 
   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);
+  info = hfp_info_create();
+  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.direction, dev.format));
+  ASSERT_EQ(0, hfp_info_add_iodev(info, &dev));
 
   buffer_frames = 500;
-  hfp_buf_acquire(info, dev.direction, &samples, &buffer_frames);
+  hfp_buf_acquire(info, &dev, &samples, &buffer_frames);
   ASSERT_EQ(500, buffer_frames);
 
-  hfp_buf_release(info, dev.direction, 500);
-  ASSERT_EQ(500, hfp_buf_queued(info, dev.direction));
+  hfp_buf_release(info, &dev, 500);
+  ASSERT_EQ(500, hfp_buf_queued(info, &dev));
 
   /* 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.direction);
+  queued = hfp_buf_queued(info, &dev);
   buffer_frames = 500;
-  hfp_buf_acquire(info, dev.direction, &samples, &buffer_frames);
+  hfp_buf_acquire(info, &dev, &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.direction);
+  queued = hfp_buf_queued(info, &dev);
   ASSERT_EQ(0, queued);
 
   /* Assert consecutive acquire buffer will acquire full used size of buffer */
   buffer_frames = 500;
-  hfp_buf_acquire(info, dev.direction, &samples, &buffer_frames);
-  hfp_buf_release(info, dev.direction, buffer_frames);
+  hfp_buf_acquire(info, &dev, &samples, &buffer_frames);
+  hfp_buf_release(info, &dev, buffer_frames);
 
   buffer_frames2 = 500;
-  hfp_buf_acquire(info, dev.direction, &samples, &buffer_frames2);
-  hfp_buf_release(info, dev.direction, buffer_frames2);
+  hfp_buf_acquire(info, &dev, &samples, &buffer_frames2);
+  hfp_buf_release(info, &dev, buffer_frames2);
 
   ASSERT_GE(info->playback_buf->used_size / 2, buffer_frames + buffer_frames2);
 
@@ -121,27 +110,27 @@
 
 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);
+  info = hfp_info_create();
+  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.direction, dev.format));
+  ASSERT_EQ(0, hfp_info_add_iodev(info, &dev));
 
   /* 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.direction, &samples, &buffer_frames);
+  hfp_buf_acquire(info, &dev, &samples, &buffer_frames);
   ASSERT_EQ(50, buffer_frames);
 
-  hfp_buf_release(info, dev.direction, buffer_frames);
-  ASSERT_EQ(0, hfp_buf_queued(info, dev.direction));
+  hfp_buf_release(info, &dev, buffer_frames);
+  ASSERT_EQ(0, hfp_buf_queued(info, &dev));
 
   /* Push fake data to capture buffer */
   buf_increment_write(info->capture_buf, info->capture_buf->used_size - 100);
@@ -149,13 +138,13 @@
 
   /* Assert consecutive acquire call will consume the whole buffer */
   buffer_frames = 1000;
-  hfp_buf_acquire(info, dev.direction, &samples, &buffer_frames);
-  hfp_buf_release(info, dev.direction, buffer_frames);
+  hfp_buf_acquire(info, &dev, &samples, &buffer_frames);
+  hfp_buf_release(info, &dev, buffer_frames);
   ASSERT_GE(1000, buffer_frames);
 
   buffer_frames2 = 1000;
-  hfp_buf_acquire(info, dev.direction, &samples, &buffer_frames2);
-  hfp_buf_release(info, dev.direction, buffer_frames2);
+  hfp_buf_acquire(info, &dev, &samples, &buffer_frames2);
+  hfp_buf_release(info, &dev, buffer_frames2);
 
   ASSERT_GE(info->capture_buf->used_size / 2, buffer_frames + buffer_frames2);
 
@@ -166,19 +155,17 @@
   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);
+  info = hfp_info_create();
+  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.direction, dev.format));
+  ASSERT_EQ(0, hfp_info_add_iodev(info, &dev));
 
   /* Mock the sco fd and send some fake data */
   send(sock[0], sample, 48, 0);
@@ -186,21 +173,21 @@
   rc = hfp_read(info);
   ASSERT_EQ(48, rc);
 
-  rc = hfp_buf_queued(info, dev.direction);
+  rc = hfp_buf_queued(info, &dev);
   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.direction));
+  ASSERT_EQ(0, hfp_info_rm_iodev(info, &dev));
   dev.direction = CRAS_STREAM_OUTPUT;
-  ASSERT_EQ(0, hfp_info_add_iodev(info, dev.direction, dev.format));
+  ASSERT_EQ(0, hfp_info_add_iodev(info, &dev));
 
   /* Initial buffer is empty */
   rc = hfp_write(info);
@@ -224,12 +211,12 @@
 
   ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, sock));
 
-  info = hfp_info_create(HFP_CODEC_ID_CVSD);
-  ASSERT_NE(info, (void*)NULL);
+  info = hfp_info_create();
+  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));
@@ -247,30 +234,30 @@
 
   ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, sock));
 
-  info = hfp_info_create(HFP_CODEC_ID_CVSD);
-  ASSERT_NE(info, (void*)NULL);
+  info = hfp_info_create();
+  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.direction, dev.format));
+  ASSERT_EQ(0, hfp_info_add_iodev(info, &dev));
 
   /* Expect no data read, since no idev present at previous thread callback */
-  rc = hfp_buf_queued(info, dev.direction);
+  rc = hfp_buf_queued(info, &dev);
   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.direction);
+  rc = hfp_buf_queued(info, &dev);
   ASSERT_EQ(48 / 2, rc);
 
   /* Assert wait time is unchanged. */
@@ -288,251 +275,63 @@
   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);
+  info = hfp_info_create();
+  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);
-
-  /* Without odev in presence, zero packet should be sent. */
-  rc = recv(sock[0], sample, 48, 0);
-  ASSERT_EQ(48, rc);
+  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_EQ(0, hfp_info_add_iodev(info, &dev));
 
   /* Assert queued samples unchanged before output device added */
-  ASSERT_EQ(0, hfp_buf_queued(info, dev.direction));
+  ASSERT_EQ(0, hfp_buf_queued(info, &dev));
 
   /* 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.direction));
+  ASSERT_EQ(480, hfp_buf_queued(info, &dev));
 
   hfp_info_stop(info);
   hfp_info_destroy(info);
 }
 
-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
+} // 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) {}
-
-struct cras_msbc_plc* cras_msbc_plc_create() {
-  cras_msbc_plc_create_called++;
-  return NULL;
 }
 
-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 9bfb2dd..3e1dc2d 100644
--- a/cras/src/tests/hfp_iodev_unittest.cc
+++ b/cras/src/tests/hfp_iodev_unittest.cc
@@ -7,16 +7,15 @@
 
 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;
@@ -39,11 +38,7 @@
 static unsigned hfp_buf_acquire_return_val;
 static size_t hfp_buf_release_called;
 static unsigned hfp_buf_release_nwritten_val;
-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;
@@ -67,33 +62,33 @@
   hfp_buf_acquire_return_val = 0;
   hfp_buf_release_called = 0;
   hfp_buf_release_nwritten_val = 0;
-  hfp_fill_output_with_zeros_called = 0;
-  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);
@@ -127,7 +122,8 @@
 
 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 */
@@ -151,7 +147,8 @@
 
 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;
 
@@ -173,12 +170,13 @@
 }
 
 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);
 
@@ -195,192 +193,185 @@
   ASSERT_EQ(1, cras_iodev_free_resources_called);
 }
 
-TEST_F(HfpIodev, NoStreamState) {
-  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);
-  iodev->format = &fake_format;
-  iodev->configure_dev(iodev);
-  iodev->min_cb_level = iodev->buffer_size / 2;
-
-  hfp_buf_acquire_return_val = 100;
-  iodev->get_buffer(iodev, &area, &frames);
-  iodev->put_buffer(iodev, 100);
-
-  iodev->no_stream(iodev, 1);
-  ASSERT_EQ(1, hfp_fill_output_with_zeros_called);
-
-  iodev->no_stream(iodev, 0);
-  ASSERT_EQ(1, hfp_force_output_level_called);
-  ASSERT_EQ(fake_buffer_size / 2, hfp_force_output_level_target);
-
-  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)
+{
   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 sco_socket,
-                                   int codec) {
+int cras_bt_device_sco_mtu(struct cras_bt_device *device, int sco_socket)
+{
   return 48;
 }
-const char* cras_bt_device_object_path(const struct cras_bt_device* device) {
+void cras_bt_device_iodev_buffer_size_changed(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,
-                       enum CRAS_STREAM_DIRECTION direction,
-                       struct cras_audio_format* format) {
+int hfp_info_add_iodev(struct hfp_info *info, struct cras_iodev *dev)
+{
   hfp_info_add_iodev_called++;
   return 0;
 }
 
-int hfp_info_rm_iodev(struct hfp_info* info,
-                      enum CRAS_STREAM_DIRECTION direction) {
+int hfp_info_rm_iodev(struct hfp_info *info, struct cras_iodev *dev)
+{
   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 enum CRAS_STREAM_DIRECTION direction) {
+int hfp_buf_queued(struct hfp_info *info, const struct cras_iodev *dev)
+{
   return 0;
 }
 
-int hfp_buf_size(struct hfp_info* info, enum CRAS_STREAM_DIRECTION direction) {
-  return fake_buffer_size;
+int hfp_buf_size(struct hfp_info *info, struct cras_iodev *dev)
+{
+  /* 1008 / 2 */
+  return 504;
 }
 
-void hfp_buf_acquire(struct hfp_info* info,
-                     enum CRAS_STREAM_DIRECTION direction,
-                     uint8_t** buf,
-                     unsigned* count) {
+void hfp_buf_acquire(struct hfp_info *info,  struct cras_iodev *dev,
+		     uint8_t **buf, unsigned *count)
+{
   hfp_buf_acquire_called++;
   *count = hfp_buf_acquire_return_val;
 }
 
-void hfp_buf_release(struct hfp_info* info,
-                     enum CRAS_STREAM_DIRECTION direction,
-                     unsigned written_bytes) {
+void hfp_buf_release(struct hfp_info *info, struct cras_iodev *dev,
+		     unsigned written_bytes)
+{
   hfp_buf_release_called++;
   hfp_buf_release_nwritten_val = written_bytes;
 }
 
-int hfp_fill_output_with_zeros(struct hfp_info* info, unsigned int nframes) {
-  hfp_fill_output_with_zeros_called++;
-  return 0;
+void hfp_register_packet_size_changed_callback(struct hfp_info *info,
+                 void (*cb)(void *data),
+                 void *data)
+{
 }
 
-void hfp_force_output_level(struct hfp_info* info, unsigned int level) {
-  hfp_force_output_level_called++;
-  hfp_force_output_level_target = level;
+void hfp_unregister_packet_size_changed_callback(struct hfp_info *info,
+             void *data)
+{
 }
 
-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_resources(struct cras_iodev* iodev) {
-  cras_iodev_free_resources_called++;
+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_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)
+{
   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) {
-  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 f98a1f3..32749fd 100644
--- a/cras/src/tests/hfp_slc_unittest.cc
+++ b/cras/src/tests/hfp_slc_unittest.cc
@@ -5,31 +5,29 @@
 
 #include <gtest/gtest.h>
 #include <stdint.h>
-#include <stdio.h>
 #include <sys/socket.h>
 
+#include <stdio.h>
+
 extern "C" {
-#include "cras_bt_log.h"
-#include "cras_hfp_slc.h"
-#include "cras_telephony.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 void (*cras_tm_timer_cb)(struct cras_timer* t, void* data);
-static void* cras_tm_timer_cb_data;
+static struct cras_bt_device *device =
+    reinterpret_cast<struct cras_bt_device *>(2);
 
-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;
@@ -44,8 +42,8 @@
 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, device, slc_initialized_cb,
+                          slc_disconnected_cb);
   ASSERT_EQ(1, cras_system_add_select_fd_called);
   ASSERT_EQ(handle, slc_cb_data);
 
@@ -56,12 +54,12 @@
   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, device, slc_initialized_cb,
+                          slc_disconnected_cb);
 
   err = write(sock[1], "AT+CIND=?\r", 10);
   ASSERT_EQ(10, err);
@@ -70,16 +68,16 @@
 
   /* 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);
@@ -92,7 +90,7 @@
   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);
@@ -102,7 +100,7 @@
   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);
@@ -115,8 +113,8 @@
   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, 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]);
@@ -128,207 +126,64 @@
 
   hfp_slc_destroy(handle);
 }
+} // namespace
 
-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) {
+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;
-
 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() {
-  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) {
-  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
deleted file mode 100644
index f1c3fd7..0000000
--- a/cras/src/tests/input_data_unittest.cc
+++ /dev/null
@@ -1,104 +0,0 @@
-// 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>
-
-extern "C" {
-#include "buffer_share.c"
-#include "cras_audio_area.h"
-#include "cras_rstream.h"
-#include "input_data.h"
-}
-
-namespace {
-
-#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;
-#endif  // HAVE_WEBRTC_APM
-
-TEST(InputData, GetForInputStream) {
-  void* dev_ptr = reinterpret_cast<void*>(0x123);
-  struct input_data* data;
-  struct cras_rstream stream;
-  struct buffer_share* offsets;
-  struct cras_audio_area* area;
-  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);
-  data->ext.configure(&data->ext, 8192, 2, 48000);
-
-  // Prepare offsets data for 2 streams.
-  offsets = buffer_share_create(8192);
-  buffer_share_add_id(offsets, 111, NULL);
-  buffer_share_add_id(offsets, 222, NULL);
-  buffer_share_offset_update(offsets, 111, 2048);
-
-  dev_area.frames = 600;
-  data->area = &dev_area;
-
-  stream.apm_list = NULL;
-  input_data_get_for_stream(data, &stream, offsets, &area, &offset);
-
-  // 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;
-}
-int cras_apm_list_process(struct cras_apm* apm,
-                          struct float_buffer* input,
-                          unsigned int offset) {
-  cras_apm_list_process_called++;
-  cras_apm_list_process_offset_val = offset;
-  return 0;
-}
-
-struct cras_audio_area* cras_apm_list_get_processed(struct cras_apm* apm) {
-  return &apm_area;
-}
-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
-
-int main(int argc, char** argv) {
-  ::testing::InitGoogleTest(&argc, argv);
-  return RUN_ALL_TESTS();
-}
diff --git a/cras/src/tests/iodev_list_unittest.cc b/cras/src/tests/iodev_list_unittest.cc
index 798f295..26ebc8d 100644
--- a/cras/src/tests/iodev_list_unittest.cc
+++ b/cras/src/tests/iodev_list_unittest.cc
@@ -2,10 +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 <algorithm>
+#include <stdio.h>
+#include <gtest/gtest.h>
 #include <map>
 
 extern "C" {
@@ -24,56 +23,52 @@
 namespace {
 
 struct cras_server_state server_state_stub;
-struct cras_server_state* server_state_update_begin_return;
-int system_get_mute_return;
+struct cras_server_state *server_state_update_begin_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 unsigned int set_node_attr_called;
+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 cras_iodev_start_volume_ramp_called;
 static size_t cras_observer_add_called;
 static size_t cras_observer_remove_called;
 static size_t cras_observer_notify_nodes_called;
@@ -85,193 +80,179 @@
 static int cras_iodev_open_ret[8];
 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 struct cras_iodev *audio_thread_dev_start_ramp_dev;
 static int audio_thread_dev_start_ramp_called;
-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 enum CRAS_IODEV_RAMP_REQUEST audio_thread_dev_start_ramp_req ;
+static std::map<const struct cras_iodev*, enum CRAS_IODEV_STATE> cras_iodev_state_ret;
+static std::map<const struct cras_iodev*, int> cras_iodev_has_pinned_stream_ret;
+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;
+static int cras_iodev_is_zero_volume_ret;
 
-int dev_idx_in_vector(std::vector<unsigned int> v, unsigned int idx) {
-  return std::find(v.begin(), v.end(), idx) != v.end();
+void dummy_update_active_node(struct cras_iodev *iodev,
+                              unsigned node_idx,
+                              unsigned dev_enabled) {
 }
 
-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();
+  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;
+      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();
+      audio_thread_disconnect_stream_called = 0;
+      audio_thread_disconnect_stream_stream = NULL;
+      audio_thread_is_dev_open_ret = 0;
+      cras_iodev_has_pinned_stream_ret.clear();
 
-    sample_rates_[0] = 44100;
-    sample_rates_[1] = 48000;
-    sample_rates_[2] = 0;
+      sample_rates_[0] = 44100;
+      sample_rates_[1] = 48000;
+      sample_rates_[2] = 0;
 
-    channel_counts_[0] = 2;
-    channel_counts_[1] = 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(&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));
+      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_;
+      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_.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_;
+      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;
+      server_state_update_begin_return = &server_state_stub;
 
-    /* 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;
-  }
+      /* Reset stub data. */
+      add_stream_called = 0;
+      rm_stream_called = 0;
+      set_node_attr_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();
+      audio_thread_dev_start_ramp_dev = NULL;
+      audio_thread_dev_start_ramp_called = 0;
+      audio_thread_dev_start_ramp_req =
+          CRAS_IODEV_RAMP_REQUEST_UP_START_PLAYBACK;
+      cras_iodev_is_zero_volume_ret = 0;
 
-  virtual void TearDown() { cras_iodev_list_reset(); }
+      dummy_empty_iodev[0].state = CRAS_IODEV_STATE_CLOSE;
+      dummy_empty_iodev[1].state = CRAS_IODEV_STATE_CLOSE;
+    }
 
-  static void set_volume_1(struct cras_iodev* iodev) { set_volume_1_called_++; }
+    virtual void TearDown() {
+      cras_iodev_list_reset();
+    }
 
-  static void set_capture_gain_1(struct cras_iodev* iodev) {
-    set_capture_gain_1_called_++;
-  }
+    static void set_volume_1(struct cras_iodev* iodev) {
+      set_volume_1_called_++;
+    }
 
-  static void set_capture_mute_1(struct cras_iodev* iodev) {
-    set_capture_mute_1_called_++;
-  }
+    static void set_capture_gain_1(struct cras_iodev* iodev) {
+      set_capture_gain_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 set_capture_mute_1(struct cras_iodev* iodev) {
+      set_capture_mute_1_called_++;
+    }
 
-  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 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;
+    }
 
-  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_;
@@ -290,7 +271,7 @@
  * 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));
@@ -305,7 +286,7 @@
 
   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);
@@ -351,7 +332,7 @@
 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();
@@ -361,7 +342,7 @@
   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;
@@ -378,7 +359,7 @@
 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();
@@ -394,7 +375,7 @@
   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);
 
@@ -424,7 +405,7 @@
 
 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));
@@ -439,7 +420,7 @@
   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);
@@ -448,7 +429,7 @@
   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);
@@ -461,14 +442,14 @@
   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;
@@ -487,16 +468,16 @@
   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();
 }
@@ -504,7 +485,7 @@
 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();
@@ -514,9 +495,8 @@
   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;
   cras_iodev_open_ret[1] = 0;
   cras_tm_timer_cb = NULL;
@@ -526,11 +506,8 @@
   /* open dev called twice, one for fallback device. */
   EXPECT_EQ(2, cras_iodev_open_called);
   EXPECT_EQ(1, audio_thread_add_stream_called);
-  EXPECT_EQ(0, update_active_node_called);
-  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. */
@@ -542,7 +519,7 @@
   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_);
@@ -553,7 +530,7 @@
 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();
@@ -575,7 +552,7 @@
   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);
@@ -586,13 +563,15 @@
   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;
@@ -624,10 +603,10 @@
   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);
@@ -652,7 +631,7 @@
   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);
@@ -693,11 +672,11 @@
   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);
@@ -716,7 +695,7 @@
 
   // 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);
@@ -730,7 +709,7 @@
   // 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);
@@ -761,9 +740,9 @@
   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(1, update_active_node_called);
   EXPECT_EQ(&d2_, update_active_node_iodev_val[0]);
   EXPECT_EQ(1, update_active_node_node_idx_val[0]);
   EXPECT_EQ(1, update_active_node_dev_enabled_val[0]);
@@ -772,15 +751,15 @@
    * 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]);
-  EXPECT_EQ(&d1_, update_active_node_iodev_val[3]);
-  EXPECT_EQ(2, update_active_node_node_idx_val[2]);
-  EXPECT_EQ(0, update_active_node_node_idx_val[3]);
-  EXPECT_EQ(0, update_active_node_dev_enabled_val[2]);
-  EXPECT_EQ(1, update_active_node_dev_enabled_val[3]);
+  EXPECT_EQ(3, update_active_node_called);
+  EXPECT_EQ(&d2_, update_active_node_iodev_val[1]);
+  EXPECT_EQ(&d1_, update_active_node_iodev_val[2]);
+  EXPECT_EQ(2, update_active_node_node_idx_val[1]);
+  EXPECT_EQ(0, update_active_node_node_idx_val[2]);
+  EXPECT_EQ(0, update_active_node_dev_enabled_val[1]);
+  EXPECT_EQ(1, update_active_node_dev_enabled_val[2]);
   EXPECT_EQ(2, cras_observer_notify_active_node_called);
   cras_iodev_list_deinit();
 }
@@ -794,11 +773,12 @@
   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();
@@ -817,7 +797,7 @@
 
 // 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_);
@@ -856,6 +836,11 @@
 TEST_F(IoDevTestSuite, OutputMuteChangedToMute) {
   cras_iodev_list_init();
 
+  // d1_ and d3_ have ramp while d2_ does not have ramp.
+  d1_.ramp = reinterpret_cast<cras_ramp*>(0x123);
+  d2_.ramp = NULL;
+  d3_.ramp = reinterpret_cast<cras_ramp*>(0x124);
+
   cras_iodev_list_add_output(&d1_);
   cras_iodev_list_add_output(&d2_);
   cras_iodev_list_add_output(&d3_);
@@ -864,29 +849,70 @@
   cras_iodev_list_enable_dev(&d1_);
   cras_iodev_list_enable_dev(&d2_);
 
-  // Assume d1 and d2 devices are open.
-  d1_.state = CRAS_IODEV_STATE_OPEN;
-  d2_.state = CRAS_IODEV_STATE_OPEN;
-  d3_.state = CRAS_IODEV_STATE_CLOSE;
+  // Assume d1 and d2 devices are in normal run.
+  cras_iodev_state_ret[&d1_] = CRAS_IODEV_STATE_NORMAL_RUN;
+  cras_iodev_state_ret[&d2_] = CRAS_IODEV_STATE_NORMAL_RUN;
+  cras_iodev_state_ret[&d3_] = CRAS_IODEV_STATE_CLOSE;
 
   // Execute the callback.
   observer_ops->output_mute_changed(NULL, 0, 1, 0);
 
-  // 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));
+  // d1_ should set mute state through audio_thread_dev_start_ramp.
+  EXPECT_EQ(&d1_, audio_thread_dev_start_ramp_dev);
+  EXPECT_EQ(1, audio_thread_dev_start_ramp_called);
   EXPECT_EQ(CRAS_IODEV_RAMP_REQUEST_DOWN_MUTE, audio_thread_dev_start_ramp_req);
 
+  // d2_ should set mute state right away.
   // d3_ should set mute state right away without calling ramp
-  // because it is not open.
-  EXPECT_EQ(1, set_mute_called);
-  EXPECT_EQ(1, set_mute_dev_vector.size());
+  // because it is not enabled.
+  EXPECT_EQ(2, set_mute_called);
+  EXPECT_EQ(2, set_mute_dev_vector.size());
+  ASSERT_TRUE(device_in_vector(set_mute_dev_vector, &d2_));
   ASSERT_TRUE(device_in_vector(set_mute_dev_vector, &d3_));
 
+  // Assume d1_ should mute for volume.
+  // It should not use ramp.
+  cras_iodev_is_zero_volume_ret = 1;
+
+  // Clear stub data of interest.
+  audio_thread_dev_start_ramp_dev = NULL;
+  audio_thread_dev_start_ramp_called = 0;
+  set_mute_called = 0;
+  set_mute_dev_vector.clear();
+
+  // Execute the callback.
+  observer_ops->output_mute_changed(NULL, 0, 1, 0);
+
+  // Verify three devices all set mute state right away.
+  EXPECT_EQ(NULL, audio_thread_dev_start_ramp_dev);
+  EXPECT_EQ(0, audio_thread_dev_start_ramp_called);
+  EXPECT_EQ(3, set_mute_called);
+  EXPECT_EQ(3, set_mute_dev_vector.size());
+  ASSERT_TRUE(device_in_vector(set_mute_dev_vector, &d1_));
+  ASSERT_TRUE(device_in_vector(set_mute_dev_vector, &d2_));
+  ASSERT_TRUE(device_in_vector(set_mute_dev_vector, &d3_));
+
+  // Assume d1_ is changed to no_stream run state
+  // It should not use ramp.
+  cras_iodev_state_ret[&d1_] = CRAS_IODEV_STATE_NO_STREAM_RUN;
+
+  // Clear stub data of interest.
+  audio_thread_dev_start_ramp_dev = NULL;
+  audio_thread_dev_start_ramp_called = 0;
+  set_mute_called = 0;
+  set_mute_dev_vector.clear();
+
+  // Execute the callback.
+  observer_ops->output_mute_changed(NULL, 0, 1, 0);
+
+  // Verify three devices all set mute state right away.
+  EXPECT_EQ(NULL, audio_thread_dev_start_ramp_dev);
+  EXPECT_EQ(0, audio_thread_dev_start_ramp_called);
+  EXPECT_EQ(3, set_mute_called);
+  EXPECT_EQ(3, set_mute_dev_vector.size());
+  ASSERT_TRUE(device_in_vector(set_mute_dev_vector, &d1_));
+  ASSERT_TRUE(device_in_vector(set_mute_dev_vector, &d2_));
+  ASSERT_TRUE(device_in_vector(set_mute_dev_vector, &d3_));
   cras_iodev_list_deinit();
 }
 
@@ -894,6 +920,11 @@
 TEST_F(IoDevTestSuite, OutputMuteChangedToUnmute) {
   cras_iodev_list_init();
 
+  // d1_ and d3_ have ramp while d2_ does not have ramp.
+  d1_.ramp = reinterpret_cast<cras_ramp*>(0x123);
+  d2_.ramp = NULL;
+  d3_.ramp = reinterpret_cast<cras_ramp*>(0x124);
+
   cras_iodev_list_add_output(&d1_);
   cras_iodev_list_add_output(&d2_);
   cras_iodev_list_add_output(&d3_);
@@ -902,27 +933,71 @@
   cras_iodev_list_enable_dev(&d1_);
   cras_iodev_list_enable_dev(&d2_);
 
-  // Assume d1 and d2 devices are open.
-  d1_.state = CRAS_IODEV_STATE_OPEN;
-  d2_.state = CRAS_IODEV_STATE_CLOSE;
-  d3_.state = CRAS_IODEV_STATE_CLOSE;
+  // Assume d1 and d2 devices are in normal run.
+  cras_iodev_state_ret[&d1_] = CRAS_IODEV_STATE_NORMAL_RUN;
+  cras_iodev_state_ret[&d2_] = CRAS_IODEV_STATE_NORMAL_RUN;
+  cras_iodev_state_ret[&d3_] = CRAS_IODEV_STATE_CLOSE;
 
   // Execute the callback.
   observer_ops->output_mute_changed(NULL, 0, 0, 0);
 
   // d1_ should set mute state through audio_thread_dev_start_ramp.
+  EXPECT_EQ(&d1_, audio_thread_dev_start_ramp_dev);
   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);
+  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.
+  // d2_ should set mute state right away.
+  // d3_ should set mute state right away without calling ramp
+  // because it is not enabled.
   EXPECT_EQ(2, set_mute_called);
   EXPECT_EQ(2, set_mute_dev_vector.size());
   ASSERT_TRUE(device_in_vector(set_mute_dev_vector, &d2_));
   ASSERT_TRUE(device_in_vector(set_mute_dev_vector, &d3_));
 
+  // Assume d1_ should mute for volume.
+  // It should not use ramp.
+  cras_iodev_is_zero_volume_ret = 1;
+
+  // Clear stub data of interest.
+  audio_thread_dev_start_ramp_dev = NULL;
+  audio_thread_dev_start_ramp_called = 0;
+  set_mute_called = 0;
+  set_mute_dev_vector.clear();
+
+  // Execute the callback.
+  observer_ops->output_mute_changed(NULL, 0, 1, 0);
+
+  // Verify three devices all set mute state right away.
+  EXPECT_EQ(NULL, audio_thread_dev_start_ramp_dev);
+  EXPECT_EQ(0, audio_thread_dev_start_ramp_called);
+  EXPECT_EQ(3, set_mute_called);
+  EXPECT_EQ(3, set_mute_dev_vector.size());
+  ASSERT_TRUE(device_in_vector(set_mute_dev_vector, &d1_));
+  ASSERT_TRUE(device_in_vector(set_mute_dev_vector, &d2_));
+  ASSERT_TRUE(device_in_vector(set_mute_dev_vector, &d3_));
+
+  // Assume d1_ is changed to no_stream run state
+  // It should not use ramp.
+  cras_iodev_state_ret[&d1_] = CRAS_IODEV_STATE_NO_STREAM_RUN;
+
+  // Clear stub data of interest.
+  audio_thread_dev_start_ramp_dev = NULL;
+  audio_thread_dev_start_ramp_called = 0;
+  set_mute_called = 0;
+  set_mute_dev_vector.clear();
+
+  // Execute the callback.
+  observer_ops->output_mute_changed(NULL, 0, 1, 0);
+
+  // Verify three devices all set mute state right away.
+  EXPECT_EQ(NULL, audio_thread_dev_start_ramp_dev);
+  EXPECT_EQ(0, audio_thread_dev_start_ramp_called);
+  EXPECT_EQ(3, set_mute_called);
+  EXPECT_EQ(3, set_mute_dev_vector.size());
+  ASSERT_TRUE(device_in_vector(set_mute_dev_vector, &d1_));
+  ASSERT_TRUE(device_in_vector(set_mute_dev_vector, &d2_));
+  ASSERT_TRUE(device_in_vector(set_mute_dev_vector, &d3_));
   cras_iodev_list_deinit();
 }
 
@@ -934,12 +1009,12 @@
   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));
 
@@ -947,10 +1022,10 @@
   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));
@@ -958,7 +1033,7 @@
 
 // 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;
 
@@ -1044,7 +1119,7 @@
 
 // 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;
@@ -1101,6 +1176,7 @@
 
 // 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));
@@ -1112,6 +1188,7 @@
 
 // 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));
@@ -1132,7 +1209,7 @@
   rc = cras_iodev_list_set_node_attr(cras_make_node_id(0, 0),
                                      IONODE_ATTR_PLUGGED, 1);
   EXPECT_LE(rc, 0);
-  EXPECT_EQ(0, set_node_plugged_called);
+  EXPECT_EQ(0, set_node_attr_called);
 
   // Add two device, each with one node.
   d1_.direction = CRAS_STREAM_INPUT;
@@ -1145,93 +1222,19 @@
   rc = cras_iodev_list_set_node_attr(cras_make_node_id(d2_.info.idx, 1),
                                      IONODE_ATTR_PLUGGED, 1);
   EXPECT_LT(rc, 0);
-  EXPECT_EQ(0, set_node_plugged_called);
+  EXPECT_EQ(0, set_node_attr_called);
 
   // Mismatch id
   rc = cras_iodev_list_set_node_attr(cras_make_node_id(d1_.info.idx, 2),
                                      IONODE_ATTR_PLUGGED, 1);
   EXPECT_LT(rc, 0);
-  EXPECT_EQ(0, set_node_plugged_called);
+  EXPECT_EQ(0, set_node_attr_called);
 
   // Correct device id and node id
   rc = cras_iodev_list_set_node_attr(cras_make_node_id(d1_.info.idx, 1),
                                      IONODE_ATTR_PLUGGED, 1);
   EXPECT_EQ(rc, 0);
-  EXPECT_EQ(1, set_node_plugged_called);
-  cras_iodev_list_deinit();
-}
-
-TEST_F(IoDevTestSuite, SetNodeVolumeCaptureGain) {
-  int rc;
-
-  cras_iodev_list_init();
-
-  d1_.direction = CRAS_STREAM_OUTPUT;
-  rc = cras_iodev_list_add_output(&d1_);
-  ASSERT_EQ(0, rc);
-  node1.idx = 1;
-  node1.dev = &d1_;
-
-  // Do not ramp without software volume.
-  d1_.software_volume_needed = 0;
-  cras_iodev_list_set_node_attr(cras_make_node_id(d1_.info.idx, 1),
-                                IONODE_ATTR_VOLUME, 10);
-  EXPECT_EQ(1, cras_observer_notify_output_node_volume_called);
-  EXPECT_EQ(0, cras_iodev_start_volume_ramp_called);
-
-  // Even with software volume, device with NULL ramp won't trigger ramp start.
-  d1_.software_volume_needed = 1;
-  cras_iodev_list_set_node_attr(cras_make_node_id(d1_.info.idx, 1),
-                                IONODE_ATTR_VOLUME, 20);
-  EXPECT_EQ(2, cras_observer_notify_output_node_volume_called);
-  EXPECT_EQ(0, cras_iodev_start_volume_ramp_called);
-
-  // System mute prevents volume ramp from starting
-  system_get_mute_return = true;
-  cras_iodev_list_set_node_attr(cras_make_node_id(d1_.info.idx, 1),
-                                IONODE_ATTR_VOLUME, 20);
-  EXPECT_EQ(3, cras_observer_notify_output_node_volume_called);
-  EXPECT_EQ(0, cras_iodev_start_volume_ramp_called);
-
-  // Ramp starts only when it's non-NULL, software volume is used, and
-  // system is not muted
-  system_get_mute_return = false;
-  d1_.ramp = reinterpret_cast<struct cras_ramp*>(0x1);
-  cras_iodev_list_set_node_attr(cras_make_node_id(d1_.info.idx, 1),
-                                IONODE_ATTR_VOLUME, 20);
-  EXPECT_EQ(4, cras_observer_notify_output_node_volume_called);
-  EXPECT_EQ(1, cras_iodev_start_volume_ramp_called);
-
-  d1_.direction = CRAS_STREAM_INPUT;
-  cras_iodev_list_set_node_attr(cras_make_node_id(d1_.info.idx, 1),
-                                IONODE_ATTR_CAPTURE_GAIN, 15);
-  EXPECT_EQ(1, cras_observer_notify_input_node_gain_called);
-  cras_iodev_list_deinit();
-}
-
-TEST_F(IoDevTestSuite, SetNodeSwapLeftRight) {
-  int rc;
-
-  cras_iodev_list_init();
-
-  rc = cras_iodev_list_add_output(&d1_);
-  ASSERT_EQ(0, rc);
-  node1.idx = 1;
-  node1.dev = &d1_;
-
-  cras_iodev_list_set_node_attr(cras_make_node_id(d1_.info.idx, 1),
-                                IONODE_ATTR_SWAP_LEFT_RIGHT, 1);
-  EXPECT_EQ(1, set_swap_mode_for_node_called);
-  EXPECT_EQ(1, set_swap_mode_for_node_enable);
-  EXPECT_EQ(1, node1.left_right_swapped);
-  EXPECT_EQ(1, cras_observer_notify_node_left_right_swapped_called);
-
-  cras_iodev_list_set_node_attr(cras_make_node_id(d1_.info.idx, 1),
-                                IONODE_ATTR_SWAP_LEFT_RIGHT, 0);
-  EXPECT_EQ(2, set_swap_mode_for_node_called);
-  EXPECT_EQ(0, set_swap_mode_for_node_enable);
-  EXPECT_EQ(0, node1.left_right_swapped);
-  EXPECT_EQ(2, cras_observer_notify_node_left_right_swapped_called);
+  EXPECT_EQ(1, set_node_attr_called);
   cras_iodev_list_deinit();
 }
 
@@ -1255,7 +1258,7 @@
 
   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);
 
@@ -1303,7 +1306,7 @@
 
   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);
 
@@ -1375,8 +1378,8 @@
   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));
-  EXPECT_EQ(2, update_active_node_called);
+      cras_make_node_id(d1_.info.idx, 0));
+  EXPECT_EQ(1, update_active_node_called);
   EXPECT_EQ(&d1_, update_active_node_iodev_val[0]);
 
   d2_.direction = CRAS_STREAM_OUTPUT;
@@ -1389,43 +1392,36 @@
   rstream.pinned_dev_idx = d1_.info.idx;
 
   // Add pinned stream to d1.
-  update_active_node_called = 0;
   EXPECT_EQ(0, stream_add_cb(&rstream));
   EXPECT_EQ(1, audio_thread_add_stream_called);
   EXPECT_EQ(&d1_, audio_thread_add_stream_dev);
   EXPECT_EQ(&rstream, audio_thread_add_stream_stream);
-  EXPECT_EQ(1, update_active_node_called);
+  EXPECT_EQ(2, update_active_node_called);
   // Init d1_ because of pinned stream
-  EXPECT_EQ(&d1_, update_active_node_iodev_val[0]);
+  EXPECT_EQ(&d1_, update_active_node_iodev_val[1]);
 
   // Select d2, check pinned stream is not added to d2.
-  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);
+  EXPECT_EQ(4, update_active_node_called);
   // Unselect d1_ and select to d2_
-  EXPECT_EQ(&d2_, update_active_node_iodev_val[0]);
-  EXPECT_EQ(&dummy_empty_iodev[CRAS_STREAM_OUTPUT],
-            update_active_node_iodev_val[1]);
+  EXPECT_EQ(&d1_, update_active_node_iodev_val[2]);
+  EXPECT_EQ(&d2_, update_active_node_iodev_val[3]);
 
   // Remove pinned stream from d1, check d1 is closed after stream removed.
-  update_active_node_called = 0;
-  stream_list_has_pinned_stream_ret[d1_.info.idx] = 0;
   EXPECT_EQ(0, stream_rm_cb(&rstream));
   EXPECT_EQ(1, cras_iodev_close_called);
   EXPECT_EQ(&d1_, cras_iodev_close_dev);
-  EXPECT_EQ(1, update_active_node_called);
+  EXPECT_EQ(5, update_active_node_called);
   // close pinned device
-  EXPECT_EQ(&d1_, update_active_node_iodev_val[0]);
+  EXPECT_EQ(&d1_, update_active_node_iodev_val[4]);
 
   // Assume dev is already opened, add pin stream should not trigger another
   // update_active_node call, but will trigger audio_thread_add_stream.
   audio_thread_is_dev_open_ret = 1;
-  update_active_node_called = 0;
   EXPECT_EQ(0, stream_add_cb(&rstream));
-  EXPECT_EQ(0, update_active_node_called);
+  EXPECT_EQ(5, update_active_node_called);
   EXPECT_EQ(2, audio_thread_add_stream_called);
 
   cras_iodev_list_deinit();
@@ -1459,9 +1455,8 @@
 
   // 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.
-  stream_list_has_pinned_stream_ret[d1_.info.idx] = 0;
+  // Device has no pinned stream now. But this pinned stream remains in stream_list.
+  cras_iodev_has_pinned_stream_ret[&d1_] = 0;
 
   // Suspend
   observer_ops->suspend_changed(NULL, 1);
@@ -1490,7 +1485,7 @@
 
 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;
@@ -1535,7 +1530,7 @@
 
 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;
@@ -1573,27 +1568,9 @@
   cras_iodev_list_deinit();
 }
 
-TEST_F(IoDevTestSuite, GetSCOPCMIodevs) {
-  cras_iodev_list_init();
-
-  fake_sco_in_dev.direction = CRAS_STREAM_INPUT;
-  fake_sco_in_node.is_sco_pcm = 1;
-  cras_iodev_list_add_input(&fake_sco_in_dev);
-  fake_sco_out_dev.direction = CRAS_STREAM_OUTPUT;
-  fake_sco_out_node.is_sco_pcm = 1;
-  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));
-  EXPECT_EQ(&fake_sco_out_dev,
-            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();
 }
@@ -1602,139 +1579,183 @@
 
 // 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() {}
-
-int cras_system_get_mute() {
-  return system_get_mute_return;
+void cras_system_state_update_complete() {
 }
 
-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,
-                             enum CRAS_STREAM_DIRECTION dir,
-                             unsigned int dev_idx) {
+int audio_thread_rm_open_dev(struct audio_thread *thread,
+                               struct cras_iodev *dev)
+{
   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,
+void set_node_volume(struct cras_ionode *node, int value)
+{
+  struct cras_iodev *dev = node->dev;
+  unsigned int volume;
+
+  if (dev->direction != CRAS_STREAM_OUTPUT)
+    return;
+
+  volume = (unsigned int)std::min(value, 100);
+  node->volume = volume;
+  if (dev->set_volume)
+    dev->set_volume(dev);
+
+  cras_iodev_list_notify_node_volume(node);
+}
+
+int cras_iodev_set_node_attr(struct cras_ionode *ionode,
+                             enum ionode_attr attr, int value)
+{
+  set_node_attr_called++;
+
+  switch (attr) {
+  case IONODE_ATTR_PLUGGED:
+    // plug_node(ionode, value);
+    break;
+  case IONODE_ATTR_VOLUME:
+    set_node_volume(ionode, value);
+    break;
+  case IONODE_ATTR_CAPTURE_GAIN:
+    // set_node_capture_gain(ionode, value);
+    break;
+  default:
+    return -EINVAL;
+  }
+
+  return 0;
+}
+
+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 {
     dev = &dummy_empty_iodev[direction];
   }
   dev->direction = direction;
+  dev->update_active_node = dummy_update_active_node;
   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;
 }
 
@@ -1744,93 +1765,102 @@
   return 0;
 }
 
-void cras_iodev_set_node_plugged(struct cras_ionode* node, int plugged) {
-  set_node_plugged_called++;
+int cras_iodev_is_zero_volume(const struct cras_iodev *iodev)
+{
+  return cras_iodev_is_zero_volume_ret;
 }
 
-int cras_iodev_start_volume_ramp(struct cras_iodev* odev,
-                                 unsigned int old_volume,
-                                 unsigned int new_volume) {
-  cras_iodev_start_volume_ramp_called++;
-  return 0;
+enum CRAS_IODEV_STATE cras_iodev_state(const struct cras_iodev *iodev)
+{
+	return cras_iodev_state_ret[iodev];
 }
 
-bool stream_list_has_pinned_stream(struct stream_list* list,
-                                   unsigned int dev_idx) {
-  return stream_list_has_pinned_stream_ret[dev_idx];
+int cras_iodev_has_pinned_stream(const struct cras_iodev *dev)
+{
+  return cras_iodev_has_pinned_stream_ret[dev];
 }
 
-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) {}
-
-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);
+void cras_channel_remix_convert(struct cras_fmt_conv *conv,
+    uint8_t *in_buf, size_t frames)
+{
 }
 
-void cras_observer_remove(struct cras_observer_client* client) {
+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);
+}
+
+void cras_observer_remove(struct cras_observer_client *client)
+{
   if (observer_ops)
     free(observer_ops);
   cras_observer_remove_called++;
@@ -1841,48 +1871,57 @@
 }
 
 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,
-                                unsigned int dev_idx,
-                                enum CRAS_IODEV_RAMP_REQUEST request) {
+int audio_thread_dev_start_ramp(struct audio_thread *thread,
+                                struct cras_iodev *dev,
+                                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_dev = dev;
   audio_thread_dev_start_ramp_req = request;
   return 0;
 }
 
 #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 25d59da..519c3f0 100644
--- a/cras/src/tests/iodev_stub.cc
+++ b/cras/src/tests/iodev_stub.cc
@@ -4,61 +4,43 @@
  */
 
 #include <time.h>
-
 #include <unordered_map>
 
 extern "C" {
 #include "cras_iodev.h"
-#include "dev_stream.h"
-#include "utlist.h"
 }
 
 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
+  struct cb_data {
+    int frames_queued_ret;
+    timespec frames_queued_ts;
+  };
+  std::unordered_map<cras_iodev*, cb_data> data_map;
+} // namespace
 
 void iodev_stub_reset() {
-  frames_queued_map.clear();
-  valid_frames_map.clear();
-  drop_time_map.clear();
+  data_map.clear();
 }
 
 void iodev_stub_frames_queued(cras_iodev* iodev, int ret, timespec ts) {
-  cb_data data = {ret, ts};
-  frames_queued_map.insert({iodev, data});
-}
-
-void iodev_stub_valid_frames(cras_iodev* iodev, int ret, timespec ts) {
-  cb_data data = {ret, 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;
+  cb_data data = { ret, ts };
+  data_map.insert({iodev, data});
 }
 
 extern "C" {
 
-int cras_iodev_add_stream(struct cras_iodev* iodev, struct dev_stream* stream) {
-  DL_APPEND(iodev->streams, stream);
+double cras_iodev_get_est_rate_ratio(const struct cras_iodev *iodev) {
+  return 48000.0;
+}
+
+int cras_iodev_get_dsp_delay(const struct cras_iodev *iodev) {
   return 0;
 }
 
-int cras_iodev_get_valid_frames(struct cras_iodev* iodev,
-                                struct timespec* tstamp) {
-  auto elem = valid_frames_map.find(iodev);
-  if (elem != valid_frames_map.end()) {
+int cras_iodev_frames_queued(struct cras_iodev *iodev,
+                             struct timespec *tstamp) {
+  auto elem = data_map.find(iodev);
+  if (elem != data_map.end()) {
     *tstamp = elem->second.frames_queued_ts;
     return elem->second.frames_queued_ret;
   }
@@ -66,91 +48,72 @@
   return 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) {
-  return 0;
-}
-
-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;
-    return elem->second.frames_queued_ret;
-  }
-  clock_gettime(CLOCK_MONOTONIC_RAW, tstamp);
-  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) {
-  return iodev->state;
+enum CRAS_IODEV_STATE cras_iodev_state(const struct cras_iodev *iodev) {
+  return CRAS_IODEV_STATE_OPEN;
 }
 
-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) {
+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) {
   return 0;
 }
 
-int cras_iodev_buffer_avail(struct cras_iodev* iodev, unsigned hw_level) {
+unsigned int cras_iodev_max_stream_offset(const struct cras_iodev *iodev) {
   return 0;
 }
 
-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;
 }
 
@@ -158,32 +121,28 @@
   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_start_stream(struct cras_iodev* iodev,
-                             struct dev_stream* stream) {}
-
-int cras_iodev_drop_frames_by_time(struct cras_iodev* iodev,
-                                   struct timespec ts) {
-  drop_time_map.insert({iodev, ts});
-  return 0;
+void cras_iodev_update_highest_hw_level(struct cras_iodev *iodev,
+		unsigned int hw_level)
+{
 }
-}  // extern "C"
+
+} // extern "C"
diff --git a/cras/src/tests/iodev_stub.h b/cras/src/tests/iodev_stub.h
index dde1b9f..b1c4745 100644
--- a/cras/src/tests/iodev_stub.h
+++ b/cras/src/tests/iodev_stub.h
@@ -12,8 +12,4 @@
 
 void iodev_stub_frames_queued(cras_iodev* iodev, int ret, timespec ts);
 
-void iodev_stub_valid_frames(cras_iodev* iodev, int ret, timespec ts);
-
-bool iodev_stub_get_drop_time(cras_iodev* iodev, timespec* ts);
-
-#endif  // IODEV_STUB_H_
+#endif // IODEV_STUB_H_
diff --git a/cras/src/tests/iodev_unittest.cc b/cras/src/tests/iodev_unittest.cc
index 61f8f69..f022164 100644
--- a/cras/src/tests/iodev_unittest.cc
+++ b/cras/src/tests/iodev_unittest.cc
@@ -2,25 +2,21 @@
 // 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 <gtest/gtest.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 "input_data.h"
 #include "utlist.h"
+#include "cras_audio_area.h"
+#include "audio_thread_log.h"
+#include "input_data.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
@@ -28,20 +24,24 @@
 static const float RAMP_UNMUTE_DURATION_SECS = 0.5;
 static const float RAMP_NEW_STREAM_DURATION_SECS = 0.01;
 static const float RAMP_MUTE_DURATION_SECS = 0.1;
-static const float RAMP_VOLUME_CHANGE_DURATION_SECS = 0.1;
 
 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 size_t notify_node_volume_called;
+static size_t notify_node_capture_gain_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;
+static int  set_swap_mode_for_node_called;
+static int  set_swap_mode_for_node_enable;
+static int notify_node_left_right_swapped_called;
 static int cras_audio_format_set_channel_layout_called;
 static unsigned int cras_system_get_volume_return;
 static int cras_dsp_get_pipeline_called;
@@ -58,7 +58,7 @@
 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;
@@ -67,21 +67,22 @@
 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 output_should_wake_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;
@@ -89,9 +90,7 @@
 static int device_monitor_reset_device_called;
 static int output_underrun_called;
 static int set_mute_called;
-static int cras_ramp_start_mute_ramp;
-static float cras_ramp_start_from;
-static float cras_ramp_start_to;
+static int cras_ramp_start_is_up;
 static int cras_ramp_start_duration_frames;
 static int cras_ramp_start_is_called;
 static int cras_ramp_reset_is_called;
@@ -100,37 +99,47 @@
 static cras_ramp_cb cras_ramp_start_cb;
 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 struct cras_iodev* cras_device_monitor_set_device_mute_state_dev;
 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;
-static float cras_scale_buffer_increment_target;
 static int cras_scale_buffer_increment_channel;
 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 double rate_estimator_get_rate_ret;
-
-static char* atlog_name;
+static struct input_data *input_data_create_ret;
 
 // 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;
 }
 
+// Iodev callback
+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;
+}
+
 void ResetStubData() {
   cras_iodev_list_disable_dev_called = 0;
   select_node_called = 0;
   notify_nodes_changed_called = 0;
   notify_active_node_changed_called = 0;
+  notify_node_volume_called = 0;
+  notify_node_capture_gain_called = 0;
   dsp_context_new_sample_rate = 0;
   dsp_context_new_purpose = NULL;
   dsp_context_free_called = 0;
+  set_swap_mode_for_node_called = 0;
+  set_swap_mode_for_node_enable = 0;
+  notify_node_left_right_swapped_called = 0;
   cras_audio_format_set_channel_layout_called = 0;
   cras_dsp_get_pipeline_called = 0;
   cras_dsp_get_pipeline_ret = 0;
@@ -157,8 +166,7 @@
   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));
@@ -167,27 +175,19 @@
     audio_area = NULL;
   }
   put_buffer_nframes = 0;
-  is_free_running_ret = 0;
+  output_should_wake_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) {
-    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);
-  }
+  if (!atlog)
+    atlog = audio_thread_event_log_init();
   get_num_underruns_ret = 0;
   device_monitor_reset_device_called = 0;
   output_underrun_called = 0;
   set_mute_called = 0;
-  cras_ramp_start_mute_ramp = 0;
-  cras_ramp_start_from = 0.0;
-  cras_ramp_start_to = 0.0;
+  cras_ramp_start_is_up = 0;
   cras_ramp_start_duration_frames = 0;
   cras_ramp_start_cb = NULL;
   cras_ramp_start_cb_data = NULL;
@@ -196,21 +196,19 @@
   cras_ramp_get_current_action_ret.type = CRAS_RAMP_ACTION_NONE;
   cras_ramp_update_ramped_frames_num_frames = 0;
   cras_device_monitor_set_device_mute_state_called = 0;
-  cras_device_monitor_set_device_mute_state_dev_idx = 0;
+  cras_device_monitor_set_device_mute_state_dev = NULL;
   cras_scale_buffer_called = 0;
   cras_scale_buffer_increment_fmt = SND_PCM_FORMAT_UNKNOWN;
   cras_scale_buffer_increment_buff = NULL;
   cras_scale_buffer_increment_frame = 0;
   cras_scale_buffer_increment_scaler = 0;
   cras_scale_buffer_increment_increment = 0;
-  cras_scale_buffer_increment_target = 0.0;
   cras_scale_buffer_increment_channel = 0;
   audio_fmt.format = SND_PCM_FORMAT_S16_LE;
   audio_fmt.frame_rate = 48000;
   audio_fmt.num_channels = 2;
   buffer_share_add_id_called = 0;
   ext_mod_configure_called = 0;
-  rate_estimator_get_rate_ret = 0;
 }
 
 namespace {
@@ -243,40 +241,42 @@
 }
 
 class IoDevSetFormatTestSuite : public testing::Test {
- protected:
-  virtual void SetUp() {
-    ResetStubData();
-    sample_rates_[0] = 44100;
-    sample_rates_[1] = 48000;
-    sample_rates_[2] = 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;
+      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);
+      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;
+      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;
+      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;
-  }
+      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) {
@@ -290,9 +290,9 @@
   ResetStubData();
   rc = cras_iodev_set_format(&iodev_, &fmt);
   EXPECT_EQ(0, rc);
-  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.format->format);
-  EXPECT_EQ(48000, iodev_.format->frame_rate);
-  EXPECT_EQ(2, iodev_.format->num_channels);
+  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.ext_format->format);
+  EXPECT_EQ(48000, iodev_.ext_format->frame_rate);
+  EXPECT_EQ(2, iodev_.ext_format->num_channels);
   EXPECT_EQ(dsp_context_new_sample_rate, 48000);
   EXPECT_STREQ(dsp_context_new_purpose, "playback");
 }
@@ -308,9 +308,9 @@
   ResetStubData();
   rc = cras_iodev_set_format(&iodev_, &fmt);
   EXPECT_EQ(0, rc);
-  EXPECT_EQ(SND_PCM_FORMAT_S32_LE, iodev_.format->format);
-  EXPECT_EQ(48000, iodev_.format->frame_rate);
-  EXPECT_EQ(2, iodev_.format->num_channels);
+  EXPECT_EQ(SND_PCM_FORMAT_S32_LE, iodev_.ext_format->format);
+  EXPECT_EQ(48000, iodev_.ext_format->frame_rate);
+  EXPECT_EQ(2, iodev_.ext_format->num_channels);
   EXPECT_EQ(dsp_context_new_sample_rate, 48000);
   EXPECT_STREQ(dsp_context_new_purpose, "playback");
 }
@@ -326,9 +326,9 @@
   ResetStubData();
   rc = cras_iodev_set_format(&iodev_, &fmt);
   EXPECT_EQ(0, rc);
-  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.format->format);
-  EXPECT_EQ(44100, iodev_.format->frame_rate);
-  EXPECT_EQ(2, iodev_.format->num_channels);
+  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.ext_format->format);
+  EXPECT_EQ(44100, iodev_.ext_format->frame_rate);
+  EXPECT_EQ(2, iodev_.ext_format->num_channels);
   EXPECT_EQ(dsp_context_new_sample_rate, 44100);
   EXPECT_STREQ(dsp_context_new_purpose, "capture");
 }
@@ -342,9 +342,9 @@
   fmt.num_channels = 2;
   rc = cras_iodev_set_format(&iodev_, &fmt);
   EXPECT_EQ(0, rc);
-  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.format->format);
-  EXPECT_EQ(48000, iodev_.format->frame_rate);
-  EXPECT_EQ(2, iodev_.format->num_channels);
+  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.ext_format->format);
+  EXPECT_EQ(48000, iodev_.ext_format->frame_rate);
+  EXPECT_EQ(2, iodev_.ext_format->num_channels);
 }
 
 TEST_F(IoDevSetFormatTestSuite, Supported96k) {
@@ -360,9 +360,9 @@
   fmt.num_channels = 2;
   rc = cras_iodev_set_format(&iodev_, &fmt);
   EXPECT_EQ(0, rc);
-  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.format->format);
-  EXPECT_EQ(96000, iodev_.format->frame_rate);
-  EXPECT_EQ(2, iodev_.format->num_channels);
+  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.ext_format->format);
+  EXPECT_EQ(96000, iodev_.ext_format->frame_rate);
+  EXPECT_EQ(2, iodev_.ext_format->num_channels);
 }
 
 TEST_F(IoDevSetFormatTestSuite, LimitLowRate) {
@@ -378,9 +378,9 @@
   fmt.num_channels = 2;
   rc = cras_iodev_set_format(&iodev_, &fmt);
   EXPECT_EQ(0, rc);
-  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.format->format);
-  EXPECT_EQ(48000, iodev_.format->frame_rate);
-  EXPECT_EQ(2, iodev_.format->num_channels);
+  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.ext_format->format);
+  EXPECT_EQ(48000, iodev_.ext_format->frame_rate);
+  EXPECT_EQ(2, iodev_.ext_format->num_channels);
 }
 
 TEST_F(IoDevSetFormatTestSuite, UnsupportedChannelCount) {
@@ -392,9 +392,9 @@
   fmt.num_channels = 1;
   rc = cras_iodev_set_format(&iodev_, &fmt);
   EXPECT_EQ(0, rc);
-  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.format->format);
-  EXPECT_EQ(48000, iodev_.format->frame_rate);
-  EXPECT_EQ(2, iodev_.format->num_channels);
+  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.ext_format->format);
+  EXPECT_EQ(48000, iodev_.ext_format->frame_rate);
+  EXPECT_EQ(2, iodev_.ext_format->num_channels);
 }
 
 TEST_F(IoDevSetFormatTestSuite, SupportedFormatFallbackDefault) {
@@ -406,9 +406,53 @@
   fmt.num_channels = 2;
   rc = cras_iodev_set_format(&iodev_, &fmt);
   EXPECT_EQ(0, rc);
-  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.format->format);
-  EXPECT_EQ(44100, iodev_.format->frame_rate);
-  EXPECT_EQ(2, iodev_.format->num_channels);
+  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.ext_format->format);
+  EXPECT_EQ(44100, iodev_.ext_format->frame_rate);
+  EXPECT_EQ(2, iodev_.ext_format->num_channels);
+}
+
+TEST_F(IoDevSetFormatTestSuite, OutputDSPChannleReduction) {
+  struct cras_audio_format fmt;
+  int rc;
+
+  fmt.format = SND_PCM_FORMAT_S16_LE;
+  fmt.frame_rate = 48000;
+  fmt.num_channels = 2;
+
+  iodev_.direction = CRAS_STREAM_OUTPUT;
+  iodev_.supported_channel_counts[0] = 1;
+  iodev_.supported_channel_counts[1] = 0;
+  cras_dsp_context_new_return = reinterpret_cast<cras_dsp_context *>(0xf00);
+  cras_dsp_get_pipeline_ret =  0xf01;
+  cras_dsp_num_input_channels_return = 2;
+  cras_dsp_num_output_channels_return = 1;
+  rc = cras_iodev_set_format(&iodev_, &fmt);
+  EXPECT_EQ(0, rc);
+  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.ext_format->format);
+  EXPECT_EQ(48000, iodev_.ext_format->frame_rate);
+  EXPECT_EQ(2, iodev_.ext_format->num_channels);
+}
+
+TEST_F(IoDevSetFormatTestSuite, InputDSPChannleReduction) {
+  struct cras_audio_format fmt;
+  int rc;
+
+  fmt.format = SND_PCM_FORMAT_S16_LE;
+  fmt.frame_rate = 48000;
+  fmt.num_channels = 2;
+
+  iodev_.direction = CRAS_STREAM_INPUT;
+  iodev_.supported_channel_counts[0] = 10;
+  iodev_.supported_channel_counts[1] = 0;
+  cras_dsp_context_new_return = reinterpret_cast<cras_dsp_context *>(0xf00);
+  cras_dsp_get_pipeline_ret =  0xf01;
+  cras_dsp_num_input_channels_return = 10;
+  cras_dsp_num_output_channels_return = 2;
+  rc = cras_iodev_set_format(&iodev_, &fmt);
+  EXPECT_EQ(0, rc);
+  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.ext_format->format);
+  EXPECT_EQ(48000, iodev_.ext_format->frame_rate);
+  EXPECT_EQ(2, iodev_.ext_format->num_channels);
 }
 
 TEST_F(IoDevSetFormatTestSuite, UpdateChannelLayoutSuccess) {
@@ -424,14 +468,14 @@
 
   rc = cras_iodev_set_format(&iodev_, &fmt);
   EXPECT_EQ(0, rc);
-  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.format->format);
-  EXPECT_EQ(48000, iodev_.format->frame_rate);
-  EXPECT_EQ(6, iodev_.format->num_channels);
+  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.ext_format->format);
+  EXPECT_EQ(48000, iodev_.ext_format->frame_rate);
+  EXPECT_EQ(6, iodev_.ext_format->num_channels);
 }
 
 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;
 
@@ -439,7 +483,7 @@
   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;
@@ -447,17 +491,19 @@
 
   rc = cras_iodev_set_format(&iodev_, &fmt);
   EXPECT_EQ(0, rc);
-  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.format->format);
-  EXPECT_EQ(48000, iodev_.format->frame_rate);
-  EXPECT_EQ(2, iodev_.format->num_channels);
+  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.ext_format->format);
+  EXPECT_EQ(48000, iodev_.ext_format->frame_rate);
+  EXPECT_EQ(2, iodev_.ext_format->num_channels);
   EXPECT_EQ(0, dsp_context_free_called);
-  for (i = 0; i < CRAS_CH_MAX; i++)
+  for (i = 0; i < CRAS_CH_MAX; i++) {
     EXPECT_EQ(iodev_.format->channel_layout[i], stereo_layout[i]);
+    EXPECT_EQ(iodev_.ext_format->channel_layout[i], stereo_layout[i]);
+  }
 }
 
 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;
 
@@ -465,7 +511,7 @@
   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;
@@ -473,19 +519,20 @@
 
   rc = cras_iodev_set_format(&iodev_, &fmt);
   EXPECT_EQ(0, rc);
-  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.format->format);
-  EXPECT_EQ(48000, iodev_.format->frame_rate);
-  EXPECT_EQ(6, iodev_.format->num_channels);
+  EXPECT_EQ(SND_PCM_FORMAT_S16_LE, iodev_.ext_format->format);
+  EXPECT_EQ(48000, iodev_.ext_format->frame_rate);
+  EXPECT_EQ(6, iodev_.ext_format->num_channels);
   EXPECT_EQ(0, dsp_context_free_called);
-  for (i = 0; i < CRAS_CH_MAX; i++)
+  for (i = 0; i < CRAS_CH_MAX; i++) {
     EXPECT_EQ(iodev_.format->channel_layout[i], default_6ch_layout[i]);
+    EXPECT_EQ(iodev_.ext_format->channel_layout[i], default_6ch_layout[i]);
+  }
 }
 
 // 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);
@@ -502,7 +549,8 @@
   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);
@@ -511,45 +559,41 @@
   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) {
-  return is_free_running_ret;
+static int output_should_wake(const struct cras_iodev *odev)
+{
+  return output_should_wake_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) {
-  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();
@@ -561,7 +605,6 @@
   fmt.num_channels = 2;
   iodev.format = &fmt;
   iodev.put_buffer = put_buffer;
-  iodev.rate_est = reinterpret_cast<struct rate_estimator*>(0xdeadbeef);
 
   rc = cras_iodev_put_output_buffer(&iodev, frames, 20, NULL, nullptr);
   EXPECT_EQ(0, rc);
@@ -607,7 +650,7 @@
   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();
@@ -624,7 +667,6 @@
   fmt.num_channels = 2;
   iodev.format = &fmt;
   iodev.put_buffer = put_buffer;
-  iodev.rate_est = reinterpret_cast<struct rate_estimator*>(0xdeadbeef);
 
   rc = cras_iodev_put_output_buffer(&iodev, frames, 20, NULL, nullptr);
   EXPECT_EQ(0, rc);
@@ -636,7 +678,7 @@
 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();
@@ -651,7 +693,6 @@
 
   // Assume device has ramp member.
   iodev.ramp = reinterpret_cast<struct cras_ramp*>(0x1);
-  iodev.rate_est = reinterpret_cast<struct rate_estimator*>(0xdeadbeef);
 
   // Assume ramping is done.
   cras_ramp_get_current_action_ret.type = CRAS_RAMP_ACTION_NONE;
@@ -681,7 +722,7 @@
   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();
@@ -698,7 +739,6 @@
   fmt.num_channels = 2;
   iodev.format = &fmt;
   iodev.put_buffer = put_buffer;
-  iodev.rate_est = reinterpret_cast<struct rate_estimator*>(0xdeadbeef);
 
   // Assume device has ramp member.
   iodev.ramp = reinterpret_cast<struct cras_ramp*>(0x1);
@@ -729,7 +769,7 @@
   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();
@@ -746,7 +786,6 @@
   fmt.num_channels = 2;
   iodev.format = &fmt;
   iodev.put_buffer = put_buffer;
-  iodev.rate_est = reinterpret_cast<struct rate_estimator*>(0xdeadbeef);
 
   rc = cras_iodev_put_output_buffer(&iodev, frames, 22, NULL, nullptr);
   EXPECT_EQ(0, rc);
@@ -758,10 +797,8 @@
 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;
 
   ResetStubData();
   memset(&iodev, 0, sizeof(iodev));
@@ -773,26 +810,17 @@
   fmt.num_channels = 2;
   iodev.format = &fmt;
   iodev.put_buffer = put_buffer;
-  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;
-  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;
-  DL_APPEND(iodev.loopbacks, &post_dsp);
+  cras_iodev_register_pre_dsp_hook(&iodev, pre_dsp_hook, (void *)0x1234);
+  cras_iodev_register_post_dsp_hook(&iodev, post_dsp_hook, (void *)0x5678);
 
   rc = cras_iodev_put_output_buffer(&iodev, frames, 32, NULL, nullptr);
   EXPECT_EQ(0, rc);
   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);
@@ -802,7 +830,7 @@
 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();
@@ -814,7 +842,6 @@
   fmt.num_channels = 2;
   iodev.format = &fmt;
   iodev.put_buffer = put_buffer;
-  iodev.rate_est = reinterpret_cast<struct rate_estimator*>(0xdeadbeef);
 
   cras_system_get_volume_return = 13;
   softvol_scalers[13] = 0.435;
@@ -831,12 +858,11 @@
 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;
   float increment = 0.001;
-  float target = 1.0;
   int volume = 13;
   float volume_scaler = 0.435;
 
@@ -851,7 +877,6 @@
   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);
 
   // Assume ramping is done.
   cras_ramp_get_current_action_ret.type = CRAS_RAMP_ACTION_NONE;
@@ -872,7 +897,6 @@
   cras_ramp_get_current_action_ret.type = CRAS_RAMP_ACTION_PARTIAL;
   cras_ramp_get_current_action_ret.scaler = ramp_scaler;
   cras_ramp_get_current_action_ret.increment = increment;
-  cras_ramp_get_current_action_ret.target = target;
 
   cras_system_get_volume_return = volume;
   softvol_scalers[volume] = volume_scaler;
@@ -895,8 +919,6 @@
   // ramp increment.
   EXPECT_FLOAT_EQ(softvol_scalers[volume] * increment,
                   cras_scale_buffer_increment_increment);
-  EXPECT_FLOAT_EQ(softvol_scalers[volume] * target,
-                  cras_scale_buffer_increment_target);
   EXPECT_EQ(fmt.num_channels, cras_scale_buffer_increment_channel);
 
   EXPECT_EQ(n_frames, put_buffer_nframes);
@@ -906,12 +928,11 @@
 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;
   float increment = 0.001;
-  float target = 1.0;
 
   ResetStubData();
   memset(&iodev, 0, sizeof(iodev));
@@ -924,7 +945,6 @@
   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);
 
   // Assume ramping is done.
   cras_ramp_get_current_action_ret.type = CRAS_RAMP_ACTION_NONE;
@@ -942,7 +962,6 @@
   cras_ramp_get_current_action_ret.type = CRAS_RAMP_ACTION_PARTIAL;
   cras_ramp_get_current_action_ret.scaler = ramp_scaler;
   cras_ramp_get_current_action_ret.increment = increment;
-  cras_ramp_get_current_action_ret.target = target;
 
   rc = cras_iodev_put_output_buffer(&iodev, frames, n_frames, NULL, nullptr);
   EXPECT_EQ(0, rc);
@@ -956,7 +975,6 @@
   EXPECT_EQ(n_frames, cras_scale_buffer_increment_frame);
   EXPECT_FLOAT_EQ(ramp_scaler, cras_scale_buffer_increment_scaler);
   EXPECT_FLOAT_EQ(increment, cras_scale_buffer_increment_increment);
-  EXPECT_FLOAT_EQ(1.0, cras_scale_buffer_increment_target);
   EXPECT_EQ(fmt.num_channels, cras_scale_buffer_increment_channel);
 
   EXPECT_EQ(n_frames, put_buffer_nframes);
@@ -966,7 +984,7 @@
 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();
@@ -981,7 +999,6 @@
   fmt.num_channels = 2;
   iodev.format = &fmt;
   iodev.put_buffer = put_buffer;
-  iodev.rate_est = reinterpret_cast<struct rate_estimator*>(0xdeadbeef);
 
   rc = cras_iodev_put_output_buffer(&iodev, frames, 53, NULL, nullptr);
   EXPECT_EQ(0, rc);
@@ -995,8 +1012,9 @@
 
 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;
 }
@@ -1046,11 +1064,22 @@
   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_volume(struct cras_iodev *iodev)
+{
+}
+
+static void dev_set_capture_gain(struct cras_iodev *iodev)
+{
+}
+
+static void dev_set_mute(struct cras_iodev *iodev)
+{
   set_mute_called++;
 }
 
@@ -1069,15 +1098,15 @@
   cras_iodev_add_node(&iodev, &ionode2);
   cras_iodev_set_active_node(&iodev, &ionode);
   ResetStubData();
-  cras_iodev_set_node_plugged(&ionode, 1);
+  cras_iodev_set_node_attr(&ionode, IONODE_ATTR_PLUGGED, 1);
   EXPECT_EQ(0, cras_iodev_list_disable_dev_called);
-  cras_iodev_set_node_plugged(&ionode, 0);
+  cras_iodev_set_node_attr(&ionode, IONODE_ATTR_PLUGGED, 0);
   EXPECT_EQ(1, cras_iodev_list_disable_dev_called);
 
   /* Unplug non-active node shouldn't disable iodev. */
-  cras_iodev_set_node_plugged(&ionode2, 1);
+  cras_iodev_set_node_attr(&ionode2, IONODE_ATTR_PLUGGED, 1);
   EXPECT_EQ(1, cras_iodev_list_disable_dev_called);
-  cras_iodev_set_node_plugged(&ionode2, 0);
+  cras_iodev_set_node_attr(&ionode2, IONODE_ATTR_PLUGGED, 0);
   EXPECT_EQ(1, cras_iodev_list_disable_dev_called);
 }
 
@@ -1107,6 +1136,44 @@
   EXPECT_EQ(1, notify_active_node_changed_called);
 }
 
+TEST(IoDev, SetNodeVolume) {
+  struct cras_iodev iodev;
+  struct cras_ionode ionode;
+
+  memset(&iodev, 0, sizeof(iodev));
+  memset(&ionode, 0, sizeof(ionode));
+  iodev.set_volume = dev_set_volume;
+  iodev.set_capture_gain = dev_set_capture_gain;
+  ionode.dev = &iodev;
+  ResetStubData();
+  cras_iodev_set_node_attr(&ionode, IONODE_ATTR_VOLUME, 10);
+  EXPECT_EQ(1, notify_node_volume_called);
+  iodev.direction = CRAS_STREAM_INPUT;
+  cras_iodev_set_node_attr(&ionode, IONODE_ATTR_CAPTURE_GAIN, 10);
+  EXPECT_EQ(1, notify_node_capture_gain_called);
+}
+
+TEST(IoDev, SetNodeSwapLeftRight) {
+  struct cras_iodev iodev;
+  struct cras_ionode ionode;
+
+  memset(&iodev, 0, sizeof(iodev));
+  memset(&ionode, 0, sizeof(ionode));
+  iodev.set_swap_mode_for_node = set_swap_mode_for_node;
+  ionode.dev = &iodev;
+  ResetStubData();
+  cras_iodev_set_node_attr(&ionode, IONODE_ATTR_SWAP_LEFT_RIGHT, 1);
+  EXPECT_EQ(1, set_swap_mode_for_node_called);
+  EXPECT_EQ(1, set_swap_mode_for_node_enable);
+  EXPECT_EQ(1, ionode.left_right_swapped);
+  EXPECT_EQ(1, notify_node_left_right_swapped_called);
+  cras_iodev_set_node_attr(&ionode, IONODE_ATTR_SWAP_LEFT_RIGHT, 0);
+  EXPECT_EQ(2, set_swap_mode_for_node_called);
+  EXPECT_EQ(0, set_swap_mode_for_node_enable);
+  EXPECT_EQ(0, ionode.left_right_swapped);
+  EXPECT_EQ(2, notify_node_left_right_swapped_called);
+}
+
 TEST(IoDev, SetMute) {
   struct cras_iodev iodev;
   int rc;
@@ -1142,6 +1209,7 @@
   iodev.active_node->volume = 100;
   iodev.software_volume_needed = 0;
 
+
   softvol_scalers[80] = 0.5;
   softvol_scalers[70] = 0.3;
 
@@ -1169,7 +1237,7 @@
   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;
 
@@ -1188,9 +1256,10 @@
 
 // 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;
 }
@@ -1200,7 +1269,7 @@
 // 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;
 
@@ -1220,7 +1289,7 @@
   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;
 }
@@ -1231,7 +1300,7 @@
   memset(&iodev, 0, sizeof(iodev));
   iodev.configure_dev = configure_dev;
   iodev.direction = CRAS_STREAM_OUTPUT;
-  iodev.format = &audio_fmt;
+  iodev.ext_format = &audio_fmt;
   ResetStubData();
 
   iodev.state = CRAS_IODEV_STATE_CLOSE;
@@ -1251,7 +1320,7 @@
   memset(&iodev, 0, sizeof(iodev));
   iodev.configure_dev = configure_dev;
   iodev.direction = CRAS_STREAM_OUTPUT;
-  iodev.format = &audio_fmt;
+  iodev.ext_format = &audio_fmt;
   ResetStubData();
 
   cras_audio_format low_rate_fmt = audio_fmt;
@@ -1267,7 +1336,7 @@
   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;
 }
 
@@ -1277,7 +1346,7 @@
   memset(&iodev, 0, sizeof(iodev));
   iodev.configure_dev = configure_dev;
   iodev.direction = CRAS_STREAM_OUTPUT;
-  iodev.format = &audio_fmt;
+  iodev.ext_format = &audio_fmt;
   ResetStubData();
 
   iodev.state = CRAS_IODEV_STATE_CLOSE;
@@ -1298,7 +1367,7 @@
   memset(&iodev, 0, sizeof(iodev));
   iodev.configure_dev = configure_dev;
   iodev.direction = CRAS_STREAM_INPUT;
-  iodev.format = &audio_fmt;
+  iodev.ext_format = &audio_fmt;
   ResetStubData();
 
   iodev.state = CRAS_IODEV_STATE_CLOSE;
@@ -1318,7 +1387,7 @@
   memset(&iodev, 0, sizeof(iodev));
   iodev.configure_dev = configure_dev;
   iodev.direction = CRAS_STREAM_INPUT;
-  iodev.format = &audio_fmt;
+  iodev.ext_format = &audio_fmt;
   ResetStubData();
 
   iodev.state = CRAS_IODEV_STATE_CLOSE;
@@ -1339,7 +1408,7 @@
   memset(&iodev, 0, sizeof(iodev));
   iodev.configure_dev = configure_dev;
   iodev.direction = CRAS_STREAM_INPUT;
-  iodev.format = &audio_fmt;
+  iodev.ext_format = &audio_fmt;
   ResetStubData();
 
   cras_audio_format low_rate_fmt = audio_fmt;
@@ -1355,7 +1424,8 @@
   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;
@@ -1371,14 +1441,12 @@
   memset(&rstream2, 0, sizeof(rstream2));
   iodev.configure_dev = configure_dev;
   iodev.no_stream = simple_no_stream;
-  iodev.format = &audio_fmt;
+  iodev.ext_format = &audio_fmt;
   iodev.state = CRAS_IODEV_STATE_NORMAL_RUN;
   rstream1.cb_threshold = 800;
   stream1.stream = &rstream1;
-  stream1.is_running = 0;
   rstream2.cb_threshold = 400;
   stream2.stream = &rstream2;
-  stream2.is_running = 0;
   ResetStubData();
 
   iodev_buffer_size = 1024;
@@ -1388,13 +1456,11 @@
 
   /* min_cb_level should not exceed half the buffer size. */
   cras_iodev_add_stream(&iodev, &stream1);
-  cras_iodev_start_stream(&iodev, &stream1);
   EXPECT_EQ(800, iodev.max_cb_level);
   EXPECT_EQ(512, iodev.min_cb_level);
   EXPECT_EQ(1, buffer_share_add_id_called);
 
   cras_iodev_add_stream(&iodev, &stream2);
-  cras_iodev_start_stream(&iodev, &stream2);
   EXPECT_EQ(800, iodev.max_cb_level);
   EXPECT_EQ(400, iodev.min_cb_level);
   EXPECT_EQ(2, buffer_share_add_id_called);
@@ -1410,94 +1476,6 @@
   EXPECT_EQ(512, iodev.min_cb_level);
 }
 
-TEST(IoDev, RmStreamUpdateFetchTime) {
-  struct cras_iodev iodev;
-  struct cras_rstream rstream1, rstream2, rstream3;
-  struct dev_stream stream1, stream2, stream3;
-
-  memset(&iodev, 0, sizeof(iodev));
-  memset(&rstream1, 0, sizeof(rstream1));
-  memset(&rstream2, 0, sizeof(rstream2));
-  memset(&rstream3, 0, sizeof(rstream2));
-  memset(&stream1, 0, sizeof(stream2));
-  memset(&stream2, 0, sizeof(stream2));
-  memset(&stream3, 0, sizeof(stream2));
-  iodev.configure_dev = configure_dev;
-  iodev.no_stream = simple_no_stream;
-  iodev.format = &audio_fmt;
-  iodev.state = CRAS_IODEV_STATE_NORMAL_RUN;
-  rstream1.direction = CRAS_STREAM_OUTPUT;
-  rstream2.direction = CRAS_STREAM_OUTPUT;
-  rstream3.direction = CRAS_STREAM_OUTPUT;
-  stream1.stream = &rstream1;
-  stream2.stream = &rstream2;
-  stream3.stream = &rstream3;
-  ResetStubData();
-
-  cras_iodev_open(&iodev, 1024, &audio_fmt);
-
-  cras_iodev_add_stream(&iodev, &stream1);
-  cras_iodev_start_stream(&iodev, &stream1);
-  cras_iodev_add_stream(&iodev, &stream2);
-  cras_iodev_start_stream(&iodev, &stream2);
-  cras_iodev_add_stream(&iodev, &stream3);
-
-  rstream1.next_cb_ts.tv_sec = 2;
-  rstream1.next_cb_ts.tv_nsec = 0;
-  rstream2.next_cb_ts.tv_sec = 1;
-  rstream2.next_cb_ts.tv_nsec = 0;
-  rstream3.next_cb_ts.tv_sec = 1;
-  rstream3.next_cb_ts.tv_nsec = 0;
-
-  /*
-   * Because rstream3 has not started yet, the next_cb_ts will be change to the
-   * earliest fetch time of remaining streams, which is rstream1.
-   */
-  cras_iodev_rm_stream(&iodev, &rstream2);
-
-  EXPECT_EQ(rstream3.next_cb_ts.tv_sec, rstream1.next_cb_ts.tv_sec);
-  EXPECT_EQ(rstream3.next_cb_ts.tv_nsec, rstream1.next_cb_ts.tv_nsec);
-}
-
-TEST(IoDev, StartStreams) {
-  struct cras_iodev iodev1, iodev2;
-  struct cras_rstream rstream1, rstream2;
-  struct dev_stream stream1, stream2;
-
-  memset(&iodev1, 0, sizeof(iodev1));
-  memset(&iodev2, 0, sizeof(iodev2));
-  memset(&rstream1, 0, sizeof(rstream1));
-  memset(&rstream2, 0, sizeof(rstream2));
-  memset(&stream1, 0, sizeof(stream1));
-  memset(&stream2, 0, sizeof(stream2));
-  iodev1.configure_dev = configure_dev;
-  iodev1.format = &audio_fmt;
-  iodev1.state = CRAS_IODEV_STATE_NORMAL_RUN;
-  iodev2.configure_dev = configure_dev;
-  iodev2.format = &audio_fmt;
-  iodev2.state = CRAS_IODEV_STATE_NORMAL_RUN;
-  rstream1.direction = CRAS_STREAM_INPUT;
-  rstream2.direction = CRAS_STREAM_OUTPUT;
-  stream1.stream = &rstream1;
-  stream2.stream = &rstream2;
-
-  /* An input stream starts running immediately. */
-  ResetStubData();
-  iodev1.direction = CRAS_STREAM_INPUT;
-  cras_iodev_open(&iodev1, 1024, &audio_fmt);
-  cras_iodev_add_stream(&iodev1, &stream1);
-  EXPECT_EQ(1, dev_stream_is_running(&stream1));
-  EXPECT_EQ(1, buffer_share_add_id_called);
-
-  /* An output stream starts running after its first fetch. */
-  ResetStubData();
-  iodev2.direction = CRAS_STREAM_OUTPUT;
-  cras_iodev_open(&iodev2, 1024, &audio_fmt);
-  cras_iodev_add_stream(&iodev2, &stream2);
-  EXPECT_EQ(0, dev_stream_is_running(&stream2));
-  EXPECT_EQ(0, buffer_share_add_id_called);
-}
-
 TEST(IoDev, TriggerOnlyStreamNoBufferShare) {
   struct cras_iodev iodev;
   struct cras_rstream rstream;
@@ -1506,7 +1484,7 @@
   memset(&iodev, 0, sizeof(iodev));
   memset(&rstream, 0, sizeof(rstream));
   iodev.configure_dev = configure_dev;
-  iodev.format = &audio_fmt;
+  iodev.ext_format = &audio_fmt;
   iodev.state = CRAS_IODEV_STATE_NORMAL_RUN;
   rstream.cb_threshold = 800;
   rstream.flags = TRIGGER_ONLY;
@@ -1523,7 +1501,7 @@
   struct cras_iodev iodev;
   struct cras_audio_format fmt;
   unsigned int frames = 50;
-  int16_t* zeros;
+  int16_t *zeros;
   int rc;
 
   ResetStubData();
@@ -1532,7 +1510,7 @@
   fmt.format = SND_PCM_FORMAT_S16_LE;
   fmt.frame_rate = 48000;
   fmt.num_channels = 2;
-  iodev.format = &fmt;
+  iodev.ext_format = &fmt;
   iodev.get_buffer = get_buffer;
   iodev.put_buffer = put_buffer;
 
@@ -1545,7 +1523,7 @@
 
   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);
@@ -1557,7 +1535,7 @@
   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));
@@ -1565,7 +1543,7 @@
   fmt.format = SND_PCM_FORMAT_S16_LE;
   fmt.frame_rate = 48000;
   fmt.num_channels = 2;
-  iodev.format = &fmt;
+  iodev.ext_format = &fmt;
   iodev.min_cb_level = min_cb_level;
   iodev.get_buffer = get_buffer;
   iodev.put_buffer = put_buffer;
@@ -1588,7 +1566,7 @@
   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);
 
@@ -1622,14 +1600,13 @@
 
   rstream1.cb_threshold = min_cb_level;
   stream1.stream = &rstream1;
-  stream1.is_running = 1;
 
   memset(&iodev, 0, sizeof(iodev));
 
   fmt.format = SND_PCM_FORMAT_S16_LE;
   fmt.frame_rate = 48000;
   fmt.num_channels = 2;
-  iodev.format = &fmt;
+  iodev.ext_format = &fmt;
   iodev.format = &fmt;
   iodev.min_cb_level = min_cb_level;
   iodev.get_buffer = get_buffer;
@@ -1733,9 +1710,7 @@
   // Device should start ramping up without setting mute callback.
   EXPECT_EQ(0, rc);
   EXPECT_EQ(1, cras_ramp_start_is_called);
-  EXPECT_EQ(1, cras_ramp_start_mute_ramp);
-  EXPECT_FLOAT_EQ(0.0, cras_ramp_start_from);
-  EXPECT_FLOAT_EQ(1.0, cras_ramp_start_to);
+  EXPECT_EQ(1, cras_ramp_start_is_up);
   EXPECT_EQ(fmt.frame_rate * RAMP_NEW_STREAM_DURATION_SECS,
             cras_ramp_start_duration_frames);
   EXPECT_EQ(NULL, cras_ramp_start_cb);
@@ -1769,9 +1744,7 @@
   // Device should start ramping up without setting mute callback.
   EXPECT_EQ(0, rc);
   EXPECT_EQ(1, cras_ramp_start_is_called);
-  EXPECT_EQ(1, cras_ramp_start_mute_ramp);
-  EXPECT_FLOAT_EQ(0.0, cras_ramp_start_from);
-  EXPECT_FLOAT_EQ(1.0, cras_ramp_start_to);
+  EXPECT_EQ(1, cras_ramp_start_is_up);
   EXPECT_EQ(fmt.frame_rate * RAMP_NEW_STREAM_DURATION_SECS,
             cras_ramp_start_duration_frames);
   EXPECT_EQ(NULL, cras_ramp_start_cb);
@@ -1830,9 +1803,7 @@
   // Device should start ramping up without setting mute callback.
   EXPECT_EQ(0, rc);
   EXPECT_EQ(1, cras_ramp_start_is_called);
-  EXPECT_EQ(1, cras_ramp_start_mute_ramp);
-  EXPECT_FLOAT_EQ(0.0, cras_ramp_start_from);
-  EXPECT_FLOAT_EQ(1.0, cras_ramp_start_to);
+  EXPECT_EQ(1, cras_ramp_start_is_up);
   EXPECT_EQ(fmt.frame_rate * RAMP_NEW_STREAM_DURATION_SECS,
             cras_ramp_start_duration_frames);
   EXPECT_EQ(NULL, cras_ramp_start_cb);
@@ -1848,16 +1819,14 @@
   // Device should start ramping up.
   EXPECT_EQ(0, rc);
   EXPECT_EQ(1, cras_ramp_start_is_called);
-  EXPECT_EQ(1, cras_ramp_start_mute_ramp);
-  EXPECT_FLOAT_EQ(0.0, cras_ramp_start_from);
-  EXPECT_FLOAT_EQ(1.0, cras_ramp_start_to);
+  EXPECT_EQ(1, cras_ramp_start_is_up);
   EXPECT_EQ(fmt.frame_rate * RAMP_UNMUTE_DURATION_SECS,
             cras_ramp_start_duration_frames);
   // Callback for unmute is not used.
   EXPECT_EQ(NULL, cras_ramp_start_cb);
   // Device mute state is set after ramping starts.
   EXPECT_EQ(1, cras_device_monitor_set_device_mute_state_called);
-  EXPECT_EQ(iodev.info.idx, cras_device_monitor_set_device_mute_state_dev_idx);
+  EXPECT_EQ(&iodev, cras_device_monitor_set_device_mute_state_dev);
 }
 
 TEST(IoDev, StartRampDown) {
@@ -1897,95 +1866,19 @@
   // Device should start ramping down with mute callback.
   EXPECT_EQ(0, rc);
   EXPECT_EQ(1, cras_ramp_start_is_called);
-  EXPECT_EQ(1, cras_ramp_start_mute_ramp);
-  EXPECT_FLOAT_EQ(1.0, cras_ramp_start_from);
-  EXPECT_FLOAT_EQ(0.0, cras_ramp_start_to);
+  EXPECT_EQ(0, cras_ramp_start_is_up);
   EXPECT_EQ(fmt.frame_rate * RAMP_MUTE_DURATION_SECS,
             cras_ramp_start_duration_frames);
 
   // Device mute state is not set yet. It should wait for ramp to finish.
   EXPECT_EQ(0, cras_device_monitor_set_device_mute_state_called);
+  EXPECT_EQ(NULL, cras_device_monitor_set_device_mute_state_dev);
 
   // Assume the callback is set, and it is later called after ramp is done.
   // It should trigger cras_device_monitor_set_device_mute_state.
   cras_ramp_start_cb(cras_ramp_start_cb_data);
   EXPECT_EQ(1, cras_device_monitor_set_device_mute_state_called);
-  EXPECT_EQ(iodev.info.idx, cras_device_monitor_set_device_mute_state_dev_idx);
-}
-
-TEST(IoDev, StartVolumeRamp) {
-  struct cras_ionode ionode;
-  struct cras_iodev iodev;
-  int rc;
-  struct cras_audio_format fmt;
-  int expected_frames;
-  float ionode_softvol_scalers[101];
-  memset(&iodev, 0, sizeof(iodev));
-
-  // Format will be used in cras_iodev_start_ramp to determine ramp duration.
-  fmt.format = SND_PCM_FORMAT_S16_LE;
-  fmt.frame_rate = 48000;
-  fmt.num_channels = 2;
-  iodev.format = &fmt;
-  expected_frames = fmt.frame_rate * RAMP_VOLUME_CHANGE_DURATION_SECS;
-
-  // Assume device has ramp member.
-  iodev.ramp = reinterpret_cast<struct cras_ramp*>(0x1);
-
-  // Case 1: Device is not opened yet.
-  ResetStubData();
-  iodev.state = CRAS_IODEV_STATE_CLOSE;
-  rc = cras_iodev_start_volume_ramp(&iodev, 30, 94);
-
-  // Ramp request is ignored.
-  EXPECT_EQ(0, rc);
-  EXPECT_EQ(0, cras_ramp_start_is_called);
-
-  // Case 2: Volumes are equal.
-  ResetStubData();
-  iodev.state = CRAS_IODEV_STATE_OPEN;
-  rc = cras_iodev_start_volume_ramp(&iodev, 70, 70);
-
-  // Ramp request is ignored.
-  EXPECT_EQ(0, rc);
-  EXPECT_EQ(0, cras_ramp_start_is_called);
-
-  // Case 3: Ramp up, global scalers
-  ResetStubData();
-  iodev.state = CRAS_IODEV_STATE_OPEN;
-  softvol_scalers[40] = 0.2;
-  softvol_scalers[60] = 0.8;
-
-  rc = cras_iodev_start_volume_ramp(&iodev, 40, 60);
-
-  EXPECT_EQ(0, rc);
-  EXPECT_EQ(1, cras_ramp_start_is_called);
-  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(NULL, cras_ramp_start_cb);
-  EXPECT_EQ(NULL, cras_ramp_start_cb_data);
-
-  // Case 4: Ramp down, device saclers
-  ResetStubData();
-  iodev.state = CRAS_IODEV_STATE_OPEN;
-
-  ionode_softvol_scalers[40] = 0.4;
-  ionode_softvol_scalers[60] = 0.5;
-  ionode.softvol_scalers = ionode_softvol_scalers;
-  iodev.active_node = &ionode;
-
-  rc = cras_iodev_start_volume_ramp(&iodev, 60, 40);
-
-  EXPECT_EQ(0, rc);
-  EXPECT_EQ(1, cras_ramp_start_is_called);
-  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(NULL, cras_ramp_start_cb);
-  EXPECT_EQ(NULL, cras_ramp_start_cb_data);
+  EXPECT_EQ(&iodev, cras_device_monitor_set_device_mute_state_dev);
 }
 
 TEST(IoDev, OutputDeviceShouldWake) {
@@ -2006,14 +1899,14 @@
   rc = cras_iodev_odev_should_wake(&iodev);
   EXPECT_EQ(1, rc);
 
-  // Device is running. Device has is_free_running ops.
-  iodev.is_free_running = is_free_running;
-  is_free_running_ret = 1;
+  // Device is running. Device has output_should_wake ops.
+  iodev.output_should_wake = output_should_wake;
+  output_should_wake_ret = 0;
   rc = cras_iodev_odev_should_wake(&iodev);
   EXPECT_EQ(0, rc);
 
-  // Device is running. Device has is_free_running ops.
-  is_free_running_ret = 0;
+  // Device is running. Device has output_should_wake ops.
+  output_should_wake_ret = 1;
   rc = cras_iodev_odev_should_wake(&iodev);
   EXPECT_EQ(1, rc);
 
@@ -2029,8 +1922,6 @@
   unsigned int min_cb_level = 512, hw_level;
   unsigned int got_hw_level, got_frames;
   struct timespec hw_tstamp;
-  struct cras_rstream rstream;
-  struct dev_stream stream;
 
   memset(&iodev, 0, sizeof(iodev));
   memset(&fmt, 0, sizeof(fmt));
@@ -2039,35 +1930,19 @@
   iodev.direction = CRAS_STREAM_OUTPUT;
   iodev.buffer_size = BUFFER_SIZE;
   iodev.min_cb_level = min_cb_level;
+  iodev.streams = reinterpret_cast<struct dev_stream *>(0x1);
   iodev.state = CRAS_IODEV_STATE_NORMAL_RUN;
   iodev.format = &fmt;
   fmt.frame_rate = 48000;
-  rstream.cb_threshold = min_cb_level;
-  stream.stream = &rstream;
 
   ResetStubData();
 
-  cras_iodev_add_stream(&iodev, &stream);
-  cras_iodev_start_stream(&iodev, &stream);
-
-  // Device is running. There is at least one stream for this device
-  // and there are frames waiting to be played. hw_level is greater
-  // than min_cb_level.
-  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);
-  EXPECT_EQ(got_hw_level, hw_level);
-  EXPECT_EQ(got_frames, 50);
-  dev_stream_playback_frames_ret = 0;
-
   // Device is running. There is at least one stream for this device.
   // 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);
 
@@ -2075,8 +1950,8 @@
   // 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);
 
@@ -2084,24 +1959,33 @@
   // 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);
 
-  // Device is running. There is no stream for this device. The audio thread
-  // will wake up until hw_level drops to DEV_NO_STREAM_WAKE_UP_LATEST_TIME,
-  // which is defined as 5 milliseconds in cras_iodev.c.
+  // Device is running. There is no stream for this device.
+  // hw_level is greater than min_cb_level.
   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);
+  EXPECT_EQ(got_frames, 0);
+
+  // Device is running. There is no stream for this device.
+  // hw_level is less than min_cb_level.
+  iodev.streams = NULL;
+  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);
+  EXPECT_EQ(got_hw_level, hw_level);
+  EXPECT_EQ(got_frames, 0);
 }
 
-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;
 }
 
@@ -2124,7 +2008,7 @@
 
   iodev.configure_dev = configure_dev;
   iodev.direction = CRAS_STREAM_OUTPUT;
-  iodev.format = &audio_fmt;
+  iodev.ext_format = &audio_fmt;
 
   iodev.state = CRAS_IODEV_STATE_CLOSE;
   iodev_buffer_size = 1024;
@@ -2148,16 +2032,17 @@
   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();
@@ -2166,7 +2051,7 @@
   fmt.format = SND_PCM_FORMAT_S16_LE;
   fmt.frame_rate = 48000;
   fmt.num_channels = 2;
-  iodev.format = &fmt;
+  iodev.ext_format = &fmt;
   iodev.get_buffer = get_buffer;
   iodev.put_buffer = put_buffer;
   iodev.direction = CRAS_STREAM_OUTPUT;
@@ -2176,7 +2061,7 @@
   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);
@@ -2187,10 +2072,12 @@
   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++;
 }
 
@@ -2206,12 +2093,12 @@
   fmt.frame_rate = 48000;
   fmt.num_channels = 2;
   iodev.configure_dev = configure_dev;
-  iodev.format = &fmt;
+  iodev.ext_format = &fmt;
   iodev.format = &fmt;
   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);
@@ -2224,21 +2111,19 @@
 
   cras_iodev_set_ext_dsp_module(&iodev, NULL);
   EXPECT_EQ(1, ext_mod_configure_called);
-  EXPECT_EQ(2, cras_dsp_get_pipeline_called);
-  EXPECT_EQ(2, cras_dsp_pipeline_set_sink_ext_module_called);
 
   cras_iodev_set_ext_dsp_module(&iodev, &ext);
   EXPECT_EQ(2, ext_mod_configure_called);
-  EXPECT_EQ(3, cras_dsp_get_pipeline_called);
-  EXPECT_EQ(3, cras_dsp_pipeline_set_sink_ext_module_called);
+  EXPECT_EQ(2, cras_dsp_get_pipeline_called);
+  EXPECT_EQ(2, cras_dsp_pipeline_set_sink_ext_module_called);
 
   /* If pipeline doesn't exist, dummy pipeline should be loaded. */
   cras_dsp_get_pipeline_ret = 0x0;
   cras_iodev_set_ext_dsp_module(&iodev, &ext);
   EXPECT_EQ(3, ext_mod_configure_called);
-  EXPECT_EQ(5, cras_dsp_get_pipeline_called);
+  EXPECT_EQ(4, cras_dsp_get_pipeline_called);
   EXPECT_EQ(1, cras_dsp_load_dummy_pipeline_called);
-  EXPECT_EQ(4, cras_dsp_pipeline_set_sink_ext_module_called);
+  EXPECT_EQ(3, cras_dsp_pipeline_set_sink_ext_module_called);
 }
 
 TEST(IoDev, InputDspOffset) {
@@ -2248,7 +2133,6 @@
   struct dev_stream stream1;
   struct input_data data;
   unsigned int frames = 240;
-  int rc;
 
   ResetStubData();
 
@@ -2261,7 +2145,7 @@
   fmt.frame_rate = 48000;
   fmt.num_channels = 2;
   iodev.configure_dev = configure_dev;
-  iodev.format = &fmt;
+  iodev.ext_format = &fmt;
   iodev.format = &fmt;
   iodev.state = CRAS_IODEV_STATE_CLOSE;
   iodev.get_buffer = get_buffer;
@@ -2269,7 +2153,7 @@
   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;
 
@@ -2279,253 +2163,241 @@
   cras_iodev_get_input_buffer(&iodev, &frames);
 
   buffer_share_get_new_write_point_ret = 100;
-  rc = cras_iodev_put_input_buffer(&iodev);
+  cras_iodev_put_input_buffer(&iodev);
   EXPECT_EQ(140, iodev.input_dsp_offset);
-  EXPECT_EQ(100, rc);
 
   frames = 130;
   cras_iodev_get_input_buffer(&iodev, &frames);
   EXPECT_EQ(130, iodev.input_frames_read);
 
   buffer_share_get_new_write_point_ret = 80;
-  rc = cras_iodev_put_input_buffer(&iodev);
+  cras_iodev_put_input_buffer(&iodev);
   EXPECT_EQ(60, iodev.input_dsp_offset);
-  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_boolean(struct cras_dsp_context* ctx,
-                                   const char* key,
-                                   char value) {}
-
-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);
+void cras_dsp_set_variable_string(struct cras_dsp_context *ctx, const char *key,
+                                  const char *value)
+{
 }
 
-void cras_dsp_put_pipeline(struct cras_dsp_context* ctx) {
+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)
+{
+  cras_dsp_get_pipeline_called++;
+  return reinterpret_cast<struct pipeline *>(cras_dsp_get_pipeline_ret);
+}
+
+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;
+void cras_iodev_list_notify_node_volume(struct cras_ionode *node)
+{
+	notify_node_volume_called++;
 }
 
-void cras_audio_area_destroy(struct cras_audio_area* area) {}
+void cras_iodev_list_notify_node_capture_gain(struct cras_ionode *node)
+{
+	notify_node_capture_gain_called++;
+}
 
-void cras_audio_area_config_channels(struct cras_audio_area* area,
-                                     const struct cras_audio_format* fmt) {}
+void cras_iodev_list_notify_node_left_right_swapped(struct cras_ionode *node)
+{
+  notify_node_left_right_swapped_called++;
+}
 
-int cras_audio_format_set_channel_layout(struct cras_audio_format* format,
-                                         const int8_t layout[CRAS_CH_MAX]) {
+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_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 i;
   cras_audio_format_set_channel_layout_called++;
   for (i = 0; i < CRAS_CH_MAX; i++)
@@ -2533,8 +2405,9 @@
   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() {
@@ -2553,78 +2426,76 @@
   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, int channel)
+{
   cras_scale_buffer_increment_fmt = fmt;
   cras_scale_buffer_increment_buff = buff;
   cras_scale_buffer_increment_frame = frame;
   cras_scale_buffer_increment_scaler = scaler;
   cras_scale_buffer_increment_increment = increment;
-  cras_scale_buffer_increment_target = target;
   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) {}
-
-double rate_estimator_get_rate(struct rate_estimator* re) {
-  return rate_estimator_get_rate_ret;
+void rate_estimator_reset_rate(struct rate_estimator *re, unsigned int rate) {
 }
 
-unsigned int dev_stream_cb_threshold(const struct dev_stream* dev_stream) {
+double rate_estimator_get_rate(struct rate_estimator *re) {
+  return 0.0;
+}
+
+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;
 }
@@ -2633,52 +2504,54 @@
   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 is_up, 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;
-  cras_ramp_start_to = to;
+  cras_ramp_start_is_up = is_up;
   cras_ramp_start_duration_frames = duration_frames;
   cras_ramp_start_cb = cb;
   cras_ramp_start_cb_data = cb_data;
   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(struct cras_iodev *iodev)
+{
   cras_device_monitor_set_device_mute_state_called++;
-  cras_device_monitor_set_device_mute_state_dev_idx = dev_idx;
+  cras_device_monitor_set_device_mute_state_dev = iodev;
   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;
@@ -2686,30 +2559,31 @@
   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_event_severe_underrun() {
+int cras_audio_thread_severe_underrun()
+{
   return 0;
 }
 
-int cras_audio_thread_event_underrun() {
-  return 0;
-}
-
-int cras_server_metrics_device_runtime(struct cras_iodev* iodev) {
+int cras_audio_thread_underrun()
+{
   return 0;
 }
 
 }  // 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, atlog_name);
-  free(atlog_name);
+  audio_thread_event_log_deinit(atlog);
   return rc;
 }
diff --git a/cras/src/tests/linear_resampler_unittest.cc b/cras/src/tests/linear_resampler_unittest.cc
index 6095d5b..6dbab94 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 <stdint.h>
 #include <stdio.h>
+#include <stdint.h>
+#include <gtest/gtest.h>
 
 extern "C" {
 #include "linear_resampler.h"
@@ -17,204 +17,208 @@
 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;
+	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);
+	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;
+	}
 
-  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);
+	lr = linear_resampler_create(2, 4, 48000, 48001);
 
-  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);
+	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);
 
-  /* 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);
+	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;
+	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;
-  }
+	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);
+	/* 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);
+	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 = 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);
+	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);
+	/* 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;
+	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;
-  }
+	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);
+	/* 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);
+	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;
+	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);
+	/* 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);
+	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);
+	/* 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;
+	int rc;
+	unsigned int count;
+	struct linear_resampler *lr;
 
-  memset(in_buf, 0, BUF_SIZE);
-  memset(out_buf, 0, BUF_SIZE);
+	memset(in_buf, 0, BUF_SIZE);
+	memset(out_buf, 0, BUF_SIZE);
 
-  /* Rate 10 -> 9 */
-  lr = linear_resampler_create(2, 4, 10, 9);
+	/* 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);
+	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;
+	int rc;
+	unsigned int count;
+	struct linear_resampler *lr;
 
-  memset(in_buf, 0, BUF_SIZE);
-  memset(out_buf, 0, BUF_SIZE);
+	memset(in_buf, 0, BUF_SIZE);
+	memset(out_buf, 0, BUF_SIZE);
 
-  /* Rate 10 -> 9 */
-  lr = linear_resampler_create(2, 4, 10, 9);
+	/* 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);
+	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;
+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;
-  }
+	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 3cdaffb..b5acb1a 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,50 @@
 static const unsigned int kBufferSize = kBufferFrames * kFrameBytes;
 
 static struct timespec time_now;
-static cras_audio_area* dummy_audio_area;
-static loopback_hook_data_t loop_hook;
-static struct cras_iodev* enabled_dev;
+static cras_audio_area *dummy_audio_area;
+static loopback_hook_t loop_hook;
+static void *loop_hook_cb_data;
+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 int cras_iodev_list_register_loopback_called;
-static int cras_iodev_list_unregister_loopback_called;
+static void *device_enabled_callback_cb_data;
 
-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();
+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;
     }
-    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_;
+    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);
+    }
 
-    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_;
+    uint8_t buf_[kBufferSize];
+    struct cras_audio_format fmt_;
+    struct cras_iodev *loop_in_;
 };
 
 TEST_F(LoopBackTestSuite, InstallLoopHook) {
@@ -79,68 +76,31 @@
 
   iodev.direction = CRAS_STREAM_OUTPUT;
   iodev.format = &fmt_;
+  iodev.ext_format = &fmt_;
   iodev.streams = NULL;
-  iodev.info.idx = 123;
   enabled_dev = &iodev;
 
   // Open loopback devices.
   EXPECT_EQ(0, loop_in_->configure_dev(loop_in_));
   EXPECT_EQ(1, cras_iodev_list_set_device_enabled_callback_called);
-  EXPECT_EQ(1, cras_iodev_list_register_loopback_called);
 
   // Signal an output device is enabled.
   device_enabled_callback_cb(&iodev, device_enabled_callback_cb_data);
 
   // Expect that a hook was added to the iodev
-  EXPECT_EQ(2, cras_iodev_list_register_loopback_called);
-  ASSERT_NE(reinterpret_cast<loopback_hook_data_t>(NULL), loop_hook);
+  ASSERT_NE(reinterpret_cast<loopback_hook_t>(NULL), loop_hook);
 
   // Check zero frames queued.
   EXPECT_EQ(0, loop_in_->frames_queued(loop_in_, &tstamp));
 
-  device_disabled_callback_cb(&iodev, device_enabled_callback_cb_data);
-  EXPECT_EQ(1, cras_iodev_list_unregister_loopback_called);
-  EXPECT_EQ(3, cras_iodev_list_register_loopback_called);
-
-  enabled_dev->info.idx = 456;
-  device_enabled_callback_cb(&iodev, device_enabled_callback_cb_data);
-  EXPECT_EQ(4, cras_iodev_list_register_loopback_called);
-
   // Close loopback devices.
   EXPECT_EQ(0, loop_in_->close_dev(loop_in_));
-  EXPECT_EQ(2, cras_iodev_list_unregister_loopback_called);
-  EXPECT_EQ(2, cras_iodev_list_set_device_enabled_callback_called);
-}
-
-TEST_F(LoopBackTestSuite, SelectDevFromAToB) {
-  struct cras_iodev iodev1, iodev2;
-
-  iodev1.direction = CRAS_STREAM_OUTPUT;
-  iodev2.direction = CRAS_STREAM_OUTPUT;
-  enabled_dev = &iodev1;
-
-  enabled_dev->info.idx = 111;
-  EXPECT_EQ(0, loop_in_->configure_dev(loop_in_));
-  EXPECT_EQ(1, cras_iodev_list_set_device_enabled_callback_called);
-  EXPECT_EQ(1, cras_iodev_list_register_loopback_called);
-
-  /* Not the current sender being disabled, assert unregister not called. */
-  iodev2.info.idx = 222;
-  device_disabled_callback_cb(&iodev2, device_enabled_callback_cb_data);
-  EXPECT_EQ(0, cras_iodev_list_unregister_loopback_called);
-  EXPECT_EQ(1, cras_iodev_list_register_loopback_called);
-
-  enabled_dev = &iodev2;
-  device_disabled_callback_cb(&iodev1, device_enabled_callback_cb_data);
-  EXPECT_EQ(1, cras_iodev_list_unregister_loopback_called);
-  EXPECT_EQ(2, cras_iodev_list_register_loopback_called);
-
-  EXPECT_EQ(0, loop_in_->close_dev(loop_in_));
+  EXPECT_EQ(reinterpret_cast<loopback_hook_t>(NULL), loop_hook);
 }
 
 // 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 +132,7 @@
 }
 
 TEST_F(LoopBackTestSuite, SimpleLoopback) {
-  cras_audio_area* area;
+  cras_audio_area *area;
   unsigned int nframes = 1024;
   unsigned int nread = 1024;
   int rc;
@@ -184,10 +144,10 @@
   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_);
+  loop_hook(buf_, nframes, &fmt_, loop_hook_cb_data);
 
   // Verify frames from loopback record.
   loop_in_->get_buffer(loop_in_, &area, &nread);
@@ -207,47 +167,60 @@
 /* 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) {
-  cras_iodev_list_register_loopback_called++;
-  loop_hook = hook_data;
+void cras_iodev_set_active_node(struct cras_iodev *iodev,
+                                struct cras_ionode *node)
+{
 }
 
-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++;
+void cras_iodev_register_pre_dsp_hook(struct cras_iodev *iodev,
+				      loopback_hook_t loop_cb,
+				      void *cb_data)
+{
+  loop_hook = loop_cb;
+  loop_hook_cb_data = cb_data;
 }
 
-int cras_iodev_list_add_input(struct cras_iodev* input) {
+void cras_iodev_register_post_dsp_hook(struct cras_iodev *iodev,
+				       loopback_hook_t loop_cb,
+				       void *cb_data)
+{
+  loop_hook = loop_cb;
+  loop_hook_cb_data = cb_data;
+}
+
+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;
 }
@@ -255,7 +228,8 @@
 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;
@@ -263,13 +237,14 @@
   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;
 }
 
@@ -277,7 +252,7 @@
 
 }  //  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
deleted file mode 100644
index d0f19c3..0000000
--- a/cras/src/tests/metrics_stub.cc
+++ /dev/null
@@ -1,49 +0,0 @@
-/* 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.
- */
-
-extern "C" {
-#include "cras_server_metrics.h"
-
-int cras_server_metrics_device_runtime(struct cras_iodev* iodev) {
-  return 0;
-}
-
-int cras_server_metrics_highest_device_delay(
-    unsigned int hw_level,
-    unsigned int largest_cb_level,
-    enum CRAS_STREAM_DIRECTION direction) {
-  return 0;
-}
-
-int cras_server_metrics_highest_hw_level(unsigned hw_level,
-                                         enum CRAS_STREAM_DIRECTION direction) {
-  return 0;
-}
-
-int cras_server_metrics_longest_fetch_delay(unsigned delay_msec) {
-  return 0;
-}
-
-int cras_server_metrics_missed_cb_event(const struct cras_rstream* stream) {
-  return 0;
-}
-
-int cras_server_metrics_num_underruns(unsigned num_underruns) {
-  return 0;
-}
-
-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
deleted file mode 100644
index 1d07e3e..0000000
--- a/cras/src/tests/metrics_stub.h
+++ /dev/null
@@ -1,9 +0,0 @@
-/* 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 METRICS_STUB_H_
-#define METRICS_STUB_H_
-
-#endif  // METRICS_STUB_H_
diff --git a/cras/src/tests/mix_unittest.cc b/cras/src/tests/mix_unittest.cc
index dbbbdb0..df4c5b4 100644
--- a/cras/src/tests/mix_unittest.cc
+++ b/cras/src/tests/mix_unittest.cc
@@ -2,13 +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 <stdio.h>
+#include <gtest/gtest.h>
 
 extern "C" {
-#include "cras_mix.h"
 #include "cras_shm.h"
+#include "cras_mix.h"
 #include "cras_types.h"
+
 }
 
 namespace {
@@ -16,176 +17,167 @@
 static const size_t kBufferFrames = 8192;
 static const size_t kNumChannels = 2;
 static const size_t kNumSamples = kBufferFrames * kNumChannels;
-static const float kMaxVolumeToScale = 0.9999999;
-static const float kMinVolumeToScale = 0.0000001;
+
 
 static inline int need_to_scale(float scaler) {
-  return (scaler < 0.99 || scaler > 1.01);
+	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_area)));
 
-    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_);
-  }
-
-  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];
-    }
-  }
-
-  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;
-    }
-
-    cras_mix_add_scale_stride(fmt_, (uint8_t*)mix_buffer_,
-                              (uint8_t*)src_buffer_, kBufferFrames, 4, 2,
-                              scaler);
-
-    EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4));
-  }
-
-  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 > 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;
+      for (size_t i = 0; i < kBufferFrames * 2; i++) {
+        src_buffer_[i] = i;
+        mix_buffer_[i] = -i;
       }
 
-      if (i % 2 == 1)
-        scaler += increment;
+      compare_buffer_ = (int16_t *)malloc(kBufferFrames * 4);
     }
-  }
 
-  int16_t* mix_buffer_;
-  int16_t* src_buffer_;
-  int16_t* compare_buffer_;
+    virtual void TearDown() {
+      free(mix_buffer_);
+      free(compare_buffer_);
+      free(src_buffer_);
+    }
+
+    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];
+      }
+    }
+
+    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;
+      }
+
+      cras_mix_add_scale_stride(
+          fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_,
+          kBufferFrames, 4, 2, scaler);
+
+      EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4));
+    }
+
+    void ScaleIncrement(float start_scaler, float increment) {
+      float scaler = start_scaler;
+      for (size_t i = 0; i < kBufferFrames * 2; i++) {
+        if (scaler > 0.9999999) {
+        } else if (scaler < 0.0000001) {
+          compare_buffer_[i] = 0;
+        } else {
+          compare_buffer_[i] = mix_buffer_[i] * scaler;
+        }
+        if (i % 2 == 1)
+          scaler += increment;
+      }
+    }
+
+  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) {
   float increment = 0.01;
   int step = 2;
   float start_scaler = 0.999999999;
-  float target = 1.0;
 
   _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, step);
 
   EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4));
 }
@@ -194,13 +186,12 @@
   float increment = -0.01;
   int step = 2;
   float start_scaler = 0.000000001;
-  float target = 0.0;
 
   _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, step);
 
   EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4));
 }
@@ -209,13 +200,12 @@
   float increment = 0.0001;
   int step = 2;
   float start_scaler = 0.1;
-  float target = 1.0;
 
   _SetupBuffer();
-  ScaleIncrement(start_scaler, increment, target);
+  ScaleIncrement(start_scaler, increment);
 
-  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, step);
   EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4));
 }
 
@@ -223,13 +213,12 @@
   float increment = -0.0001;
   int step = 2;
   float start_scaler = 0.8;
-  float target = 0.0;
 
   _SetupBuffer();
-  ScaleIncrement(start_scaler, increment, target);
+  ScaleIncrement(start_scaler, increment);
 
-  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, step);
 
   EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4));
 }
@@ -238,13 +227,12 @@
   float increment = -0.0001;
   int step = 2;
   float start_scaler = 1.0;
-  float target = 0.0;
 
   _SetupBuffer();
-  ScaleIncrement(start_scaler, increment, target);
+  ScaleIncrement(start_scaler, increment);
 
-  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, step);
 
   EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4));
 }
@@ -253,55 +241,26 @@
   float increment = 0.0001;
   int step = 2;
   float start_scaler = 0.0;
-  float target = 1.0;
 
   _SetupBuffer();
-  ScaleIncrement(start_scaler, increment, target);
+  ScaleIncrement(start_scaler, increment);
 
-  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, step);
 
   EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4));
 }
 
-TEST_F(MixTestSuiteS16_LE, ScaleVolumePositiveIncrementCappedByTarget) {
-  float increment = 0.0001;
-  int step = 2;
-  float start_scaler = 0.1;
-  float target = 0.5;
-
-  _SetupBuffer();
-  ScaleIncrement(start_scaler, increment, target);
-
-  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, ScaleVolumeNegativeIncrementCappedByTarget) {
-  float increment = -0.01;
-  int step = 2;
-  float start_scaler = 0.8;
-  float target = 0.5;
-
-  _SetupBuffer();
-  ScaleIncrement(start_scaler, increment, target);
-
-  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));
 }
@@ -309,134 +268,122 @@
 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)));
+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_area)));
 
-    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_);
-  }
-
-  virtual void TearDown() {
-    free(mix_buffer_);
-    free(compare_buffer_);
-    free(src_buffer_);
-  }
-
-  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];
-    }
-  }
-
-  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;
-    }
-
-    cras_mix_add_scale_stride(fmt_, (uint8_t*)mix_buffer_,
-                              (uint8_t*)src_buffer_, kBufferFrames, 8, 4,
-                              scaler);
-
-    EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 8));
-  }
-
-  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 > 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] = Scale(mix_buffer_[i], applied_scaler);
+      for (size_t i = 0; i < kBufferFrames * 2; i++) {
+        src_buffer_[i] = i;
+        mix_buffer_[i] = -i;
       }
 
-      if (i % 2 == 1)
-        scaler += increment;
+      compare_buffer_ = (int32_t *)malloc(kBufferFrames * fr_bytes_);
     }
-  }
 
-  int32_t Scale(int32_t value, float scaler) {
-    value = ((uint32_t)(value & 0x00ffffff)) << 8;
-    value *= scaler;
-    return (value >> 8) & 0x00ffffff;
-  }
+    virtual void TearDown() {
+      free(mix_buffer_);
+      free(compare_buffer_);
+      free(src_buffer_);
+    }
 
-  int32_t* mix_buffer_;
-  int32_t* src_buffer_;
-  int32_t* compare_buffer_;
+    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];
+      }
+    }
+
+    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 > 0x007fffff)
+          tmp = 0x007fffff;
+        else if (tmp < (int32_t)0xff800000)
+          tmp = (int32_t)0xff800000;
+        compare_buffer_[i] = tmp;
+      }
+
+      cras_mix_add_scale_stride(
+          fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_,
+          kBufferFrames, 8, 4, scaler);
+
+      EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 8));
+    }
+
+    void ScaleIncrement(float start_scaler, float increment) {
+      float scaler = start_scaler;
+      for (size_t i = 0; i < kBufferFrames * 2; i++) {
+        if (scaler > 0.9999999) {
+        } else if (scaler < 0.0000001) {
+          compare_buffer_[i] = 0;
+        } else {
+          compare_buffer_[i] = mix_buffer_[i] * scaler;
+        }
+        if (i % 2 == 1)
+          scaler += increment;
+      }
+    }
+
+  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);
+    compare_buffer_[i] = src_buffer_[i] * 2;
   EXPECT_EQ(0, memcmp(mix_buffer_, compare_buffer_, kBufferFrames * fr_bytes_));
 }
 
 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;
@@ -444,8 +391,8 @@
 }
 
 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;
@@ -453,8 +400,8 @@
 }
 
 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;
@@ -462,22 +409,22 @@
 }
 
 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);
+    compare_buffer_[i] = src_buffer_[i] * 0.5;
   EXPECT_EQ(0, memcmp(mix_buffer_, compare_buffer_, kBufferFrames * fr_bytes_));
 }
 
 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);
+    compare_buffer_[i] = src_buffer_[i] + (int32_t)(src_buffer_[i] * 0.5);
   EXPECT_EQ(0, memcmp(mix_buffer_, compare_buffer_, kBufferFrames * fr_bytes_));
 }
 
@@ -485,13 +432,12 @@
   float increment = 0.01;
   int step = 2;
   float start_scaler = 0.999999999;
-  float target = 1.0;
 
   _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, step);
 
   EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_));
 }
@@ -500,13 +446,12 @@
   float increment = -0.01;
   int step = 2;
   float start_scaler = 0.000000001;
-  float target = 0.0;
 
   _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, step);
 
   EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_));
 }
@@ -515,13 +460,12 @@
   float increment = 0.0001;
   int step = 2;
   float start_scaler = 0.1;
-  float target = 1.0;
 
   _SetupBuffer();
-  ScaleIncrement(start_scaler, increment, target);
+  ScaleIncrement(start_scaler, increment);
 
-  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, step);
   EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_));
 }
 
@@ -529,13 +473,12 @@
   float increment = -0.0001;
   int step = 2;
   float start_scaler = 0.8;
-  float target = 0.0;
 
   _SetupBuffer();
-  ScaleIncrement(start_scaler, increment, target);
+  ScaleIncrement(start_scaler, increment);
 
-  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, step);
 
   EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_));
 }
@@ -544,13 +487,12 @@
   float increment = -0.0001;
   int step = 2;
   float start_scaler = 1.0;
-  float target = 0.0;
 
   _SetupBuffer();
-  ScaleIncrement(start_scaler, increment, target);
+  ScaleIncrement(start_scaler, increment);
 
-  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, step);
 
   EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4));
 }
@@ -559,63 +501,34 @@
   float increment = 0.0001;
   int step = 2;
   float start_scaler = 0.0;
-  float target = 1.0;
 
   _SetupBuffer();
-  ScaleIncrement(start_scaler, increment, target);
+  ScaleIncrement(start_scaler, increment);
 
-  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, step);
 
   EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4));
 }
 
-TEST_F(MixTestSuiteS24_LE, ScaleVolumePositiveIncrementCappedByTarget) {
-  float increment = 0.0001;
-  int step = 2;
-  float start_scaler = 0.1;
-  float target = 0.5;
-
-  _SetupBuffer();
-  ScaleIncrement(start_scaler, increment, target);
-
-  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, ScaleVolumeNegativeIncrementCappedByTarget) {
-  float increment = -0.01;
-  int step = 2;
-  float start_scaler = 0.8;
-  float target = 0.5;
-
-  _SetupBuffer();
-  ScaleIncrement(start_scaler, increment, target);
-
-  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_));
 }
 
 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);
+    compare_buffer_[i] = src_buffer_[i] * 0.5;
+  cras_scale_buffer(fmt_, (uint8_t *)src_buffer_, kNumSamples, 0.5);
 
   EXPECT_EQ(0, memcmp(compare_buffer_, src_buffer_, kBufferFrames * fr_bytes_));
 }
@@ -626,104 +539,96 @@
   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)));
+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_area)));
 
-    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_);
-  }
-
-  virtual void TearDown() {
-    free(mix_buffer_);
-    free(compare_buffer_);
-    free(src_buffer_);
-  }
-
-  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];
-    }
-  }
-
-  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;
-    }
-
-    cras_mix_add_scale_stride(fmt_, (uint8_t*)mix_buffer_,
-                              (uint8_t*)src_buffer_, kBufferFrames, 8, 4,
-                              scaler);
-
-    EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 8));
-  }
-
-  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 > 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;
+      for (size_t i = 0; i < kBufferFrames * 2; i++) {
+        src_buffer_[i] = i;
+        mix_buffer_[i] = -i;
       }
 
-      if (i % 2 == 1)
-        scaler += increment;
+      compare_buffer_ = (int32_t *)malloc(kBufferFrames * fr_bytes_);
     }
-  }
 
-  int32_t* mix_buffer_;
-  int32_t* src_buffer_;
-  int32_t* compare_buffer_;
+    virtual void TearDown() {
+      free(mix_buffer_);
+      free(compare_buffer_);
+      free(src_buffer_);
+    }
+
+    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];
+      }
+    }
+
+    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;
+      }
+
+      cras_mix_add_scale_stride(
+          fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_,
+          kBufferFrames, 8, 4, scaler);
+
+      EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 8));
+    }
+
+    void ScaleIncrement(float start_scaler, float increment) {
+      float scaler = start_scaler;
+      for (size_t i = 0; i < kBufferFrames * 2; i++) {
+        if (scaler > 0.9999999) {
+        } else if (scaler < 0.0000001) {
+          compare_buffer_[i] = 0;
+        } else {
+          compare_buffer_[i] = mix_buffer_[i] * scaler;
+        }
+        if (i % 2 == 1)
+          scaler += increment;
+      }
+    }
+
+  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;
@@ -731,12 +636,12 @@
 }
 
 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;
@@ -744,8 +649,8 @@
 }
 
 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;
@@ -753,8 +658,8 @@
 }
 
 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;
@@ -762,8 +667,8 @@
 }
 
 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;
@@ -771,10 +676,10 @@
 }
 
 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);
@@ -785,13 +690,12 @@
   float increment = 0.01;
   int step = 2;
   float start_scaler = 0.999999999;
-  float target = 1.0;
 
   _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, step);
 
   EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_));
 }
@@ -800,13 +704,12 @@
   float increment = -0.01;
   int step = 2;
   float start_scaler = 0.000000001;
-  float target = 0.0;
 
   _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, step);
 
   EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_));
 }
@@ -815,13 +718,12 @@
   float increment = 0.0001;
   int step = 2;
   float start_scaler = 0.1;
-  float target = 1.0;
 
   _SetupBuffer();
-  ScaleIncrement(start_scaler, increment, target);
+  ScaleIncrement(start_scaler, increment);
 
-  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, step);
   EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_));
 }
 
@@ -829,13 +731,12 @@
   float increment = -0.0001;
   int step = 2;
   float start_scaler = 0.8;
-  float target = 0.0;
 
   _SetupBuffer();
-  ScaleIncrement(start_scaler, increment, target);
+  ScaleIncrement(start_scaler, increment);
 
-  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, step);
 
   EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_));
 }
@@ -844,13 +745,12 @@
   float increment = -0.0001;
   int step = 2;
   float start_scaler = 1.0;
-  float target = 0.0;
 
   _SetupBuffer();
-  ScaleIncrement(start_scaler, increment, target);
+  ScaleIncrement(start_scaler, increment);
 
-  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, step);
 
   EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4));
 }
@@ -859,55 +759,26 @@
   float increment = 0.0001;
   int step = 2;
   float start_scaler = 0.0;
-  float target = 1.0;
 
   _SetupBuffer();
-  ScaleIncrement(start_scaler, increment, target);
+  ScaleIncrement(start_scaler, increment);
 
-  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, step);
 
   EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4));
 }
 
-TEST_F(MixTestSuiteS32_LE, ScaleVolumePositiveIncrementCappedByTarget) {
-  float increment = 0.0001;
-  int step = 2;
-  float start_scaler = 0.1;
-  float target = 0.5;
-
-  _SetupBuffer();
-  ScaleIncrement(start_scaler, increment, target);
-
-  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, ScaleVolumeNegativeIncrementCappedByTarget) {
-  float increment = -0.01;
-  int step = 2;
-  float start_scaler = 0.8;
-  float target = 0.5;
-
-  _SetupBuffer();
-  ScaleIncrement(start_scaler, increment, target);
-
-  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_));
 }
@@ -915,7 +786,7 @@
 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_));
 }
@@ -926,187 +797,181 @@
   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_area)));
 
-    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_);
-  }
-
-  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);
-    }
-  }
-
-  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);
-    }
-
-    cras_mix_add_scale_stride(fmt_, (uint8_t*)mix_buffer_,
-                              (uint8_t*)src_buffer_, kBufferFrames, 6, 3,
-                              scaler);
-
-    EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 6));
-  }
-
-  void ScaleIncrement(float start_scaler, float increment, float target) {
-    float scaler = start_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);
-
-      if ((applied_scaler > target && increment > 0) ||
-          (applied_scaler < target && increment < 0))
-        applied_scaler = target;
-
-      if (applied_scaler > kMaxVolumeToScale) {
-      } else if (applied_scaler < kMinVolumeToScale) {
-        tmp = 0;
-      } else {
-        tmp *= applied_scaler;
+      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);
       }
 
-      memcpy(compare_buffer_ + 3 * i, (uint8_t*)&tmp + 1, 3);
-
-      if (i % 2 == 1)
-        scaler += increment;
+      compare_buffer_ = (uint8_t *)malloc(kBufferFrames * fr_bytes_);
     }
-  }
 
-  uint8_t* mix_buffer_;
-  uint8_t* src_buffer_;
-  uint8_t* compare_buffer_;
+    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);
+      }
+    }
+
+    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);
+      }
+
+      cras_mix_add_scale_stride(
+          fmt_, (uint8_t *)mix_buffer_, (uint8_t *)src_buffer_,
+          kBufferFrames, 6, 3, scaler);
+
+      EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 6));
+    }
+
+    void ScaleIncrement(float start_scaler, float increment) {
+      float scaler = start_scaler;
+      for (size_t i = 0; i < kBufferFrames * kNumChannels; i++) {
+        int32_t tmp = 0;
+        memcpy((uint8_t *)&tmp + 1, src_buffer_ + 3*i, 3);
+
+        if (scaler > 0.9999999) {
+	} else if (scaler < 0.0000001) {
+	  tmp = 0;
+        } else {
+          tmp *= 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_;
   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_));
 }
@@ -1115,13 +980,12 @@
   float increment = 0.01;
   int step = 2;
   float start_scaler = 0.999999999;
-  float target = 1.0;
 
   _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, step);
 
   EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_));
 }
@@ -1130,13 +994,12 @@
   float increment = -0.01;
   int step = 2;
   float start_scaler = 0.000000001;
-  float target = 0.0;
 
   _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, step);
 
   EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_));
 }
@@ -1145,13 +1008,12 @@
   float increment = 0.0001;
   int step = 2;
   float start_scaler = 0.1;
-  float target = 1.0;
 
   _SetupBuffer();
-  ScaleIncrement(start_scaler, increment, target);
+  ScaleIncrement(start_scaler, increment);
 
-  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, step);
   EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_));
 }
 
@@ -1159,13 +1021,12 @@
   float increment = -0.0001;
   int step = 2;
   float start_scaler = 0.8;
-  float target = 0.0;
 
   _SetupBuffer();
-  ScaleIncrement(start_scaler, increment, target);
+  ScaleIncrement(start_scaler, increment);
 
-  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, step);
 
   EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * fr_bytes_));
 }
@@ -1174,13 +1035,12 @@
   float increment = -0.0001;
   int step = 2;
   float start_scaler = 1.0;
-  float target = 0.0;
 
   _SetupBuffer();
-  ScaleIncrement(start_scaler, increment, target);
+  ScaleIncrement(start_scaler, increment);
 
-  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, step);
 
   EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4));
 }
@@ -1189,55 +1049,26 @@
   float increment = 0.0001;
   int step = 2;
   float start_scaler = 0.0;
-  float target = 1.0;
 
   _SetupBuffer();
-  ScaleIncrement(start_scaler, increment, target);
+  ScaleIncrement(start_scaler, increment);
 
-  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, step);
 
   EXPECT_EQ(0, memcmp(compare_buffer_, mix_buffer_, kBufferFrames * 4));
 }
 
-TEST_F(MixTestSuiteS24_3LE, ScaleVolumePositiveIncrementCappedByTarget) {
-  float increment = 0.0001;
-  int step = 2;
-  float start_scaler = 0.1;
-  float target = 0.5;
-
-  _SetupBuffer();
-  ScaleIncrement(start_scaler, increment, target);
-
-  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, ScaleVolumeNegativeIncrementCappedByTarget) {
-  float increment = -0.01;
-  int step = 2;
-  float start_scaler = 0.8;
-  float target = 0.5;
-
-  _SetupBuffer();
-  ScaleIncrement(start_scaler, increment, target);
-
-  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_));
 }
@@ -1245,11 +1076,11 @@
 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_));
 }
@@ -1261,11 +1092,13 @@
 }
 
 /* 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 5c9ca14..899590f 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 <map>
 #include <vector>
+#include <map>
 
 extern "C" {
 #include "cras_observer.c"
@@ -17,17 +17,17 @@
 
 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,16 +102,14 @@
 }
 
 /* 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);
@@ -119,14 +117,14 @@
   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);
@@ -134,14 +132,14 @@
 }
 
 /* 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++;
@@ -151,7 +149,7 @@
 }
 
 /* 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++;
@@ -161,7 +159,7 @@
 }
 
 /* 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++;
@@ -171,7 +169,7 @@
 }
 
 /* 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++;
@@ -181,9 +179,9 @@
 }
 
 /* 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);
@@ -199,47 +197,44 @@
     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_));
@@ -247,8 +242,8 @@
     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() {
@@ -257,11 +252,11 @@
     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);
@@ -270,10 +265,10 @@
     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_);
@@ -288,7 +283,7 @@
 
     // 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_);
@@ -302,24 +297,24 @@
     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;
@@ -333,7 +328,7 @@
 };
 
 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;
@@ -341,9 +336,9 @@
   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);
@@ -363,15 +358,15 @@
 };
 
 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;
@@ -385,16 +380,16 @@
 };
 
 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);
 
@@ -423,16 +418,16 @@
 };
 
 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);
 
@@ -449,7 +444,7 @@
 };
 
 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;
 
@@ -457,9 +452,9 @@
   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);
 
@@ -476,7 +471,7 @@
 };
 
 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;
 
@@ -484,9 +479,9 @@
   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);
 
@@ -503,16 +498,17 @@
 };
 
 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);
 
@@ -529,27 +525,29 @@
 };
 
 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;
 
@@ -557,9 +555,9 @@
   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);
 
@@ -576,65 +574,63 @@
 };
 
 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)
@@ -642,7 +638,8 @@
   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;
 }
 
@@ -654,7 +651,7 @@
 
 }  // 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
deleted file mode 100644
index aa24bc2..0000000
--- a/cras/src/tests/playback_rclient_unittest.cc
+++ /dev/null
@@ -1,331 +0,0 @@
-// 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 c18fdf7..c799387 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 <gtest/gtest.h>
 #include <stdio.h>
+#include <gtest/gtest.h>
 
 extern "C" {
 #include "polled_interval_checker.h"
@@ -14,15 +14,15 @@
 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 @@
   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 @@
   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 @@
   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 @@
 /* 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 8d67479..7bd8fac 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 <gtest/gtest.h>
 #include <stdio.h>
+#include <gtest/gtest.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 @@
 namespace {
 
 TEST(RampTestSuite, Init) {
-  struct cras_ramp* ramp;
+  struct cras_ramp *ramp;
   struct cras_ramp_action action;
 
   ResetStubData();
@@ -31,49 +31,45 @@
   EXPECT_EQ(action.type, CRAS_RAMP_ACTION_NONE);
   EXPECT_FLOAT_EQ(1.0, action.scaler);
   EXPECT_FLOAT_EQ(0.0, action.increment);
-  EXPECT_FLOAT_EQ(1.0, action.target);
 
   cras_ramp_destroy(ramp);
 }
 
 TEST(RampTestSuite, RampUpInitialIncrement) {
-  float from = 0.0;
-  float to = 1.0;
+  int ramp_up = 1;
   int duration_frames = 48000;
   float increment = 1.0 / 48000;
-  cras_ramp* ramp;
+  cras_ramp *ramp;
   cras_ramp_action action;
 
   ResetStubData();
 
   ramp = cras_ramp_create();
-  cras_mute_ramp_start(ramp, from, to, duration_frames, NULL, NULL);
+  cras_ramp_start(ramp, ramp_up, duration_frames, NULL, NULL);
 
   action = cras_ramp_get_current_action(ramp);
 
   EXPECT_EQ(CRAS_RAMP_ACTION_PARTIAL, action.type);
   EXPECT_FLOAT_EQ(0.0, action.scaler);
   EXPECT_FLOAT_EQ(increment, action.increment);
-  EXPECT_FLOAT_EQ(to, action.target);
 
   cras_ramp_destroy(ramp);
 }
 
 TEST(RampTestSuite, RampUpUpdateRampedFrames) {
-  float from = 0.0;
-  float to = 1.0;
+  int ramp_up = 1;
   int duration_frames = 48000;
   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;
 
   ResetStubData();
 
   ramp = cras_ramp_create();
-  cras_mute_ramp_start(ramp, from, to, duration_frames, NULL, NULL);
+  cras_ramp_start(ramp, ramp_up, duration_frames, NULL, NULL);
 
   rc = cras_ramp_update_ramped_frames(ramp, ramped_frames);
 
@@ -83,24 +79,22 @@
   EXPECT_EQ(CRAS_RAMP_ACTION_PARTIAL, action.type);
   EXPECT_FLOAT_EQ(scaler, action.scaler);
   EXPECT_FLOAT_EQ(increment, action.increment);
-  EXPECT_FLOAT_EQ(to, action.target);
 
   cras_ramp_destroy(ramp);
 }
 
 TEST(RampTestSuite, RampUpPassedRamp) {
-  float from = 0.0;
-  float to = 1.0;
+  int ramp_up = 1;
   int duration_frames = 48000;
   int rc;
   int ramped_frames = 48000;
-  struct cras_ramp* ramp;
+  struct cras_ramp *ramp;
   struct cras_ramp_action action;
 
   ResetStubData();
 
   ramp = cras_ramp_create();
-  cras_mute_ramp_start(ramp, from, to, duration_frames, NULL, NULL);
+  cras_ramp_start(ramp, ramp_up, duration_frames, NULL, NULL);
 
   rc = cras_ramp_update_ramped_frames(ramp, ramped_frames);
 
@@ -110,18 +104,16 @@
   EXPECT_EQ(CRAS_RAMP_ACTION_NONE, action.type);
   EXPECT_FLOAT_EQ(1.0, action.scaler);
   EXPECT_FLOAT_EQ(0.0, action.increment);
-  EXPECT_FLOAT_EQ(1.0, action.target);
 
   cras_ramp_destroy(ramp);
 }
 
 TEST(RampTestSuite, RampUpWhileHalfWayRampDown) {
-  float from;
-  float to;
+  int ramp_up;
   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;
@@ -130,9 +122,8 @@
   ResetStubData();
 
   ramp = cras_ramp_create();
-  from = 1.0;
-  to = 0.0;
-  cras_mute_ramp_start(ramp, from, to, duration_frames, NULL, NULL);
+  ramp_up = 0;
+  cras_ramp_start(ramp, ramp_up, duration_frames, NULL, NULL);
 
   rc = cras_ramp_update_ramped_frames(ramp, ramped_frames);
 
@@ -141,9 +132,8 @@
   // The increment will be calculated by ramping to 1 starting from scaler.
   up_increment = (1 - scaler) / 48000;
 
-  from = 0.0;
-  to = 1.0;
-  cras_mute_ramp_start(ramp, from, to, duration_frames, NULL, NULL);
+  ramp_up = 1;
+  cras_ramp_start(ramp, ramp_up, duration_frames, NULL, NULL);
 
   action = cras_ramp_get_current_action(ramp);
 
@@ -151,18 +141,16 @@
   EXPECT_EQ(CRAS_RAMP_ACTION_PARTIAL, action.type);
   EXPECT_FLOAT_EQ(scaler, action.scaler);
   EXPECT_FLOAT_EQ(up_increment, action.increment);
-  EXPECT_FLOAT_EQ(to, action.target);
 
   cras_ramp_destroy(ramp);
 }
 
 TEST(RampTestSuite, RampUpWhileHalfWayRampUp) {
-  float from = 0.0;
-  float to = 1.0;
+  int ramp_up;
   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;
@@ -171,7 +159,8 @@
   ResetStubData();
 
   ramp = cras_ramp_create();
-  cras_mute_ramp_start(ramp, from, to, duration_frames, NULL, NULL);
+  ramp_up = 1;
+  cras_ramp_start(ramp, ramp_up, duration_frames, NULL, NULL);
 
   rc = cras_ramp_update_ramped_frames(ramp, ramped_frames);
 
@@ -180,7 +169,8 @@
   // The increment will be calculated by ramping to 1 starting from scaler.
   second_increment = (1 - scaler) / 48000;
 
-  cras_mute_ramp_start(ramp, from, to, duration_frames, NULL, NULL);
+  ramp_up = 1;
+  cras_ramp_start(ramp, ramp_up, duration_frames, NULL, NULL);
 
   action = cras_ramp_get_current_action(ramp);
 
@@ -188,49 +178,45 @@
   EXPECT_EQ(CRAS_RAMP_ACTION_PARTIAL, action.type);
   EXPECT_FLOAT_EQ(scaler, action.scaler);
   EXPECT_FLOAT_EQ(second_increment, action.increment);
-  EXPECT_FLOAT_EQ(to, action.target);
 
   cras_ramp_destroy(ramp);
 }
 
 TEST(RampTestSuite, RampDownInitialIncrement) {
-  float from = 1.0;
-  float to = 0.0;
+  int ramp_up = 0;
   int duration_frames = 48000;
   float increment = -1.0 / 48000;
-  cras_ramp* ramp;
+  cras_ramp *ramp;
   cras_ramp_action action;
 
   ResetStubData();
 
   ramp = cras_ramp_create();
-  cras_mute_ramp_start(ramp, from, to, duration_frames, NULL, NULL);
+  cras_ramp_start(ramp, ramp_up, duration_frames, NULL, NULL);
 
   action = cras_ramp_get_current_action(ramp);
 
   EXPECT_EQ(CRAS_RAMP_ACTION_PARTIAL, action.type);
   EXPECT_FLOAT_EQ(1.0, action.scaler);
   EXPECT_FLOAT_EQ(increment, action.increment);
-  EXPECT_FLOAT_EQ(to, action.target);
 
   cras_ramp_destroy(ramp);
 }
 
 TEST(RampTestSuite, RampDownUpdateRampedFrames) {
-  float from = 1.0;
-  float to = 0.0;
+  int ramp_up = 0;
   int duration_frames = 48000;
   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;
 
   ResetStubData();
 
   ramp = cras_ramp_create();
-  cras_mute_ramp_start(ramp, from, to, duration_frames, NULL, NULL);
+  cras_ramp_start(ramp, ramp_up, duration_frames, NULL, NULL);
 
   rc = cras_ramp_update_ramped_frames(ramp, ramped_frames);
 
@@ -240,24 +226,22 @@
   EXPECT_EQ(CRAS_RAMP_ACTION_PARTIAL, action.type);
   EXPECT_FLOAT_EQ(scaler, action.scaler);
   EXPECT_FLOAT_EQ(increment, action.increment);
-  EXPECT_FLOAT_EQ(to, action.target);
 
   cras_ramp_destroy(ramp);
 }
 
 TEST(RampTestSuite, RampDownPassedRamp) {
-  float from = 1.0;
-  float to = 0.0;
+  int ramp_up = 0;
   int duration_frames = 48000;
   int rc;
   int ramped_frames = 48000;
-  struct cras_ramp* ramp;
+  struct cras_ramp *ramp;
   struct cras_ramp_action action;
 
   ResetStubData();
 
   ramp = cras_ramp_create();
-  cras_mute_ramp_start(ramp, from, to, duration_frames, NULL, NULL);
+  cras_ramp_start(ramp, ramp_up, duration_frames, NULL, NULL);
 
   rc = cras_ramp_update_ramped_frames(ramp, ramped_frames);
 
@@ -267,18 +251,16 @@
   EXPECT_EQ(CRAS_RAMP_ACTION_NONE, action.type);
   EXPECT_FLOAT_EQ(1.0, action.scaler);
   EXPECT_FLOAT_EQ(0.0, action.increment);
-  EXPECT_FLOAT_EQ(1.0, action.target);
 
   cras_ramp_destroy(ramp);
 }
 
 TEST(RampTestSuite, RampDownWhileHalfWayRampUp) {
-  float from;
-  float to;
+  int ramp_up;
   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;
@@ -288,9 +270,8 @@
 
   ramp = cras_ramp_create();
   // Ramp up first.
-  from = 0.0;
-  to = 1.0;
-  cras_mute_ramp_start(ramp, from, to, duration_frames, NULL, NULL);
+  ramp_up = 1;
+  cras_ramp_start(ramp, ramp_up, duration_frames, NULL, NULL);
 
   rc = cras_ramp_update_ramped_frames(ramp, ramped_frames);
 
@@ -299,10 +280,10 @@
   // 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;
-  cras_mute_ramp_start(ramp, from, to, duration_frames, NULL, NULL);
+  ramp_up = 0;
+  cras_ramp_start(ramp, ramp_up, duration_frames, NULL, NULL);
 
   action = cras_ramp_get_current_action(ramp);
 
@@ -310,18 +291,16 @@
   EXPECT_EQ(CRAS_RAMP_ACTION_PARTIAL, action.type);
   EXPECT_FLOAT_EQ(scaler, action.scaler);
   EXPECT_FLOAT_EQ(down_increment, action.increment);
-  EXPECT_FLOAT_EQ(to, action.target);
 
   cras_ramp_destroy(ramp);
 }
 
 TEST(RampTestSuite, RampDownWhileHalfWayRampDown) {
-  float from = 1.0;
-  float to = 0.0;
+  int ramp_up;
   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;
@@ -331,7 +310,8 @@
 
   ramp = cras_ramp_create();
   // Ramp down.
-  cras_mute_ramp_start(ramp, from, to, duration_frames, NULL, NULL);
+  ramp_up = 0;
+  cras_ramp_start(ramp, ramp_up, duration_frames, NULL, NULL);
 
   rc = cras_ramp_update_ramped_frames(ramp, ramped_frames);
 
@@ -340,8 +320,10 @@
   // 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);
+  ramp_up = 0;
+  cras_ramp_start(ramp, ramp_up, duration_frames, NULL, NULL);
 
   action = cras_ramp_get_current_action(ramp);
 
@@ -349,76 +331,28 @@
   EXPECT_EQ(CRAS_RAMP_ACTION_PARTIAL, action.type);
   EXPECT_FLOAT_EQ(scaler, action.scaler);
   EXPECT_FLOAT_EQ(second_down_increment, action.increment);
-  EXPECT_FLOAT_EQ(to, action.target);
 
   cras_ramp_destroy(ramp);
 }
 
-TEST(RampTestSuite, PartialRamp) {
-  float from_one = 0.75;
-  float to_one = 0.4;
-  float from_two = 0.6;
-  float to_two = 0.9;
-  int duration_frames = 1200;
-  int rc;
-  int ramped_frames = 600;
-  struct cras_ramp* ramp;
-  struct cras_ramp_action action;
-  float down_increment = (to_one - from_one) / duration_frames;
-  float up_increment;
-  float scaler;
-
-  ResetStubData();
-
-  ramp = cras_ramp_create();
-  // Ramp down.
-  cras_volume_ramp_start(ramp, from_one, to_one, duration_frames, NULL, NULL);
-
-  rc = cras_ramp_update_ramped_frames(ramp, ramped_frames);
-
-  scaler = from_one + ramped_frames * down_increment;
-  action = cras_ramp_get_current_action(ramp);
-  EXPECT_EQ(0, rc);
-  EXPECT_EQ(CRAS_RAMP_ACTION_PARTIAL, action.type);
-  EXPECT_FLOAT_EQ(scaler, action.scaler);
-  EXPECT_FLOAT_EQ(down_increment, action.increment);
-  EXPECT_FLOAT_EQ(to_one, action.target);
-
-  // Ramp up starting from current scaler.
-  cras_volume_ramp_start(ramp, from_two, to_two, duration_frames, NULL, NULL);
-
-  // we start by multiplying by previous scaler
-  scaler = scaler * from_two;
-  action = cras_ramp_get_current_action(ramp);
-  up_increment = (to_two - scaler) / duration_frames;
-  EXPECT_EQ(0, rc);
-  EXPECT_EQ(CRAS_RAMP_ACTION_PARTIAL, action.type);
-  EXPECT_FLOAT_EQ(scaler, action.scaler);
-  EXPECT_FLOAT_EQ(up_increment, action.increment);
-  EXPECT_FLOAT_EQ(to_two, action.target);
-
-  cras_ramp_destroy(ramp);
-}
-
-void ramp_callback(void* arg) {
+void ramp_callback(void *arg) {
   callback_called++;
   callback_arg = arg;
 }
 
 TEST(RampTestSuite, RampUpPassedRampCallback) {
-  float from = 0.0;
-  float to = 1.0;
+  int ramp_up = 1;
   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();
 
   ramp = cras_ramp_create();
-  cras_mute_ramp_start(ramp, from, to, duration_frames, ramp_callback, cb_data);
+  cras_ramp_start(ramp, ramp_up, duration_frames, ramp_callback, cb_data);
 
   rc = cras_ramp_update_ramped_frames(ramp, ramped_frames);
 
@@ -428,7 +362,6 @@
   EXPECT_EQ(CRAS_RAMP_ACTION_NONE, action.type);
   EXPECT_FLOAT_EQ(1.0, action.scaler);
   EXPECT_FLOAT_EQ(0.0, action.increment);
-  EXPECT_FLOAT_EQ(1.0, action.target);
   EXPECT_EQ(1, callback_called);
   EXPECT_EQ(cb_data, callback_arg);
 
@@ -436,19 +369,18 @@
 }
 
 TEST(RampTestSuite, RampDownPassedRampCallback) {
-  float from = 1.0;
-  float to = 0.0;
+  int ramp_up = 0;
   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();
 
   ramp = cras_ramp_create();
-  cras_mute_ramp_start(ramp, from, to, duration_frames, ramp_callback, cb_data);
+  cras_ramp_start(ramp, ramp_up, duration_frames, ramp_callback, cb_data);
 
   rc = cras_ramp_update_ramped_frames(ramp, ramped_frames);
 
@@ -458,7 +390,6 @@
   EXPECT_EQ(CRAS_RAMP_ACTION_NONE, action.type);
   EXPECT_FLOAT_EQ(1.0, action.scaler);
   EXPECT_FLOAT_EQ(0.0, action.increment);
-  EXPECT_FLOAT_EQ(1.0, action.target);
   EXPECT_EQ(1, callback_called);
   EXPECT_EQ(cb_data, callback_arg);
 
@@ -467,7 +398,7 @@
 
 }  // 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 66f7c58..23922c1 100644
--- a/cras/src/tests/rate_estimator_unittest.cc
+++ b/cras/src/tests/rate_estimator_unittest.cc
@@ -8,11 +8,17 @@
 #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);
@@ -37,8 +43,11 @@
 }
 
 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;
 
@@ -66,8 +75,11 @@
 }
 
 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;
 
@@ -94,7 +106,7 @@
 }
 
 TEST(RateEstimatorTest, EstimateOutputSmooth) {
-  struct rate_estimator* re;
+  struct rate_estimator *re;
   struct timespec t;
   int rc;
 
@@ -123,7 +135,7 @@
 }
 
 TEST(RateEstimatorTest, EstimateInputLinear) {
-  struct rate_estimator* re;
+  struct rate_estimator *re;
   struct timespec t;
   int i, rc, level, tmp;
 
@@ -150,10 +162,13 @@
 }
 
 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;
@@ -178,7 +193,7 @@
   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/rclient_unittest.cc b/cras/src/tests/rclient_unittest.cc
new file mode 100644
index 0000000..0d32c2a
--- /dev/null
+++ b/cras/src/tests/rclient_unittest.cc
@@ -0,0 +1,969 @@
+// Copyright (c) 2012 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 <stdio.h>
+#include <gtest/gtest.h>
+#include <unistd.h>
+
+extern "C" {
+#include "audio_thread.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_rclient.c"
+}
+
+//  Stub data.
+static int cras_rstream_create_return;
+static struct cras_rstream *cras_rstream_create_stream_out;
+static int cras_iodev_attach_stream_retval;
+static size_t cras_system_set_volume_value;
+static int cras_system_set_volume_called;
+static size_t cras_system_set_capture_gain_value;
+static int cras_system_set_capture_gain_called;
+static size_t cras_system_set_mute_value;
+static int cras_system_set_mute_called;
+static size_t cras_system_set_user_mute_value;
+static int cras_system_set_user_mute_called;
+static size_t cras_system_set_mute_locked_value;
+static int cras_system_set_mute_locked_called;
+static size_t cras_system_set_capture_mute_value;
+static int cras_system_set_capture_mute_called;
+static size_t cras_system_set_capture_mute_locked_value;
+static int cras_system_set_capture_mute_locked_called;
+static int cras_system_state_dump_snapshots_called;
+static size_t cras_make_fd_nonblocking_called;
+static audio_thread* iodev_get_thread_return;
+static int stream_list_add_stream_return;
+static unsigned int stream_list_add_stream_called;
+static unsigned int stream_list_disconnect_stream_called;
+static unsigned int cras_iodev_list_rm_input_called;
+static unsigned int cras_iodev_list_rm_output_called;
+static unsigned int cras_server_metrics_stream_config_called;
+static struct cras_rstream dummy_rstream;
+static size_t cras_observer_num_ops_registered;
+static size_t cras_observer_register_notify_called;
+static size_t cras_observer_add_called;
+static void *cras_observer_add_context_value;
+static struct cras_observer_client *cras_observer_add_return_value;
+static size_t cras_observer_get_ops_called;
+static struct cras_observer_ops cras_observer_ops_value;
+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;
+
+void ResetStubData() {
+  cras_rstream_create_return = 0;
+  cras_rstream_create_stream_out = (struct cras_rstream *)NULL;
+  cras_iodev_attach_stream_retval = 0;
+  cras_server_metrics_stream_config_called = 0;
+  cras_system_set_volume_value = 0;
+  cras_system_set_volume_called = 0;
+  cras_system_set_capture_gain_value = 0;
+  cras_system_set_capture_gain_called = 0;
+  cras_system_set_mute_value = 0;
+  cras_system_set_mute_called = 0;
+  cras_system_set_user_mute_value = 0;
+  cras_system_set_user_mute_called = 0;
+  cras_system_set_mute_locked_value = 0;
+  cras_system_set_mute_locked_called = 0;
+  cras_system_set_capture_mute_value = 0;
+  cras_system_set_capture_mute_called = 0;
+  cras_system_set_capture_mute_locked_value = 0;
+  cras_system_set_capture_mute_locked_called = 0;
+  cras_system_state_dump_snapshots_called = 0;
+  cras_make_fd_nonblocking_called = 0;
+  iodev_get_thread_return = reinterpret_cast<audio_thread*>(0xad);
+  stream_list_add_stream_return = 0;
+  stream_list_add_stream_called = 0;
+  stream_list_disconnect_stream_called = 0;
+  cras_iodev_list_rm_output_called = 0;
+  cras_iodev_list_rm_input_called = 0;
+  cras_observer_num_ops_registered = 0;
+  cras_observer_register_notify_called = 0;
+  cras_observer_add_called = 0;
+  cras_observer_add_return_value =
+      reinterpret_cast<struct cras_observer_client *>(1);
+  cras_observer_add_context_value = NULL;
+  cras_observer_get_ops_called = 0;
+  memset(&cras_observer_ops_value, 0, sizeof(cras_observer_ops_value));
+  cras_observer_set_ops_called = 0;
+  cras_observer_ops_are_empty_called = 0;
+  memset(&cras_observer_ops_are_empty_empty_ops, 0,
+         sizeof(cras_observer_ops_are_empty_empty_ops));
+  cras_observer_remove_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_rclient_create(pipe_fds[1], 800);
+  ASSERT_NE((void *)NULL, rclient);
+
+  rc = read(pipe_fds[0], &msg, sizeof(msg));
+  EXPECT_EQ(sizeof(msg), rc);
+  EXPECT_EQ(CRAS_CLIENT_CONNECTED, msg.header.id);
+
+  cras_rclient_destroy(rclient);
+  close(pipe_fds[0]);
+  close(pipe_fds[1]);
+}
+
+class RClientMessagesSuite : public testing::Test {
+  protected:
+    virtual void SetUp() {
+      int rc;
+      struct cras_client_connected msg;
+
+      rc = pipe(pipe_fds_);
+      if (rc < 0)
+        return;
+      rclient_ = cras_rclient_create(pipe_fds_[1], 800);
+      rc = read(pipe_fds_[0], &msg, sizeof(msg));
+      if (rc < 0)
+        return;
+
+      rstream_ = (struct cras_rstream *)calloc(1, sizeof(*rstream_));
+
+      stream_id_ = 0x10002;
+      connect_msg_.header.id = CRAS_SERVER_CONNECT_STREAM;
+      connect_msg_.header.length = sizeof(connect_msg_);
+      connect_msg_.proto_version = CRAS_PROTO_VER;
+      connect_msg_.stream_type = CRAS_STREAM_TYPE_DEFAULT;
+      connect_msg_.direction = CRAS_STREAM_OUTPUT;
+      connect_msg_.stream_id = stream_id_;
+      connect_msg_.buffer_frames = 480;
+      connect_msg_.cb_threshold = 240;
+      connect_msg_.flags = 0;
+      connect_msg_.format.num_channels = 2;
+      connect_msg_.format.frame_rate = 48000;
+      connect_msg_.format.format = SND_PCM_FORMAT_S16_LE;
+      connect_msg_.dev_idx = NO_DEVICE;
+
+      ResetStubData();
+    }
+
+    virtual void TearDown() {
+      cras_rclient_destroy(rclient_);
+      free(rstream_);
+      close(pipe_fds_[0]);
+      close(pipe_fds_[1]);
+    }
+
+    void RegisterNotification(enum CRAS_CLIENT_MESSAGE_ID msg_id,
+                              void *callback, void **ops_address);
+
+    struct cras_connect_message connect_msg_;
+    struct cras_rclient *rclient_;
+    struct cras_rstream *rstream_;
+    size_t stream_id_;
+    int pipe_fds_[2];
+};
+
+TEST_F(RClientMessagesSuite, AudThreadAttachFail) {
+  struct cras_client_stream_connected out_msg;
+  int rc;
+
+  cras_rstream_create_stream_out = rstream_;
+  stream_list_add_stream_return = -EINVAL;
+
+  rc = cras_rclient_message_from_client(rclient_, &connect_msg_.header, 100);
+  EXPECT_EQ(0, 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, 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, ConnectMsgWithBadFd) {
+  struct cras_client_stream_connected out_msg;
+  int rc;
+
+  rc = cras_rclient_message_from_client(rclient_, &connect_msg_.header, -1);
+  EXPECT_EQ(0, 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(stream_list_add_stream_called,
+            stream_list_disconnect_stream_called);
+  EXPECT_EQ(0, cras_server_metrics_stream_config_called);
+}
+
+TEST_F(RClientMessagesSuite, ConnectMsgFromOldClient) {
+  struct cras_client_stream_connected_old 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 = CRAS_PROTO_VER - 1;
+
+  rc = cras_rclient_message_from_client(rclient_, &connect_msg_.header, 100);
+  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, 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, SuccessReply) {
+  struct cras_client_stream_connected out_msg;
+  int rc;
+
+  cras_rstream_create_stream_out = rstream_;
+  cras_iodev_attach_stream_retval = 0;
+
+  rc = cras_rclient_message_from_client(rclient_, &connect_msg_.header, 100);
+  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, 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, SuccessCreateThreadReply) {
+  struct cras_client_stream_connected out_msg;
+  int rc;
+
+  cras_rstream_create_stream_out = rstream_;
+  cras_iodev_attach_stream_retval = 0;
+
+  rc = cras_rclient_message_from_client(rclient_, &connect_msg_.header, 100);
+  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, 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, SetVolume) {
+  struct cras_set_system_volume msg;
+  int rc;
+
+  msg.header.id = CRAS_SERVER_SET_SYSTEM_VOLUME;
+  msg.header.length = sizeof(msg);
+  msg.volume = 66;
+
+  rc = cras_rclient_message_from_client(rclient_, &msg.header, -1);
+  EXPECT_EQ(0, rc);
+  EXPECT_EQ(1, cras_system_set_volume_called);
+  EXPECT_EQ(66, cras_system_set_volume_value);
+}
+
+TEST_F(RClientMessagesSuite, SetCaptureVolume) {
+  struct cras_set_system_volume msg;
+  int rc;
+
+  msg.header.id = CRAS_SERVER_SET_SYSTEM_CAPTURE_GAIN;
+  msg.header.length = sizeof(msg);
+  msg.volume = 66;
+
+  rc = cras_rclient_message_from_client(rclient_, &msg.header, -1);
+  EXPECT_EQ(0, rc);
+  EXPECT_EQ(1, cras_system_set_capture_gain_called);
+  EXPECT_EQ(66, cras_system_set_capture_gain_value);
+}
+
+TEST_F(RClientMessagesSuite, SetMute) {
+  struct cras_set_system_mute msg;
+  int rc;
+
+  msg.header.id = CRAS_SERVER_SET_SYSTEM_MUTE;
+  msg.header.length = sizeof(msg);
+  msg.mute = 1;
+
+  rc = cras_rclient_message_from_client(rclient_, &msg.header, -1);
+  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 = cras_rclient_message_from_client(rclient_, &msg.header, -1);
+  EXPECT_EQ(0, rc);
+  EXPECT_EQ(1, cras_system_set_mute_locked_called);
+  EXPECT_EQ(1, cras_system_set_mute_locked_value);
+}
+
+TEST_F(RClientMessagesSuite, SetUserMute) {
+  struct cras_set_system_mute msg;
+  int rc;
+
+  msg.header.id = CRAS_SERVER_SET_USER_MUTE;
+  msg.header.length = sizeof(msg);
+  msg.mute = 1;
+
+  rc = cras_rclient_message_from_client(rclient_, &msg.header, -1);
+  EXPECT_EQ(0, rc);
+  EXPECT_EQ(1, cras_system_set_user_mute_called);
+  EXPECT_EQ(1, cras_system_set_user_mute_value);
+}
+
+TEST_F(RClientMessagesSuite, SetCaptureMute) {
+  struct cras_set_system_mute msg;
+  int rc;
+
+  msg.header.id = CRAS_SERVER_SET_SYSTEM_CAPTURE_MUTE;
+  msg.header.length = sizeof(msg);
+  msg.mute = 1;
+
+  rc = cras_rclient_message_from_client(rclient_, &msg.header, -1);
+  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 = cras_rclient_message_from_client(rclient_, &msg.header, -1);
+  EXPECT_EQ(0, rc);
+  EXPECT_EQ(1, cras_system_set_capture_mute_locked_called);
+  EXPECT_EQ(1, cras_system_set_capture_mute_locked_value);
+}
+
+TEST_F(RClientMessagesSuite, DumpSnapshots) {
+  struct cras_dump_snapshots msg;
+  int rc;
+  cras_fill_dump_snapshots(&msg);
+  rc = cras_rclient_message_from_client(rclient_, &msg.header, -1);
+  EXPECT_EQ(0, rc);
+  EXPECT_EQ(1, cras_system_state_dump_snapshots_called);
+}
+
+void RClientMessagesSuite::RegisterNotification(
+    enum CRAS_CLIENT_MESSAGE_ID msg_id,
+    void *callback, void **ops_address) {
+  struct cras_register_notification msg;
+  int do_register = callback != NULL ? 1 : 0;
+  int rc;
+
+  cras_observer_register_notify_called++;
+
+  cras_fill_register_notification_message(&msg, msg_id, do_register);
+  EXPECT_EQ(msg.header.length, sizeof(msg));
+  EXPECT_EQ(msg.header.id, CRAS_SERVER_REGISTER_NOTIFICATION);
+  EXPECT_EQ(msg.do_register, do_register);
+  EXPECT_EQ(msg.msg_id, msg_id);
+
+  rc = cras_rclient_message_from_client(rclient_, &msg.header, -1);
+  EXPECT_EQ(0, rc);
+  EXPECT_EQ(cras_observer_register_notify_called, cras_observer_get_ops_called);
+  EXPECT_EQ(cras_observer_register_notify_called,\
+            cras_observer_ops_are_empty_called);
+  if (msg.do_register)
+    cras_observer_num_ops_registered++;
+  if (cras_observer_num_ops_registered == 1) {
+    if (msg.do_register) {
+      EXPECT_EQ(1, cras_observer_add_called);
+      EXPECT_EQ(rclient_, cras_observer_add_context_value);
+      EXPECT_EQ(rclient_->observer, cras_observer_add_return_value);
+    } else {
+      EXPECT_EQ(1, cras_observer_remove_called);
+      EXPECT_EQ(rclient_->observer, (struct cras_observer_client *)NULL);
+    }
+  } else {
+    EXPECT_EQ(cras_observer_register_notify_called - 1,\
+              cras_observer_set_ops_called);
+  }
+  if (!msg.do_register)
+    cras_observer_num_ops_registered--;
+  if (cras_observer_num_ops_registered) {
+    EXPECT_EQ(callback, *ops_address);
+  }
+}
+
+TEST_F(RClientMessagesSuite, RegisterStatusNotification) {
+  /* First registration for this client. */
+  RegisterNotification(
+      CRAS_CLIENT_OUTPUT_VOLUME_CHANGED,
+      (void *)send_output_volume_changed,
+      (void **)&cras_observer_ops_value.output_volume_changed);
+
+  /* Second registration for this client. */
+  RegisterNotification(
+      CRAS_CLIENT_CAPTURE_GAIN_CHANGED,
+      (void *)send_capture_gain_changed,
+      (void **)&cras_observer_ops_value.capture_gain_changed);
+
+  /* Deregister output_volume. */
+  RegisterNotification(
+      CRAS_CLIENT_OUTPUT_VOLUME_CHANGED, NULL,
+      (void **)&cras_observer_ops_value.output_volume_changed);
+
+  /* Register/deregister all msg_ids. */
+
+  RegisterNotification(
+      CRAS_CLIENT_OUTPUT_MUTE_CHANGED,
+      (void *)send_output_mute_changed,
+      (void **)&cras_observer_ops_value.output_mute_changed);
+  RegisterNotification(
+      CRAS_CLIENT_OUTPUT_MUTE_CHANGED, NULL,
+      (void **)&cras_observer_ops_value.output_mute_changed);
+
+  RegisterNotification(
+      CRAS_CLIENT_CAPTURE_MUTE_CHANGED,
+      (void *)send_capture_mute_changed,
+      (void **)&cras_observer_ops_value.capture_mute_changed);
+  RegisterNotification(
+      CRAS_CLIENT_CAPTURE_MUTE_CHANGED, NULL,
+      (void **)&cras_observer_ops_value.capture_mute_changed);
+
+  RegisterNotification(
+      CRAS_CLIENT_NODES_CHANGED,
+      (void *)send_nodes_changed,
+      (void **)&cras_observer_ops_value.nodes_changed);
+  RegisterNotification(
+      CRAS_CLIENT_NODES_CHANGED, NULL,
+      (void **)&cras_observer_ops_value.nodes_changed);
+
+  RegisterNotification(
+      CRAS_CLIENT_ACTIVE_NODE_CHANGED,
+      (void *)send_active_node_changed,
+      (void **)&cras_observer_ops_value.active_node_changed);
+  RegisterNotification(
+      CRAS_CLIENT_ACTIVE_NODE_CHANGED, NULL,
+      (void **)&cras_observer_ops_value.active_node_changed);
+
+  RegisterNotification(
+      CRAS_CLIENT_OUTPUT_NODE_VOLUME_CHANGED,
+      (void *)send_output_node_volume_changed,
+      (void **)&cras_observer_ops_value.output_node_volume_changed);
+  RegisterNotification(
+      CRAS_CLIENT_OUTPUT_NODE_VOLUME_CHANGED, NULL,
+      (void **)&cras_observer_ops_value.output_node_volume_changed);
+
+  RegisterNotification(
+      CRAS_CLIENT_NODE_LEFT_RIGHT_SWAPPED_CHANGED,
+      (void *)send_node_left_right_swapped_changed,
+      (void **)&cras_observer_ops_value.node_left_right_swapped_changed);
+  RegisterNotification(
+      CRAS_CLIENT_NODE_LEFT_RIGHT_SWAPPED_CHANGED, NULL,
+      (void **)&cras_observer_ops_value.node_left_right_swapped_changed);
+
+  RegisterNotification(
+      CRAS_CLIENT_INPUT_NODE_GAIN_CHANGED,
+      (void *)send_input_node_gain_changed,
+      (void **)&cras_observer_ops_value.input_node_gain_changed);
+  RegisterNotification(
+      CRAS_CLIENT_INPUT_NODE_GAIN_CHANGED, NULL,
+      (void **)&cras_observer_ops_value.input_node_gain_changed);
+
+  RegisterNotification(
+      CRAS_CLIENT_NUM_ACTIVE_STREAMS_CHANGED,
+      (void *)send_num_active_streams_changed,
+      (void **)&cras_observer_ops_value.num_active_streams_changed);
+  RegisterNotification(
+      CRAS_CLIENT_NUM_ACTIVE_STREAMS_CHANGED, NULL,
+      (void **)&cras_observer_ops_value.num_active_streams_changed);
+
+  /* Deregister last. */
+  RegisterNotification(
+      CRAS_CLIENT_CAPTURE_GAIN_CHANGED, NULL,
+      (void **)&cras_observer_ops_value.capture_gain_changed);
+}
+
+TEST_F(RClientMessagesSuite, SendOutputVolumeChanged) {
+  void *void_client = reinterpret_cast<void *>(rclient_);
+  char buf[1024];
+  ssize_t rc;
+  struct cras_client_volume_changed *msg =
+      (struct cras_client_volume_changed *)buf;
+  const int32_t volume = 90;
+
+  send_output_volume_changed(void_client, volume);
+  rc = read(pipe_fds_[0], buf, sizeof(buf));
+  ASSERT_EQ(rc, (ssize_t)sizeof(*msg));
+  EXPECT_EQ(msg->header.id, CRAS_CLIENT_OUTPUT_VOLUME_CHANGED);
+  EXPECT_EQ(msg->volume, volume);
+}
+
+TEST_F(RClientMessagesSuite, SendOutputMuteChanged) {
+  void *void_client = reinterpret_cast<void *>(rclient_);
+  char buf[1024];
+  ssize_t rc;
+  struct cras_client_mute_changed *msg =
+      (struct cras_client_mute_changed *)buf;
+  const int muted = 1;
+  const int user_muted = 0;
+  const int mute_locked = 1;
+
+  send_output_mute_changed(void_client, muted, user_muted, mute_locked);
+  rc = read(pipe_fds_[0], buf, sizeof(buf));
+  ASSERT_EQ(rc, (ssize_t)sizeof(*msg));
+  EXPECT_EQ(msg->header.id, CRAS_CLIENT_OUTPUT_MUTE_CHANGED);
+  EXPECT_EQ(msg->muted, muted);
+  EXPECT_EQ(msg->user_muted, user_muted);
+  EXPECT_EQ(msg->mute_locked, mute_locked);
+}
+
+TEST_F(RClientMessagesSuite, SendCaptureGainChanged) {
+  void *void_client = reinterpret_cast<void *>(rclient_);
+  char buf[1024];
+  ssize_t rc;
+  struct cras_client_volume_changed *msg =
+      (struct cras_client_volume_changed *)buf;
+  const int32_t gain = 90;
+
+  send_capture_gain_changed(void_client, gain);
+  rc = read(pipe_fds_[0], buf, sizeof(buf));
+  ASSERT_EQ(rc, (ssize_t)sizeof(*msg));
+  EXPECT_EQ(msg->header.id, CRAS_CLIENT_CAPTURE_GAIN_CHANGED);
+  EXPECT_EQ(msg->volume, gain);
+}
+
+TEST_F(RClientMessagesSuite, SendCaptureMuteChanged) {
+  void *void_client = reinterpret_cast<void *>(rclient_);
+  char buf[1024];
+  ssize_t rc;
+  struct cras_client_mute_changed *msg =
+      (struct cras_client_mute_changed *)buf;
+  const int muted = 1;
+  const int mute_locked = 0;
+
+  send_capture_mute_changed(void_client, muted, mute_locked);
+  rc = read(pipe_fds_[0], buf, sizeof(buf));
+  ASSERT_EQ(rc, (ssize_t)sizeof(*msg));
+  EXPECT_EQ(msg->header.id, CRAS_CLIENT_CAPTURE_MUTE_CHANGED);
+  EXPECT_EQ(msg->muted, muted);
+  EXPECT_EQ(msg->mute_locked, mute_locked);
+}
+
+TEST_F(RClientMessagesSuite, SendNodesChanged) {
+  void *void_client = reinterpret_cast<void *>(rclient_);
+  char buf[1024];
+  ssize_t rc;
+  struct cras_client_nodes_changed *msg =
+      (struct cras_client_nodes_changed *)buf;
+
+  send_nodes_changed(void_client);
+  rc = read(pipe_fds_[0], buf, sizeof(buf));
+  ASSERT_EQ(rc, (ssize_t)sizeof(*msg));
+  EXPECT_EQ(msg->header.id, CRAS_CLIENT_NODES_CHANGED);
+}
+
+TEST_F(RClientMessagesSuite, SendActiveNodeChanged) {
+  void *void_client = reinterpret_cast<void *>(rclient_);
+  char buf[1024];
+  ssize_t rc;
+  struct cras_client_active_node_changed *msg =
+      (struct cras_client_active_node_changed *)buf;
+  const enum CRAS_STREAM_DIRECTION dir = CRAS_STREAM_INPUT;
+  const cras_node_id_t node_id = 0x0001000200030004;
+
+  send_active_node_changed(void_client, dir, node_id);
+  rc = read(pipe_fds_[0], buf, sizeof(buf));
+  ASSERT_EQ(rc, (ssize_t)sizeof(*msg));
+  EXPECT_EQ(msg->header.id, CRAS_CLIENT_ACTIVE_NODE_CHANGED);
+  EXPECT_EQ(msg->direction, (int32_t)dir);
+  EXPECT_EQ((uint64_t)msg->node_id, node_id);
+}
+
+TEST_F(RClientMessagesSuite, SendOutputNodeVolumeChanged) {
+  void *void_client = reinterpret_cast<void *>(rclient_);
+  char buf[1024];
+  ssize_t rc;
+  struct cras_client_node_value_changed *msg =
+      (struct cras_client_node_value_changed *)buf;
+  const cras_node_id_t node_id = 0x0001000200030004;
+  const int32_t value = 90;
+
+  send_output_node_volume_changed(void_client, node_id, value);
+  rc = read(pipe_fds_[0], buf, sizeof(buf));
+  ASSERT_EQ(rc, (ssize_t)sizeof(*msg));
+  EXPECT_EQ(msg->header.id, CRAS_CLIENT_OUTPUT_NODE_VOLUME_CHANGED);
+  EXPECT_EQ(msg->node_id, node_id);
+  EXPECT_EQ(msg->value, value);
+}
+
+TEST_F(RClientMessagesSuite, SendNodeLeftRightSwappedChanged) {
+  void *void_client = reinterpret_cast<void *>(rclient_);
+  char buf[1024];
+  ssize_t rc;
+  struct cras_client_node_value_changed *msg =
+      (struct cras_client_node_value_changed *)buf;
+  const cras_node_id_t node_id = 0x0001000200030004;
+  const int32_t value = 0;
+
+  send_node_left_right_swapped_changed(void_client, node_id, value);
+  rc = read(pipe_fds_[0], buf, sizeof(buf));
+  ASSERT_EQ(rc, (ssize_t)sizeof(*msg));
+  EXPECT_EQ(msg->header.id, CRAS_CLIENT_NODE_LEFT_RIGHT_SWAPPED_CHANGED);
+  EXPECT_EQ(msg->node_id, node_id);
+  EXPECT_EQ(msg->value, value);
+}
+
+TEST_F(RClientMessagesSuite, SendNodeInputNodeGainChanged) {
+  void *void_client = reinterpret_cast<void *>(rclient_);
+  char buf[1024];
+  ssize_t rc;
+  struct cras_client_node_value_changed *msg =
+      (struct cras_client_node_value_changed *)buf;
+  const cras_node_id_t node_id = 0x0001000200030004;
+  const int32_t value = -19;
+
+  send_input_node_gain_changed(void_client, node_id, value);
+  rc = read(pipe_fds_[0], buf, sizeof(buf));
+  ASSERT_EQ(rc, (ssize_t)sizeof(*msg));
+  EXPECT_EQ(msg->header.id, CRAS_CLIENT_INPUT_NODE_GAIN_CHANGED);
+  EXPECT_EQ(msg->node_id, node_id);
+  EXPECT_EQ(msg->value, value);
+}
+
+TEST_F(RClientMessagesSuite, SendNumActiveStreamsChanged) {
+  void *void_client = reinterpret_cast<void *>(rclient_);
+  char buf[1024];
+  ssize_t rc;
+  struct cras_client_num_active_streams_changed *msg =
+      (struct cras_client_num_active_streams_changed *)buf;
+  const enum CRAS_STREAM_DIRECTION dir = CRAS_STREAM_INPUT;
+  const uint32_t num_active_streams = 3;
+
+  send_num_active_streams_changed(void_client, dir, num_active_streams);
+  rc = read(pipe_fds_[0], buf, sizeof(buf));
+  ASSERT_EQ(rc, (ssize_t)sizeof(*msg));
+  EXPECT_EQ(msg->header.id, CRAS_CLIENT_NUM_ACTIVE_STREAMS_CHANGED);
+  EXPECT_EQ(msg->direction, (int32_t)dir);
+  EXPECT_EQ(msg->num_active_streams, num_active_streams);
+}
+
+}  //  namespace
+
+int main(int argc, char **argv) {
+  ::testing::InitGoogleTest(&argc, argv);
+  return RUN_ALL_TESTS();
+}
+
+/* stubs */
+extern "C" {
+
+struct audio_thread* cras_iodev_list_get_audio_thread() {
+  return iodev_get_thread_return;
+}
+
+void cras_iodev_list_add_active_node(enum CRAS_STREAM_DIRECTION dir,
+                                     cras_node_id_t node_id)
+{
+}
+
+void cras_iodev_list_rm_active_node(enum CRAS_STREAM_DIRECTION dir,
+                                    cras_node_id_t node_id)
+{
+}
+
+int audio_thread_rm_stream(audio_thread* thread,
+			   cras_rstream* stream) {
+  return 0;
+}
+
+void audio_thread_add_output_dev(struct audio_thread *thread,
+				 struct cras_iodev *odev)
+{
+}
+
+int audio_thread_dump_thread_info(struct audio_thread *thread,
+				  struct audio_debug_info *info)
+{
+  return 0;
+}
+
+int audio_thread_suspend(struct audio_thread *thread)
+{
+  return 0;
+}
+
+int audio_thread_resume(struct audio_thread *thread)
+{
+  return 0;
+}
+
+int audio_thread_config_global_remix(struct audio_thread *thread,
+    unsigned int num_channels,
+    const float *coefficient)
+{
+  return 0;
+}
+
+int audio_thread_set_aec_dump(struct audio_thread *thread,
+			      cras_stream_id_t stream_id,
+			      unsigned int start,
+			      int fd)
+{
+  return 0;
+}
+
+#ifdef HAVE_WEBRTC_APM
+void cras_apm_list_reload_aec_config()
+{
+}
+#endif
+
+const char *cras_config_get_socket_file_dir()
+{
+  return CRAS_UT_TMPDIR;
+}
+
+int cras_rstream_create(struct cras_rstream_config *stream_config,
+			struct cras_rstream **stream_out)
+{
+  *stream_out = cras_rstream_create_stream_out;
+  return cras_rstream_create_return;
+}
+
+unsigned int cras_rstream_get_effects(const struct cras_rstream *stream)
+{
+  return 0;
+}
+
+int cras_iodev_move_stream_type(uint32_t type, uint32_t index)
+{
+  return 0;
+}
+
+int cras_iodev_list_rm_output(struct cras_iodev *output) {
+  cras_iodev_list_rm_output_called++;
+  return 0;
+}
+
+int cras_iodev_list_rm_input(struct cras_iodev *input) {
+  cras_iodev_list_rm_input_called++;
+  return 0;
+}
+
+int cras_server_disconnect_from_client_socket(int socket_fd) {
+  return 0;
+}
+
+int cras_make_fd_nonblocking(int fd)
+{
+  cras_make_fd_nonblocking_called++;
+  return 0;
+}
+
+void cras_system_state_dump_snapshots()
+{
+  cras_system_state_dump_snapshots_called ++;
+}
+
+void cras_system_set_volume(size_t volume)
+{
+  cras_system_set_volume_value = volume;
+  cras_system_set_volume_called++;
+}
+
+void cras_system_set_capture_gain(long gain)
+{
+  cras_system_set_capture_gain_value = gain;
+  cras_system_set_capture_gain_called++;
+}
+
+//  From system_state.
+void cras_system_set_mute(int mute)
+{
+  cras_system_set_mute_value = mute;
+  cras_system_set_mute_called++;
+}
+void cras_system_set_user_mute(int mute)
+{
+  cras_system_set_user_mute_value = mute;
+  cras_system_set_user_mute_called++;
+}
+void cras_system_set_mute_locked(int mute)
+{
+  cras_system_set_mute_locked_value = mute;
+  cras_system_set_mute_locked_called++;
+}
+void cras_system_set_capture_mute(int mute)
+{
+  cras_system_set_capture_mute_value = mute;
+  cras_system_set_capture_mute_called++;
+}
+void cras_system_set_capture_mute_locked(int mute)
+{
+  cras_system_set_capture_mute_locked_value = mute;
+  cras_system_set_capture_mute_locked_called++;
+}
+
+int cras_system_remove_alsa_card(size_t alsa_card_index)
+{
+	return -1;
+}
+
+void cras_system_set_suspended(int suspended) {
+}
+
+struct cras_server_state *cras_system_state_get_no_lock()
+{
+  return NULL;
+}
+
+key_t cras_sys_state_shm_fd()
+{
+  return 1;
+}
+
+void cras_dsp_reload_ini()
+{
+}
+
+void cras_dsp_dump_info()
+{
+}
+
+int cras_iodev_list_set_node_attr(cras_node_id_t id,
+				  enum ionode_attr attr, int value)
+{
+  return 0;
+}
+
+void cras_iodev_list_select_node(enum CRAS_STREAM_DIRECTION direction,
+				 cras_node_id_t node_id)
+{
+}
+
+void cras_iodev_list_add_test_dev(enum TEST_IODEV_TYPE type) {
+}
+
+struct stream_list *cras_iodev_list_get_stream_list()
+{
+  return NULL;
+}
+
+/* Handles sending a command to a test iodev. */
+void cras_iodev_list_test_dev_command(unsigned int iodev_idx,
+                                      enum CRAS_TEST_IODEV_CMD command,
+                                      unsigned int data_len,
+                                      const uint8_t *data) {
+}
+
+void cras_iodev_list_configure_global_remix_converter(
+    unsigned int num_channels,
+    const float *coefficient)
+{
+}
+
+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_stream_called++;
+  ret = stream_list_add_stream_return;
+  if (ret)
+    stream_list_add_stream_return = -EINVAL;
+
+  dummy_rstream.direction = config->direction;
+  dummy_rstream.stream_id = config->stream_id;
+
+  return ret;
+}
+
+int stream_list_rm(struct stream_list *list, cras_stream_id_t id)
+{
+  stream_list_disconnect_stream_called++;
+  return 0;
+}
+
+int stream_list_rm_all_client_streams(struct stream_list *list,
+				      struct cras_rclient *rclient)
+{
+  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);
+}
+
+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 id,
+              const char *model_name)
+{
+  return 0;
+}
+
+struct cras_observer_client *cras_observer_add(
+			const struct cras_observer_ops *ops,
+			void *context)
+{
+  cras_observer_add_called++;
+  cras_observer_add_context_value = context;
+  memcpy(&cras_observer_ops_value, ops, sizeof(cras_observer_ops_value));
+  return cras_observer_add_return_value;
+}
+
+void cras_observer_get_ops(const struct cras_observer_client *client,
+			   struct cras_observer_ops *ops)
+{
+  cras_observer_get_ops_called++;
+  memcpy(ops, &cras_observer_ops_value, sizeof(*ops));
+}
+
+void cras_observer_set_ops(struct cras_observer_client *client,
+			   const struct cras_observer_ops *ops)
+{
+  cras_observer_set_ops_called++;
+  memcpy(&cras_observer_ops_value, ops, sizeof(cras_observer_ops_value));
+}
+
+int cras_observer_ops_are_empty(const struct cras_observer_ops *ops)
+{
+  cras_observer_ops_are_empty_called++;
+  return memcmp(&cras_observer_ops_are_empty_empty_ops, ops,
+                sizeof(cras_observer_ops_are_empty_empty_ops)) == 0;
+}
+
+void cras_observer_remove(struct cras_observer_client *client)
+{
+  cras_observer_remove_called++;
+}
+
+int cras_server_metrics_stream_config(struct cras_rstream_config *config)
+{
+  cras_server_metrics_stream_config_called++;
+  return 0;
+}
+
+}  // extern "C"
diff --git a/cras/src/tests/rstream_stub.cc b/cras/src/tests/rstream_stub.cc
index 18f6f95..d0b7a0a 100644
--- a/cras/src/tests/rstream_stub.cc
+++ b/cras/src/tests/rstream_stub.cc
@@ -12,12 +12,12 @@
 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,7 +36,8 @@
   }
 }
 
-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;
@@ -49,17 +50,19 @@
 
 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())
@@ -67,54 +70,61 @@
   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) {
-  return 1.0;
+float cras_rstream_get_volume_scaler(struct cras_rstream *rstream) {
+  return 0.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) {
-  cras_shm_buffer_write_complete(stream->shm);
+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 249bcb7..39a48b2 100644
--- a/cras/src/tests/rstream_stub.h
+++ b/cras/src/tests/rstream_stub.h
@@ -11,10 +11,11 @@
 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 69523f5..2261d47 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,67 +19,65 @@
 namespace {
 
 class RstreamTestSuite : public testing::Test {
- protected:
-  virtual void SetUp() {
-    int rc;
-    int sock[2] = {-1, -1};
+  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;
+      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;
+      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];
+      // 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;
-  }
+      config_.client = NULL;
+    }
 
-  virtual void TearDown() {
-    close(config_.audio_fd);
-    close(client_fd_);
-  }
+    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;
-  }
+    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;
+    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;
-  }
+      // 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_;
+    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;
@@ -88,7 +86,7 @@
 }
 
 TEST_F(RstreamTestSuite, InvalidStreamType) {
-  struct cras_rstream* s;
+  struct cras_rstream *s;
   int rc;
 
   config_.stream_type = (enum CRAS_STREAM_TYPE)7;
@@ -97,7 +95,7 @@
 }
 
 TEST_F(RstreamTestSuite, InvalidBufferSize) {
-  struct cras_rstream* s;
+  struct cras_rstream *s;
   int rc;
 
   config_.buffer_frames = 3;
@@ -106,7 +104,7 @@
 }
 
 TEST_F(RstreamTestSuite, InvalidCallbackThreshold) {
-  struct cras_rstream* s;
+  struct cras_rstream *s;
   int rc;
 
   config_.cb_threshold = 3;
@@ -122,82 +120,80 @@
 }
 
 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;
+  int rc, fd_ret;
   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));
   EXPECT_EQ(CRAS_STREAM_OUTPUT, cras_rstream_get_direction(s));
-  EXPECT_NE((void*)NULL, cras_rstream_shm(s));
+  EXPECT_NE((void *)NULL, cras_rstream_output_shm(s));
   rc = cras_rstream_get_format(s, &fmt_ret);
   EXPECT_EQ(0, rc);
   EXPECT_TRUE(format_equal(&fmt_ret, &fmt_));
 
   // Check if shm is really set up.
-  shm_ret = cras_rstream_shm(s);
-  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);
-  shm_mapped.header = (struct cras_audio_shm_header*)mmap(
-      NULL, cras_shm_header_size(), PROT_READ | PROT_WRITE, MAP_SHARED,
-      header_fd, 0);
-  EXPECT_NE((void*)NULL, shm_mapped.header);
+  shm_ret = cras_rstream_output_shm(s);
+  ASSERT_NE((void *)NULL, shm_ret);
+  fd_ret = cras_rstream_output_shm_fd(s);
+  shm_size = cras_rstream_get_total_shm_size(s);
+  EXPECT_GT(shm_size, 4096);
+  shm_mapped.area = (struct cras_audio_shm_area *)mmap(
+      NULL, shm_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_ret, 0);
+  EXPECT_NE((void *)NULL, shm_mapped.area);
   cras_shm_copy_shared_config(&shm_mapped);
   EXPECT_EQ(cras_shm_used_size(&shm_mapped), cras_shm_used_size(shm_ret));
-  munmap(shm_mapped.header, cras_shm_header_size());
+  munmap(shm_mapped.area, shm_size);
 
   cras_rstream_destroy(s);
 }
 
 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;
+  int rc, fd_ret;
   size_t shm_size;
 
   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));
   EXPECT_EQ(CRAS_STREAM_INPUT, cras_rstream_get_direction(s));
-  EXPECT_NE((void*)NULL, cras_rstream_shm(s));
+  EXPECT_NE((void *)NULL, cras_rstream_input_shm(s));
   rc = cras_rstream_get_format(s, &fmt_ret);
   EXPECT_EQ(0, rc);
   EXPECT_TRUE(format_equal(&fmt_ret, &fmt_));
 
   // Check if shm is really set up.
-  shm_ret = cras_rstream_shm(s);
-  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);
-  shm_mapped.header = (struct cras_audio_shm_header*)mmap(
-      NULL, cras_shm_header_size(), PROT_READ | PROT_WRITE, MAP_SHARED,
-      header_fd, 0);
-  EXPECT_NE((void*)NULL, shm_mapped.header);
+  shm_ret = cras_rstream_input_shm(s);
+  ASSERT_NE((void *)NULL, shm_ret);
+  fd_ret = cras_rstream_input_shm_fd(s);
+  shm_size = cras_rstream_get_total_shm_size(s);
+  EXPECT_GT(shm_size, 4096);
+  shm_mapped.area = (struct cras_audio_shm_area *)mmap(
+      NULL, shm_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_ret, 0);
+  EXPECT_NE((void *)NULL, shm_mapped.area);
   cras_shm_copy_shared_config(&shm_mapped);
   EXPECT_EQ(cras_shm_used_size(&shm_mapped), cras_shm_used_size(shm_ret));
-  munmap(shm_mapped.header, cras_shm_header_size());
+  munmap(shm_mapped.area, shm_size);
 
   cras_rstream_destroy(s);
 }
 
 TEST_F(RstreamTestSuite, VerifyStreamTypes) {
-  struct cras_rstream* s;
+  struct cras_rstream *s;
   int rc;
 
   config_.stream_type = CRAS_STREAM_TYPE_DEFAULT;
@@ -228,7 +224,7 @@
 }
 
 TEST_F(RstreamTestSuite, OutputStreamIsPendingReply) {
-  struct cras_rstream* s;
+  struct cras_rstream *s;
   int rc;
   struct timespec ts;
 
@@ -251,7 +247,7 @@
 }
 
 TEST_F(RstreamTestSuite, OutputStreamFlushMessages) {
-  struct cras_rstream* s;
+  struct cras_rstream *s;
   int rc;
   struct timespec ts;
 
@@ -284,7 +280,7 @@
 }
 
 TEST_F(RstreamTestSuite, InputStreamIsPendingReply) {
-  struct cras_rstream* s;
+  struct cras_rstream *s;
   int rc;
 
   config_.direction = CRAS_STREAM_INPUT;
@@ -308,7 +304,7 @@
 }
 
 TEST_F(RstreamTestSuite, InputStreamFlushMessages) {
-  struct cras_rstream* s;
+  struct cras_rstream *s;
   int rc;
 
   config_.direction = CRAS_STREAM_INPUT;
@@ -343,7 +339,7 @@
 
 }  //  namespace
 
-int main(int argc, char** argv) {
+int main(int argc, char **argv) {
   ::testing::InitGoogleTest(&argc, argv);
   return RUN_ALL_TESTS();
 }
@@ -351,66 +347,74 @@
 /* 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) {
-  return 0;
-}
 }
diff --git a/cras/src/tests/sbc_codec_stub.cc b/cras/src/tests/sbc_codec_stub.cc
deleted file mode 100644
index 95bd091..0000000
--- a/cras/src/tests/sbc_codec_stub.cc
+++ /dev/null
@@ -1,174 +0,0 @@
-/* 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
deleted file mode 100644
index b166b39..0000000
--- a/cras/src/tests/sbc_codec_stub.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/* 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 94a689c..c7d2339 100644
--- a/cras/src/tests/server_metrics_unittest.cc
+++ b/cras/src/tests/server_metrics_unittest.cc
@@ -2,24 +2,20 @@
 // 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 <vector>
+#include <gtest/gtest.h>
 
 extern "C" {
+#include "cras_server_metrics.c"
 #include "cras_main_message.h"
 #include "cras_rstream.h"
-#include "cras_server_metrics.c"
 }
 
 static enum CRAS_MAIN_MESSAGE_TYPE type_set;
-static struct timespec clock_gettime_retspec;
-std::vector<struct cras_server_metrics_message> sent_msgs;
+static struct cras_server_metrics_message *sent_msg;
 
 void ResetStubData() {
   type_set = (enum CRAS_MAIN_MESSAGE_TYPE)0;
-  sent_msgs.clear();
 }
 
 namespace {
@@ -32,374 +28,114 @@
   EXPECT_EQ(type_set, CRAS_MAIN_METRICS);
 }
 
-TEST(ServerMetricsTestSuite, SetMetricsDeviceRuntime) {
-  ResetStubData();
-  struct cras_iodev iodev;
-  struct cras_ionode active_node;
-
-  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;
-  iodev.active_node = &active_node;
-  active_node.type = CRAS_NODE_TYPE_USB;
-
-  cras_server_metrics_device_runtime(&iodev);
-
-  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, DEVICE_RUNTIME);
-  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);
-
-  sent_msgs.clear();
-
-  clock_gettime_retspec.tv_sec = 300;
-  clock_gettime_retspec.tv_nsec = 0;
-  iodev.open_ts.tv_sec = 100;
-  iodev.open_ts.tv_nsec = 0;
-  iodev.direction = CRAS_STREAM_OUTPUT;
-  iodev.active_node = &active_node;
-  active_node.type = CRAS_NODE_TYPE_HEADPHONE;
-
-  cras_server_metrics_device_runtime(&iodev);
-
-  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, DEVICE_RUNTIME);
-  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);
-}
-
-TEST(ServerMetricsTestSuite, SetMetricsHighestDeviceDelay) {
-  ResetStubData();
-  unsigned int hw_level = 1000;
-  unsigned int largest_cb_level = 500;
-
-  cras_server_metrics_highest_device_delay(hw_level, largest_cb_level,
-                                           CRAS_STREAM_INPUT);
-
-  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, HIGHEST_DEVICE_DELAY_INPUT);
-  EXPECT_EQ(sent_msgs[0].data.value, 2000);
-
-  sent_msgs.clear();
-
-  cras_server_metrics_highest_device_delay(hw_level, largest_cb_level,
-                                           CRAS_STREAM_OUTPUT);
-
-  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, HIGHEST_DEVICE_DELAY_OUTPUT);
-  EXPECT_EQ(sent_msgs[0].data.value, 2000);
-}
-
 TEST(ServerMetricsTestSuite, SetMetricHighestHardwareLevel) {
   ResetStubData();
   unsigned int hw_level = 1000;
+  sent_msg = (struct cras_server_metrics_message *)calloc(1, sizeof(*sent_msg));
 
   cras_server_metrics_highest_hw_level(hw_level, CRAS_STREAM_INPUT);
 
-  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, HIGHEST_INPUT_HW_LEVEL);
-  EXPECT_EQ(sent_msgs[0].data.value, hw_level);
+  EXPECT_EQ(sent_msg->header.type, CRAS_MAIN_METRICS);
+  EXPECT_EQ(sent_msg->header.length, sizeof(*sent_msg));
+  EXPECT_EQ(sent_msg->metrics_type, HIGHEST_INPUT_HW_LEVEL);
+  EXPECT_EQ(sent_msg->data.value, hw_level);
 
-  sent_msgs.clear();
+  free(sent_msg);
+
+  sent_msg = (struct cras_server_metrics_message *)calloc(1, sizeof(*sent_msg));
 
   cras_server_metrics_highest_hw_level(hw_level, CRAS_STREAM_OUTPUT);
 
-  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, HIGHEST_OUTPUT_HW_LEVEL);
-  EXPECT_EQ(sent_msgs[0].data.value, hw_level);
+  EXPECT_EQ(sent_msg->header.type, CRAS_MAIN_METRICS);
+  EXPECT_EQ(sent_msg->header.length, sizeof(*sent_msg));
+  EXPECT_EQ(sent_msg->metrics_type, HIGHEST_OUTPUT_HW_LEVEL);
+  EXPECT_EQ(sent_msg->data.value, hw_level);
+
+  free(sent_msg);
 }
 
 TEST(ServerMetricsTestSuite, SetMetricsLongestFetchDelay) {
   ResetStubData();
   unsigned int delay = 100;
+  sent_msg = (struct cras_server_metrics_message *)calloc(1, sizeof(*sent_msg));
 
   cras_server_metrics_longest_fetch_delay(delay);
 
-  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, LONGEST_FETCH_DELAY);
-  EXPECT_EQ(sent_msgs[0].data.value, delay);
+  EXPECT_EQ(sent_msg->header.type, CRAS_MAIN_METRICS);
+  EXPECT_EQ(sent_msg->header.length, sizeof(*sent_msg));
+  EXPECT_EQ(sent_msg->metrics_type, LONGEST_FETCH_DELAY);
+  EXPECT_EQ(sent_msg->data.value, delay);
+
+  free(sent_msg);
 }
 
 TEST(ServerMetricsTestSuite, SetMetricsNumUnderruns) {
   ResetStubData();
   unsigned int underrun = 10;
+  sent_msg = (struct cras_server_metrics_message *)calloc(1, sizeof(*sent_msg));
 
   cras_server_metrics_num_underruns(underrun);
 
-  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, NUM_UNDERRUNS);
-  EXPECT_EQ(sent_msgs[0].data.value, underrun);
-}
+  EXPECT_EQ(sent_msg->header.type, CRAS_MAIN_METRICS);
+  EXPECT_EQ(sent_msg->header.length, sizeof(*sent_msg));
+  EXPECT_EQ(sent_msg->metrics_type, NUM_UNDERRUNS);
+  EXPECT_EQ(sent_msg->data.value, underrun);
 
-TEST(ServerMetricsTestSuite, SetMetricsMissedCallbackFrequencyInputStream) {
-  ResetStubData();
-  struct cras_rstream stream;
-  struct timespec diff_ts;
-
-  stream.flags = 0;
-  stream.start_ts.tv_sec = 0;
-  stream.start_ts.tv_nsec = 0;
-  clock_gettime_retspec.tv_sec = 1000;
-  clock_gettime_retspec.tv_nsec = 0;
-  stream.num_missed_cb = 5;
-  stream.first_missed_cb_ts.tv_sec = 100;
-  stream.first_missed_cb_ts.tv_nsec = 0;
-
-  stream.direction = CRAS_STREAM_INPUT;
-  cras_server_metrics_missed_cb_frequency(&stream);
-
-  subtract_timespecs(&clock_gettime_retspec, &stream.start_ts, &diff_ts);
-  EXPECT_EQ(sent_msgs.size(), 2);
-  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, MISSED_CB_FREQUENCY_INPUT);
-  EXPECT_EQ(sent_msgs[0].data.value,
-            stream.num_missed_cb * 86400 / diff_ts.tv_sec);
-
-  subtract_timespecs(&clock_gettime_retspec, &stream.first_missed_cb_ts,
-                     &diff_ts);
-  EXPECT_EQ(sent_msgs[1].header.type, CRAS_MAIN_METRICS);
-  EXPECT_EQ(sent_msgs[1].header.length,
-            sizeof(struct cras_server_metrics_message));
-  EXPECT_EQ(sent_msgs[1].metrics_type,
-            MISSED_CB_FREQUENCY_AFTER_RESCHEDULING_INPUT);
-  EXPECT_EQ(sent_msgs[1].data.value,
-            (stream.num_missed_cb - 1) * 86400 / diff_ts.tv_sec);
-}
-
-TEST(ServerMetricsTestSuite, SetMetricsMissedCallbackFrequencyOutputStream) {
-  ResetStubData();
-  struct cras_rstream stream;
-  struct timespec diff_ts;
-
-  stream.flags = 0;
-  stream.start_ts.tv_sec = 0;
-  stream.start_ts.tv_nsec = 0;
-  clock_gettime_retspec.tv_sec = 1000;
-  clock_gettime_retspec.tv_nsec = 0;
-  stream.num_missed_cb = 5;
-  stream.first_missed_cb_ts.tv_sec = 100;
-  stream.first_missed_cb_ts.tv_nsec = 0;
-  stream.direction = CRAS_STREAM_OUTPUT;
-  cras_server_metrics_missed_cb_frequency(&stream);
-
-  subtract_timespecs(&clock_gettime_retspec, &stream.start_ts, &diff_ts);
-  EXPECT_EQ(sent_msgs.size(), 2);
-  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, MISSED_CB_FREQUENCY_OUTPUT);
-  EXPECT_EQ(sent_msgs[0].data.value,
-            stream.num_missed_cb * 86400 / diff_ts.tv_sec);
-
-  subtract_timespecs(&clock_gettime_retspec, &stream.first_missed_cb_ts,
-                     &diff_ts);
-  EXPECT_EQ(sent_msgs[1].header.type, CRAS_MAIN_METRICS);
-  EXPECT_EQ(sent_msgs[1].header.length,
-            sizeof(struct cras_server_metrics_message));
-  EXPECT_EQ(sent_msgs[1].metrics_type,
-            MISSED_CB_FREQUENCY_AFTER_RESCHEDULING_OUTPUT);
-  EXPECT_EQ(sent_msgs[1].data.value,
-            (stream.num_missed_cb - 1) * 86400 / diff_ts.tv_sec);
-}
-
-TEST(ServerMetricsTestSuite, SetMetricsMissedCallbackEventInputStream) {
-  ResetStubData();
-  struct cras_rstream stream;
-  struct timespec diff_ts;
-
-  stream.flags = 0;
-  stream.start_ts.tv_sec = 0;
-  stream.start_ts.tv_nsec = 0;
-  stream.num_missed_cb = 0;
-  stream.direction = CRAS_STREAM_INPUT;
-
-  clock_gettime_retspec.tv_sec = 100;
-  clock_gettime_retspec.tv_nsec = 0;
-  cras_server_metrics_missed_cb_event(&stream);
-
-  subtract_timespecs(&clock_gettime_retspec, &stream.start_ts, &diff_ts);
-  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, MISSED_CB_FIRST_TIME_INPUT);
-  EXPECT_EQ(sent_msgs[0].data.value, diff_ts.tv_sec);
-  EXPECT_EQ(stream.num_missed_cb, 1);
-  EXPECT_EQ(stream.first_missed_cb_ts.tv_sec, clock_gettime_retspec.tv_sec);
-  EXPECT_EQ(stream.first_missed_cb_ts.tv_nsec, clock_gettime_retspec.tv_nsec);
-
-  clock_gettime_retspec.tv_sec = 200;
-  clock_gettime_retspec.tv_nsec = 0;
-  cras_server_metrics_missed_cb_event(&stream);
-
-  subtract_timespecs(&clock_gettime_retspec, &stream.first_missed_cb_ts,
-                     &diff_ts);
-  EXPECT_EQ(sent_msgs.size(), 2);
-  EXPECT_EQ(sent_msgs[1].header.type, CRAS_MAIN_METRICS);
-  EXPECT_EQ(sent_msgs[1].header.length,
-            sizeof(struct cras_server_metrics_message));
-  EXPECT_EQ(sent_msgs[1].metrics_type, MISSED_CB_SECOND_TIME_INPUT);
-  EXPECT_EQ(sent_msgs[1].data.value, diff_ts.tv_sec);
-  EXPECT_EQ(stream.num_missed_cb, 2);
-}
-
-TEST(ServerMetricsTestSuite, SetMetricsMissedCallbackEventOutputStream) {
-  ResetStubData();
-  struct cras_rstream stream;
-  struct timespec diff_ts;
-
-  stream.flags = 0;
-  stream.start_ts.tv_sec = 0;
-  stream.start_ts.tv_nsec = 0;
-  stream.num_missed_cb = 0;
-  stream.direction = CRAS_STREAM_OUTPUT;
-
-  clock_gettime_retspec.tv_sec = 100;
-  clock_gettime_retspec.tv_nsec = 0;
-  cras_server_metrics_missed_cb_event(&stream);
-
-  subtract_timespecs(&clock_gettime_retspec, &stream.start_ts, &diff_ts);
-  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, MISSED_CB_FIRST_TIME_OUTPUT);
-  EXPECT_EQ(sent_msgs[0].data.value, diff_ts.tv_sec);
-  EXPECT_EQ(stream.num_missed_cb, 1);
-  EXPECT_EQ(stream.first_missed_cb_ts.tv_sec, clock_gettime_retspec.tv_sec);
-  EXPECT_EQ(stream.first_missed_cb_ts.tv_nsec, clock_gettime_retspec.tv_nsec);
-
-  clock_gettime_retspec.tv_sec = 200;
-  clock_gettime_retspec.tv_nsec = 0;
-  cras_server_metrics_missed_cb_event(&stream);
-
-  subtract_timespecs(&clock_gettime_retspec, &stream.first_missed_cb_ts,
-                     &diff_ts);
-  EXPECT_EQ(sent_msgs.size(), 2);
-  EXPECT_EQ(sent_msgs[1].header.type, CRAS_MAIN_METRICS);
-  EXPECT_EQ(sent_msgs[1].header.length,
-            sizeof(struct cras_server_metrics_message));
-  EXPECT_EQ(sent_msgs[1].metrics_type, MISSED_CB_SECOND_TIME_OUTPUT);
-  EXPECT_EQ(sent_msgs[1].data.value, diff_ts.tv_sec);
-  EXPECT_EQ(stream.num_missed_cb, 2);
+  free(sent_msg);
 }
 
 TEST(ServerMetricsTestSuite, SetMetricsStreamConfig) {
   ResetStubData();
   struct cras_rstream_config config;
   struct cras_audio_format format;
+  sent_msg = (struct cras_server_metrics_message *)calloc(1, sizeof(*sent_msg));
 
-  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);
 
-  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, 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);
-}
+  EXPECT_EQ(sent_msg->header.type, CRAS_MAIN_METRICS);
+  EXPECT_EQ(sent_msg->header.length, sizeof(*sent_msg));
+  EXPECT_EQ(sent_msg->metrics_type, STREAM_CONFIG);
+  EXPECT_EQ(sent_msg->data.stream_config.cb_threshold, 1024);
+  EXPECT_EQ(sent_msg->data.stream_config.flags, BULK_AUDIO_OK);
+  EXPECT_EQ(sent_msg->data.stream_config.format, SND_PCM_FORMAT_S16_LE);
+  EXPECT_EQ(sent_msg->data.stream_config.rate, 48000);
 
-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);
+  free(sent_msg);
 }
 
 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;
 }
 
-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_sparse_histogram(const char* name, int sample) {}
+void cras_metrics_log_sparse_histogram(const char *name, int sample)
+{
+}
 
-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.
-  struct cras_server_metrics_message sent_msg;
-  memcpy(&sent_msg, msg, sizeof(sent_msg));
-  sent_msgs.push_back(sent_msg);
+  memcpy(sent_msg, msg, sizeof(*sent_msg));
   return 0;
-}
-
-int cras_system_state_in_main_thread() {
-  return 0;
-}
-
-//  From librt.
-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"
 }  // 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/shm_unittest.cc b/cras/src/tests/shm_unittest.cc
index b5df1f6..9c36432 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 <gtest/gtest.h>
 #include <stdio.h>
+#include <gtest/gtest.h>
 
 extern "C" {
 #include "cras_shm.h"
@@ -12,30 +12,27 @@
 
 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));
-    shm_.samples_info.length = 2048;
-    cras_shm_set_frame_bytes(&shm_, 4);
+class ShmTestSuite : public testing::Test{
+  protected:
+    virtual void SetUp() {
+      memset(&shm_, 0, sizeof(shm_));
+      shm_.area =
+          static_cast<cras_audio_shm_area *>(
+              calloc(1, sizeof(*shm_.area) + 2048));
+      cras_shm_set_frame_bytes(&shm_, 4);
+      cras_shm_set_used_size(&shm_, 1024);
+      memcpy(&shm_.area->config, &shm_.config, sizeof(shm_.config));
 
-    cras_shm_set_used_size(&shm_, 1024);
-    memcpy(&shm_.header->config, &shm_.config, sizeof(shm_.config));
+      frames_ = 0;
+    }
 
-    frames_ = 0;
-  }
+    virtual void TearDown() {
+      free(shm_.area);
+    }
 
-  virtual void TearDown() {
-    free(shm_.header);
-    free(shm_.samples);
-  }
-
-  struct cras_audio_shm shm_;
-  uint8_t* buf_;
-  size_t frames_;
+    struct cras_audio_shm shm_;
+    uint8_t *buf_;
+    size_t frames_;
 };
 
 // Test that and empty buffer returns 0 readable bytes.
@@ -43,121 +40,110 @@
   buf_ = cras_shm_get_readable_frames(&shm_, 0, &frames_);
   EXPECT_EQ(0, frames_);
   cras_shm_buffer_read(&shm_, frames_);
-  EXPECT_EQ(0, shm_.header->read_offset[0]);
+  EXPECT_EQ(0, shm_.area->read_offset[0]);
 }
 
 // Buffer with 100 frames filled.
 TEST_F(ShmTestSuite, OneHundredFilled) {
-  shm_.header->write_offset[0] = 100 * shm_.header->config.frame_bytes;
+  shm_.area->write_offset[0] = 100 * shm_.area->config.frame_bytes;
   buf_ = cras_shm_get_readable_frames(&shm_, 0, &frames_);
   EXPECT_EQ(100, frames_);
-  EXPECT_EQ(shm_.samples, buf_);
+  EXPECT_EQ(shm_.area->samples, buf_);
   cras_shm_buffer_read(&shm_, frames_ - 9);
-  EXPECT_EQ((frames_ - 9) * shm_.config.frame_bytes,
-            shm_.header->read_offset[0]);
+  EXPECT_EQ((frames_ - 9) * shm_.config.frame_bytes, shm_.area->read_offset[0]);
   cras_shm_buffer_read(&shm_, 9);
-  EXPECT_EQ(0, shm_.header->read_offset[0]);
-  EXPECT_EQ(1, shm_.header->read_buf_idx);
+  EXPECT_EQ(0, shm_.area->read_offset[0]);
+  EXPECT_EQ(1, shm_.area->read_buf_idx);
 }
 
 // Buffer with 100 frames filled, 50 read.
 TEST_F(ShmTestSuite, OneHundredFilled50Read) {
-  shm_.header->write_offset[0] = 100 * shm_.config.frame_bytes;
-  shm_.header->read_offset[0] = 50 * shm_.config.frame_bytes;
+  shm_.area->write_offset[0] = 100 * shm_.config.frame_bytes;
+  shm_.area->read_offset[0] = 50 * shm_.config.frame_bytes;
   buf_ = cras_shm_get_readable_frames(&shm_, 0, &frames_);
   EXPECT_EQ(50, frames_);
-  EXPECT_EQ((shm_.samples + shm_.header->read_offset[0]), buf_);
+  EXPECT_EQ((shm_.area->samples + shm_.area->read_offset[0]), buf_);
   cras_shm_buffer_read(&shm_, frames_ - 10);
-  EXPECT_EQ(shm_.header->write_offset[0] - 10 * shm_.config.frame_bytes,
-            shm_.header->read_offset[0]);
+  EXPECT_EQ(shm_.area->write_offset[0] - 10 * shm_.config.frame_bytes,
+            shm_.area->read_offset[0]);
   cras_shm_buffer_read(&shm_, 10);
-  EXPECT_EQ(0, shm_.header->read_offset[0]);
+  EXPECT_EQ(0, shm_.area->read_offset[0]);
 }
 
 // Buffer with 100 frames filled, 50 read, offset by 25.
 TEST_F(ShmTestSuite, OneHundredFilled50Read25offset) {
-  shm_.header->write_offset[0] = 100 * shm_.config.frame_bytes;
-  shm_.header->read_offset[0] = 50 * shm_.config.frame_bytes;
+  shm_.area->write_offset[0] = 100 * shm_.config.frame_bytes;
+  shm_.area->read_offset[0] = 50 * shm_.config.frame_bytes;
   buf_ = cras_shm_get_readable_frames(&shm_, 25, &frames_);
   EXPECT_EQ(25, frames_);
-  EXPECT_EQ(shm_.samples + shm_.header->read_offset[0] +
-                25 * shm_.header->config.frame_bytes,
-            (uint8_t*)buf_);
+  EXPECT_EQ(shm_.area->samples + shm_.area->read_offset[0] +
+                25 * shm_.area->config.frame_bytes,
+            (uint8_t *)buf_);
 }
 
 // Test wrapping across buffers.
 TEST_F(ShmTestSuite, WrapToNextBuffer) {
-  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);
+  shm_.config.used_size = 480 * shm_.config.frame_bytes;
+  shm_.area->write_offset[0] = 240 * shm_.config.frame_bytes;
+  shm_.area->read_offset[0] = 120 * shm_.config.frame_bytes;
+  shm_.area->write_offset[1] = 240 * 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) + (used_size / 4), (uint8_t*)buf_);
+  EXPECT_EQ(120, frames_);
+  EXPECT_EQ(shm_.area->samples + shm_.area->read_offset[0], (uint8_t *)buf_);
   buf_ = cras_shm_get_readable_frames(&shm_, frames_, &frames_);
-  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(((used_frames / 2) - 10) * shm_.config.frame_bytes,
-            shm_.header->read_offset[1]);
-  EXPECT_EQ(1, shm_.header->read_buf_idx);
+  EXPECT_EQ(240, frames_);
+  EXPECT_EQ(shm_.area->samples + shm_.config.used_size, (uint8_t *)buf_);
+  cras_shm_buffer_read(&shm_, 350); /* Mark all-10 as read */
+  EXPECT_EQ(0, shm_.area->read_offset[0]);
+  EXPECT_EQ(230 * shm_.config.frame_bytes, shm_.area->read_offset[1]);
 }
 
 // Test wrapping across buffers reading all samples.
 TEST_F(ShmTestSuite, WrapToNextBufferReadAll) {
-  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);
+  shm_.config.used_size = 480 * shm_.config.frame_bytes;
+  shm_.area->write_offset[0] = 240 * shm_.config.frame_bytes;
+  shm_.area->read_offset[0] = 120 * shm_.config.frame_bytes;
+  shm_.area->write_offset[1] = 240 * 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) + (used_size / 4), (uint8_t*)buf_);
+  EXPECT_EQ(120, frames_);
+  EXPECT_EQ(shm_.area->samples + shm_.area->read_offset[0], (uint8_t *)buf_);
   buf_ = cras_shm_get_readable_frames(&shm_, frames_, &frames_);
-  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);
+  EXPECT_EQ(240, frames_);
+  EXPECT_EQ(shm_.area->samples + shm_.config.used_size, (uint8_t *)buf_);
+  cras_shm_buffer_read(&shm_, 360); /* Mark all as read */
+  EXPECT_EQ(0, shm_.area->read_offset[0]);
+  EXPECT_EQ(0, shm_.area->read_offset[1]);
+  EXPECT_EQ(0, shm_.area->read_buf_idx);
 }
 
 // Test wrapping last buffer.
 TEST_F(ShmTestSuite, WrapFromFinalBuffer) {
-  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);
+  shm_.area->read_buf_idx = CRAS_NUM_SHM_BUFFERS - 1;
+  shm_.config.used_size = 480 * shm_.config.frame_bytes;
+  shm_.area->write_offset[shm_.area->read_buf_idx] =
+      240 * shm_.config.frame_bytes;
+  shm_.area->read_offset[shm_.area->read_buf_idx] =
+      120 * shm_.config.frame_bytes;
+  shm_.area->write_offset[0] = 240 * 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_, buf_idx) + (used_size / 4),
-            (uint8_t*)buf_);
-
+  EXPECT_EQ(120, frames_);
+  EXPECT_EQ((uint8_t *)buf_, shm_.area->samples +
+      shm_.config.used_size * shm_.area->read_buf_idx +
+      shm_.area->read_offset[shm_.area->read_buf_idx]);
   buf_ = cras_shm_get_readable_frames(&shm_, frames_, &frames_);
-  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);
+  EXPECT_EQ(240, frames_);
+  EXPECT_EQ(shm_.area->samples, (uint8_t *)buf_);
+  cras_shm_buffer_read(&shm_, 350); /* Mark all-10 as read */
+  EXPECT_EQ(0, shm_.area->read_offset[1]);
+  EXPECT_EQ(230 * shm_.config.frame_bytes, shm_.area->read_offset[0]);
 }
 
 // Test Check available to write returns 0 if not free buffer.
 TEST_F(ShmTestSuite, WriteAvailNotFree) {
   size_t ret;
-  shm_.header->write_buf_idx = 0;
-  shm_.header->write_offset[0] = 100 * shm_.config.frame_bytes;
-  shm_.header->read_offset[0] = 50 * shm_.config.frame_bytes;
+  shm_.area->write_buf_idx = 0;
+  shm_.area->write_offset[0] = 100 * shm_.config.frame_bytes;
+  shm_.area->read_offset[0] = 50 * shm_.config.frame_bytes;
   ret = cras_shm_get_num_writeable(&shm_);
   EXPECT_EQ(0, ret);
 }
@@ -165,10 +151,10 @@
 // Test Check available to write returns num_frames if free buffer.
 TEST_F(ShmTestSuite, WriteAvailValid) {
   size_t ret;
-  shm_.header->write_buf_idx = 0;
+  shm_.area->write_buf_idx = 0;
   shm_.config.used_size = 480 * shm_.config.frame_bytes;
-  shm_.header->write_offset[0] = 0;
-  shm_.header->read_offset[0] = 0;
+  shm_.area->write_offset[0] = 0;
+  shm_.area->read_offset[0] = 0;
   ret = cras_shm_get_num_writeable(&shm_);
   EXPECT_EQ(480, ret);
 }
@@ -176,10 +162,10 @@
 // Test get frames_written returns the number of frames written.
 TEST_F(ShmTestSuite, GetNumWritten) {
   size_t ret;
-  shm_.header->write_buf_idx = 0;
+  shm_.area->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->read_offset[0] = 0;
+  shm_.area->write_offset[0] = 200 * shm_.config.frame_bytes;
+  shm_.area->read_offset[0] = 0;
   ret = cras_shm_frames_written(&shm_);
   EXPECT_EQ(200, ret);
 }
@@ -188,64 +174,65 @@
 TEST_F(ShmTestSuite, GetWriteBufferBase) {
   uint8_t* ret;
 
-  shm_.header->write_buf_idx = 0;
-  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;
+  shm_.area->write_buf_idx = 0;
+  shm_.config.used_size = 480 * shm_.config.frame_bytes;
+  shm_.area->write_offset[0] = 200 * shm_.config.frame_bytes;
+  shm_.area->write_offset[1] = 200 * shm_.config.frame_bytes;
+  shm_.area->read_offset[0] = 0;
+  shm_.area->read_offset[1] = 0;
   ret = cras_shm_get_write_buffer_base(&shm_);
-  EXPECT_EQ(shm_.samples, ret);
+  EXPECT_EQ(shm_.area->samples, ret);
 
-  shm_.header->write_buf_idx = 1;
+  shm_.area->write_buf_idx = 1;
   ret = cras_shm_get_write_buffer_base(&shm_);
-  EXPECT_EQ(shm_.samples + shm_.config.used_size, ret);
+  EXPECT_EQ(shm_.area->samples + shm_.config.used_size, ret);
 }
 
 TEST_F(ShmTestSuite, SetVolume) {
   cras_shm_set_volume_scaler(&shm_, 1.0);
-  EXPECT_EQ(shm_.header->volume_scaler, 1.0);
+  EXPECT_EQ(shm_.area->volume_scaler, 1.0);
   cras_shm_set_volume_scaler(&shm_, 1.4);
-  EXPECT_EQ(shm_.header->volume_scaler, 1.0);
+  EXPECT_EQ(shm_.area->volume_scaler, 1.0);
   cras_shm_set_volume_scaler(&shm_, -0.5);
-  EXPECT_EQ(shm_.header->volume_scaler, 0.0);
+  EXPECT_EQ(shm_.area->volume_scaler, 0.0);
   cras_shm_set_volume_scaler(&shm_, 0.5);
-  EXPECT_EQ(shm_.header->volume_scaler, 0.5);
+  EXPECT_EQ(shm_.area->volume_scaler, 0.5);
 }
 
 // Test that invalid read/write offsets are detected.
 
 TEST_F(ShmTestSuite, InvalidWriteOffset) {
-  shm_.header->write_offset[0] = shm_.config.used_size + 50;
-  shm_.header->read_offset[0] = 0;
+  shm_.area->write_offset[0] = shm_.config.used_size + 50;
+  shm_.area->read_offset[0] = 0;
   buf_ = cras_shm_get_readable_frames(&shm_, 0, &frames_);
   EXPECT_EQ(shm_.config.used_size / 4, frames_);
 }
 
 TEST_F(ShmTestSuite, InvalidReadOffset) {
   // Should ignore read+_offset and assume 0.
-  shm_.header->write_offset[0] = 44;
-  shm_.header->read_offset[0] = shm_.config.used_size + 25;
+  shm_.area->write_offset[0] = 44;
+  shm_.area->read_offset[0] = shm_.config.used_size + 25;
   buf_ = cras_shm_get_readable_frames(&shm_, 0, &frames_);
-  EXPECT_EQ(shm_.header->write_offset[0] / shm_.config.frame_bytes, frames_);
-  EXPECT_EQ(shm_.samples, (uint8_t*)buf_);
+  EXPECT_EQ(shm_.area->write_offset[0] / shm_.config.frame_bytes, frames_);
+  EXPECT_EQ(shm_.area->samples, (uint8_t *)buf_);
 }
 
 TEST_F(ShmTestSuite, InvalidReadAndWriteOffset) {
-  shm_.header->write_offset[0] = shm_.config.used_size + 50;
-  shm_.header->read_offset[0] = shm_.config.used_size + 25;
+  shm_.area->write_offset[0] = shm_.config.used_size + 50;
+  shm_.area->read_offset[0] = shm_.config.used_size + 25;
   buf_ = cras_shm_get_readable_frames(&shm_, 0, &frames_);
   EXPECT_EQ(shm_.config.used_size / 4, frames_);
 }
 
 TEST_F(ShmTestSuite, InputBufferOverrun) {
   int rc;
-  shm_.header->write_offset[0] = 0;
-  shm_.header->read_offset[0] = 0;
-  shm_.header->write_offset[1] = 0;
-  shm_.header->read_offset[1] = 0;
+  shm_.area->write_offset[0] = 0;
+  shm_.area->read_offset[0] = 0;
+  shm_.area->write_offset[1] = 0;
+  shm_.area->read_offset[1] = 0;
 
-  shm_.header->write_buf_idx = 0;
-  shm_.header->read_buf_idx = 0;
+  shm_.area->write_buf_idx = 0;
+  shm_.area->read_buf_idx = 0;
 
   EXPECT_EQ(0, cras_shm_num_overruns(&shm_));
   rc = cras_shm_check_write_overrun(&shm_);
@@ -269,12 +256,12 @@
   unsigned limit = 480;
   unsigned written = 200;
   unsigned frames;
-  shm_.header->write_buf_idx = 0;
+  shm_.area->write_buf_idx = 0;
   shm_.config.used_size = buffer_size * shm_.config.frame_bytes;
-  shm_.header->write_offset[0] = written * shm_.config.frame_bytes;
+  shm_.area->write_offset[0] = written * shm_.config.frame_bytes;
   buf_ = cras_shm_get_writeable_frames(&shm_, limit, &frames);
   EXPECT_EQ(limit - written, frames);
-  EXPECT_EQ(shm_.samples + shm_.header->write_offset[0], buf_);
+  EXPECT_EQ(shm_.area->samples + shm_.area->write_offset[0], buf_);
 }
 
 TEST_F(ShmTestSuite, GetWritableFramesNoNeedToWrite) {
@@ -282,291 +269,17 @@
   unsigned limit = 240;
   unsigned written = 300;
   unsigned frames;
-  shm_.header->write_buf_idx = 0;
+  shm_.area->write_buf_idx = 0;
   shm_.config.used_size = buffer_size * shm_.config.frame_bytes;
-  shm_.header->write_offset[0] = written * shm_.config.frame_bytes;
+  shm_.area->write_offset[0] = written * shm_.config.frame_bytes;
   buf_ = cras_shm_get_writeable_frames(&shm_, limit, &frames);
   EXPECT_EQ(0, frames);
-  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;
-  }
+  EXPECT_EQ(shm_.area->samples + shm_.area->write_offset[0], buf_);
 }
 
 }  //  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 d144458..d2e5ea6 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 <gtest/gtest.h>
 #include <stdio.h>
+#include <gtest/gtest.h>
 
 extern "C" {
 #include "softvol_curve.h"
@@ -28,9 +28,12 @@
 }  //  namespace
 
 /* Stubs */
-extern "C" {}  // extern "C"
+extern "C" {
 
-int main(int argc, char** argv) {
+}  // extern "C"
+
+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 8f3c2e3..f2e8fbb 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 <gtest/gtest.h>
 #include <stdio.h>
+#include <gtest/gtest.h>
 
 extern "C" {
 #include "cras_rstream.h"
@@ -13,24 +13,24 @@
 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 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 @@
 }
 
 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,20 +74,22 @@
 
 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);
+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) {}
+void cras_tm_cancel_timer(struct cras_tm *tm, struct cras_timer *t) {
 }
 
-}  // namespace
+}
 
-int main(int argc, char** argv) {
+} // namespace
+
+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 9e7ecc8..d71d5f5 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 <gtest/gtest.h>
 #include <stdio.h>
+#include <gtest/gtest.h>
 
 extern "C" {
 #include "cras_alert.h"
@@ -20,14 +20,14 @@
 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,44 +59,49 @@
   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);
 }
 
@@ -351,8 +356,8 @@
 }
 
 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();
@@ -381,8 +386,8 @@
 }
 
 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();
@@ -425,23 +430,29 @@
   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);
 
@@ -450,98 +461,110 @@
 
 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) {
+struct cras_device_blacklist *cras_device_blacklist_create(
+		const char *config_path)
+{
+	return NULL;
+}
+
+void cras_device_blacklist_destroy(struct cras_device_blacklist *blacklist)
+{
+}
+
+struct cras_alert *cras_alert_create(cras_alert_prepare prepare,
+                                     unsigned int flags)
+{
   return NULL;
 }
 
-void cras_device_blacklist_destroy(struct cras_device_blacklist* blacklist) {}
-
-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 beba2f7..bae0fee 100644
--- a/cras/src/tests/timing_unittest.cc
+++ b/cras/src/tests/timing_unittest.cc
@@ -2,21 +2,20 @@
 // 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 <memory>
 #include <stdint.h>
 #include <stdio.h>
-#include <syslog.h>
 #include <time.h>
 
-#include <memory>
+#include <gtest/gtest.h>
 
 extern "C" {
-#include "cras_iodev.h"    // stubbed
-#include "cras_rstream.h"  // stubbed
+#include "dev_io.h" // tested
+#include "dev_stream.h" // tested
+#include "cras_rstream.h" // stubbed
+#include "cras_iodev.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;
@@ -24,14 +23,13 @@
 
 #include "dev_io_stubs.h"
 #include "iodev_stub.h"
-#include "metrics_stub.h"
 #include "rstream_stub.h"
 
 #define FAKE_POLL_FD 33
 
 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)));
@@ -39,7 +37,9 @@
     rstream_stub_reset();
   }
 
-  virtual void TearDown() { free(atlog); }
+  virtual void TearDown() {
+    free(atlog);
+  }
 
   timespec SingleInputDevNextWake(
       size_t dev_cb_threshold,
@@ -65,414 +65,12 @@
     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;
   }
-
-  timespec SingleOutputDevNextWake(
-      size_t dev_cb_threshold,
-      size_t dev_level,
-      const timespec* level_timestamp,
-      cras_audio_format* dev_format,
-      const std::vector<StreamPtr>& streams,
-      const timespec* dev_wake_ts,
-      CRAS_NODE_TYPE active_node_type = CRAS_NODE_TYPE_HEADPHONE) {
-    struct open_dev* dev_list_ = NULL;
-
-    DevicePtr dev = create_device(CRAS_STREAM_OUTPUT, dev_cb_threshold,
-                                  dev_format, active_node_type);
-    DL_APPEND(dev_list_, dev->odev.get());
-
-    for (auto const& stream : streams) {
-      add_stream_to_dev(dev->dev, stream);
-    }
-
-    dev->odev->wake_ts = *dev_wake_ts;
-
-    // Set response for frames_queued.
-    iodev_stub_frames_queued(dev->dev.get(), dev_level, *level_timestamp);
-
-    struct timespec dev_time, now;
-    dev_time.tv_sec = level_timestamp->tv_sec + 500;  // Far in the future.
-    clock_gettime(CLOCK_MONOTONIC_RAW, &now);
-    dev_io_next_output_wake(&dev_list_, &dev_time, &now);
-    return dev_time;
-  }
 };
 
-extern "C" {
-//  From librt. Fix now at this time.
-int clock_gettime(clockid_t clk_id, struct timespec* tp) {
-  tp->tv_sec = 12345;
-  tp->tv_nsec = 987654321;
-  return 0;
-}
-};
-
-// Add a new input stream, make sure the initial next_cb_ts is 0.
-TEST_F(TimingSuite, NewInputStreamInit) {
-  struct open_dev* dev_list_ = NULL;
-
-  cras_audio_format format;
-  fill_audio_format(&format, 48000);
-  DevicePtr dev =
-      create_device(CRAS_STREAM_INPUT, 1024, &format, CRAS_NODE_TYPE_MIC);
-  DL_APPEND(dev_list_, dev->odev.get());
-  struct cras_iodev* iodev = dev->odev->dev;
-
-  ShmPtr shm = create_shm(480);
-  RstreamPtr rstream =
-      create_rstream(1, CRAS_STREAM_INPUT, 480, &format, shm.get());
-
-  dev_io_append_stream(&dev_list_, rstream.get(), &iodev, 1);
-
-  EXPECT_EQ(0, rstream->next_cb_ts.tv_sec);
-  EXPECT_EQ(0, rstream->next_cb_ts.tv_nsec);
-
-  dev_stream_destroy(iodev->streams);
-}
-
-// There is the pseudo code about wake up time for an input device.
-//
-// function set_input_dev_wake_ts(dev):
-//   wake_ts = now + 20s #rule_1
-//
-//   cap_limit = MIN(dev_stream_capture_avail(stream)) for stream on dev
-//
-//   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
-//
-//   device.wake_ts = wake_ts
-//
-// function get_input_wake_time(stream, cap_limit):
-//   needed_frames_from_device = dev_stream_capture_avail(stream)
-//
-//   if needed_frames_from_device > cap_limit: #rule_4
-//     return None
-//
-//   if stream is USE_DEV_TIMING and stream is pending reply: #rule_5
-//     return None
-//
-//   time_for_sample = The time when device gets enough samples #rule_6
-//
-//   wake_time_out = MAX(stream.next_cb_ts, time_for_sample) #rule_7
-//
-//   if stream is USE_DEV_TIMING:
-//     wake_time_out =  time_for_sample #rule_8
-//
-//   return wake_time_out
-//
-// function get_input_dev_max_wake_ts(dev):
-//   return MAX(5ms, The time when hw_level = buffer_size / 2) #rule_9
-//
-//
-// dev_stream_capture_avail: The number of frames free to be written to in a
-//                           capture stream.
-//
-// The following unittests will check these logics.
-
-// Test rule_1.
-// The device wake up time should be 20s from now.
-TEST_F(TimingSuite, InputWakeTimeNoStreamWithBigBufferDevice) {
-  cras_audio_format format;
-  fill_audio_format(&format, 48000);
-
-  struct timespec start;
-  clock_gettime(CLOCK_MONOTONIC_RAW, &start);
-
-  std::vector<StreamPtr> streams;
-  timespec dev_time =
-      SingleInputDevNextWake(4800000, 0, &start, &format, streams);
-
-  const timespec add_millis = {20, 0};
-  add_timespecs(&start, &add_millis);
-  EXPECT_EQ(start.tv_sec, dev_time.tv_sec);
-  EXPECT_EQ(start.tv_nsec, dev_time.tv_nsec);
-}
-
-// Test rule_2, rule_4(Stream 1), rule_7(Stream 2)
-// Stream 1: next_cb_ts = now, cb_threshold = 480, dev_offset = 0
-// Stream 2: next_cb_ts = now + 5s, cb_threshold = 480, dev_offset = 200
-// Stream 1 need 480 frames and Stream 2 need 240 frames. So 240 will be the
-// cap_limit and Stream 1 will be ignored. The next wake up time should be
-// the next_cb_ts of stream2.
-TEST_F(TimingSuite, InputWakeTimeTwoStreamsWithFramesInside) {
-  cras_audio_format format;
-  fill_audio_format(&format, 48000);
-  struct timespec start;
-  clock_gettime(CLOCK_MONOTONIC_RAW, &start);
-
-  StreamPtr stream1 = create_stream(1, 1, CRAS_STREAM_INPUT, 480, &format);
-  stream1->rstream->next_cb_ts = start;
-
-  StreamPtr stream2 = create_stream(1, 2, CRAS_STREAM_INPUT, 480, &format);
-  stream2->rstream->next_cb_ts = start;
-  stream2->rstream->next_cb_ts.tv_sec += 5;
-  rstream_stub_dev_offset(stream2->rstream.get(), 1, 200);
-
-  std::vector<StreamPtr> streams;
-  streams.emplace_back(std::move(stream1));
-  streams.emplace_back(std::move(stream2));
-  timespec dev_time =
-      SingleInputDevNextWake(480000, 0, &start, &format, streams);
-
-  EXPECT_EQ(start.tv_sec + 5, dev_time.tv_sec);
-  EXPECT_EQ(start.tv_nsec, dev_time.tv_nsec);
-}
-
-// Test rule_2, rule_7
-// Stream 1: next_cb_ts = now + 2s, cb_threshold = 480, dev_offset = 0
-// Stream 2: next_cb_ts = now + 5s, cb_threshold = 480, dev_offset = 0
-// The audio thread will choose the earliest next_cb_ts because the they have
-// the same value of needed_frames_from_device. The next wake up time should
-// be the next_cb_ts of stream1.
-TEST_F(TimingSuite, InputWakeTimeTwoEmptyStreams) {
-  cras_audio_format format;
-  fill_audio_format(&format, 48000);
-  struct timespec start;
-  clock_gettime(CLOCK_MONOTONIC_RAW, &start);
-
-  StreamPtr stream1 = create_stream(1, 1, CRAS_STREAM_INPUT, 480, &format);
-  stream1->rstream->next_cb_ts = start;
-  stream1->rstream->next_cb_ts.tv_sec += 2;
-
-  StreamPtr stream2 = create_stream(1, 2, CRAS_STREAM_INPUT, 480, &format);
-  stream2->rstream->next_cb_ts = start;
-  stream2->rstream->next_cb_ts.tv_sec += 5;
-
-  std::vector<StreamPtr> streams;
-  streams.emplace_back(std::move(stream1));
-  streams.emplace_back(std::move(stream2));
-  timespec dev_time =
-      SingleInputDevNextWake(480000, 0, &start, &format, streams);
-
-  EXPECT_EQ(start.tv_sec + 2, dev_time.tv_sec);
-  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.
-TEST_F(TimingSuite, InputWakeTimeOneStreamWithDeviceWakeUp) {
-  cras_audio_format format;
-  fill_audio_format(&format, 48000);
-
-  StreamPtr stream = create_stream(1, 1, CRAS_STREAM_INPUT, 480, &format);
-
-  struct timespec start;
-  clock_gettime(CLOCK_MONOTONIC_RAW, &start);
-
-  // The next callback of the new stream is 0.
-  stream->rstream->next_cb_ts.tv_sec = 0;
-  stream->rstream->next_cb_ts.tv_nsec = 0;
-
-  std::vector<StreamPtr> streams;
-  streams.emplace_back(std::move(stream));
-  timespec dev_time = SingleInputDevNextWake(240, 0, &start, &format, streams);
-  // The device wake up time should be 5ms from now. At that time there are
-  // 240 frames in the device.
-  const timespec add_millis = {0, 5 * 1000 * 1000};
-  add_timespecs(&start, &add_millis);
-  EXPECT_EQ(start.tv_sec, dev_time.tv_sec);
-  EXPECT_EQ(start.tv_nsec, dev_time.tv_nsec);
-}
-
-// Test rule_5.
-// The stream with USE_DEV_TIMING flag will be ignore if it is pending reply.
-TEST_F(TimingSuite, InputWakeTimeOneStreamUsingDevTimingWithPendingReply) {
-  cras_audio_format format;
-  fill_audio_format(&format, 48000);
-
-  StreamPtr stream = create_stream(1, 1, CRAS_STREAM_INPUT, 480, &format);
-
-  struct timespec start;
-  clock_gettime(CLOCK_MONOTONIC_RAW, &start);
-
-  // The next callback should be ignored.
-  stream->rstream->next_cb_ts = start;
-  stream->rstream->next_cb_ts.tv_sec += 10;
-  stream->rstream->flags = USE_DEV_TIMING;
-  rstream_stub_pending_reply(stream->rstream.get(), 1);
-
-  std::vector<StreamPtr> streams;
-  streams.emplace_back(std::move(stream));
-  timespec dev_time = SingleInputDevNextWake(4800, 0, &start, &format, streams);
-
-  // The device wake up time should be 100ms from now. At that time the hw_level
-  // is buffer_size / 2.
-  const timespec add_millis = {0, 100 * 1000 * 1000};
-  add_timespecs(&start, &add_millis);
-  EXPECT_EQ(start.tv_sec, dev_time.tv_sec);
-  EXPECT_EQ(start.tv_nsec, dev_time.tv_nsec);
-}
-
-// Test rule_6.
-// Add a new stream, the wake up time is the time when it has enough data to
-// post.
-TEST_F(TimingSuite, InputWakeTimeOneStreamWithEmptyDevice) {
-  cras_audio_format format;
-  fill_audio_format(&format, 48000);
-
-  StreamPtr stream = create_stream(1, 1, CRAS_STREAM_INPUT, 480, &format);
-
-  struct timespec start;
-  clock_gettime(CLOCK_MONOTONIC_RAW, &start);
-
-  // The next callback of the new stream is 0.
-  stream->rstream->next_cb_ts.tv_sec = 0;
-  stream->rstream->next_cb_ts.tv_nsec = 0;
-
-  std::vector<StreamPtr> streams;
-  streams.emplace_back(std::move(stream));
-  timespec dev_time = SingleInputDevNextWake(600, 0, &start, &format, streams);
-
-  // 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};
-  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);
-  EXPECT_EQ(start.tv_sec, dev_time.tv_sec);
-  EXPECT_EQ(start.tv_nsec, dev_time.tv_nsec);
-}
-
-// Test rule_6.
-// Add a new stream with enough frames in device, check the wake up time is
-// right now.
-TEST_F(TimingSuite, InputWakeTimeOneStreamWithFullDevice) {
-  cras_audio_format format;
-  fill_audio_format(&format, 48000);
-
-  StreamPtr stream = create_stream(1, 1, CRAS_STREAM_INPUT, 480, &format);
-
-  struct timespec start;
-  clock_gettime(CLOCK_MONOTONIC_RAW, &start);
-
-  // The next callback of the new stream is 0.
-  stream->rstream->next_cb_ts.tv_sec = 0;
-  stream->rstream->next_cb_ts.tv_nsec = 0;
-
-  // If there are enough frames in the device, we should wake up immediately.
-  std::vector<StreamPtr> streams;
-  streams.emplace_back(std::move(stream));
-  timespec dev_time =
-      SingleInputDevNextWake(480, 480, &start, &format, streams);
-  EXPECT_EQ(0, streams[0]->rstream->next_cb_ts.tv_sec);
-  EXPECT_EQ(0, streams[0]->rstream->next_cb_ts.tv_nsec);
-  EXPECT_EQ(start.tv_sec, dev_time.tv_sec);
-  EXPECT_EQ(start.tv_nsec, dev_time.tv_nsec);
-}
-
-// Test rule_8.
-// The stream with USE_DEV_TIMING flag should wake up when it has enough frames
-// to post.
-TEST_F(TimingSuite, InputWakeTimeOneStreamUsingDevTiming) {
-  cras_audio_format format;
-  fill_audio_format(&format, 48000);
-
-  StreamPtr stream = create_stream(1, 1, CRAS_STREAM_INPUT, 480, &format);
-
-  struct timespec start;
-  clock_gettime(CLOCK_MONOTONIC_RAW, &start);
-
-  // The next callback should be ignored.
-  stream->rstream->next_cb_ts = start;
-  stream->rstream->next_cb_ts.tv_sec += 10;
-  stream->rstream->flags = USE_DEV_TIMING;
-
-  std::vector<StreamPtr> streams;
-  streams.emplace_back(std::move(stream));
-  timespec dev_time = SingleInputDevNextWake(600, 0, &start, &format, streams);
-
-  // The device wake up time should be 10ms from now. At that time the
-  // stream will have 480 samples to post.
-  const timespec add_millis = {0, 10 * 1000 * 1000};
-  add_timespecs(&start, &add_millis);
-  EXPECT_EQ(start.tv_sec, dev_time.tv_sec);
-  EXPECT_EQ(start.tv_nsec, dev_time.tv_nsec);
-}
-
-// Test rule_9.
-// The device wake up time should be 10ms from now. At that time the hw_level
-// is buffer_size / 2.
-TEST_F(TimingSuite, InputWakeTimeNoStreamSmallBufferDevice) {
-  cras_audio_format format;
-  fill_audio_format(&format, 48000);
-
-  struct timespec start;
-  clock_gettime(CLOCK_MONOTONIC_RAW, &start);
-
-  std::vector<StreamPtr> streams;
-  timespec dev_time = SingleInputDevNextWake(480, 0, &start, &format, streams);
-
-  const timespec add_millis = {0, 10 * 1000 * 1000};
-  add_timespecs(&start, &add_millis);
-  EXPECT_EQ(start.tv_sec, dev_time.tv_sec);
-  EXPECT_EQ(start.tv_nsec, dev_time.tv_nsec);
-}
-
-// Test rule_9.
-// There are more than buffer_size / 2 frames in the device. The device needs
-// to sleep at least 5ms.
-TEST_F(TimingSuite, InputWakeTimeOneStreamWithEnoughFramesInDevice) {
-  cras_audio_format format;
-  fill_audio_format(&format, 48000);
-
-  StreamPtr stream = create_stream(1, 1, CRAS_STREAM_INPUT, 480, &format);
-
-  struct timespec start;
-  clock_gettime(CLOCK_MONOTONIC_RAW, &start);
-
-  // Make next_cb_ts far from now.
-  stream->rstream->next_cb_ts = start;
-  stream->rstream->next_cb_ts.tv_sec += 10;
-
-  std::vector<StreamPtr> streams;
-  streams.emplace_back(std::move(stream));
-  timespec dev_time =
-      SingleInputDevNextWake(480, 480, &start, &format, streams);
-
-  const timespec add_millis = {0, 5 * 1000 * 1000};
-  add_timespecs(&start, &add_millis);
-  EXPECT_EQ(start.tv_sec, dev_time.tv_sec);
-  EXPECT_EQ(start.tv_nsec, dev_time.tv_nsec);
-}
-
 // One device, one stream, write a callback of data and check the sleep time is
 // one more wakeup interval.
 TEST_F(TimingSuite, WaitAfterFill) {
@@ -491,15 +89,11 @@
 
   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.
-  const timespec ten_millis = {0, 10 * 1000 * 1000};
-  add_timespecs(&start, &ten_millis);
-  EXPECT_EQ(start.tv_sec, streams[0]->rstream->next_cb_ts.tv_sec);
-  EXPECT_EQ(start.tv_nsec, streams[0]->rstream->next_cb_ts.tv_nsec);
   EXPECT_EQ(dev_time.tv_sec, streams[0]->rstream->next_cb_ts.tv_sec);
   EXPECT_EQ(dev_time.tv_nsec, streams[0]->rstream->next_cb_ts.tv_nsec);
 }
@@ -523,8 +117,8 @@
 
   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 +148,8 @@
 
   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);
@@ -583,8 +177,8 @@
 
   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;
@@ -611,7 +205,7 @@
   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);
@@ -619,8 +213,8 @@
   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;
@@ -639,21 +233,23 @@
   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.
@@ -675,23 +271,25 @@
   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;
@@ -710,7 +308,8 @@
   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;
@@ -723,7 +322,8 @@
   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.
@@ -742,7 +342,8 @@
   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;
 
@@ -753,8 +354,8 @@
   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());
@@ -781,7 +382,8 @@
   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;
 
@@ -792,7 +394,8 @@
   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());
@@ -805,380 +408,52 @@
   EXPECT_LT(delta.tv_sec, 0.1);
 }
 
-// When a new output stream is added, there are two rules to determine the
-// initial next_cb_ts.
-// 1. If the device already has streams, the next_cb_ts will be the earliest
-// next callback time from these streams.
-// 2. If there are no other streams, the next_cb_ts will be set to the time
-// when the valid frames in device is lower than cb_threshold. (If it is
-// already lower than cb_threshold, set next_cb_ts to now.)
-
-// Test rule 1.
-// The device already has streams, the next_cb_ts will be the earliest
-// next_cb_ts from these streams.
-TEST_F(TimingSuite, NewOutputStreamInitStreamInDevice) {
-  struct open_dev* dev_list_ = NULL;
-
-  cras_audio_format format;
-  fill_audio_format(&format, 48000);
-  DevicePtr dev = create_device(CRAS_STREAM_OUTPUT, 1024, &format,
-                                CRAS_NODE_TYPE_HEADPHONE);
-  DL_APPEND(dev_list_, dev->odev.get());
-  struct cras_iodev* iodev = dev->odev->dev;
-
-  StreamPtr stream = create_stream(1, 1, CRAS_STREAM_OUTPUT, 480, &format);
-  add_stream_to_dev(dev->dev, stream);
-  stream->rstream->next_cb_ts.tv_sec = 54321;
-  stream->rstream->next_cb_ts.tv_nsec = 12345;
-
-  ShmPtr shm = create_shm(480);
-  RstreamPtr rstream =
-      create_rstream(1, CRAS_STREAM_OUTPUT, 480, &format, shm.get());
-
-  dev_io_append_stream(&dev_list_, rstream.get(), &iodev, 1);
-
-  EXPECT_EQ(stream->rstream->next_cb_ts.tv_sec, rstream->next_cb_ts.tv_sec);
-  EXPECT_EQ(stream->rstream->next_cb_ts.tv_nsec, rstream->next_cb_ts.tv_nsec);
-
-  dev_stream_destroy(iodev->streams->next);
-}
-
-// Test rule 2.
-// The there are no streams and no frames in device buffer. The next_cb_ts
-// will be set to now.
-TEST_F(TimingSuite, NewOutputStreamInitNoStreamNoFramesInDevice) {
-  struct open_dev* dev_list_ = NULL;
-
-  cras_audio_format format;
-  fill_audio_format(&format, 48000);
-  DevicePtr dev = create_device(CRAS_STREAM_OUTPUT, 1024, &format,
-                                CRAS_NODE_TYPE_HEADPHONE);
-  DL_APPEND(dev_list_, dev->odev.get());
-  struct cras_iodev* iodev = dev->odev->dev;
-
-  struct timespec start;
-  clock_gettime(CLOCK_MONOTONIC_RAW, &start);
-
-  ShmPtr shm = create_shm(480);
-  RstreamPtr rstream =
-      create_rstream(1, CRAS_STREAM_OUTPUT, 480, &format, shm.get());
-
-  dev_io_append_stream(&dev_list_, rstream.get(), &iodev, 1);
-
-  EXPECT_EQ(start.tv_sec, rstream->next_cb_ts.tv_sec);
-  EXPECT_EQ(start.tv_nsec, rstream->next_cb_ts.tv_nsec);
-
-  dev_stream_destroy(iodev->streams);
-}
-
-// Test rule 2.
-// The there are no streams and some valid frames in device buffer. The
-// next_cb_ts will be set to the time that valid frames in device is lower
-// than cb_threshold.
-TEST_F(TimingSuite, NewOutputStreamInitNoStreamSomeFramesInDevice) {
-  struct open_dev* dev_list_ = NULL;
-
-  cras_audio_format format;
-  fill_audio_format(&format, 48000);
-  DevicePtr dev = create_device(CRAS_STREAM_OUTPUT, 1024, &format,
-                                CRAS_NODE_TYPE_HEADPHONE);
-  DL_APPEND(dev_list_, dev->odev.get());
-  struct cras_iodev* iodev = dev->odev->dev;
-
-  struct timespec start;
-  clock_gettime(CLOCK_MONOTONIC_RAW, &start);
-
-  iodev_stub_valid_frames(iodev, 960, start);
-
-  ShmPtr shm = create_shm(480);
-  RstreamPtr rstream =
-      create_rstream(1, CRAS_STREAM_OUTPUT, 480, &format, shm.get());
-
-  dev_io_append_stream(&dev_list_, rstream.get(), &iodev, 1);
-
-  // The next_cb_ts should be 10ms from now. At that time there are
-  // only 480 valid frames in the device.
-  const timespec add_millis = {0, 10 * 1000 * 1000};
-  add_timespecs(&start, &add_millis);
-  EXPECT_EQ(start.tv_sec, rstream->next_cb_ts.tv_sec);
-  EXPECT_EQ(start.tv_nsec, rstream->next_cb_ts.tv_nsec);
-
-  dev_stream_destroy(iodev->streams);
-}
-
-// There is the pseudo code about wake up time for a output device.
-//
-// function dev_io_next_output_wake(dev):
-//   wake_ts = get_next_stream_wake_from_list(dev.streams)
-//   if cras_iodev_odev_should_wake(dev):
-//     wake_ts = MIN(wake_ts, dev.wake_ts) # rule_1
-//
-// function get_next_stream_wake_from_list(streams):
-//   for stream in streams:
-//     if stream is draining: # rule_2
-//     	 continue
-//     if stream is pending reply: # rule_3
-//       continue
-//     if stream is USE_DEV_TIMING: # rule_4
-//       continue
-//     min_ts = MIN(min_ts, stream.next_cb_ts) # rule_5
-//   return min_ts
-//
-// # This function is in iodev so we don't test its logic here.
-// function cras_iodev_odev_should_wake(dev):
-//   if dev.is_free_running:
-//     return False
-//   if dev.state == NORMAL_RUN or dev.state == NO_STREAM_RUN:
-//     return True
-//   return False
-
-// Test rule_1.
-// The wake up time should be the earlier time amoung streams and devices.
-TEST_F(TimingSuite, OutputWakeTimeOneStreamWithEarlierStreamWakeTime) {
-  cras_audio_format format;
-  fill_audio_format(&format, 48000);
-  struct timespec start;
-  clock_gettime(CLOCK_MONOTONIC_RAW, &start);
-
-  StreamPtr stream = create_stream(1, 1, CRAS_STREAM_OUTPUT, 480, &format);
-  stream->rstream->next_cb_ts = start;
-  stream->rstream->next_cb_ts.tv_sec += 1;
-
-  std::vector<StreamPtr> streams;
-  streams.emplace_back(std::move(stream));
-
-  struct timespec dev_wake_ts = start;
-  dev_wake_ts.tv_sec += 2;
-
-  timespec dev_time =
-      SingleOutputDevNextWake(48000, 0, &start, &format, streams, &dev_wake_ts);
-
-  EXPECT_EQ(start.tv_sec + 1, dev_time.tv_sec);
-  EXPECT_EQ(start.tv_nsec, dev_time.tv_nsec);
-}
-
-// Test rule_1.
-// The wake up time should be the earlier time amoung streams and devices.
-TEST_F(TimingSuite, OutputWakeTimeOneStreamWithEarlierDeviceWakeTime) {
-  cras_audio_format format;
-  fill_audio_format(&format, 48000);
-  struct timespec start;
-  clock_gettime(CLOCK_MONOTONIC_RAW, &start);
-
-  StreamPtr stream = create_stream(1, 1, CRAS_STREAM_OUTPUT, 480, &format);
-  stream->rstream->next_cb_ts = start;
-  stream->rstream->next_cb_ts.tv_sec += 2;
-
-  std::vector<StreamPtr> streams;
-  streams.emplace_back(std::move(stream));
-
-  struct timespec dev_wake_ts = start;
-  dev_wake_ts.tv_sec += 1;
-
-  timespec dev_time =
-      SingleOutputDevNextWake(48000, 0, &start, &format, streams, &dev_wake_ts);
-
-  EXPECT_EQ(start.tv_sec + 1, dev_time.tv_sec);
-  EXPECT_EQ(start.tv_nsec, dev_time.tv_nsec);
-}
-
-// Test rule_2.
-// The stream 1 is draining so it will be ignored. The wake up time should be
-// the next_cb_ts of stream 2.
-TEST_F(TimingSuite, OutputWakeTimeTwoStreamsWithOneIsDraining) {
-  cras_audio_format format;
-  fill_audio_format(&format, 48000);
-  struct timespec start;
-  clock_gettime(CLOCK_MONOTONIC_RAW, &start);
-
-  StreamPtr stream1 = create_stream(1, 1, CRAS_STREAM_OUTPUT, 480, &format);
-  stream1->rstream->next_cb_ts = start;
-  stream1->rstream->next_cb_ts.tv_sec += 2;
-  stream1->rstream->is_draining = 1;
-  stream1->rstream->queued_frames = 480;
-
-  StreamPtr stream2 = create_stream(1, 2, CRAS_STREAM_OUTPUT, 480, &format);
-  stream2->rstream->next_cb_ts = start;
-  stream2->rstream->next_cb_ts.tv_sec += 5;
-
-  std::vector<StreamPtr> streams;
-  streams.emplace_back(std::move(stream1));
-  streams.emplace_back(std::move(stream2));
-
-  struct timespec dev_wake_ts = start;
-  dev_wake_ts.tv_sec += 10;
-
-  timespec dev_time =
-      SingleOutputDevNextWake(48000, 0, &start, &format, streams, &dev_wake_ts);
-
-  EXPECT_EQ(start.tv_sec + 5, dev_time.tv_sec);
-  EXPECT_EQ(start.tv_nsec, dev_time.tv_nsec);
-}
-
-// Test rule_3.
-// The stream 1 is pending reply so it will be ignored. The wake up time should
-// be the next_cb_ts of stream 2.
-TEST_F(TimingSuite, OutputWakeTimeTwoStreamsWithOneIsPendingReply) {
-  cras_audio_format format;
-  fill_audio_format(&format, 48000);
-  struct timespec start;
-  clock_gettime(CLOCK_MONOTONIC_RAW, &start);
-
-  StreamPtr stream1 = create_stream(1, 1, CRAS_STREAM_OUTPUT, 480, &format);
-  stream1->rstream->next_cb_ts = start;
-  stream1->rstream->next_cb_ts.tv_sec += 2;
-  rstream_stub_pending_reply(stream1->rstream.get(), 1);
-
-  StreamPtr stream2 = create_stream(1, 2, CRAS_STREAM_OUTPUT, 480, &format);
-  stream2->rstream->next_cb_ts = start;
-  stream2->rstream->next_cb_ts.tv_sec += 5;
-
-  std::vector<StreamPtr> streams;
-  streams.emplace_back(std::move(stream1));
-  streams.emplace_back(std::move(stream2));
-
-  struct timespec dev_wake_ts = start;
-  dev_wake_ts.tv_sec += 10;
-
-  timespec dev_time =
-      SingleOutputDevNextWake(48000, 0, &start, &format, streams, &dev_wake_ts);
-
-  EXPECT_EQ(start.tv_sec + 5, dev_time.tv_sec);
-  EXPECT_EQ(start.tv_nsec, dev_time.tv_nsec);
-}
-
-// Test rule_4.
-// The stream 1 is uning device timing so it will be ignored. The wake up time
-// should be the next_cb_ts of stream 2.
-TEST_F(TimingSuite, OutputWakeTimeTwoStreamsWithOneIsUsingDevTiming) {
-  cras_audio_format format;
-  fill_audio_format(&format, 48000);
-  struct timespec start;
-  clock_gettime(CLOCK_MONOTONIC_RAW, &start);
-
-  StreamPtr stream1 = create_stream(1, 1, CRAS_STREAM_OUTPUT, 480, &format);
-  stream1->rstream->next_cb_ts = start;
-  stream1->rstream->next_cb_ts.tv_sec += 2;
-  stream1->rstream->flags = USE_DEV_TIMING;
-
-  StreamPtr stream2 = create_stream(1, 2, CRAS_STREAM_OUTPUT, 480, &format);
-  stream2->rstream->next_cb_ts = start;
-  stream2->rstream->next_cb_ts.tv_sec += 5;
-
-  std::vector<StreamPtr> streams;
-  streams.emplace_back(std::move(stream1));
-  streams.emplace_back(std::move(stream2));
-
-  struct timespec dev_wake_ts = start;
-  dev_wake_ts.tv_sec += 10;
-
-  timespec dev_time =
-      SingleOutputDevNextWake(48000, 0, &start, &format, streams, &dev_wake_ts);
-
-  EXPECT_EQ(start.tv_sec + 5, dev_time.tv_sec);
-  EXPECT_EQ(start.tv_nsec, dev_time.tv_nsec);
-}
-
-// Test rule_5.
-// The wake up time should be the next_cb_ts of streams.
-TEST_F(TimingSuite, OutputWakeTimeTwoStreams) {
-  cras_audio_format format;
-  fill_audio_format(&format, 48000);
-  struct timespec start;
-  clock_gettime(CLOCK_MONOTONIC_RAW, &start);
-
-  StreamPtr stream1 = create_stream(1, 1, CRAS_STREAM_OUTPUT, 480, &format);
-  stream1->rstream->next_cb_ts = start;
-  stream1->rstream->next_cb_ts.tv_sec += 2;
-
-  StreamPtr stream2 = create_stream(1, 2, CRAS_STREAM_OUTPUT, 480, &format);
-  stream2->rstream->next_cb_ts = start;
-  stream2->rstream->next_cb_ts.tv_sec += 5;
-
-  std::vector<StreamPtr> streams;
-  streams.emplace_back(std::move(stream1));
-  streams.emplace_back(std::move(stream2));
-
-  struct timespec dev_wake_ts = start;
-  dev_wake_ts.tv_sec += 10;
-
-  timespec dev_time =
-      SingleOutputDevNextWake(48000, 0, &start, &format, streams, &dev_wake_ts);
-
-  EXPECT_EQ(start.tv_sec + 2, dev_time.tv_sec);
-  EXPECT_EQ(start.tv_nsec, dev_time.tv_nsec);
-}
-
-// One device, one stream, fetch stream and check the sleep time is one more
-// wakeup interval.
-TEST_F(TimingSuite, OutputStreamsUpdateAfterFetching) {
-  cras_audio_format format;
-  fill_audio_format(&format, 48000);
-
-  StreamPtr stream = create_stream(1, 1, CRAS_STREAM_OUTPUT, 480, &format);
-
-  // rstream's next callback is now.
-  struct timespec start;
-  clock_gettime(CLOCK_MONOTONIC_RAW, &start);
-  stream->rstream->next_cb_ts = start;
-
-  struct open_dev* dev_list_ = NULL;
-
-  DevicePtr dev = create_device(CRAS_STREAM_OUTPUT, 1024, &format,
-                                CRAS_NODE_TYPE_HEADPHONE);
-  DL_APPEND(dev_list_, dev->odev.get());
-
-  add_stream_to_dev(dev->dev, stream);
-
-  dev_io_playback_fetch(dev_list_);
-
-  // The next callback should be scheduled 10ms in the future.
-  const timespec ten_millis = {0, 10 * 1000 * 1000};
-  add_timespecs(&start, &ten_millis);
-  EXPECT_EQ(start.tv_sec, stream->rstream->next_cb_ts.tv_sec);
-  EXPECT_EQ(start.tv_nsec, stream->rstream->next_cb_ts.tv_nsec);
-}
-
-// TODO(yuhsuan): There are some time scheduling rules in cras_iodev. Maybe we
-// can move them into dev_io so that all timing related codes are in the same
-// file or leave them in iodev_unittest like now.
-// 1. Device's wake_ts update: cras_iodev_frames_to_play_in_sleep.
-// 2. wake_ts update when removing stream: cras_iodev_rm_stream.
-
 /* 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 cras_server_metrics_highest_hw_level(unsigned hw_level,
+		enum CRAS_STREAM_DIRECTION direction)
+{
   return 0;
 }
 
-int input_data_put_for_stream(struct input_data* data,
-                              struct cras_rstream* stream,
-                              struct buffer_share* offsets,
-                              unsigned int frames) {
+int cras_server_metrics_longest_fetch_delay(unsigned delay_msec)
+{
   return 0;
 }
 
-struct cras_audio_format* cras_rstream_post_processing_format(
-    const struct cras_rstream* stream,
-    void* dev_ptr) {
+int cras_server_metrics_num_underruns(unsigned num_underruns)
+{
+  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)
+{
+  return 0;
+}
+
+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)
+{
   return NULL;
 }
-
-int cras_audio_thread_event_drop_samples() {
-  return 0;
-}
-
 }  // extern "C"
 
 }  //  namespace
 
 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/utf8_unittest.cc b/cras/src/tests/utf8_unittest.cc
index 4a13fcf..34360c3 100644
--- a/cras/src/tests/utf8_unittest.cc
+++ b/cras/src/tests/utf8_unittest.cc
@@ -19,8 +19,7 @@
 
   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));
@@ -116,22 +115,18 @@
 
   /* 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. */
@@ -153,7 +148,7 @@
 
 }  //  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 e61336a..3dbc026 100644
--- a/cras/src/tests/util_unittest.cc
+++ b/cras/src/tests/util_unittest.cc
@@ -3,11 +3,10 @@
 // found in the LICENSE file.
 
 #include <gtest/gtest.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <unistd.h>
-
 #include <string>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <unistd.h>
 #include <vector>
 
 #include "cras_util.h"
@@ -209,6 +208,7 @@
 }
 
 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));
@@ -246,7 +246,7 @@
 
 TEST(Util, FramesSinceTime) {
   struct timespec t, tn;
-  uint64_t frames;
+  unsigned int frames;
 
   t.tv_sec = 0;
   t.tv_nsec = 500000000;
@@ -310,12 +310,13 @@
 /* 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;
 }
@@ -324,7 +325,7 @@
 
 }  //  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 267452a..2f8c300 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 <gtest/gtest.h>
 #include <stdio.h>
+#include <gtest/gtest.h>
 
 extern "C" {
 #include "cras_volume_curve.h"
@@ -12,9 +12,9 @@
 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, 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, 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/tools/cras_test_client/cras_test_client.c b/cras/src/tools/cras_test_client/cras_test_client.c
deleted file mode 100644
index a784506..0000000
--- a/cras/src/tools/cras_test_client/cras_test_client.c
+++ /dev/null
@@ -1,2168 +0,0 @@
-/* Copyright (c) 2012 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 <fcntl.h>
-#include <getopt.h>
-#include <inttypes.h>
-#include <limits.h>
-#include <math.h>
-#include <pthread.h>
-#include <stdio.h>
-#include <stdint.h>
-#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>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include "cras_client.h"
-#include "cras_types.h"
-#include "cras_util.h"
-#include "cras_version.h"
-
-#define NOT_ASSIGNED (0)
-#define PLAYBACK_BUFFERED_TIME_IN_US (5000)
-
-#define BUF_SIZE 32768
-
-static const size_t MAX_IODEVS = 10; /* Max devices to print out. */
-static const size_t MAX_IONODES = 20; /* Max ionodes to print out. */
-static const size_t MAX_ATTACHED_CLIENTS = 10; /* Max clients to print out. */
-
-static int pipefd[2];
-static struct timespec last_latency;
-static int show_latency;
-static float last_rms_sqr_sum;
-static int last_rms_size;
-static float total_rms_sqr_sum;
-static int total_rms_size;
-static int show_rms;
-static int show_total_rms;
-static int keep_looping = 1;
-static int exit_after_done_playing = 1;
-static size_t duration_frames;
-static int pause_client = 0;
-static int pause_a_reply = 0;
-static int pause_in_playback_reply = 1000;
-
-static char *channel_layout = NULL;
-static int pin_device_id;
-
-static int play_short_sound = 0;
-static int play_short_sound_periods = 0;
-static int play_short_sound_periods_left = 0;
-
-static int effect_aec = 0;
-static int effect_ns = 0;
-static int effect_agc = 0;
-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;
-
-struct cras_audio_format *aud_format;
-struct {
-	char *name;
-	snd_pcm_format_t format;
-} supported_formats[] = {
-	{ "S16_LE", SND_PCM_FORMAT_S16_LE },
-	{ "S24_LE", SND_PCM_FORMAT_S24_LE },
-	{ "S32_LE", SND_PCM_FORMAT_S32_LE },
-	{ NULL, 0 },
-};
-
-static int terminate_stream_loop()
-{
-	keep_looping = 0;
-	return write(pipefd[1], "1", 1);
-}
-
-static size_t get_block_size(uint64_t buffer_time_in_us, size_t rate)
-{
-	return (size_t)(buffer_time_in_us * rate / 1000000);
-}
-
-static void check_stream_terminate(size_t frames)
-{
-	if (duration_frames) {
-		if (duration_frames <= frames)
-			terminate_stream_loop();
-		else
-			duration_frames -= 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)
-{
-	unsigned i;
-	float sqr_sum = 0;
-
-	for (i = 0; i < size; i++)
-		sqr_sum += samples[i] * samples[i];
-
-	return sqr_sum;
-}
-
-/* Update the RMS values with the given samples. */
-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_size = size / 2;
-		break;
-	}
-	default:
-		return -EINVAL;
-	}
-
-	total_rms_sqr_sum += last_rms_sqr_sum;
-	total_rms_size += last_rms_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,
-		       unsigned int frames,
-		       const struct timespec *captured_time,
-		       const struct timespec *playback_time, void *user_arg)
-{
-	int *fd = (int *)user_arg;
-	int ret;
-	int write_size;
-	int frame_bytes;
-
-	while (pause_client)
-		usleep(10000);
-
-	cras_client_calc_capture_latency(captured_time, &last_latency);
-
-	frame_bytes = cras_client_format_bytes_per_frame(aud_format);
-	write_size = frames * frame_bytes;
-
-	/* Update RMS values with all available frames. */
-	if (keep_looping) {
-		update_rms(captured_samples,
-			   MIN(write_size, duration_frames * frame_bytes));
-	}
-
-	check_stream_terminate(frames);
-
-	ret = write(*fd, captured_samples, write_size);
-	if (ret != write_size)
-		printf("Error writing file\n");
-	return frames;
-}
-
-/* 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,
-		       unsigned int frames,
-		       const struct timespec *captured_time,
-		       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;
-	uint8_t buff[BUF_SIZE];
-	int nread;
-
-	while (pause_client)
-		usleep(10000);
-
-	if (pause_a_reply) {
-		usleep(pause_in_playback_reply);
-		pause_a_reply = 0;
-	}
-
-	check_stream_terminate(frames);
-
-	cras_client_calc_playback_latency(playback_time, &last_latency);
-
-	if (play_short_sound) {
-		if (play_short_sound_periods_left)
-			/* Play a period from file. */
-			play_short_sound_periods_left--;
-		else {
-			/* Fill zeros to play silence. */
-			memset(playback_samples, 0,
-			       MIN(frames * frame_bytes, BUF_SIZE));
-			return frames;
-		}
-	}
-
-	nread = read(fd, buff, MIN(frames * frame_bytes, BUF_SIZE));
-	if (nread <= 0) {
-		if (exit_after_done_playing)
-			terminate_stream_loop();
-		return nread;
-	}
-
-	memcpy(playback_samples, buff, nread);
-	return nread / frame_bytes;
-}
-
-/* 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)
-{
-	int rc = 0;
-	uint32_t frame_bytes = cras_client_format_bytes_per_frame(aud_format);
-
-	rc = read(0, playback_samples, frames * frame_bytes);
-	if (rc <= 0) {
-		terminate_stream_loop();
-		return -1;
-	}
-
-	return rc / frame_bytes;
-}
-
-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 void print_last_latency()
-{
-	if (last_latency.tv_sec > 0 || last_latency.tv_nsec > 0)
-		printf("%u.%09u\n", (unsigned)last_latency.tv_sec,
-		       (unsigned)last_latency.tv_nsec);
-	else {
-		printf("-%lld.%09lld\n", (long long)-last_latency.tv_sec,
-		       (long long)-last_latency.tv_nsec);
-	}
-}
-
-static void print_last_rms()
-{
-	if (last_rms_size != 0)
-		printf("%.9f\n", sqrt(last_rms_sqr_sum / last_rms_size));
-}
-
-static void print_total_rms()
-{
-	if (total_rms_size != 0)
-		printf("%.9f\n", sqrt(total_rms_sqr_sum / total_rms_size));
-}
-
-static void print_dev_info(const struct cras_iodev_info *devs, int num_devs)
-{
-	unsigned i;
-
-	printf("\tID\tName\n");
-	for (i = 0; i < num_devs; i++)
-		printf("\t%u\t%s\n", devs[i].idx, devs[i].name);
-}
-
-static void print_node_info(const struct cras_ionode_info *nodes, int num_nodes,
-			    int is_input)
-{
-	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");
-	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].ionode_idx,
-		       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);
-}
-
-static void print_device_lists(struct cras_client *client)
-{
-	struct cras_iodev_info devs[MAX_IODEVS];
-	struct cras_ionode_info nodes[MAX_IONODES];
-	size_t num_devs, num_nodes;
-	int rc;
-
-	num_devs = MAX_IODEVS;
-	num_nodes = MAX_IONODES;
-	rc = cras_client_get_output_devices(client, devs, nodes, &num_devs,
-					    &num_nodes);
-	if (rc < 0)
-		return;
-	printf("Output Devices:\n");
-	print_dev_info(devs, num_devs);
-	printf("Output Nodes:\n");
-	print_node_info(nodes, num_nodes, 0);
-
-	num_devs = MAX_IODEVS;
-	num_nodes = MAX_IONODES;
-	rc = cras_client_get_input_devices(client, devs, nodes, &num_devs,
-					   &num_nodes);
-	printf("Input Devices:\n");
-	print_dev_info(devs, num_devs);
-	printf("Input Nodes:\n");
-	print_node_info(nodes, num_nodes, 1);
-}
-
-static void print_attached_client_list(struct cras_client *client)
-{
-	struct cras_attached_client_info clients[MAX_ATTACHED_CLIENTS];
-	size_t i;
-	int num_clients;
-
-	num_clients = cras_client_get_attached_clients(client, clients,
-						       MAX_ATTACHED_CLIENTS);
-	if (num_clients < 0)
-		return;
-	num_clients = MIN(num_clients, MAX_ATTACHED_CLIENTS);
-	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,
-		       clients[i].gid);
-}
-
-static void print_active_stream_info(struct cras_client *client)
-{
-	struct timespec ts;
-	unsigned num_streams;
-
-	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);
-}
-
-static void print_system_volumes(struct cras_client *client)
-{
-	printf("System Volume (0-100): %zu %s\n"
-	       "Capture Gain (%.2f - %.2f): %.2fdB %s\n",
-	       cras_client_get_system_volume(client),
-	       cras_client_get_system_muted(client) ? "(Muted)" : "",
-	       cras_client_get_system_min_capture_gain(client) / 100.0,
-	       cras_client_get_system_max_capture_gain(client) / 100.0,
-	       cras_client_get_system_capture_gain(client) / 100.0,
-	       cras_client_get_system_capture_muted(client) ? "(Muted)" : "");
-}
-
-static void print_user_muted(struct cras_client *client)
-{
-	printf("User muted: %s\n",
-	       cras_client_get_user_muted(client) ? "Muted" : "Not muted");
-}
-
-/*
- * Convert time value from one clock to the other using given offset
- * in sec and nsec.
- */
-static void convert_time(unsigned int *sec, unsigned int *nsec,
-			 time_t sec_offset, int32_t nsec_offset)
-{
-	sec_offset += *sec;
-	nsec_offset += *nsec;
-	if (nsec_offset >= 1000000000L) {
-		sec_offset++;
-		nsec_offset -= 1000000000L;
-	} else if (nsec_offset < 0) {
-		sec_offset--;
-		nsec_offset += 1000000000L;
-	}
-	*sec = sec_offset;
-	*nsec = nsec_offset;
-}
-
-static void show_alog_tag(const struct audio_thread_event_log *log,
-			  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;
-	unsigned int nsec = log->log[tag_idx].nsec;
-	unsigned int data1 = log->log[tag_idx].data1;
-	unsigned int data2 = log->log[tag_idx].data2;
-	unsigned int data3 = log->log[tag_idx].data3;
-	time_t lt;
-	struct tm *t;
-
-	/* Skip unused log entries. */
-	if (log->log[tag_idx].tag_sec == 0 && log->log[tag_idx].nsec == 0)
-		return;
-
-	/* Convert from monotomic raw clock to realtime clock. */
-	convert_time(&sec, &nsec, sec_offset, nsec_offset);
-	lt = sec;
-	t = localtime(&lt);
-	strftime(time_str, 128, "%Y-%m-%dT%H:%M:%S", t);
-
-	printf("%s.%09u cras atlog  ", time_str, nsec);
-
-	/* Prepare realtime string for arguments. */
-	switch (tag) {
-	case AUDIO_THREAD_READ_AUDIO_TSTAMP:
-	case AUDIO_THREAD_FILL_AUDIO_TSTAMP:
-	case AUDIO_THREAD_STREAM_RESCHEDULE:
-	case AUDIO_THREAD_STREAM_SLEEP_TIME:
-	case AUDIO_THREAD_STREAM_SLEEP_ADJUST:
-	case AUDIO_THREAD_DEV_SLEEP_TIME:
-		sec = data2;
-		nsec = data3;
-		break;
-	}
-	convert_time(&sec, &nsec, sec_offset, nsec_offset);
-	lt = sec;
-	t = localtime(&lt);
-	strftime(time_str, 128, " %H:%M:%S", t);
-
-	switch (tag) {
-	case AUDIO_THREAD_WAKE:
-		printf("%-30s num_fds:%d\n", "WAKE", (int)data1);
-		break;
-	case AUDIO_THREAD_SLEEP:
-		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);
-		break;
-	case AUDIO_THREAD_READ_AUDIO_TSTAMP:
-		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);
-		break;
-	case AUDIO_THREAD_READ_OVERRUN:
-		printf("%-30s dev:%u stream:%x num_overruns:%u\n",
-		       "READ_AUDIO_OVERRUN", data1, data2, data3);
-		break;
-	case AUDIO_THREAD_FILL_AUDIO:
-		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);
-		break;
-	case AUDIO_THREAD_FILL_AUDIO_DONE:
-		printf("%-30s hw_level:%u total_written:%u min_cb_level:%u\n",
-		       "FILL_AUDIO_DONE", data1, data2, data3);
-		break;
-	case AUDIO_THREAD_WRITE_STREAMS_WAIT:
-		printf("%-30s stream:%x\n", "WRITE_STREAMS_WAIT", data1);
-		break;
-	case AUDIO_THREAD_WRITE_STREAMS_WAIT_TO:
-		printf("%-30s\n", "WRITE_STREAMS_WAIT_TO");
-		break;
-	case AUDIO_THREAD_WRITE_STREAMS_MIX:
-		printf("%-30s write_limit:%u max_offset:%u\n",
-		       "WRITE_STREAMS_MIX", data1, data2);
-		break;
-	case AUDIO_THREAD_WRITE_STREAMS_MIXED:
-		printf("%-30s write_limit:%u\n", "WRITE_STREAMS_MIXED", data1);
-		break;
-	case AUDIO_THREAD_WRITE_STREAMS_STREAM:
-		printf("%-30s id:%x shm_frames:%u cb_pending:%u\n",
-		       "WRITE_STREAMS_STREAM", data1, data2, data3);
-		break;
-	case AUDIO_THREAD_FETCH_STREAM:
-		printf("%-30s id:%x cbth:%u delay:%u\n",
-		       "WRITE_STREAMS_FETCH_STREAM", data1, data2, data3);
-		break;
-	case AUDIO_THREAD_STREAM_ADDED:
-		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);
-		break;
-	case AUDIO_THREAD_A2DP_WRITE:
-		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);
-		break;
-	case AUDIO_THREAD_CAPTURE_POST:
-		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);
-		break;
-	case AUDIO_THREAD_CONV_COPY:
-		printf("%-30s wr_buf:%u shm_writable:%u offset:%u\n",
-		       "CONV_COPY", data1, data2, data3);
-		break;
-	case AUDIO_THREAD_STREAM_FETCH_PENDING:
-		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);
-		break;
-	case AUDIO_THREAD_STREAM_SLEEP_TIME:
-		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);
-		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);
-		break;
-	case AUDIO_THREAD_SET_DEV_WAKE:
-		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);
-		break;
-	case AUDIO_THREAD_DEV_REMOVED:
-		printf("%-30s dev:%u\n", "DEV_REMOVED", data1);
-		break;
-	case AUDIO_THREAD_IODEV_CB:
-		printf("%-30s is_write:%u\n", "IODEV_CB", data1);
-		break;
-	case AUDIO_THREAD_PB_MSG:
-		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);
-		break;
-	case AUDIO_THREAD_ODEV_LEAVE_NO_STREAMS:
-		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);
-		break;
-	case AUDIO_THREAD_FILL_ODEV_ZEROS:
-		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",
-		       "DEFAULT_NO_STREAMS", data1, data2, data3);
-		break;
-	case AUDIO_THREAD_UNDERRUN:
-		printf("%-30s dev:%u hw_level:%u total_written:%u\n",
-		       "UNDERRUN", data1, data2, data3);
-		break;
-	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);
-		break;
-	}
-}
-
-static void print_audio_debug_info(const struct audio_debug_info *info)
-{
-	time_t sec_offset;
-	int32_t nsec_offset;
-	int i, j;
-
-	printf("Audio Debug Stats:\n");
-	printf("-------------devices------------\n");
-	if (info->num_devs > MAX_DEBUG_DEVS)
-		return;
-
-	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].dev_name);
-		printf("buffer_size: %u\n"
-		       "min_buffer_level: %u\n"
-		       "min_cb_level: %u\n"
-		       "max_cb_level: %u\n"
-		       "frame_rate: %u\n"
-		       "num_channels: %u\n"
-		       "est_rate_ratio: %lf\n"
-		       "num_underruns: %u\n"
-		       "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,
-		       (unsigned int)info->devs[i].min_cb_level,
-		       (unsigned int)info->devs[i].max_cb_level,
-		       (unsigned int)info->devs[i].frame_rate,
-		       (unsigned int)info->devs[i].num_channels,
-		       info->devs[i].est_rate_ratio,
-		       (unsigned int)info->devs[i].num_underruns,
-		       (unsigned int)info->devs[i].num_severe_underruns,
-		       (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");
-	}
-
-	printf("-------------stream_dump------------\n");
-	if (info->num_streams > MAX_DEBUG_STREAMS)
-		return;
-
-	for (i = 0; i < info->num_streams; i++) {
-		int channel;
-		printf("stream: %llu dev: %u\n",
-		       (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");
-		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"
-		       "frame_rate: %u\n"
-		       "num_channels: %u\n"
-		       "longest_fetch_sec: %u.%09u\n"
-		       "num_overruns: %u\n"
-		       "is_pinned: %x\n"
-		       "pinned_dev_idx: %x\n"
-		       "num_missed_cb: %u\n"
-		       "%s: %lf\n"
-		       "runtime: %u.%09u\n",
-		       (unsigned int)info->streams[i].buffer_frames,
-		       (unsigned int)info->streams[i].cb_threshold,
-		       (unsigned int)info->streams[i].effects,
-		       (unsigned int)info->streams[i].frame_rate,
-		       (unsigned int)info->streams[i].num_channels,
-		       (unsigned int)info->streams[i].longest_fetch_sec,
-		       (unsigned int)info->streams[i].longest_fetch_nsec,
-		       (unsigned int)info->streams[i].num_overruns,
-		       (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].stream_volume,
-		       (unsigned int)info->streams[i].runtime_sec,
-		       (unsigned int)info->streams[i].runtime_nsec);
-		printf("channel map:");
-		for (channel = 0; channel < CRAS_CH_MAX; channel++)
-			printf("%d ", info->streams[i].channel_layout[channel]);
-		printf("\n\n");
-	}
-
-	printf("Audio Thread Event Log:\n");
-
-	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++) {
-		show_alog_tag(&info->log, j, sec_offset, nsec_offset);
-		j++;
-		j %= info->log.len;
-	}
-}
-
-static void audio_debug_info(struct cras_client *client)
-{
-	const struct audio_debug_info *info;
-	info = cras_client_get_audio_debug_info(client);
-	if (!info)
-		return;
-	print_audio_debug_info(info);
-
-	/* Signal main thread we are done after the last chunk. */
-	pthread_mutex_lock(&done_mutex);
-	pthread_cond_signal(&done_cond);
-	pthread_mutex_unlock(&done_mutex);
-}
-
-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 = (log->log[tag_idx].tag_sec >> 24) & 0xff;
-	unsigned int sec = log->log[tag_idx].tag_sec & 0x00ffffff;
-	unsigned int nsec = log->log[tag_idx].nsec;
-	unsigned int data1 = log->log[tag_idx].data1;
-	unsigned int data2 = log->log[tag_idx].data2;
-	time_t lt;
-	struct tm *t;
-
-	/* Skip unused log entries. */
-	if (log->log[tag_idx].tag_sec == 0 && log->log[tag_idx].nsec == 0)
-		return;
-
-	/* Convert from monotomic raw clock to realtime clock. */
-	convert_time(&sec, &nsec, sec_offset, nsec_offset);
-	lt = sec;
-	t = localtime(&lt);
-	strftime(time_str, 128, "%Y-%m-%dT%H:%M:%S", t);
-
-	printf("%s.%09u cras btlog  ", time_str, nsec);
-
-	switch (tag) {
-	case BT_ADAPTER_ADDED:
-		printf("%-30s\n", "ADAPTER_ADDED");
-		break;
-	case BT_ADAPTER_REMOVED:
-		printf("%-30s\n", "ADAPTER_REMOVED");
-		break;
-	case BT_A2DP_CONFIGURED:
-		printf("%-30s connected profiles %u\n", "A2DP_CONFIGURED",
-		       data1);
-		break;
-	case BT_A2DP_START:
-		printf("%-30s\n", "A2DP_START");
-		break;
-	case BT_A2DP_SUSPENDED:
-		printf("%-30s\n", "A2DP_SUSPENDED");
-		break;
-	case BT_AUDIO_GATEWAY_INIT:
-		printf("%-30s supported profiles %u\n", "AUDIO_GATEWAY_INIT",
-		       data1);
-		break;
-	case BT_AUDIO_GATEWAY_START:
-		printf("%-30s \n", "AUDIO_GATEWAY_START");
-		break;
-	case BT_AVAILABLE_CODECS:
-		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);
-		break;
-	case BT_DEV_CONNECTED_CHANGE:
-		printf("%-30s profiles %u now %u\n", "DEV_CONENCTED_CHANGE",
-		       data1, data2);
-		break;
-	case BT_DEV_CONN_WATCH_CB:
-		printf("%-30s %u retries left, supported profiles %u\n",
-		       "DEV_CONN_WATCH_CB", data1, data2);
-		break;
-	case BT_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");
-		break;
-	case BT_HFP_REQUEST_DISCONNECT:
-		printf("%-30s\n", "HFP_REQUEST_DISCONNECT");
-		break;
-	case BT_HFP_SUPPORTED_FEATURES:
-		printf("%-30s role %s features %u\n", "HFP_SUPPORTED_FEATURES",
-		       data1 ? "AG" : "HF", data2);
-		break;
-	case BT_HSP_NEW_CONNECTION:
-		printf("%-30s\n", "HSP_NEW_CONNECTION");
-		break;
-	case BT_HSP_REQUEST_DISCONNECT:
-		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);
-		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);
-		break;
-	case BT_TRANSPORT_ACQUIRE:
-		printf("%-30s %s fd %d\n", "TRANSPORT_ACQUIRE",
-		       data1 ? "success" : "failed", (int)data2);
-		break;
-	case BT_TRANSPORT_RELEASE:
-		printf("%-30s\n", "TRANSPORT_RELEASE");
-		break;
-	default:
-		printf("%-30s\n", "UNKNOWN");
-		break;
-	}
-}
-
-static void cras_bt_debug_info(struct cras_client *client)
-{
-	const struct cras_bt_debug_info *info;
-	time_t sec_offset;
-	int32_t nsec_offset;
-	int i, j;
-
-	info = cras_client_get_bt_debug_info(client);
-	fill_time_offset(&sec_offset, &nsec_offset);
-	j = info->bt_log.write_pos;
-	i = 0;
-	printf("BT debug log:\n");
-	for (; i < info->bt_log.len; i++) {
-		show_btlog_tag(&info->bt_log, j, sec_offset, nsec_offset);
-		j++;
-		j %= info->bt_log.len;
-	}
-
-	/* Signal main thread we are done after the last chunk. */
-	pthread_mutex_lock(&done_mutex);
-	pthread_cond_signal(&done_cond);
-	pthread_mutex_unlock(&done_mutex);
-}
-
-static void print_cras_audio_thread_snapshot(
-	const struct cras_audio_thread_snapshot *snapshot)
-{
-	printf("-------------snapshot------------\n");
-	printf("Event time: %" PRId64 ".%ld\n",
-	       (int64_t)snapshot->timestamp.tv_sec,
-	       snapshot->timestamp.tv_nsec);
-
-	printf("Event type: ");
-	switch (snapshot->event_type) {
-	case AUDIO_THREAD_EVENT_BUSYLOOP:
-		printf("busyloop\n");
-		break;
-	case AUDIO_THREAD_EVENT_UNDERRUN:
-		printf("underrun\n");
-		break;
-	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;
-	default:
-		printf("no such type\n");
-	}
-	print_audio_debug_info(&snapshot->audio_debug_info);
-}
-
-static void audio_thread_snapshots(struct cras_client *client)
-{
-	const struct cras_audio_thread_snapshot_buffer *snapshot_buffer;
-	uint32_t i;
-	int j;
-	int count = 0;
-
-	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) {
-			print_cras_audio_thread_snapshot(
-				&snapshot_buffer->snapshots[i]);
-			count++;
-		}
-		i++;
-		i %= CRAS_MAX_AUDIO_THREAD_SNAPSHOTS;
-	}
-	printf("There are %d, snapshots.\n", count);
-
-	/* Signal main thread we are done after the last chunk. */
-	pthread_mutex_lock(&done_mutex);
-	pthread_cond_signal(&done_cond);
-	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)
-{
-	int rc;
-
-	if (pin_device_id)
-		rc = cras_client_add_pinned_stream(client, pin_device_id,
-						   stream_id, params);
-	else
-		rc = cras_client_add_stream(client, stream_id, params);
-	if (rc < 0) {
-		fprintf(stderr, "adding a stream %d\n", rc);
-		return rc;
-	}
-	return cras_client_set_stream_volume(client, *stream_id, stream_volume);
-}
-
-static int parse_channel_layout(char *channel_layout_str,
-				int8_t channel_layout[CRAS_CH_MAX])
-{
-	int i = 0;
-	char *chp;
-
-	chp = strtok(channel_layout_str, ",");
-	while (chp && i < CRAS_CH_MAX) {
-		channel_layout[i++] = atoi(chp);
-		chp = strtok(NULL, ",");
-	}
-
-	return 0;
-}
-
-static void run_aecdump(struct cras_client *client, uint64_t stream_id,
-			int start)
-{
-	int aecdump_fd;
-	if (start) {
-		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;
-		}
-
-		printf("Dumping AEC info to %s, stream %" PRId64 ", fd %d\n",
-		       aecdump_file, stream_id, aecdump_fd);
-		cras_client_set_aec_dump(client, stream_id, 1, aecdump_fd);
-	} else {
-		cras_client_set_aec_dump(client, stream_id, 0, -1);
-		printf("Close AEC dump file %s\n", aecdump_file);
-	}
-}
-
-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)
-{
-	int rc, tty;
-	struct cras_stream_params *params;
-	cras_unified_cb_t aud_cb;
-	cras_stream_id_t stream_id = 0;
-	int stream_playing = 0;
-	int *pfd = malloc(sizeof(*pfd));
-	*pfd = fd;
-	fd_set poll_set;
-	struct timespec sleep_ts;
-	float volume_scaler = 1.0;
-	size_t sys_volume = 100;
-	long cap_gain = 0;
-	int mute = 0;
-	int8_t layout[CRAS_CH_MAX];
-
-	/* Set the sleep interval between latency/RMS prints. */
-	sleep_ts.tv_sec = 1;
-	sleep_ts.tv_nsec = 0;
-
-	/* Open the pipe file descriptor. */
-	rc = pipe(pipefd);
-	if (rc == -1) {
-		perror("failed to open pipe");
-		return -errno;
-	}
-
-	/* Reset the total RMS value. */
-	total_rms_sqr_sum = 0;
-	total_rms_size = 0;
-
-	if (direction == CRAS_STREAM_INPUT)
-		aud_cb = got_samples;
-	else
-		aud_cb = put_samples;
-
-	if (fd == 0) {
-		if (direction != CRAS_STREAM_OUTPUT)
-			return -EINVAL;
-		aud_cb = put_stdin_samples;
-	}
-
-	aud_format = cras_audio_format_create(format, rate, num_channels);
-	if (aud_format == NULL)
-		return -ENOMEM;
-
-	if (channel_layout) {
-		/* Set channel layout to format */
-		parse_channel_layout(channel_layout, layout);
-		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,
-						   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)
-		cras_client_stream_params_enable_ns(params);
-	if (effect_agc)
-		cras_client_stream_params_enable_agc(params);
-	if (effect_vad)
-		cras_client_stream_params_enable_vad(params);
-
-	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);
-
-		cras_client_connected_wait(client);
-		pin_device_id = cras_client_get_first_dev_type_idx(
-			client, type, CRAS_STREAM_INPUT);
-	}
-
-	stream_playing =
-		start_stream(client, &stream_id, params, volume_scaler) == 0;
-
-	tty = open("/dev/tty", O_RDONLY);
-
-	// There could be no terminal available when run in autotest.
-	if (tty == -1)
-		perror("warning: failed to open /dev/tty");
-
-	while (keep_looping) {
-		char input;
-		int nread;
-
-		FD_ZERO(&poll_set);
-		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);
-
-		if (stream_playing && show_latency)
-			print_last_latency();
-
-		if (stream_playing && show_rms)
-			print_last_rms();
-
-		if (tty < 0 || !FD_ISSET(tty, &poll_set))
-			continue;
-
-		nread = read(tty, &input, 1);
-		if (nread < 1) {
-			fprintf(stderr, "Error reading stdin\n");
-			return nread;
-		}
-		switch (input) {
-		case 'p':
-			pause_client = !pause_client;
-			break;
-		case 'i':
-			pause_a_reply = 1;
-			break;
-		case 'q':
-			terminate_stream_loop();
-			break;
-		case 's':
-			if (stream_playing)
-				break;
-
-			/* 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;
-			break;
-		case 'r':
-			if (!stream_playing)
-				break;
-			cras_client_rm_stream(client, stream_id);
-			stream_playing = 0;
-			break;
-		case 'u':
-			volume_scaler = MIN(volume_scaler + 0.1, 1.0);
-			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,
-						      volume_scaler);
-			break;
-		case 'k':
-			sys_volume = MIN(sys_volume + 1, 100);
-			cras_client_set_system_volume(client, sys_volume);
-			break;
-		case 'j':
-			sys_volume = sys_volume == 0 ? 0 : sys_volume - 1;
-			cras_client_set_system_volume(client, sys_volume);
-			break;
-		case 'K':
-			cap_gain = MIN(cap_gain + 100, 5000);
-			cras_client_set_system_capture_gain(client, cap_gain);
-			break;
-		case 'J':
-			cap_gain = cap_gain == -5000 ? -5000 : cap_gain - 100;
-			cras_client_set_system_capture_gain(client, cap_gain);
-			break;
-		case 'm':
-			mute = !mute;
-			cras_client_set_system_mute(client, mute);
-			break;
-		case '@':
-			print_device_lists(client);
-			break;
-		case '#':
-			print_attached_client_list(client);
-			break;
-		case 'v':
-			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_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)" :
-				       "",
-			       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;
-			break;
-		case '\n':
-			break;
-		default:
-			printf("Invalid key\n");
-			break;
-		}
-	}
-
-	if (show_total_rms)
-		print_total_rms();
-
-	cras_client_stop(client);
-
-	cras_audio_format_destroy(aud_format);
-	cras_client_stream_params_destroy(params);
-	free(pfd);
-
-	close(pipefd[0]);
-	close(pipefd[1]);
-
-	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,
-		       int is_post_dsp)
-{
-	int fd = open(file, O_CREAT | O_RDWR | O_TRUNC, 0666);
-	if (fd == -1) {
-		perror("failed to open file");
-		return -errno;
-	}
-
-	run_file_io_stream(client, fd, CRAS_STREAM_INPUT, block_size,
-			   stream_type, rate, format, num_channels, flags,
-			   is_loopback, is_post_dsp);
-
-	close(fd);
-	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,
-			size_t num_channels)
-{
-	int fd;
-
-	fd = open(file, O_RDONLY);
-	if (fd == -1) {
-		perror("failed to open file");
-		return -errno;
-	}
-
-	run_file_io_stream(client, fd, CRAS_STREAM_OUTPUT, block_size,
-			   stream_type, rate, format, num_channels, 0, 0, 0);
-
-	close(fd);
-	return 0;
-}
-
-static void print_server_info(struct cras_client *client)
-{
-	cras_client_run_thread(client);
-	cras_client_connected_wait(client); /* To synchronize data. */
-	print_system_volumes(client);
-	print_user_muted(client);
-	print_device_lists(client);
-	print_attached_client_list(client);
-	print_active_stream_info(client);
-}
-
-static void show_audio_thread_snapshots(struct cras_client *client)
-{
-	struct timespec wait_time;
-
-	cras_client_run_thread(client);
-	cras_client_connected_wait(client); /* To synchronize data. */
-	cras_client_update_audio_thread_snapshots(client,
-						  audio_thread_snapshots);
-
-	clock_gettime(CLOCK_REALTIME, &wait_time);
-	wait_time.tv_sec += 2;
-
-	pthread_mutex_lock(&done_mutex);
-	pthread_cond_timedwait(&done_cond, &done_mutex, &wait_time);
-	pthread_mutex_unlock(&done_mutex);
-}
-
-static void show_audio_debug_info(struct cras_client *client)
-{
-	struct timespec wait_time;
-
-	cras_client_run_thread(client);
-	cras_client_connected_wait(client); /* To synchronize data. */
-	cras_client_update_audio_debug_info(client, audio_debug_info);
-
-	clock_gettime(CLOCK_REALTIME, &wait_time);
-	wait_time.tv_sec += 2;
-
-	pthread_mutex_lock(&done_mutex);
-	pthread_cond_timedwait(&done_cond, &done_mutex, &wait_time);
-	pthread_mutex_unlock(&done_mutex);
-}
-
-static void show_cras_bt_debug_info(struct cras_client *client)
-{
-	struct timespec wait_time;
-
-	cras_client_run_thread(client);
-	cras_client_connected_wait(client); /* To synchronize data. */
-	cras_client_update_bt_debug_info(client, cras_bt_debug_info);
-
-	clock_gettime(CLOCK_REALTIME, &wait_time);
-	wait_time.tv_sec += 2;
-
-	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,
-			      const char *hotword_models)
-{
-	printf("Hotword models: %s\n", hotword_models);
-}
-
-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);
-
-	clock_gettime(CLOCK_REALTIME, &wait_time);
-	wait_time.tv_sec += 2;
-
-	pthread_mutex_lock(&done_mutex);
-	pthread_cond_timedwait(&done_cond, &done_mutex, &wait_time);
-	pthread_mutex_unlock(&done_mutex);
-}
-
-static void check_output_plugged(struct cras_client *client, const char *name)
-{
-	cras_client_run_thread(client);
-	cras_client_connected_wait(client); /* To synchronize data. */
-	printf("%s\n",
-	       cras_client_output_dev_plugged(client, name) ? "Yes" : "No");
-}
-
-/* Repeatedly mute and unmute the output until there is an error. */
-static void mute_loop_test(struct cras_client *client, int auto_reconnect)
-{
-	int mute = 0;
-	int rc;
-
-	if (auto_reconnect)
-		cras_client_run_thread(client);
-	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)
-			return;
-		mute = !mute;
-		sleep(2);
-	}
-}
-
-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},
-	{"select_input",        required_argument,      0, 'a'},
-	{"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'},
-	{"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'},
-	{"dump_dsp",            no_argument,            0, 'l'},
-	{"dump_audio_thread",   no_argument,            0, 'm'},
-	{"syslog_mask",         required_argument,      0, 'n'},
-	{"channel_layout",      required_argument,      0, 'o'},
-	{"get_aec_group_id",    no_argument,            0, 'p'},
-	{"user_mute",           required_argument,      0, 'q'},
-	{"rate",                required_argument,      0, 'r'},
-	{"reload_dsp",          no_argument,            0, 's'},
-	{"add_active_output",   required_argument,      0, 't'},
-	{"mute",                required_argument,      0, 'u'},
-	{"volume",              required_argument,      0, 'v'},
-	{"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'},
-	{"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'},
-	{"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("--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.\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");
-}
-
-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)
-{
-	struct cras_client *client;
-	int c, option_index;
-	size_t block_size = NOT_ASSIGNED;
-	size_t rate = 48000;
-	size_t num_channels = 2;
-	float duration_seconds = 0;
-	const char *capture_file = NULL;
-	const char *playback_file = NULL;
-	const char *loopback_file = NULL;
-	int post_dsp = 0;
-	enum CRAS_STREAM_TYPE stream_type = CRAS_STREAM_TYPE_DEFAULT;
-	int rc = 0;
-	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_and_connect(&client, conn_type);
-	if (rc) {
-		return rc;
-	}
-
-	if (argc == 1) {
-		/* Nothing specified, default to dump_server_info. */
-		print_server_info(client);
-		goto destroy_exit;
-	}
-
-	while (1) {
-		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': {
-			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;
-			cras_client_select_node(client, direction, id);
-			break;
-		}
-		case 'b':
-			block_size = atoi(optarg);
-			break;
-		case 'c':
-			num_channels = atoi(optarg);
-			break;
-		case 'd':
-			duration_seconds = atof(optarg);
-			break;
-		case 'e':
-			show_audio_thread_snapshots(client);
-			break;
-		case 'f': {
-			int i;
-
-			for (i = 0; supported_formats[i].name; ++i) {
-				if (strcasecmp(optarg,
-					       supported_formats[i].name) ==
-				    0) {
-					format = supported_formats[i].format;
-					break;
-				}
-			}
-
-			if (!supported_formats[i].name) {
-				printf("Unsupported format: %s\n", optarg);
-				return -EINVAL;
-			}
-			break;
-		}
-		case 'g': {
-			long gain = atol(optarg);
-			rc = cras_client_set_system_capture_gain(client, gain);
-			if (rc < 0) {
-				fprintf(stderr, "problem setting capture\n");
-				goto destroy_exit;
-			}
-			break;
-		}
-		case 'h':
-			show_usage();
-			break;
-		case 'i':
-			print_server_info(client);
-			break;
-		case 'j':
-			check_output_plugged(client, optarg);
-			break;
-		case 'k':
-		case 't':
-		case '1':
-		case '2': {
-			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
-				dir = CRAS_STREAM_INPUT;
-
-			if (c == 'k' || c == 't')
-				cras_client_add_active_node(client, dir, id);
-			else
-				cras_client_rm_active_node(client, dir, id);
-			break;
-		}
-		case 'l':
-			cras_client_dump_dsp_info(client);
-			break;
-		case 'm':
-			show_audio_debug_info(client);
-			break;
-		case 'n': {
-			int log_level = atoi(optarg);
-
-			setlogmask(LOG_UPTO(log_level));
-			break;
-		}
-		case 'o':
-			channel_layout = optarg;
-			break;
-		case 'p':
-			printf("AEC group ID %d\n",
-			       cras_client_get_aec_group_id(client));
-			break;
-		case 'q': {
-			int mute = atoi(optarg);
-			rc = cras_client_set_user_mute(client, mute);
-			if (rc < 0) {
-				fprintf(stderr, "problem setting mute\n");
-				goto destroy_exit;
-			}
-			break;
-		}
-		case 'r':
-			rate = atoi(optarg);
-			break;
-		case 's':
-			cras_client_reload_dsp(client);
-			break;
-		case 'u': {
-			int mute = atoi(optarg);
-			rc = cras_client_set_system_mute(client, mute);
-			if (rc < 0) {
-				fprintf(stderr, "problem setting mute\n");
-				goto destroy_exit;
-			}
-			break;
-		}
-		case 'v': {
-			int volume = atoi(optarg);
-			volume = MIN(100, MAX(0, volume));
-			rc = cras_client_set_system_volume(client, volume);
-			if (rc < 0) {
-				fprintf(stderr, "problem setting volume\n");
-				goto destroy_exit;
-			}
-			break;
-		}
-		case ':':
-		case 'w': {
-			cras_node_id_t id;
-			int value;
-			rc = parse_node_id_with_value(optarg, &id, &value);
-			if (rc) {
-				show_usage();
-				return rc;
-			}
-
-			if (c == 'w')
-				cras_client_set_node_volume(client, id, value);
-			else
-				cras_client_set_node_capture_gain(client, id,
-								  value);
-			break;
-		}
-		case 'x': {
-			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;
-		}
-		case 'z':
-			pause_in_playback_reply = atoi(optarg);
-			break;
-
-		case '0': {
-			int mute = atoi(optarg);
-			rc = cras_client_set_system_capture_mute(client, mute);
-			if (rc < 0) {
-				fprintf(stderr, "problem setting mute\n");
-				goto destroy_exit;
-			}
-			break;
-		}
-		case '3': {
-			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;
-		}
-		case '4':
-			printf("%s\n", VCSID);
-			break;
-		case '5': {
-			cras_client_add_test_iodev(client, atoi(optarg));
-			break;
-		}
-		case '6': {
-			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, ":");
-			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': {
-			stream_flags = HOTWORD_STREAM;
-			capture_file = optarg;
-			break;
-		}
-		case '8':
-			pin_device_id = atoi(optarg);
-			break;
-		case '9': {
-			int suspend = atoi(optarg);
-			cras_client_set_suspend(client, suspend);
-			break;
-		}
-
-		case '!': {
-			play_short_sound = 1;
-			play_short_sound_periods = atoi(optarg);
-			break;
-		}
-		case ';': {
-			char *s;
-			int nch;
-			int size = 0;
-			float *coeff;
-
-			s = strtok(optarg, ":");
-			nch = atoi(s);
-			coeff = (float *)calloc(nch * nch, sizeof(*coeff));
-			for (size = 0; size < nch * nch; size++) {
-				s = strtok(NULL, ",");
-				if (NULL == s)
-					break;
-				coeff[size] = atof(s);
-			}
-			cras_client_config_global_remix(client, nch, coeff);
-			free(coeff);
-			break;
-		}
-		case '<':
-		case '>': {
-			char *s;
-			int dev_index;
-			int node_index;
-
-			s = strtok(optarg, ":");
-			if (!s) {
-				show_usage();
-				return -EINVAL;
-			}
-			dev_index = atoi(s);
-
-			s = strtok(NULL, ":");
-			if (!s) {
-				show_usage();
-				return -EINVAL;
-			}
-			node_index = atoi(s);
-
-			s = strtok(NULL, ":");
-			if (!s && c == ';') {
-				//TODO: c never == ';'
-				show_usage();
-				return -EINVAL;
-			}
-
-			cras_node_id_t id =
-				cras_make_node_id(dev_index, node_index);
-			if (c == '<')
-				cras_client_set_hotword_model(client, id, s);
-			else
-				print_hotword_models(client, id);
-			break;
-		}
-
-		case 'A':
-			post_dsp = atoi(optarg);
-			break;
-		case 'B':
-			stream_id = atoi(optarg);
-			break;
-		case 'C':
-			capture_file = optarg;
-			break;
-		case 'D':
-			cras_client_reload_aec_config(client);
-			break;
-		case 'E': {
-			char *s;
-
-			s = strtok(optarg, ",");
-			while (s) {
-				if (strcmp("aec", s) == 0)
-					effect_aec = 1;
-				else if (strcmp("ns", s) == 0)
-					effect_ns = 1;
-				else if (strcmp("agc", s) == 0)
-					effect_agc = 1;
-				else if (strcmp("vad", s) == 0)
-					effect_vad = 1;
-				else
-					printf("Unknown effect %s\n", s);
-				s = strtok(NULL, ",");
-			}
-			break;
-		}
-		case 'F':
-			printf("AEC supported %d\n",
-			       !!cras_client_get_aec_supported(client));
-			break;
-		case 'G':
-			aecdump_file = optarg;
-			break;
-		case 'H':
-			show_cras_bt_debug_info(client);
-			break;
-		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;
-		case 'M':
-			mute_loop_test(client, atoi(optarg));
-			break;
-		case 'P':
-			playback_file = optarg;
-			break;
-		case 'T':
-			stream_type = atoi(optarg);
-			break;
-
-		default:
-			break;
-		}
-	}
-
-	duration_frames = duration_seconds * rate;
-	if (block_size == NOT_ASSIGNED)
-		block_size = get_block_size(PLAYBACK_BUFFERED_TIME_IN_US, rate);
-
-	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);
-		else
-			rc = run_capture(client, capture_file, block_size,
-					 stream_type, rate, format,
-					 num_channels, stream_flags, 0, 0);
-	} 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);
-		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);
-	} else if (aecdump_file != NULL) {
-		run_aecdump(client, stream_id, 1);
-		sleep(duration_seconds);
-		run_aecdump(client, stream_id, 0);
-	}
-
-destroy_exit:
-	cras_client_destroy(client);
-	return rc;
-}
diff --git a/init/cras.sh b/init/cras.sh
index a1a21db..cebf3a9 100644
--- a/init/cras.sh
+++ b/init/cras.sh
@@ -3,7 +3,7 @@
 # found in the LICENSE file.
 
 # Unified build config.
-device_config_dir="$(cros_config /audio/main cras-config-dir)"
+device_config_dir="$(cros_config --abspath /audio/main cras-config-dir)"
 internal_ucm_suffix="$(cros_config /audio/main ucm-suffix)"
 
 # Handle legacy config.
@@ -23,8 +23,6 @@
   if [ -f /etc/cras/get_internal_ucm_suffix ]; then
     internal_ucm_suffix="$(sh /etc/cras/get_internal_ucm_suffix)"
   fi
-else
-  device_config_dir="/etc/cras/${device_config_dir}"
 fi
 
 if [ -n "${device_config_dir}" ]; then
@@ -36,14 +34,12 @@
 fi
 
 # Leave cras in the init pid namespace as it uses its PID as an IPC identifier.
-exec minijail0 -u cras -g cras -G --uts -v -l \
-        -T static \
-        -P /mnt/empty \
+exec minijail0 -u cras -g cras -G -n --uts -v -l \
+        -P /var/empty \
         -b /,/ \
         -k 'tmpfs,/run,tmpfs,MS_NODEV|MS_NOEXEC|MS_NOSUID,mode=755,size=10M' \
         -b /run/cras,/run/cras,1 \
         -b /run/dbus,/run/dbus,1 \
-        -b /run/systemd/journal \
         -b /run/udev,/run/udev \
         -b /dev,/dev \
         -b /dev/shm,/dev/shm,1 \
@@ -51,9 +47,7 @@
         -b /sys,/sys \
         -k 'tmpfs,/var,tmpfs,MS_NODEV|MS_NOEXEC|MS_NOSUID,mode=755,size=10M' \
         -b /var/lib/metrics/,/var/lib/metrics/,1 \
-        -- \
-        /sbin/minijail0 -n \
-        -S /usr/share/policy/cras-seccomp.policy \
+	-S /usr/share/policy/cras-seccomp.policy \
         -- \
         /usr/bin/cras \
         ${DSP_CONFIG} ${DEVICE_CONFIG_DIR} ${DISABLE_PROFILE} \
diff --git a/scripts/asoc_dapm_graph b/scripts/asoc_dapm_graph
deleted file mode 100755
index f02c60c..0000000
--- a/scripts/asoc_dapm_graph
+++ /dev/null
@@ -1,95 +0,0 @@
-#!/usr/bin/env python
-# Copyright 2014 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.
-
-"""Dump DAPM widgets status as a 'dot' graph file.
-
-To generate widget status for a device run
-  ssh $REMOTE asoc_dapm_graph > dot.txt && dot -Kfdp -Tpng dot.txt -o widgets.png
-"""
-
-from __future__ import print_function
-import os
-import platform
-import re
-import sys
-import time
-
-ROOTDIR = '/sys/kernel/debug/asoc/'
-# Some widget names are widely used by many codecs, adding them to the graph
-# creates a mess.
-IGNORE_WIDGETS = ('Playback', 'Capture', 'bias_level')
-
-
-def handle_widgets(path):
-  """Reads DAPM widget information from sysfs and generates dot graph entry.
-
-  Args:
-    path: path for sysfs file that exports information about DAPM widget.
-  """
-  for w in os.listdir(path):
-    if w in IGNORE_WIDGETS:
-      continue
-
-    with open(os.path.join(path, w)) as f:
-      lines = f.readlines()
-
-    active = lines[0].startswith(w + ': On ')
-    color = 'green' if active else 'red'
-    print('\t"%s" [color = %s]' % (w, color))
-
-    for l in lines[1:]:
-      l = l.rstrip()
-      # The string format is (in/out) "switch" "widget".
-      edge = filter(None, re.split(r' (in|out)  "(.+)" "(.+)"', l))
-
-      if len(edge) != 3:
-        continue
-
-      direction = edge[0]
-      source = edge[2]
-
-      if source in IGNORE_WIDGETS:
-        continue
-
-      # We need to output the edge only once (e.g. inbound).
-      if direction != 'in':
-        continue
-
-      print('\t"%s" -> "%s"' % (source, w))
-
-
-def handle_card(path):
-  """Generates dot graph file for the given card.
-
-  Args:
-    path: path to sysfs directory that exports DAPM information for a sound card.
-  """
-  host = platform.uname()[1]
-  print('// Generated %s at %s.' % (time.strftime("%c"), host))
-  print('// To visualize the graph run "dot -Kfdp -Tpng $SCRIPT_OUTPUT_FILE -o widgets.png".')
-  print('digraph G {')
-  print('\tbgcolor = grey')
-  for root, dirs, files in os.walk(path):
-    if 'dapm' in dirs:
-      handle_widgets(os.path.join(root, 'dapm'))
-      dirs.remove('dapm')
-  print('}')
-
-
-def main(argv):
-  for c in os.listdir(ROOTDIR):
-    path = os.path.join(ROOTDIR, c)
-    # We assume that directories in ROOTDIR are cards.
-    if os.path.isdir(path):
-      handle_card(path)
-      sys.exit(0)
-
-  print('No cards found', file=sys.stderr)
-  sys.exit(1)
-
-
-if __name__ == '__main__':
-  main(sys.argv[1:])
-
diff --git a/scripts/audio_diagnostics b/scripts/audio_diagnostics
index c3fe4f8..83a380c 100755
--- a/scripts/audio_diagnostics
+++ b/scripts/audio_diagnostics
@@ -22,9 +22,6 @@
 echo '=== cras_test_client --dump_audio_thread ==='
 cras_test_client --dump_audio_thread
 
-echo '=== cras_test_client --dump_bt ==='
-cras_test_client --dump_bt
-
 echo '=== cras_test_client --dump_events ==='
 cras_test_client --dump_events
 
diff --git a/scripts/audio_thread_log_viewer/README.md b/scripts/audio_thread_log_viewer/README.md
deleted file mode 100644
index 7b2612d..0000000
--- a/scripts/audio_thread_log_viewer/README.md
+++ /dev/null
@@ -1,45 +0,0 @@
-# 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
deleted file mode 100644
index 2fd7c9c..0000000
--- a/scripts/audio_thread_log_viewer/example.html
+++ /dev/null
@@ -1,783 +0,0 @@
-
-<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 f8d4f57..2f23dd5 100755
--- a/scripts/audio_thread_log_viewer/viewer_c3.py
+++ b/scripts/audio_thread_log_viewer/viewer_c3.py
@@ -11,7 +11,6 @@
 import collections
 import logging
 import string
-import time
 
 page_content = string.Template("""
 <html meta charset="UTF8">
@@ -54,30 +53,17 @@
     }
   </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',
-          },
-          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;
+              buffer_level: 'line',
           },
         },
         zoom: {
@@ -151,22 +137,7 @@
 """)
 
 
-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'])
+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
@@ -440,9 +411,9 @@
         """Parses one line of event log.
 
         Split a line like
-        2019-07-02T15:30:46.683829810 cras atlog  WRITE_STREAMS_FETCH_STREAM     id:1e0000 cbth:512 delay:1136
+        169536.504763588  WRITE_STREAMS_FETCH_STREAM     id:0 cbth:512 delay:1136
         into time, name, and props where
-        time = '54946.683829810'
+        time = '169536.504763588'
         name = 'WRITE_STREAMS_FETCH_STREAM'
         props = {
             'id': 0,
@@ -456,11 +427,11 @@
 
         """
         line_split = line.split()
-        time, name = StrToTimestamp(line_split[0]), line_split[3]
+        time, name = line_split[0], line_split[1]
         logging.debug('time: %s, name: %s', time, name)
         props = {}
-        for index in xrange(4, len(line_split)):
-            key, value = line_split[index].split(':')[:2]
+        for index in xrange(2, len(line_split)):
+            key, value = line_split[index].split(':')
             props[key] = value
         logging.debug('props: %s', props)
         return self._CreateEventData(time, name, props)
@@ -538,15 +509,7 @@
         @returns: A string for filled page.
 
         """
-        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)
-
+        logs = '\n<br>'.join(self.content)
         return page_template.substitute(logs=logs)
 
 
diff --git a/seccomp/cras-seccomp-amd64.policy b/seccomp/cras-seccomp-amd64.policy
index 06dc224..41b5d2a 100644
--- a/seccomp/cras-seccomp-amd64.policy
+++ b/seccomp/cras-seccomp-amd64.policy
@@ -82,7 +82,3 @@
 # HCIGETDEVINFO
 ioctl: arg1 in 0xffff41ff && arg1 & 0x00004100 || arg1 in 0xffff55ff && arg1 & 0x00005500 || arg1 == 0x8008451b || arg1 == 0x81004506 || arg1 == 0x80084525 || arg1 == 0x800448d3
 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 f917036..74676a0 100644
--- a/seccomp/cras-seccomp-arm.policy
+++ b/seccomp/cras-seccomp-arm.policy
@@ -88,7 +88,3 @@
 # HCIGETDEVINFO
 ioctl: arg1 in 0xffff41ff && arg1 & 0x00004100 || arg1 in 0xffff55ff && arg1 & 0x00005500 || arg1 == 0x8008451b || arg1 == 0x81004506 || arg1 == 0x80084525 || arg1 == 0x800448d3
 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 64f3244..569c10c 100644
--- a/seccomp/cras-seccomp-arm64.policy
+++ b/seccomp/cras-seccomp-arm64.policy
@@ -80,7 +80,3 @@
 uname: 1
 unlinkat: 1
 getpid: 1
-prlimit64: 1
-tgkill: 1
-mremap: 1
-dup: 1
diff --git a/ubsan_blocklist.txt b/ubsan_blocklist.txt
deleted file mode 100644
index 983b1a8..0000000
--- a/ubsan_blocklist.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-# Suppress float devide-by-zero error in dsp.
-# https://crbug.com/965725
-[float-divide-by-zero]
-src:cras/src/dsp/drc_kernel.c
-fun:dk_update_envelope
diff --git a/ucm-config/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf b/ucm-config/auron/HDA Intel PCH/HDA Intel PCH.conf
similarity index 67%
copy from ucm-config/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf
copy to ucm-config/auron/HDA Intel PCH/HDA Intel PCH.conf
index e7394ba..aa3c8dd 100644
--- a/ucm-config/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf
+++ b/ucm-config/auron/HDA Intel PCH/HDA Intel PCH.conf
@@ -1,4 +1,4 @@
-Comment "HD Pro Webcam C920"
+Comment "Auron internal card"
 
 SectionUseCase."HiFi" {
 	File "HiFi.conf"
diff --git a/ucm-config/auron/HDA Intel PCH/HiFi.conf b/ucm-config/auron/HDA Intel PCH/HiFi.conf
new file mode 100644
index 0000000..de154ca
--- /dev/null
+++ b/ucm-config/auron/HDA Intel PCH/HiFi.conf
@@ -0,0 +1,55 @@
+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"
+		OutputDspName ""
+	}
+	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/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf b/ucm-config/auron_paine/HDA Intel PCH/HDA Intel PCH.conf
similarity index 67%
copy from ucm-config/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf
copy to ucm-config/auron_paine/HDA Intel PCH/HDA Intel PCH.conf
index e7394ba..7a62b05 100644
--- a/ucm-config/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf
+++ b/ucm-config/auron_paine/HDA Intel PCH/HDA Intel PCH.conf
@@ -1,4 +1,4 @@
-Comment "HD Pro Webcam C920"
+Comment "Paine internal card"
 
 SectionUseCase."HiFi" {
 	File "HiFi.conf"
diff --git a/ucm-config/auron_paine/HDA Intel PCH/HiFi.conf b/ucm-config/auron_paine/HDA Intel PCH/HiFi.conf
new file mode 100644
index 0000000..73df073
--- /dev/null
+++ b/ucm-config/auron_paine/HDA Intel PCH/HiFi.conf
@@ -0,0 +1,55 @@
+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='Input Source' 1"
+	]
+	DisableSequence [
+	]
+}
+
+SectionDevice."Headphone".0 {
+	Value {
+		JackName "Headphone Jack"
+		OutputDspName ""
+	}
+	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='Input Source' 0"
+	]
+	DisableSequence [
+		cdev "hw:PCH"
+
+		cset "name='Input Source' 1"
+	]
+}
diff --git a/ucm-config/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf b/ucm-config/auron_yuna/HDA Intel PCH/HDA Intel PCH.conf
similarity index 68%
copy from ucm-config/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf
copy to ucm-config/auron_yuna/HDA Intel PCH/HDA Intel PCH.conf
index e7394ba..5133a98 100644
--- a/ucm-config/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf
+++ b/ucm-config/auron_yuna/HDA Intel PCH/HDA Intel PCH.conf
@@ -1,4 +1,4 @@
-Comment "HD Pro Webcam C920"
+Comment "Yuna internal card"
 
 SectionUseCase."HiFi" {
 	File "HiFi.conf"
diff --git a/ucm-config/auron_yuna/HDA Intel PCH/HiFi.conf b/ucm-config/auron_yuna/HDA Intel PCH/HiFi.conf
new file mode 100644
index 0000000..de154ca
--- /dev/null
+++ b/ucm-config/auron_yuna/HDA Intel PCH/HiFi.conf
@@ -0,0 +1,55 @@
+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"
+		OutputDspName ""
+	}
+	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/chell-cheets b/ucm-config/chell-cheets
new file mode 120000
index 0000000..1ec1f47
--- /dev/null
+++ b/ucm-config/chell-cheets
@@ -0,0 +1 @@
+glados/
\ No newline at end of file
diff --git a/ucm-config/cid/HDA Intel PCH/HiFi.conf b/ucm-config/cid/HDA Intel PCH/HiFi.conf
index 6174c0b..de154ca 100644
--- a/ucm-config/cid/HDA Intel PCH/HiFi.conf
+++ b/ucm-config/cid/HDA Intel PCH/HiFi.conf
@@ -22,7 +22,7 @@
 SectionDevice."Headphone".0 {
 	Value {
 		JackName "Headphone Jack"
-		DspName ""
+		OutputDspName ""
 	}
 	EnableSequence [
 		cdev "hw:PCH"
diff --git a/ucm-config/cyan-cheets b/ucm-config/cyan-cheets
new file mode 120000
index 0000000..d8fcd90
--- /dev/null
+++ b/ucm-config/cyan-cheets
@@ -0,0 +1 @@
+cyan
\ No newline at end of file
diff --git a/ucm-config/cyan/chtmax98090/HiFi.conf b/ucm-config/cyan/chtmax98090/HiFi.conf
new file mode 100644
index 0000000..4cf5204
--- /dev/null
+++ b/ucm-config/cyan/chtmax98090/HiFi.conf
@@ -0,0 +1,135 @@
+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"
+		OutputDspName ""
+	}
+
+	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/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf b/ucm-config/cyan/chtmax98090/chtmax98090.conf
similarity index 68%
copy from ucm-config/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf
copy to ucm-config/cyan/chtmax98090/chtmax98090.conf
index e7394ba..2263279 100644
--- a/ucm-config/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf
+++ b/ucm-config/cyan/chtmax98090/chtmax98090.conf
@@ -1,4 +1,4 @@
-Comment "HD Pro Webcam C920"
+Comment "Cyan internal card"
 
 SectionUseCase."HiFi" {
 	File "HiFi.conf"
diff --git a/ucm-config/cyan/sof-chtmax98090/HiFi.conf b/ucm-config/cyan/sof-chtmax98090/HiFi.conf
new file mode 100644
index 0000000..8b7aacd
--- /dev/null
+++ b/ucm-config/cyan/sof-chtmax98090/HiFi.conf
@@ -0,0 +1,185 @@
+# 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/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf b/ucm-config/cyan/sof-chtmax98090/sof-chtmax98090.conf
similarity index 61%
copy from ucm-config/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf
copy to ucm-config/cyan/sof-chtmax98090/sof-chtmax98090.conf
index e7394ba..6f73533 100644
--- a/ucm-config/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf
+++ b/ucm-config/cyan/sof-chtmax98090/sof-chtmax98090.conf
@@ -1,4 +1,4 @@
-Comment "HD Pro Webcam C920"
+Comment "sof-chtmax98090 internal card"
 
 SectionUseCase."HiFi" {
 	File "HiFi.conf"
diff --git a/ucm-config/daisy/DAISY-I2S-98090/HiFi.conf b/ucm-config/daisy/DAISY-I2S-98090/HiFi.conf
index 54e92b3..bddfce6 100644
--- a/ucm-config/daisy/DAISY-I2S-98090/HiFi.conf
+++ b/ucm-config/daisy/DAISY-I2S-98090/HiFi.conf
@@ -41,7 +41,7 @@
 SectionDevice."HDMI".0 {
 	Value {
 		JackName "DAISY-I2S-98090 HDMI Jack"
-		DspName ""
+		OutputDspName ""
 		EDIDFile "/sys/devices/platform/exynos-drm/drm/card1/card1-HDMI-A-1/edid"
 	}
 	EnableSequence [
@@ -59,7 +59,7 @@
 SectionDevice."Headphone".0 {
 	Value {
 		JackName "DAISY-I2S-98090 Headphone Jack"
-		DspName ""
+		OutputDspName ""
 	}
 
 	EnableSequence [
diff --git a/ucm-config/daisy_skate/DAISY-I2S/HiFi.conf b/ucm-config/daisy_skate/DAISY-I2S/HiFi.conf
index d2a913b..ce1e45d 100644
--- a/ucm-config/daisy_skate/DAISY-I2S/HiFi.conf
+++ b/ucm-config/daisy_skate/DAISY-I2S/HiFi.conf
@@ -22,7 +22,7 @@
 SectionDevice."HDMI".0 {
 	Value {
 		JackName "DAISY-I2S HDMI Jack"
-		DspName ""
+		OutputDspName ""
 		EDIDFile "/sys/devices/platform/exynos-drm/drm/card1/card1-HDMI-A-1/edid"
 	}
 }
@@ -30,7 +30,7 @@
 SectionDevice."Headphone".0 {
 	Value {
 		JackName "DAISY-I2S Headphone Jack"
-		DspName ""
+		OutputDspName ""
 	}
 
 	EnableSequence [
diff --git a/ucm-config/daisy_spring/DAISY-I2S/HiFi.conf b/ucm-config/daisy_spring/DAISY-I2S/HiFi.conf
index af49a05..f6a1d31 100644
--- a/ucm-config/daisy_spring/DAISY-I2S/HiFi.conf
+++ b/ucm-config/daisy_spring/DAISY-I2S/HiFi.conf
@@ -47,7 +47,7 @@
 SectionDevice."HDMI".0 {
 	Value {
 		JackName "DAISY-I2S HDMI Jack"
-		DspName ""
+		OutputDspName ""
 		EDIDFile "/sys/devices/platform/exynos-drm/drm/card1/card1-HDMI-A-1/edid"
 	}
 }
@@ -55,7 +55,7 @@
 SectionDevice."Headphone".0 {
 	Value {
 		JackName "DAISY-I2S Headphone Jack"
-		DspName ""
+		OutputDspName ""
 	}
 
 	EnableSequence [
diff --git a/ucm-config/falco/HDA Intel PCH/HiFi.conf b/ucm-config/falco/HDA Intel PCH/HiFi.conf
index 03f431e..f477543 100644
--- a/ucm-config/falco/HDA Intel PCH/HiFi.conf
+++ b/ucm-config/falco/HDA Intel PCH/HiFi.conf
@@ -22,7 +22,7 @@
 SectionDevice."Headphone".0 {
 	Value {
 		JackName "Headphone Jack"
-		DspName ""
+		OutputDspName ""
 	}
 	EnableSequence [
 		cdev "hw:PCH"
diff --git a/ucm-config/for_all_boards/HD Pro Webcam C920/HiFi.conf b/ucm-config/for_all_boards/HD Pro Webcam C920/HiFi.conf
deleted file mode 100644
index e7d3723..0000000
--- a/ucm-config/for_all_boards/HD Pro Webcam C920/HiFi.conf
+++ /dev/null
@@ -1,28 +0,0 @@
-SectionVerb {
-	Value {
-		FullySpecifiedUCM "1"
-	}
-
-	EnableSequence [
-		cdev "hw:C920"
-
-		cset "name='Mic Capture Volume' 5"
-	]
-
-	DisableSequence [
-	]
-}
-
-SectionDevice."Mic" {
-	Value {
-		CapturePCM "hw:HD Pro Webcam C920,0"
-		MaxSoftwareGain "2000"
-		JackType "always"
-	}
-
-	EnableSequence [
-	]
-
-	DisableSequence [
-	]
-}
diff --git a/ucm-config/for_all_boards/Plankton Captured HDMI Audio/HiFi.conf b/ucm-config/for_all_boards/Plankton Captured HDMI Audio/HiFi.conf
index 1a1f4a2..13db891 100644
--- a/ucm-config/for_all_boards/Plankton Captured HDMI Audio/HiFi.conf
+++ b/ucm-config/for_all_boards/Plankton Captured HDMI Audio/HiFi.conf
@@ -13,7 +13,6 @@
 SectionDevice."Plankton Captured HDMI Audio".0 {
         Value {
                 CapturePCM "hw:Plankton Captured HDMI Audio,0"
-		JackType "always"
         }
 
         EnableSequence [
diff --git a/ucm-config/for_all_boards/README b/ucm-config/for_all_boards/README
deleted file mode 100644
index b538435..0000000
--- a/ucm-config/for_all_boards/README
+++ /dev/null
@@ -1,8 +0,0 @@
-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/for_all_boards/WD15 Dock b/ucm-config/for_all_boards/WD15 Dock
deleted file mode 120000
index 0d69a72..0000000
--- a/ucm-config/for_all_boards/WD15 Dock
+++ /dev/null
@@ -1 +0,0 @@
-Dell-WD15-Dock
\ No newline at end of file
diff --git a/ucm-config/for_all_boards/WD19 Dock b/ucm-config/for_all_boards/WD19 Dock
deleted file mode 120000
index 0d69a72..0000000
--- a/ucm-config/for_all_boards/WD19 Dock
+++ /dev/null
@@ -1 +0,0 @@
-Dell-WD15-Dock
\ No newline at end of file
diff --git a/ucm-config/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf b/ucm-config/gandof/HDA Intel PCH/HDA Intel PCH.conf
similarity index 66%
copy from ucm-config/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf
copy to ucm-config/gandof/HDA Intel PCH/HDA Intel PCH.conf
index e7394ba..b38ce17 100644
--- a/ucm-config/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf
+++ b/ucm-config/gandof/HDA Intel PCH/HDA Intel PCH.conf
@@ -1,4 +1,4 @@
-Comment "HD Pro Webcam C920"
+Comment "Gandof internal card"
 
 SectionUseCase."HiFi" {
 	File "HiFi.conf"
diff --git a/ucm-config/gandof/HDA Intel PCH/HiFi.conf b/ucm-config/gandof/HDA Intel PCH/HiFi.conf
new file mode 100644
index 0000000..de154ca
--- /dev/null
+++ b/ucm-config/gandof/HDA Intel PCH/HiFi.conf
@@ -0,0 +1,55 @@
+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"
+		OutputDspName ""
+	}
+	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 c10104d..6a53caf 100644
--- a/ucm-config/glados/sklnau8825adi/HiFi.conf
+++ b/ucm-config/glados/sklnau8825adi/HiFi.conf
@@ -12,7 +12,7 @@
 		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' 0"
+		cset "name='codec0_iv_in Switch' 1"
 		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"
@@ -53,7 +53,7 @@
 SectionDevice."HDMI1".0 {
 	Value {
 		JackName "HDMI/DP, pcm=4 Jack"
-		DspName ""
+		OutputDspName ""
 	}
 
 	EnableSequence [
@@ -66,7 +66,7 @@
 SectionDevice."HDMI2".0 {
 	Value {
 		JackName "HDMI/DP, pcm=5 Jack"
-		DspName ""
+		OutputDspName ""
 	}
 
 	EnableSequence [
@@ -79,11 +79,12 @@
 SectionDevice."Headphone".0 {
 	Value {
 		JackName "sklnau8825adi Headset Jack"
-		DspName ""
+		OutputDspName ""
 	}
 
 	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"
@@ -94,6 +95,7 @@
 		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/veyron_fievel/VEYRON-I2S/HiFi.conf b/ucm-config/glimmer-cheets/byt-max98090/HiFi.conf
similarity index 65%
rename from ucm-config/veyron_fievel/VEYRON-I2S/HiFi.conf
rename to ucm-config/glimmer-cheets/byt-max98090/HiFi.conf
index f23f3bc..8f6d77d 100644
--- a/ucm-config/veyron_fievel/VEYRON-I2S/HiFi.conf
+++ b/ucm-config/glimmer-cheets/byt-max98090/HiFi.conf
@@ -1,13 +1,13 @@
 SectionVerb {
 	Value {
 		OutputDspName "speaker_eq"
-		MinBufferLevel "512"
-		FullySpecifiedUCM "1"
 	}
 
 	EnableSequence [
-		cdev "hw:VEYRONI2S"
+		cdev "hw:bytmax98090"
 
+		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"
 		cset "name='Digital EQ 3 Band Switch' off"
@@ -22,7 +22,6 @@
 		cset "name='Right ADC Mixer MIC2 Switch' on"
 		cset "name='Left ADC Mixer MIC2 Switch' on"
 		cset "name='MIC2 Volume' 20"
-		cset "name='Headset Mic Switch' off"
 		cset "name='Int Mic Switch' on"
 
 		cset "name='ADCR Boost Volume' 4"
@@ -37,15 +36,15 @@
 		cset "name='Record Path DC Blocking' on"
 		cset "name='Playback Path DC Blocking' on"
 
-		cset "name='Speaker Left Switch' off"
-		cset "name='Speaker Right Switch' off"
-		cset "name='Speaker Switch' off"
-
+		cset "name='Headphone Left Switch' on"
+		cset "name='Headphone Right 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"
+
+		cset "name='Speaker Left Switch' on"
+		cset "name='Speaker Right Switch' on"
+		cset "name='Ext Spk Switch' on"
 	]
 
 	DisableSequence [
@@ -54,67 +53,69 @@
 
 SectionDevice."Headphone".0 {
 	Value {
-		PlaybackPCM "hw:VEYRONI2S,0"
-		MixerName "Headphone"
-		JackType "gpio"
-		JackName "VEYRON-I2S Headset Jack"
+		JackName "byt-max98090 Headphone Jack"
 		OutputDspName ""
 	}
 
 	EnableSequence [
-		cdev "hw:VEYRONI2S"
-
+		cdev "hw:bytmax98090"
+		cset "name='Speaker Left Switch' off"
+		cset "name='Speaker Right Switch' off"
+		cset "name='Headphone Switch' on"
 		cset "name='HP Left Out Switch' on"
 		cset "name='HP Right Out Switch' on"
-		cset "name='Headphone Switch' on"
 	]
 	DisableSequence [
-		cdev "hw:VEYRONI2S"
-
-		cset "name='Headphone Switch' off"
+		cdev "hw:bytmax98090"
 		cset "name='HP Left Out Switch' off"
 		cset "name='HP Right Out Switch' off"
+		cset "name='Headphone Switch' off"
+		cset "name='Speaker Left Switch' on"
+		cset "name='Speaker Right Switch' on"
 	]
 }
 
 SectionDevice."Mic".0 {
 	Value {
-		CapturePCM "hw:VEYRONI2S,0"
-		MixerName "Headset Mic"
-		JackType "gpio"
-		JackName "VEYRON-I2S Headset Jack"
+		JackName "byt-max98090 Mic Jack"
+		CaptureControl "MIC2"
 	}
 
 	EnableSequence [
-		cdev "hw:VEYRONI2S"
-
+		cdev "hw:bytmax98090"
 		cset "name='Int Mic Switch' off"
-		cset "name='DMIC Mux' ADC"
 		cset "name='Headset Mic Switch' on"
+		cset "name='DMIC Mux' ADC"
 		cset "name='Record Path DC Blocking' on"
 	]
 
 	DisableSequence [
-		cdev "hw:VEYRONI2S"
-
+		cdev "hw:bytmax98090"
 		cset "name='Headset Mic Switch' off"
-		cset "name='DMIC Mux' DMIC"
 		cset "name='Int Mic Switch' on"
+		cset "name='DMIC Mux' DMIC"
 		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"
-	}
+SectionModifier."Speaker Swap Mode".0 {
+	Comment "Swap the left and right channels of speaker."
+
 	EnableSequence [
-		cdev "hw:VEYRONI2S"
+		cdev "hw:bytmax98090"
+
+		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:VEYRONI2S"
+		cdev "hw:bytmax98090"
+
+		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/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf b/ucm-config/glimmer-cheets/byt-max98090/byt-max98090.conf
similarity index 66%
copy from ucm-config/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf
copy to ucm-config/glimmer-cheets/byt-max98090/byt-max98090.conf
index e7394ba..eec1436 100644
--- a/ucm-config/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf
+++ b/ucm-config/glimmer-cheets/byt-max98090/byt-max98090.conf
@@ -1,4 +1,4 @@
-Comment "HD Pro Webcam C920"
+Comment "Glimmer internal card"
 
 SectionUseCase."HiFi" {
 	File "HiFi.conf"
diff --git a/ucm-config/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf b/ucm-config/guado/HDA Intel PCH/HDA Intel PCH.conf
similarity index 67%
copy from ucm-config/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf
copy to ucm-config/guado/HDA Intel PCH/HDA Intel PCH.conf
index e7394ba..cdb20bf 100644
--- a/ucm-config/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf
+++ b/ucm-config/guado/HDA Intel PCH/HDA Intel PCH.conf
@@ -1,4 +1,4 @@
-Comment "HD Pro Webcam C920"
+Comment "Guado internal card"
 
 SectionUseCase."HiFi" {
 	File "HiFi.conf"
diff --git a/ucm-config/guado/HDA Intel PCH/HiFi.conf b/ucm-config/guado/HDA Intel PCH/HiFi.conf
new file mode 100644
index 0000000..5e280c2
--- /dev/null
+++ b/ucm-config/guado/HDA Intel PCH/HiFi.conf
@@ -0,0 +1,32 @@
+SectionVerb {
+	Value {
+		NoCreateDefaultOutputNode "1"
+		NoCreateDefaultInputNode "1"
+	}
+	EnableSequence [
+		cdev "hw:PCH"
+
+		cset "name='Capture Switch' off"
+		cset "name='Capture Volume' 23"
+		cset "name='Master Playback Switch' on"
+		cset "name='Master Playback Volume' 87"
+	]
+	DisableSequence [
+	]
+}
+
+SectionDevice."Mic".0 {
+        Value {
+		JackName "Mic Jack"
+        }
+	EnableSequence [
+		cdev "hw:PCH"
+
+		cset "name='Capture Switch' on"
+	]
+	DisableSequence [
+		cdev "hw:PCH"
+
+		cset "name='Capture Switch' off"
+	]
+}
diff --git a/ucm-config/leon/HDA Intel PCH/HiFi.conf b/ucm-config/leon/HDA Intel PCH/HiFi.conf
index 03f431e..f477543 100644
--- a/ucm-config/leon/HDA Intel PCH/HiFi.conf
+++ b/ucm-config/leon/HDA Intel PCH/HiFi.conf
@@ -22,7 +22,7 @@
 SectionDevice."Headphone".0 {
 	Value {
 		JackName "Headphone Jack"
-		DspName ""
+		OutputDspName ""
 	}
 	EnableSequence [
 		cdev "hw:PCH"
diff --git a/ucm-config/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf b/ucm-config/lulu/HDA Intel PCH/HDA Intel PCH.conf
similarity index 68%
rename from ucm-config/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf
rename to ucm-config/lulu/HDA Intel PCH/HDA Intel PCH.conf
index e7394ba..f5bbcb2 100644
--- a/ucm-config/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf
+++ b/ucm-config/lulu/HDA Intel PCH/HDA Intel PCH.conf
@@ -1,4 +1,4 @@
-Comment "HD Pro Webcam C920"
+Comment "Lulu internal card"
 
 SectionUseCase."HiFi" {
 	File "HiFi.conf"
diff --git a/ucm-config/lulu/HDA Intel PCH/HiFi.conf b/ucm-config/lulu/HDA Intel PCH/HiFi.conf
new file mode 100644
index 0000000..de154ca
--- /dev/null
+++ b/ucm-config/lulu/HDA Intel PCH/HiFi.conf
@@ -0,0 +1,55 @@
+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"
+		OutputDspName ""
+	}
+	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/peppy/HDA Intel PCH/HiFi.conf b/ucm-config/peppy/HDA Intel PCH/HiFi.conf
index c33144d..73df073 100644
--- a/ucm-config/peppy/HDA Intel PCH/HiFi.conf
+++ b/ucm-config/peppy/HDA Intel PCH/HiFi.conf
@@ -22,7 +22,7 @@
 SectionDevice."Headphone".0 {
 	Value {
 		JackName "Headphone Jack"
-		DspName ""
+		OutputDspName ""
 	}
 	EnableSequence [
 		cdev "hw:PCH"
diff --git a/ucm-config/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf b/ucm-config/peppy_freon/HDA Intel PCH/HDA Intel PCH.conf
similarity index 67%
copy from ucm-config/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf
copy to ucm-config/peppy_freon/HDA Intel PCH/HDA Intel PCH.conf
index e7394ba..819f826 100644
--- a/ucm-config/for_all_boards/HD Pro Webcam C920/HD Pro Webcam C920.conf
+++ b/ucm-config/peppy_freon/HDA Intel PCH/HDA Intel PCH.conf
@@ -1,4 +1,4 @@
-Comment "HD Pro Webcam C920"
+Comment "Peppy internal card"
 
 SectionUseCase."HiFi" {
 	File "HiFi.conf"
diff --git a/ucm-config/peppy_freon/HDA Intel PCH/HiFi.conf b/ucm-config/peppy_freon/HDA Intel PCH/HiFi.conf
new file mode 100644
index 0000000..73df073
--- /dev/null
+++ b/ucm-config/peppy_freon/HDA Intel PCH/HiFi.conf
@@ -0,0 +1,55 @@
+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='Input Source' 1"
+	]
+	DisableSequence [
+	]
+}
+
+SectionDevice."Headphone".0 {
+	Value {
+		JackName "Headphone Jack"
+		OutputDspName ""
+	}
+	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='Input Source' 0"
+	]
+	DisableSequence [
+		cdev "hw:PCH"
+
+		cset "name='Input Source' 1"
+	]
+}
diff --git a/ucm-config/rush_ryu/NVIDIA Tegra Ryu/HiFi.conf b/ucm-config/rush_ryu/NVIDIA Tegra Ryu/HiFi.conf
new file mode 100644
index 0000000..97655f0
--- /dev/null
+++ b/ucm-config/rush_ryu/NVIDIA Tegra Ryu/HiFi.conf
@@ -0,0 +1,113 @@
+SectionVerb {
+	Value {
+		ExtraMainVolume "DAC1"
+	}
+
+	EnableSequence [
+		cdev "hw:Ryu"
+
+		cset "name='ADC1 Capture Volume' 31"
+		cset "name='STO1 ADC Boost Volume' 2"
+		cset "name='Sidetone Volume' 0"
+
+		cset "name='OUT1 Playback Switch' on"
+		cset "name='OUT2 Playback Switch' on"
+		cset "name='DAC1 Playback Volume' 175"
+		cset "name='DAC2 Playback Volume' 175"
+
+		cset "name='DAC12 SRC Mux' STO1 DAC MIX"
+
+		cset "name='Headphone Switch' off"
+		cset "name='Headset Mic Switch' off"
+		cset "name='Internal Mic 1 Switch' on"
+		cset "name='Internal Mic 2 Switch' off"
+		cset "name='Speaker Switch' on"
+
+		cset "name='PDM1 L Mux' STO1 DAC MIX"
+		cset "name='PDM2 L Mux' STO1 DAC MIX"
+
+		cset "name='Stereo DAC MIXL ST L Switch' off"
+		cset "name='Stereo DAC MIXL DAC2 L Switch' off"
+		cset "name='Stereo DAC MIXL DAC1 R Switch' off"
+		cset "name='Stereo DAC MIXL DAC1 L Switch' on"
+
+		cset "name='Stereo DAC MIXR ST R Switch' off"
+		cset "name='Stereo DAC MIXR DAC2 R Switch' off"
+		cset "name='Stereo DAC MIXR DAC1 L Switch' off"
+		cset "name='Stereo DAC MIXR DAC1 R Switch' on"
+
+		cset "name='IF1 ADC1 Mux' STO1 ADC MIX"
+		cset "name='IF1 ADC1 Swap Mux' L/R"
+
+		cset "name='DAC1 MIXL Stereo ADC Switch' off"
+		cset "name='DAC1 MIXL DAC1 Switch' on"
+
+		cset "name='DAC1 Mux' IF1 DAC 01"
+
+		cset "name='Stereo1 DMIC Mux' DMIC1"
+		cset "name='Stereo1 ADC2 Mux' DMIC"
+		cset "name='Stereo1 ADC1 Mux' ADC1/2"
+
+		cset "name='Sto1 ADC MIXL ADC1 Switch' off"
+		cset "name='Sto1 ADC MIXL ADC2 Switch' on"
+		cset "name='Sto1 ADC MIXR ADC1 Switch' off"
+		cset "name='Sto1 ADC MIXR ADC2 Switch' on"
+	]
+
+	DisableSequence [
+	]
+}
+
+SectionDevice."Headphone".0 {
+	Value {
+		JackName "NVIDIA Tegra Ryu Headphone Jack"
+	}
+
+	EnableSequence [
+		cdev "hw:Ryu"
+		cset "name='Speaker Switch' off"
+		cset "name='Headphone Switch' on"
+	]
+
+	DisableSequence [
+		cdev "hw:Ryu"
+		cset "name='Headphone Switch' off"
+		cset "name='Speaker Switch' on"
+	]
+}
+
+SectionDevice."Mic".0 {
+	Value {
+		JackName "NVIDIA Tegra Ryu Mic Jack"
+	}
+
+	EnableSequence [
+		cdev "hw:Ryu"
+
+		cset "name='Internal Mic 1 Switch' off"
+
+		cset "name='IF1 ADC1 Swap Mux' L/L"
+
+		cset "name='Sto1 ADC MIXL ADC2 Switch' off"
+		cset "name='Sto1 ADC MIXR ADC2 Switch' off"
+		cset "name='Sto1 ADC MIXL ADC1 Switch' on"
+		cset "name='Sto1 ADC MIXR ADC1 Switch' on"
+
+		cset "name='Headset Mic Switch' on"
+	]
+
+	DisableSequence [
+		cdev "hw:Ryu"
+
+		cset "name='Headset Mic Switch' off"
+
+		cset "name='IF1 ADC1 Swap Mux' L/R"
+
+		cset "name='Sto1 ADC MIXL ADC1 Switch' off"
+		cset "name='Sto1 ADC MIXR ADC1 Switch' off"
+		cset "name='Sto1 ADC MIXL ADC2 Switch' on"
+		cset "name='Sto1 ADC MIXR ADC2 Switch' on"
+
+		cset "name='Internal Mic 1 Switch' on"
+	]
+}
diff --git a/ucm-config/rush_ryu/NVIDIA Tegra Ryu/NVIDIA Tegra Ryu.conf b/ucm-config/rush_ryu/NVIDIA Tegra Ryu/NVIDIA Tegra Ryu.conf
new file mode 100644
index 0000000..e9a6bde
--- /dev/null
+++ b/ucm-config/rush_ryu/NVIDIA Tegra Ryu/NVIDIA Tegra Ryu.conf
@@ -0,0 +1,6 @@
+Comment "Ryu internal card"
+
+SectionUseCase."HiFi" {
+        File "HiFi.conf"
+        Comment "Default"
+}
diff --git a/ucm-config/stout32 b/ucm-config/stout32
new file mode 120000
index 0000000..9d9837c
--- /dev/null
+++ b/ucm-config/stout32
@@ -0,0 +1 @@
+stout/
\ No newline at end of file
diff --git a/ucm-config/strago/chtrt5645/HiFi.conf b/ucm-config/strago/chtrt5645/HiFi.conf
index e51c947..6f6c356 100644
--- a/ucm-config/strago/chtrt5645/HiFi.conf
+++ b/ucm-config/strago/chtrt5645/HiFi.conf
@@ -70,7 +70,7 @@
 SectionDevice."Headphone".0 {
 	Value {
 		JackName "chtrt5645 Headphone Jack"
-		DspName ""
+		OutputDspName ""
 	}
 
 	EnableSequence [
diff --git a/ucm-config/strago/chtrt5650/HiFi.conf b/ucm-config/strago/chtrt5650/HiFi.conf
index 4cdc900..4af6590 100644
--- a/ucm-config/strago/chtrt5650/HiFi.conf
+++ b/ucm-config/strago/chtrt5650/HiFi.conf
@@ -81,7 +81,7 @@
 SectionDevice."Headphone".0 {
 	Value {
 		JackName "chtrt5650 Headset Jack"
-		DspName ""
+		OutputDspName ""
 	}
 
 	EnableSequence [
diff --git a/ucm-config/strago/chtrt5676/HiFi.conf b/ucm-config/strago/chtrt5676/HiFi.conf
index dd2354f..a5b6903 100644
--- a/ucm-config/strago/chtrt5676/HiFi.conf
+++ b/ucm-config/strago/chtrt5676/HiFi.conf
@@ -71,7 +71,7 @@
 SectionDevice."Headphone".0 {
 	Value {
 		JackName "chtrt5676 Headset Jack"
-		DspName ""
+		OutputDspName ""
 	}
 
 	EnableSequence [
diff --git a/ucm-config/veyron/ROCKCHIP-I2S/HiFi.conf b/ucm-config/veyron/ROCKCHIP-I2S/HiFi.conf
index a7d8020..f01190c 100644
--- a/ucm-config/veyron/ROCKCHIP-I2S/HiFi.conf
+++ b/ucm-config/veyron/ROCKCHIP-I2S/HiFi.conf
@@ -88,7 +88,7 @@
 		MixerName "Headphone"
 		JackType "gpio"
 		JackName "ROCKCHIP-I2S Headset Jack"
-		DspName ""
+		OutputDspName ""
 	}
 
 	EnableSequence [
diff --git a/ucm-config/veyron/RockchipHDMI/HiFi.conf b/ucm-config/veyron/RockchipHDMI/HiFi.conf
index bf76d6a..890c97c 100644
--- a/ucm-config/veyron/RockchipHDMI/HiFi.conf
+++ b/ucm-config/veyron/RockchipHDMI/HiFi.conf
@@ -1,5 +1,6 @@
 SectionVerb {
 	Value {
+		OutputDspName ""
 		MinBufferLevel "512"
 	}
 }
@@ -7,6 +8,7 @@
 SectionDevice."HDMI".0 {
 	Value {
 		JackName "RockchipHDMI HDMI Jack"
+		OutputDspName ""
 		EDIDFile "/sys/class/drm/card1-HDMI-A-1/edid"
 	}
 }
diff --git a/ucm-config/veyron/VEYRON-I2S/HiFi.conf b/ucm-config/veyron/VEYRON-I2S/HiFi.conf
deleted file mode 100644
index 2698529..0000000
--- a/ucm-config/veyron/VEYRON-I2S/HiFi.conf
+++ /dev/null
@@ -1,158 +0,0 @@
-SectionVerb {
-	Value {
-		OutputDspName "speaker_eq"
-		MinBufferLevel "512"
-		FullySpecifiedUCM "1"
-	}
-
-	EnableSequence [
-		cdev "hw:VEYRONI2S"
-
-		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='Right ADC Mixer MIC2 Switch' on"
-		cset "name='Left ADC Mixer MIC2 Switch' on"
-		cset "name='MIC2 Volume' 20"
-		cset "name='Headset Mic Switch' off"
-		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='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 [
-	]
-}
-
-SectionDevice."Speaker".0 {
-	Value {
-		PlaybackPCM "hw:VEYRONI2S,0"
-		MixerName "Speaker"
-	}
-	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"
-	]
-}
-
-SectionDevice."Internal Mic".0 {
-	Value {
-		CapturePCM "hw:VEYRONI2S,0"
-		MixerName "Int Mic"
-	}
-	EnableSequence [
-		cdev "hw:VEYRONI2S"
-
-		cset "name='Int Mic Switch' on"
-	]
-	DisableSequence [
-		cdev "hw:VEYRONI2S"
-
-		cset "name='Int Mic Switch' off"
-	]
-}
-
-SectionDevice."Headphone".0 {
-	Value {
-		PlaybackPCM "hw:VEYRONI2S,0"
-		MixerName "Headphone"
-		JackType "gpio"
-		JackName "VEYRON-I2S Headset Jack"
-		OutputDspName ""
-	}
-
-	EnableSequence [
-		cdev "hw:VEYRONI2S"
-
-		cset "name='HP Left Out Switch' on"
-		cset "name='HP Right Out Switch' on"
-		cset "name='Headphone Switch' on"
-	]
-	DisableSequence [
-		cdev "hw:VEYRONI2S"
-
-		cset "name='Headphone Switch' off"
-		cset "name='HP Left Out Switch' off"
-		cset "name='HP Right Out Switch' off"
-	]
-}
-
-SectionDevice."Mic".0 {
-	Value {
-		CapturePCM "hw:VEYRONI2S,0"
-		MixerName "Headset Mic"
-		JackType "gpio"
-		JackName "VEYRON-I2S Headset Jack"
-	}
-
-	EnableSequence [
-		cdev "hw:VEYRONI2S"
-
-		cset "name='Int Mic Switch' off"
-		cset "name='DMIC Mux' ADC"
-		cset "name='Headset Mic Switch' on"
-		cset "name='Record Path DC Blocking' on"
-	]
-
-	DisableSequence [
-		cdev "hw:VEYRONI2S"
-
-		cset "name='Headset Mic Switch' off"
-		cset "name='DMIC Mux' DMIC"
-		cset "name='Int Mic Switch' on"
-		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/VEYRON-I2S/VEYRON-I2S.conf b/ucm-config/veyron/VEYRON-I2S/VEYRON-I2S.conf
deleted file mode 100644
index 0c399b0..0000000
--- a/ucm-config/veyron/VEYRON-I2S/VEYRON-I2S.conf
+++ /dev/null
@@ -1,6 +0,0 @@
-Comment "Rockchip card"
-
-SectionUseCase."HiFi" {
-	File "HiFi.conf"
-	Comment "Default"
-}
diff --git a/ucm-config/veyron_fievel/ROCKCHIP-I2S/HiFi.conf b/ucm-config/veyron_fievel/ROCKCHIP-I2S/HiFi.conf
index c9e570a..bf52f73 100644
--- a/ucm-config/veyron_fievel/ROCKCHIP-I2S/HiFi.conf
+++ b/ucm-config/veyron_fievel/ROCKCHIP-I2S/HiFi.conf
@@ -54,7 +54,7 @@
 		MixerName "Headphone"
 		JackType "gpio"
 		JackName "ROCKCHIP-I2S Headset Jack"
-		DspName ""
+		OutputDspName ""
 	}
 
 	EnableSequence [
diff --git a/ucm-config/veyron_fievel/RockchipHDMI/HiFi.conf b/ucm-config/veyron_fievel/RockchipHDMI/HiFi.conf
index bf76d6a..890c97c 100644
--- a/ucm-config/veyron_fievel/RockchipHDMI/HiFi.conf
+++ b/ucm-config/veyron_fievel/RockchipHDMI/HiFi.conf
@@ -1,5 +1,6 @@
 SectionVerb {
 	Value {
+		OutputDspName ""
 		MinBufferLevel "512"
 	}
 }
@@ -7,6 +8,7 @@
 SectionDevice."HDMI".0 {
 	Value {
 		JackName "RockchipHDMI HDMI Jack"
+		OutputDspName ""
 		EDIDFile "/sys/class/drm/card1-HDMI-A-1/edid"
 	}
 }
diff --git a/ucm-config/veyron_fievel/VEYRON-I2S/VEYRON-I2S.conf b/ucm-config/veyron_fievel/VEYRON-I2S/VEYRON-I2S.conf
deleted file mode 100644
index 0c399b0..0000000
--- a/ucm-config/veyron_fievel/VEYRON-I2S/VEYRON-I2S.conf
+++ /dev/null
@@ -1,6 +0,0 @@
-Comment "Rockchip card"
-
-SectionUseCase."HiFi" {
-	File "HiFi.conf"
-	Comment "Default"
-}
diff --git a/ucm-config/veyron_jaq/ROCKCHIP-I2S/HiFi.conf b/ucm-config/veyron_jaq/ROCKCHIP-I2S/HiFi.conf
index 8523a81..4701262 100644
--- a/ucm-config/veyron_jaq/ROCKCHIP-I2S/HiFi.conf
+++ b/ucm-config/veyron_jaq/ROCKCHIP-I2S/HiFi.conf
@@ -93,7 +93,7 @@
 		MixerName "Headphone"
 		JackType "gpio"
 		JackName "ROCKCHIP-I2S Headset Jack"
-		DspName ""
+		OutputDspName ""
 	}
 
 	EnableSequence [
diff --git a/ucm-config/veyron_jaq/RockchipHDMI/HiFi.conf b/ucm-config/veyron_jaq/RockchipHDMI/HiFi.conf
index bf76d6a..890c97c 100644
--- a/ucm-config/veyron_jaq/RockchipHDMI/HiFi.conf
+++ b/ucm-config/veyron_jaq/RockchipHDMI/HiFi.conf
@@ -1,5 +1,6 @@
 SectionVerb {
 	Value {
+		OutputDspName ""
 		MinBufferLevel "512"
 	}
 }
@@ -7,6 +8,7 @@
 SectionDevice."HDMI".0 {
 	Value {
 		JackName "RockchipHDMI HDMI Jack"
+		OutputDspName ""
 		EDIDFile "/sys/class/drm/card1-HDMI-A-1/edid"
 	}
 }
diff --git a/ucm-config/veyron_jaq/VEYRON-I2S/HiFi.conf b/ucm-config/veyron_jaq/VEYRON-I2S/HiFi.conf
deleted file mode 100644
index 2698529..0000000
--- a/ucm-config/veyron_jaq/VEYRON-I2S/HiFi.conf
+++ /dev/null
@@ -1,158 +0,0 @@
-SectionVerb {
-	Value {
-		OutputDspName "speaker_eq"
-		MinBufferLevel "512"
-		FullySpecifiedUCM "1"
-	}
-
-	EnableSequence [
-		cdev "hw:VEYRONI2S"
-
-		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='Right ADC Mixer MIC2 Switch' on"
-		cset "name='Left ADC Mixer MIC2 Switch' on"
-		cset "name='MIC2 Volume' 20"
-		cset "name='Headset Mic Switch' off"
-		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='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 [
-	]
-}
-
-SectionDevice."Speaker".0 {
-	Value {
-		PlaybackPCM "hw:VEYRONI2S,0"
-		MixerName "Speaker"
-	}
-	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"
-	]
-}
-
-SectionDevice."Internal Mic".0 {
-	Value {
-		CapturePCM "hw:VEYRONI2S,0"
-		MixerName "Int Mic"
-	}
-	EnableSequence [
-		cdev "hw:VEYRONI2S"
-
-		cset "name='Int Mic Switch' on"
-	]
-	DisableSequence [
-		cdev "hw:VEYRONI2S"
-
-		cset "name='Int Mic Switch' off"
-	]
-}
-
-SectionDevice."Headphone".0 {
-	Value {
-		PlaybackPCM "hw:VEYRONI2S,0"
-		MixerName "Headphone"
-		JackType "gpio"
-		JackName "VEYRON-I2S Headset Jack"
-		OutputDspName ""
-	}
-
-	EnableSequence [
-		cdev "hw:VEYRONI2S"
-
-		cset "name='HP Left Out Switch' on"
-		cset "name='HP Right Out Switch' on"
-		cset "name='Headphone Switch' on"
-	]
-	DisableSequence [
-		cdev "hw:VEYRONI2S"
-
-		cset "name='Headphone Switch' off"
-		cset "name='HP Left Out Switch' off"
-		cset "name='HP Right Out Switch' off"
-	]
-}
-
-SectionDevice."Mic".0 {
-	Value {
-		CapturePCM "hw:VEYRONI2S,0"
-		MixerName "Headset Mic"
-		JackType "gpio"
-		JackName "VEYRON-I2S Headset Jack"
-	}
-
-	EnableSequence [
-		cdev "hw:VEYRONI2S"
-
-		cset "name='Int Mic Switch' off"
-		cset "name='DMIC Mux' ADC"
-		cset "name='Headset Mic Switch' on"
-		cset "name='Record Path DC Blocking' on"
-	]
-
-	DisableSequence [
-		cdev "hw:VEYRONI2S"
-
-		cset "name='Headset Mic Switch' off"
-		cset "name='DMIC Mux' DMIC"
-		cset "name='Int Mic Switch' on"
-		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/VEYRON-I2S.conf b/ucm-config/veyron_jaq/VEYRON-I2S/VEYRON-I2S.conf
deleted file mode 100644
index 0c399b0..0000000
--- a/ucm-config/veyron_jaq/VEYRON-I2S/VEYRON-I2S.conf
+++ /dev/null
@@ -1,6 +0,0 @@
-Comment "Rockchip card"
-
-SectionUseCase."HiFi" {
-	File "HiFi.conf"
-	Comment "Default"
-}
diff --git a/ucm-config/veyron_minnie-kernelnext b/ucm-config/veyron_minnie-kernelnext
deleted file mode 120000
index 5fea6bb..0000000
--- a/ucm-config/veyron_minnie-kernelnext
+++ /dev/null
@@ -1 +0,0 @@
-veyron_minnie
\ No newline at end of file
diff --git a/ucm-config/veyron_minnie/ROCKCHIP-I2S/HiFi.conf b/ucm-config/veyron_minnie/ROCKCHIP-I2S/HiFi.conf
index bcfe915..ce29a3f 100644
--- a/ucm-config/veyron_minnie/ROCKCHIP-I2S/HiFi.conf
+++ b/ucm-config/veyron_minnie/ROCKCHIP-I2S/HiFi.conf
@@ -88,7 +88,7 @@
 		MixerName "Headphone"
 		JackType "gpio"
 		JackName "ROCKCHIP-I2S Headset Jack"
-		DspName ""
+		OutputDspName ""
 	}
 
 	EnableSequence [
diff --git a/ucm-config/veyron_minnie/RockchipHDMI/HiFi.conf b/ucm-config/veyron_minnie/RockchipHDMI/HiFi.conf
index bf76d6a..890c97c 100644
--- a/ucm-config/veyron_minnie/RockchipHDMI/HiFi.conf
+++ b/ucm-config/veyron_minnie/RockchipHDMI/HiFi.conf
@@ -1,5 +1,6 @@
 SectionVerb {
 	Value {
+		OutputDspName ""
 		MinBufferLevel "512"
 	}
 }
@@ -7,6 +8,7 @@
 SectionDevice."HDMI".0 {
 	Value {
 		JackName "RockchipHDMI HDMI Jack"
+		OutputDspName ""
 		EDIDFile "/sys/class/drm/card1-HDMI-A-1/edid"
 	}
 }
diff --git a/ucm-config/veyron_minnie/VEYRON-I2S/HiFi.conf b/ucm-config/veyron_minnie/VEYRON-I2S/HiFi.conf
deleted file mode 100644
index fd4e6a8..0000000
--- a/ucm-config/veyron_minnie/VEYRON-I2S/HiFi.conf
+++ /dev/null
@@ -1,158 +0,0 @@
-SectionVerb {
-	Value {
-		OutputDspName "speaker_eq"
-		MinBufferLevel "512"
-		FullySpecifiedUCM "1"
-	}
-
-	EnableSequence [
-		cdev "hw:VEYRONI2S"
-
-		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='Right ADC Mixer MIC2 Switch' on"
-		cset "name='Left ADC Mixer MIC2 Switch' on"
-		cset "name='MIC2 Volume' 20"
-		cset "name='Headset Mic Switch' off"
-		cset "name='Int Mic Switch' on"
-
-		cset "name='ADCR Boost Volume' 4"
-		cset "name='ADCL Boost Volume' 4"
-		cset "name='ADCR Volume' 8"
-		cset "name='ADCL Volume' 8"
-
-		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='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 [
-	]
-}
-
-SectionDevice."Speaker".0 {
-	Value {
-		PlaybackPCM "hw:VEYRONI2S,0"
-		MixerName "Speaker"
-	}
-	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"
-	]
-}
-
-SectionDevice."Internal Mic".0 {
-	Value {
-		CapturePCM "hw:VEYRONI2S,0"
-		MixerName "Int Mic"
-	}
-	EnableSequence [
-		cdev "hw:VEYRONI2S"
-
-		cset "name='Int Mic Switch' on"
-	]
-	DisableSequence [
-		cdev "hw:VEYRONI2S"
-
-		cset "name='Int Mic Switch' off"
-	]
-}
-
-SectionDevice."Headphone".0 {
-	Value {
-		PlaybackPCM "hw:VEYRONI2S,0"
-		MixerName "Headphone"
-		JackType "gpio"
-		JackName "VEYRON-I2S Headset Jack"
-		OutputDspName ""
-	}
-
-	EnableSequence [
-		cdev "hw:VEYRONI2S"
-
-		cset "name='HP Left Out Switch' on"
-		cset "name='HP Right Out Switch' on"
-		cset "name='Headphone Switch' on"
-	]
-	DisableSequence [
-		cdev "hw:VEYRONI2S"
-
-		cset "name='Headphone Switch' off"
-		cset "name='HP Left Out Switch' off"
-		cset "name='HP Right Out Switch' off"
-	]
-}
-
-SectionDevice."Mic".0 {
-	Value {
-		CapturePCM "hw:VEYRONI2S,0"
-		MixerName "Headset Mic"
-		JackType "gpio"
-		JackName "VEYRON-I2S Headset Jack"
-	}
-
-	EnableSequence [
-		cdev "hw:VEYRONI2S"
-
-		cset "name='Int Mic Switch' off"
-		cset "name='DMIC Mux' ADC"
-		cset "name='Headset Mic Switch' on"
-		cset "name='Record Path DC Blocking' on"
-	]
-
-	DisableSequence [
-		cdev "hw:VEYRONI2S"
-
-		cset "name='Headset Mic Switch' off"
-		cset "name='DMIC Mux' DMIC"
-		cset "name='Int Mic Switch' on"
-		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/VEYRON-I2S.conf b/ucm-config/veyron_minnie/VEYRON-I2S/VEYRON-I2S.conf
deleted file mode 100644
index 0c399b0..0000000
--- a/ucm-config/veyron_minnie/VEYRON-I2S/VEYRON-I2S.conf
+++ /dev/null
@@ -1,6 +0,0 @@
-Comment "Rockchip card"
-
-SectionUseCase."HiFi" {
-	File "HiFi.conf"
-	Comment "Default"
-}
diff --git a/ucm-config/veyron_speedy/ROCKCHIP-I2S/HiFi.conf b/ucm-config/veyron_speedy/ROCKCHIP-I2S/HiFi.conf
index bcfe915..ce29a3f 100644
--- a/ucm-config/veyron_speedy/ROCKCHIP-I2S/HiFi.conf
+++ b/ucm-config/veyron_speedy/ROCKCHIP-I2S/HiFi.conf
@@ -88,7 +88,7 @@
 		MixerName "Headphone"
 		JackType "gpio"
 		JackName "ROCKCHIP-I2S Headset Jack"
-		DspName ""
+		OutputDspName ""
 	}
 
 	EnableSequence [
diff --git a/ucm-config/veyron_speedy/RockchipHDMI/HiFi.conf b/ucm-config/veyron_speedy/RockchipHDMI/HiFi.conf
index bf76d6a..890c97c 100644
--- a/ucm-config/veyron_speedy/RockchipHDMI/HiFi.conf
+++ b/ucm-config/veyron_speedy/RockchipHDMI/HiFi.conf
@@ -1,5 +1,6 @@
 SectionVerb {
 	Value {
+		OutputDspName ""
 		MinBufferLevel "512"
 	}
 }
@@ -7,6 +8,7 @@
 SectionDevice."HDMI".0 {
 	Value {
 		JackName "RockchipHDMI HDMI Jack"
+		OutputDspName ""
 		EDIDFile "/sys/class/drm/card1-HDMI-A-1/edid"
 	}
 }
diff --git a/ucm-config/veyron_speedy/VEYRON-I2S/HiFi.conf b/ucm-config/veyron_speedy/VEYRON-I2S/HiFi.conf
deleted file mode 100644
index fd4e6a8..0000000
--- a/ucm-config/veyron_speedy/VEYRON-I2S/HiFi.conf
+++ /dev/null
@@ -1,158 +0,0 @@
-SectionVerb {
-	Value {
-		OutputDspName "speaker_eq"
-		MinBufferLevel "512"
-		FullySpecifiedUCM "1"
-	}
-
-	EnableSequence [
-		cdev "hw:VEYRONI2S"
-
-		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='Right ADC Mixer MIC2 Switch' on"
-		cset "name='Left ADC Mixer MIC2 Switch' on"
-		cset "name='MIC2 Volume' 20"
-		cset "name='Headset Mic Switch' off"
-		cset "name='Int Mic Switch' on"
-
-		cset "name='ADCR Boost Volume' 4"
-		cset "name='ADCL Boost Volume' 4"
-		cset "name='ADCR Volume' 8"
-		cset "name='ADCL Volume' 8"
-
-		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='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 [
-	]
-}
-
-SectionDevice."Speaker".0 {
-	Value {
-		PlaybackPCM "hw:VEYRONI2S,0"
-		MixerName "Speaker"
-	}
-	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"
-	]
-}
-
-SectionDevice."Internal Mic".0 {
-	Value {
-		CapturePCM "hw:VEYRONI2S,0"
-		MixerName "Int Mic"
-	}
-	EnableSequence [
-		cdev "hw:VEYRONI2S"
-
-		cset "name='Int Mic Switch' on"
-	]
-	DisableSequence [
-		cdev "hw:VEYRONI2S"
-
-		cset "name='Int Mic Switch' off"
-	]
-}
-
-SectionDevice."Headphone".0 {
-	Value {
-		PlaybackPCM "hw:VEYRONI2S,0"
-		MixerName "Headphone"
-		JackType "gpio"
-		JackName "VEYRON-I2S Headset Jack"
-		OutputDspName ""
-	}
-
-	EnableSequence [
-		cdev "hw:VEYRONI2S"
-
-		cset "name='HP Left Out Switch' on"
-		cset "name='HP Right Out Switch' on"
-		cset "name='Headphone Switch' on"
-	]
-	DisableSequence [
-		cdev "hw:VEYRONI2S"
-
-		cset "name='Headphone Switch' off"
-		cset "name='HP Left Out Switch' off"
-		cset "name='HP Right Out Switch' off"
-	]
-}
-
-SectionDevice."Mic".0 {
-	Value {
-		CapturePCM "hw:VEYRONI2S,0"
-		MixerName "Headset Mic"
-		JackType "gpio"
-		JackName "VEYRON-I2S Headset Jack"
-	}
-
-	EnableSequence [
-		cdev "hw:VEYRONI2S"
-
-		cset "name='Int Mic Switch' off"
-		cset "name='DMIC Mux' ADC"
-		cset "name='Headset Mic Switch' on"
-		cset "name='Record Path DC Blocking' on"
-	]
-
-	DisableSequence [
-		cdev "hw:VEYRONI2S"
-
-		cset "name='Headset Mic Switch' off"
-		cset "name='DMIC Mux' DMIC"
-		cset "name='Int Mic Switch' on"
-		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/VEYRON-I2S.conf b/ucm-config/veyron_speedy/VEYRON-I2S/VEYRON-I2S.conf
deleted file mode 100644
index 0c399b0..0000000
--- a/ucm-config/veyron_speedy/VEYRON-I2S/VEYRON-I2S.conf
+++ /dev/null
@@ -1,6 +0,0 @@
-Comment "Rockchip card"
-
-SectionUseCase."HiFi" {
-	File "HiFi.conf"
-	Comment "Default"
-}
diff --git a/ucm-config/wolf/HDA Intel PCH/HiFi.conf b/ucm-config/wolf/HDA Intel PCH/HiFi.conf
index 03f431e..f477543 100644
--- a/ucm-config/wolf/HDA Intel PCH/HiFi.conf
+++ b/ucm-config/wolf/HDA Intel PCH/HiFi.conf
@@ -22,7 +22,7 @@
 SectionDevice."Headphone".0 {
 	Value {
 		JackName "Headphone Jack"
-		DspName ""
+		OutputDspName ""
 	}
 	EnableSequence [
 		cdev "hw:PCH"