diff --git a/.gitignore b/.gitignore index 7cc22e6..e994d4d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ bin/test_recoder .vscode/launch.json bin/logs/* -bin/res/* \ No newline at end of file +bin/res/* +bin/vpt_proj +bin/libvpt_ascend.so diff --git a/src/decoder/dvpp/FFRecoder.cpp b/src/decoder/dvpp/FFRecoder.cpp index 3f14288..f3c8d78 100644 --- a/src/decoder/dvpp/FFRecoder.cpp +++ b/src/decoder/dvpp/FFRecoder.cpp @@ -39,13 +39,13 @@ bool FFRecoder::init(int w, int h, AVRational time_base, AVCodecContext* avctx, // [1] 创建解码器 const AVCodec* encoder = avcodec_find_encoder(AV_CODEC_ID_HEVC); if (!encoder) { - fprintf(stderr, "Find encoder AV_CODEC_ID_H264 failed!\n"); + LOG_ERROR("Find encoder AV_CODEC_ID_H264 failed!"); return false; } // 获取解码器上下文 codec_ctx_ = avcodec_alloc_context3(encoder); if (!codec_ctx_) { - fprintf(stderr, "Alloc context for encoder contx failed!\n"); + LOG_ERROR("Alloc context for encoder contx failed!"); return false; } // 设置解码器上下文参数 @@ -68,7 +68,7 @@ bool FFRecoder::init(int w, int h, AVRational time_base, AVCodecContext* avctx, // 打开解码器 int ret = avcodec_open2(codec_ctx_, encoder, nullptr); if (ret < 0) { - fprintf(stderr, "Open encoder failed!\n"); + LOG_ERROR("Open encoder failed!"); return false; } @@ -93,17 +93,17 @@ bool FFRecoder::init(int w, int h, AVRational time_base, AVCodecContext* avctx, if (av_frame_get_buffer(yuv_frame_, 0) < 0) { av_frame_free(&yuv_frame_); yuv_frame_ = nullptr; - fprintf(stderr, "Frame get buffer failed!\n"); + LOG_ERROR("Frame get buffer failed!"); return false; } // [5] 打开输出视频文件并写入视频头信息 if (avio_open(&fmt_ctx_->pb, outfile_name, AVIO_FLAG_WRITE) < 0) { - fprintf(stderr, "avio_open failed!\n"); + LOG_ERROR("avio_open failed!"); return false; } if (avformat_write_header(fmt_ctx_, nullptr) < 0) { - fprintf(stderr, "Write header failed!\n"); + LOG_ERROR("Write header failed!"); return false; } @@ -150,11 +150,11 @@ bool FFRecoder::init(AVStream* stream, AVCodecContext* avctx, const char* outfil // [5] 打开输出视频文件并写入视频头信息 if (avio_open(&fmt_ctx_->pb, outfile_name, AVIO_FLAG_WRITE) < 0) { - fprintf(stderr, "avio_open failed!\n"); + LOG_ERROR("avio_open failed!"); return false; } if (avformat_write_header(fmt_ctx_, nullptr) < 0) { - fprintf(stderr, "Write header failed!\n"); + LOG_ERROR("Write header failed!"); return false; } @@ -270,7 +270,7 @@ bool FFRecoder::write_pkt(AVPacket *pkt) { // pkt->stream_index = out_stream_->index; if(pkt->pts==AV_NOPTS_VALUE) { - // printf("frame_index:%d\n", frame_index); + // printf("frame_index:%d", frame_index); //Write PTS AVRational time_base1 = codec_ctx_->time_base; //Duration between 2 frames (us) @@ -293,7 +293,7 @@ bool FFRecoder::write_pkt(AVPacket *pkt) { // 将数据写入到输出流 int ret = av_write_frame(fmt_ctx_, pkt); if (ret < 0) { - fprintf(stderr, "Error while writing output packet: %s\n", av_make_error_string(errbuf, sizeof(errbuf), ret)); + LOG_ERROR("Error while writing output packet: {}", av_make_error_string(errbuf, sizeof(errbuf), ret)); return false; } return true; @@ -316,7 +316,7 @@ bool FFRecoder::write_frame(AVFrame* frame) int ret = avcodec_send_frame(codec_ctx_, pFrameOut); av_frame_free(&pFrameOut); if (ret < 0) { - fprintf(stderr, "Error sending a frame to the encoder: %s\n", av_make_error_string(errbuf, sizeof(errbuf), ret)); + LOG_ERROR("Error sending a frame to the encoder: {}", av_make_error_string(errbuf, sizeof(errbuf), ret)); return false; } @@ -327,7 +327,7 @@ bool FFRecoder::write_frame(AVFrame* frame) if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) return true; else if (ret < 0) { - fprintf(stderr, "Error encoding a frame: %s\n", av_make_error_string(errbuf, sizeof(errbuf), ret)); + LOG_ERROR("Error encoding a frame: {}", av_make_error_string(errbuf, sizeof(errbuf), ret)); return false; } // 将pts缩放到输出流的time_base上 @@ -339,7 +339,7 @@ bool FFRecoder::write_frame(AVFrame* frame) //ret = av_write_frame(fmt_ctx_, &pkt); av_packet_unref(&pkt); if (ret < 0) { - fprintf(stderr, "Error while writing output packet: %s\n", av_make_error_string(errbuf, sizeof(errbuf), ret)); + LOG_ERROR("Error while writing output packet: {}", av_make_error_string(errbuf, sizeof(errbuf), ret)); return false; } /* av_interleaved_write_frame(fmt_ctx_, nullptr); diff --git a/src/decoder/dvpp/FFRecoder.h b/src/decoder/dvpp/FFRecoder.h index ec99c15..dfee0e4 100644 --- a/src/decoder/dvpp/FFRecoder.h +++ b/src/decoder/dvpp/FFRecoder.h @@ -1,14 +1,7 @@ #pragma once #include -extern "C" { - #include - #include - #include - #include - #include - #include -} +#include "depend_headers.h" class FFRecoder { diff --git a/src/decoder/dvpp/FFRecoderTaskManager.cpp b/src/decoder/dvpp/FFRecoderTaskManager.cpp index 77b2c50..18ce62e 100644 --- a/src/decoder/dvpp/FFRecoderTaskManager.cpp +++ b/src/decoder/dvpp/FFRecoderTaskManager.cpp @@ -198,14 +198,6 @@ list::iterator FFRecoderTaskManager::getStartIterator(unsigned long return it_first; } - // auto it_second = m_pkt_list.begin(); - // for(;it_second != m_pkt_list.end(); it_second++) { - // DataPacket* dataPkt = *it_second; - // if (dataPkt->frame_nb >= start_frame_nb){ - // return it_second; - // } - // } - auto it_second = m_pkt_list.begin(); for(;it_second != m_pkt_list.end(); it_second++) { DataPacket* dataPkt = *it_second; @@ -359,8 +351,6 @@ void FFRecoderTaskManager::recode_thread2() { continue; } - auto it_end = getEndIterator(recoderinfo.frame_nb); - LOG_INFO("start frame_nb: {}", (*it_data)->frame_nb); m_pkt_list_mtx.lock(); @@ -387,7 +377,7 @@ void FFRecoderTaskManager::recode_thread2() { ffrecoder.uninit(); continue; } - LOG_INFO("record start, pkt_list size: {} id: {}", m_pkt_list.size(), id); + LOG_DEBUG("record start, pkt_list size: {} id: {}", m_pkt_list.size(), id); int count = 0; auto it_save = it_data; @@ -420,7 +410,7 @@ void FFRecoderTaskManager::recode_thread2() { } void FFRecoderTaskManager::recode_thread3() { - LOG_INFO("recode_thread2 start..."); + LOG_INFO("recode_thread3 start..."); while(true) { if(m_bExit) { break; @@ -491,11 +481,11 @@ void FFRecoderTaskManager::recode_thread3() { LOG_INFO("record end, total save: {} start_frame_nb: {} end_frame_nb: {} file_path: {}", count, start_frame_nb, end_frame_nb, file_name); } - LOG_INFO("recode_thread2 end."); + LOG_INFO("recode_thread3 end."); } void FFRecoderTaskManager::recode_thread4() { - LOG_INFO("recode_thread2 start..."); + LOG_INFO("recode_thread4 start..."); while(true) { if(m_bExit) { break; @@ -566,7 +556,7 @@ void FFRecoderTaskManager::recode_thread4() { LOG_INFO("record end, total save: {} start_frame_nb: {} end_frame_nb: {} file_path: {}", count, start_frame_nb, end_frame_nb, file_name); } - LOG_INFO("recode_thread2 end."); + LOG_INFO("recode_thread4 end."); } void FFRecoderTaskManager::close() { diff --git a/src/decoder/dvpp/depend_headers.h b/src/decoder/dvpp/depend_headers.h index 562a3b9..92064d3 100755 --- a/src/decoder/dvpp/depend_headers.h +++ b/src/decoder/dvpp/depend_headers.h @@ -27,6 +27,9 @@ extern "C" { #include "libavutil/samplefmt.h" #include "libavformat/avformat.h" #include "libavcodec/avcodec.h" + #include + #include + #include }