Mercurial > mplayer.hg
annotate libaf/af_stats.c @ 33283:7b18f6e6e11c
configure: Employ proper autodetection for the matrixview video output.
author | diego |
---|---|
date | Thu, 05 May 2011 10:25:14 +0000 |
parents | 8e9f6dfd7580 |
children | a93891202051 |
rev | line source |
---|---|
28661
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
1 /* |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
2 * Copyright (C) 2009 Nicolas George <nicolas.george@normalesup.org> |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
3 * |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
4 * This file is part of MPlayer. |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
5 * |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
6 * MPlayer is free software; you can redistribute it and/or modify |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
7 * it under the terms of the GNU General Public License as published by |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
8 * the Free Software Foundation; either version 2 of the License, or |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
9 * (at your option) any later version. |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
10 * |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
11 * MPlayer is distributed in the hope that it will be useful, |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
14 * GNU General Public License for more details. |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
15 * |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
16 * You should have received a copy of the GNU General Public License along |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
17 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
19 */ |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
20 |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
21 #include <stdio.h> |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
22 #include <stdlib.h> |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
23 #include <inttypes.h> |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
24 #include <math.h> |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
25 |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
26 #include "af.h" |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
27 |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
28 #define MAX_DB 80 |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
29 #define MIN_VAL 1E-8 |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
30 |
28663 | 31 struct af_stats { |
28661
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
32 long long n_samples; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
33 double tsquare; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
34 int max; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
35 long long histogram[65536]; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
36 }; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
37 |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
38 static inline int logdb(double v) |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
39 { |
28663 | 40 if (v > 1) |
41 return 0; | |
42 if (v <= MIN_VAL) | |
43 return MAX_DB - 1; | |
44 return log(v) / -0.23025850929940456840179914546843642076; | |
28661
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
45 } |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
46 |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
47 static int stats_init(af_instance_t *af, struct af_stats *s, af_data_t *data) |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
48 { |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
49 int i; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
50 |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
51 if (!data) |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
52 return AF_ERROR; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
53 *(af->data) = *data; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
54 af->data->format = AF_FORMAT_S16_NE; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
55 af->data->bps = 2; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
56 s->n_samples = 0; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
57 s->tsquare = 0; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
58 s->max = 0; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
59 for (i = 0; i < 65536; i++) |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
60 s->histogram[i] = 0; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
61 return af_test_output(af, data); |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
62 } |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
63 |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
64 static void stats_print(struct af_stats *s) |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
65 { |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
66 int i; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
67 long long sum; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
68 float v; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
69 long long h[MAX_DB]; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
70 |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
71 s->tsquare /= 32768 * 32768; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
72 mp_msg(MSGT_AFILTER, MSGL_INFO, "stats: n_samples: %lld\n", s->n_samples); |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
73 if (s->n_samples == 0) |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
74 return; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
75 mp_msg(MSGT_AFILTER, MSGL_INFO, "stats: mean_volume: -%d dB\n", |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
76 logdb(s->tsquare / s->n_samples)); |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
77 mp_msg(MSGT_AFILTER, MSGL_INFO, "stats: max_volume: -%d dB\n", |
28663 | 78 logdb(s->max / (32768.0 * 32768.0))); |
28661
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
79 for (i = 0; i < MAX_DB; i++) |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
80 h[i] = 0; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
81 for (i = 0; i < 65536; i++) { |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
82 v = (i - 32768) / 32768.0; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
83 h[logdb(v * v)] += s->histogram[i]; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
84 } |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
85 for (i = 0; i < MAX_DB; i++) |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
86 if (h[i] != 0) |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
87 break; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
88 sum = 0; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
89 for (; i < MAX_DB; i++) { |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
90 sum += h[i]; |
28663 | 91 mp_msg(MSGT_AFILTER, MSGL_INFO, "stats: histogram_%ddb: %lld\n", |
28661
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
92 i, h[i]); |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
93 if (sum > s->n_samples / 1000) |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
94 break; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
95 } |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
96 } |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
97 |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
98 static int control(struct af_instance_s *af, int cmd, void *arg) |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
99 { |
28663 | 100 struct af_stats *s = af->setup; |
28661
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
101 |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
102 switch(cmd) { |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
103 case AF_CONTROL_REINIT: |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
104 return stats_init(af, s, arg); |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
105 |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
106 case AF_CONTROL_PRE_DESTROY: |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
107 stats_print(s); |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
108 return AF_OK; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
109 } |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
110 return AF_UNKNOWN; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
111 } |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
112 |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
113 static void uninit(struct af_instance_s *af) |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
114 { |
28663 | 115 free(af->data); |
116 free(af->setup); | |
28661
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
117 } |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
118 |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
119 static af_data_t *play(struct af_instance_s *af, af_data_t *data) |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
120 { |
28663 | 121 struct af_stats *s = af->setup; |
28661
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
122 int16_t *a, *aend; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
123 int v, v2; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
124 |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
125 a = data->audio; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
126 aend = (int16_t *)((char *)data->audio + data->len); |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
127 s->n_samples += aend - a; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
128 for (; a < aend; a++) { |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
129 v = *a; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
130 v2 = v * v; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
131 s->tsquare += v2; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
132 s->histogram[v + 32768]++; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
133 if (v2 > s->max) |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
134 s->max = v2; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
135 } |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
136 return data; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
137 } |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
138 |
28663 | 139 static int af_open(af_instance_t *af) |
140 { | |
28661
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
141 af->control = control; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
142 af->uninit = uninit; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
143 af->play = play; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
144 af->mul = 1; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
145 af->data = malloc(sizeof(af_data_t)); |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
146 af->setup = malloc(sizeof(struct af_stats)); |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
147 if (af->data == NULL || af->setup == NULL) |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
148 return AF_ERROR; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
149 return AF_OK; |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
150 } |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
151 |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
152 af_info_t af_info_stats = { |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
153 "Statistics audio filter", |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
154 "stats", |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
155 "Nicolas George", |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
156 "", |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
157 0, |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
158 af_open |
20787bd5c506
Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff
changeset
|
159 }; |