StreamingProtocolService.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #include "base/basictypes.h"
  5. #include "mozilla/ClearOnShutdown.h"
  6. #include "StreamingProtocolService.h"
  7. #include "mozilla/net/NeckoChild.h"
  8. #include "nsIURI.h"
  9. #include "necko-config.h"
  10. #ifdef NECKO_PROTOCOL_rtsp
  11. #include "RtspControllerChild.h"
  12. #include "RtspController.h"
  13. #endif
  14. namespace mozilla {
  15. namespace net {
  16. NS_IMPL_ISUPPORTS(StreamingProtocolControllerService,
  17. nsIStreamingProtocolControllerService)
  18. /* static */
  19. StaticRefPtr<StreamingProtocolControllerService> sSingleton;
  20. /* static */
  21. already_AddRefed<StreamingProtocolControllerService>
  22. StreamingProtocolControllerService::GetInstance()
  23. {
  24. if (!sSingleton) {
  25. sSingleton = new StreamingProtocolControllerService();
  26. ClearOnShutdown(&sSingleton);
  27. }
  28. RefPtr<StreamingProtocolControllerService> service = sSingleton.get();
  29. return service.forget();
  30. }
  31. NS_IMETHODIMP
  32. StreamingProtocolControllerService::Create(nsIChannel *aChannel, nsIStreamingProtocolController **aResult)
  33. {
  34. RefPtr<nsIStreamingProtocolController> mediacontroller;
  35. nsCOMPtr<nsIURI> uri;
  36. nsAutoCString scheme;
  37. NS_ENSURE_ARG_POINTER(aChannel);
  38. aChannel->GetURI(getter_AddRefs(uri));
  39. nsresult rv = uri->GetScheme(scheme);
  40. if (NS_FAILED(rv)) return rv;
  41. #ifdef NECKO_PROTOCOL_rtsp
  42. if (scheme.EqualsLiteral("rtsp")) {
  43. if (IsNeckoChild()) {
  44. mediacontroller = new RtspControllerChild(aChannel);
  45. } else {
  46. mediacontroller = new RtspController(aChannel);
  47. }
  48. }
  49. #endif
  50. if (!mediacontroller) {
  51. return NS_ERROR_NO_INTERFACE;
  52. }
  53. mediacontroller->Init(uri);
  54. mediacontroller.forget(aResult);
  55. return NS_OK;
  56. }
  57. } // namespace net
  58. } // namespace mozilla