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(AudioSinkInputPin_h_)
8 #define AudioSinkInputPin_h_
9 
10 #include "BaseInputPin.h"
11 #include "DirectShowUtils.h"
12 #include "mozilla/RefPtr.h"
13 #include "nsAutoPtr.h"
14 
15 namespace mozilla {
16 
17 namespace media {
18   class MediaType;
19 }
20 
21 class AudioSinkFilter;
22 class SampleSink;
23 
24 
25 // Input pin for capturing audio output of a DirectShow filter graph.
26 // This is the input pin for the AudioSinkFilter.
27 class AudioSinkInputPin: public mozilla::media::BaseInputPin
28 {
29 public:
30   AudioSinkInputPin(wchar_t* aObjectName,
31                     AudioSinkFilter* aFilter,
32                     mozilla::CriticalSection* aLock,
33                     HRESULT* aOutResult);
34   virtual ~AudioSinkInputPin();
35 
36   HRESULT GetMediaType (IN int iPos, OUT mozilla::media::MediaType * pmt);
37   HRESULT CheckMediaType (IN const mozilla::media::MediaType * pmt);
38   STDMETHODIMP Receive (IN IMediaSample *);
39   STDMETHODIMP BeginFlush() override;
40   STDMETHODIMP EndFlush() override;
41 
42   // Called when we start decoding a new segment, that happens directly after
43   // a seek. This captures the segment's start time. Samples decoded by the
44   // MP3 decoder have their timestamps offset from the segment start time.
45   // Storing the segment start time enables us to set each sample's MediaTime
46   // as an offset in the stream relative to the start of the stream, rather
47   // than the start of the segment, i.e. its absolute time in the stream.
48   STDMETHODIMP NewSegment(REFERENCE_TIME tStart,
49                           REFERENCE_TIME tStop,
50                           double dRate) override;
51 
52   STDMETHODIMP EndOfStream() override;
53 
54   // Returns the IMediaSeeking interface of the connected output pin.
55   // We forward seeking requests upstream from the sink to the source
56   // filters.
57   already_AddRefed<IMediaSeeking> GetConnectedPinSeeking();
58 
59   SampleSink* GetSampleSink();
60 
61 private:
62   AudioSinkFilter* GetAudioSinkFilter();
63 
64   // Sets the media time on the media sample, relative to the segment
65   // start time.
66   HRESULT SetAbsoluteMediaTime(IMediaSample* aSample);
67 
68   nsAutoPtr<SampleSink> mSampleSink;
69 
70   // Synchronized by the filter lock; BaseInputPin::mLock.
71   REFERENCE_TIME mSegmentStartTime;
72 };
73 
74 } // namespace mozilla
75 
76 #endif // AudioSinkInputPin_h_
77