Custom Anbox installation files & patches, including patched Android OS image file.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
7.0 KiB

4 years ago
  1. From 5e754cda716b9f17a69bf3363bb6dfc46ba6194d Mon Sep 17 00:00:00 2001
  2. From: awakening <lucidsunlight@yandex.ru>
  3. Date: Sun, 20 Jan 2019 21:54:03 +0700
  4. Subject: [PATCH] Pass messenger to audio sink
  5. ---
  6. src/anbox/audio/server.cpp | 9 ++++++---
  7. src/anbox/platform/base_platform.h | 3 ++-
  8. src/anbox/platform/null/platform.cpp | 3 ++-
  9. src/anbox/platform/null/platform.h | 2 +-
  10. src/anbox/platform/sdl/audio_sink.cpp | 3 ++-
  11. src/anbox/platform/sdl/audio_sink.h | 6 ++++--
  12. src/anbox/platform/sdl/platform.cpp | 4 ++--
  13. src/anbox/platform/sdl/platform.h | 2 +-
  14. 8 files changed, 20 insertions(+), 12 deletions(-)
  15. diff --git a/src/anbox/audio/server.cpp b/src/anbox/audio/server.cpp
  16. index ad1396808..21f86ae60 100644
  17. --- a/src/anbox/audio/server.cpp
  18. +++ b/src/anbox/audio/server.cpp
  19. @@ -31,8 +31,10 @@ using namespace std::placeholders;
  20. namespace {
  21. class AudioForwarder : public anbox::network::MessageProcessor {
  22. public:
  23. - AudioForwarder(const std::shared_ptr<anbox::audio::Sink> &sink) :
  24. - sink_(sink) {
  25. + AudioForwarder(const std::shared_ptr<anbox::audio::Sink> &sink,
  26. + const std::shared_ptr<anbox::network::LocalSocketMessenger> &messenger) :
  27. + sink_(sink),
  28. + messenger_(messenger) {
  29. }
  30. bool process_data(const std::vector<std::uint8_t> &data) override {
  31. @@ -42,6 +44,7 @@ class AudioForwarder : public anbox::network::MessageProcessor {
  32. private:
  33. std::shared_ptr<anbox::audio::Sink> sink_;
  34. + std::shared_ptr<anbox::network::LocalSocketMessenger> messenger_;
  35. };
  36. }
  37. @@ -81,7 +84,7 @@ void Server::create_connection_for(std::shared_ptr<boost::asio::basic_stream_soc
  38. switch (client_info.type) {
  39. case ClientInfo::Type::Playback:
  40. - processor = std::make_shared<AudioForwarder>(platform_->create_audio_sink());
  41. + processor = std::make_shared<AudioForwarder>(platform_->create_audio_sink(messenger), messenger);
  42. break;
  43. case ClientInfo::Type::Recording:
  44. break;
  45. diff --git a/src/anbox/platform/base_platform.h b/src/anbox/platform/base_platform.h
  46. index 042781fef..bd6eed11a 100644
  47. --- a/src/anbox/platform/base_platform.h
  48. +++ b/src/anbox/platform/base_platform.h
  49. @@ -20,6 +20,7 @@
  50. #include "anbox/graphics/rect.h"
  51. #include "anbox/wm/window_state.h"
  52. +#include "anbox/network/local_socket_messenger.h"
  53. #include <memory>
  54. @@ -51,7 +52,7 @@ class BasePlatform {
  55. virtual void set_clipboard_data(const ClipboardData &data) = 0;
  56. virtual ClipboardData get_clipboard_data() = 0;
  57. - virtual std::shared_ptr<audio::Sink> create_audio_sink() = 0;
  58. + virtual std::shared_ptr<audio::Sink> create_audio_sink(const std::shared_ptr<anbox::network::LocalSocketMessenger> &messenger) = 0;
  59. virtual std::shared_ptr<audio::Source> create_audio_source() = 0;
  60. virtual void set_renderer(const std::shared_ptr<Renderer> &renderer) = 0;
  61. diff --git a/src/anbox/platform/null/platform.cpp b/src/anbox/platform/null/platform.cpp
  62. index c89480640..27a97e3d8 100644
  63. --- a/src/anbox/platform/null/platform.cpp
  64. +++ b/src/anbox/platform/null/platform.cpp
  65. @@ -48,7 +48,8 @@ NullPlatform::ClipboardData NullPlatform::get_clipboard_data() {
  66. return ClipboardData{};
  67. }
  68. -std::shared_ptr<audio::Sink> NullPlatform::create_audio_sink() {
  69. +std::shared_ptr<audio::Sink> NullPlatform::create_audio_sink(const std::shared_ptr<network::LocalSocketMessenger> &messenger) {
  70. + (void) messenger;
  71. ERROR("Not implemented");
  72. return nullptr;
  73. }
  74. diff --git a/src/anbox/platform/null/platform.h b/src/anbox/platform/null/platform.h
  75. index 24ad341e2..c0da52b08 100644
  76. --- a/src/anbox/platform/null/platform.h
  77. +++ b/src/anbox/platform/null/platform.h
  78. @@ -31,7 +31,7 @@ class NullPlatform : public BasePlatform {
  79. const std::string &title) override;
  80. void set_clipboard_data(const ClipboardData &data) override;
  81. ClipboardData get_clipboard_data() override;
  82. - std::shared_ptr<audio::Sink> create_audio_sink() override;
  83. + std::shared_ptr<audio::Sink> create_audio_sink(const std::shared_ptr<network::LocalSocketMessenger> &messenger) override;
  84. std::shared_ptr<audio::Source> create_audio_source() override;
  85. void set_renderer(const std::shared_ptr<Renderer> &renderer) override;
  86. void set_window_manager(const std::shared_ptr<wm::Manager> &window_manager) override;
  87. diff --git a/src/anbox/platform/sdl/audio_sink.cpp b/src/anbox/platform/sdl/audio_sink.cpp
  88. index 5a0c4ad25..118093de7 100644
  89. --- a/src/anbox/platform/sdl/audio_sink.cpp
  90. +++ b/src/anbox/platform/sdl/audio_sink.cpp
  91. @@ -29,7 +29,8 @@ const constexpr size_t max_queue_size{16};
  92. namespace anbox {
  93. namespace platform {
  94. namespace sdl {
  95. -AudioSink::AudioSink() :
  96. +AudioSink::AudioSink(const std::shared_ptr<network::LocalSocketMessenger> &messenger) :
  97. + messenger_(messenger),
  98. device_id_(0),
  99. queue_(max_queue_size) {
  100. }
  101. diff --git a/src/anbox/platform/sdl/audio_sink.h b/src/anbox/platform/sdl/audio_sink.h
  102. index f09db6975..636bcb16b 100644
  103. --- a/src/anbox/platform/sdl/audio_sink.h
  104. +++ b/src/anbox/platform/sdl/audio_sink.h
  105. @@ -21,6 +21,7 @@
  106. #include "anbox/audio/sink.h"
  107. #include "anbox/graphics/buffer_queue.h"
  108. #include "anbox/platform/sdl/sdl_wrapper.h"
  109. +#include "anbox/network/local_socket_messenger.h"
  110. #include <thread>
  111. @@ -29,7 +30,7 @@ namespace platform {
  112. namespace sdl {
  113. class AudioSink : public audio::Sink {
  114. public:
  115. - AudioSink();
  116. + AudioSink(const std::shared_ptr<network::LocalSocketMessenger> &messenger);
  117. ~AudioSink();
  118. void write_data(const std::vector<std::uint8_t> &data) override;
  119. @@ -40,7 +41,8 @@ class AudioSink : public audio::Sink {
  120. void read_data(std::uint8_t *buffer, int size);
  121. static void on_data_requested(void *user_data, std::uint8_t *buffer, int size);
  122. -
  123. +
  124. + std::shared_ptr<anbox::network::LocalSocketMessenger> messenger_;
  125. std::mutex lock_;
  126. SDL_AudioSpec spec_;
  127. SDL_AudioDeviceID device_id_;
  128. diff --git a/src/anbox/platform/sdl/platform.cpp b/src/anbox/platform/sdl/platform.cpp
  129. index 1bf5292e8..b3c80ae49 100644
  130. --- a/src/anbox/platform/sdl/platform.cpp
  131. +++ b/src/anbox/platform/sdl/platform.cpp
  132. @@ -491,8 +491,8 @@ Platform::ClipboardData Platform::get_clipboard_data() {
  133. return data;
  134. }
  135. -std::shared_ptr<audio::Sink> Platform::create_audio_sink() {
  136. - return std::make_shared<AudioSink>();
  137. +std::shared_ptr<audio::Sink> Platform::create_audio_sink(const std::shared_ptr<network::LocalSocketMessenger> &messenger) {
  138. + return std::make_shared<AudioSink>(messenger);
  139. }
  140. std::shared_ptr<audio::Source> Platform::create_audio_source() {
  141. diff --git a/src/anbox/platform/sdl/platform.h b/src/anbox/platform/sdl/platform.h
  142. index 7c73e86e0..5c4633fe7 100644
  143. --- a/src/anbox/platform/sdl/platform.h
  144. +++ b/src/anbox/platform/sdl/platform.h
  145. @@ -64,7 +64,7 @@ class Platform : public std::enable_shared_from_this<Platform>,
  146. void set_clipboard_data(const ClipboardData &data) override;
  147. ClipboardData get_clipboard_data() override;
  148. - std::shared_ptr<audio::Sink> create_audio_sink() override;
  149. + std::shared_ptr<audio::Sink> create_audio_sink(const std::shared_ptr<network::LocalSocketMessenger> &messenger) override;
  150. std::shared_ptr<audio::Source> create_audio_source() override;
  151. bool supports_multi_window() const override;