OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 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 #include "webrtc/media/base/videoframe.h" | 11 #include "webrtc/media/base/videoframe.h" |
12 | 12 |
13 #include <string.h> | 13 #include <string.h> |
14 | 14 |
15 #include "libyuv/compare.h" | 15 #include "libyuv/compare.h" |
16 #include "libyuv/planar_functions.h" | 16 #include "libyuv/planar_functions.h" |
17 #include "libyuv/scale.h" | 17 #include "libyuv/scale.h" |
18 #include "webrtc/base/arraysize.h" | 18 #include "webrtc/base/arraysize.h" |
19 #include "webrtc/base/checks.h" | 19 #include "webrtc/base/checks.h" |
20 #include "webrtc/base/logging.h" | 20 #include "webrtc/base/logging.h" |
21 #include "webrtc/media/base/videocommon.h" | 21 #include "webrtc/media/base/videocommon.h" |
22 | 22 |
23 namespace cricket { | 23 namespace cricket { |
24 | 24 |
25 // Round to 2 pixels because Chroma channels are half size. | 25 // Round to 2 pixels because Chroma channels are half size. |
26 #define ROUNDTO2(v) (v & ~1) | 26 #define ROUNDTO2(v) (v & ~1) |
27 | 27 |
| 28 rtc::StreamResult VideoFrame::Write(rtc::StreamInterface* stream, |
| 29 int* error) const { |
| 30 rtc::StreamResult result = rtc::SR_SUCCESS; |
| 31 const uint8_t* src_y = GetYPlane(); |
| 32 const uint8_t* src_u = GetUPlane(); |
| 33 const uint8_t* src_v = GetVPlane(); |
| 34 if (!src_y || !src_u || !src_v) { |
| 35 return result; // Nothing to write. |
| 36 } |
| 37 const int32_t y_pitch = GetYPitch(); |
| 38 const int32_t u_pitch = GetUPitch(); |
| 39 const int32_t v_pitch = GetVPitch(); |
| 40 const size_t width = GetWidth(); |
| 41 const size_t height = GetHeight(); |
| 42 const size_t half_width = (width + 1) >> 1; |
| 43 const size_t half_height = (height + 1) >> 1; |
| 44 // Write Y. |
| 45 for (size_t row = 0; row < height; ++row) { |
| 46 result = stream->Write(src_y + row * y_pitch, width, NULL, error); |
| 47 if (result != rtc::SR_SUCCESS) { |
| 48 return result; |
| 49 } |
| 50 } |
| 51 // Write U. |
| 52 for (size_t row = 0; row < half_height; ++row) { |
| 53 result = stream->Write(src_u + row * u_pitch, half_width, NULL, error); |
| 54 if (result != rtc::SR_SUCCESS) { |
| 55 return result; |
| 56 } |
| 57 } |
| 58 // Write V. |
| 59 for (size_t row = 0; row < half_height; ++row) { |
| 60 result = stream->Write(src_v + row * v_pitch, half_width, NULL, error); |
| 61 if (result != rtc::SR_SUCCESS) { |
| 62 return result; |
| 63 } |
| 64 } |
| 65 return result; |
| 66 } |
| 67 |
| 68 size_t VideoFrame::CopyToBuffer(uint8_t* buffer, size_t size) const { |
| 69 const size_t y_size = GetHeight() * GetYPitch(); |
| 70 const size_t u_size = GetUPitch() * GetChromaHeight(); |
| 71 const size_t v_size = GetVPitch() * GetChromaHeight(); |
| 72 const size_t needed = y_size + u_size + v_size; |
| 73 if (size < needed) |
| 74 return needed; |
| 75 CopyToPlanes(buffer, buffer + y_size, buffer + y_size + u_size, |
| 76 GetYPitch(), GetUPitch(), GetVPitch()); |
| 77 return needed; |
| 78 } |
| 79 |
28 bool VideoFrame::CopyToPlanes(uint8_t* dst_y, | 80 bool VideoFrame::CopyToPlanes(uint8_t* dst_y, |
29 uint8_t* dst_u, | 81 uint8_t* dst_u, |
30 uint8_t* dst_v, | 82 uint8_t* dst_v, |
31 int32_t dst_pitch_y, | 83 int32_t dst_pitch_y, |
32 int32_t dst_pitch_u, | 84 int32_t dst_pitch_u, |
33 int32_t dst_pitch_v) const { | 85 int32_t dst_pitch_v) const { |
34 if (!GetYPlane() || !GetUPlane() || !GetVPlane()) { | 86 if (!GetYPlane() || !GetUPlane() || !GetVPlane()) { |
35 LOG(LS_ERROR) << "NULL plane pointer."; | 87 LOG(LS_ERROR) << "NULL plane pointer."; |
36 return false; | 88 return false; |
37 } | 89 } |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 << " expected: " << expected_size | 363 << " expected: " << expected_size |
312 << " sample[0..3]: " << static_cast<int>(four_samples[0]) | 364 << " sample[0..3]: " << static_cast<int>(four_samples[0]) |
313 << ", " << static_cast<int>(four_samples[1]) | 365 << ", " << static_cast<int>(four_samples[1]) |
314 << ", " << static_cast<int>(four_samples[2]) | 366 << ", " << static_cast<int>(four_samples[2]) |
315 << ", " << static_cast<int>(four_samples[3]); | 367 << ", " << static_cast<int>(four_samples[3]); |
316 } | 368 } |
317 return true; | 369 return true; |
318 } | 370 } |
319 | 371 |
320 } // namespace cricket | 372 } // namespace cricket |
OLD | NEW |