Index: /branches/echoaudio/src/libstreaming/MotuPort.h =================================================================== --- /branches/echoaudio/src/libstreaming/MotuPort.h (revision 445) +++ /branches/echoaudio/src/libstreaming/MotuPort.h (revision 545) @@ -52,5 +52,5 @@ int size) : AudioPort(name, direction), - MotuPortInfo(name, position, size) // TODO: add more port information parameters here if nescessary + MotuPortInfo( position, size) // TODO: add more port information parameters here if nescessary {}; @@ -76,5 +76,5 @@ int position) : MidiPort(name, direction), - MotuPortInfo(name, position, 0) // TODO: add more port information parameters here if nescessary + MotuPortInfo(position, 0) // TODO: add more port information parameters here if nescessary {}; Index: /branches/echoaudio/src/libstreaming/MotuPortInfo.h =================================================================== --- /branches/echoaudio/src/libstreaming/MotuPortInfo.h (revision 445) +++ /branches/echoaudio/src/libstreaming/MotuPortInfo.h (revision 545) @@ -60,5 +60,4 @@ * the name parameter is mandatory * - * @param name Port name * @param position Start position of port's data in iso event * @param format Format of data in iso event @@ -66,16 +65,14 @@ * @return */ - MotuPortInfo(std::string name, int position, int size) - : m_name(name), m_position(position), m_size(size) + MotuPortInfo( int position, int size) + : m_position(position), m_size(size) {}; virtual ~MotuPortInfo() {}; - std::string getName() {return m_name;}; int getPosition() {return m_position;}; int getSize() {return m_size;}; protected: - std::string m_name; int m_position; Index: /branches/echoaudio/src/libstreaming/AmdtpPort.h =================================================================== --- /branches/echoaudio/src/libstreaming/AmdtpPort.h (revision 445) +++ /branches/echoaudio/src/libstreaming/AmdtpPort.h (revision 545) @@ -53,5 +53,5 @@ enum E_Formats format) : AudioPort(name, direction), - AmdtpPortInfo(name, position, location, format) + AmdtpPortInfo(position, location, format) {}; @@ -80,5 +80,5 @@ enum E_Formats format) : MidiPort(name, direction), - AmdtpPortInfo(name, position, location, format) + AmdtpPortInfo(position, location, format) {}; Index: /branches/echoaudio/src/libstreaming/Port.cpp =================================================================== --- /branches/echoaudio/src/libstreaming/Port.cpp (revision 445) +++ /branches/echoaudio/src/libstreaming/Port.cpp (revision 545) @@ -35,5 +35,4 @@ m_BufferType(E_PointerBuffer), m_disabled(true), - m_initialized(false), m_buffersize(0), m_eventsize(0), @@ -49,6 +48,6 @@ m_rate_counter(0), m_rate_counter_minimum(0), - m_average_ratecontrol(false) - + m_average_ratecontrol(false), + m_State(E_Created) { @@ -63,6 +62,6 @@ */ bool Port::init() { - if (m_initialized) { - debugFatal("Port already initialized... (%s)\n",m_Name.c_str()); + if (m_State != E_Created) { + debugFatal("Port (%s) not in E_Created state: %d\n",m_Name.c_str(),m_State); return false; } @@ -98,9 +97,8 @@ } - m_initialized=true; - m_eventsize=getEventSize(); // this won't change, so cache it - - return m_initialized; + + m_State = E_Initialized; + return true; } @@ -112,4 +110,17 @@ }; +void Port::show() { + debugOutput(DEBUG_LEVEL_VERBOSE,"Name : %s\n", m_Name.c_str()); + debugOutput(DEBUG_LEVEL_VERBOSE,"Signal Type : %d\n", m_SignalType); + debugOutput(DEBUG_LEVEL_VERBOSE,"Buffer Type : %d\n", m_BufferType); + debugOutput(DEBUG_LEVEL_VERBOSE,"Enabled? : %d\n", m_disabled); + debugOutput(DEBUG_LEVEL_VERBOSE,"State? : %d\n", m_State); + debugOutput(DEBUG_LEVEL_VERBOSE,"Buffer Size : %d\n", m_buffersize); + debugOutput(DEBUG_LEVEL_VERBOSE,"Event Size : %d\n", m_eventsize); + debugOutput(DEBUG_LEVEL_VERBOSE,"Data Type : %d\n", m_DataType); + debugOutput(DEBUG_LEVEL_VERBOSE,"Port Type : %d\n", m_PortType); + debugOutput(DEBUG_LEVEL_VERBOSE,"Direction : %d\n", m_Direction); + debugOutput(DEBUG_LEVEL_VERBOSE,"Rate Control? : %d\n", m_do_ratecontrol); +} void Port::setVerboseLevel(int l) { @@ -120,6 +131,6 @@ debugOutput( DEBUG_LEVEL_VERBOSE, "Setting name to %s for port %s\n",name.c_str(),m_Name.c_str()); - if (m_initialized) { - debugFatal("Port already initialized... (%s)\n",m_Name.c_str()); + if (m_State != E_Created) { + debugFatal("Port (%s) not in E_Created state: %d\n",m_Name.c_str(),m_State); return false; } @@ -132,6 +143,6 @@ bool Port::setBufferSize(unsigned int newsize) { debugOutput( DEBUG_LEVEL_VERBOSE, "Setting buffersize to %d for port %s\n",newsize,m_Name.c_str()); - if (m_initialized) { - debugFatal("Port already initialized... (%s)\n",m_Name.c_str()); + if (m_State != E_Created) { + debugFatal("Port (%s) not in E_Created state: %d\n",m_Name.c_str(),m_State); return false; } @@ -157,6 +168,6 @@ bool Port::setDataType(enum E_DataType d) { debugOutput( DEBUG_LEVEL_VERBOSE, "Setting datatype to %d for port %s\n",(int) d,m_Name.c_str()); - if (m_initialized) { - debugFatal("Port already initialized... (%s)\n",m_Name.c_str()); + if (m_State != E_Created) { + debugFatal("Port (%s) not in E_Created state: %d\n",m_Name.c_str(),m_State); return false; } @@ -190,6 +201,6 @@ bool Port::setSignalType(enum E_SignalType s) { debugOutput( DEBUG_LEVEL_VERBOSE, "Setting signaltype to %d for port %s\n",(int)s,m_Name.c_str()); - if (m_initialized) { - debugFatal("Port already initialized... (%s)\n",m_Name.c_str()); + if (m_State != E_Created) { + debugFatal("Port (%s) not in E_Created state: %d\n",m_Name.c_str(),m_State); return false; } @@ -223,6 +234,6 @@ bool Port::setBufferType(enum E_BufferType b) { debugOutput( DEBUG_LEVEL_VERBOSE, "Setting buffer type to %d for port %s\n",(int)b,m_Name.c_str()); - if (m_initialized) { - debugFatal("Port already initialized... (%s)\n",m_Name.c_str()); + if (m_State != E_Created) { + debugFatal("Port (%s) not in E_Created state: %d\n",m_Name.c_str(),m_State); return false; } @@ -257,11 +268,11 @@ // If called on an initialised stream but the request isn't for a change silently // allow it (relied on by C API as used by jack backend driver) - if (m_initialized && m_use_external_buffer==b) + if (m_State==E_Initialized && m_use_external_buffer==b) return true; debugOutput( DEBUG_LEVEL_VERBOSE, "Setting external buffer use to %d for port %s\n",(int)b,m_Name.c_str()); - if (m_initialized) { - debugFatal("Port already initialized... (%s)\n",m_Name.c_str()); + if (m_State != E_Created) { + debugFatal("Port (%s) not in E_Created state: %d\n",m_Name.c_str(),m_State); return false; } @@ -284,5 +295,6 @@ /** * Set the external buffer address. - * only call this when specifying an external buffer before init() + * only call this when you have specified that you will use + * an external buffer before doing the init() * * @param buff @@ -296,6 +308,18 @@ // buffer handling api's for ringbuffers bool Port::writeEvent(void *event) { - assert(m_BufferType==E_RingBuffer); + +#ifdef DEBUG + if (m_State != E_Initialized) { + debugFatal("Port (%s) not in E_Initialized state: %d\n",m_Name.c_str(),m_State); + return false; + } + + if(m_BufferType!=E_RingBuffer) { + debugError("operation not allowed on non E_RingBuffer ports\n"); + show(); + return false; + } assert(m_ringbuffer); +#endif debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "Writing event %08X with size %d to port %s\n",*((quadlet_t *)event),m_eventsize, m_Name.c_str()); @@ -305,15 +329,44 @@ bool Port::readEvent(void *event) { + +#ifdef DEBUG + if (m_State != E_Initialized) { + debugFatal("Port (%s) not in E_Initialized state: %d\n",m_Name.c_str(),m_State); + return false; + } + + if(m_BufferType!=E_RingBuffer) { + debugError("operation not allowed on non E_RingBuffer ports\n"); + show(); + return false; + } assert(m_ringbuffer); - +#endif + + unsigned int read=ffado_ringbuffer_read(m_ringbuffer, (char *)event, m_eventsize); - + debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "Reading event %X with size %d from port %s\n",*((quadlet_t *)event),m_eventsize,m_Name.c_str()); + + return (read==m_eventsize); } int Port::writeEvents(void *event, unsigned int nevents) { - assert(m_BufferType==E_RingBuffer); + +#ifdef DEBUG + if (m_State != E_Initialized) { + debugFatal("Port (%s) not in E_Initialized state: %d\n",m_Name.c_str(),m_State); + return false; + } + + if(m_BufferType!=E_RingBuffer) { + debugError("operation not allowed on non E_RingBuffer ports\n"); + show(); + return false; + } assert(m_ringbuffer); +#endif + unsigned int bytes2write=m_eventsize*nevents; @@ -338,5 +391,18 @@ int Port::readEvents(void *event, unsigned int nevents) { + +#ifdef DEBUG + if (m_State != E_Initialized) { + debugFatal("Port (%s) not in E_Initialized state: %d\n",m_Name.c_str(),m_State); + return false; + } + if(m_BufferType!=E_RingBuffer) { + debugError("operation not allowed on non E_RingBuffer ports\n"); + show(); + return false; + } assert(m_ringbuffer); +#endif + unsigned int bytes2read=m_eventsize*nevents; Index: /branches/echoaudio/src/libstreaming/Port.h =================================================================== --- /branches/echoaudio/src/libstreaming/Port.h (revision 445) +++ /branches/echoaudio/src/libstreaming/Port.h (revision 545) @@ -270,6 +270,7 @@ int readEvents(void *event, unsigned int nevents); ///< read multiple events - virtual void setVerboseLevel(int l); - + virtual void setVerboseLevel(int l); + virtual void show(); + protected: std::string m_Name; ///< Port name, [at construction] @@ -279,5 +280,4 @@ bool m_disabled; ///< is the port disabled?, [anytime] - bool m_initialized; ///< is the port initialized? [after init()] unsigned int m_buffersize; @@ -306,5 +306,16 @@ DECLARE_DEBUG_MODULE; - + + // the state machine + protected: + enum EStates { + E_Created, + E_Initialized, + E_Prepared, + E_Running, + E_Error + }; + + enum EStates m_State; }; Index: /branches/echoaudio/src/libstreaming/AmdtpPortInfo.h =================================================================== --- /branches/echoaudio/src/libstreaming/AmdtpPortInfo.h (revision 445) +++ /branches/echoaudio/src/libstreaming/AmdtpPortInfo.h (revision 545) @@ -54,11 +54,10 @@ }; - AmdtpPortInfo(std::string name, int position, int location, enum E_Formats format) - : m_name(name), m_position(position), m_location(location), m_format(format) + AmdtpPortInfo( int position, int location, enum E_Formats format) + : m_position(position), m_location(location), m_format(format) {}; virtual ~AmdtpPortInfo() {}; - std::string getName() {return m_name;}; int getLocation() {return m_location;}; int getPosition() {return m_position;}; @@ -66,6 +65,4 @@ protected: - std::string m_name; - int m_position; int m_location;