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

Unified Diff: media/video/capture/screen/screen_capture_frame_queue.cc

Issue 13983010: Use webrtc::DesktopCapturer for screen capturer implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: q Created 7 years, 8 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
Index: media/video/capture/screen/screen_capture_frame_queue.cc
diff --git a/media/video/capture/screen/screen_capture_frame_queue.cc b/media/video/capture/screen/screen_capture_frame_queue.cc
index 610a0628cfb753bf618d1779d003609c1ca2a79c..3027c29e035da66f294c8d77b4e6accd4feceef8 100644
--- a/media/video/capture/screen/screen_capture_frame_queue.cc
+++ b/media/video/capture/screen/screen_capture_frame_queue.cc
@@ -7,28 +7,81 @@
#include <algorithm>
#include "base/basictypes.h"
-#include "media/video/capture/screen/screen_capture_frame.h"
+#include "base/logging.h"
+#include "base/threading/non_thread_safe.h"
+#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
namespace media {
+class ScreenCaptureFrameQueue::EmittedFrame
alexeypa (please no reviews) 2013/04/26 21:33:58 Describe briefly what this class is for.
Sergey Ulanov 2013/05/07 22:25:50 Done.
+ : public webrtc::DesktopFrame,
alexeypa (please no reviews) 2013/04/26 21:33:58 It does not look EmittedFrame is ever used as webr
Sergey Ulanov 2013/05/07 22:25:50 Actually EmitCurrentFrameAndMoveToNext() returns i
+ public base::NonThreadSafe {
+ public:
+ EmittedFrame(webrtc::DesktopFrame* frame, ScreenCaptureFrameQueue* queue)
+ : DesktopFrame(frame->size(), frame->stride(), frame->data(),
+ frame->shared_memory()),
+ frame_(frame),
+ queue_(queue) {
+ set_dpi(frame->dpi());
+ set_capture_time_ms(frame->capture_time_ms());
+ updated_region_ = frame->updated_region();
+ }
+
+ virtual ~EmittedFrame() {
+ if (queue_)
+ queue_->ReturnEmittedFrame(frame_.release());
+ }
+
+ void DetachFromQueue() {
+ queue_ = NULL;
+ }
+
+ private:
+ scoped_ptr<webrtc::DesktopFrame> frame_;
+ ScreenCaptureFrameQueue* queue_;
+};
+
ScreenCaptureFrameQueue::ScreenCaptureFrameQueue()
: current_(0),
previous_(NULL) {
+ memset(frames_, 0, sizeof(frames_));
+ memset(emitted_frames_, 0, sizeof(emitted_frames_));
SetAllFramesNeedUpdate();
}
ScreenCaptureFrameQueue::~ScreenCaptureFrameQueue() {
+ for (int i = 0; i < kQueueLength; ++i) {
+ if (emitted_frames_[i]) {
+ emitted_frames_[i]->DetachFromQueue();
+ } else {
+ delete frames_[i];
+ }
+ }
}
-void ScreenCaptureFrameQueue::DoneWithCurrentFrame() {
+webrtc::DesktopFrame* ScreenCaptureFrameQueue::EmitCurrentFrameAndMoveToNext() {
+ DCHECK(!emitted_frames_[current_]);
+
+ EmittedFrame* result = new EmittedFrame(frames_[current_], this);
Wez 2013/04/26 18:48:14 Add some comments to explain what this logic is tr
alexeypa (please no reviews) 2013/04/26 21:33:58 This code is very confusing. I stared at it for a
Sergey Ulanov 2013/05/07 22:25:50 What wouldn't work without downcasting frames to E
Sergey Ulanov 2013/05/07 22:25:50 I've split this method into two separate methods.
+ emitted_frames_[current_] = result;
previous_ = current_frame();
current_ = (current_ + 1) % kQueueLength;
+ if (emitted_frames_[current_]) {
Wez 2013/04/26 18:48:14 Wouldn't it be more correct to leave the frame in-
Sergey Ulanov 2013/05/07 22:25:50 The DesktopCapturer interface doesn't specify when
+ emitted_frames_[current_]->DetachFromQueue();
alexeypa (please no reviews) 2013/04/26 21:33:58 If I read this right this will always delete the f
Sergey Ulanov 2013/05/07 22:25:50 See my comment above, we normally should never rea
+ emitted_frames_[current_] = NULL;
+ frames_[current_] = NULL;
+ }
+ return result;
}
void ScreenCaptureFrameQueue::ReplaceCurrentFrame(
- scoped_ptr<ScreenCaptureFrame> frame) {
- frames_[current_] = frame.Pass();
+ scoped_ptr<webrtc::DesktopFrame> frame) {
+ frames_[current_] = frame.release();
needs_update_[current_] = false;
+ if (emitted_frames_[current_]) {
+ emitted_frames_[current_]->DetachFromQueue();
Wez 2013/04/26 18:48:14 For this to happen the caller would have to have c
Sergey Ulanov 2013/05/07 22:25:50 Yes, but that's not documented for DesktopCapturer
+ emitted_frames_[current_] = NULL;
+ }
}
void ScreenCaptureFrameQueue::SetAllFramesNeedUpdate() {
@@ -36,4 +89,17 @@ void ScreenCaptureFrameQueue::SetAllFramesNeedUpdate() {
previous_ = NULL;
}
+void ScreenCaptureFrameQueue::ReturnEmittedFrame(
+ webrtc::DesktopFrame* frame) {
+ if (frame == frames_[0]) {
+ emitted_frames_[0] = NULL;
alexeypa (please no reviews) 2013/04/26 21:33:58 This does not work if kQueueLength is not 2.
Sergey Ulanov 2013/05/07 22:25:50 Done.
+ } else if (frame == frames_[1]) {
+ emitted_frames_[1] = NULL;
+ } else {
+ if (previous_ == frame)
+ previous_ = NULL;
Wez 2013/04/26 18:48:14 nit: If previous_ were an index into frames_ rathe
Sergey Ulanov 2013/05/07 22:25:50 Done.
+ delete frame;
+ }
+}
+
} // namespace media

Powered by Google App Engine
This is Rietveld 408576698