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.

81 lines
3.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright 2015 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #import "RTCVideoSource+Private.h"
  11. #include "api/video_track_source_proxy.h"
  12. #include "rtc_base/checks.h"
  13. #include "sdk/objc/native/src/objc_video_track_source.h"
  14. static webrtc::ObjCVideoTrackSource *getObjCVideoSource(
  15. const rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> nativeSource) {
  16. webrtc::VideoTrackSourceProxy *proxy_source =
  17. static_cast<webrtc::VideoTrackSourceProxy *>(nativeSource.get());
  18. return static_cast<webrtc::ObjCVideoTrackSource *>(proxy_source->internal());
  19. }
  20. // TODO(magjed): Refactor this class and target ObjCVideoTrackSource only once
  21. // RTCAVFoundationVideoSource is gone. See http://crbug/webrtc/7177 for more
  22. // info.
  23. @implementation RTCVideoSource {
  24. rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> _nativeVideoSource;
  25. }
  26. - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
  27. nativeVideoSource:
  28. (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource {
  29. RTC_DCHECK(factory);
  30. RTC_DCHECK(nativeVideoSource);
  31. if (self = [super initWithFactory:factory
  32. nativeMediaSource:nativeVideoSource
  33. type:RTCMediaSourceTypeVideo]) {
  34. _nativeVideoSource = nativeVideoSource;
  35. }
  36. return self;
  37. }
  38. - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
  39. nativeMediaSource:(rtc::scoped_refptr<webrtc::MediaSourceInterface>)nativeMediaSource
  40. type:(RTCMediaSourceType)type {
  41. RTC_NOTREACHED();
  42. return nil;
  43. }
  44. - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
  45. signalingThread:(rtc::Thread *)signalingThread
  46. workerThread:(rtc::Thread *)workerThread {
  47. rtc::scoped_refptr<webrtc::ObjCVideoTrackSource> objCVideoTrackSource(
  48. new rtc::RefCountedObject<webrtc::ObjCVideoTrackSource>());
  49. return [self initWithFactory:factory
  50. nativeVideoSource:webrtc::VideoTrackSourceProxy::Create(
  51. signalingThread, workerThread, objCVideoTrackSource)];
  52. }
  53. - (NSString *)description {
  54. NSString *stateString = [[self class] stringForState:self.state];
  55. return [NSString stringWithFormat:@"RTCVideoSource( %p ): %@", self, stateString];
  56. }
  57. - (void)capturer:(RTCVideoCapturer *)capturer didCaptureVideoFrame:(RTCVideoFrame *)frame {
  58. getObjCVideoSource(_nativeVideoSource)->OnCapturedFrame(frame);
  59. }
  60. - (void)adaptOutputFormatToWidth:(int)width height:(int)height fps:(int)fps {
  61. getObjCVideoSource(_nativeVideoSource)->OnOutputFormatRequest(width, height, fps);
  62. }
  63. #pragma mark - Private
  64. - (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource {
  65. return _nativeVideoSource;
  66. }
  67. @end