amend list of known video file extensions.
[ardour.git] / gtk2_ardour / add_video_dialog.cc
1 /*
2     Copyright (C) 2010-2013 Paul Davis
3     Author: Robin Gareus <robin@gareus.org>
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20 #include <cstdio>
21 #include <cmath>
22
23 #include <sigc++/bind.h>
24 #include <curl/curl.h>
25
26 #include "pbd/error.h"
27 #include "pbd/convert.h"
28 #include "gtkmm2ext/utils.h"
29 #include "gtkmm2ext/rgb_macros.h"
30 #include "ardour/session_directory.h"
31 #include "ardour/profile.h"
32 #include "ardour/template_utils.h"
33 #include "ardour/session.h"
34 #include "ardour_ui.h"
35
36 #include "utils.h"
37 #include "add_video_dialog.h"
38 #include "utils_videotl.h"
39 #include "i18n.h"
40
41 using namespace Gtk;
42 using namespace std;
43 using namespace PBD;
44 using namespace ARDOUR;
45 using namespace VideoUtils;
46
47 #define PREVIEW_WIDTH (240)
48 #define PREVIEW_HEIGHT (180)
49
50 #ifndef MIN
51 #define MIN(a,b) ( (a) < (b) ? (a) : (b) )
52 #endif
53
54 AddVideoDialog::AddVideoDialog (Session* s)
55         : ArdourDialog (_("Set Video Track"))
56         , seek_slider (0,1000,1)
57         , preview_path ("")
58         , pi_tcin ("-", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false)
59         , pi_tcout ("-", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false)
60         , pi_aspect ("-", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false)
61         , pi_fps ("-", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false)
62         , chooser (FILE_CHOOSER_ACTION_OPEN)
63         , xjadeo_checkbox (_("Launch External Video Monitor"))
64         , set_session_fps_checkbox (_("Adjust Session Framerate to Match Video Framerate"))
65         , harvid_path ("")
66         , harvid_reset (_("Reload docroot"))
67         , harvid_list (ListStore::create(harvid_list_columns))
68         , harvid_list_view (harvid_list)
69 {
70         set_session (s);
71         set_name ("AddVideoDialog");
72         set_modal (true);
73         set_skip_taskbar_hint (true);
74         set_resizable (true);
75         set_size_request (800, -1);
76
77         harvid_initialized = false;
78         std::string dstdir = video_dest_dir(_session->session_directory().video_path(), video_get_docroot(Config));
79
80         if (Config->get_video_advanced_setup()) {
81
82                 /* Harvid Browser */
83                 harvid_list_view.append_column("", pixBufRenderer);
84                 harvid_list_view.append_column(_("Filename"), harvid_list_columns.filename);
85
86                 harvid_list_view.get_column(0)->set_alignment(0.5);
87                 harvid_list_view.get_column(0)->add_attribute(pixBufRenderer, "stock-id", harvid_list_columns.id);
88                 harvid_list_view.get_column(1)->set_expand(true);
89                 harvid_list_view.get_column(1)->set_sort_column(harvid_list_columns.filename);
90                 harvid_list_view.set_enable_search(true);
91                 harvid_list_view.set_search_column(1);
92
93                 harvid_list_view.get_selection()->set_mode (SELECTION_SINGLE);
94
95                 harvid_list_view.get_selection()->signal_changed().connect(sigc::mem_fun(*this, &AddVideoDialog::harvid_list_view_selected));
96                 harvid_list_view.signal_row_activated().connect (sigc::mem_fun (*this, &AddVideoDialog::harvid_list_view_activated));
97
98                 VBox* vbox = manage (new VBox);
99                 Gtk::ScrolledWindow *scroll = manage(new ScrolledWindow);
100                 scroll->add(harvid_list_view);
101                 scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
102
103                 HBox* hbox = manage (new HBox);
104                 harvid_path.set_alignment (0, 0.5);
105                 hbox->pack_start (harvid_path, true, true);
106                 hbox->pack_start (harvid_reset, false, false);
107
108                 vbox->pack_start (*hbox, false, false);
109                 vbox->pack_start (*scroll, true, true);
110
111                 notebook.append_page (*vbox, _("VideoServerIndex"));
112         } else {
113                 /* dummy entry */
114                 VBox* vbox = manage (new VBox);
115                 notebook.append_page (*vbox, _("VideoServerIndex"));
116         }
117
118         /* file chooser */
119         chooser.set_border_width (4);
120 #ifdef GTKOSX
121         /* some broken redraw behaviour - this is a bandaid */
122         chooser.signal_selection_changed().connect (mem_fun (chooser, &Widget::queue_draw));
123 #endif
124         chooser.set_current_folder (dstdir);
125
126         Gtk::FileFilter video_filter;
127         Gtk::FileFilter matchall_filter;
128         video_filter.add_custom (FILE_FILTER_FILENAME, mem_fun(*this, &AddVideoDialog::on_video_filter));
129         video_filter.set_name (_("Video files"));
130
131         matchall_filter.add_pattern ("*.*");
132         matchall_filter.set_name (_("All files"));
133
134         chooser.add_filter (video_filter);
135         chooser.add_filter (matchall_filter);
136         chooser.set_select_multiple (false);
137
138         VBox* vboxfb = manage (new VBox);
139         vboxfb->pack_start (chooser, true, true, 0);
140
141         if (video_get_docroot(Config).size() > 0 &&
142                         Config->get_video_advanced_setup()) {
143                 notebook.append_page (*vboxfb, _("Browse Files"));
144         }
145
146         /* Global Options*/
147         Gtk::Label* l;
148         VBox* options_box = manage (new VBox);
149
150         l = manage (new Label (_("<b>Options</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
151         l->set_use_markup ();
152
153         options_box->pack_start (*l, false, true, 4);
154         options_box->pack_start (xjadeo_checkbox, false, true, 2);
155         options_box->pack_start (set_session_fps_checkbox, false, true, 2);
156
157         /* preview pane */
158         VBox* previewpane = manage (new VBox);
159         Gtk::Table *table = manage(new Table(5,2));
160
161         table->set_row_spacings(2);
162         table->set_col_spacings(4);
163
164         l = manage (new Label (_("<b>Video Information</b>"), Gtk::ALIGN_CENTER, Gtk::ALIGN_CENTER, false));
165         l->set_use_markup ();
166         table->attach (*l, 0, 2, 0, 1, FILL, FILL);
167         l = manage (new Label (_("Start:"), Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER, false));
168         table->attach (*l, 0, 1, 1, 2, FILL, FILL);
169         table->attach (pi_tcin, 1, 2, 1, 2, FILL, FILL);
170         l = manage (new Label (_("End:"), Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER, false));
171         table->attach (*l, 0, 1, 2, 3, FILL, FILL);
172         table->attach (pi_tcout, 1, 2, 2, 3, FILL, FILL);
173         l = manage (new Label (_("Frame rate:"), Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER, false));
174         table->attach (*l, 0, 1, 3, 4, FILL, FILL);
175         table->attach (pi_fps, 1, 2, 3, 4, FILL, FILL);
176         l = manage (new Label (_("Aspect Ratio:"), Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER, false));
177         table->attach (*l, 0, 1, 4, 5, FILL, FILL);
178         table->attach (pi_aspect, 1, 2, 4, 5, FILL, FILL);
179
180         preview_image = manage(new Gtk::Image);
181
182         imgbuf = Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, true, 8, PREVIEW_WIDTH, PREVIEW_HEIGHT);
183         imgbuf->fill(RGBA_TO_UINT(127,0,0,255));
184         preview_image->set(imgbuf);
185         seek_slider.set_draw_value(false);
186
187         HBox* hbox = manage (new HBox);
188         hbox->pack_start (*table, true, false);
189
190         Gtk::Alignment *al = manage(new Gtk::Alignment());
191         al->set_size_request(-1, 20);
192
193         previewpane->pack_start (*preview_image, false, false);
194         previewpane->pack_start (seek_slider, false, false);
195         previewpane->pack_start (*al, false, false);
196         previewpane->pack_start (*hbox, true, true, 6);
197
198         /* Overall layout */
199         hbox = manage (new HBox);
200         if (Config->get_video_advanced_setup()) {
201                 hbox->pack_start (notebook, true, true);
202         } else {
203                 hbox->pack_start (*vboxfb, true, true);
204         }
205         hbox->pack_start (*previewpane, false, false);
206
207         get_vbox()->set_spacing (4);
208         get_vbox()->pack_start (*hbox, true, true);
209         get_vbox()->pack_start (*options_box, false, false);
210
211
212         /* xjadeo checkbox */
213         if (ARDOUR_UI::instance()->video_timeline->found_xjadeo()
214                         /* TODO xjadeo setup w/ xjremote */
215                         && video_get_docroot(Config).size() > 0) {
216                 xjadeo_checkbox.set_active(true);  /* set in ardour_ui.cpp ?! */
217         } else {
218                 printf("xjadeo was not found or video-server docroot is unset (remote video-server)\n");
219                 xjadeo_checkbox.set_active(false);
220                 xjadeo_checkbox.set_sensitive(false);
221         }
222
223         /* FPS checkbox */
224         set_session_fps_checkbox.set_active(true);
225
226         /* Buttons */
227         add_button (Stock::CANCEL, RESPONSE_CANCEL);
228         ok_button = add_button (Stock::OK, RESPONSE_ACCEPT);
229         //ok_button->set_sensitive(false);
230         set_action_ok(false);
231
232         /* connect signals after eveything has been initialized */
233         chooser.signal_selection_changed().connect (mem_fun (*this, &AddVideoDialog::file_selection_changed));
234         chooser.signal_file_activated().connect (mem_fun (*this, &AddVideoDialog::file_activated));
235         //chooser.signal_update_preview().connect(sigc::mem_fun(*this, &AddVideoDialog::update_preview));
236         notebook.signal_switch_page().connect (sigc::hide_return (sigc::hide (sigc::hide (sigc::mem_fun (*this, &AddVideoDialog::page_switch)))));
237         seek_slider.signal_value_changed().connect(sigc::mem_fun(*this, &AddVideoDialog::seek_preview));
238         harvid_reset.signal_clicked().connect (sigc::mem_fun (*this, &AddVideoDialog::harvid_load_docroot));
239
240         show_all_children ();
241 }
242
243 AddVideoDialog::~AddVideoDialog ()
244 {
245 }
246
247 void
248 AddVideoDialog::on_show ()
249 {
250         Dialog::on_show ();
251 }
252
253 static bool check_video_file_extension(std::string file)
254 {
255         const char* suffixes[] = {
256                 ".avi"     , ".AVI"     ,
257                 ".mov"     , ".MOV"     ,
258                 ".ogg"     , ".OGG"     ,
259                 ".ogv"     , ".OGV"     ,
260                 ".mpg"     , ".MPG"     ,
261                 ".mpeg"    , ".MPEG"    ,
262                 ".mts"     , ".MTS"    ,
263                 ".mp4"     , ".MP4"     ,
264                 ".mkv"     , ".MKV"     ,
265                 ".vob"     , ".VOB"     ,
266                 ".asf"     , ".ASF"     ,
267                 ".avs"     , ".AVS"     ,
268                 ".dts"     , ".DTS"     ,
269                 ".flv"     , ".FLV"     ,
270                 ".m4v"     , ".M4V"     ,
271                 ".matroska", ".MATROSKA",
272                 ".h264"    , ".H264"    ,
273                 ".dv"      , ".DV"      ,
274                 ".dirac"   , ".DIRAC"   ,
275                 ".webm"    , ".WEBM"    ,
276                 ".wmv"     , ".wmv"     ,
277                 ".ts"      , ".ts"      ,
278         };
279
280         for (size_t n = 0; n < sizeof(suffixes)/sizeof(suffixes[0]); ++n) {
281                 if (file.rfind (suffixes[n]) == file.length() - strlen (suffixes[n])) {
282                         return true;
283                 }
284         }
285
286         return false;
287 }
288
289 bool
290 AddVideoDialog::on_video_filter (const FileFilter::Info& filter_info)
291 {
292         return check_video_file_extension(filter_info.filename);
293 }
294
295 std::string
296 AddVideoDialog::file_name (bool &local_file)
297 {
298         int n = notebook.get_current_page ();
299         if (n == 1 || ! Config->get_video_advanced_setup()) {
300                 local_file = true;
301                 return chooser.get_filename();
302         } else {
303                 local_file = false;
304                 Gtk::TreeModel::iterator iter = harvid_list_view.get_selection()->get_selected();
305                 if(!iter) return "";
306
307                 std::string uri = (*iter)[harvid_list_columns.uri];
308                 std::string video_server_url = video_get_server_url(Config);
309
310                 /* check if video server is running locally */
311                 if (video_get_docroot(Config).size() > 0
312                                 && !video_server_url.compare(0, 16, "http://localhost"))
313                 {
314                         /* check if the file can be accessed */
315                         int plen;
316                         CURL *curl;
317                         curl = curl_easy_init();
318                         char *ue = curl_easy_unescape(curl, uri.c_str(), uri.length(), &plen);
319                         std::string path = video_get_docroot(Config) + ue;
320                         if (!::access(path.c_str(), R_OK)) {
321                                 uri = path;
322                                 local_file = true;
323                         }
324                         curl_easy_cleanup(curl);
325                         curl_free(ue);
326                 }
327                 return uri;
328         }
329 }
330
331 enum VtlImportOption
332 AddVideoDialog::import_option ()
333 {
334         int n = notebook.get_current_page ();
335         if (n == 0 && Config->get_video_advanced_setup()) { return VTL_IMPORT_NONE; }
336         return VTL_IMPORT_TRANSCODE;
337 }
338
339 bool
340 AddVideoDialog::launch_xjadeo ()
341 {
342         return xjadeo_checkbox.get_active();
343 }
344
345 bool
346 AddVideoDialog::auto_set_session_fps ()
347 {
348         return set_session_fps_checkbox.get_active();
349 }
350
351 void
352 AddVideoDialog::clear_preview_image ()
353 {
354         imgbuf->fill(RGBA_TO_UINT(0,0,0,255));
355         video_draw_cross(imgbuf);
356         preview_image->set(imgbuf);
357         preview_image->show();
358 }
359
360 void
361 AddVideoDialog::set_action_ok (bool yn)
362 {
363         if (yn) {
364                 ok_button->set_sensitive(true);
365         } else {
366                 preview_path = "";
367                 pi_tcin.set_text("-");
368                 pi_tcout.set_text("-");
369                 pi_aspect.set_text("-");
370                 pi_fps.set_text("-");
371                 ok_button->set_sensitive(false);
372                 clear_preview_image();
373         }
374 }
375
376 void
377 AddVideoDialog::file_selection_changed ()
378 {
379         if (chooser.get_filename().size() > 0) {
380                 std::string path = chooser.get_filename();
381                 bool ok =
382                                 check_video_file_extension(path)
383                                 &&  Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_REGULAR | Glib::FILE_TEST_IS_SYMLINK)
384                                 && !Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_DIR);
385                 set_action_ok(ok);
386                 if (ok) {
387                         seek_slider.set_value(0);
388                         request_preview(video_map_path(video_get_docroot(Config), path));
389                 }
390         } else {
391                 set_action_ok(false);
392         }
393 }
394
395 void
396 AddVideoDialog::file_activated ()
397 {
398         if (chooser.get_filename().size() > 0) {
399                 std::string path = chooser.get_filename();
400                 // TODO check docroot -> set import options
401                 bool ok =
402                                 check_video_file_extension(path)
403                                 &&  Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_REGULAR | Glib::FILE_TEST_IS_SYMLINK)
404                                 && !Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_DIR);
405                 if (ok) {
406                         Gtk::Dialog::response(RESPONSE_ACCEPT);
407                 }
408         }
409 }
410
411 /**** Tree List Interaction ***/
412
413 void
414 AddVideoDialog::harvid_list_view_selected () {
415         Gtk::TreeModel::iterator iter = harvid_list_view.get_selection()->get_selected();
416         // TODO check docroot -> set import options, xjadeo
417         if(!iter) {
418                 set_action_ok(false);
419                 return;
420         }
421         if ((std::string)((*iter)[harvid_list_columns.id]) == Stock::DIRECTORY.id) {
422                 set_action_ok(false);
423         } else {
424                 set_action_ok(true);
425                 seek_slider.set_value(0);
426                 request_preview((*iter)[harvid_list_columns.uri]);
427         }
428 }
429
430 void
431 AddVideoDialog::harvid_list_view_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn*) {
432         Gtk::TreeModel::iterator iter = harvid_list->get_iter(path);
433         if (!iter) return;
434         std::string type = (*iter)[harvid_list_columns.id];
435         std::string url = (*iter)[harvid_list_columns.uri];
436
437 #if 0
438         printf ("A: %s %s %s\n",
439                         ((std::string)((*iter)[harvid_list_columns.id])).c_str(),
440                         ((std::string)((*iter)[harvid_list_columns.uri])).c_str(),
441                         ((std::string)((*iter)[harvid_list_columns.filename])).c_str());
442 #endif
443
444         if (type == Gtk::Stock::DIRECTORY.id) {
445                 harvid_request(url.c_str());
446         } else {
447                 Gtk::Dialog::response(RESPONSE_ACCEPT);
448         }
449 }
450
451 void
452 AddVideoDialog::harvid_load_docroot() {
453         set_action_ok(false);
454
455         std::string video_server_url = video_get_server_url(Config);
456         char url[2048];
457         snprintf(url, sizeof(url), "%s%sindex/"
458                 , video_server_url.c_str()
459                 , (video_server_url.length()>0 && video_server_url.at(video_server_url.length()-1) == '/')?"":"/");
460         harvid_request(url);
461         harvid_initialized = true;
462 }
463
464 bool
465 AddVideoDialog::page_switch() {
466         if (notebook.get_current_page () == 1 || Config->get_video_advanced_setup()) {
467                 file_selection_changed();
468                 return true;
469         }
470
471         if (harvid_initialized) {
472                 harvid_list_view_selected();
473         } else {
474                 harvid_load_docroot();
475         }
476         return true;
477 }
478
479 /**** Harvid HTTP interface ***/
480 void
481 AddVideoDialog::harvid_request(std::string u)
482 {
483         char url[2048];
484         int status;
485         snprintf(url, sizeof(url), "%s?format=csv", u.c_str());
486
487         harvid_list->clear();
488
489         char *res = a3_curl_http_get(url, &status);
490         if (status != 200) {
491                 printf("request failed\n"); // XXX
492                 harvid_path.set_text(" - request failed -");
493                 free(res);
494                 return;
495         }
496
497         /* add up-to-parent */
498         size_t se = u.find_last_of("/", u.size()-2);
499         size_t ss = u.find("/index/");
500         if (se != string::npos && ss != string::npos && se > ss) {
501                 TreeModel::iterator new_row = harvid_list->append();
502                 TreeModel::Row row = *new_row;
503                 row[harvid_list_columns.id      ] = Gtk::Stock::DIRECTORY.id;
504                 row[harvid_list_columns.uri     ] = u.substr(0, se + 1);
505                 row[harvid_list_columns.filename] = X_("..");
506         }
507         if (se != string::npos) {
508                 int plen;
509                 std::string path = u.substr(ss + 6);
510                 CURL *curl;
511                 curl = curl_easy_init();
512                 char *ue = curl_easy_unescape(curl, path.c_str(), path.length(), &plen);
513                 harvid_path.set_text(std::string(ue));
514                 curl_easy_cleanup(curl);
515                 curl_free(ue);
516         } else {
517                 harvid_path.set_text(" ??? ");
518         }
519
520         if (!res) return;
521
522         std::vector<std::vector<std::string> > lines;
523         ParseCSV(std::string(res), lines);
524         for (std::vector<std::vector<std::string> >::iterator i = lines.begin(); i != lines.end(); ++i) {
525                 TreeModel::iterator new_row = harvid_list->append();
526                 TreeModel::Row row = *new_row;
527
528                 if (i->at(0) == X_("D")) {
529                         row[harvid_list_columns.id      ] = Gtk::Stock::DIRECTORY.id;
530                         row[harvid_list_columns.uri     ] = i->at(1).c_str();
531                         row[harvid_list_columns.filename] = i->at(2).c_str();
532                 } else {
533                         row[harvid_list_columns.id      ] = Gtk::Stock::MEDIA_PLAY.id;
534                         row[harvid_list_columns.uri     ] = i->at(2).c_str();
535                         row[harvid_list_columns.filename] = i->at(3).c_str();
536                 }
537         }
538
539         free(res);
540 }
541
542 void
543 AddVideoDialog::seek_preview()
544 {
545         if (preview_path.size() > 0)
546                 request_preview(preview_path);
547 }
548
549 void
550 AddVideoDialog::request_preview(std::string u)
551 {
552         std::string video_server_url = video_get_server_url(Config);
553
554         double video_file_fps;
555         long long int video_duration;
556         double video_start_offset;
557         double video_aspect_ratio;
558
559         int clip_width = PREVIEW_WIDTH;
560         int clip_height = PREVIEW_HEIGHT;
561         int clip_xoff, clip_yoff;
562
563         if (!video_query_info(video_server_url, u,
564                         video_file_fps, video_duration, video_start_offset, video_aspect_ratio))
565         {
566                 printf("image preview info request failed\n");
567                 // set_action_ok(false); // XXX only if docroot mismatch
568                 preview_path = "";
569                 pi_tcin.set_text("-");
570                 pi_tcout.set_text("-");
571                 pi_aspect.set_text("-");
572                 pi_fps.set_text("-");
573
574                 clear_preview_image();
575                 return;
576         }
577
578         if ((PREVIEW_WIDTH / (double)PREVIEW_HEIGHT) > video_aspect_ratio ) {
579                 clip_width = MIN(PREVIEW_WIDTH, rint(clip_height * video_aspect_ratio));
580         } else {
581                 clip_height = MIN(PREVIEW_HEIGHT, rint(clip_width / video_aspect_ratio));
582         }
583
584         pi_tcin.set_text(Timecode::timecode_format_sampletime(
585                                 video_start_offset, video_file_fps, video_file_fps, rint(video_file_fps*100.0)==2997));
586         pi_tcout.set_text(Timecode::timecode_format_sampletime(
587                                 video_start_offset + video_duration, video_file_fps, video_file_fps, rint(video_file_fps*100.0)==2997));
588
589         /* todo break out this code -> re-usability */
590         const int arc = rint(video_aspect_ratio*100);
591
592         switch (arc) {
593                 case 100:
594                         pi_aspect.set_text(X_(" 1:1"));  // square (large format stills)
595                         break;
596                 case 125:
597                         pi_aspect.set_text(X_(" 5:4"));
598                         break;
599                 case 133:
600                         pi_aspect.set_text(X_(" 4:3"));
601                         break;
602                 case 134:
603                         pi_aspect.set_text(X_(" 47:35")); // 752x560, Super8-scans
604                         break;
605                 case 137:
606                 case 138:
607                         pi_aspect.set_text(X_(" 1.37:1")); // 'Academy ratio' <= 1953
608                         break;
609                 case 141:
610                         pi_aspect.set_text(X_(" 1.41:1")); //  Lichtenberg ratio
611                         break;
612                 case 150:
613                         pi_aspect.set_text(X_(" 3:2"));  // classic 35mm
614                         break;
615                 case 160:
616                         pi_aspect.set_text(X_(" 8:5"));  // credit-card size
617                         break;
618                 case 162:
619                         pi_aspect.set_text(X_(" 16:10")); // golden ratio 1.61803..
620                         break;
621                 case 166:
622                 case 167:
623                         pi_aspect.set_text(X_(" 5:3")); // Super16, EU-widescreen
624                         break;
625                 case 177:
626                 case 178:
627                         pi_aspect.set_text(X_(" 16:9")); // HD video
628                         break;
629                 case 180:
630                         pi_aspect.set_text(X_(" 9:5"));
631                         break;
632                 case 185:
633                         pi_aspect.set_text(X_(" 1.85:1")); // US widescreen cinema
634                         break;
635                 case 200:
636                         pi_aspect.set_text(X_(" 2:1"));
637                         break;
638                 case 239:
639                 case 240:
640                         pi_aspect.set_text(X_(" 2.40:1")); // Anamorphic
641                         break;
642                 case 266:
643                 case 267:
644                         pi_aspect.set_text(X_(" 2.66:1")); // CinemaScope
645                         break;
646                 case 275:
647                         pi_aspect.set_text(X_(" 2.75:1")); // Ultra Panavision
648                         break;
649                 case 400:
650                         pi_aspect.set_text(X_(" 4.00:1")); // three 35mm 1.33:1 polyvision
651                         break;
652                 default:
653                         pi_aspect.set_text(string_compose(X_(" %1:1"), video_aspect_ratio));
654                 break;
655         }
656
657         pi_fps.set_text(string_compose(_(" %1 fps"), video_file_fps));
658
659         clip_xoff = (PREVIEW_WIDTH - clip_width)/2;
660         clip_yoff = (PREVIEW_HEIGHT - clip_height)/2;
661
662         char url[2048];
663         snprintf(url, sizeof(url), "%s%s?frame=%lli&w=%d&h=%di&file=%s&format=rgb"
664                 , video_server_url.c_str()
665                 , (video_server_url.length()>0 && video_server_url.at(video_server_url.length()-1) == '/')?"":"/"
666                 , (long long) (video_duration * seek_slider.get_value() / 1000.0)
667                 , clip_width, clip_height, u.c_str());
668
669         char *data = a3_curl_http_get(url, NULL);
670         if (!data) {
671                 printf("image preview request failed %s\n", url);
672                 imgbuf->fill(RGBA_TO_UINT(0,0,0,255));
673                 video_draw_cross(imgbuf);
674                 preview_path = "";
675         } else {
676                 Glib::RefPtr<Gdk::Pixbuf> tmp;
677                 tmp = Gdk::Pixbuf::create_from_data ((guint8*) data, Gdk::COLORSPACE_RGB, false, 8, clip_width, clip_height, clip_width*3);
678                 if (clip_width != PREVIEW_WIDTH || clip_height != PREVIEW_HEIGHT) {
679                         imgbuf->fill(RGBA_TO_UINT(0,0,0,255));
680                 }
681                 tmp->copy_area (0, 0, clip_width, clip_height, imgbuf, clip_xoff, clip_yoff);
682                 preview_path = u;
683                 free(data);
684         }
685         preview_image->set(imgbuf);
686         preview_image->show();
687 }