hc
2023-03-13 2ec15ae1cb4be1b4fcb56c6d621123d7ebdaad6c
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * Copyright 2020 Rockchip Electronics Co. LTD
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
 
#ifndef SRC_RT_TASK_TASK_GRAPH_RTTASKNODECONTEXT_H_
#define SRC_RT_TASK_TASK_GRAPH_RTTASKNODECONTEXT_H_
 
#include <string>
#include <vector>
#include <list>
#include <memory>
#include <map>
 
#include "rt_header.h"
#include "rt_metadata.h"
#include "RTStreamInfo.h"
 
class RTMediaBuffer;
class RTBufferListener;
class RTOutputStreamShared;
class RTMediaBufferPool;
class RTTaskNodeStat;
class RTTaskNodeContext {
 public:
    explicit RTTaskNodeContext(
            std::string nodeName,
            INT32 nodeId,
            std::vector<RTStreamInfo *> *inputInfos,
            std::vector<RTStreamInfo *> *outputInfos);
    ~RTTaskNodeContext();
 
    RTTaskNodeContext(const RTTaskNodeContext&) = delete;
    RTTaskNodeContext& operator=(const RTTaskNodeContext&) = delete;
 
    RT_RET              prepareForRun(RtMetaData* options);
    RT_RET              cleanupAfterRun();
 
    const std::string&  nodeName() const { return mNodeName; }
    INT32               nodeId() const { return mNodeId; }
    void                suspend() { mSuspend = true; }
    void                resume() { mSuspend = false; }
    RT_RET              flush();
    bool                isSuspend() { return mSuspend; }
    RtMetaData*         options() { return mOptions; }
    void                sendInterrupt(std::string reason);
    void                cancelInterrupt(std::string reason);
    void                setOutputBufferListener(RTBufferListener *listener);
    void                setMaxBatchPrcoessSize(INT32 maxBatchSize);
    INT32               getMaxBatchPrcoessSize();
 
    RTStreamInfo*       getInputInfo(std::string streamType = "none");
    RTStreamInfo*       getOutputInfo(std::string streamType = "none");
 
    RT_RET              getPackets(std::list<RTMediaBuffer *> *packets, std::string streamType = "none");
 
    RT_BOOL             hasInputStream(std::string streamType = "none");
    RT_BOOL             hasOutputStream(std::string streamType = "none");
    INT32               inputQueueSize(std::string streamType = "none");
    RT_BOOL             inputIsEmpty(std::string streamType = "none");
    RT_BOOL             outputIsEmpty(std::string streamType = "none");
 
    RTMediaBuffer*      inputHeadBuffer(std::string streamType = "none");
    RTMediaBuffer*      dequeInputBuffer(std::string streamType = "none");
    RT_RET              queueInputBuffer(RTMediaBuffer *packet, std::string streamTpye = "none");
    RTMediaBuffer*      dequeOutputBuffer(RT_BOOL block = RT_TRUE,
                                           UINT32 size = 0,
                                           std::string streamType = "none");
    RT_RET              queueOutputBuffer(RTMediaBuffer *packet, std::string streamType = "none");
    RT_RET              getBufferStat(RTTaskNodeStat *stat);
 
    RT_RET              reallocOutputBuffers(INT32 wantSize, std::string streamType = "none");
 
    RT_RET              attachOutStreamPool(RTMediaBufferPool *pool, std::string streamType = "none");
    RT_RET              detachOutStreamPool(std::string streamType = "none");
    RT_RET              pollOutputBuffer(RT_BOOL block = RT_TRUE,
                                          UINT32 size = 0,
                                          std::string streamType = "none");
    INT32               getOutputBufferSize(std::string streamType = "none");
 
    RT_RET              dump();
 
 private:
    std::vector<RTMediaBuffer *>*   inputs(std::string streamType = "none");
    RTOutputStreamShared*           outputs(std::string streamType = "none");
 
 private:
    std::map<std::string, std::vector<RTMediaBuffer *>> mInputs;
    std::map<std::string, RTOutputStreamShared *>       mOutputs;
    RtMetaData                     *mOptions;
    INT32                           mNodeId;
    std::string                     mNodeName;
    bool                            mSuspend = false;
    INT32                           mMaxBatchProcessSize = 4;
    std::vector<RTStreamInfo *>    *mInputInfos;
    std::vector<RTStreamInfo *>    *mOutputInfos;
    RtMutex                         mInputMutex;
};
 
#endif  // SRC_RT_TASK_TASK_GRAPH_RTTASKNODECONTEXT_H_