source: roaraudio/roard/loop.c @ 68:797b3512e1d9

Last change on this file since 68:797b3512e1d9 was 68:797b3512e1d9, checked in by phi, 16 years ago

added basic demon support, a option to not listen on any sockets and support to create clients out of given FHs

File size: 2.1 KB
Line 
1//loop.c:
2
3#include "roard.h"
4
5int main_loop (int driver, DRIVER_USERDATA_T driver_inst, struct roar_audio_info * sa) {
6 void ** streams_input = NULL;
7 uint32_t pos = 0;
8#ifdef MONITOR_LATENCY
9 struct timeval         try, ans;
10 long int ans_1last = 0, ans_2last = 0, ans_3last = 0;
11 long int loopc = 0;
12
13 printf("\n\e[s");
14 fflush(stdout);
15#endif
16
17 ROAR_DBG("main_loop(*) = ?");
18 alive = 1;
19
20 while (alive) {
21#ifdef MONITOR_LATENCY
22 gettimeofday(&try, NULL);
23#endif
24
25  ROAR_DBG("main_loop(*): looping...");
26
27  if ( g_listen_socket != -1 ) {
28   ROAR_DBG("main_loop(*): check for new clients...");
29   net_check_listen();
30  }
31
32  ROAR_DBG("main_loop(*): check for new data...");
33  clients_check_all();
34
35  ROAR_DBG("main_loop(*): mixing clients...");
36  if ( g_standby ) {
37   // while in standby we still neet to get the buffers to free input buffer space.
38   streams_get_mixbuffers(&streams_input, sa, pos);
39  } else {
40   if ( streams_get_mixbuffers(&streams_input, sa, pos) == 0 ) {
41    mix_clients(g_output_buffer, sa->bits, streams_input, ROAR_OUTPUT_BUFFER_SAMPLES * sa->channels);
42   }
43  }
44
45/*
46  // while in standby we still need to write out our buffer to not run in an endless loop without
47  // a break
48*/
49
50  if ( g_standby ) {
51   usleep((1000000 * ROAR_OUTPUT_BUFFER_SAMPLES) / sa->rate);
52   printf("usleep(%u) = ?\n", (1000000 * ROAR_OUTPUT_BUFFER_SAMPLES) / sa->rate);
53  } else {
54   clients_send_filter(sa, pos);
55   output_buffer_flush(driver_inst, driver);
56   clients_send_mon(sa, pos);
57  }
58//  output_buffer_reinit();
59
60  pos = ROAR_MATH_OVERFLOW_ADD(pos, ROAR_OUTPUT_BUFFER_SAMPLES);
61  ROAR_DBG("main_loop(*): current pos: %u", pos);
62#ifdef MONITOR_LATENCY
63 gettimeofday(&ans, NULL);
64
65 while (ans.tv_sec > try.tv_sec) {
66  ans.tv_sec--;
67  ans.tv_usec += 1000000;
68 }
69 ans.tv_usec -= try.tv_usec;
70
71 if ( loopc % 128 ) {
72  printf("\e[ucurrent latency: %.3fms  average: %.3fms   ",  ans.tv_usec                               / (double)1000,
73                                                            (ans.tv_usec+ans_3last+ans_2last+ans_1last)/ (double)4000);
74  fflush(stdout);
75 }
76
77 ans_3last = ans_2last;
78 ans_2last = ans_1last;
79 ans_1last = ans.tv_usec;
80 loopc++;
81#endif
82 }
83
84 return -1;
85}
86
87//ll
Note: See TracBrowser for help on using the repository browser.