blob: 5ff2f18b2738f91bf9f7f9178d32c13722bbf5a3 [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**
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#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
31// ----------------------------------------------------------------------------
32
33AudioDumpInterface::AudioDumpInterface(AudioHardwareInterface* hw)
34{
35 if(hw == 0) {
36 LOGE("Dump construct hw = 0");
37 }
38 mFinalInterface = hw;
39 mStreamOut = 0;
40}
41
42
43status_t AudioDumpInterface::standby()
44{
45 if(mStreamOut) mStreamOut->Close();
46 return mFinalInterface->standby();
47}
48
49
50AudioStreamOut* AudioDumpInterface::openOutputStream(
51 int format, int channelCount, uint32_t sampleRate)
52{
53 AudioStreamOut* outFinal = mFinalInterface->openOutputStream(format, channelCount, sampleRate);
54
55 if(outFinal) {
56 mStreamOut = new AudioStreamOutDump(outFinal);
57 return mStreamOut;
58 } else {
59 LOGE("Dump outFinal=0");
60 return 0;
61 }
62}
63
64// ----------------------------------------------------------------------------
65
66AudioStreamOutDump::AudioStreamOutDump( AudioStreamOut* finalStream)
67{
68 mFinalStream = finalStream;
69 mOutFile = 0;
70}
71
72ssize_t AudioStreamOutDump::write(const void* buffer, size_t bytes)
73{
74 ssize_t ret;
75
76 ret = mFinalStream->write(buffer, bytes);
77 if(!mOutFile) {
78 mOutFile = fopen(FLINGER_DUMP_NAME, "ab");
79 }
80 if (mOutFile) {
81 fwrite(buffer, bytes, 1, mOutFile);
82 }
83 return ret;
84}
85
86void AudioStreamOutDump::Close(void)
87{
88 if(mOutFile) {
89 fclose(mOutFile);
90 mOutFile = 0;
91 }
92}
93
94}; // namespace android