blob: b4940cb1e42d8455b8878ad28e318356304fb6c9 [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 -070052AudioStreamOut* AudioDumpInterface::openOutputStream(
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080053 int format, int channelCount, uint32_t sampleRate, status_t *status)
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070054{
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080055 AudioStreamOut* outFinal = mFinalInterface->openOutputStream(format, channelCount, sampleRate, status);
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070056
57 if(outFinal) {
58 mStreamOut = new AudioStreamOutDump(outFinal);
59 return mStreamOut;
60 } else {
61 LOGE("Dump outFinal=0");
62 return 0;
63 }
64}
65
66// ----------------------------------------------------------------------------
67
68AudioStreamOutDump::AudioStreamOutDump( AudioStreamOut* finalStream)
69{
70 mFinalStream = finalStream;
71 mOutFile = 0;
72}
73
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080074
75AudioStreamOutDump::~AudioStreamOutDump()
76{
77 Close();
78 delete mFinalStream;
79}
80
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070081ssize_t AudioStreamOutDump::write(const void* buffer, size_t bytes)
82{
83 ssize_t ret;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080084
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070085 ret = mFinalStream->write(buffer, bytes);
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080086 if(!mOutFile && gFirst) {
87 gFirst = false;
88 // check if dump file exist
89 mOutFile = fopen(FLINGER_DUMP_NAME, "r");
90 if(mOutFile) {
91 fclose(mOutFile);
92 mOutFile = fopen(FLINGER_DUMP_NAME, "ab");
93 }
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070094 }
95 if (mOutFile) {
96 fwrite(buffer, bytes, 1, mOutFile);
97 }
98 return ret;
99}
100
The Android Open Source Project27629322009-01-09 17:51:23 -0800101status_t AudioStreamOutDump::standby()
102{
103 Close();
104 gFirst = true;
105 return mFinalStream->standby();
106}
107
108
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700109void AudioStreamOutDump::Close(void)
110{
111 if(mOutFile) {
112 fclose(mOutFile);
113 mOutFile = 0;
114 }
115}
116
117}; // namespace android