blob: c523f555a9b3e282002ac5e8ca2c94ab81a9b7d3 (
plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
/*
* This file is part of gapk (GSM Audio Pocket Knife).
*
* gapk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gapk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gapk. If not, see <http://www.gnu.org/licenses/>.
*
* (C) 2014 Harald Welte <laforge@gnumonks.org>
*/
#include <talloc.h>
#include <errno.h>
#include <osmocom/gapk/benchmark.h>
#include <osmocom/gapk/codecs.h>
struct osmo_gapk_bench_cycles *
osmo_gapk_bench_codec[_CODEC_MAX] = { NULL };
int osmo_gapk_bench_enable(enum osmo_gapk_codec_type codec)
{
struct osmo_gapk_bench_cycles *bench;
/* Allocate zero-initialized memory */
bench = talloc_zero(NULL, struct osmo_gapk_bench_cycles);
if (!bench)
return -ENOMEM;
/* Set up pointer */
osmo_gapk_bench_codec[codec] = bench;
return 0;
}
unsigned long long
osmo_gapk_bench_get_cycles(enum osmo_gapk_codec_type codec, int enc)
{
struct osmo_gapk_bench_cycles *bench;
unsigned long long cycles = 0;
int i;
/* Check if there are benchmark data */
bench = osmo_gapk_bench_codec[codec];
if (!bench)
return -EAGAIN;
if (enc) {
for (i = 0; i < bench->enc_used; i++)
cycles += bench->enc[i];
} else {
for (i = 0; i < bench->dec_used; i++)
cycles += bench->dec[i];
}
return cycles;
}
unsigned int
osmo_gapk_bench_get_frames(enum osmo_gapk_codec_type codec, int enc)
{
struct osmo_gapk_bench_cycles *bench;
/* Check if there are benchmark data */
bench = osmo_gapk_bench_codec[codec];
if (!bench)
return -EAGAIN;
return enc ? bench->enc_used : bench->dec_used;
}
void osmo_gapk_bench_free(void)
{
int i;
for (i = 0; i < _CODEC_MAX; i++)
talloc_free(osmo_gapk_bench_codec[i]);
}
|