• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 INTERFACES_INNER_API_ALGORITHM_VIDEO_H
17 #define INTERFACES_INNER_API_ALGORITHM_VIDEO_H
18 
19 #include <cinttypes>
20 #include <memory>
21 
22 #include "meta/format.h"
23 #include "refbase.h"
24 #include "surface.h"
25 
26 #include "algorithm_errors.h"
27 #include "algorithm_video_common.h"
28 
29 namespace OHOS {
30 namespace Media {
31 namespace VideoProcessingEngine {
32 class __attribute__((visibility("default"))) VpeVideo {
33 public:
34     /**
35      * @brief Create a VpeVideo object.
36      * @param type Use VIDEO_TYPE_XXX to specify the processing type. For details, see {@link VpeVideoType}.
37      * @return If successful, returns a pointer to the VpeVideo object. On error, returns a null pointer.
38      * @since 5.1
39      * @version 5.1
40      */
41     static std::shared_ptr<VpeVideo> Create(uint32_t type);
42 
43     /**
44      * @brief Query whether the feature altorithm is supported.
45      * @param type Use VIDEO_TYPE_XXX to specify the processing type. For details, see {@link VpeVideoType}.
46      * @param parameter The parameter of video processing.
47      * @return true if the feature altorithm is supported. false If the feature altorithm is unsupported.
48      * @since 5.1
49      * @version 5.1
50      */
51     static bool IsSupported(uint32_t type, const Format& parameter);
52 
53     /**
54      * @brief Query whether the product is supported.
55      * @return true if the product is supported. false If the product is unsupported.
56      * @since 6.0
57      */
58     static bool IsSupported(void);
59 
60     /**
61      * @brief Register callback object.
62      * @param callback Callback object to be registered. For details, see {@link VpeVideoCallback}.
63      * @return If successful, returns {@link VPE_ALGO_ERR_OK}. On error, retuns an error code.
64      * @since 5.1
65      * @version 5.1
66      */
67     virtual VPEAlgoErrCode RegisterCallback(const std::shared_ptr<VpeVideoCallback>& callback);
68 
69     /**
70      * @brief Set the output surface for video processing.
71      * @param surface The output surface object.
72      * @return If successful, returns {@link VPE_ALGO_ERR_OK}. On error, retuns an error code.
73      * @since 5.1
74      * @version 5.1
75      */
76     virtual VPEAlgoErrCode SetOutputSurface(const sptr<Surface>& surface);
77 
78     /**
79      * @brief Create an input surface.
80      * @return If successful, returns a pointer to the input surface object. On error, returns a null pointer.
81      * @since 5.1
82      * @version 5.1
83      */
84     virtual sptr<Surface> GetInputSurface();
85 
86     /**
87      * @brief Set parameter for video processing. Add parameter identified by the specified parameter key.
88      * @param parameter The parameter for video processing.
89      * @return If successful, returns {@link VPE_ALGO_ERR_OK}. On error, retuns an error code.
90      * @since 5.1
91      * @version 5.1
92      */
93     virtual VPEAlgoErrCode SetParameter(const Format& parameter);
94 
95     /**
96      * @brief Get parameter of video processing. Get parameter identified by the specified parameter key.
97      * @param parameter The parameter of video processing.
98      * @return If successful, returns {@link VPE_ALGO_ERR_OK}. On error, retuns an error code.
99      * @since 5.1
100      * @version 5.1
101      */
102     virtual VPEAlgoErrCode GetParameter(Format& parameter);
103 
104     /**
105      * @brief Start video processing.
106      * @return If successful, returns {@link VPE_ALGO_ERR_OK}. On error, retuns an error code.
107      * @since 5.1
108      * @version 5.1
109      */
110     virtual VPEAlgoErrCode Start();
111 
112     /**
113      * @brief Stop video processing.
114      *
115      * This method must be called during running.
116      *
117      * @return If successful, returns {@link VPE_ALGO_ERR_OK}. On error, retuns an error code.
118      * @since 5.1
119      * @version 5.1
120      */
121     virtual VPEAlgoErrCode Stop();
122 
123     /**
124      * @brief Releases all resources before destructor. All methods are unavailable after calling this.
125      * @return If successful, returns {@link VPE_ALGO_ERR_OK}. On error, retuns an error code.
126      * @since 5.1
127      * @version 5.1
128      */
129     virtual VPEAlgoErrCode Release();
130 
131     /**
132      * @brief Flush both input and output buffers for video processing.
133      *
134      * This method must be called during running.
135      *
136      * @return If successful, returns {@link VPE_ALGO_ERR_OK}. On error, retuns an error code.
137      * @since 5.1
138      * @version 5.1
139      */
140     virtual VPEAlgoErrCode Flush();
141 
142     /**
143      * @brief Enable video processing effect. It only can be called after {@link Disable}.
144      *
145      * This method must be called during running.
146      *
147      * @return If successful, returns {@link VPE_ALGO_ERR_OK}. On error, retuns an error code.
148      * @since 5.1
149      * @version 5.1
150      */
151     virtual VPEAlgoErrCode Enable();
152 
153     /**
154      * @brief Disable video processing effect. If video processing is disabled, then the processor
155      * sends the surfacebuffer of the input surface to the output surface directly.
156      *
157      * This method must be called during running.
158      *
159      * @return If successful, returns {@link VPE_ALGO_ERR_OK}. On error, retuns an error code.
160      * @since 5.1
161      * @version 5.1
162      */
163     virtual VPEAlgoErrCode Disable();
164 
165     /**
166      * @brief Notify the end of stream.
167      *
168      * This method must be called during running.
169      *
170      * @return If successful, returns {@link VPE_ALGO_ERR_OK}. On error, retuns an error code.
171      * @since 5.1
172      * @version 5.1
173      */
174     virtual VPEAlgoErrCode NotifyEos();
175 
176     /**
177      * @brief Returns the output buffer to video processing.
178      *
179      * This method must be called during running.
180      *
181      * @param index The index of the output buffer.
182      * @param render Whether to render the buffer.
183      * @return If successful, returns {@link VPE_ALGO_ERR_OK}. On error, retuns an error code.
184      * @since 5.1
185      * @version 5.1
186      */
187     virtual VPEAlgoErrCode ReleaseOutputBuffer(uint32_t index, bool render);
188 
189     /**
190      * @brief Send the output buffer out.
191      *
192      * This method must be called during running.
193      *
194      * @param index The index of the output buffer.
195      * @param renderTimestamp The timestamp is associated with the output buffer when it is sent to the surface.
196      * @return If successful, returns {@link VPE_ALGO_ERR_OK}. On error, retuns an error code.
197      * @since 5.1
198      * @version 5.1
199      */
200     virtual VPEAlgoErrCode RenderOutputBufferAtTime(uint32_t index, int64_t renderTimestamp);
201 
202 protected:
203     VpeVideo() = default;
204     virtual ~VpeVideo() = default;
205     VpeVideo(const VpeVideo&) = delete;
206     VpeVideo& operator=(const VpeVideo&) = delete;
207     VpeVideo(VpeVideo&&) = delete;
208     VpeVideo& operator=(VpeVideo&&) = delete;
209 };
210 } // namespace VideoProcessingEngine
211 } // namespace Media
212 } // namespace OHOS
213 
214 #endif // INTERFACES_INNER_API_ALGORITHM_VIDEO_H
215