OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/video/capture/screen/screen_capture_frame_queue.h" | 5 #include "media/video/capture/screen/screen_capture_frame_queue.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "media/video/capture/screen/screen_capture_frame.h" | 10 #include "base/logging.h" |
11 #include "base/threading/non_thread_safe.h" | |
12 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | |
11 | 13 |
12 namespace media { | 14 namespace media { |
13 | 15 |
16 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.
| |
17 : 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
| |
18 public base::NonThreadSafe { | |
19 public: | |
20 EmittedFrame(webrtc::DesktopFrame* frame, ScreenCaptureFrameQueue* queue) | |
21 : DesktopFrame(frame->size(), frame->stride(), frame->data(), | |
22 frame->shared_memory()), | |
23 frame_(frame), | |
24 queue_(queue) { | |
25 set_dpi(frame->dpi()); | |
26 set_capture_time_ms(frame->capture_time_ms()); | |
27 updated_region_ = frame->updated_region(); | |
28 } | |
29 | |
30 virtual ~EmittedFrame() { | |
31 if (queue_) | |
32 queue_->ReturnEmittedFrame(frame_.release()); | |
33 } | |
34 | |
35 void DetachFromQueue() { | |
36 queue_ = NULL; | |
37 } | |
38 | |
39 private: | |
40 scoped_ptr<webrtc::DesktopFrame> frame_; | |
41 ScreenCaptureFrameQueue* queue_; | |
42 }; | |
43 | |
14 ScreenCaptureFrameQueue::ScreenCaptureFrameQueue() | 44 ScreenCaptureFrameQueue::ScreenCaptureFrameQueue() |
15 : current_(0), | 45 : current_(0), |
16 previous_(NULL) { | 46 previous_(NULL) { |
47 memset(frames_, 0, sizeof(frames_)); | |
48 memset(emitted_frames_, 0, sizeof(emitted_frames_)); | |
17 SetAllFramesNeedUpdate(); | 49 SetAllFramesNeedUpdate(); |
18 } | 50 } |
19 | 51 |
20 ScreenCaptureFrameQueue::~ScreenCaptureFrameQueue() { | 52 ScreenCaptureFrameQueue::~ScreenCaptureFrameQueue() { |
53 for (int i = 0; i < kQueueLength; ++i) { | |
54 if (emitted_frames_[i]) { | |
55 emitted_frames_[i]->DetachFromQueue(); | |
56 } else { | |
57 delete frames_[i]; | |
58 } | |
59 } | |
21 } | 60 } |
22 | 61 |
23 void ScreenCaptureFrameQueue::DoneWithCurrentFrame() { | 62 webrtc::DesktopFrame* ScreenCaptureFrameQueue::EmitCurrentFrameAndMoveToNext() { |
63 DCHECK(!emitted_frames_[current_]); | |
64 | |
65 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.
| |
66 emitted_frames_[current_] = result; | |
24 previous_ = current_frame(); | 67 previous_ = current_frame(); |
25 current_ = (current_ + 1) % kQueueLength; | 68 current_ = (current_ + 1) % kQueueLength; |
69 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
| |
70 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
| |
71 emitted_frames_[current_] = NULL; | |
72 frames_[current_] = NULL; | |
73 } | |
74 return result; | |
26 } | 75 } |
27 | 76 |
28 void ScreenCaptureFrameQueue::ReplaceCurrentFrame( | 77 void ScreenCaptureFrameQueue::ReplaceCurrentFrame( |
29 scoped_ptr<ScreenCaptureFrame> frame) { | 78 scoped_ptr<webrtc::DesktopFrame> frame) { |
30 frames_[current_] = frame.Pass(); | 79 frames_[current_] = frame.release(); |
31 needs_update_[current_] = false; | 80 needs_update_[current_] = false; |
81 if (emitted_frames_[current_]) { | |
82 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
| |
83 emitted_frames_[current_] = NULL; | |
84 } | |
32 } | 85 } |
33 | 86 |
34 void ScreenCaptureFrameQueue::SetAllFramesNeedUpdate() { | 87 void ScreenCaptureFrameQueue::SetAllFramesNeedUpdate() { |
35 std::fill(needs_update_, needs_update_ + arraysize(needs_update_), true); | 88 std::fill(needs_update_, needs_update_ + arraysize(needs_update_), true); |
36 previous_ = NULL; | 89 previous_ = NULL; |
37 } | 90 } |
38 | 91 |
92 void ScreenCaptureFrameQueue::ReturnEmittedFrame( | |
93 webrtc::DesktopFrame* frame) { | |
94 if (frame == frames_[0]) { | |
95 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.
| |
96 } else if (frame == frames_[1]) { | |
97 emitted_frames_[1] = NULL; | |
98 } else { | |
99 if (previous_ == frame) | |
100 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.
| |
101 delete frame; | |
102 } | |
103 } | |
104 | |
39 } // namespace media | 105 } // namespace media |
OLD | NEW |