程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> player stop處理

player stop處理

編輯:C++入門知識

幾乎所有的播放器都是基於ffmpeg,所以這就用ffmpeg 來說吧.
大家都只是stop其實做了幾個處理,一個是暫停播放,另外一個就是將播放位置seek到0點上.

除了這些,其實內部在seek的時候將播放隊列的buffer 全部都清空了.

為了不紙上談兵,這裡就貼一段ffplay的代碼
[cpp]
 if (is->seek_req) { 
            int64_t seek_target= is->seek_pos; 
            int64_t seek_min= is->seek_rel > 0 ? seek_target - is->seek_rel + 2: INT64_MIN; 
            int64_t seek_max= is->seek_rel < 0 ? seek_target - is->seek_rel - 2: INT64_MAX; 
//FIXME the +-2 is due to rounding being not done in the correct direction in generation 
//      of the seek_pos/seek_rel variables 
 
            ret = avformat_seek_file(is->ic, -1, seek_min, seek_target, seek_max, is->seek_flags); 
            if (ret < 0) { 
                fprintf(stderr, "%s: error while seeking\n", is->ic->filename); 
            }else{ 
                if (is->audio_stream >= 0) { 
                    packet_queue_flush(&is->audioq); 
                    packet_queue_put(&is->audioq, &flush_pkt); 
                } 
                if (is->subtitle_stream >= 0) { 
                    packet_queue_flush(&is->subtitleq); 
                    packet_queue_put(&is->subtitleq, &flush_pkt); 
                } 
                if (is->video_stream >= 0) { 
                    packet_queue_flush(&is->videoq); 
                    packet_queue_put(&is->videoq, &flush_pkt); 
                } 
            }  www.2cto.com
            is->seek_req = 0; 
            eof= 0; 
        } 

seek完之後調用flush把緩沖隊列的所有內容清空,包括音頻,視頻,字幕等數據.

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved