Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-2-2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc-2-2
Commits
d87ff6d8
Commit
d87ff6d8
authored
Feb 04, 2013
by
Felix Paul Kühne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
audioqueue: clean-up
parent
08ec4920
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
105 additions
and
105 deletions
+105
-105
modules/audio_output/audioqueue.c
modules/audio_output/audioqueue.c
+105
-105
No files found.
modules/audio_output/audioqueue.c
View file @
d87ff6d8
...
...
@@ -26,20 +26,19 @@
* Preamble
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# i
nclude
"config.h"
# i
mport
"config.h"
#endif
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_aout.h>
#include <AudioToolBox/AudioToolBox.h>
#import <vlc_common.h>
#import <vlc_plugin.h>
#import <vlc_aout.h>
#import <AudioToolBox/AudioQueue.h>
/*****************************************************************************
* aout_sys_t:
AudioQueu
e audio output method descriptor
* aout_sys_t:
privat
e audio output method descriptor
*****************************************************************************
* This structure is part of the audio output thread descriptor.
* It describes the
specific properties of an audio device
.
* It describes the
AudioQueue specific properties of an output thread
.
*****************************************************************************/
struct
aout_sys_t
{
...
...
@@ -55,13 +54,17 @@ struct aout_sys_t
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static
int
Open
(
vlc_object_t
*
);
static
void
Close
(
vlc_object_t
*
);
static
void
Play
(
audio_output_t
*
,
block_t
*
);
static
void
Pause
(
audio_output_t
*
p_aout
,
bool
pause
,
mtime_t
date
);
static
void
Flush
(
audio_output_t
*
p_aout
,
bool
wait
);
static
int
TimeGet
(
audio_output_t
*
aout
,
mtime_t
*
);
static
void
AudioQueueCallback
(
void
*
,
AudioQueueRef
,
AudioQueueBufferRef
);
static
int
Open
(
vlc_object_t
*
);
static
void
Close
(
vlc_object_t
*
);
static
void
Play
(
audio_output_t
*
,
block_t
*
);
static
void
Pause
(
audio_output_t
*
p_aout
,
bool
pause
,
mtime_t
date
);
static
void
Flush
(
audio_output_t
*
p_aout
,
bool
wait
);
static
int
TimeGet
(
audio_output_t
*
aout
,
mtime_t
*
);
static
void
UnusedAudioQueueCallback
(
void
*
,
AudioQueueRef
,
AudioQueueBufferRef
);
static
int
Start
(
audio_output_t
*
,
audio_sample_format_t
*
);
static
void
Stop
(
audio_output_t
*
);
static
int
VolumeSet
(
audio_output_t
*
,
float
);
/*****************************************************************************
* Module descriptor
...
...
@@ -76,6 +79,52 @@ add_shortcut("audioqueue")
set_callbacks
(
Open
,
Close
)
vlc_module_end
()
/*****************************************************************************
* Module management
*****************************************************************************/
static
int
Open
(
vlc_object_t
*
obj
)
{
audio_output_t
*
aout
=
(
audio_output_t
*
)
obj
;
aout_sys_t
*
sys
=
malloc
(
sizeof
(
*
sys
));
if
(
unlikely
(
sys
==
NULL
))
return
VLC_ENOMEM
;
aout
->
sys
=
sys
;
aout
->
start
=
Start
;
aout
->
stop
=
Stop
;
aout
->
volume_set
=
VolumeSet
;
/* reset volume */
aout_VolumeReport
(
aout
,
1
.
0
);
return
VLC_SUCCESS
;
}
static
void
Close
(
vlc_object_t
*
obj
)
{
audio_output_t
*
aout
=
(
audio_output_t
*
)
obj
;
msg_Dbg
(
aout
,
"audioqueue: Close"
);
aout_sys_t
*
sys
=
aout
->
sys
;
free
(
sys
);
}
static
int
VolumeSet
(
audio_output_t
*
p_aout
,
float
volume
)
{
struct
aout_sys_t
*
p_sys
=
p_aout
->
sys
;
OSStatus
ostatus
;
aout_VolumeReport
(
p_aout
,
volume
);
p_sys
->
f_volume
=
volume
;
/* Set volume for output unit */
ostatus
=
AudioQueueSetParameter
(
p_sys
->
audioQueue
,
kAudioQueueParam_Volume
,
volume
*
volume
*
volume
);
return
ostatus
;
}
/*****************************************************************************
* Start: open the audio device
*****************************************************************************/
...
...
@@ -83,30 +132,30 @@ vlc_module_end ()
static
int
Start
(
audio_output_t
*
p_aout
,
audio_sample_format_t
*
restrict
fmt
)
{
aout_sys_t
*
p_sys
=
p_aout
->
sys
;
OSStatus
status
=
0
;
//
Setup the audio device.
AudioStreamBasicDescription
deviceFormat
;
deviceFormat
.
mSampleRate
=
fmt
->
i_rate
;
deviceFormat
.
mFormatID
=
kAudioFormatLinearPCM
;
deviceFormat
.
mFormatFlags
=
kAudioFormatFlagsNativeFloatPacked
;
// FL32
deviceFormat
.
mFramesPerPacket
=
1
;
deviceFormat
.
mChannelsPerFrame
=
2
;
deviceFormat
.
mBitsPerChannel
=
32
;
deviceFormat
.
mBytesPerFrame
=
deviceFormat
.
mBitsPerChannel
*
deviceFormat
.
mChannelsPerFrame
/
8
;
deviceFormat
.
mBytesPerPacket
=
deviceFormat
.
mBytesPerFrame
*
deviceFormat
.
mFramesPerPacket
;
//
Create a new output AudioQueue for the device.
status
=
AudioQueueNewOutput
(
&
deviceFormat
,
// Format
AudioQueueCallback
,
// Callback
NULL
,
// User data, passed to the callback
NULL
,
// RunLoop
kCFRunLoopCommonModes
,
// RunLoop mode
0
,
// Flags ; must be zero (per documentation)...
&
(
p_sys
->
audioQueue
));
// Output
msg_Dbg
(
p_aout
,
"New AudioQueue output created (status = %li)"
,
status
);
if
(
status
!=
noErr
)
OSStatus
error
=
0
;
//
prepare the format description for our output
AudioStreamBasicDescription
streamDescription
;
streamDescription
.
mSampleRate
=
fmt
->
i_rate
;
streamDescription
.
mFormatID
=
kAudioFormatLinearPCM
;
streamDescription
.
mFormatFlags
=
kAudioFormatFlagsNativeFloatPacked
;
// FL32
streamDescription
.
mFramesPerPacket
=
1
;
streamDescription
.
mChannelsPerFrame
=
2
;
streamDescription
.
mBitsPerChannel
=
32
;
streamDescription
.
mBytesPerFrame
=
streamDescription
.
mBitsPerChannel
*
streamDescription
.
mChannelsPerFrame
/
8
;
streamDescription
.
mBytesPerPacket
=
streamDescription
.
mBytesPerFrame
*
streamDescription
.
mFramesPerPacket
;
//
init new output instance
error
=
AudioQueueNewOutput
(
&
streamDescription
,
// Format
UnusedAudioQueueCallback
,
// Unused Callback, which needs to be provided to have a proper instance
NULL
,
// User data, passed to the callback
NULL
,
// RunLoop
kCFRunLoopCommonModes
,
// RunLoop mode
0
,
// Flags ; must be zero (per documentation)...
&
(
p_sys
->
audioQueue
));
// Output
msg_Dbg
(
p_aout
,
"New AudioQueue output created (status = %li)"
,
error
);
if
(
error
!=
noErr
)
return
VLC_EGENERIC
;
fmt
->
i_format
=
VLC_CODEC_FL32
;
...
...
@@ -116,20 +165,22 @@ static int Start(audio_output_t *p_aout, audio_sample_format_t *restrict fmt)
p_aout
->
sys
->
b_stopped
=
false
;
p_aout
->
sys
->
i_rate
=
fmt
->
i_rate
;
status
=
AudioQueueStart
(
p_sys
->
audioQueue
,
NULL
);
msg_Dbg
(
p_aout
,
"Starting AudioQueue (status = %li)"
,
status
);
// start queue
error
=
AudioQueueStart
(
p_sys
->
audioQueue
,
NULL
);
msg_Dbg
(
p_aout
,
"Starting AudioQueue (status = %li)"
,
error
);
// start timeline for synchro
error
=
AudioQueueCreateTimeline
(
p_sys
->
audioQueue
,
&
p_sys
->
outTimeline
);
msg_Dbg
(
p_aout
,
"AudioQueue Timeline started (status = %li)"
,
error
);
status
=
AudioQueueCreateTimeline
(
p_sys
->
audioQueue
,
&
p_sys
->
outTimeline
);
msg_Dbg
(
p_aout
,
"AudioQueue Timeline started (status = %li)"
,
status
)
;
if
(
error
!=
noErr
)
return
VLC_EGENERIC
;
p_aout
->
time_get
=
TimeGet
;
p_aout
->
play
=
Play
;
p_aout
->
pause
=
Pause
;
p_aout
->
flush
=
Flush
;
if
(
status
!=
noErr
)
return
VLC_EGENERIC
;
return
VLC_SUCCESS
;
}
...
...
@@ -137,24 +188,23 @@ static int Start(audio_output_t *p_aout, audio_sample_format_t *restrict fmt)
* Stop: close the audio device
*****************************************************************************/
static
void
Stop
(
audio_output_t
*
p_aout
)
static
void
Stop
(
audio_output_t
*
p_aout
)
{
p_aout
->
sys
->
b_stopped
=
true
;
p_aout
->
sys
->
i_played_length
=
0
;
msg_Dbg
(
p_aout
,
"Stopping AudioQueue timeline"
);
AudioQueueDisposeTimeline
(
p_aout
->
sys
->
audioQueue
,
p_aout
->
sys
->
outTimeline
);
msg_Dbg
(
p_aout
,
"Stopping AudioQueue"
);
AudioQueueStop
(
p_aout
->
sys
->
audioQueue
,
true
);
msg_Dbg
(
p_aout
,
"Disposing AudioQueue"
);
AudioQueueDispose
(
p_aout
->
sys
->
audioQueue
,
true
);
msg_Dbg
(
p_aout
,
"audioqueue stopped and disposed"
);
}
/*****************************************************************************
* actual playback
*****************************************************************************/
static
void
Play
(
audio_output_t
*
p_aout
,
block_t
*
p_block
)
static
void
Play
(
audio_output_t
*
p_aout
,
block_t
*
p_block
)
{
AudioQueueBufferRef
inBuffer
=
NULL
;
OSStatus
status
;
...
...
@@ -177,7 +227,7 @@ static void Play (audio_output_t *p_aout, block_t *p_block)
block_Release
(
p_block
);
}
void
AudioQueueCallback
(
void
*
inUserData
,
AudioQueueRef
inAQ
,
AudioQueueBufferRef
inBuffer
)
{
void
Unused
AudioQueueCallback
(
void
*
inUserData
,
AudioQueueRef
inAQ
,
AudioQueueBufferRef
inBuffer
)
{
/* this function does nothing, but needs to be here to make the AudioQueue API happy.
* without a callback, it will refuse to create an AudioQueue instance. */
VLC_UNUSED
(
inUserData
);
...
...
@@ -185,7 +235,7 @@ void AudioQueueCallback(void * inUserData, AudioQueueRef inAQ, AudioQueueBufferR
VLC_UNUSED
(
inBuffer
);
}
static
void
Pause
(
audio_output_t
*
p_aout
,
bool
pause
,
mtime_t
date
)
static
void
Pause
(
audio_output_t
*
p_aout
,
bool
pause
,
mtime_t
date
)
{
VLC_UNUSED
(
date
);
...
...
@@ -195,7 +245,7 @@ static void Pause (audio_output_t *p_aout, bool pause, mtime_t date)
AudioQueueStart
(
p_aout
->
sys
->
audioQueue
,
NULL
);
}
static
void
Flush
(
audio_output_t
*
p_aout
,
bool
wait
)
static
void
Flush
(
audio_output_t
*
p_aout
,
bool
wait
)
{
if
(
p_aout
->
sys
->
b_stopped
||
!
p_aout
->
sys
->
audioQueue
)
return
;
...
...
@@ -212,7 +262,7 @@ static void Flush (audio_output_t *p_aout, bool wait)
AudioQueueCreateTimeline
(
p_aout
->
sys
->
audioQueue
,
&
p_aout
->
sys
->
outTimeline
);
}
static
int
TimeGet
(
audio_output_t
*
p_aout
,
mtime_t
*
restrict
delay
)
static
int
TimeGet
(
audio_output_t
*
p_aout
,
mtime_t
*
restrict
delay
)
{
AudioTimeStamp
outTimeStamp
;
Boolean
b_discontinuity
;
...
...
@@ -229,53 +279,3 @@ static int TimeGet (audio_output_t *p_aout, mtime_t *restrict delay)
return
0
;
}
/*****************************************************************************
* Module management
*****************************************************************************/
static
int
VolumeSet
(
audio_output_t
*
p_aout
,
float
volume
)
{
struct
aout_sys_t
*
p_sys
=
p_aout
->
sys
;
OSStatus
ostatus
;
aout_VolumeReport
(
p_aout
,
volume
);
p_sys
->
f_volume
=
volume
;
/* Set volume for output unit */
ostatus
=
AudioQueueSetParameter
(
p_sys
->
audioQueue
,
kAudioQueueParam_Volume
,
volume
*
volume
*
volume
);
return
ostatus
;
}
/*****************************************************************************
* Module management
*****************************************************************************/
static
int
Open
(
vlc_object_t
*
obj
)
{
audio_output_t
*
aout
=
(
audio_output_t
*
)
obj
;
aout_sys_t
*
sys
=
malloc
(
sizeof
(
*
sys
));
if
(
unlikely
(
sys
==
NULL
))
return
VLC_ENOMEM
;
aout
->
sys
=
sys
;
aout
->
start
=
Start
;
aout
->
stop
=
Stop
;
aout
->
volume_set
=
VolumeSet
;
/* reset volume */
aout_VolumeReport
(
aout
,
1
.
0
);
return
VLC_SUCCESS
;
}
static
void
Close
(
vlc_object_t
*
obj
)
{
audio_output_t
*
aout
=
(
audio_output_t
*
)
obj
;
msg_Dbg
(
aout
,
"audioqueue: Close"
);
aout_sys_t
*
sys
=
aout
->
sys
;
free
(
sys
);
}
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