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; |
Wally Yau | ad36f647 | 2015-10-06 11:33:19 -0700 | [diff] [blame^] | 41 | import android.media.AudioSystem; |
Jae Seo | d5cc4a2 | 2014-05-30 16:57:43 -0700 | [diff] [blame] | 42 | import android.media.tv.ITvInputHardware; |
| 43 | import android.media.tv.ITvInputHardwareCallback; |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 44 | import android.media.tv.TvInputHardwareInfo; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 45 | import android.media.tv.TvInputInfo; |
Jae Seo | d5cc4a2 | 2014-05-30 16:57:43 -0700 | [diff] [blame] | 46 | import android.media.tv.TvStreamConfig; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 47 | import android.os.Handler; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 48 | import android.os.IBinder; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 49 | import android.os.Message; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 50 | import android.os.RemoteException; |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 51 | import android.os.ServiceManager; |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 52 | import android.util.ArrayMap; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 53 | import android.util.Slog; |
| 54 | import android.util.SparseArray; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 55 | import android.util.SparseBooleanArray; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 56 | import android.view.KeyEvent; |
| 57 | import android.view.Surface; |
| 58 | |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 59 | import com.android.server.SystemService; |
| 60 | |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 61 | import java.util.ArrayList; |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 62 | import java.util.Collections; |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 63 | import java.util.Iterator; |
| 64 | import java.util.LinkedList; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 65 | import java.util.List; |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 66 | import java.util.Map; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * A helper class for TvInputManagerService to handle TV input hardware. |
| 70 | * |
| 71 | * This class does a basic connection management and forwarding calls to TvInputHal which eventually |
| 72 | * calls to tv_input HAL module. |
| 73 | * |
| 74 | * @hide |
| 75 | */ |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 76 | class TvInputHardwareManager implements TvInputHal.Callback { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 77 | private static final String TAG = TvInputHardwareManager.class.getSimpleName(); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 78 | |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 79 | private final Context mContext; |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 80 | private final Listener mListener; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 81 | private final TvInputHal mHal = new TvInputHal(this); |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 82 | private final SparseArray<Connection> mConnections = new SparseArray<>(); |
| 83 | private final List<TvInputHardwareInfo> mHardwareList = new ArrayList<>(); |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 84 | private final List<HdmiDeviceInfo> mHdmiDeviceList = new LinkedList<>(); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 85 | /* A map from a device ID to the matching TV input ID. */ |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 86 | private final SparseArray<String> mHardwareInputIdMap = new SparseArray<>(); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 87 | /* 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] | 88 | private final SparseArray<String> mHdmiInputIdMap = new SparseArray<>(); |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 89 | private final Map<String, TvInputInfo> mInputMap = new ArrayMap<>(); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 90 | |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 91 | private final AudioManager mAudioManager; |
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) { |
Jae Seo | 38b3257 | 2015-06-05 14:43:11 -0700 | [diff] [blame] | 124 | IHdmiControlService hdmiControlService = IHdmiControlService.Stub.asInterface( |
| 125 | ServiceManager.getService(Context.HDMI_CONTROL_SERVICE)); |
| 126 | if (hdmiControlService != null) { |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 127 | try { |
Jae Seo | 38b3257 | 2015-06-05 14:43:11 -0700 | [diff] [blame] | 128 | hdmiControlService.addHotplugEventListener(mHdmiHotplugEventListener); |
| 129 | hdmiControlService.addDeviceEventListener(mHdmiDeviceEventListener); |
| 130 | hdmiControlService.addSystemAudioModeChangeListener( |
Jungshik Jang | 1f819bb | 2014-08-08 10:46:54 +0900 | [diff] [blame] | 131 | mHdmiSystemAudioModeChangeListener); |
Jae Seo | 38b3257 | 2015-06-05 14:43:11 -0700 | [diff] [blame] | 132 | mHdmiDeviceList.addAll(hdmiControlService.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(); |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 256 | return connectionCallingUid == null || connectionResolvedUserId == null |
| 257 | || connectionCallingUid != callingUid || connectionResolvedUserId != resolvedUserId; |
Wonsik Kim | e7ae0ce | 2014-06-19 00:48:35 +0900 | [diff] [blame] | 258 | } |
| 259 | |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 260 | private int convertConnectedToState(boolean connected) { |
| 261 | if (connected) { |
| 262 | return INPUT_STATE_CONNECTED; |
| 263 | } else { |
| 264 | return INPUT_STATE_DISCONNECTED; |
| 265 | } |
| 266 | } |
| 267 | |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 268 | public void addHardwareTvInput(int deviceId, TvInputInfo info) { |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 269 | synchronized (mLock) { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 270 | String oldInputId = mHardwareInputIdMap.get(deviceId); |
| 271 | if (oldInputId != null) { |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 272 | Slog.w(TAG, "Trying to override previous registration: old = " |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 273 | + mInputMap.get(oldInputId) + ":" + deviceId + ", new = " |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 274 | + info + ":" + deviceId); |
| 275 | } |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 276 | mHardwareInputIdMap.put(deviceId, info.getId()); |
| 277 | mInputMap.put(info.getId(), info); |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 278 | |
Wonsik Kim | 9a10365 | 2014-10-21 17:46:31 +0900 | [diff] [blame] | 279 | // Process pending state changes |
| 280 | |
| 281 | // For logical HDMI devices, they have information from HDMI CEC signals. |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 282 | for (int i = 0; i < mHdmiStateMap.size(); ++i) { |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 283 | TvInputHardwareInfo hardwareInfo = |
| 284 | findHardwareInfoForHdmiPortLocked(mHdmiStateMap.keyAt(i)); |
| 285 | if (hardwareInfo == null) { |
| 286 | continue; |
| 287 | } |
| 288 | String inputId = mHardwareInputIdMap.get(hardwareInfo.getDeviceId()); |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 289 | if (inputId != null && inputId.equals(info.getId())) { |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 290 | mHandler.obtainMessage(ListenerHandler.STATE_CHANGED, |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 291 | convertConnectedToState(mHdmiStateMap.valueAt(i)), 0, |
| 292 | inputId).sendToTarget(); |
Wonsik Kim | 9a10365 | 2014-10-21 17:46:31 +0900 | [diff] [blame] | 293 | return; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 294 | } |
| 295 | } |
Wonsik Kim | 9a10365 | 2014-10-21 17:46:31 +0900 | [diff] [blame] | 296 | // For the rest of the devices, we can tell by the number of available streams. |
| 297 | Connection connection = mConnections.get(deviceId); |
| 298 | if (connection != null) { |
| 299 | mHandler.obtainMessage(ListenerHandler.STATE_CHANGED, |
| 300 | convertConnectedToState(connection.getConfigsLocked().length > 0), 0, |
| 301 | info.getId()).sendToTarget(); |
Wonsik Kim | 9a10365 | 2014-10-21 17:46:31 +0900 | [diff] [blame] | 302 | } |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | |
Wonsik Kim | 38feae9 | 2014-07-21 21:35:50 +0900 | [diff] [blame] | 306 | private static <T> int indexOfEqualValue(SparseArray<T> map, T value) { |
| 307 | for (int i = 0; i < map.size(); ++i) { |
| 308 | if (map.valueAt(i).equals(value)) { |
| 309 | return i; |
| 310 | } |
| 311 | } |
| 312 | return -1; |
| 313 | } |
| 314 | |
Wonsik Kim | 71dfa96 | 2014-11-15 14:18:49 +0900 | [diff] [blame] | 315 | private static boolean intArrayContains(int[] array, int value) { |
| 316 | for (int element : array) { |
| 317 | if (element == value) return true; |
| 318 | } |
| 319 | return false; |
| 320 | } |
| 321 | |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 322 | public void addHdmiTvInput(int id, TvInputInfo info) { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 323 | if (info.getType() != TvInputInfo.TYPE_HDMI) { |
| 324 | throw new IllegalArgumentException("info (" + info + ") has non-HDMI type."); |
| 325 | } |
| 326 | synchronized (mLock) { |
| 327 | String parentId = info.getParentId(); |
Wonsik Kim | 38feae9 | 2014-07-21 21:35:50 +0900 | [diff] [blame] | 328 | int parentIndex = indexOfEqualValue(mHardwareInputIdMap, parentId); |
| 329 | if (parentIndex < 0) { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 330 | throw new IllegalArgumentException("info (" + info + ") has invalid parentId."); |
| 331 | } |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 332 | String oldInputId = mHdmiInputIdMap.get(id); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 333 | if (oldInputId != null) { |
| 334 | Slog.w(TAG, "Trying to override previous registration: old = " |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 335 | + mInputMap.get(oldInputId) + ":" + id + ", new = " |
| 336 | + info + ":" + id); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 337 | } |
Jinsuk Kim | 8960d1b | 2014-08-13 10:48:30 +0900 | [diff] [blame] | 338 | mHdmiInputIdMap.put(id, info.getId()); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 339 | mInputMap.put(info.getId(), info); |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | public void removeTvInput(String inputId) { |
| 344 | synchronized (mLock) { |
| 345 | mInputMap.remove(inputId); |
Wonsik Kim | 38feae9 | 2014-07-21 21:35:50 +0900 | [diff] [blame] | 346 | int hardwareIndex = indexOfEqualValue(mHardwareInputIdMap, inputId); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 347 | if (hardwareIndex >= 0) { |
| 348 | mHardwareInputIdMap.removeAt(hardwareIndex); |
| 349 | } |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 350 | int deviceIndex = indexOfEqualValue(mHdmiInputIdMap, inputId); |
| 351 | if (deviceIndex >= 0) { |
| 352 | mHdmiInputIdMap.removeAt(deviceIndex); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | } |
| 356 | |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 357 | /** |
| 358 | * Create a TvInputHardware object with a specific deviceId. One service at a time can access |
| 359 | * the object, and if more than one process attempts to create hardware with the same deviceId, |
| 360 | * the latest service will get the object and all the other hardware are released. The |
| 361 | * release is notified via ITvInputHardwareCallback.onReleased(). |
| 362 | */ |
| 363 | public ITvInputHardware acquireHardware(int deviceId, ITvInputHardwareCallback callback, |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 364 | TvInputInfo info, int callingUid, int resolvedUserId) { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 365 | if (callback == null) { |
| 366 | throw new NullPointerException(); |
| 367 | } |
| 368 | synchronized (mLock) { |
| 369 | Connection connection = mConnections.get(deviceId); |
| 370 | if (connection == null) { |
| 371 | Slog.e(TAG, "Invalid deviceId : " + deviceId); |
| 372 | return null; |
| 373 | } |
Wonsik Kim | e7ae0ce | 2014-06-19 00:48:35 +0900 | [diff] [blame] | 374 | if (checkUidChangedLocked(connection, callingUid, resolvedUserId)) { |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 375 | TvInputHardwareImpl hardware = |
| 376 | new TvInputHardwareImpl(connection.getHardwareInfoLocked()); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 377 | try { |
| 378 | callback.asBinder().linkToDeath(connection, 0); |
| 379 | } catch (RemoteException e) { |
| 380 | hardware.release(); |
| 381 | return null; |
| 382 | } |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 383 | connection.resetLocked(hardware, callback, info, callingUid, resolvedUserId); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 384 | } |
| 385 | return connection.getHardwareLocked(); |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | /** |
| 390 | * Release the specified hardware. |
| 391 | */ |
| 392 | public void releaseHardware(int deviceId, ITvInputHardware hardware, int callingUid, |
| 393 | int resolvedUserId) { |
| 394 | synchronized (mLock) { |
| 395 | Connection connection = mConnections.get(deviceId); |
| 396 | if (connection == null) { |
| 397 | Slog.e(TAG, "Invalid deviceId : " + deviceId); |
| 398 | return; |
| 399 | } |
| 400 | if (connection.getHardwareLocked() != hardware |
Wonsik Kim | e7ae0ce | 2014-06-19 00:48:35 +0900 | [diff] [blame] | 401 | || checkUidChangedLocked(connection, callingUid, resolvedUserId)) { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 402 | return; |
| 403 | } |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 404 | connection.resetLocked(null, null, null, null, null); |
| 405 | } |
| 406 | } |
| 407 | |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 408 | private TvInputHardwareInfo findHardwareInfoForHdmiPortLocked(int port) { |
| 409 | for (TvInputHardwareInfo hardwareInfo : mHardwareList) { |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 410 | if (hardwareInfo.getType() == TvInputHardwareInfo.TV_INPUT_TYPE_HDMI |
| 411 | && hardwareInfo.getHdmiPortId() == port) { |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 412 | return hardwareInfo; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 413 | } |
| 414 | } |
| 415 | return null; |
| 416 | } |
| 417 | |
Terry Heo | c086a3d | 2014-06-18 14:26:44 +0900 | [diff] [blame] | 418 | private int findDeviceIdForInputIdLocked(String inputId) { |
| 419 | for (int i = 0; i < mConnections.size(); ++i) { |
| 420 | Connection connection = mConnections.get(i); |
| 421 | if (connection.getInfoLocked().getId().equals(inputId)) { |
| 422 | return i; |
| 423 | } |
| 424 | } |
| 425 | return -1; |
| 426 | } |
| 427 | |
| 428 | /** |
| 429 | * Get the list of TvStreamConfig which is buffered mode. |
| 430 | */ |
| 431 | public List<TvStreamConfig> getAvailableTvStreamConfigList(String inputId, int callingUid, |
| 432 | int resolvedUserId) { |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 433 | List<TvStreamConfig> configsList = new ArrayList<>(); |
Terry Heo | c086a3d | 2014-06-18 14:26:44 +0900 | [diff] [blame] | 434 | synchronized (mLock) { |
| 435 | int deviceId = findDeviceIdForInputIdLocked(inputId); |
| 436 | if (deviceId < 0) { |
| 437 | Slog.e(TAG, "Invalid inputId : " + inputId); |
| 438 | return configsList; |
| 439 | } |
| 440 | Connection connection = mConnections.get(deviceId); |
| 441 | for (TvStreamConfig config : connection.getConfigsLocked()) { |
| 442 | if (config.getType() == TvStreamConfig.STREAM_TYPE_BUFFER_PRODUCER) { |
| 443 | configsList.add(config); |
| 444 | } |
| 445 | } |
| 446 | } |
| 447 | return configsList; |
| 448 | } |
| 449 | |
| 450 | /** |
| 451 | * Take a snapshot of the given TV input into the provided Surface. |
| 452 | */ |
| 453 | public boolean captureFrame(String inputId, Surface surface, final TvStreamConfig config, |
| 454 | int callingUid, int resolvedUserId) { |
| 455 | synchronized (mLock) { |
| 456 | int deviceId = findDeviceIdForInputIdLocked(inputId); |
| 457 | if (deviceId < 0) { |
| 458 | Slog.e(TAG, "Invalid inputId : " + inputId); |
| 459 | return false; |
| 460 | } |
| 461 | Connection connection = mConnections.get(deviceId); |
| 462 | final TvInputHardwareImpl hardwareImpl = connection.getHardwareImplLocked(); |
| 463 | if (hardwareImpl != null) { |
| 464 | // Stop previous capture. |
| 465 | Runnable runnable = connection.getOnFirstFrameCapturedLocked(); |
| 466 | if (runnable != null) { |
| 467 | runnable.run(); |
| 468 | connection.setOnFirstFrameCapturedLocked(null); |
| 469 | } |
| 470 | |
| 471 | boolean result = hardwareImpl.startCapture(surface, config); |
| 472 | if (result) { |
| 473 | connection.setOnFirstFrameCapturedLocked(new Runnable() { |
| 474 | @Override |
| 475 | public void run() { |
| 476 | hardwareImpl.stopCapture(config); |
| 477 | } |
| 478 | }); |
| 479 | } |
| 480 | return result; |
| 481 | } |
| 482 | } |
| 483 | return false; |
| 484 | } |
| 485 | |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 486 | private void processPendingHdmiDeviceEventsLocked() { |
| 487 | for (Iterator<Message> it = mPendingHdmiDeviceEvents.iterator(); it.hasNext(); ) { |
| 488 | Message msg = it.next(); |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 489 | HdmiDeviceInfo deviceInfo = (HdmiDeviceInfo) msg.obj; |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 490 | TvInputHardwareInfo hardwareInfo = |
| 491 | findHardwareInfoForHdmiPortLocked(deviceInfo.getPortId()); |
| 492 | if (hardwareInfo != null) { |
| 493 | msg.sendToTarget(); |
| 494 | it.remove(); |
| 495 | } |
| 496 | } |
| 497 | } |
| 498 | |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 499 | private void updateVolume() { |
| 500 | mCurrentMaxIndex = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); |
| 501 | mCurrentIndex = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); |
| 502 | } |
| 503 | |
| 504 | private void handleVolumeChange(Context context, Intent intent) { |
| 505 | String action = intent.getAction(); |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 506 | switch (action) { |
| 507 | case AudioManager.VOLUME_CHANGED_ACTION: { |
| 508 | int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1); |
| 509 | if (streamType != AudioManager.STREAM_MUSIC) { |
| 510 | return; |
| 511 | } |
| 512 | int index = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, 0); |
| 513 | if (index == mCurrentIndex) { |
| 514 | return; |
| 515 | } |
| 516 | mCurrentIndex = index; |
| 517 | break; |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 518 | } |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 519 | case AudioManager.STREAM_MUTE_CHANGED_ACTION: { |
| 520 | int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1); |
| 521 | if (streamType != AudioManager.STREAM_MUSIC) { |
| 522 | return; |
| 523 | } |
| 524 | // volume index will be updated at onMediaStreamVolumeChanged() through |
| 525 | // updateVolume(). |
| 526 | break; |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 527 | } |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 528 | default: |
| 529 | Slog.w(TAG, "Unrecognized intent: " + intent); |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 530 | return; |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 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(); |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 695 | ArrayList<AudioDevicePort> devicePorts = new ArrayList<>(); |
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) { |
Wally Yau | ad36f647 | 2015-10-06 11:33:19 -0700 | [diff] [blame^] | 701 | if ((port.type() & sinkDevice) != 0 && |
| 702 | (port.type() & AudioSystem.DEVICE_BIT_IN) == 0) { |
Paul McLean | ceb47aa | 2015-02-19 15:09:53 -0800 | [diff] [blame] | 703 | sinks.add(port); |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 704 | } |
| 705 | } |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | private AudioDevicePort findAudioDevicePort(int type, String address) { |
| 709 | if (type == AudioManager.DEVICE_NONE) { |
| 710 | return null; |
| 711 | } |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 712 | ArrayList<AudioDevicePort> devicePorts = new ArrayList<>(); |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 713 | if (mAudioManager.listAudioDevicePorts(devicePorts) != AudioManager.SUCCESS) { |
| 714 | return null; |
| 715 | } |
Paul McLean | ceb47aa | 2015-02-19 15:09:53 -0800 | [diff] [blame] | 716 | for (AudioDevicePort port : devicePorts) { |
| 717 | if (port.type() == type && port.address().equals(address)) { |
| 718 | return port; |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 719 | } |
| 720 | } |
| 721 | return null; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | public void release() { |
| 725 | synchronized (mImplLock) { |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 726 | mAudioManager.unregisterAudioPortUpdateListener(mAudioListener); |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 727 | if (mAudioPatch != null) { |
| 728 | mAudioManager.releaseAudioPatch(mAudioPatch); |
| 729 | mAudioPatch = null; |
| 730 | } |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 731 | mReleased = true; |
| 732 | } |
| 733 | } |
| 734 | |
Wonsik Kim | 839ae5f | 2014-07-03 19:06:56 +0900 | [diff] [blame] | 735 | // A TvInputHardwareImpl object holds only one active session. Therefore, if a client |
| 736 | // attempts to call setSurface with different TvStreamConfig objects, the last call will |
| 737 | // prevail. |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 738 | @Override |
| 739 | public boolean setSurface(Surface surface, TvStreamConfig config) |
| 740 | throws RemoteException { |
| 741 | synchronized (mImplLock) { |
| 742 | if (mReleased) { |
| 743 | throw new IllegalStateException("Device already released."); |
| 744 | } |
Wonsik Kim | 7587d29 | 2014-08-09 10:01:01 +0900 | [diff] [blame] | 745 | |
Wonsik Kim | 102670f | 2014-11-20 14:38:02 +0900 | [diff] [blame] | 746 | int result = TvInputHal.SUCCESS; |
Wonsik Kim | 839ae5f | 2014-07-03 19:06:56 +0900 | [diff] [blame] | 747 | if (surface == null) { |
Wonsik Kim | b683e6e | 2014-11-17 16:31:39 +0900 | [diff] [blame] | 748 | // The value of config is ignored when surface == null. |
| 749 | if (mActiveConfig != null) { |
| 750 | result = mHal.removeStream(mInfo.getDeviceId(), mActiveConfig); |
| 751 | mActiveConfig = null; |
| 752 | } else { |
| 753 | // We already have no active stream. |
| 754 | return true; |
| 755 | } |
Wonsik Kim | 839ae5f | 2014-07-03 19:06:56 +0900 | [diff] [blame] | 756 | } else { |
Wonsik Kim | b683e6e | 2014-11-17 16:31:39 +0900 | [diff] [blame] | 757 | // It's impossible to set a non-null surface with a null config. |
| 758 | if (config == null) { |
| 759 | return false; |
| 760 | } |
| 761 | // Remove stream only if we have an existing active configuration. |
| 762 | if (mActiveConfig != null && !config.equals(mActiveConfig)) { |
Wonsik Kim | 839ae5f | 2014-07-03 19:06:56 +0900 | [diff] [blame] | 763 | result = mHal.removeStream(mInfo.getDeviceId(), mActiveConfig); |
| 764 | if (result != TvInputHal.SUCCESS) { |
| 765 | mActiveConfig = null; |
Wonsik Kim | 839ae5f | 2014-07-03 19:06:56 +0900 | [diff] [blame] | 766 | } |
| 767 | } |
Wonsik Kim | b683e6e | 2014-11-17 16:31:39 +0900 | [diff] [blame] | 768 | // Proceed only if all previous operations succeeded. |
Wonsik Kim | 839ae5f | 2014-07-03 19:06:56 +0900 | [diff] [blame] | 769 | if (result == TvInputHal.SUCCESS) { |
Wonsik Kim | b683e6e | 2014-11-17 16:31:39 +0900 | [diff] [blame] | 770 | result = mHal.addOrUpdateStream(mInfo.getDeviceId(), surface, config); |
| 771 | if (result == TvInputHal.SUCCESS) { |
| 772 | mActiveConfig = config; |
| 773 | } |
Wonsik Kim | 839ae5f | 2014-07-03 19:06:56 +0900 | [diff] [blame] | 774 | } |
| 775 | } |
Wonsik Kim | 7587d29 | 2014-08-09 10:01:01 +0900 | [diff] [blame] | 776 | updateAudioConfigLocked(); |
Wonsik Kim | 839ae5f | 2014-07-03 19:06:56 +0900 | [diff] [blame] | 777 | return result == TvInputHal.SUCCESS; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 778 | } |
| 779 | } |
| 780 | |
Wonsik Kim | 7587d29 | 2014-08-09 10:01:01 +0900 | [diff] [blame] | 781 | /** |
| 782 | * Update audio configuration (source, sink, patch) all up to current state. |
| 783 | */ |
| 784 | private void updateAudioConfigLocked() { |
| 785 | boolean sinkUpdated = updateAudioSinkLocked(); |
| 786 | boolean sourceUpdated = updateAudioSourceLocked(); |
| 787 | // We can't do updated = updateAudioSinkLocked() || updateAudioSourceLocked() here |
| 788 | // because Java won't evaluate the latter if the former is true. |
| 789 | |
Wonsik Kim | b2b85f9 | 2015-01-19 16:07:48 +0900 | [diff] [blame] | 790 | if (mAudioSource == null || mAudioSink.isEmpty() || mActiveConfig == null) { |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 791 | if (mAudioPatch != null) { |
Wonsik Kim | 7587d29 | 2014-08-09 10:01:01 +0900 | [diff] [blame] | 792 | mAudioManager.releaseAudioPatch(mAudioPatch); |
| 793 | mAudioPatch = null; |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 794 | } |
| 795 | return; |
| 796 | } |
| 797 | |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 798 | updateVolume(); |
| 799 | float volume = mSourceVolume * getMediaStreamVolume(); |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 800 | AudioGainConfig sourceGainConfig = null; |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 801 | if (mAudioSource.gains().length > 0 && volume != mCommittedVolume) { |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 802 | AudioGain sourceGain = null; |
| 803 | for (AudioGain gain : mAudioSource.gains()) { |
| 804 | if ((gain.mode() & AudioGain.MODE_JOINT) != 0) { |
| 805 | sourceGain = gain; |
| 806 | break; |
| 807 | } |
| 808 | } |
| 809 | // NOTE: we only change the source gain in MODE_JOINT here. |
| 810 | if (sourceGain != null) { |
| 811 | int steps = (sourceGain.maxValue() - sourceGain.minValue()) |
| 812 | / sourceGain.stepValue(); |
| 813 | int gainValue = sourceGain.minValue(); |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 814 | if (volume < 1.0f) { |
| 815 | gainValue += sourceGain.stepValue() * (int) (volume * steps + 0.5); |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 816 | } else { |
| 817 | gainValue = sourceGain.maxValue(); |
| 818 | } |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 819 | // size of gain values is 1 in MODE_JOINT |
| 820 | int[] gainValues = new int[] { gainValue }; |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 821 | sourceGainConfig = sourceGain.buildConfig(AudioGain.MODE_JOINT, |
| 822 | sourceGain.channelMask(), gainValues, 0); |
| 823 | } else { |
| 824 | Slog.w(TAG, "No audio source gain with MODE_JOINT support exists."); |
| 825 | } |
| 826 | } |
| 827 | |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 828 | AudioPortConfig sourceConfig = mAudioSource.activeConfig(); |
Wonsik Kim | b2b85f9 | 2015-01-19 16:07:48 +0900 | [diff] [blame] | 829 | List<AudioPortConfig> sinkConfigs = new ArrayList<>(); |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 830 | AudioPatch[] audioPatchArray = new AudioPatch[] { mAudioPatch }; |
Wonsik Kim | 7587d29 | 2014-08-09 10:01:01 +0900 | [diff] [blame] | 831 | boolean shouldRecreateAudioPatch = sourceUpdated || sinkUpdated; |
Wonsik Kim | 71dfa96 | 2014-11-15 14:18:49 +0900 | [diff] [blame] | 832 | |
Wonsik Kim | b2b85f9 | 2015-01-19 16:07:48 +0900 | [diff] [blame] | 833 | for (AudioDevicePort audioSink : mAudioSink) { |
| 834 | AudioPortConfig sinkConfig = audioSink.activeConfig(); |
| 835 | int sinkSamplingRate = mDesiredSamplingRate; |
| 836 | int sinkChannelMask = mDesiredChannelMask; |
| 837 | int sinkFormat = mDesiredFormat; |
| 838 | // If sinkConfig != null and values are set to default, |
| 839 | // fill in the sinkConfig values. |
| 840 | if (sinkConfig != null) { |
| 841 | if (sinkSamplingRate == 0) { |
| 842 | sinkSamplingRate = sinkConfig.samplingRate(); |
| 843 | } |
| 844 | if (sinkChannelMask == AudioFormat.CHANNEL_OUT_DEFAULT) { |
| 845 | sinkChannelMask = sinkConfig.channelMask(); |
| 846 | } |
| 847 | if (sinkFormat == AudioFormat.ENCODING_DEFAULT) { |
| 848 | sinkChannelMask = sinkConfig.format(); |
| 849 | } |
Wonsik Kim | 71dfa96 | 2014-11-15 14:18:49 +0900 | [diff] [blame] | 850 | } |
Wonsik Kim | 71dfa96 | 2014-11-15 14:18:49 +0900 | [diff] [blame] | 851 | |
Wonsik Kim | b2b85f9 | 2015-01-19 16:07:48 +0900 | [diff] [blame] | 852 | if (sinkConfig == null |
| 853 | || sinkConfig.samplingRate() != sinkSamplingRate |
| 854 | || sinkConfig.channelMask() != sinkChannelMask |
| 855 | || sinkConfig.format() != sinkFormat) { |
| 856 | // Check for compatibility and reset to default if necessary. |
| 857 | if (!intArrayContains(audioSink.samplingRates(), sinkSamplingRate) |
| 858 | && audioSink.samplingRates().length > 0) { |
| 859 | sinkSamplingRate = audioSink.samplingRates()[0]; |
| 860 | } |
| 861 | if (!intArrayContains(audioSink.channelMasks(), sinkChannelMask)) { |
| 862 | sinkChannelMask = AudioFormat.CHANNEL_OUT_DEFAULT; |
| 863 | } |
| 864 | if (!intArrayContains(audioSink.formats(), sinkFormat)) { |
| 865 | sinkFormat = AudioFormat.ENCODING_DEFAULT; |
| 866 | } |
| 867 | sinkConfig = audioSink.buildConfig(sinkSamplingRate, sinkChannelMask, |
| 868 | sinkFormat, null); |
| 869 | shouldRecreateAudioPatch = true; |
Wonsik Kim | 71dfa96 | 2014-11-15 14:18:49 +0900 | [diff] [blame] | 870 | } |
Wonsik Kim | b2b85f9 | 2015-01-19 16:07:48 +0900 | [diff] [blame] | 871 | sinkConfigs.add(sinkConfig); |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 872 | } |
Wonsik Kim | b2b85f9 | 2015-01-19 16:07:48 +0900 | [diff] [blame] | 873 | // sinkConfigs.size() == mAudioSink.size(), and mAudioSink is guaranteed to be |
| 874 | // non-empty at the beginning of this method. |
| 875 | AudioPortConfig sinkConfig = sinkConfigs.get(0); |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 876 | if (sourceConfig == null || sourceGainConfig != null) { |
Wonsik Kim | 71dfa96 | 2014-11-15 14:18:49 +0900 | [diff] [blame] | 877 | int sourceSamplingRate = 0; |
| 878 | if (intArrayContains(mAudioSource.samplingRates(), sinkConfig.samplingRate())) { |
| 879 | sourceSamplingRate = sinkConfig.samplingRate(); |
| 880 | } else if (mAudioSource.samplingRates().length > 0) { |
| 881 | // Use any sampling rate and hope audio patch can handle resampling... |
| 882 | sourceSamplingRate = mAudioSource.samplingRates()[0]; |
| 883 | } |
| 884 | int sourceChannelMask = AudioFormat.CHANNEL_IN_DEFAULT; |
| 885 | for (int inChannelMask : mAudioSource.channelMasks()) { |
| 886 | if (AudioFormat.channelCountFromOutChannelMask(sinkConfig.channelMask()) |
| 887 | == AudioFormat.channelCountFromInChannelMask(inChannelMask)) { |
| 888 | sourceChannelMask = inChannelMask; |
| 889 | break; |
| 890 | } |
| 891 | } |
| 892 | int sourceFormat = AudioFormat.ENCODING_DEFAULT; |
| 893 | if (intArrayContains(mAudioSource.formats(), sinkConfig.format())) { |
| 894 | sourceFormat = sinkConfig.format(); |
| 895 | } |
| 896 | sourceConfig = mAudioSource.buildConfig(sourceSamplingRate, sourceChannelMask, |
| 897 | sourceFormat, sourceGainConfig); |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 898 | shouldRecreateAudioPatch = true; |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 899 | } |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 900 | if (shouldRecreateAudioPatch) { |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 901 | mCommittedVolume = volume; |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 902 | mAudioManager.createAudioPatch( |
| 903 | audioPatchArray, |
| 904 | new AudioPortConfig[] { sourceConfig }, |
Jae Seo | 93ff14b | 2015-06-21 14:08:54 -0700 | [diff] [blame] | 905 | sinkConfigs.toArray(new AudioPortConfig[sinkConfigs.size()])); |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 906 | mAudioPatch = audioPatchArray[0]; |
Wonsik Kim | 71dfa96 | 2014-11-15 14:18:49 +0900 | [diff] [blame] | 907 | if (sourceGainConfig != null) { |
| 908 | mAudioManager.setAudioPortGain(mAudioSource, sourceGainConfig); |
| 909 | } |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 910 | } |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 911 | } |
| 912 | |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 913 | @Override |
Wonsik Kim | 8e45a33 | 2014-08-04 10:17:18 +0900 | [diff] [blame] | 914 | public void setStreamVolume(float volume) throws RemoteException { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 915 | synchronized (mImplLock) { |
| 916 | if (mReleased) { |
| 917 | throw new IllegalStateException("Device already released."); |
| 918 | } |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 919 | mSourceVolume = volume; |
Wonsik Kim | 7587d29 | 2014-08-09 10:01:01 +0900 | [diff] [blame] | 920 | updateAudioConfigLocked(); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 921 | } |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | @Override |
| 925 | public boolean dispatchKeyEventToHdmi(KeyEvent event) throws RemoteException { |
| 926 | synchronized (mImplLock) { |
| 927 | if (mReleased) { |
| 928 | throw new IllegalStateException("Device already released."); |
| 929 | } |
| 930 | } |
Wonsik Kim | 610ccd9 | 2014-07-19 18:49:49 +0900 | [diff] [blame] | 931 | if (mInfo.getType() != TvInputHardwareInfo.TV_INPUT_TYPE_HDMI) { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 932 | return false; |
| 933 | } |
| 934 | // TODO(hdmi): mHdmiClient.sendKeyEvent(event); |
| 935 | return false; |
| 936 | } |
Terry Heo | c086a3d | 2014-06-18 14:26:44 +0900 | [diff] [blame] | 937 | |
| 938 | private boolean startCapture(Surface surface, TvStreamConfig config) { |
| 939 | synchronized (mImplLock) { |
| 940 | if (mReleased) { |
| 941 | return false; |
| 942 | } |
| 943 | if (surface == null || config == null) { |
| 944 | return false; |
| 945 | } |
| 946 | if (config.getType() != TvStreamConfig.STREAM_TYPE_BUFFER_PRODUCER) { |
| 947 | return false; |
| 948 | } |
| 949 | |
Wonsik Kim | 8f24a8b | 2014-10-22 16:27:39 +0900 | [diff] [blame] | 950 | int result = mHal.addOrUpdateStream(mInfo.getDeviceId(), surface, config); |
Terry Heo | c086a3d | 2014-06-18 14:26:44 +0900 | [diff] [blame] | 951 | return result == TvInputHal.SUCCESS; |
| 952 | } |
| 953 | } |
| 954 | |
| 955 | private boolean stopCapture(TvStreamConfig config) { |
| 956 | synchronized (mImplLock) { |
| 957 | if (mReleased) { |
| 958 | return false; |
| 959 | } |
| 960 | if (config == null) { |
| 961 | return false; |
| 962 | } |
| 963 | |
| 964 | int result = mHal.removeStream(mInfo.getDeviceId(), config); |
| 965 | return result == TvInputHal.SUCCESS; |
| 966 | } |
| 967 | } |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 968 | |
Wonsik Kim | 7587d29 | 2014-08-09 10:01:01 +0900 | [diff] [blame] | 969 | private boolean updateAudioSourceLocked() { |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 970 | if (mInfo.getAudioType() == AudioManager.DEVICE_NONE) { |
Wonsik Kim | 7587d29 | 2014-08-09 10:01:01 +0900 | [diff] [blame] | 971 | return false; |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 972 | } |
Wonsik Kim | 7587d29 | 2014-08-09 10:01:01 +0900 | [diff] [blame] | 973 | AudioDevicePort previousSource = mAudioSource; |
| 974 | mAudioSource = findAudioDevicePort(mInfo.getAudioType(), mInfo.getAudioAddress()); |
| 975 | return mAudioSource == null ? (previousSource != null) |
| 976 | : !mAudioSource.equals(previousSource); |
| 977 | } |
| 978 | |
| 979 | private boolean updateAudioSinkLocked() { |
| 980 | if (mInfo.getAudioType() == AudioManager.DEVICE_NONE) { |
| 981 | return false; |
| 982 | } |
Wonsik Kim | b2b85f9 | 2015-01-19 16:07:48 +0900 | [diff] [blame] | 983 | List<AudioDevicePort> previousSink = mAudioSink; |
| 984 | mAudioSink = new ArrayList<>(); |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 985 | if (mOverrideAudioType == AudioManager.DEVICE_NONE) { |
Wonsik Kim | b2b85f9 | 2015-01-19 16:07:48 +0900 | [diff] [blame] | 986 | findAudioSinkFromAudioPolicy(mAudioSink); |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 987 | } else { |
| 988 | AudioDevicePort audioSink = |
| 989 | findAudioDevicePort(mOverrideAudioType, mOverrideAudioAddress); |
| 990 | if (audioSink != null) { |
Wonsik Kim | b2b85f9 | 2015-01-19 16:07:48 +0900 | [diff] [blame] | 991 | mAudioSink.add(audioSink); |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 992 | } |
| 993 | } |
Wonsik Kim | b2b85f9 | 2015-01-19 16:07:48 +0900 | [diff] [blame] | 994 | |
| 995 | // Returns true if mAudioSink and previousSink differs. |
| 996 | if (mAudioSink.size() != previousSink.size()) { |
| 997 | return true; |
| 998 | } |
| 999 | previousSink.removeAll(mAudioSink); |
| 1000 | return !previousSink.isEmpty(); |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 1001 | } |
| 1002 | |
Jungshik Jang | 1f819bb | 2014-08-08 10:46:54 +0900 | [diff] [blame] | 1003 | private void handleAudioSinkUpdated() { |
| 1004 | synchronized (mImplLock) { |
Wonsik Kim | 7587d29 | 2014-08-09 10:01:01 +0900 | [diff] [blame] | 1005 | updateAudioConfigLocked(); |
Jungshik Jang | 1f819bb | 2014-08-08 10:46:54 +0900 | [diff] [blame] | 1006 | } |
| 1007 | } |
| 1008 | |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 1009 | @Override |
| 1010 | public void overrideAudioSink(int audioType, String audioAddress, int samplingRate, |
| 1011 | int channelMask, int format) { |
| 1012 | synchronized (mImplLock) { |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 1013 | mOverrideAudioType = audioType; |
| 1014 | mOverrideAudioAddress = audioAddress; |
Wonsik Kim | 06c41a3 | 2014-08-04 18:57:47 +0900 | [diff] [blame] | 1015 | |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 1016 | mDesiredSamplingRate = samplingRate; |
| 1017 | mDesiredChannelMask = channelMask; |
| 1018 | mDesiredFormat = format; |
| 1019 | |
Wonsik Kim | 7587d29 | 2014-08-09 10:01:01 +0900 | [diff] [blame] | 1020 | updateAudioConfigLocked(); |
Wonsik Kim | ca17a90 | 2014-07-31 10:09:46 +0900 | [diff] [blame] | 1021 | } |
| 1022 | } |
Wonsik Kim | 49e5593 | 2014-12-04 17:22:09 +0900 | [diff] [blame] | 1023 | |
| 1024 | public void onMediaStreamVolumeChanged() { |
| 1025 | synchronized (mImplLock) { |
| 1026 | updateAudioConfigLocked(); |
| 1027 | } |
| 1028 | } |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 1029 | } |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 1030 | |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 1031 | interface Listener { |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 1032 | void onStateChanged(String inputId, int state); |
| 1033 | void onHardwareDeviceAdded(TvInputHardwareInfo info); |
| 1034 | void onHardwareDeviceRemoved(TvInputHardwareInfo info); |
| 1035 | void onHdmiDeviceAdded(HdmiDeviceInfo device); |
| 1036 | void onHdmiDeviceRemoved(HdmiDeviceInfo device); |
| 1037 | void onHdmiDeviceUpdated(String inputId, HdmiDeviceInfo device); |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 1038 | } |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 1039 | |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 1040 | private class ListenerHandler extends Handler { |
| 1041 | private static final int STATE_CHANGED = 1; |
| 1042 | private static final int HARDWARE_DEVICE_ADDED = 2; |
| 1043 | private static final int HARDWARE_DEVICE_REMOVED = 3; |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 1044 | private static final int HDMI_DEVICE_ADDED = 4; |
| 1045 | private static final int HDMI_DEVICE_REMOVED = 5; |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1046 | private static final int HDMI_DEVICE_UPDATED = 6; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 1047 | |
| 1048 | @Override |
| 1049 | public final void handleMessage(Message msg) { |
| 1050 | switch (msg.what) { |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 1051 | case STATE_CHANGED: { |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 1052 | String inputId = (String) msg.obj; |
| 1053 | int state = msg.arg1; |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 1054 | mListener.onStateChanged(inputId, state); |
| 1055 | break; |
| 1056 | } |
| 1057 | case HARDWARE_DEVICE_ADDED: { |
| 1058 | TvInputHardwareInfo info = (TvInputHardwareInfo) msg.obj; |
| 1059 | mListener.onHardwareDeviceAdded(info); |
| 1060 | break; |
| 1061 | } |
| 1062 | case HARDWARE_DEVICE_REMOVED: { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 1063 | TvInputHardwareInfo info = (TvInputHardwareInfo) msg.obj; |
| 1064 | mListener.onHardwareDeviceRemoved(info); |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 1065 | break; |
| 1066 | } |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 1067 | case HDMI_DEVICE_ADDED: { |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1068 | HdmiDeviceInfo info = (HdmiDeviceInfo) msg.obj; |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 1069 | mListener.onHdmiDeviceAdded(info); |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 1070 | break; |
| 1071 | } |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 1072 | case HDMI_DEVICE_REMOVED: { |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 1073 | HdmiDeviceInfo info = (HdmiDeviceInfo) msg.obj; |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 1074 | mListener.onHdmiDeviceRemoved(info); |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 1075 | break; |
| 1076 | } |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1077 | case HDMI_DEVICE_UPDATED: { |
Wonsik Kim | 184a6d6 | 2014-10-08 13:05:56 +0900 | [diff] [blame] | 1078 | HdmiDeviceInfo info = (HdmiDeviceInfo) msg.obj; |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 1079 | String inputId; |
Wonsik Kim | 184a6d6 | 2014-10-08 13:05:56 +0900 | [diff] [blame] | 1080 | synchronized (mLock) { |
| 1081 | inputId = mHdmiInputIdMap.get(info.getId()); |
| 1082 | } |
| 1083 | if (inputId != null) { |
| 1084 | mListener.onHdmiDeviceUpdated(inputId, info); |
| 1085 | } else { |
| 1086 | Slog.w(TAG, "Could not resolve input ID matching the device info; " |
| 1087 | + "ignoring."); |
| 1088 | } |
| 1089 | break; |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1090 | } |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 1091 | default: { |
| 1092 | Slog.w(TAG, "Unhandled message: " + msg); |
| 1093 | break; |
| 1094 | } |
| 1095 | } |
| 1096 | } |
| 1097 | } |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 1098 | |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 1099 | // Listener implementations for HdmiControlService |
| 1100 | |
| 1101 | private final class HdmiHotplugEventListener extends IHdmiHotplugEventListener.Stub { |
| 1102 | @Override |
| 1103 | public void onReceived(HdmiHotplugEvent event) { |
| 1104 | synchronized (mLock) { |
| 1105 | mHdmiStateMap.put(event.getPort(), event.isConnected()); |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 1106 | TvInputHardwareInfo hardwareInfo = |
| 1107 | findHardwareInfoForHdmiPortLocked(event.getPort()); |
| 1108 | if (hardwareInfo == null) { |
| 1109 | return; |
| 1110 | } |
| 1111 | String inputId = mHardwareInputIdMap.get(hardwareInfo.getDeviceId()); |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 1112 | if (inputId == null) { |
| 1113 | return; |
| 1114 | } |
| 1115 | mHandler.obtainMessage(ListenerHandler.STATE_CHANGED, |
| 1116 | convertConnectedToState(event.isConnected()), 0, inputId).sendToTarget(); |
| 1117 | } |
| 1118 | } |
| 1119 | } |
| 1120 | |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 1121 | private final class HdmiDeviceEventListener extends IHdmiDeviceEventListener.Stub { |
| 1122 | @Override |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1123 | public void onStatusChanged(HdmiDeviceInfo deviceInfo, int status) { |
Jinsuk Kim | 98d760e | 2014-12-23 07:01:51 +0900 | [diff] [blame] | 1124 | if (!deviceInfo.isSourceType()) return; |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 1125 | synchronized (mLock) { |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1126 | int messageType = 0; |
Wonsik Kim | e92f857 | 2014-08-12 18:30:24 +0900 | [diff] [blame] | 1127 | Object obj = null; |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1128 | switch (status) { |
| 1129 | case HdmiControlManager.DEVICE_EVENT_ADD_DEVICE: { |
Jungshik Jang | cf44587 | 2014-08-20 15:06:01 +0900 | [diff] [blame] | 1130 | if (findHdmiDeviceInfo(deviceInfo.getId()) == null) { |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1131 | mHdmiDeviceList.add(deviceInfo); |
| 1132 | } else { |
| 1133 | Slog.w(TAG, "The list already contains " + deviceInfo + "; ignoring."); |
| 1134 | return; |
| 1135 | } |
| 1136 | messageType = ListenerHandler.HDMI_DEVICE_ADDED; |
Wonsik Kim | e92f857 | 2014-08-12 18:30:24 +0900 | [diff] [blame] | 1137 | obj = deviceInfo; |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1138 | break; |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 1139 | } |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1140 | case HdmiControlManager.DEVICE_EVENT_REMOVE_DEVICE: { |
Jungshik Jang | cf44587 | 2014-08-20 15:06:01 +0900 | [diff] [blame] | 1141 | HdmiDeviceInfo originalDeviceInfo = findHdmiDeviceInfo(deviceInfo.getId()); |
| 1142 | if (!mHdmiDeviceList.remove(originalDeviceInfo)) { |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1143 | Slog.w(TAG, "The list doesn't contain " + deviceInfo + "; ignoring."); |
| 1144 | return; |
| 1145 | } |
| 1146 | messageType = ListenerHandler.HDMI_DEVICE_REMOVED; |
Wonsik Kim | e92f857 | 2014-08-12 18:30:24 +0900 | [diff] [blame] | 1147 | obj = deviceInfo; |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1148 | break; |
| 1149 | } |
| 1150 | case HdmiControlManager.DEVICE_EVENT_UPDATE_DEVICE: { |
Jungshik Jang | cf44587 | 2014-08-20 15:06:01 +0900 | [diff] [blame] | 1151 | HdmiDeviceInfo originalDeviceInfo = findHdmiDeviceInfo(deviceInfo.getId()); |
| 1152 | if (!mHdmiDeviceList.remove(originalDeviceInfo)) { |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1153 | Slog.w(TAG, "The list doesn't contain " + deviceInfo + "; ignoring."); |
| 1154 | return; |
| 1155 | } |
| 1156 | mHdmiDeviceList.add(deviceInfo); |
| 1157 | messageType = ListenerHandler.HDMI_DEVICE_UPDATED; |
Wonsik Kim | 184a6d6 | 2014-10-08 13:05:56 +0900 | [diff] [blame] | 1158 | obj = deviceInfo; |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1159 | break; |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 1160 | } |
| 1161 | } |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 1162 | |
Wonsik Kim | e92f857 | 2014-08-12 18:30:24 +0900 | [diff] [blame] | 1163 | Message msg = mHandler.obtainMessage(messageType, 0, 0, obj); |
Wonsik Kim | d922a54 | 2014-07-24 18:25:29 +0900 | [diff] [blame] | 1164 | if (findHardwareInfoForHdmiPortLocked(deviceInfo.getPortId()) != null) { |
| 1165 | msg.sendToTarget(); |
| 1166 | } else { |
| 1167 | mPendingHdmiDeviceEvents.add(msg); |
| 1168 | } |
| 1169 | } |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 1170 | } |
Jungshik Jang | cf44587 | 2014-08-20 15:06:01 +0900 | [diff] [blame] | 1171 | |
| 1172 | private HdmiDeviceInfo findHdmiDeviceInfo(int id) { |
| 1173 | for (HdmiDeviceInfo info : mHdmiDeviceList) { |
| 1174 | if (info.getId() == id) { |
| 1175 | return info; |
| 1176 | } |
| 1177 | } |
| 1178 | return null; |
| 1179 | } |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 1180 | } |
Jinsuk Kim | 7474fac | 2014-07-18 17:22:26 +0900 | [diff] [blame] | 1181 | |
Jungshik Jang | 1f819bb | 2014-08-08 10:46:54 +0900 | [diff] [blame] | 1182 | private final class HdmiSystemAudioModeChangeListener extends |
| 1183 | IHdmiSystemAudioModeChangeListener.Stub { |
| 1184 | @Override |
| 1185 | public void onStatusChanged(boolean enabled) throws RemoteException { |
| 1186 | synchronized (mLock) { |
| 1187 | for (int i = 0; i < mConnections.size(); ++i) { |
| 1188 | TvInputHardwareImpl impl = mConnections.valueAt(i).getHardwareImplLocked(); |
Jungshik Jang | 44bb3a5 | 2014-08-26 17:24:24 +0900 | [diff] [blame] | 1189 | if (impl != null) { |
| 1190 | impl.handleAudioSinkUpdated(); |
| 1191 | } |
Jungshik Jang | 1f819bb | 2014-08-08 10:46:54 +0900 | [diff] [blame] | 1192 | } |
| 1193 | } |
| 1194 | } |
| 1195 | } |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 1196 | } |