mp-sfml/include/videoService.h

49 lines
1.2 KiB
C++

#ifndef VIDEOSERVICE_H
#define VIDEOSERVICE_H
#include "thread_queue.h"
#include <SFML/Graphics.hpp>
#include <functional>
#include <memory>
#include <thread>
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>
}
void AVFormatContextDeleter(AVFormatContext *context);
void AVCodecContextDeleter(AVCodecContext *context);
class VideoService {
private:
std::shared_ptr<sf::Texture> texture;
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();
};
#endif