音视频项目—基于FFmpeg和SDL的音视频播放器解析(十八)

介绍

在本系列,我打算花大篇幅讲解我的 gitee 项目音视频播放器,在这个项目,您可以学到音视频解封装,解码,SDL渲染相关的知识。您对源代码感兴趣的话,请查看基于FFmpeg和SDL的音视频播放器

如果您不理解本文,可参考我的前一篇文章音视频项目—基于FFmpeg和SDL的音视频播放器解析(十七)

解析

之前解析的 fill_audio_pcm 函数有点复杂,先不继续讲这个了。

我们讲最后一个类 videooutput,可见这是负责视频播放的函数,先看 .h 文件

#ifndef VIDEOOUTPUT_H_
#define VIDEOOUTPUT_H_

#ifdef __cplusplus
extern "C"{
#include"libavutil/avutil.h"
#include"SDL.h"
#include"libavutil/time.h"
}
#endif

#include"avframequeue.h"
#include"avsync.h"

class VideoOutput{
public:
    VideoOutput(AVSync* avsync, AVRational time_base, AVFrameQueue* frame_queue, int video_width, int video_height);
    ~VideoOutput();
    int Init();
    int MainLoop();
    void RefreshLoopWaitEvent(SDL_Event* event);
private:
    void videoRefresh(double* remaining_time);
    AVFrameQueue* frame_queue = nullptr;
    SDL_Event event;
    SDL_Rect rect;
    SDL_Window* win = nullptr;
    SDL_Renderer* renderer = nullptr;
    SDL_Texture* texture = nullptr;

    AVSync* avsync = nullptr;
    AVRational time_base;

    int video_width = 0;
    int video_height = 0;
    uint8_t* yuv_buf = nullptr;
    int yuv_buf_size = 0;
};

#endif

公有成员,都是构造函数,析构函数,初始化函数,循环函数,等待函数。

私有成员有比较多,我们这篇文章解析一下。

    void videoRefresh(double* remaining_time);        负责刷新的函数

    AVFrameQueue* frame_queue = nullptr;              视频帧数据队列

    SDL_Event event;                                                 SDL 事件

    SDL_Rect rect;                                                      SDL rectangle

    SDL_Window* win = nullptr;                                  SDL 窗口

    SDL_Renderer* renderer = nullptr;                        SDL 渲染器

    SDL_Texture* texture = nullptr;                              SDL 纹理

    AVSync* avsync = nullptr;                                       负责音视频同步的类

    AVRational time_base;                                           用于计算时间戳与帧率

    int video_width = 0;                                                视频窗口的宽度

    int video_height = 0;                                               视频窗口的高度

    uint8_t* yuv_buf = nullptr;                                       存放 yuv 数据的数组

    int yuv_buf_size = 0;                                               存放 yuv 数据的数组长度

好了,这篇文章讲解了 VieoOutput 类的私有成员变量,下一篇文章开始讲解函数。

欲知后事如何,请听下回分解。

猜你喜欢

转载自blog.csdn.net/weixin_60701731/article/details/134562254