From 5403cbb3899cde81bb696a15a70e3fac9ec6ad73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Tue, 6 Aug 2019 14:30:58 +0200 Subject: [PATCH] Log into SessionLog --- gui/include/avopenglwidget.h | 5 +++-- gui/include/videodecoder.h | 7 ++++++- gui/src/avopenglframeuploader.cpp | 2 +- gui/src/avopenglwidget.cpp | 14 ++++---------- gui/src/streamsession.cpp | 5 +++-- gui/src/videodecoder.cpp | 14 ++++++++------ 6 files changed, 25 insertions(+), 22 deletions(-) diff --git a/gui/include/avopenglwidget.h b/gui/include/avopenglwidget.h index 2396547..3d5982c 100644 --- a/gui/include/avopenglwidget.h +++ b/gui/include/avopenglwidget.h @@ -21,6 +21,8 @@ #include #include +#include + extern "C" { #include @@ -35,7 +37,7 @@ struct AVOpenGLFrame unsigned int width; unsigned int height; - bool Update(AVFrame *frame); + bool Update(AVFrame *frame, ChiakiLog *log); }; class AVOpenGLWidget: public QOpenGLWidget @@ -65,7 +67,6 @@ class AVOpenGLWidget: public QOpenGLWidget protected: void initializeGL() override; - void resizeGL(int w, int h) override; void paintGL() override; }; diff --git a/gui/include/videodecoder.h b/gui/include/videodecoder.h index 12316aa..ffc65e5 100644 --- a/gui/include/videodecoder.h +++ b/gui/include/videodecoder.h @@ -20,6 +20,8 @@ #include "exception.h" +#include + #include #include @@ -41,16 +43,19 @@ class VideoDecoder: public QObject Q_OBJECT public: - VideoDecoder(); + VideoDecoder(ChiakiLog *log); ~VideoDecoder(); void PushFrame(uint8_t *buf, size_t buf_size); AVFrame *PullFrame(); + ChiakiLog *GetChiakiLog() { return log; } + signals: void FramesAvailable(); private: + ChiakiLog *log; QMutex mutex; AVCodec *codec; diff --git a/gui/src/avopenglframeuploader.cpp b/gui/src/avopenglframeuploader.cpp index 6431218..1c2905a 100644 --- a/gui/src/avopenglframeuploader.cpp +++ b/gui/src/avopenglframeuploader.cpp @@ -41,7 +41,7 @@ void AVOpenGLFrameUploader::UpdateFrame() if(!next_frame) return; - bool success = widget->GetBackgroundFrame()->Update(next_frame); + bool success = widget->GetBackgroundFrame()->Update(next_frame, decoder->GetChiakiLog()); av_frame_free(&next_frame); if(success) diff --git a/gui/src/avopenglwidget.cpp b/gui/src/avopenglwidget.cpp index fed5e2b..d0d3bf1 100644 --- a/gui/src/avopenglwidget.cpp +++ b/gui/src/avopenglwidget.cpp @@ -107,14 +107,13 @@ void AVOpenGLWidget::SwapFrames() QMetaObject::invokeMethod(this, "update"); } -bool AVOpenGLFrame::Update(AVFrame *frame) +bool AVOpenGLFrame::Update(AVFrame *frame, ChiakiLog *log) { auto f = QOpenGLContext::currentContext()->functions(); if(frame->format != AV_PIX_FMT_YUV420P) { - // TODO: log to somewhere else - printf("Invalid Format\n"); + CHIAKI_LOGE(log, "AVOpenGLFrame got AVFrame with invalid format"); return false; } @@ -175,8 +174,7 @@ void AVOpenGLWidget::initializeGL() std::vector info_log(info_log_size); f->glGetProgramInfoLog(program, info_log_size, &info_log_size, info_log.data()); f->glDeleteProgram(program); - // TODO: log to somewhere else - printf("Failed to Link Shader Program:\n%s\n", info_log.data()); + CHIAKI_LOGE(decoder->GetChiakiLog(), "Failed to Link Shader Program:\n%s", info_log.data()); return; } @@ -222,7 +220,7 @@ void AVOpenGLWidget::initializeGL() frame_uploader_context->setShareContext(context()); if(!frame_uploader_context->create()) { - printf("Failed to create upload context!\n"); // TODO: log to somewhere else + CHIAKI_LOGE(decoder->GetChiakiLog(), "Failed to create upload OpenGL context"); return; } @@ -236,10 +234,6 @@ void AVOpenGLWidget::initializeGL() frame_uploader_thread->start(); } -void AVOpenGLWidget::resizeGL(int w, int h) -{ -} - void AVOpenGLWidget::paintGL() { auto f = QOpenGLContext::currentContext()->extraFunctions(); diff --git a/gui/src/streamsession.cpp b/gui/src/streamsession.cpp index bd5b8fb..4677111 100644 --- a/gui/src/streamsession.cpp +++ b/gui/src/streamsession.cpp @@ -36,10 +36,11 @@ static void EventCb(ChiakiEvent *event, void *user); StreamSession::StreamSession(const StreamSessionConnectInfo &connect_info, QObject *parent) : QObject(parent), - log(this, connect_info.log_level_mask, connect_info.log_file) + log(this, connect_info.log_level_mask, connect_info.log_file), #if CHIAKI_GUI_ENABLE_QT_GAMEPAD - ,gamepad(nullptr) + gamepad(nullptr), #endif + video_decoder(log.GetChiakiLog()) { QByteArray host_str = connect_info.host.toUtf8(); QByteArray registkey_str = connect_info.registkey.toUtf8(); diff --git a/gui/src/videodecoder.cpp b/gui/src/videodecoder.cpp index e78662b..88f6ad0 100644 --- a/gui/src/videodecoder.cpp +++ b/gui/src/videodecoder.cpp @@ -21,7 +21,7 @@ #include -VideoDecoder::VideoDecoder() +VideoDecoder::VideoDecoder(ChiakiLog *log) : log(log) { codec = avcodec_find_decoder(AV_CODEC_ID_H264); if(!codec) @@ -60,25 +60,27 @@ send_packet: { if(r == AVERROR(EAGAIN)) { - printf("avcodec internal buffer is full, removing frames\n"); // TODO: log to somewhere else + CHIAKI_LOGE(log, "AVCodec internal buffer is full removing frames before pushing"); AVFrame *frame = av_frame_alloc(); if(!frame) { - printf("failed to alloc frame\n"); + CHIAKI_LOGE(log, "Failed to alloc AVFrame"); return; } r = avcodec_receive_frame(codec_context, frame); av_frame_free(&frame); if(r != 0) { - printf("failed to pull packet\n"); + CHIAKI_LOGE(log, "Failed to pull frame"); return; } goto send_packet; } else { - printf("failed to push frame\n"); + char errbuf[128]; + av_make_error_string(errbuf, sizeof(errbuf), r); + CHIAKI_LOGE(log, "Failed to push frame: %s", errbuf); return; } } @@ -116,7 +118,7 @@ AVFrame *VideoDecoder::PullFrame() if(r != 0) { if(r != AVERROR(EAGAIN)) - printf("decoding with ffmpeg failed!!\n"); // TODO: log somewhere else + CHIAKI_LOGE(log, "Decoding with FFMPEG failed"); av_frame_free(&frame); return frame_last; }