The Java Sound Internet Phone



Similar documents
point to point and point to multi point calls over IP

RTP / RTCP. Announcements. Today s Lecture. RTP Info RTP (RFC 3550) I. Final Exam study guide online. Signup for project demos

Broadband Networks. Prof. Dr. Abhay Karandikar. Electrical Engineering Department. Indian Institute of Technology, Bombay. Lecture - 29.

The POSIX Socket API

Wireless In-Ear Audio Monitor

USER GUIDE. MyNetFone USB VoIP Phone with Soft Phone Software User Guide. Table of Contents

Curso de Telefonía IP para el MTC. Sesión 2 Requerimientos principales. Mg. Antonio Ocampo Zúñiga

Network administrators must be aware that delay exists, and then design their network to bring end-to-end delay within acceptable limits.

Encapsulating Voice in IP Packets

Question1-part2 What undesirable consequences might there be in having too long a DNS cache entry lifetime?

Voice-Over-IP. Daniel Zappala. CS 460 Computer Networking Brigham Young University

Call Recorder Oygo Manual. Version

Special Note Ethernet Connection Problems and Handling Methods (CS203 / CS468 / CS469)

Communicating with a Barco projector over network. Technical note

Tutorial on Socket Programming

Building a Multi-Threaded Web Server

The BSN Hardware and Software Platform: Enabling Easy Development of Body Sensor Network Applications

Application Development with TCP/IP. Brian S. Mitchell Drexel University

SIP SOFTPHONE SDK Microsoft Windows Desktop OS

Frequently Asked Questions

Study and installation of a VOIP service on ipaq in Linux environment

Web Conferencing Version 8.3 Troubleshooting Guide

Generalised Socket Addresses for Unix Squeak

VoIP network planning guide

USER GUIDE. Table of Contents. MyNetFone Soft Phone Software User Guide

Optimizing Converged Cisco Networks (ONT)

Socket Programming in C/C++

Network Simulation Traffic, Paths and Impairment

Network Communication

How to develop your own app

Java Network. Slides prepared by : Farzana Rahman

2. Download, save and unzip the Cambridge Audio USB 2.0 driver from the Cambridge Audio website

Configuration Guide. T.38 Protocol in AOS L1-29.1D September 2011

Voice over IP. Demonstration 1: VoIP Protocols. Network Environment

Assignment 4 Solutions

Getting Started with Microsoft Office Live Meeting. Published October 2007

Internet Access to a Radio Astronomy Observatory Whitham D. Reeve ( 2012 W. Reeve)

Learning Outcomes. Networking. Sockets. TCP/IP Networks. Hostnames and DNS TCP/IP

Zoom Participant Guide

Getting Started with Microsoft Office Live Meeting. Published October 2007 Last Update: August 2009

Chapter 3. Internet Applications and Network Programming

Creating a Simple, Multithreaded Chat System with Java

ENGG*44200 Real Time System Design Lab3 Implement VoIP on ARM Outline

The Problem with Faxing over VoIP Channels

Evaluating Data Networks for Voice Readiness

VegaStream Information Note Considerations for a VoIP installation

User Manual. For additional help please send a detailed to Support@phnxaudio.com. - 1 Phoenix Audio Technologies

Java Network Programming. The java.net package contains the Socket class. This class speaks TCP (connection-oriented protocol).

3.5. cmsg Developer s Guide. Data Acquisition Group JEFFERSON LAB. Version

Unit 23. RTP, VoIP. Shyam Parekh

Understanding Latency in IP Telephony

WebEx. Network Bandwidth White Paper. WebEx Communications Inc

Voice Over IP Per Call Bandwidth Consumption

CNT5106C Project Description

MixMeister EZ Converter Setup & Troubleshooting Contents:

Division of Informatics, University of Edinburgh

Intranet, Extranet, Firewall

Bandwidth Security and QoS Considerations

SSC - Communication and Networking Java Socket Programming (II)

Original brief explanation

IP Telephony v1.0 Scope and Sequence. Cisco Networking Academy Program

Internet Technology Voice over IP

ICS 351: Today's plan. IP addresses Network Address Translation Dynamic Host Configuration Protocol Small Office / Home Office configuration

VoIP Bandwidth Calculation

