Commit e6fa5f8503beb36fb9f63f5a6dbc4c51ec28ae48

Authored by Hu Chunming
1 parent d7f431fe

日志优化

.gitignore
1 1 bin/test_recoder
2 2 .vscode/launch.json
3 3 bin/logs/*
4   -bin/res/*
5 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 39 // [1] 创建解码器
40 40 const AVCodec* encoder = avcodec_find_encoder(AV_CODEC_ID_HEVC);
41 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 43 return false;
44 44 }
45 45 // 获取解码器上下文
46 46 codec_ctx_ = avcodec_alloc_context3(encoder);
47 47 if (!codec_ctx_) {
48   - fprintf(stderr, "Alloc context for encoder contx failed!\n");
  48 + LOG_ERROR("Alloc context for encoder contx failed!");
49 49 return false;
50 50 }
51 51 // 设置解码器上下文参数
... ... @@ -68,7 +68,7 @@ bool FFRecoder::init(int w, int h, AVRational time_base, AVCodecContext* avctx,
68 68 // 打开解码器
69 69 int ret = avcodec_open2(codec_ctx_, encoder, nullptr);
70 70 if (ret < 0) {
71   - fprintf(stderr, "Open encoder failed!\n");
  71 + LOG_ERROR("Open encoder failed!");
72 72 return false;
73 73 }
74 74  
... ... @@ -93,17 +93,17 @@ bool FFRecoder::init(int w, int h, AVRational time_base, AVCodecContext* avctx,
93 93 if (av_frame_get_buffer(yuv_frame_, 0) < 0) {
94 94 av_frame_free(&yuv_frame_);
95 95 yuv_frame_ = nullptr;
96   - fprintf(stderr, "Frame get buffer failed!\n");
  96 + LOG_ERROR("Frame get buffer failed!");
97 97 return false;
98 98 }
99 99  
100 100 // [5] 打开输出视频文件并写入视频头信息
101 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 103 return false;
104 104 }
105 105 if (avformat_write_header(fmt_ctx_, nullptr) < 0) {
106   - fprintf(stderr, "Write header failed!\n");
  106 + LOG_ERROR("Write header failed!");
107 107 return false;
108 108 }
109 109  
... ... @@ -150,11 +150,11 @@ bool FFRecoder::init(AVStream* stream, AVCodecContext* avctx, const char* outfil
150 150  
151 151 // [5] 打开输出视频文件并写入视频头信息
152 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 154 return false;
155 155 }
156 156 if (avformat_write_header(fmt_ctx_, nullptr) < 0) {
157   - fprintf(stderr, "Write header failed!\n");
  157 + LOG_ERROR("Write header failed!");
158 158 return false;
159 159 }
160 160  
... ... @@ -270,7 +270,7 @@ bool FFRecoder::write_pkt(AVPacket *pkt) {
270 270 // pkt->stream_index = out_stream_->index;
271 271  
272 272 if(pkt->pts==AV_NOPTS_VALUE) {
273   - // printf("frame_index:%d\n", frame_index);
  273 + // printf("frame_index:%d", frame_index);
274 274 //Write PTS
275 275 AVRational time_base1 = codec_ctx_->time_base;
276 276 //Duration between 2 frames (us)
... ... @@ -293,7 +293,7 @@ bool FFRecoder::write_pkt(AVPacket *pkt) {
293 293 // 将数据写入到输出流
294 294 int ret = av_write_frame(fmt_ctx_, pkt);
295 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 297 return false;
298 298 }
299 299 return true;
... ... @@ -316,7 +316,7 @@ bool FFRecoder::write_frame(AVFrame* frame)
316 316 int ret = avcodec_send_frame(codec_ctx_, pFrameOut);
317 317 av_frame_free(&pFrameOut);
318 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 320 return false;
321 321 }
322 322  
... ... @@ -327,7 +327,7 @@ bool FFRecoder::write_frame(AVFrame* frame)
327 327 if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
328 328 return true;
329 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 331 return false;
332 332 }
333 333 // 将pts缩放到输出流的time_base上
... ... @@ -339,7 +339,7 @@ bool FFRecoder::write_frame(AVFrame* frame)
339 339 //ret = av_write_frame(fmt_ctx_, &pkt);
340 340 av_packet_unref(&pkt);
341 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 343 return false;
344 344 }
345 345 /* av_interleaved_write_frame(fmt_ctx_, nullptr);
... ...
src/decoder/dvpp/FFRecoder.h
1 1 #pragma once
2 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 6 class FFRecoder
14 7 {
... ...
src/decoder/dvpp/FFRecoderTaskManager.cpp
... ... @@ -198,14 +198,6 @@ list&lt;DataPacket*&gt;::iterator FFRecoderTaskManager::getStartIterator(unsigned long
198 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 201 auto it_second = m_pkt_list.begin();
210 202 for(;it_second != m_pkt_list.end(); it_second++) {
211 203 DataPacket* dataPkt = *it_second;
... ... @@ -359,8 +351,6 @@ void FFRecoderTaskManager::recode_thread2() {
359 351 continue;
360 352 }
361 353  
362   - auto it_end = getEndIterator(recoderinfo.frame_nb);
363   -
364 354 LOG_INFO("start frame_nb: {}", (*it_data)->frame_nb);
365 355  
366 356 m_pkt_list_mtx.lock();
... ... @@ -387,7 +377,7 @@ void FFRecoderTaskManager::recode_thread2() {
387 377 ffrecoder.uninit();
388 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 382 int count = 0;
393 383 auto it_save = it_data;
... ... @@ -420,7 +410,7 @@ void FFRecoderTaskManager::recode_thread2() {
420 410 }
421 411  
422 412 void FFRecoderTaskManager::recode_thread3() {
423   - LOG_INFO("recode_thread2 start...");
  413 + LOG_INFO("recode_thread3 start...");
424 414 while(true) {
425 415 if(m_bExit) {
426 416 break;
... ... @@ -491,11 +481,11 @@ void FFRecoderTaskManager::recode_thread3() {
491 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 487 void FFRecoderTaskManager::recode_thread4() {
498   - LOG_INFO("recode_thread2 start...");
  488 + LOG_INFO("recode_thread4 start...");
499 489 while(true) {
500 490 if(m_bExit) {
501 491 break;
... ... @@ -566,7 +556,7 @@ void FFRecoderTaskManager::recode_thread4() {
566 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 562 void FFRecoderTaskManager::close() {
... ...
src/decoder/dvpp/depend_headers.h
... ... @@ -27,6 +27,9 @@ extern &quot;C&quot; {
27 27 #include "libavutil/samplefmt.h"
28 28 #include "libavformat/avformat.h"
29 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  
... ...