Recording Using RTP Mediastreaming
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anshul_Shelley
Posted On:   Saturday, August 11, 2001 10:39 AM

How can i do the recording using JTAPI and JMF? I have tried doing the following code as under, but  i fail to capture the data on arrival at the registerd port(RTP is used)? The environment uses Cisco AVVID architecture which includes Cisco Call Manager, Cisco IP Phone 7960, JTAPI and JMF. The Following application registers media capabilities with a CTI port and another application listens to the reistered port. The MyReceiver.java implements "ReceiveStreamListener" but is unable to catch "ReceiveStreamEvent". import javax.telephony.*; import javax.telephony.callcontrol.*; import javax.telephony.events.*; import javax.telephony.m   More>>

How can i do the recording using JTAPI and JMF? I have tried doing the following
code as under, but  i fail to capture the data on arrival at the
registerd port(RTP is used)?
The environment uses Cisco AVVID architecture which includes Cisco Call Manager,
Cisco IP Phone 7960, JTAPI and JMF. The Following application registers media
capabilities with a CTI port and another application listens to the reistered
port. The MyReceiver.java implements "ReceiveStreamListener" but is
unable to catch "ReceiveStreamEvent".



import javax.telephony.*;
import javax.telephony.callcontrol.*;
import javax.telephony.events.*;
import javax.telephony.media.*;
import javax.telephony.media.events.*;
import com.cisco.cti.util.Condition;
import com.cisco.jtapi.extensions.*;
import java.net.*;
import java.io.*;
import javax.telephony.callcontrol.events.*;
import javax.media.*;
import javax.media.protocol.*;
import javax.media.protocol.DataSource;
import javax.media.format.*;
import javax.media.control.*;
import javax.media.rtp.*;
import javax.media.rtp.rtcp.*;
import com.sun.media.rtp.*;
import com.cisco.jtapi.extensions.*;
import javax.media.rtp.event.*;
import java.util.*;
import javax.telephony.callcenter.*;

