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