summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chong Zhang <chz@google.com> 2018-03-22 17:39:52 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2018-03-22 17:39:52 +0000
commit9e64c01d02d8054a78efc60b333ccf86499a337f (patch)
tree239c5df4aa3879832bc1b3691421c8f246141ebc
parentde6dfd93e5531e8111043c3b21af0d66b32f175f (diff)
parent63f819203de3a029f2397510c48101b343441df3 (diff)
Merge "heif: fix Exif extraction in mtp database" into pi-dev
-rw-r--r--media/jni/android_mtp_MtpDatabase.cpp50
1 files changed, 48 insertions, 2 deletions
diff --git a/media/jni/android_mtp_MtpDatabase.cpp b/media/jni/android_mtp_MtpDatabase.cpp
index 23ef84f6ad90..12d7440e3762 100644
--- a/media/jni/android_mtp_MtpDatabase.cpp
+++ b/media/jni/android_mtp_MtpDatabase.cpp
@@ -39,6 +39,7 @@ extern "C" {
#include <android_runtime/AndroidRuntime.h>
#include <android_runtime/Log.h>
#include <jni.h>
+#include <media/stagefright/NuMediaExtractor.h>
#include <nativehelper/JNIHelp.h>
#include <nativehelper/ScopedLocalRef.h>
@@ -788,6 +789,41 @@ static long getLongFromExifEntry(ExifEntry *e) {
return exif_get_long(e->data, o);
}
+static ExifData *getExifFromExtractor(const char *path) {
+ std::unique_ptr<uint8_t[]> exifBuf;
+ ExifData *exifdata = NULL;
+
+ FILE *fp = fopen (path, "rb");
+ if (!fp) {
+ ALOGE("failed to open file");
+ return NULL;
+ }
+
+ sp<NuMediaExtractor> extractor = new NuMediaExtractor();
+ fseek(fp, 0L, SEEK_END);
+ if (extractor->setDataSource(fileno(fp), 0, ftell(fp)) != OK) {
+ ALOGE("failed to setDataSource");
+ fclose(fp);
+ return NULL;
+ }
+
+ off64_t offset;
+ size_t size;
+ if (extractor->getExifOffsetSize(&offset, &size) != OK) {
+ fclose(fp);
+ return NULL;
+ }
+
+ exifBuf.reset(new uint8_t[size]);
+ fseek(fp, offset, SEEK_SET);
+ if (fread(exifBuf.get(), 1, size, fp) == size) {
+ exifdata = exif_data_new_from_data(exifBuf.get(), size);
+ }
+
+ fclose(fp);
+ return exifdata;
+}
+
MtpResponseCode MtpDatabase::getObjectInfo(MtpObjectHandle handle,
MtpObjectInfo& info) {
MtpString path;
@@ -834,7 +870,12 @@ MtpResponseCode MtpDatabase::getObjectInfo(MtpObjectHandle handle,
case MTP_FORMAT_EXIF_JPEG:
case MTP_FORMAT_HEIF:
case MTP_FORMAT_JFIF: {
- ExifData *exifdata = exif_data_new_from_file(path);
+ ExifData *exifdata;
+ if (info.mFormat == MTP_FORMAT_HEIF) {
+ exifdata = getExifFromExtractor(path);
+ } else {
+ exifdata = exif_data_new_from_file(path);
+ }
if (exifdata) {
if ((false)) {
exif_data_foreach_content(exifdata, foreachcontent, NULL);
@@ -892,7 +933,12 @@ void* MtpDatabase::getThumbnail(MtpObjectHandle handle, size_t& outThumbSize) {
case MTP_FORMAT_EXIF_JPEG:
case MTP_FORMAT_HEIF:
case MTP_FORMAT_JFIF: {
- ExifData *exifdata = exif_data_new_from_file(path);
+ ExifData *exifdata;
+ if (format == MTP_FORMAT_HEIF) {
+ exifdata = getExifFromExtractor(path);
+ } else {
+ exifdata = exif_data_new_from_file(path);
+ }
if (exifdata) {
if (exifdata->data) {
result = malloc(exifdata->size);