Skip to content

Commit

Permalink
Revert "added some optimization patches by @j1rie"
Browse files Browse the repository at this point in the history
This reverts commit dc8740b.
  • Loading branch information
louisbraun committed Jul 17, 2016
1 parent dc8740b commit a5ba215
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 119 deletions.
49 changes: 12 additions & 37 deletions audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ static int AudioBufferTime = 336; ///< audio buffer time in ms
#ifdef USE_AUDIO_THREAD
static pthread_t AudioThread; ///< audio play thread
static pthread_mutex_t AudioMutex; ///< audio condition mutex
pthread_mutex_t PTS_mutex; ///< PTS mutex
pthread_mutex_t ReadAdvance_mutex; ///< PTS mutex
static pthread_cond_t AudioStartCond; ///< condition variable
static char AudioThreadStop; ///< stop audio thread
#else
Expand All @@ -170,13 +168,10 @@ static int AudioStereoDescent; ///< volume descent for stereo
static int AudioVolume; ///< current volume (0 .. 1000)

extern int VideoAudioDelay; ///< import audio/video delay
extern volatile char SoftIsPlayingVideo; ///< stream contains video data

/// default ring buffer size ~2s 8ch 16bit (3 * 5 * 7 * 8)
static const unsigned AudioRingBufferSize = 3 * 5 * 7 * 8 * 2 * 1000;

#define AUDIO_MIN_BUFFER_FREE (3072 * 8 * 8)

static int AudioChannelsInHw[9]; ///< table which channels are supported
enum _audio_rates
{ ///< sample rates enumeration
Expand Down Expand Up @@ -862,7 +857,6 @@ static int AlsaPlayRingbuffer(void)
#endif

for (;;) {
pthread_mutex_lock(&ReadAdvance_mutex);
if (AlsaUseMmap) {
err = snd_pcm_mmap_writei(AlsaPCMHandle, p, frames);
} else {
Expand All @@ -871,7 +865,6 @@ static int AlsaPlayRingbuffer(void)
//Debug(3, "audio/alsa: wrote %d/%d frames\n", err, frames);
if (err != frames) {
if (err < 0) {
pthread_mutex_unlock(&ReadAdvance_mutex);
if (err == -EAGAIN) {
continue;
}
Expand All @@ -884,7 +877,7 @@ static int AlsaPlayRingbuffer(void)
snd_strerror(err));
err = snd_pcm_recover(AlsaPCMHandle, err, 0);
if (err >= 0) {
return 0;
continue;
}
Error(_("audio/alsa: snd_pcm_writei failed: %s\n"),
snd_strerror(err));
Expand All @@ -897,7 +890,6 @@ static int AlsaPlayRingbuffer(void)
break;
}
RingBufferReadAdvance(AudioRing[AudioRingRead].RingBuffer, avail);
pthread_mutex_unlock(&ReadAdvance_mutex);
first = 0;
}

Expand Down Expand Up @@ -968,7 +960,7 @@ static int AlsaThread(void)
}
break;
}
if (/*!err ||*/ AudioPaused) { // timeout or some commands
if (!err || AudioPaused) { // timeout or some commands
return 1;
}

Expand Down Expand Up @@ -2026,7 +2018,6 @@ static int AudioNextRing(void)
int sample_rate;
int channels;
size_t used;
size_t remain;

// update audio format
// not always needed, but check if needed is too complex
Expand All @@ -2051,14 +2042,9 @@ static int AudioNextRing(void)
/ (AudioRing[AudioRingWrite].HwSampleRate *
AudioRing[AudioRingWrite].HwChannels * AudioBytesProSample));

used = RingBufferUsedBytes(AudioRing[AudioRingRead].RingBuffer);
remain = RingBufferFreeBytes(AudioRing[AudioRingRead].RingBuffer);
// stop, if not enough in next buffer
if (remain <= AUDIO_MIN_BUFFER_FREE) {
Debug(3, "audio: force start\n");
}
if (remain <= AUDIO_MIN_BUFFER_FREE || ((AudioVideoIsReady
|| !SoftIsPlayingVideo)
used = RingBufferUsedBytes(AudioRing[AudioRingRead].RingBuffer);
if (AudioStartThreshold * 4 < used || (AudioVideoIsReady
&& AudioStartThreshold < used)) {
return 0;
}
Expand Down Expand Up @@ -2193,8 +2179,6 @@ static void AudioInitThread(void)
{
AudioThreadStop = 0;
pthread_mutex_init(&AudioMutex, NULL);
pthread_mutex_init(&PTS_mutex, NULL);
pthread_mutex_init(&ReadAdvance_mutex, NULL);
pthread_cond_init(&AudioStartCond, NULL);
pthread_create(&AudioThread, NULL, AudioPlayHandlerThread, NULL);
pthread_setname_np(AudioThread, "softhddev audio");
Expand All @@ -2218,8 +2202,6 @@ static void AudioExitThread(void)
}
pthread_cond_destroy(&AudioStartCond);
pthread_mutex_destroy(&AudioMutex);
pthread_mutex_destroy(&PTS_mutex);
pthread_mutex_destroy(&ReadAdvance_mutex);
AudioThread = 0;
}
}
Expand Down Expand Up @@ -2315,7 +2297,6 @@ void AudioEnqueue(const void *samples, int count)
}
}

pthread_mutex_lock(&PTS_mutex);
n = RingBufferWrite(AudioRing[AudioRingWrite].RingBuffer, buffer, count);
if (n != (size_t) count) {
Error(_("audio: can't place %d samples in ring buffer\n"), count);
Expand All @@ -2327,7 +2308,6 @@ void AudioEnqueue(const void *samples, int count)

if (!AudioRunning) { // check, if we can start the thread
int skip;
size_t remain;

n = RingBufferUsedBytes(AudioRing[AudioRingWrite].RingBuffer);
skip = AudioSkip;
Expand All @@ -2349,12 +2329,8 @@ void AudioEnqueue(const void *samples, int count)
n = RingBufferUsedBytes(AudioRing[AudioRingWrite].RingBuffer);
}
// forced start or enough video + audio buffered
remain = RingBufferFreeBytes(AudioRing[AudioRingRead].RingBuffer);
if (remain <= AUDIO_MIN_BUFFER_FREE) {
Debug(3, "audio: force start\n");
}
if (remain <= AUDIO_MIN_BUFFER_FREE || ((AudioVideoIsReady
|| !SoftIsPlayingVideo)
// for some exotic channels * 4 too small
if (AudioStartThreshold * 4 < n || (AudioVideoIsReady
&& AudioStartThreshold < n)) {
// restart play-back
// no lock needed, can wakeup next time
Expand All @@ -2368,7 +2344,6 @@ void AudioEnqueue(const void *samples, int count)
/ (AudioRing[AudioRingWrite].HwSampleRate *
AudioRing[AudioRingWrite].HwChannels * AudioBytesProSample);
}
pthread_mutex_unlock(&PTS_mutex);
}

/**
Expand Down Expand Up @@ -2415,7 +2390,7 @@ void AudioVideoReady(int64_t pts)
// buffer ~15 video frames
// FIXME: HDTV can use smaller video buffer
skip =
pts - 15 * 20 * 90 - AudioBufferTime * 90 - audio_pts -
pts - 15 * 20 * 90 - AudioBufferTime * 90 - audio_pts +
VideoAudioDelay;
#ifdef DEBUG
fprintf(stderr, "%dms %dms %dms\n", (int)(pts - audio_pts) / 90,
Expand All @@ -2427,14 +2402,14 @@ void AudioVideoReady(int64_t pts)
/ (1000 * 90))
* AudioRing[AudioRingWrite].HwChannels * AudioBytesProSample;
// FIXME: round to packet size
Debug(3, "audio: sync advance %dms %d/%zd\n",
(skip * 1000) / (AudioRing[AudioRingWrite].HwSampleRate *
AudioRing[AudioRingWrite].HwChannels *
AudioBytesProSample), skip, used);
if ((unsigned)skip > used) {
AudioSkip = skip - used;
skip = used;
}
Debug(3, "audio: sync advance %dms %d/%zd\n",
(skip * 1000) / (AudioRing[AudioRingWrite].HwSampleRate *
AudioRing[AudioRingWrite].HwChannels *
AudioBytesProSample), skip, used);
RingBufferReadAdvance(AudioRing[AudioRingWrite].RingBuffer, skip);

used = RingBufferUsedBytes(AudioRing[AudioRingWrite].RingBuffer);
Expand Down Expand Up @@ -2611,7 +2586,7 @@ int64_t AudioGetDelay(void)
void AudioSetClock(int64_t pts)
{
if (AudioRing[AudioRingWrite].PTS != pts) {
Debug(3, "audio: sync set clock %s -> %s pts\n",
Debug(4, "audio: set clock %s -> %s pts\n",
Timestamp2String(AudioRing[AudioRingWrite].PTS),
Timestamp2String(pts));
}
Expand Down
7 changes: 1 addition & 6 deletions softhddev.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static void DumpMpeg(const uint8_t * data, int size);
//////////////////////////////////////////////////////////////////////////////

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
static signed char ConfigStartSuspended; ///< flag to start in suspend mode
static char ConfigFullscreen; ///< fullscreen modus
Expand Down Expand Up @@ -3504,8 +3504,3 @@ int PipPlayVideo(const uint8_t * data, int size)
}

#endif

int IsReplay(void)
{
return !AudioSyncStream || AudioSyncStream->ClearClose;
}
9 changes: 0 additions & 9 deletions softhddevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ static volatile int DoMakePrimary; ///< switch primary device to this
#define SUSPEND_NORMAL 1 ///< normal suspend mode
#define SUSPEND_DETACHED 2 ///< detached suspend mode
static signed char SuspendMode; ///< suspend mode
volatile char SoftIsPlayingVideo; ///< stream contains video data

//////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -2866,13 +2865,6 @@ int cSoftHdDevice::PlayTsVideo(const uchar * data, int length)
int cSoftHdDevice::PlayTsAudio(const uchar * data, int length)
{
#ifndef NO_TS_AUDIO
if (SoftIsPlayingVideo != cDevice::IsPlayingVideo()) {
SoftIsPlayingVideo = cDevice::IsPlayingVideo();
#ifdef DEBUG
dsyslog("[softhddev]%s: SoftIsPlayingVideo: %d\n", __FUNCTION__, SoftIsPlayingVideo);
#endif
}

return::PlayTsAudio(data, length);
#else
AudioPoller();
Expand Down Expand Up @@ -3396,7 +3388,6 @@ bool cPluginSoftHdDevice::SetupParse(const char *name, const char *value)
}
if (!strcasecmp(name, "AudioBufferTime")) {
ConfigAudioBufferTime = atoi(value);
AudioSetBufferTime(ConfigAudioBufferTime);
return true;
}
if (!strcasecmp(name, "AudioAutoAES")) {
Expand Down
Loading

0 comments on commit a5ba215

Please sign in to comment.