You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
4.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * libjingle
  3. * Copyright 2004--2010, Google Inc.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  19. * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  22. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  23. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  24. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  25. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #include "talk/media/devices/devicemanager.h"
  28. #import <assert.h>
  29. #import <QTKit/QTKit.h>
  30. #include "talk/base/logging.h"
  31. @interface DeviceWatcherImpl : NSObject {
  32. @private
  33. cricket::DeviceManagerInterface* manager_;
  34. }
  35. - (id)init:(cricket::DeviceManagerInterface*)manager;
  36. - (void)onDevicesChanged:(NSNotification *)notification;
  37. @end
  38. @implementation DeviceWatcherImpl
  39. - (id)init:(cricket::DeviceManagerInterface*)manager {
  40. if ((self = [super init])) {
  41. assert(manager != NULL);
  42. manager_ = manager;
  43. [[NSNotificationCenter defaultCenter] addObserver:self
  44. selector:@selector(onDevicesChanged:)
  45. name:QTCaptureDeviceWasConnectedNotification
  46. object:nil];
  47. [[NSNotificationCenter defaultCenter] addObserver:self
  48. selector:@selector(onDevicesChanged:)
  49. name:QTCaptureDeviceWasDisconnectedNotification
  50. object:nil];
  51. }
  52. return self;
  53. }
  54. - (void)dealloc {
  55. [[NSNotificationCenter defaultCenter] removeObserver:self];
  56. [super dealloc];
  57. }
  58. - (void)onDevicesChanged:(NSNotification *)notification {
  59. manager_->SignalDevicesChange();
  60. }
  61. @end
  62. namespace cricket {
  63. DeviceWatcherImpl* CreateDeviceWatcherCallback(
  64. DeviceManagerInterface* manager) {
  65. NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
  66. DeviceWatcherImpl* impl = [[DeviceWatcherImpl alloc] init:manager];
  67. [pool drain];
  68. return impl;
  69. }
  70. void ReleaseDeviceWatcherCallback(DeviceWatcherImpl* watcher) {
  71. NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
  72. [watcher release];
  73. [pool drain];
  74. }
  75. bool GetQTKitVideoDevices(std::vector<Device>* devices) {
  76. NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
  77. NSArray* qt_capture_devices =
  78. [QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeVideo];
  79. NSUInteger count = [qt_capture_devices count];
  80. LOG(LS_INFO) << count << " capture device(s) found:";
  81. for (QTCaptureDevice* qt_capture_device in qt_capture_devices) {
  82. static NSString* const kFormat = @"localizedDisplayName: \"%@\", "
  83. @"modelUniqueID: \"%@\", uniqueID \"%@\", isConnected: %d, isOpen: %d, "
  84. @"isInUseByAnotherApplication: %d";
  85. NSString* info = [NSString stringWithFormat:kFormat,
  86. [qt_capture_device localizedDisplayName],
  87. [qt_capture_device modelUniqueID],
  88. [qt_capture_device uniqueID],
  89. [qt_capture_device isConnected],
  90. [qt_capture_device isOpen],
  91. [qt_capture_device isInUseByAnotherApplication]];
  92. LOG(LS_INFO) << [info UTF8String];
  93. std::string name([[qt_capture_device localizedDisplayName]
  94. UTF8String]);
  95. devices->push_back(Device(name,
  96. [[qt_capture_device uniqueID]
  97. UTF8String]));
  98. }
  99. [pool drain];
  100. return true;
  101. }
  102. } // namespace cricket