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