/src/mozilla-central/dom/media/systemservices/VideoEngine.h
Line | Count | Source (jump to first uncovered line) |
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 mozilla_VideoEngine_h |
8 | | #define mozilla_VideoEngine_h |
9 | | |
10 | | #include "MediaEngine.h" |
11 | | #include "VideoFrameUtils.h" |
12 | | #include "mozilla/media/MediaUtils.h" |
13 | | #include "webrtc/modules/video_capture/video_capture_impl.h" |
14 | | #include "webrtc/modules/video_capture/video_capture_defines.h" |
15 | | #include "webrtc/modules/video_capture/video_capture_factory.h" |
16 | | #include "webrtc/video_engine/desktop_capture_impl.h" |
17 | | #include <memory> |
18 | | #include <functional> |
19 | | |
20 | | namespace mozilla { |
21 | | namespace camera { |
22 | | |
23 | | // Historically the video engine was part of webrtc |
24 | | // it was removed (and reimplemented in Talk) |
25 | | class VideoEngine |
26 | | { |
27 | | private: |
28 | 0 | virtual ~VideoEngine (){}; |
29 | | // Base cache expiration period |
30 | | // Note because cameras use HW plug event detection, this |
31 | | // only applies to screen based modes. |
32 | | static const int64_t kCacheExpiryPeriodMs = 2000; |
33 | | |
34 | | public: |
35 | | VideoEngine() : mId(0) {}; |
36 | | NS_INLINE_DECL_REFCOUNTING(VideoEngine) |
37 | | |
38 | | static already_AddRefed<VideoEngine> Create(UniquePtr<const webrtc::Config>&& aConfig); |
39 | | #if defined(ANDROID) |
40 | | static int SetAndroidObjects(); |
41 | | #endif |
42 | | void CreateVideoCapture(int32_t& id, const char* deviceUniqueIdUTF8); |
43 | | |
44 | | int ReleaseVideoCapture(const int32_t id); |
45 | | |
46 | | // VideoEngine is responsible for any cleanup in its modules |
47 | 0 | static void Delete(VideoEngine * engine) { } |
48 | | |
49 | | /** Returns an existing or creates a new new DeviceInfo. |
50 | | * Camera info is cached to prevent repeated lengthy polling for "realness" |
51 | | * of the hardware devices. Other types of capture, e.g. screen share info, |
52 | | * are cached for 1 second. This could be handled in a more elegant way in |
53 | | * the future. |
54 | | * @return on failure the shared_ptr will be null, otherwise it will contain |
55 | | * a DeviceInfo. |
56 | | * @see bug 1305212 https://bugzilla.mozilla.org/show_bug.cgi?id=1305212 |
57 | | */ |
58 | | std::shared_ptr<webrtc::VideoCaptureModule::DeviceInfo> GetOrCreateVideoCaptureDeviceInfo(); |
59 | | |
60 | | const UniquePtr<const webrtc::Config>& GetConfiguration(); |
61 | | |
62 | | class CaptureEntry { |
63 | | public: |
64 | | CaptureEntry(int32_t aCapnum, |
65 | | rtc::scoped_refptr<webrtc::VideoCaptureModule> aCapture); |
66 | | int32_t Capnum() const; |
67 | | rtc::scoped_refptr<webrtc::VideoCaptureModule> VideoCapture(); |
68 | | private: |
69 | | int32_t mCapnum; |
70 | | rtc::scoped_refptr<webrtc::VideoCaptureModule> mVideoCaptureModule; |
71 | | friend class VideoEngine; |
72 | | }; |
73 | | |
74 | | // Returns true iff an entry for capnum exists |
75 | | bool WithEntry(const int32_t entryCapnum, const std::function<void(CaptureEntry &entry)>&& fn); |
76 | | |
77 | | private: |
78 | | explicit VideoEngine(UniquePtr<const webrtc::Config>&& aConfig); |
79 | | int32_t mId; |
80 | | webrtc::CaptureDeviceInfo mCaptureDevInfo; |
81 | | std::shared_ptr<webrtc::VideoCaptureModule::DeviceInfo> mDeviceInfo; |
82 | | UniquePtr<const webrtc::Config> mConfig; |
83 | | std::map<int32_t, CaptureEntry> mCaps; |
84 | | std::map<int32_t, int32_t> mIdMap; |
85 | | // The validity period for non-camera capture device infos` |
86 | | int64_t mExpiryTimeInMs = 0; |
87 | | int32_t GenerateId(); |
88 | | static int32_t sId; |
89 | | }; |
90 | | } |
91 | | } |
92 | | #endif |