blob: 39b952ac21c8e92ee890d6e00b884f2692a6b89f [file] [log] [blame]
Phil Burk2355edb2016-12-26 13:54:02 -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 OBOE_OBOE_SERVICE_STREAM_FAKE_HAL_H
18#define OBOE_OBOE_SERVICE_STREAM_FAKE_HAL_H
19
20#include "OboeService.h"
21#include "OboeServiceStreamBase.h"
22#include "FakeAudioHal.h"
23#include "MonotonicCounter.h"
24#include "AudioEndpointParcelable.h"
Phil Burkdec33ab2017-01-17 14:48:16 -080025#include "TimestampScheduler.h"
Phil Burk2355edb2016-12-26 13:54:02 -080026
27namespace oboe {
28
Phil Burkdec33ab2017-01-17 14:48:16 -080029class OboeServiceStreamFakeHal
30 : public OboeServiceStreamBase
31 , public Runnable {
Phil Burk2355edb2016-12-26 13:54:02 -080032
33public:
34 OboeServiceStreamFakeHal();
35 virtual ~OboeServiceStreamFakeHal();
36
37 virtual oboe_result_t getDescription(AudioEndpointParcelable &parcelable) override;
38
39 virtual oboe_result_t open(oboe::OboeStreamRequest &request,
40 oboe::OboeStreamConfiguration &configuration) override;
41
42 /**
43 * Start the flow of data.
44 */
45 virtual oboe_result_t start() override;
46
47 /**
48 * Stop the flow of data such that start() can resume with loss of data.
49 */
50 virtual oboe_result_t pause() override;
51
52 /**
53 * Discard any data held by the underlying HAL or Service.
54 */
55 virtual oboe_result_t flush() override;
56
57 virtual oboe_result_t close() override;
58
Phil Burk2355edb2016-12-26 13:54:02 -080059 void sendCurrentTimestamp();
60
Phil Burkdec33ab2017-01-17 14:48:16 -080061 virtual void run() override; // to implement Runnable
62
Phil Burk2355edb2016-12-26 13:54:02 -080063private:
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 oboe_stream_state_t mState = OBOE_STREAM_STATE_UNINITIALIZED;
Phil Burkdec33ab2017-01-17 14:48:16 -080072
73 OboeThread mOboeThread;
74 std::atomic<bool> mThreadEnabled;
Phil Burk2355edb2016-12-26 13:54:02 -080075};
76
77} // namespace oboe
78
79#endif //OBOE_OBOE_SERVICE_STREAM_FAKE_HAL_H