Skip to content

Commit 347aa77

Browse files
committed
将Video统一为C++封装,修复虚拟文件系统重复打开同一文件指针的错误
1 parent d6d4829 commit 347aa77

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2657
-770
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ add_subdirectory ("Runtime/VGLua")
3636
add_subdirectory ("Runtime/HCore")
3737
add_subdirectory ("Runtime/VGPackage")
3838
add_subdirectory ("Runtime/VGImgui")
39+
add_subdirectory ("Runtime/HMedia")
3940
add_subdirectory ("Runtime/VGEngine")
4041
# 编辑器
4142
add_subdirectory ("Editor/VGEditorFramework")

Editor/VGEditorFramework/Source/EditorComponents/DetailBrowser/ComponentDrawer.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <VGEngine/Include/Interface/Loader.h>
2222
#include <VGEngine/Include/Lua/LuaScript.h>
2323
#include <VGEngine/Include/Resource/Audio.h>
24+
#include <VGEngine/Include/Resource/FVideo.h>
2425

2526
namespace VisionGal::Editor
2627
{
@@ -587,12 +588,18 @@ namespace VisionGal::Editor
587588
if (com->videoPlayer == nullptr)
588589
return;
589590

590-
if (com->videoPlayer->GetSprite() == nullptr)
591-
return;
591+
//if (com->videoPlayer->GetSprite() == nullptr)
592+
// return;
593+
//
594+
//if (com->videoPlayer->GetSprite()->GetITexture() != nullptr)
595+
//{
596+
// auto* tex = com->videoPlayer->GetSprite()->GetITexture();
597+
// ImGuiEx::ImageGL(tex->GetShaderResourceView(), 100, 100);
598+
//}
592599

593-
if (com->videoPlayer->GetSprite()->GetITexture() != nullptr)
600+
if (com->videoPlayer->GetVideoTexture() != nullptr)
594601
{
595-
auto* tex = com->videoPlayer->GetSprite()->GetITexture();
602+
auto* tex = com->videoPlayer->GetVideoTexture();
596603
ImGuiEx::ImageGL(tex->GetShaderResourceView(), 100, 100);
597604
}
598605
}
@@ -611,7 +618,7 @@ namespace VisionGal::Editor
611618
{
612619
std::string path = static_cast<char*>(payload->Data);
613620

614-
if (auto video = LoadObject<VideoClip>(path))
621+
if (auto video = LoadObject<FVideoClip>(path))
615622
{
616623
com->videoClip = video;
617624
ImGuiEx::PushNotification({ ImGuiExToastType::Info, "设置视频成功!" });

Editor/VGEditorFramework/Source/EditorCore/AssetWatcher.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "VGEngine/Include/Galgame/GalGameEngine.h"
1616
#include "VGEngine/Include/Galgame/GameEngineCore.h"
1717
#include "VGEngine/Include/UI/UISystem.h"
18+
#include "VGEngine/Include/Core/VFS.h"
1819

1920
namespace VisionGal::Editor
2021
{

Runtime/HCore/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
1717
add_compile_options(-finput-charset=UTF-8 -fexec-charset=UTF-8)
1818
endif()
1919

20+
21+
# 设置 C++ 标准为 C++17
22+
set(CMAKE_CXX_STANDARD 17)
23+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
24+
25+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
26+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
27+
28+
# 开启utf-8编码支持
29+
if (MSVC)
30+
add_compile_options(/utf-8)
31+
endif()
32+
33+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
34+
add_compile_options(-finput-charset=UTF-8 -fexec-charset=UTF-8)
35+
endif()
36+
37+
2038
file(GLOB HCORE_GEN_FILES
2139
"${CMAKE_CURRENT_SOURCE_DIR}/.Generated/*.h"
2240
"${CMAKE_CURRENT_SOURCE_DIR}/.Generated/*.cpp"

Runtime/HCore/Include/VFS/MemoryFileSystem.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ class MemoryFileSystem final : public IFileSystem
273273
}
274274

275275
if (file) {
276+
// 修复重复打开一个文件指针的错误
277+
file.reset(new MemoryFile(filePath));
278+
276279
file->Open(mode);
277280

278281
if (!isExists && file->IsOpened()) {

Runtime/HCore/Include/VFS/NativeFileSystem.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@ class NativeFileSystem final : public IFileSystem
315315
}
316316

317317
if (file) {
318+
// 修复重复打开一个文件指针的错误
319+
file.reset(new NativeFile(filePath));
320+
318321
file->Open(mode);
319322

320323
if (!isExists && file->IsOpened()) {

Runtime/HCore/Include/VFS/ZipFile.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ namespace vfspp
2424
{
2525
}
2626

27+
ZipFile(const ZipFile& other)
28+
: m_FileInfo(other.m_FileInfo)
29+
, m_EntryID(other.m_EntryID)
30+
, m_Size(other.m_Size)
31+
, m_ZipArchive(other.m_ZipArchive)
32+
, m_IsOpened(other.m_IsOpened)
33+
, m_SeekPos(other.m_SeekPos)
34+
{
35+
36+
}
37+
ZipFile& operator=(const ZipFile&) = delete;
38+
2739
~ZipFile()
2840
{
2941
Close();

Runtime/HCore/Include/VFS/ZipFileSystem.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ class ZipFileSystem final : public IFileSystem
260260

261261
IFilePtr file = FindFile(filePath, m_FileList);
262262
if (file) {
263+
// 修复重复打开一个文件指针的错误
264+
file.reset(new ZipFile(*dynamic_cast<ZipFile*>( file.get() )));
265+
263266
file->Open(mode);
264267
}
265268

Runtime/HMedia/CMakeLists.txt

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# 设置 C++ 标准为 C++17
2+
#cmake_minimum_required(VERSION 3.10)
3+
#project(HMedia LANGUAGES CXX) # 明确指定为C++项目
4+
5+
set(CMAKE_CXX_STANDARD 17)
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
8+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
9+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
10+
11+
# 开启utf-8编码支持
12+
if (MSVC)
13+
add_compile_options(/utf-8)
14+
endif()
15+
16+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
17+
add_compile_options(-finput-charset=UTF-8 -fexec-charset=UTF-8)
18+
endif()
19+
20+
#开启MSVC多线程编译 # windows 并行编译选项
21+
add_compile_options($<$<CXX_COMPILER_ID:MSVC>:/Gm->) #高版本已被废弃,但是低版本的Gm会影响并行
22+
cmake_host_system_information(RESULT CPU_NUMBER_OF_LOGICAL_CORES QUERY NUMBER_OF_LOGICAL_CORES)
23+
add_compile_options($<$<CXX_COMPILER_ID:MSVC>:/MP${CPU_NUMBER_OF_LOGICAL_CORES}>)
24+
25+
# 添加宏
26+
add_definitions(-DH_MEDIA_API_EXPORT)
27+
28+
# 将源代码添加到此项目的可执行文件。
29+
file(GLOB H_MEDIA_SRC_FILES
30+
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
31+
"${CMAKE_CURRENT_SOURCE_DIR}/Source/*.cpp"
32+
"${CMAKE_CURRENT_SOURCE_DIR}/Source/Audio/*.cpp"
33+
"${CMAKE_CURRENT_SOURCE_DIR}/Source/Common/*.cpp"
34+
"${CMAKE_CURRENT_SOURCE_DIR}/Source/SDL/*.cpp"
35+
"${CMAKE_CURRENT_SOURCE_DIR}/Source/FFmpeg/*.cpp"
36+
)
37+
38+
file(GLOB H_MEDIA_HEADER_FILES
39+
"${CMAKE_CURRENT_SOURCE_DIR}/Include/*.h"
40+
"${CMAKE_CURRENT_SOURCE_DIR}/Include/Audio/*.h"
41+
"${CMAKE_CURRENT_SOURCE_DIR}/Include/Common/*.h"
42+
"${CMAKE_CURRENT_SOURCE_DIR}/Include/SDL/*.h"
43+
"${CMAKE_CURRENT_SOURCE_DIR}/Include/FFmpeg/*.h"
44+
45+
"${CMAKE_CURRENT_SOURCE_DIR}/Interface/*.h"
46+
)
47+
48+
# 启用预编译头支持
49+
#set(CMAKE_PCH_ENABLED ON)
50+
51+
# 当前cmake C++项目为动态库
52+
add_library (HMedia SHARED ${H_MEDIA_SRC_FILES} ${H_MEDIA_HEADER_FILES})
53+
54+
# 添加头文件搜索路径
55+
target_include_directories(HMedia PRIVATE ${PROJECT_SOURCE_DIR}/Runtime)
56+
target_include_directories(HMedia PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Include)
57+
58+
# 配置预编译头
59+
#target_precompile_headers(VGEngine PRIVATE
60+
# "Include/pch.h" # 项目级头文件
61+
#)
62+
63+
#
64+
#find_package(glad CONFIG REQUIRED)
65+
find_package(SDL3 CONFIG REQUIRED)
66+
find_package(RmlUi REQUIRED)
67+
find_package(SDL3_image CONFIG REQUIRED)
68+
69+
# FFmpeg
70+
find_package(FFMPEG REQUIRED)
71+
target_include_directories(HMedia PRIVATE ${FFMPEG_INCLUDE_DIRS})
72+
target_link_directories(HMedia PRIVATE ${FFMPEG_LIBRARY_DIRS})
73+
target_link_libraries(HMedia PRIVATE ${FFMPEG_LIBRARIES})
74+
75+
# 链接动态库
76+
target_link_libraries(HMedia PRIVATE SDL3::SDL3)
77+
target_link_libraries(HMedia PRIVATE HCore)
78+
79+
# TODO: 如有需要,请添加测试并安装目标。
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* This source file is part of VisionGal, the Visual Novel Engine
3+
*
4+
* For the latest information, see https://darlingzerox.github.io/VisionGalDoc/
5+
* GitHub page: https://github.com/DarlingZeroX/VisionGal
6+
*
7+
* Copyright (c) 2025-present 梦旅缘心
8+
*
9+
* See the LICENSE file in the project root for details.
10+
*/
11+
12+
#pragma once
13+
#include <vector>
14+
#include <mutex>
15+
#include "../Interface/AudioDecoderInterface.h"
16+
#include "../HMediaConfig.h"
17+
18+
namespace Horizon {
19+
20+
// 简单线程安全环形缓冲
21+
class H_MEDIA_API AudioRingBuffer: public IAudioDataBuffer{
22+
public:
23+
AudioRingBuffer(size_t capacity);
24+
25+
size_t Write(const uint8_t* data, size_t len) override;
26+
size_t Read(uint8_t* out, size_t len) override;
27+
size_t Available() const override;
28+
bool IsAlmostFull() const override;
29+
void Stop() override;
30+
bool IsFinish() const override;
31+
void WriteFinish() override;
32+
bool IsWriteFinish() const override;
33+
void Reset() override;
34+
private:
35+
std::vector<uint8_t> buffer;
36+
size_t head = 0;
37+
size_t tail = 0;
38+
size_t size = 0;
39+
size_t capacity = 0;
40+
mutable std::mutex mutex;
41+
bool m_IsFinish = false;
42+
bool m_IsWriteFinish = false;
43+
};
44+
}

0 commit comments

Comments
 (0)