diff options
Diffstat (limited to 'media')
14 files changed, 147 insertions, 261 deletions
diff --git a/media/java/android/media/MediaFile.java b/media/java/android/media/MediaFile.java index 66a93f04..381b77a 100644 --- a/media/java/android/media/MediaFile.java +++ b/media/java/android/media/MediaFile.java @@ -229,6 +229,12 @@ public class MediaFile { return sFileTypeMap.get(path.substring(lastDot + 1).toUpperCase()); } + public static boolean isMimeTypeMedia(String mimeType) { + int fileType = getFileTypeForMimeType(mimeType); + return isAudioFileType(fileType) || isVideoFileType(fileType) + || isImageFileType(fileType) || isPlayListFileType(fileType); + } + // generates a title based on file name public static String getFileTitle(String path) { // extract file name after last slash diff --git a/media/java/android/media/videoeditor/AudioTrack.java b/media/java/android/media/videoeditor/AudioTrack.java index 6303b9d..573208a 100755 --- a/media/java/android/media/videoeditor/AudioTrack.java +++ b/media/java/android/media/videoeditor/AudioTrack.java @@ -48,6 +48,8 @@ public class AudioTrack { // The audio waveform filename
private String mAudioWaveformFilename;
+ // The audio waveform data
+ private WaveformData mWaveformData;
/**
* An object of this type cannot be instantiated by using the default
@@ -103,6 +105,7 @@ public class AudioTrack { // The audio waveform file is generated later
mAudioWaveformFilename = null;
+ mWaveformData = null;
}
/**
@@ -161,6 +164,11 @@ public class AudioTrack { mDuckedTrackVolume = duckedTrackVolume;
mAudioWaveformFilename = audioWaveformFilename;
+ if (audioWaveformFilename != null) {
+ mWaveformData = new WaveformData(audioWaveformFilename);
+ } else {
+ mWaveformData = null;
+ }
}
/**
@@ -416,6 +424,7 @@ public class AudioTrack { throws IOException {
// TODO: Set mAudioWaveformFilename at the end once the extract is
// complete
+ mWaveformData = new WaveformData(mAudioWaveformFilename);
}
/**
@@ -431,10 +440,17 @@ public class AudioTrack { *
* @return the name of the file, null if the file does not exist
*/
- public String getAudioWaveformFilename() {
+ String getAudioWaveformFilename() {
return mAudioWaveformFilename;
}
+ /**
+ * @return The waveform data
+ */
+ public WaveformData getWaveformData() {
+ return mWaveformData;
+ }
+
/*
* {@inheritDoc}
*/
diff --git a/media/java/android/media/videoeditor/MediaVideoItem.java b/media/java/android/media/videoeditor/MediaVideoItem.java index 341bf8e..f09219d 100755 --- a/media/java/android/media/videoeditor/MediaVideoItem.java +++ b/media/java/android/media/videoeditor/MediaVideoItem.java @@ -46,6 +46,8 @@ public class MediaVideoItem extends MediaItem { private int mVolumePercentage;
private boolean mMuted;
private String mAudioWaveformFilename;
+ // The audio waveform data
+ private WaveformData mWaveformData;
/**
* An object of this type cannot be instantiated with a default constructor
@@ -115,6 +117,11 @@ public class MediaVideoItem extends MediaItem { mVolumePercentage = volumePercent;
mMuted = muted;
mAudioWaveformFilename = audioWaveformFilename;
+ if (audioWaveformFilename != null) {
+ mWaveformData = new WaveformData(audioWaveformFilename);
+ } else {
+ mWaveformData = null;
+ }
}
/**
@@ -286,6 +293,7 @@ public class MediaVideoItem extends MediaItem { public void extractAudioWaveform(ExtractAudioWaveformProgressListener listener)
throws IOException {
// TODO: Set mAudioWaveformFilename at the end once the export is complete
+ mWaveformData = new WaveformData(mAudioWaveformFilename);
}
/**
@@ -299,11 +307,18 @@ public class MediaVideoItem extends MediaItem { * @return the name of the file, null if the file has not been computed or
* if there is no Audio track in the mediaItem
*/
- public String getAudioWaveformFilename() {
+ String getAudioWaveformFilename() {
return mAudioWaveformFilename;
}
/**
+ * @return The waveform data
+ */
+ public WaveformData getWaveformData() {
+ return mWaveformData;
+ }
+
+ /**
* Set volume of the Audio track of this mediaItem
*
* @param volumePercent in %/. 100% means no change; 50% means half value, 200%
diff --git a/media/java/android/media/videoeditor/TransitionEndCurtainClosing.java b/media/java/android/media/videoeditor/TransitionEndCurtainClosing.java deleted file mode 100644 index b1c6bb5..0000000 --- a/media/java/android/media/videoeditor/TransitionEndCurtainClosing.java +++ /dev/null @@ -1,54 +0,0 @@ -/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.media.videoeditor;
-
-/**
- * This transition fades to black frame using curtain closing: A black image is
- * moved from top to bottom to cover the video. This transition is always
- * applied at the end of the movie. {@hide}
- */
-public class TransitionEndCurtainClosing extends Transition {
- /**
- * An object of this type cannot be instantiated by using the default
- * constructor
- */
- @SuppressWarnings("unused")
- private TransitionEndCurtainClosing() {
- this(null, null, 0, BEHAVIOR_LINEAR);
- }
-
- /**
- * Constructor.
- *
- * @param transitionId The transition id
- * @param afterMediaItem The transition is applied to the end of this
- * media item
- * @param durationMs duration of the transition in milliseconds
- * @param behavior The transition behavior
- */
- public TransitionEndCurtainClosing(String transitionId, MediaItem afterMediaItem,
- long duration, int behavior) {
- super(transitionId, afterMediaItem, null, duration, behavior);
- }
-
- /*
- * {@inheritDoc}
- */
- @Override
- void generate() {
- }
-}
diff --git a/media/java/android/media/videoeditor/TransitionEndFadeToBlack.java b/media/java/android/media/videoeditor/TransitionEndFadeToBlack.java deleted file mode 100755 index 5f913fc..0000000 --- a/media/java/android/media/videoeditor/TransitionEndFadeToBlack.java +++ /dev/null @@ -1,54 +0,0 @@ -/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.media.videoeditor;
-
-/**
- * This transition fades to black frame using fade out in a certain provided
- * duration. This transition is always applied at the end of the movie. {@hide
- * }
- */
-public class TransitionEndFadeToBlack extends Transition {
- /**
- * An object of this type cannot be instantiated by using the default
- * constructor
- */
- @SuppressWarnings("unused")
- private TransitionEndFadeToBlack() {
- this(null, null, 0, BEHAVIOR_LINEAR);
- }
-
- /**
- * Constructor.
- *
- * @param transitionId The transition id
- * @param afterMediaItem The transition is applied to the end of this
- * media item
- * @param durationMs duration of the transition in milliseconds
- * @param behavior The transition behavior
- */
- public TransitionEndFadeToBlack(String transitionId, MediaItem afterMediaItem, long duration,
- int behavior) {
- super(transitionId, afterMediaItem, null, duration, behavior);
- }
-
- /*
- * {@inheritDoc}
- */
- @Override
- void generate() {
- }
-}
diff --git a/media/java/android/media/videoeditor/TransitionFadeToBlack.java b/media/java/android/media/videoeditor/TransitionFadeBlack.java index 9569a65..a9bf4ce 100755 --- a/media/java/android/media/videoeditor/TransitionFadeToBlack.java +++ b/media/java/android/media/videoeditor/TransitionFadeBlack.java @@ -18,16 +18,17 @@ package android.media.videoeditor; /**
- * This class is used to render a fade to black transition between two videos.
+ * This class is used to render a fade to black and fade from black transition
+ * between two media items.
* {@hide}
*/
-public class TransitionFadeToBlack extends Transition {
+public class TransitionFadeBlack extends Transition {
/**
* An object of this type cannot be instantiated by using the default
* constructor
*/
@SuppressWarnings("unused")
- private TransitionFadeToBlack() {
+ private TransitionFadeBlack() {
this(null, null, null, 0, 0);
}
@@ -45,7 +46,7 @@ public class TransitionFadeToBlack extends Transition { *
* @throws IllegalArgumentException if behavior is not supported.
*/
- public TransitionFadeToBlack(String transitionId, MediaItem afterMediaItem,
+ public TransitionFadeBlack(String transitionId, MediaItem afterMediaItem,
MediaItem beforeMediaItem, long durationMs, int behavior) {
super(transitionId, afterMediaItem, beforeMediaItem, durationMs, behavior);
}
diff --git a/media/java/android/media/videoeditor/TransitionStartCurtainOpening.java b/media/java/android/media/videoeditor/TransitionStartCurtainOpening.java deleted file mode 100755 index b787b32..0000000 --- a/media/java/android/media/videoeditor/TransitionStartCurtainOpening.java +++ /dev/null @@ -1,56 +0,0 @@ -/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.media.videoeditor;
-
-
-/**
- * This transition fades from black frame using curtain opening. A black
- * image is displayed and moves from bottom to top making the video visible.
- * This transition is always applied at the beginning of the movie.
- * {@hide}
- */
-public class TransitionStartCurtainOpening extends Transition {
- /**
- * An object of this type cannot be instantiated by using the default
- * constructor
- */
- @SuppressWarnings("unused")
- private TransitionStartCurtainOpening() {
- this(null, null, 0, Transition.BEHAVIOR_LINEAR);
- }
-
- /**
- * Constructor
- *
- * @param transitionId The transition id
- * @param beforeMediaItem The transition is applied to the beginning of
- * this media item
- * @param durationMs The duration of the transition in milliseconds
- * @param behavior The transition behavior
- */
- public TransitionStartCurtainOpening(String transitionId, MediaItem beforeMediaItem,
- long durationMs, int behavior) {
- super(transitionId, null, beforeMediaItem, durationMs, behavior);
- }
-
- /*
- * {@inheritDoc}
- */
- @Override
- public void generate() {
- }
-}
diff --git a/media/java/android/media/videoeditor/TransitionStartFadeFromBlack.java b/media/java/android/media/videoeditor/TransitionStartFadeFromBlack.java deleted file mode 100644 index be993a5..0000000 --- a/media/java/android/media/videoeditor/TransitionStartFadeFromBlack.java +++ /dev/null @@ -1,54 +0,0 @@ -/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.media.videoeditor;
-
-/**
- * This transition fades from black using fade-in in a certain provided
- * duration. This transition is always applied at the beginning of the movie.
- * {@hide}
- */
-public class TransitionStartFadeFromBlack extends Transition {
- /**
- * An object of this type cannot be instantiated by using the default
- * constructor
- */
- @SuppressWarnings("unused")
- private TransitionStartFadeFromBlack() {
- this(null, null, 0, Transition.BEHAVIOR_LINEAR);
- }
-
- /**
- * Constructor
- *
- * @param transitionId The transition id
- * @param beforeMediaItem The transition is applied to the beginning of
- * this media item
- * @param durationMs The duration of the transition in milliseconds
- * @param behavior The transition behavior
- */
- public TransitionStartFadeFromBlack(String transitionId, MediaItem beforeMediaItem,
- long durationMs, int behavior) {
- super(transitionId, null, beforeMediaItem, durationMs, behavior);
- }
-
- /*
- * {@inheritDoc}
- */
- @Override
- public void generate() {
- }
-}
diff --git a/media/java/android/media/videoeditor/VideoEditorTestImpl.java b/media/java/android/media/videoeditor/VideoEditorTestImpl.java index 505b93e..ba84f49 100644 --- a/media/java/android/media/videoeditor/VideoEditorTestImpl.java +++ b/media/java/android/media/videoeditor/VideoEditorTestImpl.java @@ -892,13 +892,7 @@ public class VideoEditorTestImpl implements VideoEditor { } final Transition transition; - if (TransitionStartCurtainOpening.class.getSimpleName().equals(type)) { - transition = new TransitionStartCurtainOpening(transitionId, beforeMediaItem, - durationMs, behavior); - } else if (TransitionStartFadeFromBlack.class.getSimpleName().equals(type)) { - transition = new TransitionStartFadeFromBlack(transitionId, beforeMediaItem, - durationMs, behavior); - } else if (TransitionAlpha.class.getSimpleName().equals(type)) { + if (TransitionAlpha.class.getSimpleName().equals(type)) { final int blending = Integer.parseInt(parser.getAttributeValue("", ATTR_BLENDING)); final String maskFilename = parser.getAttributeValue("", ATTR_MASK); final boolean invert = Boolean.getBoolean(parser.getAttributeValue("", ATTR_INVERT)); @@ -911,15 +905,9 @@ public class VideoEditorTestImpl implements VideoEditor { final int direction = Integer.parseInt(parser.getAttributeValue("", ATTR_DIRECTION)); transition = new TransitionSliding(transitionId, afterMediaItem, beforeMediaItem, durationMs, behavior, direction); - } else if (TransitionFadeToBlack.class.getSimpleName().equals(type)) { - transition = new TransitionFadeToBlack(transitionId, afterMediaItem, beforeMediaItem, + } else if (TransitionFadeBlack.class.getSimpleName().equals(type)) { + transition = new TransitionFadeBlack(transitionId, afterMediaItem, beforeMediaItem, durationMs, behavior); - } else if (TransitionEndCurtainClosing.class.getSimpleName().equals(type)) { - transition = new TransitionEndCurtainClosing(transitionId, afterMediaItem, durationMs, - behavior); - } else if (TransitionEndFadeToBlack.class.getSimpleName().equals(type)) { - transition = new TransitionEndFadeToBlack(transitionId, afterMediaItem, durationMs, - behavior); } else { transition = null; } @@ -1132,17 +1120,14 @@ public class VideoEditorTestImpl implements VideoEditor { */ private void computeTimelineDuration() { mDurationMs = 0; - for (MediaItem mediaItem : mMediaItems) { + final int mediaItemsCount = mMediaItems.size(); + for (int i = 0; i < mediaItemsCount; i++) { + final MediaItem mediaItem = mMediaItems.get(i); mDurationMs += mediaItem.getTimelineDuration(); - } - - // Subtract the transition times - for (Transition transition : mTransitions) { - if (!(transition instanceof TransitionStartCurtainOpening) - && !(transition instanceof TransitionStartFadeFromBlack) - && !(transition instanceof TransitionEndFadeToBlack) - && !(transition instanceof TransitionEndCurtainClosing)) { - mDurationMs -= transition.getDuration(); + if (mediaItem.getEndTransition() != null) { + if (i < mediaItemsCount - 1) { + mDurationMs -= mediaItem.getEndTransition().getDuration(); + } } } } diff --git a/media/java/android/media/videoeditor/WaveformData.java b/media/java/android/media/videoeditor/WaveformData.java new file mode 100644 index 0000000..67789de --- /dev/null +++ b/media/java/android/media/videoeditor/WaveformData.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.media.videoeditor; + +/** + * Class which describes the waveform data of an audio track. The gain values + * represent the average gain for an audio frame. For audio codecs which do + * not operate on a per frame bases (eg. ALAW, ULAW) a reasonable audio frame + * duration will be assumed (eg. 50ms). + * {@hide} + */ +public class WaveformData { + // Instance variables + final int mFrameDurationMs; + final int mFramesCount; + final short[] mGains; + + /** + * This constructor shall not be used + */ + @SuppressWarnings("unused") + private WaveformData() { + mFrameDurationMs = 0; + mFramesCount = 0; + mGains = null; + } + + /** + * Constructor + * + * @param audioWaveformFilename The name of the audio waveform file + */ + WaveformData(String audioWaveformFilename) { + // TODO: Read these values from the file + mFrameDurationMs = 20; + mFramesCount = 300000 / mFrameDurationMs; + mGains = new short[mFramesCount]; + for (int i = 0; i < mFramesCount; i++) { + mGains[i] = (short)((i * 5) % 256); + } + } + + /** + * @return The duration of a frame in milliseconds + */ + public int getFrameDuration() { + return mFrameDurationMs; + } + + /** + * @return The number of frames within the waveform data + */ + public int getFramesCount() { + return mFramesCount; + } + + /** + * @return The array of frame gains. The size of the array is the frames + * count. The values of the frame gains range from 0 to 256. + */ + public short[] getFrameGains() { + return mGains; + } +} diff --git a/media/libeffects/visualizer/EffectVisualizer.cpp b/media/libeffects/visualizer/EffectVisualizer.cpp index 5505f14..c957dba 100644 --- a/media/libeffects/visualizer/EffectVisualizer.cpp +++ b/media/libeffects/visualizer/EffectVisualizer.cpp @@ -243,19 +243,22 @@ extern "C" int Visualizer_process( // derive capture scaling factor from peak value in current buffer // this gives more interesting captures for display. int32_t shift = 32; - for (size_t i = 0; i < inBuffer->frameCount; i++) { + int len = inBuffer->frameCount * 2; + for (size_t i = 0; i < len; i++) { int32_t smp = inBuffer->s16[i]; - if (smp < 0) smp = -smp; + if (smp < 0) smp = -smp - 1; // take care to keep the max negative in range int32_t clz = __builtin_clz(smp); if (shift > clz) shift = clz; } - // never scale by less than 8 to avoid returning unaltered PCM signal. - // add one to combine the division by 2 needed after summing left and right channels below - if (20 > shift) { - shift = (31 - 8 + 1) - shift; - } else { - shift = (3 + 1); + // A maximum amplitude signal will have 17 leading zeros, which we want to + // translate to a shift of 8 (for converting 16 bit to 8 bit) + shift = 25 - shift; + // Never scale by less than 8 to avoid returning unaltered PCM signal. + if (shift < 3) { + shift = 3; } + // add one to combine the division by 2 needed after summing left and right channels below + shift++; uint32_t captIdx; uint32_t inIdx; @@ -264,7 +267,7 @@ extern "C" int Visualizer_process( inIdx < inBuffer->frameCount && captIdx < pContext->mCaptureSize; inIdx++, captIdx++) { int32_t smp = inBuffer->s16[2 * inIdx] + inBuffer->s16[2 * inIdx + 1]; - smp = (smp + (1 << (shift - 1))) >> shift; + smp = smp >> shift; buf[captIdx] = ((uint8_t)smp)^0x80; } pContext->mCaptureIdx = captIdx; diff --git a/media/libstagefright/FileSource.cpp b/media/libstagefright/FileSource.cpp index b46d8d0..e4f9a47 100644 --- a/media/libstagefright/FileSource.cpp +++ b/media/libstagefright/FileSource.cpp @@ -21,7 +21,7 @@ namespace android { FileSource::FileSource(const char *filename) : mFile(fopen(filename, "rb")), - mFd(fileno(mFile)), + mFd(mFile == NULL ? -1 : fileno(mFile)), mOffset(0), mLength(-1), mDecryptHandle(NULL), diff --git a/media/libstagefright/MediaExtractor.cpp b/media/libstagefright/MediaExtractor.cpp index ee03c52..965c370 100644 --- a/media/libstagefright/MediaExtractor.cpp +++ b/media/libstagefright/MediaExtractor.cpp @@ -65,7 +65,7 @@ sp<MediaExtractor> MediaExtractor::Create( } if (!strncmp(mime, "drm", 3)) { - char *originalMime = strrchr(mime, '+') + 1; + const char *originalMime = strrchr(mime, '+') + 1; if (!strncmp(mime, "drm+es_based", 12)) { return new DRMExtractor(source, originalMime); diff --git a/media/libstagefright/SampleTable.cpp b/media/libstagefright/SampleTable.cpp index 27faf4f..092c33e 100644 --- a/media/libstagefright/SampleTable.cpp +++ b/media/libstagefright/SampleTable.cpp @@ -281,7 +281,7 @@ status_t SampleTable::setSyncSampleParams(off_t data_offset, size_t data_size) { mNumSyncSamples = U32_AT(&header[4]); if (mNumSyncSamples < 2) { - LOGW("Table of sync samples is empty or has only a single entry!"); + LOGV("Table of sync samples is empty or has only a single entry!"); } mSyncSamples = new uint32_t[mNumSyncSamples]; |
