OpenRTMFP / Cumulus

CumulusServer is a complete open source and cross-platform RTMFP server extensible by way of scripting
http://groups.google.com/group/openrtmfp-cumulus
GNU General Public License v3.0
593 stars 222 forks source link

Pixel Level Access #43

Closed anderflash closed 12 years ago

anderflash commented 12 years ago

I need to draw a BitmapData from a Video which has a Cumulus NetStream attached in. The problem is: Cumulus is not allowing to have pixel level access.

What is the configuration to have this permission?

Thanks.

cumulusdev commented 12 years ago

Hi,

Yes, I have never tried this feature indeed :-) So possible that it doesn't work, contact me at the address: cumulus.dev@gmail.com, to see it together.

anderflash commented 12 years ago

I was using Cumulus with Away3D. I've put the remote NetStream in a StageVideo, behind Away3D with transparent background. So I have seen remote webcam as a background for Away3D. But the new release of FP11 doesn't allow transparent background. Away3D let me use a backgroundImage property, but it needs pixel-level access. When I use this strategy, it gives me an Error #2123 (Security Violation). That's why I write this post. The NetStream has a checkPolicyFile property. If set to true, it looks for a crossdomain.xml file to get the permission. I think the solution can be an answer for crossdomain request. If I use rtmfp://localhost as a server, I think it looks for an rtmfp://localhost/crossdomain.xml.

See the description for checkPolicyFile:

flash.net.NetStream.checkPolicyFile(state:Boolean):void

Specifies whether the application tries to download a cross-domain policy file from the loaded video file's server before beginning to load the video file. Use this property for progressive video download, and to load files that are outside the calling SWF file's own domain. This property is ignored when you are using RTMP. Set this property to true to call BitmapData.draw() on a video file loaded from a domain outside that of the calling SWF. The BitmapData.draw() method provides pixel-level access to the video. If you call BitmapData.draw() without setting the checkPolicyFile property to true at loading time, you can get a SecurityError exception because the required policy file was not downloaded. Do not set this property to true unless you want pixel-level access to the video you are loading. Checking for a policy file consumes network bandwidth and can delay the start of your download. When you call the NetStream.play() method with checkPolicyFile set to true, Flash Player or the AIR runtime must either successfully download a relevant cross-domain policy file or determine that no such policy file exists before it begins downloading. To verify the existence of a policy file, Flash Player or the AIR runtime performs the following actions, in this order:

  1. The application considers policy files that have already been downloaded.
  2. The application tries to download any pending policy files specified in calls to the Security.loadPolicyFile() method.
  3. The application tries to download a policy file from the default location that corresponds to the URL you passed to NetStream.play(), which is /crossdomain.xml on the same server as that URL. In all cases, Flash Player or Adobe AIR requires that an appropriate policy file exist on the video's server, that it provide access to the object at the URL you passed to play() based on the policy file's location, and that it allow the domain of the calling code's file to access the video, through one or more tags. If you set checkPolicyFile to true, the application waits until the policy file is verified before downloading the video. Wait to perform any pixel-level operations on the video data, such as calling BitmapData.draw(), until you receive onMetaData or NetStatus events from your NetStream object. If you set checkPolicyFile to true but no relevant policy file is found, you won't receive an error until you perform an operation that requires a policy file, and then the application throws a SecurityError exception. Be careful with checkPolicyFile if you are downloading a file from a URL that uses server-side HTTP redirects. The application tries to retrieve policy files that correspond to the initial URL that you specify in NetStream.play(). If the final file comes from a different URL because of HTTP redirects, the initially downloaded policy files might not be applicable to the file's final URL, which is the URL that matters in security decisions. For more information on policy files, see "Website controls (policy files)" in the ActionScript 3.0 Developer's Guide and the Flash Player Developer Center Topic: Security. See Also: flash.display.BitmapData.draw() flash.system.Security.loadPolicyFile() netStatus onMetaData play() Language Version: 3.0 Player Version: Flash 9
anderflash commented 12 years ago

I don't know if it helps, but try to see if the Cumulus Server receives an . If yes, send an xml stream to the client. You can get an crossdomain.xml file like the auth file. To test, create publisher and receiver clients. The receiver client shows the webcam by a Bitmap. I tried ns.videoSampleAccess = true; ns.checkPolicyFile = true; ns.send("|RtmpSampleAccess",true,true);

But it's not working.

anderflash commented 12 years ago

I think I found a solution.

On the publisher client:

On the receiver client:

Well. To save bandwidth, the receiver can send to the publisher a message to stop the timer (for example, using a NetGroup.post).

The simple demo here worked (the bitmap showed the remote webcam). I will try on my project (as a background for Away3D) to see if it can be a solution. Thanks

cumulusdev commented 12 years ago

It exists a clean way, but here, in your case, publisher publishs to Cumulus? or between peers? It's a publisher->Cumulus->subscriber case? or publisher->subscriber (in P2P) ?

cumulusdev commented 12 years ago

I have just added two new options: videoSampleAccess and audioSampleAccess (see readme file), but it works only for publication not in P2P (with Cumulus intermediate).

anderflash commented 12 years ago

I think ns.send("|RtmpSampleAccess",true,true) will send directly to the subscriber. After the subscriber start playing the publisher stream, he asks for permission. So the publisher sends this property, until the subscriber receives it.

As I have some code in Java, I'm using (in fact, learning) Red5 as Database Server, and Cumulus as P2P Server. It's a very interesting world I'm learning.

cumulusdev commented 12 years ago

Ok, I see, so it's in P2P, it means that the property "videoSampleAccess" of "NetStream" doesn't work, and Michael Thornburgh seems confirming it on this post: http://forums.adobe.com/thread/632355?decorator=print&displayFullThread=true So... the trick "ns.send("|RtmpSampleAccess",true,true)" is the good way today...