OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 // Implementation of GtkVideoRenderer | 11 // Implementation of GtkVideoRenderer |
12 | 12 |
13 #include "webrtc/media/devices/gtkvideorenderer.h" | 13 #include "webrtc/media/devices/gtkvideorenderer.h" |
| 14 #include "webrtc/video_frame.h" |
14 | 15 |
15 #include <gdk/gdk.h> | 16 #include <gdk/gdk.h> |
16 #include <glib.h> | 17 #include <glib.h> |
17 #include <gtk/gtk.h> | 18 #include <gtk/gtk.h> |
18 | 19 |
19 #include "libyuv/convert_argb.h" | 20 #include "libyuv/convert_argb.h" |
20 #include "webrtc/media/engine/webrtcvideoframe.h" | |
21 | 21 |
22 namespace cricket { | 22 namespace cricket { |
23 | 23 |
24 class ScopedGdkLock { | 24 class ScopedGdkLock { |
25 public: | 25 public: |
26 ScopedGdkLock() { | 26 ScopedGdkLock() { |
27 gdk_threads_enter(); | 27 gdk_threads_enter(); |
28 } | 28 } |
29 | 29 |
30 ~ScopedGdkLock() { | 30 ~ScopedGdkLock() { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 } | 73 } |
74 | 74 |
75 image_.reset(new uint8_t[width * height * 4]); | 75 image_.reset(new uint8_t[width * height * 4]); |
76 gtk_widget_set_size_request(draw_area_, width, height); | 76 gtk_widget_set_size_request(draw_area_, width, height); |
77 | 77 |
78 width_ = width; | 78 width_ = width; |
79 height_ = height; | 79 height_ = height; |
80 return true; | 80 return true; |
81 } | 81 } |
82 | 82 |
83 void GtkVideoRenderer::OnFrame(const VideoFrame& video_frame) { | 83 void GtkVideoRenderer::OnFrame(const webrtc::VideoFrame& video_frame) { |
84 const cricket::WebRtcVideoFrame frame( | 84 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer( |
85 webrtc::I420Buffer::Rotate(video_frame.video_frame_buffer(), | 85 webrtc::I420Buffer::Rotate(video_frame.video_frame_buffer(), |
86 video_frame.rotation()), | 86 video_frame.rotation())); |
87 webrtc::kVideoRotation_0, video_frame.timestamp_us()); | |
88 | 87 |
89 // Need to set size as the frame might be rotated. | 88 // Need to set size as the frame might be rotated. |
90 if (!SetSize(frame.width(), frame.height())) { | 89 if (!SetSize(buffer->width(), buffer->height())) { |
91 return; | 90 return; |
92 } | 91 } |
93 | 92 |
94 // convert I420 frame to ABGR format, which is accepted by GTK | 93 // convert I420 frame to ABGR format, which is accepted by GTK |
95 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer( | |
96 frame.video_frame_buffer()); | |
97 libyuv::I420ToARGB(buffer->DataY(), buffer->StrideY(), | 94 libyuv::I420ToARGB(buffer->DataY(), buffer->StrideY(), |
98 buffer->DataU(), buffer->StrideU(), | 95 buffer->DataU(), buffer->StrideU(), |
99 buffer->DataV(), buffer->StrideV(), | 96 buffer->DataV(), buffer->StrideV(), |
100 image_.get(), frame.width() * 4, | 97 image_.get(), buffer->width() * 4, |
101 buffer->width(), buffer->height()); | 98 buffer->width(), buffer->height()); |
102 | 99 |
103 ScopedGdkLock lock; | 100 ScopedGdkLock lock; |
104 | 101 |
105 if (IsClosed()) { | 102 if (IsClosed()) { |
106 return; | 103 return; |
107 } | 104 } |
108 | 105 |
109 // draw the ABGR image | 106 // draw the ABGR image |
110 gdk_draw_rgb_32_image(draw_area_->window, | 107 gdk_draw_rgb_32_image(draw_area_->window, |
111 draw_area_->style->fg_gc[GTK_STATE_NORMAL], | 108 draw_area_->style->fg_gc[GTK_STATE_NORMAL], |
112 0, | 109 0, |
113 0, | 110 0, |
114 frame.width(), | 111 buffer->width(), |
115 frame.height(), | 112 buffer->height(), |
116 GDK_RGB_DITHER_MAX, | 113 GDK_RGB_DITHER_MAX, |
117 image_.get(), | 114 image_.get(), |
118 frame.width() * 4); | 115 buffer->width() * 4); |
119 | 116 |
120 // Run the Gtk main loop to refresh the window. | 117 // Run the Gtk main loop to refresh the window. |
121 Pump(); | 118 Pump(); |
122 } | 119 } |
123 | 120 |
124 bool GtkVideoRenderer::Initialize(int width, int height) { | 121 bool GtkVideoRenderer::Initialize(int width, int height) { |
125 gtk_init(NULL, NULL); | 122 gtk_init(NULL, NULL); |
126 window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); | 123 window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
127 draw_area_ = gtk_drawing_area_new(); | 124 draw_area_ = gtk_drawing_area_new(); |
128 if (!window_ || !draw_area_) { | 125 if (!window_ || !draw_area_) { |
(...skipping 25 matching lines...) Expand all Loading... |
154 } | 151 } |
155 | 152 |
156 if (!GTK_IS_WINDOW(window_) || !GTK_IS_DRAWING_AREA(draw_area_)) { | 153 if (!GTK_IS_WINDOW(window_) || !GTK_IS_DRAWING_AREA(draw_area_)) { |
157 return true; | 154 return true; |
158 } | 155 } |
159 | 156 |
160 return false; | 157 return false; |
161 } | 158 } |
162 | 159 |
163 } // namespace cricket | 160 } // namespace cricket |
OLD | NEW |