3 * Many concepts and protocol specification in this code are taken from
4 * the Boxee project. http://www.boxee.tv
6 * Copyright (C) 2011-2013 Team XBMC
9 * This Program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
14 * This Program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with XBMC; see the file COPYING. If not, see
21 * <http://www.gnu.org/licenses/>.
28 #if defined(HAVE_LIBSHAIRPLAY)
29 #include "DllLibShairplay.h"
31 #include "DllLibShairport.h"
33 #include <sys/types.h>
34 #include <sys/socket.h>
35 #include <netinet/in.h>
36 #include <arpa/inet.h>
39 #include "threads/Thread.h"
40 #include "threads/CriticalSection.h"
41 #include "utils/HttpParser.h"
42 #include "utils/StdString.h"
43 #include "filesystem/PipeFile.h"
44 #include "interfaces/IAnnouncer.h"
46 class DllLibShairport;
49 class CAirTunesServer : public CThread, public ANNOUNCEMENT::IAnnouncer
52 virtual void Announce(ANNOUNCEMENT::AnnouncementFlag flag, const char *sender, const char *message, const CVariant &data);
54 static bool StartServer(int port, bool nonlocal, bool usePassword, const CStdString &password="");
55 static void StopServer(bool bWait);
56 static bool IsRunning();
57 static void SetMetadataFromBuffer(const char *buffer, unsigned int size);
58 static void SetCoverArtFromBuffer(const char *buffer, unsigned int size);
64 CAirTunesServer(int port, bool nonlocal);
66 bool Initialize(const CStdString &password);
68 static void RefreshCoverArt();
69 static void RefreshMetadata();
72 #if defined(HAVE_LIBSHAIRPLAY)
73 static DllLibShairplay *m_pLibShairplay;//the lib
75 XFILE::CPipeFile *m_pPipe;
77 static DllLibShairport *m_pLibShairport;//the lib
79 static CAirTunesServer *ServerInstance;
80 static CStdString m_macAddress;
81 static CCriticalSection m_metadataLock;
82 static std::string m_metadata[3];//0 - album, 1 - title, 2 - artist
83 static bool m_streamStarted;
85 class AudioOutputFunctions
88 #if defined(HAVE_LIBSHAIRPLAY)
89 static void* audio_init(void *cls, int bits, int channels, int samplerate);
90 static void audio_set_volume(void *cls, void *session, float volume);
91 static void audio_set_metadata(void *cls, void *session, const void *buffer, int buflen);
92 static void audio_set_coverart(void *cls, void *session, const void *buffer, int buflen);
93 static void audio_process(void *cls, void *session, const void *buffer, int buflen);
94 static void audio_flush(void *cls, void *session);
95 static void audio_destroy(void *cls, void *session);
97 static void ao_initialize(void);
98 static void ao_set_volume(float volume);
99 static int ao_play(ao_device *device, char *output_samples, uint32_t num_bytes);
100 static int ao_default_driver_id(void);
101 static ao_device* ao_open_live( int driver_id, ao_sample_format *format,
103 static int ao_close(ao_device *device);
104 /* -- Device Setup/Playback/Teardown -- */
105 static int ao_append_option(ao_option **options, const char *key, const char *value);
106 static void ao_free_options(ao_option *options);
107 static char* ao_get_option(ao_option *options, const char* key);
108 static void ao_set_metadata(const char *buffer, unsigned int size);
109 static void ao_set_metadata_coverart(const char *buffer, unsigned int size);