diff options
author | Lajos Molnar <lajos@google.com> | 2015-04-23 00:03:50 -0700 |
---|---|---|
committer | Lajos Molnar <lajos@google.com> | 2015-04-23 13:38:39 +0000 |
commit | 17d79047c7c3919e75ce0d4bc1eb062528818212 (patch) | |
tree | 14ded9571f8a4d46b9440fa8f0ec8e12cc99469c /media | |
parent | aba29b77a5742fc920ec62dbc9ddb6f025759d65 (diff) | |
download | frameworks_base-17d79047c7c3919e75ce0d4bc1eb062528818212.zip frameworks_base-17d79047c7c3919e75ce0d4bc1eb062528818212.tar.gz frameworks_base-17d79047c7c3919e75ce0d4bc1eb062528818212.tar.bz2 |
media: surface parity for MediaCodec & Recorder
allow setting output surface dynamically on MediaCodec
allow creating persistent input surface for MediaCodec and MediaRecorder
Bug: 19127604
Bug: 19489395
Change-Id: I68d95ce012574f1cc161556fd7d016be104e5076
Diffstat (limited to 'media')
-rw-r--r-- | media/java/android/media/MediaCodec.java | 55 | ||||
-rw-r--r-- | media/java/android/media/MediaRecorder.java | 18 |
2 files changed, 73 insertions, 0 deletions
diff --git a/media/java/android/media/MediaCodec.java b/media/java/android/media/MediaCodec.java index b0cd3e4..680c376 100644 --- a/media/java/android/media/MediaCodec.java +++ b/media/java/android/media/MediaCodec.java @@ -610,6 +610,61 @@ final public class MediaCodec { native_configure(keys, values, surface, crypto, flags); } + /** + * Dynamically sets the output surface of a codec. + * <p> + * This can only be used if the codec was configured with an output surface. The + * new output surface should have a compatible usage type to the original output surface. + * E.g. codecs may not support switching from a SurfaceTexture (GPU readable) output + * to ImageReader (software readable) output. + * @param surface the output surface to use. It must not be {@code null}. + * @throws IllegalStateException if the codec does not support setting the output + * surface in the current state. + * @throws IllegalArgumentException if the new surface is not of a suitable type for the codec. + */ + public void setSurface(@NonNull Surface surface) { + if (!mHasSurface) { + throw new IllegalStateException("codec was not configured for an output surface"); + } + + // TODO implement this + throw new IllegalArgumentException("codec does not support this surface"); + } + + /** + * Create a persistent input surface that can be used with codecs that normally have an input + * surface, such as video encoders. A persistent input can be reused by subsequent + * {@link MediaCodec} or {@link MediaRecorder} instances, but can only be used by at + * most one codec or recorder instance concurrently. + * <p> + * The application is responsible for calling release() on the Surface when done. + * + * @return an input surface that can be used with {@link #usePersistentInputSurface}. + */ + @NonNull + public static Surface createPersistentInputSurface() { + // TODO implement this + return new PersistentSurface(); + } + + static class PersistentSurface extends Surface { + PersistentSurface() {} + }; + + /** + * Configures the codec (e.g. encoder) to use a persistent input surface in place of input + * buffers. This may only be called after {@link #configure} and before {@link #start}, in + * lieu of {@link #createInputSurface}. + * @param surface a persistent input surface created by {@link #createPersistentInputSurface} + * @throws IllegalStateException if not in the Configured state or does not require an input + * surface. + * @throws IllegalArgumentException if the surface was not created by + * {@link #createPersistentInputSurface}. + */ + public void usePersistentInputSurface(@NonNull Surface surface) { + throw new IllegalArgumentException("not implemented"); + } + private native final void native_setCallback(@Nullable Callback cb); private native final void native_configure( diff --git a/media/java/android/media/MediaRecorder.java b/media/java/android/media/MediaRecorder.java index 876aebc..78fd9f0 100644 --- a/media/java/android/media/MediaRecorder.java +++ b/media/java/android/media/MediaRecorder.java @@ -140,6 +140,24 @@ public class MediaRecorder public native Surface getSurface(); /** + * Configures the recorder to use a persistent surface when using SURFACE video source. + * <p> May only be called after {@link #prepare} in lieu of {@link #getSurface}. + * Frames rendered to the Surface before {@link #start} will be discarded.</p> + + * @param surface a persistent input surface created by + * {@link MediaCodec#createPersistentInputSurface} + * @throws IllegalStateException if it is called before {@link #prepare}, after + * {@link #stop}, or is called when VideoSource is not set to SURFACE. + * @throws IllegalArgumentException if the surface was not created by + * {@link MediaCodec#createPersistentInputSurface}. + * @see MediaCodec#createPersistentInputSurface + * @see MediaRecorder.VideoSource + */ + public void usePersistentSurface(Surface surface) { + throw new IllegalArgumentException("not implemented"); + } + + /** * Sets a Surface to show a preview of recorded media (video). Calls this * before prepare() to make sure that the desirable preview display is * set. If {@link #setCamera(Camera)} is used and the surface has been |