Fix compile with newer libav.

This commit is contained in:
Johns 2014-02-27 14:20:25 +01:00
parent 5bf2a9b761
commit 42bbb763fd
7 changed files with 123 additions and 15 deletions

View File

@ -1,6 +1,7 @@
User johns User johns
Date: Date:
Fix compile with newer libav.
Fix OSD bugs. Fix OSD bugs.
Add some VA-API VPP info outputs. Add some VA-API VPP info outputs.
Remove build files for old unstable VDR. Remove build files for old unstable VDR.

View File

@ -25,6 +25,10 @@ VDPAU ?= $(shell pkg-config --exists vdpau && echo 1)
SCREENSAVER ?= 1 SCREENSAVER ?= 1
# use ffmpeg libswresample # use ffmpeg libswresample
SWRESAMPLE ?= $(shell pkg-config --exists libswresample && echo 1) SWRESAMPLE ?= $(shell pkg-config --exists libswresample && echo 1)
# use libav libavresample
ifneq ($(SWRESAMPLE),1)
AVRESAMPLE ?= $(shell pkg-config --exists libavresample && echo 1)
endif
CONFIG := # -DDEBUG #-DOSD_DEBUG # enable debug output+functions CONFIG := # -DDEBUG #-DOSD_DEBUG # enable debug output+functions
#CONFIG += -DSTILL_DEBUG=2 # still picture debug verbose level #CONFIG += -DSTILL_DEBUG=2 # still picture debug verbose level
@ -78,6 +82,11 @@ CONFIG += -DUSE_SWRESAMPLE
_CFLAGS += $(shell pkg-config --cflags libswresample) _CFLAGS += $(shell pkg-config --cflags libswresample)
LIBS += $(shell pkg-config --libs libswresample) LIBS += $(shell pkg-config --libs libswresample)
endif endif
ifeq ($(AVRESAMPLE),1)
CONFIG += -DUSE_AVRESAMPLE
_CFLAGS += $(shell pkg-config --cflags libavresample)
LIBS += $(shell pkg-config --libs libavresample)
endif
_CFLAGS += $(shell pkg-config --cflags libavcodec x11 x11-xcb xcb xcb-icccm) _CFLAGS += $(shell pkg-config --cflags libavcodec x11 x11-xcb xcb xcb-icccm)
LIBS += -lrt $(shell pkg-config --libs libavcodec x11 x11-xcb xcb xcb-icccm) LIBS += -lrt $(shell pkg-config --libs libavcodec x11 x11-xcb xcb xcb-icccm)

112
codec.c
View File

