summaryrefslogtreecommitdiffstats
path: root/src/avremote.h
blob: 66e5347d300ec8bce2c2267048452ae1b778ebd7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* AVRemote
   
 (c) 2011 Nederlands Instituut voor Mediakunst (NIMk)
     2011 Denis Roio <jaromil@nimk.nl>

     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU Affero General Public License as
     published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
     
     You should have received a copy of the GNU Affero General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>

*/

#ifndef __AVREMOTE_H__
#define __AVREMOTE_H__

// messages get rendered in this structure
// allocated and freed with create/free_upnp
typedef struct {
  char *hostname;
  int port;
  int sockfd;

  char *hdr;
  size_t hdrlen;

  char *msg;
  size_t msglen;

  char *res;
  size_t reslen;

  char *meta;

} upnp_t;

// format (printf style) to be used when generating xml markup
#define UPNP_MSG_FORMAT "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" \
  "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"" \
  "xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n<s:Body>\r\n" \
  "<u:%s xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\">\r\n"	\
  "<InstanceID>0</InstanceID>\r\n%s\r\n</u:%s>\r\n</s:Body>\r\n</s:Envelope>\r\n"

#define UPNP_HDR_FORMAT "POST /MediaRenderer_AVTransport/control HTTP/1.0\r\n" \
	   "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#%s\"\r\n" \
	   "CONTENT-TYPE: text/xml ; charset=\"utf-8\"\r\n" \
	   "HOST: %s:%u\r\n" \
	   "Connection: close\r\n" \
	   "Content-Length: %u\r\n" \
	   "\r\n"

#define UPNP_META_FORMAT "<CurrentURI>%s</CurrentURI>" \
  "<CurrentURIMetaData><DIDL-Lite xmlns=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite\"" \
  "xmlns:dc=\"http://purl.org/dc/elements/1.1/\"" \
  "xmlns:upnp=\"urn:schemas-upnp-org:metadata-1-0/upnp/\">" \
  "<item id=\"2%s\" parentID=\"2%s\" restricted=\"0\">" \
  "<dc:title>%s</dc:title><dc:date></dc:date>" \
  "<upnp:class>object.item.imageItem</upnp:class><dc:creator></dc:creator>" \
  "<upnp:genre></upnp:genre><upnp:artist></upnp:artist><upnp:album></upnp:album>" \
  "<res protocolInfo=\"file-get:*:*:*:DLNA.ORG_OP=01;DLNA.ORG_CI=0;" \
  "DLNA.ORG_FLAGS=00000000001000000000000000000000\" protection=\"\" tokenType=\"0\" " \
  "bitrate=\"0\" duration=\"\" size=\"%u\" colorDepth=\"0\" ifoFileURI=\"\" " \
  "resolution=\"\">%s</res></item></DIDL-Lite></CurrentURIMetaData>"

upnp_t *create_upnp();
void free_upnp(upnp_t *upnp);

int connect_upnp(upnp_t *upnp, char *hostname, int port);

/*
Available AVTransport actions:

GetCurrentTransportActions
GetDeviceCapabilities
GetMediaInfo
GetPositionInfo
GetTransportInfo
GetTransportSettings
Next
Pause
Play
Previous
Seek <SeekMode> <SeekTarget> (allowed SeekMode: "X_DLNA_REL_BYTE", "REL_TIME", "TRACK_NR")
SetAVTransportURI <URI> <URIMetaData> (allowed URI: "http://server/file", "file:///folder/file"
SetPlayMode <NewPlayMode> (allowed NewPlayMode = "NORMAL", "REPEAT_ONE", "REPEAT_ALL", "RANDOM")
Stop
X_DLNA_GetBytePositionInfo

Available RenderingControl actions:

GetMute
GetVolume
SetMute <DesiredMute> (allowed DesiredMute = 0 or 1)
SetVolume <DesiredVolume> (allowed DesiredVolume = 1 to 100)
*/
   
void render_upnp(upnp_t *upnp, char *action, char *arg);
void render_uri_meta(upnp_t *upnp, char *path);

int send_upnp(upnp_t *upnp);
int recv_upnp(upnp_t *upnp);
int print_upnp(upnp_t *upnp);

#endif