SfxDecoder.cpp
3.35 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include "SfxDecoder.h"
#include <thread>
#include <chrono>
#include "sfx_depend_inc.h"
using namespace std;
SfxDecoder::SfxDecoder( )
{
memset( &m_video, 0, sizeof( DxVideoConfig ) );
m_handler = sfx_null;
return;
}
SfxDecoder::~SfxDecoder()
{
LOG_INFO( "[{}]-free SfxDecoder..", m_dec_name);
if ( sfx_null != m_handler )
{
SfxStreamHandlerInterface::SfxReleaseInstance( m_handler );
m_handler = sfx_null;
}
return;
}
bool SfxDecoder::OpenDecoder(DxDecoderConfig& cfg)
{
m_cfg = cfg;
SfxStreamHandlerConfig* sfx_cfg = new SfxStreamHandlerConfig();
sfx_cfg->userPtr = this;
sfx_cfg->escb = SfxStreamCallback;
sfx_cfg->log = SfxLogDefaultHandler;
sfx_cfg->flags.outFrameIndex = 1;
sfx_cfg->flags.preposeFrameCount = 1;
sfx_cfg->flags.useFastDecode = 0;
sfx_cfg->flags.accelId = m_cfg.devId;
sfx_cfg->flags.frameNumber = 1;
sfx_cfg->flags.fmt = SFX_VIDEO_FORMAT_NV12U8;
//sfx_cfg->flags.fmt = SFX_VIDEO_FORMAT_C3BGRU8;
m_handler = SfxStreamHandlerInterface::SfxGetInstance(sfx_cfg);
m_dec_name = m_cfg.dec_name;
int nRet = m_handler->SfxOpenStreamHandler( m_cfg.uri.c_str() );
if (nRet != 0) {
m_bRun = false;
LOG_INFO( "[{}]-OpenDecoder failed!", m_dec_name);
return false;
}
m_bRun = true;
return true;
}
int SfxDecoder::CloseDecoder()
{
m_handler->SfxCloseStreamHandler();
while (m_bRun)
{
std::this_thread::sleep_for(std::chrono::milliseconds(250));
}
return 0;
}
bool SfxDecoder::isFinished() {
return !m_bRun;
}
unsigned int SfxDecoder::GetFrameCount() {
return m_video.frame_count;
}
sfx_32 SfxDecoder::SfxStreamCallback(
const sfx_void * userPtr,
SfxFrameType type,
const sfx_u8 * buf,
sfx_u32 segLen,
sfx_u32 len,
sfx_u32 timestamp
)
{
SfxDecoder * pThis = sfx_null;
pThis = ( SfxDecoder * )userPtr;
if (!pThis->m_bRun)
{
return 0;
}
if ( SFX_FRAME_TYPE_CONFIG == type )
{
if (pThis->m_handler) {
SfxStreamHandlerConfigInterface *sc = nullptr;
pThis->m_handler->SfxQueryInterface(SFX_STREAM_HANDLER_CONFIG_INTERFACE, ( sfx_void ** )&sc);
if (sc) {
pThis->m_video.frame_count = sc->SfxGetFrameNumber();
}
}
pThis->m_video.height = ( ( SfxMediaConfig * )buf )->v.height;
pThis->m_video.width = ( ( SfxMediaConfig * )buf )->v.width;
pThis->m_cfg.escbk( pThis->m_cfg.userPtr, &pThis->m_video, 0, pThis->m_video.width, pThis->m_video.height, timestamp);
return 0;
}
pThis->m_cfg.escbk( pThis->m_cfg.userPtr, ( void * )buf, segLen, pThis->m_video.width, pThis->m_video.height, timestamp);
return 0;
}
sfx_32 SfxDecoder::SfxLogDefaultHandler(
const sfx_void * userPtr,
SfxLogLevel level,
const sfx_8 * log,
sfx_u32 logLen
)
{
SfxDecoder * pThis = sfx_null;
pThis = ( SfxDecoder * )userPtr;
if ( SFX_LOG_LEVEL_IMPORTANT == level) //modify by zsh 220602
{
pThis->m_cfg.logcbk( pThis->m_cfg.userPtr, DX_LOG_LEVEL_IMPORTANT, log, 0 );
return 0;
}
if ( SFX_LOG_LEVEL_CLEANUP == level )
{
pThis->m_bRun = sfx_false;
if ( pThis->m_cfg.logcbk )
{
pThis->m_cfg.logcbk(
pThis->m_cfg.userPtr,
DX_LOG_LEVEL_CLEANUP,
"DxDecoder[CUDA] module exited..",
0
);
}
}
return 0;
}