Commit b22a69d1 authored by phoglund's avatar phoglund Committed by Commit bot

Revert of Refactored pixel format resize operations in media/video/capture...

Revert of Refactored pixel format resize operations in  media/video/capture into a function called VideoCaptu… (patchset #13 id:240001 of https://codereview.chromium.org/897483002/)

Reason for revert:
This breaks the WebRTC real webcam tests on Windows. See for instance http://chromegw.corp.google.com/i/internal.chromium.webrtc/builders/Win7%20Tester/builds/13860. The error is

[2292:2232:0206/211958:997267:FATAL:video_capture_controller.cc(474)] Check failed: static_cast<size_t>(length) >= frame_format.ImageAllocationSize() (0 vs. 614400)

The Win bots are equipped with C920 webcams. I logged into the bot to make sure the webcam was working right - it is as far I can see.

Original issue's description:
> Refactored pixel format resize operations in  media/video/capture into a function called VideoCaptureFormat::GetSizeForVideoPixelFormat().
>
> BUG=
>
> TEST=VideoCaptureDeviceTest.* in media_unittests pass.
>
> Committed: https://crrev.com/79288ba0b63021e8731e0401b8a4a9055d33fa10
> Cr-Commit-Position: refs/heads/master@{#315175}

TBR=mcasas@chromium.org,perkj@chromium.org,emircan@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=

Review URL: https://codereview.chromium.org/898803004

Cr-Commit-Position: refs/heads/master@{#315203}
parent 03ba3b4b
......@@ -469,10 +469,6 @@ void VideoCaptureController::VideoCaptureDeviceClient::OnIncomingCapturedData(
NOTREACHED();
}
// The input |length| can be greater than the required buffer size because of
// paddings and/or alignments, but it cannot be less.
DCHECK_GE(static_cast<size_t>(length), frame_format.ImageAllocationSize());
if (libyuv::ConvertToI420(data,
length,
yplane,
......
......@@ -10,7 +10,6 @@
#include "base/memory/scoped_ptr.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "media/video/capture/video_capture_types.h"
namespace media {
static const int kY4MHeaderMaxSize = 200;
......@@ -170,10 +169,10 @@ void FileVideoCaptureDevice::StopAndDeAllocate() {
capture_thread_.Stop();
}
int FileVideoCaptureDevice::CalculateFrameSize() const {
int FileVideoCaptureDevice::CalculateFrameSize() {
DCHECK_EQ(capture_format_.pixel_format, PIXEL_FORMAT_I420);
DCHECK_EQ(capture_thread_.message_loop(), base::MessageLoop::current());
return capture_format_.ImageAllocationSize();
return capture_format_.frame_size.GetArea() * 12 / 8;
}
void FileVideoCaptureDevice::OnAllocateAndStart(
......
......@@ -43,7 +43,7 @@ class MEDIA_EXPORT FileVideoCaptureDevice : public VideoCaptureDevice {
private:
// Returns size in bytes of an I420 frame, not including possible paddings,
// defined by |capture_format_|.
int CalculateFrameSize() const;
int CalculateFrameSize();
// Called on the |capture_thread_|.
void OnAllocateAndStart(const VideoCaptureParams& params,
......
......@@ -269,8 +269,6 @@ TEST_F(VideoCaptureDeviceTest, CaptureVGA) {
WaitForCapturedFrame();
EXPECT_EQ(last_format().frame_size.width(), 640);
EXPECT_EQ(last_format().frame_size.height(), 480);
EXPECT_EQ(static_cast<size_t>(640 * 480 * 3 / 2),
last_format().ImageAllocationSize());
device->StopAndDeAllocate();
}
......@@ -295,10 +293,6 @@ TEST_F(VideoCaptureDeviceTest, Capture720p) {
device->AllocateAndStart(capture_params, client_.Pass());
// Get captured video frames.
WaitForCapturedFrame();
EXPECT_EQ(last_format().frame_size.width(), 1280);
EXPECT_EQ(last_format().frame_size.height(), 720);
EXPECT_EQ(static_cast<size_t>(1280 * 720 * 3 / 2),
last_format().ImageAllocationSize());
device->StopAndDeAllocate();
}
......@@ -324,8 +318,6 @@ TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) {
device->StopAndDeAllocate();
EXPECT_EQ(last_format().frame_size.width(), 640);
EXPECT_EQ(last_format().frame_size.height(), 480);
EXPECT_EQ(static_cast<size_t>(640 * 480 * 3 / 2),
last_format().ImageAllocationSize());
}
// Cause hangs on Windows Debug. http://crbug.com/417824
......@@ -430,8 +422,6 @@ TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) {
// Verify we get MJPEG from the device. Not all devices can capture 1280x720
// @ 30 fps, so we don't care about the exact resolution we get.
EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG);
EXPECT_GE(static_cast<size_t>(1280 * 720),
last_format().ImageAllocationSize());
device->StopAndDeAllocate();
}
......
......@@ -31,36 +31,6 @@ bool VideoCaptureFormat::IsValid() const {
(pixel_format < PIXEL_FORMAT_MAX);
}
size_t VideoCaptureFormat::ImageAllocationSize() const {
size_t result_frame_size = frame_size.GetArea();
switch (pixel_format) {
case PIXEL_FORMAT_I420:
case PIXEL_FORMAT_YV12:
case PIXEL_FORMAT_NV12:
case PIXEL_FORMAT_NV21:
result_frame_size = result_frame_size * 3 / 2;
break;
case PIXEL_FORMAT_UYVY:
case PIXEL_FORMAT_YUY2:
result_frame_size *= 2;
break;
case PIXEL_FORMAT_RGB24:
result_frame_size *= 3;
break;
case PIXEL_FORMAT_ARGB:
result_frame_size *= 4;
break;
case PIXEL_FORMAT_MJPEG:
case PIXEL_FORMAT_TEXTURE:
result_frame_size = 0;
break;
default: // Sizes for the rest of the formats are unknown.
NOTREACHED() << "Unknown pixel format provided.";
break;
}
return result_frame_size;
}
std::string VideoCaptureFormat::ToString() const {
return base::StringPrintf("resolution: %s, fps: %.3f, pixel format: %s",
frame_size.ToString().c_str(),
......
......@@ -67,10 +67,6 @@ class MEDIA_EXPORT VideoCaptureFormat {
std::string ToString() const;
static std::string PixelFormatToString(VideoPixelFormat format);
// Returns the required buffer size to hold an image of a given
// VideoCaptureFormat with no padding and tightly packed.
size_t ImageAllocationSize() const;
// Checks that all values are in the expected range. All limits are specified
// in media::Limits.
bool IsValid() const;
......
......@@ -69,7 +69,8 @@ bool SinkInputPin::GetValidMediaType(int index, AM_MEDIA_TYPE* media_type) {
pvi->bmiHeader.biBitCount = 12; // bit per pixel
pvi->bmiHeader.biWidth = requested_format_.frame_size.width();
pvi->bmiHeader.biHeight = requested_format_.frame_size.height();
pvi->bmiHeader.biSizeImage = requested_format_.ImageAllocationSize();
pvi->bmiHeader.biSizeImage =
requested_format_.frame_size.GetArea() * 3 / 2;
media_type->subtype = kMediaSubTypeI420;
break;
}
......@@ -78,7 +79,7 @@ bool SinkInputPin::GetValidMediaType(int index, AM_MEDIA_TYPE* media_type) {
pvi->bmiHeader.biBitCount = 16;
pvi->bmiHeader.biWidth = requested_format_.frame_size.width();
pvi->bmiHeader.biHeight = requested_format_.frame_size.height();
pvi->bmiHeader.biSizeImage = requested_format_.ImageAllocationSize();
pvi->bmiHeader.biSizeImage = requested_format_.frame_size.GetArea() * 2;
media_type->subtype = MEDIASUBTYPE_YUY2;
break;
}
......@@ -87,7 +88,7 @@ bool SinkInputPin::GetValidMediaType(int index, AM_MEDIA_TYPE* media_type) {
pvi->bmiHeader.biBitCount = 24;
pvi->bmiHeader.biWidth = requested_format_.frame_size.width();
pvi->bmiHeader.biHeight = requested_format_.frame_size.height();
pvi->bmiHeader.biSizeImage = requested_format_.ImageAllocationSize();
pvi->bmiHeader.biSizeImage = requested_format_.frame_size.GetArea() * 3;
media_type->subtype = MEDIASUBTYPE_RGB24;
break;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment