Home | History | Annotate | Download | only in audioflinger
      1 /* //device/servers/AudioFlinger/AudioDumpInterface.h
      2 **
      3 ** Copyright 2008, The Android Open Source Project
      4 **
      5 ** Licensed under the Apache License, Version 2.0 (the "License");
      6 ** you may not use this file except in compliance with the License.
      7 ** You may obtain a copy of the License at
      8 **
      9 **     http://www.apache.org/licenses/LICENSE-2.0
     10 **
     11 ** Unless required by applicable law or agreed to in writing, software
     12 ** distributed under the License is distributed on an "AS IS" BASIS,
     13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 ** See the License for the specific language governing permissions and
     15 ** limitations under the License.
     16 */
     17 
     18 #ifndef ANDROID_AUDIO_DUMP_INTERFACE_H
     19 #define ANDROID_AUDIO_DUMP_INTERFACE_H
     20 
     21 #include <stdint.h>
     22 #include <sys/types.h>
     23 #include <utils/String8.h>
     24 #include <utils/SortedVector.h>
     25 
     26 #include <hardware_legacy/AudioHardwareBase.h>
     27 
     28 namespace android {
     29 
     30 #define AUDIO_DUMP_WAVE_HDR_SIZE 44
     31 
     32 class AudioDumpInterface;
     33 
     34 class AudioStreamOutDump : public AudioStreamOut {
     35 public:
     36                         AudioStreamOutDump(AudioDumpInterface *interface,
     37                                             int id,
     38                                             AudioStreamOut* finalStream,
     39                                             uint32_t devices,
     40                                             int format,
     41                                             uint32_t channels,
     42                                             uint32_t sampleRate);
     43                         ~AudioStreamOutDump();
     44 
     45     virtual ssize_t     write(const void* buffer, size_t bytes);
     46     virtual uint32_t    sampleRate() const;
     47     virtual size_t      bufferSize() const;
     48     virtual uint32_t    channels() const;
     49     virtual int         format() const;
     50     virtual uint32_t    latency() const;
     51     virtual status_t    setVolume(float left, float right);
     52     virtual status_t    standby();
     53     virtual status_t    setParameters(const String8& keyValuePairs);
     54     virtual String8     getParameters(const String8& keys);
     55     virtual status_t    dump(int fd, const Vector<String16>& args);
     56     void                Close(void);
     57     AudioStreamOut*     finalStream() { return mFinalStream; }
     58     uint32_t            device() { return mDevice; }
     59     int                 getId()  { return mId; }
     60     virtual status_t    getRenderPosition(uint32_t *dspFrames);
     61 
     62 private:
     63     AudioDumpInterface *mInterface;
     64     int                  mId;
     65     uint32_t mSampleRate;               //
     66     uint32_t mFormat;                   //
     67     uint32_t mChannels;                 // output configuration
     68     uint32_t mLatency;                  //
     69     uint32_t mDevice;                   // current device this output is routed to
     70     size_t  mBufferSize;
     71     AudioStreamOut      *mFinalStream;
     72     FILE                *mOutFile;      // output file
     73     int                 mFileCount;
     74 };
     75 
     76 class AudioStreamInDump : public AudioStreamIn {
     77 public:
     78                         AudioStreamInDump(AudioDumpInterface *interface,
     79                                             int id,
     80                                             AudioStreamIn* finalStream,
     81                                             uint32_t devices,
     82                                             int format,
     83                                             uint32_t channels,
     84                                             uint32_t sampleRate);
     85                         ~AudioStreamInDump();
     86 
     87     virtual uint32_t    sampleRate() const;
     88     virtual size_t      bufferSize() const;
     89     virtual uint32_t    channels() const;
     90     virtual int         format() const;
     91 
     92     virtual status_t    setGain(float gain);
     93     virtual ssize_t     read(void* buffer, ssize_t bytes);
     94     virtual status_t    standby();
     95     virtual status_t    setParameters(const String8& keyValuePairs);
     96     virtual String8     getParameters(const String8& keys);
     97     virtual unsigned int  getInputFramesLost() const;
     98     virtual status_t    dump(int fd, const Vector<String16>& args);
     99     void                Close(void);
    100     AudioStreamIn*     finalStream() { return mFinalStream; }
    101     uint32_t            device() { return mDevice; }
    102 
    103 private:
    104     AudioDumpInterface *mInterface;
    105     int                  mId;
    106     uint32_t mSampleRate;               //
    107     uint32_t mFormat;                   //
    108     uint32_t mChannels;                 // output configuration
    109     uint32_t mDevice;                   // current device this output is routed to
    110     size_t  mBufferSize;
    111     AudioStreamIn      *mFinalStream;
    112     FILE                *mInFile;      // output file
    113 };
    114 
    115 class AudioDumpInterface : public AudioHardwareBase
    116 {
    117 
    118 public:
    119                         AudioDumpInterface(AudioHardwareInterface* hw);
    120     virtual AudioStreamOut* openOutputStream(
    121                                 uint32_t devices,
    122                                 int *format=0,
    123                                 uint32_t *channels=0,
    124                                 uint32_t *sampleRate=0,
    125                                 status_t *status=0);
    126     virtual    void        closeOutputStream(AudioStreamOut* out);
    127 
    128     virtual             ~AudioDumpInterface();
    129 
    130     virtual status_t    initCheck()
    131                             {return mFinalInterface->initCheck();}
    132     virtual status_t    setVoiceVolume(float volume)
    133                             {return mFinalInterface->setVoiceVolume(volume);}
    134     virtual status_t    setMasterVolume(float volume)
    135                             {return mFinalInterface->setMasterVolume(volume);}
    136 
    137     // mic mute
    138     virtual status_t    setMicMute(bool state)
    139                             {return mFinalInterface->setMicMute(state);}
    140     virtual status_t    getMicMute(bool* state)
    141                             {return mFinalInterface->getMicMute(state);}
    142 
    143     virtual status_t    setParameters(const String8& keyValuePairs);
    144     virtual String8     getParameters(const String8& keys);
    145 
    146     virtual AudioStreamIn* openInputStream(uint32_t devices, int *format, uint32_t *channels,
    147             uint32_t *sampleRate, status_t *status, AudioSystem::audio_in_acoustics acoustics);
    148     virtual    void        closeInputStream(AudioStreamIn* in);
    149 
    150     virtual status_t    dump(int fd, const Vector<String16>& args) { return mFinalInterface->dumpState(fd, args); }
    151 
    152             String8     fileName() const { return mFileName; }
    153 protected:
    154 
    155     AudioHardwareInterface          *mFinalInterface;
    156     SortedVector<AudioStreamOutDump *>    mOutputs;
    157     bool                            mFirstHwOutput;
    158     SortedVector<AudioStreamInDump *>    mInputs;
    159     Mutex                           mLock;
    160     String8                         mPolicyCommands;
    161     String8                         mFileName;
    162 };
    163 
    164 }; // namespace android
    165 
    166 #endif // ANDROID_AUDIO_DUMP_INTERFACE_H
    167