mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
Bug 462957 - DOM implementation of HTMLMediaElement.buffered. r=roc a=blocking2.0
This commit is contained in:
parent
e7719dff47
commit
6cc25b1183
@ -110,6 +110,7 @@ CPPSRCS = \
|
||||
nsHTMLTableRowElement.cpp \
|
||||
nsHTMLTableSectionElement.cpp \
|
||||
nsHTMLTextAreaElement.cpp \
|
||||
nsHTMLTimeRanges.cpp \
|
||||
nsHTMLTitleElement.cpp \
|
||||
$(NULL)
|
||||
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include "nsIDOMHTMLMediaElement.h"
|
||||
#include "nsIDOMHTMLSourceElement.h"
|
||||
#include "nsHTMLMediaElement.h"
|
||||
#include "nsHTMLTimeRanges.h"
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "nsPresContext.h"
|
||||
#include "nsIPresShell.h"
|
||||
@ -2213,3 +2214,13 @@ nsHTMLMediaElement::CopyInnerTo(nsGenericElement* aDest) const
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsHTMLMediaElement::GetBuffered(nsIDOMHTMLTimeRanges** aBuffered)
|
||||
{
|
||||
nsHTMLTimeRanges* ranges = new nsHTMLTimeRanges();
|
||||
NS_ADDREF(*aBuffered = ranges);
|
||||
if (mReadyState >= nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA && mDecoder) {
|
||||
return mDecoder->GetBuffered(ranges);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
79
content/html/content/src/nsHTMLTimeRanges.cpp
Normal file
79
content/html/content/src/nsHTMLTimeRanges.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
/* -*- 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: MPL 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 Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Chris Pearce <chris@pearce.org.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 ***** */
|
||||
|
||||
#include "nsHTMLTimeRanges.h"
|
||||
#include "nsDOMError.h"
|
||||
#include "nsContentUtils.h"
|
||||
|
||||
NS_IMPL_ADDREF(nsHTMLTimeRanges)
|
||||
NS_IMPL_RELEASE(nsHTMLTimeRanges)
|
||||
|
||||
DOMCI_DATA(HTMLTimeRanges, nsHTMLTimeRanges)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsHTMLTimeRanges)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLTimeRanges)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(HTMLTimeRanges)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLTimeRanges::GetLength(PRUint32* aLength) {
|
||||
*aLength = mRanges.Length();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLTimeRanges::Start(PRUint32 aIndex, float* aTime) {
|
||||
if (aIndex > mRanges.Length())
|
||||
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
||||
*aTime = mRanges[aIndex].mStart;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLTimeRanges::End(PRUint32 aIndex, float* aTime) {
|
||||
if (aIndex > mRanges.Length())
|
||||
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
||||
*aTime = mRanges[aIndex].mEnd;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsHTMLTimeRanges::Add(float aStart, float aEnd) {
|
||||
mRanges.AppendElement(TimeRange(aStart,aEnd));
|
||||
}
|
63
content/html/content/src/nsHTMLTimeRanges.h
Normal file
63
content/html/content/src/nsHTMLTimeRanges.h
Normal file
@ -0,0 +1,63 @@
|
||||
/* -*- 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: MPL 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 Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Chris Pearce <chris@pearce.org.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 ***** */
|
||||
|
||||
#include "nsIDOMHTMLTimeRanges.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
// Implements media TimeRanges:
|
||||
// http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#timeranges
|
||||
class nsHTMLTimeRanges : public nsIDOMHTMLTimeRanges {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDOMHTMLTIMERANGES
|
||||
|
||||
void Add(float aStart, float aEnd);
|
||||
|
||||
private:
|
||||
|
||||
struct TimeRange {
|
||||
TimeRange(float aStart, float aEnd)
|
||||
: mStart(aStart),
|
||||
mEnd(aEnd) {}
|
||||
float mStart;
|
||||
float mEnd;
|
||||
};
|
||||
|
||||
nsAutoTArray<TimeRange,4> mRanges;
|
||||
};
|
@ -294,6 +294,8 @@ public:
|
||||
// the decode monitor held.
|
||||
virtual void UpdatePlaybackPosition(PRInt64 aTime) = 0;
|
||||
|
||||
virtual nsresult GetBuffered(nsHTMLTimeRanges* aBuffered) = 0;
|
||||
|
||||
// Causes the state machine to switch to buffering state, and to
|
||||
// immediately stop playback and buffer downloaded data. Must be called
|
||||
// with the decode monitor held. Called on the state machine thread and
|
||||
@ -426,6 +428,12 @@ class nsBuiltinDecoder : public nsMediaDecoder
|
||||
return mMonitor;
|
||||
}
|
||||
|
||||
// Constructs the time ranges representing what segments of the media
|
||||
// are buffered and playable.
|
||||
virtual nsresult GetBuffered(nsHTMLTimeRanges* aBuffered) {
|
||||
return mDecoderStateMachine->GetBuffered(aBuffered);
|
||||
}
|
||||
|
||||
public:
|
||||
// Return the current state. Can be called on any thread. If called from
|
||||
// a non-main thread, the decoder monitor must be held.
|
||||
|
@ -452,6 +452,9 @@ public:
|
||||
// Queue of video samples. This queue is threadsafe.
|
||||
MediaQueue<VideoData> mVideoQueue;
|
||||
|
||||
// This is called on the main thread, and it must not block.
|
||||
virtual nsresult GetBuffered(nsHTMLTimeRanges* aBuffered, PRInt64 aStartTime) = 0;
|
||||
|
||||
protected:
|
||||
|
||||
// Reader decode function. Matches DecodeVideoFrame() and
|
||||
|
@ -234,6 +234,10 @@ public:
|
||||
// Accessed on state machine, audio, main, and AV thread.
|
||||
State mState;
|
||||
|
||||
nsresult GetBuffered(nsHTMLTimeRanges* aBuffered) {
|
||||
return mReader->GetBuffered(aBuffered, mStartTime);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
// Returns PR_TRUE when there's decoded audio waiting to play.
|
||||
|
@ -51,6 +51,7 @@
|
||||
class nsHTMLMediaElement;
|
||||
class nsMediaStream;
|
||||
class nsIStreamListener;
|
||||
class nsHTMLTimeRanges;
|
||||
|
||||
// All methods of nsMediaDecoder must be called from the main thread only
|
||||
// with the exception of GetImageContainer, SetVideoData and GetStatistics,
|
||||
@ -236,6 +237,10 @@ public:
|
||||
float aPixelAspectRatio,
|
||||
Image* aImage);
|
||||
|
||||
// Constructs the time ranges representing what segments of the media
|
||||
// are buffered and playable.
|
||||
virtual nsresult GetBuffered(nsHTMLTimeRanges* aBuffered) = 0;
|
||||
|
||||
// Returns PR_TRUE if we can play the entire media through without stopping
|
||||
// to buffer, given the current download and playback rates.
|
||||
PRBool CanPlayThrough();
|
||||
|
@ -1387,4 +1387,7 @@ nsresult nsOggReader::SeekBisection(PRInt64 aTarget,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult nsOggReader::GetBuffered(nsHTMLTimeRanges* aBuffered)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -46,6 +46,7 @@
|
||||
#include "nsOggCodecState.h"
|
||||
|
||||
class nsMediaDecoder;
|
||||
class nsHTMLTimeRanges;
|
||||
|
||||
class nsOggReader : public nsBuiltinDecoderReader
|
||||
{
|
||||
@ -81,6 +82,9 @@ public:
|
||||
virtual nsresult ReadMetadata();
|
||||
virtual nsresult Seek(PRInt64 aTime, PRInt64 aStartTime, PRInt64 aEndTime);
|
||||
|
||||
// This is called on the main thread, and it must not block.
|
||||
virtual nsresult GetBuffered(nsHTMLTimeRanges* aBuffered);
|
||||
|
||||
private:
|
||||
// Decodes one packet of Vorbis data, storing the resulting chunks of
|
||||
// PCM samples in aChunks.
|
||||
|
@ -49,6 +49,7 @@
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsWaveDecoder.h"
|
||||
#include "nsHTMLTimeRanges.h"
|
||||
|
||||
using mozilla::TimeDuration;
|
||||
using mozilla::TimeStamp;
|
||||
@ -1653,3 +1654,9 @@ nsWaveDecoder::MoveLoadsToBackground()
|
||||
mStream->MoveLoadsToBackground();
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsWaveDecoder::GetBuffered(nsHTMLTimeRanges* aBuffered)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -134,6 +134,7 @@
|
||||
*/
|
||||
|
||||
class nsWaveStateMachine;
|
||||
class nsHTMLTimeRanges;
|
||||
|
||||
class nsWaveDecoder : public nsMediaDecoder
|
||||
{
|
||||
@ -236,6 +237,10 @@ class nsWaveDecoder : public nsMediaDecoder
|
||||
// Called asynchronously to shut down the decoder
|
||||
void Stop();
|
||||
|
||||
// Constructs the time ranges representing what segments of the media
|
||||
// are buffered and playable.
|
||||
virtual nsresult GetBuffered(nsHTMLTimeRanges* aBuffered);
|
||||
|
||||
private:
|
||||
// Notifies the element that seeking has started.
|
||||
void SeekingStarted();
|
||||
|
@ -305,6 +305,7 @@
|
||||
#include "nsIDOMHTMLTitleElement.h"
|
||||
#include "nsIDOMHTMLUListElement.h"
|
||||
#include "nsIDOMHTMLMediaError.h"
|
||||
#include "nsIDOMHTMLTimeRanges.h"
|
||||
#include "nsIDOMHTMLSourceElement.h"
|
||||
#include "nsIDOMHTMLVideoElement.h"
|
||||
#include "nsIDOMHTMLAudioElement.h"
|
||||
@ -1355,6 +1356,8 @@ static nsDOMClassInfoData sClassInfoData[] = {
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CLASSINFO_DATA(HTMLAudioElement, nsElementSH,
|
||||
ELEMENT_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CLASSINFO_DATA(HTMLTimeRanges, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
#endif
|
||||
|
||||
NS_DEFINE_CLASSINFO_DATA(ProgressEvent, nsDOMGenericSH,
|
||||
@ -3845,6 +3848,11 @@ nsDOMClassInfo::Init()
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMHTMLAudioElement)
|
||||
DOM_CLASSINFO_GENERIC_HTML_MAP_ENTRIES
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN(HTMLTimeRanges, nsIDOMHTMLTimeRanges)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMHTMLTimeRanges)
|
||||
DOM_CLASSINFO_EVENT_MAP_ENTRIES
|
||||
DOM_CLASSINFO_MAP_END
|
||||
#endif
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN(ProgressEvent, nsIDOMProgressEvent)
|
||||
|
@ -433,6 +433,7 @@ DOMCI_CLASS(HTMLVideoElement)
|
||||
DOMCI_CLASS(HTMLSourceElement)
|
||||
DOMCI_CLASS(HTMLMediaError)
|
||||
DOMCI_CLASS(HTMLAudioElement)
|
||||
DOMCI_CLASS(HTMLTimeRanges)
|
||||
#endif
|
||||
|
||||
DOMCI_CLASS(ProgressEvent)
|
||||
|
@ -38,6 +38,7 @@
|
||||
|
||||
#include "nsIDOMHTMLElement.idl"
|
||||
#include "nsIDOMHTMLMediaError.idl"
|
||||
#include "nsIDOMHTMLTimeRanges.idl"
|
||||
|
||||
/**
|
||||
* The nsIDOMHTMLMediaElement interface is an interface to be implemented by the HTML
|
||||
@ -56,7 +57,7 @@
|
||||
#endif
|
||||
%}
|
||||
|
||||
[scriptable, uuid(505b523e-4a27-4151-b0eb-750b7258760e)]
|
||||
[scriptable, uuid(b6c9f51d-237c-44d1-842d-996f4d62c843)]
|
||||
interface nsIDOMHTMLMediaElement : nsIDOMHTMLElement
|
||||
{
|
||||
// error state
|
||||
@ -71,6 +72,7 @@ interface nsIDOMHTMLMediaElement : nsIDOMHTMLElement
|
||||
const unsigned short NETWORK_LOADED = 3;
|
||||
const unsigned short NETWORK_NO_SOURCE = 4;
|
||||
readonly attribute unsigned short networkState;
|
||||
readonly attribute nsIDOMHTMLTimeRanges buffered;
|
||||
void load();
|
||||
DOMString canPlayType(in DOMString type);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user