diff options
Diffstat (limited to 'src/player.c')
-rw-r--r-- | src/player.c | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/src/player.c b/src/player.c index b8eeead..753d490 100644 --- a/src/player.c +++ b/src/player.c @@ -235,7 +235,7 @@ static bool openStream (player_t * const player) { softfail ("avcodec_parameters_to_context"); } - AVCodec * const decoder = avcodec_find_decoder (cp->codec_id); + const AVCodec * const decoder = avcodec_find_decoder (cp->codec_id); if (decoder == NULL) { softfail ("find_decoder"); } @@ -282,11 +282,13 @@ static bool openFilter (player_t * const player) { /* abuffer */ AVRational time_base = player->st->time_base; + char channelLayout[128]; + av_channel_layout_describe(&player->cctx->ch_layout, channelLayout, sizeof(channelLayout)); snprintf (strbuf, sizeof (strbuf), - "time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=0x%"PRIx64, + "time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=%s", time_base.num, time_base.den, cp->sample_rate, av_get_sample_fmt_name (player->cctx->sample_fmt), - cp->channel_layout); + channelLayout); if ((ret = avfilter_graph_create_filter (&player->fabuf, avfilter_get_by_name ("abuffer"), "source", strbuf, NULL, player->fgraph)) < 0) { @@ -340,7 +342,7 @@ static bool openDevice (player_t * const player) { memset (&aoFmt, 0, sizeof (aoFmt)); aoFmt.bits = av_get_bytes_per_sample (avformat) * 8; assert (aoFmt.bits > 0); - aoFmt.channels = cp->channels; + aoFmt.channels = cp->ch_layout.nb_channels; aoFmt.rate = getSampleRate (player); aoFmt.byte_format = AO_FMT_NATIVE; @@ -401,12 +403,12 @@ BarPlayerMode BarPlayerGetMode (player_t * const player) { static int play (player_t * const player) { assert (player != NULL); const int64_t minBufferHealth = player->settings->bufferSecs; - - AVPacket pkt; AVCodecContext * const cctx = player->cctx; - av_init_packet (&pkt); - pkt.data = NULL; - pkt.size = 0; + + AVPacket *pkt = av_packet_alloc (); + assert (pkt != NULL); + pkt->data = NULL; + pkt->size = 0; AVFrame *frame = NULL; frame = av_frame_alloc (); @@ -418,21 +420,25 @@ static int play (player_t * const player) { const double timeBase = av_q2d (player->st->time_base); while (!shouldQuit (player) && drainMode != DONE) { if (drainMode == FILL) { - ret = av_read_frame (player->fctx, &pkt); + ret = av_read_frame (player->fctx, pkt); if (ret == AVERROR_EOF) { /* 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) { + } else if (pkt->stream_index != player->streamIdx) { /* unused packet */ - av_packet_unref (&pkt); + av_packet_unref (pkt); continue; } 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); + char error[AV_ERROR_MAX_STRING_SIZE]; + if (av_strerror(ret, error, sizeof(error)) < 0) { + strncpy (error, "(unknown)", sizeof(error)-1); + } + debugPrint (DEBUG_AUDIO, "av_read_frame failed with code %i (%s), " + "sending NULL frame\n", ret, error); pthread_mutex_lock (&player->aoplayLock); const int rt = av_buffersrc_add_frame (player->fabuf, NULL); assert (rt == 0); @@ -441,7 +447,7 @@ static int play (player_t * const player) { break; } else { /* fill buffer */ - avcodec_send_packet (cctx, &pkt); + avcodec_send_packet (cctx, pkt); } } @@ -490,9 +496,10 @@ static int play (player_t * const player) { } while (bufferHealth > minBufferHealth); } - av_packet_unref (&pkt); + av_packet_unref (pkt); } av_frame_free (&frame); + av_packet_free (&pkt); debugPrint (DEBUG_AUDIO, "decoder is done, waiting for ao player\n"); pthread_join (aoplaythread, NULL); @@ -532,7 +539,9 @@ void *BarPlayerThread (void *data) { if (openFilter (player) && openDevice (player)) { changeMode (player, PLAYER_PLAYING); BarPlayerSetVolume (player); - retry = play (player) == AVERROR_INVALIDDATA && + const int ret = play (player); + retry = (ret == AVERROR_INVALIDDATA || + ret == -ECONNRESET) && !player->interrupted; } else { /* filter missing or audio device busy */ @@ -582,8 +591,7 @@ void *BarAoPlayThread (void *data) { } pthread_mutex_unlock (&player->aoplayLock); - const int numChannels = av_get_channel_layout_nb_channels ( - filteredFrame->channel_layout); + const int numChannels = filteredFrame->ch_layout.nb_channels; const int bps = av_get_bytes_per_sample (filteredFrame->format); ao_play (player->aoDev, (char *) filteredFrame->data[0], filteredFrame->nb_samples * numChannels * bps); |