comparison stream/stream.c @ 25135:66f628d13442

Support stream redirection from http to mms, fix bug #927.
author ulion
date Mon, 26 Nov 2007 00:41:21 +0000
parents 0a733c2c577e
children 919916007cd2
comparison
equal deleted inserted replaced
25134:dcf1bfb29dc8 25135:66f628d13442
143 &stream_info_file, 143 &stream_info_file,
144 NULL 144 NULL
145 }; 145 };
146 146
147 stream_t* open_stream_plugin(stream_info_t* sinfo,char* filename,int mode, 147 stream_t* open_stream_plugin(stream_info_t* sinfo,char* filename,int mode,
148 char** options, int* file_format, int* ret) { 148 char** options, int* file_format, int* ret,
149 char** redirected_url) {
149 void* arg = NULL; 150 void* arg = NULL;
150 stream_t* s; 151 stream_t* s;
151 m_struct_t* desc = (m_struct_t*)sinfo->opts; 152 m_struct_t* desc = (m_struct_t*)sinfo->opts;
152 153
153 // Parse options 154 // Parse options
176 s = new_stream(-2,-2); 177 s = new_stream(-2,-2);
177 s->url=strdup(filename); 178 s->url=strdup(filename);
178 s->flags |= mode; 179 s->flags |= mode;
179 *ret = sinfo->open(s,mode,arg,file_format); 180 *ret = sinfo->open(s,mode,arg,file_format);
180 if((*ret) != STREAM_OK) { 181 if((*ret) != STREAM_OK) {
182 #ifdef MPLAYER_NETWORK
183 if (*ret == STREAM_REDIRECTED && redirected_url) {
184 if (s->streaming_ctrl && s->streaming_ctrl->url
185 && s->streaming_ctrl->url->url)
186 *redirected_url = strdup(s->streaming_ctrl->url->url);
187 else
188 *redirected_url = NULL;
189 }
190 streaming_ctrl_free(s->streaming_ctrl);
191 #endif
181 free(s->url); 192 free(s->url);
182 free(s); 193 free(s);
183 return NULL; 194 return NULL;
184 } 195 }
185 if(s->type <= -2) 196 if(s->type <= -2)
202 213
203 stream_t* open_stream_full(char* filename,int mode, char** options, int* file_format) { 214 stream_t* open_stream_full(char* filename,int mode, char** options, int* file_format) {
204 int i,j,l,r; 215 int i,j,l,r;
205 stream_info_t* sinfo; 216 stream_info_t* sinfo;
206 stream_t* s; 217 stream_t* s;
218 char *redirected_url = NULL;
207 219
208 for(i = 0 ; auto_open_streams[i] ; i++) { 220 for(i = 0 ; auto_open_streams[i] ; i++) {
209 sinfo = auto_open_streams[i]; 221 sinfo = auto_open_streams[i];
210 if(!sinfo->protocols) { 222 if(!sinfo->protocols) {
211 mp_msg(MSGT_OPEN,MSGL_WARN, "Stream type %s has protocols == NULL, it's a bug\n", sinfo->name); 223 mp_msg(MSGT_OPEN,MSGL_WARN, "Stream type %s has protocols == NULL, it's a bug\n", sinfo->name);
216 // l == 0 => Don't do protocol matching (ie network and filenames) 228 // l == 0 => Don't do protocol matching (ie network and filenames)
217 if((l == 0 && !strstr(filename, "://")) || 229 if((l == 0 && !strstr(filename, "://")) ||
218 ((strncmp(sinfo->protocols[j],filename,l) == 0) && 230 ((strncmp(sinfo->protocols[j],filename,l) == 0) &&
219 (strncmp("://",filename+l,3) == 0))) { 231 (strncmp("://",filename+l,3) == 0))) {
220 *file_format = DEMUXER_TYPE_UNKNOWN; 232 *file_format = DEMUXER_TYPE_UNKNOWN;
221 s = open_stream_plugin(sinfo,filename,mode,options,file_format,&r); 233 s = open_stream_plugin(sinfo,filename,mode,options,file_format,&r,
234 &redirected_url);
222 if(s) return s; 235 if(s) return s;
223 if(r != STREAM_UNSUPPORTED) { 236 if(r == STREAM_REDIRECTED && redirected_url) {
237 mp_msg(MSGT_OPEN,MSGL_V, "[%s] open %s redirected to %s\n",
238 sinfo->info, filename, redirected_url);
239 s = open_stream_full(redirected_url, mode, options, file_format);
240 free(redirected_url);
241 return s;
242 }
243 else if(r != STREAM_UNSUPPORTED) {
224 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_FailedToOpen,filename); 244 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_FailedToOpen,filename);
225 return NULL; 245 return NULL;
226 } 246 }
227 break; 247 break;
228 } 248 }