1
0
mirror of https://github.com/jojo61/vdr-plugin-softhdcuvid.git synced 2023-10-10 13:37:41 +02:00

Vaapi changed to egl

This commit is contained in:
jojo61 2019-10-04 10:37:57 +02:00
parent cdac2bcc3d
commit 4d2735a971
7 changed files with 1895 additions and 1504 deletions

View File

@ -7,9 +7,9 @@
# This name will be used in the '-P...' option of VDR to load the plugin. # This name will be used in the '-P...' option of VDR to load the plugin.
# By default the main source file also carries this name. # By default the main source file also carries this name.
PLUGIN = softhdcuvid
### Configuration (edit this for your needs) ### Configuration (edit this for your needs)
# comment out if not needed
# what kind of driver do we make - # what kind of driver do we make -
# if VAAPI is enabled the drivername is softhdvaapi # if VAAPI is enabled the drivername is softhdvaapi
@ -17,18 +17,30 @@ PLUGIN = softhdcuvid
#VAAPI=1 #VAAPI=1
CUVID=1 CUVID=1
# use libplacebo - available for both drivers
#LIBPLACEBO=1
# use YADIF deint - only available with cuvid
#YADIF=1
# support OPENGLOSD - only configurable with cuvid
OPENGLOSD=1
# use Libplacebo - only configurable with cuvid
LIBPLACEBO=1
# use YADIF deint - only configurable with cuvid
YADIF=0
#--------------------- no more config needed past this point-------------------------------- #--------------------- no more config needed past this point--------------------------------
# support alsa audio output module PLUGIN = softhdcuvid
# support OPENGLOSD always needed
OPENGLOSD=1
# support alsa audio output module
ALSA ?= $(shell pkg-config --exists alsa && echo 1) ALSA ?= $(shell pkg-config --exists alsa && echo 1)
# support OSS audio output module # support OSS audio output module
OSS ?= 1 OSS ?= 1
@ -48,7 +60,7 @@ SWRESAMPLE = 1
#AVRESAMPLE = 1 #AVRESAMPLE = 1
#endif #endif
CONFIG := -DDEBUG #-DOSD_DEBUG # enable debug output+functions CONFIG := #-DDEBUG #-DOSD_DEBUG # enable debug output+functions
CONFIG += -DHAVE_GL # needed for mpv libs CONFIG += -DHAVE_GL # needed for mpv libs
#CONFIG += -DSTILL_DEBUG=2 # still picture debug verbose level #CONFIG += -DSTILL_DEBUG=2 # still picture debug verbose level
CONFIG += -DAV_INFO -DAV_INFO_TIME=3000 # info/debug a/v sync CONFIG += -DAV_INFO -DAV_INFO_TIME=3000 # info/debug a/v sync
@ -114,8 +126,8 @@ CONFIG += -DUSE_OSS
endif endif
ifeq ($(OPENGL),1) ifeq ($(OPENGL),1)
_CFLAGS += $(shell pkg-config --cflags libva-glx) #_CFLAGS += $(shell pkg-config --cflags libva-glx)
LIBS += $(shell pkg-config --libs libva-glx) #LIBS += $(shell pkg-config --libs libva-glx)
endif endif
ifeq ($(OPENGLOSD),1) ifeq ($(OPENGLOSD),1)
@ -125,17 +137,16 @@ endif
ifeq ($(OPENGL),1) ifeq ($(OPENGL),1)
CONFIG += -DUSE_GLX CONFIG += -DUSE_GLX
_CFLAGS += $(shell pkg-config --cflags gl glu glew) _CFLAGS += $(shell pkg-config --cflags gl glu glew)
LIBS += $(shell pkg-config --libs gl glu glew) #LIBS += $(shell pkg-config --libs glu glew)
_CFLAGS += $(shell pkg-config --cflags glew)
LIBS += $(shell pkg-config --libs glew)
_CFLAGS += $(shell pkg-config --cflags freetype2) _CFLAGS += $(shell pkg-config --cflags freetype2)
LIBS += $(shell pkg-config --libs freetype2) LIBS += $(shell pkg-config --libs freetype2)
endif endif
ifeq ($(VAAPI),1) ifeq ($(VAAPI),1)
CONFIG += -DVAAPI -DUSE_OPENGLOSD CONFIG += -DVAAPI
LIBPLACEBO=1 #LIBPLACEBO=1
PLUGIN = softhdvaapi PLUGIN = softhdvaapi
LIBS += -lEGL -lEGL_mesa
endif endif
ifeq ($(LIBPLACEBO),1) ifeq ($(LIBPLACEBO),1)
@ -144,6 +155,7 @@ endif
ifeq ($(CUVID),1) ifeq ($(CUVID),1)
CONFIG += -DCUVID # enable CUVID decoder CONFIG += -DCUVID # enable CUVID decoder
LIBS += -lEGL -lGL
ifeq ($(YADIF),1) ifeq ($(YADIF),1)
CONFIG += -DYADIF # Yadif only with CUVID CONFIG += -DYADIF # Yadif only with CUVID
endif endif
@ -235,10 +247,10 @@ LIBS += -lplacebo -lglut
endif endif
ifeq ($(CUVID),1) ifeq ($(CUVID),1)
LIBS += -lcuda -L/usr/local/cuda/targets/x86_64-linux/lib -lcudart -lnvcuvid LIBS += -lcuda -L/usr/local/cuda/targets/x86_64-linux/lib -lcudart -lnvcuvid
endif endif
LIBS += -lGLEW -lGLX -ldl LIBS += -lGLEW -lGLU -ldl
### Includes and Defines (add further entries here): ### Includes and Defines (add further entries here):
INCLUDES += INCLUDES +=

1222
audio.c

File diff suppressed because it is too large Load Diff

290
codec.c
View File

