summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/CameraSource.cpp
diff options
context:
space:
mode:
authorJames Dong <jdong@google.com>2010-05-20 02:44:49 -0700
committerJames Dong <jdong@google.com>2010-05-26 16:54:18 -0700
commitcbe48a0678729eb863b259b4744e6ad12faf0475 (patch)
treed0331f351a139dddc9fe42eacebbb964864132fa /media/libstagefright/CameraSource.cpp
parent1cb8fa1e670786bf83ccde7571c5ac1fc087d4f1 (diff)
downloadframeworks_av-cbe48a0678729eb863b259b4744e6ad12faf0475.zip
frameworks_av-cbe48a0678729eb863b259b4744e6ad12faf0475.tar.gz
frameworks_av-cbe48a0678729eb863b259b4744e6ad12faf0475.tar.bz2
Avoid repeatedly allocating and freeing memory in CameraSource
Change-Id: Ia3760820da0559e4e908dedae1f1df05f9a6a242
Diffstat (limited to 'media/libstagefright/CameraSource.cpp')
-rw-r--r--media/libstagefright/CameraSource.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/media/libstagefright/CameraSource.cpp b/media/libstagefright/CameraSource.cpp
index cd26e6b..87d7ebb 100644
--- a/media/libstagefright/CameraSource.cpp
+++ b/media/libstagefright/CameraSource.cpp
@@ -104,6 +104,7 @@ CameraSource::CameraSource(const sp<Camera> &camera)
mNumFramesReceived(0),
mNumFramesEncoded(0),
mNumFramesDropped(0),
+ mBufferGroup(NULL),
mStarted(false) {
String8 s = mCamera->getParameters();
printf("params: \"%s\"\n", s.string());
@@ -118,6 +119,23 @@ CameraSource::~CameraSource() {
}
}
+static int bytesPerPixelTimes10(const char *colorFormat) {
+ LOGI("color format: %s", colorFormat);
+ return 20;
+#if 0
+ // XXX: Fix Camera Hal bug?
+ // On sholes, it returns CameraParameters::PIXEL_FORMAT_YUV420SP???
+ if (!strcmp(colorFormat, CameraParameters::PIXEL_FORMAT_YUV422SP) ||
+ !strcmp(colorFormat, CameraParameters::PIXEL_FORMAT_YUV422I) ||
+ !strcmp(colorFormat, CameraParameters::PIXEL_FORMAT_RGB565)) {
+ return 20;
+ } else if (!strcmp(colorFormat, CameraParameters::PIXEL_FORMAT_YUV420SP)) {
+ return 15;
+ }
+ CHECK_EQ(0, "Unknown color format");
+#endif
+}
+
status_t CameraSource::start(MetaData *) {
LOGV("start");
CHECK(!mStarted);
@@ -126,6 +144,12 @@ status_t CameraSource::start(MetaData *) {
CHECK_EQ(OK, mCamera->startRecording());
mStarted = true;
+ mBufferGroup = new MediaBufferGroup();
+ String8 s = mCamera->getParameters();
+ CameraParameters params(s);
+ const char *colorFormat = params.getPreviewFormat();
+ const int size = (mWidth * mHeight * bytesPerPixelTimes10(colorFormat))/10;
+ mBufferGroup->add_buffer(new MediaBuffer(size));
return OK;
}
@@ -139,6 +163,8 @@ status_t CameraSource::stop() {
mCamera->stopRecording();
releaseQueuedFrames();
+ delete mBufferGroup;
+ mBufferGroup = NULL;
LOGI("Frames received/encoded/dropped: %d/%d/%d, timestamp (us) last/first: %lld/%lld",
mNumFramesReceived, mNumFramesEncoded, mNumFramesDropped,
mLastFrameTimestampUs, mFirstFrameTimeUs);
@@ -197,7 +223,7 @@ status_t CameraSource::read(
++mNumFramesEncoded;
}
- *buffer = new MediaBuffer(frame->size());
+ mBufferGroup->acquire_buffer(buffer);
memcpy((*buffer)->data(), frame->pointer(), frame->size());
(*buffer)->set_range(0, frame->size());
mCamera->releaseRecordingFrame(frame);