Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set sw=2 ts=8 et ft=cpp : */
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 file,
5 : * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef MEDIAENGINE_REMOTE_VIDEO_SOURCE_H_
8 : #define MEDIAENGINE_REMOTE_VIDEO_SOURCE_H_
9 :
10 : #include "prcvar.h"
11 : #include "prthread.h"
12 : #include "nsIThread.h"
13 : #include "nsIRunnable.h"
14 :
15 : #include "mozilla/Mutex.h"
16 : #include "mozilla/Monitor.h"
17 : #include "nsCOMPtr.h"
18 : #include "nsThreadUtils.h"
19 : #include "DOMMediaStream.h"
20 : #include "nsDirectoryServiceDefs.h"
21 : #include "nsComponentManagerUtils.h"
22 :
23 : // Avoid warnings about redefinition of WARN_UNUSED_RESULT
24 : #include "ipc/IPCMessageUtils.h"
25 : #include "VideoUtils.h"
26 : #include "MediaEngineCameraVideoSource.h"
27 : #include "VideoSegment.h"
28 : #include "AudioSegment.h"
29 : #include "StreamTracks.h"
30 : #include "MediaStreamGraph.h"
31 :
32 : #include "MediaEngineWrapper.h"
33 : #include "mozilla/dom/MediaStreamTrackBinding.h"
34 :
35 : // Camera Access via IPC
36 : #include "CamerasChild.h"
37 :
38 : #include "NullTransport.h"
39 :
40 : namespace mozilla {
41 :
42 : /**
43 : * The WebRTC implementation of the MediaEngine interface.
44 : */
45 : class MediaEngineRemoteVideoSource : public MediaEngineCameraVideoSource,
46 : public camera::FrameRelay
47 : {
48 : typedef MediaEngineCameraVideoSource Super;
49 : public:
50 : NS_DECL_THREADSAFE_ISUPPORTS
51 :
52 : // Old ExternalRenderer
53 : void FrameSizeChange(unsigned int w, unsigned int h) override;
54 : // ExternalRenderer
55 : int DeliverFrame(uint8_t* buffer,
56 : const camera::VideoFrameProperties& properties) override;
57 :
58 : // MediaEngineCameraVideoSource
59 : MediaEngineRemoteVideoSource(int aIndex, mozilla::camera::CaptureEngine aCapEngine,
60 : dom::MediaSourceEnum aMediaSource,
61 : bool aScary = false,
62 : const char* aMonitorName = "RemoteVideo.Monitor");
63 :
64 : nsresult Allocate(const dom::MediaTrackConstraints& aConstraints,
65 : const MediaEnginePrefs& aPrefs,
66 : const nsString& aDeviceId,
67 : const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
68 : AllocationHandle** aOutHandle,
69 : const char** aOutBadConstraint) override;
70 : nsresult Deallocate(AllocationHandle* aHandle) override;
71 : nsresult Start(SourceMediaStream*, TrackID, const PrincipalHandle&) override;
72 : nsresult Stop(SourceMediaStream*, TrackID) override;
73 : nsresult Restart(AllocationHandle* aHandle,
74 : const dom::MediaTrackConstraints& aConstraints,
75 : const MediaEnginePrefs &aPrefs,
76 : const nsString& aDeviceId,
77 : const char** aOutBadConstraint) override;
78 : void NotifyPull(MediaStreamGraph* aGraph,
79 : SourceMediaStream* aSource,
80 : TrackID aId,
81 : StreamTime aDesiredTime,
82 : const PrincipalHandle& aPrincipalHandle) override;
83 0 : dom::MediaSourceEnum GetMediaSource() const override {
84 0 : return mMediaSource;
85 : }
86 :
87 : bool ChooseCapability(const NormalizedConstraints &aConstraints,
88 : const MediaEnginePrefs &aPrefs,
89 : const nsString& aDeviceId) override;
90 :
91 : void Refresh(int aIndex);
92 :
93 : void Shutdown() override;
94 :
95 0 : bool GetScary() const override { return mScary; }
96 :
97 : protected:
98 0 : ~MediaEngineRemoteVideoSource() { }
99 :
100 : private:
101 : // Initialize the needed Video engine interfaces.
102 : void Init();
103 : size_t NumCapabilities() const override;
104 : void GetCapability(size_t aIndex, webrtc::CaptureCapability& aOut) const override;
105 : void SetLastCapability(const webrtc::CaptureCapability& aCapability);
106 :
107 : nsresult
108 : UpdateSingleSource(const AllocationHandle* aHandle,
109 : const NormalizedConstraints& aNetConstraints,
110 : const MediaEnginePrefs& aPrefs,
111 : const nsString& aDeviceId,
112 : const char** aOutBadConstraint) override;
113 :
114 : dom::MediaSourceEnum mMediaSource; // source of media (camera | application | screen)
115 : mozilla::camera::CaptureEngine mCapEngine;
116 :
117 : // To only restart camera when needed, we keep track previous settings.
118 : webrtc::CaptureCapability mLastCapability;
119 : bool mScary;
120 : };
121 :
122 : }
123 :
124 : #endif /* MEDIAENGINE_REMOTE_VIDEO_SOURCE_H_ */
|