Merge lp:~vikoadi/audience/fix-resize into lp:~vikoadi/audience/audience-refactor

Proposed by Viko Adi Rahmawan
Status: Merged
Approved by: Viko Adi Rahmawan
Approved revision: 571
Merged at revision: 568
Proposed branch: lp:~vikoadi/audience/fix-resize
Merge into: lp:~vikoadi/audience/audience-refactor
Diff against target: 242 lines (+68/-62)
4 files modified
src/Audience.vala (+18/-31)
src/CMakeLists.txt (+2/-1)
src/Widgets/PlayerPage.vala (+1/-3)
src/Widgets/VideoPlayer.vala (+47/-27)
To merge this branch: bzr merge lp:~vikoadi/audience/fix-resize
Reviewer Review Type Date Requested Status
Viko Adi Rahmawan Approve
Review via email: mp+270178@code.launchpad.net

Commit message

merge fix-resize branch

To post a comment you must log in.
Revision history for this message
Viko Adi Rahmawan (vikoadi) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Audience.vala'
2--- src/Audience.vala 2015-06-19 14:28:39 +0000
3+++ src/Audience.vala 2015-09-04 13:47:58 +0000
4@@ -168,6 +168,7 @@
5 mainwindow.set_application (this);
6 mainwindow.set_titlebar (header);
7 mainwindow.window_position = Gtk.WindowPosition.CENTER;
8+ mainwindow.gravity = Gdk.Gravity.CENTER;
9 mainwindow.show_all ();
10 if (!settings.show_window_decoration)
11 mainwindow.decorated = false;
12@@ -200,40 +201,26 @@
13 }
14
15 public void set_content_size (double width, double height, double content_height){
16- double width_offset = mainwindow.get_allocated_width () - width;
17- double height_offset = mainwindow.get_allocated_height () - content_height;
18-
19- print ("Width: %f, Height: %f, Offset: %f )\n", width, height,content_height);
20-
21 var geom = Gdk.Geometry ();
22- geom.min_aspect = geom.max_aspect = (width + width_offset) / (height + height_offset);
23-
24- var w = mainwindow.get_allocated_width ();
25- var h = (int) (w * geom.max_aspect);
26- int b, c;
27-
28- mainwindow.get_window ().set_geometry_hints (geom, Gdk.WindowHints.ASPECT);
29-
30- mainwindow.get_window ().constrain_size (geom, Gdk.WindowHints.ASPECT, w, h, out b, out c);
31- print ("Result: %i %i == %i %i\n", w, h, b, c);
32- mainwindow.get_window ().resize (b, c);
33-
34- }
35-
36- public void on_configure_window (uint video_w, uint video_h) {
37- Gdk.Rectangle monitor;
38- var screen = Gdk.Screen.get_default ();
39- screen.get_monitor_geometry (screen.get_monitor_at_window (mainwindow.get_window ()), out monitor);
40-
41- int width = 0, height = 0;
42- if (monitor.width > video_w && monitor.height > video_h) {
43- width = (int) mainwindow.get_allocated_width ();
44- height = (int) mainwindow.get_allocated_height ();
45+
46+ if (width == 0
47+ && height == 0
48+ && content_height == 0) {
49+ geom.min_aspect = geom.max_aspect = 0;
50 } else {
51- width = (int)(monitor.width * 0.9);
52- height = (int)((double)video_h / video_w * width);
53+ double width_offset = mainwindow.get_allocated_width () - width;
54+ double height_offset = mainwindow.get_allocated_height () - content_height;
55+
56+ debug ("Width: %f, Height: %f, Offset: %f )\n", width, height, content_height);
57+
58+ geom.min_aspect = geom.max_aspect = (width + width_offset) / (height + height_offset);
59+
60+ var w = mainwindow.get_allocated_width ();
61+ var h = (int) (w * geom.max_aspect);
62+ int b, c;
63 }
64- mainwindow.resize(width, height);
65+
66+ mainwindow.set_geometry_hints (mainwindow, geom, Gdk.WindowHints.ASPECT);
67 }
68
69 private void on_player_ended () {
70
71=== modified file 'src/CMakeLists.txt'
72--- src/CMakeLists.txt 2015-06-14 07:03:13 +0000
73+++ src/CMakeLists.txt 2015-09-04 13:47:58 +0000
74@@ -11,13 +11,14 @@
75 # pkgconfig, real C code
76 find_package (PkgConfig)
77
78-set (PKG_DEPS granite>=0.3.0 clutter-gtk-1.0 gstreamer-1.0 gstreamer-pbutils-1.0 gstreamer-tag-1.0)
79+set (PKG_DEPS granite>=0.3.0 clutter-gtk-1.0 gstreamer-1.0 gstreamer-pbutils-1.0 gstreamer-video-1.0 gstreamer-tag-1.0)
80 set (VALA_DEPS
81 granite>=0.3.0
82 clutter-gtk-1.0
83 gdk-x11-3.0
84 gstreamer-1.0
85 gstreamer-pbutils-1.0
86+ gstreamer-video-1.0
87 gstreamer-tag-1.0
88 )
89
90
91=== modified file 'src/Widgets/PlayerPage.vala'
92--- src/Widgets/PlayerPage.vala 2015-06-22 17:39:00 +0000
93+++ src/Widgets/PlayerPage.vala 2015-09-04 13:47:58 +0000
94@@ -35,7 +35,6 @@
95 public signal void ended ();
96
97 public PlayerPage () {
98- /* video_player = Widgets.VideoPlayer.get_default (); */
99 video_player = new Widgets.VideoPlayer();
100 video_player.notify["playing"].connect (() => {bottom_bar.toggle_play_pause ();});
101
102@@ -190,8 +189,6 @@
103 App.get_instance ().mainwindow.set_keep_above (video_player.playing && settings.stay_on_top);
104 });
105
106- video_player.configure_window.connect ((video_w, video_h) => {App.get_instance ().on_configure_window (video_w, video_h);});
107-
108 bottom_bar.time_widget.slider_motion_event.connect ((event) => {
109 int x, y;
110 bottom_bar.translate_coordinates (App.get_instance ().mainwindow, (int)event.x, (int)event.y, out x, out y);
111@@ -224,6 +221,7 @@
112 ~PlayerPage () {
113 video_player.playing = false;
114
115+ App.get_instance ().set_content_size (0, 0, 0);
116 this.size_allocate.disconnect (on_size_allocate);
117 App.get_instance ().mainwindow.window_state_event.disconnect (on_window_state_event);
118 App.get_instance ().mainwindow.key_press_event.disconnect (on_key_press_event);
119
120=== modified file 'src/Widgets/VideoPlayer.vala'
121--- src/Widgets/VideoPlayer.vala 2015-07-15 17:19:55 +0000
122+++ src/Widgets/VideoPlayer.vala 2015-09-04 13:47:58 +0000
123@@ -35,6 +35,16 @@
124 SOFT_COLORBALANCE = (1 << 10)
125 }
126
127+/* use internal function while
128+ * https://bugzilla.gnome.org/show_bug.cgi?id=754567
129+ * isn't fixed
130+ */
131+[CCode (cprefix = "Gst", gir_namespace="GstVideo", gir_version="1.0", lower_case_cprefix="gst_video_", cheader_filename = "gst/video/video.h")]
132+namespace GstVideo {
133+ [CCode (cheader_filename = "gst/video/video.h")]
134+ public static extern bool calculate_display_ratio (out uint dar_n, out uint dar_d, uint video_width, uint video_height, uint video_par_n, uint video_par_d, uint display_par_n, uint display_par_d);
135+}
136+
137 namespace Audience.Widgets {
138 public class VideoPlayer : Actor {
139 public bool at_end;
140@@ -94,8 +104,10 @@
141 var video = info.get_video_streams ();
142 if (video != null && video.data != null) {
143 var video_info = (Gst.PbUtils.DiscovererVideoInfo)video.data;
144- video_height = video_info.get_height ();
145- video_width = query_video_width (video_info);
146+ uint w, h;
147+ get_media_size (video_info, out w, out h);
148+ video_width = w;
149+ video_height = h;
150 }
151 } catch (Error e) {
152 error ();
153@@ -103,8 +115,6 @@
154 return;
155 }
156
157- intial_relayout = true;
158-
159 playbin.get_bus ().set_flushing (true);
160 playing = false;
161 playbin.set_state (Gst.State.READY);
162@@ -180,7 +190,6 @@
163 public signal void audio_tags_changed ();
164 public signal void error ();
165 public signal void plugin_install_done ();
166- public signal void configure_window (uint video_w, uint video_h);
167 public signal void progression_changed (double current_time, double total_time);
168 public signal void external_subtitle_changed (string? uri);
169
170@@ -363,16 +372,10 @@
171 }
172 }
173
174- bool intial_relayout = false;
175 public bool relayout () {
176 if (video_width < 1 || video_height < 1 || uri == null)
177 return false;
178
179- if (intial_relayout) {
180- configure_window (video_width, video_height);
181- intial_relayout = false;
182- }
183-
184 var stage = get_stage ();
185 var aspect = stage.width / video_width < stage.height / video_height ?
186 stage.width / video_width : stage.height / video_height;
187@@ -485,22 +488,39 @@
188 playbin.seek_simple (Gst.Format.TIME, Gst.SeekFlags.FLUSH | Gst.SeekFlags.ACCURATE, new_position);
189 }
190
191- uint query_video_width (Gst.PbUtils.DiscovererVideoInfo video_info) {
192- var par = get_video_par (video_info);
193- if (par == -1) {
194- return video_info.get_width ();
195- }
196- return (uint)(video_height * par);
197- }
198-
199- //pixel aspect ratio
200- double get_video_par (Gst.PbUtils.DiscovererVideoInfo video_info) {
201- var num = video_info.get_par_num ();
202- var denom = video_info.get_par_denom ();
203- if (num == 1 && denom == 1) {
204- return -1; //Error.
205- }
206- return num / (double)denom;
207+
208+
209+ private void get_media_size (Gst.PbUtils.DiscovererVideoInfo video_info, out uint video_width, out uint video_height) {
210+ var video_w = video_info.get_width ();
211+ var video_h = video_info.get_height ();
212+ var video_par_n = video_info.get_par_num ();
213+ var video_par_d = video_info.get_par_denom ();
214+ if (video_par_n == 0 || video_par_d == 0) {
215+ debug ("width and/or height 0, assumming 1/1");
216+ video_par_n = 1;
217+ video_par_d = 1;
218+ }
219+ debug ("video PAR %u/%u", video_par_n, video_par_d);
220+
221+ uint num;
222+ uint den;
223+ if (!GstVideo.calculate_display_ratio (out num, out den, video_w, video_h, video_par_n, video_par_d, 1, 1)) {
224+ warning ("overflow calculating display ratio");
225+ num = 1;
226+ den = 1;
227+ }
228+ debug ("calculated scale ratio %u / %u for %ux%u", num, den, video_w, video_h);
229+
230+ if (video_w % num == 0) {
231+ debug ("keeping video width");
232+ video_width = video_w;
233+ video_height = (uint) Gst.Util.uint64_scale (video_w, den, num);
234+ } else {
235+ debug ("keeping video height");
236+ video_width = (uint) Gst.Util.uint64_scale (video_h, num, den);
237+ video_height = video_h;
238+ }
239+ debug ("scaling to %ux%u", video_width, video_height);
240 }
241
242 void update_subtitle_font () {

Subscribers

People subscribed via source and target branches

to all changes: