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