mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
216fe28466
--HG-- rename : content/media/nsAudioAvailableEventManager.cpp => content/media/AudioAvailableEventManager.cpp rename : content/media/nsAudioAvailableEventManager.h => content/media/AudioAvailableEventManager.h rename : content/media/nsAudioStream.cpp => content/media/AudioStream.cpp rename : content/media/nsAudioStream.h => content/media/AudioStream.h rename : content/media/nsMediaCache.cpp => content/media/MediaCache.cpp rename : content/media/nsMediaCache.h => content/media/MediaCache.h rename : content/media/nsBuiltinDecoder.cpp => content/media/MediaDecoder.cpp rename : content/media/nsBuiltinDecoder.h => content/media/MediaDecoder.h rename : content/media/nsBuiltinDecoderReader.cpp => content/media/MediaDecoderReader.cpp rename : content/media/nsBuiltinDecoderReader.h => content/media/MediaDecoderReader.h rename : content/media/nsBuiltinDecoderStateMachine.cpp => content/media/MediaDecoderStateMachine.cpp rename : content/media/nsBuiltinDecoderStateMachine.h => content/media/MediaDecoderStateMachine.h rename : content/media/dash/nsDASHDecoder.cpp => content/media/dash/DASHDecoder.cpp rename : content/media/dash/nsDASHDecoder.h => content/media/dash/DASHDecoder.h rename : content/media/dash/nsDASHReader.cpp => content/media/dash/DASHReader.cpp rename : content/media/dash/nsDASHReader.h => content/media/dash/DASHReader.h rename : content/media/dash/nsDASHRepDecoder.cpp => content/media/dash/DASHRepDecoder.cpp rename : content/media/dash/nsDASHRepDecoder.h => content/media/dash/DASHRepDecoder.h rename : content/media/gstreamer/nsGStreamerDecoder.cpp => content/media/gstreamer/GStreamerDecoder.cpp rename : content/media/gstreamer/nsGStreamerDecoder.h => content/media/gstreamer/GStreamerDecoder.h rename : content/media/gstreamer/nsGStreamerReader.cpp => content/media/gstreamer/GStreamerReader.cpp rename : content/media/gstreamer/nsGStreamerReader.h => content/media/gstreamer/GStreamerReader.h rename : content/media/ogg/nsOggCodecState.cpp => content/media/ogg/OggCodecState.cpp rename : content/media/ogg/nsOggCodecState.h => content/media/ogg/OggCodecState.h rename : content/media/ogg/nsOggDecoder.cpp => content/media/ogg/OggDecoder.cpp rename : content/media/ogg/nsOggDecoder.h => content/media/ogg/OggDecoder.h rename : content/media/ogg/nsOggReader.cpp => content/media/ogg/OggReader.cpp rename : content/media/ogg/nsOggReader.h => content/media/ogg/OggReader.h rename : content/media/omx/nsMediaOmxDecoder.cpp => content/media/omx/MediaOmxDecoder.cpp rename : content/media/omx/nsMediaOmxDecoder.h => content/media/omx/MediaOmxDecoder.h rename : content/media/omx/nsMediaOmxReader.cpp => content/media/omx/MediaOmxReader.cpp rename : content/media/omx/nsMediaOmxReader.h => content/media/omx/MediaOmxReader.h rename : content/media/plugins/nsMediaPluginDecoder.cpp => content/media/plugins/MediaPluginDecoder.cpp rename : content/media/plugins/nsMediaPluginDecoder.h => content/media/plugins/MediaPluginDecoder.h rename : content/media/plugins/nsMediaPluginHost.cpp => content/media/plugins/MediaPluginHost.cpp rename : content/media/plugins/nsMediaPluginHost.h => content/media/plugins/MediaPluginHost.h rename : content/media/plugins/nsMediaPluginReader.cpp => content/media/plugins/MediaPluginReader.cpp rename : content/media/plugins/nsMediaPluginReader.h => content/media/plugins/MediaPluginReader.h rename : content/media/raw/nsRawDecoder.cpp => content/media/raw/RawDecoder.cpp rename : content/media/raw/nsRawDecoder.h => content/media/raw/RawDecoder.h rename : content/media/raw/nsRawReader.cpp => content/media/raw/RawReader.cpp rename : content/media/raw/nsRawReader.h => content/media/raw/RawReader.h rename : content/media/raw/nsRawStructs.h => content/media/raw/RawStructs.h rename : content/media/wave/nsWaveDecoder.cpp => content/media/wave/WaveDecoder.cpp rename : content/media/wave/nsWaveDecoder.h => content/media/wave/WaveDecoder.h rename : content/media/wave/nsWaveReader.cpp => content/media/wave/WaveReader.cpp rename : content/media/wave/nsWaveReader.h => content/media/wave/WaveReader.h rename : content/media/webm/nsWebMBufferedParser.cpp => content/media/webm/WebMBufferedParser.cpp rename : content/media/webm/nsWebMBufferedParser.h => content/media/webm/WebMBufferedParser.h rename : content/media/webm/nsWebMDecoder.cpp => content/media/webm/WebMDecoder.cpp rename : content/media/webm/nsWebMDecoder.h => content/media/webm/WebMDecoder.h rename : content/media/webm/nsWebMReader.cpp => content/media/webm/WebMReader.cpp rename : content/media/webm/nsWebMReader.h => content/media/webm/WebMReader.h
243 lines
7.4 KiB
C++
243 lines
7.4 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 "mozilla/StandardInteger.h"
|
|
|
|
#include "nsDeque.h"
|
|
#include "MediaDecoderReader.h"
|
|
#include "nsAutoRef.h"
|
|
#include "nestegg/nestegg.h"
|
|
|
|
#define VPX_DONT_DEFINE_STDINT_TYPES
|
|
#include "vpx/vpx_codec.h"
|
|
|
|
#ifdef MOZ_TREMOR
|
|
#include "tremor/ivorbiscodec.h"
|
|
#else
|
|
#include "vorbis/codec.h"
|
|
#endif
|
|
|
|
namespace mozilla {
|
|
|
|
class WebMBufferedState;
|
|
|
|
// Holds a nestegg_packet, and its file offset. This is needed so we
|
|
// know the offset in the file we've played up to, in order to calculate
|
|
// whether it's likely we can play through to the end without needing
|
|
// to stop to buffer, given the current download rate.
|
|
class NesteggPacketHolder {
|
|
public:
|
|
NesteggPacketHolder(nestegg_packet* aPacket, int64_t aOffset)
|
|
: mPacket(aPacket), mOffset(aOffset)
|
|
{
|
|
MOZ_COUNT_CTOR(NesteggPacketHolder);
|
|
}
|
|
~NesteggPacketHolder() {
|
|
MOZ_COUNT_DTOR(NesteggPacketHolder);
|
|
nestegg_free_packet(mPacket);
|
|
}
|
|
nestegg_packet* mPacket;
|
|
// Offset in bytes. This is the offset of the end of the Block
|
|
// which contains the packet.
|
|
int64_t mOffset;
|
|
private:
|
|
// Copy constructor and assignment operator not implemented. Don't use them!
|
|
NesteggPacketHolder(const NesteggPacketHolder &aOther);
|
|
NesteggPacketHolder& operator= (NesteggPacketHolder const& aOther);
|
|
};
|
|
|
|
// Thread and type safe wrapper around nsDeque.
|
|
class PacketQueueDeallocator : public nsDequeFunctor {
|
|
virtual void* operator() (void* anObject) {
|
|
delete static_cast<NesteggPacketHolder*>(anObject);
|
|
return nullptr;
|
|
}
|
|
};
|
|
|
|
// Typesafe queue for holding nestegg packets. It has
|
|
// ownership of the items in the queue and will free them
|
|
// when destroyed.
|
|
class PacketQueue : private nsDeque {
|
|
public:
|
|
PacketQueue()
|
|
: nsDeque(new PacketQueueDeallocator())
|
|
{}
|
|
|
|
~PacketQueue() {
|
|
Reset();
|
|
}
|
|
|
|
inline int32_t GetSize() {
|
|
return nsDeque::GetSize();
|
|
}
|
|
|
|
inline void Push(NesteggPacketHolder* aItem) {
|
|
NS_ASSERTION(aItem, "NULL pushed to PacketQueue");
|
|
nsDeque::Push(aItem);
|
|
}
|
|
|
|
inline void PushFront(NesteggPacketHolder* aItem) {
|
|
NS_ASSERTION(aItem, "NULL pushed to PacketQueue");
|
|
nsDeque::PushFront(aItem);
|
|
}
|
|
|
|
inline NesteggPacketHolder* PopFront() {
|
|
return static_cast<NesteggPacketHolder*>(nsDeque::PopFront());
|
|
}
|
|
|
|
void Reset() {
|
|
while (GetSize() > 0) {
|
|
delete PopFront();
|
|
}
|
|
}
|
|
};
|
|
|
|
class WebMReader : public MediaDecoderReader
|
|
{
|
|
public:
|
|
WebMReader(MediaDecoder* aDecoder);
|
|
~WebMReader();
|
|
|
|
virtual nsresult Init(MediaDecoderReader* aCloneDonor);
|
|
virtual nsresult ResetDecode();
|
|
virtual bool DecodeAudioData();
|
|
|
|
// If the Theora granulepos has not been captured, it may read several packets
|
|
// until one with a granulepos has been captured, to ensure that all packets
|
|
// read have valid time info.
|
|
virtual bool DecodeVideoFrame(bool &aKeyframeSkip,
|
|
int64_t aTimeThreshold);
|
|
|
|
virtual bool HasAudio()
|
|
{
|
|
NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
|
|
return mHasAudio;
|
|
}
|
|
|
|
virtual bool HasVideo()
|
|
{
|
|
NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
|
|
return mHasVideo;
|
|
}
|
|
|
|
// Bug 575140, cannot seek in webm if no cue is present.
|
|
bool IsSeekableInBufferedRanges() {
|
|
return false;
|
|
}
|
|
|
|
virtual nsresult ReadMetadata(nsVideoInfo* aInfo,
|
|
MetadataTags** aTags);
|
|
virtual nsresult Seek(int64_t aTime, int64_t aStartTime, int64_t aEndTime, int64_t aCurrentTime);
|
|
virtual nsresult GetBuffered(nsTimeRanges* aBuffered, int64_t aStartTime);
|
|
virtual void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset);
|
|
|
|
// Sets byte range for initialization (EBML); used by DASH.
|
|
void SetInitByteRange(MediaByteRange &aByteRange) {
|
|
mInitByteRange = aByteRange;
|
|
}
|
|
|
|
// Sets byte range for cue points, i.e. cluster offsets; used by DASH.
|
|
void SetIndexByteRange(MediaByteRange &aByteRange) {
|
|
mCuesByteRange = aByteRange;
|
|
}
|
|
|
|
// Returns list of ranges for cluster start and end offsets.
|
|
nsresult GetIndexByteRanges(nsTArray<MediaByteRange>& aByteRanges);
|
|
|
|
private:
|
|
// 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 NULL 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.
|
|
nsReturnRef<NesteggPacketHolder> NextPacket(TrackType aTrackType);
|
|
|
|
// Returns an initialized ogg packet with data obtained from the WebM container.
|
|
ogg_packet InitOggPacket(unsigned char* aData,
|
|
size_t aLength,
|
|
bool aBOS,
|
|
bool aEOS,
|
|
int64_t aGranulepos);
|
|
|
|
// 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. This function will free the packet
|
|
// so the caller must not use the packet after calling.
|
|
bool DecodeAudioPacket(nestegg_packet* aPacket, int64_t aOffset);
|
|
|
|
// Release context and set to null. Called when an error occurs during
|
|
// reading metadata or destruction of the reader itself.
|
|
void Cleanup();
|
|
|
|
private:
|
|
// libnestegg context for webm container. Access on state machine thread
|
|
// or decoder thread only.
|
|
nestegg* mContext;
|
|
|
|
// VP8 decoder state
|
|
vpx_codec_ctx_t mVP8;
|
|
|
|
// Vorbis decoder state
|
|
vorbis_info mVorbisInfo;
|
|
vorbis_comment mVorbisComment;
|
|
vorbis_dsp_state mVorbisDsp;
|
|
vorbis_block mVorbisBlock;
|
|
uint32_t mPacketCount;
|
|
uint32_t mChannels;
|
|
|
|
// Queue of video and audio packets that have been read but not decoded. These
|
|
// must only be accessed from the state machine thread.
|
|
PacketQueue mVideoPackets;
|
|
PacketQueue 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;
|
|
|
|
// Parser state and computed offset-time mappings. Shared by multiple
|
|
// readers when decoder has been cloned. Main thread only.
|
|
nsRefPtr<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;
|
|
|
|
// Booleans to indicate if we have audio and/or video data
|
|
bool mHasVideo;
|
|
bool mHasAudio;
|
|
|
|
// Byte range for initialisation data; e.g. specified in DASH manifest.
|
|
MediaByteRange mInitByteRange;
|
|
|
|
// Byte range for cues; e.g. specified in DASH manifest.
|
|
MediaByteRange mCuesByteRange;
|
|
|
|
// Byte ranges for clusters; set internally, derived from cues.
|
|
nsTArray<MediaByteRange> mClusterByteRanges;
|
|
};
|
|
|
|
} // namespace mozilla
|
|
|
|
#endif
|