| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 package org.webrtc; | 11 package org.webrtc; |
| 12 | 12 |
| 13 import java.nio.ByteBuffer; | 13 import java.nio.ByteBuffer; |
| 14 import org.webrtc.VideoFrame.I420Buffer; | 14 import org.webrtc.VideoFrame.I420Buffer; |
| 15 | 15 |
| 16 /** Implementation of an I420 VideoFrame buffer. */ | 16 /** Implementation of an I420 VideoFrame buffer. */ |
| 17 class I420BufferImpl implements VideoFrame.I420Buffer { | 17 class I420BufferImpl implements VideoFrame.I420Buffer { |
| 18 private final int width; | 18 private final int width; |
| 19 private final int height; | 19 private final int height; |
| 20 private final ByteBuffer dataY; | 20 private final ByteBuffer dataY; |
| 21 private final ByteBuffer dataU; | 21 private final ByteBuffer dataU; |
| 22 private final ByteBuffer dataV; | 22 private final ByteBuffer dataV; |
| 23 private final int strideY; | 23 private final int strideY; |
| 24 private final int strideU; | 24 private final int strideU; |
| 25 private final int strideV; | 25 private final int strideV; |
| 26 private final Runnable releaseCallback; | 26 private final Runnable releaseCallback; |
| 27 private final Object refCountLock = new Object(); |
| 27 | 28 |
| 28 private int refCount; | 29 private int refCount; |
| 29 | 30 |
| 30 /** Constructs an I420Buffer backed by existing data. */ | 31 /** Constructs an I420Buffer backed by existing data. */ |
| 31 I420BufferImpl(int width, int height, ByteBuffer dataY, int strideY, ByteBuffe
r dataU, | 32 I420BufferImpl(int width, int height, ByteBuffer dataY, int strideY, ByteBuffe
r dataU, |
| 32 int strideU, ByteBuffer dataV, int strideV, Runnable releaseCallback) { | 33 int strideU, ByteBuffer dataV, int strideV, Runnable releaseCallback) { |
| 33 this.width = width; | 34 this.width = width; |
| 34 this.height = height; | 35 this.height = height; |
| 35 this.dataY = dataY; | 36 this.dataY = dataY; |
| 36 this.dataU = dataU; | 37 this.dataU = dataU; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 } | 110 } |
| 110 | 111 |
| 111 @Override | 112 @Override |
| 112 public I420Buffer toI420() { | 113 public I420Buffer toI420() { |
| 113 retain(); | 114 retain(); |
| 114 return this; | 115 return this; |
| 115 } | 116 } |
| 116 | 117 |
| 117 @Override | 118 @Override |
| 118 public void retain() { | 119 public void retain() { |
| 119 ++refCount; | 120 synchronized (refCountLock) { |
| 121 ++refCount; |
| 122 } |
| 120 } | 123 } |
| 121 | 124 |
| 122 @Override | 125 @Override |
| 123 public void release() { | 126 public void release() { |
| 124 if (--refCount == 0 && releaseCallback != null) { | 127 synchronized (refCountLock) { |
| 125 releaseCallback.run(); | 128 if (--refCount == 0 && releaseCallback != null) { |
| 129 releaseCallback.run(); |
| 130 } |
| 126 } | 131 } |
| 127 } | 132 } |
| 128 | 133 |
| 129 @Override | 134 @Override |
| 130 public VideoFrame.Buffer cropAndScale( | 135 public VideoFrame.Buffer cropAndScale( |
| 131 int cropX, int cropY, int cropWidth, int cropHeight, int scaleWidth, int s
caleHeight) { | 136 int cropX, int cropY, int cropWidth, int cropHeight, int scaleWidth, int s
caleHeight) { |
| 132 return VideoFrame.cropAndScaleI420( | 137 return VideoFrame.cropAndScaleI420( |
| 133 this, cropX, cropY, cropWidth, cropHeight, scaleWidth, scaleHeight); | 138 this, cropX, cropY, cropWidth, cropHeight, scaleWidth, scaleHeight); |
| 134 } | 139 } |
| 135 } | 140 } |
| OLD | NEW |