Streaming webcam & desktop em Silverlight

LINK for Youtube VIDEO 

Silverlight 4 – Silverlight Chat – Streaming u'r desktop and webcam from Rui Marinho on Vimeo.

 (Scroll down to the english version of the blog post)

PT:  Já foi algum tempo o primeiro screencast que fiz, mas mais vale tarde que nunca, aqui estou eu de volta para mostrar mais uma brincadeira desta vez com o Silverlight 4.

Neste video mostro uma uma aplicaçao demo que fiz durante a ultima semana cá em casa, nos pequenos intrevalos que a minha filha me deixou. Silverlight Chat é uma chatroom em Silverlight que utiliza a nova funcionalidade do sl 4 UPDMulticast , basicamente isto permite-nos usar outro protocolo de comunicaçao sem ser o normal http, usamos uma socket especial para nos ligarmos a um certo ip que é o grupo de multicast, a partir do momento que entramos nesse grupo tudo que enviamos é recebido por todos, este método não é muito seguro e tem outros contras, mas para transmitir dentro de uma rede interna em que temos total controlo sobre a nossa rede pode ser usado a nosso favor para transmitir dados, video, ou qualquer outro tipo de dados. A vantagem é que só mandamos os dados uma vez em vez e a nossa rede faz o resto, em vez do tradicional modo de cliente-servidor.

Esta aplicação serviu também para por em prática e tentar arranjar a minha zona de conforto na implementação das novas patterns em voga, MVVM e MEF. Comecei por estudar, ler bastante e correr alguns exemplos sobre estes novos modelos que são usados e recomendados vivamente pela Microsoft para o futuro desenvolvimento de aplicações em .NET , especialmente Silverlight, depois aliado ao facto de eu me sentir inspirado por grandes trabalhos com writablebitmaps de Rick Barraza, e video no Commodare64 de Pete Brown fiquei com o bichinho e tentei trazer algo novo ainda nao muito visto na blogosfera.

A aplicação respeita MVVM em quase todos os sentidos, para começar tive a grande ajuda da framework MVVM Light do Laurent Bugnion, estes templates para o vs e a librarias ajudam muito quem se inicia nestes andanças. A construção das views, view model e models, bem como a sua ligação usando o Locator ou o sistema de Messanging e bastante fácil e eficaz. A minha unica alteração foi usar MEF para ligar as views – viewmodel – model em vez do locator.

Para capturar o desktop utilizei uma class escrita em .Net que modifiquei para a tornar visivel com objecto COM e resistei na minha gac de modo a poder ser descoberta pela minha aplicação silverlight quando esta a ser exectuda fora do browser. Apesar disso funcionar, quebra o modelo de deployment da nossa aplicação, ficamos dependentes da presença da dll no computador do cliente, se nao existir, ou não existir .NET isto já não é possivel. Com esta solução tinhamos que assegurar que registavamos a dll em todos os computadores que iam executar aplicação o que para a aplicação web não é aconselhável. Mas se estivermos a falar de um ambiente controlado como é uma intranet já faz mais sentido.

Para enviar o streaming e todos os dados criei um pequeno sistema de comunicação ,o que é enviado para o nosso canal multicast são arrays the bytes, no inicio de cada mensagem escrevo no array informações que me permitem saber qual o conteudo da messagem,  uma frame, uma imagem, um login, uma msg de texto, depois isso permite me saber o que fazer com a mensagem e o mvvm faz o resto, usando comandos, databinding e separando os nossos blocos da aplicação a implementação foi bastante simples.

Claro que nem tudo são rosas, neste momento deparei me com um problema, não consigo comunicar ainda com outro computador diferente na minha rede, visto que a minha rede em casa é fornecida pelo router wireless do meu isp provavelmente tem algum tipo de bloqueio,  vou ter que tentar no trabalho para saber se funciona mesmo ou não.

Para já fica esta intro, qualquer dúvida usem o twitter @ruiespinho ou o mail.

ps – adorava ouvir feedback , não a queixarem-se meu mau inglês (desculpem não tenho treinado), mas sim da aplicação, potencialidades que veêm neste projecto, as vossas experiências com multicast, se alguem souber como resolver o problema da minha rede não funcionar com udp… estejam a vontade.

EN:  It has been some time since the first screencast I've done, but better late than never. I am back to show one more fun this time with Silverlight 4.

In this video I show a demo application that I made during the last week here at home, in the small moments that my daughter left me. Silverlight Chat is a chatroom in Silverlight that uses the new functionality of SL 4 UPDMulticast to comunicate, basically this allows us to use a different protocol of communication other than the normal http, we use a special socket for tapping into a certain ip which is the multicast group from the moment we enter this group everything we send is received by all, this method is not very secure and has other cons, but to work in an internal network where we have total control over our network can be used to our please and transmit text, video, or any other type of data. The advantage is that only send data once and our network does the rest, instead of the traditional mode of multiple client-server.

This application also served to put into practice and try to get my comfort zone in the implementation of new patterns in vogue, MVVM and MEF. I began to study, read a lot and run some examples of these new models that are used and strongly recommended by Microsoft for future application development. NET, Silverlight especially. The fact that I feel inspired by great works with writablebitmaps by Rick Barraza and René, and video on Commodare64 project  by Pete Brown got me the bug to try something new that  has not seen too much in the blogosphere.

The application complies with MVVM in almost every way, to start I had the great help of the framework MVVM Light from Laurent Bugnion, these templates help alot in vs specialy for those starting these wanderings. The construction of views, view model and models, as well as their connection done using the Locator our Messanging are very easy and effective. The only change I made was to use MEF to link views – ViewModel – model instead of the locator.

To capture the desktop i used a class written in .Net that I modified to make it visible to COM object and register it in my GAC so that it can be discovered by my silverlight application when it is executed to outside the browser. Despite this work, it breaks the model of deployment of our application, we are dependent on the presence of the DLL on the client computer, if not exist, or .Net does not exist, then is not possible. With this solution we had to ensure that the DLL can be registered on all computers that would run the application and for the web application that is not advisable. But if we're talking about a controlled environment like an intranet is now makes more sense.

To send the stream and all data i  created a brief communication system, what is sent to our multicast channel are byte arrays, at the beginning of each message in the array i write information so I may know the content of the data in that package when received, a frame , one image, new person, one msg text, then it lets me know what to do with the message and mvvm does the rest, using commands, databinding and separating our concerns in the the application implementation was quite simple.

Of course not all are roses,  at this time I came across a problem, I can not  communicate with other different computer on my network, since my home network is provided by the wireless router from my isp probably has some kind of blockage, I have to try in my job if it works or not.

For now this is intro, any doubt use the Twitter @ruiespinho or mail.

ps – i will love to hear feedback, not complaining about my bad english (sorry I have not trained), but rather the application, who see's potential in this project, your experience with multicast, if anyone knows how to solve the problem of my network does not work udp with …

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top