Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

/usr/local/FlashphonerWebCallServer/clientclient2/examples/demo/streaming/flash_client/streaming.html

...

1. Right after the application is loaded, we get access to the web camera and the microphone.line 42, line 44

Code Block
languagejsactionscript3
themeRDark
cam = Camera.getCamera();
videoMy.attachCamera(cam);
mic = Microphone.getEnhancedMicrophone();

...

  • Speex audio codec:mic.codec = SoundCodec.SPEEX;
  • The number of frames per packet:mic.framesPerPacket=1;
  • A sound threshold to send audio:mic.setSilenceLevel(0,2000);
Code Block
languagejsactionscript3
themeRDark
privatefunctioninitCamprivate function initCam():void{
    cam.setMode(int(camWidth.text),int(camHeight.text),int(camFPS.text),true);
    cam.setQuality(0,int(camQuality.text));
    cam.setKeyFrameInterval(int(camKeyFrame.text));
    cam.setMotionLevel(0,2000);
    Logger.info("Cam initizlized "+cam.width+"x"+cam.height);
}

privatefunctioninitMicprivate function initMic():void{
    var varoptionsoptions:MicrophoneEnhancedOptions =newMicrophoneEnhancedOptions new MicrophoneEnhancedOptions();
    options.mode = MicrophoneEnhancedMode.FULL_DUPLEX;
    options.echoPath = 128;
    options.nonLinearProcessing = true;
    mic.codec = SoundCodec.SPEEX;
    mic.encodeQuality = 5;
    mic.framesPerPacket=1;
    mic.gain=50;
    mic.setSilenceLevel(0,2000);
    mic.enhancedOptions = options;
    Logger.info("Mic initialized");
}

...

Here we establish connection to the server and send obj.appKey = "flashStreamingApp";
This appKey tells the server, that it should deal with a Flash application, not with a Websocket/WebRTC client

Code Block
languagejsactionscript3
themeRDark
privatefunctionconnectprivate function connect():void{
    trace("connect");
 varurl   var url:String = connectUrl.text;
    nc =newNetConnection new NetConnection();
    //if (url.indexOf("rtmp") == 0){
    nc.objectEncoding = ObjectEncoding.AMF0;
    //}
    nc.client = this;
    nc.addEventListener(NetStatusEvent.NET_STATUS, handleConnectionStatus);
 varobj    var obj:Object =newObject new Object();
    obj.login = generateRandomString(20);
    obj.appKey  = "flashStreamingApp";
    nc.connect(url,obj);
}

4. Sending the stream to the server is performed in the publish() method of the example. line 165

Code Block
languagejsactionscript3
themeRDark
if (publishAudio.selected){
    initMic();
    publishStream.attachAudio(mic);
    Logger.info("Init audio stream")
}
if (publishVideo.selected){
    initCam();
    publishStream.attachCamera(cam);
    addH264();
    Logger.info("Init video stream");
}
addListenerAndPublish();

5.Directly before sending the stream, we set additional buffering parameters and parameters of the H.264 codec in addH264() and addListenerAndPublish() methods.line 199, line 208

Code Block
languagejsactionscript3
themeRDark
privatefunctionaddListenerAndPublishprivate function addListenerAndPublish():void{
    publishStream.videoReliable=true;
    publishStream.audioReliable=false;
    publishStream.useHardwareDecoder=true;
    publishStream.addEventListener(NetStatusEvent.NET_STATUS, handleStreamStatus);
    publishStream.bufferTime=0;
    publishStream.publish(publishStreamName.text);
}

publicfunctionaddH264public function addH264():void{
    var varvideoStreamSettingsvideoStreamSettings:H264VideoStreamSettings =newH264VideoStreamSettings new H264VideoStreamSettings();
    videoStreamSettings.setProfileLevel(H264Profile.MAIN,H264Level.LEVEL_3_1);
    publishStream.videoStreamSettings = videoStreamSettings;
}

6. Playing the stream starts after the play() method is invoked. line 223

Code Block
languagejsactionscript3
themeRDark
privatefunctionplayprivate function play():void{
    if (playStreamName.text == "") {
        playStatus.text = "Empty stream name";
        playStatus.setStyle("color","#ff0000");
        return;
    }
    playStatus.setStyle("color","#000000");
    Logger.info("play");
    subscribeStream =newNetStream new NetStream(nc);
    addListenerAndPlay();
}

7. All settings and buffer sizes are set directly before playing in the addListenerAndPlay() method. line 244

Code Block
languagejsactionscript3
themeRDark
privatefunctionaddListenerAndPlayprivate function addListenerAndPlay():void{
    subscribeStream.videoReliable=true;
    subscribeStream.audioReliable=false;
    subscribeStream.useHardwareDecoder=true;
    subscribeStream.addEventListener(NetStatusEvent.NET_STATUS, handleSubscribeStreamStatus);
    subscribeStream.bufferTime=0;
 varsoundTransform   var soundTransform:SoundTransform =newSoundTransform new SoundTransform();
    soundTransform.volume=0.7;
    subscribeStream.soundTransform = soundTransform;
    subscribeStreamObject = createStreamObject();
    subscribeStream.play(playStreamName.text);
    videoFarEnd.attachNetStream(subscribeStream);
    videoFarEnd.width = 320;
    videoFarEnd.height = 240;
    videoFarEnd.visible = true;
}