diff --git a/gtk2_ardour/utils_videotl.cc b/gtk2_ardour/utils_videotl.cc index b90abf7fb8..504fc3d2eb 100644 --- a/gtk2_ardour/utils_videotl.cc +++ b/gtk2_ardour/utils_videotl.cc @@ -314,3 +314,71 @@ video_draw_cross (Glib::RefPtr img) if (n_channels>3) p[3] = 255; } } + + +extern "C" { +#include + + struct MemoryStruct { + 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 MemoryStruct *mem = (struct MemoryStruct *)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 *curl_http_get (const char *u, int *status) { + CURL *curl; + CURLcode res; + struct MemoryStruct chunk; + long int httpstatus; + if (status) *status = 0; + //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, ARDOUR_USER_AGENT); + 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("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" */ diff --git a/gtk2_ardour/utils_videotl.h b/gtk2_ardour/utils_videotl.h index 913af2ab55..89daadc40e 100644 --- a/gtk2_ardour/utils_videotl.h +++ b/gtk2_ardour/utils_videotl.h @@ -53,4 +53,8 @@ bool video_query_info ( double &video_aspect_ratio ); +extern "C" { + char *curl_http_get (const char *u, int *status); +} + #endif /* __gtk_ardour_video_utils_h__ */ diff --git a/gtk2_ardour/video_image_frame.cc b/gtk2_ardour/video_image_frame.cc index 46fd64413d..3c39dea77b 100644 --- a/gtk2_ardour/video_image_frame.cc +++ b/gtk2_ardour/video_image_frame.cc @@ -301,70 +301,3 @@ VideoImageFrame::http_get_again(framepos_t /*fn*/) { http_get_thread(this); } - -extern "C" { -#include - - struct MemoryStruct { - 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 MemoryStruct *mem = (struct MemoryStruct *)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 *curl_http_get (const char *u, int *status) { - CURL *curl; - CURLcode res; - struct MemoryStruct chunk; - long int httpstatus; - if (status) *status = 0; - //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, ARDOUR_USER_AGENT); - 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("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" */ diff --git a/gtk2_ardour/video_image_frame.h b/gtk2_ardour/video_image_frame.h index feeab37039..b6d45dbe6d 100644 --- a/gtk2_ardour/video_image_frame.h +++ b/gtk2_ardour/video_image_frame.h @@ -105,8 +105,4 @@ class VideoImageFrame : public sigc::trackable }; -extern "C" { - char *curl_http_get (const char *u, int *status); -} - #endif /* __ardour_video_image_frame_h__ */