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

Unified Diff: content/browser/renderer_host/media/video_capture_controller.cc

Issue 10837225: chop the width/height to even number when incoming frame has odd number dimension. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/renderer_host/media/video_capture_controller.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/renderer_host/media/video_capture_controller.cc
===================================================================
--- content/browser/renderer_host/media/video_capture_controller.cc (revision 151718)
+++ content/browser/renderer_host/media/video_capture_controller.cc (working copy)
@@ -67,7 +67,9 @@
VideoCaptureController::VideoCaptureController(
media_stream::VideoCaptureManager* video_capture_manager)
- : frame_info_available_(false),
+ : chopped_width_(0),
+ chopped_height_(0),
+ frame_info_available_(false),
video_capture_manager_(video_capture_manager),
device_in_use_(false),
state_(video_capture::kStopped) {
@@ -277,10 +279,12 @@
case media::VideoCaptureCapability::kColorUnknown: // Color format not set.
break;
case media::VideoCaptureCapability::kI420: {
+ DCHECK(!chopped_width_ && !chopped_height_);
memcpy(target, data, (frame_info_.width * frame_info_.height * 3) / 2);
break;
}
case media::VideoCaptureCapability::kYV12: {
+ DCHECK(!chopped_width_ && !chopped_height_);
const uint8* ptr = data;
memcpy(yplane, ptr, (frame_info_.width * frame_info_.height));
ptr += frame_info_.width * frame_info_.height;
@@ -290,11 +294,13 @@
break;
}
case media::VideoCaptureCapability::kNV21: {
+ DCHECK(!chopped_width_ && !chopped_height_);
media::ConvertNV21ToYUV(data, yplane, uplane, vplane, frame_info_.width,
frame_info_.height);
break;
}
case media::VideoCaptureCapability::kYUY2: {
+ DCHECK(!chopped_width_ && !chopped_height_);
media::ConvertYUY2ToYUV(data, yplane, uplane, vplane, frame_info_.width,
frame_info_.height);
break;
@@ -303,11 +309,11 @@
int ystride = frame_info_.width;
int uvstride = frame_info_.width / 2;
#if defined(OS_WIN) // RGB on Windows start at the bottom line.
- int rgb_stride = -3 * frame_info_.width;
- const uint8* rgb_src = data + 3 * frame_info_.width *
- (frame_info_.height -1);
+ int rgb_stride = -3 * (frame_info_.width + chopped_width_);
+ const uint8* rgb_src = data + 3 * (frame_info_.width + chopped_width_) *
+ (frame_info_.height -1 + chopped_height_);
#else
- int rgb_stride = 3 * frame_info_.width;
+ int rgb_stride = 3 * (frame_info_.width + chopped_width_);
const uint8* rgb_src = data;
#endif
media::ConvertRGB24ToYUV(rgb_src, yplane, uplane, vplane,
@@ -317,7 +323,8 @@
}
case media::VideoCaptureCapability::kARGB: {
media::ConvertRGB32ToYUV(data, yplane, uplane, vplane, frame_info_.width,
- frame_info_.height, frame_info_.width * 4,
+ frame_info_.height,
+ (frame_info_.width + chopped_width_) * 4,
frame_info_.width, frame_info_.width / 2);
break;
}
@@ -341,10 +348,22 @@
void VideoCaptureController::OnFrameInfo(
const media::VideoCaptureCapability& info) {
frame_info_= info;
+ // Handle cases when |info| has odd numbers for width/height.
+ if (info.width & 1) {
+ --frame_info_.width;
+ chopped_width_ = 1;
+ } else {
+ chopped_width_ = 0;
+ }
+ if (info.height & 1) {
+ --frame_info_.height;
+ chopped_height_ = 1;
+ } else {
+ chopped_height_ = 0;
+ }
BrowserThread::PostTask(BrowserThread::IO,
FROM_HERE,
- base::Bind(&VideoCaptureController::DoFrameInfoOnIOThread,
- this, info));
+ base::Bind(&VideoCaptureController::DoFrameInfoOnIOThread, this));
}
VideoCaptureController::~VideoCaptureController() {
@@ -389,14 +408,17 @@
}
}
-void VideoCaptureController::DoFrameInfoOnIOThread(
- const media::VideoCaptureCapability& info) {
+void VideoCaptureController::DoFrameInfoOnIOThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
DCHECK(owned_dibs_.empty())
<< "Device is restarted without releasing shared memory.";
+ // Allocate memory only when device has been started.
+ if (state_ != video_capture::kStarted)
+ return;
+
bool frames_created = true;
- const size_t needed_size = (info.width * info.height * 3) / 2;
+ const size_t needed_size = (frame_info_.width * frame_info_.height * 3) / 2;
{
base::AutoLock lock(lock_);
for (size_t i = 1; i <= kNoOfDIBS; ++i) {
« no previous file with comments | « content/browser/renderer_host/media/video_capture_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698