From c17af0e95857877c608bcced814ed2cd1edb1482 Mon Sep 17 00:00:00 2001 From: Johns Date: Thu, 23 Feb 2012 15:32:43 +0100 Subject: [PATCH] Fix bug: 100% cpu use with plugins like mp3. --- ChangeLog | 1 + softhddev.c | 23 ++++++++++++++++------- softhddev.h | 2 +- softhddevice.cpp | 8 ++++---- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index e07909e..e0c1d9d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ User johns Date: + Fix bug: 100% cpu use with plugins like mp3. Wakeup display thread on channel switch, osd can now be shown without video. Makes 60Hz display mode configurable with setup.conf. diff --git a/softhddev.c b/softhddev.c index ec73ba5..b9c4dfd 100644 --- a/softhddev.c +++ b/softhddev.c @@ -75,6 +75,8 @@ static AudioDecoder *MyAudioDecoder; ///< audio decoder static enum CodecID AudioCodecID; ///< current codec id static int AudioChannelID; ///< current audio channel id + /// Minimum free space in audio buffer 8 packets for 8 channels +#define AUDIO_MIN_BUFFER_FREE (3072 * 8 * 8) #define AUDIO_BUFFER_SIZE (512 * 1024) ///< audio PES buffer default size static AVPacket AudioAvPkt[1]; ///< audio a/v packet @@ -864,7 +866,7 @@ int PlayAudio(const uint8_t * data, int size, uint8_t id) NewAudioStream = 0; } // Don't overrun audio buffers on replay - if (AudioFreeBytes() < 3072 * 8 * 8) { // 8 channels 8 packets + if (AudioFreeBytes() < AUDIO_MIN_BUFFER_FREE) { return 0; } // PES header 0x00 0x00 0x01 ID @@ -1058,7 +1060,7 @@ int PlayTsAudio(const uint8_t * data, int size) return size; } // Don't overrun audio buffers on replay - if (AudioFreeBytes() < 3072 * 8 * 8) { // 8 channels 8 packets + if (AudioFreeBytes() < AUDIO_MIN_BUFFER_FREE) { return 0; } @@ -1827,7 +1829,7 @@ uint8_t *GrabImage(int *size, int jpeg, int quality, int width, int height) /** ** Set play mode, called on channel switch. */ -void SetPlayMode(void) +int SetPlayMode(int play_mode) { if (ConfigStartSuspended) { // ignore first call, if start suspended ConfigStartSuspended = 0; @@ -1835,18 +1837,23 @@ void SetPlayMode(void) } Resume(); VideoDisplayWakeup(); - if (MyVideoDecoder) { + if (MyVideoDecoder) { // tell video parser we have new stream if (VideoCodecID != CODEC_ID_NONE) { NewVideoStream = 1; VideoSwitch = GetMsTicks(); } } - if (MyAudioDecoder) { + if (MyAudioDecoder) { // tell audio parser we have new stream if (AudioCodecID != CODEC_ID_NONE) { NewAudioStream = 1; } } + if (play_mode == 2 || play_mode == 3 ) { + Debug(3, "softhddev: FIXME: audio only, silence video errors\n"); + } Play(); + + return 1; } /** @@ -1990,11 +1997,13 @@ void StillPicture(const uint8_t * data, int size) int Poll(int timeout) { // buffers are too full - if (atomic_read(&VideoPacketsFilled) >= VIDEO_PACKET_MAX * 2 / 3) { + if ( atomic_read(&VideoPacketsFilled) >= VIDEO_PACKET_MAX * 2 / 3 + || AudioFreeBytes() < AUDIO_MIN_BUFFER_FREE * 2) { if (timeout) { // let display thread work usleep(timeout * 1000); } - return atomic_read(&VideoPacketsFilled) < VIDEO_PACKET_MAX * 2 / 3; + return atomic_read(&VideoPacketsFilled) < VIDEO_PACKET_MAX * 2 / 3 + && AudioFreeBytes() > AUDIO_MIN_BUFFER_FREE; } return 1; } diff --git a/softhddev.h b/softhddev.h index 573c37a..60bca89 100644 --- a/softhddev.h +++ b/softhddev.h @@ -50,7 +50,7 @@ extern "C" extern uint8_t *GrabImage(int *, int, int, int, int); /// C plugin set play mode - extern void SetPlayMode(void); + extern int SetPlayMode(int); /// C plugin set trick speed extern void TrickSpeed(int); /// C plugin clears all video and audio data from the device diff --git a/softhddevice.cpp b/softhddevice.cpp index 77cdec2..a63d02e 100644 --- a/softhddevice.cpp +++ b/softhddevice.cpp @@ -295,7 +295,7 @@ void cSoftOsd::Flush(void) } #ifdef DEBUG if (w > bitmap->Width() || h > bitmap->Height()) { - esyslog(tr("softhddev: dirty area too big\n")); + esyslog(tr("[softhddev]: dirty area too big\n")); abort(); } #endif @@ -742,7 +742,7 @@ static void HandleHotkey(int code) CodecSetAudioPassthrough(ConfigAudioPassthrough ^= 1); break; default: - esyslog(tr("softhddev: hot key %d is not supported\n"), code); + esyslog(tr("[softhddev]: hot key %d is not supported\n"), code); break; } } @@ -954,8 +954,8 @@ bool cSoftHdDevice::SetPlayMode(ePlayMode play_mode) dsyslog("[softhddev] playmode not implemented... %d\n", play_mode); break; } - ::SetPlayMode(); - return true; + + return ::SetPlayMode(play_mode); } /**