Mercurial > mplayer.hg
annotate stream/network.c @ 35457:f4991a47d0c8
Add FourCC V264 for H264 in CCTV recordings.
author | cehoyos |
---|---|
date | Sat, 01 Dec 2012 23:45:59 +0000 |
parents | 8f6d3f8ffa61 |
children | 525bcc0a8e16 |
rev | line source |
---|---|
903 | 1 /* |
2 * Network layer for MPlayer | |
30426
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
3 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
4 * Copyright (C) 2001 Bertrand Baudet <bertrand_baudet@yahoo.com> |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
5 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
6 * This file is part of MPlayer. |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
7 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
8 * 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:
29263
diff
changeset
|
9 * 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:
29263
diff
changeset
|
10 * 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:
29263
diff
changeset
|
11 * (at your option) any later version. |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
12 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
13 * 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:
29263
diff
changeset
|
14 * 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:
29263
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
16 * GNU General Public License for more details. |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
17 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
18 * 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:
29263
diff
changeset
|
19 * 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:
29263
diff
changeset
|
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
903 | 21 */ |
22 | |
1430 | 23 #include <stdio.h> |
24 #include <stdlib.h> | |
25 #include <string.h> | |
833 | 26 #include <unistd.h> |
1430 | 27 |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
28 #include <errno.h> |
903 | 29 #include <ctype.h> |
833 | 30 |
2555
66837325b929
config.h cleanup, few things added to steram/demuxer headers
arpi
parents:
2489
diff
changeset
|
31 #include "config.h" |
66837325b929
config.h cleanup, few things added to steram/demuxer headers
arpi
parents:
2489
diff
changeset
|
32 |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
33 #include "mp_msg.h" |
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
34 #include "help_mp.h" |
27472
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
35 |
28402 | 36 #if HAVE_WINSOCK2_H |
27472
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
37 #include <winsock2.h> |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
38 #include <ws2tcpip.h> |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
39 #endif |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
40 |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
41 #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
|
42 #include "libmpdemux/demuxer.h" |
17012 | 43 #include "m_config.h" |
31511
13ca93203358
Factorize MPlayer/MEncoder version string handling.
diego
parents:
31500
diff
changeset
|
44 #include "mpcommon.h" |
841 | 45 #include "network.h" |
19335
2a9d669e5ff6
isolated tcp socket code from network.c to a dedicated file
ben
parents:
19331
diff
changeset
|
46 #include "tcp.h" |
903 | 47 #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
|
48 #include "cookies.h" |
903 | 49 #include "url.h" |
841 | 50 |
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 /* 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
|
52 -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
|
53 |
7867 | 54 char *network_username=NULL; |
55 char *network_password=NULL; | |
56 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
|
57 int network_cookies_enabled = 0; |
11228 | 58 char *network_useragent=NULL; |
31222
d739cbeb0e38
Add a referrer option to set the HTTP Referer field.
reimar
parents:
30909
diff
changeset
|
59 char *network_referrer=NULL; |
32995 | 60 char **network_http_header_fields=NULL; |
6558
b379b061ce50
Read username/password from the -user -pass command line options.
bertrand
parents:
6555
diff
changeset
|
61 |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
62 /* IPv6 options */ |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
63 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
|
64 |
6558
b379b061ce50
Read username/password from the -user -pass command line options.
bertrand
parents:
6555
diff
changeset
|
65 |
25246 | 66 const mime_struct_t mime_type_table[] = { |
32142
4614728cab25
build system: Merge all FFmpeg library checks into a single FFmpeg check.
diego
parents:
32051
diff
changeset
|
67 #ifdef CONFIG_FFMPEG |
30475
9f36eccc490a
Prefer libavformat over our own mov demuxer also for video/quicktime
reimar
parents:
30426
diff
changeset
|
68 // Flash Video |
9f36eccc490a
Prefer libavformat over our own mov demuxer also for video/quicktime
reimar
parents:
30426
diff
changeset
|
69 { "video/x-flv", DEMUXER_TYPE_LAVF_PREFERRED}, |
30621
300fd6ee0f8b
Fix mov reference files: for video/quicktime mime do not force a demuxer
reimar
parents:
30557
diff
changeset
|
70 // do not force any demuxer in this case! |
300fd6ee0f8b
Fix mov reference files: for video/quicktime mime do not force a demuxer
reimar
parents:
30557
diff
changeset
|
71 // we want the lavf demuxer to be tried first (happens automatically anyway), |
300fd6ee0f8b
Fix mov reference files: for video/quicktime mime do not force a demuxer
reimar
parents:
30557
diff
changeset
|
72 // but for mov reference files to work we must also try |
300fd6ee0f8b
Fix mov reference files: for video/quicktime mime do not force a demuxer
reimar
parents:
30557
diff
changeset
|
73 // the native demuxer if lavf fails. |
300fd6ee0f8b
Fix mov reference files: for video/quicktime mime do not force a demuxer
reimar
parents:
30557
diff
changeset
|
74 { "video/quicktime", 0 }, |
30475
9f36eccc490a
Prefer libavformat over our own mov demuxer also for video/quicktime
reimar
parents:
30426
diff
changeset
|
75 #endif |
3042 | 76 // 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
|
77 { "audio/mpeg", DEMUXER_TYPE_AUDIO }, |
3042 | 78 // 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
|
79 { "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
|
80 { "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
|
81 { "video/x-mpeg2", DEMUXER_TYPE_UNKNOWN }, |
3042 | 82 // AVI ??? => video/x-msvideo |
83 { "video/x-msvideo", DEMUXER_TYPE_AVI }, | |
84 // MOV => video/quicktime | |
85 { "video/quicktime", DEMUXER_TYPE_MOV }, | |
86 // ASF | |
87 { "audio/x-ms-wax", DEMUXER_TYPE_ASF }, | |
88 { "audio/x-ms-wma", DEMUXER_TYPE_ASF }, | |
89 { "video/x-ms-asf", DEMUXER_TYPE_ASF }, | |
90 { "video/x-ms-afs", DEMUXER_TYPE_ASF }, | |
91 { "video/x-ms-wmv", DEMUXER_TYPE_ASF }, | |
92 { "video/x-ms-wma", DEMUXER_TYPE_ASF }, | |
17235 | 93 { "application/x-mms-framed", DEMUXER_TYPE_ASF }, |
17657
f5f4200785fc
More complete ASF MIME detection, closing bug# 248,
gpoirier
parents:
17566
diff
changeset
|
94 { "application/vnd.ms.wms-hdr.asfv1", DEMUXER_TYPE_ASF }, |
19841
e7f56cc4505e
Change demuxer for "application/octet-stream" http streams from
eugeni
parents:
19335
diff
changeset
|
95 { "application/octet-stream", DEMUXER_TYPE_UNKNOWN }, |
4783 | 96 // Playlists |
7393 | 97 { "video/x-ms-wmx", DEMUXER_TYPE_PLAYLIST }, |
23675
c056ed2819e8
wvx files (mimetype video/x-ms-wvx) are asx playlists. Fix bugzilla #750
rtogni
parents:
22142
diff
changeset
|
98 { "video/x-ms-wvx", DEMUXER_TYPE_PLAYLIST }, |
4783 | 99 { "audio/x-scpls", DEMUXER_TYPE_PLAYLIST }, |
100 { "audio/x-mpegurl", DEMUXER_TYPE_PLAYLIST }, | |
6032 | 101 { "audio/x-pls", DEMUXER_TYPE_PLAYLIST }, |
102 // Real Media | |
15209
b9c199dd123f
Do not force real demuxer on x-pn-realaudio mimetype
rtognimp
parents:
14720
diff
changeset
|
103 // { "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
|
104 // OGG Streaming |
34846 | 105 { "application/ogg", DEMUXER_TYPE_OGG }, |
12175 | 106 { "application/x-ogg", DEMUXER_TYPE_OGG }, |
107 // NullSoft Streaming Video | |
12477
1550ef7117c4
Add detection of nsa streamed by aol ultravox server
rtognimp
parents:
12390
diff
changeset
|
108 { "video/nsv", DEMUXER_TYPE_NSV}, |
15585 | 109 { "misc/ultravox", DEMUXER_TYPE_NSV}, |
110 { NULL, DEMUXER_TYPE_UNKNOWN}, | |
3042 | 111 }; |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
112 |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
113 |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
114 streaming_ctrl_t * |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
17235
diff
changeset
|
115 streaming_ctrl_new(void) { |
32560 | 116 streaming_ctrl_t *streaming_ctrl = calloc(1, sizeof(*streaming_ctrl)); |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
117 if( streaming_ctrl==NULL ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
118 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
119 return NULL; |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
120 } |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
121 return streaming_ctrl; |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
122 } |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
123 |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
124 void |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
125 streaming_ctrl_free( streaming_ctrl_t *streaming_ctrl ) { |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
126 if( streaming_ctrl==NULL ) return; |
4251
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4236
diff
changeset
|
127 if( streaming_ctrl->url ) url_free( streaming_ctrl->url ); |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32422
diff
changeset
|
128 free(streaming_ctrl->buffer); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32422
diff
changeset
|
129 free(streaming_ctrl->data); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32422
diff
changeset
|
130 free(streaming_ctrl); |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
131 } |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
132 |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
133 URL_t* |
35296
4dc2b1261d29
check4proxies does not modify input URL, so mark it const.
reimar
parents:
34846
diff
changeset
|
134 check4proxies( const URL_t *url ) { |
4652 | 135 URL_t *url_out = NULL; |
4251
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4236
diff
changeset
|
136 if( url==NULL ) return NULL; |
4652 | 137 url_out = url_new( url->url ); |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
138 if( !strcasecmp(url->protocol, "http_proxy") ) { |
5915 | 139 mp_msg(MSGT_NETWORK,MSGL_V,"Using HTTP proxy: http://%s:%d\n", url->hostname, url->port ); |
4652 | 140 return url_out; |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
141 } |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
142 // Check if the http_proxy environment variable is set. |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
143 if( !strcasecmp(url->protocol, "http") ) { |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
144 char *proxy; |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
145 proxy = getenv("http_proxy"); |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
146 if( proxy!=NULL ) { |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
147 // We got a proxy, build the URL to use it |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
148 char *new_url; |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
149 URL_t *tmp_url; |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
150 URL_t *proxy_url = url_new( proxy ); |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
151 |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
152 if( proxy_url==NULL ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
153 mp_msg(MSGT_NETWORK,MSGL_WARN, |
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
154 MSGTR_MPDEMUX_NW_InvalidProxySettingTryingWithout); |
4652 | 155 return url_out; |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
156 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
157 |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
158 #ifdef HAVE_AF_INET6 |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
159 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
|
160 mp_msg(MSGT_NETWORK,MSGL_WARN, |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
161 MSGTR_MPDEMUX_NW_CantResolvTryingWithoutProxy); |
16419 | 162 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
|
163 return url_out; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
164 } |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
165 #endif |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
166 |
5915 | 167 mp_msg(MSGT_NETWORK,MSGL_V,"Using HTTP proxy: %s\n", proxy_url->url ); |
32884
0d95f044c589
Use mp_asprintf in make_noauth_url and make_http_proxy_url.
cboesch
parents:
32586
diff
changeset
|
168 new_url = get_http_proxy_url(proxy_url, url->url); |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
169 if( new_url==NULL ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
170 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
16419 | 171 url_free(proxy_url); |
4652 | 172 return url_out; |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
173 } |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
174 tmp_url = url_new( new_url ); |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
175 if( tmp_url==NULL ) { |
16419 | 176 free( new_url ); |
177 url_free( proxy_url ); | |
4652 | 178 return url_out; |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
179 } |
4652 | 180 url_free( url_out ); |
181 url_out = tmp_url; | |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
182 free( new_url ); |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
183 url_free( proxy_url ); |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
184 } |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
185 } |
4652 | 186 return url_out; |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
187 } |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
188 |
35301
8f6d3f8ffa61
Add url_new_with_proxy function to reduce code duplication and memleaks.
reimar
parents:
35296
diff
changeset
|
189 URL_t *url_new_with_proxy(const char *urlstr) |
8f6d3f8ffa61
Add url_new_with_proxy function to reduce code duplication and memleaks.
reimar
parents:
35296
diff
changeset
|
190 { |
8f6d3f8ffa61
Add url_new_with_proxy function to reduce code duplication and memleaks.
reimar
parents:
35296
diff
changeset
|
191 URL_t *url = url_new(urlstr); |
8f6d3f8ffa61
Add url_new_with_proxy function to reduce code duplication and memleaks.
reimar
parents:
35296
diff
changeset
|
192 URL_t *url_with_proxy = check4proxies(url); |
8f6d3f8ffa61
Add url_new_with_proxy function to reduce code duplication and memleaks.
reimar
parents:
35296
diff
changeset
|
193 url_free(url); |
8f6d3f8ffa61
Add url_new_with_proxy function to reduce code duplication and memleaks.
reimar
parents:
35296
diff
changeset
|
194 return url_with_proxy; |
8f6d3f8ffa61
Add url_new_with_proxy function to reduce code duplication and memleaks.
reimar
parents:
35296
diff
changeset
|
195 } |
8f6d3f8ffa61
Add url_new_with_proxy function to reduce code duplication and memleaks.
reimar
parents:
35296
diff
changeset
|
196 |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
197 int |
11965 | 198 http_send_request( URL_t *url, off_t pos ) { |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
199 HTTP_header_t *http_hdr; |
4121 | 200 URL_t *server_url; |
11228 | 201 char str[256]; |
21535 | 202 int fd = -1; |
4121 | 203 int ret; |
204 int proxy = 0; // Boolean | |
205 | |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
206 http_hdr = http_new_header(); |
4121 | 207 |
4145 | 208 if( !strcasecmp(url->protocol, "http_proxy") ) { |
4121 | 209 proxy = 1; |
210 server_url = url_new( (url->file)+1 ); | |
32422
01115062cb22
Fix possible crash for invalid http_proxy URLs like just
reimar
parents:
32142
diff
changeset
|
211 if (!server_url) { |
01115062cb22
Fix possible crash for invalid http_proxy URLs like just
reimar
parents:
32142
diff
changeset
|
212 mp_msg(MSGT_NETWORK, MSGL_ERR, "Invalid URL '%s' to proxify\n", url->file+1); |
01115062cb22
Fix possible crash for invalid http_proxy URLs like just
reimar
parents:
32142
diff
changeset
|
213 goto err_out; |
01115062cb22
Fix possible crash for invalid http_proxy URLs like just
reimar
parents:
32142
diff
changeset
|
214 } |
32553
c44141d4e443
Do not keep authentication in URL on connection through a proxy
cboesch
parents:
32547
diff
changeset
|
215 http_set_uri( http_hdr, server_url->noauth_url ); |
4121 | 216 } else { |
217 server_url = url; | |
218 http_set_uri( http_hdr, server_url->file ); | |
219 } | |
12638
2ebd553876c8
RFC compliance patch by Eric Lammerts <eric@lammerts.org>
alex
parents:
12610
diff
changeset
|
220 if (server_url->port && server_url->port != 80) |
32516 | 221 snprintf(str, sizeof(str), "Host: %s:%d", server_url->hostname, server_url->port ); |
12638
2ebd553876c8
RFC compliance patch by Eric Lammerts <eric@lammerts.org>
alex
parents:
12610
diff
changeset
|
222 else |
32516 | 223 snprintf(str, sizeof(str), "Host: %s", server_url->hostname ); |
3585 | 224 http_set_field( http_hdr, str); |
11228 | 225 if (network_useragent) |
32516 | 226 snprintf(str, sizeof(str), "User-Agent: %s", network_useragent); |
11228 | 227 else |
32516 | 228 snprintf(str, sizeof(str), "User-Agent: %s", mplayer_version); |
31511
13ca93203358
Factorize MPlayer/MEncoder version string handling.
diego
parents:
31500
diff
changeset
|
229 http_set_field(http_hdr, str); |
11965 | 230 |
31222
d739cbeb0e38
Add a referrer option to set the HTTP Referer field.
reimar
parents:
30909
diff
changeset
|
231 if (network_referrer) { |
d739cbeb0e38
Add a referrer option to set the HTTP Referer field.
reimar
parents:
30909
diff
changeset
|
232 char *referrer = NULL; |
d739cbeb0e38
Add a referrer option to set the HTTP Referer field.
reimar
parents:
30909
diff
changeset
|
233 size_t len = strlen(network_referrer) + 10; |
d739cbeb0e38
Add a referrer option to set the HTTP Referer field.
reimar
parents:
30909
diff
changeset
|
234 |
d739cbeb0e38
Add a referrer option to set the HTTP Referer field.
reimar
parents:
30909
diff
changeset
|
235 // Check len to ensure we don't do something really bad in case of an overflow |
d739cbeb0e38
Add a referrer option to set the HTTP Referer field.
reimar
parents:
30909
diff
changeset
|
236 if (len > 10) |
d739cbeb0e38
Add a referrer option to set the HTTP Referer field.
reimar
parents:
30909
diff
changeset
|
237 referrer = malloc(len); |
d739cbeb0e38
Add a referrer option to set the HTTP Referer field.
reimar
parents:
30909
diff
changeset
|
238 |
d739cbeb0e38
Add a referrer option to set the HTTP Referer field.
reimar
parents:
30909
diff
changeset
|
239 if (referrer == NULL) { |
d739cbeb0e38
Add a referrer option to set the HTTP Referer field.
reimar
parents:
30909
diff
changeset
|
240 mp_msg(MSGT_NETWORK, MSGL_FATAL, MSGTR_MemAllocFailed); |
d739cbeb0e38
Add a referrer option to set the HTTP Referer field.
reimar
parents:
30909
diff
changeset
|
241 } else { |
d739cbeb0e38
Add a referrer option to set the HTTP Referer field.
reimar
parents:
30909
diff
changeset
|
242 snprintf(referrer, len, "Referer: %s", network_referrer); |
d739cbeb0e38
Add a referrer option to set the HTTP Referer field.
reimar
parents:
30909
diff
changeset
|
243 http_set_field(http_hdr, referrer); |
d739cbeb0e38
Add a referrer option to set the HTTP Referer field.
reimar
parents:
30909
diff
changeset
|
244 free(referrer); |
d739cbeb0e38
Add a referrer option to set the HTTP Referer field.
reimar
parents:
30909
diff
changeset
|
245 } |
d739cbeb0e38
Add a referrer option to set the HTTP Referer field.
reimar
parents:
30909
diff
changeset
|
246 } |
d739cbeb0e38
Add a referrer option to set the HTTP Referer field.
reimar
parents:
30909
diff
changeset
|
247 |
27847
28deb37052cd
Add a noicyx:// protocol to allow easier testing for misconfigured servers.
reimar
parents:
27473
diff
changeset
|
248 if( strcasecmp(url->protocol, "noicyx") ) |
27848 | 249 http_set_field(http_hdr, "Icy-MetaData: 1"); |
16013 | 250 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
251 if(pos>0) { |
11965 | 252 // Extend http_send_request with possibility to do partial content retrieval |
32516 | 253 snprintf(str, sizeof(str), "Range: bytes=%"PRId64"-", (int64_t)pos); |
11965 | 254 http_set_field(http_hdr, str); |
255 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
256 |
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
|
257 if (network_cookies_enabled) cookies_set( http_hdr, server_url->hostname, server_url->url ); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
258 |
32995 | 259 if (network_http_header_fields) { |
260 int i=0; | |
261 while (network_http_header_fields[i]) | |
262 http_set_field(http_hdr, network_http_header_fields[i++]); | |
263 } | |
264 | |
12352 | 265 http_set_field( http_hdr, "Connection: close"); |
32547
6a629e6fdb09
Add Proxy-Authorization header to authenticate on proxies
cboesch
parents:
32546
diff
changeset
|
266 if (proxy) |
6a629e6fdb09
Add Proxy-Authorization header to authenticate on proxies
cboesch
parents:
32546
diff
changeset
|
267 http_add_basic_proxy_authentication(http_hdr, url->username, url->password); |
32546
e21aa887e9df
"Authentication" header is for the destination server URL, even through a proxy
cboesch
parents:
32516
diff
changeset
|
268 http_add_basic_authentication(http_hdr, server_url->username, server_url->password); |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
269 if( http_build_request( http_hdr )==NULL ) { |
16417 | 270 goto err_out; |
833 | 271 } |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
272 |
4121 | 273 if( proxy ) { |
274 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
|
275 fd = connect2Server( url->hostname, url->port,1 ); |
4121 | 276 url_free( server_url ); |
17777
13b2332c5154
missing url_free when using proxy and connect fails
reimar
parents:
17657
diff
changeset
|
277 server_url = NULL; |
4121 | 278 } else { |
279 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
|
280 fd = connect2Server( server_url->hostname, server_url->port,1 ); |
4121 | 281 } |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
282 if( fd<0 ) { |
16417 | 283 goto err_out; |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
284 } |
5915 | 285 mp_msg(MSGT_NETWORK,MSGL_DBG2,"Request: [%s]\n", http_hdr->buffer ); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
286 |
31500 | 287 ret = send( fd, http_hdr->buffer, http_hdr->buffer_size, DEFAULT_SEND_FLAGS ); |
7953 | 288 if( ret!=(int)http_hdr->buffer_size ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
289 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_ErrSendingHTTPRequest); |
16417 | 290 goto err_out; |
4121 | 291 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
292 |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
293 http_free( http_hdr ); |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
294 |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
295 return fd; |
16417 | 296 err_out: |
21535 | 297 if (fd > 0) closesocket(fd); |
16417 | 298 http_free(http_hdr); |
17777
13b2332c5154
missing url_free when using proxy and connect fails
reimar
parents:
17657
diff
changeset
|
299 if (proxy && server_url) |
13b2332c5154
missing url_free when using proxy and connect fails
reimar
parents:
17657
diff
changeset
|
300 url_free(server_url); |
16417 | 301 return -1; |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
302 } |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
303 |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
304 HTTP_header_t * |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
305 http_read_response( int fd ) { |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
306 HTTP_header_t *http_hdr; |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
307 char response[BUFFER_SIZE]; |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
308 int i; |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
309 |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
310 http_hdr = http_new_header(); |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
311 if( http_hdr==NULL ) { |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
312 return NULL; |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
313 } |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
314 |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
315 do { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
316 i = recv( fd, response, BUFFER_SIZE, 0 ); |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
317 if( i<0 ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
318 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_ReadFailed); |
3365 | 319 http_free( http_hdr ); |
320 return NULL; | |
321 } | |
322 if( i==0 ) { | |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
323 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_Read0CouldBeEOF); |
3365 | 324 http_free( http_hdr ); |
325 return NULL; | |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
326 } |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
327 http_response_append( http_hdr, response, i ); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
328 } while( !http_is_header_entire( http_hdr ) ); |
30909
0d0f53c47bd8
Make http_read_response fail if parsing the response failed.
reimar
parents:
30723
diff
changeset
|
329 if (http_response_parse( http_hdr ) < 0) { |
0d0f53c47bd8
Make http_read_response fail if parsing the response failed.
reimar
parents:
30723
diff
changeset
|
330 http_free( http_hdr ); |
0d0f53c47bd8
Make http_read_response fail if parsing the response failed.
reimar
parents:
30723
diff
changeset
|
331 return NULL; |
0d0f53c47bd8
Make http_read_response fail if parsing the response failed.
reimar
parents:
30723
diff
changeset
|
332 } |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
333 return http_hdr; |
833 | 334 } |
335 | |
6555 | 336 int |
337 http_authenticate(HTTP_header_t *http_hdr, URL_t *url, int *auth_retry) { | |
338 char *aut; | |
7953 | 339 |
6558
b379b061ce50
Read username/password from the -user -pass command line options.
bertrand
parents:
6555
diff
changeset
|
340 if( *auth_retry==1 ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
341 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_AuthFailed); |
6555 | 342 return -1; |
343 } | |
344 if( *auth_retry>0 ) { | |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32422
diff
changeset
|
345 free(url->username); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32422
diff
changeset
|
346 url->username = NULL; |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32422
diff
changeset
|
347 free(url->password); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32422
diff
changeset
|
348 url->password = NULL; |
6555 | 349 } |
6558
b379b061ce50
Read username/password from the -user -pass command line options.
bertrand
parents:
6555
diff
changeset
|
350 |
6555 | 351 aut = http_get_field(http_hdr, "WWW-Authenticate"); |
352 if( aut!=NULL ) { | |
353 char *aut_space; | |
354 aut_space = strstr(aut, "realm="); | |
355 if( aut_space!=NULL ) aut_space += 6; | |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
356 mp_msg(MSGT_NETWORK,MSGL_INFO,MSGTR_MPDEMUX_NW_AuthRequiredFor, aut_space); |
6555 | 357 } else { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
358 mp_msg(MSGT_NETWORK,MSGL_INFO,MSGTR_MPDEMUX_NW_AuthRequired); |
6555 | 359 } |
7867 | 360 if( network_username ) { |
361 url->username = strdup(network_username); | |
6555 | 362 if( url->username==NULL ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
363 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
6555 | 364 return -1; |
365 } | |
366 } else { | |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
367 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_AuthFailed); |
6555 | 368 return -1; |
369 } | |
7867 | 370 if( network_password ) { |
371 url->password = strdup(network_password); | |
6558
b379b061ce50
Read username/password from the -user -pass command line options.
bertrand
parents:
6555
diff
changeset
|
372 if( url->password==NULL ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
373 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
|
374 return -1; |
b379b061ce50
Read username/password from the -user -pass command line options.
bertrand
parents:
6555
diff
changeset
|
375 } |
b379b061ce50
Read username/password from the -user -pass command line options.
bertrand
parents:
6555
diff
changeset
|
376 } else { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
377 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
|
378 } |
6555 | 379 (*auth_retry)++; |
380 return 0; | |
381 } | |
382 | |
11965 | 383 int |
384 http_seek( stream_t *stream, off_t pos ) { | |
385 HTTP_header_t *http_hdr = NULL; | |
386 int fd; | |
387 if( stream==NULL ) return 0; | |
388 | |
389 if( stream->fd>0 ) closesocket(stream->fd); // need to reconnect to seek in http-stream | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
390 fd = http_send_request( stream->streaming_ctrl->url, pos ); |
11965 | 391 if( fd<0 ) return 0; |
392 | |
393 http_hdr = http_read_response( fd ); | |
394 | |
395 if( http_hdr==NULL ) return 0; | |
396 | |
30628
5fd3ea86cf0d
Print response headers as debugging output also for HTTP seeks.
reimar
parents:
30627
diff
changeset
|
397 if( mp_msg_test(MSGT_NETWORK,MSGL_V) ) |
5fd3ea86cf0d
Print response headers as debugging output also for HTTP seeks.
reimar
parents:
30627
diff
changeset
|
398 http_debug_hdr( http_hdr ); |
5fd3ea86cf0d
Print response headers as debugging output also for HTTP seeks.
reimar
parents:
30627
diff
changeset
|
399 |
11965 | 400 switch( http_hdr->status_code ) { |
401 case 200: | |
402 case 206: // OK | |
403 mp_msg(MSGT_NETWORK,MSGL_V,"Content-Type: [%s]\n", http_get_field(http_hdr, "Content-Type") ); | |
404 mp_msg(MSGT_NETWORK,MSGL_V,"Content-Length: [%s]\n", http_get_field(http_hdr, "Content-Length") ); | |
405 if( http_hdr->body_size>0 ) { | |
406 if( streaming_bufferize( stream->streaming_ctrl, http_hdr->body, http_hdr->body_size )<0 ) { | |
407 http_free( http_hdr ); | |
408 return -1; | |
409 } | |
410 } | |
411 break; | |
412 default: | |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
413 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_ErrServerReturned, http_hdr->status_code, http_hdr->reason_phrase ); |
30627 | 414 closesocket( fd ); |
11965 | 415 fd = -1; |
416 } | |
417 stream->fd = fd; | |
418 | |
419 if( http_hdr ) { | |
420 http_free( http_hdr ); | |
421 stream->streaming_ctrl->data = NULL; | |
422 } | |
423 | |
424 stream->pos=pos; | |
425 | |
426 return 1; | |
427 } | |
428 | |
429 | |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
430 int |
3042 | 431 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
|
432 //printf("streaming_bufferize\n"); |
19062
83c3afeab35d
drops casts from void * on malloc/calloc from libmpdemux code
reynaldo
parents:
18466
diff
changeset
|
433 streaming_ctrl->buffer = malloc(size); |
3042 | 434 if( streaming_ctrl->buffer==NULL ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
435 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
3042 | 436 return -1; |
437 } | |
438 memcpy( streaming_ctrl->buffer, buffer, size ); | |
439 streaming_ctrl->buffer_size = size; | |
3599 | 440 return size; |
3042 | 441 } |
442 | |
443 int | |
444 nop_streaming_read( int fd, char *buffer, int size, streaming_ctrl_t *stream_ctrl ) { | |
445 int len=0; | |
446 //printf("nop_streaming_read\n"); | |
447 if( stream_ctrl->buffer_size!=0 ) { | |
448 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
|
449 //printf("%d bytes in buffer\n", stream_ctrl->buffer_size); |
3042 | 450 len = (size<buffer_len)?size:buffer_len; |
451 memcpy( buffer, (stream_ctrl->buffer)+(stream_ctrl->buffer_pos), len ); | |
452 stream_ctrl->buffer_pos += len; | |
4251
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4236
diff
changeset
|
453 //printf("buffer_pos = %d\n", stream_ctrl->buffer_pos ); |
3042 | 454 if( stream_ctrl->buffer_pos>=stream_ctrl->buffer_size ) { |
455 free( stream_ctrl->buffer ); | |
456 stream_ctrl->buffer = NULL; | |
457 stream_ctrl->buffer_size = 0; | |
458 stream_ctrl->buffer_pos = 0; | |
4251
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4236
diff
changeset
|
459 //printf("buffer cleaned\n"); |
3042 | 460 } |
4251
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4236
diff
changeset
|
461 //printf("read %d bytes from buffer\n", len ); |
3042 | 462 } |
463 | |
464 if( len<size ) { | |
3365 | 465 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
|
466 ret = recv( fd, buffer+len, size-len, 0 ); |
3494
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3453
diff
changeset
|
467 if( ret<0 ) { |
5915 | 468 mp_msg(MSGT_NETWORK,MSGL_ERR,"nop_streaming_read error : %s\n",strerror(errno)); |
33719
1a7ac6b2d447
Ensure we do not add strange values to amount of buffered bytes
reimar
parents:
33718
diff
changeset
|
469 ret = 0; |
33718
b4c4ee25269f
Signal EOF vs. error also via streaming control API (not yet evaluated).
reimar
parents:
32995
diff
changeset
|
470 } else if (ret == 0) |
b4c4ee25269f
Signal EOF vs. error also via streaming control API (not yet evaluated).
reimar
parents:
32995
diff
changeset
|
471 stream_ctrl->status = streaming_stopped_e; |
3365 | 472 len += ret; |
3042 | 473 //printf("read %d bytes from network\n", len ); |
474 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
475 |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
476 return len; |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
477 } |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
478 |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
479 int |
3042 | 480 nop_streaming_seek( int fd, off_t pos, streaming_ctrl_t *stream_ctrl ) { |
481 return -1; | |
482 } | |
483 | |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
484 |
15954 | 485 void fixup_network_stream_cache(stream_t *stream) { |
15585 | 486 if(stream->streaming_ctrl->buffering) { |
487 if(stream_cache_size<0) { | |
488 // cache option not set, will use our computed value. | |
489 // buffer in KBytes, *5 because the prefill is 20% of the buffer. | |
490 stream_cache_size = (stream->streaming_ctrl->prebuffer_size/1024)*5; | |
491 if( stream_cache_size<64 ) stream_cache_size = 64; // 16KBytes min buffer | |
492 } | |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
493 mp_msg(MSGT_NETWORK,MSGL_INFO,MSGTR_MPDEMUX_NW_CacheSizeSetTo, stream_cache_size); |
15585 | 494 } |
9922 | 495 } |
496 |