成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

OH-v3.0-LTS Camera相機(jī)驅(qū)動(dòng)框架(L2)解析之創(chuàng)建流

原創(chuàng)
系統(tǒng) OpenHarmony
本篇接著上章的代碼繼續(xù)往下看,將創(chuàng)建好的StreamInfo作為參數(shù)丟給StreamOperator進(jìn)行流的創(chuàng)建

??想了解更多內(nèi)容,請(qǐng)?jiān)L問(wèn):??

??51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)??

??https://harmonyos.51cto.com??

接著上章的代碼繼續(xù)往下看,將創(chuàng)建好的StreamInfo作為參數(shù)丟給StreamOperator進(jìn)行流的創(chuàng)建

程序調(diào)用流程圖

1. StreamOperator::CreateStreams()

創(chuàng)建過(guò)程

  • 實(shí)例化一個(gè)stream對(duì)象,用stremInfos中的參數(shù)信息對(duì)相關(guān)成員進(jìn)行賦值。
  • 創(chuàng)建一個(gè)StreamTunnel對(duì)象,把StreamTunnel和stream進(jìn)行綁定。
  • 把創(chuàng)建好的每一個(gè)stream 對(duì)應(yīng)它的stremId 放在 streamMap_里。
//drivers\peripheral\camera\hal\hdi_impl\src\stream_operator\stream_operator.cpp
CamRetCode StreamOperator::CreateStreams(const std::vector<std::shared_ptr<StreamInfo>>& streamInfos)
{
...
for (auto it : streamInfos) {
...

std::shared_ptr<IStream> stream = StreamFactory::Instance().CreateShared(
IStream::g_avaliableStreamType[it->intent_], it->streamId_, it->intent_, pipelineCore_, messenger_);

...

StreamConfiguration scg;
scg.id = it->streamId_;
scg.type = it->intent_;
scg.width = it->width_;
scg.height = it->height_;
PixelFormat pf = static_cast<PixelFormat>(it->format_);
scg.format = BufferAdapter::PixelFormatToCameraFormat(pf);
scg.dataspace = it->datasapce_; // fix misspell
scg.tunnelMode = it->tunneledMode_;
scg.minFrameDuration = it->minFrameDuration_;
scg.encodeType = it->encodeType_;

RetCode rc = stream->ConfigStream(scg);

...

if (it->bufferQueue_ != nullptr) {
auto tunnel = std::make_shared<StreamTunnel>();
CHECK_IF_PTR_NULL_RETURN_VALUE(tunnel, INSUFFICIENT_RESOURCES);
RetCode rc = tunnel->AttachBufferQueue(it->bufferQueue_);
CHECK_IF_NOT_EQUAL_RETURN_VALUE(rc, RC_OK, INVALID_ARGUMENT);
if (stream->AttachStreamTunnel(tunnel) != RC_OK) {
CAMERA_LOGE("attach buffer queue to stream [id = %{public}d] failed", it->streamId_);
return INVALID_ARGUMENT;
}
}
{
std::lock_guard<std::mutex> l(streamLock_);
streamMap_[stream->GetStreamId()] = stream;
}
}
return NO_ERROR;
}

這里需要注意的一個(gè)地方RetCode rc = tunnel->AttachBufferQueue(it->bufferQueue_);單獨(dú)把這個(gè)代碼帖出來(lái)看下

//drivers\peripheral\camera\hal\hdi_impl\src\stream_operator\stream_tunnel.cpp
RetCode StreamTunnel::AttachBufferQueue(OHOS::sptr<OHOS::IBufferProducer>& producer)
{
CHECK_IF_PTR_NULL_RETURN_VALUE(producer, RC_ERROR);
bufferQueue_ = OHOS::Surface::CreateSurfaceAsProducer(producer); //Buffer的生產(chǎn)者使用該函數(shù)創(chuàng)建一個(gè)Surface,只能使用與生產(chǎn)相關(guān)的接口
CHECK_IF_PTR_NULL_RETURN_VALUE(bufferQueue_, RC_ERROR);
return RC_OK;
}

