summaryrefslogtreecommitdiffstats
path: root/media/libmediaplayerservice/StagefrightRecorder.cpp
diff options
context:
space:
mode:
authorChong Zhang <chz@google.com>2015-02-20 16:40:04 -0800
committerChong Zhang <chz@google.com>2015-02-23 14:22:30 -0800
commit9ee53a49860e91c2b012883eef09d669a7829e06 (patch)
tree902cb3ebd35c41dc9b2a6188dbe0d1561335f334 /media/libmediaplayerservice/StagefrightRecorder.cpp
parent96faa25f4aea2c792523ae920da91f919f5ea392 (diff)
downloadframeworks_av-9ee53a49860e91c2b012883eef09d669a7829e06.zip
frameworks_av-9ee53a49860e91c2b012883eef09d669a7829e06.tar.gz
frameworks_av-9ee53a49860e91c2b012883eef09d669a7829e06.tar.bz2
MediaRecorder: pass capture fps in float
bug: 19460202 Change-Id: Ic8f2dc02dfd482c4b2065b16e28721fc6e3cf696
Diffstat (limited to 'media/libmediaplayerservice/StagefrightRecorder.cpp')
-rw-r--r--media/libmediaplayerservice/StagefrightRecorder.cpp45
1 files changed, 36 insertions, 9 deletions
diff --git a/media/libmediaplayerservice/StagefrightRecorder.cpp b/media/libmediaplayerservice/StagefrightRecorder.cpp
index 887d4ec..55763f0 100644
--- a/media/libmediaplayerservice/StagefrightRecorder.cpp
+++ b/media/libmediaplayerservice/StagefrightRecorder.cpp
@@ -75,6 +75,7 @@ StagefrightRecorder::StagefrightRecorder()
mAudioSource(AUDIO_SOURCE_CNT),
mVideoSource(VIDEO_SOURCE_LIST_END),
mCaptureTimeLapse(false),
+ mCaptureFps(0.0f),
mStarted(false) {
ALOGV("Constructor");
@@ -263,6 +264,31 @@ status_t StagefrightRecorder::setOutputFile(int fd, int64_t offset, int64_t leng
return OK;
}
+// Attempt to parse an float literal optionally surrounded by whitespace,
+// returns true on success, false otherwise.
+static bool safe_strtof(const char *s, float *val) {
+ char *end;
+
+ // It is lame, but according to man page, we have to set errno to 0
+ // before calling strtof().
+ errno = 0;
+ *val = strtof(s, &end);
+
+ if (end == s || errno == ERANGE) {
+ return false;
+ }
+
+ // Skip trailing whitespace
+ while (isspace(*end)) {
+ ++end;
+ }
+
+ // For a successful return, the string must contain nothing but a valid
+ // float literal optionally surrounded by whitespace.
+
+ return *end == '\0';
+}
+
// Attempt to parse an int64 literal optionally surrounded by whitespace,
// returns true on success, false otherwise.
static bool safe_strtoi64(const char *s, int64_t *val) {
@@ -546,8 +572,10 @@ status_t StagefrightRecorder::setParamTimeLapseEnable(int32_t timeLapseEnable) {
return OK;
}
-status_t StagefrightRecorder::setParamTimeBetweenTimeLapseFrameCapture(int64_t timeUs) {
- ALOGV("setParamTimeBetweenTimeLapseFrameCapture: %lld us", timeUs);
+status_t StagefrightRecorder::setParamTimeLapseFps(float fps) {
+ ALOGV("setParamTimeLapseFps: %.2f", fps);
+
+ int64_t timeUs = (int64_t) (1000000.0 / fps + 0.5f);
// Not allowing time more than a day
if (timeUs <= 0 || timeUs > 86400*1E6) {
@@ -555,6 +583,7 @@ status_t StagefrightRecorder::setParamTimeBetweenTimeLapseFrameCapture(int64_t t
return BAD_VALUE;
}
+ mCaptureFps = fps;
mTimeBetweenTimeLapseFrameCaptureUs = timeUs;
return OK;
}
@@ -682,11 +711,10 @@ status_t StagefrightRecorder::setParameter(
if (safe_strtoi32(value.string(), &timeLapseEnable)) {
return setParamTimeLapseEnable(timeLapseEnable);
}
- } else if (key == "time-between-time-lapse-frame-capture") {
- int64_t timeBetweenTimeLapseFrameCaptureUs;
- if (safe_strtoi64(value.string(), &timeBetweenTimeLapseFrameCaptureUs)) {
- return setParamTimeBetweenTimeLapseFrameCapture(
- timeBetweenTimeLapseFrameCaptureUs);
+ } else if (key == "time-lapse-fps") {
+ float fps;
+ if (safe_strtof(value.string(), &fps)) {
+ return setParamTimeLapseFps(fps);
}
} else {
ALOGE("setParameter: failed to find key %s", key.string());
@@ -1619,8 +1647,7 @@ status_t StagefrightRecorder::setupMPEG4orWEBMRecording() {
}
if (mCaptureTimeLapse) {
- // TODO(chz): pass down fps in float from MediaRecorder.java
- mp4writer->setCaptureRate(1000000.0f / mTimeBetweenTimeLapseFrameCaptureUs);
+ mp4writer->setCaptureRate(mCaptureFps);
}
if (mInterleaveDurationUs > 0) {