diff --git a/Buffer/Makefile b/Buffer/Makefile index 20469803..604cd26d 100644 --- a/Buffer/Makefile +++ b/Buffer/Makefile @@ -1,4 +1,4 @@ -SRC = main.cpp ../util/json/json_reader.cpp ../util/json/json_value.cpp ../util/json/json_writer.cpp ../util/socket.cpp ../util/flv_tag.cpp +SRC = main.cpp ../util/json/json_reader.cpp ../util/json/json_value.cpp ../util/json/json_writer.cpp ../util/socket.cpp ../util/dtsc.cpp OBJ = $(SRC:.cpp=.o) OUT = DDV_Buffer INCLUDES = diff --git a/Connector_HTTP/Makefile b/Connector_HTTP/Makefile index 4b296653..a57fa022 100644 --- a/Connector_HTTP/Makefile +++ b/Connector_HTTP/Makefile @@ -1,4 +1,4 @@ -SRC = main.cpp ../util/socket.cpp ../util/http_parser.cpp ../util/flv_tag.cpp ../util/amf.cpp ../util/util.cpp +SRC = main.cpp ../util/socket.cpp ../util/http_parser.cpp ../util/flv_tag.cpp ../util/amf.cpp ../util/dtsc.cpp ../util/util.cpp OBJ = $(SRC:.cpp=.o) OUT = DDV_Conn_HTTP INCLUDES = diff --git a/Connector_HTTP/main.cpp b/Connector_HTTP/main.cpp index 24d03510..da297cf8 100644 --- a/Connector_HTTP/main.cpp +++ b/Connector_HTTP/main.cpp @@ -13,6 +13,7 @@ #include #include "../util/socket.h" #include "../util/http_parser.h" +#include "../util/dtsc.h" #include "../util/flv_tag.h" #include "../util/MP4/interface.cpp" #include "../util/amf.h" @@ -149,26 +150,110 @@ namespace Connector_HTTP{ return Result; }//BuildManifest + /// Handles Progressive download streaming requests + void Progressive(FLV::Tag & tag, HTTP::Parser HTTP_S, Socket::Connection & conn, DTSC::Stream & Strm){ + static bool progressive_has_sent_header = false; + if (!progressive_has_sent_header){ + HTTP_S.Clean();//troep opruimen die misschien aanwezig is... + HTTP_S.SetHeader("Content-Type", "video/x-flv");//FLV files hebben altijd dit content-type. + //HTTP_S.SetHeader("Transfer-Encoding", "chunked"); + HTTP_S.protocol = "HTTP/1.0"; + HTTP_S.SendResponse(conn, "200", "OK");//geen SetBody = unknown length! Dat willen we hier. + //HTTP_S.SendBodyPart(CONN_fd, FLVHeader, 13);//schrijf de FLV header + conn.write(FLV::Header, 13); + FLV::Tag tmp; + tmp.DTSCMetaInit(Strm); + conn.write(tmp.data, tmp.len); + if (Strm.metadata.getContentP("audio") && Strm.metadata.getContentP("audio")->getContentP("init")){ + tmp.DTSCAudioInit(Strm); + conn.write(tmp.data, tmp.len); + } + if (Strm.metadata.getContentP("video") && Strm.metadata.getContentP("video")->getContentP("init")){ + tmp.DTSCVideoInit(Strm); + conn.write(tmp.data, tmp.len); + } + progressive_has_sent_header = true; + #if DEBUG >= 1 + fprintf(stderr, "Sent progressive FLV header\n"); + #endif + } + //HTTP_S.SendBodyPart(CONN_fd, tag->data, tag->len);//schrijf deze FLV tag onbewerkt weg + conn.write(tag.data, tag.len); + } + + /// Handles Flash Dynamic HTTP streaming requests + void FlashDynamic(FLV::Tag & tag, HTTP::Parser HTTP_S, Socket::Connection & conn, DTSC::Stream & Strm){ + static std::queue Flash_FragBuffer; + static unsigned int Flash_StartTime = 0; + static std::string FlashBuf; + static std::string FlashMeta; + static bool FlashFirstVideo = false; + static bool FlashFirstAudio = false; + static bool Flash_ManifestSent = false; + static int Flash_RequestPending = 0; + if (tag.tagTime() > 0){ + if (Flash_StartTime == 0){ + Flash_StartTime = tag.tagTime(); + } + tag.tagTime(tag.tagTime() - Flash_StartTime); + } + if (tag.data[0] != 0x12 ) { + if (tag.isKeyframe){ + if (FlashBuf != "" && !FlashFirstVideo && !FlashFirstAudio){ + Flash_FragBuffer.push(FlashBuf); + #if DEBUG >= 4 + fprintf(stderr, "Received a fragment. Now %i in buffer.\n", (int)Flash_FragBuffer.size()); + #endif + } + FlashBuf.clear(); + FlashFirstVideo = true; + FlashFirstAudio = true; + } + /// \todo Check metadata for video/audio, append if needed. + /* + if (FlashFirstVideo && (tag.data[0] == 0x09) && (Video_Init.len > 0)){ + Video_Init.tagTime(tag.tagTime()); + FlashBuf.append(Video_Init.data, Video_Init.len); + FlashFirstVideo = false; + } + if (FlashFirstAudio && (tag.data[0] == 0x08) && (Audio_Init.len > 0)){ + Audio_Init.tagTime(tag.tagTime()); + FlashBuf.append(Audio_Init.data, Audio_Init.len); + FlashFirstAudio = false; + } + #if DEBUG >= 5 + fprintf(stderr, "Received a tag of type %2hhu and length %i\n", tag.data[0], tag.len); + #endif + if ((Video_Init.len > 0) && (Audio_Init.len > 0)){ + FlashBuf.append(tag.data,tag.len); + } + */ + } else { + /* + FlashMeta = ""; + FlashMeta.append(tag.data+11,tag.len-15); + if( !Flash_ManifestSent ) { + HTTP_S.Clean(); + HTTP_S.SetHeader("Content-Type","text/xml"); + HTTP_S.SetHeader("Cache-Control","no-cache"); + HTTP_S.SetBody(BuildManifest(FlashMeta, Movie, tag.tagTime())); + HTTP_S.SendResponse(conn, "200", "OK"); + } + */ + } + } + + /// Main function for Connector_HTTP int Connector_HTTP(Socket::Connection conn){ int handler = HANDLER_PROGRESSIVE;///< The handler used for processing this request. bool ready4data = false;///< Set to true when streaming is to begin. bool inited = false; - bool progressive_has_sent_header = false; Socket::Connection ss(-1); std::string streamname; - std::string extension; - std::string FlashBuf; - std::string FlashMeta; - bool Flash_ManifestSent = false; - int Flash_RequestPending = 0; - unsigned int Flash_StartTime; - std::queue Flash_FragBuffer; - FLV::Tag tag;///< Temporary tag buffer for incoming video data. - FLV::Tag Audio_Init;///< Audio initialization data, if available. - FLV::Tag Video_Init;///< Video initialization data, if available. - bool FlashFirstVideo = false; - bool FlashFirstAudio = false; + FLV::Tag tag;///< Temporary tag buffer. + std::string recBuffer = ""; + DTSC::Stream Strm;///< Incoming stream buffer. HTTP::Parser HTTP_R, HTTP_S;//HTTP Receiver en HTTP Sender. std::string Movie = ""; @@ -179,7 +264,7 @@ namespace Connector_HTTP{ unsigned int lastStats = 0; //int CurrentFragment = -1; later herbruiken? - while (conn.connected() && !FLV::Parse_Error){ + while (conn.connected()){ //only parse input if available or not yet init'ed if (HTTP_R.Read(conn, ready4data)){ handler = HANDLER_PROGRESSIVE; @@ -209,8 +294,11 @@ namespace Connector_HTTP{ printf( "URL: %s\n", HTTP_R.url.c_str()); printf( "Movie: %s, Quality: %s, Seg %d Frag %d\n", Movie.c_str(), Quality.c_str(), Segment, ReqFragment); #endif + /// \todo Handle these requests properly... + /* Flash_ManifestSent = true;//stop manifest from being sent multiple times Flash_RequestPending++; + */ }else{ Movie = HTTP_R.url.substr(1); Movie = Movie.substr(0,Movie.find("/")); @@ -255,6 +343,8 @@ namespace Connector_HTTP{ #endif inited = true; } + /// \todo Send pending flash requests... + /* if ((Flash_RequestPending > 0) && !Flash_FragBuffer.empty()){ HTTP_S.Clean(); HTTP_S.SetHeader("Content-Type","video/mp4"); @@ -284,97 +374,16 @@ namespace Connector_HTTP{ break; case 0: break;//not ready yet default: - if (tag.SockLoader(ss)){//able to read a full packet? - if (handler == HANDLER_FLASH){ - if (tag.tagTime() > 0){ - if (Flash_StartTime == 0){ - Flash_StartTime = tag.tagTime(); - } - tag.tagTime(tag.tagTime() - Flash_StartTime); + if (ss.iread(recBuffer)){ + if (Strm.parsePacket(recBuffer)){ + tag.DTSCLoader(Strm); + if (handler == HANDLER_FLASH){ + FlashDynamic(tag, HTTP_S, conn, Strm); } - if (tag.data[0] != 0x12 ) { - if ( (tag.data[0] == 0x09) && tag.isInitData()){ - if (((tag.data[11] & 0x0f) == 7) && (tag.data[12] == 0)){ - tag.tagTime(0);//timestamp to zero - Video_Init = tag; - break; - } - } - if ((tag.data[0] == 0x08) && tag.isInitData()){ - if (((tag.data[11] & 0xf0) >> 4) == 10){//aac packet - tag.tagTime(0);//timestamp to zero - Audio_Init = tag; - break; - } - } - if (tag.isKeyframe){ - if (FlashBuf != "" && !FlashFirstVideo && !FlashFirstAudio){ - Flash_FragBuffer.push(FlashBuf); - #if DEBUG >= 4 - fprintf(stderr, "Received a fragment. Now %i in buffer.\n", (int)Flash_FragBuffer.size()); - #endif - } - FlashBuf.clear(); - FlashFirstVideo = true; - FlashFirstAudio = true; - } - if (FlashFirstVideo){ - if (Video_Init.len > 0){ - Video_Init.tagTime(tag.tagTime()); - FlashBuf.append(Video_Init.data, Video_Init.len); - } - FlashFirstVideo = false; - if (Audio_Init.len > 0){ - Audio_Init.tagTime(tag.tagTime()); - FlashBuf.append(Audio_Init.data, Audio_Init.len); - } - FlashFirstAudio = false; - } - #if DEBUG >= 5 - fprintf(stderr, "Received a tag of type %2hhu and length %i\n", tag.data[0], tag.len); - #endif - if (!FlashFirstVideo && !FlashFirstAudio){ - FlashBuf.append(tag.data,tag.len); - } - } else { - FlashMeta = ""; - FlashMeta.append(tag.data+11,tag.len-15); - if( !Flash_ManifestSent ) { - HTTP_S.Clean(); - HTTP_S.SetHeader("Content-Type","text/xml"); - HTTP_S.SetHeader("Cache-Control","no-cache"); - HTTP_S.SetBody(BuildManifest(FlashMeta, Movie, tag.tagTime())); - HTTP_S.SendResponse(conn, "200", "OK"); - } + if (handler == HANDLER_PROGRESSIVE){ + Progressive(tag, HTTP_S, conn, Strm); } } - if (handler == HANDLER_PROGRESSIVE){ - if (!progressive_has_sent_header){ - HTTP_S.Clean();//troep opruimen die misschien aanwezig is... - if (extension == ".mp3"){ - HTTP_S.SetHeader("Content-Type", "audio/mpeg3");//MP3 files hebben dit content-type. - HTTP_S.protocol = "HTTP/1.0"; - HTTP_S.SendResponse(conn, "200", "OK");//geen SetBody = unknown length! Dat willen we hier. - }else{ - HTTP_S.SetHeader("Content-Type", "video/x-flv");//FLV files hebben altijd dit content-type. - //HTTP_S.SetHeader("Transfer-Encoding", "chunked"); - HTTP_S.protocol = "HTTP/1.0"; - HTTP_S.SendResponse(conn, "200", "OK");//geen SetBody = unknown length! Dat willen we hier. - //HTTP_S.SendBodyPart(CONN_fd, FLVHeader, 13);//schrijf de FLV header - conn.write(FLV::Header, 13); - } - progressive_has_sent_header = true; - } - if (extension == ".mp3"){ - if (tag.data[0] == 0x08){ - if (((tag.data[11] & 0xf0) >> 4) == 2){//mp3 packet - conn.write(tag.data+12, tag.len-16);//write only the MP3 data of the tag - } - } - }else{ - conn.write(tag.data, tag.len); - } - }//PROGRESSIVE handler } break; } diff --git a/Connector_RTSP/main.cpp b/Connector_RTSP/main.cpp index a861aec7..b0b0edd4 100644 --- a/Connector_RTSP/main.cpp +++ b/Connector_RTSP/main.cpp @@ -23,7 +23,9 @@ #include "rtp.h" /// Reads a single NALU from std::cin. Expected is H.264 Bytestream format. +/// Function was used as a way of debugging data. FLV does not contain all the metadata we need, so we had to try different approaches. /// \return The Nalu data. +/// \todo Throw this function away when everything works, it is not needed. std::string ReadNALU( ) { static char Separator[3] = { (char)0x00, (char)0x00, (char)0x01 }; std::string Buffer; @@ -38,62 +40,95 @@ std::string ReadNALU( ) { return Result; } -/// The main function of the connector -/// \param conn A connection with the client +/// The main function of the connector. +/// Used by server_setup.cpp in the bottom of the file, to start up the Connector. +/// This function contains the while loop the accepts connections, and sends them data. +/// \param conn A connection with the client. int RTSP_Handler( Socket::Connection conn ) { - FLV::Tag tag;///< Temporary tag buffer for incoming video data. + /// \todo Convert this to DTSC::DTMI, with an additional DTSC::Stream/ + FLV::Tag tag;// Temporary tag buffer for incoming video data. bool PlayVideo = false; bool PlayAudio = true; + //JRTPlib Objects to handle the RTP connection, which runs "parallel" to RTSP. jrtplib::RTPSession VideoSession; jrtplib::RTPSessionParams VideoParams; jrtplib::RTPUDPv6TransmissionParams VideoTransParams; std::string PreviousRequest = ""; Socket::Connection ss(-1); HTTP::Parser HTTP_R, HTTP_S; + //Some clients appear to expect a single request per connection. Don't know which ones. bool PerRequest = false; + //The main loop of the function while(conn.connected() && !FLV::Parse_Error) { if( HTTP_R.Read(conn ) ) { + //send Debug info to stderr. + //send the appropriate responses on RTSP Commands. fprintf( stderr, "REQUEST:\n%s\n", HTTP_R.BuildRequest().c_str() ); HTTP_S.protocol = "RTSP/1.0"; if( HTTP_R.method == "OPTIONS" ) { + //Always return the requested CSeq value. HTTP_S.SetHeader( "CSeq", HTTP_R.GetHeader( "CSeq" ).c_str() ); + //The minimal set of options required for RTSP, add new options here as well if we want to support these. HTTP_S.SetHeader( "Public", "OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY" ); + //End the HTTP body, IMPORTANT!! Connection hangs otherwise!! HTTP_S.SetBody( "\r\n\r\n" ); fprintf( stderr, "RESPONSE:\n%s\n", HTTP_S.BuildResponse( "200", "OK" ).c_str() ); conn.write( HTTP_S.BuildResponse( "200", "OK" ) ); } else if ( HTTP_R.method == "DESCRIBE" ) { + ///\todo Implement DESCRIBE option. + //Don't know if a 501 response is seen as valid. If it is, don't bother changing it. if( HTTP_R.GetHeader( "Accept" ).find( "application/sdp" ) == std::string::npos ) { fprintf( stderr, "RESPONSE:\n%s\n", HTTP_S.BuildResponse( "501", "Not Implemented" ).c_str() ); conn.write( HTTP_S.BuildResponse( "501", "Not Implemented" ) ); } else { HTTP_S.SetHeader( "CSeq", HTTP_R.GetHeader( "CSeq" ).c_str() ); HTTP_S.SetHeader( "Content-Type", "application/sdp" ); - /// \todo Retrieve presence of video and audio data, and process into response - /// \todo Retrieve Packetization mode ( is 0 for now ). Where can I retrieve this? + /// \todo Retrieve presence of video and audio data, and process into response. Can now easily be done through DTSC::DTMI + /// \todo Retrieve Packetization mode ( is 0 for now ). I suppose this is the H264 packetization mode. Can maybe be retrieved from the docs on H64. + /// \todo Send a valid SDP file. + /// \todo Add audio to SDP file. + //This is just a dummy with data that was supposedly right for our teststream. + //SDP Docs: http://tools.ietf.org/html/rfc4566 + //v=0 + //o=- 0 0 IN IP4 ddvtech.com + //s=Fifa Test + //c=IN IP4 127.0.0.1 + //t=0 0 + //a=recvonly + //m=video 0 RTP/AVP 98 + //a=control:rtsp://localhost/fifa/video + //a=rtpmap:98 H264/90000 + //a=fmtp:98 packetization-mode=0 HTTP_S.SetBody( "v=0\r\no=- 0 0 IN IP4 ddvtech.com\r\ns=Fifa Test\r\nc=IN IP4 127.0.0.1\r\nt=0 0\r\na=recvonly\r\nm=video 0 RTP/AVP 98\r\na=control:rtsp://localhost/fifa/video\r\na=rtpmap:98 H264/90000\r\na=fmtp:98 packetization-mode=0\r\n\r\n");//m=audio 0 RTP/AAP 96\r\na=control:rtsp://localhost/fifa/audio\r\na=rtpmap:96 mpeg4-generic/16000/2\r\n\r\n"); fprintf( stderr, "RESPONSE:\n%s\n", HTTP_S.BuildResponse( "200", "OK" ).c_str() ); conn.write( HTTP_S.BuildResponse( "200", "OK" ) ); } } else if ( HTTP_R.method == "SETUP" ) { std::string temp = HTTP_R.GetHeader("Transport"); + //Extract the random UTP pair for video data ( RTP/RTCP) int ClientRTPLoc = temp.find( "client_port=" ) + 12; int PortSpacer = temp.find( "-", ClientRTPLoc ); int RTPClientPort = atoi( temp.substr( ClientRTPLoc, ( PortSpacer - ClientRTPLoc ) ).c_str() ); if( HTTP_S.GetHeader( "Session" ) != "" ) { + //Return an error if a second client tries to connect with an already running stream. fprintf( stderr, "RESPONSE:\n%s\n", HTTP_S.BuildResponse( "459", "Aggregate Operation Not Allowed" ).c_str() ); conn.write( HTTP_S.BuildResponse( "459", "Aggregate Operation Not Allowed" ) ); } else { HTTP_S.SetHeader( "CSeq", HTTP_R.GetHeader( "CSeq" ).c_str() ); HTTP_S.SetHeader( "Session", time(NULL) ); /// \todo "Random" generation of server_ports - if( HTTP_R.url.find( "audio" ) != std::string::npos ) { - HTTP_S.SetHeader( "Transport", HTTP_R.GetHeader( "Transport" ) + ";server_port=50002-50003" ); - } else { + /// \todo Add support for audio +// if( HTTP_R.url.find( "audio" ) != std::string::npos ) { +// HTTP_S.SetHeader( "Transport", HTTP_R.GetHeader( "Transport" ) + ";server_port=50002-50003" ); +// } else { + //send video data HTTP_S.SetHeader( "Transport", HTTP_R.GetHeader( "Transport" ) + ";server_port=50000-50001" ); + //Stub data for testing purposes. This should now be extracted somehow from DTSC::DTMI VideoParams.SetOwnTimestampUnit( ( 1.0 / 29.917 ) * 90000.0 ); VideoParams.SetMaximumPacketSize( 10000 ); - //pick the right port here + //pick the right port here VideoTransParams.SetPortbase( 50000 ); + //create a JRTPlib session int VideoStatus = VideoSession.Create( VideoParams, &VideoTransParams, jrtplib::RTPTransmitter::IPv6UDPProto ); if( VideoStatus < 0 ) { std::cerr << jrtplib::RTPGetErrorString( VideoStatus ) << std::endl; @@ -101,13 +136,15 @@ int RTSP_Handler( Socket::Connection conn ) { } else { std::cerr << "Created video session\n"; } - /// \todo retrieve other client than localhost --> Socket::Connection has no support for this yet? - + + /// \todo Connect with clients other than localhost uint8_t localip[32]; int status = inet_pton( AF_INET6, conn.getHost().c_str(), localip ) ; + //Debug info std::cerr << "Status: " << status << "\n"; jrtplib::RTPIPv6Address addr(localip,RTPClientPort); + //add the destination address to the VideoSession VideoStatus = VideoSession.AddDestination(addr); if (VideoStatus < 0) { std::cerr << jrtplib::RTPGetErrorString(VideoStatus) << std::endl; @@ -115,19 +152,24 @@ int RTSP_Handler( Socket::Connection conn ) { } else { std::cerr << "Destination Set\n"; } + //Stub data for testing purposes. + //Payload type should confirm with the SDP File. 98 == H264 / AVC VideoSession.SetDefaultPayloadType(98); VideoSession.SetDefaultMark(false); + //We have no idea if this timestamp has to correspond with the OwnTimeStampUnit() above. VideoSession.SetDefaultTimestampIncrement( ( 1.0 / 29.917 ) * 90000 ); - } +// } HTTP_S.SetBody( "\r\n\r\n" ); fprintf( stderr, "RESPONSE:\n%s\n", HTTP_S.BuildResponse( "200", "OK" ).c_str() ); conn.write( HTTP_S.BuildResponse( "200", "OK" ) ); } } else if( HTTP_R.method == "PLAY" ) { if( HTTP_R.GetHeader( "Range" ).substr(0,4) != "npt=" ) { + //We do not support this, whatever it is. Not needed for minimal compliance. fprintf( stderr, "RESPONSE:\n%s\n", HTTP_S.BuildResponse( "501", "Not Implemented" ).c_str() ); conn.write( HTTP_S.BuildResponse( "501", "Not Implemented" ) ); } else { + //Initializes for actual streaming over the SETUP connection. HTTP_S.SetHeader( "CSeq", HTTP_R.GetHeader( "CSeq" ).c_str() ); HTTP_S.SetHeader( "Session", HTTP_R.GetHeader( "Session" ) ); HTTP_S.SetHeader( "Range", HTTP_R.GetHeader( "Range" ) ); @@ -135,15 +177,20 @@ int RTSP_Handler( Socket::Connection conn ) { HTTP_S.SetBody( "\r\n\r\n" ); fprintf( stderr, "RESPONSE:\n%s\n", HTTP_S.BuildResponse( "200", "OK" ).c_str() ); conn.write( HTTP_S.BuildResponse( "200", "OK" ) ); + //Used further down, to start streaming video. + //PlayAudio = true; PlayVideo = true; } } else if( HTTP_R.method == "TEARDOWN" ) { + //If we were sending any stream data at this point, stop it, but keep the setup. HTTP_S.SetHeader( "CSeq", HTTP_R.GetHeader( "CSeq" ).c_str() ); HTTP_S.SetBody( "\r\n\r\n" ); fprintf( stderr, "RESPONSE:\n%s\n", HTTP_S.BuildResponse( "200", "OK" ).c_str() ); conn.write( HTTP_S.BuildResponse( "200", "OK" ) ); + //PlayAudio = false; PlayVideo = false; } else { + //We do not implement other commands ( yet ) fprintf( stderr, "RESPONSE:\n%s\n", HTTP_S.BuildResponse( "501", "Not Implemented" ).c_str() ); conn.write( HTTP_S.BuildResponse( "501", "Not Implemented" ) ); } @@ -154,14 +201,18 @@ int RTSP_Handler( Socket::Connection conn ) { } } if( PlayVideo ) { - /// \todo Select correct source + /// \todo Select correct source. This should become the DTSC::DTMI or the DTSC::Stream, whatever seems more natural. std::string VideoBuf = ReadNALU( ); if( VideoBuf == "" ) { + //videobuffer is empty, no more data. jrtplib::RTPTime delay = jrtplib::RTPTime(10.0); VideoSession.BYEDestroy(delay,"Out of data",11); conn.close(); } else { + //Send a single NALU (H264 block) here. VideoSession.SendPacket( VideoBuf.c_str(), VideoBuf.size(), 98, false, ( 1.0 / 29.917 ) * 90000 ); + //we can add delays here as follows: + //don't know if these are nescecary or not, but good for testing nonetheless // jrtplib::RTPTime delay( ( 1.0 / 29.917 ) * 90000 ); // jrtplib::RTPTime::Wait( delay ); } @@ -170,7 +221,11 @@ int RTSP_Handler( Socket::Connection conn ) { return 0; } +//Set Default Port #define DEFAULT_PORT 554 +//Set the function that should be forked for each client #define MAINHANDLER RTSP_Handler +//Set the section in the Config file, though we will not use this yet #define CONFIGSECT RTSP +//Include the main functionality, as well as fork support and everything. #include "../util/server_setup.cpp" diff --git a/Connector_TS/Makefile b/Connector_TS/Makefile index a248e725..267fcece 100644 --- a/Connector_TS/Makefile +++ b/Connector_TS/Makefile @@ -1,4 +1,4 @@ -SRC = main.cpp ../util/socket.cpp ../util/flv_tag.cpp +SRC = main.cpp ../util/socket.cpp ../util/dtsc.cpp ../util/util.cpp OBJ = $(SRC:.cpp=.o) OUT = DDV_Conn_TS INCLUDES = diff --git a/Connector_TS/main.cpp b/Connector_TS/main.cpp index 2d800430..a296aba5 100644 --- a/Connector_TS/main.cpp +++ b/Connector_TS/main.cpp @@ -18,7 +18,7 @@ #include #include #include "../util/socket.h" -#include "../util/flv_tag.h" +#include "../util/dtsc.h" /// A simple class to create a single Transport Packet class Transport_Packet { @@ -216,37 +216,39 @@ void SendPMT( Socket::Connection conn ) { /// Wraps one or more NALU packets into transport packets /// \param tag The FLV Tag -std::vector WrapNalus( FLV::Tag tag ) { +std::vector WrapNalus( DTSC::DTMI Tag ) { static int ContinuityCounter = 0; static int Previous_Tag = 0; static int First_PCR = getNowMS(); static int Previous_PCR = 0; + static char LeadIn[4] = { (char)0x00, (char)0x00, (char)0x00, (char)0x001 }; int Current_PCR; int Current_Tag; - + std::string Data = Tag.getContentP("data")->StrValue(); + int Offset = 0; Transport_Packet TS; int Sent = 0; - int PacketAmount = ( ( tag.len - (188 - 35 ) ) / 184 ) + 2; + + int PacketAmount = ceil( ( ( Data.size() - (188 - 35 ) ) / 184 ) + 1 );//Minus first packet, + round up and first packet. std::vector Result; - char LeadIn[4] = { (char)0x00, (char)0x00, (char)0x00, (char)0x01 }; TS = Transport_Packet( true, 0x100 ); TS.SetContinuityCounter( ContinuityCounter ); ContinuityCounter = ( ( ContinuityCounter + 1 ) & 0x0F ); Current_PCR = getNowMS(); - Current_Tag = ( tag.data[7] << 24 ) + ( tag.data[4] << 16 ) + ( tag.data[5] << 8 ) + ( tag.data[6] ); + Current_Tag = Tag.getContentP("time")->NumValue(); if( true ) { //Current_PCR - Previous_PCR >= 1 ) { TS.SetAdaptationField( Current_PCR - First_PCR ); Offset = 8; Previous_PCR = Current_PCR; } - TS.SetPesHeader( 4 + Offset, tag.len - 16 , Current_Tag, Previous_Tag ); + TS.SetPesHeader( 4 + Offset, Data.size() , Current_Tag, Previous_Tag ); Previous_Tag = Current_Tag; - TS.SetPayload( LeadIn, 31, 23 + Offset ); - TS.SetPayload( &tag.data[16], 157 - Offset, 27 + Offset ); + TS.SetPayload( LeadIn, 4, 23 + Offset ); + TS.SetPayload( &Data[16], 157 - Offset, 27 + Offset ); Sent = 157 - Offset; Result.push_back( TS ); - while( Sent + 176 < tag.len - 16 ) { + while( Sent + 176 < Data.size() ) { // for( int i = 0; i < (PacketAmount - 1); i++ ) { TS = Transport_Packet( false, 0x100 ); TS.SetContinuityCounter( ContinuityCounter ); @@ -258,11 +260,11 @@ std::vector WrapNalus( FLV::Tag tag ) { Offset = 8; Previous_PCR = Current_PCR; } - TS.SetPayload( &tag.data[16 + Sent], 184 - Offset, 4 + Offset ); + TS.SetPayload( &Data[16 + Sent], 184 - Offset, 4 + Offset ); Sent += 184 - Offset; Result.push_back( TS ); } - if( Sent < ( tag.len - 16 ) ) { + if( Sent < ( Data.size() ) ) { Current_PCR = getNowMS(); Offset = 0; if( true ) { //now - Previous_PCR >= 5 ) { @@ -271,16 +273,16 @@ std::vector WrapNalus( FLV::Tag tag ) { Previous_PCR = Current_PCR; } std::cerr << "Wrapping packet: last packet length\n"; - std::cerr << "\tTotal:\t\t" << tag.len - 16 << "\n"; + std::cerr << "\tTotal:\t\t" << Data.size() << "\n"; std::cerr << "\tSent:\t\t" << Sent << "\n"; - int To_Send = ( tag.len - 16 ) - Sent; + int To_Send = ( Data.size() ) - Sent; std::cerr << "\tTo Send:\t" << To_Send << "\n"; std::cerr << "\tStuffing:\t" << 176 - To_Send << "\n"; char Stuffing = (char)0xFF; for( int i = 0; i < ( 176 - To_Send ); i++ ) { TS.SetPayload( &Stuffing, 1, 4 + Offset + i ); } - TS.SetPayload( &tag.data[16 + Sent], 176 - To_Send , 4 + Offset + ( 176 - To_Send ) ); + TS.SetPayload( &Data[16 + Sent], 176 - To_Send , 4 + Offset + ( 176 - To_Send ) ); Result.push_back( TS ); } return Result; @@ -301,12 +303,13 @@ void Transport_Packet::Write( Socket::Connection conn ) { /// The main function of the connector /// \param conn A connection with the client int TS_Handler( Socket::Connection conn ) { - FLV::Tag tag;///< Temporary tag buffer for incoming video data. + DTSC::Stream stream; +// FLV::Tag tag;///< Temporary tag buffer for incoming video data. bool inited = false; bool firstvideo = true; Socket::Connection ss(-1); int zet = 0; - while(conn.connected() && !FLV::Parse_Error) { + while(conn.connected()) {// && !FLV::Parse_Error) { if( !inited ) { ss = Socket::Connection("/tmp/shared_socket_fifa"); if (!ss.connected()){ @@ -331,27 +334,22 @@ int TS_Handler( Socket::Connection conn ) { break; case 0: break;//not ready yet default: - if (tag.SockLoader(ss)){//able to read a full packet? - if( tag.data[ 0 ] == 0x09 ) { - if( ( ( tag.data[ 11 ] & 0x0F ) == 7 ) ) { //&& ( tag.data[ 12 ] == 1 ) ) { - fprintf(stderr, "Video contains NALU\n" ); - // if( firstvideo ) { - // firstvideo = false; - // } else { - SendPAT( conn ); - SendPMT( conn ); - std::vector Meh = WrapNalus( tag ); - for( int i = 0; i < Meh.size( ); i++ ) { - Meh[i].Write( conn ); - } - std::cerr << "Item: " << ++zet << "\n"; - // } - } + ss.spool(); + if ( stream.parsePacket( conn.Received() ) ) { + if( stream.lastType() == DTSC::VIDEO ) { + fprintf(stderr, "Video contains NALU\n" ); + SendPAT( conn ); + SendPMT( conn ); + std::vector AllNalus = WrapNalus( stream.getPacket(0) ); + for( int i = 0; i < AllNalus.size( ); i++ ) { + AllNalus[i].Write( conn ); + } + std::cerr << "Item: " << ++zet << "\n"; } - if( tag.data[ 0 ] == 0x08 ) { - if( ( tag.data[ 11 ] == 0xAF ) && ( tag.data[ 12 ] == 0x01 ) ) { + if( stream.lastType() == DTSC::AUDIO ) { +// if( ( tag.data[ 11 ] == 0xAF ) && ( tag.data[ 12 ] == 0x01 ) ) { fprintf(stderr, "Audio Contains Raw AAC\n"); - } +// } } } break; diff --git a/jquery.js b/jquery.js old mode 100755 new mode 100644 index b8080781..b1b47b81 --- a/jquery.js +++ b/jquery.js @@ -1,169 +1,4 @@ - -/*! -* jQuery JavaScript Library v1.4.3 -* http://jquery.com/ -* -* Copyright 2010, John Resig -* Dual licensed under the MIT or GPL Version 2 licenses. -* http://jquery.org/license -* -* Includes Sizzle.js -* http://sizzlejs.com/ -* Copyright 2010, The Dojo Foundation -* Released under the MIT, BSD, and GPL Licenses. -* -* Date: Thu Oct 14 23:10:06 2010 -0400 -*/ - -(function(E,A){function U(){return false}function ba(){return true}function ja(a,b,d){d[0].type=a;return c.event.handle.apply(b,d)}function Ga(a){var b,d,e=[],f=[],h,k,l,n,s,v,B,D;k=c.data(this,this.nodeType?"events":"__events__");if(typeof k==="function")k=k.events;if(!(a.liveFired===this||!k||!k.live||a.button&&a.type==="click")){if(a.namespace)D=RegExp("(^|\\.)"+a.namespace.split(".").join("\\.(?:.*\\.)?")+"(\\.|$)");a.liveFired=this;var H=k.live.slice(0);for(n=0;nd)break;a.currentTarget=f.elem;a.data=f.handleObj.data; - a.handleObj=f.handleObj;D=f.handleObj.origHandler.apply(f.elem,arguments);if(D===false||a.isPropagationStopped()){d=f.level;if(D===false)b=false}}return b}}function Y(a,b){return(a&&a!=="*"?a+".":"")+b.replace(Ha,"`").replace(Ia,"&")}function ka(a,b,d){if(c.isFunction(b))return c.grep(a,function(f,h){return!!b.call(f,h,f)===d});else if(b.nodeType)return c.grep(a,function(f){return f===b===d});else if(typeof b==="string"){var e=c.grep(a,function(f){return f.nodeType===1});if(Ja.test(b))return c.filter(b, - e,!d);else b=c.filter(b,e)}return c.grep(a,function(f){return c.inArray(f,b)>=0===d})}function la(a,b){var d=0;b.each(function(){if(this.nodeName===(a[d]&&a[d].nodeName)){var e=c.data(a[d++]),f=c.data(this,e);if(e=e&&e.events){delete f.handle;f.events={};for(var h in e)for(var k in e[h])c.event.add(this,h,e[h][k],e[h][k].data)}}})}function Ka(a,b){b.src?c.ajax({url:b.src,async:false,dataType:"script"}):c.globalEval(b.text||b.textContent||b.innerHTML||"");b.parentNode&&b.parentNode.removeChild(b)} - function ma(a,b,d){var e=b==="width"?a.offsetWidth:a.offsetHeight;if(d==="border")return e;c.each(b==="width"?La:Ma,function(){d||(e-=parseFloat(c.css(a,"padding"+this))||0);if(d==="margin")e+=parseFloat(c.css(a,"margin"+this))||0;else e-=parseFloat(c.css(a,"border"+this+"Width"))||0});return e}function ca(a,b,d,e){if(c.isArray(b)&&b.length)c.each(b,function(f,h){d||Na.test(a)?e(a,h):ca(a+"["+(typeof h==="object"||c.isArray(h)?f:"")+"]",h,d,e)});else if(!d&&b!=null&&typeof b==="object")c.isEmptyObject(b)? - e(a,""):c.each(b,function(f,h){ca(a+"["+f+"]",h,d,e)});else e(a,b)}function S(a,b){var d={};c.each(na.concat.apply([],na.slice(0,b)),function(){d[this]=a});return d}function oa(a){if(!da[a]){var b=c("<"+a+">").appendTo("body"),d=b.css("display");b.remove();if(d==="none"||d==="")d="block";da[a]=d}return da[a]}function ea(a){return c.isWindow(a)?a:a.nodeType===9?a.defaultView||a.parentWindow:false}var u=E.document,c=function(){function a(){if(!b.isReady){try{u.documentElement.doScroll("left")}catch(i){setTimeout(a, - 1);return}b.ready()}}var b=function(i,r){return new b.fn.init(i,r)},d=E.jQuery,e=E.$,f,h=/^(?:[^<]*(<[\w\W]+>)[^>]*$|#([\w\-]+)$)/,k=/\S/,l=/^\s+/,n=/\s+$/,s=/\W/,v=/\d/,B=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,D=/^[\],:{}\s]*$/,H=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,w=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,G=/(?:^|:|,)(?:\s*\[)+/g,M=/(webkit)[ \/]([\w.]+)/,g=/(opera)(?:.*version)?[ \/]([\w.]+)/,j=/(msie) ([\w.]+)/,o=/(mozilla)(?:.*? rv:([\w.]+))?/,m=navigator.userAgent,p=false, - q=[],t,x=Object.prototype.toString,C=Object.prototype.hasOwnProperty,P=Array.prototype.push,N=Array.prototype.slice,R=String.prototype.trim,Q=Array.prototype.indexOf,L={};b.fn=b.prototype={init:function(i,r){var y,z,F;if(!i)return this;if(i.nodeType){this.context=this[0]=i;this.length=1;return this}if(i==="body"&&!r&&u.body){this.context=u;this[0]=u.body;this.selector="body";this.length=1;return this}if(typeof i==="string")if((y=h.exec(i))&&(y[1]||!r))if(y[1]){F=r?r.ownerDocument||r:u;if(z=B.exec(i))if(b.isPlainObject(r)){i= - [u.createElement(z[1])];b.fn.attr.call(i,r,true)}else i=[F.createElement(z[1])];else{z=b.buildFragment([y[1]],[F]);i=(z.cacheable?z.fragment.cloneNode(true):z.fragment).childNodes}return b.merge(this,i)}else{if((z=u.getElementById(y[2]))&&z.parentNode){if(z.id!==y[2])return f.find(i);this.length=1;this[0]=z}this.context=u;this.selector=i;return this}else if(!r&&!s.test(i)){this.selector=i;this.context=u;i=u.getElementsByTagName(i);return b.merge(this,i)}else return!r||r.jquery?(r||f).find(i):b(r).find(i); - else if(b.isFunction(i))return f.ready(i);if(i.selector!==A){this.selector=i.selector;this.context=i.context}return b.makeArray(i,this)},selector:"",jquery:"1.4.3",length:0,size:function(){return this.length},toArray:function(){return N.call(this,0)},get:function(i){return i==null?this.toArray():i<0?this.slice(i)[0]:this[i]},pushStack:function(i,r,y){var z=b();b.isArray(i)?P.apply(z,i):b.merge(z,i);z.prevObject=this;z.context=this.context;if(r==="find")z.selector=this.selector+(this.selector?" ": - "")+y;else if(r)z.selector=this.selector+"."+r+"("+y+")";return z},each:function(i,r){return b.each(this,i,r)},ready:function(i){b.bindReady();if(b.isReady)i.call(u,b);else q&&q.push(i);return this},eq:function(i){return i===-1?this.slice(i):this.slice(i,+i+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(N.apply(this,arguments),"slice",N.call(arguments).join(","))},map:function(i){return this.pushStack(b.map(this,function(r,y){return i.call(r, - y,r)}))},end:function(){return this.prevObject||b(null)},push:P,sort:[].sort,splice:[].splice};b.fn.init.prototype=b.fn;b.extend=b.fn.extend=function(){var i=arguments[0]||{},r=1,y=arguments.length,z=false,F,I,K,J,fa;if(typeof i==="boolean"){z=i;i=arguments[1]||{};r=2}if(typeof i!=="object"&&!b.isFunction(i))i={};if(y===r){i=this;--r}for(;r0)){if(q){for(var r=0;i=q[r++];)i.call(u,b);q=null}b.fn.triggerHandler&&b(u).triggerHandler("ready")}}},bindReady:function(){if(!p){p=true;if(u.readyState==="complete")return setTimeout(b.ready, - 1);if(u.addEventListener){u.addEventListener("DOMContentLoaded",t,false);E.addEventListener("load",b.ready,false)}else if(u.attachEvent){u.attachEvent("onreadystatechange",t);E.attachEvent("onload",b.ready);var i=false;try{i=E.frameElement==null}catch(r){}u.documentElement.doScroll&&i&&a()}}},isFunction:function(i){return b.type(i)==="function"},isArray:Array.isArray||function(i){return b.type(i)==="array"},isWindow:function(i){return i&&typeof i==="object"&&"setInterval"in i},isNaN:function(i){return i== - null||!v.test(i)||isNaN(i)},type:function(i){return i==null?String(i):L[x.call(i)]||"object"},isPlainObject:function(i){if(!i||b.type(i)!=="object"||i.nodeType||b.isWindow(i))return false;if(i.constructor&&!C.call(i,"constructor")&&!C.call(i.constructor.prototype,"isPrototypeOf"))return false;for(var r in i);return r===A||C.call(i,r)},isEmptyObject:function(i){for(var r in i)return false;return true},error:function(i){throw i;},parseJSON:function(i){if(typeof i!=="string"||!i)return null;i=b.trim(i); - if(D.test(i.replace(H,"@").replace(w,"]").replace(G,"")))return E.JSON&&E.JSON.parse?E.JSON.parse(i):(new Function("return "+i))();else b.error("Invalid JSON: "+i)},noop:function(){},globalEval:function(i){if(i&&k.test(i)){var r=u.getElementsByTagName("head")[0]||u.documentElement,y=u.createElement("script");y.type="text/javascript";if(b.support.scriptEval)y.appendChild(u.createTextNode(i));else y.text=i;r.insertBefore(y,r.firstChild);r.removeChild(y)}},nodeName:function(i,r){return i.nodeName&&i.nodeName.toUpperCase()=== - r.toUpperCase()},each:function(i,r,y){var z,F=0,I=i.length,K=I===A||b.isFunction(i);if(y)if(K)for(z in i){if(r.apply(i[z],y)===false)break}else for(;F";a=u.createDocumentFragment();a.appendChild(d.firstChild);c.support.checkClone=a.cloneNode(true).cloneNode(true).lastChild.checked;c(function(){var s=u.createElement("div"); - s.style.width=s.style.paddingLeft="1px";u.body.appendChild(s);c.boxModel=c.support.boxModel=s.offsetWidth===2;if("zoom"in s.style){s.style.display="inline";s.style.zoom=1;c.support.inlineBlockNeedsLayout=s.offsetWidth===2;s.style.display="";s.innerHTML="
";c.support.shrinkWrapBlocks=s.offsetWidth!==2}s.innerHTML="
t
";var v=s.getElementsByTagName("td");c.support.reliableHiddenOffsets=v[0].offsetHeight=== - 0;v[0].style.display="";v[1].style.display="none";c.support.reliableHiddenOffsets=c.support.reliableHiddenOffsets&&v[0].offsetHeight===0;s.innerHTML="";u.body.removeChild(s).style.display="none"});a=function(s){var v=u.createElement("div");s="on"+s;var B=s in v;if(!B){v.setAttribute(s,"return;");B=typeof v[s]==="function"}return B};c.support.submitBubbles=a("submit");c.support.changeBubbles=a("change");a=b=d=f=h=null}})();c.props={"for":"htmlFor","class":"className",readonly:"readOnly",maxlength:"maxLength", - cellspacing:"cellSpacing",rowspan:"rowSpan",colspan:"colSpan",tabindex:"tabIndex",usemap:"useMap",frameborder:"frameBorder"};var pa={},Oa=/^(?:\{.*\}|\[.*\])$/;c.extend({cache:{},uuid:0,expando:"jQuery"+c.now(),noData:{embed:true,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:true},data:function(a,b,d){if(c.acceptData(a)){a=a==E?pa:a;var e=a.nodeType,f=e?a[c.expando]:null,h=c.cache;if(!(e&&!f&&typeof b==="string"&&d===A)){if(e)f||(a[c.expando]=f=++c.uuid);else h=a;if(typeof b==="object")if(e)h[f]= - c.extend(h[f],b);else c.extend(h,b);else if(e&&!h[f])h[f]={};a=e?h[f]:h;if(d!==A)a[b]=d;return typeof b==="string"?a[b]:a}}},removeData:function(a,b){if(c.acceptData(a)){a=a==E?pa:a;var d=a.nodeType,e=d?a[c.expando]:a,f=c.cache,h=d?f[e]:e;if(b){if(h){delete h[b];d&&c.isEmptyObject(h)&&c.removeData(a)}}else if(d&&c.support.deleteExpando)delete a[c.expando];else if(a.removeAttribute)a.removeAttribute(c.expando);else if(d)delete f[e];else for(var k in a)delete a[k]}},acceptData:function(a){if(a.nodeName){var b= - c.noData[a.nodeName.toLowerCase()];if(b)return!(b===true||a.getAttribute("classid")!==b)}return true}});c.fn.extend({data:function(a,b){if(typeof a==="undefined")return this.length?c.data(this[0]):null;else if(typeof a==="object")return this.each(function(){c.data(this,a)});var d=a.split(".");d[1]=d[1]?"."+d[1]:"";if(b===A){var e=this.triggerHandler("getData"+d[1]+"!",[d[0]]);if(e===A&&this.length){e=c.data(this[0],a);if(e===A&&this[0].nodeType===1){e=this[0].getAttribute("data-"+a);if(typeof e=== - "string")try{e=e==="true"?true:e==="false"?false:e==="null"?null:!c.isNaN(e)?parseFloat(e):Oa.test(e)?c.parseJSON(e):e}catch(f){}else e=A}}return e===A&&d[1]?this.data(d[0]):e}else return this.each(function(){var h=c(this),k=[d[0],b];h.triggerHandler("setData"+d[1]+"!",k);c.data(this,a,b);h.triggerHandler("changeData"+d[1]+"!",k)})},removeData:function(a){return this.each(function(){c.removeData(this,a)})}});c.extend({queue:function(a,b,d){if(a){b=(b||"fx")+"queue";var e=c.data(a,b);if(!d)return e|| - [];if(!e||c.isArray(d))e=c.data(a,b,c.makeArray(d));else e.push(d);return e}},dequeue:function(a,b){b=b||"fx";var d=c.queue(a,b),e=d.shift();if(e==="inprogress")e=d.shift();if(e){b==="fx"&&d.unshift("inprogress");e.call(a,function(){c.dequeue(a,b)})}}});c.fn.extend({queue:function(a,b){if(typeof a!=="string"){b=a;a="fx"}if(b===A)return c.queue(this[0],a);return this.each(function(){var d=c.queue(this,a,b);a==="fx"&&d[0]!=="inprogress"&&c.dequeue(this,a)})},dequeue:function(a){return this.each(function(){c.dequeue(this, - a)})},delay:function(a,b){a=c.fx?c.fx.speeds[a]||a:a;b=b||"fx";return this.queue(b,function(){var d=this;setTimeout(function(){c.dequeue(d,b)},a)})},clearQueue:function(a){return this.queue(a||"fx",[])}});var qa=/[\n\t]/g,ga=/\s+/,Pa=/\r/g,Qa=/^(?:href|src|style)$/,Ra=/^(?:button|input)$/i,Sa=/^(?:button|input|object|select|textarea)$/i,Ta=/^a(?:rea)?$/i,ra=/^(?:radio|checkbox)$/i;c.fn.extend({attr:function(a,b){return c.access(this,a,b,true,c.attr)},removeAttr:function(a){return this.each(function(){c.attr(this, - a,"");this.nodeType===1&&this.removeAttribute(a)})},addClass:function(a){if(c.isFunction(a))return this.each(function(s){var v=c(this);v.addClass(a.call(this,s,v.attr("class")))});if(a&&typeof a==="string")for(var b=(a||"").split(ga),d=0,e=this.length;d-1)return true;return false}, - val:function(a){if(!arguments.length){var b=this[0];if(b){if(c.nodeName(b,"option")){var d=b.attributes.value;return!d||d.specified?b.value:b.text}if(c.nodeName(b,"select")){var e=b.selectedIndex;d=[];var f=b.options;b=b.type==="select-one";if(e<0)return null;var h=b?e:0;for(e=b?e+1:f.length;h=0;else if(c.nodeName(this,"select")){var B=c.makeArray(v);c("option",this).each(function(){this.selected= - c.inArray(c(this).val(),B)>=0});if(!B.length)this.selectedIndex=-1}else this.value=v}})}});c.extend({attrFn:{val:true,css:true,html:true,text:true,data:true,width:true,height:true,offset:true},attr:function(a,b,d,e){if(!a||a.nodeType===3||a.nodeType===8)return A;if(e&&b in c.attrFn)return c(a)[b](d);e=a.nodeType!==1||!c.isXMLDoc(a);var f=d!==A;b=e&&c.props[b]||b;if(a.nodeType===1){var h=Qa.test(b);if((b in a||a[b]!==A)&&e&&!h){if(f){b==="type"&&Ra.test(a.nodeName)&&a.parentNode&&c.error("type property can't be changed"); - if(d===null)a.nodeType===1&&a.removeAttribute(b);else a[b]=d}if(c.nodeName(a,"form")&&a.getAttributeNode(b))return a.getAttributeNode(b).nodeValue;if(b==="tabIndex")return(b=a.getAttributeNode("tabIndex"))&&b.specified?b.value:Sa.test(a.nodeName)||Ta.test(a.nodeName)&&a.href?0:A;return a[b]}if(!c.support.style&&e&&b==="style"){if(f)a.style.cssText=""+d;return a.style.cssText}f&&a.setAttribute(b,""+d);if(!a.attributes[b]&&a.hasAttribute&&!a.hasAttribute(b))return A;a=!c.support.hrefNormalized&&e&& - h?a.getAttribute(b,2):a.getAttribute(b);return a===null?A:a}}});var X=/\.(.*)$/,ha=/^(?:textarea|input|select)$/i,Ha=/\./g,Ia=/ /g,Ua=/[^\w\s.|`]/g,Va=function(a){return a.replace(Ua,"\\$&")},sa={focusin:0,focusout:0};c.event={add:function(a,b,d,e){if(!(a.nodeType===3||a.nodeType===8)){if(c.isWindow(a)&&a!==E&&!a.frameElement)a=E;if(d===false)d=U;var f,h;if(d.handler){f=d;d=f.handler}if(!d.guid)d.guid=c.guid++;if(h=c.data(a)){var k=a.nodeType?"events":"__events__",l=h[k],n=h.handle;if(typeof l=== - "function"){n=l.handle;l=l.events}else if(!l){a.nodeType||(h[k]=h=function(){});h.events=l={}}if(!n)h.handle=n=function(){return typeof c!=="undefined"&&!c.event.triggered?c.event.handle.apply(n.elem,arguments):A};n.elem=a;b=b.split(" ");for(var s=0,v;k=b[s++];){h=f?c.extend({},f):{handler:d,data:e};if(k.indexOf(".")>-1){v=k.split(".");k=v.shift();h.namespace=v.slice(0).sort().join(".")}else{v=[];h.namespace=""}h.type=k;if(!h.guid)h.guid=d.guid;var B=l[k],D=c.event.special[k]||{};if(!B){B=l[k]=[]; - if(!D.setup||D.setup.call(a,e,v,n)===false)if(a.addEventListener)a.addEventListener(k,n,false);else a.attachEvent&&a.attachEvent("on"+k,n)}if(D.add){D.add.call(a,h);if(!h.handler.guid)h.handler.guid=d.guid}B.push(h);c.event.global[k]=true}a=null}}},global:{},remove:function(a,b,d,e){if(!(a.nodeType===3||a.nodeType===8)){if(d===false)d=U;var f,h,k=0,l,n,s,v,B,D,H=a.nodeType?"events":"__events__",w=c.data(a),G=w&&w[H];if(w&&G){if(typeof G==="function"){w=G;G=G.events}if(b&&b.type){d=b.handler;b=b.type}if(!b|| - typeof b==="string"&&b.charAt(0)==="."){b=b||"";for(f in G)c.event.remove(a,f+b)}else{for(b=b.split(" ");f=b[k++];){v=f;l=f.indexOf(".")<0;n=[];if(!l){n=f.split(".");f=n.shift();s=RegExp("(^|\\.)"+c.map(n.slice(0).sort(),Va).join("\\.(?:.*\\.)?")+"(\\.|$)")}if(B=G[f])if(d){v=c.event.special[f]||{};for(h=e||0;h=0){a.type= - f=f.slice(0,-1);a.exclusive=true}if(!d){a.stopPropagation();c.event.global[f]&&c.each(c.cache,function(){this.events&&this.events[f]&&c.event.trigger(a,b,this.handle.elem)})}if(!d||d.nodeType===3||d.nodeType===8)return A;a.result=A;a.target=d;b=c.makeArray(b);b.unshift(a)}a.currentTarget=d;(e=d.nodeType?c.data(d,"handle"):(c.data(d,"__events__")||{}).handle)&&e.apply(d,b);e=d.parentNode||d.ownerDocument;try{if(!(d&&d.nodeName&&c.noData[d.nodeName.toLowerCase()]))if(d["on"+f]&&d["on"+f].apply(d,b)=== - false){a.result=false;a.preventDefault()}}catch(h){}if(!a.isPropagationStopped()&&e)c.event.trigger(a,b,e,true);else if(!a.isDefaultPrevented()){e=a.target;var k,l=f.replace(X,""),n=c.nodeName(e,"a")&&l==="click",s=c.event.special[l]||{};if((!s._default||s._default.call(d,a)===false)&&!n&&!(e&&e.nodeName&&c.noData[e.nodeName.toLowerCase()])){try{if(e[l]){if(k=e["on"+l])e["on"+l]=null;c.event.triggered=true;e[l]()}}catch(v){}if(k)e["on"+l]=k;c.event.triggered=false}}},handle:function(a){var b,d,e; - d=[];var f,h=c.makeArray(arguments);a=h[0]=c.event.fix(a||E.event);a.currentTarget=this;b=a.type.indexOf(".")<0&&!a.exclusive;if(!b){e=a.type.split(".");a.type=e.shift();d=e.slice(0).sort();e=RegExp("(^|\\.)"+d.join("\\.(?:.*\\.)?")+"(\\.|$)")}a.namespace=a.namespace||d.join(".");f=c.data(this,this.nodeType?"events":"__events__");if(typeof f==="function")f=f.events;d=(f||{})[a.type];if(f&&d){d=d.slice(0);f=0;for(var k=d.length;f-1?c.map(a.options,function(e){return e.selected}).join("-"):"";else if(a.nodeName.toLowerCase()==="select")d=a.selectedIndex;return d},Z=function(a,b){var d=a.target,e,f;if(!(!ha.test(d.nodeName)||d.readOnly)){e=c.data(d,"_change_data");f=va(d);if(a.type!=="focusout"||d.type!=="radio")c.data(d,"_change_data",f);if(!(e===A||f===e))if(e!=null||f){a.type="change";a.liveFired= - A;return c.event.trigger(a,b,d)}}};c.event.special.change={filters:{focusout:Z,beforedeactivate:Z,click:function(a){var b=a.target,d=b.type;if(d==="radio"||d==="checkbox"||b.nodeName.toLowerCase()==="select")return Z.call(this,a)},keydown:function(a){var b=a.target,d=b.type;if(a.keyCode===13&&b.nodeName.toLowerCase()!=="textarea"||a.keyCode===32&&(d==="checkbox"||d==="radio")||d==="select-multiple")return Z.call(this,a)},beforeactivate:function(a){a=a.target;c.data(a,"_change_data",va(a))}},setup:function(){if(this.type=== - "file")return false;for(var a in V)c.event.add(this,a+".specialChange",V[a]);return ha.test(this.nodeName)},teardown:function(){c.event.remove(this,".specialChange");return ha.test(this.nodeName)}};V=c.event.special.change.filters;V.focus=V.beforeactivate}u.addEventListener&&c.each({focus:"focusin",blur:"focusout"},function(a,b){function d(e){e=c.event.fix(e);e.type=b;return c.event.trigger(e,null,e.target)}c.event.special[b]={setup:function(){sa[b]++===0&&u.addEventListener(a,d,true)},teardown:function(){--sa[b]=== - 0&&u.removeEventListener(a,d,true)}}});c.each(["bind","one"],function(a,b){c.fn[b]=function(d,e,f){if(typeof d==="object"){for(var h in d)this[b](h,e,d[h],f);return this}if(c.isFunction(e)||e===false){f=e;e=A}var k=b==="one"?c.proxy(f,function(n){c(this).unbind(n,k);return f.apply(this,arguments)}):f;if(d==="unload"&&b!=="one")this.one(d,e,f);else{h=0;for(var l=this.length;h0?this.bind(b,d,e):this.trigger(b)};if(c.attrFn)c.attrFn[b]=true});E.attachEvent&&!E.addEventListener&&c(E).bind("unload",function(){for(var a in c.cache)if(c.cache[a].handle)try{c.event.remove(c.cache[a].handle.elem)}catch(b){}}); - (function(){function a(g,j,o,m,p,q){p=0;for(var t=m.length;p0){C=x;break}}x=x[g]}m[p]=C}}}var d=/((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,e=0,f=Object.prototype.toString,h=false,k=true;[0,0].sort(function(){k=false;return 0});var l=function(g,j,o,m){o=o||[];var p=j=j||u;if(j.nodeType!==1&&j.nodeType!==9)return[];if(!g||typeof g!=="string")return o;var q=[],t,x,C,P,N=true,R=l.isXML(j),Q=g,L;do{d.exec("");if(t=d.exec(Q)){Q=t[3];q.push(t[1]);if(t[2]){P=t[3]; - break}}}while(t);if(q.length>1&&s.exec(g))if(q.length===2&&n.relative[q[0]])x=M(q[0]+q[1],j);else for(x=n.relative[q[0]]?[j]:l(q.shift(),j);q.length;){g=q.shift();if(n.relative[g])g+=q.shift();x=M(g,x)}else{if(!m&&q.length>1&&j.nodeType===9&&!R&&n.match.ID.test(q[0])&&!n.match.ID.test(q[q.length-1])){t=l.find(q.shift(),j,R);j=t.expr?l.filter(t.expr,t.set)[0]:t.set[0]}if(j){t=m?{expr:q.pop(),set:D(m)}:l.find(q.pop(),q.length===1&&(q[0]==="~"||q[0]==="+")&&j.parentNode?j.parentNode:j,R);x=t.expr?l.filter(t.expr, - t.set):t.set;if(q.length>0)C=D(x);else N=false;for(;q.length;){t=L=q.pop();if(n.relative[L])t=q.pop();else L="";if(t==null)t=j;n.relative[L](C,t,R)}}else C=[]}C||(C=x);C||l.error(L||g);if(f.call(C)==="[object Array]")if(N)if(j&&j.nodeType===1)for(g=0;C[g]!=null;g++){if(C[g]&&(C[g]===true||C[g].nodeType===1&&l.contains(j,C[g])))o.push(x[g])}else for(g=0;C[g]!=null;g++)C[g]&&C[g].nodeType===1&&o.push(x[g]);else o.push.apply(o,C);else D(C,o);if(P){l(P,p,o,m);l.uniqueSort(o)}return o};l.uniqueSort=function(g){if(w){h= - k;g.sort(w);if(h)for(var j=1;j0};l.find=function(g,j,o){var m;if(!g)return[];for(var p=0,q=n.order.length;p":function(g,j){var o=typeof j==="string",m,p=0,q=g.length;if(o&&!/\W/.test(j))for(j=j.toLowerCase();p=0))o||m.push(t);else if(o)j[q]=false;return false},ID:function(g){return g[1].replace(/\\/g,"")},TAG:function(g){return g[1].toLowerCase()},CHILD:function(g){if(g[1]==="nth"){var j=/(-?)(\d*)n((?:\+|-)?\d*)/.exec(g[2]==="even"&&"2n"||g[2]==="odd"&&"2n+1"||!/\D/.test(g[2])&&"0n+"+g[2]||g[2]);g[2]=j[1]+(j[2]||1)-0;g[3]=j[3]-0}g[0]=e++;return g},ATTR:function(g,j,o, - m,p,q){j=g[1].replace(/\\/g,"");if(!q&&n.attrMap[j])g[1]=n.attrMap[j];if(g[2]==="~=")g[4]=" "+g[4]+" ";return g},PSEUDO:function(g,j,o,m,p){if(g[1]==="not")if((d.exec(g[3])||"").length>1||/^\w/.test(g[3]))g[3]=l(g[3],null,null,j);else{g=l.filter(g[3],j,o,true^p);o||m.push.apply(m,g);return false}else if(n.match.POS.test(g[0])||n.match.CHILD.test(g[0]))return true;return g},POS:function(g){g.unshift(true);return g}},filters:{enabled:function(g){return g.disabled===false&&g.type!=="hidden"},disabled:function(g){return g.disabled=== - true},checked:function(g){return g.checked===true},selected:function(g){return g.selected===true},parent:function(g){return!!g.firstChild},empty:function(g){return!g.firstChild},has:function(g,j,o){return!!l(o[3],g).length},header:function(g){return/h\d/i.test(g.nodeName)},text:function(g){return"text"===g.type},radio:function(g){return"radio"===g.type},checkbox:function(g){return"checkbox"===g.type},file:function(g){return"file"===g.type},password:function(g){return"password"===g.type},submit:function(g){return"submit"=== - g.type},image:function(g){return"image"===g.type},reset:function(g){return"reset"===g.type},button:function(g){return"button"===g.type||g.nodeName.toLowerCase()==="button"},input:function(g){return/input|select|textarea|button/i.test(g.nodeName)}},setFilters:{first:function(g,j){return j===0},last:function(g,j,o,m){return j===m.length-1},even:function(g,j){return j%2===0},odd:function(g,j){return j%2===1},lt:function(g,j,o){return jo[3]-0},nth:function(g,j,o){return o[3]- - 0===j},eq:function(g,j,o){return o[3]-0===j}},filter:{PSEUDO:function(g,j,o,m){var p=j[1],q=n.filters[p];if(q)return q(g,o,j,m);else if(p==="contains")return(g.textContent||g.innerText||l.getText([g])||"").indexOf(j[3])>=0;else if(p==="not"){j=j[3];o=0;for(m=j.length;o=0}},ID:function(g,j){return g.nodeType===1&&g.getAttribute("id")===j},TAG:function(g,j){return j==="*"&&g.nodeType===1||g.nodeName.toLowerCase()=== - j},CLASS:function(g,j){return(" "+(g.className||g.getAttribute("class"))+" ").indexOf(j)>-1},ATTR:function(g,j){var o=j[1];o=n.attrHandle[o]?n.attrHandle[o](g):g[o]!=null?g[o]:g.getAttribute(o);var m=o+"",p=j[2],q=j[4];return o==null?p==="!=":p==="="?m===q:p==="*="?m.indexOf(q)>=0:p==="~="?(" "+m+" ").indexOf(q)>=0:!q?m&&o!==false:p==="!="?m!==q:p==="^="?m.indexOf(q)===0:p==="$="?m.substr(m.length-q.length)===q:p==="|="?m===q||m.substr(0,q.length+1)===q+"-":false},POS:function(g,j,o,m){var p=n.setFilters[j[2]]; - if(p)return p(g,o,j,m)}}},s=n.match.POS,v=function(g,j){return"\\"+(j-0+1)},B;for(B in n.match){n.match[B]=RegExp(n.match[B].source+/(?![^\[]*\])(?![^\(]*\))/.source);n.leftMatch[B]=RegExp(/(^(?:.|\r|\n)*?)/.source+n.match[B].source.replace(/\\(\d+)/g,v))}var D=function(g,j){g=Array.prototype.slice.call(g,0);if(j){j.push.apply(j,g);return j}return g};try{Array.prototype.slice.call(u.documentElement.childNodes,0)}catch(H){D=function(g,j){var o=j||[],m=0;if(f.call(g)==="[object Array]")Array.prototype.push.apply(o, - g);else if(typeof g.length==="number")for(var p=g.length;m";var o=u.documentElement;o.insertBefore(g,o.firstChild);if(u.getElementById(j)){n.find.ID=function(m,p,q){if(typeof p.getElementById!=="undefined"&&!q)return(p=p.getElementById(m[1]))?p.id===m[1]||typeof p.getAttributeNode!=="undefined"&&p.getAttributeNode("id").nodeValue===m[1]?[p]:A:[]};n.filter.ID=function(m,p){var q=typeof m.getAttributeNode!=="undefined"&&m.getAttributeNode("id");return m.nodeType===1&&q&&q.nodeValue===p}}o.removeChild(g); - o=g=null})();(function(){var g=u.createElement("div");g.appendChild(u.createComment(""));if(g.getElementsByTagName("*").length>0)n.find.TAG=function(j,o){var m=o.getElementsByTagName(j[1]);if(j[1]==="*"){for(var p=[],q=0;m[q];q++)m[q].nodeType===1&&p.push(m[q]);m=p}return m};g.innerHTML="";if(g.firstChild&&typeof g.firstChild.getAttribute!=="undefined"&&g.firstChild.getAttribute("href")!=="#")n.attrHandle.href=function(j){return j.getAttribute("href",2)};g=null})();u.querySelectorAll&& - function(){var g=l,j=u.createElement("div");j.innerHTML="

