1094332d3Sopenharmony_ci/* 2094332d3Sopenharmony_ci * Copyright (c) 2022 - 2023 Huawei Device Co., Ltd. 3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License. 5094332d3Sopenharmony_ci * You may obtain a copy of the License at 6094332d3Sopenharmony_ci * 7094332d3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8094332d3Sopenharmony_ci * 9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and 13094332d3Sopenharmony_ci * limitations under the License. 14094332d3Sopenharmony_ci */ 15094332d3Sopenharmony_ci 16094332d3Sopenharmony_ci#ifndef DISTRIBUTED_STREAM_CUSTOMER_H 17094332d3Sopenharmony_ci#define DISTRIBUTED_STREAM_CUSTOMER_H 18094332d3Sopenharmony_ci 19094332d3Sopenharmony_ci#include <fstream> 20094332d3Sopenharmony_ci#include <iostream> 21094332d3Sopenharmony_ci#include <thread> 22094332d3Sopenharmony_ci#include <vector> 23094332d3Sopenharmony_ci#include <map> 24094332d3Sopenharmony_ci#include <surface.h> 25094332d3Sopenharmony_ci#include "constants.h" 26094332d3Sopenharmony_ci#include "distributed_hardware_log.h" 27094332d3Sopenharmony_ci#include "iconsumer_surface.h" 28094332d3Sopenharmony_ci#include "v1_0/ioffline_stream_operator.h" 29094332d3Sopenharmony_ci 30094332d3Sopenharmony_cinamespace OHOS { 31094332d3Sopenharmony_cinamespace DistributedHardware { 32094332d3Sopenharmony_ci 33094332d3Sopenharmony_cienum CaptureMode { 34094332d3Sopenharmony_ci CAPTURE_PREVIEW = 0, 35094332d3Sopenharmony_ci CAPTURE_SNAPSHOT, 36094332d3Sopenharmony_ci CAPTURE_VIDEO, 37094332d3Sopenharmony_ci}; 38094332d3Sopenharmony_ci 39094332d3Sopenharmony_ciclass TestBuffersConsumerListener : public IBufferConsumerListener { 40094332d3Sopenharmony_cipublic: 41094332d3Sopenharmony_ci TestBuffersConsumerListener(const sptr<IConsumerSurface>& surface, 42094332d3Sopenharmony_ci const std::function<void(void*, const uint32_t)> callback) : callback_(callback), consumer_(surface) 43094332d3Sopenharmony_ci { 44094332d3Sopenharmony_ci } 45094332d3Sopenharmony_ci 46094332d3Sopenharmony_ci ~TestBuffersConsumerListener() 47094332d3Sopenharmony_ci { 48094332d3Sopenharmony_ci } 49094332d3Sopenharmony_ci 50094332d3Sopenharmony_ci void OnBufferAvailable() 51094332d3Sopenharmony_ci { 52094332d3Sopenharmony_ci DHLOGI("demo test:enter OnBufferAvailable start"); 53094332d3Sopenharmony_ci OHOS::Rect damage; 54094332d3Sopenharmony_ci int32_t flushFence = 0; 55094332d3Sopenharmony_ci int64_t timestamp = 0; 56094332d3Sopenharmony_ci 57094332d3Sopenharmony_ci OHOS::sptr<OHOS::SurfaceBuffer> buff = nullptr; 58094332d3Sopenharmony_ci consumer_->AcquireBuffer(buff, flushFence, timestamp, damage); 59094332d3Sopenharmony_ci if (buff != nullptr) { 60094332d3Sopenharmony_ci void* addr = buff->GetVirAddr(); 61094332d3Sopenharmony_ci if (callback_ != nullptr) { 62094332d3Sopenharmony_ci int32_t size = buff->GetSize(); 63094332d3Sopenharmony_ci callback_(addr, size); 64094332d3Sopenharmony_ci } 65094332d3Sopenharmony_ci consumer_->ReleaseBuffer(buff, -1); 66094332d3Sopenharmony_ci DHLOGI("demo test:Exiting OnBufferAvailable end"); 67094332d3Sopenharmony_ci } 68094332d3Sopenharmony_ci } 69094332d3Sopenharmony_ci 70094332d3Sopenharmony_ciprivate: 71094332d3Sopenharmony_ci std::function<void(void*, uint32_t)> callback_; 72094332d3Sopenharmony_ci sptr<IConsumerSurface> consumer_; 73094332d3Sopenharmony_ci}; 74094332d3Sopenharmony_ci 75094332d3Sopenharmony_ciclass StreamCustomer { 76094332d3Sopenharmony_cipublic: 77094332d3Sopenharmony_ci StreamCustomer(); 78094332d3Sopenharmony_ci ~StreamCustomer(); 79094332d3Sopenharmony_ci sptr<OHOS::IBufferProducer> CreateProducer(CaptureMode mode, const std::function<void(void*, uint32_t)> callback); 80094332d3Sopenharmony_ci 81094332d3Sopenharmony_ciprivate: 82094332d3Sopenharmony_ci sptr<OHOS::IConsumerSurface> consumer_ = nullptr; 83094332d3Sopenharmony_ci}; 84094332d3Sopenharmony_ci 85094332d3Sopenharmony_ci} // namespace OHOS::DistributedHardware 86094332d3Sopenharmony_ci} 87094332d3Sopenharmony_ci#endif // DISTRIBUTED_STREAM_CUSTOMER_H