diff options
| author | 2014-07-18 03:28:15 +0000 | |
|---|---|---|
| committer | 2014-07-17 21:58:28 +0000 | |
| commit | c66ca1267cfa4aca70d3dceaf5962ff77ee030b3 (patch) | |
| tree | fe26b28a03fc114caa7e36a58795d4613e9fe917 | |
| parent | b375805f3b1672e68d1511565af4700e5fa8491d (diff) | |
| parent | e821d711db1799dc51661a3ed6188f3cd942bae7 (diff) | |
Merge "TIF: Add a notification for surface change from TvView to TvInputService" into lmp-dev
| -rw-r--r-- | api/current.txt | 1 | ||||
| -rw-r--r-- | media/java/android/media/tv/ITvInputManager.aidl | 2 | ||||
| -rw-r--r-- | media/java/android/media/tv/ITvInputSession.aidl | 1 | ||||
| -rw-r--r-- | media/java/android/media/tv/ITvInputSessionWrapper.java | 29 | ||||
| -rw-r--r-- | media/java/android/media/tv/TvInputManager.java | 21 | ||||
| -rw-r--r-- | media/java/android/media/tv/TvInputService.java | 23 | ||||
| -rw-r--r-- | media/java/android/media/tv/TvView.java | 39 | ||||
| -rw-r--r-- | services/core/java/com/android/server/tv/TvInputManagerService.java | 21 |
8 files changed, 122 insertions, 15 deletions
diff --git a/api/current.txt b/api/current.txt index cae770348005..3402a6207417 100644 --- a/api/current.txt +++ b/api/current.txt @@ -16652,6 +16652,7 @@ package android.media.tv { method public abstract void onSetCaptionEnabled(boolean); method public abstract void onSetStreamVolume(float); method public abstract boolean onSetSurface(android.view.Surface); + method public void onSurfaceChanged(int, int, int); method public boolean onTouchEvent(android.view.MotionEvent); method public boolean onTrackballEvent(android.view.MotionEvent); method public abstract boolean onTune(android.net.Uri); diff --git a/media/java/android/media/tv/ITvInputManager.aidl b/media/java/android/media/tv/ITvInputManager.aidl index d4b33590733e..6147f407d573 100644 --- a/media/java/android/media/tv/ITvInputManager.aidl +++ b/media/java/android/media/tv/ITvInputManager.aidl @@ -43,6 +43,8 @@ interface ITvInputManager { void releaseSession(in IBinder sessionToken, int userId); void setSurface(in IBinder sessionToken, in Surface surface, int userId); + void dispatchSurfaceChanged(in IBinder sessionToken, int format, int width, int height, + int userId); void setVolume(in IBinder sessionToken, float volume, int userId); void tune(in IBinder sessionToken, in Uri channelUri, int userId); void setCaptionEnabled(in IBinder sessionToken, boolean enabled, int userId); diff --git a/media/java/android/media/tv/ITvInputSession.aidl b/media/java/android/media/tv/ITvInputSession.aidl index 875fa34246a3..9211dfc41c88 100644 --- a/media/java/android/media/tv/ITvInputSession.aidl +++ b/media/java/android/media/tv/ITvInputSession.aidl @@ -29,6 +29,7 @@ oneway interface ITvInputSession { void release(); void setSurface(in Surface surface); + void dispatchSurfaceChanged(int format, int width, int height); // TODO: Remove this once it becomes irrelevant for applications to handle audio focus. The plan // is to introduce some new concepts that will solve a number of problems in audio policy today. void setVolume(float volume); diff --git a/media/java/android/media/tv/ITvInputSessionWrapper.java b/media/java/android/media/tv/ITvInputSessionWrapper.java index 0c085903d058..c9c0768b1db4 100644 --- a/media/java/android/media/tv/ITvInputSessionWrapper.java +++ b/media/java/android/media/tv/ITvInputSessionWrapper.java @@ -42,14 +42,15 @@ public class ITvInputSessionWrapper extends ITvInputSession.Stub implements Hand private static final int DO_RELEASE = 1; private static final int DO_SET_SURFACE = 2; - private static final int DO_SET_VOLUME = 3; - private static final int DO_TUNE = 4; - private static final int DO_SET_CAPTION_ENABLED = 5; - private static final int DO_SELECT_TRACK = 6; - private static final int DO_UNSELECT_TRACK = 7; - private static final int DO_CREATE_OVERLAY_VIEW = 8; - private static final int DO_RELAYOUT_OVERLAY_VIEW = 9; - private static final int DO_REMOVE_OVERLAY_VIEW = 10; + private static final int DO_DISPATCH_SURFACE_CHANGED = 3; + private static final int DO_SET_VOLUME = 4; + private static final int DO_TUNE = 5; + private static final int DO_SET_CAPTION_ENABLED = 6; + private static final int DO_SELECT_TRACK = 7; + private static final int DO_UNSELECT_TRACK = 8; + private static final int DO_CREATE_OVERLAY_VIEW = 9; + private static final int DO_RELAYOUT_OVERLAY_VIEW = 10; + private static final int DO_REMOVE_OVERLAY_VIEW = 11; private final HandlerCaller mCaller; @@ -91,6 +92,12 @@ public class ITvInputSessionWrapper extends ITvInputSession.Stub implements Hand mTvInputSessionImpl.setSurface((Surface) msg.obj); return; } + case DO_DISPATCH_SURFACE_CHANGED: { + SomeArgs args = (SomeArgs) msg.obj; + mTvInputSessionImpl.dispatchSurfaceChanged(args.argi1, args.argi2, args.argi3); + args.recycle(); + return; + } case DO_SET_VOLUME: { mTvInputSessionImpl.setVolume((Float) msg.obj); return; @@ -143,6 +150,12 @@ public class ITvInputSessionWrapper extends ITvInputSession.Stub implements Hand } @Override + public void dispatchSurfaceChanged(int format, int width, int height) { + mCaller.executeOrSendMessage(mCaller.obtainMessageIIII(DO_DISPATCH_SURFACE_CHANGED, + format, width, height, 0)); + } + + @Override public final void setVolume(float volume) { mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_SET_VOLUME, volume)); } diff --git a/media/java/android/media/tv/TvInputManager.java b/media/java/android/media/tv/TvInputManager.java index a16315079920..57a8eb8326a1 100644 --- a/media/java/android/media/tv/TvInputManager.java +++ b/media/java/android/media/tv/TvInputManager.java @@ -669,6 +669,27 @@ public final class TvInputManager { } /** + * Notifies of any structural changes (format or size) of the {@link Surface} + * passed by {@link #setSurface}. + * + * @param format The new PixelFormat of the {@link Surface}. + * @param width The new width of the {@link Surface}. + * @param height The new height of the {@link Surface}. + * @hide + */ + public void dispatchSurfaceChanged(int format, int width, int height) { + if (mToken == null) { + Log.w(TAG, "The session has been already released"); + return; + } + try { + mService.dispatchSurfaceChanged(mToken, format, width, height, mUserId); + } catch (RemoteException e) { + throw new RuntimeException(e); + } + } + + /** * Sets the relative stream volume of this session to handle a change of audio focus. * * @param volume A volume value between 0.0f to 1.0f. diff --git a/media/java/android/media/tv/TvInputService.java b/media/java/android/media/tv/TvInputService.java index ecffb7bc2269..fccc3ce80020 100644 --- a/media/java/android/media/tv/TvInputService.java +++ b/media/java/android/media/tv/TvInputService.java @@ -399,6 +399,18 @@ public abstract class TvInputService extends Service { public abstract boolean onSetSurface(Surface surface); /** + * Called after any structural changes (format or size) have been made to the + * {@link Surface} passed by {@link #onSetSurface}. This method is always called + * at least once, after {@link #onSetSurface} with non-null {@link Surface} is called. + * + * @param format The new PixelFormat of the {@link Surface}. + * @param width The new width of the {@link Surface}. + * @param height The new height of the {@link Surface}. + */ + public void onSurfaceChanged(int format, int width, int height) { + } + + /** * Sets the relative stream volume of the current TV input session to handle the change of * audio focus by setting. * @@ -612,6 +624,17 @@ public abstract class TvInputService extends Service { } /** + * Calls {@link #onSurfaceChanged}. + */ + void dispatchSurfaceChanged(int format, int width, int height) { + if (DEBUG) { + Log.d(TAG, "dispatchSurfaceChanged(format=" + format + ", width=" + width + + ", height=" + height + ")"); + } + onSurfaceChanged(format, width, height); + } + + /** * Calls {@link #onSetStreamVolume}. */ void setVolume(float volume) { diff --git a/media/java/android/media/tv/TvView.java b/media/java/android/media/tv/TvView.java index 12a696141597..afdd971b696c 100644 --- a/media/java/android/media/tv/TvView.java +++ b/media/java/android/media/tv/TvView.java @@ -75,17 +75,21 @@ public class TvView extends ViewGroup { private float mStreamVolume; private int mVideoWidth = VIDEO_SIZE_VALUE_UNKNOWN; private int mVideoHeight = VIDEO_SIZE_VALUE_UNKNOWN; + private boolean mSurfaceChanged; + private int mSurfaceFormat; + private int mSurfaceWidth; + private int mSurfaceHeight; private final SurfaceHolder.Callback mSurfaceHolderCallback = new SurfaceHolder.Callback() { @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Log.d(TAG, "surfaceChanged(holder=" + holder + ", format=" + format + ", width=" + width + ", height=" + height + ")"); - if (holder.getSurface() == mSurface) { - return; - } - mSurface = holder.getSurface(); - setSessionSurface(mSurface); + mSurfaceFormat = format; + mSurfaceWidth = width; + mSurfaceHeight = height; + mSurfaceChanged = true; + dispatchSurfaceChanged(mSurfaceFormat, mSurfaceWidth, mSurfaceHeight); } @Override @@ -97,6 +101,7 @@ public class TvView extends ViewGroup { @Override public void surfaceDestroyed(SurfaceHolder holder) { mSurface = null; + mSurfaceChanged = false; setSessionSurface(null); } }; @@ -423,6 +428,13 @@ public class TvView extends ViewGroup { mSession.setSurface(surface); } + private void dispatchSurfaceChanged(int format, int width, int height) { + if (mSession == null) { + return; + } + mSession.dispatchSurfaceChanged(format, width, height); + } + private void createSessionOverlayView() { if (mSession == null || !isAttachedToWindow() || mOverlayViewCreated) { @@ -609,6 +621,9 @@ public class TvView extends ViewGroup { // setSessionSurface will be called in surfaceCreated. if (mSurface != null) { setSessionSurface(mSurface); + if (mSurfaceChanged) { + dispatchSurfaceChanged(mSurfaceFormat, mSurfaceWidth, mSurfaceHeight); + } } createSessionOverlayView(); mSession.tune(mChannelUri); @@ -624,9 +639,10 @@ public class TvView extends ViewGroup { @Override public void onSessionReleased(Session session) { - if (this == mSessionCallback) { - mSessionCallback = null; + if (this != mSessionCallback) { + return; } + mSessionCallback = null; mSession = null; if (mListener != null) { mListener.onError(mInputId, ERROR_TV_INPUT_DISCONNECTED); @@ -635,6 +651,9 @@ public class TvView extends ViewGroup { @Override public void onChannelRetuned(Session session, Uri channelUri) { + if (this != mSessionCallback) { + return; + } if (DEBUG) { Log.d(TAG, "onChannelChangedByTvInput(" + channelUri + ")"); } @@ -659,6 +678,9 @@ public class TvView extends ViewGroup { @Override public void onVideoAvailable(Session session) { + if (this != mSessionCallback) { + return; + } if (DEBUG) { Log.d(TAG, "onVideoAvailable()"); } @@ -669,6 +691,9 @@ public class TvView extends ViewGroup { @Override public void onVideoUnavailable(Session session, int reason) { + if (this != mSessionCallback) { + return; + } if (DEBUG) { Log.d(TAG, "onVideoUnavailable(" + reason + ")"); } diff --git a/services/core/java/com/android/server/tv/TvInputManagerService.java b/services/core/java/com/android/server/tv/TvInputManagerService.java index 0407b10413df..33a379ae4e6f 100644 --- a/services/core/java/com/android/server/tv/TvInputManagerService.java +++ b/services/core/java/com/android/server/tv/TvInputManagerService.java @@ -888,6 +888,27 @@ public final class TvInputManagerService extends SystemService { } @Override + public void dispatchSurfaceChanged(IBinder sessionToken, int format, int width, + int height, int userId) { + final int callingUid = Binder.getCallingUid(); + final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, + userId, "dispatchSurfaceChanged"); + final long identity = Binder.clearCallingIdentity(); + try { + synchronized (mLock) { + try { + getSessionLocked(sessionToken, callingUid, resolvedUserId) + .dispatchSurfaceChanged(format, width, height); + } catch (RemoteException e) { + Slog.e(TAG, "error in dispatchSurfaceChanged", e); + } + } + } finally { + Binder.restoreCallingIdentity(identity); + } + } + + @Override public void setVolume(IBinder sessionToken, float volume, int userId) { final int callingUid = Binder.getCallingUid(); final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |