Files
palemoon27/dom/media/MP3FrameParser.h
T
roytam1 e1776c67f8 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1199885 - Part 2: Add AsyncDragMetrics. r=kats (220a4f445e)
- Bug 1149482 - Localize the 'none' string for APZ in about:support. r=dvander (3e0128f62e)
- Bug 1199885 - Part 3: Add 'apz.drag.enabled' preference for async scrollbars. r=kats (5133061d3f)
- Bug 1199885 - Part 4: Let the hit testing tree know about the scroll thumb. r=kats (26a9a69443)
- Bug 1199885 - Part 5: Make mRootLayerTreeID const to prove that there's no data races. r=kats (88e2eb80f1)
- Bug 1199885 - Part 8: Add FindScrollNode to locate the scrollbar thumb. r=kats (a545ec9569)
- Bug 1199885 - Part 9: Let APZC handle the drag events. r=kats (4cc0f88153)
- Bug 1199885 - Part 9.5: Make the mouse events APZC aware. r=kats (69bd4caf94)
- Bug 1199885 - Part 10: Add APZTeeManager API to start an async scroll. r=kats (e212ee2750)
- Bug 1199885 - Part 12: Add StartScrollbarDrag IPC message. r=kats (705af3b233)
- Bug 1199885 - Part 13: Let nsSliderFrame trigger async scrolling via StartScrollbarDrag. r=kats (d31b5a790d)
- put in gstreamer as of 2015-10-05 Bug 1146482 (7cca45858c)
- pointer style (f8041af438)
- Bug 1197097 - Don't use a context-wide cycle-detection mechanism for detecting cycles during JSON.stringify. This prevents nested (yet separate) JSON.stringify, and it causes that algorithm to be affected by specification-unrelated operations like toSource. r=jonco (09652471c1)
- align to ugly grammaer of 1114782 (c760693693)
- remove space (7158a0c2bf)
- align to FF/TFF (27138a55bb)
- Bug 1205887 - Verify that MOZILLA_VERSION was set correctly, r=glandium (2269e8f31b)
- Bug 1205012 - Allow rust source code in SpiderMonkey; r=mshal (9ebca9ed28)
- Bug 1197281 - Use MOZ_FIND_WINSDK_VERSION for MOZ_WINSDK_MAXVER on mingw. r=glandium (2910b2160e)
- Bug 1207893 - Refactor how build backend execution is summarized. r=gps (56d8fecbc2)
- Bug 1207893 - Allow to create multiple build backends at once. r=gps (d8cba87d2b)
- Bug 1207897 - Add a configure option to build multiple build backends. r=gps (f9c7851d02)
- Bug 1188555 - part 1 - remove write-only configure.in variable NO_LD_ARCHIVE_FLAGS; r=mshal (461958b100)
- Bug 1188555 - part 2 - remove write-only configure.in variables MKSHLIB_{UN,}FORCE_ALL; r=mshal (1813210dda)
- Bug 1207882 - Ensure chrome manifests are created in a directory that exists when processing jar manifests. r=gps (59165a64cb)
- Bug 1204712 - Handle wildcards properly for localized content in jar manifests. r=gps (54dfb632c7)
- Bug 1188551: treat assertion failures as bad mozconfig; r=mshal (e307769de7)
- Bug 1181040 - Set ${var}_IS_SET variables for mk_add_options-defined variables. r=gps (19f169556b)
- Bug 1193015 - Require MOZ_GLX_USE_SURFACE_SHARING to enable WebGL surface sharing on GLX. r=jgilbert (9aa4fa8f41)
- Bug 1211324 (part 1) - Remove BILINEAR and GAUSSIAN filter constants. (3d9290ef02)
- Bug 1211324 (part 2) - Make gfx::FILTER::GOOD convert to GraphicsFilter::FILTER_GOOD. r=mattwoodrow. (16e7607c70)
- Bug 1208365 (part 1) - Remove unused EXTEND_PAD_EDGE. r=Bas. (10920e2bb6)
- Bug 1208365 (part 2) - Remove gfxPattern::Extend(). r=bas. (3703b9748a)
- Bug 1208365 (part 3) - Change gfxPattern::mExtend from a GraphicsExtend to a gfx::ExtendMode. r=bas. (b105d06e91)
- Bug 1208365 (part 4) - Remove gfxPattern::GraphicsExtend. r=bas. (7a16d48995)
- Bug 1211324 (part 3) - Remove GraphicsFilter::FILTER_FAST and replace it with FILTER_BEST. r=mattwoodrow. (b5101e049f)
- Bug 1211324 (part 4) - Replace GraphicsFilter constants with gfx::Filter equivalents. r=mattwoodrow. (c19b6b030e)
- Bug 1190117 - Track mLastProducerID and mLastFrameID explicitly in ImageLayerProperties. r=roc (ed9a5c777f)
- Bug 1211324 (part 5) - Remove GraphicsFilter and gfxGraphicsFilter. r=mattwoodrow. (0bd4ce7160)
- Bug 1194954 - Fix -Wunreachable-code warnings in gfx/layers and gfx/thebes. r=BenWa (1a3d68c490)
- Bug 1180509 - Fix judder of icons in Australis doorhanger menu at the end of its scale-in animation. r=roc (9b4df470fa)
- Bug 1206915 - Make paint dumping to a file e10s-friendly. r=mattwoodrow (87d2e12c2b)
- Bug 1206915 - Handle nested PaintFrame() calls correctly during paint dumping. r=mattwoodrow,BenWa (d30f77fbdd)
- Fix max texture size handling in displayport clamping. (bug 1135907 follow-up, r=kats) (a791894332)
- Fix bogus assertion in nsLayoutUtils::SetDisplayPortMargins. (bug 1156409, r=botond, a=philor) (b635b21c34)
- Bug 1169879 - Use only the critical displayport when computing image visibility. r=tn (9ec91c9527)
- Bug 1169881 - Recompute image visibility when display port margins change. r=tn (35a5bd3a51)
- Bug 1197765 - Compare text content inside frame instead of the content node for ruby autohiding. r=dbaron (00cf5b7674)
- Bug 1173580 - Record content descriptions in APZ test data. r=kats (7a72d1ac0a)
- Bug 1178971 - Changed line snapping behaviour depending on even/odd-ness of stroke width. r=mstange (495b32dc23)
- Bug 1208953: [mp3] Don't parse data we've already parsed. r=cpearce (72eed4309f)
- Bug 1137151: Marked destructor of |android::MediaCodecReader| as protected, r=sotaro (0632b34bc5)
- Bug 1205351 - Replace nsBaseHashtable::Enumerate() calls in dom/media/ with iterators r=cpearce (45976c24c0)
- Bug 1133624 - Add lang-specific ruby rules to ua.css. r=dbaron (46788cc220)
- Bug 1133624 - followup add fuzzy maxdiff on CLOSED TREE (1b6b62aded)
- Bug 1180443 - Consider whitespace collapse when calculating intrinsic isize of ruby. r=dbaron (3862184acd)
- Bug 1153764 - Avoid explicitly doing break before when there is ruby span. r=roc (71b4ec7749)
- add gstreamer parts (7e562556be)
- some preferences aligned to FF (b26d0b389c)
- Bug 1166301 - If APZ is enabled, clip fixed background images at the layer level rather than the display item level. r=mattwoodrow (5644e22090)
- Bug 1144990 - Dump display items with class id and name, r=roc (aa2e227e35)
- Bug 1205087 - Remove LayerManager parameter for ShouldFixToViewport. r=roc (00a1f2e36f)
- Bug 1205087 - Make nsSVGIntegrationUtils paint frame continuations manually since combining them meant that our reference frame wasn't an ancestor of all painted frames. r=roc (e40f6b7b81)
- Bug 1195400 - Check ancestor geometry roots when determining scrollability of a layer. r=mattwoodrow (4699b7e935)
- Bug 1205087 - Cache the AnimatedGeometryRoot on DisplayItem. r=roc (06bba311c3)
- Back out the bits of bug 1205087 that cache the AnimatedGeometryRoot on DisplayItem. r=backout (254057a6b6)
- Bug 1203190 - Don't intersect with the visible rect for fixed background images. r=mattwoodrow (1c5a432459)
- Bug 1208438 - Don't allow layers with scrolling clips to occlusion-cull layers behind them. r=mattwoodrow (c3d77a9846)
- Bug 1205630 - Translate a fixed background display item's clip rect correctly when setting it on the layer. r=mstange (49039f0e2d)
- Bug 1205630 - Reftest. r=mstange (a8db59eaee)
- Bug 1105832 - Also dump inactive layer managers when display list dumping is enabled. r=mattwoodrow (564fe5fcbc)
- Bug 1208661 - Move Dump() up from ContentClient to CompositableClient. r=BenWa (37915312b3)
2022-09-22 10:16:52 +08:00