class MyCallObserver implements CallControlCallObserver, MediaCallObserver,
CiscoTerminalObserver, CiscoAddressObserver
{
       MyCallObserver( ) {

   }

  /**
   * This methods implements the CallObserver and the CallControlCallObserver.
   * It is called by the implementation to notify us of state
changes in the
   * terminal.
   */
   public synchronized void callChangedEvent( CallEv[] eventList
)
   {
       try
       {
           for ( int i = 0; i < eventList.length;
i++ )
           {
               if (eventList[i].isNewMetaEvent())
{
                   //System.out.println
( "NEW META EVENT_________" + JTAPIDecoder.getMetaCode( eventList[i].getMetaCode()
) + "
");
               }

               //System.out.println
( "Received " + eventList[i] + " for " );

               if ( eventList[i]
instanceof ConnEv ) {
                   //System.out.println
( ((ConnEv)eventList[i]).getConnection().getAddress().getName() );
               } else if ( eventList[i]
instanceof TermConnEv ) {
                   //System.out.println
( ((TermConnEv)eventList[i]).getTerminalConnection().getTerminal().getName()
);
               } else if ( eventList[i]
instanceof CallEv ) {
                   //System.out.println
( "callID=" + ((CallEv)eventList[i]).getID() );
               }

               //System.out.println
( " Cause: " + JTAPIDecoder.getCause( eventList[i].getCause() ) );
               if ( eventList[i]
instanceof CallCtlEv ) {
                   //System.out.println
( " CallControlCause: " + JTAPIDecoder.getCallCtlCause( ((CallCtlEv)eventList[i]).getCallControlCause()
) );
               }
               //System.out.println
( "
" );

               switch ( eventList[i].getID
() ) {
               case CallCtlConnOfferedEv.ID:
                   offered
( (CallCtlConnOfferedEv) eventList[i] );
                   break;
               case CallCtlConnAlertingEv.ID:
                   alerting
( (CallCtlConnAlertingEv) eventList[i] );
                   break;
               case MediaTermConnDtmfEv.ID:
                   digit
( (MediaTermConnDtmfEv) eventList[i] );
                   break;
               }
           }
       }catch(Exception ex) {}
      }

   public synchronized void addressChangedEvent ( AddrEv [] eventList
) {
       traceGenericEvents ( eventList );
   }

   public synchronized void terminalChangedEvent ( TermEv [] eventList
) {
       traceGenericEvents ( eventList );
   }

   void traceGenericEvents ( Ev [] eventList ) {
       try {
           for ( int i = 0; i < eventList.length;
i++ )
           {
               if (eventList[i].isNewMetaEvent())
{
                   //System.out.println
( "NEW META EVENT_________" + JTAPIDecoder.getMetaCode( eventList[i].getMetaCode()
) + "
");
               }
               //System.out.println
( "Received " + eventList[i] );
               //System.out.println
( " Cause: " + JTAPIDecoder.getCause( eventList[i].getCause() ) );
               //System.out.println
( "
" );
           }
       }
       finally {

       }
   }

   void digit ( MediaTermConnDtmfEv ev ) {
   }

   void offered ( CallCtlConnOfferedEv ev ) {
   }

   void alerting ( CallCtlConnAlertingEv ev ) {
   }


}


class CiscoMediaTerminalObserver extends MyCallObserver implements CiscoTerminalObserver
{
   CiscoMediaTerminal    terminal;
   private static final int PORT_NUM = 0x2232;


   CiscoMediaTerminalObserver(  CiscoMediaTerminal terminal
) {
       super ();
       this.terminal = terminal;
       try {
           register ();
           terminal.addObserver ( this );
       }
       catch ( Throwable t ) {
           System.out.println ( "Caught exception
while adding observer: " + t );
       }
   }

   void register () throws Throwable {

       terminal.register (
           InetAddress.getLocalHost (),
           PORT_NUM,
           new CiscoMediaCapability [] { CiscoMediaCapability.G711_64K_30_MILLISECONDS
}
           );
   }

   void unregister () throws Throwable {
       terminal.unregister ();
   }


   void digit ( MediaTermConnDtmfEv ev ) {

   }

   void accept ( CallControlConnection conn ) {
       try {
           System.out.println ( "Got offering,
trying to accept... " );

           conn.accept ();
           System.out.println ( "...accepted.
"
);

       }
       catch ( Exception e ) {
           System.out.println ( "Couldn't
accept, caught " + e );
           System.out.println ( "
" );

       }
   }

   void answer ( CallControlConnection conn ) {
       TerminalConnection tc = conn.getTerminalConnections
()[0];
       try {
           System.out.println ( "Got alerting,
trying to answer... " );

           tc.answer ();
           System.out.println ( "...answered.
"
);
      

       }
       catch ( Exception e ) {
           System.out.println ( "Couldn't
answer, caught " + e );
           System.out.println ( "
" );

       }
   }

   void offered ( CallCtlConnOfferedEv ev ) {
       CallControlConnection conn = (CallControlConnection)
ev.getConnection ();
       //
       // not entirely safe, but it works!
       //
       Address address = terminal.getAddresses ()[0];
       if ( address.equals ( conn.getAddress () ) )
{
           accept ( conn );
       }
   }

   void alerting ( CallCtlConnAlertingEv ev ) {
       CallControlConnection conn = (CallControlConnection)
ev.getConnection ();
       //
       // not entirely safe, but it works!
       //
       Address address = terminal.getAddresses ()[0];
       if ( address.equals ( conn.getAddress () ) )
{
           answer ( conn );
       }
   }

   public void terminalChangedEvent ( TermEv [] eventList )
   {
       try {
           for ( int i = 0; i < eventList.length;
i++ )
           {
              

               if ( eventList[i]
instanceof CiscoTermEv ) {
                   CiscoMediaTerminal
mediaTerm;
                   CiscoTermEv
ev = (CiscoTermEv) eventList[i];
                   switch
( ev.getID () ) {
                   case
CiscoRTPInputStartedEv.ID:
                    
  //System.out.println ( "Received CiscoRTPInputStartedEv :: {
" );
                    
  CiscoRTPInputStartedEv inEv = (CiscoRTPInputStartedEv) ev;
                    
  mediaTerm = (CiscoMediaTerminal) ev.getTerminal ();
                    
  dumpRTPInputProperties ( mediaTerm, inEv.getRTPInputProperties ()
);
                    
  try {
                    
      dumpRTPInputProperties ( mediaTerm, mediaTerm.getRTPInputProperties
() );

                    
  }
                    
  catch ( InvalidStateException e ) {
                    
      //System.out.println ( "
While getting input properties
caught exception: " + e + "
" );
                    
  }
                    
  break;
                   case
CiscoRTPOutputStartedEv.ID:
                    
  //System.out.println ( "Received CiscoRTPOutputStartedEv :: {
" );
                    
  CiscoRTPOutputStartedEv outEv = (CiscoRTPOutputStartedEv) ev;
                    
  mediaTerm = (CiscoMediaTerminal) ev.getTerminal ();
                    
  dumpRTPOutputProperties (  mediaTerm, outEv.getRTPOutputProperties
() );
                    
  try {
                    
      dumpRTPOutputProperties (mediaTerm, mediaTerm.getRTPOutputProperties
() );
                    
  }
                    
  catch ( InvalidStateException e ) {
                    
      //System.out.println ( "
While getting input properties
caught exception: " + e + "
" );
                    
  }
                    
  break;
                   case
CiscoRTPInputStoppedEv.ID:
                    
  //System.out.println ( "Received CiscoRTPInputStoppedEv :: {
" );
                    
  //System.out.println ( "}
" );
                    
  mediaTerm = (CiscoMediaTerminal) ev.getTerminal ();
                    
  try {
                    
      dumpRTPInputProperties ( mediaTerm, mediaTerm.getRTPInputProperties
() );
                    
  }
                    
  catch ( InvalidStateException e ) {
                    
      System.out.println ( "
While getting output properties
caught exception: " + e + "
" );
                    
  }
                    
  break;
                   case
CiscoRTPOutputStoppedEv.ID:
                    
  //System.out.println ( "Received CiscoRTPOutputStoppedEv :: {
" );
                    
  //System.out.println ( "}
" );
                    
  mediaTerm = (CiscoMediaTerminal) ev.getTerminal ();
                    
  try {
                    
      dumpRTPOutputProperties (  mediaTerm, mediaTerm.getRTPOutputProperties
() );
                    
  }
                    
  catch ( InvalidStateException e ) {
                    
      //System.out.println ( "
While getting output properties
caught exception: " + e + "
" );
                    
  }
                    
  break;
                   default:
                    
  //System.out.println ( "Received " + eventList[i] );
                    
  break;
                   }
               }
               else {
                   //System.out.println
( "Received " + eventList[i] );
               }
               //System.out.println
( " Cause: " + JTAPIDecoder.getCause( eventList[i].getCause() ) );
               //System.out.println
( "
" );
           }
       }
       finally {

       }
      }

    void dumpRTPInputProperties (  Terminal terminal, CiscoRTPInputProperties
properties ) {
       System.out.println ( """ + terminal.getName
() + "" CiscoRTPInputProperties :: " );
       System.out.println ( "  localAddress: "
+ properties.getLocalAddress ());
       System.out.println ( "  localPort: " + properties.getLocalPort
());
       System.out.println ( "  packetSize: " +
properties.getPacketSize ());
       //System.out.println ( "  payloadType: "
+ JTAPIDecoder.getPayloadType( properties.getPayloadType ()) + "

);
       MyReceiver receiver = new MyReceiver(properties);
       System.out.println ( "  echoCancellation:
" + properties.getEchoCancellation ());
       System.out.println ( "  bitRate: " + properties.getBitRate
());

   }

    void dumpRTPOutputProperties (  Terminal terminal, CiscoRTPOutputProperties
properties ) {
       System.out.println ( """ + terminal.getName
() + "" CiscoRTPOutputProperties :: " );
       System.out.println ( "  remoteAddress: "
+ properties.getRemoteAddress ());
       System.out.println ( "  remotePort: " +
properties.getRemotePort ());
       System.out.println ( "  packetSize: " +
properties.getPacketSize ());
       //System.out.println ( "  payloadType: "
+ JTAPIDecoder.getPayloadType( properties.getPayloadType ()) + "

);
       System.out.println ( "  precedenceValue:
" + properties.getPrecedenceValue ());
       System.out.println ( "  silenceSuppression:
" + properties.getSilenceSuppression ());
       System.out.println ( "  maxFramesPerPacket:
" + properties.getMaxFramesPerPacket ());
       System.out.println ( "  bitRate: " + properties.getBitRate
());
   }

}

public class ZonePage implements ProviderObserver
{
   Condition conditionInService = new Condition ();
  public static final void main(String args[])
  {
   Provider myprovider = null;
   String providerName="146.127.100.50";
   String login="anshul";
   String passwd="anshul";
   String providerStr = providerName + ";login=" + login + ";passwd="
+ passwd;
   Terminal term = null;
   Address addr = null;
   ZonePage zpage = new ZonePage();

   try
   {

     JtapiPeer peer = JtapiPeerFactory.getJtapiPeer(null);
     System.out.println("Getting destination provider..");
     myprovider = peer.getProvider(providerStr);
     myprovider.addObserver(zpage);
     zpage.conditionInService.waitTrue();

   } catch (Exception excp)
   {
     System.out.println("Can't get destination  Provider:
" + excp.toString());
     System.exit(0);
   }
   try
   {
    // ZonePageObserver observer = new ZonePageObserver();

    // ZonePageObserver1 observer = new ZonePageObserver1();
     addr = myprovider.getAddress("6488");

     CiscoMediaTerminal terminal =(CiscoMediaTerminal) myprovider.getTerminal("AnshulCTI");
     CiscoMediaTerminalObserver observer = new CiscoMediaTerminalObserver(terminal);
     terminal.addCallObserver(observer);
     terminal.addObserver(observer);
     addr.addCallObserver(observer);
    // zpage.registerTerminal (myprovider, "AnshulCTI") ;
     System.out.println("Got destination Terminal...."+terminal);
     //char ch = observer.getDigit();
     //System.out.println("the digit in the main is.."+ch);

   } catch (Exception excp)
   {
     System.out.println("Can't get destination Terminal:
" + excp.toString());
     System.exit(0);
   }
  }
 
  public void providerChangedEvent(ProvEv[] eventList)
  {
     if ( eventList != null )
     {
       for ( int i = 0; i < eventList.length; i++
)
       {
        if ( eventList[i] instanceof ProvInServiceEv
)
        {
          conditionInService.set ();
        }
      }
    }
  }
*******************************************************************************************************
The Class Using JMF for MediaStreaming.
******************************************************************

import javax.telephony.*;
import javax.telephony.callcontrol.*;
import javax.telephony.events.*;
import javax.telephony.media.*;
import javax.telephony.media.events.*;
import com.cisco.cti.util.Condition;
import com.cisco.jtapi.extensions.*;
import java.net.*;
import java.io.*;
import javax.telephony.callcontrol.events.*;
import MyMediaTerminalObserver;
import MyPlayer;
import javax.media.*;
import javax.media.protocol.*;
import javax.media.protocol.DataSource;
import javax.media.format.*;
import javax.media.control.*;
import javax.media.rtp.*;
import javax.media.rtp.rtcp.*;
import com.sun.media.rtp.*;
import com.cisco.jtapi.extensions.*;
import javax.media.rtp.event.*;

public class MyReceiver extends Thread
{
   String sessions[] = {"146.127.98.130/4699"};
   boolean                
dataReceived = false;
   Object                
    dataSync = new Object();
   InetAddress             ipAddr;
   SessionAddress             localAddr;
   SessionAddress             destAddr;
   SessionLabel             session;
   private Call             call;
   private Terminal         term=null;
   private Address         addr =null;
   private String             dest
= null;


       public MyReceiver(CiscoRTPInputProperties properties)
                    
                     
                     
                     
//CiscoRTPInputProperties inputproperties)
       {
           System.out.println("Inside MyReceiver.....");

           Format       
  format;
           FormatControl   fcs [];
           AudioFormat     
  inputFormat;
           AudioFormat     formatAudioDevice
= null;
           try
           {

               RTPManager mgrs =
(RTPManager)RTPManager.newInstance();
               mgrs.addReceiveStreamListener(new
StreamListener());
               ipAddr = InetAddress.getByName("146.127.98.130");
               //localAddr= new
SessionAddress( InetAddress.getLocalHost(), properties.getRemotePort ());
               localAddr= new SessionAddress(
InetAddress.getLocalHost(), properties.getLocalPort ());
               try
               {
                   System.out.println("RTPManager
before initialization....."+mgrs);
                   mgrs.initialize(localAddr);
                   //mgrs.initialize(new
RTPSocketAdapter(InetAddress.getByName("146.127.98.130"),22332, 1));
                   System.out.println("RTPManager
after initialization...."+mgrs);


               }catch (Exception
ee)
               {
                   System.out.println("Error
in intialization");
                   ee.printStackTrace();
               }




               BufferControl bc
= (BufferControl)mgrs.getControl("javax.media.control.BufferControl");
               if (bc != null)
               {
                   System.out.println("bufferlength
before..."+bc.getBufferLength());
                   System.out.println("bufferlength
before..."+bc.getMinimumThreshold());
                   //bc.setEnabledThreshold(false);
                   //bc.setBufferLength(bc.DEFAULT_VALUE);
                   System.out.println("bufferlength
after..."+bc.getBufferLength());
                   System.out.println("mgrs...."+mgrs);
               }

               } catch (Exception
e){e.printStackTrace();
                   System.err.println("Cannot
create the RTP Session: " + e.getMessage());

               }
                    
                     
            // Wait for data to arrive before
moving on.

           long then = System.currentTimeMillis();
           long waitingPeriod = 60000;   
              // wait for a maximum of
30 secs.

           try{
                   synchronized
(dataSync)
                   {
                    
  while (!dataReceived && System.currentTimeMillis() - then
< waitingPeriod)
                    
  {
                    
      if (!dataReceived)
                    
      System.err.println("  - Waiting for RTP data to
arrive...");
                    
      dataSync.wait(1000);
                    
  }
                   }
              } catch (Exception e) {}

           if (!dataReceived)
           {
               System.err.println("No
RTP data was received.");

           }
       }
   }

   class StreamListener implements ReceiveStreamListener
   {
        public void update( ReceiveStreamEvent evt)
       {
           System.out.println(evt+"  
********** ReceiveStreamEvent");
       }
   }

   <<Less
About | Sitemap | Contact