int frame_drops_early;
int frame_drops_late;
AVFrame *frame;
+ int64_t audio_frame_next_pts;
enum ShowMode {
SHOW_MODE_NONE = -1, SHOW_MODE_VIDEO = 0, SHOW_MODE_WAVES, SHOW_MODE_RDFT, SHOW_MODE_NB
}
av_rdft_calc(s->rdft, data[ch]);
}
- // least efficient way to do this, we should of course directly access it but its more than fast enough
+ /* Least efficient way to do this, we should of course
+ * directly access it but it is more than fast enough. */
for (y = 0; y < s->height; y++) {
double w = 1 / sqrt(nb_freq);
int a = sqrt(w * sqrt(data[0][2 * y + 0] * data[0][2 * y + 0] + data[0][2 * y + 1] * data[0][2 * y + 1]));
int64_t dec_channel_layout;
int got_frame;
av_unused double audio_clock0;
- int new_packet = 0;
- int flush_complete = 0;
int wanted_nb_samples;
AVRational tb;
int ret;
for (;;) {
/* NOTE: the audio packet can contain several frames */
- while (pkt_temp->size > 0 || (!pkt_temp->data && new_packet) || is->audio_buf_frames_pending) {
+ while (pkt_temp->stream_index != -1 || is->audio_buf_frames_pending) {
if (!is->frame) {
if (!(is->frame = avcodec_alloc_frame()))
return AVERROR(ENOMEM);
return -1;
if (!is->audio_buf_frames_pending) {
- if (flush_complete)
- break;
- new_packet = 0;
len1 = avcodec_decode_audio4(dec, is->frame, &got_frame, pkt_temp);
if (len1 < 0) {
/* if error, we skip the frame */
break;
}
+ pkt_temp->dts =
+ pkt_temp->pts = AV_NOPTS_VALUE;
pkt_temp->data += len1;
pkt_temp->size -= len1;
+ if (pkt_temp->data && pkt_temp->size <= 0 || !pkt_temp->data && !got_frame)
+ pkt_temp->stream_index = -1;
- if (!got_frame) {
- /* stop sending empty packets if the decoder is finished */
- if (!pkt_temp->data && dec->codec->capabilities & CODEC_CAP_DELAY)
- flush_complete = 1;
+ if (!got_frame)
continue;
- }
tb = (AVRational){1, is->frame->sample_rate};
if (is->frame->pts != AV_NOPTS_VALUE)
is->frame->pts = av_rescale_q(is->frame->pts, dec->time_base, tb);
else if (is->frame->pkt_pts != AV_NOPTS_VALUE)
is->frame->pts = av_rescale_q(is->frame->pkt_pts, is->audio_st->time_base, tb);
- if (pkt_temp->pts != AV_NOPTS_VALUE)
- pkt_temp->pts += (double) is->frame->nb_samples / is->frame->sample_rate / av_q2d(is->audio_st->time_base);
+ else if (is->audio_frame_next_pts != AV_NOPTS_VALUE)
+#if CONFIG_AVFILTER
+ is->frame->pts = av_rescale_q(is->audio_frame_next_pts, (AVRational){1, is->audio_filter_src.freq}, tb);
+#else
+ is->frame->pts = av_rescale_q(is->audio_frame_next_pts, (AVRational){1, is->audio_src.freq}, tb);
+#endif
+
+ if (is->frame->pts != AV_NOPTS_VALUE)
+ is->audio_frame_next_pts = is->frame->pts + is->frame->nb_samples;
#if CONFIG_AVFILTER
dec_channel_layout = get_valid_channel_layout(is->frame->channel_layout, av_frame_get_channels(is->frame));
if (pkt->data)
av_free_packet(pkt);
memset(pkt_temp, 0, sizeof(*pkt_temp));
+ pkt_temp->stream_index = -1;
if (is->audioq.abort_request) {
return -1;
SDL_CondSignal(is->continue_read_thread);
/* read next packet */
- if ((new_packet = packet_queue_get(&is->audioq, pkt, 1, &is->audio_pkt_temp_serial)) < 0)
+ if ((packet_queue_get(&is->audioq, pkt, 1, &is->audio_pkt_temp_serial)) < 0)
return -1;
if (pkt->data == flush_pkt.data) {
avcodec_flush_buffers(dec);
- flush_complete = 0;
is->audio_buf_frames_pending = 0;
+ is->audio_frame_next_pts = AV_NOPTS_VALUE;
+ if ((is->ic->iformat->flags & (AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK)) && !is->ic->iformat->read_seek)
+ is->audio_frame_next_pts = is->audio_st->start_time;
}
*pkt_temp = *pkt;
memset(&is->audio_pkt, 0, sizeof(is->audio_pkt));
memset(&is->audio_pkt_temp, 0, sizeof(is->audio_pkt_temp));
+ is->audio_pkt_temp.stream_index = -1;
is->audio_stream = stream_index;
is->audio_st = ic->streams[stream_index];
}
if (is->video_stream < 0 && is->audio_stream < 0) {
- av_log(NULL, AV_LOG_FATAL, "%s: could not open codecs\n", is->filename);
+ av_log(NULL, AV_LOG_FATAL, "Failed to open file '%s' or configure filtergraph\n",
+ is->filename);
ret = -1;
goto fail;
}