|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef MOZILLA_SUBBUFFERDECODER_H_ |
|
8 #define MOZILLA_SUBBUFFERDECODER_H_ |
|
9 |
|
10 #include "BufferDecoder.h" |
|
11 #include "SourceBufferResource.h" |
|
12 |
|
13 namespace mozilla { |
|
14 |
|
15 class MediaSourceDecoder; |
|
16 |
|
17 class SubBufferDecoder : public BufferDecoder |
|
18 { |
|
19 public: |
|
20 // This class holds a weak pointer to MediaResource. It's the responsibility |
|
21 // of the caller to manage the memory of the MediaResource object. |
|
22 SubBufferDecoder(MediaResource* aResource, MediaSourceDecoder* aParentDecoder) |
|
23 : BufferDecoder(aResource), mParentDecoder(aParentDecoder), mReader(nullptr) |
|
24 { |
|
25 } |
|
26 |
|
27 void SetReader(MediaDecoderReader* aReader) |
|
28 { |
|
29 MOZ_ASSERT(!mReader); |
|
30 mReader = aReader; |
|
31 } |
|
32 |
|
33 MediaDecoderReader* GetReader() |
|
34 { |
|
35 return mReader; |
|
36 } |
|
37 |
|
38 virtual ReentrantMonitor& GetReentrantMonitor() MOZ_OVERRIDE; |
|
39 virtual bool OnStateMachineThread() const MOZ_OVERRIDE; |
|
40 virtual bool OnDecodeThread() const MOZ_OVERRIDE; |
|
41 virtual SourceBufferResource* GetResource() const MOZ_OVERRIDE; |
|
42 virtual void SetMediaDuration(int64_t aDuration) MOZ_OVERRIDE; |
|
43 virtual void UpdateEstimatedMediaDuration(int64_t aDuration) MOZ_OVERRIDE; |
|
44 virtual void SetMediaSeekable(bool aMediaSeekable) MOZ_OVERRIDE; |
|
45 virtual void SetTransportSeekable(bool aTransportSeekable) MOZ_OVERRIDE; |
|
46 virtual layers::ImageContainer* GetImageContainer() MOZ_OVERRIDE; |
|
47 virtual MediaDecoderOwner* GetOwner() MOZ_OVERRIDE; |
|
48 |
|
49 void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset) |
|
50 { |
|
51 mReader->NotifyDataArrived(aBuffer, aLength, aOffset); |
|
52 |
|
53 // XXX: Params make no sense to parent decoder as it relates to a |
|
54 // specific SubBufferDecoder's data stream. Pass bogus values here to |
|
55 // force parent decoder's state machine to recompute end time for |
|
56 // infinite length media. |
|
57 mParentDecoder->NotifyDataArrived(nullptr, 0, 0); |
|
58 } |
|
59 |
|
60 nsresult GetBuffered(dom::TimeRanges* aBuffered) |
|
61 { |
|
62 // XXX: Need mStartTime (from StateMachine) instead of passing 0. |
|
63 return mReader->GetBuffered(aBuffered, 0); |
|
64 } |
|
65 |
|
66 // Given a time convert it into an approximate byte offset from the |
|
67 // cached data. Returns -1 if no such value is computable. |
|
68 int64_t ConvertToByteOffset(double aTime); |
|
69 |
|
70 int64_t GetMediaDuration() MOZ_OVERRIDE |
|
71 { |
|
72 return mMediaDuration; |
|
73 } |
|
74 |
|
75 private: |
|
76 MediaSourceDecoder* mParentDecoder; |
|
77 nsAutoPtr<MediaDecoderReader> mReader; |
|
78 int64_t mMediaDuration; |
|
79 }; |
|
80 |
|
81 } // namespace mozilla |
|
82 |
|
83 #endif /* MOZILLA_SUBBUFFERDECODER_H_ */ |