The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | /* //device/servers/AudioFlinger/AudioDumpInterface.cpp |
| 2 | ** |
| 3 | ** Copyright 2008, The Android Open Source Project |
| 4 | ** |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 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 |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 8 | ** |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 10 | ** |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 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 |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #define LOG_TAG "AudioFlingerDump" |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | #include <utils/Log.h> |
| 23 | |
| 24 | #include <stdlib.h> |
| 25 | #include <unistd.h> |
| 26 | |
| 27 | #include "AudioDumpInterface.h" |
| 28 | |
| 29 | namespace android { |
| 30 | |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 31 | bool gFirst = true; // true if first write after a standby |
| 32 | |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 33 | // ---------------------------------------------------------------------------- |
| 34 | |
| 35 | AudioDumpInterface::AudioDumpInterface(AudioHardwareInterface* hw) |
| 36 | { |
| 37 | if(hw == 0) { |
| 38 | LOGE("Dump construct hw = 0"); |
| 39 | } |
| 40 | mFinalInterface = hw; |
| 41 | mStreamOut = 0; |
| 42 | } |
| 43 | |
| 44 | |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 45 | AudioDumpInterface::~AudioDumpInterface() |
| 46 | { |
| 47 | if(mFinalInterface) delete mFinalInterface; |
| 48 | if(mStreamOut) delete mStreamOut; |
| 49 | } |
| 50 | |
| 51 | |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 52 | status_t AudioDumpInterface::standby() |
| 53 | { |
| 54 | if(mStreamOut) mStreamOut->Close(); |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 55 | gFirst = true; |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 56 | return mFinalInterface->standby(); |
| 57 | } |
| 58 | |
| 59 | |
| 60 | AudioStreamOut* AudioDumpInterface::openOutputStream( |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 61 | int format, int channelCount, uint32_t sampleRate, status_t *status) |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 62 | { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 63 | AudioStreamOut* outFinal = mFinalInterface->openOutputStream(format, channelCount, sampleRate, status); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 64 | |
| 65 | if(outFinal) { |
| 66 | mStreamOut = new AudioStreamOutDump(outFinal); |
| 67 | return mStreamOut; |
| 68 | } else { |
| 69 | LOGE("Dump outFinal=0"); |
| 70 | return 0; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | // ---------------------------------------------------------------------------- |
| 75 | |
| 76 | AudioStreamOutDump::AudioStreamOutDump( AudioStreamOut* finalStream) |
| 77 | { |
| 78 | mFinalStream = finalStream; |
| 79 | mOutFile = 0; |
| 80 | } |
| 81 | |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 82 | |
| 83 | AudioStreamOutDump::~AudioStreamOutDump() |
| 84 | { |
| 85 | Close(); |
| 86 | delete mFinalStream; |
| 87 | } |
| 88 | |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 89 | ssize_t AudioStreamOutDump::write(const void* buffer, size_t bytes) |
| 90 | { |
| 91 | ssize_t ret; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 92 | |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 93 | ret = mFinalStream->write(buffer, bytes); |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 94 | if(!mOutFile && gFirst) { |
| 95 | gFirst = false; |
| 96 | // check if dump file exist |
| 97 | mOutFile = fopen(FLINGER_DUMP_NAME, "r"); |
| 98 | if(mOutFile) { |
| 99 | fclose(mOutFile); |
| 100 | mOutFile = fopen(FLINGER_DUMP_NAME, "ab"); |
| 101 | } |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 102 | } |
| 103 | if (mOutFile) { |
| 104 | fwrite(buffer, bytes, 1, mOutFile); |
| 105 | } |
| 106 | return ret; |
| 107 | } |
| 108 | |
| 109 | void AudioStreamOutDump::Close(void) |
| 110 | { |
| 111 | if(mOutFile) { |
| 112 | fclose(mOutFile); |
| 113 | mOutFile = 0; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | }; // namespace android |