1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
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 #include "MediaDataDecoderProxy.h"
8
9 namespace mozilla {
10
Init()11 RefPtr<MediaDataDecoder::InitPromise> MediaDataDecoderProxy::Init() {
12 MOZ_ASSERT(!mIsShutdown);
13
14 if (!mProxyThread) {
15 return mProxyDecoder->Init();
16 }
17 RefPtr<MediaDataDecoderProxy> self = this;
18 return InvokeAsync(mProxyThread, __func__,
19 [self]() { return self->mProxyDecoder->Init(); });
20 }
21
Decode(MediaRawData * aSample)22 RefPtr<MediaDataDecoder::DecodePromise> MediaDataDecoderProxy::Decode(
23 MediaRawData* aSample) {
24 MOZ_ASSERT(!mIsShutdown);
25
26 if (!mProxyThread) {
27 return mProxyDecoder->Decode(aSample);
28 }
29 RefPtr<MediaDataDecoderProxy> self = this;
30 RefPtr<MediaRawData> sample = aSample;
31 return InvokeAsync(mProxyThread, __func__, [self, sample]() {
32 return self->mProxyDecoder->Decode(sample);
33 });
34 }
35
Flush()36 RefPtr<MediaDataDecoder::FlushPromise> MediaDataDecoderProxy::Flush() {
37 MOZ_ASSERT(!mIsShutdown);
38
39 if (!mProxyThread) {
40 return mProxyDecoder->Flush();
41 }
42 RefPtr<MediaDataDecoderProxy> self = this;
43 return InvokeAsync(mProxyThread, __func__,
44 [self]() { return self->mProxyDecoder->Flush(); });
45 }
46
Drain()47 RefPtr<MediaDataDecoder::DecodePromise> MediaDataDecoderProxy::Drain() {
48 MOZ_ASSERT(!mIsShutdown);
49
50 if (!mProxyThread) {
51 return mProxyDecoder->Drain();
52 }
53 RefPtr<MediaDataDecoderProxy> self = this;
54 return InvokeAsync(mProxyThread, __func__,
55 [self]() { return self->mProxyDecoder->Drain(); });
56 }
57
Shutdown()58 RefPtr<ShutdownPromise> MediaDataDecoderProxy::Shutdown() {
59 MOZ_ASSERT(!mIsShutdown);
60
61 #if defined(DEBUG)
62 mIsShutdown = true;
63 #endif
64
65 if (!mProxyThread) {
66 return mProxyDecoder->Shutdown();
67 }
68 RefPtr<MediaDataDecoderProxy> self = this;
69 return InvokeAsync(mProxyThread, __func__,
70 [self]() { return self->mProxyDecoder->Shutdown(); });
71 }
72
GetDescriptionName() const73 nsCString MediaDataDecoderProxy::GetDescriptionName() const {
74 MOZ_ASSERT(!mIsShutdown);
75
76 return mProxyDecoder->GetDescriptionName();
77 }
78
IsHardwareAccelerated(nsACString & aFailureReason) const79 bool MediaDataDecoderProxy::IsHardwareAccelerated(
80 nsACString& aFailureReason) const {
81 MOZ_ASSERT(!mIsShutdown);
82
83 return mProxyDecoder->IsHardwareAccelerated(aFailureReason);
84 }
85
SetSeekThreshold(const media::TimeUnit & aTime)86 void MediaDataDecoderProxy::SetSeekThreshold(const media::TimeUnit& aTime) {
87 MOZ_ASSERT(!mIsShutdown);
88
89 if (!mProxyThread) {
90 mProxyDecoder->SetSeekThreshold(aTime);
91 return;
92 }
93 RefPtr<MediaDataDecoderProxy> self = this;
94 media::TimeUnit time = aTime;
95 mProxyThread->Dispatch(NS_NewRunnableFunction(
96 "MediaDataDecoderProxy::SetSeekThreshold",
97 [self, time] { self->mProxyDecoder->SetSeekThreshold(time); }));
98 }
99
SupportDecoderRecycling() const100 bool MediaDataDecoderProxy::SupportDecoderRecycling() const {
101 MOZ_ASSERT(!mIsShutdown);
102
103 return mProxyDecoder->SupportDecoderRecycling();
104 }
105
NeedsConversion() const106 MediaDataDecoder::ConversionRequired MediaDataDecoderProxy::NeedsConversion()
107 const {
108 MOZ_ASSERT(!mIsShutdown);
109
110 return mProxyDecoder->NeedsConversion();
111 }
112
113 } // namespace mozilla
114