annotate TOOLS/netstream.c @ 26770:7437ddc4dba4

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