2 Copyright (C) 2010-2013 Paul Davis
3 Author: Robin Gareus <robin@gareus.org>
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.
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.
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.
20 #ifdef WITH_VIDEOTIMELINE
26 #include <curl/curl.h>
28 #include "pbd/error.h"
29 #include "ardour/ardour.h"
30 #include "ardour/session_directory.h"
31 #include "video_image_frame.h"
32 #include "utils_videotl.h"
39 using namespace ARDOUR;
42 confirm_video_outfn (std::string outfn, std::string docroot)
44 /* replace docroot's '/' to G_DIR_SEPARATOR for the comparison */
47 const char ds = G_DIR_SEPARATOR;
48 while((found_here = docroot.find('/', look_here)) != string::npos) {
49 docroot.replace(found_here, 1, std::string(&ds, 1));
50 look_here = found_here + 1;
53 if (!docroot.empty() && docroot.compare(0, docroot.length(), outfn, 0, docroot.length())) {
54 ArdourDialog confirm (_("Destination is outside Video Server's docroot. "), true);
55 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?"));
56 confirm.get_vbox()->pack_start (m, true, true);
57 confirm.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
58 confirm.add_button (_("Continue"), Gtk::RESPONSE_ACCEPT);
60 if (confirm.run() == RESPONSE_CANCEL) { return false; }
63 if (Glib::file_test(outfn, Glib::FILE_TEST_EXISTS)) {
64 ArdourDialog confirm (_("Confirm Overwrite"), true);
65 Label m (_("A file with the same name already exists. Do you want to overwrite it?"));
66 confirm.get_vbox()->pack_start (m, true, true);
67 confirm.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
68 confirm.add_button (_("Overwrite"), Gtk::RESPONSE_ACCEPT);
70 if (confirm.run() == RESPONSE_CANCEL) { return false; }
73 std::string dir = Glib::path_get_dirname (outfn);
74 if (g_mkdir_with_parents (dir.c_str(), 0755) < 0) {
75 error << string_compose(_("Cannot create video folder \"%1\" (%2)"), dir, strerror (errno)) << endmsg;
82 video_dest_dir (const std::string sessiondir, const std::string docroot)
84 std::string dir = docroot;
85 if (dir.empty() || !dir.compare(0, dir.length(), sessiondir, 0, dir.length())) {
88 if ((dir.empty() || dir.at(dir.length()-1) != G_DIR_SEPARATOR)) { dir += G_DIR_SEPARATOR; }
90 if (g_mkdir_with_parents (dir.c_str(), 0755) < 0) {
91 error << string_compose(_("Cannot create video folder \"%1\" (%2)"), dir, strerror (errno)) << endmsg;
97 video_get_docroot (ARDOUR::RCConfiguration* config)
99 if (config->get_video_advanced_setup()) {
100 return config->get_video_server_docroot();
106 video_get_server_url (ARDOUR::RCConfiguration* config)
108 if (config->get_video_advanced_setup()) {
109 return config->get_video_server_url();
111 return X_("http://localhost:1554");
116 strip_file_extension (const std::string infile)
119 char *ext, *bn = strdup(infile.c_str());
120 if ((ext=strrchr(bn, '.'))) {
121 if (!strchr(ext, G_DIR_SEPARATOR)) {
125 rv = std::string(bn);
131 get_file_extension (const std::string infile)
134 char *ext, *bn = strdup(infile.c_str());
135 if ((ext=strrchr(bn, '.'))) {
136 if (!strchr(ext, G_DIR_SEPARATOR)) {
137 rv=std::string(ext+1);
145 video_dest_file (const std::string dir, const std::string infile)
147 return dir + "a3_" + strip_file_extension(Glib::path_get_basename(infile)) + ".avi";
151 video_map_path (std::string server_docroot, std::string filepath)
153 std::string rv = filepath;
155 /* replace all G_DIR_SEPARATOR with '/' */
156 size_t look_here = 0;
158 while((found_here = rv.find(G_DIR_SEPARATOR, look_here)) != string::npos) {
159 rv.replace(found_here, 1, "/");
160 look_here = found_here + 1;
164 if (server_docroot.length() > 0) {
165 if (rv.compare(0, server_docroot.length(), server_docroot) == 0 ) {
166 rv = rv.substr(server_docroot.length());
172 curl = curl_easy_init();
173 ue = curl_easy_escape(curl, rv.c_str(),rv.length());
175 rv = std::string(ue);
178 curl_easy_cleanup(curl);
184 ParseCSV (const std::string &csv, std::vector<std::vector<std::string> > &lines)
190 std::vector<std::string> line;
192 std::string::const_iterator aChar = csv.begin();
193 while (aChar != csv.end()) {
202 if (inQuote == true) {
205 line.push_back(field);
212 if (inQuote == true) {
215 if (newLine == false) {
216 line.push_back(field);
217 lines.push_back(line);
227 field.push_back(*aChar);
234 line.push_back(field);
237 lines.push_back(line);
242 std::string video_server_url,
243 std::string filepath,
244 double &video_file_fps,
245 long long int &video_duration,
246 double &video_start_offset,
247 double &video_aspect_ratio
252 snprintf(url, sizeof(url), "%s%sinfo/?file=%s&format=plain"
253 , video_server_url.c_str()
254 , (video_server_url.length()>0 && video_server_url.at(video_server_url.length()-1) == '/')?"":"/"
256 char *res = curl_http_get(url, NULL);
261 pch = strtok_r(res, "\n", &pst);
264 printf("VideoFileInfo [%i] -> '%s'\n", pid, pch);
269 if (version != 1) break;
271 video_file_fps = atof(pch);
274 video_duration = atoll(pch);
277 video_start_offset = atof(pch);
280 video_aspect_ratio = atof(pch);
285 pch = strtok_r(NULL,"\n", &pst);
297 video_draw_cross (Glib::RefPtr<Gdk::Pixbuf> img)
300 int rowstride = img->get_rowstride();
301 int n_channels = img->get_n_channels();
303 pixels = img->get_pixels();
306 int clip_width = img->get_width();
307 int clip_height = img->get_height();
309 for (x=0;x<clip_width;x++) {
310 y = clip_height * x / clip_width;
311 p = pixels + y * rowstride + x * n_channels;
312 p[0] = 192; p[1] = 192; p[2] = 192;
313 if (n_channels>3) p[3] = 255;
314 p = pixels + y * rowstride + (clip_width-x-1) * n_channels;
315 p[0] = 192; p[1] = 192; p[2] = 192;
316 if (n_channels>3) p[3] = 255;
320 #endif /* WITH_VIDEOTIMELINE */