19bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava/*
29bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava * Copyright (C) 2010 The Android Open Source Project
39bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava *
49bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava * Licensed under the Apache License, Version 2.0 (the "License");
59bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava * you may not use this file except in compliance with the License.
69bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava * You may obtain a copy of the License at
79bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava *
89bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava *      http://www.apache.org/licenses/LICENSE-2.0
99bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava *
109bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava * Unless required by applicable law or agreed to in writing, software
119bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava * distributed under the License is distributed on an "AS IS" BASIS,
129bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava * See the License for the specific language governing permissions and
149bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava * limitations under the License.
159bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava */
169bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
179bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
189bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhavapackage android.media.videoeditor;
199bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
209bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhavaimport java.io.IOException;
219bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhavaimport java.util.List;
229bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhavaimport java.util.concurrent.CancellationException;
239c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargiimport android.graphics.Bitmap;
249c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargiimport android.graphics.Color;
259c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargiimport android.graphics.Canvas;
26a573b563b3c6a3edc60393543dc9adb7ade4f188Dharmaray Kundargiimport android.graphics.Paint;
279c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargiimport android.graphics.Rect;
289bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhavaimport android.view.SurfaceHolder;
299bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
309bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava/**
319bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava * This is the interface implemented by classes which provide video editing
329bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava * functionality. The VideoEditor implementation class manages all input and
339bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava * output files. Unless specifically mentioned, methods are blocking. A typical
349bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava * editing session may consist of the following sequence of operations:
359bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava *
369bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava * <ul>
379bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava *  <li>Add a set of MediaItems</li>
389bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava *  <li>Apply a set of Transitions between MediaItems</li>
399bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava *  <li>Add Effects and Overlays to media items</li>
409bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava *  <li>Preview the movie at any time</li>
419bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava *  <li>Save the VideoEditor implementation class internal state</li>
429bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava *  <li>Release the VideoEditor implementation class instance by invoking
439bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava * {@link #release()}
449bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava * </ul>
459bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava * The internal VideoEditor state consists of the following elements:
469bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava * <ul>
479bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava *  <li>Ordered & trimmed MediaItems</li>
489bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava *  <li>Transition video clips</li>
499bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava *  <li>Overlays</li>
509bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava *  <li>Effects</li>
519bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava *  <li>Audio waveform for the background audio and MediaItems</li>
529bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava *  <li>Project thumbnail</li>
539bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava *  <li>Last exported movie.</li>
549bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava *  <li>Other project specific data such as the current aspect ratio.</li>
559bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava * </ul>
569bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava * {@hide}
579bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava */
589bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhavapublic interface VideoEditor {
599bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
609bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *  The file name of the project thumbnail
619bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
629bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public static final String THUMBNAIL_FILENAME = "thumbnail.jpg";
639bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
649bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
659bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *  Use this value instead of the specific end of the storyboard timeline
669bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *  value.
679bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
689bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public final static int DURATION_OF_STORYBOARD = -1;
699bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
709bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
714d0ec22aa91428030ae9ef1ead6f1b1d769745acShailendra Yadav     *  Maximum supported file size
724d0ec22aa91428030ae9ef1ead6f1b1d769745acShailendra Yadav     */
734d0ec22aa91428030ae9ef1ead6f1b1d769745acShailendra Yadav    public static final long MAX_SUPPORTED_FILE_SIZE = 2147483648L;
744d0ec22aa91428030ae9ef1ead6f1b1d769745acShailendra Yadav
754d0ec22aa91428030ae9ef1ead6f1b1d769745acShailendra Yadav    /**
769bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * This listener interface is used by the VideoEditor to emit preview
779bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * progress notifications. This callback should be invoked after the number
789bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * of frames specified by
799bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * {@link #startPreview(SurfaceHolder surfaceHolder, long fromMs,
809bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *           int callbackAfterFrameCount, PreviewProgressListener listener)}
819bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
829bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public interface PreviewProgressListener {
839bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava        /**
849bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         * This method notifies the listener of the current time position while
859bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         * previewing a project.
869bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         *
879bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         * @param videoEditor The VideoEditor instance
889bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         * @param timeMs The current preview position (expressed in milliseconds
899bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         *        since the beginning of the storyboard timeline).
909c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         * @param overlayData The overlay data (null if the overlay data
919c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         *      is unchanged)
929c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         */
939c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        public void onProgress(VideoEditor videoEditor, long timeMs,
949c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                               OverlayData overlayData);
959c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        /**
969c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         * This method notifies the listener when the preview is started
979c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         * previewing a project.
989c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         *
999c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         * @param videoEditor The VideoEditor instance
1009bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         */
1019c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        public void onStart(VideoEditor videoEditor);
1029c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi
1039c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        /**
1049c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         * This method notifies the listener when the preview is stopped
1059c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         * previewing a project.
1069c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         *
1079c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         * @param videoEditor The VideoEditor instance
1089c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         */
1099c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        public void onStop(VideoEditor videoEditor);
11063149c81adf79f43c6508647614247277f8052e2Hong Teng
11163149c81adf79f43c6508647614247277f8052e2Hong Teng        /**
11263149c81adf79f43c6508647614247277f8052e2Hong Teng         * This method notifies the listener when error has occurred during
11363149c81adf79f43c6508647614247277f8052e2Hong Teng         * previewing a project.
11463149c81adf79f43c6508647614247277f8052e2Hong Teng         *
11563149c81adf79f43c6508647614247277f8052e2Hong Teng         * @param videoEditor The VideoEditor instance
11663149c81adf79f43c6508647614247277f8052e2Hong Teng         * @param error The error that has occurred
11763149c81adf79f43c6508647614247277f8052e2Hong Teng         * FIXME: We should pass well-defined error code to the application;
11863149c81adf79f43c6508647614247277f8052e2Hong Teng         * but for now, we just pass whatever error code reported by the native layer.
11963149c81adf79f43c6508647614247277f8052e2Hong Teng         */
12063149c81adf79f43c6508647614247277f8052e2Hong Teng        public void onError(VideoEditor videoEditor, int error);
1219bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    }
1229bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
1239bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
1249bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * This listener interface is used by the VideoEditor to emit export status
1259bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * notifications.
1269bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * {@link #export(String filename, ExportProgressListener listener,
1279bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *                int height, int bitrate)}
1289bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
1299bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public interface ExportProgressListener {
1309bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava        /**
1319bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         * This method notifies the listener of the progress status of a export
1329bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         * operation.
1339bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         *
1349bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         * @param videoEditor The VideoEditor instance
1359bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         * @param filename The name of the file which is in the process of being
1369bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         *        exported.
1379bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         * @param progress The progress in %. At the beginning of the export,
1389bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         *        this value is set to 0; at the end, the value is set to 100.
1399bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         */
1409bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava        public void onProgress(VideoEditor videoEditor, String filename,
1419bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava                              int progress);
1429bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    }
1439bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
1449bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public interface MediaProcessingProgressListener {
1459bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava        /**
1469bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         *  Values used for the action parameter
1479bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         */
1489bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava        public static final int ACTION_ENCODE = 1;
1499bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava        public static final int ACTION_DECODE = 2;
1509bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
1519bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava        /**
1529bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         * This method notifies the listener of the progress status of
1539bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         * processing a media object such as a Transition, AudioTrack & Kenburns
1549bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         * This method may be called maximum 100 times for one operation.
1559bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         *
1569bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         * @param object The object that is being processed such as a Transition
1579bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         *               or AudioTrack
1589bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         * @param action The type of processing being performed
1599bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         * @param progress The progress in %. At the beginning of the operation,
1609bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         *          this value is set to 0; at the end, the value is set to 100.
1619bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava         */
1629bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava        public void onProgress(Object item, int action, int progress);
1639bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    }
1649bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
1659bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
1669c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi     * The overlay data
1679c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi     */
1689c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi    public static final class OverlayData {
1699c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        // Instance variables
1709c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        private Bitmap mOverlayBitmap;
1719c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        private int mRenderingMode;
1729c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        private boolean mClear;
173a573b563b3c6a3edc60393543dc9adb7ade4f188Dharmaray Kundargi        private static final Paint sResizePaint = new Paint(Paint.FILTER_BITMAP_FLAG);
1749c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi
1759c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        /**
1769c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         * Default constructor
1779c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         */
1789c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        public OverlayData() {
1799c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi            mOverlayBitmap = null;
1809c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi            mRenderingMode = MediaArtistNativeHelper.MediaRendering.BLACK_BORDERS;
1819c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi            mClear = false;
1829c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        }
1839c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi
1849c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        /**
1859c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         * Releases the bitmap
1869c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         */
1879c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        public void release() {
1889c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi            if (mOverlayBitmap != null) {
1899c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                mOverlayBitmap.recycle();
1909c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                mOverlayBitmap = null;
1919c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi            }
1929c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        }
1939c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi
1949c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        /**
1959c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         * Check if the overlay needs to be rendered
1969c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         *
1979c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         * @return true if rendering is needed
1989c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         */
1999c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        public boolean needsRendering() {
2009c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi            return (mClear || mOverlayBitmap != null);
2019c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        }
2029c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi
2039c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        /**
2049c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         * Store the overlay data
2059c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         *
2069c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         * @param overlayBitmap The overlay bitmap
2079c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         * @param renderingMode The rendering mode
2089c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         */
2099c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        void set(Bitmap overlayBitmap, int renderingMode) {
2109c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi            mOverlayBitmap = overlayBitmap;
2119c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi            mRenderingMode = renderingMode;
2129c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi            mClear = false;
2139c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        }
2149c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi
2159c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        /**
2169c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         * Clear the overlay
2179c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi         */
2189c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        void setClear() {
2199c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi            mClear = true;
2209c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        }
2219c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi
2229c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        /**
2239c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        * Render the overlay by either clearing it or by
2249c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        * rendering the overlay bitmap with the specified
2259c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        * rendering mode
2269c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        *
2279c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        * @param destBitmap The destination bitmap
2289c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        */
2299c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        public void renderOverlay(Bitmap destBitmap) {
2309c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi            if (mClear) {
2319c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                destBitmap.eraseColor(Color.TRANSPARENT);
2329c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi            } else if (mOverlayBitmap != null) {
2339c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                final Canvas overlayCanvas = new Canvas(destBitmap);
2349c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                final Rect destRect;
2359c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                final Rect srcRect;
2369c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                switch (mRenderingMode) {
2379c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                    case MediaArtistNativeHelper.MediaRendering.RESIZING: {
2389c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                        destRect = new Rect(0, 0, overlayCanvas.getWidth(),
2399c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                                                 overlayCanvas.getHeight());
2409c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                        srcRect = new Rect(0, 0, mOverlayBitmap.getWidth(),
2419c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                                                 mOverlayBitmap.getHeight());
2429c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                        break;
2439c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                    }
2449c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi
2459c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                    case MediaArtistNativeHelper.MediaRendering.BLACK_BORDERS: {
2469c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                        int left, right, top, bottom;
2479c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                        float aROverlayImage, aRCanvas;
2489c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                        aROverlayImage = (float)(mOverlayBitmap.getWidth()) /
2499c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                                         (float)(mOverlayBitmap.getHeight());
2509c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi
2519c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                        aRCanvas = (float)(overlayCanvas.getWidth()) /
2529c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                                         (float)(overlayCanvas.getHeight());
2539c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi
2549c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                        if (aROverlayImage > aRCanvas) {
2559c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                            int newHeight = ((overlayCanvas.getWidth() * mOverlayBitmap.getHeight())
2569c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                                             / mOverlayBitmap.getWidth());
2579c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                            left = 0;
2589c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                            top  = (overlayCanvas.getHeight() - newHeight) / 2;
2599c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                            right = overlayCanvas.getWidth();
2609c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                            bottom = top + newHeight;
2619c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                        } else {
2629c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                            int newWidth = ((overlayCanvas.getHeight() * mOverlayBitmap.getWidth())
2639c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                                                / mOverlayBitmap.getHeight());
2649c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                            left = (overlayCanvas.getWidth() - newWidth) / 2;
2659c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                            top  = 0;
2669c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                            right = left + newWidth;
2679c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                            bottom = overlayCanvas.getHeight();
2689c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                        }
2699c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi
2709c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                        destRect = new Rect(left, top, right, bottom);
2719c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                        srcRect = new Rect(0, 0, mOverlayBitmap.getWidth(), mOverlayBitmap.getHeight());
2729c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                        break;
2739c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                    }
2749c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi
2759c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                    case MediaArtistNativeHelper.MediaRendering.CROPPING: {
2769c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                        // Calculate the source rect
2779c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                        int left, right, top, bottom;
2789c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                        float aROverlayImage, aRCanvas;
2799c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                        aROverlayImage = (float)(mOverlayBitmap.getWidth()) /
2809c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                                         (float)(mOverlayBitmap.getHeight());
2819c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                        aRCanvas = (float)(overlayCanvas.getWidth()) /
2829c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                                        (float)(overlayCanvas.getHeight());
2839c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                        if (aROverlayImage < aRCanvas) {
2849c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                            int newHeight = ((mOverlayBitmap.getWidth() * overlayCanvas.getHeight())
2859c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                                       / overlayCanvas.getWidth());
2869c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi
2879c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                            left = 0;
2889c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                            top  = (mOverlayBitmap.getHeight() - newHeight) / 2;
2899c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                            right = mOverlayBitmap.getWidth();
2909c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                            bottom = top + newHeight;
2919c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                        } else {
2929c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                            int newWidth = ((mOverlayBitmap.getHeight() * overlayCanvas.getWidth())
2939c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                                        / overlayCanvas.getHeight());
2949c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                            left = (mOverlayBitmap.getWidth() - newWidth) / 2;
2959c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                            top  = 0;
2969c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                            right = left + newWidth;
2979c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                            bottom = mOverlayBitmap.getHeight();
2989c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                        }
2999c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi
3009c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                        srcRect = new Rect(left, top, right, bottom);
3019c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                        destRect = new Rect(0, 0, overlayCanvas.getWidth(), overlayCanvas.getHeight());
3029c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                        break;
3039c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                    }
3049c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi
3059c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                    default: {
3069c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                        throw new IllegalStateException("Rendering mode: " + mRenderingMode);
3079c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                    }
3089c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                }
3099c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi
3109c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                destBitmap.eraseColor(Color.TRANSPARENT);
311a573b563b3c6a3edc60393543dc9adb7ade4f188Dharmaray Kundargi                overlayCanvas.drawBitmap(mOverlayBitmap, srcRect, destRect, sResizePaint);
3129c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi
3139c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi                mOverlayBitmap.recycle();
3149c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi            }
3159c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi        }
3169c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi    }
3179c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi
3189c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi    /**
3199bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @return The path where the VideoEditor stores all files related to the
3209bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *         project
3219bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
3229bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public String getPath();
3239bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
3249bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
3259bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * This method releases all in-memory resources used by the VideoEditor
3269bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * instance. All pending operations such as preview, export and extract
3279bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * audio waveform must be canceled.
3289bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
3299bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public void release();
3309bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
3319bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
3329bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Persist the current internal state of VideoEditor to the project path.
3339bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * The VideoEditor state may be restored by invoking the
3349bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * {@link VideoEditorFactory#load(String)} method. This method does not
3359bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * release the internal in-memory state of the VideoEditor. To release
3369bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * the in-memory state of the VideoEditor the {@link #release()} method
3379bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * must be invoked.
3389bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
3399bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Pending transition generations must be allowed to complete before the
3409bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * state is saved.
3419bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Pending audio waveform generations must be allowed to complete.
3429bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Pending export operations must be allowed to continue.
3439bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
3449bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IOException if the internal state cannot be saved to project file
3459bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
3469bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public void save() throws IOException;
3479bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
3489bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
3499bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Create the output movie based on all media items added and the applied
3509bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * storyboard items. This method can take a long time to execute and is
3519bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * blocking. The application will receive progress notifications via the
3529bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * ExportProgressListener. Specific implementations may not support multiple
3539bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * simultaneous export operations. Note that invoking methods which would
3549bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * change the contents of the output movie throw an IllegalStateException
3559bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * while an export operation is pending.
3569bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
3579bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * The audio and video codecs are automatically selected by the underlying
3589bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * implementation.
3599bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
3609bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param filename The output file name (including the full path)
3619bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param height The height of the output video file. The supported values
3629bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        for height are described in the MediaProperties class, for
3639bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        example: HEIGHT_480. The width will be automatically computed
3649bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        according to the aspect ratio provided by
3659bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        {@link #setAspectRatio(int)}
3669bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param bitrate The bitrate of the output video file. This is approximate
3679bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        value for the output movie. Supported bitrate values are
3689bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        described in the MediaProperties class for example: BITRATE_384K
3699bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param listener The listener for progress notifications. Use null if
3709bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        export progress notifications are not needed.
3719bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
3729bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalArgumentException if height or bitrate are not supported
3739bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        or if the audio or video codecs are not supported
3749bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IOException if output file cannot be created
3759bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalStateException if a preview or an export is in progress or
3769bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        if no MediaItem has been added
3779bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws CancellationException if export is canceled by calling
3789bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        {@link #cancelExport()}
3799bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws UnsupportOperationException if multiple simultaneous export() are
3809bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        not allowed
3819bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
3829bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public void export(String filename, int height, int bitrate,
3839bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava                       ExportProgressListener listener)
384600acf14ff12eaf139f0ac644fb7e17849af65faHong Teng                       throws IOException;
3859bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
3869bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
3879bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Create the output movie based on all media items added and the applied
3889bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * storyboard items. This method can take a long time to execute and is
3899bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * blocking. The application will receive progress notifications via the
3909bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * ExportProgressListener. Specific implementations may not support multiple
3919bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * simultaneous export operations. Note that invoking methods which would
3929bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * change the contents of the output movie throw an IllegalStateException
3939bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * while an export operation is pending.
3949bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
3959bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param filename The output file name (including the full path)
3969bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param height The height of the output video file. The supported values
3979bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        for height are described in the MediaProperties class, for
3989bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        example: HEIGHT_480. The width will be automatically computed
3999bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        according to the aspect ratio provided by
4009bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        {@link #setAspectRatio(int)}
4019bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param bitrate The bitrate of the output video file. This is approximate
4029bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        value for the output movie. Supported bitrate values are
4039bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        described in the MediaProperties class for example: BITRATE_384K
4049bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param audioCodec The audio codec to be used for the export. The audio
4059bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        codec values are defined in the MediaProperties class (e.g.
4069bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        ACODEC_AAC_LC). Note that not all audio codec types are
4079bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        supported for export purposes.
4089bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param videoCodec The video codec to be used for the export. The video
4099bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        codec values are defined in the MediaProperties class (e.g.
4103ced044154945f9d60983032278e00fe28f4ab1bRajneesh Chowdury     *        VCODEC_H264). Note that not all video codec types are
4119bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        supported for export purposes.
4129bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param listener The listener for progress notifications. Use null if
4139bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        export progress notifications are not needed.
4149bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
4159bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalArgumentException if height or bitrate are not supported
4169bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        or if the audio or video codecs are not supported
4179bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IOException if output file cannot be created
4189bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalStateException if a preview or an export is in progress or
4199bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        if no MediaItem has been added
4209bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws CancellationException if export is cancelled by calling
4219bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        {@link #cancelExport()}
4229bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws UnsupportOperationException if multiple simultaneous export() are
4239bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        not allowed
4249bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
4259bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public void export(String filename, int height, int bitrate, int audioCodec,
4269bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava                       int videoCodec, ExportProgressListener listener)
427600acf14ff12eaf139f0ac644fb7e17849af65faHong Teng                       throws IOException;
4289bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
4299bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
4309bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Cancel the running export operation. This method blocks until the export
4319bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * is cancelled and the exported file (if any) is deleted. If the export
4329bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * completed by the time this method is invoked, the export file will be
4339bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * deleted.
4349bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
4359bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param filename The filename which identifies the export operation to be
4369bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *            canceled.
4379bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     **/
4389bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public void cancelExport(String filename);
4399bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
4409bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
4419bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Add a media item at the end of the storyboard.
4429bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
4439bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param mediaItem The media item object to add
4449bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
4459bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalStateException if a preview or an export is in progress or
4469bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        if the media item id is not unique across all the media items
4479bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        added.
4489bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
4499bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public void addMediaItem(MediaItem mediaItem);
4509bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
4519bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
4529bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Insert a media item after the media item with the specified id.
4539bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
4549bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param mediaItem The media item object to insert
4559bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param afterMediaItemId Insert the mediaItem after the media item
4569bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        identified by this id. If this parameter is null, the media
4579bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        item is inserted at the beginning of the timeline.
4589bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
4599bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalStateException if a preview or an export is in progress
4609bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalArgumentException if media item with the specified id does
4619bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        not exist (null is a valid value) or if the media item id is
4629bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        not unique across all the media items added.
4639bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
4649bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public void insertMediaItem(MediaItem mediaItem, String afterMediaItemId);
4659bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
4669bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
4679bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Move a media item after the media item with the specified id.
4689bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
4699bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Note: The project thumbnail is regenerated if the media item is or
4709bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * becomes the first media item in the storyboard timeline.
4719bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
4729bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param mediaItemId The id of the media item to move
4739bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param afterMediaItemId Move the media item identified by mediaItemId
4749bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        after the media item identified by this parameter. If this
4759bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        parameter is null, the media item is moved at the beginning of
4769bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        the timeline.
4779bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
4789bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalStateException if a preview or an export is in progress
4799bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalArgumentException if one of media item ids is invalid
4809bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        (null is a valid value)
4819bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
4829bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public void moveMediaItem(String mediaItemId, String afterMediaItemId);
4839bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
4849bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
4859bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Remove the media item with the specified id. If there are transitions
4869bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * before or after this media item, then this/these transition(s) are
4879bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * removed from the storyboard. If the extraction of the audio waveform is
4889bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * in progress, the extraction is canceled and the file is deleted.
4899bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
4909bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Effects and overlays associated with the media item will also be removed.
4919bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
4929bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Note: The project thumbnail is regenerated if the media item which is
4939bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * removed is the first media item in the storyboard or if the media item is
4949bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * the only one in the storyboard. If the media item is the only one in the
4959bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * storyboard, the project thumbnail will be set to a black frame and the
4969bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * aspect ratio will revert to the default aspect ratio and this method is
4979bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * equivalent to removeAllMediaItems() in this case.
4989bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
4999bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param mediaItemId The unique id of the media item to be removed
5009bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
5019bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @return The media item that was removed
5029bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
5039bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalStateException if a preview or an export is in progress
5049bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalArgumentException if media item with the specified id does
5059bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        not exist
5069bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
5079bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public MediaItem removeMediaItem(String mediaItemId);
5089bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
5099bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
5109bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Remove all media items in the storyboard. All effects, overlays and all
5119bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * transitions are also removed.
5129bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
5139bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Note: The project thumbnail will be set to a black frame and the aspect
5149bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * ratio will revert to the default aspect ratio.
5159bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
5169bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalStateException if a preview or an export is in progress
5179bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
5189bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public void removeAllMediaItems();
5199bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
5209bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
5219bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Get the list of media items in the order in which it they appear in the
5229bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * storyboard timeline.
5239bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
5249bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Note that if any media item source files are no longer
5259bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * accessible, this method will still provide the full list of media items.
5269bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
5279bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @return The list of media items. If no media item exist an empty list
5289bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        will be returned.
5299bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
5309bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public List<MediaItem> getAllMediaItems();
5319bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
5329bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
5339bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Find the media item with the specified id
5349bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
5359bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param mediaItemId The media item id
5369bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
5379bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @return The media item with the specified id (null if it does not exist)
5389bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
5399bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public MediaItem getMediaItem(String mediaItemId);
5409bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
5419bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
5429bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Add a transition between the media items specified by the transition.
5439bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * If a transition existed at the same position it is invalidated and then
5449bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * the transition is replaced. Note that the new transition video clip is
5459bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * not automatically generated by this method. The
5469bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * {@link Transition#generate()} method must be invoked to generate
5479bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * the transition video clip.
5489bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
5499bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Note that the TransitionAtEnd and TransitionAtStart are special kinds
5509bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * that can not be applied between two media items.
5519bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
5529bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * A crossfade audio transition will be automatically applied regardless of
5539bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * the video transition.
5549bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
5559bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param transition The transition to apply
5569bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
5579bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalStateException if a preview or an export is in progress
5589bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalArgumentException if the transition duration is larger
5599bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        than the smallest duration of the two media item files or if
5609bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        the two media items specified in the transition are not
5619bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        adjacent
5629bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
5639bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public void addTransition(Transition transition);
5649bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
5659bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
5669bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Remove the transition with the specified id.
5679bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
5689bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param transitionId The id of the transition to be removed
5699bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
5709bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @return The transition that was removed
5719bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
5729bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalStateException if a preview or an export is in progress
5739bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalArgumentException if transition with the specified id does
5749bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        not exist
5759bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
5769bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public Transition removeTransition(String transitionId);
5779bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
5789bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
5799bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Get the list of transitions
5809bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
5819bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @return The list of transitions. If no transitions exist an empty list
5829bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        will be returned.
5839bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
5849bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public List<Transition> getAllTransitions();
5859bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
5869bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
5879bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Find the transition with the specified transition id.
5889bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
5899bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param transitionId The transition id
5909bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
5919bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @return The transition
5929bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
5939bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public Transition getTransition(String transitionId);
5949bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
5959bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
5969bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Add the specified AudioTrack to the storyboard. Note: Specific
5979bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * implementations may support a limited number of audio tracks (e.g. only
5989bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * one audio track)
5999bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
6009bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param audioTrack The AudioTrack to add
6019bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
6029bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws UnsupportedOperationException if the implementation supports a
6039bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        limited number of audio tracks.
6049bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalArgumentException if media item is not unique across all
6059bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        the audio tracks already added.
6069bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
6079bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public void addAudioTrack(AudioTrack audioTrack);
6089bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
6099bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
6109bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Insert an audio track after the audio track with the specified id. Use
6119bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * addAudioTrack to add an audio track at the end of the storyboard
6129bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * timeline.
6139bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
6149bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param audioTrack The audio track object to insert
6159bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param afterAudioTrackId Insert the audio track after the audio track
6169bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        identified by this parameter. If this parameter is null the
6179bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        audio track is added at the beginning of the timeline.
6189bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
6199bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalStateException if a preview or an export is in progress
6209bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalArgumentException if media item with the specified id does
6219bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        not exist (null is a valid value). if media item is not unique
6229bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        across all the audio tracks already added.
6239bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws UnsupportedOperationException if the implementation supports a
6249bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        limited number of audio tracks
6259bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
6269bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public void insertAudioTrack(AudioTrack audioTrack, String afterAudioTrackId);
6279bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
6289bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
6299bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Move an AudioTrack after the AudioTrack with the specified id.
6309bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
6319bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param audioTrackId The id of the AudioTrack to move
6329bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param afterAudioTrackId Move the AudioTrack identified by audioTrackId
6339bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        after the AudioTrack identified by this parameter. If this
6349bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        parameter is null the audio track is added at the beginning of
6359bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        the timeline.
6369bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
6379bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalStateException if a preview or an export is in progress
6389bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalArgumentException if one of media item ids is invalid
6399bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        (null is a valid value)
6409bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
6419bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public void moveAudioTrack(String audioTrackId, String afterAudioTrackId);
6429bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
6439bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
6449bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Remove the audio track with the specified id. If the extraction of the
6459bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * audio waveform is in progress, the extraction is canceled and the file is
6469bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * deleted.
6479bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
6489bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param audioTrackId The id of the audio track to be removed
6499bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
6509bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @return The audio track that was removed
6519bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalStateException if a preview or an export is in progress
6529bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
6539bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public AudioTrack removeAudioTrack(String audioTrackId);
6549bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
6559bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
6569bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Get the list of AudioTracks in order in which they appear in the
6579bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * storyboard.
6589bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
6599bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Note that if any AudioTrack source files are not accessible anymore,
6609bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * this method will still provide the full list of audio tracks.
6619bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
6629bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @return The list of AudioTracks. If no audio tracks exist an empty list
6639bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        will be returned.
6649bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
6659bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public List<AudioTrack> getAllAudioTracks();
6669bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
6679bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
6689bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Find the AudioTrack with the specified id
6699bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
6709bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param audioTrackId The AudioTrack id
6719bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
6729bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @return The AudioTrack with the specified id (null if it does not exist)
6739bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
6749bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public AudioTrack getAudioTrack(String audioTrackId);
6759bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
6769bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
6779bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Set the aspect ratio used in the preview and the export movie.
6789bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
6799bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * The default aspect ratio is ASPECTRATIO_16_9 (16:9).
6809bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
6819bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param aspectRatio to apply. If aspectRatio is the same as the current
6829bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        aspect ratio, then this function just returns. The supported
6839bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        aspect ratio are defined in the MediaProperties class for
6849bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        example: ASPECTRATIO_16_9
6859bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
6869bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalStateException if a preview or an export is in progress
6879bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalArgumentException if aspect ratio is not supported
6889bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
6899bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public void setAspectRatio(int aspectRatio);
6909bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
6919bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
6929bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Get current aspect ratio.
6939bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
6949bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @return The aspect ratio as described in MediaProperties
6959bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
6969bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public int getAspectRatio();
6979bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
6989bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
6999bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Get the preview (and output movie) duration.
7009bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
7019bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @return The duration of the preview (and output movie)
7029bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
7039bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public long getDuration();
7049bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
7059bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
7069bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Render a frame according to the preview aspect ratio and activating all
7079bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * storyboard items relative to the specified time.
7089bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
7099bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param surfaceHolder SurfaceHolder used by the application
7109bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param timeMs time corresponding to the frame to display
7119c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi     * @param overlayData The overlay data
7129bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
7139bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @return The accurate time stamp of the frame that is rendered.
7149bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
7159bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalStateException if a preview or an export is already in
7169bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        progress
7179bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalArgumentException if time is negative or beyond the
7189bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        preview duration
7199bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
7209c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi    public long renderPreviewFrame(SurfaceHolder surfaceHolder, long timeMs,
7219c077e44c05f6829dd12067947a387c132dc6eaaDharmaray Kundargi            OverlayData overlayData);
7229bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
7239bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
7249bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * This method must be called after any changes made to the storyboard
7259bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * and before startPreview is called. Note that this method may block for an
7269bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * extensive period of time.
7279bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
7289bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public void generatePreview(MediaProcessingProgressListener listener);
7299bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
7309bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
7319bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Start the preview of all the storyboard items applied on all MediaItems
7329bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * This method does not block (does not wait for the preview to complete).
7339bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * The PreviewProgressListener allows to track the progress at the time
7349bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * interval determined by the callbackAfterFrameCount parameter. The
7359bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * SurfaceHolder has to be created and ready for use before calling this
7369bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * method. The method is a no-op if there are no MediaItems in the
7379bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * storyboard.
7389bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
7399bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param surfaceHolder SurfaceHolder where the preview is rendered.
7409bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param fromMs The time (relative to the timeline) at which the preview
7419bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        will start
7429bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param toMs The time (relative to the timeline) at which the preview will
7439bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        stop. Use -1 to play to the end of the timeline
7449bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param loop true if the preview should be looped once it reaches the end
7459bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param callbackAfterFrameCount The listener interface should be invoked
7469bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        after the number of frames specified by this parameter.
7479bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @param listener The listener which will be notified of the preview
7489bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        progress
7499bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
7509bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalArgumentException if fromMs is beyond the preview duration
7519bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @throws IllegalStateException if a preview or an export is already in
7529bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        progress
7539bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
7549bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public void startPreview(SurfaceHolder surfaceHolder, long fromMs, long toMs,
7559bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava                             boolean loop,int callbackAfterFrameCount,
7569bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava                             PreviewProgressListener listener);
7579bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava
7589bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    /**
7599bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * Stop the current preview. This method blocks until ongoing preview is
7609bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * stopped. Ignored if there is no preview running.
7619bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *
7629bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     * @return The accurate current time when stop is effective expressed in
7639bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     *        milliseconds
7649bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava     */
7659bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava    public long stopPreview();
76605d9f81bd638a749669192b50e680b166529d5f3Dheeraj Sharma
76705d9f81bd638a749669192b50e680b166529d5f3Dheeraj Sharma    /**
76805d9f81bd638a749669192b50e680b166529d5f3Dheeraj Sharma     * Clears the preview surface
76905d9f81bd638a749669192b50e680b166529d5f3Dheeraj Sharma     *
77005d9f81bd638a749669192b50e680b166529d5f3Dheeraj Sharma     * @param surfaceHolder SurfaceHolder where the preview is rendered
77105d9f81bd638a749669192b50e680b166529d5f3Dheeraj Sharma     * and needs to be cleared.
77205d9f81bd638a749669192b50e680b166529d5f3Dheeraj Sharma     */
77305d9f81bd638a749669192b50e680b166529d5f3Dheeraj Sharma    public void clearSurface(SurfaceHolder surfaceHolder);
7749bcedf7cf3e9c981837f2d8ec98cd118efad3f01Santosh Madhava}
775