MediaRecorder.java revision a7cc59c3187711d390c5a483d26c463a1bcbd331
19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Copyright (C) 2007 The Android Open Source Project
39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you may not use this file except in compliance with the License.
69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * You may obtain a copy of the License at
79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Unless required by applicable law or agreed to in writing, software
119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * See the License for the specific language governing permissions and
149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * limitations under the License.
159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpackage android.media;
189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1903359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhangimport android.annotation.NonNull;
2000a009204e51997249d60eab4f147eff566e2b1fEric Laurentimport android.annotation.SystemApi;
21788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvalaimport android.app.ActivityThread;
229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.hardware.Camera;
239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Handler;
249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Looper;
259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Message;
269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.util.Log;
279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.view.Surface;
2842419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li
299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport java.io.FileDescriptor;
3042419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Liimport java.io.IOException;
310d5d3b7cc8b9ff142269a947443c758cb2af4684Robert Shihimport java.io.RandomAccessFile;
329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport java.lang.ref.WeakReference;
339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/**
359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Used to record audio and video. The recording control is based on a
369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * simple state machine (see below).
379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p><img src="{@docRoot}images/mediarecorder_state_diagram.gif" border="0" />
399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </p>
409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p>A common case of using MediaRecorder to record audio works as follows:
429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <pre>MediaRecorder recorder = new MediaRecorder();
449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.setOutputFile(PATH_NAME);
489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.prepare();
499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.start();   // Recording is now started
509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * ...
519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.stop();
529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.reset();   // You can reuse the object by going back to setAudioSource() step
539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.release(); // Now the object cannot be reused
549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </pre>
559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
569ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * <p>Applications may want to register for informational and error
579ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * events in order to be informed of some internal update and possible
589ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * runtime errors during recording. Registration for such events is
599ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * done by setting the appropriate listeners (via calls
609ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * (to {@link #setOnInfoListener(OnInfoListener)}setOnInfoListener and/or
619ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * {@link #setOnErrorListener(OnErrorListener)}setOnErrorListener).
629ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * In order to receive the respective callback associated with these listeners,
639ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * applications are required to create MediaRecorder objects on threads with a
649ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * Looper running (the main UI thread by default already has a Looper running).
659ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong *
6661fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <p><strong>Note:</strong> Currently, MediaRecorder does not work on the emulator.
6761fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez *
6861fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <div class="special reference">
6961fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <h3>Developer Guides</h3>
7061fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <p>For more information about how to use MediaRecorder for recording video, read the
7161fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <a href="{@docRoot}guide/topics/media/camera.html#capture-video">Camera</a> developer guide.
7261fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * For more information about how to use MediaRecorder for recording sound, read the
7361fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <a href="{@docRoot}guide/topics/media/audio-capture.html">Audio Capture</a> developer guide.</p>
7461fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * </div>
759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpublic class MediaRecorder
779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    static {
799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        System.loadLibrary("media_jni");
804935d05eaa306cef88cf0ab13eca386f270409ecMarco Nelissen        native_init();
819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private final static String TAG = "MediaRecorder";
839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    // The two fields below are accessed by native methods
859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    @SuppressWarnings("unused")
86075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat    private long mNativeContext;
879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    @SuppressWarnings("unused")
899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private Surface mSurface;
909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private String mPath;
929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private FileDescriptor mFd;
939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private EventHandler mEventHandler;
949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private OnErrorListener mOnErrorListener;
95ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project    private OnInfoListener mOnInfoListener;
969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Default constructor.
999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public MediaRecorder() {
1019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        Looper looper;
1039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if ((looper = Looper.myLooper()) != null) {
1049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mEventHandler = new EventHandler(this, looper);
1059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } else if ((looper = Looper.getMainLooper()) != null) {
1069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mEventHandler = new EventHandler(this, looper);
1079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } else {
1089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mEventHandler = null;
1099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
1109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
111788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvala        String packageName = ActivityThread.currentPackageName();
1129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /* Native setup requires a weak reference to our object.
1139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * It's easier to create it here than in C++.
1149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
115fbf0ecabac5d7a929628b43ffe8f4f953e47bd54Svetoslav        native_setup(new WeakReference<MediaRecorder>(this), packageName,
116fbf0ecabac5d7a929628b43ffe8f4f953e47bd54Svetoslav                ActivityThread.currentOpPackageName());
1179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
120b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * Sets a {@link android.hardware.Camera} to use for recording.
121b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *
122b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * <p>Use this function to switch quickly between preview and capture mode without a teardown of
123b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * the camera object. {@link android.hardware.Camera#unlock()} should be called before
124b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * this. Must call before {@link #prepare}.</p>
1259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
1269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param c the Camera to use for recording
127b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated Use {@link #getSurface} and the {@link android.hardware.camera2} API instead.
1289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
129b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
1309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public native void setCamera(Camera c);
1319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
13383cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang     * Gets the surface to record from when using SURFACE video source.
134b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *
135b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * <p> May only be called after {@link #prepare}. Frames rendered to the Surface before
136b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * {@link #start} will be discarded.</p>
137b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *
138b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @throws IllegalStateException if it is called before {@link #prepare}, after
139b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * {@link #stop}, or is called when VideoSource is not set to SURFACE.
14083cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang     * @see android.media.MediaRecorder.VideoSource
14183cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang     */
14283cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang    public native Surface getSurface();
14383cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang
14483cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang    /**
14517d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar     * Configures the recorder to use a persistent surface when using SURFACE video source.
14603359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang     * <p> May only be called before {@link #prepare}. If called, {@link #getSurface} should
14703359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang     * not be used and will throw IllegalStateException. Frames rendered to the Surface
14803359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang     * before {@link #start} will be discarded.</p>
14917d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar
15017d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar     * @param surface a persistent input surface created by
15117d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar     *           {@link MediaCodec#createPersistentInputSurface}
15203359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang     * @throws IllegalStateException if it is called after {@link #prepare} and before
15303359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang     * {@link #stop}.
15417d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar     * @throws IllegalArgumentException if the surface was not created by
15517d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar     *           {@link MediaCodec#createPersistentInputSurface}.
15617d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar     * @see MediaCodec#createPersistentInputSurface
15717d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar     * @see MediaRecorder.VideoSource
15817d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar     */
1599560ddb48af0e2da7743452f8d9d6d9cd34d8438Chong Zhang    public void setInputSurface(@NonNull Surface surface) {
16003359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang        if (!(surface instanceof MediaCodec.PersistentSurface)) {
16103359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang            throw new IllegalArgumentException("not a PersistentSurface");
16203359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang        }
1639560ddb48af0e2da7743452f8d9d6d9cd34d8438Chong Zhang        native_setInputSurface(surface);
16417d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar    }
16517d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar
1669560ddb48af0e2da7743452f8d9d6d9cd34d8438Chong Zhang    private native final void native_setInputSurface(@NonNull Surface surface);
16703359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang
16817d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar    /**
1699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Sets a Surface to show a preview of recorded media (video). Calls this
1709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * before prepare() to make sure that the desirable preview display is
171c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li     * set. If {@link #setCamera(Camera)} is used and the surface has been
172c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li     * already set to the camera, application do not need to call this. If
173c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li     * this is called with non-null surface, the preview surface of the camera
174c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li     * will be replaced by the new surface. If this method is called with null
175c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li     * surface or not called at all, media recorder will not change the preview
176c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li     * surface of the camera.
1779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
1789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param sv the Surface to use for the preview
179c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li     * @see android.hardware.Camera#setPreviewDisplay(android.view.SurfaceHolder)
1809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void setPreviewDisplay(Surface sv) {
1829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mSurface = sv;
1839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1867af0d66c2270d2b804b029bf33d6d8b532625a74Jean-Michel Trivi     * Defines the audio source.
1877af0d66c2270d2b804b029bf33d6d8b532625a74Jean-Michel Trivi     * An audio source defines both a default physical source of audio signal, and a recording
188fd3ac3da172b877c6f316de2d066883e7a2d0631Jean-Michel Trivi     * configuration. These constants are for instance used
1897af0d66c2270d2b804b029bf33d6d8b532625a74Jean-Michel Trivi     * in {@link MediaRecorder#setAudioSource(int)} or
190fd3ac3da172b877c6f316de2d066883e7a2d0631Jean-Michel Trivi     * {@link AudioRecord.Builder#setAudioSource(int)}.
1919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final class AudioSource {
193701d6ff12f36bf5e9de0dafdaced06744fd411ebJean-Michel Trivi
194701d6ff12f36bf5e9de0dafdaced06744fd411ebJean-Michel Trivi        private AudioSource() {}
195701d6ff12f36bf5e9de0dafdaced06744fd411ebJean-Michel Trivi
196701d6ff12f36bf5e9de0dafdaced06744fd411ebJean-Michel Trivi        /** @hide */
197701d6ff12f36bf5e9de0dafdaced06744fd411ebJean-Michel Trivi        public final static int AUDIO_SOURCE_INVALID = -1;
198701d6ff12f36bf5e9de0dafdaced06744fd411ebJean-Michel Trivi
1999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project      /* Do not change these values without updating their counterparts
200b2b292317482d00d067bc91669322b273be61926Rom Lemarchand       * in system/media/audio/include/system/audio.h!
2019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project       */
2020f0fbd9441f40c6f99470b89774e397f99bf61ebGlenn Kasten
2030f0fbd9441f40c6f99470b89774e397f99bf61ebGlenn Kasten        /** Default audio source **/
2049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public static final int DEFAULT = 0;
2050f0fbd9441f40c6f99470b89774e397f99bf61ebGlenn Kasten
2069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /** Microphone audio source */
2079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public static final int MIC = 1;
2084bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent
2094bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent        /** Voice call uplink (Tx) audio source */
2104bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent        public static final int VOICE_UPLINK = 2;
2114bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent
2124bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent        /** Voice call downlink (Rx) audio source */
2134bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent        public static final int VOICE_DOWNLINK = 3;
2144bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent
2154bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent        /** Voice call uplink + downlink audio source */
2164bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent        public static final int VOICE_CALL = 4;
2176869df3a5db0ca0037394f0fd14aecc1d80b5b42Jean-Michel Trivi
218941136fd089d40a80d63fcaf99b4a0bdeb6e349cJean-Michel Trivi        /** Microphone audio source with same orientation as camera if available, the main
219941136fd089d40a80d63fcaf99b4a0bdeb6e349cJean-Michel Trivi         *  device microphone otherwise */
2206869df3a5db0ca0037394f0fd14aecc1d80b5b42Jean-Michel Trivi        public static final int CAMCORDER = 5;
2216869df3a5db0ca0037394f0fd14aecc1d80b5b42Jean-Michel Trivi
222941136fd089d40a80d63fcaf99b4a0bdeb6e349cJean-Michel Trivi        /** Microphone audio source tuned for voice recognition if available, behaves like
223941136fd089d40a80d63fcaf99b4a0bdeb6e349cJean-Michel Trivi         *  {@link #DEFAULT} otherwise. */
2246869df3a5db0ca0037394f0fd14aecc1d80b5b42Jean-Michel Trivi        public static final int VOICE_RECOGNITION = 6;
225820b9e0d3b6f94fe0b524aebf756ce25df273e6aJean-Michel Trivi
226ffd0eb0f1106b0229694a1a86ce7d6356efcf50dJean-Michel Trivi        /** Microphone audio source tuned for voice communications such as VoIP. It
227ffd0eb0f1106b0229694a1a86ce7d6356efcf50dJean-Michel Trivi         *  will for instance take advantage of echo cancellation or automatic gain control
228ffd0eb0f1106b0229694a1a86ce7d6356efcf50dJean-Michel Trivi         *  if available. It otherwise behaves like {@link #DEFAULT} if no voice processing
229ffd0eb0f1106b0229694a1a86ce7d6356efcf50dJean-Michel Trivi         *  is applied.
230820b9e0d3b6f94fe0b524aebf756ce25df273e6aJean-Michel Trivi         */
231820b9e0d3b6f94fe0b524aebf756ce25df273e6aJean-Michel Trivi        public static final int VOICE_COMMUNICATION = 7;
23264dfb604e70b70b7c346768114e05ddfadc09addJeff Brown
23364dfb604e70b70b7c346768114e05ddfadc09addJeff Brown        /**
23464dfb604e70b70b7c346768114e05ddfadc09addJeff Brown         * Audio source for a submix of audio streams to be presented remotely.
23564dfb604e70b70b7c346768114e05ddfadc09addJeff Brown         * <p>
23664dfb604e70b70b7c346768114e05ddfadc09addJeff Brown         * An application can use this audio source to capture a mix of audio streams
23764dfb604e70b70b7c346768114e05ddfadc09addJeff Brown         * that should be transmitted to a remote receiver such as a Wifi display.
23864dfb604e70b70b7c346768114e05ddfadc09addJeff Brown         * While recording is active, these audio streams are redirected to the remote
23964dfb604e70b70b7c346768114e05ddfadc09addJeff Brown         * submix instead of being played on the device speaker or headset.
24064dfb604e70b70b7c346768114e05ddfadc09addJeff Brown         * </p><p>
24164dfb604e70b70b7c346768114e05ddfadc09addJeff Brown         * Certain streams are excluded from the remote submix, including
24264dfb604e70b70b7c346768114e05ddfadc09addJeff Brown         * {@link AudioManager#STREAM_RING}, {@link AudioManager#STREAM_ALARM},
24364dfb604e70b70b7c346768114e05ddfadc09addJeff Brown         * and {@link AudioManager#STREAM_NOTIFICATION}.  These streams will continue
24464dfb604e70b70b7c346768114e05ddfadc09addJeff Brown         * to be presented locally as usual.
24564dfb604e70b70b7c346768114e05ddfadc09addJeff Brown         * </p><p>
24664dfb604e70b70b7c346768114e05ddfadc09addJeff Brown         * Capturing the remote submix audio requires the
24764dfb604e70b70b7c346768114e05ddfadc09addJeff Brown         * {@link android.Manifest.permission#CAPTURE_AUDIO_OUTPUT} permission.
24864dfb604e70b70b7c346768114e05ddfadc09addJeff Brown         * This permission is reserved for use by system components and is not available to
24964dfb604e70b70b7c346768114e05ddfadc09addJeff Brown         * third-party applications.
25064dfb604e70b70b7c346768114e05ddfadc09addJeff Brown         * </p>
25164dfb604e70b70b7c346768114e05ddfadc09addJeff Brown         */
25264dfb604e70b70b7c346768114e05ddfadc09addJeff Brown        public static final int REMOTE_SUBMIX = 8;
253357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent
254a7cc59c3187711d390c5a483d26c463a1bcbd331rago        /** Microphone audio source tuned for unprocessed (raw) sound if available, behaves like
255a7cc59c3187711d390c5a483d26c463a1bcbd331rago         *  {@link #DEFAULT} otherwise. */
256a7cc59c3187711d390c5a483d26c463a1bcbd331rago        public static final int UNPROCESSED = 9;
257a7cc59c3187711d390c5a483d26c463a1bcbd331rago
258357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent        /**
25900a009204e51997249d60eab4f147eff566e2b1fEric Laurent         * Audio source for capturing broadcast radio tuner output.
260ce4483cb83afb3a42a32ef2cb00cf04d6f9018fdBenson Huang         * @hide
261ce4483cb83afb3a42a32ef2cb00cf04d6f9018fdBenson Huang         */
26200a009204e51997249d60eab4f147eff566e2b1fEric Laurent        @SystemApi
26300a009204e51997249d60eab4f147eff566e2b1fEric Laurent        public static final int RADIO_TUNER = 1998;
264ce4483cb83afb3a42a32ef2cb00cf04d6f9018fdBenson Huang
265ce4483cb83afb3a42a32ef2cb00cf04d6f9018fdBenson Huang        /**
266357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent         * Audio source for preemptible, low-priority software hotword detection
267357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent         * It presents the same gain and pre processing tuning as {@link #VOICE_RECOGNITION}.
268357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent         * <p>
269357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent         * An application should use this audio source when it wishes to do
270357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent         * always-on software hotword detection, while gracefully giving in to any other application
271357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent         * that might want to read from the microphone.
272357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent         * </p>
273357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent         * This is a hidden audio source.
274357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent         * @hide
275357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent         */
27600a009204e51997249d60eab4f147eff566e2b1fEric Laurent        @SystemApi
27700a009204e51997249d60eab4f147eff566e2b1fEric Laurent        public static final int HOTWORD = 1999;
2789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
2819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Defines the video source. These constants are used with
2829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * {@link MediaRecorder#setVideoSource(int)}.
2839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final class VideoSource {
2859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project      /* Do not change these values without updating their counterparts
2869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project       * in include/media/mediarecorder.h!
2879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project       */
2889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        private VideoSource() {}
2899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public static final int DEFAULT = 0;
29083cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang        /** Camera video source
29183cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang         * <p>
292b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala         * Using the {@link android.hardware.Camera} API as video source.
29383cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang         * </p>
29483cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang         */
2959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public static final int CAMERA = 1;
29683cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang        /** Surface video source
29783cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang         * <p>
29883cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang         * Using a Surface as video source.
29983cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang         * </p><p>
30083cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang         * This flag must be used when recording from an
301b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala         * {@link android.hardware.camera2} API source.
30283cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang         * </p><p>
30383cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang         * When using this video source type, use {@link MediaRecorder#getSurface()}
30483cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang         * to retrieve the surface created by MediaRecorder.
30583cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang         */
30683cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang        public static final int SURFACE = 2;
3079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
3109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Defines the output format. These constants are used with
3119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * {@link MediaRecorder#setOutputFormat(int)}.
3129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final class OutputFormat {
3149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project      /* Do not change these values without updating their counterparts
3159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project       * in include/media/mediarecorder.h!
3169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project       */
3179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        private OutputFormat() {}
3189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public static final int DEFAULT = 0;
3199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /** 3GPP media file format*/
3209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public static final int THREE_GPP = 1;
3219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /** MPEG4 media file format*/
3229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public static final int MPEG_4 = 2;
3232bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang
324874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong        /** The following formats are audio only .aac or .amr formats */
325874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong
326874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong        /**
327874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong         * AMR NB file format
328874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong         * @deprecated  Deprecated in favor of MediaRecorder.OutputFormat.AMR_NB
329874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong         */
3309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public static final int RAW_AMR = 3;
331874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong
3322116dc91e96f7153f65468ed40a0b57e437679f7James Dong        /** AMR NB file format */
3332bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang        public static final int AMR_NB = 3;
334874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong
3352116dc91e96f7153f65468ed40a0b57e437679f7James Dong        /** AMR WB file format */
3362bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang        public static final int AMR_WB = 4;
337874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong
3382bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang        /** @hide AAC ADIF file format */
3392bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang        public static final int AAC_ADIF = 5;
340874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong
341874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong        /** AAC ADTS file format */
3422bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang        public static final int AAC_ADTS = 6;
34357648e4eec7dd2593af467877bc7cce4aa654759Andreas Huber
34457648e4eec7dd2593af467877bc7cce4aa654759Andreas Huber        /** @hide Stream over a socket, limited to a single stream */
34557648e4eec7dd2593af467877bc7cce4aa654759Andreas Huber        public static final int OUTPUT_FORMAT_RTP_AVP = 7;
3469adf466021d37a5062d7d3361e14bfd9e7ffeba6Andreas Huber
3479adf466021d37a5062d7d3361e14bfd9e7ffeba6Andreas Huber        /** @hide H.264/AAC data encapsulated in MPEG2/TS */
3489adf466021d37a5062d7d3361e14bfd9e7ffeba6Andreas Huber        public static final int OUTPUT_FORMAT_MPEG2TS = 8;
349c20533c1a7772f61d904fad31e3998c055c03da5Robert Shih
350c20533c1a7772f61d904fad31e3998c055c03da5Robert Shih        /** VP8/VORBIS data in a WEBM container */
351c20533c1a7772f61d904fad31e3998c055c03da5Robert Shih        public static final int WEBM = 9;
3529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    };
3539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
3559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Defines the audio encoding. These constants are used with
3569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * {@link MediaRecorder#setAudioEncoder(int)}.
3579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final class AudioEncoder {
3599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project      /* Do not change these values without updating their counterparts
3609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project       * in include/media/mediarecorder.h!
3619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project       */
3629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        private AudioEncoder() {}
3639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public static final int DEFAULT = 0;
3649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /** AMR (Narrowband) audio codec */
3659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public static final int AMR_NB = 1;
3662116dc91e96f7153f65468ed40a0b57e437679f7James Dong        /** AMR (Wideband) audio codec */
3672bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang        public static final int AMR_WB = 2;
368ec3f31f6215cb380bba5ab36c9e4c21b13f046a1Dave Burke        /** AAC Low Complexity (AAC-LC) audio codec */
3692bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang        public static final int AAC = 3;
370ec3f31f6215cb380bba5ab36c9e4c21b13f046a1Dave Burke        /** High Efficiency AAC (HE-AAC) audio codec */
371ec3f31f6215cb380bba5ab36c9e4c21b13f046a1Dave Burke        public static final int HE_AAC = 4;
372ec3f31f6215cb380bba5ab36c9e4c21b13f046a1Dave Burke        /** Enhanced Low Delay AAC (AAC-ELD) audio codec */
373ec3f31f6215cb380bba5ab36c9e4c21b13f046a1Dave Burke        public static final int AAC_ELD = 5;
374c20533c1a7772f61d904fad31e3998c055c03da5Robert Shih        /** Ogg Vorbis audio codec */
375c20533c1a7772f61d904fad31e3998c055c03da5Robert Shih        public static final int VORBIS = 6;
3769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
3799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Defines the video encoding. These constants are used with
3809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * {@link MediaRecorder#setVideoEncoder(int)}.
3819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final class VideoEncoder {
3839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project      /* Do not change these values without updating their counterparts
3849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project       * in include/media/mediarecorder.h!
3859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project       */
3869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        private VideoEncoder() {}
3879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public static final int DEFAULT = 0;
3889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public static final int H263 = 1;
3899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public static final int H264 = 2;
3909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public static final int MPEG_4_SP = 3;
391c20533c1a7772f61d904fad31e3998c055c03da5Robert Shih        public static final int VP8 = 4;
3929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
3959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Sets the audio source to be used for recording. If this method is not
3969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * called, the output file will not contain an audio track. The source needs
3979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * to be specified before setting recording-parameters or encoders. Call
3989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * this only before setOutputFormat().
3999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
4009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param audio_source the audio source to use
4019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @throws IllegalStateException if it is called after setOutputFormat()
4029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see android.media.MediaRecorder.AudioSource
4039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
4049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public native void setAudioSource(int audio_source)
4059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            throws IllegalStateException;
4069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
4084bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent     * Gets the maximum value for audio sources.
4094bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent     * @see android.media.MediaRecorder.AudioSource
4104bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent     */
4112ac2afeac989ea1dc326b0db996d6c6c8e00cc29Jean-Michel Trivi    public static final int getAudioSourceMax() {
412a7cc59c3187711d390c5a483d26c463a1bcbd331rago        return AudioSource.UNPROCESSED;
4132ac2afeac989ea1dc326b0db996d6c6c8e00cc29Jean-Michel Trivi    }
4144bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent
4154bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent    /**
4169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Sets the video source to be used for recording. If this method is not
4179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * called, the output file will not contain an video track. The source needs
4189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * to be specified before setting recording-parameters or encoders. Call
4199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * this only before setOutputFormat().
4209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
4219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param video_source the video source to use
4229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @throws IllegalStateException if it is called after setOutputFormat()
4239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see android.media.MediaRecorder.VideoSource
4249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
4259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public native void setVideoSource(int video_source)
4269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            throws IllegalStateException;
4279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
429e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong     * Uses the settings from a CamcorderProfile object for recording. This method should
430e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong     * be called after the video AND audio sources are set, and before setOutputFile().
431a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong     * If a time lapse CamcorderProfile is used, audio related source or recording
432a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong     * parameters are ignored.
433e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong     *
434e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong     * @param profile the CamcorderProfile to use
435e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong     * @see android.media.CamcorderProfile
436e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong     */
437e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong    public void setProfile(CamcorderProfile profile) {
438e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong        setOutputFormat(profile.fileFormat);
439e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong        setVideoFrameRate(profile.videoFrameRate);
440e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong        setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
441e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong        setVideoEncodingBitRate(profile.videoBitRate);
442e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong        setVideoEncoder(profile.videoCodec);
4434f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra        if (profile.quality >= CamcorderProfile.QUALITY_TIME_LAPSE_LOW &&
44433fe290ca33235d7e0988cace14de3319a9a83f1James Dong             profile.quality <= CamcorderProfile.QUALITY_TIME_LAPSE_QVGA) {
445a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong            // Nothing needs to be done. Call to setCaptureRate() enables
446a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong            // time lapse video recording.
4474f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra        } else {
4484f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra            setAudioEncodingBitRate(profile.audioBitRate);
4494f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra            setAudioChannels(profile.audioChannels);
4504f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra            setAudioSamplingRate(profile.audioSampleRate);
4514f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra            setAudioEncoder(profile.audioCodec);
4524f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra        }
453e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong    }
454e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong
455e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong    /**
4564f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra     * Set video frame capture rate. This can be used to set a different video frame capture
457a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong     * rate than the recorded video's playback rate. This method also sets the recording mode
458a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong     * to time lapse. In time lapse video recording, only video is recorded. Audio related
459a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong     * parameters are ignored when a time lapse recording session starts, if an application
460a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong     * sets them.
461ab15bce98d44b67f221b6fb8a377744940dda46cNipun Kwatra     *
4624f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra     * @param fps Rate at which frames should be captured in frames per second.
4634f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra     * The fps can go as low as desired. However the fastest fps will be limited by the hardware.
4644f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra     * For resolutions that can be captured by the video camera, the fastest fps can be computed using
4654f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra     * {@link android.hardware.Camera.Parameters#getPreviewFpsRange(int[])}. For higher
4664f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra     * resolutions the fastest fps may be more restrictive.
4674f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra     * Note that the recorder cannot guarantee that frames will be captured at the
4684f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra     * given rate due to camera/encoder limitations. However it tries to be as close as
4694f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra     * possible.
470ab15bce98d44b67f221b6fb8a377744940dda46cNipun Kwatra     */
4714f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra    public void setCaptureRate(double fps) {
472a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong        // Make sure that time lapse is enabled when this method is called.
4731c7928e8c68654d087f83c7cefc59095950b8befJohan Redestig        setParameter("time-lapse-enable=1");
474fbdee2c04b88210bab5c9a769908be42d1775e16Chong Zhang        setParameter("time-lapse-fps=" + fps);
475ab15bce98d44b67f221b6fb8a377744940dda46cNipun Kwatra    }
476ab15bce98d44b67f221b6fb8a377744940dda46cNipun Kwatra
477ab15bce98d44b67f221b6fb8a377744940dda46cNipun Kwatra    /**
478ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong     * Sets the orientation hint for output video playback.
4795aa95dd36cd0708d25accd8d745ae8ebc255758fJames Dong     * This method should be called before prepare(). This method will not
480ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong     * trigger the source video frame to rotate during video recording, but to
481ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong     * add a composition matrix containing the rotation angle in the output
482ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong     * video if the output format is OutputFormat.THREE_GPP or
483ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong     * OutputFormat.MPEG_4 so that a video player can choose the proper
484ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong     * orientation for playback. Note that some video players may choose
485ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong     * to ignore the compostion matrix in a video during playback.
486ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong     *
487ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong     * @param degrees the angle to be rotated clockwise in degrees.
488ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong     * The supported angles are 0, 90, 180, and 270 degrees.
489ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong     * @throws IllegalArgumentException if the angle is not supported.
490ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong     *
491ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong     */
492ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong    public void setOrientationHint(int degrees) {
493ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong        if (degrees != 0   &&
494ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong            degrees != 90  &&
495ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong            degrees != 180 &&
496ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong            degrees != 270) {
497ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong            throw new IllegalArgumentException("Unsupported angle: " + degrees);
498ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong        }
4992450830c0c41a45d333838f4dcf3ba1e4a2409a2Henrik Backlund        setParameter("video-param-rotation-angle-degrees=" + degrees);
500ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong    }
501ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong
502ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong    /**
503af3131fe2e20c7b5e080d098a3b6847c5414bcaeJames Dong     * Set and store the geodata (latitude and longitude) in the output file.
504987ab4833ecbafbdf750eb1b04e43693433c4783James Dong     * This method should be called before prepare(). The geodata is
505987ab4833ecbafbdf750eb1b04e43693433c4783James Dong     * stored in udta box if the output format is OutputFormat.THREE_GPP
506987ab4833ecbafbdf750eb1b04e43693433c4783James Dong     * or OutputFormat.MPEG_4, and is ignored for other output formats.
507987ab4833ecbafbdf750eb1b04e43693433c4783James Dong     * The geodata is stored according to ISO-6709 standard.
508987ab4833ecbafbdf750eb1b04e43693433c4783James Dong     *
509987ab4833ecbafbdf750eb1b04e43693433c4783James Dong     * @param latitude latitude in degrees. Its value must be in the
510987ab4833ecbafbdf750eb1b04e43693433c4783James Dong     * range [-90, 90].
511987ab4833ecbafbdf750eb1b04e43693433c4783James Dong     * @param longitude longitude in degrees. Its value must be in the
512987ab4833ecbafbdf750eb1b04e43693433c4783James Dong     * range [-180, 180].
513987ab4833ecbafbdf750eb1b04e43693433c4783James Dong     *
514987ab4833ecbafbdf750eb1b04e43693433c4783James Dong     * @throws IllegalArgumentException if the given latitude or
515987ab4833ecbafbdf750eb1b04e43693433c4783James Dong     * longitude is out of range.
516987ab4833ecbafbdf750eb1b04e43693433c4783James Dong     *
517987ab4833ecbafbdf750eb1b04e43693433c4783James Dong     */
518af3131fe2e20c7b5e080d098a3b6847c5414bcaeJames Dong    public void setLocation(float latitude, float longitude) {
519987ab4833ecbafbdf750eb1b04e43693433c4783James Dong        int latitudex10000  = (int) (latitude * 10000 + 0.5);
520987ab4833ecbafbdf750eb1b04e43693433c4783James Dong        int longitudex10000 = (int) (longitude * 10000 + 0.5);
521987ab4833ecbafbdf750eb1b04e43693433c4783James Dong
522987ab4833ecbafbdf750eb1b04e43693433c4783James Dong        if (latitudex10000 > 900000 || latitudex10000 < -900000) {
523af3131fe2e20c7b5e080d098a3b6847c5414bcaeJames Dong            String msg = "Latitude: " + latitude + " out of range.";
524987ab4833ecbafbdf750eb1b04e43693433c4783James Dong            throw new IllegalArgumentException(msg);
525987ab4833ecbafbdf750eb1b04e43693433c4783James Dong        }
526987ab4833ecbafbdf750eb1b04e43693433c4783James Dong        if (longitudex10000 > 1800000 || longitudex10000 < -1800000) {
527af3131fe2e20c7b5e080d098a3b6847c5414bcaeJames Dong            String msg = "Longitude: " + longitude + " out of range";
528987ab4833ecbafbdf750eb1b04e43693433c4783James Dong            throw new IllegalArgumentException(msg);
529987ab4833ecbafbdf750eb1b04e43693433c4783James Dong        }
530987ab4833ecbafbdf750eb1b04e43693433c4783James Dong
531987ab4833ecbafbdf750eb1b04e43693433c4783James Dong        setParameter("param-geotag-latitude=" + latitudex10000);
532987ab4833ecbafbdf750eb1b04e43693433c4783James Dong        setParameter("param-geotag-longitude=" + longitudex10000);
533987ab4833ecbafbdf750eb1b04e43693433c4783James Dong    }
534987ab4833ecbafbdf750eb1b04e43693433c4783James Dong
535987ab4833ecbafbdf750eb1b04e43693433c4783James Dong    /**
5369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Sets the format of the output file produced during recording. Call this
5379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * after setAudioSource()/setVideoSource() but before prepare().
5389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
5392170312ab0b6766e8b73b806efbe6abdbb702bbcDave Sparks     * <p>It is recommended to always use 3GP format when using the H.263
5402170312ab0b6766e8b73b806efbe6abdbb702bbcDave Sparks     * video encoder and AMR audio encoder. Using an MPEG-4 container format
5412170312ab0b6766e8b73b806efbe6abdbb702bbcDave Sparks     * may confuse some desktop players.</p>
5422170312ab0b6766e8b73b806efbe6abdbb702bbcDave Sparks     *
5439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param output_format the output format to use. The output format
5449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * needs to be specified before setting recording-parameters or encoders.
5459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @throws IllegalStateException if it is called after prepare() or before
5469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * setAudioSource()/setVideoSource().
5479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see android.media.MediaRecorder.OutputFormat
5489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
5499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public native void setOutputFormat(int output_format)
5509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            throws IllegalStateException;
5519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
5539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Sets the width and height of the video to be captured.  Must be called
5549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * after setVideoSource(). Call this after setOutFormat() but before
5559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * prepare().
5569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
5579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param width the width of the video to be captured
5589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param height the height of the video to be captured
5599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @throws IllegalStateException if it is called after
5609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * prepare() or before setOutputFormat()
5619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
5629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public native void setVideoSize(int width, int height)
5639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            throws IllegalStateException;
5649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
5669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Sets the frame rate of the video to be captured.  Must be called
5679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * after setVideoSource(). Call this after setOutFormat() but before
5689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * prepare().
5699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
5709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param rate the number of frames per second of video to capture
5719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @throws IllegalStateException if it is called after
5729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * prepare() or before setOutputFormat().
5739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
5749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * NOTE: On some devices that have auto-frame rate, this sets the
5759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * maximum frame rate, not a constant frame rate. Actual frame rate
5769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * will vary according to lighting conditions.
5779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
5789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public native void setVideoFrameRate(int rate) throws IllegalStateException;
5799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
581ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project     * Sets the maximum duration (in ms) of the recording session.
582ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project     * Call this after setOutFormat() but before prepare().
583105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project     * After recording reaches the specified duration, a notification
584105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project     * will be sent to the {@link android.media.MediaRecorder.OnInfoListener}
585105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project     * with a "what" code of {@link #MEDIA_RECORDER_INFO_MAX_DURATION_REACHED}
586105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project     * and recording will be stopped. Stopping happens asynchronously, there
587105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project     * is no guarantee that the recorder will have stopped by the time the
588105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project     * listener is notified.
589ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project     *
590ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project     * @param max_duration_ms the maximum duration in ms (if zero or negative, disables the duration limit)
591ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project     *
592ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project     */
593ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project    public native void setMaxDuration(int max_duration_ms) throws IllegalArgumentException;
594ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project
595ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project    /**
596105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project     * Sets the maximum filesize (in bytes) of the recording session.
597105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project     * Call this after setOutFormat() but before prepare().
598105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project     * After recording reaches the specified filesize, a notification
599105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project     * will be sent to the {@link android.media.MediaRecorder.OnInfoListener}
600105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project     * with a "what" code of {@link #MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED}
601105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project     * and recording will be stopped. Stopping happens asynchronously, there
602105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project     * is no guarantee that the recorder will have stopped by the time the
603105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project     * listener is notified.
604105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project     *
605105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project     * @param max_filesize_bytes the maximum filesize in bytes (if zero or negative, disables the limit)
606105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project     *
607105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project     */
608105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project    public native void setMaxFileSize(long max_filesize_bytes) throws IllegalArgumentException;
609105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project
610105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project    /**
6119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Sets the audio encoder to be used for recording. If this method is not
6129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * called, the output file will not contain an audio track. Call this after
6139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * setOutputFormat() but before prepare().
6149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
6159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param audio_encoder the audio encoder to use.
6169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @throws IllegalStateException if it is called before
6179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * setOutputFormat() or after prepare().
6189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see android.media.MediaRecorder.AudioEncoder
6199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
6209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public native void setAudioEncoder(int audio_encoder)
6219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            throws IllegalStateException;
6229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
6249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Sets the video encoder to be used for recording. If this method is not
6259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * called, the output file will not contain an video track. Call this after
6269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * setOutputFormat() and before prepare().
6279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
6289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param video_encoder the video encoder to use.
6299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @throws IllegalStateException if it is called before
6309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * setOutputFormat() or after prepare()
6319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see android.media.MediaRecorder.VideoEncoder
6329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
6339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public native void setVideoEncoder(int video_encoder)
6349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            throws IllegalStateException;
6359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
6370fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     * Sets the audio sampling rate for recording. Call this method before prepare().
6380fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     * Prepare() may perform additional checks on the parameter to make sure whether
6390fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     * the specified audio sampling rate is applicable. The sampling rate really depends
6400fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     * on the format for the audio recording, as well as the capabilities of the platform.
6410fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     * For instance, the sampling rate supported by AAC audio coding standard ranges
64254815a78aff9bd453a8f0ac3c02f3a35c4b04146James Dong     * from 8 to 96 kHz, the sampling rate supported by AMRNB is 8kHz, and the sampling
64354815a78aff9bd453a8f0ac3c02f3a35c4b04146James Dong     * rate supported by AMRWB is 16kHz. Please consult with the related audio coding
64454815a78aff9bd453a8f0ac3c02f3a35c4b04146James Dong     * standard for the supported audio sampling rate.
6450fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     *
6460fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     * @param samplingRate the sampling rate for audio in samples per second.
6470fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     */
6480fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong    public void setAudioSamplingRate(int samplingRate) {
6490fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong        if (samplingRate <= 0) {
6500fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong            throw new IllegalArgumentException("Audio sampling rate is not positive");
6510fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong        }
6522450830c0c41a45d333838f4dcf3ba1e4a2409a2Henrik Backlund        setParameter("audio-param-sampling-rate=" + samplingRate);
6530fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong    }
6540fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong
6550fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong    /**
6560fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     * Sets the number of audio channels for recording. Call this method before prepare().
6570fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     * Prepare() may perform additional checks on the parameter to make sure whether the
6580fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     * specified number of audio channels are applicable.
6592bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang     *
6600fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     * @param numChannels the number of audio channels. Usually it is either 1 (mono) or 2
6610fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     * (stereo).
6622bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang     */
6630fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong    public void setAudioChannels(int numChannels) {
6640fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong        if (numChannels <= 0) {
6650fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong            throw new IllegalArgumentException("Number of channels is not positive");
6660fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong        }
6672450830c0c41a45d333838f4dcf3ba1e4a2409a2Henrik Backlund        setParameter("audio-param-number-of-channels=" + numChannels);
6680fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong    }
6690fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong
6700fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong    /**
6710fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     * Sets the audio encoding bit rate for recording. Call this method before prepare().
6720fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     * Prepare() may perform additional checks on the parameter to make sure whether the
6730fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     * specified bit rate is applicable, and sometimes the passed bitRate will be clipped
6740fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     * internally to ensure the audio recording can proceed smoothly based on the
6750fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     * capabilities of the platform.
6760fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     *
6770fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     * @param bitRate the audio encoding bit rate in bits per second.
6780fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     */
6790fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong    public void setAudioEncodingBitRate(int bitRate) {
6800fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong        if (bitRate <= 0) {
6810fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong            throw new IllegalArgumentException("Audio encoding bit rate is not positive");
6820fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong        }
6832450830c0c41a45d333838f4dcf3ba1e4a2409a2Henrik Backlund        setParameter("audio-param-encoding-bitrate=" + bitRate);
6840fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong    }
6850fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong
6860fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong    /**
6870fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     * Sets the video encoding bit rate for recording. Call this method before prepare().
6880fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     * Prepare() may perform additional checks on the parameter to make sure whether the
6890fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     * specified bit rate is applicable, and sometimes the passed bitRate will be
6900fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     * clipped internally to ensure the video recording can proceed smoothly based on
6910fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     * the capabilities of the platform.
6920fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     *
6930fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     * @param bitRate the video encoding bit rate in bits per second.
6940fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong     */
6950fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong    public void setVideoEncodingBitRate(int bitRate) {
6960fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong        if (bitRate <= 0) {
6970fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong            throw new IllegalArgumentException("Video encoding bit rate is not positive");
6980fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong        }
6992450830c0c41a45d333838f4dcf3ba1e4a2409a2Henrik Backlund        setParameter("video-param-encoding-bitrate=" + bitRate);
7000fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong    }
7012bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang
7022bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang    /**
7033ff98beeafd271a65c1f824699431366882b04f6James Dong     * Currently not implemented. It does nothing.
7043ff98beeafd271a65c1f824699431366882b04f6James Dong     * @deprecated Time lapse mode video recording using camera still image capture
7053ff98beeafd271a65c1f824699431366882b04f6James Dong     * is not desirable, and will not be supported.
706029d7e15f38cdd3c1941a16186c5941edc85bc3dJames Dong     * @hide
707b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra     */
7081fec21be65ddda46fe39c40e00d2fb94a8ce59f1Nipun Kwatra    public void setAuxiliaryOutputFile(FileDescriptor fd)
709b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra    {
7103ff98beeafd271a65c1f824699431366882b04f6James Dong        Log.w(TAG, "setAuxiliaryOutputFile(FileDescriptor) is no longer supported.");
711b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra    }
712b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra
713b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra    /**
7143ff98beeafd271a65c1f824699431366882b04f6James Dong     * Currently not implemented. It does nothing.
7153ff98beeafd271a65c1f824699431366882b04f6James Dong     * @deprecated Time lapse mode video recording using camera still image capture
7163ff98beeafd271a65c1f824699431366882b04f6James Dong     * is not desirable, and will not be supported.
717029d7e15f38cdd3c1941a16186c5941edc85bc3dJames Dong     * @hide
718b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra     */
7191fec21be65ddda46fe39c40e00d2fb94a8ce59f1Nipun Kwatra    public void setAuxiliaryOutputFile(String path)
720b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra    {
7213ff98beeafd271a65c1f824699431366882b04f6James Dong        Log.w(TAG, "setAuxiliaryOutputFile(String) is no longer supported.");
722b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra    }
723b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra
724b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra    /**
7259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Pass in the file descriptor of the file to be written. Call this after
7269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * setOutputFormat() but before prepare().
7279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
7289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param fd an open file descriptor to be written into.
7299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @throws IllegalStateException if it is called before
7309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * setOutputFormat() or after prepare()
7319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
7329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void setOutputFile(FileDescriptor fd) throws IllegalStateException
7339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
7349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mPath = null;
7359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mFd = fd;
7369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
7379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
7399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Sets the path of the output file to be produced. Call this after
7409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * setOutputFormat() but before prepare().
7419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
7429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param path The pathname to use.
7439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @throws IllegalStateException if it is called before
7449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * setOutputFormat() or after prepare()
7459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
7469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void setOutputFile(String path) throws IllegalStateException
7479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
7489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mFd = null;
7499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mPath = path;
7509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
7519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    // native implementation
7539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private native void _setOutputFile(FileDescriptor fd, long offset, long length)
7549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        throws IllegalStateException, IOException;
7559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private native void _prepare() throws IllegalStateException, IOException;
7569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
7589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Prepares the recorder to begin capturing and encoding data. This method
7599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * must be called after setting up the desired audio and video sources,
7609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * encoders, file format, etc., but before start().
7619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
7629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @throws IllegalStateException if it is called after
7639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * start() or before setOutputFormat().
7649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @throws IOException if prepare fails otherwise.
7659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
7669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void prepare() throws IllegalStateException, IOException
7679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
7689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (mPath != null) {
7690d5d3b7cc8b9ff142269a947443c758cb2af4684Robert Shih            RandomAccessFile file = new RandomAccessFile(mPath, "rws");
7709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            try {
7710d5d3b7cc8b9ff142269a947443c758cb2af4684Robert Shih                _setOutputFile(file.getFD(), 0, 0);
7729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            } finally {
7730d5d3b7cc8b9ff142269a947443c758cb2af4684Robert Shih                file.close();
7749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
7759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } else if (mFd != null) {
7769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            _setOutputFile(mFd, 0, 0);
7779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } else {
7789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            throw new IOException("No valid output file");
7799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
780b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra
7819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        _prepare();
7829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
7839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
7859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Begins capturing and encoding data to the file specified with
7869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * setOutputFile(). Call this after prepare().
7879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
78842419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * <p>Since API level 13, if applications set a camera via
78942419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * {@link #setCamera(Camera)}, the apps can use the camera after this method
790528b084be26ff6f5b5d8cf42007bf964857be8daWu-cheng Li     * call. The apps do not need to lock the camera again. However, if this
791528b084be26ff6f5b5d8cf42007bf964857be8daWu-cheng Li     * method fails, the apps should still lock the camera back. The apps should
792528b084be26ff6f5b5d8cf42007bf964857be8daWu-cheng Li     * not start another recording session during recording.
79342419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     *
7949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @throws IllegalStateException if it is called before
7959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * prepare().
7969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
7979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public native void start() throws IllegalStateException;
7989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
8009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Stops recording. Call this after start(). Once recording is stopped,
8019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * you will have to configure it again as if it has just been constructed.
80222bf7a7ea768c2cdadc5faf643aba70aebafc0d5James Dong     * Note that a RuntimeException is intentionally thrown to the
80322bf7a7ea768c2cdadc5faf643aba70aebafc0d5James Dong     * application, if no valid audio/video data has been received when stop()
80422bf7a7ea768c2cdadc5faf643aba70aebafc0d5James Dong     * is called. This happens if stop() is called immediately after
80522bf7a7ea768c2cdadc5faf643aba70aebafc0d5James Dong     * start(). The failure lets the application take action accordingly to
80622bf7a7ea768c2cdadc5faf643aba70aebafc0d5James Dong     * clean up the output file (delete the output file, for instance), since
80722bf7a7ea768c2cdadc5faf643aba70aebafc0d5James Dong     * the output file is not properly constructed when this happens.
8089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
8099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @throws IllegalStateException if it is called before start()
8109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
8119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public native void stop() throws IllegalStateException;
8129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
8139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
81483995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim     * Pauses recording. Call this after start(). You may resume recording
81583995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim     * with resume() without reconfiguration, as opposed to stop(). It does
81683995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim     * nothing if the recording is already paused.
81783995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim     *
81883995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim     * When the recording is paused and resumed, the resulting output would
81983995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim     * be as if nothing happend during paused period, immediately switching
82083995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim     * to the resumed scene.
82183995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim     *
82283995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim     * @throws IllegalStateException if it is called before start() or after
82383995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim     * stop()
82483995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim     * {@hide}
82583995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim     */
82683995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim    public native void pause() throws IllegalStateException;
82783995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim
82883995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim    /**
82983995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim     * Resumes recording. Call this after start(). It does nothing if the
83083995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim     * recording is not paused.
83183995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim     *
83283995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim     * @throws IllegalStateException if it is called before start() or after
83383995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim     * stop()
83483995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim     * @see android.media.MediaRecorder#pause
83583995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim     * {@hide}
83683995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim     */
83783995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim    public native void resume() throws IllegalStateException;
83883995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim
83983995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim    /**
8409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Restarts the MediaRecorder to its idle state. After calling
8419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * this method, you will have to configure it again as if it had just been
8429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * constructed.
8439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
8449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void reset() {
8459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        native_reset();
8469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
8479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // make sure none of the listeners get called anymore
8489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mEventHandler.removeCallbacksAndMessages(null);
8499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
8509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
8519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private native void native_reset();
8529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
8539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
8549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Returns the maximum absolute amplitude that was sampled since the last
8559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * call to this method. Call this only after the setAudioSource().
8569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
8579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return the maximum absolute amplitude measured since the last call, or
8589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * 0 when called for the first time
8599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @throws IllegalStateException if it is called before
8609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * the audio source has been set.
8619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
8629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public native int getMaxAmplitude() throws IllegalStateException;
8639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
8649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /* Do not change this value without updating its counterpart
865a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong     * in include/media/mediarecorder.h or mediaplayer.h!
8669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
8679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /** Unspecified media recorder error.
8689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see android.media.MediaRecorder.OnErrorListener
8699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
8709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int MEDIA_RECORDER_ERROR_UNKNOWN = 1;
871a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong    /** Media server died. In this case, the application must release the
872a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong     * MediaRecorder object and instantiate a new one.
873a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong     * @see android.media.MediaRecorder.OnErrorListener
874a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong     */
875a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong    public static final int MEDIA_ERROR_SERVER_DIED = 100;
8769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
8779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
8789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Interface definition for a callback to be invoked when an error
8799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * occurs while recording.
8809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
8819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public interface OnErrorListener
8829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
8839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
8849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Called when an error occurs while recording.
8852bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang         *
8869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param mr the MediaRecorder that encountered the error
8879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param what    the type of error that has occurred:
8889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * <ul>
8899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * <li>{@link #MEDIA_RECORDER_ERROR_UNKNOWN}
890a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong         * <li>{@link #MEDIA_ERROR_SERVER_DIED}
8919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * </ul>
8929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param extra   an extra code, specific to the error type
8939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
8949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        void onError(MediaRecorder mr, int what, int extra);
8959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
8969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
8979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
8989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Register a callback to be invoked when an error occurs while
8999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * recording.
9009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
9019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param l the callback that will be run
9029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
9039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void setOnErrorListener(OnErrorListener l)
9049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
9059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mOnErrorListener = l;
9069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
9079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
908ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project    /* Do not change these values without updating their counterparts
909ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project     * in include/media/mediarecorder.h!
910ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project     */
911ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project    /** Unspecified media recorder error.
912ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project     * @see android.media.MediaRecorder.OnInfoListener
913ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project     */
914ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project    public static final int MEDIA_RECORDER_INFO_UNKNOWN              = 1;
915ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project    /** A maximum duration had been setup and has now been reached.
916ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project     * @see android.media.MediaRecorder.OnInfoListener
917ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project     */
918ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project    public static final int MEDIA_RECORDER_INFO_MAX_DURATION_REACHED = 800;
919105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project    /** A maximum filesize had been setup and has now been reached.
920105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project     * @see android.media.MediaRecorder.OnInfoListener
921105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project     */
922105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project    public static final int MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED = 801;
923ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project
9249e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong    /** informational events for individual tracks, for testing purpose.
9259e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * The track informational event usually contains two parts in the ext1
9269e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * arg of the onInfo() callback: bit 31-28 contains the track id; and
9279e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * the rest of the 28 bits contains the informational event defined here.
9289e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * For example, ext1 = (1 << 28 | MEDIA_RECORDER_TRACK_INFO_TYPE) if the
9299e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * track id is 1 for informational event MEDIA_RECORDER_TRACK_INFO_TYPE;
9309e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * while ext1 = (0 << 28 | MEDIA_RECORDER_TRACK_INFO_TYPE) if the track
9319e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * id is 0 for informational event MEDIA_RECORDER_TRACK_INFO_TYPE. The
9329e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * application should extract the track id and the type of informational
9339e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * event from ext1, accordingly.
9349e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     *
9359e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * FIXME:
9369e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * Please update the comment for onInfo also when these
9379e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * events are unhidden so that application knows how to extract the track
9389e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * id and the informational event type from onInfo callback.
9399e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     *
9409e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * {@hide}
9419e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     */
9429e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong    public static final int MEDIA_RECORDER_TRACK_INFO_LIST_START        = 1000;
9439e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong    /** Signal the completion of the track for the recording session.
9449e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * {@hide}
9459e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     */
9469e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong    public static final int MEDIA_RECORDER_TRACK_INFO_COMPLETION_STATUS = 1000;
9479e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong    /** Indicate the recording progress in time (ms) during recording.
9489e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * {@hide}
9499e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     */
9509e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong    public static final int MEDIA_RECORDER_TRACK_INFO_PROGRESS_IN_TIME  = 1001;
9519e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong    /** Indicate the track type: 0 for Audio and 1 for Video.
9529e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * {@hide}
9539e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     */
9549e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong    public static final int MEDIA_RECORDER_TRACK_INFO_TYPE              = 1002;
9559e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong    /** Provide the track duration information.
9569e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * {@hide}
9579e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     */
9589e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong    public static final int MEDIA_RECORDER_TRACK_INFO_DURATION_MS       = 1003;
9599e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong    /** Provide the max chunk duration in time (ms) for the given track.
9609e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * {@hide}
9619e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     */
9629e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong    public static final int MEDIA_RECORDER_TRACK_INFO_MAX_CHUNK_DUR_MS  = 1004;
9639e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong    /** Provide the total number of recordd frames.
9649e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * {@hide}
9659e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     */
9669e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong    public static final int MEDIA_RECORDER_TRACK_INFO_ENCODED_FRAMES    = 1005;
9679e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong    /** Provide the max spacing between neighboring chunks for the given track.
9689e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * {@hide}
9699e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     */
9709e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong    public static final int MEDIA_RECORDER_TRACK_INTER_CHUNK_TIME_MS    = 1006;
9719e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong    /** Provide the elapsed time measuring from the start of the recording
9729e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * till the first output frame of the given track is received, excluding
9739e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * any intentional start time offset of a recording session for the
9749e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * purpose of eliminating the recording sound in the recorded file.
9759e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * {@hide}
9769e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     */
9779e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong    public static final int MEDIA_RECORDER_TRACK_INFO_INITIAL_DELAY_MS  = 1007;
9789e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong    /** Provide the start time difference (delay) betweeen this track and
9799e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * the start of the movie.
9809e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * {@hide}
9819e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     */
9829e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong    public static final int MEDIA_RECORDER_TRACK_INFO_START_OFFSET_MS   = 1008;
9830f32fb3ecfdfaa03acf880a356629d43da3fe2feJames Dong    /** Provide the total number of data (in kilo-bytes) encoded.
9840f32fb3ecfdfaa03acf880a356629d43da3fe2feJames Dong     * {@hide}
9850f32fb3ecfdfaa03acf880a356629d43da3fe2feJames Dong     */
9860f32fb3ecfdfaa03acf880a356629d43da3fe2feJames Dong    public static final int MEDIA_RECORDER_TRACK_INFO_DATA_KBYTES       = 1009;
9879e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong    /**
9889e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     * {@hide}
9899e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong     */
9909e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong    public static final int MEDIA_RECORDER_TRACK_INFO_LIST_END          = 2000;
9919e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong
9929e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong
993ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project    /**
994ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project     * Interface definition for a callback to be invoked when an error
995ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project     * occurs while recording.
996ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project     */
997ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project    public interface OnInfoListener
998ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project    {
999ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project        /**
1000ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project         * Called when an error occurs while recording.
10012bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang         *
1002ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project         * @param mr the MediaRecorder that encountered the error
1003ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project         * @param what    the type of error that has occurred:
1004ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project         * <ul>
1005ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project         * <li>{@link #MEDIA_RECORDER_INFO_UNKNOWN}
1006105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project         * <li>{@link #MEDIA_RECORDER_INFO_MAX_DURATION_REACHED}
1007105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project         * <li>{@link #MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED}
1008ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project         * </ul>
1009ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project         * @param extra   an extra code, specific to the error type
1010ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project         */
1011ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project        void onInfo(MediaRecorder mr, int what, int extra);
1012ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project    }
1013ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project
1014ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project    /**
1015ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project     * Register a callback to be invoked when an informational event occurs while
1016ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project     * recording.
1017ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project     *
1018ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project     * @param listener the callback that will be run
1019ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project     */
1020ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project    public void setOnInfoListener(OnInfoListener listener)
1021ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project    {
1022ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project        mOnInfoListener = listener;
1023ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project    }
1024ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project
10259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private class EventHandler extends Handler
10269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
10279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        private MediaRecorder mMediaRecorder;
10289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
10299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public EventHandler(MediaRecorder mr, Looper looper) {
10309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            super(looper);
10319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mMediaRecorder = mr;
10329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
10339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1034ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project        /* Do not change these values without updating their counterparts
10359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * in include/media/mediarecorder.h!
10369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
10379e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong        private static final int MEDIA_RECORDER_EVENT_LIST_START = 1;
10389e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong        private static final int MEDIA_RECORDER_EVENT_ERROR      = 1;
10399e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong        private static final int MEDIA_RECORDER_EVENT_INFO       = 2;
10409e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong        private static final int MEDIA_RECORDER_EVENT_LIST_END   = 99;
10419e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong
10429e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong        /* Events related to individual tracks */
10439e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong        private static final int MEDIA_RECORDER_TRACK_EVENT_LIST_START = 100;
10449e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong        private static final int MEDIA_RECORDER_TRACK_EVENT_ERROR      = 100;
10459e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong        private static final int MEDIA_RECORDER_TRACK_EVENT_INFO       = 101;
10469e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong        private static final int MEDIA_RECORDER_TRACK_EVENT_LIST_END   = 1000;
10479e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong
10489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
10499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        @Override
10509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void handleMessage(Message msg) {
10519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            if (mMediaRecorder.mNativeContext == 0) {
10529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                Log.w(TAG, "mediarecorder went away with unhandled events");
10539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
10549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
10559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            switch(msg.what) {
10569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            case MEDIA_RECORDER_EVENT_ERROR:
10579e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong            case MEDIA_RECORDER_TRACK_EVENT_ERROR:
10589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                if (mOnErrorListener != null)
10599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    mOnErrorListener.onError(mMediaRecorder, msg.arg1, msg.arg2);
10609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
10619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
10629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1063ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project            case MEDIA_RECORDER_EVENT_INFO:
10649e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong            case MEDIA_RECORDER_TRACK_EVENT_INFO:
1065ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project                if (mOnInfoListener != null)
1066ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project                    mOnInfoListener.onInfo(mMediaRecorder, msg.arg1, msg.arg2);
1067ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project
1068ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project                return;
1069ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project
10709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            default:
10719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                Log.e(TAG, "Unknown message type " + msg.what);
10729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
10739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
10749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
10759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
10769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
10779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
10789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Called from native code when an interesting event happens.  This method
10799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * just uses the EventHandler system to post the event back to the main app thread.
10809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * We use a weak reference to the original MediaRecorder object so that the native
10819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * code is safe from the object disappearing from underneath it.  (This is
10829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * the cookie passed to native_setup().)
10839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
10849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private static void postEventFromNative(Object mediarecorder_ref,
10859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                                            int what, int arg1, int arg2, Object obj)
10869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
10879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        MediaRecorder mr = (MediaRecorder)((WeakReference)mediarecorder_ref).get();
10889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (mr == null) {
10899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return;
10909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
10919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
10929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (mr.mEventHandler != null) {
10939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            Message m = mr.mEventHandler.obtainMessage(what, arg1, arg2, obj);
10949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mr.mEventHandler.sendMessage(m);
10959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
10969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
10979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
10989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
10999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Releases resources associated with this MediaRecorder object.
11009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * It is good practice to call this method when you're done
110189ca6983eb2be21848f5ac884a2c118f152c83e6James Dong     * using the MediaRecorder. In particular, whenever an Activity
110289ca6983eb2be21848f5ac884a2c118f152c83e6James Dong     * of an application is paused (its onPause() method is called),
110389ca6983eb2be21848f5ac884a2c118f152c83e6James Dong     * or stopped (its onStop() method is called), this method should be
110489ca6983eb2be21848f5ac884a2c118f152c83e6James Dong     * invoked to release the MediaRecorder object, unless the application
110589ca6983eb2be21848f5ac884a2c118f152c83e6James Dong     * has a special need to keep the object around. In addition to
110689ca6983eb2be21848f5ac884a2c118f152c83e6James Dong     * unnecessary resources (such as memory and instances of codecs)
110789ca6983eb2be21848f5ac884a2c118f152c83e6James Dong     * being held, failure to call this method immediately if a
110889ca6983eb2be21848f5ac884a2c118f152c83e6James Dong     * MediaRecorder object is no longer needed may also lead to
110989ca6983eb2be21848f5ac884a2c118f152c83e6James Dong     * continuous battery consumption for mobile devices, and recording
111089ca6983eb2be21848f5ac884a2c118f152c83e6James Dong     * failure for other applications if no multiple instances of the
111189ca6983eb2be21848f5ac884a2c118f152c83e6James Dong     * same codec are supported on a device. Even if multiple instances
111289ca6983eb2be21848f5ac884a2c118f152c83e6James Dong     * of the same codec are supported, some performance degradation
111389ca6983eb2be21848f5ac884a2c118f152c83e6James Dong     * may be expected when unnecessary multiple instances are used
111489ca6983eb2be21848f5ac884a2c118f152c83e6James Dong     * at the same time.
11159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
11169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public native void release();
11179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
11184935d05eaa306cef88cf0ab13eca386f270409ecMarco Nelissen    private static native final void native_init();
11194935d05eaa306cef88cf0ab13eca386f270409ecMarco Nelissen
1120788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvala    private native final void native_setup(Object mediarecorder_this,
1121fa5ecdc4ac6d7a8db2bb9e4a6a60a3189025df30Svet Ganov            String clientName, String opPackageName) throws IllegalStateException;
11229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
11239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private native final void native_finalize();
11249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
11250fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong    private native void setParameter(String nameValuePair);
11260fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong
11279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    @Override
11289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    protected void finalize() { native_finalize(); }
11299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
1130