output/raop: new output plugin
Remote Audio Output Protocol (RAOP), for Apple devices.
This commit is contained in:

committed by
Max Kellermann

parent
9ae3acf2e7
commit
79e0db4ca0
78
src/mixer/raop_mixer_plugin.c
Normal file
78
src/mixer/raop_mixer_plugin.c
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2009 The Music Player Daemon Project
|
||||
* http://www.musicpd.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "../output/raop_output_plugin.h"
|
||||
#include "../output_plugin.h"
|
||||
#include "../mixer_api.h"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
struct raop_mixer_plugin {
|
||||
struct mixer base;
|
||||
struct raop_data *rd;
|
||||
};
|
||||
|
||||
static struct mixer *
|
||||
raop_mixer_init(void *ao, G_GNUC_UNUSED const struct config_param *param,
|
||||
G_GNUC_UNUSED GError **error_r)
|
||||
{
|
||||
struct raop_mixer_plugin *rm = g_new(struct raop_mixer_plugin, 1);
|
||||
rm->rd = (struct raop_data *) ao;
|
||||
mixer_init(&rm->base, &raop_mixer_plugin);
|
||||
|
||||
return &rm->base;
|
||||
}
|
||||
|
||||
static void
|
||||
raop_mixer_finish(struct mixer *data)
|
||||
{
|
||||
struct raop_mixer_plugin *rm = (struct raop_mixer_plugin *) data;
|
||||
|
||||
g_free(rm);
|
||||
}
|
||||
|
||||
static int
|
||||
raop_mixer_get_volume(struct mixer *mixer, G_GNUC_UNUSED GError **error_r)
|
||||
{
|
||||
struct raop_mixer_plugin *rm = (struct raop_mixer_plugin *)mixer;
|
||||
return raop_get_volume(rm->rd);
|
||||
}
|
||||
|
||||
static bool
|
||||
raop_mixer_set_volume(struct mixer *mixer, unsigned volume, G_GNUC_UNUSED GError **error_r)
|
||||
{
|
||||
struct raop_mixer_plugin *rm = (struct raop_mixer_plugin *)mixer;
|
||||
g_debug("raop_mixer_set_volume\n");
|
||||
return raop_set_volume(rm->rd, volume);
|
||||
}
|
||||
|
||||
const struct mixer_plugin raop_mixer_plugin = {
|
||||
.init = raop_mixer_init,
|
||||
.finish = raop_mixer_finish,
|
||||
.get_volume = raop_mixer_get_volume,
|
||||
.set_volume = raop_mixer_set_volume,
|
||||
};
|
@@ -29,6 +29,7 @@ extern const struct mixer_plugin software_mixer_plugin;
|
||||
extern const struct mixer_plugin alsa_mixer_plugin;
|
||||
extern const struct mixer_plugin oss_mixer_plugin;
|
||||
extern const struct mixer_plugin pulse_mixer_plugin;
|
||||
extern const struct mixer_plugin raop_mixer_plugin;
|
||||
extern const struct mixer_plugin winmm_mixer_plugin;
|
||||
|
||||
#endif
|
||||
|
1427
src/output/raop_output_plugin.c
Normal file
1427
src/output/raop_output_plugin.c
Normal file
File diff suppressed because it is too large
Load Diff
159
src/output/raop_output_plugin.h
Normal file
159
src/output/raop_output_plugin.h
Normal file
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2010 The Music Player Daemon Project
|
||||
* http://www.musicpd.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef MPD_OUTPUT_RAOP_PLUGIN_H
|
||||
#define MPD_OUTPUT_RAOP_PLUGIN_H
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdbool.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/time.h>
|
||||
#include <openssl/aes.h>
|
||||
|
||||
struct key_data {
|
||||
unsigned char *key;
|
||||
unsigned char *data;
|
||||
struct key_data *next;
|
||||
};
|
||||
|
||||
struct play_state {
|
||||
bool playing;
|
||||
unsigned short seq_num;
|
||||
unsigned int rtptime;
|
||||
unsigned int sync_src;
|
||||
unsigned int start_rtptime;
|
||||
struct timeval start_time;
|
||||
struct timeval last_send;
|
||||
};
|
||||
|
||||
/*********************************************************************/
|
||||
|
||||
struct rtspcl_data {
|
||||
int fd;
|
||||
char url[128];
|
||||
int cseq;
|
||||
struct key_data *kd;
|
||||
struct key_data *exthds;
|
||||
char *session;
|
||||
char *transport;
|
||||
unsigned short server_port;
|
||||
unsigned short control_port;
|
||||
struct in_addr host_addr;
|
||||
struct in_addr local_addr;
|
||||
const char *useragent;
|
||||
|
||||
};
|
||||
|
||||
enum pause_state {
|
||||
NO_PAUSE = 0,
|
||||
OP_PAUSE,
|
||||
NODATA_PAUSE,
|
||||
};
|
||||
|
||||
#define MINIMUM_SAMPLE_SIZE 32
|
||||
|
||||
#define RAOP_FD_READ (1<<0)
|
||||
#define RAOP_FD_WRITE (1<<1)
|
||||
|
||||
/*********************************************************************/
|
||||
|
||||
struct encrypt_data {
|
||||
AES_KEY ctx;
|
||||
unsigned char iv[16]; // initialization vector for aes-cbc
|
||||
unsigned char nv[16]; // next vector for aes-cbc
|
||||
unsigned char key[16]; // key for aes-cbc
|
||||
};
|
||||
|
||||
/*********************************************************************/
|
||||
|
||||
struct ntp_data {
|
||||
unsigned short port;
|
||||
int fd;
|
||||
};
|
||||
|
||||
/*********************************************************************/
|
||||
|
||||
struct raop_data {
|
||||
struct rtspcl_data *rtspcl;
|
||||
const char *addr; // target host address
|
||||
short rtsp_port;
|
||||
struct sockaddr_in ctrl_addr;
|
||||
struct sockaddr_in data_addr;
|
||||
|
||||
bool is_master;
|
||||
struct raop_data *next;
|
||||
|
||||
unsigned volume;
|
||||
|
||||
pthread_mutex_t control_mutex;
|
||||
|
||||
bool started;
|
||||
bool paused;
|
||||
};
|
||||
|
||||
/*********************************************************************/
|
||||
|
||||
struct control_data {
|
||||
unsigned short port;
|
||||
int fd;
|
||||
};
|
||||
|
||||
bool
|
||||
send_control_command(struct control_data *ctrl, struct raop_data *rd, struct play_state *state);
|
||||
|
||||
/*********************************************************************/
|
||||
|
||||
#define NUMSAMPLES 352
|
||||
#define RAOP_BUFFER_SIZE NUMSAMPLES * 4
|
||||
#define RAOP_HEADER_SIZE 12
|
||||
#define ALAC_MAX_HEADER_SIZE 8
|
||||
#define RAOP_MAX_PACKET_SIZE RAOP_BUFFER_SIZE + RAOP_HEADER_SIZE + ALAC_MAX_HEADER_SIZE
|
||||
|
||||
// session
|
||||
struct raop_session_data {
|
||||
struct raop_data *raop_list;
|
||||
struct ntp_data ntp;
|
||||
struct control_data ctrl;
|
||||
struct encrypt_data encrypt;
|
||||
struct play_state play_state;
|
||||
|
||||
int data_fd;
|
||||
|
||||
unsigned char buffer[RAOP_BUFFER_SIZE];
|
||||
size_t bufferSize;
|
||||
|
||||
unsigned char data[RAOP_MAX_PACKET_SIZE];
|
||||
int wblk_wsize;
|
||||
int wblk_remsize;
|
||||
|
||||
pthread_mutex_t data_mutex;
|
||||
pthread_mutex_t list_mutex;
|
||||
};
|
||||
|
||||
//static struct raop_session_data *raop_session;
|
||||
|
||||
/*********************************************************************/
|
||||
|
||||
bool
|
||||
raop_set_volume(struct raop_data *rd, unsigned volume);
|
||||
|
||||
int
|
||||
raop_get_volume(struct raop_data *rd);
|
||||
|
||||
#endif
|
@@ -30,6 +30,7 @@ extern const struct audio_output_plugin ao_output_plugin;
|
||||
extern const struct audio_output_plugin oss_output_plugin;
|
||||
extern const struct audio_output_plugin openal_output_plugin;
|
||||
extern const struct audio_output_plugin osxPlugin;
|
||||
extern const struct audio_output_plugin raopPlugin;
|
||||
extern const struct audio_output_plugin solaris_output_plugin;
|
||||
extern const struct audio_output_plugin pulse_output_plugin;
|
||||
extern const struct audio_output_plugin mvp_output_plugin;
|
||||
@@ -65,6 +66,9 @@ const struct audio_output_plugin *audio_output_plugins[] = {
|
||||
#ifdef HAVE_OSX
|
||||
&osxPlugin,
|
||||
#endif
|
||||
#ifdef ENABLE_RAOP_OUTPUT
|
||||
&raopPlugin,
|
||||
#endif
|
||||
#ifdef ENABLE_SOLARIS_OUTPUT
|
||||
&solaris_output_plugin,
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user