LCOV - code coverage report
Current view: top level - dom/media/systemservices - VideoEngine.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 58 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 12 0.0 %
Legend: Lines: hit not hit

          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             : #include "VideoEngine.h"
       8             : #include "webrtc/video_engine/browser_capture_impl.h"
       9             : #ifdef WEBRTC_ANDROID
      10             : #include "webrtc/modules/video_capture/video_capture.h"
      11             : #endif
      12             : 
      13             : 
      14             : namespace mozilla {
      15             : namespace camera {
      16             : 
      17             : #undef LOG
      18             : #undef LOG_ENABLED
      19             : mozilla::LazyLogModule gVideoEngineLog("VideoEngine");
      20             : #define LOG(args) MOZ_LOG(gVideoEngineLog, mozilla::LogLevel::Debug, args)
      21             : #define LOG_ENABLED() MOZ_LOG_TEST(gVideoEngineLog, mozilla::LogLevel::Debug)
      22             : 
      23             : int VideoEngine::sId = 0;
      24             : 
      25             : #if defined(ANDROID)
      26             : int VideoEngine::SetAndroidObjects(JavaVM* javaVM) {
      27             :   LOG((__PRETTY_FUNCTION__));
      28             : 
      29             :   if (webrtc::SetCaptureAndroidVM(javaVM) != 0) {
      30             :     LOG(("Could not set capture Android VM"));
      31             :     return -1;
      32             :   }
      33             : #ifdef WEBRTC_INCLUDE_INTERNAL_VIDEO_RENDER
      34             :   if (webrtc::SetRenderAndroidVM(javaVM) != 0) {
      35             :     LOG(("Could not set render Android VM"));
      36             :     return -1;
      37             :   }
      38             : #endif
      39             :   return 0;
      40             : }
      41             : #endif
      42             : 
      43             : void
      44           0 : VideoEngine::CreateVideoCapture(int32_t& id, const char* deviceUniqueIdUTF8) {
      45           0 :   LOG((__PRETTY_FUNCTION__));
      46           0 :   id = GenerateId();
      47           0 :   LOG(("CaptureDeviceInfo.type=%s id=%d",mCaptureDevInfo.TypeName(),id));
      48           0 :   CaptureEntry entry = {-1, nullptr};
      49             : 
      50           0 :   if (mCaptureDevInfo.type == webrtc::CaptureDeviceType::Camera) {
      51           0 :     entry = CaptureEntry(id,
      52           0 :                          webrtc::VideoCaptureFactory::Create(deviceUniqueIdUTF8));
      53             :   } else {
      54             : #ifndef WEBRTC_ANDROID
      55           0 :     entry = CaptureEntry(
      56             :               id,
      57           0 :               webrtc::DesktopCaptureImpl::Create(id, deviceUniqueIdUTF8, mCaptureDevInfo.type));
      58             : #else
      59             :     MOZ_ASSERT("CreateVideoCapture NO DESKTOP CAPTURE IMPL ON ANDROID" == nullptr);
      60             : #endif
      61             :   }
      62           0 :   mCaps.emplace(id,std::move(entry));
      63           0 : }
      64             : 
      65             : int
      66           0 : VideoEngine::ReleaseVideoCapture(const int32_t id) {
      67           0 :   bool found = false;
      68           0 :   WithEntry(id, [&found](CaptureEntry& cap) {
      69           0 :          cap.mVideoCaptureModule = nullptr;
      70           0 :         found = true;
      71           0 :    });
      72           0 :   return found ? 0 : (-1);
      73             : }
      74             : 
      75             : std::shared_ptr<webrtc::VideoCaptureModule::DeviceInfo>
      76           0 : VideoEngine::GetOrCreateVideoCaptureDeviceInfo() {
      77           0 :   if (mDeviceInfo) {
      78           0 :     return mDeviceInfo;
      79             :   }
      80           0 :   switch (mCaptureDevInfo.type) {
      81             :     case webrtc::CaptureDeviceType::Camera: {
      82           0 :       mDeviceInfo.reset(webrtc::VideoCaptureFactory::CreateDeviceInfo());
      83           0 :       break;
      84             :     }
      85             :     case webrtc::CaptureDeviceType::Browser: {
      86           0 :       mDeviceInfo.reset(webrtc::BrowserDeviceInfoImpl::CreateDeviceInfo());
      87           0 :       break;
      88             :     }
      89             :     // Window, Application, and Screen types are handled by DesktopCapture
      90             :     case webrtc::CaptureDeviceType::Window:
      91             :     case webrtc::CaptureDeviceType::Application:
      92             :     case webrtc::CaptureDeviceType::Screen: {
      93             : #if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_IOS)
      94           0 :       mDeviceInfo.reset(webrtc::DesktopCaptureImpl::CreateDeviceInfo(mId,mCaptureDevInfo.type));
      95             : #else
      96             :       MOZ_ASSERT("GetVideoCaptureDeviceInfo NO DESKTOP CAPTURE IMPL ON ANDROID" == nullptr);
      97             :       mDeviceInfo.reset();
      98             : #endif
      99           0 :       break;
     100             :     }
     101             :   }
     102           0 :   return mDeviceInfo;
     103             : }
     104             : 
     105             : const UniquePtr<const webrtc::Config>&
     106           0 : VideoEngine::GetConfiguration() {
     107           0 :   return mConfig;
     108             : }
     109             : 
     110           0 : RefPtr<VideoEngine> VideoEngine::Create(UniquePtr<const webrtc::Config>&& aConfig) {
     111           0 :   LOG((__PRETTY_FUNCTION__));
     112           0 :   LOG(("Creating new VideoEngine with CaptureDeviceType %s",
     113             :        aConfig->Get<webrtc::CaptureDeviceInfo>().TypeName()));
     114           0 :   RefPtr<VideoEngine> engine(new VideoEngine(std::move(aConfig)));
     115           0 :   return engine;
     116             : }
     117             : 
     118           0 : VideoEngine::CaptureEntry::CaptureEntry(int32_t aCapnum,
     119           0 :                                         rtc::scoped_refptr<webrtc::VideoCaptureModule> aCapture)
     120             :   : mCapnum(aCapnum)
     121           0 :   , mVideoCaptureModule(aCapture)
     122           0 : {}
     123             : 
     124             : rtc::scoped_refptr<webrtc::VideoCaptureModule>
     125           0 : VideoEngine::CaptureEntry::VideoCapture() {
     126           0 :   return mVideoCaptureModule;
     127             : }
     128             : 
     129             : int32_t
     130           0 : VideoEngine::CaptureEntry::Capnum() const {
     131           0 :   return mCapnum;
     132             : }
     133             : 
     134           0 : bool VideoEngine::WithEntry(const int32_t entryCapnum,
     135             :                             const std::function<void(CaptureEntry &entry)>&& fn) {
     136           0 :   auto it = mCaps.find(entryCapnum);
     137           0 :   if (it == mCaps.end()) {
     138           0 :     return false;
     139             :   }
     140           0 :   fn(it->second);
     141           0 :   return true;
     142             : }
     143             : 
     144             : int32_t
     145           0 : VideoEngine::GenerateId() {
     146             :   // XXX Something better than this (a map perhaps, or a simple boolean TArray, given
     147             :   // the number in-use is O(1) normally!)
     148           0 :   return mId = sId++;
     149             : }
     150             : 
     151           0 : VideoEngine::VideoEngine(UniquePtr<const webrtc::Config>&& aConfig):
     152           0 :   mCaptureDevInfo(aConfig->Get<webrtc::CaptureDeviceInfo>()),
     153             :   mDeviceInfo(nullptr),
     154           0 :   mConfig(std::move(aConfig))
     155             : {
     156           0 :   LOG((__PRETTY_FUNCTION__));
     157           0 : }
     158             : 
     159             : }
     160             : }

Generated by: LCOV version 1.13