| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 // Creating empty frame - reset all values. | 62 // Creating empty frame - reset all values. |
| 63 timestamp_ = 0; | 63 timestamp_ = 0; |
| 64 ntp_time_ms_ = 0; | 64 ntp_time_ms_ = 0; |
| 65 render_time_ms_ = 0; | 65 render_time_ms_ = 0; |
| 66 rotation_ = kVideoRotation_0; | 66 rotation_ = kVideoRotation_0; |
| 67 | 67 |
| 68 // Check if it's safe to reuse allocation. | 68 // Check if it's safe to reuse allocation. |
| 69 if (video_frame_buffer_ && video_frame_buffer_->IsMutable() && | 69 if (video_frame_buffer_ && video_frame_buffer_->IsMutable() && |
| 70 !video_frame_buffer_->native_handle() && | 70 !video_frame_buffer_->native_handle() && |
| 71 width == video_frame_buffer_->width() && | 71 width == video_frame_buffer_->width() && |
| 72 height == video_frame_buffer_->height() && stride_y == stride(kYPlane) && | 72 height == video_frame_buffer_->height() && |
| 73 stride_u == stride(kUPlane) && stride_v == stride(kVPlane)) { | 73 stride_y == video_frame_buffer_->StrideY() && |
| 74 stride_u == video_frame_buffer_->StrideU() && |
| 75 stride_v == video_frame_buffer_->StrideV()) { |
| 74 return; | 76 return; |
| 75 } | 77 } |
| 76 | 78 |
| 77 // Need to allocate new buffer. | 79 // Need to allocate new buffer. |
| 78 video_frame_buffer_ = new rtc::RefCountedObject<I420Buffer>( | 80 video_frame_buffer_ = new rtc::RefCountedObject<I420Buffer>( |
| 79 width, height, stride_y, stride_u, stride_v); | 81 width, height, stride_y, stride_u, stride_v); |
| 80 } | 82 } |
| 81 | 83 |
| 82 void VideoFrame::CreateFrame(const uint8_t* buffer_y, | 84 void VideoFrame::CreateFrame(const uint8_t* buffer_y, |
| 83 const uint8_t* buffer_u, | 85 const uint8_t* buffer_u, |
| 84 const uint8_t* buffer_v, | 86 const uint8_t* buffer_v, |
| 85 int width, | 87 int width, |
| 86 int height, | 88 int height, |
| 87 int stride_y, | 89 int stride_y, |
| 88 int stride_u, | 90 int stride_u, |
| 89 int stride_v, | 91 int stride_v, |
| 90 VideoRotation rotation) { | 92 VideoRotation rotation) { |
| 91 const int half_height = (height + 1) / 2; | 93 const int half_height = (height + 1) / 2; |
| 92 const int expected_size_y = height * stride_y; | 94 const int expected_size_y = height * stride_y; |
| 93 const int expected_size_u = half_height * stride_u; | 95 const int expected_size_u = half_height * stride_u; |
| 94 const int expected_size_v = half_height * stride_v; | 96 const int expected_size_v = half_height * stride_v; |
| 95 CreateEmptyFrame(width, height, stride_y, stride_u, stride_v); | 97 CreateEmptyFrame(width, height, stride_y, stride_u, stride_v); |
| 96 memcpy(buffer(kYPlane), buffer_y, expected_size_y); | 98 memcpy(video_frame_buffer_->MutableDataY(), buffer_y, expected_size_y); |
| 97 memcpy(buffer(kUPlane), buffer_u, expected_size_u); | 99 memcpy(video_frame_buffer_->MutableDataU(), buffer_u, expected_size_u); |
| 98 memcpy(buffer(kVPlane), buffer_v, expected_size_v); | 100 memcpy(video_frame_buffer_->MutableDataV(), buffer_v, expected_size_v); |
| 99 rotation_ = rotation; | 101 rotation_ = rotation; |
| 100 } | 102 } |
| 101 | 103 |
| 102 void VideoFrame::CreateFrame(const uint8_t* buffer, | 104 void VideoFrame::CreateFrame(const uint8_t* buffer, |
| 103 int width, | 105 int width, |
| 104 int height, | 106 int height, |
| 105 VideoRotation rotation) { | 107 VideoRotation rotation) { |
| 106 const int stride_y = width; | 108 const int stride_y = width; |
| 107 const int stride_uv = (width + 1) / 2; | 109 const int stride_uv = (width + 1) / 2; |
| 108 | 110 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 123 } | 125 } |
| 124 | 126 |
| 125 void VideoFrame::ShallowCopy(const VideoFrame& videoFrame) { | 127 void VideoFrame::ShallowCopy(const VideoFrame& videoFrame) { |
| 126 video_frame_buffer_ = videoFrame.video_frame_buffer(); | 128 video_frame_buffer_ = videoFrame.video_frame_buffer(); |
| 127 timestamp_ = videoFrame.timestamp_; | 129 timestamp_ = videoFrame.timestamp_; |
| 128 ntp_time_ms_ = videoFrame.ntp_time_ms_; | 130 ntp_time_ms_ = videoFrame.ntp_time_ms_; |
| 129 render_time_ms_ = videoFrame.render_time_ms_; | 131 render_time_ms_ = videoFrame.render_time_ms_; |
| 130 rotation_ = videoFrame.rotation_; | 132 rotation_ = videoFrame.rotation_; |
| 131 } | 133 } |
| 132 | 134 |
| 133 uint8_t* VideoFrame::buffer(PlaneType type) { | 135 // TODO(nisse): Delete. Besides test code, only one use, in |
| 134 return video_frame_buffer_ ? video_frame_buffer_->MutableData(type) | 136 // webrtcvideoengine2.cc:CreateBlackFrame. |
| 135 : nullptr; | |
| 136 } | |
| 137 | |
| 138 const uint8_t* VideoFrame::buffer(PlaneType type) const { | |
| 139 return video_frame_buffer_ ? video_frame_buffer_->data(type) : nullptr; | |
| 140 } | |
| 141 | |
| 142 int VideoFrame::allocated_size(PlaneType type) const { | 137 int VideoFrame::allocated_size(PlaneType type) const { |
| 143 const int plane_height = (type == kYPlane) ? height() : (height() + 1) / 2; | 138 const int plane_height = (type == kYPlane) ? height() : (height() + 1) / 2; |
| 144 return plane_height * stride(type); | 139 int stride; |
| 145 } | 140 switch (type) { |
| 146 | 141 case kYPlane: |
| 147 int VideoFrame::stride(PlaneType type) const { | 142 stride = video_frame_buffer_->StrideY(); |
| 148 return video_frame_buffer_ ? video_frame_buffer_->stride(type) : 0; | 143 break; |
| 144 case kUPlane: |
| 145 stride = video_frame_buffer_->StrideU(); |
| 146 break; |
| 147 case kVPlane: |
| 148 stride = video_frame_buffer_->StrideV(); |
| 149 break; |
| 150 default: |
| 151 RTC_NOTREACHED(); |
| 152 return 0; |
| 153 } |
| 154 return plane_height * stride; |
| 149 } | 155 } |
| 150 | 156 |
| 151 int VideoFrame::width() const { | 157 int VideoFrame::width() const { |
| 152 return video_frame_buffer_ ? video_frame_buffer_->width() : 0; | 158 return video_frame_buffer_ ? video_frame_buffer_->width() : 0; |
| 153 } | 159 } |
| 154 | 160 |
| 155 int VideoFrame::height() const { | 161 int VideoFrame::height() const { |
| 156 return video_frame_buffer_ ? video_frame_buffer_->height() : 0; | 162 return video_frame_buffer_ ? video_frame_buffer_->height() : 0; |
| 157 } | 163 } |
| 158 | 164 |
| 159 bool VideoFrame::IsZeroSize() const { | 165 bool VideoFrame::IsZeroSize() const { |
| 160 return !video_frame_buffer_; | 166 return !video_frame_buffer_; |
| 161 } | 167 } |
| 162 | 168 |
| 163 rtc::scoped_refptr<VideoFrameBuffer> VideoFrame::video_frame_buffer() const { | 169 const rtc::scoped_refptr<VideoFrameBuffer>& VideoFrame::video_frame_buffer() |
| 170 const { |
| 164 return video_frame_buffer_; | 171 return video_frame_buffer_; |
| 165 } | 172 } |
| 166 | 173 |
| 167 void VideoFrame::set_video_frame_buffer( | 174 void VideoFrame::set_video_frame_buffer( |
| 168 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer) { | 175 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer) { |
| 169 video_frame_buffer_ = buffer; | 176 video_frame_buffer_ = buffer; |
| 170 } | 177 } |
| 171 | 178 |
| 172 VideoFrame VideoFrame::ConvertNativeToI420Frame() const { | 179 VideoFrame VideoFrame::ConvertNativeToI420Frame() const { |
| 173 RTC_DCHECK(video_frame_buffer_->native_handle()); | 180 RTC_DCHECK(video_frame_buffer_->native_handle()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 189 case kVideoCodecULPFEC: | 196 case kVideoCodecULPFEC: |
| 190 case kVideoCodecGeneric: | 197 case kVideoCodecGeneric: |
| 191 case kVideoCodecUnknown: | 198 case kVideoCodecUnknown: |
| 192 return 0; | 199 return 0; |
| 193 } | 200 } |
| 194 RTC_NOTREACHED(); | 201 RTC_NOTREACHED(); |
| 195 return 0; | 202 return 0; |
| 196 } | 203 } |
| 197 | 204 |
| 198 } // namespace webrtc | 205 } // namespace webrtc |
| OLD | NEW |