Skip to content

Commit

Permalink
In Context, hold pools not factories.
Browse files Browse the repository at this point in the history
  • Loading branch information
nolan-veed committed Dec 27, 2023
1 parent b98c7ab commit 2dcf8d3
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/internal_modules/roc_core/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "roc_core/align_ops.h"
#include "roc_core/macro_helpers.h"
#include "roc_core/ref_counted.h"
#include "roc_core/slab_pool.h"
#include "roc_core/ipool.h"
#include "roc_core/stddefs.h"

namespace roc {
Expand Down
8 changes: 4 additions & 4 deletions src/internal_modules/roc_core/buffer_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

#include "roc_core/allocation_policy.h"
#include "roc_core/buffer.h"
#include "roc_core/ipool.h"
#include "roc_core/noncopyable.h"
#include "roc_core/shared_ptr.h"
#include "roc_core/slab_pool.h"

namespace roc {
namespace core {
Expand All @@ -28,8 +28,8 @@ template <class T> class BufferFactory : public core::NonCopyable<> {
public:
//! Initialization.
//! @p buffer_size defines number of elements in buffer.
BufferFactory(IArena& arena, size_t buffer_size)
: buffer_pool_("buffer_pool", arena, sizeof(Buffer<T>) + sizeof(T) * buffer_size)
BufferFactory(IPool& pool, size_t buffer_size)
: buffer_pool_(pool)
, buffer_size_(buffer_size) {
}

Expand All @@ -44,7 +44,7 @@ template <class T> class BufferFactory : public core::NonCopyable<> {
}

private:
SlabPool<Buffer<T> > buffer_pool_;
IPool& buffer_pool_;
const size_t buffer_size_;
};

Expand Down
19 changes: 10 additions & 9 deletions src/internal_modules/roc_node/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ namespace node {

Context::Context(const ContextConfig& config, core::IArena& arena)
: arena_(arena)
, packet_factory_(arena_)
, byte_buffer_factory_(arena_, config.max_packet_size)
, sample_buffer_factory_(arena_, config.max_frame_size / sizeof(audio::sample_t))
, packet_pool_("packet_pool", arena_)
, byte_buffer_pool_("byte_buf_pool", arena_, sizeof(core::Buffer<uint8_t >) + sizeof(uint8_t) * config.max_packet_size)
, sample_buffer_pool_("sample_buf_pool", arena_, sizeof(core::Buffer<audio::sample_t >) + sizeof(audio::sample_t) * config.max_frame_size)
, encoding_map_(arena_)
// TODO:
, network_loop_(packet_factory_, byte_buffer_factory_, arena_)
, control_loop_(network_loop_, arena_) {
roc_log(LogDebug, "context: initializing");
Expand All @@ -36,16 +37,16 @@ core::IArena& Context::arena() {
return arena_;
}

packet::PacketFactory& Context::packet_factory() {
return packet_factory_;
core::IPool& Context::packet_pool() {
return packet_pool_;
}

core::BufferFactory<uint8_t>& Context::byte_buffer_factory() {
return byte_buffer_factory_;
core::IPool& Context::byte_buffer_pool() {
return byte_buffer_pool_;
}

core::BufferFactory<audio::sample_t>& Context::sample_buffer_factory() {
return sample_buffer_factory_;
core::IPool& Context::sample_buffer_pool() {
return sample_buffer_pool_;
}

rtp::EncodingMap& Context::encoding_map() {
Expand Down
18 changes: 9 additions & 9 deletions src/internal_modules/roc_node/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ class Context : public core::RefCounted<Context, core::ManualAllocation> {
//! Get arena.
core::IArena& arena();

//! Get packet factory.
packet::PacketFactory& packet_factory();
//! Get packet pool.
core::IPool& packet_pool();

//! Get byte buffer factory.
core::BufferFactory<uint8_t>& byte_buffer_factory();
//! Get byte buffer pool.
core::IPool& byte_buffer_pool();

//! Get sample buffer factory.
core::BufferFactory<audio::sample_t>& sample_buffer_factory();
//! Get sample buffer pool.
core::IPool& sample_buffer_pool();

//! Get encoding map.
rtp::EncodingMap& encoding_map();
Expand All @@ -76,9 +76,9 @@ class Context : public core::RefCounted<Context, core::ManualAllocation> {
private:
core::IArena& arena_;

packet::PacketFactory packet_factory_;
core::BufferFactory<uint8_t> byte_buffer_factory_;
core::BufferFactory<audio::sample_t> sample_buffer_factory_;
core::SlabPool<packet::Packet> packet_pool_;
core::SlabPool<core::Buffer<uint8_t> > byte_buffer_pool_;
core::SlabPool<core::Buffer<audio::sample_t> > sample_buffer_pool_;

rtp::EncodingMap encoding_map_;

Expand Down
4 changes: 2 additions & 2 deletions src/internal_modules/roc_packet/packet_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
namespace roc {
namespace packet {

PacketFactory::PacketFactory(core::IArena& arena)
: pool_("packet_pool", arena) {
PacketFactory::PacketFactory(core::IPool& pool)
: pool_(pool) {
}

core::SharedPtr<Packet> PacketFactory::new_packet() {
Expand Down
6 changes: 3 additions & 3 deletions src/internal_modules/roc_packet/packet_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "roc_core/allocation_policy.h"
#include "roc_core/noncopyable.h"
#include "roc_core/shared_ptr.h"
#include "roc_core/slab_pool.h"
#include "roc_core/ipool.h"
#include "roc_packet/packet.h"

namespace roc {
Expand All @@ -25,13 +25,13 @@ namespace packet {
class PacketFactory : public core::NonCopyable<> {
public:
//! Constructor.
PacketFactory(core::IArena& arena);
PacketFactory(core::IPool& pool);

//! Create new packet;
core::SharedPtr<Packet> new_packet();

private:
core::SlabPool<Packet> pool_;
core::IPool& pool_;
};

} // namespace packet
Expand Down

0 comments on commit 2dcf8d3

Please sign in to comment.