SDL& ffmpeg实现的播放器架构

一、版本说明:ffmpeg3.4.2和SDL2-2.0.8

        a.整体图形说明:

SDL& ffmpeg实现的播放器架构

        b.播放器源码:~\ffmpeg-3.4.2\fftools\ffplay.c

二、主要的3个线程:

1.event_loop:视频播放循环取图像队列里的图像,包含SDL消息处理:快进快退、暂停、调整音量等UI交互。

->refresh_loop_wait_event  SDL消息处理
->video_refresh 显示每一帧图像到SDL界面
->video_display
->video_image_display (frame_queue_peek_last) ->AVFrame *frame; 所想要的图片



2.stream_open  创建的解码线程,负责音视频字幕解码压队列
-> read_thread
->stream_component_open//再创建3个线程
A.decoder_start(&is->viddec, video_thread, is) //图像
B.decoder_start(&is->auddec, audio_thread, is)) //声音
C.decoder_start(&is->subdec, subtitle_thread, is))//字幕
->for (;;) 
3.stream_component_open -> audio_open ->sdl_audio_callback





三、同步和seek:
Clock 时钟同步
SDL_mutex *wait_mutex = SDL_CreateMutex();
seek定位函数
static void stream_seek(VideoState *is, int64_t pos, int64_t rel, int seek_by_bytes)
SDL_CondSignal(is->continue_read_thread);










四、ffplay播放无声音出错:
ffplay播放没有声音"SDL_OpenAudio (2 channels, 44100 Hz): WASAPI can't initialize audio client"
set SDL_AUDIODRIVER=directsound
_putenv("SDL_AUDIODRIVER=directsound");





五、参考资料
https://blog.****.net/A694543965/article/details/78786230
https://blog.****.net/i_scream_/article/details/52760033
https://cloud.tencent.com/developer/article/1004559

最简单的视音频播放示例9:SDL2播放PCM
https://blog.****.net/leixiaohua1020/article/details/40544521