source: roaraudio/roard/driver_sysclock.c @ 5276:0eb24ca6810e

Last change on this file since 5276:0eb24ca6810e was 5276:0eb24ca6810e, checked in by phi, 12 years ago

merged VIO's _nonblock() into _ctl() (Closes: #135)

File size: 2.9 KB
RevLine 
[4668]1//driver_sysclock.c:
[2208]2
3/*
[4708]4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2011
[2208]5 *
6 *  This file is part of roard a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
[3517]21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
[2208]23 *
24 */
25
26#include "roard.h"
27
[2209]28#ifdef ROAR_HAVE_DRIVER_SYSCLOCK
[2367]29int driver_sysclock_open_vio(struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) {
[4898]30 struct driver_sysclock * self = roar_mm_malloc(sizeof(struct driver_sysclock));
[2212]31
32 if ( self == NULL )
33  return -1;
[2208]34
35 if ( device != NULL ) {
36  return -1;
37 }
38
[2212]39 memset(self, 0, sizeof(struct driver_sysclock));
40 memset(inst, 0, sizeof(struct roar_vio_calls));
41
[4897]42 inst->inst     = self;
43 inst->close    = driver_sysclock_close;
44 inst->write    = driver_sysclock_write;
[5276]45 inst->ctl      = driver_dummy_ctl;
[2212]46
[4898]47 self->bps      = roar_info2bitspersec(info)/8;
[2212]48
[2213]49 if (!self->bps) {
[4898]50  roar_mm_free(self);
[2212]51  return -1;
52 }
53
54 switch (info->codec) {
55  case ROAR_CODEC_PCM_S_LE:
56  case ROAR_CODEC_PCM_S_BE:
57  case ROAR_CODEC_PCM_S_PDP:
58  case ROAR_CODEC_PCM_U_LE:
59  case ROAR_CODEC_PCM_U_BE:
60  case ROAR_CODEC_PCM_U_PDP:
61  case ROAR_CODEC_ALAW:
62  case ROAR_CODEC_MULAW:
63   break;
64  default:
[4898]65    roar_mm_free(self);
[2212]66    return -1;
67   break;
68 }
69
70 gettimeofday(&(self->lasttime), NULL);
71
[2422]72 self->last_wanted = 0;
73
[2212]74 return 0;
75}
76
77int     driver_sysclock_close   (struct roar_vio_calls * vio) {
78 struct driver_sysclock * self = vio->inst;
79
80 if ( self == NULL )
81  return -1;
82
[4898]83 roar_mm_free(self);
[2212]84
85 return 0;
86}
87
88ssize_t driver_sysclock_write   (struct roar_vio_calls * vio, void *buf, size_t count) {
89 struct driver_sysclock * self = vio->inst;
[2213]90 struct timeval now;
[2911]91 long long diff = (1000000LL * count / (long long)self->bps);
[2422]92 long long ago;
[2213]93
94 gettimeofday(&now, NULL);
95
96 ago  = now.tv_usec - self->lasttime.tv_usec;
97 ago += 1000000*(now.tv_sec - self->lasttime.tv_sec);
98
[2422]99 ago -= self->last_wanted;
100
[2213]101 memcpy(&(self->lasttime), &now, sizeof(now));
102
103 ROAR_DBG("driver_sysclock_write(*): count=%u, bps=%u, diff=%llu, ago=%llu", count, self->bps, diff, ago);
104
105 diff -= ago;
106
[2422]107 self->last_wanted = diff;
108
[2911]109 ROAR_DBG("driver_sysclock_write(*): diff=%lli", diff);
110
[2422]111 if ( diff > 0 )
[4896]112  roar_usleep(diff);
[2213]113
114 return count;
[2208]115}
[2212]116
[2209]117#endif
[2208]118
119//ll
Note: See TracBrowser for help on using the repository browser.