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

Side by Side Diff: remoting/client/jni/jni_frame_consumer.cc

Issue 24072012: Hold video frame in Bitmap instead of keeping a ByteBuffer reference. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "remoting/client/jni/jni_frame_consumer.h" 5 #include "remoting/client/jni/jni_frame_consumer.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/synchronization/waitable_event.h" 9 #include "base/synchronization/waitable_event.h"
10 #include "remoting/client/frame_producer.h" 10 #include "remoting/client/frame_producer.h"
11 #include "remoting/client/jni/chromoting_jni_runtime.h" 11 #include "remoting/client/jni/chromoting_jni_runtime.h"
12 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" 12 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
13 13
14 namespace {
15
16 // Allocates its buffer within a Java direct byte buffer, where it can be
17 // accessed by both native and managed code.
18 class DirectDesktopFrame : public webrtc::BasicDesktopFrame {
19 public:
20 DirectDesktopFrame(int width, int height);
21
22 virtual ~DirectDesktopFrame();
23
24 jobject buffer() const {
25 return buffer_;
26 }
27
28 private:
29 jobject buffer_;
30 };
31
32 DirectDesktopFrame::DirectDesktopFrame(int width, int height)
33 : webrtc::BasicDesktopFrame(webrtc::DesktopSize(width, height)) {
34 JNIEnv* env = base::android::AttachCurrentThread();
35 buffer_ = env->NewDirectByteBuffer(data(), stride()*height);
36 }
37
38 DirectDesktopFrame::~DirectDesktopFrame() {}
39
40 } // namespace
41
42 namespace remoting { 14 namespace remoting {
43 15
44 JniFrameConsumer::JniFrameConsumer(ChromotingJniRuntime* jni_runtime) 16 JniFrameConsumer::JniFrameConsumer(ChromotingJniRuntime* jni_runtime)
45 : jni_runtime_(jni_runtime), 17 : jni_runtime_(jni_runtime),
46 in_dtor_(false), 18 in_dtor_(false),
47 frame_producer_(NULL) { 19 frame_producer_(NULL) {
48 } 20 }
49 21
50 JniFrameConsumer::~JniFrameConsumer() { 22 JniFrameConsumer::~JniFrameConsumer() {
51 // Stop giving the producer a buffer to work with. 23 // Stop giving the producer a buffer to work with.
(...skipping 10 matching lines...) Expand all
62 frame_producer_ = producer; 34 frame_producer_ = producer;
63 } 35 }
64 36
65 void JniFrameConsumer::ApplyBuffer(const SkISize& view_size, 37 void JniFrameConsumer::ApplyBuffer(const SkISize& view_size,
66 const SkIRect& clip_area, 38 const SkIRect& clip_area,
67 webrtc::DesktopFrame* buffer, 39 webrtc::DesktopFrame* buffer,
68 const SkRegion& region) { 40 const SkRegion& region) {
69 DCHECK(jni_runtime_->display_task_runner()->BelongsToCurrentThread()); 41 DCHECK(jni_runtime_->display_task_runner()->BelongsToCurrentThread());
70 42
71 scoped_ptr<webrtc::DesktopFrame> buffer_scoped(buffer); 43 scoped_ptr<webrtc::DesktopFrame> buffer_scoped(buffer);
72 jni_runtime_->RedrawCanvas(); 44
45 jni_runtime_->UpdateImageBuffer(view_size.width(), view_size.height(),
46 buffer->data());
73 47
74 if (view_size.width() > view_size_.width() || 48 if (view_size.width() > view_size_.width() ||
75 view_size.height() > view_size_.height()) { 49 view_size.height() > view_size_.height()) {
76 LOG(INFO) << "Existing buffer is too small"; 50 LOG(INFO) << "Existing buffer is too small";
77 view_size_ = view_size; 51 view_size_ = view_size;
78 52
79 // Manually destroy the old buffer before allocating a new one to prevent 53 // Manually destroy the old buffer before allocating a new one to prevent
80 // our memory footprint from temporarily ballooning. 54 // our memory footprint from temporarily ballooning.
81 buffer_scoped.reset(); 55 buffer_scoped.reset();
82 AllocateBuffer(); 56 AllocateBuffer();
(...skipping 28 matching lines...) Expand all
111 void JniFrameConsumer::AllocateBuffer() { 85 void JniFrameConsumer::AllocateBuffer() {
112 // Only do anything if we're not being destructed. 86 // Only do anything if we're not being destructed.
113 if (!in_dtor_) { 87 if (!in_dtor_) {
114 if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) { 88 if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) {
115 jni_runtime_->display_task_runner()->PostTask(FROM_HERE, 89 jni_runtime_->display_task_runner()->PostTask(FROM_HERE,
116 base::Bind(&JniFrameConsumer::AllocateBuffer, 90 base::Bind(&JniFrameConsumer::AllocateBuffer,
117 base::Unretained(this))); 91 base::Unretained(this)));
118 return; 92 return;
119 } 93 }
120 94
121 DirectDesktopFrame* buffer = new DirectDesktopFrame(view_size_.width(), 95 webrtc::DesktopSize size(view_size_.width(), view_size_.height());
122 view_size_.height()); 96 webrtc::DesktopFrame* buffer = new webrtc::BasicDesktopFrame(size);
123
124 // Update Java's reference to the buffer and record of its dimensions.
125 jni_runtime_->UpdateImageBuffer(view_size_.width(),
126 view_size_.height(),
127 buffer->buffer());
128
129 frame_producer_->DrawBuffer(buffer); 97 frame_producer_->DrawBuffer(buffer);
130 } 98 }
131 } 99 }
132 100
133 } // namespace remoting 101 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698