Revision 39c6a118 ffplay.c

View differences:

ffplay.c
171 171
    SDL_mutex *pictq_mutex;
172 172
    SDL_cond *pictq_cond;
173 173

  
174
    SDL_mutex *video_decoder_mutex;
175
    SDL_mutex *audio_decoder_mutex;
176
    SDL_mutex *subtitle_decoder_mutex;
177

  
178 174
    //    QETimer *video_timer;
179 175
    char filename[1024];
180 176
    int width, height, xleft, ytop;
......
217 213
static VideoState *cur_stream;
218 214
static int64_t audio_callback_time;
219 215

  
216
AVPacket flush_pkt;
217

  
220 218
#define FF_ALLOC_EVENT   (SDL_USEREVENT)
221 219
#define FF_REFRESH_EVENT (SDL_USEREVENT + 1)
222 220
#define FF_QUIT_EVENT    (SDL_USEREVENT + 2)
......
260 258
    AVPacketList *pkt1;
261 259

  
262 260
    /* duplicate the packet */
263
    if (av_dup_packet(pkt) < 0)
261
    if (pkt!=&flush_pkt && av_dup_packet(pkt) < 0)
264 262
        return -1;
265 263

  
266 264
    pkt1 = av_malloc(sizeof(AVPacketList));
......
1283 1281
        }
1284 1282
        if (packet_queue_get(&is->videoq, pkt, 1) < 0)
1285 1283
            break;
1284

  
1285
        if(pkt->data == flush_pkt.data){
1286
            avcodec_flush_buffers(is->video_st->codec);
1287
            continue;
1288
        }
1289

  
1286 1290
        /* NOTE: ipts is the PTS of the _first_ picture beginning in
1287 1291
           this packet, if any */
1288 1292
        pts = 0;
1289 1293
        if (pkt->dts != AV_NOPTS_VALUE)
1290 1294
            pts = av_q2d(is->video_st->time_base)*pkt->dts;
1291 1295

  
1292
            SDL_LockMutex(is->video_decoder_mutex);
1293 1296
            len1 = avcodec_decode_video(is->video_st->codec,
1294 1297
                                        frame, &got_picture,
1295 1298
                                        pkt->data, pkt->size);
1296
            SDL_UnlockMutex(is->video_decoder_mutex);
