diff options
Diffstat (limited to 'modules/camera/Metadata.cpp')
-rw-r--r-- | modules/camera/Metadata.cpp | 80 |
1 files changed, 67 insertions, 13 deletions
diff --git a/modules/camera/Metadata.cpp b/modules/camera/Metadata.cpp index 77f5405..362a087 100644 --- a/modules/camera/Metadata.cpp +++ b/modules/camera/Metadata.cpp @@ -33,7 +33,9 @@ Metadata::Metadata() : mHead(NULL), mTail(NULL), mEntryCount(0), - mDataCount(0) + mDataCount(0), + mGenerated(NULL), + mDirty(true) { // NULL (default) pthread mutex attributes pthread_mutex_init(&mMutex, NULL); @@ -41,6 +43,37 @@ Metadata::Metadata() Metadata::~Metadata() { + if (mGenerated != NULL) + free_camera_metadata(mGenerated); +} + +Metadata::Metadata(uint8_t mode, uint8_t intent) + : mHead(NULL), + mTail(NULL), + mEntryCount(0), + mDataCount(0), + mGenerated(NULL), + mDirty(true) +{ + pthread_mutex_init(&mMutex, NULL); + + if (validate(ANDROID_CONTROL_MODE, TYPE_BYTE, 1)) { + int res = add(ANDROID_CONTROL_MODE, 1, &mode); + if (res != 0) { + ALOGE("%s: Unable to add mode to template!", __func__); + } + } else { + ALOGE("%s: Invalid mode constructing template!", __func__); + } + + if (validate(ANDROID_CONTROL_CAPTURE_INTENT, TYPE_BYTE, 1)) { + int res = add(ANDROID_CONTROL_CAPTURE_INTENT, 1, &intent); + if (res != 0) { + ALOGE("%s: Unable to add capture intent to template!", __func__); + } + } else { + ALOGE("%s: Invalid capture intent constructing template!", __func__); + } } int Metadata::addUInt8(uint32_t tag, int count, uint8_t *data) @@ -113,33 +146,54 @@ int Metadata::add(uint32_t tag, int count, void *tag_data) return -ENOMEM; memcpy(data, tag_data, count * type_sz); + pthread_mutex_lock(&mMutex); mEntryCount++; mDataCount += calculate_camera_metadata_entry_data_size(tag_type, count); push(new Entry(tag, data, count)); + mDirty = true; + pthread_mutex_unlock(&mMutex); return 0; } camera_metadata_t* Metadata::generate() { - Entry *current = mHead; + Entry *current; pthread_mutex_lock(&mMutex); + // Reuse if old generated metadata still valid + if (!mDirty && mGenerated != NULL) { + ALOGV("%s: Reusing generated metadata at %p", __func__, mGenerated); + goto out; + } + // Destroy old metadata + if (mGenerated != NULL) { + ALOGV("%s: Freeing generated metadata at %p", __func__, mGenerated); + free_camera_metadata(mGenerated); + mGenerated = NULL; + } + // Generate new metadata structure + ALOGV("%s: Generating new camera metadata structure, Entries:%d Data:%d", + __func__, mEntryCount, mDataCount); + mGenerated = allocate_camera_metadata(mEntryCount, mDataCount); if (mGenerated == NULL) { - ALOGV("Generating new camera metadata structure"); - mGenerated = allocate_camera_metadata(mEntryCount, mDataCount); - if (mGenerated == NULL) { - ALOGE("%s: Failed to allocate metadata (%d entries %d data)", - __func__, mEntryCount, mDataCount); - } + ALOGE("%s: Failed to allocate metadata (%d entries %d data)", + __func__, mEntryCount, mDataCount); + goto out; } // Walk list of entries adding each one to newly allocated metadata - while (current != NULL) { - add_camera_metadata_entry(mGenerated, current->mTag, current->mData, - current->mCount); - current = current->mNext; + for (current = mHead; current != NULL; current = current->mNext) { + int res = add_camera_metadata_entry(mGenerated, current->mTag, + current->mData, current->mCount); + if (res != 0) { + ALOGE("%s: Failed to add camera metadata: %d", __func__, res); + free_camera_metadata(mGenerated); + mGenerated = NULL; + goto out; + } } - pthread_mutex_unlock(&mMutex); +out: + pthread_mutex_unlock(&mMutex); return mGenerated; } |