Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | package com.android.server.tv; |
| 18 | |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 19 | import static android.media.tv.TvInputManager.INPUT_STATE_CONNECTED; |
| 20 | import static android.media.tv.TvInputManager.INPUT_STATE_DISCONNECTED; |
| 21 | |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 22 | import android.content.BroadcastReceiver; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 23 | import android.content.Context; |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 24 | import android.content.Intent; |
| 25 | import android.content.IntentFilter; |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 26 | import android.hardware.hdmi.HdmiControlManager; |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 27 | import android.hardware.hdmi.HdmiDeviceInfo; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 28 | import android.hardware.hdmi.HdmiHotplugEvent; |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 29 | import android.hardware.hdmi.IHdmiControlService; |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 30 | import android.hardware.hdmi.IHdmiDeviceEventListener; |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 31 | import android.hardware.hdmi.IHdmiHotplugEventListener; |
Jungshik Jang | 1f819bb | 2014-08-08 10:46:54 +0900 | [diff] [blame] | 32 | import android.hardware.hdmi.IHdmiSystemAudioModeChangeListener; |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 33 | import android.media.AudioDevicePort; |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 34 | import android.media.AudioFormat; |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 35 | import android.media.AudioGain; |
| 36 | import android.media.AudioGainConfig; |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 37 | import android.media.AudioManager; |
| 38 | import android.media.AudioPatch; |
| 39 | import android.media.AudioPort; |
| 40 | import android.media.AudioPortConfig; |
Jae Seo | d5cc4a2 | 2014-05-30 16:57:43 -0700 | [diff] [blame] | 41 | import android.media.tv.ITvInputHardware; |
| 42 | import android.media.tv.ITvInputHardwareCallback; |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 43 | import android.media.tv.TvInputHardwareInfo; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 44 | import android.media.tv.TvInputInfo; |
Jae Seo | d5cc4a2 | 2014-05-30 16:57:43 -0700 | [diff] [blame] | 45 | import android.media.tv.TvStreamConfig; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 46 | import android.os.Handler; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 47 | import android.os.IBinder; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 48 | import android.os.Message; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 49 | import android.os.RemoteException; |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 50 | import android.os.ServiceManager; |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 51 | import android.util.ArrayMap; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 52 | import android.util.Slog; |
| 53 | import android.util.SparseArray; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 54 | import android.util.SparseBooleanArray; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 55 | import android.view.KeyEvent; |
| 56 | import android.view.Surface; |
| 57 | |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 58 | import com.android.server.SystemService; |
| 59 | |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 60 | import java.util.ArrayList; |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 61 | import java.util.Collections; |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 62 | import java.util.Iterator; |
| 63 | import java.util.LinkedList; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 64 | import java.util.List; |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 65 | import java.util.Map; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * A helper class for TvInputManagerService to handle TV input hardware. |
| 69 | * |
| 70 | * This class does a basic connection management and forwarding calls to TvInputHal which eventually |
| 71 | * calls to tv_input HAL module. |
| 72 | * |
| 73 | * @hide |
| 74 | */ |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 75 | class TvInputHardwareManager implements TvInputHal.Callback { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 76 | private static final String TAG = TvInputHardwareManager.class.getSimpleName(); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 77 | |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 78 | private final Context mContext; |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 79 | private final Listener mListener; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 80 | private final TvInputHal mHal = new TvInputHal(this); |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 81 | private final SparseArray<Connection> mConnections = new SparseArray<>(); |
| 82 | private final List<TvInputHardwareInfo> mHardwareList = new ArrayList<>(); |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 83 | private final List<HdmiDeviceInfo> mHdmiDeviceList = new LinkedList<>(); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 84 | /* A map from a device ID to the matching TV input ID. */ |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 85 | private final SparseArray<String> mHardwareInputIdMap = new SparseArray<>(); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 86 | /* A map from a HDMI logical address to the matching TV input ID. */ |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 87 | private final SparseArray<String> mHdmiInputIdMap = new SparseArray<>(); |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 88 | private final Map<String, TvInputInfo> mInputMap = new ArrayMap<>(); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 89 | |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 90 | private final AudioManager mAudioManager; |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 91 | private IHdmiControlService mHdmiControlService; |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 92 | private final IHdmiHotplugEventListener mHdmiHotplugEventListener = |
| 93 | new HdmiHotplugEventListener(); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 94 | private final IHdmiDeviceEventListener mHdmiDeviceEventListener = new HdmiDeviceEventListener(); |
Jungshik Jang | 1f819bb | 2014-08-08 10:46:54 +0900 | [diff] [blame] | 95 | private final IHdmiSystemAudioModeChangeListener mHdmiSystemAudioModeChangeListener = |
| 96 | new HdmiSystemAudioModeChangeListener(); |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 97 | private final BroadcastReceiver mVolumeReceiver = new BroadcastReceiver() { |
| 98 | @Override |
| 99 | public void onReceive(Context context, Intent intent) { |
| 100 | handleVolumeChange(context, intent); |
| 101 | } |
| 102 | }; |
| 103 | private int mCurrentIndex = 0; |
| 104 | private int mCurrentMaxIndex = 0; |
Jinsuk Kim | d38bf47 | 2014-08-11 11:29:18 +0900 | [diff] [blame] | 105 | |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 106 | // TODO: Should handle STANDBY case. |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 107 | private final SparseBooleanArray mHdmiStateMap = new SparseBooleanArray(); |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 108 | private final List<Message> mPendingHdmiDeviceEvents = new LinkedList<>(); |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 109 | |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 110 | // Calls to mListener should happen here. |
| 111 | private final Handler mHandler = new ListenerHandler(); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 112 | |
| 113 | private final Object mLock = new Object(); |
| 114 | |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 115 | public TvInputHardwareManager(Context context, Listener listener) { |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 116 | mContext = context; |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 117 | mListener = listener; |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 118 | mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 119 | mHal.init(); |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | public void onBootPhase(int phase) { |
| 123 | if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 124 | mHdmiControlService = IHdmiControlService.Stub.asInterface(ServiceManager.getService( |
| 125 | Context.HDMI_CONTROL_SERVICE)); |
| 126 | if (mHdmiControlService != null) { |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 127 | try { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 128 | mHdmiControlService.addHotplugEventListener(mHdmiHotplugEventListener); |
| 129 | mHdmiControlService.addDeviceEventListener(mHdmiDeviceEventListener); |
Jungshik Jang | 1f819bb | 2014-08-08 10:46:54 +0900 | [diff] [blame] | 130 | mHdmiControlService.addSystemAudioModeChangeListener( |
| 131 | mHdmiSystemAudioModeChangeListener); |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 132 | mHdmiDeviceList.addAll(mHdmiControlService.getInputDevices()); |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 133 | } catch (RemoteException e) { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 134 | Slog.w(TAG, "Error registering listeners to HdmiControlService:", e); |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 135 | } |
Jinsuk Kim | 08f1ab0 | 2014-10-13 10:38:16 +0900 | [diff] [blame] | 136 | } else { |
| 137 | Slog.w(TAG, "HdmiControlService is not available"); |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 138 | } |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame^] | 139 | final IntentFilter filter = new IntentFilter(); |
| 140 | filter.addAction(AudioManager.VOLUME_CHANGED_ACTION); |
| 141 | filter.addAction(AudioManager.STREAM_MUTE_CHANGED_ACTION); |
| 142 | mContext.registerReceiver(mVolumeReceiver, filter); |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 143 | updateVolume(); |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 144 | } |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | @Override |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 148 | public void onDeviceAvailable(TvInputHardwareInfo info, TvStreamConfig[] configs) { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 149 | synchronized (mLock) { |
| 150 | Connection connection = new Connection(info); |
| 151 | connection.updateConfigsLocked(configs); |
| 152 | mConnections.put(info.getDeviceId(), connection); |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 153 | buildHardwareListLocked(); |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 154 | mHandler.obtainMessage( |
| 155 | ListenerHandler.HARDWARE_DEVICE_ADDED, 0, 0, info).sendToTarget(); |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 156 | if (info.getType() == TvInputHardwareInfo.TV_INPUT_TYPE_HDMI) { |
| 157 | processPendingHdmiDeviceEventsLocked(); |
| 158 | } |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 162 | private void buildHardwareListLocked() { |
| 163 | mHardwareList.clear(); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 164 | for (int i = 0; i < mConnections.size(); ++i) { |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 165 | mHardwareList.add(mConnections.valueAt(i).getHardwareInfoLocked()); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 166 | } |
| 167 | } |
| 168 | |
| 169 | @Override |
| 170 | public void onDeviceUnavailable(int deviceId) { |
| 171 | synchronized (mLock) { |
| 172 | Connection connection = mConnections.get(deviceId); |
| 173 | if (connection == null) { |
| 174 | Slog.e(TAG, "onDeviceUnavailable: Cannot find a connection with " + deviceId); |
| 175 | return; |
| 176 | } |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 177 | connection.resetLocked(null, null, null, null, null); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 178 | mConnections.remove(deviceId); |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 179 | buildHardwareListLocked(); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 180 | TvInputHardwareInfo info = connection.getHardwareInfoLocked(); |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 181 | if (info.getType() == TvInputHardwareInfo.TV_INPUT_TYPE_HDMI) { |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 182 | // Remove HDMI devices linked with this hardware. |
| 183 | for (Iterator<HdmiDeviceInfo> it = mHdmiDeviceList.iterator(); it.hasNext();) { |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 184 | HdmiDeviceInfo deviceInfo = it.next(); |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 185 | if (deviceInfo.getPortId() == info.getHdmiPortId()) { |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 186 | mHandler.obtainMessage(ListenerHandler.HDMI_DEVICE_REMOVED, 0, 0, |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 187 | deviceInfo).sendToTarget(); |
| 188 | it.remove(); |
| 189 | } |
| 190 | } |
| 191 | } |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 192 | mHandler.obtainMessage( |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 193 | ListenerHandler.HARDWARE_DEVICE_REMOVED, 0, 0, info).sendToTarget(); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | |
| 197 | @Override |
| 198 | public void onStreamConfigurationChanged(int deviceId, TvStreamConfig[] configs) { |
| 199 | synchronized (mLock) { |
| 200 | Connection connection = mConnections.get(deviceId); |
| 201 | if (connection == null) { |
| 202 | Slog.e(TAG, "StreamConfigurationChanged: Cannot find a connection with " |
| 203 | + deviceId); |
| 204 | return; |
| 205 | } |
| 206 | connection.updateConfigsLocked(configs); |
Wonsik Kim | 9a10365 | 2014-10-21 17:46:31 +0900 | [diff] [blame] | 207 | String inputId = mHardwareInputIdMap.get(deviceId); |
| 208 | if (inputId != null) { |
| 209 | mHandler.obtainMessage(ListenerHandler.STATE_CHANGED, |
Wonsik Kim | 5b820a8 | 2014-10-27 11:02:10 +0900 | [diff] [blame] | 210 | convertConnectedToState(configs.length > 0), 0, inputId).sendToTarget(); |
Wonsik Kim | 9a10365 | 2014-10-21 17:46:31 +0900 | [diff] [blame] | 211 | } |
Dongwon Kang | 017bb85 | 2014-12-26 14:53:14 +0900 | [diff] [blame] | 212 | ITvInputHardwareCallback callback = connection.getCallbackLocked(); |
| 213 | if (callback != null) { |
| 214 | try { |
| 215 | callback.onStreamConfigChanged(configs); |
| 216 | } catch (RemoteException e) { |
| 217 | Slog.e(TAG, "error in onStreamConfigurationChanged", e); |
| 218 | } |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | } |
| 222 | |
Terry Heo | c086a3d | 2014-06-18 14:26:44 +0900 | [diff] [blame] | 223 | @Override |
| 224 | public void onFirstFrameCaptured(int deviceId, int streamId) { |
| 225 | synchronized (mLock) { |
| 226 | Connection connection = mConnections.get(deviceId); |
| 227 | if (connection == null) { |
| 228 | Slog.e(TAG, "FirstFrameCaptured: Cannot find a connection with " |
| 229 | + deviceId); |
| 230 | return; |
| 231 | } |
| 232 | Runnable runnable = connection.getOnFirstFrameCapturedLocked(); |
| 233 | if (runnable != null) { |
| 234 | runnable.run(); |
| 235 | connection.setOnFirstFrameCapturedLocked(null); |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 240 | public List<TvInputHardwareInfo> getHardwareList() { |
| 241 | synchronized (mLock) { |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 242 | return Collections.unmodifiableList(mHardwareList); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 246 | public List<HdmiDeviceInfo> getHdmiDeviceList() { |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 247 | synchronized (mLock) { |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 248 | return Collections.unmodifiableList(mHdmiDeviceList); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 249 | } |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 250 | } |
| 251 | |
Wonsik Kim | e7ae0ce | 2014-06-19 00:48:35 +0900 | [diff] [blame] | 252 | private boolean checkUidChangedLocked( |
| 253 | Connection connection, int callingUid, int resolvedUserId) { |
| 254 | Integer connectionCallingUid = connection.getCallingUidLocked(); |
| 255 | Integer connectionResolvedUserId = connection.getResolvedUserIdLocked(); |
| 256 | if (connectionCallingUid == null || connectionResolvedUserId == null) { |
| 257 | return true; |
| 258 | } |
| 259 | if (connectionCallingUid != callingUid || connectionResolvedUserId != resolvedUserId) { |
| 260 | return true; |
| 261 | } |
| 262 | return false; |
| 263 | } |
| 264 | |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 265 | private int convertConnectedToState(boolean connected) { |
| 266 | if (connected) { |
| 267 | return INPUT_STATE_CONNECTED; |
| 268 | } else { |
| 269 | return INPUT_STATE_DISCONNECTED; |
| 270 | } |
| 271 | } |
| 272 | |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 273 | public void addHardwareTvInput(int deviceId, TvInputInfo info) { |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 274 | synchronized (mLock) { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 275 | String oldInputId = mHardwareInputIdMap.get(deviceId); |
| 276 | if (oldInputId != null) { |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 277 | Slog.w(TAG, "Trying to override previous registration: old = " |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 278 | + mInputMap.get(oldInputId) + ":" + deviceId + ", new = " |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 279 | + info + ":" + deviceId); |
| 280 | } |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 281 | mHardwareInputIdMap.put(deviceId, info.getId()); |
| 282 | mInputMap.put(info.getId(), info); |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 283 | |
Wonsik Kim | 9a10365 | 2014-10-21 17:46:31 +0900 | [diff] [blame] | 284 | // Process pending state changes |
| 285 | |
| 286 | // For logical HDMI devices, they have information from HDMI CEC signals. |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 287 | for (int i = 0; i < mHdmiStateMap.size(); ++i) { |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 288 | TvInputHardwareInfo hardwareInfo = |
| 289 | findHardwareInfoForHdmiPortLocked(mHdmiStateMap.keyAt(i)); |
| 290 | if (hardwareInfo == null) { |
| 291 | continue; |
| 292 | } |
| 293 | String inputId = mHardwareInputIdMap.get(hardwareInfo.getDeviceId()); |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 294 | if (inputId != null && inputId.equals(info.getId())) { |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 295 | mHandler.obtainMessage(ListenerHandler.STATE_CHANGED, |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 296 | convertConnectedToState(mHdmiStateMap.valueAt(i)), 0, |
| 297 | inputId).sendToTarget(); |
Wonsik Kim | 9a10365 | 2014-10-21 17:46:31 +0900 | [diff] [blame] | 298 | return; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 299 | } |
| 300 | } |
Wonsik Kim | 9a10365 | 2014-10-21 17:46:31 +0900 | [diff] [blame] | 301 | // For the rest of the devices, we can tell by the number of available streams. |
| 302 | Connection connection = mConnections.get(deviceId); |
| 303 | if (connection != null) { |
| 304 | mHandler.obtainMessage(ListenerHandler.STATE_CHANGED, |
| 305 | convertConnectedToState(connection.getConfigsLocked().length > 0), 0, |
| 306 | info.getId()).sendToTarget(); |
| 307 | return; |
| 308 | } |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 309 | } |
| 310 | } |
| 311 | |
Wonsik Kim | 38feae9 | 2014-07-21 21:35:50 +0900 | [diff] [blame] | 312 | private static <T> int indexOfEqualValue(SparseArray<T> map, T value) { |
| 313 | for (int i = 0; i < map.size(); ++i) { |
| 314 | if (map.valueAt(i).equals(value)) { |
| 315 | return i; |
| 316 | } |
| 317 | } |
| 318 | return -1; |
| 319 | } |
| 320 | |
Wonsik Kim | 71dfa96 | 2014-11-15 14:18:49 +0900 | [diff] [blame] | 321 | private static boolean intArrayContains(int[] array, int value) { |
| 322 | for (int element : array) { |
| 323 | if (element == value) return true; |
| 324 | } |
| 325 | return false; |
| 326 | } |
| 327 | |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 328 | public void addHdmiTvInput(int id, TvInputInfo info) { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 329 | if (info.getType() != TvInputInfo.TYPE_HDMI) { |
| 330 | throw new IllegalArgumentException("info (" + info + ") has non-HDMI type."); |
| 331 | } |
| 332 | synchronized (mLock) { |
| 333 | String parentId = info.getParentId(); |
Wonsik Kim | 38feae9 | 2014-07-21 21:35:50 +0900 | [diff] [blame] | 334 | int parentIndex = indexOfEqualValue(mHardwareInputIdMap, parentId); |
| 335 | if (parentIndex < 0) { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 336 | throw new IllegalArgumentException("info (" + info + ") has invalid parentId."); |
| 337 | } |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 338 | String oldInputId = mHdmiInputIdMap.get(id); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 339 | if (oldInputId != null) { |
| 340 | Slog.w(TAG, "Trying to override previous registration: old = " |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 341 | + mInputMap.get(oldInputId) + ":" + id + ", new = " |
| 342 | + info + ":" + id); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 343 | } |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 344 | mHdmiInputIdMap.put(id, info.getId()); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 345 | mInputMap.put(info.getId(), info); |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | public void removeTvInput(String inputId) { |
| 350 | synchronized (mLock) { |
| 351 | mInputMap.remove(inputId); |
Wonsik Kim | 38feae9 | 2014-07-21 21:35:50 +0900 | [diff] [blame] | 352 | int hardwareIndex = indexOfEqualValue(mHardwareInputIdMap, inputId); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 353 | if (hardwareIndex >= 0) { |
| 354 | mHardwareInputIdMap.removeAt(hardwareIndex); |
| 355 | } |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 356 | int deviceIndex = indexOfEqualValue(mHdmiInputIdMap, inputId); |
| 357 | if (deviceIndex >= 0) { |
| 358 | mHdmiInputIdMap.removeAt(deviceIndex); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | } |
| 362 | |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 363 | /** |
| 364 | * Create a TvInputHardware object with a specific deviceId. One service at a time can access |
| 365 | * the object, and if more than one process attempts to create hardware with the same deviceId, |
| 366 | * the latest service will get the object and all the other hardware are released. The |
| 367 | * release is notified via ITvInputHardwareCallback.onReleased(). |
| 368 | */ |
| 369 | public ITvInputHardware acquireHardware(int deviceId, ITvInputHardwareCallback callback, |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 370 | TvInputInfo info, int callingUid, int resolvedUserId) { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 371 | if (callback == null) { |
| 372 | throw new NullPointerException(); |
| 373 | } |
| 374 | synchronized (mLock) { |
| 375 | Connection connection = mConnections.get(deviceId); |
| 376 | if (connection == null) { |
| 377 | Slog.e(TAG, "Invalid deviceId : " + deviceId); |
| 378 | return null; |
| 379 | } |
Wonsik Kim | e7ae0ce | 2014-06-19 00:48:35 +0900 | [diff] [blame] | 380 | if (checkUidChangedLocked(connection, callingUid, resolvedUserId)) { |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 381 | TvInputHardwareImpl hardware = |
| 382 | new TvInputHardwareImpl(connection.getHardwareInfoLocked()); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 383 | try { |
| 384 | callback.asBinder().linkToDeath(connection, 0); |
| 385 | } catch (RemoteException e) { |
| 386 | hardware.release(); |
| 387 | return null; |
| 388 | } |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 389 | connection.resetLocked(hardware, callback, info, callingUid, resolvedUserId); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 390 | } |
| 391 | return connection.getHardwareLocked(); |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | /** |
| 396 | * Release the specified hardware. |
| 397 | */ |
| 398 | public void releaseHardware(int deviceId, ITvInputHardware hardware, int callingUid, |
| 399 | int resolvedUserId) { |
| 400 | synchronized (mLock) { |
| 401 | Connection connection = mConnections.get(deviceId); |
| 402 | if (connection == null) { |
| 403 | Slog.e(TAG, "Invalid deviceId : " + deviceId); |
| 404 | return; |
| 405 | } |
| 406 | if (connection.getHardwareLocked() != hardware |
Wonsik Kim | e7ae0ce | 2014-06-19 00:48:35 +0900 | [diff] [blame] | 407 | || checkUidChangedLocked(connection, callingUid, resolvedUserId)) { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 408 | return; |
| 409 | } |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 410 | connection.resetLocked(null, null, null, null, null); |
| 411 | } |
| 412 | } |
| 413 | |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 414 | private TvInputHardwareInfo findHardwareInfoForHdmiPortLocked(int port) { |
| 415 | for (TvInputHardwareInfo hardwareInfo : mHardwareList) { |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 416 | if (hardwareInfo.getType() == TvInputHardwareInfo.TV_INPUT_TYPE_HDMI |
| 417 | && hardwareInfo.getHdmiPortId() == port) { |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 418 | return hardwareInfo; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 419 | } |
| 420 | } |
| 421 | return null; |
| 422 | } |
| 423 | |
Terry Heo | c086a3d | 2014-06-18 14:26:44 +0900 | [diff] [blame] | 424 | private int findDeviceIdForInputIdLocked(String inputId) { |
| 425 | for (int i = 0; i < mConnections.size(); ++i) { |
| 426 | Connection connection = mConnections.get(i); |
| 427 | if (connection.getInfoLocked().getId().equals(inputId)) { |
| 428 | return i; |
| 429 | } |
| 430 | } |
| 431 | return -1; |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * Get the list of TvStreamConfig which is buffered mode. |
| 436 | */ |
| 437 | public List<TvStreamConfig> getAvailableTvStreamConfigList(String inputId, int callingUid, |
| 438 | int resolvedUserId) { |
| 439 | List<TvStreamConfig> configsList = new ArrayList<TvStreamConfig>(); |
| 440 | synchronized (mLock) { |
| 441 | int deviceId = findDeviceIdForInputIdLocked(inputId); |
| 442 | if (deviceId < 0) { |
| 443 | Slog.e(TAG, "Invalid inputId : " + inputId); |
| 444 | return configsList; |
| 445 | } |
| 446 | Connection connection = mConnections.get(deviceId); |
| 447 | for (TvStreamConfig config : connection.getConfigsLocked()) { |
| 448 | if (config.getType() == TvStreamConfig.STREAM_TYPE_BUFFER_PRODUCER) { |
| 449 | configsList.add(config); |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | return configsList; |
| 454 | } |
| 455 | |
| 456 | /** |
| 457 | * Take a snapshot of the given TV input into the provided Surface. |
| 458 | */ |
| 459 | public boolean captureFrame(String inputId, Surface surface, final TvStreamConfig config, |
| 460 | int callingUid, int resolvedUserId) { |
| 461 | synchronized (mLock) { |
| 462 | int deviceId = findDeviceIdForInputIdLocked(inputId); |
| 463 | if (deviceId < 0) { |
| 464 | Slog.e(TAG, "Invalid inputId : " + inputId); |
| 465 | return false; |
| 466 | } |
| 467 | Connection connection = mConnections.get(deviceId); |
| 468 | final TvInputHardwareImpl hardwareImpl = connection.getHardwareImplLocked(); |
| 469 | if (hardwareImpl != null) { |
| 470 | // Stop previous capture. |
| 471 | Runnable runnable = connection.getOnFirstFrameCapturedLocked(); |
| 472 | if (runnable != null) { |
| 473 | runnable.run(); |
| 474 | connection.setOnFirstFrameCapturedLocked(null); |
| 475 | } |
| 476 | |
| 477 | boolean result = hardwareImpl.startCapture(surface, config); |
| 478 | if (result) { |
| 479 | connection.setOnFirstFrameCapturedLocked(new Runnable() { |
| 480 | @Override |
| 481 | public void run() { |
| 482 | hardwareImpl.stopCapture(config); |
| 483 | } |
| 484 | }); |
| 485 | } |
| 486 | return result; |
| 487 | } |
| 488 | } |
| 489 | return false; |
| 490 | } |
| 491 | |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 492 | private void processPendingHdmiDeviceEventsLocked() { |
| 493 | for (Iterator<Message> it = mPendingHdmiDeviceEvents.iterator(); it.hasNext(); ) { |
| 494 | Message msg = it.next(); |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 495 | HdmiDeviceInfo deviceInfo = (HdmiDeviceInfo) msg.obj; |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 496 | TvInputHardwareInfo hardwareInfo = |
| 497 | findHardwareInfoForHdmiPortLocked(deviceInfo.getPortId()); |
| 498 | if (hardwareInfo != null) { |
| 499 | msg.sendToTarget(); |
| 500 | it.remove(); |
| 501 | } |
| 502 | } |
| 503 | } |
| 504 | |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 505 | private void updateVolume() { |
| 506 | mCurrentMaxIndex = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); |
| 507 | mCurrentIndex = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); |
| 508 | } |
| 509 | |
| 510 | private void handleVolumeChange(Context context, Intent intent) { |
| 511 | String action = intent.getAction(); |
| 512 | if (action.equals(AudioManager.VOLUME_CHANGED_ACTION)) { |
| 513 | int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1); |
| 514 | if (streamType != AudioManager.STREAM_MUSIC) { |
| 515 | return; |
| 516 | } |
| 517 | int index = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, 0); |
| 518 | if (index == mCurrentIndex) { |
| 519 | return; |
| 520 | } |
| 521 | mCurrentIndex = index; |
| 522 | } else if (action.equals(AudioManager.STREAM_MUTE_CHANGED_ACTION)) { |
| 523 | int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1); |
| 524 | if (streamType != AudioManager.STREAM_MUSIC) { |
| 525 | return; |
| 526 | } |
| 527 | // volume index will be updated at onMediaStreamVolumeChanged() through updateVolume(). |
| 528 | } else { |
| 529 | Slog.w(TAG, "Unrecognized intent: " + intent); |
| 530 | return; |
| 531 | } |
| 532 | synchronized (mLock) { |
| 533 | for (int i = 0; i < mConnections.size(); ++i) { |
| 534 | TvInputHardwareImpl hardwareImpl = mConnections.valueAt(i).getHardwareImplLocked(); |
| 535 | if (hardwareImpl != null) { |
| 536 | hardwareImpl.onMediaStreamVolumeChanged(); |
| 537 | } |
| 538 | } |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | private float getMediaStreamVolume() { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame^] | 543 | return (float) mCurrentIndex / (float) mCurrentMaxIndex; |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 544 | } |
| 545 | |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 546 | private class Connection implements IBinder.DeathRecipient { |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 547 | private final TvInputHardwareInfo mHardwareInfo; |
| 548 | private TvInputInfo mInfo; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 549 | private TvInputHardwareImpl mHardware = null; |
| 550 | private ITvInputHardwareCallback mCallback; |
| 551 | private TvStreamConfig[] mConfigs = null; |
| 552 | private Integer mCallingUid = null; |
| 553 | private Integer mResolvedUserId = null; |
Terry Heo | c086a3d | 2014-06-18 14:26:44 +0900 | [diff] [blame] | 554 | private Runnable mOnFirstFrameCaptured; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 555 | |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 556 | public Connection(TvInputHardwareInfo hardwareInfo) { |
| 557 | mHardwareInfo = hardwareInfo; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | // *Locked methods assume TvInputHardwareManager.mLock is held. |
| 561 | |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 562 | public void resetLocked(TvInputHardwareImpl hardware, ITvInputHardwareCallback callback, |
| 563 | TvInputInfo info, Integer callingUid, Integer resolvedUserId) { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 564 | if (mHardware != null) { |
| 565 | try { |
| 566 | mCallback.onReleased(); |
| 567 | } catch (RemoteException e) { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 568 | Slog.e(TAG, "error in Connection::resetLocked", e); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 569 | } |
| 570 | mHardware.release(); |
| 571 | } |
| 572 | mHardware = hardware; |
| 573 | mCallback = callback; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 574 | mInfo = info; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 575 | mCallingUid = callingUid; |
| 576 | mResolvedUserId = resolvedUserId; |
Terry Heo | c086a3d | 2014-06-18 14:26:44 +0900 | [diff] [blame] | 577 | mOnFirstFrameCaptured = null; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 578 | |
| 579 | if (mHardware != null && mCallback != null) { |
| 580 | try { |
| 581 | mCallback.onStreamConfigChanged(getConfigsLocked()); |
| 582 | } catch (RemoteException e) { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 583 | Slog.e(TAG, "error in Connection::resetLocked", e); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 584 | } |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | public void updateConfigsLocked(TvStreamConfig[] configs) { |
| 589 | mConfigs = configs; |
| 590 | } |
| 591 | |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 592 | public TvInputHardwareInfo getHardwareInfoLocked() { |
| 593 | return mHardwareInfo; |
| 594 | } |
| 595 | |
| 596 | public TvInputInfo getInfoLocked() { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 597 | return mInfo; |
| 598 | } |
| 599 | |
| 600 | public ITvInputHardware getHardwareLocked() { |
| 601 | return mHardware; |
| 602 | } |
| 603 | |
Terry Heo | c086a3d | 2014-06-18 14:26:44 +0900 | [diff] [blame] | 604 | public TvInputHardwareImpl getHardwareImplLocked() { |
| 605 | return mHardware; |
| 606 | } |
| 607 | |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 608 | public ITvInputHardwareCallback getCallbackLocked() { |
| 609 | return mCallback; |
| 610 | } |
| 611 | |
| 612 | public TvStreamConfig[] getConfigsLocked() { |
| 613 | return mConfigs; |
| 614 | } |
| 615 | |
Wonsik Kim | e7ae0ce | 2014-06-19 00:48:35 +0900 | [diff] [blame] | 616 | public Integer getCallingUidLocked() { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 617 | return mCallingUid; |
| 618 | } |
| 619 | |
Wonsik Kim | e7ae0ce | 2014-06-19 00:48:35 +0900 | [diff] [blame] | 620 | public Integer getResolvedUserIdLocked() { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 621 | return mResolvedUserId; |
| 622 | } |
| 623 | |
Terry Heo | c086a3d | 2014-06-18 14:26:44 +0900 | [diff] [blame] | 624 | public void setOnFirstFrameCapturedLocked(Runnable runnable) { |
| 625 | mOnFirstFrameCaptured = runnable; |
| 626 | } |
| 627 | |
| 628 | public Runnable getOnFirstFrameCapturedLocked() { |
| 629 | return mOnFirstFrameCaptured; |
| 630 | } |
| 631 | |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 632 | @Override |
| 633 | public void binderDied() { |
| 634 | synchronized (mLock) { |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 635 | resetLocked(null, null, null, null, null); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 636 | } |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | private class TvInputHardwareImpl extends ITvInputHardware.Stub { |
| 641 | private final TvInputHardwareInfo mInfo; |
| 642 | private boolean mReleased = false; |
| 643 | private final Object mImplLock = new Object(); |
| 644 | |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 645 | private final AudioManager.OnAudioPortUpdateListener mAudioListener = |
| 646 | new AudioManager.OnAudioPortUpdateListener() { |
| 647 | @Override |
| 648 | public void onAudioPortListUpdate(AudioPort[] portList) { |
| 649 | synchronized (mImplLock) { |
Wonsik Kim | 7587d29 | 2014-08-09 10:01:01 +0900 | [diff] [blame] | 650 | updateAudioConfigLocked(); |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | |
| 654 | @Override |
| 655 | public void onAudioPatchListUpdate(AudioPatch[] patchList) { |
| 656 | // No-op |
| 657 | } |
| 658 | |
| 659 | @Override |
| 660 | public void onServiceDied() { |
| 661 | synchronized (mImplLock) { |
| 662 | mAudioSource = null; |
Wonsik Kim | b2b85f9 | 2015-01-19 16:07:48 +0900 | [diff] [blame] | 663 | mAudioSink.clear(); |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 664 | mAudioPatch = null; |
| 665 | } |
| 666 | } |
| 667 | }; |
| 668 | private int mOverrideAudioType = AudioManager.DEVICE_NONE; |
| 669 | private String mOverrideAudioAddress = ""; |
| 670 | private AudioDevicePort mAudioSource; |
Wonsik Kim | b2b85f9 | 2015-01-19 16:07:48 +0900 | [diff] [blame] | 671 | private List<AudioDevicePort> mAudioSink = new ArrayList<>(); |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 672 | private AudioPatch mAudioPatch = null; |
Wonsik Kim | 485e7e1 | 2015-01-26 17:28:55 +0900 | [diff] [blame] | 673 | // Set to an invalid value for a volume, so that current volume can be applied at the |
| 674 | // first call to updateAudioConfigLocked(). |
| 675 | private float mCommittedVolume = -1f; |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 676 | private float mSourceVolume = 0.0f; |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 677 | |
Wonsik Kim | 839ae5f | 2014-07-03 19:06:56 +0900 | [diff] [blame] | 678 | private TvStreamConfig mActiveConfig = null; |
| 679 | |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 680 | private int mDesiredSamplingRate = 0; |
| 681 | private int mDesiredChannelMask = AudioFormat.CHANNEL_OUT_DEFAULT; |
| 682 | private int mDesiredFormat = AudioFormat.ENCODING_DEFAULT; |
| 683 | |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 684 | public TvInputHardwareImpl(TvInputHardwareInfo info) { |
| 685 | mInfo = info; |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 686 | mAudioManager.registerAudioPortUpdateListener(mAudioListener); |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 687 | if (mInfo.getAudioType() != AudioManager.DEVICE_NONE) { |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 688 | mAudioSource = findAudioDevicePort(mInfo.getAudioType(), mInfo.getAudioAddress()); |
Wonsik Kim | b2b85f9 | 2015-01-19 16:07:48 +0900 | [diff] [blame] | 689 | findAudioSinkFromAudioPolicy(mAudioSink); |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 690 | } |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 691 | } |
| 692 | |
Wonsik Kim | b2b85f9 | 2015-01-19 16:07:48 +0900 | [diff] [blame] | 693 | private void findAudioSinkFromAudioPolicy(List<AudioDevicePort> sinks) { |
| 694 | sinks.clear(); |
Paul McLean | ceb47aa | 2015-02-19 15:09:53 -0800 | [diff] [blame] | 695 | ArrayList<AudioDevicePort> devicePorts = new ArrayList<AudioDevicePort>(); |
Wonsik Kim | b2b85f9 | 2015-01-19 16:07:48 +0900 | [diff] [blame] | 696 | if (mAudioManager.listAudioDevicePorts(devicePorts) != AudioManager.SUCCESS) { |
| 697 | return; |
| 698 | } |
| 699 | int sinkDevice = mAudioManager.getDevicesForStream(AudioManager.STREAM_MUSIC); |
Paul McLean | ceb47aa | 2015-02-19 15:09:53 -0800 | [diff] [blame] | 700 | for (AudioDevicePort port : devicePorts) { |
| 701 | if ((port.type() & sinkDevice) != 0) { |
| 702 | sinks.add(port); |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 703 | } |
| 704 | } |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | private AudioDevicePort findAudioDevicePort(int type, String address) { |
| 708 | if (type == AudioManager.DEVICE_NONE) { |
| 709 | return null; |
| 710 | } |
Paul McLean | ceb47aa | 2015-02-19 15:09:53 -0800 | [diff] [blame] | 711 | ArrayList<AudioDevicePort> devicePorts = new ArrayList<AudioDevicePort>(); |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 712 | if (mAudioManager.listAudioDevicePorts(devicePorts) != AudioManager.SUCCESS) { |
| 713 | return null; |
| 714 | } |
Paul McLean | ceb47aa | 2015-02-19 15:09:53 -0800 | [diff] [blame] | 715 | for (AudioDevicePort port : devicePorts) { |
| 716 | if (port.type() == type && port.address().equals(address)) { |
| 717 | return port; |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 718 | } |
| 719 | } |
| 720 | return null; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | public void release() { |
| 724 | synchronized (mImplLock) { |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 725 | mAudioManager.unregisterAudioPortUpdateListener(mAudioListener); |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 726 | if (mAudioPatch != null) { |
| 727 | mAudioManager.releaseAudioPatch(mAudioPatch); |
| 728 | mAudioPatch = null; |
| 729 | } |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 730 | mReleased = true; |
| 731 | } |
| 732 | } |
| 733 | |
Wonsik Kim | 839ae5f | 2014-07-03 19:06:56 +0900 | [diff] [blame] | 734 | // A TvInputHardwareImpl object holds only one active session. Therefore, if a client |
| 735 | // attempts to call setSurface with different TvStreamConfig objects, the last call will |
| 736 | // prevail. |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 737 | @Override |
| 738 | public boolean setSurface(Surface surface, TvStreamConfig config) |
| 739 | throws RemoteException { |
| 740 | synchronized (mImplLock) { |
| 741 | if (mReleased) { |
| 742 | throw new IllegalStateException("Device already released."); |
| 743 | } |
Wonsik Kim | 7587d29 | 2014-08-09 10:01:01 +0900 | [diff] [blame] | 744 | |
Wonsik Kim | 102670f | 2014-11-20 14:38:02 +0900 | [diff] [blame] | 745 | int result = TvInputHal.SUCCESS; |
Wonsik Kim | 839ae5f | 2014-07-03 19:06:56 +0900 | [diff] [blame] | 746 | if (surface == null) { |
Wonsik Kim | b683e6e | 2014-11-17 16:31:39 +0900 | [diff] [blame] | 747 | // The value of config is ignored when surface == null. |
| 748 | if (mActiveConfig != null) { |
| 749 | result = mHal.removeStream(mInfo.getDeviceId(), mActiveConfig); |
| 750 | mActiveConfig = null; |
| 751 | } else { |
| 752 | // We already have no active stream. |
| 753 | return true; |
| 754 | } |
Wonsik Kim | 839ae5f | 2014-07-03 19:06:56 +0900 | [diff] [blame] | 755 | } else { |
Wonsik Kim | b683e6e | 2014-11-17 16:31:39 +0900 | [diff] [blame] | 756 | // It's impossible to set a non-null surface with a null config. |
| 757 | if (config == null) { |
| 758 | return false; |
| 759 | } |
| 760 | // Remove stream only if we have an existing active configuration. |
| 761 | if (mActiveConfig != null && !config.equals(mActiveConfig)) { |
Wonsik Kim | 839ae5f | 2014-07-03 19:06:56 +0900 | [diff] [blame] | 762 | result = mHal.removeStream(mInfo.getDeviceId(), mActiveConfig); |
| 763 | if (result != TvInputHal.SUCCESS) { |
| 764 | mActiveConfig = null; |
Wonsik Kim | 839ae5f | 2014-07-03 19:06:56 +0900 | [diff] [blame] | 765 | } |
| 766 | } |
Wonsik Kim | b683e6e | 2014-11-17 16:31:39 +0900 | [diff] [blame] | 767 | // Proceed only if all previous operations succeeded. |
Wonsik Kim | 839ae5f | 2014-07-03 19:06:56 +0900 | [diff] [blame] | 768 | if (result == TvInputHal.SUCCESS) { |
Wonsik Kim | b683e6e | 2014-11-17 16:31:39 +0900 | [diff] [blame] | 769 | result = mHal.addOrUpdateStream(mInfo.getDeviceId(), surface, config); |
| 770 | if (result == TvInputHal.SUCCESS) { |
| 771 | mActiveConfig = config; |
| 772 | } |
Wonsik Kim | 839ae5f | 2014-07-03 19:06:56 +0900 | [diff] [blame] | 773 | } |
| 774 | } |
Wonsik Kim | 7587d29 | 2014-08-09 10:01:01 +0900 | [diff] [blame] | 775 | updateAudioConfigLocked(); |
Wonsik Kim | 839ae5f | 2014-07-03 19:06:56 +0900 | [diff] [blame] | 776 | return result == TvInputHal.SUCCESS; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 777 | } |
| 778 | } |
| 779 | |
Wonsik Kim | 7587d29 | 2014-08-09 10:01:01 +0900 | [diff] [blame] | 780 | /** |
| 781 | * Update audio configuration (source, sink, patch) all up to current state. |
| 782 | */ |
| 783 | private void updateAudioConfigLocked() { |
| 784 | boolean sinkUpdated = updateAudioSinkLocked(); |
| 785 | boolean sourceUpdated = updateAudioSourceLocked(); |
| 786 | // We can't do updated = updateAudioSinkLocked() || updateAudioSourceLocked() here |
| 787 | // because Java won't evaluate the latter if the former is true. |
| 788 | |
Wonsik Kim | b2b85f9 | 2015-01-19 16:07:48 +0900 | [diff] [blame] | 789 | if (mAudioSource == null || mAudioSink.isEmpty() || mActiveConfig == null) { |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 790 | if (mAudioPatch != null) { |
Wonsik Kim | 7587d29 | 2014-08-09 10:01:01 +0900 | [diff] [blame] | 791 | mAudioManager.releaseAudioPatch(mAudioPatch); |
| 792 | mAudioPatch = null; |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 793 | } |
| 794 | return; |
| 795 | } |
| 796 | |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 797 | updateVolume(); |
| 798 | float volume = mSourceVolume * getMediaStreamVolume(); |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 799 | AudioGainConfig sourceGainConfig = null; |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 800 | if (mAudioSource.gains().length > 0 && volume != mCommittedVolume) { |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 801 | AudioGain sourceGain = null; |
| 802 | for (AudioGain gain : mAudioSource.gains()) { |
| 803 | if ((gain.mode() & AudioGain.MODE_JOINT) != 0) { |
| 804 | sourceGain = gain; |
| 805 | break; |
| 806 | } |
| 807 | } |
| 808 | // NOTE: we only change the source gain in MODE_JOINT here. |
| 809 | if (sourceGain != null) { |
| 810 | int steps = (sourceGain.maxValue() - sourceGain.minValue()) |
| 811 | / sourceGain.stepValue(); |
| 812 | int gainValue = sourceGain.minValue(); |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 813 | if (volume < 1.0f) { |
| 814 | gainValue += sourceGain.stepValue() * (int) (volume * steps + 0.5); |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 815 | } else { |
| 816 | gainValue = sourceGain.maxValue(); |
| 817 | } |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 818 | // size of gain values is 1 in MODE_JOINT |
| 819 | int[] gainValues = new int[] { gainValue }; |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 820 | sourceGainConfig = sourceGain.buildConfig(AudioGain.MODE_JOINT, |
| 821 | sourceGain.channelMask(), gainValues, 0); |
| 822 | } else { |
| 823 | Slog.w(TAG, "No audio source gain with MODE_JOINT support exists."); |
| 824 | } |
| 825 | } |
| 826 | |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 827 | AudioPortConfig sourceConfig = mAudioSource.activeConfig(); |
Wonsik Kim | b2b85f9 | 2015-01-19 16:07:48 +0900 | [diff] [blame] | 828 | List<AudioPortConfig> sinkConfigs = new ArrayList<>(); |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 829 | AudioPatch[] audioPatchArray = new AudioPatch[] { mAudioPatch }; |
Wonsik Kim | 7587d29 | 2014-08-09 10:01:01 +0900 | [diff] [blame] | 830 | boolean shouldRecreateAudioPatch = sourceUpdated || sinkUpdated; |
Wonsik Kim | 71dfa96 | 2014-11-15 14:18:49 +0900 | [diff] [blame] | 831 | |
Wonsik Kim | b2b85f9 | 2015-01-19 16:07:48 +0900 | [diff] [blame] | 832 | for (AudioDevicePort audioSink : mAudioSink) { |
| 833 | AudioPortConfig sinkConfig = audioSink.activeConfig(); |
| 834 | int sinkSamplingRate = mDesiredSamplingRate; |
| 835 | int sinkChannelMask = mDesiredChannelMask; |
| 836 | int sinkFormat = mDesiredFormat; |
| 837 | // If sinkConfig != null and values are set to default, |
| 838 | // fill in the sinkConfig values. |
| 839 | if (sinkConfig != null) { |
| 840 | if (sinkSamplingRate == 0) { |
| 841 | sinkSamplingRate = sinkConfig.samplingRate(); |
| 842 | } |
| 843 | if (sinkChannelMask == AudioFormat.CHANNEL_OUT_DEFAULT) { |
| 844 | sinkChannelMask = sinkConfig.channelMask(); |
| 845 | } |
| 846 | if (sinkFormat == AudioFormat.ENCODING_DEFAULT) { |
| 847 | sinkChannelMask = sinkConfig.format(); |
| 848 | } |
Wonsik Kim | 71dfa96 | 2014-11-15 14:18:49 +0900 | [diff] [blame] | 849 | } |
Wonsik Kim | 71dfa96 | 2014-11-15 14:18:49 +0900 | [diff] [blame] | 850 | |
Wonsik Kim | b2b85f9 | 2015-01-19 16:07:48 +0900 | [diff] [blame] | 851 | if (sinkConfig == null |
| 852 | || sinkConfig.samplingRate() != sinkSamplingRate |
| 853 | || sinkConfig.channelMask() != sinkChannelMask |
| 854 | || sinkConfig.format() != sinkFormat) { |
| 855 | // Check for compatibility and reset to default if necessary. |
| 856 | if (!intArrayContains(audioSink.samplingRates(), sinkSamplingRate) |
| 857 | && audioSink.samplingRates().length > 0) { |
| 858 | sinkSamplingRate = audioSink.samplingRates()[0]; |
| 859 | } |
| 860 | if (!intArrayContains(audioSink.channelMasks(), sinkChannelMask)) { |
| 861 | sinkChannelMask = AudioFormat.CHANNEL_OUT_DEFAULT; |
| 862 | } |
| 863 | if (!intArrayContains(audioSink.formats(), sinkFormat)) { |
| 864 | sinkFormat = AudioFormat.ENCODING_DEFAULT; |
| 865 | } |
| 866 | sinkConfig = audioSink.buildConfig(sinkSamplingRate, sinkChannelMask, |
| 867 | sinkFormat, null); |
| 868 | shouldRecreateAudioPatch = true; |
Wonsik Kim | 71dfa96 | 2014-11-15 14:18:49 +0900 | [diff] [blame] | 869 | } |
Wonsik Kim | b2b85f9 | 2015-01-19 16:07:48 +0900 | [diff] [blame] | 870 | sinkConfigs.add(sinkConfig); |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 871 | } |
Wonsik Kim | b2b85f9 | 2015-01-19 16:07:48 +0900 | [diff] [blame] | 872 | // sinkConfigs.size() == mAudioSink.size(), and mAudioSink is guaranteed to be |
| 873 | // non-empty at the beginning of this method. |
| 874 | AudioPortConfig sinkConfig = sinkConfigs.get(0); |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 875 | if (sourceConfig == null || sourceGainConfig != null) { |
Wonsik Kim | 71dfa96 | 2014-11-15 14:18:49 +0900 | [diff] [blame] | 876 | int sourceSamplingRate = 0; |
| 877 | if (intArrayContains(mAudioSource.samplingRates(), sinkConfig.samplingRate())) { |
| 878 | sourceSamplingRate = sinkConfig.samplingRate(); |
| 879 | } else if (mAudioSource.samplingRates().length > 0) { |
| 880 | // Use any sampling rate and hope audio patch can handle resampling... |
| 881 | sourceSamplingRate = mAudioSource.samplingRates()[0]; |
| 882 | } |
| 883 | int sourceChannelMask = AudioFormat.CHANNEL_IN_DEFAULT; |
| 884 | for (int inChannelMask : mAudioSource.channelMasks()) { |
| 885 | if (AudioFormat.channelCountFromOutChannelMask(sinkConfig.channelMask()) |
| 886 | == AudioFormat.channelCountFromInChannelMask(inChannelMask)) { |
| 887 | sourceChannelMask = inChannelMask; |
| 888 | break; |
| 889 | } |
| 890 | } |
| 891 | int sourceFormat = AudioFormat.ENCODING_DEFAULT; |
| 892 | if (intArrayContains(mAudioSource.formats(), sinkConfig.format())) { |
| 893 | sourceFormat = sinkConfig.format(); |
| 894 | } |
| 895 | sourceConfig = mAudioSource.buildConfig(sourceSamplingRate, sourceChannelMask, |
| 896 | sourceFormat, sourceGainConfig); |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 897 | shouldRecreateAudioPatch = true; |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 898 | } |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 899 | if (shouldRecreateAudioPatch) { |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 900 | mCommittedVolume = volume; |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 901 | mAudioManager.createAudioPatch( |
| 902 | audioPatchArray, |
| 903 | new AudioPortConfig[] { sourceConfig }, |
Wonsik Kim | b2b85f9 | 2015-01-19 16:07:48 +0900 | [diff] [blame] | 904 | sinkConfigs.toArray(new AudioPortConfig[0])); |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 905 | mAudioPatch = audioPatchArray[0]; |
Wonsik Kim | 71dfa96 | 2014-11-15 14:18:49 +0900 | [diff] [blame] | 906 | if (sourceGainConfig != null) { |
| 907 | mAudioManager.setAudioPortGain(mAudioSource, sourceGainConfig); |
| 908 | } |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 909 | } |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 910 | } |
| 911 | |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 912 | @Override |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 913 | public void setStreamVolume(float volume) throws RemoteException { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 914 | synchronized (mImplLock) { |
| 915 | if (mReleased) { |
| 916 | throw new IllegalStateException("Device already released."); |
| 917 | } |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 918 | mSourceVolume = volume; |
Wonsik Kim | 7587d29 | 2014-08-09 10:01:01 +0900 | [diff] [blame] | 919 | updateAudioConfigLocked(); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 920 | } |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | @Override |
| 924 | public boolean dispatchKeyEventToHdmi(KeyEvent event) throws RemoteException { |
| 925 | synchronized (mImplLock) { |
| 926 | if (mReleased) { |
| 927 | throw new IllegalStateException("Device already released."); |
| 928 | } |
| 929 | } |
Wonsik Kim | 610ccd9 | 2014-07-19 18:49:49 +0900 | [diff] [blame] | 930 | if (mInfo.getType() != TvInputHardwareInfo.TV_INPUT_TYPE_HDMI) { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 931 | return false; |
| 932 | } |
| 933 | // TODO(hdmi): mHdmiClient.sendKeyEvent(event); |
| 934 | return false; |
| 935 | } |
Terry Heo | c086a3d | 2014-06-18 14:26:44 +0900 | [diff] [blame] | 936 | |
| 937 | private boolean startCapture(Surface surface, TvStreamConfig config) { |
| 938 | synchronized (mImplLock) { |
| 939 | if (mReleased) { |
| 940 | return false; |
| 941 | } |
| 942 | if (surface == null || config == null) { |
| 943 | return false; |
| 944 | } |
| 945 | if (config.getType() != TvStreamConfig.STREAM_TYPE_BUFFER_PRODUCER) { |
| 946 | return false; |
| 947 | } |
| 948 | |
Wonsik Kim | 8f24a8b | 2014-10-22 16:27:39 +0900 | [diff] [blame] | 949 | int result = mHal.addOrUpdateStream(mInfo.getDeviceId(), surface, config); |
Terry Heo | c086a3d | 2014-06-18 14:26:44 +0900 | [diff] [blame] | 950 | return result == TvInputHal.SUCCESS; |
| 951 | } |
| 952 | } |
| 953 | |
| 954 | private boolean stopCapture(TvStreamConfig config) { |
| 955 | synchronized (mImplLock) { |
| 956 | if (mReleased) { |
| 957 | return false; |
| 958 | } |
| 959 | if (config == null) { |
| 960 | return false; |
| 961 | } |
| 962 | |
| 963 | int result = mHal.removeStream(mInfo.getDeviceId(), config); |
| 964 | return result == TvInputHal.SUCCESS; |
| 965 | } |
| 966 | } |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 967 | |
Wonsik Kim | 7587d29 | 2014-08-09 10:01:01 +0900 | [diff] [blame] | 968 | private boolean updateAudioSourceLocked() { |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 969 | if (mInfo.getAudioType() == AudioManager.DEVICE_NONE) { |
Wonsik Kim | 7587d29 | 2014-08-09 10:01:01 +0900 | [diff] [blame] | 970 | return false; |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 971 | } |
Wonsik Kim | 7587d29 | 2014-08-09 10:01:01 +0900 | [diff] [blame] | 972 | AudioDevicePort previousSource = mAudioSource; |
| 973 | mAudioSource = findAudioDevicePort(mInfo.getAudioType(), mInfo.getAudioAddress()); |
| 974 | return mAudioSource == null ? (previousSource != null) |
| 975 | : !mAudioSource.equals(previousSource); |
| 976 | } |
| 977 | |
| 978 | private boolean updateAudioSinkLocked() { |
| 979 | if (mInfo.getAudioType() == AudioManager.DEVICE_NONE) { |
| 980 | return false; |
| 981 | } |
Wonsik Kim | b2b85f9 | 2015-01-19 16:07:48 +0900 | [diff] [blame] | 982 | List<AudioDevicePort> previousSink = mAudioSink; |
| 983 | mAudioSink = new ArrayList<>(); |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 984 | if (mOverrideAudioType == AudioManager.DEVICE_NONE) { |
Wonsik Kim | b2b85f9 | 2015-01-19 16:07:48 +0900 | [diff] [blame] | 985 | findAudioSinkFromAudioPolicy(mAudioSink); |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 986 | } else { |
| 987 | AudioDevicePort audioSink = |
| 988 | findAudioDevicePort(mOverrideAudioType, mOverrideAudioAddress); |
| 989 | if (audioSink != null) { |
Wonsik Kim | b2b85f9 | 2015-01-19 16:07:48 +0900 | [diff] [blame] | 990 | mAudioSink.add(audioSink); |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 991 | } |
| 992 | } |
Wonsik Kim | b2b85f9 | 2015-01-19 16:07:48 +0900 | [diff] [blame] | 993 | |
| 994 | // Returns true if mAudioSink and previousSink differs. |
| 995 | if (mAudioSink.size() != previousSink.size()) { |
| 996 | return true; |
| 997 | } |
| 998 | previousSink.removeAll(mAudioSink); |
| 999 | return !previousSink.isEmpty(); |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 1000 | } |
| 1001 | |
Jungshik Jang | 1f819bb | 2014-08-08 10:46:54 +0900 | [diff] [blame] | 1002 | private void handleAudioSinkUpdated() { |
| 1003 | synchronized (mImplLock) { |
Wonsik Kim | 7587d29 | 2014-08-09 10:01:01 +0900 | [diff] [blame] | 1004 | updateAudioConfigLocked(); |
Jungshik Jang | 1f819bb | 2014-08-08 10:46:54 +0900 | [diff] [blame] | 1005 | } |
| 1006 | } |
| 1007 | |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 1008 | @Override |
| 1009 | public void overrideAudioSink(int audioType, String audioAddress, int samplingRate, |
| 1010 | int channelMask, int format) { |
| 1011 | synchronized (mImplLock) { |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 1012 | mOverrideAudioType = audioType; |
| 1013 | mOverrideAudioAddress = audioAddress; |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 1014 | |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 1015 | mDesiredSamplingRate = samplingRate; |
| 1016 | mDesiredChannelMask = channelMask; |
| 1017 | mDesiredFormat = format; |
| 1018 | |
Wonsik Kim | 7587d29 | 2014-08-09 10:01:01 +0900 | [diff] [blame] | 1019 | updateAudioConfigLocked(); |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 1020 | } |
| 1021 | } |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 1022 | |
| 1023 | public void onMediaStreamVolumeChanged() { |
| 1024 | synchronized (mImplLock) { |
| 1025 | updateAudioConfigLocked(); |
| 1026 | } |
| 1027 | } |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 1028 | } |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 1029 | |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 1030 | interface Listener { |
| 1031 | public void onStateChanged(String inputId, int state); |
| 1032 | public void onHardwareDeviceAdded(TvInputHardwareInfo info); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 1033 | public void onHardwareDeviceRemoved(TvInputHardwareInfo info); |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 1034 | public void onHdmiDeviceAdded(HdmiDeviceInfo device); |
| 1035 | public void onHdmiDeviceRemoved(HdmiDeviceInfo device); |
Wonsik Kim | e92f857 | 2014-08-12 18:30:24 +0900 | [diff] [blame] | 1036 | public void onHdmiDeviceUpdated(String inputId, HdmiDeviceInfo device); |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 1037 | } |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 1038 | |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 1039 | private class ListenerHandler extends Handler { |
| 1040 | private static final int STATE_CHANGED = 1; |
| 1041 | private static final int HARDWARE_DEVICE_ADDED = 2; |
| 1042 | private static final int HARDWARE_DEVICE_REMOVED = 3; |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 1043 | private static final int HDMI_DEVICE_ADDED = 4; |
| 1044 | private static final int HDMI_DEVICE_REMOVED = 5; |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1045 | private static final int HDMI_DEVICE_UPDATED = 6; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 1046 | |
| 1047 | @Override |
| 1048 | public final void handleMessage(Message msg) { |
| 1049 | switch (msg.what) { |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 1050 | case STATE_CHANGED: { |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 1051 | String inputId = (String) msg.obj; |
| 1052 | int state = msg.arg1; |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 1053 | mListener.onStateChanged(inputId, state); |
| 1054 | break; |
| 1055 | } |
| 1056 | case HARDWARE_DEVICE_ADDED: { |
| 1057 | TvInputHardwareInfo info = (TvInputHardwareInfo) msg.obj; |
| 1058 | mListener.onHardwareDeviceAdded(info); |
| 1059 | break; |
| 1060 | } |
| 1061 | case HARDWARE_DEVICE_REMOVED: { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 1062 | TvInputHardwareInfo info = (TvInputHardwareInfo) msg.obj; |
| 1063 | mListener.onHardwareDeviceRemoved(info); |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 1064 | break; |
| 1065 | } |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 1066 | case HDMI_DEVICE_ADDED: { |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1067 | HdmiDeviceInfo info = (HdmiDeviceInfo) msg.obj; |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 1068 | mListener.onHdmiDeviceAdded(info); |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 1069 | break; |
| 1070 | } |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 1071 | case HDMI_DEVICE_REMOVED: { |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1072 | HdmiDeviceInfo info = (HdmiDeviceInfo) msg.obj; |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 1073 | mListener.onHdmiDeviceRemoved(info); |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 1074 | break; |
| 1075 | } |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1076 | case HDMI_DEVICE_UPDATED: { |
Wonsik Kim | 184a6d6 | 2014-10-08 13:05:56 +0900 | [diff] [blame] | 1077 | HdmiDeviceInfo info = (HdmiDeviceInfo) msg.obj; |
| 1078 | String inputId = null; |
| 1079 | synchronized (mLock) { |
| 1080 | inputId = mHdmiInputIdMap.get(info.getId()); |
| 1081 | } |
| 1082 | if (inputId != null) { |
| 1083 | mListener.onHdmiDeviceUpdated(inputId, info); |
| 1084 | } else { |
| 1085 | Slog.w(TAG, "Could not resolve input ID matching the device info; " |
| 1086 | + "ignoring."); |
| 1087 | } |
| 1088 | break; |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1089 | } |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 1090 | default: { |
| 1091 | Slog.w(TAG, "Unhandled message: " + msg); |
| 1092 | break; |
| 1093 | } |
| 1094 | } |
| 1095 | } |
| 1096 | } |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 1097 | |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 1098 | // Listener implementations for HdmiControlService |
| 1099 | |
| 1100 | private final class HdmiHotplugEventListener extends IHdmiHotplugEventListener.Stub { |
| 1101 | @Override |
| 1102 | public void onReceived(HdmiHotplugEvent event) { |
| 1103 | synchronized (mLock) { |
| 1104 | mHdmiStateMap.put(event.getPort(), event.isConnected()); |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 1105 | TvInputHardwareInfo hardwareInfo = |
| 1106 | findHardwareInfoForHdmiPortLocked(event.getPort()); |
| 1107 | if (hardwareInfo == null) { |
| 1108 | return; |
| 1109 | } |
| 1110 | String inputId = mHardwareInputIdMap.get(hardwareInfo.getDeviceId()); |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 1111 | if (inputId == null) { |
| 1112 | return; |
| 1113 | } |
| 1114 | mHandler.obtainMessage(ListenerHandler.STATE_CHANGED, |
| 1115 | convertConnectedToState(event.isConnected()), 0, inputId).sendToTarget(); |
| 1116 | } |
| 1117 | } |
| 1118 | } |
| 1119 | |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 1120 | private final class HdmiDeviceEventListener extends IHdmiDeviceEventListener.Stub { |
| 1121 | @Override |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1122 | public void onStatusChanged(HdmiDeviceInfo deviceInfo, int status) { |
Jinsuk Kim | 98d760e | 2014-12-23 07:01:51 +0900 | [diff] [blame] | 1123 | if (!deviceInfo.isSourceType()) return; |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 1124 | synchronized (mLock) { |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1125 | int messageType = 0; |
Wonsik Kim | e92f857 | 2014-08-12 18:30:24 +0900 | [diff] [blame] | 1126 | Object obj = null; |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1127 | switch (status) { |
| 1128 | case HdmiControlManager.DEVICE_EVENT_ADD_DEVICE: { |
Jungshik Jang | cf44587 | 2014-08-20 15:06:01 +0900 | [diff] [blame] | 1129 | if (findHdmiDeviceInfo(deviceInfo.getId()) == null) { |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1130 | mHdmiDeviceList.add(deviceInfo); |
| 1131 | } else { |
| 1132 | Slog.w(TAG, "The list already contains " + deviceInfo + "; ignoring."); |
| 1133 | return; |
| 1134 | } |
| 1135 | messageType = ListenerHandler.HDMI_DEVICE_ADDED; |
Wonsik Kim | e92f857 | 2014-08-12 18:30:24 +0900 | [diff] [blame] | 1136 | obj = deviceInfo; |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1137 | break; |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 1138 | } |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1139 | case HdmiControlManager.DEVICE_EVENT_REMOVE_DEVICE: { |
Jungshik Jang | cf44587 | 2014-08-20 15:06:01 +0900 | [diff] [blame] | 1140 | HdmiDeviceInfo originalDeviceInfo = findHdmiDeviceInfo(deviceInfo.getId()); |
| 1141 | if (!mHdmiDeviceList.remove(originalDeviceInfo)) { |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1142 | Slog.w(TAG, "The list doesn't contain " + deviceInfo + "; ignoring."); |
| 1143 | return; |
| 1144 | } |
| 1145 | messageType = ListenerHandler.HDMI_DEVICE_REMOVED; |
Wonsik Kim | e92f857 | 2014-08-12 18:30:24 +0900 | [diff] [blame] | 1146 | obj = deviceInfo; |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1147 | break; |
| 1148 | } |
| 1149 | case HdmiControlManager.DEVICE_EVENT_UPDATE_DEVICE: { |
Jungshik Jang | cf44587 | 2014-08-20 15:06:01 +0900 | [diff] [blame] | 1150 | HdmiDeviceInfo originalDeviceInfo = findHdmiDeviceInfo(deviceInfo.getId()); |
| 1151 | if (!mHdmiDeviceList.remove(originalDeviceInfo)) { |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1152 | Slog.w(TAG, "The list doesn't contain " + deviceInfo + "; ignoring."); |
| 1153 | return; |
| 1154 | } |
| 1155 | mHdmiDeviceList.add(deviceInfo); |
| 1156 | messageType = ListenerHandler.HDMI_DEVICE_UPDATED; |
Wonsik Kim | 184a6d6 | 2014-10-08 13:05:56 +0900 | [diff] [blame] | 1157 | obj = deviceInfo; |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1158 | break; |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 1159 | } |
| 1160 | } |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1161 | |
Wonsik Kim | e92f857 | 2014-08-12 18:30:24 +0900 | [diff] [blame] | 1162 | Message msg = mHandler.obtainMessage(messageType, 0, 0, obj); |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 1163 | if (findHardwareInfoForHdmiPortLocked(deviceInfo.getPortId()) != null) { |
| 1164 | msg.sendToTarget(); |
| 1165 | } else { |
| 1166 | mPendingHdmiDeviceEvents.add(msg); |
| 1167 | } |
| 1168 | } |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 1169 | } |
Jungshik Jang | cf44587 | 2014-08-20 15:06:01 +0900 | [diff] [blame] | 1170 | |
| 1171 | private HdmiDeviceInfo findHdmiDeviceInfo(int id) { |
| 1172 | for (HdmiDeviceInfo info : mHdmiDeviceList) { |
| 1173 | if (info.getId() == id) { |
| 1174 | return info; |
| 1175 | } |
| 1176 | } |
| 1177 | return null; |
| 1178 | } |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 1179 | } |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 1180 | |
Jungshik Jang | 1f819bb | 2014-08-08 10:46:54 +0900 | [diff] [blame] | 1181 | private final class HdmiSystemAudioModeChangeListener extends |
| 1182 | IHdmiSystemAudioModeChangeListener.Stub { |
| 1183 | @Override |
| 1184 | public void onStatusChanged(boolean enabled) throws RemoteException { |
| 1185 | synchronized (mLock) { |
| 1186 | for (int i = 0; i < mConnections.size(); ++i) { |
| 1187 | TvInputHardwareImpl impl = mConnections.valueAt(i).getHardwareImplLocked(); |
Jungshik Jang | 44bb3a5 | 2014-08-26 17:24:24 +0900 | [diff] [blame] | 1188 | if (impl != null) { |
| 1189 | impl.handleAudioSinkUpdated(); |
| 1190 | } |
Jungshik Jang | 1f819bb | 2014-08-08 10:46:54 +0900 | [diff] [blame] | 1191 | } |
| 1192 | } |
| 1193 | } |
| 1194 | } |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 1195 | } |