Commit 6fc86385103936523a5daa2bf07ec544f038efbd
1 parent
7e9074f2
代码优化
Showing
2 changed files
with
14 additions
and
12 deletions
src/FFNvDecoder.cpp
@@ -233,13 +233,13 @@ void FFNvDecoder::decode_thread() | @@ -233,13 +233,13 @@ void FFNvDecoder::decode_thread() | ||
233 | if (stream_index == pkt->stream_index){ | 233 | if (stream_index == pkt->stream_index){ |
234 | result = avcodec_send_packet(avctx, pkt); | 234 | result = avcodec_send_packet(avctx, pkt); |
235 | if (result < 0){ | 235 | if (result < 0){ |
236 | - av_log(nullptr, AV_LOG_ERROR, "Failed to send pkt: %d \n",result); | 236 | + av_log(nullptr, AV_LOG_ERROR, "%s - Failed to send pkt: %d \n",name,result); |
237 | continue; | 237 | continue; |
238 | } | 238 | } |
239 | 239 | ||
240 | result = avcodec_receive_frame(avctx, gpuFrame); | 240 | result = avcodec_receive_frame(avctx, gpuFrame); |
241 | if ((result == AVERROR(EAGAIN) || result == AVERROR_EOF) || result < 0){ | 241 | if ((result == AVERROR(EAGAIN) || result == AVERROR_EOF) || result < 0){ |
242 | - av_log(nullptr, AV_LOG_ERROR, "Failed to receive frame: %d \n",result); | 242 | + av_log(nullptr, AV_LOG_ERROR, "%s - Failed to receive frame: %d \n",name,result); |
243 | continue; | 243 | continue; |
244 | } | 244 | } |
245 | 245 | ||
@@ -271,7 +271,7 @@ void FFNvDecoder::decode_thread() | @@ -271,7 +271,7 @@ void FFNvDecoder::decode_thread() | ||
271 | 271 | ||
272 | decode_finished(); | 272 | decode_finished(); |
273 | 273 | ||
274 | - av_log(nullptr, AV_LOG_INFO, "decode thread exited. \n"); | 274 | + av_log(nullptr, AV_LOG_INFO, "%s - decode thread exited. \n",name); |
275 | } | 275 | } |
276 | 276 | ||
277 | void FFNvDecoder::decode_finished() | 277 | void FFNvDecoder::decode_finished() |
src/main.cpp
@@ -94,14 +94,10 @@ int count_std = 100; | @@ -94,14 +94,10 @@ int count_std = 100; | ||
94 | 94 | ||
95 | static long long get_cur_time(){ | 95 | static long long get_cur_time(){ |
96 | // 获取操作系统当前时间点(精确到微秒) | 96 | // 获取操作系统当前时间点(精确到微秒) |
97 | - chrono::time_point<chrono::system_clock, chrono::microseconds> tpMicro | ||
98 | - = chrono::time_point_cast<chrono::microseconds>(chrono::system_clock::now()); | 97 | + chrono::time_point<chrono::system_clock, chrono::milliseconds> tpMicro |
98 | + = chrono::time_point_cast<chrono::milliseconds>(chrono::system_clock::now()); | ||
99 | // (微秒精度的)时间点 => (微秒精度的)时间戳 | 99 | // (微秒精度的)时间点 => (微秒精度的)时间戳 |
100 | - time_t totalMicroSeconds = tpMicro.time_since_epoch().count(); | ||
101 | - | ||
102 | - long long currentTime = ((long long)totalMicroSeconds)/1000; | ||
103 | - | ||
104 | - return currentTime; | 100 | + return tpMicro.time_since_epoch().count(); |
105 | } | 101 | } |
106 | 102 | ||
107 | static int sum = 0; | 103 | static int sum = 0; |
@@ -160,6 +156,10 @@ void postDecoded0(const void * userPtr, AVFrame * gpuFrame){ | @@ -160,6 +156,10 @@ void postDecoded0(const void * userPtr, AVFrame * gpuFrame){ | ||
160 | } | 156 | } |
161 | } | 157 | } |
162 | 158 | ||
159 | +void decode_finished_cbk(const void* userPtr){ | ||
160 | + cout << "decode_finish timestamp: " << get_cur_time() << endl; | ||
161 | +} | ||
162 | + | ||
163 | // string test_uri = "rtmp://192.168.10.56:1935/objecteye/1"; | 163 | // string test_uri = "rtmp://192.168.10.56:1935/objecteye/1"; |
164 | // string test_uri = "/home/cmhu/data/output_800x480.mp4"; | 164 | // string test_uri = "/home/cmhu/data/output_800x480.mp4"; |
165 | // string test_uri = "/home/cmhu/data/output_1920x1080.mp4"; | 165 | // string test_uri = "/home/cmhu/data/output_1920x1080.mp4"; |
@@ -173,15 +173,16 @@ void createDecode(int index){ | @@ -173,15 +173,16 @@ void createDecode(int index){ | ||
173 | config.name = "dec" + to_string(index); | 173 | config.name = "dec" + to_string(index); |
174 | config.cfg.uri = test_uri; | 174 | config.cfg.uri = test_uri; |
175 | config.cfg.post_decoded_cbk = postDecoded; | 175 | config.cfg.post_decoded_cbk = postDecoded; |
176 | + config.cfg.decode_finished_cbk = decode_finished_cbk; | ||
176 | config.cfg.force_tcp = true; | 177 | config.cfg.force_tcp = true; |
177 | 178 | ||
178 | if (index % 2 == 0) | 179 | if (index % 2 == 0) |
179 | { | 180 | { |
180 | - config.cfg.gpuid = "2"; | 181 | + config.cfg.gpuid = "0"; |
181 | } | 182 | } |
182 | else | 183 | else |
183 | { | 184 | { |
184 | - config.cfg.gpuid = "1"; | 185 | + config.cfg.gpuid = "0"; |
185 | } | 186 | } |
186 | 187 | ||
187 | FFNvDecoder* decoder = pDecManager->createDecoder(config); | 188 | FFNvDecoder* decoder = pDecManager->createDecoder(config); |
@@ -253,6 +254,7 @@ int main(){ | @@ -253,6 +254,7 @@ int main(){ | ||
253 | config.name = "dec"; | 254 | config.name = "dec"; |
254 | config.cfg.uri = test_uri; | 255 | config.cfg.uri = test_uri; |
255 | config.cfg.post_decoded_cbk = postDecoded0; | 256 | config.cfg.post_decoded_cbk = postDecoded0; |
257 | + config.cfg.decode_finished_cbk = decode_finished_cbk; | ||
256 | config.cfg.force_tcp = true; | 258 | config.cfg.force_tcp = true; |
257 | config.cfg.gpuid = "0"; | 259 | config.cfg.gpuid = "0"; |
258 | FFNvDecoder* dec2 = pDecManager->createDecoder(config); | 260 | FFNvDecoder* dec2 = pDecManager->createDecoder(config); |