Files
palemoon27/dom/media/webm/WebMReader.h
T
roytam1 9855d648fe import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1144107 - Part 4: Prevent assert when hitting EOS. r=kentuckyfriedtakahe (4e66e9d148)
- Bug 1226842: Error rather than asserting when encountering error in sample table. r=gerald (4bbe6cd7f2)
- Bug 1189992: Don't assume the last chunk always contains the sample we're looking for. r=gerald (4cf3a3f63a)
- Bug 1225703 - Update in-tree libcubeb. r=padenot (49ce53e3c8)
- Bug 1203449 - Remove OutputStreamListener from DecodedStream.cpp. r=roc. (24421a02e1)
- Bug 1207915 - Apply the fix of bug 1052206 to DecodedStream. r=roc. (c73a3aecc6)
- Bug 1218311 - Port the fix of bug 1193614 to VideoSink. r=cpearce. (cbbe3dc1ab)
- Bug 1230338 - Record video frames dropped by the compositor, or while flushing during skip-to-keyframe. r=jya (edf53548d3)
- Bug 1230882. Part 1 - destroy DecodedStreamData properly when dispatch fails. r=roc. (adb3c05671)
- Bug 1230004. Part 1 - cache data in MDSM so it won't need to ask MediaDecoder. r=cpearce. (728c6b3e82)
- Bug 1219163. Part 1 - Remove unused functions from AbstractMediaDecoder. r=jya. (f1dba3d50c)
- Bug 1219163. Part 2 - Move some functions that are never called from the interface of AbstractMediaDecoder down the class hierarchy. r=jya. (c0fc72790f)
- Bug 1226569. Part 1 - Use MediaEventSource to publish MetadataLoaded and FirstFrameLoaded events. r=jya. (76195567a5)
- Bug 1226569. Part 2 - assert functions that should never be called after shutdown. r=jya. (672df604e5)
- Bug 1227797 - Use MediaEventSource to publish playback events for MDSM. r=jya. (4a3fda2f34)
- Bug 1228923 - Merge some MediaEventSource for MDSM. r=jya. (31929f5777)
- Bug 1228939 - 1. add mSeekable to MediaInfo. 2. use MediaEventSource to notify the decoder when the media is not seekable. 3. remove unused code. r=jya. (38fb6d1099)
- Bug 1230004. Part 2 - have MDSM::BeginShutdown return a promise and remove MDSM::mDecoder. r=cpearce. (0f45558e15)
- add some disabled EME stuff (c4fa7e65be)
- Bug 873438 - Implement IAccessible2_2::accessibleWithCaret, r=yzen (9fb71ce7f3)
- Bug 1159872 - Make IAccessible2::Get_States once again return S_OK when it detects a defunct accessible. r=surkov (91ad6d1798)
- bug 606080 - on windows give accessibles a unique 32 bit id r=surkov (848c16f16c)
- Bug 1220897 - fix IAccessible2::get_accessibleWithCaret, r=tbsaunde (492790b4e1)
- Bug 1225298 - Use GCHashMap for UniqueIdMap, r=terrence (ee896fb807)
- Bug 1227567 - Optimise module namespace imports in Ion where we have type information r=shu (19fdf97bc3)
- Bug 1230337 - Fix TypedArrayObject::isNeutered to stop calling typed arrays using inline storage neutered. (r=Waldo) (2838830319)
- Bug 1055472 - Part 1: Factor out GetPrototypeFromConstructor and use it in existing object creation paths. (r=Waldo) (a26c188064)
- Bug 1055472 - Part 2: Make the Function constructor properly subclassable. (r=Waldo) (e2ff4b48d4)
- Bug 1055472 - Part 2b: Make Function.prototype.bind play nicely with subclassed functions. (r=Waldo, shoutouts for good flyby by evilpie) (59b347ced4)
- Bug 1055472 - Part 3: Make the Object constructor properly subclassable. (r=Waldo) (aa23b6c005)
- Bug 1055472 - Part 4: Make the Boolean constructor properly subclassable. (r=Waldo) (6ff68c5198)
- Bug 1055472 - Part 5: Make the various Error constructors properly subclassable. (r=Waldo) (7e36f26bcd)
- Bug 1055472 - Part 6: Make the Number constructor properly subclassable. (r=Waldo) (5b081bb54c)
- Bug 1055472 - Part 7: Make the Date constructor properly subclassable. (r=Waldo) (a841523521)
- Bug 1055472 - Part 8 prelim: Rename InitializeRegExp to RegExpObject::initFromAtom for readability. (r=Waldo) (053ce20768)
- Bug 1055472 - Part 8: Make the RegExp constructor properly subclassable. (r=Waldo) (a522ecca25)
- Bug 1055472 - Part 9: Make the Map constructor properly subclassable. (r=Waldo) (a29bb1408a)
- Bug 1055472 - Part 10: Make the Set constructor properly subclassable. (r=Waldo) (82befdc508)
- Bug 1055472 - Part 11: Make the WeakMap constructor properly subclassable. (r=Waldo) (0ea50757d4)
- Bug 1055472 - Part 12: Mae the WeakSet constructor properly subclassable. (r=Waldo) (6ba67d4fe6)
- Bug 1055472 - Part 13: Make the ArrayBuffer constructor properly subclassable. (r=Waldo) (7811dadf92)
- Bug 1055472 - Part 14: Make the various TypedArray constructors properly subclassable. (r=Waldo, r=bhackett) (6bc10f8ec1)
- Bug 1055472 - Part 15: Make the DataView constructor properly subclassable. (r=jorendorff, r=bhackett) (b2b6aef1f6)
- Bug 1055472 - Part 16: Make the String constructor properly subclassable. (r=Waldo) (6bed2e45bc)
- Bug 1055472 - Part 17: Make the Array constructor properly subclassable. (r=jorendorff, r=bhackett, r=terrence) (d301fe9814)
- Bug 1055472 - Part 18: Incorportate arai's test into the subclassing suite. (r=me) (cfbc97738a)
- Bug 1226416 - Expose a method to get a node's set of immediately dominated nodes in the dominator tree; r=bz,sfink (8226985fb6)
- Bug 1199422 - Stop pattern matching class-constructors in String#replace and Array#sort. r=efaust (58b56ad143)
- Bug 1206308 - include nsprpub and zlib for Windows, plus minor enhancements to make-source-package.sh, r=sstangl (e933f3a27a)
- Bug 1229729 - Make make-source-package.sh work on OS X. r=sfink (d55f9bc552)
- Bug 1221747 - Make JS_vsnprintf() return a value that indicates failure if we reach the buffer limit r=nbp (1bc82ccafd)
- Bug 1227385 - Properly propagate $DIST from top-level after bug 1224490. r=mshal (ee4fc81981)
- Bug 1200304 - Move stumbling code from gonkgps to MozStumbler.cpp. r=jdm (89aea7211c)
- Bug 1207266 - turn off b2g stumbler if no RIL. r=jdm (ae42aeb5a2)
- Bug 1228947 - Replace mfbt/Constants.h with math.h. r=roc (d56e2bbe2f)
- Bug 1176261 - Discard gps with impossibly tiny accuracy. r=jaliu (93a4114ac7)
- Bug 772750 - Get mobile connection technology from MobileConnectionService. r=garvank,echen (742d68becb)
- Bug 1168068 - GonkGPSGeolocationProvider should use mRilDataServiceId in SetReferenceLocation. r=garvank (b07ee26cc4)
- Bug 1227385 - Avoid make variable references in VISIBILITY_FLAGS and STL_FLAGS. r=mshal (e3e7fc9d99)
- Bug 1225298 - Use GCHashSet for atoms table, r=terrence (4bce42238c)
- Bug 1225298 - Use GCHashSet for InnerViewTable, r=terrence (e8da10443c)
- Bug 1203297 - Fix one last bit of unified bustage; r=bbouvier (7395aca8da)
- Bug 1228340: Rename JitOptions into DefaultJitOptions and get rid of the js_ prefix for the instance; r=h4writer (19777f9a49)
- Bug 1227190 part 1. change PrepareScriptEnvironmentAndInvoke to return void, not bool, to make it clearer that it reports exceptions for you. r=jorendorff (7525efb3ad)
- Bug 1227190 part 2. Change PrepareScriptEnvironmentAndInvoke to take a JSContext*, not a JSRuntime*. r=jorendorff (01b69ccab1)
- Bug 1227190 part 3. Make debugger error reporting play nice with the embedding taking ownership of error reporting. r=jorendorff (008195b9a3)
- Bug 1221600 - Tweak comments about standard internal methods in jsobj.h, jsfriendapi.h. r=efaust. (c1a4b0e2bf)
- Bug 1223372 - Handle ToWindowProxyIfWindow returning a dead wrapper in PrepareForWrapping. r=bholley (0b3dd8084b)
- Bug 1197095 - ensure that ForOfIterator does not pass arguments to next calls; r=evilpie (29acf9b12d)
- Bug 1197094 - ForOfIterator calls ToObject on iterable; r=evilpie (533dd11111)
- Bug 1216379 - Throw less cryptic error message when using a non-iterable in a for...of loop. r=jorendorff (ae7d4c3734)
- Bug 1230010 - OdinMonkey: MIPS: Make immediate patching shared. r=luke (97b5650d3a)
- Bug 1131759 - Atomicize SharedScriptData::marked. (r=terrence) (bafe64c080)
- Bug 1229579 - Make class members properly XDR-able. (r=billm) (d95743694f)
- Bug 1227642: Make data a ScopedJSFreePtr in js::detail::CopyScript to ensure it doesn't leak; r=jonco (db8bcafc09)
- Bug 1227287 - Fix minor bug with f.arguments and lazy arguments. r=luke (9c1cc5aaad)
- Bug 1228947 - mingw fixup. (3216b8df21)
- Bug 1231163 - Don't assume the RNG's been initialized by a prior call to Math.random, when a call to Math.random is being inlined. (A method can be inlined once its identity has been guarded against, but mere identity can be established without the method having been called.) r=jwalden (d7e2235e63)
- crash stuff (12dfaea226)
- Bug 1218027 - "--with-system-icu fails: js/src/jsapi.cpp:69: error: visibility does not match previous declaration". r=mh+mozilla (5929f4280c)
- Bug 1229740 - add <array> to the list of wrapped system headers; r=glandium (990a0a22ab)
- Bug 1192312 - Use MediaCodecSource for camera recording since gonkL r=aosmond (f68121e622)
- Bug 1210293 - Remove legacy check from the XPIDL HTMLInputElement::SetUserInput. r=bz (f70fbfd8ea)
- Bug 1220323 - Enable FasterMake backend by default for all apps. r=gps (7421f68979)
- Fixup for b2g bustage from bug 1164921. r=me (6207a28039)
- Bug 1209391 - Remove build/unix/uniq.py. r=mshal (d757f44938)
- Bug 1192233 - delete check for sys/cdefs.h from configure; r=mshal (ca2709a478)
- Bug 1191816 - don't check for sys/int_types.h in configure; r=mshal (3f77884338)
- Bug 1182565 - Disable sandboxing on Linux Thread Sanitizer builds. r=kang (5dcd521ca1)
- missing bits of Bug 1157768 - Build files and config headers for libav fft (5ab19c5158)
- Bug 1149279 - Remove unused build config variable NSS_NO_LIBPKIX. r=gps (0abbcd89c3)
- Bug 1161238 - Remove --disable-logging. r=gps (b896b8f77d)
- Bug 1167201 - Make absence of gconf developer packages a fatal error rather than disabling gconf automatically in the build system. This is necessary because if gconf is disabled, many tests don't work because they use gconf to detect linux. r=glandium (4def45dc4f)
- bug 1220037 pack and unpack Nyquist for MOZ_LIBAV_FFT r=padenot (23e4e277ff)
- bug 1220041 remove unnecessary temp buffer and copy with libav FFT r=padenot (20df464d7b)
- bug 1220041 scale when copying for inverse FFT to avoid iterating twice r=padenot (d9c11db7e2)
- bug 1223520 avoid leaking NaNs to and from the otherwise unused imaginary frequency components r=padenot (0ff120a534)
- bug 1188704 remove now unused PerformInverseFFT() variation r=rillian (b82b4d459a)
- bug 1188704 add accessor functions for setting frequency components for inverse FFT r=rillian (c8357b6268)
- style (3b9fc23a34)
- Bug 1173016 - Properly refcount the inner PeriodicWave object. r=karlt (634e09bb79)
- bug 1187785 reverse tableInterpolationFactor to make it consistent with documentation r=rillian (928fa29f6c)
- bug 1188704 redefine halfSize as fftSize / 2 r=rillian (1cf36a13e3)
- bug 1188704 trim unnecessary extra basic waveform coeffient r=rillian (c33983684a)
- bug 1188704 simplify culling of partials r=rillian (484932e54e)
- bug 1188704 combine scaling with copying r=rillian (7e5d3f9c7d)
- bug 1188704 limit number of Fourier coefficients used to halfSize earlier r=rillian (abba4f31bb)
- bug 1188704 use existing FFTBlock arrays instead of allocating and copying and scaling r=rillian (74b58f3bc3)
- warnings (cf6c0840e8)
- Bug 1171436 - support at least 8192 elements for PeriodicWave r=padenot (7ddeb3ec3f)
- bug 1221831 remove unused Reverb::reset() r=padenot (913849471f)
- bug 1221831 remove unused Reverb::latencyFrames() r=padenot (767744e87c)
- bug 1221830 use WEBAUDIO_BLOCK_SIZE constant in Reverb methods r=padenot (38dc6b0a92)
- bug 1221831 use initial input buffer offset to control when convolver stages perform their FFT r=padenot (4f594ded7a)
- bug 1221831 remove now-unnecessary m_preDelayBuffer r=padenot (af5b36efdc)
- bug 1221830 use WEBAUDIO_BLOCK_SIZE slice size for background convolver thread r=padenot (0d6dbe1daa)
- bug 1221830 double maximum realtime convolver stage size to 2048 r=padenot (1cf7698f2d)
- bug 1221830 use WEBAUDIO_BLOCK_SIZE constant in FFTConvolver r=padenot (955e902db8)
- bug 1221833 reduce FFTConvolver latency by one block r=padenot (024b13396a)
- bug 1221833 replace initial direct convolution stage with fft r=padenot (70319e951b)
- bug 1221833 remove first two half-block-size convolver stages r=padenot (2709910848)
- bug 1221833 remove now-unused direct convolver r=padenot (d0cfb712af)
- bug 1221836 return output pointer from FFTConvolver::process() to save a buffer copy r=padenot (4bf6c5e6c8)
- Bug 1196608 - Link liblgpllibs against mozglue. r=mshal (3212491e68)
- missing bit of 1157768 (3d6844b56e)
- bug 1224102 reduce the size of the final FFT convolution stage if possible r=padenot (f1fbd7f04d)
- Bug 1192587 - Build media/libav in unified mode. r=qDot (77dd2810e3)
- Bug 1228230 - Rely more on top-level configure auto-detection. r=qdot (8add5f4014)
- Bug 1261414 - Don't build libav with sysctl on Unix (it's not used anyway). r=glandium (195c3ddba4)
- Bug 1222405 - (part 1) Store PeriodicWave components for later use r=padenot (a993b3303d)
- Bug 1222405 - (part 2) Build band limited tables after fundamental frequency is known r=padenot (d350f2e201)
- Bug 1222405 - (part 3) Build band limited tables lazily r=padenot (0dc6f013fc)
2023-05-09 11:34:56 +08:00

