Support gles animation.
[vuplus_openvuplus] / meta-openvuplus / recipes-support / libshairport / libshairport / 010_handle_metadata.patch
1 diff -ruP src/ao.h libshairport.new/src/ao.h
2 --- src/ao.h    2012-05-07 22:26:53.000000000 +0200
3 +++ src/ao.h    2012-05-08 18:46:42.000000000 +0200
4 @@ -152,5 +152,7 @@
5        /* -- Device Setup/Playback/Teardown -- */                                                                                                                                                                 
6        int (*ao_append_option)(ao_option **, const char *, const char *);                                                                                                                                         
7        void (*ao_free_options)(ao_option *);                                                                                                                                                                      
8 -      char* (*ao_get_option)(ao_option *, const char* );                                                                                                                                                         
9 +      char* (*ao_get_option)(ao_option *, const char* );
10 +      void (*ao_set_metadata)(const char *buffer, unsigned int size);                                                                                                                                                         
11 +      void (*ao_set_metadata_coverart)(const char *buffer, unsigned int size);
12    }; 
13 diff -ruP src/hairtunes.c src/hairtunes.c
14 --- src/hairtunes.c     2012-05-07 22:26:53.000000000 +0200
15 +++ src/hairtunes.c     2012-05-08 18:45:51.000000000 +0200
16 @@ -267,6 +267,16 @@
17    fix_volume = 65536.0 * volume;
18  }
19  
20 +void hairtunes_set_metadata(const char *buffer, unsigned int size)
21 +{
22 +  g_ao.ao_set_metadata(buffer, size);
23 +}
24 +
25 +void hairtunes_set_metadata_coverart(const char *buffer, unsigned int size)
26 +{
27 +  g_ao.ao_set_metadata_coverart(buffer, size);
28 +}
29 +
30  void hairtunes_flush(void)
31  {
32    pthread_mutex_lock(&ab_mutex);
33 diff -ruP src/hairtunes.h src/hairtunes.h
34 --- src/hairtunes.h     2011-08-21 00:06:21.000000000 +0200
35 +++ src/hairtunes.h     2012-05-08 18:46:00.000000000 +0200
36 @@ -4,6 +4,8 @@
37  int hairtunes_init(char *pAeskey, char *pAesiv, char *pFmtpstr, int pCtrlPort, int pTimingPort,
38           int pDataPort, char *pRtpHost, char*pPipeName, char *pLibaoDriver, char *pLibaoDeviceName, char *pLibaoDeviceId);
39  void hairtunes_setvolume(float vol);
40 +void hairtunes_set_metadata(const char *buffer, unsigned int size);
41 +void hairtunes_set_metadata_coverart(const char *buffer, unsigned int size);
42  void hairtunes_flush(void);
43  void hairtunes_cleanup(void);
44  
45 diff -ruP src/shairport.c src/shairport.c
46 --- src/shairport.c     2012-05-07 22:26:53.000000000 +0200
47 +++ src/shairport.c     2012-05-08 18:45:30.000000000 +0200
48 @@ -513,7 +513,8 @@
49      while(1 == tMoreDataNeeded)
50      {
51        tError = readDataFromClient(pSock, &(tConn.recv));
52 -      if(!tError && strlen(tConn.recv.data) > 0)
53 +      //if(!tError && strlen(tConn.recv.data) > 0)
54 +      if(!tError && tConn.recv.current > 0)
55        {
56          xprintf("Finished Reading some data from client\n");
57          // parse client request
58 @@ -632,7 +633,7 @@
59      }
60      
61      tSize = (int) (tShortest - tFound);
62 -    xprintf("Found %.*s  length: %d\n", tSize, tFound, tSize);
63 +    xprintf("Found %s  length: %d\n",tFound, tSize);
64      if(pReturnSize != NULL)
65      {
66        *pReturnSize = tSize;
67 @@ -744,7 +745,7 @@
68    if(tContent != NULL)
69    {
70      int tContentSize = atoi(tContent);
71 -    if(pConn->recv.marker == 0 || strlen(pConn->recv.data+pConn->recv.marker) != tContentSize)
72 +    if(pConn->recv.marker == 0 || pConn->recv.current-pConn->recv.marker != tContentSize)
73      {
74        if(isLogEnabledFor(HEADER_LOG_LEVEL))
75        {
76 @@ -752,7 +753,7 @@
77          if(pConn->recv.marker != 0)
78          {
79            xprintf("ContentPtr has %d, but needs %d\n", 
80 -                  strlen(pConn->recv.data+pConn->recv.marker), tContentSize);
81 +                  (pConn->recv.current-pConn->recv.marker), tContentSize);
82          }
83        }
84        // check if value in tContent > 2nd read from client.
85 @@ -989,15 +990,67 @@
86    {
87      propogateCSeq(pConn);
88      int tSize = 0;
89 +    char *buffer = NULL;
90 +    char *contentType = getFromHeader(pConn->recv.data, "Content-Type", &tSize);
91 +    char *tContent = getFromHeader(pConn->recv.data, "Content-Length", NULL);
92 +    int iContentSize = 0;
93 +    int isJpg = 0;
94 +    
95 +    if(tContent != NULL)
96 +    {
97 +      iContentSize = atoi(tContent);
98 +    }
99 +
100 +    if( tSize > 1 && 
101 +        (strncmp(contentType, "application/x-dmap-tagged", tSize) == 0) ||
102 +        (strncmp(contentType, "image/jpeg", tSize) == 0)                 )
103 +    {
104 +      if( (pConn->recv.current - pConn->recv.marker) == iContentSize && pConn->recv.marker != 0)
105 +      {
106 +        if(strncmp(contentType, "image/jpeg", tSize) == 0)
107 +        {
108 +          isJpg = 1;
109 +        }
110 +        buffer = (char *)malloc(iContentSize * sizeof(char));
111 +        memcpy(buffer, pConn->recv.data + pConn->recv.marker, iContentSize);                                                                                                                                     
112 +      }
113 +      else
114 +      {
115 +        iContentSize = 0;
116 +      }
117 +    }
118 +    else
119 +    {
120 +      iContentSize = 0;
121 +    }
122      char *tVol = getFromHeader(pConn->recv.data, "volume", &tSize);
123 -    xprintf("About to write [vol: %.*s] data to hairtunes\n", tSize, tVol);
124 +    if( tVol)
125 +    {
126 +      xprintf("About to write [vol: %.*s] data to hairtunes\n", tSize, tVol);
127 +    }
128      // TBD VOLUME
129  #ifndef XBMC
130      write(pConn->hairtunes->in[1], "vol: ", 5);
131      write(pConn->hairtunes->in[1], tVol, tSize);
132      write(pConn->hairtunes->in[1], "\n", 1);
133  #else
134 -    hairtunes_setvolume(atof(tVol));
135 +    if(tVol)
136 +    {
137 +      hairtunes_setvolume(atof(tVol));
138 +    }
139 +    
140 +    if(iContentSize)
141 +    {
142 +      if(isJpg)
143 +      {
144 +        hairtunes_set_metadata_coverart(buffer, iContentSize);      
145 +      }
146 +      else
147 +      {
148 +        hairtunes_set_metadata(buffer, iContentSize);
149 +      }
150 +      free(buffer);
151 +    }
152  #endif
153      xprintf("Finished writing data write data to hairtunes\n");
154    }