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 #include "moving_photo_capi.h"
17 
18 #include "oh_moving_photo.h"
19 #include "media_log.h"
20 
OH_MovingPhoto_GetUri(OH_MovingPhoto * movingPhoto,const char ** uri)21 MediaLibrary_ErrorCode OH_MovingPhoto_GetUri(OH_MovingPhoto* movingPhoto, const char** uri)
22 {
23     CHECK_AND_RETURN_RET_LOG(movingPhoto != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "movingPhoto is nullptr!");
24     CHECK_AND_RETURN_RET_LOG(movingPhoto->movingPhoto_ != nullptr,
25         MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "movingPhoto_ is nullptr!");
26     CHECK_AND_RETURN_RET_LOG(uri != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "uri is nullptr!");
27 
28     return movingPhoto->movingPhoto_->GetUri(uri);
29 }
30 
OH_MovingPhoto_RequestContentWithUris(OH_MovingPhoto * movingPhoto,char * imageUri,char * videoUri)31 MediaLibrary_ErrorCode OH_MovingPhoto_RequestContentWithUris(OH_MovingPhoto* movingPhoto, char* imageUri,
32     char* videoUri)
33 {
34     CHECK_AND_RETURN_RET_LOG(movingPhoto != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "movingPhoto is nullptr!");
35     CHECK_AND_RETURN_RET_LOG(movingPhoto->movingPhoto_ != nullptr,
36         MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "movingPhoto_ is nullptr!");
37     CHECK_AND_RETURN_RET_LOG(imageUri != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "imageUri is nullptr!");
38     CHECK_AND_RETURN_RET_LOG(videoUri != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "videoUri is nullptr!");
39 
40     return movingPhoto->movingPhoto_->RequestContentWithUris(imageUri, videoUri);
41 }
42 
OH_MovingPhoto_RequestContentWithUri(OH_MovingPhoto * movingPhoto,MediaLibrary_ResourceType resourceType,char * uri)43 MediaLibrary_ErrorCode OH_MovingPhoto_RequestContentWithUri(OH_MovingPhoto* movingPhoto,
44     MediaLibrary_ResourceType resourceType, char* uri)
45 {
46     CHECK_AND_RETURN_RET_LOG(movingPhoto != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "movingPhoto is nullptr!");
47     CHECK_AND_RETURN_RET_LOG(movingPhoto->movingPhoto_ != nullptr,
48         MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "movingPhoto_ is nullptr!");
49     CHECK_AND_RETURN_RET_LOG(uri != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "uri is nullptr!");
50 
51     return movingPhoto->movingPhoto_->RequestContentWithUri(resourceType, uri);
52 }
53 
OH_MovingPhoto_RequestContentWithBuffer(OH_MovingPhoto * movingPhoto,MediaLibrary_ResourceType resourceType,const uint8_t ** buffer,uint32_t * size)54 MediaLibrary_ErrorCode OH_MovingPhoto_RequestContentWithBuffer(OH_MovingPhoto* movingPhoto,
55     MediaLibrary_ResourceType resourceType, const uint8_t** buffer, uint32_t* size)
56 {
57     CHECK_AND_RETURN_RET_LOG(movingPhoto != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "movingPhoto is nullptr!");
58     CHECK_AND_RETURN_RET_LOG(movingPhoto->movingPhoto_ != nullptr,
59         MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED, "movingPhoto_ is nullptr!");
60     CHECK_AND_RETURN_RET_LOG(buffer != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "buffer is nullptr!");
61     CHECK_AND_RETURN_RET_LOG(size != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "size is nullptr!");
62 
63     return movingPhoto->movingPhoto_->RequestContentWithBuffer(resourceType, buffer, size);
64 }
65 
OH_MovingPhoto_Release(OH_MovingPhoto * movingPhoto)66 MediaLibrary_ErrorCode OH_MovingPhoto_Release(OH_MovingPhoto* movingPhoto)
67 {
68     CHECK_AND_RETURN_RET_LOG(movingPhoto != nullptr, MEDIA_LIBRARY_PARAMETER_ERROR, "movingPhoto is nullptr!");
69 
70     delete movingPhoto;
71     movingPhoto = nullptr;
72     return MEDIA_LIBRARY_OK;
73 }
74