diff --git a/bundle.json b/bundle.json index 7f3209d99ec5bce75460d44bf56a8d2b98fa6449..aa21b4d2e7b061481f294205e2adc6b9a1f1ae9d 100644 --- a/bundle.json +++ b/bundle.json @@ -143,21 +143,12 @@ "media_access_helper_capi.h", "media_asset_capi.h", "media_asset_change_request_capi.h", - "media_asset_manager_capi.h" + "media_asset_manager_capi.h", + "moving_photo_capi.h" ] }, "name": "//foundation/multimedia/media_library/interfaces/kits/c:native_media_asset_manager" }, - { - "header": { - "header_base": "//foundation/multimedia/media_library/interfaces/inner_api/media_library_helper/include", - "header_files": [ - "media_asset_impl.h", - "media_asset_change_request_impl.h" - ] - }, - "name": "//foundation/multimedia/media_library/frameworks/native/c_api:native_media_library_ndk" - }, { "header": { "header_base": "//foundation/multimedia/media_library/interfaces/inner_api/media_library_helper/include", diff --git a/frameworks/innerkitsimpl/test/unittest/media_asset_test/BUILD.gn b/frameworks/innerkitsimpl/test/unittest/media_asset_test/BUILD.gn index a07a994c008d80219183d15c7788a654d3d5d0d7..2993722825109036acb87afd241516911cef2b3e 100644 --- a/frameworks/innerkitsimpl/test/unittest/media_asset_test/BUILD.gn +++ b/frameworks/innerkitsimpl/test/unittest/media_asset_test/BUILD.gn @@ -37,6 +37,7 @@ ohos_unittest("media_asset_test") { "//third_party/json/include", "${MEDIALIB_INTERFACES_PATH}/kits/native/include", "${MEDIALIB_IMAGE_FRAMEWORK_PATH}/interfaces/kits/native/include/image", + "${MEDIALIB_NATIVE_PATH}/c_api/common", ] sources = [ @@ -50,7 +51,7 @@ ohos_unittest("media_asset_test") { "${MEDIALIB_INTERFACES_PATH}/kits/c:native_media_asset_manager", "${MEDIALIB_INTERFACES_PATH}/kits/js:medialibrary", "${MEDIALIB_INTERFACES_PATH}/kits/js:medialibrary_js", - "${MEDIALIB_NATIVE_PATH}/c_api:native_media_library_ndk", + "${MEDIALIB_NATIVE_PATH}/media_library_asset_manager:media_library_asset_manager", ] external_deps = [ diff --git a/frameworks/innerkitsimpl/test/unittest/media_asset_test/src/media_asset_test.cpp b/frameworks/innerkitsimpl/test/unittest/media_asset_test/src/media_asset_test.cpp index 1861bd4393ac6237eaa59cb4eaf67e235f299489..dcc8b11d42e2ef40a1844e734ecf0b2c674a9976 100644 --- a/frameworks/innerkitsimpl/test/unittest/media_asset_test/src/media_asset_test.cpp +++ b/frameworks/innerkitsimpl/test/unittest/media_asset_test/src/media_asset_test.cpp @@ -20,7 +20,8 @@ #include "media_asset_base_capi.h" #include "media_asset_manager_capi.h" #include "media_asset_capi.h" -#include "media_asset_impl.h" +#include "oh_media_asset.h" +#include "media_asset.h" namespace OHOS { namespace Media { @@ -45,7 +46,8 @@ void MediaAssetTest::FreeCharPointer(const char *freeCharPointer) HWTEST_F(MediaAssetTest, mediaAsset_GetUri_test_001, TestSize.Level0) { std::shared_ptr fileAsset = std::make_shared(); - auto* mediaAsset = new OH_MediaAsset(fileAsset); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto* mediaAsset = new OH_MediaAsset(mediaAssetImpl); const char *uri = nullptr; MediaLibrary_ErrorCode ret = OH_MediaAsset_GetUri(mediaAsset, &uri); EXPECT_EQ(ret, MEDIA_LIBRARY_OK); @@ -56,7 +58,8 @@ HWTEST_F(MediaAssetTest, mediaAsset_GetUri_test_001, TestSize.Level0) HWTEST_F(MediaAssetTest, mediaAsset_GetUri_test_002, TestSize.Level0) { std::shared_ptr fileAsset = std::make_shared(); - auto* mediaAsset = new OH_MediaAsset(fileAsset); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto* mediaAsset = new OH_MediaAsset(mediaAssetImpl); MediaLibrary_ErrorCode ret = OH_MediaAsset_GetUri(mediaAsset, nullptr); EXPECT_EQ(ret, MEDIA_LIBRARY_PARAMETER_ERROR); EXPECT_EQ(OH_MediaAsset_Release(mediaAsset), MEDIA_LIBRARY_OK); @@ -65,7 +68,8 @@ HWTEST_F(MediaAssetTest, mediaAsset_GetUri_test_002, TestSize.Level0) HWTEST_F(MediaAssetTest, mediaAsset_GetDisplayName_test_001, TestSize.Level0) { std::shared_ptr fileAsset = std::make_shared(); - auto* mediaAsset = new OH_MediaAsset(fileAsset); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto* mediaAsset = new OH_MediaAsset(mediaAssetImpl); const char *displayName = nullptr; MediaLibrary_ErrorCode ret = OH_MediaAsset_GetDisplayName(mediaAsset, &displayName); EXPECT_EQ(ret, MEDIA_LIBRARY_OK); @@ -76,7 +80,8 @@ HWTEST_F(MediaAssetTest, mediaAsset_GetDisplayName_test_001, TestSize.Level0) HWTEST_F(MediaAssetTest, mediaAsset_GetDisplayName_test_002, TestSize.Level0) { std::shared_ptr fileAsset = std::make_shared(); - auto* mediaAsset = new OH_MediaAsset(fileAsset); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto* mediaAsset = new OH_MediaAsset(mediaAssetImpl); MediaLibrary_ErrorCode ret = OH_MediaAsset_GetDisplayName(mediaAsset, nullptr); EXPECT_EQ(ret, MEDIA_LIBRARY_PARAMETER_ERROR); EXPECT_EQ(OH_MediaAsset_Release(mediaAsset), MEDIA_LIBRARY_OK); @@ -85,7 +90,8 @@ HWTEST_F(MediaAssetTest, mediaAsset_GetDisplayName_test_002, TestSize.Level0) HWTEST_F(MediaAssetTest, mediaAsset_GetSize_test_001, TestSize.Level0) { std::shared_ptr fileAsset = std::make_shared(); - auto* mediaAsset = new OH_MediaAsset(fileAsset); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto* mediaAsset = new OH_MediaAsset(mediaAssetImpl); uint32_t size = 0; MediaLibrary_ErrorCode ret = OH_MediaAsset_GetSize(mediaAsset, &size); EXPECT_EQ(ret, MEDIA_LIBRARY_OK); @@ -95,7 +101,8 @@ HWTEST_F(MediaAssetTest, mediaAsset_GetSize_test_001, TestSize.Level0) HWTEST_F(MediaAssetTest, mediaAsset_GetSize_test_002, TestSize.Level0) { std::shared_ptr fileAsset = std::make_shared(); - auto* mediaAsset = new OH_MediaAsset(fileAsset); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto* mediaAsset = new OH_MediaAsset(mediaAssetImpl); uint32_t size = 0; MediaLibrary_ErrorCode ret = OH_MediaAsset_GetSize(nullptr, &size); EXPECT_EQ(ret, MEDIA_LIBRARY_PARAMETER_ERROR); @@ -107,7 +114,8 @@ HWTEST_F(MediaAssetTest, mediaAsset_GetSize_test_002, TestSize.Level0) HWTEST_F(MediaAssetTest, mediaAsset_GetDateModifiedMs_test_001, TestSize.Level0) { std::shared_ptr fileAsset = std::make_shared(); - auto* mediaAsset = new OH_MediaAsset(fileAsset); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto* mediaAsset = new OH_MediaAsset(mediaAssetImpl); uint32_t dateModifiedMs = 0; MediaLibrary_ErrorCode ret = OH_MediaAsset_GetDateModifiedMs(mediaAsset, &dateModifiedMs); EXPECT_EQ(ret, MEDIA_LIBRARY_OK); @@ -117,7 +125,8 @@ HWTEST_F(MediaAssetTest, mediaAsset_GetDateModifiedMs_test_001, TestSize.Level0) HWTEST_F(MediaAssetTest, mediaAsset_GetDateModifiedMs_test_002, TestSize.Level0) { std::shared_ptr fileAsset = std::make_shared(); - auto* mediaAsset = new OH_MediaAsset(fileAsset); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto* mediaAsset = new OH_MediaAsset(mediaAssetImpl); uint32_t dateModifiedMs = 0; MediaLibrary_ErrorCode ret = OH_MediaAsset_GetDateModifiedMs(nullptr, &dateModifiedMs); EXPECT_EQ(ret, MEDIA_LIBRARY_PARAMETER_ERROR); @@ -129,7 +138,8 @@ HWTEST_F(MediaAssetTest, mediaAsset_GetDateModifiedMs_test_002, TestSize.Level0) HWTEST_F(MediaAssetTest, mediaAsset_GetWidth_test_001, TestSize.Level0) { std::shared_ptr fileAsset = std::make_shared(); - auto* mediaAsset = new OH_MediaAsset(fileAsset); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto* mediaAsset = new OH_MediaAsset(mediaAssetImpl); uint32_t width = 0; MediaLibrary_ErrorCode ret = OH_MediaAsset_GetWidth(mediaAsset, &width); EXPECT_EQ(ret, MEDIA_LIBRARY_OK); @@ -139,7 +149,8 @@ HWTEST_F(MediaAssetTest, mediaAsset_GetWidth_test_001, TestSize.Level0) HWTEST_F(MediaAssetTest, mediaAsset_GetWidth_test_002, TestSize.Level0) { std::shared_ptr fileAsset = std::make_shared(); - auto* mediaAsset = new OH_MediaAsset(fileAsset); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto* mediaAsset = new OH_MediaAsset(mediaAssetImpl); uint32_t width = 0; MediaLibrary_ErrorCode ret = OH_MediaAsset_GetWidth(nullptr, &width); EXPECT_EQ(ret, MEDIA_LIBRARY_PARAMETER_ERROR); @@ -151,7 +162,8 @@ HWTEST_F(MediaAssetTest, mediaAsset_GetWidth_test_002, TestSize.Level0) HWTEST_F(MediaAssetTest, mediaAsset_GetHeight_test_001, TestSize.Level0) { std::shared_ptr fileAsset = std::make_shared(); - auto* mediaAsset = new OH_MediaAsset(fileAsset); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto* mediaAsset = new OH_MediaAsset(mediaAssetImpl); uint32_t height = 0; MediaLibrary_ErrorCode ret = OH_MediaAsset_GetHeight(mediaAsset, &height); EXPECT_EQ(ret, MEDIA_LIBRARY_OK); @@ -161,7 +173,8 @@ HWTEST_F(MediaAssetTest, mediaAsset_GetHeight_test_001, TestSize.Level0) HWTEST_F(MediaAssetTest, mediaAsset_GetHeight_test_002, TestSize.Level0) { std::shared_ptr fileAsset = std::make_shared(); - auto* mediaAsset = new OH_MediaAsset(fileAsset); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto* mediaAsset = new OH_MediaAsset(mediaAssetImpl); uint32_t height = 0; MediaLibrary_ErrorCode ret = OH_MediaAsset_GetHeight(nullptr, &height); EXPECT_EQ(ret, MEDIA_LIBRARY_PARAMETER_ERROR); @@ -173,7 +186,8 @@ HWTEST_F(MediaAssetTest, mediaAsset_GetHeight_test_002, TestSize.Level0) HWTEST_F(MediaAssetTest, mediaAsset_GetOrientation_test_001, TestSize.Level0) { std::shared_ptr fileAsset = std::make_shared(); - auto* mediaAsset = new OH_MediaAsset(fileAsset); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto* mediaAsset = new OH_MediaAsset(mediaAssetImpl); uint32_t orientation = 0; MediaLibrary_ErrorCode ret = OH_MediaAsset_GetOrientation(mediaAsset, &orientation); EXPECT_EQ(ret, MEDIA_LIBRARY_OK); @@ -183,7 +197,8 @@ HWTEST_F(MediaAssetTest, mediaAsset_GetOrientation_test_001, TestSize.Level0) HWTEST_F(MediaAssetTest, mediaAsset_GetOrientation_test_002, TestSize.Level0) { std::shared_ptr fileAsset = std::make_shared(); - auto* mediaAsset = new OH_MediaAsset(fileAsset); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto* mediaAsset = new OH_MediaAsset(mediaAssetImpl); uint32_t orientation = 0; MediaLibrary_ErrorCode ret = OH_MediaAsset_GetOrientation(nullptr, &orientation); EXPECT_EQ(ret, MEDIA_LIBRARY_PARAMETER_ERROR); @@ -195,7 +210,8 @@ HWTEST_F(MediaAssetTest, mediaAsset_GetOrientation_test_002, TestSize.Level0) HWTEST_F(MediaAssetTest, mediaAsset_Release_test_001, TestSize.Level0) { std::shared_ptr fileAsset = std::make_shared(); - auto* mediaAsset = new OH_MediaAsset(fileAsset); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto* mediaAsset = new OH_MediaAsset(mediaAssetImpl); uint32_t orientation = 0; MediaLibrary_ErrorCode ret = OH_MediaAsset_GetOrientation(nullptr, &orientation); EXPECT_EQ(ret, MEDIA_LIBRARY_PARAMETER_ERROR); diff --git a/frameworks/innerkitsimpl/test/unittest/media_library_asset_helper_capi_test/BUILD.gn b/frameworks/innerkitsimpl/test/unittest/media_library_asset_helper_capi_test/BUILD.gn index 0762a036f94ea098db678647c329313488a941f3..0a101a84d72a287021de3a885b424cffb99edb71 100644 --- a/frameworks/innerkitsimpl/test/unittest/media_library_asset_helper_capi_test/BUILD.gn +++ b/frameworks/innerkitsimpl/test/unittest/media_library_asset_helper_capi_test/BUILD.gn @@ -44,7 +44,7 @@ ohos_unittest("media_library_asset_helper_capi_test") { "${MEDIALIB_INNERKITS_PATH}/media_library_helper:media_library", "${MEDIALIB_INNERKITS_PATH}/medialibrary_data_extension:medialibrary_data_extension", "${MEDIALIB_INTERFACES_PATH}/kits/c:native_media_asset_manager", - "${MEDIALIB_NATIVE_PATH}/c_api:native_media_library_ndk", + "${MEDIALIB_NATIVE_PATH}/media_library_asset_manager:media_library_asset_manager", ] external_deps = [ diff --git a/frameworks/innerkitsimpl/test/unittest/media_library_asset_helper_capi_test/src/media_library_asset_helper_capi_test.cpp b/frameworks/innerkitsimpl/test/unittest/media_library_asset_helper_capi_test/src/media_library_asset_helper_capi_test.cpp index d2895c599f5f158d1d10f330bc22213d798db414..1780e665df86cf04180d973db94f59583d594c9a 100644 --- a/frameworks/innerkitsimpl/test/unittest/media_library_asset_helper_capi_test/src/media_library_asset_helper_capi_test.cpp +++ b/frameworks/innerkitsimpl/test/unittest/media_library_asset_helper_capi_test/src/media_library_asset_helper_capi_test.cpp @@ -25,11 +25,13 @@ #include "medialibrary_db_const.h" #include "medialibrary_errno.h" #include "media_access_helper_capi.h" -#include "media_asset_change_request_impl.h" +#include "media_asset_types.h" +#include "oh_media_asset_change_request.h" #include "media_asset_change_request_capi.h" #include "media_asset_capi.h" #include "system_ability_definition.h" -#include "media_asset_impl.h" +#include "oh_media_asset.h" +#include "media_asset.h" #include "media_file_utils.h" #include "media_library_manager.h" #include "media_log.h" @@ -62,8 +64,9 @@ HWTEST_F(MediaLibraryAssetHelperCapiTest, media_library_capi_test_001, TestSize. std::shared_ptr fileAsset = std::make_shared(); fileAsset->SetResultNapiType(OHOS::Media::ResultNapiType::TYPE_PHOTOACCESS_HELPER); fileAsset->SetMediaType(OHOS::Media::MEDIA_TYPE_IMAGE); - auto mediaAsset = new OH_MediaAsset(fileAsset); - auto fileAssetPtr = mediaAsset->GetFileAssetInstance(); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto mediaAsset = new OH_MediaAsset(mediaAssetImpl); + auto fileAssetPtr = mediaAsset->mediaAsset_->GetFileAssetInstance(); auto changeRequest = OH_MediaAssetChangeRequest_Create(mediaAsset); ASSERT_NE(changeRequest, nullptr); @@ -81,8 +84,9 @@ HWTEST_F(MediaLibraryAssetHelperCapiTest, media_library_capi_test_002, TestSize. std::shared_ptr fileAsset = std::make_shared(); fileAsset->SetResultNapiType(OHOS::Media::ResultNapiType::TYPE_PHOTOACCESS_HELPER); fileAsset->SetMediaType(OHOS::Media::MEDIA_TYPE_VIDEO); - auto mediaAsset = new OH_MediaAsset(fileAsset); - auto fileAssetPtr = mediaAsset->GetFileAssetInstance(); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto mediaAsset = new OH_MediaAsset(mediaAssetImpl); + auto fileAssetPtr = mediaAsset->mediaAsset_->GetFileAssetInstance(); auto changeRequest = OH_MediaAssetChangeRequest_Create(mediaAsset); ASSERT_NE(changeRequest, nullptr); @@ -99,8 +103,9 @@ HWTEST_F(MediaLibraryAssetHelperCapiTest, media_library_capi_test_003, TestSize. { std::shared_ptr fileAsset = std::make_shared(); fileAsset->SetResultNapiType(OHOS::Media::ResultNapiType::TYPE_MEDIALIBRARY); - auto mediaAsset = new OH_MediaAsset(fileAsset); - auto fileAssetPtr = mediaAsset->GetFileAssetInstance(); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto mediaAsset = new OH_MediaAsset(mediaAssetImpl); + auto fileAssetPtr = mediaAsset->mediaAsset_->GetFileAssetInstance(); auto changeRequest = OH_MediaAssetChangeRequest_Create(mediaAsset); ASSERT_EQ(changeRequest, nullptr); @@ -120,8 +125,9 @@ HWTEST_F(MediaLibraryAssetHelperCapiTest, media_library_capi_test_004, TestSize. fileAsset->SetPhotoSubType(static_cast(PhotoSubType::MOVING_PHOTO)); fileAsset->SetResultNapiType(OHOS::Media::ResultNapiType::TYPE_PHOTOACCESS_HELPER); fileAsset->SetMediaType(OHOS::Media::MEDIA_TYPE_IMAGE); - auto mediaAsset = new OH_MediaAsset(fileAsset); - auto fileAssetPtr = mediaAsset->GetFileAssetInstance(); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto mediaAsset = new OH_MediaAsset(mediaAssetImpl); + auto fileAssetPtr = mediaAsset->mediaAsset_->GetFileAssetInstance(); auto changeRequest = OH_MediaAssetChangeRequest_Create(mediaAsset); ASSERT_NE(changeRequest, nullptr); @@ -146,8 +152,9 @@ HWTEST_F(MediaLibraryAssetHelperCapiTest, media_library_capi_test_005, TestSize. fileAsset->SetPhotoSubType(static_cast(PhotoSubType::MOVING_PHOTO)); fileAsset->SetResultNapiType(OHOS::Media::ResultNapiType::TYPE_PHOTOACCESS_HELPER); fileAsset->SetMediaType(OHOS::Media::MEDIA_TYPE_IMAGE); - auto mediaAsset = new OH_MediaAsset(fileAsset); - auto fileAssetPtr = mediaAsset->GetFileAssetInstance(); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto mediaAsset = new OH_MediaAsset(mediaAssetImpl); + auto fileAssetPtr = mediaAsset->mediaAsset_->GetFileAssetInstance(); auto changeRequest = OH_MediaAssetChangeRequest_Create(mediaAsset); ASSERT_NE(changeRequest, nullptr); @@ -172,8 +179,9 @@ HWTEST_F(MediaLibraryAssetHelperCapiTest, media_library_capi_test_006, TestSize. fileAsset->SetPhotoSubType(static_cast(PhotoSubType::MOVING_PHOTO)); fileAsset->SetResultNapiType(OHOS::Media::ResultNapiType::TYPE_PHOTOACCESS_HELPER); fileAsset->SetMediaType(OHOS::Media::MEDIA_TYPE_IMAGE); - auto mediaAsset = new OH_MediaAsset(fileAsset); - auto fileAssetPtr = mediaAsset->GetFileAssetInstance(); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto mediaAsset = new OH_MediaAsset(mediaAssetImpl); + auto fileAssetPtr = mediaAsset->mediaAsset_->GetFileAssetInstance(); auto changeRequest = OH_MediaAssetChangeRequest_Create(mediaAsset); ASSERT_NE(changeRequest, nullptr); @@ -198,8 +206,9 @@ HWTEST_F(MediaLibraryAssetHelperCapiTest, media_library_capi_test_007, TestSize. fileAsset->SetPhotoSubType(static_cast(PhotoSubType::CAMERA)); fileAsset->SetResultNapiType(OHOS::Media::ResultNapiType::TYPE_PHOTOACCESS_HELPER); fileAsset->SetMediaType(OHOS::Media::MEDIA_TYPE_IMAGE); - auto mediaAsset = new OH_MediaAsset(fileAsset); - auto fileAssetPtr = mediaAsset->GetFileAssetInstance(); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto mediaAsset = new OH_MediaAsset(mediaAssetImpl); + auto fileAssetPtr = mediaAsset->mediaAsset_->GetFileAssetInstance(); auto changeRequest = OH_MediaAssetChangeRequest_Create(mediaAsset); ASSERT_NE(changeRequest, nullptr); @@ -224,8 +233,9 @@ HWTEST_F(MediaLibraryAssetHelperCapiTest, media_library_capi_test_008, TestSize. fileAsset->SetPhotoSubType(static_cast(PhotoSubType::MOVING_PHOTO)); fileAsset->SetResultNapiType(OHOS::Media::ResultNapiType::TYPE_PHOTOACCESS_HELPER); fileAsset->SetMediaType(OHOS::Media::MEDIA_TYPE_IMAGE); - auto mediaAsset = new OH_MediaAsset(fileAsset); - auto fileAssetPtr = mediaAsset->GetFileAssetInstance(); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto mediaAsset = new OH_MediaAsset(mediaAssetImpl); + auto fileAssetPtr = mediaAsset->mediaAsset_->GetFileAssetInstance(); auto changeRequest = OH_MediaAssetChangeRequest_Create(mediaAsset); ASSERT_NE(changeRequest, nullptr); @@ -252,14 +262,15 @@ HWTEST_F(MediaLibraryAssetHelperCapiTest, media_library_capi_test_009, TestSize. std::shared_ptr fileAsset = std::make_shared(); fileAsset->SetResultNapiType(OHOS::Media::ResultNapiType::TYPE_PHOTOACCESS_HELPER); fileAsset->SetMediaType(OHOS::Media::MEDIA_TYPE_IMAGE); - auto mediaAsset = new OH_MediaAsset(fileAsset); - auto fileAssetPtr = mediaAsset->GetFileAssetInstance(); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto mediaAsset = new OH_MediaAsset(mediaAssetImpl); + auto fileAssetPtr = mediaAsset->mediaAsset_->GetFileAssetInstance(); auto changeRequest = OH_MediaAssetChangeRequest_Create(mediaAsset); ASSERT_NE(changeRequest, nullptr); MediaLibrary_ImageFileType imageFileType = MEDIA_LIBRARY_IMAGE_JPEG; AssetChangeOperation changeOperation = AssetChangeOperation::SET_EDIT_DATA; - changeRequest->RecordChangeOperation(changeOperation); + changeRequest->request_->RecordChangeOperation(changeOperation); uint32_t result = OH_MediaAssetChangeRequest_SaveCameraPhoto(changeRequest, imageFileType); ASSERT_EQ(result, MEDIA_LIBRARY_OK); @@ -277,14 +288,15 @@ HWTEST_F(MediaLibraryAssetHelperCapiTest, media_library_capi_test_010, TestSize. std::shared_ptr fileAsset = std::make_shared(); fileAsset->SetResultNapiType(OHOS::Media::ResultNapiType::TYPE_PHOTOACCESS_HELPER); fileAsset->SetMediaType(OHOS::Media::MEDIA_TYPE_IMAGE); - auto mediaAsset = new OH_MediaAsset(fileAsset); - auto fileAssetPtr = mediaAsset->GetFileAssetInstance(); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto mediaAsset = new OH_MediaAsset(mediaAssetImpl); + auto fileAssetPtr = mediaAsset->mediaAsset_->GetFileAssetInstance(); auto changeRequest = OH_MediaAssetChangeRequest_Create(mediaAsset); ASSERT_NE(changeRequest, nullptr); MediaLibrary_ImageFileType imageFileType = MEDIA_LIBRARY_IMAGE_JPEG; AssetChangeOperation changeOperation = AssetChangeOperation::ADD_FILTERS; - changeRequest->RecordChangeOperation(changeOperation); + changeRequest->request_->RecordChangeOperation(changeOperation); uint32_t result = OH_MediaAssetChangeRequest_SaveCameraPhoto(changeRequest, imageFileType); ASSERT_EQ(result, MEDIA_LIBRARY_OK); uint32_t resultChange = OH_MediaAccessHelper_ApplyChanges(changeRequest); @@ -304,14 +316,15 @@ HWTEST_F(MediaLibraryAssetHelperCapiTest, media_library_capi_test_011, TestSize. std::shared_ptr fileAsset = std::make_shared(); fileAsset->SetResultNapiType(OHOS::Media::ResultNapiType::TYPE_PHOTOACCESS_HELPER); fileAsset->SetMediaType(OHOS::Media::MEDIA_TYPE_IMAGE); - auto mediaAsset = new OH_MediaAsset(fileAsset); - auto fileAssetPtr = mediaAsset->GetFileAssetInstance(); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto mediaAsset = new OH_MediaAsset(mediaAssetImpl); + auto fileAssetPtr = mediaAsset->mediaAsset_->GetFileAssetInstance(); auto changeRequest = OH_MediaAssetChangeRequest_Create(mediaAsset); ASSERT_NE(changeRequest, nullptr); MediaLibrary_ImageFileType imageFileType = MEDIA_LIBRARY_IMAGE_JPEG; AssetChangeOperation changeOperation = AssetChangeOperation::CREATE_FROM_SCRATCH; - changeRequest->RecordChangeOperation(changeOperation); + changeRequest->request_->RecordChangeOperation(changeOperation); uint32_t result = OH_MediaAssetChangeRequest_SaveCameraPhoto(changeRequest, imageFileType); ASSERT_EQ(result, MEDIA_LIBRARY_OK); uint32_t resultChange = OH_MediaAccessHelper_ApplyChanges(changeRequest); @@ -331,14 +344,15 @@ HWTEST_F(MediaLibraryAssetHelperCapiTest, media_library_capi_test_012, TestSize. std::shared_ptr fileAsset = std::make_shared(); fileAsset->SetResultNapiType(OHOS::Media::ResultNapiType::TYPE_PHOTOACCESS_HELPER); fileAsset->SetMediaType(OHOS::Media::MEDIA_TYPE_IMAGE); - auto mediaAsset = new OH_MediaAsset(fileAsset); - auto fileAssetPtr = mediaAsset->GetFileAssetInstance(); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto mediaAsset = new OH_MediaAsset(mediaAssetImpl); + auto fileAssetPtr = mediaAsset->mediaAsset_->GetFileAssetInstance(); auto changeRequest = OH_MediaAssetChangeRequest_Create(mediaAsset); ASSERT_NE(changeRequest, nullptr); MediaLibrary_ImageFileType imageFileType = MEDIA_LIBRARY_IMAGE_JPEG; AssetChangeOperation changeOperation = AssetChangeOperation::GET_WRITE_CACHE_HANDLER; - changeRequest->RecordChangeOperation(changeOperation); + changeRequest->request_->RecordChangeOperation(changeOperation); uint32_t result = OH_MediaAssetChangeRequest_SaveCameraPhoto(changeRequest, imageFileType); ASSERT_EQ(result, MEDIA_LIBRARY_OK); uint32_t resultChange = OH_MediaAccessHelper_ApplyChanges(changeRequest); @@ -358,14 +372,15 @@ HWTEST_F(MediaLibraryAssetHelperCapiTest, media_library_capi_test_013, TestSize. std::shared_ptr fileAsset = std::make_shared(); fileAsset->SetResultNapiType(OHOS::Media::ResultNapiType::TYPE_PHOTOACCESS_HELPER); fileAsset->SetMediaType(OHOS::Media::MEDIA_TYPE_IMAGE); - auto mediaAsset = new OH_MediaAsset(fileAsset); - auto fileAssetPtr = mediaAsset->GetFileAssetInstance(); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto mediaAsset = new OH_MediaAsset(mediaAssetImpl); + auto fileAssetPtr = mediaAsset->mediaAsset_->GetFileAssetInstance(); auto changeRequest = OH_MediaAssetChangeRequest_Create(mediaAsset); ASSERT_NE(changeRequest, nullptr); MediaLibrary_ImageFileType imageFileType = MEDIA_LIBRARY_IMAGE_JPEG; AssetChangeOperation changeOperation = AssetChangeOperation::ADD_RESOURCE; - changeRequest->RecordChangeOperation(changeOperation); + changeRequest->request_->RecordChangeOperation(changeOperation); uint32_t result = OH_MediaAssetChangeRequest_SaveCameraPhoto(changeRequest, imageFileType); ASSERT_EQ(result, MEDIA_LIBRARY_OK); uint32_t resultChange = OH_MediaAccessHelper_ApplyChanges(changeRequest); @@ -385,13 +400,14 @@ HWTEST_F(MediaLibraryAssetHelperCapiTest, media_library_capi_test_014, TestSize. std::shared_ptr fileAsset = std::make_shared(); fileAsset->SetResultNapiType(OHOS::Media::ResultNapiType::TYPE_PHOTOACCESS_HELPER); fileAsset->SetMediaType(OHOS::Media::MEDIA_TYPE_IMAGE); - auto mediaAsset = new OH_MediaAsset(fileAsset); - auto fileAssetPtr = mediaAsset->GetFileAssetInstance(); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto mediaAsset = new OH_MediaAsset(mediaAssetImpl); + auto fileAssetPtr = mediaAsset->mediaAsset_->GetFileAssetInstance(); auto changeRequest = OH_MediaAssetChangeRequest_Create(mediaAsset); ASSERT_NE(changeRequest, nullptr); AssetChangeOperation changeOperation = AssetChangeOperation::SET_EDIT_DATA; - changeRequest->RecordChangeOperation(changeOperation); + changeRequest->request_->RecordChangeOperation(changeOperation); uint32_t result = OH_MediaAssetChangeRequest_DiscardCameraPhoto(changeRequest); ASSERT_EQ(result, MEDIA_LIBRARY_OK); uint32_t resultChange = OH_MediaAccessHelper_ApplyChanges(changeRequest); @@ -411,13 +427,14 @@ HWTEST_F(MediaLibraryAssetHelperCapiTest, media_library_capi_test_015, TestSize. std::shared_ptr fileAsset = std::make_shared(); fileAsset->SetResultNapiType(OHOS::Media::ResultNapiType::TYPE_PHOTOACCESS_HELPER); fileAsset->SetMediaType(OHOS::Media::MEDIA_TYPE_IMAGE); - auto mediaAsset = new OH_MediaAsset(fileAsset); - auto fileAssetPtr = mediaAsset->GetFileAssetInstance(); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto mediaAsset = new OH_MediaAsset(mediaAssetImpl); + auto fileAssetPtr = mediaAsset->mediaAsset_->GetFileAssetInstance(); auto changeRequest = OH_MediaAssetChangeRequest_Create(mediaAsset); ASSERT_NE(changeRequest, nullptr); AssetChangeOperation changeOperation = AssetChangeOperation::ADD_FILTERS; - changeRequest->RecordChangeOperation(changeOperation); + changeRequest->request_->RecordChangeOperation(changeOperation); uint32_t result = OH_MediaAssetChangeRequest_DiscardCameraPhoto(changeRequest); ASSERT_EQ(result, MEDIA_LIBRARY_OK); uint32_t resultChange = OH_MediaAccessHelper_ApplyChanges(changeRequest); @@ -437,13 +454,14 @@ HWTEST_F(MediaLibraryAssetHelperCapiTest, media_library_capi_test_016, TestSize. std::shared_ptr fileAsset = std::make_shared(); fileAsset->SetResultNapiType(OHOS::Media::ResultNapiType::TYPE_PHOTOACCESS_HELPER); fileAsset->SetMediaType(OHOS::Media::MEDIA_TYPE_IMAGE); - auto mediaAsset = new OH_MediaAsset(fileAsset); - auto fileAssetPtr = mediaAsset->GetFileAssetInstance(); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto mediaAsset = new OH_MediaAsset(mediaAssetImpl); + auto fileAssetPtr = mediaAsset->mediaAsset_->GetFileAssetInstance(); auto changeRequest = OH_MediaAssetChangeRequest_Create(mediaAsset); ASSERT_NE(changeRequest, nullptr); AssetChangeOperation changeOperation = AssetChangeOperation::CREATE_FROM_SCRATCH; - changeRequest->RecordChangeOperation(changeOperation); + changeRequest->request_->RecordChangeOperation(changeOperation); uint32_t result = OH_MediaAssetChangeRequest_DiscardCameraPhoto(changeRequest); ASSERT_EQ(result, MEDIA_LIBRARY_OK); uint32_t resultChange = OH_MediaAccessHelper_ApplyChanges(changeRequest); @@ -463,13 +481,14 @@ HWTEST_F(MediaLibraryAssetHelperCapiTest, media_library_capi_test_017, TestSize. std::shared_ptr fileAsset = std::make_shared(); fileAsset->SetResultNapiType(OHOS::Media::ResultNapiType::TYPE_PHOTOACCESS_HELPER); fileAsset->SetMediaType(OHOS::Media::MEDIA_TYPE_IMAGE); - auto mediaAsset = new OH_MediaAsset(fileAsset); - auto fileAssetPtr = mediaAsset->GetFileAssetInstance(); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto mediaAsset = new OH_MediaAsset(mediaAssetImpl); + auto fileAssetPtr = mediaAsset->mediaAsset_->GetFileAssetInstance(); auto changeRequest = OH_MediaAssetChangeRequest_Create(mediaAsset); ASSERT_NE(changeRequest, nullptr); AssetChangeOperation changeOperation = AssetChangeOperation::GET_WRITE_CACHE_HANDLER; - changeRequest->RecordChangeOperation(changeOperation); + changeRequest->request_->RecordChangeOperation(changeOperation); uint32_t result = OH_MediaAssetChangeRequest_DiscardCameraPhoto(changeRequest); ASSERT_EQ(result, MEDIA_LIBRARY_OK); uint32_t resultChange = OH_MediaAccessHelper_ApplyChanges(changeRequest); @@ -489,13 +508,14 @@ HWTEST_F(MediaLibraryAssetHelperCapiTest, media_library_capi_test_018, TestSize. std::shared_ptr fileAsset = std::make_shared(); fileAsset->SetResultNapiType(OHOS::Media::ResultNapiType::TYPE_PHOTOACCESS_HELPER); fileAsset->SetMediaType(OHOS::Media::MEDIA_TYPE_IMAGE); - auto mediaAsset = new OH_MediaAsset(fileAsset); - auto fileAssetPtr = mediaAsset->GetFileAssetInstance(); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto mediaAsset = new OH_MediaAsset(mediaAssetImpl); + auto fileAssetPtr = mediaAsset->mediaAsset_->GetFileAssetInstance(); auto changeRequest = OH_MediaAssetChangeRequest_Create(mediaAsset); ASSERT_NE(changeRequest, nullptr); AssetChangeOperation changeOperation = AssetChangeOperation::ADD_RESOURCE; - changeRequest->RecordChangeOperation(changeOperation); + changeRequest->request_->RecordChangeOperation(changeOperation); uint32_t result = OH_MediaAssetChangeRequest_DiscardCameraPhoto(changeRequest); ASSERT_EQ(result, MEDIA_LIBRARY_OK); uint32_t resultChange = OH_MediaAccessHelper_ApplyChanges(changeRequest); @@ -514,8 +534,9 @@ HWTEST_F(MediaLibraryAssetHelperCapiTest, media_library_capi_test_019, TestSize. { std::shared_ptr fileAsset = std::make_shared(); fileAsset->SetResultNapiType(OHOS::Media::ResultNapiType::TYPE_MEDIALIBRARY); - auto mediaAsset = new OH_MediaAsset(fileAsset); - auto fileAssetPtr = mediaAsset->GetFileAssetInstance(); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto mediaAsset = new OH_MediaAsset(mediaAssetImpl); + auto fileAssetPtr = mediaAsset->mediaAsset_->GetFileAssetInstance(); auto changeRequest = OH_MediaAssetChangeRequest_Create(mediaAsset); ASSERT_EQ(changeRequest, nullptr); @@ -537,8 +558,9 @@ HWTEST_F(MediaLibraryAssetHelperCapiTest, media_library_capi_test_020, TestSize. { std::shared_ptr fileAsset = std::make_shared(); fileAsset->SetResultNapiType(OHOS::Media::ResultNapiType::TYPE_MEDIALIBRARY); - auto mediaAsset = new OH_MediaAsset(fileAsset); - auto fileAssetPtr = mediaAsset->GetFileAssetInstance(); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto mediaAsset = new OH_MediaAsset(mediaAssetImpl); + auto fileAssetPtr = mediaAsset->mediaAsset_->GetFileAssetInstance(); auto changeRequest = OH_MediaAssetChangeRequest_Create(mediaAsset); ASSERT_EQ(changeRequest, nullptr); @@ -559,11 +581,12 @@ HWTEST_F(MediaLibraryAssetHelperCapiTest, media_library_capi_test_021, TestSize. std::shared_ptr fileAsset = std::make_shared(); fileAsset->SetResultNapiType(OHOS::Media::ResultNapiType::TYPE_PHOTOACCESS_HELPER); fileAsset->SetMediaType(OHOS::Media::MEDIA_TYPE_IMAGE); - auto mediaAsset = new OH_MediaAsset(fileAsset); - auto fileAssetPtr = mediaAsset->GetFileAssetInstance(); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto mediaAsset = new OH_MediaAsset(mediaAssetImpl); + auto fileAssetPtr = mediaAsset->mediaAsset_->GetFileAssetInstance(); AssetChangeOperation changeOperation = AssetChangeOperation::CREATE_FROM_SCRATCH; auto changeRequest = OH_MediaAssetChangeRequest_Create(mediaAsset); - changeRequest->RecordChangeOperation(changeOperation); + changeRequest->request_->RecordChangeOperation(changeOperation); ASSERT_NE(changeRequest, nullptr); uint32_t resultChange = OH_MediaAccessHelper_ApplyChanges(changeRequest); @@ -583,11 +606,12 @@ HWTEST_F(MediaLibraryAssetHelperCapiTest, media_library_capi_test_022, TestSize. std::shared_ptr fileAsset = std::make_shared(); fileAsset->SetResultNapiType(OHOS::Media::ResultNapiType::TYPE_PHOTOACCESS_HELPER); fileAsset->SetMediaType(OHOS::Media::MEDIA_TYPE_IMAGE); - auto mediaAsset = new OH_MediaAsset(fileAsset); - auto fileAssetPtr = mediaAsset->GetFileAssetInstance(); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto mediaAsset = new OH_MediaAsset(mediaAssetImpl); + auto fileAssetPtr = mediaAsset->mediaAsset_->GetFileAssetInstance(); AssetChangeOperation changeOperation = AssetChangeOperation::SET_EDIT_DATA; auto changeRequest = OH_MediaAssetChangeRequest_Create(mediaAsset); - changeRequest->RecordChangeOperation(changeOperation); + changeRequest->request_->RecordChangeOperation(changeOperation); ASSERT_NE(changeRequest, nullptr); uint32_t resultChange = OH_MediaAccessHelper_ApplyChanges(changeRequest); @@ -607,11 +631,12 @@ HWTEST_F(MediaLibraryAssetHelperCapiTest, media_library_capi_test_023, TestSize. std::shared_ptr fileAsset = std::make_shared(); fileAsset->SetResultNapiType(OHOS::Media::ResultNapiType::TYPE_PHOTOACCESS_HELPER); fileAsset->SetMediaType(OHOS::Media::MEDIA_TYPE_IMAGE); - auto mediaAsset = new OH_MediaAsset(fileAsset); - auto fileAssetPtr = mediaAsset->GetFileAssetInstance(); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto mediaAsset = new OH_MediaAsset(mediaAssetImpl); + auto fileAssetPtr = mediaAsset->mediaAsset_->GetFileAssetInstance(); AssetChangeOperation changeOperation = AssetChangeOperation::CREATE_FROM_URI; auto changeRequest = OH_MediaAssetChangeRequest_Create(mediaAsset); - changeRequest->RecordChangeOperation(changeOperation); + changeRequest->request_->RecordChangeOperation(changeOperation); ASSERT_NE(changeRequest, nullptr); uint32_t resultChange = OH_MediaAccessHelper_ApplyChanges(changeRequest); diff --git a/frameworks/innerkitsimpl/test/unittest/media_library_asset_manager_test/BUILD.gn b/frameworks/innerkitsimpl/test/unittest/media_library_asset_manager_test/BUILD.gn index 8f159c4eb2feea6a58797ccb1e135eb75fee9bab..f4492b8d264ca9d37a6972e6e00566caab7efb87 100755 --- a/frameworks/innerkitsimpl/test/unittest/media_library_asset_manager_test/BUILD.gn +++ b/frameworks/innerkitsimpl/test/unittest/media_library_asset_manager_test/BUILD.gn @@ -37,6 +37,7 @@ ohos_unittest("media_library_asset_manager_test") { "${MEDIALIB_INTERFACES_PATH}/kits/c/", "${MEDIALIB_INTERFACES_PATH}/kits/native/include", "${MEDIALIB_IMAGE_FRAMEWORK_PATH}/interfaces/kits/native/include/image", + "${MEDIALIB_NATIVE_PATH}/c_api/common", ] sources = [ @@ -50,7 +51,6 @@ ohos_unittest("media_library_asset_manager_test") { "${MEDIALIB_INTERFACES_PATH}/kits/c:native_media_asset_manager", "${MEDIALIB_INTERFACES_PATH}/kits/js:medialibrary", "${MEDIALIB_INTERFACES_PATH}/kits/js:medialibrary_js", - "${MEDIALIB_NATIVE_PATH}/c_api:native_media_library_ndk", "${MEDIALIB_NATIVE_PATH}/media_library_asset_manager:media_library_asset_manager", ] diff --git a/frameworks/innerkitsimpl/test/unittest/media_library_asset_manager_test/src/media_library_asset_manager_test.cpp b/frameworks/innerkitsimpl/test/unittest/media_library_asset_manager_test/src/media_library_asset_manager_test.cpp index a7b8781ac2fcd8fd78123707e4bd314091478b3a..be99f18e6d494799901ba6ff79c3bc1d94d65eaa 100644 --- a/frameworks/innerkitsimpl/test/unittest/media_library_asset_manager_test/src/media_library_asset_manager_test.cpp +++ b/frameworks/innerkitsimpl/test/unittest/media_library_asset_manager_test/src/media_library_asset_manager_test.cpp @@ -31,7 +31,8 @@ #include "system_ability_definition.h" #include "media_asset_base_capi.h" #include "media_asset_manager_capi.h" -#include "media_asset_impl.h" +#include "oh_media_asset.h" +#include "media_asset.h" using namespace std; using namespace OHOS; @@ -546,7 +547,8 @@ HWTEST_F(MediaLibraryAssetManagerTest, MediaLibraryAssetManager_test_008, TestSi fileAsset->SetResultNapiType(OHOS::Media::ResultNapiType::TYPE_MEDIALIBRARY); fileAsset->SetMediaType(OHOS::Media::MEDIA_TYPE_IMAGE); fileAsset->SetDisplayName(TEST_DISPLAY_NAME); - auto mediaAsset = new OH_MediaAsset(fileAsset); + auto mediaAssetImpl = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto mediaAsset = new OH_MediaAsset(mediaAssetImpl); ASSERT_NE(mediaAsset, nullptr); MediaLibrary_RequestId requestID = OH_MediaAssetManager_RequestImageForPath(manager, srcuri.c_str(), requestOptions, destUri.c_str(), callback_); @@ -561,7 +563,7 @@ HWTEST_F(MediaLibraryAssetManagerTest, MediaLibraryAssetManager_test_008, TestSi EXPECT_EQ(ret, MEDIA_LIBRARY_PARAMETER_ERROR); ret = OH_MediaAssetManager_RequestImage(manager, mediaAsset, requestOptions, &requestID, nullptr); EXPECT_EQ(ret, MEDIA_LIBRARY_PARAMETER_ERROR); - std::shared_ptr fileAsset_ = mediaAsset->GetFileAssetInstance(); + std::shared_ptr fileAsset_ = mediaAsset->mediaAsset_->GetFileAssetInstance(); const string displayName = ""; fileAsset_->SetDisplayName(displayName); ret = OH_MediaAssetManager_RequestImage(manager, mediaAsset, requestOptions, &requestID, callback); diff --git a/frameworks/native/c_api/BUILD.gn b/frameworks/native/c_api/BUILD.gn deleted file mode 100644 index 5a79570529b75db265f34520cd33690a9c18f12c..0000000000000000000000000000000000000000 --- a/frameworks/native/c_api/BUILD.gn +++ /dev/null @@ -1,97 +0,0 @@ -# Copyright (C) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//foundation/multimedia/media_library/media_library.gni") - -ohos_shared_library("native_media_library_ndk") { - install_enable = true - - sources = [ - "${MEDIALIB_NATIVE_PATH}/c_api/media_asset_change_request_impl.cpp", - "${MEDIALIB_NATIVE_PATH}/c_api/media_asset_helper.cpp", - "${MEDIALIB_NATIVE_PATH}/c_api/media_asset_impl.cpp", - "${MEDIALIB_NATIVE_PATH}/c_api/media_userfile_client.cpp", - ] - - include_dirs = [ - "${MEDIALIB_INTERFACES_PATH}/inner_api/media_library_helper/include", - "${MEDIALIB_INTERFACES_PATH}/kits/c", - "${MEDIALIB_INNERKITS_PATH}/media_library_helper/include", - "${MEDIALIB_ROOT_PATH}/frameworks/utils/include", - "${MEDIALIB_NATIVE_PATH}/c_api/common", - ] - - deps = [ - "${MEDIALIB_INNERKITS_PATH}/media_library_helper:media_library", - "${MEDIALIB_UTILS_PATH}:permission_utils", - ] - - external_deps = [ - "ability_base:want", - "ability_base:zuri", - "ability_runtime:app_context", - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libprivacy_sdk", - "access_token:libtoken_setproc", - "access_token:libtokenid_sdk", - "app_file_service:fileuri_native", - "bundle_framework:appexecfwk_core", - "c_utils:utils", - "data_share:datashare_common", - "data_share:datashare_consumer", - "hilog:libhilog", - "hitrace:hitrace_meter", - "image_framework:image_native", - "image_framework:ohimage", - "ipc:ipc_core", - "napi:ace_napi", - "player_framework:media_client", - "relational_store:native_rdb", - "relational_store:rdb_data_share_adapter", - "resource_management:librawfile", - ] - - public_external_deps = [ "e2fsprogs:libext2_uuid" ] - - ldflags = [ "-Wl,--gc-sections" ] - - cflags = [ - "-Wall", - "-Werror", - "-Wno-unused-but-set-variable", - "-fdata-sections", - "-ffunction-sections", - "-Os", - ] - - cflags_cc = [ "-Os" ] - - if (!media_library_link_opt) { - sanitize = { - cfi = true - cfi_cross_dso = true - debug = false - integer_overflow = true - ubsan = true - boundary_sanitize = true - stack_protector_ret = true - } - } - - defines = [ "MEDIALIBRARY_COMPATIBILITY=1" ] - - part_name = "media_library" - subsystem_name = "multimedia" -} diff --git a/frameworks/native/c_api/common/oh_media_asset.h b/frameworks/native/c_api/common/oh_media_asset.h new file mode 100644 index 0000000000000000000000000000000000000000..95c05d9ebb4c8d9e89e71fb093c15ebee2b3baaf --- /dev/null +++ b/frameworks/native/c_api/common/oh_media_asset.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MULTIMEDIA_MEDIA_LIBRARY_NATIVE_OH_MEDIA_ASSET_H +#define MULTIMEDIA_MEDIA_LIBRARY_NATIVE_OH_MEDIA_ASSET_H + +#include +#include "media_asset.h" + +struct OH_MediaAsset : public OHOS::RefBase { + explicit OH_MediaAsset(const std::shared_ptr &mediaAsset) + : mediaAsset_(mediaAsset) {} + ~OH_MediaAsset() = default; + + std::shared_ptr mediaAsset_ = nullptr; +}; + +#endif // MULTIMEDIA_MEDIA_LIBRARY_NATIVE_OH_MEDIA_ASSET_H \ No newline at end of file diff --git a/frameworks/native/c_api/common/oh_media_asset_change_request.h b/frameworks/native/c_api/common/oh_media_asset_change_request.h new file mode 100644 index 0000000000000000000000000000000000000000..ea9257b42858adeabd277a3da3756c90b8d5e1ae --- /dev/null +++ b/frameworks/native/c_api/common/oh_media_asset_change_request.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MULTIMEDIA_MEDIA_LIBRARY_NATIVE_OH_MEDIA_ASSET_CHANGE_REQUEST_H +#define MULTIMEDIA_MEDIA_LIBRARY_NATIVE_OH_MEDIA_ASSET_CHANGE_REQUEST_H + +#include +#include "media_asset.h" +#include "media_asset_change_request.h" + +struct OH_MediaAssetChangeRequest : public OHOS::RefBase { + explicit OH_MediaAssetChangeRequest(const std::shared_ptr &request) + : request_(request) {} + ~OH_MediaAssetChangeRequest() = default; + + std::shared_ptr request_ = nullptr; +}; + +#endif // MULTIMEDIA_MEDIA_LIBRARY_NATIVE_OH_MEDIA_ASSET_CHANGE_REQUEST_H \ No newline at end of file diff --git a/frameworks/native/c_api/common/oh_moving_photo.h b/frameworks/native/c_api/common/oh_moving_photo.h new file mode 100644 index 0000000000000000000000000000000000000000..123a8dd6b5fb1f018b7c39ff0df8372dfdd12a91 --- /dev/null +++ b/frameworks/native/c_api/common/oh_moving_photo.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MULTIMEDIA_MEDIA_LIBRARY_NATIVE_OH_MOVING_PHOTO_H +#define MULTIMEDIA_MEDIA_LIBRARY_NATIVE_OH_MOVING_PHOTO_H + +#include +#include "moving_photo.h" + +struct OH_MovingPhoto : public OHOS::RefBase { + explicit OH_MovingPhoto(const std::shared_ptr &movingPhoto) + : movingPhoto_(movingPhoto) {} + ~OH_MovingPhoto() = default; + + std::shared_ptr movingPhoto_ = nullptr; +}; + +#endif // MULTIMEDIA_MEDIA_LIBRARY_NATIVE_OH_MOVING_PHOTO_H \ No newline at end of file diff --git a/frameworks/native/c_api/media_access_helper_capi/media_access_helper_capi.cpp b/frameworks/native/c_api/media_access_helper_capi/media_access_helper_capi.cpp index 67f2fed3abc16c398a53f0453337b14e73421442..8381b98591858424d60311cd85343b576091f4fc 100644 --- a/frameworks/native/c_api/media_access_helper_capi/media_access_helper_capi.cpp +++ b/frameworks/native/c_api/media_access_helper_capi/media_access_helper_capi.cpp @@ -16,11 +16,13 @@ #include "media_access_helper_capi.h" #include "media_log.h" -#include "media_asset_change_request_impl.h" +#include "oh_media_asset_change_request.h" MediaLibrary_ErrorCode OH_MediaAccessHelper_ApplyChanges(OH_MediaAssetChangeRequest* changeRequest) { CHECK_AND_RETURN_RET_LOG(changeRequest != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "changeRequest is nullptr!"); + CHECK_AND_RETURN_RET_LOG(changeRequest->request_ != nullptr, MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, + "request_ is nullptr!"); - return changeRequest->ApplyChanges(); + return changeRequest->request_->ApplyChanges(); } \ No newline at end of file diff --git a/frameworks/native/c_api/media_asset_capi/media_asset_capi.cpp b/frameworks/native/c_api/media_asset_capi/media_asset_capi.cpp index 2fb352b517fddb0df07f7f14ff018d7ff661cd35..861a93d0c08ac609073307e42624b53d38b59084 100644 --- a/frameworks/native/c_api/media_asset_capi/media_asset_capi.cpp +++ b/frameworks/native/c_api/media_asset_capi/media_asset_capi.cpp @@ -16,62 +16,167 @@ #include "media_asset_capi.h" #include "media_log.h" -#include "media_asset_impl.h" +#include "oh_media_asset.h" MediaLibrary_ErrorCode OH_MediaAsset_GetUri(OH_MediaAsset* mediaAsset, const char** uri) { CHECK_AND_RETURN_RET_LOG(mediaAsset != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "mediaAsset is nullptr!"); + CHECK_AND_RETURN_RET_LOG(mediaAsset->mediaAsset_ != nullptr, + MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "mediaAsset_ is nullptr!"); CHECK_AND_RETURN_RET_LOG(uri != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "uri is nullptr!"); - return mediaAsset->GetUri(uri); + return mediaAsset->mediaAsset_->GetUri(uri); +} + +MediaLibrary_ErrorCode OH_MediaAsset_GetMediaType(OH_MediaAsset* mediaAsset, MediaLibrary_MediaType* mediaType) +{ + CHECK_AND_RETURN_RET_LOG(mediaAsset != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "mediaAsset is nullptr!"); + CHECK_AND_RETURN_RET_LOG(mediaAsset->mediaAsset_ != nullptr, + MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "mediaAsset_ is nullptr!"); + CHECK_AND_RETURN_RET_LOG(mediaType != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "mediaType is nullptr!"); + + return mediaAsset->mediaAsset_->GetMediaType(mediaType); +} + +MediaLibrary_ErrorCode OH_MediaAsset_GetMediaSubType(OH_MediaAsset* mediaAsset, + MediaLibrary_MediaSubType* mediaSubType) +{ + CHECK_AND_RETURN_RET_LOG(mediaAsset != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "mediaAsset is nullptr!"); + CHECK_AND_RETURN_RET_LOG(mediaAsset->mediaAsset_ != nullptr, + MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "mediaAsset_ is nullptr!"); + CHECK_AND_RETURN_RET_LOG(mediaSubType != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "mediaSubType is nullptr!"); + + return mediaAsset->mediaAsset_->GetMediaSubType(mediaSubType); } MediaLibrary_ErrorCode OH_MediaAsset_GetDisplayName(OH_MediaAsset* mediaAsset, const char** displayName) { CHECK_AND_RETURN_RET_LOG(mediaAsset != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "mediaAsset is nullptr!"); + CHECK_AND_RETURN_RET_LOG(mediaAsset->mediaAsset_ != nullptr, + MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "mediaAsset_ is nullptr!"); CHECK_AND_RETURN_RET_LOG(displayName != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "displayName is nullptr!"); - return mediaAsset->GetDisplayName(displayName); + return mediaAsset->mediaAsset_->GetDisplayName(displayName); } MediaLibrary_ErrorCode OH_MediaAsset_GetSize(OH_MediaAsset* mediaAsset, uint32_t* size) { CHECK_AND_RETURN_RET_LOG(mediaAsset != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "mediaAsset is nullptr!"); + CHECK_AND_RETURN_RET_LOG(mediaAsset->mediaAsset_ != nullptr, + MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "mediaAsset_ is nullptr!"); CHECK_AND_RETURN_RET_LOG(size != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "size is nullptr!"); - return mediaAsset->GetSize(size); + return mediaAsset->mediaAsset_->GetSize(size); +} + +MediaLibrary_ErrorCode OH_MediaAsset_GetDateAdded(OH_MediaAsset* mediaAsset, uint32_t* dateAdded) +{ + CHECK_AND_RETURN_RET_LOG(mediaAsset != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "mediaAsset is nullptr!"); + CHECK_AND_RETURN_RET_LOG(mediaAsset->mediaAsset_ != nullptr, + MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "mediaAsset_ is nullptr!"); + CHECK_AND_RETURN_RET_LOG(dateAdded != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "dateAdded is nullptr!"); + + return mediaAsset->mediaAsset_->GetDateAdded(dateAdded); +} + +MediaLibrary_ErrorCode OH_MediaAsset_GetDateModified(OH_MediaAsset* mediaAsset, uint32_t* dateModified) +{ + CHECK_AND_RETURN_RET_LOG(mediaAsset != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "mediaAsset is nullptr!"); + CHECK_AND_RETURN_RET_LOG(mediaAsset->mediaAsset_ != nullptr, + MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "mediaAsset_ is nullptr!"); + CHECK_AND_RETURN_RET_LOG(dateModified != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "dateModified is nullptr!"); + + return mediaAsset->mediaAsset_->GetDateModified(dateModified); +} + +MediaLibrary_ErrorCode OH_MediaAsset_GetDateTaken(OH_MediaAsset* mediaAsset, uint32_t* dateTaken) +{ + CHECK_AND_RETURN_RET_LOG(mediaAsset != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "mediaAsset is nullptr!"); + CHECK_AND_RETURN_RET_LOG(mediaAsset->mediaAsset_ != nullptr, + MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "mediaAsset_ is nullptr!"); + CHECK_AND_RETURN_RET_LOG(dateTaken != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "dateTaken is nullptr!"); + + return mediaAsset->mediaAsset_->GetDateTaken(dateTaken); +} + +MediaLibrary_ErrorCode OH_MediaAsset_GetDateAddedMs(OH_MediaAsset* mediaAsset, uint32_t* dateAddedMs) +{ + CHECK_AND_RETURN_RET_LOG(mediaAsset != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "mediaAsset is nullptr!"); + CHECK_AND_RETURN_RET_LOG(mediaAsset->mediaAsset_ != nullptr, + MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "mediaAsset_ is nullptr!"); + CHECK_AND_RETURN_RET_LOG(dateAddedMs != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "dateAddedMs is nullptr!"); + + return mediaAsset->mediaAsset_->GetDateAddedMs(dateAddedMs); } MediaLibrary_ErrorCode OH_MediaAsset_GetDateModifiedMs(OH_MediaAsset* mediaAsset, uint32_t* dateModifiedMs) { CHECK_AND_RETURN_RET_LOG(mediaAsset != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "mediaAsset is nullptr!"); + CHECK_AND_RETURN_RET_LOG(mediaAsset->mediaAsset_ != nullptr, + MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "mediaAsset_ is nullptr!"); CHECK_AND_RETURN_RET_LOG(dateModifiedMs != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "dateModifiedMs is nullptr!"); - return mediaAsset->GetDateModifiedMs(dateModifiedMs); + return mediaAsset->mediaAsset_->GetDateModifiedMs(dateModifiedMs); +} + +MediaLibrary_ErrorCode OH_MediaAsset_GetDuration(OH_MediaAsset* mediaAsset, uint32_t* duration) +{ + CHECK_AND_RETURN_RET_LOG(mediaAsset != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "mediaAsset is nullptr!"); + CHECK_AND_RETURN_RET_LOG(mediaAsset->mediaAsset_ != nullptr, + MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "mediaAsset_ is nullptr!"); + CHECK_AND_RETURN_RET_LOG(duration != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "duration is nullptr!"); + + return mediaAsset->mediaAsset_->GetDuration(duration); } MediaLibrary_ErrorCode OH_MediaAsset_GetWidth(OH_MediaAsset* mediaAsset, uint32_t* width) { CHECK_AND_RETURN_RET_LOG(mediaAsset != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "mediaAsset is nullptr!"); + CHECK_AND_RETURN_RET_LOG(mediaAsset->mediaAsset_ != nullptr, + MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "mediaAsset_ is nullptr!"); CHECK_AND_RETURN_RET_LOG(width != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "width is nullptr!"); - return mediaAsset->GetWidth(width); + return mediaAsset->mediaAsset_->GetWidth(width); } MediaLibrary_ErrorCode OH_MediaAsset_GetHeight(OH_MediaAsset* mediaAsset, uint32_t* height) { CHECK_AND_RETURN_RET_LOG(mediaAsset != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "mediaAsset is nullptr!"); + CHECK_AND_RETURN_RET_LOG(mediaAsset->mediaAsset_ != nullptr, + MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "mediaAsset_ is nullptr!"); CHECK_AND_RETURN_RET_LOG(height != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "height is nullptr!"); - return mediaAsset->GetHeight(height); + return mediaAsset->mediaAsset_->GetHeight(height); } MediaLibrary_ErrorCode OH_MediaAsset_GetOrientation(OH_MediaAsset* mediaAsset, uint32_t* orientation) { CHECK_AND_RETURN_RET_LOG(mediaAsset != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "mediaAsset is nullptr!"); + CHECK_AND_RETURN_RET_LOG(mediaAsset->mediaAsset_ != nullptr, + MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "mediaAsset_ is nullptr!"); CHECK_AND_RETURN_RET_LOG(orientation != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "orientation is nullptr!"); - return mediaAsset->GetOrientation(orientation); + return mediaAsset->mediaAsset_->GetOrientation(orientation); +} + +MediaLibrary_ErrorCode OH_MediaAsset_IsFavorite(OH_MediaAsset* mediaAsset, uint32_t* favorite) +{ + CHECK_AND_RETURN_RET_LOG(mediaAsset != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "mediaAsset is nullptr!"); + CHECK_AND_RETURN_RET_LOG(mediaAsset->mediaAsset_ != nullptr, + MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "mediaAsset_ is nullptr!"); + CHECK_AND_RETURN_RET_LOG(favorite != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "favorite is nullptr!"); + + return mediaAsset->mediaAsset_->IsFavorite(favorite); +} + +MediaLibrary_ErrorCode OH_MediaAsset_GetTitle(OH_MediaAsset* mediaAsset, const char** title) +{ + CHECK_AND_RETURN_RET_LOG(mediaAsset != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "mediaAsset is nullptr!"); + CHECK_AND_RETURN_RET_LOG(mediaAsset->mediaAsset_ != nullptr, + MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "mediaAsset_ is nullptr!"); + CHECK_AND_RETURN_RET_LOG(title != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "title is nullptr!"); + + return mediaAsset->mediaAsset_->GetTitle(title); } MediaLibrary_ErrorCode OH_MediaAsset_Release(OH_MediaAsset* mediaAsset) diff --git a/frameworks/native/c_api/media_asset_change_request_capi/media_asset_change_request_capi.cpp b/frameworks/native/c_api/media_asset_change_request_capi/media_asset_change_request_capi.cpp index 0b8dd9a6f36594abffe65cc5bcda6cf5fe87021a..d634225e94121c0b08840af408fde23ccbc2802f 100644 --- a/frameworks/native/c_api/media_asset_change_request_capi/media_asset_change_request_capi.cpp +++ b/frameworks/native/c_api/media_asset_change_request_capi/media_asset_change_request_capi.cpp @@ -16,48 +16,83 @@ #include "media_asset_change_request_capi.h" #include "media_log.h" -#include "media_asset_change_request_impl.h" -#include "media_asset_impl.h" +#include "oh_media_asset.h" +#include "oh_media_asset_change_request.h" +#include "media_asset_change_request.h" #include "userfile_manager_types.h" +using namespace OHOS::Media; + +MediaLibrary_ErrorCode OH_MediaAssetChangeRequest_GetWriteCacheHandler(OH_MediaAssetChangeRequest* changeRequest, + int32_t* fd) +{ + CHECK_AND_RETURN_RET_LOG(changeRequest != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "changeRequest is nullptr!"); + CHECK_AND_RETURN_RET_LOG(changeRequest->request_ != nullptr, MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, + "request_ is nullptr!"); + + return changeRequest->request_->GetWriteCacheHandler(fd); +} + MediaLibrary_ErrorCode OH_MediaAssetChangeRequest_SaveCameraPhoto(OH_MediaAssetChangeRequest* changeRequest, MediaLibrary_ImageFileType imageFileType) { CHECK_AND_RETURN_RET_LOG(changeRequest != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "changeRequest is nullptr!"); + CHECK_AND_RETURN_RET_LOG(changeRequest->request_ != nullptr, MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, + "request_ is nullptr!"); - return changeRequest->SaveCameraPhoto(imageFileType); + return changeRequest->request_->SaveCameraPhoto(imageFileType); } MediaLibrary_ErrorCode OH_MediaAssetChangeRequest_DiscardCameraPhoto(OH_MediaAssetChangeRequest* changeRequest) { CHECK_AND_RETURN_RET_LOG(changeRequest != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "changeRequest is nullptr!"); + CHECK_AND_RETURN_RET_LOG(changeRequest->request_ != nullptr, MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, + "request_ is nullptr!"); - return changeRequest->DiscardCameraPhoto(); + return changeRequest->request_->DiscardCameraPhoto(); } OH_MediaAssetChangeRequest* OH_MediaAssetChangeRequest_Create(OH_MediaAsset* mediaAsset) { CHECK_AND_RETURN_RET_LOG(mediaAsset != nullptr, nullptr, "mediaAsset is nullptr!"); - auto fileAssetPtr = mediaAsset->GetFileAssetInstance(); + CHECK_AND_RETURN_RET_LOG(mediaAsset->mediaAsset_ != nullptr, nullptr, "mediaAsset_ is nullptr!"); + auto fileAssetPtr = mediaAsset->mediaAsset_->GetFileAssetInstance(); CHECK_AND_RETURN_RET_LOG(fileAssetPtr != nullptr, nullptr, "fileAssetPtr is nullptr!"); OH_MediaAssetChangeRequest* changeRequest = nullptr; if (fileAssetPtr->GetMediaType() == OHOS::Media::MEDIA_TYPE_IMAGE || fileAssetPtr->GetMediaType() == OHOS::Media::MEDIA_TYPE_VIDEO) { - changeRequest = new OH_MediaAssetChangeRequest(mediaAsset); + auto mediaAssetChangeRequest = + MediaAssetChangeRequestFactory::CreateMediaAssetChangeRequest(mediaAsset->mediaAsset_); + CHECK_AND_RETURN_RET_LOG(mediaAssetChangeRequest != nullptr, nullptr, + "create CreateMediaAssetChangeRequest failed!"); + changeRequest = new OH_MediaAssetChangeRequest(mediaAssetChangeRequest); CHECK_AND_RETURN_RET_LOG(changeRequest != nullptr, nullptr, "create OH_MediaAssetChangeRequest failed!"); } return changeRequest; } +MediaLibrary_ErrorCode OH_MediaAssetChangeRequest_AddResourceWithUri(OH_MediaAssetChangeRequest* changeRequest, + MediaLibrary_ResourceType resourceType, char* fileUri) +{ + CHECK_AND_RETURN_RET_LOG(changeRequest != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "changeRequest is nullptr!"); + CHECK_AND_RETURN_RET_LOG(changeRequest->request_ != nullptr, MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, + "request_ is nullptr!"); + CHECK_AND_RETURN_RET_LOG(fileUri != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "fileUri is nullptr!"); + + return changeRequest->request_->AddResourceWithUri(resourceType, fileUri); +} + MediaLibrary_ErrorCode OH_MediaAssetChangeRequest_AddResourceWithBuffer(OH_MediaAssetChangeRequest* changeRequest, MediaLibrary_ResourceType resourceType, uint8_t* buffer, uint32_t length) { CHECK_AND_RETURN_RET_LOG(changeRequest != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "changeRequest is nullptr!"); + CHECK_AND_RETURN_RET_LOG(changeRequest->request_ != nullptr, MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, + "request_ is nullptr!"); CHECK_AND_RETURN_RET_LOG(buffer != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "buffer is null"); CHECK_AND_RETURN_RET_LOG(length > 0, MEDIA_LIBRARY_PARAMETER_ERROR, "length is zero"); - return changeRequest->AddResourceWithBuffer(resourceType, buffer, length); + return changeRequest->request_->AddResourceWithBuffer(resourceType, buffer, length); } MediaLibrary_ErrorCode OH_MediaAssetChangeRequest_Release(OH_MediaAssetChangeRequest* changeRequest) diff --git a/frameworks/native/c_api/media_asset_change_request_impl.cpp b/frameworks/native/c_api/media_asset_change_request_impl.cpp index 856c3eebdb2f93fe7b414a777a410f12d05ecc11..e43f4fb57c85c94bb06b12c195764f6c6a4a787a 100644 --- a/frameworks/native/c_api/media_asset_change_request_impl.cpp +++ b/frameworks/native/c_api/media_asset_change_request_impl.cpp @@ -17,8 +17,9 @@ #include #include +#include "securec.h" -#include "media_asset_impl.h" +#include "oh_media_asset.h" #include "media_log.h" #include "medialibrary_errno.h" #include "media_file_utils.h" @@ -26,7 +27,6 @@ #include "file_uri.h" #include "directory_ex.h" #include "medialibrary_db_const.h" -#include "avmetadatahelper.h" #include "access_token.h" #include "accesstoken_kit.h" #include "ipc_skeleton.h" @@ -39,11 +39,20 @@ using namespace std; using namespace OHOS::Media; using namespace OHOS::Security::AccessToken; -atomic OH_MediaAssetChangeRequest::cacheFileId_(0); +atomic MediaAssetChangeRequestImpl::cacheFileId_(0); const string MOVING_PHOTO_VIDEO_EXTENSION = "mp4"; const string API_VERSION = "api_version"; -OH_MediaAssetChangeRequest::OH_MediaAssetChangeRequest(OH_MediaAsset* mediaAsset) +std::shared_ptr MediaAssetChangeRequestFactory::CreateMediaAssetChangeRequest( + std::shared_ptr mediaAsset) +{ + std::shared_ptr impl = std::make_shared(mediaAsset); + CHECK_AND_PRINT_LOG(impl != nullptr, "Failed to create MediaAssetChangeRequestImpl instance."); + + return impl; +} + +MediaAssetChangeRequestImpl::MediaAssetChangeRequestImpl(std::shared_ptr mediaAsset) { mediaAsset_ = mediaAsset; movingPhotoVideoDataBuffer_ = nullptr; @@ -54,7 +63,7 @@ OH_MediaAssetChangeRequest::OH_MediaAssetChangeRequest(OH_MediaAsset* mediaAsset dataBufferSize_ = 0; } -OH_MediaAssetChangeRequest::~OH_MediaAssetChangeRequest() +MediaAssetChangeRequestImpl::~MediaAssetChangeRequestImpl() { mediaAsset_ = nullptr; if (movingPhotoVideoDataBuffer_ != nullptr) { @@ -75,7 +84,26 @@ OH_MediaAssetChangeRequest::~OH_MediaAssetChangeRequest() assetChangeOperations_.clear(); } -MediaLibrary_ErrorCode OH_MediaAssetChangeRequest::SaveCameraPhoto(MediaLibrary_ImageFileType imageFileType) +MediaLibrary_ErrorCode MediaAssetChangeRequestImpl::GetWriteCacheHandler(int32_t* fd) +{ + unique_lock ulock(mutex_); + auto fileAsset = mediaAsset_->GetFileAssetInstance(); + CHECK_AND_RETURN_RET_LOG(fileAsset != nullptr, MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR, "fileAsset get failed!"); + CHECK_AND_RETURN_RET_LOG(!IsMovingPhoto(), MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "cann't be moving photo!"); + CHECK_AND_RETURN_RET_LOG(CheckWriteOperation(MediaLibrary_ResourceType::MEDIA_LIBRARY_VIDEO_RESOURCE), + MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "Not supported!"); + + int32_t ret = OpenWriteCacheHandler(); + if (ret < 0) { + MEDIA_ERR_LOG("Failed to open write cache handler,ret: %{public}d", ret); + return MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED; + } + *fd = ret; + RecordChangeOperation(AssetChangeOperation::GET_WRITE_CACHE_HANDLER); + return MEDIA_LIBRARY_OK; +} + +MediaLibrary_ErrorCode MediaAssetChangeRequestImpl::SaveCameraPhoto(MediaLibrary_ImageFileType imageFileType) { CHECK_AND_RETURN_RET_LOG(imageFileType == MEDIA_LIBRARY_IMAGE_JPEG, MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "imageFileType not support"); @@ -88,7 +116,7 @@ MediaLibrary_ErrorCode OH_MediaAssetChangeRequest::SaveCameraPhoto(MediaLibrary_ return MEDIA_LIBRARY_OK; } -MediaLibrary_ErrorCode OH_MediaAssetChangeRequest::DiscardCameraPhoto() +MediaLibrary_ErrorCode MediaAssetChangeRequestImpl::DiscardCameraPhoto() { unique_lock ulock(mutex_); auto fileAsset = mediaAsset_->GetFileAssetInstance(); @@ -98,44 +126,63 @@ MediaLibrary_ErrorCode OH_MediaAssetChangeRequest::DiscardCameraPhoto() return MEDIA_LIBRARY_OK; } -MediaLibrary_ErrorCode OH_MediaAssetChangeRequest::AddResourceWithBuffer(MediaLibrary_ResourceType resourceType, - uint8_t* buffer, uint32_t length) +MediaLibrary_ErrorCode MediaAssetChangeRequestImpl::AddResourceWithUri(MediaLibrary_ResourceType resourceType, + char* fileUri) { unique_lock ulock(mutex_); CHECK_AND_RETURN_RET_LOG(CheckWriteOperation(resourceType), MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "operation not support"); + string realPath; + OHOS::AppFileService::ModuleFileUri::FileUri fileUriStr(fileUri); + string path = fileUriStr.GetRealPath(); + bool result = OHOS::PathToRealPath(path, realPath); + CHECK_AND_RETURN_RET_LOG(result, MEDIA_LIBRARY_NO_SUCH_FILE, "File real path isn't existed"); + auto fileAsset = mediaAsset_->GetFileAssetInstance(); CHECK_AND_RETURN_RET_LOG(fileAsset != nullptr, MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "fileAsset get failed!"); if ((fileAsset->GetPhotoSubType() == static_cast(PhotoSubType::MOVING_PHOTO)) && resourceType == static_cast(MediaLibrary_ResourceType::MEDIA_LIBRARY_VIDEO_RESOURCE)) { - if (movingPhotoVideoDataBuffer_ != nullptr) { - delete[] movingPhotoVideoDataBuffer_; + if ((MediaType::MEDIA_TYPE_VIDEO) != MediaFileUtils::GetMediaType(realPath)) { + MEDIA_ERR_LOG("Invalid file type"); + return MEDIA_LIBRARY_PARAMETER_ERROR; } - movingPhotoVideoDataBuffer_ = new uint8_t[length + 1]; - CHECK_AND_RETURN_RET_LOG(movingPhotoVideoDataBuffer_ != nullptr, MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR, - "create movingPhotoVideoDataBuffer_ failed!"); - - movingPhotoVideoBufferSize_ = length; - if (length > 0) { - int ret = memcpy_s(movingPhotoVideoDataBuffer_, length + 1, buffer, length); - CHECK_AND_RETURN_RET_LOG(ret == EOK, MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR, - "memcpy buffer failed!"); - } - - if (!(CheckMovingPhotoVideo(static_cast(movingPhotoVideoDataBuffer_), - static_cast(length)))) { + if (!(MediaFileUtils::CheckMovingPhotoVideo(realPath))) { MEDIA_ERR_LOG("invalid param code"); - return MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR; + return MEDIA_LIBRARY_NO_SUCH_FILE; } - movingPhotoVideoResourceMode_ = AddResourceMode::DATA_BUFFER; + movingPhotoVideoRealPath_ = realPath; + movingPhotoVideoResourceMode_ = AddResourceMode::FILE_URI; RecordChangeOperation(AssetChangeOperation::ADD_RESOURCE); addResourceTypes_.push_back(MediaLibrary_ResourceType::MEDIA_LIBRARY_VIDEO_RESOURCE); return MEDIA_LIBRARY_OK; } + if (fileAsset->GetMediaType() != MediaFileUtils::GetMediaType(realPath)) { + MEDIA_ERR_LOG("Invalid file type"); + return MEDIA_LIBRARY_PARAMETER_ERROR; + } + realPath_ = realPath; + addResourceMode_ = AddResourceMode::FILE_URI; + RecordChangeOperation(AssetChangeOperation::ADD_RESOURCE); + addResourceTypes_.push_back(resourceType); + return MEDIA_LIBRARY_OK; +} + +MediaLibrary_ErrorCode MediaAssetChangeRequestImpl::AddResourceWithBuffer(MediaLibrary_ResourceType resourceType, + uint8_t* buffer, uint32_t length) +{ + unique_lock ulock(mutex_); + CHECK_AND_RETURN_RET_LOG(CheckWriteOperation(resourceType), MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, + "operation not support"); + + auto fileAsset = mediaAsset_->GetFileAssetInstance(); + CHECK_AND_RETURN_RET_LOG(fileAsset != nullptr, MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "fileAsset get failed!"); + CHECK_AND_RETURN_RET_LOG(!IsMovingPhoto(), MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, + "not support edit moving photo with buffer"); + if (dataBuffer_ != nullptr) { delete[] dataBuffer_; } @@ -146,7 +193,7 @@ MediaLibrary_ErrorCode OH_MediaAssetChangeRequest::AddResourceWithBuffer(MediaLi dataBufferSize_ = length; if (length > 0) { int ret = memcpy_s(dataBuffer_, length + 1, buffer, length); - CHECK_AND_RETURN_RET_LOG(ret == EOK, MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR, + CHECK_AND_RETURN_RET_LOG(ret == E_OK, MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR, "memcpy buffer failed!"); } addResourceMode_ = AddResourceMode::DATA_BUFFER; @@ -155,7 +202,7 @@ MediaLibrary_ErrorCode OH_MediaAssetChangeRequest::AddResourceWithBuffer(MediaLi return MEDIA_LIBRARY_OK; } -MediaLibrary_ErrorCode OH_MediaAssetChangeRequest::ApplyChanges() +MediaLibrary_ErrorCode MediaAssetChangeRequestImpl::ApplyChanges() { unique_lock ulock(mutex_); bool result = CheckChangeOperations(); @@ -170,13 +217,7 @@ MediaLibrary_ErrorCode OH_MediaAssetChangeRequest::ApplyChanges() continue; } - bool valid = false; - if (changeOperation == AssetChangeOperation::CREATE_FROM_SCRATCH || - changeOperation == AssetChangeOperation::SET_EDIT_DATA) { - valid = true; - } else { - valid = ChangeOperationExecute(changeOperation); - } + bool valid = ChangeOperationExecute(changeOperation); if (!valid) { MEDIA_ERR_LOG("Failed to apply asset change request, operation: %{public}d", changeOperation); @@ -186,10 +227,12 @@ MediaLibrary_ErrorCode OH_MediaAssetChangeRequest::ApplyChanges() } assetChangeOperations_.clear(); addResourceTypes_.clear(); + movingPhotoVideoResourceMode_ = AddResourceMode::DEFAULT; + addResourceMode_ = AddResourceMode::DEFAULT; return MEDIA_LIBRARY_OK; } -bool OH_MediaAssetChangeRequest::IsMovingPhoto() +bool MediaAssetChangeRequestImpl::IsMovingPhoto() { auto fileAsset = mediaAsset_->GetFileAssetInstance(); CHECK_AND_RETURN_RET_LOG(fileAsset != nullptr, false, "fileAsset is nullptr"); @@ -197,7 +240,7 @@ bool OH_MediaAssetChangeRequest::IsMovingPhoto() return fileAsset->GetPhotoSubType() == static_cast(PhotoSubType::MOVING_PHOTO); } -bool OH_MediaAssetChangeRequest::CheckWriteOperation(MediaLibrary_ResourceType resourceType) +bool MediaAssetChangeRequestImpl::CheckWriteOperation(MediaLibrary_ResourceType resourceType) { if (IsMovingPhoto()) { CHECK_AND_RETURN_RET_LOG(CheckMovingPhotoResource(resourceType), false, @@ -214,7 +257,7 @@ bool OH_MediaAssetChangeRequest::CheckWriteOperation(MediaLibrary_ResourceType r return true; } -bool OH_MediaAssetChangeRequest::CheckMovingPhotoResource(MediaLibrary_ResourceType resourceType) +bool MediaAssetChangeRequestImpl::CheckMovingPhotoResource(MediaLibrary_ResourceType resourceType) { bool isResourceTypeVaild = !ContainsResource(resourceType); int addResourceTimes = @@ -222,18 +265,18 @@ bool OH_MediaAssetChangeRequest::CheckMovingPhotoResource(MediaLibrary_ResourceT return isResourceTypeVaild && addResourceTimes <= 1; } -bool OH_MediaAssetChangeRequest::ContainsResource(MediaLibrary_ResourceType resourceType) +bool MediaAssetChangeRequestImpl::ContainsResource(MediaLibrary_ResourceType resourceType) { return find(addResourceTypes_.begin(), addResourceTypes_.end(), resourceType) != addResourceTypes_.end(); } -bool OH_MediaAssetChangeRequest::Contains(AssetChangeOperation changeOperation) +bool MediaAssetChangeRequestImpl::Contains(AssetChangeOperation changeOperation) { return find(assetChangeOperations_.begin(), assetChangeOperations_.end(), changeOperation) != assetChangeOperations_.end(); } -int32_t OH_MediaAssetChangeRequest::OpenWriteCacheHandler(bool isMovingPhotoVideo) +int32_t MediaAssetChangeRequestImpl::OpenWriteCacheHandler(bool isMovingPhotoVideo) { auto fileAsset = mediaAsset_->GetFileAssetInstance(); CHECK_AND_RETURN_RET_LOG(fileAsset != nullptr, E_FAIL, "fileAsset is null"); @@ -262,12 +305,12 @@ int32_t OH_MediaAssetChangeRequest::OpenWriteCacheHandler(bool isMovingPhotoVide return ret; } -uint32_t OH_MediaAssetChangeRequest::FetchAddCacheFileId() +uint32_t MediaAssetChangeRequestImpl::FetchAddCacheFileId() { return cacheFileId_.fetch_add(1); } -void OH_MediaAssetChangeRequest::RecordChangeOperation(AssetChangeOperation changeOperation) +void MediaAssetChangeRequestImpl::RecordChangeOperation(AssetChangeOperation changeOperation) { if ((changeOperation == AssetChangeOperation::GET_WRITE_CACHE_HANDLER || changeOperation == AssetChangeOperation::ADD_RESOURCE || @@ -279,35 +322,7 @@ void OH_MediaAssetChangeRequest::RecordChangeOperation(AssetChangeOperation chan assetChangeOperations_.push_back(changeOperation); } -bool OH_MediaAssetChangeRequest::CheckMovingPhotoVideo(void* dataBuffer, size_t size) -{ - auto dataSource = make_shared(dataBuffer, static_cast(size)); - auto avMetadataHelper = AVMetadataHelperFactory::CreateAVMetadataHelper(); - CHECK_AND_RETURN_RET_LOG(avMetadataHelper != nullptr, true, - "Failed to create AVMetadataHelper, ignore checking duration of moving photo video"); - - int32_t err = avMetadataHelper->SetSource(dataSource); - if (err != E_OK) { - MEDIA_ERR_LOG("SetSource failed for dataSource, err = %{public}d", err); - return false; - } - - unordered_map resultMap = avMetadataHelper->ResolveMetadata(); - if (resultMap.find(AV_KEY_DURATION) == resultMap.end()) { - MEDIA_ERR_LOG("AV_KEY_DURATION does not exist"); - return false; - } - - string durationStr = resultMap.at(AV_KEY_DURATION); - int32_t duration = atoi(durationStr.c_str()); - if (!MediaFileUtils::CheckMovingPhotoVideoDuration(duration)) { - MEDIA_ERR_LOG("Failed to check duration of moving photo video"); - return false; - } - return true; -} - -bool OH_MediaAssetChangeRequest::CheckChangeOperations() +bool MediaAssetChangeRequestImpl::CheckChangeOperations() { CHECK_AND_RETURN_RET_LOG(assetChangeOperations_.size() != 0, false, "None request to apply"); @@ -345,7 +360,7 @@ bool OH_MediaAssetChangeRequest::CheckChangeOperations() return true; } -bool OH_MediaAssetChangeRequest::CheckMovingPhotoWriteOperation() +bool MediaAssetChangeRequestImpl::CheckMovingPhotoWriteOperation() { if (!Contains(AssetChangeOperation::ADD_RESOURCE)) { return true; @@ -363,7 +378,7 @@ bool OH_MediaAssetChangeRequest::CheckMovingPhotoWriteOperation() return addResourceTimes == 2 && isImageExist && isVideoExist; // must add resource 2 times with image and video } -bool OH_MediaAssetChangeRequest::ChangeOperationExecute(AssetChangeOperation option) +bool MediaAssetChangeRequestImpl::ChangeOperationExecute(AssetChangeOperation option) { bool ret = false; switch (option) { @@ -385,7 +400,7 @@ bool OH_MediaAssetChangeRequest::ChangeOperationExecute(AssetChangeOperation opt return ret; } -bool OH_MediaAssetChangeRequest::SubmitCacheExecute() +bool MediaAssetChangeRequestImpl::SubmitCacheExecute() { bool isCreation = IsCreation(); bool isSetEffectMode = IsSetEffectMode(); @@ -397,17 +412,15 @@ bool OH_MediaAssetChangeRequest::SubmitCacheExecute() return true; } -bool OH_MediaAssetChangeRequest::AddResourceExecute() +bool MediaAssetChangeRequestImpl::AddResourceExecute() { - unique_lock ulock(mutex_); + if (IsMovingPhoto() && movingPhotoVideoResourceMode_ != AddResourceMode::FILE_URI) { + MEDIA_ERR_LOG("not support edit moving photo with buffer"); + return false; + } if (!HasWritePermission()) { return WriteBySecurityComponent(); } - if (IsMovingPhoto() && HasAddResource(MediaLibrary_ResourceType::MEDIA_LIBRARY_VIDEO_RESOURCE) && - AddMovingPhotoVideoExecute()) { - MEDIA_ERR_LOG("Faild to write cache file for video of moving photo"); - return false; - } if (IsMovingPhoto() && HasAddResource(MediaLibrary_ResourceType::MEDIA_LIBRARY_VIDEO_RESOURCE) && !AddMovingPhotoVideoExecute()) { @@ -432,7 +445,7 @@ bool OH_MediaAssetChangeRequest::AddResourceExecute() return SubmitCacheExecute(); } -bool OH_MediaAssetChangeRequest::SaveCameraPhotoExecute() +bool MediaAssetChangeRequestImpl::SaveCameraPhotoExecute() { bool containsAddResource = find(assetChangeOperations_.begin(), assetChangeOperations_.end(), AssetChangeOperation::ADD_RESOURCE) != assetChangeOperations_.end(); @@ -466,7 +479,7 @@ bool OH_MediaAssetChangeRequest::SaveCameraPhotoExecute() return true; } -bool OH_MediaAssetChangeRequest::DiscardCameraPhotoExecute() +bool MediaAssetChangeRequestImpl::DiscardCameraPhotoExecute() { OHOS::DataShare::DataSharePredicates predicates; OHOS::DataShare::DataShareValuesBucket valuesBucket; @@ -486,14 +499,14 @@ bool OH_MediaAssetChangeRequest::DiscardCameraPhotoExecute() return true; } -bool OH_MediaAssetChangeRequest::HasWritePermission() +bool MediaAssetChangeRequestImpl::HasWritePermission() { AccessTokenID tokenCaller = OHOS::IPCSkeleton::GetSelfTokenID(); int result = AccessTokenKit::VerifyAccessToken(tokenCaller, PERM_WRITE_IMAGEVIDEO); return result == PermissionState::PERMISSION_GRANTED; } -bool OH_MediaAssetChangeRequest::WriteBySecurityComponent() +bool MediaAssetChangeRequestImpl::WriteBySecurityComponent() { bool isCreation = IsCreation(); int32_t ret = E_FAIL; @@ -511,7 +524,7 @@ bool OH_MediaAssetChangeRequest::WriteBySecurityComponent() return true; } -bool OH_MediaAssetChangeRequest::IsCreation() +bool MediaAssetChangeRequestImpl::IsCreation() { bool isCreateFromScratch = find(assetChangeOperations_.begin(), assetChangeOperations_.end(), AssetChangeOperation::CREATE_FROM_SCRATCH) != assetChangeOperations_.end(); @@ -520,7 +533,7 @@ bool OH_MediaAssetChangeRequest::IsCreation() return isCreateFromScratch || isCreateFromUri; } -int32_t OH_MediaAssetChangeRequest::CopyToMediaLibrary(bool isCreation, AddResourceMode mode) +int32_t MediaAssetChangeRequestImpl::CopyToMediaLibrary(bool isCreation, AddResourceMode mode) { auto fileAsset = mediaAsset_->GetFileAssetInstance(); CHECK_AND_RETURN_RET_LOG(fileAsset != nullptr, E_FAIL, "fileAsset is null"); @@ -548,7 +561,7 @@ int32_t OH_MediaAssetChangeRequest::CopyToMediaLibrary(bool isCreation, AddResou Uri uri(assetUri); OHOS::UniqueFd destFd(UserFileClient::OpenFile(uri, MEDIA_FILEMODE_WRITEONLY)); if (destFd.Get() < 0) { - MEDIA_ERR_LOG("Failed to open %{private}s with error: %{public}d", assetUri.c_str(), destFd.Get()); + MEDIA_ERR_LOG("Failed to open %{public}s with error: %{public}d", assetUri.c_str(), destFd.Get()); return destFd.Get(); } @@ -567,7 +580,7 @@ int32_t OH_MediaAssetChangeRequest::CopyToMediaLibrary(bool isCreation, AddResou return ret; } -int32_t OH_MediaAssetChangeRequest::CreateAssetBySecurityComponent(string& assetUri) +int32_t MediaAssetChangeRequestImpl::CreateAssetBySecurityComponent(string& assetUri) { bool isValid = false; string title = creationValuesBucket_.Get(PhotoColumn::MEDIA_TITLE, isValid); @@ -579,12 +592,12 @@ int32_t OH_MediaAssetChangeRequest::CreateAssetBySecurityComponent(string& asset creationValuesBucket_.valuesMap.erase(MEDIA_DATA_DB_NAME); string uri = PAH_CREATE_PHOTO_COMPONENT; - OHOS::Media::MediaFileUtils::UriAppendKeyValue(uri, API_VERSION, to_string(MEDIA_API_VERSION_V10)); + MediaFileUtils::UriAppendKeyValue(uri, API_VERSION, to_string(MEDIA_API_VERSION_V10)); Uri createAssetUri(uri); return UserFileClient::InsertExt(createAssetUri, creationValuesBucket_, assetUri); } -int32_t OH_MediaAssetChangeRequest::CopyMovingPhotoVideo(const string& assetUri) +int32_t MediaAssetChangeRequestImpl::CopyMovingPhotoVideo(const string& assetUri) { CHECK_AND_RETURN_RET_LOG(!assetUri.empty(), E_INVALID_URI, "Failed to check empty asset uri"); @@ -607,18 +620,18 @@ int32_t OH_MediaAssetChangeRequest::CopyMovingPhotoVideo(const string& assetUri) return ret; } -int32_t OH_MediaAssetChangeRequest::CopyFileToMediaLibrary(const OHOS::UniqueFd& destFd, bool isMovingPhotoVideo) +int32_t MediaAssetChangeRequestImpl::CopyFileToMediaLibrary(const OHOS::UniqueFd& destFd, bool isMovingPhotoVideo) { string srcRealPath = isMovingPhotoVideo ? movingPhotoVideoRealPath_ : realPath_; CHECK_AND_RETURN_RET_LOG(!srcRealPath.empty(), E_FAIL, "Failed to check real path of source"); string absFilePath; - CHECK_AND_RETURN_RET_LOG(OHOS::PathToRealPath(srcRealPath, absFilePath), E_FAIL, "Not real path %{private}s", + CHECK_AND_RETURN_RET_LOG(OHOS::PathToRealPath(srcRealPath, absFilePath), E_FAIL, "Not real path %{public}s", srcRealPath.c_str()); OHOS::UniqueFd srcFd(open(absFilePath.c_str(), O_RDONLY)); if (srcFd.Get() < 0) { - MEDIA_ERR_LOG("Failed to open %{private}s, errno=%{public}d", absFilePath.c_str(), errno); + MEDIA_ERR_LOG("Failed to open %{public}s, errno=%{public}d", absFilePath.c_str(), errno); return srcFd.Get(); } @@ -629,7 +642,8 @@ int32_t OH_MediaAssetChangeRequest::CopyFileToMediaLibrary(const OHOS::UniqueFd& return err; } -int32_t OH_MediaAssetChangeRequest::CopyDataBufferToMediaLibrary(const OHOS::UniqueFd& destFd, bool isMovingPhotoVideo) +int32_t MediaAssetChangeRequestImpl::CopyDataBufferToMediaLibrary(const OHOS::UniqueFd& destFd, + bool isMovingPhotoVideo) { size_t offset = 0; size_t length = isMovingPhotoVideo ? movingPhotoVideoBufferSize_ : dataBufferSize_; @@ -645,7 +659,7 @@ int32_t OH_MediaAssetChangeRequest::CopyDataBufferToMediaLibrary(const OHOS::Uni return E_OK; } -void OH_MediaAssetChangeRequest::SetNewFileAsset(int32_t id, const string& uri) +void MediaAssetChangeRequestImpl::SetNewFileAsset(int32_t id, const string& uri) { auto fileAsset = mediaAsset_->GetFileAssetInstance(); if (fileAsset == nullptr) { @@ -662,12 +676,12 @@ void OH_MediaAssetChangeRequest::SetNewFileAsset(int32_t id, const string& uri) fileAsset->SetTimePending(0); } -bool OH_MediaAssetChangeRequest::SendToCacheFile(const OHOS::UniqueFd& destFd, bool isMovingPhotoVideo) +bool MediaAssetChangeRequestImpl::SendToCacheFile(const OHOS::UniqueFd& destFd, bool isMovingPhotoVideo) { string realPath = isMovingPhotoVideo ? movingPhotoVideoRealPath_ : realPath_; string absFilePath; if (!OHOS::PathToRealPath(realPath, absFilePath)) { - MEDIA_ERR_LOG("Not real path %{private}s, errno=%{public}d", realPath.c_str(), errno); + MEDIA_ERR_LOG("Not real path %{public}s, errno=%{public}d", realPath.c_str(), errno); return false; } @@ -685,13 +699,13 @@ bool OH_MediaAssetChangeRequest::SendToCacheFile(const OHOS::UniqueFd& destFd, b return true; } -bool OH_MediaAssetChangeRequest::IsSetEffectMode() +bool MediaAssetChangeRequestImpl::IsSetEffectMode() { return find(assetChangeOperations_.begin(), assetChangeOperations_.end(), AssetChangeOperation::SET_MOVING_PHOTO_EFFECT_MODE) != assetChangeOperations_.end(); } -int32_t OH_MediaAssetChangeRequest::SubmitCache(bool isCreation, bool isSetEffectMode) +int32_t MediaAssetChangeRequestImpl::SubmitCache(bool isCreation, bool isSetEffectMode) { auto fileAsset = mediaAsset_->GetFileAssetInstance(); CHECK_AND_RETURN_RET_LOG(fileAsset != nullptr, E_FAIL, "fileAsset is null"); @@ -736,7 +750,7 @@ int32_t OH_MediaAssetChangeRequest::SubmitCache(bool isCreation, bool isSetEffec return ret; } -int32_t OH_MediaAssetChangeRequest::SendFile(const OHOS::UniqueFd& srcFd, const OHOS::UniqueFd& destFd) +int32_t MediaAssetChangeRequestImpl::SendFile(const OHOS::UniqueFd& srcFd, const OHOS::UniqueFd& destFd) { if (srcFd.Get() < 0 || destFd.Get() < 0) { MEDIA_ERR_LOG("Failed to check srcFd: %{public}d and destFd: %{public}d", srcFd.Get(), destFd.Get()); @@ -755,7 +769,7 @@ int32_t OH_MediaAssetChangeRequest::SendFile(const OHOS::UniqueFd& srcFd, const while (offset < fileSize) { ssize_t sent = sendfile(destFd.Get(), srcFd.Get(), &offset, fileSize - offset); if (sent < 0) { - MEDIA_ERR_LOG("Failed to sendfile with errno=%{public}d, srcFd=%{private}d, destFd=%{private}d", errno, + MEDIA_ERR_LOG("Failed to sendfile with errno=%{public}d, srcFd=%{public}d, destFd=%{public}d", errno, srcFd.Get(), destFd.Get()); return sent; } @@ -764,7 +778,7 @@ int32_t OH_MediaAssetChangeRequest::SendFile(const OHOS::UniqueFd& srcFd, const return E_OK; } -int32_t OH_MediaAssetChangeRequest::PutMediaAssetEditData(OHOS::DataShare::DataShareValuesBucket& valuesBucket) +int32_t MediaAssetChangeRequestImpl::PutMediaAssetEditData(OHOS::DataShare::DataShareValuesBucket& valuesBucket) { if (editData_ == nullptr) { return E_OK; @@ -785,14 +799,16 @@ int32_t OH_MediaAssetChangeRequest::PutMediaAssetEditData(OHOS::DataShare::DataS return E_OK; } -bool OH_MediaAssetChangeRequest::HasAddResource(MediaLibrary_ResourceType resourceType) +bool MediaAssetChangeRequestImpl::HasAddResource(MediaLibrary_ResourceType resourceType) { return find(addResourceTypes_.begin(), addResourceTypes_.end(), resourceType) != addResourceTypes_.end(); } -bool OH_MediaAssetChangeRequest::AddMovingPhotoVideoExecute() +bool MediaAssetChangeRequestImpl::AddMovingPhotoVideoExecute() { + CHECK_AND_RETURN_RET_LOG(movingPhotoVideoResourceMode_ == AddResourceMode::FILE_URI, false, + "not support edit moving photo with buffer"); int32_t cacheVideoFd = OpenWriteCacheHandler(true); if (cacheVideoFd < 0) { MEDIA_ERR_LOG("Failed to open cache moving photo video, err: %{public}d", cacheVideoFd); @@ -807,7 +823,7 @@ bool OH_MediaAssetChangeRequest::AddMovingPhotoVideoExecute() return true; } -bool OH_MediaAssetChangeRequest::AddResourceByMode(const OHOS::UniqueFd& uniqueFd, +bool MediaAssetChangeRequestImpl::AddResourceByMode(const OHOS::UniqueFd& uniqueFd, AddResourceMode mode, bool isMovingPhotoVideo) { bool isWriteSuccess = false; @@ -821,7 +837,7 @@ bool OH_MediaAssetChangeRequest::AddResourceByMode(const OHOS::UniqueFd& uniqueF return isWriteSuccess; } -bool OH_MediaAssetChangeRequest::WriteCacheByArrayBuffer(const OHOS::UniqueFd& destFd, bool isMovingPhotoVideo) +bool MediaAssetChangeRequestImpl::WriteCacheByArrayBuffer(const OHOS::UniqueFd& destFd, bool isMovingPhotoVideo) { size_t offset = 0; size_t length = isMovingPhotoVideo ? movingPhotoVideoBufferSize_ : dataBufferSize_; @@ -837,10 +853,10 @@ bool OH_MediaAssetChangeRequest::WriteCacheByArrayBuffer(const OHOS::UniqueFd& d return true; } -void OH_MediaAssetChangeRequest::DiscardHighQualityPhoto() +void MediaAssetChangeRequestImpl::DiscardHighQualityPhoto() { string uriStr = PAH_REMOVE_MSC_TASK; - OHOS::Media::MediaFileUtils::UriAppendKeyValue(uriStr, API_VERSION, to_string(MEDIA_API_VERSION_V10)); + MediaFileUtils::UriAppendKeyValue(uriStr, API_VERSION, to_string(MEDIA_API_VERSION_V10)); Uri uri(uriStr); OHOS::DataShare::DataSharePredicates predicates; int errCode = 0; @@ -849,41 +865,3 @@ void OH_MediaAssetChangeRequest::DiscardHighQualityPhoto() vector columns { to_string(fileAsset->GetId()) }; UserFileClient::Query(uri, predicates, columns, errCode); } - -int32_t MediaDataSource::ReadData(const shared_ptr& mem, uint32_t length) -{ - if (readPos_ >= size_) { - MEDIA_ERR_LOG("Failed to check read position"); - return SOURCE_ERROR_EOF; - } - - if (memcpy_s(mem->GetBase(), mem->GetSize(), (char*)buffer_ + readPos_, length) != E_OK) { - MEDIA_ERR_LOG("Failed to copy buffer to mem"); - return SOURCE_ERROR_IO; - } - readPos_ += static_cast(length); - return static_cast(length); -} - -int32_t MediaDataSource::ReadAt(const shared_ptr& mem, uint32_t length, int64_t pos) -{ - readPos_ = pos; - return ReadData(mem, length); -} - -int32_t MediaDataSource::ReadAt(int64_t pos, uint32_t length, const shared_ptr& mem) -{ - readPos_ = pos; - return ReadData(mem, length); -} - -int32_t MediaDataSource::ReadAt(uint32_t length, const shared_ptr& mem) -{ - return ReadData(mem, length); -} - -int32_t MediaDataSource::GetSize(int64_t& size) -{ - size = size_; - return E_OK; -} diff --git a/frameworks/native/c_api/media_asset_helper.cpp b/frameworks/native/c_api/media_asset_helper_impl.cpp similarity index 86% rename from frameworks/native/c_api/media_asset_helper.cpp rename to frameworks/native/c_api/media_asset_helper_impl.cpp index 18ac16ce463fa1f4ecabdbd2a5ed6a2505ea45a6..ca561c2501d779e63a385b0ced78fd922ff32233 100644 --- a/frameworks/native/c_api/media_asset_helper.cpp +++ b/frameworks/native/c_api/media_asset_helper_impl.cpp @@ -13,24 +13,32 @@ * limitations under the License. */ -#include "media_asset_helper.h" +#include "media_asset_helper_impl.h" + #include "media_file_utils.h" #include "media_log.h" #include "media_userfile_client.h" #include "media_column.h" #include "medialibrary_errno.h" #include "userfilemgr_uri.h" +#include "oh_media_asset.h" namespace OHOS { namespace Media { -MediaAssetHelper* MediaAssetHelper::GetInstance() +std::shared_ptr MediaAssetHelperFactory::CreateMediaAssetHelper() { - static MediaAssetHelper instance; - return &instance; + std::shared_ptr impl = std::make_shared(); + CHECK_AND_PRINT_LOG(impl != nullptr, "Failed to create MediaAssetHelperImpl instance."); + + return impl; } -OH_MediaAsset* MediaAssetHelper::GetMediaAsset(std::string uri, int32_t cameraShotType, std::string burstKey) +MediaAssetHelperImpl::MediaAssetHelperImpl() {} + +MediaAssetHelperImpl::~MediaAssetHelperImpl() {} + +OH_MediaAsset* MediaAssetHelperImpl::GetMediaAsset(std::string uri, int32_t cameraShotType, std::string burstKey) { std::shared_ptr fileAsset = std::make_shared(); CHECK_AND_RETURN_RET_LOG(fileAsset != nullptr, nullptr, "create file asset failed"); @@ -56,12 +64,13 @@ OH_MediaAsset* MediaAssetHelper::GetMediaAsset(std::string uri, int32_t cameraSh } InitFileAsset(fileAsset); - auto mediaAsset = new OH_MediaAsset(fileAsset); + auto mediaAssetObj = MediaAssetFactory::CreateMediaAsset(fileAsset); + auto mediaAsset = new OH_MediaAsset(mediaAssetObj); CHECK_AND_RETURN_RET_LOG(mediaAsset != nullptr, nullptr, "create media asset failed"); return mediaAsset; } -void MediaAssetHelper::InitFileAsset(std::shared_ptr fileAsset) +void MediaAssetHelperImpl::InitFileAsset(std::shared_ptr fileAsset) { auto resultSet = QueryFileAsset(fileAsset->GetId()); CHECK_AND_RETURN_LOG(resultSet != nullptr, "query resultSet is nullptr"); @@ -98,7 +107,7 @@ void MediaAssetHelper::InitFileAsset(std::shared_ptr fileAsset) return; } -std::shared_ptr MediaAssetHelper::QueryFileAsset(int32_t mediaId) +std::shared_ptr MediaAssetHelperImpl::QueryFileAsset(int32_t mediaId) { if (!UserFileClient::IsValid()) { UserFileClient::Init(); @@ -128,7 +137,7 @@ std::shared_ptr MediaAssetHelper::QueryFileAsset( return resultSet; } -void MediaAssetHelper::UpdateFileAsset(std::shared_ptr resultSet, +void MediaAssetHelperImpl::UpdateFileAsset(std::shared_ptr resultSet, std::shared_ptr fileAsset) { int indexPos = -1; diff --git a/frameworks/native/c_api/media_asset_impl.cpp b/frameworks/native/c_api/media_asset_impl.cpp index 70ce34adca16a4852052d9d58a708b0642d9c1d0..889ba96f882f57681443da276c55cb8c94d12fef 100644 --- a/frameworks/native/c_api/media_asset_impl.cpp +++ b/frameworks/native/c_api/media_asset_impl.cpp @@ -22,8 +22,10 @@ using namespace OHOS::Media; +const static int64_t MILLI_TO_SECOND = 1000; const static int32_t MAX_URI_LENGTH = 256; const static int32_t MAX_DISPLAY_NAME_LENGTH = MAX_URI_LENGTH + 6; +const static int32_t MAX_TITLE_LENGTH = 256; const std::unordered_map g_mediaTypeMapping = { {MediaType::MEDIA_TYPE_IMAGE, MediaLibrary_MediaType::MEDIA_LIBRARY_IMAGE}, @@ -33,18 +35,28 @@ const std::unordered_map g_mediaTypeMapping = const std::unordered_map g_photoSubTypeMapping = { {PhotoSubType::DEFAULT, MediaLibrary_MediaSubType::MEDIA_LIBRARY_DEFAULT}, {PhotoSubType::MOVING_PHOTO, MediaLibrary_MediaSubType::MEDIA_LIBRARY_MOVING_PHOTO}, - {PhotoSubType::SUBTYPE_END, MediaLibrary_MediaSubType::MEDIA_LIBRARY_BURST}, + {PhotoSubType::BURST, MediaLibrary_MediaSubType::MEDIA_LIBRARY_BURST}, }; -OH_MediaAsset::OH_MediaAsset(std::shared_ptr fileAsset) +std::shared_ptr MediaAssetFactory::CreateMediaAsset( + std::shared_ptr fileAsset) { - MEDIA_DEBUG_LOG("OH_MediaAsset Constructor is called."); + std::shared_ptr impl = std::make_shared(fileAsset); + CHECK_AND_PRINT_LOG(impl != nullptr, "Failed to create MediaAssetManagerImpl instance."); + + return impl; +} + +MediaAssetImpl::MediaAssetImpl(std::shared_ptr fileAsset) +{ + MEDIA_DEBUG_LOG("MediaAssetImpl Constructor is called."); fileAsset_ = fileAsset; uri_ = new char[MAX_URI_LENGTH]; displayName_ = new char[MAX_DISPLAY_NAME_LENGTH]; + title_ = new char[MAX_TITLE_LENGTH]; } -OH_MediaAsset::~OH_MediaAsset() +MediaAssetImpl::~MediaAssetImpl() { if (fileAsset_ != nullptr) { fileAsset_ = nullptr; @@ -59,9 +71,14 @@ OH_MediaAsset::~OH_MediaAsset() delete[] displayName_; displayName_ = nullptr; } + + if (title_ != nullptr) { + delete[] title_; + title_ = nullptr; + } } -MediaLibrary_ErrorCode OH_MediaAsset::GetUri(const char** uri) +MediaLibrary_ErrorCode MediaAssetImpl::GetUri(const char** uri) { if (uri_ == nullptr) { uri_ = new(std::nothrow) char[MAX_URI_LENGTH]; @@ -72,13 +89,37 @@ MediaLibrary_ErrorCode OH_MediaAsset::GetUri(const char** uri) int32_t uriLen = static_cast(fileUri.length()); int32_t len = uriLen < MAX_URI_LENGTH ? uriLen : MAX_URI_LENGTH - 1; strncpy_s(uri_, MAX_URI_LENGTH, fileUri.c_str(), len); - MEDIA_INFO_LOG("OH_MediaAsset::GetUri, uri: %{public}s, return uri: %{public}s", + MEDIA_INFO_LOG("MediaAssetImpl::GetUri, uri: %{public}s, return uri: %{public}s", fileUri.c_str(), uri_); *uri = uri_; return MEDIA_LIBRARY_OK; } -MediaLibrary_ErrorCode OH_MediaAsset::GetDisplayName(const char** displayName) +MediaLibrary_ErrorCode MediaAssetImpl::GetMediaType(MediaLibrary_MediaType* mediaType) +{ + MediaType type = fileAsset_->GetMediaType(); + MEDIA_INFO_LOG("GetMediaType type: %{public}d", static_cast(type)); + auto itr = g_mediaTypeMapping.find(type); + if (itr != g_mediaTypeMapping.end()) { + *mediaType = itr->second; + return MEDIA_LIBRARY_OK; + } + return MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR; +} + +MediaLibrary_ErrorCode MediaAssetImpl::GetMediaSubType(MediaLibrary_MediaSubType* mediaSubType) +{ + PhotoSubType subType = static_cast(fileAsset_->GetPhotoSubType()); + MEDIA_INFO_LOG("GetMediaSubType subType: %{public}d", static_cast(subType)); + auto itr = g_photoSubTypeMapping.find(subType); + if (itr != g_photoSubTypeMapping.end()) { + *mediaSubType = itr->second; + return MEDIA_LIBRARY_OK; + } + return MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR; +} + +MediaLibrary_ErrorCode MediaAssetImpl::GetDisplayName(const char** displayName) { if (displayName_ == nullptr) { displayName_ = new(std::nothrow) char[MAX_DISPLAY_NAME_LENGTH]; @@ -89,43 +130,95 @@ MediaLibrary_ErrorCode OH_MediaAsset::GetDisplayName(const char** displayName) int32_t displayNameLen = static_cast(display.length()); int32_t len = displayNameLen < MAX_DISPLAY_NAME_LENGTH ? displayNameLen : MAX_DISPLAY_NAME_LENGTH - 1; strncpy_s(displayName_, MAX_DISPLAY_NAME_LENGTH, display.c_str(), len); - MEDIA_INFO_LOG("OH_MediaAsset::GetDisplayName, display name: %{public}s, return display name: %{public}s", + MEDIA_INFO_LOG("MediaAssetImpl::GetDisplayName, display name: %{public}s, return display name: %{public}s", display.c_str(), displayName_); *displayName = displayName_; return MEDIA_LIBRARY_OK; } -MediaLibrary_ErrorCode OH_MediaAsset::GetSize(uint32_t* size) +MediaLibrary_ErrorCode MediaAssetImpl::GetSize(uint32_t* size) { *size = static_cast(fileAsset_->GetSize()); return MEDIA_LIBRARY_OK; } -MediaLibrary_ErrorCode OH_MediaAsset::GetDateModifiedMs(uint32_t* dateModifiedMs) +MediaLibrary_ErrorCode MediaAssetImpl::GetDateAdded(uint32_t* dateAdded) +{ + *dateAdded = static_cast(fileAsset_->GetDateAdded() / MILLI_TO_SECOND); + return MEDIA_LIBRARY_OK; +} + +MediaLibrary_ErrorCode MediaAssetImpl::GetDateModified(uint32_t* dateModified) +{ + *dateModified = static_cast(fileAsset_->GetDateModified() / MILLI_TO_SECOND); + return MEDIA_LIBRARY_OK; +} + +MediaLibrary_ErrorCode MediaAssetImpl::GetDateAddedMs(uint32_t* dateAddedMs) +{ + *dateAddedMs = static_cast(fileAsset_->GetDateModified()); + return MEDIA_LIBRARY_OK; +} + +MediaLibrary_ErrorCode MediaAssetImpl::GetDateModifiedMs(uint32_t* dateModifiedMs) { *dateModifiedMs = static_cast(fileAsset_->GetDateModified()); return MEDIA_LIBRARY_OK; } -std::shared_ptr OH_MediaAsset::GetFileAssetInstance() const +MediaLibrary_ErrorCode MediaAssetImpl::GetDateTaken(uint32_t* dateTaken) +{ + *dateTaken = static_cast(fileAsset_->GetDateTaken()); + return MEDIA_LIBRARY_OK; +} + +std::shared_ptr MediaAssetImpl::GetFileAssetInstance() const { return fileAsset_; } -MediaLibrary_ErrorCode OH_MediaAsset::GetWidth(uint32_t* width) +MediaLibrary_ErrorCode MediaAssetImpl::GetDuration(uint32_t* duration) +{ + *duration = static_cast(fileAsset_->GetDuration()); + return MEDIA_LIBRARY_OK; +} + +MediaLibrary_ErrorCode MediaAssetImpl::GetWidth(uint32_t* width) { *width = static_cast(fileAsset_->GetWidth()); return MEDIA_LIBRARY_OK; } -MediaLibrary_ErrorCode OH_MediaAsset::GetHeight(uint32_t* height) +MediaLibrary_ErrorCode MediaAssetImpl::GetHeight(uint32_t* height) { *height = static_cast(fileAsset_->GetHeight()); return MEDIA_LIBRARY_OK; } -MediaLibrary_ErrorCode OH_MediaAsset::GetOrientation(uint32_t* orientation) +MediaLibrary_ErrorCode MediaAssetImpl::GetOrientation(uint32_t* orientation) { *orientation = static_cast(fileAsset_->GetOrientation()); return MEDIA_LIBRARY_OK; } + +MediaLibrary_ErrorCode MediaAssetImpl::IsFavorite(uint32_t* favorite) +{ + *favorite = static_cast(fileAsset_->IsFavorite()); + return MEDIA_LIBRARY_OK; +} + +MediaLibrary_ErrorCode MediaAssetImpl::GetTitle(const char** title) +{ + if (title_ == nullptr) { + title_ = new(std::nothrow) char[MAX_TITLE_LENGTH]; + CHECK_AND_RETURN_RET_LOG(title_ != nullptr, MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR, "alloc memory failed!"); + } + + const std::string titleStr = fileAsset_->GetTitle(); + int32_t titleLen = static_cast(titleStr.length()); + int32_t len = titleLen < MAX_TITLE_LENGTH ? titleLen : MAX_TITLE_LENGTH - 1; + strncpy_s(title_, MAX_TITLE_LENGTH, titleStr.c_str(), len); + MEDIA_INFO_LOG("GetTitle, title: %{public}s, return title: %{public}s", titleStr.c_str(), title_); + *title = title_; + return MEDIA_LIBRARY_OK; +} diff --git a/frameworks/native/c_api/media_asset_manger_capi/media_asset_manager_capi.cpp b/frameworks/native/c_api/media_asset_manger_capi/media_asset_manager_capi.cpp index 28f525bb7c8050c7722431ad48a0c4994aee42be..4d5aeeee636d1a10513f84282c8de344750ebd5a 100644 --- a/frameworks/native/c_api/media_asset_manger_capi/media_asset_manager_capi.cpp +++ b/frameworks/native/c_api/media_asset_manger_capi/media_asset_manager_capi.cpp @@ -22,7 +22,6 @@ #include "media_asset_base_capi.h" #include "media_asset_data_handler_capi.h" #include "media_asset_magic.h" -#include "image_source_native_impl.h" using namespace OHOS::Media; @@ -125,4 +124,31 @@ MediaLibrary_ErrorCode OH_MediaAssetManager_RequestImage(OH_MediaAssetManager* m NativeRequestOptions nativeRequestOptions; OH_MediaAssetManager_Convert(requestOptions, nativeRequestOptions); return managerObj->manager_->NativeRequestImageSource(mediaAsset, nativeRequestOptions, requestId, callback); +} + +MediaLibrary_ErrorCode OH_MediaAssetManager_RequestMovingPhoto(OH_MediaAssetManager* manager, OH_MediaAsset* mediaAsset, + MediaLibrary_RequestOptions requestOptions, MediaLibrary_RequestId* requestId, + OH_MediaLibrary_OnMovingPhotoDataPrepared callback) +{ + CHECK_AND_RETURN_RET_LOG(manager != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "input manager is nullptr!"); + struct MediaAssetMangerObject *managerObj = reinterpret_cast(manager); + CHECK_AND_RETURN_RET_LOG(managerObj != nullptr, MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR, "managerObj is null"); + CHECK_AND_RETURN_RET_LOG(managerObj->manager_ != nullptr, MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, + "manager_ is null"); + CHECK_AND_RETURN_RET_LOG(mediaAsset != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "mediaAsset is nullptr!"); + CHECK_AND_RETURN_RET_LOG(requestId != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "requestId is nullptr!"); + CHECK_AND_RETURN_RET_LOG(callback != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "callback is nullptr!"); + + NativeRequestOptions nativeRequestOptions; + OH_MediaAssetManager_Convert(requestOptions, nativeRequestOptions); + return managerObj->manager_->NativeRequestMovingPhoto(mediaAsset, nativeRequestOptions, requestId, callback); +} + +MediaLibrary_ErrorCode OH_MediaAssetManager_Release(OH_MediaAssetManager* manager) +{ + CHECK_AND_RETURN_RET_LOG(manager != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "input manager is nullptr!"); + + delete manager; + manager = nullptr; + return MEDIA_LIBRARY_OK; } \ No newline at end of file diff --git a/frameworks/native/c_api/moving_photo_capi/moving_photo_capi.cpp b/frameworks/native/c_api/moving_photo_capi/moving_photo_capi.cpp new file mode 100644 index 0000000000000000000000000000000000000000..077f9edbc766a8e439195b4a0fff9eb37a924df2 --- /dev/null +++ b/frameworks/native/c_api/moving_photo_capi/moving_photo_capi.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "moving_photo_capi.h" + +#include "oh_moving_photo.h" +#include "media_log.h" + +MediaLibrary_ErrorCode OH_MovingPhoto_GetUri(OH_MovingPhoto* movingPhoto, const char** uri) +{ + CHECK_AND_RETURN_RET_LOG(movingPhoto != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "movingPhoto is nullptr!"); + CHECK_AND_RETURN_RET_LOG(movingPhoto->movingPhoto_ != nullptr, + MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "movingPhoto_ is nullptr!"); + CHECK_AND_RETURN_RET_LOG(uri != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "uri is nullptr!"); + + return movingPhoto->movingPhoto_->GetUri(uri); +} + +MediaLibrary_ErrorCode OH_MovingPhoto_RequestContentWithUris(OH_MovingPhoto* movingPhoto, char* imageUri, + char* videoUri) +{ + CHECK_AND_RETURN_RET_LOG(movingPhoto != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "movingPhoto is nullptr!"); + CHECK_AND_RETURN_RET_LOG(movingPhoto->movingPhoto_ != nullptr, + MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "movingPhoto_ is nullptr!"); + CHECK_AND_RETURN_RET_LOG(imageUri != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "imageUri is nullptr!"); + CHECK_AND_RETURN_RET_LOG(videoUri != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "videoUri is nullptr!"); + + return movingPhoto->movingPhoto_->RequestContentWithUris(imageUri, videoUri); +} + +MediaLibrary_ErrorCode OH_MovingPhoto_RequestContentWithUri(OH_MovingPhoto* movingPhoto, + MediaLibrary_ResourceType resourceType, char* uri) +{ + CHECK_AND_RETURN_RET_LOG(movingPhoto != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "movingPhoto is nullptr!"); + CHECK_AND_RETURN_RET_LOG(movingPhoto->movingPhoto_ != nullptr, + MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "movingPhoto_ is nullptr!"); + CHECK_AND_RETURN_RET_LOG(uri != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "uri is nullptr!"); + + return movingPhoto->movingPhoto_->RequestContentWithUri(resourceType, uri); +} + +MediaLibrary_ErrorCode OH_MovingPhoto_RequestContentWithBuffer(OH_MovingPhoto* movingPhoto, + MediaLibrary_ResourceType resourceType, const uint8_t** buffer, uint32_t* size) +{ + CHECK_AND_RETURN_RET_LOG(movingPhoto != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "movingPhoto is nullptr!"); + CHECK_AND_RETURN_RET_LOG(movingPhoto->movingPhoto_ != nullptr, + MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "movingPhoto_ is nullptr!"); + CHECK_AND_RETURN_RET_LOG(buffer != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "buffer is nullptr!"); + CHECK_AND_RETURN_RET_LOG(size != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "size is nullptr!"); + + return movingPhoto->movingPhoto_->RequestContentWithBuffer(resourceType, buffer, size); +} + +MediaLibrary_ErrorCode OH_MovingPhoto_Release(OH_MovingPhoto* movingPhoto) +{ + CHECK_AND_RETURN_RET_LOG(movingPhoto != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "movingPhoto is nullptr!"); + + delete movingPhoto; + movingPhoto = nullptr; + return MEDIA_LIBRARY_OK; +} \ No newline at end of file diff --git a/frameworks/native/c_api/moving_photo_impl.cpp b/frameworks/native/c_api/moving_photo_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..858758a28a26c82a0005f71caca05ed6d3ba9f34 --- /dev/null +++ b/frameworks/native/c_api/moving_photo_impl.cpp @@ -0,0 +1,311 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "moving_photo_impl.h" +#include "media_file_utils.h" +#include "media_log.h" +#include "unique_fd.h" +#include "userfilemgr_uri.h" +#include "file_uri.h" +#include "medialibrary_db_const.h" +#include "medialibrary_errno.h" +#include "media_userfile_client.h" + +using namespace OHOS::Media; +using UniqueFd = OHOS::UniqueFd; +using Uri = OHOS::Uri; + +std::shared_ptr MovingPhotoFactory::CreateMovingPhoto(const std::string& uri) +{ + std::shared_ptr impl = std::make_shared(uri); + CHECK_AND_PRINT_LOG(impl != nullptr, "Failed to create MovingPhotoImpl instance."); + + return impl; +} + +MovingPhotoImpl::MovingPhotoImpl(const std::string& imageUri) : imageUri_(imageUri) +{ + +} + +MovingPhotoImpl::~MovingPhotoImpl() +{ + if (arrayBufferData_ != nullptr) { + free(arrayBufferData_); + arrayBufferData_ = nullptr; + } +} + +MediaLibrary_ErrorCode MovingPhotoImpl::GetUri(const char** uri) +{ + *uri = imageUri_.c_str(); + MEDIA_INFO_LOG("Moving photo uri = %{public}s", imageUri_.c_str()); + return MEDIA_LIBRARY_OK; +} + +MediaLibrary_ErrorCode MovingPhotoImpl::RequestContentWithUris(char* imageUri, char* videoUri) +{ + destImageUri_ = imageUri; + destVideoUri_ = videoUri; + MEDIA_DEBUG_LOG("Request content imageUri = %{public}s, video = %{public}s", imageUri, videoUri); + int32_t ret = RequestContentToSandbox(); + CHECK_AND_RETURN_RET_LOG(ret == E_OK, MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "RequestContentToSandbox failed"); + + return MEDIA_LIBRARY_OK; +} + +MediaLibrary_ErrorCode MovingPhotoImpl::RequestContentWithUri(MediaLibrary_ResourceType resourceType, char* uri) +{ + resourceType_ = resourceType; + if (resourceType == MEDIA_LIBRARY_IMAGE_RESOURCE) { + destImageUri_ = uri; + MEDIA_DEBUG_LOG("Request content with uri destImageUri_ = %{public}s", destImageUri_); + } else if (resourceType == MEDIA_LIBRARY_VIDEO_RESOURCE) { + destVideoUri_ = uri; + MEDIA_DEBUG_LOG("Request content with uri destVideoUri_ = %{public}s", destVideoUri_); + } else { + MEDIA_ERR_LOG("Request content with uri, invalid resourceType"); + return MEDIA_LIBRARY_PARAMETER_ERROR; + } + int32_t ret = RequestContentToSandbox(); + CHECK_AND_RETURN_RET_LOG(ret == E_OK, MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "RequestContentToSandbox failed"); + + return MEDIA_LIBRARY_OK; +} + +MediaLibrary_ErrorCode MovingPhotoImpl::RequestContentWithBuffer(MediaLibrary_ResourceType resourceType, + const uint8_t** buffer, uint32_t* size) +{ + resourceType_ = resourceType; + int32_t ret = RequestContentToArrayBuffer(); + CHECK_AND_RETURN_RET_LOG(ret == E_OK, MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "RequestContentToArrayBuffer failed"); + + if (arrayBufferLength_ <= 0) { + MEDIA_ERR_LOG("arrayBufferLength equals 0,ivalid buffer length"); + return MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED; + } + + *buffer = reinterpret_cast(arrayBufferData_); + *size = arrayBufferLength_; + MEDIA_INFO_LOG("Request content buffer size = %{public}zu", arrayBufferLength_); + return MEDIA_LIBRARY_OK; +} + +int32_t MovingPhotoImpl::RequestContentToSandbox() +{ + std::string movingPhotoUri = imageUri_; + if (sourceMode_ == SourceMode::ORIGINAL_MODE) { + MediaFileUtils::UriAppendKeyValue(movingPhotoUri, MEDIA_OPERN_KEYWORD, SOURCE_REQUEST); + } + + if (destImageUri_ && sizeof(destImageUri_) > 0) { + MEDIA_DEBUG_LOG("Sandbox image movingPhotoUri = %{public}s, destImageUri_ = %{public}s", + movingPhotoUri.c_str(), destImageUri_); + int32_t imageFd = OpenReadOnlyFile(movingPhotoUri, true); + CHECK_AND_RETURN_RET_LOG(HandleFd(imageFd), imageFd, "Open source image file failed"); + std::string imageUri(destImageUri_); + int32_t ret = WriteToSandboxUri(imageFd, imageUri); + CHECK_AND_RETURN_RET_LOG(ret == E_OK, ret, "Write image to sandbox failed"); + } + if (destVideoUri_ && strlen(destVideoUri_) > 0) { + MEDIA_DEBUG_LOG("Sandbox video movingPhotoUri = %{public}s, destVideoUri_ = %{public}s", + movingPhotoUri.c_str(), destVideoUri_); + int32_t videoFd = OpenReadOnlyFile(movingPhotoUri, false); + CHECK_AND_RETURN_RET_LOG(HandleFd(videoFd), videoFd, "Open source video file failed"); + std::string videoUri(destVideoUri_); + int32_t ret = WriteToSandboxUri(videoFd, videoUri); + CHECK_AND_RETURN_RET_LOG(ret == E_OK, ret, "Write video to sandbox failed"); + } + MEDIA_INFO_LOG("Request content to sandbox done"); + return E_OK; +} + +int32_t MovingPhotoImpl::WriteToSandboxUri(int32_t srcFd, std::string& sandboxUri) +{ + UniqueFd srcUniqueFd(srcFd); + OHOS::AppFileService::ModuleFileUri::FileUri fileUri(sandboxUri); + std::string destPath = fileUri.GetRealPath(); + MEDIA_INFO_LOG("Dest real path = %{public}s", destPath.c_str()); + if (!MediaFileUtils::IsFileExists(destPath) && !MediaFileUtils::CreateFile(destPath)) { + MEDIA_ERR_LOG("Create empty dest file in sandbox failed, path:%{public}s", destPath.c_str()); + return E_HAS_FS_ERROR; + } + + int32_t destFd = MediaFileUtils::OpenFile(destPath, MEDIA_FILEMODE_READWRITE); + if (destFd < 0) { + MEDIA_ERR_LOG("Open dest file failed, error: %{public}d", errno); + return E_HAS_FS_ERROR; + } + UniqueFd destUniqueFd(destFd); + + if (ftruncate(destUniqueFd.Get(), 0) == -1) { + MEDIA_ERR_LOG("Truncate old file in sandbox failed, error:%{public}d", errno); + return E_HAS_FS_ERROR; + } + return CopyFileFromMediaLibrary(srcUniqueFd.Get(), destUniqueFd.Get()); +} + +int32_t MovingPhotoImpl::CopyFileFromMediaLibrary(int32_t srcFd, int32_t destFd) +{ + constexpr size_t bufferSize = 4096; + char buffer[bufferSize]; + ssize_t bytesRead; + ssize_t bytesWritten; + while ((bytesRead = read(srcFd, buffer, bufferSize)) > 0) { + bytesWritten = write(destFd, buffer, bytesRead); + if (bytesWritten != bytesRead) { + MEDIA_ERR_LOG("Failed to copy file from srcFd=%{public}d to destFd=%{public}d, errno=%{public}d", + srcFd, destFd, errno); + return E_HAS_FS_ERROR; + } + } + + if (bytesRead < 0) { + MEDIA_ERR_LOG("Failed to read from srcFd=%{public}d, errno=%{public}d", srcFd, errno); + return E_HAS_FS_ERROR; + } + MEDIA_INFO_LOG("Copy file from media library done"); + return E_OK; +} + +int32_t MovingPhotoImpl::OpenReadOnlyFile(const std::string& uri, bool isReadImage) +{ + CHECK_AND_RETURN_RET_LOG(!uri.empty(), E_ERR, "Failed to open read only file, uri is empty"); + + std::string curUri = uri; + bool isMediaLibUri = MediaFileUtils::IsMediaLibraryUri(uri); + MEDIA_DEBUG_LOG("isMediaLibUri = %{public}d, isReadImage = %{public}d", isMediaLibUri, isReadImage); + if (!isMediaLibUri) { + std::vector uris; + if (!MediaFileUtils::SplitMovingPhotoUri(uri, uris)) { + MEDIA_ERR_LOG("Failed to open read only file, split moving photo failed"); + return -1; + } + curUri = uris[isReadImage ? MOVING_PHOTO_IMAGE_POS : MOVING_PHOTO_VIDEO_POS]; + } + return isReadImage ? OpenReadOnlyImage(curUri, isMediaLibUri) : OpenReadOnlyVideo(curUri, isMediaLibUri); +} + +int32_t MovingPhotoImpl::OpenReadOnlyImage(const std::string& imageUri, bool isMediaLibUri) +{ + if (isMediaLibUri) { + Uri uri(imageUri); + return UserFileClient::OpenFile(uri, MEDIA_FILEMODE_READONLY); + } + OHOS::AppFileService::ModuleFileUri::FileUri fileUri(imageUri); + std::string realPath = fileUri.GetRealPath(); + int32_t fd = open(realPath.c_str(), O_RDONLY); + CHECK_AND_RETURN_RET_LOG(fd >= 0, E_ERR, "Failed to open read only image file"); + + return fd; +} + +bool MovingPhotoImpl::HandleFd(int32_t& fd) +{ + if (fd == E_ERR) { + fd = E_HAS_FS_ERROR; + return false; + } else if (fd < 0) { + MEDIA_ERR_LOG("Open failed due to OpenFile failure, error: %{public}d", fd); + return false; + } + return true; +} + +int32_t MovingPhotoImpl::OpenReadOnlyVideo(const std::string& videoUri, bool isMediaLibUri) +{ + if (isMediaLibUri) { + std::string openVideoUri = videoUri; + MediaFileUtils::UriAppendKeyValue(openVideoUri, MEDIA_MOVING_PHOTO_OPRN_KEYWORD, + OPEN_MOVING_PHOTO_VIDEO); + Uri uri(openVideoUri); + return UserFileClient::OpenFile(uri, MEDIA_FILEMODE_READONLY); + } + OHOS::AppFileService::ModuleFileUri::FileUri fileUri(videoUri); + std::string realPath = fileUri.GetRealPath(); + int32_t fd = open(realPath.c_str(), O_RDONLY); + if (fd < 0) { + MEDIA_ERR_LOG("Failed to open read only video file"); + return -1; + } + return fd; +} + +int32_t MovingPhotoImpl::AcquireFdForArrayBuffer() +{ + int32_t fd = 0; + std::string movingPhotoUri = imageUri_; + switch (resourceType_) { + case MediaLibrary_ResourceType::MEDIA_LIBRARY_IMAGE_RESOURCE: { + fd = OpenReadOnlyFile(movingPhotoUri, true); + CHECK_AND_RETURN_RET_LOG(HandleFd(fd), fd, "Open source image file failed"); + return fd; + } + case MediaLibrary_ResourceType::MEDIA_LIBRARY_VIDEO_RESOURCE: { + fd = OpenReadOnlyFile(movingPhotoUri, false); + CHECK_AND_RETURN_RET_LOG(HandleFd(fd), fd, "Open source video file failed"); + return fd; + } + default: + MEDIA_ERR_LOG("Invalid resource type: %{public}d", static_cast(resourceType_)); + return -EINVAL; + } +} + +int32_t MovingPhotoImpl::RequestContentToArrayBuffer() +{ + int32_t fd = AcquireFdForArrayBuffer(); + CHECK_AND_RETURN_RET_LOG(fd >= 0, fd, "Acquire fd for arraybuffer failed"); + + UniqueFd uniqueFd(fd); + off_t fileLen = lseek(uniqueFd.Get(), 0, SEEK_END); + if (fileLen < 0) { + MEDIA_ERR_LOG("Failed to get file length, error: %{public}d", errno); + return E_HAS_FS_ERROR; + } + + off_t ret = lseek(uniqueFd.Get(), 0, SEEK_SET); + if (ret < 0) { + MEDIA_ERR_LOG("Failed to reset file offset, error: %{public}d", errno); + return E_HAS_FS_ERROR; + } + + if (fileLen > SIZE_MAX) { + MEDIA_ERR_LOG("File length is too large to fit in a size_t, length: %{public}zu", + static_cast(fileLen)); + return E_HAS_FS_ERROR; + } + + size_t fileSize = static_cast(fileLen); + arrayBufferData_ = malloc(fileSize); + if (!arrayBufferData_) { + MEDIA_ERR_LOG("Failed to malloc array buffer, moving photo uri is %{public}s, resource type is %{public}d", + imageUri_.c_str(), static_cast(resourceType_)); + return E_HAS_FS_ERROR; + } + arrayBufferLength_ = fileSize; + + size_t readBytes = static_cast(read(uniqueFd.Get(), arrayBufferData_, fileSize)); + if (readBytes != fileSize) { + MEDIA_ERR_LOG("read file failed, read bytes is %{public}zu, actual length is %{public}zu, error: %{public}d", + readBytes, fileSize, errno); + return E_HAS_FS_ERROR; + } + return E_OK; +} diff --git a/frameworks/native/media_library_asset_manager/BUILD.gn b/frameworks/native/media_library_asset_manager/BUILD.gn index abe9f962b2632ae6074b852313b1a5c2f8861b1e..fe0049c8d8dbc29007b5cbc30f693bffce065ae8 100644 --- a/frameworks/native/media_library_asset_manager/BUILD.gn +++ b/frameworks/native/media_library_asset_manager/BUILD.gn @@ -18,6 +18,11 @@ ohos_shared_library("media_library_asset_manager") { install_enable = true sources = [ + "${MEDIALIB_NATIVE_PATH}/c_api/media_asset_change_request_impl.cpp", + "${MEDIALIB_NATIVE_PATH}/c_api/media_asset_helper_impl.cpp", + "${MEDIALIB_NATIVE_PATH}/c_api/media_asset_impl.cpp", + "${MEDIALIB_NATIVE_PATH}/c_api/media_userfile_client.cpp", + "${MEDIALIB_NATIVE_PATH}/c_api/moving_photo_impl.cpp", "./src/media_asset_data_handler_capi.cpp", "./src/media_asset_manager_impl.cpp", ] @@ -27,7 +32,6 @@ ohos_shared_library("media_library_asset_manager") { "${MEDIALIB_INNERKITS_PATH}/media_library_helper/include", "${MEDIALIB_SERVICES_PATH}/media_thumbnail/include", "${MEDIALIB_INNERKITS_PATH}/medialibrary_data_extension/include", - "${MEDIALIB_INTERFACES_PATH}/inner_api/media_library_helper/include", "${MEDIALIB_INTERFACES_PATH}/kits/c", "${MEDIALIB_NATIVE_PATH}/c_api/common", ] @@ -36,15 +40,19 @@ ohos_shared_library("media_library_asset_manager") { "${MEDIALIB_INNERKITS_PATH}/media_library_helper:media_library", "${MEDIALIB_INNERKITS_PATH}/media_library_manager:media_library_manager", "${MEDIALIB_INNERKITS_PATH}/medialibrary_data_extension:medialibrary_data_extension", - "${MEDIALIB_NATIVE_PATH}/c_api:native_media_library_ndk", + "${MEDIALIB_UTILS_PATH}:permission_utils", ] external_deps = [ "ability_base:want", "ability_base:zuri", + "ability_runtime:app_context", + "access_token:libaccesstoken_sdk", "access_token:libnativetoken_shared", + "access_token:libprivacy_sdk", "access_token:libtokensetproc_shared", "app_file_service:fileuri_native", + "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", "data_share:datashare_common", @@ -57,6 +65,7 @@ ohos_shared_library("media_library_asset_manager") { "ipc:ipc_core", "napi:ace_napi", "relational_store:native_rdb", + "relational_store:rdb_data_share_adapter", "resource_management:librawfile", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/frameworks/native/media_library_asset_manager/src/media_asset_data_handler_capi.cpp b/frameworks/native/media_library_asset_manager/src/media_asset_data_handler_capi.cpp index 15e5a60801b6cd8352dff1a4bf2a8df5d4ec1644..d8bf00e54ccc8937abd3505c164b5fe6b5eeb587 100644 --- a/frameworks/native/media_library_asset_manager/src/media_asset_data_handler_capi.cpp +++ b/frameworks/native/media_library_asset_manager/src/media_asset_data_handler_capi.cpp @@ -42,6 +42,16 @@ CapiMediaAssetDataHandler::CapiMediaAssetDataHandler(OH_MediaLibrary_OnImageData sourceMode_ = sourceMode; } +CapiMediaAssetDataHandler::CapiMediaAssetDataHandler(OH_MediaLibrary_OnMovingPhotoDataPrepared photoDataHandler, + ReturnDataType dataType, const std::string &uri, const std::string &destUri, NativeSourceMode sourceMode) +{ + onRequestMovingPhotoDataPreparedHandler_ = photoDataHandler; + dataType_ = dataType; + requestUri_ = uri; + destUri_ = destUri; + sourceMode_ = sourceMode; +} + int32_t CapiMediaAssetDataHandler::GetPhotoQuality() { return photoQuality_; diff --git a/frameworks/native/media_library_asset_manager/src/media_asset_manager_impl.cpp b/frameworks/native/media_library_asset_manager/src/media_asset_manager_impl.cpp index bb895bcd6fba224285ccd9e6dec02d74b89a01a0..6813838a4b69c443193fbc080af0a9038b9f6525 100644 --- a/frameworks/native/media_library_asset_manager/src/media_asset_manager_impl.cpp +++ b/frameworks/native/media_library_asset_manager/src/media_asset_manager_impl.cpp @@ -34,7 +34,9 @@ #include "medialibrary_bundle_manager.h" #include "medialibrary_tracer.h" #include "file_asset.h" -#include "media_asset_impl.h" +#include "oh_media_asset.h" +#include "oh_moving_photo.h" +#include "moving_photo.h" #include "image_source_native.h" #include "media_userfile_client.h" @@ -223,6 +225,11 @@ static AssetHandler* InsertDataHandler(NativeNotifyMode notifyMode, asyncContext->onRequestImageDataPreparedHandler, asyncContext->returnDataType, asyncContext->requestUri, asyncContext->destUri, asyncContext->requestOptions.sourceMode); mediaAssetDataHandler->SetPhotoQuality(static_cast(asyncContext->photoQuality)); + } else if (asyncContext->returnDataType == ReturnDataType::TYPE_MOVING_PHOTO) { + mediaAssetDataHandler = make_shared( + asyncContext->onRequestMovingPhotoDataPreparedHandler, asyncContext->returnDataType, + asyncContext->requestUri, asyncContext->destUri, asyncContext->requestOptions.sourceMode); + mediaAssetDataHandler->SetPhotoQuality(static_cast(asyncContext->photoQuality)); } else { mediaAssetDataHandler = make_shared( asyncContext->onDataPreparedHandler, asyncContext->returnDataType, asyncContext->requestUri, @@ -329,6 +336,20 @@ bool MediaAssetManagerImpl::NotifyImageDataPrepared(AssetHandler *assetHandler) dataHandler->onRequestImageDataPreparedHandler_(status, requestId, quality, MEDIA_LIBRARY_COMPRESSED, imageSource); } + } else if (dataHandler->GetReturnDataType() == ReturnDataType::TYPE_MOVING_PHOTO) { + MediaLibrary_RequestId requestId; + strncpy_s(requestId.requestId, UUID_STR_LENGTH, assetHandler->requestId.c_str(), UUID_STR_LENGTH); + if (dataHandler->onRequestMovingPhotoDataPreparedHandler_ != nullptr) { + int32_t photoQuality = static_cast(MultiStagesCapturePhotoStatus::HIGH_QUALITY_STATUS); + MediaLibrary_MediaQuality quality = (dataHandler->GetPhotoQuality() == photoQuality) + ? MEDIA_LIBRARY_QUALITY_FULL + : MEDIA_LIBRARY_QUALITY_FAST; + auto movingPhotoImpl = MovingPhotoFactory::CreateMovingPhoto(assetHandler->requestUri); + auto movingPhoto = new OH_MovingPhoto(movingPhotoImpl); + auto status = movingPhoto != nullptr ? MEDIA_LIBRARY_OK : MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR; + dataHandler->onRequestMovingPhotoDataPreparedHandler_(status, requestId, quality, + MEDIA_LIBRARY_COMPRESSED, movingPhoto); + } } else { MEDIA_ERR_LOG("Return mode type invalid %{public}d", dataHandler->GetReturnDataType()); return false; @@ -474,7 +495,7 @@ MediaLibrary_ErrorCode MediaAssetManagerImpl::NativeRequestImageSource(OH_MediaA OH_MediaLibrary_OnImageDataPrepared callback) { MEDIA_INFO_LOG("MediaAssetManagerImpl::NativeRequestImageSource Called"); - std::shared_ptr fileAsset_ = mediaAsset->GetFileAssetInstance(); + std::shared_ptr fileAsset_ = mediaAsset->mediaAsset_->GetFileAssetInstance(); MediaLibraryTracer tracer; tracer.Start("NativeRequestImageSource"); @@ -520,6 +541,62 @@ MediaLibrary_ErrorCode MediaAssetManagerImpl::NativeRequestImageSource(OH_MediaA } } +MediaLibrary_ErrorCode MediaAssetManagerImpl::NativeRequestMovingPhoto(OH_MediaAsset* mediaAsset, + NativeRequestOptions requestOptions, MediaLibrary_RequestId* requestId, + OH_MediaLibrary_OnMovingPhotoDataPrepared callback) +{ + std::shared_ptr fileAsset_ = mediaAsset->mediaAsset_->GetFileAssetInstance(); + MediaLibraryTracer tracer; + tracer.Start("NativeRequestMovingPhoto"); + + std::unique_ptr asyncContext = std::make_unique(); + asyncContext->callingPkgName = MediaLibraryBundleManager::GetInstance()->GetClientBundleName(); + asyncContext->requestUri = fileAsset_->GetUri(); + asyncContext->fileId = fileAsset_->GetId(); + asyncContext->displayName = fileAsset_->GetDisplayName(); + asyncContext->requestOptions.deliveryMode = requestOptions.deliveryMode; + asyncContext->requestOptions.sourceMode = NativeSourceMode::EDITED_MODE; + asyncContext->returnDataType = ReturnDataType::TYPE_MOVING_PHOTO; + asyncContext->onRequestMovingPhotoDataPreparedHandler = callback; + + if (sDataShareHelper_ == nullptr) { + CreateDataHelper(STORAGE_MANAGER_MANAGER_ID); + CHECK_AND_RETURN_RET_LOG(sDataShareHelper_ == nullptr, MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR, + "sDataShareHelper_ is null"); + } + + if (asyncContext->requestUri.length() > MAX_URI_SIZE) { + MEDIA_ERR_LOG("Request image uri lens out of limit requestUri lens: %{public}zu", + asyncContext->requestUri.length()); + strncpy_s(requestId->requestId, UUID_STR_LENGTH, (ERROR_REQUEST_ID.c_str()), UUID_STR_LENGTH); + return MEDIA_LIBRARY_PARAMETER_ERROR; + } + + if (MediaFileUtils::GetMediaType(asyncContext->displayName) != MEDIA_TYPE_IMAGE) { + MEDIA_ERR_LOG("Request image file type invalid"); + strncpy_s(requestId->requestId, UUID_STR_LENGTH, (ERROR_REQUEST_ID.c_str()), UUID_STR_LENGTH); + return MEDIA_LIBRARY_PARAMETER_ERROR; + } + + bool isSuccess = false; + asyncContext->requestId = GenerateRequestId(); + isSuccess = OnHandleRequestImage(asyncContext); + string uri = LOG_MOVING_PHOTO; + Uri logMovingPhotoUri(uri); + DataShare::DataShareValuesBucket valuesBucket; + string result; + valuesBucket.Put("package_name", asyncContext->callingPkgName); + valuesBucket.Put("adapted", asyncContext->returnDataType == ReturnDataType::TYPE_MOVING_PHOTO); + UserFileClient::InsertExt(logMovingPhotoUri, valuesBucket, result); + if (isSuccess) { + strncpy_s(requestId->requestId, UUID_STR_LENGTH, (asyncContext->requestId.c_str()), UUID_STR_LENGTH); + return MEDIA_LIBRARY_OK; + } else { + strncpy_s(requestId->requestId, UUID_STR_LENGTH, (ERROR_REQUEST_ID.c_str()), UUID_STR_LENGTH); + return MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED; + } +} + OH_ImageSourceNative* MediaAssetManagerImpl::CreateImageSource(const std::string requestId, const std::string requestUri) { diff --git a/interfaces/inner_api/media_library_helper/include/media_asset.h b/interfaces/inner_api/media_library_helper/include/media_asset.h new file mode 100644 index 0000000000000000000000000000000000000000..e0c213b16c46433b4c17a0322e7eb63fde44c076 --- /dev/null +++ b/interfaces/inner_api/media_library_helper/include/media_asset.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_ASSET_H +#define INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_ASSET_H + +#include "file_asset.h" +#include "media_asset_base_capi.h" + +namespace OHOS { +namespace Media { + +class MediaAsset { +public: + virtual ~MediaAsset() = default; + +public: + virtual MediaLibrary_ErrorCode GetUri(const char** uri) = 0; + virtual MediaLibrary_ErrorCode GetMediaType(MediaLibrary_MediaType* mediaType) = 0; + virtual MediaLibrary_ErrorCode GetMediaSubType(MediaLibrary_MediaSubType* mediaSubType) = 0; + virtual MediaLibrary_ErrorCode GetDisplayName(const char** displayName) = 0; + virtual MediaLibrary_ErrorCode GetSize(uint32_t* size) = 0; + virtual MediaLibrary_ErrorCode GetDateAdded(uint32_t* dateAdded) = 0; + virtual MediaLibrary_ErrorCode GetDateModified(uint32_t* dateModified) = 0; + virtual MediaLibrary_ErrorCode GetDateAddedMs(uint32_t* dateAddedMs) = 0; + virtual MediaLibrary_ErrorCode GetDateModifiedMs(uint32_t* dateModifiedMs) = 0; + virtual MediaLibrary_ErrorCode GetDateTaken(uint32_t* dateTaken) = 0; + virtual MediaLibrary_ErrorCode GetDuration(uint32_t* duration) = 0; + virtual MediaLibrary_ErrorCode GetWidth(uint32_t* width) = 0; + virtual MediaLibrary_ErrorCode GetHeight(uint32_t* height) = 0; + virtual MediaLibrary_ErrorCode GetOrientation(uint32_t* orientation) = 0; + virtual MediaLibrary_ErrorCode IsFavorite(uint32_t* favorite) = 0; + virtual MediaLibrary_ErrorCode GetTitle(const char** title) = 0; + + virtual std::shared_ptr GetFileAssetInstance() const = 0; +}; + +class __attribute__((visibility("default"))) MediaAssetFactory { +public: + static std::shared_ptr CreateMediaAsset(std::shared_ptr fileAsset); +private: + MediaAssetFactory() = default; + ~MediaAssetFactory() = default; +}; + +} // Media +} // OHOS +#endif // INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_ASSET_H diff --git a/interfaces/inner_api/media_library_helper/include/media_asset_change_request.h b/interfaces/inner_api/media_library_helper/include/media_asset_change_request.h new file mode 100644 index 0000000000000000000000000000000000000000..ee9892adfe2fc0d0167b82664b99923c946151c3 --- /dev/null +++ b/interfaces/inner_api/media_library_helper/include/media_asset_change_request.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_ASSET_CHANGE_REQUEST_H +#define INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_ASSET_CHANGE_REQUEST_H + +#include "media_asset_base_capi.h" +#include "media_asset.h" +#include "media_asset_types.h" + +namespace OHOS { +namespace Media { + +class MediaAssetChangeRequest { +public: + virtual ~MediaAssetChangeRequest() = default; + +public: + virtual MediaLibrary_ErrorCode GetWriteCacheHandler(int32_t* fd) = 0; + virtual MediaLibrary_ErrorCode AddResourceWithUri(MediaLibrary_ResourceType resourceType, char* fileUri) = 0; + virtual MediaLibrary_ErrorCode AddResourceWithBuffer(MediaLibrary_ResourceType resourceType, uint8_t* buffer, + uint32_t length) = 0; + virtual MediaLibrary_ErrorCode SaveCameraPhoto(MediaLibrary_ImageFileType imageFileType) = 0; + virtual MediaLibrary_ErrorCode DiscardCameraPhoto() = 0; + virtual MediaLibrary_ErrorCode ApplyChanges() = 0; + + virtual void RecordChangeOperation(AssetChangeOperation changeOperation) = 0; +}; + +class __attribute__((visibility("default"))) MediaAssetChangeRequestFactory { +public: + static std::shared_ptr CreateMediaAssetChangeRequest( + std::shared_ptr mediaAsset); +private: + MediaAssetChangeRequestFactory() = default; + ~MediaAssetChangeRequestFactory() = default; +}; + +} // Media +} // OHOS +#endif // INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_ASSET_CHANGE_REQUEST_H diff --git a/interfaces/inner_api/media_library_helper/include/media_asset_change_request_impl.h b/interfaces/inner_api/media_library_helper/include/media_asset_change_request_impl.h index d0cc529771a608619f3e7358487c7246ee41c62a..dbbf5658968ed0ac7b3b40a7c7777a2b231cfe08 100644 --- a/interfaces/inner_api/media_library_helper/include/media_asset_change_request_impl.h +++ b/interfaces/inner_api/media_library_helper/include/media_asset_change_request_impl.h @@ -21,59 +21,44 @@ #include #include "media_asset_base_capi.h" +#include "nocopyable.h" #include "media_asset_types.h" #include "unique_fd.h" #include "media_asset_edit_data.h" -#include "values_bucket.h" #include "datashare_helper.h" -#include "media_data_source.h" +#include "media_asset.h" +#include "media_asset_change_request.h" constexpr int32_t YES = 1; constexpr int32_t NO = 0; -/* - * MediaDataSource - */ -class MediaDataSource : public OHOS::Media::IMediaDataSource { -public: - MediaDataSource(void* buffer, int64_t size) : buffer_(buffer), size_(size), readPos_(0) {} - ~MediaDataSource() = default; - - int32_t ReadAt(const std::shared_ptr& mem, uint32_t length, int64_t pos = -1) override; - int32_t ReadAt(int64_t pos, uint32_t length, const std::shared_ptr& mem) override; - int32_t ReadAt(uint32_t length, const std::shared_ptr& mem) override; - int32_t GetSize(int64_t& size) override; - -private: - int32_t ReadData(const std::shared_ptr& mem, uint32_t length); - - void* buffer_; - int64_t size_; - int64_t readPos_; -}; +namespace OHOS { +namespace Media { -struct OH_MediaAssetChangeRequest { +class MediaAssetChangeRequestImpl : public MediaAssetChangeRequest, public NoCopyable { public: - OH_MediaAssetChangeRequest(OH_MediaAsset* mediaAsset); - ~OH_MediaAssetChangeRequest(); + MediaAssetChangeRequestImpl(std::shared_ptr mediaAsset); + ~MediaAssetChangeRequestImpl(); + MediaLibrary_ErrorCode GetWriteCacheHandler(int32_t* fd) override; + MediaLibrary_ErrorCode AddResourceWithUri(MediaLibrary_ResourceType resourceType, char* fileUri) override; MediaLibrary_ErrorCode AddResourceWithBuffer(MediaLibrary_ResourceType resourceType, uint8_t* buffer, - uint32_t length); - MediaLibrary_ErrorCode SaveCameraPhoto(MediaLibrary_ImageFileType imageFileType); - MediaLibrary_ErrorCode DiscardCameraPhoto(); - MediaLibrary_ErrorCode ApplyChanges(); + uint32_t length) override; + MediaLibrary_ErrorCode SaveCameraPhoto(MediaLibrary_ImageFileType imageFileType) override; + MediaLibrary_ErrorCode DiscardCameraPhoto() override; + MediaLibrary_ErrorCode ApplyChanges() override; + + void RecordChangeOperation(AssetChangeOperation changeOperation) override; private: bool IsMovingPhoto(); bool CheckWriteOperation(MediaLibrary_ResourceType resourceType); bool CheckMovingPhotoResource(MediaLibrary_ResourceType resourceType); bool ContainsResource(MediaLibrary_ResourceType resourceType); - bool Contains(OHOS::Media::AssetChangeOperation changeOperation); + bool Contains(AssetChangeOperation changeOperation); int32_t OpenWriteCacheHandler(bool isMovingPhotoVideo = false); uint32_t FetchAddCacheFileId(); - void RecordChangeOperation(OHOS::Media::AssetChangeOperation changeOperation); - bool CheckMovingPhotoVideo(void* dataBuffer, size_t size); - bool ChangeOperationExecute(OHOS::Media::AssetChangeOperation option); + bool ChangeOperationExecute(AssetChangeOperation option); bool CheckChangeOperations(); bool CheckMovingPhotoWriteOperation(); bool SubmitCacheExecute(); @@ -83,7 +68,7 @@ private: bool HasWritePermission(); bool WriteBySecurityComponent(); bool IsCreation(); - int32_t CopyToMediaLibrary(bool isCreation, OHOS::Media::AddResourceMode mode); + int32_t CopyToMediaLibrary(bool isCreation, AddResourceMode mode); int32_t CreateAssetBySecurityComponent(std::string& assetUri); int32_t CopyMovingPhotoVideo(const std::string& assetUri); int32_t CopyFileToMediaLibrary(const OHOS::UniqueFd& destFd, bool isMovingPhotoVideo = false); @@ -96,29 +81,32 @@ private: int32_t PutMediaAssetEditData(OHOS::DataShare::DataShareValuesBucket& valuesBucket); bool HasAddResource(MediaLibrary_ResourceType resourceType); bool AddMovingPhotoVideoExecute(); - bool AddResourceByMode(const OHOS::UniqueFd& uniqueFd, OHOS::Media::AddResourceMode mode, + bool AddResourceByMode(const OHOS::UniqueFd& uniqueFd, AddResourceMode mode, bool isMovingPhotoVideo = false); bool WriteCacheByArrayBuffer(const OHOS::UniqueFd& destFd, bool isMovingPhotoVideo = false); void DiscardHighQualityPhoto(); private: - OH_MediaAsset* mediaAsset_; + std::shared_ptr mediaAsset_ = nullptr; std::vector addResourceTypes_; - std::vector assetChangeOperations_; + std::vector assetChangeOperations_; std::string cacheMovingPhotoVideoName_; std::string cacheFileName_; static std::atomic cacheFileId_; std::mutex mutex_; - uint8_t* dataBuffer_; - uint8_t* movingPhotoVideoDataBuffer_; + uint8_t* dataBuffer_ = nullptr; + uint8_t* movingPhotoVideoDataBuffer_ = nullptr; OHOS::DataShare::DataShareValuesBucket creationValuesBucket_; - OHOS::Media::AddResourceMode movingPhotoVideoResourceMode_; + AddResourceMode movingPhotoVideoResourceMode_; std::string realPath_; std::string movingPhotoVideoRealPath_; uint32_t movingPhotoVideoBufferSize_; uint32_t dataBufferSize_; - OHOS::Media::AddResourceMode addResourceMode_; - std::shared_ptr editData_ = nullptr; + AddResourceMode addResourceMode_; + std::shared_ptr editData_ = nullptr; }; +} +} + #endif // INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_ASSET_CHANGE_REQUEST_IMPL_H diff --git a/interfaces/inner_api/media_library_helper/include/media_asset_data_handler_capi.h b/interfaces/inner_api/media_library_helper/include/media_asset_data_handler_capi.h index 36e25604efc8fb2df51ea208b6f50da3260c5131..fa498b859cc84cd5c03589773e5e67682c002ddb 100644 --- a/interfaces/inner_api/media_library_helper/include/media_asset_data_handler_capi.h +++ b/interfaces/inner_api/media_library_helper/include/media_asset_data_handler_capi.h @@ -117,6 +117,7 @@ typedef struct NativeRequestOptions { enum class ReturnDataType { TYPE_IMAGE_SOURCE = 0, TYPE_ARRAY_BUFFER, + TYPE_MOVING_PHOTO, TYPE_TARGET_FILE, }; @@ -126,6 +127,8 @@ public: const std::string &destUri, NativeSourceMode sourceMode); CapiMediaAssetDataHandler(OH_MediaLibrary_OnImageDataPrepared imageDataHandler, ReturnDataType dataType, const std::string &uri, const std::string &destUri, NativeSourceMode sourceMode); + CapiMediaAssetDataHandler(OH_MediaLibrary_OnMovingPhotoDataPrepared photoDataHandler, ReturnDataType dataType, + const std::string &uri, const std::string &destUri, NativeSourceMode sourceMode); ~CapiMediaAssetDataHandler() = default; ReturnDataType GetReturnDataType(); std::string GetRequestUri(); @@ -135,6 +138,7 @@ public: NativeNotifyMode GetNotifyMode(); NativeOnDataPrepared onDataPreparedHandler_ = nullptr; OH_MediaLibrary_OnImageDataPrepared onRequestImageDataPreparedHandler_ = nullptr; + OH_MediaLibrary_OnMovingPhotoDataPrepared onRequestMovingPhotoDataPreparedHandler_ = nullptr; int32_t GetPhotoQuality(); void SetPhotoQuality(int32_t photoQuality); diff --git a/interfaces/inner_api/media_library_helper/include/media_asset_helper.h b/interfaces/inner_api/media_library_helper/include/media_asset_helper.h index 66089bc859b64f0b0cb89f71c2d9208c858cc5be..cf715aa9ef7ad8e8afdb598d1690b2204aa8a167 100644 --- a/interfaces/inner_api/media_library_helper/include/media_asset_helper.h +++ b/interfaces/inner_api/media_library_helper/include/media_asset_helper.h @@ -16,24 +16,24 @@ #ifndef INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_ASSET_HELPER_H #define INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_ASSET_HELPER_H -#include "media_photo_asset_proxy.h" -#include "media_asset_impl.h" +#include "media_asset_base_capi.h" namespace OHOS { namespace Media { class MediaAssetHelper { public: - MediaAssetHelper() = default; - ~MediaAssetHelper() = default; - static MediaAssetHelper* GetInstance(); - OH_MediaAsset* GetMediaAsset(std::string uri, int32_t cameraShotType, std::string burstKey); + virtual ~MediaAssetHelper() = default; + virtual OH_MediaAsset* GetMediaAsset(std::string uri, int32_t cameraShotType, std::string burstKey) = 0; +}; + +class __attribute__((visibility("default"))) MediaAssetHelperFactory { +public: + static std::shared_ptr CreateMediaAssetHelper(); private: - void InitFileAsset(std::shared_ptr fileAsset); - std::shared_ptr QueryFileAsset(int32_t mediaId); - void UpdateFileAsset(std::shared_ptr resultSet, - std::shared_ptr fileAsset); + MediaAssetHelperFactory() = default; + ~MediaAssetHelperFactory() = default; }; } // Media diff --git a/interfaces/inner_api/media_library_helper/include/media_asset_helper_impl.h b/interfaces/inner_api/media_library_helper/include/media_asset_helper_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..404def9f95c450bd3afe030002c51ffd47e6624b --- /dev/null +++ b/interfaces/inner_api/media_library_helper/include/media_asset_helper_impl.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_ASSET_HELPER_IMPL_H +#define INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_ASSET_HELPER_IMPL_H + +#include "nocopyable.h" +#include "media_asset_helper.h" +#include "media_photo_asset_proxy.h" + +namespace OHOS { +namespace Media { + +class MediaAssetHelperImpl : public MediaAssetHelper, public NoCopyable { +public: + MediaAssetHelperImpl(); + ~MediaAssetHelperImpl(); + + OH_MediaAsset* GetMediaAsset(std::string uri, int32_t cameraShotType, std::string burstKey) override; + +private: + void InitFileAsset(std::shared_ptr fileAsset); + std::shared_ptr QueryFileAsset(int32_t mediaId); + void UpdateFileAsset(std::shared_ptr resultSet, + std::shared_ptr fileAsset); +}; + +} // Media +} // OHOS +#endif // INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_ASSET_HELPER_IMPL_H \ No newline at end of file diff --git a/interfaces/inner_api/media_library_helper/include/media_asset_impl.h b/interfaces/inner_api/media_library_helper/include/media_asset_impl.h index fefec22b3528d955198ebca71db05bfcbec6e773..0309bab882fd7079e43ba348565c1c0476d5a2a5 100644 --- a/interfaces/inner_api/media_library_helper/include/media_asset_impl.h +++ b/interfaces/inner_api/media_library_helper/include/media_asset_impl.h @@ -16,28 +16,45 @@ #ifndef INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_ASSET_IMPL_H #define INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_ASSET_IMPL_H -#include "media_asset_base_capi.h" +#include "nocopyable.h" #include "file_asset.h" +#include "media_asset.h" -struct OH_MediaAsset { +namespace OHOS { +namespace Media { + +class MediaAssetImpl : public MediaAsset, public NoCopyable { public: - OH_MediaAsset(std::shared_ptr fileAsset); - ~OH_MediaAsset(); + MediaAssetImpl(std::shared_ptr fileAsset); + ~MediaAssetImpl(); - MediaLibrary_ErrorCode GetUri(const char** uri); - MediaLibrary_ErrorCode GetDisplayName(const char** displayName); - MediaLibrary_ErrorCode GetSize(uint32_t* size); - MediaLibrary_ErrorCode GetDateModifiedMs(uint32_t* dateModifiedMs); - MediaLibrary_ErrorCode GetWidth(uint32_t* width); - MediaLibrary_ErrorCode GetHeight(uint32_t* height); - MediaLibrary_ErrorCode GetOrientation(uint32_t* orientation); + MediaLibrary_ErrorCode GetUri(const char** uri) override; + MediaLibrary_ErrorCode GetMediaType(MediaLibrary_MediaType* mediaType) override; + MediaLibrary_ErrorCode GetMediaSubType(MediaLibrary_MediaSubType* mediaSubType) override; + MediaLibrary_ErrorCode GetDisplayName(const char** displayName) override; + MediaLibrary_ErrorCode GetSize(uint32_t* size) override; + MediaLibrary_ErrorCode GetDateAdded(uint32_t* dateAdded) override; + MediaLibrary_ErrorCode GetDateModified(uint32_t* dateModified) override; + MediaLibrary_ErrorCode GetDateAddedMs(uint32_t* dateAddedMs) override; + MediaLibrary_ErrorCode GetDateModifiedMs(uint32_t* dateModifiedMs) override; + MediaLibrary_ErrorCode GetDateTaken(uint32_t* dateTaken) override; + MediaLibrary_ErrorCode GetDuration(uint32_t* duration) override; + MediaLibrary_ErrorCode GetWidth(uint32_t* width) override; + MediaLibrary_ErrorCode GetHeight(uint32_t* height) override; + MediaLibrary_ErrorCode GetOrientation(uint32_t* orientation) override; + MediaLibrary_ErrorCode IsFavorite(uint32_t* favorite) override; + MediaLibrary_ErrorCode GetTitle(const char** title) override; - std::shared_ptr GetFileAssetInstance() const; + std::shared_ptr GetFileAssetInstance() const override; private: - std::shared_ptr fileAsset_ = nullptr; + std::shared_ptr fileAsset_ = nullptr; char* uri_; char* displayName_; + char* title_; }; +} +} + #endif // INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_ASSET_IMPL_H diff --git a/interfaces/inner_api/media_library_helper/include/media_asset_manager.h b/interfaces/inner_api/media_library_helper/include/media_asset_manager.h index a7d85563de6e4184e89c8277baf614bcce9d3da3..5a3f2753830127c5d3a8a3970a4d6914cf500f54 100644 --- a/interfaces/inner_api/media_library_helper/include/media_asset_manager.h +++ b/interfaces/inner_api/media_library_helper/include/media_asset_manager.h @@ -23,7 +23,6 @@ #include "datashare_helper.h" #include "media_asset_data_handler_capi.h" #include "media_asset_base_capi.h" -#include "image_source_native.h" namespace OHOS { namespace Media { @@ -48,6 +47,7 @@ struct RequestSourceAsyncContext { NativeRequestOptions requestOptions; ReturnDataType returnDataType; OH_MediaLibrary_OnImageDataPrepared onRequestImageDataPreparedHandler; + OH_MediaLibrary_OnMovingPhotoDataPrepared onRequestMovingPhotoDataPreparedHandler; MultiStagesCapturePhotoStatus photoQuality = MultiStagesCapturePhotoStatus::HIGH_QUALITY_STATUS; bool needsExtraInfo; }; @@ -92,6 +92,9 @@ public: virtual MediaLibrary_ErrorCode NativeRequestImageSource(OH_MediaAsset* mediaAsset, NativeRequestOptions requestOptions, MediaLibrary_RequestId* requestId, OH_MediaLibrary_OnImageDataPrepared callback) = 0; + virtual MediaLibrary_ErrorCode NativeRequestMovingPhoto(OH_MediaAsset* mediaAsset, + NativeRequestOptions requestOptions, MediaLibrary_RequestId* requestId, + OH_MediaLibrary_OnMovingPhotoDataPrepared callback) = 0; }; class __attribute__((visibility("default"))) MediaAssetManagerFactory { diff --git a/interfaces/inner_api/media_library_helper/include/media_asset_manager_impl.h b/interfaces/inner_api/media_library_helper/include/media_asset_manager_impl.h index cbecf347482178833a6b9cc5b035239b5881a4ca..8d7999eaec29ede4e0b634d7677062251dcf4cbd 100644 --- a/interfaces/inner_api/media_library_helper/include/media_asset_manager_impl.h +++ b/interfaces/inner_api/media_library_helper/include/media_asset_manager_impl.h @@ -39,6 +39,9 @@ public: MediaLibrary_ErrorCode NativeRequestImageSource(OH_MediaAsset* mediaAsset, NativeRequestOptions requestOptions, MediaLibrary_RequestId* requestId, OH_MediaLibrary_OnImageDataPrepared callback) override; + MediaLibrary_ErrorCode NativeRequestMovingPhoto(OH_MediaAsset* mediaAsset, + NativeRequestOptions requestOptions, MediaLibrary_RequestId* requestId, + OH_MediaLibrary_OnMovingPhotoDataPrepared callback) override; private: void CreateDataHelper(int32_t systemAbilityId); diff --git a/interfaces/inner_api/media_library_helper/include/moving_photo.h b/interfaces/inner_api/media_library_helper/include/moving_photo.h new file mode 100644 index 0000000000000000000000000000000000000000..ee1686351b47e6fac1e3de4452a79760da59dae6 --- /dev/null +++ b/interfaces/inner_api/media_library_helper/include/moving_photo.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INTERFACES_INNERKITS_NATIVE_INCLUDE_MOVING_PHOTO_H +#define INTERFACES_INNERKITS_NATIVE_INCLUDE_MOVING_PHOTO_H + +#include + +#include "media_asset_base_capi.h" + +namespace OHOS { +namespace Media { + +class MovingPhoto { +public: + virtual ~MovingPhoto() = default; + +public: + virtual MediaLibrary_ErrorCode GetUri(const char** uri) = 0; + virtual MediaLibrary_ErrorCode RequestContentWithUris(char* imageUri, char* videoUri) = 0; + virtual MediaLibrary_ErrorCode RequestContentWithUri(MediaLibrary_ResourceType resourceType, char* uri) = 0; + virtual MediaLibrary_ErrorCode RequestContentWithBuffer(MediaLibrary_ResourceType resourceType, + const uint8_t** buffer,uint32_t* size) = 0; +}; + +class __attribute__((visibility("default"))) MovingPhotoFactory { +public: + static std::shared_ptr CreateMovingPhoto(const std::string& uri); +private: + MovingPhotoFactory() = default; + ~MovingPhotoFactory() = default; +}; + +} // Media +} // OHOS +#endif // INTERFACES_INNERKITS_NATIVE_INCLUDE_MOVING_PHOTO_H diff --git a/interfaces/inner_api/media_library_helper/include/moving_photo_impl.h b/interfaces/inner_api/media_library_helper/include/moving_photo_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..6f4b4773c3a22b28f62f4e33a551ddd714444ef5 --- /dev/null +++ b/interfaces/inner_api/media_library_helper/include/moving_photo_impl.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NTERFACES_INNERKITS_NATIVE_INCLUDE_MOVING_PHOTO_IMPL_H +#define NTERFACES_INNERKITS_NATIVE_INCLUDE_MOVING_PHOTO_IMPL_H + +#include "nocopyable.h" +#include "moving_photo.h" + +namespace OHOS { +namespace Media { + +enum class SourceMode { + ORIGINAL_MODE = 0, + EDITED_MODE, +}; + +class MovingPhotoImpl : public MovingPhoto, public NoCopyable { +public: + MovingPhotoImpl(const std::string& imageUri); + ~MovingPhotoImpl(); + + MediaLibrary_ErrorCode GetUri(const char** uri) override; + MediaLibrary_ErrorCode RequestContentWithUris(char* imageUri, char* videoUri) override; + MediaLibrary_ErrorCode RequestContentWithUri(MediaLibrary_ResourceType resourceType, char* uri) override; + MediaLibrary_ErrorCode RequestContentWithBuffer(MediaLibrary_ResourceType resourceType, + const uint8_t** buffer,uint32_t* size) override; + +private: + int32_t RequestContentToSandbox(); + int32_t WriteToSandboxUri(int32_t srcFd, std::string& sandboxUri); + int32_t CopyFileFromMediaLibrary(int32_t srcFd, int32_t destFd); + int32_t OpenReadOnlyFile(const std::string& uri, bool isReadImage); + bool HandleFd(int32_t& fd); + int32_t OpenReadOnlyImage(const std::string& imageUri, bool isMediaLibUri); + int32_t RequestContentToArrayBuffer(); + int32_t AcquireFdForArrayBuffer(); + int32_t OpenReadOnlyVideo(const std::string& videoUri, bool isMediaLibUri); + +private: + std::string imageUri_; + char* destImageUri_ = nullptr; + char* destVideoUri_ = nullptr; + MediaLibrary_ResourceType resourceType_ = MEDIA_LIBRARY_IMAGE_RESOURCE; + void* arrayBufferData_ = nullptr; + size_t arrayBufferLength_ = 0; + SourceMode sourceMode_ = SourceMode::ORIGINAL_MODE; +}; + +} +} + +#endif // NTERFACES_INNERKITS_NATIVE_INCLUDE_MOVING_PHOTO_IMPL_H \ No newline at end of file diff --git a/interfaces/kits/c/BUILD.gn b/interfaces/kits/c/BUILD.gn index ceb3052bcd19b58811c8045cdc9f214a9263083e..cddab3e5038d6c5a6400fdc567bd7529b69ea221 100644 --- a/interfaces/kits/c/BUILD.gn +++ b/interfaces/kits/c/BUILD.gn @@ -19,8 +19,6 @@ config("media_capi_config") { "${MEDIALIB_INTERFACES_PATH}/inner_api/media_library_helper/include", "${MEDIALIB_INTERFACES_PATH}/kits/c", "${MEDIALIB_ROOT_PATH}/frameworks/native/c_api/common", - "${MEDIALIB_INNERKITS_PATH}/media_library_helper/include", - "${MEDIALIB_ROOT_PATH}/frameworks/utils/include", ] cflags = [ @@ -64,6 +62,7 @@ ohos_shared_library("native_media_asset_manager") { "${MEDIALIB_NATIVE_PATH}/c_api/media_access_helper_capi/media_access_helper_capi.cpp", "${MEDIALIB_NATIVE_PATH}/c_api/media_asset_capi/media_asset_capi.cpp", "${MEDIALIB_NATIVE_PATH}/c_api/media_asset_change_request_capi/media_asset_change_request_capi.cpp", + "${MEDIALIB_NATIVE_PATH}/c_api/moving_photo_capi/moving_photo_capi.cpp", "${MEDIALIB_ROOT_PATH}/frameworks/native/c_api/media_asset_manger_capi/media_asset_manager_capi.cpp", ] @@ -71,7 +70,6 @@ ohos_shared_library("native_media_asset_manager") { deps = [ "${MEDIALIB_INNERKITS_PATH}/media_library_helper:media_library", - "${MEDIALIB_NATIVE_PATH}/c_api:native_media_library_ndk", "${MEDIALIB_NATIVE_PATH}/media_library_asset_manager:media_library_asset_manager", ] @@ -82,15 +80,13 @@ ohos_shared_library("native_media_asset_manager") { "data_share:datashare_common", "data_share:datashare_consumer", "hilog:libhilog", - "image_framework:image_native", "image_framework:ohimage", "napi:ace_napi", - "player_framework:media_client", - "relational_store:native_rdb", "resource_management:librawfile", ] output_name = "media_asset_manager" output_extension = "so" + innerapi_tags = [ "ndk" ] subsystem_name = "multimedia" part_name = "media_library" } diff --git a/interfaces/kits/c/media_asset_base_capi.h b/interfaces/kits/c/media_asset_base_capi.h index 3b4373b959201577309b030f86dcc18e0833f99e..234f0e4feccc018c2885a7ee75f1e1c67ac26107 100644 --- a/interfaces/kits/c/media_asset_base_capi.h +++ b/interfaces/kits/c/media_asset_base_capi.h @@ -82,6 +82,15 @@ typedef struct OH_MediaAssetManager OH_MediaAssetManager; */ typedef struct OH_MediaAssetChangeRequest OH_MediaAssetChangeRequest; +/** + * @brief Define Moving Photo + * + * This structure provides the ability to obtain information about moving photo. + * + * @since 12 + */ +typedef struct OH_MovingPhoto OH_MovingPhoto; + /** * @brief Define Media Asset * @@ -285,6 +294,22 @@ typedef void (*OH_MediaLibrary_OnImageDataPrepared)(MediaLibrary_ErrorCode resul MediaLibrary_RequestId requestId, MediaLibrary_MediaQuality mediaQuality, MediaLibrary_MediaContentType type, OH_ImageSourceNative* imageSourceNative); +/** + * @brief Called when a requested source is prepared. + * + * This function is called when the requested source is prepared. + * + * @param result Results {@link MediaLibrary_ErrorCode} of the processing of the requested resources. + * @param requestId the {@link MediaLibrary_RequestId}. + * @param mediaQuality the {@link MediaLibrary_MediaQuality} of the requested source. + * @param type the {@link MediaLibrary_MediaContentType} of the requested source. + * @param movingPhoto the {@link OH_MovingPhoto} of the requested source. + * @since 12 + */ +typedef void (*OH_MediaLibrary_OnMovingPhotoDataPrepared)(MediaLibrary_ErrorCode result, + MediaLibrary_RequestId requestId, MediaLibrary_MediaQuality mediaQuality, MediaLibrary_MediaContentType type, + OH_MovingPhoto* movingPhoto); + #ifdef __cplusplus } #endif diff --git a/interfaces/kits/c/media_asset_capi.h b/interfaces/kits/c/media_asset_capi.h index ba286c81159a2aa0bda0b223b333cecdc71791ba..4017b0be8e7b9d99714d37d922714e2ca7a7ed19 100644 --- a/interfaces/kits/c/media_asset_capi.h +++ b/interfaces/kits/c/media_asset_capi.h @@ -56,9 +56,40 @@ extern "C" { * 3. Parameter verification failed. * {@link #MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR} if internal system error. * @since 12 -*/ + */ MediaLibrary_ErrorCode OH_MediaAsset_GetUri(OH_MediaAsset* mediaAsset, const char** uri); +/** + * @brief Get the media file type of the media asset. + * + * @param mediaAsset the {@link OH_MediaAsset} instance. + * @param mediaType the media file type of the media asset. + * @return {@link #MEDIA_LIBRARY_OK} if the method call succeeds. + * {@link #MEDIA_LIBRARY_PARAMETER_ERROR} Parameter error. Possible causes: + * 1. Mandatory parameters are left unspecified. + * 2. Incorrect parameter types. + * 3. Parameter verification failed. + * {@link #MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR} if internal system error. + * @since 12 + */ +MediaLibrary_ErrorCode OH_MediaAsset_GetMediaType(OH_MediaAsset* mediaAsset, MediaLibrary_MediaType* mediaType); + +/** + * @brief Get the subtype of the media asset. + * + * @param mediaAsset the {@link OH_MediaAsset} instance. + * @param mediaSubType the subtype of the media asset. + * @return {@link #MEDIA_LIBRARY_OK} if the method call succeeds. + * {@link #MEDIA_LIBRARY_PARAMETER_ERROR} Parameter error. Possible causes: + * 1. Mandatory parameters are left unspecified. + * 2. Incorrect parameter types. + * 3. Parameter verification failed. + * {@link #MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR} if internal system error. + * @since 12 + */ +MediaLibrary_ErrorCode OH_MediaAsset_GetMediaSubType(OH_MediaAsset* mediaAsset, + MediaLibrary_MediaSubType* mediaSubType); + /** * @brief Get the display name of the media asset. * @@ -71,7 +102,7 @@ MediaLibrary_ErrorCode OH_MediaAsset_GetUri(OH_MediaAsset* mediaAsset, const cha * 3. Parameter verification failed. * {@link #MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR} if internal system error. * @since 12 -*/ + */ MediaLibrary_ErrorCode OH_MediaAsset_GetDisplayName(OH_MediaAsset* mediaAsset, const char** displayName); /** @@ -86,9 +117,72 @@ MediaLibrary_ErrorCode OH_MediaAsset_GetDisplayName(OH_MediaAsset* mediaAsset, c * 3. Parameter verification failed. * {@link #MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR} if internal system error. * @since 12 -*/ + */ MediaLibrary_ErrorCode OH_MediaAsset_GetSize(OH_MediaAsset* mediaAsset, uint32_t* size); +/** + * @brief Get the date of asset creation. + * + * @param mediaAsset the {@link OH_MediaAsset} instance. + * @param dateAdded the creation date of the asset. + * The value is the number of seconds elapsed since the Epoch time (00:00:00 UTC on January 1, 1970). + * @return {@link #MEDIA_LIBRARY_OK} if the method call succeeds. + * {@link #MEDIA_LIBRARY_PARAMETER_ERROR} Parameter error. Possible causes: + * 1. Mandatory parameters are left unspecified. + * 2. Incorrect parameter types. + * 3. Parameter verification failed. + * {@link #MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR} if internal system error. + * @since 12 + */ +MediaLibrary_ErrorCode OH_MediaAsset_GetDateAdded(OH_MediaAsset* mediaAsset, uint32_t* dateAdded); + +/** + * @brief Get the modified date of the asset. + * + * @param mediaAsset the {@link OH_MediaAsset} instance. + * @param dateModified the modified date of the asset. + * The value is the number of seconds elapsed since the Epoch time. + * @return {@link #MEDIA_LIBRARY_OK} if the method call succeeds. + * {@link #MEDIA_LIBRARY_PARAMETER_ERROR} Parameter error. Possible causes: + * 1. Mandatory parameters are left unspecified. + * 2. Incorrect parameter types. + * 3. Parameter verification failed. + * {@link #MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR} if internal system error. + * @since 12 + */ +MediaLibrary_ErrorCode OH_MediaAsset_GetDateModified(OH_MediaAsset* mediaAsset, uint32_t* dateModified); + +/** + * @brief Get the date taken of the asset. + * + * @param mediaAsset the {@link OH_MediaAsset} instance. + * @param dateTaken the date taken of the asset. + * The value is the number of seconds elapsed since the Epoch time. + * @return {@link #MEDIA_LIBRARY_OK} if the method call succeeds. + * {@link #MEDIA_LIBRARY_PARAMETER_ERROR} Parameter error. Possible causes: + * 1. Mandatory parameters are left unspecified. + * 2. Incorrect parameter types. + * 3. Parameter verification failed. + * {@link #MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR} if internal system error. + * @since 12 + */ +MediaLibrary_ErrorCode OH_MediaAsset_GetDateTaken(OH_MediaAsset* mediaAsset, uint32_t* dateTaken); + +/** + * @brief Get the creation time of the asset in milliseconds. + * + * @param mediaAsset the {@link OH_MediaAsset} instance. + * @param dateAddedMs the creation time of the asset in milliseconds. + * @return {@link #MEDIA_LIBRARY_OK} if the method call succeeds. + * {@link #MEDIA_LIBRARY_PARAMETER_ERROR} Parameter error. Possible causes: + * 1. Mandatory parameters are left unspecified. + * 2. Incorrect parameter types. + * 3. Parameter verification failed. + * {@link #MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR} if internal system error. + * @since 12 + */ +MediaLibrary_ErrorCode OH_MediaAsset_GetDateAddedMs(OH_MediaAsset* mediaAsset, uint32_t* dateAddedMs); + /** * @brief Get the modified time of the asset in milliseconds. * @@ -101,9 +195,24 @@ MediaLibrary_ErrorCode OH_MediaAsset_GetSize(OH_MediaAsset* mediaAsset, uint32_t * 3. Parameter verification failed. * {@link #MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR} if internal system error. * @since 12 -*/ + */ MediaLibrary_ErrorCode OH_MediaAsset_GetDateModifiedMs(OH_MediaAsset* mediaAsset, uint32_t* dateModifiedMs); +/** + * @brief Get the duration of the media asset in milliseconds. + * + * @param mediaAsset the {@link OH_MediaAsset} instance. + * @param duration the duration of the media asset in milliseconds. + * @return {@link #MEDIA_LIBRARY_OK} if the method call succeeds. + * {@link #MEDIA_LIBRARY_PARAMETER_ERROR} Parameter error. Possible causes: + * 1. Mandatory parameters are left unspecified. + * 2. Incorrect parameter types. + * 3. Parameter verification failed. + * {@link #MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR} if internal system error. + * @since 12 + */ +MediaLibrary_ErrorCode OH_MediaAsset_GetDuration(OH_MediaAsset* mediaAsset, uint32_t* duration); + /** * @brief Get the image width(in pixels) of the media asset. * @@ -116,7 +225,7 @@ MediaLibrary_ErrorCode OH_MediaAsset_GetDateModifiedMs(OH_MediaAsset* mediaAsset * 3. Parameter verification failed. * {@link #MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR} if internal system error. * @since 12 -*/ + */ MediaLibrary_ErrorCode OH_MediaAsset_GetWidth(OH_MediaAsset* mediaAsset, uint32_t* width); /** @@ -131,7 +240,7 @@ MediaLibrary_ErrorCode OH_MediaAsset_GetWidth(OH_MediaAsset* mediaAsset, uint32_ * 3. Parameter verification failed. * {@link #MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR} if internal system error. * @since 12 -*/ + */ MediaLibrary_ErrorCode OH_MediaAsset_GetHeight(OH_MediaAsset* mediaAsset, uint32_t* height); /** @@ -145,9 +254,40 @@ MediaLibrary_ErrorCode OH_MediaAsset_GetHeight(OH_MediaAsset* mediaAsset, uint32 * 2. Incorrect parameter types. * 3. Parameter verification failed. * {@link #MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR} if internal system error. -*/ + * @since 12 + */ MediaLibrary_ErrorCode OH_MediaAsset_GetOrientation(OH_MediaAsset* mediaAsset, uint32_t* orientation); +/** + * @brief Get the favorite state of the asset. + * + * @param mediaAsset the {@link OH_MediaAsset} instance. + * @param favorite the favorite state of the media asset. + * @return {@link #MEDIA_LIBRARY_OK} if the method call succeeds. + * {@link #MEDIA_LIBRARY_PARAMETER_ERROR} Parameter error. Possible causes: + * 1. Mandatory parameters are left unspecified. + * 2. Incorrect parameter types. + * 3. Parameter verification failed. + * {@link #MEDIA_LIBRARY_INVALID_PHOTO_KEY} if member is not a valid PhotoKey. + * @since 12 + */ +MediaLibrary_ErrorCode OH_MediaAsset_IsFavorite(OH_MediaAsset* mediaAsset, uint32_t* favorite); + +/** + * @brief Get the title of the media asset. + * + * @param mediaAsset the {@link OH_MediaAsset} instance. + * @param title the title of the media asset. + * @return {@link #MEDIA_LIBRARY_OK} if the method call succeeds. + * {@link #MEDIA_LIBRARY_PARAMETER_ERROR} Parameter error. Possible causes: + * 1. Mandatory parameters are left unspecified. + * 2. Incorrect parameter types. + * 3. Parameter verification failed. + * {@link #MEDIA_LIBRARY_INVALID_PHOTO_KEY} if member is not a valid PhotoKey + * @since 12 + */ +MediaLibrary_ErrorCode OH_MediaAsset_GetTitle(OH_MediaAsset* mediaAsset, const char** title); + /** * @brief Release the media asset * @@ -158,7 +298,7 @@ MediaLibrary_ErrorCode OH_MediaAsset_GetOrientation(OH_MediaAsset* mediaAsset, u * 2. Incorrect parameter types. * 3. Parameter verification failed. * @since 12 -*/ + */ MediaLibrary_ErrorCode OH_MediaAsset_Release(OH_MediaAsset* mediaAsset); #ifdef __cplusplus diff --git a/interfaces/kits/c/media_asset_change_request_capi.h b/interfaces/kits/c/media_asset_change_request_capi.h index d4bb6a77270ecf0f5a8173130f418af337c841ac..26388bc66744d59580dacc76f26d27850a4cf9ef 100644 --- a/interfaces/kits/c/media_asset_change_request_capi.h +++ b/interfaces/kits/c/media_asset_change_request_capi.h @@ -55,9 +55,28 @@ extern "C" { * 3. Parameter verification failed. * {@link #MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR} if internal system error. * @since 12 -*/ + */ OH_MediaAssetChangeRequest* OH_MediaAssetChangeRequest_Create(OH_MediaAsset* mediaAsset); +/** + * @brief Add resource of the asset using file uri. + * + * @param changeRequest the {@link OH_MediaAssetChangeRequest} instance. + * @param resourceType the {@link MediaLibrary_ResourceType} of the resource to add. + * @param fileUri the file uri. + * @return {@link #MEDIA_LIBRARY_OK} if the method call succeeds. + * {@link #MEDIA_LIBRARY_PARAMETER_ERROR} Parameter error. Possible causes: + * 1. Mandatory parameters are left unspecified. + * 2. Incorrect parameter types. + * 3. Parameter verification failed. + * {@link #MEDIA_LIBRARY_NO_SUCH_FILE} if file does not exist. + * {@link #MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR} if internal system error. + * {@link #MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED} if operation is not supported. + * @since 12 + */ +MediaLibrary_ErrorCode OH_MediaAssetChangeRequest_AddResourceWithUri(OH_MediaAssetChangeRequest* changeRequest, + MediaLibrary_ResourceType resourceType, char* fileUri); + /** * @brief Add resource of the asset using ArrayBuffer. * @@ -73,10 +92,29 @@ OH_MediaAssetChangeRequest* OH_MediaAssetChangeRequest_Create(OH_MediaAsset* med * {@link #MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR} if internal system error. * {@link #MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED} if operation is not supported. * @since 12 -*/ + */ MediaLibrary_ErrorCode OH_MediaAssetChangeRequest_AddResourceWithBuffer(OH_MediaAssetChangeRequest* changeRequest, MediaLibrary_ResourceType resourceType, uint8_t* buffer, uint32_t length); +/** + * @brief Get write cache handler. + * + * @permission ohos.permission.WRITE_IMAGEVIDEO + * @param changeRequest the {@link OH_MediaAssetChangeRequest} instance. + * @param fd the write cache handler. + * @return {@link #MEDIA_LIBRARY_OK} if the method call succeeds. + * {@link #MEDIA_LIBRARY_PARAMETER_ERROR} Parameter error. Possible causes: + * 1. Mandatory parameters are left unspecified. + * 2. Incorrect parameter types. + * 3. Parameter verification failed. + * {@link #MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR} if internal system error. + * {@link #MEDIA_LIBRARY_PERMISSION_DENIED} if permission is denied. + * {@link #MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED} if operation is not supported. + * @since 12 + */ +MediaLibrary_ErrorCode OH_MediaAssetChangeRequest_GetWriteCacheHandler(OH_MediaAssetChangeRequest* changeRequest, + int32_t* fd); + /** * @brief Save the photo asset captured by camera. * @@ -90,7 +128,7 @@ MediaLibrary_ErrorCode OH_MediaAssetChangeRequest_AddResourceWithBuffer(OH_Media * {@link #MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR} if internal system error. * {@link #MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED} if operation is not supported. * @since 12 -*/ + */ MediaLibrary_ErrorCode OH_MediaAssetChangeRequest_SaveCameraPhoto(OH_MediaAssetChangeRequest* changeRequest, MediaLibrary_ImageFileType imageFileType); @@ -106,7 +144,7 @@ MediaLibrary_ErrorCode OH_MediaAssetChangeRequest_SaveCameraPhoto(OH_MediaAssetC * {@link #MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR} if internal system error. * {@link #MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED} if operation is not supported. * @since 12 -*/ + */ MediaLibrary_ErrorCode OH_MediaAssetChangeRequest_DiscardCameraPhoto(OH_MediaAssetChangeRequest* changeRequest); /** @@ -119,7 +157,7 @@ MediaLibrary_ErrorCode OH_MediaAssetChangeRequest_DiscardCameraPhoto(OH_MediaAss * 2. Incorrect parameter types. * 3. Parameter verification failed. * @since 12 -*/ + */ MediaLibrary_ErrorCode OH_MediaAssetChangeRequest_Release(OH_MediaAssetChangeRequest* changeRequest); #ifdef __cplusplus diff --git a/interfaces/kits/c/media_asset_manager_capi.h b/interfaces/kits/c/media_asset_manager_capi.h index bac661c7990af3f9c5ba2f55a53e0f07569816a9..b6658343c926f2d9dd307d75baa5cdfb6daad1a0 100644 --- a/interfaces/kits/c/media_asset_manager_capi.h +++ b/interfaces/kits/c/media_asset_manager_capi.h @@ -113,11 +113,28 @@ bool OH_MediaAssetManager_CancelRequest(OH_MediaAssetManager* manager, const Med * {@link #MEDIA_LIBRARY_PERMISSION_DENIED} if permission is denied. * {@link #MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR} if internal system error. * @since 12 -*/ + */ MediaLibrary_ErrorCode OH_MediaAssetManager_RequestImage(OH_MediaAssetManager* manager, OH_MediaAsset* mediaAsset, MediaLibrary_RequestOptions requestOptions, MediaLibrary_RequestId* requestId, OH_MediaLibrary_OnImageDataPrepared callback); +/** + * @brief Request moving photo object. + * + * @permission ohos.permission.READ_IMAGEVIDEO + * @param manager the pointer to {@link OH_MediaAssetManager} instance. + * @param mediaAsset the {@link OH_MediaAsset} instance of media file object to be requested. + * @param requestOptions the {@link MediaLibrary_RequestOptions} for image request strategy mode. + * @param callback the {@link OH_MediaLibrary_OnMovingPhotoDataPrepared} that will be called + * when the requested source is prepared. + * @return the {@link MediaLibrary_RequestId}, if the request fails, "" is returned. + The possible reason is that the parameter is invalid, or permission is denied, or there is system error. + * @since 12 + */ +MediaLibrary_ErrorCode OH_MediaAssetManager_RequestMovingPhoto(OH_MediaAssetManager* manager, OH_MediaAsset* mediaAsset, + MediaLibrary_RequestOptions requestOptions, MediaLibrary_RequestId* requestId, + OH_MediaLibrary_OnMovingPhotoDataPrepared callback); + /** * @brief Release the {@link OH_MediaAssetManager} instance. * @@ -128,7 +145,7 @@ MediaLibrary_ErrorCode OH_MediaAssetManager_RequestImage(OH_MediaAssetManager* m * 2. Incorrect parameter types. * 3. Parameter verification failed. * @since 12 -*/ + */ MediaLibrary_ErrorCode OH_MediaAssetManager_Release(OH_MediaAssetManager* manager); #ifdef __cplusplus diff --git a/interfaces/kits/c/moving_photo_capi.h b/interfaces/kits/c/moving_photo_capi.h new file mode 100644 index 0000000000000000000000000000000000000000..db2a0b5c695bc463fdcb87ad9d72b2fd31e4396a --- /dev/null +++ b/interfaces/kits/c/moving_photo_capi.h @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup MovingPhoto + * @{ + * + * @brief Provides APIs of request capability for Media Source. + * + * @since 12 + */ + +/** + * @file moving_photo_capi.h + * + * @brief Defines APIs related to moving photo. + * + * Provides the ability to obtain moving photo information. + * + * @kit MediaLibraryKit + * @syscap SystemCapability.FileManagement.PhotoAccessHelper.Core + * @library libmedia_asset_manager.so + * @since 12 + */ + +#ifndef MULTIMEDIA_MEDIA_LIBRARY_NATIVE_MOVING_PHOTO_H +#define MULTIMEDIA_MEDIA_LIBRARY_NATIVE_MOVING_PHOTO_H + +#include "media_asset_base_capi.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Get uri of the moving photo. + * + * @param movingPhoto the {@link OH_MovingPhoto} instance. + * @param uri the uri of the moving photo. + * @return {@link #MEDIA_LIBRARY_OK} if the method call succeeds. + * {@link #MEDIA_LIBRARY_PARAMETER_ERROR} Parameter error. Possible causes: + * 1. Mandatory parameters are left unspecified. + * 2. Incorrect parameter types. + * 3. Parameter verification failed. + * {@link #MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR} if internal system error. + * @since 12 + */ +MediaLibrary_ErrorCode OH_MovingPhoto_GetUri(OH_MovingPhoto* movingPhoto, const char** uri); + +/** + * @brief Request the image and video content of the moving photo and write to destination uri. + * + * @permission ohos.permission.READ_IMAGEVIDEO + * @param movingPhoto the {@link OH_MovingPhoto} instance. + * @param imageUri the destination file uri to save the image data. + * @param videoUri the destination file uri to save the video data. + * @return {@link #MEDIA_LIBRARY_OK} if the method call succeeds. + * {@link #MEDIA_LIBRARY_PARAMETER_ERROR} Parameter error. Possible causes: + * 1. Mandatory parameters are left unspecified. + * 2. Incorrect parameter types. + * 3. Parameter verification failed. + * {@link #MEDIA_LIBRARY_PERMISSION_DENIED} if permission is denied. + * {@link #MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR} if internal system error. + * @since 12 + */ +MediaLibrary_ErrorCode OH_MovingPhoto_RequestContentWithUris(OH_MovingPhoto* movingPhoto, char* imageUri, + char* videoUri); + +/** + * @brief Request the image or video content of the moving photo and write to destination uri. + * + * @permission ohos.permission.READ_IMAGEVIDEO + * @param movingPhoto the {@link OH_MovingPhoto} instance. + * @param resourceType the {@link MediaLibrary_ResourceType} of the moving photo content to request. + * @param uri the destination file uri to save the data. + * @return {@link #MEDIA_LIBRARY_OK} if the method call succeeds. + * {@link #MEDIA_LIBRARY_PARAMETER_ERROR} Parameter error. Possible causes: + * 1. Mandatory parameters are left unspecified. + * 2. Incorrect parameter types. + * 3. Parameter verification failed. + * {@link #MEDIA_LIBRARY_PERMISSION_DENIED} if permission is denied. + * {@link #MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR} if internal system error. + * @since 12 + */ +MediaLibrary_ErrorCode OH_MovingPhoto_RequestContentWithUri(OH_MovingPhoto* movingPhoto, + MediaLibrary_ResourceType resourceType, char* uri); + +/** + * @brief Request data of the moving photo. + * + * @permission ohos.permission.READ_IMAGEVIDEO + * @param movingPhoto the {@link OH_MovingPhoto} instance. + * @param resourceType the {@link MediaLibrary_ResourceType} of the moving photo content to request. + * @param buffer the buffer of the content. + * @param size the size of the buffer. + * @return {@link #MEDIA_LIBRARY_OK} if the method call succeeds. + * {@link #MEDIA_LIBRARY_PARAMETER_ERROR} Parameter error. Possible causes: + * 1. Mandatory parameters are left unspecified. + * 2. Incorrect parameter types. + * 3. Parameter verification failed. + * {@link #MEDIA_LIBRARY_PERMISSION_DENIED} if permission is denied. + * {@link #MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR} if internal system error. + * @since 12 + */ +MediaLibrary_ErrorCode OH_MovingPhoto_RequestContentWithBuffer(OH_MovingPhoto* movingPhoto, + MediaLibrary_ResourceType resourceType, const uint8_t** buffer, uint32_t* size); + +/** + * @brief Release the {@link OH_MovingPhoto} instance. + * + * @param movingPhoto the {@link OH_MovingPhoto} instance. + * @return {@link #MEDIA_LIBRARY_OK} if the method call succeeds. + * {@link #MEDIA_LIBRARY_PARAMETER_ERROR} Parameter error. Possible causes: + * 1. Mandatory parameters are left unspecified. + * 2. Incorrect parameter types. + * 3. Parameter verification failed. + * @since 12 + */ +MediaLibrary_ErrorCode OH_MovingPhoto_Release(OH_MovingPhoto* movingPhoto); + +#ifdef __cplusplus +} +#endif + +#endif // MULTIMEDIA_MEDIA_LIBRARY_NATIVE_MOVING_PHOTO_H +/** @} */ \ No newline at end of file