Skip to content

Commit 47686ca

Browse files
authored
feat: Audio Visualizer for Windows/Linux. (#739)
close #734 - [x] Windows - [x] Linux ![image](https://github.com/user-attachments/assets/e1655d24-9575-4f91-9a55-da1171a13ccc)
1 parent f822e70 commit 47686ca

Some content is hidden

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

48 files changed

+6530
-32
lines changed

example/linux/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ project(runner LANGUAGES CXX)
44

55
# The name of the executable created for the application. Change this to change
66
# the on-disk name of your application.
7-
set(BINARY_NAME "example")
7+
set(BINARY_NAME "livekit_client_example")
88
# The unique GTK application identifier for this application. See:
99
# https://wiki.gnome.org/HowDoI/ChooseApplicationID
1010
set(APPLICATION_ID "io.livekit.example.example")

example/linux/my_application.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ static void my_application_activate(GApplication* application) {
4040
if (use_header_bar) {
4141
GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new());
4242
gtk_widget_show(GTK_WIDGET(header_bar));
43-
gtk_header_bar_set_title(header_bar, "example");
43+
gtk_header_bar_set_title(header_bar, "livekit_client_example");
4444
gtk_header_bar_set_show_close_button(header_bar, TRUE);
4545
gtk_window_set_titlebar(window, GTK_WIDGET(header_bar));
4646
} else {
47-
gtk_window_set_title(window, "example");
47+
gtk_window_set_title(window, "livekit_client_example");
4848
}
4949

5050
gtk_window_set_default_size(window, 1280, 720);

example/windows/flutter/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ include(${EPHEMERAL_DIR}/generated_config.cmake)
99
# https://github.com/flutter/flutter/issues/57146.
1010
set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper")
1111

12+
# Set fallback configurations for older versions of the flutter tool.
13+
if (NOT DEFINED FLUTTER_TARGET_PLATFORM)
14+
set(FLUTTER_TARGET_PLATFORM "windows-x64")
15+
endif()
16+
1217
# === Flutter Library ===
1318
set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll")
1419

@@ -91,7 +96,7 @@ add_custom_command(
9196
COMMAND ${CMAKE_COMMAND} -E env
9297
${FLUTTER_TOOL_ENVIRONMENT}
9398
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
94-
windows-x64 $<CONFIG>
99+
${FLUTTER_TARGET_PLATFORM} $<CONFIG>
95100
VERBATIM
96101
)
97102
add_custom_target(flutter_assemble DEPENDS

example/windows/runner/Runner.rc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ IDI_APP_ICON ICON "resources\\app_icon.ico"
6060
// Version
6161
//
6262

63-
#ifdef FLUTTER_BUILD_NUMBER
64-
#define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER
63+
#if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD)
64+
#define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD
6565
#else
66-
#define VERSION_AS_NUMBER 1,0,0
66+
#define VERSION_AS_NUMBER 1,0,0,0
6767
#endif
6868

69-
#ifdef FLUTTER_BUILD_NAME
70-
#define VERSION_AS_STRING #FLUTTER_BUILD_NAME
69+
#if defined(FLUTTER_VERSION)
70+
#define VERSION_AS_STRING FLUTTER_VERSION
7171
#else
7272
#define VERSION_AS_STRING "1.0.0"
7373
#endif

linux/CMakeLists.txt

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# The Flutter tooling requires that developers have CMake 3.10 or later
2+
# installed. You should not increase this version, as doing so will cause
3+
# the plugin to fail to compile for some customers of the plugin.
4+
cmake_minimum_required(VERSION 3.10)
5+
6+
# Project-level configuration.
7+
set(PROJECT_NAME "livekit")
8+
project(${PROJECT_NAME} LANGUAGES CXX C)
9+
10+
# This value is used when generating builds using this plugin, so it must
11+
# not be changed.
12+
set(PLUGIN_NAME "livekit_client_plugin")
13+
14+
15+
add_definitions(-D_USE_MATH_DEFINES)
16+
add_definitions(-DRTC_DESKTOP_DEVICE)
17+
18+
include_directories(
19+
"${CMAKE_CURRENT_SOURCE_DIR}"
20+
"${CMAKE_CURRENT_SOURCE_DIR}/flutter/include"
21+
"${CMAKE_CURRENT_SOURCE_DIR}/../shared_cpp"
22+
)
23+
24+
# Any new source files that you add to the plugin should be added here.
25+
list(APPEND PLUGIN_SOURCES
26+
"livekit_plugin.cpp"
27+
"task_runner_linux.cc"
28+
"../shared_cpp/fft_processor.cpp"
29+
"../shared_cpp/audio_visualizer.cpp"
30+
"../shared_cpp/pffft.c"
31+
"flutter/core_implementations.cc"
32+
"flutter/standard_codec.cc"
33+
"flutter/plugin_registrar.cc"
34+
)
35+
36+
#target_compile_options(${PLUGIN_NAME} PRIVATE -Wno-deprecated-declarations)
37+
38+
# Define the plugin library target. Its name must not be changed (see comment
39+
# on PLUGIN_NAME above).
40+
add_library(${PLUGIN_NAME} SHARED
41+
${PLUGIN_SOURCES}
42+
)
43+
44+
# Apply a standard set of build settings that are configured in the
45+
# application-level CMakeLists.txt. This can be removed for plugins that want
46+
# full control over build settings.
47+
apply_standard_settings(${PLUGIN_NAME})
48+
49+
# Symbols are hidden by default to reduce the chance of accidental conflicts
50+
# between plugins. This should not be removed; any symbols that should be
51+
# exported should be explicitly exported with the FLUTTER_PLUGIN_EXPORT macro.
52+
set_target_properties(${PLUGIN_NAME} PROPERTIES
53+
CXX_VISIBILITY_PRESET hidden)
54+
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
55+
56+
# Source include directories and library dependencies. Add any plugin-specific
57+
# dependencies here.
58+
target_include_directories(${PLUGIN_NAME} INTERFACE
59+
"${CMAKE_CURRENT_SOURCE_DIR}/include")
60+
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_webrtc_plugin)
61+
target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK)
62+
63+
# List of absolute paths to libraries that should be bundled with the plugin.
64+
# This list could contain prebuilt libraries, or libraries created by an
65+
# external build triggered from this build file.
66+
set(livekit_bundled_libraries
67+
""
68+
PARENT_SCOPE
69+
)
70+
71+
# === Tests ===
72+
# These unit tests can be run from a terminal after building the example.
73+
74+
# Only enable test builds when building the example (which sets this variable)
75+
# so that plugin clients aren't building the tests.
76+
if (${include_${PROJECT_NAME}_tests})
77+
if(${CMAKE_VERSION} VERSION_LESS "3.11.0")
78+
message("Unit tests require CMake 3.11.0 or later")
79+
else()
80+
set(TEST_RUNNER "${PROJECT_NAME}_test")
81+
enable_testing()
82+
83+
# Add the Google Test dependency.
84+
include(FetchContent)
85+
FetchContent_Declare(
86+
googletest
87+
URL https://github.com/google/googletest/archive/release-1.11.0.zip
88+
)
89+
# Prevent overriding the parent project's compiler/linker settings
90+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
91+
# Disable install commands for gtest so it doesn't end up in the bundle.
92+
set(INSTALL_GTEST OFF CACHE BOOL "Disable installation of googletest" FORCE)
93+
94+
FetchContent_MakeAvailable(googletest)
95+
96+
# The plugin's exported API is not very useful for unit testing, so build the
97+
# sources directly into the test binary rather than using the shared library.
98+
add_executable(${TEST_RUNNER}
99+
test/livekit_plugin_test.cc
100+
${PLUGIN_SOURCES}
101+
)
102+
apply_standard_settings(${TEST_RUNNER})
103+
target_include_directories(${TEST_RUNNER} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
104+
target_link_libraries(${TEST_RUNNER} PRIVATE flutter)
105+
target_link_libraries(${TEST_RUNNER} PRIVATE PkgConfig::GTK)
106+
target_link_libraries(${TEST_RUNNER} PRIVATE gtest_main gmock)
107+
108+
# Enable automatic test discovery.
109+
include(GoogleTest)
110+
gtest_discover_tests(${TEST_RUNNER})
111+
112+
endif() # CMake version check
113+
endif() # include_${PROJECT_NAME}_tests

linux/flutter/binary_messenger_impl.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_BINARY_MESSENGER_IMPL_H_
6+
#define FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_BINARY_MESSENGER_IMPL_H_
7+
8+
#include <flutter_linux/flutter_linux.h>
9+
10+
#include <map>
11+
#include <string>
12+
13+
#include "include/flutter/binary_messenger.h"
14+
15+
namespace flutter {
16+
17+
// Wrapper around a FlutterDesktopMessengerRef that implements the
18+
// BinaryMessenger API.
19+
class BinaryMessengerImpl : public BinaryMessenger {
20+
public:
21+
explicit BinaryMessengerImpl(FlBinaryMessenger* core_messenger);
22+
23+
virtual ~BinaryMessengerImpl();
24+
25+
// Prevent copying.
26+
BinaryMessengerImpl(BinaryMessengerImpl const&) = delete;
27+
BinaryMessengerImpl& operator=(BinaryMessengerImpl const&) = delete;
28+
29+
// |flutter::BinaryMessenger|
30+
void Send(const std::string& channel,
31+
const uint8_t* message,
32+
size_t message_size,
33+
BinaryReply reply) const override;
34+
35+
// |flutter::BinaryMessenger|
36+
void SetMessageHandler(const std::string& channel,
37+
BinaryMessageHandler handler) override;
38+
39+
private:
40+
// Handle for interacting with the C API.
41+
FlBinaryMessenger* messenger_;
42+
43+
// A map from channel names to the BinaryMessageHandler that should be called
44+
// for incoming messages on that channel.
45+
std::map<std::string, BinaryMessageHandler> handlers_;
46+
};
47+
48+
} // namespace flutter
49+
50+
#endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_BINARY_MESSENGER_IMPL_H_

linux/flutter/byte_buffer_streams.h

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_BYTE_BUFFER_STREAMS_H_
6+
#define FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_BYTE_BUFFER_STREAMS_H_
7+
8+
#include <cassert>
9+
#include <cstdint>
10+
#include <cstring>
11+
#include <iostream>
12+
#include <vector>
13+
14+
#include "include/flutter/byte_streams.h"
15+
16+
namespace flutter {
17+
18+
// Implementation of ByteStreamReader base on a byte array.
19+
class ByteBufferStreamReader : public ByteStreamReader {
20+
public:
21+
// Createa a reader reading from |bytes|, which must have a length of |size|.
22+
// |bytes| must remain valid for the lifetime of this object.
23+
explicit ByteBufferStreamReader(const uint8_t* bytes, size_t size)
24+
: bytes_(bytes), size_(size) {}
25+
26+
virtual ~ByteBufferStreamReader() = default;
27+
28+
// |ByteStreamReader|
29+
uint8_t ReadByte() override {
30+
if (location_ >= size_) {
31+
std::cerr << "Invalid read in StandardCodecByteStreamReader" << std::endl;
32+
return 0;
33+
}
34+
return bytes_[location_++];
35+
}
36+
37+
// |ByteStreamReader|
38+
void ReadBytes(uint8_t* buffer, size_t length) override {
39+
if (location_ + length > size_) {
40+
std::cerr << "Invalid read in StandardCodecByteStreamReader" << std::endl;
41+
return;
42+
}
43+
std::memcpy(buffer, &bytes_[location_], length);
44+
location_ += length;
45+
}
46+
47+
// |ByteStreamReader|
48+
void ReadAlignment(uint8_t alignment) override {
49+
uint8_t mod = location_ % alignment;
50+
if (mod) {
51+
location_ += alignment - mod;
52+
}
53+
}
54+
55+
private:
56+
// The buffer to read from.
57+
const uint8_t* bytes_;
58+
// The total size of the buffer.
59+
size_t size_;
60+
// The current read location.
61+
size_t location_ = 0;
62+
};
63+
64+
// Implementation of ByteStreamWriter based on a byte array.
65+
class ByteBufferStreamWriter : public ByteStreamWriter {
66+
public:
67+
// Creates a writer that writes into |buffer|.
68+
// |buffer| must remain valid for the lifetime of this object.
69+
explicit ByteBufferStreamWriter(std::vector<uint8_t>* buffer)
70+
: bytes_(buffer) {
71+
assert(buffer);
72+
}
73+
74+
virtual ~ByteBufferStreamWriter() = default;
75+
76+
// |ByteStreamWriter|
77+
void WriteByte(uint8_t byte) { bytes_->push_back(byte); }
78+
79+
// |ByteStreamWriter|
80+
void WriteBytes(const uint8_t* bytes, size_t length) {
81+
assert(length > 0);
82+
bytes_->insert(bytes_->end(), bytes, bytes + length);
83+
}
84+
85+
// |ByteStreamWriter|
86+
void WriteAlignment(uint8_t alignment) {
87+
uint8_t mod = bytes_->size() % alignment;
88+
if (mod) {
89+
for (int i = 0; i < alignment - mod; ++i) {
90+
WriteByte(0);
91+
}
92+
}
93+
}
94+
95+
private:
96+
// The buffer to write to.
97+
std::vector<uint8_t>* bytes_;
98+
};
99+
100+
} // namespace flutter
101+
102+
#endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_BYTE_BUFFER_STREAMS_H_

0 commit comments

Comments
 (0)