diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2018-12-16 14:14:41 +0100 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2020-08-09 08:42:11 +0200 |
commit | bc6bd8a2b8b84a79dd77b81d6a25b661c5d1d1ca (patch) | |
tree | 3013cbf73ea3374d9974d251e11da87be7d1276b /src/player.c | |
parent | 7f6457aa9b7110869e89111c42651b1055728679 (diff) | |
download | pianobar-bc6bd8a2b8b84a79dd77b81d6a25b661c5d1d1ca.tar.gz pianobar-bc6bd8a2b8b84a79dd77b81d6a25b661c5d1d1ca.tar.bz2 pianobar-bc6bd8a2b8b84a79dd77b81d6a25b661c5d1d1ca.zip |
Add optional debugging code
Compile *without* -DNDEBUG. The environment variable PIANOBAR_DEBUG
accepts a bitfield which enables (1) network (2) audio (4) UI debug
messages.
Diffstat (limited to 'src/player.c')
-rw-r--r-- | src/player.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/player.c b/src/player.c index d73b718..b8eeead 100644 --- a/src/player.c +++ b/src/player.c @@ -41,6 +41,7 @@ THE SOFTWARE. #include <fcntl.h> #include <limits.h> #include <assert.h> +#include <inttypes.h> #include <arpa/inet.h> #include <sys/stat.h> @@ -58,6 +59,7 @@ THE SOFTWARE. #include <libavutil/frame.h> #include "player.h" +#include "debug.h" #include "ui.h" #include "ui_types.h" @@ -421,6 +423,7 @@ static int play (player_t * const player) { /* enter drain mode */ drainMode = DRAIN; avcodec_send_packet (cctx, NULL); + debugPrint (DEBUG_AUDIO, "decoder entering drain mode after EOF\n"); } else if (pkt.stream_index != player->streamIdx) { /* unused packet */ av_packet_unref (&pkt); @@ -428,6 +431,8 @@ static int play (player_t * const player) { } else if (ret < 0) { /* error, abort */ /* mark the EOF, so that BarAoPlayThread can quit*/ + debugPrint (DEBUG_AUDIO, "av_read_frame failed with code %i, sending " + "NULL frame\n", ret); pthread_mutex_lock (&player->aoplayLock); const int rt = av_buffersrc_add_frame (player->fabuf, NULL); assert (rt == 0); @@ -446,6 +451,7 @@ static int play (player_t * const player) { /* done draining */ drainMode = DONE; /* mark the EOF*/ + debugPrint (DEBUG_AUDIO, "receive_frame got EOF, sending NULL frame\n"); pthread_mutex_lock (&player->aoplayLock); const int rt = av_buffersrc_add_frame (player->fabuf, NULL); assert (rt == 0); @@ -471,10 +477,14 @@ static int play (player_t * const player) { pthread_mutex_lock (&player->aoplayLock); bufferHealth = timeBase * (double) (frame->pts - player->lastTimestamp); if (bufferHealth > minBufferHealth) { + debugPrint (DEBUG_AUDIO, "decoding buffer filled health %"PRIi64" minHealth %"PRIi64"\n", + bufferHealth, minBufferHealth); /* Buffer get healthy, resume */ pthread_cond_broadcast (&player->aoplayCond); /* Buffer is healthy enough, wait */ pthread_cond_wait (&player->aoplayCond, &player->aoplayLock); + debugPrint (DEBUG_AUDIO, "ao play signalled it needs more data health %"PRIi64" minHealth %"PRIi64"\n", + bufferHealth, minBufferHealth); } pthread_mutex_unlock (&player->aoplayLock); } while (bufferHealth > minBufferHealth); @@ -483,6 +493,7 @@ static int play (player_t * const player) { av_packet_unref (&pkt); } av_frame_free (&frame); + debugPrint (DEBUG_AUDIO, "decoder is done, waiting for ao player\n"); pthread_join (aoplaythread, NULL); return ret; @@ -558,9 +569,12 @@ void *BarAoPlayThread (void *data) { if (ret == AVERROR_EOF || shouldQuit (player)) { /* we are done here */ pthread_mutex_unlock (&player->aoplayLock); + debugPrint (DEBUG_AUDIO, "ao player got EOF, exiting\n"); break; } else if (ret < 0) { /* wait for more frames */ + debugPrint (DEBUG_AUDIO, "ao player is waiting for more frames after code %i (%s)\n", + ret, av_err2str (ret)); pthread_cond_broadcast (&player->aoplayCond); pthread_cond_wait (&player->aoplayCond, &player->aoplayLock); pthread_mutex_unlock (&player->aoplayLock); @@ -582,8 +596,10 @@ void *BarAoPlayThread (void *data) { /* pausing */ if (player->doPause) { do { + debugPrint (DEBUG_AUDIO, "ao player is paused\n"); pthread_cond_wait (&player->cond, &player->lock); } while (player->doPause); + debugPrint (DEBUG_AUDIO, "ao player continues\n"); } pthread_mutex_unlock (&player->lock); @@ -599,6 +615,7 @@ void *BarAoPlayThread (void *data) { av_frame_unref (filteredFrame); } av_frame_free (&filteredFrame); + debugPrint (DEBUG_AUDIO, "ao player is done\n"); return (void *) 0; } |