CefMediaObserver.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. namespace Xilium.CefGlue
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Runtime.InteropServices;
  7. using Xilium.CefGlue.Interop;
  8. /// <summary>
  9. /// Implemented by the client to observe MediaRouter events and registered via
  10. /// CefMediaRouter::AddObserver. The methods of this class will be called on the
  11. /// browser process UI thread.
  12. /// </summary>
  13. public abstract unsafe partial class CefMediaObserver
  14. {
  15. private void on_sinks(cef_media_observer_t* self, UIntPtr sinksCount, cef_media_sink_t** sinks)
  16. {
  17. CheckSelf(self);
  18. var mSinksCount = checked((int)sinksCount);
  19. var mSinks = new CefMediaSink[mSinksCount];
  20. for (var i = 0; i < mSinksCount; i++)
  21. {
  22. mSinks[i] = CefMediaSink.FromNative(sinks[i]);
  23. }
  24. OnSinks(mSinks);
  25. }
  26. /// <summary>
  27. /// The list of available media sinks has changed or
  28. /// CefMediaRouter::NotifyCurrentSinks was called.
  29. /// </summary>
  30. protected abstract void OnSinks(CefMediaSink[] sinks);
  31. private void on_routes(cef_media_observer_t* self, UIntPtr routesCount, cef_media_route_t** routes)
  32. {
  33. CheckSelf(self);
  34. var mRoutesCount = checked((int)routesCount);
  35. var mRoutes = new CefMediaRoute[mRoutesCount];
  36. for (var i = 0; i < mRoutesCount; i++)
  37. {
  38. mRoutes[i] = CefMediaRoute.FromNative(routes[i]);
  39. }
  40. OnRoutes(mRoutes);
  41. }
  42. /// <summary>
  43. /// The list of available media routes has changed or
  44. /// CefMediaRouter::NotifyCurrentRoutes was called.
  45. /// </summary>
  46. protected abstract void OnRoutes(CefMediaRoute[] routes);
  47. private void on_route_state_changed(cef_media_observer_t* self, cef_media_route_t* route, CefMediaRouteConnectionState state)
  48. {
  49. CheckSelf(self);
  50. var mRoute = CefMediaRoute.FromNative(route);
  51. OnRouteStateChanged(mRoute, state);
  52. }
  53. /// <summary>
  54. /// The connection state of |route| has changed.
  55. /// </summary>
  56. protected abstract void OnRouteStateChanged(CefMediaRoute route, CefMediaRouteConnectionState state);
  57. private void on_route_message_received(cef_media_observer_t* self, cef_media_route_t* route, void* message, UIntPtr message_size)
  58. {
  59. CheckSelf(self);
  60. var mRoute = CefMediaRoute.FromNative(route);
  61. var mMessageSize = checked((int)message_size);
  62. OnRouteMessageReceived(mRoute, (IntPtr)message, mMessageSize);
  63. }
  64. /// <summary>
  65. /// A message was recieved over |route|. |message| is only valid for
  66. /// the scope of this callback and should be copied if necessary.
  67. /// </summary>
  68. protected abstract void OnRouteMessageReceived(CefMediaRoute route, IntPtr message, int messageSize);
  69. }
  70. }