summaryrefslogtreecommitdiff
path: root/src/player.h
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2014-03-31 17:35:28 +0200
committerLars-Dominik Braun <lars@6xq.net>2014-03-31 20:20:22 +0200
commitc872f00508ce4afe3b8ec863b23595c31fd8b4be (patch)
treec441d537a5ead0d659bb05e83e8b4bd7d4066f87 /src/player.h
parent8e685c992516834e35bcccea1f61c39a9d847e2f (diff)
downloadpianobar-c872f00508ce4afe3b8ec863b23595c31fd8b4be.tar.gz
pianobar-c872f00508ce4afe3b8ec863b23595c31fd8b4be.tar.bz2
pianobar-c872f00508ce4afe3b8ec863b23595c31fd8b4be.zip
Use libav/ffmpeg for audio decoding
libav 9.12 and ffmpeg 2.2 have been tested. Here’s why: My mp4 “parser” *cough* never was a mp4 parser in the sense that it actually understood the file format. Instead it grepped the input stream for “magic” strings (section identifiers). That alone should be sufficient to throw away the code and rewrite it. Additionally libfaad2 has not been updated for ages. I guess it was abandoned in favor of libav/ffmpeg. With libav/ffmpeg, which we support both as long as the API’s don’t diverge too much, pianobar gains fast and reliable AAC and MP3 decoding without bothering too much about the details. Most users will have it installed already. On my own machine libav consumes about 2/3 CPU time compared to the previous solution when playing AAC. Unfortunately memory usage doubled and my attempts to disable unused protocols/formats/codec failed due to libav’s API limitations. While cleaning up a small detail regarding the eventcmd API has changed too: Song duration and position are measured in seconds instead of milliseconds now. Since libav/ffmpeg keeps track of accurate timing the precision pianobar keeps track of can be reduced, while still being sufficient for most users.
Diffstat (limited to 'src/player.h')
-rw-r--r--src/player.h84
1 files changed, 21 insertions, 63 deletions
diff --git a/src/player.h b/src/player.h
index d107e41..562c12d 100644
--- a/src/player.h
+++ b/src/player.h
@@ -26,90 +26,48 @@ THE SOFTWARE.
#include "config.h"
-#ifdef ENABLE_FAAD
-#include <neaacdec.h>
-#endif
-
-#ifdef ENABLE_MAD
-#include <mad.h>
-#endif
-
-#include <ao/ao.h>
/* required for freebsd */
#include <sys/types.h>
#include <pthread.h>
#include <stdint.h>
+#include <libavfilter/avfilter.h>
#include <piano.h>
#include <waitress.h>
#include "settings.h"
-#define BAR_PLAYER_MS_TO_S_FACTOR 1000
-#define BAR_PLAYER_BUFSIZE (WAITRESS_BUFFER_SIZE*2)
-
struct audioPlayer {
- bool doQuit; /* protected by pauseMutex */
- bool doPause; /* protected by pauseMutex */
- unsigned char channels;
- unsigned char aoError;
+ /* protected by pauseMutex */
+ volatile bool doQuit;
+ volatile bool doPause;
+ pthread_mutex_t pauseMutex;
+ pthread_cond_t pauseCond;
enum {
- PLAYER_FREED = 0, /* thread is not running */
+ PLAYER_DEAD = 0, /* thread is not running */
PLAYER_STARTING, /* thread is starting */
- PLAYER_INITIALIZED, /* decoder/waitress initialized */
- PLAYER_FOUND_ESDS,
- PLAYER_AUDIO_INITIALIZED, /* audio device opened */
- PLAYER_FOUND_STSZ,
- PLAYER_SAMPLESIZE_INITIALIZED,
- PLAYER_RECV_DATA, /* playing track */
- PLAYER_FINISHED_PLAYBACK
+ PLAYER_PLAYING,
+ PLAYER_FINISHED,
} mode;
- PianoAudioFormat_t audioFormat;
-
- unsigned int scale;
- float gain;
-
- /* duration and already played time; measured in milliseconds */
- unsigned long int songDuration;
- unsigned long int songPlayed;
-
- unsigned long samplerate;
-
- size_t bufferFilled;
- size_t bufferRead;
- size_t bytesReceived;
-
- /* aac */
- #ifdef ENABLE_FAAD
- /* stsz atom: sample sizes */
- size_t sampleSizeN;
- size_t sampleSizeCurr;
- uint32_t *sampleSize;
- NeAACDecHandle aacHandle;
- #endif
-
- /* mp3 */
- #ifdef ENABLE_MAD
- struct mad_stream mp3Stream;
- struct mad_frame mp3Frame;
- struct mad_synth mp3Synth;
- #endif
-
- /* audio out */
- ao_device *audioOutDevice;
- const BarSettings_t *settings;
- unsigned char *buffer;
+ AVFilterContext *fvolume;
- pthread_mutex_t pauseMutex;
- pthread_cond_t pauseCond;
- WaitressHandle_t waith;
+ volatile double volume;
+ double gain;
+ char *url;
+ const BarSettings_t *settings;
+
+ /* measured in seconds */
+ volatile unsigned int songDuration;
+ volatile unsigned int songPlayed;
};
enum {PLAYER_RET_OK = 0, PLAYER_RET_HARDFAIL = 1, PLAYER_RET_SOFTFAIL = 2};
void *BarPlayerThread (void *data);
-unsigned int BarPlayerCalcScale (float);
+void BarPlayerSetVolume (struct audioPlayer * const player);
+void BarPlayerInit ();
+void BarPlayerDestroy ();
#endif /* _PLAYER_H */