90
92
// Clean up parser module
91
93
parser_module_exit();
95
// Clean up gst-listener.c
96
listener_module_exit();
101
void timer_set_debug_flag(gboolean on_off) {
102
// Set debug flag. Please see application options:
103
// $ audio-recorder --help
104
listener_set_debug_flag(on_off);
96
107
void timer_module_reset(gint for_state) {
97
// Reset timer for the given state (before gst-recorder moves to new state)
100
stop if silence 5s 4%
108
// Reset timer before we move to the given state
108
110
switch (for_state) {
109
111
case GST_STATE_PLAYING:
229
234
gboolean timer_func_cb(gpointer user_data) {
230
235
// The actual timer function
233
238
static gboolean timer_active = FALSE;
240
// Do we need data from the gst-listener.c?
241
static gboolean need_listener = FALSE;
235
243
// Counter to detect if GConf settings have been altered
236
244
static gint setting_counter = -1;
267
275
// Free the old g_t_list
268
276
timer_clear_list();
270
// Get new timer (action/command) list.
271
279
G_LOCK(g_t_list);
273
// Get timer commands/text
274
282
gchar *timer_text = NULL;
275
283
conf_get_string_value("timer_text", &timer_text);
277
285
LOG_TIMER("----------------\nTimer text is:\n<%s>\n--------------\n", timer_text);
279
// Note: This returns pointer to the g_timer_list in timer-parser.c.
287
// Parse timer conditions.
288
// This will return pointer to the g_timer_list (GList) in timer-parser.c.
280
289
g_t_list = parser_parse_actions(timer_text);
282
291
g_free(timer_text);
284
293
if (g_list_length(g_t_list) < 1) {
285
294
LOG_TIMER("The timer has no conditions.\n");
287
// Timer has no conditions. Switch off listener.
288
timer_active = FALSE;
292
297
LOG_TIMER("The timer conditions are:\n");
294
#if defined(DEBUG_TIMER)
295
// Debug print the command list
296
parser_print_list(g_t_list);
299
#if defined(DEBUG_TIMER)
300
// Debug print the command list
301
parser_print_list(g_t_list);
305
// Important: Start the listener only when we need it. It's CPU intensive.
306
// Only "silence", "voice", "audio" and "sound" commands need data from the listener.
308
need_listener = FALSE;
310
GList *item = g_list_first(g_t_list);
312
TimerRec *tr = (TimerRec*)item->data;
314
if (!g_strcmp0(tr->label, "silence") ||
315
!g_strcmp0(tr->label, "voice") ||
316
!g_strcmp0(tr->label, "sound") ||
317
!g_strcmp0(tr->label, "audio")) {
319
need_listener = TRUE;
324
item = g_list_next(item);
300
328
G_UNLOCK(g_t_list);
304
gboolean active = timer_active;
306
// Execute timer commands?
309
336
// Make sure the listener has stopped (do not waste CPU cycles)
310
337
listener_stop_listening();
315
// Start the listener and collect signal/level statistics
316
listener_start_listening();
343
// Do we need data from gst-listener.c?
344
if (!need_listener) {
346
// Make sure the listener has stopped (do not waste CPU cycles)
347
listener_stop_listening();
351
// Start the listener and collect signal/level statistics
352
listener_start_listening();
319
357
// Execute the TimerRec commands. For all TimerRec structures in GList...
320
358
GList *item = g_list_first(g_t_list);
322
360
TimerRec *tr = (TimerRec*)item->data;
325
363
G_LOCK(g_t_list);
327
365
// Check the timer condition
356
394
LOG_TIMER("Filesize test = TRUE.\n");
359
// Test for silence (if average audio signal is under givel level)?
397
// Test for silence (if average audio signal is under givel level)?
360
398
} else if (!g_strcmp0(tr->label, "silence")) {
362
400
// stop/pause if silence 8s -26 dB
363
401
// stop/pause if silence 8 sec 7 %
364
// = start/stop/pause recording if sound level is under -26dB (ca.7%) in 8 seconds time.
402
// = start/stop/pause recording if sound level is under x dB in n seconds time.
366
404
action = timer_test_silence(tr);
371
409
LOG_TIMER("Silence test = TRUE.\n");
374
// Test for voice/audio/sound?
412
// Test for voice/audio/sound?
375
413
} else if (!g_strcmp0(tr->label, "voice") ||
376
414
!g_strcmp0(tr->label, "sound") ||
377
415
!g_strcmp0(tr->label, "audio")) {
379
417
// start/stop/pause if voice/audio/sound 8s 7%
380
418
// start/stop/pause if voice/audio/sound 8s -26dB
381
// = start/stop/pause recording if voice/audio/sound is above 7% (ca.-26dB) in 8 seconds period.
419
// = start/stop/pause recording if voice/audio/sound is above x dB in n seconds period.
383
421
action = timer_test_sound(tr);