예제 #1
0
srt_t* srt_from_fd(int fd)
{
    int eof;
    uint8_t c;

    for (;;) {
        int ret = fd_read(fd, &c, 1, &eof);

        if (eof || (1 == ret && 0 == c)) {
            srt_t* srt = srt_parse(&g_srt_data[0], g_srt_size);
            g_srt_size = 0;
            return srt;
        }

        if (1 == ret) {
            if (g_srt_size >= MAX_SRT_SIZE - 1) {
                fprintf(stderr, "Warning MAX_SRT_SIZE reached. Clearing buffer\n");
                g_srt_size = 0;
            }

            g_srt_data[g_srt_size] = c;
            g_srt_size += 1;
        } else {
            return 0;
        }
    }
}
예제 #2
0
srt_t* srt_from_file (const char* path)
{
    srt_t* head = 0;
    size_t read, totl = 0;
    FILE* file = fopen (path,"r");

    if (file) {
        char* srt_data = malloc (MAX_SRT_SIZE);
        size_t srt_size = 0;
        size_t size = MAX_SRT_SIZE;
        char* data = srt_data;

        while (0 < (read = fread (data,1,size,file))) {
            totl += read; data += read; size -= read; srt_size += read;
        }

        head = srt_parse (srt_data,srt_size);
        free (srt_data);
    }

    return head;
}
예제 #3
0
int main (int argc, char** argv)
{
    srt_t* srt;
    caption_frame_t frame;
    char frame_buf[CAPTION_FRAME_DUMP_BUF_SIZE];

    if (argc < 2) {
        return 0;
    }

    FILE* file = fopen (argv[1],"r");

    if (! file) {
        return 0;
    }

    utf8_char_t* data = malloc (MAX_SRT_SIZE);
    size_t size = read_file (file,data,MAX_SRT_SIZE);
    srt_t* head = srt_parse (data,size);
    vtt_dump (head);
    srt_free (head);
}