/usr/include/thunderbird/MediaDataDecoderProxy.h is in thunderbird-dev 1:38.6.0+build1-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#if !defined(MediaDataDecoderProxy_h_)
#define MediaDataDecoderProxy_h_
#include "PlatformDecoderModule.h"
#include "mp4_demuxer/DecoderData.h"
#include "nsAutoPtr.h"
#include "nsRefPtr.h"
#include "nsThreadUtils.h"
#include "nscore.h"
namespace mozilla {
class InputTask : public nsRunnable {
public:
InputTask(MediaDataDecoder* aDecoder,
mp4_demuxer::MP4Sample* aSample)
: mDecoder(aDecoder)
, mSample(aSample)
{}
NS_IMETHOD Run() {
mDecoder->Input(mSample.forget());
return NS_OK;
}
private:
nsRefPtr<MediaDataDecoder> mDecoder;
nsAutoPtr<mp4_demuxer::MP4Sample> mSample;
};
class InitTask : public nsRunnable {
public:
explicit InitTask(MediaDataDecoder* aDecoder)
: mDecoder(aDecoder)
, mResultValid(false)
{}
NS_IMETHOD Run() {
mResult = mDecoder->Init();
mResultValid = true;
return NS_OK;
}
nsresult Result() {
MOZ_ASSERT(mResultValid);
return mResult;
}
private:
MediaDataDecoder* mDecoder;
nsresult mResult;
bool mResultValid;
};
template<typename T>
class Condition {
public:
explicit Condition(T aValue)
: mMonitor("Condition")
, mCondition(aValue)
{}
void Set(T aValue) {
MonitorAutoLock mon(mMonitor);
mCondition = aValue;
mon.NotifyAll();
}
void WaitUntil(T aValue) {
MonitorAutoLock mon(mMonitor);
while (mCondition != aValue) {
mon.Wait();
}
}
private:
Monitor mMonitor;
T mCondition;
};
class MediaDataDecoderProxy;
class MediaDataDecoderCallbackProxy : public MediaDataDecoderCallback {
public:
explicit MediaDataDecoderCallbackProxy(MediaDataDecoderProxy* aProxyDecoder, MediaDataDecoderCallback* aCallback)
: mProxyDecoder(aProxyDecoder)
, mProxyCallback(aCallback)
{
}
virtual void Output(MediaData* aData) override {
mProxyCallback->Output(aData);
}
virtual void Error() override;
virtual void InputExhausted() override {
mProxyCallback->InputExhausted();
}
virtual void DrainComplete() override {
mProxyCallback->DrainComplete();
}
virtual void NotifyResourcesStatusChanged() override {
mProxyCallback->NotifyResourcesStatusChanged();
}
virtual void ReleaseMediaResources() override {
mProxyCallback->ReleaseMediaResources();
}
virtual void FlushComplete();
private:
MediaDataDecoderProxy* mProxyDecoder;
MediaDataDecoderCallback* mProxyCallback;
};
class MediaDataDecoderProxy : public MediaDataDecoder {
public:
MediaDataDecoderProxy(nsIThread* aProxyThread, MediaDataDecoderCallback* aCallback)
: mProxyThread(aProxyThread)
, mProxyCallback(this, aCallback)
, mFlushComplete(false)
#if defined(DEBUG)
, mIsShutdown(false)
#endif
{
}
// Ideally, this would return a regular MediaDataDecoderCallback pointer
// to retain the clean abstraction, but until MediaDataDecoderCallback
// supports the FlushComplete interface, this will have to do. When MDDC
// supports FlushComplete, this, the GMP*Decoders, and the
// *CallbackAdapters can be reverted to accepting a regular
// MediaDataDecoderCallback pointer.
MediaDataDecoderCallbackProxy* Callback()
{
return &mProxyCallback;
}
void SetProxyTarget(MediaDataDecoder* aProxyDecoder)
{
MOZ_ASSERT(aProxyDecoder);
mProxyDecoder = aProxyDecoder;
}
// These are called from the decoder thread pool.
// Init and Shutdown run synchronously on the proxy thread, all others are
// asynchronously and responded to via the MediaDataDecoderCallback.
// Note: the nsresults returned by the proxied decoder are lost.
virtual nsresult Init() override;
virtual nsresult Input(mp4_demuxer::MP4Sample* aSample) override;
virtual nsresult Flush() override;
virtual nsresult Drain() override;
virtual nsresult Shutdown() override;
// Called by MediaDataDecoderCallbackProxy.
void FlushComplete();
private:
#ifdef DEBUG
bool IsOnProxyThread() {
return NS_GetCurrentThread() == mProxyThread;
}
#endif
friend class InputTask;
friend class InitTask;
nsRefPtr<MediaDataDecoder> mProxyDecoder;
nsCOMPtr<nsIThread> mProxyThread;
MediaDataDecoderCallbackProxy mProxyCallback;
Condition<bool> mFlushComplete;
#if defined(DEBUG)
bool mIsShutdown;
#endif
};
} // namespace mozilla
#endif // MediaDataDecoderProxy_h_
|