diff --git a/Source/FLVFileStream.cpp b/Source/FLVFileStream.cpp index bd6afad59..f1ec3bb1a 100644 --- a/Source/FLVFileStream.cpp +++ b/Source/FLVFileStream.cpp @@ -20,6 +20,8 @@ #include "Main.h" #include "RTMPStuff.h" +#include "DataPacketHelpers.h" + class FLVFileStream : public VideoFileStream @@ -30,14 +32,15 @@ class FLVFileStream : public VideoFileStream UINT64 metaDataPos; DWORD lastTimeStamp, initialTimestamp; + decltype(GetBufferedSEIPacket()) sei = GetBufferedSEIPacket(); + decltype(GetBufferedAudioHeadersPacket()) audioHeaders = GetBufferedAudioHeadersPacket(); + decltype(GetBufferedVideoHeadersPacket()) videoHeaders = GetBufferedVideoHeadersPacket(); + bool bSentFirstPacket, bSentSEI; 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 - DataPacket sei; - App->GetVideoEncoder()->GetSEI(sei); - UINT networkDataSize = fastHtonl(size+sei.size); UINT networkTimestamp = fastHtonl(timestamp); UINT streamID = 0; @@ -124,16 +127,21 @@ class FLVFileStream : public VideoFileStream } } + void InitBufferedPackets() + { + sei.InitBuffer(); + audioHeaders.InitBuffer(); + videoHeaders.InitBuffer(); + } + virtual void AddPacket(const BYTE *data, UINT size, DWORD timestamp, DWORD /*pts*/, PacketType type) override { + InitBufferedPackets(); + if(!bSentFirstPacket) { bSentFirstPacket = true; - DataPacket audioHeaders, videoHeaders;//, videoSEI; - App->GetAudioHeaders(audioHeaders); - App->GetVideoHeaders(videoHeaders); - AppendFLVPacket(audioHeaders.lpPacket, audioHeaders.size, 8, 0); AppendFLVPacket(videoHeaders.lpPacket, videoHeaders.size, 9, 0); } diff --git a/Source/MP4FileStream.cpp b/Source/MP4FileStream.cpp index 341c2b5f9..8a85f1812 100644 --- a/Source/MP4FileStream.cpp +++ b/Source/MP4FileStream.cpp @@ -20,6 +20,8 @@ #include "Main.h" #include +#include "DataPacketHelpers.h" + time_t GetMacTime() { @@ -287,28 +289,30 @@ class MP4FileStream : public VideoFileStream UINT frameTime = 0; UINT sampleRateHz = 0; UINT width = 0, height = 0; - DataPacket videoHeaders; - List AACHeader; UINT maxBitRate = 0; - DataPacket sei; void CopyMetadata() { frameTime = App->GetFrameTime(); sampleRateHz = App->GetSampleRateHz(); App->GetOutputSize(width, height); - App->GetVideoHeaders(videoHeaders); //------------------------------------------- // get AAC headers if using AAC - if (!bMP3) - { - DataPacket data; - App->GetAudioHeaders(data); - AACHeader.CopyArray(data.lpPacket + 2, data.size - 2); - } maxBitRate = fastHtonl(App->GetAudioEncoder()->GetBitRate() * 1000); - App->GetVideoEncoder()->GetSEI(sei); + InitBufferedPackets(); + } + + decltype(GetBufferedSEIPacket()) sei = GetBufferedSEIPacket(); + decltype(GetBufferedAudioHeadersPacket()) audioHeaders = GetBufferedAudioHeadersPacket(); + decltype(GetBufferedVideoHeadersPacket()) videoHeaders = GetBufferedVideoHeadersPacket(); + + void InitBufferedPackets() + { + sei.InitBuffer(); + if (!bMP3) + audioHeaders.InitBuffer(); + videoHeaders.InitBuffer(); } ~MP4FileStream() @@ -382,8 +386,9 @@ class MP4FileStream : public VideoFileStream /*esDecoderOut.OutputByte(0x80); //some stuff that no one should probably care about esDecoderOut.OutputByte(0x80); esDecoderOut.OutputByte(0x80);*/ - esDecoderOut.OutputByte(AACHeader.Num()); - esDecoderOut.Serialize((LPVOID)AACHeader.Array(), AACHeader.Num()); + assert(audioHeaders.size >= 2); + esDecoderOut.OutputByte(audioHeaders.size - 2); + esDecoderOut.Serialize(audioHeaders.lpPacket + 2, audioHeaders.size - 2); } @@ -821,6 +826,8 @@ class MP4FileStream : public VideoFileStream virtual void AddPacket(const BYTE *data, UINT size, DWORD timestamp, DWORD /*pts*/, PacketType type) override { + InitBufferedPackets(); + UINT64 offset = fileOut.GetPos(); if(initialTimeStamp == -1 && data[0] != 0x17)