1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4  * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 #ifndef MEDIAENGINEWEBRTC_H_
7 #define MEDIAENGINEWEBRTC_H_
8 
9 #include "AudioDeviceInfo.h"
10 #include "CamerasChild.h"
11 #include "CubebUtils.h"
12 #include "DOMMediaStream.h"
13 #include "MediaEngine.h"
14 #include "MediaEnginePrefs.h"
15 #include "MediaEngineSource.h"
16 #include "MediaEngineWrapper.h"
17 #include "MediaTrackGraph.h"
18 #include "NullTransport.h"
19 #include "VideoSegment.h"
20 #include "VideoUtils.h"
21 #include "CubebDeviceEnumerator.h"
22 #include "ipc/IPCMessageUtils.h"
23 #include "mozilla/Mutex.h"
24 #include "mozilla/Mutex.h"
25 #include "mozilla/Sprintf.h"
26 #include "mozilla/StaticMutex.h"
27 #include "mozilla/UniquePtr.h"
28 #include "mozilla/dom/File.h"
29 #include "mozilla/dom/MediaStreamTrackBinding.h"
30 #include "nsCOMPtr.h"
31 #include "nsComponentManagerUtils.h"
32 #include "nsDirectoryServiceDefs.h"
33 #include "nsRefPtrHashtable.h"
34 #include "nsThreadUtils.h"
35 #include "prcvar.h"
36 #include "prthread.h"
37 
38 // WebRTC library includes follow
39 // Video Engine
40 // conflicts with #include of scoped_ptr.h
41 #undef FF
42 #include "webrtc/modules/video_capture/video_capture_defines.h"
43 
44 namespace mozilla {
45 
46 class MediaEngineWebRTC : public MediaEngine {
47   typedef MediaEngine Super;
48 
49  public:
50   explicit MediaEngineWebRTC(MediaEnginePrefs& aPrefs);
51 
52   // Enable periodic fake "devicechange" event. Must always be called from the
53   // same thread, and must be disabled before shutdown.
54   void SetFakeDeviceChangeEventsEnabled(bool aEnable) override;
55 
56   // Clients should ensure to clean-up sources video/audio sources
57   // before invoking Shutdown on this class.
58   void Shutdown() override;
59 
60   // Returns whether the host supports duplex audio track.
61   bool SupportsDuplex();
62 
63   void EnumerateDevices(uint64_t aWindowId, dom::MediaSourceEnum, MediaSinkEnum,
64                         nsTArray<RefPtr<MediaDevice>>*) override;
65 
DeviceListChangeEvent()66   MediaEventSource<void>& DeviceListChangeEvent() override {
67     return mDeviceListChangeEvent;
68   }
69 
70  private:
71   ~MediaEngineWebRTC() = default;
72   void EnumerateVideoDevices(uint64_t aWindowId,
73                              camera::CaptureEngine aCapEngine,
74                              nsTArray<RefPtr<MediaDevice>>*);
75   void EnumerateMicrophoneDevices(uint64_t aWindowId,
76                                   nsTArray<RefPtr<MediaDevice>>*);
77   void EnumerateSpeakerDevices(uint64_t aWindowId,
78                                nsTArray<RefPtr<MediaDevice>>*);
79 
DeviceListChanged()80   void DeviceListChanged() { mDeviceListChangeEvent.Notify(); }
81 
82   static void FakeDeviceChangeEventTimerTick(nsITimer* aTimer, void* aClosure);
83 
84   const bool mDelayAgnostic;
85   const bool mExtendedFilter;
86   // This also is set in the ctor and then never changed, but we can't make it
87   // const because we pass it to a function that takes bool* in the ctor.
88   bool mHasTabVideoSource;
89   MediaEventListener mCameraListChangeListener;
90   MediaEventListener mMicrophoneListChangeListener;
91   MediaEventListener mSpeakerListChangeListener;
92   MediaEventProducer<void> mDeviceListChangeEvent;
93   nsCOMPtr<nsITimer> mFakeDeviceChangeEventTimer;
94 };
95 
96 }  // namespace mozilla
97 
98 #endif /* NSMEDIAENGINEWEBRTC_H_ */
99