SfxDecoder.cpp
2.77 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
#include "SfxDecoder.h"
#include <thread>
#include <chrono>
using namespace std;
SfxDecoder::SfxDecoder( const DxDecoderConfig * cfg )
{
memset( &m_video, 0, sizeof( DxVideoConfig ) );
m_handler = sfx_null;
m_bRun = sfx_true;
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 = cfg->cfg.devId;
m_handler = SfxStreamHandlerInterface::SfxGetInstance(sfx_cfg);
memcpy( &m_cfg, cfg, sizeof( DxDecoderConfig ) );
printf( "alloc SfxDecoder..\n" );
return;
}
SfxDecoder::~SfxDecoder()
{
printf( "free SfxDecoder..\n" );
if ( sfx_null != m_handler )
{
SfxStreamHandlerInterface::SfxReleaseInstance( m_handler );
m_handler = sfx_null;
}
return;
}
int SfxDecoder::OpenDecoder( const char * uri )
{
return m_handler->SfxOpenStreamHandler( uri );
}
int SfxDecoder::CloseDecoder()
{
m_handler->SfxCloseStreamHandler();
while (m_bRun)
{
//sfxSleepMs(250); //220729
std::this_thread::sleep_for(std::chrono::milliseconds(250));
}
return 0;
}
int SfxDecoder::GetFrameCount(){
return m_handler->SfxGetFrameCount();
}
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 )
{
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, 0 );
return 0;
}
pThis->m_cfg.escbk( pThis->m_cfg.userPtr, ( void * )buf, segLen, 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;
}