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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 this.surface = surface; | 82 this.surface = surface; |
83 // Create an OpenGL ES 2.0 context. | 83 // Create an OpenGL ES 2.0 context. |
84 surface.setPreserveEGLContextOnPause(true); | 84 surface.setPreserveEGLContextOnPause(true); |
85 surface.setEGLContextClientVersion(2); | 85 surface.setEGLContextClientVersion(2); |
86 surface.setRenderer(this); | 86 surface.setRenderer(this); |
87 surface.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); | 87 surface.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); |
88 | 88 |
89 yuvImageRenderers = new ArrayList<YuvImageRenderer>(); | 89 yuvImageRenderers = new ArrayList<YuvImageRenderer>(); |
90 } | 90 } |
91 | 91 |
92 public static synchronized void dispose() { | |
93 if (instance == null){ | |
94 return; | |
95 } | |
96 synchronized (instance.yuvImageRenderers) { | |
97 for (YuvImageRenderer yuvImageRenderer : instance.yuvImageRenderers) { | |
98 yuvImageRenderer.release(); | |
99 } | |
100 instance.yuvImageRenderers.clear(); | |
101 if (instance.drawer != null) { | |
102 instance.drawer.release(); | |
103 } | |
104 } | |
105 instance.surface = null; | |
106 instance.eglContext = null; | |
107 instance.eglContextReady = null; | |
108 instance = null; | |
109 } | |
110 | |
111 /** | 92 /** |
112 * Class used to display stream of YUV420 frames at particular location | 93 * Class used to display stream of YUV420 frames at particular location |
113 * on a screen. New video frames are sent to display using renderFrame() | 94 * on a screen. New video frames are sent to display using renderFrame() |
114 * call. | 95 * call. |
115 */ | 96 */ |
116 private static class YuvImageRenderer implements VideoRenderer.Callbacks { | 97 private static class YuvImageRenderer implements VideoRenderer.Callbacks { |
117 // |surface| is synchronized on |this|. | 98 // |surface| is synchronized on |this|. |
118 private GLSurfaceView surface; | 99 private GLSurfaceView surface; |
119 private int id; | 100 private int id; |
120 private int[] yuvTextures = { -1, -1, -1 }; | 101 private int[] yuvTextures = { -1, -1, -1 }; |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 Runnable eglContextReadyCallback) { | 442 Runnable eglContextReadyCallback) { |
462 Log.d(TAG, "VideoRendererGui.setView"); | 443 Log.d(TAG, "VideoRendererGui.setView"); |
463 instance = new VideoRendererGui(surface); | 444 instance = new VideoRendererGui(surface); |
464 eglContextReady = eglContextReadyCallback; | 445 eglContextReady = eglContextReadyCallback; |
465 } | 446 } |
466 | 447 |
467 public static synchronized EGLContext getEGLContext() { | 448 public static synchronized EGLContext getEGLContext() { |
468 return eglContext; | 449 return eglContext; |
469 } | 450 } |
470 | 451 |
| 452 /** Releases GLSurfaceView video renderer. */ |
| 453 public static synchronized void dispose() { |
| 454 if (instance == null){ |
| 455 return; |
| 456 } |
| 457 Log.d(TAG, "VideoRendererGui.dispose"); |
| 458 synchronized (instance.yuvImageRenderers) { |
| 459 for (YuvImageRenderer yuvImageRenderer : instance.yuvImageRenderers) { |
| 460 yuvImageRenderer.release(); |
| 461 } |
| 462 instance.yuvImageRenderers.clear(); |
| 463 if (instance.drawer != null) { |
| 464 instance.drawer.release(); |
| 465 } |
| 466 } |
| 467 instance.surface = null; |
| 468 eglContext = null; |
| 469 eglContextReady = null; |
| 470 instance = null; |
| 471 } |
| 472 |
471 /** | 473 /** |
472 * Creates VideoRenderer with top left corner at (x, y) and resolution | 474 * Creates VideoRenderer with top left corner at (x, y) and resolution |
473 * (width, height). All parameters are in percentage of screen resolution. | 475 * (width, height). All parameters are in percentage of screen resolution. |
474 */ | 476 */ |
475 public static VideoRenderer createGui(int x, int y, int width, int height, | 477 public static VideoRenderer createGui(int x, int y, int width, int height, |
476 RendererCommon.ScalingType scalingType, boolean mirror) throws Exception { | 478 RendererCommon.ScalingType scalingType, boolean mirror) throws Exception { |
477 YuvImageRenderer javaGuiRenderer = create( | 479 YuvImageRenderer javaGuiRenderer = create( |
478 x, y, width, height, scalingType, mirror); | 480 x, y, width, height, scalingType, mirror); |
479 return new VideoRenderer(javaGuiRenderer); | 481 return new VideoRenderer(javaGuiRenderer); |
480 } | 482 } |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 GLES20.glViewport(0, 0, screenWidth, screenHeight); | 635 GLES20.glViewport(0, 0, screenWidth, screenHeight); |
634 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); | 636 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); |
635 synchronized (yuvImageRenderers) { | 637 synchronized (yuvImageRenderers) { |
636 for (YuvImageRenderer yuvImageRenderer : yuvImageRenderers) { | 638 for (YuvImageRenderer yuvImageRenderer : yuvImageRenderers) { |
637 yuvImageRenderer.draw(drawer); | 639 yuvImageRenderer.draw(drawer); |
638 } | 640 } |
639 } | 641 } |
640 } | 642 } |
641 | 643 |
642 } | 644 } |
OLD | NEW |