1 /*
2 * Copyright (c) 2022-2024 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 #include "stream_customer.h"
17 #include "distributed_hardware_log.h"
18
19 namespace OHOS {
20 namespace DistributedHardware {
StreamCustomer()21 StreamCustomer::StreamCustomer() {}
~StreamCustomer()22 StreamCustomer::~StreamCustomer() {}
23
CreateProducer(CaptureMode mode,const std::function<void (void *,uint32_t)> callback)24 sptr<OHOS::IBufferProducer> StreamCustomer::CreateProducer(CaptureMode mode,
25 const std::function<void(void*, uint32_t)> callback)
26 {
27 consumer_ = OHOS::IConsumerSurface::Create();
28 if (consumer_ == nullptr) {
29 return nullptr;
30 }
31 sptr<IBufferConsumerListener> listener = nullptr;
32 if (mode == CAPTURE_SNAPSHOT) {
33 listener = new TestBuffersConsumerListener(consumer_, callback);
34 } else if (mode == CAPTURE_VIDEO) {
35 listener = new TestBuffersConsumerListener(consumer_, callback);
36 }
37 consumer_->RegisterConsumerListener(listener);
38
39 auto producer = consumer_->GetProducer();
40 if (producer == nullptr) {
41 return nullptr;
42 }
43
44 DHLOGI("demo test, create a buffer queue producer %{public}p", producer.GetRefPtr());
45 return producer;
46 }
47 }
48 }