Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Mayank Gupta 2017-03-15 00:50:34 +05:30
commit 0bc2dbac4a
3 changed files with 8 additions and 51 deletions

View File

@ -252,7 +252,6 @@ bool_t in_array(uint16_t *array, uint16_t length, uint16_t element) ;
int hex_to_int (char high, char low);
int hex_string_to_int(char* string, int len);
void timestamp_to_srttime(uint64_t timestamp, char *buffer);
void timestamp_to_smptetttime(uint64_t timestamp, char *buffer);
int levenshtein_dist (const uint64_t *s1, const uint64_t *s2, unsigned s1len, unsigned s2len);
void millis_to_date (uint64_t timestamp, char *buffer, enum ccx_output_date_format date_format, char millis_separator);
void signal_handler(int sig_type);

View File

@ -1,4 +1,5 @@
#include "lib_ccx.h"
#include "utility.h"
#include "matroska.h"
#include <limits.h>
@ -211,20 +212,6 @@ void parse_segment_info(FILE* file) {
}
}
char* generate_timestamp_utf8(ULLONG milliseconds) {
ULLONG millis = milliseconds % 1000;
milliseconds /= 1000;
ULLONG seconds = milliseconds % 60;
milliseconds /= 60;
ULLONG minutes = milliseconds % 60;
milliseconds /= 60;
ULLONG hours = milliseconds;
char* buf = malloc(sizeof(char) * 15);
sprintf(buf, "%02" LLD_M ":%02" LLD_M ":%02" LLD_M ",%03" LLD_M, hours, minutes, seconds, millis);
return buf;
}
char* generate_timestamp_ass_ssa(ULLONG milliseconds) {
ULLONG millis = (milliseconds % 1000) / 10;
milliseconds /= 1000;
@ -738,35 +725,14 @@ void parse_segment(struct matroska_ctx* mkv_ctx)
}
}
char *filename_without_ext(char* filename) {
char *returnname;
char *lastdot;
if (filename == NULL)
return filename;
if ((returnname = malloc (strlen (filename) + 1)) == NULL)
return filename;
strcpy (returnname, filename);
lastdot = strrchr (returnname, '.');
if (lastdot != NULL)
*lastdot = '\0';
return returnname;
}
char* generate_filename_from_track(struct matroska_ctx* mkv_ctx, struct matroska_sub_track* track)
{
char* filename = malloc(sizeof(char)*(MAX_FILE_NAME_SIZE-30));
char * filename_non_ext;
filename[MAX_FILE_NAME_SIZE-31] = '\0';
strncpy(filename, mkv_ctx->filename,(MAX_FILE_NAME_SIZE-31));
filename_non_ext=filename_without_ext(filename);
char* buf = malloc(sizeof(char) * MAX_FILE_NAME_SIZE);
char* buf = malloc(sizeof(char) * 200);
if (track->lang_index == 0)
sprintf(buf, "%s_%s.%s", filename_non_ext, track->lang, matroska_track_text_subtitle_id_extensions[track->codec_id]);
sprintf(buf, "%s_%s.%s", get_basename(mkv_ctx->filename), track->lang, matroska_track_text_subtitle_id_extensions[track->codec_id]);
else
sprintf(buf, "%s_%s_" LLD ".%s", filename_non_ext, track->lang, track->lang_index,
sprintf(buf, "%s_%s_" LLD ".%s", get_basename(mkv_ctx->filename), track->lang, track->lang_index,
matroska_track_text_subtitle_id_extensions[track->codec_id]);
free(filename);
free(filename_non_ext);
return buf;
}
@ -814,11 +780,13 @@ void save_sub_track(struct matroska_ctx* mkv_ctx, struct matroska_sub_track* tra
char number[9];
sprintf(number, "%d", i + 1);
char *timestamp_start = generate_timestamp_utf8(sentence->time_start);
char *timestamp_start = malloc(sizeof(char) * 80); //being generous
timestamp_to_srttime(sentence->time_start, timestamp_start);
ULLONG time_end = sentence->time_end;
if (i + 1 < track->sentence_count)
time_end = MIN(time_end, track->sentences[i + 1]->time_start - 1);
char *timestamp_end = generate_timestamp_utf8(time_end);
char *timestamp_end = malloc(sizeof(char) * 80);
timestamp_to_srttime(time_end, timestamp_end);
write(desc, number, strlen(number));
write(desc, "\n", 1);

View File

@ -139,16 +139,6 @@ void timestamp_to_srttime(uint64_t timestamp, char *buffer)
sprintf(buffer, "%02"PRIu8":%02"PRIu8":%02"PRIu8",%03"PRIu16, h, m, s, u);
}
void timestamp_to_smptetttime(uint64_t timestamp, char *buffer)
{
uint64_t p = timestamp;
uint8_t h = (uint8_t) (p / 3600000);
uint8_t m = (uint8_t) (p / 60000 - 60 * h);
uint8_t s = (uint8_t) (p / 1000 - 3600 * h - 60 * m);
uint16_t u = (uint16_t) (p - 3600000 * h - 60000 * m - 1000 * s);
sprintf(buffer, "%02"PRIu8":%02"PRIu8":%02"PRIu8".%03"PRIu16, h, m, s, u);
}
#define MIN3(a, b, c) ((a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c)))
int levenshtein_dist (const uint64_t *s1, const uint64_t *s2, unsigned s1len, unsigned s2len)