Mercurial > mplayer.hg
annotate libmpdemux/asf_streaming.c @ 3599:2141db140d84
nop_steraming fixed
author | arpi |
---|---|
date | Wed, 19 Dec 2001 01:59:25 +0000 |
parents | 314987c0aaf4 |
children | deba2b4fe4b4 |
rev | line source |
---|---|
871 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
833 | 3 #include <string.h> |
1430 | 4 #include <unistd.h> |
3494
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3475
diff
changeset
|
5 #include <errno.h> |
833 | 6 |
2555
66837325b929
config.h cleanup, few things added to steram/demuxer headers
arpi
parents:
2489
diff
changeset
|
7 #include "config.h" |
66837325b929
config.h cleanup, few things added to steram/demuxer headers
arpi
parents:
2489
diff
changeset
|
8 |
871 | 9 #include "url.h" |
10 #include "http.h" | |
1001 | 11 #include "asf.h" |
905 | 12 #include "network.h" |
871 | 13 |
1001 | 14 #include "stream.h" |
833 | 15 |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
16 typedef struct { |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
17 ASF_StreamType_e streaming_type; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
18 int request; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
19 int packet_size; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
20 int *audio_streams,n_audio,*video_streams,n_video; |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
21 } asf_http_streaming_ctrl_t; |
871 | 22 |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
23 #ifdef ARCH_X86 |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
24 #define ASF_LOAD_GUID_PREFIX(guid) (*(uint32_t *)(guid)) |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
25 #else |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
26 #define ASF_LOAD_GUID_PREFIX(guid) \ |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
27 ((guid)[3] << 24 | (guid)[2] << 16 | (guid)[1] << 8 | (guid)[0]) |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
28 #endif |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
29 |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
30 extern int audio_id,video_id; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
31 extern int verbose; |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
32 |
3042 | 33 // ASF streaming support several network protocol. |
34 // One use UDP, not known, yet! | |
35 // Another is HTTP, this one is known. | |
36 // So for now, we use the HTTP protocol. | |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
37 // |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
38 // We can try several protocol for asf streaming |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
39 // * first the UDP protcol, if there is a firewall, UDP |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
40 // packets will not come back, so the mmsu will failed. |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
41 // * Then we can try TCP, but if there is a proxy for |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
42 // internet connection, the TCP connection will not get |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
43 // through |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
44 // * Then we can try HTTP. |
1001 | 45 int |
3042 | 46 asf_streaming_start( stream_t *stream ) { |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
47 char proto_s[10]; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
48 int fd = -1; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
49 |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
50 strncpy( proto_s, stream->streaming_ctrl->url->protocol, 10 ); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
51 |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
52 if( !strncasecmp( proto_s, "mms", 3) && strncasecmp( proto_s, "mmst", 4) ) { |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
53 printf("Trying ASF/UDP...\n"); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
54 //fd = asf_mmsu_streaming_start( stream ); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
55 if( fd!=-1 ) return fd; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
56 printf(" ===> ASF/UDP failed\n"); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
57 } |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
58 if( !strncasecmp( proto_s, "mms", 3) ) { |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
59 printf("Trying ASF/TCP...\n"); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
60 //fd = asf_mmst_streaming_start( stream ); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
61 if( fd!=-1 ) return fd; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
62 printf(" ===> ASF/TCP failed\n"); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
63 } |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
64 if( !strncasecmp( proto_s, "http", 4) || !strncasecmp( proto_s, "mms", 3) ) { |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
65 printf("Trying ASF/HTTP...\n"); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
66 fd = asf_http_streaming_start( stream ); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
67 if( fd!=-1 ) return fd; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
68 printf(" ===> ASF/HTTP failed\n"); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
69 } |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
70 |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
71 printf("Unknown protocol: %s\n", proto_s ); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
72 return -1; |
3042 | 73 } |
74 | |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
75 static int |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
76 asf_streaming_parse_header(int fd, streaming_ctrl_t* streaming_ctrl) { |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
77 ASF_header_t asfh; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
78 ASF_obj_header_t objh; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
79 ASF_file_header_t fileh; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
80 ASF_stream_header_t streamh; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
81 ASF_stream_chunck_t chunk; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
82 asf_http_streaming_ctrl_t* asf_ctrl = (asf_http_streaming_ctrl_t*) streaming_ctrl->data; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
83 char* buffer=NULL, *chunk_buffer=NULL; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
84 int i,r,size,pos = 0; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
85 int buffer_size = 0; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
86 int chunk_size2read = 0; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
87 |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
88 if(asf_ctrl == NULL) return -1; |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
89 |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
90 // The ASF header can be in several network chunks. For example if the content description |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
91 // is big, the ASF header will be split in 2 network chunk. |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
92 // So we need to retrieve all the chunk before starting to parse the header. |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
93 do { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
94 for( r=0; r < sizeof(ASF_stream_chunck_t) ; ) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
95 i = nop_streaming_read(fd,((char*)&chunk)+r,sizeof(ASF_stream_chunck_t) - r,streaming_ctrl); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
96 if(i <= 0) return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
97 r += i; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
98 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
99 size = asf_streaming( &chunk, &r) - sizeof(ASF_stream_chunck_t); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
100 if(r) printf("Warning : drop header ????\n"); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
101 if(size < 0){ |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
102 printf("Error while parsing chunk header\n"); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
103 return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
104 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
105 if (chunk.type != 0x4824) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
106 printf("Don't got a header as first chunk !!!!\n"); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
107 return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
108 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
109 |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
110 buffer = (char*) malloc(size+buffer_size); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
111 if(buffer == NULL) { |
3551 | 112 printf("Error can't allocate %d bytes buffer\n",size+buffer_size); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
113 return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
114 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
115 if( chunk_buffer!=NULL ) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
116 memcpy( buffer, chunk_buffer, buffer_size ); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
117 free( chunk_buffer ); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
118 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
119 chunk_buffer = buffer; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
120 buffer += buffer_size; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
121 buffer_size += size; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
122 |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
123 for(r = 0; r < size;) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
124 i = nop_streaming_read(fd,buffer+r,size-r,streaming_ctrl); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
125 if(i < 0) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
126 printf("Error while reading network stream\n"); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
127 return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
128 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
129 r += i; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
130 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
131 |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
132 if( chunk_size2read==0 ) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
133 if(size < (int)sizeof(asfh)) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
134 printf("Error chunk is too small\n"); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
135 return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
136 } else printf("Got chunk\n"); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
137 memcpy(&asfh,buffer,sizeof(asfh)); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
138 le2me_ASF_header_t(&asfh); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
139 chunk_size2read = asfh.objh.size; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
140 printf("Size 2 read=%d\n", chunk_size2read); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
141 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
142 } while( buffer_size<chunk_size2read); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
143 buffer = chunk_buffer; |
3551 | 144 size = buffer_size; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
145 |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
146 if(asfh.cno > 256) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
147 printf("Error sub chunks number is invalid\n"); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
148 return -1; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
149 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
150 |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
151 pos += sizeof(asfh); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
152 |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
153 while(size - pos >= (int)sizeof(objh)) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
154 memcpy(&objh,buffer+pos,sizeof(objh)); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
155 le2me_ASF_obj_header_t(&objh); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
156 |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
157 switch(ASF_LOAD_GUID_PREFIX(objh.guid)) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
158 case 0x8CABDCA1 : // File header |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
159 pos += sizeof(objh); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
160 memcpy(&fileh,buffer + pos,sizeof(fileh)); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
161 le2me_ASF_file_header_t(&fileh); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
162 if(fileh.packetsize != fileh.packetsize2) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
163 printf("Error packetsize check don't match\n"); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
164 return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
165 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
166 asf_ctrl->packet_size = fileh.packetsize; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
167 // FIXME: preroll contains the amount of time to bufferize |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
168 // before playing. To be able to do that we need to |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
169 // read the timestamp of the first data packet and bufferize. |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
170 streaming_ctrl->prebuffer_size = fileh.preroll; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
171 pos += sizeof(fileh); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
172 break; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
173 case 0xB7DC0791 : // stream header |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
174 pos += sizeof(objh); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
175 memcpy(&streamh,buffer + pos,sizeof(streamh)); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
176 le2me_ASF_stream_header_t(&streamh); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
177 pos += sizeof(streamh) + streamh.type_size; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
178 switch(ASF_LOAD_GUID_PREFIX(streamh.type)) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
179 case 0xF8699E40 : // audio stream |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
180 if(asf_ctrl->audio_streams == NULL){ |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
181 asf_ctrl->audio_streams = (int*)malloc(sizeof(int)); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
182 asf_ctrl->n_audio = 1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
183 } else { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
184 asf_ctrl->n_audio++; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
185 asf_ctrl->audio_streams = (int*)realloc(asf_ctrl->audio_streams, |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
186 asf_ctrl->n_audio*sizeof(int)); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
187 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
188 asf_ctrl->audio_streams[asf_ctrl->n_audio-1] = streamh.stream_no; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
189 pos += streamh.stream_size; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
190 break; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
191 case 0xBC19EFC0 : // video stream |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
192 if(asf_ctrl->video_streams == NULL){ |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
193 asf_ctrl->video_streams = (int*)malloc(sizeof(int)); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
194 asf_ctrl->n_video = 1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
195 } else { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
196 asf_ctrl->n_video++; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
197 asf_ctrl->video_streams = (int*)realloc(asf_ctrl->video_streams, |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
198 asf_ctrl->n_video*sizeof(int)); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
199 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
200 asf_ctrl->video_streams[asf_ctrl->n_video-1] = streamh.stream_no; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
201 break; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
202 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
203 break; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
204 default : |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
205 pos += objh.size; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
206 break; |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
207 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
208 } |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
209 free(buffer); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
210 return 1; |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
211 } |
3042 | 212 |
213 int | |
214 asf_http_streaming_read( int fd, char *buffer, int size, streaming_ctrl_t *streaming_ctrl ) { | |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
215 static ASF_stream_chunck_t chunk; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
216 int read,chunk_size = 0; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
217 static int rest = 0, drop_chunk = 0, waiting = 0; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
218 asf_http_streaming_ctrl_t *asf_http_ctrl = (asf_http_streaming_ctrl_t*)streaming_ctrl->data; |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
219 |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
220 while(1) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
221 if (rest == 0 && waiting == 0) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
222 read = 0; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
223 while(read < (int)sizeof(ASF_stream_chunck_t)){ |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
224 int r = nop_streaming_read( fd, ((char*)&chunk) + read, |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
225 sizeof(ASF_stream_chunck_t)-read, |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
226 streaming_ctrl ); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
227 if(r < 0){ |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
228 printf("End of stream without a full chunk header\n"); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
229 return -1; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
230 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
231 read += r; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
232 } |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
233 chunk_size = asf_streaming( &chunk, &drop_chunk ); |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
234 if(chunk_size < 0) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
235 printf("Error while parsing chunk header\n"); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
236 return -1; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
237 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
238 chunk_size -= sizeof(ASF_stream_chunck_t); |
3042 | 239 |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
240 if(chunk.type != 0x4824 && (!drop_chunk)) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
241 if (asf_http_ctrl->packet_size < chunk_size) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
242 printf("Error chunk_size > packet_size\n"); |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
243 return -1; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
244 } |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
245 waiting = asf_http_ctrl->packet_size; |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
246 } else { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
247 waiting = chunk_size; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
248 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
249 |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
250 } else if (rest){ |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
251 chunk_size = rest; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
252 rest = 0; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
253 } |
3042 | 254 |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
255 read = 0; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
256 if ( waiting >= chunk_size) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
257 if (chunk_size > size){ |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
258 rest = chunk_size - size; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
259 chunk_size = size; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
260 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
261 while(read < chunk_size) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
262 int got = nop_streaming_read( fd,buffer+read,chunk_size-read,streaming_ctrl ); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
263 if(got < 0) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
264 printf("Error while reading chunk EOF ?\n"); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
265 return -1; |
1001 | 266 } |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
267 read += got; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
268 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
269 waiting -= read; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
270 if (drop_chunk) continue; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
271 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
272 if (rest == 0 && waiting > 0 && size-read > 0) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
273 int s = MIN(waiting,size-read); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
274 memset(buffer+read,0,s); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
275 waiting -= s; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
276 read += s; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
277 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
278 break; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
279 } |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
280 |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
281 return read; |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
282 } |
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
283 |
1001 | 284 int |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
285 asf_streaming(ASF_stream_chunck_t *stream_chunck, int *drop_packet ) { |
3042 | 286 /* |
287 printf("ASF stream chunck size=%d\n", stream_chunck->size); | |
1001 | 288 printf("length: %d\n", length ); |
289 printf("0x%02X\n", stream_chunck->type ); | |
3042 | 290 */ |
1001 | 291 if( drop_packet!=NULL ) *drop_packet = 0; |
871 | 292 |
293 if( stream_chunck->size<8 ) { | |
294 printf("Ahhhh, stream_chunck size is too small: %d\n", stream_chunck->size); | |
1001 | 295 return -1; |
871 | 296 } |
297 if( stream_chunck->size!=stream_chunck->size_confirm ) { | |
298 printf("size_confirm mismatch!: %d %d\n", stream_chunck->size, stream_chunck->size_confirm); | |
1001 | 299 return -1; |
871 | 300 } |
3042 | 301 /* |
1001 | 302 printf(" type: 0x%02X\n", stream_chunck->type ); |
303 printf(" size: %d (0x%02X)\n", stream_chunck->size, stream_chunck->size ); | |
304 printf(" sequence_number: 0x%04X\n", stream_chunck->sequence_number ); | |
305 printf(" unknown: 0x%02X\n", stream_chunck->unknown ); | |
306 printf(" size_confirm: 0x%02X\n", stream_chunck->size_confirm ); | |
3042 | 307 */ |
833 | 308 switch(stream_chunck->type) { |
3042 | 309 case 0x4324: // $C Clear ASF configuration |
871 | 310 printf("=====> Clearing ASF stream configuration!\n"); |
1001 | 311 if( drop_packet!=NULL ) *drop_packet = 1; |
312 return stream_chunck->size; | |
833 | 313 break; |
3042 | 314 case 0x4424: // $D Data follows |
315 // printf("=====> Data follows\n"); | |
833 | 316 break; |
3042 | 317 case 0x4524: // $E Transfer complete |
871 | 318 printf("=====> Transfer complete\n"); |
1001 | 319 if( drop_packet!=NULL ) *drop_packet = 1; |
320 return stream_chunck->size; | |
833 | 321 break; |
3042 | 322 case 0x4824: // $H ASF header chunk follows |
871 | 323 printf("=====> ASF header chunk follows\n"); |
833 | 324 break; |
325 default: | |
871 | 326 printf("=====> Unknown stream type 0x%x\n", stream_chunck->type ); |
833 | 327 } |
1001 | 328 return stream_chunck->size+4; |
833 | 329 } |
330 | |
905 | 331 int |
3042 | 332 asf_http_streaming_seek( int fd, off_t pos, streaming_ctrl_t *streaming_ctrl ) { |
333 return -1; | |
334 } | |
335 | |
336 int | |
905 | 337 asf_http_streaming_type(char *content_type, char *features) { |
338 if( content_type==NULL ) return ASF_Unknown_e; | |
833 | 339 if( !strcasecmp(content_type, "application/octet-stream") ) { |
905 | 340 if( features==NULL ) { |
1001 | 341 printf("=====> ASF Prerecorded\n"); |
905 | 342 return ASF_Prerecorded_e; |
343 } else if( strstr(features, "broadcast")) { | |
1001 | 344 printf("=====> ASF Live stream\n"); |
905 | 345 return ASF_Live_e; |
833 | 346 } else { |
1001 | 347 printf("=====> ASF Prerecorded\n"); |
905 | 348 return ASF_Prerecorded_e; |
833 | 349 } |
350 } else { | |
871 | 351 if( (!strcasecmp(content_type, "audio/x-ms-wax")) || |
833 | 352 (!strcasecmp(content_type, "audio/x-ms-wma")) || |
353 (!strcasecmp(content_type, "video/x-ms-asf")) || | |
354 (!strcasecmp(content_type, "video/x-ms-afs")) || | |
355 (!strcasecmp(content_type, "video/x-ms-wvx")) || | |
356 (!strcasecmp(content_type, "video/x-ms-wmv")) || | |
357 (!strcasecmp(content_type, "video/x-ms-wma")) ) { | |
1001 | 358 printf("=====> ASF Redirector\n"); |
905 | 359 return ASF_Redirector_e; |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
360 } else if( !strcasecmp(content_type, "text/plain") ) { |
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
361 printf("=====> ASF Plain text\n"); |
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
362 return ASF_PlainText_e; |
833 | 363 } else { |
1001 | 364 printf("=====> ASF unknown content-type: %s\n", content_type ); |
905 | 365 return ASF_Unknown_e; |
833 | 366 } |
367 } | |
905 | 368 return ASF_Unknown_e; |
833 | 369 } |
871 | 370 |
905 | 371 HTTP_header_t * |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
372 asf_http_request(streaming_ctrl_t *streaming_ctrl) { |
871 | 373 HTTP_header_t *http_hdr; |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
374 URL_t *url = streaming_ctrl->url; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
375 asf_http_streaming_ctrl_t *asf_http_ctrl = (asf_http_streaming_ctrl_t*)streaming_ctrl->data; |
871 | 376 char str[250]; |
1001 | 377 char *ptr; |
871 | 378 char *request; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
379 int i,as = -1,vs = -1; |
871 | 380 |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
381 int offset_hi=0, offset_lo=0, length=0; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
382 int asf_nb_stream=0; |
871 | 383 |
384 // Common header for all requests. | |
385 http_hdr = http_new_header(); | |
386 http_set_uri( http_hdr, url->file ); | |
387 http_set_field( http_hdr, "Accept: */*" ); | |
388 http_set_field( http_hdr, "User-Agent: NSPlayer/4.1.0.3856" ); | |
389 sprintf( str, "Host: %s:%d", url->hostname, url->port ); | |
390 http_set_field( http_hdr, str ); | |
391 http_set_field( http_hdr, "Pragma: xClientGUID={c77e7400-738a-11d2-9add-0020af0a3278}" ); | |
392 sprintf(str, | |
393 "Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=%u:%u,request-context=%d,max-duration=%u", | |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
394 offset_hi, offset_lo, asf_http_ctrl->request, length ); |
871 | 395 http_set_field( http_hdr, str ); |
396 | |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
397 switch( asf_http_ctrl->streaming_type ) { |
871 | 398 case ASF_Live_e: |
399 case ASF_Prerecorded_e: | |
400 http_set_field( http_hdr, "Pragma: xPlayStrm=1" ); | |
1001 | 401 ptr = str; |
402 ptr += sprintf( ptr, "Pragma: stream-switch-entry="); | |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
403 if(asf_http_ctrl->n_audio > 0) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
404 if(audio_id > 0) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
405 for( i=0; i<asf_http_ctrl->n_audio ; i++ ) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
406 if(asf_http_ctrl->audio_streams[i] == audio_id) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
407 as = audio_id; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
408 break; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
409 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
410 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
411 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
412 if(as < 0) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
413 if(audio_id > 0) |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
414 printf("Audio stream %d don't exist\n"); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
415 as = asf_http_ctrl->audio_streams[0]; |
1001 | 416 } |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
417 ptr += sprintf(ptr, " ffff:%d:0",as); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
418 asf_nb_stream++; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
419 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
420 if(asf_http_ctrl->n_video > 0) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
421 if(video_id > 0) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
422 for( i=0; i<asf_http_ctrl->n_video ; i++ ) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
423 if(asf_http_ctrl->video_streams[i] == video_id) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
424 vs = video_id; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
425 break; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
426 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
427 } |
1001 | 428 } |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
429 if(vs < 0) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
430 if(video_id > 0) |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
431 printf("Video stream %d don't exist\n"); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
432 vs = asf_http_ctrl->video_streams[0]; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
433 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
434 ptr += sprintf( ptr, " ffff:%d:0",vs); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
435 asf_nb_stream++; |
1001 | 436 } |
437 http_set_field( http_hdr, str ); | |
871 | 438 sprintf( str, "Pragma: stream-switch-count=%d", asf_nb_stream ); |
439 http_set_field( http_hdr, str ); | |
440 break; | |
441 case ASF_Redirector_e: | |
442 break; | |
443 case ASF_Unknown_e: | |
444 // First request goes here. | |
445 break; | |
446 default: | |
447 printf("Unknown asf stream type\n"); | |
448 } | |
449 | |
450 http_set_field( http_hdr, "Connection: Close" ); | |
905 | 451 http_build_request( http_hdr ); |
871 | 452 |
905 | 453 return http_hdr; |
871 | 454 } |
455 | |
456 int | |
905 | 457 asf_http_parse_response( HTTP_header_t *http_hdr ) { |
871 | 458 char *content_type, *pragma; |
459 char features[64] = "\0"; | |
460 int len; | |
905 | 461 if( http_response_parse(http_hdr)<0 ) { |
462 printf("Failed to parse HTTP response\n"); | |
463 return -1; | |
464 } | |
871 | 465 if( http_hdr->status_code!=200 ) { |
466 printf("Server return %d:%s\n", http_hdr->status_code, http_hdr->reason_phrase); | |
467 return -1; | |
468 } | |
469 | |
470 content_type = http_get_field( http_hdr, "Content-Type"); | |
3042 | 471 //printf("Content-Type: [%s]\n", content_type); |
871 | 472 |
473 pragma = http_get_field( http_hdr, "Pragma"); | |
905 | 474 while( pragma!=NULL ) { |
871 | 475 char *comma_ptr=NULL; |
476 char *end; | |
3042 | 477 //printf("Pragma: [%s]\n", pragma ); |
871 | 478 // The pragma line can get severals attributes |
479 // separeted with a comma ','. | |
480 do { | |
481 if( !strncasecmp( pragma, "features=", 9) ) { | |
482 pragma += 9; | |
483 end = strstr( pragma, "," ); | |
484 if( end==NULL ) { | |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
485 int s = strlen(pragma); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
486 if(s > sizeof(features)) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
487 printf("ASF HTTP PARSE WARNING : Pragma %s cuted from %d bytes to %d\n",pragma,s,sizeof(features)); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
488 len = sizeof(features); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
489 } else { |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
490 len = s; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
491 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
492 } else { |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
493 len = MIN(end-pragma,sizeof(features)); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
494 } |
871 | 495 strncpy( features, pragma, len ); |
496 features[len]='\0'; | |
497 break; | |
498 } | |
499 comma_ptr = strstr( pragma, "," ); | |
500 if( comma_ptr!=NULL ) { | |
501 pragma = comma_ptr+1; | |
502 if( pragma[0]==' ' ) pragma++; | |
503 } | |
504 } while( comma_ptr!=NULL ); | |
505 pragma = http_get_next_field( http_hdr ); | |
905 | 506 } |
507 | |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
508 return asf_http_streaming_type( content_type, features ); |
871 | 509 } |
510 | |
905 | 511 URL_t * |
512 asf_http_ASX_redirect( HTTP_header_t *http_hdr ) { | |
513 URL_t *url_redirect=NULL; | |
514 printf("=========>> ASX parser not yet implemented <<==========\n"); | |
515 | |
516 printf("ASX=[%s]\n", http_hdr->body ); | |
517 | |
518 return url_redirect; | |
871 | 519 } |
905 | 520 |
521 int | |
3042 | 522 asf_http_streaming_start( stream_t *stream ) { |
905 | 523 HTTP_header_t *http_hdr=NULL; |
524 URL_t *url_next=NULL; | |
3042 | 525 URL_t *url = stream->streaming_ctrl->url; |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
526 asf_http_streaming_ctrl_t *asf_http_ctrl; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
527 ASF_StreamType_e streaming_type; |
905 | 528 char buffer[BUFFER_SIZE]; |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
529 unsigned int port; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
530 int i, ret; |
3042 | 531 int fd = stream->fd; |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
532 int done; |
1001 | 533 |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
534 asf_http_ctrl = (asf_http_streaming_ctrl_t*)malloc(sizeof(asf_http_streaming_ctrl_t)); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
535 if( asf_http_ctrl==NULL ) { |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
536 printf("Memory allocation failed\n"); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
537 return -1; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
538 } |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
539 asf_http_ctrl->streaming_type = ASF_Unknown_e; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
540 asf_http_ctrl->request = 1; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
541 asf_http_ctrl->audio_streams = asf_http_ctrl->video_streams = NULL; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
542 asf_http_ctrl->n_audio = asf_http_ctrl->n_video = 0; |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
543 stream->streaming_ctrl->data = (void*)asf_http_ctrl; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
544 |
905 | 545 do { |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
546 done = 1; |
905 | 547 if( fd>0 ) close( fd ); |
1001 | 548 |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
549 if( url->port==0 ) url->port = 80; |
905 | 550 fd = connect2Server( url->hostname, url->port ); |
551 if( fd<0 ) return -1; | |
552 | |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
553 http_hdr = asf_http_request( stream->streaming_ctrl ); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
554 if( verbose>0 ) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
555 printf("Request [%s]\n", http_hdr->buffer ); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
556 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
557 for(i=0; i < http_hdr->buffer_size ; ) { |
3494
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3475
diff
changeset
|
558 int r = write( fd, http_hdr->buffer+i, http_hdr->buffer_size-i ); |
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3475
diff
changeset
|
559 if(r <0) { |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
560 printf("Socket write error : %s\n",strerror(errno)); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
561 return -1; |
3494
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3475
diff
changeset
|
562 } |
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3475
diff
changeset
|
563 i += r; |
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3475
diff
changeset
|
564 } |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
565 http_free( http_hdr ); |
905 | 566 http_hdr = http_new_header(); |
567 do { | |
3042 | 568 i = read( fd, buffer, BUFFER_SIZE ); |
905 | 569 printf("read: %d\n", i ); |
1001 | 570 if( i<0 ) { |
571 perror("read"); | |
572 http_free( http_hdr ); | |
573 return -1; | |
574 } | |
905 | 575 http_response_append( http_hdr, buffer, i ); |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
576 } while( !http_is_header_entire( http_hdr ) ); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
577 if( verbose>0 ) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
578 http_hdr->buffer[http_hdr->buffer_size]='\0'; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
579 printf("Response [%s]\n", http_hdr->buffer ); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
580 } |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
581 streaming_type = asf_http_parse_response(http_hdr); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
582 if( streaming_type<0 ) { |
905 | 583 printf("Failed to parse header\n"); |
1001 | 584 http_free( http_hdr ); |
905 | 585 return -1; |
586 } | |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
587 asf_http_ctrl->streaming_type = streaming_type; |
1001 | 588 switch( streaming_type ) { |
905 | 589 case ASF_Live_e: |
590 case ASF_Prerecorded_e: | |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
591 case ASF_PlainText_e: |
1001 | 592 if( http_hdr->body_size>0 ) { |
3042 | 593 if( streaming_bufferize( stream->streaming_ctrl, http_hdr->body, http_hdr->body_size )<0 ) { |
594 http_free( http_hdr ); | |
595 return -1; | |
1001 | 596 } |
905 | 597 } |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
598 if( asf_http_ctrl->request==1 ) { |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
599 if( streaming_type!=ASF_PlainText_e ) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
600 // First request, we only got the ASF header. |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
601 ret = asf_streaming_parse_header(fd,stream->streaming_ctrl); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
602 if(ret < 0) return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
603 if(asf_http_ctrl->n_audio == 0 && asf_http_ctrl->n_video == 0) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
604 printf("No stream found\n"); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
605 return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
606 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
607 } |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
608 asf_http_ctrl->request++; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
609 done = 0; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
610 } |
905 | 611 break; |
612 case ASF_Redirector_e: | |
613 url_next = asf_http_ASX_redirect( http_hdr ); | |
614 if( url_next==NULL ) { | |
615 printf("Failed to parse ASX file\n"); | |
616 close(fd); | |
1001 | 617 http_free( http_hdr ); |
905 | 618 return -1; |
619 } | |
3042 | 620 url_free( stream->streaming_ctrl->url ); |
621 stream->streaming_ctrl->url = url_next; | |
905 | 622 url = url_next; |
3042 | 623 done = 0; |
905 | 624 break; |
625 case ASF_Unknown_e: | |
626 default: | |
627 printf("Unknown ASF streaming type\n"); | |
628 close(fd); | |
1001 | 629 http_free( http_hdr ); |
905 | 630 return -1; |
631 } | |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
632 // Check if we got a redirect. |
905 | 633 } while(!done); |
634 | |
3042 | 635 stream->fd= fd; |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
636 if( streaming_type==ASF_PlainText_e ) { |
3042 | 637 stream->streaming_ctrl->streaming_read = nop_streaming_read; |
638 stream->streaming_ctrl->streaming_seek = nop_streaming_seek; | |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
639 } else { |
3042 | 640 stream->streaming_ctrl->streaming_read = asf_http_streaming_read; |
641 stream->streaming_ctrl->streaming_seek = asf_http_streaming_seek; | |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
642 } |
3042 | 643 stream->streaming_ctrl->prebuffer_size = 20000; |
644 stream->streaming_ctrl->buffering = 1; | |
645 stream->streaming_ctrl->status = streaming_playing_e; | |
1001 | 646 |
647 http_free( http_hdr ); | |
905 | 648 return fd; |
649 } | |
650 |