Remove AVFrame copy...

This commit is contained in:
rock88 2021-02-23 14:53:54 +03:00
parent d3233d1ee0
commit c4a10ced6f
3 changed files with 10 additions and 55 deletions

View file

@ -1,7 +1,5 @@
#include <iostream>
#include "Singleton.hpp"
#include <mutex>
#include <string>
#include <thread>
extern "C" {
#include <libavcodec/avcodec.h>
@ -9,55 +7,12 @@ extern "C" {
#pragma once
class AVFrameHolder {
class AVFrameHolder: public Singleton<AVFrameHolder> {
public:
static AVFrameHolder* holder() {
static AVFrameHolder holder;
return &holder;
}
void push(AVFrame *frame) {
std::lock_guard<std::mutex> lock(m_mutex);
if (m_frame) {
av_frame_free(&m_frame);
m_frame = nullptr;
}
if (frame == nullptr) {
printf("frame is nullptr...\n");
return;
}
m_frame = av_frame_alloc();
if (m_frame == nullptr) {
printf("m_frame is nullptr...\n");
return;
}
m_frame->format = frame->format;
m_frame->width = frame->width;
m_frame->height = frame->height;
m_frame->channels = frame->channels;
m_frame->channel_layout = frame->channel_layout;
m_frame->nb_samples = frame->nb_samples;
int result = 0;
result = av_frame_get_buffer(m_frame, 32);
if (result != 0) {
Logger::error("AVFrameHolder", "av_frame_get_buffer");
}
result = av_frame_copy(m_frame, frame);
if (result != 0) {
Logger::error("AVFrameHolder", "av_frame_copy");
}
result = av_frame_copy_props(m_frame, frame);
if (result != 0) {
Logger::error("AVFrameHolder", "av_frame_copy_props");
}
m_frame = frame;
}
void get(const std::function<void(AVFrame*)> fn) {
@ -69,14 +24,13 @@ public:
}
void cleanup() {
// TODO: plz...
std::lock_guard<std::mutex> lock(m_mutex);
m_frame = nullptr;
}
private:
AVFrameHolder() {};
std::mutex m_mutex;
AVFrame *m_frame = nullptr;
bool m_has_frame = false;
};

View file

@ -241,12 +241,11 @@ void MoonlightSession::stop(int terminate_app) {
}
LiStopConnection();
AVFrameHolder::holder()->cleanup();
}
void MoonlightSession::draw() {
if (m_video_decoder && m_video_renderer) {
AVFrameHolder::holder()->get([this](auto frame) {
AVFrameHolder::instance().get([this](auto frame) {
m_video_renderer->draw(m_config.width, m_config.height, frame);
});

View file

@ -194,6 +194,8 @@ void FFmpegVideoDecoder::cleanup() {
m_ffmpeg_buffer = nullptr;
}
AVFrameHolder::instance().cleanup();
Logger::info("FFmpeg", "Cleanup done!");
}
@ -256,7 +258,7 @@ int FFmpegVideoDecoder::submit_decode_unit(PDECODE_UNIT decode_unit) {
DBG();
//if (pthread_mutex_lock(&m_mutex) == 0) {
m_frame = get_frame(true);
AVFrameHolder::holder()->push(m_frame);
AVFrameHolder::instance().push(m_frame);
DBG();//
// Push event!!
//pthread_mutex_unlock(&m_mutex);