summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer
authorllornkcor <llornkcor>2002-04-20 21:02:20 (UTC)
committer llornkcor <llornkcor>2002-04-20 21:02:20 (UTC)
commitb452044ec1b3327f25f8552045b4229c8af39bf7 (patch) (unidiff)
tree1a3785f1af71fe38aabe131a2a8f0ad8a5be76c9 /core/multimedia/opieplayer
parent99904a1df601bb5d1c0e6d43a3e04a63fe13cf51 (diff)
downloadopie-b452044ec1b3327f25f8552045b4229c8af39bf7.zip
opie-b452044ec1b3327f25f8552045b4229c8af39bf7.tar.gz
opie-b452044ec1b3327f25f8552045b4229c8af39bf7.tar.bz2
http streaming
Diffstat (limited to 'core/multimedia/opieplayer') (more/less context) (show whitespace changes)
-rw-r--r--core/multimedia/opieplayer/libmad/libmad.pro2
-rw-r--r--core/multimedia/opieplayer/libmad/libmadplugin.cpp55
2 files changed, 40 insertions, 17 deletions
diff --git a/core/multimedia/opieplayer/libmad/libmad.pro b/core/multimedia/opieplayer/libmad/libmad.pro
index eddf242..679242b 100644
--- a/core/multimedia/opieplayer/libmad/libmad.pro
+++ b/core/multimedia/opieplayer/libmad/libmad.pro
@@ -2,13 +2,13 @@ TEMPLATE = lib
2CONFIG += qt warn_on release 2CONFIG += qt warn_on release
3HEADERS = libmad_version.h fixed.h bit.h timer.h stream.h frame.h synth.h decoder.h \ 3HEADERS = libmad_version.h fixed.h bit.h timer.h stream.h frame.h synth.h decoder.h \
4 layer12.h layer3.h huffman.h libmad_global.h mad.h libmadplugin.h libmadpluginimpl.h 4 layer12.h layer3.h huffman.h libmad_global.h mad.h libmadplugin.h libmadpluginimpl.h
5SOURCES = version.c fixed.c bit.c timer.c stream.c frame.c synth.c decoder.c \ 5SOURCES = version.c fixed.c bit.c timer.c stream.c frame.c synth.c decoder.c \
6 layer12.c layer3.c huffman.c libmadplugin.cpp libmadpluginimpl.cpp 6 layer12.c layer3.c huffman.c libmadplugin.cpp libmadpluginimpl.cpp
7TARGET = madplugin 7TARGET = madplugin
8DESTDIR = ../../plugins/codecs 8DESTDIR = ../../../plugins/codecs
9INCLUDEPATH += $(OPIEDIR)/include .. 9INCLUDEPATH += $(OPIEDIR)/include ..
10DEPENDPATH += ../$(OPIEDIR)/include .. 10DEPENDPATH += ../$(OPIEDIR)/include ..
11LIBS += -lqpe -lm 11LIBS += -lqpe -lm
12VERSION = 1.0.0 12VERSION = 1.0.0
13 13
14TRANSLATIONS = ../../i18n/pt_BR/libmadplugin.ts 14TRANSLATIONS = ../../i18n/pt_BR/libmadplugin.ts
diff --git a/core/multimedia/opieplayer/libmad/libmadplugin.cpp b/core/multimedia/opieplayer/libmad/libmadplugin.cpp
index 46f2450..4665408 100644
--- a/core/multimedia/opieplayer/libmad/libmadplugin.cpp
+++ b/core/multimedia/opieplayer/libmad/libmadplugin.cpp
@@ -14,12 +14,17 @@
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <qapplication.h>
21#include <qpe/config.h>
22#include <qmessagebox.h>
23#include <qstring.h>
24
20#include <stdio.h> 25#include <stdio.h>
21#include <stdarg.h> 26#include <stdarg.h>
22#include <stdlib.h> 27#include <stdlib.h>
23#include <sys/types.h> 28#include <sys/types.h>
24#include <sys/stat.h> 29#include <sys/stat.h>
25#include <fcntl.h> 30#include <fcntl.h>
@@ -28,14 +33,13 @@
28#include <ctype.h> 33#include <ctype.h>
29#include <errno.h> 34#include <errno.h>
30#include <time.h> 35#include <time.h>
31#include <locale.h> 36#include <locale.h>
32#include <math.h> 37#include <math.h>
33#include <assert.h> 38#include <assert.h>
34#include <qapplication.h> 39
35#include <qpe/config.h>
36 40
37// for network handling 41// for network handling
38#include <netinet/in.h> 42#include <netinet/in.h>
39#include <netdb.h> 43#include <netdb.h>
40#include <sys/socket.h> 44#include <sys/socket.h>
41#include <arpa/inet.h> 45#include <arpa/inet.h>
@@ -230,58 +234,67 @@ int LibMadPlugin::http_read_line(int tcp_sock, char *buf, int size) {
230 234
231 buf[offset] = 0; 235 buf[offset] = 0;
232 return offset; 236 return offset;
233} 237}
234 238
235int LibMadPlugin::http_open(const QString& path ) { 239int LibMadPlugin::http_open(const QString& path ) {
240 qDebug("Open http");
236 char *host; 241 char *host;
237 int port; 242 int port;
238 char *request; 243 char *request;
239 int tcp_sock; 244 int tcp_sock;
240 char http_request[PATH_MAX]; 245 char http_request[PATH_MAX];
241 char filename[PATH_MAX]; 246 char filename[PATH_MAX];
242 char c; 247 char c;
243 char *arg =strdup(path.latin1()); 248 char *arg =strdup(path.latin1());
244 249
250 QString errorMsg;
251
245 /* Check for URL syntax */ 252 /* Check for URL syntax */
246 if (strncmp(arg, "http://", strlen("http://"))) 253// if (strncmp(arg, "http://", strlen("http://"))) {
247 return (0); 254// qDebug("Url syntax error");
255// return (0);
256// }
248 257
249 /* Parse URL */ 258 qDebug("Parse URL");
250 port = 80; 259 port = 80;
251 host = arg + strlen("http://"); 260 host = arg + strlen("http://");
252 if ((request = strchr(host, '/')) == NULL) 261 if ((request = strchr(host, '/')) == NULL) {
262 qDebug("Url syntax 2error %s", host);
253 return (0); 263 return (0);
264 }
254 *request++ = 0; 265 *request++ = 0;
255 266
256 if (strchr(host, ':') != NULL) /* port is specified */ 267 if (strchr(host, ':') != NULL) /* port is specified */
257 { 268 {
258 port = atoi(strchr(host, ':') + 1); 269 port = atoi(strchr(host, ':') + 1);
259 *strchr(host, ':') = 0; 270 *strchr(host, ':') = 0;
260 } 271 }
261 272
262 /* Open a TCP socket */ 273 qDebug("Open a TCP socket");
263 if (!(tcp_sock = tcp_open(host, port))) 274 if (!(tcp_sock = tcp_open(host, port))) {
264 {
265 perror("http_open"); 275 perror("http_open");
276 errorMsg="http_open "+(QString)strerror(errno);
277 QMessageBox::message("OPiePlayer",errorMsg);
266 return (0); 278 return (0);
267 } 279 }
268 280
269 snprintf(filename, sizeof(filename) - strlen(host) - 75, "%s", request); 281 snprintf(filename, sizeof(filename) - strlen(host) - 75, "%s", request);
270 282
271 /* Send HTTP GET request */ 283 /* Send HTTP GET request */
272 /* Please don't use a Agent know by shoutcast (Lynx, Mozilla) seems to be reconized and print 284 /* Please don't use a Agent know by shoutcast (Lynx, Mozilla) seems to be reconized and print
273 * a html page and not the stream */ 285 * a html page and not the stream */
274 snprintf(http_request, sizeof(http_request), "GET /%s HTTP/1.0\r\n" 286 snprintf(http_request, sizeof(http_request), "GET /%s HTTP/1.0\r\n"
275/* "User-Agent: Mozilla/2.0 (Win95; I)\r\n" */ 287/* "User-Agent: Mozilla/2.0 (Win95; I)\r\n" */
276 "Pragma: no-cache\r\n" "Host: %s\r\n" "Accept: */*\r\n" "\r\n", filename, host); 288 "Pragma: no-cache\r\n" "Host: %s\r\n" "Accept: */*\r\n" "\r\n", filename, host);
277 289 qDebug("send");
278 send(tcp_sock, http_request, strlen(http_request), 0); 290 send(tcp_sock, http_request, strlen(http_request), 0);
279 291
280 /* Parse server reply */ 292 qDebug("Parse server reply");
281#if 0 293#if 0
294 qDebug("do 0");
282 do 295 do
283 read(tcp_sock, &c, sizeof(char)); 296 read(tcp_sock, &c, sizeof(char));
284 while (c != ' '); 297 while (c != ' ');
285 read(tcp_sock, http_request, 4 * sizeof(char)); 298 read(tcp_sock, http_request, 4 * sizeof(char));
286 http_request[4] = 0; 299 http_request[4] = 0;
287 if (strcmp(http_request, "200 ")) 300 if (strcmp(http_request, "200 "))
@@ -309,23 +322,23 @@ int LibMadPlugin::http_open(const QString& path ) {
309 fprintf(stderr, "http_open: %s\n", strerror(errno)); 322 fprintf(stderr, "http_open: %s\n", strerror(errno));
310 return 0; 323 return 0;
311 } 324 }
312 325
313 if (strncmp(http_request, "Location:", 9) == 0) 326 if (strncmp(http_request, "Location:", 9) == 0)
314 { 327 {
315 /* redirect */ 328 qDebug("redirect");
316 std::close(tcp_sock); 329 std::close(tcp_sock);
317 330
318 http_request[strlen(http_request) - 1] = '\0'; 331 http_request[strlen(http_request) - 1] = '\0';
319 332
320 return http_open(&http_request[10]); 333 return http_open(&http_request[10]);
321 } 334 }
322 335
323 if (strncmp(http_request, "ICY ", 4) == 0) 336 if (strncmp(http_request, "ICY ", 4) == 0)
324 { 337 {
325 /* This is icecast streaming */ 338 qDebug(" This is icecast streaming");
326 if (strncmp(http_request + 4, "200 ", 4)) 339 if (strncmp(http_request + 4, "200 ", 4))
327 { 340 {
328 fprintf(stderr, "http_open: %s\n", http_request); 341 fprintf(stderr, "http_open: %s\n", http_request);
329 return 0; 342 return 0;
330 } 343 }
331 } 344 }
@@ -349,28 +362,35 @@ bool LibMadPlugin::open( const QString& path ) {
349 bufferSize = cfg.readNumEntry("MPeg_BufferSize",MPEG_BUFFER_SIZE); 362 bufferSize = cfg.readNumEntry("MPeg_BufferSize",MPEG_BUFFER_SIZE);
350 qDebug("buffer size is %d", bufferSize); 363 qDebug("buffer size is %d", bufferSize);
351 d->bad_last_frame = 0; 364 d->bad_last_frame = 0;
352 d->flush = TRUE; 365 d->flush = TRUE;
353 info = QString( "" ); 366 info = QString( "" );
354 367
355 //qDebug( "Opening %s", path.latin1() ); 368 qDebug( "Opening %s", path.latin1() );
356
357 369
370 bool isStream=FALSE;
358 if (path.left( 4 ) == "http" ) { 371 if (path.left( 4 ) == "http" ) {
359 d->input.fd = http_open(path); 372 d->input.fd = http_open(path);
373 if(d->input.fd == 0) {
374 qDebug("http_open error");
375 }
376 isStream=TRUE;
377 qDebug("Opened ok");
360 378
361 } else { 379 } else {
362 d->input.path = path.latin1(); 380 d->input.path = path.latin1();
363 d->input.fd = ::open( d->input.path, O_RDONLY ); 381 d->input.fd = ::open( d->input.path, O_RDONLY );
364 } 382 }
365 if (d->input.fd == -1) { 383 if (d->input.fd == -1) {
366 qDebug("error opening %s", d->input.path ); 384 qDebug("error opening %s", d->input.path );
367 return FALSE; 385 return FALSE;
368 } 386 }
369 387 if(!isStream) {
388 qDebug("Print ID#tags");
370 printID3Tags(); 389 printID3Tags();
390 }
371 391
372#if defined(HAVE_MMAP) 392#if defined(HAVE_MMAP)
373 struct stat stat; 393 struct stat stat;
374 if (fstat(d->input.fd, &stat) == -1) { 394 if (fstat(d->input.fd, &stat) == -1) {
375 qDebug("error calling fstat"); return FALSE; 395 qDebug("error calling fstat"); return FALSE;
376 } 396 }
@@ -392,14 +412,17 @@ bool LibMadPlugin::open( const QString& path ) {
392 } 412 }
393 d->input.length = 0; 413 d->input.length = 0;
394 } 414 }
395 415
396 d->input.eof = 0; 416 d->input.eof = 0;
397 417
418qDebug("about to mad_stream");
398 mad_stream_init(&d->stream); 419 mad_stream_init(&d->stream);
420qDebug("mad_frame");
399 mad_frame_init(&d->frame); 421 mad_frame_init(&d->frame);
422qDebug("mad_synth");
400 mad_synth_init(&d->synth); 423 mad_synth_init(&d->synth);
401 424
402 return TRUE; 425 return TRUE;
403} 426}
404 427
405 428