root/branches/api-cleanup/src/libstreaming/generic/Port.cpp

Revision 816, 4.3 kB (checked in by ppalmers, 14 years ago)

remove support for per-port datatypes. It's too much hassle and it doesn't add enough value.
It also prevents thorough performance optimizations, especially for larger channel counts (e.g. SSE based).

Audio ports are now either all float or all int24. This can be specified by the ffado_streaming_set_audio_datatype
API function before the streaming is prepared. Hence we can still support the direct conversion to the
clients datatype when demuxing the packets.

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  * This program 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 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program 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 program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #include "Port.h"
25 #include "PortManager.h"
26
27 #include <stdlib.h>
28 #include <assert.h>
29
30 namespace Streaming {
31
32 IMPL_DEBUG_MODULE( Port, Port, DEBUG_LEVEL_NORMAL );
33
34 Port::Port(PortManager& m, std::string name,
35            enum E_PortType porttype, enum E_Direction direction)
36     : m_Name( name )
37     , m_disabled( true )
38     , m_buffersize( 0 )
39     , m_PortType( porttype )
40     , m_Direction( direction )
41     , m_buffer( NULL )
42     , m_manager( m )
43     , m_State( E_Created )
44 {
45     m_manager.registerPort(this);
46 }
47
48 Port::~Port() {
49     debugOutput( DEBUG_LEVEL_VERBOSE, "deleting port %s\n", getName().c_str());
50     m_manager.unregisterPort(this);
51 }
52
53 /**
54  * The idea is that you set all port parameters, and then initialize the port.
55  * This allocates all resources and makes the port usable. However, you can't
56  * change the port properties anymore after this.
57  *
58  * @return true if successfull. false if not (all resources are freed).
59  */
60 bool Port::init() {
61     debugOutput( DEBUG_LEVEL_VERBOSE, "Initialize port %s\n", m_Name.c_str());
62     if (m_State != E_Created) {
63         debugFatal("Port (%s) not in E_Created state: %d\n", m_Name.c_str(), m_State);
64         return false;
65     }
66
67     if (m_buffersize == 0) {
68         debugFatal("Cannot initialize a port with buffersize=0\n");
69         return false;
70     }
71
72     if (m_buffer == NULL) {
73         debugFatal("Cannot initialize a port with no attached buffer\n");
74         return false;
75     }
76
77     m_State = E_Initialized;
78     return true;
79 }
80
81 bool Port::reset() {
82     return true;
83 }
84
85 bool Port::setName(std::string name) {
86     debugOutput( DEBUG_LEVEL_VERBOSE, "Setting name to %s for port %s\n",name.c_str(),m_Name.c_str());
87
88     if (m_State != E_Created) {
89         debugFatal("Port (%s) not in E_Created state: %d\n",m_Name.c_str(),m_State);
90         return false;
91     }
92     m_Name=name;
93     return true;
94 }
95
96 bool Port::setBufferSize(unsigned int newsize) {
97     debugOutput( DEBUG_LEVEL_VERBOSE, "Setting buffersize to %d for port %s\n",newsize,m_Name.c_str());
98     if (m_State != E_Created) {
99         debugFatal("Port (%s) not in E_Created state: %d\n",m_Name.c_str(),m_State);
100         return false;
101     }
102     m_buffersize=newsize;
103     return true;
104 }
105
106 unsigned int Port::getEventSize() {
107     return 4; // whether it's float, int24, midi or control, it's 4
108 }
109
110 // buffer handling api's for pointer buffers
111 /**
112  * Get the buffer address
113  *
114  * @param buff
115  */
116 void *Port::getBufferAddress() {
117     return m_buffer;
118 };
119
120 /**
121  * Set the external buffer address.
122  *
123  * @param buff
124  */
125 void Port::setBufferAddress(void *buff) {
126     m_buffer=buff;
127 }
128
129 /// Enable the port. (this can be called anytime)
130 void
131 Port::enable()  {
132     debugOutput(DEBUG_LEVEL_VERBOSE, "Enabling port %s...\n",m_Name.c_str());
133     m_disabled=false;
134 }
135
136 /// Disable the port. (this can be called anytime)
137 void
138 Port::disable() {
139     debugOutput(DEBUG_LEVEL_VERBOSE, "Disabling port %s...\n",m_Name.c_str());
140     m_disabled=false;
141 }
142
143 void Port::show() {
144     debugOutput(DEBUG_LEVEL_VERBOSE,"Name          : %s\n", m_Name.c_str());
145     debugOutput(DEBUG_LEVEL_VERBOSE,"Enabled?      : %d\n", m_disabled);
146     debugOutput(DEBUG_LEVEL_VERBOSE,"State?        : %d\n", m_State);
147     debugOutput(DEBUG_LEVEL_VERBOSE,"Buffer Size   : %d\n", m_buffersize);
148     debugOutput(DEBUG_LEVEL_VERBOSE,"Event Size    : %d\n", getEventSize());
149     debugOutput(DEBUG_LEVEL_VERBOSE,"Port Type     : %d\n", m_PortType);
150     debugOutput(DEBUG_LEVEL_VERBOSE,"Direction     : %d\n", m_Direction);
151 }
152
153 void Port::setVerboseLevel(int l) {
154     setDebugLevel(l);
155 }
156
157 }
Note: See TracBrowser for help on using the browser.