OSDN Git Service

Fix issue 3408285. Fix issue in Thread safe in Java.
authorDharmaray Kundargi <dharmaray@google.com>
Tue, 1 Feb 2011 01:54:55 +0000 (17:54 -0800)
committerDharmaray Kundargi <dharmaray@google.com>
Tue, 1 Feb 2011 01:54:55 +0000 (17:54 -0800)
Change-Id: Ifddcecfc2d7b1bd3e8a91c4850c169e1fb7c65ae

media/java/android/media/videoeditor/AudioTrack.java
media/java/android/media/videoeditor/Effect.java
media/java/android/media/videoeditor/EffectKenBurns.java
media/java/android/media/videoeditor/MediaItem.java
media/java/android/media/videoeditor/VideoEditor.java
media/java/android/media/videoeditor/VideoEditorImpl.java

index eeace13..b2f547b 100755 (executable)
@@ -402,11 +402,11 @@ public class AudioTrack {
      */
     public void enableLoop() {
         if (!mLoop) {
-            mLoop = true;
             /**
              *  Force update of preview settings
              */
             mMANativeHelper.setGeneratePreview(true);
+            mLoop = true;
         }
     }
 
index c6b0839..2f7ae03 100755 (executable)
@@ -102,6 +102,8 @@ public abstract class Effect {
             throw new IllegalArgumentException("Duration is too large");
         }
 
+        getMediaItem().getNativeContext().setGeneratePreview(true);
+
         final long oldDurationMs = mDurationMs;
         mDurationMs = durationMs;
 
@@ -156,6 +158,7 @@ public abstract class Effect {
             throw new IllegalArgumentException("Invalid start time or duration");
         }
 
+        getMediaItem().getNativeContext().setGeneratePreview(true);
         final long oldStartTimeMs = mStartTimeMs;
         final long oldDurationMs = mDurationMs;
 
index 66c9e86..9ef458b 100755 (executable)
@@ -57,21 +57,6 @@ public class EffectKenBurns extends Effect {
         mEndRect = endRect;
     }
 
-    /**
-     * Set the start rectangle.
-     *
-     * @param startRect The start rectangle
-     *
-     * @throws IllegalArgumentException if start rectangle is incorrectly set.
-     */
-    public void setStartRect(Rect startRect) {
-        if ( (startRect.left == 0) && (startRect.right == 0)
-            && (startRect.bottom == 0) && (startRect.top == 0) ) {
-            throw new IllegalArgumentException("Invalid Rectangle");
-        }
-
-        mStartRect = startRect;
-    }
 
     /**
      * Get the start rectangle.
@@ -82,21 +67,6 @@ public class EffectKenBurns extends Effect {
         return mStartRect;
     }
 
-    /**
-     * Set the end rectangle.
-     *
-     * @param endRect The end rectangle
-     *
-     * @throws IllegalArgumentException if end rectangle is incorrectly set.
-     */
-    public void setEndRect(Rect endRect) {
-        if ( (endRect.left == 0) && (endRect.right == 0)
-           && (endRect.bottom == 0) && (endRect.top == 0) ) {
-            throw new IllegalArgumentException("Invalid Rectangle");
-        }
-
-        mEndRect = endRect;
-    }
 
     /**
      * Get the end rectangle.
index d3ab051..e3ef599 100755 (executable)
@@ -295,6 +295,8 @@ public abstract class MediaItem {
             "Effect start time + effect duration > media clip duration");
         }
 
+        mMANativeHelper.setGeneratePreview(true);
+
         mEffects.add(effect);
 
         invalidateTransitions(effect.getStartTime(), effect.getDuration());
@@ -302,7 +304,6 @@ public abstract class MediaItem {
         if (effect instanceof EffectKenBurns) {
             mRegenerateClip = true;
         }
-        mMANativeHelper.setGeneratePreview(true);
     }
 
     /**
@@ -424,8 +425,6 @@ public abstract class MediaItem {
                 throw new IllegalArgumentException("Overlay bitmap not specified");
             }
 
-            ((OverlayFrame)overlay).save(mProjectPath);
-
             final int scaledWidth, scaledHeight;
             if (this instanceof MediaVideoItem) {
                 scaledWidth = getWidth();
@@ -443,13 +442,16 @@ public abstract class MediaItem {
                 throw new IllegalArgumentException(
                 "Bitmap dimensions must match media item dimensions");
             }
+
+            mMANativeHelper.setGeneratePreview(true);
+            ((OverlayFrame)overlay).save(mProjectPath);
+
+            mOverlays.add(overlay);
+            invalidateTransitions(overlay.getStartTime(), overlay.getDuration());
+
         } else {
             throw new IllegalArgumentException("Overlay not supported");
         }
-
-        mOverlays.add(overlay);
-        invalidateTransitions(overlay.getStartTime(), overlay.getDuration());
-        mMANativeHelper.setGeneratePreview(true);
     }
 
     /**
index 9006613..122dc8d 100755 (executable)
@@ -23,6 +23,7 @@ import java.util.concurrent.CancellationException;
 import android.graphics.Bitmap;
 import android.graphics.Color;
 import android.graphics.Canvas;
+import android.graphics.Paint;
 import android.graphics.Rect;
 import android.view.SurfaceHolder;
 
@@ -153,6 +154,7 @@ public interface VideoEditor {
         private Bitmap mOverlayBitmap;
         private int mRenderingMode;
         private boolean mClear;
+        private static final Paint sResizePaint = new Paint(Paint.FILTER_BITMAP_FLAG);
 
         /**
          * Default constructor
@@ -290,7 +292,7 @@ public interface VideoEditor {
                 }
 
                 destBitmap.eraseColor(Color.TRANSPARENT);
-                overlayCanvas.drawBitmap(mOverlayBitmap, srcRect, destRect, null);
+                overlayCanvas.drawBitmap(mOverlayBitmap, srcRect, destRect, sResizePaint);
 
                 mOverlayBitmap.recycle();
             }
index cc847ef..25b25ee 100755 (executable)
@@ -167,6 +167,8 @@ public class VideoEditorImpl implements VideoEditor {
             throw new IllegalArgumentException("No more tracks can be added");
         }
 
+        mMANativeHelper.setGeneratePreview(true);
+
         /*
          * Add the audio track to AudioTrack list
          */
@@ -185,7 +187,6 @@ public class VideoEditorImpl implements VideoEditor {
             mMANativeHelper.setAudioflag(false);
         }
 
-        mMANativeHelper.setGeneratePreview(true);
     }
 
     /*
@@ -205,6 +206,8 @@ public class VideoEditorImpl implements VideoEditor {
             throw new IllegalArgumentException("Media item already exists: " + mediaItem.getId());
         }
 
+        mMANativeHelper.setGeneratePreview(true);
+
         /*
          *  Invalidate the end transition if necessary
          */
