Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2015 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 #define LOG_TAG "VehicleNetworkAudioHelper-C"
     18 
     19 #include <VehicleNetwork.h>
     20 #include <vehicle-internal.h>
     21 #include <utils/SystemClock.h>
     22 #include "VehicleNetworkAudioHelper.h"
     23 #include "vehicle-network-audio-helper-for-c.h"
     24 
     25 extern "C" {
     26 
     27 vehicle_network_audio_helper_t* vehicle_network_audio_helper_create(nsecs_t timeout) {
     28     android::status_t r;
     29     android::VehicleNetworkAudioHelper* helperObj = new android::VehicleNetworkAudioHelper(timeout);
     30     if (helperObj == NULL) {
     31         return NULL;
     32     }
     33     vehicle_network_audio_helper_t *helper = new vehicle_network_audio_helper_t();
     34     if (helper == NULL) {
     35         goto error;
     36     }
     37     r = helperObj->init();
     38     if (r != android::NO_ERROR) {
     39         goto error;
     40     }
     41     helper->obj = helperObj;
     42     return helper;
     43 
     44 error:
     45     delete helperObj;
     46     return NULL;
     47 }
     48 
     49 vehicle_network_audio_helper_t* vehicle_network_audio_helper_create_with_default_timeout() {
     50     return vehicle_network_audio_helper_create(FOCUS_WAIT_DEFAULT_TIMEOUT_NS);
     51 }
     52 
     53 void vehicle_network_audio_helper_destroy(vehicle_network_audio_helper_t* helper) {
     54     android::VehicleNetworkAudioHelper* helperObj =
     55             (android::VehicleNetworkAudioHelper*) helper->obj;
     56     helperObj->release();
     57     delete helperObj;
     58     delete helper;
     59 }
     60 
     61 void vehicle_network_audio_helper_notify_stream_started(vehicle_network_audio_helper_t* helper,
     62         int32_t stream) {
     63     android::VehicleNetworkAudioHelper* helperObj =
     64             (android::VehicleNetworkAudioHelper*) helper->obj;
     65     helperObj->notifyStreamStarted(stream);
     66 }
     67 
     68 void vehicle_network_audio_helper_notify_stream_stopped(vehicle_network_audio_helper_t* helper,
     69         int32_t stream) {
     70     android::VehicleNetworkAudioHelper* helperObj =
     71             (android::VehicleNetworkAudioHelper*) helper->obj;
     72     helperObj->notifyStreamStopped(stream);
     73 }
     74 
     75 int vehicle_network_audio_helper_get_stream_focus_state(
     76         vehicle_network_audio_helper_t* helper, int32_t stream) {
     77     android::VehicleNetworkAudioHelper* helperObj =
     78             (android::VehicleNetworkAudioHelper*) helper->obj;
     79     return helperObj->getStreamFocusState(stream);
     80 }
     81 
     82 int vehicle_network_audio_helper_wait_for_stream_focus(vehicle_network_audio_helper_t* helper,
     83         int32_t stream, nsecs_t waitTimeNs) {
     84     android::VehicleNetworkAudioHelper* helperObj =
     85             (android::VehicleNetworkAudioHelper*) helper->obj;
     86     if (helperObj->waitForStreamFocus(stream, waitTimeNs)) {
     87         return 1;
     88     }
     89     return 0;
     90 }
     91 
     92 }
     93