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