Home | History | Annotate | Download | only in libvpx

Lines Matching refs:stats

19 int stats_open_file(stats_io_t *stats, const char *fpf, int pass) {
21 stats->pass = pass;
24 stats->file = fopen(fpf, "wb");
25 stats->buf.sz = 0;
26 stats->buf.buf = NULL;
27 res = (stats->file != NULL);
31 stats->file = fopen(fpf, "rb");
33 if (stats->file == NULL) fatal("First-pass stats file does not exist!");
35 if (fseek(stats->file, 0, SEEK_END))
36 fatal("First-pass stats file must be seekable!");
38 stats->buf.sz = stats->buf_alloc_sz = ftell(stats->file);
39 rewind(stats->file);
41 stats->buf.buf = malloc(stats->buf_alloc_sz);
43 if (!stats->buf.buf)
44 fatal("Failed to allocate first-pass stats buffer (%lu bytes)",
45 (unsigned int)stats->buf_alloc_sz);
47 nbytes = fread(stats->buf.buf, 1, stats->buf.sz, stats->file);
48 res = (nbytes == stats->buf.sz);
54 int stats_open_mem(stats_io_t *stats, int pass) {
56 stats->pass = pass;
59 stats->buf.sz = 0;
60 stats->buf_alloc_sz = 64 * 1024;
61 stats->buf.buf = malloc(stats->buf_alloc_sz);
64 stats->buf_ptr = stats->buf.buf;
65 res = (stats->buf.buf != NULL);
69 void stats_close(stats_io_t *stats, int last_pass) {
70 if (stats->file) {
71 if (stats->pass == last_pass) {
72 free(stats->buf.buf);
75 fclose(stats->file);
76 stats->file = NULL;
78 if (stats->pass == last_pass) free(stats->buf.buf);
82 void stats_write(stats_io_t *stats, const void *pkt, size_t len) {
83 if (stats->file) {
84 (void)fwrite(pkt, 1, len, stats->file);
86 if (stats->buf.sz + len > stats->buf_alloc_sz) {
87 size_t new_sz = stats->buf_alloc_sz + 64 * 1024;
88 char *new_ptr = realloc(stats->buf.buf, new_sz);
91 stats->buf_ptr = new_ptr + (stats->buf_ptr - (char *)stats->buf.buf);
92 stats->buf.buf = new_ptr;
93 stats->buf_alloc_sz = new_sz;
95 fatal("Failed to realloc firstpass stats buffer.");
99 memcpy(stats->buf_ptr, pkt, len);
100 stats->buf.sz += len;
101 stats->buf_ptr += len;
105 vpx_fixed_buf_t stats_get(stats_io_t *stats) { return stats->buf; }