Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b0725a4a authored by Gil Dobjanschi's avatar Gil Dobjanschi Committed by Android (Google) Code Review
Browse files

Merge "Validate Overlay and effect duration and start time."

parents 9231e822 f8b04868
Loading
Loading
Loading
Loading
+29 −1
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ package android.media.videoeditor;
public abstract class Effect {
    // Instance variables
    private final String mUniqueId;
    // The effect owner
    private final MediaItem mMediaItem;
    protected long mDurationMs;
    // The start time of the effect relative to the media item timeline
    protected long mStartTimeMs;
@@ -35,6 +37,7 @@ public abstract class Effect {
     */
    @SuppressWarnings("unused")
    private Effect() {
        mMediaItem = null;
        mUniqueId = null;
        mStartTimeMs = 0;
        mDurationMs = 0;
@@ -43,12 +46,18 @@ public abstract class Effect {
    /**
     * Constructor
     *
     * @param mediaItem The media item owner
     * @param effectId The effect id
     * @param startTimeMs The start time relative to the media item to which it
     *            is applied
     * @param durationMs The effect duration in milliseconds
     */
    public Effect(String effectId, long startTimeMs, long durationMs) {
    public Effect(MediaItem mediaItem, String effectId, long startTimeMs, long durationMs) {
        if (mediaItem == null) {
            throw new IllegalArgumentException("Media item cannot be null");
        }

        mMediaItem = mediaItem;
        mUniqueId = effectId;
        mStartTimeMs = startTimeMs;
        mDurationMs = durationMs;
@@ -68,7 +77,13 @@ public abstract class Effect {
     * @param durationMs of the effect in milliseconds
     */
    public void setDuration(long durationMs) {
        if (mStartTimeMs + durationMs > mMediaItem.getTimelineDuration()) {
            throw new IllegalArgumentException("Duration is too large");
        }

        mDurationMs = durationMs;

        mMediaItem.invalidateTransitions(this);
    }

    /**
@@ -88,7 +103,13 @@ public abstract class Effect {
     *            of the media item in milliseconds
     */
    public void setStartTime(long startTimeMs) {
        if (startTimeMs + mDurationMs > mMediaItem.getTimelineDuration()) {
            throw new IllegalArgumentException("Start time is too large");
        }

        mStartTimeMs = startTimeMs;

        mMediaItem.invalidateTransitions(this);
    }

    /**
@@ -98,6 +119,13 @@ public abstract class Effect {
        return mStartTimeMs;
    }

    /**
     * @return The media item owner
     */
    public MediaItem getMediaItem() {
        return mMediaItem;
    }

    /*
     * {@inheritDoc}
     */
+4 −3
Original line number Diff line number Diff line
@@ -61,12 +61,13 @@ public class EffectColor extends Effect {
     */
    @SuppressWarnings("unused")
    private EffectColor() {
        this(null, 0, 0, 0, 0);
        this(null, null, 0, 0, 0, 0);
    }

    /**
     * Constructor
     *
     * @param mediaItem The media item owner
     * @param effectId The effect id
     * @param startTimeMs The start time relative to the media item to which it
     *            is applied
@@ -77,9 +78,9 @@ public class EffectColor extends Effect {
     * @param param if type is TYPE_COLOR, param is the RGB color as 888.
     *            Otherwise, param is ignored
     */
    public EffectColor(String effectId, long startTimeMs, long durationMs,
    public EffectColor(MediaItem mediaItem, String effectId, long startTimeMs, long durationMs,
            int type, int param) {
        super(effectId, startTimeMs, durationMs);
        super(mediaItem, effectId, startTimeMs, durationMs);
        mType = type;
        mParam = param;
    }
+5 −4
Original line number Diff line number Diff line
@@ -35,22 +35,23 @@ public class EffectKenBurns extends Effect {
     */
    @SuppressWarnings("unused")
    private EffectKenBurns() throws IOException {
        this(null, null, null, 0, 0);
        this(null, null, null, null, 0, 0);
    }

    /**
     * Constructor
     *
     * @param mediaItem The media item owner
     * @param effectId The effect id
     * @param startRect The start rectangle
     * @param endRect The end rectangle
     * @param startTimeMs The start time
     * @param durationMs The duration of the Ken Burns effect in milliseconds
     */
    public EffectKenBurns(String effectId, Rect startRect, Rect endRect, long startTime,
            long durationMs)
    public EffectKenBurns(MediaItem mediaItem, String effectId, Rect startRect, Rect endRect,
            long startTime, long durationMs)
            throws IOException {
        super(effectId, startTime, durationMs);
        super(mediaItem, effectId, startTime, durationMs);

        mStartRect = startRect;
        mEndRect = endRect;
+10 −2
Original line number Diff line number Diff line
@@ -205,6 +205,10 @@ public abstract class MediaItem {
     *      added.
     */
    public void addEffect(Effect effect) {
        if (effect.getMediaItem() != this) {
            throw new IllegalArgumentException("Media item mismatch");
        }

        if (mEffects.contains(effect)) {
            throw new IllegalArgumentException("Effect already exists: " + effect.getId());
        }
@@ -278,6 +282,10 @@ public abstract class MediaItem {
     *             the bitmap do not match the dimensions of the media item
     */
    public void addOverlay(Overlay overlay) {
        if (overlay.getMediaItem() != this) {
            throw new IllegalArgumentException("Media item mismatch");
        }

        if (mOverlays.contains(overlay)) {
            throw new IllegalArgumentException("Overlay already exists: " + overlay.getId());
        }
@@ -428,7 +436,7 @@ public abstract class MediaItem {
     *
     * @param effect The effect that was added or removed
     */
    private void invalidateTransitions(Effect effect) {
    void invalidateTransitions(Effect effect) {
        // Check if the effect overlaps with the beginning and end transitions
        if (mBeginTransition != null) {
            if (effect.getStartTime() < mBeginTransition.getDuration()) {
@@ -449,7 +457,7 @@ public abstract class MediaItem {
     *
     * @param overlay The effect that was added or removed
     */
    private void invalidateTransitions(Overlay overlay) {
    void invalidateTransitions(Overlay overlay) {
        // Check if the overlay overlaps with the beginning and end transitions
        if (mBeginTransition != null) {
            if (overlay.getStartTime() < mBeginTransition.getDuration()) {
+30 −1
Original line number Diff line number Diff line
@@ -24,16 +24,20 @@ package android.media.videoeditor;
public abstract class Overlay {
    // Instance variables
    private final String mUniqueId;
    // The overlay owner
    private final MediaItem mMediaItem;

    protected long mStartTimeMs;
    protected long mDurationMs;


    /**
     * Default constructor
     */
    @SuppressWarnings("unused")
    private Overlay() {
        mUniqueId = null;
        mMediaItem = null;
        mStartTimeMs = 0;
        mDurationMs = 0;
    }
@@ -41,6 +45,7 @@ public abstract class Overlay {
    /**
     * Constructor
     *
     * @param mediaItem The media item owner
     * @param overlayId The overlay id
     * @param startTimeMs The start time relative to the media item start time
     * @param durationMs The duration
@@ -48,7 +53,12 @@ public abstract class Overlay {
     * @throws IllegalArgumentException if the file type is not PNG or the
     *      startTimeMs and durationMs are incorrect.
     */
    public Overlay(String overlayId, long startTimeMs, long durationMs) {
    public Overlay(MediaItem mediaItem, String overlayId, long startTimeMs, long durationMs) {
        if (mediaItem == null) {
            throw new IllegalArgumentException("Media item cannot be null");
        }

        mMediaItem = mediaItem;
        mUniqueId = overlayId;
        mStartTimeMs = startTimeMs;
        mDurationMs = durationMs;
@@ -75,7 +85,13 @@ public abstract class Overlay {
     * @param durationMs The duration in milliseconds
     */
    public void setDuration(long durationMs) {
        if (mStartTimeMs + durationMs > mMediaItem.getTimelineDuration()) {
            throw new IllegalArgumentException("Duration is too large");
        }

        mDurationMs = durationMs;

        mMediaItem.invalidateTransitions(this);
    }

    /**
@@ -93,7 +109,20 @@ public abstract class Overlay {
     * @param startTimeMs start time in milliseconds
     */
    public void setStartTime(long startTimeMs) {
        if (startTimeMs + mDurationMs > mMediaItem.getTimelineDuration()) {
            throw new IllegalArgumentException("Start time is too large");
        }

        mStartTimeMs = startTimeMs;

        mMediaItem.invalidateTransitions(this);
    }

    /**
     * @return The media item owner
     */
    public MediaItem getMediaItem() {
        return mMediaItem;
    }

    /*
Loading