annotate stream/pnm.c @ 35005:b1a1dcae9760

Replace MESA YCBCR support by the Apple variant. This adds hardware support for yuy2 and uyvy color formats when running on OSX. In addition add some hacks to make it fast (at least on PPC Mac Mini running OSX 10.5), ca. 20% faster than -vo corevideo. The MESA YCBCR variant never worked properly and has become even more broken and thus been disabled in most maintained drivers and thus is really a dead-end.
author reimar
date Sat, 18 Aug 2012 15:54:34 +0000
parents a93891202051
children 7505733df2b4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
1 /*
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
2 * Copyright (C) 2000-2002 the xine project
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
3 *
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
4 * This file is part of xine, a free video player.
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
5 *
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
6 * xine is free software; you can redistribute it and/or modify
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
9 * (at your option) any later version.
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
10 *
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
11 * xine is distributed in the hope that it will be useful,
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
14 * GNU General Public License for more details.
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
15 *
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
19614
36589811e5d0 The FSF changed postal address.
diego
parents: 19335
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
19 *
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
20 * $Id$
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
21 *
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
22 * pnm protocol implementation
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
23 * based upon code from joschka
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
24 */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
25
15614
a4a46131ee71 Change header order to avoid compile error because of STREAM_SEEK
reimar
parents: 15585
diff changeset
26 #include "config.h"
a4a46131ee71 Change header order to avoid compile error because of STREAM_SEEK
reimar
parents: 15585
diff changeset
27
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
28 #include <unistd.h>
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
29 #include <stdio.h>
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
30 #include <assert.h>
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
31 #include <string.h>
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
32 #include <sys/stat.h>
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
33 #include <fcntl.h>
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
34 #include <errno.h>
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
35 #include <stdlib.h>
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
36 #include <sys/time.h>
8584
2d4328af7ea9 prefer inttypes.h (probably fix cygwin compile)
arpi
parents: 8570
diff changeset
37 #include <inttypes.h>
28402
c884d17bd005 Convert HAVE_WINSOCK2_H into a 0/1 definition.
diego
parents: 27473
diff changeset
38 #if !HAVE_WINSOCK2_H
27472
c0b233cd30ca Revert moving closesocket definition and network headers to network.h.
diego
parents: 27464
diff changeset
39 #include <sys/socket.h>
c0b233cd30ca Revert moving closesocket definition and network headers to network.h.
diego
parents: 27464
diff changeset
40 //#include <netinet/in.h>
c0b233cd30ca Revert moving closesocket definition and network headers to network.h.
diego
parents: 27464
diff changeset
41 //#include <netdb.h>
c0b233cd30ca Revert moving closesocket definition and network headers to network.h.
diego
parents: 27464
diff changeset
42 #else
c0b233cd30ca Revert moving closesocket definition and network headers to network.h.
diego
parents: 27464
diff changeset
43 #include <winsock2.h>
c0b233cd30ca Revert moving closesocket definition and network headers to network.h.
diego
parents: 27464
diff changeset
44 #endif
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 10232
diff changeset
45
25697
43d2ca88edc1 Use AV_RB* instead of custom variants.
reimar
parents: 25696
diff changeset
46 #include "libavutil/intreadwrite.h"
34174
a93891202051 Add missing mp_msg.h #includes, remove some unnecessary ones.
diego
parents: 33346
diff changeset
47 #include "mp_msg.h"
15614
a4a46131ee71 Change header order to avoid compile error because of STREAM_SEEK
reimar
parents: 15585
diff changeset
48 #include "stream.h"
19312
ab8d6b6deb63 proper inclusion of demuxer.h (including libmpdemux in Makefile only was to make previous split easier)
ben
parents: 19271
diff changeset
49 #include "libmpdemux/demuxer.h"
15614
a4a46131ee71 Change header order to avoid compile error because of STREAM_SEEK
reimar
parents: 15585
diff changeset
50 #include "help_mp.h"
17092
rathann
parents: 16372
diff changeset
51 #include "osdep/timer.h"
27473
ae5da477539e Move '#define closesocket close' preprocessor directive to a common place
diego
parents: 27472
diff changeset
52 #include "network.h"
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
53 #include "pnm.h"
19335
2a9d669e5ff6 isolated tcp socket code from network.c to a dedicated file
ben
parents: 19312
diff changeset
54 #include "tcp.h"
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
55 //#include "libreal/rmff.h"
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
56
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
57 #define FOURCC_TAG( ch0, ch1, ch2, ch3 ) \
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
58 (((long)(unsigned char)(ch3) ) | \
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
59 ( (long)(unsigned char)(ch2) << 8 ) | \
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
60 ( (long)(unsigned char)(ch1) << 16 ) | \
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
61 ( (long)(unsigned char)(ch0) << 24 ) )
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
62
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
63
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
64 #define RMF_TAG FOURCC_TAG('.', 'R', 'M', 'F')
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
65 #define PROP_TAG FOURCC_TAG('P', 'R', 'O', 'P')
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
66 #define MDPR_TAG FOURCC_TAG('M', 'D', 'P', 'R')
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
67 #define CONT_TAG FOURCC_TAG('C', 'O', 'N', 'T')
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
68 #define DATA_TAG FOURCC_TAG('D', 'A', 'T', 'A')
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
69 #define INDX_TAG FOURCC_TAG('I', 'N', 'D', 'X')
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
70 #define PNA_TAG FOURCC_TAG('P', 'N', 'A', 0 )
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
71
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
72 /*
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
73 #define LOG
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
74 */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
75
8880
e44d2ac094e8 buffer overflow fix :)
arpi
parents: 8852
diff changeset
76 #define BUF_SIZE 4096
e44d2ac094e8 buffer overflow fix :)
arpi
parents: 8852
diff changeset
77 #define HEADER_SIZE 4096
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
78
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
79 struct pnm_s {
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
80
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
81 int s;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
82
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
83 // char *host;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
84 // int port;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
85 char *path;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
86 // char *url;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
87
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
88 char buffer[BUF_SIZE]; /* scratch buffer */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
89
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
90 /* receive buffer */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
91 uint8_t recv[BUF_SIZE];
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
92 int recv_size;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
93 int recv_read;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
94
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
95 uint8_t header[HEADER_SIZE];
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
96 int header_len;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
97 int header_read;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
98 unsigned int seq_num[4]; /* two streams with two indices */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
99 unsigned int seq_current[2]; /* seqs of last stream chunk read */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
100 uint32_t ts_current; /* timestamp of current chunk */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
101 uint32_t ts_last[2]; /* timestamps of last chunks */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
102 unsigned int packet; /* number of last recieved packet */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
103 };
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
104
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
105 /* sizes */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
106 #define PREAMBLE_SIZE 8
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
107 #define CHECKSUM_SIZE 3
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
108
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
109
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
110 /* header of rm files */
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
111 static const unsigned char rm_header[]={
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
112 0x2e, 0x52, 0x4d, 0x46, /* object_id ".RMF" */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
113 0x00, 0x00, 0x00, 0x12, /* header_size 0x12 */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
114 0x00, 0x00, /* object_version 0x00 */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
115 0x00, 0x00, 0x00, 0x00, /* file_version 0x00 */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
116 0x00, 0x00, 0x00, 0x06 /* num_headers 0x06 */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
117 };
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
118
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
119 /* data chunk header */
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
120 static const unsigned char pnm_data_header[]={
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
121 'D','A','T','A',
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
122 0,0,0,0, /* data chunk size */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
123 0,0, /* object version */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
124 0,0,0,0, /* num packets */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
125 0,0,0,0}; /* next data header */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
126
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
127 /* pnm request chunk ids */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
128
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
129 #define PNA_CLIENT_CAPS 0x03
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
130 #define PNA_CLIENT_CHALLANGE 0x04
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
131 #define PNA_BANDWIDTH 0x05
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
132 #define PNA_GUID 0x13
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
133 #define PNA_TIMESTAMP 0x17
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
134 #define PNA_TWENTYFOUR 0x18
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
135
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
136 #define PNA_CLIENT_STRING 0x63
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
137 #define PNA_PATH_REQUEST 0x52
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
138
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
139 static const unsigned char pnm_challenge[] = "0990f6b4508b51e801bd6da011ad7b56";
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
140 static const unsigned char pnm_timestamp[] = "[15/06/1999:22:22:49 00:00]";
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
141 static const unsigned char pnm_guid[] = "3eac2411-83d5-11d2-f3ea-d7c3a51aa8b0";
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
142 static const unsigned char pnm_response[] = "97715a899cbe41cee00dd434851535bf";
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
143 static const unsigned char client_string[] = "WinNT_9.0_6.0.6.45_plus32_MP60_en-US_686l";
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
144
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
145 static const unsigned char pnm_header[] = {
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
146 'P','N','A',
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
147 0x00, 0x0a,
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
148 0x00, 0x14,
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
149 0x00, 0x02,
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
150 0x00, 0x01 };
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
151
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
152 static const unsigned char pnm_client_caps[] = {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
153 0x07, 0x8a, 'p','n','r','v',
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
154 0, 0x90, 'p','n','r','v',
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
155 0, 0x64, 'd','n','e','t',
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
156 0, 0x46, 'p','n','r','v',
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
157 0, 0x32, 'd','n','e','t',
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
158 0, 0x2b, 'p','n','r','v',
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
159 0, 0x28, 'd','n','e','t',
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
160 0, 0x24, 'p','n','r','v',
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
161 0, 0x19, 'd','n','e','t',
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
162 0, 0x18, 'p','n','r','v',
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
163 0, 0x14, 's','i','p','r',
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
164 0, 0x14, 'd','n','e','t',
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
165 0, 0x24, '2','8','_','8',
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
166 0, 0x12, 'p','n','r','v',
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
167 0, 0x0f, 'd','n','e','t',
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
168 0, 0x0a, 's','i','p','r',
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
169 0, 0x0a, 'd','n','e','t',
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
170 0, 0x08, 's','i','p','r',
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
171 0, 0x06, 's','i','p','r',
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
172 0, 0x12, 'l','p','c','J',
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
173 0, 0x07, '0','5','_','6' };
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
174
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
175 static const uint32_t pnm_default_bandwidth=10485800;
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
176 static const uint32_t pnm_available_bandwidths[]={14400,19200,28800,33600,34430,57600,
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
177 115200,262200,393216,524300,1544000,10485800};
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
178
25695
33972bac0c16 Make some pnm data const
reimar
parents: 25211
diff changeset
179 static const unsigned char pnm_twentyfour[]={
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
180 0xd5, 0x42, 0xa3, 0x1b, 0xef, 0x1f, 0x70, 0x24,
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
181 0x85, 0x29, 0xb3, 0x8d, 0xba, 0x11, 0xf3, 0xd6 };
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
182
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
183 /* now other data follows. marked with 0x0000 at the beginning */
25695
33972bac0c16 Make some pnm data const
reimar
parents: 25211
diff changeset
184 static const unsigned char after_chunks[]={
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
185 0x00, 0x00, /* mark */
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
186
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
187 0x50, 0x84, /* seems to be fixated */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
188 0x1f, 0x3a /* varies on each request (checksum ?)*/
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
189 };
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
190
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
191 static void hexdump (char *buf, int length);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
192
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
193 static int rm_write(int s, const char *buf, int len) {
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
194 int total, timeout;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
195
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
196 total = 0; timeout = 30;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
197 while (total < len){
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
198 int n;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
199
10206
35e306346e59 Using recv/send instead read/write for proper MinGW support (it's a 4.2BSD standard). Patch by FloDt <flodt8@yahoo.de>
alex
parents: 8880
diff changeset
200 n = send (s, &buf[total], len - total, 0);
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
201
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
202 if (n > 0)
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
203 total += n;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
204 else if (n < 0) {
28402
c884d17bd005 Convert HAVE_WINSOCK2_H into a 0/1 definition.
diego
parents: 27473
diff changeset
205 #if !HAVE_WINSOCK2_H
25700
5ac12852a918 Remove some useless () and {}
reimar
parents: 25699
diff changeset
206 if (timeout>0 && (errno == EAGAIN || errno == EINPROGRESS)) {
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 10232
diff changeset
207 #else
25700
5ac12852a918 Remove some useless () and {}
reimar
parents: 25699
diff changeset
208 if (timeout>0 && (errno == EAGAIN || WSAGetLastError() == WSAEINPROGRESS)) {
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 10232
diff changeset
209 #endif
16372
b313a38c69cb replace sleep with usec_sleep, required for recent mingw versions, patch by Robert Swain <robert.swain at gmail.com>
faust3
parents: 15626
diff changeset
210 usec_sleep (1000000); timeout--;
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
211 } else
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
212 return -1;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
213 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
214 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
215
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
216 return total;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
217 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
218
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
219 static ssize_t rm_read(int fd, void *buf, size_t count) {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
220
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
221 ssize_t ret, total;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
222
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
223 total = 0;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
224
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
225 while (total < count) {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
226
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
227 fd_set rset;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
228 struct timeval timeout;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
229
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
230 FD_ZERO (&rset);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
231 FD_SET (fd, &rset);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
232
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
233 timeout.tv_sec = 3;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
234 timeout.tv_usec = 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
235
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
236 if (select (fd+1, &rset, NULL, NULL, &timeout) <= 0) {
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
237 return -1;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
238 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
239
10206
35e306346e59 Using recv/send instead read/write for proper MinGW support (it's a 4.2BSD standard). Patch by FloDt <flodt8@yahoo.de>
alex
parents: 8880
diff changeset
240 ret=recv (fd, ((uint8_t*)buf)+total, count-total, 0);
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
241
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
242 if (ret<=0) {
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
243 mp_msg(MSGT_OPEN, MSGL_ERR, "input_pnm: read error.\n");
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
244 return ret;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
245 } else
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
246 total += ret;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
247 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
248
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
249 return total;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
250 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
251
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
252 /*
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
253 * debugging utilities
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
254 */
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
255
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
256 static void hexdump (char *buf, int length) {
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
257
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
258 int i;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
259
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
260 mp_msg(MSGT_OPEN, MSGL_INFO, "input_pnm: ascii>");
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
261 for (i = 0; i < length; i++) {
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
262 unsigned char c = buf[i];
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
263
25700
5ac12852a918 Remove some useless () and {}
reimar
parents: 25699
diff changeset
264 if (c >= 32 && c <= 128)
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
265 mp_msg(MSGT_OPEN, MSGL_INFO, "%c", c);
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
266 else
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
267 mp_msg(MSGT_OPEN, MSGL_INFO, ".");
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
268 }
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
269 mp_msg(MSGT_OPEN, MSGL_INFO, "\n");
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
270
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
271 mp_msg(MSGT_OPEN, MSGL_INFO, "input_pnm: hexdump> ");
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
272 for (i = 0; i < length; i++) {
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
273 unsigned char c = buf[i];
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
274
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
275 mp_msg(MSGT_OPEN, MSGL_INFO, "%02x", c);
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
276
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
277 if ((i % 16) == 15)
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
278 mp_msg(MSGT_OPEN, MSGL_INFO, "\npnm: ");
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
279
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
280 if ((i % 2) == 1)
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
281 mp_msg(MSGT_OPEN, MSGL_INFO, " ");
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
282
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
283 }
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
284 mp_msg(MSGT_OPEN, MSGL_INFO, "\n");
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
285 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
286
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
287 /*
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
288 * pnm_get_chunk gets a chunk from stream
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
289 * and returns number of bytes read
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
290 */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
291
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
292 static int pnm_get_chunk(pnm_t *p,
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
293 unsigned int max,
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
294 unsigned int *chunk_type,
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
295 char *data, int *need_response) {
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
296
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
297 unsigned int chunk_size;
14164
5901a6392db3 Security fixes ported from upstream (xine)
rtognimp
parents: 11000
diff changeset
298 unsigned int n;
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
299 char *ptr;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
300
14164
5901a6392db3 Security fixes ported from upstream (xine)
rtognimp
parents: 11000
diff changeset
301 if (max < PREAMBLE_SIZE)
5901a6392db3 Security fixes ported from upstream (xine)
rtognimp
parents: 11000
diff changeset
302 return -1;
5901a6392db3 Security fixes ported from upstream (xine)
rtognimp
parents: 11000
diff changeset
303
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
304 /* get first PREAMBLE_SIZE bytes and ignore checksum */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
305 rm_read (p->s, data, CHECKSUM_SIZE);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
306 if (data[0] == 0x72)
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
307 rm_read (p->s, data, PREAMBLE_SIZE);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
308 else
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
309 rm_read (p->s, data+CHECKSUM_SIZE, PREAMBLE_SIZE-CHECKSUM_SIZE);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
310
14164
5901a6392db3 Security fixes ported from upstream (xine)
rtognimp
parents: 11000
diff changeset
311 max -= PREAMBLE_SIZE;
5901a6392db3 Security fixes ported from upstream (xine)
rtognimp
parents: 11000
diff changeset
312
25697
43d2ca88edc1 Use AV_RB* instead of custom variants.
reimar
parents: 25696
diff changeset
313 *chunk_type = AV_RB32(data);
43d2ca88edc1 Use AV_RB* instead of custom variants.
reimar
parents: 25696
diff changeset
314 chunk_size = AV_RB32(data+4);
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
315
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
316 switch (*chunk_type) {
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
317 case PNA_TAG:
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
318 *need_response=0;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
319 ptr=data+PREAMBLE_SIZE;
14164
5901a6392db3 Security fixes ported from upstream (xine)
rtognimp
parents: 11000
diff changeset
320 if (max < 1)
5901a6392db3 Security fixes ported from upstream (xine)
rtognimp
parents: 11000
diff changeset
321 return -1;
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
322 rm_read (p->s, ptr++, 1);
14164
5901a6392db3 Security fixes ported from upstream (xine)
rtognimp
parents: 11000
diff changeset
323 max -= 1;
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
324
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
325 while(1) {
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
326 /* expecting following chunk format: 0x4f <chunk size> <data...> */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
327
14164
5901a6392db3 Security fixes ported from upstream (xine)
rtognimp
parents: 11000
diff changeset
328 if (max < 2)
5901a6392db3 Security fixes ported from upstream (xine)
rtognimp
parents: 11000
diff changeset
329 return -1;
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
330 rm_read (p->s, ptr, 2);
14164
5901a6392db3 Security fixes ported from upstream (xine)
rtognimp
parents: 11000
diff changeset
331 max -= 2;
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
332 if (*ptr == 'X') /* checking for server message */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
333 {
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
334 mp_msg(MSGT_OPEN, MSGL_WARN, "input_pnm: got a message from server:\n");
14164
5901a6392db3 Security fixes ported from upstream (xine)
rtognimp
parents: 11000
diff changeset
335 if (max < 1)
5901a6392db3 Security fixes ported from upstream (xine)
rtognimp
parents: 11000
diff changeset
336 return -1;
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
337 rm_read (p->s, ptr+2, 1);
14164
5901a6392db3 Security fixes ported from upstream (xine)
rtognimp
parents: 11000
diff changeset
338 max = -1;
25697
43d2ca88edc1 Use AV_RB* instead of custom variants.
reimar
parents: 25696
diff changeset
339 n=AV_RB16(ptr+1);
14164
5901a6392db3 Security fixes ported from upstream (xine)
rtognimp
parents: 11000
diff changeset
340 if (max < n)
5901a6392db3 Security fixes ported from upstream (xine)
rtognimp
parents: 11000
diff changeset
341 return -1;
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
342 rm_read (p->s, ptr+3, n);
14164
5901a6392db3 Security fixes ported from upstream (xine)
rtognimp
parents: 11000
diff changeset
343 max -= n;
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
344 ptr[3+n]=0;
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
345 mp_msg(MSGT_OPEN, MSGL_WARN, "%s\n",ptr+3);
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
346 return -1;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
347 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
348
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
349 if (*ptr == 'F') /* checking for server error */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
350 {
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
351 mp_msg(MSGT_OPEN, MSGL_ERR, "input_pnm: server error.\n");
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
352 return -1;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
353 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
354 if (*ptr == 'i')
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
355 {
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
356 ptr+=2;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
357 *need_response=1;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
358 continue;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
359 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
360 if (*ptr != 0x4f) break;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
361 n=ptr[1];
14164
5901a6392db3 Security fixes ported from upstream (xine)
rtognimp
parents: 11000
diff changeset
362 if (max < n)
5901a6392db3 Security fixes ported from upstream (xine)
rtognimp
parents: 11000
diff changeset
363 return -1;
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
364 rm_read (p->s, ptr+2, n);
14164
5901a6392db3 Security fixes ported from upstream (xine)
rtognimp
parents: 11000
diff changeset
365 max -= n;
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
366 ptr+=(n+2);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
367 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
368 /* the checksum of the next chunk is ignored here */
14164
5901a6392db3 Security fixes ported from upstream (xine)
rtognimp
parents: 11000
diff changeset
369 if (max < 1)
5901a6392db3 Security fixes ported from upstream (xine)
rtognimp
parents: 11000
diff changeset
370 return -1;
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
371 rm_read (p->s, ptr+2, 1);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
372 ptr+=3;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
373 chunk_size=ptr-data;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
374 break;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
375 case RMF_TAG:
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
376 case DATA_TAG:
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
377 case PROP_TAG:
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
378 case MDPR_TAG:
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
379 case CONT_TAG:
14164
5901a6392db3 Security fixes ported from upstream (xine)
rtognimp
parents: 11000
diff changeset
380 if (chunk_size > max || chunk_size < PREAMBLE_SIZE) {
31834
64ba1daa147a various spelling fixes, found by the Debian QA tool 'lintian'
siretart
parents: 31427
diff changeset
381 mp_msg(MSGT_OPEN, MSGL_ERR, "error: max chunk size exceeded (max was 0x%04x)\n", max);
14164
5901a6392db3 Security fixes ported from upstream (xine)
rtognimp
parents: 11000
diff changeset
382 #ifdef LOG
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
383 n=rm_read (p->s, &data[PREAMBLE_SIZE], 0x100 - PREAMBLE_SIZE);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
384 hexdump(data,n+PREAMBLE_SIZE);
14164
5901a6392db3 Security fixes ported from upstream (xine)
rtognimp
parents: 11000
diff changeset
385 #endif
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
386 return -1;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
387 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
388 rm_read (p->s, &data[PREAMBLE_SIZE], chunk_size-PREAMBLE_SIZE);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
389 break;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
390 default:
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
391 *chunk_type = 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
392 chunk_size = PREAMBLE_SIZE;
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
393 break;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
394 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
395
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
396 return chunk_size;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
397 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
398
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
399 /*
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
400 * writes a chunk to a buffer, returns number of bytes written
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
401 */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
402
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
403 static int pnm_write_chunk(uint16_t chunk_id, uint16_t length,
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
404 const char *chunk, char *data) {
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
405
25701
d3943c815424 Use AV_WB*
reimar
parents: 25700
diff changeset
406 AV_WB16(&data[0], chunk_id);
d3943c815424 Use AV_WB*
reimar
parents: 25700
diff changeset
407 AV_WB16(&data[2], length);
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
408 memcpy(&data[4],chunk,length);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
409
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
410 return length+4;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
411 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
412
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
413 /*
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
414 * constructs a request and sends it
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
415 */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
416
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
417 static void pnm_send_request(pnm_t *p, uint32_t bandwidth) {
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
418
25696
f159db1e77db Use sizeof instead of size variables/defines
reimar
parents: 25695
diff changeset
419 int c=sizeof(pnm_header);
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
420 char fixme[]={0,1};
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
421
25696
f159db1e77db Use sizeof instead of size variables/defines
reimar
parents: 25695
diff changeset
422 memcpy(p->buffer,pnm_header,sizeof(pnm_header));
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
423 c+=pnm_write_chunk(PNA_CLIENT_CHALLANGE,strlen(pnm_challenge),
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
424 pnm_challenge,&p->buffer[c]);
25696
f159db1e77db Use sizeof instead of size variables/defines
reimar
parents: 25695
diff changeset
425 c+=pnm_write_chunk(PNA_CLIENT_CAPS,sizeof(pnm_client_caps),
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
426 pnm_client_caps,&p->buffer[c]);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
427 c+=pnm_write_chunk(0x0a,0,NULL,&p->buffer[c]);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
428 c+=pnm_write_chunk(0x0c,0,NULL,&p->buffer[c]);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
429 c+=pnm_write_chunk(0x0d,0,NULL,&p->buffer[c]);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
430 c+=pnm_write_chunk(0x16,2,fixme,&p->buffer[c]);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
431 c+=pnm_write_chunk(PNA_TIMESTAMP,strlen(pnm_timestamp),
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
432 pnm_timestamp,&p->buffer[c]);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
433 c+=pnm_write_chunk(PNA_BANDWIDTH,4,
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
434 (const char *)&pnm_default_bandwidth,&p->buffer[c]);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
435 c+=pnm_write_chunk(0x08,0,NULL,&p->buffer[c]);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
436 c+=pnm_write_chunk(0x0e,0,NULL,&p->buffer[c]);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
437 c+=pnm_write_chunk(0x0f,0,NULL,&p->buffer[c]);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
438 c+=pnm_write_chunk(0x11,0,NULL,&p->buffer[c]);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
439 c+=pnm_write_chunk(0x10,0,NULL,&p->buffer[c]);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
440 c+=pnm_write_chunk(0x15,0,NULL,&p->buffer[c]);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
441 c+=pnm_write_chunk(0x12,0,NULL,&p->buffer[c]);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
442 c+=pnm_write_chunk(PNA_GUID,strlen(pnm_guid),
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
443 pnm_guid,&p->buffer[c]);
25696
f159db1e77db Use sizeof instead of size variables/defines
reimar
parents: 25695
diff changeset
444 c+=pnm_write_chunk(PNA_TWENTYFOUR,sizeof(pnm_twentyfour),
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
445 pnm_twentyfour,&p->buffer[c]);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
446
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
447 /* data after chunks */
25696
f159db1e77db Use sizeof instead of size variables/defines
reimar
parents: 25695
diff changeset
448 memcpy(&p->buffer[c],after_chunks,sizeof(after_chunks));
f159db1e77db Use sizeof instead of size variables/defines
reimar
parents: 25695
diff changeset
449 c+=sizeof(after_chunks);
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
450
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
451 /* client id string */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
452 p->buffer[c]=PNA_CLIENT_STRING;
25698
6fe76fc5d7fa Use AV_WB16 instead of ugly memcpy hacks
reimar
parents: 25697
diff changeset
453 AV_WB16(&p->buffer[c+1], strlen(client_string)-1); /* don't know why do we have -1 here */
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
454 memcpy(&p->buffer[c+3],client_string,strlen(client_string)+1);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
455 c=c+3+strlen(client_string)+1;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
456
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
457 /* file path */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
458 p->buffer[c]=0;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
459 p->buffer[c+1]=PNA_PATH_REQUEST;
25698
6fe76fc5d7fa Use AV_WB16 instead of ugly memcpy hacks
reimar
parents: 25697
diff changeset
460 AV_WB16(&p->buffer[c+2], strlen(p->path));
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
461 memcpy(&p->buffer[c+4],p->path,strlen(p->path));
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
462 c=c+4+strlen(p->path);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
463
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
464 /* some trailing bytes */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
465 p->buffer[c]='y';
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
466 p->buffer[c+1]='B';
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
467
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
468 rm_write(p->s,p->buffer,c+2);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
469 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
470
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
471 /*
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
472 * pnm_send_response sends a response of a challenge
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
473 */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
474
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
475 static void pnm_send_response(pnm_t *p, const char *response) {
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
476
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
477 int size=strlen(response);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
478
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
479 p->buffer[0]=0x23;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
480 p->buffer[1]=0;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
481 p->buffer[2]=(unsigned char) size;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
482
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
483 memcpy(&p->buffer[3], response, size);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
484
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
485 rm_write (p->s, p->buffer, size+3);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
486
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
487 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
488
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
489 /*
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
490 * get headers and challenge and fix headers
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
491 * write headers to p->header
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
492 * write challenge to p->buffer
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
493 *
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
494 * return 0 on error. != 0 on success
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
495 */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
496
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
497 static int pnm_get_headers(pnm_t *p, int *need_response) {
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
498
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
499 uint32_t chunk_type;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
500 uint8_t *ptr=p->header;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
501 uint8_t *prop_hdr=NULL;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
502 int chunk_size,size=0;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
503 int nr;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
504 /* rmff_header_t *h; */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
505
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
506 *need_response=0;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
507
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
508 while(1) {
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
509 if (HEADER_SIZE-size<=0)
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
510 {
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
511 mp_msg(MSGT_OPEN, MSGL_ERR, "input_pnm: header buffer overflow. exiting\n");
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
512 return 0;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
513 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
514 chunk_size=pnm_get_chunk(p,HEADER_SIZE-size,&chunk_type,ptr,&nr);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
515 if (chunk_size < 0) return 0;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
516 if (chunk_type == 0) break;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
517 if (chunk_type == PNA_TAG)
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
518 {
25696
f159db1e77db Use sizeof instead of size variables/defines
reimar
parents: 25695
diff changeset
519 memcpy(ptr, rm_header, sizeof(rm_header));
f159db1e77db Use sizeof instead of size variables/defines
reimar
parents: 25695
diff changeset
520 chunk_size=sizeof(rm_header);
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
521 *need_response=nr;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
522 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
523 if (chunk_type == DATA_TAG)
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
524 chunk_size=0;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
525 if (chunk_type == RMF_TAG)
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
526 chunk_size=0;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
527 if (chunk_type == PROP_TAG)
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
528 prop_hdr=ptr;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
529 size+=chunk_size;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
530 ptr+=chunk_size;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
531 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
532
8852
668cc9e77d2d check if prop_hdr==NULL insteda of sig11
arpi
parents: 8584
diff changeset
533 if (!prop_hdr) {
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
534 mp_msg(MSGT_OPEN, MSGL_ERR, "input_pnm: error while parsing headers.\n");
8852
668cc9e77d2d check if prop_hdr==NULL insteda of sig11
arpi
parents: 8584
diff changeset
535 return 0;
668cc9e77d2d check if prop_hdr==NULL insteda of sig11
arpi
parents: 8584
diff changeset
536 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
537
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
538 /* set data offset */
25701
d3943c815424 Use AV_WB*
reimar
parents: 25700
diff changeset
539 AV_WB32(&prop_hdr[42], size - 1);
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
540
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
541 /* read challenge */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
542 memcpy (p->buffer, ptr, PREAMBLE_SIZE);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
543 rm_read (p->s, &p->buffer[PREAMBLE_SIZE], 64);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
544
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
545 /* now write a data header */
25696
f159db1e77db Use sizeof instead of size variables/defines
reimar
parents: 25695
diff changeset
546 memcpy(ptr, pnm_data_header, sizeof(pnm_data_header));
f159db1e77db Use sizeof instead of size variables/defines
reimar
parents: 25695
diff changeset
547 size+=sizeof(pnm_data_header);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
548 /*
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
549 h=rmff_scan_header(p->header);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
550 rmff_fix_header(h);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
551 p->header_len=rmff_get_header_size(h);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
552 rmff_dump_header(h, p->header, HEADER_SIZE);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
553 */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
554 p->header_len=size;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
555
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
556 return 1;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
557 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
558
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
559 /*
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
560 * determine correct stream number by looking at indices
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
561 */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
562
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
563 static int pnm_calc_stream(pnm_t *p) {
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
564
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
565 char str0=0,str1=0;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
566
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
567 /* looking at the first index to
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
568 * find possible stream types
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
569 */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
570 if (p->seq_current[0]==p->seq_num[0]) str0=1;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
571 if (p->seq_current[0]==p->seq_num[2]) str1=1;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
572
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
573 switch (str0+str1) {
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
574 case 1: /* one is possible, good. */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
575 if (str0)
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
576 {
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
577 p->seq_num[0]++;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
578 p->seq_num[1]=p->seq_current[1]+1;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
579 return 0;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
580 } else
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
581 {
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
582 p->seq_num[2]++;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
583 p->seq_num[3]=p->seq_current[1]+1;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
584 return 1;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
585 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
586 break;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
587 case 0:
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
588 case 2: /* both types or none possible, not so good */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
589 /* try to figure out by second index */
25700
5ac12852a918 Remove some useless () and {}
reimar
parents: 25699
diff changeset
590 if ( p->seq_current[1] == p->seq_num[1]
5ac12852a918 Remove some useless () and {}
reimar
parents: 25699
diff changeset
591 && p->seq_current[1] != p->seq_num[3])
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
592 {
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
593 /* ok, only stream0 matches */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
594 p->seq_num[0]=p->seq_current[0]+1;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
595 p->seq_num[1]++;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
596 return 0;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
597 }
25700
5ac12852a918 Remove some useless () and {}
reimar
parents: 25699
diff changeset
598 if ( p->seq_current[1] == p->seq_num[3]
5ac12852a918 Remove some useless () and {}
reimar
parents: 25699
diff changeset
599 && p->seq_current[1] != p->seq_num[1])
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
600 {
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
601 /* ok, only stream1 matches */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
602 p->seq_num[2]=p->seq_current[0]+1;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
603 p->seq_num[3]++;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
604 return 1;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
605 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
606 /* wow, both streams match, or not. */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
607 /* now we try to decide by timestamps */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
608 if (p->ts_current < p->ts_last[1])
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
609 return 0;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
610 if (p->ts_current < p->ts_last[0])
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
611 return 1;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
612 /* does not help, we guess type 0 */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
613 #ifdef LOG
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
614 mp_msg(MSGT_OPEN, MSGL_INFO, "guessing stream# 0\n");
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
615 #endif
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
616 p->seq_num[0]=p->seq_current[0]+1;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
617 p->seq_num[1]=p->seq_current[1]+1;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
618 return 0;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
619 break;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
620 }
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
621 mp_msg(MSGT_OPEN, MSGL_ERR, "input_pnm: wow, something very nasty happened in pnm_calc_stream\n");
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
622 return 2;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
623 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
624
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
625 /*
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
626 * gets a stream chunk and writes it to a recieve buffer
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
627 */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
628
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
629 static int pnm_get_stream_chunk(pnm_t *p) {
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
630
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
631 int n;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
632 char keepalive='!';
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
633 unsigned int fof1, fof2, stream;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
634
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
635 /* send a keepalive */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
636 /* realplayer seems to do that every 43th package */
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
637 if (p->packet%43 == 42)
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
638 rm_write(p->s,&keepalive,1);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
639
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
640 /* data chunks begin with: 'Z' <o> <o> <i1> 'Z' <i2>
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
641 * where <o> is the offset to next stream chunk,
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
642 * <i1> is a 16 bit index
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
643 * <i2> is a 8 bit index which counts from 0x10 to somewhere
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
644 */
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
645
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
646 n = rm_read (p->s, p->buffer, 8);
15077
a893e0bfa9d6 "Fix" for pnm EOF detection (stop on read errors)
rtognimp
parents: 15076
diff changeset
647 if (n<0) return -1;
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
648 if (n<8) return 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
649
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
650 /* skip 8 bytes if 0x62 is read */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
651 if (p->buffer[0] == 0x62)
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
652 {
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
653 n = rm_read (p->s, p->buffer, 8);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
654 if (n<8) return 0;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
655 #ifdef LOG
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
656 mp_msg(MSGT_OPEN, MSGL_WARN, "input_pnm: had to seek 8 bytes on 0x62\n");
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
657 #endif
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
658 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
659
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
660 /* a server message */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
661 if (p->buffer[0] == 'X')
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
662 {
25697
43d2ca88edc1 Use AV_RB* instead of custom variants.
reimar
parents: 25696
diff changeset
663 int size=AV_RB16(&p->buffer[1]);
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
664
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
665 rm_read (p->s, &p->buffer[8], size-5);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
666 p->buffer[size+3]=0;
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
667 mp_msg(MSGT_OPEN, MSGL_WARN, "input_pnm: got message from server while reading stream:\n%s\n", &p->buffer[3]);
15076
1a02a23202c2 Stop streaming if we got a server error or message on pnm streaming.
rtognimp
parents: 14164
diff changeset
668 return -1;
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
669 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
670 if (p->buffer[0] == 'F')
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
671 {
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
672 mp_msg(MSGT_OPEN, MSGL_ERR, "input_pnm: server error.\n");
15076
1a02a23202c2 Stop streaming if we got a server error or message on pnm streaming.
rtognimp
parents: 14164
diff changeset
673 return -1;
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
674 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
675
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
676 /* skip bytewise to next chunk.
11000
6e35326c742f many small typo and grammar fixes
gabucino
parents: 10350
diff changeset
677 * seems, that we don't need that, if we send enough
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
678 * keepalives
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
679 */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
680 n=0;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
681 while (p->buffer[0] != 0x5a) {
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
682 int i;
25700
5ac12852a918 Remove some useless () and {}
reimar
parents: 25699
diff changeset
683 for (i=1; i<8; i++)
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
684 p->buffer[i-1]=p->buffer[i];
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
685 rm_read (p->s, &p->buffer[7], 1);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
686 n++;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
687 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
688
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
689 #ifdef LOG
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
690 if (n) mp_msg(MSGT_OPEN, MSGL_WARN, "input_pnm: had to seek %i bytes to next chunk\n", n);
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
691 #endif
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
692
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
693 /* check for 'Z's */
25700
5ac12852a918 Remove some useless () and {}
reimar
parents: 25699
diff changeset
694 if (p->buffer[0] != 0x5a || p->buffer[7] != 0x5a)
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
695 {
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
696 mp_msg(MSGT_OPEN, MSGL_ERR, "input_pnm: bad boundaries\n");
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
697 hexdump(p->buffer, 8);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
698 return 0;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
699 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
700
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
701 /* check offsets */
25697
43d2ca88edc1 Use AV_RB* instead of custom variants.
reimar
parents: 25696
diff changeset
702 fof1=AV_RB16(&p->buffer[1]);
43d2ca88edc1 Use AV_RB* instead of custom variants.
reimar
parents: 25696
diff changeset
703 fof2=AV_RB16(&p->buffer[3]);
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
704 if (fof1 != fof2)
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
705 {
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
706 mp_msg(MSGT_OPEN, MSGL_ERR, "input_pnm: frame offsets are different: 0x%04x 0x%04x\n",fof1,fof2);
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
707 return 0;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
708 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
709
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
710 /* get first index */
25697
43d2ca88edc1 Use AV_RB* instead of custom variants.
reimar
parents: 25696
diff changeset
711 p->seq_current[0]=AV_RB16(&p->buffer[5]);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
712
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
713 /* now read the rest of stream chunk */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
714 n = rm_read (p->s, &p->recv[5], fof1-5);
25700
5ac12852a918 Remove some useless () and {}
reimar
parents: 25699
diff changeset
715 if (n<fof1-5) return 0;
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
716
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
717 /* get second index */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
718 p->seq_current[1]=p->recv[5];
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
719
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
720 /* get timestamp */
25697
43d2ca88edc1 Use AV_RB* instead of custom variants.
reimar
parents: 25696
diff changeset
721 p->ts_current=AV_RB32(&p->recv[6]);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
722
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
723 /* get stream number */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
724 stream=pnm_calc_stream(p);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
725
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
726 /* saving timestamp */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
727 p->ts_last[stream]=p->ts_current;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
728
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
729 /* constructing a data packet header */
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
730
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
731 p->recv[0]=0; /* object version */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
732 p->recv[1]=0;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
733
25698
6fe76fc5d7fa Use AV_WB16 instead of ugly memcpy hacks
reimar
parents: 25697
diff changeset
734 AV_WB16(&p->recv[2], fof2); /* length */
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
735
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
736 p->recv[4]=0; /* stream number */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
737 p->recv[5]=stream;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
738
25699
b5854f719081 Simplify
reimar
parents: 25698
diff changeset
739 p->recv[10] &= 0xfe; /* streambox seems to do that... */
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
740
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
741 p->packet++;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
742
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
743 p->recv_size=fof1;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
744
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
745 return fof1;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
746 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
747
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
748 // pnm_t *pnm_connect(const char *mrl) {
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
749 static pnm_t *pnm_connect(int fd, char *path) {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
750
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
751 pnm_t *p=malloc(sizeof(pnm_t));
8852
668cc9e77d2d check if prop_hdr==NULL insteda of sig11
arpi
parents: 8584
diff changeset
752 int need_response=0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
753
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
754 p->path=strdup(path);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
755 p->s=fd;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
756
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
757 pnm_send_request(p,pnm_available_bandwidths[10]);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
758 if (!pnm_get_headers(p, &need_response)) {
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
759 mp_msg(MSGT_OPEN, MSGL_ERR, "input_pnm: failed to set up stream\n");
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
760 free(p->path);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
761 free(p);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
762 return NULL;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
763 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
764 if (need_response)
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
765 pnm_send_response(p, pnm_response);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
766 p->ts_last[0]=0;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
767 p->ts_last[1]=0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
768
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
769 /* copy header to recv */
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
770
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
771 memcpy(p->recv, p->header, p->header_len);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
772 p->recv_size = p->header_len;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
773 p->recv_read = 0;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
774
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
775 return p;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
776 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
777
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
778 static int pnm_read (pnm_t *this, char *data, int len) {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
779
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
780 int to_copy=len;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
781 char *dest=data;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
782 char *source=this->recv + this->recv_read;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
783 int fill=this->recv_size - this->recv_read;
15076
1a02a23202c2 Stop streaming if we got a server error or message on pnm streaming.
rtognimp
parents: 14164
diff changeset
784 int retval;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
785
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
786 if (len < 0) return 0;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
787 while (to_copy > fill) {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
788
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
789 memcpy(dest, source, fill);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
790 to_copy -= fill;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
791 dest += fill;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
792 this->recv_read=0;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
793
15076
1a02a23202c2 Stop streaming if we got a server error or message on pnm streaming.
rtognimp
parents: 14164
diff changeset
794 if ((retval = pnm_get_stream_chunk (this)) <= 0) {
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
795 #ifdef LOG
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15614
diff changeset
796 mp_msg(MSGT_OPEN, MSGL_INFO, "input_pnm: %d of %d bytes provided\n", len-to_copy, len);
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
797 #endif
15076
1a02a23202c2 Stop streaming if we got a server error or message on pnm streaming.
rtognimp
parents: 14164
diff changeset
798 if (retval < 0)
1a02a23202c2 Stop streaming if we got a server error or message on pnm streaming.
rtognimp
parents: 14164
diff changeset
799 return retval;
1a02a23202c2 Stop streaming if we got a server error or message on pnm streaming.
rtognimp
parents: 14164
diff changeset
800 else
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
801 return len-to_copy;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
802 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
803 source = this->recv;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
804 fill = this->recv_size - this->recv_read;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
805 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
806
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
807 memcpy(dest, source, to_copy);
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
808 this->recv_read += to_copy;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
809
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
810 #ifdef LOG
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
811 mp_msg(MSGT_OPEN, MSGL_INFO, "input_pnm: %d bytes provided\n", len);
8570
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
812 #endif
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
813
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
814 return len;
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
815 }
16af93c01dbf pnm:// support (ported from xine)
arpi
parents:
diff changeset
816
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
817 static int pnm_streaming_read( int fd, char *buffer, int size, streaming_ctrl_t *stream_ctrl ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
818 return pnm_read(stream_ctrl->data, buffer, size);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
819 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
820
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
821 static int open_s(stream_t *stream,int mode, void* opts, int* file_format) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
822 int fd;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
823 pnm_t *pnm;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
824 URL_t *url;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
825
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
826 mp_msg(MSGT_OPEN, MSGL_INFO, "STREAM_PNM, URL: %s\n", stream->url);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
827 stream->streaming_ctrl = streaming_ctrl_new();
25700
5ac12852a918 Remove some useless () and {}
reimar
parents: 25699
diff changeset
828 if(stream->streaming_ctrl==NULL)
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
829 return STREAM_ERROR;
25700
5ac12852a918 Remove some useless () and {}
reimar
parents: 25699
diff changeset
830
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
831 stream->streaming_ctrl->bandwidth = network_bandwidth;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
832 url = url_new(stream->url);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
833 stream->streaming_ctrl->url = check4proxies(url);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
834 //url_free(url);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
835
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
836 fd = connect2Server( stream->streaming_ctrl->url->hostname,
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
837 stream->streaming_ctrl->url->port ? stream->streaming_ctrl->url->port : 7070,1 );
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
838
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
839 if(fd<0)
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
840 goto fail;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
841
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
842 pnm = pnm_connect(fd,stream->streaming_ctrl->url->file);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
843 if(!pnm)
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
844 goto fail;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
845 stream->type = STREAMTYPE_STREAM;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
846 stream->fd=fd;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
847 stream->streaming_ctrl->data=pnm;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
848 stream->streaming_ctrl->streaming_read = pnm_streaming_read;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
849 //stream->streaming_ctrl->streaming_seek = nop_streaming_seek;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
850 stream->streaming_ctrl->prebuffer_size = 8*1024; // 8 KBytes
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
851 stream->streaming_ctrl->buffering = 1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
852 stream->streaming_ctrl->status = streaming_playing_e;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
853 *file_format = DEMUXER_TYPE_REAL;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
854 fixup_network_stream_cache(stream);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
855 return STREAM_OK;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
856
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
857 fail:
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
858 streaming_ctrl_free(stream->streaming_ctrl);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
859 stream->streaming_ctrl = NULL;
24257
d261f5109660 cosmetics: typo fix UNSUPORTED --> UNSUPPORTED
diego
parents: 19614
diff changeset
860 return STREAM_UNSUPPORTED;
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
861 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
862
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
863
25211
c1d17bd6683c Mark all stream_info_t as const
reimar
parents: 24860
diff changeset
864 const stream_info_t stream_info_pnm = {
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
865 "RealNetworks pnm",
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
866 "pnm",
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
867 "Arpi, xine team",
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
868 "ported from xine",
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
869 open_s,
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
870 {"pnm", NULL}, //pnm as fallback
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
871 NULL,
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
872 0 // Urls are an option string
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15077
diff changeset
873 };