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 User johns
Date: Date:
Always compile audio drift correction.
Add audio drift correction configuration to the setup.
User mini73 User mini73
Date: Fri Apr 20 16:51:14 CEST 2012 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) ### Configuration (edit this for your needs)
CONFIG := #-DDEBUG 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 += -DAV_INFO -DAV_INFO_TIME=3000 # debug a/v sync
#CONFIG += -DHAVE_PTHREAD_NAME # supports new pthread_setname_np #CONFIG += -DHAVE_PTHREAD_NAME # supports new pthread_setname_np
#CONFIG += -DNO_TS_AUDIO # disable ts audio parser #CONFIG += -DNO_TS_AUDIO # disable ts audio parser

41
codec.c
View File

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

10
codec.h
View File

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

View File

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