238 lines
7.1 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef MP3FrameParser_h
#define MP3FrameParser_h
#include <stdint.h>
#include "mozilla/Mutex.h"
#include "nsString.h"
#include "Intervals.h"
namespace mozilla {
// Simple parser to tell whether we've found an ID3 header and how long it is,
// so that we can skip it.
// XXX maybe actually parse this stuff?
class ID3Parser
{
public:
ID3Parser();
void Reset();
bool ParseChar(char ch);
bool IsParsed() const;
uint32_t GetHeaderLength() const;
private:
uint32_t mCurrentChar;
uint8_t mVersion;
uint8_t mFlags;
uint32_t mHeaderLength;
};
struct MP3Frame {
uint16_t mSync1 : 8; // Always all set
uint16_t mProtected : 1; // Ignored
uint16_t mLayer : 2;
uint16_t mVersion : 2;
uint16_t mSync2 : 3; // Always all set
uint16_t mPrivate : 1; // Ignored
uint16_t mPad : 1;
uint16_t mSampleRate : 2; // Index into mpeg_srates above
uint16_t mBitrate : 4; // Index into mpeg_bitrates above
uint16_t CalculateLength();
};
// Buffering parser for MP3 frames.
class MP3Parser
{
public:
MP3Parser();
// Forget all data the parser has seen so far.
void Reset();
// Parse the given byte. If we have found a frame header, return the length of
// the frame.
uint16_t ParseFrameLength(uint8_t ch);
// Get the sample rate from the current header.
uint32_t GetSampleRate();
// Get the number of samples per frame.
uint32_t GetSamplesPerFrame();
private:
uint32_t mCurrentChar;
union {
uint8_t mRaw[3];
MP3Frame mFrame;
} mData;
};
// A description of the MP3 format and its extensions is available at
//
// http://www.codeproject.com/Articles/8295/MPEG-Audio-Frame-Header
//
// The data in MP3 streams is split into small frames, with each frame
// containing a fixed number of samples. The duration of a frame depends
// on the frame's bit rate and sample rate. Both values can vary among
// frames, so it is necessary to examine each individual frame of an MP3
// stream to calculate the stream's overall duration.
//
// The MP3 frame parser extracts information from an MP3 data stream. It
// accepts a range of frames of an MP3 stream as input, and parses all
// frames for their duration. Callers can query the stream's overall
// duration from the parser.
//
// Call the methods NotifyDataArrived or Parse to add new data. If you added
// information for a certain stream position, you cannot go back to previous
// positions. The parser will simply ignore the input. If you skip stream
// positions, the duration of the related MP3 frames will be estimated from
// the stream's average.
//
// The method GetDuration returns calculated duration of the stream, including
// estimates for skipped ranges.
//
// All public methods are thread-safe.
class MP3FrameParser
{
public:
explicit MP3FrameParser(int64_t aLength=-1);
bool IsMP3() {
MutexAutoLock mon(mLock);
return mIsMP3 != NOT_MP3;
}
void Parse(const uint8_t* aBuffer, uint32_t aLength, uint64_t aStreamOffset);
// Returns the duration, in microseconds. If the entire stream has not
// been parsed yet, this is an estimate based on the bitrate of the
// frames parsed so far.
int64_t GetDuration();
// Returns the offset of the first MP3 frame in the stream, or -1 of
// no MP3 frame has been detected yet.
int64_t GetMP3Offset();
// Returns true if we've seen the whole first frame of the MP3 stream, and
// therefore can make an estimate on the stream duration.
// Otherwise, returns false.
bool ParsedHeaders();
// Returns true if we know the exact duration of the MP3 stream;
// false otherwise.
bool HasExactDuration();
// Returns true if the parser needs more data for duration estimation.
bool NeedsData();
// Assign the total lenght of this mp3 stream
void SetLength(int64_t aLength) {
MutexAutoLock mon(mLock);
mLength = aLength;
}
private:
// Parses aBuffer, starting at offset 0. Returns the number of bytes
// parsed, relative to the start of the buffer. Note this may be
// greater than aLength if the headers in the buffer indicate that
// the frame or ID3 tag extends outside of aBuffer. Returns failure
// if too many non-MP3 bytes are parsed.
nsresult ParseBuffer(const uint8_t* aBuffer,
uint32_t aLength,
int64_t aStreamOffset,
uint32_t* aOutBytesRead);
// A low-contention lock for protecting the parser results
Mutex mLock;
// ID3 header parser. Keeps state between reads in case the header falls
// in between.
ID3Parser mID3Parser;
// MP3 frame header parser.
MP3Parser mMP3Parser;
// If we read |MAX_SKIPPED_BYTES| from the stream without finding any MP3
// frames, we give up and report |NOT_MP3|. Here we track the cumulative size
// of any ID3 headers we've seen so big ID3 sections aren't counted towards
// skipped bytes.
uint32_t mTotalID3Size;
// All fields below are protected by mLock
// We keep stats on the size of all the frames we've seen, as well as how many
// so that we can estimate the duration of the rest of the stream.
uint64_t mTotalFrameSize;
uint64_t mFrameCount;
// Offset of the last data parsed. This is the end offset of the last data
// block parsed, so it's the start offset we expect to get on the next
// call to Parse().
uint64_t mOffset;
// Total length of the stream in bytes.
int64_t mLength;
// Offset of first MP3 frame in the bitstream. Has value -1 until the
// first MP3 frame is found.
int64_t mMP3Offset;
// The exact number of frames in this stream, if we know it. -1 otherwise.
int64_t mNumFrames;
// Number of audio samples per second and per frame. Fixed through the whole
// file. If we know these variables as well as the number of frames in the
// file, we can get an exact duration for the stream.
uint16_t mSamplesPerSecond;
uint16_t mSamplesPerFrame;
// If the MP3 has a variable bitrate, then there *should* be metadata about
// the encoding in the first frame. We buffer the first frame here.
nsAutoCString mFirstFrame;
// While we are reading the first frame, this is the stream offset of the
// last byte of that frame. -1 at all other times.
int64_t mFirstFrameEnd;
enum eIsMP3 {
MAYBE_MP3, // We're giving the stream the benefit of the doubt...
DEFINITELY_MP3, // We've hit at least one ID3 tag or MP3 frame.
NOT_MP3 // Not found any evidence of the stream being MP3.
};
eIsMP3 mIsMP3;
};
class NotifyDataArrivedFilter {
public:
media::IntervalSet<int64_t> NotifyDataArrived(uint32_t aLength, int64_t aOffset) {
media::Interval<int64_t> interval(aOffset, aOffset + aLength);
media::IntervalSet<int64_t> newIntervals(interval);
newIntervals -= mIntervals;
mIntervals += interval;
return newIntervals;
}
const media::IntervalSet<int64_t>& GetIntervals() {
return mIntervals;
}
private:
media::IntervalSet<int64_t> mIntervals;
};
} // namespace mozilla
#endif