Monday, April 5, 2021

First day with Elixir

 It's been quite some time I have been feeling a great urge to explore elixir. Today, I read the Elixir and Phoenix after two years blog post and it seems the time has come. I should learn some Elixir. 💪

I live with a MacBook Pro and so it was easy to install elixir. 

brew install elixir

More details installation guide can be found https://elixir-lang.org/install.html

Now that I have elixir installed in my machine, I can not wait to get my terminal dirty with some elixir. I should start from https://elixir-lang.org/getting-started/introduction.html, and invest some time every day. I hope I will find it interesting.

So, I opened my terminal and embrace elixir by typing

$iex

Saturday, July 9, 2016

Install, and run CoTurn in Amazon EC2

I have been doing WebRTC recently. I always preferred ICE to be relayed. This means, all WebRTC connections will be relayed, and ignore STUN, or P2P. My SFU, and relay servers were hosted in EC2 instances. SFU are docarized, but TURN servers are not. Right now, I am only interested with UDP relay, and password based ( key-pair ) authentication. So, this setup will only work with UDP relay, and no rest-based authentication will not work with this installation. I don't recommend key-pair authentication. It is recommended to add some extra layer of verification by adding time-stamp, server-token if you really want to support password ( key-pair ) based authentication.

I am using an Ubuntu 14.04 EC2 image.
  • Install Dependencies 
       sudo apt-get update && 
       sudo apt-get install -y build-essential \ 
       golang git libav-tools libavcodec-dev \ 
       libavcodec-extra libavformat-dev zip unzip \ 
       libmicrohttpd-dev libjansson-dev libnice-dev \ 
       libssl-dev libsrtp-dev libsofia-sip-ua-dev libglib2.0-dev \ 
       libopus-dev libogg-dev pkg-config gengetopt libtool automake wget cmake vim sqlite3 libsqlite3-dev
    
  • Install libevent
       wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
       tar xvfz libevent-2.0.21-stable.tar.gz
       cd libevent-2.0.21-stable
       ./configure
       make
       sudo make install
    
  • Install CoTurn
      wget -c https://github.com/coturn/coturn/archive/4.5.0.3.tar.gz
      tar -xzvf 4.5.0.3.tar.gz
      cd coturn-4.5.0.3/
      ./configure
      make
      sudo make install
    
  • Run CoTurn
      PRIVATE_IP=`curl http://169.254.169.254/latest/meta-data/local-ipv4 2> /dev/null`
      PUBLIC_IP=`curl -4 icanhazip.com 2> /dev/null`
      sudo sh -c "nohup turnserver --syslog -a -L ${PRIVATE_IP} -X ${PUBLIC_IP} -E ${PRIVATE_IP} -f --min-port=1024 --max-port=65535 --user=ninefingers:youhavetoberealistic -r realm --log-file=stdout &"Th
    
    • This will start CoTurn server as a background process. To stop the co-turn, you will need to find the process Id ( PID ), and kill the process.
    •   sudo ps aux | grep turn
        sudo kill -9 "current coturn process id"
      

  • Open EC2 UDP ports
    • I had to open UDP ports 1024-65535 for for amazon instance. For simplicity, right now I opened all incoming UDP ports for Turn server.

Saturday, July 12, 2014

Angular Notes

I have been doing angular for around six months by now. It's pretty cool that I don't feel bored to write javascript and htmls anymore. I guess you can take a look at it too.

Where to go first ?

  1. Their website
  2. I guess you can start with this video first. It's just a twenty minutes amazing youtube video on angularJS for beginners
  3. Their official phone cat app. I didn't liked it that first. But I heard they updated it. I am going to read it right after finishing my notes
  4. You can also subscribe to their youtube channel.
  5. Google is your friend. There are so many useful and interesting blogs,books and tutorials on angularJS. Please explore yourself

In this github repo. I wrote a few commits to introduce myself with angularJS. I will be describe them from commit to commit tomorrow.

Sunday, January 12, 2014

How to publish a live stream (MPEG-TS based encoder)

