00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 #include "jaus/extras/audio/reportaudio.h" 00041 00042 using namespace JAUS; 00043 00044 00053 ReportAudio::ReportAudio(const Address& dest, 00054 const Address& src) : Message(REPORT_AUDIO, dest, src) 00055 { 00056 mDeviceID = 0; 00057 mFormat = Mono8; 00058 mFrequency = 0; 00059 } 00060 00061 00067 ReportAudio::ReportAudio(const ReportAudio& message) : Message(REPORT_AUDIO) 00068 { 00069 *this = message; 00070 } 00071 00072 00078 ReportAudio::~ReportAudio() 00079 { 00080 00081 } 00082 00083 00095 int ReportAudio::WriteMessageBody(Packet& packet) const 00096 { 00097 int total = 0; 00098 int expected = BYTE_SIZE*2 + 00099 INT_SIZE + 00100 UINT_SIZE*2 + 00101 mAudio.Length(); 00102 00103 total += packet.WriteByte(mDeviceID); 00104 total += packet.WriteByte((Byte)mFormat); 00105 total += packet.Write(mFrequency); 00106 total += packet.Write(mTimeStamp.ToUInt()); 00107 total += packet.Write((UInt)mAudio.Length()); 00108 total += packet.Write(mAudio); 00109 return total == expected ? total : -1; 00110 } 00111 00112 00124 int ReportAudio::ReadMessageBody(const Packet& packet) 00125 { 00126 int total = 0; 00127 int expected = BYTE_SIZE*2 + 00128 INT_SIZE + 00129 UINT_SIZE*2; 00130 Byte temp = 0; 00131 total += packet.Read(mDeviceID); 00132 00133 total += packet.Read(temp); 00134 mFormat = (Format)temp; 00135 00136 total += packet.Read(mFrequency); 00137 UInt tstamp = 0; 00138 total += packet.Read(tstamp); 00139 mTimeStamp.SetTime(tstamp); 00140 00141 UInt len = 0; 00142 total += packet.Read(len); 00143 total += packet.Read(mAudio, len); 00144 00145 return total == expected ? total : -1; 00146 } 00147 00148 00154 void ReportAudio::ClearMessageBody() 00155 { 00156 mDeviceID = 0; 00157 mFormat = Mono8; 00158 mFrequency = 0; 00159 mAudio.Clear(); 00160 mTimeStamp.Clear(); 00161 } 00162 00163 00172 bool ReportAudio::IsLargeDataSet(const unsigned int maxPayloadSize) const 00173 { 00174 unsigned int size = BYTE_SIZE*2 + 00175 INT_SIZE + 00176 UINT_SIZE*2 + 00177 mAudio.Length(); 00178 return size > maxPayloadSize ? true : false; 00179 } 00180 00181 00187 ReportAudio& ReportAudio::operator =(const ReportAudio& message) 00188 { 00189 if(this != &message) 00190 { 00191 CopyHeaderData(&message); 00192 mDeviceID = message.mDeviceID; 00193 mFormat = message.mFormat; 00194 mFrequency = message.mFrequency; 00195 mAudio = message.mAudio; 00196 mTimeStamp = message.mTimeStamp; 00197 } 00198 return *this; 00199 } 00200 00201 00202 /* End of File */