diff options
author | James Dong <jdong@google.com> | 2010-05-26 17:01:16 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-05-26 17:01:16 -0700 |
commit | 5b39604a55f1624ced347da7b790c4206d2d999f (patch) | |
tree | 71bde464029685210f228e6a8e43e9b4f1f71097 /media | |
parent | 5a4001ddb2536d65d966970fc0579bf6bd11b5a0 (diff) | |
parent | cbe48a0678729eb863b259b4744e6ad12faf0475 (diff) | |
download | frameworks_av-5b39604a55f1624ced347da7b790c4206d2d999f.zip frameworks_av-5b39604a55f1624ced347da7b790c4206d2d999f.tar.gz frameworks_av-5b39604a55f1624ced347da7b790c4206d2d999f.tar.bz2 |
Merge "Avoid repeatedly allocating and freeing memory in CameraSource" into kraken
Diffstat (limited to 'media')
-rw-r--r-- | media/libstagefright/CameraSource.cpp | 28 |
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); |