introduce
In this series, I plan to spend a lot of time explaining my gitee project audio and video player. In this project, you can learn audio and video decapsulation, decoding, and SDL rendering related knowledge. If you are interested in the source code, please check out the audio and video player based on FFmpeg and SDL
If you don’t understand this article, you can refer to my previous article Audio and Video Project— Audio and Video Player Analysis Based on FFmpeg and SDL (Seventeen)
parse
The fill_audio_pcm function analyzed before is a bit complicated, so I won’t continue talking about it now.
Let’s talk about the last class videooutput. It can be seen that this is the function responsible for video playback. Let’s look at the .h file first.
#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
Public members are constructors, destructors, initialization functions, loop functions, and wait functions.
There are many private members. Let’s analyze them in this article.
void videoRefresh(double* remaining_time); function responsible for refreshing
AVFrameQueue* frame_queue = nullptr; video frame data queue
SDL_Event event; SDL event
SDL_Rect rect; SDL rectangle
SDL_Window* win = nullptr; SDL window
SDL_Renderer* renderer = nullptr; SDL renderer
SDL_Texture* texture = nullptr; SDL texture
AVSync* avsync = nullptr; Class responsible for audio and video synchronization
AVRational time_base; used to calculate timestamps and frame rates
int video_width = 0; width of the video window
int video_height = 0; height of the video window
uint8_t* yuv_buf = nullptr; array to store yuv data
int yuv_buf_size = 0; length of array storing yuv data
Okay, this article explains the private member variables of the VieoOutput class, and the next article starts to explain the functions.
If you want to know what happened next, please listen to the breakdown next time.