annotate libmpdemux/asf_streaming.c @ 3477:9e7289fdc471

ize ... majd gabu ide irja. ilyen fullscreenben mouse button press - re jon elo main window.
author pontscho
date Wed, 12 Dec 2001 23:15:15 +0000
parents 390388c75209
children fb9de639ed30
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
1 #include <stdio.h>
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
2 #include <stdlib.h>
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
3 #include <string.h>
1430
1728d249c783 missing unistd.h (requires for off_t under freebsd)
arpi
parents: 1340
diff changeset
4 #include <unistd.h>
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
5
2555
66837325b929 config.h cleanup, few things added to steram/demuxer headers
arpi
parents: 2489
diff changeset
6 #include "config.h"
66837325b929 config.h cleanup, few things added to steram/demuxer headers
arpi
parents: 2489
diff changeset
7
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
8 #include "url.h"
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
9 #include "http.h"
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
10 #include "asf.h"
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
11 #include "network.h"
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
12
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
13 #include "stream.h"
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
14
3454
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
15 typedef struct {
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
16 ASF_StreamType_e streaming_type;
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
17 int request;
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
18 } asf_http_streaming_ctrl_t;
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
19
3475
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
20 #ifdef ARCH_X86
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
21 #define ASF_LOAD_GUID_PREFIX(guid) (*(uint32_t *)(guid))
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
22 #else
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
23 #define ASF_LOAD_GUID_PREFIX(guid) \
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
24 ((guid)[3] << 24 | (guid)[2] << 16 | (guid)[1] << 8 | (guid)[0])
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
25 #endif
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
26
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
27
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
28
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
29 // ASF streaming support several network protocol.
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
30 // One use UDP, not known, yet!
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
31 // Another is HTTP, this one is known.
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
32 // So for now, we use the HTTP protocol.
3454
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
33 //
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
34 // We can try several protocol for asf streaming
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
35 // * first the UDP protcol, if there is a firewall, UDP
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
36 // packets will not come back, so the mmsu will failed.
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
37 // * Then we can try TCP, but if there is a proxy for
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
38 // internet connection, the TCP connection will not get
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
39 // through
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
40 // * Then we can try HTTP.
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
41 int
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
42 asf_streaming_start( stream_t *stream ) {
3454
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
43 char proto_s[10];
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
44 int fd = -1;
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
45
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
46 strncpy( proto_s, stream->streaming_ctrl->url->protocol, 10 );
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
47
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
48 if( !strncasecmp( proto_s, "mms", 3) && strncasecmp( proto_s, "mmst", 4) ) {
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
49 printf("Trying ASF/UDP...\n");
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
50 //fd = asf_mmsu_streaming_start( stream );
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
51 if( fd!=-1 ) return fd;
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
52 printf(" ===> ASF/UDP failed\n");
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
53 }
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
54 if( !strncasecmp( proto_s, "mms", 3) ) {
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
55 printf("Trying ASF/TCP...\n");
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
56 //fd = asf_mmst_streaming_start( stream );
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
57 if( fd!=-1 ) return fd;
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
58 printf(" ===> ASF/TCP failed\n");
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
59 }
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
60 if( !strncasecmp( proto_s, "http", 4) || !strncasecmp( proto_s, "mms", 3) ) {
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
61 printf("Trying ASF/HTTP...\n");
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
62 fd = asf_http_streaming_start( stream );
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
63 if( fd!=-1 ) return fd;
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
64 printf(" ===> ASF/HTTP failed\n");
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
65 }
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
66
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
67 printf("Unknown protocol: %s\n", proto_s );
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
68 return -1;
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
69 }
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
70
3475
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
71 static int
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
72 asf_streaming_parse_header(char* buffer,int size) {
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
73 ASF_header_t asfh;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
74 ASF_obj_header_t objh;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
75 ASF_file_header_t fileh;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
76 int pos = 0;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
77
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
78 if(size < (int)sizeof(asfh)) {
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
79 printf("Error chunk is too small\n");
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
80 return -1;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
81 }
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
82 memcpy(&asfh,buffer,sizeof(asfh));
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
83 le2me_ASF_header_t(&asfh);
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
84 if(size < (int)asfh.objh.size) {
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
85 printf("Error chunk is too small\n");
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
86 return -1;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
87 }
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
88
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
89 if(asfh.cno > 256) {
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
90 printf("Error sub chunks number is invalid\n");
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
91 return -1;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
92 }
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
93
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
94 pos += sizeof(asfh);
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
95
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
96 while(size - pos >= (int)sizeof(objh)) {
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
97 memcpy(&objh,buffer+pos,sizeof(objh));
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
98 le2me_ASF_obj_header_t(&objh);
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
99
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
100 if(ASF_LOAD_GUID_PREFIX(objh.guid) == 0x8CABDCA1) {
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
101 pos += sizeof(objh);
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
102 memcpy(&fileh,buffer + pos,sizeof(fileh));
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
103 le2me_ASF_file_header_t(&fileh);
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
104 return fileh.packetsize == fileh.packetsize2 ? fileh.packetsize : -1;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
105 } else {
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
106 pos += objh.size;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
107 }
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
108 }
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
109
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
110 return -1;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
111 }
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
112
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
113 int
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
114 asf_http_streaming_read( int fd, char *buffer, int size, streaming_ctrl_t *streaming_ctrl ) {
3475
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
115 static ASF_stream_chunck_t chunk;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
116 int read,chunk_size = 0;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
117 static int rest = 0, drop_chunk = 0, waiting = 0;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
118 static int asf_packetsize = 0;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
119
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
120 while(1) {
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
121 if (rest == 0 && waiting == 0) {
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
122 read = 0;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
123 while(read < (int)sizeof(ASF_stream_chunck_t)){
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
124 int r = nop_streaming_read( fd, ((char*)&chunk) + read,
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
125 sizeof(ASF_stream_chunck_t)-read,
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
126 streaming_ctrl );
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
127 if(r < 0){
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
128 printf("End of stream without a full chunk header\n");
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
129 return -1;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
130 }
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
131 read += r;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
132 }
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
133 chunk_size = asf_streaming( (char*)&chunk, read, &drop_chunk );
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
134 if(chunk_size < 0) {
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
135 printf("Error while parsing chunk header\n");
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
136 return -1;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
137 }
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
138 chunk_size -= sizeof(ASF_stream_chunck_t);
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
139
3475
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
140 if(asf_packetsize && (!drop_chunk)) {
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
141 if (asf_packetsize < chunk_size) {
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
142 printf("Error chunk_size > asf_packetsize\n");
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
143 return -1;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
144 }
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
145 waiting = asf_packetsize;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
146 } else {
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
147 waiting = chunk_size;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
148 }
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
149
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
150 } else if (rest){
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
151 chunk_size = rest;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
152 rest = 0;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
153 }
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
154
3475
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
155 read = 0;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
156 if ( waiting >= chunk_size) {
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
157 if (chunk_size > size){
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
158 rest = chunk_size - size;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
159 chunk_size = size;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
160 }
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
161 while(read < chunk_size) {
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
162 int got = nop_streaming_read( fd,buffer+read,chunk_size-read,streaming_ctrl );
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
163 if(got < 0) {
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
164 printf("Error while reading chunk EOF ?\n");
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
165 return -1;
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
166 }
3475
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
167 read += got;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
168 }
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
169 waiting -= read;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
170 if (drop_chunk) continue;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
171 }
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
172 if (rest == 0 && waiting > 0 && size-read > 0) {
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
173 int s = MIN(waiting,size-read);
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
174 memset(buffer+read,0,s);
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
175 waiting -= s;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
176 read += s;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
177 }
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
178 break;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
179 }
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
180
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
181 if (chunk.type == 0x4824) { // Header
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
182 static char* save_buffer = NULL;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
183 static int save_pos = 0,save_size = 0;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
184 if(rest > 0 || save_buffer) {
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
185 if(save_buffer == NULL){
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
186 save_size = read+rest;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
187 save_pos = 0;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
188 save_buffer = (char*)malloc(save_size);
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
189 }
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
190 memcpy(save_buffer+save_pos,buffer,MIN(read,save_size-save_pos));
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
191 save_pos += MIN(read,save_size-save_pos);
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
192 }
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
193 if( rest == 0 ){
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
194 if(save_buffer && save_pos != save_size){
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
195 printf("Header buffer inconsitency\n");
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
196 return -1;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
197 }
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
198 asf_packetsize = asf_streaming_parse_header(save_buffer ? save_buffer : buffer,
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
199 save_buffer ? save_pos : read);
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
200 if(save_buffer) {
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
201 free(save_buffer);
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
202 save_buffer = NULL;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
203 }
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
204 if(asf_packetsize < 0) {
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
205 printf("Error during header parsing\n");
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
206 return -1;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
207 }
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
208 }
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
209 }
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
210 return read;
2489
0ecc1b4f7cf8 Added ASF http server streaming (Not mms streaming).
bertrand
parents: 2310
diff changeset
211 }
0ecc1b4f7cf8 Added ASF http server streaming (Not mms streaming).
bertrand
parents: 2310
diff changeset
212
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
213 int
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
214 asf_streaming(char *data, int length, int *drop_packet ) {
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
215 ASF_stream_chunck_t *stream_chunck=(ASF_stream_chunck_t*)data;
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
216 /*
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
217 printf("ASF stream chunck size=%d\n", stream_chunck->size);
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
218 printf("length: %d\n", length );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
219 printf("0x%02X\n", stream_chunck->type );
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
220 */
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
221 if( data==NULL || length<=0 ) return -1;
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
222 if( drop_packet!=NULL ) *drop_packet = 0;
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
223
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
224 if( stream_chunck->size<8 ) {
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
225 printf("Ahhhh, stream_chunck size is too small: %d\n", stream_chunck->size);
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
226 return -1;
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
227 }
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
228 if( stream_chunck->size!=stream_chunck->size_confirm ) {
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
229 printf("size_confirm mismatch!: %d %d\n", stream_chunck->size, stream_chunck->size_confirm);
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
230 return -1;
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
231 }
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
232 /*
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
233 printf(" type: 0x%02X\n", stream_chunck->type );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
234 printf(" size: %d (0x%02X)\n", stream_chunck->size, stream_chunck->size );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
235 printf(" sequence_number: 0x%04X\n", stream_chunck->sequence_number );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
236 printf(" unknown: 0x%02X\n", stream_chunck->unknown );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
237 printf(" size_confirm: 0x%02X\n", stream_chunck->size_confirm );
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
238 */
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
239 switch(stream_chunck->type) {
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
240 case 0x4324: // $C Clear ASF configuration
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
241 printf("=====> Clearing ASF stream configuration!\n");
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
242 if( drop_packet!=NULL ) *drop_packet = 1;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
243 return stream_chunck->size;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
244 break;
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
245 case 0x4424: // $D Data follows
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
246 // printf("=====> Data follows\n");
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
247 break;
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
248 case 0x4524: // $E Transfer complete
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
249 printf("=====> Transfer complete\n");
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
250 if( drop_packet!=NULL ) *drop_packet = 1;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
251 return stream_chunck->size;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
252 break;
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
253 case 0x4824: // $H ASF header chunk follows
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
254 printf("=====> ASF header chunk follows\n");
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
255 break;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
256 default:
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
257 printf("=====> Unknown stream type 0x%x\n", stream_chunck->type );
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
258 }
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
259 return stream_chunck->size+4;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
260 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
261
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
262 int
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
263 asf_http_streaming_seek( int fd, off_t pos, streaming_ctrl_t *streaming_ctrl ) {
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
264 return -1;
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
265 }
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
266
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
267 int
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
268 asf_http_streaming_type(char *content_type, char *features) {
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
269 if( content_type==NULL ) return ASF_Unknown_e;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
270 if( !strcasecmp(content_type, "application/octet-stream") ) {
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
271 if( features==NULL ) {
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
272 printf("=====> ASF Prerecorded\n");
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
273 return ASF_Prerecorded_e;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
274 } else if( strstr(features, "broadcast")) {
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
275 printf("=====> ASF Live stream\n");
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
276 return ASF_Live_e;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
277 } else {
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
278 printf("=====> ASF Prerecorded\n");
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
279 return ASF_Prerecorded_e;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
280 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
281 } else {
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
282 if( (!strcasecmp(content_type, "audio/x-ms-wax")) ||
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
283 (!strcasecmp(content_type, "audio/x-ms-wma")) ||
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
284 (!strcasecmp(content_type, "video/x-ms-asf")) ||
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
285 (!strcasecmp(content_type, "video/x-ms-afs")) ||
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
286 (!strcasecmp(content_type, "video/x-ms-wvx")) ||
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
287 (!strcasecmp(content_type, "video/x-ms-wmv")) ||
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
288 (!strcasecmp(content_type, "video/x-ms-wma")) ) {
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
289 printf("=====> ASF Redirector\n");
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
290 return ASF_Redirector_e;
2489
0ecc1b4f7cf8 Added ASF http server streaming (Not mms streaming).
bertrand
parents: 2310
diff changeset
291 } else if( !strcasecmp(content_type, "text/plain") ) {
0ecc1b4f7cf8 Added ASF http server streaming (Not mms streaming).
bertrand
parents: 2310
diff changeset
292 printf("=====> ASF Plain text\n");
0ecc1b4f7cf8 Added ASF http server streaming (Not mms streaming).
bertrand
parents: 2310
diff changeset
293 return ASF_PlainText_e;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
294 } else {
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
295 printf("=====> ASF unknown content-type: %s\n", content_type );
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
296 return ASF_Unknown_e;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
297 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
298 }
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
299 return ASF_Unknown_e;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
300 }
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
301
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
302 HTTP_header_t *
3454
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
303 //asf_http_request(URL_t *url) {
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
304 asf_http_request(streaming_ctrl_t *streaming_ctrl) {
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
305 HTTP_header_t *http_hdr;
3454
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
306 URL_t *url = streaming_ctrl->url;
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
307 asf_http_streaming_ctrl_t *asf_http_ctrl = (asf_http_streaming_ctrl_t*)streaming_ctrl->data;
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
308 char str[250];
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
309 char *ptr;
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
310 char *request;
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
311 int i;
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
312
3454
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
313 int offset_hi=0, offset_lo=0, length=0;
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
314 int asf_nb_stream;
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
315
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
316 // Common header for all requests.
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
317 http_hdr = http_new_header();
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
318 http_set_uri( http_hdr, url->file );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
319 http_set_field( http_hdr, "Accept: */*" );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
320 http_set_field( http_hdr, "User-Agent: NSPlayer/4.1.0.3856" );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
321 sprintf( str, "Host: %s:%d", url->hostname, url->port );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
322 http_set_field( http_hdr, str );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
323 http_set_field( http_hdr, "Pragma: xClientGUID={c77e7400-738a-11d2-9add-0020af0a3278}" );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
324 sprintf(str,
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
325 "Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=%u:%u,request-context=%d,max-duration=%u",
3454
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
326 offset_hi, offset_lo, asf_http_ctrl->request, length );
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
327 http_set_field( http_hdr, str );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
328
3454
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
329 switch( asf_http_ctrl->streaming_type ) {
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
330 case ASF_Live_e:
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
331 case ASF_Prerecorded_e:
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
332 http_set_field( http_hdr, "Pragma: xPlayStrm=1" );
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
333 ptr = str;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
334 ptr += sprintf( ptr, "Pragma: stream-switch-entry=");
1340
d4f1e8d0e591 demuxer struct access code temporary disabled - FIXME
arpi
parents: 1001
diff changeset
335
d4f1e8d0e591 demuxer struct access code temporary disabled - FIXME
arpi
parents: 1001
diff changeset
336 #if 0
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
337 for( i=0, asf_nb_stream=0 ; i<256 ; i++ ) {
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
338 // FIXME START
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
339 if( demuxer==NULL ) {
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
340 ptr += sprintf( ptr, " ffff:1:0" );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
341 asf_nb_stream = 1;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
342 break;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
343 }
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
344 // FIXME END
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
345 if( demuxer->a_streams[i] ) {
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
346 ptr += sprintf( ptr, " ffff:%d:0", i );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
347 asf_nb_stream++;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
348 }
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
349 if( demuxer->v_streams[i] ) {
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
350 ptr += sprintf( ptr, " ffff:%d:0", i );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
351 asf_nb_stream++;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
352 }
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
353 }
1340
d4f1e8d0e591 demuxer struct access code temporary disabled - FIXME
arpi
parents: 1001
diff changeset
354 #endif
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
355 http_set_field( http_hdr, str );
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
356 sprintf( str, "Pragma: stream-switch-count=%d", asf_nb_stream );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
357 http_set_field( http_hdr, str );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
358 break;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
359 case ASF_Redirector_e:
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
360 break;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
361 case ASF_Unknown_e:
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
362 // First request goes here.
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
363 break;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
364 default:
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
365 printf("Unknown asf stream type\n");
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
366 }
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
367
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
368 http_set_field( http_hdr, "Connection: Close" );
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
369 http_build_request( http_hdr );
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
370
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
371 return http_hdr;
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
372 }
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
373
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
374 int
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
375 asf_http_parse_response( HTTP_header_t *http_hdr ) {
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
376 char *content_type, *pragma;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
377 char features[64] = "\0";
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
378 int len;
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
379 if( http_response_parse(http_hdr)<0 ) {
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
380 printf("Failed to parse HTTP response\n");
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
381 return -1;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
382 }
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
383 if( http_hdr->status_code!=200 ) {
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
384 printf("Server return %d:%s\n", http_hdr->status_code, http_hdr->reason_phrase);
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
385 return -1;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
386 }
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
387
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
388 content_type = http_get_field( http_hdr, "Content-Type");
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
389 //printf("Content-Type: [%s]\n", content_type);
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
390
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
391 pragma = http_get_field( http_hdr, "Pragma");
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
392 while( pragma!=NULL ) {
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
393 char *comma_ptr=NULL;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
394 char *end;
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
395 //printf("Pragma: [%s]\n", pragma );
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
396 // The pragma line can get severals attributes
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
397 // separeted with a comma ','.
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
398 do {
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
399 if( !strncasecmp( pragma, "features=", 9) ) {
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
400 pragma += 9;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
401 end = strstr( pragma, "," );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
402 if( end==NULL ) {
3475
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
403 int s = strlen(pragma);
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
404 if(s > sizeof(features)) {
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
405 printf("ASF HTTP PARSE WARNING : Pragma %s cuted from %d bytes to %d\n",pragma,s,sizeof(features));
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
406 len = sizeof(features);
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
407 } else
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
408 len = s;
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
409 } else
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
410 len = MIN(end-pragma,sizeof(features));
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
411 strncpy( features, pragma, len );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
412 features[len]='\0';
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
413 break;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
414 }
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
415 comma_ptr = strstr( pragma, "," );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
416 if( comma_ptr!=NULL ) {
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
417 pragma = comma_ptr+1;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
418 if( pragma[0]==' ' ) pragma++;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
419 }
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
420 } while( comma_ptr!=NULL );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
421 pragma = http_get_next_field( http_hdr );
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
422 }
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
423
3454
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
424 return asf_http_streaming_type( content_type, features );
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
425 }
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
426
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
427 URL_t *
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
428 asf_http_ASX_redirect( HTTP_header_t *http_hdr ) {
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
429 URL_t *url_redirect=NULL;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
430 printf("=========>> ASX parser not yet implemented <<==========\n");
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
431
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
432 printf("ASX=[%s]\n", http_hdr->body );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
433
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
434 return url_redirect;
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
435 }
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
436
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
437 int
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
438 asf_http_streaming_start( stream_t *stream ) {
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
439 HTTP_header_t *http_hdr=NULL;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
440 URL_t *url_next=NULL;
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
441 URL_t *url = stream->streaming_ctrl->url;
3454
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
442 asf_http_streaming_ctrl_t *asf_http_ctrl;
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
443 ASF_StreamType_e streaming_type;
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
444 char buffer[BUFFER_SIZE];
3454
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
445 unsigned int port;
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
446 int i, ret;
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
447 int fd = stream->fd;
3454
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
448 int done;
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
449
3454
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
450 asf_http_ctrl = (asf_http_streaming_ctrl_t*)malloc(sizeof(asf_http_streaming_ctrl_t));
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
451 if( asf_http_ctrl==NULL ) {
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
452 printf("Memory allocation failed\n");
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
453 return -1;
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
454 }
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
455 asf_http_ctrl->streaming_type = ASF_Unknown_e;
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
456 asf_http_ctrl->request = 1;
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
457 stream->streaming_ctrl->data = (void*)asf_http_ctrl;
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
458
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
459 //streaming_type = ASF_Live_e;
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
460 do {
3454
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
461 done = 1;
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
462 if( fd>0 ) close( fd );
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
463
3454
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
464 if( url->port==0 ) url->port = 80;
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
465 fd = connect2Server( url->hostname, url->port );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
466 if( fd<0 ) return -1;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
467
3454
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
468 //http_hdr = asf_http_request( url );
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
469 http_hdr = asf_http_request( stream->streaming_ctrl );
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
470 printf("Request [%s]\n", http_hdr->buffer );
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
471 write( fd, http_hdr->buffer, http_hdr->buffer_size );
3475
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
472 printf("1\n");
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
473 // http_free( http_hdr );
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
474 printf("2\n");
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
475
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
476 http_hdr = http_new_header();
3475
390388c75209 Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents: 3454
diff changeset
477 printf("3\n");
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
478 do {
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
479 i = read( fd, buffer, BUFFER_SIZE );
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
480 printf("read: %d\n", i );
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
481 if( i<0 ) {
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
482 perror("read");
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
483 http_free( http_hdr );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
484 return -1;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
485 }
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
486 http_response_append( http_hdr, buffer, i );
2489
0ecc1b4f7cf8 Added ASF http server streaming (Not mms streaming).
bertrand
parents: 2310
diff changeset
487 } while( !http_is_header_entire( http_hdr ) );
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
488 http_hdr->buffer[http_hdr->buffer_size]='\0';
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
489 printf("Response [%s]\n", http_hdr->buffer );
3454
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
490 streaming_type = asf_http_parse_response(http_hdr);
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
491 if( streaming_type<0 ) {
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
492 printf("Failed to parse header\n");
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
493 http_free( http_hdr );
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
494 return -1;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
495 }
3454
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
496 asf_http_ctrl->streaming_type = streaming_type;
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
497 switch( streaming_type ) {
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
498 case ASF_Live_e:
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
499 case ASF_Prerecorded_e:
2489
0ecc1b4f7cf8 Added ASF http server streaming (Not mms streaming).
bertrand
parents: 2310
diff changeset
500 case ASF_PlainText_e:
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
501 if( http_hdr->body_size>0 ) {
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
502 if( streaming_bufferize( stream->streaming_ctrl, http_hdr->body, http_hdr->body_size )<0 ) {
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
503 http_free( http_hdr );
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
504 return -1;
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
505 }
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
506 }
3454
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
507 if( asf_http_ctrl->request==1 ) {
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
508 // First request, we only got the ASF header.
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
509 // We can redo the request and ask for all the stream.
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
510 // TODO: Here goes the code to read the ASF header and get the proper values.
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
511 asf_http_ctrl->request++;
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
512 done = 0;
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
513 }
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
514 break;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
515 case ASF_Redirector_e:
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
516 url_next = asf_http_ASX_redirect( http_hdr );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
517 if( url_next==NULL ) {
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
518 printf("Failed to parse ASX file\n");
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
519 close(fd);
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
520 http_free( http_hdr );
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
521 return -1;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
522 }
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
523 url_free( stream->streaming_ctrl->url );
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
524 stream->streaming_ctrl->url = url_next;
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
525 url = url_next;
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
526 done = 0;
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
527 break;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
528 case ASF_Unknown_e:
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
529 default:
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
530 printf("Unknown ASF streaming type\n");
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
531 close(fd);
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
532 http_free( http_hdr );
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
533 return -1;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
534 }
3454
78057c7120f6 Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents: 3042
diff changeset
535 // Check if we got a redirect.
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
536 } while(!done);
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
537
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
538 stream->fd= fd;
2489
0ecc1b4f7cf8 Added ASF http server streaming (Not mms streaming).
bertrand
parents: 2310
diff changeset
539 if( streaming_type==ASF_PlainText_e ) {
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
540 stream->streaming_ctrl->streaming_read = nop_streaming_read;
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
541 stream->streaming_ctrl->streaming_seek = nop_streaming_seek;
2489
0ecc1b4f7cf8 Added ASF http server streaming (Not mms streaming).
bertrand
parents: 2310
diff changeset
542 } else {
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
543 stream->streaming_ctrl->streaming_read = asf_http_streaming_read;
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
544 stream->streaming_ctrl->streaming_seek = asf_http_streaming_seek;
2489
0ecc1b4f7cf8 Added ASF http server streaming (Not mms streaming).
bertrand
parents: 2310
diff changeset
545 }
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
546 stream->streaming_ctrl->prebuffer_size = 20000;
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
547 stream->streaming_ctrl->buffering = 1;
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
548 stream->streaming_ctrl->status = streaming_playing_e;
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
549
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
550 http_free( http_hdr );
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
551 return fd;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
552 }
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
553