26 Commits
0.1.3 ... 0.2.0

Author SHA1 Message Date
Johns
cac1e5ce17 Release Version 0.2.0. 2012-01-07 13:21:27 +01:00
Johns
d6e2d04505 Fix compiler error with -DDEBUG. 2012-01-07 03:13:33 +01:00
Johns
45a34a3381 Add support for ac3 audio pass through. 2012-01-07 03:05:43 +01:00
Johns
92ffd978b0 Add workaround for alsa not playing hdmi sound.
Without open/close pcm, hdmi is quiet after second snd_pcm_set_params.
2012-01-07 02:35:49 +01:00
Johns
878813f206 Fix bug: broken device plugin stop and exit. 2012-01-06 15:39:32 +01:00
Johns
cb2314837c uwm window manager hide cursor workaround. 2012-01-06 15:37:21 +01:00
Johns
820c246148 Fix bug: old surface stay in video ringbuffer. 2012-01-05 22:55:57 +01:00
Johns
8dda2a0b8a Show transparent cursor to hide cursor. 2012-01-05 22:33:14 +01:00
Johns
761c06eac1 Add color standard support to vdpau. 2012-01-05 20:24:18 +01:00
Johns
0776bc5ee4 VDPAU improvements.
Add denoise, sharpness, skip chroma deinterlace support.
Show OSD only if something is to display, improves performance.
Add deinterlace mode with only 4 surfaces.
2012-01-05 17:20:44 +01:00
Johns
aba14813c0 Add OSS Mixer support. 2012-01-04 16:59:48 +01:00
Johns
0f449c2394 Remove warnings, reduce debug informations. 2012-01-04 16:58:35 +01:00
Johns
9a30d387a1 Crash and thread fixes.
Check if PTS is valid, otherwise debug code does false abort.
Fix bug: audio new stream is not thread safe.
2012-01-03 22:10:04 +01:00
Johns
c8e70ec0fe Audio update.
Alsa: report needed down sampling of 3/5/6 to 2 channels.
Moved alsa code into alsa module.
Initial OSS output support.
2012-01-03 21:42:39 +01:00
Johns
5546354cc7 Version bump. 2012-01-02 19:31:08 +01:00
Johns
442e021d87 Lock av_open/close calls.
New ffmpeg dislikes simultaneous open/close from audio/video.
Prepared audio decoder without av_parser_parse2.
Handle av_audio_resample_init errors.
2012-01-02 17:47:50 +01:00
Johns
4301718329 Documents updates. 2012-01-02 15:27:03 +01:00
Johns
3b7688b78b Print debug only, if compiled with -DDEBUG. 2012-01-02 15:21:58 +01:00
Johns
d2606a5d5f Search audio sync inside PES packets. 2012-01-01 21:14:15 +01:00
Johns
0d63fac2e8 Use only the needed number of surfaces.
Fix problem with video-xvba and too many surfaces used.
Prepare new audio driver "oss".
2011-12-31 18:55:07 +01:00
Johns
c8c760a069 Make pthread_setname_np optional for older glibc. 2011-12-31 17:28:58 +01:00
Johns
0c7170989d Remove warning, when building without vdpau. 2011-12-30 21:50:58 +01:00
Johns
12bfab3f10 Name threads for easier debugging. 2011-12-30 16:47:57 +01:00
Johns
bded2ae5df Prepared vdpau noise reduction support. 2011-12-29 19:45:00 +01:00
Johns
1f2d1d235e Vpdau displays black, when no video available. 2011-12-29 17:47:21 +01:00
Johns
f179264468 Fix bug: CodecVideoDecode destroys avpkt. 2011-12-29 13:43:12 +01:00
12 changed files with 2647 additions and 633 deletions

View File

@@ -1,4 +1,43 @@
User johns
Data: Sat Jan 7 13:20:07 CET 2012
Release Version 0.2.0
Add support for ac3 audio pass through.
Add workaround for alsa not playing hdmi sound.
Fix bug: broken device plugin stop and exit.
Show transparent cursor to hide cursor.
VDPAU: Add color standard support.
VDPAU: Add denoise and sharpness support.
VDPAU: Add skip chroma deinterlace support.
VDPAU: Show OSD only if something is to display, improves performance.
VDPAU: Add deinterlace with only 4 surfaces.
Date: Thu Jan 4 17:00:00 CET 2012
Release Version 0.1.5
Adds OSS mixer support.
Fix bug: audio new stream is not thread safe.
New audio driver OSS.
Fix bug: needed down sampling of 3/5/6 to 2 channels not reported.
Search audio sync inside PES packets, for insane dvb streams.
Use only the needed number of surfaces.
Date: Thu Dec 29 19:44:43 CET 2011
Release Version 0.1.4
Prepared vdpau noise reduction support.
Vdpau also displays a black surface, when no video is available.
Fix bug: CodecVideoDecode destroys avpkt.
Date: Thu Dec 29 00:55:57 CET 2011
Release Version 0.1.3
Add missing VdpauDecoderDestroy.
Cleanup video packet ringbuffer.
Allow build without VDPAU.
Fix bug: swapped end and start.
Support other than "PCM" alsa mixer channels.
Date: Sat Dec 24 15:26:27 CET 2011
Release Version 0.1.2

View File

