From 0b260a90879d50a26b22bd8f6640de85bb8023db Mon Sep 17 00:00:00 2001
From: eisneinechse <42617957+eisneinechse@users.noreply.github.com>
Date: Tue, 18 Sep 2018 15:31:34 -0700
Subject: [PATCH] Code cleanup and move messages regarding hardware
acceleration to Debug Logger
---
src/FFmpegReader.cpp | 31 ++++++++++++++++---------------
src/FFmpegWriter.cpp | 15 ++++++++++-----
2 files changed, 26 insertions(+), 20 deletions(-)
diff --git a/src/FFmpegReader.cpp b/src/FFmpegReader.cpp
index aab11460..2225e72c 100644
--- a/src/FFmpegReader.cpp
+++ b/src/FFmpegReader.cpp
@@ -334,7 +334,7 @@ void FFmpegReader::Open()
pCodecCtx->coded_width > constraints->max_width ||
pCodecCtx->coded_height > constraints->max_height) {
ZmqLogger::Instance()->AppendDebugMethod("DIMENSIONS ARE TOO LARGE for hardware acceleration\n", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1);
- cerr << "DIMENSIONS ARE TOO LARGE for hardware acceleration\n";
+ //cerr << "DIMENSIONS ARE TOO LARGE for hardware acceleration\n";
hw_de_supported = 0;
retry_decode_open = 1;
AV_FREE_CONTEXT(pCodecCtx);
@@ -345,10 +345,10 @@ void FFmpegReader::Open()
}
else {
// All is just peachy
- ZmqLogger::Instance()->AppendDebugMethod("\nDecode hardware acceleration is used\n", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1);
- cerr << "\nDecode hardware acceleration is used\n";
- cerr << "Min width : " << constraints->min_width << " MinHeight : " << constraints->min_height << "MaxWidth : " << constraints->max_width << "MaxHeight : " << constraints->max_height << "\n";
- cerr << "Frame width : " << pCodecCtx->coded_width << " Frame height : " << pCodecCtx->coded_height << "\n";
+ ZmqLogger::Instance()->AppendDebugMethod("\nDecode hardware acceleration is used\n", "Min width :", constraints->min_width, "Min Height :", constraints->min_height, "MaxWidth :", constraints->max_width, "MaxHeight :", constraints->max_height, "Frame width :", pCodecCtx->coded_width, "Frame height :", pCodecCtx->coded_height);
+ //cerr << "\nDecode hardware acceleration is used\n";
+ //cerr << "Min width : " << constraints->min_width << " MinHeight : " << constraints->min_height << "MaxWidth : " << constraints->max_width << "MaxHeight : " << constraints->max_height << "\n";
+ //cerr << "Frame width : " << pCodecCtx->coded_width << " Frame height : " << pCodecCtx->coded_height << "\n";
retry_decode_open = 0;
}
av_hwframe_constraints_free(&constraints);
@@ -360,15 +360,16 @@ void FFmpegReader::Open()
int max_h, max_w;
max_h = ((getenv( "LIMIT_HEIGHT_MAX" )==NULL) ? MAX_SUPPORTED_HEIGHT : atoi(getenv( "LIMIT_HEIGHT_MAX" )));
max_w = ((getenv( "LIMIT_WIDTH_MAX" )==NULL) ? MAX_SUPPORTED_WIDTH : atoi(getenv( "LIMIT_WIDTH_MAX" )));
- cerr << "Constraints could not be found using default limit\n";
+ ZmqLogger::Instance()->AppendDebugMethod("Constraints could not be found using default limit\n", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1);
+ //cerr << "Constraints could not be found using default limit\n";
if (pCodecCtx->coded_width < 0 ||
pCodecCtx->coded_height < 0 ||
pCodecCtx->coded_width > max_w ||
pCodecCtx->coded_height > max_h ) {
- ZmqLogger::Instance()->AppendDebugMethod("DIMENSIONS ARE TOO LARGE for hardware acceleration\n", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1);
- cerr << "DIMENSIONS ARE TOO LARGE for hardware acceleration\n";
- cerr << " Max Width : " << max_w << " Height : " << max_h << "\n";
- cerr << "Frame width : " << pCodecCtx->coded_width << " Frame height : " << pCodecCtx->coded_height << "\n";
+ ZmqLogger::Instance()->AppendDebugMethod("DIMENSIONS ARE TOO LARGE for hardware acceleration\n", "Max Width :", max_w, "Max Height :", max_h, "Frame width :", pCodecCtx->coded_width, "Frame height :", pCodecCtx->coded_height, "", -1, "", -1);
+ //cerr << "DIMENSIONS ARE TOO LARGE for hardware acceleration\n";
+ //cerr << " Max Width : " << max_w << " Height : " << max_h << "\n";
+ //cerr << "Frame width : " << pCodecCtx->coded_width << " Frame height : " << pCodecCtx->coded_height << "\n";
hw_de_supported = 0;
retry_decode_open = 1;
AV_FREE_CONTEXT(pCodecCtx);
@@ -378,17 +379,17 @@ void FFmpegReader::Open()
}
}
else {
- ZmqLogger::Instance()->AppendDebugMethod("\nDecode hardware acceleration is used\n", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1);
- cerr << "\nDecode hardware acceleration is used\n";
- cerr << " Max Width : " << max_w << " Height : " << max_h << "\n";
- cerr << "Frame width : " << pCodecCtx->coded_width << " Frame height : " << pCodecCtx->coded_height << "\n";
+ ZmqLogger::Instance()->AppendDebugMethod("\nDecode hardware acceleration is used\n", "Max Width :", max_w, "Max Height :", max_h, "Frame width :", pCodecCtx->coded_width, "Frame height :", pCodecCtx->coded_height, "", -1, "", -1);
+ //cerr << "\nDecode hardware acceleration is used\n";
+ //cerr << " Max Width : " << max_w << " Height : " << max_h << "\n";
+ //cerr << "Frame width : " << pCodecCtx->coded_width << " Frame height : " << pCodecCtx->coded_height << "\n";
retry_decode_open = 0;
}
}
} // if hw_de_on && hw_de_supported
else {
ZmqLogger::Instance()->AppendDebugMethod("\nDecode in software is used\n", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1);
- cerr << "\nDecode in software is used\n";
+ //cerr << "\nDecode in software is used\n";
}
#else
retry_decode_open = 0;
diff --git a/src/FFmpegWriter.cpp b/src/FFmpegWriter.cpp
index 840acba1..9791043c 100644
--- a/src/FFmpegWriter.cpp
+++ b/src/FFmpegWriter.cpp
@@ -1254,7 +1254,8 @@ void FFmpegWriter::open_video(AVFormatContext *oc, AVStream *st)
#endif
if (av_hwdevice_ctx_create(&hw_device_ctx, hw_en_av_device_type,
dev_hw, NULL, 0) < 0) {
- cerr << "FFmpegWriter::open_video : Codec name: " << info.vcodec.c_str() << " ERROR creating\n";
+ ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::open_video : Codec name: ", info.vcodec.c_str(), -1, " ERROR creating\n", -1, "", -1, "", -1, "", -1, "", -1);
+ //cerr << "FFmpegWriter::open_video : Codec name: " << info.vcodec.c_str() << " ERROR creating\n";
throw InvalidCodec("Could not create hwdevice", path);
}
}
@@ -1860,10 +1861,12 @@ bool FFmpegWriter::write_video_packet(std::shared_ptr frame, AVFrame* fra
error_code = ret;
if (ret < 0 ) {
ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::write_video_packet (Frame not sent)", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1);
- if (ret == AVERROR(EAGAIN) )
+ if (ret == AVERROR(EAGAIN) ) {
cerr << "Frame EAGAIN" << "\n";
- if (ret == AVERROR_EOF )
+ }
+ if (ret == AVERROR_EOF ) {
cerr << "Frame AVERROR_EOF" << "\n";
+ }
avcodec_send_frame(video_codec, NULL);
}
else {
@@ -1884,10 +1887,12 @@ bool FFmpegWriter::write_video_packet(std::shared_ptr frame, AVFrame* fra
#if LIBAVFORMAT_VERSION_MAJOR >= 54
// Write video packet (older than FFmpeg 3.2)
error_code = avcodec_encode_video2(video_codec, &pkt, frame_final, &got_packet_ptr);
- if (error_code != 0 )
+ if (error_code != 0 ) {
cerr << "Frame AVERROR_EOF" << "\n";
- if (got_packet_ptr == 0 )
+ }
+ if (got_packet_ptr == 0 ) {
cerr << "Frame gotpacket error" << "\n";
+ }
#else
// Write video packet (even older versions of FFmpeg)
int video_outbuf_size = 200000;