Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTestFixtures.java

Issue 1471333003: Add support for scaling textures in AndroidVideoCapturer. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: git cl format Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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.width;
magjed_webrtc 2015/11/25 13:38:28 Maybe use frame.rotatedWidth(), because you don't
perkj_webrtc 2015/11/25 20:56:20 Done.
54 height = frame.height;
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
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);
578
579 boolean gotExpectedResolution = false;
580 int numberOfInspectedFrames = 0;
581
582 do {
583 renderer.WaitForNextFrameToRender();
584 ++numberOfInspectedFrames;
585 // Check the frame size. The actual width and height depend on how the cap turer is mounted.
586 final boolean identicalResolution = (renderer.frameWidth() == scaledWidth
587 && renderer.frameHeight() == scaledHeight);
588 final boolean flippedResolution = (renderer.frameWidth() == scaledHeight
589 && renderer.frameHeight() == scaledWidth);
590
591 gotExpectedResolution = identicalResolution || flippedResolution;
592 } while (!gotExpectedResolution && numberOfInspectedFrames < 30);
593
594 source.stop();
595 track.dispose();
596 source.dispose();
597 factory.dispose();
598 assertTrue(capturer.isReleased());
599
600 assertTrue(gotExpectedResolution);
601 }
602
544 } 603 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698