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 | 14 |
15 #include <gdk/gdk.h> | 15 #include <gdk/gdk.h> |
16 #include <glib.h> | 16 #include <glib.h> |
17 #include <gtk/gtk.h> | 17 #include <gtk/gtk.h> |
18 | 18 |
19 #include "webrtc/media/base/videocommon.h" | 19 #include "webrtc/media/base/videocommon.h" |
20 #include "webrtc/media/base/videoframe.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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 VideoFrame& video_frame) { |
84 const VideoFrame* frame = video_frame.GetCopyWithRotationApplied(); | 84 const cricket::WebRtcVideoFrame frame( |
| 85 webrtc::VideoFrameBuffer::Rotate(video_frame.video_frame_buffer(), |
| 86 video_frame.rotation()), |
| 87 webrtc::kVideoRotation_0, |
| 88 video_frame.timestamp_us()); |
85 | 89 |
86 // Need to set size as the frame might be rotated. | 90 // Need to set size as the frame might be rotated. |
87 if (!SetSize(frame->width(), frame->height())) { | 91 if (!SetSize(frame.width(), frame.height())) { |
88 return; | 92 return; |
89 } | 93 } |
90 | 94 |
91 // convert I420 frame to ABGR format, which is accepted by GTK | 95 // convert I420 frame to ABGR format, which is accepted by GTK |
92 frame->ConvertToRgbBuffer(cricket::FOURCC_ABGR, | 96 frame.ConvertToRgbBuffer(cricket::FOURCC_ABGR, |
93 image_.get(), | 97 image_.get(), |
94 static_cast<size_t>(frame->width()) * | 98 static_cast<size_t>(frame.width()) * |
95 frame->height() * 4, | 99 frame.height() * 4, |
96 frame->width() * 4); | 100 frame.width() * 4); |
97 | 101 |
98 ScopedGdkLock lock; | 102 ScopedGdkLock lock; |
99 | 103 |
100 if (IsClosed()) { | 104 if (IsClosed()) { |
101 return; | 105 return; |
102 } | 106 } |
103 | 107 |
104 // draw the ABGR image | 108 // draw the ABGR image |
105 gdk_draw_rgb_32_image(draw_area_->window, | 109 gdk_draw_rgb_32_image(draw_area_->window, |
106 draw_area_->style->fg_gc[GTK_STATE_NORMAL], | 110 draw_area_->style->fg_gc[GTK_STATE_NORMAL], |
107 0, | 111 0, |
108 0, | 112 0, |
109 frame->width(), | 113 frame.width(), |
110 frame->height(), | 114 frame.height(), |
111 GDK_RGB_DITHER_MAX, | 115 GDK_RGB_DITHER_MAX, |
112 image_.get(), | 116 image_.get(), |
113 frame->width() * 4); | 117 frame.width() * 4); |
114 | 118 |
115 // Run the Gtk main loop to refresh the window. | 119 // Run the Gtk main loop to refresh the window. |
116 Pump(); | 120 Pump(); |
117 } | 121 } |
118 | 122 |
119 bool GtkVideoRenderer::Initialize(int width, int height) { | 123 bool GtkVideoRenderer::Initialize(int width, int height) { |
120 gtk_init(NULL, NULL); | 124 gtk_init(NULL, NULL); |
121 window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); | 125 window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
122 draw_area_ = gtk_drawing_area_new(); | 126 draw_area_ = gtk_drawing_area_new(); |
123 if (!window_ || !draw_area_) { | 127 if (!window_ || !draw_area_) { |
(...skipping 25 matching lines...) Expand all Loading... |
149 } | 153 } |
150 | 154 |
151 if (!GTK_IS_WINDOW(window_) || !GTK_IS_DRAWING_AREA(draw_area_)) { | 155 if (!GTK_IS_WINDOW(window_) || !GTK_IS_DRAWING_AREA(draw_area_)) { |
152 return true; | 156 return true; |
153 } | 157 } |
154 | 158 |
155 return false; | 159 return false; |
156 } | 160 } |
157 | 161 |
158 } // namespace cricket | 162 } // namespace cricket |
OLD | NEW |