Digital Audio and Video Data

Troubleshooting Common Issues in VoIP

How To Understand How Bandwidth Is Used In A Network With A Realtime Connection

Quality of Service (QoS) and Quality of Experience (QoE) VoiceCon Fall 2008

Audio Help for Webinar Attendees. GoToWebinar User Guide. Virtual Operating System (VMware, Parallels, etc.)

Introduction VOIP in an Network VOIP 3

Mobicents. The Open Source Communication Platform

How To. Instreamer to Exstreamer connection. Project Name: Document Type: Document Revision: Instreamer to Exstreamer connection. How To 1.

Machine Problem 3 (Option 1): Mobile Video Chat

Clearing the Way for VoIP

Voice over Internet Protocol (VoIP) systems can be built up in numerous forms and these systems include mobile units, conferencing units and

QNX Software Development Platform 6.6. QNX Neutrino OS Audio Developer's Guide

The network we see so far. Internet Best Effort Service. Is best-effort good enough? An Audio Example. Network Support for Playback

A Transport Protocol for Multimedia Wireless Sensor Networks

Lesson 8: Simon - Arrays

VOICE OVER IP AND NETWORK CONVERGENCE

CTI Products. TurboVUi Dispatch. Demo Installation and Test Drive. Document # S For Version 7 Software

AI Audio 2 (SoundMAX High Definition Audio utility)

Using IPM to Measure Network Performance

1. Software Version. 2. iphone User Manual. 2.1 Sign in/sign out. This manual is for iphone and Android software version

IHM VoIP Products. Document history:

TELE 301 Network Management. Lecture 17: File Transfer & Web Caching

Basics. Mbox 2. Version 7.0

Radio for Everyone...

Mobicents 2.0 The Open Source Communication Platform. DERUELLE Jean JBoss, by Red Hat 138

Combining Voice over IP with Policy-Based Quality of Service

Soft Call Recorder v3 Manual Version

Intel Retail Client Manager Audience Analytics

How To Solve A Network Communication Problem

VoIPvoice MAC Integration User Guide. VoIPvoice Skype Integration for MAC. User Guide. Last Updated 02 December Page 1 of 11

Transcription:

The Java Sound Internet Phone java.sun.com/javaone/sf Florian Bomers Sun Microsystems, Inc. Matthias Pfisterer itservices pfisterer 1

Overall Presentation Goal Simple VoIP with Java Learn how to build a simple Voice over IP (VoIP) application with Java. Explore how to leverage new features in J2SE 5.0. 2

Speaker Introduction Florian Bomers is leading Java Sound development at Sun Microsystems Matthias Pfisterer is an independent contractor mainly for Java technology-based projects Both have been programming with the Java Sound API since its very beginning They lead the Tritonus project an open source implementation of the Java Sound API, and plugins. They founded the jsresources.org project (Java Sound Resources): open source FAQs, examples, applications. Today's application is available at jsresources.org 3

Agenda Demo General Architecture and program details New Tiger Features Problems and Solutions Future Enhancements Your Questions 4

Demo The Java Sound Internet Phone in Action! 5

General Architecture Network I Uses a simple TCP connection Not well suited: delay, jitter overhead But very simple: InputStream, OutputStream Connection class is abstract; UDP connection fits into architecture 6

General Architecture Network II The active side initiates the connection The listener (passive side) accepts connection The active side sends a small header with magic, protocol version, audio format code The passive side responds with ACK From then on, only direct audio 7

General Architecture Audio I: general Network format: possibly compressed choice of GSM, phone, FM, CD quality Line format: the format that the soundcard is opened usually only PCM use AudioSystem.getAudioInputStream to convert network audio format to line format use new Direct Audio devices for high performance 8

General Architecture Audio II: playback Use SourceDataLine for streaming playback receives audio data from network in an AudioInputStream converted PCM stream is read in a thread and written to the SourceDataLine use SourceDataLine's buffer size for reading and writing Network AIS GSM AudioSystem AIS PCM Playback 9

General Architecture Audio III: capture Use TargetDataLine for streaming capture The TargetDataLine is wrapped in an AudioInputStream so that it can be converted to the network format with AudioSystem a capture thread reads from the converted AudioInputStream and writes it to the network connection's OutputStream Capture AIS PCM AudioSystem AIS GSM Network 10

