OLD | NEW |
(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 NV12Buffer implements VideoFrame.Buffer { |
| 16 private final int width; |
| 17 private final int height; |
| 18 private final int stride; |
| 19 private final int sliceHeight; |
| 20 private final ByteBuffer buffer; |
| 21 private final Runnable releaseCallback; |
| 22 |
| 23 private int refCount; |
| 24 |
| 25 public NV12Buffer(int width, int height, int stride, int sliceHeight, ByteBuff
er buffer, |
| 26 Runnable releaseCallback) { |
| 27 this.width = width; |
| 28 this.height = height; |
| 29 this.stride = stride; |
| 30 this.sliceHeight = sliceHeight; |
| 31 this.buffer = buffer; |
| 32 this.releaseCallback = releaseCallback; |
| 33 |
| 34 refCount = 1; |
| 35 } |
| 36 |
| 37 @Override |
| 38 public int getWidth() { |
| 39 return width; |
| 40 } |
| 41 |
| 42 @Override |
| 43 public int getHeight() { |
| 44 return height; |
| 45 } |
| 46 |
| 47 @Override |
| 48 public VideoFrame.I420Buffer toI420() { |
| 49 return (VideoFrame.I420Buffer) cropAndScale(0, 0, width, height, width, heig
ht); |
| 50 } |
| 51 |
| 52 @Override |
| 53 public void retain() { |
| 54 refCount++; |
| 55 } |
| 56 |
| 57 @Override |
| 58 public void release() { |
| 59 if (--refCount == 0) { |
| 60 releaseCallback.run(); |
| 61 } |
| 62 } |
| 63 |
| 64 @Override |
| 65 public VideoFrame.Buffer cropAndScale( |
| 66 int cropX, int cropY, int cropWidth, int cropHeight, int scaleWidth, int s
caleHeight) { |
| 67 I420BufferImpl newBuffer = I420BufferImpl.allocate(scaleWidth, scaleHeight); |
| 68 nativeCropAndScale(cropX, cropY, cropWidth, cropHeight, scaleWidth, scaleHei
ght, buffer, width, |
| 69 height, stride, sliceHeight, newBuffer.getDataY(), newBuffer.getStrideY(
), |
| 70 newBuffer.getDataU(), newBuffer.getStrideU(), newBuffer.getDataV(), newB
uffer.getStrideV()); |
| 71 return newBuffer; |
| 72 } |
| 73 |
| 74 private static native void nativeCropAndScale(int cropX, int cropY, int cropWi
dth, int cropHeight, |
| 75 int scaleWidth, int scaleHeight, ByteBuffer src, int srcWidth, int srcHeig
ht, int srcStride, |
| 76 int srcSliceHeight, ByteBuffer dstY, int dstStrideY, ByteBuffer dstU, int
dstStrideU, |
| 77 ByteBuffer dstV, int dstStrideV); |
| 78 } |
OLD | NEW |