Mercurial > mplayer.hg
annotate stream/stream_netstream.c @ 22187:88b36fd17976
Precent overflow of this->m_sVhdr->bmiHeader buffer, may have been
exploitable.
author | rtogni |
---|---|
date | Sun, 11 Feb 2007 17:57:02 +0000 |
parents | cea0eb833758 |
children | d261f5109660 |
rev | line source |
---|---|
9850
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
1 /* |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
2 * stream_netstream.c |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
3 * |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
4 * Copyright (C) Alban Bedel - 04/2003 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
5 * |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
6 * This file is part of MPlayer, a free movie player. |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
7 * |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
8 * MPlayer is free software; you can redistribute it and/or modify |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
10 * the Free Software Foundation; either version 2, or (at your option) |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
11 * any later version. |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
12 * |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
13 * MPlayer is distributed in the hope that it will be useful, |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
16 * GNU General Public License for more details. |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
17 * |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
21977
cea0eb833758
Fix FSF address and otherwise broken license headers.
diego
parents:
21507
diff
changeset
|
19 * along with MPlayer; if not, write to the Free Software |
cea0eb833758
Fix FSF address and otherwise broken license headers.
diego
parents:
21507
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
9850
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
21 */ |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
22 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
23 /* |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
24 * Net stream allow you to access MPlayer stream accross a tcp |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
25 * connection. |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
26 * Note that at least mf and tv use a dummy stream (they are |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
27 * implemented at the demuxer level) so you won't be able to |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
28 * access those :(( but dvd, vcd and so on should work perfectly |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
29 * (if you have the bandwidth ;) |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
30 * A simple server is in TOOLS/netstream. |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
31 * |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
32 */ |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
33 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
34 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
35 #include "config.h" |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
36 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
37 #include <sys/types.h> |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
38 #include <sys/stat.h> |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
39 #include <fcntl.h> |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
40 #include <unistd.h> |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
41 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
42 #include <stdlib.h> |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
43 #include <stdio.h> |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
44 #include <inttypes.h> |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
45 #include <errno.h> |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
46 |
10281 | 47 #ifndef HAVE_WINSOCK2 |
48 #define closesocket close | |
9850
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
49 #include <sys/socket.h> |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
50 #include <netinet/in.h> |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
51 #include <arpa/inet.h> |
10281 | 52 #else |
53 #include <winsock2.h> | |
54 #endif | |
9850
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
55 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
56 #include "mp_msg.h" |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
57 #include "stream.h" |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
58 #include "help_mp.h" |
17012 | 59 #include "m_option.h" |
60 #include "m_struct.h" | |
21372 | 61 #include "libavutil/common.h" |
21507
fa99b3d31d13
Hack around libavutil/bswap.h compilation problems due to always_inline undefined.
reimar
parents:
21372
diff
changeset
|
62 #include "mpbswap.h" |
9850
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
63 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
64 #include "netstream.h" |
19335
2a9d669e5ff6
isolated tcp socket code from network.c to a dedicated file
ben
parents:
19271
diff
changeset
|
65 #include "tcp.h" |
9850
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
66 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
67 static struct stream_priv_s { |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
68 char* host; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
69 int port; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
70 char* url; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
71 } stream_priv_dflts = { |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
72 NULL, |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
73 10000, |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
74 NULL |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
75 }; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
76 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
77 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f) |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
78 /// URL definition |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
79 static m_option_t stream_opts_fields[] = { |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
80 {"hostname", ST_OFF(host), CONF_TYPE_STRING, 0, 0 ,0, NULL}, |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
81 {"port", ST_OFF(port), CONF_TYPE_INT, M_OPT_MIN, 1 ,0, NULL}, |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
82 {"filename", ST_OFF(url), CONF_TYPE_STRING, 0, 0 ,0, NULL}, |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
83 { NULL, NULL, 0, 0, 0, 0, NULL } |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
84 }; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
85 static struct m_struct_st stream_opts = { |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
86 "netstream", |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
87 sizeof(struct stream_priv_s), |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
88 &stream_priv_dflts, |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
89 stream_opts_fields |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
90 }; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
91 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
92 //// When the cache is running we need a lock as |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
93 //// fill_buffer is called from another proccess |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
94 static int lock_fd(int fd) { |
10281 | 95 #ifndef HAVE_WINSOCK2 |
9850
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
96 struct flock lock; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
97 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
98 memset(&lock,0,sizeof(struct flock)); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
99 lock.l_type = F_WRLCK; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
100 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
101 mp_msg(MSGT_STREAM,MSGL_DBG2, "Lock (%d)\n",getpid()); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
102 do { |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
103 if(fcntl(fd,F_SETLKW,&lock)) { |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
104 if(errno == EAGAIN) continue; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
105 mp_msg(MSGT_STREAM,MSGL_ERR, "Failed to get the lock: %s\n", |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
106 strerror(errno)); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
107 return 0; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
108 } |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
109 } while(0); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
110 mp_msg(MSGT_STREAM,MSGL_DBG2, "Locked (%d)\n",getpid()); |
10281 | 111 #else |
112 printf("FIXME? should lock here\n"); | |
113 #endif | |
9850
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
114 return 1; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
115 } |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
116 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
117 static int unlock_fd(int fd) { |
10281 | 118 #ifndef HAVE_WINSOCK2 |
9850
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
119 struct flock lock; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
120 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
121 memset(&lock,0,sizeof(struct flock)); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
122 lock.l_type = F_UNLCK; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
123 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
124 mp_msg(MSGT_STREAM,MSGL_DBG2, "Unlock (%d)\n",getpid()); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
125 if(fcntl(fd,F_SETLK,&lock)) { |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
126 mp_msg(MSGT_STREAM,MSGL_ERR, "Failed to release the lock: %s\n", |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
127 strerror(errno)); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
128 return 0; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
129 } |
10281 | 130 #else |
131 printf("FIXME? should unlock here\n"); | |
132 #endif | |
9850
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
133 return 1; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
134 } |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
135 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
136 static mp_net_stream_packet_t* send_net_stream_cmd(stream_t *s,uint16_t cmd,char* data,int len) { |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
137 mp_net_stream_packet_t* pack; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
138 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
139 // Cache is enabled : lock |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
140 if(s->cache_data && !lock_fd(s->fd)) |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
141 return NULL; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
142 // Send a command |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
143 if(!write_packet(s->fd,cmd,data,len)) { |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
144 if(s->cache_data) unlock_fd(s->fd); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
145 return 0; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
146 } |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
147 // Read the response |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
148 pack = read_packet(s->fd); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
149 // Now we can unlock |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
150 if(s->cache_data) unlock_fd(s->fd); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
151 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
152 if(!pack) |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
153 return NULL; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
154 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
155 switch(pack->cmd) { |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
156 case NET_STREAM_OK: |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
157 return pack; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
158 case NET_STREAM_ERROR: |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
159 if(pack->len > sizeof(mp_net_stream_packet_t)) |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
160 mp_msg(MSGT_STREAM,MSGL_ERR, "Fill buffer failed: %s\n",pack->data); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
161 else |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
162 mp_msg(MSGT_STREAM,MSGL_ERR, "Fill buffer failed\n"); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
163 free(pack); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
164 return NULL; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
165 } |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
166 |
10735
8a10d5d0ce86
serious bugs - 1l absinth (changed to absinth against cola inflation)
alex
parents:
10625
diff
changeset
|
167 mp_msg(MSGT_STREAM,MSGL_ERR, "Unknown response to %d: %d\n",cmd,pack->cmd); |
9850
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
168 free(pack); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
169 return NULL; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
170 } |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
171 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
172 static int fill_buffer(stream_t *s, char* buffer, int max_len){ |
9863
4c6c6c361f24
It should now be endian aware. Untested as i only have le box :(
albeu
parents:
9850
diff
changeset
|
173 uint16_t len = le2me_16(max_len); |
9850
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
174 mp_net_stream_packet_t* pack; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
175 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
176 pack = send_net_stream_cmd(s,NET_STREAM_FILL_BUFFER,(char*)&len,2); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
177 if(!pack) { |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
178 return -1; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
179 } |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
180 len = pack->len - sizeof(mp_net_stream_packet_t); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
181 if(len > max_len) { |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
182 mp_msg(MSGT_STREAM,MSGL_ERR, "Got a too big a packet %d / %d\n",len,max_len); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
183 free(pack); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
184 return 0; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
185 } |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
186 if(len > 0) |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
187 memcpy(buffer,pack->data,len); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
188 free(pack); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
189 return len; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
190 } |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
191 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
192 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
193 static int seek(stream_t *s,off_t newpos) { |
9863
4c6c6c361f24
It should now be endian aware. Untested as i only have le box :(
albeu
parents:
9850
diff
changeset
|
194 uint64_t pos = le2me_64((uint64_t)newpos); |
9850
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
195 mp_net_stream_packet_t* pack; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
196 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
197 pack = send_net_stream_cmd(s,NET_STREAM_SEEK,(char*)&pos,8); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
198 if(!pack) { |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
199 return 0; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
200 } |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
201 s->pos = newpos; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
202 free(pack); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
203 return 1; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
204 } |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
205 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
206 static int net_stream_reset(struct stream_st *s) { |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
207 mp_net_stream_packet_t* pack; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
208 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
209 pack = send_net_stream_cmd(s,NET_STREAM_RESET,NULL,0); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
210 if(!pack) { |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
211 return 0; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
212 } |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
213 free(pack); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
214 return 1; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
215 } |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
216 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
217 static int control(struct stream_st *s,int cmd,void* arg) { |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
218 switch(cmd) { |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
219 case STREAM_CTRL_RESET: |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
220 return net_stream_reset(s); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
221 } |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
222 return STREAM_UNSUPORTED; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
223 } |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
224 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
225 static void close_s(struct stream_st *s) { |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
226 mp_net_stream_packet_t* pack; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
227 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
228 pack = send_net_stream_cmd(s,NET_STREAM_CLOSE,NULL,0); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
229 if(pack) |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
230 free(pack); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
231 } |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
232 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
233 static int open_s(stream_t *stream,int mode, void* opts, int* file_format) { |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
234 int f; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
235 struct stream_priv_s* p = (struct stream_priv_s*)opts; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
236 mp_net_stream_packet_t* pack; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
237 mp_net_stream_opened_t* opened; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
238 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
239 if(mode != STREAM_READ) |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
240 return STREAM_UNSUPORTED; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
241 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
242 if(!p->host) { |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
243 mp_msg(MSGT_OPEN,MSGL_ERR, "We need an host name (ex: mpst://server.net/cdda://5)\n"); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
244 m_struct_free(&stream_opts,opts); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
245 return STREAM_ERROR; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
246 } |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
247 if(!p->url || strlen(p->url) == 0) { |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
248 mp_msg(MSGT_OPEN,MSGL_ERR, "We need a remote url (ex: mpst://server.net/cdda://5)\n"); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
249 m_struct_free(&stream_opts,opts); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
250 return STREAM_ERROR; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
251 } |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
252 |
10625
620cc649f519
ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
10608
diff
changeset
|
253 f = connect2Server(p->host,p->port,1); |
9850
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
254 if(f < 0) { |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
255 mp_msg(MSGT_OPEN,MSGL_ERR, "Connection to %s:%d failed\n",p->host,p->port); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
256 m_struct_free(&stream_opts,opts); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
257 return STREAM_ERROR; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
258 } |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
259 stream->fd = f; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
260 /// Now send an open command |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
261 pack = send_net_stream_cmd(stream,NET_STREAM_OPEN,p->url,strlen(p->url) + 1); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
262 if(!pack) { |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
263 goto error; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
264 } |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
265 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
266 if(pack->len != sizeof(mp_net_stream_packet_t) + |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
267 sizeof(mp_net_stream_opened_t)) { |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
268 mp_msg(MSGT_OPEN,MSGL_ERR, "Invalid open response packet len (%d bytes)\n",pack->len); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
269 free(pack); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
270 goto error; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
271 } |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
272 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
273 opened = (mp_net_stream_opened_t*)pack->data; |
9863
4c6c6c361f24
It should now be endian aware. Untested as i only have le box :(
albeu
parents:
9850
diff
changeset
|
274 net_stream_opened_2_me(opened); |
4c6c6c361f24
It should now be endian aware. Untested as i only have le box :(
albeu
parents:
9850
diff
changeset
|
275 |
9850
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
276 *file_format = opened->file_format; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
277 stream->flags = opened->flags; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
278 stream->sector_size = opened->sector_size; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
279 stream->start_pos = opened->start_pos; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
280 stream->end_pos = opened->end_pos; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
281 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
282 stream->fill_buffer = fill_buffer; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
283 stream->control = control; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
284 if(stream->flags & STREAM_SEEK) |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
285 stream->seek = seek; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
286 stream->close = close_s; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
287 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
288 free(pack); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
289 m_struct_free(&stream_opts,opts); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
290 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
291 return STREAM_OK; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
292 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
293 error: |
10281 | 294 closesocket(f); |
9850
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
295 m_struct_free(&stream_opts,opts); |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
296 return STREAM_ERROR; |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
297 } |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
298 |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
299 stream_info_t stream_info_netstream = { |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
300 "Net stream", |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
301 "netstream", |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
302 "Albeu", |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
303 "", |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
304 open_s, |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
305 { "mpst",NULL }, |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
306 &stream_opts, |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
307 1 // Url is an option string |
564678d0bc15
A new stream wich allow access to MPlayer stream accross the network.
albeu
parents:
diff
changeset
|
308 }; |