OLD | NEW |
---|---|
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 25 matching lines...) Expand all Loading... | |
36 import java.util.ArrayList; | 36 import java.util.ArrayList; |
37 import java.util.List; | 37 import java.util.List; |
38 import java.util.concurrent.CountDownLatch; | 38 import java.util.concurrent.CountDownLatch; |
39 | 39 |
40 import static junit.framework.Assert.*; | 40 import static junit.framework.Assert.*; |
41 | 41 |
42 public class VideoCapturerAndroidTestFixtures { | 42 public class VideoCapturerAndroidTestFixtures { |
43 static class RendererCallbacks implements VideoRenderer.Callbacks { | 43 static class RendererCallbacks implements VideoRenderer.Callbacks { |
44 private int framesRendered = 0; | 44 private int framesRendered = 0; |
45 private Object frameLock = 0; | 45 private Object frameLock = 0; |
46 private int width = 0; | |
47 private int height = 0; | |
46 | 48 |
47 @Override | 49 @Override |
48 public void renderFrame(I420Frame frame) { | 50 public void renderFrame(I420Frame frame) { |
49 synchronized (frameLock) { | 51 synchronized (frameLock) { |
50 ++framesRendered; | 52 ++framesRendered; |
53 width = frame.rotatedWidth(); | |
54 height = frame.rotatedHeight(); | |
51 frameLock.notify(); | 55 frameLock.notify(); |
52 } | 56 } |
53 VideoRenderer.renderFrameDone(frame); | 57 VideoRenderer.renderFrameDone(frame); |
54 } | 58 } |
55 | 59 |
60 public int frameWidth() { | |
61 synchronized (frameLock) { | |
62 return width; | |
63 } | |
64 } | |
65 | |
66 public int frameHeight() { | |
67 synchronized (frameLock) { | |
68 return height; | |
69 } | |
70 } | |
71 | |
56 public int WaitForNextFrameToRender() throws InterruptedException { | 72 public int WaitForNextFrameToRender() throws InterruptedException { |
57 synchronized (frameLock) { | 73 synchronized (frameLock) { |
58 frameLock.wait(); | 74 frameLock.wait(); |
59 return framesRendered; | 75 return framesRendered; |
60 } | 76 } |
61 } | 77 } |
62 } | 78 } |
63 | 79 |
64 static class FakeAsyncRenderer implements VideoRenderer.Callbacks { | 80 static class FakeAsyncRenderer implements VideoRenderer.Callbacks { |
65 private final List<I420Frame> pendingFrames = new ArrayList<I420Frame>(); | 81 private final List<I420Frame> pendingFrames = new ArrayList<I420Frame>(); |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
534 // Since we don't call returnBuffer, we should get a starvation message. | 550 // Since we don't call returnBuffer, we should get a starvation message. |
535 assertEquals("Camera failure. Client must return video buffers.", events.Wai tForCameraError()); | 551 assertEquals("Camera failure. Client must return video buffers.", events.Wai tForCameraError()); |
536 | 552 |
537 capturer.stopCapture(); | 553 capturer.stopCapture(); |
538 for (long timeStamp : observer.getCopyAndResetListOftimeStamps()) { | 554 for (long timeStamp : observer.getCopyAndResetListOftimeStamps()) { |
539 capturer.returnBuffer(timeStamp); | 555 capturer.returnBuffer(timeStamp); |
540 } | 556 } |
541 capturer.dispose(); | 557 capturer.dispose(); |
542 assertTrue(capturer.isReleased()); | 558 assertTrue(capturer.isReleased()); |
543 } | 559 } |
560 | |
561 static public void scaleCameraOutput(VideoCapturerAndroid capturer) throws Int erruptedException { | |
562 PeerConnectionFactory factory = new PeerConnectionFactory(); | |
563 VideoSource source = | |
564 factory.createVideoSource(capturer, new MediaConstraints()); | |
565 VideoTrack track = factory.createVideoTrack("dummy", source); | |
566 RendererCallbacks renderer = new RendererCallbacks(); | |
567 track.addRenderer(new VideoRenderer(renderer)); | |
568 assertTrue(renderer.WaitForNextFrameToRender() > 0); | |
569 | |
570 final int startWidth = renderer.frameWidth(); | |
571 final int startHeight = renderer.frameHeight(); | |
572 final int frameRate = 30; | |
573 final int scaledWidth = startWidth / 2; | |
574 final int scaledHeight = startHeight / 2; | |
575 | |
576 // Request the captured frames to be scaled. | |
577 capturer.onOutputFormatRequest(scaledWidth, scaledHeight, frameRate); | |
magjed_webrtc
2015/11/26 10:08:33
I know why this works now. The order does not matt
perkj_webrtc
2015/11/26 10:56:14
Done.
| |
578 | |
579 boolean gotExpectedResolution = false; | |
580 int numberOfInspectedFrames = 0; | |
581 | |
582 do { | |
583 renderer.WaitForNextFrameToRender(); | |
584 ++numberOfInspectedFrames; | |
585 | |
586 gotExpectedResolution = (renderer.frameWidth() == scaledWidth | |
587 && renderer.frameHeight() == scaledHeight); | |
588 } while (!gotExpectedResolution && numberOfInspectedFrames < 30); | |
589 | |
590 source.stop(); | |
591 track.dispose(); | |
592 source.dispose(); | |
593 factory.dispose(); | |
594 assertTrue(capturer.isReleased()); | |
595 | |
596 assertTrue(gotExpectedResolution); | |
597 } | |
598 | |
544 } | 599 } |
OLD | NEW |