Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
Loading...
Searching...
No Matches
encoding_map.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2017 Roc Streaming authors
3
*
4
* This Source Code Form is subject to the terms of the Mozilla Public
5
* License, v. 2.0. If a copy of the MPL was not distributed with this
6
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
*/
8
9
//! @file roc_rtp/encoding_map.h
10
//! @brief RTP encoding map.
11
12
#ifndef ROC_RTP_ENCODING_MAP_H_
13
#define ROC_RTP_ENCODING_MAP_H_
14
15
#include "
roc_audio/sample_spec.h
"
16
#include "
roc_core/allocation_policy.h
"
17
#include "
roc_core/attributes.h
"
18
#include "
roc_core/hashmap.h
"
19
#include "
roc_core/iarena.h
"
20
#include "
roc_core/mutex.h
"
21
#include "
roc_core/noncopyable.h
"
22
#include "
roc_core/ref_counted.h
"
23
#include "
roc_core/slab_pool.h
"
24
#include "
roc_rtp/encoding.h
"
25
26
namespace
roc
{
27
namespace
rtp
{
28
29
//! RTP encoding map.
30
//! Thread-safe.
31
//! Returned encodings are immutable and can be safely used from
32
//! any thread.
33
class
EncodingMap
:
public
core::NonCopyable
<> {
34
public
:
35
//! Initialize.
36
EncodingMap
(
core::IArena
& arena);
37
38
//! Find encoding by payload type.
39
//! @returns
40
//! pointer to the encoding structure or null if there is no encoding
41
//! registered for this payload type.
42
const
Encoding
*
find_by_pt
(
unsigned
int
pt)
const
;
43
44
//! Find encoding by sample specification.
45
//! @returns
46
//! pointer to the encoding structure or null if there is no encoding
47
//! with matching specification.
48
const
Encoding
*
find_by_spec
(
const
audio::SampleSpec
& spec)
const
;
49
50
//! Add encoding to the map.
51
//! @returns
52
//! true if successfully added or false if another encoding with the same
53
//! payload type already exists.
54
ROC_ATTR_NODISCARD
bool
add_encoding
(
Encoding
enc);
55
56
private
:
57
enum
{ PreallocatedNodes = 16 };
58
59
struct
Node :
core::RefCounted
<Node, core::PoolAllocation>,
core::HashmapNode
<> {
60
Node(
core::IPool
&
pool
,
const
Encoding
& encoding)
61
:
core
::
RefCounted
<Node,
core
::
PoolAllocation
>(
pool
)
62
, encoding(encoding) {
63
}
64
65
Encoding encoding;
66
67
unsigned
int
key()
const
{
68
return
encoding.
payload_type
;
69
}
70
71
static
core::hashsum_t
key_hash(
unsigned
int
pt) {
72
return
core::hashsum_int
(pt);
73
}
74
75
static
bool
key_equal(
unsigned
int
pt1,
unsigned
int
pt2) {
76
return
pt1 == pt2;
77
}
78
};
79
80
void
add_builtin_(
const
Encoding& enc);
81
void
find_codecs_(Encoding& enc);
82
83
core::Mutex mutex_;
84
85
core::SlabPool<Node, PreallocatedNodes> node_pool_;
86
core::Hashmap<Node, PreallocatedNodes> node_map_;
87
};
88
89
}
// namespace rtp
90
}
// namespace roc
91
92
#endif
// ROC_RTP_ENCODING_MAP_H_
allocation_policy.h
Allocation policies.
attributes.h
Compiler attributes.
ROC_ATTR_NODISCARD
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition
attributes.h:31
roc::audio::SampleSpec
Sample specification. Describes sample rate and channels.
Definition
sample_spec.h:30
roc::core::HashmapNode
Base class for Hashmap element.
Definition
hashmap_node.h:61
roc::core::IArena
Memory arena interface.
Definition
iarena.h:23
roc::core::IPool
Memory pool interface.
Definition
ipool.h:23
roc::core::NonCopyable
Base class for non-copyable objects.
Definition
noncopyable.h:23
roc::core::PoolAllocation::PoolAllocation
PoolAllocation(IPool &pool)
Initialize.
Definition
allocation_policy.h:49
roc::core::PoolAllocation::pool
IPool & pool() const
Get pool.
Definition
allocation_policy.h:60
roc::core::RefCounted
Base class for object with reference counter.
Definition
ref_counted.h:40
roc::core::RefCounted< Node, core::PoolAllocation >::RefCounted
RefCounted()
Definition
ref_counted.h:43
roc::rtp::EncodingMap::find_by_spec
const Encoding * find_by_spec(const audio::SampleSpec &spec) const
Find encoding by sample specification.
roc::rtp::EncodingMap::find_by_pt
const Encoding * find_by_pt(unsigned int pt) const
Find encoding by payload type.
roc::rtp::EncodingMap::EncodingMap
EncodingMap(core::IArena &arena)
Initialize.
roc::rtp::EncodingMap::add_encoding
ROC_ATTR_NODISCARD bool add_encoding(Encoding enc)
Add encoding to the map.
encoding.h
RTP encoding.
hashmap.h
Intrusive hash table.
iarena.h
Memory arena interface.
mutex.h
Mutex.
roc::core
General-purpose building blocks and platform abstraction layer.
roc::core::hashsum_int
hashsum_t hashsum_int(int16_t)
Compute hash of 16-bit integer.
roc::core::hashsum_t
size_t hashsum_t
Hash type.
Definition
hashsum.h:21
roc::rtp
RTP protocol support.
roc
Root namespace.
noncopyable.h
Non-copyable object.
ref_counted.h
Base class for object with reference counter.
sample_spec.h
Sample specifications.
slab_pool.h
Memory pool.
roc::rtp::Encoding
RTP encoding.
Definition
encoding.h:27
roc::rtp::Encoding::payload_type
unsigned int payload_type
Payload type.
Definition
encoding.h:29
roc_rtp
encoding_map.h
Generated by
1.17.0