blob: f604871f22c5df5db8eda30b5f2f2e4eff518560 [file] [log] [blame]
Phil Burke1ce4912016-11-21 10:40:25 -08001/*
2 * Copyright 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Phil Burkdec33ab2017-01-17 14:48:16 -080017#ifndef LEGACY_AUDIO_STREAM_TRACK_H
18#define LEGACY_AUDIO_STREAM_TRACK_H
Phil Burke1ce4912016-11-21 10:40:25 -080019
Phil Burke4d7bb42017-03-28 11:32:39 -070020#include <math.h>
Eric Laurent1d32e9f2017-06-02 14:01:32 -070021#include <media/TrackPlayerBase.h>
Phil Burk965650e2017-09-07 21:00:09 -070022#include <media/AudioTrack.h>
Phil Burk5ed503c2017-02-01 09:38:15 -080023#include <aaudio/AAudio.h>
Phil Burke1ce4912016-11-21 10:40:25 -080024
25#include "AudioStreamBuilder.h"
26#include "AudioStream.h"
Phil Burke4d7bb42017-03-28 11:32:39 -070027#include "legacy/AAudioLegacy.h"
28#include "legacy/AudioStreamLegacy.h"
29#include "utility/FixedBlockReader.h"
Phil Burke1ce4912016-11-21 10:40:25 -080030
Phil Burk5ed503c2017-02-01 09:38:15 -080031namespace aaudio {
Phil Burke1ce4912016-11-21 10:40:25 -080032
Phil Burke1ce4912016-11-21 10:40:25 -080033/**
34 * Internal stream that uses the legacy AudioTrack path.
35 */
Phil Burk965650e2017-09-07 21:00:09 -070036class AudioStreamTrack : public AudioStreamLegacy {
Phil Burke1ce4912016-11-21 10:40:25 -080037public:
38 AudioStreamTrack();
39
40 virtual ~AudioStreamTrack();
41
42
Phil Burke4d7bb42017-03-28 11:32:39 -070043 aaudio_result_t open(const AudioStreamBuilder & builder) override;
Phil Burk8b4e05e2019-12-17 12:12:09 -080044 aaudio_result_t release_l() override;
Phil Burk320910f2020-08-12 14:29:10 +000045 void close_l() override;
Phil Burke1ce4912016-11-21 10:40:25 -080046
Phil Burk0bd745e2020-10-17 18:20:01 +000047protected:
48 aaudio_result_t requestStart_l() REQUIRES(mStreamLock) override;
49 aaudio_result_t requestPause_l() REQUIRES(mStreamLock) override;
50 aaudio_result_t requestFlush_l() REQUIRES(mStreamLock) override;
51 aaudio_result_t requestStop_l() REQUIRES(mStreamLock) override;
Phil Burke1ce4912016-11-21 10:40:25 -080052
Phil Burk0bd745e2020-10-17 18:20:01 +000053public:
Phil Burk5cc83c32017-11-28 15:43:18 -080054 bool isFlushSupported() const override {
55 // Only implement FLUSH for OUTPUT streams.
56 return true;
57 }
58
59 bool isPauseSupported() const override {
60 // Only implement PAUSE for OUTPUT streams.
61 return true;
62 }
63
Phil Burke4d7bb42017-03-28 11:32:39 -070064 aaudio_result_t getTimestamp(clockid_t clockId,
Phil Burk3316d5e2017-02-15 11:23:01 -080065 int64_t *framePosition,
Phil Burk35e80f32017-03-28 10:25:21 -070066 int64_t *timeNanoseconds) override;
Phil Burke1ce4912016-11-21 10:40:25 -080067
Phil Burke4d7bb42017-03-28 11:32:39 -070068 aaudio_result_t write(const void *buffer,
Phil Burk3316d5e2017-02-15 11:23:01 -080069 int32_t numFrames,
70 int64_t timeoutNanoseconds) override;
Phil Burke1ce4912016-11-21 10:40:25 -080071
Phil Burke4d7bb42017-03-28 11:32:39 -070072 aaudio_result_t setBufferSize(int32_t requestedFrames) override;
73 int32_t getBufferSize() const override;
Phil Burke4d7bb42017-03-28 11:32:39 -070074 int32_t getXRunCount() const override;
Phil Burke1ce4912016-11-21 10:40:25 -080075
Phil Burke4d7bb42017-03-28 11:32:39 -070076 int64_t getFramesRead() override;
Phil Burke1ce4912016-11-21 10:40:25 -080077
Phil Burk87c9f642017-05-17 07:22:39 -070078 aaudio_direction_t getDirection() const override {
79 return AAUDIO_DIRECTION_OUTPUT;
80 }
81
Phil Burk0befec62017-07-28 15:12:13 -070082 aaudio_result_t updateStateMachine() override;
Phil Burke4d7bb42017-03-28 11:32:39 -070083
84 // This is public so it can be called from the C callback function.
85 void processCallback(int event, void *info) override;
Phil Burke1ce4912016-11-21 10:40:25 -080086
Phil Burk4c5129b2017-04-28 15:17:32 -070087 int64_t incrementClientFrameCounter(int32_t frames) override {
88 return incrementFramesWritten(frames);
89 }
90
Phil Burk965650e2017-09-07 21:00:09 -070091 android::status_t doSetVolume() override;
92
93#if AAUDIO_USE_VOLUME_SHAPER
94 virtual android::binder::Status applyVolumeShaper(
95 const android::media::VolumeShaper::Configuration& configuration,
96 const android::media::VolumeShaper::Operation& operation) override;
97#endif
98
Phil Burk8d97b8e2020-09-25 23:18:14 +000099protected:
100
101 int32_t getFramesPerBurstFromDevice() const override;
102 int32_t getBufferCapacityFromDevice() const override;
103
Phil Burke1ce4912016-11-21 10:40:25 -0800104private:
Phil Burke4d7bb42017-03-28 11:32:39 -0700105
Phil Burk965650e2017-09-07 21:00:09 -0700106 android::sp<android::AudioTrack> mAudioTrack;
107
Phil Burke4d7bb42017-03-28 11:32:39 -0700108 // adapts between variable sized blocks and fixed size blocks
109 FixedBlockReader mFixedBlockReader;
110
Phil Burk0befec62017-07-28 15:12:13 -0700111 // TODO add 64-bit position reporting to AudioTrack and use it.
Phil Burk3316d5e2017-02-15 11:23:01 -0800112 aaudio_wrapping_frames_t mPositionWhenPausing = 0;
Phil Burke1ce4912016-11-21 10:40:25 -0800113};
114
Phil Burk5ed503c2017-02-01 09:38:15 -0800115} /* namespace aaudio */
Phil Burke1ce4912016-11-21 10:40:25 -0800116
Phil Burkdec33ab2017-01-17 14:48:16 -0800117#endif /* LEGACY_AUDIO_STREAM_TRACK_H */