1 /*
2  * Copyright (C) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef NTERFACES_INNERKITS_NATIVE_INCLUDE_MOVING_PHOTO_IMPL_H
17 #define NTERFACES_INNERKITS_NATIVE_INCLUDE_MOVING_PHOTO_IMPL_H
18 
19 #include "nocopyable.h"
20 #include "moving_photo.h"
21 
22 namespace OHOS {
23 namespace Media {
24 
25 enum class SourceMode {
26     ORIGINAL_MODE = 0,
27     EDITED_MODE,
28 };
29 
30 class MovingPhotoImpl : public MovingPhoto, public NoCopyable {
31 public:
32     MovingPhotoImpl(const std::string& imageUri);
33     ~MovingPhotoImpl();
34 
35     MediaLibrary_ErrorCode GetUri(const char** uri) override;
36     MediaLibrary_ErrorCode RequestContentWithUris(char* imageUri, char* videoUri) override;
37     MediaLibrary_ErrorCode RequestContentWithUri(MediaLibrary_ResourceType resourceType, char* uri) override;
38     MediaLibrary_ErrorCode RequestContentWithBuffer(MediaLibrary_ResourceType resourceType,
39         const uint8_t** buffer, uint32_t* size) override;
40 
41 private:
42     int32_t RequestContentToSandbox();
43     int32_t WriteToSandboxUri(int32_t srcFd, std::string& sandboxUri);
44     int32_t CopyFileFromMediaLibrary(int32_t srcFd, int32_t destFd);
45     int32_t OpenReadOnlyFile(const std::string& uri, bool isReadImage);
46     bool HandleFd(int32_t& fd);
47     int32_t OpenReadOnlyImage(const std::string& imageUri, bool isMediaLibUri);
48     int32_t RequestContentToArrayBuffer();
49     int32_t AcquireFdForArrayBuffer();
50     int32_t OpenReadOnlyVideo(const std::string& videoUri, bool isMediaLibUri);
51 
52 private:
53     std::string imageUri_;
54     char* destImageUri_ = nullptr;
55     char* destVideoUri_ = nullptr;
56     MediaLibrary_ResourceType resourceType_ = MEDIA_LIBRARY_IMAGE_RESOURCE;
57     void* arrayBufferData_ = nullptr;
58     size_t arrayBufferLength_ = 0;
59     SourceMode sourceMode_ = SourceMode::ORIGINAL_MODE;
60 };
61 
62 }
63 }
64 
65 #endif // NTERFACES_INNERKITS_NATIVE_INCLUDE_MOVING_PHOTO_IMPL_H
66