Jitendra Naruka | 1b6513f | 2014-11-22 19:34:13 -0800 | [diff] [blame] | 1 | /*Copyright (C) 2014 The Android Open Source Project |
| 2 | * |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | * This file was modified by DTS, Inc. The portions of the |
| 15 | * code modified by DTS, Inc are copyrighted and |
| 16 | * licensed separately, as follows: |
| 17 | * |
| 18 | * (C) 2014 DTS, Inc. |
| 19 | * |
| 20 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 21 | * you may not use this file except in compliance with the License. |
| 22 | * You may obtain a copy of the License at |
| 23 | * |
| 24 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 25 | * |
| 26 | * Unless required by applicable law or agreed to in writing, software |
| 27 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 29 | * See the License for the specific language governing permissions and |
| 30 | * limitations under the License. |
| 31 | */ |
| 32 | |
| 33 | #define LOG_TAG "AudioUtil" |
| 34 | //#define LOG_NDEBUG 0 |
| 35 | #include <utils/Log.h> |
| 36 | #include <stdlib.h> |
| 37 | |
| 38 | #include <cutils/properties.h> |
| 39 | #include <fcntl.h> |
| 40 | #include <sys/ioctl.h> |
| 41 | #include <sys/stat.h> |
| 42 | #include <sound/devdep_params.h> |
| 43 | #include <sound/asound.h> |
| 44 | #include "AudioUtil.h" |
| 45 | |
| 46 | #define ROUTE_PATH "/data/data/dts/route" |
| 47 | #define DEVICE_NODE "/dev/snd/hwC0D3" |
| 48 | |
| 49 | static int32_t mDevices = 0; |
| 50 | static int32_t mCurrDevice = 0; |
| 51 | |
| 52 | void create_route_node(void) |
| 53 | { |
| 54 | char prop[PROPERTY_VALUE_MAX] = "true"; |
| 55 | int fd; |
| 56 | property_get("use.dts_eagle", prop, "0"); |
| 57 | if (!strncmp("true", prop, sizeof("true")) || atoi(prop)) { |
| 58 | ALOGV("create_route_node"); |
| 59 | if ((fd=open(ROUTE_PATH, O_RDONLY)) < 0) { |
| 60 | ALOGV("No File exisit"); |
| 61 | } else { |
| 62 | ALOGV("A file with the same name exist. Remove it before creating it"); |
| 63 | close(fd); |
| 64 | remove(ROUTE_PATH); |
| 65 | } |
| 66 | if ((fd=creat(ROUTE_PATH, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0) { |
| 67 | ALOGE("opening route node failed returned"); |
| 68 | return; |
| 69 | } |
| 70 | chmod(ROUTE_PATH, S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH); |
| 71 | ALOGV("opening route node successful"); |
| 72 | close(fd); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | void notify_route_node(int active_device, int devices) |
| 77 | { |
| 78 | char prop[PROPERTY_VALUE_MAX] = "true"; |
| 79 | char buf[1024]; |
| 80 | int fd; |
| 81 | if ((mCurrDevice == active_device) && |
| 82 | (mDevices == devices)) { |
| 83 | ALOGV("nothing to update to route node"); |
| 84 | return; |
| 85 | } |
| 86 | mDevices = devices; |
| 87 | mCurrDevice = active_device; |
| 88 | property_get("use.dts_eagle", prop, "0"); |
| 89 | if (!strncmp("true", prop, sizeof("true")) || atoi(prop)) { |
| 90 | ALOGV("notify active device : %d all_devices : %d", active_device, devices); |
| 91 | if ((fd=open(ROUTE_PATH, O_TRUNC|O_WRONLY)) < 0) { |
| 92 | ALOGV("Write device to route node failed"); |
| 93 | } else { |
| 94 | ALOGV("Write device to route node successful"); |
| 95 | snprintf(buf, sizeof(buf), "device=%d;all_devices=%d", active_device, devices); |
| 96 | int n = write(fd, buf, strlen(buf)); |
| 97 | ALOGV("number of bytes written: %d", n); |
| 98 | close(fd); |
| 99 | } |
| 100 | int eaglefd = open(DEVICE_NODE, O_RDWR); |
| 101 | int32_t params[2] = {active_device, 1 /*is primary device*/}; |
| 102 | if (eaglefd > 0) { |
| 103 | if(ioctl(eaglefd, DTS_EAGLE_IOCTL_SET_ACTIVE_DEVICE, ¶ms) < 0) { |
| 104 | ALOGE("DTS_EAGLE (%s): error sending primary device\n", __func__); |
| 105 | } |
| 106 | ALOGD("DTS_EAGLE (%s): sent primary device\n", __func__); |
| 107 | close(eaglefd); |
| 108 | } else { |
| 109 | ALOGE("DTS_EAGLE (%s): error opening eagle\n", __func__); |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | void remove_route_node(void) |
| 115 | { |
| 116 | char prop[PROPERTY_VALUE_MAX] = "true"; |
| 117 | int fd; |
| 118 | property_get("use.dts_eagle", prop, "0"); |
| 119 | if (!strncmp("true", prop, sizeof("true")) || atoi(prop)) { |
| 120 | ALOGV("remove_route_node"); |
| 121 | if ((fd=open(ROUTE_PATH, O_RDONLY)) < 0) { |
| 122 | ALOGV("open route node failed"); |
| 123 | } else { |
| 124 | ALOGV("open route node successful"); |
| 125 | ALOGV("Remove the file"); |
| 126 | close(fd); |
| 127 | remove(ROUTE_PATH); |
| 128 | } |
| 129 | } |
| 130 | } |