Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Suyu
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
many-archive
Suyu
Commits
e01c5351
There was an error fetching the commit references. Please try again later.
Commit
e01c5351
authored
1 year ago
by
Liam
Browse files
Options
Downloads
Patches
Plain Diff
oboe_sink: implement channel count querying
parent
7239547e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/audio_core/sink/oboe_sink.cpp
+35
-12
35 additions, 12 deletions
src/audio_core/sink/oboe_sink.cpp
with
35 additions
and
12 deletions
src/audio_core/sink/oboe_sink.cpp
+
35
−
12
View file @
e01c5351
...
@@ -20,11 +20,10 @@ class OboeSinkStream final : public SinkStream,
...
@@ -20,11 +20,10 @@ class OboeSinkStream final : public SinkStream,
public
oboe
::
AudioStreamErrorCallback
{
public
oboe
::
AudioStreamErrorCallback
{
public:
public:
explicit
OboeSinkStream
(
Core
::
System
&
system_
,
StreamType
type_
,
const
std
::
string
&
name_
,
explicit
OboeSinkStream
(
Core
::
System
&
system_
,
StreamType
type_
,
const
std
::
string
&
name_
,
u32
device_channels_
,
u32
system_channels_
)
u32
system_channels_
)
:
SinkStream
(
system_
,
type_
)
{
:
SinkStream
(
system_
,
type_
)
{
name
=
name_
;
name
=
name_
;
system_channels
=
system_channels_
;
system_channels
=
system_channels_
;
device_channels
=
device_channels_
;
this
->
OpenStream
();
this
->
OpenStream
();
}
}
...
@@ -62,6 +61,21 @@ public:
...
@@ -62,6 +61,21 @@ public:
}
}
}
}
public
:
static
s32
QueryChannelCount
(
oboe
::
Direction
direction
)
{
std
::
shared_ptr
<
oboe
::
AudioStream
>
temp_stream
;
oboe
::
AudioStreamBuilder
builder
;
const
auto
result
=
builder
.
setDirection
(
direction
)
->
setSampleRate
(
TargetSampleRate
)
->
setFormat
(
oboe
::
AudioFormat
::
I16
)
->
setFormatConversionAllowed
(
true
)
->
openStream
(
temp_stream
);
ASSERT
(
result
==
oboe
::
Result
::
OK
);
return
temp_stream
->
getChannelCount
()
>=
6
?
6
:
2
;
}
protected
:
protected
:
oboe
::
DataCallbackResult
onAudioReady
(
oboe
::
AudioStream
*
,
void
*
audio_data
,
oboe
::
DataCallbackResult
onAudioReady
(
oboe
::
AudioStream
*
,
void
*
audio_data
,
s32
num_buffer_frames
)
override
{
s32
num_buffer_frames
)
override
{
...
@@ -105,8 +119,9 @@ private:
...
@@ -105,8 +119,9 @@ private:
}
}
}();
}();
const
auto
channel_mask
=
[
&
]()
{
const
auto
expected_channels
=
QueryChannelCount
(
direction
);
switch
(
device_channels
)
{
const
auto
expected_mask
=
[
&
]()
{
switch
(
expected_channels
)
{
case
1
:
case
1
:
return
oboe
::
ChannelMask
::
Mono
;
return
oboe
::
ChannelMask
::
Mono
;
case
2
:
case
2
:
...
@@ -122,25 +137,33 @@ private:
...
@@ -122,25 +137,33 @@ private:
oboe
::
AudioStreamBuilder
builder
;
oboe
::
AudioStreamBuilder
builder
;
const
auto
result
=
builder
.
setDirection
(
direction
)
const
auto
result
=
builder
.
setDirection
(
direction
)
->
setSampleRate
(
TargetSampleRate
)
->
setSampleRate
(
TargetSampleRate
)
->
setChannelCount
(
device
_channels
)
->
setChannelCount
(
expected
_channels
)
->
setChannelMask
(
channel
_mask
)
->
setChannelMask
(
expected
_mask
)
->
setFormat
(
oboe
::
AudioFormat
::
I16
)
->
setFormat
(
oboe
::
AudioFormat
::
I16
)
->
setFormatConversionAllowed
(
true
)
->
setFormatConversionAllowed
(
true
)
->
setDataCallback
(
this
)
->
setDataCallback
(
this
)
->
setErrorCallback
(
this
)
->
setErrorCallback
(
this
)
->
openStream
(
m_stream
);
->
openStream
(
m_stream
);
ASSERT
(
result
==
oboe
::
Result
::
OK
);
ASSERT
(
result
==
oboe
::
Result
::
OK
);
return
result
==
oboe
::
Result
::
OK
;
return
result
==
oboe
::
Result
::
OK
&&
this
->
SetStreamProperties
();
}
bool
SetStreamProperties
()
{
ASSERT
(
m_stream
);
device_channels
=
m_stream
->
getChannelCount
();
LOG_INFO
(
Audio_Sink
,
"Opened Oboe stream with {} channels"
,
device_channels
);
return
true
;
}
}
std
::
shared_ptr
<
oboe
::
AudioStream
>
m_stream
{};
std
::
shared_ptr
<
oboe
::
AudioStream
>
m_stream
{};
};
};
OboeSink
::
OboeSink
()
{
OboeSink
::
OboeSink
()
{
// TODO:
how do we get the number of channels, or device list?
// TODO:
This is not generally knowable
// Th
is seems to be missing from NDK.
// Th
e channel count is distinct based on direction and can change
device_channels
=
2
;
device_channels
=
OboeSinkStream
::
QueryChannelCount
(
oboe
::
Direction
::
Output
)
;
}
}
OboeSink
::~
OboeSink
()
=
default
;
OboeSink
::~
OboeSink
()
=
default
;
...
@@ -148,7 +171,7 @@ OboeSink::~OboeSink() = default;
...
@@ -148,7 +171,7 @@ OboeSink::~OboeSink() = default;
SinkStream
*
OboeSink
::
AcquireSinkStream
(
Core
::
System
&
system
,
u32
system_channels
,
SinkStream
*
OboeSink
::
AcquireSinkStream
(
Core
::
System
&
system
,
u32
system_channels
,
const
std
::
string
&
name
,
StreamType
type
)
{
const
std
::
string
&
name
,
StreamType
type
)
{
SinkStreamPtr
&
stream
=
sink_streams
.
emplace_back
(
SinkStreamPtr
&
stream
=
sink_streams
.
emplace_back
(
std
::
make_unique
<
OboeSinkStream
>
(
system
,
type
,
name
,
device_channels
,
system_channels
));
std
::
make_unique
<
OboeSinkStream
>
(
system
,
type
,
name
,
system_channels
));
return
stream
.
get
();
return
stream
.
get
();
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment