Issue #2673 - Part 2: Add ADTS format sniffer.

This commit is contained in:
Moonchild 2024-12-29 13:31:47 +01:00 committed by roytam1
commit e25b285ca7
2 changed files with 25 additions and 0 deletions

View file

@ -840,4 +840,26 @@ ADTSTrackDemuxer::AverageFrameLength() const
return 0.0;
}
/* static */ bool
ADTSDemuxer::ADTSSniffer(const uint8_t* aData, const uint32_t aLength)
{
if (aLength < 7) {
return false;
}
auto parser = MakeUnique<adts::FrameParser>();
if (!parser->Parse(0, aData, aData + aLength)) {
return false;
}
const adts::Frame& currentFrame = parser->CurrentFrame();
// Check for sync marker after the found frame, since it's
// possible to find sync marker in AAC data. If sync marker
// exists after the current frame then we've found a frame
// header.
int64_t nextFrameHeaderOffset = currentFrame.Offset() + currentFrame.Length();
return int64_t(aLength) > nextFrameHeaderOffset &&
aLength - nextFrameHeaderOffset >= 2 &&
adts::FrameHeader::MatchesSync(aData + nextFrameHeaderOffset);
}
} // namespace mozilla

View file

@ -32,6 +32,9 @@ public:
TrackInfo::TrackType aType, uint32_t aTrackNumber) override;
bool IsSeekable() const override;
// Return true if a valid ADTS frame header could be found.
static bool ADTSSniffer(const uint8_t* aData, const uint32_t aLength);
private:
bool InitInternal();