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 @@
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "osx"
typedef
struct
_OsxData
{
struct
osx_output
{
AudioUnit
au
;
GMutex
*
mutex
;
GCond
*
condition
;
char
*
buffer
;
size_t
buffer
S
ize
;
size_t
buffer
_s
ize
;
size_t
pos
;
size_t
len
;
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;
ComponentDescription desc;
...
...
@@ -80,38 +65,45 @@ static bool osx_testDefault(void)
}
static
void
*
osx_
initDriver
(
G_GNUC_UNUSED
const
struct
audio_format
*
audio_format
,
G_GNUC_UNUSED
const
struct
config_param
*
param
)
osx_
output_init
(
G_GNUC_UNUSED
const
struct
audio_format
*
audio_format
,
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_mutex_free
(
od
->
mutex
);
g_cond_free
(
od
->
condition
);
g_free
(
od
);
}
static
void
osx_finishDriver
(
void
*
data
)
{
OsxData
*
od
=
data
;
freeOsxData
(
od
);
}
static
void
osx_dropBufferedAudio
(
void
*
data
)
static
void
osx_output_cancel
(
void
*
data
)
{
OsxData
*
od
=
data
;
struct
osx_output
*
od
=
data
;
g_mutex_lock
(
od
->
mutex
);
od
->
len
=
0
;
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
);
while
(
od
->
len
)
{
...
...
@@ -130,45 +122,47 @@ static void osx_closeDevice(void *data)
static
OSStatus
osx_render
(
void
*
vdata
,
G_GNUC_UNUSED
AudioUnitRenderActionFlags
*
ioActionF
lags
,
G_GNUC_UNUSED
const
AudioTimeStamp
*
inTimeS
tamp
,
G_GNUC_UNUSED
UInt32
in
BusN
umber
,
G_GNUC_UNUSED
UInt32
in
NumberF
rames
,
AudioBufferList
*
bufferL
ist
)
G_GNUC_UNUSED
AudioUnitRenderActionFlags
*
io_action_f
lags
,
G_GNUC_UNUSED
const
AudioTimeStamp
*
in_times
tamp
,
G_GNUC_UNUSED
UInt32
in
_bus_n
umber
,
G_GNUC_UNUSED
UInt32
in
_number_f
rames
,
AudioBufferList
*
buffer_l
ist
)
{
OsxData
*
od
=
(
OsxData
*
)
vdata
;
AudioBuffer
*
buffer
=
&
buffer
L
ist
->
mBuffers
[
0
];
size_t
buffer
S
ize
=
buffer
->
mDataByteSize
;
size_t
bytes
ToC
opy
;
size_t
bytes
;
int
cur
pos
=
0
;
struct
osx_output
*
od
=
(
struct
osx_output
*
)
vdata
;
AudioBuffer
*
buffer
=
&
buffer
_l
ist
->
mBuffers
[
0
];
size_t
buffer
_s
ize
=
buffer
->
mDataByteSize
;
size_t
bytes
_to_c
opy
;
size_t
trailer_length
;
size_t
dest_
pos
=
0
;
g_mutex_lock
(
od
->
mutex
);
bytes
ToCopy
=
MIN
(
od
->
len
,
bufferS
ize
);
buffer
Size
=
bytesToC
opy
;
od
->
len
-=
bytes
ToC
opy
;
bytes
_to_copy
=
MIN
(
od
->
len
,
buffer_s
ize
);
buffer
_size
=
bytes_to_c
opy
;
od
->
len
-=
bytes
_to_c
opy
;
bytes
=
od
->
bufferSize
-
od
->
pos
;
if
(
bytesToCopy
>
bytes
)
{
memcpy
((
unsigned
char
*
)
buffer
->
mData
+
curpos
,
od
->
buffer
+
od
->
pos
,
bytes
);
trailer_length
=
od
->
buffer_size
-
od
->
pos
;
if
(
bytes_to_copy
>
trailer_length
)
{
memcpy
((
unsigned
char
*
)
buffer
->
mData
+
dest_pos
,
od
->
buffer
+
od
->
pos
,
trailer_length
);
od
->
pos
=
0
;
curpos
+=
bytes
;
bytes
ToCopy
-=
bytes
;
dest_pos
+=
trailer_length
;
bytes
_to_copy
-=
trailer_length
;
}
memcpy
((
unsigned
char
*
)
buffer
->
mData
+
curpos
,
od
->
buffer
+
od
->
pos
,
bytesToCopy
);
od
->
pos
+=
bytesToCopy
;
memcpy
((
unsigned
char
*
)
buffer
->
mData
+
dest_pos
,
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
;
g_mutex_unlock
(
od
->
mutex
);
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
);
}
...
...
@@ -176,16 +170,16 @@ osx_render(void *vdata,
}
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
;
Component
comp
;
AURenderCallbackStruct
callback
;
AudioStreamBasicDescription
stream
Desc
;
AudioStreamBasicDescription
stream
_description
;
if
(
audio
F
ormat
->
bits
>
16
)
audio
F
ormat
->
bits
=
16
;
if
(
audio
_f
ormat
->
bits
>
16
)
audio
_f
ormat
->
bits
=
16
;
desc
.
componentType
=
kAudioUnitType_Output
;
desc
.
componentSubType
=
kAudioUnitSubType_DefaultOutput
;
...
...
@@ -222,22 +216,24 @@ osx_openDevice(void *data, struct audio_format *audioFormat)
return
false
;
}
stream
Desc
.
mSampleRate
=
audioF
ormat
->
sample_rate
;
stream
Desc
.
mFormatID
=
kAudioFormatLinearPCM
;
stream
Desc
.
mFormatFlags
=
kLinearPCMFormatFlagIsSignedInteger
;
stream
_description
.
mSampleRate
=
audio_f
ormat
->
sample_rate
;
stream
_description
.
mFormatID
=
kAudioFormatLinearPCM
;
stream
_description
.
mFormatFlags
=
kLinearPCMFormatFlagIsSignedInteger
;
#if G_BYTE_ORDER == G_BIG_ENDIAN
stream
Desc
.
mFormatFlags
|=
kLinearPCMFormatFlagIsBigEndian
;
stream
_description
.
mFormatFlags
|=
kLinearPCMFormatFlagIsBigEndian
;
#endif
streamDesc
.
mBytesPerPacket
=
audio_format_frame_size
(
audioFormat
);
streamDesc
.
mFramesPerPacket
=
1
;
streamDesc
.
mBytesPerFrame
=
streamDesc
.
mBytesPerPacket
;
streamDesc
.
mChannelsPerFrame
=
audioFormat
->
channels
;
streamDesc
.
mBitsPerChannel
=
audioFormat
->
bits
;
stream_description
.
mBytesPerPacket
=
audio_format_frame_size
(
audio_format
);
stream_description
.
mFramesPerPacket
=
1
;
stream_description
.
mBytesPerFrame
=
stream_description
.
mBytesPerPacket
;
stream_description
.
mChannelsPerFrame
=
audio_format
->
channels
;
stream_description
.
mBitsPerChannel
=
audio_format
->
bits
;
if
(
AudioUnitSetProperty
(
od
->
au
,
kAudioUnitProperty_StreamFormat
,
kAudioUnitScope_Input
,
0
,
&
streamDesc
,
sizeof
(
streamDesc
))
!=
0
)
{
&
stream_description
,
sizeof
(
stream_description
))
!=
0
)
{
AudioUnitUninitialize
(
od
->
au
);
CloseComponent
(
od
->
au
);
g_warning
(
"Unable to set format on OS X device
\n
"
);
...
...
@@ -245,9 +241,9 @@ osx_openDevice(void *data, struct audio_format *audioFormat)
}
/* create a buffer of 1s */
od
->
buffer
Size
=
(
audioF
ormat
->
sample_rate
)
*
audio_format_frame_size
(
audio
F
ormat
);
od
->
buffer
=
g_realloc
(
od
->
buffer
,
od
->
buffer
S
ize
);
od
->
buffer
_size
=
(
audio_f
ormat
->
sample_rate
)
*
audio_format_frame_size
(
audio
_f
ormat
);
od
->
buffer
=
g_realloc
(
od
->
buffer
,
od
->
buffer
_s
ize
);
od
->
pos
=
0
;
od
->
len
=
0
;
...
...
@@ -256,9 +252,9 @@ osx_openDevice(void *data, struct audio_format *audioFormat)
}
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
;
if
(
!
od
->
started
)
{
...
...
@@ -273,17 +269,17 @@ osx_play(void *data, const void *chunk, size_t size)
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 */
g_cond_wait
(
od
->
condition
,
od
->
mutex
);
start
=
od
->
pos
+
od
->
len
;
if
(
start
>=
od
->
buffer
S
ize
)
start
-=
od
->
buffer
S
ize
;
if
(
start
>=
od
->
buffer
_s
ize
)
start
-=
od
->
buffer
_s
ize
;
nbytes
=
start
<
od
->
pos
?
od
->
pos
-
start
:
od
->
buffer
S
ize
-
start
;
:
od
->
buffer
_s
ize
-
start
;
assert
(
nbytes
>
0
);
...
...
@@ -300,11 +296,11 @@ osx_play(void *data, const void *chunk, size_t size)
const
struct
audio_output_plugin
osxPlugin
=
{
.
name
=
"osx"
,
.
test_default_device
=
osx_
testDefault
,
.
init
=
osx_
initDriver
,
.
finish
=
osx_
finishDriver
,
.
open
=
osx_o
penDevice
,
.
play
=
osx_play
,
.
cancel
=
osx_dropBufferedAudio
,
.
c
lose
=
osx_closeDevice
,
.
test_default_device
=
osx_
output_test_default_device
,
.
init
=
osx_
output_init
,
.
finish
=
osx_
output_finish
,
.
open
=
osx_o
utput_open
,
.
close
=
osx_output_close
,
.
play
=
osx_output_play
,
.
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