| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 case kVideoMJPEG: | 51 case kVideoMJPEG: |
| 52 return kMJPG; | 52 return kMJPG; |
| 53 default: | 53 default: |
| 54 assert(false); | 54 assert(false); |
| 55 } | 55 } |
| 56 return kUnknown; | 56 return kUnknown; |
| 57 } | 57 } |
| 58 | 58 |
| 59 int AlignInt(int value, int alignment) { | 59 int AlignInt(int value, int alignment) { |
| 60 assert(!((alignment - 1) & alignment)); | 60 assert(!((alignment - 1) & alignment)); |
| 61 return ((value + alignment - 1) & ~ (alignment - 1)); | 61 return ((value + alignment - 1) & ~(alignment - 1)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void Calc16ByteAlignedStride(int width, int* stride_y, int* stride_uv) { | 64 void Calc16ByteAlignedStride(int width, int* stride_y, int* stride_uv) { |
| 65 *stride_y = AlignInt(width, k16ByteAlignment); | 65 *stride_y = AlignInt(width, k16ByteAlignment); |
| 66 *stride_uv = AlignInt((width + 1) / 2, k16ByteAlignment); | 66 *stride_uv = AlignInt((width + 1) / 2, k16ByteAlignment); |
| 67 } | 67 } |
| 68 | 68 |
| 69 size_t CalcBufferSize(VideoType type, int width, int height) { | 69 size_t CalcBufferSize(VideoType type, int width, int height) { |
| 70 assert(width >= 0); | 70 assert(width >= 0); |
| 71 assert(height >= 0); | 71 assert(height >= 0); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 int height = (planeNum ? (frame.height() + 1) / 2 : frame.height()); | 112 int height = (planeNum ? (frame.height() + 1) / 2 : frame.height()); |
| 113 PlaneType plane_type = static_cast<PlaneType>(planeNum); | 113 PlaneType plane_type = static_cast<PlaneType>(planeNum); |
| 114 const uint8_t* plane_buffer = frame.buffer(plane_type); | 114 const uint8_t* plane_buffer = frame.buffer(plane_type); |
| 115 for (int y = 0; y < height; y++) { | 115 for (int y = 0; y < height; y++) { |
| 116 if (fwrite(plane_buffer, 1, width, file) != | 116 if (fwrite(plane_buffer, 1, width, file) != |
| 117 static_cast<unsigned int>(width)) { | 117 static_cast<unsigned int>(width)) { |
| 118 return -1; | 118 return -1; |
| 119 } | 119 } |
| 120 plane_buffer += frame.stride(plane_type); | 120 plane_buffer += frame.stride(plane_type); |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 return 0; | 123 return 0; |
| 124 } | 124 } |
| 125 | 125 |
| 126 int ExtractBuffer(const VideoFrame& input_frame, size_t size, uint8_t* buffer) { | 126 int ExtractBuffer(const VideoFrame& input_frame, size_t size, uint8_t* buffer) { |
| 127 assert(buffer); | 127 assert(buffer); |
| 128 if (input_frame.IsZeroSize()) | 128 if (input_frame.IsZeroSize()) |
| 129 return -1; | 129 return -1; |
| 130 size_t length = | 130 size_t length = |
| 131 CalcBufferSize(kI420, input_frame.width(), input_frame.height()); | 131 CalcBufferSize(kI420, input_frame.width(), input_frame.height()); |
| 132 if (size < length) { | 132 if (size < length) { |
| 133 return -1; | 133 return -1; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 int ConvertRGB24ToARGB(const uint8_t* src_frame, uint8_t* dst_frame, | 169 int ConvertRGB24ToARGB(const uint8_t* src_frame, uint8_t* dst_frame, |
| 170 int width, int height, int dst_stride) { | 170 int width, int height, int dst_stride) { |
| 171 if (dst_stride == 0) | 171 if (dst_stride == 0) |
| 172 dst_stride = width; | 172 dst_stride = width; |
| 173 return libyuv::RGB24ToARGB(src_frame, width, | 173 return libyuv::RGB24ToARGB(src_frame, width, |
| 174 dst_frame, dst_stride, | 174 dst_frame, dst_stride, |
| 175 width, height); | 175 width, height); |
| 176 } | 176 } |
| 177 | 177 |
| 178 libyuv::RotationMode ConvertRotationMode(VideoRotation rotation) { | 178 libyuv::RotationMode ConvertRotationMode(VideoRotation rotation) { |
| 179 switch(rotation) { | 179 switch (rotation) { |
| 180 case kVideoRotation_0: | 180 case kVideoRotation_0: |
| 181 return libyuv::kRotate0; | 181 return libyuv::kRotate0; |
| 182 case kVideoRotation_90: | 182 case kVideoRotation_90: |
| 183 return libyuv::kRotate90; | 183 return libyuv::kRotate90; |
| 184 case kVideoRotation_180: | 184 case kVideoRotation_180: |
| 185 return libyuv::kRotate180; | 185 return libyuv::kRotate180; |
| 186 case kVideoRotation_270: | 186 case kVideoRotation_270: |
| 187 return libyuv::kRotate270; | 187 return libyuv::kRotate270; |
| 188 } | 188 } |
| 189 assert(false); | 189 assert(false); |
| 190 return libyuv::kRotate0; | 190 return libyuv::kRotate0; |
| 191 } | 191 } |
| 192 | 192 |
| 193 int ConvertVideoType(VideoType video_type) { | 193 int ConvertVideoType(VideoType video_type) { |
| 194 switch(video_type) { | 194 switch (video_type) { |
| 195 case kUnknown: | 195 case kUnknown: |
| 196 return libyuv::FOURCC_ANY; | 196 return libyuv::FOURCC_ANY; |
| 197 case kI420: | 197 case kI420: |
| 198 return libyuv::FOURCC_I420; | 198 return libyuv::FOURCC_I420; |
| 199 case kIYUV: // same as KYV12 | 199 case kIYUV: // same as KYV12 |
| 200 case kYV12: | 200 case kYV12: |
| 201 return libyuv::FOURCC_YV12; | 201 return libyuv::FOURCC_YV12; |
| 202 case kRGB24: | 202 case kRGB24: |
| 203 return libyuv::FOURCC_24BG; | 203 return libyuv::FOURCC_24BG; |
| 204 case kABGR: | 204 case kABGR: |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 int src_height, | 236 int src_height, |
| 237 size_t sample_size, | 237 size_t sample_size, |
| 238 VideoRotation rotation, | 238 VideoRotation rotation, |
| 239 VideoFrame* dst_frame) { | 239 VideoFrame* dst_frame) { |
| 240 int dst_width = dst_frame->width(); | 240 int dst_width = dst_frame->width(); |
| 241 int dst_height = dst_frame->height(); | 241 int dst_height = dst_frame->height(); |
| 242 // LibYuv expects pre-rotation values for dst. | 242 // LibYuv expects pre-rotation values for dst. |
| 243 // Stride values should correspond to the destination values. | 243 // Stride values should correspond to the destination values. |
| 244 if (rotation == kVideoRotation_90 || rotation == kVideoRotation_270) { | 244 if (rotation == kVideoRotation_90 || rotation == kVideoRotation_270) { |
| 245 dst_width = dst_frame->height(); | 245 dst_width = dst_frame->height(); |
| 246 dst_height =dst_frame->width(); | 246 dst_height = dst_frame->width(); |
| 247 } | 247 } |
| 248 return libyuv::ConvertToI420(src_frame, sample_size, | 248 return libyuv::ConvertToI420(src_frame, sample_size, |
| 249 dst_frame->buffer(kYPlane), | 249 dst_frame->buffer(kYPlane), |
| 250 dst_frame->stride(kYPlane), | 250 dst_frame->stride(kYPlane), |
| 251 dst_frame->buffer(kUPlane), | 251 dst_frame->buffer(kUPlane), |
| 252 dst_frame->stride(kUPlane), | 252 dst_frame->stride(kUPlane), |
| 253 dst_frame->buffer(kVPlane), | 253 dst_frame->buffer(kVPlane), |
| 254 dst_frame->stride(kVPlane), | 254 dst_frame->stride(kVPlane), |
| 255 crop_x, crop_y, | 255 crop_x, crop_y, |
| 256 src_width, src_height, | 256 src_width, src_height, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 ref_frame->stride(kVPlane), | 337 ref_frame->stride(kVPlane), |
| 338 test_frame->buffer(kYPlane), | 338 test_frame->buffer(kYPlane), |
| 339 test_frame->stride(kYPlane), | 339 test_frame->stride(kYPlane), |
| 340 test_frame->buffer(kUPlane), | 340 test_frame->buffer(kUPlane), |
| 341 test_frame->stride(kUPlane), | 341 test_frame->stride(kUPlane), |
| 342 test_frame->buffer(kVPlane), | 342 test_frame->buffer(kVPlane), |
| 343 test_frame->stride(kVPlane), | 343 test_frame->stride(kVPlane), |
| 344 test_frame->width(), test_frame->height()); | 344 test_frame->width(), test_frame->height()); |
| 345 } | 345 } |
| 346 } // namespace webrtc | 346 } // namespace webrtc |
| OLD | NEW |