Index: media/video/capture/screen/screen_capturer_linux.cc |
diff --git a/remoting/capturer/video_frame_capturer_linux.cc b/media/video/capture/screen/screen_capturer_linux.cc |
similarity index 79% |
rename from remoting/capturer/video_frame_capturer_linux.cc |
rename to media/video/capture/screen/screen_capturer_linux.cc |
index edfa1a436a8ccc143fe1dda9a079b7723326a960..774d62ef939aeac24c9d417dbe9287c9fa269b1a 100644 |
--- a/remoting/capturer/video_frame_capturer_linux.cc |
+++ b/media/video/capture/screen/screen_capturer_linux.cc |
@@ -2,7 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "remoting/capturer/video_frame_capturer.h" |
+#include "media/video/capture/screen/screen_capturer.h" |
#include <X11/Xlib.h> |
#include <X11/Xutil.h> |
@@ -16,15 +16,15 @@ |
#include "base/memory/scoped_ptr.h" |
#include "base/stl_util.h" |
#include "base/time.h" |
-#include "remoting/capturer/capture_data.h" |
-#include "remoting/capturer/differ.h" |
-#include "remoting/capturer/linux/x_server_pixel_buffer.h" |
-#include "remoting/capturer/mouse_cursor_shape.h" |
-#include "remoting/capturer/video_frame.h" |
-#include "remoting/capturer/video_frame_capturer_helper.h" |
-#include "remoting/capturer/video_frame_queue.h" |
+#include "media/video/capture/screen/differ.h" |
+#include "media/video/capture/screen/linux/x_server_pixel_buffer.h" |
+#include "media/video/capture/screen/mouse_cursor_shape.h" |
+#include "media/video/capture/screen/screen_capture_data.h" |
+#include "media/video/capture/screen/screen_capture_frame.h" |
+#include "media/video/capture/screen/screen_capture_frame_queue.h" |
+#include "media/video/capture/screen/screen_capturer_helper.h" |
-namespace remoting { |
+namespace media { |
namespace { |
@@ -37,23 +37,23 @@ static bool ShouldUseXDamage() { |
} |
// A class representing a full-frame pixel buffer. |
-class VideoFrameLinux : public VideoFrame { |
+class ScreenCaptureFrameLinux : public ScreenCaptureFrame { |
public: |
- explicit VideoFrameLinux(const SkISize& window_size); |
- virtual ~VideoFrameLinux(); |
+ explicit ScreenCaptureFrameLinux(const SkISize& window_size); |
+ virtual ~ScreenCaptureFrameLinux(); |
private: |
// Allocated pixel buffer. |
scoped_array<uint8> data_; |
- DISALLOW_COPY_AND_ASSIGN(VideoFrameLinux); |
+ DISALLOW_COPY_AND_ASSIGN(ScreenCaptureFrameLinux); |
}; |
// A class to perform video frame capturing for Linux. |
-class VideoFrameCapturerLinux : public VideoFrameCapturer { |
+class ScreenCapturerLinux : public ScreenCapturer { |
public: |
- VideoFrameCapturerLinux(); |
- virtual ~VideoFrameCapturerLinux(); |
+ ScreenCapturerLinux(); |
+ virtual ~ScreenCapturerLinux(); |
bool Init(); // TODO(ajwong): Do we really want this to be synchronous? |
@@ -68,7 +68,7 @@ class VideoFrameCapturerLinux : public VideoFrameCapturer { |
// Read and handle all currently-pending XEvents. |
// In the DAMAGE case, process the XDamage events and store the resulting |
- // damage rectangles in the VideoFrameCapturerHelper. |
+ // damage rectangles in the ScreenCapturerHelper. |
// In all cases, call ScreenConfigurationChanged() in response to any |
// ConfigNotify events. |
void ProcessPendingXEvents(); |
@@ -76,14 +76,13 @@ class VideoFrameCapturerLinux : public VideoFrameCapturer { |
// Capture the cursor image and notify the delegate if it was captured. |
void CaptureCursor(); |
- // Capture screen pixels, and return the data in a new CaptureData object, |
- // to be freed by the caller. |
- // In the DAMAGE case, the VideoFrameCapturerHelper already holds the list of |
- // invalid rectangles from ProcessPendingXEvents(). |
- // In the non-DAMAGE case, this captures the whole screen, then calculates |
- // some invalid rectangles that include any differences between this and the |
- // previous capture. |
- scoped_refptr<CaptureData> CaptureScreen(); |
+ // Capture screen pixels, and return the data in a new ScreenCaptureData |
+ // object, to be freed by the caller. In the DAMAGE case, the |
+ // ScreenCapturerHelper already holds the list of invalid rectangles from |
+ // ProcessPendingXEvents(). In the non-DAMAGE case, this captures the whole |
+ // screen, then calculates some invalid rectangles that include any |
+ // differences between this and the previous capture. |
+ scoped_refptr<ScreenCaptureData> CaptureScreen(); |
// Called when the screen configuration is changed. |root_window_size| |
// specifies the most recent size of the root window. |
@@ -100,12 +99,16 @@ class VideoFrameCapturerLinux : public VideoFrameCapturer { |
// Capture a rectangle from |x_server_pixel_buffer_|, and copy the data into |
// |capture_data|. |
- void CaptureRect(const SkIRect& rect, CaptureData* capture_data); |
+ void CaptureRect(const SkIRect& rect, ScreenCaptureData* capture_data); |
// We expose two forms of blitting to handle variations in the pixel format. |
// In FastBlit, the operation is effectively a memcpy. |
- void FastBlit(uint8* image, const SkIRect& rect, CaptureData* capture_data); |
- void SlowBlit(uint8* image, const SkIRect& rect, CaptureData* capture_data); |
+ void FastBlit(uint8* image, |
+ const SkIRect& rect, |
+ ScreenCaptureData* capture_data); |
+ void SlowBlit(uint8* image, |
+ const SkIRect& rect, |
+ ScreenCaptureData* capture_data); |
Delegate* delegate_; |
@@ -134,10 +137,10 @@ class VideoFrameCapturerLinux : public VideoFrameCapturer { |
// A thread-safe list of invalid rectangles, and the size of the most |
// recently captured screen. |
- VideoFrameCapturerHelper helper_; |
+ ScreenCapturerHelper helper_; |
// Queue of the frames buffers. |
- VideoFrameQueue queue_; |
+ ScreenCaptureFrameQueue queue_; |
// Invalid region from the previous capture. This is used to synchronize the |
// current with the last buffer used. |
@@ -146,11 +149,11 @@ class VideoFrameCapturerLinux : public VideoFrameCapturer { |
// |Differ| for use when polling for changes. |
scoped_ptr<Differ> differ_; |
- DISALLOW_COPY_AND_ASSIGN(VideoFrameCapturerLinux); |
+ DISALLOW_COPY_AND_ASSIGN(ScreenCapturerLinux); |
}; |
-VideoFrameLinux::VideoFrameLinux(const SkISize& window_size) { |
- set_bytes_per_row(window_size.width() * CaptureData::kBytesPerPixel); |
+ScreenCaptureFrameLinux::ScreenCaptureFrameLinux(const SkISize& window_size) { |
+ set_bytes_per_row(window_size.width() * ScreenCaptureData::kBytesPerPixel); |
set_dimensions(window_size); |
size_t buffer_size = bytes_per_row() * window_size.height(); |
@@ -158,10 +161,10 @@ VideoFrameLinux::VideoFrameLinux(const SkISize& window_size) { |
set_pixels(data_.get()); |
} |
-VideoFrameLinux::~VideoFrameLinux() { |
+ScreenCaptureFrameLinux::~ScreenCaptureFrameLinux() { |
} |
-VideoFrameCapturerLinux::VideoFrameCapturerLinux() |
+ScreenCapturerLinux::ScreenCapturerLinux() |
: delegate_(NULL), |
display_(NULL), |
gc_(NULL), |
@@ -178,11 +181,11 @@ VideoFrameCapturerLinux::VideoFrameCapturerLinux() |
helper_.SetLogGridSize(4); |
} |
-VideoFrameCapturerLinux::~VideoFrameCapturerLinux() { |
+ScreenCapturerLinux::~ScreenCapturerLinux() { |
DeinitXlib(); |
} |
-bool VideoFrameCapturerLinux::Init() { |
+bool ScreenCapturerLinux::Init() { |
// TODO(ajwong): We should specify the display string we are attaching to |
// in the constructor. |
display_ = XOpenDisplay(NULL); |
@@ -233,7 +236,7 @@ bool VideoFrameCapturerLinux::Init() { |
return true; |
} |
-void VideoFrameCapturerLinux::InitXDamage() { |
+void ScreenCapturerLinux::InitXDamage() { |
// Our use of XDamage requires XFixes. |
if (!has_xfixes_) { |
return; |
@@ -271,20 +274,20 @@ void VideoFrameCapturerLinux::InitXDamage() { |
LOG(INFO) << "Using XDamage extension."; |
} |
-void VideoFrameCapturerLinux::Start(Delegate* delegate) { |
+void ScreenCapturerLinux::Start(Delegate* delegate) { |
DCHECK(delegate_ == NULL); |
delegate_ = delegate; |
} |
-void VideoFrameCapturerLinux::Stop() { |
+void ScreenCapturerLinux::Stop() { |
} |
-void VideoFrameCapturerLinux::InvalidateRegion(const SkRegion& invalid_region) { |
+void ScreenCapturerLinux::InvalidateRegion(const SkRegion& invalid_region) { |
helper_.InvalidateRegion(invalid_region); |
} |
-void VideoFrameCapturerLinux::CaptureFrame() { |
+void ScreenCapturerLinux::CaptureFrame() { |
base::Time capture_start_time = base::Time::Now(); |
// Process XEvents for XDamage and cursor shape tracking. |
@@ -294,13 +297,13 @@ void VideoFrameCapturerLinux::CaptureFrame() { |
// Note that we can't reallocate other buffers at this point, since the caller |
// may still be reading from them. |
if (queue_.current_frame_needs_update()) { |
- scoped_ptr<VideoFrameLinux> buffer(new VideoFrameLinux( |
+ scoped_ptr<ScreenCaptureFrameLinux> buffer(new ScreenCaptureFrameLinux( |
root_window_size_)); |
- queue_.ReplaceCurrentFrame(buffer.PassAs<VideoFrame>()); |
+ queue_.ReplaceCurrentFrame(buffer.PassAs<ScreenCaptureFrame>()); |
} |
// Refresh the Differ helper used by CaptureFrame(), if needed. |
- const VideoFrame* current_buffer = queue_.current_frame(); |
+ const ScreenCaptureFrame* current_buffer = queue_.current_frame(); |
if (!use_damage_ && ( |
!differ_.get() || |
(differ_->width() != current_buffer->dimensions().width()) || |
@@ -308,11 +311,11 @@ void VideoFrameCapturerLinux::CaptureFrame() { |
(differ_->bytes_per_row() != current_buffer->bytes_per_row()))) { |
differ_.reset(new Differ(current_buffer->dimensions().width(), |
current_buffer->dimensions().height(), |
- CaptureData::kBytesPerPixel, |
+ ScreenCaptureData::kBytesPerPixel, |
current_buffer->bytes_per_row())); |
} |
- scoped_refptr<CaptureData> capture_data(CaptureScreen()); |
+ scoped_refptr<ScreenCaptureData> capture_data(CaptureScreen()); |
// Swap the current & previous buffers ready for the next capture. |
last_invalid_region_ = capture_data->dirty_region(); |
@@ -324,7 +327,7 @@ void VideoFrameCapturerLinux::CaptureFrame() { |
delegate_->OnCaptureCompleted(capture_data); |
} |
-void VideoFrameCapturerLinux::ProcessPendingXEvents() { |
+void ScreenCapturerLinux::ProcessPendingXEvents() { |
// Find the number of events that are outstanding "now." We don't just loop |
// on XPending because we want to guarantee this terminates. |
int events_to_process = XPending(display_); |
@@ -351,7 +354,7 @@ void VideoFrameCapturerLinux::ProcessPendingXEvents() { |
} |
} |
-void VideoFrameCapturerLinux::CaptureCursor() { |
+void ScreenCapturerLinux::CaptureCursor() { |
DCHECK(has_xfixes_); |
XFixesCursorImage* img = XFixesGetCursorImage(display_); |
@@ -364,7 +367,7 @@ void VideoFrameCapturerLinux::CaptureCursor() { |
cursor->hotspot.set(img->xhot, img->yhot); |
int total_bytes = cursor->size.width() * cursor->size.height() * |
- CaptureData::kBytesPerPixel; |
+ ScreenCaptureData::kBytesPerPixel; |
cursor->data.resize(total_bytes); |
// Xlib stores 32-bit data in longs, even if longs are 64-bits long. |
@@ -379,9 +382,9 @@ void VideoFrameCapturerLinux::CaptureCursor() { |
delegate_->OnCursorShapeChanged(cursor.Pass()); |
} |
-scoped_refptr<CaptureData> VideoFrameCapturerLinux::CaptureScreen() { |
- VideoFrame* frame = queue_.current_frame(); |
- scoped_refptr<CaptureData> capture_data(new CaptureData( |
+scoped_refptr<ScreenCaptureData> ScreenCapturerLinux::CaptureScreen() { |
+ ScreenCaptureFrame* frame = queue_.current_frame(); |
+ scoped_refptr<ScreenCaptureData> capture_data(new ScreenCaptureData( |
frame->pixels(), frame->bytes_per_row(), frame->dimensions())); |
// Pass the screen size to the helper, so it can clip the invalid region if it |
@@ -450,7 +453,7 @@ scoped_refptr<CaptureData> VideoFrameCapturerLinux::CaptureScreen() { |
return capture_data; |
} |
-void VideoFrameCapturerLinux::ScreenConfigurationChanged( |
+void ScreenCapturerLinux::ScreenConfigurationChanged( |
const SkISize& root_window_size) { |
root_window_size_ = root_window_size; |
@@ -461,7 +464,7 @@ void VideoFrameCapturerLinux::ScreenConfigurationChanged( |
x_server_pixel_buffer_.Init(display_, root_window_size_); |
} |
-void VideoFrameCapturerLinux::SynchronizeFrame() { |
+void ScreenCapturerLinux::SynchronizeFrame() { |
// Synchronize the current buffer with the previous one since we do not |
// capture the entire desktop. Note that encoder may be reading from the |
// previous buffer at this time so thread access complaints are false |
@@ -472,22 +475,23 @@ void VideoFrameCapturerLinux::SynchronizeFrame() { |
// http://crbug.com/92354 |
DCHECK(queue_.previous_frame()); |
- VideoFrame* current = queue_.current_frame(); |
- VideoFrame* last = queue_.previous_frame(); |
+ ScreenCaptureFrame* current = queue_.current_frame(); |
+ ScreenCaptureFrame* last = queue_.previous_frame(); |
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 * CaptureData::kBytesPerPixel; |
+ r.fLeft * ScreenCaptureData::kBytesPerPixel; |
for (int i = 0; i < r.height(); ++i) { |
memcpy(current->pixels() + offset, last->pixels() + offset, |
- r.width() * CaptureData::kBytesPerPixel); |
- offset += current->dimensions().width() * CaptureData::kBytesPerPixel; |
+ r.width() * ScreenCaptureData::kBytesPerPixel); |
+ offset += current->dimensions().width() * |
+ ScreenCaptureData::kBytesPerPixel; |
} |
} |
} |
-void VideoFrameCapturerLinux::DeinitXlib() { |
+void ScreenCapturerLinux::DeinitXlib() { |
if (gc_) { |
XFreeGC(display_, gc_); |
gc_ = NULL; |
@@ -507,8 +511,8 @@ void VideoFrameCapturerLinux::DeinitXlib() { |
} |
} |
-void VideoFrameCapturerLinux::CaptureRect(const SkIRect& rect, |
- CaptureData* capture_data) { |
+void ScreenCapturerLinux::CaptureRect(const SkIRect& rect, |
+ ScreenCaptureData* capture_data) { |
uint8* image = x_server_pixel_buffer_.CaptureRect(rect); |
int depth = x_server_pixel_buffer_.GetDepth(); |
int bpp = x_server_pixel_buffer_.GetBitsPerPixel(); |
@@ -522,17 +526,17 @@ void VideoFrameCapturerLinux::CaptureRect(const SkIRect& rect, |
} |
} |
-void VideoFrameCapturerLinux::FastBlit(uint8* image, const SkIRect& rect, |
- CaptureData* capture_data) { |
+void ScreenCapturerLinux::FastBlit(uint8* image, const SkIRect& rect, |
+ ScreenCaptureData* capture_data) { |
uint8* src_pos = image; |
int src_stride = x_server_pixel_buffer_.GetStride(); |
int dst_x = rect.fLeft, dst_y = rect.fTop; |
uint8* dst_pos = capture_data->data() + capture_data->stride() * dst_y; |
- dst_pos += dst_x * CaptureData::kBytesPerPixel; |
+ dst_pos += dst_x * ScreenCaptureData::kBytesPerPixel; |
int height = rect.height(); |
- int row_bytes = rect.width() * CaptureData::kBytesPerPixel; |
+ int row_bytes = rect.width() * ScreenCaptureData::kBytesPerPixel; |
for (int y = 0; y < height; ++y) { |
memcpy(dst_pos, src_pos, row_bytes); |
src_pos += src_stride; |
@@ -540,8 +544,8 @@ void VideoFrameCapturerLinux::FastBlit(uint8* image, const SkIRect& rect, |
} |
} |
-void VideoFrameCapturerLinux::SlowBlit(uint8* image, const SkIRect& rect, |
- CaptureData* capture_data) { |
+void ScreenCapturerLinux::SlowBlit(uint8* image, const SkIRect& rect, |
+ ScreenCaptureData* capture_data) { |
int src_stride = x_server_pixel_buffer_.GetStride(); |
int dst_x = rect.fLeft, dst_y = rect.fTop; |
int width = rect.width(), height = rect.height(); |
@@ -561,7 +565,7 @@ void VideoFrameCapturerLinux::SlowBlit(uint8* image, const SkIRect& rect, |
uint8* dst_pos = capture_data->data() + capture_data->stride() * dst_y; |
uint8* src_pos = image; |
- dst_pos += dst_x * CaptureData::kBytesPerPixel; |
+ dst_pos += dst_x * ScreenCaptureData::kBytesPerPixel; |
// TODO(hclam): Optimize, perhaps using MMX code or by converting to |
// YUV directly |
for (int y = 0; y < height; y++) { |
@@ -591,23 +595,23 @@ void VideoFrameCapturerLinux::SlowBlit(uint8* image, const SkIRect& rect, |
} // namespace |
// static |
-scoped_ptr<VideoFrameCapturer> VideoFrameCapturer::Create() { |
- scoped_ptr<VideoFrameCapturerLinux> capturer(new VideoFrameCapturerLinux()); |
+scoped_ptr<ScreenCapturer> ScreenCapturer::Create() { |
+ scoped_ptr<ScreenCapturerLinux> capturer(new ScreenCapturerLinux()); |
if (!capturer->Init()) |
capturer.reset(); |
- return capturer.PassAs<VideoFrameCapturer>(); |
+ return capturer.PassAs<ScreenCapturer>(); |
} |
// static |
-scoped_ptr<VideoFrameCapturer> VideoFrameCapturer::CreateWithFactory( |
+scoped_ptr<ScreenCapturer> ScreenCapturer::CreateWithFactory( |
SharedBufferFactory* shared_buffer_factory) { |
NOTIMPLEMENTED(); |
- return scoped_ptr<VideoFrameCapturer>(); |
+ return scoped_ptr<ScreenCapturer>(); |
} |
// static |
-void VideoFrameCapturer::EnableXDamage(bool enable) { |
+void ScreenCapturer::EnableXDamage(bool enable) { |
g_should_use_x_damage = enable; |
} |
-} // namespace remoting |
+} // namespace media |