import java.io.IOException;
import java.math.BigDecimal;
import java.nio.IntBuffer;
-import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.concurrent.Semaphore;
+
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
*This class provide Native methods to be used by MediaArtist {@hide}
*/
class MediaArtistNativeHelper {
+ private static final String TAG = "MediaArtistNativeHelper";
static {
System.loadLibrary("videoeditor_jni");
}
- private final int MAX_THUMBNAIL_PERMITTED = 8;
+ private static final int MAX_THUMBNAIL_PERMITTED = 8;
+
+ public static final int TASK_LOADING_SETTINGS = 1;
+ public static final int TASK_ENCODING = 2;
+
+ /**
+ * The resize paint
+ */
+ private static final Paint sResizePaint = new Paint(Paint.FILTER_BITMAP_FLAG);
private final VideoEditor mVideoEditor;
- public EditSettings mStoryBoardSettings;
+ private EditSettings mStoryBoardSettings;
private String mOutputFilename;
- EditSettings mEditSettings = null;
-
- PreviewClipProperties mClipProperties = null;
+ private PreviewClipProperties mClipProperties = null;
private EditSettings mPreviewEditSettings;
private AudioTrack mAudioTrack = null;
- public boolean mInvalidatePreviewArray = true;
+ private boolean mInvalidatePreviewArray = true;
private boolean mRegenerateAudio = true;
private String mExportFilename = null;
- private boolean mExportDone = false;
-
private int mProgressToApp;
- /**
- * The resize paint
+ /*
+ * Semaphore to control preview calls
*/
- private static final Paint sResizePaint = new Paint(Paint.FILTER_BITMAP_FLAG);
+ private final Semaphore mLock = new Semaphore(1, true);
private String mRenderPreviewOverlayFile;
- private int mRenderPreviewRenderingMode;
+ private int mRenderPreviewRenderingMode;
private boolean mIsFirstProgress;
- public static final int TASK_LOADING_SETTINGS = 1;
-
- public static final int TASK_ENCODING = 2;
-
private static final String AUDIO_TRACK_PCM_FILE = "AudioPcm.pcm";
// Processing indication
public static final int PROCESSING_INTERMEDIATE3 = 13;
public static final int PROCESSING_EXPORT = 20;
- private int mProcessingState;
+ private int mProcessingState;
private Object mProcessingObject;
-
private PreviewProgressListener mPreviewProgressListener;
private ExportProgressListener mExportProgressListener;
private ExtractAudioWaveformProgressListener mExtractAudioWaveformProgressListener;
- private MediaProcessingProgressListener mMediaProcessingProgressListener;
+ private MediaProcessingProgressListener mMediaProcessingProgressListener;
private final String mProjectPath;
private long mPreviewProgress;
private String mAudioTrackPCMFilePath;
- int mTotalClips = 0;
-
- int mPreviewEffectsSize = 0;
+ private int mTotalClips = 0;
private boolean mErrorFlagSet = false;
@SuppressWarnings("unused")
private int mManualEditContext;
-
- List<Effect> mMediaEffectList;
-
- List<Overlay> mMediaOverLayList;
-
/* Listeners */
/**
/** Internal error. */
public static final int ERR_INTERNAL = 255;
-
}
/**
}
/**
- * Defines transition behaviours.
- **/
-
+ * Defines transition behaviors.
+ */
public static final class TransitionBehaviour {
/** The transition uses an increasing speed. */
public static final int FAST_MIDDLE = 4;
}
- /** Defines settings for the background music. */
+ /**
+ * Defines settings for the background music.
+ */
public static class BackgroundMusicSettings {
/** Background music file. */
public int lowVolume;
public boolean isLooping;
-
}
/** Defines settings for an effect. */
boolean bInDucking_enable;
String pcmFilePath;
-
}
/** Encapsulates preview clips and effect settings */
public int audioVolumeValue;
public String Id;
-
}
/**
if (mStoryBoardSettings == null)
mStoryBoardSettings = new EditSettings();
- mMediaEffectList = new ArrayList<Effect>();
- mMediaOverLayList = new ArrayList<Overlay>();
_init(mProjectPath, "null");
mAudioTrackPCMFilePath = null;
}
case PROCESSING_NONE:
default:
- Log.e("MediaArtistNativeHelper", "ERROR unexpected State=" + mProcessingState);
+ Log.e(TAG, "ERROR unexpected State=" + mProcessingState);
return;
}
if ((mProgressToApp != actualProgress) && (actualProgress != 0)) {
if (mMediaProcessingProgressListener != null) {
// Send the progress indication
- mMediaProcessingProgressListener.onProgress(mProcessingObject,
- action,
+ mMediaProcessingProgressListener.onProgress(mProcessingObject, action,
actualProgress);
}
}
/*
* Send the progress indication
*/
- mMediaProcessingProgressListener.onProgress(mProcessingObject,
- action,
+ mMediaProcessingProgressListener.onProgress(mProcessingObject, action,
actualProgress);
}
mProgressToApp = 1;
/**
* Release the native helper object
*/
- public void releaseNativeHelper() {
+ void releaseNativeHelper() {
try {
release();
} catch (IllegalStateException ex) {
- Log.e("MediaArtistNativeHelper",
- "Illegal State exeption caught in releaseNativeHelper");
+ Log.e(TAG, "Illegal State exeption caught in releaseNativeHelper");
throw ex;
} catch (RuntimeException ex) {
- Log.e("MediaArtistNativeHelper", "Runtime exeption caught in releaseNativeHelper");
+ Log.e(TAG, "Runtime exeption caught in releaseNativeHelper");
throw ex;
}
}
*/
@SuppressWarnings("unused")
private void onAudioGraphExtractProgressUpdate(int progress, boolean isVideo) {
-
- if ((mExtractAudioWaveformProgressListener != null) && (progress > 0))
- {
+ if ((mExtractAudioWaveformProgressListener != null) && (progress > 0)) {
mExtractAudioWaveformProgressListener.onProgress(progress);
}
}
*
* @param effects The reference of EffectColor
*
- * @return The populated effect settings in EffectSettings
- * reference
+ * @return The populated effect settings in EffectSettings reference
*/
EffectSettings getEffectSettings(EffectColor effects) {
EffectSettings effectSettings = new EffectSettings();
*
* @param overlay The reference of OverlayFrame
*
- * @return The populated overlay settings in EffectSettings
- * reference
+ * @return The populated overlay settings in EffectSettings reference
*/
EffectSettings getOverlaySettings(OverlayFrame overlay) {
EffectSettings effectSettings = new EffectSettings();
try {
(overlay).save(mProjectPath);
} catch (IOException e) {
- Log.e("MediaArtistNativeHelper","getOverlaySettings : File not found");
+ Log.e(TAG, "getOverlaySettings : File not found");
}
effectSettings.framingFile = overlay.getFilename();
}
int aspectRatio;
if (overlay.getMediaItem() instanceof MediaImageItem) {
if (((MediaImageItem)overlay.getMediaItem()).getGeneratedImageClip() != null) {
- //Kenburns was applied
+ // Ken Burns was applied
mediaItemHeight = ((MediaImageItem)overlay.getMediaItem()).getGeneratedClipHeight();
aspectRatio = getAspectRatio(
((MediaImageItem)overlay.getMediaItem()).getGeneratedClipWidth()
, mediaItemHeight);
- }
- else {
+ } else {
//For image get the scaled height. Aspect ratio would remain the same
mediaItemHeight = ((MediaImageItem)overlay.getMediaItem()).getScaledHeight();
aspectRatio = overlay.getMediaItem().getAspectRatio();
*
* @return The frame rate from one of the defined enum values
*/
- public int GetClosestVideoFrameRate(int averageFrameRate) {
+ int GetClosestVideoFrameRate(int averageFrameRate) {
if (averageFrameRate >= 25) {
return VideoFrameRate.FR_30_FPS;
} else if (averageFrameRate >= 20) {
* Helper function to adjust the effect or overlay start time
* depending on the begin and end boundary time of meddia item
*/
- public void adjustEffectsStartTimeAndDuration(EffectSettings lEffect,
- int beginCutTime,
+ public void adjustEffectsStartTimeAndDuration(EffectSettings lEffect, int beginCutTime,
int endCutTime) {
int effectStartTime = 0;
try {
err = nativeGenerateClip(editSettings);
} catch (IllegalArgumentException ex) {
- Log.e("MediaArtistNativeHelper","Illegal Argument exception in load settings");
+ Log.e(TAG, "Illegal Argument exception in load settings");
return -1;
} catch (IllegalStateException ex) {
- Log.e("MediaArtistNativeHelper","Illegal state exception in load settings");
+ Log.e(TAG, "Illegal state exception in load settings");
return -1;
} catch (RuntimeException ex) {
- Log.e("MediaArtistNativeHelper", "Runtime exception in load settings");
+ Log.e(TAG, "Runtime exception in load settings");
return -1;
}
return err;
}
/**
- * Init function to initialise the ClipSettings reference to
+ * Init function to initialiZe the ClipSettings reference to
* default values
*
* @param lclipSettings The ClipSettings reference
//editSettings.videoFormat = VideoFormat.MPEG4;
editSettings.videoFormat = VideoFormat.H264;
editSettings.videoFrameRate = VideoFrameRate.FR_30_FPS;
- editSettings.videoFrameSize = findVideoResolution(mVideoEditor.getAspectRatio(), m
- .getHeight());
-
+ editSettings.videoFrameSize = findVideoResolution(mVideoEditor.getAspectRatio(),
+ m.getHeight());
} else {
MediaImageItem m = (MediaImageItem)lMediaItem;
editSettings.audioBitrate = Bitrate.BR_64_KBPS;
editSettings.videoBitrate = Bitrate.BR_5_MBPS;
editSettings.videoFormat = VideoFormat.H264;
editSettings.videoFrameRate = VideoFrameRate.FR_30_FPS;
- editSettings.videoFrameSize = findVideoResolution(mVideoEditor.getAspectRatio(), m
- .getScaledHeight());
+ editSettings.videoFrameSize = findVideoResolution(mVideoEditor.getAspectRatio(),
+ m.getScaledHeight());
}
editSettings.outputFile = EffectClipPath;
clip2Height = ((MediaImageItem)m2).getScaledHeight();
}
if (clip1Height > clip2Height) {
- videoSize = findVideoResolution(mVideoEditor.getAspectRatio(),
- clip1Height);
+ videoSize = findVideoResolution(mVideoEditor.getAspectRatio(), clip1Height);
} else {
- videoSize = findVideoResolution(mVideoEditor.getAspectRatio(),
- clip2Height);
+ videoSize = findVideoResolution(mVideoEditor.getAspectRatio(), clip2Height);
}
} else if (m1 == null && m2 != null) {
if (m2 instanceof MediaVideoItem) {
} else if (m2 instanceof MediaImageItem) {
clip2Height = ((MediaImageItem)m2).getScaledHeight();
}
- videoSize = findVideoResolution(mVideoEditor.getAspectRatio(),
- clip2Height);
+ videoSize = findVideoResolution(mVideoEditor.getAspectRatio(), clip2Height);
} else if (m1 != null && m2 == null) {
if (m1 instanceof MediaVideoItem) {
clip1Height = m1.getHeight();
} else if (m1 instanceof MediaImageItem) {
clip1Height = ((MediaImageItem)m1).getScaledHeight();
}
- videoSize = findVideoResolution(mVideoEditor.getAspectRatio(),
- clip1Height);
+ videoSize = findVideoResolution(mVideoEditor.getAspectRatio(), clip1Height);
}
return videoSize;
}
*
* @param m1 Media item associated with effect
* @param effectSettings The EffectSettings reference containing
- * effect specific data
+ * effect specific data
* @param beginCutTime The begin cut time of the clip associated with effect
* @param endCutTime The end cut time of the clip associated with effect
* @param storyBoardTime The current story board time
*/
private int populateEffects(MediaItem m, EffectSettings[] effectSettings, int i,
int beginCutTime, int endCutTime, int storyBoardTime) {
- List<Effect> effects = m.getAllEffects();
- List<Overlay> overlays = m.getAllOverlays();
if (m.getBeginTransition() != null && m.getBeginTransition().getDuration() > 0
&& m.getEndTransition() != null && m.getEndTransition().getDuration() > 0) {
beginCutTime += m.getBeginTransition().getDuration();
}
+ final List<Effect> effects = m.getAllEffects();
+ final List<Overlay> overlays = m.getAllOverlays();
for (Effect effect : effects) {
if (effect instanceof EffectColor) {
effectSettings[i] = getEffectSettings((EffectColor)effect);
- adjustEffectsStartTimeAndDuration(effectSettings[i],
- beginCutTime, endCutTime);
+ adjustEffectsStartTimeAndDuration(effectSettings[i], beginCutTime, endCutTime);
effectSettings[i].startTime += storyBoardTime;
i++;
}
}
+
for (Overlay overlay : overlays) {
effectSettings[i] = getOverlaySettings((OverlayFrame)overlay);
- adjustEffectsStartTimeAndDuration(effectSettings[i],
- beginCutTime, endCutTime);
+ adjustEffectsStartTimeAndDuration(effectSettings[i], beginCutTime, endCutTime);
effectSettings[i].startTime += storyBoardTime;
i++;
}
Properties clipProperties, MediaItem m) {
if (m.getBeginTransition() != null && m.getBeginTransition().getDuration() > 0
&& m.getEndTransition() != null && m.getEndTransition().getDuration() > 0) {
-
clipSettings.beginCutTime += m.getBeginTransition().getDuration();
clipSettings.endCutTime -= m.getEndTransition().getDuration();
-
} else if (m.getBeginTransition() == null && m.getEndTransition() != null
&& m.getEndTransition().getDuration() > 0) {
-
clipSettings.endCutTime -= m.getEndTransition().getDuration();
-
} else if (m.getEndTransition() == null && m.getBeginTransition() != null
&& m.getBeginTransition().getDuration() > 0) {
-
clipSettings.beginCutTime += m.getBeginTransition().getDuration();
}
- clipProperties.duration = clipSettings.endCutTime -
- clipSettings.beginCutTime;
+
+ clipProperties.duration = clipSettings.endCutTime - clipSettings.beginCutTime;
if (clipProperties.videoDuration != 0) {
- clipProperties.videoDuration = clipSettings.endCutTime -
- clipSettings.beginCutTime;
+ clipProperties.videoDuration = clipSettings.endCutTime - clipSettings.beginCutTime;
}
if (clipProperties.audioDuration != 0) {
- clipProperties.audioDuration = clipSettings.endCutTime -
- clipSettings.beginCutTime;
+ clipProperties.audioDuration = clipSettings.endCutTime - clipSettings.beginCutTime;
}
}
editSettings.clipSettingsArray[index].clipPath = transition.getFilename();
editSettings.clipSettingsArray[index].fileType = FileType.THREE_GPP;
editSettings.clipSettingsArray[index].beginCutTime = 0;
- editSettings.clipSettingsArray[index].endCutTime =
- (int)transition.getDuration();
- editSettings.clipSettingsArray[index].mediaRendering =
- MediaRendering.BLACK_BORDERS;
+ editSettings.clipSettingsArray[index].endCutTime = (int)transition.getDuration();
+ editSettings.clipSettingsArray[index].mediaRendering = MediaRendering.BLACK_BORDERS;
+
try {
clipPropertiesArray.clipProperties[index] =
- getMediaProperties(transition.getFilename());
+ getMediaProperties(transition.getFilename());
} catch (Exception e) {
throw new IllegalArgumentException("Unsupported file or file not found");
}
+
clipPropertiesArray.clipProperties[index].Id = null;
clipPropertiesArray.clipProperties[index].audioVolumeValue = 100;
- clipPropertiesArray.clipProperties[index].duration =
- (int)transition.getDuration();
+ clipPropertiesArray.clipProperties[index].duration = (int)transition.getDuration();
if (clipPropertiesArray.clipProperties[index].videoDuration != 0) {
- clipPropertiesArray.clipProperties[index].videoDuration =
- (int)transition.getDuration();
+ clipPropertiesArray.clipProperties[index].videoDuration = (int)transition.getDuration();
}
+
if (clipPropertiesArray.clipProperties[index].audioDuration != 0) {
- clipPropertiesArray.clipProperties[index].audioDuration =
- (int)transition.getDuration();
+ clipPropertiesArray.clipProperties[index].audioDuration = (int)transition.getDuration();
}
}
private void adjustVolume(MediaItem m, PreviewClipProperties clipProperties,
int index) {
if (m instanceof MediaVideoItem) {
- boolean videoMuted = ((MediaVideoItem)m).isMuted();
+ final boolean videoMuted = ((MediaVideoItem)m).isMuted();
if (videoMuted == false) {
- mClipProperties.clipProperties[index].audioVolumeValue = ((MediaVideoItem)m)
- .getVolume();
+ mClipProperties.clipProperties[index].audioVolumeValue =
+ ((MediaVideoItem)m).getVolume();
} else {
mClipProperties.clipProperties[index].audioVolumeValue = 0;
}
private int populateMediaItemProperties(MediaItem m, int index, int maxHeight) {
mPreviewEditSettings.clipSettingsArray[index] = new ClipSettings();
if (m instanceof MediaVideoItem) {
- mPreviewEditSettings.clipSettingsArray[index] = ((MediaVideoItem)m)
- .getVideoClipProperties();
+ mPreviewEditSettings.clipSettingsArray[index] =
+ ((MediaVideoItem)m).getVideoClipProperties();
if (((MediaVideoItem)m).getHeight() > maxHeight) {
maxHeight = ((MediaVideoItem)m).getHeight();
}
} else if (m instanceof MediaImageItem) {
- mPreviewEditSettings.clipSettingsArray[index] = ((MediaImageItem)m)
- .getImageClipProperties();
+ mPreviewEditSettings.clipSettingsArray[index] =
+ ((MediaImageItem)m).getImageClipProperties();
if (((MediaImageItem)m).getScaledHeight() > maxHeight) {
maxHeight = ((MediaImageItem)m).getScaledHeight();
}
}
/** + Handle the image files here */
if (mPreviewEditSettings.clipSettingsArray[index].fileType == FileType.JPG) {
- mPreviewEditSettings.clipSettingsArray[index].clipDecodedPath = ((MediaImageItem)m)
- .getDecodedImageFileName();
+ mPreviewEditSettings.clipSettingsArray[index].clipDecodedPath =
+ ((MediaImageItem)m).getDecodedImageFileName();
mPreviewEditSettings.clipSettingsArray[index].clipOriginalPath =
mPreviewEditSettings.clipSettingsArray[index].clipPath;
if (mediaBGMList.size() == 1) {
mAudioTrack = mediaBGMList.get(0);
- } else
- {
+ } else {
mAudioTrack = null;
}
mAudioSettings.ducking_threshold = mAudioTrack.getDuckingThreshhold();
mAudioSettings.bInDucking_enable = mAudioTrack.isDuckingEnabled();
mAudioTrackPCMFilePath = String.format(mProjectPath + "/" + AUDIO_TRACK_PCM_FILE);
- //String.format(mProjectPath + "/" + "AudioPcm" + ".pcm");
mAudioSettings.pcmFilePath = mAudioTrackPCMFilePath;
- mPreviewEditSettings.backgroundMusicSettings =
- new BackgroundMusicSettings();
- mPreviewEditSettings.backgroundMusicSettings.file =
- mAudioTrackPCMFilePath;
- mPreviewEditSettings.backgroundMusicSettings.fileType =
- mAudioProperties.fileType;
+ mPreviewEditSettings.backgroundMusicSettings = new BackgroundMusicSettings();
+ mPreviewEditSettings.backgroundMusicSettings.file = mAudioTrackPCMFilePath;
+ mPreviewEditSettings.backgroundMusicSettings.fileType = mAudioProperties.fileType;
mPreviewEditSettings.backgroundMusicSettings.insertionTime =
- mAudioTrack.getStartTime();
- mPreviewEditSettings.backgroundMusicSettings.volumePercent =
- mAudioTrack.getVolume();
- mPreviewEditSettings.backgroundMusicSettings.beginLoop = mAudioTrack
- .getBoundaryBeginTime();
+ mAudioTrack.getStartTime();
+ mPreviewEditSettings.backgroundMusicSettings.volumePercent = mAudioTrack.getVolume();
+ mPreviewEditSettings.backgroundMusicSettings.beginLoop =
+ mAudioTrack.getBoundaryBeginTime();
mPreviewEditSettings.backgroundMusicSettings.endLoop =
mAudioTrack.getBoundaryEndTime();
- mPreviewEditSettings.backgroundMusicSettings.enableDucking = mAudioTrack
- .isDuckingEnabled();
- mPreviewEditSettings.backgroundMusicSettings.duckingThreshold = mAudioTrack
- .getDuckingThreshhold();
- mPreviewEditSettings.backgroundMusicSettings.lowVolume = mAudioTrack
- .getDuckedTrackVolume();
- mPreviewEditSettings.backgroundMusicSettings.isLooping =
- mAudioTrack.isLooping();
+ mPreviewEditSettings.backgroundMusicSettings.enableDucking =
+ mAudioTrack.isDuckingEnabled();
+ mPreviewEditSettings.backgroundMusicSettings.duckingThreshold =
+ mAudioTrack.getDuckingThreshhold();
+ mPreviewEditSettings.backgroundMusicSettings.lowVolume =
+ mAudioTrack.getDuckedTrackVolume();
+ mPreviewEditSettings.backgroundMusicSettings.isLooping = mAudioTrack.isLooping();
mPreviewEditSettings.primaryTrackVolume = 100;
mProcessingState = PROCESSING_AUDIO_PCM;
mProcessingObject = mAudioTrack;
} else {
- if (mAudioSettings != null) {
- mAudioSettings = null;
- }
- if (mPreviewEditSettings.backgroundMusicSettings != null) {
- mPreviewEditSettings.backgroundMusicSettings = null;
- }
+ mAudioSettings = null;
+ mPreviewEditSettings.backgroundMusicSettings = null;
mAudioTrackPCMFilePath = null;
}
}
final Iterator<Effect> ef = t.getAllEffects().iterator();
while (ef.hasNext()) {
final Effect e = ef.next();
- if (e instanceof EffectKenBurns)
+ if (e instanceof EffectKenBurns) {
totalEffects--;
+ }
}
}
return totalEffects;
* @param listener The MediaProcessingProgressListener
*
*/
- public void previewStoryBoard(List<MediaItem> mediaItemsList,
+ void previewStoryBoard(List<MediaItem> mediaItemsList,
List<Transition> mediaTransitionList, List<AudioTrack> mediaBGMList,
MediaProcessingProgressListener listener) {
if (mInvalidatePreviewArray) {
mTotalClips = mediaItemsList.size();
for (Transition transition : mediaTransitionList) {
- if (transition.getDuration() > 0)
+ if (transition.getDuration() > 0) {
mTotalClips++;
+ }
}
totalEffects = getTotalEffects(mediaItemsList);
mPreviewEditSettings.effectSettingsArray = new EffectSettings[totalEffects];
mClipProperties.clipProperties = new Properties[mTotalClips];
- /** record the call back progress listner */
+ /** record the call back progress listener */
mMediaProcessingProgressListener = listener;
mProgressToApp = 0;
previewIndex++;
}
/* Populate media item properties */
- maxHeight = populateMediaItemProperties(lMediaItem,
- previewIndex,
- maxHeight);
+ maxHeight = populateMediaItemProperties(lMediaItem, previewIndex, maxHeight);
/* Get the clip properties of the media item. */
- if (lMediaItem instanceof MediaImageItem)
- {
+ if (lMediaItem instanceof MediaImageItem) {
int tmpCnt = 0;
boolean bEffectKbPresent = false;
- List<Effect> effectList = lMediaItem.getAllEffects();
+ final List<Effect> effectList = lMediaItem.getAllEffects();
/**
- * check if Kenburns effect is present
+ * Check if Ken Burns effect is present
*/
- while ( tmpCnt < effectList.size()) {
+ while (tmpCnt < effectList.size()) {
if (effectList.get(tmpCnt) instanceof EffectKenBurns) {
bEffectKbPresent = true;
break;
mClipProperties.clipProperties[previewIndex].width = ((MediaImageItem)lMediaItem).getScaledWidth();
mClipProperties.clipProperties[previewIndex].height = ((MediaImageItem)lMediaItem).getScaledHeight();
}
-
- }else
- {
+ } else {
try {
mClipProperties.clipProperties[previewIndex]
= getMediaProperties(lMediaItem.getFilename());
if (!mErrorFlagSet) {
mPreviewEditSettings.videoFrameSize = findVideoResolution(mVideoEditor
.getAspectRatio(), maxHeight);
- /*if (mediaBGMList.size() == 1) //for remove Audio check */ {
- populateBackgroundMusicProperties(mediaBGMList);
- }
+ populateBackgroundMusicProperties(mediaBGMList);
+
/** call to native populate settings */
try {
nativePopulateSettings(mPreviewEditSettings, mClipProperties, mAudioSettings);
} catch (IllegalArgumentException ex) {
- Log.e("MediaArtistNativeHelper",
- "Illegal argument exception in nativePopulateSettings");
+ Log.e(TAG, "Illegal argument exception in nativePopulateSettings");
throw ex;
} catch (IllegalStateException ex) {
- Log.e("MediaArtistNativeHelper",
- "Illegal state exception in nativePopulateSettings");
+ Log.e(TAG, "Illegal state exception in nativePopulateSettings");
throw ex;
} catch (RuntimeException ex) {
- Log.e("MediaArtistNativeHelper", "Runtime exception in nativePopulateSettings");
+ Log.e(TAG, "Runtime exception in nativePopulateSettings");
throw ex;
}
mInvalidatePreviewArray = false;
* the callback is needed
* @param listener The PreviewProgressListener
*/
- public void doPreview(Surface surface, long fromMs, long toMs, boolean loop,
+ void doPreview(Surface surface, long fromMs, long toMs, boolean loop,
int callbackAfterFrameCount, PreviewProgressListener listener) {
mPreviewProgress = fromMs;
mIsFirstProgress = true;
if (!mInvalidatePreviewArray) {
try {
/** Modify the image files names to rgb image files. */
- for (int clipCnt = 0; clipCnt < mPreviewEditSettings.clipSettingsArray.length; clipCnt++) {
+ for (int clipCnt = 0; clipCnt < mPreviewEditSettings.clipSettingsArray.length;
+ clipCnt++) {
if (mPreviewEditSettings.clipSettingsArray[clipCnt].fileType == FileType.JPG) {
- mPreviewEditSettings.clipSettingsArray[clipCnt].clipPath = mPreviewEditSettings.clipSettingsArray[clipCnt].clipDecodedPath;
+ mPreviewEditSettings.clipSettingsArray[clipCnt].clipPath =
+ mPreviewEditSettings.clipSettingsArray[clipCnt].clipDecodedPath;
}
}
nativePopulateSettings(mPreviewEditSettings, mClipProperties, mAudioSettings);
nativeStartPreview(surface, fromMs, toMs, callbackAfterFrameCount, loop);
} catch (IllegalArgumentException ex) {
- Log.e("MediaArtistNativeHelper",
- "Illegal argument exception in nativeStartPreview");
+ Log.e(TAG, "Illegal argument exception in nativeStartPreview");
throw ex;
} catch (IllegalStateException ex) {
- Log.e("MediaArtistNativeHelper", "Illegal state exception in nativeStartPreview");
+ Log.e(TAG, "Illegal state exception in nativeStartPreview");
throw ex;
} catch (RuntimeException ex) {
- Log.e("MediaArtistNativeHelper", "Runtime exception in nativeStartPreview");
+ Log.e(TAG, "Runtime exception in nativeStartPreview");
throw ex;
}
}
/**
* This function is responsible for stopping the preview
*/
- public long stopPreview() {
+ long stopPreview() {
nativeStopPreview();
return mPreviewProgress;
}
* @return The actual time from the story board at which the frame was extracted
* and rendered
*/
- public long renderPreviewFrame(Surface surface, long time, int surfaceWidth,
+ long renderPreviewFrame(Surface surface, long time, int surfaceWidth,
int surfaceHeight, VideoEditor.OverlayData overlayData) {
- long timeMs = 0;
- if (!mInvalidatePreviewArray) {
- try {
- for (int clipCnt = 0;
- clipCnt < mPreviewEditSettings.clipSettingsArray.length;
- clipCnt++) {
+ if (mInvalidatePreviewArray) {
+ throw new RuntimeException("Call generate preview first");
+ }
- if (mPreviewEditSettings.clipSettingsArray[clipCnt].fileType == FileType.JPG) {
- mPreviewEditSettings.clipSettingsArray[clipCnt].clipPath =
- mPreviewEditSettings.clipSettingsArray[clipCnt].clipDecodedPath;
- }
+ long timeMs = 0;
+ try {
+ for (int clipCnt = 0; clipCnt < mPreviewEditSettings.clipSettingsArray.length;
+ clipCnt++) {
+ if (mPreviewEditSettings.clipSettingsArray[clipCnt].fileType == FileType.JPG) {
+ mPreviewEditSettings.clipSettingsArray[clipCnt].clipPath =
+ mPreviewEditSettings.clipSettingsArray[clipCnt].clipDecodedPath;
}
+ }
- // Reset the render preview frame params that shall be set by native.
- mRenderPreviewOverlayFile = null;
- mRenderPreviewRenderingMode = MediaRendering.RESIZING;
- nativePopulateSettings(mPreviewEditSettings, mClipProperties, mAudioSettings);
- timeMs = (long)nativeRenderPreviewFrame(surface, time, surfaceWidth, surfaceHeight);
+ // Reset the render preview frame params that shall be set by native.
+ mRenderPreviewOverlayFile = null;
+ mRenderPreviewRenderingMode = MediaRendering.RESIZING;
- if (mRenderPreviewOverlayFile != null) {
- overlayData.set(BitmapFactory.decodeFile(mRenderPreviewOverlayFile), mRenderPreviewRenderingMode);
- } else {
- overlayData.setClear();
- }
- } catch (IllegalArgumentException ex) {
- Log.e("MediaArtistNativeHelper",
- "Illegal Argument exception in nativeRenderPreviewFrame");
- throw ex;
- } catch (IllegalStateException ex) {
- Log.e("MediaArtistNativeHelper",
- "Illegal state exception in nativeRenderPreviewFrame");
- throw ex;
- } catch (RuntimeException ex) {
- Log.e("MediaArtistNativeHelper", "Runtime exception in nativeRenderPreviewFrame");
- throw ex;
+ nativePopulateSettings(mPreviewEditSettings, mClipProperties, mAudioSettings);
+
+ timeMs = (long)nativeRenderPreviewFrame(surface, time, surfaceWidth, surfaceHeight);
+
+ if (mRenderPreviewOverlayFile != null) {
+ overlayData.set(BitmapFactory.decodeFile(mRenderPreviewOverlayFile),
+ mRenderPreviewRenderingMode);
+ } else {
+ overlayData.setClear();
}
- return timeMs;
- } else {
- throw new RuntimeException("Call generate preview first");
+ } catch (IllegalArgumentException ex) {
+ Log.e(TAG, "Illegal Argument exception in nativeRenderPreviewFrame");
+ throw ex;
+ } catch (IllegalStateException ex) {
+ Log.e(TAG, "Illegal state exception in nativeRenderPreviewFrame");
+ throw ex;
+ } catch (RuntimeException ex) {
+ Log.e(TAG, "Runtime exception in nativeRenderPreviewFrame");
+ throw ex;
}
+
+ return timeMs;
}
private void previewFrameEditInfo(String filename, int renderingMode) {
* @return The actual time from media item at which the frame was extracted
* and rendered
*/
- public long renderMediaItemPreviewFrame(Surface surface, String filepath,
- long time, int framewidth,
- int frameheight) {
+ long renderMediaItemPreviewFrame(Surface surface, String filepath,
+ long time, int framewidth, int frameheight) {
long timeMs = 0;
try {
-
timeMs = (long)nativeRenderMediaItemPreviewFrame(surface, filepath, framewidth,
frameheight, 0, 0, time);
} catch (IllegalArgumentException ex) {
- Log.e("MediaArtistNativeHelper",
- "Illegal Argument exception in renderMediaItemPreviewFrame");
+ Log.e(TAG, "Illegal Argument exception in renderMediaItemPreviewFrame");
throw ex;
} catch (IllegalStateException ex) {
- Log.e("MediaArtistNativeHelper",
- "Illegal state exception in renderMediaItemPreviewFrame");
+ Log.e(TAG, "Illegal state exception in renderMediaItemPreviewFrame");
throw ex;
} catch (RuntimeException ex) {
- Log.e("MediaArtistNativeHelper", "Runtime exception in renderMediaItemPreviewFrame");
+ Log.e(TAG, "Runtime exception in renderMediaItemPreviewFrame");
throw ex;
}
* and for generating the preview again
*/
void setGeneratePreview(boolean isRequired) {
- mInvalidatePreviewArray = isRequired;
+ boolean semAcquiredDone = false;
+ try {
+ lock();
+ semAcquiredDone = true;
+ mInvalidatePreviewArray = isRequired;
+ } catch (InterruptedException ex) {
+ Log.e(TAG, "Runtime exception in renderMediaItemPreviewFrame");
+ } finally {
+ if (semAcquiredDone) {
+ unlock();
+ }
+ }
}
/**
*
* @return The calculated aspect ratio
*/
- public int getAspectRatio(int w, int h) {
+ int getAspectRatio(int w, int h) {
double apRatio = (double)(w) / (double)(h);
BigDecimal bd = new BigDecimal(apRatio);
bd = bd.setScale(3, BigDecimal.ROUND_HALF_UP);
*
* @return The File type in JAVA layer
*/
- public int getFileType(int fileType) {
+ int getFileType(int fileType) {
int retValue = -1;
switch (fileType) {
case FileType.UNSUPPORTED:
*
* @return The video codec type in JAVA layer
*/
- public int getVideoCodecType(int codecType) {
+ int getVideoCodecType(int codecType) {
int retValue = -1;
switch (codecType) {
case VideoFormat.H263:
*
* @return The audio codec type in JAVA layer
*/
- public int getAudioCodecType(int codecType) {
+ int getAudioCodecType(int codecType) {
int retValue = -1;
switch (codecType) {
case AudioFormat.AMR_NB:
*
* @return The frame rate as integer
*/
- public int getFrameRate(int fps) {
+ int getFrameRate(int fps) {
int retValue = -1;
switch (fps) {
case VideoFrameRate.FR_5_FPS:
}
/**
- * Calculates videdo resolution for output clip
+ * Calculates video resolution for output clip
* based on clip's height and aspect ratio of storyboard
*
* @param aspectRatio The aspect ratio of story board
resolutions = MediaProperties.getSupportedResolutions(mVideoEditor.getAspectRatio());
// Get the highest resolution
maxResolution = resolutions[resolutions.length - 1];
- retValue = findVideoResolution(mVideoEditor.getAspectRatio(),
- maxResolution.second);
+ retValue = findVideoResolution(mVideoEditor.getAspectRatio(), maxResolution.second);
}
return retValue;
* @param height The height of clip
* @param bitrate The bitrate at which the movie should be exported
* @param mediaItemsList The media items list
- * @param mediaTransitionList The transitons list
+ * @param mediaTransitionList The transitions list
* @param mediaBGMList The background track list
* @param listener The ExportProgressListener
*
*/
- public void export(String filePath, String projectDir, int height, int bitrate,
+ void export(String filePath, String projectDir, int height, int bitrate,
List<MediaItem> mediaItemsList, List<Transition> mediaTransitionList,
List<AudioTrack> mediaBGMList, ExportProgressListener listener) {
mPreviewEditSettings.transitionSettingsArray = new TransitionSettings[mTotalClips - 1];
for (int index = 0; index < mTotalClips - 1; index++) {
mPreviewEditSettings.transitionSettingsArray[index] = new TransitionSettings();
- mPreviewEditSettings.transitionSettingsArray[index].videoTransitionType = VideoTransition.NONE;
- mPreviewEditSettings.transitionSettingsArray[index].audioTransitionType = AudioTransition.NONE;
+ mPreviewEditSettings.transitionSettingsArray[index].videoTransitionType =
+ VideoTransition.NONE;
+ mPreviewEditSettings.transitionSettingsArray[index].audioTransitionType =
+ AudioTransition.NONE;
}
for (int clipCnt = 0; clipCnt < mPreviewEditSettings.clipSettingsArray.length; clipCnt++) {
if (mPreviewEditSettings.clipSettingsArray[clipCnt].fileType == FileType.JPG) {
err = generateClip(mPreviewEditSettings);
mProcessingState = PROCESSING_NONE;
} catch (IllegalArgumentException ex) {
- Log.e("MediaArtistNativeHelper", "IllegalArgument for generateClip");
+ Log.e(TAG, "IllegalArgument for generateClip");
throw ex;
} catch (IllegalStateException ex) {
- Log.e("MediaArtistNativeHelper", "IllegalStateExceptiont for generateClip");
+ Log.e(TAG, "IllegalStateExceptiont for generateClip");
throw ex;
} catch (RuntimeException ex) {
- Log.e("MediaArtistNativeHelper", "RuntimeException for generateClip");
+ Log.e(TAG, "RuntimeException for generateClip");
throw ex;
}
if (err != 0) {
- Log.e("MediaArtistNativeHelper", "RuntimeException for generateClip");
- throw new RuntimeException("generateClip failed with error="+err );
+ Log.e(TAG, "RuntimeException for generateClip");
+ throw new RuntimeException("generateClip failed with error=" + err);
}
- mExportDone = true;
mExportProgressListener = null;
}
/**
- * This method is responsible for exporting a movie
- *
- * @param filePath The output file path
- * @param projectDir The output project directory
- * @param height The height of clip
- * @param bitrate The bitrate at which the movie should be exported
- * @param audioCodec The audio codec to use
- * @param videoCodec The video codec to use
- * @param mediaItemsList The media items list
- * @param mediaTransitionList The transitons list
- * @param mediaBGMList The background track list
- * @param listener The ExportProgressListener
+ * This methods takes care of stopping the Export process
*
+ * @param The input file name for which export has to be stopped
*/
- public void export(String filePath, String projectDir,int height,int bitrate,
- int audioCodec,int videoCodec,List<MediaItem> mediaItemsList,
- List<Transition> mediaTransitionList,List<AudioTrack> mediaBGMList,
- ExportProgressListener listener) {
-
- int outBitrate = 0;
- mExportFilename = filePath;
- previewStoryBoard(mediaItemsList, mediaTransitionList, mediaBGMList,null);
- mExportProgressListener = listener;
-
- mProgressToApp = 0;
-
- switch (bitrate) {
- case MediaProperties.BITRATE_28K:
- outBitrate = Bitrate.BR_32_KBPS;
- break;
- case MediaProperties.BITRATE_40K:
- outBitrate = Bitrate.BR_48_KBPS;
- break;
- case MediaProperties.BITRATE_64K:
- outBitrate = Bitrate.BR_64_KBPS;
- break;
- case MediaProperties.BITRATE_96K:
- outBitrate = Bitrate.BR_96_KBPS;
- break;
- case MediaProperties.BITRATE_128K:
- outBitrate = Bitrate.BR_128_KBPS;
- break;
- case MediaProperties.BITRATE_192K:
- outBitrate = Bitrate.BR_192_KBPS;
- break;
- case MediaProperties.BITRATE_256K:
- outBitrate = Bitrate.BR_256_KBPS;
- break;
- case MediaProperties.BITRATE_384K:
- outBitrate = Bitrate.BR_384_KBPS;
- break;
- case MediaProperties.BITRATE_512K:
- outBitrate = Bitrate.BR_512_KBPS;
- break;
- case MediaProperties.BITRATE_800K:
- outBitrate = Bitrate.BR_800_KBPS;
- break;
- case MediaProperties.BITRATE_2M:
- outBitrate = Bitrate.BR_2_MBPS;
- break;
- case MediaProperties.BITRATE_5M:
- outBitrate = Bitrate.BR_5_MBPS;
- break;
- case MediaProperties.BITRATE_8M:
- outBitrate = Bitrate.BR_8_MBPS;
- break;
-
- default:
- throw new IllegalArgumentException("Argument Bitrate incorrect");
- }
- mPreviewEditSettings.videoFrameRate = VideoFrameRate.FR_30_FPS;
- mPreviewEditSettings.outputFile = mOutputFilename = filePath;
-
- int aspectRatio = mVideoEditor.getAspectRatio();
- mPreviewEditSettings.videoFrameSize = findVideoResolution(aspectRatio, height);
- switch (audioCodec) {
- case MediaProperties.ACODEC_AAC_LC:
- mPreviewEditSettings.audioFormat = AudioFormat.AAC;
- break;
- case MediaProperties.ACODEC_AMRNB:
- mPreviewEditSettings.audioFormat = AudioFormat.AMR_NB;
- break;
- }
-
- switch (videoCodec) {
- case MediaProperties.VCODEC_H263:
- mPreviewEditSettings.videoFormat = VideoFormat.H263;
- break;
- case MediaProperties.VCODEC_H264BP:
- mPreviewEditSettings.videoFormat = VideoFormat.H264;
- break;
- case MediaProperties.VCODEC_MPEG4:
- mPreviewEditSettings.videoFormat = VideoFormat.MPEG4;
- break;
- }
-
- mPreviewEditSettings.audioSamplingFreq = AudioSamplingFrequency.FREQ_32000;
- mPreviewEditSettings.maxFileSize = 0;
- mPreviewEditSettings.audioChannels = 2;
- mPreviewEditSettings.videoBitrate = outBitrate;
- mPreviewEditSettings.audioBitrate = Bitrate.BR_96_KBPS;
-
- mPreviewEditSettings.transitionSettingsArray =
- new TransitionSettings[mTotalClips - 1];
- for (int index = 0; index < mTotalClips - 1; index++) {
- mPreviewEditSettings.transitionSettingsArray[index] =
- new TransitionSettings();
- mPreviewEditSettings.transitionSettingsArray[index].videoTransitionType =
- VideoTransition.NONE;
- mPreviewEditSettings.transitionSettingsArray[index].audioTransitionType =
- AudioTransition.NONE;
- }
- for (int clipCnt = 0; clipCnt < mPreviewEditSettings.clipSettingsArray.length; clipCnt++) {
- if (mPreviewEditSettings.clipSettingsArray[clipCnt].fileType == FileType.JPG) {
- mPreviewEditSettings.clipSettingsArray[clipCnt].clipPath =
- mPreviewEditSettings.clipSettingsArray[clipCnt].clipOriginalPath;
- }
- }
- nativePopulateSettings(mPreviewEditSettings, mClipProperties, mAudioSettings);
-
- int err = 0;
+ void stop(String filename) {
try {
- mProcessingState = PROCESSING_EXPORT;
- mProcessingObject = null;
- err = generateClip(mPreviewEditSettings);
- mProcessingState = PROCESSING_NONE;
- } catch (IllegalArgumentException ex) {
- Log.e("MediaArtistNativeHelper", "IllegalArgument for generateClip");
- throw ex;
+ stopEncoding();
+ new File(mExportFilename).delete();
} catch (IllegalStateException ex) {
- Log.e("MediaArtistNativeHelper", "IllegalStateExceptiont for generateClip");
+ Log.e(TAG, "Illegal state exception in unload settings");
throw ex;
} catch (RuntimeException ex) {
- Log.e("MediaArtistNativeHelper", "RuntimeException for generateClip");
+ Log.e(TAG, "Runtime exception in unload settings");
throw ex;
}
-
- if (err != 0) {
- Log.e("MediaArtistNativeHelper", "RuntimeException for generateClip");
- throw new RuntimeException("generateClip failed with error="+err );
- }
-
- mExportDone = true;
- mExportProgressListener = null;
- }
-
-
- /**
- * This methods takes care of stopping the Export process
- *
- * @param The input file name for which export has to be stopped
- */
- public void stop(String filename) {
- if (!mExportDone) {
- try {
- stopEncoding();
- } catch (IllegalStateException ex) {
- Log.e("MediaArtistNativeHelper", "Illegal state exception in unload settings");
- throw ex;
- } catch (RuntimeException ex) {
- Log.e("MediaArtistNativeHelper", "Runtime exception in unload settings");
- throw ex;
- }
-
- new File(mExportFilename).delete();
- }
}
/**
* @param inputFile The inputFile
* @param width The width of the output frame
* @param height The height of the output frame
- * @param timeMS The time in ms at which the frame hass to be extracted
+ * @param timeMS The time in ms at which the frame has to be extracted
*/
- public Bitmap getPixels(String inputFile, int width, int height, long timeMS) {
+ Bitmap getPixels(String inputFile, int width, int height, long timeMS) {
if (inputFile == null) {
throw new IllegalArgumentException();
}
/* Create a canvas to resize */
final Canvas canvas = new Canvas(bitmap);
canvas.drawBitmap(tempBitmap, new Rect(0, 0, newWidth, newHeight),
- new Rect(0, 0, width, height),
- sResizePaint);
+ new Rect(0, 0, width, height), sResizePaint);
}
if (tempBitmap != null) {
}
int i = 0;
int deltaTime = (int)(endMs - startMs) / thumbnailCount;
- Bitmap[] bitmap = null;
+ Bitmap[] bitmaps = null;
try {
// This may result in out of Memory Error
rgb888 = new int[thumbnailSize * thumbnailCount];
- bitmap = new Bitmap[thumbnailCount];
+ bitmaps = new Bitmap[thumbnailCount];
} catch (Throwable e) {
// Allocating to new size with Fixed count
try {
System.gc();
rgb888 = new int[thumbnailSize * MAX_THUMBNAIL_PERMITTED];
- bitmap = new Bitmap[MAX_THUMBNAIL_PERMITTED];
+ bitmaps = new Bitmap[MAX_THUMBNAIL_PERMITTED];
thumbnailCount = MAX_THUMBNAIL_PERMITTED;
} catch (Throwable ex) {
throw new RuntimeException("Memory allocation fails, thumbnail count too large: "+thumbnailCount);
}
}
IntBuffer tmpBuffer = IntBuffer.allocate(thumbnailSize);
- nativeGetPixelsList(filename, rgb888, newWidth, newHeight, deltaTime, thumbnailCount, startMs,
- endMs);
+ nativeGetPixelsList(filename, rgb888, newWidth, newHeight, deltaTime, thumbnailCount,
+ startMs, endMs);
for (; i < thumbnailCount; i++) {
- bitmap[i] = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+ bitmaps[i] = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
tmpBuffer.put(rgb888, (i * thumbnailSize), thumbnailSize);
tmpBuffer.rewind();
if ((newWidth == width) && (newHeight == height)) {
- bitmap[i].copyPixelsFromBuffer(tmpBuffer);
+ bitmaps[i].copyPixelsFromBuffer(tmpBuffer);
} else {
/* Copy the out rgb buffer to temp bitmap */
tempBitmap.copyPixelsFromBuffer(tmpBuffer);
/* Create a canvas to resize */
- final Canvas canvas = new Canvas(bitmap[i]);
+ final Canvas canvas = new Canvas(bitmaps[i]);
canvas.drawBitmap(tempBitmap, new Rect(0, 0, newWidth, newHeight),
- new Rect(0, 0, width, height),
- sResizePaint);
+ new Rect(0, 0, width, height), sResizePaint);
}
}
if (tempBitmap != null) {
tempBitmap.recycle();
}
- return bitmap;
+ return bitmaps;
}
/**
* @param isVideo The flag to indicate if the file is video file or not
*
**/
- public void generateAudioGraph(String uniqueId, String inFileName, String OutAudiGraphFileName,
+ void generateAudioGraph(String uniqueId, String inFileName, String OutAudiGraphFileName,
int frameDuration, int audioChannels, int samplesCount,
ExtractAudioWaveformProgressListener listener, boolean isVideo) {
String tempPCMFileName;
mExtractAudioWaveformProgressListener = listener;
/**
- * in case of Video , first call will generate the PCM file to make the
+ * In case of Video, first call will generate the PCM file to make the
* audio graph
*/
if (isVideo) {
} else {
tempPCMFileName = mAudioTrackPCMFilePath;
}
+
/**
* For Video item, generate the PCM
*/
nativeGenerateAudioGraph(tempPCMFileName, OutAudiGraphFileName, frameDuration,
audioChannels, samplesCount);
- /* once the audio graph file is generated, delete the pcm file */
+ /**
+ * Once the audio graph file is generated, delete the pcm file
+ */
if (isVideo) {
new File(tempPCMFileName).delete();
}
}
- public void clearPreviewSurface(Surface surface) {
- nativeClearSurface(surface);
+ void clearPreviewSurface(Surface surface) {
+ nativeClearSurface(surface);
+ }
+
+ /**
+ * Grab the semaphore which arbitrates access to the editor
+ *
+ * @throws InterruptedException
+ */
+ void lock() throws InterruptedException {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "lock: grabbing semaphore", new Throwable());
+ }
+ mLock.acquire();
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "lock: grabbed semaphore");
+ }
+ }
+
+ /**
+ * Release the semaphore which arbitrates access to the editor
+ */
+ void unlock() {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "unlock: releasing semaphore");
+ }
+ mLock.release();
}
/** Native Methods */
native Properties getMediaProperties(String file) throws IllegalArgumentException,
- IllegalStateException, RuntimeException, Exception;
+ IllegalStateException, RuntimeException, Exception;
/**
* Get the version of ManualEdit.
* Returns the video thumbnail in an array of integers. Output format is
* ARGB8888.
*
- * @param pixelArray the array that receives the pixelvalues
+ * @param pixelArray the array that receives the pixel values
* @param width width of the video thumbnail
* @param height height of the video thumbnail
* @param timeMS desired time of the thumbnail in ms
*/
private native void nativeClearSurface(Surface surface);
-
/**
* Stops the encoding. This method should only be called after encoding has
* started using method <code> startEncoding</code>
private native void stopEncoding() throws IllegalStateException, RuntimeException;
-
private native void _init(String tempPath, String libraryPath)
throws IllegalArgumentException, IllegalStateException, RuntimeException;
int callbackAfterFrameCount, boolean loop) throws IllegalArgumentException,
IllegalStateException, RuntimeException;
- private native void nativePopulateSettings(EditSettings mEditSettings,
+ private native void nativePopulateSettings(EditSettings editSettings,
PreviewClipProperties mProperties, AudioSettings mAudioSettings)
throws IllegalArgumentException, IllegalStateException, RuntimeException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.Semaphore;
-
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
+import android.graphics.Bitmap;
import android.graphics.Rect;
import android.util.Log;
import android.util.Xml;
import android.view.Surface;
import android.view.SurfaceHolder;
-import android.graphics.Bitmap;
-
/**
* The VideoEditor implementation {@hide}
*/
* The project filename
*/
private static final String PROJECT_FILENAME = "videoeditor.xml";
- /*
- * Semaphore to control preview calls
- */
- final Semaphore mPreviewSemaphore = new Semaphore(1, true);
-
- /*
- * Semaphore to control export calls
- */
- final Semaphore mExportSemaphore = new Semaphore(1, true);
/*
* XML tags
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 TAG_OVERLAY_USER_ATTRIBUTES = "overlay_user_attributes";
private static final String TAG_EFFECTS = "effects";
private static final String TAG_EFFECT = "effect";
private static final String TAG_AUDIO_TRACKS = "audio_tracks";
private static final String ATTR_AUDIO_WAVEFORM_FILENAME = "waveform";
private static final String ATTR_RENDERING_MODE = "rendering_mode";
private static final String ATTR_ASPECT_RATIO = "aspect_ratio";
- private static final String ATTR_PREVIEW_PREPARE = "preview_prepare_invalid";
private static final String ATTR_REGENERATE_PCM = "regeneratePCMFlag";
private static final String ATTR_TYPE = "type";
private static final String ATTR_DURATION = "duration";
private static final String ATTR_DUCK_ENABLED = "ducking_enabled";
private static final String ATTR_DUCK_THRESHOLD = "ducking_threshold";
private static final String ATTR_DUCKED_TRACK_VOLUME = "ducking_volume";
- private static final String ATTR_GENERATED_IMAGE_CLIP =
- "generated_image_clip";
- private static final String ATTR_GENERATED_TRANSITION_CLIP =
- "generated_transition_clip";
- private static final String ATTR_IS_TRANSITION_GENERATED =
- "is_transition_generated";
- private static final String ATTR_OVERLAY_RGB_FILENAME =
- "overlay_rgb_filename";
- private static final String ATTR_OVERLAY_FRAME_WIDTH =
- "overlay_frame_width";
- private static final String ATTR_OVERLAY_FRAME_HEIGHT =
- "overlay_frame_height";
+ private static final String ATTR_GENERATED_IMAGE_CLIP = "generated_image_clip";
+ private static final String ATTR_GENERATED_TRANSITION_CLIP = "generated_transition_clip";
+ private static final String ATTR_IS_TRANSITION_GENERATED = "is_transition_generated";
+ private static final String ATTR_OVERLAY_RGB_FILENAME = "overlay_rgb_filename";
+ private static final String ATTR_OVERLAY_FRAME_WIDTH = "overlay_frame_width";
+ private static final String ATTR_OVERLAY_FRAME_HEIGHT = "overlay_frame_height";
/*
* Instance variables
* Private Object for calling native Methods via MediaArtistNativeHelper
*/
private MediaArtistNativeHelper mMANativeHelper;
- private VideoEditor veObject = null;
private boolean mPreviewInProgress = false;
/**
* related to the project
*/
public VideoEditorImpl(String projectPath) throws IOException {
-
mMANativeHelper = new MediaArtistNativeHelper(projectPath, this);
mProjectPath = projectPath;
final File projectXml = new File(projectPath, PROJECT_FILENAME);
if (audioTrack == null) {
throw new IllegalArgumentException("Audio Track is null");
}
+
if (mAudioTracks.size() == 1) {
throw new IllegalArgumentException("No more tracks can be added");
}
/*
* Form the audio PCM file path
*/
- String audioTrackPCMFilePath = String.format(mProjectPath + "/"
+ final String audioTrackPCMFilePath = String.format(mProjectPath + "/"
+ "AudioPcm" + audioTrack.getId() + ".pcm");
/*
* Create PCM only if not generated in previous session
*/
- if (new File(audioTrackPCMFilePath).exists())
- {
+ if (new File(audioTrackPCMFilePath).exists()) {
mMANativeHelper.setAudioflag(false);
}
+
mMANativeHelper.setGeneratePreview(true);
}
* Add the Media item to MediaItem list
*/
if (mMediaItems.contains(mediaItem)) {
- throw new IllegalArgumentException("Media item already exists: " +
- mediaItem.getId());
+ throw new IllegalArgumentException("Media item already exists: " + mediaItem.getId());
}
/*
* Invalidate the end transition if necessary
*/
final int mediaItemsCount = mMediaItems.size();
- if ( mediaItemsCount > 0) {
+ if (mediaItemsCount > 0) {
removeTransitionAfter(mediaItemsCount - 1);
}
if (transition == null) {
throw new IllegalArgumentException("Null Transition");
}
+
final MediaItem beforeMediaItem = transition.getBeforeMediaItem();
final MediaItem afterMediaItem = transition.getAfterMediaItem();
/*
if (mMediaItems == null) {
throw new IllegalArgumentException("No media items are added");
}
- if ((afterMediaItem != null) && (beforeMediaItem != null)) {
- int afterMediaItemIndex = mMediaItems.indexOf(afterMediaItem);
- int beforeMediaItemIndex = mMediaItems.indexOf(beforeMediaItem);
+ if ((afterMediaItem != null) && (beforeMediaItem != null)) {
+ final int afterMediaItemIndex = mMediaItems.indexOf(afterMediaItem);
+ final int beforeMediaItemIndex = mMediaItems.indexOf(beforeMediaItem);
if ((afterMediaItemIndex == -1) || (beforeMediaItemIndex == -1)) {
throw new IllegalArgumentException
("Either of the mediaItem is not found in the list");
}
+
if (afterMediaItemIndex != (beforeMediaItemIndex - 1) ) {
throw new IllegalArgumentException("MediaItems are not in sequence");
}
case MediaProperties.ACODEC_AMRNB:
break;
- default :
+ default: {
String message = "Unsupported audio codec type " + audioCodec;
throw new IllegalArgumentException(message);
+ }
}
switch (videoCodec) {
case MediaProperties.VCODEC_MPEG4:
break;
- default :
+ default: {
String message = "Unsupported video codec type " + videoCodec;
throw new IllegalArgumentException(message);
+ }
}
export(filename, height, bitrate, listener);
*/
public void export(String filename, int height, int bitrate,
ExportProgressListener listener) throws IOException {
- if ( filename == null) {
+ if (filename == null) {
throw new IllegalArgumentException("export: filename is null");
}
- File tempPathFile = new File(filename);
+
+ final File tempPathFile = new File(filename);
if (tempPathFile == null) {
throw new IOException(filename + "can not be created");
}
+
if (mMediaItems.size() == 0) {
throw new IllegalStateException("No MediaItems added");
}
case MediaProperties.HEIGHT_720:
break;
- default:
+ default: {
String message = "Unsupported height value " + height;
throw new IllegalArgumentException(message);
+ }
}
+
switch (bitrate) {
case MediaProperties.BITRATE_28K:
break;
case MediaProperties.BITRATE_8M:
break;
- default:
+ default: {
final String message = "Unsupported bitrate value " + bitrate;
throw new IllegalArgumentException(message);
+ }
}
+ boolean semAcquireDone = false;
try {
- mExportSemaphore.acquire();
+ mMANativeHelper.lock();
+ semAcquireDone = true;
mMANativeHelper.export(filename, mProjectPath, height,bitrate,
- mMediaItems, mTransitions, mAudioTracks,
- listener);
+ mMediaItems, mTransitions, mAudioTracks, listener);
} catch (InterruptedException ex) {
Log.e(TAG, "Sem acquire NOT successful in export");
} finally {
- mExportSemaphore.release();
+ if (semAcquireDone) {
+ mMANativeHelper.unlock();
+ }
}
}
public void generatePreview(MediaProcessingProgressListener listener) {
boolean semAcquireDone = false;
try {
- mPreviewSemaphore.acquire();
+ mMANativeHelper.lock();
semAcquireDone = true;
- mMANativeHelper.setGeneratePreview(true);
+
if ((mMediaItems.size() > 0) || (mAudioTracks.size() > 0)) {
- mMANativeHelper.previewStoryBoard(mMediaItems, mTransitions,
- mAudioTracks, listener);
+ mMANativeHelper.previewStoryBoard(mMediaItems, mTransitions, mAudioTracks,
+ listener);
}
} catch (InterruptedException ex) {
Log.e(TAG, "Sem acquire NOT successful in previewStoryBoard");
} finally {
if (semAcquireDone) {
- mPreviewSemaphore.release();
+ mMANativeHelper.unlock();
}
}
}
if (afterAudioTrackId == null) {
mAudioTracks.add(0, audioTrack);
+ mMANativeHelper.setGeneratePreview(true);
} 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);
return;
}
}
- throw new IllegalArgumentException("AudioTrack not found: "
- + afterAudioTrackId);
+
+ throw new IllegalArgumentException("AudioTrack not found: " + afterAudioTrackId);
}
- mMANativeHelper.setGeneratePreview(true);
}
/*
* {@inheritDoc}
*/
- public synchronized void insertMediaItem(MediaItem mediaItem,
- String afterMediaItemId) {
+ public synchronized void insertMediaItem(MediaItem mediaItem, String afterMediaItemId) {
if (mMediaItems.contains(mediaItem)) {
- throw new IllegalArgumentException("Media item already exists: "
- + mediaItem.getId());
+ throw new IllegalArgumentException("Media item already exists: " + mediaItem.getId());
}
if (afterMediaItemId == null) {
*/
removeTransitionBefore(0);
}
+
mMediaItems.add(0, mediaItem);
computeTimelineDuration();
generateProjectThumbnail();
+ mMANativeHelper.setGeneratePreview(true);
} else {
final int mediaItemCount = mMediaItems.size();
for (int i = 0; i < mediaItemCount; i++) {
return;
}
}
- throw new IllegalArgumentException("MediaItem not found: "
- + afterMediaItemId);
+
+ throw new IllegalArgumentException("MediaItem not found: " + afterMediaItemId);
}
- mMANativeHelper.setGeneratePreview(true);
}
/*
* {@inheritDoc}
*/
- public synchronized void moveAudioTrack(String audioTrackId,
- String afterAudioTrackId) {
+ public synchronized void moveAudioTrack(String audioTrackId, String afterAudioTrackId) {
throw new IllegalStateException("Not supported");
}
/*
* {@inheritDoc}
*/
- public synchronized void moveMediaItem(String mediaItemId,
- String afterMediaItemId) {
+ public synchronized void moveMediaItem(String mediaItemId, String afterMediaItemId) {
final MediaItem moveMediaItem = removeMediaItem(mediaItemId,true);
if (moveMediaItem == null) {
- throw new IllegalArgumentException("Target MediaItem not found: "
- + mediaItemId);
+ throw new IllegalArgumentException("Target MediaItem not found: " + mediaItemId);
}
if (afterMediaItemId == null) {
*/
mMediaItems.add(0, moveMediaItem);
computeTimelineDuration();
+ mMANativeHelper.setGeneratePreview(true);
+
generateProjectThumbnail();
} else {
throw new IllegalStateException("Cannot move media item (it is the only item)");
}
}
- throw new IllegalArgumentException("MediaItem not found: "
- + afterMediaItemId);
+ throw new IllegalArgumentException("MediaItem not found: " + afterMediaItemId);
}
- mMANativeHelper.setGeneratePreview(true);
}
/*
mAudioTracks.clear();
mTransitions.clear();
mMANativeHelper.releaseNativeHelper();
- if (mMANativeHelper!= null)
- mMANativeHelper = null;
- if (veObject != null)
- veObject= null;
+ mMANativeHelper = null;
}
/*
* {@inheritDoc}
*/
public synchronized void removeAllMediaItems() {
+ mMANativeHelper.setGeneratePreview(true);
+
mMediaItems.clear();
/**
mTransitions.clear();
mDurationMs = 0;
- mMANativeHelper.setGeneratePreview(true);
/**
* If a thumbnail already exists, then delete it
*/
audioTrack.invalidate();
mMANativeHelper.invalidatePcmFile();
mMANativeHelper.setAudioflag(true);
- }
- else {
+ mMANativeHelper.setGeneratePreview(true);
+ } else {
throw new IllegalArgumentException(" No more audio tracks");
}
- mMANativeHelper.setGeneratePreview(true);
return audioTrack;
}
final String firstItemString = mMediaItems.get(0).getId();
final MediaItem mediaItem = getMediaItem(mediaItemId);
if (mediaItem != null) {
+ mMANativeHelper.setGeneratePreview(true);
/**
* Remove the media item
*/
removeAdjacentTransitions(mediaItem);
computeTimelineDuration();
}
- mMANativeHelper.setGeneratePreview(true);
+
/**
* If string equals first mediaItem, then
- * generate Project thumbail
+ * generate Project thumbnail
*/
if (firstItemString.equals(mediaItemId)) {
generateProjectThumbnail();
final MediaItem mediaItem = getMediaItem(mediaItemId);
if (mediaItem != null) {
+ mMANativeHelper.setGeneratePreview(true);
/**
* Remove the media item
*/
removeAdjacentTransitions(mediaItem);
computeTimelineDuration();
}
- mMANativeHelper.setGeneratePreview(true);
/**
* If string equals first mediaItem, then
public synchronized Transition removeTransition(String transitionId) {
final Transition transition = getTransition(transitionId);
if (transition == null) {
- throw new IllegalStateException("Transition not found: "
- + transitionId);
+ throw new IllegalStateException("Transition not found: " + transitionId);
}
+ mMANativeHelper.setGeneratePreview(true);
+
/**
* Remove the transition references
*/
mTransitions.remove(transition);
transition.invalidate();
computeTimelineDuration();
- mMANativeHelper.setGeneratePreview(true);
return transition;
}
*/
public long renderPreviewFrame(SurfaceHolder surfaceHolder, long timeMs,
OverlayData overlayData) {
- long result = 0;
- int surfaceWidth = 0;
- int surfaceHeight = 0;
- Rect frame;
-
if (surfaceHolder == null) {
throw new IllegalArgumentException("Surface Holder is null");
}
+ final Surface surface = surfaceHolder.getSurface();
+ if (surface == null) {
+ throw new IllegalArgumentException("Surface could not be retrieved from Surface holder");
+ }
+
if (timeMs < 0) {
throw new IllegalArgumentException("requested time not correct");
} else if (timeMs > mDurationMs) {
throw new IllegalArgumentException("requested time more than duration");
}
- if (mMANativeHelper != null) {
- if (mMANativeHelper.mInvalidatePreviewArray) {
- return -1;
- }
- }
- else {
- return -1;
- }
- boolean semAcquireDone = false;
- try{
- mPreviewSemaphore.acquire();
- semAcquireDone = true;
- Surface surface = surfaceHolder.getSurface();
- frame = surfaceHolder.getSurfaceFrame();
- surfaceWidth = frame.width();
- surfaceHeight = frame.height();
+ long result = 0;
- if (surface == null) {
- throw new RuntimeException("Surface could not be retrieved from Surface holder");
- }
+ boolean semAcquireDone = false;
+ try {
+ mMANativeHelper.lock();
+ semAcquireDone = true;
- if (!mMANativeHelper.mInvalidatePreviewArray) {
- if (mMediaItems.size() > 0) {
- result = mMANativeHelper.renderPreviewFrame(surface,
- timeMs,surfaceWidth,surfaceHeight, overlayData);
- }
- else {
- result = 0;
- }
- }
- else {
- result = -1;
+ if (mMediaItems.size() > 0) {
+ final Rect frame = surfaceHolder.getSurfaceFrame();
+ result = mMANativeHelper.renderPreviewFrame(surface,
+ timeMs, frame.width(), frame.height(), overlayData);
+ } else {
+ result = 0;
}
-
} catch (InterruptedException ex) {
Log.e(TAG, "Sem acquire NOT successful in renderPreviewFrame");
- }
- finally {
+ } finally {
if (semAcquireDone) {
- mPreviewSemaphore.release();
+ mMANativeHelper.unlock();
}
}
+
return result;
}
mAspectRatio =
Integer.parseInt(parser.getAttributeValue("",
ATTR_ASPECT_RATIO));
- final boolean mInvalidatePreviewArray =
- Boolean.parseBoolean(parser.getAttributeValue("",
- ATTR_PREVIEW_PREPARE));
- mMANativeHelper.setGeneratePreview(mInvalidatePreviewArray);
final boolean mRegenPCM =
Boolean.parseBoolean(parser.getAttributeValue("",
final String transitionFile = parser.getAttributeValue("",
ATTR_GENERATED_TRANSITION_CLIP);
- if (new File(transitionFile).exists() == true) {
+ if (new File(transitionFile).exists()) {
transition.setFilename(transitionFile);
} else {
transition.setFilename(null);
serializer.startTag("", TAG_PROJECT);
serializer.attribute("",
ATTR_ASPECT_RATIO, Integer.toString(mAspectRatio));
- serializer.attribute("", ATTR_PREVIEW_PREPARE,
- Boolean.toString(mMANativeHelper.getGeneratePreview()));
serializer.attribute("", ATTR_REGENERATE_PCM,
Boolean.toString(mMANativeHelper.getAudioflag()));
if (surfaceHolder == null) {
throw new IllegalArgumentException();
}
+
+ final Surface surface = surfaceHolder.getSurface();
+ if (surface == null) {
+ throw new IllegalArgumentException("Surface could not be retrieved from surface holder");
+ }
+
if (listener == null) {
throw new IllegalArgumentException();
}
+
if (fromMs >= mDurationMs) {
- throw new IllegalArgumentException("requested time not correct");
+ throw new IllegalArgumentException("Requested time not correct");
}
if (fromMs < 0) {
- throw new IllegalArgumentException("requested time not correct");
+ throw new IllegalArgumentException("Requested time not correct");
}
boolean semAcquireDone = false;
try{
- mPreviewSemaphore.acquire();
+ mMANativeHelper.lock();
semAcquireDone = true;
- } catch (InterruptedException ex) {
- Log.e(TAG, "Sem acquire NOT successful in startPreview");
- }
-
- if (semAcquireDone) {
- Surface mSurface = surfaceHolder.getSurface();
-
- if (mSurface == null) {
- throw new RuntimeException("Surface could not be retrieved from surface holder");
- }
if (mMediaItems.size() > 0) {
- try {
- mMANativeHelper.previewStoryBoard(mMediaItems, mTransitions,
- mAudioTracks, null);
- mMANativeHelper.doPreview(mSurface, fromMs, toMs, loop,
- callbackAfterFrameCount, listener);
- mPreviewInProgress = true;
- } catch (IllegalArgumentException ex) {
- mPreviewSemaphore.release();
- Log.e(TAG, "Illegal Argument exception in do preview");
- throw ex;
- } catch (IllegalStateException ex) {
- mPreviewSemaphore.release();
- Log.e(TAG, "Illegal State exception in do preview");
- throw ex;
- } catch (RuntimeException ex) {
- mPreviewSemaphore.release();
- Log.e(TAG, "Runtime exception in do preview");
- throw ex;
- }
+ mMANativeHelper.previewStoryBoard(mMediaItems, mTransitions,
+ mAudioTracks, null);
+ mMANativeHelper.doPreview(surface, fromMs, toMs, loop,
+ callbackAfterFrameCount, listener);
+ mPreviewInProgress = true;
}
/**
* release on complete by calling stopPreview
*/
+ } catch (InterruptedException ex) {
+ Log.e(TAG, "Sem acquire NOT successful in startPreview");
+ } catch (IllegalArgumentException ex) {
+ Log.e(TAG, "Illegal Argument exception in do preview");
+ throw ex;
+ } catch (IllegalStateException ex) {
+ Log.e(TAG, "Illegal State exception in do preview");
+ throw ex;
+ } catch (RuntimeException ex) {
+ Log.e(TAG, "Runtime exception in do preview");
+ throw ex;
+ } finally {
+ if (semAcquireDone) {
+ mMANativeHelper.unlock();
+ }
}
}
/**
* release the sem acquired in startPreview
*/
- mPreviewSemaphore.release();
+ mMANativeHelper.unlock();
return result;
- }
- else {
+ } else {
return 0;
}
}
Transition t = it.next();
if (t.getBeforeMediaItem() == mediaItem) {
it.remove();
+ mMANativeHelper.setGeneratePreview(true);
t.invalidate();
mediaItem.setBeginTransition(null);
if (index > 0) {
Transition t = it.next();
if (t.getAfterMediaItem() == mediaItem) {
it.remove();
+ mMANativeHelper.setGeneratePreview(true);
t.invalidate();
mediaItem.setEndTransition(null);
/**
if (mMediaItems.size() > 0) {
MediaItem mI = mMediaItems.get(0);
/*
- * Lets initialiZe the width for default aspect ratio i.e 16:9
+ * Lets initialize the width for default aspect ratio i.e 16:9
*/
int height = 480;
int width = 854;
switch (mI.getAspectRatio()) {
case MediaProperties.ASPECT_RATIO_3_2:
- width = 720;
+ width = 720;
break;
case MediaProperties.ASPECT_RATIO_4_3:
- width = 640;
+ width = 640;
break;
case MediaProperties.ASPECT_RATIO_5_3:
- width = 800;
+ width = 800;
break;
case MediaProperties.ASPECT_RATIO_11_9:
- width = 586;
+ width = 586;
break;
case MediaProperties.ASPECT_RATIO_16_9:
case MediaProperties.ASPECT_RATIO_UNDEFINED:
try {
projectBitmap = mI.getThumbnail(width, height, 500);
} catch (IllegalArgumentException e) {
- throw new IllegalArgumentException ("Illegal Argument Error creating project thumbnail");
+ throw new IllegalArgumentException ("Illegal argument error creating project thumbnail");
} catch (IOException e) {
throw new IllegalArgumentException ("IO Error creating project thumbnail");
}
+
try {
FileOutputStream stream = new FileOutputStream(mProjectPath + "/"
+ THUMBNAIL_FILENAME);
stream.flush();
stream.close();
} catch (IOException e) {
-
throw new IllegalArgumentException ("Error creating project thumbnail");
} finally {
projectBitmap.recycle();
final Surface surface = surfaceHolder.getSurface();
if (surface == null) {
- throw new RuntimeException("Surface could not be retrieved from surface holder");
+ throw new IllegalArgumentException("Surface could not be retrieved from surface holder");
}
if (mMANativeHelper != null) {