NVIDIA DeepStream SDK API Reference

9.1 Release
sources/includes/ds3d/common/impl/impl_dataloader.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2021-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef _DS3D_COMMON_IMPL_BASE_IDATALOADER__H
19 #define _DS3D_COMMON_IMPL_BASE_IDATALOADER__H
20 
21 #include "ds3d/common/hpp/datamap.hpp"
22 #include "ds3d/common/impl/impl_dataprocess.h"
23 
24 namespace ds3d { namespace impl {
25 
40 class BaseImplDataLoader : public BaseImplDataProcessor<abiDataLoader> {
41 public:
43  ~BaseImplDataLoader() override = default;
44 
45  ErrCode readData_i(abiRefDataMap*& datamap) final
46  {
47  DS_ASSERT(!datamap);
49  getStateSafe() == State::kRunning, ErrCode::kState, "dataloader is not started");
50  GuardDataMap data;
51  ErrCode code = readDataImpl(data);
52  datamap = data.release();
53  return code;
54  }
55  ErrCode readDataAsync_i(const abiOnDataCB* dataReadyCb) final
56  {
58  getStateSafe() == State::kRunning, ErrCode::kState, "dataloader is not started");
59 
60  GuardCB<abiOnDataCB> guardCb(dataReadyCb ? dataReadyCb->refCopy() : nullptr);
61  OnGuardDataCBImpl readyCB = [guardCb = std::move(guardCb), this](
62  ErrCode code, GuardDataMap data) {
63  guardCb(code, data.abiRef());
64  };
65  return readDataAsyncImpl(std::move(readyCB));
66  }
67 
68 protected:
69  // cplusplus virtual interface, user need to derive from
70  virtual ErrCode readDataImpl(GuardDataMap& datamap) = 0;
71  virtual ErrCode readDataAsyncImpl(OnGuardDataCBImpl dataReadCB) = 0;
72 };
73 
75 protected:
76  SyncImplDataLoader() = default;
78  ErrCode flushImpl() override { return ErrCode::kGood; }
79 };
80 
81 }} // namespace ds3d::impl
82 
83 #endif // _DS3D_COMMON_IMPL_BASE_IDATALOADER__H
ds3d::impl::SyncImplDataLoader::readDataAsyncImpl
ErrCode readDataAsyncImpl(OnGuardDataCBImpl dataReadCB) final
Definition: sources/includes/ds3d/common/impl/impl_dataloader.h:77
ds3d::impl::BaseImplDataLoader::readDataImpl
virtual ErrCode readDataImpl(GuardDataMap &datamap)=0
ds3d::ErrCode::kUnsupported
@ kUnsupported
ds3d::impl::BaseImplDataLoader
Any custom dataloader must derive from BaseImplDataLoader, For convenience, If dataloader is in sync ...
Definition: sources/includes/ds3d/common/impl/impl_dataloader.h:40
ds3d::impl::SyncImplDataLoader
Definition: sources/includes/ds3d/common/impl/impl_dataloader.h:74
DS3D_FAILED_RETURN
#define DS3D_FAILED_RETURN(condition, ret, fmt,...)
Definition: sources/includes/ds3d/common/defines.h:69
ds3d::impl::BaseImplDataLoader::readDataAsyncImpl
virtual ErrCode readDataAsyncImpl(OnGuardDataCBImpl dataReadCB)=0
ds3d::impl::BaseImplDataLoader::~BaseImplDataLoader
~BaseImplDataLoader() override=default
ds3d::ErrCode::kGood
@ kGood
ds3d::impl::BaseImplDataProcessor< abiDataLoader >::OnGuardDataCBImpl
std::function< void(ErrCode, GuardDataMap)> OnGuardDataCBImpl
Definition: sources/includes/ds3d/common/impl/impl_dataprocess.h:33
ds3d::abiRefT< abiDataMap >
ds3d::impl::BaseImplDataLoader::BaseImplDataLoader
BaseImplDataLoader()
Definition: sources/includes/ds3d/common/impl/impl_dataloader.h:42
DS_ASSERT
#define DS_ASSERT(...)
Definition: sources/includes/ds3d/common/defines.h:36
ds3d::ErrCode
ErrCode
Definition: sources/includes/ds3d/common/common.h:47
ds3d::impl::SyncImplDataLoader::SyncImplDataLoader
SyncImplDataLoader()=default
ds3d::impl::BaseImplDataProcessor< abiDataLoader >::getStateSafe
State getStateSafe() const
Definition: sources/includes/ds3d/common/impl/impl_dataprocess.h:116
ds3d::impl::BaseImplDataProcessor
BaseProcessIF could be abiDataLoader/abiDataRender/abiDataFilter or any others abi interface that der...
Definition: sources/includes/ds3d/common/impl/impl_dataprocess.h:31
ds3d::GuardRef::release
ref * release()
Definition: sources/includes/ds3d/common/hpp/obj.hpp:257
ds3d::impl::SyncImplDataLoader::flushImpl
ErrCode flushImpl() override
Definition: sources/includes/ds3d/common/impl/impl_dataloader.h:78
ds3d::GuardDataMap
Definition: sources/includes/ds3d/common/hpp/datamap.hpp:27
ds3d::impl::BaseImplDataLoader::readDataAsync_i
ErrCode readDataAsync_i(const abiOnDataCB *dataReadyCb) final
Definition: sources/includes/ds3d/common/impl/impl_dataloader.h:55
ds3d::State::kRunning
@ kRunning
ds3d::impl::BaseImplDataLoader::readData_i
ErrCode readData_i(abiRefDataMap *&datamap) final
Definition: sources/includes/ds3d/common/impl/impl_dataloader.h:45
ds3d
Definition: sources/includes/ds3d/common/abi_dataprocess.h:25
ds3d::abiCallBackT
Definition: sources/includes/ds3d/common/abi_obj.h:75
ds3d::ErrCode::kState
@ kState
ds3d::GuardCB
Definition: sources/includes/ds3d/common/hpp/obj.hpp:289