OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 RTC_CHECK_GE(width, 0); | 114 RTC_CHECK_GE(width, 0); |
115 RTC_CHECK_GE(height, 0); | 115 RTC_CHECK_GE(height, 0); |
116 int ret = av_image_check_size(static_cast<unsigned int>(width), | 116 int ret = av_image_check_size(static_cast<unsigned int>(width), |
117 static_cast<unsigned int>(height), 0, nullptr); | 117 static_cast<unsigned int>(height), 0, nullptr); |
118 if (ret < 0) { | 118 if (ret < 0) { |
119 LOG(LS_ERROR) << "Invalid picture size " << width << "x" << height; | 119 LOG(LS_ERROR) << "Invalid picture size " << width << "x" << height; |
120 decoder->ReportError(); | 120 decoder->ReportError(); |
121 return ret; | 121 return ret; |
122 } | 122 } |
123 | 123 |
124 // The video frame is stored in |frame_buffer|. |av_frame| is FFmpeg's version | 124 // The video frame is stored in |video_frame|. |av_frame| is FFmpeg's version |
125 // of a video frame and will be set up to reference |frame_buffer|'s data. | 125 // of a video frame and will be set up to reference |video_frame|'s buffers. |
| 126 |
| 127 // TODO(nisse): The VideoFrame's timestamp and rotation info is not used. |
| 128 // Refactor to do not use a VideoFrame object at all. |
126 | 129 |
127 // FFmpeg expects the initial allocation to be zero-initialized according to | 130 // FFmpeg expects the initial allocation to be zero-initialized according to |
128 // http://crbug.com/390941. Our pool is set up to zero-initialize new buffers. | 131 // http://crbug.com/390941. Our pool is set up to zero-initialize new buffers. |
129 // TODO(nisse): Delete that feature from the video pool, instead add | 132 VideoFrame* video_frame = new VideoFrame( |
130 // an explicit call to InitializeData here. | 133 decoder->pool_.CreateBuffer(width, height), |
131 rtc::scoped_refptr<I420Buffer> frame_buffer = | 134 0 /* timestamp */, 0 /* render_time_ms */, kVideoRotation_0); |
132 decoder->pool_.CreateBuffer(width, height); | |
133 | 135 |
134 int y_size = width * height; | |
135 int uv_size = ((width + 1) / 2) * ((height + 1) / 2); | |
136 // DCHECK that we have a continuous buffer as is required. | 136 // DCHECK that we have a continuous buffer as is required. |
137 RTC_DCHECK_EQ(frame_buffer->DataU(), frame_buffer->DataY() + y_size); | 137 RTC_DCHECK_EQ(video_frame->video_frame_buffer()->DataU(), |
138 RTC_DCHECK_EQ(frame_buffer->DataV(), frame_buffer->DataU() + uv_size); | 138 video_frame->video_frame_buffer()->DataY() + |
139 int total_size = y_size + 2 * uv_size; | 139 video_frame->allocated_size(kYPlane)); |
| 140 RTC_DCHECK_EQ(video_frame->video_frame_buffer()->DataV(), |
| 141 video_frame->video_frame_buffer()->DataU() + |
| 142 video_frame->allocated_size(kUPlane)); |
| 143 int total_size = video_frame->allocated_size(kYPlane) + |
| 144 video_frame->allocated_size(kUPlane) + |
| 145 video_frame->allocated_size(kVPlane); |
140 | 146 |
141 av_frame->format = context->pix_fmt; | 147 av_frame->format = context->pix_fmt; |
142 av_frame->reordered_opaque = context->reordered_opaque; | 148 av_frame->reordered_opaque = context->reordered_opaque; |
143 | 149 |
144 // Set |av_frame| members as required by FFmpeg. | 150 // Set |av_frame| members as required by FFmpeg. |
145 av_frame->data[kYPlaneIndex] = frame_buffer->MutableDataY(); | 151 av_frame->data[kYPlaneIndex] = |
146 av_frame->linesize[kYPlaneIndex] = frame_buffer->StrideY(); | 152 video_frame->video_frame_buffer()->MutableDataY(); |
147 av_frame->data[kUPlaneIndex] = frame_buffer->MutableDataU(); | 153 av_frame->linesize[kYPlaneIndex] = |
148 av_frame->linesize[kUPlaneIndex] = frame_buffer->StrideU(); | 154 video_frame->video_frame_buffer()->StrideY(); |
149 av_frame->data[kVPlaneIndex] = frame_buffer->MutableDataV(); | 155 av_frame->data[kUPlaneIndex] = |
150 av_frame->linesize[kVPlaneIndex] = frame_buffer->StrideV(); | 156 video_frame->video_frame_buffer()->MutableDataU(); |
| 157 av_frame->linesize[kUPlaneIndex] = |
| 158 video_frame->video_frame_buffer()->StrideU(); |
| 159 av_frame->data[kVPlaneIndex] = |
| 160 video_frame->video_frame_buffer()->MutableDataV(); |
| 161 av_frame->linesize[kVPlaneIndex] = |
| 162 video_frame->video_frame_buffer()->StrideV(); |
151 RTC_DCHECK_EQ(av_frame->extended_data, av_frame->data); | 163 RTC_DCHECK_EQ(av_frame->extended_data, av_frame->data); |
152 | 164 |
153 // Create a VideoFrame object, to keep a reference to the buffer. | 165 av_frame->buf[0] = av_buffer_create(av_frame->data[kYPlaneIndex], |
154 // TODO(nisse): The VideoFrame's timestamp and rotation info is not used. | 166 total_size, |
155 // Refactor to do not use a VideoFrame object at all. | 167 AVFreeBuffer2, |
156 av_frame->buf[0] = av_buffer_create( | 168 static_cast<void*>(video_frame), |
157 av_frame->data[kYPlaneIndex], | 169 0); |
158 total_size, | |
159 AVFreeBuffer2, | |
160 static_cast<void*>(new VideoFrame(frame_buffer, | |
161 0 /* timestamp */, | |
162 0 /* render_time_ms */, | |
163 kVideoRotation_0)), | |
164 0); | |
165 RTC_CHECK(av_frame->buf[0]); | 170 RTC_CHECK(av_frame->buf[0]); |
166 return 0; | 171 return 0; |
167 } | 172 } |
168 | 173 |
169 void H264DecoderImpl::AVFreeBuffer2(void* opaque, uint8_t* data) { | 174 void H264DecoderImpl::AVFreeBuffer2(void* opaque, uint8_t* data) { |
170 // The buffer pool recycles the buffer used by |video_frame| when there are no | 175 // The buffer pool recycles the buffer used by |video_frame| when there are no |
171 // more references to it. |video_frame| is a thin buffer holder and is not | 176 // more references to it. |video_frame| is a thin buffer holder and is not |
172 // recycled. | 177 // recycled. |
173 VideoFrame* video_frame = static_cast<VideoFrame*>(opaque); | 178 VideoFrame* video_frame = static_cast<VideoFrame*>(opaque); |
174 delete video_frame; | 179 delete video_frame; |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 void H264DecoderImpl::ReportError() { | 415 void H264DecoderImpl::ReportError() { |
411 if (has_reported_error_) | 416 if (has_reported_error_) |
412 return; | 417 return; |
413 RTC_HISTOGRAM_ENUMERATION("WebRTC.Video.H264DecoderImpl.Event", | 418 RTC_HISTOGRAM_ENUMERATION("WebRTC.Video.H264DecoderImpl.Event", |
414 kH264DecoderEventError, | 419 kH264DecoderEventError, |
415 kH264DecoderEventMax); | 420 kH264DecoderEventMax); |
416 has_reported_error_ = true; | 421 has_reported_error_ = true; |
417 } | 422 } |
418 | 423 |
419 } // namespace webrtc | 424 } // namespace webrtc |
OLD | NEW |