Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Side by Side Diff: media/capture/video/video_capture_device_client.cc

Issue 2369983003: Win video capture: Fix capture format and frame buffer mismatch (Closed)
Patch Set: Move length check to Win code Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/capture/video/video_capture_device_client.h" 5 #include "media/capture/video/video_capture_device_client.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 82
83 void VideoCaptureDeviceClient::OnIncomingCapturedData( 83 void VideoCaptureDeviceClient::OnIncomingCapturedData(
84 const uint8_t* data, 84 const uint8_t* data,
85 int length, 85 int length,
86 const VideoCaptureFormat& frame_format, 86 const VideoCaptureFormat& frame_format,
87 int rotation, 87 int rotation,
88 base::TimeTicks reference_time, 88 base::TimeTicks reference_time,
89 base::TimeDelta timestamp) { 89 base::TimeDelta timestamp) {
90 TRACE_EVENT0("video", "VideoCaptureDeviceClient::OnIncomingCapturedData"); 90 TRACE_EVENT0("video", "VideoCaptureDeviceClient::OnIncomingCapturedData");
91 DCHECK_EQ(media::PIXEL_STORAGE_CPU, frame_format.pixel_storage); 91 DCHECK_EQ(media::PIXEL_STORAGE_CPU, frame_format.pixel_storage);
92 // The input |length| can be greater than the required buffer size because of
93 // paddings and/or alignments, but it cannot be smaller.
94 DCHECK_GE(static_cast<size_t>(length), frame_format.ImageAllocationSize());
92 95
93 if (last_captured_pixel_format_ != frame_format.pixel_format) { 96 if (last_captured_pixel_format_ != frame_format.pixel_format) {
94 OnLog("Pixel format: " + 97 OnLog("Pixel format: " +
95 media::VideoPixelFormatToString(frame_format.pixel_format)); 98 media::VideoPixelFormatToString(frame_format.pixel_format));
96 last_captured_pixel_format_ = frame_format.pixel_format; 99 last_captured_pixel_format_ = frame_format.pixel_format;
97 100
98 if (frame_format.pixel_format == media::PIXEL_FORMAT_MJPEG && 101 if (frame_format.pixel_format == media::PIXEL_FORMAT_MJPEG &&
99 !external_jpeg_decoder_initialized_) { 102 !external_jpeg_decoder_initialized_) {
100 external_jpeg_decoder_initialized_ = true; 103 external_jpeg_decoder_initialized_ = true;
101 external_jpeg_decoder_ = jpeg_decoder_factory_callback_.Run(); 104 external_jpeg_decoder_ = jpeg_decoder_factory_callback_.Run();
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 case media::PIXEL_FORMAT_ARGB: 211 case media::PIXEL_FORMAT_ARGB:
209 origin_colorspace = libyuv::FOURCC_ARGB; 212 origin_colorspace = libyuv::FOURCC_ARGB;
210 break; 213 break;
211 case media::PIXEL_FORMAT_MJPEG: 214 case media::PIXEL_FORMAT_MJPEG:
212 origin_colorspace = libyuv::FOURCC_MJPG; 215 origin_colorspace = libyuv::FOURCC_MJPG;
213 break; 216 break;
214 default: 217 default:
215 NOTREACHED(); 218 NOTREACHED();
216 } 219 }
217 220
218 // The input |length| can be greater than the required buffer size because of
219 // paddings and/or alignments, but it cannot be smaller.
220 DCHECK_GE(static_cast<size_t>(length), frame_format.ImageAllocationSize());
221
222 if (external_jpeg_decoder_) { 221 if (external_jpeg_decoder_) {
223 const VideoCaptureJpegDecoder::STATUS status = 222 const VideoCaptureJpegDecoder::STATUS status =
224 external_jpeg_decoder_->GetStatus(); 223 external_jpeg_decoder_->GetStatus();
225 if (status == VideoCaptureJpegDecoder::FAILED) { 224 if (status == VideoCaptureJpegDecoder::FAILED) {
226 external_jpeg_decoder_.reset(); 225 external_jpeg_decoder_.reset();
227 } else if (status == VideoCaptureJpegDecoder::INIT_PASSED && 226 } else if (status == VideoCaptureJpegDecoder::INIT_PASSED &&
228 frame_format.pixel_format == media::PIXEL_FORMAT_MJPEG && 227 frame_format.pixel_format == media::PIXEL_FORMAT_MJPEG &&
229 rotation == 0 && !flip) { 228 rotation == 0 && !flip) {
230 external_jpeg_decoder_->DecodeCapturedData(data, length, frame_format, 229 external_jpeg_decoder_->DecodeCapturedData(data, length, frame_format,
231 reference_time, timestamp, 230 reference_time, timestamp,
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 reinterpret_cast<uint8_t*>(buffer->data(VideoFrame::kUPlane)); 395 reinterpret_cast<uint8_t*>(buffer->data(VideoFrame::kUPlane));
397 *v_plane_data = 396 *v_plane_data =
398 reinterpret_cast<uint8_t*>(buffer->data(VideoFrame::kVPlane)); 397 reinterpret_cast<uint8_t*>(buffer->data(VideoFrame::kVPlane));
399 return buffer; 398 return buffer;
400 } 399 }
401 NOTREACHED(); 400 NOTREACHED();
402 return std::unique_ptr<Buffer>(); 401 return std::unique_ptr<Buffer>();
403 } 402 }
404 403
405 } // namespace media 404 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698