合并
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
#include <imageService.h>
|
||||
#include <UtilTool.h>
|
||||
#include <string>
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <memory>
|
||||
#include "videoService.h"
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <UtilTool.h>
|
||||
#include <imageService.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class MediaService
|
||||
{
|
||||
private:
|
||||
class MediaService {
|
||||
private:
|
||||
ImageService *imageService = nullptr;
|
||||
VideoService *videoService = nullptr;
|
||||
MediaType type;
|
||||
@@ -15,18 +14,15 @@ private:
|
||||
std::shared_ptr<sf::Sprite> sprite;
|
||||
std::shared_ptr<sf::RenderWindow> window;
|
||||
int client_width = 0;
|
||||
int client_height = 0;
|
||||
public:
|
||||
MediaService(const std::string &filename, int width, int height);
|
||||
~MediaService(){
|
||||
int client_height = 0;
|
||||
|
||||
public:
|
||||
MediaService(std::shared_ptr<sf::RenderWindow> window,
|
||||
const std::string &filename, int width, int height);
|
||||
~MediaService() {
|
||||
delete imageService;
|
||||
delete videoService;
|
||||
}
|
||||
std::shared_ptr<sf::Sprite> GetSprite()
|
||||
{
|
||||
return sprite;
|
||||
}
|
||||
void SetWindow(std::shared_ptr<sf::RenderWindow> window);
|
||||
std::shared_ptr<sf::Sprite> GetSprite() { return sprite; }
|
||||
void Play();
|
||||
|
||||
};
|
||||
|
||||
@@ -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