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 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 17 | #define LOG_TAG "AAudioService" |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 18 | //#define LOG_NDEBUG 0 |
| 19 | #include <utils/Log.h> |
| 20 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 21 | #include "IAAudioService.h" |
| 22 | #include "AAudioServiceDefinitions.h" |
| 23 | #include "AAudioServiceStreamBase.h" |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 24 | #include "AudioEndpointParcelable.h" |
| 25 | |
| 26 | using namespace android; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 27 | using namespace aaudio; |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * Construct the AudioCommandQueues and the AudioDataQueue |
| 31 | * and fill in the endpoint parcelable. |
| 32 | */ |
| 33 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 34 | AAudioServiceStreamBase::AAudioServiceStreamBase() |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 35 | : mUpMessageQueue(nullptr) |
| 36 | { |
| 37 | // TODO could fail so move out of constructor |
| 38 | mUpMessageQueue = new SharedRingBuffer(); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 39 | mUpMessageQueue->allocate(sizeof(AAudioServiceMessage), QUEUE_UP_CAPACITY_COMMANDS); |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 40 | } |
| 41 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 42 | AAudioServiceStreamBase::~AAudioServiceStreamBase() { |
Phil Burk | dec33ab | 2017-01-17 14:48:16 -0800 | [diff] [blame] | 43 | Mutex::Autolock _l(mLockUpMessageQueue); |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 44 | delete mUpMessageQueue; |
| 45 | } |
| 46 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 47 | void AAudioServiceStreamBase::sendServiceEvent(aaudio_service_event_t event, |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 48 | int32_t data1, |
| 49 | int64_t data2) { |
Phil Burk | dec33ab | 2017-01-17 14:48:16 -0800 | [diff] [blame] | 50 | |
| 51 | Mutex::Autolock _l(mLockUpMessageQueue); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 52 | AAudioServiceMessage command; |
| 53 | command.what = AAudioServiceMessage::code::EVENT; |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 54 | command.event.event = event; |
| 55 | command.event.data1 = data1; |
| 56 | command.event.data2 = data2; |
| 57 | mUpMessageQueue->getFifoBuffer()->write(&command, 1); |
| 58 | } |
| 59 | |
| 60 | |