播放逻辑暂存
This commit is contained in:
@@ -10,6 +10,8 @@ extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavformat/avformat.h>
|
||||
#include <libavutil/avutil.h>
|
||||
#include <libavutil/imgutils.h>
|
||||
#include <libswscale/swscale.h>
|
||||
}
|
||||
|
||||
void AVFormatContextDeleter(AVFormatContext *context);
|
||||
@@ -17,32 +19,41 @@ 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;
|
||||
ThreadQueue<AVPacket *> packetQueue;
|
||||
ThreadQueue<AVFrame *> frameQueue;
|
||||
ThreadQueue<AVPacket *> audioQueue;
|
||||
std::string_view filename;
|
||||
std::jthread decodeThread;
|
||||
std::jthread decodePacketThread;
|
||||
std::jthread decodeFrameThread;
|
||||
int videoStreamIndex;
|
||||
int audioStreamIndex;
|
||||
int waitDelay = 50;
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
std::stop_source stopSource;
|
||||
std::shared_ptr<sf::RenderWindow> window;
|
||||
std::unique_ptr<sf::Sprite> sprite;
|
||||
std::unique_ptr<sf::Texture> texture;
|
||||
|
||||
|
||||
public:
|
||||
VideoService(std::string_view filename);
|
||||
VideoService(std::string_view filename, std::shared_ptr<sf::RenderWindow> window);
|
||||
~VideoService() {
|
||||
if (decodeThread.joinable()) {
|
||||
decodeThread.join();
|
||||
if (decodePacketThread.joinable()) {
|
||||
decodePacketThread.join();
|
||||
}
|
||||
if (decodeFrameThread.joinable()) {
|
||||
decodeFrameThread.join();
|
||||
}
|
||||
}
|
||||
void InitContext();
|
||||
void Decode();
|
||||
void PaintFrame();
|
||||
void Play();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user