Commit e6fa5f8503beb36fb9f63f5a6dbc4c51ec28ae48

Authored by Hu Chunming
1 parent d7f431fe

日志优化

.gitignore
1 bin/test_recoder 1 bin/test_recoder
2 .vscode/launch.json 2 .vscode/launch.json
3 bin/logs/* 3 bin/logs/*
4 -bin/res/*  
5 \ No newline at end of file 4 \ No newline at end of file
  5 +bin/res/*
  6 +bin/vpt_proj
  7 +bin/libvpt_ascend.so
src/decoder/dvpp/FFRecoder.cpp
@@ -39,13 +39,13 @@ bool FFRecoder::init(int w, int h, AVRational time_base, AVCodecContext* avctx, @@ -39,13 +39,13 @@ bool FFRecoder::init(int w, int h, AVRational time_base, AVCodecContext* avctx,
39 // [1] 创建解码器 39 // [1] 创建解码器
40 const AVCodec* encoder = avcodec_find_encoder(AV_CODEC_ID_HEVC); 40 const AVCodec* encoder = avcodec_find_encoder(AV_CODEC_ID_HEVC);
41 if (!encoder) { 41 if (!encoder) {
42 - fprintf(stderr, "Find encoder AV_CODEC_ID_H264 failed!\n"); 42 + LOG_ERROR("Find encoder AV_CODEC_ID_H264 failed!");
43 return false; 43 return false;
44 } 44 }
45 // 获取解码器上下文 45 // 获取解码器上下文
46 codec_ctx_ = avcodec_alloc_context3(encoder); 46 codec_ctx_ = avcodec_alloc_context3(encoder);
47 if (!codec_ctx_) { 47 if (!codec_ctx_) {
48 - fprintf(stderr, "Alloc context for encoder contx failed!\n"); 48 + LOG_ERROR("Alloc context for encoder contx failed!");
49 return false; 49 return false;
50 } 50 }
51 // 设置解码器上下文参数 51 // 设置解码器上下文参数
@@ -68,7 +68,7 @@ bool FFRecoder::init(int w, int h, AVRational time_base, AVCodecContext* avctx, @@ -68,7 +68,7 @@ bool FFRecoder::init(int w, int h, AVRational time_base, AVCodecContext* avctx,
68 // 打开解码器 68 // 打开解码器
69 int ret = avcodec_open2(codec_ctx_, encoder, nullptr); 69 int ret = avcodec_open2(codec_ctx_, encoder, nullptr);
70 if (ret < 0) { 70 if (ret < 0) {
71 - fprintf(stderr, "Open encoder failed!\n"); 71 + LOG_ERROR("Open encoder failed!");
72 return false; 72 return false;
73 } 73 }
74 74
@@ -93,17 +93,17 @@ bool FFRecoder::init(int w, int h, AVRational time_base, AVCodecContext* avctx, @@ -93,17 +93,17 @@ bool FFRecoder::init(int w, int h, AVRational time_base, AVCodecContext* avctx,
93 if (av_frame_get_buffer(yuv_frame_, 0) < 0) { 93 if (av_frame_get_buffer(yuv_frame_, 0) < 0) {
94 av_frame_free(&yuv_frame_); 94 av_frame_free(&yuv_frame_);
95 yuv_frame_ = nullptr; 95 yuv_frame_ = nullptr;
96 - fprintf(stderr, "Frame get buffer failed!\n"); 96 + LOG_ERROR("Frame get buffer failed!");
97 return false; 97 return false;
98 } 98 }
99 99
100 // [5] 打开输出视频文件并写入视频头信息 100 // [5] 打开输出视频文件并写入视频头信息
101 if (avio_open(&fmt_ctx_->pb, outfile_name, AVIO_FLAG_WRITE) < 0) { 101 if (avio_open(&fmt_ctx_->pb, outfile_name, AVIO_FLAG_WRITE) < 0) {
102 - fprintf(stderr, "avio_open failed!\n"); 102 + LOG_ERROR("avio_open failed!");
103 return false; 103 return false;
104 } 104 }
105 if (avformat_write_header(fmt_ctx_, nullptr) < 0) { 105 if (avformat_write_header(fmt_ctx_, nullptr) < 0) {
106 - fprintf(stderr, "Write header failed!\n"); 106 + LOG_ERROR("Write header failed!");
107 return false; 107 return false;
108 } 108 }
109 109
@@ -150,11 +150,11 @@ bool FFRecoder::init(AVStream* stream, AVCodecContext* avctx, const char* outfil @@ -150,11 +150,11 @@ bool FFRecoder::init(AVStream* stream, AVCodecContext* avctx, const char* outfil
150 150
151 // [5] 打开输出视频文件并写入视频头信息 151 // [5] 打开输出视频文件并写入视频头信息
152 if (avio_open(&fmt_ctx_->pb, outfile_name, AVIO_FLAG_WRITE) < 0) { 152 if (avio_open(&fmt_ctx_->pb, outfile_name, AVIO_FLAG_WRITE) < 0) {
153 - fprintf(stderr, "avio_open failed!\n"); 153 + LOG_ERROR("avio_open failed!");
154 return false; 154 return false;
155 } 155 }
156 if (avformat_write_header(fmt_ctx_, nullptr) < 0) { 156 if (avformat_write_header(fmt_ctx_, nullptr) < 0) {
157 - fprintf(stderr, "Write header failed!\n"); 157 + LOG_ERROR("Write header failed!");
158 return false; 158 return false;
159 } 159 }
160 160
@@ -270,7 +270,7 @@ bool FFRecoder::write_pkt(AVPacket *pkt) { @@ -270,7 +270,7 @@ bool FFRecoder::write_pkt(AVPacket *pkt) {
270 // pkt->stream_index = out_stream_->index; 270 // pkt->stream_index = out_stream_->index;
271 271
272 if(pkt->pts==AV_NOPTS_VALUE) { 272 if(pkt->pts==AV_NOPTS_VALUE) {
273 - // printf("frame_index:%d\n", frame_index); 273 + // printf("frame_index:%d", frame_index);
274 //Write PTS 274 //Write PTS
275 AVRational time_base1 = codec_ctx_->time_base; 275 AVRational time_base1 = codec_ctx_->time_base;
276 //Duration between 2 frames (us) 276 //Duration between 2 frames (us)
@@ -293,7 +293,7 @@ bool FFRecoder::write_pkt(AVPacket *pkt) { @@ -293,7 +293,7 @@ bool FFRecoder::write_pkt(AVPacket *pkt) {
293 // 将数据写入到输出流 293 // 将数据写入到输出流
294 int ret = av_write_frame(fmt_ctx_, pkt); 294 int ret = av_write_frame(fmt_ctx_, pkt);
295 if (ret < 0) { 295 if (ret < 0) {
296 - fprintf(stderr, "Error while writing output packet: %s\n", av_make_error_string(errbuf, sizeof(errbuf), ret)); 296 + LOG_ERROR("Error while writing output packet: {}", av_make_error_string(errbuf, sizeof(errbuf), ret));
297 return false; 297 return false;
298 } 298 }
299 return true; 299 return true;
@@ -316,7 +316,7 @@ bool FFRecoder::write_frame(AVFrame* frame) @@ -316,7 +316,7 @@ bool FFRecoder::write_frame(AVFrame* frame)
316 int ret = avcodec_send_frame(codec_ctx_, pFrameOut); 316 int ret = avcodec_send_frame(codec_ctx_, pFrameOut);
317 av_frame_free(&pFrameOut); 317 av_frame_free(&pFrameOut);
318 if (ret < 0) { 318 if (ret < 0) {
319 - fprintf(stderr, "Error sending a frame to the encoder: %s\n", av_make_error_string(errbuf, sizeof(errbuf), ret)); 319 + LOG_ERROR("Error sending a frame to the encoder: {}", av_make_error_string(errbuf, sizeof(errbuf), ret));
320 return false; 320 return false;
321 } 321 }
322 322
@@ -327,7 +327,7 @@ bool FFRecoder::write_frame(AVFrame* frame) @@ -327,7 +327,7 @@ bool FFRecoder::write_frame(AVFrame* frame)
327 if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) 327 if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
328 return true; 328 return true;
329 else if (ret < 0) { 329 else if (ret < 0) {
330 - fprintf(stderr, "Error encoding a frame: %s\n", av_make_error_string(errbuf, sizeof(errbuf), ret)); 330 + LOG_ERROR("Error encoding a frame: {}", av_make_error_string(errbuf, sizeof(errbuf), ret));
331 return false; 331 return false;
332 } 332 }
333 // 将pts缩放到输出流的time_base上 333 // 将pts缩放到输出流的time_base上
@@ -339,7 +339,7 @@ bool FFRecoder::write_frame(AVFrame* frame) @@ -339,7 +339,7 @@ bool FFRecoder::write_frame(AVFrame* frame)
339 //ret = av_write_frame(fmt_ctx_, &pkt); 339 //ret = av_write_frame(fmt_ctx_, &pkt);
340 av_packet_unref(&pkt); 340 av_packet_unref(&pkt);
341 if (ret < 0) { 341 if (ret < 0) {
342 - fprintf(stderr, "Error while writing output packet: %s\n", av_make_error_string(errbuf, sizeof(errbuf), ret)); 342 + LOG_ERROR("Error while writing output packet: {}", av_make_error_string(errbuf, sizeof(errbuf), ret));
343 return false; 343 return false;
344 } 344 }
345 /* av_interleaved_write_frame(fmt_ctx_, nullptr); 345 /* av_interleaved_write_frame(fmt_ctx_, nullptr);
src/decoder/dvpp/FFRecoder.h
1 #pragma once 1 #pragma once
2 #include <memory> 2 #include <memory>
3 3
4 -extern "C" {  
5 - #include <libavcodec/avcodec.h>  
6 - #include <libavformat/avformat.h>  
7 - #include <libavutil/opt.h>  
8 - #include <libavutil/timestamp.h>  
9 - #include <libavutil/imgutils.h>  
10 - #include <libswscale/swscale.h>  
11 -} 4 +#include "depend_headers.h"
12 5
13 class FFRecoder 6 class FFRecoder
14 { 7 {
src/decoder/dvpp/FFRecoderTaskManager.cpp
@@ -198,14 +198,6 @@ list&lt;DataPacket*&gt;::iterator FFRecoderTaskManager::getStartIterator(unsigned long @@ -198,14 +198,6 @@ list&lt;DataPacket*&gt;::iterator FFRecoderTaskManager::getStartIterator(unsigned long
198 return it_first; 198 return it_first;
199 } 199 }
200 200
201 - // auto it_second = m_pkt_list.begin();  
202 - // for(;it_second != m_pkt_list.end(); it_second++) {  
203 - // DataPacket* dataPkt = *it_second;  
204 - // if (dataPkt->frame_nb >= start_frame_nb){  
205 - // return it_second;  
206 - // }  
207 - // }  
208 -  
209 auto it_second = m_pkt_list.begin(); 201 auto it_second = m_pkt_list.begin();
210 for(;it_second != m_pkt_list.end(); it_second++) { 202 for(;it_second != m_pkt_list.end(); it_second++) {
211 DataPacket* dataPkt = *it_second; 203 DataPacket* dataPkt = *it_second;
@@ -359,8 +351,6 @@ void FFRecoderTaskManager::recode_thread2() { @@ -359,8 +351,6 @@ void FFRecoderTaskManager::recode_thread2() {
359 continue; 351 continue;
360 } 352 }
361 353
362 - auto it_end = getEndIterator(recoderinfo.frame_nb);  
363 -  
364 LOG_INFO("start frame_nb: {}", (*it_data)->frame_nb); 354 LOG_INFO("start frame_nb: {}", (*it_data)->frame_nb);
365 355
366 m_pkt_list_mtx.lock(); 356 m_pkt_list_mtx.lock();
@@ -387,7 +377,7 @@ void FFRecoderTaskManager::recode_thread2() { @@ -387,7 +377,7 @@ void FFRecoderTaskManager::recode_thread2() {
387 ffrecoder.uninit(); 377 ffrecoder.uninit();
388 continue; 378 continue;
389 } 379 }
390 - LOG_INFO("record start, pkt_list size: {} id: {}", m_pkt_list.size(), id); 380 + LOG_DEBUG("record start, pkt_list size: {} id: {}", m_pkt_list.size(), id);
391 381
392 int count = 0; 382 int count = 0;
393 auto it_save = it_data; 383 auto it_save = it_data;
@@ -420,7 +410,7 @@ void FFRecoderTaskManager::recode_thread2() { @@ -420,7 +410,7 @@ void FFRecoderTaskManager::recode_thread2() {
420 } 410 }
421 411
422 void FFRecoderTaskManager::recode_thread3() { 412 void FFRecoderTaskManager::recode_thread3() {
423 - LOG_INFO("recode_thread2 start..."); 413 + LOG_INFO("recode_thread3 start...");
424 while(true) { 414 while(true) {
425 if(m_bExit) { 415 if(m_bExit) {
426 break; 416 break;
@@ -491,11 +481,11 @@ void FFRecoderTaskManager::recode_thread3() { @@ -491,11 +481,11 @@ void FFRecoderTaskManager::recode_thread3() {
491 LOG_INFO("record end, total save: {} start_frame_nb: {} end_frame_nb: {} file_path: {}", count, start_frame_nb, end_frame_nb, file_name); 481 LOG_INFO("record end, total save: {} start_frame_nb: {} end_frame_nb: {} file_path: {}", count, start_frame_nb, end_frame_nb, file_name);
492 } 482 }
493 483
494 - LOG_INFO("recode_thread2 end."); 484 + LOG_INFO("recode_thread3 end.");
495 } 485 }
496 486
497 void FFRecoderTaskManager::recode_thread4() { 487 void FFRecoderTaskManager::recode_thread4() {
498 - LOG_INFO("recode_thread2 start..."); 488 + LOG_INFO("recode_thread4 start...");
499 while(true) { 489 while(true) {
500 if(m_bExit) { 490 if(m_bExit) {
501 break; 491 break;
@@ -566,7 +556,7 @@ void FFRecoderTaskManager::recode_thread4() { @@ -566,7 +556,7 @@ void FFRecoderTaskManager::recode_thread4() {
566 LOG_INFO("record end, total save: {} start_frame_nb: {} end_frame_nb: {} file_path: {}", count, start_frame_nb, end_frame_nb, file_name); 556 LOG_INFO("record end, total save: {} start_frame_nb: {} end_frame_nb: {} file_path: {}", count, start_frame_nb, end_frame_nb, file_name);
567 } 557 }
568 558
569 - LOG_INFO("recode_thread2 end."); 559 + LOG_INFO("recode_thread4 end.");
570 } 560 }
571 561
572 void FFRecoderTaskManager::close() { 562 void FFRecoderTaskManager::close() {
src/decoder/dvpp/depend_headers.h
@@ -27,6 +27,9 @@ extern &quot;C&quot; { @@ -27,6 +27,9 @@ extern &quot;C&quot; {
27 #include "libavutil/samplefmt.h" 27 #include "libavutil/samplefmt.h"
28 #include "libavformat/avformat.h" 28 #include "libavformat/avformat.h"
29 #include "libavcodec/avcodec.h" 29 #include "libavcodec/avcodec.h"
  30 + #include <libavutil/opt.h>
  31 + #include <libavutil/timestamp.h>
  32 + #include <libswscale/swscale.h>
30 } 33 }
31 34
32 35