X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Futils_videotl.cc;h=b6eace7675e28d9f13065b0d03c954a0f514feb8;hb=4a60c277dbf28b5fd371a04e5d7ca3d7b8df669f;hp=0c94f378f02bfa9ac3376cfc2d3507a252af1de7;hpb=2c4e79d0a087ab1aafb5aa53ce0e88c3b74220bc;p=ardour.git diff --git a/gtk2_ardour/utils_videotl.cc b/gtk2_ardour/utils_videotl.cc index 0c94f378f0..b6eace7675 100644 --- a/gtk2_ardour/utils_videotl.cc +++ b/gtk2_ardour/utils_videotl.cc @@ -21,14 +21,17 @@ #include #include #include -#include #include "pbd/error.h" +#include "pbd/string_convert.h" + #include "ardour/ardour.h" #include "ardour/session_directory.h" -#include "video_image_frame.h" -#include "utils_videotl.h" + +#include "ardour_http.h" #include "utils.h" +#include "utils_videotl.h" +#include "video_image_frame.h" #ifdef WAF_BUILD #include "gtk2ardour-version.h" @@ -37,7 +40,7 @@ #ifndef ARDOUR_CURL_TIMEOUT #define ARDOUR_CURL_TIMEOUT (60) #endif -#include "i18n.h" +#include "pbd/i18n.h" using namespace Gtk; using namespace std; @@ -45,8 +48,10 @@ using namespace PBD; using namespace ARDOUR; using namespace VideoUtils; +unsigned int VideoUtils::harvid_version = 0x0; + bool -VideoUtils::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; @@ -68,7 +73,8 @@ VideoUtils::confirm_video_outfn (std::string outfn, std::string docroot) } if (Glib::file_test(outfn, Glib::FILE_TEST_EXISTS)) { - bool overwrite = ARDOUR_UI_UTILS::overwrite_file_dialog (_("Confirm Overwrite"), + 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) { @@ -108,7 +114,11 @@ VideoUtils::video_get_docroot (ARDOUR::RCConfiguration* config) #ifndef PLATFORM_WINDOWS return X_("/"); #else - return X_("C:\\"); + if (harvid_version >= 0x000802) { // 0.8.2 + return X_(""); + } else { + return X_("C:\\"); + } #endif } @@ -263,23 +273,28 @@ VideoUtils::video_query_info ( , video_server_url.c_str() , (video_server_url.length()>0 && video_server_url.at(video_server_url.length()-1) == '/')?"":"/" , filepath.c_str()); - char *res = a3_curl_http_get(url, NULL); - if (!res) { + std::string res = ArdourCurl::http_get (url); + if (res.empty ()) { return false; } std::vector > lines; - ParseCSV(std::string(res), lines); - free(res); + ParseCSV(res, lines); if (lines.empty() || lines.at(0).empty() || lines.at(0).size() != 6) { return false; } 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)); + video_aspect_ratio = string_to(lines.at(0).at(3)); + video_file_fps = string_to(lines.at(0).at(4)); + video_duration = string_to(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; } @@ -307,70 +322,3 @@ VideoUtils::video_draw_cross (Glib::RefPtr img) } } - -extern "C" { -#include - - struct A3MemoryStruct { - char *data; - size_t size; - }; - - static size_t - WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) { - size_t realsize = size * nmemb; - struct A3MemoryStruct *mem = (struct A3MemoryStruct *)data; - - mem->data = (char *)realloc(mem->data, mem->size + realsize + 1); - if (mem->data) { - memcpy(&(mem->data[mem->size]), ptr, realsize); - mem->size += realsize; - mem->data[mem->size] = 0; - } - return realsize; - } - - char *a3_curl_http_get (const char *u, int *status) { - CURL *curl; - CURLcode res; - struct A3MemoryStruct chunk; - long int httpstatus; - if (status) *status = 0; - //Glib::usleep(500000); return NULL; // TEST & DEBUG - if (strncmp("http://", u, 7)) return NULL; - - chunk.data=NULL; - chunk.size=0; - - curl = curl_easy_init(); - if(!curl) return NULL; - curl_easy_setopt(curl, CURLOPT_URL, u); - - curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); - curl_easy_setopt(curl, CURLOPT_USERAGENT, PROGRAM_NAME VERSIONSTRING); - curl_easy_setopt(curl, CURLOPT_TIMEOUT, ARDOUR_CURL_TIMEOUT); - curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); -#ifdef CURLERRORDEBUG - char curlerror[CURL_ERROR_SIZE] = ""; - curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curlerror); -#endif - - res = curl_easy_perform(curl); - curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpstatus); - curl_easy_cleanup(curl); - if (status) *status = httpstatus; - if (res) { -#ifdef CURLERRORDEBUG - printf("a3_curl_http_get() failed: %s\n", curlerror); -#endif - return NULL; - } - if (httpstatus != 200) { - free (chunk.data); - chunk.data = NULL; - } - return (chunk.data); - } - -} /* end extern "C" */