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