hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2019 Fuzhou Rockchip Electronics Co., Ltd. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
 
#ifndef EASYMEDIA_MEDIA_REFLECTOR_H_
#define EASYMEDIA_MEDIA_REFLECTOR_H_
 
#include <algorithm>
 
#include "key_string.h"
#include "reflector.h"
 
#define DEFINE_MEDIA_CHILD_FACTORY(REAL_PRODUCT, IDENTIFIER, FINAL_EXPOSE_PRODUCT, PRODUCT)                            \
    DEFINE_CHILD_FACTORY(REAL_PRODUCT, IDENTIFIER, FINAL_EXPOSE_PRODUCT, PRODUCT,                                      \
                                                                                                                       \
                         public                                                                                        \
                         :                                                                                             \
                                                                                                                       \
                         virtual bool AcceptRules(const std::map<std::string, std::string>& map) const override;       \
                                                                                                                       \
                         /* common type: "video", "audio", "image", "stream", etc.                                     \
                            Even "video && audio".                                                                     \
                            Empty "" means any type while nullptr means nothing.                                       \
                            self-defined type: "video:h264", etc.                                                      \
                            more ref to media_type.h */                                                                \
                         static const char* ExpectedInputDataType(); static const char* OutPutDataType();              \
                                                                                                                       \
    )
 
#define DEFINE_MEDIA_CHILD_FACTORY_EXTRA(REAL_PRODUCT)                                                                 \
    bool REAL_PRODUCT##Factory::AcceptRules(const std::map<std::string, std::string>& map) const                       \
    {                                                                                                                  \
        static std::list<std::string> expected_data_type_list;                                                         \
        static std::list<std::string> out_data_type_list;                                                              \
        static const char* static_keys[] = {KEY_INPUTDATATYPE, KEY_OUTPUTDATATYPE, NULL};                              \
        static const decltype(ExpectedInputDataType)* static_call[] = {&ExpectedInputDataType, &OutPutDataType, NULL}; \
        static std::list<std::string>* static_list[] = {&expected_data_type_list, &out_data_type_list, NULL};          \
        const char** keys = static_keys;                                                                               \
        const decltype(ExpectedInputDataType)** call = static_call;                                                    \
        std::list<std::string>** list = static_list;                                                                   \
        while (*keys) {                                                                                                \
            auto it = map.find(*keys);                                                                                 \
            if (it == map.end()) {                                                                                     \
                if ((*call)())                                                                                         \
                    return false;                                                                                      \
            } else {                                                                                                   \
                const std::string& value = it->second;                                                                 \
                if (!value.empty() && !has_intersection(value.c_str(), (*call)(), *list))                              \
                    return false;                                                                                      \
            }                                                                                                          \
            ++keys;                                                                                                    \
            ++call;                                                                                                    \
            ++list;                                                                                                    \
        }                                                                                                              \
        return true;                                                                                                   \
    }
 
#define DEFINE_MEDIA_NEW_PRODUCT_BY(REAL_PRODUCT, PRODUCT, COND)                                                       \
    std::shared_ptr<PRODUCT> FACTORY(REAL_PRODUCT)::NewProduct(const char* param)                                      \
    {                                                                                                                  \
        auto ret = std::make_shared<REAL_PRODUCT>(param);                                                              \
        if (ret && ret->COND)                                                                                          \
            return nullptr;                                                                                            \
        return ret;                                                                                                    \
    }
 
#endif // #ifndef EASYMEDIA_MEDIA_REFLECTOR_H_