initial audio HAL implementation for mako

alsa_sound is imported from codeaurora at:

c1217338f349fe746e0933fcf9b1b288b532808d

[remote "quic"]
        url = git://git-android.quicinc.com/platform/hardware/alsa_sound.git
        review = review-android.quicinc.com
        projectname = platform/hardware/alsa_sound
        fetch = +refs/heads/*:refs/remotes/quic/*

Change-Id: Ic985cc3a1088c3957b6e2ac5537e2c36caaf7212
Signed-off-by: Iliyan Malchev <malchev@google.com>
diff --git a/alsa_sound/AudioUsbALSA.h b/alsa_sound/AudioUsbALSA.h
new file mode 100644
index 0000000..1b6104d
--- /dev/null
+++ b/alsa_sound/AudioUsbALSA.h
@@ -0,0 +1,148 @@
+/* AudioUsbALSA.h
+
+Copyright (c) 2012, Code Aurora Forum. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above
+      copyright notice, this list of conditions and the following
+      disclaimer in the documentation and/or other materials provided
+      with the distribution.
+    * Neither the name of Code Aurora Forum, Inc. nor the names of its
+      contributors may be used to endorse or promote products derived
+      from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
+
+#ifndef ANDROID_AUDIO_USB_ALSA_H
+#define ANDROID_AUDIO_USB_ALSA_H
+
+#include <utils/List.h>
+#include <hardware_legacy/AudioHardwareBase.h>
+
+#include <hardware_legacy/AudioHardwareInterface.h>
+#include <hardware_legacy/AudioSystemLegacy.h>
+#include <system/audio.h>
+#include <hardware/audio.h>
+#include <utils/threads.h>
+
+#define DEFAULT_BUFFER_SIZE   2048
+#define POLL_TIMEOUT   3000
+#define DEFAULT_CHANNEL_MODE  2
+#define CHANNEL_MODE_ONE  1
+#define PROXY_DEFAULT_SAMPLING_RATE 48000
+#define SIGNAL_EVENT_TIMEOUT 1
+#define SIGNAL_EVENT_KILLTHREAD 2
+
+#define BUFFSIZE 1000000
+
+#define PATH "/proc/asound/card1/stream0"
+
+extern "C" {
+   #include <sound/asound.h>
+   #include "alsa_audio.h"
+   #include "msm8960_use_cases.h"
+}
+
+#include <hardware/hardware.h>
+
+namespace android_audio_legacy
+{
+using android::List;
+using android::Mutex;
+class AudioUsbALSA;
+
+class AudioUsbALSA
+{
+private:
+    int mproxypfdPlayback;
+    int musbpfdPlayback;
+    int mnfdsPlayback;
+    int mnfdsRecording;
+    int mtimeOut;
+    int mtimeOutRecording;
+    struct pcm *mproxyRecordingHandle;
+    struct pcm *musbRecordingHandle;
+    struct pcm *mproxyPlaybackHandle;
+    struct pcm *musbPlaybackHandle;
+    u_int8_t *mdstUsb_addr;
+    u_int8_t *msrcProxy_addr;
+    bool mkillPlayBackThread;
+    bool mkillRecordingThread;
+    pthread_t mPlaybackUsb;
+    pthread_t mRecordingUsb;
+    snd_use_case_mgr_t *mUcMgr;
+
+public:
+    AudioUsbALSA();
+    virtual            ~AudioUsbALSA();
+
+    //Helper functions
+    status_t configureUsbDevice();
+    status_t configureProxyDevice();
+    status_t configureUsbDeviceForRecording();
+    status_t configureProxyDeviceForRecording();
+    status_t syncPtr(struct pcm *handle, bool *killThread);
+
+    //playback
+    void pollForProxyData();
+    void pollForUsbData();
+
+    //recording
+    void pollForUsbDataForRecording();
+    void pollForProxyDataForRecording();
+
+    status_t startDevice(pcm *handle, bool *killThread);
+
+    void exitPlaybackThread(uint64_t writeVal);
+    void exitRecordingThread(uint64_t writeVal);
+    void setkillUsbRecordingThread(bool val);
+    bool getkillUsbPlaybackThread() {
+        return mkillPlayBackThread;
+    }
+    bool getkillUsbRecordingThread() {
+        return mkillRecordingThread;
+    }
+    void closePlaybackDevices();
+    void closeRecordingDevices();
+    //Playback
+    void startPlayback();
+    void PlaybackThreadEntry();
+    static void *PlaybackThreadWrapper(void *me);
+
+    //Capture
+    void startRecording();
+    void RecordingThreadEntry();
+
+    static void *RecordingThreadWrapper(void *me);
+
+    status_t setHardwareParams(pcm *local_handle, uint32_t sampleRate, uint32_t channels);
+
+    status_t setSoftwareParams(pcm *pcm);
+
+    status_t closeDevice(pcm *handle);
+
+    status_t    getPlaybackCap();
+    status_t    getCaptureCap();
+    int         getnumOfRates(char *rateStr);
+    int         mchannelsPlayback;
+    int         msampleRatePlayback;
+    int         mchannelsCapture;
+    int         msampleRateCapture;
+};
+
+};        // namespace android_audio_legacy
+#endif    // ANDROID_AUDIO_USB_ALSA_H