Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 1 | /* |
| 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 Burk | dec33ab | 2017-01-17 14:48:16 -0800 | [diff] [blame] | 17 | #ifndef LEGACY_AUDIO_STREAM_TRACK_H |
| 18 | #define LEGACY_AUDIO_STREAM_TRACK_H |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 19 | |
| 20 | #include <media/AudioTrack.h> |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 21 | #include <aaudio/AAudio.h> |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 22 | |
| 23 | #include "AudioStreamBuilder.h" |
| 24 | #include "AudioStream.h" |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 25 | #include "AAudioLegacy.h" |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 26 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 27 | namespace aaudio { |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 28 | |
| 29 | |
| 30 | /** |
| 31 | * Internal stream that uses the legacy AudioTrack path. |
| 32 | */ |
| 33 | class AudioStreamTrack : public AudioStream { |
| 34 | public: |
| 35 | AudioStreamTrack(); |
| 36 | |
| 37 | virtual ~AudioStreamTrack(); |
| 38 | |
| 39 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 40 | virtual aaudio_result_t open(const AudioStreamBuilder & builder) override; |
| 41 | virtual aaudio_result_t close() override; |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 42 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 43 | 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 Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 47 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 48 | virtual aaudio_result_t getTimestamp(clockid_t clockId, |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 49 | int64_t *framePosition, |
Phil Burk | 35e80f3 | 2017-03-28 10:25:21 -0700 | [diff] [blame^] | 50 | int64_t *timeNanoseconds) override; |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 51 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 52 | virtual aaudio_result_t write(const void *buffer, |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 53 | int32_t numFrames, |
| 54 | int64_t timeoutNanoseconds) override; |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 55 | |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 56 | virtual aaudio_result_t setBufferSize(int32_t requestedFrames) override; |
| 57 | virtual int32_t getBufferSize() const override; |
| 58 | virtual int32_t getBufferCapacity() const override; |
| 59 | virtual int32_t getFramesPerBurst()const override; |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 60 | virtual int32_t getXRunCount() const override; |
| 61 | |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 62 | virtual int64_t getFramesRead() override; |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 63 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 64 | virtual aaudio_result_t updateState() override; |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 65 | |
| 66 | private: |
| 67 | android::sp<android::AudioTrack> mAudioTrack; |
| 68 | // TODO add 64-bit position reporting to AudioRecord and use it. |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 69 | aaudio_wrapping_frames_t mPositionWhenStarting = 0; |
| 70 | aaudio_wrapping_frames_t mPositionWhenPausing = 0; |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 71 | }; |
| 72 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 73 | } /* namespace aaudio */ |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 74 | |
Phil Burk | dec33ab | 2017-01-17 14:48:16 -0800 | [diff] [blame] | 75 | #endif /* LEGACY_AUDIO_STREAM_TRACK_H */ |