Bug 1004434 - MaxFileSize, MaxVideoLength of CameraControl Interface recording options should be of 64 bits. r=dhylands, r=bzbarsky

--HG--
extra : rebase_source : 50b6301e11c09cc82bd42e99a738b565c0039bcb
This commit is contained in:
Mike Habicher 2014-05-14 17:33:00 -04:00
Родитель e23b619846
Коммит de3c473c32
5 изменённых файлов: 45 добавлений и 24 удалений

Просмотреть файл

@ -1540,8 +1540,8 @@ nsGonkCameraControl::OnRecorderEvent(int msg, int ext1, int ext2)
nsresult
nsGonkCameraControl::SetupRecording(int aFd, int aRotation,
int64_t aMaxFileSizeBytes,
int64_t aMaxVideoLengthMs)
uint64_t aMaxFileSizeBytes,
uint64_t aMaxVideoLengthMs)
{
RETURN_IF_NO_CAMERA_HW();
@ -1550,26 +1550,39 @@ nsGonkCameraControl::SetupRecording(int aFd, int aRotation,
char buffer[SIZE];
mRecorder = new GonkRecorder();
CHECK_SETARG(mRecorder->init());
CHECK_SETARG_RETURN(mRecorder->init(), NS_ERROR_FAILURE);
nsresult rv = mRecorderProfile->ConfigureRecorder(mRecorder);
NS_ENSURE_SUCCESS(rv, rv);
CHECK_SETARG(mRecorder->setCamera(mCameraHw));
CHECK_SETARG_RETURN(mRecorder->setCamera(mCameraHw), NS_ERROR_FAILURE);
DOM_CAMERA_LOGI("maxVideoLengthMs=%lld\n", aMaxVideoLengthMs);
DOM_CAMERA_LOGI("maxVideoLengthMs=%llu\n", aMaxVideoLengthMs);
const uint64_t kMaxVideoLengthMs = INT64_MAX / 1000;
if (aMaxVideoLengthMs == 0) {
aMaxVideoLengthMs = -1;
} else if (aMaxVideoLengthMs > kMaxVideoLengthMs) {
// GonkRecorder parameters are internally limited to signed 64-bit values,
// and the time length limit is converted from milliseconds to microseconds,
// so we limit this value to prevent any unexpected overflow weirdness.
DOM_CAMERA_LOGW("maxVideoLengthMs capped to %lld\n", kMaxVideoLengthMs);
aMaxVideoLengthMs = kMaxVideoLengthMs;
}
snprintf(buffer, SIZE, "max-duration=%lld", aMaxVideoLengthMs);
CHECK_SETARG(mRecorder->setParameters(String8(buffer)));
CHECK_SETARG_RETURN(mRecorder->setParameters(String8(buffer)),
NS_ERROR_INVALID_ARG);
DOM_CAMERA_LOGI("maxFileSizeBytes=%lld\n", aMaxFileSizeBytes);
DOM_CAMERA_LOGI("maxFileSizeBytes=%llu\n", aMaxFileSizeBytes);
if (aMaxFileSizeBytes == 0) {
aMaxFileSizeBytes = -1;
} else if (aMaxFileSizeBytes > INT64_MAX) {
// GonkRecorder parameters are internally limited to signed 64-bit values
DOM_CAMERA_LOGW("maxFileSizeBytes capped to INT64_MAX\n");
aMaxFileSizeBytes = INT64_MAX;
}
snprintf(buffer, SIZE, "max-filesize=%lld", aMaxFileSizeBytes);
CHECK_SETARG(mRecorder->setParameters(String8(buffer)));
CHECK_SETARG_RETURN(mRecorder->setParameters(String8(buffer)),
NS_ERROR_INVALID_ARG);
// adjust rotation by camera sensor offset
int r = aRotation;
@ -1577,13 +1590,15 @@ nsGonkCameraControl::SetupRecording(int aFd, int aRotation,
r = RationalizeRotation(r);
DOM_CAMERA_LOGI("setting video rotation to %d degrees (mapped from %d)\n", r, aRotation);
snprintf(buffer, SIZE, "video-param-rotation-angle-degrees=%d", r);
CHECK_SETARG(mRecorder->setParameters(String8(buffer)));
CHECK_SETARG_RETURN(mRecorder->setParameters(String8(buffer)),
NS_ERROR_INVALID_ARG);
CHECK_SETARG(mRecorder->setListener(new GonkRecorderListener(this)));
CHECK_SETARG_RETURN(mRecorder->setListener(new GonkRecorderListener(this)),
NS_ERROR_FAILURE);
// recording API needs file descriptor of output file
CHECK_SETARG(mRecorder->setOutputFile(aFd, 0, 0));
CHECK_SETARG(mRecorder->prepare());
CHECK_SETARG_RETURN(mRecorder->setOutputFile(aFd, 0, 0), NS_ERROR_FAILURE);
CHECK_SETARG_RETURN(mRecorder->prepare(), NS_ERROR_FAILURE);
return NS_OK;
}

Просмотреть файл

@ -119,8 +119,8 @@ protected:
virtual already_AddRefed<RecorderProfileManager> GetRecorderProfileManagerImpl() MOZ_OVERRIDE;
already_AddRefed<GonkRecorderProfileManager> GetGonkRecorderProfileManager();
nsresult SetupRecording(int aFd, int aRotation, int64_t aMaxFileSizeBytes,
int64_t aMaxVideoLengthMs);
nsresult SetupRecording(int aFd, int aRotation, uint64_t aMaxFileSizeBytes,
uint64_t aMaxVideoLengthMs);
nsresult SetupRecordingFlash(bool aAutoEnableLowLightTorch);
nsresult SetupVideoMode(const nsAString& aProfile);
nsresult SetPreviewSize(const Size& aSize);

Просмотреть файл

@ -9,16 +9,19 @@
#include "CameraRecorderProfiles.h"
#include "ICameraControl.h"
#ifndef CHECK_SETARG
#define CHECK_SETARG(x) \
#ifndef CHECK_SETARG_RETURN
#define CHECK_SETARG_RETURN(x, rv) \
do { \
if (x) { \
DOM_CAMERA_LOGE(#x " failed\n"); \
return NS_ERROR_NOT_AVAILABLE; \
return rv; \
} \
} while(0)
#endif
#ifndef CHECK_SETARG
#define CHECK_SETARG(x) CHECK_SETARG_RETURN(x, NS_ERROR_NOT_AVAILABLE)
#endif
namespace android {
class GonkRecorder;

Просмотреть файл

@ -132,8 +132,8 @@ public:
struct StartRecordingOptions {
uint32_t rotation;
uint32_t maxFileSizeBytes;
uint32_t maxVideoLengthMs;
uint64_t maxFileSizeBytes;
uint64_t maxVideoLengthMs;
bool autoEnableLowLightTorch;
};

Просмотреть файл

@ -89,14 +89,17 @@ dictionary CameraPictureOptions
'maxVideoLengthMs' is the maximum length in milliseconds to which the
recorded video will be allowed to grow.
if either 'maxFileSizeBytes' or 'maxVideoLengthMs' is missing, zero,
or negative, that limit will be disabled.
if either 'maxFileSizeBytes' or 'maxVideoLengthMs' is missing or zero,
that limit will be disabled; if either value is out of range, it will
be clamped from 0 to the upper limit for an 'unsigned long long'.
*/
dictionary CameraStartRecordingOptions
{
long rotation = 0;
long long maxFileSizeBytes = 0;
long long maxVideoLengthMs = 0;
long rotation = 0;
[Clamp]
unsigned long long maxFileSizeBytes = 0;
[Clamp]
unsigned long long maxVideoLengthMs = 0;
/* If startRecording() is called with flashMode set to "auto" and the
camera has determined that the scene is poorly lit, the flash mode