bool Init(CTSTR lpFile) { strFile = lpFile; initialTimestamp = -1; if(!fileOut.Open(lpFile, XFILE_CREATEALWAYS, 1024*1024)) return false; fileOut.OutputByte('F'); fileOut.OutputByte('L'); fileOut.OutputByte('V'); fileOut.OutputByte(1); fileOut.OutputByte(5); //bit 0 = (hasAudio), bit 2 = (hasAudio) fileOut.OutputDword(DWORD_BE(9)); fileOut.OutputDword(0); metaDataPos = fileOut.GetPos(); char metaDataBuffer[2048]; char *enc = metaDataBuffer; char *pend = metaDataBuffer+sizeof(metaDataBuffer); enc = AMF_EncodeString(enc, pend, &av_onMetaData); char *endMetaData = App->EncMetaData(enc, pend, true); UINT metaDataSize = endMetaData-metaDataBuffer; AppendFLVPacket((LPBYTE)metaDataBuffer, metaDataSize, 18, 0); return true; }
void AppendFLVPacket(const BYTE *lpData, UINT size, BYTE type, DWORD timestamp) { if (!bSentSEI && type == 9 && lpData[0] == 0x17 && lpData[1] == 0x1) { //send SEI with first keyframe packet UINT networkDataSize = fastHtonl(size+sei.size); UINT networkTimestamp = fastHtonl(timestamp); UINT streamID = 0; fileOut.OutputByte(type); fileOut.Serialize(((LPBYTE)(&networkDataSize))+1, 3); fileOut.Serialize(((LPBYTE)(&networkTimestamp))+1, 3); fileOut.Serialize(&networkTimestamp, 1); fileOut.Serialize(&streamID, 3); fileOut.Serialize(lpData, 5); fileOut.Serialize(sei.lpPacket, sei.size); fileOut.Serialize(lpData+5, size-5); fileOut.OutputDword(fastHtonl(size+sei.size+11)); bSentSEI = true; } else { UINT networkDataSize = fastHtonl(size); UINT networkTimestamp = fastHtonl(timestamp); UINT streamID = 0; fileOut.OutputByte(type); fileOut.Serialize(((LPBYTE)(&networkDataSize))+1, 3); fileOut.Serialize(((LPBYTE)(&networkTimestamp))+1, 3); fileOut.Serialize(&networkTimestamp, 1); fileOut.Serialize(&streamID, 3); fileOut.Serialize(lpData, size); fileOut.OutputDword(fastHtonl(size+11)); } lastTimeStamp = timestamp; }