Skip to content

Commit

Permalink
Support DLNA Renderer (#168)
Browse files Browse the repository at this point in the history
* Support DLNA Renderer

* Adjusting the player interface during live streaming and DLNA casting

---------

Co-authored-by: zeromake <a390720046@gmail.com>
  • Loading branch information
xfangfang and zeromake authored Jul 21, 2023
1 parent cf1a250 commit e68e216
Show file tree
Hide file tree
Showing 34 changed files with 547 additions and 102 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ jobs:
mkdir -p build/xrepo
cd build/xrepo
git clone https://github.com/xfangfang/borealis.git -b wiliwili --depth=1
git clone https://github.com/xfangfang/libpdr.git -b master --depth=1
cd ../../
- name: build
shell: powershell
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
[submodule "library/mongoose"]
path = library/mongoose
url = https://github.com/xfangfang/mongoose.git
[submodule "library/libpdr"]
path = library/libpdr
url = https://github.com/xfangfang/libpdr.git
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,5 @@ endif ()

target_include_directories(${PROJECT_NAME} PRIVATE wiliwili/include wiliwili/include/api ${APP_PLATFORM_INCLUDE})
target_compile_options(${PROJECT_NAME} PRIVATE -ffunction-sections -fdata-sections -Wunused-variable ${APP_PLATFORM_OPTION})
target_link_libraries(${PROJECT_NAME} PRIVATE cpr::cpr qrcode borealis lunasvg pystring mongoose z ${APP_PLATFORM_LIB})
target_link_libraries(${PROJECT_NAME} PRIVATE cpr::cpr qrcode borealis lunasvg pystring pdr mongoose z ${APP_PLATFORM_LIB})
target_link_options(${PROJECT_NAME} PRIVATE ${APP_PLATFORM_LINK_OPTION})
10 changes: 10 additions & 0 deletions library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,13 @@ if (NOT ${USE_LIBROMFS})
set(BRLS_USE_OPENCC ON)
endif ()
add_subdirectory(borealis/library)

# add libpdr (不使用项目内的 cmake 配置,因为 wiliwili 使用支持 switch 的 mongoose)
file(GLOB_RECURSE PDR_SRC ${CMAKE_CURRENT_SOURCE_DIR}/libpdr/src/*.cpp)
add_library(pdr ${PDR_SRC})
set_property(TARGET pdr PROPERTY CXX_STANDARD 17)
target_include_directories(pdr PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/libpdr/include)
target_link_libraries(pdr mongoose tinyxml2)
if(PLATFORM_SWITCH)
target_compile_options(pdr PUBLIC -D__SWITCH__)
endif ()
1 change: 1 addition & 0 deletions library/libpdr
Submodule libpdr added at 01bc08
2 changes: 1 addition & 1 deletion library/mongoose
Submodule mongoose updated 1 files
+9 −6 mongoose.h
2 changes: 2 additions & 0 deletions resources/i18n/en-US/wiliwili.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
},
"others": {
"header": "Others",
"dlna": "DLNA Renderer",
"dlna_waiting": "Waiting for DLNA casting...",
"up2date": "App is up to date",
"release": "Check for updates",
"config": "Open config directory"
Expand Down
2 changes: 2 additions & 0 deletions resources/i18n/zh-Hans/wiliwili.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
},
"others": {
"header": "其他",
"dlna": "DLNA 投屏",
"dlna_waiting": "等待 DLNA 投屏中...",
"up2date": "应用已经是最新版",
"release": "检查更新",
"config": "打开配置目录"
Expand Down
2 changes: 2 additions & 0 deletions resources/i18n/zh-Hant/wiliwili.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
},
"others": {
"header": "其他",
"dlna": "DLNA 投映",
"dlna_waiting": "等待 DLNA 投映中...",
"up2date": "應用程式為最新版本。",
"release": "檢查更新",
"config": "開啟設定檔目錄"
Expand Down
6 changes: 0 additions & 6 deletions resources/xml/activity/live_player_activity.xml

This file was deleted.

4 changes: 4 additions & 0 deletions resources/xml/activity/setting_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@
title="@i18n/wiliwili/setting/tools/others/header"
marginBottom="0px"/>

<brls:RadioCell
id="tools/dlna"
title="@i18n/wiliwili/setting/tools/others/dlna"/>

<brls:RadioCell
id="tools/config_dir"
title="@i18n/wiliwili/setting/tools/others/config"/>
Expand Down
9 changes: 9 additions & 0 deletions resources/xml/activity/video_activity.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<brls:Box
width="1280"
height="720">
<VideoView
id="fullscreen/video"
hideHighlight="true"
width="1280"
height="720"/>
</brls:Box>
35 changes: 35 additions & 0 deletions wiliwili/include/activity/dlna_activity.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Created by fang on 2023/7/18.
//

#pragma once

#include <borealis/core/activity.hpp>
#include <libpdr.h>

#include "view/mpv_core.hpp"


class VideoView;
class DLNAActivity : public brls::Activity {
public:
CONTENT_FROM_XML_RES("activity/video_activity.xml");

DLNAActivity();

void onContentAvailable() override;

~DLNAActivity() override;

private:
BRLS_BIND(VideoView, video, "fullscreen/video");

// 监控mpv事件
MPVEvent::Subscription mpvEventSubscribeID;
// 监控DLNA事件
pdr::Subscription dlnaEventSubscribeID;
std::shared_ptr<pdr::DLNA> dlna;

std::string ip, uuid;
size_t port;
};
9 changes: 2 additions & 7 deletions wiliwili/include/activity/live_player_activity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class VideoView;
class LiveActivity : public brls::Activity, public LiveDataRequest {
public:
// Declare that the content of this activity is the given XML file
CONTENT_FROM_XML_RES("activity/live_player_activity.xml");
CONTENT_FROM_XML_RES("activity/video_activity.xml");

explicit LiveActivity(const bilibili::LiveVideoResult& live);
LiveActivity(int roomid, const std::string& name = "",
Expand All @@ -34,15 +34,10 @@ class LiveActivity : public brls::Activity, public LiveDataRequest {
~LiveActivity() override;

private:
BRLS_BIND(VideoView, video, "live/video");
BRLS_BIND(VideoView, video, "fullscreen/video");

bilibili::LiveVideoResult liveData;

// 监控mpv事件
MPVCustomEvent::Subscription eventSubscribeID;

// 用于缓存全局状态,进入直播时关闭弹幕与底部进度条,退出时恢复
bool globalShowDanmaku = false;
bool globalBottomBar = false;
bool globalExitFullscreen = false;
};
1 change: 1 addition & 0 deletions wiliwili/include/activity/setting_activity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class SettingActivity : public brls::Activity {
BRLS_BIND(brls::RadioCell, btnQuit, "tools/quit");
BRLS_BIND(brls::RadioCell, btnOpenConfig, "tools/config_dir");
BRLS_BIND(brls::RadioCell, btnVibrationTest, "tools/vibration_test");
BRLS_BIND(brls::RadioCell, btnDLNA, "tools/dlna");
BRLS_BIND(SelectorCell, selectorLang, "setting/language");
BRLS_BIND(SelectorCell, selectorTheme, "setting/ui/theme");
BRLS_BIND(SelectorCell, selectorTexture, "setting/image/texture");
Expand Down
27 changes: 27 additions & 0 deletions wiliwili/include/api/bilibili/util/uuid.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Created by fang on 2023/7/18.
//

#pragma once

#include <string>
#include <sstream>
#include <iomanip>
#include "bilibili/util/md5.hpp"

namespace bilibili {

std::string genUUID(const std::string& str){
auto hash = websocketpp::md5::md5_hash_hex(str);

std::ostringstream uuid;
uuid << std::setw(8) << std::setfill('0') << hash.substr(0, 8) << "-";
uuid << std::setw(4) << std::setfill('0') << hash.substr(8, 4) << "-";
uuid << std::setw(4) << std::setfill('0') << hash.substr(12, 4) << "-";
uuid << std::setw(4) << std::setfill('0') << hash.substr(16, 4) << "-";
uuid << std::setw(12) << std::setfill('0') << hash.substr(20, 12);

return uuid.str();
}

}
8 changes: 8 additions & 0 deletions wiliwili/include/fragment/player_setting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ class PlayerSetting : public brls::Box {

void setupSubtitle();

void hideHistoryCell();

void hideVideoRelatedCells();

void hideSubtitleCells();

void hideBottomLineCells();

private:
BRLS_BIND(ButtonClose, closebtn, "button/close");
BRLS_BIND(brls::ScrollingFrame, settings, "player/settings");
Expand Down
3 changes: 3 additions & 0 deletions wiliwili/include/utils/activity_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ class Intent {

// 浏览图片
static void openGallery(const std::vector<std::string>& data);

// 开启 DLNA
static void openDLNA();
};
3 changes: 3 additions & 0 deletions wiliwili/include/utils/config_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ enum class SettingItem {
LIMITED_FPS,
DEACTIVATED_TIME,
DEACTIVATED_FPS,
DLNA_IP,
DLNA_PORT,
DLNA_NAME,
};

class APPVersion : public brls::Singleton<APPVersion> {
Expand Down
4 changes: 4 additions & 0 deletions wiliwili/include/utils/number_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ std::string getRandomHex(int length, bool lowerCase = true);
//4180 => 01:09:40
std::string sec2Time(size_t t);

// 100 => 0:01:40
// 4180 => 1:09:40
std::string sec2TimeDLNA(size_t t);

//4180 => 69:40
std::string sec2MinSec(size_t t);

Expand Down
6 changes: 0 additions & 6 deletions wiliwili/include/view/mpv_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@ class MPVCore : public brls::Singleton<MPVCore> {
double percent_pos = 0;
int64_t video_progress = 0;

// Bottom progress bar
inline static bool BOTTOM_BAR = true;

// 低画质解码,剔除解码过程中的部分步骤,可以用来节省cpu
inline static bool LOW_QUALITY = false;

Expand All @@ -183,9 +180,6 @@ class MPVCore : public brls::Singleton<MPVCore> {
// 默认的音量
inline static int VIDEO_VOLUME = 100;

NVGcolor bottomBarColor =
brls::Application::getTheme().getColor("color/bilibili");

private:
mpv_handle *mpv = nullptr;
mpv_render_context *mpv_context = nullptr;
Expand Down
41 changes: 36 additions & 5 deletions wiliwili/include/view/video_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class VideoView : public brls::Box {

void hideOSD();

bool isOSDShown();
bool isOSDShown() const;

void onOSDStateChanged(bool state);

Expand All @@ -78,10 +78,25 @@ class VideoView : public brls::Box {

void hideLoading();

/**
* 隐藏一部分视频播放相关的按钮,在直播页面调用此函数用来隐藏不需要的 UI
*/
void hideActionButtons();
void hideDanmakuButton();

void hideDLNAButton();

void hideVideoQualityButton();

void hideVideoSpeedButton();

void disableCloseOnEndOfFile();

void disableBottomBar();

void hideHistorySetting();

void hideVideoRelatedSetting();

void hideSubtitleSetting();

void hideBottomLineSetting();

void setTitle(const std::string& title);

Expand Down Expand Up @@ -158,12 +173,28 @@ class VideoView : public brls::Box {
// 当自动跳转下一集时不退出全屏
inline static bool EXIT_FULLSCREEN_ON_END = true;

// Bottom progress bar
inline static bool BOTTOM_BAR = true;

private:
bool allowFullscreen = true;
bool registerMPVEvent = false;
bool showDanmaku = true;
// 和前面的 EXIT_FULLSCREEN_ON_END 共同控制,closeOnEndOfFile用来控制单个VideoView行为
bool closeOnEndOfFile = true;
// 播放设置中显示 上传历史记录
bool showHistorySetting = true;
// 播放设置中显示 播放结束行为相关的设置
bool showVideoRelatedSetting = true;
// 播放设置中显示 字幕选择
bool showSubtitleSetting = true;
// 播放设置中显示 底部进度条
bool showBottomLineSetting = true;
MPVEvent::Subscription eventSubscribeID;
MPVCustomEvent::Subscription customEventSubscribeID;
brls::InputManager* input;
NVGcolor bottomBarColor =
brls::Application::getTheme().getColor("color/bilibili");

///OSD
BRLS_BIND(brls::Label, videoTitleLabel, "video/osd/title");
Expand Down
Loading

0 comments on commit e68e216

Please sign in to comment.