@ -1,7 +1,7 @@
/// ///
/// @file codec.c @brief Codec functions /// @file codec.c @brief Codec functions
/// ///
/// Copyright (c) 2009 - 2013 by Johns. All Rights Reserved. /// Copyright (c) 2009 - 2014 by Johns. All Rights Reserved.
/// ///
/// Contributor(s): /// Contributor(s):
/// ///
@ -38,8 +38,12 @@
#define USE_AC3_DRIFT_CORRECTION #define USE_AC3_DRIFT_CORRECTION
/// use ffmpeg libswresample API (autodected, Makefile) /// use ffmpeg libswresample API (autodected, Makefile)
#define noUSE_SWRESAMPLE #define noUSE_SWRESAMPLE
/// use libav libavresample API (autodected, Makefile)
#define noUSE_AVRESAMPLE
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#ifdef __FreeBSD__ #ifdef __FreeBSD__
#include <sys/endian.h> #include <sys/endian.h>
@ -56,6 +60,7 @@
#include <alsa/iatomic.h> #include <alsa/iatomic.h>
#include <libavcodec/avcodec.h> #include <libavcodec/avcodec.h>
#include <libavutil/mem.h>
// support old ffmpeg versions <1.0 // support old ffmpeg versions <1.0
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,18,102) #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,18,102)
#define AVCodecID CodecID #define AVCodecID CodecID
@ -70,6 +75,10 @@
#ifdef USE_SWRESAMPLE #ifdef USE_SWRESAMPLE
#include <libswresample/swresample.h> #include <libswresample/swresample.h>
#endif #endif
#ifdef USE_AVRESAMPLE
#include <libavresample/avresample.h>
#include <libavutil/opt.h>
#endif
#ifndef __USE_GNU #ifndef __USE_GNU
#define __USE_GNU #define __USE_GNU
@ -201,7 +210,9 @@ static int Codec_get_buffer(AVCodecContext * video_ctx, AVFrame * frame)
//Debug(3, "codec: use surface %#010x\n", surface); //Debug(3, "codec: use surface %#010x\n", surface);
#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(52,48,101)
frame->type = FF_BUFFER_TYPE_USER; frame->type = FF_BUFFER_TYPE_USER;
#endif
#if LIBAVCODEC_VERSION_INT <= AV_VERSION_INT(53,46,0) #if LIBAVCODEC_VERSION_INT <= AV_VERSION_INT(53,46,0)
frame->age = 256 * 256 * 256 * 64; frame->age = 256 * 256 * 256 * 64;
#endif #endif
@ -228,7 +239,9 @@ static int Codec_get_buffer(AVCodecContext * video_ctx, AVFrame * frame)
//Debug(3, "codec: use surface %#010x\n", surface); //Debug(3, "codec: use surface %#010x\n", surface);
#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(52,48,101)
frame->type = FF_BUFFER_TYPE_USER; frame->type = FF_BUFFER_TYPE_USER;
#endif
#if LIBAVCODEC_VERSION_INT <= AV_VERSION_INT(53,46,0) #if LIBAVCODEC_VERSION_INT <= AV_VERSION_INT(53,46,0)
frame->age = 256 * 256 * 256 * 64; frame->age = 256 * 256 * 256 * 64;
#endif #endif
@ -664,15 +677,18 @@ struct _audio_decoder_
int HwSampleRate; ///< hw sample rate int HwSampleRate; ///< hw sample rate
int HwChannels; ///< hw channels int HwChannels; ///< hw channels
#ifndef USE_SWRESAMPLE #if !defined(USE_SWRESAMPLE) && !defined(USE_AVRESAMPLE)
ReSampleContext *ReSample; ///< audio resampling context ReSampleContext *ReSample; ///< old resampling context
#endif #endif
#ifdef USE_SWRESAMPLE #ifdef USE_SWRESAMPLE
#if LIBSWRESAMPLE_VERSION_INT < AV_VERSION_INT(0, 15, 100) #if LIBSWRESAMPLE_VERSION_INT < AV_VERSION_INT(0, 15, 100)
struct SwrContext *Resample; ///< audio software resample context struct SwrContext *Resample; ///< ffmpeg software resample context
#else #else
SwrContext *Resample; ///< audio software resample context SwrContext *Resample; ///< ffmpeg software resample context
#endif #endif
#endif
#ifdef USE_AVRESAMPLE
AVAudioResampleContext *Resample; ///< libav software resample context
#endif #endif
uint16_t Spdif[24576 / 2]; ///< SPDIF output buffer uint16_t Spdif[24576 / 2]; ///< SPDIF output buffer
@ -687,7 +703,7 @@ struct _audio_decoder_
int DriftCorr; ///< audio drift correction value int DriftCorr; ///< audio drift correction value
int DriftFrac; ///< audio drift fraction for ac3 int DriftFrac; ///< audio drift fraction for ac3
#ifndef USE_SWRESAMPLE #if !defined(USE_SWRESAMPLE) && !defined(USE_AVRESAMPLE)
struct AVResampleContext *AvResample; ///< second audio resample context struct AVResampleContext *AvResample; ///< second audio resample context
#define MAX_CHANNELS 8 ///< max number of channels supported #define MAX_CHANNELS 8 ///< max number of channels supported
int16_t *Buffer[MAX_CHANNELS]; ///< deinterleave sample buffers int16_t *Buffer[MAX_CHANNELS]; ///< deinterleave sample buffers
@ -785,7 +801,7 @@ void CodecAudioOpen(AudioDecoder * audio_decoder, const char *name,
AV_CH_LAYOUT_STEREO_DOWNMIX; AV_CH_LAYOUT_STEREO_DOWNMIX;
} }
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,61,100) #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,61,100)
// this has no effect // this has no effect (with ffmpeg and libav)
// audio_decoder->AudioCtx->request_sample_fmt = AV_SAMPLE_FMT_S16; // audio_decoder->AudioCtx->request_sample_fmt = AV_SAMPLE_FMT_S16;
#endif #endif
pthread_mutex_lock(&CodecLockMutex); pthread_mutex_lock(&CodecLockMutex);
@ -834,7 +850,7 @@ void CodecAudioOpen(AudioDecoder * audio_decoder, const char *name,
void CodecAudioClose(AudioDecoder * audio_decoder) void CodecAudioClose(AudioDecoder * audio_decoder)
{ {
// FIXME: output any buffered data // FIXME: output any buffered data
#ifndef USE_SWRESAMPLE #if !defined(USE_SWRESAMPLE) && !defined(USE_AVRESAMPLE)
if (audio_decoder->AvResample) { if (audio_decoder->AvResample) {
int ch; int ch;
@ -859,6 +875,11 @@ void CodecAudioClose(AudioDecoder * audio_decoder)
if (audio_decoder->Resample) { if (audio_decoder->Resample) {
swr_free(&audio_decoder->Resample); swr_free(&audio_decoder->Resample);
} }
#endif
#ifdef USE_AVRESAMPLE
if (audio_decoder->Resample) {
avresample_free(&audio_decoder->Resample);
}
#endif #endif
if (audio_decoder->AudioCtx) { if (audio_decoder->AudioCtx) {
pthread_mutex_lock(&CodecLockMutex); pthread_mutex_lock(&CodecLockMutex);
@ -1155,7 +1176,7 @@ static int CodecAudioPassthroughHelper(AudioDecoder * audio_decoder,
return 0; return 0;
} }
#ifndef USE_SWRESAMPLE #if !defined(USE_SWRESAMPLE) && !defined(USE_AVRESAMPLE)
/** /**
** Set/update audio pts clock. ** Set/update audio pts clock.
@ -1557,7 +1578,7 @@ void CodecAudioDecode(AudioDecoder * audio_decoder, const AVPacket * avpkt)
#endif #endif
#ifdef USE_SWRESAMPLE #if defined(USE_SWRESAMPLE) || defined(USE_AVRESAMPLE)
/** /**
** Set/update audio pts clock. ** Set/update audio pts clock.
@ -1646,6 +1667,7 @@ static void CodecAudioSetClock(AudioDecoder * audio_decoder, int64_t pts)
} }
} }
#ifdef USE_SWRESAMPLE
if (audio_decoder->Resample && audio_decoder->DriftCorr) { if (audio_decoder->Resample && audio_decoder->DriftCorr) {
int distance; int distance;
@ -1660,6 +1682,18 @@ static void CodecAudioSetClock(AudioDecoder * audio_decoder, int64_t pts)
Debug(3, "codec/audio: swr_set_compensation failed\n"); Debug(3, "codec/audio: swr_set_compensation failed\n");
} }
} }
#endif
#ifdef USE_AVRESAMPLE
if (audio_decoder->Resample && audio_decoder->DriftCorr) {
int distance;
distance = (pts_diff * audio_decoder->HwSampleRate) / (900 * 1000);
if (avresample_set_compensation(audio_decoder->Resample,
audio_decoder->DriftCorr / 10, distance)) {
Debug(3, "codec/audio: swr_set_compensation failed\n");
}
}
#endif
if (1) { if (1) {
static int c; static int c;
@ -1699,6 +1733,7 @@ static void CodecAudioUpdateFormat(AudioDecoder * audio_decoder)
} }
#endif #endif
#ifdef USE_SWRESAMPLE
audio_decoder->Resample = audio_decoder->Resample =
swr_alloc_set_opts(audio_decoder->Resample, audio_ctx->channel_layout, swr_alloc_set_opts(audio_decoder->Resample, audio_ctx->channel_layout,
AV_SAMPLE_FMT_S16, audio_decoder->HwSampleRate, AV_SAMPLE_FMT_S16, audio_decoder->HwSampleRate,
@ -1709,6 +1744,33 @@ static void CodecAudioUpdateFormat(AudioDecoder * audio_decoder)
} else { } else {
Error(_("codec/audio: can't setup resample\n")); Error(_("codec/audio: can't setup resample\n"));
} }
#endif
#ifdef USE_AVRESAMPLE
if (!(audio_decoder->Resample = avresample_alloc_context())) {
Error(_("codec/audio: can't setup resample\n"));
return;
}
av_opt_set_int(audio_decoder->Resample, "in_channel_layout",
audio_ctx->channel_layout, 0);
av_opt_set_int(audio_decoder->Resample, "in_sample_fmt",
audio_ctx->sample_fmt, 0);
av_opt_set_int(audio_decoder->Resample, "in_sample_rate",
audio_ctx->sample_rate, 0);
av_opt_set_int(audio_decoder->Resample, "out_channel_layout",
audio_ctx->channel_layout, 0);
av_opt_set_int(audio_decoder->Resample, "out_sample_fmt",
AV_SAMPLE_FMT_S16, 0);
av_opt_set_int(audio_decoder->Resample, "out_sample_rate",
audio_decoder->HwSampleRate, 0);
if (avresample_open(audio_decoder->Resample)) {
avresample_free(&audio_decoder->Resample);
audio_decoder->Resample = NULL;
Error(_("codec/audio: can't open resample\n"));
return;
}
#endif
} }
/** /**
@ -1731,7 +1793,9 @@ void CodecAudioDecode(AudioDecoder * audio_decoder, const AVPacket * avpkt)
audio_ctx = audio_decoder->AudioCtx; audio_ctx = audio_decoder->AudioCtx;
// FIXME: don't need to decode pass-through codecs // FIXME: don't need to decode pass-through codecs
frame.data[0] = NULL; // libav needs memset, frame.data[0] = NULL;
memset(&frame, 0, sizeof(frame));
got_frame = 0;
n = avcodec_decode_audio4(audio_ctx, &frame, &got_frame, n = avcodec_decode_audio4(audio_ctx, &frame, &got_frame,
(AVPacket *) avpkt); (AVPacket *) avpkt);
if (n != avpkt->size) { if (n != avpkt->size) {
@ -1785,7 +1849,7 @@ void CodecAudioDecode(AudioDecoder * audio_decoder, const AVPacket * avpkt)
"codec/audio: channels %d samples %d plane %d data %d\n", "codec/audio: channels %d samples %d plane %d data %d\n",
audio_ctx->channels, frame.nb_samples, plane_sz, data_sz); audio_ctx->channels, frame.nb_samples, plane_sz, data_sz);
} }
#ifdef USE_SWRESAMPLE
if (audio_decoder->Resample) { if (audio_decoder->Resample) {
uint8_t outbuf[8192 * 2 * 8]; uint8_t outbuf[8192 * 2 * 8];
uint8_t *out[1]; uint8_t *out[1];
@ -1804,6 +1868,30 @@ void CodecAudioDecode(AudioDecoder * audio_decoder, const AVPacket * avpkt)
} }
return; return;
} }
#endif
#ifdef USE_AVRESAMPLE
if (audio_decoder->Resample) {
uint8_t outbuf[8192 * 2 * 8];
uint8_t *out[1];
out[0] = outbuf;
n = avresample_convert(audio_decoder->Resample, out, 0,
sizeof(outbuf) / (2 * audio_decoder->HwChannels),
(uint8_t **) frame.extended_data, 0, frame.nb_samples);
// FIXME: set out_linesize, in_linesize correct
if (n > 0) {
if (!(audio_decoder->Passthrough & CodecPCM)) {
CodecReorderAudioFrame((int16_t *) outbuf,
n * 2 * audio_decoder->HwChannels,
audio_decoder->HwChannels);
}
AudioEnqueue(outbuf, n * 2 * audio_decoder->HwChannels);
}
return;
}
#endif
#ifdef DEBUG #ifdef DEBUG
// should be never reached // should be never reached
fprintf(stderr, "oops\n"); fprintf(stderr, "oops\n");

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: 2014-02-04 14:38+0100\n" "POT-Creation-Date: 2014-02-26 15:08+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -309,6 +309,9 @@ msgstr ""
msgid "codec/audio: can't setup resample\n" msgid "codec/audio: can't setup resample\n"
msgstr "" msgstr ""
msgid "codec/audio: can't open resample\n"
msgstr ""
msgid "codec/audio: latm\n" msgid "codec/audio: latm\n"
msgstr "" msgstr ""

View File

@ -1,7 +1,7 @@
/// ///
/// @file softhddev.c @brief A software HD device plugin for VDR. /// @file softhddev.c @brief A software HD device plugin for VDR.
/// ///
/// Copyright (c) 2011 - 2013 by Johns. All Rights Reserved. /// Copyright (c) 2011 - 2014 by Johns. All Rights Reserved.
/// ///
/// Contributor(s): /// Contributor(s):
/// ///
@ -32,15 +32,18 @@
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <inttypes.h> #include <inttypes.h>
#include <unistd.h> #include <unistd.h>
#include <string.h>
#include <libintl.h> #include <libintl.h>
#define _(str) gettext(str) ///< gettext shortcut #define _(str) gettext(str) ///< gettext shortcut
#define _N(str) str ///< gettext_noop shortcut #define _N(str) str ///< gettext_noop shortcut
#include <libavcodec/avcodec.h> #include <libavcodec/avcodec.h>
#include <libavutil/mem.h>
// support old ffmpeg versions <1.0 // support old ffmpeg versions <1.0
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,18,102) #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,18,102)
#define AVCodecID CodecID #define AVCodecID CodecID

View File

@ -61,6 +61,9 @@ src_prepare() {
if has_version ">=media-video/ffmpeg-0.8"; then if has_version ">=media-video/ffmpeg-0.8"; then
BUILD_PARAMS+=" SWRESAMPLE=1" BUILD_PARAMS+=" SWRESAMPLE=1"
fi fi
if has_version ">=media-video/libav-0.8"; then
BUILD_PARAMS+=" AVRESAMPLE=1"
fi
} }
src_install() { src_install() {

View File

@ -64,6 +64,7 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <math.h>
#include <libintl.h> #include <libintl.h>
#define _(str) gettext(str) ///< gettext shortcut #define _(str) gettext(str) ///< gettext shortcut
@ -11474,7 +11475,7 @@ static void PrintVersion(void)
#ifdef GIT_REV #ifdef GIT_REV
"(GIT-" GIT_REV ")" "(GIT-" GIT_REV ")"
#endif #endif
",\n\t(c) 2009 - 2013 by Johns\n" ",\n\t(c) 2009 - 2014 by Johns\n"
"\tLicense AGPLv3: GNU Affero General Public License version 3\n"); "\tLicense AGPLv3: GNU Affero General Public License version 3\n");
} }