• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 DISTRIBUTED_STREAM_CUSTOMER_H
17 #define DISTRIBUTED_STREAM_CUSTOMER_H
18 
19 #include <fstream>
20 #include <iostream>
21 #include <thread>
22 #include <vector>
23 #include <map>
24 #include <surface.h>
25 #include <display_type.h>
26 #include "constants.h"
27 #include "camera.h"
28 #include "distributed_hardware_log.h"
29 #include "v1_0/ioffline_stream_operator.h"
30 
31 namespace OHOS {
32 namespace DistributedHardware {
33 
34 typedef enum {
35     CAPTURE_PREVIEW = 0,
36     CAPTURE_SNAPSHOT,
37     CAPTURE_VIDEO,
38 } CaptureMode;
39 
40 class TestBuffersConsumerListener : public IBufferConsumerListener {
41 public:
TestBuffersConsumerListener(const sptr<Surface> & surface,const std::function<void (void *,const uint32_t)> callback)42     TestBuffersConsumerListener(const sptr<Surface>& surface,
43     const std::function<void(void*, const uint32_t)> callback):callback_(callback), consumer_(surface)
44     {
45     }
46 
~TestBuffersConsumerListener()47     ~TestBuffersConsumerListener()
48     {
49     }
50 
OnBufferAvailable()51     void OnBufferAvailable()
52     {
53         DHLOGI("demo test:enter OnBufferAvailable start");
54         OHOS::Rect damage;
55         int32_t flushFence = 0;
56         int64_t timestamp = 0;
57 
58         OHOS::sptr<OHOS::SurfaceBuffer> buff = nullptr;
59         consumer_->AcquireBuffer(buff, flushFence, timestamp, damage);
60         if (buff != nullptr) {
61             void* addr = buff->GetVirAddr();
62             if (callback_ != nullptr) {
63                 int32_t size = buff->GetSize();
64                 callback_(addr, size);
65             }
66             consumer_->ReleaseBuffer(buff, -1);
67             DHLOGI("demo test:Exiting OnBufferAvailable end");
68         }
69     }
SetCallback(const std::function<void (void *,const uint32_t)> callback)70     void SetCallback(const std::function<void(void*, const uint32_t)> callback)
71     {
72         callback_ = callback;
73     }
74 private:
75     std::function<void(void*, uint32_t)> callback_;
76     sptr<Surface> consumer_;
77 };
78 
79 class StreamCustomer {
80 public:
81     StreamCustomer();
82     ~StreamCustomer();
83     sptr<OHOS::IBufferProducer> CreateProducer(CaptureMode mode,
84         const std::function<void(void*, uint32_t)> callback);
85 
86 private:
87     sptr<OHOS::Surface> consumer_ = nullptr;
88 };
89 } // namespace OHOS::Camera
90 }
91 #endif // DISTRIBUTED_STREAM_CUSTOMER_H
92