netwerk/base/src/StreamingProtocolService.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/base/src/StreamingProtocolService.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,72 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#include "base/basictypes.h"
     1.9 +#include "mozilla/ClearOnShutdown.h"
    1.10 +#include "StreamingProtocolService.h"
    1.11 +#include "mozilla/net/NeckoChild.h"
    1.12 +#include "nsIURI.h"
    1.13 +#include "necko-config.h"
    1.14 +
    1.15 +#ifdef NECKO_PROTOCOL_rtsp
    1.16 +#include "RtspControllerChild.h"
    1.17 +#include "RtspController.h"
    1.18 +#endif
    1.19 +
    1.20 +namespace mozilla {
    1.21 +namespace net {
    1.22 +
    1.23 +NS_IMPL_ISUPPORTS(StreamingProtocolControllerService,
    1.24 +                  nsIStreamingProtocolControllerService)
    1.25 +
    1.26 +/* static */
    1.27 +StaticRefPtr<StreamingProtocolControllerService> sSingleton;
    1.28 +
    1.29 +/* static */
    1.30 +already_AddRefed<StreamingProtocolControllerService>
    1.31 +StreamingProtocolControllerService::GetInstance()
    1.32 +{
    1.33 +  if (!sSingleton) {
    1.34 +    sSingleton = new StreamingProtocolControllerService();
    1.35 +    ClearOnShutdown(&sSingleton);
    1.36 +  }
    1.37 +  nsRefPtr<StreamingProtocolControllerService> service = sSingleton.get();
    1.38 +  return service.forget();
    1.39 +}
    1.40 +
    1.41 +NS_IMETHODIMP
    1.42 +StreamingProtocolControllerService::Create(nsIChannel *aChannel, nsIStreamingProtocolController **aResult)
    1.43 +{
    1.44 +  nsRefPtr<nsIStreamingProtocolController> mediacontroller;
    1.45 +  nsCOMPtr<nsIURI> uri;
    1.46 +  nsAutoCString scheme;
    1.47 +
    1.48 +  NS_ENSURE_ARG_POINTER(aChannel);
    1.49 +  aChannel->GetURI(getter_AddRefs(uri));
    1.50 +
    1.51 +  nsresult rv = uri->GetScheme(scheme);
    1.52 +  if (NS_FAILED(rv)) return rv;
    1.53 +
    1.54 +#ifdef NECKO_PROTOCOL_rtsp
    1.55 +  if (scheme.EqualsLiteral("rtsp")) {
    1.56 +    if (IsNeckoChild()) {
    1.57 +      mediacontroller = new RtspControllerChild(aChannel);
    1.58 +    } else {
    1.59 +      mediacontroller = new RtspController(aChannel);
    1.60 +    }
    1.61 +  }
    1.62 +#endif
    1.63 +
    1.64 +  if (!mediacontroller) {
    1.65 +    return NS_ERROR_NO_INTERFACE;
    1.66 +  }
    1.67 +
    1.68 +  mediacontroller->Init(uri);
    1.69 +
    1.70 +  mediacontroller.forget(aResult);
    1.71 +  return NS_OK;
    1.72 +}
    1.73 +
    1.74 +} // namespace net
    1.75 +} // namespace mozilla

mercurial