netwerk/protocol/rtsp/RtspChannelChild.cpp

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set sw=2 ts=8 et tw=80 : */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "RtspChannelChild.h"
michael@0 8 #include "mozilla/ipc/URIUtils.h"
michael@0 9
michael@0 10 using namespace mozilla::ipc;
michael@0 11
michael@0 12 namespace mozilla {
michael@0 13 namespace net {
michael@0 14
michael@0 15 //-----------------------------------------------------------------------------
michael@0 16 // RtspChannelChild
michael@0 17 //-----------------------------------------------------------------------------
michael@0 18 RtspChannelChild::RtspChannelChild(nsIURI *aUri)
michael@0 19 : mIPCOpen(false)
michael@0 20 , mCanceled(false)
michael@0 21 {
michael@0 22 nsBaseChannel::SetURI(aUri);
michael@0 23 }
michael@0 24
michael@0 25 RtspChannelChild::~RtspChannelChild()
michael@0 26 {
michael@0 27 }
michael@0 28
michael@0 29 nsIStreamingProtocolController*
michael@0 30 RtspChannelChild::GetController()
michael@0 31 {
michael@0 32 return mMediaStreamController;
michael@0 33 }
michael@0 34
michael@0 35 void
michael@0 36 RtspChannelChild::ReleaseController()
michael@0 37 {
michael@0 38 if (mMediaStreamController) {
michael@0 39 mMediaStreamController = nullptr;
michael@0 40 }
michael@0 41 }
michael@0 42
michael@0 43 //-----------------------------------------------------------------------------
michael@0 44 // IPDL
michael@0 45 //-----------------------------------------------------------------------------
michael@0 46 void
michael@0 47 RtspChannelChild::AddIPDLReference()
michael@0 48 {
michael@0 49 NS_ABORT_IF_FALSE(!mIPCOpen,
michael@0 50 "Attempt to retain more than one IPDL reference");
michael@0 51 mIPCOpen = true;
michael@0 52 AddRef();
michael@0 53 }
michael@0 54
michael@0 55 void
michael@0 56 RtspChannelChild::ReleaseIPDLReference()
michael@0 57 {
michael@0 58 NS_ABORT_IF_FALSE(mIPCOpen, "Attempt to release nonexistent IPDL reference");
michael@0 59 mIPCOpen = false;
michael@0 60 Release();
michael@0 61 }
michael@0 62
michael@0 63 //-----------------------------------------------------------------------------
michael@0 64 // nsISupports
michael@0 65 //-----------------------------------------------------------------------------
michael@0 66 NS_IMPL_ISUPPORTS_INHERITED(RtspChannelChild,
michael@0 67 nsBaseChannel,
michael@0 68 nsIChannel,
michael@0 69 nsIChildChannel)
michael@0 70
michael@0 71 //-----------------------------------------------------------------------------
michael@0 72 // nsBaseChannel::nsIChannel
michael@0 73 //-----------------------------------------------------------------------------
michael@0 74 NS_IMETHODIMP
michael@0 75 RtspChannelChild::GetContentType(nsACString& aContentType)
michael@0 76 {
michael@0 77 aContentType.AssignLiteral("RTSP");
michael@0 78 return NS_OK;
michael@0 79 }
michael@0 80
michael@0 81 class CallListenerOnStartRequestEvent : public nsRunnable
michael@0 82 {
michael@0 83 public:
michael@0 84 CallListenerOnStartRequestEvent(nsIStreamListener *aListener,
michael@0 85 nsIRequest *aRequest, nsISupports *aContext)
michael@0 86 : mListener(aListener)
michael@0 87 , mRequest(aRequest)
michael@0 88 , mContext(aContext)
michael@0 89 {
michael@0 90 MOZ_RELEASE_ASSERT(aListener);
michael@0 91 }
michael@0 92 NS_IMETHOD Run()
michael@0 93 {
michael@0 94 MOZ_ASSERT(NS_IsMainThread());
michael@0 95 mListener->OnStartRequest(mRequest, mContext);
michael@0 96 return NS_OK;
michael@0 97 }
michael@0 98 private:
michael@0 99 nsRefPtr<nsIStreamListener> mListener;
michael@0 100 nsRefPtr<nsIRequest> mRequest;
michael@0 101 nsRefPtr<nsISupports> mContext;
michael@0 102 };
michael@0 103
michael@0 104 NS_IMETHODIMP
michael@0 105 RtspChannelChild::AsyncOpen(nsIStreamListener *aListener, nsISupports *aContext)
michael@0 106 {
michael@0 107 // Precondition checks.
michael@0 108 MOZ_ASSERT(aListener);
michael@0 109 nsCOMPtr<nsIURI> uri = nsBaseChannel::URI();
michael@0 110 NS_ENSURE_TRUE(uri, NS_ERROR_ILLEGAL_VALUE);
michael@0 111
michael@0 112 // Create RtspController.
michael@0 113 nsCOMPtr<nsIStreamingProtocolControllerService> mediaControllerService =
michael@0 114 do_GetService(MEDIASTREAMCONTROLLERSERVICE_CONTRACTID);
michael@0 115 MOZ_RELEASE_ASSERT(mediaControllerService,
michael@0 116 "Cannot proceed if media controller service is unavailable!");
michael@0 117 mediaControllerService->Create(this, getter_AddRefs(mMediaStreamController));
michael@0 118 MOZ_ASSERT(mMediaStreamController);
michael@0 119
michael@0 120 // Add ourselves to the load group.
michael@0 121 if (mLoadGroup) {
michael@0 122 mLoadGroup->AddRequest(this, nullptr);
michael@0 123 }
michael@0 124
michael@0 125 // Dispatch mListener's OnStartRequest directly. mListener is expected to
michael@0 126 // create an RtspMediaResource and use the RtspController we just created to
michael@0 127 // manage the control and data streams to and from the network.
michael@0 128 mListener = aListener;
michael@0 129 mListenerContext = aContext;
michael@0 130 NS_DispatchToMainThread(
michael@0 131 new CallListenerOnStartRequestEvent(mListener, this, mListenerContext));
michael@0 132
michael@0 133 return NS_OK;
michael@0 134 }
michael@0 135
michael@0 136 //-----------------------------------------------------------------------------
michael@0 137 // nsBaseChannel::nsIStreamListener::nsIRequestObserver
michael@0 138 //-----------------------------------------------------------------------------
michael@0 139 NS_IMETHODIMP
michael@0 140 RtspChannelChild::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext)
michael@0 141 {
michael@0 142 MOZ_CRASH("Should never be called");
michael@0 143 }
michael@0 144
michael@0 145 NS_IMETHODIMP
michael@0 146 RtspChannelChild::OnStopRequest(nsIRequest *aRequest, nsISupports *aContext,
michael@0 147 nsresult aStatusCode)
michael@0 148 {
michael@0 149 MOZ_CRASH("Should never be called");
michael@0 150 }
michael@0 151
michael@0 152 //-----------------------------------------------------------------------------
michael@0 153 // nsBaseChannel::nsIStreamListener
michael@0 154 //-----------------------------------------------------------------------------
michael@0 155 NS_IMETHODIMP
michael@0 156 RtspChannelChild::OnDataAvailable(nsIRequest *aRequest,
michael@0 157 nsISupports *aContext,
michael@0 158 nsIInputStream *aInputStream,
michael@0 159 uint64_t aOffset,
michael@0 160 uint32_t aCount)
michael@0 161 {
michael@0 162 MOZ_CRASH("Should never be called");
michael@0 163 }
michael@0 164
michael@0 165 //-----------------------------------------------------------------------------
michael@0 166 // nsBaseChannel::nsIChannel::nsIRequest
michael@0 167 //-----------------------------------------------------------------------------
michael@0 168 class CallListenerOnStopRequestEvent : public nsRunnable
michael@0 169 {
michael@0 170 public:
michael@0 171 CallListenerOnStopRequestEvent(nsIStreamListener *aListener,
michael@0 172 nsIRequest *aRequest,
michael@0 173 nsISupports *aContext, nsresult aStatus)
michael@0 174 : mListener(aListener)
michael@0 175 , mRequest(aRequest)
michael@0 176 , mContext(aContext)
michael@0 177 , mStatus(aStatus)
michael@0 178 {
michael@0 179 MOZ_RELEASE_ASSERT(aListener);
michael@0 180 }
michael@0 181 NS_IMETHOD Run()
michael@0 182 {
michael@0 183 MOZ_ASSERT(NS_IsMainThread());
michael@0 184 mListener->OnStopRequest(mRequest, mContext, mStatus);
michael@0 185 return NS_OK;
michael@0 186 }
michael@0 187 private:
michael@0 188 nsRefPtr<nsIStreamListener> mListener;
michael@0 189 nsRefPtr<nsIRequest> mRequest;
michael@0 190 nsRefPtr<nsISupports> mContext;
michael@0 191 nsresult mStatus;
michael@0 192 };
michael@0 193
michael@0 194 NS_IMETHODIMP
michael@0 195 RtspChannelChild::Cancel(nsresult status)
michael@0 196 {
michael@0 197 if (mCanceled) {
michael@0 198 return NS_OK;
michael@0 199 }
michael@0 200
michael@0 201 mCanceled = true;
michael@0 202 // Stop RtspController.
michael@0 203 if (mMediaStreamController) {
michael@0 204 mMediaStreamController->Stop();
michael@0 205 }
michael@0 206
michael@0 207 // Call mListener's OnStopRequest to do clean up.
michael@0 208 NS_DispatchToMainThread(
michael@0 209 new CallListenerOnStopRequestEvent(mListener, this,
michael@0 210 mListenerContext, status));
michael@0 211 mListener = nullptr;
michael@0 212 mListenerContext = nullptr;
michael@0 213
michael@0 214 // Remove ourselves from the load group.
michael@0 215 if (mLoadGroup) {
michael@0 216 mLoadGroup->RemoveRequest(this, nullptr, status);
michael@0 217 }
michael@0 218
michael@0 219 return NS_OK;
michael@0 220 }
michael@0 221
michael@0 222 NS_IMETHODIMP
michael@0 223 RtspChannelChild::Suspend()
michael@0 224 {
michael@0 225 MOZ_CRASH("Should never be called");
michael@0 226 }
michael@0 227
michael@0 228 NS_IMETHODIMP
michael@0 229 RtspChannelChild::Resume()
michael@0 230 {
michael@0 231 MOZ_CRASH("Should never be called");
michael@0 232 }
michael@0 233
michael@0 234 //-----------------------------------------------------------------------------
michael@0 235 // nsBaseChannel
michael@0 236 //-----------------------------------------------------------------------------
michael@0 237 NS_IMETHODIMP
michael@0 238 RtspChannelChild::OpenContentStream(bool aAsync,
michael@0 239 nsIInputStream **aStream,
michael@0 240 nsIChannel **aChannel)
michael@0 241 {
michael@0 242 MOZ_CRASH("Should never be called");
michael@0 243 }
michael@0 244
michael@0 245 //-----------------------------------------------------------------------------
michael@0 246 // nsIChildChannel
michael@0 247 //-----------------------------------------------------------------------------
michael@0 248 NS_IMETHODIMP
michael@0 249 RtspChannelChild::ConnectParent(uint32_t id)
michael@0 250 {
michael@0 251 // Create RtspChannelParent for redirection.
michael@0 252 AddIPDLReference();
michael@0 253 RtspChannelConnectArgs connectArgs;
michael@0 254 SerializeURI(nsBaseChannel::URI(), connectArgs.uri());
michael@0 255 connectArgs.channelId() = id;
michael@0 256 if (!gNeckoChild->SendPRtspChannelConstructor(this, connectArgs)) {
michael@0 257 return NS_ERROR_FAILURE;
michael@0 258 }
michael@0 259
michael@0 260 return NS_OK;
michael@0 261 }
michael@0 262
michael@0 263 NS_IMETHODIMP
michael@0 264 RtspChannelChild::CompleteRedirectSetup(nsIStreamListener *aListener,
michael@0 265 nsISupports *aContext)
michael@0 266 {
michael@0 267 return AsyncOpen(aListener, aContext);
michael@0 268 }
michael@0 269
michael@0 270 } // namespace net
michael@0 271 } // namespace mozilla

mercurial