annotate libmpdemux/asf_mmst_streaming.c @ 8473:12d19b01d4c6

handle mencoder's 0-byte 'skipped frames'
author arpi
date Mon, 16 Dec 2002 02:38:37 +0000
parents 0c660f21e0e4
children 2ffb9a8b0428
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6092
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
1 // mmst implementation taken from the xine-mms plugin made by majormms (http://geocities.com/majormms/)
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
2 //
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
3 // ported to mplayer by Abhijeet Phatak <abhijeetphatak@yahoo.com>
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
4 // date : 16 April 2002
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
5 //
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
6 // information about the mms protocol can be find at http://get.to/sdp
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
7 //
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
8
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
9
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
10 #include <stdio.h>
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
11 #include <stdlib.h>
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
12 #include <string.h>
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
13 #include <unistd.h>
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
14 #include <errno.h>
7880
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
15 #include <inttypes.h>
6092
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
16
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
17 #include "config.h"
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
18
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
19 #include "url.h"
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
20 #include "asf.h"
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
21
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
22 #include "stream.h"
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
23
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
24 #include "network.h"
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
25
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
26 #define BUF_SIZE 102400
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
27
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
28 typedef struct
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
29 {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
30 uint8_t buf[BUF_SIZE];
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
31 int num_bytes;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
32
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
33 } command_t;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
34
7880
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
35 static int seq_num;
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
36 static int num_stream_ids;
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
37 static int stream_ids[20];
6092
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
38
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
39 static int get_data (int s, char *buf, size_t count);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
40
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
41 static void put_32 (command_t *cmd, uint32_t value)
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
42 {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
43 cmd->buf[cmd->num_bytes ] = value % 256;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
44 value = value >> 8;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
45 cmd->buf[cmd->num_bytes+1] = value % 256 ;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
46 value = value >> 8;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
47 cmd->buf[cmd->num_bytes+2] = value % 256 ;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
48 value = value >> 8;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
49 cmd->buf[cmd->num_bytes+3] = value % 256 ;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
50
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
51 cmd->num_bytes += 4;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
52 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
53
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
54 static uint32_t get_32 (unsigned char *cmd, int offset)
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
55 {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
56 uint32_t ret;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
57
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
58 ret = cmd[offset] ;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
59 ret |= cmd[offset+1]<<8 ;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
60 ret |= cmd[offset+2]<<16 ;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
61 ret |= cmd[offset+3]<<24 ;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
62
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
63 return ret;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
64 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
65
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
66 static void send_command (int s, int command, uint32_t switches,
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
67 uint32_t extra, int length,
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
68 char *data)
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
69 {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
70 command_t cmd;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
71 int len8;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
72
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
73 len8 = (length + (length%8)) / 8;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
74
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
75 cmd.num_bytes = 0;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
76
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
77 put_32 (&cmd, 0x00000001); /* start sequence */
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
78 put_32 (&cmd, 0xB00BFACE); /* #-)) */
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
79 put_32 (&cmd, length + 32);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
80 put_32 (&cmd, 0x20534d4d); /* protocol type "MMS " */
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
81 put_32 (&cmd, len8 + 4);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
82 put_32 (&cmd, seq_num);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
83 seq_num++;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
84 put_32 (&cmd, 0x0); /* unknown */
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
85 put_32 (&cmd, 0x0);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
86 put_32 (&cmd, len8+2);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
87 put_32 (&cmd, 0x00030000 | command); /* dir | command */
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
88 put_32 (&cmd, switches);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
89 put_32 (&cmd, extra);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
90
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
91 memcpy (&cmd.buf[48], data, length);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
92
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
93 if (write (s, cmd.buf, length+48) != (length+48)) {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
94 printf ("write error\n");
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
95 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
96 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
97
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
98 static void string_utf16(char *dest, char *src, int len)
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
99 {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
100 int i;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
101
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
102 memset (dest, 0, 1000);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
103
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
104 for (i=0; i<len; i++) {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
105 dest[i*2] = src[i];
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
106 dest[i*2+1] = 0;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
107 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
108
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
109 dest[i*2] = 0;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
110 dest[i*2+1] = 0;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
111 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
112
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
113 static void get_answer (int s)
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
114 {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
115 char data[BUF_SIZE];
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
116 int command = 0x1b;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
117
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
118 while (command == 0x1b) {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
119 int len;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
120
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
121 len = read (s, data, BUF_SIZE) ;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
122 if (!len) {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
123 printf ("\nalert! eof\n");
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
124 return;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
125 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
126
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
127 command = get_32 (data, 36) & 0xFFFF;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
128
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
129 if (command == 0x1b)
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
130 send_command (s, 0x1b, 0, 0, 0, data);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
131 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
132 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
133
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
134 static int get_data (int s, char *buf, size_t count)
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
135 {
7953
60624e692b95 GCC warning fixes
bertrand
parents: 7880
diff changeset
136 ssize_t len;
60624e692b95 GCC warning fixes
bertrand
parents: 7880
diff changeset
137 size_t total = 0;
6092
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
138
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
139 while (total < count) {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
140
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
141 len = read (s, &buf[total], count-total);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
142
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
143 if (len<0) {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
144 perror ("read error:");
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
145 return 0;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
146 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
147
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
148 total += len;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
149
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
150 if (len != 0) {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
151 // printf ("[%d/%d]", total, count);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
152 fflush (stdout);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
153 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
154
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
155 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
156
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
157 return 1;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
158
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
159 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
160
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
161 static int get_header (int s, uint8_t *header, streaming_ctrl_t *streaming_ctrl)
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
162 {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
163 unsigned char pre_header[8];
7953
60624e692b95 GCC warning fixes
bertrand
parents: 7880
diff changeset
164 int header_len;
6092
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
165
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
166 header_len = 0;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
167
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
168 while (1) {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
169 if (!get_data (s, pre_header, 8)) {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
170 printf ("pre-header read failed\n");
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
171 return 0;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
172 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
173 if (pre_header[4] == 0x02) {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
174
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
175 int packet_len;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
176
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
177 packet_len = (pre_header[7] << 8 | pre_header[6]) - 8;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
178
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
179 // printf ("asf header packet detected, len=%d\n", packet_len);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
180
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
181 if (!get_data (s, &header[header_len], packet_len)) {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
182 printf ("header data read failed\n");
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
183 return 0;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
184 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
185
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
186 header_len += packet_len;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
187
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
188 if ( (header[header_len-1] == 1) && (header[header_len-2]==1)) {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
189
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
190
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
191 if( streaming_bufferize( streaming_ctrl, header, header_len )<0 ) {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
192 return -1;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
193 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
194
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
195 // printf ("get header packet finished\n");
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
196
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
197 return (header_len);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
198
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
199 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
200
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
201 } else {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
202
7953
60624e692b95 GCC warning fixes
bertrand
parents: 7880
diff changeset
203 int32_t packet_len;
6092
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
204 int command;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
205 char data[BUF_SIZE];
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
206
7953
60624e692b95 GCC warning fixes
bertrand
parents: 7880
diff changeset
207 if (!get_data (s, (char*)&packet_len, 4)) {
6092
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
208 printf ("packet_len read failed\n");
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
209 return 0;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
210 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
211
7953
60624e692b95 GCC warning fixes
bertrand
parents: 7880
diff changeset
212 packet_len = get_32 ((unsigned char*)&packet_len, 0) + 4;
6092
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
213
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
214 // printf ("command packet detected, len=%d\n", packet_len);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
215
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
216 if (!get_data (s, data, packet_len)) {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
217 printf ("command data read failed\n");
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
218 return 0;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
219 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
220
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
221 command = get_32 (data, 24) & 0xFFFF;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
222
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
223 // printf ("command: %02x\n", command);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
224
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
225 if (command == 0x1b)
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
226 send_command (s, 0x1b, 0, 0, 0, data);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
227
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
228 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
229
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
230 // printf ("get header packet succ\n");
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
231 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
232 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
233
7880
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
234 static int interp_header (uint8_t *header, int header_len)
6092
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
235 {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
236 int i;
7472
c4434bdf6e51 tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents: 7309
diff changeset
237 int packet_length=-1;
6092
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
238
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
239 /*
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
240 * parse header
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
241 */
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
242
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
243 i = 30;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
244 while (i<header_len) {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
245
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
246 uint64_t guid_1, guid_2, length;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
247
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
248 guid_2 = (uint64_t)header[i] | ((uint64_t)header[i+1]<<8)
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
249 | ((uint64_t)header[i+2]<<16) | ((uint64_t)header[i+3]<<24)
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
250 | ((uint64_t)header[i+4]<<32) | ((uint64_t)header[i+5]<<40)
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
251 | ((uint64_t)header[i+6]<<48) | ((uint64_t)header[i+7]<<56);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
252 i += 8;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
253
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
254 guid_1 = (uint64_t)header[i] | ((uint64_t)header[i+1]<<8)
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
255 | ((uint64_t)header[i+2]<<16) | ((uint64_t)header[i+3]<<24)
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
256 | ((uint64_t)header[i+4]<<32) | ((uint64_t)header[i+5]<<40)
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
257 | ((uint64_t)header[i+6]<<48) | ((uint64_t)header[i+7]<<56);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
258 i += 8;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
259
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
260 // printf ("guid found: %016llx%016llx\n", guid_1, guid_2);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
261
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
262 length = (uint64_t)header[i] | ((uint64_t)header[i+1]<<8)
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
263 | ((uint64_t)header[i+2]<<16) | ((uint64_t)header[i+3]<<24)
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
264 | ((uint64_t)header[i+4]<<32) | ((uint64_t)header[i+5]<<40)
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
265 | ((uint64_t)header[i+6]<<48) | ((uint64_t)header[i+7]<<56);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
266
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
267 i += 8;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
268
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
269 if ( (guid_1 == 0x6cce6200aa00d9a6) && (guid_2 == 0x11cf668e75b22630) ) {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
270 printf ("header object\n");
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
271 } else if ((guid_1 == 0x6cce6200aa00d9a6) && (guid_2 == 0x11cf668e75b22636)) {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
272 printf ("data object\n");
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
273 } else if ((guid_1 == 0x6553200cc000e48e) && (guid_2 == 0x11cfa9478cabdca1)) {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
274
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
275 packet_length = get_32(header, i+92-24);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
276
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
277 printf ("file object, packet length = %d (%d)\n",
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
278 packet_length, get_32(header, i+96-24));
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
279
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
280
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
281 } else if ((guid_1 == 0x6553200cc000e68e) && (guid_2 == 0x11cfa9b7b7dc0791)) {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
282
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
283 int stream_id = header[i+48] | header[i+49] << 8;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
284
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
285 printf ("stream object, stream id: %d\n", stream_id);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
286
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
287 stream_ids[num_stream_ids] = stream_id;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
288 num_stream_ids++;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
289
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
290 } else {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
291 printf ("unknown object\n");
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
292 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
293
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
294 // printf ("length : %lld\n", length);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
295
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
296 i += length-24;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
297
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
298 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
299
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
300 return packet_length;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
301
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
302 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
303
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
304
7880
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
305 static int get_media_packet (int s, int padding, streaming_ctrl_t *stream_ctrl) {
6092
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
306 unsigned char pre_header[8];
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
307 char data[BUF_SIZE];
7880
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
308
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
309 if (!get_data (s, pre_header, 8)) {
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
310 printf ("pre-header read failed\n");
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
311 return 0;
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
312 }
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
313
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
314 // for (i=0; i<8; i++)
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
315 // printf ("pre_header[%d] = %02x (%d)\n",
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
316 // i, pre_header[i], pre_header[i]);
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
317
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
318 if (pre_header[4] == 0x04) {
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
319
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
320 int packet_len;
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
321
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
322 packet_len = (pre_header[7] << 8 | pre_header[6]) - 8;
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
323
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
324 // printf ("asf media packet detected, len=%d\n", packet_len);
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
325
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
326 if (!get_data (s, data, packet_len)) {
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
327 printf ("media data read failed\n");
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
328 return 0;
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
329 }
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
330
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
331 streaming_bufferize(stream_ctrl, data, padding);
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
332
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
333 } else {
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
334
7953
60624e692b95 GCC warning fixes
bertrand
parents: 7880
diff changeset
335 int32_t packet_len;
60624e692b95 GCC warning fixes
bertrand
parents: 7880
diff changeset
336 int command;
7880
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
337
7953
60624e692b95 GCC warning fixes
bertrand
parents: 7880
diff changeset
338 if (!get_data (s, (char*)&packet_len, 4)) {
7880
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
339 printf ("packet_len read failed\n");
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
340 return 0;
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
341 }
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
342
7953
60624e692b95 GCC warning fixes
bertrand
parents: 7880
diff changeset
343 packet_len = get_32 ((unsigned char*)&packet_len, 0) + 4;
7880
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
344
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
345 if (!get_data (s, data, packet_len)) {
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
346 printf ("command data read failed\n");
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
347 return 0;
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
348 }
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
349
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
350 if ( (pre_header[7] != 0xb0) || (pre_header[6] != 0x0b)
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
351 || (pre_header[5] != 0xfa) || (pre_header[4] != 0xce) ) {
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
352
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
353 printf ("missing signature\n");
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
354 return -1;
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
355 }
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
356
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
357 command = get_32 (data, 24) & 0xFFFF;
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
358
7977
0c660f21e0e4 debug printf
arpi
parents: 7953
diff changeset
359 // printf ("\ncommand packet detected, len=%d cmd=0x%X\n", packet_len, command);
7880
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
360
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
361 if (command == 0x1b)
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
362 send_command (s, 0x1b, 0, 0, 0, data);
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
363 else if (command == 0x1e) {
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
364 printf ("everything done. Thank you for downloading a media file containing proprietary and patentend technology.\n");
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
365 return 0;
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
366 }
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
367 else if (command == 0x21 ) {
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
368 // Looks like it's new in WMS9
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
369 // Unknown command, but ignoring it seems to work.
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
370 return 0;
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
371 }
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
372 else if (command != 0x05) {
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
373 printf ("unknown command %02x\n", command);
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
374 return -1;
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
375 }
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
376 }
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
377
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
378 // printf ("get media packet succ\n");
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
379
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
380 return 1;
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
381 }
6092
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
382
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
383
7880
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
384 static int packet_length1;
6092
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
385
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
386 int
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
387 asf_mmst_streaming_read( int fd, char *buffer, int size, streaming_ctrl_t *stream_ctrl )
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
388 {
7880
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
389 int len;
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
390
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
391 while( stream_ctrl->buffer_size==0 ) {
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
392 // buffer is empty - fill it!
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
393 int ret = get_media_packet( fd, packet_length1, stream_ctrl);
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
394 if( ret<0 ) {
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
395 printf("get_media_packet error : %s\n",strerror(errno));
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
396 return -1;
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
397 }
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
398 }
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
399
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
400 len = stream_ctrl->buffer_size-stream_ctrl->buffer_pos;
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
401 if(len>size) len=size;
6092
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
402 memcpy( buffer, (stream_ctrl->buffer)+(stream_ctrl->buffer_pos), len );
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
403 stream_ctrl->buffer_pos += len;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
404 if( stream_ctrl->buffer_pos>=stream_ctrl->buffer_size ) {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
405 free( stream_ctrl->buffer );
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
406 stream_ctrl->buffer = NULL;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
407 stream_ctrl->buffer_size = 0;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
408 stream_ctrl->buffer_pos = 0;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
409 }
7880
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
410 return len;
6092
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
411
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
412 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
413
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
414 int
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
415 asf_mmst_streaming_seek( int fd, off_t pos, streaming_ctrl_t *streaming_ctrl )
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
416 {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
417 return -1;
7953
60624e692b95 GCC warning fixes
bertrand
parents: 7880
diff changeset
418 // Shut up gcc warning
60624e692b95 GCC warning fixes
bertrand
parents: 7880
diff changeset
419 fd++;
60624e692b95 GCC warning fixes
bertrand
parents: 7880
diff changeset
420 pos++;
60624e692b95 GCC warning fixes
bertrand
parents: 7880
diff changeset
421 streaming_ctrl=NULL;
6092
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
422 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
423
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
424 int asf_mmst_streaming_start(stream_t *stream)
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
425 {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
426 char str[1024];
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
427 char data[1024];
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
428 uint8_t asf_header[8192];
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
429 int asf_header_len;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
430 int len, i, packet_length;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
431 char *path;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
432 URL_t *url1 = stream->streaming_ctrl->url;
7953
60624e692b95 GCC warning fixes
bertrand
parents: 7880
diff changeset
433 int s = stream->fd;
6092
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
434
7250
27a1315d6af4 Checked if the connection succeeded before writing in the socket.
bertrand
parents: 6092
diff changeset
435 if( s>0 ) {
27a1315d6af4 Checked if the connection succeeded before writing in the socket.
bertrand
parents: 6092
diff changeset
436 close( stream->fd );
27a1315d6af4 Checked if the connection succeeded before writing in the socket.
bertrand
parents: 6092
diff changeset
437 stream->fd = -1;
27a1315d6af4 Checked if the connection succeeded before writing in the socket.
bertrand
parents: 6092
diff changeset
438 }
27a1315d6af4 Checked if the connection succeeded before writing in the socket.
bertrand
parents: 6092
diff changeset
439
6092
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
440 /* parse url */
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
441 path = strchr(url1->file,'/') + 1;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
442
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
443 url1->port=1755;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
444 s = connect2Server( url1->hostname, url1->port );
7250
27a1315d6af4 Checked if the connection succeeded before writing in the socket.
bertrand
parents: 6092
diff changeset
445 if( s<0 ) {
27a1315d6af4 Checked if the connection succeeded before writing in the socket.
bertrand
parents: 6092
diff changeset
446 return s;
27a1315d6af4 Checked if the connection succeeded before writing in the socket.
bertrand
parents: 6092
diff changeset
447 }
6092
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
448 printf ("connected\n");
7880
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
449
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
450 seq_num=0;
6092
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
451
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
452 /*
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
453 * Send the initial connect info including player version no. Client GUID (random) and the host address being connected to.
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
454 * This command is sent at the very start of protocol initiation. It sends local information to the serve
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
455 * cmd 1 0x01
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
456 * */
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
457
7880
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
458 sprintf (str, "\034\003NSPlayer/7.0.0.1956; {33715801-BAB3-9D85-24E9-03B90328270A}; Host: %s", url1->hostname);
6092
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
459 string_utf16 (data, str, strlen(str)+2);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
460 // send_command(s, commandno ....)
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
461 send_command (s, 1, 0, 0x0004000b, strlen(str) * 2+8, data);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
462
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
463 len = read (s, data, BUF_SIZE) ;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
464
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
465 /*This sends details of the local machine IP address to a Funnel system at the server.
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
466 * Also, the TCP or UDP transport selection is sent.
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
467 *
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
468 * here 192.168.0.129 is local ip address TCP/UDP states the tronsport we r using
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
469 * and 1037 is the local TCP or UDP socket number
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
470 * cmd 2 0x02
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
471 * */
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
472
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
473 string_utf16 (&data[8], "\002\000\\\\192.168.0.1\\TCP\\1037\0000",
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
474 28);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
475 memset (data, 0, 8);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
476 send_command (s, 2, 0, 0, 28*2+8, data);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
477
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
478 len = read (s, data, BUF_SIZE) ;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
479
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
480 /* This command sends file path (at server) and file name request to the server.
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
481 * 0x5 */
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
482
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
483 string_utf16 (&data[8], path, strlen(path));
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
484 memset (data, 0, 8);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
485 send_command (s, 5, 0, 0, strlen(path)*2+12, data);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
486
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
487 get_answer (s);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
488
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
489 /* The ASF header chunk request. Includes ?session' variable for pre header value.
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
490 * After this command is sent,
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
491 * the server replies with 0x11 command and then the header chunk with header data follows.
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
492 * 0x15 */
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
493
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
494 memset (data, 0, 40);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
495 data[32] = 2;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
496
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
497 send_command (s, 0x15, 1, 0, 40, data);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
498
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
499 num_stream_ids = 0;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
500 /* get_headers(s, asf_header); */
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
501
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
502 asf_header_len = get_header (s, asf_header, stream->streaming_ctrl);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
503 // printf("---------------------------------- asf_header %d\n",asf_header);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
504 packet_length = interp_header (asf_header, asf_header_len);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
505
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
506
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
507 /*
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
508 * This command is the media stream MBR selector. Switches are always 6 bytes in length.
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
509 * After all switch elements, data ends with bytes [00 00] 00 20 ac 40 [02].
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
510 * Where:
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
511 * [00 00] shows 0x61 0x00 (on the first 33 sent) or 0xff 0xff for ASF files, and with no ending data for WMV files.
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
512 * It is not yet understood what all this means.
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
513 * And the last [02] byte is probably the header ?session' value.
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
514 *
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
515 * 0x33 */
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
516
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
517 memset (data, 0, 40);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
518
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
519 for (i=1; i<num_stream_ids; i++) {
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
520 data [ (i-1) * 6 + 2 ] = 0xFF;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
521 data [ (i-1) * 6 + 3 ] = 0xFF;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
522 data [ (i-1) * 6 + 4 ] = stream_ids[i];
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
523 data [ (i-1) * 6 + 5 ] = 0x00;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
524 }
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
525
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
526 send_command (s, 0x33, num_stream_ids, 0xFFFF | stream_ids[0] << 16, (num_stream_ids-1)*6+2 , data);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
527
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
528 get_answer (s);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
529
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
530 /* Start sending file from packet xx.
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
531 * This command is also used for resume downloads or requesting a lost packet.
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
532 * Also used for seeking by sending a play point value which seeks to the media time point.
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
533 * Includes ?session' value in pre header and the maximum media stream time.
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
534 * 0x07 */
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
535
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
536 memset (data, 0, 40);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
537
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
538 for (i=8; i<16; i++)
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
539 data[i] = 0xFF;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
540
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
541 data[20] = 0x04;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
542
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
543 send_command (s, 0x07, 1, 0xFFFF | stream_ids[0] << 16, 24, data);
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
544
7880
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
545 stream->fd = s;
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
546 stream->streaming_ctrl->streaming_read = asf_mmst_streaming_read;
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
547 stream->streaming_ctrl->streaming_seek = asf_mmst_streaming_seek;
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
548 stream->streaming_ctrl->buffering = 1;
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
549 stream->streaming_ctrl->status = streaming_playing_e;
6092
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
550
7880
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
551 packet_length1 = packet_length;
5bb4d8801a2c - fixed several 10l bugs
arpi
parents: 7472
diff changeset
552 printf("mmst packet_length = %d\n",packet_length);
6092
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
553
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
554 return 0;
1529f01e8108 Added support for asf mmst protocol.
bertrand
parents:
diff changeset
555 }