-
Notifications
You must be signed in to change notification settings - Fork 0
/
replay.c
71 lines (62 loc) · 1.44 KB
/
replay.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
inline void second_sleep(int x) {
#if defined(__WINDOWS_) || defined(_WIN32)
Sleep(x * 1000);
#else
sleep(x);
#endif
}
FILE* fp;
inline int gt() {
return getc(fp);
}
int r() {
int c = gt();
while (c < '0' || '9' < c) {
c = gt();
}
int ans = 0;
while ('0' <= c && c <= '9') {
ans = (ans << 1) + (ans << 3) + c - '0';
c = gt();
}
return ans;
}
int main(int argc, char** argv) {
fp = fopen("badapple.mp4.badapple", "r");
const int x = r();
const int y = r();
const int clk = r();
printf("[%d:%d %.2lfHz]\n", x, y, CLOCKS_PER_SEC / (double)clk);
const int print_size = (x + 1) * y;
char* buffer = (char*)malloc(print_size + 2);
clock_t t0, t1;
/*
printf("BEGINNING... [replay]\n");
fflush(stdout);
second_sleep(1);
printf("\n");
*/
t0 = clock();
int i;
for (i = 0;; i++) {
if ((print_size + 1) ^ fread(buffer, 1, print_size + 1, fp)) {
if (!i) {
printf("The first frame is empty.");
return 1;
}
break;
}
fwrite(buffer, 1, print_size + 1, stdout);
fflush(stdout);
t1 = clock();
while (t1 - t0 < clk) {
t1 = clock();
}
t0 = t1;
}
fclose(fp);
return 0;
}