MP3 support for the progressive connector

This commit is contained in:
Erik Zandvliet 2013-03-07 20:55:31 +01:00
parent 7a887d5cd2
commit d72062ee92

View file

@ -38,6 +38,8 @@ namespace Connector_HTTP {
unsigned int seek_sec = 0; //seek position in ms
unsigned int seek_byte = 0; //seek position in bytes
bool isMP3 = false;
while (conn.connected()){
//only parse input if available or not yet init'ed
if ( !inited){
@ -61,6 +63,9 @@ namespace Connector_HTTP {
streamname = HTTP_R.getUrl().substr(1);
size_t extDot = streamname.rfind('.');
if (extDot != std::string::npos){
if (streamname.substr(extDot + 1) == "mp3"){
isMP3 = true;
}
streamname.resize(extDot);
}; //strip the extension
int start = 0;
@ -115,7 +120,7 @@ namespace Connector_HTTP {
}
}
int byterate = 0;
if (Strm.metadata.isMember("video")){
if (Strm.metadata.isMember("video") && !isMP3){
byterate += Strm.metadata["video"]["bps"].asInt();
}
if (Strm.metadata.isMember("audio")){
@ -143,10 +148,15 @@ namespace Connector_HTTP {
while (Strm.parsePacket(ss.Received())){
if ( !progressive_has_sent_header){
HTTP_S.Clean(); //make sure no parts of old requests are left in any buffers
if (!isMP3){
HTTP_S.SetHeader("Content-Type", "video/x-flv"); //Send the correct content-type for FLV files
}else{
HTTP_S.SetHeader("Content-Type", "audio/mpeg"); //Send the correct content-type for MP3 files
}
//HTTP_S.SetHeader("Transfer-Encoding", "chunked");
HTTP_S.protocol = "HTTP/1.0";
conn.SendNow(HTTP_S.BuildResponse("200", "OK")); //no SetBody = unknown length - this is intentional, we will stream the entire file
if ( !isMP3){
conn.SendNow(FLV::Header, 13); //write FLV header
//write metadata
tag.DTSCMetaInit(Strm);
@ -161,13 +171,20 @@ namespace Connector_HTTP {
tag.DTSCAudioInit(Strm);
conn.SendNow(tag.data, tag.len);
}
}
progressive_has_sent_header = true;
#if DEBUG >= 1
fprintf(stderr, "Sent progressive FLV header\n");
#endif
}
if ( !isMP3){
tag.DTSCLoader(Strm);
conn.SendNow(tag.data, tag.len); //write the tag contents
}else{
if(Strm.lastType() == DTSC::AUDIO){
conn.SendNow(Strm.lastData()); //write the MP3 contents
}
}
}
}else{
Util::sleep(1);