blob: e9480fb9dacf54ab4d92e9a77669ec7b13088eda [file] [log] [blame]
Phil Burk5ed503c2017-02-01 09:38:15 -08001/*
2 * Copyright (C) 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
17#ifndef AAUDIO_AAUDIO_SERVICE_STREAM_FAKE_HAL_H
18#define AAUDIO_AAUDIO_SERVICE_STREAM_FAKE_HAL_H
19
20#include "AAudioServiceDefinitions.h"
21#include "AAudioServiceStreamBase.h"
22#include "FakeAudioHal.h"
23#include "MonotonicCounter.h"
24#include "AudioEndpointParcelable.h"
25#include "TimestampScheduler.h"
26
27namespace aaudio {
28
29class AAudioServiceStreamFakeHal
30 : public AAudioServiceStreamBase
31 , public Runnable {
32
33public:
34 AAudioServiceStreamFakeHal();
35 virtual ~AAudioServiceStreamFakeHal();
36
37 virtual aaudio_result_t getDescription(AudioEndpointParcelable &parcelable) override;
38
39 virtual aaudio_result_t open(aaudio::AAudioStreamRequest &request,
Phil Burk3df348f2017-02-08 11:41:55 -080040 aaudio::AAudioStreamConfiguration &configurationOutput) override;
Phil Burk5ed503c2017-02-01 09:38:15 -080041
42 /**
43 * Start the flow of data.
44 */
45 virtual aaudio_result_t start() override;
46
47 /**
48 * Stop the flow of data such that start() can resume with loss of data.
49 */
50 virtual aaudio_result_t pause() override;
51
52 /**
53 * Discard any data held by the underlying HAL or Service.
54 */
55 virtual aaudio_result_t flush() override;
56
57 virtual aaudio_result_t close() override;
58
59 void sendCurrentTimestamp();
60
61 virtual void run() override; // to implement Runnable
62
63private:
64 fake_hal_stream_ptr mStreamId; // Move to HAL
65
66 MonotonicCounter mFramesWritten;
67 MonotonicCounter mFramesRead;
68 int mHalFileDescriptor = -1;
69 int mPreviousFrameCounter = 0; // from HAL
70
71 aaudio_stream_state_t mState = AAUDIO_STREAM_STATE_UNINITIALIZED;
72
73 AAudioThread mAAudioThread;
74 std::atomic<bool> mThreadEnabled;
75};
76
77} // namespace aaudio
78
79#endif //AAUDIO_AAUDIO_SERVICE_STREAM_FAKE_HAL_H