The procedure I followed is mentioned in details here
http://www.wowza.com/forums/content.php?37
I am using , Linux Mint-13 and wowza media server-3.


The basic steps for setting up an application for live streaming and configuring Application.xml :
     1. Create application folder [install-dir]/applications/live. [ I have this application already available ]  
     2. Create configuration folder [install-dir]/conf/live [ I have this application already available ]  
     3. Copy/Overwrite Pre-configured version of Application.xml to [install-dir]/conf/live  
     4. From Application.xml, changes the followings if they are not already configured  
         1. Set the Streams/StreamType property to:  
                <StreamType>live</StreamType>  
         2. Set the HTTPStreamers property to:  
 <HTTPStreamers>cupertinostreaming,smoothstreaming,sanjosestreaming</HTTPStreamers>  
         3. Set the Streams/LiveStreamPacketizers property to:  
 <LiveStreamPacketizers>cupertinostreamingpacketizer,smoothstreamingpacketizer,sanjosestreamingpacketizer</LiveStreamPacketizers>  
         4. Set the RTP/Authentication/PlayMethod property to:  
 <PlayMethod>none</PlayMethod>  

Publishing the stream :
    1. Create .stream file:  
        a. Use a text editor to create the file [install-dir]/content/mpegts.stream and set the contents of this file to udp://[myip]:10000. If you're receiving a multicast stream, change [myip] part of the URL to the multicast address of the stream.  

             
 b. Using a text editor, edit the [install-dir]/conf/admin.password file and add a username and password that will be used to start and stop the publishing of the MPEG-TS stream (below is an example of the file with the username myuser and password mypassword):   


     
   3. Start/Restart Wowza Media Server.     
    4. Use Stream Manager to start the MPEG-TS stream:          
             a. Enter the following URL in a web browser:   
                    URL: http://[wowza-ip-address]:8086/streammanager    
             b. In the Security dialog box, enter your admin username and password from above.     
           





        c. In the Stream Manager webpage, click the [start-receiving-stream] link just below the live application folder.         
        d. In the Start Receiving Stream dialog box, select the following MediaCaster Type option: rtp  
        e.In the Stream Name field, enter mpegts.stream and press ok.   







Publish stream using ffmpeg : 
 
  $ ffmpeg -re -i file.ts -acodec copy -vcodec copy -f mpegts udp://192.168.43.129:10000?pkt_size=1316 I played the stream using mplayer  


I played the stream using mplayer
 $ mplayer -msglevel all=6 rtmp://192.168.43.129:1935/live/mpegts.stream

Friday, November 22, 2013

Install a particular version of gcc.

 sudo apt-get install gcc-4.4  
 sudo apt-get install gcc-4.4-multilib  
 sudo apt-get install g++-4.4  
 sudo apt-get install g++-4.4-multilib  
 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.4  

I am using ubuntu 12.04, and my default gcc version is 4.7. I wanted to install gcc 4.4.


 ~$ gcc -v  
 Using built-in specs.  
 Target: x86_64-linux-gnu  
 Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.4.7-1ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu  
 Thread model: posix  
 gcc version 4.4.7 (Ubuntu/Linaro 4.4.7-1ubuntu2)   

Problem I faced with git

Changed a lots of code for testing, now I want to go back to commit state. All changes will be undone.
     git checkout -- .

Checkout a specific commit.
    git checkout 'hashvalue'

Force push a revision
   git push --force origin development



Monday, November 18, 2013

Creates a functional field that save field value in database

I have a field name as :
 _column {  
   'name': fields.char('Name', size=64, required=True, translate=True),  
   'hash_value': fields.function(_get_hash,method=True,type='char',string='Hash Value', store=True )  
 }  

I want hash_value equal to the slugify value of name and also want to save it in database. This code will do the trick.
  def _get_hash(self, cr, uid, ids, fld_name, arg, context=None):  
     if not len(ids):  
       return []  
     result={}  
     reads = self.read(cr, uid, ids, ['name'], context=context)  
     for atr in reads:  
       result[ atr['id'] ] = slugify(atr['name'])  
     return result