• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /**
16  * This class wraps a webrtc::I420BufferInterface into a VideoFrame.I420Buffer.
17  */
18 class WrappedNativeI420Buffer implements VideoFrame.I420Buffer {
19   private final int width;
20   private final int height;
21   private final ByteBuffer dataY;
22   private final int strideY;
23   private final ByteBuffer dataU;
24   private final int strideU;
25   private final ByteBuffer dataV;
26   private final int strideV;
27   private final long nativeBuffer;
28 
29   @CalledByNative
WrappedNativeI420Buffer(int width, int height, ByteBuffer dataY, int strideY, ByteBuffer dataU, int strideU, ByteBuffer dataV, int strideV, long nativeBuffer)30   WrappedNativeI420Buffer(int width, int height, ByteBuffer dataY, int strideY, ByteBuffer dataU,
31       int strideU, ByteBuffer dataV, int strideV, long nativeBuffer) {
32     this.width = width;
33     this.height = height;
34     this.dataY = dataY;
35     this.strideY = strideY;
36     this.dataU = dataU;
37     this.strideU = strideU;
38     this.dataV = dataV;
39     this.strideV = strideV;
40     this.nativeBuffer = nativeBuffer;
41 
42     retain();
43   }
44 
45   @Override
getWidth()46   public int getWidth() {
47     return width;
48   }
49 
50   @Override
getHeight()51   public int getHeight() {
52     return height;
53   }
54 
55   @Override
getDataY()56   public ByteBuffer getDataY() {
57     // Return a slice to prevent relative reads from changing the position.
58     return dataY.slice();
59   }
60 
61   @Override
getDataU()62   public ByteBuffer getDataU() {
63     // Return a slice to prevent relative reads from changing the position.
64     return dataU.slice();
65   }
66 
67   @Override
getDataV()68   public ByteBuffer getDataV() {
69     // Return a slice to prevent relative reads from changing the position.
70     return dataV.slice();
71   }
72 
73   @Override
getStrideY()74   public int getStrideY() {
75     return strideY;
76   }
77 
78   @Override
getStrideU()79   public int getStrideU() {
80     return strideU;
81   }
82 
83   @Override
getStrideV()84   public int getStrideV() {
85     return strideV;
86   }
87 
88   @Override
toI420()89   public VideoFrame.I420Buffer toI420() {
90     retain();
91     return this;
92   }
93 
94   @Override
retain()95   public void retain() {
96     JniCommon.nativeAddRef(nativeBuffer);
97   }
98 
99   @Override
release()100   public void release() {
101     JniCommon.nativeReleaseRef(nativeBuffer);
102   }
103 
104   @Override
cropAndScale( int cropX, int cropY, int cropWidth, int cropHeight, int scaleWidth, int scaleHeight)105   public VideoFrame.Buffer cropAndScale(
106       int cropX, int cropY, int cropWidth, int cropHeight, int scaleWidth, int scaleHeight) {
107     return JavaI420Buffer.cropAndScaleI420(
108         this, cropX, cropY, cropWidth, cropHeight, scaleWidth, scaleHeight);
109   }
110 }
111