annotate TOOLS/netstream.c @ 24180:73aafdcc92fc

warning fix: modify_reg.c: In function 'remove_key': modify_reg.c:39: warning: unused variable 'tmp_name' modify_reg.c:39: warning: unused variable 'tmp_val'
author diego
date Sat, 25 Aug 2007 17:39:15 +0000
parents d258dd05e0ab
children fe3fd951b8cc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22855
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
1 /*
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
2 * netstream.c
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
3 *
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
4 * Copyright (C) Alban Bedel - 04/2003
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
5 *
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
6 * This file is part of MPlayer, a free movie player.
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
7 *
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
8 * MPlayer is free software; you can redistribute it and/or modify
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
10 * the Free Software Foundation; either version 2, or (at your option)
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
11 * any later version.
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
12 *
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
13 * MPlayer is distributed in the hope that it will be useful,
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
16 * GNU General Public License for more details.
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
17 *
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
19 * along with MPlayer; if not, write to the Free Software
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
21 */
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
22
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
23 #include <stdlib.h>
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
24 #include <stdio.h>
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
25 #include <unistd.h>
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
26 #include <inttypes.h>
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
27 #include <errno.h>
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
28 #include <signal.h>
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
29 #include <sys/types.h>
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
30
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
31 #include "config.h"
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
32
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
33 #ifndef HAVE_WINSOCK2
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
34 #include <sys/socket.h>
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
35 #include <netinet/in.h>
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
36 #include <arpa/inet.h>
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
37 #else
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
38 #include <winsock2.h>
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
39 #include <ws2tcpip.h>
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
40 #endif
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
41
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
42 #include "stream/stream.h"
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
43 #include "libmpdemux/demuxer.h"
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
44 #include "mp_msg.h"
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
45 #include "libavutil/common.h"
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
46 #include "mpbswap.h"
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
47
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
48 /// Netstream packets def and some helpers
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
49 #include "stream/netstream.h"
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
50
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
51
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
52 //Set some standard variables
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
53 char* dvdsub_lang=NULL;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
54 char* audio_lang=NULL;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
55 int sub_justify=0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
56 int identify=0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
57 int dvdsub_id=0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
58 int audio_id=0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
59 int video_id=0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
60 void af_fmt2str() {};
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
61
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
62 #ifdef __MINGW32__
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
63 #define usleep sleep
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
64 void strsep() {};
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
65 #endif
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
66
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
67 static unsigned short int port = 10000;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
68
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
69 typedef struct client_st client_t;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
70 struct client_st {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
71 int fd;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
72 stream_t* stream;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
73 client_t* next;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
74 client_t* prev;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
75 };
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
76
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
77 static int write_error(int fd,char* msg) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
78 int len = strlen(msg) + 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
79 return write_packet(fd,NET_STREAM_ERROR,msg,len);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
80 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
81
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
82 static int net_stream_open(client_t* cl,char* url) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
83 int file_format=DEMUXER_TYPE_UNKNOWN;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
84 mp_net_stream_opened_t ret;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
85
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
86 if(cl->stream) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
87 if(!write_error(cl->fd,"A stream is currently opened\n"))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
88 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
89 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
90 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
91
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
92 mp_msg(MSGT_NETST,MSGL_V,"Open stream %s\n",url);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
93 cl->stream = open_stream(url,NULL,&file_format);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
94 if(!cl->stream) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
95 if(!write_error(cl->fd,"Open failed\n"))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
96 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
97 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
98 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
99 stream_reset(cl->stream);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
100 stream_seek(cl->stream,cl->stream->start_pos);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
101 ret.file_format = file_format;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
102 ret.flags = cl->stream->flags;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
103 ret.sector_size = cl->stream->sector_size;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
104 ret.start_pos = cl->stream->start_pos;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
105 ret.end_pos = cl->stream->end_pos;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
106 net_stream_opened_2_me(&ret);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
107
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
108 if(!write_packet(cl->fd,NET_STREAM_OK,(char*)&ret,sizeof(mp_net_stream_opened_t)))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
109 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
110 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
111 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
112
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
113 static int net_stream_fill_buffer(client_t* cl,uint16_t max_len) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
114 int r;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
115 mp_net_stream_packet_t *pack;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
116
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
117 if(!cl->stream) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
118 if(!write_error(cl->fd,"No stream is currently opened\n"))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
119 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
120 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
121 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
122 if(max_len == 0) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
123 if(!write_error(cl->fd,"Fill buffer called with 0 lenght\n"))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
124 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
125 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
126 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
127 pack = malloc(max_len + sizeof(mp_net_stream_packet_t));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
128 pack->cmd = NET_STREAM_OK;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
129 r = stream_read(cl->stream,pack->data,max_len);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
130 pack->len = le2me_16(r + sizeof(mp_net_stream_packet_t));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
131 if(!net_write(cl->fd,(char*)pack,le2me_16(pack->len))) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
132 free(pack);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
133 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
134 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
135 free(pack);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
136 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
137 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
138
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
139 static int net_stream_seek(client_t* cl, uint64_t pos) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
140
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
141 if(!cl->stream) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
142 if(!write_error(cl->fd,"No stream is currently opened\n"))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
143 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
144 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
145 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
146
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
147 if(!stream_seek(cl->stream,(off_t)pos)) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
148 if(!write_error(cl->fd,"Seek failed\n"))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
149 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
150 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
151 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
152 if(!write_packet(cl->fd,NET_STREAM_OK,NULL,0))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
153 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
154 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
155 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
156
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
157 static int net_stream_reset(client_t* cl) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
158 if(!cl->stream) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
159 if(!write_error(cl->fd,"No stream is currently opened\n"))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
160 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
161 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
162 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
163 stream_reset(cl->stream);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
164 if(!write_packet(cl->fd,NET_STREAM_OK,NULL,0))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
165 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
166 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
167 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
168
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
169 static int net_stream_close(client_t* cl) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
170 if(!cl->stream) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
171 if(!write_error(cl->fd,"No stream is currently opened\n"))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
172 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
173 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
174 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
175
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
176 free_stream(cl->stream);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
177 cl->stream = NULL;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
178
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
179 if(!write_packet(cl->fd,NET_STREAM_OK,NULL,0))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
180 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
181 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
182 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
183
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
184 int handle_client(client_t* cl,mp_net_stream_packet_t* pack) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
185
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
186 if(!pack)
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
187 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
188
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
189 switch(pack->cmd) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
190 case NET_STREAM_OPEN:
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
191 if(((char*)pack)[pack->len-1] != '\0') {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
192 mp_msg(MSGT_NETST,MSGL_WARN,"Got invalid open packet\n");
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
193 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
194 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
195 return net_stream_open(cl,pack->data);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
196 case NET_STREAM_FILL_BUFFER:
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
197 if(pack->len != sizeof(mp_net_stream_packet_t) + 2) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
198 mp_msg(MSGT_NETST,MSGL_WARN,"Got invalid fill buffer packet\n");
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
199 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
200 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
201 return net_stream_fill_buffer(cl,le2me_16(*((uint16_t*)pack->data)));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
202 case NET_STREAM_SEEK:
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
203 if(pack->len != sizeof(mp_net_stream_packet_t) + 8) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
204 mp_msg(MSGT_NETST,MSGL_WARN,"Got invalid fill buffer packet\n");
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
205 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
206 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
207 return net_stream_seek(cl,le2me_64(*((uint64_t*)pack->data)));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
208 case NET_STREAM_RESET:
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
209 return net_stream_reset(cl);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
210 case NET_STREAM_CLOSE:
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
211 if(pack->len != sizeof(mp_net_stream_packet_t)){
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
212 mp_msg(MSGT_NETST,MSGL_WARN,"Got invalid fill buffer packet\n");
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
213 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
214 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
215 return net_stream_close(cl);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
216 default:
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
217 mp_msg(MSGT_NETST,MSGL_WARN,"Got unknown command %d\n",pack->cmd);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
218 if(!write_error(cl->fd,"Unknown command\n"))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
219 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
220 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
221 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
222 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
223
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
224 static client_t* add_client(client_t *head,int fd) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
225 client_t *new = calloc(1,sizeof(client_t));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
226 new->fd = fd;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
227 if(!head) return new;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
228 new->next = head;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
229 head->prev = new;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
230 return new;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
231 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
232
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
233 static int make_fd_set(fd_set* fds, client_t** _cl, int listen) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
234 int max_fd = listen;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
235 client_t *cl = *_cl;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
236 FD_ZERO(fds);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
237 FD_SET(listen,fds);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
238 while(cl) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
239 // Remove this client
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
240 if(cl->fd < 0) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
241 client_t* f = cl;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
242 if(cl->prev) cl->prev->next = cl->next;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
243 if(cl->next) cl->next->prev = cl->prev;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
244 if(cl->stream) free_stream(cl->stream);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
245 if(!cl->prev) // Remove the head
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
246 *_cl = cl->next;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
247 cl = cl->next;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
248 free(f);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
249 continue;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
250 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
251 FD_SET(cl->fd,fds);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
252 if(cl->fd > max_fd) max_fd = cl->fd;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
253 cl = cl->next;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
254 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
255 return max_fd+1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
256 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
257
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
258 /// Hack to 'cleanly' exit
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
259 static int run_server = 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
260
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
261 void exit_sig(int sig) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
262 static int count = 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
263 sig++; // gcc warning
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
264 count++;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
265 if(count==3) exit(1);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
266 if(count > 3)
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
267 #ifdef __MINGW32__
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
268 WSACleanup();
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
269 #else
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
270 kill(getpid(),SIGKILL);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
271 #endif
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
272 run_server = 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
273 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
274
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
275 static int main_loop(int listen_fd) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
276 client_t *clients = NULL,*iter;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
277 fd_set fds;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
278
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
279 signal(SIGTERM,exit_sig); // kill
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
280 #ifndef __MINGW32__
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
281 signal(SIGHUP,exit_sig); // kill -HUP / xterm closed
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
282 signal(SIGINT,exit_sig); // Interrupt from keyboard
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
283 signal(SIGQUIT,exit_sig); // Quit from keyboard
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
284 #endif
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
285
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
286 while(run_server) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
287 int sel_n = make_fd_set(&fds,&clients,listen_fd);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
288 int n = select(sel_n,&fds,NULL,NULL,NULL);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
289 if(n < 0) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
290 if(errno == EINTR)
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
291 continue;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
292 mp_msg(MSGT_NETST,MSGL_FATAL,"Select error: %s\n",strerror(errno));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
293 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
294 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
295 // New connection
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
296 if(FD_ISSET(listen_fd,&fds)) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
297 struct sockaddr_in addr;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
298 socklen_t slen = sizeof(struct sockaddr_in);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
299 int client_fd = accept(listen_fd,(struct sockaddr*)&addr,&slen);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
300 if(client_fd < 0) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
301 mp_msg(MSGT_NETST,MSGL_ERR,"accept failed: %s\n",strerror(errno));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
302 continue;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
303 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
304 mp_msg(MSGT_NETST,MSGL_V,"New client from %s\n",inet_ntoa(addr.sin_addr));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
305 clients = add_client(clients,client_fd);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
306 if(n == 1) continue;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
307 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
308 // Look for the clients
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
309 for(iter = clients ; iter ; iter = iter->next) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
310 mp_net_stream_packet_t* pack;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
311 if(!FD_ISSET(iter->fd,&fds)) continue;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
312 pack = read_packet(iter->fd);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
313 if(!pack) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
314 close(iter->fd);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
315 iter->fd = -1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
316 continue;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
317 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
318 if(!handle_client(iter,pack)) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
319 close(iter->fd);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
320 iter->fd = -1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
321 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
322 free(pack);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
323 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
324 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
325 mp_msg(MSGT_NETST,MSGL_INFO,"Exit ....\n");
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
326 close(listen_fd);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
327 #ifdef __MINGW32__
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
328 WSACleanup();
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
329 #endif
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
330 while(clients) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
331 client_t* f = clients;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
332 if(f->stream) free_stream(f->stream);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
333 if(f->fd > 0) close(f->fd);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
334 free(f);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
335 clients = clients->next;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
336 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
337 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
338 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
339
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
340 int main(int argc, char** argv) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
341 int listen_fd;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
342 struct sockaddr_in addr;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
343
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
344 mp_msg_init();
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
345 // mp_msg_set_level(verbose+MSGL_STATUS);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
346
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
347 #ifdef __MINGW32__
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
348 WSADATA wsaData;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
349 WSAStartup(MAKEWORD(1,1), &wsaData);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
350 #endif
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
351 listen_fd = socket(AF_INET, SOCK_STREAM, 0);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
352 if(listen_fd < 0) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
353 mp_msg(MSGT_NETST,MSGL_FATAL,"Failed to create listen_fd: %s\n",strerror(errno));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
354 return -1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
355 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
356 memset(&addr,0,sizeof(struct sockaddr));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
357 addr.sin_addr.s_addr = INADDR_ANY;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
358 addr.sin_port = htons(port);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
359 addr.sin_family = AF_INET;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
360 if(bind(listen_fd,(struct sockaddr*)&addr,sizeof(struct sockaddr))) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
361 mp_msg(MSGT_NETST,MSGL_FATAL,"Failed to bind listen socket: %s\n",strerror(errno));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
362 return -1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
363 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
364
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
365
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
366 if(listen(listen_fd,1)) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
367 mp_msg(MSGT_NETST,MSGL_FATAL,"Failed to turn the socket in listen state: %s\n",strerror(errno));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
368 return -1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
369 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
370 return main_loop(listen_fd);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
371 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
372
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
373
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
374
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
375 //---- For libmpdemux
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
376
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
377 float stream_cache_seek_min_percent=50.0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
378 float stream_cache_min_percent=20.0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
379
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
380 #include <libmpdemux/demuxer.h>
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
381 #include <libmpdemux/stheader.h>
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
382
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
383 // audio stream skip/resync functions requires only for seeking.
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
384 // (they should be implemented in the audio codec layer)
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
385 void skip_audio_frame(sh_audio_t *sh_audio){
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
386 sh_audio=NULL;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
387 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
388 void resync_audio_stream(sh_audio_t *sh_audio){
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
389 sh_audio=NULL;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
390 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
391
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
392 int mp_input_check_interrupt(int time){
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
393 if(time) usleep(time);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
394 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
395 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
396
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
397 // for libdvdread:
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
398 #include "get_path.c"
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
399
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
400 int stream_cache_size=0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
401
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
402 // for demux_ogg:
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
403 void* vo_sub=NULL;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
404 int vo_osd_changed(int new_value){ new_value++; return 0;}
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
405 int subcc_enabled=0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
406
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
407 float sub_fps=0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
408 int sub_utf8=0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
409 int suboverlap_enabled = 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
410 float sub_delay=0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
411
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
412 //---------------