From f957fcdd98d85615680b0037d7246935745391bb Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Fri, 6 Jan 2017 15:32:53 +0100 Subject: [PATCH] use Attached_dataspace at audio streams Ref #1987 --- repos/dde_bsd/src/drivers/audio/main.cc | 61 +++++++++---------- repos/dde_bsd/src/test/audio_in/main.cc | 45 +++++--------- repos/os/include/audio_in_session/client.h | 10 ++- .../os/include/audio_in_session/connection.h | 15 +---- .../os/include/audio_in_session/rpc_object.h | 26 +++----- repos/os/include/audio_out_session/client.h | 13 ++-- .../os/include/audio_out_session/connection.h | 4 +- .../os/include/audio_out_session/rpc_object.h | 29 ++++----- repos/os/src/drivers/audio/spec/linux/main.cc | 15 ++--- repos/os/src/server/mixer/mixer.cc | 23 ++++--- repos/ports/src/virtualbox/audiodrv.cpp | 4 +- 11 files changed, 107 insertions(+), 138 deletions(-) diff --git a/repos/dde_bsd/src/drivers/audio/main.cc b/repos/dde_bsd/src/drivers/audio/main.cc index 6e513cd353..130f6c42d2 100644 --- a/repos/dde_bsd/src/drivers/audio/main.cc +++ b/repos/dde_bsd/src/drivers/audio/main.cc @@ -51,9 +51,9 @@ class Audio_out::Session_component : public Audio_out::Session_rpc_object public: - Session_component(Channel_number channel, Signal_context_capability cap) + Session_component(Genode::Env &env, Channel_number channel, Signal_context_capability cap) : - Session_rpc_object(cap), _channel(channel) + Session_rpc_object(env, cap), _channel(channel) { Audio_out::channel_acquired[_channel] = this; } @@ -69,7 +69,7 @@ class Audio_out::Out { private: - Genode::Entrypoint &_ep; + Genode::Env &_env; Genode::Signal_handler _data_avail_dispatcher; Genode::Signal_handler _notify_dispatcher; @@ -173,11 +173,11 @@ class Audio_out::Out public: - Out(Genode::Entrypoint &ep) + Out(Genode::Env &env) : - _ep(ep), - _data_avail_dispatcher(ep, *this, &Audio_out::Out::_handle_data_avail), - _notify_dispatcher(ep, *this, &Audio_out::Out::_handle_notify) + _env(env), + _data_avail_dispatcher(env.ep(), *this, &Audio_out::Out::_handle_data_avail), + _notify_dispatcher(env.ep(), *this, &Audio_out::Out::_handle_notify) { /* play a silence packet to get the driver running */ _play_silence(); @@ -262,7 +262,7 @@ class Audio_out::Root : public Audio_out::Root_component { private: - Genode::Entrypoint &_ep; + Genode::Env &_env; Signal_context_capability _cap; @@ -278,16 +278,16 @@ class Audio_out::Root : public Audio_out::Root_component Out::channel_number(channel_name, &channel_number); return new (md_alloc()) - Session_component(channel_number, _cap); + Session_component(_env, channel_number, _cap); } public: - Root(Genode::Entrypoint &ep, Allocator &md_alloc, + Root(Genode::Env &env, Allocator &md_alloc, Signal_context_capability cap) : - Root_component(&ep.rpc_ep(), &md_alloc), - _ep(ep), _cap(cap) + Root_component(env.ep(), md_alloc), + _env(env), _cap(cap) { } }; @@ -315,9 +315,9 @@ class Audio_in::Session_component : public Audio_in::Session_rpc_object public: - Session_component(Channel_number channel, + Session_component(Genode::Env &env, Channel_number channel, Genode::Signal_context_capability cap) - : Session_rpc_object(cap), _channel(channel) { + : Session_rpc_object(env, cap), _channel(channel) { channel_acquired = this; } ~Session_component() { channel_acquired = nullptr; } @@ -328,7 +328,7 @@ class Audio_in::In { private: - Genode::Entrypoint &_ep; + Genode::Env &_env; Genode::Signal_handler _notify_dispatcher; bool _active() { return channel_acquired && channel_acquired->active(); } @@ -375,10 +375,10 @@ class Audio_in::In public: - In(Genode::Entrypoint &ep) + In(Genode::Env &env) : - _ep(ep), - _notify_dispatcher(ep, *this, &Audio_in::In::_handle_notify) + _env(env), + _notify_dispatcher(env.ep(), *this, &Audio_in::In::_handle_notify) { _record_packet(); } Signal_context_capability sigh() { return _notify_dispatcher; } @@ -453,7 +453,7 @@ class Audio_in::Root : public Audio_in::Root_component { private: - Genode::Entrypoint &_ep; + Genode::Env &_env; Signal_context_capability _cap; protected: @@ -466,14 +466,14 @@ class Audio_in::Root : public Audio_in::Root_component sizeof(channel_name), "left"); In::channel_number(channel_name, &channel_number); - return new (md_alloc()) Session_component(channel_number, _cap); + return new (md_alloc()) Session_component(_env, channel_number, _cap); } public: - Root(Genode::Entrypoint &ep, Allocator &md_alloc, + Root(Genode::Env &env, Allocator &md_alloc, Signal_context_capability cap) - : Root_component(&ep.rpc_ep(), &md_alloc), _ep(ep), _cap(cap) { } + : Root_component(env.ep(), md_alloc), _env(env), _cap(cap) { } }; @@ -484,13 +484,12 @@ class Audio_in::Root : public Audio_in::Root_component struct Main { Genode::Env &env; - Genode::Entrypoint &ep; Genode::Heap heap { &env.ram(), &env.rm() }; Genode::Attached_rom_dataspace config { env, "config" }; Genode::Signal_handler
config_update_dispatcher { - ep, *this, &Main::handle_config_update }; + env.ep(), *this, &Main::handle_config_update }; void handle_config_update() { @@ -499,7 +498,7 @@ struct Main Audio::update_config(config.xml()); } - Main(Genode::Env &env) : env(env), ep(env.ep()) + Main(Genode::Env &env) : env(env) { Audio::init_driver(env, heap, config.xml()); @@ -509,21 +508,21 @@ struct Main /* playback */ if (config.xml().attribute_value("playback", true)) { - static Audio_out::Out out(ep); + static Audio_out::Out out(env); Audio::play_sigh(out.sigh()); - static Audio_out::Root out_root(ep, heap, out.data_avail()); - env.parent().announce(ep.manage(out_root)); + static Audio_out::Root out_root(env, heap, out.data_avail()); + env.parent().announce(env.ep().manage(out_root)); Genode::log("--- BSD Audio driver enable playback ---"); } /* recording */ if (config.xml().attribute_value("recording", true)) { - static Audio_in::In in(ep); + static Audio_in::In in(env); Audio::record_sigh(in.sigh()); - static Audio_in::Root in_root(ep, heap, + static Audio_in::Root in_root(env, heap, Genode::Signal_context_capability()); - env.parent().announce(ep.manage(in_root)); + env.parent().announce(env.ep().manage(in_root)); Genode::log("--- BSD Audio driver enable recording ---"); } diff --git a/repos/dde_bsd/src/test/audio_in/main.cc b/repos/dde_bsd/src/test/audio_in/main.cc index db87889a3e..3b0fd8978f 100644 --- a/repos/dde_bsd/src/test/audio_in/main.cc +++ b/repos/dde_bsd/src/test/audio_in/main.cc @@ -7,7 +7,7 @@ */ /* - * Copyright (C) 2015 Genode Labs GmbH + * Copyright (C) 2015-2017 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU General Public License version 2. @@ -16,10 +16,10 @@ /* Genode includes */ #include #include +#include +#include #include -#include #include -#include #include @@ -36,12 +36,11 @@ class Recording { private: - Genode::Signal_receiver &_sig_rec; - Genode::Signal_dispatcher _record_progress; - Genode::Signal_dispatcher _record_overrun; + Genode::Signal_handler _record_progress; + Genode::Signal_handler _record_overrun; Audio_out::Connection *_audio_out[CHANNELS]; - Audio_in::Connection _audio_in { "left" }; + Audio_in::Connection _audio_in; Audio_in::Stream &_stream; void _play(Audio_in::Packet *ip) @@ -68,7 +67,7 @@ class Recording _audio_out[c]->submit(op[c]); } - void _handle_record_progress(unsigned) + void _handle_record_progress() { Audio_in::Packet *p = _stream.get(_stream.pos()); @@ -83,7 +82,7 @@ class Recording _stream.increment_position(); } - void _handle_record_overrun(unsigned) + void _handle_record_overrun() { unsigned pos = _stream.pos(); unsigned tail = _stream.tail(); @@ -101,11 +100,11 @@ class Recording public: - Recording(Genode::Allocator &md_alloc, Genode::Signal_receiver &sig_rec) + Recording(Genode::Env &env, Genode::Allocator &md_alloc) : - _sig_rec(sig_rec), - _record_progress(_sig_rec, *this, &Recording::_handle_record_progress), - _record_overrun(_sig_rec, *this, &Recording::_handle_record_overrun), + _record_progress(env.ep(), *this, &Recording::_handle_record_progress), + _record_overrun(env.ep(), *this, &Recording::_handle_record_overrun), + _audio_in(env, "left" ), _stream(*_audio_in.stream()) { _audio_in.progress_sigh(_record_progress); @@ -121,24 +120,10 @@ class Recording } }; -int main(int argc, char *argv[]) +void Component::construct(Genode::Env &env) { Genode::log("--- Audio_in test ---"); - using namespace Genode; - - Signal_receiver sig_rec; - - Recording record(*env()->heap(), sig_rec); - - for (;;) { - Signal sig = sig_rec.wait_for_signal(); - Signal_dispatcher_base *dispatcher = - dynamic_cast(sig.context()); - - if (dispatcher) - dispatcher->dispatch(sig.num()); - } - - return 0; + static Genode::Heap heap { env.ram(), env.rm() }; + static Recording record(env, heap); } diff --git a/repos/os/include/audio_in_session/client.h b/repos/os/include/audio_in_session/client.h index 8267178fbf..4a02940c73 100644 --- a/repos/os/include/audio_in_session/client.h +++ b/repos/os/include/audio_in_session/client.h @@ -17,6 +17,7 @@ /* Genode includes */ #include #include +#include #include @@ -43,6 +44,8 @@ class Audio_in::Session_client : public Genode::Rpc_client { private: + Genode::Attached_dataspace _shared_ds; + Signal _progress; Genode::Signal_transmitter _data_avail; @@ -55,14 +58,15 @@ class Audio_in::Session_client : public Genode::Rpc_client * \param session session capability * \param progress_signal true, install 'progress_signal' receiver */ - Session_client(Genode::Capability session, + Session_client(Genode::Region_map &rm, + Genode::Capability session, bool progress_signal) : Genode::Rpc_client(session), + _shared_ds(rm, call()), _data_avail(call()) { - /* ask server for stream data space and attach it */ - _stream = static_cast(Genode::env()->rm_session()->attach(call())); + _stream = _shared_ds.local_addr(); if (progress_signal) progress_sigh(_progress.cap); diff --git a/repos/os/include/audio_in_session/connection.h b/repos/os/include/audio_in_session/connection.h index bc57529983..3977be6291 100644 --- a/repos/os/include/audio_in_session/connection.h +++ b/repos/os/include/audio_in_session/connection.h @@ -44,20 +44,7 @@ struct Audio_in::Connection : Genode::Connection, Audio_in::Session_cli Connection(Genode::Env &env, char const *channel, bool progress_signal = false) : Genode::Connection(env, _session(env.parent(), channel)), - Session_client(cap(), progress_signal) - { } - - /** - * Constructor - * - * \noapi - * \deprecated Use the constructor with 'Env &' as first - * argument instead - */ - Connection(char const *channel, bool progress_signal = false) - : - Genode::Connection(_session(*Genode::env()->parent(), channel)), - Session_client(cap(), progress_signal) + Session_client(env.rm(), cap(), progress_signal) { } }; diff --git a/repos/os/include/audio_in_session/rpc_object.h b/repos/os/include/audio_in_session/rpc_object.h index 2034aa056e..cec8246ab2 100644 --- a/repos/os/include/audio_in_session/rpc_object.h +++ b/repos/os/include/audio_in_session/rpc_object.h @@ -17,6 +17,7 @@ /* Genode includes */ #include #include +#include #include @@ -28,31 +29,22 @@ class Audio_in::Session_rpc_object : public Genode::Rpc_objectram_session()->alloc(sizeof(Stream)); - _stream = static_cast(env()->rm_session()->attach(_ds)); - } - - virtual ~Session_rpc_object() - { - if (_ds.valid()) { - Genode::env()->rm_session()->detach(_stream); - Genode::env()->ram_session()->free(_ds); - } + _stream = _ds.local_addr(); } @@ -77,7 +69,7 @@ class Audio_in::Session_rpc_object : public Genode::Rpc_object #include +#include #include namespace Audio_out { @@ -41,6 +42,8 @@ class Audio_out::Session_client : public Genode::Rpc_client { private: + Genode::Attached_dataspace _shared_ds; + Signal _progress; Signal _alloc; @@ -51,18 +54,20 @@ class Audio_out::Session_client : public Genode::Rpc_client /** * Constructor * + * \param rm region map for attaching shared buffer * \param session session capability * \param alloc_signal true, install 'alloc_signal' receiver * \param progress_signal true, install 'progress_signal' receiver */ - Session_client(Genode::Capability session, bool alloc_signal, - bool progress_signal) + Session_client(Genode::Region_map &rm, + Genode::Capability session, + bool alloc_signal, bool progress_signal) : Genode::Rpc_client(session), + _shared_ds(rm, call()), _data_avail(call()) { - /* ask server for stream data space and attach it */ - _stream = static_cast(Genode::env()->rm_session()->attach(call())); + _stream = _shared_ds.local_addr(); if (progress_signal) progress_sigh(_progress.cap); diff --git a/repos/os/include/audio_out_session/connection.h b/repos/os/include/audio_out_session/connection.h index 393a1dbdf3..92b5534820 100644 --- a/repos/os/include/audio_out_session/connection.h +++ b/repos/os/include/audio_out_session/connection.h @@ -50,7 +50,7 @@ struct Audio_out::Connection : Genode::Connection, Audio_out::Session_c bool progress_signal = false) : Genode::Connection(env, _session(env.parent(), channel)), - Session_client(cap(), alloc_signal, progress_signal) + Session_client(env.rm(), cap(), alloc_signal, progress_signal) { } /** @@ -65,7 +65,7 @@ struct Audio_out::Connection : Genode::Connection, Audio_out::Session_c bool progress_signal = false) : Genode::Connection(_session(*Genode::env()->parent(), channel)), - Session_client(cap(), alloc_signal, progress_signal) + Session_client(*Genode::env()->rm_session(), cap(), alloc_signal, progress_signal) { } }; diff --git a/repos/os/include/audio_out_session/rpc_object.h b/repos/os/include/audio_out_session/rpc_object.h index fa9bb322be..88a76c119a 100644 --- a/repos/os/include/audio_out_session/rpc_object.h +++ b/repos/os/include/audio_out_session/rpc_object.h @@ -16,6 +16,7 @@ #include #include +#include #include @@ -27,33 +28,25 @@ class Audio_out::Session_rpc_object : public Genode::Rpc_objectram_session()->alloc(sizeof(Stream)); - _stream = static_cast(Genode::env()->rm_session()->attach(_ds)); - } - - virtual ~Session_rpc_object() - { - if (_ds.valid()) { - Genode::env()->rm_session()->detach(_stream); - Genode::env()->ram_session()->free(_ds); - } + _stream = _ds.local_addr(); } @@ -84,7 +77,7 @@ class Audio_out::Session_rpc_object : public Genode::Rpc_objectget(stream()->pos() + offset); } @@ -608,10 +609,11 @@ class Audio_out::Session_component : public Audio_out::Session_elem public: - Session_component(char const *label, + Session_component(Genode::Env &env, + char const *label, Channel::Number number, Mixer &mixer) - : Session_elem(label, mixer.sig_cap()), _mixer(mixer) + : Session_elem(env, label, mixer.sig_cap()), _mixer(mixer) { Session_elem::number = number; _mixer.add_session(Session_elem::number, *this); @@ -647,8 +649,9 @@ class Audio_out::Root : public Audio_out::Root_component { private: - Mixer &_mixer; - int _sessions = { 0 }; + Genode::Env &_env; + Mixer &_mixer; + int _sessions = { 0 }; Session_component *_create_session(const char *args) { @@ -681,7 +684,7 @@ class Audio_out::Root : public Audio_out::Root_component throw Root::Invalid_args(); Session_component *session = new (md_alloc()) - Session_component(label, (Channel::Number)ch, _mixer); + Session_component(_env, label, (Channel::Number)ch, _mixer); if (++_sessions == 1) _mixer.start(); return session; @@ -696,10 +699,10 @@ class Audio_out::Root : public Audio_out::Root_component public: - Root(Genode::Entrypoint &ep, + Root(Genode::Env &env, Mixer &mixer, Genode::Allocator &md_alloc) - : Root_component(&ep.rpc_ep(), &md_alloc), _mixer(mixer) { } + : Root_component(env.ep(), md_alloc), _env(env), _mixer(mixer) { } }; @@ -716,7 +719,7 @@ struct Mixer::Main Genode::Sliced_heap heap { env.ram(), env.rm() }; Audio_out::Mixer mixer = { env }; - Audio_out::Root root = { env.ep(), mixer, heap }; + Audio_out::Root root = { env, mixer, heap }; Main(Genode::Env &env) : env(env) { diff --git a/repos/ports/src/virtualbox/audiodrv.cpp b/repos/ports/src/virtualbox/audiodrv.cpp index cf1397de77..32fc570047 100644 --- a/repos/ports/src/virtualbox/audiodrv.cpp +++ b/repos/ports/src/virtualbox/audiodrv.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2015 Genode Labs GmbH + * Copyright (C) 2015-2017 Genode Labs GmbH * * This file is distributed under the terms of the GNU General Public License * version 2. @@ -341,7 +341,7 @@ static int genode_init_in(HWVoiceIn *hw, audsettings_t *as) GenodeVoiceIn *in = (GenodeVoiceIn*)hw; try { - in->audio = new (vmm_heap()) Audio_in::Connection("left"); + in->audio = new (vmm_heap()) Audio_in::Connection(genode_env(), "left"); } catch (...) { Genode::error("could not establish Audio_in connection"); return -1;