Mercurial > mplayer.hg
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 |
rev | line source |
---|---|
871 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
833 | 3 #include <string.h> |
1430 | 4 #include <unistd.h> |
833 | 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 | 8 #include "url.h" |
9 #include "http.h" | |
1001 | 10 #include "asf.h" |
905 | 11 #include "network.h" |
871 | 12 |
1001 | 13 #include "stream.h" |
833 | 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 | 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 | 29 // ASF streaming support several network protocol. |
30 // One use UDP, not known, yet! | |
31 // Another is HTTP, this one is known. | |
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 | 41 int |
3042 | 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 | 69 } |
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 | 112 |
113 int | |
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 | 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 | 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 | 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 | 213 int |
214 asf_streaming(char *data, int length, int *drop_packet ) { | |
833 | 215 ASF_stream_chunck_t *stream_chunck=(ASF_stream_chunck_t*)data; |
3042 | 216 /* |
217 printf("ASF stream chunck size=%d\n", stream_chunck->size); | |
1001 | 218 printf("length: %d\n", length ); |
219 printf("0x%02X\n", stream_chunck->type ); | |
3042 | 220 */ |
221 if( data==NULL || length<=0 ) return -1; | |
1001 | 222 if( drop_packet!=NULL ) *drop_packet = 0; |
871 | 223 |
224 if( stream_chunck->size<8 ) { | |
225 printf("Ahhhh, stream_chunck size is too small: %d\n", stream_chunck->size); | |
1001 | 226 return -1; |
871 | 227 } |
228 if( stream_chunck->size!=stream_chunck->size_confirm ) { | |
229 printf("size_confirm mismatch!: %d %d\n", stream_chunck->size, stream_chunck->size_confirm); | |
1001 | 230 return -1; |
871 | 231 } |
3042 | 232 /* |
1001 | 233 printf(" type: 0x%02X\n", stream_chunck->type ); |
234 printf(" size: %d (0x%02X)\n", stream_chunck->size, stream_chunck->size ); | |
235 printf(" sequence_number: 0x%04X\n", stream_chunck->sequence_number ); | |
236 printf(" unknown: 0x%02X\n", stream_chunck->unknown ); | |
237 printf(" size_confirm: 0x%02X\n", stream_chunck->size_confirm ); | |
3042 | 238 */ |
833 | 239 switch(stream_chunck->type) { |
3042 | 240 case 0x4324: // $C Clear ASF configuration |
871 | 241 printf("=====> Clearing ASF stream configuration!\n"); |
1001 | 242 if( drop_packet!=NULL ) *drop_packet = 1; |
243 return stream_chunck->size; | |
833 | 244 break; |
3042 | 245 case 0x4424: // $D Data follows |
246 // printf("=====> Data follows\n"); | |
833 | 247 break; |
3042 | 248 case 0x4524: // $E Transfer complete |
871 | 249 printf("=====> Transfer complete\n"); |
1001 | 250 if( drop_packet!=NULL ) *drop_packet = 1; |
251 return stream_chunck->size; | |
833 | 252 break; |
3042 | 253 case 0x4824: // $H ASF header chunk follows |
871 | 254 printf("=====> ASF header chunk follows\n"); |
833 | 255 break; |
256 default: | |
871 | 257 printf("=====> Unknown stream type 0x%x\n", stream_chunck->type ); |
833 | 258 } |
1001 | 259 return stream_chunck->size+4; |
833 | 260 } |
261 | |
905 | 262 int |
3042 | 263 asf_http_streaming_seek( int fd, off_t pos, streaming_ctrl_t *streaming_ctrl ) { |
264 return -1; | |
265 } | |
266 | |
267 int | |
905 | 268 asf_http_streaming_type(char *content_type, char *features) { |
269 if( content_type==NULL ) return ASF_Unknown_e; | |
833 | 270 if( !strcasecmp(content_type, "application/octet-stream") ) { |
905 | 271 if( features==NULL ) { |
1001 | 272 printf("=====> ASF Prerecorded\n"); |
905 | 273 return ASF_Prerecorded_e; |
274 } else if( strstr(features, "broadcast")) { | |
1001 | 275 printf("=====> ASF Live stream\n"); |
905 | 276 return ASF_Live_e; |
833 | 277 } else { |
1001 | 278 printf("=====> ASF Prerecorded\n"); |
905 | 279 return ASF_Prerecorded_e; |
833 | 280 } |
281 } else { | |
871 | 282 if( (!strcasecmp(content_type, "audio/x-ms-wax")) || |
833 | 283 (!strcasecmp(content_type, "audio/x-ms-wma")) || |
284 (!strcasecmp(content_type, "video/x-ms-asf")) || | |
285 (!strcasecmp(content_type, "video/x-ms-afs")) || | |
286 (!strcasecmp(content_type, "video/x-ms-wvx")) || | |
287 (!strcasecmp(content_type, "video/x-ms-wmv")) || | |
288 (!strcasecmp(content_type, "video/x-ms-wma")) ) { | |
1001 | 289 printf("=====> ASF Redirector\n"); |
905 | 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 | 294 } else { |
1001 | 295 printf("=====> ASF unknown content-type: %s\n", content_type ); |
905 | 296 return ASF_Unknown_e; |
833 | 297 } |
298 } | |
905 | 299 return ASF_Unknown_e; |
833 | 300 } |
871 | 301 |
905 | 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 | 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 | 308 char str[250]; |
1001 | 309 char *ptr; |
871 | 310 char *request; |
1001 | 311 int i; |
871 | 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 | 314 int asf_nb_stream; |
871 | 315 |
316 // Common header for all requests. | |
317 http_hdr = http_new_header(); | |
318 http_set_uri( http_hdr, url->file ); | |
319 http_set_field( http_hdr, "Accept: */*" ); | |
320 http_set_field( http_hdr, "User-Agent: NSPlayer/4.1.0.3856" ); | |
321 sprintf( str, "Host: %s:%d", url->hostname, url->port ); | |
322 http_set_field( http_hdr, str ); | |
323 http_set_field( http_hdr, "Pragma: xClientGUID={c77e7400-738a-11d2-9add-0020af0a3278}" ); | |
324 sprintf(str, | |
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 | 327 http_set_field( http_hdr, str ); |
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 | 330 case ASF_Live_e: |
331 case ASF_Prerecorded_e: | |
332 http_set_field( http_hdr, "Pragma: xPlayStrm=1" ); | |
1001 | 333 ptr = str; |
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 | 337 for( i=0, asf_nb_stream=0 ; i<256 ; i++ ) { |
338 // FIXME START | |
339 if( demuxer==NULL ) { | |
340 ptr += sprintf( ptr, " ffff:1:0" ); | |
341 asf_nb_stream = 1; | |
342 break; | |
343 } | |
344 // FIXME END | |
345 if( demuxer->a_streams[i] ) { | |
346 ptr += sprintf( ptr, " ffff:%d:0", i ); | |
347 asf_nb_stream++; | |
348 } | |
349 if( demuxer->v_streams[i] ) { | |
350 ptr += sprintf( ptr, " ffff:%d:0", i ); | |
351 asf_nb_stream++; | |
352 } | |
353 } | |
1340
d4f1e8d0e591
demuxer struct access code temporary disabled - FIXME
arpi
parents:
1001
diff
changeset
|
354 #endif |
1001 | 355 http_set_field( http_hdr, str ); |
871 | 356 sprintf( str, "Pragma: stream-switch-count=%d", asf_nb_stream ); |
357 http_set_field( http_hdr, str ); | |
358 break; | |
359 case ASF_Redirector_e: | |
360 break; | |
361 case ASF_Unknown_e: | |
362 // First request goes here. | |
363 break; | |
364 default: | |
365 printf("Unknown asf stream type\n"); | |
366 } | |
367 | |
368 http_set_field( http_hdr, "Connection: Close" ); | |
905 | 369 http_build_request( http_hdr ); |
871 | 370 |
905 | 371 return http_hdr; |
871 | 372 } |
373 | |
374 int | |
905 | 375 asf_http_parse_response( HTTP_header_t *http_hdr ) { |
871 | 376 char *content_type, *pragma; |
377 char features[64] = "\0"; | |
378 int len; | |
905 | 379 if( http_response_parse(http_hdr)<0 ) { |
380 printf("Failed to parse HTTP response\n"); | |
381 return -1; | |
382 } | |
871 | 383 if( http_hdr->status_code!=200 ) { |
384 printf("Server return %d:%s\n", http_hdr->status_code, http_hdr->reason_phrase); | |
385 return -1; | |
386 } | |
387 | |
388 content_type = http_get_field( http_hdr, "Content-Type"); | |
3042 | 389 //printf("Content-Type: [%s]\n", content_type); |
871 | 390 |
391 pragma = http_get_field( http_hdr, "Pragma"); | |
905 | 392 while( pragma!=NULL ) { |
871 | 393 char *comma_ptr=NULL; |
394 char *end; | |
3042 | 395 //printf("Pragma: [%s]\n", pragma ); |
871 | 396 // The pragma line can get severals attributes |
397 // separeted with a comma ','. | |
398 do { | |
399 if( !strncasecmp( pragma, "features=", 9) ) { | |
400 pragma += 9; | |
401 end = strstr( pragma, "," ); | |
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 | 411 strncpy( features, pragma, len ); |
412 features[len]='\0'; | |
413 break; | |
414 } | |
415 comma_ptr = strstr( pragma, "," ); | |
416 if( comma_ptr!=NULL ) { | |
417 pragma = comma_ptr+1; | |
418 if( pragma[0]==' ' ) pragma++; | |
419 } | |
420 } while( comma_ptr!=NULL ); | |
421 pragma = http_get_next_field( http_hdr ); | |
905 | 422 } |
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 | 425 } |
426 | |
905 | 427 URL_t * |
428 asf_http_ASX_redirect( HTTP_header_t *http_hdr ) { | |
429 URL_t *url_redirect=NULL; | |
430 printf("=========>> ASX parser not yet implemented <<==========\n"); | |
431 | |
432 printf("ASX=[%s]\n", http_hdr->body ); | |
433 | |
434 return url_redirect; | |
871 | 435 } |
905 | 436 |
437 int | |
3042 | 438 asf_http_streaming_start( stream_t *stream ) { |
905 | 439 HTTP_header_t *http_hdr=NULL; |
440 URL_t *url_next=NULL; | |
3042 | 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 | 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 | 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 | 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 | 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 | 462 if( fd>0 ) close( fd ); |
1001 | 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 | 465 fd = connect2Server( url->hostname, url->port ); |
466 if( fd<0 ) return -1; | |
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 | 470 printf("Request [%s]\n", http_hdr->buffer ); |
905 | 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 | 475 |
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 | 478 do { |
3042 | 479 i = read( fd, buffer, BUFFER_SIZE ); |
905 | 480 printf("read: %d\n", i ); |
1001 | 481 if( i<0 ) { |
482 perror("read"); | |
483 http_free( http_hdr ); | |
484 return -1; | |
485 } | |
905 | 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 | 488 http_hdr->buffer[http_hdr->buffer_size]='\0'; |
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 | 492 printf("Failed to parse header\n"); |
1001 | 493 http_free( http_hdr ); |
905 | 494 return -1; |
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 | 497 switch( streaming_type ) { |
905 | 498 case ASF_Live_e: |
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 | 501 if( http_hdr->body_size>0 ) { |
3042 | 502 if( streaming_bufferize( stream->streaming_ctrl, http_hdr->body, http_hdr->body_size )<0 ) { |
503 http_free( http_hdr ); | |
504 return -1; | |
1001 | 505 } |
905 | 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 | 514 break; |
515 case ASF_Redirector_e: | |
516 url_next = asf_http_ASX_redirect( http_hdr ); | |
517 if( url_next==NULL ) { | |
518 printf("Failed to parse ASX file\n"); | |
519 close(fd); | |
1001 | 520 http_free( http_hdr ); |
905 | 521 return -1; |
522 } | |
3042 | 523 url_free( stream->streaming_ctrl->url ); |
524 stream->streaming_ctrl->url = url_next; | |
905 | 525 url = url_next; |
3042 | 526 done = 0; |
905 | 527 break; |
528 case ASF_Unknown_e: | |
529 default: | |
530 printf("Unknown ASF streaming type\n"); | |
531 close(fd); | |
1001 | 532 http_free( http_hdr ); |
905 | 533 return -1; |
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 | 536 } while(!done); |
537 | |
3042 | 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 | 540 stream->streaming_ctrl->streaming_read = nop_streaming_read; |
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 | 543 stream->streaming_ctrl->streaming_read = asf_http_streaming_read; |
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 | 546 stream->streaming_ctrl->prebuffer_size = 20000; |
547 stream->streaming_ctrl->buffering = 1; | |
548 stream->streaming_ctrl->status = streaming_playing_e; | |
1001 | 549 |
550 http_free( http_hdr ); | |
905 | 551 return fd; |
552 } | |
553 |