24 #include <curl/curl.h>
33 #include "gtk2ardour-version.h"
36 #ifndef ARDOUR_CURL_TIMEOUT
37 #define ARDOUR_CURL_TIMEOUT (60)
53 const char ds = G_DIR_SEPARATOR;
54 while((found_here = docroot.find(
'/', look_here)) != string::npos) {
55 docroot.replace(found_here, 1, std::string(&ds, 1));
56 look_here = found_here + 1;
59 if (!docroot.empty() && docroot.compare(0, docroot.length(), outfn, 0, docroot.length())) {
60 ArdourDialog confirm (
_(
"Destination is outside Video Server's docroot. "),
true);
61 Label m (
_(
"The destination file path is outside of the Video Server's docroot. The file will not be readable by the Video Server. Do you still want to continue?"));
62 confirm.get_vbox()->pack_start (m,
true,
true);
63 confirm.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
64 confirm.add_button (
_(
"Continue"), Gtk::RESPONSE_ACCEPT);
66 if (confirm.run() == RESPONSE_CANCEL) {
return false; }
69 if (Glib::file_test(outfn, Glib::FILE_TEST_EXISTS)) {
71 Label m (
_(
"A file with the same name already exists. Do you want to overwrite it?"));
72 confirm.get_vbox()->pack_start (m,
true,
true);
73 confirm.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
74 confirm.add_button (
_(
"Overwrite"), Gtk::RESPONSE_ACCEPT);
76 if (confirm.run() == RESPONSE_CANCEL) {
return false; }
79 std::string dir = Glib::path_get_dirname (outfn);
80 if (g_mkdir_with_parents (dir.c_str(), 0755) < 0) {
90 std::string dir = docroot;
91 if (dir.empty() || !dir.compare(0, dir.length(), sessiondir, 0, dir.length())) {
94 if ((dir.empty() || dir.at(dir.length()-1) != G_DIR_SEPARATOR)) { dir += G_DIR_SEPARATOR; }
96 if (g_mkdir_with_parents (dir.c_str(), 0755) < 0) {
105 if (config->get_video_advanced_setup()) {
106 return config->get_video_server_docroot();
108 #ifndef PLATFORM_WINDOWS
118 if (config->get_video_advanced_setup()) {
119 return config->get_video_server_url();
121 return X_(
"http://localhost:1554");
129 char *ext, *bn = strdup(infile.c_str());
130 if ((ext=strrchr(bn,
'.'))) {
131 if (!strchr(ext, G_DIR_SEPARATOR)) {
135 rv = std::string(bn);
144 char *ext, *bn = strdup(infile.c_str());
145 if ((ext=strrchr(bn,
'.'))) {
146 if (!strchr(ext, G_DIR_SEPARATOR)) {
147 rv=std::string(ext+1);
157 return Glib::build_filename(dir,
strip_file_extension(Glib::path_get_basename(infile)) +
".avi");
163 std::string rv = filepath;
166 if (server_docroot.length() > 0) {
167 if (rv.compare(0, server_docroot.length(), server_docroot) == 0 ) {
168 rv = rv.substr(server_docroot.length());
173 size_t look_here = 0;
175 while((found_here = rv.find(G_DIR_SEPARATOR, look_here)) != string::npos) {
176 rv.replace(found_here, 1,
"/");
177 look_here = found_here + 1;
182 curl = curl_easy_init();
183 ue = curl_easy_escape(curl, rv.c_str(),rv.length());
185 rv = std::string(ue);
188 curl_easy_cleanup(curl);
200 std::vector<std::string> line;
202 std::string::const_iterator aChar = csv.begin();
203 while (aChar != csv.end()) {
212 if (inQuote ==
true) {
215 line.push_back(field);
222 if (inQuote ==
true) {
225 if (newLine ==
false) {
226 line.push_back(field);
227 lines.push_back(line);
237 field.push_back(*aChar);
244 line.push_back(field);
247 lines.push_back(line);
252 std::string video_server_url,
253 std::string filepath,
254 double &video_file_fps,
255 long long int &video_duration,
256 double &video_start_offset,
257 double &video_aspect_ratio
262 snprintf(url,
sizeof(url),
"%s%sinfo/?file=%s&format=csv"
263 , video_server_url.c_str()
264 , (video_server_url.length()>0 && video_server_url.at(video_server_url.length()-1) ==
'/')?
"":
"/"
271 std::vector<std::vector<std::string> > lines;
275 if (lines.empty() || lines.at(0).empty() || lines.at(0).size() != 6) {
278 if (
atoi(lines.at(0).at(0)) != 1)
return false;
279 video_start_offset = 0.0;
280 video_aspect_ratio =
atof (lines.at(0).at(3));
281 video_file_fps =
atof (lines.at(0).at(4));
282 video_duration =
atoll(lines.at(0).at(5));
290 int rowstride = img->get_rowstride();
291 int n_channels = img->get_n_channels();
293 pixels = img->get_pixels();
296 int clip_width = img->get_width();
297 int clip_height = img->get_height();
299 for (x=0;x<clip_width;x++) {
300 y = clip_height * x / clip_width;
301 p = pixels + y * rowstride + x * n_channels;
302 p[0] = 192; p[1] = 192; p[2] = 192;
303 if (n_channels>3) p[3] = 255;
304 p = pixels + y * rowstride + (clip_width-x-1) * n_channels;
305 p[0] = 192; p[1] = 192; p[2] = 192;
306 if (n_channels>3) p[3] = 255;
312 #include <curl/curl.h>
321 size_t realsize = size * nmemb;
324 mem->
data = (
char *)realloc(mem->
data, mem->
size + realsize + 1);
326 memcpy(&(mem->
data[mem->
size]), ptr, realsize);
327 mem->
size += realsize;
338 if (status) *status = 0;
340 if (strncmp(
"http://", u, 7))
return NULL;
345 curl = curl_easy_init();
346 if(!curl)
return NULL;
347 curl_easy_setopt(curl, CURLOPT_URL, u);
349 curl_easy_setopt(curl, CURLOPT_WRITEDATA, (
void *)&chunk);
351 curl_easy_setopt(curl, CURLOPT_USERAGENT, PROGRAM_NAME VERSIONSTRING);
353 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
354 #ifdef CURLERRORDEBUG
355 char curlerror[CURL_ERROR_SIZE] =
"";
356 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curlerror);
359 res = curl_easy_perform(curl);
360 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpstatus);
361 curl_easy_cleanup(curl);
362 if (status) *status = httpstatus;
364 #ifdef CURLERRORDEBUG
365 printf(
"a3_curl_http_get() failed: %s\n", curlerror);
369 if (httpstatus != 200) {
std::string video_get_docroot(ARDOUR::RCConfiguration *config)
int atoi(const string &s)
bool video_query_info(std::string video_server_url, std::string filepath, double &video_file_fps, long long int &video_duration, double &video_start_offset, double &video_aspect_ratio)
void video_draw_cross(Glib::RefPtr< Gdk::Pixbuf > img)
std::string video_dest_file(const std::string, const std::string)
int64_t atoll(const string &s)
char * a3_curl_http_get(const char *u, int *status)
static size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)
std::string strip_file_extension(const std::string infile)
void ParseCSV(const std::string &csv, std::vector< std::vector< std::string > > &lines)
LIBPBD_API Transmitter error
std::ostream & endmsg(std::ostream &ostr)
#define ARDOUR_CURL_TIMEOUT
std::string video_map_path(std::string server_docroot, std::string filepath)
bool confirm_video_outfn(std::string, std::string docroot="")
common functions used for video-file im/export
std::string video_dest_dir(const std::string, const std::string)
std::string video_get_server_url(ARDOUR::RCConfiguration *config)
std::string get_file_extension(const std::string infile)
std::string string_compose(const std::string &fmt, const T1 &o1)
double atof(const string &s)