VideoEditorStressTest.java revision 8b9ba616444a265df6cd2b4f4a0a39d808c65ade
1/* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.mediaframeworktest.stress; 18 19import java.io.BufferedWriter; 20import java.io.File; 21import java.io.FileOutputStream; 22import java.io.FileWriter; 23import java.io.Writer; 24import java.util.List; 25 26import android.graphics.Bitmap; 27import android.graphics.Rect; 28import android.media.videoeditor.AudioTrack; 29import android.media.videoeditor.EffectColor; 30import android.media.videoeditor.EffectKenBurns; 31import android.media.videoeditor.MediaImageItem; 32import android.media.videoeditor.MediaItem; 33import android.media.videoeditor.MediaProperties; 34import android.media.videoeditor.MediaVideoItem; 35import android.media.videoeditor.OverlayFrame; 36import android.media.videoeditor.Transition; 37import android.media.videoeditor.TransitionCrossfade; 38import android.media.videoeditor.TransitionAlpha; 39import android.media.videoeditor.TransitionFadeBlack; 40import android.media.videoeditor.TransitionSliding; 41import android.media.videoeditor.VideoEditor; 42import android.os.Environment; 43import android.test.ActivityInstrumentationTestCase; 44import android.media.videoeditor.VideoEditor.MediaProcessingProgressListener; 45import android.os.Environment; 46import android.os.SystemClock; 47import android.test.ActivityInstrumentationTestCase; 48import android.media.videoeditor.VideoEditor.ExportProgressListener; 49import android.media.videoeditor.VideoEditorFactory; 50import android.media.videoeditor.ExtractAudioWaveformProgressListener; 51 52import android.os.Debug; 53import android.util.Log; 54 55import com.android.mediaframeworktest.MediaFrameworkTest; 56import android.test.suitebuilder.annotation.LargeTest; 57import com.android.mediaframeworktest.VideoEditorHelper; 58 59/** 60 * Junit / Instrumentation - performance measurement for media player and 61 * recorder 62 */ 63public class VideoEditorStressTest 64 extends ActivityInstrumentationTestCase<MediaFrameworkTest> { 65 66 private final String TAG = "VideoEditorPerformance"; 67 68 private final String PROJECT_LOCATION = VideoEditorHelper.PROJECT_LOCATION_COMMON; 69 70 private final String INPUT_FILE_PATH = VideoEditorHelper.INPUT_FILE_PATH_COMMON; 71 72 73 private final String VIDEOEDITOR_OUTPUT = PROJECT_LOCATION + 74 "VideoEditorStressMemOutput.txt"; 75 76 public VideoEditorStressTest() { 77 super("com.android.mediaframeworktest", MediaFrameworkTest.class); 78 new File(VIDEOEDITOR_OUTPUT).delete(); 79 } 80 81 private final String PROJECT_CLASS_NAME = 82 "android.media.videoeditor.VideoEditorImpl"; 83 private VideoEditor mVideoEditor; 84 private VideoEditorHelper mVideoEditorHelper; 85 86 @Override 87 protected void setUp() throws Exception { 88 // setup for each test case. 89 super.setUp(); 90 mVideoEditorHelper = new VideoEditorHelper(); 91 // Create a random String which will be used as project path, where all 92 // project related files will be stored. 93 final String projectPath = 94 mVideoEditorHelper.createRandomFile(PROJECT_LOCATION); 95 mVideoEditor = mVideoEditorHelper.createVideoEditor(projectPath); 96 } 97 98 @Override 99 protected void tearDown() throws Exception { 100 mVideoEditorHelper.destroyVideoEditor(mVideoEditor); 101 // Clean the directory created as project path 102 mVideoEditorHelper.deleteProject(new File(mVideoEditor.getPath())); 103 System.gc(); 104 super.tearDown(); 105 } 106 107 private void writeTimingInfo(String testCaseName, String[] information) 108 throws Exception { 109 File outFile = new File(VIDEOEDITOR_OUTPUT); 110 Writer output = new BufferedWriter(new FileWriter(outFile, true)); 111 output.write(testCaseName + "\n\t"); 112 for (int i = 0; i < information.length; i++) { 113 output.write(information[i]); 114 } 115 output.write("\n\n"); 116 output.close(); 117 } 118 119 /** 120 * To stress test MediaItem(Video Item) adding functionality 121 * 122 * @throws Exception 123 */ 124 // TODO : remove TC_STR_001 125 @LargeTest 126 public void testStressAddRemoveVideoItem() throws Exception { 127 final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; 128 129 final String videoItemFileName1 = INPUT_FILE_PATH + 130 "H264_BP_176x144_15fps_144kbps_AMRNB_8kHz_12.2kbps_m_1_17.3gp"; 131 final String videoItemFileName2 = INPUT_FILE_PATH + 132 "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_96kbps_s_0_21.mp4"; 133 final String videoItemFileName3 = INPUT_FILE_PATH + 134 "H263_profile0_176x144_15fps_128kbps_1_35.3gp"; 135 final String videoItemFileName4 = INPUT_FILE_PATH + 136 "MPEG4_SP_640x480_15fps_1200kbps_AACLC_48khz_64kbps_m_1_17.3gp"; 137 final String[] loggingInfo = new String[4]; 138 139 // Take snapShot of Java and Native Memory, do a GC 140 System.gc(); 141 final Runtime runtimeObjStart = Runtime.getRuntime(); 142 final long javaMemStart = runtimeObjStart.totalMemory(); 143 final long nativeMemStart = Debug.getNativeHeapAllocatedSize(); 144 for (int i = 0; i < 50; i++) { 145 if (i % 4 == 0) { 146 final MediaVideoItem mediaItem1 = new MediaVideoItem(mVideoEditor, 147 "m1" + i, videoItemFileName1, renderingMode); 148 mediaItem1.setExtractBoundaries(0, 5000); 149 mVideoEditor.addMediaItem(mediaItem1); 150 } 151 if (i % 4 == 1) { 152 final MediaVideoItem mediaItem2 = new MediaVideoItem(mVideoEditor, 153 "m2" + i, videoItemFileName2, renderingMode); 154 mediaItem2.setExtractBoundaries(0, 10000); 155 mVideoEditor.addMediaItem(mediaItem2); 156 } 157 if (i % 4 == 2) { 158 final MediaVideoItem mediaItem3 = new MediaVideoItem(mVideoEditor, 159 "m3" + i, videoItemFileName3, renderingMode); 160 mediaItem3.setExtractBoundaries(30000, 45000); 161 mVideoEditor.addMediaItem(mediaItem3); 162 } 163 if (i % 4 == 3) { 164 final MediaVideoItem mediaItem4 = new MediaVideoItem(mVideoEditor, 165 "m4" + i, videoItemFileName4, renderingMode); 166 mediaItem4.setExtractBoundaries(10000, 30000); 167 mVideoEditor.addMediaItem(mediaItem4); 168 } 169 } 170 // We will sleep for some time & do an Explicit GC, So that we can get 171 // real memory snapshot 172 System.gc(); 173 Thread.sleep(2500); 174 final Runtime runtimeObjEnd = Runtime.getRuntime(); 175 final long javaMemEnd = runtimeObjEnd.totalMemory(); 176 final long nativeMemEnd = Debug.getNativeHeapAllocatedSize(); 177 loggingInfo[0] = "\nJava Memory at Start = " + javaMemStart + 178 "\n\tJava Memory at End = " + javaMemEnd + 179 "\n\tJava Memory (End - Start) = " + (javaMemEnd - javaMemStart); 180 loggingInfo[1] = "\nNative Memory at Start = " + nativeMemStart + 181 "\n\tNative Memory at End = " + nativeMemEnd + 182 "\n\tNative Memory (End-Start)= " + (nativeMemEnd - nativeMemStart); 183 184 /** Remove items and check for memory leak if any */ 185 // Take snapShot of Java and Native Memory, do a GC 186 System.gc(); 187 final Runtime runtimeObjStart1 = Runtime.getRuntime(); 188 final long javaMemStart1 = runtimeObjStart.totalMemory(); 189 final long nativeMemStart1 = Debug.getNativeHeapAllocatedSize(); 190 for (int i = 0; i < 50; i++) { 191 if (i % 4 == 0) { 192 mVideoEditor.removeMediaItem("m1" + i); 193 } 194 if (i % 4 == 1) { 195 mVideoEditor.removeMediaItem("m2" + i); 196 } 197 if (i % 4 == 2) { 198 mVideoEditor.removeMediaItem("m3" + i); 199 } 200 if (i % 4 == 3) { 201 mVideoEditor.removeMediaItem("m4" + i); 202 } 203 } 204 // We will sleep for some time & do an Explicit GC, So that we can get 205 // real memory snapshot 206 System.gc(); 207 Thread.sleep(2500); 208 final Runtime runtimeObjEnd1 = Runtime.getRuntime(); 209 final long javaMemEnd1 = runtimeObjEnd.totalMemory(); 210 final long nativeMemEnd1 = Debug.getNativeHeapAllocatedSize(); 211 loggingInfo[2] = "\nAfter Items remvoed:\nJava Memory at Start = " + 212 javaMemStart1 + "\n\tJava Memory at End = " + javaMemEnd1 + 213 "\n\tJava Memory (End - Start) = " + (javaMemEnd1 - javaMemStart1); 214 loggingInfo[3] = "\nNative Memory at Start = " + nativeMemStart1 + 215 "\n\tNative Memory at End = " + nativeMemEnd1 + 216 "\n\tNative Memory (End-Start)= " + (nativeMemEnd1 - nativeMemStart1); 217 218 writeTimingInfo("testStressAddRemoveVideoItem", loggingInfo); 219 } 220 221 /** 222 * To stress test MediaItem(Image Item) adding functionality 223 * 224 * @throws Exception 225 */ 226 // TODO : remove TC_STR_002 227 @LargeTest 228 public void testStressAddRemoveImageItem() throws Exception { 229 final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; 230 final String ImageItemFileName1 = INPUT_FILE_PATH + 231 "IMG_1600x1200.jpg"; 232 final String ImageItemFileName2 = INPUT_FILE_PATH + 233 "IMG_640x480.jpg"; 234 final String ImageItemFileName3 = INPUT_FILE_PATH + 235 "IMG_320x240.jpg"; 236 final String ImageItemFileName4 = INPUT_FILE_PATH + 237 "IMG_176x144.jpg"; 238 final String[] loggingInfo = new String[4]; 239 240 // Take snapShot of Java and Native Memory, do a GC 241 System.gc(); 242 final Runtime runtimeObjStart = Runtime.getRuntime(); 243 final long javaMemStart = runtimeObjStart.totalMemory(); 244 final long nativeMemStart = Debug.getNativeHeapAllocatedSize(); 245 for (int i = 0; i < 500; i++) { 246 if (i % 4 == 0) { 247 final MediaImageItem mediaItem1 = new MediaImageItem(mVideoEditor, 248 "m1"+ i, ImageItemFileName1, 5000, renderingMode); 249 mVideoEditor.addMediaItem(mediaItem1); 250 } 251 if (i % 4 == 1) { 252 final MediaImageItem mediaItem2 = new MediaImageItem(mVideoEditor, 253 "m2"+ i, ImageItemFileName2, 10000, renderingMode); 254 mVideoEditor.addMediaItem(mediaItem2); 255 } 256 if (i % 4 == 2) { 257 final MediaImageItem mediaItem3 = new MediaImageItem(mVideoEditor, 258 "m3"+ i, ImageItemFileName3, 15000, renderingMode); 259 mVideoEditor.addMediaItem(mediaItem3); 260 } 261 if (i % 4 == 3) { 262 final MediaImageItem mediaItem4 = new MediaImageItem(mVideoEditor, 263 "m4"+ i, ImageItemFileName4, 20000, renderingMode); 264 mVideoEditor.addMediaItem(mediaItem4); 265 } 266 } 267 // We will sleep for some time & do an Explicit GC, So that we can get 268 // real memory snapshot 269 System.gc(); 270 Thread.sleep(2500); 271 final Runtime runtimeObjEnd = Runtime.getRuntime(); 272 final long javaMemEnd = runtimeObjEnd.totalMemory(); 273 final long nativeMemEnd = Debug.getNativeHeapAllocatedSize(); 274 loggingInfo[0] = "Java Memory at Start = " + javaMemStart + 275 "\n\tJava Memory at End = " + javaMemEnd + 276 "\n\tJava Memory (End - Start) = " + (javaMemEnd - javaMemStart); 277 loggingInfo[1] = "Native Memory at Start = " + nativeMemStart + 278 "\n\tNative Memory at End = " + nativeMemEnd + 279 "\n\tNative Memory (End-Start) = " + (nativeMemEnd - nativeMemStart); 280 281 /** Remove items and check for memory leak if any */ 282 // Take snapShot of Java and Native Memory, do a GC 283 System.gc(); 284 final Runtime runtimeObjStart1 = Runtime.getRuntime(); 285 final long javaMemStart1 = runtimeObjStart.totalMemory(); 286 final long nativeMemStart1 = Debug.getNativeHeapAllocatedSize(); 287 for (int i = 0; i < 500; i++) { 288 if (i % 4 == 0) { 289 mVideoEditor.removeMediaItem("m1"+i); 290 } 291 if (i % 4 == 1) { 292 mVideoEditor.removeMediaItem("m2"+i); 293 } 294 if (i % 4 == 2) { 295 mVideoEditor.removeMediaItem("m3"+i); 296 } 297 if (i % 4 == 3) { 298 mVideoEditor.removeMediaItem("m4"+i); 299 } 300 } 301 // We will sleep for some time & do an Explicit GC, So that we can get 302 // real memory snapshot 303 System.gc(); 304 Thread.sleep(2500); 305 final Runtime runtimeObjEnd1 = Runtime.getRuntime(); 306 final long javaMemEnd1 = runtimeObjEnd.totalMemory(); 307 final long nativeMemEnd1 = Debug.getNativeHeapAllocatedSize(); 308 loggingInfo[2] = "\nAfter removal:\nJava Memory at Start = " + 309 javaMemStart1 + "\n\tJava Memory at End = " + javaMemEnd1 + 310 "\n\tJava Memory (End - Start) = " + (javaMemEnd1 - javaMemStart1); 311 loggingInfo[3] = "Native Memory at Start = " + nativeMemStart1 + 312 "\n\tNative Memory at End = " + nativeMemEnd1 + 313 "\n\tNative Memory (End-Start) = " + (nativeMemEnd1 - nativeMemStart1); 314 315 writeTimingInfo("testStressAddRemoveImageItem", loggingInfo); 316 } 317 318 /** 319 * To stress test transition 320 * 321 * @throws Exception 322 */ 323 // TODO : remove TC_STR_003 324 @LargeTest 325 public void testStressAddRemoveTransition() throws Exception { 326 final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; 327 final String VideoItemFileName1 = INPUT_FILE_PATH + 328 "H264_BP_800x480_15fps_512kbps_1_17.mp4"; 329 final String ImageItemFileName2 = INPUT_FILE_PATH + 330 "IMG_1600x1200.jpg"; 331 final String VideoItemFileName3 = INPUT_FILE_PATH + 332 "MPEG4_SP_640x480_15fps_512kbps_AACLC_48khz_132kbps_s_0_26.mp4"; 333 final String maskFilename = INPUT_FILE_PATH + 334 "TransitionSpiral_QVGA.jpg"; 335 final String[] loggingInfo = new String[4]; 336 337 // Take snapShot of Java and Native Memory, do a GC 338 System.gc(); 339 final Runtime runtimeObjStart = Runtime.getRuntime(); 340 final long javaMemStart = runtimeObjStart.totalMemory(); 341 final long nativeMemStart = Debug.getNativeHeapAllocatedSize(); 342 for (int i = 0; i < 50; i++) { 343 if (i % 4 == 0) { 344 final MediaVideoItem mediaItem1 = new MediaVideoItem(mVideoEditor, 345 "m1"+i, VideoItemFileName1, renderingMode); 346 mVideoEditor.addMediaItem(mediaItem1); 347 mediaItem1.setExtractBoundaries(0, 10000); 348 final TransitionCrossfade tranCrossfade = 349 new TransitionCrossfade("transCF" + i, null, 350 mediaItem1, 5000, Transition.BEHAVIOR_MIDDLE_FAST); 351 mVideoEditor.addTransition(tranCrossfade); 352 } 353 if (i % 4 == 1) { 354 final MediaVideoItem mediaItem1 = new MediaVideoItem(mVideoEditor, 355 "m1"+i, VideoItemFileName1, renderingMode); 356 mVideoEditor.addMediaItem(mediaItem1); 357 mediaItem1.setExtractBoundaries(0, 10000); 358 359 final MediaImageItem mediaItem2 = new MediaImageItem(mVideoEditor, 360 "m2" +i, ImageItemFileName2, 10000, renderingMode); 361 mVideoEditor.addMediaItem(mediaItem2); 362 363 final TransitionAlpha transitionAlpha = 364 mVideoEditorHelper.createTAlpha("transAlpha" + i, mediaItem1, 365 mediaItem2, 5000, Transition.BEHAVIOR_SPEED_UP, 366 maskFilename, 10, false); 367 transitionAlpha.setDuration(4000); 368 mVideoEditor.addTransition(transitionAlpha); 369 } 370 if (i % 4 == 2) { 371 final MediaImageItem mediaItem2 = new MediaImageItem(mVideoEditor, 372 "m2" + i, ImageItemFileName2, 10000, renderingMode); 373 mVideoEditor.addMediaItem(mediaItem2); 374 375 final MediaVideoItem mediaItem3 = new MediaVideoItem(mVideoEditor, 376 "m3" + i, VideoItemFileName3, renderingMode); 377 mVideoEditor.addMediaItem(mediaItem3); 378 379 mediaItem3.setExtractBoundaries(0, 10000); 380 final TransitionAlpha transitionAlpha = 381 mVideoEditorHelper.createTAlpha("transAlpha" + i, mediaItem2, 382 mediaItem3, 5000, Transition.BEHAVIOR_SPEED_UP, 383 maskFilename, 10, false); 384 transitionAlpha.setDuration(4000); 385 mVideoEditor.addTransition(transitionAlpha); 386 387 mediaItem3.setExtractBoundaries(0, 6000); 388 389 final TransitionSliding transition2And3 = 390 mVideoEditorHelper.createTSliding("transSlide" +i, mediaItem2, 391 mediaItem3, 3000, Transition.BEHAVIOR_MIDDLE_FAST, 392 TransitionSliding.DIRECTION_LEFT_OUT_RIGHT_IN); 393 mVideoEditor.addTransition(transition2And3); 394 } 395 if (i % 4 == 3) { 396 final MediaVideoItem mediaItem3 = new MediaVideoItem(mVideoEditor, 397 "m3" + i, VideoItemFileName3, renderingMode); 398 mVideoEditor.addMediaItem(mediaItem3); 399 mediaItem3.setExtractBoundaries(0, 5000); 400 401 final TransitionFadeBlack transition3 = 402 mVideoEditorHelper.createTFadeBlack("transFB" +i, mediaItem3, 403 null, 2500, Transition.BEHAVIOR_SPEED_UP); 404 transition3.setDuration(500); 405 mVideoEditor.addTransition(transition3); 406 } 407 } 408 // We will sleep for some time & do an Explicit GC, So that we can get 409 // real memory snapshot 410 System.gc(); 411 Thread.sleep(2500); 412 final Runtime runtimeObjEnd = Runtime.getRuntime(); 413 final long javaMemEnd = runtimeObjEnd.totalMemory(); 414 final long nativeMemEnd = Debug.getNativeHeapAllocatedSize(); 415 loggingInfo[0] = "Java Memory at Start = " + javaMemStart + 416 "\n\tJava Memory at End = " + javaMemEnd + 417 "\n\tJava Memory (End - Start) = " + (javaMemEnd - javaMemStart); 418 loggingInfo[1] = "Native Memory at Start = " + nativeMemStart + 419 "\n\tNative Memory at End = " + nativeMemEnd + 420 "\n\tNative Memory (End-Start) = " + (nativeMemEnd - nativeMemStart); 421 422 /** Remove items and check for memory leak if any */ 423 // Take snapShot of Java and Native Memory, do a GC 424 System.gc(); 425 final Runtime runtimeObjStart1 = Runtime.getRuntime(); 426 final long javaMemStart1 = runtimeObjStart.totalMemory(); 427 final long nativeMemStart1 = Debug.getNativeHeapAllocatedSize(); 428 for (int i = 0; i < 50; i++) { 429 if (i % 4 == 0) { 430 mVideoEditor.removeTransition("transCF" + i); 431 mVideoEditor.removeMediaItem("m1" + i); 432 } 433 if (i % 4 == 1) { 434 mVideoEditor.removeTransition("transAlpha" + i); 435 mVideoEditor.removeMediaItem("m1" + i); 436 mVideoEditor.removeMediaItem("m2" + i); 437 } 438 if (i % 4 == 2) { 439 /* Because transition is overrid */ 440// mVideoEditor.removeTransition("transAlpha" + i); 441 mVideoEditor.removeTransition("transSlide" +i); 442 mVideoEditor.removeMediaItem("m2" + i); 443 mVideoEditor.removeMediaItem("m3" + i); 444 } 445 if (i % 4 == 3) { 446// mVideoEditor.removeTransition("transFB" +i); 447 mVideoEditor.removeMediaItem("m3" + i); 448 } 449 } 450 // We will sleep for some time & do an Explicit GC, So that we can get 451 // real memory snapshot 452 System.gc(); 453 Thread.sleep(2500); 454 final Runtime runtimeObjEnd1 = Runtime.getRuntime(); 455 final long javaMemEnd1 = runtimeObjEnd.totalMemory(); 456 final long nativeMemEnd1 = Debug.getNativeHeapAllocatedSize(); 457 loggingInfo[2] = "\nAfter removal:\nJava Memory at Start = " + 458 javaMemStart1 + "\n\tJava Memory at End = " + javaMemEnd1 + 459 "\n\tJava Memory (End - Start) = " + (javaMemEnd1 - javaMemStart1); 460 loggingInfo[3] = "Native Memory at Start = " + nativeMemStart1 + 461 "\n\tNative Memory at End = " + nativeMemEnd1 + 462 "\n\tNative Memory (End-Start) = " + (nativeMemEnd1 - nativeMemStart1); 463 464 writeTimingInfo("testStressAddRemoveTransition", loggingInfo); 465 } 466 467 /** 468 * To stress test overlay 469 * 470 * @throws Exception 471 */ 472 // TODO : remove TC_STR_004 473 @LargeTest 474 public void testStressAddRemoveOverlay() throws Exception { 475 final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; 476 final String VideoItemFileName1 = INPUT_FILE_PATH + 477 "MPEG4_SP_640x480_15fps_512kbps_AACLC_48khz_132kbps_s_0_26.mp4"; 478 final String ImageItemFileName2 = INPUT_FILE_PATH + 479 "IMG_640x480.jpg"; 480 final String OverlayFile3 = INPUT_FILE_PATH + 481 "IMG_640x480_Overlay1.png"; 482 final String OverlayFile4 = INPUT_FILE_PATH + 483 "IMG_640x480_Overlay2.png"; 484 final String[] loggingInfo = new String[2]; 485 486 final MediaVideoItem mediaItem1 = new MediaVideoItem(mVideoEditor, 487 "m1", VideoItemFileName1, renderingMode); 488 mVideoEditor.addMediaItem(mediaItem1); 489 490 final MediaImageItem mediaItem2 = new MediaImageItem(mVideoEditor, 491 "m2", ImageItemFileName2, 10000, renderingMode); 492 mVideoEditor.addMediaItem(mediaItem2); 493 494 // Take snapShot of Java and Native Memory, do a GC 495 System.gc(); 496 final Runtime runtimeObjStart = Runtime.getRuntime(); 497 final long javaMemStart = runtimeObjStart.totalMemory(); 498 final long nativeMemStart = Debug.getNativeHeapAllocatedSize(); 499 for (int i = 0; i < 50; i++) { 500 if (i % 3 == 0) { 501 mediaItem1.setExtractBoundaries(0, 10000); 502 final Bitmap mBitmap = mVideoEditorHelper.getBitmap( 503 OverlayFile3, 640, 480); 504 final OverlayFrame overlayFrame = 505 mVideoEditorHelper.createOverlay(mediaItem1, "overlay" + i, 506 mBitmap, 1000, 5000); 507 mediaItem1.addOverlay(overlayFrame); 508 mediaItem1.removeOverlay("overlay"+i); 509 } 510 if (i % 3 == 1) { 511 final Bitmap mBitmap = mVideoEditorHelper.getBitmap( 512 OverlayFile4, 640, 480); 513 final OverlayFrame overlayFrame = 514 mVideoEditorHelper.createOverlay(mediaItem2, "overlay" + i, 515 mBitmap, 1000, 5000); 516 mediaItem2.addOverlay(overlayFrame); 517 mediaItem2.removeOverlay("overlay"+i); 518 } 519 if (i % 3 == 2) { 520 mediaItem1.setExtractBoundaries(0, 10000); 521 final Bitmap mBitmap = mVideoEditorHelper.getBitmap( 522 OverlayFile4, 640, 480); 523 final OverlayFrame overlayFrame = 524 mVideoEditorHelper.createOverlay(mediaItem1, "overlay" + i, 525 mBitmap, 0, mediaItem1.getDuration()); 526 mediaItem1.addOverlay(overlayFrame); 527 mediaItem1.removeOverlay("overlay"+i); 528 } 529 } 530 // We will sleep for some time & do an Explicit GC, So that we can get 531 // real memory snapshot 532 System.gc(); 533 Thread.sleep(2500); 534 final Runtime runtimeObjEnd = Runtime.getRuntime(); 535 final long javaMemEnd = runtimeObjEnd.totalMemory(); 536 final long nativeMemEnd = Debug.getNativeHeapAllocatedSize(); 537 loggingInfo[0] = "Java Memory at Start = " + javaMemStart + 538 "\n\tJava Memory at End = " + javaMemEnd + 539 "\n\tJava Memory (End - Start) = " + (javaMemEnd - javaMemStart); 540 loggingInfo[1] = "Native Memory at Start = " + nativeMemStart + 541 "\n\tNative Memory at End = " + nativeMemEnd + 542 "\n\tNative Memory (End-Start) = " + (nativeMemEnd - nativeMemStart); 543 writeTimingInfo("testStressAddRemoveOverlay", loggingInfo); 544 } 545 546 /** 547 * To stress test Effects 548 * 549 * @throws Exception 550 */ 551 // TODO : remove TC_STR_005 552 @LargeTest 553 public void testStressAddRemoveEffects() throws Exception { 554 final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; 555 final String VideoItemFileName1 = INPUT_FILE_PATH + 556 "MPEG4_SP_640x480_15fps_1200kbps_AACLC_48khz_64kbps_m_1_17.3gp"; 557 final String ImageItemFileName2 = INPUT_FILE_PATH + 558 "IMG_1600x1200.jpg"; 559 560 final String[] loggingInfo = new String[4]; 561 562 final MediaVideoItem mediaItem1 = new MediaVideoItem(mVideoEditor, 563 "m1", VideoItemFileName1, renderingMode); 564 mVideoEditor.addMediaItem(mediaItem1); 565 566 final MediaImageItem mediaItem2 = new MediaImageItem(mVideoEditor, 567 "m2", ImageItemFileName2, 10000, renderingMode); 568 mVideoEditor.addMediaItem(mediaItem2); 569 570 // Take snapShot of Java and Native Memory, do a GC 571 System.gc(); 572 final Runtime runtimeObjStart = Runtime.getRuntime(); 573 final long javaMemStart = runtimeObjStart.totalMemory(); 574 final long nativeMemStart = Debug.getNativeHeapAllocatedSize(); 575 for (int i = 0; i < 500; i++) { 576 if (i % 5 == 0) { 577 mediaItem1.setExtractBoundaries(10000, 30000); 578 final EffectColor effectColor1 = 579 mVideoEditorHelper.createEffectItem(mediaItem1, "effect1"+i, 580 10000, (mediaItem1.getTimelineDuration()-1000), 581 EffectColor.TYPE_COLOR, EffectColor.GREEN); 582 mediaItem1.addEffect(effectColor1); 583 } 584 if (i % 5 == 1) { 585 mediaItem2.setDuration(20000); 586 final EffectColor effectColor1 = 587 mVideoEditorHelper.createEffectItem(mediaItem2, "effect1"+i, 588 0, 4000, EffectColor.TYPE_GRADIENT, EffectColor.GRAY); 589 mediaItem2.addEffect(effectColor1); 590 } 591 if (i % 5 == 2) { 592 mediaItem1.setExtractBoundaries(10000, 30000); 593 final EffectColor effectColor1 = 594 mVideoEditorHelper.createEffectItem(mediaItem1, "effect1"+i, 595 (mediaItem1.getTimelineDuration() - 4000), 4000, 596 EffectColor.TYPE_SEPIA, 0); 597 mediaItem1.addEffect(effectColor1); 598 } 599 if (i % 5 == 3) { 600 mediaItem2.setDuration(20000); 601 final EffectColor effectColor1 = 602 mVideoEditorHelper.createEffectItem(mediaItem2, "effect1"+i, 603 10000, 4000, EffectColor.TYPE_NEGATIVE, 0); 604 mediaItem2.addEffect(effectColor1); 605 } 606 if (i % 5 == 4) { 607 mediaItem2.setDuration(20000); 608 final Rect startRect = new Rect((mediaItem2.getHeight() / 3), 609 (mediaItem2.getWidth() / 3), (mediaItem2.getHeight() / 2), 610 (mediaItem2.getWidth() / 2)); 611 final Rect endRect = new Rect(0, 0, mediaItem2.getWidth(), 612 mediaItem2.getHeight()); 613 final EffectKenBurns kbEffectOnMediaItem = new EffectKenBurns( 614 mediaItem2, "KBOnM2" + i, startRect, endRect, 500, 615 (mediaItem2.getDuration() - 500)); 616 mediaItem2.addEffect(kbEffectOnMediaItem); 617 } 618 } 619 // We will sleep for some time & do an Explicit GC, So that we can get 620 // real memory snapshot 621 System.gc(); 622 Thread.sleep(2500); 623 final Runtime runtimeObjEnd = Runtime.getRuntime(); 624 final long javaMemEnd = runtimeObjEnd.totalMemory(); 625 final long nativeMemEnd = Debug.getNativeHeapAllocatedSize(); 626 loggingInfo[0] = "Java Memory at Start = " + javaMemStart + 627 "\n\tJava Memory at End = " + javaMemEnd + 628 "\n\tJava Memory (End - Start) = " + (javaMemEnd - javaMemStart); 629 loggingInfo[1] = "Native Memory at Start = " + nativeMemStart + 630 "\n\tNative Memory at End = " + nativeMemEnd + 631 "\n\tNative Memory (End-Start) = " + (nativeMemEnd - nativeMemStart); 632 633 /** Remove items and check for memory leak if any */ 634 // Take snapShot of Java and Native Memory, do a GC 635 System.gc(); 636 final Runtime runtimeObjStart1 = Runtime.getRuntime(); 637 final long javaMemStart1 = runtimeObjStart.totalMemory(); 638 final long nativeMemStart1 = Debug.getNativeHeapAllocatedSize(); 639 for (int i = 0; i < 500; i++) { 640 if (i % 5 == 0) { 641 mediaItem1.removeEffect("effect1"+i); 642 } 643 if (i % 5 == 1) { 644 mediaItem1.removeEffect("effect1"+i); 645 } 646 if (i % 5 == 2) { 647 mediaItem1.removeEffect("effect1"+i); 648 } 649 if (i % 5 == 3) { 650 mediaItem1.removeEffect("effect1"+i); 651 } 652 if (i % 5 == 4) { 653 mediaItem1.removeEffect("KBOnM2"+i); 654 } 655 } 656 // We will sleep for some time & do an Explicit GC, So that we can get 657 // real memory snapshot 658 System.gc(); 659 Thread.sleep(2500); 660 final Runtime runtimeObjEnd1 = Runtime.getRuntime(); 661 final long javaMemEnd1 = runtimeObjEnd.totalMemory(); 662 final long nativeMemEnd1 = Debug.getNativeHeapAllocatedSize(); 663 loggingInfo[2] = "\nAfter removal:\nJava Memory at Start = " + 664 javaMemStart1 + "\n\tJava Memory at End = " + javaMemEnd1 + 665 "\n\tJava Memory (End - Start) = " + (javaMemEnd1 - javaMemStart1); 666 loggingInfo[3] = "Native Memory at Start = " + nativeMemStart1 + 667 "\n\tNative Memory at End = " + nativeMemEnd1 + 668 "\n\tNative Memory (End-Start)= " + (nativeMemEnd1 - nativeMemStart1); 669 670 writeTimingInfo("testStressAddRemoveEffects", loggingInfo); 671 } 672 673 /** 674 * This method will test thumbnail list extraction in a loop = 200 for Video 675 * Item 676 * 677 * @throws Exception 678 */ 679 // TODO : remove TC_STR_006 680 @LargeTest 681 public void testStressThumbnailVideoItem() throws Exception { 682 final String videoItemFileName = INPUT_FILE_PATH 683 + "H264_BP_640x480_15fps_1200Kbps_AACLC_48KHz_64kps_m_0_27.3gp"; 684 final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; 685 final String[] loggingInfo = new String[2]; 686 687 final MediaVideoItem mediaVideoItem = new MediaVideoItem(mVideoEditor, 688 "m1", videoItemFileName, renderingMode); 689 // Take snapShot of Java and Native Memory, do a GC 690 System.gc(); 691 final Runtime runtimeObjStart = Runtime.getRuntime(); 692 final long javaMemStart = runtimeObjStart.totalMemory(); 693 final long nativeMemStart = Debug.getNativeHeapAllocatedSize(); 694 695 for (int i = 0; i < 50; i++) { 696 if (i % 4 == 0) { 697 final Bitmap[] thumbNails = 698 mediaVideoItem.getThumbnailList(mediaVideoItem.getWidth()*3, 699 mediaVideoItem.getHeight()*2, i, 5000, 2); 700 // Recycle this Bitmap array 701 for (int i1 = 0; i1 < thumbNails.length; i1++) { 702 thumbNails[i1].recycle(); 703 } 704 } 705 if (i % 4 == 1) { 706 final Bitmap[] thumbNails = 707 mediaVideoItem.getThumbnailList(mediaVideoItem.getWidth()/2, 708 mediaVideoItem.getHeight() * 3, i, 5000, 2); 709 // Recycle this Bitmap array 710 for (int i1 = 0; i1 < thumbNails.length; i1++) { 711 thumbNails[i1].recycle(); 712 } 713 } 714 if (i % 4 == 2) { 715 final Bitmap[] thumbNails = 716 mediaVideoItem.getThumbnailList(mediaVideoItem.getWidth()*2, 717 mediaVideoItem.getHeight() / 3, i, 5000, 2); 718 // Recycle this Bitmap array 719 for (int i1 = 0; i1 < thumbNails.length; i1++) { 720 thumbNails[i1].recycle(); 721 } 722 } 723 if (i % 4 == 3) { 724 final Bitmap[] thumbNails = 725 mediaVideoItem.getThumbnailList(mediaVideoItem.getWidth(), 726 mediaVideoItem.getHeight(), i, 5000, 2); 727 // Recycle this Bitmap array 728 for (int i1 = 0; i1 < thumbNails.length; i1++) { 729 thumbNails[i1].recycle(); 730 } 731 } 732 } 733 // We will sleep for some time & do an Explicit GC, So that we can get 734 // real memory snapshot 735 System.gc(); 736 Thread.sleep(2500); 737 final Runtime runtimeObjEnd = Runtime.getRuntime(); 738 final long javaMemEnd = runtimeObjEnd.totalMemory(); 739 final long nativeMemEnd = Debug.getNativeHeapAllocatedSize(); 740 loggingInfo[0] = "Java Memory at Start = " + javaMemStart + 741 "\t\tJava Memory at End = " + javaMemEnd + 742 "\t\tJava Memory (End - Start) = " + (javaMemEnd - javaMemStart); 743 loggingInfo[1] = "Native Memory at Start = " + nativeMemStart + 744 "\tNative Memory at End = " + nativeMemEnd + 745 "\t\tNative Memory (End-Start) = " + (nativeMemEnd - nativeMemStart); 746 writeTimingInfo("testStressThumbnailVideoItem", loggingInfo); 747 } 748 749 750 751 /** 752 * To stress test media properties 753 * 754 * @throws Exception 755 */ 756 // TODO : remove TC_STR_007 757 @LargeTest 758 public void testStressMediaProperties() throws Exception { 759 final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; 760 final String VideoItemFileName1 = INPUT_FILE_PATH + 761 "H264_BP_1080x720_30fps_800kbps_1_17.mp4"; 762 final String ImageItemFileName2 = INPUT_FILE_PATH + 763 "IMG_640x480.jpg"; 764 final String AudioItemFileName3 = INPUT_FILE_PATH + 765 "AACLC_44.1kHz_256kbps_s_1_17.mp4"; 766 final String[] loggingInfo = new String[2]; 767 768 final int videoAspectRatio = MediaProperties.ASPECT_RATIO_3_2; 769 final int videoFileType = MediaProperties.FILE_MP4; 770 final int videoCodecType = MediaProperties.VCODEC_H264BP; 771 final int videoDuration = 77366; 772 final int videoProfile = 0; 773 final int videoHeight = MediaProperties.HEIGHT_720; 774 final int videoWidth = 1080; 775 776 final int imageAspectRatio = MediaProperties.ASPECT_RATIO_4_3; 777 final int imageFileType = MediaProperties.FILE_JPEG; 778 final int imageWidth = 640; 779 final int imageHeight = MediaProperties.HEIGHT_480; 780 781 final int audioDuration = 77554; 782 final int audioCodecType = MediaProperties.ACODEC_AAC_LC; 783 final int audioSamplingFrequency = 44100; 784 final int audioChannel = 2; 785 786 // Take snapShot of Java and Native Memory 787 // System gC 788 System.gc(); 789 final Runtime runtimeObjStart = Runtime.getRuntime(); 790 final long javaMemStart = runtimeObjStart.totalMemory(); 791 final long nativeMemStart = Debug.getNativeHeapAllocatedSize(); 792 for (int i = 0; i < 200; i++) { 793 if (i % 3 == 0) { 794 final MediaVideoItem mediaItem1 = new MediaVideoItem(mVideoEditor, 795 "m1" + i, VideoItemFileName1, renderingMode); 796 mVideoEditor.addMediaItem(mediaItem1); 797 mediaItem1.setExtractBoundaries(0, 20000); 798 assertEquals("Aspect Ratio Mismatch", 799 videoAspectRatio, mediaItem1.getAspectRatio()); 800 assertEquals("File Type Mismatch", 801 videoFileType, mediaItem1.getFileType()); 802 assertEquals("VideoCodec Mismatch", 803 videoCodecType, mediaItem1.getVideoType()); 804 assertEquals("duration Mismatch", 805 videoDuration, mediaItem1.getDuration()); 806 assertEquals("Video Profile ", 807 videoProfile, mediaItem1.getVideoProfile()); 808 assertEquals("Video height ", 809 videoHeight, mediaItem1.getHeight()); 810 assertEquals("Video width ", 811 videoWidth, mediaItem1.getWidth()); 812 mVideoEditor.removeMediaItem("m1" + i); 813 } 814 if (i % 3 == 1) { 815 final MediaImageItem mediaItem2 = new MediaImageItem(mVideoEditor, 816 "m2" + i, ImageItemFileName2, 10000, renderingMode); 817 mVideoEditor.addMediaItem(mediaItem2); 818 assertEquals("Aspect Ratio Mismatch", 819 imageAspectRatio, mediaItem2.getAspectRatio()); 820 assertEquals("File Type Mismatch", 821 imageFileType, mediaItem2.getFileType()); 822 assertEquals("Image height", 823 imageHeight, mediaItem2.getHeight()); 824 assertEquals("Image width", 825 imageWidth, mediaItem2.getWidth()); 826 mVideoEditor.removeMediaItem("m2" + i); 827 } 828 if (i % 3 == 2) { 829 final AudioTrack mediaItem3 = new AudioTrack(mVideoEditor, 830 "m3" + i, AudioItemFileName3); 831 mVideoEditor.addAudioTrack(mediaItem3); 832 assertEquals("AudioType Mismatch", audioCodecType, 833 mediaItem3.getAudioType()); 834 assertEquals("Audio Sampling", audioSamplingFrequency, 835 mediaItem3.getAudioSamplingFrequency()); 836 assertEquals("Audio Channels", 837 audioChannel, mediaItem3.getAudioChannels()); 838 assertEquals("duration Mismatch", audioDuration, 839 mediaItem3.getDuration()); 840 mVideoEditor.removeAudioTrack("m3" + i); 841 } 842 } 843 // We will sleep for some time & do an Explicit GC, So that we can get 844 // real memory snapshot 845 System.gc(); 846 Thread.sleep(2500); 847 final Runtime runtimeObjEnd = Runtime.getRuntime(); 848 final long javaMemEnd = runtimeObjEnd.totalMemory(); 849 final long nativeMemEnd = Debug.getNativeHeapAllocatedSize(); 850 loggingInfo[0] = "Java Memory at Start = " + javaMemStart + 851 "\t\tJava Memory at End = " + javaMemEnd + 852 "\t\tJava Memory (End - Start) = " + (javaMemEnd - javaMemStart); 853 loggingInfo[1] = "Native Memory at Start = " + nativeMemStart + 854 "\tNative Memory at End = " + nativeMemEnd + 855 "\t\tNative Memory (End - Start) = " + (nativeMemEnd-nativeMemStart); 856 writeTimingInfo("testStressMediaProperties", loggingInfo); 857 } 858 859 /** 860 * To stress test insert and move of mediaitems 861 * 862 * @throws Exception 863 */ 864 // TODO : remove TC_STR_008 865 @LargeTest 866 public void testStressInsertMoveItems() throws Exception { 867 final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; 868 final String VideoItemFileName1 = INPUT_FILE_PATH + 869 "H264_BP_1080x720_30fps_800kbps_1_17.mp4"; 870 final String VideoItemFileName2 = INPUT_FILE_PATH + 871 "H264_BP_800x480_15fps_512kbps_1_17.mp4"; 872 final String VideoItemFileName3 = INPUT_FILE_PATH + 873 "MPEG4_SP_640x480_15fps_1200kbps_AACLC_48khz_64kbps_m_1_17.3gp"; 874 final String[] loggingInfo = new String[4]; 875 876 // Take snapShot of Java and Native Memory 877 // System gC 878 System.gc(); 879 final Runtime runtimeObjStart = Runtime.getRuntime(); 880 final long javaMemStart = runtimeObjStart.totalMemory(); 881 final long nativeMemStart = Debug.getNativeHeapAllocatedSize(); 882 883 final MediaVideoItem mediaItem1 = new MediaVideoItem(mVideoEditor, 884 "m1", VideoItemFileName1, renderingMode); 885 mVideoEditor.addMediaItem(mediaItem1); 886 mediaItem1.setExtractBoundaries(0, 10000); 887 888 final MediaVideoItem mediaItem2 = new MediaVideoItem(mVideoEditor, 889 "m2", VideoItemFileName2, renderingMode); 890 mVideoEditor.addMediaItem(mediaItem2); 891 mediaItem2.setExtractBoundaries(0, 15000); 892 893 for (int i = 0; i < 500; i++) { 894 final MediaVideoItem mediaItem3 = new MediaVideoItem(mVideoEditor, 895 "m3" + i, VideoItemFileName3, renderingMode); 896 mediaItem3.setExtractBoundaries(0, 15000); 897 mVideoEditor.insertMediaItem(mediaItem3, "m1"); 898 } 899 900 for (int i = 0; i < 500; i++) { 901 mVideoEditor.moveMediaItem("m2", "m3" + i); 902 } 903 // We will sleep for some time & do an Explicit GC, So that we can get 904 // real memory snapshot 905 System.gc(); 906 Thread.sleep(2500); 907 final Runtime runtimeObjEnd = Runtime.getRuntime(); 908 final long javaMemEnd = runtimeObjEnd.totalMemory(); 909 final long nativeMemEnd = Debug.getNativeHeapAllocatedSize(); 910 loggingInfo[0] = "Java Memory at Start = " + javaMemStart + 911 "\t\tJava Memory at End = " + javaMemEnd + 912 "\t\tJava Memory (End - Start) = " + (javaMemEnd - javaMemStart); 913 loggingInfo[1] = "Native Memory at Start = " + nativeMemStart + 914 "\tNative Memory at End = " + nativeMemEnd + 915 "\t\tNative Memory (End-Start)= " + (nativeMemEnd - nativeMemStart); 916 917 /** Remove items and check for memory leak if any */ 918 // Take snapShot of Java and Native Memory, do a GC 919 System.gc(); 920 final Runtime runtimeObjStart1 = Runtime.getRuntime(); 921 final long javaMemStart1 = runtimeObjStart.totalMemory(); 922 final long nativeMemStart1 = Debug.getNativeHeapAllocatedSize(); 923 for (int i = 0; i < 500; i++) { 924 mVideoEditor.removeMediaItem("m3" + i); 925 } 926 mVideoEditor.removeMediaItem("m2"); 927 mVideoEditor.removeMediaItem("m1"); 928 // We will sleep for some time & do an Explicit GC, So that we can get 929 // real memory snapshot 930 System.gc(); 931 Thread.sleep(2500); 932 final Runtime runtimeObjEnd1 = Runtime.getRuntime(); 933 final long javaMemEnd1 = runtimeObjEnd.totalMemory(); 934 final long nativeMemEnd1 = Debug.getNativeHeapAllocatedSize(); 935 loggingInfo[2] = "\nAfter removal:\nJava Memory at Start = " + 936 javaMemStart1 + "\n\tJava Memory at End = " + javaMemEnd1 + 937 "\n\tJava Memory (End - Start) = " + (javaMemEnd1 - javaMemStart1); 938 loggingInfo[3] = "Native Memory at Start = " + nativeMemStart1 + 939 "\n\tNative Memory at End = " + nativeMemEnd1 + 940 "\n\tNative Memory (End-Start)= " + (nativeMemEnd1-nativeMemStart1); 941 942 writeTimingInfo("testStressInsertMoveItems", loggingInfo); 943 } 944 945 /** 946 * To stress test : load and save 947 * 948 * @throws Exception 949 */ 950 // TODO : remove TC_STR_009 951 @LargeTest 952 public void testStressLoadAndSave() throws Exception { 953 final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; 954 final String VideoItemFileName1 = INPUT_FILE_PATH + 955 "H264_BP_1080x720_30fps_800kbps_1_17.mp4"; 956 final String VideoItemFileName2 = INPUT_FILE_PATH + 957 "H264_BP_800x480_15fps_512kbps_1_17.mp4"; 958 final String VideoItemFileName3 = INPUT_FILE_PATH + 959 "MPEG4_SP_640x480_15fps_1200kbps_AACLC_48khz_64kbps_m_1_17.3gp"; 960 final String ImageItemFileName4 = INPUT_FILE_PATH + 961 "IMG_640x480.jpg"; 962 final String ImageItemFileName5 = INPUT_FILE_PATH + 963 "IMG_176x144.jpg"; 964 final String OverlayFile6 = INPUT_FILE_PATH + 965 "IMG_640x480_Overlay1.png"; 966 final String[] loggingInfo = new String[4]; 967 968 final String[] projectPath = new String[10]; 969 970 // Take snapShot of Java and Native Memory 971 // System gC 972 System.gc(); 973 final Runtime runtimeObjStart = Runtime.getRuntime(); 974 final long javaMemStart = runtimeObjStart.totalMemory(); 975 final long nativeMemStart = Debug.getNativeHeapAllocatedSize(); 976 977 for(int i=0; i < 10; i++){ 978 979 projectPath[i] = 980 mVideoEditorHelper.createRandomFile(PROJECT_LOCATION); 981 final VideoEditor mVideoEditor1 = 982 mVideoEditorHelper.createVideoEditor(projectPath[i]); 983 984 final MediaVideoItem mediaItem1 = new MediaVideoItem(mVideoEditor1, 985 "m1", VideoItemFileName1, renderingMode); 986 mVideoEditor1.addMediaItem(mediaItem1); 987 mediaItem1.setExtractBoundaries(0, 10000); 988 989 final MediaVideoItem mediaItem2 = new MediaVideoItem(mVideoEditor1, 990 "m2", VideoItemFileName2, renderingMode); 991 mVideoEditor1.addMediaItem(mediaItem2); 992 mediaItem2.setExtractBoundaries(mediaItem2.getDuration()/4, 993 mediaItem2.getDuration()/2); 994 995 final MediaVideoItem mediaItem3 = new MediaVideoItem(mVideoEditor1, 996 "m3", VideoItemFileName3, renderingMode); 997 mVideoEditor1.addMediaItem(mediaItem3); 998 mediaItem3.setExtractBoundaries(mediaItem3.getDuration()/2, 999 mediaItem3.getDuration()); 1000 1001 final MediaImageItem mediaItem4 = new MediaImageItem(mVideoEditor1, 1002 "m4", ImageItemFileName4, 5000, renderingMode); 1003 mVideoEditor1.addMediaItem(mediaItem4); 1004 1005 final MediaImageItem mediaItem5 = new MediaImageItem(mVideoEditor1, 1006 "m5", ImageItemFileName5, 5000, renderingMode); 1007 mVideoEditor1.addMediaItem(mediaItem5); 1008 1009 final EffectColor effectColor1 = 1010 mVideoEditorHelper.createEffectItem(mediaItem3, "effect1", 1011 10000, 2000, EffectColor.TYPE_COLOR, EffectColor.GREEN); 1012 mediaItem3.addEffect(effectColor1); 1013 1014 final Bitmap mBitmap = mVideoEditorHelper.getBitmap(OverlayFile6, 1015 640, 480); 1016 final OverlayFrame overlayFrame = 1017 mVideoEditorHelper.createOverlay(mediaItem4, "overlay", 1018 mBitmap, 4000, 1000); 1019 mediaItem4.addOverlay(overlayFrame); 1020 1021 final TransitionCrossfade tranCrossfade = 1022 new TransitionCrossfade("transCF", mediaItem1, 1023 mediaItem2, 5000, Transition.BEHAVIOR_MIDDLE_FAST); 1024 mVideoEditor1.addTransition(tranCrossfade); 1025 1026 final EffectColor effectColor2 = 1027 mVideoEditorHelper.createEffectItem(mediaItem4, "effect2", 0, 1028 mediaItem4.getDuration(), EffectColor.TYPE_COLOR, 1029 EffectColor.PINK); 1030 mediaItem4.addEffect(effectColor2); 1031 1032 mVideoEditor1.generatePreview(new MediaProcessingProgressListener() { 1033 public void onProgress(Object item, int action, int progress) { 1034 } 1035 }); 1036 1037 mVideoEditor1.save(); 1038 mVideoEditor1.release(); 1039 } 1040 // We will sleep for some time & do an Explicit GC, So that we can get 1041 // real memory snapshot 1042 System.gc(); 1043 Thread.sleep(2500); 1044 final Runtime runtimeObjEnd = Runtime.getRuntime(); 1045 final long javaMemEnd = runtimeObjEnd.totalMemory(); 1046 final long nativeMemEnd = Debug.getNativeHeapAllocatedSize(); 1047 loggingInfo[0] = "Java Memory at Start = " + javaMemStart + 1048 "\n\tJava Memory at End = " + javaMemEnd + 1049 "\n\tJava Memory (End - Start) = " + (javaMemEnd - javaMemStart); 1050 loggingInfo[1] = "Native Memory at Start = " + nativeMemStart + 1051 "\n\tNative Memory at End = " + nativeMemEnd + 1052 "\n\tNative Memory (End-Start)= " + (nativeMemEnd - nativeMemStart); 1053 1054 /** Remove items and check for memory leak if any */ 1055 // Take snapShot of Java and Native Memory, do a GC 1056 System.gc(); 1057 final Runtime runtimeObjStart1 = Runtime.getRuntime(); 1058 final long javaMemStart1 = runtimeObjStart.totalMemory(); 1059 final long nativeMemStart1 = Debug.getNativeHeapAllocatedSize(); 1060 1061 for(int i=0; i<10; i++){ 1062 final VideoEditor mVideoEditor1b = 1063 VideoEditorFactory.load(projectPath[i], true); 1064 List<MediaItem> mediaList = mVideoEditor1b.getAllMediaItems(); 1065 assertEquals("Media Item List Size", 5, mediaList.size()); 1066 1067 mediaList.get(3).removeEffect("effect1"); 1068 mediaList.get(3).removeEffect("effect2"); 1069 mediaList.get(2).removeOverlay("overlay"); 1070 mVideoEditor1b.removeTransition("transCF"); 1071 mVideoEditor1b.removeMediaItem("m5"); 1072 mVideoEditor1b.removeMediaItem("m4"); 1073 mVideoEditor1b.removeMediaItem("m3"); 1074 mVideoEditor1b.removeMediaItem("m2"); 1075 mVideoEditor1b.removeMediaItem("m1"); 1076 mVideoEditor1b.release(); 1077 } 1078 // We will sleep for some time & do an Explicit GC, So that we can get 1079 // real memory snapshot 1080 System.gc(); 1081 Thread.sleep(2500); 1082 final Runtime runtimeObjEnd1 = Runtime.getRuntime(); 1083 final long javaMemEnd1 = runtimeObjEnd.totalMemory(); 1084 final long nativeMemEnd1 = Debug.getNativeHeapAllocatedSize(); 1085 loggingInfo[2] = "\nAfter removal:\nJava Memory at Start = " + 1086 javaMemStart1 + "\n\tJava Memory at End = " + javaMemEnd1 + 1087 "\n\tJava Memory (End - Start) = " + (javaMemEnd1 - javaMemStart1); 1088 loggingInfo[3] = "Native Memory at Start = " + nativeMemStart1 + 1089 "\n\tNative Memory at End = " + nativeMemEnd1 + 1090 "\n\tNative Memory (End-Start)= " + (nativeMemEnd1-nativeMemStart1); 1091 writeTimingInfo("testStressLoadAndSave", loggingInfo); 1092 } 1093 1094 /** 1095 * To stress test : Multiple Export 1096 * 1097 * @throws Exception 1098 */ 1099 // TODO : remove TC_STR_010 1100 @LargeTest 1101 public void testStressMultipleExport() throws Exception { 1102 final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; 1103 final String VideoItemFileName1 = INPUT_FILE_PATH + 1104 "H264_BP_1080x720_30fps_800kbps_1_17.mp4"; 1105 final String VideoItemFileName2 = INPUT_FILE_PATH + 1106 "H264_BP_800x480_15fps_512kbps_1_17.mp4"; 1107 final String VideoItemFileName3 = INPUT_FILE_PATH + 1108 "MPEG4_SP_640x480_15fps_1200kbps_AACLC_48khz_64kbps_m_1_17.3gp"; 1109 final String[] loggingInfo = new String[4]; 1110 1111 final String outFilename = mVideoEditorHelper.createRandomFile( 1112 mVideoEditor.getPath() + "/") + ".3gp"; 1113 1114 // Take snapShot of Java and Native Memory 1115 // System gC 1116 System.gc(); 1117 final Runtime runtimeObjStart = Runtime.getRuntime(); 1118 final long javaMemStart = runtimeObjStart.totalMemory(); 1119 final long nativeMemStart = Debug.getNativeHeapAllocatedSize(); 1120 1121 final MediaVideoItem mediaItem1 = new MediaVideoItem(mVideoEditor, 1122 "m1", VideoItemFileName1, renderingMode); 1123 mVideoEditor.addMediaItem(mediaItem1); 1124 mediaItem1.setExtractBoundaries(0, 10000); 1125 1126 final MediaVideoItem mediaItem2 = new MediaVideoItem(mVideoEditor, 1127 "m2", VideoItemFileName2, renderingMode); 1128 mVideoEditor.addMediaItem(mediaItem2); 1129 mediaItem2.setExtractBoundaries(0, 15000); 1130 1131 for (int i = 0; i < 100; i++) { 1132 if(i%4 ==0){ 1133 final int aspectRatio = MediaProperties.ASPECT_RATIO_4_3; 1134 mVideoEditor.setAspectRatio(aspectRatio); 1135 mVideoEditor.export(outFilename, MediaProperties.HEIGHT_480, 1136 MediaProperties.BITRATE_256K,MediaProperties.ACODEC_AAC_LC, 1137 MediaProperties.VCODEC_H263, 1138 new ExportProgressListener() { 1139 public void onProgress(VideoEditor ve, String outFileName, 1140 int progress) { 1141 } 1142 }); 1143 } 1144 if(i%4 ==1){ 1145 final int aspectRatio = MediaProperties.ASPECT_RATIO_5_3; 1146 mVideoEditor.setAspectRatio(aspectRatio); 1147 mVideoEditor.export(outFilename, MediaProperties.HEIGHT_144, 1148 MediaProperties.BITRATE_384K,MediaProperties.ACODEC_AAC_LC, 1149 MediaProperties.VCODEC_MPEG4, 1150 new ExportProgressListener() { 1151 public void onProgress(VideoEditor ve, String outFileName, 1152 int progress) { 1153 } 1154 }); 1155 } 1156 if(i%4 ==2){ 1157 final int aspectRatio = MediaProperties.ASPECT_RATIO_11_9; 1158 mVideoEditor.setAspectRatio(aspectRatio); 1159 mVideoEditor.export(outFilename, 640, 1160 MediaProperties.BITRATE_512K,MediaProperties.ACODEC_AAC_LC, 1161 MediaProperties.VCODEC_H264BP, 1162 new ExportProgressListener() { 1163 public void onProgress(VideoEditor ve, String outFileName, 1164 int progress) { 1165 } 1166 }); 1167 } 1168 if(i%4 ==3){ 1169 final int aspectRatio = MediaProperties.ASPECT_RATIO_3_2; 1170 mVideoEditor.setAspectRatio(aspectRatio); 1171 mVideoEditor.export(outFilename, MediaProperties.HEIGHT_480, 1172 MediaProperties.BITRATE_800K,MediaProperties.ACODEC_AAC_LC, 1173 MediaProperties.VCODEC_H264BP, 1174 new ExportProgressListener() { 1175 public void onProgress(VideoEditor ve, String outFileName, 1176 int progress) { 1177 } 1178 }); 1179 } 1180 } 1181 // We will sleep for some time & do an Explicit GC, So that we can get 1182 // real memory snapshot 1183 System.gc(); 1184 Thread.sleep(2500); 1185 final Runtime runtimeObjEnd = Runtime.getRuntime(); 1186 final long javaMemEnd = runtimeObjEnd.totalMemory(); 1187 final long nativeMemEnd = Debug.getNativeHeapAllocatedSize(); 1188 loggingInfo[0] = "Java Memory at Start = " + javaMemStart + 1189 "\n\tJava Memory at End = " + javaMemEnd + 1190 "\n\tJava Memory (End - Start) = " + (javaMemEnd - javaMemStart); 1191 loggingInfo[1] = "Native Memory at Start = " + nativeMemStart + 1192 "\n\tNative Memory at End = " + nativeMemEnd + 1193 "\n\tNative Memory (End-Start)= " + (nativeMemEnd - nativeMemStart); 1194 1195 /** Remove items and check for memory leak if any */ 1196 // Take snapShot of Java and Native Memory, do a GC 1197 System.gc(); 1198 final Runtime runtimeObjStart1 = Runtime.getRuntime(); 1199 final long javaMemStart1 = runtimeObjStart.totalMemory(); 1200 final long nativeMemStart1 = Debug.getNativeHeapAllocatedSize(); 1201 1202 mVideoEditor.removeMediaItem("m2"); 1203 mVideoEditor.removeMediaItem("m1"); 1204 1205 // We will sleep for some time & do an Explicit GC, So that we can get 1206 // real memory snapshot 1207 System.gc(); 1208 Thread.sleep(2500); 1209 final Runtime runtimeObjEnd1 = Runtime.getRuntime(); 1210 final long javaMemEnd1 = runtimeObjEnd.totalMemory(); 1211 final long nativeMemEnd1 = Debug.getNativeHeapAllocatedSize(); 1212 loggingInfo[2] = "\nAfter removal:\nJava Memory at Start = " + 1213 javaMemStart1 + "\n\tJava Memory at End = " + javaMemEnd1 + 1214 "\n\tJava Memory (End - Start) = " + (javaMemEnd1 - javaMemStart1); 1215 loggingInfo[3] = "Native Memory at Start = " + nativeMemStart1 + 1216 "\n\tNative Memory at End = " + nativeMemEnd1 + 1217 "\n\tNative Memory (End-Start)= " + (nativeMemEnd1-nativeMemStart1); 1218 writeTimingInfo("testStressMultipleExport", loggingInfo); 1219 } 1220 1221 1222 /** 1223 * To stress test Media Item,Overlays,Transitions and Ken Burn 1224 * 1225 * @throws Exception 1226 */ 1227 // TODO : remove TC_STR_011 1228 @LargeTest 1229 public void testStressOverlayTransKenBurn() throws Exception { 1230 final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; 1231 final String VideoItemFileName1 = INPUT_FILE_PATH + 1232 "H264_BP_640x480_30fps_256kbps_1_17.mp4"; 1233 final String ImageItemFileName2 = INPUT_FILE_PATH + 1234 "IMG_640x480.jpg"; 1235 final String OverlayFile3 = INPUT_FILE_PATH + 1236 "IMG_640x480_Overlay1.png"; 1237 final String audioFilename4 = INPUT_FILE_PATH + 1238 "AACLC_44.1kHz_256kbps_s_1_17.mp4"; 1239 1240 final String[] loggingInfo = new String[4]; 1241 1242 // Take snapShot of Java and Native Memory, do a GC 1243 System.gc(); 1244 final Runtime runtimeObjStart = Runtime.getRuntime(); 1245 final long javaMemStart = runtimeObjStart.totalMemory(); 1246 final long nativeMemStart = Debug.getNativeHeapAllocatedSize(); 1247 for (int i = 0; i < 10; i++) { 1248 final MediaVideoItem mediaItem1 = new MediaVideoItem(mVideoEditor, 1249 "m1" + i, VideoItemFileName1, renderingMode); 1250 mVideoEditor.addMediaItem(mediaItem1); 1251 mediaItem1.setExtractBoundaries(0, 10000); 1252 1253 final MediaImageItem mediaItem2 = new MediaImageItem(mVideoEditor, 1254 "m2" + i, ImageItemFileName2, 10000, renderingMode); 1255 mVideoEditor.addMediaItem(mediaItem2); 1256 1257 final EffectColor effectColor1 = 1258 mVideoEditorHelper.createEffectItem(mediaItem1, "effect1"+i, 1259 (mediaItem1.getDuration() - 4000), 4000, 1260 EffectColor.TYPE_SEPIA, 0); 1261 mediaItem1.addEffect(effectColor1); 1262 1263 final TransitionCrossfade tranCrossfade = 1264 new TransitionCrossfade("transCF" + i, mediaItem1, 1265 mediaItem2, 4000, Transition.BEHAVIOR_MIDDLE_FAST); 1266 mVideoEditor.addTransition(tranCrossfade); 1267 1268 final Bitmap mBitmap = mVideoEditorHelper.getBitmap(OverlayFile3, 1269 640, 480); 1270 final OverlayFrame overlayFrame = 1271 mVideoEditorHelper.createOverlay(mediaItem1, "overlay" + i, 1272 mBitmap, 1000, 5000); 1273 mediaItem1.addOverlay(overlayFrame); 1274 1275 final Rect startRect = new Rect((mediaItem2.getHeight() / 3), 1276 (mediaItem2.getWidth() / 3), (mediaItem2.getHeight() / 2), 1277 (mediaItem2.getWidth() / 2)); 1278 final Rect endRect = new Rect(0, 0, mediaItem2.getWidth(), 1279 mediaItem2.getHeight()); 1280 1281 final EffectKenBurns kbEffectOnMediaItem = new EffectKenBurns( 1282 mediaItem2, "KBOnM2" + i, startRect, endRect, 500, 1283 (mediaItem2.getDuration()-500)); 1284 mediaItem2.addEffect(kbEffectOnMediaItem); 1285 1286 if(i == 5) { 1287 final AudioTrack audioTrack1 = new AudioTrack(mVideoEditor, 1288 "Audio Track1", audioFilename4); 1289 mVideoEditor.addAudioTrack(audioTrack1); 1290 } 1291 1292 } 1293 // We will sleep for some time & do an Explicit GC, So that we can get 1294 // real memory snapshot 1295 System.gc(); 1296 Thread.sleep(2500); 1297 final Runtime runtimeObjEnd = Runtime.getRuntime(); 1298 final long javaMemEnd = runtimeObjEnd.totalMemory(); 1299 final long nativeMemEnd = Debug.getNativeHeapAllocatedSize(); 1300 loggingInfo[0] = "Java Memory at Start = " + javaMemStart + 1301 "\n\tJava Memory at End = " + javaMemEnd + 1302 "\n\tJava Memory (End - Start) = " + (javaMemEnd - javaMemStart); 1303 loggingInfo[1] = "Native Memory at Start = " + nativeMemStart + 1304 "\n\tNative Memory at End = " + nativeMemEnd + 1305 "\n\tNative Memory (End-Start)= " + (nativeMemEnd - nativeMemStart); 1306 1307 /** Remove items and check for memory leak if any */ 1308 // Take snapShot of Java and Native Memory, do a GC 1309 System.gc(); 1310 final Runtime runtimeObjStart1 = Runtime.getRuntime(); 1311 final long javaMemStart1 = runtimeObjStart.totalMemory(); 1312 final long nativeMemStart1 = Debug.getNativeHeapAllocatedSize(); 1313 1314 for (int i = 0; i < 10; i++) { 1315 MediaImageItem m2 = (MediaImageItem)mVideoEditor.getMediaItem("m2"+i); 1316 MediaVideoItem m1 = (MediaVideoItem)mVideoEditor.getMediaItem("m1"+i); 1317 m2.removeEffect("KBOnM2" + i); 1318 m1.removeOverlay("overlay" + i); 1319 mVideoEditor.removeTransition("transCF" + i); 1320 m1.removeEffect("effect1" + i); 1321 mVideoEditor.removeMediaItem("m2" + i); 1322 mVideoEditor.removeMediaItem("m1" + i); 1323 if(i == 5) { 1324 mVideoEditor.removeAudioTrack("Audio Track1"); 1325 } 1326 } 1327 // We will sleep for some time & do an Explicit GC, So that we can get 1328 // real memory snapshot 1329 System.gc(); 1330 Thread.sleep(2500); 1331 final Runtime runtimeObjEnd1 = Runtime.getRuntime(); 1332 final long javaMemEnd1 = runtimeObjEnd.totalMemory(); 1333 final long nativeMemEnd1 = Debug.getNativeHeapAllocatedSize(); 1334 loggingInfo[2] = "\nAfter removal:\nJava Memory at Start = " + 1335 javaMemStart1 + "\n\tJava Memory at End = " + javaMemEnd1 + 1336 "\n\tJava Memory (End - Start) = " + (javaMemEnd1 - javaMemStart1); 1337 loggingInfo[3] = "Native Memory at Start = " + nativeMemStart1 + 1338 "\n\tNative Memory at End = " + nativeMemEnd1 + 1339 "\n\tNative Memory (End-Start)= " + (nativeMemEnd1-nativeMemStart1); 1340 writeTimingInfo("testStressOverlayTransKenBurn", loggingInfo); 1341 } 1342 1343 /** 1344 * To test the performance : With an audio track with Video 1345 * 1346 * @throws Exception 1347 */ 1348 // TODO : remove TC_STR_012 1349 @LargeTest 1350 public void testStressAudioTrackVideo() throws Exception { 1351 final String videoItemFileName1 = INPUT_FILE_PATH + 1352 "H264_BP_1080x720_30fps_800kbps_1_17.mp4"; 1353 final String audioFilename1 = INPUT_FILE_PATH + 1354 "AACLC_44.1kHz_256kbps_s_1_17.mp4"; 1355 final String audioFilename2 = INPUT_FILE_PATH + 1356 "AMRNB_8KHz_12.2Kbps_m_1_17.3gp"; 1357 final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; 1358 final int audioVolume = 50; 1359 final String[] loggingInfo = new String[4]; 1360 1361 // Take snapShot of Java and Native Memory 1362 // System gC 1363 System.gc(); 1364 final Runtime runtimeObjStart = Runtime.getRuntime(); 1365 final long javaMemStart = runtimeObjStart.totalMemory(); 1366 final long nativeMemStart = Debug.getNativeHeapAllocatedSize(); 1367 1368 final MediaVideoItem mediaVideoItem = new MediaVideoItem(mVideoEditor, 1369 "mediaItem1", videoItemFileName1, renderingMode); 1370 mVideoEditor.addMediaItem(mediaVideoItem); 1371 1372 final AudioTrack audioTrack1 = new AudioTrack(mVideoEditor, 1373 "Audio Track1", audioFilename1); 1374 audioTrack1.disableDucking(); 1375 audioTrack1.setVolume(audioVolume); 1376 mVideoEditor.addAudioTrack(audioTrack1); 1377 1378 mVideoEditor.generatePreview(new MediaProcessingProgressListener() { 1379 public void onProgress(Object item, int action, int progress) { 1380 } 1381 }); 1382 1383 mVideoEditor.removeAudioTrack("Audio Track1"); 1384 1385 final AudioTrack audioTrack2 = new AudioTrack(mVideoEditor, 1386 "Audio Track2", audioFilename2); 1387 audioTrack2.enableLoop(); 1388 1389 mVideoEditor.generatePreview(new MediaProcessingProgressListener() { 1390 public void onProgress(Object item, int action, int progress) { 1391 } 1392 }); 1393 1394 // We will sleep for some time & do an Explicit GC, So that we can get 1395 // real memory snapshot 1396 System.gc(); 1397 Thread.sleep(2500); 1398 final Runtime runtimeObjEnd = Runtime.getRuntime(); 1399 final long javaMemEnd = runtimeObjEnd.totalMemory(); 1400 final long nativeMemEnd = Debug.getNativeHeapAllocatedSize(); 1401 loggingInfo[0] = "Java Memory at Start = " + javaMemStart + 1402 "\t\tJava Memory at End = " + javaMemEnd + 1403 "\t\tJava Memory (End - Start) = " + (javaMemEnd - javaMemStart); 1404 loggingInfo[1] = "Native Memory at Start = " + nativeMemStart + 1405 "\tNative Memory at End = " + nativeMemEnd + 1406 "\t\tNative Memory (End-Start) = " + (nativeMemEnd - nativeMemStart); 1407 1408 /** Remove items and check for memory leak if any */ 1409 // Take snapShot of Java and Native Memory, do a GC 1410 System.gc(); 1411 final Runtime runtimeObjStart1 = Runtime.getRuntime(); 1412 final long javaMemStart1 = runtimeObjStart.totalMemory(); 1413 final long nativeMemStart1 = Debug.getNativeHeapAllocatedSize(); 1414 1415 mVideoEditor.removeMediaItem("mediaItem1"); 1416 1417 // We will sleep for some time & do an Explicit GC, So that we can get 1418 // real memory snapshot 1419 System.gc(); 1420 Thread.sleep(2500); 1421 final Runtime runtimeObjEnd1 = Runtime.getRuntime(); 1422 final long javaMemEnd1 = runtimeObjEnd.totalMemory(); 1423 final long nativeMemEnd1 = Debug.getNativeHeapAllocatedSize(); 1424 loggingInfo[2] = "\nAfter removal:\nJava Memory at Start = " + 1425 javaMemStart1 + "\n\tJava Memory at End = " + javaMemEnd1 + 1426 "\n\tJava Memory (End - Start) = " + (javaMemEnd1 - javaMemStart1); 1427 loggingInfo[3] = "Native Memory at Start = " + nativeMemStart1 + 1428 "\n\tNative Memory at End = " + nativeMemEnd1 + 1429 "\n\tNative Memory (End-Start)= " + (nativeMemEnd1-nativeMemStart1); 1430 1431 writeTimingInfo("testStressAudioTrackVideo", loggingInfo); 1432 } 1433 1434 /** 1435 * To Test Stress : Story Board creation with out preview or export 1436 * 1437 * @throws Exception 1438 */ 1439 // TODO : remove TC_STR_013 1440 @LargeTest 1441 public void testStressStoryBoard() throws Exception { 1442 final String videoItemFileName1 = INPUT_FILE_PATH + 1443 "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_161kbps_s_0_26.mp4"; 1444 final String videoItemFileName2 = INPUT_FILE_PATH + 1445 "MPEG4_SP_854x480_15fps_256kbps_AACLC_16khz_48kbps_s_0_26.mp4"; 1446 final String videoItemFileName3= INPUT_FILE_PATH + 1447 "MPEG4_SP_640x480_15fps_512kbps_AACLC_48khz_132kbps_s_0_26.mp4"; 1448 final String imageItemFileName4 = INPUT_FILE_PATH + 1449 "IMG_1600x1200.jpg"; 1450 final String imageItemFileName5 = INPUT_FILE_PATH + 1451 "IMG_176x144.jpg"; 1452 final String audioFilename6 = INPUT_FILE_PATH + 1453 "AMRNB_8KHz_12.2Kbps_m_1_17.3gp"; 1454 final String audioFilename7 = INPUT_FILE_PATH + 1455 "AACLC_44.1kHz_256kbps_s_1_17.mp4"; 1456 1457 final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; 1458 final int audioVolume = 50; 1459 final String[] loggingInfo = new String[4]; 1460 1461 // Take snapShot of Java and Native Memory 1462 // System gC 1463 System.gc(); 1464 final Runtime runtimeObjStart = Runtime.getRuntime(); 1465 final long javaMemStart = runtimeObjStart.totalMemory(); 1466 final long nativeMemStart = Debug.getNativeHeapAllocatedSize(); 1467 1468 final MediaVideoItem mediaItem1 = new MediaVideoItem(mVideoEditor, 1469 "m1", videoItemFileName1, renderingMode); 1470 mediaItem1.setExtractBoundaries(0, 10000); 1471 mVideoEditor.addMediaItem(mediaItem1); 1472 1473 final MediaVideoItem mediaItem2 = new MediaVideoItem(mVideoEditor, 1474 "m2", videoItemFileName2, renderingMode); 1475 mediaItem2.setExtractBoundaries(mediaItem2.getDuration()/4, 1476 mediaItem2.getDuration()/2); 1477 mVideoEditor.addMediaItem(mediaItem2); 1478 1479 final MediaVideoItem mediaItem3 = new MediaVideoItem(mVideoEditor, 1480 "m3", videoItemFileName3, renderingMode); 1481 mediaItem3.setExtractBoundaries(mediaItem3.getDuration()/2, 1482 mediaItem3.getDuration()); 1483 mVideoEditor.addMediaItem(mediaItem3); 1484 1485 final MediaImageItem mediaItem4 = new MediaImageItem(mVideoEditor, 1486 "m4", imageItemFileName4, 5000, renderingMode); 1487 mVideoEditor.addMediaItem(mediaItem4); 1488 1489 final MediaImageItem mediaItem5 = new MediaImageItem(mVideoEditor, 1490 "m5", imageItemFileName5, 5000, renderingMode); 1491 mVideoEditor.addMediaItem(mediaItem5); 1492 1493 final TransitionCrossfade tranCrossfade = 1494 new TransitionCrossfade("transCF", mediaItem2, mediaItem3, 2500, 1495 Transition.BEHAVIOR_MIDDLE_FAST); 1496 mVideoEditor.addTransition(tranCrossfade); 1497 1498 final TransitionCrossfade tranCrossfade1 = 1499 new TransitionCrossfade("transCF1", mediaItem3, mediaItem4, 2500, 1500 Transition.BEHAVIOR_MIDDLE_FAST); 1501 mVideoEditor.addTransition(tranCrossfade1); 1502 1503 final AudioTrack audioTrack1 = new AudioTrack(mVideoEditor, 1504 "Audio Track1", audioFilename6); 1505 mVideoEditor.addAudioTrack(audioTrack1); 1506 1507 mVideoEditor.removeAudioTrack("Audio Track1"); 1508 final AudioTrack audioTrack2 = new AudioTrack(mVideoEditor, 1509 "Audio Track2", audioFilename7); 1510 mVideoEditor.addAudioTrack(audioTrack2); 1511 audioTrack2.enableLoop(); 1512 1513 // We will sleep for some time & do an Explicit GC, So that we can get 1514 // real memory snapshot 1515 System.gc(); 1516 Thread.sleep(2500); 1517 final Runtime runtimeObjEnd = Runtime.getRuntime(); 1518 final long javaMemEnd = runtimeObjEnd.totalMemory(); 1519 final long nativeMemEnd = Debug.getNativeHeapAllocatedSize(); 1520 loggingInfo[0] = "Java Memory at Start = " + javaMemStart + 1521 "\t\tJava Memory at End = " + javaMemEnd + 1522 "\t\tJava Memory (End - Start) = " + (javaMemEnd - javaMemStart); 1523 loggingInfo[1] = "Native Memory at Start = " + nativeMemStart + 1524 "\tNative Memory at End = " + nativeMemEnd + 1525 "\t\tNative Memory (End-Start) = " + (nativeMemEnd - nativeMemStart); 1526 1527 1528 /** Remove items and check for memory leak if any */ 1529 // Take snapShot of Java and Native Memory, do a GC 1530 System.gc(); 1531 final Runtime runtimeObjStart1 = Runtime.getRuntime(); 1532 final long javaMemStart1 = runtimeObjStart.totalMemory(); 1533 final long nativeMemStart1 = Debug.getNativeHeapAllocatedSize(); 1534 1535 mVideoEditor.removeAudioTrack("Audio Track2"); 1536 mVideoEditor.removeTransition("transCF"); 1537 mVideoEditor.removeTransition("transCF1"); 1538 mVideoEditor.removeMediaItem("m5"); 1539 mVideoEditor.removeMediaItem("m4"); 1540 mVideoEditor.removeMediaItem("m3"); 1541 mVideoEditor.removeMediaItem("m2"); 1542 mVideoEditor.removeMediaItem("m1"); 1543 1544 // We will sleep for some time & do an Explicit GC, So that we can get 1545 // real memory snapshot 1546 System.gc(); 1547 Thread.sleep(2500); 1548 final Runtime runtimeObjEnd1 = Runtime.getRuntime(); 1549 final long javaMemEnd1 = runtimeObjEnd.totalMemory(); 1550 final long nativeMemEnd1 = Debug.getNativeHeapAllocatedSize(); 1551 loggingInfo[2] = "\nAfter removal:\nJava Memory at Start = " + 1552 javaMemStart1 + "\n\tJava Memory at End = " + javaMemEnd1 + 1553 "\n\tJava Memory (End - Start) = " + (javaMemEnd1 - javaMemStart1); 1554 loggingInfo[3] = "Native Memory at Start = " + nativeMemStart1 + 1555 "\n\tNative Memory at End = " + nativeMemEnd1 + 1556 "\n\tNative Memory (End-Start)= " + (nativeMemEnd1-nativeMemStart1); 1557 1558 writeTimingInfo("testStressStoryBoard", loggingInfo); 1559 1560 } 1561 1562 /** 1563 * To test the performance : With an audio track Only 1564 * 1565 * @throws Exception 1566 */ 1567 // TODO : remove TC_STR_014 1568 @LargeTest 1569 public void testStressAudioTrackOnly() throws Exception { 1570 1571 final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; 1572 final String AudioItemFileName1 = INPUT_FILE_PATH + 1573 "AACLC_44.1kHz_256kbps_s_1_17.mp4"; 1574 final String[] loggingInfo = new String[2]; 1575 // Take snapShot of Java and Native Memory 1576 // System gC 1577 System.gc(); 1578 final Runtime runtimeObjStart = Runtime.getRuntime(); 1579 final long javaMemStart = runtimeObjStart.totalMemory(); 1580 final long nativeMemStart = Debug.getNativeHeapAllocatedSize(); 1581 1582 for (int i = 0; i < 200; i++) { 1583 final AudioTrack mediaItem1 = new AudioTrack(mVideoEditor, 1584 "m1" + i, AudioItemFileName1); 1585 mVideoEditor.addAudioTrack(mediaItem1); 1586 mediaItem1.enableLoop(); 1587 mVideoEditor.removeAudioTrack("m1" + i); 1588 } 1589 // We will sleep for some time & do an Explicit GC, So that we can get 1590 // real memory snapshot 1591 System.gc(); 1592 Thread.sleep(2500); 1593 final Runtime runtimeObjEnd = Runtime.getRuntime(); 1594 final long javaMemEnd = runtimeObjEnd.totalMemory(); 1595 final long nativeMemEnd = Debug.getNativeHeapAllocatedSize(); 1596 loggingInfo[0] = "Java Memory at Start = " + javaMemStart + 1597 "\t\tJava Memory at End = " + javaMemEnd + 1598 "\t\tJava Memory (End - Start) = " + (javaMemEnd - javaMemStart); 1599 loggingInfo[1] = "Native Memory at Start = " + nativeMemStart + 1600 "\tNative Memory at End = " + nativeMemEnd + 1601 "\t\tNative Memory (End-Start) = " + (nativeMemEnd - nativeMemStart); 1602 writeTimingInfo("testStressAudioTrackOnly", loggingInfo); 1603 } 1604 1605 /** 1606 * This method will test thumbnail list extraction in a loop = 200 for Image 1607 * Item 1608 * 1609 * @throws Exception 1610 */ 1611 // TODO : remove TC_STR_016 -- New Test Case 1612 @LargeTest 1613 public void testStressThumbnailImageItem() throws Exception { 1614 final String imageItemFileName = INPUT_FILE_PATH + "IMG_640x480.jpg"; 1615 final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; 1616 final String[] loggingInfo = new String[2]; 1617 1618 final MediaImageItem mediaImageItem = new MediaImageItem(mVideoEditor, 1619 "m1", imageItemFileName, 5000, renderingMode); 1620 // Take snapShot of Java and Native Memory 1621 // System gC 1622 System.gc(); 1623 final Runtime runtimeObjStart = Runtime.getRuntime(); 1624 final long javaMemStart = runtimeObjStart.totalMemory(); 1625 final long nativeMemStart = Debug.getNativeHeapAllocatedSize(); 1626 for (int i = 0; i < 200; i++) { 1627 if (i % 4 == 0) { 1628 final Bitmap[] thumbNails = mediaImageItem.getThumbnailList( 1629 mediaImageItem.getWidth() / 2 , 1630 mediaImageItem.getHeight() / 2, i, 5000, 2); 1631 // Recycle this Bitmap array 1632 for (int i1 = 0; i1 < thumbNails.length; i1++) { 1633 thumbNails[i1].recycle(); 1634 } 1635 } 1636 if (i % 4 == 1) { 1637 final Bitmap[] thumbNails = mediaImageItem.getThumbnailList( 1638 mediaImageItem.getWidth() / 2, 1639 mediaImageItem.getHeight() * 3, i, 5000, 2); 1640 // Recycle this Bitmap array 1641 for (int i1 = 0; i1 < thumbNails.length; i1++) { 1642 thumbNails[i1].recycle(); 1643 } 1644 } 1645 if (i % 4 == 2) { 1646 final Bitmap[] thumbNails = mediaImageItem.getThumbnailList( 1647 mediaImageItem.getWidth() * 2, 1648 mediaImageItem.getHeight() / 3, i, 5000, 2); 1649 // Recycle this Bitmap array 1650 for (int i1 = 0; i1 < thumbNails.length; i1++) { 1651 thumbNails[i1].recycle(); 1652 } 1653 } 1654 if (i % 4 == 3) { 1655 final Bitmap[] thumbNails = mediaImageItem.getThumbnailList( 1656 mediaImageItem.getWidth(), 1657 mediaImageItem.getHeight(), i, 5000, 2); 1658 // Recycle this Bitmap array 1659 for (int i1 = 0; i1 < thumbNails.length; i1++) { 1660 thumbNails[i1].recycle(); 1661 } 1662 } 1663 } 1664 // We will sleep for some time & do an Explicit GC, So that we can get 1665 // real memory snapshot 1666 System.gc(); 1667 Thread.sleep(2500); 1668 final Runtime runtimeObjEnd = Runtime.getRuntime(); 1669 final long javaMemEnd = runtimeObjEnd.totalMemory(); 1670 final long nativeMemEnd = Debug.getNativeHeapAllocatedSize(); 1671 loggingInfo[0] = "Java Memory at Start = " + javaMemStart + 1672 "\t\tJava Memory at End = " + javaMemEnd + 1673 "\t\tJava Memory (End - Start) = " + (javaMemEnd - javaMemStart); 1674 loggingInfo[1] = "Native Memory at Start = " + nativeMemStart + 1675 "\tNative Memory at End = " + nativeMemEnd + 1676 "\t\tNative Memory (End-Start) = " + (nativeMemEnd - nativeMemStart); 1677 writeTimingInfo("testStressThumbnailImageItem", loggingInfo); 1678 } 1679 1680 1681 1682} 1683