@@ -219,7 +222,7 @@ public class VideoEditorImpl implements VideoEditor {
         mMediaItems.add(mediaItem);
 
         computeTimelineDuration();
-        mMANativeHelper.setGeneratePreview(true);
+
         /*
          *  Generate project thumbnail only from first media Item on storyboard
          */
@@ -258,7 +261,9 @@ public class VideoEditorImpl implements VideoEditor {
             if (afterMediaItemIndex != (beforeMediaItemIndex - 1) ) {
                 throw new IllegalArgumentException("MediaItems are not in sequence");
             }
-         }
+        }
+
+        mMANativeHelper.setGeneratePreview(true);
 
         mTransitions.add(transition);
         /*
@@ -289,7 +294,6 @@ public class VideoEditorImpl implements VideoEditor {
         }
 
         computeTimelineDuration();
-        mMANativeHelper.setGeneratePreview(true);
     }
 
     /*
@@ -542,15 +546,15 @@ public class VideoEditorImpl implements VideoEditor {
         }
 
         if (afterAudioTrackId == null) {
-            mAudioTracks.add(0, audioTrack);
             mMANativeHelper.setGeneratePreview(true);
+            mAudioTracks.add(0, audioTrack);
         } else {
             final int audioTrackCount = mAudioTracks.size();
             for (int i = 0; i < audioTrackCount; i++) {
                 AudioTrack at = mAudioTracks.get(i);
                 if (at.getId().equals(afterAudioTrackId)) {
-                    mAudioTracks.add(i + 1, audioTrack);
                     mMANativeHelper.setGeneratePreview(true);
+                    mAudioTracks.add(i + 1, audioTrack);
                     return;
                 }
             }
@@ -568,6 +572,7 @@ public class VideoEditorImpl implements VideoEditor {
         }
 
         if (afterMediaItemId == null) {
+            mMANativeHelper.setGeneratePreview(true);
             if (mMediaItems.size() > 0) {
                 /**
                  *  Invalidate the transition at the beginning of the timeline
@@ -578,12 +583,12 @@ public class VideoEditorImpl implements VideoEditor {
             mMediaItems.add(0, mediaItem);
             computeTimelineDuration();
             generateProjectThumbnail();
-            mMANativeHelper.setGeneratePreview(true);
         } else {
             final int mediaItemCount = mMediaItems.size();
             for (int i = 0; i < mediaItemCount; i++) {
                 final MediaItem mi = mMediaItems.get(i);
                 if (mi.getId().equals(afterMediaItemId)) {
+                    mMANativeHelper.setGeneratePreview(true);
                     /**
                      *  Invalidate the transition at this position
                      */
