Skip to content

Commit

Permalink
Move audio/video headers and SEI packet to BufferedDataPacket
Browse files Browse the repository at this point in the history
  • Loading branch information
palana committed Oct 10, 2014
1 parent af8df3d commit bc0cc9c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
22 changes: 15 additions & 7 deletions Source/FLVFileStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "Main.h"
#include "RTMPStuff.h"

#include "DataPacketHelpers.h"



class FLVFileStream : public VideoFileStream
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
33 changes: 20 additions & 13 deletions Source/MP4FileStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "Main.h"
#include <time.h>

#include "DataPacketHelpers.h"


time_t GetMacTime()
{
Expand Down Expand Up @@ -287,28 +289,30 @@ class MP4FileStream : public VideoFileStream
UINT frameTime = 0;
UINT sampleRateHz = 0;
UINT width = 0, height = 0;
DataPacket videoHeaders;
List<BYTE> 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()
Expand Down Expand Up @@ -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);
}


Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bc0cc9c

Please sign in to comment.