MP3 support for the progressive connector
This commit is contained in:
parent
7a887d5cd2
commit
d72062ee92
1 changed files with 33 additions and 16 deletions
|
@ -38,6 +38,8 @@ namespace Connector_HTTP {
|
||||||
unsigned int seek_sec = 0; //seek position in ms
|
unsigned int seek_sec = 0; //seek position in ms
|
||||||
unsigned int seek_byte = 0; //seek position in bytes
|
unsigned int seek_byte = 0; //seek position in bytes
|
||||||
|
|
||||||
|
bool isMP3 = false;
|
||||||
|
|
||||||
while (conn.connected()){
|
while (conn.connected()){
|
||||||
//only parse input if available or not yet init'ed
|
//only parse input if available or not yet init'ed
|
||||||
if ( !inited){
|
if ( !inited){
|
||||||
|
@ -61,6 +63,9 @@ namespace Connector_HTTP {
|
||||||
streamname = HTTP_R.getUrl().substr(1);
|
streamname = HTTP_R.getUrl().substr(1);
|
||||||
size_t extDot = streamname.rfind('.');
|
size_t extDot = streamname.rfind('.');
|
||||||
if (extDot != std::string::npos){
|
if (extDot != std::string::npos){
|
||||||
|
if (streamname.substr(extDot + 1) == "mp3"){
|
||||||
|
isMP3 = true;
|
||||||
|
}
|
||||||
streamname.resize(extDot);
|
streamname.resize(extDot);
|
||||||
}; //strip the extension
|
}; //strip the extension
|
||||||
int start = 0;
|
int start = 0;
|
||||||
|
@ -115,7 +120,7 @@ namespace Connector_HTTP {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int byterate = 0;
|
int byterate = 0;
|
||||||
if (Strm.metadata.isMember("video")){
|
if (Strm.metadata.isMember("video") && !isMP3){
|
||||||
byterate += Strm.metadata["video"]["bps"].asInt();
|
byterate += Strm.metadata["video"]["bps"].asInt();
|
||||||
}
|
}
|
||||||
if (Strm.metadata.isMember("audio")){
|
if (Strm.metadata.isMember("audio")){
|
||||||
|
@ -143,10 +148,15 @@ namespace Connector_HTTP {
|
||||||
while (Strm.parsePacket(ss.Received())){
|
while (Strm.parsePacket(ss.Received())){
|
||||||
if ( !progressive_has_sent_header){
|
if ( !progressive_has_sent_header){
|
||||||
HTTP_S.Clean(); //make sure no parts of old requests are left in any buffers
|
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
|
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.SetHeader("Transfer-Encoding", "chunked");
|
||||||
HTTP_S.protocol = "HTTP/1.0";
|
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
|
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
|
conn.SendNow(FLV::Header, 13); //write FLV header
|
||||||
//write metadata
|
//write metadata
|
||||||
tag.DTSCMetaInit(Strm);
|
tag.DTSCMetaInit(Strm);
|
||||||
|
@ -161,13 +171,20 @@ namespace Connector_HTTP {
|
||||||
tag.DTSCAudioInit(Strm);
|
tag.DTSCAudioInit(Strm);
|
||||||
conn.SendNow(tag.data, tag.len);
|
conn.SendNow(tag.data, tag.len);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
progressive_has_sent_header = true;
|
progressive_has_sent_header = true;
|
||||||
#if DEBUG >= 1
|
#if DEBUG >= 1
|
||||||
fprintf(stderr, "Sent progressive FLV header\n");
|
fprintf(stderr, "Sent progressive FLV header\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
if ( !isMP3){
|
||||||
tag.DTSCLoader(Strm);
|
tag.DTSCLoader(Strm);
|
||||||
conn.SendNow(tag.data, tag.len); //write the tag contents
|
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{
|
}else{
|
||||||
Util::sleep(1);
|
Util::sleep(1);
|
||||||
|
|
Loading…
Add table
Reference in a new issue