General Architecture Audio IV: Mixers, Ports User can choose the Mixer for capture and for playback User can choose the Port to capture from: a list of all Ports a volume slider User can change the volume of an arbitrary Port: a list of all Ports a volume slider does not select which output port is used for playback! 11

New Tiger Features Ports Select input port on soundcard Adjust volume for input and output ports gain, pan, mute, select Partial implementation available in J2SDK 1.4.2 Since JDK 1.5: available on all platforms 12

New Tiger Features Direct Audio New, additional set of Mixers direct access to the soundcard access to all soundcards low latency (small buffers) possible implementation for Linux available in J2SDK 1.4.2 Since JDK 1.5: available on all platforms Requires ALSA on Linux, DirectSound 5 on Windows, and mixer on Solaris 13

New Tiger Features sound-properties -- default devices Specify system default device for SourceDataLine, TargetDataLine,... in jre/lib/sound/properties file: # use ALSA plughw:1 device as default SourceDataLine javax.sound.sampled.sourcedataline=#audiopci [plughw:1,0] Use new convenience methods: // retrieve the default SourceDataLine // with a given format: SourceDataLine line=audiosystem.getsourcedataline(format); 14

New Tiger Features New Language Features Static import: import static org.jsresources.apps.chat.constants.*; Generics: List<String> portnames = new List<String>(); Autoboxing: List<Integer> controlindex = new List<Integer>(); controlindex.add(10); // <=> add(new Integer(10)) Enhanced For: List<String> getmixernames(list<mixer> mixers) { List<String> res = new ArrayList<String>(); for (Mixer m: mixers) { res.add(m.getmixerinfo().getname()); } return res; } 15

Problems and Solutions: Audio Port assignments Problem: now we can access all Ports on the system, but which Port really selects, e.g., the microphone? Which port will adjust the volume for the selected Mixer and SourceDataLine? Java Sound does not give access to this connection. In our application, we present the user a list of all Ports, and she/he needs to pick the correct one to be able to adjust the gain/volume. 16

Problems and Solutions: Audio Create a list of all Ports Many ports per soundcard, flexible configurations possible! Mixer Delta66 [hw:0] Mixer AudioPCI [hw:1] Source Port Microphone Source Port Line In Source Port CD Target Port Aux Target Port Speaker CompoundControl Microphone CompoundControl Line In CompoundControl Wave FloatControl Master BoolControl Mute FloatControl Volume BooleanControl Select FloatControl Volume BooleanControl Mute FloatControl Pan 17

