Skip to content

Commit

Permalink
[Packages] GhafAudioControl: add app stream support
Browse files Browse the repository at this point in the history
Also refactored code, changed UI to show app streams
per AppVM view

Signed-off-by: Nikita Bazulin <[email protected]>
  • Loading branch information
baz2142 authored and humaidq-tii committed Sep 30, 2024
1 parent 83a954a commit b02f0c2
Show file tree
Hide file tree
Showing 33 changed files with 1,377 additions and 571 deletions.
4 changes: 2 additions & 2 deletions packages/ghaf-audio-control/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
#set(CMAKE_CXX_FLAGS_DEBUG -fsanitize=thread)

#add_definitions(-DLIBCXX_HARDENING_MODE=debug)
#add_compile_options(-fsanitize=address -fsanitize-recover=all)
#add_link_options(-fsanitize=address -fsanitize-recover=all)
# add_compile_options(-fsanitize=address -fsanitize-recover=all)
# add_link_options(-fsanitize=address -fsanitize-recover=all)

add_subdirectory(app)
add_subdirectory(lib)
3 changes: 2 additions & 1 deletion packages/ghaf-audio-control/src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
#include <GhafAudioControl/Backends/PulseAudio/AudioControlBackend.hpp>
#include <GhafAudioControl/utils/Logger.hpp>

#include <glibmm/optioncontext.h>
#include <gtkmm/applicationwindow.h>

#include <glibmm/optioncontext.h>

#include <format>

using namespace ghaf::AudioControl;
Expand Down
36 changes: 26 additions & 10 deletions packages/ghaf-audio-control/src/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,59 @@ add_library(${LIBRARY_NAME})

target_sources(${LIBRARY_NAME}
PRIVATE
src/AppList.cpp
src/AudioControl.cpp

src/Backends/PulseAudio/AudioControlBackend.cpp
src/Backends/PulseAudio/GeneralDevide.cpp
src/Backends/PulseAudio/Helpers.cpp
src/Backends/PulseAudio/Sink.cpp
src/Backends/PulseAudio/SinkInput.cpp
src/Backends/PulseAudio/Source.cpp
src/Backends/PulseAudio/SourceOutput.cpp
src/Backends/PulseAudio/Volume.cpp

src/models/AppVmModel.cpp
src/models/DeviceModel.cpp

src/utils/ConnectionContainer.cpp
src/utils/Logger.cpp

src/AppList.cpp
src/AppListRow.cpp
src/AudioControl.cpp
src/widgets/AppVmWidget.cpp
src/widgets/DeviceWidget.cpp
src/widgets/SinkWidget.cpp

PUBLIC
FILE_SET public_headers
TYPE HEADERS
BASE_DIRS include
FILES
include/GhafAudioControl/AppList.hpp
include/GhafAudioControl/AudioControl.hpp

include/GhafAudioControl/Backends/PulseAudio/AudioControlBackend.hpp
include/GhafAudioControl/Backends/PulseAudio/GeneralDevice.hpp
include/GhafAudioControl/Backends/PulseAudio/Helpers.hpp
include/GhafAudioControl/Backends/PulseAudio/Sink.hpp
include/GhafAudioControl/Backends/PulseAudio/SinkInput.hpp
include/GhafAudioControl/Backends/PulseAudio/Source.hpp
include/GhafAudioControl/Backends/PulseAudio/SourceOutput.hpp
include/GhafAudioControl/Backends/PulseAudio/Volume.hpp

include/GhafAudioControl/IAudioControlBackend.hpp
include/GhafAudioControl/Volume.hpp

include/GhafAudioControl/models/AppVmModel.hpp
include/GhafAudioControl/models/DeviceModel.hpp

include/GhafAudioControl/utils/ConnectionContainer.hpp
include/GhafAudioControl/utils/Logger.hpp
include/GhafAudioControl/utils/RaiiWrap.hpp
include/GhafAudioControl/utils/ScopeExit.hpp

include/GhafAudioControl/AppList.hpp
include/GhafAudioControl/AppListRow.hpp
include/GhafAudioControl/AudioControl.hpp
include/GhafAudioControl/IAudioControlBackend.hpp

include/GhafAudioControl/Volume.hpp

include/GhafAudioControl/widgets/AppVmWidget.hpp
include/GhafAudioControl/widgets/DeviceWidget.hpp
include/GhafAudioControl/widgets/SinkWidget.hpp
)

