1 /*
2 * Copyright (c) 2023-2023 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 "kits/native/include/camera/video_output.h"
17 #include "impl/video_output_impl.h"
18 #include "camera_log.h"
19 #include "hilog/log.h"
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 /**
26 * @since 11
27 * @version 1.0
28 */
OH_VideoOutput_RegisterCallback(Camera_VideoOutput * videoOutput,VideoOutput_Callbacks * callback)29 Camera_ErrorCode OH_VideoOutput_RegisterCallback(Camera_VideoOutput* videoOutput, VideoOutput_Callbacks* callback)
30 {
31 CHECK_AND_RETURN_RET_LOG(videoOutput != nullptr, CAMERA_INVALID_ARGUMENT,
32 "invaild argument! videoOutput is null!");
33 CHECK_AND_RETURN_RET_LOG(callback != nullptr, CAMERA_INVALID_ARGUMENT,
34 "invaild argument! callback is null!");
35 CHECK_AND_RETURN_RET_LOG(callback->onFrameStart!= nullptr, CAMERA_INVALID_ARGUMENT,
36 "invaild argument! callback onFrameStart is null!");
37 CHECK_AND_RETURN_RET_LOG(callback->onFrameEnd!= nullptr, CAMERA_INVALID_ARGUMENT,
38 "invaild argument! callback onFrameEnd is null!");
39 CHECK_AND_RETURN_RET_LOG(callback->onError!= nullptr, CAMERA_INVALID_ARGUMENT,
40 "invaild argument! callback onError is null!");
41
42 videoOutput->RegisterCallback(callback);
43 return CAMERA_OK;
44 }
45
46 /**
47 * @since 11
48 * @version 1.0
49 */
OH_VideoOutput_UnregisterCallback(Camera_VideoOutput * videoOutput,VideoOutput_Callbacks * callback)50 Camera_ErrorCode OH_VideoOutput_UnregisterCallback(Camera_VideoOutput* videoOutput, VideoOutput_Callbacks* callback)
51 {
52 CHECK_AND_RETURN_RET_LOG(videoOutput != nullptr, CAMERA_INVALID_ARGUMENT,
53 "invaild argument! videoOutput is null!");
54 CHECK_AND_RETURN_RET_LOG(callback != nullptr, CAMERA_INVALID_ARGUMENT,
55 "invaild argument! callback is null!");
56 CHECK_AND_RETURN_RET_LOG(callback->onFrameStart!= nullptr, CAMERA_INVALID_ARGUMENT,
57 "invaild argument! callback onFrameStart is null!");
58 CHECK_AND_RETURN_RET_LOG(callback->onFrameEnd!= nullptr, CAMERA_INVALID_ARGUMENT,
59 "invaild argument! callback onFrameEnd is null!");
60 CHECK_AND_RETURN_RET_LOG(callback->onError!= nullptr, CAMERA_INVALID_ARGUMENT,
61 "invaild argument! callback onError is null!");
62
63 videoOutput->UnregisterCallback(callback);
64 return CAMERA_OK;
65 }
66
67 /**
68 * @since 11
69 * @version 1.0
70 */
OH_VideoOutput_Start(Camera_VideoOutput * videoOutput)71 Camera_ErrorCode OH_VideoOutput_Start(Camera_VideoOutput* videoOutput)
72 {
73 CHECK_AND_RETURN_RET_LOG(videoOutput != nullptr, CAMERA_INVALID_ARGUMENT,
74 "invaild argument! videoOutput is null!");
75
76 return videoOutput->Start();
77 }
78
79 /**
80 * @since 11
81 * @version 1.0
82 */
OH_VideoOutput_Stop(Camera_VideoOutput * videoOutput)83 Camera_ErrorCode OH_VideoOutput_Stop(Camera_VideoOutput* videoOutput)
84 {
85 CHECK_AND_RETURN_RET_LOG(videoOutput != nullptr, CAMERA_INVALID_ARGUMENT,
86 "invaild argument! videoOutput is null!");
87
88 return videoOutput->Stop();
89 }
90
91 /**
92 * @since 11
93 * @version 1.0
94 */
OH_VideoOutput_Release(Camera_VideoOutput * videoOutput)95 Camera_ErrorCode OH_VideoOutput_Release(Camera_VideoOutput* videoOutput)
96 {
97 CHECK_AND_RETURN_RET_LOG(videoOutput != nullptr, CAMERA_INVALID_ARGUMENT,
98 "invaild argument! videoOutput is null!");
99
100 Camera_ErrorCode retCode = videoOutput->Release();
101 if (videoOutput != nullptr) {
102 delete videoOutput;
103 }
104 return retCode;
105 }
106
107 #ifdef __cplusplus
108 }
109 #endif