這個(gè)成員函數(shù)的作用就是把應(yīng)用層中的StreamCustomer::CreateProducer()獲取的producer作為參數(shù)創(chuàng)建與“消費(fèi)者”對(duì)應(yīng)的“生成型”Surface。 而StreamTunnel類(lèi)就是對(duì)這個(gè)生成型Surface的一個(gè)功能封裝。

2. StreamOperator::CommitStreams()

源碼有點(diǎn)長(zhǎng) 去掉一些參數(shù)的校驗(yàn)和準(zhǔn)備相關(guān)的代碼

一共調(diào)用 StreamBase::CommitStream() 、StreamPipelineCore::PreConfig()、StreamPipelineCore::CreatePipeline()三個(gè)函數(shù)

下面一個(gè)個(gè)來(lái)看

//drivers\peripheral\camera\hal\hdi_impl\src\stream_operator\stream_operator.cpp
CamRetCode StreamOperator::CommitStreams(OperationMode mode,
const std::shared_ptr<CameraStandard::CameraMetadata>& modeSetting)
{
...
{
std::lock_guard<std::mutex> l(streamLock_);
for (auto it : streamMap_) {
if (it.second->CommitStream() != RC_OK) {
CAMERA_LOGE("commit stream [id = %{public}d] failed.", it.first);
return DEVICE_ERROR;
}
}
}
RetCode rc = streamPipeline_->PreConfig(modeSetting);
if (rc != RC_OK) {
CAMERA_LOGE("prepare mode settings failed");
return DEVICE_ERROR;
}
rc = streamPipeline_->CreatePipeline(mode);
if (rc != RC_OK) {
CAMERA_LOGE("create pipeline failed.");
return INVALID_ARGUMENT;
}

DFX_LOCAL_HITRACE_END;
return NO_ERROR;
}

2.1 StreamBase::CommitStream()

按照代碼LOG中的說(shuō)明commit a stream to pipeline。大家可以自行理解,本人的理解是

  • 通過(guò)BufferManager創(chuàng)建并初始化BufferPool 數(shù)據(jù)緩存池
  • 給這個(gè)Stream對(duì)應(yīng)的pipeline 創(chuàng)建一個(gè)StreamMgr,讓pipeline可以通過(guò)StreamMgr對(duì)Stream進(jìn)行對(duì)應(yīng)的控制。
//drivers\peripheral\camera\hal\hdi_impl\src\stream_operator\stream_base.cpp
RetCode StreamBase::CommitStream()
{
...

HostStreamInfo info;
info.type_ = static_cast<StreamIntent>(streamType_);
info.streamId_ = streamId_;
info.width_ = streamConfig_.width;
info.height_ = streamConfig_.height;
info.format_ = streamConfig_.format;
info.usage_ = streamConfig_.usage;
info.encodeType_ = streamConfig_.encodeType;

if (streamConfig_.tunnelMode) {
BufferManager* mgr = BufferManager::GetInstance();
CHECK_IF_PTR_NULL_RETURN_VALUE(mgr, RC_ERROR);

if (bufferPool_ == nullptr) {
poolId_ = mgr->GenerateBufferPoolId();
CHECK_IF_EQUAL_RETURN_VALUE(poolId_, 0, RC_ERROR);

bufferPool_ = mgr->GetBufferPool(poolId_);
if (bufferPool_ == nullptr) {
CAMERA_LOGE("stream [id:%{public}d] get buffer pool failed.", streamId_);
return RC_ERROR;
}
}

info.bufferPoolId_ = poolId_;
info.bufferCount_ = GetBufferCount();
RetCode rc = bufferPool_->Init(streamConfig_.width, streamConfig_.height, streamConfig_.usage,
streamConfig_.format, GetBufferCount(), CAMERA_BUFFER_SOURCE_TYPE_EXTERNAL);
if (rc != RC_OK) {
CAMERA_LOGE("stream [id:%{public}d] initialize buffer pool failed.", streamId_);
return RC_ERROR;
}
}

RetCode rc = hostStreamMgr_->CreateHostStream(info, [this](std::shared_ptr<IBuffer> buffer) {
HandleResult(buffer);
return;
});

...

return RC_OK;
}

