• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 OHOS_CAMERA_PREVIEW_OUTPUT_H
17 #define OHOS_CAMERA_PREVIEW_OUTPUT_H
18 
19 #include "capture_output.h"
20 #include "istream_repeat.h"
21 #include "istream_repeat_callback.h"
22 
23 namespace OHOS {
24 namespace CameraStandard {
25 class PreviewStateCallback {
26 public:
27     PreviewStateCallback() = default;
28     virtual ~PreviewStateCallback() = default;
29 
30     /**
31      * @brief Called when preview frame is started rendering.
32      */
33     virtual void OnFrameStarted() const = 0;
34 
35     /**
36      * @brief Called when preview frame is ended.
37      *
38      * @param frameCount Indicates number of frames captured.
39      */
40     virtual void OnFrameEnded(const int32_t frameCount) const = 0;
41 
42     /**
43      * @brief Called when error occured during preview rendering.
44      *
45      * @param errorCode Indicates a {@link ErrorCode} which will give information for preview callback error.
46      */
47     virtual void OnError(const int32_t errorCode) const = 0;
48 };
49 
50 class PreviewOutput : public CaptureOutput {
51 public:
52     explicit PreviewOutput(sptr<IStreamRepeat> &streamRepeat);
53     virtual ~PreviewOutput();
54 
55     /**
56      * @brief Set the preview callback for the preview output.
57      *
58      * @param PreviewStateCallback to be triggered.
59      */
60     void SetCallback(std::shared_ptr<PreviewStateCallback> callback);
61 
62     /**
63      * @brief Releases a instance of the preview output.
64      */
65     int32_t Release() override;
66 
67     /**
68      * @brief Add delayed preview surface.
69      *
70      * @param surface to add.
71      */
72     void AddDeferredSurface(sptr<Surface> surface);
73 
74     /**
75      * @brief Start preview stream.
76      */
77     int32_t Start();
78 
79     /**
80      * @brief stop preview stream.
81      */
82     int32_t Stop();
83 
84     /**
85      * @brief Get the application callback information.
86      *
87      * @return Returns the pointer application callback.
88      */
89     std::shared_ptr<PreviewStateCallback> GetApplicationCallback();
90 
91 private:
92     std::shared_ptr<PreviewStateCallback> appCallback_;
93     sptr<IStreamRepeatCallback> svcCallback_;
94 };
95 } // namespace CameraStandard
96 } // namespace OHOS
97 #endif // OHOS_CAMERA_PREVIEW_OUTPUT_H
98 
99