Merge pull request #4857 from t-nelson/Gotham_13.2_backports
[vuplus_xbmc] / xbmc / network / AirTunesServer.h
1 #pragma once
2 /*
3  * Many concepts and protocol specification in this code are taken from
4  * the Boxee project. http://www.boxee.tv
5  *
6  *      Copyright (C) 2011-2013 Team XBMC
7  *      http://xbmc.org
8  *
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)
12  *  any later version.
13  *
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.
18  *
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/>.
22  *
23  */
24 #include "system.h"
25
26 #ifdef HAS_AIRTUNES
27
28 #if defined(HAVE_LIBSHAIRPLAY)
29 #include "DllLibShairplay.h"
30 #else
31 #include "DllLibShairport.h"
32 #endif
33 #include <sys/types.h>
34 #include <sys/socket.h>
35 #include <netinet/in.h>
36 #include <arpa/inet.h>
37 #include <string>
38 #include <vector>
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"
45
46 class DllLibShairport;
47
48
49 class CAirTunesServer : public CThread, public ANNOUNCEMENT::IAnnouncer
50 {
51 public:
52   virtual void Announce(ANNOUNCEMENT::AnnouncementFlag flag, const char *sender, const char *message, const CVariant &data);
53
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);
59
60 protected:
61   void Process();
62
63 private:
64   CAirTunesServer(int port, bool nonlocal);
65   ~CAirTunesServer();
66   bool Initialize(const CStdString &password);
67   void Deinitialize();
68   static void RefreshCoverArt();
69   static void RefreshMetadata();
70
71   int m_port;
72 #if defined(HAVE_LIBSHAIRPLAY)
73   static DllLibShairplay *m_pLibShairplay;//the lib
74   raop_t *m_pRaop;
75   XFILE::CPipeFile *m_pPipe;
76 #else
77   static DllLibShairport *m_pLibShairport;//the lib
78 #endif
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;
84
85   class AudioOutputFunctions
86   {
87     public:
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);
96 #else
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,
102                                       ao_option *option);
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);      
110 #endif
111     };
112 };
113
114 #endif