root/branches/ppalmers-streaming/tests/SytMonitor.cpp

Revision 714, 4.5 kB (checked in by ppalmers, 15 years ago)

- cleanup of streaming interfaces
- doesn't work yet

Line 
1 /*
2  * Copyright (C) 2005-2007 by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB
8  *
9  * FFADO is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  * FFADO is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with FFADO; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA.
22  *
23  */
24
25 #include "SytMonitor.h"
26
27 #include <netinet/in.h>
28 #include <assert.h>
29
30
31 IMPL_DEBUG_MODULE( SytMonitor, SytMonitor, DEBUG_LEVEL_VERBOSE );
32
33
34 /* --------------------- RECEIVE ----------------------- */
35
36 SytMonitor::SytMonitor(int port)
37     : IsoStream(IsoStream::eST_Receive, port) {
38     m_cinfo_buffer=ffado_ringbuffer_create(16384*sizeof(struct cycle_info));
39
40 }
41
42 SytMonitor::~SytMonitor() {
43     ffado_ringbuffer_free(m_cinfo_buffer);
44
45 }
46
47 enum raw1394_iso_disposition
48 SytMonitor::putPacket(unsigned char *data, unsigned int length,
49                   unsigned char channel, unsigned char tag, unsigned char sy,
50                   unsigned int cycle, unsigned int dropped) {
51     enum raw1394_iso_disposition retval=RAW1394_ISO_OK;
52
53     struct iec61883_packet *packet = (struct iec61883_packet *) data;
54     unsigned int syt_timestamp=ntohs(packet->syt);
55
56     if (syt_timestamp == 0xFFFF) {
57         return RAW1394_ISO_OK;
58     }
59
60     uint32_t m_full_timestamp;
61     uint32_t m_full_timestamp_ticks;
62
63     debugOutput(DEBUG_LEVEL_VERBOSE,"%2u,%2u: CY=%4u, SYT=%08X (%3u secs + %4u cycles + %04u ticks)\n",
64         m_port,channel,
65         cycle,syt_timestamp,
66         CYCLE_TIMER_GET_SECS(syt_timestamp),
67         CYCLE_TIMER_GET_CYCLES(syt_timestamp),
68         CYCLE_TIMER_GET_OFFSET(syt_timestamp)
69
70         );
71
72     // reconstruct the full cycle
73     unsigned int cc=m_handler->getCycleTimer();
74
75     unsigned int cc_cycles=CYCLE_TIMER_GET_CYCLES(cc);
76
77     unsigned int cc_seconds=CYCLE_TIMER_GET_SECS(cc);
78
79
80     // the cycletimer has wrapped since this packet was received
81     // we want cc_seconds to reflect the 'seconds' at the point this
82     // was received
83     if (cycle>cc_cycles) cc_seconds--;
84
85     m_full_timestamp_ticks=sytRecvToFullTicks((uint32_t)syt_timestamp, cycle, cc);
86     m_full_timestamp=TICKS_TO_CYCLE_TIMER(m_full_timestamp_ticks);
87
88     struct cycle_info cif;
89     cif.cycle=cycle;
90     cif.seconds=cc_seconds;
91
92     cif.syt=packet->syt;
93     cif.full_syt=m_full_timestamp;
94
95     // now we reconstruct the presentation time
96     cif.pres_seconds = CYCLE_TIMER_GET_SECS(m_full_timestamp);
97     cif.pres_cycle   = CYCLE_TIMER_GET_CYCLES(m_full_timestamp);
98     cif.pres_offset  = CYCLE_TIMER_GET_OFFSET(m_full_timestamp);
99     cif.pres_ticks   = m_full_timestamp_ticks;
100
101     if (cif.pres_offset != (syt_timestamp & 0xFFF)) {
102         debugOutput(DEBUG_LEVEL_NORMAL,"P-offset error: %04X != %04X (P: %08X, R: %08X)\n",
103         cif.pres_offset, syt_timestamp & 0xFFF, m_full_timestamp, syt_timestamp);
104     }
105     if ((cif.pres_cycle & 0xF) != ((syt_timestamp & 0xF000)>>12)) {
106         debugOutput(DEBUG_LEVEL_NORMAL,"P-cycle error: %01X != %01X (P: %08X, R: %08X)\n",
107             cif.pres_cycle &0xF, (syt_timestamp & 0xF000)>>12, m_full_timestamp, syt_timestamp);
108     }
109
110     putCycleInfo(&cif);
111
112     return retval;
113 }
114
115 bool SytMonitor::putCycleInfo(struct cycle_info *cif) {
116     if(ffado_ringbuffer_write(m_cinfo_buffer,(char *)cif,sizeof(struct cycle_info))
117         !=sizeof(struct cycle_info)) {
118         return false;
119     }
120     return true;
121 }
122
123 bool SytMonitor::readNextCycleInfo(struct cycle_info *cif) {
124     if(ffado_ringbuffer_peek(m_cinfo_buffer,(char *)cif,sizeof(struct cycle_info))
125         !=sizeof(struct cycle_info)) {
126         return false;
127     }
128     return true;
129
130 }
131
132 bool SytMonitor::consumeNextCycleInfo() {
133     struct cycle_info cif;
134     if(ffado_ringbuffer_read(m_cinfo_buffer,(char *)&cif,sizeof(struct cycle_info))
135         !=sizeof(struct cycle_info)) {
136         return false;
137     }
138     return true;
139 }
140
141 void SytMonitor::dumpInfo()
142 {
143     IsoStream::dumpInfo();
144     debugOutputShort( DEBUG_LEVEL_NORMAL, "  Ringbuffer fill: %d\n",
145        ffado_ringbuffer_read_space(m_cinfo_buffer)/sizeof(struct cycle_info));
146 };
Note: See TracBrowser for help on using the browser.