blob: 736c754a15466a72ca0e42613537671a903ce680 [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
20#include "IOboeAudioService.h"
21#include "OboeService.h"
22#include "AudioStream.h"
23#include "fifo/FifoBuffer.h"
24#include "SharedRingBuffer.h"
25#include "AudioEndpointParcelable.h"
26
27namespace oboe {
28
29// We expect the queue to only have a few commands.
30// This should be way more than we need.
31#define QUEUE_UP_CAPACITY_COMMANDS (128)
32
33class OboeServiceStreamBase {
34
35public:
36 OboeServiceStreamBase();
37 virtual ~OboeServiceStreamBase();
38
39 enum {
40 ILLEGAL_THREAD_ID = 0
41 };
42
43 /**
44 * Fill in a parcelable description of stream.
45 */
46 virtual oboe_result_t getDescription(oboe::AudioEndpointParcelable &parcelable) = 0;
47
48 /**
49 * Open the device.
50 */
51 virtual oboe_result_t open(oboe::OboeStreamRequest &request,
52 oboe::OboeStreamConfiguration &configuration) = 0;
53
54 /**
55 * Start the flow of data.
56 */
57 virtual oboe_result_t start() = 0;
58
59 /**
60 * Stop the flow of data such that start() can resume with loss of data.
61 */
62 virtual oboe_result_t pause() = 0;
63
64 /**
65 * Discard any data held by the underlying HAL or Service.
66 */
67 virtual oboe_result_t flush() = 0;
68
69 virtual oboe_result_t close() = 0;
70
71 virtual void tickle() = 0;
72
73 virtual void sendServiceEvent(oboe_service_event_t event,
74 int32_t data1 = 0,
75 int64_t data2 = 0);
76
77 virtual void setRegisteredThread(pid_t pid) {
78 mRegisteredClientThread = pid;
79 }
80 virtual pid_t getRegisteredThread() {
81 return mRegisteredClientThread;
82 }
83
84protected:
85
86 pid_t mRegisteredClientThread = ILLEGAL_THREAD_ID;
87
88 SharedRingBuffer * mUpMessageQueue;
89
90 oboe_sample_rate_t mSampleRate = 0;
91 oboe_size_bytes_t mBytesPerFrame = 0;
92 oboe_size_frames_t mFramesPerBurst = 0;
93 oboe_size_frames_t mCapacityInFrames = 0;
94 oboe_size_bytes_t mCapacityInBytes = 0;
95};
96
97} /* namespace oboe */
98
99#endif //OBOE_OBOE_SERVICE_STREAM_BASE_H