Start working on a VDPAUVideoDecoder

This commit is contained in:
rock88 2020-05-13 00:42:31 +03:00
parent 9d8d6c51a4
commit d9d25622e7
7 changed files with 74 additions and 7 deletions

View file

@ -86,6 +86,7 @@
3661D2F92469D1940060EE24 /* FFmpegVideoDecoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3661D2F72469D1940060EE24 /* FFmpegVideoDecoder.cpp */; };
3661D2FF2469E0C00060EE24 /* GLVideoRenderer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3661D2FD2469E0C00060EE24 /* GLVideoRenderer.cpp */; };
3661D3022469EFFA0060EE24 /* RetroAudioRenderer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3661D3002469EFFA0060EE24 /* RetroAudioRenderer.cpp */; };
3661D30A246B0C820060EE24 /* VDPAUVideoDecoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3661D308246B0C820060EE24 /* VDPAUVideoDecoder.cpp */; };
367CD95A245DE25F00A95738 /* StreamWindow.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 367CD958245DE25F00A95738 /* StreamWindow.cpp */; };
36A0C0372461DBA30083289C /* AddHostButton.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 36A0C0352461DBA30083289C /* AddHostButton.cpp */; };
36A0C03A2461E4C00083289C /* SettingsWindow.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 36A0C0382461E4C00083289C /* SettingsWindow.cpp */; };
@ -282,6 +283,9 @@
3661D2FE2469E0C00060EE24 /* GLVideoRenderer.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = GLVideoRenderer.hpp; sourceTree = "<group>"; };
3661D3002469EFFA0060EE24 /* RetroAudioRenderer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RetroAudioRenderer.cpp; sourceTree = "<group>"; };
3661D3012469EFFA0060EE24 /* RetroAudioRenderer.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = RetroAudioRenderer.hpp; sourceTree = "<group>"; };
3661D308246B0C820060EE24 /* VDPAUVideoDecoder.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = VDPAUVideoDecoder.cpp; sourceTree = "<group>"; };
3661D309246B0C820060EE24 /* VDPAUVideoDecoder.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = VDPAUVideoDecoder.hpp; sourceTree = "<group>"; };
3661D30B246B1C680060EE24 /* build_ffmpeg_lakka_switch.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = build_ffmpeg_lakka_switch.sh; sourceTree = "<group>"; };
367CD958245DE25F00A95738 /* StreamWindow.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = StreamWindow.cpp; sourceTree = "<group>"; };
367CD959245DE25F00A95738 /* StreamWindow.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = StreamWindow.hpp; sourceTree = "<group>"; };
36A0C0352461DBA30083289C /* AddHostButton.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = AddHostButton.cpp; sourceTree = "<group>"; };
@ -660,6 +664,8 @@
children = (
3661D2F72469D1940060EE24 /* FFmpegVideoDecoder.cpp */,
3661D2F82469D1940060EE24 /* FFmpegVideoDecoder.hpp */,
3661D308246B0C820060EE24 /* VDPAUVideoDecoder.cpp */,
3661D309246B0C820060EE24 /* VDPAUVideoDecoder.hpp */,
3661D2FA2469D1E50060EE24 /* IFFmpegVideoDecoder.hpp */,
);
path = ffmpeg;
@ -680,6 +686,7 @@
children = (
3602C3C0245DC7E300368900 /* Makefile */,
36A0C03E2461FFF10083289C /* build_opus_lakka_switch.sh */,
3661D30B246B1C680060EE24 /* build_ffmpeg_lakka_switch.sh */,
3652F006245C2918001FABF3 /* libgamestream */,
36B406932459F41E005BD903 /* src */,
36DFDCF62459F80600FC51CE /* third_party */,
@ -920,6 +927,7 @@
3652EFD5245B3B00001FABF3 /* canvas.cpp in Sources */,
3652F078245C292B001FABF3 /* FakeCallbacks.c in Sources */,
3652F06B245C292B001FABF3 /* host.c in Sources */,
3661D30A246B0C820060EE24 /* VDPAUVideoDecoder.cpp in Sources */,
3602C3BA245DB3C800368900 /* AppListWindow.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

View file

@ -16,7 +16,7 @@ extern "C" {
#include "client.h"
}
static struct retro_hw_render_callback hw_render;
struct retro_hw_render_callback hw_render;
#if defined(HAVE_PSGL)
#define RARCH_GL_FRAMEBUFFER GL_FRAMEBUFFER_OES

View file

@ -16,9 +16,7 @@
#define DECODER_BUFFER_SIZE 92 * 1024
FFmpegVideoDecoder::FFmpegVideoDecoder(IFFmpegHardwareVideoDecoder* hardware_video_decoder) {
m_hardware_video_decoder = hardware_video_decoder;
FFmpegVideoDecoder::FFmpegVideoDecoder() {
pthread_mutex_init(&m_mutex, NULL);
}

View file

@ -10,9 +10,13 @@ public:
class FFmpegVideoDecoder: public IFFmpegVideoDecoder {
public:
FFmpegVideoDecoder(IFFmpegHardwareVideoDecoder* hardware_video_decoder = nullptr);
FFmpegVideoDecoder();
~FFmpegVideoDecoder();
void set_hardware_video_decoder(IFFmpegHardwareVideoDecoder* hardware_video_decoder) {
m_hardware_video_decoder = hardware_video_decoder;
}
int setup(int video_format, int width, int height, int redraw_rate, void *context, int dr_flags) override;
void cleanup() override;
int submit_decode_unit(PDECODE_UNIT decode_unit) override;
@ -23,7 +27,7 @@ private:
int decode(char* indata, int inlen);
AVFrame* get_frame(bool native_frame);
IFFmpegHardwareVideoDecoder* m_hardware_video_decoder;
IFFmpegHardwareVideoDecoder* m_hardware_video_decoder = nullptr;
AVPacket m_packet;
AVCodec* m_decoder = nullptr;

View file

@ -0,0 +1,39 @@
#include "VDPAUVideoDecoder.hpp"
#include "Log.h"
#include <libavcodec/vdpau.h>
#include <libavutil/hwcontext.h>
#include <libavutil/hwcontext_vdpau.h>
// TODO: Currently doesn't work :(
VDPAUVideoDecoder::VDPAUVideoDecoder() {
putenv("VDPAU_DRIVER=tegra");
putenv("VDPAU_DRIVER_PATH=/storage/cores");
int err = av_hwdevice_ctx_create(&m_hw_context, AV_HWDEVICE_TYPE_VDPAU, nullptr, nullptr, 0);
if (err) {
LOG_FMT("Failed to create VDPAU context: %d\n", err);
} else {
LOG("Success create VDPAU context\n");
}
}
VDPAUVideoDecoder::~VDPAUVideoDecoder() {
if (m_hw_context) {
av_buffer_unref(&m_hw_context);
}
}
bool VDPAUVideoDecoder::prepare_decoder_context(AVCodecContext *context, AVDictionary **options) {
if (m_hw_context) {
context->hw_device_ctx = av_buffer_ref(m_hw_context);
context->hwaccel_flags |= AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH;
context->hwaccel_flags |= AV_HWACCEL_FLAG_IGNORE_LEVEL;
LOG("Using VDPAU accelerated renderer\n");
return true;
}
LOG("Failed to use VDPAU accelerated renderer\n");
return false;
}

View file

@ -0,0 +1,13 @@
#include "FFmpegVideoDecoder.hpp"
#pragma once
class VDPAUVideoDecoder: public IFFmpegHardwareVideoDecoder {
public:
VDPAUVideoDecoder();
~VDPAUVideoDecoder();
bool prepare_decoder_context(AVCodecContext *context, AVDictionary **options) override;
private:
AVBufferRef* m_hw_context = nullptr;
};

View file

@ -2,6 +2,7 @@
#include "LoadingOverlay.hpp"
#include "InputController.hpp"
#include "FFmpegVideoDecoder.hpp"
#include "VDPAUVideoDecoder.hpp"
#include "GLVideoRenderer.hpp"
#include "RetroAudioRenderer.hpp"
#include "nanovg.h"
@ -13,9 +14,13 @@ using namespace nanogui;
StreamWindow::StreamWindow(Widget *parent, const std::string &address, int app_id): Widget(parent) {
m_size = parent->size();
m_session = new MoonlightSession(address, app_id);
m_session->set_video_decoder(new FFmpegVideoDecoder());
auto video_decoder = new FFmpegVideoDecoder();
m_session->set_video_decoder(video_decoder);
m_session->set_video_renderer(new GLVideoRenderer());
//video_decoder->set_hardware_video_decoder(new VDPAUVideoDecoder());
#ifdef __LIBRETRO__
m_session->set_audio_renderer(new RetroAudioRenderer());
#endif