Mercurial > mplayer.hg
annotate libmpdemux/asf_streaming.c @ 4294:21dbbbbd5479
a few filters (should be removed/merged when arpis videofilter stuff is finished)
-ssf cgb=<float> -> chrominance gaussian blur (nice to improve picture quality)
-ssf lgb=<float> -> luminance gaussian blur (dunno what its good for)
-ssf chs=<int> -> shift chrominance horizontally
-ssf cvs=<int> -> shift chrominance vertically
these will only work if the swscaler is used at all
author | michael |
---|---|
date | Mon, 21 Jan 2002 15:22:28 +0000 |
parents | b84e9861461c |
children | 971836f677a9 |
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 } |
4121 | 64 if( !strncasecmp( proto_s, "http", 4) || |
65 !strncasecmp( proto_s, "mms", 3) || | |
4145 | 66 !strncasecmp( proto_s, "http_proxy", 10) |
4121 | 67 ) { |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
68 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
|
69 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
|
70 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
|
71 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
|
72 } |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
73 |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
74 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
|
75 return -1; |
3042 | 76 } |
77 | |
4046
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
78 int |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
79 asf_streaming(ASF_stream_chunck_t *stream_chunck, int *drop_packet ) { |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
80 /* |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
81 printf("ASF stream chunck size=%d\n", stream_chunck->size); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
82 printf("length: %d\n", length ); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
83 printf("0x%02X\n", stream_chunck->type ); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
84 */ |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
85 if( drop_packet!=NULL ) *drop_packet = 0; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
86 |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
87 if( stream_chunck->size<8 ) { |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
88 printf("Ahhhh, stream_chunck size is too small: %d\n", stream_chunck->size); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
89 return -1; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
90 } |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
91 if( stream_chunck->size!=stream_chunck->size_confirm ) { |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
92 printf("size_confirm mismatch!: %d %d\n", stream_chunck->size, stream_chunck->size_confirm); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
93 return -1; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
94 } |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
95 /* |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
96 printf(" type: 0x%02X\n", stream_chunck->type ); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
97 printf(" size: %d (0x%02X)\n", stream_chunck->size, stream_chunck->size ); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
98 printf(" sequence_number: 0x%04X\n", stream_chunck->sequence_number ); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
99 printf(" unknown: 0x%02X\n", stream_chunck->unknown ); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
100 printf(" size_confirm: 0x%02X\n", stream_chunck->size_confirm ); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
101 */ |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
102 switch(stream_chunck->type) { |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
103 case 0x4324: // $C Clear ASF configuration |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
104 printf("=====> Clearing ASF stream configuration!\n"); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
105 if( drop_packet!=NULL ) *drop_packet = 1; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
106 return stream_chunck->size; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
107 break; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
108 case 0x4424: // $D Data follows |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
109 // printf("=====> Data follows\n"); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
110 break; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
111 case 0x4524: // $E Transfer complete |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
112 printf("=====> Transfer complete\n"); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
113 if( drop_packet!=NULL ) *drop_packet = 1; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
114 return stream_chunck->size; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
115 break; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
116 case 0x4824: // $H ASF header chunk follows |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
117 printf("=====> ASF header chunk follows\n"); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
118 break; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
119 default: |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
120 printf("=====> Unknown stream type 0x%x\n", stream_chunck->type ); |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
121 } |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
122 return stream_chunck->size+4; |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
123 } |
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
4041
diff
changeset
|
124 |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
125 static int |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
126 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
|
127 ASF_header_t asfh; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
128 ASF_obj_header_t objh; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
129 ASF_file_header_t fileh; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
130 ASF_stream_header_t streamh; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
131 ASF_stream_chunck_t chunk; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
132 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
|
133 char* buffer=NULL, *chunk_buffer=NULL; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
134 int i,r,size,pos = 0; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
135 int buffer_size = 0; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
136 int chunk_size2read = 0; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
137 |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
138 if(asf_ctrl == NULL) return -1; |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
139 |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
140 // 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
|
141 // 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
|
142 // 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
|
143 do { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
144 for( r=0; r < sizeof(ASF_stream_chunck_t) ; ) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
145 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
|
146 if(i <= 0) return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
147 r += i; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
148 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
149 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
|
150 if(r) printf("Warning : drop header ????\n"); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
151 if(size < 0){ |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
152 printf("Error while parsing chunk header\n"); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
153 return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
154 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
155 if (chunk.type != 0x4824) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
156 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
|
157 return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
158 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
159 |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
160 buffer = (char*) malloc(size+buffer_size); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
161 if(buffer == NULL) { |
3551 | 162 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
|
163 return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
164 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
165 if( chunk_buffer!=NULL ) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
166 memcpy( buffer, chunk_buffer, buffer_size ); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
167 free( chunk_buffer ); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
168 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
169 chunk_buffer = buffer; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
170 buffer += buffer_size; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
171 buffer_size += size; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
172 |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
173 for(r = 0; r < size;) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
174 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
|
175 if(i < 0) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
176 printf("Error while reading network stream\n"); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
177 return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
178 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
179 r += i; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
180 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
181 |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
182 if( chunk_size2read==0 ) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
183 if(size < (int)sizeof(asfh)) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
184 printf("Error chunk is too small\n"); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
185 return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
186 } else printf("Got chunk\n"); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
187 memcpy(&asfh,buffer,sizeof(asfh)); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
188 le2me_ASF_header_t(&asfh); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
189 chunk_size2read = asfh.objh.size; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
190 printf("Size 2 read=%d\n", chunk_size2read); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
191 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
192 } while( buffer_size<chunk_size2read); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
193 buffer = chunk_buffer; |
3551 | 194 size = buffer_size; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
195 |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
196 if(asfh.cno > 256) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
197 printf("Error sub chunks number is invalid\n"); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
198 return -1; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
199 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
200 |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
201 pos += sizeof(asfh); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
202 |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
203 while(size - pos >= (int)sizeof(objh)) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
204 memcpy(&objh,buffer+pos,sizeof(objh)); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
205 le2me_ASF_obj_header_t(&objh); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
206 |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
207 switch(ASF_LOAD_GUID_PREFIX(objh.guid)) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
208 case 0x8CABDCA1 : // File header |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
209 pos += sizeof(objh); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
210 memcpy(&fileh,buffer + pos,sizeof(fileh)); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
211 le2me_ASF_file_header_t(&fileh); |
4288
b84e9861461c
Changed the asf_file_header_t struct to read all the fields properly.
bertrand
parents:
4145
diff
changeset
|
212 /* |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
213 if(fileh.packetsize != fileh.packetsize2) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
214 printf("Error packetsize check don't match\n"); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
215 return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
216 } |
4288
b84e9861461c
Changed the asf_file_header_t struct to read all the fields properly.
bertrand
parents:
4145
diff
changeset
|
217 */ |
b84e9861461c
Changed the asf_file_header_t struct to read all the fields properly.
bertrand
parents:
4145
diff
changeset
|
218 asf_ctrl->packet_size = fileh.max_packet_size; |
b84e9861461c
Changed the asf_file_header_t struct to read all the fields properly.
bertrand
parents:
4145
diff
changeset
|
219 // before playing. |
b84e9861461c
Changed the asf_file_header_t struct to read all the fields properly.
bertrand
parents:
4145
diff
changeset
|
220 // preroll: time in ms to bufferize before playing |
b84e9861461c
Changed the asf_file_header_t struct to read all the fields properly.
bertrand
parents:
4145
diff
changeset
|
221 streaming_ctrl->prebuffer_size = (unsigned int)((double)((double)fileh.preroll/1000)*((double)fileh.max_bitrate/8)); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
222 pos += sizeof(fileh); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
223 break; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
224 case 0xB7DC0791 : // stream header |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
225 pos += sizeof(objh); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
226 memcpy(&streamh,buffer + pos,sizeof(streamh)); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
227 le2me_ASF_stream_header_t(&streamh); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
228 pos += sizeof(streamh) + streamh.type_size; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
229 switch(ASF_LOAD_GUID_PREFIX(streamh.type)) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
230 case 0xF8699E40 : // audio stream |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
231 if(asf_ctrl->audio_streams == NULL){ |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
232 asf_ctrl->audio_streams = (int*)malloc(sizeof(int)); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
233 asf_ctrl->n_audio = 1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
234 } else { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
235 asf_ctrl->n_audio++; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
236 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
|
237 asf_ctrl->n_audio*sizeof(int)); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
238 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
239 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
|
240 pos += streamh.stream_size; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
241 break; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
242 case 0xBC19EFC0 : // video stream |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
243 if(asf_ctrl->video_streams == NULL){ |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
244 asf_ctrl->video_streams = (int*)malloc(sizeof(int)); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
245 asf_ctrl->n_video = 1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
246 } else { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
247 asf_ctrl->n_video++; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
248 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
|
249 asf_ctrl->n_video*sizeof(int)); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
250 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
251 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
|
252 break; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
253 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
254 break; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
255 default : |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
256 pos += objh.size; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
257 break; |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
258 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
259 } |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
260 free(buffer); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
261 return 1; |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
262 } |
3042 | 263 |
264 int | |
265 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
|
266 static ASF_stream_chunck_t chunk; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
267 int read,chunk_size = 0; |
4041
879a668ee540
various small streaming fixes by Alban Bedel <albeu@free.fr>
arpi
parents:
3727
diff
changeset
|
268 static int rest = 0, drop_chunk = 0, waiting = 0,eof= 0; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
269 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
|
270 |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
271 while(1) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
272 if (rest == 0 && waiting == 0) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
273 read = 0; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
274 while(read < (int)sizeof(ASF_stream_chunck_t)){ |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
275 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
|
276 sizeof(ASF_stream_chunck_t)-read, |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
277 streaming_ctrl ); |
4041
879a668ee540
various small streaming fixes by Alban Bedel <albeu@free.fr>
arpi
parents:
3727
diff
changeset
|
278 if(r <= 0){ |
879a668ee540
various small streaming fixes by Alban Bedel <albeu@free.fr>
arpi
parents:
3727
diff
changeset
|
279 if( r < 0) |
879a668ee540
various small streaming fixes by Alban Bedel <albeu@free.fr>
arpi
parents:
3727
diff
changeset
|
280 printf("Error while reading chunk header\n"); |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
281 return -1; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
282 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
283 read += r; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
284 } |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
285 chunk_size = asf_streaming( &chunk, &drop_chunk ); |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
286 if(chunk_size < 0) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
287 printf("Error while parsing chunk header\n"); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
288 return -1; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
289 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
290 chunk_size -= sizeof(ASF_stream_chunck_t); |
3042 | 291 |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
292 if(chunk.type != 0x4824 && (!drop_chunk)) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
293 if (asf_http_ctrl->packet_size < chunk_size) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
294 printf("Error chunk_size > packet_size\n"); |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
295 return -1; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
296 } |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
297 waiting = asf_http_ctrl->packet_size; |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
298 } else { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
299 waiting = chunk_size; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
300 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
301 |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
302 } else if (rest){ |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
303 chunk_size = rest; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
304 rest = 0; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
305 } |
3042 | 306 |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
307 read = 0; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
308 if ( waiting >= chunk_size) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
309 if (chunk_size > size){ |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
310 rest = chunk_size - size; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
311 chunk_size = size; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
312 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
313 while(read < chunk_size) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
314 int got = nop_streaming_read( fd,buffer+read,chunk_size-read,streaming_ctrl ); |
4041
879a668ee540
various small streaming fixes by Alban Bedel <albeu@free.fr>
arpi
parents:
3727
diff
changeset
|
315 if(got <= 0) { |
879a668ee540
various small streaming fixes by Alban Bedel <albeu@free.fr>
arpi
parents:
3727
diff
changeset
|
316 if(got < 0) |
879a668ee540
various small streaming fixes by Alban Bedel <albeu@free.fr>
arpi
parents:
3727
diff
changeset
|
317 printf("Error while reading chunk\n"); |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
318 return -1; |
1001 | 319 } |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
320 read += got; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
321 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
322 waiting -= read; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
323 if (drop_chunk) continue; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
324 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
325 if (rest == 0 && waiting > 0 && size-read > 0) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
326 int s = MIN(waiting,size-read); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
327 memset(buffer+read,0,s); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
328 waiting -= s; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
329 read += s; |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
330 } |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
331 break; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
332 } |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
333 |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
334 return read; |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
335 } |
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
336 |
905 | 337 int |
3042 | 338 asf_http_streaming_seek( int fd, off_t pos, streaming_ctrl_t *streaming_ctrl ) { |
339 return -1; | |
340 } | |
341 | |
342 int | |
905 | 343 asf_http_streaming_type(char *content_type, char *features) { |
344 if( content_type==NULL ) return ASF_Unknown_e; | |
833 | 345 if( !strcasecmp(content_type, "application/octet-stream") ) { |
905 | 346 if( features==NULL ) { |
1001 | 347 printf("=====> ASF Prerecorded\n"); |
905 | 348 return ASF_Prerecorded_e; |
349 } else if( strstr(features, "broadcast")) { | |
1001 | 350 printf("=====> ASF Live stream\n"); |
905 | 351 return ASF_Live_e; |
833 | 352 } else { |
1001 | 353 printf("=====> ASF Prerecorded\n"); |
905 | 354 return ASF_Prerecorded_e; |
833 | 355 } |
356 } else { | |
871 | 357 if( (!strcasecmp(content_type, "audio/x-ms-wax")) || |
833 | 358 (!strcasecmp(content_type, "audio/x-ms-wma")) || |
359 (!strcasecmp(content_type, "video/x-ms-asf")) || | |
360 (!strcasecmp(content_type, "video/x-ms-afs")) || | |
361 (!strcasecmp(content_type, "video/x-ms-wvx")) || | |
362 (!strcasecmp(content_type, "video/x-ms-wmv")) || | |
363 (!strcasecmp(content_type, "video/x-ms-wma")) ) { | |
1001 | 364 printf("=====> ASF Redirector\n"); |
905 | 365 return ASF_Redirector_e; |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
366 } else if( !strcasecmp(content_type, "text/plain") ) { |
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
367 printf("=====> ASF Plain text\n"); |
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
368 return ASF_PlainText_e; |
833 | 369 } else { |
1001 | 370 printf("=====> ASF unknown content-type: %s\n", content_type ); |
905 | 371 return ASF_Unknown_e; |
833 | 372 } |
373 } | |
905 | 374 return ASF_Unknown_e; |
833 | 375 } |
871 | 376 |
905 | 377 HTTP_header_t * |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
378 asf_http_request(streaming_ctrl_t *streaming_ctrl) { |
871 | 379 HTTP_header_t *http_hdr; |
4121 | 380 URL_t *url = NULL; |
381 URL_t *server_url = NULL; | |
382 asf_http_streaming_ctrl_t *asf_http_ctrl; | |
871 | 383 char str[250]; |
1001 | 384 char *ptr; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
385 int i,as = -1,vs = -1; |
871 | 386 |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
387 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
|
388 int asf_nb_stream=0; |
871 | 389 |
4121 | 390 // Sanity check |
391 if( streaming_ctrl==NULL ) return NULL; | |
392 url = streaming_ctrl->url; | |
393 asf_http_ctrl = (asf_http_streaming_ctrl_t*)streaming_ctrl->data; | |
394 if( url==NULL || asf_http_ctrl==NULL ) return NULL; | |
395 | |
871 | 396 // Common header for all requests. |
397 http_hdr = http_new_header(); | |
398 http_set_field( http_hdr, "Accept: */*" ); | |
399 http_set_field( http_hdr, "User-Agent: NSPlayer/4.1.0.3856" ); | |
4121 | 400 |
401 // Check if we are using a proxy | |
4145 | 402 if( !strcasecmp( url->protocol, "http_proxy" ) ) { |
4121 | 403 server_url = url_new( (url->file)+1 ); |
404 if( server_url==NULL ) { | |
405 printf("Invalid proxy URL\n"); | |
406 http_free( http_hdr ); | |
407 return NULL; | |
408 } | |
409 http_set_uri( http_hdr, server_url->url ); | |
410 sprintf( str, "Host: %s:%d", server_url->hostname, server_url->port ); | |
411 url_free( server_url ); | |
412 } else { | |
413 http_set_uri( http_hdr, url->file ); | |
414 sprintf( str, "Host: %s:%d", url->hostname, url->port ); | |
415 } | |
416 | |
871 | 417 http_set_field( http_hdr, str ); |
418 http_set_field( http_hdr, "Pragma: xClientGUID={c77e7400-738a-11d2-9add-0020af0a3278}" ); | |
419 sprintf(str, | |
420 "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
|
421 offset_hi, offset_lo, asf_http_ctrl->request, length ); |
871 | 422 http_set_field( http_hdr, str ); |
423 | |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
424 switch( asf_http_ctrl->streaming_type ) { |
871 | 425 case ASF_Live_e: |
426 case ASF_Prerecorded_e: | |
427 http_set_field( http_hdr, "Pragma: xPlayStrm=1" ); | |
1001 | 428 ptr = str; |
429 ptr += sprintf( ptr, "Pragma: stream-switch-entry="); | |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
430 if(asf_http_ctrl->n_audio > 0) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
431 if(audio_id > 0) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
432 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
|
433 if(asf_http_ctrl->audio_streams[i] == audio_id) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
434 as = audio_id; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
435 break; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
436 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
437 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
438 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
439 if(as < 0) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
440 if(audio_id > 0) |
3727 | 441 printf("Audio stream %d don't exist\n", as); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
442 as = asf_http_ctrl->audio_streams[0]; |
1001 | 443 } |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
444 ptr += sprintf(ptr, " ffff:%d:0",as); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
445 asf_nb_stream++; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
446 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
447 if(asf_http_ctrl->n_video > 0) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
448 if(video_id > 0) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
449 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
|
450 if(asf_http_ctrl->video_streams[i] == video_id) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
451 vs = video_id; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
452 break; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
453 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
454 } |
1001 | 455 } |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
456 if(vs < 0) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
457 if(video_id > 0) |
3727 | 458 printf("Video stream %d don't exist\n",vs); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
459 vs = asf_http_ctrl->video_streams[0]; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
460 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
461 ptr += sprintf( ptr, " ffff:%d:0",vs); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
462 asf_nb_stream++; |
1001 | 463 } |
464 http_set_field( http_hdr, str ); | |
871 | 465 sprintf( str, "Pragma: stream-switch-count=%d", asf_nb_stream ); |
466 http_set_field( http_hdr, str ); | |
467 break; | |
468 case ASF_Redirector_e: | |
469 break; | |
470 case ASF_Unknown_e: | |
471 // First request goes here. | |
472 break; | |
473 default: | |
474 printf("Unknown asf stream type\n"); | |
475 } | |
476 | |
477 http_set_field( http_hdr, "Connection: Close" ); | |
905 | 478 http_build_request( http_hdr ); |
871 | 479 |
905 | 480 return http_hdr; |
871 | 481 } |
482 | |
483 int | |
905 | 484 asf_http_parse_response( HTTP_header_t *http_hdr ) { |
871 | 485 char *content_type, *pragma; |
486 char features[64] = "\0"; | |
487 int len; | |
905 | 488 if( http_response_parse(http_hdr)<0 ) { |
489 printf("Failed to parse HTTP response\n"); | |
490 return -1; | |
491 } | |
871 | 492 if( http_hdr->status_code!=200 ) { |
493 printf("Server return %d:%s\n", http_hdr->status_code, http_hdr->reason_phrase); | |
494 return -1; | |
495 } | |
496 | |
497 content_type = http_get_field( http_hdr, "Content-Type"); | |
3042 | 498 //printf("Content-Type: [%s]\n", content_type); |
871 | 499 |
500 pragma = http_get_field( http_hdr, "Pragma"); | |
905 | 501 while( pragma!=NULL ) { |
871 | 502 char *comma_ptr=NULL; |
503 char *end; | |
3042 | 504 //printf("Pragma: [%s]\n", pragma ); |
871 | 505 // The pragma line can get severals attributes |
506 // separeted with a comma ','. | |
507 do { | |
508 if( !strncasecmp( pragma, "features=", 9) ) { | |
509 pragma += 9; | |
510 end = strstr( pragma, "," ); | |
511 if( end==NULL ) { | |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
512 int s = strlen(pragma); |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
513 if(s > sizeof(features)) { |
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
514 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
|
515 len = sizeof(features); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
516 } else { |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
517 len = s; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
518 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
519 } else { |
3475
390388c75209
Applied the patch from Alban Bedel <albeu@free.fr> to
bertrand
parents:
3454
diff
changeset
|
520 len = MIN(end-pragma,sizeof(features)); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
521 } |
871 | 522 strncpy( features, pragma, len ); |
523 features[len]='\0'; | |
524 break; | |
525 } | |
526 comma_ptr = strstr( pragma, "," ); | |
527 if( comma_ptr!=NULL ) { | |
528 pragma = comma_ptr+1; | |
529 if( pragma[0]==' ' ) pragma++; | |
530 } | |
531 } while( comma_ptr!=NULL ); | |
532 pragma = http_get_next_field( http_hdr ); | |
905 | 533 } |
534 | |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
535 return asf_http_streaming_type( content_type, features ); |
871 | 536 } |
537 | |
905 | 538 int |
3042 | 539 asf_http_streaming_start( stream_t *stream ) { |
905 | 540 HTTP_header_t *http_hdr=NULL; |
541 URL_t *url_next=NULL; | |
3042 | 542 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
|
543 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
|
544 ASF_StreamType_e streaming_type; |
905 | 545 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
|
546 int i, ret; |
3042 | 547 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
|
548 int done; |
1001 | 549 |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
550 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
|
551 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
|
552 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
|
553 return -1; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
554 } |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
555 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
|
556 asf_http_ctrl->request = 1; |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
557 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
|
558 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
|
559 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
|
560 |
905 | 561 do { |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
562 done = 1; |
905 | 563 if( fd>0 ) close( fd ); |
1001 | 564 |
4145 | 565 if( !strcasecmp( url->protocol, "http_proxy" ) ) { |
4121 | 566 if( url->port==0 ) url->port = 8080; |
567 } else { | |
568 if( url->port==0 ) url->port = 80; | |
569 } | |
905 | 570 fd = connect2Server( url->hostname, url->port ); |
571 if( fd<0 ) return -1; | |
572 | |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
573 http_hdr = asf_http_request( stream->streaming_ctrl ); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
574 if( verbose>0 ) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
575 printf("Request [%s]\n", http_hdr->buffer ); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
576 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
577 for(i=0; i < http_hdr->buffer_size ; ) { |
3494
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3475
diff
changeset
|
578 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
|
579 if(r <0) { |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
580 printf("Socket write error : %s\n",strerror(errno)); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
581 return -1; |
3494
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3475
diff
changeset
|
582 } |
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3475
diff
changeset
|
583 i += r; |
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3475
diff
changeset
|
584 } |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
585 http_free( http_hdr ); |
905 | 586 http_hdr = http_new_header(); |
587 do { | |
3042 | 588 i = read( fd, buffer, BUFFER_SIZE ); |
4121 | 589 //printf("read: %d\n", i ); |
1001 | 590 if( i<0 ) { |
591 perror("read"); | |
592 http_free( http_hdr ); | |
593 return -1; | |
594 } | |
905 | 595 http_response_append( http_hdr, buffer, i ); |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
596 } while( !http_is_header_entire( http_hdr ) ); |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
597 if( verbose>0 ) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
598 http_hdr->buffer[http_hdr->buffer_size]='\0'; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
599 printf("Response [%s]\n", http_hdr->buffer ); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
600 } |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
601 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
|
602 if( streaming_type<0 ) { |
905 | 603 printf("Failed to parse header\n"); |
1001 | 604 http_free( http_hdr ); |
905 | 605 return -1; |
606 } | |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
607 asf_http_ctrl->streaming_type = streaming_type; |
1001 | 608 switch( streaming_type ) { |
905 | 609 case ASF_Live_e: |
610 case ASF_Prerecorded_e: | |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
611 case ASF_PlainText_e: |
1001 | 612 if( http_hdr->body_size>0 ) { |
3042 | 613 if( streaming_bufferize( stream->streaming_ctrl, http_hdr->body, http_hdr->body_size )<0 ) { |
614 http_free( http_hdr ); | |
615 return -1; | |
1001 | 616 } |
905 | 617 } |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
618 if( asf_http_ctrl->request==1 ) { |
3533
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
619 if( streaming_type!=ASF_PlainText_e ) { |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
620 // First request, we only got the ASF header. |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
621 ret = asf_streaming_parse_header(fd,stream->streaming_ctrl); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
622 if(ret < 0) return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
623 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
|
624 printf("No stream found\n"); |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
625 return -1; |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
626 } |
6e6a74d2d1ea
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3494
diff
changeset
|
627 } |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
628 asf_http_ctrl->request++; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
629 done = 0; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
630 } |
905 | 631 break; |
632 case ASF_Redirector_e: | |
4073
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
633 if( http_hdr->body_size>0 ) { |
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
634 if( streaming_bufferize( stream->streaming_ctrl, http_hdr->body, http_hdr->body_size )<0 ) { |
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
635 http_free( http_hdr ); |
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
636 return -1; |
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
637 } |
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
638 } |
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
639 stream->type = STREAMTYPE_PLAYLIST; |
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
640 done = 1; |
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
641 break; |
905 | 642 case ASF_Unknown_e: |
643 default: | |
644 printf("Unknown ASF streaming type\n"); | |
645 close(fd); | |
1001 | 646 http_free( http_hdr ); |
905 | 647 return -1; |
648 } | |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
649 // Check if we got a redirect. |
905 | 650 } while(!done); |
651 | |
4073
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
652 stream->fd = fd; |
4041
879a668ee540
various small streaming fixes by Alban Bedel <albeu@free.fr>
arpi
parents:
3727
diff
changeset
|
653 if( streaming_type==ASF_PlainText_e || streaming_type==ASF_Redirector_e ) { |
3042 | 654 stream->streaming_ctrl->streaming_read = nop_streaming_read; |
655 stream->streaming_ctrl->streaming_seek = nop_streaming_seek; | |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
656 } else { |
3042 | 657 stream->streaming_ctrl->streaming_read = asf_http_streaming_read; |
658 stream->streaming_ctrl->streaming_seek = asf_http_streaming_seek; | |
4288
b84e9861461c
Changed the asf_file_header_t struct to read all the fields properly.
bertrand
parents:
4145
diff
changeset
|
659 stream->streaming_ctrl->buffering = 1; |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
660 } |
3042 | 661 stream->streaming_ctrl->status = streaming_playing_e; |
1001 | 662 |
663 http_free( http_hdr ); | |
4073
5f28d9d7d346
Changed the return value of the start function. Doesn't return the fd
bertrand
parents:
4046
diff
changeset
|
664 return 0; |
905 | 665 } |
666 |