Mercurial > mplayer.hg
annotate libmpdemux/asf_streaming.c @ 11469:7cce7a837481
- style and vocabulary corrections
- use Polish comma instead of dot in real numbers (where appropriate)
- some cosmetics
author | rathann |
---|---|
date | Sun, 16 Nov 2003 01:23:14 +0000 |
parents | 786407b1bc78 |
children | acb8ed9cfe70 |
rev | line source |
---|---|
871 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
833 | 3 #include <string.h> |
1430 | 4 #include <unistd.h> |
3494
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3475
diff
changeset
|
5 #include <errno.h> |
833 | 6 |
2555
66837325b929
config.h cleanup, few things added to steram/demuxer headers
arpi
parents:
2489
diff
changeset
|
7 #include "config.h" |
66837325b929
config.h cleanup, few things added to steram/demuxer headers
arpi
parents:
2489
diff
changeset
|
8 |
10281 | 9 #ifndef HAVE_WINSOCK2 |
10 #define closesocket close | |
11 #else | |
12 #include <winsock2.h> | |
13 #endif | |
14 | |
871 | 15 #include "url.h" |
16 #include "http.h" | |
1001 | 17 #include "asf.h" |
871 | 18 |
1001 | 19 #include "stream.h" |
9749 | 20 #include "demuxer.h" |
833 | 21 |
4315 | 22 #include "network.h" |
23 | |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
24 #ifdef ARCH_X86 |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
25 #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
|
26 #else |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
27 #define ASF_LOAD_GUID_PREFIX(guid) \ |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
28 ((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
|
29 #endif |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
30 |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
31 extern int verbose; |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
32 |
7953 | 33 |
9749 | 34 int asf_http_streaming_start( stream_t *stream, int *demuxer_type ); |
7953 | 35 int asf_mmst_streaming_start( stream_t *stream ); |
36 | |
37 | |
3042 | 38 // ASF streaming support several network protocol. |
39 // One use UDP, not known, yet! | |
40 // Another is HTTP, this one is known. | |
41 // 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
|
42 // |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
43 // 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
|
44 // * 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
|
45 // 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
|
46 // * 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
|
47 // 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
|
48 // through |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
49 // * Then we can try HTTP. |
6094
0f4dbbe57c08
Enable mmst support. MMST will be tried if the HTTP support failed.
bertrand
parents:
5915
diff
changeset
|
50 // |
0f4dbbe57c08
Enable mmst support. MMST will be tried if the HTTP support failed.
bertrand
parents:
5915
diff
changeset
|
51 // Note: MMS/HTTP support is now a "well known" support protocol, |
0f4dbbe57c08
Enable mmst support. MMST will be tried if the HTTP support failed.
bertrand
parents:
5915
diff
changeset
|
52 // it has been tested for while, not like MMST support. |
0f4dbbe57c08
Enable mmst support. MMST will be tried if the HTTP support failed.
bertrand
parents:
5915
diff
changeset
|
53 // WMP sequence is MMSU then MMST and then HTTP. |
0f4dbbe57c08
Enable mmst support. MMST will be tried if the HTTP support failed.
bertrand
parents:
5915
diff
changeset
|
54 // In MPlayer case since HTTP support is more reliable, |
0f4dbbe57c08
Enable mmst support. MMST will be tried if the HTTP support failed.
bertrand
parents:
5915
diff
changeset
|
55 // we are doing HTTP first then we try MMST if HTTP fail. |
1001 | 56 int |
9749 | 57 asf_streaming_start( stream_t *stream, int *demuxer_type) { |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
58 char proto_s[10]; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
59 int fd = -1; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
60 |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
61 strncpy( proto_s, stream->streaming_ctrl->url->protocol, 10 ); |
6643 | 62 |
6094
0f4dbbe57c08
Enable mmst support. MMST will be tried if the HTTP support failed.
bertrand
parents:
5915
diff
changeset
|
63 if( !strncasecmp( proto_s, "http", 4) || |
8718
d630a6f4c7c0
- Now mmst will use the MMS/TCP implementation first, instead of trying
bertrand
parents:
7953
diff
changeset
|
64 (!strncasecmp( proto_s, "mms", 3) && strncasecmp( proto_s, "mmst", 4)) || |
6094
0f4dbbe57c08
Enable mmst support. MMST will be tried if the HTTP support failed.
bertrand
parents:
5915
diff
changeset
|
65 !strncasecmp( proto_s, "http_proxy", 10) |
0f4dbbe57c08
Enable mmst support. MMST will be tried if the HTTP support failed.
bertrand
parents:
5915
diff
changeset
|
66 ) { |
0f4dbbe57c08
Enable mmst support. MMST will be tried if the HTTP support failed.
bertrand
parents:
5915
diff
changeset
|
67 mp_msg(MSGT_NETWORK,MSGL_V,"Trying ASF/HTTP...\n"); |
9749 | 68 fd = asf_http_streaming_start( stream, demuxer_type ); |
8823 | 69 if( fd>-1 ) return fd; |
6094
0f4dbbe57c08
Enable mmst support. MMST will be tried if the HTTP support failed.
bertrand
parents:
5915
diff
changeset
|
70 mp_msg(MSGT_NETWORK,MSGL_V," ===> ASF/HTTP failed\n"); |
7252
0a0527c82560
- If fatal error while trying to connect to a WM server, skip other proto.
bertrand
parents:
6677
diff
changeset
|
71 if( fd==-2 ) return -1; |
6094
0f4dbbe57c08
Enable mmst support. MMST will be tried if the HTTP support failed.
bertrand
parents:
5915
diff
changeset
|
72 } |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
73 if( !strncasecmp( proto_s, "mms", 3) && strncasecmp( proto_s, "mmst", 4) ) { |
5915 | 74 mp_msg(MSGT_NETWORK,MSGL_V,"Trying ASF/UDP...\n"); |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
75 //fd = asf_mmsu_streaming_start( stream ); |
8823 | 76 if( fd>-1 ) return fd; |
5915 | 77 mp_msg(MSGT_NETWORK,MSGL_V," ===> ASF/UDP failed\n"); |
7252
0a0527c82560
- If fatal error while trying to connect to a WM server, skip other proto.
bertrand
parents:
6677
diff
changeset
|
78 if( fd==-2 ) return -1; |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
79 } |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
80 if( !strncasecmp( proto_s, "mms", 3) ) { |
5915 | 81 mp_msg(MSGT_NETWORK,MSGL_V,"Trying ASF/TCP...\n"); |
6094
0f4dbbe57c08
Enable mmst support. MMST will be tried if the HTTP support failed.
bertrand
parents:
5915
diff
changeset
|
82 fd = asf_mmst_streaming_start( stream ); |
8823 | 83 if( fd>-1 ) return fd; |
5915 | 84 mp_msg(MSGT_NETWORK,MSGL_V," ===> ASF/TCP failed\n"); |
7252
0a0527c82560
- If fatal error while trying to connect to a WM server, skip other proto.
bertrand
parents:
6677
diff
changeset
|
85 if( fd==-2 ) return -1; |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
86 } |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
87 |
5915 | 88 mp_msg(MSGT_NETWORK,MSGL_ERR,"Unknown protocol: %s\n", proto_s ); |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
89 return -1; |
3042 | 90 } |
91 | |
4046
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
92 int |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
93 asf_streaming(ASF_stream_chunck_t *stream_chunck, int *drop_packet ) { |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
94 /* |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
95 printf("ASF stream chunck size=%d\n", stream_chunck->size); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
96 printf("length: %d\n", length ); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
97 printf("0x%02X\n", stream_chunck->type ); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
98 */ |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
99 if( drop_packet!=NULL ) *drop_packet = 0; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
100 |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
101 if( stream_chunck->size<8 ) { |
5915 | 102 mp_msg(MSGT_NETWORK,MSGL_ERR,"Ahhhh, stream_chunck size is too small: %d\n", stream_chunck->size); |
4046
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
103 return -1; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
104 } |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
105 if( stream_chunck->size!=stream_chunck->size_confirm ) { |
5915 | 106 mp_msg(MSGT_NETWORK,MSGL_ERR,"size_confirm mismatch!: %d %d\n", stream_chunck->size, stream_chunck->size_confirm); |
4046
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
107 return -1; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
108 } |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
109 /* |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
110 printf(" type: 0x%02X\n", stream_chunck->type ); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
111 printf(" size: %d (0x%02X)\n", stream_chunck->size, stream_chunck->size ); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
112 printf(" sequence_number: 0x%04X\n", stream_chunck->sequence_number ); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
113 printf(" unknown: 0x%02X\n", stream_chunck->unknown ); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
114 printf(" size_confirm: 0x%02X\n", stream_chunck->size_confirm ); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
115 */ |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
116 switch(stream_chunck->type) { |
5617
75a43bb3ed80
Added big endian handling for the ASF_chunk_t struct.
bertrand
parents:
4334
diff
changeset
|
117 case ASF_STREAMING_CLEAR: // $C Clear ASF configuration |
5915 | 118 mp_msg(MSGT_NETWORK,MSGL_V,"=====> Clearing ASF stream configuration!\n"); |
4046
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
119 if( drop_packet!=NULL ) *drop_packet = 1; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
120 return stream_chunck->size; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
121 break; |
5617
75a43bb3ed80
Added big endian handling for the ASF_chunk_t struct.
bertrand
parents:
4334
diff
changeset
|
122 case ASF_STREAMING_DATA: // $D Data follows |
4046
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
123 // printf("=====> Data follows\n"); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
124 break; |
5617
75a43bb3ed80
Added big endian handling for the ASF_chunk_t struct.
bertrand
parents:
4334
diff
changeset
|
125 case ASF_STREAMING_END_TRANS: // $E Transfer complete |
5915 | 126 mp_msg(MSGT_NETWORK,MSGL_V,"=====> Transfer complete\n"); |
4046
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
127 if( drop_packet!=NULL ) *drop_packet = 1; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
128 return stream_chunck->size; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
129 break; |
5617
75a43bb3ed80
Added big endian handling for the ASF_chunk_t struct.
bertrand
parents:
4334
diff
changeset
|
130 case ASF_STREAMING_HEADER: // $H ASF header chunk follows |
5915 | 131 mp_msg(MSGT_NETWORK,MSGL_V,"=====> ASF header chunk follows\n"); |
4046
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
132 break; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
133 default: |
5915 | 134 mp_msg(MSGT_NETWORK,MSGL_V,"=====> Unknown stream type 0x%x\n", stream_chunck->type ); |
4046
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
135 } |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
136 return stream_chunck->size+4; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
137 } |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
138 |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
139 static int |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
140 asf_streaming_parse_header(int fd, streaming_ctrl_t* streaming_ctrl) { |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
141 ASF_header_t asfh; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
142 ASF_obj_header_t objh; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
143 ASF_file_header_t fileh; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
144 ASF_stream_header_t streamh; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
145 ASF_stream_chunck_t chunk; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
146 asf_http_streaming_ctrl_t* asf_ctrl = (asf_http_streaming_ctrl_t*) streaming_ctrl->data; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
147 char* buffer=NULL, *chunk_buffer=NULL; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
148 int i,r,size,pos = 0; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
149 int buffer_size = 0; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
150 int chunk_size2read = 0; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
151 |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
152 if(asf_ctrl == NULL) return -1; |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
153 |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
154 // The ASF header can be in several network chunks. For example if the content description |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
155 // is big, the ASF header will be split in 2 network chunk. |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
156 // So we need to retrieve all the chunk before starting to parse the header. |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
157 do { |
7953 | 158 for( r=0; r < (int)sizeof(ASF_stream_chunck_t) ; ) { |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
159 i = nop_streaming_read(fd,((char*)&chunk)+r,sizeof(ASF_stream_chunck_t) - r,streaming_ctrl); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
160 if(i <= 0) return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
161 r += i; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
162 } |
5617
75a43bb3ed80
Added big endian handling for the ASF_chunk_t struct.
bertrand
parents:
4334
diff
changeset
|
163 // Endian handling of the stream chunk |
75a43bb3ed80
Added big endian handling for the ASF_chunk_t struct.
bertrand
parents:
4334
diff
changeset
|
164 le2me_ASF_stream_chunck_t(&chunk); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
165 size = asf_streaming( &chunk, &r) - sizeof(ASF_stream_chunck_t); |
5915 | 166 if(r) mp_msg(MSGT_NETWORK,MSGL_WARN,"Warning : drop header ????\n"); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
167 if(size < 0){ |
5915 | 168 mp_msg(MSGT_NETWORK,MSGL_ERR,"Error while parsing chunk header\n"); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
169 return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
170 } |
5617
75a43bb3ed80
Added big endian handling for the ASF_chunk_t struct.
bertrand
parents:
4334
diff
changeset
|
171 if (chunk.type != ASF_STREAMING_HEADER) { |
5915 | 172 mp_msg(MSGT_NETWORK,MSGL_ERR,"Don't got a header as first chunk !!!!\n"); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
173 return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
174 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
175 |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
176 buffer = (char*) malloc(size+buffer_size); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
177 if(buffer == NULL) { |
5915 | 178 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Error can't allocate %d bytes buffer\n",size+buffer_size); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
179 return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
180 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
181 if( chunk_buffer!=NULL ) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
182 memcpy( buffer, chunk_buffer, buffer_size ); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
183 free( chunk_buffer ); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
184 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
185 chunk_buffer = buffer; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
186 buffer += buffer_size; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
187 buffer_size += size; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
188 |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
189 for(r = 0; r < size;) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
190 i = nop_streaming_read(fd,buffer+r,size-r,streaming_ctrl); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
191 if(i < 0) { |
5915 | 192 mp_msg(MSGT_NETWORK,MSGL_ERR,"Error while reading network stream\n"); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
193 return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
194 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
195 r += i; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
196 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
197 |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
198 if( chunk_size2read==0 ) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
199 if(size < (int)sizeof(asfh)) { |
5915 | 200 mp_msg(MSGT_NETWORK,MSGL_ERR,"Error chunk is too small\n"); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
201 return -1; |
5915 | 202 } else mp_msg(MSGT_NETWORK,MSGL_DBG2,"Got chunk\n"); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
203 memcpy(&asfh,buffer,sizeof(asfh)); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
204 le2me_ASF_header_t(&asfh); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
205 chunk_size2read = asfh.objh.size; |
5915 | 206 mp_msg(MSGT_NETWORK,MSGL_DBG2,"Size 2 read=%d\n", chunk_size2read); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
207 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
208 } while( buffer_size<chunk_size2read); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
209 buffer = chunk_buffer; |
3551 | 210 size = buffer_size; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
211 |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
212 if(asfh.cno > 256) { |
5915 | 213 mp_msg(MSGT_NETWORK,MSGL_ERR,"Error sub chunks number is invalid\n"); |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
214 return -1; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
215 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
216 |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
217 pos += sizeof(asfh); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
218 |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
219 while(size - pos >= (int)sizeof(objh)) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
220 memcpy(&objh,buffer+pos,sizeof(objh)); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
221 le2me_ASF_obj_header_t(&objh); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
222 |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
223 switch(ASF_LOAD_GUID_PREFIX(objh.guid)) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
224 case 0x8CABDCA1 : // File header |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
225 pos += sizeof(objh); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
226 memcpy(&fileh,buffer + pos,sizeof(fileh)); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
227 le2me_ASF_file_header_t(&fileh); |
4288
b84e9861461c
Changed the asf_file_header_t struct to read all the fields properly.
bertrand
parents:
4145
diff
changeset
|
228 /* |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
229 if(fileh.packetsize != fileh.packetsize2) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
230 printf("Error packetsize check don't match\n"); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
231 return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
232 } |
4288
b84e9861461c
Changed the asf_file_header_t struct to read all the fields properly.
bertrand
parents:
4145
diff
changeset
|
233 */ |
b84e9861461c
Changed the asf_file_header_t struct to read all the fields properly.
bertrand
parents:
4145
diff
changeset
|
234 asf_ctrl->packet_size = fileh.max_packet_size; |
b84e9861461c
Changed the asf_file_header_t struct to read all the fields properly.
bertrand
parents:
4145
diff
changeset
|
235 // before playing. |
b84e9861461c
Changed the asf_file_header_t struct to read all the fields properly.
bertrand
parents:
4145
diff
changeset
|
236 // preroll: time in ms to bufferize before playing |
b84e9861461c
Changed the asf_file_header_t struct to read all the fields properly.
bertrand
parents:
4145
diff
changeset
|
237 streaming_ctrl->prebuffer_size = (unsigned int)((double)((double)fileh.preroll/1000)*((double)fileh.max_bitrate/8)); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
238 pos += sizeof(fileh); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
239 break; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
240 case 0xB7DC0791 : // stream header |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
241 pos += sizeof(objh); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
242 memcpy(&streamh,buffer + pos,sizeof(streamh)); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
243 le2me_ASF_stream_header_t(&streamh); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
244 pos += sizeof(streamh) + streamh.type_size; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
245 switch(ASF_LOAD_GUID_PREFIX(streamh.type)) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
246 case 0xF8699E40 : // audio stream |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
247 if(asf_ctrl->audio_streams == NULL){ |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
248 asf_ctrl->audio_streams = (int*)malloc(sizeof(int)); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
249 asf_ctrl->n_audio = 1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
250 } else { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
251 asf_ctrl->n_audio++; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
252 asf_ctrl->audio_streams = (int*)realloc(asf_ctrl->audio_streams, |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
253 asf_ctrl->n_audio*sizeof(int)); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
254 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
255 asf_ctrl->audio_streams[asf_ctrl->n_audio-1] = streamh.stream_no; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
256 pos += streamh.stream_size; |
6643 | 257 if( streaming_ctrl->bandwidth==0 ) { |
258 asf_ctrl->audio_id = streamh.stream_no; | |
259 } | |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
260 break; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
261 case 0xBC19EFC0 : // video stream |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
262 if(asf_ctrl->video_streams == NULL){ |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
263 asf_ctrl->video_streams = (int*)malloc(sizeof(int)); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
264 asf_ctrl->n_video = 1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
265 } else { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
266 asf_ctrl->n_video++; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
267 asf_ctrl->video_streams = (int*)realloc(asf_ctrl->video_streams, |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
268 asf_ctrl->n_video*sizeof(int)); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
269 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
270 asf_ctrl->video_streams[asf_ctrl->n_video-1] = streamh.stream_no; |
6643 | 271 if( streaming_ctrl->bandwidth==0 ) { |
272 asf_ctrl->video_id = streamh.stream_no; | |
273 } | |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
274 break; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
275 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
276 break; |
6643 | 277 case 0x7bf875ce : // stream bitrate properties object |
278 printf("Stream bitrate properties object\n"); | |
279 printf("Max bandwidth set to %d\n", streaming_ctrl->bandwidth); | |
280 asf_ctrl->audio_id = 0; | |
281 asf_ctrl->video_id = 0; | |
282 if( streaming_ctrl->bandwidth!=0 ) { | |
283 int stream_count, stream_id, max_bitrate; | |
284 char *ptr = buffer+pos; | |
7953 | 285 unsigned int total_bitrate=0, p_id=0, p_br=0; |
6643 | 286 int i; |
287 ptr += sizeof(objh); | |
288 stream_count = le2me_16(*(uint16_t*)ptr); | |
289 ptr += sizeof(uint16_t); | |
290 printf(" stream count=[0x%x][%u]\n", stream_count, stream_count ); | |
291 for( i=0 ; i<stream_count && ptr<((char*)buffer+pos+objh.size) ; i++ ) { | |
292 stream_id = le2me_16(*(uint16_t*)ptr); | |
293 ptr += sizeof(uint16_t); | |
294 memcpy(&max_bitrate, ptr, sizeof(uint32_t));// workaround unaligment bug on sparc | |
295 max_bitrate = le2me_32(max_bitrate); | |
296 if( stream_id==1 ) total_bitrate = max_bitrate; | |
297 else if( total_bitrate+max_bitrate>streaming_ctrl->bandwidth ) { | |
298 total_bitrate += p_br; | |
299 printf("total_bitrate=%d\n", total_bitrate); | |
300 printf("id=%d\n", p_id); | |
301 break; | |
302 } | |
303 ptr += sizeof(uint32_t); | |
304 printf(" stream id=[0x%x][%u]\n", stream_id, stream_id ); | |
305 printf(" max bitrate=[0x%x][%u]\n", max_bitrate, max_bitrate ); | |
306 p_id = stream_id; | |
307 p_br = max_bitrate; | |
308 } | |
309 asf_ctrl->audio_id = 1; | |
310 asf_ctrl->video_id = p_id; | |
311 } | |
312 pos += objh.size; | |
313 break; | |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
314 default : |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
315 pos += objh.size; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
316 break; |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
317 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
318 } |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
319 free(buffer); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
320 return 1; |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
321 } |
3042 | 322 |
323 int | |
324 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
|
325 static ASF_stream_chunck_t chunk; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
326 int read,chunk_size = 0; |
7472
c4434bdf6e51
tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents:
7310
diff
changeset
|
327 static int rest = 0, drop_chunk = 0, waiting = 0; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
328 asf_http_streaming_ctrl_t *asf_http_ctrl = (asf_http_streaming_ctrl_t*)streaming_ctrl->data; |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
329 |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
330 while(1) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
331 if (rest == 0 && waiting == 0) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
332 read = 0; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
333 while(read < (int)sizeof(ASF_stream_chunck_t)){ |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
334 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
|
335 sizeof(ASF_stream_chunck_t)-read, |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
336 streaming_ctrl ); |
4041
879a668ee540
various small streaming fixes by Alban Bedel <albeu@free.fr>
arpi
parents:
3727
diff
changeset
|
337 if(r <= 0){ |
879a668ee540
various small streaming fixes by Alban Bedel <albeu@free.fr>
arpi
parents:
3727
diff
changeset
|
338 if( r < 0) |
5915 | 339 mp_msg(MSGT_NETWORK,MSGL_ERR,"Error while reading chunk header\n"); |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
340 return -1; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
341 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
342 read += r; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
343 } |
5617
75a43bb3ed80
Added big endian handling for the ASF_chunk_t struct.
bertrand
parents:
4334
diff
changeset
|
344 |
75a43bb3ed80
Added big endian handling for the ASF_chunk_t struct.
bertrand
parents:
4334
diff
changeset
|
345 // Endian handling of the stream chunk |
75a43bb3ed80
Added big endian handling for the ASF_chunk_t struct.
bertrand
parents:
4334
diff
changeset
|
346 le2me_ASF_stream_chunck_t(&chunk); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
347 chunk_size = asf_streaming( &chunk, &drop_chunk ); |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
348 if(chunk_size < 0) { |
5915 | 349 mp_msg(MSGT_NETWORK,MSGL_ERR,"Error while parsing chunk header\n"); |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
350 return -1; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
351 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
352 chunk_size -= sizeof(ASF_stream_chunck_t); |
3042 | 353 |
5617
75a43bb3ed80
Added big endian handling for the ASF_chunk_t struct.
bertrand
parents:
4334
diff
changeset
|
354 if(chunk.type != ASF_STREAMING_HEADER && (!drop_chunk)) { |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
355 if (asf_http_ctrl->packet_size < chunk_size) { |
5915 | 356 mp_msg(MSGT_NETWORK,MSGL_ERR,"Error chunk_size > packet_size\n"); |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
357 return -1; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
358 } |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
359 waiting = asf_http_ctrl->packet_size; |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
360 } else { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
361 waiting = chunk_size; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
362 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
363 |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
364 } else if (rest){ |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
365 chunk_size = rest; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
366 rest = 0; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
367 } |
3042 | 368 |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
369 read = 0; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
370 if ( waiting >= chunk_size) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
371 if (chunk_size > size){ |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
372 rest = chunk_size - size; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
373 chunk_size = size; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
374 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
375 while(read < chunk_size) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
376 int got = nop_streaming_read( fd,buffer+read,chunk_size-read,streaming_ctrl ); |
4041
879a668ee540
various small streaming fixes by Alban Bedel <albeu@free.fr>
arpi
parents:
3727
diff
changeset
|
377 if(got <= 0) { |
879a668ee540
various small streaming fixes by Alban Bedel <albeu@free.fr>
arpi
parents:
3727
diff
changeset
|
378 if(got < 0) |
5915 | 379 mp_msg(MSGT_NETWORK,MSGL_ERR,"Error while reading chunk\n"); |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
380 return -1; |
1001 | 381 } |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
382 read += got; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
383 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
384 waiting -= read; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
385 if (drop_chunk) continue; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
386 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
387 if (rest == 0 && waiting > 0 && size-read > 0) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
388 int s = MIN(waiting,size-read); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
389 memset(buffer+read,0,s); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
390 waiting -= s; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
391 read += s; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
392 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
393 break; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
394 } |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
395 |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
396 return read; |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
397 } |
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
398 |
905 | 399 int |
3042 | 400 asf_http_streaming_seek( int fd, off_t pos, streaming_ctrl_t *streaming_ctrl ) { |
401 return -1; | |
7953 | 402 // to shut up gcc warning |
403 fd++; | |
404 pos++; | |
405 streaming_ctrl=NULL; | |
3042 | 406 } |
407 | |
408 int | |
4312
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
409 asf_header_check( HTTP_header_t *http_hdr ) { |
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
410 ASF_obj_header_t *objh; |
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
411 if( http_hdr==NULL ) return -1; |
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
412 if( http_hdr->body==NULL || http_hdr->body_size<sizeof(ASF_obj_header_t) ) return -1; |
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
413 |
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
414 objh = (ASF_obj_header_t*)http_hdr->body; |
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
415 if( ASF_LOAD_GUID_PREFIX(objh->guid)==0x75B22630 ) return 0; |
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
416 return -1; |
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
417 } |
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
418 |
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
419 int |
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
420 asf_http_streaming_type(char *content_type, char *features, HTTP_header_t *http_hdr ) { |
905 | 421 if( content_type==NULL ) return ASF_Unknown_e; |
7252
0a0527c82560
- If fatal error while trying to connect to a WM server, skip other proto.
bertrand
parents:
6677
diff
changeset
|
422 if( !strcasecmp(content_type, "application/octet-stream") || |
0a0527c82560
- If fatal error while trying to connect to a WM server, skip other proto.
bertrand
parents:
6677
diff
changeset
|
423 !strcasecmp(content_type, "application/vnd.ms.wms-hdr.asfv1") || // New in Corona, first request |
11349
786407b1bc78
Accept video/x-ms-asf as the MIME type for ASF as well. Patch by Dominique Andre Gunia <Dominique.Gunia@schunter.etc.tu-bs.de>.
mosu
parents:
10939
diff
changeset
|
424 !strcasecmp(content_type, "application/x-mms-framed") || // New in Corana, second request |
786407b1bc78
Accept video/x-ms-asf as the MIME type for ASF as well. Patch by Dominique Andre Gunia <Dominique.Gunia@schunter.etc.tu-bs.de>.
mosu
parents:
10939
diff
changeset
|
425 !strcasecmp(content_type, "video/x-ms-asf")) { |
7252
0a0527c82560
- If fatal error while trying to connect to a WM server, skip other proto.
bertrand
parents:
6677
diff
changeset
|
426 |
8718
d630a6f4c7c0
- Now mmst will use the MMS/TCP implementation first, instead of trying
bertrand
parents:
7953
diff
changeset
|
427 if( strstr(features, "broadcast") ) { |
5915 | 428 mp_msg(MSGT_NETWORK,MSGL_V,"=====> ASF Live stream\n"); |
905 | 429 return ASF_Live_e; |
833 | 430 } else { |
5915 | 431 mp_msg(MSGT_NETWORK,MSGL_V,"=====> ASF Prerecorded\n"); |
905 | 432 return ASF_Prerecorded_e; |
833 | 433 } |
434 } else { | |
4312
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
435 // Ok in a perfect world, web servers should be well configured |
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
436 // so we could used mime type to know the stream type, |
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
437 // but guess what? All of them are not well configured. |
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
438 // So we have to check for an asf header :(, but it works :p |
4334
3fb147d59ca6
Readded the content-type checking, in case of the no HTTP body are
bertrand
parents:
4315
diff
changeset
|
439 if( http_hdr->body_size>sizeof(ASF_obj_header_t) ) { |
3fb147d59ca6
Readded the content-type checking, in case of the no HTTP body are
bertrand
parents:
4315
diff
changeset
|
440 if( asf_header_check( http_hdr )==0 ) { |
5915 | 441 mp_msg(MSGT_NETWORK,MSGL_V,"=====> ASF Plain text\n"); |
4334
3fb147d59ca6
Readded the content-type checking, in case of the no HTTP body are
bertrand
parents:
4315
diff
changeset
|
442 return ASF_PlainText_e; |
8718
d630a6f4c7c0
- Now mmst will use the MMS/TCP implementation first, instead of trying
bertrand
parents:
7953
diff
changeset
|
443 } else if( (!strcasecmp(content_type, "text/html")) ) { |
d630a6f4c7c0
- Now mmst will use the MMS/TCP implementation first, instead of trying
bertrand
parents:
7953
diff
changeset
|
444 mp_msg(MSGT_NETWORK,MSGL_V,"=====> HTML, mplayer is not a browser...yet!\n"); |
d630a6f4c7c0
- Now mmst will use the MMS/TCP implementation first, instead of trying
bertrand
parents:
7953
diff
changeset
|
445 return ASF_Unknown_e; |
4334
3fb147d59ca6
Readded the content-type checking, in case of the no HTTP body are
bertrand
parents:
4315
diff
changeset
|
446 } else { |
5915 | 447 mp_msg(MSGT_NETWORK,MSGL_V,"=====> ASF Redirector\n"); |
4334
3fb147d59ca6
Readded the content-type checking, in case of the no HTTP body are
bertrand
parents:
4315
diff
changeset
|
448 return ASF_Redirector_e; |
3fb147d59ca6
Readded the content-type checking, in case of the no HTTP body are
bertrand
parents:
4315
diff
changeset
|
449 } |
4312
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
450 } else { |
4334
3fb147d59ca6
Readded the content-type checking, in case of the no HTTP body are
bertrand
parents:
4315
diff
changeset
|
451 if( (!strcasecmp(content_type, "audio/x-ms-wax")) || |
3fb147d59ca6
Readded the content-type checking, in case of the no HTTP body are
bertrand
parents:
4315
diff
changeset
|
452 (!strcasecmp(content_type, "audio/x-ms-wma")) || |
3fb147d59ca6
Readded the content-type checking, in case of the no HTTP body are
bertrand
parents:
4315
diff
changeset
|
453 (!strcasecmp(content_type, "video/x-ms-asf")) || |
3fb147d59ca6
Readded the content-type checking, in case of the no HTTP body are
bertrand
parents:
4315
diff
changeset
|
454 (!strcasecmp(content_type, "video/x-ms-afs")) || |
3fb147d59ca6
Readded the content-type checking, in case of the no HTTP body are
bertrand
parents:
4315
diff
changeset
|
455 (!strcasecmp(content_type, "video/x-ms-wvx")) || |
3fb147d59ca6
Readded the content-type checking, in case of the no HTTP body are
bertrand
parents:
4315
diff
changeset
|
456 (!strcasecmp(content_type, "video/x-ms-wmv")) || |
3fb147d59ca6
Readded the content-type checking, in case of the no HTTP body are
bertrand
parents:
4315
diff
changeset
|
457 (!strcasecmp(content_type, "video/x-ms-wma")) ) { |
5915 | 458 mp_msg(MSGT_NETWORK,MSGL_ERR,"=====> ASF Redirector\n"); |
4334
3fb147d59ca6
Readded the content-type checking, in case of the no HTTP body are
bertrand
parents:
4315
diff
changeset
|
459 return ASF_Redirector_e; |
3fb147d59ca6
Readded the content-type checking, in case of the no HTTP body are
bertrand
parents:
4315
diff
changeset
|
460 } else if( !strcasecmp(content_type, "text/plain") ) { |
5915 | 461 mp_msg(MSGT_NETWORK,MSGL_V,"=====> ASF Plain text\n"); |
4334
3fb147d59ca6
Readded the content-type checking, in case of the no HTTP body are
bertrand
parents:
4315
diff
changeset
|
462 return ASF_PlainText_e; |
3fb147d59ca6
Readded the content-type checking, in case of the no HTTP body are
bertrand
parents:
4315
diff
changeset
|
463 } else { |
5915 | 464 mp_msg(MSGT_NETWORK,MSGL_V,"=====> ASF unknown content-type: %s\n", content_type ); |
4334
3fb147d59ca6
Readded the content-type checking, in case of the no HTTP body are
bertrand
parents:
4315
diff
changeset
|
465 return ASF_Unknown_e; |
3fb147d59ca6
Readded the content-type checking, in case of the no HTTP body are
bertrand
parents:
4315
diff
changeset
|
466 } |
4312
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
467 } |
833 | 468 } |
905 | 469 return ASF_Unknown_e; |
833 | 470 } |
871 | 471 |
905 | 472 HTTP_header_t * |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
473 asf_http_request(streaming_ctrl_t *streaming_ctrl) { |
871 | 474 HTTP_header_t *http_hdr; |
4121 | 475 URL_t *url = NULL; |
476 URL_t *server_url = NULL; | |
477 asf_http_streaming_ctrl_t *asf_http_ctrl; | |
871 | 478 char str[250]; |
1001 | 479 char *ptr; |
6643 | 480 int i, enable; |
871 | 481 |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
482 int offset_hi=0, offset_lo=0, length=0; |
6643 | 483 int asf_nb_stream=0, stream_id; |
871 | 484 |
4121 | 485 // Sanity check |
486 if( streaming_ctrl==NULL ) return NULL; | |
487 url = streaming_ctrl->url; | |
488 asf_http_ctrl = (asf_http_streaming_ctrl_t*)streaming_ctrl->data; | |
489 if( url==NULL || asf_http_ctrl==NULL ) return NULL; | |
490 | |
871 | 491 // Common header for all requests. |
492 http_hdr = http_new_header(); | |
493 http_set_field( http_hdr, "Accept: */*" ); | |
494 http_set_field( http_hdr, "User-Agent: NSPlayer/4.1.0.3856" ); | |
6670 | 495 http_add_basic_authentication( http_hdr, url->username, url->password ); |
4121 | 496 |
497 // Check if we are using a proxy | |
4145 | 498 if( !strcasecmp( url->protocol, "http_proxy" ) ) { |
4121 | 499 server_url = url_new( (url->file)+1 ); |
500 if( server_url==NULL ) { | |
5915 | 501 mp_msg(MSGT_NETWORK,MSGL_ERR,"Invalid proxy URL\n"); |
4121 | 502 http_free( http_hdr ); |
503 return NULL; | |
504 } | |
505 http_set_uri( http_hdr, server_url->url ); | |
10939
55c9903bd51c
simple fix for buffer overflow (remotely exploitable). feel free to
rfelker
parents:
10625
diff
changeset
|
506 sprintf( str, "Host: %.220s:%d", server_url->hostname, server_url->port ); |
4121 | 507 url_free( server_url ); |
508 } else { | |
509 http_set_uri( http_hdr, url->file ); | |
10939
55c9903bd51c
simple fix for buffer overflow (remotely exploitable). feel free to
rfelker
parents:
10625
diff
changeset
|
510 sprintf( str, "Host: %.220s:%d", url->hostname, url->port ); |
4121 | 511 } |
512 | |
871 | 513 http_set_field( http_hdr, str ); |
514 http_set_field( http_hdr, "Pragma: xClientGUID={c77e7400-738a-11d2-9add-0020af0a3278}" ); | |
515 sprintf(str, | |
516 "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
|
517 offset_hi, offset_lo, asf_http_ctrl->request, length ); |
871 | 518 http_set_field( http_hdr, str ); |
519 | |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
520 switch( asf_http_ctrl->streaming_type ) { |
871 | 521 case ASF_Live_e: |
522 case ASF_Prerecorded_e: | |
523 http_set_field( http_hdr, "Pragma: xPlayStrm=1" ); | |
1001 | 524 ptr = str; |
525 ptr += sprintf( ptr, "Pragma: stream-switch-entry="); | |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
526 if(asf_http_ctrl->n_audio > 0) { |
6643 | 527 for( i=0; i<asf_http_ctrl->n_audio ; i++ ) { |
528 stream_id = asf_http_ctrl->audio_streams[i]; | |
529 if(stream_id == asf_http_ctrl->audio_id) { | |
530 enable = 0; | |
531 } else { | |
532 enable = 2; | |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
533 } |
6643 | 534 asf_nb_stream++; |
535 ptr += sprintf(ptr, "ffff:%d:%d ", stream_id, enable); | |
1001 | 536 } |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
537 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
538 if(asf_http_ctrl->n_video > 0) { |
6643 | 539 for( i=0; i<asf_http_ctrl->n_video ; i++ ) { |
540 stream_id = asf_http_ctrl->video_streams[i]; | |
541 if(stream_id == asf_http_ctrl->video_id) { | |
542 enable = 0; | |
543 } else { | |
544 enable = 2; | |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
545 } |
6643 | 546 asf_nb_stream++; |
547 ptr += sprintf(ptr, "ffff:%d:%d ", stream_id, enable); | |
1001 | 548 } |
549 } | |
550 http_set_field( http_hdr, str ); | |
871 | 551 sprintf( str, "Pragma: stream-switch-count=%d", asf_nb_stream ); |
552 http_set_field( http_hdr, str ); | |
553 break; | |
554 case ASF_Redirector_e: | |
555 break; | |
556 case ASF_Unknown_e: | |
557 // First request goes here. | |
558 break; | |
559 default: | |
5915 | 560 mp_msg(MSGT_NETWORK,MSGL_ERR,"Unknown asf stream type\n"); |
871 | 561 } |
562 | |
563 http_set_field( http_hdr, "Connection: Close" ); | |
905 | 564 http_build_request( http_hdr ); |
871 | 565 |
905 | 566 return http_hdr; |
871 | 567 } |
568 | |
569 int | |
7953 | 570 asf_http_parse_response(asf_http_streaming_ctrl_t *asf_http_ctrl, HTTP_header_t *http_hdr ) { |
871 | 571 char *content_type, *pragma; |
572 char features[64] = "\0"; | |
7953 | 573 size_t len; |
905 | 574 if( http_response_parse(http_hdr)<0 ) { |
5915 | 575 mp_msg(MSGT_NETWORK,MSGL_ERR,"Failed to parse HTTP response\n"); |
905 | 576 return -1; |
577 } | |
6677 | 578 switch( http_hdr->status_code ) { |
579 case 200: | |
580 break; | |
581 case 401: // Authentication required | |
582 return ASF_Authenticate_e; | |
583 default: | |
584 mp_msg(MSGT_NETWORK,MSGL_ERR,"Server return %d:%s\n", http_hdr->status_code, http_hdr->reason_phrase); | |
585 return -1; | |
871 | 586 } |
587 | |
588 content_type = http_get_field( http_hdr, "Content-Type"); | |
3042 | 589 //printf("Content-Type: [%s]\n", content_type); |
871 | 590 |
591 pragma = http_get_field( http_hdr, "Pragma"); | |
905 | 592 while( pragma!=NULL ) { |
871 | 593 char *comma_ptr=NULL; |
594 char *end; | |
3042 | 595 //printf("Pragma: [%s]\n", pragma ); |
871 | 596 // The pragma line can get severals attributes |
597 // separeted with a comma ','. | |
598 do { | |
599 if( !strncasecmp( pragma, "features=", 9) ) { | |
600 pragma += 9; | |
601 end = strstr( pragma, "," ); | |
602 if( end==NULL ) { | |
7953 | 603 size_t s = strlen(pragma); |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
604 if(s > sizeof(features)) { |
5915 | 605 mp_msg(MSGT_NETWORK,MSGL_WARN,"ASF HTTP PARSE WARNING : Pragma %s cuted from %d bytes to %d\n",pragma,s,sizeof(features)); |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
606 len = sizeof(features); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
607 } else { |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
608 len = s; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
609 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
610 } else { |
7953 | 611 len = MIN((unsigned int)(end-pragma),sizeof(features)); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
612 } |
871 | 613 strncpy( features, pragma, len ); |
614 features[len]='\0'; | |
615 break; | |
616 } | |
617 comma_ptr = strstr( pragma, "," ); | |
618 if( comma_ptr!=NULL ) { | |
619 pragma = comma_ptr+1; | |
620 if( pragma[0]==' ' ) pragma++; | |
621 } | |
622 } while( comma_ptr!=NULL ); | |
623 pragma = http_get_next_field( http_hdr ); | |
905 | 624 } |
7953 | 625 asf_http_ctrl->streaming_type = asf_http_streaming_type( content_type, features, http_hdr ); |
626 return 0; | |
871 | 627 } |
628 | |
905 | 629 int |
9749 | 630 asf_http_streaming_start( stream_t *stream, int *demuxer_type ) { |
905 | 631 HTTP_header_t *http_hdr=NULL; |
3042 | 632 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
|
633 asf_http_streaming_ctrl_t *asf_http_ctrl; |
905 | 634 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
|
635 int i, ret; |
3042 | 636 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
|
637 int done; |
6677 | 638 int auth_retry = 0; |
1001 | 639 |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
640 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
|
641 if( asf_http_ctrl==NULL ) { |
5915 | 642 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n"); |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
643 return -1; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
644 } |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
645 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
|
646 asf_http_ctrl->request = 1; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
647 asf_http_ctrl->audio_streams = asf_http_ctrl->video_streams = NULL; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
648 asf_http_ctrl->n_audio = asf_http_ctrl->n_video = 0; |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
649 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
|
650 |
905 | 651 do { |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
652 done = 1; |
10281 | 653 if( fd>0 ) closesocket( fd ); |
1001 | 654 |
4145 | 655 if( !strcasecmp( url->protocol, "http_proxy" ) ) { |
4121 | 656 if( url->port==0 ) url->port = 8080; |
657 } else { | |
658 if( url->port==0 ) url->port = 80; | |
659 } | |
10625
620cc649f519
ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
10281
diff
changeset
|
660 fd = connect2Server( url->hostname, url->port, 1); |
7252
0a0527c82560
- If fatal error while trying to connect to a WM server, skip other proto.
bertrand
parents:
6677
diff
changeset
|
661 if( fd<0 ) return fd; |
905 | 662 |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
663 http_hdr = asf_http_request( stream->streaming_ctrl ); |
5915 | 664 mp_msg(MSGT_NETWORK,MSGL_DBG2,"Request [%s]\n", http_hdr->buffer ); |
7953 | 665 for(i=0; i < (int)http_hdr->buffer_size ; ) { |
10206
35e306346e59
Using recv/send instead read/write for proper MinGW support (it's a 4.2BSD standard). Patch by FloDt <flodt8@yahoo.de>
alex
parents:
9749
diff
changeset
|
666 int r = send( fd, http_hdr->buffer+i, http_hdr->buffer_size-i, 0 ); |
3494
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3475
diff
changeset
|
667 if(r <0) { |
5915 | 668 mp_msg(MSGT_NETWORK,MSGL_ERR,"Socket write error : %s\n",strerror(errno)); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
669 return -1; |
3494
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3475
diff
changeset
|
670 } |
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3475
diff
changeset
|
671 i += r; |
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3475
diff
changeset
|
672 } |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
673 http_free( http_hdr ); |
905 | 674 http_hdr = http_new_header(); |
675 do { | |
10206
35e306346e59
Using recv/send instead read/write for proper MinGW support (it's a 4.2BSD standard). Patch by FloDt <flodt8@yahoo.de>
alex
parents:
9749
diff
changeset
|
676 i = recv( fd, buffer, BUFFER_SIZE, 0 ); |
4121 | 677 //printf("read: %d\n", i ); |
7310
d8e2623a2ea1
Don't try to reread from the socket if the server says EOF
bertrand
parents:
7252
diff
changeset
|
678 if( i<=0 ) { |
1001 | 679 perror("read"); |
680 http_free( http_hdr ); | |
681 return -1; | |
682 } | |
905 | 683 http_response_append( http_hdr, buffer, i ); |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
684 } while( !http_is_header_entire( http_hdr ) ); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
685 if( verbose>0 ) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
686 http_hdr->buffer[http_hdr->buffer_size]='\0'; |
5915 | 687 mp_msg(MSGT_NETWORK,MSGL_DBG2,"Response [%s]\n", http_hdr->buffer ); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
688 } |
7953 | 689 ret = asf_http_parse_response(asf_http_ctrl, http_hdr); |
690 if( ret<0 ) { | |
5915 | 691 mp_msg(MSGT_NETWORK,MSGL_ERR,"Failed to parse header\n"); |
1001 | 692 http_free( http_hdr ); |
905 | 693 return -1; |
694 } | |
7953 | 695 switch( asf_http_ctrl->streaming_type ) { |
905 | 696 case ASF_Live_e: |
697 case ASF_Prerecorded_e: | |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
698 case ASF_PlainText_e: |
1001 | 699 if( http_hdr->body_size>0 ) { |
3042 | 700 if( streaming_bufferize( stream->streaming_ctrl, http_hdr->body, http_hdr->body_size )<0 ) { |
701 http_free( http_hdr ); | |
702 return -1; | |
1001 | 703 } |
905 | 704 } |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
705 if( asf_http_ctrl->request==1 ) { |
7953 | 706 if( asf_http_ctrl->streaming_type!=ASF_PlainText_e ) { |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
707 // First request, we only got the ASF header. |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
708 ret = asf_streaming_parse_header(fd,stream->streaming_ctrl); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
709 if(ret < 0) return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
710 if(asf_http_ctrl->n_audio == 0 && asf_http_ctrl->n_video == 0) { |
5915 | 711 mp_msg(MSGT_NETWORK,MSGL_ERR,"No stream found\n"); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
712 return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
713 } |
4312
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
714 asf_http_ctrl->request++; |
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
715 done = 0; |
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
716 } else { |
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
717 done = 1; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
718 } |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
719 } |
905 | 720 break; |
721 case ASF_Redirector_e: | |
4073
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
722 if( http_hdr->body_size>0 ) { |
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
723 if( streaming_bufferize( stream->streaming_ctrl, http_hdr->body, http_hdr->body_size )<0 ) { |
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
724 http_free( http_hdr ); |
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
725 return -1; |
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
726 } |
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
727 } |
9749 | 728 *demuxer_type = DEMUXER_TYPE_PLAYLIST; |
4073
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
729 done = 1; |
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
730 break; |
6677 | 731 case ASF_Authenticate_e: |
732 if( http_authenticate( http_hdr, url, &auth_retry)<0 ) return -1; | |
733 asf_http_ctrl->streaming_type = ASF_Unknown_e; | |
734 done = 0; | |
735 break; | |
905 | 736 case ASF_Unknown_e: |
737 default: | |
5915 | 738 mp_msg(MSGT_NETWORK,MSGL_ERR,"Unknown ASF streaming type\n"); |
10281 | 739 closesocket(fd); |
1001 | 740 http_free( http_hdr ); |
905 | 741 return -1; |
742 } | |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
743 // Check if we got a redirect. |
905 | 744 } while(!done); |
745 | |
4073
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
746 stream->fd = fd; |
7953 | 747 if( asf_http_ctrl->streaming_type==ASF_PlainText_e || asf_http_ctrl->streaming_type==ASF_Redirector_e ) { |
3042 | 748 stream->streaming_ctrl->streaming_read = nop_streaming_read; |
749 stream->streaming_ctrl->streaming_seek = nop_streaming_seek; | |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
750 } else { |
3042 | 751 stream->streaming_ctrl->streaming_read = asf_http_streaming_read; |
752 stream->streaming_ctrl->streaming_seek = asf_http_streaming_seek; | |
4288
b84e9861461c
Changed the asf_file_header_t struct to read all the fields properly.
bertrand
parents:
4145
diff
changeset
|
753 stream->streaming_ctrl->buffering = 1; |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
754 } |
3042 | 755 stream->streaming_ctrl->status = streaming_playing_e; |
1001 | 756 |
757 http_free( http_hdr ); | |
4073
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
758 return 0; |
905 | 759 } |
760 |