~ft/mcfs

ref: d4879b4b179f892b55fd1fd6adae62ffb14aad8c mcfs/srt.c -rw-r--r-- 1.1 KiB
d4879b4b — Sigrid Solveig Haflínudóttir ivf2raw: fix wrong timestamps 1 year, 3 months ago
                                                                                
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
#include <u.h>
#include <libc.h>
#include <bio.h>
#include "common.h"
#include "packet.h"

enum {
	Timedenum = 1000ULL,
};

int
srttsfmt(Fmt *f)
{
	char *s, *e, tmp[64];
	uvlong nsec, sec, msec;

	s = tmp;
	e = tmp + sizeof(tmp);
	nsec = va_arg(f->args, uvlong);
	sec = nsec / 1000000000ULL;
	msec = nsec/1000000ULL - sec*1000ULL;
	if(sec >= 3600){
		s = seprint(s, e, "%02llud:", sec/3600);
		sec %= 3600;
	}
	s = seprint(s, e, "%02llud:", sec/60);
	sec %= 60;
	seprint(s, e, "%02llud,%03llud", sec, msec);

	return fmtstrcpy(f, tmp);
}

int
srtpacket(Biobuf *out, Packetctx *ctx, Packet *p, int np, uvlong ts, int key)
{
	int i, n;
	uchar *s, *o;

	USED(key);
	for(i = 0; i < np; i++, p++){
		for(s = o = p->data, n = 0; n < p->sz;){
			if(*s == '\r'){
				*o++ = '\n';
				s++;
				n++;
				if(n >= p->sz)
					break;
				if(*s == '\n'){
					s++;
					n++;
					continue;
				}
			}
			*o++ = *s++;
			n++;
		}
		if(*o == '\n' && o != p->data)
			o--;
		Bprint(out, "%llud\n%P --> %P\n", ++ctx->frid, ts, ts+ctx->blockdur);
		Bwrite(out, p->data, o - p->data);
		Bwrite(out, "\n\n", 2);
	}
	Bflush(out);

	return 0;
}