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

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

Issue 1422963003: Android MediaCodecVideoDecoder: Manage lifetime of texture frames (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressed magjeds comments. Created 5 years, 1 month 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
« no previous file with comments | « talk/app/webrtc/java/src/org/webrtc/MediaCodecVideoDecoder.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 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 28 matching lines...) Expand all
39 /** 39 /**
40 * Java version of cricket::VideoFrame. Frames are only constructed from nativ e code and test 40 * Java version of cricket::VideoFrame. Frames are only constructed from nativ e code and test
41 * code. 41 * code.
42 */ 42 */
43 public static class I420Frame { 43 public static class I420Frame {
44 public final int width; 44 public final int width;
45 public final int height; 45 public final int height;
46 public final int[] yuvStrides; 46 public final int[] yuvStrides;
47 public ByteBuffer[] yuvPlanes; 47 public ByteBuffer[] yuvPlanes;
48 public final boolean yuvFrame; 48 public final boolean yuvFrame;
49 public Object textureObject; 49 // Matrix that transforms standard coordinates to their proper sampling loca tions in
50 // the texture. This transform compensates for any properties of the video s ource that
51 // cause it to appear different from a normalized texture. This matrix does not take
52 // |rotationDegree| into account.
53 public final float[] samplingMatrix;
50 public int textureId; 54 public int textureId;
51 // Frame pointer in C++. 55 // Frame pointer in C++.
52 private long nativeFramePointer; 56 private long nativeFramePointer;
53 57
54 // rotationDegree is the degree that the frame must be rotated clockwisely 58 // rotationDegree is the degree that the frame must be rotated clockwisely
55 // to be rendered correctly. 59 // to be rendered correctly.
56 public int rotationDegree; 60 public int rotationDegree;
57 61
58 /** 62 /**
59 * Construct a frame of the given dimensions with the specified planar data. 63 * Construct a frame of the given dimensions with the specified planar data.
60 */ 64 */
61 I420Frame(int width, int height, int rotationDegree, int[] yuvStrides, ByteB uffer[] yuvPlanes, 65 I420Frame(int width, int height, int rotationDegree, int[] yuvStrides, ByteB uffer[] yuvPlanes,
62 long nativeFramePointer) { 66 long nativeFramePointer) {
63 this.width = width; 67 this.width = width;
64 this.height = height; 68 this.height = height;
65 this.yuvStrides = yuvStrides; 69 this.yuvStrides = yuvStrides;
66 this.yuvPlanes = yuvPlanes; 70 this.yuvPlanes = yuvPlanes;
67 this.yuvFrame = true; 71 this.yuvFrame = true;
68 this.rotationDegree = rotationDegree; 72 this.rotationDegree = rotationDegree;
69 this.nativeFramePointer = nativeFramePointer; 73 this.nativeFramePointer = nativeFramePointer;
70 if (rotationDegree % 90 != 0) { 74 if (rotationDegree % 90 != 0) {
71 throw new IllegalArgumentException("Rotation degree not multiple of 90: " + rotationDegree); 75 throw new IllegalArgumentException("Rotation degree not multiple of 90: " + rotationDegree);
72 } 76 }
77 // The convention in WebRTC is that the first element in a ByteBuffer corr esponds to the
78 // top-left corner of the image, but in glTexImage2D() the first element c orresponds to the
79 // bottom-left corner. This discrepancy is corrected by setting a vertical flip as sampling
80 // matrix.
81 samplingMatrix = new float[] {
82 1, 0, 0, 0,
83 0, -1, 0, 0,
84 0, 0, 1, 0,
85 0, 1, 0, 1};
73 } 86 }
74 87
75 /** 88 /**
76 * Construct a texture frame of the given dimensions with data in SurfaceTex ture 89 * Construct a texture frame of the given dimensions with data in SurfaceTex ture
77 */ 90 */
78 I420Frame( 91 I420Frame(int width, int height, int rotationDegree, int textureId, float[] samplingMatrix,
79 int width, int height, int rotationDegree, 92 long nativeFramePointer) {
80 Object textureObject, int textureId, long nativeFramePointer) {
81 this.width = width; 93 this.width = width;
82 this.height = height; 94 this.height = height;
83 this.yuvStrides = null; 95 this.yuvStrides = null;
84 this.yuvPlanes = null; 96 this.yuvPlanes = null;
85 this.textureObject = textureObject; 97 this.samplingMatrix = samplingMatrix;
86 this.textureId = textureId; 98 this.textureId = textureId;
87 this.yuvFrame = false; 99 this.yuvFrame = false;
88 this.rotationDegree = rotationDegree; 100 this.rotationDegree = rotationDegree;
89 this.nativeFramePointer = nativeFramePointer; 101 this.nativeFramePointer = nativeFramePointer;
90 if (rotationDegree % 90 != 0) { 102 if (rotationDegree % 90 != 0) {
91 throw new IllegalArgumentException("Rotation degree not multiple of 90: " + rotationDegree); 103 throw new IllegalArgumentException("Rotation degree not multiple of 90: " + rotationDegree);
92 } 104 }
93 } 105 }
94 106
95 public int rotatedWidth() { 107 public int rotatedWidth() {
(...skipping 22 matching lines...) Expand all
118 // is responsible for signaling when it is done with |frame| by calling 130 // is responsible for signaling when it is done with |frame| by calling
119 // renderFrameDone(frame). 131 // renderFrameDone(frame).
120 public void renderFrame(I420Frame frame); 132 public void renderFrame(I420Frame frame);
121 } 133 }
122 134
123 /** 135 /**
124 * This must be called after every renderFrame() to release the frame. 136 * This must be called after every renderFrame() to release the frame.
125 */ 137 */
126 public static void renderFrameDone(I420Frame frame) { 138 public static void renderFrameDone(I420Frame frame) {
127 frame.yuvPlanes = null; 139 frame.yuvPlanes = null;
128 frame.textureObject = null;
129 frame.textureId = 0; 140 frame.textureId = 0;
130 if (frame.nativeFramePointer != 0) { 141 if (frame.nativeFramePointer != 0) {
131 releaseNativeFrame(frame.nativeFramePointer); 142 releaseNativeFrame(frame.nativeFramePointer);
132 frame.nativeFramePointer = 0; 143 frame.nativeFramePointer = 0;
133 } 144 }
134 } 145 }
135 146
136 // |this| either wraps a native (GUI) renderer or a client-supplied Callbacks 147 // |this| either wraps a native (GUI) renderer or a client-supplied Callbacks
137 // (Java) implementation; this is indicated by |isWrappedVideoRenderer|. 148 // (Java) implementation; this is indicated by |isWrappedVideoRenderer|.
138 long nativeVideoRenderer; 149 long nativeVideoRenderer;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 } 181 }
171 182
172 private static native long nativeCreateGuiVideoRenderer(int x, int y); 183 private static native long nativeCreateGuiVideoRenderer(int x, int y);
173 private static native long nativeWrapVideoRenderer(Callbacks callbacks); 184 private static native long nativeWrapVideoRenderer(Callbacks callbacks);
174 185
175 private static native void freeGuiVideoRenderer(long nativeVideoRenderer); 186 private static native void freeGuiVideoRenderer(long nativeVideoRenderer);
176 private static native void freeWrappedVideoRenderer(long nativeVideoRenderer); 187 private static native void freeWrappedVideoRenderer(long nativeVideoRenderer);
177 188
178 private static native void releaseNativeFrame(long nativeFramePointer); 189 private static native void releaseNativeFrame(long nativeFramePointer);
179 } 190 }
OLDNEW
« no previous file with comments | « talk/app/webrtc/java/src/org/webrtc/MediaCodecVideoDecoder.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698