root/branches/libfreebob-2.0/src/libstreaming/IsoStream.cpp

Revision 207, 4.3 kB (checked in by pieterpalmers, 18 years ago)

- temp commit

Line 
1 /* $Id$ */
2
3 /*
4  *   FreeBob Streaming API
5  *   FreeBob = Firewire (pro-)audio for linux
6  *
7  *   http://freebob.sf.net
8  *
9  *   Copyright (C) 2005,2006 Pieter Palmers <pieterpalmers@users.sourceforge.net>
10  *
11  *   This program is free software {} you can redistribute it and/or modify
12  *   it under the terms of the GNU General Public License as published by
13  *   the Free Software Foundation {} either version 2 of the License, or
14  *   (at your option) any later version.
15  *
16  *   This program is distributed in the hope that it will be useful,
17  *   but WITHOUT ANY WARRANTY {} without even the implied warranty of
18  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *   GNU General Public License for more details.
20  *
21  *   You should have received a copy of the GNU General Public License
22  *   along with this program {} if not, write to the Free Software
23  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  *
25  *
26  *
27  */
28
29 #include "IsoStream.h"
30 #include "PacketBuffer.h"
31
32 namespace FreebobStreaming
33 {
34
35 IMPL_DEBUG_MODULE( IsoStream, IsoStream, DEBUG_LEVEL_NORMAL );
36 IMPL_DEBUG_MODULE( IsoStreamBuffered, IsoStreamBuffered, DEBUG_LEVEL_NORMAL );
37
38 int IsoStream::putPacket(unsigned char *data, unsigned int length,
39                               unsigned char channel, unsigned char tag, unsigned char sy,
40                                   unsigned int cycle, unsigned int dropped) {
41
42         debugOutput( DEBUG_LEVEL_VERY_VERBOSE,
43                      "received packet: length=%d, channel=%d, cycle=%d\n",
44                      length, channel, cycle );
45
46         return 0;
47 }
48
49 int IsoStream::getPacket(unsigned char *data, unsigned int *length,
50                               unsigned char *tag, unsigned char *sy,
51                               int cycle, unsigned int dropped, unsigned int max_length) {
52         debugOutput( DEBUG_LEVEL_VERY_VERBOSE,
53                      "sending packet: length=%d, cycle=%d\n",
54                      *length, cycle );
55
56         memcpy(data,&cycle,sizeof(cycle));
57         *length=sizeof(cycle);
58         *tag = 1;
59         *sy = 0;
60
61
62         return 0;
63 }
64
65 int IsoStream::getNodeId() {
66         if (m_handler) {
67                 return m_handler->getLocalNodeId();
68         }
69         return -1;
70 }
71
72
73 void IsoStream::dumpInfo()
74 {
75
76         debugOutputShort( DEBUG_LEVEL_NORMAL, "  Stream type    : %s\n",
77              (this->getType()==EST_Receive ? "Receive" : "Transmit"));
78         debugOutputShort( DEBUG_LEVEL_NORMAL, "  Port, Channel  : %d, %d\n",
79              m_port, m_channel);
80
81 };
82
83 void IsoStream::reset() {
84
85 }
86
87 void IsoStream::prepare() {
88 }
89
90 int IsoStream::init() {
91         return 0;
92
93 }
94
95 /* buffered variant of the ISO stream */
96 IsoStreamBuffered::~IsoStreamBuffered() {
97         debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n");
98         if(buffer) delete buffer;
99
100 }
101
102 int IsoStreamBuffered::init() {
103         debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n");
104         buffer=new PacketBuffer(m_headersize, m_buffersize, m_max_packetsize);
105
106         if(buffer==NULL) return -1;
107
108         return buffer->initialize();
109
110 }
111
112 int IsoStreamBuffered::putPacket(unsigned char *data, unsigned int length,
113                               unsigned char channel, unsigned char tag, unsigned char sy,
114                                   unsigned int cycle, unsigned int dropped) {
115         int retval;
116
117         debugOutput( DEBUG_LEVEL_VERY_VERBOSE,
118                      "received packet: length=%d, channel=%d, cycle=%d\n",
119                      length, channel, cycle );
120         if(buffer) {
121                 if((retval=buffer->addPacket((quadlet_t *)data,length))) {
122                         debugWarning("Receive buffer overflow\n");
123                 }
124         }
125
126         return 0;
127 }
128
129 int IsoStreamBuffered::getPacket(unsigned char *data, unsigned int *length,
130                               unsigned char *tag, unsigned char *sy,
131                               int cycle, unsigned int dropped, unsigned int max_length) {
132         debugOutput( DEBUG_LEVEL_VERY_VERBOSE,
133                      "sending packet: length=%d, cycle=%d\n",
134                      *length, cycle );
135
136         int retval;
137         *length=sizeof(cycle);
138         *tag = 1;
139         *sy = 0;
140
141         if(buffer) {
142                 if((retval=buffer->getNextPacket((quadlet_t *)data,max_length))<0) {
143                         debugWarning("Transmit buffer underflow: %d\n",retval);
144                         return -1;
145                 }
146                 *length=retval;
147         }
148
149         return 0;
150 }
151
152 int IsoStreamBuffered::getBufferFillPackets() {
153         debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n");
154
155         if(buffer) return buffer->getBufferFillPackets();
156         return -1;
157
158 }
159 int IsoStreamBuffered::getBufferFillPayload() {
160         debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n");
161
162         if(buffer) return buffer->getBufferFillPayload();
163         return -1;
164
165 }
166
167 void IsoStreamBuffered::setVerboseLevel(int l) {
168         setDebugLevel( l );
169         if(buffer) {
170                 buffer->setVerboseLevel(l);
171         }
172 }
173
174 }
Note: See TracBrowser for help on using the browser.