@ -315,7 +315,7 @@ void CodecVideoOpen(VideoDecoder * decoder, int codec_id)
decoder->VideoCtx->pkt_timebase.den = 90000; decoder->VideoCtx->pkt_timebase.den = 90000;
decoder->VideoCtx->framerate.num = 50; decoder->VideoCtx->framerate.num = 50;
decoder->VideoCtx->framerate.den = 1; decoder->VideoCtx->framerate.den = 1;
decoder->VideoCtx->extra_hw_frames = 8; // VIDEO_SURFACES_MAX +1
pthread_mutex_lock(&CodecLockMutex); pthread_mutex_lock(&CodecLockMutex);
// open codec // open codec
@ -323,6 +323,7 @@ void CodecVideoOpen(VideoDecoder * decoder, int codec_id)
deint = 2; deint = 2;
#endif #endif
#ifdef VAAPI #ifdef VAAPI
decoder->VideoCtx->extra_hw_frames = 8; // VIDEO_SURFACES_MAX +1
if (video_codec->capabilities & (AV_CODEC_CAP_AUTO_THREADS)) { if (video_codec->capabilities & (AV_CODEC_CAP_AUTO_THREADS)) {
Debug(3,"codec: auto threads enabled"); Debug(3,"codec: auto threads enabled");
decoder->VideoCtx->thread_count = 0; decoder->VideoCtx->thread_count = 0;
@ -1220,23 +1221,23 @@ static void CodecAudioSetClock(AudioDecoder * audio_decoder, int64_t pts)
delay = AudioGetDelay(); delay = AudioGetDelay();
if (!delay) { if (!delay) {
return; return;
} }
clock_gettime(CLOCK_MONOTONIC, &nowtime); clock_gettime(CLOCK_MONOTONIC, &nowtime);
if (!audio_decoder->LastDelay) { if (!audio_decoder->LastDelay) {
audio_decoder->LastTime = nowtime; audio_decoder->LastTime = nowtime;
audio_decoder->LastPTS = pts; audio_decoder->LastPTS = pts;
audio_decoder->LastDelay = delay; audio_decoder->LastDelay = delay;
audio_decoder->Drift = 0; audio_decoder->Drift = 0;
audio_decoder->DriftFrac = 0; audio_decoder->DriftFrac = 0;
Debug(3, "codec/audio: inital drift delay %" PRId64 "ms\n", Debug(3, "codec/audio: inital drift delay %" PRId64 "ms\n",
delay / 90); delay / 90);
return; return;
} }
// collect over some time // collect over some time
pts_diff = pts - audio_decoder->LastPTS; pts_diff = pts - audio_decoder->LastPTS;
if (pts_diff < 10 * 1000 * 90) { if (pts_diff < 10 * 1000 * 90) {
return; return;
} }
tim_diff = (nowtime.tv_sec - audio_decoder->LastTime.tv_sec) tim_diff = (nowtime.tv_sec - audio_decoder->LastTime.tv_sec)
@ -1262,51 +1263,51 @@ static void CodecAudioSetClock(AudioDecoder * audio_decoder, int64_t pts)
// underruns and av_resample have the same time :((( // underruns and av_resample have the same time :(((
if (abs(drift) > 10 * 90) { if (abs(drift) > 10 * 90) {
// drift too big, pts changed? // drift too big, pts changed?
Debug(3, "codec/audio: drift(%6d) %3dms reset\n", Debug(3, "codec/audio: drift(%6d) %3dms reset\n",
audio_decoder->DriftCorr, drift / 90); audio_decoder->DriftCorr, drift / 90);
audio_decoder->LastDelay = 0; audio_decoder->LastDelay = 0;
#ifdef DEBUG #ifdef DEBUG
corr = 0; // keep gcc happy corr = 0; // keep gcc happy
#endif #endif
} else { } else {
drift += audio_decoder->Drift; drift += audio_decoder->Drift;
audio_decoder->Drift = drift; audio_decoder->Drift = drift;
corr = (10 * audio_decoder->HwSampleRate * drift) / (90 * 1000); corr = (10 * audio_decoder->HwSampleRate * drift) / (90 * 1000);
// SPDIF/HDMI passthrough // SPDIF/HDMI passthrough
if ((CodecAudioDrift & CORRECT_AC3) && (!(CodecPassthrough & CodecAC3) if ((CodecAudioDrift & CORRECT_AC3) && (!(CodecPassthrough & CodecAC3)
|| audio_decoder->AudioCtx->codec_id != AV_CODEC_ID_AC3) || audio_decoder->AudioCtx->codec_id != AV_CODEC_ID_AC3)
&& (!(CodecPassthrough & CodecEAC3) && (!(CodecPassthrough & CodecEAC3)
|| audio_decoder->AudioCtx->codec_id != AV_CODEC_ID_EAC3)) { || audio_decoder->AudioCtx->codec_id != AV_CODEC_ID_EAC3)) {
audio_decoder->DriftCorr = -corr; audio_decoder->DriftCorr = -corr;
} }
if (audio_decoder->DriftCorr < -20000) { // limit correction if (audio_decoder->DriftCorr < -20000) { // limit correction
audio_decoder->DriftCorr = -20000; audio_decoder->DriftCorr = -20000;
} else if (audio_decoder->DriftCorr > 20000) { } else if (audio_decoder->DriftCorr > 20000) {
audio_decoder->DriftCorr = 20000; audio_decoder->DriftCorr = 20000;
} }
} }
// FIXME: this works with libav 0.8, and only with >10ms with ffmpeg 0.10 // FIXME: this works with libav 0.8, and only with >10ms with ffmpeg 0.10
if (audio_decoder->AvResample && audio_decoder->DriftCorr) { if (audio_decoder->AvResample && audio_decoder->DriftCorr) {
int distance; int distance;
// try workaround for buggy ffmpeg 0.10 // try workaround for buggy ffmpeg 0.10
if (abs(audio_decoder->DriftCorr) < 2000) { if (abs(audio_decoder->DriftCorr) < 2000) {
distance = (pts_diff * audio_decoder->HwSampleRate) / (900 * 1000); distance = (pts_diff * audio_decoder->HwSampleRate) / (900 * 1000);
} else { } else {
distance = (pts_diff * audio_decoder->HwSampleRate) / (90 * 1000); distance = (pts_diff * audio_decoder->HwSampleRate) / (90 * 1000);
} }
av_resample_compensate(audio_decoder->AvResample, av_resample_compensate(audio_decoder->AvResample,
audio_decoder->DriftCorr / 10, distance); audio_decoder->DriftCorr / 10, distance);
} }
if (1) { if (1) {
static int c; static int c;
if (!(c++ % 10)) { if (!(c++ % 10)) {
Debug(3, "codec/audio: drift(%6d) %8dus %5d\n", Debug(3, "codec/audio: drift(%6d) %8dus %5d\n",
audio_decoder->DriftCorr, drift * 1000 / 90, corr); audio_decoder->DriftCorr, drift * 1000 / 90, corr);
} }
} }
} }
@ -1324,64 +1325,64 @@ static void CodecAudioUpdateFormat(AudioDecoder * audio_decoder)
int err; int err;
if (audio_decoder->ReSample) { if (audio_decoder->ReSample) {
audio_resample_close(audio_decoder->ReSample); audio_resample_close(audio_decoder->ReSample);
audio_decoder->ReSample = NULL; audio_decoder->ReSample = NULL;
} }
if (audio_decoder->AvResample) { if (audio_decoder->AvResample) {
av_resample_close(audio_decoder->AvResample); av_resample_close(audio_decoder->AvResample);
audio_decoder->AvResample = NULL; audio_decoder->AvResample = NULL;
audio_decoder->RemainCount = 0; audio_decoder->RemainCount = 0;
} }
audio_ctx = audio_decoder->AudioCtx; audio_ctx = audio_decoder->AudioCtx;
if ((err = CodecAudioUpdateHelper(audio_decoder, &passthrough))) { if ((err = CodecAudioUpdateHelper(audio_decoder, &passthrough))) {
Debug(3, "codec/audio: resample %dHz *%d -> %dHz *%d err %d\n", Debug(3, "codec/audio: resample %dHz *%d -> %dHz *%d err %d\n",
audio_ctx->sample_rate, audio_ctx->channels, audio_ctx->sample_rate, audio_ctx->channels,
audio_decoder->HwSampleRate, audio_decoder->HwChannels,err); audio_decoder->HwSampleRate, audio_decoder->HwChannels,err);
if (err == 1) { if (err == 1) {
audio_decoder->ReSample = audio_decoder->ReSample =
av_audio_resample_init(audio_decoder->HwChannels, av_audio_resample_init(audio_decoder->HwChannels,
audio_ctx->channels, audio_decoder->HwSampleRate, audio_ctx->channels, audio_decoder->HwSampleRate,
audio_ctx->sample_rate, audio_ctx->sample_fmt, audio_ctx->sample_rate, audio_ctx->sample_fmt,
audio_ctx->sample_fmt, 16, 10, 0, 0.8); audio_ctx->sample_fmt, 16, 10, 0, 0.8);
// libav-0.8_pre didn't support 6 -> 2 channels // libav-0.8_pre didn't support 6 -> 2 channels
if (!audio_decoder->ReSample) { if (!audio_decoder->ReSample) {
Error(_("codec/audio: resample setup error\n")); Error(_("codec/audio: resample setup error\n"));
audio_decoder->HwChannels = 0;
audio_decoder->HwSampleRate = 0;
}
return;
}
Debug(3, "codec/audio: audio setup error\n");
// FIXME: handle errors
audio_decoder->HwChannels = 0; audio_decoder->HwChannels = 0;
audio_decoder->HwSampleRate = 0; audio_decoder->HwSampleRate = 0;
} return;
return;
}
Debug(3, "codec/audio: audio setup error\n");
// FIXME: handle errors
audio_decoder->HwChannels = 0;
audio_decoder->HwSampleRate = 0;
return;
} }
if (passthrough) { // pass-through no conversion allowed if (passthrough) { // pass-through no conversion allowed
return; return;
} }
// prepare audio drift resample // prepare audio drift resample
#ifdef USE_AUDIO_DRIFT_CORRECTION #ifdef USE_AUDIO_DRIFT_CORRECTION
if (CodecAudioDrift & CORRECT_PCM) { if (CodecAudioDrift & CORRECT_PCM) {
if (audio_decoder->AvResample) { if (audio_decoder->AvResample) {
Error(_("codec/audio: overwrite resample\n")); Error(_("codec/audio: overwrite resample\n"));
} }
audio_decoder->AvResample = audio_decoder->AvResample =
av_resample_init(audio_decoder->HwSampleRate, av_resample_init(audio_decoder->HwSampleRate,
audio_decoder->HwSampleRate, 16, 10, 0, 0.8); audio_decoder->HwSampleRate, 16, 10, 0, 0.8);
if (!audio_decoder->AvResample) { if (!audio_decoder->AvResample) {
Error(_("codec/audio: AvResample setup error\n")); Error(_("codec/audio: AvResample setup error\n"));
} else { } else {
// reset drift to some default value // reset drift to some default value
audio_decoder->DriftCorr /= 2; audio_decoder->DriftCorr /= 2;
audio_decoder->DriftFrac = 0; audio_decoder->DriftFrac = 0;
av_resample_compensate(audio_decoder->AvResample, av_resample_compensate(audio_decoder->AvResample,
audio_decoder->DriftCorr / 10, audio_decoder->DriftCorr / 10,
10 * audio_decoder->HwSampleRate); 10 * audio_decoder->HwSampleRate);
} }
} }
#endif #endif
} }
@ -1718,22 +1719,22 @@ static void CodecAudioSetClock(AudioDecoder * audio_decoder, int64_t pts)
#endif #endif
#ifdef USE_AVRESAMPLE #ifdef USE_AVRESAMPLE
if (audio_decoder->Resample && audio_decoder->DriftCorr) { if (audio_decoder->Resample && audio_decoder->DriftCorr) {
int distance; int distance;
distance = (pts_diff * audio_decoder->HwSampleRate) / (900 * 1000); distance = (pts_diff * audio_decoder->HwSampleRate) / (900 * 1000);
if (avresample_set_compensation(audio_decoder->Resample, if (avresample_set_compensation(audio_decoder->Resample,
audio_decoder->DriftCorr / 10, distance)) { audio_decoder->DriftCorr / 10, distance)) {
Debug(3, "codec/audio: swr_set_compensation failed\n"); Debug(3, "codec/audio: swr_set_compensation failed\n");
} }
} }
#endif #endif
if (1) { if (1) {
static int c; static int c;
if (!(c++ % 10)) { if (!(c++ % 10)) {
Debug(3, "codec/audio: drift(%6d) %8dus %5d\n", Debug(3, "codec/audio: drift(%6d) %8dus %5d\n",
audio_decoder->DriftCorr, drift * 1000 / 90, corr); audio_decoder->DriftCorr, drift * 1000 / 90, corr);
} }
} }
#else #else
AudioSetClock(pts); AudioSetClock(pts);
@ -1825,55 +1826,56 @@ void CodecAudioDecode(AudioDecoder * audio_decoder, const AVPacket * avpkt)
AVCodecContext *audio_ctx = audio_decoder->AudioCtx; AVCodecContext *audio_ctx = audio_decoder->AudioCtx;
if (audio_ctx->codec_type == AVMEDIA_TYPE_AUDIO) { if (audio_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
int ret; int ret;
AVPacket pkt[1]; AVPacket pkt[1];
AVFrame *frame = audio_decoder->Frame; AVFrame *frame = audio_decoder->Frame;
av_frame_unref(frame); av_frame_unref(frame);
*pkt = *avpkt; // use copy *pkt = *avpkt; // use copy
ret = avcodec_send_packet(audio_ctx, pkt); ret = avcodec_send_packet(audio_ctx, pkt);
if (ret < 0) { if (ret < 0) {
Debug(3, "codec: sending audio packet failed"); Debug(3, "codec: sending audio packet failed");
return; return;
} }
ret = avcodec_receive_frame(audio_ctx, frame); ret = avcodec_receive_frame(audio_ctx, frame);
if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) { if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) {
Debug(3, "codec: receiving audio frame failed"); Debug(3, "codec: receiving audio frame failed");
return; return;
} }
if (ret >= 0) {
// update audio clock if (ret >= 0) {
if (avpkt->pts != (int64_t) AV_NOPTS_VALUE) { // update audio clock
CodecAudioSetClock(audio_decoder, avpkt->pts); if (avpkt->pts != (int64_t) AV_NOPTS_VALUE) {
} CodecAudioSetClock(audio_decoder, avpkt->pts);
// format change }
if (audio_decoder->Passthrough != CodecPassthrough || audio_decoder->SampleRate != audio_ctx->sample_rate // format change
|| audio_decoder->Channels != audio_ctx->channels) { if (audio_decoder->Passthrough != CodecPassthrough || audio_decoder->SampleRate != audio_ctx->sample_rate
CodecAudioUpdateFormat(audio_decoder); || audio_decoder->Channels != audio_ctx->channels) {
} CodecAudioUpdateFormat(audio_decoder);
if (!audio_decoder->HwSampleRate || !audio_decoder->HwChannels) { }
return; // unsupported sample format if (!audio_decoder->HwSampleRate || !audio_decoder->HwChannels) {
} return; // unsupported sample format
if (CodecAudioPassthroughHelper(audio_decoder, avpkt)) { }
return; if (CodecAudioPassthroughHelper(audio_decoder, avpkt)) {
} return;
if (audio_decoder->Resample) { }
uint8_t outbuf[8192 * 2 * 8]; if (audio_decoder->Resample) {
uint8_t *out[1]; uint8_t outbuf[8192 * 2 * 8];
uint8_t *out[1];
out[0] = outbuf;
ret = swr_convert(audio_decoder->Resample, out, sizeof(outbuf) / (2 * audio_decoder->HwChannels), out[0] = outbuf;
(const uint8_t **)frame->extended_data, frame->nb_samples); ret = swr_convert(audio_decoder->Resample, out, sizeof(outbuf) / (2 * audio_decoder->HwChannels),
if (ret > 0) { (const uint8_t **)frame->extended_data, frame->nb_samples);
if (!(audio_decoder->Passthrough & CodecPCM)) { if (ret > 0) {
CodecReorderAudioFrame((int16_t *) outbuf, ret * 2 * audio_decoder->HwChannels, if (!(audio_decoder->Passthrough & CodecPCM)) {
audio_decoder->HwChannels); CodecReorderAudioFrame((int16_t *) outbuf, ret * 2 * audio_decoder->HwChannels,
} audio_decoder->HwChannels);
AudioEnqueue(outbuf, ret * 2 * audio_decoder->HwChannels); }
AudioEnqueue(outbuf, ret * 2 * audio_decoder->HwChannels);
}
return;
}
} }
return;
}
}
} }
} }

