diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-22 10:19:20 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-22 10:19:20 +0000 |
commit | 8a4541fc6c5749ddf6d6bed49a4c69a897ff006f (patch) | |
tree | 2916ecb8ca9f19ebe1df995b20ec01fc673d89b3 /remoting | |
parent | 1c4582423ff5aa1776deef53bbd0c11c1f0bc354 (diff) | |
download | chromium_src-8a4541fc6c5749ddf6d6bed49a4c69a897ff006f.zip chromium_src-8a4541fc6c5749ddf6d6bed49a4c69a897ff006f.tar.gz chromium_src-8a4541fc6c5749ddf6d6bed49a4c69a897ff006f.tar.bz2 |
Simplify remoting::CaptureData
1. Previously CaptureData had pixel_format() field but we only use that
class for RGB. Removed that field.
2. Removed DataPlanes because it's doesn't make sense for RGB32. Instead
CaptureData class now stored data pointer and stride values.
TBR=tsepez@chromium.org
Review URL: https://chromiumcodereview.appspot.com/11637031
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@174519 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
20 files changed, 94 insertions, 240 deletions
diff --git a/remoting/capturer/capture_data.cc b/remoting/capturer/capture_data.cc index 55ba9e8..49511da 100644 --- a/remoting/capturer/capture_data.cc +++ b/remoting/capturer/capture_data.cc @@ -6,19 +6,10 @@ namespace remoting { -DataPlanes::DataPlanes() { - for (int i = 0; i < kPlaneCount; ++i) { - data[i] = NULL; - strides[i] = 0; - } -} - -CaptureData::CaptureData(const DataPlanes &data_planes, - const SkISize& size, - media::VideoFrame::Format format) - : data_planes_(data_planes), +CaptureData::CaptureData(uint8* data, int stride, const SkISize& size) + : data_(data), + stride_(stride), size_(size), - pixel_format_(format), capture_time_ms_(0), client_sequence_number_(0), dpi_(SkIPoint::Make(0, 0)) { diff --git a/remoting/capturer/capture_data.h b/remoting/capturer/capture_data.h index e30f30d..a68ebe8 100644 --- a/remoting/capturer/capture_data.h +++ b/remoting/capturer/capture_data.h @@ -9,7 +9,6 @@ #include "base/basictypes.h" #include "base/memory/ref_counted.h" -#include "media/base/video_frame.h" #include "remoting/capturer/shared_buffer.h" #include "third_party/skia/include/core/SkRegion.h" @@ -17,24 +16,20 @@ namespace remoting { class SharedBuffer; -struct DataPlanes { - DataPlanes(); - - static const int kPlaneCount = 3; - uint8* data[kPlaneCount]; - int strides[kPlaneCount]; -}; - // Stores the data and information of a capture to pass off to the // encoding thread. class CaptureData : public base::RefCountedThreadSafe<CaptureData> { public: - CaptureData(const DataPlanes &data_planes, - const SkISize& size, - media::VideoFrame::Format format); + // 32 bit RGB is 4 bytes per pixel. + static const int kBytesPerPixel = 4; - // Gets the data_planes data of the previous capture. - const DataPlanes& data_planes() const { return data_planes_; } + CaptureData(uint8* data, int stride, const SkISize& size); + + // Data buffer. + uint8* data() const { return data_; } + + // Distance in bytes between neighboring lines in the data buffer. + int stride() const { return stride_; } // Gets the dirty region from the previous capture. const SkRegion& dirty_region() const { return dirty_region_; } @@ -42,9 +37,6 @@ class CaptureData : public base::RefCountedThreadSafe<CaptureData> { // Returns the size of the image captured. SkISize size() const { return size_; } - // Gets the pixel format of the image captured. - media::VideoFrame::Format pixel_format() const { return pixel_format_; } - SkRegion& mutable_dirty_region() { return dirty_region_; } // Returns the time spent on capturing. @@ -65,10 +57,10 @@ class CaptureData : public base::RefCountedThreadSafe<CaptureData> { void set_dpi(const SkIPoint& dpi) { dpi_ = dpi; } - // Returns the shared memory buffer pointed to by |data_planes_.data[0]|. + // Returns the shared memory buffer pointed to by |data|. scoped_refptr<SharedBuffer> shared_buffer() const { return shared_buffer_; } - // Sets the shared memory buffer pointed to by |data_planes_.data[0]|. + // Sets the shared memory buffer pointed to by |data|. void set_shared_buffer(scoped_refptr<SharedBuffer> shared_buffer) { shared_buffer_ = shared_buffer; } @@ -77,10 +69,10 @@ class CaptureData : public base::RefCountedThreadSafe<CaptureData> { friend class base::RefCountedThreadSafe<CaptureData>; virtual ~CaptureData(); - const DataPlanes data_planes_; + uint8* data_; + int stride_; SkRegion dirty_region_; SkISize size_; - media::VideoFrame::Format pixel_format_; // Time spent in capture. Unit is in milliseconds. int capture_time_ms_; diff --git a/remoting/capturer/video_capturer_mock_objects.h b/remoting/capturer/video_capturer_mock_objects.h index 4774bed..5afd123 100644 --- a/remoting/capturer/video_capturer_mock_objects.h +++ b/remoting/capturer/video_capturer_mock_objects.h @@ -19,7 +19,6 @@ class MockVideoFrameCapturer : public VideoFrameCapturer { MOCK_METHOD1(Start, void(Delegate* delegate)); MOCK_METHOD0(Stop, void()); - MOCK_CONST_METHOD0(pixel_format, media::VideoFrame::Format()); MOCK_METHOD1(InvalidateRegion, void(const SkRegion& invalid_region)); MOCK_METHOD0(CaptureFrame, void()); MOCK_CONST_METHOD0(size_most_recent, const SkISize&()); diff --git a/remoting/capturer/video_frame_capturer.h b/remoting/capturer/video_frame_capturer.h index 927c610..d126126 100644 --- a/remoting/capturer/video_frame_capturer.h +++ b/remoting/capturer/video_frame_capturer.h @@ -8,7 +8,6 @@ #include "base/basictypes.h" #include "base/callback.h" #include "base/shared_memory.h" -#include "media/base/video_frame.h" #include "third_party/skia/include/core/SkRegion.h" namespace remoting { @@ -97,9 +96,6 @@ class VideoFrameCapturer { // Called at the end of a capturing session. virtual void Stop() = 0; - // Returns the pixel format of the screen. - virtual media::VideoFrame::Format pixel_format() const = 0; - // Invalidates the specified region. virtual void InvalidateRegion(const SkRegion& invalid_region) = 0; diff --git a/remoting/capturer/video_frame_capturer_fake.cc b/remoting/capturer/video_frame_capturer_fake.cc index a1294e9..a27e62cf1 100644 --- a/remoting/capturer/video_frame_capturer_fake.cc +++ b/remoting/capturer/video_frame_capturer_fake.cc @@ -23,8 +23,6 @@ COMPILE_ASSERT((kBoxWidth % kSpeed == 0) && (kWidth % kSpeed == 0) && (kBoxHeight % kSpeed == 0) && (kHeight % kSpeed == 0), sizes_must_be_multiple_of_kSpeed); -static const int kBytesPerPixel = 4; // 32 bit RGB is 4 bytes per pixel. - VideoFrameCapturerFake::VideoFrameCapturerFake() : size_(SkISize::Make(0, 0)), bytes_per_row_(0), @@ -32,8 +30,7 @@ VideoFrameCapturerFake::VideoFrameCapturerFake() box_pos_y_(0), box_speed_x_(kSpeed), box_speed_y_(kSpeed), - current_buffer_(0), - pixel_format_(media::VideoFrame::RGB32) { + current_buffer_(0) { ScreenConfigurationChanged(); } @@ -47,10 +44,6 @@ void VideoFrameCapturerFake::Start(Delegate* delegate) { void VideoFrameCapturerFake::Stop() { } -media::VideoFrame::Format VideoFrameCapturerFake::pixel_format() const { - return pixel_format_; -} - void VideoFrameCapturerFake::InvalidateRegion(const SkRegion& invalid_region) { helper_.InvalidateRegion(invalid_region); } @@ -64,14 +57,10 @@ void VideoFrameCapturerFake::CaptureFrame() { SkRegion invalid_region; helper_.SwapInvalidRegion(&invalid_region); - DataPlanes planes; - planes.data[0] = buffers_[current_buffer_].get(); current_buffer_ = (current_buffer_ + 1) % kNumBuffers; - planes.strides[0] = bytes_per_row_; - scoped_refptr<CaptureData> capture_data(new CaptureData(planes, - size_, - pixel_format_)); + scoped_refptr<CaptureData> capture_data(new CaptureData( + buffers_[current_buffer_].get(), bytes_per_row_, size_)); capture_data->mutable_dirty_region() = invalid_region; helper_.set_size_most_recent(capture_data->size()); @@ -87,10 +76,10 @@ const SkISize& VideoFrameCapturerFake::size_most_recent() const { void VideoFrameCapturerFake::GenerateImage() { memset(buffers_[current_buffer_].get(), 0xff, - size_.width() * size_.height() * kBytesPerPixel); + size_.width() * size_.height() * CaptureData::kBytesPerPixel); uint8* row = buffers_[current_buffer_].get() + - (box_pos_y_ * size_.width() + box_pos_x_) * kBytesPerPixel; + (box_pos_y_ * size_.width() + box_pos_x_) * CaptureData::kBytesPerPixel; box_pos_x_ += box_speed_x_; if (box_pos_x_ + kBoxWidth >= size_.width() || box_pos_x_ == 0) @@ -109,10 +98,10 @@ void VideoFrameCapturerFake::GenerateImage() { int r = x * 255 / kBoxWidth; int g = y * 255 / kBoxHeight; int b = 255 - (x * 255 / kBoxWidth); - row[x * kBytesPerPixel] = r; - row[x * kBytesPerPixel+1] = g; - row[x * kBytesPerPixel+2] = b; - row[x * kBytesPerPixel+3] = 0xff; + row[x * CaptureData::kBytesPerPixel] = r; + row[x * CaptureData::kBytesPerPixel + 1] = g; + row[x * CaptureData::kBytesPerPixel + 2] = b; + row[x * CaptureData::kBytesPerPixel + 3] = 0xff; } row += bytes_per_row_; } @@ -120,8 +109,7 @@ void VideoFrameCapturerFake::GenerateImage() { void VideoFrameCapturerFake::ScreenConfigurationChanged() { size_ = SkISize::Make(kWidth, kHeight); - bytes_per_row_ = size_.width() * kBytesPerPixel; - pixel_format_ = media::VideoFrame::RGB32; + bytes_per_row_ = size_.width() * CaptureData::kBytesPerPixel; // Create memory for the buffers. int buffer_size = size_.height() * bytes_per_row_; diff --git a/remoting/capturer/video_frame_capturer_fake.h b/remoting/capturer/video_frame_capturer_fake.h index 1084a08..c3a818b 100644 --- a/remoting/capturer/video_frame_capturer_fake.h +++ b/remoting/capturer/video_frame_capturer_fake.h @@ -23,7 +23,6 @@ class VideoFrameCapturerFake : public VideoFrameCapturer { // Overridden from VideoFrameCapturer: virtual void Start(Delegate* delegate) OVERRIDE; virtual void Stop() OVERRIDE; - virtual media::VideoFrame::Format pixel_format() const OVERRIDE; virtual void InvalidateRegion(const SkRegion& invalid_region) OVERRIDE; virtual void CaptureFrame() OVERRIDE; virtual const SkISize& size_most_recent() const OVERRIDE; @@ -53,9 +52,6 @@ class VideoFrameCapturerFake : public VideoFrameCapturer { // The current buffer with valid data for reading. int current_buffer_; - // Format of pixels returned in buffer. - media::VideoFrame::Format pixel_format_; - DISALLOW_COPY_AND_ASSIGN(VideoFrameCapturerFake); }; diff --git a/remoting/capturer/video_frame_capturer_linux.cc b/remoting/capturer/video_frame_capturer_linux.cc index 3b17687..c3f33af 100644 --- a/remoting/capturer/video_frame_capturer_linux.cc +++ b/remoting/capturer/video_frame_capturer_linux.cc @@ -28,8 +28,6 @@ namespace remoting { namespace { -static const int kBytesPerPixel = 4; - // Default to false, since many systems have broken XDamage support - see // http://crbug.com/73423. static bool g_should_use_x_damage = false; @@ -62,7 +60,6 @@ class VideoFrameCapturerLinux : public VideoFrameCapturer { // Capturer interface. virtual void Start(Delegate* delegate) OVERRIDE; virtual void Stop() OVERRIDE; - virtual media::VideoFrame::Format pixel_format() const OVERRIDE; virtual void InvalidateRegion(const SkRegion& invalid_region) OVERRIDE; virtual void CaptureFrame() OVERRIDE; virtual const SkISize& size_most_recent() const OVERRIDE; @@ -143,9 +140,6 @@ class VideoFrameCapturerLinux : public VideoFrameCapturer { // Queue of the frames buffers. VideoFrameQueue queue_; - // Format of pixels returned in buffer. - media::VideoFrame::Format pixel_format_; - // Invalid region from the previous capture. This is used to synchronize the // current with the last buffer used. SkRegion last_invalid_region_; @@ -157,7 +151,7 @@ class VideoFrameCapturerLinux : public VideoFrameCapturer { }; VideoFrameLinux::VideoFrameLinux(const SkISize& window_size) { - set_bytes_per_row(window_size.width() * kBytesPerPixel); + set_bytes_per_row(window_size.width() * CaptureData::kBytesPerPixel); set_dimensions(window_size); size_t buffer_size = bytes_per_row() * window_size.height(); @@ -181,8 +175,7 @@ VideoFrameCapturerLinux::VideoFrameCapturerLinux() damage_handle_(0), damage_event_base_(-1), damage_error_base_(-1), - damage_region_(0), - pixel_format_(media::VideoFrame::RGB32) { + damage_region_(0) { helper_.SetLogGridSize(4); } @@ -288,10 +281,6 @@ void VideoFrameCapturerLinux::Start(Delegate* delegate) { void VideoFrameCapturerLinux::Stop() { } -media::VideoFrame::Format VideoFrameCapturerLinux::pixel_format() const { - return pixel_format_; -} - void VideoFrameCapturerLinux::InvalidateRegion(const SkRegion& invalid_region) { helper_.InvalidateRegion(invalid_region); } @@ -320,7 +309,7 @@ void VideoFrameCapturerLinux::CaptureFrame() { (differ_->bytes_per_row() != current_buffer->bytes_per_row()))) { differ_.reset(new Differ(current_buffer->dimensions().width(), current_buffer->dimensions().height(), - kBytesPerPixel, + CaptureData::kBytesPerPixel, current_buffer->bytes_per_row())); } @@ -375,8 +364,8 @@ void VideoFrameCapturerLinux::CaptureCursor() { cursor->size.set(img->width, img->height); cursor->hotspot.set(img->xhot, img->yhot); - int total_bytes = - cursor->size.width() * cursor->size.height() * kBytesPerPixel; + int total_bytes = cursor->size.width() * cursor->size.height() * + CaptureData::kBytesPerPixel; cursor->data.resize(total_bytes); // Xlib stores 32-bit data in longs, even if longs are 64-bits long. @@ -392,13 +381,9 @@ void VideoFrameCapturerLinux::CaptureCursor() { } scoped_refptr<CaptureData> VideoFrameCapturerLinux::CaptureScreen() { - VideoFrame* current = queue_.current_frame(); - DataPlanes planes; - planes.data[0] = current->pixels(); - planes.strides[0] = current->bytes_per_row(); - - scoped_refptr<CaptureData> capture_data( - new CaptureData(planes, current->dimensions(), media::VideoFrame::RGB32)); + VideoFrame* frame = queue_.current_frame(); + scoped_refptr<CaptureData> capture_data(new CaptureData( + frame->pixels(), frame->bytes_per_row(), frame->dimensions())); // Pass the screen size to the helper, so it can clip the invalid region if it // expands that region to a grid. @@ -443,8 +428,8 @@ scoped_refptr<CaptureData> VideoFrameCapturerLinux::CaptureScreen() { } else { // Doing full-screen polling, or this is the first capture after a // screen-resolution change. In either case, need a full-screen capture. - SkIRect screen_rect = SkIRect::MakeWH(current->dimensions().width(), - current->dimensions().height()); + SkIRect screen_rect = SkIRect::MakeWH(frame->dimensions().width(), + frame->dimensions().height()); CaptureRect(screen_rect, capture_data); if (queue_.previous_frame()) { @@ -452,7 +437,7 @@ scoped_refptr<CaptureData> VideoFrameCapturerLinux::CaptureScreen() { // changed pixels between current and previous buffers. DCHECK(differ_ != NULL); differ_->CalcDirtyRegion(queue_.previous_frame()->pixels(), - current->pixels(), &invalid_region); + frame->pixels(), &invalid_region); } else { // No previous buffer, so always invalidate the whole screen, whether // or not DAMAGE is being used. DAMAGE doesn't necessarily send a @@ -493,11 +478,12 @@ void VideoFrameCapturerLinux::SynchronizeFrame() { DCHECK_NE(current, last); for (SkRegion::Iterator it(last_invalid_region_); !it.done(); it.next()) { const SkIRect& r = it.rect(); - int offset = r.fTop * current->bytes_per_row() + r.fLeft * kBytesPerPixel; + int offset = r.fTop * current->bytes_per_row() + + r.fLeft * CaptureData::kBytesPerPixel; for (int i = 0; i < r.height(); ++i) { memcpy(current->pixels() + offset, last->pixels() + offset, - r.width() * kBytesPerPixel); - offset += current->dimensions().width() * kBytesPerPixel; + r.width() * CaptureData::kBytesPerPixel); + offset += current->dimensions().width() * CaptureData::kBytesPerPixel; } } } @@ -543,27 +529,20 @@ void VideoFrameCapturerLinux::FastBlit(uint8* image, const SkIRect& rect, int src_stride = x_server_pixel_buffer_.GetStride(); int dst_x = rect.fLeft, dst_y = rect.fTop; - DataPlanes planes = capture_data->data_planes(); - uint8* dst_buffer = planes.data[0]; - - const int dst_stride = planes.strides[0]; - - uint8* dst_pos = dst_buffer + dst_stride * dst_y; - dst_pos += dst_x * kBytesPerPixel; + uint8* dst_pos = capture_data->data() + capture_data->stride() * dst_y; + dst_pos += dst_x * CaptureData::kBytesPerPixel; - int height = rect.height(), row_bytes = rect.width() * kBytesPerPixel; + int height = rect.height(); + int row_bytes = rect.width() * CaptureData::kBytesPerPixel; for (int y = 0; y < height; ++y) { memcpy(dst_pos, src_pos, row_bytes); src_pos += src_stride; - dst_pos += dst_stride; + dst_pos += capture_data->stride(); } } void VideoFrameCapturerLinux::SlowBlit(uint8* image, const SkIRect& rect, CaptureData* capture_data) { - DataPlanes planes = capture_data->data_planes(); - uint8* dst_buffer = planes.data[0]; - const int dst_stride = planes.strides[0]; int src_stride = x_server_pixel_buffer_.GetStride(); int dst_x = rect.fLeft, dst_y = rect.fTop; int width = rect.width(), height = rect.height(); @@ -581,9 +560,9 @@ void VideoFrameCapturerLinux::SlowBlit(uint8* image, const SkIRect& rect, unsigned int bits_per_pixel = x_server_pixel_buffer_.GetBitsPerPixel(); - uint8* dst_pos = dst_buffer + dst_stride * dst_y; + uint8* dst_pos = capture_data->data() + capture_data->stride() * dst_y; uint8* src_pos = image; - dst_pos += dst_x * kBytesPerPixel; + dst_pos += dst_x * CaptureData::kBytesPerPixel; // TODO(hclam): Optimize, perhaps using MMX code or by converting to // YUV directly for (int y = 0; y < height; y++) { @@ -605,7 +584,7 @@ void VideoFrameCapturerLinux::SlowBlit(uint8* image, const SkIRect& rect, // Write as 32-bit RGB. dst_pos_32[x] = r << 16 | g << 8 | b; } - dst_pos += dst_stride; + dst_pos += capture_data->stride(); src_pos += src_stride; } } diff --git a/remoting/capturer/video_frame_capturer_mac.mm b/remoting/capturer/video_frame_capturer_mac.mm index 40c5765..8230c9b 100644 --- a/remoting/capturer/video_frame_capturer_mac.mm +++ b/remoting/capturer/video_frame_capturer_mac.mm @@ -110,7 +110,6 @@ class VideoFrameCapturerMac : public VideoFrameCapturer { // Overridden from VideoFrameCapturer: virtual void Start(Delegate* delegate) OVERRIDE; virtual void Stop() OVERRIDE; - virtual media::VideoFrame::Format pixel_format() const OVERRIDE; virtual void InvalidateRegion(const SkRegion& invalid_region) OVERRIDE; virtual void CaptureFrame() OVERRIDE; virtual const SkISize& size_most_recent() const OVERRIDE; @@ -167,9 +166,6 @@ class VideoFrameCapturerMac : public VideoFrameCapturer { // Contains an invalid region from the previous capture. SkRegion last_invalid_region_; - // Format of pixels returned in buffer. - media::VideoFrame::Format pixel_format_; - // Used to ensure that frame captures do not take place while displays // are being reconfigured. base::WaitableEvent display_configuration_capture_event_; @@ -216,7 +212,6 @@ VideoFrameMac::~VideoFrameMac() { VideoFrameCapturerMac::VideoFrameCapturerMac() : delegate_(NULL), cgl_context_(NULL), - pixel_format_(media::VideoFrame::RGB32), display_configuration_capture_event_(false, true), power_assertion_id_display_(kIOPMNullAssertionID), power_assertion_id_user_(kIOPMNullAssertionID), @@ -309,10 +304,6 @@ void VideoFrameCapturerMac::Stop() { } } -media::VideoFrame::Format VideoFrameCapturerMac::pixel_format() const { - return pixel_format_; -} - void VideoFrameCapturerMac::InvalidateRegion(const SkRegion& invalid_region) { helper_.InvalidateRegion(invalid_region); } @@ -363,16 +354,15 @@ void VideoFrameCapturerMac::CaptureFrame() { CgBlitPreLion(*current_buffer, region); } - DataPlanes planes; - planes.data[0] = current_buffer->pixels(); - planes.strides[0] = current_buffer->bytes_per_row(); + uint8* buffer = current_buffer->pixels(); + int stride = current_buffer->bytes_per_row(); if (flip) { - planes.strides[0] = -planes.strides[0]; - planes.data[0] += (current_buffer->dimensions().height() - 1) * + stride = -stride; + buffer += (current_buffer->dimensions().height() - 1) * current_buffer->bytes_per_row(); } - data = new CaptureData(planes, current_buffer->dimensions(), pixel_format()); + data = new CaptureData(buffer, stride, current_buffer->dimensions()); data->set_dpi(static_cast<VideoFrameMac*>(current_buffer)->dpi()); data->mutable_dirty_region() = region; diff --git a/remoting/capturer/video_frame_capturer_mac_unittest.cc b/remoting/capturer/video_frame_capturer_mac_unittest.cc index 1a93add..12435b3 100644 --- a/remoting/capturer/video_frame_capturer_mac_unittest.cc +++ b/remoting/capturer/video_frame_capturer_mac_unittest.cc @@ -71,16 +71,11 @@ void VideoFrameCapturerMacTest::CaptureDoneCallback2( EXPECT_EQ(region_, capture_data->dirty_region()); EXPECT_EQ(width, capture_data->size().width()); EXPECT_EQ(height, capture_data->size().height()); - const DataPlanes &planes = capture_data->data_planes(); - EXPECT_TRUE(planes.data[0] != NULL); - EXPECT_TRUE(planes.data[1] == NULL); - EXPECT_TRUE(planes.data[2] == NULL); + EXPECT_TRUE(capture_data->data() != NULL); // Depending on the capture method, the screen may be flipped or not, so // the stride may be positive or negative. EXPECT_EQ(static_cast<int>(sizeof(uint32_t) * width), - abs(planes.strides[0])); - EXPECT_EQ(0, planes.strides[1]); - EXPECT_EQ(0, planes.strides[2]); + abs(capture_data->stride())); } TEST_F(VideoFrameCapturerMacTest, Capture) { diff --git a/remoting/capturer/video_frame_capturer_win.cc b/remoting/capturer/video_frame_capturer_win.cc index e9f5ab1..d39ee64 100644 --- a/remoting/capturer/video_frame_capturer_win.cc +++ b/remoting/capturer/video_frame_capturer_win.cc @@ -84,7 +84,6 @@ class VideoFrameCapturerWin : public VideoFrameCapturer { // Overridden from VideoFrameCapturer: virtual void Start(Delegate* delegate) OVERRIDE; virtual void Stop() OVERRIDE; - virtual media::VideoFrame::Format pixel_format() const OVERRIDE; virtual void InvalidateRegion(const SkRegion& invalid_region) OVERRIDE; virtual void CaptureFrame() OVERRIDE; virtual const SkISize& size_most_recent() const OVERRIDE; @@ -134,9 +133,6 @@ class VideoFrameCapturerWin : public VideoFrameCapturer { // Rectangle describing the bounds of the desktop device context. SkIRect desktop_dc_rect_; - // Format of pixels returned in buffer. - media::VideoFrame::Format pixel_format_; - // Class to calculate the difference between two screen bitmaps. scoped_ptr<Differ> differ_; @@ -148,8 +144,6 @@ class VideoFrameCapturerWin : public VideoFrameCapturer { // 3780 pixels per meter is equivalent to 96 DPI, typical on desktop monitors. static const int kPixelsPerMeter = 3780; -// 32 bit RGBA is 4 bytes per pixel. -static const int kBytesPerPixel = 4; VideoFrameWin::VideoFrameWin( HDC desktop_dc, @@ -157,7 +151,8 @@ VideoFrameWin::VideoFrameWin( SharedBufferFactory* shared_buffer_factory) : shared_buffer_factory_(shared_buffer_factory) { // Allocate a shared memory buffer. - uint32 buffer_size = size.width() * size.height() * kBytesPerPixel; + uint32 buffer_size = + size.width() * size.height() * CaptureData::kBytesPerPixel; if (shared_buffer_factory_) { scoped_refptr<SharedBuffer> shared_buffer = shared_buffer_factory_->CreateSharedBuffer(buffer_size); @@ -178,7 +173,7 @@ HBITMAP VideoFrameWin::GetBitmap() { } void VideoFrameWin::AllocateBitmap(HDC desktop_dc, const SkISize& size) { - int bytes_per_row = size.width() * kBytesPerPixel; + int bytes_per_row = size.width() * CaptureData::kBytesPerPixel; // Describe a device independent bitmap (DIB) that is the size of the desktop. BITMAPINFO bmi; @@ -186,7 +181,7 @@ void VideoFrameWin::AllocateBitmap(HDC desktop_dc, const SkISize& size) { bmi.bmiHeader.biHeight = -size.height(); bmi.bmiHeader.biWidth = size.width(); bmi.bmiHeader.biPlanes = 1; - bmi.bmiHeader.biBitCount = kBytesPerPixel * 8; + bmi.bmiHeader.biBitCount = CaptureData::kBytesPerPixel * 8; bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader); bmi.bmiHeader.biSizeImage = bytes_per_row * size.height(); bmi.bmiHeader.biXPelsPerMeter = kPixelsPerMeter; @@ -215,7 +210,6 @@ VideoFrameCapturerWin::VideoFrameCapturerWin() : shared_buffer_factory_(NULL), delegate_(NULL), desktop_dc_rect_(SkIRect::MakeEmpty()), - pixel_format_(media::VideoFrame::RGB32), composition_func_(NULL) { } @@ -224,17 +218,12 @@ VideoFrameCapturerWin::VideoFrameCapturerWin( : shared_buffer_factory_(shared_buffer_factory), delegate_(NULL), desktop_dc_rect_(SkIRect::MakeEmpty()), - pixel_format_(media::VideoFrame::RGB32), composition_func_(NULL) { } VideoFrameCapturerWin::~VideoFrameCapturerWin() { } -media::VideoFrame::Format VideoFrameCapturerWin::pixel_format() const { - return pixel_format_; -} - void VideoFrameCapturerWin::InvalidateRegion(const SkRegion& invalid_region) { helper_.InvalidateRegion(invalid_region); } @@ -262,7 +251,7 @@ void VideoFrameCapturerWin::CaptureFrame() { (differ_->bytes_per_row() != current_buffer->bytes_per_row())) { differ_.reset(new Differ(current_buffer->dimensions().width(), current_buffer->dimensions().height(), - kBytesPerPixel, + CaptureData::kBytesPerPixel, current_buffer->bytes_per_row())); } @@ -370,13 +359,9 @@ void VideoFrameCapturerWin::CaptureRegion( const base::Time& capture_start_time) { const VideoFrame* current_buffer = queue_.current_frame(); - DataPlanes planes; - planes.data[0] = current_buffer->pixels(); - planes.strides[0] = current_buffer->bytes_per_row(); - - scoped_refptr<CaptureData> data(new CaptureData(planes, - current_buffer->dimensions(), - pixel_format_)); + scoped_refptr<CaptureData> data( + new CaptureData(current_buffer->pixels(), current_buffer->bytes_per_row(), + current_buffer->dimensions())); data->mutable_dirty_region() = region; data->set_shared_buffer(current_buffer->shared_buffer()); @@ -396,9 +381,6 @@ void VideoFrameCapturerWin::CaptureImage() { if (queue_.current_frame_needs_update()) { DCHECK(desktop_dc_.get() != NULL); DCHECK(memory_dc_.Get() != NULL); - // Windows requires DIB sections' rows to start DWORD-aligned, which is - // implicit when working with RGB32 pixels. - DCHECK_EQ(pixel_format_, media::VideoFrame::RGB32); SkISize size = SkISize::Make(desktop_dc_rect_.width(), desktop_dc_rect_.height()); @@ -501,7 +483,7 @@ void VideoFrameCapturerWin::CaptureCursor() { if (!color_bitmap) { height /= 2; } - int data_size = height * width * kBytesPerPixel; + int data_size = height * width * CaptureData::kBytesPerPixel; scoped_ptr<MouseCursorShape> cursor(new MouseCursorShape()); cursor->data.resize(data_size); @@ -529,10 +511,10 @@ void VideoFrameCapturerWin::CaptureCursor() { dst[1] = SkAlphaMul(src[1], src[3]); dst[2] = SkAlphaMul(src[2], src[3]); dst[3] = src[3]; - dst += kBytesPerPixel; - src += kBytesPerPixel; + dst += CaptureData::kBytesPerPixel; + src += CaptureData::kBytesPerPixel; } - src -= row_bytes + (width * kBytesPerPixel); + src -= row_bytes + (width * CaptureData::kBytesPerPixel); } } else { if (bitmap.bmPlanes != 1 || bitmap.bmBitsPixel != 1) { diff --git a/remoting/codec/codec_test.cc b/remoting/codec/codec_test.cc index fb2d1a6..7f45828 100644 --- a/remoting/codec/codec_test.cc +++ b/remoting/codec/codec_test.cc @@ -204,10 +204,10 @@ class VideoDecoderTester { EXPECT_EQ(expected_region_, update_region_); for (SkRegion::Iterator i(update_region_); !i.done(); i.next()) { const int stride = view_size_.width() * kBytesPerPixel; - EXPECT_EQ(stride, capture_data_->data_planes().strides[0]); + EXPECT_EQ(stride, capture_data_->stride()); const int offset = stride * i.rect().top() + kBytesPerPixel * i.rect().left(); - const uint8* original = capture_data_->data_planes().data[0] + offset; + const uint8* original = capture_data_->data() + offset; const uint8* decoded = image_data_.get() + offset; const int row_size = kBytesPerPixel * i.rect().width(); for (int y = 0; y < i.rect().height(); ++y) { @@ -318,10 +318,7 @@ class VideoEncoderTester { }; scoped_refptr<CaptureData> PrepareEncodeData(const SkISize& size, - media::VideoFrame::Format format, scoped_array<uint8>* memory) { - // TODO(hclam): Support also YUV format. - CHECK_EQ(format, media::VideoFrame::RGB32); int memory_size = size.width() * size.height() * kBytesPerPixel; memory->reset(new uint8[memory_size]); @@ -331,14 +328,8 @@ scoped_refptr<CaptureData> PrepareEncodeData(const SkISize& size, (*memory)[i] = rand() % 256; } - DataPlanes planes; - memset(planes.data, 0, sizeof(planes.data)); - memset(planes.strides, 0, sizeof(planes.strides)); - planes.data[0] = memory->get(); - planes.strides[0] = size.width() * kBytesPerPixel; - scoped_refptr<CaptureData> data = - new CaptureData(planes, size, format); + new CaptureData(memory->get(), size.width() * kBytesPerPixel, size); return data; } @@ -370,7 +361,7 @@ void TestVideoEncoder(VideoEncoder* encoder, bool strict) { for (size_t yi = 0; yi < arraysize(kSizes); ++yi) { SkISize size = SkISize::Make(kSizes[xi], kSizes[yi]); scoped_refptr<CaptureData> data = - PrepareEncodeData(size, media::VideoFrame::RGB32, &memory); + PrepareEncodeData(size, &memory); std::vector<std::vector<SkIRect> > test_rect_lists = MakeTestRectLists(size); for (size_t i = 0; i < test_rect_lists.size(); ++i) { @@ -394,16 +385,15 @@ static void TestEncodeDecodeRects(VideoEncoder* encoder, // Generate random data for the updated region. srand(0); for (int i = 0; i < count; ++i) { - CHECK_EQ(data->pixel_format(), media::VideoFrame::RGB32); const int bytes_per_pixel = 4; // Because of RGB32 on previous line. const int row_size = bytes_per_pixel * rects[i].width(); - uint8* memory = data->data_planes().data[0] + - data->data_planes().strides[0] * rects[i].top() + + uint8* memory = data->data() + + data->stride() * rects[i].top() + bytes_per_pixel * rects[i].left(); for (int y = 0; y < rects[i].height(); ++y) { for (int x = 0; x < row_size; ++x) memory[x] = rand() % 256; - memory += data->data_planes().strides[0]; + memory += data->stride(); } } @@ -423,8 +413,7 @@ void TestVideoEncoderDecoder( VideoEncoderTester encoder_tester(&message_tester); scoped_array<uint8> memory; - scoped_refptr<CaptureData> data = - PrepareEncodeData(kSize, media::VideoFrame::RGB32, &memory); + scoped_refptr<CaptureData> data = PrepareEncodeData(kSize, &memory); VideoDecoderTester decoder_tester(decoder, kSize, kSize); decoder_tester.set_strict(strict); @@ -469,14 +458,9 @@ void TestVideoEncoderDecoderGradient(VideoEncoder* encoder, view_size.width() * view_size.height() * kBytesPerPixel]); FillWithGradient(expected_view_data.get(), view_size, view_rect); - DataPlanes planes; - memset(planes.data, 0, sizeof(planes.data)); - memset(planes.strides, 0, sizeof(planes.strides)); - planes.data[0] = screen_data.get(); - planes.strides[0] = screen_size.width() * kBytesPerPixel; - scoped_refptr<CaptureData> capture_data = - new CaptureData(planes, screen_size, media::VideoFrame::RGB32); + new CaptureData(screen_data.get(), screen_size.width() * kBytesPerPixel, + screen_size); capture_data->mutable_dirty_region().op(screen_rect, SkRegion::kUnion_Op); VideoDecoderTester decoder_tester(decoder, screen_size, view_size); diff --git a/remoting/codec/video_encoder_verbatim.cc b/remoting/codec/video_encoder_verbatim.cc index 0884551..0633ac2 100644 --- a/remoting/codec/video_encoder_verbatim.cc +++ b/remoting/codec/video_encoder_verbatim.cc @@ -29,9 +29,6 @@ void VideoEncoderVerbatim::Encode( scoped_refptr<CaptureData> capture_data, bool key_frame, const DataAvailableCallback& data_available_callback) { - CHECK(capture_data->pixel_format() == media::VideoFrame::RGB32) - << "RowBased VideoEncoder only works with RGB32. Got " - << capture_data->pixel_format(); capture_data_ = capture_data; callback_ = data_available_callback; encode_start_time_ = base::Time::Now(); @@ -49,16 +46,15 @@ void VideoEncoderVerbatim::Encode( } void VideoEncoderVerbatim::EncodeRect(const SkIRect& rect, bool last) { - CHECK(capture_data_->data_planes().data[0]); - CHECK_EQ(capture_data_->pixel_format(), media::VideoFrame::RGB32); - const int strides = capture_data_->data_planes().strides[0]; + CHECK(capture_data_->data()); + const int stride = capture_data_->stride(); const int bytes_per_pixel = 4; const int row_size = bytes_per_pixel * rect.width(); scoped_ptr<VideoPacket> packet(new VideoPacket()); PrepareUpdateStart(rect, packet.get()); - const uint8* in = capture_data_->data_planes().data[0] + - rect.fTop * strides + rect.fLeft * bytes_per_pixel; + const uint8* in = capture_data_->data() + + rect.fTop * stride + rect.fLeft * bytes_per_pixel; // TODO(hclam): Fill in the sequence number. uint8* out = GetOutputBuffer(packet.get(), max_packet_size_); int filled = 0; @@ -82,7 +78,7 @@ void VideoEncoderVerbatim::EncodeRect(const SkIRect& rect, bool last) { // Jump to the next row when we've reached the end of the current row. if (row_pos == row_size) { row_pos = 0; - in += strides; + in += stride; ++row_y; } } diff --git a/remoting/codec/video_encoder_vp8.cc b/remoting/codec/video_encoder_vp8.cc index 3295904..03758ca 100644 --- a/remoting/codec/video_encoder_vp8.cc +++ b/remoting/codec/video_encoder_vp8.cc @@ -147,10 +147,6 @@ bool VideoEncoderVp8::Init(const SkISize& size) { void VideoEncoderVp8::PrepareImage(scoped_refptr<CaptureData> capture_data, SkRegion* updated_region) { - // Perform RGB->YUV conversion. - DCHECK_EQ(capture_data->pixel_format(), media::VideoFrame::RGB32) - << "Only RGB32 is supported"; - const SkRegion& region = capture_data->dirty_region(); if (region.isEmpty()) { updated_region->setEmpty(); @@ -174,8 +170,8 @@ void VideoEncoderVp8::PrepareImage(scoped_refptr<CaptureData> capture_data, SkRegion::kIntersect_Op); // Convert the updated region to YUV ready for encoding. - const uint8* rgb_data = capture_data->data_planes().data[0]; - const int rgb_stride = capture_data->data_planes().strides[0]; + const uint8* rgb_data = capture_data->data(); + const int rgb_stride = capture_data->stride(); const int y_stride = image_->stride[0]; DCHECK_EQ(image_->stride[1], image_->stride[2]); const int uv_stride = image_->stride[1]; diff --git a/remoting/codec/video_encoder_vp8_unittest.cc b/remoting/codec/video_encoder_vp8_unittest.cc index 5707c98..11d5ded 100644 --- a/remoting/codec/video_encoder_vp8_unittest.cc +++ b/remoting/codec/video_encoder_vp8_unittest.cc @@ -45,19 +45,15 @@ TEST(VideoEncoderVp8Test, TestSizeChangeNoLeak) { VideoEncoderCallback callback; std::vector<uint8> buffer(width * height * kBytesPerPixel); - DataPlanes planes; - planes.data[0] = &buffer.front(); - planes.strides[0] = width; - scoped_refptr<CaptureData> capture_data(new CaptureData( - planes, SkISize::Make(width, height), media::VideoFrame::RGB32)); + &buffer.front(), width * kBytesPerPixel, SkISize::Make(width, height))); encoder.Encode(capture_data, false, base::Bind(&VideoEncoderCallback::DataAvailable, base::Unretained(&callback))); height /= 2; - capture_data = new CaptureData(planes, SkISize::Make(width, height), - media::VideoFrame::RGB32); + capture_data = new CaptureData( + &buffer.front(), width * kBytesPerPixel, SkISize::Make(width, height)); encoder.Encode(capture_data, false, base::Bind(&VideoEncoderCallback::DataAvailable, base::Unretained(&callback))); @@ -82,12 +78,8 @@ TEST(VideoEncoderVp8Test, TestDpiPropagation) { VideoEncoderDpiCallback callback; std::vector<uint8> buffer(width * height * kBytesPerPixel); - DataPlanes planes; - planes.data[0] = &buffer.front(); - planes.strides[0] = width; - scoped_refptr<CaptureData> capture_data(new CaptureData( - planes, SkISize::Make(width, height), media::VideoFrame::RGB32)); + &buffer.front(), width * kBytesPerPixel, SkISize::Make(width, height))); capture_data->set_dpi(SkIPoint::Make(96, 97)); encoder.Encode(capture_data, false, base::Bind(&VideoEncoderDpiCallback::DataAvailable, diff --git a/remoting/host/chromoting_messages.h b/remoting/host/chromoting_messages.h index f389467..214007a 100644 --- a/remoting/host/chromoting_messages.h +++ b/remoting/host/chromoting_messages.h @@ -148,9 +148,6 @@ IPC_STRUCT_BEGIN(SerializedCapturedData) // Dimentions of the buffer in pixels. IPC_STRUCT_MEMBER(SkISize, dimensions) - // Pixel format. - IPC_STRUCT_MEMBER(int32, pixel_format) - // Time spent in capture. Unit is in milliseconds. IPC_STRUCT_MEMBER(int, capture_time_ms) diff --git a/remoting/host/desktop_session_agent.cc b/remoting/host/desktop_session_agent.cc index e918850..64492f5 100644 --- a/remoting/host/desktop_session_agent.cc +++ b/remoting/host/desktop_session_agent.cc @@ -149,9 +149,8 @@ void DesktopSessionAgent::OnCaptureCompleted( // Serialize CaptureData SerializedCapturedData serialized_data; serialized_data.shared_buffer_id = capture_data->shared_buffer()->id(); - serialized_data.bytes_per_row = capture_data->data_planes().strides[0]; + serialized_data.bytes_per_row = capture_data->stride(); serialized_data.dimensions = capture_data->size(); - serialized_data.pixel_format = capture_data->pixel_format(); serialized_data.capture_time_ms = capture_data->capture_time_ms(); serialized_data.client_sequence_number = capture_data->client_sequence_number(); diff --git a/remoting/host/desktop_session_proxy.cc b/remoting/host/desktop_session_proxy.cc index 74043e1..6489df45 100644 --- a/remoting/host/desktop_session_proxy.cc +++ b/remoting/host/desktop_session_proxy.cc @@ -287,13 +287,9 @@ void DesktopSessionProxy::OnCaptureCompleted( GetSharedBuffer(serialized_data.shared_buffer_id); CHECK(shared_buffer); - DataPlanes planes; - planes.data[0] = reinterpret_cast<uint8*>(shared_buffer->ptr()); - planes.strides[0] = serialized_data.bytes_per_row; - - capture_data = new CaptureData( - planes, serialized_data.dimensions, - static_cast<media::VideoFrame::Format>(serialized_data.pixel_format)); + capture_data = new CaptureData(reinterpret_cast<uint8*>(shared_buffer->ptr()), + serialized_data.bytes_per_row, + serialized_data.dimensions); capture_data->set_capture_time_ms(serialized_data.capture_time_ms); capture_data->set_client_sequence_number( serialized_data.client_sequence_number); diff --git a/remoting/host/ipc_video_frame_capturer.cc b/remoting/host/ipc_video_frame_capturer.cc index e0629b8..4c67a5d 100644 --- a/remoting/host/ipc_video_frame_capturer.cc +++ b/remoting/host/ipc_video_frame_capturer.cc @@ -30,10 +30,6 @@ void IpcVideoFrameCapturer::Stop() { delegate_ = NULL; } -media::VideoFrame::Format IpcVideoFrameCapturer::pixel_format() const { - return media::VideoFrame::RGB32; -} - void IpcVideoFrameCapturer::InvalidateRegion(const SkRegion& invalid_region) { desktop_session_proxy_->InvalidateRegion(invalid_region); } diff --git a/remoting/host/ipc_video_frame_capturer.h b/remoting/host/ipc_video_frame_capturer.h index c8590ef5..e942028 100644 --- a/remoting/host/ipc_video_frame_capturer.h +++ b/remoting/host/ipc_video_frame_capturer.h @@ -28,7 +28,6 @@ class IpcVideoFrameCapturer : public VideoFrameCapturer { // VideoFrameCapturer interface. virtual void Start(Delegate* delegate) OVERRIDE; virtual void Stop() OVERRIDE; - virtual media::VideoFrame::Format pixel_format() const OVERRIDE; virtual void InvalidateRegion(const SkRegion& invalid_region) OVERRIDE; virtual void CaptureFrame() OVERRIDE; virtual const SkISize& size_most_recent() const OVERRIDE; diff --git a/remoting/host/video_scheduler_unittest.cc b/remoting/host/video_scheduler_unittest.cc index 7ef6439..8335c5c 100644 --- a/remoting/host/video_scheduler_unittest.cc +++ b/remoting/host/video_scheduler_unittest.cc @@ -52,9 +52,6 @@ ACTION_P2(StopVideoScheduler, scheduler, task) { static const int kWidth = 640; static const int kHeight = 480; -static const media::VideoFrame::Format kFormat = media::VideoFrame::RGB32; -static const VideoPacketFormat::Encoding kEncoding = - VideoPacketFormat::ENCODING_VERBATIM; class MockVideoEncoder : public VideoEncoder { public: @@ -126,16 +123,10 @@ void VideoSchedulerTest::GenerateOnCaptureCompleted() { // VideoScheduler is instructed to come to a complete stop. We expect the stop // sequence to be executed successfully. TEST_F(VideoSchedulerTest, StartAndStop) { - DataPlanes planes; - for (int i = 0; i < DataPlanes::kPlaneCount; ++i) { - planes.data[i] = reinterpret_cast<uint8*>(i); - planes.strides[i] = kWidth * 4; - } - Expectation capturer_start = EXPECT_CALL(capturer_, Start(_)); size_.set(kWidth, kHeight); - data_ = new CaptureData(planes, size_, kFormat); + data_ = new CaptureData(NULL, kWidth * CaptureData::kBytesPerPixel, size_); // Create a RunLoop through which to drive |message_loop_|. base::RunLoop run_loop; |