mirror of
https://github.com/openharmony/multimedia_medialibrary_standard.git
synced 2026-07-01 00:17:55 -04:00
!2371 fix title and fast thumbnail name
Merge pull request !2371 from 梁家熙/20230915-fixbug
This commit is contained in:
+12
-5
@@ -1560,9 +1560,6 @@ HWTEST_F(MediaLibraryAudioOperationsTest, audio_oprn_pending_api10_test_002, Tes
|
||||
pendingStatus = GetAudioPendingStatus(fileId);
|
||||
EXPECT_GT(pendingStatus, 0);
|
||||
|
||||
char data = 'A';
|
||||
write(fd, &data, 1);
|
||||
|
||||
MediaLibraryCommand closeCmd(OperationObject::FILESYSTEM_AUDIO, OperationType::CLOSE,
|
||||
MediaLibraryApi::API_10);
|
||||
auto fileAssetPtr = QueryAudioAsset(AudioColumn::MEDIA_ID, to_string(fileId));
|
||||
@@ -1574,6 +1571,11 @@ HWTEST_F(MediaLibraryAudioOperationsTest, audio_oprn_pending_api10_test_002, Tes
|
||||
EXPECT_EQ(ret, 0);
|
||||
pendingStatus = GetAudioPendingStatus(fileId);
|
||||
EXPECT_GT(pendingStatus, 0);
|
||||
|
||||
ret = SetAudioPendingStatus(0, fileId);
|
||||
EXPECT_EQ(ret, 0);
|
||||
pendingStatus = GetAudioPendingStatus(fileId);
|
||||
EXPECT_EQ(pendingStatus, 0);
|
||||
MEDIA_INFO_LOG("end tdd audio_oprn_pending_api10_test_002");
|
||||
}
|
||||
|
||||
@@ -1606,8 +1608,10 @@ HWTEST_F(MediaLibraryAudioOperationsTest, audio_oprn_pending_api10_test_003, Tes
|
||||
pendingStatus = GetAudioPendingStatus(fileId);
|
||||
EXPECT_GT(pendingStatus, 0);
|
||||
|
||||
char data = 'A';
|
||||
write(fd, &data, 1);
|
||||
ret = SetAudioPendingStatus(0, fileId);
|
||||
EXPECT_EQ(ret, 0);
|
||||
pendingStatus = GetAudioPendingStatus(fileId);
|
||||
EXPECT_EQ(pendingStatus, 0);
|
||||
|
||||
MediaLibraryCommand closeCmd(OperationObject::FILESYSTEM_AUDIO, OperationType::CLOSE);
|
||||
auto fileAssetPtr = QueryAudioAsset(AudioColumn::MEDIA_ID, to_string(fileId));
|
||||
@@ -1617,6 +1621,9 @@ HWTEST_F(MediaLibraryAudioOperationsTest, audio_oprn_pending_api10_test_003, Tes
|
||||
closeCmd.SetValueBucket(closeValues);
|
||||
ret = MediaLibraryAudioOperations::Close(closeCmd);
|
||||
EXPECT_EQ(ret, 0);
|
||||
pendingStatus = GetAudioPendingStatus(fileId);
|
||||
EXPECT_EQ(pendingStatus, 0);
|
||||
|
||||
MEDIA_INFO_LOG("end tdd audio_oprn_pending_api10_test_003");
|
||||
}
|
||||
|
||||
|
||||
@@ -204,7 +204,7 @@ napi_value FileAssetNapi::PhotoAccessHelperInit(napi_env env, napi_value exports
|
||||
DECLARE_NAPI_FUNCTION("getExif", JSGetExif),
|
||||
DECLARE_NAPI_FUNCTION("setUserComment", PhotoAccessHelperSetUserComment),
|
||||
DECLARE_NAPI_FUNCTION("requestPhoto", PhotoAccessHelperRequestPhoto),
|
||||
DECLARE_NAPI_FUNCTION("cancelRequestPhoto", PhotoAccessHelperCancelRequestPhoto),
|
||||
DECLARE_NAPI_FUNCTION("cancelPhotoRequest", PhotoAccessHelperCancelPhotoRequest),
|
||||
}
|
||||
};
|
||||
MediaLibraryNapiUtils::NapiDefineClass(env, exports, info);
|
||||
@@ -1603,24 +1603,44 @@ static void JSGetThumbnailCompleteCallback(napi_env env, napi_status status,
|
||||
delete context;
|
||||
}
|
||||
|
||||
static void GetSizeInfo(napi_env env, napi_value configObj, std::string type, int32_t &result)
|
||||
static bool GetInt32InfoFromNapiObject(napi_env env, napi_value configObj, std::string type, int32_t &result)
|
||||
{
|
||||
napi_value item = nullptr;
|
||||
bool exist = false;
|
||||
napi_status status = napi_has_named_property(env, configObj, type.c_str(), &exist);
|
||||
if (status != napi_ok || !exist) {
|
||||
NAPI_ERR_LOG("can not find named property, status: %{public}d", status);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (napi_get_named_property(env, configObj, type.c_str(), &item) != napi_ok) {
|
||||
NAPI_ERR_LOG("get named property fail");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (napi_get_value_int32(env, item, &result) != napi_ok) {
|
||||
NAPI_ERR_LOG("get property value fail");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool GetNapiObjectFromNapiObject(napi_env env, napi_value configObj, std::string type, napi_value *object)
|
||||
{
|
||||
bool exist = false;
|
||||
napi_status status = napi_has_named_property(env, configObj, type.c_str(), &exist);
|
||||
if (status != napi_ok || !exist) {
|
||||
NAPI_ERR_LOG("can not find named property, status: %{public}d", status);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (napi_get_named_property(env, configObj, type.c_str(), object) != napi_ok) {
|
||||
NAPI_ERR_LOG("get named property fail");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
napi_value GetJSArgsForGetThumbnail(napi_env env, size_t argc, const napi_value argv[],
|
||||
@@ -1642,8 +1662,8 @@ napi_value GetJSArgsForGetThumbnail(napi_env env, size_t argc, const napi_value
|
||||
napi_typeof(env, argv[i], &valueType);
|
||||
|
||||
if (i == PARAM0 && valueType == napi_object) {
|
||||
GetSizeInfo(env, argv[PARAM0], "width", asyncContext->size.width);
|
||||
GetSizeInfo(env, argv[PARAM0], "height", asyncContext->size.height);
|
||||
GetInt32InfoFromNapiObject(env, argv[PARAM0], "width", asyncContext->size.width);
|
||||
GetInt32InfoFromNapiObject(env, argv[PARAM0], "height", asyncContext->size.height);
|
||||
} else if (i == PARAM0 && valueType == napi_function) {
|
||||
napi_create_reference(env, argv[i], NAPI_INIT_REF_COUNT, &asyncContext->callbackRef);
|
||||
break;
|
||||
@@ -1661,6 +1681,46 @@ napi_value GetJSArgsForGetThumbnail(napi_env env, size_t argc, const napi_value
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value GetPhotoRequestArgs(napi_env env, size_t argc, const napi_value argv[],
|
||||
unique_ptr<FileAssetAsyncContext> &asyncContext, RequestPhotoType &type)
|
||||
{
|
||||
if (argc != ARGS_TWO) {
|
||||
NapiError::ThrowError(env, JS_ERR_PARAMETER_INVALID, "Invalid parameter number " + to_string(argc));
|
||||
return nullptr;
|
||||
}
|
||||
asyncContext->size.width = DEFAULT_THUMB_SIZE;
|
||||
asyncContext->size.height = DEFAULT_THUMB_SIZE;
|
||||
|
||||
for (size_t i = PARAM0; i < argc; i++) {
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
napi_typeof(env, argv[i], &valueType);
|
||||
|
||||
if (i == PARAM0 && valueType == napi_object) {
|
||||
napi_value sizeObj;
|
||||
if (GetNapiObjectFromNapiObject(env, argv[PARAM0], "size", &sizeObj)) {
|
||||
GetInt32InfoFromNapiObject(env, sizeObj, "width", asyncContext->size.width);
|
||||
GetInt32InfoFromNapiObject(env, sizeObj, "height", asyncContext->size.height);
|
||||
}
|
||||
int32_t requestType = 0;
|
||||
if (GetInt32InfoFromNapiObject(env, argv[i], REQUEST_PHOTO_TYPE, requestType)) {
|
||||
type = static_cast<RequestPhotoType>(requestType);
|
||||
} else {
|
||||
type = RequestPhotoType::REQUEST_ALL;
|
||||
}
|
||||
} else if (i == PARAM1 && valueType == napi_function) {
|
||||
napi_create_reference(env, argv[i], NAPI_INIT_REF_COUNT, &asyncContext->callbackRef);
|
||||
break;
|
||||
} else {
|
||||
NapiError::ThrowError(env, JS_ERR_PARAMETER_INVALID, "Invalid parameter type");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
napi_value result = nullptr;
|
||||
CHECK_ARGS(env, napi_get_boolean(env, true, &result), JS_INNER_FAIL);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value FileAssetNapi::JSGetThumbnail(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_status status;
|
||||
@@ -3438,12 +3498,19 @@ napi_value FileAssetNapi::PhotoAccessHelperRequestPhoto(napi_env env, napi_callb
|
||||
CHECK_COND_RET(MediaLibraryNapiUtils::AsyncContextSetObjectInfo(env, info, asyncContext, ARGS_TWO, ARGS_TWO) ==
|
||||
napi_ok, result, "Failed to get object info");
|
||||
// use current parse args function temporary
|
||||
result = GetJSArgsForGetThumbnail(env, asyncContext->argc, asyncContext->argv, asyncContext);
|
||||
RequestPhotoType type = RequestPhotoType::REQUEST_ALL;
|
||||
result = GetPhotoRequestArgs(env, asyncContext->argc, asyncContext->argv, asyncContext, type);
|
||||
ASSERT_NULLPTR_CHECK(env, result);
|
||||
auto obj = asyncContext->objectInfo;
|
||||
napi_value ret = nullptr;
|
||||
CHECK_NULL_PTR_RETURN_UNDEFINED(env, asyncContext->objectInfo, ret, "FileAsset is nullptr");
|
||||
|
||||
RequestPhotoParams params = {
|
||||
.uri = obj->fileAssetPtr->GetUri(),
|
||||
.path = obj->fileAssetPtr->GetFilePath(),
|
||||
.size = asyncContext->size,
|
||||
.type = type
|
||||
};
|
||||
static std::once_flag onceFlag;
|
||||
std::call_once(onceFlag, []() mutable {
|
||||
thumbnailManager_ = ThumbnailManager::GetInstance();
|
||||
@@ -3453,17 +3520,16 @@ napi_value FileAssetNapi::PhotoAccessHelperRequestPhoto(napi_env env, napi_callb
|
||||
});
|
||||
string requestId;
|
||||
if (thumbnailManager_ != nullptr) {
|
||||
requestId = thumbnailManager_->AddPhotoRequest(obj->fileAssetPtr->GetUri(), obj->fileAssetPtr->GetPath(),
|
||||
asyncContext->size, env, asyncContext->callbackRef);
|
||||
requestId = thumbnailManager_->AddPhotoRequest(params, env, asyncContext->callbackRef);
|
||||
}
|
||||
napi_create_string_utf8(env, requestId.c_str(), NAPI_AUTO_LENGTH, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value FileAssetNapi::PhotoAccessHelperCancelRequestPhoto(napi_env env, napi_callback_info info)
|
||||
napi_value FileAssetNapi::PhotoAccessHelperCancelPhotoRequest(napi_env env, napi_callback_info info)
|
||||
{
|
||||
MediaLibraryTracer tracer;
|
||||
tracer.Start("PhotoAccessHelperCancelRequestPhoto");
|
||||
tracer.Start("PhotoAccessHelperCancelPhotoRequest");
|
||||
|
||||
napi_value ret = nullptr;
|
||||
unique_ptr<FileAssetAsyncContext> asyncContext = make_unique<FileAssetAsyncContext>();
|
||||
|
||||
@@ -17,16 +17,20 @@
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <uuid/uuid.h>
|
||||
|
||||
#include "ashmem.h"
|
||||
#include "image_source.h"
|
||||
#include "image_type.h"
|
||||
#include "js_native_api.h"
|
||||
#include "media_file_uri.h"
|
||||
#include "medialibrary_errno.h"
|
||||
#include "medialibrary_napi_log.h"
|
||||
#include "medialibrary_napi_utils.h"
|
||||
#include "medialibrary_tracer.h"
|
||||
#include "pixel_map.h"
|
||||
#include "pixel_map_napi.h"
|
||||
#include "post_proc.h"
|
||||
#include "string_ex.h"
|
||||
@@ -49,9 +53,9 @@ shared_ptr<ThumbnailManager> ThumbnailManager::instance_ = nullptr;
|
||||
mutex ThumbnailManager::mutex_;
|
||||
bool ThumbnailManager::init_ = false;
|
||||
|
||||
ThumbnailRequest::ThumbnailRequest(const string &uri, const string &path, const Size &size,
|
||||
napi_env env, napi_ref callback) : callback_(env, callback), uri_(uri),
|
||||
path_(path), requestSize_(size)
|
||||
ThumbnailRequest::ThumbnailRequest(const RequestPhotoParams ¶ms, napi_env env,
|
||||
napi_ref callback) : callback_(env, callback), requestPhotoType(params.type), uri_(params.uri),
|
||||
path_(params.path), requestSize_(params.size)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -81,14 +85,64 @@ bool ThumbnailRequest::NeedContinue()
|
||||
return GetStatus() < ThumbnailStatus::THUMB_REMOVE;
|
||||
}
|
||||
|
||||
static bool IsPhotoNeedFastThumb(const Size &size)
|
||||
static bool IsPhotoSizeThumb(const Size &size)
|
||||
{
|
||||
return (size.width >= DEFAULT_THUMB_SIZE || size.height >= DEFAULT_THUMB_SIZE);
|
||||
}
|
||||
|
||||
bool ThumbnailRequest::NeedQualityPhoto()
|
||||
static bool NeedFastThumb(const Size &size, RequestPhotoType type)
|
||||
{
|
||||
return IsPhotoNeedFastThumb(requestSize_);
|
||||
return IsPhotoSizeThumb(size) && (type != RequestPhotoType::REQUEST_QUALITY_THUMB);
|
||||
}
|
||||
|
||||
static bool NeedQualityThumb(const Size &size, RequestPhotoType type)
|
||||
{
|
||||
return IsPhotoSizeThumb(size) && (type != RequestPhotoType::REQUEST_FAST_THUMB);
|
||||
}
|
||||
|
||||
MMapFdPtr::MMapFdPtr(int32_t fd)
|
||||
{
|
||||
if (fd < 0) {
|
||||
NAPI_ERR_LOG("Fd is invalid: %{public}d", fd);
|
||||
return;
|
||||
}
|
||||
|
||||
struct stat st;
|
||||
if (fstat(fd, &st) == -1) {
|
||||
NAPI_ERR_LOG("fstat error, errno:%{public}d", errno);
|
||||
return;
|
||||
}
|
||||
size_ = st.st_size;
|
||||
|
||||
// mmap ptr from fd
|
||||
fdPtr_ = mmap(nullptr, size_, PROT_READ, MAP_SHARED, fd, 0);
|
||||
if (fdPtr_ == MAP_FAILED || fdPtr_ == nullptr) {
|
||||
NAPI_ERR_LOG("mmap uniqueFd failed, errno = %{public}d", errno);
|
||||
return;
|
||||
}
|
||||
|
||||
isValid_ = true;
|
||||
}
|
||||
|
||||
MMapFdPtr::~MMapFdPtr()
|
||||
{
|
||||
// munmap ptr from fd
|
||||
munmap(fdPtr_, size_);
|
||||
}
|
||||
|
||||
void* MMapFdPtr::GetFdPtr()
|
||||
{
|
||||
return fdPtr_;
|
||||
}
|
||||
|
||||
off_t MMapFdPtr::GetFdSize()
|
||||
{
|
||||
return size_;
|
||||
}
|
||||
|
||||
bool MMapFdPtr::IsValid()
|
||||
{
|
||||
return isValid_;
|
||||
}
|
||||
|
||||
static string GenerateRequestId()
|
||||
@@ -120,8 +174,10 @@ void ThumbnailManager::Init()
|
||||
}
|
||||
init_ = true;
|
||||
isThreadRunning_ = true;
|
||||
fastThread_ = thread(bind(&ThumbnailManager::FastImageWorker, this, 0));
|
||||
fastThread_.detach();
|
||||
for (auto i = 0; i < FAST_THREAD_NUM; i++) {
|
||||
fastThreads_.emplace_back(bind(&ThumbnailManager::FastImageWorker, this, i));
|
||||
fastThreads_[i].detach();
|
||||
}
|
||||
for (auto i = 0; i < THREAD_NUM; i++) {
|
||||
threads_.emplace_back(bind(&ThumbnailManager::QualityImageWorker, this, i));
|
||||
threads_[i].detach();
|
||||
@@ -129,17 +185,16 @@ void ThumbnailManager::Init()
|
||||
return;
|
||||
}
|
||||
|
||||
string ThumbnailManager::AddPhotoRequest(const string &uri, const string &path, const Size &size,
|
||||
napi_env env, napi_ref callback)
|
||||
string ThumbnailManager::AddPhotoRequest(const RequestPhotoParams ¶ms, napi_env env, napi_ref callback)
|
||||
{
|
||||
shared_ptr<ThumbnailRequest> request = make_shared<ThumbnailRequest>(uri, path, size, env, callback);
|
||||
shared_ptr<ThumbnailRequest> request = make_shared<ThumbnailRequest>(params, env, callback);
|
||||
string requestId = GenerateRequestId();
|
||||
request->SetUUID(requestId);
|
||||
if (!thumbRequest_.Insert(requestId, request)) {
|
||||
return "";
|
||||
}
|
||||
// judge from request option
|
||||
if (IsPhotoNeedFastThumb(size)) {
|
||||
if (NeedFastThumb(params.size, params.type)) {
|
||||
AddFastPhotoRequest(request);
|
||||
} else {
|
||||
AddQualityPhotoRequest(request);
|
||||
@@ -165,8 +220,10 @@ ThumbnailManager::~ThumbnailManager()
|
||||
isThreadRunning_ = false;
|
||||
fastCv_.notify_all();
|
||||
qualityCv_.notify_all();
|
||||
if (fastThread_.joinable()) {
|
||||
fastThread_.join();
|
||||
for (auto &fastThread_ : fastThreads_) {
|
||||
if (fastThread_.joinable()) {
|
||||
fastThread_.join();
|
||||
}
|
||||
}
|
||||
for (auto &thread : threads_) {
|
||||
if (thread.joinable()) {
|
||||
@@ -237,7 +294,67 @@ static bool IfSizeEqualsRatio(const Size &imageSize, const Size &targetSize)
|
||||
return imageSize.width / imageSize.height == targetSize.width / targetSize.height;
|
||||
}
|
||||
|
||||
static unique_ptr<PixelMap> DecodeThumbnail(UniqueFd& uniqueFd, const Size& size)
|
||||
static bool GetAshmemPtr(int32_t memSize, void **sharedPtr, int32_t &fd)
|
||||
{
|
||||
fd = AshmemCreate("MediaLibrary Create Ashmem Data", memSize);
|
||||
if (fd < 0) {
|
||||
NAPI_ERR_LOG("Can not create ashmem, fd:%{public}d", fd);
|
||||
return false;
|
||||
}
|
||||
int32_t result = AshmemSetProt(fd, PROT_READ | PROT_WRITE);
|
||||
if (result < 0) {
|
||||
NAPI_ERR_LOG("Can not set ashmem prot, result:%{public}d", result);
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
*sharedPtr = mmap(nullptr, memSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (*sharedPtr == MAP_FAILED || *sharedPtr == nullptr) {
|
||||
NAPI_ERR_LOG("mmap ashmem ptr failed, errno = %{public}d", errno);
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static PixelMapPtr CreateThumbnailByAshmem(UniqueFd &uniqueFd, const Size &size)
|
||||
{
|
||||
Media::InitializationOptions option = {
|
||||
.size = size,
|
||||
.pixelFormat = PixelFormat::BGRA_8888
|
||||
};
|
||||
PixelMapPtr pixel = Media::PixelMap::Create(option);
|
||||
if (pixel == nullptr) {
|
||||
NAPI_ERR_LOG("Can not create pixel");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MMapFdPtr mmapFd(uniqueFd.Get());
|
||||
if (!mmapFd.IsValid()) {
|
||||
NAPI_ERR_LOG("Can not mmap by fd");
|
||||
return nullptr;
|
||||
}
|
||||
auto memSize = static_cast<int32_t>(mmapFd.GetFdSize());
|
||||
|
||||
// create ashmem and mmap
|
||||
void *sharedPtr = nullptr;
|
||||
int32_t fd = 0;
|
||||
if (!GetAshmemPtr(memSize, &sharedPtr, fd)) {
|
||||
return nullptr;
|
||||
}
|
||||
int32_t err = memcpy_s(sharedPtr, memSize + 1, mmapFd.GetFdPtr(), memSize);
|
||||
if (err != EOK) {
|
||||
NAPI_ERR_LOG("memcpy failed, errno:%{public}d", err);
|
||||
return nullptr;
|
||||
}
|
||||
auto data = static_cast<uint8_t*>(sharedPtr);
|
||||
void* fdPtr = new int32_t();
|
||||
*static_cast<int32_t*>(fdPtr) = fd;
|
||||
pixel->SetPixelsAddr(data, fdPtr, memSize, Media::AllocatorType::SHARE_MEM_ALLOC, nullptr);
|
||||
return pixel;
|
||||
}
|
||||
|
||||
static PixelMapPtr DecodeThumbnail(UniqueFd &uniqueFd, const Size &size)
|
||||
{
|
||||
MediaLibraryTracer tracer;
|
||||
tracer.Start("ImageSource::CreateImageSource");
|
||||
@@ -275,25 +392,6 @@ static unique_ptr<PixelMap> DecodeThumbnail(UniqueFd& uniqueFd, const Size& size
|
||||
return pixelMap;
|
||||
}
|
||||
|
||||
static PixelMapPtr GetPixelMapWithoutDecode(UniqueFd &uniqueFd, const Size &size)
|
||||
{
|
||||
struct stat statInfo;
|
||||
if (fstat(uniqueFd.Get(), &statInfo) == E_ERR) {
|
||||
return nullptr;
|
||||
}
|
||||
uint32_t *buffer = static_cast<uint32_t*>(malloc(statInfo.st_size));
|
||||
if (buffer == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
read(uniqueFd.Get(), buffer, statInfo.st_size);
|
||||
InitializationOptions option;
|
||||
option.size = size;
|
||||
|
||||
PixelMapPtr pixelMap = PixelMap::Create(buffer, statInfo.st_size, option);
|
||||
free(buffer);
|
||||
return pixelMap;
|
||||
}
|
||||
|
||||
unique_ptr<PixelMap> ThumbnailManager::QueryThumbnail(const string &uriStr, const Size &size, const string &path)
|
||||
{
|
||||
MediaLibraryTracer tracer;
|
||||
@@ -321,7 +419,7 @@ unique_ptr<PixelMap> ThumbnailManager::QueryThumbnail(const string &uriStr, cons
|
||||
}
|
||||
tracer.Finish();
|
||||
if (thumbType == ThumbnailType::MTH || thumbType == ThumbnailType::YEAR) {
|
||||
return GetPixelMapWithoutDecode(uniqueFd, size);
|
||||
return CreateThumbnailByAshmem(uniqueFd, size);
|
||||
} else {
|
||||
return DecodeThumbnail(uniqueFd, size);
|
||||
}
|
||||
@@ -341,7 +439,7 @@ bool ThumbnailManager::RequestFastImage(const RequestSharedPtr &request)
|
||||
return false;
|
||||
}
|
||||
|
||||
PixelMapPtr pixelMap = GetPixelMapWithoutDecode(uniqueFd, fastSize);
|
||||
PixelMapPtr pixelMap = CreateThumbnailByAshmem(uniqueFd, fastSize);
|
||||
request->SetFastPixelMap(move(pixelMap));
|
||||
return true;
|
||||
}
|
||||
@@ -361,7 +459,7 @@ void ThumbnailManager::DealWithFastRequest(const RequestSharedPtr &request)
|
||||
return;
|
||||
}
|
||||
|
||||
if (request->NeedQualityPhoto()) {
|
||||
if (NeedQualityThumb(request->GetRequestSize(), request->requestPhotoType)) {
|
||||
AddQualityPhotoRequest(request);
|
||||
} else {
|
||||
DeleteRequestIdFromMap(request->GetUUID());
|
||||
@@ -480,6 +578,11 @@ static void UvJsExecute(uv_work_t *work)
|
||||
|
||||
bool ThumbnailManager::NotifyImage(const RequestSharedPtr &request, bool isFastImage)
|
||||
{
|
||||
if (!request->NeedContinue()) {
|
||||
DeleteRequestIdFromMap(request->GetUUID());
|
||||
return false;
|
||||
}
|
||||
|
||||
uv_loop_s *loop = nullptr;
|
||||
napi_get_uv_event_loop(request->callback_.env_, &loop);
|
||||
if (loop == nullptr) {
|
||||
|
||||
@@ -143,6 +143,8 @@ static void SetValuesFromMetaDataApi10(const Metadata &metadata, ValuesBucket &v
|
||||
values.PutString(MediaColumn::MEDIA_FILE_PATH, metadata.GetFilePath());
|
||||
values.PutString(MediaColumn::MEDIA_MIME_TYPE, metadata.GetFileMimeType());
|
||||
values.PutInt(MediaColumn::MEDIA_TYPE, mediaType);
|
||||
values.PutString(MediaColumn::MEDIA_NAME, metadata.GetFileName());
|
||||
values.PutString(MediaColumn::MEDIA_TITLE, metadata.GetFileTitle());
|
||||
|
||||
values.PutLong(MediaColumn::MEDIA_SIZE, metadata.GetFileSize());
|
||||
values.PutLong(MediaColumn::MEDIA_DATE_MODIFIED, metadata.GetFileDateModified());
|
||||
|
||||
@@ -67,6 +67,9 @@ const std::string CLOSE_CREATE_THUMB_STATUS = "create_thumbnail_sync_status";
|
||||
const int32_t CREATE_THUMB_SYNC_STATUS = 1;
|
||||
const int32_t CREATE_THUMB_ASYNC_STATUS = 0;
|
||||
|
||||
// request photo type
|
||||
const std::string REQUEST_PHOTO_TYPE = "request_photo_type";
|
||||
|
||||
static inline std::string GetThumbnailPath(const std::string &path, const std::string &key)
|
||||
{
|
||||
if (path.length() < ROOT_MEDIA_DIR.length()) {
|
||||
|
||||
@@ -99,6 +99,12 @@ enum NotifyType {
|
||||
NOTIFY_ALBUM_ADD_ASSERT,
|
||||
NOTIFY_ALBUM_REMOVE_ASSET
|
||||
};
|
||||
|
||||
enum class RequestPhotoType : int32_t {
|
||||
REQUEST_ALL = 0,
|
||||
REQUEST_FAST_THUMB = 1,
|
||||
REQUEST_QUALITY_THUMB = 2,
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_FILEMANAGEMENT_USERFILEMGR_TYPES_H
|
||||
|
||||
@@ -129,7 +129,7 @@ private:
|
||||
static napi_value PhotoAccessHelperFavorite(napi_env env, napi_callback_info info);
|
||||
static napi_value PhotoAccessHelperGetThumbnail(napi_env env, napi_callback_info info);
|
||||
static napi_value PhotoAccessHelperRequestPhoto(napi_env env, napi_callback_info info);
|
||||
static napi_value PhotoAccessHelperCancelRequestPhoto(napi_env env, napi_callback_info info);
|
||||
static napi_value PhotoAccessHelperCancelPhotoRequest(napi_env env, napi_callback_info info);
|
||||
static napi_value PhotoAccessHelperSetHidden(napi_env env, napi_callback_info info);
|
||||
static napi_value PhotoAccessHelperSetPending(napi_env env, napi_callback_info info);
|
||||
static napi_value PhotoAccessHelperSetUserComment(napi_env env, napi_callback_info info);
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "safe_map.h"
|
||||
#include "safe_queue.h"
|
||||
#include "pixel_map.h"
|
||||
#include "userfile_manager_types.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
@@ -44,6 +45,13 @@ enum class ThumbnailStatus : int32_t {
|
||||
THUMB_REMOVE,
|
||||
};
|
||||
|
||||
struct RequestPhotoParams {
|
||||
std::string uri;
|
||||
std::string path;
|
||||
Size size;
|
||||
RequestPhotoType type;
|
||||
};
|
||||
|
||||
class ThumbnailCallback {
|
||||
public:
|
||||
ThumbnailCallback(napi_env env, napi_ref callback) : env_(env), callBackRef_(callback)
|
||||
@@ -64,13 +72,11 @@ public:
|
||||
|
||||
class ThumbnailRequest {
|
||||
public:
|
||||
explicit ThumbnailRequest(const std::string &uri, const std::string &path, const Size &size,
|
||||
napi_env env, napi_ref callback);
|
||||
explicit ThumbnailRequest(const RequestPhotoParams ¶ms, napi_env env, napi_ref callback);
|
||||
virtual ~ThumbnailRequest();
|
||||
bool UpdateStatus(ThumbnailStatus status);
|
||||
ThumbnailStatus GetStatus();
|
||||
bool NeedContinue();
|
||||
bool NeedQualityPhoto();
|
||||
|
||||
std::string GetUri() const
|
||||
{
|
||||
@@ -118,6 +124,7 @@ public:
|
||||
}
|
||||
|
||||
ThumbnailCallback callback_;
|
||||
RequestPhotoType requestPhotoType;
|
||||
private:
|
||||
std::string uri_;
|
||||
std::string path_;
|
||||
@@ -130,15 +137,28 @@ private:
|
||||
PixelMapPtr pixelMap;
|
||||
};
|
||||
|
||||
constexpr int THREAD_NUM = 4;
|
||||
class MMapFdPtr {
|
||||
public:
|
||||
explicit MMapFdPtr(int32_t fd);
|
||||
~MMapFdPtr();
|
||||
void* GetFdPtr();
|
||||
off_t GetFdSize();
|
||||
bool IsValid();
|
||||
private:
|
||||
void* fdPtr_;
|
||||
off_t size_;
|
||||
bool isValid_ = false;
|
||||
};
|
||||
|
||||
constexpr int FAST_THREAD_NUM = 3;
|
||||
constexpr int THREAD_NUM = 2;
|
||||
class ThumbnailManager : NoCopyable {
|
||||
public:
|
||||
virtual ~ThumbnailManager();
|
||||
static std::shared_ptr<ThumbnailManager> GetInstance();
|
||||
|
||||
void Init();
|
||||
std::string AddPhotoRequest(const std::string &uri, const std::string &path, const Size &size,
|
||||
napi_env env, napi_ref callback);
|
||||
std::string AddPhotoRequest(const RequestPhotoParams ¶ms, napi_env env, napi_ref callback);
|
||||
void RemovePhotoRequest(const std::string &requestId);
|
||||
static std::unique_ptr<PixelMap> QueryThumbnail(const std::string &uri, const Size &size,
|
||||
const std::string &path);
|
||||
@@ -158,11 +178,11 @@ private:
|
||||
SafeQueue<RequestSharedPtr> fastQueue_;
|
||||
SafeQueue<RequestSharedPtr> qualityQueue_;
|
||||
|
||||
std::thread fastThread_;
|
||||
std::mutex fastLock_;
|
||||
std::condition_variable fastCv_;
|
||||
std::mutex qualityLock_;
|
||||
std::condition_variable qualityCv_;
|
||||
std::vector<std::thread> fastThreads_;
|
||||
std::vector<std::thread> threads_;
|
||||
|
||||
static std::shared_ptr<ThumbnailManager> instance_;
|
||||
|
||||
Reference in New Issue
Block a user