214 lines
6.5 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/. */
#if !defined(WebMReader_h_)
#define WebMReader_h_
#include <stdint.h>
#include "FlushableTaskQueue.h"
#include "MediaDecoderReader.h"
#include "MediaResource.h"
#include "nsAutoRef.h"
#include "nestegg/nestegg.h"
#define VPX_DONT_DEFINE_STDINT_TYPES
#include "vpx/vpx_codec.h"
#include "mozilla/layers/LayersTypes.h"
#include "NesteggPacketHolder.h"
namespace mozilla {
static const unsigned NS_PER_USEC = 1000;
static const double NS_PER_S = 1e9;
typedef TrackInfo::TrackType TrackType;
class WebMBufferedState;
class WebMPacketQueue;
class WebMReader;
// Class to handle various video decode paths
class WebMVideoDecoder
{
public:
virtual nsresult Init(unsigned int aWidth = 0, unsigned int aHeight = 0) = 0;
virtual nsresult Flush() { return NS_OK; }
virtual void Shutdown() = 0;
virtual bool DecodeVideoFrame(bool &aKeyframeSkip,
int64_t aTimeThreshold) = 0;
WebMVideoDecoder() {}
virtual ~WebMVideoDecoder() {}
};
// Class to handle various audio decode paths
class WebMAudioDecoder
{
public:
virtual nsresult Init() = 0;
virtual void Shutdown() = 0;
virtual nsresult ResetDecode() = 0;
virtual nsresult DecodeHeader(const unsigned char* aData, size_t aLength) = 0;
virtual nsresult FinishInit(AudioInfo& aInfo) = 0;
virtual bool Decode(const unsigned char* aData, size_t aLength,
int64_t aOffset, uint64_t aTstampUsecs,
int64_t aDiscardPadding, int32_t* aTotalFrames) = 0;
virtual ~WebMAudioDecoder() {}
};
class WebMReader : public MediaDecoderReader
{
public:
explicit WebMReader(AbstractMediaDecoder* aDecoder);
protected:
~WebMReader();
public:
// Returns a pointer to the decoder.
AbstractMediaDecoder* GetDecoder()
{
return mDecoder;
}
MediaInfo GetMediaInfo() { return mInfo; }
virtual RefPtr<ShutdownPromise> Shutdown() override;
virtual nsresult Init() override;
virtual nsresult ResetDecode() override;
virtual bool DecodeAudioData() override;
virtual bool DecodeVideoFrame(bool &aKeyframeSkip,
int64_t aTimeThreshold) override;
virtual RefPtr<MetadataPromise> AsyncReadMetadata() override;
virtual RefPtr<SeekPromise>
Seek(int64_t aTime, int64_t aEndTime) override;
virtual media::TimeIntervals GetBuffered() override;
// Value passed to NextPacket to determine if we are reading a video or an
// audio packet.
enum TrackType {
VIDEO = 0,
AUDIO = 1
};
// Read a packet from the nestegg file. Returns nullptr if all packets for
// the particular track have been read. Pass VIDEO or AUDIO to indicate the
// type of the packet we want to read.
RefPtr<NesteggPacketHolder> NextPacket(TrackType aTrackType);
// Pushes a packet to the front of the video packet queue.
virtual void PushVideoPacket(NesteggPacketHolder* aItem);
int GetVideoCodec();
nsIntRect GetPicture();
nsIntSize GetInitialFrame();
int64_t GetLastVideoFrameTime();
void SetLastVideoFrameTime(int64_t aFrameTime);
layers::LayersBackend GetLayersBackendType() { return mLayersBackendType; }
uint64_t GetCodecDelay() { return mCodecDelay; }
protected:
virtual void NotifyDataArrivedInternal() override;
// Decode a nestegg packet of audio data. Push the audio data on the
// audio queue. Returns true when there's more audio to decode,
// false if the audio is finished, end of file has been reached,
// or an un-recoverable read error has occured. The reader's monitor
// must be held during this call. The caller is responsible for freeing
// aPacket.
bool DecodeAudioPacket(NesteggPacketHolder* aHolder);
// Release context and set to null. Called when an error occurs during
// reading metadata or destruction of the reader itself.
void Cleanup();
virtual nsresult SeekInternal(int64_t aTime);
// Initializes mLayersBackendType if possible.
void InitLayersBackendType();
bool ShouldSkipVideoFrame(int64_t aTimeThreshold);
private:
nsresult RetrieveWebMMetadata(MediaInfo* aInfo);
// Get the timestamp of keyframe greater than aTimeThreshold.
int64_t GetNextKeyframeTime(int64_t aTimeThreshold);
// Push the packets into aOutput which's timestamp is less than aEndTime.
// Return false if we reach the end of stream or something wrong.
bool FilterPacketByTime(int64_t aEndTime, WebMPacketQueue& aOutput);
// Internal method that demuxes the next packet from the stream. The caller
// is responsible for making sure it doesn't get lost.
RefPtr<NesteggPacketHolder> DemuxPacket();
// libnestegg context for webm container. Access on state machine thread
// or decoder thread only.
nestegg* mContext;
nsAutoPtr<WebMAudioDecoder> mAudioDecoder;
nsAutoPtr<WebMVideoDecoder> mVideoDecoder;
// Queue of video and audio packets that have been read but not decoded. These
// must only be accessed from the decode thread.
WebMPacketQueue mVideoPackets;
WebMPacketQueue mAudioPackets;
// Index of video and audio track to play
uint32_t mVideoTrack;
uint32_t mAudioTrack;
// Time in microseconds of the start of the first audio frame we've decoded.
int64_t mAudioStartUsec;
// Number of audio frames we've decoded since decoding began at mAudioStartMs.
uint64_t mAudioFrames;
// Number of microseconds that must be discarded from the start of the Stream.
uint64_t mCodecDelay;
// Nanoseconds to discard after seeking.
uint64_t mSeekPreroll;
// Calculate the frame duration from the last decodeable frame using the
// previous frame's timestamp. In NS.
int64_t mLastVideoFrameTime;
// Parser state and computed offset-time mappings. Shared by multiple
// readers when decoder has been cloned. Main thread only.
RefPtr<WebMBufferedState> mBufferedState;
// Size of the frame initially present in the stream. The picture region
// is defined as a ratio relative to this.
nsIntSize mInitialFrame;
// Picture region, as relative to the initial frame size.
nsIntRect mPicture;
// Codec ID of audio track
int mAudioCodec;
// Codec ID of video track
int mVideoCodec;
layers::LayersBackend mLayersBackendType;
// Booleans to indicate if we have audio and/or video data
bool mHasVideo;
bool mHasAudio;
MediaResourceIndex mResource;
};
} // namespace mozilla
#endif