blob: 1de07cedd101c91308f01fa0f4aeb4146e0a024b [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
20#include <media/AudioTrack.h>
Phil Burk5ed503c2017-02-01 09:38:15 -080021#include <aaudio/AAudio.h>
Phil Burke1ce4912016-11-21 10:40:25 -080022
23#include "AudioStreamBuilder.h"
24#include "AudioStream.h"
Phil Burk5ed503c2017-02-01 09:38:15 -080025#include "AAudioLegacy.h"
Phil Burke1ce4912016-11-21 10:40:25 -080026
Phil Burk5ed503c2017-02-01 09:38:15 -080027namespace aaudio {
Phil Burke1ce4912016-11-21 10:40:25 -080028
29
30/**
31 * Internal stream that uses the legacy AudioTrack path.
32 */
33class AudioStreamTrack : public AudioStream {
34public:
35 AudioStreamTrack();
36
37 virtual ~AudioStreamTrack();
38
39
Phil Burk5ed503c2017-02-01 09:38:15 -080040 virtual aaudio_result_t open(const AudioStreamBuilder & builder) override;
41 virtual aaudio_result_t close() override;
Phil Burke1ce4912016-11-21 10:40:25 -080042
Phil Burk5ed503c2017-02-01 09:38:15 -080043 virtual aaudio_result_t requestStart() override;
44 virtual aaudio_result_t requestPause() override;
45 virtual aaudio_result_t requestFlush() override;
46 virtual aaudio_result_t requestStop() override;
Phil Burke1ce4912016-11-21 10:40:25 -080047
Phil Burk5ed503c2017-02-01 09:38:15 -080048 virtual aaudio_result_t getTimestamp(clockid_t clockId,
Phil Burk3316d5e2017-02-15 11:23:01 -080049 int64_t *framePosition,
50 int64_t *timeNanoseconds) override {
Phil Burk5ed503c2017-02-01 09:38:15 -080051 return AAUDIO_ERROR_UNIMPLEMENTED; // TODO call getTimestamp(ExtendedTimestamp *timestamp);
Phil Burke1ce4912016-11-21 10:40:25 -080052 }
53
Phil Burk5ed503c2017-02-01 09:38:15 -080054 virtual aaudio_result_t write(const void *buffer,
Phil Burk3316d5e2017-02-15 11:23:01 -080055 int32_t numFrames,
56 int64_t timeoutNanoseconds) override;
Phil Burke1ce4912016-11-21 10:40:25 -080057
Phil Burk3316d5e2017-02-15 11:23:01 -080058 virtual aaudio_result_t setBufferSize(int32_t requestedFrames) override;
59 virtual int32_t getBufferSize() const override;
60 virtual int32_t getBufferCapacity() const override;
61 virtual int32_t getFramesPerBurst()const override;
Phil Burke1ce4912016-11-21 10:40:25 -080062 virtual int32_t getXRunCount() const override;
63
Phil Burk3316d5e2017-02-15 11:23:01 -080064 virtual int64_t getFramesRead() override;
Phil Burke1ce4912016-11-21 10:40:25 -080065
Phil Burk5ed503c2017-02-01 09:38:15 -080066 virtual aaudio_result_t updateState() override;
Phil Burke1ce4912016-11-21 10:40:25 -080067
68private:
69 android::sp<android::AudioTrack> mAudioTrack;
70 // TODO add 64-bit position reporting to AudioRecord and use it.
Phil Burk3316d5e2017-02-15 11:23:01 -080071 aaudio_wrapping_frames_t mPositionWhenStarting = 0;
72 aaudio_wrapping_frames_t mPositionWhenPausing = 0;
Phil Burke1ce4912016-11-21 10:40:25 -080073};
74
Phil Burk5ed503c2017-02-01 09:38:15 -080075} /* namespace aaudio */
Phil Burke1ce4912016-11-21 10:40:25 -080076
Phil Burkdec33ab2017-01-17 14:48:16 -080077#endif /* LEGACY_AUDIO_STREAM_TRACK_H */