tags:

views:

52

answers:

1

Hi!

I have several flash clients that send live audio stream to the Red5 server. Is it possible to combine all this audio streams together so that other clients could subscribe only to one audio stream and listen live audio from all publishers?

A: 

Is this possible yes, but only with red5, no. You will need to write your own library or use something like Xuggler. Red5 does not encode or decode audio or video data, so it is not able to merge or manipulate your stream in the way you would like.
Also be aware that if you do use a library to gain access to the audio stream, you will need to pay close attention when merging so that you don't get hiss'es and pops in your output audio. A more involved method, than the one below will be needed for more than two streams:

private short[] mixSamples(short[] samples1, short[] samples2) {
    short[] mixedSamples = new short[samples1.length];
    for (int s = 0; s < samples1.length; s++) {
        int sum = (samples1[s] + samples2[s]) / 2; 
        mixedSamples[s] = (short) (sum < Short.MIN_VALUE ? Short.MIN_VALUE : sum > Short.MAX_VALUE ? Short.MAX_VALUE : sum); 
    }
    return mixedSamples;
}

Mondain