How about centralized client-server system by using JMF and RTP ?

I have a question about using jmf.

First, i want to make a conferans system just for audio. Before i met jmf i try to do it by using udp.

By using UDP, i had been able to send packets, which i just captured from mic, to server and on server side

i could send to clients.

The sound format was PCM, 8000, 8, mono. I decided to change it to G.723.1. When i was googling for it, i saw that jmf already doing it.

I had read about jmf, and its protocols on suns tutorials. They are using RTP. So i decided to use jmf. I looked the source code of AVReceive2 and AVTransmit2.

They are try to create a session to communicate. But i have a centralized client-server system. For example, on the client side,

i want to take one of the clients sound packet and on the server side, send that packet all other clients.

How can i do this with jmf? Am i be able to reach the packets? OR to do this, should i create sessions between clients?

I read an article about jmf. It says that with jmf by using RTP, we arent be able to write sockets. Is that my answer?

I hope i could explain my problem in spite of my english.

Im waiting for any help.

[1200 byte] By [itsnavigator@yahoo.com] at [2007-11-26 12:05:33]
# 1

Doesnt anybody have any ideas? or are my questions soo stupid, so nobody answer me?

Also i change my question. As i told before, i wanna make a centralized client server system.

Is the algorithym wrong ?

Sample adresses :

Server IP= a.a.a.a

Client1 IP = x.x.x.x

Client2 IP = y.y.y.y

Client3 IP = z.z.z.z

(They are all public)

The situation is :

Both Client1 and Client2 have got a mic, Client3 hasnt got. All of them are in the same room and wanna make

an audio conversation. Also, they connected to server (whose IP is a.a.a.a).

We have 3 clients. Two of them sending packets to server and all of them recieving these packets from server.

Algorithym (I assume that they had already connected to the server):

- Client1 is sending his packet which was just captured from his mic by using his session.

- At that time, Client2 is doing the same thing, sending his packet.

- Server has received a packet from Client1 and then Client2. Server puts them its message queue.

- By the way, server is going on sending packets from queue. Server is getting a packet from his queue and

sending them to all clients.

Also in the samples of Sun, there are AVTransmit2 and AVRecieve2.

AVTransmit2 is trying to open a session with given args.

Also i can give some args to connect my server. ( like "dsound:// a.a.a.a 22222 44444" )

And for server i can make some changes to AVRecieve2. AVReceive2 takes packets and create a Player and then play it.

Have i a changes to say server "Dont play them. U are a server, u must send them to clients." ?

I guess it is been able to do. But its more important " HOW ? ".

It must be here somewhere.

(These codes are from one of the Suns sample, AVTransmit2.java)

public synchronized void update(ReceiveStreamEvent evt) {

RTPManager mgr = (RTPManager) evt.getSource();

Participant participant = evt.getParticipant(); // could be null.

ReceiveStream stream = evt.getReceiveStream(); // could be null.

if (evt instanceof RemotePayloadChangeEvent) {

System.err.println(" - Received an RTP PayloadChangeEvent.");

System.err.println("Sorry, cannot handle payload change.");

System.exit(0);

}

else if (evt instanceof NewReceiveStreamEvent) {

try {

stream = ((NewReceiveStreamEvent) evt).getReceiveStream();

DataSource ds = stream.getDataSource();

// Find out the formats.

RTPControl ctl = (RTPControl) ds

.getControl("javax.media.rtp.RTPControl");

if (ctl != null) {

System.err.println(" - Recevied new RTP stream: "

+ ctl.getFormat());

} else

System.err.println(" - Recevied new RTP stream");

if (participant == null)

System.err

.println(" The sender of this stream had yet to be identified.");

else {

System.err.println(" The stream comes from: "

+ participant.getCNAME());

}

// create a player by passing datasource to the Media Manager

Player p = javax.media.Manager.createPlayer(ds);

if (p == null)

return;

p.addControllerListener(this);

p.realize();

PlayerWindow pw = new PlayerWindow(p, stream);

playerWindows.addElement(pw);

// Notify intialize() that a new stream had arrived.

synchronized (dataSync) {

dataReceived = true;

dataSync.notifyAll();

}

} catch (Exception e) {

System.err.println("NewReceiveStreamEvent exception "

+ e.getMessage());

return;

}

}

else if (evt instanceof StreamMappedEvent) {

if (stream != null && stream.getDataSource() != null) {

DataSource ds = stream.getDataSource();

// Find out the formats.

RTPControl ctl = (RTPControl) ds

.getControl("javax.media.rtp.RTPControl");

System.err.println(" - The previously unidentified stream ");

if (ctl != null)

System.err.println(" " + ctl.getFormat());

System.err.println(" had now been identified as sent by: "

+ participant.getCNAME());

}

}

else if (evt instanceof ByeEvent) {

System.err

.println(" - Got \"bye\" from: " + participant.getCNAME());

PlayerWindow pw = find(stream);

if (pw != null) {

pw.close();

playerWindows.removeElement(pw);

}

}

}

Also to solve my problem, should i send the (ReceiveStreamEvent) "evt" to all clients

"if (evt instanceof NewReceiveStreamEvent)" ?

Waiting for help...

Navigator

itsnavigator@yahoocom at 2007-7-7 12:33:05 > top of Java-index,Security,Cryptography...
# 2

You have the right idea. The idea is to add a receiveStreamListener on the RTPManager that is accepting audio from the client. In the update method of the receiveStreamListener you should have something like this:

public void update(ReceiveStreamEvent event){

if (event instanceof NewReceiveStreamEvent)){

DataSource relayedSource = event.getReceiveStream().getDataSource();

sendRelayedAudioManager.createSendStream(relayedSource, 0).start();

}

Where sendRelayedAudioManager is the RTPManager that sends the relayed audio out to the appropriate clients. In your case its targets would be the ip addresses and ports of all of the clients excluding the one sending the audio. I have already implemented all of this so good luck and let me know if you have any more questions.

Malcolm_F at 2007-7-7 12:33:05 > top of Java-index,Security,Cryptography...
# 3

Thanx for ur reply Malcolm. Im glad u have worked about this project. Im not feeling along, not any more ;)

I begun to write my client code. I am writing an applet for client. Are there any security issues for applet using jmf with rtp? Or anything that i have to know ?

( I have some chat works by using applet, using TCP. I didnt have to give any security permission on client side even SocketPermission. )

itsnavigator@yahoocom at 2007-7-7 12:33:05 > top of Java-index,Security,Cryptography...
# 4

I'm having the same problems described here.

My doubt is slightly different, I pretend to have simultaneous sessions, like:

Session 1 - client 1; 2; 3

Session 2 - client 4; 5; 6

Should I use more than one instance of receiveStreamListener? Like 2 threads of AVReceiver2? I'm trying to put it all on one instance (it seems more logic), but I'm having some difficulties to keep the sessions this way.

It's possible to do this with only one listener for all the sessions? Or I should I have a listener for which session?

Passadena at 2007-7-7 12:33:05 > top of Java-index,Security,Cryptography...