Always compile audio drift correction.

Add audio drift correction configuration to the setup.
This commit is contained in:
Johns 2012-04-20 18:28:25 +02:00
parent 24a8c7f763
commit d26c34f34f
5 changed files with 60 additions and 15 deletions

View File

@ -1,6 +1,9 @@
User johns
Date:
Always compile audio drift correction.
Add audio drift correction configuration to the setup.
User mini73
Date: Fri Apr 20 16:51:14 CEST 2012

View File

@ -19,8 +19,6 @@ GIT_REV = $(shell git describe --always 2>/dev/null)
### Configuration (edit this for your needs)
CONFIG := #-DDEBUG
#CONFIG += -DUSE_AUDIO_DRIFT_CORRECTION # build new audio drift code
#CONFIG += -DUSE_AC3_DRIFT_CORRECTION # build new ac-3 drift code
CONFIG += -DAV_INFO -DAV_INFO_TIME=3000 # debug a/v sync
#CONFIG += -DHAVE_PTHREAD_NAME # supports new pthread_setname_np
#CONFIG += -DNO_TS_AUDIO # disable ts audio parser

41
codec.c
View File

@ -33,7 +33,9 @@
/// compile with passthrough support (stable, ac3 only)
#define USE_PASSTHROUGH
/// compile audio drift correction support (experimental)
#define noUSE_AUDIO_DRIFT_CORRECTION
#define USE_AUDIO_DRIFT_CORRECTION
/// compile AC3 audio drift correction support (experimental)
#define USE_AC3_DRIFT_CORRECTION
#include <stdio.h>
#include <unistd.h>
@ -631,6 +633,11 @@ struct _audio_decoder_
int RemainCount; ///< number of remaining samples
};
#ifdef USE_AUDIO_DRIFT_CORRECTION
static char CodecAudioDrift; ///< flag: enable audio-drift correction
#else
static const int CodecAudioDrift = 0;
#endif
#ifdef USE_PASSTHROUGH
//static char CodecPassthroughPCM; ///< pass pcm through (unsupported)
static char CodecPassthroughAC3; ///< pass ac3 through
@ -773,8 +780,23 @@ void CodecAudioClose(AudioDecoder * audio_decoder)
}
}
/**
** Set audio drift correction.
**
** @param mask enable mask (PCM, AC3)
*/
void CodecSetAudioDrift(int mask)
{
#ifdef USE_AUDIO_DRIFT_CORRECTION
CodecAudioDrift = mask & 3;
#endif
(void)mask;
}
/**
** Set audio pass-through.
**
** @param mask enable mask (PCM, AC3)
*/
void CodecSetAudioPassthrough(int mask)
{
@ -791,6 +813,10 @@ void CodecSetAudioPassthrough(int mask)
*/
void CodecSetAudioDownmix(int onoff)
{
if (onoff == -1) {
CodecDownmix ^= 1;
return;
}
CodecDownmix = onoff;
}
@ -921,12 +947,9 @@ static void CodecAudioSetClock(AudioDecoder * audio_decoder, int64_t pts)
drift += audio_decoder->Drift;
audio_decoder->Drift = drift;
corr = (10 * audio_decoder->HwSampleRate * drift) / (90 * 1000);
#if defined(USE_PASSTHROUGH) && !defined(USE_AC3_DRIFT_CORRECTION)
// SPDIF/HDMI passthrough
if (!CodecPassthroughAC3
|| audio_decoder->AudioCtx->codec_id != CODEC_ID_AC3)
#endif
{
if ((CodecAudioDrift & 2) && (!CodecPassthroughAC3
|| audio_decoder->AudioCtx->codec_id != CODEC_ID_AC3)) {
audio_decoder->DriftCorr = -corr;
}
@ -1031,7 +1054,7 @@ static void CodecAudioUpdateFormat(AudioDecoder * audio_decoder)
}
// prepare audio drift resample
#ifdef USE_AUDIO_DRIFT_CORRECTION
if (!isAC3) {
if ((CodecAudioDrift & 1) && !isAC3) {
if (audio_decoder->AvResample) {
Error(_("codec/audio: overwrite resample\n"));
}
@ -1062,7 +1085,7 @@ static void CodecAudioUpdateFormat(AudioDecoder * audio_decoder)
void CodecAudioEnqueue(AudioDecoder * audio_decoder, int16_t * data, int count)
{
#ifdef USE_AUDIO_DRIFT_CORRECTION
if (audio_decoder->AvResample) {
if ((CodecAudioDrift & 1) && audio_decoder->AvResample) {
int16_t buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 4 +
FF_INPUT_BUFFER_PADDING_SIZE] __attribute__ ((aligned(16)));
int16_t buftmp[MAX_CHANNELS][(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 4];
@ -1217,7 +1240,7 @@ void CodecAudioDecode(AudioDecoder * audio_decoder, const AVPacket * avpkt)
buf_sz = 6144;
#ifdef USE_AC3_DRIFT_CORRECTION
if (1) {
if (CodecAudioDrift & 2) {
int x;
x = (audio_decoder->DriftFrac +

10
codec.h
View File

@ -67,8 +67,14 @@ extern void CodecAudioOpen(AudioDecoder *, const char *, int);
/// Close audio codec.
extern void CodecAudioClose(AudioDecoder *);
/// Decode an audio packet.
extern void CodecAudioDecodeOld(AudioDecoder *, const AVPacket *);
/// Set audio drift correction.
extern void CodecSetAudioDrift(int);
/// Set audio pass-through.
extern void CodecSetAudioPassthrough(int);
/// Set audio downmix.
extern void CodecSetAudioDownmix(int);
/// Decode an audio packet.
extern void CodecAudioDecode(AudioDecoder *, const AVPacket *);

View File

@ -39,6 +39,7 @@ extern "C"
#include "video.h"
extern const char *X11DisplayName; ///< x11 display name
extern void CodecSetAudioDrift(int);
extern void CodecSetAudioPassthrough(int);
extern void CodecSetAudioDownmix(int);
}
@ -114,8 +115,9 @@ static int ConfigAutoCropDelay; ///< auto crop detection delay
static int ConfigAutoCropTolerance; ///< auto crop detection tolerance
static int ConfigVideoAudioDelay; ///< config audio delay
static int ConfigAudioPassthrough; ///< config audio pass-through
static int ConfigAudioDownmix; ///< config ffmpeg audio downmix
static char ConfigAudioDrift; ///< config audio drift
static char ConfigAudioPassthrough; ///< config audio pass-through
static char ConfigAudioDownmix; ///< config ffmpeg audio downmix
static char ConfigAudioSoftvol; ///< config use software volume
static char ConfigAudioNormalize; ///< config use normalize volume
static int ConfigAudioMaxNormalize; ///< config max normalize factor
@ -509,6 +511,7 @@ class cMenuSetupSoft:public cMenuSetupPage
int Audio;
int AudioDelay;
int AudioDrift;
int AudioPassthrough;
int AudioDownmix;
int AudioSoftvol;
@ -581,6 +584,9 @@ void cMenuSetupSoft::Create(void)
static const char *const scaling[] = {
"Normal", "Fast", "HQ", "Anamorphic"
};
static const char *const audiodrift[] = {
"None", "PCM", "AC-3", "PCM + AC-3"
};
static const char *const passthrough[] = {
"None", "AC-3"
};
@ -687,6 +693,8 @@ void cMenuSetupSoft::Create(void)
if (Audio) {
Add(new cMenuEditIntItem(tr("Audio/Video delay (ms)"), &AudioDelay,
-1000, 1000));
Add(new cMenuEditStraItem(tr("Audio drift correction"),
&AudioDrift, 4, audiodrift));
Add(new cMenuEditStraItem(tr("Audio pass-through"), &AudioPassthrough,
2, passthrough));
Add(new cMenuEditBoolItem(tr("Enable AC-3 downmix"), &AudioDownmix,
@ -809,6 +817,7 @@ cMenuSetupSoft::cMenuSetupSoft(void)
//
Audio = 0;
AudioDelay = ConfigVideoAudioDelay;
AudioDrift = ConfigAudioDrift;
AudioPassthrough = ConfigAudioPassthrough;
AudioDownmix = ConfigAudioDownmix;
AudioSoftvol = ConfigAudioSoftvol;
@ -904,6 +913,8 @@ void cMenuSetupSoft::Store(void)
SetupStore("AudioDelay", ConfigVideoAudioDelay = AudioDelay);
VideoSetAudioDelay(ConfigVideoAudioDelay);
SetupStore("AudioDrift", ConfigAudioDrift = AudioDrift);
CodecSetAudioDrift(ConfigAudioDrift);
SetupStore("AudioPassthrough", ConfigAudioPassthrough = AudioPassthrough);
CodecSetAudioPassthrough(ConfigAudioPassthrough);
SetupStore("AudioDownmix", ConfigAudioDownmix = AudioDownmix);
@ -2014,6 +2025,10 @@ bool cPluginSoftHdDevice::SetupParse(const char *name, const char *value)
VideoSetAudioDelay(ConfigVideoAudioDelay = atoi(value));
return true;
}
if (!strcasecmp(name, "AudioDrift")) {
CodecSetAudioDrift(ConfigAudioDrift = atoi(value));
return true;
}
if (!strcasecmp(name, "AudioPassthrough")) {
CodecSetAudioPassthrough(ConfigAudioPassthrough = atoi(value));
return true;