Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 1 | /* |
| 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 Burk | dec33ab | 2017-01-17 14:48:16 -0800 | [diff] [blame^] | 25 | #include "TimestampScheduler.h" |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 26 | |
| 27 | namespace oboe { |
| 28 | |
Phil Burk | dec33ab | 2017-01-17 14:48:16 -0800 | [diff] [blame^] | 29 | class OboeServiceStreamFakeHal |
| 30 | : public OboeServiceStreamBase |
| 31 | , public Runnable { |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 32 | |
| 33 | public: |
| 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 Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 59 | void sendCurrentTimestamp(); |
| 60 | |
Phil Burk | dec33ab | 2017-01-17 14:48:16 -0800 | [diff] [blame^] | 61 | virtual void run() override; // to implement Runnable |
| 62 | |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 63 | private: |
| 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 Burk | dec33ab | 2017-01-17 14:48:16 -0800 | [diff] [blame^] | 72 | |
| 73 | OboeThread mOboeThread; |
| 74 | std::atomic<bool> mThreadEnabled; |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | } // namespace oboe |
| 78 | |
| 79 | #endif //OBOE_OBOE_SERVICE_STREAM_FAKE_HAL_H |