2.2 StreamPipelineCore::PreConfig()

這里的代碼比較簡(jiǎn)單,根據(jù)參數(shù)信息,調(diào)用deviceManager的PreConfig接口從來(lái)配置下面的硬件設(shè)備。

deviceManager在前面PowerUp的解析已經(jīng)說(shuō)明了,Hi3516實(shí)際上是將硬件適配層相關(guān)的代碼都封閉在了so里面,

所以這里實(shí)際調(diào)用就一行代碼sysObject_->PreConfig(meta, settings);

//drivers\peripheral\camera\hal\pipeline_core\pipeline_impl\src\stream_pipeline_core.cpp
RetCode StreamPipelineCore::PreConfig(const ModeMeta& meta)
{
auto deviceManager = IDeviceManager::GetInstance();
CHECK_IF_PTR_NULL_RETURN_VALUE(deviceManager, RC_ERROR);

std::vector<DeviceStreamSetting> settings = {};
std::vector<int32_t> ids = {};
context_->streamMgr_->GetStreamIds(ids);
for (auto i : ids) {
auto info = context_->streamMgr_->GetStreamInfo(i);
DeviceStreamSetting setting = {info.streamId_, info.bufferCount_, info.width_, info.height_,
info.format_, info.usage_, static_cast<CameraEncodeType>(info.encodeType_)};
settings.emplace_back(setting);
}
return deviceManager->PreConfig(meta, settings);
}

2.3 StreamPipelineCore::CreatePipeline()

有關(guān)stategy、builder、dispatcher實(shí)現(xiàn)的函數(shù)代碼比較多,大家感興趣自行閱讀??偟恼f(shuō)一下整體功能:

  • StreamPipelineStrategy 負(fù)責(zé)根據(jù)mode從對(duì)應(yīng)的配置文件中創(chuàng)建pipeline。
  • StreamPipelineBuilder 負(fù)責(zé)創(chuàng)建Node并鏈接
  • StreamPipelineDispatcher 負(fù)責(zé)管理創(chuàng)建好的pipeline
  • 最終建立的StreamPipeline是由Node(節(jié)點(diǎn))組成,Node(節(jié)點(diǎn))由Port(端口)組成。Port(端口)分為in端口和out端口(可以有多個(gè))。out鏈接in最終構(gòu)建出整個(gè)StreamPipeline

Demo案例建立了兩個(gè)streamPipeline

//drivers\peripheral\camera\hal\pipeline_core\pipeline_impl\src\stream_pipeline_core.cpp
RetCode StreamPipelineCore::CreatePipeline(const int32_t& mode)
{
std::lock_guard<std::mutex> l(mutex_);
std::shared_ptr<PipelineSpec> spec = strategy_->GeneratePipelineSpec(mode);
if (spec == nullptr) {
return RC_ERROR;
}
std::shared_ptr<Pipeline> pipeline = builder_->Build(spec);
if (pipeline == nullptr) {
return RC_ERROR;
}
return dispatcher_->Update(pipeline);
}

需要注意幾個(gè)問(wèn)題

  1. pipeline的配置文件在drivers\peripheral\camera\hal\pipeline_core\pipeline_impl\src\strategy\config目錄下的config.c和params.c
  2. 這兩個(gè)文件是由BUILD.gn 腳本生成的。
