1 #ifndef _NNDEPLOY_CODEC_CODEC_H_
2 #define _NNDEPLOY_CODEC_CODEC_H_
25 Decode(
const std::string &name) : dag::Node(name) {
27 this->addRequiredParam(
"path_");
29 Decode(
const std::string &name, std::vector<dag::Edge *> inputs,
30 std::vector<dag::Edge *> outputs)
45 this->addRequiredParam(
"path_");
51 this->addRequiredParam(
"path_");
53 Decode(
const std::string &name, std::vector<dag::Edge *> inputs,
71 this->addRequiredParam(
"path_");
106 if (loop_count > 0) {
107 loop_count_ = loop_count;
116 rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator) {
124 json.AddMember(
"path_", rapidjson::Value(path_.c_str(), allocator),
143 if (json.HasMember(
"size_") && json[
"size_"].IsInt()) {
144 int size = json[
"size_"].GetInt();
161 if (json.HasMember(
"path_") && json[
"path_"].IsString()) {
162 std::string path = json[
"path_"].GetString();
170 std::string path_ =
"";
171 bool path_changed_ =
false;
180 bool path_ready_ =
false;
185 Encode(
const std::string &name) : dag::Node(name) {
188 this->addRequiredParam(
"path_");
190 Encode(
const std::string &name, std::vector<dag::Edge *> inputs,
191 std::vector<dag::Edge *> outputs)
207 this->addRequiredParam(
"path_");
213 this->addRequiredParam(
"path_");
215 Encode(
const std::string &name, std::vector<dag::Edge *> inputs,
233 this->addRequiredParam(
"path_");
254 void setFourcc(
const std::string &fourcc) { fourcc_ = fourcc; }
269 rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator) {
281 json.AddMember(
"path_", rapidjson::Value(path_.c_str(), allocator),
284 json.AddMember(
"ref_path_",
285 rapidjson::Value(ref_path_.c_str(), allocator), allocator);
286 json.AddMember(
"fourcc_", rapidjson::Value(fourcc_.c_str(), allocator),
300 if (json.HasMember(
"fps_") && json[
"fps_"].IsNumber()) {
301 setFps(json[
"fps_"].GetDouble());
303 if (json.HasMember(
"width_") && json[
"width_"].IsInt()) {
304 setWidth(json[
"width_"].GetInt());
306 if (json.HasMember(
"height_") && json[
"height_"].IsInt()) {
307 setHeight(json[
"height_"].GetInt());
309 if (json.HasMember(
"size_") && json[
"size_"].IsInt()) {
310 int size = json[
"size_"].GetInt();
315 if (json.HasMember(
"fourcc_") && json[
"fourcc_"].IsString()) {
316 setFourcc(json[
"fourcc_"].GetString());
318 if (json.HasMember(
"ref_path_") && json[
"ref_path_"].IsString()) {
319 status = setRefPath(json[
"ref_path_"].GetString());
323 if (json.HasMember(
"path_") && json[
"path_"].IsString()) {
324 status = setPath(json[
"path_"].GetString());
333 std::string path_ =
"";
334 bool path_changed_ =
false;
335 std::string ref_path_ =
"";
338 std::string fourcc_ =
"avc1";
353 std::map<base::CodecType, createDecodeSharedPtrFunc> &
373 const std::string &name,
387 std::map<base::CodecType, createEncodeSharedPtrFunc> &
408 const std::string &name,
Decode(const std::string &name)
virtual base::Status run()=0
Run node (pure virtual function)
virtual base::EdgeUpdateFlag updateInput()
Update input.
std::condition_variable path_cv_
Decode(const std::string &name, std::vector< dag::Edge * > inputs, std::vector< dag::Edge * > outputs)
virtual base::Status serialize(rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator)
Serialize to JSON.
Decode(const std::string &name, base::CodecFlag flag)
Decode(const std::string &name, std::vector< dag::Edge * > inputs, std::vector< dag::Edge * > outputs, base::CodecFlag flag)
base::Status setCodecFlag(base::CodecFlag flag)
virtual base::Status deserialize(rapidjson::Value &json)
Deserialize from JSON.
void setLoopCount(int loop_count)
Set loop count.
virtual base::Status setPath(const std::string &path)=0
base::CodecFlag getCodecFlag()
void setFourcc(const std::string &fourcc)
base::Status setCodecFlag(base::CodecFlag flag)
virtual base::Status deserialize(rapidjson::Value &json)
Deserialize from JSON.
base::CodecFlag getCodecFlag()
virtual base::Status run()=0
Run node (pure virtual function)
void setHeight(int height)
Encode(const std::string &name, std::vector< dag::Edge * > inputs, std::vector< dag::Edge * > outputs)
virtual base::Status setRefPath(const std::string &ref_path)=0
Encode(const std::string &name, std::vector< dag::Edge * > inputs, std::vector< dag::Edge * > outputs, base::CodecFlag flag)
virtual base::Status serialize(rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator)
Serialize to JSON.
Encode(const std::string &name)
Encode(const std::string &name, base::CodecFlag flag)
virtual base::Status setPath(const std::string &path)=0
TypeCreatelDecodeRegister(base::CodecType type, createDecodeFunc func)
TypeCreatelDecodeSharedPtrRegister(base::CodecType type, createDecodeSharedPtrFunc func)
TypeCreatelEncodeRegister(base::CodecType type, createEncodeFunc func)
TypeCreatelEncodeSharedPtrRegister(base::CodecType type, createEncodeSharedPtrFunc func)
Edge class in DAG graph for connecting nodes and transferring data.
virtual std::string serialize()
Serialize to JSON string.
virtual base::Status deserialize(rapidjson::Value &json)
Deserialize from JSON.
#define NNDEPLOY_CC_API
api
std::string codecFlagToString(CodecFlag src)
@ kEdgeUpdateFlagComplete
@ kEdgeUpdateFlagTerminate
Encode * createEncode(base::CodecType type, base::CodecFlag flag, const std::string &name, dag::Edge *input)
Decode * createDecode(base::CodecType type, base::CodecFlag flag, const std::string &name, dag::Edge *output)
std::map< base::CodecType, createEncodeSharedPtrFunc > & getGlobalCreateEncodeSharedPtrFuncMap()
std::function< std::shared_ptr< Encode >(base::CodecFlag flag, const std::string &name, dag::Edge *input)> createEncodeSharedPtrFunc
std::function< Encode *(base::CodecFlag flag, const std::string &name, dag::Edge *input)> createEncodeFunc
std::map< base::CodecType, createDecodeSharedPtrFunc > & getGlobalCreateDecodeSharedPtrFuncMap()
std::function< std::shared_ptr< Decode >(base::CodecFlag flag, const std::string &name, dag::Edge *output)> createDecodeSharedPtrFunc
std::shared_ptr< Decode > createDecodeSharedPtr(base::CodecType type, base::CodecFlag flag, const std::string &name, dag::Edge *output)
std::map< base::CodecType, createDecodeFunc > & getGlobalCreateDecodeFuncMap()
std::function< Decode *(base::CodecFlag flag, const std::string &name, dag::Edge *output)> createDecodeFunc
std::map< base::CodecType, createEncodeFunc > & getGlobalCreateEncodeFuncMap()
std::shared_ptr< Encode > createEncodeSharedPtr(base::CodecType type, base::CodecFlag flag, const std::string &name, dag::Edge *input)
#define NNDEPLOY_RETURN_ON_NEQ(status, expected, str)