";if(!(j.querySelectorAll&&j.querySelectorAll(".TEST").length===0)){l=function(m,p,q,t){p=p||u;if(!t&&!l.isXML(p))if(p.nodeType===9)try{return D(p.querySelectorAll(m),q)}catch(x){}else if(p.nodeType===1&&p.nodeName.toLowerCase()!=="object"){var C=p.id,P=p.id="__sizzle__";try{return D(p.querySelectorAll("#"+P+" "+m),q)}catch(N){}finally{if(C)p.id=C;else p.removeAttribute("id")}}return g(m,p,q,t)};for(var o in g)l[o]=g[o]; - j=null}}();(function(){var g=u.documentElement,j=g.matchesSelector||g.mozMatchesSelector||g.webkitMatchesSelector||g.msMatchesSelector,o=false;try{j.call(u.documentElement,":sizzle")}catch(m){o=true}if(j)l.matchesSelector=function(p,q){try{if(o||!n.match.PSEUDO.test(q))return j.call(p,q)}catch(t){}return l(q,null,null,[p]).length>0}})();(function(){var g=u.createElement("div");g.innerHTML="
";if(!(!g.getElementsByClassName||g.getElementsByClassName("e").length=== - 0)){g.lastChild.className="e";if(g.getElementsByClassName("e").length!==1){n.order.splice(1,0,"CLASS");n.find.CLASS=function(j,o,m){if(typeof o.getElementsByClassName!=="undefined"&&!m)return o.getElementsByClassName(j[1])};g=null}}})();l.contains=u.documentElement.contains?function(g,j){return g!==j&&(g.contains?g.contains(j):true)}:function(g,j){return!!(g.compareDocumentPosition(j)&16)};l.isXML=function(g){return(g=(g?g.ownerDocument||g:0).documentElement)?g.nodeName!=="HTML":false};var M=function(g, - j){for(var o=[],m="",p,q=j.nodeType?[j]:j;p=n.match.PSEUDO.exec(g);){m+=p[0];g=g.replace(n.match.PSEUDO,"")}g=n.relative[g]?g+"*":g;p=0;for(var t=q.length;p0)for(var h=d;h0},closest:function(a, - b){var d=[],e,f,h=this[0];if(c.isArray(a)){var k={},l,n=1;if(h&&a.length){e=0;for(f=a.length;e-1:c(h).is(e))d.push({selector:l,elem:h,level:n})}h=h.parentNode;n++}}return d}k=$a.test(a)?c(a,b||this.context):null;e=0;for(f=this.length;e-1:c.find.matchesSelector(h,a)){d.push(h);break}else{h=h.parentNode;if(!h|| - !h.ownerDocument||h===b)break}d=d.length>1?c.unique(d):d;return this.pushStack(d,"closest",a)},index:function(a){if(!a||typeof a==="string")return c.inArray(this[0],a?c(a):this.parent().children());return c.inArray(a.jquery?a[0]:a,this)},add:function(a,b){var d=typeof a==="string"?c(a,b||this.context):c.makeArray(a),e=c.merge(this.get(),d);return this.pushStack(!d[0]||!d[0].parentNode||d[0].parentNode.nodeType===11||!e[0]||!e[0].parentNode||e[0].parentNode.nodeType===11?e:c.unique(e))},andSelf:function(){return this.add(this.prevObject)}}); - c.each({parent:function(a){return(a=a.parentNode)&&a.nodeType!==11?a:null},parents:function(a){return c.dir(a,"parentNode")},parentsUntil:function(a,b,d){return c.dir(a,"parentNode",d)},next:function(a){return c.nth(a,2,"nextSibling")},prev:function(a){return c.nth(a,2,"previousSibling")},nextAll:function(a){return c.dir(a,"nextSibling")},prevAll:function(a){return c.dir(a,"previousSibling")},nextUntil:function(a,b,d){return c.dir(a,"nextSibling",d)},prevUntil:function(a,b,d){return c.dir(a,"previousSibling", - d)},siblings:function(a){return c.sibling(a.parentNode.firstChild,a)},children:function(a){return c.sibling(a.firstChild)},contents:function(a){return c.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:c.makeArray(a.childNodes)}},function(a,b){c.fn[a]=function(d,e){var f=c.map(this,b,d);Wa.test(a)||(e=d);if(e&&typeof e==="string")f=c.filter(e,f);f=this.length>1?c.unique(f):f;if((this.length>1||Ya.test(e))&&Xa.test(a))f=f.reverse();return this.pushStack(f,a,Za.call(arguments).join(","))}}); - c.extend({filter:function(a,b,d){if(d)a=":not("+a+")";return b.length===1?c.find.matchesSelector(b[0],a)?[b[0]]:[]:c.find.matches(a,b)},dir:function(a,b,d){var e=[];for(a=a[b];a&&a.nodeType!==9&&(d===A||a.nodeType!==1||!c(a).is(d));){a.nodeType===1&&e.push(a);a=a[b]}return e},nth:function(a,b,d){b=b||1;for(var e=0;a;a=a[d])if(a.nodeType===1&&++e===b)break;return a},sibling:function(a,b){for(var d=[];a;a=a.nextSibling)a.nodeType===1&&a!==b&&d.push(a);return d}});var xa=/ jQuery\d+="(?:\d+|null)"/g, - $=/^\s+/,ya=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,za=/<([\w:]+)/,ab=/\s]+\/)>/g,O={option:[1,""],legend:[1,"
","
"],thead:[1,"","
"],tr:[2,"","
"],td:[3,"","
"],col:[2,"","
"], - area:[1,"",""],_default:[0,"",""]};O.optgroup=O.option;O.tbody=O.tfoot=O.colgroup=O.caption=O.thead;O.th=O.td;if(!c.support.htmlSerialize)O._default=[1,"div
","
"];c.fn.extend({text:function(a){if(c.isFunction(a))return this.each(function(b){var d=c(this);d.text(a.call(this,b,d.text()))});if(typeof a!=="object"&&a!==A)return this.empty().append((this[0]&&this[0].ownerDocument||u).createTextNode(a));return c.text(this)},wrapAll:function(a){if(c.isFunction(a))return this.each(function(d){c(this).wrapAll(a.call(this, - d))});if(this[0]){var b=c(a,this[0].ownerDocument).eq(0).clone(true);this[0].parentNode&&b.insertBefore(this[0]);b.map(function(){for(var d=this;d.firstChild&&d.firstChild.nodeType===1;)d=d.firstChild;return d}).append(this)}return this},wrapInner:function(a){if(c.isFunction(a))return this.each(function(b){c(this).wrapInner(a.call(this,b))});return this.each(function(){var b=c(this),d=b.contents();d.length?d.wrapAll(a):b.append(a)})},wrap:function(a){return this.each(function(){c(this).wrapAll(a)})}, - unwrap:function(){return this.parent().each(function(){c.nodeName(this,"body")||c(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,true,function(a){this.nodeType===1&&this.appendChild(a)})},prepend:function(){return this.domManip(arguments,true,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,false,function(b){this.parentNode.insertBefore(b,this)});else if(arguments.length){var a= - c(arguments[0]);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,false,function(b){this.parentNode.insertBefore(b,this.nextSibling)});else if(arguments.length){var a=this.pushStack(this,"after",arguments);a.push.apply(a,c(arguments[0]).toArray());return a}},remove:function(a,b){for(var d=0,e;(e=this[d])!=null;d++)if(!a||c.filter(a,[e]).length){if(!b&&e.nodeType===1){c.cleanData(e.getElementsByTagName("*")); - c.cleanData([e])}e.parentNode&&e.parentNode.removeChild(e)}return this},empty:function(){for(var a=0,b;(b=this[a])!=null;a++)for(b.nodeType===1&&c.cleanData(b.getElementsByTagName("*"));b.firstChild;)b.removeChild(b.firstChild);return this},clone:function(a){var b=this.map(function(){if(!c.support.noCloneEvent&&!c.isXMLDoc(this)){var d=this.outerHTML,e=this.ownerDocument;if(!d){d=e.createElement("div");d.appendChild(this.cloneNode(true));d=d.innerHTML}return c.clean([d.replace(xa,"").replace(cb,'="$1">').replace($, - "")],e)[0]}else return this.cloneNode(true)});if(a===true){la(this,b);la(this.find("*"),b.find("*"))}return b},html:function(a){if(a===A)return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(xa,""):null;else if(typeof a==="string"&&!Aa.test(a)&&(c.support.leadingWhitespace||!$.test(a))&&!O[(za.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(ya,"<$1>");try{for(var b=0,d=this.length;b0||e.cacheable||this.length>1?l.cloneNode(true):l)}k.length&&c.each(k,Ka)}return this}});c.buildFragment=function(a,b,d){var e,f,h;b=b&&b[0]?b[0].ownerDocument||b[0]:u;if(a.length===1&&typeof a[0]==="string"&&a[0].length<512&&b===u&&!Aa.test(a[0])&&(c.support.checkClone|| - !Ba.test(a[0]))){f=true;if(h=c.fragments[a[0]])if(h!==1)e=h}if(!e){e=b.createDocumentFragment();c.clean(a,b,e,d)}if(f)c.fragments[a[0]]=h?e:1;return{fragment:e,cacheable:f}};c.fragments={};c.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){c.fn[a]=function(d){var e=[];d=c(d);var f=this.length===1&&this[0].parentNode;if(f&&f.nodeType===11&&f.childNodes.length===1&&d.length===1){d[b](this[0]);return this}else{f=0;for(var h= - d.length;f0?this.clone(true):this).get();c(d[f])[b](k);e=e.concat(k)}return this.pushStack(e,a,d.selector)}}});c.extend({clean:function(a,b,d,e){b=b||u;if(typeof b.createElement==="undefined")b=b.ownerDocument||b[0]&&b[0].ownerDocument||u;for(var f=[],h=0,k;(k=a[h])!=null;h++){if(typeof k==="number")k+="";if(k){if(typeof k==="string"&&!bb.test(k))k=b.createTextNode(k);else if(typeof k==="string"){k=k.replace(ya,"<$1>");var l=(za.exec(k)||["",""])[1].toLowerCase(),n=O[l]||O._default, - s=n[0],v=b.createElement("div");for(v.innerHTML=n[1]+k+n[2];s--;)v=v.lastChild;if(!c.support.tbody){s=ab.test(k);l=l==="table"&&!s?v.firstChild&&v.firstChild.childNodes:n[1]===""&&!s?v.childNodes:[];for(n=l.length-1;n>=0;--n)c.nodeName(l[n],"tbody")&&!l[n].childNodes.length&&l[n].parentNode.removeChild(l[n])}!c.support.leadingWhitespace&&$.test(k)&&v.insertBefore(b.createTextNode($.exec(k)[0]),v.firstChild);k=v.childNodes}if(k.nodeType)f.push(k);else f=c.merge(f,k)}}if(d)for(h=0;f[h];h++)if(e&& - c.nodeName(f[h],"script")&&(!f[h].type||f[h].type.toLowerCase()==="text/javascript"))e.push(f[h].parentNode?f[h].parentNode.removeChild(f[h]):f[h]);else{f[h].nodeType===1&&f.splice.apply(f,[h+1,0].concat(c.makeArray(f[h].getElementsByTagName("script"))));d.appendChild(f[h])}return f},cleanData:function(a){for(var b,d,e=c.cache,f=c.event.special,h=c.support.deleteExpando,k=0,l;(l=a[k])!=null;k++)if(!(l.nodeName&&c.noData[l.nodeName.toLowerCase()]))if(d=l[c.expando]){if((b=e[d])&&b.events)for(var n in b.events)f[n]? - c.event.remove(l,n):c.removeEvent(l,n,b.handle);if(h)delete l[c.expando];else l.removeAttribute&&l.removeAttribute(c.expando);delete e[d]}}});var Ca=/alpha\([^)]*\)/i,db=/opacity=([^)]*)/,eb=/-([a-z])/ig,fb=/([A-Z])/g,Da=/^-?\d+(?:px)?$/i,gb=/^-?\d/,hb={position:"absolute",visibility:"hidden",display:"block"},La=["Left","Right"],Ma=["Top","Bottom"],W,ib=u.defaultView&&u.defaultView.getComputedStyle,jb=function(a,b){return b.toUpperCase()};c.fn.css=function(a,b){if(arguments.length===2&&b===A)return this; - return c.access(this,a,b,true,function(d,e,f){return f!==A?c.style(d,e,f):c.css(d,e)})};c.extend({cssHooks:{opacity:{get:function(a,b){if(b){var d=W(a,"opacity","opacity");return d===""?"1":d}else return a.style.opacity}}},cssNumber:{zIndex:true,fontWeight:true,opacity:true,zoom:true,lineHeight:true},cssProps:{"float":c.support.cssFloat?"cssFloat":"styleFloat"},style:function(a,b,d,e){if(!(!a||a.nodeType===3||a.nodeType===8||!a.style)){var f,h=c.camelCase(b),k=a.style,l=c.cssHooks[h];b=c.cssProps[h]|| - h;if(d!==A){if(!(typeof d==="number"&&isNaN(d)||d==null)){if(typeof d==="number"&&!c.cssNumber[h])d+="px";if(!l||!("set"in l)||(d=l.set(a,d))!==A)try{k[b]=d}catch(n){}}}else{if(l&&"get"in l&&(f=l.get(a,false,e))!==A)return f;return k[b]}}},css:function(a,b,d){var e,f=c.camelCase(b),h=c.cssHooks[f];b=c.cssProps[f]||f;if(h&&"get"in h&&(e=h.get(a,true,d))!==A)return e;else if(W)return W(a,b,f)},swap:function(a,b,d){var e={},f;for(f in b){e[f]=a.style[f];a.style[f]=b[f]}d.call(a);for(f in b)a.style[f]= - e[f]},camelCase:function(a){return a.replace(eb,jb)}});c.curCSS=c.css;c.each(["height","width"],function(a,b){c.cssHooks[b]={get:function(d,e,f){var h;if(e){if(d.offsetWidth!==0)h=ma(d,b,f);else c.swap(d,hb,function(){h=ma(d,b,f)});return h+"px"}},set:function(d,e){if(Da.test(e)){e=parseFloat(e);if(e>=0)return e+"px"}else return e}}});if(!c.support.opacity)c.cssHooks.opacity={get:function(a,b){return db.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||"")?parseFloat(RegExp.$1)/100+"": - b?"1":""},set:function(a,b){var d=a.style;d.zoom=1;var e=c.isNaN(b)?"":"alpha(opacity="+b*100+")",f=d.filter||"";d.filter=Ca.test(f)?f.replace(Ca,e):d.filter+" "+e}};if(ib)W=function(a,b,d){var e;d=d.replace(fb,"-$1").toLowerCase();if(!(b=a.ownerDocument.defaultView))return A;if(b=b.getComputedStyle(a,null)){e=b.getPropertyValue(d);if(e===""&&!c.contains(a.ownerDocument.documentElement,a))e=c.style(a,d)}return e};else if(u.documentElement.currentStyle)W=function(a,b){var d,e,f=a.currentStyle&&a.currentStyle[b], - h=a.style;if(!Da.test(f)&&gb.test(f)){d=h.left;e=a.runtimeStyle.left;a.runtimeStyle.left=a.currentStyle.left;h.left=b==="fontSize"?"1em":f||0;f=h.pixelLeft+"px";h.left=d;a.runtimeStyle.left=e}return f};if(c.expr&&c.expr.filters){c.expr.filters.hidden=function(a){var b=a.offsetHeight;return a.offsetWidth===0&&b===0||!c.support.reliableHiddenOffsets&&(a.style.display||c.css(a,"display"))==="none"};c.expr.filters.visible=function(a){return!c.expr.filters.hidden(a)}}var kb=c.now(),lb=/)<[^<]*)*<\/script>/gi, - mb=/^(?:select|textarea)/i,nb=/^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,ob=/^(?:GET|HEAD|DELETE)$/,Na=/\[\]$/,T=/\=\?(&|$)/,ia=/\?/,pb=/([?&])_=[^&]*/,qb=/^(\w+:)?\/\/([^\/?#]+)/,rb=/%20/g,sb=/#.*$/,Ea=c.fn.load;c.fn.extend({load:function(a,b,d){if(typeof a!=="string"&&Ea)return Ea.apply(this,arguments);else if(!this.length)return this;var e=a.indexOf(" ");if(e>=0){var f=a.slice(e,a.length);a=a.slice(0,e)}e="GET";if(b)if(c.isFunction(b)){d= - b;b=null}else if(typeof b==="object"){b=c.param(b,c.ajaxSettings.traditional);e="POST"}var h=this;c.ajax({url:a,type:e,dataType:"html",data:b,complete:function(k,l){if(l==="success"||l==="notmodified")h.html(f?c("
").append(k.responseText.replace(lb,"")).find(f):k.responseText);d&&h.each(d,[k.responseText,l,k])}});return this},serialize:function(){return c.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?c.makeArray(this.elements):this}).filter(function(){return this.name&& - !this.disabled&&(this.checked||mb.test(this.nodeName)||nb.test(this.type))}).map(function(a,b){var d=c(this).val();return d==null?null:c.isArray(d)?c.map(d,function(e){return{name:b.name,value:e}}):{name:b.name,value:d}}).get()}});c.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(a,b){c.fn[b]=function(d){return this.bind(b,d)}});c.extend({get:function(a,b,d,e){if(c.isFunction(b)){e=e||d;d=b;b=null}return c.ajax({type:"GET",url:a,data:b,success:d,dataType:e})}, - getScript:function(a,b){return c.get(a,null,b,"script")},getJSON:function(a,b,d){return c.get(a,b,d,"json")},post:function(a,b,d,e){if(c.isFunction(b)){e=e||d;d=b;b={}}return c.ajax({type:"POST",url:a,data:b,success:d,dataType:e})},ajaxSetup:function(a){c.extend(c.ajaxSettings,a)},ajaxSettings:{url:location.href,global:true,type:"GET",contentType:"application/x-www-form-urlencoded",processData:true,async:true,xhr:function(){return new E.XMLHttpRequest},accepts:{xml:"application/xml, text/xml",html:"text/html", - script:"text/javascript, application/javascript",json:"application/json, text/javascript",text:"text/plain",_default:"*/*"}},ajax:function(a){var b=c.extend(true,{},c.ajaxSettings,a),d,e,f,h=b.type.toUpperCase(),k=ob.test(h);b.url=b.url.replace(sb,"");b.context=a&&a.context!=null?a.context:b;if(b.data&&b.processData&&typeof b.data!=="string")b.data=c.param(b.data,b.traditional);if(b.dataType==="jsonp"){if(h==="GET")T.test(b.url)||(b.url+=(ia.test(b.url)?"&":"?")+(b.jsonp||"callback")+"=?");else if(!b.data|| - !T.test(b.data))b.data=(b.data?b.data+"&":"")+(b.jsonp||"callback")+"=?";b.dataType="json"}if(b.dataType==="json"&&(b.data&&T.test(b.data)||T.test(b.url))){d=b.jsonpCallback||"jsonp"+kb++;if(b.data)b.data=(b.data+"").replace(T,"="+d+"$1");b.url=b.url.replace(T,"="+d+"$1");b.dataType="script";var l=E[d];E[d]=function(m){f=m;c.handleSuccess(b,w,e,f);c.handleComplete(b,w,e,f);if(c.isFunction(l))l(m);else{E[d]=A;try{delete E[d]}catch(p){}}v&&v.removeChild(B)}}if(b.dataType==="script"&&b.cache===null)b.cache= - false;if(b.cache===false&&h==="GET"){var n=c.now(),s=b.url.replace(pb,"$1_="+n);b.url=s+(s===b.url?(ia.test(b.url)?"&":"?")+"_="+n:"")}if(b.data&&h==="GET")b.url+=(ia.test(b.url)?"&":"?")+b.data;b.global&&c.active++===0&&c.event.trigger("ajaxStart");n=(n=qb.exec(b.url))&&(n[1]&&n[1]!==location.protocol||n[2]!==location.host);if(b.dataType==="script"&&h==="GET"&&n){var v=u.getElementsByTagName("head")[0]||u.documentElement,B=u.createElement("script");if(b.scriptCharset)B.charset=b.scriptCharset;B.src= - b.url;if(!d){var D=false;B.onload=B.onreadystatechange=function(){if(!D&&(!this.readyState||this.readyState==="loaded"||this.readyState==="complete")){D=true;c.handleSuccess(b,w,e,f);c.handleComplete(b,w,e,f);B.onload=B.onreadystatechange=null;v&&B.parentNode&&v.removeChild(B)}}}v.insertBefore(B,v.firstChild);return A}var H=false,w=b.xhr();if(w){b.username?w.open(h,b.url,b.async,b.username,b.password):w.open(h,b.url,b.async);try{if(b.data!=null&&!k||a&&a.contentType)w.setRequestHeader("Content-Type", - b.contentType);if(b.ifModified){c.lastModified[b.url]&&w.setRequestHeader("If-Modified-Since",c.lastModified[b.url]);c.etag[b.url]&&w.setRequestHeader("If-None-Match",c.etag[b.url])}n||w.setRequestHeader("X-Requested-With","XMLHttpRequest");w.setRequestHeader("Accept",b.dataType&&b.accepts[b.dataType]?b.accepts[b.dataType]+", */*; q=0.01":b.accepts._default)}catch(G){}if(b.beforeSend&&b.beforeSend.call(b.context,w,b)===false){b.global&&c.active--===1&&c.event.trigger("ajaxStop");w.abort();return false}b.global&& - c.triggerGlobal(b,"ajaxSend",[w,b]);var M=w.onreadystatechange=function(m){if(!w||w.readyState===0||m==="abort"){H||c.handleComplete(b,w,e,f);H=true;if(w)w.onreadystatechange=c.noop}else if(!H&&w&&(w.readyState===4||m==="timeout")){H=true;w.onreadystatechange=c.noop;e=m==="timeout"?"timeout":!c.httpSuccess(w)?"error":b.ifModified&&c.httpNotModified(w,b.url)?"notmodified":"success";var p;if(e==="success")try{f=c.httpData(w,b.dataType,b)}catch(q){e="parsererror";p=q}if(e==="success"||e==="notmodified")d|| - c.handleSuccess(b,w,e,f);else c.handleError(b,w,e,p);d||c.handleComplete(b,w,e,f);m==="timeout"&&w.abort();if(b.async)w=null}};try{var g=w.abort;w.abort=function(){w&&g.call&&g.call(w);M("abort")}}catch(j){}b.async&&b.timeout>0&&setTimeout(function(){w&&!H&&M("timeout")},b.timeout);try{w.send(k||b.data==null?null:b.data)}catch(o){c.handleError(b,w,null,o);c.handleComplete(b,w,e,f)}b.async||M();return w}},param:function(a,b){var d=[],e=function(h,k){k=c.isFunction(k)?k():k;d[d.length]=encodeURIComponent(h)+ - "="+encodeURIComponent(k)};if(b===A)b=c.ajaxSettings.traditional;if(c.isArray(a)||a.jquery)c.each(a,function(){e(this.name,this.value)});else for(var f in a)ca(f,a[f],b,e);return d.join("&").replace(rb,"+")}});c.extend({active:0,lastModified:{},etag:{},handleError:function(a,b,d,e){a.error&&a.error.call(a.context,b,d,e);a.global&&c.triggerGlobal(a,"ajaxError",[b,a,e])},handleSuccess:function(a,b,d,e){a.success&&a.success.call(a.context,e,d,b);a.global&&c.triggerGlobal(a,"ajaxSuccess",[b,a])},handleComplete:function(a, - b,d){a.complete&&a.complete.call(a.context,b,d);a.global&&c.triggerGlobal(a,"ajaxComplete",[b,a]);a.global&&c.active--===1&&c.event.trigger("ajaxStop")},triggerGlobal:function(a,b,d){(a.context&&a.context.url==null?c(a.context):c.event).trigger(b,d)},httpSuccess:function(a){try{return!a.status&&location.protocol==="file:"||a.status>=200&&a.status<300||a.status===304||a.status===1223}catch(b){}return false},httpNotModified:function(a,b){var d=a.getResponseHeader("Last-Modified"),e=a.getResponseHeader("Etag"); - if(d)c.lastModified[b]=d;if(e)c.etag[b]=e;return a.status===304},httpData:function(a,b,d){var e=a.getResponseHeader("content-type")||"",f=b==="xml"||!b&&e.indexOf("xml")>=0;a=f?a.responseXML:a.responseText;f&&a.documentElement.nodeName==="parsererror"&&c.error("parsererror");if(d&&d.dataFilter)a=d.dataFilter(a,b);if(typeof a==="string")if(b==="json"||!b&&e.indexOf("json")>=0)a=c.parseJSON(a);else if(b==="script"||!b&&e.indexOf("javascript")>=0)c.globalEval(a);return a}});if(E.ActiveXObject)c.ajaxSettings.xhr= - function(){if(E.location.protocol!=="file:")try{return new E.XMLHttpRequest}catch(a){}try{return new E.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}};c.support.ajax=!!c.ajaxSettings.xhr();var da={},tb=/^(?:toggle|show|hide)$/,ub=/^([+\-]=)?([\d+.\-]+)(.*)$/,aa,na=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]];c.fn.extend({show:function(a,b,d){if(a||a===0)return this.animate(S("show",3),a,b,d);else{a= - 0;for(b=this.length;a=0;e--)if(d[e].elem===this){b&&d[e](true);d.splice(e,1)}});b||this.dequeue();return this}});c.each({slideDown:S("show",1),slideUp:S("hide",1),slideToggle:S("toggle",1),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"}},function(a,b){c.fn[a]=function(d,e,f){return this.animate(b, - d,e,f)}});c.extend({speed:function(a,b,d){var e=a&&typeof a==="object"?c.extend({},a):{complete:d||!d&&b||c.isFunction(a)&&a,duration:a,easing:d&&b||b&&!c.isFunction(b)&&b};e.duration=c.fx.off?0:typeof e.duration==="number"?e.duration:e.duration in c.fx.speeds?c.fx.speeds[e.duration]:c.fx.speeds._default;e.old=e.complete;e.complete=function(){e.queue!==false&&c(this).dequeue();c.isFunction(e.old)&&e.old.call(this)};return e},easing:{linear:function(a,b,d,e){return d+e*a},swing:function(a,b,d,e){return(-Math.cos(a* - Math.PI)/2+0.5)*e+d}},timers:[],fx:function(a,b,d){this.options=b;this.elem=a;this.prop=d;if(!b.orig)b.orig={}}});c.fx.prototype={update:function(){this.options.step&&this.options.step.call(this.elem,this.now,this);(c.fx.step[this.prop]||c.fx.step._default)(this)},cur:function(){if(this.elem[this.prop]!=null&&(!this.elem.style||this.elem.style[this.prop]==null))return this.elem[this.prop];var a=parseFloat(c.css(this.elem,this.prop));return a&&a>-1E4?a:0},custom:function(a,b,d){function e(h){return f.step(h)} - this.startTime=c.now();this.start=a;this.end=b;this.unit=d||this.unit||"px";this.now=this.start;this.pos=this.state=0;var f=this;a=c.fx;e.elem=this.elem;if(e()&&c.timers.push(e)&&!aa)aa=setInterval(a.tick,a.interval)},show:function(){this.options.orig[this.prop]=c.style(this.elem,this.prop);this.options.show=true;this.custom(this.prop==="width"||this.prop==="height"?1:0,this.cur());c(this.elem).show()},hide:function(){this.options.orig[this.prop]=c.style(this.elem,this.prop);this.options.hide=true; - this.custom(this.cur(),0)},step:function(a){var b=c.now(),d=true;if(a||b>=this.options.duration+this.startTime){this.now=this.end;this.pos=this.state=1;this.update();this.options.curAnim[this.prop]=true;for(var e in this.options.curAnim)if(this.options.curAnim[e]!==true)d=false;if(d){if(this.options.overflow!=null&&!c.support.shrinkWrapBlocks){var f=this.elem,h=this.options;c.each(["","X","Y"],function(l,n){f.style["overflow"+n]=h.overflow[l]})}this.options.hide&&c(this.elem).hide();if(this.options.hide|| - this.options.show)for(var k in this.options.curAnim)c.style(this.elem,k,this.options.orig[k]);this.options.complete.call(this.elem)}return false}else{a=b-this.startTime;this.state=a/this.options.duration;b=this.options.easing||(c.easing.swing?"swing":"linear");this.pos=c.easing[this.options.specialEasing&&this.options.specialEasing[this.prop]||b](this.state,a,0,1,this.options.duration);this.now=this.start+(this.end-this.start)*this.pos;this.update()}return true}};c.extend(c.fx,{tick:function(){for(var a= - c.timers,b=0;b-1;e={};var s={};if(n)s=f.position();k=n?s.top:parseInt(k,10)||0;l=n?s.left:parseInt(l,10)||0;if(c.isFunction(b))b=b.call(a,d,h);if(b.top!=null)e.top=b.top-h.top+k;if(b.left!=null)e.left=b.left-h.left+l;"using"in b?b.using.call(a, - e):f.css(e)}};c.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),d=this.offset(),e=Fa.test(b[0].nodeName)?{top:0,left:0}:b.offset();d.top-=parseFloat(c.css(a,"marginTop"))||0;d.left-=parseFloat(c.css(a,"marginLeft"))||0;e.top+=parseFloat(c.css(b[0],"borderTopWidth"))||0;e.left+=parseFloat(c.css(b[0],"borderLeftWidth"))||0;return{top:d.top-e.top,left:d.left-e.left}},offsetParent:function(){return this.map(function(){for(var a=this.offsetParent||u.body;a&&!Fa.test(a.nodeName)&& - c.css(a,"position")==="static";)a=a.offsetParent;return a})}});c.each(["Left","Top"],function(a,b){var d="scroll"+b;c.fn[d]=function(e){var f=this[0],h;if(!f)return null;if(e!==A)return this.each(function(){if(h=ea(this))h.scrollTo(!a?e:c(h).scrollLeft(),a?e:c(h).scrollTop());else this[d]=e});else return(h=ea(f))?"pageXOffset"in h?h[a?"pageYOffset":"pageXOffset"]:c.support.boxModel&&h.document.documentElement[d]||h.document.body[d]:f[d]}});c.each(["Height","Width"],function(a,b){var d=b.toLowerCase(); - c.fn["inner"+b]=function(){return this[0]?parseFloat(c.css(this[0],d,"padding")):null};c.fn["outer"+b]=function(e){return this[0]?parseFloat(c.css(this[0],d,e?"margin":"border")):null};c.fn[d]=function(e){var f=this[0];if(!f)return e==null?null:this;if(c.isFunction(e))return this.each(function(h){var k=c(this);k[d](e.call(this,h,k[d]()))});return c.isWindow(f)?f.document.compatMode==="CSS1Compat"&&f.document.documentElement["client"+b]||f.document.body["client"+b]:f.nodeType===9?Math.max(f.documentElement["client"+ - b],f.body["scroll"+b],f.documentElement["scroll"+b],f.body["offset"+b],f.documentElement["offset"+b]):e===A?parseFloat(c.css(f,d)):this.css(d,typeof e==="string"?e:e+"px")}})})(window); - +/*! jQuery v1.7.1 jquery.com | jquery.org/license */ +(function(a,b){function cy(a){return f.isWindow(a)?a:a.nodeType===9?a.defaultView||a.parentWindow:!1}function cv(a){if(!ck[a]){var b=c.body,d=f("<"+a+">").appendTo(b),e=d.css("display");d.remove();if(e==="none"||e===""){cl||(cl=c.createElement("iframe"),cl.frameBorder=cl.width=cl.height=0),b.appendChild(cl);if(!cm||!cl.createElement)cm=(cl.contentWindow||cl.contentDocument).document,cm.write((c.compatMode==="CSS1Compat"?"":"")+""),cm.close();d=cm.createElement(a),cm.body.appendChild(d),e=f.css(d,"display"),b.removeChild(cl)}ck[a]=e}return ck[a]}function cu(a,b){var c={};f.each(cq.concat.apply([],cq.slice(0,b)),function(){c[this]=a});return c}function ct(){cr=b}function cs(){setTimeout(ct,0);return cr=f.now()}function cj(){try{return new a.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}}function ci(){try{return new a.XMLHttpRequest}catch(b){}}function cc(a,c){a.dataFilter&&(c=a.dataFilter(c,a.dataType));var d=a.dataTypes,e={},g,h,i=d.length,j,k=d[0],l,m,n,o,p;for(g=1;g0){if(c!=="border")for(;g=0===c})}function S(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function K(){return!0}function J(){return!1}function n(a,b,c){var d=b+"defer",e=b+"queue",g=b+"mark",h=f._data(a,d);h&&(c==="queue"||!f._data(a,e))&&(c==="mark"||!f._data(a,g))&&setTimeout(function(){!f._data(a,e)&&!f._data(a,g)&&(f.removeData(a,d,!0),h.fire())},0)}function m(a){for(var b in a){if(b==="data"&&f.isEmptyObject(a[b]))continue;if(b!=="toJSON")return!1}return!0}function l(a,c,d){if(d===b&&a.nodeType===1){var e="data-"+c.replace(k,"-$1").toLowerCase();d=a.getAttribute(e);if(typeof d=="string"){try{d=d==="true"?!0:d==="false"?!1:d==="null"?null:f.isNumeric(d)?parseFloat(d):j.test(d)?f.parseJSON(d):d}catch(g){}f.data(a,c,d)}else d=b}return d}function h(a){var b=g[a]={},c,d;a=a.split(/\s+/);for(c=0,d=a.length;c)[^>]*$|#([\w\-]*)$)/,j=/\S/,k=/^\s+/,l=/\s+$/,m=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,n=/^[\],:{}\s]*$/,o=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,p=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,q=/(?:^|:|,)(?:\s*\[)+/g,r=/(webkit)[ \/]([\w.]+)/,s=/(opera)(?:.*version)?[ \/]([\w.]+)/,t=/(msie) ([\w.]+)/,u=/(mozilla)(?:.*? rv:([\w.]+))?/,v=/-([a-z]|[0-9])/ig,w=/^-ms-/,x=function(a,b){return(b+"").toUpperCase()},y=d.userAgent,z,A,B,C=Object.prototype.toString,D=Object.prototype.hasOwnProperty,E=Array.prototype.push,F=Array.prototype.slice,G=String.prototype.trim,H=Array.prototype.indexOf,I={};e.fn=e.prototype={constructor:e,init:function(a,d,f){var g,h,j,k;if(!a)return this;if(a.nodeType){this.context=this[0]=a,this.length=1;return this}if(a==="body"&&!d&&c.body){this.context=c,this[0]=c.body,this.selector=a,this.length=1;return this}if(typeof a=="string"){a.charAt(0)!=="<"||a.charAt(a.length-1)!==">"||a.length<3?g=i.exec(a):g=[null,a,null];if(g&&(g[1]||!d)){if(g[1]){d=d instanceof e?d[0]:d,k=d?d.ownerDocument||d:c,j=m.exec(a),j?e.isPlainObject(d)?(a=[c.createElement(j[1])],e.fn.attr.call(a,d,!0)):a=[k.createElement(j[1])]:(j=e.buildFragment([g[1]],[k]),a=(j.cacheable?e.clone(j.fragment):j.fragment).childNodes);return e.merge(this,a)}h=c.getElementById(g[2]);if(h&&h.parentNode){if(h.id!==g[2])return f.find(a);this.length=1,this[0]=h}this.context=c,this.selector=a;return this}return!d||d.jquery?(d||f).find(a):this.constructor(d).find(a)}if(e.isFunction(a))return f.ready(a);a.selector!==b&&(this.selector=a.selector,this.context=a.context);return e.makeArray(a,this)},selector:"",jquery:"1.7.1",length:0,size:function(){return this.length},toArray:function(){return F.call(this,0)},get:function(a){return a==null?this.toArray():a<0?this[this.length+a]:this[a]},pushStack:function(a,b,c){var d=this.constructor();e.isArray(a)?E.apply(d,a):e.merge(d,a),d.prevObject=this,d.context=this.context,b==="find"?d.selector=this.selector+(this.selector?" ":"")+c:b&&(d.selector=this.selector+"."+b+"("+c+")");return d},each:function(a,b){return e.each(this,a,b)},ready:function(a){e.bindReady(),A.add(a);return this},eq:function(a){a=+a;return a===-1?this.slice(a):this.slice(a,a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(F.apply(this,arguments),"slice",F.call(arguments).join(","))},map:function(a){return this.pushStack(e.map(this,function(b,c){return a.call(b,c,b)}))},end:function(){return this.prevObject||this.constructor(null)},push:E,sort:[].sort,splice:[].splice},e.fn.init.prototype=e.fn,e.extend=e.fn.extend=function(){var a,c,d,f,g,h,i=arguments[0]||{},j=1,k=arguments.length,l=!1;typeof i=="boolean"&&(l=i,i=arguments[1]||{},j=2),typeof i!="object"&&!e.isFunction(i)&&(i={}),k===j&&(i=this,--j);for(;j0)return;A.fireWith(c,[e]),e.fn.trigger&&e(c).trigger("ready").off("ready")}},bindReady:function(){if(!A){A=e.Callbacks("once memory");if(c.readyState==="complete")return setTimeout(e.ready,1);if(c.addEventListener)c.addEventListener("DOMContentLoaded",B,!1),a.addEventListener("load",e.ready,!1);else if(c.attachEvent){c.attachEvent("onreadystatechange",B),a.attachEvent("onload",e.ready);var b=!1;try{b=a.frameElement==null}catch(d){}c.documentElement.doScroll&&b&&J()}}},isFunction:function(a){return e.type(a)==="function"},isArray:Array.isArray||function(a){return e.type(a)==="array"},isWindow:function(a){return a&&typeof a=="object"&&"setInterval"in a},isNumeric:function(a){return!isNaN(parseFloat(a))&&isFinite(a)},type:function(a){return a==null?String(a):I[C.call(a)]||"object"},isPlainObject:function(a){if(!a||e.type(a)!=="object"||a.nodeType||e.isWindow(a))return!1;try{if(a.constructor&&!D.call(a,"constructor")&&!D.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(c){return!1}var d;for(d in a);return d===b||D.call(a,d)},isEmptyObject:function(a){for(var b in a)return!1;return!0},error:function(a){throw new Error(a)},parseJSON:function(b){if(typeof b!="string"||!b)return null;b=e.trim(b);if(a.JSON&&a.JSON.parse)return a.JSON.parse(b);if(n.test(b.replace(o,"@").replace(p,"]").replace(q,"")))return(new Function("return "+b))();e.error("Invalid JSON: "+b)},parseXML:function(c){var d,f;try{a.DOMParser?(f=new DOMParser,d=f.parseFromString(c,"text/xml")):(d=new ActiveXObject("Microsoft.XMLDOM"),d.async="false",d.loadXML(c))}catch(g){d=b}(!d||!d.documentElement||d.getElementsByTagName("parsererror").length)&&e.error("Invalid XML: "+c);return d},noop:function(){},globalEval:function(b){b&&j.test(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(w,"ms-").replace(v,x)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toUpperCase()===b.toUpperCase()},each:function(a,c,d){var f,g=0,h=a.length,i=h===b||e.isFunction(a);if(d){if(i){for(f in a)if(c.apply(a[f],d)===!1)break}else for(;g0&&a[0]&&a[j-1]||j===0||e.isArray(a));if(k)for(;i1?i.call(arguments,0):b,j.notifyWith(k,e)}}function l(a){return function(c){b[a]=arguments.length>1?i.call(arguments,0):c,--g||j.resolveWith(j,b)}}var b=i.call(arguments,0),c=0,d=b.length,e=Array(d),g=d,h=d,j=d<=1&&a&&f.isFunction(a.promise)?a:f.Deferred(),k=j.promise();if(d>1){for(;c
a",d=q.getElementsByTagName("*"),e=q.getElementsByTagName("a")[0];if(!d||!d.length||!e)return{};g=c.createElement("select"),h=g.appendChild(c.createElement("option")),i=q.getElementsByTagName("input")[0],b={leadingWhitespace:q.firstChild.nodeType===3,tbody:!q.getElementsByTagName("tbody").length,htmlSerialize:!!q.getElementsByTagName("link").length,style:/top/.test(e.getAttribute("style")),hrefNormalized:e.getAttribute("href")==="/a",opacity:/^0.55/.test(e.style.opacity),cssFloat:!!e.style.cssFloat,checkOn:i.value==="on",optSelected:h.selected,getSetAttribute:q.className!=="t",enctype:!!c.createElement("form").enctype,html5Clone:c.createElement("nav").cloneNode(!0).outerHTML!=="<:nav>",submitBubbles:!0,changeBubbles:!0,focusinBubbles:!1,deleteExpando:!0,noCloneEvent:!0,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableMarginRight:!0},i.checked=!0,b.noCloneChecked=i.cloneNode(!0).checked,g.disabled=!0,b.optDisabled=!h.disabled;try{delete q.test}catch(s){b.deleteExpando=!1}!q.addEventListener&&q.attachEvent&&q.fireEvent&&(q.attachEvent("onclick",function(){b.noCloneEvent=!1}),q.cloneNode(!0).fireEvent("onclick")),i=c.createElement("input"),i.value="t",i.setAttribute("type","radio"),b.radioValue=i.value==="t",i.setAttribute("checked","checked"),q.appendChild(i),k=c.createDocumentFragment(),k.appendChild(q.lastChild),b.checkClone=k.cloneNode(!0).cloneNode(!0).lastChild.checked,b.appendChecked=i.checked,k.removeChild(i),k.appendChild(q),q.innerHTML="",a.getComputedStyle&&(j=c.createElement("div"),j.style.width="0",j.style.marginRight="0",q.style.width="2px",q.appendChild(j),b.reliableMarginRight=(parseInt((a.getComputedStyle(j,null)||{marginRight:0}).marginRight,10)||0)===0);if(q.attachEvent)for(o in{submit:1,change:1,focusin:1})n="on"+o,p=n in q,p||(q.setAttribute(n,"return;"),p=typeof q[n]=="function"),b[o+"Bubbles"]=p;k.removeChild(q),k=g=h=j=q=i=null,f(function(){var a,d,e,g,h,i,j,k,m,n,o,r=c.getElementsByTagName("body")[0];!r||(j=1,k="position:absolute;top:0;left:0;width:1px;height:1px;margin:0;",m="visibility:hidden;border:0;",n="style='"+k+"border:5px solid #000;padding:0;'",o="
"+""+"
",a=c.createElement("div"),a.style.cssText=m+"width:0;height:0;position:static;top:0;margin-top:"+j+"px",r.insertBefore(a,r.firstChild),q=c.createElement("div"),a.appendChild(q),q.innerHTML="
t
",l=q.getElementsByTagName("td"),p=l[0].offsetHeight===0,l[0].style.display="",l[1].style.display="none",b.reliableHiddenOffsets=p&&l[0].offsetHeight===0,q.innerHTML="",q.style.width=q.style.paddingLeft="1px",f.boxModel=b.boxModel=q.offsetWidth===2,typeof q.style.zoom!="undefined"&&(q.style.display="inline",q.style.zoom=1,b.inlineBlockNeedsLayout=q.offsetWidth===2,q.style.display="",q.innerHTML="
",b.shrinkWrapBlocks=q.offsetWidth!==2),q.style.cssText=k+m,q.innerHTML=o,d=q.firstChild,e=d.firstChild,h=d.nextSibling.firstChild.firstChild,i={doesNotAddBorder:e.offsetTop!==5,doesAddBorderForTableAndCells:h.offsetTop===5},e.style.position="fixed",e.style.top="20px",i.fixedPosition=e.offsetTop===20||e.offsetTop===15,e.style.position=e.style.top="",d.style.overflow="hidden",d.style.position="relative",i.subtractsBorderForOverflowNotVisible=e.offsetTop===-5,i.doesNotIncludeMarginInBodyOffset=r.offsetTop!==j,r.removeChild(a),q=a=null,f.extend(b,i))});return b}();var j=/^(?:\{.*\}|\[.*\])$/,k=/([A-Z])/g;f.extend({cache:{},uuid:0,expando:"jQuery"+(f.fn.jquery+Math.random()).replace(/\D/g,""),noData:{embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:!0},hasData:function(a){a=a.nodeType?f.cache[a[f.expando]]:a[f.expando];return!!a&&!m(a)},data:function(a,c,d,e){if(!!f.acceptData(a)){var g,h,i,j=f.expando,k=typeof c=="string",l=a.nodeType,m=l?f.cache:a,n=l?a[j]:a[j]&&j,o=c==="events";if((!n||!m[n]||!o&&!e&&!m[n].data)&&k&&d===b)return;n||(l?a[j]=n=++f.uuid:n=j),m[n]||(m[n]={},l||(m[n].toJSON=f.noop));if(typeof c=="object"||typeof c=="function")e?m[n]=f.extend(m[n],c):m[n].data=f.extend(m[n].data,c);g=h=m[n],e||(h.data||(h.data={}),h=h.data),d!==b&&(h[f.camelCase(c)]=d);if(o&&!h[c])return g.events;k?(i=h[c],i==null&&(i=h[f.camelCase(c)])):i=h;return i}},removeData:function(a,b,c){if(!!f.acceptData(a)){var d,e,g,h=f.expando,i=a.nodeType,j=i?f.cache:a,k=i?a[h]:h;if(!j[k])return;if(b){d=c?j[k]:j[k].data;if(d){f.isArray(b)||(b in d?b=[b]:(b=f.camelCase(b),b in d?b=[b]:b=b.split(" ")));for(e=0,g=b.length;e-1)return!0;return!1},val:function(a){var c,d,e,g=this[0];{if(!!arguments.length){e=f.isFunction(a);return this.each(function(d){var g=f(this),h;if(this.nodeType===1){e?h=a.call(this,d,g.val()):h=a,h==null?h="":typeof h=="number"?h+="":f.isArray(h)&&(h=f.map(h,function(a){return a==null?"":a+""})),c=f.valHooks[this.nodeName.toLowerCase()]||f.valHooks[this.type];if(!c||!("set"in c)||c.set(this,h,"value")===b)this.value=h}})}if(g){c=f.valHooks[g.nodeName.toLowerCase()]||f.valHooks[g.type];if(c&&"get"in c&&(d=c.get(g,"value"))!==b)return d;d=g.value;return typeof d=="string"?d.replace(q,""):d==null?"":d}}}}),f.extend({valHooks:{option:{get:function(a){var b=a.attributes.value;return!b||b.specified?a.value:a.text}},select:{get:function(a){var b,c,d,e,g=a.selectedIndex,h=[],i=a.options,j=a.type==="select-one";if(g<0)return null;c=j?g:0,d=j?g+1:i.length;for(;c=0}),c.length||(a.selectedIndex=-1);return c}}},attrFn:{val:!0,css:!0,html:!0,text:!0,data:!0,width:!0,height:!0,offset:!0},attr:function(a,c,d,e){var g,h,i,j=a.nodeType;if(!!a&&j!==3&&j!==8&&j!==2){if(e&&c in f.attrFn)return f(a)[c](d);if(typeof a.getAttribute=="undefined")return f.prop(a,c,d);i=j!==1||!f.isXMLDoc(a),i&&(c=c.toLowerCase(),h=f.attrHooks[c]||(u.test(c)?x:w));if(d!==b){if(d===null){f.removeAttr(a,c);return}if(h&&"set"in h&&i&&(g=h.set(a,d,c))!==b)return g;a.setAttribute(c,""+d);return d}if(h&&"get"in h&&i&&(g=h.get(a,c))!==null)return g;g=a.getAttribute(c);return g===null?b:g}},removeAttr:function(a,b){var c,d,e,g,h=0;if(b&&a.nodeType===1){d=b.toLowerCase().split(p),g=d.length;for(;h=0}})});var z=/^(?:textarea|input|select)$/i,A=/^([^\.]*)?(?:\.(.+))?$/,B=/\bhover(\.\S+)?\b/,C=/^key/,D=/^(?:mouse|contextmenu)|click/,E=/^(?:focusinfocus|focusoutblur)$/,F=/^(\w*)(?:#([\w\-]+))?(?:\.([\w\-]+))?$/,G=function(a){var b=F.exec(a);b&&(b[1]=(b[1]||"").toLowerCase(),b[3]=b[3]&&new RegExp("(?:^|\\s)"+b[3]+"(?:\\s|$)"));return b},H=function(a,b){var c=a.attributes||{};return(!b[1]||a.nodeName.toLowerCase()===b[1])&&(!b[2]||(c.id||{}).value===b[2])&&(!b[3]||b[3].test((c["class"]||{}).value))},I=function(a){return f.event.special.hover?a:a.replace(B,"mouseenter$1 mouseleave$1")}; +f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3||a.nodeType===8||!c||!d||!(h=f._data(a)))){d.handler&&(p=d,d=p.handler),d.guid||(d.guid=f.guid++),j=h.events,j||(h.events=j={}),i=h.handle,i||(h.handle=i=function(a){return typeof f!="undefined"&&(!a||f.event.triggered!==a.type)?f.event.dispatch.apply(i.elem,arguments):b},i.elem=a),c=f.trim(I(c)).split(" ");for(k=0;k=0&&(h=h.slice(0,-1),k=!0),h.indexOf(".")>=0&&(i=h.split("."),h=i.shift(),i.sort());if((!e||f.event.customEvent[h])&&!f.event.global[h])return;c=typeof c=="object"?c[f.expando]?c:new f.Event(h,c):new f.Event(h),c.type=h,c.isTrigger=!0,c.exclusive=k,c.namespace=i.join("."),c.namespace_re=c.namespace?new RegExp("(^|\\.)"+i.join("\\.(?:.*\\.)?")+"(\\.|$)"):null,o=h.indexOf(":")<0?"on"+h:"";if(!e){j=f.cache;for(l in j)j[l].events&&j[l].events[h]&&f.event.trigger(c,d,j[l].handle.elem,!0);return}c.result=b,c.target||(c.target=e),d=d!=null?f.makeArray(d):[],d.unshift(c),p=f.event.special[h]||{};if(p.trigger&&p.trigger.apply(e,d)===!1)return;r=[[e,p.bindType||h]];if(!g&&!p.noBubble&&!f.isWindow(e)){s=p.delegateType||h,m=E.test(s+h)?e:e.parentNode,n=null;for(;m;m=m.parentNode)r.push([m,s]),n=m;n&&n===e.ownerDocument&&r.push([n.defaultView||n.parentWindow||a,s])}for(l=0;le&&i.push({elem:this,matches:d.slice(e)});for(j=0;j0?this.on(b,null,a,c):this.trigger(b)},f.attrFn&&(f.attrFn[b]=!0),C.test(b)&&(f.event.fixHooks[b]=f.event.keyHooks),D.test(b)&&(f.event.fixHooks[b]=f.event.mouseHooks)}),function(){function x(a,b,c,e,f,g){for(var h=0,i=e.length;h0){k=j;break}}j=j[a]}e[h]=k}}}function w(a,b,c,e,f,g){for(var h=0,i=e.length;h+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,d="sizcache"+(Math.random()+"").replace(".",""),e=0,g=Object.prototype.toString,h=!1,i=!0,j=/\\/g,k=/\r\n/g,l=/\W/;[0,0].sort(function(){i=!1;return 0});var m=function(b,d,e,f){e=e||[],d=d||c;var h=d;if(d.nodeType!==1&&d.nodeType!==9)return[];if(!b||typeof b!="string")return e;var i,j,k,l,n,q,r,t,u=!0,v=m.isXML(d),w=[],x=b;do{a.exec(""),i=a.exec(x);if(i){x=i[3],w.push(i[1]);if(i[2]){l=i[3];break}}}while(i);if(w.length>1&&p.exec(b))if(w.length===2&&o.relative[w[0]])j=y(w[0]+w[1],d,f);else{j=o.relative[w[0]]?[d]:m(w.shift(),d);while(w.length)b=w.shift(),o.relative[b]&&(b+=w.shift()),j=y(b,j,f)}else{!f&&w.length>1&&d.nodeType===9&&!v&&o.match.ID.test(w[0])&&!o.match.ID.test(w[w.length-1])&&(n=m.find(w.shift(),d,v),d=n.expr?m.filter(n.expr,n.set)[0]:n.set[0]);if(d){n=f?{expr:w.pop(),set:s(f)}:m.find(w.pop(),w.length===1&&(w[0]==="~"||w[0]==="+")&&d.parentNode?d.parentNode:d,v),j=n.expr?m.filter(n.expr,n.set):n.set,w.length>0?k=s(j):u=!1;while(w.length)q=w.pop(),r=q,o.relative[q]?r=w.pop():q="",r==null&&(r=d),o.relative[q](k,r,v)}else k=w=[]}k||(k=j),k||m.error(q||b);if(g.call(k)==="[object Array]")if(!u)e.push.apply(e,k);else if(d&&d.nodeType===1)for(t=0;k[t]!=null;t++)k[t]&&(k[t]===!0||k[t].nodeType===1&&m.contains(d,k[t]))&&e.push(j[t]);else for(t=0;k[t]!=null;t++)k[t]&&k[t].nodeType===1&&e.push(j[t]);else s(k,e);l&&(m(l,h,e,f),m.uniqueSort(e));return e};m.uniqueSort=function(a){if(u){h=i,a.sort(u);if(h)for(var b=1;b0},m.find=function(a,b,c){var d,e,f,g,h,i;if(!a)return[];for(e=0,f=o.order.length;e":function(a,b){var c,d=typeof b=="string",e=0,f=a.length;if(d&&!l.test(b)){b=b.toLowerCase();for(;e=0)?c||d.push(h):c&&(b[g]=!1));return!1},ID:function(a){return a[1].replace(j,"")},TAG:function(a,b){return a[1].replace(j,"").toLowerCase()},CHILD:function(a){if(a[1]==="nth"){a[2]||m.error(a[0]),a[2]=a[2].replace(/^\+|\s*/g,"");var b=/(-?)(\d*)(?:n([+\-]?\d*))?/.exec(a[2]==="even"&&"2n"||a[2]==="odd"&&"2n+1"||!/\D/.test(a[2])&&"0n+"+a[2]||a[2]);a[2]=b[1]+(b[2]||1)-0,a[3]=b[3]-0}else a[2]&&m.error(a[0]);a[0]=e++;return a},ATTR:function(a,b,c,d,e,f){var g=a[1]=a[1].replace(j,"");!f&&o.attrMap[g]&&(a[1]=o.attrMap[g]),a[4]=(a[4]||a[5]||"").replace(j,""),a[2]==="~="&&(a[4]=" "+a[4]+" ");return a},PSEUDO:function(b,c,d,e,f){if(b[1]==="not")if((a.exec(b[3])||"").length>1||/^\w/.test(b[3]))b[3]=m(b[3],null,null,c);else{var g=m.filter(b[3],c,d,!0^f);d||e.push.apply(e,g);return!1}else if(o.match.POS.test(b[0])||o.match.CHILD.test(b[0]))return!0;return b},POS:function(a){a.unshift(!0);return a}},filters:{enabled:function(a){return a.disabled===!1&&a.type!=="hidden"},disabled:function(a){return a.disabled===!0},checked:function(a){return a.checked===!0},selected:function(a){a.parentNode&&a.parentNode.selectedIndex;return a.selected===!0},parent:function(a){return!!a.firstChild},empty:function(a){return!a.firstChild},has:function(a,b,c){return!!m(c[3],a).length},header:function(a){return/h\d/i.test(a.nodeName)},text:function(a){var b=a.getAttribute("type"),c=a.type;return a.nodeName.toLowerCase()==="input"&&"text"===c&&(b===c||b===null)},radio:function(a){return a.nodeName.toLowerCase()==="input"&&"radio"===a.type},checkbox:function(a){return a.nodeName.toLowerCase()==="input"&&"checkbox"===a.type},file:function(a){return a.nodeName.toLowerCase()==="input"&&"file"===a.type},password:function(a){return a.nodeName.toLowerCase()==="input"&&"password"===a.type},submit:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"submit"===a.type},image:function(a){return a.nodeName.toLowerCase()==="input"&&"image"===a.type},reset:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"reset"===a.type},button:function(a){var b=a.nodeName.toLowerCase();return b==="input"&&"button"===a.type||b==="button"},input:function(a){return/input|select|textarea|button/i.test(a.nodeName)},focus:function(a){return a===a.ownerDocument.activeElement}},setFilters:{first:function(a,b){return b===0},last:function(a,b,c,d){return b===d.length-1},even:function(a,b){return b%2===0},odd:function(a,b){return b%2===1},lt:function(a,b,c){return bc[3]-0},nth:function(a,b,c){return c[3]-0===b},eq:function(a,b,c){return c[3]-0===b}},filter:{PSEUDO:function(a,b,c,d){var e=b[1],f=o.filters[e];if(f)return f(a,c,b,d);if(e==="contains")return(a.textContent||a.innerText||n([a])||"").indexOf(b[3])>=0;if(e==="not"){var g=b[3];for(var h=0,i=g.length;h=0}},ID:function(a,b){return a.nodeType===1&&a.getAttribute("id")===b},TAG:function(a,b){return b==="*"&&a.nodeType===1||!!a.nodeName&&a.nodeName.toLowerCase()===b},CLASS:function(a,b){return(" "+(a.className||a.getAttribute("class"))+" ").indexOf(b)>-1},ATTR:function(a,b){var c=b[1],d=m.attr?m.attr(a,c):o.attrHandle[c]?o.attrHandle[c](a):a[c]!=null?a[c]:a.getAttribute(c),e=d+"",f=b[2],g=b[4];return d==null?f==="!=":!f&&m.attr?d!=null:f==="="?e===g:f==="*="?e.indexOf(g)>=0:f==="~="?(" "+e+" ").indexOf(g)>=0:g?f==="!="?e!==g:f==="^="?e.indexOf(g)===0:f==="$="?e.substr(e.length-g.length)===g:f==="|="?e===g||e.substr(0,g.length+1)===g+"-":!1:e&&d!==!1},POS:function(a,b,c,d){var e=b[2],f=o.setFilters[e];if(f)return f(a,c,b,d)}}},p=o.match.POS,q=function(a,b){return"\\"+(b-0+1)};for(var r in o.match)o.match[r]=new RegExp(o.match[r].source+/(?![^\[]*\])(?![^\(]*\))/.source),o.leftMatch[r]=new RegExp(/(^(?:.|\r|\n)*?)/.source+o.match[r].source.replace(/\\(\d+)/g,q));var s=function(a,b){a=Array.prototype.slice.call(a,0);if(b){b.push.apply(b,a);return b}return a};try{Array.prototype.slice.call(c.documentElement.childNodes,0)[0].nodeType}catch(t){s=function(a,b){var c=0,d=b||[];if(g.call(a)==="[object Array]")Array.prototype.push.apply(d,a);else if(typeof a.length=="number")for(var e=a.length;c",e.insertBefore(a,e.firstChild),c.getElementById(d)&&(o.find.ID=function(a,c,d){if(typeof c.getElementById!="undefined"&&!d){var e=c.getElementById(a[1]);return e?e.id===a[1]||typeof e.getAttributeNode!="undefined"&&e.getAttributeNode("id").nodeValue===a[1]?[e]:b:[]}},o.filter.ID=function(a,b){var c=typeof a.getAttributeNode!="undefined"&&a.getAttributeNode("id");return a.nodeType===1&&c&&c.nodeValue===b}),e.removeChild(a),e=a=null}(),function(){var a=c.createElement("div");a.appendChild(c.createComment("")),a.getElementsByTagName("*").length>0&&(o.find.TAG=function(a,b){var c=b.getElementsByTagName(a[1]);if(a[1]==="*"){var d=[];for(var e=0;c[e];e++)c[e].nodeType===1&&d.push(c[e]);c=d}return c}),a.innerHTML="",a.firstChild&&typeof a.firstChild.getAttribute!="undefined"&&a.firstChild.getAttribute("href")!=="#"&&(o.attrHandle.href=function(a){return a.getAttribute("href",2)}),a=null}(),c.querySelectorAll&&function(){var a=m,b=c.createElement("div"),d="__sizzle__";b.innerHTML="

";if(!b.querySelectorAll||b.querySelectorAll(".TEST").length!==0){m=function(b,e,f,g){e=e||c;if(!g&&!m.isXML(e)){var h=/^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec(b);if(h&&(e.nodeType===1||e.nodeType===9)){if(h[1])return s(e.getElementsByTagName(b),f);if(h[2]&&o.find.CLASS&&e.getElementsByClassName)return s(e.getElementsByClassName(h[2]),f)}if(e.nodeType===9){if(b==="body"&&e.body)return s([e.body],f);if(h&&h[3]){var i=e.getElementById(h[3]);if(!i||!i.parentNode)return s([],f);if(i.id===h[3])return s([i],f)}try{return s(e.querySelectorAll(b),f)}catch(j){}}else if(e.nodeType===1&&e.nodeName.toLowerCase()!=="object"){var k=e,l=e.getAttribute("id"),n=l||d,p=e.parentNode,q=/^\s*[+~]/.test(b);l?n=n.replace(/'/g,"\\$&"):e.setAttribute("id",n),q&&p&&(e=e.parentNode);try{if(!q||p)return s(e.querySelectorAll("[id='"+n+"'] "+b),f)}catch(r){}finally{l||k.removeAttribute("id")}}}return a(b,e,f,g)};for(var e in a)m[e]=a[e];b=null}}(),function(){var a=c.documentElement,b=a.matchesSelector||a.mozMatchesSelector||a.webkitMatchesSelector||a.msMatchesSelector;if(b){var d=!b.call(c.createElement("div"),"div"),e=!1;try{b.call(c.documentElement,"[test!='']:sizzle")}catch(f){e=!0}m.matchesSelector=function(a,c){c=c.replace(/\=\s*([^'"\]]*)\s*\]/g,"='$1']");if(!m.isXML(a))try{if(e||!o.match.PSEUDO.test(c)&&!/!=/.test(c)){var f=b.call(a,c);if(f||!d||a.document&&a.document.nodeType!==11)return f}}catch(g){}return m(c,null,null,[a]).length>0}}}(),function(){var a=c.createElement("div");a.innerHTML="
";if(!!a.getElementsByClassName&&a.getElementsByClassName("e").length!==0){a.lastChild.className="e";if(a.getElementsByClassName("e").length===1)return;o.order.splice(1,0,"CLASS"),o.find.CLASS=function(a,b,c){if(typeof b.getElementsByClassName!="undefined"&&!c)return b.getElementsByClassName(a[1])},a=null}}(),c.documentElement.contains?m.contains=function(a,b){return a!==b&&(a.contains?a.contains(b):!0)}:c.documentElement.compareDocumentPosition?m.contains=function(a,b){return!!(a.compareDocumentPosition(b)&16)}:m.contains=function(){return!1},m.isXML=function(a){var b=(a?a.ownerDocument||a:0).documentElement;return b?b.nodeName!=="HTML":!1};var y=function(a,b,c){var d,e=[],f="",g=b.nodeType?[b]:b;while(d=o.match.PSEUDO.exec(a))f+=d[0],a=a.replace(o.match.PSEUDO,"");a=o.relative[a]?a+"*":a;for(var h=0,i=g.length;h0)for(h=g;h=0:f.filter(a,this).length>0:this.filter(a).length>0)},closest:function(a,b){var c=[],d,e,g=this[0];if(f.isArray(a)){var h=1;while(g&&g.ownerDocument&&g!==b){for(d=0;d-1:f.find.matchesSelector(g,a)){c.push(g);break}g=g.parentNode;if(!g||!g.ownerDocument||g===b||g.nodeType===11)break}}c=c.length>1?f.unique(c):c;return this.pushStack(c,"closest",a)},index:function(a){if(!a)return this[0]&&this[0].parentNode?this.prevAll().length:-1;if(typeof a=="string")return f.inArray(this[0],f(a));return f.inArray(a.jquery?a[0]:a,this)},add:function(a,b){var c=typeof a=="string"?f(a,b):f.makeArray(a&&a.nodeType?[a]:a),d=f.merge(this.get(),c);return this.pushStack(S(c[0])||S(d[0])?d:f.unique(d))},andSelf:function(){return this.add(this.prevObject)}}),f.each({parent:function(a){var b=a.parentNode;return b&&b.nodeType!==11?b:null},parents:function(a){return f.dir(a,"parentNode")},parentsUntil:function(a,b,c){return f.dir(a,"parentNode",c)},next:function(a){return f.nth(a,2,"nextSibling")},prev:function(a){return f.nth(a,2,"previousSibling")},nextAll:function(a){return f.dir(a,"nextSibling")},prevAll:function(a){return f.dir(a,"previousSibling")},nextUntil:function(a,b,c){return f.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return f.dir(a,"previousSibling",c)},siblings:function(a){return f.sibling(a.parentNode.firstChild,a)},children:function(a){return f.sibling(a.firstChild)},contents:function(a){return f.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:f.makeArray(a.childNodes)}},function(a,b){f.fn[a]=function(c,d){var e=f.map(this,b,c);L.test(a)||(d=c),d&&typeof d=="string"&&(e=f.filter(d,e)),e=this.length>1&&!R[a]?f.unique(e):e,(this.length>1||N.test(d))&&M.test(a)&&(e=e.reverse());return this.pushStack(e,a,P.call(arguments).join(","))}}),f.extend({filter:function(a,b,c){c&&(a=":not("+a+")");return b.length===1?f.find.matchesSelector(b[0],a)?[b[0]]:[]:f.find.matches(a,b)},dir:function(a,c,d){var e=[],g=a[c];while(g&&g.nodeType!==9&&(d===b||g.nodeType!==1||!f(g).is(d)))g.nodeType===1&&e.push(g),g=g[c];return e},nth:function(a,b,c,d){b=b||1;var e=0;for(;a;a=a[c])if(a.nodeType===1&&++e===b)break;return a},sibling:function(a,b){var c=[];for(;a;a=a.nextSibling)a.nodeType===1&&a!==b&&c.push(a);return c}});var V="abbr|article|aside|audio|canvas|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",W=/ jQuery\d+="(?:\d+|null)"/g,X=/^\s+/,Y=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,Z=/<([\w:]+)/,$=/",""],legend:[1,"
","
"],thead:[1,"","
"],tr:[2,"","
"],td:[3,"","
"],col:[2,"","
"],area:[1,"",""],_default:[0,"",""]},bh=U(c);bg.optgroup=bg.option,bg.tbody=bg.tfoot=bg.colgroup=bg.caption=bg.thead,bg.th=bg.td,f.support.htmlSerialize||(bg._default=[1,"div
","
"]),f.fn.extend({text:function(a){if(f.isFunction(a))return this.each(function(b){var c=f(this);c.text(a.call(this,b,c.text()))});if(typeof a!="object"&&a!==b)return this.empty().append((this[0]&&this[0].ownerDocument||c).createTextNode(a));return f.text(this)},wrapAll:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapAll(a.call(this,b))});if(this[0]){var b=f(a,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstChild&&a.firstChild.nodeType===1)a=a.firstChild;return a}).append(this)}return this},wrapInner:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapInner(a.call(this,b))});return this.each(function(){var b=f(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){var b=f.isFunction(a);return this.each(function(c){f(this).wrapAll(b?a.call(this,c):a)})},unwrap:function(){return this.parent().each(function(){f.nodeName(this,"body")||f(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.appendChild(a)})},prepend:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this)});if(arguments.length){var a=f.clean(arguments);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this.nextSibling)});if(arguments.length){var a=this.pushStack(this,"after",arguments);a.push.apply(a,f.clean(arguments));return a}},remove:function(a,b){for(var c=0,d;(d=this[c])!=null;c++)if(!a||f.filter(a,[d]).length)!b&&d.nodeType===1&&(f.cleanData(d.getElementsByTagName("*")),f.cleanData([d])),d.parentNode&&d.parentNode.removeChild(d);return this},empty:function() +{for(var a=0,b;(b=this[a])!=null;a++){b.nodeType===1&&f.cleanData(b.getElementsByTagName("*"));while(b.firstChild)b.removeChild(b.firstChild)}return this},clone:function(a,b){a=a==null?!1:a,b=b==null?a:b;return this.map(function(){return f.clone(this,a,b)})},html:function(a){if(a===b)return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(W,""):null;if(typeof a=="string"&&!ba.test(a)&&(f.support.leadingWhitespace||!X.test(a))&&!bg[(Z.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(Y,"<$1>");try{for(var c=0,d=this.length;c1&&l0?this.clone(!0):this).get();f(e[h])[b](j),d=d.concat(j)}return this.pushStack(d,a,e.selector)}}),f.extend({clone:function(a,b,c){var d,e,g,h=f.support.html5Clone||!bc.test("<"+a.nodeName)?a.cloneNode(!0):bo(a);if((!f.support.noCloneEvent||!f.support.noCloneChecked)&&(a.nodeType===1||a.nodeType===11)&&!f.isXMLDoc(a)){bk(a,h),d=bl(a),e=bl(h);for(g=0;d[g];++g)e[g]&&bk(d[g],e[g])}if(b){bj(a,h);if(c){d=bl(a),e=bl(h);for(g=0;d[g];++g)bj(d[g],e[g])}}d=e=null;return h},clean:function(a,b,d,e){var g;b=b||c,typeof b.createElement=="undefined"&&(b=b.ownerDocument||b[0]&&b[0].ownerDocument||c);var h=[],i;for(var j=0,k;(k=a[j])!=null;j++){typeof k=="number"&&(k+="");if(!k)continue;if(typeof k=="string")if(!_.test(k))k=b.createTextNode(k);else{k=k.replace(Y,"<$1>");var l=(Z.exec(k)||["",""])[1].toLowerCase(),m=bg[l]||bg._default,n=m[0],o=b.createElement("div");b===c?bh.appendChild(o):U(b).appendChild(o),o.innerHTML=m[1]+k+m[2];while(n--)o=o.lastChild;if(!f.support.tbody){var p=$.test(k),q=l==="table"&&!p?o.firstChild&&o.firstChild.childNodes:m[1]===""&&!p?o.childNodes:[];for(i=q.length-1;i>=0;--i)f.nodeName(q[i],"tbody")&&!q[i].childNodes.length&&q[i].parentNode.removeChild(q[i])}!f.support.leadingWhitespace&&X.test(k)&&o.insertBefore(b.createTextNode(X.exec(k)[0]),o.firstChild),k=o.childNodes}var r;if(!f.support.appendChecked)if(k[0]&&typeof (r=k.length)=="number")for(i=0;i=0)return b+"px"}}}),f.support.opacity||(f.cssHooks.opacity={get:function(a,b){return br.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||"")?parseFloat(RegExp.$1)/100+"":b?"1":""},set:function(a,b){var c=a.style,d=a.currentStyle,e=f.isNumeric(b)?"alpha(opacity="+b*100+")":"",g=d&&d.filter||c.filter||"";c.zoom=1;if(b>=1&&f.trim(g.replace(bq,""))===""){c.removeAttribute("filter");if(d&&!d.filter)return}c.filter=bq.test(g)?g.replace(bq,e):g+" "+e}}),f(function(){f.support.reliableMarginRight||(f.cssHooks.marginRight={get:function(a,b){var c;f.swap(a,{display:"inline-block"},function(){b?c=bz(a,"margin-right","marginRight"):c=a.style.marginRight});return c}})}),c.defaultView&&c.defaultView.getComputedStyle&&(bA=function(a,b){var c,d,e;b=b.replace(bs,"-$1").toLowerCase(),(d=a.ownerDocument.defaultView)&&(e=d.getComputedStyle(a,null))&&(c=e.getPropertyValue(b),c===""&&!f.contains(a.ownerDocument.documentElement,a)&&(c=f.style(a,b)));return c}),c.documentElement.currentStyle&&(bB=function(a,b){var c,d,e,f=a.currentStyle&&a.currentStyle[b],g=a.style;f===null&&g&&(e=g[b])&&(f=e),!bt.test(f)&&bu.test(f)&&(c=g.left,d=a.runtimeStyle&&a.runtimeStyle.left,d&&(a.runtimeStyle.left=a.currentStyle.left),g.left=b==="fontSize"?"1em":f||0,f=g.pixelLeft+"px",g.left=c,d&&(a.runtimeStyle.left=d));return f===""?"auto":f}),bz=bA||bB,f.expr&&f.expr.filters&&(f.expr.filters.hidden=function(a){var b=a.offsetWidth,c=a.offsetHeight;return b===0&&c===0||!f.support.reliableHiddenOffsets&&(a.style&&a.style.display||f.css(a,"display"))==="none"},f.expr.filters.visible=function(a){return!f.expr.filters.hidden(a)});var bD=/%20/g,bE=/\[\]$/,bF=/\r?\n/g,bG=/#.*$/,bH=/^(.*?):[ \t]*([^\r\n]*)\r?$/mg,bI=/^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,bJ=/^(?:about|app|app\-storage|.+\-extension|file|res|widget):$/,bK=/^(?:GET|HEAD)$/,bL=/^\/\//,bM=/\?/,bN=/)<[^<]*)*<\/script>/gi,bO=/^(?:select|textarea)/i,bP=/\s+/,bQ=/([?&])_=[^&]*/,bR=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,bS=f.fn.load,bT={},bU={},bV,bW,bX=["*/"]+["*"];try{bV=e.href}catch(bY){bV=c.createElement("a"),bV.href="",bV=bV.href}bW=bR.exec(bV.toLowerCase())||[],f.fn.extend({load:function(a,c,d){if(typeof a!="string"&&bS)return bS.apply(this,arguments);if(!this.length)return this;var e=a.indexOf(" ");if(e>=0){var g=a.slice(e,a.length);a=a.slice(0,e)}var h="GET";c&&(f.isFunction(c)?(d=c,c=b):typeof c=="object"&&(c=f.param(c,f.ajaxSettings.traditional),h="POST"));var i=this;f.ajax({url:a,type:h,dataType:"html",data:c,complete:function(a,b,c){c=a.responseText,a.isResolved()&&(a.done(function(a){c=a}),i.html(g?f("
").append(c.replace(bN,"")).find(g):c)),d&&i.each(d,[c,b,a])}});return this},serialize:function(){return f.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?f.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||bO.test(this.nodeName)||bI.test(this.type))}).map(function(a,b){var c=f(this).val();return c==null?null:f.isArray(c)?f.map(c,function(a,c){return{name:b.name,value:a.replace(bF,"\r\n")}}):{name:b.name,value:c.replace(bF,"\r\n")}}).get()}}),f.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(a,b){f.fn[b]=function(a){return this.on(b,a)}}),f.each(["get","post"],function(a,c){f[c]=function(a,d,e,g){f.isFunction(d)&&(g=g||e,e=d,d=b);return f.ajax({type:c,url:a,data:d,success:e,dataType:g})}}),f.extend({getScript:function(a,c){return f.get(a,b,c,"script")},getJSON:function(a,b,c){return f.get(a,b,c,"json")},ajaxSetup:function(a,b){b?b_(a,f.ajaxSettings):(b=a,a=f.ajaxSettings),b_(a,b);return a},ajaxSettings:{url:bV,isLocal:bJ.test(bW[1]),global:!0,type:"GET",contentType:"application/x-www-form-urlencoded",processData:!0,async:!0,accepts:{xml:"application/xml, text/xml",html:"text/html",text:"text/plain",json:"application/json, text/javascript","*":bX},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText"},converters:{"* text":a.String,"text html":!0,"text json":f.parseJSON,"text xml":f.parseXML},flatOptions:{context:!0,url:!0}},ajaxPrefilter:bZ(bT),ajaxTransport:bZ(bU),ajax:function(a,c){function w(a,c,l,m){if(s!==2){s=2,q&&clearTimeout(q),p=b,n=m||"",v.readyState=a>0?4:0;var o,r,u,w=c,x=l?cb(d,v,l):b,y,z;if(a>=200&&a<300||a===304){if(d.ifModified){if(y=v.getResponseHeader("Last-Modified"))f.lastModified[k]=y;if(z=v.getResponseHeader("Etag"))f.etag[k]=z}if(a===304)w="notmodified",o=!0;else try{r=cc(d,x),w="success",o=!0}catch(A){w="parsererror",u=A}}else{u=w;if(!w||a)w="error",a<0&&(a=0)}v.status=a,v.statusText=""+(c||w),o?h.resolveWith(e,[r,w,v]):h.rejectWith(e,[v,w,u]),v.statusCode(j),j=b,t&&g.trigger("ajax"+(o?"Success":"Error"),[v,d,o?r:u]),i.fireWith(e,[v,w]),t&&(g.trigger("ajaxComplete",[v,d]),--f.active||f.event.trigger("ajaxStop"))}}typeof a=="object"&&(c=a,a=b),c=c||{};var d=f.ajaxSetup({},c),e=d.context||d,g=e!==d&&(e.nodeType||e instanceof f)?f(e):f.event,h=f.Deferred(),i=f.Callbacks("once memory"),j=d.statusCode||{},k,l={},m={},n,o,p,q,r,s=0,t,u,v={readyState:0,setRequestHeader:function(a,b){if(!s){var c=a.toLowerCase();a=m[c]=m[c]||a,l[a]=b}return this},getAllResponseHeaders:function(){return s===2?n:null},getResponseHeader:function(a){var c;if(s===2){if(!o){o={};while(c=bH.exec(n))o[c[1].toLowerCase()]=c[2]}c=o[a.toLowerCase()]}return c===b?null:c},overrideMimeType:function(a){s||(d.mimeType=a);return this},abort:function(a){a=a||"abort",p&&p.abort(a),w(0,a);return this}};h.promise(v),v.success=v.done,v.error=v.fail,v.complete=i.add,v.statusCode=function(a){if(a){var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];else b=a[v.status],v.then(b,b)}return this},d.url=((a||d.url)+"").replace(bG,"").replace(bL,bW[1]+"//"),d.dataTypes=f.trim(d.dataType||"*").toLowerCase().split(bP),d.crossDomain==null&&(r=bR.exec(d.url.toLowerCase()),d.crossDomain=!(!r||r[1]==bW[1]&&r[2]==bW[2]&&(r[3]||(r[1]==="http:"?80:443))==(bW[3]||(bW[1]==="http:"?80:443)))),d.data&&d.processData&&typeof d.data!="string"&&(d.data=f.param(d.data,d.traditional)),b$(bT,d,c,v);if(s===2)return!1;t=d.global,d.type=d.type.toUpperCase(),d.hasContent=!bK.test(d.type),t&&f.active++===0&&f.event.trigger("ajaxStart");if(!d.hasContent){d.data&&(d.url+=(bM.test(d.url)?"&":"?")+d.data,delete d.data),k=d.url;if(d.cache===!1){var x=f.now(),y=d.url.replace(bQ,"$1_="+x);d.url=y+(y===d.url?(bM.test(d.url)?"&":"?")+"_="+x:"")}}(d.data&&d.hasContent&&d.contentType!==!1||c.contentType)&&v.setRequestHeader("Content-Type",d.contentType),d.ifModified&&(k=k||d.url,f.lastModified[k]&&v.setRequestHeader("If-Modified-Since",f.lastModified[k]),f.etag[k]&&v.setRequestHeader("If-None-Match",f.etag[k])),v.setRequestHeader("Accept",d.dataTypes[0]&&d.accepts[d.dataTypes[0]]?d.accepts[d.dataTypes[0]]+(d.dataTypes[0]!=="*"?", "+bX+"; q=0.01":""):d.accepts["*"]);for(u in d.headers)v.setRequestHeader(u,d.headers[u]);if(d.beforeSend&&(d.beforeSend.call(e,v,d)===!1||s===2)){v.abort();return!1}for(u in{success:1,error:1,complete:1})v[u](d[u]);p=b$(bU,d,c,v);if(!p)w(-1,"No Transport");else{v.readyState=1,t&&g.trigger("ajaxSend",[v,d]),d.async&&d.timeout>0&&(q=setTimeout(function(){v.abort("timeout")},d.timeout));try{s=1,p.send(l,w)}catch(z){if(s<2)w(-1,z);else throw z}}return v},param:function(a,c){var d=[],e=function(a,b){b=f.isFunction(b)?b():b,d[d.length]=encodeURIComponent(a)+"="+encodeURIComponent(b)};c===b&&(c=f.ajaxSettings.traditional);if(f.isArray(a)||a.jquery&&!f.isPlainObject(a))f.each(a,function(){e(this.name,this.value)});else for(var g in a)ca(g,a[g],c,e);return d.join("&").replace(bD,"+")}}),f.extend({active:0,lastModified:{},etag:{}});var cd=f.now(),ce=/(\=)\?(&|$)|\?\?/i;f.ajaxSetup({jsonp:"callback",jsonpCallback:function(){return f.expando+"_"+cd++}}),f.ajaxPrefilter("json jsonp",function(b,c,d){var e=b.contentType==="application/x-www-form-urlencoded"&&typeof b.data=="string";if(b.dataTypes[0]==="jsonp"||b.jsonp!==!1&&(ce.test(b.url)||e&&ce.test(b.data))){var g,h=b.jsonpCallback=f.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,i=a[h],j=b.url,k=b.data,l="$1"+h+"$2";b.jsonp!==!1&&(j=j.replace(ce,l),b.url===j&&(e&&(k=k.replace(ce,l)),b.data===k&&(j+=(/\?/.test(j)?"&":"?")+b.jsonp+"="+h))),b.url=j,b.data=k,a[h]=function(a){g=[a]},d.always(function(){a[h]=i,g&&f.isFunction(i)&&a[h](g[0])}),b.converters["script json"]=function(){g||f.error(h+" was not called");return g[0]},b.dataTypes[0]="json";return"script"}}),f.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/javascript|ecmascript/},converters:{"text script":function(a){f.globalEval(a);return a}}}),f.ajaxPrefilter("script",function(a){a.cache===b&&(a.cache=!1),a.crossDomain&&(a.type="GET",a.global=!1)}),f.ajaxTransport("script",function(a){if(a.crossDomain){var d,e=c.head||c.getElementsByTagName("head")[0]||c.documentElement;return{send:function(f,g){d=c.createElement("script"),d.async="async",a.scriptCharset&&(d.charset=a.scriptCharset),d.src=a.url,d.onload=d.onreadystatechange=function(a,c){if(c||!d.readyState||/loaded|complete/.test(d.readyState))d.onload=d.onreadystatechange=null,e&&d.parentNode&&e.removeChild(d),d=b,c||g(200,"success")},e.insertBefore(d,e.firstChild)},abort:function(){d&&d.onload(0,1)}}}});var cf=a.ActiveXObject?function(){for(var a in ch)ch[a](0,1)}:!1,cg=0,ch;f.ajaxSettings.xhr=a.ActiveXObject?function(){return!this.isLocal&&ci()||cj()}:ci,function(a){f.extend(f.support,{ajax:!!a,cors:!!a&&"withCredentials"in a})}(f.ajaxSettings.xhr()),f.support.ajax&&f.ajaxTransport(function(c){if(!c.crossDomain||f.support.cors){var d;return{send:function(e,g){var h=c.xhr(),i,j;c.username?h.open(c.type,c.url,c.async,c.username,c.password):h.open(c.type,c.url,c.async);if(c.xhrFields)for(j in c.xhrFields)h[j]=c.xhrFields[j];c.mimeType&&h.overrideMimeType&&h.overrideMimeType(c.mimeType),!c.crossDomain&&!e["X-Requested-With"]&&(e["X-Requested-With"]="XMLHttpRequest");try{for(j in e)h.setRequestHeader(j,e[j])}catch(k){}h.send(c.hasContent&&c.data||null),d=function(a,e){var j,k,l,m,n;try{if(d&&(e||h.readyState===4)){d=b,i&&(h.onreadystatechange=f.noop,cf&&delete ch[i]);if(e)h.readyState!==4&&h.abort();else{j=h.status,l=h.getAllResponseHeaders(),m={},n=h.responseXML,n&&n.documentElement&&(m.xml=n),m.text=h.responseText;try{k=h.statusText}catch(o){k=""}!j&&c.isLocal&&!c.crossDomain?j=m.text?200:404:j===1223&&(j=204)}}}catch(p){e||g(-1,p)}m&&g(j,k,m,l)},!c.async||h.readyState===4?d():(i=++cg,cf&&(ch||(ch={},f(a).unload(cf)),ch[i]=d),h.onreadystatechange=d)},abort:function(){d&&d(0,1)}}}});var ck={},cl,cm,cn=/^(?:toggle|show|hide)$/,co=/^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i,cp,cq=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]],cr;f.fn.extend({show:function(a,b,c){var d,e;if(a||a===0)return this.animate(cu("show",3),a,b,c);for(var g=0,h=this.length;g=i.duration+this.startTime){this.now=this.end,this.pos=this.state=1,this.update(),i.animatedProperties[this.prop]=!0;for(b in i.animatedProperties)i.animatedProperties[b]!==!0&&(g=!1);if(g){i.overflow!=null&&!f.support.shrinkWrapBlocks&&f.each(["","X","Y"],function(a,b){h.style["overflow"+b]=i.overflow[a]}),i.hide&&f(h).hide();if(i.hide||i.show)for(b in i.animatedProperties)f.style(h,b,i.orig[b]),f.removeData(h,"fxshow"+b,!0),f.removeData(h,"toggle"+b,!0);d=i.complete,d&&(i.complete=!1,d.call(h))}return!1}i.duration==Infinity?this.now=e:(c=e-this.startTime,this.state=c/i.duration,this.pos=f.easing[i.animatedProperties[this.prop]](this.state,c,0,1,i.duration),this.now=this.start+(this.end-this.start)*this.pos),this.update();return!0}},f.extend(f.fx,{tick:function(){var a,b=f.timers,c=0;for(;c-1,k={},l={},m,n;j?(l=e.position(),m=l.top,n=l.left):(m=parseFloat(h)||0,n=parseFloat(i)||0),f.isFunction(b)&&(b=b.call(a,c,g)),b.top!=null&&(k.top=b.top-g.top+m),b.left!=null&&(k.left=b.left-g.left+n),"using"in b?b.using.call(a,k):e.css(k)}},f.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),c=this.offset(),d=cx.test(b[0].nodeName)?{top:0,left:0}:b.offset();c.top-=parseFloat(f.css(a,"marginTop"))||0,c.left-=parseFloat(f.css(a,"marginLeft"))||0,d.top+=parseFloat(f.css(b[0],"borderTopWidth"))||0,d.left+=parseFloat(f.css(b[0],"borderLeftWidth"))||0;return{top:c.top-d.top,left:c.left-d.left}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||c.body;while(a&&!cx.test(a.nodeName)&&f.css(a,"position")==="static")a=a.offsetParent;return a})}}),f.each(["Left","Top"],function(a,c){var d="scroll"+c;f.fn[d]=function(c){var e,g;if(c===b){e=this[0];if(!e)return null;g=cy(e);return g?"pageXOffset"in g?g[a?"pageYOffset":"pageXOffset"]:f.support.boxModel&&g.document.documentElement[d]||g.document.body[d]:e[d]}return this.each(function(){g=cy(this),g?g.scrollTo(a?f(g).scrollLeft():c,a?c:f(g).scrollTop()):this[d]=c})}}),f.each(["Height","Width"],function(a,c){var d=c.toLowerCase();f.fn["inner"+c]=function(){var a=this[0];return a?a.style?parseFloat(f.css(a,d,"padding")):this[d]():null},f.fn["outer"+c]=function(a){var b=this[0];return b?b.style?parseFloat(f.css(b,d,a?"margin":"border")):this[d]():null},f.fn[d]=function(a){var e=this[0];if(!e)return a==null?null:this;if(f.isFunction(a))return this.each(function(b){var c=f(this);c[d](a.call(this,b,c[d]()))});if(f.isWindow(e)){var g=e.document.documentElement["client"+c],h=e.document.body;return e.document.compatMode==="CSS1Compat"&&g||h&&h["client"+c]||g}if(e.nodeType===9)return Math.max(e.documentElement["client"+c],e.body["scroll"+c],e.documentElement["scroll"+c],e.body["offset"+c],e.documentElement["offset"+c]);if(a===b){var i=f.css(e,d),j=parseFloat(i);return f.isNumeric(j)?j:i}return this.css(d,typeof a=="string"?a:a+"px")}}),a.jQuery=a.$=f,typeof define=="function"&&define.amd&&define.amd.jQuery&&define("jquery",[],function(){return f})})(window); diff --git a/server-rel.html b/server-rel.html new file mode 100644 index 00000000..eac4bf07 --- /dev/null +++ b/server-rel.html @@ -0,0 +1,821 @@ + + + + + + + + + Server Manager - not connected + + + + + + + + + + + + + + + +
+ + + + + + diff --git a/server.html b/server.html index 743cbc33..fb91ae12 100644 --- a/server.html +++ b/server.html @@ -25,7 +25,7 @@ h2 { margin: 0 0 10px 0; - background-color: #000; + background-color: #333; color: #fff; font-size: 1.2em; padding: 5px; @@ -52,13 +52,13 @@ width: 25%; } - #stream-limit-table + #stream-limit-table, #logs table { width: 100%; margin: 10px 0 20px 15px; } - #stream-limit-table th + #stream-limit-table th, #logs th, #limits-table th { text-align: left; } @@ -69,12 +69,6 @@ width: 100%; } - #limits-table th - { - text-align: left; - } - - #limits p, #protocols p { margin: 20px 0 5px 15px; @@ -170,6 +164,16 @@ margin: 10px 0 5px 15px; } + .errorlogin + { + color: #c33; + } + + .correctlogin + { + color: #393; + } + @@ -189,17 +193,17 @@ @@ -212,11 +216,11 @@

Config

Status: @@ -307,6 +311,24 @@
+
+ +

Logs

+ +
+ + + + + + + +
DateTypeMessage
+ + + + + diff --git a/tools/DTSC_Analyser/Makefile b/tools/DTSC_Analyser/Makefile new file mode 100644 index 00000000..ad834129 --- /dev/null +++ b/tools/DTSC_Analyser/Makefile @@ -0,0 +1,23 @@ +SRC = main.cpp ../../util/dtsc.cpp +OBJ = $(SRC:.cpp=.o) +OUT = DTSC_Info +INCLUDES = +DEBUG = 4 +OPTIMIZE = -g +CCFLAGS = -Wall -Wextra -funsigned-char $(OPTIMIZE) -DDEBUG=$(DEBUG) +CC = $(CROSS)g++ +LD = $(CROSS)ld +AR = $(CROSS)ar +LIBS = +.SUFFIXES: .cpp +.PHONY: clean default +default: $(OUT) +.cpp.o: + $(CC) $(INCLUDES) $(CCFLAGS) $(LIBS) -c $< -o $@ +$(OUT): $(OBJ) + $(CC) $(LIBS) -o $(OUT) $(OBJ) +clean: + rm -rf $(OBJ) $(OUT) Makefile.bak *~ +install: $(OUT) + cp -f ./$(OUT) /usr/bin/ + diff --git a/tools/DTSC_Analyser/main.cpp b/tools/DTSC_Analyser/main.cpp new file mode 100644 index 00000000..e9c5463d --- /dev/null +++ b/tools/DTSC_Analyser/main.cpp @@ -0,0 +1,38 @@ +/// \file DTSC_Analyser/main.cpp +/// Contains the code for the DTSC Analysing tool. + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "../../util/dtsc.h" //DTSC support + +/// Reads DTSC from stdin and outputs human-readable information to stderr. +int main() { + DTSC::Stream Strm; + + std::string inBuffer; + char charBuffer[1024*10]; + unsigned int charCount; + bool doneheader = false; + + while(std::cin.good()){ + //invalidate the current buffer + std::cin.read(charBuffer, 1024*10); + charCount = std::cin.gcount(); + inBuffer.append(charBuffer, charCount); + if (Strm.parsePacket(inBuffer)){ + if (!doneheader){ + doneheader = true; + Strm.metadata.Print(); + } + Strm.getPacket().Print(); + } + } + return 0; +} diff --git a/tools/FLV2DTSC/Makefile b/tools/FLV2DTSC/Makefile new file mode 100644 index 00000000..6598d44a --- /dev/null +++ b/tools/FLV2DTSC/Makefile @@ -0,0 +1,23 @@ +SRC = main.cpp ../../util/flv_tag.cpp ../../util/dtsc.cpp ../../util/amf.cpp ../../util/socket.cpp +OBJ = $(SRC:.cpp=.o) +OUT = DDV_FLV2DTSC +INCLUDES = +DEBUG = 4 +OPTIMIZE = -g +CCFLAGS = -Wall -Wextra -funsigned-char $(OPTIMIZE) -DDEBUG=$(DEBUG) +CC = $(CROSS)g++ +LD = $(CROSS)ld +AR = $(CROSS)ar +LIBS = +.SUFFIXES: .cpp +.PHONY: clean default +default: $(OUT) +.cpp.o: + $(CC) $(INCLUDES) $(CCFLAGS) $(LIBS) -c $< -o $@ +$(OUT): $(OBJ) + $(CC) $(LIBS) -o $(OUT) $(OBJ) +clean: + rm -rf $(OBJ) $(OUT) Makefile.bak *~ +install: $(OUT) + cp -f ./$(OUT) /usr/bin/ + diff --git a/tools/FLV2DTSC/main.cpp b/tools/FLV2DTSC/main.cpp new file mode 100644 index 00000000..3655432e --- /dev/null +++ b/tools/FLV2DTSC/main.cpp @@ -0,0 +1,258 @@ +/// \file FLV2DTSC/main.cpp +/// Contains the code that will transform any valid FLV input into valid DTSC. + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "../../util/flv_tag.h" //FLV support +#include "../../util/dtsc.h" //DTSC support +#include "../../util/amf.h" //AMF support + +// String onMetaData +// ECMA Array +// Bool hasVideo 1 +// Number videocodecid 4 (2 = H263, 4 = VP6, 7 = H264) +// Number width 320 +// Number height 240 +// Number framerate 23.976 (/ 1000) +// Number videodatarate 500.349 (kbps) +// Bool hasAudio 1 +// Bool stereo 1 +// Number audiodelay 0 +// Number audiosamplerate 11025 +// Number audiosamplesize 16 +// Number audiocodecid 2 (2 = MP3, 10 = AAC) +// Number audiodatarate 64.3269 (kbps) + + +/// Holds all code that converts filetypes to DTSC. +namespace Converters{ + + /// Inserts std::string type metadata into the passed DTMI object. + /// \arg meta The DTMI object to put the metadata into. + /// \arg cat Metadata category to insert into. + /// \arg elem Element name to put into the category. + /// \arg val Value to put into the element name. + void Meta_Put(DTSC::DTMI & meta, std::string cat, std::string elem, std::string val){ + if (meta.getContentP(cat) == 0){meta.addContent(DTSC::DTMI(cat));} + meta.getContentP(cat)->addContent(DTSC::DTMI(elem, val)); + std::cerr << "Metadata " << cat << "." << elem << " = " << val << std::endl; + } + + /// Inserts uint64_t type metadata into the passed DTMI object. + /// \arg meta The DTMI object to put the metadata into. + /// \arg cat Metadata category to insert into. + /// \arg elem Element name to put into the category. + /// \arg val Value to put into the element name. + void Meta_Put(DTSC::DTMI & meta, std::string cat, std::string elem, uint64_t val){ + if (meta.getContentP(cat) == 0){meta.addContent(DTSC::DTMI(cat));} + meta.getContentP(cat)->addContent(DTSC::DTMI(elem, val)); + std::cerr << "Metadata " << cat << "." << elem << " = " << val << std::endl; + } + + /// Returns true if the named category and elementname are available in the metadata. + /// \arg meta The DTMI object to check. + /// \arg cat Metadata category to check. + /// \arg elem Element name to check. + bool Meta_Has(DTSC::DTMI & meta, std::string cat, std::string elem){ + if (meta.getContentP(cat) == 0){return false;} + if (meta.getContentP(cat)->getContentP(elem) == 0){return false;} + return true; + } + + /// Reads FLV from STDIN, outputs DTSC to STDOUT. + int FLV2DTSC() { + FLV::Tag FLV_in; // Temporary storage for incoming FLV data. + AMF::Object meta_in; // Temporary storage for incoming metadata. + DTSC::DTMI meta_out; // Storage for outgoing DTMI header data. + DTSC::DTMI pack_out; // Storage for outgoing DTMI data. + std::stringstream prebuffer; // Temporary buffer before sending real data + bool sending = false; + unsigned int counter = 0; + + while (!feof(stdin)){ + if (FLV_in.FileLoader(stdin)){ + if (!sending){ + counter++; + if (counter > 10){ + sending = true; + meta_out.Pack(true); + meta_out.packed.replace(0, 4, DTSC::Magic_Header); + std::cout << meta_out.packed; + std::cout << prebuffer.rdbuf(); + prebuffer.str(""); + std::cerr << "Buffer done, starting real-time output..." << std::endl; + } + } + if (FLV_in.data[0] == 0x12){ + meta_in = AMF::parse((unsigned char*)FLV_in.data+11, FLV_in.len-15); + if (meta_in.getContentP(0) && (meta_in.getContentP(0)->StrValue() == "onMetaData") && meta_in.getContentP(1)){ + AMF::Object * tmp = meta_in.getContentP(1); + if (tmp->getContentP("videocodecid")){ + switch ((unsigned int)tmp->getContentP("videocodecid")->NumValue()){ + case 2: Meta_Put(meta_out, "video", "codec", "H263"); break; + case 4: Meta_Put(meta_out, "video", "codec", "VP6"); break; + case 7: Meta_Put(meta_out, "video", "codec", "H264"); break; + default: Meta_Put(meta_out, "video", "codec", "?"); break; + } + } + if (tmp->getContentP("audiocodecid")){ + switch ((unsigned int)tmp->getContentP("audiocodecid")->NumValue()){ + case 2: Meta_Put(meta_out, "audio", "codec", "MP3"); break; + case 10: Meta_Put(meta_out, "audio", "codec", "AAC"); break; + default: Meta_Put(meta_out, "audio", "codec", "?"); break; + } + } + if (tmp->getContentP("width")){ + Meta_Put(meta_out, "video", "width", tmp->getContentP("width")->NumValue()); + } + if (tmp->getContentP("height")){ + Meta_Put(meta_out, "video", "height", tmp->getContentP("height")->NumValue()); + } + if (tmp->getContentP("framerate")){ + Meta_Put(meta_out, "video", "fpks", tmp->getContentP("framerate")->NumValue()*1000); + } + if (tmp->getContentP("videodatarate")){ + Meta_Put(meta_out, "video", "bps", (tmp->getContentP("videodatarate")->NumValue()*1024)/8); + } + if (tmp->getContentP("audiodatarate")){ + Meta_Put(meta_out, "audio", "bps", (tmp->getContentP("audiodatarate")->NumValue()*1024)/8); + } + if (tmp->getContentP("audiosamplerate")){ + Meta_Put(meta_out, "audio", "rate", tmp->getContentP("audiosamplerate")->NumValue()); + } + if (tmp->getContentP("audiosamplesize")){ + Meta_Put(meta_out, "audio", "size", tmp->getContentP("audiosamplesize")->NumValue()); + } + if (tmp->getContentP("stereo")){ + if (tmp->getContentP("stereo")->NumValue() == 1){ + Meta_Put(meta_out, "audio", "channels", 2); + }else{ + Meta_Put(meta_out, "audio", "channels", 1); + } + } + } + } + if (FLV_in.data[0] == 0x08){ + char audiodata = FLV_in.data[11]; + if (FLV_in.needsInitData() && FLV_in.isInitData()){ + if ((audiodata & 0xF0) == 0xA0){ + Meta_Put(meta_out, "audio", "init", std::string((char*)FLV_in.data+13, (size_t)FLV_in.len-17)); + }else{ + Meta_Put(meta_out, "audio", "init", std::string((char*)FLV_in.data+12, (size_t)FLV_in.len-16)); + } + continue;//skip rest of parsing, get next tag. + } + pack_out = DTSC::DTMI("audio", DTSC::DTMI_ROOT); + pack_out.addContent(DTSC::DTMI("datatype", "audio")); + pack_out.addContent(DTSC::DTMI("time", FLV_in.tagTime())); + if (!Meta_Has(meta_out, "audio", "codec")){ + switch (audiodata & 0xF0){ + case 0x20: Meta_Put(meta_out, "audio", "codec", "MP3"); break; + case 0xA0: Meta_Put(meta_out, "audio", "codec", "AAC"); break; + default: Meta_Put(meta_out, "audio", "codec", "?"); break; + } + } + if (!Meta_Has(meta_out, "audio", "rate")){ + switch (audiodata & 0x0C){ + case 0x0: Meta_Put(meta_out, "audio", "rate", 5512); break; + case 0x4: Meta_Put(meta_out, "audio", "rate", 11025); break; + case 0x8: Meta_Put(meta_out, "audio", "rate", 22050); break; + case 0xC: Meta_Put(meta_out, "audio", "rate", 44100); break; + } + } + if (!Meta_Has(meta_out, "audio", "size")){ + switch (audiodata & 0x02){ + case 0x0: Meta_Put(meta_out, "audio", "size", 8); break; + case 0x2: Meta_Put(meta_out, "audio", "size", 16); break; + } + } + if (!Meta_Has(meta_out, "audio", "channels")){ + switch (audiodata & 0x01){ + case 0x0: Meta_Put(meta_out, "audio", "channels", 1); break; + case 0x1: Meta_Put(meta_out, "audio", "channels", 2); break; + } + } + if ((audiodata & 0xF0) == 0xA0){ + pack_out.addContent(DTSC::DTMI("data", std::string((char*)FLV_in.data+13, (size_t)FLV_in.len-17))); + }else{ + pack_out.addContent(DTSC::DTMI("data", std::string((char*)FLV_in.data+12, (size_t)FLV_in.len-16))); + } + if (sending){ + std::cout << pack_out.Pack(true); + }else{ + prebuffer << pack_out.Pack(true); + } + } + if (FLV_in.data[0] == 0x09){ + char videodata = FLV_in.data[11]; + if (FLV_in.needsInitData() && FLV_in.isInitData()){ + if ((videodata & 0x0F) == 7){ + Meta_Put(meta_out, "video", "init", std::string((char*)FLV_in.data+16, (size_t)FLV_in.len-20)); + }else{ + Meta_Put(meta_out, "video", "init", std::string((char*)FLV_in.data+12, (size_t)FLV_in.len-16)); + } + continue;//skip rest of parsing, get next tag. + } + if (!Meta_Has(meta_out, "video", "codec")){ + switch (videodata & 0x0F){ + case 2: Meta_Put(meta_out, "video", "codec", "H263"); break; + case 4: Meta_Put(meta_out, "video", "codec", "VP6"); break; + case 7: Meta_Put(meta_out, "video", "codec", "H264"); break; + default: Meta_Put(meta_out, "video", "codec", "?"); break; + } + } + pack_out = DTSC::DTMI("video", DTSC::DTMI_ROOT); + pack_out.addContent(DTSC::DTMI("datatype", "video")); + switch (videodata & 0xF0){ + case 0x10: pack_out.addContent(DTSC::DTMI("keyframe", 1)); break; + case 0x20: pack_out.addContent(DTSC::DTMI("interframe", 1)); break; + case 0x30: pack_out.addContent(DTSC::DTMI("disposableframe", 1)); break; + case 0x40: pack_out.addContent(DTSC::DTMI("keyframe", 1)); break; + case 0x50: continue; break;//the video info byte we just throw away - useless to us... + } + if ((videodata & 0x0F) == 7){ + switch (FLV_in.data[12]){ + case 1: pack_out.addContent(DTSC::DTMI("nalu", 1)); break; + case 2: pack_out.addContent(DTSC::DTMI("nalu_end", 1)); break; + } + int offset = (FLV_in.data[13] << 16) + (FLV_in.data[14] << 8) + FLV_in.data[15]; + offset = (offset << 8) >> 8; + pack_out.addContent(DTSC::DTMI("offset", offset)); + } + pack_out.addContent(DTSC::DTMI("time", FLV_in.tagTime())); + pack_out.addContent(DTSC::DTMI("data", std::string((char*)FLV_in.data+12, (size_t)FLV_in.len-16))); + if (sending){ + std::cout << pack_out.Pack(true); + }else{ + prebuffer << pack_out.Pack(true); + } + } + } + } + + // if the FLV input is very short, do output it correctly... + if (!sending){ + std::cerr << "EOF - outputting buffer..." << std::endl; + meta_out.Pack(true); + meta_out.packed.replace(0, 4, DTSC::Magic_Header); + std::cout << meta_out.packed; + std::cout << prebuffer.rdbuf(); + } + std::cerr << "Done!" << std::endl; + + return 0; + }//FLV2DTSC + +};//Buffer namespace + +/// Entry point for FLV2DTSC, simply calls Converters::FLV2DTSC(). +int main(){ + return Converters::FLV2DTSC(); +}//main diff --git a/util/dtmi.cpp b/util/dtmi.cpp deleted file mode 100644 index a9d38299..00000000 --- a/util/dtmi.cpp +++ /dev/null @@ -1,248 +0,0 @@ -/// \file dtmi.cpp -/// Holds all code for DDVTECH MediaInfo parsing/generation. - -#include "dtmi.h" -#include //needed for stderr only - -/// Returns the std::string Indice for the current object, if available. -/// Returns an empty string if no indice exists. -std::string DTSC::DTMI::Indice(){return myIndice;}; - -/// Returns the DTSC::DTMItype AMF0 object type for this object. -DTSC::DTMItype DTSC::DTMI::GetType(){return myType;}; - -/// Returns the numeric value of this object, if available. -/// If this object holds no numeric value, 0 is returned. -uint64_t DTSC::DTMI::NumValue(){return numval;}; - -/// Returns the std::string value of this object, if available. -/// If this object holds no string value, an empty string is returned. -std::string DTSC::DTMI::StrValue(){return strval;}; - -/// Returns the C-string value of this object, if available. -/// If this object holds no string value, an empty C-string is returned. -const char * DTSC::DTMI::Str(){return strval.c_str();}; - -/// Returns a count of the amount of objects this object currently holds. -/// If this object is not a container type, this function will always return 0. -int DTSC::DTMI::hasContent(){return contents.size();}; - -/// Adds an DTSC::DTMI to this object. Works for all types, but only makes sense for container types. -void DTSC::DTMI::addContent(DTSC::DTMI c){contents.push_back(c);}; - -/// Returns a pointer to the object held at indice i. -/// Returns AMF::AMF0_DDV_CONTAINER of indice "error" if no object is held at this indice. -/// \param i The indice of the object in this container. -DTSC::DTMI* DTSC::DTMI::getContentP(int i){return &contents.at(i);}; - -/// Returns a copy of the object held at indice i. -/// Returns a AMF::AMF0_DDV_CONTAINER of indice "error" if no object is held at this indice. -/// \param i The indice of the object in this container. -DTSC::DTMI DTSC::DTMI::getContent(int i){return contents.at(i);}; - -/// Returns a pointer to the object held at indice s. -/// Returns NULL if no object is held at this indice. -/// \param s The indice of the object in this container. -DTSC::DTMI* DTSC::DTMI::getContentP(std::string s){ - for (std::vector::iterator it = contents.begin(); it != contents.end(); it++){ - if (it->Indice() == s){return &(*it);} - } - return 0; -}; - -/// Returns a copy of the object held at indice s. -/// Returns a AMF::AMF0_DDV_CONTAINER of indice "error" if no object is held at this indice. -/// \param s The indice of the object in this container. -DTSC::DTMI DTSC::DTMI::getContent(std::string s){ - for (std::vector::iterator it = contents.begin(); it != contents.end(); it++){ - if (it->Indice() == s){return *it;} - } - return DTSC::DTMI("error", DTMI::DTMI_ROOT); -}; - -/// Default constructor. -/// Simply fills the data with DTSC::DTMI("error", AMF0_DDV_CONTAINER) -DTSC::DTMI::DTMI(){ - *this = DTSC::DTMI("error", DTMI::DTMI_ROOT); -};//default constructor - -/// Constructor for numeric objects. -/// The object type is by default AMF::AMF0_NUMBER, but this can be forced to a different value. -/// \param indice The string indice of this object in its container, or empty string if none. Numeric indices are automatic. -/// \param val The numeric value of this object. Numeric AMF0 objects only support double-type values. -/// \param setType The object type to force this object to. -DTSC::DTMI::DTMI(std::string indice, double val, DTSC::DTMItype setType){//num type initializer - myIndice = indice; - myType = setType; - strval = ""; - numval = val; -}; - -/// Constructor for string objects. -/// The object type is by default AMF::AMF0_STRING, but this can be forced to a different value. -/// There is no need to manually change the type to AMF::AMF0_LONGSTRING, this will be done automatically. -/// \param indice The string indice of this object in its container, or empty string if none. Numeric indices are automatic. -/// \param val The string value of this object. -/// \param setType The object type to force this object to. -DTSC::DTMI::DTMI(std::string indice, std::string val, DTSC::DTMItype setType){//str type initializer - myIndice = indice; - myType = setType; - strval = val; - numval = 0; -}; - -/// Constructor for container objects. -/// The object type is by default AMF::AMF0_OBJECT, but this can be forced to a different value. -/// \param indice The string indice of this object in its container, or empty string if none. Numeric indices are automatic. -/// \param setType The object type to force this object to. -DTSC::DTMI::DTMI(std::string indice, DTSC::DTMItype setType){//object type initializer - myIndice = indice; - myType = setType; - strval = ""; - numval = 0; -}; - -/// Prints the contents of this object to std::cerr. -/// If this object contains other objects, it will call itself recursively -/// and print all nested content in a nice human-readable format. -void DTSC::DTMI::Print(std::string indent){ - std::cerr << indent; - // print my type - switch (myType){ - case DTMItype::DTMI_INT: std::cerr << "Integer"; break; - case DTMItype::DTMI_STRING: std::cerr << "String"; break; - case DTMItype::DTMI_OBJECT: std::cerr << "Object"; break; - case DTMItype::DTMI_OBJ_END: std::cerr << "Object end"; break; - case DTMItype::DTMI_ROOT: std::cerr << "Root Node"; break; - } - // print my string indice, if available - std::cerr << " " << myIndice << " "; - // print my numeric or string contents - switch (myType){ - case DTMItype::DTMI_INT: std::cerr << numval; break; - case DTMItype::DTMI_STRING: std::cerr << strval; break; - default: break;//we don't care about the rest, and don't want a compiler warning... - } - std::cerr << std::endl; - // if I hold other objects, print those too, recursively. - if (contents.size() > 0){ - for (std::vector::iterator it = contents.begin(); it != contents.end(); it++){it->Print(indent+" ");} - } -};//print - -/// Packs the AMF object to a std::string for transfer over the network. -/// If the object is a container type, this function will call itself recursively and contain all contents. -std::string DTSC::DTMI::Pack(){ - std::string r = ""; - //skip output of DDV container types, they do not exist. Only output their contents. - if (myType != DTMItype::DTMI_ROOT){r += myType;} - //output the properly formatted data stream for this object's contents. - switch (myType){ - case DTMItype::DTMI_INT: - r += *(((char*)&numval)+7); r += *(((char*)&numval)+6); - r += *(((char*)&numval)+5); r += *(((char*)&numval)+4); - r += *(((char*)&numval)+3); r += *(((char*)&numval)+2); - r += *(((char*)&numval)+1); r += *(((char*)&numval)); - break; - case DTMItype::DTMI_STRING: - r += strval.size() / (256*256*256); - r += strval.size() / (256*256); - r += strval.size() / 256; - r += strval.size() % 256; - r += strval; - break; - case DTMItype::DTMI_OBJECT: - if (contents.size() > 0){ - for (std::vector::iterator it = contents.begin(); it != contents.end(); it++){ - r += it->Indice().size() / 256; - r += it->Indice().size() % 256; - r += it->Indice(); - r += it->Pack(); - } - } - r += (char)0; r += (char)0; r += (char)9; - break; - case DTMItype::DTMI_ROOT://only send contents - if (contents.size() > 0){ - for (std::vector::iterator it = contents.begin(); it != contents.end(); it++){ - r += it->Pack(); - } - } - break; - } - return r; -};//pack - -/// Parses a single AMF0 type - used recursively by the AMF::parse() functions. -/// This function updates i every call with the new position in the data. -/// \param data The raw data to parse. -/// \param len The size of the raw data. -/// \param i Current parsing position in the raw data. -/// \param name Indice name for any new object created. -/// \returns A single DTSC::DTMI, parsed from the raw data. -DTSC::DTMI DTSC::parseOneDTMI(const unsigned char *& data, unsigned int &len, unsigned int &i, std::string name){ - std::string tmpstr; - unsigned int tmpi = 0; - unsigned char tmpdbl[8]; - #if DEBUG >= 10 - fprintf(stderr, "Note: AMF type %hhx found. %i bytes left\n", data[i], len-i); - #endif - switch (data[i]){ - case DTMI::DTMI_INT: - tmpdbl[7] = data[i+1]; - tmpdbl[6] = data[i+2]; - tmpdbl[5] = data[i+3]; - tmpdbl[4] = data[i+4]; - tmpdbl[3] = data[i+5]; - tmpdbl[2] = data[i+6]; - tmpdbl[1] = data[i+7]; - tmpdbl[0] = data[i+8]; - i+=9;//skip 8(a double)+1 forwards - return DTSC::DTMI(name, *(uint64_t*)tmpdbl, AMF::AMF0_NUMBER); - break; - case DTMI::DTMI_STRING: - tmpi = data[i+1]*256*256*256+data[i+2]*256*256+data[i+3]*256+data[i+4];//set tmpi to UTF-8-long length - tmpstr.clear();//clean tmpstr, just to be sure - tmpstr.append((const char *)data+i+5, (size_t)tmpi);//add the string data - i += tmpi + 5;//skip length+size+1 forwards - return DTSC::DTMI(name, tmpstr, AMF::AMF0_LONGSTRING); - break; - case DTMI::DTMI_OBJECT:{ - ++i; - DTSC::DTMI ret(name, DTMI::DTMI_OBJECT); - while (data[i] + data[i+1] != 0){//while not encountering 0x0000 (we assume 0x000009) - tmpi = data[i]*256+data[i+1];//set tmpi to the UTF-8 length - tmpstr.clear();//clean tmpstr, just to be sure - tmpstr.append((const char*)data+i+2, (size_t)tmpi);//add the string data - i += tmpi + 2;//skip length+size forwards - ret.addContent(AMF::parseOne(data, len, i, tmpstr));//add content, recursively parsed, updating i, setting indice to tmpstr - } - i += 3;//skip 0x000009 - return ret; - } break; - } - #if DEBUG >= 2 - fprintf(stderr, "Error: Unimplemented DTMI type %hhx - returning.\n", data[i]); - #endif - return DTSC::DTMI("error", DTMI::DTMI_ROOT); -}//parseOne - -/// Parses a C-string to a valid DTSC::DTMI. -/// This function will find all AMF objects in the string and return -/// them all packed in a single AMF::AMF0_DDV_CONTAINER DTSC::DTMI. -DTSC::DTMI DTSC::parseDTMI(const unsigned char * data, unsigned int len){ - DTSC::DTMI ret("returned", DTMI::DTMI_ROOT);//container type - unsigned int i = 0, j = 0; - while (i < len){ - ret.addContent(AMF::parseOne(data, len, i, "")); - if (i > j){j = i;}else{return ret;} - } - return ret; -}//parse - -/// Parses a std::string to a valid DTSC::DTMI. -/// This function will find all AMF objects in the string and return -/// them all packed in a single AMF::AMF0_DDV_CONTAINER DTSC::DTMI. -DTSC::DTMI DTSC::parseDTMI(std::string data){ - return parse((const unsigned char*)data.c_str(), data.size()); -}//parse diff --git a/util/dtmi.h b/util/dtmi.h deleted file mode 100644 index 410df97d..00000000 --- a/util/dtmi.h +++ /dev/null @@ -1,58 +0,0 @@ -/// \file dtmi.h -/// Holds all headers for DDVTECH MediaInfo parsing/generation. - -#pragma once -#include -#include -//#include -#include - -/// Holds all DDVTECH Stream Container classes and parsers. -namespace DTSC{ - - /// Enumerates all possible DTMI types. - enum DTMItype { - DTMI_INT = 0x01, ///< Unsigned 64-bit integer. - DTMI_STRING = 0x02, ///< String, equivalent to the AMF longstring type. - DTMI_OBJECT = 0xE0, ///< Object, equivalent to the AMF object type. - DTMI_OBJ_END = 0xEE, ///< End of object marker. - DTMI_ROOT = 0xFF ///< Root node for all DTMI data. - }; - - /// Recursive class that holds DDVTECH MediaInfo. - class DTMI { - public: - std::string Indice(); - DTMItype GetType(); - uint64_t NumValue(); - std::string StrValue(); - const char * Str(); - int hasContent(); - void addContent(DTMI c); - DTMI* getContentP(int i); - DTMI getContent(int i); - DTMI* getContentP(std::string s); - DTMI getContent(std::string s); - DTMI(); - DTMI(std::string indice, double val, DTMItype setType = DTMI_INT); - DTMI(std::string indice, std::string val, DTMItype setType = DTMI_STRING); - DTMI(std::string indice, DTMItype setType = DTMI_OBJECT); - void Print(std::string indent = ""); - std::string Pack(); - protected: - std::string myIndice; ///< Holds this objects indice, if any. - DTMItype myType; ///< Holds this objects AMF0 type. - std::string strval; ///< Holds this objects string value, if any. - uint64_t numval; ///< Holds this objects numeric value, if any. - std::vector contents; ///< Holds this objects contents, if any (for container types). - };//AMFType - - /// Parses a C-string to a valid DTSC::DTMI. - DTMI parseDTMI(const unsigned char * data, unsigned int len); - /// Parses a std::string to a valid DTSC::DTMI. - DTMI parseDTMI(std::string data); - /// Parses a single DTMI type - used recursively by the DTSC::parseDTMI() functions. - DTMI parseOneDTMI(const unsigned char *& data, unsigned int &len, unsigned int &i, std::string name); - -};//DTSC namespace - diff --git a/util/dtsc.cpp b/util/dtsc.cpp index bc722ecf..85e1ce47 100644 --- a/util/dtsc.cpp +++ b/util/dtsc.cpp @@ -2,33 +2,51 @@ /// Holds all code for DDVTECH Stream Container parsing/generation. #include "dtsc.h" -#include "string.h" //for memcmp -#include "arpa/inet.h" //for htonl/ntohl +#include //for memcmp +#include //for htonl/ntohl +#include //for fprint, stderr -char * DTSC::Magic_Header = "DTSC"; -char * DTSC::Magic_Packet = "DTPD"; +char DTSC::Magic_Header[] = "DTSC"; +char DTSC::Magic_Packet[] = "DTPD"; +/// Initializes a DTSC::Stream with only one packet buffer. DTSC::Stream::Stream(){ datapointer = 0; + buffercount = 1; } +/// Initializes a DTSC::Stream with a minimum of rbuffers packet buffers. +/// The actual buffer count may not at all times be the requested amount. +DTSC::Stream::Stream(unsigned int rbuffers){ + datapointer = 0; + if (rbuffers < 1){rbuffers = 1;} + buffercount = rbuffers; +} + +/// Attempts to parse a packet from the given std::string buffer. +/// Returns true if successful, removing the parsed part from the buffer string. +/// Returns false if invalid or not enough data is in the buffer. +/// \arg buffer The std::string buffer to attempt to parse. bool DTSC::Stream::parsePacket(std::string & buffer){ uint32_t len; if (buffer.length() > 8){ if (memcmp(buffer.c_str(), DTSC::Magic_Header, 4) == 0){ len = ntohl(((uint32_t *)buffer.c_str())[1]); if (buffer.length() < len+8){return false;} - metadata = DTSC::parseDTMI(buffer.c_str() + 8, len); + metadata = DTSC::parseDTMI((unsigned char*)buffer.c_str() + 8, len); + buffer.erase(0, len+8); + return false; } if (memcmp(buffer.c_str(), DTSC::Magic_Packet, 4) == 0){ len = ntohl(((uint32_t *)buffer.c_str())[1]); if (buffer.length() < len+8){return false;} - lastPacket = DTSC::parseDTMI(buffer.c_str() + 8, len); + buffers.push_front(DTSC::DTMI("empty", DTMI_ROOT)); + buffers.front() = DTSC::parseDTMI((unsigned char*)buffer.c_str() + 8, len); datapointertype = INVALID; - if (lastPacket.getContentP("data")){ - datapointer = lastPacket.getContentP("data")->StrValue.c_str(); - if (lastPacket.getContentP("datatype")){ - std::string tmp = lastPacket.getContentP("datatype")->StrValue(); + if (buffers.front().getContentP("data")){ + datapointer = &(buffers.front().getContentP("data")->StrValue()); + if (buffers.front().getContentP("datatype")){ + std::string tmp = buffers.front().getContentP("datatype")->StrValue(); if (tmp == "video"){datapointertype = VIDEO;} if (tmp == "audio"){datapointertype = AUDIO;} if (tmp == "meta"){datapointertype = META;} @@ -36,23 +54,395 @@ bool DTSC::Stream::parsePacket(std::string & buffer){ }else{ datapointer = 0; } + buffer.erase(0, len+8); + while (buffers.size() > buffercount){buffers.pop_back();} + advanceRings(); + return true; } + #if DEBUG >= 2 + std::cerr << "Error: Invalid DTMI data! I *will* get stuck!" << std::endl; + #endif } return false; } -char * DTSC::Stream::lastData(){ - return datapointer; +/// Returns a direct pointer to the data attribute of the last received packet, if available. +/// Returns NULL if no valid pointer or packet is available. +std::string & DTSC::Stream::lastData(){ + return *datapointer; } +/// Returns the packed in this buffer number. +/// \arg num Buffer number. +DTSC::DTMI & DTSC::Stream::getPacket(unsigned int num){ + return buffers[num]; +} + +/// Returns the type of the last received packet. DTSC::datatype DTSC::Stream::lastType(){ return datapointertype; } +/// Returns true if the current stream contains at least one video track. bool DTSC::Stream::hasVideo(){ return (metadata.getContentP("video") != 0); } +/// Returns true if the current stream contains at least one audio track. bool DTSC::Stream::hasAudio(){ return (metadata.getContentP("audio") != 0); } + +/// Returns a packed DTSC packet, ready to sent over the network. +std::string & DTSC::Stream::outPacket(unsigned int num){ + buffers[num].Pack(true); + return buffers[num].packed; +} + +/// Returns a packed DTSC header, ready to sent over the network. +std::string & DTSC::Stream::outHeader(){ + if ((metadata.packed.length() < 4) || !metadata.netpacked){ + metadata.Pack(true); + metadata.packed.replace(0, 4, Magic_Header); + } + return metadata.packed; +} + +/// advances all given out and internal Ring classes to point to the new buffer, after one has been added. +/// Also updates the internal keyframes ring, as well as marking rings as starved if they are. +/// Unsets waiting rings, updating them with their new buffer number. +void DTSC::Stream::advanceRings(){ + std::deque::iterator dit; + std::set::iterator sit; + for (sit = rings.begin(); sit != rings.end(); sit++){ + (*sit)->b++; + if ((*sit)->waiting){(*sit)->waiting = false; (*sit)->b = 0;} + if ((*sit)->starved || ((*sit)->b >= buffers.size())){(*sit)->starved = true; (*sit)->b = 0;} + } + for (dit = keyframes.begin(); dit != keyframes.end(); dit++){ + dit->b++; + if (dit->b >= buffers.size()){keyframes.erase(dit); break;} + } + if ((lastType() == VIDEO) && (buffers.front().getContentP("keyframe"))){ + keyframes.push_front(DTSC::Ring(0)); + } + //increase buffer size if no keyframes available + if ((buffercount > 1) && (keyframes.size() < 1)){buffercount++;} +} + +/// Constructs a new Ring, at the given buffer position. +/// \arg v Position for buffer. +DTSC::Ring::Ring(unsigned int v){ + b = v; + waiting = false; + starved = false; +} + +/// Requests a new Ring, which will be created and added to the internal Ring list. +/// This Ring will be kept updated so it always points to valid data or has the starved boolean set. +/// Don't forget to call dropRing() for all requested Ring classes that are no longer neccessary! +DTSC::Ring * DTSC::Stream::getRing(){ + DTSC::Ring * tmp; + if (keyframes.size() == 0){ + tmp = new DTSC::Ring(0); + }else{ + tmp = new DTSC::Ring(keyframes[0].b); + } + rings.insert(tmp); + return tmp; +} + +/// Deletes a given out Ring class from memory and internal Ring list. +/// Checks for NULL pointers and invalid pointers, silently discarding them. +void DTSC::Stream::dropRing(DTSC::Ring * ptr){ + if (rings.find(ptr) != rings.end()){ + rings.erase(ptr); + delete ptr; + } +} + +/// Properly cleans up the object for erasing. +/// Drops all Ring classes that have been given out. +DTSC::Stream::~Stream(){ + std::set::iterator sit; + for (sit = rings.begin(); sit != rings.end(); sit++){delete (*sit);} +} + +/// Returns the std::string Indice for the current object, if available. +/// Returns an empty string if no indice exists. +std::string DTSC::DTMI::Indice(){return myIndice;}; + +/// Returns the DTSC::DTMItype AMF0 object type for this object. +DTSC::DTMItype DTSC::DTMI::GetType(){return myType;}; + +/// Returns the numeric value of this object, if available. +/// If this object holds no numeric value, 0 is returned. +uint64_t & DTSC::DTMI::NumValue(){return numval;}; + +/// Returns the std::string value of this object, if available. +/// If this object holds no string value, an empty string is returned. +std::string & DTSC::DTMI::StrValue(){return strval;}; + +/// Returns the C-string value of this object, if available. +/// If this object holds no string value, an empty C-string is returned. +const char * DTSC::DTMI::Str(){return strval.c_str();}; + +/// Returns a count of the amount of objects this object currently holds. +/// If this object is not a container type, this function will always return 0. +int DTSC::DTMI::hasContent(){return contents.size();}; + +/// Adds an DTSC::DTMI to this object. Works for all types, but only makes sense for container types. +/// This function resets DTMI::packed to an empty string, forcing a repack on the next call to DTMI::Pack. +/// If the indice name already exists, replaces the indice. +void DTSC::DTMI::addContent(DTSC::DTMI c){ + std::vector::iterator it; + for (it = contents.begin(); it != contents.end(); it++){ + if (it->Indice() == c.Indice()){ + contents.erase(it); + break; + } + } + contents.push_back(c); packed = ""; +}; + +/// Returns a pointer to the object held at indice i. +/// Returns AMF::AMF0_DDV_CONTAINER of indice "error" if no object is held at this indice. +/// \param i The indice of the object in this container. +DTSC::DTMI* DTSC::DTMI::getContentP(int i){return &contents.at(i);}; + +/// Returns a copy of the object held at indice i. +/// Returns a AMF::AMF0_DDV_CONTAINER of indice "error" if no object is held at this indice. +/// \param i The indice of the object in this container. +DTSC::DTMI DTSC::DTMI::getContent(int i){return contents.at(i);}; + +/// Returns a pointer to the object held at indice s. +/// Returns NULL if no object is held at this indice. +/// \param s The indice of the object in this container. +DTSC::DTMI* DTSC::DTMI::getContentP(std::string s){ + for (std::vector::iterator it = contents.begin(); it != contents.end(); it++){ + if (it->Indice() == s){return &(*it);} + } + return 0; +}; + +/// Returns a copy of the object held at indice s. +/// Returns a AMF::AMF0_DDV_CONTAINER of indice "error" if no object is held at this indice. +/// \param s The indice of the object in this container. +DTSC::DTMI DTSC::DTMI::getContent(std::string s){ + for (std::vector::iterator it = contents.begin(); it != contents.end(); it++){ + if (it->Indice() == s){return *it;} + } + return DTSC::DTMI("error", DTMI_ROOT); +}; + +/// Default constructor. +/// Simply fills the data with DTSC::DTMI("error", AMF0_DDV_CONTAINER) +DTSC::DTMI::DTMI(){ + *this = DTSC::DTMI("error", DTMI_ROOT); +};//default constructor + +/// Constructor for numeric objects. +/// The object type is by default DTMItype::DTMI_INT, but this can be forced to a different value. +/// \param indice The string indice of this object in its container, or empty string if none. Numeric indices are automatic. +/// \param val The numeric value of this object. Numeric objects only support uint64_t values. +/// \param setType The object type to force this object to. +DTSC::DTMI::DTMI(std::string indice, uint64_t val, DTSC::DTMItype setType){//num type initializer + myIndice = indice; + myType = setType; + strval = ""; + numval = val; +}; + +/// Constructor for string objects. +/// \param indice The string indice of this object in its container, or empty string if none. Numeric indices are automatic. +/// \param val The string value of this object. +/// \param setType The object type to force this object to. +DTSC::DTMI::DTMI(std::string indice, std::string val, DTSC::DTMItype setType){//str type initializer + myIndice = indice; + myType = setType; + strval = val; + numval = 0; +}; + +/// Constructor for container objects. +/// \param indice The string indice of this object in its container, or empty string if none. +/// \param setType The object type to force this object to. +DTSC::DTMI::DTMI(std::string indice, DTSC::DTMItype setType){//object type initializer + myIndice = indice; + myType = setType; + strval = ""; + numval = 0; +}; + +/// Prints the contents of this object to std::cerr. +/// If this object contains other objects, it will call itself recursively +/// and print all nested content in a nice human-readable format. +void DTSC::DTMI::Print(std::string indent){ + std::cerr << indent; + // print my type + switch (myType){ + case DTMI_INT: std::cerr << "Integer"; break; + case DTMI_STRING: std::cerr << "String"; break; + case DTMI_OBJECT: std::cerr << "Object"; break; + case DTMI_OBJ_END: std::cerr << "Object end"; break; + case DTMI_ROOT: std::cerr << "Root Node"; break; + } + // print my string indice, if available + std::cerr << " " << myIndice << " "; + // print my numeric or string contents + switch (myType){ + case DTMI_INT: std::cerr << numval; break; + case DTMI_STRING: + if (strval.length() > 200 || ((strval.length() > 1) && ( (strval[0] < 'A') || (strval[0] > 'z') ) )){ + std::cerr << strval.length() << " bytes of data"; + }else{ + std::cerr << strval; + } + break; + default: break;//we don't care about the rest, and don't want a compiler warning... + } + std::cerr << std::endl; + // if I hold other objects, print those too, recursively. + if (contents.size() > 0){ + for (std::vector::iterator it = contents.begin(); it != contents.end(); it++){it->Print(indent+" ");} + } +};//print + +/// Packs the DTMI to a std::string for transfer over the network. +/// If a packed version already exists, does not regenerate it. +/// If the object is a container type, this function will call itself recursively and contain all contents. +/// \arg netpack If true, will pack as a full DTMI packet, if false only as the contents without header. +std::string DTSC::DTMI::Pack(bool netpack){ + if (packed != ""){ + if (netpacked == netpack){return packed;} + if (netpacked){ + packed.erase(0, 8); + }else{ + unsigned int size = htonl(packed.length()); + packed.insert(0, (char*)&size, 4); + packed.insert(0, Magic_Packet); + } + netpacked = !netpacked; + return packed; + } + std::string r = ""; + r += myType; + //output the properly formatted data stream for this object's contents. + switch (myType){ + case DTMI_INT: + r += *(((char*)&numval)+7); r += *(((char*)&numval)+6); + r += *(((char*)&numval)+5); r += *(((char*)&numval)+4); + r += *(((char*)&numval)+3); r += *(((char*)&numval)+2); + r += *(((char*)&numval)+1); r += *(((char*)&numval)); + break; + case DTMI_STRING: + r += strval.size() / (256*256*256); + r += strval.size() / (256*256); + r += strval.size() / 256; + r += strval.size() % 256; + r += strval; + break; + case DTMI_OBJECT: + case DTMI_ROOT: + if (contents.size() > 0){ + for (std::vector::iterator it = contents.begin(); it != contents.end(); it++){ + r += it->Indice().size() / 256; + r += it->Indice().size() % 256; + r += it->Indice(); + r += it->Pack(); + } + } + r += (char)0x0; r += (char)0x0; r += (char)0xEE; + break; + case DTMI_OBJ_END: + break; + } + packed = r; + netpacked = netpack; + if (netpacked){ + unsigned int size = htonl(packed.length()); + packed.insert(0, (char*)&size, 4); + packed.insert(0, Magic_Packet); + } + return packed; +};//pack + +/// Parses a single AMF0 type - used recursively by the AMF::parse() functions. +/// This function updates i every call with the new position in the data. +/// \param data The raw data to parse. +/// \param len The size of the raw data. +/// \param i Current parsing position in the raw data. +/// \param name Indice name for any new object created. +/// \returns A single DTSC::DTMI, parsed from the raw data. +DTSC::DTMI DTSC::parseOneDTMI(const unsigned char *& data, unsigned int &len, unsigned int &i, std::string name){ + unsigned int tmpi = 0; + unsigned char tmpdbl[8]; + #if DEBUG >= 10 + fprintf(stderr, "Note: AMF type %hhx found. %i bytes left\n", data[i], len-i); + #endif + switch (data[i]){ + case DTMI_INT: + tmpdbl[7] = data[i+1]; + tmpdbl[6] = data[i+2]; + tmpdbl[5] = data[i+3]; + tmpdbl[4] = data[i+4]; + tmpdbl[3] = data[i+5]; + tmpdbl[2] = data[i+6]; + tmpdbl[1] = data[i+7]; + tmpdbl[0] = data[i+8]; + i+=9;//skip 8(an uint64_t)+1 forwards + return DTSC::DTMI(name, *(uint64_t*)tmpdbl, DTMI_INT); + break; + case DTMI_STRING:{ + tmpi = data[i+1]*256*256*256+data[i+2]*256*256+data[i+3]*256+data[i+4];//set tmpi to UTF-8-long length + std::string tmpstr = std::string((const char *)data+i+5, (size_t)tmpi);//set the string data + i += tmpi + 5;//skip length+size+1 forwards + return DTSC::DTMI(name, tmpstr, DTMI_STRING); + } break; + case DTMI_ROOT:{ + ++i; + DTSC::DTMI ret(name, DTMI_ROOT); + while (data[i] + data[i+1] != 0){//while not encountering 0x0000 (we assume 0x0000EE) + tmpi = data[i]*256+data[i+1];//set tmpi to the UTF-8 length + std::string tmpstr = std::string((const char *)data+i+2, (size_t)tmpi);//set the string data + i += tmpi + 2;//skip length+size forwards + ret.addContent(parseOneDTMI(data, len, i, tmpstr));//add content, recursively parsed, updating i, setting indice to tmpstr + } + i += 3;//skip 0x0000EE + return ret; + } break; + case DTMI_OBJECT:{ + ++i; + DTSC::DTMI ret(name, DTMI_OBJECT); + while (data[i] + data[i+1] != 0){//while not encountering 0x0000 (we assume 0x0000EE) + tmpi = data[i]*256+data[i+1];//set tmpi to the UTF-8 length + std::string tmpstr = std::string((const char *)data+i+2, (size_t)tmpi);//set the string data + i += tmpi + 2;//skip length+size forwards + ret.addContent(parseOneDTMI(data, len, i, tmpstr));//add content, recursively parsed, updating i, setting indice to tmpstr + } + i += 3;//skip 0x0000EE + return ret; + } break; + } + #if DEBUG >= 2 + fprintf(stderr, "Error: Unimplemented DTMI type %hhx - returning.\n", data[i]); + #endif + return DTSC::DTMI("error", DTMI_ROOT); +}//parseOne + +/// Parses a C-string to a valid DTSC::DTMI. +/// This function will find one DTMI object in the string and return it. +DTSC::DTMI DTSC::parseDTMI(const unsigned char * data, unsigned int len){ + DTSC::DTMI ret;//container type + unsigned int i = 0; + ret = parseOneDTMI(data, len, i, ""); + ret.packed = std::string((char*)data, (size_t)len); + ret.netpacked = false; + return ret; +}//parse + +/// Parses a std::string to a valid DTSC::DTMI. +/// This function will find one DTMI object in the string and return it. +DTSC::DTMI DTSC::parseDTMI(std::string data){ + return parseDTMI((const unsigned char*)data.c_str(), data.size()); +}//parse diff --git a/util/dtsc.h b/util/dtsc.h index 6b918f30..3d690d53 100644 --- a/util/dtsc.h +++ b/util/dtsc.h @@ -2,46 +2,141 @@ /// Holds all headers for DDVTECH Stream Container parsing/generation. #pragma once -#include "dtmi.h" +#include +#include +#include //for uint64_t +#include +#include +#include -// Video: -// Codec (string) -// Audio: -// Codec (string) -// Samping rate (int, Hz) -// Sample Size (int, bytesize) -// Channels (int, channelcount) +/// Holds all DDVTECH Stream Container classes and parsers. +///Video: +/// - codec (string: H264, H263, VP6) +/// - width (int, pixels) +/// - height (int, pixels) +/// - fpks (int, frames per kilosecond (FPS * 1000)) +/// - bps (int, bytes per second) +/// - init (string, init data) +/// +///Audio: +/// - codec (string: AAC, MP3) +/// - rate (int, Hz) +/// - size (int, bitsize) +/// - bps (int, bytes per second) +/// - channels (int, channelcount) +/// - init (string, init data) +/// +///All packets: +/// - datatype (string: audio, video, meta (unused)) +/// - data (string: data) +/// - time (int: ms into video) +/// +///Video packets: +/// - keyframe (int, if set, is a seekable keyframe) +/// - interframe (int, if set, is a non-seekable interframe) +/// - disposableframe (int, if set, is a disposable interframe) +/// +///H264 video packets: +/// - nalu (int, if set, is a nalu) +/// - nalu_end (int, if set, is a end-of-sequence) +/// - offset (int, unsigned version of signed int! Holds the ms offset between timestamp and proper display time for B-frames) namespace DTSC{ + /// Enumerates all possible DTMI types. + enum DTMItype { + DTMI_INT = 0x01, ///< Unsigned 64-bit integer. + DTMI_STRING = 0x02, ///< String, equivalent to the AMF longstring type. + DTMI_OBJECT = 0xE0, ///< Object, equivalent to the AMF object type. + DTMI_OBJ_END = 0xEE, ///< End of object marker. + DTMI_ROOT = 0xFF ///< Root node for all DTMI data. + }; + + /// Recursive class that holds DDVTECH MediaInfo. + class DTMI { + public: + std::string Indice(); + DTMItype GetType(); + uint64_t & NumValue(); + std::string & StrValue(); + const char * Str(); + int hasContent(); + void addContent(DTMI c); + DTMI* getContentP(int i); + DTMI getContent(int i); + DTMI* getContentP(std::string s); + DTMI getContent(std::string s); + DTMI(); + DTMI(std::string indice, uint64_t val, DTMItype setType = DTMI_INT); + DTMI(std::string indice, std::string val, DTMItype setType = DTMI_STRING); + DTMI(std::string indice, DTMItype setType = DTMI_OBJECT); + void Print(std::string indent = ""); + std::string Pack(bool netpack = false); + bool netpacked; + std::string packed; + protected: + std::string myIndice; ///< Holds this objects indice, if any. + DTMItype myType; ///< Holds this objects AMF0 type. + std::string strval; ///< Holds this objects string value, if any. + uint64_t numval; ///< Holds this objects numeric value, if any. + std::vector contents; ///< Holds this objects contents, if any (for container types). + };//AMFType + + /// Parses a C-string to a valid DTSC::DTMI. + DTMI parseDTMI(const unsigned char * data, unsigned int len); + /// Parses a std::string to a valid DTSC::DTMI. + DTMI parseDTMI(std::string data); + /// Parses a single DTMI type - used recursively by the DTSC::parseDTMI() functions. + DTMI parseOneDTMI(const unsigned char *& data, unsigned int &len, unsigned int &i, std::string name); + /// This enum holds all possible datatypes for DTSC packets. enum datatype { AUDIO, ///< Stream Audio data VIDEO, ///< Stream Video data META, ///< Stream Metadata INVALID ///< Anything else or no data available. - } + }; - char * Magic_Header; ///< The magic bytes for a DTSC header - char * Magic_Packet; ///< The magic bytes for a DTSC packet + extern char Magic_Header[]; ///< The magic bytes for a DTSC header + extern char Magic_Packet[]; ///< The magic bytes for a DTSC packet - /// Holds temporary data for a DTSC stream and provides functions to access/store it. + /// A part from the DTSC::Stream ringbuffer. + /// Holds information about a buffer that will stay consistent + class Ring { + public: + Ring(unsigned int v); + unsigned int b; ///< Holds current number of buffer. May and is intended to change unexpectedly! + bool waiting; ///< If true, this Ring is currently waiting for a buffer fill. + bool starved; ///< If true, this Ring can no longer receive valid data. + }; + + /// Holds temporary data for a DTSC stream and provides functions to utilize it. + /// Optionally also acts as a ring buffer of a certain requested size. + /// If ring buffering mode is enabled, it will automatically grow in size to always contain at least one keyframe. class Stream { public: Stream(); + ~Stream(); + Stream(unsigned int buffers); DTSC::DTMI metadata; - DRSC::DTMI lastPacket; + DTSC::DTMI & getPacket(unsigned int num = 0); datatype lastType(); - char * lastData(); + std::string & lastData(); bool hasVideo(); bool hasAudio(); bool parsePacket(std::string & buffer); - private: - char * datapointer; + std::string & outPacket(unsigned int num); + std::string & outHeader(); + Ring * getRing(); + void dropRing(Ring * ptr); + private: + std::deque buffers; + std::set rings; + std::deque keyframes; + void advanceRings(); + std::string * datapointer; datatype datapointertype; - } - - - + unsigned int buffercount; + }; }; diff --git a/util/flv_tag.cpp b/util/flv_tag.cpp index 427b2243..cf75e549 100644 --- a/util/flv_tag.cpp +++ b/util/flv_tag.cpp @@ -2,6 +2,7 @@ /// Holds all code for the FLV namespace. #include "flv_tag.h" +#include "amf.h" #include "rtmpchunks.h" #include //for Tag::FileLoader #include //for Tag::FileLoader @@ -109,7 +110,7 @@ std::string FLV::Tag::tagType(){ case 4: R += "VP6"; break; case 5: R += "VP6Alpha"; break; case 6: R += "ScreenVideo2"; break; - case 7: R += "AVC"; break; + case 7: R += "H264"; break; default: R += "unknown"; break; } R += " video "; @@ -245,6 +246,265 @@ FLV::Tag & FLV::Tag::operator= (const FLV::Tag& O){ return *this; }//assignment operator +/// FLV loader function from DTSC. +/// Takes the DTSC data and makes it into FLV. +bool FLV::Tag::DTSCLoader(DTSC::Stream & S){ + switch (S.lastType()){ + case DTSC::VIDEO: + len = S.lastData().length() + 16; + if (S.metadata.getContentP("video") && S.metadata.getContentP("video")->getContentP("codec")){ + if (S.metadata.getContentP("video")->getContentP("codec")->StrValue() == "H264"){len += 4;} + } + break; + case DTSC::AUDIO: + len = S.lastData().length() + 16; + if (S.metadata.getContentP("audio") && S.metadata.getContentP("audio")->getContentP("codec")){ + if (S.metadata.getContentP("audio")->getContentP("codec")->StrValue() == "AAC"){len += 1;} + } + break; + case DTSC::META: + len = S.lastData().length() + 15; + break; + default://ignore all other types (there are currently no other types...) + break; + } + if (len > 0){ + if (!data){ + data = (char*)malloc(len); + buf = len; + }else{ + if (buf < len){ + data = (char*)realloc(data, len); + buf = len; + } + } + switch (S.lastType()){ + case DTSC::VIDEO: + if ((unsigned int)len == S.lastData().length() + 16){ + memcpy(data+12, S.lastData().c_str(), S.lastData().length()); + }else{ + memcpy(data+16, S.lastData().c_str(), S.lastData().length()); + if (S.getPacket().getContentP("nalu")){data[12] = 1;}else{data[12] = 2;} + int offset = S.getPacket().getContentP("offset")->NumValue(); + data[13] = (offset >> 16) & 0xFF; + data[14] = (offset >> 8) & 0XFF; + data[15] = offset & 0xFF; + } + data[11] = 0; + if (S.metadata.getContentP("video")->getContentP("codec")->StrValue() == "H264"){data[11] += 7;} + if (S.metadata.getContentP("video")->getContentP("codec")->StrValue() == "H263"){data[11] += 2;} + if (S.getPacket().getContentP("keyframe")){data[11] += 0x10;} + if (S.getPacket().getContentP("interframe")){data[11] += 0x20;} + if (S.getPacket().getContentP("disposableframe")){data[11] += 0x30;} + break; + case DTSC::AUDIO: + if ((unsigned int)len == S.lastData().length() + 16){ + memcpy(data+12, S.lastData().c_str(), S.lastData().length()); + }else{ + memcpy(data+13, S.lastData().c_str(), S.lastData().length()); + data[12] = 1;//raw AAC data, not sequence header + } + data[11] = 0; + if (S.metadata.getContentP("audio")->getContentP("codec")->StrValue() == "AAC"){data[11] += 0xA0;} + if (S.metadata.getContentP("audio")->getContentP("codec")->StrValue() == "MP3"){data[11] += 0x20;} + if (S.metadata.getContentP("audio")->getContentP("rate")->NumValue() == 11025){data[11] += 0x04;} + if (S.metadata.getContentP("audio")->getContentP("rate")->NumValue() == 22050){data[11] += 0x08;} + if (S.metadata.getContentP("audio")->getContentP("rate")->NumValue() == 44100){data[11] += 0x0C;} + if (S.metadata.getContentP("audio")->getContentP("size")->NumValue() == 16){data[11] += 0x02;} + if (S.metadata.getContentP("audio")->getContentP("channels")->NumValue() > 1){data[11] += 0x01;} + break; + case DTSC::META: + memcpy(data+11, S.lastData().c_str(), S.lastData().length()); + break; + default: break; + } + } + setLen(); + switch (S.lastType()){ + case DTSC::VIDEO: data[0] = 0x09; break; + case DTSC::AUDIO: data[0] = 0x08; break; + case DTSC::META: data[0] = 0x12; break; + default: break; + } + data[1] = ((len-15) >> 16) & 0xFF; + data[2] = ((len-15) >> 8) & 0xFF; + data[3] = (len-15) & 0xFF; + tagTime(S.getPacket().getContentP("time")->NumValue()); + return true; +} + +/// Helper function that properly sets the tag length from the internal len variable. +void FLV::Tag::setLen(){ + int len4 = len - 4; + int i = len-1; + data[--i] = (len4) & 0xFF; + len4 >>= 8; + data[--i] = (len4) & 0xFF; + len4 >>= 8; + data[--i] = (len4) & 0xFF; + len4 >>= 8; + data[--i] = (len4) & 0xFF; +} + +/// FLV Video init data loader function from DTSC. +/// Takes the DTSC Video init data and makes it into FLV. +/// Assumes init data is available - so check before calling! +bool FLV::Tag::DTSCVideoInit(DTSC::Stream & S){ + if (S.metadata.getContentP("video")->getContentP("codec")->StrValue() == "H264"){ + len = S.metadata.getContentP("video")->getContentP("init")->StrValue().length() + 20; + } + if (len > 0){ + if (!data){ + data = (char*)malloc(len); + buf = len; + }else{ + if (buf < len){ + data = (char*)realloc(data, len); + buf = len; + } + } + memcpy(data+16, S.metadata.getContentP("video")->getContentP("init")->StrValue().c_str(), len-20); + data[12] = 0;//H264 sequence header + data[13] = 0; + data[14] = 0; + data[15] = 0; + data[11] = 0x17;//H264 keyframe (0x07 & 0x10) + } + setLen(); + data[0] = 0x09; + data[1] = ((len-15) >> 16) & 0xFF; + data[2] = ((len-15) >> 8) & 0xFF; + data[3] = (len-15) & 0xFF; + tagTime(0); + return true; +} + +/// FLV Audio init data loader function from DTSC. +/// Takes the DTSC Audio init data and makes it into FLV. +/// Assumes init data is available - so check before calling! +bool FLV::Tag::DTSCAudioInit(DTSC::Stream & S){ + len = 0; + if (S.metadata.getContentP("audio")->getContentP("codec")->StrValue() == "AAC"){ + len = S.metadata.getContentP("audio")->getContentP("init")->StrValue().length() + 17; + } + if (len > 0){ + if (!data){ + data = (char*)malloc(len); + buf = len; + }else{ + if (buf < len){ + data = (char*)realloc(data, len); + buf = len; + } + } + memcpy(data+13, S.metadata.getContentP("audio")->getContentP("init")->StrValue().c_str(), len-17); + data[12] = 0;//AAC sequence header + data[11] = 0; + if (S.metadata.getContentP("audio")->getContentP("codec")->StrValue() == "AAC"){data[11] += 0xA0;} + if (S.metadata.getContentP("audio")->getContentP("codec")->StrValue() == "MP3"){data[11] += 0x20;} + if (S.metadata.getContentP("audio")->getContentP("rate")->NumValue() == 11000){data[11] += 0x04;} + if (S.metadata.getContentP("audio")->getContentP("rate")->NumValue() == 22000){data[11] += 0x08;} + if (S.metadata.getContentP("audio")->getContentP("rate")->NumValue() == 44000){data[11] += 0x0C;} + if (S.metadata.getContentP("audio")->getContentP("size")->NumValue() == 16){data[11] += 0x02;} + if (S.metadata.getContentP("audio")->getContentP("channels")->NumValue() > 1){data[11] += 0x01;} + } + setLen(); + switch (S.lastType()){ + case DTSC::VIDEO: data[0] = 0x09; break; + case DTSC::AUDIO: data[0] = 0x08; break; + case DTSC::META: data[0] = 0x12; break; + default: break; + } + data[0] = 0x08; + data[1] = ((len-15) >> 16) & 0xFF; + data[2] = ((len-15) >> 8) & 0xFF; + data[3] = (len-15) & 0xFF; + tagTime(0); + return true; +} + +/// FLV metadata loader function from DTSC. +/// Takes the DTSC metadata and makes it into FLV. +/// Assumes metadata is available - so check before calling! +bool FLV::Tag::DTSCMetaInit(DTSC::Stream & S){ + AMF::Object amfdata("root", AMF::AMF0_DDV_CONTAINER); + + amfdata.addContent(AMF::Object("", "onMetaData")); + amfdata.addContent(AMF::Object("", AMF::AMF0_ECMA_ARRAY)); + if (S.metadata.getContentP("video")){ + amfdata.getContentP(1)->addContent(AMF::Object("hasVideo", 1, AMF::AMF0_BOOL)); + if (S.metadata.getContentP("video")->getContentP("codec")->StrValue() == "H264"){ + amfdata.getContentP(1)->addContent(AMF::Object("videocodecid", 7, AMF::AMF0_NUMBER)); + } + if (S.metadata.getContentP("video")->getContentP("codec")->StrValue() == "VP6"){ + amfdata.getContentP(1)->addContent(AMF::Object("videocodecid", 4, AMF::AMF0_NUMBER)); + } + if (S.metadata.getContentP("video")->getContentP("codec")->StrValue() == "H263"){ + amfdata.getContentP(1)->addContent(AMF::Object("videocodecid", 2, AMF::AMF0_NUMBER)); + } + if (S.metadata.getContentP("video")->getContentP("width")){ + amfdata.getContentP(1)->addContent(AMF::Object("width", S.metadata.getContentP("video")->getContentP("width")->NumValue(), AMF::AMF0_NUMBER)); + } + if (S.metadata.getContentP("video")->getContentP("height")){ + amfdata.getContentP(1)->addContent(AMF::Object("height", S.metadata.getContentP("video")->getContentP("height")->NumValue(), AMF::AMF0_NUMBER)); + } + if (S.metadata.getContentP("video")->getContentP("fpks")){ + amfdata.getContentP(1)->addContent(AMF::Object("framerate", (double)S.metadata.getContentP("video")->getContentP("fpks")->NumValue() / 1000.0, AMF::AMF0_NUMBER)); + } + if (S.metadata.getContentP("video")->getContentP("bps")){ + amfdata.getContentP(1)->addContent(AMF::Object("videodatarate", ((double)S.metadata.getContentP("video")->getContentP("bps")->NumValue() * 8.0) / 1024.0, AMF::AMF0_NUMBER)); + } + } + if (S.metadata.getContentP("audio")){ + amfdata.getContentP(1)->addContent(AMF::Object("hasAudio", 1, AMF::AMF0_BOOL)); + amfdata.getContentP(1)->addContent(AMF::Object("audiodelay", 0, AMF::AMF0_NUMBER)); + if (S.metadata.getContentP("audio")->getContentP("codec")->StrValue() == "AAC"){ + amfdata.getContentP(1)->addContent(AMF::Object("audiocodecid", 10, AMF::AMF0_NUMBER)); + } + if (S.metadata.getContentP("audio")->getContentP("codec")->StrValue() == "MP3"){ + amfdata.getContentP(1)->addContent(AMF::Object("audiocodecid", 2, AMF::AMF0_NUMBER)); + } + if (S.metadata.getContentP("audio")->getContentP("channels")){ + if (S.metadata.getContentP("audio")->getContentP("channels")->NumValue() > 1){ + amfdata.getContentP(1)->addContent(AMF::Object("stereo", 1, AMF::AMF0_BOOL)); + }else{ + amfdata.getContentP(1)->addContent(AMF::Object("stereo", 0, AMF::AMF0_BOOL)); + } + } + if (S.metadata.getContentP("audio")->getContentP("rate")){ + amfdata.getContentP(1)->addContent(AMF::Object("audiosamplerate", S.metadata.getContentP("audio")->getContentP("rate")->NumValue(), AMF::AMF0_NUMBER)); + } + if (S.metadata.getContentP("audio")->getContentP("size")){ + amfdata.getContentP(1)->addContent(AMF::Object("audiosamplesize", S.metadata.getContentP("audio")->getContentP("size")->NumValue(), AMF::AMF0_NUMBER)); + } + if (S.metadata.getContentP("audio")->getContentP("bps")){ + amfdata.getContentP(1)->addContent(AMF::Object("audiodatarate", ((double)S.metadata.getContentP("audio")->getContentP("bps")->NumValue() * 8.0) / 1024.0, AMF::AMF0_NUMBER)); + } + } + + std::string tmp = amfdata.Pack(); + len = tmp.length() + 15; + if (len > 0){ + if (!data){ + data = (char*)malloc(len); + buf = len; + }else{ + if (buf < len){ + data = (char*)realloc(data, len); + buf = len; + } + } + memcpy(data+11, tmp.c_str(), len-15); + } + setLen(); + data[0] = 0x12; + data[1] = ((len-15) >> 16) & 0xFF; + data[2] = ((len-15) >> 8) & 0xFF; + data[3] = (len-15) & 0xFF; + tagTime(0); + return true; +} + /// FLV loader function from chunk. /// Copies the contents and wraps it in a FLV header. bool FLV::Tag::ChunkLoader(const RTMPStream::Chunk& O){ @@ -261,7 +521,7 @@ bool FLV::Tag::ChunkLoader(const RTMPStream::Chunk& O){ } memcpy(data+11, &(O.data[0]), O.len); } - ((unsigned int *)(data+len-4))[0] = O.len; + setLen(); data[0] = O.msg_type_id; data[3] = O.len & 0xFF; data[2] = (O.len >> 8) & 0xFF; diff --git a/util/flv_tag.h b/util/flv_tag.h index 1350c870..6f1f7da7 100644 --- a/util/flv_tag.h +++ b/util/flv_tag.h @@ -3,6 +3,7 @@ #pragma once #include "socket.h" +#include "dtsc.h" #include //forward declaration of RTMPStream::Chunk to avoid circular dependencies. @@ -38,6 +39,10 @@ namespace FLV { Tag(const RTMPStream::Chunk& O); ///