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 MediaResourceCallback_h_
8 #define MediaResourceCallback_h_
9 
10 #include "DecoderDoctorLogger.h"
11 #include "nsError.h"
12 #include "nsISupportsImpl.h"
13 #include "MediaResult.h"
14 
15 namespace mozilla {
16 
17 class AbstractThread;
18 class MediaDecoderOwner;
19 class MediaResource;
20 
21 DDLoggedTypeDeclName(MediaResourceCallback);
22 
23 /**
24  * A callback used by MediaResource (sub-classes like FileMediaResource,
25  * RtspMediaResource, and ChannelMediaResource) to notify various events.
26  * Currently this is implemented by MediaDecoder only.
27  *
28  * Since this class has no pure virtual function, it is convenient to write
29  * gtests for the readers without using a mock MediaResource when you don't
30  * care about the events notified by the MediaResource.
31  */
32 class MediaResourceCallback
33     : public DecoderDoctorLifeLogger<MediaResourceCallback> {
34  public:
35   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaResourceCallback);
36 
37   // Return an abstract thread on which to run main thread runnables.
AbstractMainThread()38   virtual AbstractThread* AbstractMainThread() const { return nullptr; }
39 
40   // Returns a weak reference to the media decoder owner.
GetMediaOwner()41   virtual MediaDecoderOwner* GetMediaOwner() const { return nullptr; }
42 
43   // Notify that a network error is encountered.
NotifyNetworkError(const MediaResult & aError)44   virtual void NotifyNetworkError(const MediaResult& aError) {}
45 
46   // Notify that data arrives on the stream and is read into the cache.
NotifyDataArrived()47   virtual void NotifyDataArrived() {}
48 
49   // Notify download is ended.
50   // NOTE: this can be called with the media cache lock held, so don't
51   // block or do anything which might try to acquire a lock!
NotifyDataEnded(nsresult aStatus)52   virtual void NotifyDataEnded(nsresult aStatus) {}
53 
54   // Notify that the principal of MediaResource has changed.
NotifyPrincipalChanged()55   virtual void NotifyPrincipalChanged() {}
56 
57   // Notify that the "cache suspended" status of MediaResource changes.
NotifySuspendedStatusChanged(bool aSuspendedByCache)58   virtual void NotifySuspendedStatusChanged(bool aSuspendedByCache) {}
59 
60  protected:
61   virtual ~MediaResourceCallback() = default;
62 };
63 
64 }  // namespace mozilla
65 
66 #endif  // MediaResourceCallback_h_
67