blob: e6d8f0977c9947eedf39dbf4e4c3a5b3146541f8 [file] [log] [blame]
Phil Burk062e67a2015-02-11 13:40:50 -08001/*
2**
3** Copyright 2015, 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 "AudioFlinger"
19//#define LOG_NDEBUG 0
20
21#include <hardware/audio.h>
22#include <utils/Log.h>
23
24#include "AudioHwDevice.h"
25#include "AudioStreamOut.h"
26
27namespace android {
28
29// ----------------------------------------------------------------------------
30
31AudioStreamOut::AudioStreamOut(AudioHwDevice *dev, audio_output_flags_t flags)
32 : audioHwDev(dev)
33 , stream(NULL)
34 , flags(flags)
35{
36}
37
38audio_hw_device_t* AudioStreamOut::hwDev() const
39{
40 return audioHwDev->hwDevice();
41}
42
43status_t AudioStreamOut::getRenderPosition(uint32_t *frames)
44{
45 if (stream == NULL) {
46 return NO_INIT;
47 }
48 return stream->get_render_position(stream, frames);
49}
50
51status_t AudioStreamOut::getPresentationPosition(uint64_t *frames, struct timespec *timestamp)
52{
53 if (stream == NULL) {
54 return NO_INIT;
55 }
56 return stream->get_presentation_position(stream, frames, timestamp);
57}
58
59status_t AudioStreamOut::open(
60 audio_io_handle_t handle,
61 audio_devices_t devices,
62 struct audio_config *config,
63 const char *address)
64{
65 audio_stream_out_t* outStream;
66 int status = hwDev()->open_output_stream(
67 hwDev(),
68 handle,
69 devices,
70 flags,
71 config,
72 &outStream,
73 address);
74 ALOGV("AudioStreamOut::open(), HAL open_output_stream returned "
75 " %p, sampleRate %d, Format %#x, "
76 "channelMask %#x, status %d",
77 outStream,
78 config->sample_rate,
79 config->format,
80 config->channel_mask,
81 status);
82
83 if (status == NO_ERROR) {
84 stream = outStream;
85 }
86
87 return status;
88}
89
90size_t AudioStreamOut::getFrameSize()
91{
92 ALOG_ASSERT(stream != NULL);
93 return audio_stream_out_frame_size(stream);
94}
95
96int AudioStreamOut::flush()
97{
98 ALOG_ASSERT(stream != NULL);
99 if (stream->flush != NULL) {
100 return stream->flush(stream);
101 }
102 return NO_ERROR;
103}
104
105int AudioStreamOut::standby()
106{
107 ALOG_ASSERT(stream != NULL);
108 return stream->common.standby(&stream->common);
109}
110
111ssize_t AudioStreamOut::write(const void* buffer, size_t bytes)
112{
113 ALOG_ASSERT(stream != NULL);
114 return stream->write(stream, buffer, bytes);
115}
116
117} // namespace android