ffplay source code analysis-1 framework analysis

The meaning of ffplay.c

ffplay.c is the player that comes with the FFmpeg source code. It calls FFmpeg and SDL API to implement a very useful player. For example, Bilibili's famous open source project ijkplayer is also based on ffplay.c for secondary development.

ffplay framework analysis (similar to the previous 800 lines of code to write a player logic)

Yellow wireframes indicate different threads of control
insert image description here

initialization

初始化packet queque 
初始化frame queque
初始化clock
创建数据读取线程

thread division

1 data reading thread

打开媒体⽂件
打开对应码流的decoder以及初始化对应的audio、video、subtitle输出
创建decoder线程,audio、video和subtitle的解码线程独⽴
调⽤av_read_frame读取packet,并根据steam_index放⼊不同stream对应的packet队列

2 Audio decoding (same as video with subtitles)

从packet queue读取packet,解出frame后放⼊frame queue

3 Audio playback (or callback function)

从frame queue读取frame进⾏播放

4 Video playback (ffplay is currently playing video on the main thread)

从frame queue读取frame进⾏播放

5 Subtitle playback (ffplay is currently playing subtitles on the main thread)

从frame queue读取frame进⾏播放

6 Response control (play/pause/fast forward/rewind, etc.) (ffplay currently controls playback on the main thread)

Design of packet queue

线程安全,⽀持互斥、等待、唤醒 
缓存数据⼤⼩ 
缓存包数 
队列播放可持续时间 
进队列/出队列等

Design of frame queue

线程安全,⽀持互斥、等待、唤醒 
缓存帧数 
⽀持读取数据⽽不出队列 
进出队列等

Audio and video synchronization

⾳频同步 
视频同步 
外部时钟同步

audio processing

⾳量调节 
静⾳
重采样

video processing

图像格式转换YUV->RGB等 
图像缩放1280*720->800*480等

player control

播放
暂停
停⽌
快进/快退 
逐帧
静⾳

Guess you like

Origin blog.csdn.net/qq_33329316/article/details/124165070