Preparations for new ffmpeg VDPAU API.

This commit is contained in:
Johns 2015-11-03 11:39:41 +01:00
parent ee2311d252
commit 6dfa88aecf
5 changed files with 60 additions and 40 deletions

View File

@ -1,6 +1,7 @@
User johns User johns
Date: Date:
Preparations for new ffmpeg VDPAU API.
Added VDPAU multi decoder loop changes to VA-API code. Added VDPAU multi decoder loop changes to VA-API code.
Reenabled VA-API auto detection. Reenabled VA-API auto detection.
Check and enforce USE_PIP is defined, for new code. Check and enforce USE_PIP is defined, for new code.

67
codec.c
View File

@ -65,6 +65,7 @@
#define AVCodecID CodecID #define AVCodecID CodecID
#define AV_CODEC_ID_AC3 CODEC_ID_AC3 #define AV_CODEC_ID_AC3 CODEC_ID_AC3
#define AV_CODEC_ID_EAC3 CODEC_ID_EAC3 #define AV_CODEC_ID_EAC3 CODEC_ID_EAC3
#define AV_CODEC_ID_MPEG2VIDEO CODEC_ID_MPEG2VIDEO
#define AV_CODEC_ID_H264 CODEC_ID_H264 #define AV_CODEC_ID_H264 CODEC_ID_H264
#endif #endif
#include <libavcodec/vaapi.h> #include <libavcodec/vaapi.h>
@ -419,22 +420,39 @@ void CodecVideoDelDecoder(VideoDecoder * decoder)
** Open video decoder. ** Open video decoder.
** **
** @param decoder private video decoder ** @param decoder private video decoder
** @param name video codec name ** @param codec_id video codec id
** @param codec_id video codec id, used if name == NULL
*/ */
void CodecVideoOpen(VideoDecoder * decoder, const char *name, int codec_id) void CodecVideoOpen(VideoDecoder * decoder, int codec_id)
{ {
AVCodec *video_codec; AVCodec *video_codec;
const char *name;
Debug(3, "codec: using video codec %s or ID %#06x\n", name, codec_id); Debug(3, "codec: using video codec ID %#06x (%s)\n", codec_id,
avcodec_get_name(codec_id));
if (decoder->VideoCtx) { if (decoder->VideoCtx) {
Error(_("codec: missing close\n")); Error(_("codec: missing close\n"));
} }
#if 1
// FIXME: old vdpau API: should be updated to new API
name = NULL;
if (!strcasecmp(VideoGetDriverName(), "vdpau")) {
switch (codec_id) {
case AV_CODEC_ID_MPEG2VIDEO:
name = VideoHardwareDecoder < 0 ? "mpegvideo_vdpau" : NULL;
break;
case AV_CODEC_ID_H264:
name = VideoHardwareDecoder ? "h264_vdpau" : NULL;
break;
}
}
if (name && (video_codec = avcodec_find_decoder_by_name(name))) { if (name && (video_codec = avcodec_find_decoder_by_name(name))) {
Debug(3, "codec: vdpau decoder found\n"); Debug(3, "codec: vdpau decoder found\n");
} else if (!(video_codec = avcodec_find_decoder(codec_id))) { } else
#endif
if (!(video_codec = avcodec_find_decoder(codec_id))) {
Fatal(_("codec: codec ID %#06x not found\n"), codec_id); Fatal(_("codec: codec ID %#06x not found\n"), codec_id);
// FIXME: none fatal // FIXME: none fatal
} }
@ -473,7 +491,7 @@ void CodecVideoOpen(VideoDecoder * decoder, const char *name, int codec_id)
decoder->VideoCtx->opaque = decoder; // our structure decoder->VideoCtx->opaque = decoder; // our structure
Debug(3, "codec: video '%s'\n", decoder->VideoCtx->codec_name); Debug(3, "codec: video '%s'\n", decoder->VideoCodec->long_name);
if (codec_id == AV_CODEC_ID_H264) { if (codec_id == AV_CODEC_ID_H264) {
// 2.53 Ghz CPU is too slow for this codec at 1080i // 2.53 Ghz CPU is too slow for this codec at 1080i
//decoder->VideoCtx->skip_loop_filter = AVDISCARD_ALL; //decoder->VideoCtx->skip_loop_filter = AVDISCARD_ALL;
@ -536,9 +554,15 @@ void CodecVideoOpen(VideoDecoder * decoder, const char *name, int codec_id)
// //
// Prepare frame buffer for decoder // Prepare frame buffer for decoder
// //
if (!(decoder->Frame = avcodec_alloc_frame())) { #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(56,28,1)
Fatal(_("codec: can't allocate decoder frame\n")); if (!(decoder->Frame = av_frame_alloc())) {
Fatal(_("codec: can't allocate video decoder frame buffer\n"));
} }
#else
if (!(decoder->Frame = avcodec_alloc_frame())) {
Fatal(_("codec: can't allocate video decoder frame buffer\n"));
}
#endif
// reset buggy ffmpeg/libav flag // reset buggy ffmpeg/libav flag
decoder->GetFormatDone = 0; decoder->GetFormatDone = 0;
#ifdef FFMPEG_WORKAROUND_ARTIFACTS #ifdef FFMPEG_WORKAROUND_ARTIFACTS
@ -554,7 +578,12 @@ void CodecVideoOpen(VideoDecoder * decoder, const char *name, int codec_id)
void CodecVideoClose(VideoDecoder * video_decoder) void CodecVideoClose(VideoDecoder * video_decoder)
{ {
// FIXME: play buffered data // FIXME: play buffered data
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(56,28,1)
av_frame_free(&video_decoder->Frame); // callee does checks
#else
av_freep(&video_decoder->Frame); av_freep(&video_decoder->Frame);
#endif
if (video_decoder->VideoCtx) { if (video_decoder->VideoCtx) {
pthread_mutex_lock(&CodecLockMutex); pthread_mutex_lock(&CodecLockMutex);
avcodec_close(video_decoder->VideoCtx); avcodec_close(video_decoder->VideoCtx);
@ -674,6 +703,11 @@ void CodecVideoDecode(VideoDecoder * decoder, const AVPacket * avpkt)
} }
} }
#endif #endif
// new AVFrame API
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(56,28,1)
av_frame_unref(frame);
#endif
} }
/** /**
@ -820,19 +854,16 @@ void CodecAudioDelDecoder(AudioDecoder * decoder)
** Open audio decoder. ** Open audio decoder.
** **
** @param audio_decoder private audio decoder ** @param audio_decoder private audio decoder
** @param name audio codec name ** @param codec_id audio codec id
** @param codec_id audio codec id, used if name == NULL
*/ */
void CodecAudioOpen(AudioDecoder * audio_decoder, const char *name, void CodecAudioOpen(AudioDecoder * audio_decoder, int codec_id)
int codec_id)
{ {
AVCodec *audio_codec; AVCodec *audio_codec;
Debug(3, "codec: using audio codec %s or ID %#06x\n", name, codec_id); Debug(3, "codec: using audio codec ID %#06x (%s)\n", codec_id,
avcodec_get_name(codec_id));
if (name && (audio_codec = avcodec_find_decoder_by_name(name))) { if (!(audio_codec = avcodec_find_decoder(codec_id))) {
Debug(3, "codec: audio decoder '%s' found\n", name);
} else if (!(audio_codec = avcodec_find_decoder(codec_id))) {
Fatal(_("codec: codec ID %#06x not found\n"), codec_id); Fatal(_("codec: codec ID %#06x not found\n"), codec_id);
// FIXME: errors aren't fatal // FIXME: errors aren't fatal
} }
@ -843,7 +874,7 @@ void CodecAudioOpen(AudioDecoder * audio_decoder, const char *name,
} }
if (CodecDownmix) { if (CodecDownmix) {
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(53,61,100) || FF_API_REQUEST_CHANNELS #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(53,61,100)
audio_decoder->AudioCtx->request_channels = 2; audio_decoder->AudioCtx->request_channels = 2;
#endif #endif
audio_decoder->AudioCtx->request_channel_layout = audio_decoder->AudioCtx->request_channel_layout =
@ -877,7 +908,7 @@ void CodecAudioOpen(AudioDecoder * audio_decoder, const char *name,
} }
#endif #endif
pthread_mutex_unlock(&CodecLockMutex); pthread_mutex_unlock(&CodecLockMutex);
Debug(3, "codec: audio '%s'\n", audio_decoder->AudioCtx->codec_name); Debug(3, "codec: audio '%s'\n", audio_decoder->AudioCodec->long_name);
if (audio_codec->capabilities & CODEC_CAP_TRUNCATED) { if (audio_codec->capabilities & CODEC_CAP_TRUNCATED) {
Debug(3, "codec: audio can use truncated packets\n"); Debug(3, "codec: audio can use truncated packets\n");

View File

@ -61,7 +61,7 @@ extern VideoDecoder *CodecVideoNewDecoder(VideoHwDecoder *);
extern void CodecVideoDelDecoder(VideoDecoder *); extern void CodecVideoDelDecoder(VideoDecoder *);
/// Open video codec. /// Open video codec.
extern void CodecVideoOpen(VideoDecoder *, const char *, int); extern void CodecVideoOpen(VideoDecoder *, int);
/// Close video codec. /// Close video codec.
extern void CodecVideoClose(VideoDecoder *); extern void CodecVideoClose(VideoDecoder *);
@ -79,7 +79,7 @@ extern AudioDecoder *CodecAudioNewDecoder(void);
extern void CodecAudioDelDecoder(AudioDecoder *); extern void CodecAudioDelDecoder(AudioDecoder *);
/// Open audio codec. /// Open audio codec.
extern void CodecAudioOpen(AudioDecoder *, const char *, int); extern void CodecAudioOpen(AudioDecoder *, int);
/// Close audio codec. /// Close audio codec.
extern void CodecAudioClose(AudioDecoder *); extern void CodecAudioClose(AudioDecoder *);

View File

@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: VDR \n" "Project-Id-Version: VDR \n"
"Report-Msgid-Bugs-To: <see README>\n" "Report-Msgid-Bugs-To: <see README>\n"
"POT-Creation-Date: 2015-09-30 10:48+0200\n" "POT-Creation-Date: 2015-10-20 14:39+0200\n"
"PO-Revision-Date: blabla\n" "PO-Revision-Date: blabla\n"
"Last-Translator: blabla\n" "Last-Translator: blabla\n"
"Language-Team: blabla\n" "Language-Team: blabla\n"
@ -270,7 +270,7 @@ msgstr ""
msgid "codec: can't open video codec!\n" msgid "codec: can't open video codec!\n"
msgstr "" msgstr ""
msgid "codec: can't allocate decoder frame\n" msgid "codec: can't allocate video decoder frame buffer\n"
msgstr "" msgstr ""
msgid "codec: can't allocate audio decoder\n" msgid "codec: can't allocate audio decoder\n"

View File

@ -80,12 +80,6 @@ static void DumpMpeg(const uint8_t * data, int size);
// Variables // Variables
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
#ifdef USE_VDPAU
static char VdpauDecoder = 1; ///< vdpau decoder used
#else
#define VdpauDecoder 0 ///< no vdpau decoder configured
#endif
extern int ConfigAudioBufferTime; ///< config size ms of audio buffer extern int ConfigAudioBufferTime; ///< config size ms of audio buffer
extern int ConfigVideoClearOnSwitch; //< clear decoder on channel switch extern int ConfigVideoClearOnSwitch; //< clear decoder on channel switch
char ConfigStartX11Server; ///< flag start the x11 server char ConfigStartX11Server; ///< flag start the x11 server
@ -707,7 +701,7 @@ static void PesParse(PesDemux * pesdx, const uint8_t * data, int size,
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, NULL, codec_id); CodecAudioOpen(MyAudioDecoder, codec_id);
AudioCodecID = codec_id; AudioCodecID = codec_id;
} }
av_init_packet(avpkt); av_init_packet(avpkt);
@ -880,7 +874,7 @@ static void PesParse(PesDemux * pesdx, const uint8_t * data, int size,
(q[5] & 0x7) + 1); (q[5] & 0x7) + 1);
// FIXME: support resample // FIXME: support resample
} }
//CodecAudioOpen(MyAudioDecoder, NULL, AV_CODEC_ID_PCM_DVD); //CodecAudioOpen(MyAudioDecoder, AV_CODEC_ID_PCM_DVD);
AudioCodecID = AV_CODEC_ID_PCM_DVD; AudioCodecID = AV_CODEC_ID_PCM_DVD;
} }
pesdx->State = PES_LPCM_PAYLOAD; pesdx->State = PES_LPCM_PAYLOAD;
@ -1143,7 +1137,7 @@ int PlayAudio(const uint8_t * data, int size, uint8_t id)
(p[5] & 0x7) + 1); (p[5] & 0x7) + 1);
// FIXME: support resample // FIXME: support resample
} }
//CodecAudioOpen(MyAudioDecoder, NULL, AV_CODEC_ID_PCM_DVD); //CodecAudioOpen(MyAudioDecoder, AV_CODEC_ID_PCM_DVD);
AudioCodecID = AV_CODEC_ID_PCM_DVD; AudioCodecID = AV_CODEC_ID_PCM_DVD;
} }
@ -1216,7 +1210,7 @@ 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, NULL, codec_id); CodecAudioOpen(MyAudioDecoder, codec_id);
AudioCodecID = codec_id; AudioCodecID = codec_id;
} }
av_init_packet(avpkt); av_init_packet(avpkt);
@ -1940,16 +1934,13 @@ int VideoDecodeInput(VideoStream * stream)
case AV_CODEC_ID_MPEG2VIDEO: case AV_CODEC_ID_MPEG2VIDEO:
if (stream->LastCodecID != AV_CODEC_ID_MPEG2VIDEO) { if (stream->LastCodecID != AV_CODEC_ID_MPEG2VIDEO) {
stream->LastCodecID = AV_CODEC_ID_MPEG2VIDEO; stream->LastCodecID = AV_CODEC_ID_MPEG2VIDEO;
CodecVideoOpen(stream->Decoder, VideoHardwareDecoder < 0 CodecVideoOpen(stream->Decoder, AV_CODEC_ID_MPEG2VIDEO);
&& VdpauDecoder ? "mpegvideo_vdpau" : NULL,
AV_CODEC_ID_MPEG2VIDEO);
} }
break; break;
case AV_CODEC_ID_H264: case AV_CODEC_ID_H264:
if (stream->LastCodecID != AV_CODEC_ID_H264) { if (stream->LastCodecID != AV_CODEC_ID_H264) {
stream->LastCodecID = AV_CODEC_ID_H264; stream->LastCodecID = AV_CODEC_ID_H264;
CodecVideoOpen(stream->Decoder, VideoHardwareDecoder CodecVideoOpen(stream->Decoder, AV_CODEC_ID_H264);
&& VdpauDecoder ? "h264_vdpau" : NULL, AV_CODEC_ID_H264);
} }
break; break;
default: default:
@ -2013,9 +2004,6 @@ int VideoGetBuffers(const VideoStream * stream)
static void StartVideo(void) static void StartVideo(void)
{ {
VideoInit(X11DisplayName); VideoInit(X11DisplayName);
#ifdef USE_VDPAU
VdpauDecoder = !strcasecmp(VideoGetDriverName(), "vdpau");
#endif
if (ConfigFullscreen) { if (ConfigFullscreen) {
// FIXME: not good looking, mapped and then resized. // FIXME: not good looking, mapped and then resized.