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

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

Issue 19297003: Add support for drawing video onto a Java ByteBuffer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename to JniFrameConsumer, use WeakPtrFactory, eliminate buffer_ pointer Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "remoting/client/jni/jni_frame_consumer.h"
6
7 #include "base/android/jni_android.h"
8 #include "base/logging.h"
9 #include "remoting/client/frame_producer.h"
10 #include "remoting/client/jni/chromoting_jni.h"
11 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
12
13 namespace {
14
15 // Allocates its buffer within a Java direct byte buffer, where it can be
16 // accessed by both native and managed code.
17 class DirectDesktopFrame : public webrtc::BasicDesktopFrame {
18 public:
19 DirectDesktopFrame(int width, int height);
Wez 2013/07/16 18:45:53 You need a(n empty) virtual dtor for this class, s
solb 2013/07/16 21:35:41 Done.
20
21 jobject buffer() const {
22 return buffer_;
23 }
24
25 private:
26 jobject buffer_;
27 };
28
29 DirectDesktopFrame::DirectDesktopFrame(int width, int height)
Wez 2013/07/16 18:45:53 You can move this implementation in-line to the ct
solb 2013/07/16 21:35:41 I'd rather not inline the constructor.
30 : webrtc::BasicDesktopFrame(webrtc::DesktopSize(width, height)) {
31 JNIEnv* env = base::android::AttachCurrentThread();
32 buffer_ = env->NewDirectByteBuffer(data(), stride()*height);
33 }
34
35 } // namespace
36
37 namespace remoting {
38
39 JniFrameConsumer::JniFrameConsumer()
40 : frame_producer_(NULL) {
41 }
42
43 JniFrameConsumer::~JniFrameConsumer() {}
Wez 2013/07/16 18:45:53 Because of the slightly messy Producer/Consumer in
solb 2013/07/16 21:35:41 Done.
44
45 void JniFrameConsumer::set_frame_producer(FrameProducer* producer) {
46 frame_producer_ = producer;
47 }
48
49 void JniFrameConsumer::ApplyBuffer(const SkISize& view_size,
50 const SkIRect& clip_area,
Wez 2013/07/16 18:45:53 nit: Indentation
solb 2013/07/16 21:35:41 Done.
51 webrtc::DesktopFrame* buffer,
52 const SkRegion& region) {
53 ChromotingJni::GetInstance()->RedrawCanvas();
Wez 2013/07/16 18:45:53 Rather than calling via the global instance, why n
solb 2013/07/16 21:35:41 It's a singleton. I think that holding a reference
Wez 2013/07/22 19:41:28 I disagree; it's clearer for the reader to see the
solb 2013/07/22 22:49:32 Done.
54
55 if (view_size.width() > view_size_.width() ||
56 view_size.height() > view_size_.height()) {
57 LOG(INFO) << "Existing buffer is too small";
58 view_size_ = view_size;
59 frame_producer_->RequestReturnBuffers(base::Closure());
Wez 2013/07/16 18:45:53 You don't need this - the caller just returned the
solb 2013/07/16 21:35:41 Done.
60 return;
61 }
62
63 // Return |buffer| to |frame_producer_|.
Wez 2013/07/16 18:45:53 nit: Suggest: Supply |frame_producer_| with a buff
solb 2013/07/16 21:35:41 Done.
64 frame_producer_->DrawBuffer(buffer);
65 }
66
67 void JniFrameConsumer::ReturnBuffer(webrtc::DesktopFrame* buffer) {
68 LOG(INFO) << "Returning image buffer";
69
70 // Decide whether we will need a replacement buffer.
71 bool reallocate = view_size_.width() > buffer->size().width() ||
72 view_size_.height() > buffer->size().height();
Wez 2013/07/16 18:45:53 This is fragile in the case where the view size ch
solb 2013/07/16 21:35:41 I just got rid of the reallocation, since the abov
73
74 delete buffer;
75 buffer = NULL;
Wez 2013/07/16 18:45:53 nit: no need to NULL |buffer| here.
solb 2013/07/16 21:35:41 Done.
76
77 if (reallocate) {
78 LOG(INFO) << "Allocating replacement image buffer";
79 frame_producer_->DrawBuffer(AllocateBuffer());
80 }
81 }
82
83 void JniFrameConsumer::SetSourceSize(const SkISize& source_size,
84 const SkIPoint& dpi) {
Wez 2013/07/16 18:45:53 nit: Indentation.
solb 2013/07/16 21:35:41 Done.
85 view_size_ = source_size;
Wez 2013/07/16 18:45:53 nit: Add a comment to explain that we currently re
solb 2013/07/16 21:35:41 Done.
86 clip_area_ = SkIRect::MakeSize(view_size_);
87 frame_producer_->SetOutputSizeAndClip(view_size_, clip_area_);
88
89 // Allocate a buffer and start drawing frames onto it.
90 frame_producer_->DrawBuffer(AllocateBuffer());
Wez 2013/07/16 18:45:53 This don't look right - you're un-conditionally al
solb 2013/07/16 21:35:41 Done.
91 }
92
93 webrtc::DesktopFrame* JniFrameConsumer::AllocateBuffer() {
94 DirectDesktopFrame* buffer = new DirectDesktopFrame(view_size_.width(),
95 view_size_.height());
96
97 // Update Java's reference to the buffer and record of its dimensions.
98 ChromotingJni::GetInstance()->UpdateImageBuffer(
99 view_size_.width(),
100 view_size_.height(),
101 buffer->buffer());
102
103 return buffer;
104 }
105
106 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698