target_link_libraries(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#pragma once

#include <GhafAudioControl/AppListRow.hpp>
#include <GhafAudioControl/models/AppVmModel.hpp>

#include <gtkmm/box.h>
#include <gtkmm/listbox.h>
Expand All @@ -22,24 +22,15 @@ class AppList final : public Gtk::Box
public:
AppList();

void addApp(AppRaw::AppIdType id, IAudioControlBackend::ISink::Ptr sink, IAudioControlBackend::ISource::Ptr source);
void updateApp(AppRaw::AppIdType id, IAudioControlBackend::ISink::Ptr sink, IAudioControlBackend::ISource::Ptr source);
void removeApp(AppRaw::AppIdType id);
void removeAllApps();

private:
void doUpdateApp(size_t modelIndex, IAudioControlBackend::ISink::Ptr sink, IAudioControlBackend::ISource::Ptr source);
void addDevice(IAudioControlBackend::ISinkInput::Ptr device);

[[nodiscard]] Gtk::Widget* createWidgetsForApp(const Glib::RefPtr<Glib::Object>& appVmPtr);
void removeAllApps();

private:
Gtk::ListBox m_listBox;
Gtk::Separator m_separator;
Gtk::Stack m_stack;

Glib::RefPtr<Gio::ListStore<AppRaw>> m_appsModel;
std::map<AppRaw::AppIdType, std::vector<Glib::RefPtr<Glib::Binding>>> m_appsBindings;
sigc::connection m_connection;
Glib::RefPtr<Gio::ListStore<AppVmModel>> m_appsModel;
std::map<AppVmModel::AppIdType, std::vector<Glib::RefPtr<Glib::Binding>>> m_appsBindings;
};

} // namespace ghaf::AudioControl

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ namespace ghaf::AudioControl
class AudioControl final : public Gtk::Box
{
public:
static inline std::string ModuleName = "ghaf-audio-control";

AudioControl(std::unique_ptr<IAudioControlBackend> backend);
explicit AudioControl(std::unique_ptr<IAudioControlBackend> backend);
~AudioControl() override = default;

AudioControl(AudioControl&) = delete;
Expand All @@ -36,8 +34,15 @@ class AudioControl final : public Gtk::Box
void init();

void onPulseSinksChanged(IAudioControlBackend::EventType eventType, IAudioControlBackend::Sinks::IndexT extIndex, IAudioControlBackend::Sinks::PtrT sink);
void onPulseSourcesChanged(IAudioControlBackend::EventType eventType, IAudioControlBackend::Sinks::IndexT extIndex,

void onPulseSourcesChanged(IAudioControlBackend::EventType eventType, IAudioControlBackend::Sources::IndexT extIndex,
IAudioControlBackend::Sources::PtrT source);

void onPulseSinkInputsChanged(IAudioControlBackend::EventType eventType, IAudioControlBackend::SinkInputs::IndexT extIndex,
IAudioControlBackend::SinkInputs::PtrT sinkInput);

void onPulseSourcesOutputsChanged(IAudioControlBackend::EventType eventType, IAudioControlBackend::SourceOutputs::IndexT extIndex,
IAudioControlBackend::SourceOutputs::PtrT sourceOutput);
void onPulseError(std::string_view error);

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ class AudioControlBackend final : public IAudioControlBackend
return m_sources.onChange();
}

SinkInputs::OnChangeSignal onSinkInputsChanged() const override
{
return m_sinkInputs.onChange();
}

SourceOutputs::OnChangeSignal onSourceOutputsChanged() const override
{
return m_sourceOutputs.onChange();
}

OnErrorSignal onError() const override
{
return m_onError;
Expand All @@ -49,6 +59,8 @@ class AudioControlBackend final : public IAudioControlBackend
static void contextStateCallback(pa_context* context, void* data);
static void sinkInfoCallback(pa_context* context, const pa_sink_info* info, int eol, void* data);
static void sourceInfoCallback(pa_context* context, const pa_source_info* info, int eol, void* data);
static void sinkInputInfoCallback(pa_context* context, const pa_sink_input_info* info, int eol, void* data);
static void sourceOutputInfoCallback(pa_context* context, const pa_source_output_info* info, int eol, void* data);
static void serverInfoCallback(pa_context* context, const pa_server_info* info, void* data);
static void cardInfoCallback(pa_context* context, const pa_card_info* info, int eol, void* data);

Expand All @@ -58,9 +70,17 @@ class AudioControlBackend final : public IAudioControlBackend
void onSourceInfo(const pa_source_info& info);
void deleteSource(Sources::IndexT index);

void onSinkInputInfo(const pa_sink_input_info& info);
void deleteSinkInput(SinkInputs::IndexT index);

void onSourceOutputInfo(const pa_source_output_info& info);
void deleteSourceOutput(SourceOutputs::IndexT index);

private:
Sinks m_sinks;
Sources m_sources;
SinkInputs m_sinkInputs;
SourceOutputs m_sourceOutputs;

OnErrorSignal m_onError;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class GeneralDeviceImpl final
public:
GeneralDeviceImpl(const pa_sink_info& info, pa_context& context);
GeneralDeviceImpl(const pa_source_info& info, pa_context& context);
GeneralDeviceImpl(const pa_sink_input_info& info, pa_context& context);
GeneralDeviceImpl(const pa_source_output_info& info, pa_context& context);

bool operator==(const GeneralDeviceImpl& other) const
{
Expand All @@ -39,8 +41,8 @@ class GeneralDeviceImpl final

[[nodiscard]] uint32_t getCardIndex() const noexcept;

[[nodiscard]] bool isDeleted() const noexcept;
[[nodiscard]] bool isEnabled() const noexcept;

[[nodiscard]] bool isMuted() const;

[[nodiscard]] Volume getVolume() const;
Expand All @@ -49,12 +51,6 @@ class GeneralDeviceImpl final
[[nodiscard]] pa_cvolume getPulseChannelVolume() const noexcept;

[[nodiscard]] std::string getName() const;

[[nodiscard]] sigc::signal<void()> onChanged() const
{
return m_onChanged;
}

[[nodiscard]] std::string getDescription() const;

[[nodiscard]] pa_context& getContext() const noexcept
Expand All @@ -64,14 +60,23 @@ class GeneralDeviceImpl final

void update(const pa_sink_info& info);
void update(const pa_source_info& info);
void update(const pa_sink_input_info& info);
void update(const pa_source_output_info& info);

void update(const pa_card_info& info);

void markDeleted();

[[nodiscard]] std::string toString() const;

private:
void deleteCheck();

private:
const uint32_t m_index;
uint32_t m_cardIndex;

bool m_isDeleted = false;
bool m_isEnabled = false;
std::string m_name;
std::string m_description;
Expand All @@ -83,7 +88,6 @@ class GeneralDeviceImpl final
bool m_isMuted;

mutable std::mutex m_mutex;
sigc::signal<void()> m_onChanged;
};

} // namespace ghaf::AudioControl::Backend::PulseAudio
Loading

0 comments on commit b02f0c2

Please sign in to comment.