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