Line data Source code
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 ChannelMediaDecoder_h_
8 : #define ChannelMediaDecoder_h_
9 :
10 : #include "MediaDecoder.h"
11 : #include "MediaResourceCallback.h"
12 :
13 : class nsIChannel;
14 : class nsIStreamListener;
15 :
16 : namespace mozilla {
17 :
18 0 : class ChannelMediaDecoder : public MediaDecoder
19 : {
20 : // Used to register with MediaResource to receive notifications which will
21 : // be forwarded to MediaDecoder.
22 0 : class ResourceCallback : public MediaResourceCallback
23 : {
24 : // Throttle calls to MediaDecoder::NotifyDataArrived()
25 : // to be at most once per 500ms.
26 : static const uint32_t sDelay = 500;
27 :
28 : public:
29 : explicit ResourceCallback(AbstractThread* aMainThread);
30 : // Start to receive notifications from ResourceCallback.
31 : void Connect(ChannelMediaDecoder* aDecoder);
32 : // Called upon shutdown to stop receiving notifications.
33 : void Disconnect();
34 :
35 : private:
36 : /* MediaResourceCallback functions */
37 : MediaDecoderOwner* GetMediaOwner() const override;
38 : void SetInfinite(bool aInfinite) override;
39 : void NotifyNetworkError() override;
40 : void NotifyDataArrived() override;
41 : void NotifyDataEnded(nsresult aStatus) override;
42 : void NotifyPrincipalChanged() override;
43 : void NotifySuspendedStatusChanged() override;
44 : void NotifyBytesConsumed(int64_t aBytes, int64_t aOffset) override;
45 :
46 : static void TimerCallback(nsITimer* aTimer, void* aClosure);
47 :
48 : // The decoder to send notifications. Main-thread only.
49 : ChannelMediaDecoder* mDecoder = nullptr;
50 : nsCOMPtr<nsITimer> mTimer;
51 : bool mTimerArmed = false;
52 : const RefPtr<AbstractThread> mAbstractMainThread;
53 : };
54 :
55 : protected:
56 : RefPtr<ResourceCallback> mResourceCallback;
57 :
58 : public:
59 : explicit ChannelMediaDecoder(MediaDecoderInit& aInit);
60 :
61 : void Shutdown() override;
62 :
63 : // Create a new decoder of the same type as this one.
64 : // Subclasses must implement this.
65 : virtual ChannelMediaDecoder* Clone(MediaDecoderInit& aInit) = 0;
66 :
67 : virtual nsresult Load(nsIChannel* aChannel,
68 : bool aIsPrivateBrowsing,
69 : nsIStreamListener** aStreamListener);
70 : virtual nsresult Load(MediaResource* aOriginal);
71 :
72 : private:
73 : nsresult OpenResource(nsIStreamListener** aStreamListener);
74 : };
75 :
76 : } // namespace mozilla
77 :
78 : #endif // ChannelMediaDecoder_h_
|