From: Derek J S. <der...@us...> - 2007-02-24 09:29:10
|
Update of /cvsroot/openh323/opal/samples/jester In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv9318 Modified Files: main.cxx main.h Log Message: Add ability to turn off the first packet in an audio burst. Test the jitter buffer can cope with missing the first packet. Index: main.cxx =================================================================== RCS file: /cvsroot/openh323/opal/samples/jester/main.cxx,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** main.cxx 14 Jan 2007 22:18:35 -0000 1.13 --- main.cxx 24 Feb 2007 09:29:08 -0000 1.14 *************** *** 23,26 **** --- 23,30 ---- * * $Log$ + * Revision 1.14 2007/02/24 09:29:08 dereksmithies + * Add ability to turn off the first packet in an audio burst. Test the jitter buffer + * can cope with missing the first packet. + * * Revision 1.13 2007/01/14 22:18:35 dereksmithies * MOdify the period when doing silence detect, to be 69sec off, 6 sec on. *************** *** 126,129 **** --- 130,134 ---- "s-silence." "h-help." + "m-marker." #if PTRACING "o-output:" *************** *** 139,154 **** "General options:\n" ! " -a --audiodevice : audio device to play the output on\n" ! " -i --iterations # : number of packets to ask for (default is 80)\n" ! " -s --silence : simulate silence suppression. - so audio is sent in bursts.\n" ! " -j --jitter # : size of the jitter buffer in ms (100) \n" #if PTRACING ! " -t --trace : Enable trace, use multiple times for more detail.\n" ! " -o --output : File for trace output, default is stderr.\n" #endif ! " -h --help : This help message.\n" ! " -v --version : report version and program info.\n" ! " -w --wavfile : audio file from which the source data is read from \n" "\n" "\n"; --- 144,160 ---- "General options:\n" ! " -a --audiodevice : audio device to play the output on\n" ! " -i --iterations # : number of packets to ask for (default is 80)\n" ! " -s --silence : simulate silence suppression. - so audio is sent in bursts.\n" ! " -j --jitter [min-]max : size of the jitter buffer in ms (100-1000) \n" ! " -m --marker : turn some of the marker bits off, that indicate speech bursts\n" #if PTRACING ! " -t --trace : Enable trace, use multiple times for more detail.\n" ! " -o --output : File for trace output, default is stderr.\n" #endif ! " -h --help : This help message.\n" ! " -v --version : report version and program info.\n" ! " -w --wavfile : audio file from which the source data is read from \n" "\n" "\n"; *************** *** 171,176 **** #endif - minJitterSize = 100; - if (args.HasOption('a')) audioDevice = args.GetOptionString('a'); --- 177,180 ---- *************** *** 178,186 **** audioDevice = PSoundChannel::GetDefaultDevice(PSoundChannel::Player); ! if (args.HasOption('j')) ! minJitterSize = args.GetOptionString('j').AsInteger(); silenceSuppression = args.HasOption('s'); if (args.HasOption('w')) wavFile = args.GetOptionString('w'); --- 182,215 ---- audioDevice = PSoundChannel::GetDefaultDevice(PSoundChannel::Player); ! minJitterSize = 100; ! maxJitterSize = 1000; ! ! if (args.HasOption('j')) { ! unsigned minJitterNew; ! unsigned maxJitterNew; ! PStringArray delays = args.GetOptionString('j').Tokenise(",-"); ! ! if (delays.GetSize() > 1) { ! minJitterNew = delays[0].AsUnsigned(); ! maxJitterNew = delays[1].AsUnsigned(); ! } else { ! maxJitterNew = delays[0].AsUnsigned(); ! minJitterNew = maxJitterNew; ! } ! ! if (minJitterNew >= 20 && minJitterNew <= maxJitterNew && maxJitterNew <= 1000) { ! minJitterSize = minJitterNew; ! maxJitterSize = maxJitterNew; ! } else { ! cout << "Jitter should be between 20 milliseconds and 1 seconds, is " ! << 20 << '-' << 1000 << endl; ! } ! } ! cerr << "Set jitter buffer size to " << minJitterSize << ".." << maxJitterSize << " ms" << endl; silenceSuppression = args.HasOption('s'); + markerSuppression = args.HasOption('m'); + if (args.HasOption('w')) wavFile = args.GetOptionString('w'); *************** *** 189,195 **** } ! bytesPerBlock = 480; ! ! cerr << "Jitter size is set to " << minJitterSize << " ms" << endl; if (!PFile::Exists(wavFile)) { --- 218,222 ---- } ! bytesPerBlock = 640; if (!PFile::Exists(wavFile)) { *************** *** 199,203 **** } ! if (!player.Open(audioDevice, PSoundChannel::Player)) { cerr << "Failed to open the sound device " << audioDevice << " to write the jittered audio to" << endl; --- 226,230 ---- } ! if (!player.Open(audioDevice, PSoundChannel::Player, 1, 8000, 16)) { cerr << "Failed to open the sound device " << audioDevice << " to write the jittered audio to" << endl; *************** *** 213,222 **** } ! jitterBuffer.SetDelay(8 * minJitterSize, 8 * minJitterSize * 3); jitterBuffer.Resume(); keepRunning = TRUE; ! generateTimestamp = FALSE; ! consumeTimestamp = FALSE; PThread * writer = PThread::Create(PCREATE_NOTIFIER(GenerateUdpPackets), 0, --- 240,249 ---- } ! jitterBuffer.SetDelay(8 * minJitterSize, 8 * maxJitterSize); jitterBuffer.Resume(); keepRunning = TRUE; ! generateTimestamp = 0; ! consumeTimestamp = 0; PThread * writer = PThread::Create(PCREATE_NOTIFIER(GenerateUdpPackets), 0, *************** *** 251,263 **** PWAVFile soundFile(wavFile); generateIndex = 0; ! while(keepRunning) { ! generateTimestamp = 960 + (generateIndex * 240); ! //Silence period, 45 seconds cycle, with 3 second on time. ! if (silenceSuppression && ((generateIndex % 2500) > 200)) { PTRACE(3, "Don't send this frame - silence period"); if (lastFrameWasSilence == FALSE) { PTRACE(3, "Stop Audio here"); cout << "Stop audio at " << PTime() << endl; } lastFrameWasSilence = TRUE; --- 278,292 ---- PWAVFile soundFile(wavFile); generateIndex = 0; ! PINDEX talkSequenceCounter = 0; ! while(keepRunning) { ! generateTimestamp = (bytesPerBlock * 2) + ((generateIndex * bytesPerBlock) >> 1); ! //Silence period, 10 seconds cycle, with 3 second on time. ! if (silenceSuppression && ((generateIndex % 1000) > 200)) { PTRACE(3, "Don't send this frame - silence period"); if (lastFrameWasSilence == FALSE) { PTRACE(3, "Stop Audio here"); cout << "Stop audio at " << PTime() << endl; + talkSequenceCounter++; } lastFrameWasSilence = TRUE; *************** *** 285,289 **** PTRACE(3, "Reopen the sound file, as have reached the end of it"); } ! jitterBuffer.NewFrameFromNetwork(frame); } --- 314,322 ---- PTRACE(3, "Reopen the sound file, as have reached the end of it"); } ! // cerr << " " << silenceSuppression << " " << markerSuppression << " " << frame->GetMarker() << " " << (talkSequenceCounter & 1) << endl; ! if (silenceSuppression && markerSuppression && frame->GetMarker() && (talkSequenceCounter & 1)) ! cerr << "Suppress speech frame" << endl; ! else ! jitterBuffer.NewFrameFromNetwork(frame); } *************** *** 307,327 **** { RTP_DataFrame readFrame; - PAdaptiveDelay readDelay; PBYTEArray silence(bytesPerBlock); consumeTimestamp = 0; consumeIndex = 0; while(keepRunning) { BOOL success = jitterBuffer.ReadData(consumeTimestamp, readFrame); if (success && (readFrame.GetPayloadSize() > 0)) { consumeTimestamp = readFrame.GetTimestamp(); player.Write(readFrame.GetPayloadPtr(), readFrame.GetPayloadSize()); PTRACE(3, "Play audio from the buffer to sound device, ts=" << consumeTimestamp); } else { player.Write(silence, bytesPerBlock); PTRACE(3, "Play audio from silence buffer to sound device, ts=" << consumeTimestamp); } ! consumeTimestamp += 240; consumeIndex++; } --- 340,366 ---- { RTP_DataFrame readFrame; PBYTEArray silence(bytesPerBlock); consumeTimestamp = 0; consumeIndex = 0; + while(keepRunning) { BOOL success = jitterBuffer.ReadData(consumeTimestamp, readFrame); + PTime lastWriteTime; if (success && (readFrame.GetPayloadSize() > 0)) { consumeTimestamp = readFrame.GetTimestamp(); + PTRACE(3, "Write audio to sound device, " << readFrame.GetPayloadSize() << " bytes"); player.Write(readFrame.GetPayloadPtr(), readFrame.GetPayloadSize()); PTRACE(3, "Play audio from the buffer to sound device, ts=" << consumeTimestamp); } else { + PTRACE(3, "Write silence to sound device, " << bytesPerBlock << " bytes"); player.Write(silence, bytesPerBlock); PTRACE(3, "Play audio from silence buffer to sound device, ts=" << consumeTimestamp); } ! PTime thisTime; ! PTRACE(3, "Write to sound device took " << (thisTime - lastWriteTime).GetMilliSeconds() << " ms"); ! ! consumeTimestamp += (bytesPerBlock / 2); consumeIndex++; } Index: main.h =================================================================== RCS file: /cvsroot/openh323/opal/samples/jester/main.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** main.h 12 Jan 2007 10:00:58 -0000 1.7 --- main.h 24 Feb 2007 09:29:08 -0000 1.8 *************** *** 23,26 **** --- 23,30 ---- * * $Log$ + * Revision 1.8 2007/02/24 09:29:08 dereksmithies + * Add ability to turn off the first packet in an audio burst. Test the jitter buffer + * can cope with missing the first packet. + * * Revision 1.7 2007/01/12 10:00:58 dereksmithies * bring it up to date so it compiles. *************** *** 188,194 **** --- 192,210 ---- BOOL silenceSuppression; + /**Flag to indicate if we do, or do not fiddle with the operaiton of + silence suppression function. When doing silence suppression, the start + of each talk burst has the marker bit turned on. If this flag is set + TRUE, then some of those marker bits (half of them) are + suppressed. This flag therefore tests the operation of the jitter + buffer, to see if it copes with the dropping of the first packet in + each voice stream */ + BOOL markerSuppression; + /**min size of the jitter buffer in ms */ PINDEX minJitterSize; + /**max size of the jitter buffer - time units is ms */ + PINDEX maxJitterSize; + /**A descendant of the OpalJitterBuffer, which means we have the minimum of code to write to test OpalJitterBuffer. Further, we can now access |