@@ -593,7 +598,6 @@ public class VideoEditorImpl implements VideoEditor {
                      */
                     mMediaItems.add(i + 1, mediaItem);
                     computeTimelineDuration();
-                    mMANativeHelper.setGeneratePreview(true);
                     return;
                 }
             }
@@ -620,6 +624,8 @@ public class VideoEditorImpl implements VideoEditor {
 
         if (afterMediaItemId == null) {
             if (mMediaItems.size() > 0) {
+                mMANativeHelper.setGeneratePreview(true);
+
                 /**
                  *  Invalidate adjacent transitions at the insertion point
                  */
@@ -630,7 +636,6 @@ public class VideoEditorImpl implements VideoEditor {
                  */
                 mMediaItems.add(0, moveMediaItem);
                 computeTimelineDuration();
-                mMANativeHelper.setGeneratePreview(true);
 
                 generateProjectThumbnail();
             } else {
@@ -641,6 +646,7 @@ public class VideoEditorImpl implements VideoEditor {
             for (int i = 0; i < mediaItemCount; i++) {
                 final MediaItem mi = mMediaItems.get(i);
                 if (mi.getId().equals(afterMediaItemId)) {
+                    mMANativeHelper.setGeneratePreview(true);
                     /**
                      *  Invalidate adjacent transitions at the insertion point
                      */
@@ -650,7 +656,6 @@ public class VideoEditorImpl implements VideoEditor {
                      */
                     mMediaItems.add(i + 1, moveMediaItem);
                     computeTimelineDuration();
-                    mMANativeHelper.setGeneratePreview(true);
                     return;
                 }
             }
@@ -703,11 +708,11 @@ public class VideoEditorImpl implements VideoEditor {
     public synchronized AudioTrack removeAudioTrack(String audioTrackId) {
         final AudioTrack audioTrack = getAudioTrack(audioTrackId);
         if (audioTrack != null) {
+            mMANativeHelper.setGeneratePreview(true);
             mAudioTracks.remove(audioTrack);
             audioTrack.invalidate();
             mMANativeHelper.invalidatePcmFile();
             mMANativeHelper.setAudioflag(true);
-            mMANativeHelper.setGeneratePreview(true);
         } else {
             throw new IllegalArgumentException(" No more audio tracks");
         }
@@ -840,7 +845,6 @@ public class VideoEditorImpl implements VideoEditor {
         } else if (timeMs > mDurationMs) {
             throw new IllegalArgumentException("requested time more than duration");
         }
-
         long result = 0;
 
         boolean semAcquireDone = false;
@@ -862,7 +866,7 @@ public class VideoEditorImpl implements VideoEditor {
                 mMANativeHelper.unlock();
             }
         }
-
+Log.i("VE_IMPL","renderPreviewFrame <--");
         return result;
     }
 
@@ -1617,8 +1621,8 @@ public class VideoEditorImpl implements VideoEditor {
         while (it.hasNext()) {
             Transition t = it.next();
             if (t.getBeforeMediaItem() == mediaItem) {
-                it.remove();
                 mMANativeHelper.setGeneratePreview(true);
+                it.remove();
                 t.invalidate();
                 mediaItem.setBeginTransition(null);
                 if (index > 0) {
@@ -1640,8 +1644,8 @@ public class VideoEditorImpl implements VideoEditor {
         while (it.hasNext()) {
             Transition t = it.next();
             if (t.getAfterMediaItem() == mediaItem) {
-                it.remove();
                 mMANativeHelper.setGeneratePreview(true);
+                it.remove();
                 t.invalidate();
                 mediaItem.setEndTransition(null);
                 /**