@@ -18,8 +18,11 @@ VERSION = $(shell grep 'static const char \*const VERSION *=' $(PLUGIN).cpp | aw
### Configuration (edit this for your needs)
CONFIG := #-DDEBUG
CONFIG += $(shell pkg-config --exists libva && echo "-DUSE_VAAPI")
#CONFIG += -DHAVE_PTHREAD_NAME
CONFIG += $(shell pkg-config --exists vdpau && echo "-DUSE_VDPAU")
CONFIG += $(shell pkg-config --exists libva && echo "-DUSE_VAAPI")
CONFIG += $(shell pkg-config --exists alsa && echo "-DUSE_ALSA")
#CONFIG += -DUSE_OSS
### The C++ compiler and options:
@@ -30,14 +33,27 @@ CFLAGS ?= -g -O2 -W -Wall -Wextra -Winit-self \
-Wdeclaration-after-statement -fPIC
#CFLAGS += -Werror
override CFLAGS += $(DEFINES) $(INCLUDES) \
$(shell pkg-config --cflags alsa libavcodec libavformat)
$(shell pkg-config --cflags libavcodec libavformat) \
`pkg-config --cflags x11 x11-xcb xcb xcb-xv xcb-shm xcb-dpms xcb-atom\
xcb-screensaver xcb-randr xcb-glx xcb-icccm xcb-keysyms`\
`pkg-config --cflags gl glu` \
$(if $(findstring USE_VDPAU,$(CONFIG)), \
`pkg-config --cflags vdpau`) \
$(if $(findstring USE_VAAPI,$(CONFIG)), \
`pkg-config --cflags libva-x11 libva-glx libva`) \
$(if $(findstring USE_ALSA,$(CONFIG)), \
`pkg-config --cflags alsa`)
override LDFLAGS += -lrt \
$(shell pkg-config --libs alsa libavcodec libavformat) \
$(shell pkg-config --libs libavcodec libavformat) \
`pkg-config --libs x11 x11-xcb xcb xcb-xv xcb-shm xcb-dpms xcb-atom\
xcb-screensaver xcb-randr xcb-glx xcb-icccm xcb-keysyms`\
`pkg-config --libs gl glu` \
`pkg-config --libs vdpau` \
`pkg-config --libs libva-x11 libva-glx libva`
$(if $(findstring USE_VDPAU,$(CONFIG)), \
`pkg-config --libs vdpau`) \
$(if $(findstring USE_VAAPI,$(CONFIG)), \
`pkg-config --libs libva-x11 libva-glx libva`) \
$(if $(findstring USE_ALSA,$(CONFIG)), \
`pkg-config --libs alsa`)
### The directory environment:

View File

@@ -1,6 +1,6 @@
@file README.txt @brief A software HD output device for VDR
Copyright (c) 2011 by Johns. All Rights Reserved.
Copyright (c) 2011, 2012 by Johns. All Rights Reserved.
Contributor(s):
@@ -20,14 +20,21 @@ $Id$
A software and GPU emulated HD output device plugin for VDR.
o Video VA-API/VA-API
o Video VA-API/VA-API (with intel, nvidia and amd backend supported)
o Video CPU/VA-API
o Video VDPAU/VDPAU
o Video CPU/VDPAU
o planned: Video VA-API/Opengl
o planned: Video VDPAU/Opengl
o planned: Video CPU/Xv
o planned: Video CPU/Opengl
o planned: Software Deinterlacer
o Audio FFMpeg/Analog
o Audio FFMpeg/Digital
o planned: HDMI/SPDIF Passthrough
o planned: Video XvBA/XvBA
o Audio FFMpeg/Alsa/Analog
o Audio FFMpeg/Alsa/Digital
o Audio FFMpeg/OSS/Analog
o planned: Alsa HDMI/SPDIF Passthrough
o planned: OSS HDMI/SPDIF Passthrough
To compile you must have the 'requires' installed.
@@ -57,43 +64,82 @@ Install:
cd vdr-softhddevice
make VDRDIR=<path-to-your-vdr-files> LIBDIR=.
You can edit Makefile to enable/disable VDPAU / VA-API / Alsa / OSS
support.
Setup: environment
------
Following is supported:
DISPLAY=:0.0
x11 display name
only if alsa is configured
ALSA_DEVICE=default
alsa PCM device name
ALSA_MIXER=default
alsa control device name
ALSA_MIXER_CHANNEL=PCM
alsa control channel name
only if oss is configured
OSS_AUDIODEV=/dev/dsp
oss dsp device name
OSS_MIXERDEV=/dev/mixer
oss mixer device name
OSS_MIXER_CHANNEL=pcm
oss mixer channel name
Setup: /etc/vdr/setup.conf
------
Following is supported:
softhddevice.Deinterlace = 0
0 = bob, 1 = weave, 2 = temporal, 3 = temporal_spatial, 4 = software
(only 0, 1 supported)
softhddevice.MakePrimary = 1
0 = no change, 1 make softhddevice primary at start
softhddevice.Deinterlace = 0
0 = bob, 1 = weave, 2 = temporal, 3 = temporal_spatial, 4 = software
(only 0, 1 supported with vaapi)
softhddevice.SkipChromaDeinterlace = 0
0 = disabled, 1 = enabled (for slower cards, poor qualit<69>t)
softhddevice.Denoise = 0
0 .. 1000 noise reduction level (0 off, 1000 max)
softhddevice.Sharpness = 0
-1000 .. 1000 noise reduction level (0 off, -1000 max blur,
1000 max sharp)
softhddevice.Scaling = 0
0 = normal, 1 = fast, 2 = HQ, 3 = anamorphic
softhddevice.AudioDelay = 0
+n or -n ms
softhddevice.AudioPassthrough = 0
0 = none, 1 = AC-3
Commandline:
------------
Use vdr -h to see the command line arguments support by the plugin.
Warning:
--------
libav is not supported, expect many bugs with it.
Requires:
---------
media-video/ffmpeg
media-video/ffmpeg (version >=0.7)
Complete solution to record, convert and stream audio and
video. Includes libavcodec.
http://ffmpeg.org
media-libs/alsa-lib
Advanced Linux Sound Architecture Library
http://www.alsa-project.org
or
kernel support for oss/oss4 or alsa oss emulation
x11-libs/libva
Video Acceleration (VA) API for Linux
http://www.freedesktop.org/wiki/Software/vaapi
@@ -104,7 +150,7 @@ Requires:
x11-libs/vdpau-video
VDPAU Backend for Video Acceleration (VA) API
http://www.freedesktop.org/wiki/Software/vaapi
or untested
or
x11-libs/xvba-video
XVBA Backend for Video Acceleration (VA) API
http://www.freedesktop.org/wiki/Software/vaapi
@@ -116,7 +162,7 @@ Requires:
x11-libs/xcb-util-keysyms
X C-language Bindings library
http://xcb.freedesktop.org
Only versions >= 0.3.8 are supported
Only versions >= 0.3.8 are good supported
x11-libs/libX11
X.Org X11 library

60
Todo
View File

@@ -1,3 +1,23 @@
@file Todo @brief A software HD output device for VDR
Copyright (c) 2011, 2012 by Johns. All Rights Reserved.
Contributor(s):
License: AGPLv3
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
$Id: $
missing:
video out with xv
video out with opengl
@@ -7,11 +27,20 @@ missing:
atmolight
zoom/fit-zoom 4:3
multistream handling
disable screensaver
disable window cursor
ITU BT601, ITU BT709 (HD), RGB studio levels (16-235)?
vdpau:
1080i with temporal spatial too slow GT 520
1080i with temporal spatial and level 1 scaling too slow with my GT 520
1080i with temporal spatial too slow with my GT 520 on some channels
SkipChromaDeinterlace improves performance
Improve OSD handling, show only what is used. Big OSD costs performance
VdpPreemptionCallback handling
Loose a surface
hard channel switch
libva:
hard channel switch
libva-intel-driver:
intel still has hangups most with 1080i
@@ -25,7 +54,6 @@ libva-vdpau-driver:
-> vaDestroyContext -> pthread_rwlock_wrlock)
libva-xvba-driver:
mpeg1/2 needs software decoder fixed
x11:
support resize of x11 window
@@ -35,19 +63,31 @@ x11:
disable cursor
audio/alsa:
video/audio asyncron
random crash in av_parser_parse2, when switching channels
done? video/audio asyncron
random crashes in av_parser_parse2, when switching channels
sometimes alsa hangs
playback of >2 channels on 2 channel hardware
done?
better downmix of >2 channels on 2 channel hardware
remix support of unsupported sample rates
libav supports only resample of mono to 2 channels
ffmpeg didn't support resample of 5 to 2 channels
CodecAudioOpen can fail "can't open audio codec" and does Fatal exit.
on some channels it takes long time until sound can be heared.
this channels has packet start not at the beginning of the start packet
audio/oss:
alsa oss emulation mixer "pcm" not working
ring buffer overflow with alsa oss emulation
HDMI/SPDIF Passthrough:
only AC-3 written
playback of recording
play back is too fast
pause is not reset, when replay exit
setup:
Setup menu parameters aren't automatic loaded?
Setup of decoder type.
Setup of output type.
Setup of display type.
Setup 4:3 zoom type
Setup parameters are not used until restart.
Can a notice be added to the setup menu?

1446
audio.c

File diff suppressed because it is too large Load Diff

304
codec.c
View File

