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