blob: 0c4133158cd75aa673277dd71bbc427c7150f718 [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>
21#include <oboe/OboeAudio.h>
22
23#include "AudioStreamBuilder.h"
24#include "AudioStream.h"
25#include "OboeLegacy.h"
26
27namespace oboe {
28
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
40 virtual oboe_result_t open(const AudioStreamBuilder & builder) override;
41 virtual oboe_result_t close() override;
42
43 virtual oboe_result_t requestStart() override;
44 virtual oboe_result_t requestPause() override;
45 virtual oboe_result_t requestFlush() override;
46 virtual oboe_result_t requestStop() override;
47
48 virtual oboe_result_t getTimestamp(clockid_t clockId,
49 oboe_position_frames_t *framePosition,
50 oboe_nanoseconds_t *timeNanoseconds) override {
51 return OBOE_ERROR_UNIMPLEMENTED; // TODO call getTimestamp(ExtendedTimestamp *timestamp);
52 }
53
54 virtual oboe_result_t write(const void *buffer,
55 oboe_size_frames_t numFrames,
56 oboe_nanoseconds_t timeoutNanoseconds) override;
57
58 virtual oboe_result_t setBufferSize(oboe_size_frames_t requestedFrames,
59 oboe_size_frames_t *actualFrames) override;
60 virtual oboe_size_frames_t getBufferSize() const override;
61 virtual oboe_size_frames_t getBufferCapacity() const override;
62 virtual oboe_size_frames_t getFramesPerBurst()const override;
63 virtual int32_t getXRunCount() const override;
64
65 virtual oboe_position_frames_t getFramesRead() override;
66
67 virtual oboe_result_t updateState() override;
68
69private:
70 android::sp<android::AudioTrack> mAudioTrack;
71 // TODO add 64-bit position reporting to AudioRecord and use it.
72 oboe_wrapping_frames_t mPositionWhenStarting = 0;
73 oboe_wrapping_frames_t mPositionWhenPausing = 0;
74};
75
76} /* namespace oboe */
77
Phil Burkdec33ab2017-01-17 14:48:16 -080078#endif /* LEGACY_AUDIO_STREAM_TRACK_H */