1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=99: */
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 #ifndef include_dom_ipc_VideoDecoderParent_h
7 #define include_dom_ipc_VideoDecoderParent_h
8 
9 #include "ImageContainer.h"
10 #include "MediaData.h"
11 #include "PlatformDecoderModule.h"
12 #include "VideoDecoderManagerParent.h"
13 #include "mozilla/MozPromise.h"
14 #include "mozilla/dom/PVideoDecoderParent.h"
15 #include "mozilla/layers/TextureForwarder.h"
16 
17 namespace mozilla {
18 namespace dom {
19 
20 class KnowsCompositorVideo;
21 
22 class VideoDecoderParent final : public PVideoDecoderParent {
23  public:
24   // We refcount this class since the task queue can have runnables
25   // that reference us.
26   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VideoDecoderParent)
27 
28   VideoDecoderParent(VideoDecoderManagerParent* aParent,
29                      const VideoInfo& aVideoInfo, float aFramerate,
30                      const layers::TextureFactoryIdentifier& aIdentifier,
31                      TaskQueue* aManagerTaskQueue, TaskQueue* aDecodeTaskQueue,
32                      bool* aSuccess, nsCString* aErrorDescription);
33 
34   void Destroy();
35 
36   // PVideoDecoderParent
37   mozilla::ipc::IPCResult RecvInit() override;
38   mozilla::ipc::IPCResult RecvInput(const MediaRawDataIPDL& aData) override;
39   mozilla::ipc::IPCResult RecvFlush() override;
40   mozilla::ipc::IPCResult RecvDrain() override;
41   mozilla::ipc::IPCResult RecvShutdown() override;
42   mozilla::ipc::IPCResult RecvSetSeekThreshold(const int64_t& aTime) override;
43 
44   void ActorDestroy(ActorDestroyReason aWhy) override;
45 
46  private:
47   bool OnManagerThread();
48   void Error(const MediaResult& aError);
49 
50   ~VideoDecoderParent();
51   void ProcessDecodedData(const MediaDataDecoder::DecodedData& aData);
52 
53   RefPtr<VideoDecoderManagerParent> mParent;
54   RefPtr<VideoDecoderParent> mIPDLSelfRef;
55   RefPtr<TaskQueue> mManagerTaskQueue;
56   RefPtr<TaskQueue> mDecodeTaskQueue;
57   RefPtr<MediaDataDecoder> mDecoder;
58   RefPtr<KnowsCompositorVideo> mKnowsCompositor;
59 
60   // Can only be accessed from the manager thread
61   bool mDestroyed;
62 };
63 
64 }  // namespace dom
65 }  // namespace mozilla
66 
67 #endif  // include_dom_ipc_VideoDecoderParent_h
68