1297 1299
//            if (len1 < 0)
1298 1300
//                break;
1299 1301
            if (got_picture) {
......
1327 1329
        if (packet_queue_get(&is->subtitleq, pkt, 1) < 0)
1328 1330
            break;
1329 1331

  
1332
        if(pkt->data == flush_pkt.data){
1333
            avcodec_flush_buffers(is->subtitle_st->codec);
1334
            continue;
1335
        }
1330 1336
        SDL_LockMutex(is->subpq_mutex);
1331 1337
        while (is->subpq_size >= SUBPICTURE_QUEUE_SIZE &&
1332 1338
               !is->subtitleq.abort_request) {
......
1345 1351
        if (pkt->pts != AV_NOPTS_VALUE)
1346 1352
            pts = av_q2d(is->subtitle_st->time_base)*pkt->pts;
1347 1353

  
1348
        SDL_LockMutex(is->subtitle_decoder_mutex);
1349 1354
        len1 = avcodec_decode_subtitle(is->subtitle_st->codec,
1350 1355
                                    &sp->sub, &got_subtitle,
1351 1356
                                    pkt->data, pkt->size);
1352
        SDL_UnlockMutex(is->subtitle_decoder_mutex);
1353 1357
//            if (len1 < 0)
1354 1358
//                break;
1355 1359
        if (got_subtitle && sp->sub.format == 0) {
......
1491 1495
    for(;;) {
1492 1496
        /* NOTE: the audio packet can contain several frames */
1493 1497
        while (is->audio_pkt_size > 0) {
1494
            SDL_LockMutex(is->audio_decoder_mutex);
1495 1498
            len1 = avcodec_decode_audio(is->audio_st->codec,
1496 1499
                                        (int16_t *)audio_buf, &data_size,
1497 1500
                                        is->audio_pkt_data, is->audio_pkt_size);
1498
            SDL_UnlockMutex(is->audio_decoder_mutex);
1499 1501
            if (len1 < 0) {
1500 1502
                /* if error, we skip the frame */
1501 1503
                is->audio_pkt_size = 0;
......
1535 1537
        /* read next packet */
1536 1538
        if (packet_queue_get(&is->audioq, pkt, 1) < 0)
1537 1539
            return -1;
1540
        if(pkt->data == flush_pkt.data){
1541
            avcodec_flush_buffers(is->audio_st->codec);
1542
            continue;
1543
        }
1544

  
1538 1545
        is->audio_pkt_data = pkt->data;
1539 1546
        is->audio_pkt_size = pkt->size;
1540 1547

  
......
1912 1919
        }
1913 1920
#endif
1914 1921
        if (is->seek_req) {
1915
            /* XXX: must lock decoder threads */
1916
            SDL_LockMutex(is->video_decoder_mutex);
1917
            SDL_LockMutex(is->audio_decoder_mutex);
1918
            SDL_LockMutex(is->subtitle_decoder_mutex);
1919 1922
            ret = av_seek_frame(is->ic, -1, is->seek_pos, is->seek_flags);
1920 1923
            if (ret < 0) {
1921 1924
                fprintf(stderr, "%s: error while seeking\n", is->ic->filename);
1922 1925
            }else{
1923 1926
                if (is->audio_stream >= 0) {
1924 1927
                    packet_queue_flush(&is->audioq);
1925
                    avcodec_flush_buffers(ic->streams[audio_index]->codec);
1928
                    packet_queue_put(&is->audioq, &flush_pkt);
1926 1929
                }
1927 1930
                if (is->subtitle_stream >= 0) {
1928 1931
                    packet_queue_flush(&is->subtitleq);
1932
                    packet_queue_put(&is->subtitleq, &flush_pkt);
1929 1933
                }
1930 1934
                if (is->video_stream >= 0) {
1931 1935
                    packet_queue_flush(&is->videoq);
1932
                    avcodec_flush_buffers(ic->streams[video_index]->codec);
1936
                    packet_queue_put(&is->videoq, &flush_pkt);
1933 1937
                }
1934 1938
            }
1935
            SDL_UnlockMutex(is->subtitle_decoder_mutex);
1936
            SDL_UnlockMutex(is->audio_decoder_mutex);
1937
            SDL_UnlockMutex(is->video_decoder_mutex);
1938 1939
            is->seek_req = 0;
1939 1940
        }
1940 1941

  
......
2021 2022
    is->subpq_mutex = SDL_CreateMutex();
2022 2023
    is->subpq_cond = SDL_CreateCond();
2023 2024

  
2024
    is->subtitle_decoder_mutex = SDL_CreateMutex();
2025
    is->audio_decoder_mutex = SDL_CreateMutex();
2026
    is->video_decoder_mutex = SDL_CreateMutex();
2027

  
2028 2025
    /* add the refresh timer to draw the picture */
2029 2026
    schedule_refresh(is, 40);
2030 2027

  
......
2057 2054
    SDL_DestroyCond(is->pictq_cond);
2058 2055
    SDL_DestroyMutex(is->subpq_mutex);
2059 2056
    SDL_DestroyCond(is->subpq_cond);
2060
    SDL_DestroyMutex(is->subtitle_decoder_mutex);
2061
    SDL_DestroyMutex(is->audio_decoder_mutex);
2062
    SDL_DestroyMutex(is->video_decoder_mutex);
2063 2057
}
2064 2058

  
2065 2059
static void stream_cycle_channel(VideoState *is, int codec_type)
......
2481 2475
    SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
2482 2476
    SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
2483 2477

  
2478
    av_init_packet(&flush_pkt);
2479
    flush_pkt.data= "FLUSH";
2480

  
2484 2481
    cur_stream = stream_open(input_filename, file_iformat);
2485 2482

  
2486 2483
    event_loop();

Also available in: Unified diff