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

Side by Side Diff: webrtc/sdk/android/src/java/org/webrtc/NV21Buffer.java

Issue 2984633002: Add a field trial to produce VideoFrames in camera capturers. (Closed)
Patch Set: Rebase Created 3 years, 4 months 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
(Empty)
1 /*
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 package org.webrtc;
12
13 import java.nio.ByteBuffer;
14
15 public class NV21Buffer implements VideoFrame.Buffer {
magjed_webrtc 2017/08/22 08:53:08 Maybe you want to land this class in a separate CL
sakal 2017/08/22 11:45:30 Acknowledged but let's land this with the other co
16 private final byte[] data;
17 private final int width;
18 private final int height;
19 private final Runnable releaseCallback;
20 private final Object refCountLock = new Object();
21
22 private int refCount = 1;
23
24 public NV21Buffer(byte[] data, int width, int height, Runnable releaseCallback ) {
25 this.data = data;
26 this.width = width;
27 this.height = height;
28 this.releaseCallback = releaseCallback;
29 }
30
31 @Override
32 public int getWidth() {
33 return width;
34 }
35
36 @Override
37 public int getHeight() {
38 return height;
39 }
40
41 @Override
42 public VideoFrame.I420Buffer toI420() {
43 return (VideoFrame.I420Buffer) cropAndScale(0, 0, width, height, width, heig ht);
magjed_webrtc 2017/08/22 08:53:08 Comment the literals.
sakal 2017/08/22 11:45:30 Done.
44 }
45
46 @Override
47 public void retain() {
48 synchronized (refCountLock) {
49 ++refCount;
50 }
51 }
52
53 @Override
54 public void release() {
55 synchronized (refCountLock) {
56 if (--refCount == 0 && releaseCallback != null) {
57 releaseCallback.run();
58 }
59 }
60 }
61
62 @Override
63 public VideoFrame.Buffer cropAndScale(
64 int cropX, int cropY, int cropWidth, int cropHeight, int scaleWidth, int s caleHeight) {
65 I420BufferImpl newBuffer = I420BufferImpl.allocate(scaleWidth, scaleHeight);
66 nativeCropAndScale(cropX, cropY, cropWidth, cropHeight, scaleWidth, scaleHei ght, data, width,
67 height, newBuffer.getDataY(), newBuffer.getStrideY(), newBuffer.getDataU (),
68 newBuffer.getStrideU(), newBuffer.getDataV(), newBuffer.getStrideV());
69 return newBuffer;
70 }
71
72 private static native void nativeCropAndScale(int cropX, int cropY, int cropWi dth, int cropHeight,
73 int scaleWidth, int scaleHeight, byte[] src, int srcWidth, int srcHeight, ByteBuffer dstY,
74 int dstStrideY, ByteBuffer dstU, int dstStrideU, ByteBuffer dstV, int dstS trideV);
75 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698