Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
Merge "Size limit reaches for video recording even before time lapse …
Browse files Browse the repository at this point in the history
…from Messaging" into jb-mr1-dev
  • Loading branch information
Tom Taylor authored and Android (Google) Code Review committed Oct 19, 2012
2 parents 868f2d2 + bd9d9bc commit 9f12dda
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/com/android/mms/ui/MessageUtils.java
Expand Up @@ -97,6 +97,9 @@ interface ResizeImageResultCallback {
private static final Map<String, String> sRecipientAddress =
new ConcurrentHashMap<String, String>(20 /* initial capacity */);

// When we pass a video record duration to the video recorder, use one of these values.
private static final int[] sVideoDuration =
new int[] {0, 5, 10, 15, 20, 30, 40, 50, 60, 90, 120};

/**
* MMS address parsing data structures
Expand Down Expand Up @@ -494,7 +497,7 @@ public static void recordVideo(Activity activity, int requestCode, long sizeLimi
// say we can handle. Try to handle that overshoot by specifying an 85% limit.
sizeLimit *= .85F;

int durationLimit = getVideoCaptureDurationLimit();
int durationLimit = getVideoCaptureDurationLimit(sizeLimit);

if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
log("recordVideo: durationLimit: " + durationLimit +
Expand All @@ -515,9 +518,22 @@ public static void capturePicture(Activity activity, int requestCode) {
activity.startActivityForResult(intent, requestCode);
}

private static int getVideoCaptureDurationLimit() {
// Public for until tests
public static int getVideoCaptureDurationLimit(long bytesAvailable) {
CamcorderProfile camcorder = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW);
return camcorder == null ? 0 : camcorder.duration;
if (camcorder == null) {
return 0;
}
bytesAvailable *= 8; // convert to bits
long seconds = bytesAvailable / (camcorder.audioBitRate + camcorder.videoBitRate);

// Find the best match for one of the fixed durations
for (int i = sVideoDuration.length - 1; i >= 0; i--) {
if (seconds >= sVideoDuration[i]) {
return sVideoDuration[i];
}
}
return 0;
}

public static void selectVideo(Context context, int requestCode) {
Expand Down
47 changes: 47 additions & 0 deletions tests/src/com/android/mms/util/VideoCaptureTests.java
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2012 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 com.android.mms.util;

import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import com.android.mms.ui.MessageUtils;

/**
* Unit tests for Video Capture utilities.
*
* To run the test:
* runtest --test-class=com.android.mms.util.VideoCaptureTests mms
*/
@SmallTest
public class VideoCaptureTests extends AndroidTestCase {

@Override
protected void setUp() throws Exception {
super.setUp();
}

/**
* Test the function that computes rounded video record times.
*/
public void testVideoCaptureDurationLimit() {
assertEquals(MessageUtils.getVideoCaptureDurationLimit(0), 0); // 0 -> 0 secs
assertEquals(MessageUtils.getVideoCaptureDurationLimit(100), 0); // 0 -> 0 secs
assertEquals(MessageUtils.getVideoCaptureDurationLimit(500000), 20); // 28 -> 20 secs
assertEquals(MessageUtils.getVideoCaptureDurationLimit(1000000), 50); // 57 -> 50 secs
assertEquals(MessageUtils.getVideoCaptureDurationLimit(10000000), 120); // 570 -> 120 secs
}
}

0 comments on commit 9f12dda

Please sign in to comment.