OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "remoting/ios/bridge/frame_consumer_bridge.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/logging.h" | |
9 #include "base/synchronization/waitable_event.h" | |
10 #include "remoting/base/util.h" | |
11 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | |
12 | |
13 namespace remoting { | |
14 | |
15 FrameConsumerBridge::FrameConsumerBridge(FrameConsumerBridgeCallback callback) | |
16 : callback_(callback), frame_producer_(NULL) {} | |
17 | |
18 void FrameConsumerBridge::Initialize(FrameProducer* producer) { | |
19 frame_producer_ = producer; | |
20 } | |
21 | |
22 void FrameConsumerBridge::ApplyBuffer(const webrtc::DesktopSize& view_size, | |
23 const webrtc::DesktopRect& clip_area, | |
24 webrtc::DesktopFrame* buffer, | |
25 const webrtc::DesktopRegion& region, | |
26 const webrtc::DesktopRegion& shape) { | |
27 | |
28 if (!view_size_.equals(view_size)) { | |
29 // Drop the frame, since the data belongs to the previous generation, | |
30 // before SetSourceSize() called SetOutputSizeAndClip(). | |
31 FreeBuffer(buffer); | |
32 return; | |
33 } | |
34 | |
35 callback_.Run(view_size, buffer, region); | |
36 | |
37 // Recycle |buffer| by returning the |frame_producer_| as the next buffer | |
38 if (frame_producer_) { | |
dcaiafa
2014/03/19 01:14:15
Is it valid for frame_producer_ to be NULL? If not
aboone
2014/03/21 16:42:07
It can be NULL between a call to the constructor a
| |
39 frame_producer_->DrawBuffer(buffer); | |
dcaiafa
2014/03/19 01:14:15
I don't think you can reuse the buffer here. In th
aboone
2014/03/21 16:42:07
The callback is not a task post, its just an indir
| |
40 } | |
41 } | |
42 | |
43 void FrameConsumerBridge::ReturnBuffer(webrtc::DesktopFrame* buffer) { | |
44 FreeBuffer(buffer); | |
45 } | |
46 | |
47 void FrameConsumerBridge::SetSourceSize(const webrtc::DesktopSize& source_size, | |
48 const webrtc::DesktopVector& dpi) { | |
49 view_size_ = source_size; | |
50 webrtc::DesktopRect clip_area = webrtc::DesktopRect::MakeSize(view_size_); | |
51 if (frame_producer_) { | |
52 frame_producer_->SetOutputSizeAndClip(view_size_, clip_area); | |
53 } | |
54 | |
55 // Allocate buffer and start drawing frames onto it. | |
56 AllocateBuffer(); | |
dcaiafa
2014/03/19 01:14:15
The name of the method is confusing. It's main pur
aboone
2014/03/21 16:42:07
Renamed to DrawWithNewBuffer
| |
57 } | |
58 | |
59 FrameConsumerBridge::PixelFormat FrameConsumerBridge::GetPixelFormat() { | |
60 return FORMAT_RGBA; | |
61 } | |
62 | |
63 void FrameConsumerBridge::AllocateBuffer() { | |
64 webrtc::DesktopFrame* buffer = new webrtc::BasicDesktopFrame(view_size_); | |
65 buffers_.push_back(buffer); | |
66 if (frame_producer_) { | |
67 frame_producer_->DrawBuffer(buffer); | |
68 } | |
69 } | |
70 | |
71 void FrameConsumerBridge::FreeBuffer(webrtc::DesktopFrame* buffer) { | |
72 ScopedVector<webrtc::DesktopFrame>::iterator it = | |
73 std::find(buffers_.begin(), buffers_.end(), buffer); | |
74 | |
75 if (it != buffers_.end()) { | |
76 buffers_.erase(it); | |
77 } | |
78 } | |
79 | |
80 } // namespace remoting | |
OLD | NEW |