static gboolean _gst_gl_download_perform_with_data_unlocked (GstGLDownload * download, GLuint texture_id, gpointer data[GST_VIDEO_MAX_PLANES]) { guint i; g_return_val_if_fail (download != NULL, FALSE); g_return_val_if_fail (texture_id > 0, FALSE); g_return_val_if_fail (GST_VIDEO_INFO_FORMAT (&download->info) != GST_VIDEO_FORMAT_UNKNOWN && GST_VIDEO_INFO_FORMAT (&download->info) != GST_VIDEO_FORMAT_ENCODED, FALSE); for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&download->info); i++) { g_return_val_if_fail (data[i] != NULL, FALSE); } if (!download->priv->in_tex[0]) download->priv->in_tex[0] = gst_gl_memory_wrapped_texture (download->context, texture_id, GST_VIDEO_GL_TEXTURE_TYPE_RGBA, GST_VIDEO_INFO_WIDTH (&download->info), GST_VIDEO_INFO_HEIGHT (&download->info), NULL, NULL); download->priv->in_tex[0]->tex_id = texture_id; return _do_download (download, texture_id, data); }
int do_download(const char *remote_path, const char *local_path, int overwrite, /* 是否覆盖 */ int create_new /* 是否新建 */ ) { //{{{ int ret = 0; int stdout_output = 0; PCSFile *file = NULL; /* 需要释放 */ PCSFile *t_file = NULL; const char *error = NULL; int remote_root_offset = 0; char *tmp; char t_local_root[PATH_MAX + 1]; char t_local_file[PATH_MAX + 1]; PCSFileList *stack = NULL; /* 需要释放 */ PCSFileList *list = NULL; /* 需要释放 */ /* 获取远程路径信息 */ file = BaiduPCS_NewRemoteFile(api, remote_path); error = BaiduPCS_GetError(api); if (error != NULL || file == NULL) { color_log(COLOR_LOG_ERROR, "%s 获取文件信息失败:%s\n", remote_path, error); ret = 1; goto free; } stdout_output = strcmp(local_path, "-") == 0; sprintf(t_local_file, "%s", local_path); /* 保存路径修正 */ if (!stdout_output) { /* 远端为目录 */ if (file->is_dir) { sprintf(t_local_root, "%s", local_path); remote_root_offset = strlen(file->path); if (stat(local_path, &(api->file_st)) != -1) { if (S_ISDIR(api->file_st.st_mode)){ t_local_root[0] = '\0'; strcat(t_local_root, local_path); strcat(t_local_root, "/"); strcat(t_local_root, basename(file->path)); #ifdef DEBUG fprintf(stderr, "本地根目录修正为:%s\n", t_local_root); #endif } else { color_log(COLOR_LOG_ERROR, "%s -> %s 本地已存与目录同名的文件\n", file->path, local_path); ret = 1; goto free; } } } else { if (stat(local_path, &(api->file_st)) != -1) { if (S_ISDIR(api->file_st.st_mode)){ sprintf(t_local_file, "%s/%s", local_path, basename(file->path)); } } } } /* 下载单个文件 */ if (!file->is_dir) { ret = _do_download(remote_path, t_local_file, overwrite, create_new); } else { stack = PCSFileList_New(); while(file != NULL) { tmp = file->path + remote_root_offset; sprintf(t_local_file, "%s%s", t_local_root, tmp); /* 如果是普通文件 */ if (!file->is_dir) { #ifdef DEBUG PCSFile_Dump(file); #endif _do_download(file->path, t_local_file, overwrite, create_new); PCSFile_Free(file); file = PCSFileList_Shift(stack); /* 如果是目录 */ } else { /* 创建本地目录 */ if (stat(t_local_file, &(api->file_st)) != -1) { if (!S_ISDIR(api->file_st.st_mode)){ color_log(COLOR_LOG_ERROR, "%s -> %s 本地已存与目录同名的文件\n", file->path, t_local_file); ret = 1; goto free; } } else { if (0 != mkdir(t_local_file, 0755)) { color_log(COLOR_LOG_ERROR, "%s -> %s 本地目录创建失败\n", file->path, t_local_file); ret = 1; goto free; } } list = BaiduPCS_ListRemoteDir(api, file->path); error = BaiduPCS_GetError(api); if (error != NULL || list == NULL) { color_log(COLOR_LOG_ERROR, "%s 获取目录列表失败:%s\n", file->path, error); } /* 列出目录 */ if (list != NULL) { t_file = PCSFileList_Shift(list); while(t_file != NULL) { PCSFileList_Prepend(stack, t_file); t_file = PCSFileList_Shift(list); } PCSFileList_Free(list); list = NULL; } PCSFile_Free(file); file = PCSFileList_Shift(stack); } } } free: if (file != NULL) { PCSFile_Free(file); } if (stack != NULL) { PCSFileList_Free(stack); } if (list != NULL) { PCSFileList_Free(list); } return ret; }
int channel_update(channel *c, void *user_data, channel_callback cb, int no_download, int no_mark_read, int first_only, int resume, enclosure_filter *filter, int debug, int show_progress_bar) { int i, download_failed; rss_file *f; /* Retrieve the RSS file. */ f = _get_rss(c, user_data, cb, debug); if (!f) return 1; /* Check enclosures in RSS file. */ for (i = 0; i < f->num_items; i++) if (f->items[i]->enclosure) { if (!g_hash_table_lookup_extended(c->downloaded_enclosures, f->items[i]->enclosure->url, NULL, NULL)) { rss_item *item; item = f->items[i]; if (!filter || _enclosure_pattern_match(filter, item->enclosure)) { if (no_download) download_failed = _do_catchup(c, &(f->channel_info), item, user_data, cb); else download_failed = _do_download(c, &(f->channel_info), item, user_data, cb, resume, debug, show_progress_bar); if (download_failed) break; if (!no_mark_read) { /* Mark enclosure as downloaded and immediately save channel file to ensure that it reflects the change. */ g_hash_table_insert(c->downloaded_enclosures, f->items[i]->enclosure->url, (gpointer)get_rfc822_time()); _cast_channel_save(c, debug); } /* If we have been instructed to deal only with the first available enclosure, it is time to break out of the loop. */ if (first_only) break; } } } if (!no_mark_read) { /* Update the RSS last fetched time and save the channel file again. */ if (c->rss_last_fetched) g_free(c->rss_last_fetched); c->rss_last_fetched = g_strdup(f->fetched_time); _cast_channel_save(c, debug); } rss_close(f); return 0; }