winlin

for #293, support http mp3 streaming

@@ -245,6 +245,10 @@ int SrsMp3StreamEncoder::initialize(SrsFileWriter* w) @@ -245,6 +245,10 @@ int SrsMp3StreamEncoder::initialize(SrsFileWriter* w)
245 return ret; 245 return ret;
246 } 246 }
247 247
  248 + if ((ret = enc->write_header()) != ERROR_SUCCESS) {
  249 + return ret;
  250 + }
  251 +
248 return ret; 252 return ret;
249 } 253 }
250 254
@@ -316,22 +320,24 @@ int SrsLiveStream::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r) @@ -316,22 +320,24 @@ int SrsLiveStream::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
316 { 320 {
317 int ret = ERROR_SUCCESS; 321 int ret = ERROR_SUCCESS;
318 322
319 - bool serve_flv_streaming = false;  
320 - bool serve_aac_streaming = false;  
321 - bool serve_mp3_streaming = false; 323 + ISrsStreamEncoder* enc = NULL;
322 324
323 srs_assert(entry); 325 srs_assert(entry);
324 if (srs_string_ends_with(entry->pattern, ".flv")) { 326 if (srs_string_ends_with(entry->pattern, ".flv")) {
325 - serve_flv_streaming = true; 327 + w->header()->set_content_type("video/x-flv");
  328 + enc = new SrsFlvStreamEncoder();
326 } else if (srs_string_ends_with(entry->pattern, ".aac")) { 329 } else if (srs_string_ends_with(entry->pattern, ".aac")) {
327 - serve_aac_streaming = true; 330 + w->header()->set_content_type("audio/x-aac");
  331 + enc = new SrsAacStreamEncoder();
328 } else if (srs_string_ends_with(entry->pattern, ".mp3")) { 332 } else if (srs_string_ends_with(entry->pattern, ".mp3")) {
329 - serve_mp3_streaming = true; 333 + w->header()->set_content_type("audio/mpeg");
  334 + enc = new SrsMp3StreamEncoder();
330 } else { 335 } else {
331 ret = ERROR_HTTP_LIVE_STREAM_EXT; 336 ret = ERROR_HTTP_LIVE_STREAM_EXT;
332 srs_error("http: unsupported pattern %s", entry->pattern.c_str()); 337 srs_error("http: unsupported pattern %s", entry->pattern.c_str());
333 return ret; 338 return ret;
334 } 339 }
  340 + SrsAutoFree(ISrsStreamEncoder, enc);
335 341
336 // create consumer of souce. 342 // create consumer of souce.
337 SrsConsumer* consumer = NULL; 343 SrsConsumer* consumer = NULL;
@@ -344,31 +350,9 @@ int SrsLiveStream::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r) @@ -344,31 +350,9 @@ int SrsLiveStream::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
344 350
345 SrsMessageArray msgs(SRS_PERF_MW_MSGS); 351 SrsMessageArray msgs(SRS_PERF_MW_MSGS);
346 // TODO: FIMXE: add pithy print. 352 // TODO: FIMXE: add pithy print.
347 -  
348 - // write http header for streaming.  
349 - // use chunked encoding, for we donot specifes the content length.  
350 - if (serve_flv_streaming) {  
351 - w->header()->set_content_type("video/x-flv");  
352 - }  
353 - if (serve_aac_streaming) {  
354 - w->header()->set_content_type("audio/x-aac");  
355 - }  
356 353
357 // the memory writer. 354 // the memory writer.
358 SrsStreamWriter writer(w); 355 SrsStreamWriter writer(w);
359 -  
360 - ISrsStreamEncoder* enc = NULL;  
361 - if (serve_flv_streaming) {  
362 - enc = new SrsFlvStreamEncoder();  
363 - }  
364 - if (serve_aac_streaming) {  
365 - enc = new SrsAacStreamEncoder();  
366 - }  
367 - if (serve_mp3_streaming) {  
368 - enc = new SrsMp3StreamEncoder();  
369 - }  
370 - SrsAutoFree(ISrsStreamEncoder, enc);  
371 -  
372 if ((ret = enc->initialize(&writer)) != ERROR_SUCCESS) { 356 if ((ret = enc->initialize(&writer)) != ERROR_SUCCESS) {
373 return ret; 357 return ret;
374 } 358 }