typedef struct SubPicture {
double pts; /* presentation time stamp for this picture */
AVSubtitle sub;
+ int serial;
} SubPicture;
typedef struct AudioParams {
SDL_Thread *subtitle_tid;
int subtitle_stream;
- int subtitle_stream_changed;
AVStream *subtitle_st;
PacketQueue subtitleq;
SubPicture subpq[SUBPICTURE_QUEUE_SIZE];
}
if (is->subtitle_st) {
- if (is->subtitle_stream_changed) {
- SDL_LockMutex(is->subpq_mutex);
-
- while (is->subpq_size) {
- free_subpicture(&is->subpq[is->subpq_rindex]);
-
- /* update queue size and signal for next picture */
- if (++is->subpq_rindex == SUBPICTURE_QUEUE_SIZE)
- is->subpq_rindex = 0;
-
- is->subpq_size--;
- }
- is->subtitle_stream_changed = 0;
-
- SDL_CondSignal(is->subpq_cond);
- SDL_UnlockMutex(is->subpq_mutex);
- } else {
- if (is->subpq_size > 0) {
+ while (is->subpq_size > 0) {
sp = &is->subpq[is->subpq_rindex];
if (is->subpq_size > 1)
else
sp2 = NULL;
- if ((is->vidclk.pts > (sp->pts + ((float) sp->sub.end_display_time / 1000)))
+ if (sp->serial != is->subtitleq.serial
+ || (is->vidclk.pts > (sp->pts + ((float) sp->sub.end_display_time / 1000)))
|| (sp2 && is->vidclk.pts > (sp2->pts + ((float) sp2->sub.start_display_time / 1000))))
{
free_subpicture(sp);
is->subpq_size--;
SDL_CondSignal(is->subpq_cond);
SDL_UnlockMutex(is->subpq_mutex);
+ } else {
+ break;
}
}
- }
}
display:
SubPicture *sp;
AVPacket pkt1, *pkt = &pkt1;
int got_subtitle;
+ int serial;
double pts;
int i, j;
int r, g, b, y, u, v, a;
while (is->paused && !is->subtitleq.abort_request) {
SDL_Delay(10);
}
- if (packet_queue_get(&is->subtitleq, pkt, 1, NULL) < 0)
+ if (packet_queue_get(&is->subtitleq, pkt, 1, &serial) < 0)
break;
if (pkt->data == flush_pkt.data) {
if (sp->sub.pts != AV_NOPTS_VALUE)
pts = sp->sub.pts / (double)AV_TIME_BASE;
sp->pts = pts;
+ sp->serial = serial;
for (i = 0; i < sp->sub.num_rects; i++)
{
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);
- if (is->frame->pts == AV_NOPTS_VALUE && pkt_temp->pts != AV_NOPTS_VALUE)
- is->frame->pts = av_rescale_q(pkt_temp->pts, is->audio_st->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);
/* note: we also signal this mutex to make sure we deblock the
video thread in all cases */
SDL_LockMutex(is->subpq_mutex);
- is->subtitle_stream_changed = 1;
-
SDL_CondSignal(is->subpq_cond);
SDL_UnlockMutex(is->subpq_mutex);
pkt->stream_index = is->video_stream;
packet_queue_put(&is->videoq, pkt);
}
- if (is->audio_stream >= 0 &&
- is->audio_st->codec->codec->capabilities & CODEC_CAP_DELAY) {
+ if (is->audio_stream >= 0) {
av_init_packet(pkt);
pkt->data = NULL;
pkt->size = 0;