Audio and video project—Audio and video player analysis based on FFmpeg and SDL (6)

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 (5)

parse

Our article today will analyze decodethread, the thread responsible for decoding. Let’s first look at the code of the .h file:

#ifndef DECODETHREAD_H_
#define DECODETHREAD_H_

#include"thread.h"
#include"avpacketqueue.h"
#include"avframequeue.h"

class DecodeThread : public Thread
{
public:
    DecodeThread(AVPacketQueue* packet_queue, AVPacketQueue* frame_queue);
    ~DecodeThread();
    int Init(AVCodecParameters* par);
    int Start();
    int Stop();
    void Run();
private:
    AVCodecContext* codec_ctx = nullptr;
    AVPacketQueue* packet_queue = nullptr;
    AVFrameQueue* frame_queue = nullptr;
};

#endif

As you can see, the structure is actually similar to demuxthread, the thread responsible for decapsulation. The public functions have constructors, destructors, Init, Start, Stop, and Run. However, some changes have occurred in the private members. The previous AVFormatContext has become the current AVCodecContext, and the previous packet queue (AVPacketQueue) has become the current frame queue (AVFrameQueue).

Interested friends can take a look at the demuxthread source code below for comparison:

#ifndef DECODETHREAD_H_
#define DECODETHREAD_H_

#include"thread.h"
#include"avpacketqueue.h"
#include"avframequeue.h"

class DecodeThread : public Thread
{
public:
    DecodeThread(AVPacketQueue* packet_queue, AVPacketQueue* frame_queue);
    ~DecodeThread();
    int Init(AVCodecParameters* par);
    int Start();
    int Stop();
    void Run();
private:
    AVCodecContext* codec_ctx = nullptr;
    AVPacketQueue* packet_queue = nullptr;
    AVFrameQueue* frame_queue = nullptr;
};

#endif

Finally, we look at some constructors, and we’ll cover the rest in the next article.

DecodeThread::DecodeThread(AVPacketQueue* packet_queue, AVPacketQueue* frame_queue){
    this->packet_queue = packet_queue;
    this->frame_queue = frame_queue;
}

This is easier to understand, that is, initialize two private members, a packet queue (AVodecPacket) and a frame queue (AVFrameQueue).

Okay, today’s knowledge is relatively easy to understand, so I won’t summarize it.

If you want to know what happened next, please listen to the breakdown next time.

Guess you like

Origin blog.csdn.net/weixin_60701731/article/details/134420227