audio flinger: add patch connection between hw modules

Add support for audio device connections between different audio
hw modules.
The patch is performed by creating a bridge between the playback
thread connected to the sink device and the record thread connected
to the source device using a pair of specialized PlaybackTrack and
RecordTrack.
- Added PatchTrack and PatchRecord classes.
- Added TrackBase type to indicate more clearly the track behavior.
- A TrackBase can allocate the buffer or reuse an existing one.
- Factored some code in openOutput() and openInput() for internal use
by PatchPanel.

Bug: 14815883.

Change-Id: Ib9515fcda864610458a4bc81fa8f59096ff4d7db
diff --git a/services/audioflinger/PatchPanel.h b/services/audioflinger/PatchPanel.h
index 7f78621..e31179c 100644
--- a/services/audioflinger/PatchPanel.h
+++ b/services/audioflinger/PatchPanel.h
@@ -21,6 +21,9 @@
 
 class PatchPanel : public RefBase {
 public:
+
+    class Patch;
+
     PatchPanel(const sp<AudioFlinger>& audioFlinger);
     virtual ~PatchPanel();
 
@@ -45,16 +48,31 @@
     /* Set audio port configuration */
     status_t setAudioPortConfig(const struct audio_port_config *config);
 
+    status_t createPatchConnections(Patch *patch,
+                                    const struct audio_patch *audioPatch);
+    void clearPatchConnections(Patch *patch);
+
     class Patch {
     public:
         Patch(const struct audio_patch *patch) :
-            mAudioPatch(*patch), mHandle(0), mHalHandle(0) {}
+            mAudioPatch(*patch), mHandle(AUDIO_PATCH_HANDLE_NONE),
+            mHalHandle(AUDIO_PATCH_HANDLE_NONE), mRecordPatchHandle(AUDIO_PATCH_HANDLE_NONE),
+            mPlaybackPatchHandle(AUDIO_PATCH_HANDLE_NONE) {}
+        ~Patch() {}
 
-        struct audio_patch mAudioPatch;
-        audio_patch_handle_t mHandle;
-        audio_patch_handle_t mHalHandle;
+        struct audio_patch              mAudioPatch;
+        audio_patch_handle_t            mHandle;
+        audio_patch_handle_t            mHalHandle;
+        sp<PlaybackThread>              mPlaybackThread;
+        sp<PlaybackThread::PatchTrack>  mPatchTrack;
+        sp<RecordThread>                mRecordThread;
+        sp<RecordThread::PatchRecord>   mPatchRecord;
+        audio_patch_handle_t            mRecordPatchHandle;
+        audio_patch_handle_t            mPlaybackPatchHandle;
+
     };
+
 private:
-    const wp<AudioFlinger>  mAudioFlinger;
-    SortedVector <Patch *> mPatches;
+    const wp<AudioFlinger>      mAudioFlinger;
+    SortedVector <Patch *>      mPatches;
 };