-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodec.c
45 lines (42 loc) · 933 Bytes
/
codec.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
/*
* Copyright (C) 2010 Valery V. Vorotyntsev <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <assert.h>
#include "codec.h"
#include "decoder.h"
#include "encoder.h"
#include "util.h"
IterV
run_codec(enum Codec_T type, void **z, struct Stream *str,
const struct Repr_Format *repr)
{
if (type == DECODER) {
if (*z == NULL) {
*z = xmalloc(sizeof(struct DecSt));
init_DecSt(*z, repr);
}
return decode(*z, str);
} else if (type == ENCODER) {
if (*z == NULL) {
*z = xmalloc(sizeof(struct EncSt));
init_EncSt(*z);
}
return encode(*z, str);
} else {
assert(0 == 1);
}
}
void
free_codec(enum Codec_T type, void *z)
{
if (type == DECODER)
free_DecSt(z);
else if (type == ENCODER)
free_EncSt(z);
else
assert(0 == 1);
}