Bug 1166832 - Adding test to verify video (using capture stream) after renegotiation. draft
authorMichael Froman <mfroman@mozilla.com>
Mon, 11 Jan 2016 11:09:40 -0600
changeset 320518 49ab28aad6918fca358ad90cf28acdb86dded705
parent 320517 4def1b05ece7e7d3a03ae3433417c32b8b3d2bc3
child 321546 d12fa9c3bb6acf28e4414a8640f0ab2a0bdf5240
push id9220
push usermfroman@nostrum.com
push dateMon, 11 Jan 2016 18:00:40 +0000
bugs1166832
milestone46.0a1
Bug 1166832 - Adding test to verify video (using capture stream) after renegotiation.
dom/media/tests/mochitest/mochitest.ini
dom/media/tests/mochitest/test_peerConnection_verifyAfterRenegotiation.html
media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -204,16 +204,19 @@ skip-if = toolkit == 'gonk' || (android_
 skip-if = toolkit == 'gonk' || android_version == '18'
 [test_peerConnection_removeThenAddVideoTrackNoBundle.html]
 # B2G emulator is too slow to finish a renegotiation test in under 5 minutes, Bug 1180000 for Linux debug e10s, android(Bug 1189784, timeouts on 4.3 emulator)
 skip-if = toolkit == 'gonk' || android_version == '18'
 [test_peerConnection_addDataChannel.html]
 skip-if = toolkit == 'gonk' # B2G emulator seems to be so slow that DTLS cannot establish properly
 [test_peerConnection_addDataChannelNoBundle.html]
 skip-if = toolkit == 'gonk' # B2G emulator seems to be so slow that DTLS cannot establish properly
+[test_peerConnection_verifyAfterRenegotiation.html]
+# B2G emulator is too slow to finish a renegotiation test in under 5 minutes, Bug 1180000 for Linux debug e10s, android(Bug 1189784, timeouts on 4.3 emulator)
+skip-if = toolkit == 'gonk' || android_version == '18'
 [test_peerConnection_webAudio.html]
 tags = webaudio webrtc
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' # b2g (Bug 1059867)
 [test_peerConnection_localRollback.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' # b2g (Bug 1059867)
 [test_peerConnection_localReofferRollback.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' # b2g (Bug 1059867)
 [test_peerConnection_remoteRollback.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_peerConnection_verifyAfterRenegotiation.html
@@ -0,0 +1,100 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <script type="application/javascript" src="pc.js"></script>
+  <script type="application/javascript" src="/tests/dom/canvas/test/captureStream_common.js"></script>
+</head>
+<body>
+<pre id="test">
+<script type="application/javascript">
+  createHTML({
+    bug: "1017888",
+    title: "Renegotiation: add second video stream"
+  });
+
+runNetworkTest(() => {
+  var test = new PeerConnectionTest();
+
+  var h1 = new CaptureStreamTestHelper2D(50, 50);
+  var canvas1 = h1.createAndAppendElement('canvas', 'source_canvas1');
+  var stream1;
+  var vremote1;
+
+  var h2 = new CaptureStreamTestHelper2D(50, 50);
+  var canvas2;
+  var stream2;
+  var vremote2;
+
+  test.setMediaConstraints([{video: true}], []);
+  test.chain.replace("PC_LOCAL_GUM", [
+    function DRAW_INITIAL_LOCAL_GREEN(test) {
+      h1.drawColor(canvas1, h1.green);
+    },
+    function PC_LOCAL_CANVAS_CAPTURESTREAM(test) {
+      stream1 = canvas1.captureStream(0);
+      test.pcLocal.attachMedia(stream1, 'video', 'local');
+    }
+  ]);
+
+  test.chain.append([
+    function FIND_REMOTE_VIDEO() {
+      vremote1 = document.getElementById('pcRemote_remote1_video');
+      ok(!!vremote1, "Should have remote video element for pcRemote");
+    },
+    function WAIT_FOR_REMOTE_GREEN() {
+      return h1.waitForPixelColor(vremote1, h1.green, 128,
+                                 "pcRemote's remote should become green");
+    },
+    function DRAW_LOCAL_RED() {
+      // After requesting a frame it will be captured at the time of next render.
+      // Next render will happen at next stable state, at the earliest,
+      // i.e., this order of `requestFrame(); draw();` should work.
+      stream1.requestFrame();
+      h1.drawColor(canvas1, h1.red);
+    },
+    function WAIT_FOR_REMOTE_RED() {
+      return h1.waitForPixelColor(vremote1, h1.red, 128,
+                                 "pcRemote's remote should become red");
+    }
+  ]);
+
+  addRenegotiation(test.chain,
+    [
+      function PC_LOCAL_ADD_SECOND_STREAM(test) {
+        canvas2 = h2.createAndAppendElement('canvas', 'source_canvas2');
+        h2.drawColor(canvas2, h2.blue);
+        stream2 = canvas2.captureStream(0);
+
+        // can't use test.pcLocal.getAllUserMedia([{video: true}]);
+        // because it doesn't let us substitute the capture stream
+        return test.pcLocal.attachMedia(stream2, 'video', 'local');
+      }
+    ]
+  );
+
+  test.chain.append([
+    function FIND_REMOTE2_VIDEO() {
+      vremote2 = document.getElementById('pcRemote_remote2_video');
+      ok(!!vremote2, "Should have remote2 video element for pcRemote");
+    },
+    function WAIT_FOR_REMOTE2_BLUE() {
+      return h2.waitForPixelColor(vremote2, h2.blue, 128,
+                                 "pcRemote's remote2 should become blue");
+    },
+    function DRAW_NEW_LOCAL_GREEN(test) {
+      stream1.requestFrame();
+      h1.drawColor(canvas1, h1.green);
+    },
+    function WAIT_FOR_REMOTE1_GREEN() {
+      return h1.waitForPixelColor(vremote1, h1.green, 128,
+                                 "pcRemote's remote1 should become green");
+    }
+  ]);
+
+  test.run();
+});
+
+</script>
+</pre>
+</body>
+</html>
--- a/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
+++ b/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
@@ -1139,27 +1139,31 @@ WebrtcVideoConduit::SelectSendResolution
   }
 
 
   // Adapt to getUserMedia resolution changes
   // check if we need to reconfigure the sending resolution.
   bool changed = false;
   if (mSendingWidth != width || mSendingHeight != height)
   {
+    CSFLogDebug(logTag, "%s: resolution changing to %ux%u (from %ux%u)",
+                __FUNCTION__, width, height, mSendingWidth, mSendingHeight);
     // This will avoid us continually retrying this operation if it fails.
     // If the resolution changes, we'll try again.  In the meantime, we'll
     // keep using the old size in the encoder.
     mSendingWidth = width;
     mSendingHeight = height;
     changed = true;
   }
 
   // uses mSendingWidth/Height
   unsigned int framerate = SelectSendFrameRate(mSendingFramerate);
   if (mSendingFramerate != framerate) {
+    CSFLogDebug(logTag, "%s: framerate changing to %u (from %u)",
+                __FUNCTION__, framerate, mSendingFramerate);
     mSendingFramerate = framerate;
     changed = true;
   }
 
   if (changed) {
     // On a resolution change, bounce this to the correct thread to
     // re-configure (same as used for Init().  Do *not* block the calling
     // thread since that may be the MSG thread.
@@ -1216,16 +1220,20 @@ WebrtcVideoConduit::ReconfigureSendCodec
   int32_t err;
 
   mInReconfig = false;
   if ((err = mPtrViECodec->GetSendCodec(mChannel, vie_codec)) != 0)
   {
     CSFLogError(logTag, "%s: GetSendCodec failed, err %d", __FUNCTION__, err);
     return NS_ERROR_FAILURE;
   }
+
+  CSFLogDebug(logTag,
+              "%s: Requesting resolution change to %ux%u (from %ux%u)",
+              __FUNCTION__, width, height, vie_codec.width, vie_codec.height);
   // Likely spurious unless there was some error, but rarely checked
   if (vie_codec.width != width || vie_codec.height != height ||
       vie_codec.maxFramerate != mSendingFramerate)
   {
     vie_codec.width = width;
     vie_codec.height = height;
     vie_codec.maxFramerate = mSendingFramerate;
     SelectBandwidth(vie_codec, width, height, mLastFramerateTenths);
@@ -1392,16 +1400,18 @@ WebrtcVideoConduit::SendVideoFrame(webrt
   // Don't compate mSendingWidth/Height, since those may not be the same as the input.
   {
     MutexAutoLock lock(mCodecMutex);
     if (mInReconfig) {
       // Waiting for it to finish
       return kMediaConduitNoError;
     }
     if (frame.width() != mLastWidth || frame.height() != mLastHeight) {
+      CSFLogDebug(logTag, "%s: call SelectSendResolution with %ux%u",
+                  __FUNCTION__, frame.width(), frame.height());
       if (SelectSendResolution(frame.width(), frame.height(), &frame)) {
         // SelectSendResolution took ownership of the data in i420_frame.
         // Submit the frame after reconfig is done
         return kMediaConduitNoError;
       }
     }
   }
   mPtrExtCapture->IncomingFrame(frame);