@@ -1,7 +1,7 @@
///
/// @file codec.c @brief Codec functions
///
/// Copyright (c) 2009 - 2011 by Johns. All Rights Reserved.
/// Copyright (c) 2009 - 2012 by Johns. All Rights Reserved.
///
/// Contributor(s):
///
@@ -26,9 +26,21 @@
/// This module contains all decoder and codec functions.
/// It is uses ffmpeg (http://ffmpeg.org) as backend.
///
/// It may work with libav (http://libav.org), but the tests show
/// many bugs and incompatiblity in it. Don't use this shit.
///
/**
** use av_parser to support insane dvb audio streams.
*/
#define USE_AVPARSER
/// compile with passthrough support (experimental)
#define USE_PASSTHROUGH
#include <stdio.h>
#include <unistd.h>
#include <endian.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -44,6 +56,11 @@
#include <libavcodec/vdpau.h>
#endif
#ifndef __USE_GNU
#define __USE_GNU
#endif
#include <pthread.h>
#ifdef MAIN_H
#include MAIN_H
#endif
@@ -52,6 +69,18 @@
#include "audio.h"
#include "codec.h"
//----------------------------------------------------------------------------
// Global
//----------------------------------------------------------------------------
///
/// ffmpeg lock mutex
///
/// new ffmpeg dislikes simultanous open/close
/// this breaks our code, until this is fixed use lock.
///
static pthread_mutex_t CodecLockMutex;
//----------------------------------------------------------------------------
// Video
//----------------------------------------------------------------------------
@@ -348,16 +377,20 @@ void CodecVideoOpen(VideoDecoder * decoder, const char *name, int codec_id)
}
// FIXME: for software decoder use all cpus, otherwise 1
decoder->VideoCtx->thread_count = 1;
pthread_mutex_lock(&CodecLockMutex);
// open codec
#if LIBAVCODEC_VERSION_INT <= AV_VERSION_INT(53,5,0)
if (avcodec_open(decoder->VideoCtx, video_codec) < 0) {
pthread_mutex_unlock(&CodecLockMutex);
Fatal(_("codec: can't open video codec!\n"));
}
#else
if (avcodec_open2(decoder->VideoCtx, video_codec, NULL) < 0) {
pthread_mutex_unlock(&CodecLockMutex);
Fatal(_("codec: can't open video codec!\n"));
}
#endif
pthread_mutex_unlock(&CodecLockMutex);
decoder->VideoCtx->opaque = decoder; // our structure
@@ -436,7 +469,9 @@ void CodecVideoClose(VideoDecoder * video_decoder)
// FIXME: play buffered data
av_freep(&video_decoder->Frame);
if (video_decoder->VideoCtx) {
pthread_mutex_lock(&CodecLockMutex);
avcodec_close(video_decoder->VideoCtx);
pthread_mutex_unlock(&CodecLockMutex);
av_freep(&video_decoder->VideoCtx);
}
}
@@ -446,9 +481,9 @@ void CodecVideoClose(VideoDecoder * video_decoder)
/**
** Display pts...
**
** ffmpeg 0.9 pts always AV_NOPTS_VALUE
** ffmpeg 0.9 pkt_pts nice monotonic (only with HD)
** ffmpeg 0.9 pkt_dts wild jumping -160 - 340 ms
** ffmpeg-0.9 pts always AV_NOPTS_VALUE
** ffmpeg-0.9 pkt_pts nice monotonic (only with HD)
** ffmpeg-0.9 pkt_dts wild jumping -160 - 340 ms
**
** libav 0.8_pre20111116 pts always AV_NOPTS_VALUE
** libav 0.8_pre20111116 pkt_pts always 0 (could be fixed?)
@@ -483,32 +518,28 @@ void DisplayPts(AVCodecContext * video_ctx, AVFrame * frame)
**
** @param decoder video decoder data
** @param avpkt video packet
**
** @note this version destroys avpkt!!
*/
void CodecVideoDecode(VideoDecoder * decoder, AVPacket * avpkt)
void CodecVideoDecode(VideoDecoder * decoder, const AVPacket * avpkt)
{
AVCodecContext *video_ctx;
AVFrame *frame;
int used;
int got_frame;
AVPacket pkt[1];
video_ctx = decoder->VideoCtx;
frame = decoder->Frame;
*pkt = *avpkt; // use copy
next_part:
// FIXME: this function can crash with bad packets
used = avcodec_decode_video2(video_ctx, frame, &got_frame, avpkt);
Debug(4, "%s: %p %d -> %d %d\n", __FUNCTION__, avpkt->data, avpkt->size,
used, got_frame);
used = avcodec_decode_video2(video_ctx, frame, &got_frame, pkt);
Debug(4, "%s: %p %d -> %d %d\n", __FUNCTION__, pkt->data, pkt->size, used,
got_frame);
if (got_frame) { // frame completed
//DisplayPts(video_ctx, frame);
if (video_ctx->hwaccel_context) {
VideoRenderFrame(decoder->HwDecoder, video_ctx, frame);
} else {
VideoRenderFrame(decoder->HwDecoder, video_ctx, frame);
}
VideoRenderFrame(decoder->HwDecoder, video_ctx, frame);
} else {
// some frames are needed for references, interlaced frames ...
// could happen with h264 dvb streams, just drop data.
@@ -516,23 +547,18 @@ void CodecVideoDecode(VideoDecoder * decoder, AVPacket * avpkt)
Debug(4, "codec: %8d incomplete interlaced frame %d bytes used\n",
video_ctx->frame_number, used);
}
if (used != avpkt->size) {
if (used == 0) {
goto next_part;
}
if (used != pkt->size) {
if (used >= 0) {
// some tv channels, produce this
Debug(4,
"codec: ooops didn't use complete video packet used %d of %d\n",
used, avpkt->size);
avpkt->data += used;
avpkt->size -= used;
used, pkt->size);
pkt->data += used;
pkt->size -= used;
goto next_part;
}
Debug(3, "codec: bad frame %d\n", used);
}
return;
}
//----------------------------------------------------------------------------
@@ -554,7 +580,7 @@ struct _audio_decoder_
AVCodec *AudioCodec; ///< audio codec
AVCodecContext *AudioCtx; ///< audio codec context
/// audio parser to support wired dvb streaks
/// audio parser to support insane dvb streaks
AVCodecParserContext *AudioParser;
int SampleRate; ///< current stream sample rate
int Channels; ///< current stream channels
@@ -563,8 +589,17 @@ struct _audio_decoder_
int HwChannels; ///< hw channels
ReSampleContext *ReSample; ///< audio resampling context
};
#ifdef USE_PASSTHROUGH
//static char CodecPassthroughPCM; ///< pass pcm through (unsupported)
static char CodecPassthroughAC3; ///< pass ac3 through
//static char CodecPassthroughDTS; ///< pass dts through (unsupported)
//static char CodecPassthroughMPA; ///< pass mpa through (unsupported)
#endif
/**
** Allocate a new audio decoder context.
**
@@ -606,16 +641,20 @@ void CodecAudioOpen(AudioDecoder * audio_decoder, const char *name,
if (!(audio_decoder->AudioCtx = avcodec_alloc_context3(audio_codec))) {
Fatal(_("codec: can't allocate audio codec context\n"));
}
pthread_mutex_lock(&CodecLockMutex);
// open codec
#if LIBAVCODEC_VERSION_INT <= AV_VERSION_INT(53,5,0)
if (avcodec_open(audio_decoder->AudioCtx, audio_codec) < 0) {
pthread_mutex_unlock(&CodecLockMutex);
Fatal(_("codec: can't open audio codec\n"));
}
#else
if (avcodec_open2(audio_decoder->AudioCtx, audio_codec, NULL) < 0) {
pthread_mutex_unlock(&CodecLockMutex);
Fatal(_("codec: can't open audio codec\n"));
}
#endif
pthread_mutex_unlock(&CodecLockMutex);
Debug(3, "codec: audio '%s'\n", audio_decoder->AudioCtx->codec_name);
if (audio_codec->capabilities & CODEC_CAP_TRUNCATED) {
@@ -650,20 +689,36 @@ void CodecAudioClose(AudioDecoder * audio_decoder)
audio_decoder->AudioParser = NULL;
}
if (audio_decoder->AudioCtx) {
pthread_mutex_lock(&CodecLockMutex);
avcodec_close(audio_decoder->AudioCtx);
pthread_mutex_unlock(&CodecLockMutex);
av_freep(&audio_decoder->AudioCtx);
}
}
/**
** Set audio pass-through.
*/
void CodecSetAudioPassthrough(int mask)
{
#ifdef USE_PASSTHROUGH
CodecPassthroughAC3 = mask & 1 ? 1 : 0;
#endif
// FIXME: must update audio decoder (nr. of channels wrong)
(void)mask;
}
#ifdef USE_AVPARSER
/**
** Decode an audio packet.
**
** PTS must be handled self.
**
** @param audio_decoder audio_Decoder data
** @param audio_decoder audio decoder data
** @param avpkt audio packet
*/
void CodecAudioDecode(AudioDecoder * audio_decoder, AVPacket * avpkt)
void CodecAudioDecode(AudioDecoder * audio_decoder, const AVPacket * avpkt)
{
int16_t buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 4 +
FF_INPUT_BUFFER_PADDING_SIZE] __attribute__ ((aligned(16)));
@@ -700,6 +755,7 @@ void CodecAudioDecode(AudioDecoder * audio_decoder, AVPacket * avpkt)
!index ? (uint64_t) spkt->pts : AV_NOPTS_VALUE,
!index ? (uint64_t) spkt->dts : AV_NOPTS_VALUE, -1);
// FIXME: make this a function for both #ifdef cases
if (dpkt->size) {
int buf_sz;
@@ -708,7 +764,7 @@ void CodecAudioDecode(AudioDecoder * audio_decoder, AVPacket * avpkt)
buf_sz = sizeof(buf);
l = avcodec_decode_audio3(audio_ctx, buf, &buf_sz, dpkt);
if (l < 0) { // no audio frame could be decompressed
Error(_("codec: error audio data\n"));
Error(_("codec: error audio data at %d\n"), index);
break;
}
#ifdef notyetFF_API_OLD_DECODE_AUDIO
@@ -735,14 +791,24 @@ void CodecAudioDecode(AudioDecoder * audio_decoder, AVPacket * avpkt)
audio_decoder->SampleRate = audio_ctx->sample_rate;
audio_decoder->HwSampleRate = audio_ctx->sample_rate;
audio_decoder->Channels = audio_ctx->channels;
audio_decoder->HwChannels = audio_ctx->channels;
#ifdef USE_PASSTHROUGH
// SPDIF/HDMI passthrough
if (CodecPassthroughAC3 && audio_ctx->codec_id == CODEC_ID_AC3) {
audio_decoder->HwChannels = 2;
} else
#endif
{
audio_decoder->HwChannels = audio_ctx->channels;
}
// channels not support?
if ((err =
AudioSetup(&audio_decoder->HwSampleRate,
&audio_decoder->HwChannels))) {
Debug(3, "codec/audio: resample %d -> %d\n",
audio_ctx->channels, audio_decoder->HwChannels);
Debug(3, "codec/audio: resample %dHz *%d -> %dHz *%d\n",
audio_ctx->sample_rate, audio_ctx->channels,
audio_decoder->HwSampleRate,
audio_decoder->HwChannels);
if (err == 1) {
audio_decoder->ReSample =
@@ -750,10 +816,18 @@ void CodecAudioDecode(AudioDecoder * audio_decoder, AVPacket * avpkt)
audio_ctx->channels, audio_decoder->HwSampleRate,
audio_ctx->sample_rate, audio_ctx->sample_fmt,
audio_ctx->sample_fmt, 16, 10, 0, 0.8);
// libav-0.8_pre didn't support 6 -> 2 channels
if (!audio_decoder->ReSample) {
Error(_("codec/audio: resample setup error\n"));
audio_decoder->HwChannels = 0;
audio_decoder->HwSampleRate = 0;
}
} else {
Debug(3, "codec/audio: audio setup error\n");
// FIXME: handle errors
audio_decoder->HwChannels = 0;
audio_decoder->HwSampleRate = 0;
break;
}
}
}
@@ -766,11 +840,101 @@ void CodecAudioDecode(AudioDecoder * audio_decoder, AVPacket * avpkt)
__attribute__ ((aligned(16)));
int outlen;
// FIXME: libav-0.7.2 crash here
outlen =
audio_resample(audio_decoder->ReSample, outbuf, buf,
buf_sz);
AudioEnqueue(outbuf, outlen);
#ifdef DEBUG
if (outlen != buf_sz) {
Debug(3, "codec/audio: possible fixed ffmpeg\n");
}
#endif
if (outlen) {
// outlen seems to be wrong in ffmpeg-0.9
outlen /= audio_decoder->Channels *
av_get_bytes_per_sample(audio_ctx->sample_fmt);
outlen *=
audio_decoder->HwChannels *
av_get_bytes_per_sample(audio_ctx->sample_fmt);
Debug(4, "codec/audio: %d -> %d\n", buf_sz, outlen);
AudioEnqueue(outbuf, outlen);
}
} else {
#ifdef USE_PASSTHROUGH
// SPDIF/HDMI passthrough
if (CodecPassthroughAC3
&& audio_ctx->codec_id == CODEC_ID_AC3) {
// build SPDIF header and append A52 audio to it
// dpkt is the original data
buf_sz = 6144;
if (buf_sz < dpkt->size + 8) {
Error(_
("codec/audio: decoded data smaller than encoded\n"));
break;
}
// copy original data for output
// FIXME: not 100% sure, if endian is correct
buf[0] = htole16(0xF872); // iec 61937 sync word
buf[1] = htole16(0x4E1F);
buf[2] = htole16(0x01 | (dpkt->data[5] & 0x07) << 8);
buf[3] = htole16(dpkt->size * 8);
swab(dpkt->data, buf + 4, dpkt->size);
memset(buf + 4 + dpkt->size / 2, 0,
buf_sz - 8 - dpkt->size);
}
#if 0
//
// old experimental code
//
if (1) {
// FIXME: need to detect dts
// copy original data for output
// FIXME: buf is sint
buf[0] = 0x72;
buf[1] = 0xF8;
buf[2] = 0x1F;
buf[3] = 0x4E;
buf[4] = 0x00;
switch (dpkt->size) {
case 512:
buf[5] = 0x0B;
break;
case 1024:
buf[5] = 0x0C;
break;
case 2048:
buf[5] = 0x0D;
break;
default:
Debug(3,
"codec/audio: dts sample burst not supported\n");
buf[5] = 0x00;
break;
}
buf[6] = (dpkt->size * 8);
buf[7] = (dpkt->size * 8) >> 8;
//buf[8] = 0x0B;
//buf[9] = 0x77;
//printf("%x %x\n", dpkt->data[0],dpkt->data[1]);
// swab?
memcpy(buf + 8, dpkt->data, dpkt->size);
memset(buf + 8 + dpkt->size, 0,
buf_sz - 8 - dpkt->size);
} else if (1) {
// FIXME: need to detect mp2
// FIXME: mp2 passthrough
// see softhddev.c version/layer
// 0x04 mpeg1 layer1
// 0x05 mpeg1 layer23
// 0x06 mpeg2 ext
// 0x07 mpeg2.5 layer 1
// 0x08 mpeg2.5 layer 2
// 0x09 mpeg2.5 layer 3
}
// DTS HD?
// True HD?
#endif
#endif
AudioEnqueue(buf, buf_sz);
}
}
@@ -784,10 +948,84 @@ void CodecAudioDecode(AudioDecoder * audio_decoder, AVPacket * avpkt)
}
#if 1
// or av_free_packet, make no difference here
av_destruct_packet(spkt);
#endif
}
#else
/**
** Decode an audio packet.
**
** PTS must be handled self.
**
** @param audio_decoder audio decoder data
** @param avpkt audio packet
*/
void CodecAudioDecode(AudioDecoder * audio_decoder, const AVPacket * avpkt)
{
int16_t buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 4 +
FF_INPUT_BUFFER_PADDING_SIZE] __attribute__ ((aligned(16)));
AVCodecContext *audio_ctx;
int index;
//#define spkt avpkt
#if 1
AVPacket spkt[1];
// av_new_packet reserves FF_INPUT_BUFFER_PADDING_SIZE and clears it
if (av_new_packet(spkt, avpkt->size)) {
Error(_("codec: out of memory\n"));
return;
}
memcpy(spkt->data, avpkt->data, avpkt->size);
spkt->pts = avpkt->pts;
spkt->dts = avpkt->dts;
#endif
audio_ctx = audio_decoder->AudioCtx;
index = 0;
while (spkt->size > index) {
int n;
int buf_sz;
AVPacket dpkt[1];
av_init_packet(dpkt);
dpkt->data = spkt->data + index;
dpkt->size = spkt->size - index;
buf_sz = sizeof(buf);
n = avcodec_decode_audio3(audio_ctx, buf, &buf_sz, dpkt);
if (n < 0) { // no audio frame could be decompressed
Error(_("codec: error audio data at %d\n"), index);
break;
}
#ifdef DEBUG
Debug(4, "codec/audio: -> %d\n", buf_sz);
if ((unsigned)buf_sz > sizeof(buf)) {
abort();
}
#endif
#ifdef notyetFF_API_OLD_DECODE_AUDIO
// FIXME: ffmpeg git comeing
int got_frame;
avcodec_decode_audio4(audio_ctx, frame, &got_frame, dpkt);
#else
#endif
// FIXME: see above, old code removed
index += n;
}
#if 1
// or av_free_packet, make no difference here
av_destruct_packet(spkt);
#endif
}
#endif
//----------------------------------------------------------------------------
// Codec
//----------------------------------------------------------------------------
@@ -807,6 +1045,7 @@ static void CodecNoopCallback( __attribute__ ((unused))
*/
void CodecInit(void)
{
pthread_mutex_init(&CodecLockMutex, NULL);
#ifndef DEBUG
// disable display ffmpeg error messages
av_log_set_callback(CodecNoopCallback);
@@ -821,4 +1060,5 @@ void CodecInit(void)
*/
void CodecExit(void)
{
pthread_mutex_destroy(&CodecLockMutex);
}

View File

@@ -47,7 +47,7 @@ extern void CodecVideoOpen(VideoDecoder *, const char *, int);
extern void CodecVideoClose(VideoDecoder *);
/// Decode a video packet
extern void CodecVideoDecode(VideoDecoder *, AVPacket * pkt);
extern void CodecVideoDecode(VideoDecoder *, const AVPacket * pkt);
/// Allocate a new audio decoder context.
extern AudioDecoder *CodecAudioNewDecoder(void);
@@ -59,7 +59,7 @@ extern void CodecAudioOpen(AudioDecoder *, const char *, int);
extern void CodecAudioClose(AudioDecoder *);
/// Decode an audio packet
extern void CodecAudioDecode(AudioDecoder *, AVPacket * pkt);
extern void CodecAudioDecode(AudioDecoder *, const AVPacket * pkt);
/// Setup and initialize codec module.
extern void CodecInit(void);

27
misc.h
View File

@@ -1,7 +1,7 @@
///
/// @file misc.h @brief Misc function header file
///
/// Copyright (c) 2009 - 2011 by Lutz Sammer. All Rights Reserved.
/// Copyright (c) 2009 - 2012 by Lutz Sammer. All Rights Reserved.
///
/// Contributor(s):
/// Copied from uwm.
@@ -46,24 +46,28 @@ extern int SysLogLevel; ///< how much information wanted
// Prototypes
//////////////////////////////////////////////////////////////////////////////
static inline void Debug(const int, const char *format, ...)
static inline void Syslog(const int, const char *format, ...)
__attribute__ ((format(printf, 2, 3)));
//////////////////////////////////////////////////////////////////////////////
// Inlines
//////////////////////////////////////////////////////////////////////////////
#ifdef DEBUG
#define DebugLevel 4 /// private debug level
#else
#define DebugLevel 0 /// private debug level
#endif
/**
** Debug output function.
** Syslog output function.
**
** - 0 fatal errors and errors
** - 1 warnings
** - 2 info
** - 3 important debug and fixme's
*/
static inline void Debug(const int level, const char *format, ...)
static inline void Syslog(const int level, const char *format, ...)
{
if (SysLogLevel > level || DebugLevel > level) {
va_list ap;
@@ -77,7 +81,7 @@ static inline void Debug(const int level, const char *format, ...)
/**
** Show error.
*/
#define Error(fmt...) Debug(0, fmt)
#define Error(fmt...) Syslog(0, fmt)
/**
** Show fatal error.
@@ -87,12 +91,21 @@ static inline void Debug(const int level, const char *format, ...)
/**
** Show warning.
*/
#define Warning(fmt...) Debug(1, fmt)
#define Warning(fmt...) Syslog(1, fmt)
/**
** Show info.
*/
#define Info(fmt...) Debug(2, fmt)
#define Info(fmt...) Syslog(2, fmt)
/**
** Show debug.
*/
#ifdef DEBUG
#define Debug(level, fmt...) Syslog(level, fmt)
#else
#define Debug(level, fmt...) /* disabled */
#endif
/**
** Get ticks in ms.

View File

@@ -1,7 +1,7 @@
///
/// @file softhddev.c @brief A software HD device plugin for VDR.
///
/// Copyright (c) 2011 by Johns. All Rights Reserved.
/// Copyright (c) 2011, 2012 by Johns. All Rights Reserved.
///
/// Contributor(s):
///
@@ -42,19 +42,144 @@
#include "video.h"
#include "codec.h"
static char BrokenThreadsAndPlugins; ///< broken vdr threads and plugins
//////////////////////////////////////////////////////////////////////////////
// Variables
//////////////////////////////////////////////////////////////////////////////
#ifdef USE_VDPAU
static char ConfigVdpauDecoder = 1; ///< use vdpau decoder, if possible
#else
#define ConfigVdpauDecoder 0 ///< no vdpau decoder configured
#endif
static const char DeviceStopped = 1; ///< flag device stopped
//////////////////////////////////////////////////////////////////////////////
// Audio
//////////////////////////////////////////////////////////////////////////////
static volatile char NewAudioStream; ///< new audio stream
static AudioDecoder *MyAudioDecoder; ///< audio decoder
static enum CodecID AudioCodecID; ///< current codec id
extern void AudioTest(void); // FIXME:
/**
** mpeg bitrate table.
**
** BitRateTable[Version][Layer][Index]
*/
static const uint16_t BitRateTable[2][4][16] = {
// MPEG Version 1
{{},
{0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448,
0},
{0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 0},
{0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 0}},
// MPEG Version 2 & 2.5
{{},
{0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, 0},
{0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0},
{0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0}
}
};
/**
** mpeg samperate table.
*/
static const uint16_t SampleRateTable[4] = {
44100, 48000, 32000, 0
};
/**
** Find sync in audio packet.
**
** @param avpkt audio packet
**
** From: http://www.mpgedit.org/mpgedit/mpeg_format/mpeghdr.htm
**
** AAAAAAAA AAABBCCD EEEEFFGH IIJJKLMM
**
** o a 11x frame sync
** o b 2x mpeg audio version (2.5, reserved, 2, 1)
** o c 2x layer (reserved, III, II, I)
** o e 2x BitRate index
** o f 2x SampleRate index
** o g 1x Paddding bit
** o .. doesn't care
**
** frame length:
** Layer I:
** FrameLengthInBytes = (12 * BitRate / SampleRate + Padding) * 4
** Layer II & III:
** FrameLengthInBytes = 144 * BitRate / SampleRate + Padding
*/
static int FindAudioSync(const AVPacket * avpkt)
{
int i;
const uint8_t *data;
i = 0;
data = avpkt->data;
while (i < avpkt->size - 4) {
if (data[i] == 0xFF && (data[i + 1] & 0xFC) == 0xFC) {
int mpeg2;
int mpeg25;
int layer;
int bit_rate_index;
int sample_rate_index;
int padding;
int bit_rate;
int sample_rate;
int frame_size;
mpeg2 = !(data[i + 1] & 0x08) && (data[i + 1] & 0x10);
mpeg25 = !(data[i + 1] & 0x08) && !(data[i + 1] & 0x10);
layer = 4 - ((data[i + 1] >> 1) & 0x03);
bit_rate_index = (data[i + 2] >> 4) & 0x0F;
sample_rate_index = (data[i + 2] >> 2) & 0x03;
padding = (data[i + 2] >> 1) & 0x01;
sample_rate = SampleRateTable[sample_rate_index];
if (!sample_rate) { // no valid sample rate try next
i++;
continue;
}
sample_rate >>= mpeg2; // mpeg 2 half rate
sample_rate >>= mpeg25; // mpeg 2.5 quarter rate
bit_rate = BitRateTable[mpeg2 | mpeg25][layer][bit_rate_index];
bit_rate *= 1000;
switch (layer) {
case 1:
frame_size = (12 * bit_rate) / sample_rate;
frame_size = (frame_size + padding) * 4;
break;
case 2:
case 3:
default:
frame_size = (144 * bit_rate) / sample_rate;
frame_size = frame_size + padding;
break;
}
Debug(3,
"audio: mpeg%s layer%d bitrate=%d samplerate=%d %d bytes\n",
mpeg25 ? "2.5" : mpeg2 ? "2" : "1", layer, bit_rate,
sample_rate, frame_size);
if (i + frame_size < avpkt->size - 4) {
if (data[i + frame_size] == 0xFF
&& (data[i + frame_size + 1] & 0xFC) == 0xFC) {
Debug(3, "audio: mpeg1/2 found at %d\n", i);
return i;
}
}
// no valid frame size or no continuation, try next
}
i++;
}
return -1;
}
/**
** Play audio packet.
**
@@ -62,22 +187,23 @@ extern void AudioTest(void); // FIXME:
** @param size size of PES packet
** @param id PES packet type
*/
void PlayAudio(const uint8_t * data, int size, uint8_t id)
void PlayAudio(const uint8_t * data, int size,
__attribute__ ((unused)) uint8_t id)
{
int n;
AVPacket avpkt[1];
if (BrokenThreadsAndPlugins) {
return;
// channel switch: SetAudioChannelDevice: SetDigitalAudioDevice:
if (NewAudioStream) {
// FIXME: does this clear the audio ringbuffer?
CodecAudioClose(MyAudioDecoder);
AudioCodecID = CODEC_ID_NONE;
NewAudioStream = 0;
}
// PES header 0x00 0x00 0x01 ID
// ID 0xBD 0xC0-0xCF
// channel switch: SetAudioChannelDevice: SetDigitalAudioDevice:
// Detect audio code
// MPEG-PS mp2 MPEG1, MPEG2, AC3
if (size < 9) {
Error(_("[softhddev] invalid audio packet\n"));
return;
@@ -107,6 +233,9 @@ void PlayAudio(const uint8_t * data, int size, uint8_t id)
Error(_("[softhddev] invalid audio packet\n"));
return;
}
// Detect audio code
// MPEG-PS mp2 MPEG1, MPEG2, AC3
// Syncword - 0x0B77
if (data[0] == 0x0B && data[1] == 0x77) {
if (!MyAudioDecoder) {
@@ -137,9 +266,23 @@ void PlayAudio(const uint8_t * data, int size, uint8_t id)
// no start package
// FIXME: Nick/Viva sends this shit, need to find sync in packet
// FIXME: otherwise it takes too long until sound appears
if (AudioCodecID == CODEC_ID_NONE) {
Debug(3, "[softhddev]%s: ??? %d\n", __FUNCTION__, id);
return;
avpkt->data = (void *)data;
avpkt->size = size;
n = FindAudioSync(avpkt);
if (n < 0) {
return;
}
if (!MyAudioDecoder) {
MyAudioDecoder = CodecAudioNewDecoder();
}
CodecAudioOpen(MyAudioDecoder, NULL, CODEC_ID_MP2);
AudioCodecID = CODEC_ID_MP2;
data += n;
size -= n;
}
}
@@ -159,9 +302,6 @@ void PlayAudio(const uint8_t * data, int size, uint8_t id)
*/
void Mute(void)
{
if (BrokenThreadsAndPlugins) {
return;
}
AudioSetVolume(0);
}
@@ -172,9 +312,6 @@ void Mute(void)
*/
void SetVolumeDevice(int volume)
{
if (BrokenThreadsAndPlugins) {
return;
}
AudioSetVolume((volume * 100) / 255);
}
@@ -184,13 +321,13 @@ void SetVolumeDevice(int volume)
#include <alsa/iatomic.h> // portable atomic_t
uint32_t VideoSwitch;
static int NewVideoStream; ///< new video stream
uint32_t VideoSwitch; ///< debug video switch ticks
static volatile char NewVideoStream; ///< new video stream
static VideoDecoder *MyVideoDecoder; ///< video decoder
static enum CodecID VideoCodecID; ///< current codec id
static const char *X11DisplayName; ///< x11 display name
static volatile int Usr1Signal; ///< true got usr1 signal
static volatile char Usr1Signal; ///< true got usr1 signal
/// video PES buffer default size
#define VIDEO_BUFFER_SIZE (512 * 1024)
@@ -200,8 +337,8 @@ static AVPacket VideoPacketRb[VIDEO_PACKET_MAX];
static int VideoPacketWrite; ///< write pointer
static int VideoPacketRead; ///< read pointer
static atomic_t VideoPacketsFilled; ///< how many of the buffer is used
static char VideoFreezed; ///< video freezed
static char VideoClearBuffers; ///< clear video buffers
static volatile char VideoFreezed; ///< video freezed
static volatile char VideoClearBuffers; ///< clear video buffers
#ifdef DEBUG
static int VideoMaxPacketSize; ///< biggest used packet buffer
@@ -277,6 +414,9 @@ static void VideoEnqueue(int64_t pts, const void *data, int size)
/ (VIDEO_BUFFER_SIZE / 2)) * (VIDEO_BUFFER_SIZE / 2));
#ifdef DEBUG
if (avpkt->size <= avpkt->stream_index + size) {
fprintf(stderr, "%d %d %d\n", avpkt->size, avpkt->stream_index,
size);
fflush(stderr);
abort();
}
#endif
@@ -294,6 +434,8 @@ static void VideoEnqueue(int64_t pts, const void *data, int size)
/**
** Finish current packet advance to next.
**
** @param codec_id codec id of packet (MPEG/H264)
*/
static void VideoNextPacket(int codec_id)
{
@@ -376,6 +518,7 @@ int VideoDecode(void)
CodecVideoClose(MyVideoDecoder);
goto skip;
}
goto skip;
break;
case CODEC_ID_MPEG2VIDEO:
if (last_codec_id != CODEC_ID_MPEG2VIDEO) {
@@ -434,6 +577,44 @@ static void StartVideo(void)
VideoPacketInit();
}
#ifdef DEBUG
/**
** Validate mpeg video packet.
**
** Function to validate a mpeg packet, not needed.
*/
static int ValidateMpeg(const uint8_t * data, int size)
{
int pes_l;
do {
if (size < 9) {
return -1;
}
if (data[0] || data[1] || data[2] != 0x01) {
printf("%02x: %02x %02x %02x %02x %02x\n", data[-1], data[0],
data[1], data[2], data[3], data[4]);
return -1;
}
pes_l = (data[4] << 8) | data[5];
if (!pes_l) { // contains unknown length
return 1;
}
if (6 + pes_l > size) {
return -1;
}
data += 6 + pes_l;
size -= 6 + pes_l;
} while (size);
return 0;
}
#endif
/**
** Play video packet.
**
@@ -453,9 +634,6 @@ int PlayVideo(const uint8_t * data, int size)
int64_t pts;
int n;
if (BrokenThreadsAndPlugins) {
return size;
}
if (Usr1Signal) { // x11 server ready
Usr1Signal = 0;
StartVideo();
@@ -463,7 +641,7 @@ int PlayVideo(const uint8_t * data, int size)
if (!MyVideoDecoder) { // no x11 video started
return size;
}
if (NewVideoStream) {
if (NewVideoStream) { // channel switched
Debug(3, "video: new stream %d\n", GetMsTicks() - VideoSwitch);
// FIXME: hack to test results
if (atomic_read(&VideoPacketsFilled) >= VIDEO_PACKET_MAX - 1) {
@@ -482,13 +660,15 @@ int PlayVideo(const uint8_t * data, int size)
}
n = data[8]; // header size
// wrong size
if (size < 9 + n) {
if (size < 9 + n + 4) {
Error(_("[softhddev] invalid video packet\n"));
return size;
}
check = data + 9 + n;
// FIXME: get pts/dts, when we need it
// FIXME: hack to test results
if (atomic_read(&VideoPacketsFilled) >= VIDEO_PACKET_MAX - 1) {
return 0;
}
// get pts/dts
pts = AV_NOPTS_VALUE;
if (data[7] & 0x80) {
@@ -496,6 +676,10 @@ int PlayVideo(const uint8_t * data, int size)
(int64_t) (data[9] & 0x0E) << 29 | data[10] << 22 | (data[11] &
0xFE) << 14 | data[12] << 7 | (data[13] & 0xFE) >> 1;
#ifdef DEBUG
if (!(data[13] & 1) || !(data[11] & 1) || !(data[9] & 1)) {
Error(_("[softhddev] invalid pts in video packet\n"));
return size;
}
//Debug(3, "video: pts %#012" PRIx64 "\n", pts);
if (data[13] != (((pts & 0x7F) << 1) | 1)) {
abort();
@@ -509,35 +693,36 @@ int PlayVideo(const uint8_t * data, int size)
if (data[10] != ((pts >> 22) & 0xFF)) {
abort();
}
if ((data[9] & 0x0F) != (((pts >> 30) << 1) | 1)) {
abort();
}
#endif
}
// FIXME: no valid mpeg2/h264 detection yet
check = data + 9 + n;
if (0) {
printf("%02x: %02x %02x %02x %02x %02x\n", data[6], check[0], check[1],
check[2], check[3], check[4]);
}
// PES_VIDEO_STREAM 0xE0 or PES start code
if ((data[6] & 0xC0) != 0x80 || (!check[0] && !check[1]
&& check[2] == 0x1)) {
//(data[6] & 0xC0) != 0x80 ||
if ((!check[0] && !check[1] && check[2] == 0x1)) {
if (VideoCodecID == CODEC_ID_MPEG2VIDEO) {
// FIXME: hack to test results
if (atomic_read(&VideoPacketsFilled) >= VIDEO_PACKET_MAX - 1) {
return 0;
}
VideoNextPacket(CODEC_ID_MPEG2VIDEO);
} else {
Debug(3, "video: mpeg2 detected\n");
Debug(3, "video: mpeg2 detected ID %02x\n", check[3]);
VideoCodecID = CODEC_ID_MPEG2VIDEO;
}
#ifdef DEBUG
if (ValidateMpeg(data, size)) {
Debug(3, "softhddev/video: invalid mpeg2 video packet\n");
}
#endif
// Access Unit Delimiter
} else if (!check[0] && !check[1] && !check[2] && check[3] == 0x1
&& check[4] == 0x09) {
} else if ((data[6] & 0xC0) == 0x80 && !check[0] && !check[1]
&& !check[2] && check[3] == 0x1 && check[4] == 0x09) {
if (VideoCodecID == CODEC_ID_H264) {
// FIXME: hack to test results
if (atomic_read(&VideoPacketsFilled) >= VIDEO_PACKET_MAX - 1) {
return 0;
}
VideoNextPacket(CODEC_ID_H264);
} else {
Debug(3, "video: h264 detected\n");
@@ -550,11 +735,8 @@ int PlayVideo(const uint8_t * data, int size)
return size;
}
if (VideoCodecID == CODEC_ID_MPEG2VIDEO) {
// mpeg codec supports incomplete packages
// FIXME: hack to test results
if (atomic_read(&VideoPacketsFilled) >= VIDEO_PACKET_MAX - 1) {
return 0;
}
// mpeg codec supports incomplete packets
// waiting for a full complete packages, increases needed delays
VideoNextPacket(CODEC_ID_MPEG2VIDEO);
}
}
@@ -572,9 +754,6 @@ int PlayVideo(const uint8_t * data, int size)
*/
void SetPlayMode(void)
{
if (BrokenThreadsAndPlugins) {
return;
}
if (MyVideoDecoder) {
if (VideoCodecID != CODEC_ID_NONE) {
NewVideoStream = 1;
@@ -582,9 +761,7 @@ void SetPlayMode(void)
}
}
if (MyAudioDecoder) {
// FIXME: does this clear the audio ringbuffer?
CodecAudioClose(MyAudioDecoder);
AudioCodecID = CODEC_ID_NONE;
NewAudioStream = 1;
}
}
@@ -664,9 +841,6 @@ void GetOsdSize(int *width, int *height, double *aspect)
*/
void OsdClose(void)
{
if (BrokenThreadsAndPlugins) {
return;
}
VideoOsdClear();
}
@@ -675,9 +849,6 @@ void OsdClose(void)
*/
void OsdDrawARGB(int x, int y, int height, int width, const uint8_t * argb)
{
if (BrokenThreadsAndPlugins) {
return;
}
VideoOsdDrawARGB(x, y, height, width, argb);
}
@@ -844,6 +1015,32 @@ static void StartXServer(void)
*/
void SoftHdDeviceExit(void)
{
// lets hope that vdr does a good thead cleanup
// no it doesn't do a good thread cleanup
if (MyVideoDecoder) {
CodecVideoClose(MyVideoDecoder);
// FIXME: CodecDelVideoDecoder(MyVideoDecoder);
MyVideoDecoder = NULL;
}
if (MyAudioDecoder) {
CodecAudioClose(MyAudioDecoder);
// FIXME: CodecDelAudioDecoder(MyAudioDecoder);
MyAudioDecoder = NULL;
}
VideoOsdExit();
VideoExit();
AudioExit();
CodecExit();
VideoPacketExit();
if (StartX11Server) {
Debug(3, "x-setup: Stop x11 server\n");
if (X11ServerPid) {
kill(X11ServerPid, SIGTERM);
}
}
}
/**
@@ -864,43 +1061,14 @@ void Start(void)
/**
** Stop plugin.
**
** @note stop everything, but don't cleanup, module is still called.
*/
void Stop(void)
{
#ifdef DEBUG
Debug(3, "video: max used PES packet size: %d\n", VideoMaxPacketSize);
#endif
// FIXME:
// don't let any thread enter our plugin, but can still crash, when
// a thread has called any function, while Stop is called.
BrokenThreadsAndPlugins = 1;
usleep(2 * 1000);
// lets hope that vdr does a good thead cleanup
// no it doesn't do a good thread cleanup
if (MyVideoDecoder) {
CodecVideoClose(MyVideoDecoder);
MyVideoDecoder = NULL;
}
if (MyAudioDecoder) {
CodecAudioClose(MyAudioDecoder);
MyAudioDecoder = NULL;
}
VideoOsdExit();
VideoExit();
AudioExit();
CodecExit();
VideoPacketExit();
if (StartX11Server) {
Debug(3, "x-setup: Stop x11 server\n");
if (X11ServerPid) {
kill(X11ServerPid, SIGTERM);
}
}
}
/**
@@ -908,5 +1076,7 @@ void Stop(void)
*/
void MainThreadHook(void)
{
VideoDisplayHandler();
if (!DeviceStopped) {
VideoDisplayHandler();
}
}

View File

@@ -1,7 +1,7 @@
///
/// @file softhddevice.cpp @brief A software HD device plugin for VDR.
///
/// Copyright (c) 2011 by Johns. All Rights Reserved.
/// Copyright (c) 2011, 2012 by Johns. All Rights Reserved.
///
/// Contributor(s):
///
@@ -33,13 +33,16 @@
#include "softhddev.h"
#include "softhddevice.h"
extern "C" {
#include "video.h"
extern "C"
{
#include "video.h"
extern void AudioPoller(void);
extern void CodecSetAudioPassthrough(int);
}
//////////////////////////////////////////////////////////////////////////////
static const char *const VERSION = "0.1.3";
static const char *const VERSION = "0.2.0";
static const char *const DESCRIPTION =
trNOOP("A software and GPU emulated HD device");
@@ -48,11 +51,15 @@ static class cSoftHdDevice *MyDevice;
//////////////////////////////////////////////////////////////////////////////
static char ConfigMakePrimary; ///< config primary wanted
static char ConfigVideoDeinterlace; ///< config deinterlace
static char ConfigVideoScaling; ///< config scaling
static int ConfigVideoAudioDelay; ///< config audio delay
static char DoMakePrimary; ///< flag switch primary
static char ConfigMakePrimary; ///< config primary wanted
static char ConfigVideoDeinterlace; ///< config deinterlace
static char ConfigVideoSkipChromaDeinterlace; ///< config skip chroma
static int ConfigVideoDenoise; ///< config denoise
static int ConfigVideoSharpen; ///< config sharpen
static char ConfigVideoScaling; ///< config scaling
static int ConfigVideoAudioDelay; ///< config audio delay
static int ConfigAudioPassthrough; ///< config audio pass-through
static volatile char DoMakePrimary; ///< flag switch primary
//////////////////////////////////////////////////////////////////////////////
@@ -125,7 +132,7 @@ cSoftOsd::cSoftOsd(int left, int top, uint level)
cSoftOsd::~cSoftOsd(void)
{
dsyslog("[softhddev]%s:\n", __FUNCTION__);
//dsyslog("[softhddev]%s:\n", __FUNCTION__);
SetActive(false);
OsdClose();
@@ -202,8 +209,10 @@ void cSoftOsd::Flush(void)
w = pm->ViewPort().Width();
h = pm->ViewPort().Height();
dsyslog("[softhddev]%s: draw %dx%d+%d+%d %p\n", __FUNCTION__, w, h, x,
y, pm->Data());
/*
dsyslog("[softhddev]%s: draw %dx%d+%d+%d %p\n", __FUNCTION__, w, h, x,
y, pm->Data());
*/
OsdDrawARGB(x, y, w, h, pm->Data());
@@ -225,14 +234,14 @@ class cSoftOsdProvider:public cOsdProvider
cSoftOsdProvider(void);
};
cOsd *cSoftOsdProvider::Osd; ///< single osd
cOsd *cSoftOsdProvider::Osd; ///< single osd
/**
** Create a new OSD.
*/
cOsd *cSoftOsdProvider::CreateOsd(int left, int top, uint level)
{
dsyslog("[softhddev]%s: %d, %d, %d\n", __FUNCTION__, left, top, level);
//dsyslog("[softhddev]%s: %d, %d, %d\n", __FUNCTION__, left, top, level);
Osd = new cSoftOsd(left, top, level);
return Osd;
@@ -249,7 +258,7 @@ bool cSoftOsdProvider::ProvidesTrueColor(void)
cSoftOsdProvider::cSoftOsdProvider(void)
: cOsdProvider()
{
dsyslog("[softhddev]%s:\n", __FUNCTION__);
//dsyslog("[softhddev]%s:\n", __FUNCTION__);
}
//////////////////////////////////////////////////////////////////////////////
@@ -261,8 +270,12 @@ class cMenuSetupSoft:public cMenuSetupPage
protected:
int MakePrimary;
int Deinterlace;
int SkipChromaDeinterlace;
int Denoise;
int Sharpen;
int Scaling;
int AudioDelay;
int AudioPassthrough;
protected:
virtual void Store(void);
public:
@@ -274,10 +287,15 @@ class cMenuSetupSoft:public cMenuSetupPage
*/
cMenuSetupSoft::cMenuSetupSoft(void)
{
static const char * const deinterlace[] = {
"Bob", "Weave", "Temporal", "TemporalSpatial", "Software" };
static const char * const scaling[] = {
"Normal", "Fast", "HQ", "Anamorphic" };
static const char *const deinterlace[] = {
"Bob", "Weave", "Temporal", "TemporalSpatial", "Software"
};
static const char *const scaling[] = {
"Normal", "Fast", "HQ", "Anamorphic"
};
static const char *const passthrough[] = {
"None", "AC-3"
};
// cMenuEditBoolItem cMenuEditBitItem cMenuEditNumItem
// cMenuEditStrItem cMenuEditStraItem cMenuEditIntItem
@@ -285,11 +303,25 @@ cMenuSetupSoft::cMenuSetupSoft(void)
Add(new cMenuEditBoolItem(tr("Make primary device"), &MakePrimary,
tr("no"), tr("yes")));
Deinterlace = ConfigVideoDeinterlace;
Add(new cMenuEditStraItem(tr("Deinterlace"), &Deinterlace, 5, deinterlace));
Add(new cMenuEditStraItem(tr("Deinterlace"), &Deinterlace, 5,
deinterlace));
SkipChromaDeinterlace = ConfigVideoSkipChromaDeinterlace;
Add(new cMenuEditBoolItem(tr("SkipChromaDeinterlace (vdpau)"),
&SkipChromaDeinterlace, tr("no"), tr("yes")));
Denoise = ConfigVideoDenoise;
Add(new cMenuEditIntItem(tr("Denoise (vdpau 0..1000)"), &Denoise, 0,
1000));
Sharpen = ConfigVideoSharpen;
Add(new cMenuEditIntItem(tr("Sharpen (vdpau -1000..1000)"), &Sharpen,
-1000, 1000));
Scaling = ConfigVideoScaling;
Add(new cMenuEditStraItem(tr("Scaling"), &Scaling, 4, scaling));
AudioDelay = ConfigVideoAudioDelay;
Add(new cMenuEditIntItem(tr("Audio delay (ms)"), &AudioDelay, -1000, 1000));
Add(new cMenuEditIntItem(tr("Audio delay (ms)"), &AudioDelay, -1000,
1000));
AudioPassthrough = ConfigAudioPassthrough;
Add(new cMenuEditStraItem(tr("Audio pass-through"), &AudioPassthrough, 2,
passthrough));
}
/**
@@ -300,10 +332,19 @@ void cMenuSetupSoft::Store(void)
SetupStore("MakePrimary", ConfigMakePrimary = MakePrimary);
SetupStore("Deinterlace", ConfigVideoDeinterlace = Deinterlace);
VideoSetDeinterlace(ConfigVideoDeinterlace);
SetupStore("SkipChromaDeinterlace", ConfigVideoSkipChromaDeinterlace =
SkipChromaDeinterlace);
VideoSetSkipChromaDeinterlace(ConfigVideoSkipChromaDeinterlace);
SetupStore("Denoise", ConfigVideoDenoise = Denoise);
VideoSetDenoise(ConfigVideoDenoise);
SetupStore("Sharpen", ConfigVideoSharpen = Sharpen);
VideoSetSharpen(ConfigVideoSharpen);
SetupStore("Scaling", ConfigVideoScaling = Scaling);
VideoSetScaling(ConfigVideoScaling);
SetupStore("AudioDelay", ConfigVideoAudioDelay = AudioDelay);
VideoSetAudioDelay(ConfigVideoAudioDelay);
SetupStore("AudioPassthrough", ConfigAudioPassthrough = AudioPassthrough);
CodecSetAudioPassthrough(ConfigAudioPassthrough);
}
//////////////////////////////////////////////////////////////////////////////
@@ -332,6 +373,9 @@ class cSoftHdDevice:public cDevice
virtual void GetOsdSize(int &, int &, double &);
virtual int PlayVideo(const uchar *, int);
//virtual int PlayTsVideo(const uchar *, int);
#ifdef USE_OSS // FIXME: testing only oss
virtual int PlayTsAudio(const uchar *, int);
#endif
virtual void SetAudioChannelDevice(int);
virtual int GetAudioChannelDevice(void);
virtual void SetDigitalAudioDevice(bool);
@@ -356,14 +400,14 @@ class cSoftHdDevice:public cDevice
cSoftHdDevice::cSoftHdDevice(void)
{
dsyslog("[softhddev]%s\n", __FUNCTION__);
//dsyslog("[softhddev]%s\n", __FUNCTION__);
spuDecoder = NULL;
}
cSoftHdDevice::~cSoftHdDevice(void)
{
dsyslog("[softhddev]%s:\n", __FUNCTION__);
//dsyslog("[softhddev]%s:\n", __FUNCTION__);
}
void cSoftHdDevice::MakePrimaryDevice(bool on)
@@ -379,7 +423,7 @@ void cSoftHdDevice::MakePrimaryDevice(bool on)
int cSoftHdDevice::ProvidesCa(
__attribute__ ((unused)) const cChannel * channel) const
{
dsyslog("[softhddev]%s: %p\n", __FUNCTION__, channel);
//dsyslog("[softhddev]%s: %p\n", __FUNCTION__, channel);
return 0;
}
@@ -432,7 +476,7 @@ int64_t cSoftHdDevice::GetSTC(void)
{
// dsyslog("[softhddev]%s:\n", __FUNCTION__);
return ::VideoGetClock();
return::VideoGetClock();
}
void cSoftHdDevice::TrickSpeed(int Speed)
@@ -475,7 +519,7 @@ void cSoftHdDevice::Mute(void)
void cSoftHdDevice::SetVolumeDevice(int volume)
{
dsyslog("[softhddev]%s: %d\n", __FUNCTION__, volume);
//dsyslog("[softhddev]%s: %d\n", __FUNCTION__, volume);
::SetVolumeDevice(volume);
}
@@ -492,7 +536,7 @@ bool cSoftHdDevice::Poll(
{
// dsyslog("[softhddev]%s: %d\n", __FUNCTION__, timeout_ms);
return ::Poll(timeout_ms);
return::Poll(timeout_ms);
}
bool cSoftHdDevice::Flush(int timeout_ms)
@@ -528,22 +572,23 @@ int cSoftHdDevice::PlayAudio(const uchar * data, int length, uchar id)
void cSoftHdDevice::SetAudioTrackDevice(
__attribute__ ((unused)) eTrackType type)
{
dsyslog("[softhddev]%s:\n", __FUNCTION__);
//dsyslog("[softhddev]%s:\n", __FUNCTION__);
}
void cSoftHdDevice::SetDigitalAudioDevice(bool on)
void cSoftHdDevice::SetDigitalAudioDevice( __attribute__ ((unused)) bool on)
{
dsyslog("[softhddev]%s: %s\n", __FUNCTION__, on ? "true" : "false");
//dsyslog("[softhddev]%s: %s\n", __FUNCTION__, on ? "true" : "false");
}
void cSoftHdDevice::SetAudioChannelDevice(int audio_channel)
void cSoftHdDevice::SetAudioChannelDevice( __attribute__ ((unused))
int audio_channel)
{
dsyslog("[softhddev]%s: %d\n", __FUNCTION__, audio_channel);
//dsyslog("[softhddev]%s: %d\n", __FUNCTION__, audio_channel);
}
int cSoftHdDevice::GetAudioChannelDevice(void)
{
dsyslog("[softhddev]%s:\n", __FUNCTION__);
//dsyslog("[softhddev]%s:\n", __FUNCTION__);
return 0;
}
@@ -556,7 +601,7 @@ int cSoftHdDevice::PlayVideo(const uchar * data, int length)
{
//dsyslog("[softhddev]%s: %p %d\n", __FUNCTION__, data, length);
return ::PlayVideo(data, length);
return::PlayVideo(data, length);
}
#if 0
@@ -569,6 +614,20 @@ int cSoftHdDevice::PlayTsVideo(const uchar * Data, int Length)
}
#endif
#ifdef USE_OSS // FIXME: testing only oss
///
/// Play a TS audio packet.
///
/// misuse this function as audio poller
///
int cSoftHdDevice::PlayTsAudio(const uchar * data, int length)
{
AudioPoller();
return cDevice::PlayTsAudio(data, length);
}
#endif
uchar *cSoftHdDevice::GrabImage(int &size, bool jpeg, int quality, int sizex,
int sizey)
{
@@ -608,13 +667,13 @@ cPluginSoftHdDevice::cPluginSoftHdDevice(void)
// Initialize any member variables here.
// DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
// VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
dsyslog("[softhddev]%s:\n", __FUNCTION__);
//dsyslog("[softhddev]%s:\n", __FUNCTION__);
}
cPluginSoftHdDevice::~cPluginSoftHdDevice(void)
{
// Clean up after yourself!
dsyslog("[softhddev]%s:\n", __FUNCTION__);
//dsyslog("[softhddev]%s:\n", __FUNCTION__);
::SoftHdDeviceExit();
}
@@ -642,7 +701,7 @@ const char *cPluginSoftHdDevice::CommandLineHelp(void)
*/
bool cPluginSoftHdDevice::ProcessArgs(int argc, char *argv[])
{
dsyslog("[softhddev]%s:\n", __FUNCTION__);
//dsyslog("[softhddev]%s:\n", __FUNCTION__);
return::ProcessArgs(argc, argv);
}
@@ -650,7 +709,7 @@ bool cPluginSoftHdDevice::ProcessArgs(int argc, char *argv[])
bool cPluginSoftHdDevice::Initialize(void)
{
// Start any background activities the plugin shall perform.
dsyslog("[softhddev]%s:\n", __FUNCTION__);
//dsyslog("[softhddev]%s:\n", __FUNCTION__);
MyDevice = new cSoftHdDevice();
@@ -662,7 +721,7 @@ bool cPluginSoftHdDevice::Start(void)
const cDevice *primary;
// Start any background activities the plugin shall perform.
dsyslog("[softhddev]%s:\n", __FUNCTION__);
//dsyslog("[softhddev]%s:\n", __FUNCTION__);
primary = cDevice::PrimaryDevice();
if (MyDevice != primary) {
@@ -685,7 +744,7 @@ bool cPluginSoftHdDevice::Start(void)
void cPluginSoftHdDevice::Stop(void)
{
dsyslog("[softhddev]%s:\n", __FUNCTION__);
//dsyslog("[softhddev]%s:\n", __FUNCTION__);
::Stop();
}
@@ -699,7 +758,7 @@ void cPluginSoftHdDevice::Housekeeping(void)
const char *cPluginSoftHdDevice::MainMenuEntry(void)
{
dsyslog("[softhddev]%s:\n", __FUNCTION__);
//dsyslog("[softhddev]%s:\n", __FUNCTION__);
return tr(MAINMENUENTRY);
return NULL;
}
@@ -712,7 +771,7 @@ const char *cPluginSoftHdDevice::MainMenuEntry(void)
*/
void cPluginSoftHdDevice::MainThreadHook(void)
{
// dsyslog("[softhddev]%s:\n", __FUNCTION__);
//dsyslog("[softhddev]%s:\n", __FUNCTION__);
if (DoMakePrimary && MyDevice) {
dsyslog("[softhddev]%s: switching primary device\n", __FUNCTION__);
@@ -747,7 +806,7 @@ cOsdObject *cPluginSoftHdDevice::MainMenuAction(void)
*/
cMenuSetupPage *cPluginSoftHdDevice::SetupMenu(void)
{
dsyslog("[softhddev]%s:\n", __FUNCTION__);
//dsyslog("[softhddev]%s:\n", __FUNCTION__);
return new cMenuSetupSoft;
}
@@ -757,7 +816,7 @@ cMenuSetupPage *cPluginSoftHdDevice::SetupMenu(void)
*/
bool cPluginSoftHdDevice::SetupParse(const char *name, const char *value)
{
dsyslog("[softhddev]%s: '%s' = '%s'\n", __FUNCTION__, name, value);
//dsyslog("[softhddev]%s: '%s' = '%s'\n", __FUNCTION__, name, value);
// FIXME: handle the values
if (!strcmp(name, "MakePrimary")) {
@@ -768,6 +827,19 @@ bool cPluginSoftHdDevice::SetupParse(const char *name, const char *value)
VideoSetDeinterlace(ConfigVideoDeinterlace = atoi(value));
return true;
}
if (!strcmp(name, "SkipChromaDeinterlace")) {
VideoSetSkipChromaDeinterlace(ConfigVideoSkipChromaDeinterlace =
atoi(value));
return true;
}
if (!strcmp(name, "Denoise")) {
VideoSetDenoise(ConfigVideoDenoise = atoi(value));
return true;
}
if (!strcmp(name, "Sharpen")) {
VideoSetSharpen(ConfigVideoSharpen = atoi(value));
return true;
}
if (!strcmp(name, "Scaling")) {
VideoSetScaling(ConfigVideoScaling = atoi(value));
return true;
@@ -776,6 +848,10 @@ bool cPluginSoftHdDevice::SetupParse(const char *name, const char *value)
VideoSetAudioDelay(ConfigVideoAudioDelay = atoi(value));
return true;
}
if (!strcmp(name, "AudioPassthrough")) {
CodecSetAudioPassthrough(ConfigAudioPassthrough = atoi(value));
return true;
}
return false;
}

775
video.c

File diff suppressed because it is too large Load Diff

11
video.h
View File

@@ -1,7 +1,7 @@
///
/// @file video.h @brief Video module header file
///
/// Copyright (c) 2009 - 2011 by Johns. All Rights Reserved.
/// Copyright (c) 2009 - 2012 by Johns. All Rights Reserved.
///
/// Contributor(s):
///
@@ -83,9 +83,18 @@ extern int VideoSetGeometry(const char *);
/// set deinterlace
extern void VideoSetDeinterlace(int);
/// set skip chroma deinterlace
extern void VideoSetSkipChromaDeinterlace(int);
/// set scaling
extern void VideoSetScaling(int);
/// set denoise
extern void VideoSetDenoise(int);
/// set sharpen
extern void VideoSetSharpen(int);
/// set audio delay
extern void VideoSetAudioDelay(int);