summaryrefslogtreecommitdiff
path: root/netwerk/base/StreamingProtocolService.cpp
blob: 3df3326bc11bebc8f233a65d6110a726b53be641 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "base/basictypes.h"
#include "mozilla/ClearOnShutdown.h"
#include "StreamingProtocolService.h"
#include "mozilla/net/NeckoChild.h"
#include "nsIURI.h"
#include "necko-config.h"

#ifdef NECKO_PROTOCOL_rtsp
#include "RtspControllerChild.h"
#include "RtspController.h"
#endif

namespace mozilla {
namespace net {

NS_IMPL_ISUPPORTS(StreamingProtocolControllerService,
                  nsIStreamingProtocolControllerService)

/* static */
StaticRefPtr<StreamingProtocolControllerService> sSingleton;

/* static */
already_AddRefed<StreamingProtocolControllerService>
StreamingProtocolControllerService::GetInstance()
{
  if (!sSingleton) {
    sSingleton = new StreamingProtocolControllerService();
    ClearOnShutdown(&sSingleton);
  }
  RefPtr<StreamingProtocolControllerService> service = sSingleton.get();
  return service.forget();
}

NS_IMETHODIMP
StreamingProtocolControllerService::Create(nsIChannel *aChannel, nsIStreamingProtocolController **aResult)
{
  RefPtr<nsIStreamingProtocolController> mediacontroller;
  nsCOMPtr<nsIURI> uri;
  nsAutoCString scheme;

  NS_ENSURE_ARG_POINTER(aChannel);
  aChannel->GetURI(getter_AddRefs(uri));

  nsresult rv = uri->GetScheme(scheme);
  if (NS_FAILED(rv)) return rv;

#ifdef NECKO_PROTOCOL_rtsp
  if (scheme.EqualsLiteral("rtsp")) {
    if (IsNeckoChild()) {
      mediacontroller = new RtspControllerChild(aChannel);
    } else {
      mediacontroller = new RtspController(aChannel);
    }
  }
#endif

  if (!mediacontroller) {
    return NS_ERROR_NO_INTERFACE;
  }

  mediacontroller->Init(uri);

  mediacontroller.forget(aResult);
  return NS_OK;
}

} // namespace net
} // namespace mozilla