View File

@ -14,6 +14,10 @@ void ConvertColor(const GLint &colARGB, glm::vec4 &col) {
col.b = ((colARGB & 0x000000FF) ) / 255.0; col.b = ((colARGB & 0x000000FF) ) / 255.0;
} }
extern "C" void OSD_get_context();
extern "C" void OSD_get_shared_context();
extern "C" void OSD_release_context();
/**************************************************************************************** /****************************************************************************************
* cShader * cShader
****************************************************************************************/ ****************************************************************************************/
@ -119,7 +123,7 @@ void main() \
#else #else
const char *rectVertexShader = const char *rectVertexShader =
"\n\ "\n \
\ \
layout (location = 0) in vec2 position; \ layout (location = 0) in vec2 position; \
out vec4 rectCol; \ out vec4 rectCol; \
@ -134,8 +138,9 @@ void main() \
"; ";
const char *rectFragmentShader = const char *rectFragmentShader =
"\n\ "\n \
\ \
precision mediump float; \
in vec4 rectCol; \ in vec4 rectCol; \
out vec4 color; \ out vec4 color; \
\ \
@ -146,7 +151,7 @@ void main() \
"; ";
const char *textureVertexShader = const char *textureVertexShader =
"\n\ "\n \
\ \
layout (location = 0) in vec2 position; \ layout (location = 0) in vec2 position; \
layout (location = 1) in vec2 texCoords; \ layout (location = 1) in vec2 texCoords; \
@ -166,7 +171,8 @@ void main() \
"; ";
const char *textureFragmentShader = const char *textureFragmentShader =
"\n\ "\n \
precision mediump float; \
in vec2 TexCoords; \ in vec2 TexCoords; \
in vec4 alphaValue; \ in vec4 alphaValue; \
out vec4 color; \ out vec4 color; \
@ -180,7 +186,7 @@ void main() \
"; ";
const char *textVertexShader = const char *textVertexShader =
"\n\ "\n \
\ \
layout (location = 0) in vec2 position; \ layout (location = 0) in vec2 position; \
layout (location = 1) in vec2 texCoords; \ layout (location = 1) in vec2 texCoords; \
@ -200,7 +206,8 @@ void main() \
"; ";
const char *textFragmentShader = const char *textFragmentShader =
"\n\ "\n \
precision mediump float; \
in vec2 TexCoords; \ in vec2 TexCoords; \
in vec4 textColor; \ in vec4 textColor; \
\ \
@ -287,12 +294,14 @@ bool cShader::Compile(const char *vertexCode, const char *fragmentCode) {
sVertex = glCreateShader(GL_VERTEX_SHADER); sVertex = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(sVertex, 1, &vertexCode, NULL); glShaderSource(sVertex, 1, &vertexCode, NULL);
glCompileShader(sVertex); glCompileShader(sVertex);
// esyslog("[softhddev]:SHADER:VERTEX %s\n",vertexCode);
if (!CheckCompileErrors(sVertex)) if (!CheckCompileErrors(sVertex))
return false; return false;
// Fragment Shader // Fragment Shader
sFragment = glCreateShader(GL_FRAGMENT_SHADER); sFragment = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(sFragment, 1, &fragmentCode, NULL); glShaderSource(sFragment, 1, &fragmentCode, NULL);
glCompileShader(sFragment); glCompileShader(sFragment);
// esyslog("[softhddev]:SHADER:FRAGMENT %s\n",fragmentCode);
if (!CheckCompileErrors(sFragment)) if (!CheckCompileErrors(sFragment))
return false; return false;
// link Program // link Program
@ -315,14 +324,14 @@ bool cShader::CheckCompileErrors(GLuint object, bool program) {
glGetShaderiv(object, GL_COMPILE_STATUS, &success); glGetShaderiv(object, GL_COMPILE_STATUS, &success);
if (!success) { if (!success) {
glGetShaderInfoLog(object, 1024, NULL, infoLog); glGetShaderInfoLog(object, 1024, NULL, infoLog);
esyslog("[softhddev]:SHADER: Compile-time error: Type: %d - %s", type, infoLog); esyslog("[softhddev]:SHADER: Compile-time error: Type: %d - \n%s\n", type, infoLog);
return false; return false;
} }
} else { } else {
glGetProgramiv(object, GL_LINK_STATUS, &success); glGetProgramiv(object, GL_LINK_STATUS, &success);
if (!success) { if (!success) {
glGetProgramInfoLog(object, 1024, NULL, infoLog); glGetProgramInfoLog(object, 1024, NULL, infoLog);
esyslog("[softhddev]:SHADER: Link-time error: Type: %d", type); esyslog("[softhddev]:SHADER: Link-time error: Type: %d - \n%s\n", type, infoLog);
return false; return false;
} }
} }
@ -365,6 +374,10 @@ void cOglGlyph::BindTexture(void) {
void cOglGlyph::LoadTexture(FT_BitmapGlyph ftGlyph) { void cOglGlyph::LoadTexture(FT_BitmapGlyph ftGlyph) {
// Disable byte-alignment restriction // Disable byte-alignment restriction
#ifdef VAAPI
OSD_release_context();
OSD_get_shared_context();
#endif
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &texture); glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture); glBindTexture(GL_TEXTURE_2D, texture);
@ -386,6 +399,11 @@ void cOglGlyph::LoadTexture(FT_BitmapGlyph ftGlyph) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
#ifdef VAAPI
OSD_release_context();
OSD_get_context();
#endif
} }
@ -550,6 +568,10 @@ cOglFb::~cOglFb(void) {
bool cOglFb::Init(void) { bool cOglFb::Init(void) {
initiated = true; initiated = true;
#ifdef VAAPI
OSD_release_context();
OSD_get_shared_context();
#endif
glGenTextures(1, &texture); glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture); glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
@ -562,10 +584,19 @@ bool cOglFb::Init(void) {
glBindFramebuffer(GL_FRAMEBUFFER, fb); glBindFramebuffer(GL_FRAMEBUFFER, fb);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
esyslog("[softhddev]ERROR: Framebuffer is not complete!\n"); esyslog("[softhddev]ERROR: %d Framebuffer is not complete!\n",__LINE__);
#ifdef VAAPI
OSD_release_context();
OSD_get_context();
#endif
return false; return false;
} }
#ifdef VAAPI
OSD_release_context();
OSD_get_context();
#endif
return true; return true;
} }
@ -619,6 +650,7 @@ cOglOutputFb::~cOglOutputFb(void) {
bool cOglOutputFb::Init(void) { bool cOglOutputFb::Init(void) {
initiated = true; initiated = true;
glGenTextures(1, &texture); glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture); glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
@ -634,19 +666,16 @@ bool cOglOutputFb::Init(void) {
esyslog("[softhddev]ERROR::cOglOutputFb: Framebuffer is not complete!"); esyslog("[softhddev]ERROR::cOglOutputFb: Framebuffer is not complete!");
return false; return false;
} }
return true; return true;
} }
void cOglOutputFb::BindWrite(void) { void cOglOutputFb::BindWrite(void) {
// glVDPAUMapSurfacesNV(1, &surface);
if (!initiated) if (!initiated)
Init(); Init();
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb);
} }
void cOglOutputFb::Unbind(void) { void cOglOutputFb::Unbind(void) {
// glVDPAUUnmapSurfacesNV(1, &surface);
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
} }
@ -882,6 +911,8 @@ extern unsigned char *posd;
//} //}
#endif #endif
bool cOglCmdCopyBufferToOutputFb::Execute(void) { bool cOglCmdCopyBufferToOutputFb::Execute(void) {
int i; int i;
pthread_mutex_lock(&OSDMutex); pthread_mutex_lock(&OSDMutex);
@ -896,6 +927,7 @@ bool cOglCmdCopyBufferToOutputFb::Execute(void) {
glReadPixels(0, 0 ,fb->Width(), fb->Height(),GL_BGRA,GL_UNSIGNED_BYTE,posd); glReadPixels(0, 0 ,fb->Width(), fb->Height(),GL_BGRA,GL_UNSIGNED_BYTE,posd);
#else #else
fb->Blit(x, y + fb->Height(), x + fb->Width(), y); fb->Blit(x, y + fb->Height(), x + fb->Width(), y);
glFlush();
#endif #endif
ActivateOsd(oFb->texture,x, y, fb->Width() ,fb->Height()); ActivateOsd(oFb->texture,x, y, fb->Width() ,fb->Height());
@ -1323,6 +1355,10 @@ cOglCmdDrawImage::~cOglCmdDrawImage(void) {
bool cOglCmdDrawImage::Execute(void) { bool cOglCmdDrawImage::Execute(void) {
GLuint texture; GLuint texture;
#ifdef VAAPI
OSD_release_context();
OSD_get_shared_context();
#endif
glGenTextures(1, &texture); glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture); glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D( glTexImage2D(
@ -1341,7 +1377,11 @@ bool cOglCmdDrawImage::Execute(void) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
#ifdef VAAPI
OSD_release_context();
OSD_get_context();
#endif
GLfloat x1 = x; //left GLfloat x1 = x; //left
GLfloat y1 = y; //top GLfloat y1 = y; //top
GLfloat x2 = x + width; //right GLfloat x2 = x + width; //right
@ -1430,6 +1470,10 @@ cOglCmdStoreImage::~cOglCmdStoreImage(void) {
} }
bool cOglCmdStoreImage::Execute(void) { bool cOglCmdStoreImage::Execute(void) {
#ifdef VAAPI
OSD_release_context();
OSD_get_shared_context();
#endif
glGenTextures(1, &imageRef->texture); glGenTextures(1, &imageRef->texture);
glBindTexture(GL_TEXTURE_2D, imageRef->texture); glBindTexture(GL_TEXTURE_2D, imageRef->texture);
glTexImage2D( glTexImage2D(
@ -1448,6 +1492,10 @@ bool cOglCmdStoreImage::Execute(void) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
#ifdef VAAPI
OSD_release_context();
OSD_get_context();
#endif
return true; return true;
} }
@ -2041,11 +2089,17 @@ cOglOsd::cOglOsd(int Left, int Top, uint Level, std::shared_ptr<cOglThread> oglT
posd = MALLOC(unsigned char, osdWidth * osdHeight * 4); posd = MALLOC(unsigned char, osdWidth * osdHeight * 4);
#endif #endif
//create output framebuffer //create output framebuffer
#ifdef VAAPI
OSD_release_context();
OSD_get_shared_context();
#endif
if (!oFb) { if (!oFb) {
oFb = new cOglOutputFb(osdWidth, osdHeight); oFb = new cOglOutputFb(osdWidth, osdHeight);
oglThread->DoCmd(new cOglCmdInitOutputFb(oFb)); oglThread->DoCmd(new cOglCmdInitOutputFb(oFb));
} }
#ifdef VAAPI
OSD_release_context();
#endif
} }
cOglOsd::~cOglOsd() { cOglOsd::~cOglOsd() {

196
shaders.h
View File

@ -1,54 +1,54 @@
// shader // shader
#ifdef CUVID
char vertex_osd[] = {"\
#version 330\n\
in vec2 vertex_position;\n\
in vec2 vertex_texcoord0;\n\
out vec2 texcoord0;\n\
void main() {\n\
gl_Position = vec4(vertex_position, 1.0, 1.0);\n\
texcoord0 = vertex_texcoord0;\n\
}\n"};
char fragment_osd[] = {"\
#version 330\n\
#define texture1D texture\n\
precision mediump float; \
layout(location = 0) out vec4 out_color;\n\
in vec2 texcoord0;\n\
uniform sampler2D texture0;\n\
void main() {\n\
vec4 color; \n\
color = vec4(texture(texture0, texcoord0));\n\
out_color = color;\n\
}\n"};
char vertex[] = {"\ char vertex[] = {"\
#version 330\n\ #version 310 es\n\
in vec2 vertex_position;\n\ in vec2 vertex_position;\n\
in vec2 vertex_texcoord0;\n\ in vec2 vertex_texcoord0;\n\
out vec2 texcoord0;\n\ out vec2 texcoord0;\n\
in vec2 vertex_texcoord1;\n\ in vec2 vertex_texcoord1;\n\
out vec2 texcoord1;\n\ out vec2 texcoord1;\n\
in vec2 vertex_texcoord2;\n\
out vec2 texcoord2;\n\
in vec2 vertex_texcoord3;\n\
out vec2 texcoord3;\n\
in vec2 vertex_texcoord4;\n\
out vec2 texcoord4;\n\
in vec2 vertex_texcoord5;\n\
out vec2 texcoord5;\n\
void main() {\n\ void main() {\n\
gl_Position = vec4(vertex_position, 1.0, 1.0);\n\ gl_Position = vec4(vertex_position, 1.0, 1.0);\n\
texcoord0 = vertex_texcoord0;\n\ texcoord0 = vertex_texcoord0;\n\
texcoord1 = vertex_texcoord1;\n\ texcoord1 = vertex_texcoord1;\n\
texcoord2 = vertex_texcoord2;\n\
texcoord3 = vertex_texcoord3;\n\
texcoord4 = vertex_texcoord4;\n\
texcoord5 = vertex_texcoord5;\n\
}\n"}; }\n"};
char fragment[] = {"\ char fragment[] = {"\
#version 330\n\ #version 310 es\n\
#define texture1D texture\n\ #define texture1D texture\n\
#define texture3D texture\n\ #define texture3D texture\n\
precision mediump float; \
layout(location = 0) out vec4 out_color;\n\ layout(location = 0) out vec4 out_color;\n\
in vec2 texcoord0;\n\ in vec2 texcoord0;\n\
in vec2 texcoord1;\n\ in vec2 texcoord1;\n\
in vec2 texcoord2;\n\
in vec2 texcoord3;\n\
in vec2 texcoord4;\n\
in vec2 texcoord5;\n\
uniform mat3 colormatrix;\n\ uniform mat3 colormatrix;\n\
uniform vec3 colormatrix_c;\n\ uniform vec3 colormatrix_c;\n\
uniform sampler2D texture0;\n\ uniform sampler2D texture0;\n\
//uniform vec2 texture_size0;\n\
//uniform mat2 texture_rot0;\n\
//uniform vec2 pixel_size0;\n\
uniform sampler2D texture1;\n\ uniform sampler2D texture1;\n\
//uniform vec2 texture_size1;\n\
//uniform mat2 texture_rot1;\n\
//uniform vec2 pixel_size1;\n\
//#define LUT_POS(x, lut_size) mix(0.5 / (lut_size), 1.0 - 0.5 / (lut_size), (x))\n\
void main() {\n\ void main() {\n\
vec4 color; // = vec4(0.0, 0.0, 0.0, 1.0);\n\ vec4 color; // = vec4(0.0, 0.0, 0.0, 1.0);\n\
color.r = 1.000000 * vec4(texture(texture0, texcoord0)).r;\n\ color.r = 1.000000 * vec4(texture(texture0, texcoord0)).r;\n\
@ -61,27 +61,18 @@ out_color = color;\n\
}\n"}; }\n"};
char fragment_bt2100[] = {"\ char fragment_bt2100[] = {"\
#version 330\n\ #version 310 es\n \
#define texture1D texture\n\ #define texture1D texture\n\
#define texture3D texture\n\ #define texture3D texture\n\
precision mediump float; \
layout(location = 0) out vec4 out_color;\n\ layout(location = 0) out vec4 out_color;\n\
in vec2 texcoord0;\n\ in vec2 texcoord0;\n\
in vec2 texcoord1;\n\ in vec2 texcoord1;\n\
in vec2 texcoord2;\n\
in vec2 texcoord3;\n\
in vec2 texcoord4;\n\
in vec2 texcoord5;\n\
uniform mat3 colormatrix;\n\ uniform mat3 colormatrix;\n\
uniform vec3 colormatrix_c;\n\ uniform vec3 colormatrix_c;\n\
uniform mat3 cms_matrix;\n\ uniform mat3 cms_matrix;\n\
uniform sampler2D texture0;\n\ uniform sampler2D texture0;\n\
//uniform vec2 texture_size0;\n\
//uniform mat2 texture_rot0;\n\
//uniform vec2 pixel_size0;\n\
uniform sampler2D texture1;\n\ uniform sampler2D texture1;\n\
//uniform vec2 texture_size1;\n\
//uniform mat2 texture_rot1;\n\
//uniform vec2 pixel_size1;\n\
//#define LUT_POS(x, lut_size) mix(0.5 / (lut_size), 1.0 - 0.5 / (lut_size), (x))\n\ //#define LUT_POS(x, lut_size) mix(0.5 / (lut_size), 1.0 - 0.5 / (lut_size), (x))\n\
void main() {\n\ void main() {\n\
vec4 color; // = vec4(0.0, 0.0, 0.0, 1.0);\n\ vec4 color; // = vec4(0.0, 0.0, 0.0, 1.0);\n\
@ -99,6 +90,98 @@ color.rgb = pow(color.rgb, vec3(1.0/2.4));\n\
out_color = color;\n\ out_color = color;\n\
}\n"}; }\n"};
#else
char vertex_osd[] = {"\
\n\
in vec2 vertex_position;\n\
in vec2 vertex_texcoord0;\n\
out vec2 texcoord0;\n\
void main() {\n\
gl_Position = vec4(vertex_position, 1.0, 1.0);\n\
texcoord0 = vertex_texcoord0;\n\
}\n"};
char fragment_osd[] = {"\
\n\
#define texture1D texture\n\
precision mediump float; \
layout(location = 0) out vec4 out_color;\n\
in vec2 texcoord0;\n\
uniform sampler2D texture0;\n\
void main() {\n\
vec4 color; \n\
color = vec4(texture(texture0, texcoord0));\n\
out_color = color;\n\
}\n"};
char vertex[] = {"\
\n\
in vec2 vertex_position;\n\
in vec2 vertex_texcoord0;\n\
out vec2 texcoord0;\n\
in vec2 vertex_texcoord1;\n\
out vec2 texcoord1;\n\
void main() {\n\
gl_Position = vec4(vertex_position, 1.0, 1.0);\n\
texcoord0 = vertex_texcoord0;\n\
texcoord1 = vertex_texcoord1;\n\
}\n"};
char fragment[] = {"\
\n\
#define texture1D texture\n\
#define texture3D texture\n\
precision mediump float; \
layout(location = 0) out vec4 out_color;\n\
in vec2 texcoord0;\n\
in vec2 texcoord1;\n\
uniform mat3 colormatrix;\n\
uniform vec3 colormatrix_c;\n\
uniform sampler2D texture0;\n\
uniform sampler2D texture1;\n\
//#define LUT_POS(x, lut_size) mix(0.5 / (lut_size), 1.0 - 0.5 / (lut_size), (x))\n\
void main() {\n\
vec4 color; // = vec4(0.0, 0.0, 0.0, 1.0);\n\
color.r = 1.000000 * vec4(texture(texture0, texcoord0)).r;\n\
color.gb = 1.000000 * vec4(texture(texture1, texcoord1)).rg;\n\
// color conversion\n\
color.rgb = mat3(colormatrix) * color.rgb + colormatrix_c;\n\
color.a = 1.0;\n\
// color mapping\n\
out_color = color;\n\
}\n"};
char fragment_bt2100[] = {"\
\n \
#define texture1D texture\n\
#define texture3D texture\n\
precision mediump float; \
layout(location = 0) out vec4 out_color;\n\
in vec2 texcoord0;\n\
in vec2 texcoord1;\n\
uniform mat3 colormatrix;\n\
uniform vec3 colormatrix_c;\n\
uniform mat3 cms_matrix;\n\
uniform sampler2D texture0;\n\
uniform sampler2D texture1;\n\
//#define LUT_POS(x, lut_size) mix(0.5 / (lut_size), 1.0 - 0.5 / (lut_size), (x))\n\
void main() {\n\
vec4 color; // = vec4(0.0, 0.0, 0.0, 1.0);\n\
color.r = 1.003906 * vec4(texture(texture0, texcoord0)).r;\n\
color.gb = 1.003906 * vec4(texture(texture1, texcoord1)).rg;\n\
// color conversion\n\
color.rgb = mat3(colormatrix) * color.rgb + colormatrix_c;\n\
color.a = 1.0;\n\
// color mapping\n\
color.rgb = clamp(color.rgb, 0.0, 1.0);\n\
color.rgb = pow(color.rgb, vec3(2.4));\n\
color.rgb = cms_matrix * color.rgb;\n\
color.rgb = clamp(color.rgb, 0.0, 1.0);\n\
color.rgb = pow(color.rgb, vec3(1.0/2.4));\n\
out_color = color;\n\
}\n"};
#endif
/* Color conversion matrix: RGB = m * YUV + c /* Color conversion matrix: RGB = m * YUV + c
* m is in row-major matrix, with m[row][col], e.g.: * m is in row-major matrix, with m[row][col], e.g.:
* [ a11 a12 a13 ] float m[3][3] = { { a11, a12, a13 }, * [ a11 a12 a13 ] float m[3][3] = { { a11, a12, a13 },
@ -113,12 +196,12 @@ out_color = color;\n\
* The matrix might also be used for other conversions and colorspaces. * The matrix might also be used for other conversions and colorspaces.
*/ */
struct mp_cmat { struct mp_cmat {
float m[3][3]; // colormatrix GLfloat m[3][3]; // colormatrix
float c[3]; //colormatrix_c GLfloat c[3]; //colormatrix_c
}; };
struct mp_mat { struct mp_mat {
float m[3][3]; GLfloat m[3][3];
}; };
// YUV input limited range (16-235 for luma, 16-240 for chroma) // YUV input limited range (16-235 for luma, 16-240 for chroma)
@ -185,10 +268,6 @@ static const struct gl_vao_entry vertex_vao[] = {
{"position", 2, GL_FLOAT, false, offsetof(struct vertex, position)}, {"position", 2, GL_FLOAT, false, offsetof(struct vertex, position)},
{"texcoord0", 2, GL_FLOAT, false, offsetof(struct vertex, texcoord[0])}, {"texcoord0", 2, GL_FLOAT, false, offsetof(struct vertex, texcoord[0])},
{"texcoord1", 2, GL_FLOAT, false, offsetof(struct vertex, texcoord[1])}, {"texcoord1", 2, GL_FLOAT, false, offsetof(struct vertex, texcoord[1])},
{"texcoord2", 2, GL_FLOAT, false, offsetof(struct vertex, texcoord[2])},
{"texcoord3", 2, GL_FLOAT, false, offsetof(struct vertex, texcoord[3])},
{"texcoord4", 2, GL_FLOAT, false, offsetof(struct vertex, texcoord[4])},
{"texcoord5", 2, GL_FLOAT, false, offsetof(struct vertex, texcoord[5])},
{0} {0}
}; };
@ -198,7 +277,8 @@ static void compile_attach_shader(GLuint program,
{ {
GLuint shader; GLuint shader;
GLint status, log_length; GLint status, log_length;
char log[4000];
GLsizei len;
shader = glCreateShader(type); shader = glCreateShader(type);
glShaderSource(shader, 1, &source, NULL); glShaderSource(shader, 1, &source, NULL);
glCompileShader(shader); glCompileShader(shader);
@ -206,9 +286,10 @@ static void compile_attach_shader(GLuint program,
glGetShaderiv(shader, GL_COMPILE_STATUS, &status); glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
log_length = 0; log_length = 0;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &log_length); glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &log_length);
Debug(3,"compile Status %d loglen %d\n",status,log_length); glGetShaderInfoLog(shader,4000,&len,log);
GlxCheck();
Debug(3,"compile Status %d loglen %d >%s<\n",status,log_length,log);
GlxCheck();
glAttachShader(program, shader); glAttachShader(program, shader);
glDeleteShader(shader); glDeleteShader(shader);
} }
@ -223,10 +304,24 @@ static void link_shader(GLuint program)
log_length = 0; log_length = 0;
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &log_length); glGetProgramiv(program, GL_INFO_LOG_LENGTH, &log_length);
Debug(3,"Link Status %d loglen %d\n",status,log_length); Debug(3,"Link Status %d loglen %d\n",status,log_length);
} }
static GLuint sc_generate_osd(GLuint gl_prog) {
Debug(3,"vor create osd\n");
gl_prog = glCreateProgram();
Debug(3,"vor compile vertex osd\n");
compile_attach_shader(gl_prog, GL_VERTEX_SHADER, vertex_osd);
Debug(3,"vor compile fragment osd \n");
compile_attach_shader(gl_prog, GL_FRAGMENT_SHADER, fragment_osd);
glBindAttribLocation(gl_prog,0,"vertex_position");
glBindAttribLocation(gl_prog,1,"vertex_texcoord0");
link_shader(gl_prog);
return gl_prog;
}
static GLuint sc_generate(GLuint gl_prog, enum AVColorSpace colorspace) { static GLuint sc_generate(GLuint gl_prog, enum AVColorSpace colorspace) {
char vname[80]; char vname[80];
@ -284,7 +379,8 @@ static GLuint sc_generate(GLuint gl_prog, enum AVColorSpace colorspace) {
if (gl_colormatrix != -1) if (gl_colormatrix != -1)
glProgramUniformMatrix3fv(gl_prog,gl_colormatrix,1,0,m); glProgramUniformMatrix3fv(gl_prog,gl_colormatrix,1,0,m);
GlxCheck(); GlxCheck();
//glProgramUniform3fv(gl_prog,gl_colormatrix,3,&yuv_bt709.m[0][0]); Debug(3,"nach set colormatrix\n");
gl_colormatrix_c = glGetUniformLocation(gl_prog,"colormatrix_c"); gl_colormatrix_c = glGetUniformLocation(gl_prog,"colormatrix_c");
Debug(3,"get uniform colormatrix_c %d %f\n",gl_colormatrix_c,*c); Debug(3,"get uniform colormatrix_c %d %f\n",gl_colormatrix_c,*c);
if (gl_colormatrix_c != -1) if (gl_colormatrix_c != -1)

View File

@ -107,6 +107,7 @@ static VideoStream *AudioSyncStream; ///< video stream for audio/video sync
#define AUDIO_MIN_BUFFER_FREE (3072 * 8 * 8) #define AUDIO_MIN_BUFFER_FREE (3072 * 8 * 8)
#define AUDIO_BUFFER_SIZE (512 * 1024) ///< audio PES buffer default size #define AUDIO_BUFFER_SIZE (512 * 1024) ///< audio PES buffer default size
static AVPacket AudioAvPkt[1]; ///< audio a/v packet static AVPacket AudioAvPkt[1]; ///< audio a/v packet
int AudioDelay = 0;
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// Audio codec parser // Audio codec parser
@ -579,7 +580,7 @@ static void PesInit(PesDemux * pesdx)
pesdx->Size = PES_MAX_PAYLOAD; pesdx->Size = PES_MAX_PAYLOAD;
pesdx->Buffer = av_malloc(PES_MAX_PAYLOAD + AV_INPUT_BUFFER_PADDING_SIZE); pesdx->Buffer = av_malloc(PES_MAX_PAYLOAD + AV_INPUT_BUFFER_PADDING_SIZE);
if (!pesdx->Buffer) { if (!pesdx->Buffer) {
Fatal(_("pesdemux: out of memory\n")); Fatal(_("pesdemux: out of memory\n"));
} }
PesReset(pesdx); PesReset(pesdx);
} }
@ -672,57 +673,56 @@ static void PesParse(PesDemux * pesdx, const uint8_t * data, int size,
// FIXME: simple+faster detection, if codec already known // FIXME: simple+faster detection, if codec already known
r = 0; r = 0;
if (!r && FastMpegCheck(q)) { if (!r && FastMpegCheck(q)) {
r = MpegCheck(q, n); r = MpegCheck(q, n);
codec_id = AV_CODEC_ID_MP2; codec_id = AV_CODEC_ID_MP2;
} }
if (!r && FastAc3Check(q)) { if (!r && FastAc3Check(q)) {
r = Ac3Check(q, n); r = Ac3Check(q, n);
codec_id = AV_CODEC_ID_AC3; codec_id = AV_CODEC_ID_AC3;
if (r > 0 && q[5] > (10 << 3)) { if (r > 0 && q[5] > (10 << 3)) {
codec_id = AV_CODEC_ID_EAC3; codec_id = AV_CODEC_ID_EAC3;
} }
} }
if (!r && FastLatmCheck(q)) { if (!r && FastLatmCheck(q)) {
r = LatmCheck(q, n); r = LatmCheck(q, n);
codec_id = AV_CODEC_ID_AAC_LATM; codec_id = AV_CODEC_ID_AAC_LATM;
} }
if (!r && FastAdtsCheck(q)) { if (!r && FastAdtsCheck(q)) {
r = AdtsCheck(q, n); r = AdtsCheck(q, n);
codec_id = AV_CODEC_ID_AAC; codec_id = AV_CODEC_ID_AAC;
} }
if (r < 0) { // need more bytes if (r < 0) { // need more bytes
break; break;
} }
if (r > 0) { if (r > 0) {
AVPacket avpkt[1]; AVPacket avpkt[1];
// new codec id, close and open new // new codec id, close and open new
if (AudioCodecID != codec_id) { if (AudioCodecID != codec_id) {
Debug(3, "pesdemux: new codec %#06x -> %#06x\n", Debug(3, "pesdemux: new codec %#06x -> %#06x\n",
AudioCodecID, codec_id); AudioCodecID, codec_id);
CodecAudioClose(MyAudioDecoder); CodecAudioClose(MyAudioDecoder);
CodecAudioOpen(MyAudioDecoder, codec_id); CodecAudioOpen(MyAudioDecoder, codec_id);
AudioCodecID = codec_id; AudioCodecID = codec_id;
} }
av_init_packet(avpkt); av_init_packet(avpkt);
avpkt->data = (void *)q; avpkt->data = (void *)q;
avpkt->size = r; avpkt->size = r;
avpkt->pts = pesdx->PTS; avpkt->pts = pesdx->PTS;
avpkt->dts = pesdx->DTS; avpkt->dts = pesdx->DTS;
// FIXME: not aligned for ffmpeg // FIXME: not aligned for ffmpeg
CodecAudioDecode(MyAudioDecoder, avpkt); CodecAudioDecode(MyAudioDecoder, avpkt);
pesdx->PTS = AV_NOPTS_VALUE; pesdx->PTS = AV_NOPTS_VALUE;
pesdx->DTS = AV_NOPTS_VALUE; pesdx->DTS = AV_NOPTS_VALUE;
pesdx->Skip += r; pesdx->Skip += r;
// FIXME: switch to decoder state // FIXME: switch to decoder state
//pesdx->State = PES_MPEG_DECODE; //pesdx->State = PES_MPEG_DECODE;
break; break;
} }
if (AudioCodecID != AV_CODEC_ID_NONE) { if (AudioCodecID != AV_CODEC_ID_NONE) {
// shouldn't happen after we have a vaild codec // shouldn't happen after we have a vaild codec
// detected // detected
Debug(4, "pesdemux: skip @%d %02x\n", pesdx->Skip, Debug(4, "pesdemux: skip @%d %02x\n", pesdx->Skip,q[0]);
q[0]);
} }
// try next byte // try next byte
++pesdx->Skip; ++pesdx->Skip;
@ -1024,9 +1024,15 @@ int PlayAudio(const uint8_t * data, int size, uint8_t id)
if (SkipAudio || !MyAudioDecoder) { // skip audio if (SkipAudio || !MyAudioDecoder) { // skip audio
return size; return size;
} }
if (StreamFreezed) { // stream freezed if (StreamFreezed ) { // stream freezed
return 0; return 0;
} }
if (AudioDelay) {
Debug(3,"AudioDelay %dms\n",AudioDelay);
usleep(AudioDelay/90);
AudioDelay = 0;
return 0;
}
if (NewAudioStream) { if (NewAudioStream) {
// this clears the audio ringbuffer indirect, open and setup does it // this clears the audio ringbuffer indirect, open and setup does it
CodecAudioClose(MyAudioDecoder); CodecAudioClose(MyAudioDecoder);
@ -1205,9 +1211,9 @@ int PlayAudio(const uint8_t * data, int size, uint8_t id)
// new codec id, close and open new // new codec id, close and open new
if (AudioCodecID != codec_id) { if (AudioCodecID != codec_id) {
CodecAudioClose(MyAudioDecoder); CodecAudioClose(MyAudioDecoder);
CodecAudioOpen(MyAudioDecoder, codec_id); CodecAudioOpen(MyAudioDecoder, codec_id);
AudioCodecID = codec_id; AudioCodecID = codec_id;
} }
av_init_packet(avpkt); av_init_packet(avpkt);
avpkt->data = (void *)p; avpkt->data = (void *)p;
@ -1257,6 +1263,7 @@ int PlayTsAudio(const uint8_t * data, int size)
if (StreamFreezed) { // stream freezed if (StreamFreezed) { // stream freezed
return 0; return 0;
} }
if (NewAudioStream) { if (NewAudioStream) {
// this clears the audio ringbuffer indirect, open and setup does it // this clears the audio ringbuffer indirect, open and setup does it
CodecAudioClose(MyAudioDecoder); CodecAudioClose(MyAudioDecoder);
@ -1279,7 +1286,13 @@ int PlayTsAudio(const uint8_t * data, int size)
return 0; return 0;
} }
#endif #endif
if (AudioDelay) {
Debug(3,"AudioDelay %dms\n",AudioDelay);
usleep(AudioDelay*1000);
AudioDelay = 0;
// TsDemuxer(tsdx, data, size); // insert dummy audio
}
return TsDemuxer(tsdx, data, size); return TsDemuxer(tsdx, data, size);
} }
@ -2498,27 +2511,27 @@ int SetPlayMode(int play_mode)
case 0: // audio/video from decoder case 0: // audio/video from decoder
// tell video parser we get new stream // tell video parser we get new stream
if (MyVideoStream->Decoder && !MyVideoStream->SkipStream) { if (MyVideoStream->Decoder && !MyVideoStream->SkipStream) {
// clear buffers on close configured always or replay only // clear buffers on close configured always or replay only
if (ConfigVideoClearOnSwitch || MyVideoStream->ClearClose) { if (ConfigVideoClearOnSwitch || MyVideoStream->ClearClose) {
Clear(); // flush all buffers Clear(); // flush all buffers
MyVideoStream->ClearClose = 0; MyVideoStream->ClearClose = 0;
} }
if (MyVideoStream->CodecID != AV_CODEC_ID_NONE) { if (MyVideoStream->CodecID != AV_CODEC_ID_NONE) {
MyVideoStream->NewStream = 1; MyVideoStream->NewStream = 1;
MyVideoStream->InvalidPesCounter = 0; MyVideoStream->InvalidPesCounter = 0;
// tell hw decoder we are closing stream // tell hw decoder we are closing stream
VideoSetClosing(MyVideoStream->HwDecoder); VideoSetClosing(MyVideoStream->HwDecoder);
VideoResetStart(MyVideoStream->HwDecoder); VideoResetStart(MyVideoStream->HwDecoder);
#ifdef DEBUG #ifdef DEBUG
VideoSwitch = GetMsTicks(); VideoSwitch = GetMsTicks();
Debug(3, "video: new stream start\n"); Debug(3, "video: new stream start\n");
#endif #endif
} }
} }
if (MyAudioDecoder) { // tell audio parser we have new stream if (MyAudioDecoder) { // tell audio parser we have new stream
if (AudioCodecID != AV_CODEC_ID_NONE) { if (AudioCodecID != AV_CODEC_ID_NONE) {
NewAudioStream = 1; NewAudioStream = 1;
} }
} }
break; break;
case 1: // audio/video from player case 1: // audio/video from player

1426
video.c

File diff suppressed because it is too large Load Diff