/* this parses a name-value pair of npt:xxx, smpte:xxx etc. */ double cmml_sec_parse (const char * str) { char timespec[16]; if (str == NULL) return -1.0; if (sscanf (str, "npt:%16s", timespec) == 1) { return parse_npt (str+4); /* could be longer than 16 :) */ } if (sscanf (str, "smpte-24:%16s", timespec) == 1) { return parse_smpte (str+9, 24.0); } if (sscanf (str, "smpte-24-drop:%16s", timespec) == 1) { return parse_smpte (str+14, 23.976); } if (sscanf (str, "smpte-25:%16s", timespec) == 1) { return parse_smpte (str+9, 25.0); } if (sscanf (str, "smpte-30:%16s", timespec) == 1) { return parse_smpte (str+9, 30.0); } if (sscanf (str, "smpte-30-drop:%16s", timespec) == 1) { return parse_smpte (str+14, 29.97); } if (sscanf (str, "smpte-50:%16s", timespec) == 1) { return parse_smpte (str+9, 50.0); } if (sscanf (str, "smpte-60:%16s", timespec) == 1) { return parse_smpte (str+9, 60); } if (sscanf (str, "smpte-60-drop:%16s", timespec) == 1) { return parse_smpte (str+14, 59.94); } /* default is npt */ return parse_npt(str); }
double anx_parse_time (const char * str) { char timespec[16]; if (str == NULL) return -1.0; if (sscanf (str, "npt:%16s", timespec) == 1) { return parse_npt (timespec); } if (sscanf (str, "smpte-24:%16s", timespec) == 1) { return parse_smpte (timespec, 24.0); } if (sscanf (str, "smpte-24-drop:%16s", timespec) == 1) { return parse_smpte (timespec, 23.976); } if (sscanf (str, "smpte-25:%16s", timespec) == 1) { return parse_smpte (timespec, 25.0); } if (sscanf (str, "smpte-30:%16s", timespec) == 1) { return parse_smpte (timespec, 30.0); } if (sscanf (str, "smpte-30-drop:%16s", timespec) == 1) { return parse_smpte (timespec, 29.97); } if (sscanf (str, "smpte-50:%16s", timespec) == 1) { return parse_smpte (timespec, 50.0); } if (sscanf (str, "smpte-60:%16s", timespec) == 1) { return parse_smpte (timespec, 60); } if (sscanf (str, "smpte-60-drop:%16s", timespec) == 1) { return parse_smpte (timespec, 59.94); } return parse_npt(str); }
/* creates two time constructs if the string was a time range, otherwise just a t_start time, and returns the number of times created; examples: npt:40,79 or smpte-25:00:20:20,00:21:30 */ int cmml_time_interval_new (const char * s, CMML_Time ** t_start, CMML_Time ** t_end) { char * after_scheme = NULL; char * pos = NULL; char * start_time = NULL; int len_start_time = 0; double seconds = -1.0; if (s == NULL) return -1; after_scheme = strchr(s, ':'); if (after_scheme == NULL) after_scheme = (char *) s; if ((pos=strchr(after_scheme, ',')) == NULL) { /* it's just a time point */ *t_end = NULL; *t_start = cmml_time_new(s); #ifdef DEBUG fprintf(stderr, "start time %f\n", (*t_start)->t.sec); #endif return 1; } else { /* it's a time range */ len_start_time = (int)(strlen(s) - strlen(pos)); start_time = (char *) cmml_malloc(len_start_time+1); start_time = strncpy (start_time, s, len_start_time); start_time[len_start_time]='\0'; *t_start = cmml_time_new(start_time); if ((*t_start)->type == CMML_UTC_TIME) { *t_end = cmml_utc_new(pos+1); } else { /* Find out what type the timestamp is and parse appropriately */ if (strncmp(s, "smpte-24", 8) == 0) { seconds = parse_smpte(pos+1, 24.0); } else if (strncmp(s, "smpte-24-drop", 13) == 0) { seconds = parse_smpte(pos+1, 23.976); } else if (strncmp(s, "smpte-25", 8) == 0) { seconds = parse_smpte(pos+1, 25.0); } else if (strncmp(s, "smpte-30", 8) == 0) { seconds = parse_smpte(pos+1, 30.0); } else if (strncmp(s, "smpte-30-drop", 13) == 0) { seconds = parse_smpte(pos+1, 29.97); } else if (strncmp(s, "smpte-50", 8) == 0) { seconds = parse_smpte(pos+1, 50.0); } else if (strncmp(s, "smpte-60", 8) == 0) { seconds = parse_smpte(pos+1, 60.0); } else if (strncmp(s, "smpte-60-drop", 13) == 0) { seconds = parse_smpte(pos+1, 59.94); } else { /* default is npt */ *t_end = cmml_time_new(pos+1); } /* create t_end for the smpte timecodes */ if (seconds > 0) { *t_end = (CMML_Time *) cmml_malloc(sizeof(CMML_Time)); (*t_end)->tstr = cmml_strdup(pos+1); (*t_end)->type = CMML_SEC_TIME; (*t_end)->t.sec = seconds; } } return 2; } return -1; }