• 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 <display_type.h>
26 #include "constants.h"
27 #include "distributed_hardware_log.h"
28 #include "iconsumer_surface.h"
29 #include "v1_0/ioffline_stream_operator.h"
30 
31 namespace OHOS {
32 namespace DistributedHardware {
33 
34 enum CaptureMode {
35     CAPTURE_PREVIEW = 0,
36     CAPTURE_SNAPSHOT,
37     CAPTURE_VIDEO,
38 };
39 
40 class TestBuffersConsumerListener : public IBufferConsumerListener {
41 public:
TestBuffersConsumerListener(const sptr<IConsumerSurface> & surface,const std::function<void (void *,const uint32_t)> callback)42     TestBuffersConsumerListener(const sptr<IConsumerSurface>& 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     }
70 
71 private:
72     std::function<void(void*, uint32_t)> callback_;
73     sptr<IConsumerSurface> consumer_;
74 };
75 
76 class StreamCustomer {
77 public:
78     StreamCustomer();
79     ~StreamCustomer();
80     sptr<OHOS::IBufferProducer> CreateProducer(CaptureMode mode, const std::function<void(void*, uint32_t)> callback);
81 
82 private:
83     sptr<OHOS::IConsumerSurface> consumer_ = nullptr;
84 };
85 
86 } // namespace OHOS::DistributedHardware
87 }
88 #endif // DISTRIBUTED_STREAM_CUSTOMER_H