Bug 1353668. P1 - add a member function, CopySegmentToCache. draft
authorJW Wang <jwwang@mozilla.com>
Wed, 05 Apr 2017 17:24:03 +0800
changeset 556577 87bc57d852e4469b758389132894348f35b7771a
parent 556576 e7ba74d683e46de15804a667a35827914ae66a3b
child 556578 81f2e9b5c4add258a783a8c134c2cbf93ca6322b
push id52586
push userjwwang@mozilla.com
push dateThu, 06 Apr 2017 03:05:37 +0000
bugs1353668
milestone55.0a1
Bug 1353668. P1 - add a member function, CopySegmentToCache. MozReview-Commit-ID: 5uEWpMigspX
dom/media/MediaResource.cpp
dom/media/MediaResource.h
--- a/dom/media/MediaResource.cpp
+++ b/dom/media/MediaResource.cpp
@@ -420,44 +420,51 @@ nsresult
 ChannelMediaResource::OnChannelRedirect(nsIChannel* aOld, nsIChannel* aNew,
                                         uint32_t aFlags)
 {
   mChannel = aNew;
   mSuspendAgent.NotifyChannelOpened(mChannel);
   return SetupChannelHeaders();
 }
 
+nsresult
+ChannelMediaResource::CopySegmentToCache(nsIPrincipal* aPrincipal,
+                                         const char* aFromSegment,
+                                         uint32_t aCount,
+                                         uint32_t* aWriteCount)
+{
+  mCallback->NotifyDataArrived();
+
+  // Keep track of where we're up to.
+  CMLOG("CopySegmentToCache at mOffset [%" PRId64 "] add "
+        "[%d] bytes for decoder[%p]",
+        mOffset, aCount, mCallback.get());
+  mOffset += aCount;
+  mCacheStream.NotifyDataReceived(aCount, aFromSegment, aPrincipal);
+  *aWriteCount = aCount;
+  return NS_OK;
+}
+
+
 struct CopySegmentClosure {
   nsCOMPtr<nsIPrincipal> mPrincipal;
   ChannelMediaResource*  mResource;
 };
 
 nsresult
-ChannelMediaResource::CopySegmentToCache(nsIInputStream *aInStream,
-                                         void *aClosure,
-                                         const char *aFromSegment,
+ChannelMediaResource::CopySegmentToCache(nsIInputStream* aInStream,
+                                         void* aClosure,
+                                         const char* aFromSegment,
                                          uint32_t aToOffset,
                                          uint32_t aCount,
-                                         uint32_t *aWriteCount)
+                                         uint32_t* aWriteCount)
 {
   CopySegmentClosure* closure = static_cast<CopySegmentClosure*>(aClosure);
-
-  closure->mResource->mCallback->NotifyDataArrived();
-
-  // Keep track of where we're up to.
-  RESOURCE_LOG("%p [ChannelMediaResource]: CopySegmentToCache at mOffset [%" PRId64 "] add "
-               "[%d] bytes for decoder[%p]",
-               closure->mResource, closure->mResource->mOffset, aCount,
-               closure->mResource->mCallback.get());
-  closure->mResource->mOffset += aCount;
-
-  closure->mResource->mCacheStream.NotifyDataReceived(aCount, aFromSegment,
-                                                      closure->mPrincipal);
-  *aWriteCount = aCount;
-  return NS_OK;
+  return closure->mResource->CopySegmentToCache(
+    closure->mPrincipal, aFromSegment, aCount, aWriteCount);
 }
 
 nsresult
 ChannelMediaResource::OnDataAvailable(nsIRequest* aRequest,
                                       nsIInputStream* aStream,
                                       uint32_t aCount)
 {
   NS_ASSERTION(mChannel.get() == aRequest, "Wrong channel!");
--- a/dom/media/MediaResource.h
+++ b/dom/media/MediaResource.h
@@ -653,22 +653,27 @@ protected:
   // values are out of range.
   nsresult ParseContentRangeHeader(nsIHttpChannel * aHttpChan,
                                    int64_t& aRangeStart,
                                    int64_t& aRangeEnd,
                                    int64_t& aRangeTotal);
 
   void DoNotifyDataReceived();
 
-  static nsresult CopySegmentToCache(nsIInputStream *aInStream,
-                                     void *aClosure,
-                                     const char *aFromSegment,
+  static nsresult CopySegmentToCache(nsIInputStream* aInStream,
+                                     void* aClosure,
+                                     const char* aFromSegment,
                                      uint32_t aToOffset,
                                      uint32_t aCount,
-                                     uint32_t *aWriteCount);
+                                     uint32_t* aWriteCount);
+
+  nsresult CopySegmentToCache(nsIPrincipal* aPrincipal,
+                              const char* aFromSegment,
+                              uint32_t aCount,
+                              uint32_t* aWriteCount);
 
   // Main thread access only
   int64_t            mOffset;
   RefPtr<Listener> mListener;
   // A data received event for the decoder that has been dispatched but has
   // not yet been processed.
   nsRevocableEventPtr<nsRunnableMethod<ChannelMediaResource, void, false> > mDataReceivedEvent;
   // When this flag is set, if we get a network error we should silently