diff --git a/frameworks/innerkitsimpl/media_library_helper/src/fetch_result.cpp b/frameworks/innerkitsimpl/media_library_helper/src/fetch_result.cpp index 47928406de28a7fe119f63a600f8396cf6dcc7bc..dd0c88263305da03fe33ea57bdb6de921979d77a 100644 --- a/frameworks/innerkitsimpl/media_library_helper/src/fetch_result.cpp +++ b/frameworks/innerkitsimpl/media_library_helper/src/fetch_result.cpp @@ -73,6 +73,7 @@ static const ResultTypeMap &GetResultTypeMap() { PhotoColumn::PHOTO_DATE_YEAR, TYPE_STRING}, { PhotoColumn::PHOTO_DATE_MONTH, TYPE_STRING}, { PhotoColumn::PHOTO_DATE_DAY, TYPE_STRING}, + { PhotoColumn::PHOTO_SHOOTING_MODE, TYPE_STRING}, }; return RESULT_TYPE_MAP; } diff --git a/frameworks/innerkitsimpl/media_library_helper/src/media_column.cpp b/frameworks/innerkitsimpl/media_library_helper/src/media_column.cpp index 673f2bfa59d164f4441b72ec1d6a8ab3f838c1da..26fee50f52b038bb772d3f9b8f1f4a05f4b95465 100644 --- a/frameworks/innerkitsimpl/media_library_helper/src/media_column.cpp +++ b/frameworks/innerkitsimpl/media_library_helper/src/media_column.cpp @@ -71,6 +71,7 @@ const std::string PhotoColumn::PHOTO_POSITION = "position"; const std::string PhotoColumn::PHOTO_SUBTYPE = "subtype"; const std::string PhotoColumn::CAMERA_SHOT_KEY = "camera_shot_key"; const std::string PhotoColumn::PHOTO_USER_COMMENT = "user_comment"; +const std::string PhotoColumn::PHOTO_SHOOTING_MODE = "shooting_mode"; const std::string PhotoColumn::PHOTO_ALL_EXIF = "all_exif"; const std::string PhotoColumn::PHOTO_DATE_YEAR = "date_year"; const std::string PhotoColumn::PHOTO_DATE_MONTH = "date_month"; @@ -136,7 +137,8 @@ const std::string PhotoColumn::CREATE_PHOTO_TABLE = "CREATE TABLE IF NOT EXISTS PHOTO_ALL_EXIF + " TEXT, " + PHOTO_DATE_YEAR + " TEXT, " + PHOTO_DATE_MONTH + " TEXT, " + - PHOTO_DATE_DAY + " TEXT)"; + PHOTO_DATE_DAY + " TEXT, " + + PHOTO_SHOOTING_MODE + " TEXT)"; const std::string PhotoColumn::CREATE_YEAR_INDEX = BaseColumn::CreateIndex() + @@ -218,7 +220,7 @@ const std::set PhotoColumn::PHOTO_COLUMNS = { PhotoColumn::PHOTO_HEIGHT, PhotoColumn::PHOTO_WIDTH, PhotoColumn::PHOTO_LCD_VISIT_TIME, PhotoColumn::PHOTO_POSITION, PhotoColumn::PHOTO_DIRTY, PhotoColumn::PHOTO_CLOUD_ID, PhotoColumn::CAMERA_SHOT_KEY, PhotoColumn::PHOTO_ALL_EXIF, PhotoColumn::PHOTO_USER_COMMENT, PhotoColumn::PHOTO_DATE_YEAR, PhotoColumn::PHOTO_DATE_MONTH, - PhotoColumn::PHOTO_DATE_DAY, PhotoColumn::PHOTO_EDIT_TIME, + PhotoColumn::PHOTO_DATE_DAY, PhotoColumn::PHOTO_EDIT_TIME, PHOTO_SHOOTING_MODE }; bool PhotoColumn::IsPhotoColumn(const std::string &columnName) diff --git a/frameworks/innerkitsimpl/medialibrary_data_extension/src/medialibrary_rdbstore.cpp b/frameworks/innerkitsimpl/medialibrary_data_extension/src/medialibrary_rdbstore.cpp index b266f4377218c408ab765a5387c102a0d544af0e..ad0b5ba6d0a97d170c4f5874676938a7cad57d07 100644 --- a/frameworks/innerkitsimpl/medialibrary_data_extension/src/medialibrary_rdbstore.cpp +++ b/frameworks/innerkitsimpl/medialibrary_data_extension/src/medialibrary_rdbstore.cpp @@ -1357,6 +1357,18 @@ static void AddPhotoEditTimeColumn(RdbStore &store) ExecSqls(addEditTime, store); } +void AddShootingModeColumn(RdbStore &store) +{ + const std::string addShootringMode = + "ALTER TABLE " + PhotoColumn::PHOTOS_TABLE + " ADD COLUMN " + + PhotoColumn::PHOTO_SHOOTING_MODE + " TEXT"; + const vector addShootingModeColumn = { addShootringMode }; + int32_t result = ExecSqls(addShootingModeColumn, store); + if (result != NativeRdb::E_OK) { + MEDIA_ERR_LOG("Upgrade rdb shooting_mode error %{private}d", result); + } +} + static void UpgradeOtherTable(RdbStore &store, int32_t oldVersion) { if (oldVersion < VERSION_ADD_PACKAGE_NAME) { @@ -1394,6 +1406,10 @@ static void UpgradeOtherTable(RdbStore &store, int32_t oldVersion) if (oldVersion < VERSION_ADD_PHOTO_EDIT_TIME) { AddPhotoEditTimeColumn(store); } + + if (oldVersion < VERSION_ADD_SHOOTING_MODE) { + AddShootingModeColumn(store); + } } int32_t MediaLibraryDataCallBack::OnUpgrade(RdbStore &store, int32_t oldVersion, int32_t newVersion) diff --git a/frameworks/services/media_scanner/include/scanner/metadata.h b/frameworks/services/media_scanner/include/scanner/metadata.h index 93da32a67a477e10f2cb16528d35ccf6c744556e..688eb8ae47095d5be1252205a35e2d98c683d297 100644 --- a/frameworks/services/media_scanner/include/scanner/metadata.h +++ b/frameworks/services/media_scanner/include/scanner/metadata.h @@ -123,6 +123,9 @@ public: void SetDateDay(const VariantData &dateDay); const std::string &getDateDay() const; + void SetShootingMode(const VariantData &shootingMode); + const std::string &GetShootingMode() const; + #ifdef MEDIALIBRARY_COMPATIBILITY void SetPhotoSubType(const VariantData &photoSubType); int32_t GetPhotoSubType() const; @@ -167,6 +170,7 @@ private: string dateYear_; string dateMonth_; string dateDay_; + string shootingMode_; // video, audio, image int64_t dateTaken_; diff --git a/frameworks/services/media_scanner/include/scanner/scanner_utils.h b/frameworks/services/media_scanner/include/scanner/scanner_utils.h index 8d4cda8bd35d4f727ffcff20a4002021b6b83856..f1cbff4f49c0572f346a55058f56180d08df6fcc 100644 --- a/frameworks/services/media_scanner/include/scanner/scanner_utils.h +++ b/frameworks/services/media_scanner/include/scanner/scanner_utils.h @@ -61,6 +61,7 @@ const int32_t FILE_WIDTH_DEFAULT = 0; const int32_t FILE_ALBUM_ID_DEFAULT = 0; const std::string FILE_ALBUM_NAME_DEFAULT = ""; const int32_t FILE_ORIENTATION_DEFAULT = 0; +const std::string FILE_SHOOTINGMODE_DEFAULT = ""; const std::string FILE_RELATIVE_PATH_DEFAULT = ""; const std::string FILE_RECYCLE_PATH_DEFAULT = ""; const int64_t FILE_DATE_TAKEN_DEFAULT = 0; diff --git a/frameworks/services/media_scanner/src/scanner/media_scanner_db.cpp b/frameworks/services/media_scanner/src/scanner/media_scanner_db.cpp index 250e061b917560e2b2e1d2e0305adee1cd325a1f..0b8c5878b4d5c5a973b7f721b48adb85f7bd21eb 100644 --- a/frameworks/services/media_scanner/src/scanner/media_scanner_db.cpp +++ b/frameworks/services/media_scanner/src/scanner/media_scanner_db.cpp @@ -171,6 +171,8 @@ static void SetValuesFromMetaDataApi10(const Metadata &metadata, ValuesBucket &v values.PutString(PhotoColumn::PHOTO_DATE_YEAR, metadata.getDateYear()); values.PutString(PhotoColumn::PHOTO_DATE_MONTH, metadata.getDateMonth()); values.PutString(PhotoColumn::PHOTO_DATE_DAY, metadata.getDateDay()); + values.PutString(PhotoColumn::PHOTO_SHOOTING_MODE, metadata.GetShootingMode()); + #ifdef MEDIALIBRARY_COMPATIBILITY if (metadata.GetPhotoSubType() != 0) { values.PutInt(PhotoColumn::PHOTO_SUBTYPE, metadata.GetPhotoSubType()); diff --git a/frameworks/services/media_scanner/src/scanner/metadata.cpp b/frameworks/services/media_scanner/src/scanner/metadata.cpp index f7169e3ddf2d5d9cc41d52f1be29cbb185df8676..6fdc0d663cb2b2993fe5b97f73e10f40b4a1034c 100644 --- a/frameworks/services/media_scanner/src/scanner/metadata.cpp +++ b/frameworks/services/media_scanner/src/scanner/metadata.cpp @@ -41,6 +41,7 @@ Metadata::Metadata() width_(FILE_WIDTH_DEFAULT), duration_(FILE_DURATION_DEFAULT), orientation_(FILE_ORIENTATION_DEFAULT), + shootingMode_(FILE_SHOOTINGMODE_DEFAULT), dateTaken_(FILE_DATE_TAKEN_DEFAULT), longitude_(FILE_LONGITUDE_DEFAULT), latitude_(FILE_LATITUDE_DEFAULT), @@ -399,6 +400,16 @@ const string &Metadata::getDateDay() const return dateDay_; } +void Metadata::SetShootingMode(const VariantData &shootingMode) +{ + shootingMode_ = get(shootingMode); +} + +const string &Metadata::GetShootingMode() const +{ + return shootingMode_; +} + #ifdef MEDIALIBRARY_COMPATIBILITY void Metadata::SetPhotoSubType(const VariantData &photoSubType) { diff --git a/frameworks/services/media_scanner/src/scanner/metadata_extractor.cpp b/frameworks/services/media_scanner/src/scanner/metadata_extractor.cpp index f07e6a1e5543761b7b24d3648526e9b3825a62b9..5831ff489e548bce46996d24d729e019804de731 100644 --- a/frameworks/services/media_scanner/src/scanner/metadata_extractor.cpp +++ b/frameworks/services/media_scanner/src/scanner/metadata_extractor.cpp @@ -99,7 +99,10 @@ int32_t MetadataExtractor::ExtractImageExif(std::unique_ptr &imageS if (err == 0) { data->SetUserComment(propertyStr); } - + err = imageSource->GetImagePropertyString(0, PHOTO_DATA_IMAGE_PHOTO_MODE, propertyStr); + if (err == 0) { + data->SetShootingMode(propertyStr); + } return E_OK; } @@ -158,12 +161,28 @@ int32_t MetadataExtractor::ExtractImageMetadata(std::unique_ptr &data) dbleTempMeta = GetLongitudeLatitude(propertyStr); data->SetLatitude(dbleTempMeta); } - ExtractImageExif(imageSource, data); - return E_OK; } +static std::string ExtractVideoShootingMode(const std::string &genreJson) +{ + if (genreJson.empty()) { + return ""; + } + size_t pos = genreJson.find("param-use-tag"); + if (pos != std::string::npos) { + size_t start = genreJson.find(":", pos); + size_t end = genreJson.find(",", pos); + if (end == std::string::npos) { + end = genreJson.find("}", pos); + } + return genreJson.substr(start + 1, end - start - 1); // 1: length offset + } else { + return ""; + } +} + void MetadataExtractor::FillExtractedMetadata(const std::unordered_map &resultMap, std::unique_ptr &data) { @@ -229,6 +248,11 @@ void MetadataExtractor::FillExtractedMetadata(const std::unordered_mapSetFileTitle(strTemp); } + strTemp = resultMap.at(AV_KEY_GENRE); + if (!strTemp.empty()) { + std::string videoShootingMode = ExtractVideoShootingMode(strTemp); + data->SetShootingMode(videoShootingMode); + } } int32_t MetadataExtractor::ExtractAVMetadata(std::unique_ptr &data) diff --git a/interfaces/inner_api/media_library_helper/include/media_column.h b/interfaces/inner_api/media_library_helper/include/media_column.h index 171465a3a620667f2db4259dfd61294ce4ba6471..8bc9f07dfa8fea58e6baa784c81de523212c1f43 100644 --- a/interfaces/inner_api/media_library_helper/include/media_column.h +++ b/interfaces/inner_api/media_library_helper/include/media_column.h @@ -95,6 +95,7 @@ public: static const std::string PHOTO_DATE_YEAR; static const std::string PHOTO_DATE_MONTH; static const std::string PHOTO_DATE_DAY; + static const std::string PHOTO_SHOOTING_MODE; // index in PhotoTable static const std::string PHOTO_DATE_YEAR_INDEX; static const std::string PHOTO_DATE_MONTH_INDEX; diff --git a/interfaces/inner_api/media_library_helper/include/medialibrary_db_const.h b/interfaces/inner_api/media_library_helper/include/medialibrary_db_const.h index 94a4c5db647b4f2371e2aa5b90a7bc93a3c2af17..1638bcd8c83f1faf1602a016be316e61fe301a21 100644 --- a/interfaces/inner_api/media_library_helper/include/medialibrary_db_const.h +++ b/interfaces/inner_api/media_library_helper/include/medialibrary_db_const.h @@ -22,7 +22,7 @@ namespace OHOS { namespace Media { -const int32_t MEDIA_RDB_VERSION = 21; +const int32_t MEDIA_RDB_VERSION = 22; enum { VERSION_ADD_CLOUD = 2, VERSION_ADD_META_MODIFED = 3, @@ -48,6 +48,7 @@ enum { VERSION_UPDATE_YEAR_MONTH_DAY = 18, VERSION_ADD_VISION_TABLE = 20, VERSION_ADD_PHOTO_EDIT_TIME = 21, + VERSION_ADD_SHOOTING_MODE = 22, }; enum {