content/media/wmf/WMFSourceReaderCallback.h

branch
TOR_BUG_3246
changeset 6
8bccb770b82d
equal deleted inserted replaced
-1:000000000000 0:8f8488bfadcb
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 #if !defined(WMFSourceReaderCallback_h_)
7 #define WMFSourceReaderCallback_h_
8
9 #include "WMF.h"
10 #include "mozilla/ReentrantMonitor.h"
11 #include "mozilla/RefPtr.h"
12 #include "nsISupportsImpl.h"
13
14 namespace mozilla {
15
16 // A listener which we pass into the IMFSourceReader upon creation which is
17 // notified when an asynchronous call to IMFSourceReader::ReadSample()
18 // completes. This allows us to abort ReadSample() operations when the
19 // WMFByteStream's underlying MediaResource is closed. This ensures that
20 // the decode threads don't get stuck in a synchronous ReadSample() call
21 // when the MediaResource is unexpectedly shutdown.
22 class WMFSourceReaderCallback MOZ_FINAL : public IMFSourceReaderCallback
23 {
24 public:
25 WMFSourceReaderCallback();
26
27 // IUnknown Methods.
28 STDMETHODIMP QueryInterface(REFIID aIId, LPVOID *aInterface);
29 STDMETHODIMP_(ULONG) AddRef();
30 STDMETHODIMP_(ULONG) Release();
31
32 // IMFSourceReaderCallback methods
33 STDMETHODIMP OnReadSample(HRESULT hrStatus,
34 DWORD dwStreamIndex,
35 DWORD dwStreamFlags,
36 LONGLONG llTimestamp,
37 IMFSample *pSample);
38 STDMETHODIMP OnEvent(DWORD, IMFMediaEvent *);
39 STDMETHODIMP OnFlush(DWORD);
40
41 // Causes the calling thread to block waiting for the
42 // IMFSourceReader::ReadSample() result callback to occur, or for the
43 // WMFByteStream to be closed.
44 HRESULT Wait(DWORD* aStreamFlags,
45 LONGLONG* aTimeStamp,
46 IMFSample** aSample);
47
48 // Cancels Wait() calls.
49 HRESULT Cancel();
50
51 private:
52
53 // Sets state to record the result of a read, and awake threads
54 // waiting in Wait().
55 HRESULT NotifyReadComplete(HRESULT aReadStatus,
56 DWORD aStreamIndex,
57 DWORD aStreamFlags,
58 LONGLONG aTimestamp,
59 IMFSample *aSample);
60
61 // Synchronizes all member data in this class, and Wait() blocks on
62 // and NotifyReadComplete() notifies this monitor.
63 ReentrantMonitor mMonitor;
64
65 // Read result data.
66 HRESULT mResultStatus;
67 DWORD mStreamFlags;
68 LONGLONG mTimestamp;
69 IMFSample* mSample;
70
71 // Sentinal. Set to true when a read result is returned. Wait() won't exit
72 // until this is set to true.
73 bool mReadFinished;
74
75 // IUnknown ref counting.
76 ThreadSafeAutoRefCnt mRefCnt;
77 NS_DECL_OWNINGTHREAD
78
79 };
80
81 } // namespace mozilla
82
83 #endif // WMFSourceReaderCallback_h_

mercurial