Ticket #2666: subtitle-fix.patch

File subtitle-fix.patch, 3.6 KB (added by Marton Balint, 13 years ago)

Fix subtitle issues on seek

  • ffplay.c

    diff --git a/ffplay.c b/ffplay.c
    index 74915c9..946e9b3 100644
    a b typedef struct VideoPicture {  
    134134typedef struct SubPicture {
    135135    double pts; /* presentation time stamp for this picture */
    136136    AVSubtitle sub;
     137    int serial;
    137138} SubPicture;
    138139
    139140typedef struct AudioParams {
    typedef struct VideoState {  
    230231
    231232    SDL_Thread *subtitle_tid;
    232233    int subtitle_stream;
    233     int subtitle_stream_changed;
    234234    AVStream *subtitle_st;
    235235    PacketQueue subtitleq;
    236236    SubPicture subpq[SUBPICTURE_QUEUE_SIZE];
    retry:  
    14001400            }
    14011401
    14021402            if (is->subtitle_st) {
    1403                 if (is->subtitle_stream_changed) {
    1404                     SDL_LockMutex(is->subpq_mutex);
    1405 
    1406                     while (is->subpq_size) {
    1407                         free_subpicture(&is->subpq[is->subpq_rindex]);
    1408 
    1409                         /* update queue size and signal for next picture */
    1410                         if (++is->subpq_rindex == SUBPICTURE_QUEUE_SIZE)
    1411                             is->subpq_rindex = 0;
    1412 
    1413                         is->subpq_size--;
    1414                     }
    1415                     is->subtitle_stream_changed = 0;
    1416 
    1417                     SDL_CondSignal(is->subpq_cond);
    1418                     SDL_UnlockMutex(is->subpq_mutex);
    1419                 } else {
    1420                     if (is->subpq_size > 0) {
     1403                    while (is->subpq_size > 0) {
    14211404                        sp = &is->subpq[is->subpq_rindex];
    14221405
    14231406                        if (is->subpq_size > 1)
    retry:  
    14251408                        else
    14261409                            sp2 = NULL;
    14271410
    1428                         if ((is->vidclk.pts > (sp->pts + ((float) sp->sub.end_display_time / 1000)))
     1411                        if (sp->serial != is->subtitleq.serial
     1412                                || (is->vidclk.pts > (sp->pts + ((float) sp->sub.end_display_time / 1000)))
    14291413                                || (sp2 && is->vidclk.pts > (sp2->pts + ((float) sp2->sub.start_display_time / 1000))))
    14301414                        {
    14311415                            free_subpicture(sp);
    retry:  
    14381422                            is->subpq_size--;
    14391423                            SDL_CondSignal(is->subpq_cond);
    14401424                            SDL_UnlockMutex(is->subpq_mutex);
     1425                        } else {
     1426                            break;
    14411427                        }
    14421428                    }
    1443                 }
    14441429            }
    14451430
    14461431display:
    static int subtitle_thread(void *arg)  
    20001985    SubPicture *sp;
    20011986    AVPacket pkt1, *pkt = &pkt1;
    20021987    int got_subtitle;
     1988    int serial;
    20031989    double pts;
    20041990    int i, j;
    20051991    int r, g, b, y, u, v, a;
    static int subtitle_thread(void *arg)  
    20081994        while (is->paused && !is->subtitleq.abort_request) {
    20091995            SDL_Delay(10);
    20101996        }
    2011         if (packet_queue_get(&is->subtitleq, pkt, 1, NULL) < 0)
     1997        if (packet_queue_get(&is->subtitleq, pkt, 1, &serial) < 0)
    20121998            break;
    20131999
    20142000        if (pkt->data == flush_pkt.data) {
    static int subtitle_thread(void *arg)  
    20392025            if (sp->sub.pts != AV_NOPTS_VALUE)
    20402026                pts = sp->sub.pts / (double)AV_TIME_BASE;
    20412027            sp->pts = pts;
     2028            sp->serial = serial;
    20422029
    20432030            for (i = 0; i < sp->sub.num_rects; i++)
    20442031            {
    static void stream_component_close(VideoState *is, int stream_index)  
    26332620        /* note: we also signal this mutex to make sure we deblock the
    26342621           video thread in all cases */
    26352622        SDL_LockMutex(is->subpq_mutex);
    2636         is->subtitle_stream_changed = 1;
    2637 
    26382623        SDL_CondSignal(is->subpq_cond);
    26392624        SDL_UnlockMutex(is->subpq_mutex);
    26402625