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 "video_processing_impl.h"
17
18 #include "video_processing_factory.h"
19 #include "vpe_log.h"
20
21 using namespace OHOS::Media::VideoProcessingEngine;
22
Create(OH_VideoProcessing ** instance,int type,std::shared_ptr<OpenGLContext> openglContext)23 VideoProcessing_ErrorCode OH_VideoProcessing::Create(OH_VideoProcessing** instance, int type,
24 std::shared_ptr<OpenGLContext> openglContext)
25 {
26 CHECK_AND_RETURN_RET_LOG(instance != nullptr && *instance == nullptr, VIDEO_PROCESSING_ERROR_INVALID_INSTANCE,
27 "VPE video processing instance is null or *instance is not null!");
28 CHECK_AND_RETURN_RET_LOG(VideoProcessingFactory::IsValid(type), VIDEO_PROCESSING_ERROR_INVALID_PARAMETER,
29 "VPE video processing type(%{public}d) is invalid!", type);
30
31 *instance = new(std::nothrow) OH_VideoProcessing(type);
32 CHECK_AND_RETURN_RET_LOG(*instance != nullptr, VIDEO_PROCESSING_ERROR_NO_MEMORY,
33 "VPE video processing out of memory!");
34 auto obj = (*instance)->GetVideoProcessing();
35 CHECK_AND_RETURN_RET_LOG(obj != nullptr, VIDEO_PROCESSING_ERROR_CREATE_FAILED,
36 "VPE video processing constructor failed!");
37 obj->openglContext_ = openglContext;
38 return obj->Initialize();
39 }
40
Destroy(OH_VideoProcessing * instance)41 VideoProcessing_ErrorCode OH_VideoProcessing::Destroy(OH_VideoProcessing* instance)
42 {
43 CHECK_AND_RETURN_RET_LOG(instance != nullptr, VIDEO_PROCESSING_ERROR_INVALID_INSTANCE,
44 "VPE video processing instance is null!");
45 auto obj = instance->GetVideoProcessing();
46 CHECK_AND_RETURN_RET_LOG(obj != nullptr, VIDEO_PROCESSING_ERROR_INVALID_PARAMETER,
47 "VPE video processing instance is empty!");
48 auto errorCode = obj->Deinitialize();
49 delete instance;
50 instance = nullptr;
51 return errorCode;
52 }
53
OH_VideoProcessing(int type)54 OH_VideoProcessing::OH_VideoProcessing(int type)
55 {
56 videoProcessing_ = VideoProcessingFactory::CreateVideoProcessing(type, this);
57 }
58
~OH_VideoProcessing()59 OH_VideoProcessing::~OH_VideoProcessing()
60 {
61 videoProcessing_ = nullptr;
62 }
63
GetVideoProcessing()64 std::shared_ptr<IVideoProcessingNative> OH_VideoProcessing::GetVideoProcessing()
65 {
66 return videoProcessing_;
67 }
68