1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/directshow/SampleSink.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,67 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#if !defined(SampleSink_h_) 1.11 +#define SampleSink_h_ 1.12 + 1.13 +#include "BaseFilter.h" 1.14 +#include "DirectShowUtils.h" 1.15 +#include "nsAutoPtr.h" 1.16 +#include "mozilla/RefPtr.h" 1.17 +#include "mozilla/ReentrantMonitor.h" 1.18 + 1.19 +namespace mozilla { 1.20 + 1.21 +class SampleSink { 1.22 +public: 1.23 + SampleSink(); 1.24 + virtual ~SampleSink(); 1.25 + 1.26 + // Sets the audio format of the incoming samples. The upstream filter 1.27 + // calls this. This makes a copy. 1.28 + void SetAudioFormat(const WAVEFORMATEX* aInFormat); 1.29 + 1.30 + // Copies the format of incoming audio samples into into *aOutFormat. 1.31 + void GetAudioFormat(WAVEFORMATEX* aOutFormat); 1.32 + 1.33 + // Called when a sample is delivered by the DirectShow graph to the sink. 1.34 + // The decode thread retrieves the sample by calling WaitForSample(). 1.35 + // Blocks if there's already a sample waiting to be consumed by the decode 1.36 + // thread. 1.37 + HRESULT Receive(IMediaSample* aSample); 1.38 + 1.39 + // Retrieves a sample from the sample queue, blocking until one becomes 1.40 + // available, or until an error occurs. Returns S_FALSE on EOS. 1.41 + HRESULT Extract(RefPtr<IMediaSample>& aOutSample); 1.42 + 1.43 + // Unblocks any threads waiting in GetSample(). 1.44 + // Clears mSample, which unblocks upstream stream. 1.45 + void Flush(); 1.46 + 1.47 + // Opens up the sink to receive more samples in PutSample(). 1.48 + // Clears EOS flag. 1.49 + void Reset(); 1.50 + 1.51 + // Marks that we've reacehd the end of stream. 1.52 + void SetEOS(); 1.53 + 1.54 + // Returns whether we're at end of stream. 1.55 + bool AtEOS(); 1.56 + 1.57 +private: 1.58 + // All data in this class is syncronized by mMonitor. 1.59 + ReentrantMonitor mMonitor; 1.60 + RefPtr<IMediaSample> mSample; 1.61 + 1.62 + // Format of the audio stream we're receiving. 1.63 + WAVEFORMATEX mAudioFormat; 1.64 + 1.65 + bool mIsFlushing; 1.66 + bool mAtEOS; 1.67 +}; 1.68 + 1.69 +} // namespace mozilla 1.70 +#endif // SampleSink_h_