annotate libmpdemux/network.c @ 2658:2995e0cf02e9

removed #define USE_XANIM hack
author alex
date Sat, 03 Nov 2001 21:27:23 +0000
parents 66837325b929
children 6b6fa2be9b97
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
1 /*
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
2 * Network layer for MPlayer
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
3 * by Bertrand BAUDET <bertrand_baudet@yahoo.com>
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
4 * (C) 2001, MPlayer team.
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
5 */
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
6
1028
a710b2a06564 Commented the default output to file.
bertrand
parents: 999
diff changeset
7 //#define DUMP2FILE
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
8
1430
1728d249c783 missing unistd.h (requires for off_t under freebsd)
arpi
parents: 1028
diff changeset
9 #include <stdio.h>
1728d249c783 missing unistd.h (requires for off_t under freebsd)
arpi
parents: 1028
diff changeset
10 #include <stdlib.h>
1728d249c783 missing unistd.h (requires for off_t under freebsd)
arpi
parents: 1028
diff changeset
11 #include <string.h>
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
12 #include <unistd.h>
1430
1728d249c783 missing unistd.h (requires for off_t under freebsd)
arpi
parents: 1028
diff changeset
13
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
14 #include <fcntl.h>
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
15 #include <netdb.h>
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
16 #include <netinet/in.h>
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
17 #include <sys/time.h>
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
18 #include <sys/types.h>
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
19 #include <sys/socket.h>
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
20 #include <arpa/inet.h>
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
21
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
22 #include <pthread.h>
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
23
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
24 #include <errno.h>
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
25 #include <ctype.h>
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
26
2555
66837325b929 config.h cleanup, few things added to steram/demuxer headers
arpi
parents: 2489
diff changeset
27 #include "config.h"
66837325b929 config.h cleanup, few things added to steram/demuxer headers
arpi
parents: 2489
diff changeset
28
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
29 #include "stream.h"
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
30 #include "demuxer.h"
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
31
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
32 #include "network.h"
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
33 #include "http.h"
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
34 #include "url.h"
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
35 #include "asf.h"
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
36
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
37 streaming_ctrl_t *streaming_ctrl;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
38
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
39 static ASF_StreamType_e streaming_type = ASF_Unknown_e;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
40
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
41 Net_Fifo *
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
42 net_fifo_new() {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
43 Net_Fifo *net_fifo;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
44 net_fifo = (Net_Fifo*)malloc(sizeof(Net_Fifo));
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
45 if( net_fifo==NULL ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
46 printf("Memory allocation failed\n");
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
47 return NULL;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
48 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
49 memset( net_fifo, 0, sizeof(Net_Fifo) );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
50 return net_fifo;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
51 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
52
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
53 void
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
54 net_fifo_free( Net_Fifo *net_fifo ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
55 if( net_fifo->buffer!=NULL ) free( net_fifo->buffer );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
56 free( net_fifo );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
57 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
58
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
59 int
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
60 net_fifo_push(Net_Fifo *net_fifo, char *buffer, int length ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
61 char *ptr;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
62 if( net_fifo==NULL || buffer==NULL || length<0 ) return -1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
63
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
64 ptr = (char*)malloc(length+net_fifo->length);
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
65 if( ptr==NULL ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
66 printf("Memory allocation failed\n");
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
67 return -1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
68 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
69 if( net_fifo->buffer!=NULL ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
70 memcpy( ptr, net_fifo->buffer, net_fifo->length );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
71 free( net_fifo->buffer );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
72 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
73 memcpy( ptr+net_fifo->length, buffer, length );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
74 net_fifo->buffer = ptr;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
75 net_fifo->length += length;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
76 return net_fifo->length;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
77 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
78
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
79 int
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
80 net_fifo_pop(Net_Fifo *net_fifo, char *buffer, int length ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
81 char *ptr;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
82 int len;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
83 if( net_fifo==NULL || buffer==NULL || length<0 ) return -1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
84 if( net_fifo->buffer==NULL || net_fifo->length==0 ) return -1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
85
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
86 len = MIN(net_fifo->length, length);
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
87
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
88 ptr = (char*)malloc(net_fifo->length-len);
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
89 if( ptr==NULL ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
90 printf("Memory allocation failed\n");
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
91 return -1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
92 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
93 memcpy( buffer, net_fifo->buffer, len );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
94 if( net_fifo->length-len!=0 ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
95 memcpy( ptr, net_fifo->buffer+len, net_fifo->length-len );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
96 free( net_fifo->buffer );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
97 net_fifo->buffer = ptr;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
98 net_fifo->length -= len;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
99 } else {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
100 free( net_fifo->buffer );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
101 net_fifo->buffer = NULL;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
102 net_fifo->length = 0;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
103 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
104 return len;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
105 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
106
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
107 streaming_ctrl_t *
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
108 streaming_ctrl_new( ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
109 streaming_ctrl_t *streaming_ctrl;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
110 streaming_ctrl = (streaming_ctrl_t*)malloc(sizeof(streaming_ctrl_t));
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
111 if( streaming_ctrl==NULL ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
112 printf("Failed to allocate memory\n");
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
113 return NULL;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
114 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
115 memset( streaming_ctrl, 0, sizeof(streaming_ctrl_t) );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
116 streaming_ctrl->buffer = net_fifo_new();
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
117 return streaming_ctrl;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
118 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
119
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
120 void
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
121 streaming_ctrl_free( streaming_ctrl_t *streaming_ctrl ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
122 if( streaming_ctrl==NULL ) return;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
123 if( streaming_ctrl->buffer!=NULL ) net_fifo_free( streaming_ctrl->buffer );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
124 free( streaming_ctrl );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
125 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
126
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
127 int
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
128 readFromServer(int fd, char *buffer, int length) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
129 int ret;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
130 int done=0;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
131 fd_set set;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
132 struct timeval tv;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
133 if( buffer==NULL || length<0 ) return -1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
134
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
135
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
136 // fcntl( fd, F_SETFL, fcntl(fd, F_GETFL) & ~O_NONBLOCK );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
137 return read( fd, buffer, length );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
138
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
139 do {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
140 tv.tv_sec = 0;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
141 tv.tv_usec = 10000; // 10 milli-seconds timeout
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
142 FD_ZERO( &set );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
143 FD_SET( fd, &set );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
144 ret = select( fd+1, &set, NULL, NULL, &tv );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
145 if( ret<0 ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
146 perror("select");
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
147 } else if( ret==0 ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
148 printf("timeout\n");
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
149 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
150 if( FD_ISSET(fd, &set) ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
151 ret = read( fd, buffer, length );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
152 if( ret<0 ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
153 if( errno!=EINPROGRESS ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
154 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
155 } else {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
156 done = 1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
157 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
158 } else {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
159 return -1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
160 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
161 } while( !done );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
162
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
163 return ret;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
164 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
165
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
166 // Connect to a server using a TCP connection
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
167 int
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
168 connect2Server(char *host, int port) {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
169 int socket_server_fd;
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
170 int err, err_len;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
171 fd_set set;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
172 struct timeval tv;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
173 struct sockaddr_in server_address;
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
174
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
175 printf("Connecting to server %s:%d ...\n", host, port );
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
176
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
177 socket_server_fd = socket(AF_INET, SOCK_STREAM, 0);
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
178 // fcntl( socket_server_fd, F_SETFL, fcntl(socket_server_fd, F_GETFL) | O_NONBLOCK );
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
179 if( socket_server_fd==-1 ) {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
180 perror("Failed to create socket");
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
181 return -1;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
182 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
183
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
184 if( isalpha(host[0]) ) {
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
185 struct hostent *hp =(struct hostent*)gethostbyname( host );
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
186 if( hp==NULL ) {
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
187 printf("Counldn't resolve name: %s\n", host);
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
188 return -1;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
189 }
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
190 memcpy( (void*)&server_address.sin_addr.s_addr, (void*)hp->h_addr, hp->h_length );
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
191 } else {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
192 inet_pton(AF_INET, host, &server_address.sin_addr);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
193 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
194 server_address.sin_family=AF_INET;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
195 server_address.sin_port=htons(port);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
196
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
197 if( connect( socket_server_fd, (struct sockaddr*)&server_address, sizeof(server_address) )==-1 ) {
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
198 if( errno!=EINPROGRESS ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
199 perror("Failed to connect to server");
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
200 close(socket_server_fd);
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
201 return -1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
202 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
203 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
204
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
205 tv.tv_sec = 0;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
206 tv.tv_usec = 10000; // 10 milli-seconds timeout
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
207 FD_ZERO( &set );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
208 FD_SET( socket_server_fd, &set );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
209 if( select(socket_server_fd+1, NULL, &set, NULL, &tv)>0 ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
210 err_len = sizeof( err );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
211 getsockopt( socket_server_fd, SOL_SOCKET, SO_ERROR, &err, &err_len );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
212 if( err ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
213 printf("Couldn't connect to host %s\n", host );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
214 printf("Socket error: %d\n", err );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
215 close(socket_server_fd);
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
216 return -1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
217 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
218 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
219 return socket_server_fd;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
220 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
221
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
222 int
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
223 http_send_request( URL_t *url ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
224 HTTP_header_t *http_hdr;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
225 int fd;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
226 http_hdr = http_new_header();
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
227 http_set_uri( http_hdr, url->file );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
228 http_set_field( http_hdr, "User-Agent: MPlayer");
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
229 http_set_field( http_hdr, "Connection: closed");
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
230 if( http_build_request( http_hdr )==NULL ) {
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
231 return -1;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
232 }
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
233
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
234 fd = connect2Server( url->hostname, url->port );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
235 if( fd<0 ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
236 return -1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
237 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
238 write( fd, http_hdr->buffer, http_hdr->buffer_size );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
239 http_free( http_hdr );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
240
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
241 return fd;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
242 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
243
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
244 HTTP_header_t *
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
245 http_read_response( int fd ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
246 HTTP_header_t *http_hdr;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
247 char response[BUFFER_SIZE];
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
248 int i;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
249
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
250 http_hdr = http_new_header();
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
251 if( http_hdr==NULL ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
252 return NULL;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
253 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
254
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
255 do {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
256 i = readFromServer( fd, response, BUFFER_SIZE );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
257 if( i<0 ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
258 printf("Read failed\n");
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
259 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
260 http_response_append( http_hdr, response, i );
2489
0ecc1b4f7cf8 Added ASF http server streaming (Not mms streaming).
bertrand
parents: 2310
diff changeset
261 } while( !http_is_header_entire( http_hdr ) );
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
262 http_response_parse( http_hdr );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
263 return http_hdr;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
264 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
265
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
266 // By using the protocol, the extension of the file or the content-type
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
267 // we might be able to guess the streaming type.
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
268 int
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
269 autodetectProtocol(URL_t *url, int *fd_out) {
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
270 HTTP_header_t *http_hdr;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
271 int fd=-1;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
272 int i;
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
273 int redirect;
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
274 char *extension;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
275 char *content_type;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
276 char *next_url;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
277 char response[1024];
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
278
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
279 do {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
280 *fd_out=-1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
281 next_url = NULL;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
282 extension = NULL;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
283 content_type = NULL;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
284 redirect = 0;
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
285
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
286 if( url==NULL ) return DEMUXER_TYPE_UNKNOWN;
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
287
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
288 // Get the extension of the file if present
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
289 if( url->file!=NULL ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
290 for( i=strlen(url->file) ; i>0 ; i-- ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
291 if( url->file[i]=='.' ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
292 extension=(url->file)+i+1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
293 break;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
294 }
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
295 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
296 }
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
297 // extension=NULL;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
298 if( extension!=NULL ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
299 printf("Extension: %s\n", extension );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
300 if( !strcasecmp(extension, "asf") ||
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
301 !strcasecmp(extension, "wmv") ||
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
302 !strcasecmp(extension, "asx") ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
303 if( url->port==0 ) url->port = 80;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
304 return DEMUXER_TYPE_ASF;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
305 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
306 if( !strcasecmp(extension, "mpg") ||
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
307 !strcasecmp(extension, "mpeg") ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
308 if( url->port==0 ) url->port = 80;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
309 return DEMUXER_TYPE_MPEG_PS;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
310 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
311 if( !strcasecmp(extension, "avi") ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
312 if( url->port==0 ) url->port = 80;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
313 return DEMUXER_TYPE_AVI;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
314 }
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
315 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
316
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
317 // Checking for RTSP
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
318 if( !strcasecmp(url->protocol, "rtsp") ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
319 printf("RTSP protocol not yet implemented!\n");
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
320 return DEMUXER_TYPE_UNKNOWN;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
321 }
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
322
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
323 // Checking for ASF
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
324 if( !strcasecmp(url->protocol, "mms") ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
325 if( url->port==0 ) url->port = 80;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
326 return DEMUXER_TYPE_ASF;
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
327 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
328
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
329 // HTTP based protocol
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
330 if( !strcasecmp(url->protocol, "http") ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
331 if( url->port==0 ) url->port = 80;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
332
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
333 fd = http_send_request( url );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
334 if( fd<0 ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
335 *fd_out=-1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
336 return DEMUXER_TYPE_UNKNOWN;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
337 }
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
338
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
339 http_hdr = http_read_response( fd );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
340 if( http_hdr==NULL ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
341 close( fd );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
342 *fd_out=-1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
343 return DEMUXER_TYPE_UNKNOWN;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
344 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
345
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
346 *fd_out=fd;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
347 //http_debug_hdr( http_hdr );
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
348
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
349 // Check if the response is an ICY status_code reason_phrase
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
350 if( !strcasecmp(http_hdr->protocol, "ICY") ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
351 // Ok, we have detected an mp3 streaming
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
352 return DEMUXER_TYPE_MPEG_PS;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
353 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
354
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
355 switch( http_hdr->status_code ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
356 case 200: // OK
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
357 // Look if we can use the Content-Type
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
358 content_type = http_get_field( http_hdr, "Content-Type" );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
359 if( content_type!=NULL ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
360 printf("Content-Type: [%s]\n", content_type );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
361 printf("Content-Length: [%s]\n", http_get_field(http_hdr, "Content-Length") );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
362 // Check for ASF
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
363 if( asf_http_streaming_type(content_type, NULL)!=ASF_Unknown_e ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
364 return DEMUXER_TYPE_ASF;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
365 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
366 // Check for MP3 streaming
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
367 // Some MP3 streaming server answer with audio/mpeg
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
368 if( !strcasecmp(content_type, "audio/mpeg") ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
369 return DEMUXER_TYPE_MPEG_PS;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
370 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
371 // Check for MPEG streaming
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
372 if( !strcasecmp(content_type, "video/mpeg") ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
373 return DEMUXER_TYPE_MPEG_PS;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
374 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
375 // AVI ??? => video/x-msvideo
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
376 if( !strcasecmp(content_type, "video/x-msvideo") ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
377 return DEMUXER_TYPE_AVI;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
378 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
379 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
380 break;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
381 // Redirect
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
382 case 301: // Permanently
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
383 case 302: // Temporarily
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
384 // TODO: RFC 2616, recommand to detect infinite redirection loops
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
385 next_url = http_get_field( http_hdr, "Location" );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
386 if( next_url!=NULL ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
387 close( fd );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
388 url_free( url );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
389 url = url_new( next_url );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
390 redirect = 1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
391 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
392 break;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
393 default:
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
394 printf("Server returned %d: %s\n", http_hdr->status_code, http_hdr->reason_phrase );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
395 close( fd );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
396 *fd_out=-1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
397 return DEMUXER_TYPE_UNKNOWN;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
398 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
399 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
400 } while( redirect );
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
401
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
402 return DEMUXER_TYPE_UNKNOWN;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
403 }
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
404
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
405 int
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
406 nop_streaming_read( streaming_ctrl_t *streaming_ctrl ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
407 char *buffer;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
408 int len;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
409 if( streaming_ctrl==NULL ) return -1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
410 len = streaming_ctrl->buffer->length;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
411 if( len==0 ) return 0;
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
412
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
413 buffer = (char*)malloc( len );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
414 if( buffer==NULL ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
415 printf("Memory allocation failed\n");
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
416 return -1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
417 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
418 net_fifo_pop( streaming_ctrl->buffer, buffer, len );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
419 write( streaming_ctrl->fd_pipe_in, buffer, len );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
420 free( buffer );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
421 return len;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
422 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
423
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
424 int
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
425 nop_streaming_start( streaming_ctrl_t *streaming_ctrl ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
426 HTTP_header_t *http_hdr;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
427 int fd;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
428 if( streaming_ctrl==NULL ) return -1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
429
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
430 fd = streaming_ctrl->fd_net;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
431 if( fd<0 ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
432 fd = http_send_request( *(streaming_ctrl->url) );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
433 if( fd<0 ) return -1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
434 http_hdr = http_read_response( fd );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
435 if( http_hdr==NULL ) return -1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
436
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
437 switch( http_hdr->status_code ) {
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
438 case 200: // OK
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
439 printf("Content-Type: [%s]\n", http_get_field(http_hdr, "Content-Type") );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
440 printf("Content-Length: [%s]\n", http_get_field(http_hdr, "Content-Length") );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
441 if( http_hdr->body_size>0 ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
442 write( streaming_ctrl->fd_pipe_in, http_hdr->body, http_hdr->body_size );
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
443 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
444 break;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
445 default:
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
446 printf("Server return %d: %s\n", http_hdr->status_code, http_hdr->reason_phrase );
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
447 close( fd );
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
448 fd = -1;
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
449 }
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
450 streaming_ctrl->fd_net = fd;
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
451 }
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
452
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
453 http_free( http_hdr );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
454
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
455 streaming_ctrl->streaming_read = nop_streaming_read;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
456 streaming_ctrl->prebuffer_size = 180000;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
457 // streaming_ctrl->prebuffer_size = 0;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
458 streaming_ctrl->buffering = 1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
459 // streaming_ctrl->buffering = 0;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
460 streaming_ctrl->status = streaming_playing_e;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
461 return fd;
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
462 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
463
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
464 void
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
465 network_streaming(void *arg) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
466 char buffer[BUFFER_SIZE];
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
467 fd_set fd_net_in;
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
468 int ret;
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
469
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
470 arg = arg;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
471
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
472 do {
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
473 FD_ZERO( &fd_net_in );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
474 FD_SET( streaming_ctrl->fd_net, &fd_net_in );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
475
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
476 ret = select( streaming_ctrl->fd_net+1, &fd_net_in, NULL, NULL, NULL );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
477 if( ret<0 ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
478 perror("select");
1631
09284c9c2b49 exit() -> return NULL
arpi
parents: 1430
diff changeset
479 return; //exit(1); // FIXME!
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
480 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
481 if( FD_ISSET( streaming_ctrl->fd_net, &fd_net_in ) ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
482 ret = readFromServer( streaming_ctrl->fd_net, buffer, BUFFER_SIZE );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
483 if( ret<=0 ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
484 streaming_ctrl->status=streaming_stopped_e;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
485 } else {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
486 //printf(" push: 0x%02X\n", *((unsigned int*)buffer) );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
487 net_fifo_push( streaming_ctrl->buffer, buffer, ret );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
488 if( !streaming_ctrl->buffering ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
489 do {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
490 ret = streaming_ctrl->streaming_read( streaming_ctrl );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
491 if( ret<0 && streaming_ctrl->buffer->length<streaming_ctrl->prebuffer_size ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
492 // Need buffering
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
493 streaming_ctrl->buffering = 1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
494 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
495 } while( streaming_ctrl->buffer->length>streaming_ctrl->prebuffer_size );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
496 } else {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
497 if( streaming_ctrl->buffer->length>streaming_ctrl->prebuffer_size ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
498 streaming_ctrl->buffering = 0;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
499 printf("\n");
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
500 } else {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
501 printf(" Buffering: %d \%\r", (int)((float)(((float)streaming_ctrl->buffer->length)/((float)streaming_ctrl->prebuffer_size))*100) );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
502 fflush(stdout);
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
503 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
504 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
505 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
506 } else {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
507 printf("Network fd not set\n");
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
508 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
509 } while( streaming_ctrl->status==streaming_playing_e );
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
510
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
511 // Flush the buffer
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
512 while( streaming_ctrl->buffer->length>0 ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
513 ret = streaming_ctrl->streaming_read( streaming_ctrl );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
514 if( ret<0 ) break;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
515 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
516
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
517 printf("Network thread done\n");
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
518
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
519 // Close to the pipe to stop mplayer.
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
520 close( streaming_ctrl->fd_pipe_in );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
521
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
522 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
523
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
524 int
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
525 streaming_start(URL_t **url, int fd, int streaming_type) {
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
526 int fd_pipe[2];
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
527 // Open the pipe
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
528 if( pipe(fd_pipe)<0 ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
529 printf("Pipe creation failed\n");
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
530 return -1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
531 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
532
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
533 streaming_ctrl = streaming_ctrl_new( );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
534 if( streaming_ctrl==NULL ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
535 return -1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
536 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
537 streaming_ctrl->url = url;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
538 streaming_ctrl->fd_pipe_in = fd_pipe[1];
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
539 streaming_ctrl->fd_net = fd;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
540
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
541 #ifdef DUMP2FILE
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
542 {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
543 int fd_file;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
544 fd_file = open("dump.stream", O_WRONLY | O_CREAT );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
545 if( fd_file<0 ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
546 perror("open");
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
547 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
548 streaming_ctrl->fd_pipe_in = fd_file;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
549 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
550 #endif
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
551
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
552 switch( streaming_type ) {
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
553 case DEMUXER_TYPE_ASF:
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
554 // Send the appropriate HTTP request
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
555 fd = asf_http_streaming_start( streaming_ctrl );
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
556 break;
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
557 case DEMUXER_TYPE_AVI:
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
558 case DEMUXER_TYPE_MPEG_ES:
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
559 case DEMUXER_TYPE_MPEG_PS:
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
560 fd = nop_streaming_start( streaming_ctrl );
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
561 break;
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
562 case DEMUXER_TYPE_UNKNOWN:
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
563 default:
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
564 printf("Unable to detect the streaming type\n");
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
565 close( fd );
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
566 free( streaming_ctrl );
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
567 return -1;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
568 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
569
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
570 if( fd<0 ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
571 free( streaming_ctrl );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
572 return -1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
573 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
574
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
575 // Start the network thread
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
576 if( pthread_create( &(streaming_ctrl->thread_id), NULL , (void*)network_streaming, (void*)NULL)<0 ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
577 printf("Unable to start the network thread.\n");
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
578 close( fd );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
579 free( streaming_ctrl );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
580 return -1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
581 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
582 printf("Network thread created with id: %d\n", streaming_ctrl->thread_id );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
583
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
584 // streaming_ctrl->status = streaming_stopped_e;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
585
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
586 // return fd;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
587 return fd_pipe[0];
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
588 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
589
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
590 int
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
591 streaming_stop( ) {
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
592 streaming_ctrl->status = streaming_stopped_e;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
593 return 0;
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
594 }