netwerk/base/src/StreamingProtocolService.cpp

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:6d1f9cce8092
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
5 #include "base/basictypes.h"
6 #include "mozilla/ClearOnShutdown.h"
7 #include "StreamingProtocolService.h"
8 #include "mozilla/net/NeckoChild.h"
9 #include "nsIURI.h"
10 #include "necko-config.h"
11
12 #ifdef NECKO_PROTOCOL_rtsp
13 #include "RtspControllerChild.h"
14 #include "RtspController.h"
15 #endif
16
17 namespace mozilla {
18 namespace net {
19
20 NS_IMPL_ISUPPORTS(StreamingProtocolControllerService,
21 nsIStreamingProtocolControllerService)
22
23 /* static */
24 StaticRefPtr<StreamingProtocolControllerService> sSingleton;
25
26 /* static */
27 already_AddRefed<StreamingProtocolControllerService>
28 StreamingProtocolControllerService::GetInstance()
29 {
30 if (!sSingleton) {
31 sSingleton = new StreamingProtocolControllerService();
32 ClearOnShutdown(&sSingleton);
33 }
34 nsRefPtr<StreamingProtocolControllerService> service = sSingleton.get();
35 return service.forget();
36 }
37
38 NS_IMETHODIMP
39 StreamingProtocolControllerService::Create(nsIChannel *aChannel, nsIStreamingProtocolController **aResult)
40 {
41 nsRefPtr<nsIStreamingProtocolController> mediacontroller;
42 nsCOMPtr<nsIURI> uri;
43 nsAutoCString scheme;
44
45 NS_ENSURE_ARG_POINTER(aChannel);
46 aChannel->GetURI(getter_AddRefs(uri));
47
48 nsresult rv = uri->GetScheme(scheme);
49 if (NS_FAILED(rv)) return rv;
50
51 #ifdef NECKO_PROTOCOL_rtsp
52 if (scheme.EqualsLiteral("rtsp")) {
53 if (IsNeckoChild()) {
54 mediacontroller = new RtspControllerChild(aChannel);
55 } else {
56 mediacontroller = new RtspController(aChannel);
57 }
58 }
59 #endif
60
61 if (!mediacontroller) {
62 return NS_ERROR_NO_INTERFACE;
63 }
64
65 mediacontroller->Init(uri);
66
67 mediacontroller.forget(aResult);
68 return NS_OK;
69 }
70
71 } // namespace net
72 } // namespace mozilla

mercurial