抽象多媒体类, 修复gtest问题

This commit is contained in:
Jie
2024-09-09 13:20:59 +08:00
parent 628b95d37d
commit 7c049db4ac
10 changed files with 166 additions and 31 deletions

View File

@@ -1,9 +1,27 @@
#ifndef UTILTOOL_H
#define UTILTOOL_H
#include <iostream>
#include <array>
enum class MediaType{
VIDEO,
AUDIO,
IMAGE,
UNSUPPORT,
};
class UtilTool
{
public:
constexpr static std::array<std::string, 2> ImageType{"jpg","png"};
private:
constexpr static std::array<std::string, 2> ImageTypes{"jpg","png"};
constexpr static std::array<std::string, 1> VideoTypes{"mp4"};
constexpr static std::array<std::string, 1> AudioTypes{"mp3"};
static bool CheckFileIsImage(const std::string& filename);
static bool CheckFileIsAudio(const std::string& filename);
static bool CheckFileIsVideo(const std::string& filename);
public:
static MediaType CheckFileType(const std::string& filename);
};
#endif // !UTILTOOL_H

18
include/imageService.h Normal file
View File

@@ -0,0 +1,18 @@
#include <SFML/Graphics.hpp>
#include <algorithm>
class ImageService {
private:
sf::Texture texture;
public:
ImageService(const std::string& name){
texture.loadFromFile(name);
}
sf::Texture& GetTexture(){
return texture;
}
float GetScale(int width, int height){
auto imgSize = texture.getSize();
return std::min(static_cast<float>(width) / imgSize.x, static_cast<float>(height) / imgSize.y);
}
};

25
include/mediaService.h Normal file
View File

@@ -0,0 +1,25 @@
#include <imageService.h>
#include <UtilTool.h>
#include <string>
#include <SFML/Graphics.hpp>
class MediaService
{
private:
ImageService *imageService = nullptr;
MediaType type;
sf::Texture *texture = nullptr;
sf::Sprite *sprite = nullptr;
int client_width = 0;
int client_height = 0;
public:
MediaService(const std::string &filename, int width, int height);
~MediaService(){
delete texture;
delete sprite;
}
sf::Sprite GetSprite()
{
return *sprite;
}
};

12
include/stream.h Normal file
View File

@@ -0,0 +1,12 @@
#include <libavcodec/codec.h>
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>
}
class Stream {
private:
AVFormatContext* m_avFormatContext;
};