int transcode(const char *path) { int ret; //if the file is a ts file ret = judge_file_suffix(path); //0, the file is not a ts file if (!ret) return 0; ret = if_file_exist(path); // -1 error; 0 not exist; 1 exist; if (ret == -1) return -1; else if (ret == 0) { TransTask task; ret = get_name_info(path, &task); //get the information from the file name. if (ret == -1) { servlog(ERROR, "can't get the info from file name:%s", path); return -1; } servlog(INFO, "task->file_name:%s", task.file_name); if(trans_file(&task, path)) servlog(INFO, "transcode the file success:%s", path); else { servlog(ERROR, "fail to transcode the file:%s", path); return -1; } } return 0; }
int main(int argc, char *argv[]) { int ret; //create the log creatlogfile(); servlog(INFO, "%s", "fsys start"); struct fuse_args args = FUSE_ARGS_INIT(argc, argv); if (fuse_opt_parse(&args, ¶ms, fsys_opts, fsys_opt_proc)) { fprintf(stderr, "Error parsing options.\n\n"); usage(argv[0]); return 1; } if (!params.basepath) { fprintf(stderr, "No valid flacdir specified.\n\n"); usage(argv[0]); return 1; } if (params.basepath[0] != '/') { fprintf(stderr, "flacdir must be an absolute path.\n\n"); usage(argv[0]); return 1; } struct stat st; if (stat(params.basepath, &st) != 0 || !S_ISDIR(st.st_mode)) { fprintf(stderr, "flacdir is not a valid directory: %s\n", params.basepath); fprintf(stderr, "Hint: Did you specify bitrate using the old " "syntax instead of the new -b?\n\n"); usage(argv[0]); return 1; } /* Log to the screen if debug is enabled. */ openlog("fsys", params.debug ? LOG_PERROR : 0, LOG_USER); servlog(INFO, "FSYS options:basepath->%s", params.basepath); // start FUSE umask(0); ret = fuse_main(args.argc, args.argv, &fsys_ops, NULL); fuse_opt_free_args(&args); servlog(INFO, "%s", "fsys have quited out"); closelog(); return ret; }
void serv_proc(int fd){ char buf[MAXLINE]; Req_header header; char delims[] = "/"; char *result = NULL; readline(fd, buf, MAXLINE); #ifdef DEBUG fprintf(stderr, "%s", buf); #endif parse_request(buf, &header); memset(buf, 0, MAXLINE); strcpy(buf, header.locator); result = strtok(buf, delims); if (strcmp(result, "cgi-bin") == 0) { cgi_handle(fd, &header); } else { http_respond(fd, &header); } servlog(LOG_INFO, "[client:%s][%s] %d\n", "192.168.1.1", "GET /index.html HTTP/1.1", 200); }
static int fsys_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { char* origpath; int fd; int read = 0; servlog(INFO, "read %s: %zu bytes from %jd", path, size, offset); errno = 0; origpath = translate_path(path); servlog(INFO, "the original file is %s\n", origpath); if (!origpath) return -errno; transcode(origpath); /* If this is a real file, pass the call through. */ fd = open(origpath, O_RDONLY); if (fd != -1) { read = pread(fd, buf, size, offset); close(fd); free(origpath); if (read) return read; else return -errno; } /* File does exist, but can't be opened. */ if (fd == -1 && errno != ENOENT) { free(origpath); return -errno; } free(origpath); return -errno; }
int get_name_info(const char *path, TransTask* task) { char Param[4][100] = {0}; int len = strlen(path); while (--len >= 0) if (path[len] == '/') break; if (len < 0) return -1; unsigned int i; unsigned int j = 0; unsigned int index = 0; for (i = ++len; i < strlen(path); i++) { if (path[i] != '_' && path[i] != '.' && path[i] != '-') { Param[index][j] = path[i]; j++; } else { Param[index][j] = '\0'; servlog(INFO, "file name param:%s", Param[index]); index++; j = 0; if (index == 4 && path[i] == '.') break; } } if (index == 4) { strcpy(task -> width, Param[1]); // width strcpy(task -> height, Param[2]); // height strcpy(task -> bitrate, Param[3]); // bitrate strcpy(task->file_name, Param[0]); // the file name of the original ts file return 0; } return -1; }
int trans_file(TransTask* task, const char* path) { char new_ts[200] = {0}; char original_ts[200] = {0}; strcpy(original_ts, "/home/guanyu/Public/china/"); strcat(original_ts, task->file_name); strcat(original_ts, ".ts"); char cmd[300] = {0}; strcpy(cmd, "ffmpeg -i "); strcat(cmd, original_ts); strcat(cmd, " -qscale 0 -acodec copy "); strcat(cmd, " -s "); strcat(cmd, task->width); strcat(cmd, "x"); strcat(cmd, task->height); strcat(cmd, " "); strcat(cmd, path); servlog(INFO, "command:%s", cmd); system(cmd); return 1; }