Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
985ca094
Commit
985ca094
authored
Feb 26, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
osx: no CamelCase
Renamed types, functions, variables.
parent
a7b0cfcc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
89 deletions
+85
-89
osx_plugin.c
src/output/osx_plugin.c
+85
-89
No files found.
src/output/osx_plugin.c
View file @
985ca094
...
@@ -24,34 +24,19 @@
...
@@ -24,34 +24,19 @@
#undef G_LOG_DOMAIN
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "osx"
#define G_LOG_DOMAIN "osx"
typedef
struct
_OsxData
{
struct
osx_output
{
AudioUnit
au
;
AudioUnit
au
;
GMutex
*
mutex
;
GMutex
*
mutex
;
GCond
*
condition
;
GCond
*
condition
;
char
*
buffer
;
char
*
buffer
;
size_t
buffer
S
ize
;
size_t
buffer
_s
ize
;
size_t
pos
;
size_t
pos
;
size_t
len
;
size_t
len
;
int
started
;
int
started
;
}
OsxData
;
};
static
OsxData
*
newOsxData
(
void
)
{
OsxData
*
ret
=
g_new
(
OsxData
,
1
);
ret
->
mutex
=
g_mutex_new
();
ret
->
condition
=
g_cond_new
();
ret
->
pos
=
0
;
ret
->
len
=
0
;
ret
->
started
=
0
;
ret
->
buffer
=
NULL
;
ret
->
bufferSize
=
0
;
return
ret
;
}
static
bool
osx_testDefault
(
void
)
static
bool
osx_output_test_default_device
(
void
)
{
{
/*AudioUnit au;
/*AudioUnit au;
ComponentDescription desc;
ComponentDescription desc;
...
@@ -80,38 +65,45 @@ static bool osx_testDefault(void)
...
@@ -80,38 +65,45 @@ static bool osx_testDefault(void)
}
}
static
void
*
static
void
*
osx_
initDriver
(
G_GNUC_UNUSED
const
struct
audio_format
*
audio_format
,
osx_
output_init
(
G_GNUC_UNUSED
const
struct
audio_format
*
audio_format
,
G_GNUC_UNUSED
const
struct
config_param
*
param
)
G_GNUC_UNUSED
const
struct
config_param
*
param
)
{
{
return
newOsxData
();
struct
osx_output
*
oo
=
g_new
(
struct
osx_output
,
1
);
oo
->
mutex
=
g_mutex_new
();
oo
->
condition
=
g_cond_new
();
oo
->
pos
=
0
;
oo
->
len
=
0
;
oo
->
started
=
0
;
oo
->
buffer
=
NULL
;
oo
->
buffer_size
=
0
;
return
oo
;
}
}
static
void
freeOsxData
(
OsxData
*
od
)
static
void
osx_output_finish
(
void
*
data
)
{
{
struct
osx_output
*
od
=
data
;
g_free
(
od
->
buffer
);
g_free
(
od
->
buffer
);
g_mutex_free
(
od
->
mutex
);
g_mutex_free
(
od
->
mutex
);
g_cond_free
(
od
->
condition
);
g_cond_free
(
od
->
condition
);
g_free
(
od
);
g_free
(
od
);
}
}
static
void
osx_finishDriver
(
void
*
data
)
static
void
osx_output_cancel
(
void
*
data
)
{
OsxData
*
od
=
data
;
freeOsxData
(
od
);
}
static
void
osx_dropBufferedAudio
(
void
*
data
)
{
{
OsxData
*
od
=
data
;
struct
osx_output
*
od
=
data
;
g_mutex_lock
(
od
->
mutex
);
g_mutex_lock
(
od
->
mutex
);
od
->
len
=
0
;
od
->
len
=
0
;
g_mutex_unlock
(
od
->
mutex
);
g_mutex_unlock
(
od
->
mutex
);
}
}
static
void
osx_
closeDevic
e
(
void
*
data
)
static
void
osx_
output_clos
e
(
void
*
data
)
{
{
OsxData
*
od
=
data
;
struct
osx_output
*
od
=
data
;
g_mutex_lock
(
od
->
mutex
);
g_mutex_lock
(
od
->
mutex
);
while
(
od
->
len
)
{
while
(
od
->
len
)
{
...
@@ -130,45 +122,47 @@ static void osx_closeDevice(void *data)
...
@@ -130,45 +122,47 @@ static void osx_closeDevice(void *data)
static
OSStatus
static
OSStatus
osx_render
(
void
*
vdata
,
osx_render
(
void
*
vdata
,
G_GNUC_UNUSED
AudioUnitRenderActionFlags
*
ioActionF
lags
,
G_GNUC_UNUSED
AudioUnitRenderActionFlags
*
io_action_f
lags
,
G_GNUC_UNUSED
const
AudioTimeStamp
*
inTimeS
tamp
,
G_GNUC_UNUSED
const
AudioTimeStamp
*
in_times
tamp
,
G_GNUC_UNUSED
UInt32
in
BusN
umber
,
G_GNUC_UNUSED
UInt32
in
_bus_n
umber
,
G_GNUC_UNUSED
UInt32
in
NumberF
rames
,
G_GNUC_UNUSED
UInt32
in
_number_f
rames
,
AudioBufferList
*
bufferL
ist
)
AudioBufferList
*
buffer_l
ist
)
{
{
OsxData
*
od
=
(
OsxData
*
)
vdata
;
struct
osx_output
*
od
=
(
struct
osx_output
*
)
vdata
;
AudioBuffer
*
buffer
=
&
buffer
L
ist
->
mBuffers
[
0
];
AudioBuffer
*
buffer
=
&
buffer
_l
ist
->
mBuffers
[
0
];
size_t
buffer
S
ize
=
buffer
->
mDataByteSize
;
size_t
buffer
_s
ize
=
buffer
->
mDataByteSize
;
size_t
bytes
ToC
opy
;
size_t
bytes
_to_c
opy
;
size_t
bytes
;
size_t
trailer_length
;
int
cur
pos
=
0
;
size_t
dest_
pos
=
0
;
g_mutex_lock
(
od
->
mutex
);
g_mutex_lock
(
od
->
mutex
);
bytes
ToCopy
=
MIN
(
od
->
len
,
bufferS
ize
);
bytes
_to_copy
=
MIN
(
od
->
len
,
buffer_s
ize
);
buffer
Size
=
bytesToC
opy
;
buffer
_size
=
bytes_to_c
opy
;
od
->
len
-=
bytes
ToC
opy
;
od
->
len
-=
bytes
_to_c
opy
;
bytes
=
od
->
bufferSize
-
od
->
pos
;
trailer_length
=
od
->
buffer_size
-
od
->
pos
;
if
(
bytesToCopy
>
bytes
)
{
if
(
bytes_to_copy
>
trailer_length
)
{
memcpy
((
unsigned
char
*
)
buffer
->
mData
+
curpos
,
od
->
buffer
+
od
->
pos
,
bytes
);
memcpy
((
unsigned
char
*
)
buffer
->
mData
+
dest_pos
,
od
->
buffer
+
od
->
pos
,
trailer_length
);
od
->
pos
=
0
;
od
->
pos
=
0
;
curpos
+=
bytes
;
dest_pos
+=
trailer_length
;
bytes
ToCopy
-=
bytes
;
bytes
_to_copy
-=
trailer_length
;
}
}
memcpy
((
unsigned
char
*
)
buffer
->
mData
+
curpos
,
od
->
buffer
+
od
->
pos
,
bytesToCopy
);
memcpy
((
unsigned
char
*
)
buffer
->
mData
+
dest_pos
,
od
->
pos
+=
bytesToCopy
;
od
->
buffer
+
od
->
pos
,
bytes_to_copy
);
od
->
pos
+=
bytes_to_copy
;
if
(
od
->
pos
>=
od
->
buffer
S
ize
)
if
(
od
->
pos
>=
od
->
buffer
_s
ize
)
od
->
pos
=
0
;
od
->
pos
=
0
;
g_mutex_unlock
(
od
->
mutex
);
g_mutex_unlock
(
od
->
mutex
);
g_cond_signal
(
od
->
condition
);
g_cond_signal
(
od
->
condition
);
buffer
->
mDataByteSize
=
buffer
S
ize
;
buffer
->
mDataByteSize
=
buffer
_s
ize
;
if
(
!
buffer
S
ize
)
{
if
(
!
buffer
_s
ize
)
{
g_usleep
(
1000
);
g_usleep
(
1000
);
}
}
...
@@ -176,16 +170,16 @@ osx_render(void *vdata,
...
@@ -176,16 +170,16 @@ osx_render(void *vdata,
}
}
static
bool
static
bool
osx_o
penDevice
(
void
*
data
,
struct
audio_format
*
audioF
ormat
)
osx_o
utput_open
(
void
*
data
,
struct
audio_format
*
audio_f
ormat
)
{
{
OsxData
*
od
=
data
;
struct
osx_output
*
od
=
data
;
ComponentDescription
desc
;
ComponentDescription
desc
;
Component
comp
;
Component
comp
;
AURenderCallbackStruct
callback
;
AURenderCallbackStruct
callback
;
AudioStreamBasicDescription
stream
Desc
;
AudioStreamBasicDescription
stream
_description
;
if
(
audio
F
ormat
->
bits
>
16
)
if
(
audio
_f
ormat
->
bits
>
16
)
audio
F
ormat
->
bits
=
16
;
audio
_f
ormat
->
bits
=
16
;
desc
.
componentType
=
kAudioUnitType_Output
;
desc
.
componentType
=
kAudioUnitType_Output
;
desc
.
componentSubType
=
kAudioUnitSubType_DefaultOutput
;
desc
.
componentSubType
=
kAudioUnitSubType_DefaultOutput
;
...
@@ -222,22 +216,24 @@ osx_openDevice(void *data, struct audio_format *audioFormat)
...
@@ -222,22 +216,24 @@ osx_openDevice(void *data, struct audio_format *audioFormat)
return
false
;
return
false
;
}
}
stream
Desc
.
mSampleRate
=
audioF
ormat
->
sample_rate
;
stream
_description
.
mSampleRate
=
audio_f
ormat
->
sample_rate
;
stream
Desc
.
mFormatID
=
kAudioFormatLinearPCM
;
stream
_description
.
mFormatID
=
kAudioFormatLinearPCM
;
stream
Desc
.
mFormatFlags
=
kLinearPCMFormatFlagIsSignedInteger
;
stream
_description
.
mFormatFlags
=
kLinearPCMFormatFlagIsSignedInteger
;
#if G_BYTE_ORDER == G_BIG_ENDIAN
#if G_BYTE_ORDER == G_BIG_ENDIAN
stream
Desc
.
mFormatFlags
|=
kLinearPCMFormatFlagIsBigEndian
;
stream
_description
.
mFormatFlags
|=
kLinearPCMFormatFlagIsBigEndian
;
#endif
#endif
streamDesc
.
mBytesPerPacket
=
audio_format_frame_size
(
audioFormat
);
stream_description
.
mBytesPerPacket
=
streamDesc
.
mFramesPerPacket
=
1
;
audio_format_frame_size
(
audio_format
);
streamDesc
.
mBytesPerFrame
=
streamDesc
.
mBytesPerPacket
;
stream_description
.
mFramesPerPacket
=
1
;
streamDesc
.
mChannelsPerFrame
=
audioFormat
->
channels
;
stream_description
.
mBytesPerFrame
=
stream_description
.
mBytesPerPacket
;
streamDesc
.
mBitsPerChannel
=
audioFormat
->
bits
;
stream_description
.
mChannelsPerFrame
=
audio_format
->
channels
;
stream_description
.
mBitsPerChannel
=
audio_format
->
bits
;
if
(
AudioUnitSetProperty
(
od
->
au
,
kAudioUnitProperty_StreamFormat
,
if
(
AudioUnitSetProperty
(
od
->
au
,
kAudioUnitProperty_StreamFormat
,
kAudioUnitScope_Input
,
0
,
kAudioUnitScope_Input
,
0
,
&
streamDesc
,
sizeof
(
streamDesc
))
!=
0
)
{
&
stream_description
,
sizeof
(
stream_description
))
!=
0
)
{
AudioUnitUninitialize
(
od
->
au
);
AudioUnitUninitialize
(
od
->
au
);
CloseComponent
(
od
->
au
);
CloseComponent
(
od
->
au
);
g_warning
(
"Unable to set format on OS X device
\n
"
);
g_warning
(
"Unable to set format on OS X device
\n
"
);
...
@@ -245,9 +241,9 @@ osx_openDevice(void *data, struct audio_format *audioFormat)
...
@@ -245,9 +241,9 @@ osx_openDevice(void *data, struct audio_format *audioFormat)
}
}
/* create a buffer of 1s */
/* create a buffer of 1s */
od
->
buffer
Size
=
(
audioF
ormat
->
sample_rate
)
*
od
->
buffer
_size
=
(
audio_f
ormat
->
sample_rate
)
*
audio_format_frame_size
(
audio
F
ormat
);
audio_format_frame_size
(
audio
_f
ormat
);
od
->
buffer
=
g_realloc
(
od
->
buffer
,
od
->
buffer
S
ize
);
od
->
buffer
=
g_realloc
(
od
->
buffer
,
od
->
buffer
_s
ize
);
od
->
pos
=
0
;
od
->
pos
=
0
;
od
->
len
=
0
;
od
->
len
=
0
;
...
@@ -256,9 +252,9 @@ osx_openDevice(void *data, struct audio_format *audioFormat)
...
@@ -256,9 +252,9 @@ osx_openDevice(void *data, struct audio_format *audioFormat)
}
}
static
size_t
static
size_t
osx_play
(
void
*
data
,
const
void
*
chunk
,
size_t
size
)
osx_
output_
play
(
void
*
data
,
const
void
*
chunk
,
size_t
size
)
{
{
OsxData
*
od
=
data
;
struct
osx_output
*
od
=
data
;
size_t
start
,
nbytes
;
size_t
start
,
nbytes
;
if
(
!
od
->
started
)
{
if
(
!
od
->
started
)
{
...
@@ -273,17 +269,17 @@ osx_play(void *data, const void *chunk, size_t size)
...
@@ -273,17 +269,17 @@ osx_play(void *data, const void *chunk, size_t size)
g_mutex_lock
(
od
->
mutex
);
g_mutex_lock
(
od
->
mutex
);
while
(
od
->
len
>=
od
->
buffer
S
ize
)
while
(
od
->
len
>=
od
->
buffer
_s
ize
)
/* wait for some free space in the buffer */
/* wait for some free space in the buffer */
g_cond_wait
(
od
->
condition
,
od
->
mutex
);
g_cond_wait
(
od
->
condition
,
od
->
mutex
);
start
=
od
->
pos
+
od
->
len
;
start
=
od
->
pos
+
od
->
len
;
if
(
start
>=
od
->
buffer
S
ize
)
if
(
start
>=
od
->
buffer
_s
ize
)
start
-=
od
->
buffer
S
ize
;
start
-=
od
->
buffer
_s
ize
;
nbytes
=
start
<
od
->
pos
nbytes
=
start
<
od
->
pos
?
od
->
pos
-
start
?
od
->
pos
-
start
:
od
->
buffer
S
ize
-
start
;
:
od
->
buffer
_s
ize
-
start
;
assert
(
nbytes
>
0
);
assert
(
nbytes
>
0
);
...
@@ -300,11 +296,11 @@ osx_play(void *data, const void *chunk, size_t size)
...
@@ -300,11 +296,11 @@ osx_play(void *data, const void *chunk, size_t size)
const
struct
audio_output_plugin
osxPlugin
=
{
const
struct
audio_output_plugin
osxPlugin
=
{
.
name
=
"osx"
,
.
name
=
"osx"
,
.
test_default_device
=
osx_
testDefault
,
.
test_default_device
=
osx_
output_test_default_device
,
.
init
=
osx_
initDriver
,
.
init
=
osx_
output_init
,
.
finish
=
osx_
finishDriver
,
.
finish
=
osx_
output_finish
,
.
open
=
osx_o
penDevice
,
.
open
=
osx_o
utput_open
,
.
play
=
osx_play
,
.
close
=
osx_output_close
,
.
cancel
=
osx_dropBufferedAudio
,
.
play
=
osx_output_play
,
.
c
lose
=
osx_closeDevice
,
.
c
ancel
=
osx_output_cancel
,
};
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment