|
|
|
|
| 122 |
} |
122 |
} |
| 123 |
private: |
123 |
private: |
| 124 |
PRInt64 mAccumulatedBytes; |
124 |
PRInt64 mAccumulatedBytes; |
| 125 |
TimeDuration mAccumulatedTime; |
125 |
TimeDuration mAccumulatedTime; |
| 126 |
TimeStamp mLastStartTime; |
126 |
TimeStamp mLastStartTime; |
| 127 |
PRPackedBool mIsStarted; |
127 |
PRPackedBool mIsStarted; |
| 128 |
}; |
128 |
}; |
| 129 |
|
129 |
|
|
|
130 |
// Represents a section of contiguous media, with a start and end offset. |
| 131 |
// Used to denote ranges of data which are cached. |
| 132 |
class nsByteRange { |
| 133 |
public: |
| 134 |
nsByteRange() : mStart(0), mEnd(0) {} |
| 135 |
|
| 136 |
nsByteRange(PRInt64 aStart, PRInt64 aEnd) |
| 137 |
: mStart(aStart), mEnd(aEnd) |
| 138 |
{ |
| 139 |
NS_ASSERTION(mStart < mEnd, "Range should end after start!"); |
| 140 |
} |
| 141 |
|
| 142 |
PRBool IsNull() const { |
| 143 |
return mStart == 0 && mEnd == 0; |
| 144 |
} |
| 145 |
|
| 146 |
PRInt64 mStart, mEnd; |
| 147 |
}; |
| 148 |
|
| 130 |
/* |
149 |
/* |
| 131 |
Provides the ability to open, read and seek into a media stream |
150 |
Provides the ability to open, read and seek into a media stream |
| 132 |
(audio, video). Handles the underlying machinery to do range |
151 |
(audio, video). Handles the underlying machinery to do range |
| 133 |
requests, etc as needed by the actual stream type. Instances of |
152 |
requests, etc as needed by the actual stream type. Instances of |
| 134 |
this class must be created on the main thread. |
153 |
this class must be created on the main thread. |
| 135 |
|
154 |
|
| 136 |
Most methods must be called on the main thread only. Read, Seek and |
155 |
Most methods must be called on the main thread only. Read, Seek and |
| 137 |
Tell must only be called on non-main threads. In the case of the Ogg |
156 |
Tell must only be called on non-main threads. In the case of the Ogg |
|
|
| 270 |
static nsMediaStream* Create(nsMediaDecoder* aDecoder, nsIChannel* aChannel); |
289 |
static nsMediaStream* Create(nsMediaDecoder* aDecoder, nsIChannel* aChannel); |
| 271 |
|
290 |
|
| 272 |
/** |
291 |
/** |
| 273 |
* Open the stream. This creates a stream listener and returns it in |
292 |
* Open the stream. This creates a stream listener and returns it in |
| 274 |
* aStreamListener; this listener needs to be notified of incoming data. |
293 |
* aStreamListener; this listener needs to be notified of incoming data. |
| 275 |
*/ |
294 |
*/ |
| 276 |
virtual nsresult Open(nsIStreamListener** aStreamListener) = 0; |
295 |
virtual nsresult Open(nsIStreamListener** aStreamListener) = 0; |
| 277 |
|
296 |
|
|
|
297 |
/** |
| 298 |
* Fills aRanges with ByteRanges representing the data which is cached |
| 299 |
* in the media cache. Stream should be pinned during call and while |
| 300 |
* aRanges is being used. |
| 301 |
*/ |
| 302 |
virtual nsresult GetCachedRanges(nsTArray<nsByteRange>& aRanges) = 0; |
| 303 |
|
| 278 |
protected: |
304 |
protected: |
| 279 |
nsMediaStream(nsMediaDecoder* aDecoder, nsIChannel* aChannel, nsIURI* aURI) : |
305 |
nsMediaStream(nsMediaDecoder* aDecoder, nsIChannel* aChannel, nsIURI* aURI) : |
| 280 |
mDecoder(aDecoder), |
306 |
mDecoder(aDecoder), |
| 281 |
mChannel(aChannel), |
307 |
mChannel(aChannel), |
| 282 |
mURI(aURI), |
308 |
mURI(aURI), |
| 283 |
mLoadInBackground(PR_FALSE) |
309 |
mLoadInBackground(PR_FALSE) |
| 284 |
{ |
310 |
{ |
| 285 |
MOZ_COUNT_CTOR(nsMediaStream); |
311 |
MOZ_COUNT_CTOR(nsMediaStream); |
|
|
| 390 |
|
416 |
|
| 391 |
void Revoke() { mStream = nsnull; } |
417 |
void Revoke() { mStream = nsnull; } |
| 392 |
|
418 |
|
| 393 |
private: |
419 |
private: |
| 394 |
nsMediaChannelStream* mStream; |
420 |
nsMediaChannelStream* mStream; |
| 395 |
}; |
421 |
}; |
| 396 |
friend class Listener; |
422 |
friend class Listener; |
| 397 |
|
423 |
|
|
|
424 |
nsresult GetCachedRanges(nsTArray<nsByteRange>& aRanges); |
| 425 |
|
| 398 |
protected: |
426 |
protected: |
| 399 |
// These are called on the main thread by Listener. |
427 |
// These are called on the main thread by Listener. |
| 400 |
nsresult OnStartRequest(nsIRequest* aRequest); |
428 |
nsresult OnStartRequest(nsIRequest* aRequest); |
| 401 |
nsresult OnStopRequest(nsIRequest* aRequest, nsresult aStatus); |
429 |
nsresult OnStopRequest(nsIRequest* aRequest, nsresult aStatus); |
| 402 |
nsresult OnDataAvailable(nsIRequest* aRequest, |
430 |
nsresult OnDataAvailable(nsIRequest* aRequest, |
| 403 |
nsIInputStream* aStream, |
431 |
nsIInputStream* aStream, |
| 404 |
PRUint32 aCount); |
432 |
PRUint32 aCount); |
| 405 |
nsresult OnChannelRedirect(nsIChannel* aOld, nsIChannel* aNew, PRUint32 aFlags); |
433 |
nsresult OnChannelRedirect(nsIChannel* aOld, nsIChannel* aNew, PRUint32 aFlags); |