Mercurial > mplayer.hg
annotate libmpdemux/network.c @ 17960:ec93436dc52d
Fix a/v desync for real some files
author | rtognimp |
---|---|
date | Sun, 26 Mar 2006 14:10:52 +0000 |
parents | 13b2332c5154 |
children | 77ecc381e6e9 |
rev | line source |
---|---|
903 | 1 /* |
2 * Network layer for MPlayer | |
3 * by Bertrand BAUDET <bertrand_baudet@yahoo.com> | |
4 * (C) 2001, MPlayer team. | |
5 */ | |
6 | |
1028 | 7 //#define DUMP2FILE |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
8 |
1430 | 9 #include <stdio.h> |
10 #include <stdlib.h> | |
11 #include <string.h> | |
833 | 12 #include <unistd.h> |
1430 | 13 |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
14 #include <errno.h> |
903 | 15 #include <ctype.h> |
833 | 16 |
2555
66837325b929
config.h cleanup, few things added to steram/demuxer headers
arpi
parents:
2489
diff
changeset
|
17 #include "config.h" |
66837325b929
config.h cleanup, few things added to steram/demuxer headers
arpi
parents:
2489
diff
changeset
|
18 |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
19 #include "mp_msg.h" |
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
20 #include "help_mp.h" |
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
21 |
10281 | 22 #ifndef HAVE_WINSOCK2 |
23 #define closesocket close | |
24 #else | |
25 #include <winsock2.h> | |
26 #include <ws2tcpip.h> | |
27 #endif | |
28 | |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
29 #include "stream.h" |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
30 #include "demuxer.h" |
17012 | 31 #include "m_config.h" |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
32 |
841 | 33 #include "network.h" |
903 | 34 #include "http.h" |
11583
2af52902e7dc
Send HTTP Cookies (reading from mozilla/netscape files) support by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>. Disabled by default.
alex
parents:
11505
diff
changeset
|
35 #include "cookies.h" |
903 | 36 #include "url.h" |
841 | 37 |
17012 | 38 #include "version.h" |
6466 | 39 |
4121 | 40 extern int verbose; |
7867 | 41 extern int stream_cache_size; |
4121 | 42 |
7862
013c255225d8
mpdemux.c|h moved to libinput, mpdemux_check_interrupt() -> mp_input_check_interrupt()
arpi
parents:
7513
diff
changeset
|
43 extern int mp_input_check_interrupt(int time); |
013c255225d8
mpdemux.c|h moved to libinput, mpdemux_check_interrupt() -> mp_input_check_interrupt()
arpi
parents:
7513
diff
changeset
|
44 |
11583
2af52902e7dc
Send HTTP Cookies (reading from mozilla/netscape files) support by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>. Disabled by default.
alex
parents:
11505
diff
changeset
|
45 /* Variables for the command line option -user, -passwd, -bandwidth, |
2af52902e7dc
Send HTTP Cookies (reading from mozilla/netscape files) support by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>. Disabled by default.
alex
parents:
11505
diff
changeset
|
46 -user-agent and -nocookies */ |
2af52902e7dc
Send HTTP Cookies (reading from mozilla/netscape files) support by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>. Disabled by default.
alex
parents:
11505
diff
changeset
|
47 |
7867 | 48 char *network_username=NULL; |
49 char *network_password=NULL; | |
50 int network_bandwidth=0; | |
11583
2af52902e7dc
Send HTTP Cookies (reading from mozilla/netscape files) support by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>. Disabled by default.
alex
parents:
11505
diff
changeset
|
51 int network_cookies_enabled = 0; |
11228 | 52 char *network_useragent=NULL; |
6558
b379b061ce50
Read username/password from the -user -pass command line options.
bertrand
parents:
6555
diff
changeset
|
53 |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
54 /* IPv6 options */ |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
55 int network_prefer_ipv4 = 0; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
56 int network_ipv4_only_proxy = 0; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
57 |
6558
b379b061ce50
Read username/password from the -user -pass command line options.
bertrand
parents:
6555
diff
changeset
|
58 |
15585 | 59 mime_struct_t mime_type_table[] = { |
3042 | 60 // MP3 streaming, some MP3 streaming server answer with audio/mpeg |
4729
f51bd827ed1c
fixed MP3 ICY detection, return detected file format for open_stream
alex
parents:
4652
diff
changeset
|
61 { "audio/mpeg", DEMUXER_TYPE_AUDIO }, |
3042 | 62 // MPEG streaming |
14002
009337ffcfc4
forced autodetection of file format when content-type is video-x-mpeg to give mpeg-ts a chance
nicodvb
parents:
12894
diff
changeset
|
63 { "video/mpeg", DEMUXER_TYPE_UNKNOWN }, |
009337ffcfc4
forced autodetection of file format when content-type is video-x-mpeg to give mpeg-ts a chance
nicodvb
parents:
12894
diff
changeset
|
64 { "video/x-mpeg", DEMUXER_TYPE_UNKNOWN }, |
009337ffcfc4
forced autodetection of file format when content-type is video-x-mpeg to give mpeg-ts a chance
nicodvb
parents:
12894
diff
changeset
|
65 { "video/x-mpeg2", DEMUXER_TYPE_UNKNOWN }, |
3042 | 66 // AVI ??? => video/x-msvideo |
67 { "video/x-msvideo", DEMUXER_TYPE_AVI }, | |
68 // MOV => video/quicktime | |
69 { "video/quicktime", DEMUXER_TYPE_MOV }, | |
70 // ASF | |
71 { "audio/x-ms-wax", DEMUXER_TYPE_ASF }, | |
72 { "audio/x-ms-wma", DEMUXER_TYPE_ASF }, | |
73 { "video/x-ms-asf", DEMUXER_TYPE_ASF }, | |
74 { "video/x-ms-afs", DEMUXER_TYPE_ASF }, | |
75 { "video/x-ms-wvx", DEMUXER_TYPE_ASF }, | |
76 { "video/x-ms-wmv", DEMUXER_TYPE_ASF }, | |
77 { "video/x-ms-wma", DEMUXER_TYPE_ASF }, | |
17235 | 78 { "application/x-mms-framed", DEMUXER_TYPE_ASF }, |
17657
f5f4200785fc
More complete ASF MIME detection, closing bug# 248,
gpoirier
parents:
17566
diff
changeset
|
79 { "application/vnd.ms.wms-hdr.asfv1", DEMUXER_TYPE_ASF }, |
f5f4200785fc
More complete ASF MIME detection, closing bug# 248,
gpoirier
parents:
17566
diff
changeset
|
80 { "application/octet-stream", DEMUXER_TYPE_ASF }, |
4783 | 81 // Playlists |
7393 | 82 { "video/x-ms-wmx", DEMUXER_TYPE_PLAYLIST }, |
4783 | 83 { "audio/x-scpls", DEMUXER_TYPE_PLAYLIST }, |
84 { "audio/x-mpegurl", DEMUXER_TYPE_PLAYLIST }, | |
6032 | 85 { "audio/x-pls", DEMUXER_TYPE_PLAYLIST }, |
86 // Real Media | |
15209
b9c199dd123f
Do not force real demuxer on x-pn-realaudio mimetype
rtognimp
parents:
14720
diff
changeset
|
87 // { "audio/x-pn-realaudio", DEMUXER_TYPE_REAL }, |
8114
ba66375adb6f
Added OGG streaming support, patch from Balatoni Denes <pnis@coder.hu>
bertrand
parents:
8027
diff
changeset
|
88 // OGG Streaming |
12175 | 89 { "application/x-ogg", DEMUXER_TYPE_OGG }, |
90 // NullSoft Streaming Video | |
12477
1550ef7117c4
Add detection of nsa streamed by aol ultravox server
rtognimp
parents:
12390
diff
changeset
|
91 { "video/nsv", DEMUXER_TYPE_NSV}, |
15585 | 92 { "misc/ultravox", DEMUXER_TYPE_NSV}, |
93 { NULL, DEMUXER_TYPE_UNKNOWN}, | |
3042 | 94 }; |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
95 |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
96 |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
97 streaming_ctrl_t * |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
17235
diff
changeset
|
98 streaming_ctrl_new(void) { |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
99 streaming_ctrl_t *streaming_ctrl; |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
100 streaming_ctrl = (streaming_ctrl_t*)malloc(sizeof(streaming_ctrl_t)); |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
101 if( streaming_ctrl==NULL ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
102 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
103 return NULL; |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
104 } |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
105 memset( streaming_ctrl, 0, sizeof(streaming_ctrl_t) ); |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
106 return streaming_ctrl; |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
107 } |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
108 |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
109 void |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
110 streaming_ctrl_free( streaming_ctrl_t *streaming_ctrl ) { |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
111 if( streaming_ctrl==NULL ) return; |
4251
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4236
diff
changeset
|
112 if( streaming_ctrl->url ) url_free( streaming_ctrl->url ); |
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4236
diff
changeset
|
113 if( streaming_ctrl->buffer ) free( streaming_ctrl->buffer ); |
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4236
diff
changeset
|
114 if( streaming_ctrl->data ) free( streaming_ctrl->data ); |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
115 free( streaming_ctrl ); |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
116 } |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
117 |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
118 |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
119 // Converts an address family constant to a string |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
120 |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
121 char *af2String(int af) { |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
122 switch (af) { |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
123 case AF_INET: return "AF_INET"; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
124 |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
125 #ifdef HAVE_AF_INET6 |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
126 case AF_INET6: return "AF_INET6"; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
127 #endif |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
128 default: return "Unknown address family!"; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
129 } |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
130 } |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
131 |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
132 |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
133 |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
134 // Connect to a server using a TCP connection, with specified address family |
7251
cc83ad6af513
Return -2 for fatal error while connecting to a server.
bertrand
parents:
7007
diff
changeset
|
135 // return -2 for fatal error, like unable to resolve name, connection timeout... |
cc83ad6af513
Return -2 for fatal error while connecting to a server.
bertrand
parents:
7007
diff
changeset
|
136 // return -1 is unable to connect to a particular port |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
137 |
833 | 138 int |
10625
620cc649f519
ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
10317
diff
changeset
|
139 connect2Server_with_af(char *host, int port, int af,int verb) { |
833 | 140 int socket_server_fd; |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
141 int err, err_len; |
4825
41d2da3bd082
Make blocking call in libmpdemux interuptable (only with new input,
albeu
parents:
4817
diff
changeset
|
142 int ret,count = 0; |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
143 fd_set set; |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
144 struct timeval tv; |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
145 union { |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
146 struct sockaddr_in four; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
147 #ifdef HAVE_AF_INET6 |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
148 struct sockaddr_in6 six; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
149 #endif |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
150 } server_address; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
151 size_t server_address_size; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
152 void *our_s_addr; // Pointer to sin_addr or sin6_addr |
7953 | 153 struct hostent *hp=NULL; |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
154 char buf[255]; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
155 |
10281 | 156 #ifdef HAVE_WINSOCK2 |
157 u_long val; | |
158 #endif | |
159 | |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
160 socket_server_fd = socket(af, SOCK_STREAM, 0); |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
161 |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
162 |
833 | 163 if( socket_server_fd==-1 ) { |
11227 | 164 // mp_msg(MSGT_NETWORK,MSGL_ERR,"Failed to create %s socket:\n", af2String(af)); |
7251
cc83ad6af513
Return -2 for fatal error while connecting to a server.
bertrand
parents:
7007
diff
changeset
|
165 return -2; |
833 | 166 } |
167 | |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
168 switch (af) { |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
169 case AF_INET: our_s_addr = (void *) &server_address.four.sin_addr; break; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
170 #ifdef HAVE_AF_INET6 |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
171 case AF_INET6: our_s_addr = (void *) &server_address.six.sin6_addr; break; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
172 #endif |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
173 default: |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
174 mp_msg(MSGT_NETWORK,MSGL_ERR, MSGTR_MPDEMUX_NW_UnknownAF, af); |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
175 return -2; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
176 } |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
177 |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
178 |
14642
38572280e8e7
bzero is deprecated patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
14265
diff
changeset
|
179 memset(&server_address, 0, sizeof(server_address)); |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
180 |
10281 | 181 #ifndef HAVE_WINSOCK2 |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
182 #ifdef USE_ATON |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
183 if (inet_aton(host, our_s_addr)!=1) |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
184 #else |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
185 if (inet_pton(af, host, our_s_addr)!=1) |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
186 #endif |
10281 | 187 #else |
188 if ( inet_addr(host)==INADDR_NONE ) | |
189 #endif | |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
190 { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
191 if(verb) mp_msg(MSGT_NETWORK,MSGL_STATUS,MSGTR_MPDEMUX_NW_ResolvingHostForAF, host, af2String(af)); |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
192 |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
193 #ifdef HAVE_GETHOSTBYNAME2 |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
194 hp=(struct hostent*)gethostbyname2( host, af ); |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
195 #else |
3042 | 196 hp=(struct hostent*)gethostbyname( host ); |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
197 #endif |
841 | 198 if( hp==NULL ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
199 if(verb) mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_CantResolv, af2String(af), host); |
7251
cc83ad6af513
Return -2 for fatal error while connecting to a server.
bertrand
parents:
7007
diff
changeset
|
200 return -2; |
833 | 201 } |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
202 |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
203 memcpy( our_s_addr, (void*)hp->h_addr, hp->h_length ); |
833 | 204 } |
10281 | 205 #ifdef HAVE_WINSOCK2 |
206 else { | |
207 unsigned long addr = inet_addr(host); | |
208 memcpy( our_s_addr, (void*)&addr, sizeof(addr) ); | |
209 } | |
210 #endif | |
3042 | 211 |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
212 switch (af) { |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
213 case AF_INET: |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
214 server_address.four.sin_family=af; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
215 server_address.four.sin_port=htons(port); |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
216 server_address_size = sizeof(server_address.four); |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
217 break; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
218 #ifdef HAVE_AF_INET6 |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
219 case AF_INET6: |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
220 server_address.six.sin6_family=af; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
221 server_address.six.sin6_port=htons(port); |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
222 server_address_size = sizeof(server_address.six); |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
223 break; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
224 #endif |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
225 default: |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
226 mp_msg(MSGT_NETWORK,MSGL_ERR, MSGTR_MPDEMUX_NW_UnknownAF, af); |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
227 return -2; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
228 } |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
229 |
10281 | 230 #if defined(USE_ATON) || defined(HAVE_WINSOCK2) |
9900 | 231 strncpy( buf, inet_ntoa( *((struct in_addr*)our_s_addr) ), 255); |
232 #else | |
233 inet_ntop(af, our_s_addr, buf, 255); | |
234 #endif | |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
235 if(verb) mp_msg(MSGT_NETWORK,MSGL_STATUS,MSGTR_MPDEMUX_NW_ConnectingToServer, host, buf , port ); |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
236 |
3042 | 237 // Turn the socket as non blocking so we can timeout on the connection |
10281 | 238 #ifndef HAVE_WINSOCK2 |
3042 | 239 fcntl( socket_server_fd, F_SETFL, fcntl(socket_server_fd, F_GETFL) | O_NONBLOCK ); |
10281 | 240 #else |
241 val = 1; | |
242 ioctlsocket( socket_server_fd, FIONBIO, &val ); | |
243 #endif | |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
244 if( connect( socket_server_fd, (struct sockaddr*)&server_address, server_address_size )==-1 ) { |
10281 | 245 #ifndef HAVE_WINSOCK2 |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
246 if( errno!=EINPROGRESS ) { |
10281 | 247 #else |
248 if( (WSAGetLastError() != WSAEINPROGRESS) && (WSAGetLastError() != WSAEWOULDBLOCK) ) { | |
249 #endif | |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
250 if(verb) mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_CantConnect2Server, af2String(af)); |
10281 | 251 closesocket(socket_server_fd); |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
252 return -1; |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
253 } |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
254 } |
6477 | 255 tv.tv_sec = 0; |
256 tv.tv_usec = 500000; | |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
257 FD_ZERO( &set ); |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
258 FD_SET( socket_server_fd, &set ); |
3042 | 259 // When the connection will be made, we will have a writable fd |
4825
41d2da3bd082
Make blocking call in libmpdemux interuptable (only with new input,
albeu
parents:
4817
diff
changeset
|
260 while((ret = select(socket_server_fd+1, NULL, &set, NULL, &tv)) == 0) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
261 if( ret<0 ) mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_SelectFailed); |
4825
41d2da3bd082
Make blocking call in libmpdemux interuptable (only with new input,
albeu
parents:
4817
diff
changeset
|
262 else if(ret > 0) break; |
7862
013c255225d8
mpdemux.c|h moved to libinput, mpdemux_check_interrupt() -> mp_input_check_interrupt()
arpi
parents:
7513
diff
changeset
|
263 else if(count > 30 || mp_input_check_interrupt(500)) { |
6477 | 264 if(count > 30) |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
265 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_ConnTimeout); |
4825
41d2da3bd082
Make blocking call in libmpdemux interuptable (only with new input,
albeu
parents:
4817
diff
changeset
|
266 else |
5915 | 267 mp_msg(MSGT_NETWORK,MSGL_V,"Connection interuppted by user\n"); |
8824 | 268 return -3; |
4825
41d2da3bd082
Make blocking call in libmpdemux interuptable (only with new input,
albeu
parents:
4817
diff
changeset
|
269 } |
41d2da3bd082
Make blocking call in libmpdemux interuptable (only with new input,
albeu
parents:
4817
diff
changeset
|
270 count++; |
41d2da3bd082
Make blocking call in libmpdemux interuptable (only with new input,
albeu
parents:
4817
diff
changeset
|
271 FD_ZERO( &set ); |
41d2da3bd082
Make blocking call in libmpdemux interuptable (only with new input,
albeu
parents:
4817
diff
changeset
|
272 FD_SET( socket_server_fd, &set ); |
6477 | 273 tv.tv_sec = 0; |
274 tv.tv_usec = 500000; | |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
275 } |
3042 | 276 |
277 // Turn back the socket as blocking | |
10281 | 278 #ifndef HAVE_WINSOCK2 |
3042 | 279 fcntl( socket_server_fd, F_SETFL, fcntl(socket_server_fd, F_GETFL) & ~O_NONBLOCK ); |
10281 | 280 #else |
281 val = 0; | |
282 ioctlsocket( socket_server_fd, FIONBIO, &val ); | |
283 #endif | |
3494
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3453
diff
changeset
|
284 // Check if there were any error |
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3453
diff
changeset
|
285 err_len = sizeof(int); |
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3453
diff
changeset
|
286 ret = getsockopt(socket_server_fd,SOL_SOCKET,SO_ERROR,&err,&err_len); |
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3453
diff
changeset
|
287 if(ret < 0) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
288 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_GetSockOptFailed,strerror(errno)); |
7251
cc83ad6af513
Return -2 for fatal error while connecting to a server.
bertrand
parents:
7007
diff
changeset
|
289 return -2; |
3494
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3453
diff
changeset
|
290 } |
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3453
diff
changeset
|
291 if(err > 0) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
292 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_ConnectError,strerror(err)); |
3494
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3453
diff
changeset
|
293 return -1; |
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3453
diff
changeset
|
294 } |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
295 |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
296 return socket_server_fd; |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
297 } |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
298 |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
299 // Connect to a server using a TCP connection |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
300 // return -2 for fatal error, like unable to resolve name, connection timeout... |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
301 // return -1 is unable to connect to a particular port |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
302 |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
303 |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
304 int |
10625
620cc649f519
ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
10317
diff
changeset
|
305 connect2Server(char *host, int port, int verb) { |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
306 #ifdef HAVE_AF_INET6 |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
307 int r; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
308 int s = -2; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
309 |
10625
620cc649f519
ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
10317
diff
changeset
|
310 r = connect2Server_with_af(host, port, network_prefer_ipv4 ? AF_INET:AF_INET6,verb); |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
311 if (r > -1) return r; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
312 |
10625
620cc649f519
ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
10317
diff
changeset
|
313 s = connect2Server_with_af(host, port, network_prefer_ipv4 ? AF_INET6:AF_INET,verb); |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
314 if (s == -2) return r; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
315 return s; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
316 #else |
10625
620cc649f519
ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
10317
diff
changeset
|
317 return connect2Server_with_af(host, port, AF_INET,verb); |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
318 #endif |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
319 |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
320 |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
321 } |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
322 |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
323 URL_t* |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
324 check4proxies( URL_t *url ) { |
4652 | 325 URL_t *url_out = NULL; |
4251
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4236
diff
changeset
|
326 if( url==NULL ) return NULL; |
4652 | 327 url_out = url_new( url->url ); |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
328 if( !strcasecmp(url->protocol, "http_proxy") ) { |
5915 | 329 mp_msg(MSGT_NETWORK,MSGL_V,"Using HTTP proxy: http://%s:%d\n", url->hostname, url->port ); |
4652 | 330 return url_out; |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
331 } |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
332 // Check if the http_proxy environment variable is set. |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
333 if( !strcasecmp(url->protocol, "http") ) { |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
334 char *proxy; |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
335 proxy = getenv("http_proxy"); |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
336 if( proxy!=NULL ) { |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
337 // We got a proxy, build the URL to use it |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
338 int len; |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
339 char *new_url; |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
340 URL_t *tmp_url; |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
341 URL_t *proxy_url = url_new( proxy ); |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
342 |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
343 if( proxy_url==NULL ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
344 mp_msg(MSGT_NETWORK,MSGL_WARN, |
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
345 MSGTR_MPDEMUX_NW_InvalidProxySettingTryingWithout); |
4652 | 346 return url_out; |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
347 } |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
348 |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
349 #ifdef HAVE_AF_INET6 |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
350 if (network_ipv4_only_proxy && (gethostbyname(url->hostname)==NULL)) { |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
351 mp_msg(MSGT_NETWORK,MSGL_WARN, |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
352 MSGTR_MPDEMUX_NW_CantResolvTryingWithoutProxy); |
16419 | 353 url_free(proxy_url); |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
354 return url_out; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
355 } |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
356 #endif |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
357 |
5915 | 358 mp_msg(MSGT_NETWORK,MSGL_V,"Using HTTP proxy: %s\n", proxy_url->url ); |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
359 len = strlen( proxy_url->hostname ) + strlen( url->url ) + 20; // 20 = http_proxy:// + port |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
360 new_url = malloc( len+1 ); |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
361 if( new_url==NULL ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
362 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
16419 | 363 url_free(proxy_url); |
4652 | 364 return url_out; |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
365 } |
5915 | 366 sprintf(new_url, "http_proxy://%s:%d/%s", proxy_url->hostname, proxy_url->port, url->url ); |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
367 tmp_url = url_new( new_url ); |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
368 if( tmp_url==NULL ) { |
16419 | 369 free( new_url ); |
370 url_free( proxy_url ); | |
4652 | 371 return url_out; |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
372 } |
4652 | 373 url_free( url_out ); |
374 url_out = tmp_url; | |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
375 free( new_url ); |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
376 url_free( proxy_url ); |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
377 } |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
378 } |
4652 | 379 return url_out; |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
380 } |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
381 |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
382 int |
11965 | 383 http_send_request( URL_t *url, off_t pos ) { |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
384 HTTP_header_t *http_hdr; |
4121 | 385 URL_t *server_url; |
11228 | 386 char str[256]; |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
387 int fd; |
4121 | 388 int ret; |
389 int proxy = 0; // Boolean | |
390 | |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
391 http_hdr = http_new_header(); |
4121 | 392 |
4145 | 393 if( !strcasecmp(url->protocol, "http_proxy") ) { |
4121 | 394 proxy = 1; |
395 server_url = url_new( (url->file)+1 ); | |
396 http_set_uri( http_hdr, server_url->url ); | |
397 } else { | |
398 server_url = url; | |
399 http_set_uri( http_hdr, server_url->file ); | |
400 } | |
12638
2ebd553876c8
RFC compliance patch by Eric Lammerts <eric@lammerts.org>
alex
parents:
12610
diff
changeset
|
401 if (server_url->port && server_url->port != 80) |
2ebd553876c8
RFC compliance patch by Eric Lammerts <eric@lammerts.org>
alex
parents:
12610
diff
changeset
|
402 snprintf(str, 256, "Host: %s:%d", server_url->hostname, server_url->port ); |
2ebd553876c8
RFC compliance patch by Eric Lammerts <eric@lammerts.org>
alex
parents:
12610
diff
changeset
|
403 else |
2ebd553876c8
RFC compliance patch by Eric Lammerts <eric@lammerts.org>
alex
parents:
12610
diff
changeset
|
404 snprintf(str, 256, "Host: %s", server_url->hostname ); |
3585 | 405 http_set_field( http_hdr, str); |
11228 | 406 if (network_useragent) |
407 { | |
408 snprintf(str, 256, "User-Agent: %s", network_useragent); | |
409 http_set_field(http_hdr, str); | |
410 } | |
411 else | |
412 http_set_field( http_hdr, "User-Agent: MPlayer/"VERSION); | |
11965 | 413 |
16013 | 414 http_set_field(http_hdr, "Icy-MetaData: 1"); |
415 | |
11965 | 416 if(pos>0) { |
417 // Extend http_send_request with possibility to do partial content retrieval | |
16750
0a31740dd5e6
Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents:
16419
diff
changeset
|
418 snprintf(str, 256, "Range: bytes=%"PRId64"-", (int64_t)pos); |
11965 | 419 http_set_field(http_hdr, str); |
420 } | |
11583
2af52902e7dc
Send HTTP Cookies (reading from mozilla/netscape files) support by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>. Disabled by default.
alex
parents:
11505
diff
changeset
|
421 |
2af52902e7dc
Send HTTP Cookies (reading from mozilla/netscape files) support by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>. Disabled by default.
alex
parents:
11505
diff
changeset
|
422 if (network_cookies_enabled) cookies_set( http_hdr, server_url->hostname, server_url->url ); |
2af52902e7dc
Send HTTP Cookies (reading from mozilla/netscape files) support by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>. Disabled by default.
alex
parents:
11505
diff
changeset
|
423 |
12352 | 424 http_set_field( http_hdr, "Connection: close"); |
6515 | 425 http_add_basic_authentication( http_hdr, url->username, url->password ); |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
426 if( http_build_request( http_hdr )==NULL ) { |
16417 | 427 goto err_out; |
833 | 428 } |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
429 |
4121 | 430 if( proxy ) { |
431 if( url->port==0 ) url->port = 8080; // Default port for the proxy server | |
10625
620cc649f519
ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
10317
diff
changeset
|
432 fd = connect2Server( url->hostname, url->port,1 ); |
4121 | 433 url_free( server_url ); |
17777
13b2332c5154
missing url_free when using proxy and connect fails
reimar
parents:
17657
diff
changeset
|
434 server_url = NULL; |
4121 | 435 } else { |
436 if( server_url->port==0 ) server_url->port = 80; // Default port for the web server | |
10625
620cc649f519
ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
10317
diff
changeset
|
437 fd = connect2Server( server_url->hostname, server_url->port,1 ); |
4121 | 438 } |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
439 if( fd<0 ) { |
16417 | 440 goto err_out; |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
441 } |
5915 | 442 mp_msg(MSGT_NETWORK,MSGL_DBG2,"Request: [%s]\n", http_hdr->buffer ); |
4121 | 443 |
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:
10199
diff
changeset
|
444 ret = send( fd, http_hdr->buffer, http_hdr->buffer_size, 0 ); |
7953 | 445 if( ret!=(int)http_hdr->buffer_size ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
446 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_ErrSendingHTTPRequest); |
16417 | 447 goto err_out; |
4121 | 448 } |
449 | |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
450 http_free( http_hdr ); |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
451 |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
452 return fd; |
16417 | 453 err_out: |
454 http_free(http_hdr); | |
17777
13b2332c5154
missing url_free when using proxy and connect fails
reimar
parents:
17657
diff
changeset
|
455 if (proxy && server_url) |
13b2332c5154
missing url_free when using proxy and connect fails
reimar
parents:
17657
diff
changeset
|
456 url_free(server_url); |
16417 | 457 return -1; |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
458 } |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
459 |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
460 HTTP_header_t * |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
461 http_read_response( int fd ) { |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
462 HTTP_header_t *http_hdr; |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
463 char response[BUFFER_SIZE]; |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
464 int i; |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
465 |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
466 http_hdr = http_new_header(); |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
467 if( http_hdr==NULL ) { |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
468 return NULL; |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
469 } |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
470 |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
471 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:
10199
diff
changeset
|
472 i = recv( fd, response, BUFFER_SIZE, 0 ); |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
473 if( i<0 ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
474 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_ReadFailed); |
3365 | 475 http_free( http_hdr ); |
476 return NULL; | |
477 } | |
478 if( i==0 ) { | |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
479 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_Read0CouldBeEOF); |
3365 | 480 http_free( http_hdr ); |
481 return NULL; | |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
482 } |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
483 http_response_append( http_hdr, response, i ); |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
484 } while( !http_is_header_entire( http_hdr ) ); |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
485 http_response_parse( http_hdr ); |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
486 return http_hdr; |
833 | 487 } |
488 | |
6555 | 489 int |
490 http_authenticate(HTTP_header_t *http_hdr, URL_t *url, int *auth_retry) { | |
491 char *aut; | |
7953 | 492 |
6558
b379b061ce50
Read username/password from the -user -pass command line options.
bertrand
parents:
6555
diff
changeset
|
493 if( *auth_retry==1 ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
494 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_AuthFailed); |
6555 | 495 return -1; |
496 } | |
497 if( *auth_retry>0 ) { | |
498 if( url->username ) { | |
499 free( url->username ); | |
500 url->username = NULL; | |
501 } | |
502 if( url->password ) { | |
503 free( url->password ); | |
504 url->password = NULL; | |
505 } | |
506 } | |
6558
b379b061ce50
Read username/password from the -user -pass command line options.
bertrand
parents:
6555
diff
changeset
|
507 |
6555 | 508 aut = http_get_field(http_hdr, "WWW-Authenticate"); |
509 if( aut!=NULL ) { | |
510 char *aut_space; | |
511 aut_space = strstr(aut, "realm="); | |
512 if( aut_space!=NULL ) aut_space += 6; | |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
513 mp_msg(MSGT_NETWORK,MSGL_INFO,MSGTR_MPDEMUX_NW_AuthRequiredFor, aut_space); |
6555 | 514 } else { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
515 mp_msg(MSGT_NETWORK,MSGL_INFO,MSGTR_MPDEMUX_NW_AuthRequired); |
6555 | 516 } |
7867 | 517 if( network_username ) { |
518 url->username = strdup(network_username); | |
6555 | 519 if( url->username==NULL ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
520 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
6555 | 521 return -1; |
522 } | |
523 } else { | |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
524 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_AuthFailed); |
6555 | 525 return -1; |
526 } | |
7867 | 527 if( network_password ) { |
528 url->password = strdup(network_password); | |
6558
b379b061ce50
Read username/password from the -user -pass command line options.
bertrand
parents:
6555
diff
changeset
|
529 if( url->password==NULL ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
530 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
6558
b379b061ce50
Read username/password from the -user -pass command line options.
bertrand
parents:
6555
diff
changeset
|
531 return -1; |
b379b061ce50
Read username/password from the -user -pass command line options.
bertrand
parents:
6555
diff
changeset
|
532 } |
b379b061ce50
Read username/password from the -user -pass command line options.
bertrand
parents:
6555
diff
changeset
|
533 } else { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
534 mp_msg(MSGT_NETWORK,MSGL_INFO,MSGTR_MPDEMUX_NW_NoPasswdProvidedTryingBlank); |
6558
b379b061ce50
Read username/password from the -user -pass command line options.
bertrand
parents:
6555
diff
changeset
|
535 } |
6555 | 536 (*auth_retry)++; |
537 return 0; | |
538 } | |
539 | |
11965 | 540 int |
541 http_seek( stream_t *stream, off_t pos ) { | |
542 HTTP_header_t *http_hdr = NULL; | |
543 int fd; | |
544 if( stream==NULL ) return 0; | |
545 | |
546 if( stream->fd>0 ) closesocket(stream->fd); // need to reconnect to seek in http-stream | |
547 fd = http_send_request( stream->streaming_ctrl->url, pos ); | |
548 if( fd<0 ) return 0; | |
549 | |
550 http_hdr = http_read_response( fd ); | |
551 | |
552 if( http_hdr==NULL ) return 0; | |
553 | |
554 switch( http_hdr->status_code ) { | |
555 case 200: | |
556 case 206: // OK | |
557 mp_msg(MSGT_NETWORK,MSGL_V,"Content-Type: [%s]\n", http_get_field(http_hdr, "Content-Type") ); | |
558 mp_msg(MSGT_NETWORK,MSGL_V,"Content-Length: [%s]\n", http_get_field(http_hdr, "Content-Length") ); | |
559 if( http_hdr->body_size>0 ) { | |
560 if( streaming_bufferize( stream->streaming_ctrl, http_hdr->body, http_hdr->body_size )<0 ) { | |
561 http_free( http_hdr ); | |
562 return -1; | |
563 } | |
564 } | |
565 break; | |
566 default: | |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
567 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_ErrServerReturned, http_hdr->status_code, http_hdr->reason_phrase ); |
11965 | 568 close( fd ); |
569 fd = -1; | |
570 } | |
571 stream->fd = fd; | |
572 | |
573 if( http_hdr ) { | |
574 http_free( http_hdr ); | |
575 stream->streaming_ctrl->data = NULL; | |
576 } | |
577 | |
578 stream->pos=pos; | |
579 | |
580 return 1; | |
581 } | |
582 | |
583 | |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
584 int |
3042 | 585 streaming_bufferize( streaming_ctrl_t *streaming_ctrl, char *buffer, int size) { |
4251
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4236
diff
changeset
|
586 //printf("streaming_bufferize\n"); |
3042 | 587 streaming_ctrl->buffer = (char*)malloc(size); |
588 if( streaming_ctrl->buffer==NULL ) { | |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
589 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
3042 | 590 return -1; |
591 } | |
592 memcpy( streaming_ctrl->buffer, buffer, size ); | |
593 streaming_ctrl->buffer_size = size; | |
3599 | 594 return size; |
3042 | 595 } |
596 | |
597 int | |
598 nop_streaming_read( int fd, char *buffer, int size, streaming_ctrl_t *stream_ctrl ) { | |
599 int len=0; | |
600 //printf("nop_streaming_read\n"); | |
601 if( stream_ctrl->buffer_size!=0 ) { | |
602 int buffer_len = stream_ctrl->buffer_size-stream_ctrl->buffer_pos; | |
4251
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4236
diff
changeset
|
603 //printf("%d bytes in buffer\n", stream_ctrl->buffer_size); |
3042 | 604 len = (size<buffer_len)?size:buffer_len; |
605 memcpy( buffer, (stream_ctrl->buffer)+(stream_ctrl->buffer_pos), len ); | |
606 stream_ctrl->buffer_pos += len; | |
4251
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4236
diff
changeset
|
607 //printf("buffer_pos = %d\n", stream_ctrl->buffer_pos ); |
3042 | 608 if( stream_ctrl->buffer_pos>=stream_ctrl->buffer_size ) { |
609 free( stream_ctrl->buffer ); | |
610 stream_ctrl->buffer = NULL; | |
611 stream_ctrl->buffer_size = 0; | |
612 stream_ctrl->buffer_pos = 0; | |
4251
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4236
diff
changeset
|
613 //printf("buffer cleaned\n"); |
3042 | 614 } |
4251
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4236
diff
changeset
|
615 //printf("read %d bytes from buffer\n", len ); |
3042 | 616 } |
617 | |
618 if( len<size ) { | |
3365 | 619 int ret; |
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:
10199
diff
changeset
|
620 ret = recv( fd, buffer+len, size-len, 0 ); |
3494
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3453
diff
changeset
|
621 if( ret<0 ) { |
5915 | 622 mp_msg(MSGT_NETWORK,MSGL_ERR,"nop_streaming_read error : %s\n",strerror(errno)); |
3365 | 623 } |
624 len += ret; | |
3042 | 625 //printf("read %d bytes from network\n", len ); |
626 } | |
627 | |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
628 return len; |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
629 } |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
630 |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
631 int |
3042 | 632 nop_streaming_seek( int fd, off_t pos, streaming_ctrl_t *stream_ctrl ) { |
633 return -1; | |
7953 | 634 // To shut up gcc warning |
635 fd++; | |
636 pos++; | |
637 stream_ctrl=NULL; | |
3042 | 638 } |
639 | |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
640 |
15954 | 641 void fixup_network_stream_cache(stream_t *stream) { |
15585 | 642 if(stream->streaming_ctrl->buffering) { |
643 if(stream_cache_size<0) { | |
644 // cache option not set, will use our computed value. | |
645 // buffer in KBytes, *5 because the prefill is 20% of the buffer. | |
646 stream_cache_size = (stream->streaming_ctrl->prebuffer_size/1024)*5; | |
647 if( stream_cache_size<64 ) stream_cache_size = 64; // 16KBytes min buffer | |
648 } | |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
649 mp_msg(MSGT_NETWORK,MSGL_INFO,MSGTR_MPDEMUX_NW_CacheSizeSetTo, stream_cache_size); |
15585 | 650 } |
9922 | 651 } |
652 | |
653 | |
903 | 654 int |
3042 | 655 streaming_stop( stream_t *stream ) { |
656 stream->streaming_ctrl->status = streaming_stopped_e; | |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
657 return 0; |
903 | 658 } |