//drivers\peripheral\camera\hal\adapter\chipset\hispark_taurus\BUILD.gn
source =
"$camera_path/pipeline_core/pipeline_impl/src/strategy/config/config.c"
exec_script(
"http://drivers/framework/tools/hc-gen/build_hcs.py",
[
"-o",
rebase_path(
"$camera_path/pipeline_core/pipeline_impl/src/strategy/config/config.c"),
"-t",
rebase_path(
"http://vendor/hisilicon/Hi3516DV300/hdf_config/uhdf/camera/hal/mpp/hispark_taurus/pipeline_core/config.hcs"),
],
"")
}

ohos_prebuilt_etc("params.c") {
source =
"$camera_path/pipeline_core/pipeline_impl/src/strategy/config/params.c"
exec_script(
"http://drivers/framework/tools/hc-gen/build_hcs.py",
[
"-o",
rebase_path(
"$camera_path/pipeline_core/pipeline_impl/src/strategy/config/params.c"),
"-t",
rebase_path(
"http://vendor/hisilicon/Hi3516DV300/hdf_config/uhdf/camera/hal/mpp/hispark_taurus/pipeline_core/params.hcs"),
],
"")
}

3. 小結(jié)

到此流的創(chuàng)建也完成了,最后一章節(jié)會(huì)把圖像采集的代碼講解完。

??想了解更多內(nèi)容,請(qǐng)?jiān)L問(wèn):??

??51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)??

??https://harmonyos.51cto.com??

責(zé)任編輯:jianghua 來(lái)源: 鴻蒙社區(qū)
相關(guān)推薦

2022-02-25 15:33:45

圖像采集鴻蒙Camera相機(jī)

2022-02-08 15:07:45

OpenHarmor鴻蒙操作系統(tǒng)

2022-01-06 16:16:21

鴻蒙HarmonyOS應(yīng)用

2022-02-21 15:38:57

Openharmon操作系統(tǒng)鴻蒙

2022-02-17 16:47:40

OpenharmonIPC通信鴻蒙

2014-11-25 13:28:17

openstackneutronDVR

2022-06-22 09:14:23

事件打點(diǎn)HiSysEvent

2021-10-20 19:14:30

緩存CacheCPU

2022-04-21 11:26:31

鴻蒙操作系統(tǒng)

2015-01-20 13:19:52

OpenStack網(wǎng)絡(luò)層數(shù)據(jù)鏈路層

2023-11-27 08:21:49

Camera2API,

2023-02-13 15:54:49

2022-07-04 16:41:16

IPC通信HiTrace

2021-11-01 17:31:21

Camera2 相機(jī)開(kāi)發(fā)

2022-07-14 19:03:33

IPC服務(wù)鴻蒙

2023-01-31 09:12:16

CPU芯片緩存

2021-10-27 11:29:49

Linux框架內(nèi)核

2023-02-20 08:00:00

2023-10-10 15:33:55

機(jī)器學(xué)習(xí)相似性度量

2022-08-26 14:58:43

區(qū)塊鏈比特幣架構(gòu)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: 99国产在线| 国产区精品在线观看 | 国产精品美女一区二区 | 亚洲国产情侣 | 国产乱码精品一区二区三区五月婷 | 色性av| 国产精品一区在线 | 日韩午夜场 | 在线中文字幕第一页 | 精品九九 | 天天干天天爱天天 | 亚洲精品福利视频 | 最新av在线网址 | 欧美日产国产成人免费图片 | 欧美精品一二区 | 精品成人在线视频 | 免费国产一区二区 | 日本电影一区二区 | 青青艹在线视频 | 99精品免费 | 日韩精品av一区二区三区 | 日本不卡一区二区 | 久久精品中文字幕 | 欧美成人免费在线视频 | 韩国成人在线视频 | 亚洲精品av在线 | 做a视频 | 中文字幕国产精品 | 亚洲成人久久久 | 婷婷亚洲综合 | 特黄视频| 久久国产成人午夜av影院武则天 | 国产乱码精品一区二区三区av | 成人国产在线观看 | 日韩精品免费视频 | 免费视频一区二区 | av一级久久| 综合久久亚洲 | 日韩视频1 | 一区二区三区四区在线视频 | 不卡一区 |