|
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 #if !defined(SampleSink_h_) |
|
8 #define SampleSink_h_ |
|
9 |
|
10 #include "BaseFilter.h" |
|
11 #include "DirectShowUtils.h" |
|
12 #include "nsAutoPtr.h" |
|
13 #include "mozilla/RefPtr.h" |
|
14 #include "mozilla/ReentrantMonitor.h" |
|
15 |
|
16 namespace mozilla { |
|
17 |
|
18 class SampleSink { |
|
19 public: |
|
20 SampleSink(); |
|
21 virtual ~SampleSink(); |
|
22 |
|
23 // Sets the audio format of the incoming samples. The upstream filter |
|
24 // calls this. This makes a copy. |
|
25 void SetAudioFormat(const WAVEFORMATEX* aInFormat); |
|
26 |
|
27 // Copies the format of incoming audio samples into into *aOutFormat. |
|
28 void GetAudioFormat(WAVEFORMATEX* aOutFormat); |
|
29 |
|
30 // Called when a sample is delivered by the DirectShow graph to the sink. |
|
31 // The decode thread retrieves the sample by calling WaitForSample(). |
|
32 // Blocks if there's already a sample waiting to be consumed by the decode |
|
33 // thread. |
|
34 HRESULT Receive(IMediaSample* aSample); |
|
35 |
|
36 // Retrieves a sample from the sample queue, blocking until one becomes |
|
37 // available, or until an error occurs. Returns S_FALSE on EOS. |
|
38 HRESULT Extract(RefPtr<IMediaSample>& aOutSample); |
|
39 |
|
40 // Unblocks any threads waiting in GetSample(). |
|
41 // Clears mSample, which unblocks upstream stream. |
|
42 void Flush(); |
|
43 |
|
44 // Opens up the sink to receive more samples in PutSample(). |
|
45 // Clears EOS flag. |
|
46 void Reset(); |
|
47 |
|
48 // Marks that we've reacehd the end of stream. |
|
49 void SetEOS(); |
|
50 |
|
51 // Returns whether we're at end of stream. |
|
52 bool AtEOS(); |
|
53 |
|
54 private: |
|
55 // All data in this class is syncronized by mMonitor. |
|
56 ReentrantMonitor mMonitor; |
|
57 RefPtr<IMediaSample> mSample; |
|
58 |
|
59 // Format of the audio stream we're receiving. |
|
60 WAVEFORMATEX mAudioFormat; |
|
61 |
|
62 bool mIsFlushing; |
|
63 bool mAtEOS; |
|
64 }; |
|
65 |
|
66 } // namespace mozilla |
|
67 #endif // SampleSink_h_ |