Ocean
AVFLiveAudio.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) Meta Platforms, Inc. and affiliates.
3
*
4
* This source code is licensed under the MIT license found in the
5
* LICENSE file in the root directory of this source tree.
6
*/
7
8
#ifndef META_OCEAN_MEDIA_AVF_LIVE_AUDIO_H
9
#define META_OCEAN_MEDIA_AVF_LIVE_AUDIO_H
10
11
#include "
ocean/media/avfoundation/AVFoundation.h
"
12
#include "
ocean/media/avfoundation/AVFMedium.h
"
13
14
#include "
ocean/media/LiveAudio.h
"
15
16
17
namespace
Ocean
18
{
19
20
namespace
Media
21
{
22
23
namespace
AVFoundation
24
{
25
26
/**
27
* This class implements an AVFoundation live audio object.
28
* @ingroup mediaavf
29
*/
30
class
AVFLiveAudio
:
31
virtual
public
AVFMedium
,
32
virtual
public
LiveAudio
33
{
34
friend
class
AVFLibrary
;
35
36
public
:
37
38
/**
39
* Adds new samples in case this audio object receives the audio data from a buffer/stream.
40
* @param sampleType The type of the samples, must be valid
41
* @param data The sample data, must be valid
42
* @param size The size of the sample data, in bytes, with range [1, infinity)
43
* @return True, if succeeded
44
*/
45
bool
addSamples
(
const
SampleType
sampleType,
const
void
* data,
const
size_t
size)
override
;
46
47
/**
48
* Returns whether a new sample needs to be added.
49
* @see LiveAudio::needNewSamples().
50
*/
51
bool
needNewSamples
()
const override
;
52
53
/**
54
* Returns the volume of the sound in db.
55
* @see SoundMedium::soundVolume().
56
*/
57
float
soundVolume
()
const override
;
58
59
/**
60
* Returns whether the sound medium is in a mute state.
61
* @see SoundMedium::soundMute().
62
*/
63
bool
soundMute
()
const override
;
64
65
/**
66
* Sets the volume of the sound in db.
67
* @see SoundMedium::setSoundVolume().
68
*/
69
bool
setSoundVolume
(
const
float
volume)
override
;
70
71
/**
72
* Sets or un-sets the sound medium to a mute state.
73
* @see SoundMedium::setSoundMute().
74
*/
75
bool
setSoundMute
(
const
bool
mute)
override
;
76
77
protected
:
78
79
/**
80
* Creates a new medium by a given url.
81
* @param url Url of the medium
82
*/
83
explicit
AVFLiveAudio
(
const
std::string&
url
);
84
85
/**
86
* Destructs the media object.
87
*/
88
~AVFLiveAudio
()
override
;
89
90
/**
91
* Internally starts the medium.
92
* @see AVFMedium::internalStart()
93
*/
94
bool
internalStart
()
override
;
95
96
/**
97
* Internally pauses the medium.
98
* @see AVFMedium::internalPause()
99
*/
100
bool
internalPause
()
override
;
101
102
/**
103
* Internally stops the medium.
104
* @see AVFMedium::internalStop()
105
*/
106
bool
internalStop
()
override
;
107
108
/**
109
* Extracts and sends mono samles form a PCM buffer.
110
* @param avAudioPCMBuffer The PCM buffer from which the samples will be extracted, must be valid
111
* @return True, if succeeded
112
*/
113
bool
sendSamplesMono
(AVAudioPCMBuffer* avAudioPCMBuffer);
114
115
protected
:
116
117
/// The audio engine.
118
AVAudioEngine*
avAudioEngine_
=
nullptr
;
119
120
/// The audio player node.
121
AVAudioPlayerNode*
avAudioPlayerNode_
=
nullptr
;
122
123
/// The audio mixer node e.g., allowing to control the volume.
124
AVAudioMixerNode*
avAudioMixerNode_
=
nullptr
;
125
126
/// The audio format of the audio player node.
127
AVAudioFormat*
avAudioFormat_
=
nullptr
;
128
129
/// Optional convert from external audio format to internal audio format.
130
AVAudioConverter*
avAudioConverter_
=
nullptr
;
131
132
/// Optional audio format for int16 samples.
133
AVAudioFormat*
avAudioFormatInternalInt16_
=
nullptr
;
134
135
/// Optional audio buffer for int16 samples.
136
AVAudioPCMBuffer*
avAudioPCMBufferInternalInt16_
=
nullptr
;
137
138
/// The previous volume before the medium was muted; -1 if the medium is not muted.
139
float
previousVolume_
= -1.0f;
140
141
/// True, if the audio session was started.
142
bool
audioSessionStarted_
=
false
;
143
144
/// True, if the audio object needs a new samples.
145
std::atomic_bool
needNewSamples_
=
false
;
146
};
147
148
}
149
150
}
151
152
}
153
154
#endif
// META_OCEAN_MEDIA_AVF_LIVE_AUDIO_H
AVFMedium.h
AVFoundation.h
LiveAudio.h
Ocean::Media::AVFoundation::AVFLibrary
This class implements the AVFoundation library.
Definition:
AVFLibrary.h:32
Ocean::Media::AVFoundation::AVFLiveAudio
This class implements an AVFoundation live audio object.
Definition:
AVFLiveAudio.h:33
Ocean::Media::AVFoundation::AVFLiveAudio::avAudioPCMBufferInternalInt16_
AVAudioPCMBuffer * avAudioPCMBufferInternalInt16_
Optional audio buffer for int16 samples.
Definition:
AVFLiveAudio.h:136
Ocean::Media::AVFoundation::AVFLiveAudio::needNewSamples
bool needNewSamples() const override
Returns whether a new sample needs to be added.
Ocean::Media::AVFoundation::AVFLiveAudio::addSamples
bool addSamples(const SampleType sampleType, const void *data, const size_t size) override
Adds new samples in case this audio object receives the audio data from a buffer/stream.
Ocean::Media::AVFoundation::AVFLiveAudio::audioSessionStarted_
bool audioSessionStarted_
True, if the audio session was started.
Definition:
AVFLiveAudio.h:142
Ocean::Media::AVFoundation::AVFLiveAudio::~AVFLiveAudio
~AVFLiveAudio() override
Destructs the media object.
Ocean::Media::AVFoundation::AVFLiveAudio::AVFLiveAudio
AVFLiveAudio(const std::string &url)
Creates a new medium by a given url.
Ocean::Media::AVFoundation::AVFLiveAudio::avAudioPlayerNode_
AVAudioPlayerNode * avAudioPlayerNode_
The audio player node.
Definition:
AVFLiveAudio.h:121
Ocean::Media::AVFoundation::AVFLiveAudio::avAudioEngine_
AVAudioEngine * avAudioEngine_
The audio engine.
Definition:
AVFLiveAudio.h:118
Ocean::Media::AVFoundation::AVFLiveAudio::soundVolume
float soundVolume() const override
Returns the volume of the sound in db.
Ocean::Media::AVFoundation::AVFLiveAudio::soundMute
bool soundMute() const override
Returns whether the sound medium is in a mute state.
Ocean::Media::AVFoundation::AVFLiveAudio::avAudioConverter_
AVAudioConverter * avAudioConverter_
Optional convert from external audio format to internal audio format.
Definition:
AVFLiveAudio.h:130
Ocean::Media::AVFoundation::AVFLiveAudio::previousVolume_
float previousVolume_
The previous volume before the medium was muted; -1 if the medium is not muted.
Definition:
AVFLiveAudio.h:139
Ocean::Media::AVFoundation::AVFLiveAudio::setSoundMute
bool setSoundMute(const bool mute) override
Sets or un-sets the sound medium to a mute state.
Ocean::Media::AVFoundation::AVFLiveAudio::sendSamplesMono
bool sendSamplesMono(AVAudioPCMBuffer *avAudioPCMBuffer)
Extracts and sends mono samles form a PCM buffer.
Ocean::Media::AVFoundation::AVFLiveAudio::needNewSamples_
std::atomic_bool needNewSamples_
True, if the audio object needs a new samples.
Definition:
AVFLiveAudio.h:145
Ocean::Media::AVFoundation::AVFLiveAudio::setSoundVolume
bool setSoundVolume(const float volume) override
Sets the volume of the sound in db.
Ocean::Media::AVFoundation::AVFLiveAudio::avAudioFormatInternalInt16_
AVAudioFormat * avAudioFormatInternalInt16_
Optional audio format for int16 samples.
Definition:
AVFLiveAudio.h:133
Ocean::Media::AVFoundation::AVFLiveAudio::avAudioMixerNode_
AVAudioMixerNode * avAudioMixerNode_
The audio mixer node e.g., allowing to control the volume.
Definition:
AVFLiveAudio.h:124
Ocean::Media::AVFoundation::AVFLiveAudio::internalPause
bool internalPause() override
Internally pauses the medium.
Ocean::Media::AVFoundation::AVFLiveAudio::internalStop
bool internalStop() override
Internally stops the medium.
Ocean::Media::AVFoundation::AVFLiveAudio::avAudioFormat_
AVAudioFormat * avAudioFormat_
The audio format of the audio player node.
Definition:
AVFLiveAudio.h:127
Ocean::Media::AVFoundation::AVFLiveAudio::internalStart
bool internalStart() override
Internally starts the medium.
Ocean::Media::AVFoundation::AVFMedium
This is the base class for all AVFoundation mediums.
Definition:
AVFMedium.h:36
Ocean::Media::LiveAudio
This class is the base class for all live audios.
Definition:
LiveAudio.h:39
Ocean::Media::LiveAudio::SampleType
SampleType
Definition of individual sample types.
Definition:
LiveAudio.h:46
Ocean::Media::Medium::url
const std::string & url() const
Returns the url of the medium.
Definition:
Medium.h:236
Ocean
The namespace covering the entire Ocean framework.
Definition:
Accessor.h:15
impl
ocean
media
avfoundation
AVFLiveAudio.h
Generated on Wed Nov 13 2024 18:48:16 for Ocean by
1.9.1