2024-09-30 13:34:05 +08:00
|
|
|
#ifndef VIDEOSERVICE_H
|
|
|
|
#define VIDEOSERVICE_H
|
2024-09-30 16:11:07 +08:00
|
|
|
#include "thread_queue.h"
|
2024-09-30 13:34:05 +08:00
|
|
|
#include <SFML/Graphics.hpp>
|
2024-09-30 16:11:07 +08:00
|
|
|
#include <functional>
|
2024-09-30 13:34:05 +08:00
|
|
|
#include <memory>
|
2024-09-30 16:11:07 +08:00
|
|
|
#include <thread>
|
2024-09-30 13:34:05 +08:00
|
|
|
|
2024-09-30 16:11:07 +08:00
|
|
|
extern "C" {
|
|
|
|
#include <libavcodec/avcodec.h>
|
|
|
|
#include <libavformat/avformat.h>
|
|
|
|
#include <libavutil/avutil.h>
|
|
|
|
}
|
|
|
|
|
|
|
|
void AVFormatContextDeleter(AVFormatContext *context);
|
|
|
|
|
|
|
|
void AVCodecContextDeleter(AVCodecContext *context);
|
2024-09-30 13:34:05 +08:00
|
|
|
class VideoService {
|
2024-09-30 16:11:07 +08:00
|
|
|
private:
|
2024-09-30 13:34:05 +08:00
|
|
|
std::shared_ptr<sf::Texture> texture;
|
2024-09-30 16:11:07 +08:00
|
|
|
std::unique_ptr<AVFormatContext, std::function<void(AVFormatContext *)>>
|
|
|
|
formatContext;
|
|
|
|
std::unique_ptr<AVCodecContext, std::function<void(AVCodecContext *)>>
|
|
|
|
codecContext;
|
|
|
|
ThreadQueue<AVPacket*> packetQueue;
|
|
|
|
ThreadQueue<AVFrame*> frameQueue;
|
|
|
|
ThreadQueue<AVPacket*> audioQueue;
|
|
|
|
std::string_view filename;
|
|
|
|
std::jthread decodeThread;
|
|
|
|
int videoStreamIndex;
|
|
|
|
int audioStreamIndex;
|
|
|
|
int waitDelay = 50;
|
|
|
|
unsigned int width;
|
|
|
|
unsigned int height;
|
|
|
|
std::stop_source stopSource;
|
|
|
|
|
|
|
|
public:
|
|
|
|
VideoService(std::string_view filename);
|
|
|
|
~VideoService() {
|
|
|
|
if (decodeThread.joinable()) {
|
|
|
|
decodeThread.join();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void InitContext();
|
|
|
|
void Decode();
|
2024-09-30 13:34:05 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|