2

I'm building a video chat in flash and everything works really well, except for the part where I'm trying to detect if the other user is sending a working video stream.

There's a couple of reasons why the other user isn't sending video.

  1. The other user got no camera
  2. The other user got a camera, but the camera is currently being occupied by another application(Skype, Photo Booth, Google Talk, etc.)
  3. The other user got a camera but hasn't allowed the use of his/hers camera.
  4. (Other unexpected problems I guess...)

So how do I detect if the stream I receive from the other user is a black stream(because of the reasons above) using the NetStream class?

The closest thing I have came up with is by adding a timer that polls the currentFps() function from the stream I receive from the other user. But so far this seems pretty unreliable because I might get currentFps() == 0 and show an error because of this even though I actually got video from the stream in some cases. The reason for this is because I poll the API every 4 seconds for the currentFPS function and let's say at 00:00:04 I get "no video" according to the poll but at 00:00:05 the video kicks in, and therefor I need to wait until the next tick until the error message disappears

This is what my current poll looks like

function subscribingStatusPoll(e:TimerEvent):void {
  if (subscribingStream.currentFPS == 0){
    error.text = "No video found from the other user..."
  } else {
    error.text = "";
  }
}

This is the only hack I that I can come up with to detect this, but this is unreliable and I actually would prefer a way to instantly detect if the stream I receive got a working video attached to it without this ugly poll.

Fredrik
  • 2,016
  • 3
  • 15
  • 26
  • glance: You might try a video framework that handles disconnects / bad feeds? eg osmf or ovp. Regardless those won't safeguard you from a black screen - to check for that my only solution involves more polling :( – Jacksonkr Aug 02 '11 at 05:15

2 Answers2

3

While I would agree with not sending a "blank" stream from the server-side, you may not have access to the server-side and thus it would not apply to your situation. On the client-side you could grab a frame from the stream at an interval and check for changes or just look at the timestamps (look for an increase over time). These options may seem hack-ish but they should definitely work in Flash.

If I had to develop this myself, I would start with this edge detection code and replace the webcam grab with a frame grab from the playing stream.

http://www.laserpirate.com/as3edgeandmotion/

Paul Gregoire
  • 9,715
  • 11
  • 67
  • 131
1

Wrong approach.
As much as validating the data on the receiving end is a great idea there is no way to detect if a stream is real data or not.
In your case the stream that is being sent is not a true camera stream but it is a stream none-the-less.
There is no detection for this.
Why not just handle validating on the sending client?

The_asMan
  • 6,364
  • 4
  • 23
  • 34
  • So, can you elaborate on how you would send the errors to the other side using flash only? I don't want any external dependencies on some kind of pushing server and such. – Fredrik Aug 09 '11 at 20:42
  • What I mean is basically if the receiving client is receiving a stream it should play it. You need to look on the sending side to determine if the stream should be sent or not. – The_asMan Aug 10 '11 at 01:04