Mercurial > mplayer.hg
annotate libmpdemux/asf_streaming.c @ 19075:31da49ce5a58
printf --> mp_msg
author | diego |
---|---|
date | Fri, 14 Jul 2006 07:40:36 +0000 |
parents | 83c3afeab35d |
children |
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> |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
6 #include <limits.h> |
833 | 7 |
2555
66837325b929
config.h cleanup, few things added to steram/demuxer headers
arpi
parents:
2489
diff
changeset
|
8 #include "config.h" |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
9 #include "mp_msg.h" |
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
10 #include "help_mp.h" |
2555
66837325b929
config.h cleanup, few things added to steram/demuxer headers
arpi
parents:
2489
diff
changeset
|
11 |
10281 | 12 #ifndef HAVE_WINSOCK2 |
13 #define closesocket close | |
14 #else | |
15 #include <winsock2.h> | |
16 #endif | |
17 | |
871 | 18 #include "url.h" |
19 #include "http.h" | |
1001 | 20 #include "asf.h" |
871 | 21 |
1001 | 22 #include "stream.h" |
9749 | 23 #include "demuxer.h" |
833 | 24 |
4315 | 25 #include "network.h" |
26 | |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
27 #ifdef ARCH_X86 |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
28 #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
|
29 #else |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
30 #define ASF_LOAD_GUID_PREFIX(guid) \ |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
31 ((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
|
32 #endif |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
33 |
15585 | 34 extern int network_bandwidth; |
7953 | 35 |
36 int asf_mmst_streaming_start( stream_t *stream ); | |
15585 | 37 static int asf_http_streaming_start(stream_t *stream, int *demuxer_type); |
7953 | 38 |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
39 // 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
|
40 // * first the UDP protcol, if there is a firewall, UDP |
15585 | 41 // packets will not come back, so the mmsu will fail. |
3454
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 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
|
43 // 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
|
44 // through |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
45 // * Then we can try HTTP. |
6094
0f4dbbe57c08
Enable mmst support. MMST will be tried if the HTTP support failed.
bertrand
parents:
5915
diff
changeset
|
46 // |
12535
48ae29c2298c
Use same order as WMP for mms protocols (MMSU, MMST, HTTP)
rtognimp
parents:
12396
diff
changeset
|
47 // Note: Using WMP sequence MMSU then MMST and then HTTP. |
48ae29c2298c
Use same order as WMP for mms protocols (MMSU, MMST, HTTP)
rtognimp
parents:
12396
diff
changeset
|
48 |
15585 | 49 static int asf_streaming_start( stream_t *stream, int *demuxer_type) { |
12879
542d1d2200c1
reduced code complexity, and also made consistent with other parts
alex
parents:
12878
diff
changeset
|
50 char *proto = stream->streaming_ctrl->url->protocol; |
542d1d2200c1
reduced code complexity, and also made consistent with other parts
alex
parents:
12878
diff
changeset
|
51 int fd = -1; |
14525 | 52 int port = stream->streaming_ctrl->url->port; |
6643 | 53 |
12535
48ae29c2298c
Use same order as WMP for mms protocols (MMSU, MMST, HTTP)
rtognimp
parents:
12396
diff
changeset
|
54 // Is protocol mms or mmsu? |
16112
0aeb954fc11c
strncasecmp is not necessary and e.g. strncasecmp(prot, "mms", 3) will
reimar
parents:
15626
diff
changeset
|
55 if (!strcasecmp(proto, "mmsu") || !strcasecmp(proto, "mms")) |
12879
542d1d2200c1
reduced code complexity, and also made consistent with other parts
alex
parents:
12878
diff
changeset
|
56 { |
5915 | 57 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
|
58 //fd = asf_mmsu_streaming_start( stream ); |
12535
48ae29c2298c
Use same order as WMP for mms protocols (MMSU, MMST, HTTP)
rtognimp
parents:
12396
diff
changeset
|
59 if( fd>-1 ) return fd; //mmsu support is not implemented yet - using this code |
5915 | 60 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
|
61 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
|
62 } |
12535
48ae29c2298c
Use same order as WMP for mms protocols (MMSU, MMST, HTTP)
rtognimp
parents:
12396
diff
changeset
|
63 |
48ae29c2298c
Use same order as WMP for mms protocols (MMSU, MMST, HTTP)
rtognimp
parents:
12396
diff
changeset
|
64 //Is protocol mms or mmst? |
16112
0aeb954fc11c
strncasecmp is not necessary and e.g. strncasecmp(prot, "mms", 3) will
reimar
parents:
15626
diff
changeset
|
65 if (!strcasecmp(proto, "mmst") || !strcasecmp(proto, "mms")) |
12879
542d1d2200c1
reduced code complexity, and also made consistent with other parts
alex
parents:
12878
diff
changeset
|
66 { |
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 ); |
14525 | 69 stream->streaming_ctrl->url->port = port; |
8823 | 70 if( fd>-1 ) return fd; |
5915 | 71 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
|
72 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
|
73 } |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
74 |
12535
48ae29c2298c
Use same order as WMP for mms protocols (MMSU, MMST, HTTP)
rtognimp
parents:
12396
diff
changeset
|
75 //Is protocol http, http_proxy, or mms? |
16112
0aeb954fc11c
strncasecmp is not necessary and e.g. strncasecmp(prot, "mms", 3) will
reimar
parents:
15626
diff
changeset
|
76 if (!strcasecmp(proto, "http_proxy") || !strcasecmp(proto, "http") || |
0aeb954fc11c
strncasecmp is not necessary and e.g. strncasecmp(prot, "mms", 3) will
reimar
parents:
15626
diff
changeset
|
77 !strcasecmp(proto, "mms") || !strcasecmp(proto, "mmshttp")) |
12879
542d1d2200c1
reduced code complexity, and also made consistent with other parts
alex
parents:
12878
diff
changeset
|
78 { |
12535
48ae29c2298c
Use same order as WMP for mms protocols (MMSU, MMST, HTTP)
rtognimp
parents:
12396
diff
changeset
|
79 mp_msg(MSGT_NETWORK,MSGL_V,"Trying ASF/HTTP...\n"); |
48ae29c2298c
Use same order as WMP for mms protocols (MMSU, MMST, HTTP)
rtognimp
parents:
12396
diff
changeset
|
80 fd = asf_http_streaming_start( stream, demuxer_type ); |
14525 | 81 stream->streaming_ctrl->url->port = port; |
12535
48ae29c2298c
Use same order as WMP for mms protocols (MMSU, MMST, HTTP)
rtognimp
parents:
12396
diff
changeset
|
82 if( fd>-1 ) return fd; |
48ae29c2298c
Use same order as WMP for mms protocols (MMSU, MMST, HTTP)
rtognimp
parents:
12396
diff
changeset
|
83 mp_msg(MSGT_NETWORK,MSGL_V," ===> ASF/HTTP failed\n"); |
48ae29c2298c
Use same order as WMP for mms protocols (MMSU, MMST, HTTP)
rtognimp
parents:
12396
diff
changeset
|
84 if( fd==-2 ) return -1; |
48ae29c2298c
Use same order as WMP for mms protocols (MMSU, MMST, HTTP)
rtognimp
parents:
12396
diff
changeset
|
85 } |
48ae29c2298c
Use same order as WMP for mms protocols (MMSU, MMST, HTTP)
rtognimp
parents:
12396
diff
changeset
|
86 |
48ae29c2298c
Use same order as WMP for mms protocols (MMSU, MMST, HTTP)
rtognimp
parents:
12396
diff
changeset
|
87 //everything failed |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
88 return -1; |
3042 | 89 } |
90 | |
15626
941b1a71351f
printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents:
15585
diff
changeset
|
91 static int asf_streaming(ASF_stream_chunck_t *stream_chunck, int *drop_packet ) { |
4046
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
92 /* |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
93 printf("ASF stream chunck size=%d\n", stream_chunck->size); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
94 printf("length: %d\n", length ); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
95 printf("0x%02X\n", stream_chunck->type ); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
96 */ |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
97 if( drop_packet!=NULL ) *drop_packet = 0; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
98 |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
99 if( stream_chunck->size<8 ) { |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
100 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_StreamChunkSize2Small, stream_chunck->size); |
4046
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
101 return -1; |
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 if( stream_chunck->size!=stream_chunck->size_confirm ) { |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
104 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_SizeConfirmMismatch, stream_chunck->size, stream_chunck->size_confirm); |
4046
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
105 return -1; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
106 } |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
107 /* |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
108 printf(" type: 0x%02X\n", stream_chunck->type ); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
109 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
|
110 printf(" sequence_number: 0x%04X\n", stream_chunck->sequence_number ); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
111 printf(" unknown: 0x%02X\n", stream_chunck->unknown ); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
112 printf(" size_confirm: 0x%02X\n", stream_chunck->size_confirm ); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
113 */ |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
114 switch(stream_chunck->type) { |
5617
75a43bb3ed80
Added big endian handling for the ASF_chunk_t struct.
bertrand
parents:
4334
diff
changeset
|
115 case ASF_STREAMING_CLEAR: // $C Clear ASF configuration |
5915 | 116 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
|
117 if( drop_packet!=NULL ) *drop_packet = 1; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
118 return stream_chunck->size; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
119 break; |
5617
75a43bb3ed80
Added big endian handling for the ASF_chunk_t struct.
bertrand
parents:
4334
diff
changeset
|
120 case ASF_STREAMING_DATA: // $D Data follows |
4046
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
121 // printf("=====> Data follows\n"); |
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_END_TRANS: // $E Transfer complete |
5915 | 124 mp_msg(MSGT_NETWORK,MSGL_V,"=====> Transfer complete\n"); |
4046
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
125 if( drop_packet!=NULL ) *drop_packet = 1; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
126 return stream_chunck->size; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
127 break; |
5617
75a43bb3ed80
Added big endian handling for the ASF_chunk_t struct.
bertrand
parents:
4334
diff
changeset
|
128 case ASF_STREAMING_HEADER: // $H ASF header chunk follows |
5915 | 129 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
|
130 break; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
131 default: |
5915 | 132 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
|
133 } |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
134 return stream_chunck->size+4; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
135 } |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
136 |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
137 extern int find_asf_guid(char *buf, const char *guid, int cur_pos, int buf_len); |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
138 extern const char asf_file_header_guid[]; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
139 extern const char asf_stream_header_guid[]; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
140 extern const char asf_stream_group_guid[]; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
141 extern int audio_id; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
142 extern int video_id; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
143 |
15585 | 144 static void close_s(stream_t *stream) { |
145 close(stream->fd); | |
146 stream->fd=-1; | |
147 } | |
148 | |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
149 static int max_idx(int s_count, int *s_rates, int bound) { |
14639 | 150 int i, best = -1, rate = -1; |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
151 for (i = 0; i < s_count; i++) { |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
152 if (s_rates[i] > rate && s_rates[i] <= bound) { |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
153 rate = s_rates[i]; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
154 best = i; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
155 } |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
156 } |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
157 return best; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
158 } |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
159 |
15626
941b1a71351f
printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents:
15585
diff
changeset
|
160 static int 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
|
161 ASF_header_t asfh; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
162 ASF_stream_chunck_t chunk; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
163 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
|
164 char* buffer=NULL, *chunk_buffer=NULL; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
165 int i,r,size,pos = 0; |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
166 int start; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
167 int buffer_size = 0; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
168 int chunk_size2read = 0; |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
169 int bw = streaming_ctrl->bandwidth; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
170 int *v_rates = NULL, *a_rates = NULL; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
171 int v_rate = 0, a_rate = 0, a_idx = -1, v_idx = -1; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
172 |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
173 if(asf_ctrl == NULL) return -1; |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
174 |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
175 // 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
|
176 // 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
|
177 // 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
|
178 do { |
7953 | 179 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
|
180 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
|
181 if(i <= 0) return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
182 r += i; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
183 } |
5617
75a43bb3ed80
Added big endian handling for the ASF_chunk_t struct.
bertrand
parents:
4334
diff
changeset
|
184 // Endian handling of the stream chunk |
75a43bb3ed80
Added big endian handling for the ASF_chunk_t struct.
bertrand
parents:
4334
diff
changeset
|
185 le2me_ASF_stream_chunck_t(&chunk); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
186 size = asf_streaming( &chunk, &r) - sizeof(ASF_stream_chunck_t); |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
187 if(r) mp_msg(MSGT_NETWORK,MSGL_WARN,MSGTR_MPDEMUX_ASF_WarnDropHeader); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
188 if(size < 0){ |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
189 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_ErrorParsingChunkHeader); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
190 return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
191 } |
5617
75a43bb3ed80
Added big endian handling for the ASF_chunk_t struct.
bertrand
parents:
4334
diff
changeset
|
192 if (chunk.type != ASF_STREAMING_HEADER) { |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
193 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_NoHeaderAtFirstChunk); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
194 return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
195 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
196 |
18558
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
17932
diff
changeset
|
197 // audit: do not overflow buffer_size |
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
17932
diff
changeset
|
198 if (size > SIZE_MAX - buffer_size) return -1; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
199 buffer = (char*) malloc(size+buffer_size); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
200 if(buffer == NULL) { |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
201 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MPDEMUX_ASF_BufferMallocFailed,size+buffer_size); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
202 return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
203 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
204 if( chunk_buffer!=NULL ) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
205 memcpy( buffer, chunk_buffer, buffer_size ); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
206 free( chunk_buffer ); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
207 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
208 chunk_buffer = buffer; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
209 buffer += buffer_size; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
210 buffer_size += size; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
211 |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
212 for(r = 0; r < size;) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
213 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
|
214 if(i < 0) { |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
215 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_ErrReadingNetworkStream); |
3533
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 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
218 r += i; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
219 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
220 |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
221 if( chunk_size2read==0 ) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
222 if(size < (int)sizeof(asfh)) { |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
223 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_ErrChunk2Small); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
224 return -1; |
5915 | 225 } 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
|
226 memcpy(&asfh,buffer,sizeof(asfh)); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
227 le2me_ASF_header_t(&asfh); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
228 chunk_size2read = asfh.objh.size; |
5915 | 229 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
|
230 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
231 } while( buffer_size<chunk_size2read); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
232 buffer = chunk_buffer; |
3551 | 233 size = buffer_size; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
234 |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
235 if(asfh.cno > 256) { |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
236 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_ErrSubChunkNumberInvalid); |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
237 return -1; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
238 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
239 |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
240 start = sizeof(asfh); |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
241 |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
242 pos = find_asf_guid(buffer, asf_file_header_guid, start, size); |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
243 if (pos >= 0) { |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
244 ASF_file_header_t *fileh = (ASF_file_header_t *) &buffer[pos]; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
245 pos += sizeof(ASF_file_header_t); |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
246 if (pos > size) goto len_err_out; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
247 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
|
248 /* |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
249 if(fileh.packetsize != fileh.packetsize2) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
250 printf("Error packetsize check don't match\n"); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
251 return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
252 } |
4288
b84e9861461c
Changed the asf_file_header_t struct to read all the fields properly.
bertrand
parents:
4145
diff
changeset
|
253 */ |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
254 asf_ctrl->packet_size = fileh->max_packet_size; |
4288
b84e9861461c
Changed the asf_file_header_t struct to read all the fields properly.
bertrand
parents:
4145
diff
changeset
|
255 // before playing. |
b84e9861461c
Changed the asf_file_header_t struct to read all the fields properly.
bertrand
parents:
4145
diff
changeset
|
256 // preroll: time in ms to bufferize before playing |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
257 streaming_ctrl->prebuffer_size = (unsigned int)(((double)fileh->preroll/1000.0)*((double)fileh->max_bitrate/8.0)); |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
258 } |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
259 |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
260 pos = start; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
261 while ((pos = find_asf_guid(buffer, asf_stream_header_guid, pos, size)) >= 0) |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
262 { |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
263 ASF_stream_header_t *streamh = (ASF_stream_header_t *)&buffer[pos]; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
264 pos += sizeof(ASF_stream_header_t); |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
265 if (pos > size) goto len_err_out; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
266 le2me_ASF_stream_header_t(streamh); |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
267 switch(ASF_LOAD_GUID_PREFIX(streamh->type)) { |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
268 case 0xF8699E40 : // audio stream |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
269 if(asf_ctrl->audio_streams == NULL){ |
19062
83c3afeab35d
drops casts from void * on malloc/calloc from libmpdemux code
reynaldo
parents:
18558
diff
changeset
|
270 asf_ctrl->audio_streams = malloc(sizeof(int)); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
271 asf_ctrl->n_audio = 1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
272 } else { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
273 asf_ctrl->n_audio++; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
274 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
|
275 asf_ctrl->n_audio*sizeof(int)); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
276 } |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
277 asf_ctrl->audio_streams[asf_ctrl->n_audio-1] = streamh->stream_no; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
278 break; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
279 case 0xBC19EFC0 : // video stream |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
280 if(asf_ctrl->video_streams == NULL){ |
19062
83c3afeab35d
drops casts from void * on malloc/calloc from libmpdemux code
reynaldo
parents:
18558
diff
changeset
|
281 asf_ctrl->video_streams = malloc(sizeof(int)); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
282 asf_ctrl->n_video = 1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
283 } else { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
284 asf_ctrl->n_video++; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
285 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
|
286 asf_ctrl->n_video*sizeof(int)); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
287 } |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
288 asf_ctrl->video_streams[asf_ctrl->n_video-1] = streamh->stream_no; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
289 break; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
290 } |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
291 } |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
292 |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
293 // always allocate to avoid lots of ifs later |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
294 v_rates = calloc(asf_ctrl->n_video, sizeof(int)); |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
295 a_rates = calloc(asf_ctrl->n_audio, sizeof(int)); |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
296 |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
297 pos = find_asf_guid(buffer, asf_stream_group_guid, start, size); |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
298 if (pos >= 0) { |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
299 // stream bitrate properties object |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
300 int stream_count; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
301 char *ptr = &buffer[pos]; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
302 |
14262 | 303 mp_msg(MSGT_NETWORK, MSGL_V, "Stream bitrate properties object\n"); |
6643 | 304 stream_count = le2me_16(*(uint16_t*)ptr); |
305 ptr += sizeof(uint16_t); | |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
306 if (ptr > &buffer[size]) goto len_err_out; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
307 mp_msg(MSGT_NETWORK, MSGL_V, " stream count=[0x%x][%u]\n", |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
308 stream_count, stream_count ); |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
309 for( i=0 ; i<stream_count ; i++ ) { |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
310 uint32_t rate; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
311 int id; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
312 int j; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
313 id = le2me_16(*(uint16_t*)ptr); |
6643 | 314 ptr += sizeof(uint16_t); |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
315 if (ptr > &buffer[size]) goto len_err_out; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
316 memcpy(&rate, ptr, sizeof(uint32_t));// workaround unaligment bug on sparc |
6643 | 317 ptr += sizeof(uint32_t); |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
318 if (ptr > &buffer[size]) goto len_err_out; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
319 rate = le2me_32(rate); |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
320 mp_msg(MSGT_NETWORK, MSGL_V, |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
321 " stream id=[0x%x][%u]\n", id, id); |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
322 mp_msg(MSGT_NETWORK, MSGL_V, |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
323 " max bitrate=[0x%x][%u]\n", rate, rate); |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
324 for (j = 0; j < asf_ctrl->n_video; j++) { |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
325 if (id == asf_ctrl->video_streams[j]) { |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
326 mp_msg(MSGT_NETWORK, MSGL_V, " is video stream\n"); |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
327 v_rates[j] = rate; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
328 break; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
329 } |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
330 } |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
331 for (j = 0; j < asf_ctrl->n_audio; j++) { |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
332 if (id == asf_ctrl->audio_streams[j]) { |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
333 mp_msg(MSGT_NETWORK, MSGL_V, " is audio stream\n"); |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
334 a_rates[j] = rate; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
335 break; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
336 } |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
337 } |
6643 | 338 } |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
339 } |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
340 free(buffer); |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
341 |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
342 // automatic stream selection based on bandwidth |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
343 if (bw == 0) bw = INT_MAX; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
344 mp_msg(MSGT_NETWORK, MSGL_V, "Max bandwidth set to %d\n", bw); |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
345 |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
346 if (asf_ctrl->n_audio) { |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
347 // find lowest-bitrate audio stream |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
348 a_rate = a_rates[0]; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
349 a_idx = 0; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
350 for (i = 0; i < asf_ctrl->n_audio; i++) { |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
351 if (a_rates[i] < a_rate) { |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
352 a_rate = a_rates[i]; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
353 a_idx = i; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
354 } |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
355 } |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
356 if (max_idx(asf_ctrl->n_video, v_rates, bw - a_rate) < 0) { |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
357 // both audio and video are not possible, try video only next |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
358 a_idx = -1; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
359 a_rate = 0; |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
360 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
361 } |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
362 // find best video stream |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
363 v_idx = max_idx(asf_ctrl->n_video, v_rates, bw - a_rate); |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
364 if (v_idx >= 0) |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
365 v_rate = v_rates[v_idx]; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
366 |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
367 // find best audio stream |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
368 a_idx = max_idx(asf_ctrl->n_audio, a_rates, bw - v_rate); |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
369 |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
370 free(v_rates); |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
371 free(a_rates); |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
372 |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
373 if (a_idx < 0 && v_idx < 0) { |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
374 mp_msg(MSGT_NETWORK, MSGL_FATAL, MSGTR_MPDEMUX_ASF_Bandwidth2SmallCannotPlay); |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
375 return -1; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
376 } |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
377 |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
378 if (audio_id > 0) |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
379 // a audio stream was forced |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
380 asf_ctrl->audio_id = audio_id; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
381 else if (a_idx >= 0) |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
382 asf_ctrl->audio_id = asf_ctrl->audio_streams[a_idx]; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
383 else if (asf_ctrl->n_audio) { |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
384 mp_msg(MSGT_NETWORK, MSGL_WARN, MSGTR_MPDEMUX_ASF_Bandwidth2SmallDeselectedAudio); |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
385 audio_id = -2; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
386 } |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
387 |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
388 if (video_id > 0) |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
389 // a video stream was forced |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
390 asf_ctrl->video_id = video_id; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
391 else if (v_idx >= 0) |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
392 asf_ctrl->video_id = asf_ctrl->video_streams[v_idx]; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
393 else if (asf_ctrl->n_video) { |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
394 mp_msg(MSGT_NETWORK, MSGL_WARN, MSGTR_MPDEMUX_ASF_Bandwidth2SmallDeselectedVideo); |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
395 video_id = -2; |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
396 } |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
397 |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
398 return 1; |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
399 |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
400 len_err_out: |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
401 mp_msg(MSGT_NETWORK, MSGL_FATAL, MSGTR_MPDEMUX_ASF_InvalidLenInHeader); |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
402 if (buffer) free(buffer); |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
403 if (v_rates) free(v_rates); |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
404 if (a_rates) free(a_rates); |
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
405 return -1; |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
406 } |
3042 | 407 |
15626
941b1a71351f
printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents:
15585
diff
changeset
|
408 static int 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
|
409 static ASF_stream_chunck_t chunk; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
410 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
|
411 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
|
412 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
|
413 |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
414 while(1) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
415 if (rest == 0 && waiting == 0) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
416 read = 0; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
417 while(read < (int)sizeof(ASF_stream_chunck_t)){ |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
418 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
|
419 sizeof(ASF_stream_chunck_t)-read, |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
420 streaming_ctrl ); |
4041
879a668ee540
various small streaming fixes by Alban Bedel <albeu@free.fr>
arpi
parents:
3727
diff
changeset
|
421 if(r <= 0){ |
879a668ee540
various small streaming fixes by Alban Bedel <albeu@free.fr>
arpi
parents:
3727
diff
changeset
|
422 if( r < 0) |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
423 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_ErrReadingChunkHeader); |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
424 return -1; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
425 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
426 read += r; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
427 } |
5617
75a43bb3ed80
Added big endian handling for the ASF_chunk_t struct.
bertrand
parents:
4334
diff
changeset
|
428 |
75a43bb3ed80
Added big endian handling for the ASF_chunk_t struct.
bertrand
parents:
4334
diff
changeset
|
429 // Endian handling of the stream chunk |
75a43bb3ed80
Added big endian handling for the ASF_chunk_t struct.
bertrand
parents:
4334
diff
changeset
|
430 le2me_ASF_stream_chunck_t(&chunk); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
431 chunk_size = asf_streaming( &chunk, &drop_chunk ); |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
432 if(chunk_size < 0) { |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
433 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_ErrorParsingChunkHeader); |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
434 return -1; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
435 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
436 chunk_size -= sizeof(ASF_stream_chunck_t); |
3042 | 437 |
5617
75a43bb3ed80
Added big endian handling for the ASF_chunk_t struct.
bertrand
parents:
4334
diff
changeset
|
438 if(chunk.type != ASF_STREAMING_HEADER && (!drop_chunk)) { |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
439 if (asf_http_ctrl->packet_size < chunk_size) { |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
440 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_ErrChunkBiggerThanPacket); |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
441 return -1; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
442 } |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
443 waiting = asf_http_ctrl->packet_size; |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
444 } else { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
445 waiting = chunk_size; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
446 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
447 |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
448 } else if (rest){ |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
449 chunk_size = rest; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
450 rest = 0; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
451 } |
3042 | 452 |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
453 read = 0; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
454 if ( waiting >= chunk_size) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
455 if (chunk_size > size){ |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
456 rest = chunk_size - size; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
457 chunk_size = size; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
458 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
459 while(read < chunk_size) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
460 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
|
461 if(got <= 0) { |
879a668ee540
various small streaming fixes by Alban Bedel <albeu@free.fr>
arpi
parents:
3727
diff
changeset
|
462 if(got < 0) |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
463 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_ErrReadingChunk); |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
464 return -1; |
1001 | 465 } |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
466 read += got; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
467 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
468 waiting -= read; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
469 if (drop_chunk) continue; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
470 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
471 if (rest == 0 && waiting > 0 && size-read > 0) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
472 int s = MIN(waiting,size-read); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
473 memset(buffer+read,0,s); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
474 waiting -= s; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
475 read += s; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
476 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
477 break; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
478 } |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
479 |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
480 return read; |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
481 } |
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
482 |
15626
941b1a71351f
printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents:
15585
diff
changeset
|
483 static int asf_http_streaming_seek( int fd, off_t pos, streaming_ctrl_t *streaming_ctrl ) { |
3042 | 484 return -1; |
7953 | 485 // to shut up gcc warning |
486 fd++; | |
487 pos++; | |
488 streaming_ctrl=NULL; | |
3042 | 489 } |
490 | |
15626
941b1a71351f
printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents:
15585
diff
changeset
|
491 static int asf_header_check( HTTP_header_t *http_hdr ) { |
4312
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
492 ASF_obj_header_t *objh; |
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
493 if( http_hdr==NULL ) return -1; |
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
494 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
|
495 |
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
496 objh = (ASF_obj_header_t*)http_hdr->body; |
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
497 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
|
498 return -1; |
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
499 } |
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
500 |
15626
941b1a71351f
printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents:
15585
diff
changeset
|
501 static int asf_http_streaming_type(char *content_type, char *features, HTTP_header_t *http_hdr ) { |
905 | 502 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
|
503 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
|
504 !strcasecmp(content_type, "application/vnd.ms.wms-hdr.asfv1") || // New in Corona, first request |
11349
786407b1bc78
Accept video/x-ms-asf as the MIME type for ASF as well. Patch by Dominique Andre Gunia <Dominique.Gunia@schunter.etc.tu-bs.de>.
mosu
parents:
10939
diff
changeset
|
505 !strcasecmp(content_type, "application/x-mms-framed") || // New in Corana, second request |
786407b1bc78
Accept video/x-ms-asf as the MIME type for ASF as well. Patch by Dominique Andre Gunia <Dominique.Gunia@schunter.etc.tu-bs.de>.
mosu
parents:
10939
diff
changeset
|
506 !strcasecmp(content_type, "video/x-ms-asf")) { |
7252
0a0527c82560
- If fatal error while trying to connect to a WM server, skip other proto.
bertrand
parents:
6677
diff
changeset
|
507 |
8718
d630a6f4c7c0
- Now mmst will use the MMS/TCP implementation first, instead of trying
bertrand
parents:
7953
diff
changeset
|
508 if( strstr(features, "broadcast") ) { |
5915 | 509 mp_msg(MSGT_NETWORK,MSGL_V,"=====> ASF Live stream\n"); |
905 | 510 return ASF_Live_e; |
833 | 511 } else { |
5915 | 512 mp_msg(MSGT_NETWORK,MSGL_V,"=====> ASF Prerecorded\n"); |
905 | 513 return ASF_Prerecorded_e; |
833 | 514 } |
515 } else { | |
4312
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
516 // 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
|
517 // 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
|
518 // 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
|
519 // 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
|
520 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
|
521 if( asf_header_check( http_hdr )==0 ) { |
5915 | 522 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
|
523 return ASF_PlainText_e; |
8718
d630a6f4c7c0
- Now mmst will use the MMS/TCP implementation first, instead of trying
bertrand
parents:
7953
diff
changeset
|
524 } else if( (!strcasecmp(content_type, "text/html")) ) { |
12654 | 525 mp_msg(MSGT_NETWORK,MSGL_V,"=====> HTML, MPlayer is not a browser...yet!\n"); |
8718
d630a6f4c7c0
- Now mmst will use the MMS/TCP implementation first, instead of trying
bertrand
parents:
7953
diff
changeset
|
526 return ASF_Unknown_e; |
4334
3fb147d59ca6
Readded the content-type checking, in case of the no HTTP body are
bertrand
parents:
4315
diff
changeset
|
527 } else { |
5915 | 528 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
|
529 return ASF_Redirector_e; |
3fb147d59ca6
Readded the content-type checking, in case of the no HTTP body are
bertrand
parents:
4315
diff
changeset
|
530 } |
4312
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
531 } else { |
4334
3fb147d59ca6
Readded the content-type checking, in case of the no HTTP body are
bertrand
parents:
4315
diff
changeset
|
532 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
|
533 (!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
|
534 (!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
|
535 (!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
|
536 (!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
|
537 (!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
|
538 (!strcasecmp(content_type, "video/x-ms-wma")) ) { |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
539 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_ASFRedirector); |
4334
3fb147d59ca6
Readded the content-type checking, in case of the no HTTP body are
bertrand
parents:
4315
diff
changeset
|
540 return ASF_Redirector_e; |
3fb147d59ca6
Readded the content-type checking, in case of the no HTTP body are
bertrand
parents:
4315
diff
changeset
|
541 } else if( !strcasecmp(content_type, "text/plain") ) { |
5915 | 542 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
|
543 return ASF_PlainText_e; |
3fb147d59ca6
Readded the content-type checking, in case of the no HTTP body are
bertrand
parents:
4315
diff
changeset
|
544 } else { |
5915 | 545 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
|
546 return ASF_Unknown_e; |
3fb147d59ca6
Readded the content-type checking, in case of the no HTTP body are
bertrand
parents:
4315
diff
changeset
|
547 } |
4312
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
548 } |
833 | 549 } |
905 | 550 return ASF_Unknown_e; |
833 | 551 } |
871 | 552 |
15626
941b1a71351f
printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents:
15585
diff
changeset
|
553 static HTTP_header_t *asf_http_request(streaming_ctrl_t *streaming_ctrl) { |
871 | 554 HTTP_header_t *http_hdr; |
4121 | 555 URL_t *url = NULL; |
556 URL_t *server_url = NULL; | |
557 asf_http_streaming_ctrl_t *asf_http_ctrl; | |
871 | 558 char str[250]; |
1001 | 559 char *ptr; |
6643 | 560 int i, enable; |
871 | 561 |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
562 int offset_hi=0, offset_lo=0, length=0; |
6643 | 563 int asf_nb_stream=0, stream_id; |
871 | 564 |
4121 | 565 // Sanity check |
566 if( streaming_ctrl==NULL ) return NULL; | |
567 url = streaming_ctrl->url; | |
568 asf_http_ctrl = (asf_http_streaming_ctrl_t*)streaming_ctrl->data; | |
569 if( url==NULL || asf_http_ctrl==NULL ) return NULL; | |
570 | |
871 | 571 // Common header for all requests. |
572 http_hdr = http_new_header(); | |
573 http_set_field( http_hdr, "Accept: */*" ); | |
574 http_set_field( http_hdr, "User-Agent: NSPlayer/4.1.0.3856" ); | |
6670 | 575 http_add_basic_authentication( http_hdr, url->username, url->password ); |
4121 | 576 |
577 // Check if we are using a proxy | |
4145 | 578 if( !strcasecmp( url->protocol, "http_proxy" ) ) { |
4121 | 579 server_url = url_new( (url->file)+1 ); |
580 if( server_url==NULL ) { | |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
581 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_InvalidProxyURL); |
4121 | 582 http_free( http_hdr ); |
583 return NULL; | |
584 } | |
585 http_set_uri( http_hdr, server_url->url ); | |
10939
55c9903bd51c
simple fix for buffer overflow (remotely exploitable). feel free to
rfelker
parents:
10625
diff
changeset
|
586 sprintf( str, "Host: %.220s:%d", server_url->hostname, server_url->port ); |
4121 | 587 url_free( server_url ); |
588 } else { | |
589 http_set_uri( http_hdr, url->file ); | |
10939
55c9903bd51c
simple fix for buffer overflow (remotely exploitable). feel free to
rfelker
parents:
10625
diff
changeset
|
590 sprintf( str, "Host: %.220s:%d", url->hostname, url->port ); |
4121 | 591 } |
592 | |
871 | 593 http_set_field( http_hdr, str ); |
594 http_set_field( http_hdr, "Pragma: xClientGUID={c77e7400-738a-11d2-9add-0020af0a3278}" ); | |
595 sprintf(str, | |
596 "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
|
597 offset_hi, offset_lo, asf_http_ctrl->request, length ); |
871 | 598 http_set_field( http_hdr, str ); |
599 | |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
600 switch( asf_http_ctrl->streaming_type ) { |
871 | 601 case ASF_Live_e: |
602 case ASF_Prerecorded_e: | |
603 http_set_field( http_hdr, "Pragma: xPlayStrm=1" ); | |
1001 | 604 ptr = str; |
605 ptr += sprintf( ptr, "Pragma: stream-switch-entry="); | |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
606 if(asf_http_ctrl->n_audio > 0) { |
6643 | 607 for( i=0; i<asf_http_ctrl->n_audio ; i++ ) { |
608 stream_id = asf_http_ctrl->audio_streams[i]; | |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
609 if(stream_id == asf_http_ctrl->audio_id) { |
6643 | 610 enable = 0; |
611 } else { | |
612 enable = 2; | |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
613 continue; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
614 } |
6643 | 615 asf_nb_stream++; |
616 ptr += sprintf(ptr, "ffff:%d:%d ", stream_id, enable); | |
1001 | 617 } |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
618 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
619 if(asf_http_ctrl->n_video > 0) { |
6643 | 620 for( i=0; i<asf_http_ctrl->n_video ; i++ ) { |
621 stream_id = asf_http_ctrl->video_streams[i]; | |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
622 if(stream_id == asf_http_ctrl->video_id) { |
6643 | 623 enable = 0; |
624 } else { | |
625 enable = 2; | |
14236
2dc4595c3998
fix stream selection and -bandwidth for mms-over-http.
reimar
parents:
12879
diff
changeset
|
626 continue; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
627 } |
6643 | 628 asf_nb_stream++; |
629 ptr += sprintf(ptr, "ffff:%d:%d ", stream_id, enable); | |
1001 | 630 } |
631 } | |
632 http_set_field( http_hdr, str ); | |
871 | 633 sprintf( str, "Pragma: stream-switch-count=%d", asf_nb_stream ); |
634 http_set_field( http_hdr, str ); | |
635 break; | |
636 case ASF_Redirector_e: | |
637 break; | |
638 case ASF_Unknown_e: | |
639 // First request goes here. | |
640 break; | |
641 default: | |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
642 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_UnknownASFStreamType); |
871 | 643 } |
644 | |
645 http_set_field( http_hdr, "Connection: Close" ); | |
905 | 646 http_build_request( http_hdr ); |
871 | 647 |
905 | 648 return http_hdr; |
871 | 649 } |
650 | |
15626
941b1a71351f
printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents:
15585
diff
changeset
|
651 static int asf_http_parse_response(asf_http_streaming_ctrl_t *asf_http_ctrl, HTTP_header_t *http_hdr ) { |
871 | 652 char *content_type, *pragma; |
653 char features[64] = "\0"; | |
7953 | 654 size_t len; |
905 | 655 if( http_response_parse(http_hdr)<0 ) { |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
656 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_Failed2ParseHTTPResponse); |
905 | 657 return -1; |
658 } | |
6677 | 659 switch( http_hdr->status_code ) { |
660 case 200: | |
661 break; | |
662 case 401: // Authentication required | |
663 return ASF_Authenticate_e; | |
664 default: | |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
665 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_ServerReturn, http_hdr->status_code, http_hdr->reason_phrase); |
6677 | 666 return -1; |
871 | 667 } |
668 | |
669 content_type = http_get_field( http_hdr, "Content-Type"); | |
3042 | 670 //printf("Content-Type: [%s]\n", content_type); |
871 | 671 |
672 pragma = http_get_field( http_hdr, "Pragma"); | |
905 | 673 while( pragma!=NULL ) { |
871 | 674 char *comma_ptr=NULL; |
675 char *end; | |
3042 | 676 //printf("Pragma: [%s]\n", pragma ); |
871 | 677 // The pragma line can get severals attributes |
678 // separeted with a comma ','. | |
679 do { | |
680 if( !strncasecmp( pragma, "features=", 9) ) { | |
681 pragma += 9; | |
682 end = strstr( pragma, "," ); | |
683 if( end==NULL ) { | |
17837 | 684 len = strlen(pragma); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
685 } else { |
17837 | 686 len = (unsigned int)(end-pragma); |
687 } | |
688 if(len > sizeof(features) - 1) { | |
17840 | 689 mp_msg(MSGT_NETWORK,MSGL_WARN,MSGTR_MPDEMUX_ASF_ASFHTTPParseWarnCuttedPragma,pragma,len,sizeof(features) - 1); |
17837 | 690 len = sizeof(features) - 1; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
691 } |
871 | 692 strncpy( features, pragma, len ); |
693 features[len]='\0'; | |
694 break; | |
695 } | |
696 comma_ptr = strstr( pragma, "," ); | |
697 if( comma_ptr!=NULL ) { | |
698 pragma = comma_ptr+1; | |
699 if( pragma[0]==' ' ) pragma++; | |
700 } | |
701 } while( comma_ptr!=NULL ); | |
702 pragma = http_get_next_field( http_hdr ); | |
905 | 703 } |
7953 | 704 asf_http_ctrl->streaming_type = asf_http_streaming_type( content_type, features, http_hdr ); |
705 return 0; | |
871 | 706 } |
707 | |
15626
941b1a71351f
printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents:
15585
diff
changeset
|
708 static int asf_http_streaming_start( stream_t *stream, int *demuxer_type ) { |
905 | 709 HTTP_header_t *http_hdr=NULL; |
3042 | 710 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
|
711 asf_http_streaming_ctrl_t *asf_http_ctrl; |
905 | 712 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
|
713 int i, ret; |
3042 | 714 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
|
715 int done; |
6677 | 716 int auth_retry = 0; |
1001 | 717 |
19062
83c3afeab35d
drops casts from void * on malloc/calloc from libmpdemux code
reynaldo
parents:
18558
diff
changeset
|
718 asf_http_ctrl = malloc(sizeof(asf_http_streaming_ctrl_t)); |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
719 if( asf_http_ctrl==NULL ) { |
16907
54a414dd1c0b
Changed MSGTR_MPDEMUX_ASF_MallocFailed to MSGTR_MemAllocFailed (msg defined two times inhelp_mp-en.h)
ptt
parents:
16882
diff
changeset
|
720 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
721 return -1; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
722 } |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
723 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
|
724 asf_http_ctrl->request = 1; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
725 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
|
726 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
|
727 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
|
728 |
905 | 729 do { |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
730 done = 1; |
10281 | 731 if( fd>0 ) closesocket( fd ); |
1001 | 732 |
4145 | 733 if( !strcasecmp( url->protocol, "http_proxy" ) ) { |
4121 | 734 if( url->port==0 ) url->port = 8080; |
735 } else { | |
736 if( url->port==0 ) url->port = 80; | |
737 } | |
10625
620cc649f519
ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
10281
diff
changeset
|
738 fd = connect2Server( url->hostname, url->port, 1); |
7252
0a0527c82560
- If fatal error while trying to connect to a WM server, skip other proto.
bertrand
parents:
6677
diff
changeset
|
739 if( fd<0 ) return fd; |
905 | 740 |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
741 http_hdr = asf_http_request( stream->streaming_ctrl ); |
5915 | 742 mp_msg(MSGT_NETWORK,MSGL_DBG2,"Request [%s]\n", http_hdr->buffer ); |
7953 | 743 for(i=0; i < (int)http_hdr->buffer_size ; ) { |
10206
35e306346e59
Using recv/send instead read/write for proper MinGW support (it's a 4.2BSD standard). Patch by FloDt <flodt8@yahoo.de>
alex
parents:
9749
diff
changeset
|
744 int r = send( fd, http_hdr->buffer+i, http_hdr->buffer_size-i, 0 ); |
3494
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3475
diff
changeset
|
745 if(r <0) { |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
746 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_SocketWriteError,strerror(errno)); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
747 return -1; |
3494
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3475
diff
changeset
|
748 } |
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3475
diff
changeset
|
749 i += r; |
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3475
diff
changeset
|
750 } |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
751 http_free( http_hdr ); |
905 | 752 http_hdr = http_new_header(); |
753 do { | |
10206
35e306346e59
Using recv/send instead read/write for proper MinGW support (it's a 4.2BSD standard). Patch by FloDt <flodt8@yahoo.de>
alex
parents:
9749
diff
changeset
|
754 i = recv( fd, buffer, BUFFER_SIZE, 0 ); |
4121 | 755 //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
|
756 if( i<=0 ) { |
1001 | 757 perror("read"); |
758 http_free( http_hdr ); | |
759 return -1; | |
760 } | |
905 | 761 http_response_append( http_hdr, buffer, i ); |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
762 } while( !http_is_header_entire( http_hdr ) ); |
17932 | 763 if( mp_msg_test(MSGT_NETWORK,MSGL_V) ) { |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
764 http_hdr->buffer[http_hdr->buffer_size]='\0'; |
5915 | 765 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
|
766 } |
7953 | 767 ret = asf_http_parse_response(asf_http_ctrl, http_hdr); |
768 if( ret<0 ) { | |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
769 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_HeaderParseFailed); |
1001 | 770 http_free( http_hdr ); |
905 | 771 return -1; |
772 } | |
7953 | 773 switch( asf_http_ctrl->streaming_type ) { |
905 | 774 case ASF_Live_e: |
775 case ASF_Prerecorded_e: | |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
776 case ASF_PlainText_e: |
1001 | 777 if( http_hdr->body_size>0 ) { |
3042 | 778 if( streaming_bufferize( stream->streaming_ctrl, http_hdr->body, http_hdr->body_size )<0 ) { |
779 http_free( http_hdr ); | |
780 return -1; | |
1001 | 781 } |
905 | 782 } |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
783 if( asf_http_ctrl->request==1 ) { |
7953 | 784 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
|
785 // First request, we only got the ASF header. |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
786 ret = asf_streaming_parse_header(fd,stream->streaming_ctrl); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
787 if(ret < 0) return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
788 if(asf_http_ctrl->n_audio == 0 && asf_http_ctrl->n_video == 0) { |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
789 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_NoStreamFound); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
790 return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
791 } |
4312
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
792 asf_http_ctrl->request++; |
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
793 done = 0; |
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
794 } else { |
971836f677a9
Added a turn around for badly configured web servers.
bertrand
parents:
4288
diff
changeset
|
795 done = 1; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
796 } |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
797 } |
905 | 798 break; |
799 case ASF_Redirector_e: | |
4073
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
800 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
|
801 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
|
802 http_free( http_hdr ); |
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
803 return -1; |
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
804 } |
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
805 } |
9749 | 806 *demuxer_type = DEMUXER_TYPE_PLAYLIST; |
4073
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
807 done = 1; |
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
808 break; |
6677 | 809 case ASF_Authenticate_e: |
810 if( http_authenticate( http_hdr, url, &auth_retry)<0 ) return -1; | |
811 asf_http_ctrl->streaming_type = ASF_Unknown_e; | |
812 done = 0; | |
813 break; | |
905 | 814 case ASF_Unknown_e: |
815 default: | |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
816 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_UnknownASFStreamingType); |
10281 | 817 closesocket(fd); |
1001 | 818 http_free( http_hdr ); |
905 | 819 return -1; |
820 } | |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
821 // Check if we got a redirect. |
905 | 822 } while(!done); |
823 | |
4073
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
824 stream->fd = fd; |
7953 | 825 if( asf_http_ctrl->streaming_type==ASF_PlainText_e || asf_http_ctrl->streaming_type==ASF_Redirector_e ) { |
3042 | 826 stream->streaming_ctrl->streaming_read = nop_streaming_read; |
827 stream->streaming_ctrl->streaming_seek = nop_streaming_seek; | |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
828 } else { |
3042 | 829 stream->streaming_ctrl->streaming_read = asf_http_streaming_read; |
830 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
|
831 stream->streaming_ctrl->buffering = 1; |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
832 } |
3042 | 833 stream->streaming_ctrl->status = streaming_playing_e; |
15585 | 834 stream->close = close_s; |
1001 | 835 |
836 http_free( http_hdr ); | |
4073
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
837 return 0; |
905 | 838 } |
839 | |
15585 | 840 static int open_s(stream_t *stream,int mode, void* opts, int* file_format) { |
841 URL_t *url; | |
842 | |
843 stream->streaming_ctrl = streaming_ctrl_new(); | |
844 if( stream->streaming_ctrl==NULL ) { | |
845 return STREAM_ERROR; | |
846 } | |
847 stream->streaming_ctrl->bandwidth = network_bandwidth; | |
848 url = url_new(stream->url); | |
849 stream->streaming_ctrl->url = check4proxies(url); | |
16418
264b3b909850
check4proxies always creates a copy, so url should be freed
reimar
parents:
16112
diff
changeset
|
850 url_free(url); |
15585 | 851 |
16930 | 852 mp_msg(MSGT_OPEN, MSGL_INFO, MSGTR_MPDEMUX_ASF_InfoStreamASFURL, stream->url); |
15585 | 853 if((!strncmp(stream->url, "http", 4)) && (*file_format!=DEMUXER_TYPE_ASF && *file_format!=DEMUXER_TYPE_UNKNOWN)) { |
854 streaming_ctrl_free(stream->streaming_ctrl); | |
855 stream->streaming_ctrl = NULL; | |
856 return STREAM_UNSUPORTED; | |
857 } | |
858 | |
859 if(asf_streaming_start(stream, file_format) < 0) { | |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16418
diff
changeset
|
860 mp_msg(MSGT_OPEN, MSGL_ERR, MSGTR_MPDEMUX_ASF_StreamingFailed); |
15585 | 861 streaming_ctrl_free(stream->streaming_ctrl); |
862 stream->streaming_ctrl = NULL; | |
863 return STREAM_UNSUPORTED; | |
864 } | |
865 | |
866 *file_format = DEMUXER_TYPE_ASF; | |
867 stream->type = STREAMTYPE_STREAM; | |
868 fixup_network_stream_cache(stream); | |
869 return STREAM_OK; | |
870 } | |
871 | |
872 stream_info_t stream_info_asf = { | |
873 "mms and mms over http streaming", | |
874 "null", | |
875 "Bertrand, Reimar Doeffinger, Albeu", | |
876 "originally based on work by Majormms (is that code still there?)", | |
877 open_s, | |
878 {"mms", "mmsu", "mmst", "http", "http_proxy", "mmshttp", NULL}, | |
879 NULL, | |
880 0 // Urls are an option string | |
881 }; | |
882 |