mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-02-16 10:30:47 +00:00
Cleanup and optimize FFmpeg code
This commit is contained in:
@@ -80,20 +80,22 @@ int ffmpeg_init(int videoFormat, int width, int height, int perf_lvl, int buffer
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (perf_lvl & DISABLE_LOOP_FILTER)
|
// Use low delay decoding
|
||||||
// Skip the loop filter for performance reasons
|
decoder_ctx->flags |= AV_CODEC_FLAG_LOW_DELAY;
|
||||||
decoder_ctx->skip_loop_filter = AVDISCARD_ALL;
|
|
||||||
|
|
||||||
if (perf_lvl & LOW_LATENCY_DECODE)
|
// Allow display of corrupt frames and frames missing references
|
||||||
// Use low delay single threaded encoding
|
decoder_ctx->flags |= AV_CODEC_FLAG_OUTPUT_CORRUPT;
|
||||||
decoder_ctx->flags |= AV_CODEC_FLAG_LOW_DELAY;
|
decoder_ctx->flags2 |= AV_CODEC_FLAG2_SHOW_ALL;
|
||||||
|
|
||||||
if (perf_lvl & SLICE_THREADING)
|
// Report decoding errors to allow us to request a key frame
|
||||||
|
decoder_ctx->err_recognition = AV_EF_EXPLODE;
|
||||||
|
|
||||||
|
if (perf_lvl & SLICE_THREADING) {
|
||||||
decoder_ctx->thread_type = FF_THREAD_SLICE;
|
decoder_ctx->thread_type = FF_THREAD_SLICE;
|
||||||
else
|
decoder_ctx->thread_count = thread_count;
|
||||||
decoder_ctx->thread_type = FF_THREAD_FRAME;
|
} else {
|
||||||
|
decoder_ctx->thread_count = 1;
|
||||||
decoder_ctx->thread_count = thread_count;
|
}
|
||||||
|
|
||||||
decoder_ctx->width = width;
|
decoder_ctx->width = width;
|
||||||
decoder_ctx->height = height;
|
decoder_ctx->height = height;
|
||||||
|
|||||||
@@ -21,18 +21,8 @@
|
|||||||
|
|
||||||
#include <libavcodec/avcodec.h>
|
#include <libavcodec/avcodec.h>
|
||||||
|
|
||||||
// Disables the deblocking filter at the cost of image quality
|
// Enable multi-threaded decoding
|
||||||
#define DISABLE_LOOP_FILTER 0x1
|
|
||||||
// Uses the low latency decode flag (disables multithreading)
|
|
||||||
#define LOW_LATENCY_DECODE 0x2
|
|
||||||
// Threads process each slice, rather than each frame
|
|
||||||
#define SLICE_THREADING 0x4
|
#define SLICE_THREADING 0x4
|
||||||
// Uses nonstandard speedup tricks
|
|
||||||
#define FAST_DECODE 0x8
|
|
||||||
// Uses bilinear filtering instead of bicubic
|
|
||||||
#define BILINEAR_FILTERING 0x10
|
|
||||||
// Uses a faster bilinear filtering with lower image quality
|
|
||||||
#define FAST_BILINEAR_FILTERING 0x20
|
|
||||||
// Uses hardware acceleration
|
// Uses hardware acceleration
|
||||||
#define VDPAU_ACCELERATION 0x40
|
#define VDPAU_ACCELERATION 0x40
|
||||||
#define VAAPI_ACCELERATION 0x80
|
#define VAAPI_ACCELERATION 0x80
|
||||||
|
|||||||
@@ -29,13 +29,12 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#define DECODER_BUFFER_SIZE 92*1024
|
#define DECODER_BUFFER_SIZE 92*1024
|
||||||
|
#define SLICES_PER_FRAME 4
|
||||||
|
|
||||||
static char* ffmpeg_buffer;
|
static char* ffmpeg_buffer;
|
||||||
|
|
||||||
static int sdl_setup(int videoFormat, int width, int height, int redrawRate, void* context, int drFlags) {
|
static int sdl_setup(int videoFormat, int width, int height, int redrawRate, void* context, int drFlags) {
|
||||||
int avc_flags = SLICE_THREADING;
|
if (ffmpeg_init(videoFormat, width, height, SLICE_THREADING, SDL_BUFFER_FRAMES, SLICES_PER_FRAME) < 0) {
|
||||||
|
|
||||||
if (ffmpeg_init(videoFormat, width, height, avc_flags, SDL_BUFFER_FRAMES, sysconf(_SC_NPROCESSORS_ONLN)) < 0) {
|
|
||||||
fprintf(stderr, "Couldn't initialize video decoding\n");
|
fprintf(stderr, "Couldn't initialize video decoding\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -93,5 +92,5 @@ DECODER_RENDERER_CALLBACKS decoder_callbacks_sdl = {
|
|||||||
.setup = sdl_setup,
|
.setup = sdl_setup,
|
||||||
.cleanup = sdl_cleanup,
|
.cleanup = sdl_cleanup,
|
||||||
.submitDecodeUnit = sdl_submit_decode_unit,
|
.submitDecodeUnit = sdl_submit_decode_unit,
|
||||||
.capabilities = CAPABILITY_SLICES_PER_FRAME(4) | CAPABILITY_REFERENCE_FRAME_INVALIDATION_AVC | CAPABILITY_DIRECT_SUBMIT,
|
.capabilities = CAPABILITY_SLICES_PER_FRAME(SLICES_PER_FRAME) | CAPABILITY_REFERENCE_FRAME_INVALIDATION_AVC | CAPABILITY_DIRECT_SUBMIT,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
#define DECODER_BUFFER_SIZE 92*1024
|
#define DECODER_BUFFER_SIZE 92*1024
|
||||||
#define X11_VDPAU_ACCELERATION ENABLE_HARDWARE_ACCELERATION_1
|
#define X11_VDPAU_ACCELERATION ENABLE_HARDWARE_ACCELERATION_1
|
||||||
#define X11_VAAPI_ACCELERATION ENABLE_HARDWARE_ACCELERATION_2
|
#define X11_VAAPI_ACCELERATION ENABLE_HARDWARE_ACCELERATION_2
|
||||||
|
#define SLICES_PER_FRAME 4
|
||||||
|
|
||||||
static char* ffmpeg_buffer = NULL;
|
static char* ffmpeg_buffer = NULL;
|
||||||
|
|
||||||
@@ -124,13 +125,15 @@ int x11_setup(int videoFormat, int width, int height, int redrawRate, void* cont
|
|||||||
}
|
}
|
||||||
XFlush(display);
|
XFlush(display);
|
||||||
|
|
||||||
int avc_flags = SLICE_THREADING;
|
int avc_flags;
|
||||||
if (drFlags & X11_VDPAU_ACCELERATION)
|
if (drFlags & X11_VDPAU_ACCELERATION)
|
||||||
avc_flags |= VDPAU_ACCELERATION;
|
avc_flags = VDPAU_ACCELERATION;
|
||||||
else if (drFlags & X11_VAAPI_ACCELERATION)
|
else if (drFlags & X11_VAAPI_ACCELERATION)
|
||||||
avc_flags |= VAAPI_ACCELERATION;
|
avc_flags = VAAPI_ACCELERATION;
|
||||||
|
else
|
||||||
|
avc_flags = SLICE_THREADING;
|
||||||
|
|
||||||
if (ffmpeg_init(videoFormat, width, height, avc_flags, 2, 2) < 0) {
|
if (ffmpeg_init(videoFormat, width, height, avc_flags, 2, SLICES_PER_FRAME) < 0) {
|
||||||
fprintf(stderr, "Couldn't initialize video decoding\n");
|
fprintf(stderr, "Couldn't initialize video decoding\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -185,7 +188,7 @@ DECODER_RENDERER_CALLBACKS decoder_callbacks_x11 = {
|
|||||||
.setup = x11_setup,
|
.setup = x11_setup,
|
||||||
.cleanup = x11_cleanup,
|
.cleanup = x11_cleanup,
|
||||||
.submitDecodeUnit = x11_submit_decode_unit,
|
.submitDecodeUnit = x11_submit_decode_unit,
|
||||||
.capabilities = CAPABILITY_SLICES_PER_FRAME(4) | CAPABILITY_REFERENCE_FRAME_INVALIDATION_AVC | CAPABILITY_DIRECT_SUBMIT,
|
.capabilities = CAPABILITY_SLICES_PER_FRAME(SLICES_PER_FRAME) | CAPABILITY_REFERENCE_FRAME_INVALIDATION_AVC | CAPABILITY_DIRECT_SUBMIT,
|
||||||
};
|
};
|
||||||
|
|
||||||
DECODER_RENDERER_CALLBACKS decoder_callbacks_x11_vdpau = {
|
DECODER_RENDERER_CALLBACKS decoder_callbacks_x11_vdpau = {
|
||||||
|
|||||||
Reference in New Issue
Block a user