Problems and Solutions: Audio Create a list of all Ports Solution: use the fact that all volume and select controls will reside in a CompoundControl. Only use top-level CompoundControls: void addportcontrols(list<string> portnames, Mixer mixer, Port port) { port.open(); // need to open port to access Controls! Control[] controls = port.getcontrols(); for (Control c: controls) // enhanced for with arrays if (c instanceof CompoundControl) portnames.add(mixer.getmixerinfo().getname() +": "+c.gettype().tostring()); } Delta66 [hw:0]: Microphone Delta66 [hw:0]: Line In AudioPCI [hw:1]: Microphone AudioPCI [hw:1]: Wave... 18

Problems and Solutions: Audio Changing Buffer Size while line is running In order to find out the minimum buffer size (i.e. minimize latency), we want to change the buffer size while audio is playing But buffer size is specified when opening the Line! Close the Line, and re-open it with the new buffer size. Not nice, but unavoidable. API should be enhanced to allow buffer changes while Line is open. Analogous for changing the current Mixer. 19

Problems and Solutions: Audio Test Mode for Microphone We wanted to provide a test mode: microphone is enabled and everything that is captured is played on the speakers Easy with the stream architecture: Use the capture AudioInputStream (which reads from the TargetDataLine) as input for the Playback class. The Playback class will think that the stream comes from the network. AIS PCM Capture AS AIS AS AIS GSM PCM Playback 20

Problems and Solutions: Audio Level Meter We want to display the current level of the microphone and of the speaker DataLine has a method: getlevel() which is not implemented! Need to calculate the current level on our own for each buffer that is read from the TargetDataLine, calculate the maximum value and store as current level in a separate thread, display the current level in a JProgressBar every 50 milliseconds 21

Problems and Solutions: Audio Level Meter: Code, 8-bit protected void calccurrvol(byte[] b, int off, int len) { int end = off+len; int samplesize = (lineformat.getsamplesizeinbits() + 7) / 8; int max = 0; if (samplesize == 1) { // 8-bit for ( ; off < end; off++) { int sample = (byte) (b[off] + 128); if (sample < 0) sample = -sample; if (sample > max) max = sample; } lastlevel = max; } else if (samplesize == 2) {...16-bit next slide... } } 22

Problems and Solutions: Audio Level Meter: Code, 16-bit... 16-bit: if (lineformat.isbigendian()) { // 16-bit big endian for ( ; off < end; off+=2) { int sample = (short) ((b[off]<<8) (b[off+1] & 0xFF)); if (sample < 0) sample = -sample; if (sample > max) max = sample; } } else { // 16-bit little endian for ( ; off < end; off+=2) { int sample = (short) ((b[off+1]<<8) (b[off] & 0xFF)); if (sample < 0) sample = -sample; if (sample > max) max = sample; } } // scale down to 0..127 lastlevel = max >> 8; 23

Problems and Solutions: Audio Mute button We want to provide a mute button -- may need to cover up private noises :) Could use Port's mute or Volume controls but are we sure that it's the right port? Implement a soft-mute: just zero the buffer if muted this way we're absolutely sure that it is really muted 24

Problems and Solutions: Audio Mute button: Code... capture code: int ret = line.read(b, off, len); if (ismuted()) { mutebuffer(b, off, ret); }... protected void mutebuffer(byte[] b, int off, int len) { int end = off+len; int samplesize = (lineformat.getsamplesizeinbits() + 7) / 8; byte filler = 0; if (samplesize == lineformat.getchannels()) { // 8-bit has -128 as silence filler = -128; } for ( ; off < end; off++) { b[off] = filler; } } 25

Problems and Solutions: Network Incomplete read() Calling read() on a Socket's InputStream may return less bytes than requested Solution: DataInputStream.readFully() Socket sock =...; InputStream instream = sock.getinputstream(); byte buffer = new byte[4]; // may read any between 0 and 4 bytes instream.read(buffer); 26 // guaranteed to read 4 bytes DataInputStream datainstream = new DataInputStream(inStream); datainstream.read(buffer);

Problems and Solutions: Network TCP latency Original round-trip delay: 1,5 seconds Delay end-to-end (one direction): about 750 ms Solution: set send buffer size and receive buffer size for sockets With 1024 bytes: delay barely noticable Size in bytes should depend on audio format 27 void setsocketoptions(socket sock) { sock.setnodelay(false); // delayed ACK improves // performance sock.setsendbuffersize(1024); sock.setreceivebuffersize(1024); }

Problems and Solutions: Network Connection detection Active side: plain Socket Initiates connection Passive side: ServerSocket Waits for incoming connections Socket commsock; // communication socket void connect(inetaddress addr) { commsock = new Socket(addr, PORT); // tries to connect setsocketoptions(commsock); } ServerSocket servsock = new ServerSocket(PORT); void listen() { commsock = servsock.accept(); // blocks until conn. attempt setsocketoptions(commsock); } 28

Problems and Solutions: Network Disconnect detection One side closes its communication socket to initiate a disconnect The peer detects it by receiving exceptions when reading from or writing to the socket Not yet implemented cleanly 29

Problems and Solutions: Network Two users on the same machine Only one process can listen for connections on a specific port numer Two instances need to use different port numbers Solution: port number as configuration option 30

Summary You have learned......how to build a simple VoIP application in pure Java...how to use Tiger's new language and sound features...about some limitations in Java Sound...some tips and tricks how to overcome common problems 31

For More Information Demo application and downloads: http://www.jsresources.org/apps/chat/ Tritonus (incl. download of GSM plug-in): http://www.tritonus.org Florian.Bomers@sun.com Matthias.Pfisterer@web.de 32

Q&A 33

The Java Sound Internet Phone java.sun.com/javaone/sf Florian Bomers Sun Microsystems, Inc. Matthias Pfisterer itservices pfisterer 34