OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2016 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 |
(...skipping 17 matching lines...) Expand all Loading... |
28 CVBufferRelease(pixel_buffer_); | 28 CVBufferRelease(pixel_buffer_); |
29 } | 29 } |
30 | 30 |
31 rtc::scoped_refptr<VideoFrameBuffer> | 31 rtc::scoped_refptr<VideoFrameBuffer> |
32 CoreVideoFrameBuffer::NativeToI420Buffer() { | 32 CoreVideoFrameBuffer::NativeToI420Buffer() { |
33 RTC_DCHECK(CVPixelBufferGetPixelFormatType(pixel_buffer_) == | 33 RTC_DCHECK(CVPixelBufferGetPixelFormatType(pixel_buffer_) == |
34 kCVPixelFormatType_420YpCbCr8BiPlanarFullRange); | 34 kCVPixelFormatType_420YpCbCr8BiPlanarFullRange); |
35 size_t width = CVPixelBufferGetWidthOfPlane(pixel_buffer_, 0); | 35 size_t width = CVPixelBufferGetWidthOfPlane(pixel_buffer_, 0); |
36 size_t height = CVPixelBufferGetHeightOfPlane(pixel_buffer_, 0); | 36 size_t height = CVPixelBufferGetHeightOfPlane(pixel_buffer_, 0); |
37 // TODO(tkchin): Use a frame buffer pool. | 37 // TODO(tkchin): Use a frame buffer pool. |
38 rtc::scoped_refptr<webrtc::I420Buffer> buffer = | 38 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer = |
39 new rtc::RefCountedObject<webrtc::I420Buffer>(width, height); | 39 new rtc::RefCountedObject<webrtc::I420Buffer>(width, height); |
40 CVPixelBufferLockBaseAddress(pixel_buffer_, kCVPixelBufferLock_ReadOnly); | 40 CVPixelBufferLockBaseAddress(pixel_buffer_, kCVPixelBufferLock_ReadOnly); |
41 const uint8_t* src_y = static_cast<const uint8_t*>( | 41 const uint8_t* src_y = static_cast<const uint8_t*>( |
42 CVPixelBufferGetBaseAddressOfPlane(pixel_buffer_, 0)); | 42 CVPixelBufferGetBaseAddressOfPlane(pixel_buffer_, 0)); |
43 int src_y_stride = CVPixelBufferGetBytesPerRowOfPlane(pixel_buffer_, 0); | 43 int src_y_stride = CVPixelBufferGetBytesPerRowOfPlane(pixel_buffer_, 0); |
44 const uint8_t* src_uv = static_cast<const uint8_t*>( | 44 const uint8_t* src_uv = static_cast<const uint8_t*>( |
45 CVPixelBufferGetBaseAddressOfPlane(pixel_buffer_, 1)); | 45 CVPixelBufferGetBaseAddressOfPlane(pixel_buffer_, 1)); |
46 int src_uv_stride = CVPixelBufferGetBytesPerRowOfPlane(pixel_buffer_, 1); | 46 int src_uv_stride = CVPixelBufferGetBytesPerRowOfPlane(pixel_buffer_, 1); |
47 int ret = libyuv::NV12ToI420( | 47 int ret = libyuv::NV12ToI420( |
48 src_y, src_y_stride, src_uv, src_uv_stride, | 48 src_y, src_y_stride, src_uv, src_uv_stride, |
49 buffer->MutableDataY(), buffer->StrideY(), | 49 buffer->MutableDataY(), buffer->StrideY(), |
50 buffer->MutableDataU(), buffer->StrideU(), | 50 buffer->MutableDataU(), buffer->StrideU(), |
51 buffer->MutableDataV(), buffer->StrideV(), | 51 buffer->MutableDataV(), buffer->StrideV(), |
52 width, height); | 52 width, height); |
53 CVPixelBufferUnlockBaseAddress(pixel_buffer_, kCVPixelBufferLock_ReadOnly); | 53 CVPixelBufferUnlockBaseAddress(pixel_buffer_, kCVPixelBufferLock_ReadOnly); |
54 if (ret) { | 54 if (ret) { |
55 LOG(LS_ERROR) << "Error converting NV12 to I420: " << ret; | 55 LOG(LS_ERROR) << "Error converting NV12 to I420: " << ret; |
56 return nullptr; | 56 return nullptr; |
57 } | 57 } |
58 return buffer; | 58 return buffer; |
59 } | 59 } |
60 | 60 |
61 } // namespace webrtc | 61 } // namespace webrtc |
OLD | NEW |