X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Futils_videotl.cc;h=d2bec87d9eba7b75950dc64ca28eae8f80233d13;hb=444b9e89033aa4171254a3622c583e1d791c7e9f;hp=adf7d25640682414e45a2c87cff0e9f15fe07374;hpb=0c3e840700a915fc1476cef73c591048f688f81e;p=ardour.git diff --git a/gtk2_ardour/utils_videotl.cc b/gtk2_ardour/utils_videotl.cc index adf7d25640..d2bec87d9e 100644 --- a/gtk2_ardour/utils_videotl.cc +++ b/gtk2_ardour/utils_videotl.cc @@ -17,29 +17,38 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifdef WITH_VIDEOTIMELINE - #include #include #include #include -#include #include "pbd/error.h" + #include "ardour/ardour.h" #include "ardour/session_directory.h" -#include "ardour_dialog.h" + +#include "ardour_http.h" +#include "utils.h" +#include "utils_videotl.h" #include "video_image_frame.h" -#include "i18n.h" +#ifdef WAF_BUILD +#include "gtk2ardour-version.h" +#endif + +#ifndef ARDOUR_CURL_TIMEOUT +#define ARDOUR_CURL_TIMEOUT (60) +#endif +#include "pbd/i18n.h" using namespace Gtk; using namespace std; using namespace PBD; using namespace ARDOUR; +using namespace VideoUtils; bool -confirm_video_outfn (std::string outfn, std::string docroot) +VideoUtils::confirm_video_outfn (Gtk::Window& parent, std::string outfn, std::string docroot) { /* replace docroot's '/' to G_DIR_SEPARATOR for the comparison */ size_t look_here = 0; @@ -61,13 +70,13 @@ confirm_video_outfn (std::string outfn, std::string docroot) } if (Glib::file_test(outfn, Glib::FILE_TEST_EXISTS)) { - ArdourDialog confirm (_("Confirm Overwrite"), true); - Label m (_("A file with the same name already exists. Do you want to overwrite it?")); - confirm.get_vbox()->pack_start (m, true, true); - confirm.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - confirm.add_button (_("Overwrite"), Gtk::RESPONSE_ACCEPT); - confirm.show_all (); - if (confirm.run() == RESPONSE_CANCEL) { return false; } + bool overwrite = ARDOUR_UI_UTILS::overwrite_file_dialog (parent, + _("Confirm Overwrite"), + _("A file with the same name already exists. Do you want to overwrite it?")); + + if (!overwrite) { + return false; + } } std::string dir = Glib::path_get_dirname (outfn); @@ -79,7 +88,7 @@ confirm_video_outfn (std::string outfn, std::string docroot) } std::string -video_dest_dir (const std::string sessiondir, const std::string docroot) +VideoUtils::video_dest_dir (const std::string sessiondir, const std::string docroot) { std::string dir = docroot; if (dir.empty() || !dir.compare(0, dir.length(), sessiondir, 0, dir.length())) { @@ -94,7 +103,30 @@ video_dest_dir (const std::string sessiondir, const std::string docroot) } std::string -strip_file_extension (const std::string infile) +VideoUtils::video_get_docroot (ARDOUR::RCConfiguration* config) +{ + if (config->get_video_advanced_setup()) { + return config->get_video_server_docroot(); + } +#ifndef PLATFORM_WINDOWS + return X_("/"); +#else + return X_("C:\\"); +#endif +} + +std::string +VideoUtils::video_get_server_url (ARDOUR::RCConfiguration* config) +{ + if (config->get_video_advanced_setup()) { + return config->get_video_server_url(); + } + return X_("http://127.0.0.1:1554"); +} + + +std::string +VideoUtils::strip_file_extension (const std::string infile) { std::string rv; char *ext, *bn = strdup(infile.c_str()); @@ -109,7 +141,7 @@ strip_file_extension (const std::string infile) } std::string -get_file_extension (const std::string infile) +VideoUtils::get_file_extension (const std::string infile) { std::string rv = ""; char *ext, *bn = strdup(infile.c_str()); @@ -123,16 +155,23 @@ get_file_extension (const std::string infile) } std::string -video_dest_file (const std::string dir, const std::string infile) +VideoUtils::video_dest_file (const std::string dir, const std::string infile) { - return dir + "a3_" + strip_file_extension(Glib::path_get_basename(infile)) + ".avi"; + return Glib::build_filename(dir, strip_file_extension(Glib::path_get_basename(infile)) + ".avi"); } std::string -video_map_path (std::string server_docroot, std::string filepath) +VideoUtils::video_map_path (std::string server_docroot, std::string filepath) { std::string rv = filepath; + /* strip docroot */ + if (server_docroot.length() > 0) { + if (rv.compare(0, server_docroot.length(), server_docroot) == 0 ) { + rv = rv.substr(server_docroot.length()); + } + } + /* replace all G_DIR_SEPARATOR with '/' */ size_t look_here = 0; size_t found_here; @@ -141,13 +180,6 @@ video_map_path (std::string server_docroot, std::string filepath) look_here = found_here + 1; } - /* strip docroot */ - if (server_docroot.length() > 0) { - if (rv.compare(0, server_docroot.length(), server_docroot) == 0 ) { - rv = rv.substr(server_docroot.length()); - } - } - CURL *curl; char *ue; curl = curl_easy_init(); @@ -162,7 +194,7 @@ video_map_path (std::string server_docroot, std::string filepath) } void -ParseCSV (const std::string &csv, std::vector > &lines) +VideoUtils::ParseCSV (const std::string &csv, std::vector > &lines) { bool inQuote(false); bool newLine(false); @@ -219,7 +251,7 @@ ParseCSV (const std::string &csv, std::vector > &lines) } bool -video_query_info ( +VideoUtils::video_query_info ( std::string video_server_url, std::string filepath, double &video_file_fps, @@ -228,54 +260,40 @@ video_query_info ( double &video_aspect_ratio ) { + LocaleGuard lg; char url[2048]; - snprintf(url, sizeof(url), "%s%sinfo/?file=%s&format=plain" + snprintf(url, sizeof(url), "%s%sinfo/?file=%s&format=csv" , video_server_url.c_str() , (video_server_url.length()>0 && video_server_url.at(video_server_url.length()-1) == '/')?"":"/" , filepath.c_str()); - char *res = curl_http_get(url, NULL); - int pid=0; - if (res) { - char *pch, *pst; - int version; - pch = strtok_r(res, "\n", &pst); - while (pch) { -#if 0 /* DEBUG */ - printf("VideoFileInfo [%i] -> '%s'\n", pid, pch); -#endif - switch (pid) { - case 0: - version = atoi(pch); - if (version != 1) break; - case 1: - video_file_fps = atof(pch); - break; - case 2: - video_duration = atoll(pch); - break; - case 3: - video_start_offset = atof(pch); - break; - case 4: - video_aspect_ratio = atof(pch); - break; - default: - break; - } - pch = strtok_r(NULL,"\n", &pst); - ++pid; - } - free(res); + std::string res = ArdourCurl::http_get (url); + if (res.empty ()) { + return false; + } + + std::vector > lines; + ParseCSV(res, lines); + + if (lines.empty() || lines.at(0).empty() || lines.at(0).size() != 6) { + return false; } - if (pid!=5) { + if (atoi(lines.at(0).at(0)) != 1) return false; // version + video_start_offset = 0.0; + video_aspect_ratio = atof (lines.at(0).at(3)); + video_file_fps = atof (lines.at(0).at(4)); + video_duration = atoll(lines.at(0).at(5)); + + if (video_aspect_ratio < 0.01 || video_file_fps < 0.01) { + /* catch errors early, aspect == 0 or fps == 0 will + * wreak havoc down the road */ return false; } return true; } void -video_draw_cross (Glib::RefPtr img) +VideoUtils::video_draw_cross (Glib::RefPtr img) { int rowstride = img->get_rowstride(); @@ -298,4 +316,3 @@ video_draw_cross (Glib::RefPtr img) } } -#endif /* WITH_VIDEOTIMELINE */