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
0eb4038d
Commit
0eb4038d
authored
Sep 12, 2008
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
shout: no CamelCase
parent
85d952c5
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
186 additions
and
186 deletions
+186
-186
audioOutput_shout.c
src/audioOutputs/audioOutput_shout.c
+186
-186
No files found.
src/audioOutputs/audioOutput_shout.c
View file @
0eb4038d
...
...
@@ -30,13 +30,13 @@
#define CONN_ATTEMPT_INTERVAL 60
#define DEFAULT_CONN_TIMEOUT 2
static
int
shout
InitC
ount
;
static
int
shout
_init_c
ount
;
/* lots of this code blatantly stolent from bossogg/bossao2 */
typedef
struct
_ShoutD
ata
{
shout_t
*
shout
C
onn
;
int
shout
E
rror
;
struct
shout_d
ata
{
shout_t
*
shout
_c
onn
;
int
shout
_e
rror
;
ogg_stream_state
os
;
ogg_page
og
;
...
...
@@ -56,40 +56,40 @@ typedef struct _ShoutData {
int
opened
;
struct
tag
*
tag
;
int
tag
ToS
end
;
int
tag
_to_s
end
;
int
timeout
;
int
conn
A
ttempts
;
time_t
last
A
ttempt
;
int
conn
_a
ttempts
;
time_t
last
_a
ttempt
;
Timer
*
timer
;
/* the configured audio format */
struct
audio_format
audio_format
;
}
ShoutData
;
};
static
ShoutData
*
newShoutD
ata
(
void
)
static
struct
shout_data
*
new_shout_d
ata
(
void
)
{
ShoutData
*
ret
=
xmalloc
(
sizeof
(
ShoutData
));
struct
shout_data
*
ret
=
xmalloc
(
sizeof
(
*
ret
));
ret
->
shout
C
onn
=
shout_new
();
ret
->
shout
_c
onn
=
shout_new
();
ret
->
opened
=
0
;
ret
->
tag
=
NULL
;
ret
->
tag
ToS
end
=
0
;
ret
->
tag
_to_s
end
=
0
;
ret
->
bitrate
=
-
1
;
ret
->
quality
=
-
2
.
0
;
ret
->
timeout
=
DEFAULT_CONN_TIMEOUT
;
ret
->
conn
A
ttempts
=
0
;
ret
->
last
A
ttempt
=
0
;
ret
->
conn
_a
ttempts
=
0
;
ret
->
last
_a
ttempt
=
0
;
ret
->
timer
=
NULL
;
return
ret
;
}
static
void
free
ShoutData
(
ShoutData
*
sd
)
static
void
free
_shout_data
(
struct
shout_data
*
sd
)
{
if
(
sd
->
shout
C
onn
)
shout_free
(
sd
->
shout
C
onn
);
if
(
sd
->
shout
_c
onn
)
shout_free
(
sd
->
shout
_c
onn
);
if
(
sd
->
tag
)
tag_free
(
sd
->
tag
);
if
(
sd
->
timer
)
...
...
@@ -98,18 +98,18 @@ static void freeShoutData(ShoutData * sd)
free
(
sd
);
}
#define check
BlockParam(name) {
\
blockParam = getBlockParam(param, name);
\
if (!blockParam) {
\
#define check
_block_param(name) {
\
block_param = getBlockParam(param, name);
\
if (!block_param) {
\
FATAL("no \"%s\" defined for shout device defined at line " \
"%i\n", name, param->line); \
} \
}
}
static
int
my
Shout_initDriver
(
struct
audio_output
*
audioO
utput
,
static
int
my
_shout_init_driver
(
struct
audio_output
*
audio_o
utput
,
ConfigParam
*
param
)
{
ShoutD
ata
*
sd
;
struct
shout_d
ata
*
sd
;
char
*
test
;
int
port
;
char
*
host
;
...
...
@@ -117,124 +117,124 @@ static int myShout_initDriver(struct audio_output *audioOutput,
char
*
passwd
;
const
char
*
user
;
char
*
name
;
BlockParam
*
block
P
aram
;
BlockParam
*
block
_p
aram
;
int
public
;
sd
=
new
ShoutD
ata
();
sd
=
new
_shout_d
ata
();
if
(
shout
InitC
ount
==
0
)
if
(
shout
_init_c
ount
==
0
)
shout_init
();
shout
InitC
ount
++
;
shout
_init_c
ount
++
;
check
BlockP
aram
(
"host"
);
host
=
block
P
aram
->
value
;
check
_block_p
aram
(
"host"
);
host
=
block
_p
aram
->
value
;
check
BlockP
aram
(
"mount"
);
mount
=
block
P
aram
->
value
;
check
_block_p
aram
(
"mount"
);
mount
=
block
_p
aram
->
value
;
check
BlockP
aram
(
"port"
);
check
_block_p
aram
(
"port"
);
port
=
strtol
(
block
P
aram
->
value
,
&
test
,
10
);
port
=
strtol
(
block
_p
aram
->
value
,
&
test
,
10
);
if
(
*
test
!=
'\0'
||
port
<=
0
)
{
FATAL
(
"shout port
\"
%s
\"
is not a positive integer, line %i
\n
"
,
block
Param
->
value
,
blockP
aram
->
line
);
block
_param
->
value
,
block_p
aram
->
line
);
}
check
BlockP
aram
(
"password"
);
passwd
=
block
P
aram
->
value
;
check
_block_p
aram
(
"password"
);
passwd
=
block
_p
aram
->
value
;
check
BlockP
aram
(
"name"
);
name
=
block
P
aram
->
value
;
check
_block_p
aram
(
"name"
);
name
=
block
_p
aram
->
value
;
public
=
getBoolBlockParam
(
param
,
"public"
,
1
);
if
(
public
==
CONF_BOOL_UNSET
)
public
=
0
;
block
P
aram
=
getBlockParam
(
param
,
"user"
);
if
(
block
P
aram
)
user
=
block
P
aram
->
value
;
block
_p
aram
=
getBlockParam
(
param
,
"user"
);
if
(
block
_p
aram
)
user
=
block
_p
aram
->
value
;
else
user
=
"source"
;
block
P
aram
=
getBlockParam
(
param
,
"quality"
);
block
_p
aram
=
getBlockParam
(
param
,
"quality"
);
if
(
block
P
aram
)
{
int
line
=
block
P
aram
->
line
;
if
(
block
_p
aram
)
{
int
line
=
block
_p
aram
->
line
;
sd
->
quality
=
strtod
(
block
P
aram
->
value
,
&
test
);
sd
->
quality
=
strtod
(
block
_p
aram
->
value
,
&
test
);
if
(
*
test
!=
'\0'
||
sd
->
quality
<
-
1
.
0
||
sd
->
quality
>
10
.
0
)
{
FATAL
(
"shout quality
\"
%s
\"
is not a number in the "
"range -1 to 10, line %i
\n
"
,
block
P
aram
->
value
,
block
P
aram
->
line
);
"range -1 to 10, line %i
\n
"
,
block
_p
aram
->
value
,
block
_p
aram
->
line
);
}
block
P
aram
=
getBlockParam
(
param
,
"bitrate"
);
block
_p
aram
=
getBlockParam
(
param
,
"bitrate"
);
if
(
block
P
aram
)
{
if
(
block
_p
aram
)
{
FATAL
(
"quality (line %i) and bitrate (line %i) are "
"both defined for shout output
\n
"
,
line
,
block
P
aram
->
line
);
block
_p
aram
->
line
);
}
}
else
{
block
P
aram
=
getBlockParam
(
param
,
"bitrate"
);
block
_p
aram
=
getBlockParam
(
param
,
"bitrate"
);
if
(
!
block
P
aram
)
{
if
(
!
block
_p
aram
)
{
FATAL
(
"neither bitrate nor quality defined for shout "
"output at line %i
\n
"
,
param
->
line
);
}
sd
->
bitrate
=
strtol
(
block
P
aram
->
value
,
&
test
,
10
);
sd
->
bitrate
=
strtol
(
block
_p
aram
->
value
,
&
test
,
10
);
if
(
*
test
!=
'\0'
||
sd
->
bitrate
<=
0
)
{
FATAL
(
"bitrate at line %i should be a positive integer "
"
\n
"
,
block
P
aram
->
line
);
"
\n
"
,
block
_p
aram
->
line
);
}
}
check
BlockP
aram
(
"format"
);
sd
->
audio_format
=
audio
O
utput
->
reqAudioFormat
;
check
_block_p
aram
(
"format"
);
sd
->
audio_format
=
audio
_o
utput
->
reqAudioFormat
;
if
(
shout_set_host
(
sd
->
shout
C
onn
,
host
)
!=
SHOUTERR_SUCCESS
||
shout_set_port
(
sd
->
shout
C
onn
,
port
)
!=
SHOUTERR_SUCCESS
||
shout_set_password
(
sd
->
shout
C
onn
,
passwd
)
!=
SHOUTERR_SUCCESS
||
shout_set_mount
(
sd
->
shout
C
onn
,
mount
)
!=
SHOUTERR_SUCCESS
||
shout_set_name
(
sd
->
shout
C
onn
,
name
)
!=
SHOUTERR_SUCCESS
||
shout_set_user
(
sd
->
shout
C
onn
,
user
)
!=
SHOUTERR_SUCCESS
||
shout_set_public
(
sd
->
shout
C
onn
,
public
)
!=
SHOUTERR_SUCCESS
||
shout_set_nonblocking
(
sd
->
shout
C
onn
,
1
)
!=
SHOUTERR_SUCCESS
||
shout_set_format
(
sd
->
shout
C
onn
,
SHOUT_FORMAT_VORBIS
)
if
(
shout_set_host
(
sd
->
shout
_c
onn
,
host
)
!=
SHOUTERR_SUCCESS
||
shout_set_port
(
sd
->
shout
_c
onn
,
port
)
!=
SHOUTERR_SUCCESS
||
shout_set_password
(
sd
->
shout
_c
onn
,
passwd
)
!=
SHOUTERR_SUCCESS
||
shout_set_mount
(
sd
->
shout
_c
onn
,
mount
)
!=
SHOUTERR_SUCCESS
||
shout_set_name
(
sd
->
shout
_c
onn
,
name
)
!=
SHOUTERR_SUCCESS
||
shout_set_user
(
sd
->
shout
_c
onn
,
user
)
!=
SHOUTERR_SUCCESS
||
shout_set_public
(
sd
->
shout
_c
onn
,
public
)
!=
SHOUTERR_SUCCESS
||
shout_set_nonblocking
(
sd
->
shout
_c
onn
,
1
)
!=
SHOUTERR_SUCCESS
||
shout_set_format
(
sd
->
shout
_c
onn
,
SHOUT_FORMAT_VORBIS
)
!=
SHOUTERR_SUCCESS
||
shout_set_protocol
(
sd
->
shout
C
onn
,
SHOUT_PROTOCOL_HTTP
)
shout_set_protocol
(
sd
->
shout
_c
onn
,
SHOUT_PROTOCOL_HTTP
)
!=
SHOUTERR_SUCCESS
||
shout_set_agent
(
sd
->
shout
C
onn
,
"MPD"
)
!=
SHOUTERR_SUCCESS
)
{
shout_set_agent
(
sd
->
shout
_c
onn
,
"MPD"
)
!=
SHOUTERR_SUCCESS
)
{
FATAL
(
"error configuring shout defined at line %i: %s
\n
"
,
param
->
line
,
shout_get_error
(
sd
->
shout
C
onn
));
param
->
line
,
shout_get_error
(
sd
->
shout
_c
onn
));
}
/* optional paramters */
block
P
aram
=
getBlockParam
(
param
,
"timeout"
);
if
(
block
P
aram
)
{
sd
->
timeout
=
(
int
)
strtol
(
block
P
aram
->
value
,
&
test
,
10
);
block
_p
aram
=
getBlockParam
(
param
,
"timeout"
);
if
(
block
_p
aram
)
{
sd
->
timeout
=
(
int
)
strtol
(
block
_p
aram
->
value
,
&
test
,
10
);
if
(
*
test
!=
'\0'
||
sd
->
timeout
<=
0
)
{
FATAL
(
"shout timeout is not a positive integer, "
"line %i
\n
"
,
block
P
aram
->
line
);
"line %i
\n
"
,
block
_p
aram
->
line
);
}
}
block
P
aram
=
getBlockParam
(
param
,
"genre"
);
if
(
block
Param
&&
shout_set_genre
(
sd
->
shoutConn
,
blockP
aram
->
value
))
{
block
_p
aram
=
getBlockParam
(
param
,
"genre"
);
if
(
block
_param
&&
shout_set_genre
(
sd
->
shout_conn
,
block_p
aram
->
value
))
{
FATAL
(
"error configuring shout defined at line %i: %s
\n
"
,
param
->
line
,
shout_get_error
(
sd
->
shout
C
onn
));
param
->
line
,
shout_get_error
(
sd
->
shout
_c
onn
));
}
block
P
aram
=
getBlockParam
(
param
,
"description"
);
if
(
block
Param
&&
shout_set_description
(
sd
->
shoutC
onn
,
blockP
aram
->
value
))
{
block
_p
aram
=
getBlockParam
(
param
,
"description"
);
if
(
block
_param
&&
shout_set_description
(
sd
->
shout_c
onn
,
block_p
aram
->
value
))
{
FATAL
(
"error configuring shout defined at line %i: %s
\n
"
,
param
->
line
,
shout_get_error
(
sd
->
shout
C
onn
));
param
->
line
,
shout_get_error
(
sd
->
shout
_c
onn
));
}
{
...
...
@@ -242,29 +242,29 @@ static int myShout_initDriver(struct audio_output *audioOutput,
memset
(
temp
,
0
,
sizeof
(
temp
));
snprintf
(
temp
,
sizeof
(
temp
),
"%d"
,
sd
->
audio_format
.
channels
);
shout_set_audio_info
(
sd
->
shout
C
onn
,
SHOUT_AI_CHANNELS
,
temp
);
shout_set_audio_info
(
sd
->
shout
_c
onn
,
SHOUT_AI_CHANNELS
,
temp
);
snprintf
(
temp
,
sizeof
(
temp
),
"%d"
,
sd
->
audio_format
.
sampleRate
);
shout_set_audio_info
(
sd
->
shout
C
onn
,
SHOUT_AI_SAMPLERATE
,
temp
);
shout_set_audio_info
(
sd
->
shout
_c
onn
,
SHOUT_AI_SAMPLERATE
,
temp
);
if
(
sd
->
quality
>=
-
1
.
0
)
{
snprintf
(
temp
,
sizeof
(
temp
),
"%2.2f"
,
sd
->
quality
);
shout_set_audio_info
(
sd
->
shout
C
onn
,
SHOUT_AI_QUALITY
,
shout_set_audio_info
(
sd
->
shout
_c
onn
,
SHOUT_AI_QUALITY
,
temp
);
}
else
{
snprintf
(
temp
,
sizeof
(
temp
),
"%d"
,
sd
->
bitrate
);
shout_set_audio_info
(
sd
->
shout
C
onn
,
SHOUT_AI_BITRATE
,
shout_set_audio_info
(
sd
->
shout
_c
onn
,
SHOUT_AI_BITRATE
,
temp
);
}
}
audio
O
utput
->
data
=
sd
;
audio
_o
utput
->
data
=
sd
;
return
0
;
}
static
int
myShout_handleError
(
ShoutData
*
sd
,
int
err
)
static
int
handle_shout_error
(
struct
shout_data
*
sd
,
int
err
)
{
switch
(
err
)
{
case
SHOUTERR_SUCCESS
:
...
...
@@ -272,39 +272,39 @@ static int myShout_handleError(ShoutData * sd, int err)
case
SHOUTERR_UNCONNECTED
:
case
SHOUTERR_SOCKET
:
ERROR
(
"Lost shout connection to %s:%i: %s
\n
"
,
shout_get_host
(
sd
->
shout
C
onn
),
shout_get_port
(
sd
->
shout
C
onn
),
shout_get_error
(
sd
->
shout
C
onn
));
sd
->
shout
E
rror
=
1
;
shout_get_host
(
sd
->
shout
_c
onn
),
shout_get_port
(
sd
->
shout
_c
onn
),
shout_get_error
(
sd
->
shout
_c
onn
));
sd
->
shout
_e
rror
=
1
;
return
-
1
;
default:
ERROR
(
"shout: connection to %s:%i error: %s
\n
"
,
shout_get_host
(
sd
->
shout
C
onn
),
shout_get_port
(
sd
->
shout
C
onn
),
shout_get_error
(
sd
->
shout
C
onn
));
sd
->
shout
E
rror
=
1
;
shout_get_host
(
sd
->
shout
_c
onn
),
shout_get_port
(
sd
->
shout
_c
onn
),
shout_get_error
(
sd
->
shout
_c
onn
));
sd
->
shout
_e
rror
=
1
;
return
-
1
;
}
return
0
;
}
static
int
write_page
(
ShoutData
*
sd
)
static
int
write_page
(
struct
shout_data
*
sd
)
{
int
err
;
shout_sync
(
sd
->
shout
C
onn
);
err
=
shout_send
(
sd
->
shout
C
onn
,
sd
->
og
.
header
,
sd
->
og
.
header_len
);
if
(
myShout_handleE
rror
(
sd
,
err
)
<
0
)
shout_sync
(
sd
->
shout
_c
onn
);
err
=
shout_send
(
sd
->
shout
_c
onn
,
sd
->
og
.
header
,
sd
->
og
.
header_len
);
if
(
handle_shout_e
rror
(
sd
,
err
)
<
0
)
return
-
1
;
err
=
shout_send
(
sd
->
shout
C
onn
,
sd
->
og
.
body
,
sd
->
og
.
body_len
);
if
(
myShout_handleE
rror
(
sd
,
err
)
<
0
)
err
=
shout_send
(
sd
->
shout
_c
onn
,
sd
->
og
.
body
,
sd
->
og
.
body_len
);
if
(
handle_shout_e
rror
(
sd
,
err
)
<
0
)
return
-
1
;
return
0
;
}
static
void
finish
Encoder
(
ShoutData
*
sd
)
static
void
finish
_encoder
(
struct
shout_data
*
sd
)
{
vorbis_analysis_wrote
(
&
sd
->
vd
,
0
);
...
...
@@ -317,16 +317,16 @@ static void finishEncoder(ShoutData * sd)
}
}
static
int
flush
Encoder
(
ShoutData
*
sd
)
static
int
flush
_encoder
(
struct
shout_data
*
sd
)
{
return
(
ogg_stream_pageout
(
&
sd
->
os
,
&
sd
->
og
)
>
0
);
}
static
void
clearEncoder
(
ShoutData
*
sd
)
static
void
shout_ogg_encoder_clear_encoder
(
struct
shout_data
*
sd
)
{
finish
E
ncoder
(
sd
);
while
(
1
==
flush
E
ncoder
(
sd
))
{
if
(
!
sd
->
shout
E
rror
)
finish
_e
ncoder
(
sd
);
while
(
1
==
flush
_e
ncoder
(
sd
))
{
if
(
!
sd
->
shout
_e
rror
)
write_page
(
sd
);
}
...
...
@@ -337,57 +337,57 @@ static void clearEncoder(ShoutData * sd)
vorbis_info_clear
(
&
sd
->
vi
);
}
static
void
myShout_closeShoutConn
(
ShoutData
*
sd
)
static
void
close_shout_conn
(
struct
shout_data
*
sd
)
{
if
(
sd
->
opened
)
clearE
ncoder
(
sd
);
shout_ogg_encoder_clear_e
ncoder
(
sd
);
if
(
shout_get_connected
(
sd
->
shout
C
onn
)
!=
SHOUTERR_UNCONNECTED
&&
shout_close
(
sd
->
shout
C
onn
)
!=
SHOUTERR_SUCCESS
)
{
if
(
shout_get_connected
(
sd
->
shout
_c
onn
)
!=
SHOUTERR_UNCONNECTED
&&
shout_close
(
sd
->
shout
_c
onn
)
!=
SHOUTERR_SUCCESS
)
{
ERROR
(
"problem closing connection to shout server: %s
\n
"
,
shout_get_error
(
sd
->
shout
C
onn
));
shout_get_error
(
sd
->
shout
_c
onn
));
}
sd
->
opened
=
0
;
}
static
void
my
Shout_finishDriver
(
struct
audio_output
*
audioO
utput
)
static
void
my
_shout_finish_driver
(
struct
audio_output
*
audio_o
utput
)
{
ShoutData
*
sd
=
(
ShoutData
*
)
audioO
utput
->
data
;
struct
shout_data
*
sd
=
(
struct
shout_data
*
)
audio_o
utput
->
data
;
myShout_closeShoutC
onn
(
sd
);
close_shout_c
onn
(
sd
);
free
ShoutD
ata
(
sd
);
free
_shout_d
ata
(
sd
);
shout
InitC
ount
--
;
shout
_init_c
ount
--
;
if
(
shout
InitC
ount
==
0
)
if
(
shout
_init_c
ount
==
0
)
shout_shutdown
();
}
static
void
my
Shout_dropBufferedAudio
(
struct
audio_output
*
audioO
utput
)
static
void
my
_shout_drop_buffered_audio
(
struct
audio_output
*
audio_o
utput
)
{
ShoutData
*
sd
=
(
ShoutData
*
)
audioO
utput
->
data
;
struct
shout_data
*
sd
=
(
struct
shout_data
*
)
audio_o
utput
->
data
;
timer_reset
(
sd
->
timer
);
/* needs to be implemented for shout */
}
static
void
my
Shout_closeDevice
(
struct
audio_output
*
audioO
utput
)
static
void
my
_shout_close_device
(
struct
audio_output
*
audio_o
utput
)
{
ShoutData
*
sd
=
(
ShoutData
*
)
audioO
utput
->
data
;
struct
shout_data
*
sd
=
(
struct
shout_data
*
)
audio_o
utput
->
data
;
myShout_closeShoutC
onn
(
sd
);
close_shout_c
onn
(
sd
);
if
(
sd
->
timer
)
{
timer_free
(
sd
->
timer
);
sd
->
timer
=
NULL
;
}
audio
O
utput
->
open
=
0
;
audio
_o
utput
->
open
=
0
;
}
static
void
add
Tag
(
ShoutD
ata
*
sd
,
const
char
*
name
,
char
*
value
)
static
void
add
_tag
(
struct
shout_d
ata
*
sd
,
const
char
*
name
,
char
*
value
)
{
if
(
value
)
{
union
const_hack
u
;
...
...
@@ -396,7 +396,7 @@ static void addTag(ShoutData *sd, const char *name, char *value)
}
}
static
void
copy
TagToVorbisComment
(
ShoutData
*
sd
)
static
void
copy
_tag_to_vorbis_comment
(
struct
shout_data
*
sd
)
{
if
(
sd
->
tag
)
{
int
i
;
...
...
@@ -404,13 +404,13 @@ static void copyTagToVorbisComment(ShoutData * sd)
for
(
i
=
0
;
i
<
sd
->
tag
->
numOfItems
;
i
++
)
{
switch
(
sd
->
tag
->
items
[
i
]
->
type
)
{
case
TAG_ITEM_ARTIST
:
add
T
ag
(
sd
,
"ARTIST"
,
sd
->
tag
->
items
[
i
]
->
value
);
add
_t
ag
(
sd
,
"ARTIST"
,
sd
->
tag
->
items
[
i
]
->
value
);
break
;
case
TAG_ITEM_ALBUM
:
add
T
ag
(
sd
,
"ALBUM"
,
sd
->
tag
->
items
[
i
]
->
value
);
add
_t
ag
(
sd
,
"ALBUM"
,
sd
->
tag
->
items
[
i
]
->
value
);
break
;
case
TAG_ITEM_TITLE
:
add
T
ag
(
sd
,
"TITLE"
,
sd
->
tag
->
items
[
i
]
->
value
);
add
_t
ag
(
sd
,
"TITLE"
,
sd
->
tag
->
items
[
i
]
->
value
);
break
;
default:
break
;
...
...
@@ -419,7 +419,7 @@ static void copyTagToVorbisComment(ShoutData * sd)
}
}
static
int
init
Encoder
(
ShoutData
*
sd
)
static
int
init
_encoder
(
struct
shout_data
*
sd
)
{
vorbis_info_init
(
&
(
sd
->
vi
));
...
...
@@ -453,24 +453,24 @@ static int initEncoder(ShoutData * sd)
return
0
;
}
static
int
myShout_connect
(
ShoutD
ata
*
sd
)
static
int
shout_connect
(
struct
shout_d
ata
*
sd
)
{
time_t
t
=
time
(
NULL
);
int
state
=
shout_get_connected
(
sd
->
shout
C
onn
);
int
state
=
shout_get_connected
(
sd
->
shout
_c
onn
);
/* already connected */
if
(
state
==
SHOUTERR_CONNECTED
)
return
0
;
/* waiting to connect */
if
(
state
==
SHOUTERR_BUSY
&&
sd
->
conn
A
ttempts
!=
0
)
{
if
(
state
==
SHOUTERR_BUSY
&&
sd
->
conn
_a
ttempts
!=
0
)
{
/* timeout waiting to connect */
if
((
t
-
sd
->
last
A
ttempt
)
>
sd
->
timeout
)
{
if
((
t
-
sd
->
last
_a
ttempt
)
>
sd
->
timeout
)
{
ERROR
(
"timeout connecting to shout server %s:%i "
"(attempt %i)
\n
"
,
shout_get_host
(
sd
->
shout
C
onn
),
shout_get_port
(
sd
->
shout
C
onn
),
sd
->
conn
A
ttempts
);
shout_get_host
(
sd
->
shout
_c
onn
),
shout_get_port
(
sd
->
shout
_c
onn
),
sd
->
conn
_a
ttempts
);
return
-
1
;
}
...
...
@@ -479,20 +479,20 @@ static int myShout_connect(ShoutData *sd)
/* we're in some funky state, so just reset it to unconnected */
if
(
state
!=
SHOUTERR_UNCONNECTED
)
shout_close
(
sd
->
shout
C
onn
);
shout_close
(
sd
->
shout
_c
onn
);
/* throttle new connection attempts */
if
(
sd
->
conn
A
ttempts
!=
0
&&
(
t
-
sd
->
last
A
ttempt
)
<=
CONN_ATTEMPT_INTERVAL
)
{
if
(
sd
->
conn
_a
ttempts
!=
0
&&
(
t
-
sd
->
last
_a
ttempt
)
<=
CONN_ATTEMPT_INTERVAL
)
{
return
-
1
;
}
/* initiate a new connection */
sd
->
conn
A
ttempts
++
;
sd
->
last
A
ttempt
=
t
;
sd
->
conn
_a
ttempts
++
;
sd
->
last
_a
ttempt
=
t
;
state
=
shout_open
(
sd
->
shout
C
onn
);
state
=
shout_open
(
sd
->
shout
_c
onn
);
switch
(
state
)
{
case
SHOUTERR_SUCCESS
:
case
SHOUTERR_CONNECTED
:
...
...
@@ -502,30 +502,30 @@ static int myShout_connect(ShoutData *sd)
default:
ERROR
(
"problem opening connection to shout server %s:%i "
"(attempt %i): %s
\n
"
,
shout_get_host
(
sd
->
shout
C
onn
),
shout_get_port
(
sd
->
shout
C
onn
),
sd
->
conn
Attempts
,
shout_get_error
(
sd
->
shoutC
onn
));
shout_get_host
(
sd
->
shout
_c
onn
),
shout_get_port
(
sd
->
shout
_c
onn
),
sd
->
conn
_attempts
,
shout_get_error
(
sd
->
shout_c
onn
));
return
-
1
;
}
}
static
int
myShout_openShoutConn
(
struct
audio_output
*
audioO
utput
)
static
int
open_shout_conn
(
struct
audio_output
*
audio_o
utput
)
{
ShoutData
*
sd
=
(
ShoutData
*
)
audioO
utput
->
data
;
struct
shout_data
*
sd
=
(
struct
shout_data
*
)
audio_o
utput
->
data
;
int
status
;
status
=
myS
hout_connect
(
sd
);
status
=
s
hout_connect
(
sd
);
if
(
status
!=
0
)
return
status
;
if
(
init
E
ncoder
(
sd
)
<
0
)
{
shout_close
(
sd
->
shout
C
onn
);
if
(
init
_e
ncoder
(
sd
)
<
0
)
{
shout_close
(
sd
->
shout
_c
onn
);
return
-
1
;
}
sd
->
shout
E
rror
=
0
;
sd
->
shout
_e
rror
=
0
;
copy
TagToVorbisC
omment
(
sd
);
copy
_tag_to_vorbis_c
omment
(
sd
);
vorbis_analysis_headerout
(
&
(
sd
->
vd
),
&
(
sd
->
vc
),
&
(
sd
->
header_main
),
&
(
sd
->
header_comments
),
...
...
@@ -536,47 +536,47 @@ static int myShout_openShoutConn(struct audio_output *audioOutput)
ogg_stream_packetin
(
&
(
sd
->
os
),
&
(
sd
->
header_codebooks
));
sd
->
opened
=
1
;
sd
->
tag
ToS
end
=
0
;
sd
->
tag
_to_s
end
=
0
;
while
(
ogg_stream_flush
(
&
(
sd
->
os
),
&
(
sd
->
og
)))
{
if
(
write_page
(
sd
)
<
0
)
{
myShout_closeShoutC
onn
(
sd
);
close_shout_c
onn
(
sd
);
return
-
1
;
}
}
sd
->
conn
A
ttempts
=
0
;
sd
->
conn
_a
ttempts
=
0
;
return
0
;
}
static
int
my
Shout_openDevice
(
struct
audio_output
*
audioO
utput
)
static
int
my
_shout_open_device
(
struct
audio_output
*
audio_o
utput
)
{
ShoutData
*
sd
=
(
ShoutData
*
)
audioO
utput
->
data
;
struct
shout_data
*
sd
=
(
struct
shout_data
*
)
audio_o
utput
->
data
;
if
(
!
sd
->
opened
&&
myShout_openShoutConn
(
audioO
utput
)
<
0
)
if
(
!
sd
->
opened
&&
open_shout_conn
(
audio_o
utput
)
<
0
)
return
-
1
;
if
(
sd
->
timer
)
timer_free
(
sd
->
timer
);
sd
->
timer
=
timer_new
(
&
audio
O
utput
->
outAudioFormat
);
sd
->
timer
=
timer_new
(
&
audio
_o
utput
->
outAudioFormat
);
audio
O
utput
->
open
=
1
;
audio
_o
utput
->
open
=
1
;
return
0
;
}
static
void
myShout_sendMetadata
(
ShoutD
ata
*
sd
)
static
void
send_metadata
(
struct
shout_d
ata
*
sd
)
{
if
(
!
sd
->
opened
||
!
sd
->
tag
)
return
;
clearE
ncoder
(
sd
);
if
(
init
E
ncoder
(
sd
)
<
0
)
shout_ogg_encoder_clear_e
ncoder
(
sd
);
if
(
init
_e
ncoder
(
sd
)
<
0
)
return
;
copy
TagToVorbisC
omment
(
sd
);
copy
_tag_to_vorbis_c
omment
(
sd
);
vorbis_analysis_headerout
(
&
(
sd
->
vd
),
&
(
sd
->
vc
),
&
(
sd
->
header_main
),
&
(
sd
->
header_comments
),
...
...
@@ -588,22 +588,22 @@ static void myShout_sendMetadata(ShoutData * sd)
while
(
ogg_stream_flush
(
&
(
sd
->
os
),
&
(
sd
->
og
)))
{
if
(
write_page
(
sd
)
<
0
)
{
myShout_closeShoutC
onn
(
sd
);
close_shout_c
onn
(
sd
);
return
;
}
}
/*if(sd->tag) freeMpdTag(sd->tag);
sd->tag = NULL; */
sd
->
tag
ToS
end
=
0
;
sd
->
tag
_to_s
end
=
0
;
}
static
int
my
Shout_play
(
struct
audio_output
*
audioO
utput
,
const
char
*
playC
hunk
,
size_t
size
)
static
int
my
_shout_play
(
struct
audio_output
*
audio_o
utput
,
const
char
*
c
hunk
,
size_t
size
)
{
unsigned
int
i
;
int
j
;
ShoutData
*
sd
=
(
ShoutData
*
)
audioO
utput
->
data
;
struct
shout_data
*
sd
=
(
struct
shout_data
*
)
audio_o
utput
->
data
;
float
**
vorbbuf
;
unsigned
int
samples
;
int
bytes
=
sd
->
audio_format
.
bits
/
8
;
...
...
@@ -614,13 +614,13 @@ static int myShout_play(struct audio_output *audioOutput,
timer_add
(
sd
->
timer
,
size
);
if
(
sd
->
opened
&&
sd
->
tag
ToS
end
)
myShout_sendM
etadata
(
sd
);
if
(
sd
->
opened
&&
sd
->
tag
_to_s
end
)
send_m
etadata
(
sd
);
if
(
!
sd
->
opened
)
{
status
=
myShout_openShoutConn
(
audioO
utput
);
status
=
open_shout_conn
(
audio_o
utput
);
if
(
status
<
0
)
{
my
Shout_closeDevice
(
audioO
utput
);
my
_shout_close_device
(
audio_o
utput
);
return
-
1
;
}
else
if
(
status
>
0
)
{
timer_sync
(
sd
->
timer
);
...
...
@@ -636,8 +636,8 @@ static int myShout_play(struct audio_output *audioOutput,
for
(
i
=
0
;
i
<
samples
;
i
++
)
{
for
(
j
=
0
;
j
<
sd
->
audio_format
.
channels
;
j
++
)
{
vorbbuf
[
j
][
i
]
=
(
*
((
const
mpd_sint16
*
)
playC
hunk
))
/
32768
.
0
;
playC
hunk
+=
bytes
;
vorbbuf
[
j
][
i
]
=
(
*
((
const
mpd_sint16
*
)
c
hunk
))
/
32768
.
0
;
c
hunk
+=
bytes
;
}
}
...
...
@@ -654,7 +654,7 @@ static int myShout_play(struct audio_output *audioOutput,
while
(
ogg_stream_pageout
(
&
(
sd
->
os
),
&
(
sd
->
og
))
!=
0
)
{
if
(
write_page
(
sd
)
<
0
)
{
my
Shout_closeDevice
(
audioO
utput
);
my
_shout_close_device
(
audio_o
utput
);
return
-
1
;
}
}
...
...
@@ -662,33 +662,33 @@ static int myShout_play(struct audio_output *audioOutput,
return
0
;
}
static
void
my
Shout_setTag
(
struct
audio_output
*
audioO
utput
,
static
void
my
_shout_set_tag
(
struct
audio_output
*
audio_o
utput
,
const
struct
tag
*
tag
)
{
ShoutData
*
sd
=
(
ShoutData
*
)
audioO
utput
->
data
;
struct
shout_data
*
sd
=
(
struct
shout_data
*
)
audio_o
utput
->
data
;
if
(
sd
->
tag
)
tag_free
(
sd
->
tag
);
sd
->
tag
=
NULL
;
sd
->
tag
ToS
end
=
0
;
sd
->
tag
_to_s
end
=
0
;
if
(
!
tag
)
return
;
sd
->
tag
=
tag_dup
(
tag
);
sd
->
tag
ToS
end
=
1
;
sd
->
tag
_to_s
end
=
1
;
}
const
struct
audio_output_plugin
shoutPlugin
=
{
"shout"
,
NULL
,
my
Shout_initD
river
,
my
Shout_finishD
river
,
my
Shout_openD
evice
,
my
S
hout_play
,
my
Shout_dropBufferedA
udio
,
my
Shout_closeD
evice
,
my
Shout_setT
ag
,
my
_shout_init_d
river
,
my
_shout_finish_d
river
,
my
_shout_open_d
evice
,
my
_s
hout_play
,
my
_shout_drop_buffered_a
udio
,
my
_shout_close_d
evice
,
my
_shout_set_t
ag
,
};
#else
...
...
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