修复msvc下无法正确获取拓展名的问题, 修复视频文件结束后任然解码的问题, 添加CMake Window下编译

This commit is contained in:
2024-02-20 18:37:05 +08:00
parent 3697de0b4a
commit 5cc0de59d5
6 changed files with 349 additions and 305 deletions

View File

@@ -1,25 +1,18 @@
#ifndef DECODER_H
#define DECODER_H
extern "C"{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/imgutils.h"
extern "C" {
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/imgutils.h"
}
struct DecoderParam{
AVFormatContext* fmtCtx;
AVCodecContext* codecCtx;
int width;
int height;
int videoStreamIndex;
struct DecoderParam {
AVFormatContext* fmtCtx;
AVCodecContext* codecCtx;
int width;
int height;
int videoStreamIndex;
};
extern "C"{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/imgutils.h"
}
void InitDecoder(const char* filepath, DecoderParam& param);
AVFrame* RequestFrame(DecoderParam& param);
#endif

View File

@@ -6,70 +6,69 @@
#include <string>
#include <array>
#include <cstring>
enum class FileType{
MUSIC,
VIDEO,
IMG,
ERRORTYPE
#include <string_view>
enum class FileType {
MUSIC,
VIDEO,
IMG,
ERRORTYPE
};
const std::array MusicFileExtensive = {
"mp3"
const std::array<std::string_view, 1> MusicFileExtensive = {
"mp3"
};
const std::array VideoFileExtensive = {
"mp4"
const std::array<std::string_view, 1> VideoFileExtensive = {
"mp4"
};
const std::array ImgFileExtensive = {
"jpeg",
"jpg",
"png",
const std::array<std::string_view, 3> ImgFileExtensive = {
"jpeg",
"jpg",
"png",
};
using namespace std::filesystem;
class Util{
class Util {
private:
static const char* GetFileExtensive(path filepath){
std::string ext = filepath.extension().string();
ext.erase(std::remove_if(ext.begin(), ext.end(), [](char c){return c=='.';}), ext.end());
return ext.c_str();
}
static bool IsMusic(path filepath){
const auto ext = GetFileExtensive(filepath);
for(const auto& it : MusicFileExtensive){
if(std::strcmp(it, ext) == 0)
return true;
}
return false;
}
static bool IsVideo(path filepath){
const auto ext = GetFileExtensive(filepath);
for(const auto& it : VideoFileExtensive){
if(std::strcmp(it, ext) == 0)
return true;
}
return false;
}
static bool IsImg(path filepath){
const auto ext = GetFileExtensive(filepath);
for(const auto& it : ImgFileExtensive){
if(std::strcmp(it, ext) == 0)
return true;
}
return false;
}
static std::string_view GetFileExtensive(const path& filepath) {
static std::string ext = filepath.extension().string();
ext.erase(std::ranges::remove_if(ext, [](char c) {return c == '.'; }).begin(), ext.end());
return std::string_view{ ext.c_str() };
}
static bool IsMusic(const path& filepath) {
const auto ext = GetFileExtensive(filepath);
for (const auto& it : MusicFileExtensive) {
if (it == ext)
return true;
}
return false;
}
static bool IsVideo(const path& filepath) {
const auto ext = GetFileExtensive(filepath);
for (const auto& it : VideoFileExtensive) {
if (it == ext)
return true;
}
return false;
}
static bool IsImg(const path& filepath) {
const auto ext = GetFileExtensive(filepath);
for (const auto& it : ImgFileExtensive) {
if (it == ext)
return true;
}
return false;
}
public:
static FileType GetFileType(path filepath){
if(IsMusic(filepath)) return FileType::MUSIC;
if(IsVideo(filepath)) return FileType::VIDEO;
if(IsImg(filepath)) return FileType::IMG;
return FileType::ERRORTYPE;
}
static FileType GetFileType(const path& filepath) {
if (IsMusic(filepath)) return FileType::MUSIC;
if (IsVideo(filepath)) return FileType::VIDEO;
if (IsImg(filepath)) return FileType::IMG;
return FileType::ERRORTYPE;
}
};
#endif