1  /*
2   * Copyright (c) 2020 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 HOS_CAMERA_STREAM_CUSTOMER_H
17  #define HOS_CAMERA_STREAM_CUSTOMER_H
18  
19  #include <iostream>
20  #include <thread>
21  #include <vector>
22  #include <map>
23  #include <hdf_log.h>
24  #include <iconsumer_surface.h>
25  #include "display_format.h"
26  #include "camera_metadata_info.h"
27  #include "ibuffer.h"
28  #include "v1_0/ioffline_stream_operator.h"
29  #include "camera.h"
30  #ifndef CAMERA_BUILT_ON_OHOS_LITE
31  #include "if_system_ability_manager.h"
32  #include "iservice_registry.h"
33  #endif
34  
35  namespace OHOS::Camera {
36  class StreamCustomer {
37  public:
38      StreamCustomer();
39      ~StreamCustomer();
40  #ifdef CAMERA_BUILT_ON_OHOS_LITE
41      std::shared_ptr<OHOS::Surface> CreateProducer();
42  #else
43      sptr<OHOS::IBufferProducer> CreateProducer();
44  #endif
45      void CamFrame(const std::function<void(void*, const uint32_t)> callback);
46  
47      RetCode ReceiveFrameOn(const std::function<void(void*, const uint32_t)> callback);
48      void ReceiveFrameOff();
49  
50  #ifndef CAMERA_BUILT_ON_OHOS_LITE
51      class TestBuffersConsumerListener : public IBufferConsumerListener {
52      public:
TestBuffersConsumerListener()53          TestBuffersConsumerListener()
54          {
55          }
56  
~TestBuffersConsumerListener()57          ~TestBuffersConsumerListener()
58          {
59          }
60  
OnBufferAvailable()61          void OnBufferAvailable()
62          {
63          }
64      };
65  #endif
66  
67  private:
68      unsigned int camFrameExit_ = 1;
69  
70  #ifdef CAMERA_BUILT_ON_OHOS_LITE
71      std::shared_ptr<OHOS::Surface> consumer_ = nullptr;
72  #else
73      sptr<OHOS::IConsumerSurface> consumer_ = nullptr;
74  #endif
75      std::thread* previewThreadId_ = nullptr;
76  };
77  } // namespace OHOS::Camera
78  #endif // HOS_CAMERA_STREAM_CUSTOMER_H
79