diff options
author | Gil Dobjanschi <virgild@google.com> | 2010-09-28 11:21:57 -0700 |
---|---|---|
committer | Gil Dobjanschi <virgild@google.com> | 2010-09-28 17:54:09 -0700 |
commit | 5665fd6ac2b2d3a00b3addf1ae897426896935d6 (patch) | |
tree | cf9dba6399d0bcdbf2e3ee7d4ea2c45eb86f8322 /media/java/android | |
parent | 40f45eeeb4914511c0d4d749d1f4c768e82b79a3 (diff) | |
download | frameworks_base-5665fd6ac2b2d3a00b3addf1ae897426896935d6.zip frameworks_base-5665fd6ac2b2d3a00b3addf1ae897426896935d6.tar.gz frameworks_base-5665fd6ac2b2d3a00b3addf1ae897426896935d6.tar.bz2 |
Save overlays to XML
Change-Id: I549c40b55a85022136dbd4899cc0d2d4da6e33de
Diffstat (limited to 'media/java/android')
4 files changed, 143 insertions, 9 deletions
diff --git a/media/java/android/media/videoeditor/Effect.java b/media/java/android/media/videoeditor/Effect.java index 635727a..038bfc2 100755 --- a/media/java/android/media/videoeditor/Effect.java +++ b/media/java/android/media/videoeditor/Effect.java @@ -57,6 +57,10 @@ public abstract class Effect { throw new IllegalArgumentException("Media item cannot be null");
}
+ if (startTimeMs + durationMs > mediaItem.getTimelineDuration()) {
+ throw new IllegalArgumentException("Invalid start time and duration");
+ }
+
mMediaItem = mediaItem;
mUniqueId = effectId;
mStartTimeMs = startTimeMs;
diff --git a/media/java/android/media/videoeditor/Overlay.java b/media/java/android/media/videoeditor/Overlay.java index 8e20651..d9e7f85 100755 --- a/media/java/android/media/videoeditor/Overlay.java +++ b/media/java/android/media/videoeditor/Overlay.java @@ -16,6 +16,9 @@ package android.media.videoeditor;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* This is the super class for all Overlay classes.
@@ -26,6 +29,8 @@ public abstract class Overlay { private final String mUniqueId;
// The overlay owner
private final MediaItem mMediaItem;
+ // user attributes
+ private final Map<String, String> mUserAttributes;
protected long mStartTimeMs;
protected long mDurationMs;
@@ -36,10 +41,7 @@ public abstract class Overlay { */
@SuppressWarnings("unused")
private Overlay() {
- mUniqueId = null;
- mMediaItem = null;
- mStartTimeMs = 0;
- mDurationMs = 0;
+ this(null, null, 0, 0);
}
/**
@@ -58,10 +60,15 @@ public abstract class Overlay { throw new IllegalArgumentException("Media item cannot be null");
}
+ if (startTimeMs + durationMs > mediaItem.getTimelineDuration()) {
+ throw new IllegalArgumentException("Invalid start time and duration");
+ }
+
mMediaItem = mediaItem;
mUniqueId = overlayId;
mStartTimeMs = startTimeMs;
mDurationMs = durationMs;
+ mUserAttributes = new HashMap<String, String>();
}
/**
@@ -125,6 +132,23 @@ public abstract class Overlay { return mMediaItem;
}
+ /**
+ * Set a user attribute
+ *
+ * @param name The attribute name
+ * @param value The attribute value
+ */
+ public void setUserAttribute(String name, String value) {
+ mUserAttributes.put(name, value);
+ }
+
+ /**
+ * @return The user attributes
+ */
+ public Map<String, String> getUserAttributes() {
+ return mUserAttributes;
+ }
+
/*
* {@inheritDoc}
*/
diff --git a/media/java/android/media/videoeditor/OverlayFrame.java b/media/java/android/media/videoeditor/OverlayFrame.java index 91deee4..c7dfc39 100755 --- a/media/java/android/media/videoeditor/OverlayFrame.java +++ b/media/java/android/media/videoeditor/OverlayFrame.java @@ -32,7 +32,7 @@ import android.graphics.Bitmap.CompressFormat; */
public class OverlayFrame extends Overlay {
// Instance variables
- private final Bitmap mBitmap;
+ private Bitmap mBitmap;
private String mFilename;
/**
@@ -93,6 +93,22 @@ public class OverlayFrame extends Overlay { }
/**
+ * @param bitmap The overlay bitmap
+ */
+ public void setBitmap(Bitmap bitmap) {
+ mBitmap = bitmap;
+ if (mFilename != null) {
+ // Delete the file
+ new File(mFilename).delete();
+ // Invalidate the filename
+ mFilename = null;
+ }
+
+ // Invalidate the transitions if necessary
+ getMediaItem().invalidateTransitions(this);
+ }
+
+ /**
* Get the file name of this overlay
*/
String getFilename() {
diff --git a/media/java/android/media/videoeditor/VideoEditorTestImpl.java b/media/java/android/media/videoeditor/VideoEditorTestImpl.java index 0861992..5df4ea5 100644 --- a/media/java/android/media/videoeditor/VideoEditorTestImpl.java +++ b/media/java/android/media/videoeditor/VideoEditorTestImpl.java @@ -25,6 +25,7 @@ import java.io.StringWriter; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Map; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -50,6 +51,10 @@ public class VideoEditorTestImpl implements VideoEditor { private static final String TAG_MEDIA_ITEM = "media_item"; private static final String TAG_TRANSITIONS = "transitions"; private static final String TAG_TRANSITION = "transition"; + private static final String TAG_OVERLAYS = "overlays"; + private static final String TAG_OVERLAY = "overlay"; + private static final String TAG_OVERLAY_USER_ATTRIBUTES = "overlay_user_attributes"; + private static final String ATTR_ID = "id"; private static final String ATTR_FILENAME = "filename"; private static final String ATTR_AUDIO_WAVEFORM_FILENAME = "wavefoem"; @@ -572,6 +577,40 @@ public class VideoEditorTestImpl implements VideoEditor { Long.toString(mediaItem.getTimelineDuration())); } + final List<Overlay> overlays = mediaItem.getAllOverlays(); + if (overlays.size() > 0) { + serializer.startTag("", TAG_OVERLAYS); + for (Overlay overlay : overlays) { + serializer.startTag("", TAG_OVERLAY); + serializer.attribute("", ATTR_ID, overlay.getId()); + serializer.attribute("", ATTR_TYPE, overlay.getClass().getSimpleName()); + serializer.attribute("", ATTR_BEGIN_TIME, + Long.toString(overlay.getStartTime())); + serializer.attribute("", ATTR_DURATION, Long.toString(overlay.getDuration())); + if (overlay instanceof OverlayFrame) { + final OverlayFrame overlayFrame = (OverlayFrame)overlay; + overlayFrame.save(this); + if (overlayFrame.getFilename() != null) { + serializer.attribute("", ATTR_FILENAME, overlayFrame.getFilename()); + } + } + + // Save the user attributes + serializer.startTag("", TAG_OVERLAY_USER_ATTRIBUTES); + final Map<String, String> userAttributes = overlay.getUserAttributes(); + for (String name : userAttributes.keySet()) { + final String value = userAttributes.get(name); + if (value != null) { + serializer.attribute("", name, value); + } + } + serializer.endTag("", TAG_OVERLAY_USER_ATTRIBUTES); + + serializer.endTag("", TAG_OVERLAY); + } + serializer.endTag("", TAG_OVERLAYS); + } + serializer.endTag("", TAG_MEDIA_ITEM); } serializer.endTag("", TAG_MEDIA_ITEMS); @@ -629,21 +668,22 @@ public class VideoEditorTestImpl implements VideoEditor { parser.setInput(new FileInputStream(file), "UTF-8"); int eventType = parser.getEventType(); String name; + MediaItem currentMediaItem = null; + Overlay currentOverlay = null; while (eventType != XmlPullParser.END_DOCUMENT) { switch (eventType) { case XmlPullParser.START_TAG: { name = parser.getName(); - if (name.equals(TAG_PROJECT)) { + if (TAG_PROJECT.equals(name)) { mAspectRatio = Integer.parseInt(parser.getAttributeValue("", ATTR_ASPECT_RATIO)); - } else if (name.equals(TAG_MEDIA_ITEM)) { + } else if (TAG_MEDIA_ITEM.equals(name)) { final String mediaItemId = parser.getAttributeValue("", ATTR_ID); final String type = parser.getAttributeValue("", ATTR_TYPE); final String filename = parser.getAttributeValue("", ATTR_FILENAME); final int renderingMode = Integer.parseInt(parser.getAttributeValue("", ATTR_RENDERING_MODE)); - MediaItem currentMediaItem; if (MediaImageItem.class.getSimpleName().equals(type)) { final long durationMs = Long.parseLong(parser.getAttributeValue("", ATTR_DURATION)); @@ -673,11 +713,36 @@ public class VideoEditorTestImpl implements VideoEditor { if (currentMediaItem != null) { mMediaItems.add(currentMediaItem); } - } else if (name.equals(TAG_TRANSITION)) { + } else if (TAG_TRANSITION.equals(name)) { final Transition transition = parseTransition(parser); if (transition != null) { mTransitions.add(transition); } + } else if (TAG_OVERLAY.equals(name)) { + if (currentMediaItem != null) { + currentOverlay = parseOverlay(parser, currentMediaItem); + if (currentOverlay != null) { + currentMediaItem.addOverlay(currentOverlay); + } + } + } else if (TAG_OVERLAY_USER_ATTRIBUTES.equals(name)) { + if (currentOverlay != null) { + final int attributesCount = parser.getAttributeCount(); + for (int i = 0; i < attributesCount; i++) { + currentOverlay.setUserAttribute(parser.getAttributeName(i), + parser.getAttributeValue(i)); + } + } + } + break; + } + + case XmlPullParser.END_TAG: { + name = parser.getName(); + if (TAG_MEDIA_ITEM.equals(name)) { + currentMediaItem = null; + } else if (TAG_OVERLAY.equals(name)) { + currentOverlay = null; } break; } @@ -764,6 +829,31 @@ public class VideoEditorTestImpl implements VideoEditor { return transition; } + /** + * Parse the overlay + * + * @param parser The parser + * @param mediaItem The media item owner + * + * @return The overlay + */ + private Overlay parseOverlay(XmlPullParser parser, MediaItem mediaItem) { + final String overlayId = parser.getAttributeValue("", ATTR_ID); + final String type = parser.getAttributeValue("", ATTR_TYPE); + final long durationMs = Long.parseLong(parser.getAttributeValue("", ATTR_DURATION)); + final long startTimeMs = Long.parseLong(parser.getAttributeValue("", ATTR_BEGIN_TIME)); + + final Overlay overlay; + if (OverlayFrame.class.getSimpleName().equals(type)) { + final String filename = parser.getAttributeValue("", ATTR_FILENAME); + overlay = new OverlayFrame(mediaItem, overlayId, filename, startTimeMs, durationMs); + } else { + overlay = null; + } + + return overlay; + } + public void cancelExport(String filename) { } |