blob: a7938dc02bb626749d198f8be3ecc2a0f0fec0ed [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
Phil Burk5ed503c2017-02-01 09:38:15 -080017#define LOG_TAG "AAudioService"
Phil Burk2355edb2016-12-26 13:54:02 -080018//#define LOG_NDEBUG 0
19#include <utils/Log.h>
20
Phil Burk5ed503c2017-02-01 09:38:15 -080021#include "IAAudioService.h"
22#include "AAudioServiceDefinitions.h"
23#include "AAudioServiceStreamBase.h"
Phil Burk2355edb2016-12-26 13:54:02 -080024#include "AudioEndpointParcelable.h"
25
26using namespace android;
Phil Burk5ed503c2017-02-01 09:38:15 -080027using namespace aaudio;
Phil Burk2355edb2016-12-26 13:54:02 -080028
29/**
30 * Construct the AudioCommandQueues and the AudioDataQueue
31 * and fill in the endpoint parcelable.
32 */
33
Phil Burk5ed503c2017-02-01 09:38:15 -080034AAudioServiceStreamBase::AAudioServiceStreamBase()
Phil Burk2355edb2016-12-26 13:54:02 -080035 : mUpMessageQueue(nullptr)
36{
37 // TODO could fail so move out of constructor
38 mUpMessageQueue = new SharedRingBuffer();
Phil Burk5ed503c2017-02-01 09:38:15 -080039 mUpMessageQueue->allocate(sizeof(AAudioServiceMessage), QUEUE_UP_CAPACITY_COMMANDS);
Phil Burk2355edb2016-12-26 13:54:02 -080040}
41
Phil Burk5ed503c2017-02-01 09:38:15 -080042AAudioServiceStreamBase::~AAudioServiceStreamBase() {
Phil Burkdec33ab2017-01-17 14:48:16 -080043 Mutex::Autolock _l(mLockUpMessageQueue);
Phil Burk2355edb2016-12-26 13:54:02 -080044 delete mUpMessageQueue;
45}
46
Phil Burk5ed503c2017-02-01 09:38:15 -080047void AAudioServiceStreamBase::sendServiceEvent(aaudio_service_event_t event,
Phil Burk2355edb2016-12-26 13:54:02 -080048 int32_t data1,
49 int64_t data2) {
Phil Burkdec33ab2017-01-17 14:48:16 -080050
51 Mutex::Autolock _l(mLockUpMessageQueue);
Phil Burk5ed503c2017-02-01 09:38:15 -080052 AAudioServiceMessage command;
53 command.what = AAudioServiceMessage::code::EVENT;
Phil Burk2355edb2016-12-26 13:54:02 -080054 command.event.event = event;
55 command.event.data1 = data1;
56 command.event.data2 = data2;
57 mUpMessageQueue->getFifoBuffer()->write(&command, 1);
58}
59
60