MediaStreamObserver.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "pch.h"
  2. #include "Context.h"
  3. #include "MediaStreamObserver.h"
  4. namespace unity
  5. {
  6. namespace webrtc
  7. {
  8. MediaStreamObserver::MediaStreamObserver(webrtc::MediaStreamInterface* stream, Context* context)
  9. : ::webrtc::MediaStreamObserver(stream)
  10. , m_context(context)
  11. {
  12. this->SignalVideoTrackAdded.connect(this, &MediaStreamObserver::OnVideoTrackAdded);
  13. this->SignalAudioTrackAdded.connect(this, &MediaStreamObserver::OnAudioTrackAdded);
  14. this->SignalVideoTrackRemoved.connect(this, &MediaStreamObserver::OnVideoTrackRemoved);
  15. this->SignalAudioTrackRemoved.connect(this, &MediaStreamObserver::OnAudioTrackRemoved);
  16. }
  17. void
  18. MediaStreamObserver::OnVideoTrackAdded(webrtc::VideoTrackInterface* track, webrtc::MediaStreamInterface* stream)
  19. {
  20. m_context->AddRefPtr(track);
  21. for (auto callback : m_listOnAddTrack)
  22. {
  23. callback(stream, track);
  24. }
  25. }
  26. void
  27. MediaStreamObserver::OnAudioTrackAdded(webrtc::AudioTrackInterface* track, webrtc::MediaStreamInterface* stream)
  28. {
  29. m_context->AddRefPtr(track);
  30. for (auto callback : m_listOnAddTrack)
  31. {
  32. callback(stream, track);
  33. }
  34. }
  35. void
  36. MediaStreamObserver::OnVideoTrackRemoved(webrtc::VideoTrackInterface* track, webrtc::MediaStreamInterface* stream)
  37. {
  38. for (auto callback : m_listOnRemoveTrack)
  39. {
  40. callback(stream, track);
  41. }
  42. }
  43. void
  44. MediaStreamObserver::OnAudioTrackRemoved(webrtc::AudioTrackInterface* track, webrtc::MediaStreamInterface* stream)
  45. {
  46. for (auto callback : m_listOnRemoveTrack)
  47. {
  48. callback(stream, track);
  49. }
  50. }
  51. void MediaStreamObserver::RegisterOnAddTrack(DelegateMediaStreamOnAddTrack callback)
  52. {
  53. m_listOnAddTrack.push_back(callback);
  54. }
  55. void MediaStreamObserver::RegisterOnRemoveTrack(DelegateMediaStreamOnRemoveTrack callback)
  56. {
  57. m_listOnRemoveTrack.push_back(callback);
  58. }
  59. } // end namespace webrtc
  60. } // end namespace unity