blob: 33857c6eee0e36de39eccf1fdf40f833e4eef64f [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_BASE_H
18#define OBOE_OBOE_SERVICE_STREAM_BASE_H
19
Phil Burkdec33ab2017-01-17 14:48:16 -080020#include <utils/Mutex.h>
21
Phil Burk2355edb2016-12-26 13:54:02 -080022#include "IOboeAudioService.h"
23#include "OboeService.h"
Phil Burk2355edb2016-12-26 13:54:02 -080024#include "fifo/FifoBuffer.h"
25#include "SharedRingBuffer.h"
26#include "AudioEndpointParcelable.h"
Phil Burkdec33ab2017-01-17 14:48:16 -080027#include "OboeThread.h"
Phil Burk2355edb2016-12-26 13:54:02 -080028
29namespace oboe {
30
31// We expect the queue to only have a few commands.
32// This should be way more than we need.
33#define QUEUE_UP_CAPACITY_COMMANDS (128)
34
Phil Burkdec33ab2017-01-17 14:48:16 -080035class OboeServiceStreamBase {
Phil Burk2355edb2016-12-26 13:54:02 -080036
37public:
38 OboeServiceStreamBase();
39 virtual ~OboeServiceStreamBase();
40
41 enum {
42 ILLEGAL_THREAD_ID = 0
43 };
44
45 /**
46 * Fill in a parcelable description of stream.
47 */
48 virtual oboe_result_t getDescription(oboe::AudioEndpointParcelable &parcelable) = 0;
49
50 /**
51 * Open the device.
52 */
53 virtual oboe_result_t open(oboe::OboeStreamRequest &request,
54 oboe::OboeStreamConfiguration &configuration) = 0;
55
56 /**
57 * Start the flow of data.
58 */
59 virtual oboe_result_t start() = 0;
60
61 /**
62 * Stop the flow of data such that start() can resume with loss of data.
63 */
64 virtual oboe_result_t pause() = 0;
65
66 /**
67 * Discard any data held by the underlying HAL or Service.
68 */
69 virtual oboe_result_t flush() = 0;
70
71 virtual oboe_result_t close() = 0;
72
Phil Burkdec33ab2017-01-17 14:48:16 -080073 virtual void sendCurrentTimestamp() = 0;
74
75 oboe_size_frames_t getFramesPerBurst() {
76 return mFramesPerBurst;
77 }
Phil Burk2355edb2016-12-26 13:54:02 -080078
79 virtual void sendServiceEvent(oboe_service_event_t event,
80 int32_t data1 = 0,
81 int64_t data2 = 0);
82
83 virtual void setRegisteredThread(pid_t pid) {
84 mRegisteredClientThread = pid;
85 }
Phil Burkdec33ab2017-01-17 14:48:16 -080086
Phil Burk2355edb2016-12-26 13:54:02 -080087 virtual pid_t getRegisteredThread() {
88 return mRegisteredClientThread;
89 }
90
91protected:
92
93 pid_t mRegisteredClientThread = ILLEGAL_THREAD_ID;
94
95 SharedRingBuffer * mUpMessageQueue;
96
97 oboe_sample_rate_t mSampleRate = 0;
98 oboe_size_bytes_t mBytesPerFrame = 0;
99 oboe_size_frames_t mFramesPerBurst = 0;
100 oboe_size_frames_t mCapacityInFrames = 0;
101 oboe_size_bytes_t mCapacityInBytes = 0;
Phil Burkdec33ab2017-01-17 14:48:16 -0800102
103 android::Mutex mLockUpMessageQueue;
Phil Burk2355edb2016-12-26 13:54:02 -0800104};
105
106} /* namespace oboe */
107
108#endif //OBOE_OBOE_SERVICE_STREAM_BASE_H