gecko-dev/content/media/nsMediaDecoder.h
Robert O'Callahan e38733eb15 Bug 499880 - Restructure content/media directory. r+=doublec
--HG--
rename : content/media/video/src/nsAudioStream.cpp => content/media/nsAudioStream.cpp
rename : content/media/video/public/nsAudioStream.h => content/media/nsAudioStream.h
rename : content/media/video/src/nsMediaCache.cpp => content/media/nsMediaCache.cpp
rename : content/media/video/public/nsMediaCache.h => content/media/nsMediaCache.h
rename : content/media/video/src/nsMediaDecoder.cpp => content/media/nsMediaDecoder.cpp
rename : content/media/video/public/nsMediaDecoder.h => content/media/nsMediaDecoder.h
rename : content/media/video/src/nsMediaStream.cpp => content/media/nsMediaStream.cpp
rename : content/media/video/public/nsMediaStream.h => content/media/nsMediaStream.h
rename : content/media/video/src/nsChannelReader.cpp => content/media/ogg/nsChannelReader.cpp
rename : content/media/video/public/nsChannelReader.h => content/media/ogg/nsChannelReader.h
rename : content/media/video/src/nsOggDecoder.cpp => content/media/ogg/nsOggDecoder.cpp
rename : content/media/video/public/nsOggDecoder.h => content/media/ogg/nsOggDecoder.h
rename : content/media/video/test/320x240.allow-origin.ogv => content/media/test/320x240.allow-origin.ogv
rename : content/media/video/test/320x240.allow-origin.ogv^headers^ => content/media/test/320x240.allow-origin.ogv^headers^
rename : content/media/video/test/320x240.ogv => content/media/test/320x240.ogv
rename : content/media/video/test/Makefile.in => content/media/test/Makefile.in
rename : content/media/video/test/big.wav => content/media/test/big.wav
rename : content/media/video/test/bug461281.ogg => content/media/test/bug461281.ogg
rename : content/media/video/test/bug482461.ogv => content/media/test/bug482461.ogv
rename : content/media/video/test/can_play_type_ogg.js => content/media/test/can_play_type_ogg.js
rename : content/media/video/test/can_play_type_wave.js => content/media/test/can_play_type_wave.js
rename : content/media/video/test/contentDuration1.sjs => content/media/test/contentDuration1.sjs
rename : content/media/video/test/contentDuration2.sjs => content/media/test/contentDuration2.sjs
rename : content/media/video/test/contentDuration3.sjs => content/media/test/contentDuration3.sjs
rename : content/media/video/test/contentDuration4.sjs => content/media/test/contentDuration4.sjs
rename : content/media/video/test/contentDuration5.sjs => content/media/test/contentDuration5.sjs
rename : content/media/video/test/contentDuration6.sjs => content/media/test/contentDuration6.sjs
rename : content/media/video/test/crashtests/468763-1.html => content/media/test/crashtests/468763-1.html
rename : content/media/video/test/crashtests/474744-1.html => content/media/test/crashtests/474744-1.html
rename : content/media/video/test/crashtests/crashtests.list => content/media/test/crashtests/crashtests.list
rename : content/media/video/test/dynamic_redirect.sjs => content/media/test/dynamic_redirect.sjs
rename : content/media/video/test/file_access_controls.html => content/media/test/file_access_controls.html
rename : content/media/video/test/r11025_s16_c1.wav => content/media/test/r11025_s16_c1.wav
rename : content/media/video/test/r11025_s16_c1_trailing.wav => content/media/test/r11025_s16_c1_trailing.wav
rename : content/media/video/test/r11025_u8_c1.wav => content/media/test/r11025_u8_c1.wav
rename : content/media/video/test/r11025_u8_c1_trunc.wav => content/media/test/r11025_u8_c1_trunc.wav
rename : content/media/video/test/r16000_u8_c1_list.wav => content/media/test/r16000_u8_c1_list.wav
rename : content/media/video/test/redirect.sjs => content/media/test/redirect.sjs
rename : content/media/video/test/seek.ogv => content/media/test/seek.ogv
rename : content/media/video/test/small-shot.ogg => content/media/test/small-shot.ogg
rename : content/media/video/test/sound.ogg => content/media/test/sound.ogg
rename : content/media/video/test/test_access_control.html => content/media/test/test_access_control.html
rename : content/media/video/test/test_audio1.html => content/media/test/test_audio1.html
rename : content/media/video/test/test_audio2.html => content/media/test/test_audio2.html
rename : content/media/video/test/test_audioDocumentTitle.html => content/media/test/test_audioDocumentTitle.html
rename : content/media/video/test/test_autobuffer.html => content/media/test/test_autobuffer.html
rename : content/media/video/test/test_autobuffer2.html => content/media/test/test_autobuffer2.html
rename : content/media/video/test/test_autoplay.html => content/media/test/test_autoplay.html
rename : content/media/video/test/test_bug448534.html => content/media/test/test_bug448534.html
rename : content/media/video/test/test_bug461281.html => content/media/test/test_bug461281.html
rename : content/media/video/test/test_bug463162.xhtml => content/media/test/test_bug463162.xhtml
rename : content/media/video/test/test_bug465498.html => content/media/test/test_bug465498.html
rename : content/media/video/test/test_bug468190.html => content/media/test/test_bug468190.html
rename : content/media/video/test/test_bug468190_wav.html => content/media/test/test_bug468190_wav.html
rename : content/media/video/test/test_bug476973.html => content/media/test/test_bug476973.html
rename : content/media/video/test/test_bug482461.html => content/media/test/test_bug482461.html
rename : content/media/video/test/test_bug493187.html => content/media/test/test_bug493187.html
rename : content/media/video/test/test_bug495145.html => content/media/test/test_bug495145.html
rename : content/media/video/test/test_bug495145_wav.html => content/media/test/test_bug495145_wav.html
rename : content/media/video/test/test_bug495300.html => content/media/test/test_bug495300.html
rename : content/media/video/test/test_bug495319.html => content/media/test/test_bug495319.html
rename : content/media/video/test/test_can_play_type.html => content/media/test/test_can_play_type.html
rename : content/media/video/test/test_can_play_type_no_ogg.html => content/media/test/test_can_play_type_no_ogg.html
rename : content/media/video/test/test_can_play_type_no_wave.html => content/media/test/test_can_play_type_no_wave.html
rename : content/media/video/test/test_can_play_type_ogg.html => content/media/test/test_can_play_type_ogg.html
rename : content/media/video/test/test_can_play_type_wave.html => content/media/test/test_can_play_type_wave.html
rename : content/media/video/test/test_closing_connections.html => content/media/test/test_closing_connections.html
rename : content/media/video/test/test_constants.html => content/media/test/test_constants.html
rename : content/media/video/test/test_contentDuration1.html => content/media/test/test_contentDuration1.html
rename : content/media/video/test/test_contentDuration2.html => content/media/test/test_contentDuration2.html
rename : content/media/video/test/test_contentDuration3.html => content/media/test/test_contentDuration3.html
rename : content/media/video/test/test_contentDuration4.html => content/media/test/test_contentDuration4.html
rename : content/media/video/test/test_contentDuration5.html => content/media/test/test_contentDuration5.html
rename : content/media/video/test/test_contentDuration6.html => content/media/test/test_contentDuration6.html
rename : content/media/video/test/test_controls.html => content/media/test/test_controls.html
rename : content/media/video/test/test_currentTime.html => content/media/test/test_currentTime.html
rename : content/media/video/test/test_decoder_disable.html => content/media/test/test_decoder_disable.html
rename : content/media/video/test/test_delay_load.html => content/media/test/test_delay_load.html
rename : content/media/video/test/test_duration1.html => content/media/test/test_duration1.html
rename : content/media/video/test/test_ended1.html => content/media/test/test_ended1.html
rename : content/media/video/test/test_ended2.html => content/media/test/test_ended2.html
rename : content/media/video/test/test_error_on_404.html => content/media/test/test_error_on_404.html
rename : content/media/video/test/test_info_leak.html => content/media/test/test_info_leak.html
rename : content/media/video/test/test_load.html => content/media/test/test_load.html
rename : content/media/video/test/test_load_candidates.html => content/media/test/test_load_candidates.html
rename : content/media/video/test/test_media_selection.html => content/media/test/test_media_selection.html
rename : content/media/video/test/test_mixed_principals.html => content/media/test/test_mixed_principals.html
rename : content/media/video/test/test_networkState.html => content/media/test/test_networkState.html
rename : content/media/video/test/test_onloadedmetadata.html => content/media/test/test_onloadedmetadata.html
rename : content/media/video/test/test_paused.html => content/media/test/test_paused.html
rename : content/media/video/test/test_paused_after_ended.html => content/media/test/test_paused_after_ended.html
rename : content/media/video/test/test_play.html => content/media/test/test_play.html
rename : content/media/video/test/test_progress1.html => content/media/test/test_progress1.html
rename : content/media/video/test/test_progress2.html => content/media/test/test_progress2.html
rename : content/media/video/test/test_progress3.html => content/media/test/test_progress3.html
rename : content/media/video/test/test_progress4.html => content/media/test/test_progress4.html
rename : content/media/video/test/test_readyState.html => content/media/test/test_readyState.html
rename : content/media/video/test/test_seek1.html => content/media/test/test_seek1.html
rename : content/media/video/test/test_seek2.html => content/media/test/test_seek2.html
rename : content/media/video/test/test_seek3.html => content/media/test/test_seek3.html
rename : content/media/video/test/test_seek4.html => content/media/test/test_seek4.html
rename : content/media/video/test/test_seek5.html => content/media/test/test_seek5.html
rename : content/media/video/test/test_seek6.html => content/media/test/test_seek6.html
rename : content/media/video/test/test_seek7.html => content/media/test/test_seek7.html
rename : content/media/video/test/test_seek8.html => content/media/test/test_seek8.html
rename : content/media/video/test/test_seek9.html => content/media/test/test_seek9.html
rename : content/media/video/test/test_source.html => content/media/test/test_source.html
rename : content/media/video/test/test_source_write.html => content/media/test/test_source_write.html
rename : content/media/video/test/test_standalone.html => content/media/test/test_standalone.html
rename : content/media/video/test/test_timeupdate1.html => content/media/test/test_timeupdate1.html
rename : content/media/video/test/test_timeupdate2.html => content/media/test/test_timeupdate2.html
rename : content/media/video/test/test_timeupdate3.html => content/media/test/test_timeupdate3.html
rename : content/media/video/test/test_videoDocumentTitle.html => content/media/test/test_videoDocumentTitle.html
rename : content/media/video/test/test_volume.html => content/media/test/test_volume.html
rename : content/media/video/test/test_wav_8bit.html => content/media/test/test_wav_8bit.html
rename : content/media/video/test/test_wav_ended1.html => content/media/test/test_wav_ended1.html
rename : content/media/video/test/test_wav_ended2.html => content/media/test/test_wav_ended2.html
rename : content/media/video/test/test_wav_list.html => content/media/test/test_wav_list.html
rename : content/media/video/test/test_wav_onloadedmetadata.html => content/media/test/test_wav_onloadedmetadata.html
rename : content/media/video/test/test_wav_seek1.html => content/media/test/test_wav_seek1.html
rename : content/media/video/test/test_wav_seek3.html => content/media/test/test_wav_seek3.html
rename : content/media/video/test/test_wav_seek4.html => content/media/test/test_wav_seek4.html
rename : content/media/video/test/test_wav_seek5.html => content/media/test/test_wav_seek5.html
rename : content/media/video/test/test_wav_seek6.html => content/media/test/test_wav_seek6.html
rename : content/media/video/test/test_wav_seek7.html => content/media/test/test_wav_seek7.html
rename : content/media/video/test/test_wav_seek8.html => content/media/test/test_wav_seek8.html
rename : content/media/video/test/test_wav_seek_past_end.html => content/media/test/test_wav_seek_past_end.html
rename : content/media/video/test/test_wav_seek_then_play.html => content/media/test/test_wav_seek_then_play.html
rename : content/media/video/test/test_wav_standalone.html => content/media/test/test_wav_standalone.html
rename : content/media/video/test/test_wav_timeupdate1.html => content/media/test/test_wav_timeupdate1.html
rename : content/media/video/test/test_wav_timeupdate2.html => content/media/test/test_wav_timeupdate2.html
rename : content/media/video/test/test_wav_trailing.html => content/media/test/test_wav_trailing.html
rename : content/media/video/test/test_wav_trunc.html => content/media/test/test_wav_trunc.html
rename : content/media/video/test/test_wav_trunc_seek.html => content/media/test/test_wav_trunc_seek.html
rename : content/media/video/test/use_large_cache.js => content/media/test/use_large_cache.js
rename : content/media/video/src/nsWaveDecoder.cpp => content/media/wave/nsWaveDecoder.cpp
rename : content/media/video/public/nsWaveDecoder.h => content/media/wave/nsWaveDecoder.h
2009-06-26 16:23:15 +12:00

311 lines
12 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: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: ML 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla code.
*
* The Initial Developer of the Original Code is the Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Chris Double <chris.double@double.co.nz>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#if !defined(nsMediaDecoder_h_)
#define nsMediaDecoder_h_
#include "mozilla/XPCOM.h"
#include "nsIPrincipal.h"
#include "nsSize.h"
#include "prlog.h"
#include "gfxContext.h"
#include "gfxRect.h"
#include "nsITimer.h"
#ifdef PR_LOGGING
extern PRLogModuleInfo* gVideoDecoderLog;
#define LOG(type, msg) PR_LOG(gVideoDecoderLog, type, msg)
#else
#define LOG(type, msg)
#endif
class nsHTMLMediaElement;
// All methods of nsMediaDecoder must be called from the main thread only
// with the exception of SetRGBData and GetStatistics, which can be
// called from any thread.
class nsMediaDecoder : public nsIObserver
{
public:
typedef mozilla::TimeStamp TimeStamp;
typedef mozilla::TimeDuration TimeDuration;
nsMediaDecoder();
virtual ~nsMediaDecoder();
// Initialize the logging object
static nsresult InitLogger();
// Perform any initialization required for the decoder.
// Return PR_TRUE on successful initialisation, PR_FALSE
// on failure.
virtual PRBool Init(nsHTMLMediaElement* aElement);
// Return the current URI being played or downloaded.
virtual void GetCurrentURI(nsIURI** aURI) = 0;
// Return the principal of the current URI being played or downloaded.
virtual already_AddRefed<nsIPrincipal> GetCurrentPrincipal() = 0;
// Return the time position in the video stream being
// played measured in seconds.
virtual float GetCurrentTime() = 0;
// Seek to the time position in (seconds) from the start of the video.
virtual nsresult Seek(float time) = 0;
// Called by the element when the playback rate has been changed.
// Adjust the speed of the playback, optionally with pitch correction,
// when this is called.
virtual nsresult PlaybackRateChanged() = 0;
// Return the duration of the video in seconds.
virtual float GetDuration() = 0;
// Pause video playback.
virtual void Pause() = 0;
// Set the audio volume. It should be a value from 0 to 1.0.
virtual void SetVolume(float volume) = 0;
// Start playback of a video. 'Load' must have previously been
// called.
virtual nsresult Play() = 0;
// Start downloading the video. Decode the downloaded data up to the
// point of the first frame of data.
// Exactly one of aURI and aChannel must be null. aListener must be
// null if and only if aChannel is.
virtual nsresult Load(nsIURI* aURI,
nsIChannel* aChannel,
nsIStreamListener **aListener) = 0;
// Draw the latest video data. This is done
// here instead of in nsVideoFrame so that the lock around the
// RGB buffer doesn't have to be exposed publically.
// The current video frame is drawn to fill aRect.
// Called in the main thread only.
virtual void Paint(gfxContext* aContext,
gfxPattern::GraphicsFilter aFilter,
const gfxRect& aRect);
// Called when the video file has completed downloading.
virtual void ResourceLoaded() = 0;
// Called if the media file encounters a network error.
virtual void NetworkError() = 0;
// Call from any thread safely. Return PR_TRUE if we are currently
// seeking in the media resource.
virtual PRBool IsSeeking() const = 0;
// Return PR_TRUE if the decoder has reached the end of playback.
// Call in the main thread only.
virtual PRBool IsEnded() const = 0;
struct Statistics {
// Estimate of the current playback rate (bytes/second).
double mPlaybackRate;
// Estimate of the current download rate (bytes/second). This
// ignores time that the channel was paused by Gecko.
double mDownloadRate;
// Total length of media stream in bytes; -1 if not known
PRInt64 mTotalBytes;
// Current position of the download, in bytes. This is the offset of
// the first uncached byte after the decoder position.
PRInt64 mDownloadPosition;
// Current position of decoding, in bytes (how much of the stream
// has been consumed)
PRInt64 mDecoderPosition;
// Current position of playback, in bytes
PRInt64 mPlaybackPosition;
// If false, then mDownloadRate cannot be considered a reliable
// estimate (probably because the download has only been running
// a short time).
PRPackedBool mDownloadRateReliable;
// If false, then mPlaybackRate cannot be considered a reliable
// estimate (probably because playback has only been running
// a short time).
PRPackedBool mPlaybackRateReliable;
};
// Return statistics. This is used for progress events and other things.
// This can be called from any thread. It's only a snapshot of the
// current state, since other threads might be changing the state
// at any time.
virtual Statistics GetStatistics() = 0;
// Set the duration of the media resource in units of milliseconds.
// This is called via a channel listener if it can pick up the duration
// from a content header. Must be called from the main thread only.
virtual void SetDuration(PRInt64 aDuration) = 0;
// Set a flag indicating whether seeking is supported
virtual void SetSeekable(PRBool aSeekable) = 0;
// Return PR_TRUE if seeking is supported.
virtual PRBool GetSeekable() = 0;
// Invalidate the frame.
virtual void Invalidate();
// Fire progress events if needed according to the time and byte
// constraints outlined in the specification. aTimer is PR_TRUE
// if the method is called as a result of the progress timer rather
// than the result of downloaded data.
virtual void Progress(PRBool aTimer);
// Called by nsMediaStream when the "cache suspended" status changes.
// If nsMediaStream::IsSuspendedByCache returns true, then the decoder
// should stop buffering or otherwise waiting for download progress and
// start consuming data, if possible, because the cache is full.
virtual void NotifySuspendedStatusChanged() = 0;
// Called by nsMediaStream when some data has been received.
// Call on the main thread only.
virtual void NotifyBytesDownloaded() = 0;
// Called by nsChannelToPipeListener or nsMediaStream when the
// download has ended. Called on the main thread only. aStatus is
// the result from OnStopRequest.
virtual void NotifyDownloadEnded(nsresult aStatus) = 0;
// Cleanup internal data structures. Must be called on the main
// thread by the owning object before that object disposes of this object.
virtual void Shutdown();
// Suspend any media downloads that are in progress. Called by the
// media element when it is sent to the bfcache, or when we need
// to throttle the download. Call on the main thread only. This can
// be called multiple times, there's an internal "suspend count".
virtual void Suspend() = 0;
// Resume any media downloads that have been suspended. Called by the
// media element when it is restored from the bfcache, or when we need
// to stop throttling the download. Call on the main thread only.
// The download will only actually resume once as many Resume calls
// have been made as Suspend calls.
virtual void Resume() = 0;
// Returns a weak reference to the media element we're decoding for,
// if it's available.
nsHTMLMediaElement* GetMediaElement();
// Moves any existing channel loads into the background, so that they don't
// block the load event. This is called when we stop delaying the load
// event. Any new loads initiated (for example to seek) will also be in the
// background. Implementations of this must call MoveLoadsToBackground() on
// their nsMediaStream.
virtual void MoveLoadsToBackground()=0;
protected:
// Start timer to update download progress information.
nsresult StartProgress();
// Stop progress information timer.
nsresult StopProgress();
// Set the RGB width, height, pixel aspect ratio, and framerate.
// Ownership of the passed RGB buffer is transferred to the decoder.
// This is the only nsMediaDecoder method that may be called from
// threads other than the main thread.
void SetRGBData(PRInt32 aWidth,
PRInt32 aHeight,
float aFramerate,
float aAspectRatio,
unsigned char* aRGBBuffer);
protected:
// Timer used for updating progress events
nsCOMPtr<nsITimer> mProgressTimer;
// The element is not reference counted. Instead the decoder is
// notified when it is able to be used. It should only ever be
// accessed from the main thread.
nsHTMLMediaElement* mElement;
// RGB data for last decoded frame of video data.
// The size of the buffer is mRGBWidth*mRGBHeight*4 bytes and
// contains bytes in RGBA format.
nsAutoArrayPtr<unsigned char> mRGB;
PRInt32 mRGBWidth;
PRInt32 mRGBHeight;
// Time that the last progress event was fired. Read/Write from the
// main thread only.
TimeStamp mProgressTime;
// Time that data was last read from the media resource. Used for
// computing if the download has stalled and to rate limit progress events
// when data is arriving slower than PROGRESS_MS. A value of null indicates
// that a stall event has already fired and not to fire another one until
// more data is received. Read/Write from the main thread only.
TimeStamp mDataTime;
// Lock around the video RGB, width and size data. This
// is used in the decoder backend threads and the main thread
// to ensure that repainting the video does not use these
// values while they are out of sync (width changed but
// not height yet, etc).
// Backends that are updating the height, width or writing
// to the RGB buffer must obtain this lock first to ensure that
// the video element does not use video data or sizes that are
// in the midst of being changed.
PRLock* mVideoUpdateLock;
// Framerate of video being displayed in the element
// expressed in numbers of frames per second.
float mFramerate;
// Pixel aspect ratio (ratio of the pixel width to pixel height)
float mAspectRatio;
// Has our size changed since the last repaint?
PRPackedBool mSizeChanged;
// True if the decoder is being shutdown. At this point all events that
// are currently queued need to return immediately to prevent javascript
// being run that operates on the element and decoder during shutdown.
// Read/Write from the main thread only.
PRPackedBool mShuttingDown;
};
#endif