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