OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 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 24 matching lines...) Expand all Loading... |
35 | 35 |
36 import android.annotation.SuppressLint; | 36 import android.annotation.SuppressLint; |
37 import android.graphics.Point; | 37 import android.graphics.Point; |
38 import android.graphics.Rect; | 38 import android.graphics.Rect; |
39 import android.graphics.SurfaceTexture; | 39 import android.graphics.SurfaceTexture; |
40 import android.opengl.EGL14; | 40 import android.opengl.EGL14; |
41 import android.opengl.EGLContext; | 41 import android.opengl.EGLContext; |
42 import android.opengl.GLES20; | 42 import android.opengl.GLES20; |
43 import android.opengl.GLSurfaceView; | 43 import android.opengl.GLSurfaceView; |
44 import android.opengl.Matrix; | 44 import android.opengl.Matrix; |
45 import android.util.Log; | |
46 | 45 |
47 import org.webrtc.Logging; | 46 import org.webrtc.Logging; |
48 import org.webrtc.VideoRenderer.I420Frame; | 47 import org.webrtc.VideoRenderer.I420Frame; |
49 | 48 |
50 /** | 49 /** |
51 * Efficiently renders YUV frames using the GPU for CSC. | 50 * Efficiently renders YUV frames using the GPU for CSC. |
52 * Clients will want first to call setView() to pass GLSurfaceView | 51 * Clients will want first to call setView() to pass GLSurfaceView |
53 * and then for each video stream either create instance of VideoRenderer using | 52 * and then for each video stream either create instance of VideoRenderer using |
54 * createGui() call or VideoRenderer.Callbacks interface using create() call. | 53 * createGui() call or VideoRenderer.Callbacks interface using create() call. |
55 * Only one instance of the class can be created. | 54 * Only one instance of the class can be created. |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 Logging.d(TAG, "YuvImageRenderer.Create id: " + id); | 164 Logging.d(TAG, "YuvImageRenderer.Create id: " + id); |
166 this.surface = surface; | 165 this.surface = surface; |
167 this.id = id; | 166 this.id = id; |
168 this.scalingType = scalingType; | 167 this.scalingType = scalingType; |
169 this.mirror = mirror; | 168 this.mirror = mirror; |
170 layoutInPercentage = new Rect(x, y, Math.min(100, x + width), Math.min(100
, y + height)); | 169 layoutInPercentage = new Rect(x, y, Math.min(100, x + width), Math.min(100
, y + height)); |
171 updateLayoutProperties = false; | 170 updateLayoutProperties = false; |
172 rotationDegree = 0; | 171 rotationDegree = 0; |
173 } | 172 } |
174 | 173 |
| 174 public synchronized void reset() { |
| 175 seenFrame = false; |
| 176 } |
| 177 |
175 private synchronized void release() { | 178 private synchronized void release() { |
176 surface = null; | 179 surface = null; |
177 synchronized (pendingFrameLock) { | 180 synchronized (pendingFrameLock) { |
178 if (pendingFrame != null) { | 181 if (pendingFrame != null) { |
179 VideoRenderer.renderFrameDone(pendingFrame); | 182 VideoRenderer.renderFrameDone(pendingFrame); |
180 pendingFrame = null; | 183 pendingFrame = null; |
181 } | 184 } |
182 } | 185 } |
183 } | 186 } |
184 | 187 |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 yuvImageRenderer.rendererEvents = rendererEvents; | 545 yuvImageRenderer.rendererEvents = rendererEvents; |
543 } | 546 } |
544 } | 547 } |
545 } | 548 } |
546 } | 549 } |
547 | 550 |
548 public static synchronized void remove(VideoRenderer.Callbacks renderer) { | 551 public static synchronized void remove(VideoRenderer.Callbacks renderer) { |
549 Logging.d(TAG, "VideoRendererGui.remove"); | 552 Logging.d(TAG, "VideoRendererGui.remove"); |
550 if (instance == null) { | 553 if (instance == null) { |
551 throw new RuntimeException( | 554 throw new RuntimeException( |
552 "Attempt to remove yuv renderer before setting GLSurfaceView"); | 555 "Attempt to remove renderer before setting GLSurfaceView"); |
553 } | 556 } |
554 synchronized (instance.yuvImageRenderers) { | 557 synchronized (instance.yuvImageRenderers) { |
555 final int index = instance.yuvImageRenderers.indexOf(renderer); | 558 final int index = instance.yuvImageRenderers.indexOf(renderer); |
556 if (index == -1) { | 559 if (index == -1) { |
557 Logging.w(TAG, "Couldn't remove renderer (not present in current list)")
; | 560 Logging.w(TAG, "Couldn't remove renderer (not present in current list)")
; |
558 } else { | 561 } else { |
559 instance.yuvImageRenderers.remove(index).release(); | 562 instance.yuvImageRenderers.remove(index).release(); |
560 } | 563 } |
561 } | 564 } |
562 } | 565 } |
563 | 566 |
| 567 public static synchronized void reset(VideoRenderer.Callbacks renderer) { |
| 568 Logging.d(TAG, "VideoRendererGui.reset"); |
| 569 if (instance == null) { |
| 570 throw new RuntimeException( |
| 571 "Attempt to reset renderer before setting GLSurfaceView"); |
| 572 } |
| 573 synchronized (instance.yuvImageRenderers) { |
| 574 for (YuvImageRenderer yuvImageRenderer : instance.yuvImageRenderers) { |
| 575 if (yuvImageRenderer == renderer) { |
| 576 yuvImageRenderer.reset(); |
| 577 } |
| 578 } |
| 579 } |
| 580 } |
| 581 |
564 @SuppressLint("NewApi") | 582 @SuppressLint("NewApi") |
565 @Override | 583 @Override |
566 public void onSurfaceCreated(GL10 unused, EGLConfig config) { | 584 public void onSurfaceCreated(GL10 unused, EGLConfig config) { |
567 Logging.d(TAG, "VideoRendererGui.onSurfaceCreated"); | 585 Logging.d(TAG, "VideoRendererGui.onSurfaceCreated"); |
568 // Store render EGL context. | 586 // Store render EGL context. |
569 if (CURRENT_SDK_VERSION >= EGL14_SDK_VERSION) { | 587 if (CURRENT_SDK_VERSION >= EGL14_SDK_VERSION) { |
570 synchronized (VideoRendererGui.class) { | 588 synchronized (VideoRendererGui.class) { |
571 eglContext = EGL14.eglGetCurrentContext(); | 589 eglContext = EGL14.eglGetCurrentContext(); |
572 Logging.d(TAG, "VideoRendererGui EGL Context: " + eglContext); | 590 Logging.d(TAG, "VideoRendererGui EGL Context: " + eglContext); |
573 } | 591 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 GLES20.glViewport(0, 0, screenWidth, screenHeight); | 630 GLES20.glViewport(0, 0, screenWidth, screenHeight); |
613 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); | 631 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); |
614 synchronized (yuvImageRenderers) { | 632 synchronized (yuvImageRenderers) { |
615 for (YuvImageRenderer yuvImageRenderer : yuvImageRenderers) { | 633 for (YuvImageRenderer yuvImageRenderer : yuvImageRenderers) { |
616 yuvImageRenderer.draw(drawer); | 634 yuvImageRenderer.draw(drawer); |
617 } | 635 } |
618 } | 636 } |
619 } | 637 } |
620 | 638 |
621 } | 639 } |
OLD | NEW |