blob: 8eee9cc525f68c1a103fdbc204ddad03ad6ceac1 [file] [log] [blame]
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -07001/* //device/servers/AudioFlinger/AudioDumpInterface.cpp
2**
3** Copyright 2008, The Android Open Source Project
4**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -08005** 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 Project7c1b96a2008-10-21 07:00:00 -07008**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -08009** http://www.apache.org/licenses/LICENSE-2.0
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070010**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080011** 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 Project7c1b96a2008-10-21 07:00:00 -070015** 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
29namespace android {
30
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080031bool gFirst = true; // true if first write after a standby
32
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070033// ----------------------------------------------------------------------------
34
35AudioDumpInterface::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 Projecte09fd9e2008-12-17 18:05:43 -080045AudioDumpInterface::~AudioDumpInterface()
46{
47 if(mFinalInterface) delete mFinalInterface;
48 if(mStreamOut) delete mStreamOut;
49}
50
51
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070052status_t AudioDumpInterface::standby()
53{
54 if(mStreamOut) mStreamOut->Close();
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080055 gFirst = true;
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070056 return mFinalInterface->standby();
57}
58
59
60AudioStreamOut* AudioDumpInterface::openOutputStream(
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080061 int format, int channelCount, uint32_t sampleRate, status_t *status)
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070062{
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080063 AudioStreamOut* outFinal = mFinalInterface->openOutputStream(format, channelCount, sampleRate, status);
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070064
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
76AudioStreamOutDump::AudioStreamOutDump( AudioStreamOut* finalStream)
77{
78 mFinalStream = finalStream;
79 mOutFile = 0;
80}
81
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080082
83AudioStreamOutDump::~AudioStreamOutDump()
84{
85 Close();
86 delete mFinalStream;
87}
88
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070089ssize_t AudioStreamOutDump::write(const void* buffer, size_t bytes)
90{
91 ssize_t ret;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080092
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070093 ret = mFinalStream->write(buffer, bytes);
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080094 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 Project7c1b96a2008-10-21 07:00:00 -0700102 }
103 if (mOutFile) {
104 fwrite(buffer, bytes, 1, mOutFile);
105 }
106 return ret;
107}
108
109void AudioStreamOutDump::Close(void)
110{
111 if(mOutFile) {
112 fclose(mOutFile);
113 mOutFile = 0;
114 }
115}
116
117}; // namespace android